Public API
(1 modules)index
index.ts · 152 linesMain entry point for the Boardier library. Re-exports all public components, types, themes, element factories, engine, utilities, and rendering helpers. Import from this module for the cleanest consumer experience.
`import { BoardierCanvas, defaultTheme, createElement } from 'boardier';`Core
(6 modules)core/Clipboard
core/Clipboard.ts · 35 linesIn-memory clipboard for copy/paste of canvas elements. Deep-clones elements to prevent mutation, assigns fresh IDs on paste, and applies a spatial offset so pasted content is visually distinct.
v0.1.0Classes
ClipboardStores a deep-cloned buffer of `BoardierElement[]`. `paste()` returns new elements with fresh IDs and an offset.
`clipboard.copy(selectedElements); const pasted = clipboard.paste(20, 20);`
core/Engine
core/Engine.ts · 1033 linesThe central orchestrator of the Boardier whiteboard. `BoardierEngine` owns the scene graph, undo/redo history, renderer, clipboard, and the active tool. It exposes a public API for tool switching, element manipulation, multi-page support, viewport control, theming, and an AI-facing interface for LLM integration.
See also: Scene, Renderer, History, Clipboard, BaseTool
v0.1.0Classes
BoardierEngineThe main engine class. Instantiate with a `<canvas>` element, a config, and a theme. All user interaction flows through `handlePointer ` / `handleWheel` / `handleKey ` methods which delegate to the active tool. The engine batches re-renders via `requestAnimationFrame`.
`const engine = new BoardierEngine(canvasEl, { showGrid: true }, defaultTheme);`The engine exposes `searchElements()`, `getSceneSummary()`, `getSceneStats()`, `moveElement()`, `resizeElement()`, `setElementColor()`, `deleteAll()`, `panTo()`, `selectElements()`, and `getCanvas()` specifically for LLM agents to read and manipulate the whiteboard programmatically.
core/History
core/History.ts · 67 linesSimple undo/redo stack using full-scene snapshots. Snapshots are deep-cloned via `structuredClone`, so mutations to the live scene don't affect history entries.
v0.1.0Classes
HistoryMaintains a capped stack of `BoardierElement[]` snapshots. Call `push()` after an operation, then `undo()` / `redo()` to navigate.
`history.push(scene.getElements()); // after drag-end`
core/Renderer
core/Renderer.ts · 465 linesCanvas 2D renderer responsible for drawing all elements, the grid, selection overlays, smart guides, and lasso outlines. Performs viewport culling, coordinate transforms (screen ↔ world), and theme-aware color adaptation for dark backgrounds.
See also: BoardierEngine, Scene
v0.1.0core/Scene
core/Scene.ts · 184 linesIn-memory scene graph that holds all elements and the current selection. Provides CRUD operations, hit-testing, z-ordering, and serialisation. Emits change and selection events consumed by the engine and UI.
v0.1.0Classes
SceneManages the flat element array and selection set. Provides `hitTest()` and `getElementsInBounds()` for spatial queries, and `toJSON()` / `fromJSON()` for persistence.
core/types
core/types.ts · 465 linesAll type definitions for the Boardier whiteboard engine. This module contains zero runtime code — it is purely TypeScript type declarations used across every other module. Import only what you need for tree-shaking.
v0.1.0Types
Vec22D vector / point used for positions, offsets, and control points throughout the engine.
`const pos: Vec2 = { x: 100, y: 200 };`BoundsAxis-aligned bounding box used for hit-testing, viewport culling, and layout calculations.
`const b: Bounds = { x: 0, y: 0, width: 100, height: 50 };`BoardierElementTypeUnion of all element type string identifiers. Used as the discriminant in the `BoardierElement` union and as keys in the element registry.
FillStyleAvailable fill patterns for shape elements. `hachure`, `cross-hatch`, `zigzag`, and `zigzag-line` use the rough.js hand-drawn rendering engine.
BoardierElementBaseFields shared by every element on the canvas. All concrete element interfaces extend this base. When creating elements, prefer using the factory functions in `elements/base.ts` which supply sensible defaults.
BoardierElementDiscriminated union of all element shapes. Narrow by checking `element.type` to access shape-specific fields. This is the primary type passed around the engine.
`if (el.type === 'rectangle') { console.log(el.borderRadius); }`ViewStateCamera state for the canvas viewport. `scrollX`/`scrollY` are in world-space pixels; `zoom` is a multiplier (1 = 100%).
`engine.setViewState({ scrollX: 0, scrollY: 0, zoom: 1.5 });`BoardierSceneDataSerialisation format for persisting an entire whiteboard scene. Can be stored in a database, exported as JSON, or loaded back in.
`const json = engine.getSceneData(); localStorage.setItem('scene', JSON.stringify(json));`BoardierConfigConfiguration object passed to `BoardierCanvas` or `BoardierEngine`. All fields are optional — defaults are applied internally.
`<BoardierCanvas config={{ readOnly: true, showGrid: false }} />`BoardierAIConfigConfiguration for AI-assisted features (Phase 3). Boardier never ships API keys — the developer provides their own.
`const aiConfig: BoardierAIConfig = { apiKey: process.env.OPENAI_KEY!, model: 'gpt-4' };`AIChatProviderSupported AI providers for the floating AI chat component.
AIChatMessageA single message in the AI chat conversation history.
AIChatConfigConfiguration for the floating AI chat popup component.
`<AIChatPopup config={{ defaultProvider: 'openai', allowHTMLMode: true }} />`Elements
(17 modules)elements/arrow
elements/arrow.ts · 124 linesRenderer, hit-tester, and bounds-getter for arrows. Extends line rendering with configurable arrowheads at start and/or end. Supports bézier curves and element binding.
v0.1.0elements/base
elements/base.ts · 178 linesElement registry and factory system. Each element type module (rectangle.ts, ellipse.ts, etc.) calls `registerElement()` to provide a renderer, hit-tester, and bounds getter. The factory functions (`createRectangle`, `createEllipse`, …) produce elements with sensible defaults. Use `createElement(type)` as a generic dispatcher.
See also: core/types for the element type definitions
v0.1.0Functions
registerElement()Register a renderer, hit-tester, and bounds-getter for a specific element type. Called once per element module at import time.
type— The `BoardierElementType` string identifier.renderer— Draws the element onto a `CanvasRenderingContext2D`.hitTester— Returns true if a world-space point is within `tolerance` of the element.boundsGetter— Returns the axis-aligned bounding box of the element.
elements/checkbox
elements/checkbox.ts · 95 linesRenderer, hit-tester, and bounds-getter for interactive checkbox elements. Renders a hand-drawn checkbox with check-mark, label text, and configurable check color/size.
v0.1.0elements/comment
elements/comment.ts · 124 linesRenderer, hit-tester, and bounds-getter for comment/annotation pins. Displays author, timestamp, text, and resolved status with a colored marker.
v0.1.0elements/diamond
elements/diamond.ts · 110 linesRenderer, hit-tester, and bounds-getter for the diamond (rhombus) element. Uses roughDiamond for hand-drawn rendering and point-in-polygon for hit-testing.
v0.1.0elements/ellipse
elements/ellipse.ts · 103 linesRenderer, hit-tester, and bounds-getter for the ellipse element. Uses roughEllipse for hand-drawn rendering, supports labels, fill patterns, and point-in-ellipse hit-testing.
v0.1.0elements/embed
elements/embed.ts · 97 linesRenderer, hit-tester, and bounds-getter for embedded web content placeholders. Displays a URL title card on the canvas (actual iframe rendering happens in the UI layer).
v0.1.0elements/frame
elements/frame.ts · 123 linesRenderer, hit-tester, and bounds-getter for frame containers. Frames group child elements with optional clipping, padding, and a labelled header.
v0.1.0elements/freehand
elements/freehand.ts · 76 linesRenderer, hit-tester, and bounds-getter for freehand drawing. Records an array of points (and optional per-point pressure values for stylus support). Rendered as a smooth polyline.
v0.1.0elements/icon
elements/icon.ts · 71 linesRenderer, hit-tester, and bounds-getter for icon elements. Icons are referenced by iconName and iconSet identifiers, with pre-rendered SVG markup cached as Image objects for canvas painting.
v0.1.0elements/image
elements/image.ts · 87 linesRenderer, hit-tester, and bounds-getter for image elements. Supports data URLs and external URLs with object-fit modes (contain/cover/fill).
v0.1.0elements/line
elements/line.ts · 77 linesRenderer, hit-tester, and bounds-getter for straight/bézier lines. Supports an optional controlPoint for quadratic curves and element-binding at start/end points.
v0.1.0elements/marker
elements/marker.ts · 72 linesRenderer, hit-tester, and bounds-getter for the highlighter-marker element. Draws wide, translucent strokes ideal for annotations and emphasis.
v0.1.0elements/radiogroup
elements/radiogroup.ts · 103 linesRenderer, hit-tester, and bounds-getter for interactive radio-button groups. Supports vertical/horizontal layouts with configurable option labels and selection index.
v0.1.0elements/rectangle
elements/rectangle.ts · 150 linesRenderer, hit-tester, and bounds-getter for the rectangle element. Supports border-radius (uniform or per-corner), labels, fill styles (solid/hachure/cross-hatch/dots), stroke styles, shadow, and roughness-based hand-drawn rendering via `roughRect`.
v0.1.0elements/table
elements/table.ts · 96 linesRenderer, hit-tester, and bounds-getter for grid/table elements. Renders rows, columns, cell text, optional headers, and proportional column/row sizing.
v0.1.0elements/text
elements/text.ts · 126 linesRenderer, hit-tester, bounds-getter, and measureText() utility for multi-line text elements. Supports font family/size selection, text alignment, line-height, and optional inline icon placeholders.
v0.1.0Tools
(13 modules)tools/BaseTool
tools/BaseTool.ts · 51 linesAbstract base class and `ToolContext` interface for all Boardier tools. Every tool receives a `ToolContext` with access to the scene, history, renderer, clipboard, theme, viewport, and utility callbacks. Extend `BaseTool` to create custom tool behaviours.
See also: core/Engine for tool registration
v0.1.0tools/CommentTool
tools/CommentTool.ts · 38 linesClick-to-place tool for adding comment/annotation pins. Creates a CommentElement at the click position with default author and timestamp.
v0.1.0tools/EraseTool
tools/EraseTool.ts · 47 linesEraser tool that removes elements on pointer contact. Hit-tests under the cursor and removes matching elements in real-time as the pointer moves.
v0.1.0tools/FreehandTool
tools/FreehandTool.ts · 105 linesFreehand drawing tool. Records pointer positions on move and creates a FreehandElement on release. Supports pressure-sensitive input from styluses.
v0.1.0tools/IconTool
tools/IconTool.ts · 23 linesClick-to-place tool for inserting icon elements. Creates an IconElement with a default icon that can be changed via the icon picker.
v0.1.0tools/ImageTool
tools/ImageTool.ts · 87 linesTool for inserting images. Opens a file picker on click and creates an ImageElement from the selected file.
v0.1.0tools/LineTool
tools/LineTool.ts · 231 linesTool for creating lines and arrows. Supports straight segments, bézier curves (via alt-drag control point), element binding (snapping to target shapes), and multi-point polylines.
v0.1.0tools/MarkerTool
tools/MarkerTool.ts · 91 linesHighlighter / marker tool that creates wide, translucent strokes. Records pointer positions during drag and creates a MarkerElement on release.
v0.1.0tools/PanTool
tools/PanTool.ts · 40 linesHand/pan tool for scrolling the canvas viewport. Also used as a space-bar override in the engine.
v0.1.0tools/SelectTool
tools/SelectTool.ts · 706 linesThe default selection tool. Handles click-to-select, box selection, lasso selection, drag-to-move, resize handles, smart alignment guides, and keyboard shortcuts (delete, copy, paste, undo/redo, select-all). This is the most complex tool in Boardier.
v0.1.0tools/ShapeTool
tools/ShapeTool.ts · 87 linesGeneric tool for creating rectangle, ellipse, and diamond shapes. Click-and-drag creates the shape; hold Shift for square/circle constraint.
v0.1.0tools/TextTool
tools/TextTool.ts · 44 linesClick-to-place text tool. Creates a TextElement at the click position and immediately requests the text editor overlay.
v0.1.0tools/WidgetTool
tools/WidgetTool.ts · 101 linesGeneric tool for placing widget elements (checkbox, radiogroup, frame, embed, table). Accepts a widget type and default dimensions; creates the corresponding element on click.
v0.1.0Themes
(3 modules)themes/defaultTheme
themes/defaultTheme.ts · 163 linesShips two built-in themes: `defaultTheme` (light) and `defaultDarkTheme`. Both are complete BoardierTheme objects that can be used directly or spread into custom themes. Also exports `roughUIStyle` and `cleanUIStyle` presets.
`<BoardierCanvas theme={defaultTheme} />` or `<BoardierCanvas theme={defaultDarkTheme} />`themes/notierTheme
themes/notierTheme.ts · 124 linesFactory function that creates a Notier-branded theme. Accepts optional overrides for accent and background colors.
`const theme = createNotierTheme({ accent: '#6366f1' });`themes/types
themes/types.ts · 134 linesThe complete BoardierTheme interface. Every visual aspect of the engine — canvas background, grid, selection, panels, tooltips, fonts, and element defaults — is configurable through a single theme object. The `uiStyle` section provides full CSS-level control over UI component shapes.
`const myTheme: BoardierTheme = { ...defaultTheme, canvasBackground: '#1e1e1e' };`Types
BoardierUIStyleCSS-level control over the look and shape of every UI component. Developers can make the UI look sketchy/organic, perfectly clean, or anything in between. All `borderRadius` values accept any valid CSS border-radius string.
UI
(15 modules)ui/AIChatPopup
ui/AIChatPopup.tsx · 699 linesFloating AI chat popup component for conversational whiteboard editing. Supports OpenAI, Anthropic (Claude), and Google Gemini providers. Users provide their own API keys. Integrates with Boardier's AI capabilities including element generation and HTML-based smart layouts.
`<AIChatPopup engine={engine} config={{ defaultProvider: 'openai' }} theme={theme} />`ui/BoardierCanvas
ui/BoardierCanvas.tsx · 1098 linesThe top-level React component for embedding the Boardier whiteboard. Wraps the BoardierEngine with a canvas element and provides a complete UI including toolbar, property panel, zoom controls, export dialog, text editor overlays, context menu, minimap, page navigator, and presentation mode. All UI panels are draggable via the DraggablePanel system.
`<BoardierCanvas config={{ showGrid: true }} theme={defaultTheme} onChange={handleChange} />`Ref: BoardierCanvasRef (via React.forwardRef) — exposes getEngine(), getSceneData(), loadScene(), exportToPNG(), exportToSVG(), exportToJSON()
Props: BoardierCanvasProps
v0.1.0ui/ContextMenu
ui/ContextMenu.tsx · 182 linesRight-click context menu for the canvas. Shows element operations (copy, paste, delete, duplicate, z-order, arrange submenu, send to AI, select all) positioned at the cursor.
v0.1.0ui/DraggablePanel
ui/DraggablePanel.tsx · 162 linesA generic draggable container used to wrap toolbar, zoom controls, and export panels. Supports position persistence, no-drop zones, and optional lock mode via BoardierLayoutConfig.
v0.1.0ui/ExportDialog
ui/ExportDialog.tsx · 153 linesModal dialog for exporting the scene to PNG, SVG, or JSON. Provides format selection, scale/padding controls, and a download button.
v0.1.0ui/IconPicker
ui/IconPicker.tsx · 352 linesSearchable icon picker dialog that renders icons from react-icons sets (Feather, Material Design, Font Awesome, etc.). Supports lazy loading, search filtering, and set tabs.
v0.1.0ui/Minimap
ui/Minimap.tsx · 214 linesA small overview map of the entire scene shown in a corner, with integrated zoom controls as a footer. Renders a scaled-down view of all elements and a viewport indicator. Click-to-navigate and drag-to-pan are supported.
v0.1.0ui/PresentationMode
ui/PresentationMode.tsx · 179 linesFullscreen presentation mode that displays pages/frames as slides. Supports keyboard navigation, auto-fit zoom, and ESC to exit.
v0.1.0ui/PropertyPanel
ui/PropertyPanel.tsx · 512 linesSide panel that displays and edits properties of selected elements: stroke color, fill color/style, stroke width/style, opacity, roughness, font, text alignment, border radius, and element-specific fields.
v0.1.0ui/ShapeLabelEditor
ui/ShapeLabelEditor.tsx · 76 linesInline text editor overlay positioned on top of shape elements (rectangles, ellipses, diamonds) for editing their labels.
v0.1.0ui/TextEditor
ui/TextEditor.tsx · 119 linesFloating textarea overlay for editing text elements in-place. Auto-resizes to fit content and supports multi-line editing.
v0.1.0ui/Toolbar
ui/Toolbar.tsx · 416 linesMain tool-selection toolbar. Renders tool buttons for all element types plus select, pan, and eraser. Supports keyboard shortcuts and active-tool highlighting.
v0.1.0ui/Tooltip
ui/Tooltip.tsx · 99 linesThemed tooltip component that appears on hover. Positions itself above/below the trigger element and respects theme colors.
v0.1.0ui/ZoomControls
ui/ZoomControls.tsx · 74 linesZoom-in, zoom-out, and fit-to-content buttons displayed in a compact panel. Shows the current zoom percentage.
v0.1.0Utilities
(7 modules)utils/colors
utils/colors.ts · 62 linesColour palettes, stroke widths, font sizes, and font families used as defaults throughout the UI and element creation. All are exported as `readonly` arrays.
v0.1.0utils/export
utils/export.ts · 193 linesExport functions for converting scene elements to PNG (as Blob), JSON (as string), and SVG (as string). PNG export renders to an offscreen canvas at configurable scale and padding. SVG export generates self-contained markup.
`const blob = await exportToPNG(elements, '#fff', 40, 2);`
utils/id
utils/id.ts · 11 linesUnique ID generator for element IDs. Uses `Math.random().toString(36)` for fast, collision-resistant short IDs.
v0.1.0utils/math
utils/math.ts · 147 linesPure math helpers used throughout the engine: distance, midpoint, rotation, bounds testing, segment/polyline/bézier distance, path simplification, and polygon point-in-polygon testing. All functions are stateless and tree-shakeable.
v0.1.0utils/mermaidParser
utils/mermaidParser.ts · 580 linesConverts Mermaid diagram syntax into Boardier elements. parseMermaid() parses text into a graph structure; mermaidToBoardier() converts that into positioned BoardierElement arrays.
`const elements = mermaidToBoardier('graph TD; A-->B; B-->C');`This module is particularly useful for LLM agents that generate diagrams from natural language.
utils/renderHelpers
utils/renderHelpers.ts · 132 linesShared Canvas 2D rendering helpers: applyStrokeStyle() for dash patterns and drawPatternFill() for hachure/cross-hatch/dot/zigzag fill patterns used by shape renderers.
v0.1.0utils/roughDraw
utils/roughDraw.ts · 195 linesHand-drawn rendering primitives powered by a seeded PRNG. Provides roughRect, roughEllipse, roughDiamond, roughPolyline, roughBezier, and roughFillRect for a sketchy aesthetic. Roughness 0 = clean, 2 = very rough.
v0.1.0Build
(2 modules)scripts/generateChangelog
scripts/generateChangelog.ts · 189 linesGenerates changelog data from boardier-since and boardier-changed annotations. Groups new modules by the version they were introduced, and changed modules by the version they were modified. Outputs `website/src/data/changelog.json` consumed by the /changelog page. Usage: npx tsx scripts/generateChangelog.ts
v0.2.0scripts/parseDocsFromSource
scripts/parseDocsFromSource.ts · 207 linesParses all @boardier- JSDoc annotations from the boardier source tree and outputs a structured JSON file consumed by the /docs page at build time.
v0.1.0