Boardier Docs

69 modules · 13,740 lines of code

Public API

(1 modules)

index

index.ts · 133 lines
Public API

Main 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.

Usage
`import { BoardierCanvas, defaultTheme, createElement } from 'boardier';`
v0.1.0

Core

(6 modules)

core/Clipboard

core/Clipboard.ts · 35 lines
Core

In-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.0

Classes

Clipboard

Stores 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 lines
Core

The 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.0

Classes

BoardierEngine

The 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 lines
Core

Simple 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.0

Classes

History

Maintains 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 lines
Core

Canvas 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.0

core/Scene

core/Scene.ts · 184 lines
Core

In-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.0

Classes

Scene

Manages the flat element array and selection set. Provides `hitTest()` and `getElementsInBounds()` for spatial queries, and `toJSON()` / `fromJSON()` for persistence.

core/types

core/types.ts · 404 lines
Core

All 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.0

Types

Vec2

2D vector / point used for positions, offsets, and control points throughout the engine.

`const pos: Vec2 = { x: 100, y: 200 };`
Bounds

Axis-aligned bounding box used for hit-testing, viewport culling, and layout calculations.

`const b: Bounds = { x: 0, y: 0, width: 100, height: 50 };`
BoardierElementType

Union of all element type string identifiers. Used as the discriminant in the `BoardierElement` union and as keys in the element registry.

FillStyle

Available fill patterns for shape elements. `hachure`, `cross-hatch`, `zigzag`, and `zigzag-line` use the rough.js hand-drawn rendering engine.

BoardierElementBase

Fields 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.

BoardierElement

Discriminated 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); }`
ViewState

Camera 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 });`
BoardierSceneData

Serialisation 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));`
BoardierConfig

Configuration object passed to `BoardierCanvas` or `BoardierEngine`. All fields are optional — defaults are applied internally.

`<BoardierCanvas config={{ readOnly: true, showGrid: false }} />`
BoardierAIConfig

Configuration 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' };`

Elements

(17 modules)

elements/arrow

elements/arrow.ts · 124 lines
Elements

Renderer, 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.0

elements/base

elements/base.ts · 178 lines
Elements

Element 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.0

Functions

registerElement()

Register a renderer, hit-tester, and bounds-getter for a specific element type. Called once per element module at import time.

  • typeThe `BoardierElementType` string identifier.
  • rendererDraws the element onto a `CanvasRenderingContext2D`.
  • hitTesterReturns true if a world-space point is within `tolerance` of the element.
  • boundsGetterReturns the axis-aligned bounding box of the element.

elements/checkbox

elements/checkbox.ts · 95 lines
Elements

Renderer, 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.0

elements/comment

elements/comment.ts · 124 lines
Elements

Renderer, hit-tester, and bounds-getter for comment/annotation pins. Displays author, timestamp, text, and resolved status with a colored marker.

v0.1.0

elements/diamond

elements/diamond.ts · 110 lines
Elements

Renderer, 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.0

elements/ellipse

elements/ellipse.ts · 103 lines
Elements

Renderer, 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.0

elements/embed

elements/embed.ts · 97 lines
Elements

Renderer, 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.0

elements/frame

elements/frame.ts · 123 lines
Elements

Renderer, hit-tester, and bounds-getter for frame containers. Frames group child elements with optional clipping, padding, and a labelled header.

v0.1.0

elements/freehand

elements/freehand.ts · 76 lines
Elements

Renderer, 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.0

elements/icon

elements/icon.ts · 71 lines
Elements

Renderer, 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.0

elements/image

elements/image.ts · 87 lines
Elements

Renderer, hit-tester, and bounds-getter for image elements. Supports data URLs and external URLs with object-fit modes (contain/cover/fill).

v0.1.0

elements/line

elements/line.ts · 77 lines
Elements

Renderer, 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.0

elements/marker

elements/marker.ts · 72 lines
Elements

Renderer, hit-tester, and bounds-getter for the highlighter-marker element. Draws wide, translucent strokes ideal for annotations and emphasis.

v0.1.0

elements/radiogroup

elements/radiogroup.ts · 103 lines
Elements

Renderer, hit-tester, and bounds-getter for interactive radio-button groups. Supports vertical/horizontal layouts with configurable option labels and selection index.

v0.1.0

elements/rectangle

elements/rectangle.ts · 150 lines
Elements

Renderer, 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.0

elements/table

elements/table.ts · 96 lines
Elements

Renderer, hit-tester, and bounds-getter for grid/table elements. Renders rows, columns, cell text, optional headers, and proportional column/row sizing.

v0.1.0

elements/text

elements/text.ts · 126 lines
Elements

Renderer, 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.0

Tools

(13 modules)

tools/BaseTool

tools/BaseTool.ts · 51 lines
Tools

Abstract 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.0

tools/CommentTool

tools/CommentTool.ts · 38 lines
Tools

Click-to-place tool for adding comment/annotation pins. Creates a CommentElement at the click position with default author and timestamp.

v0.1.0

tools/EraseTool

tools/EraseTool.ts · 47 lines
Tools

Eraser 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.0

tools/FreehandTool

tools/FreehandTool.ts · 105 lines
Tools

Freehand drawing tool. Records pointer positions on move and creates a FreehandElement on release. Supports pressure-sensitive input from styluses.

v0.1.0

tools/IconTool

tools/IconTool.ts · 23 lines
Tools

Click-to-place tool for inserting icon elements. Creates an IconElement with a default icon that can be changed via the icon picker.

v0.1.0

tools/ImageTool

tools/ImageTool.ts · 87 lines
Tools

Tool for inserting images. Opens a file picker on click and creates an ImageElement from the selected file.

v0.1.0

tools/LineTool

tools/LineTool.ts · 231 lines
Tools

Tool 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.0

tools/MarkerTool

tools/MarkerTool.ts · 91 lines
Tools

Highlighter / marker tool that creates wide, translucent strokes. Records pointer positions during drag and creates a MarkerElement on release.

v0.1.0

tools/PanTool

tools/PanTool.ts · 40 lines
Tools

Hand/pan tool for scrolling the canvas viewport. Also used as a space-bar override in the engine.

v0.1.0

tools/SelectTool

tools/SelectTool.ts · 706 lines
Tools

The 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.0

tools/ShapeTool

tools/ShapeTool.ts · 87 lines
Tools

Generic tool for creating rectangle, ellipse, and diamond shapes. Click-and-drag creates the shape; hold Shift for square/circle constraint.

v0.1.0

tools/TextTool

tools/TextTool.ts · 44 lines
Tools

Click-to-place text tool. Creates a TextElement at the click position and immediately requests the text editor overlay.

v0.1.0

tools/WidgetTool

tools/WidgetTool.ts · 101 lines
Tools

Generic 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.0

Themes

(3 modules)

themes/defaultTheme

themes/defaultTheme.ts · 163 lines
Themes

Ships 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.

Usage
`<BoardierCanvas theme={defaultTheme} />` or `<BoardierCanvas theme={defaultDarkTheme} />`
v0.1.0

themes/notierTheme

themes/notierTheme.ts · 124 lines
Themes

Factory function that creates a Notier-branded theme. Accepts optional overrides for accent and background colors.

Usage
`const theme = createNotierTheme({ accent: '#6366f1' });`
v0.1.0

themes/types

themes/types.ts · 134 lines
Themes

The 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.

Usage
`const myTheme: BoardierTheme = { ...defaultTheme, canvasBackground: '#1e1e1e' };`
v0.1.0

Types

BoardierUIStyle

CSS-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

(14 modules)

ui/BoardierCanvas

ui/BoardierCanvas.tsx · 1105 lines
UI

The 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.

Usage
`<BoardierCanvas config={{ showGrid: true }} theme={defaultTheme} onChange={handleChange} />`

Ref: BoardierCanvasRef (via React.forwardRef) — exposes getEngine(), getSceneData(), loadScene(), exportToPNG(), exportToSVG(), exportToJSON()

Props: BoardierCanvasProps

v0.1.0

ui/ContextMenu

ui/ContextMenu.tsx · 182 lines
UI

Right-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.0

ui/DraggablePanel

ui/DraggablePanel.tsx · 162 lines
UI

A 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.0

ui/ExportDialog

ui/ExportDialog.tsx · 153 lines
UI

Modal dialog for exporting the scene to PNG, SVG, or JSON. Provides format selection, scale/padding controls, and a download button.

v0.1.0

ui/IconPicker

ui/IconPicker.tsx · 352 lines
UI

Searchable 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.0

ui/Minimap

ui/Minimap.tsx · 160 lines
UI

A small overview map of the entire scene shown in a corner. Renders a scaled-down view of all elements and a viewport indicator. Click-to-navigate and drag-to-pan are supported.

v0.1.0

ui/PageNavigator

ui/PageNavigator.tsx · 132 lines
UI

Multi-page navigation panel. Lists all pages/slides, allows adding, deleting, renaming, and switching between pages.

v0.1.0

ui/PresentationMode

ui/PresentationMode.tsx · 179 lines
UI

Fullscreen presentation mode that displays pages/frames as slides. Supports keyboard navigation, auto-fit zoom, and ESC to exit.

v0.1.0

ui/PropertyPanel

ui/PropertyPanel.tsx · 512 lines
UI

Side 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.0

ui/ShapeLabelEditor

ui/ShapeLabelEditor.tsx · 76 lines
UI

Inline text editor overlay positioned on top of shape elements (rectangles, ellipses, diamonds) for editing their labels.

v0.1.0

ui/TextEditor

ui/TextEditor.tsx · 119 lines
UI

Floating textarea overlay for editing text elements in-place. Auto-resizes to fit content and supports multi-line editing.

v0.1.0

ui/Toolbar

ui/Toolbar.tsx · 416 lines
UI

Main tool-selection toolbar. Renders tool buttons for all element types plus select, pan, and eraser. Supports keyboard shortcuts and active-tool highlighting.

v0.1.0

ui/Tooltip

ui/Tooltip.tsx · 99 lines
UI

Themed tooltip component that appears on hover. Positions itself above/below the trigger element and respects theme colors.

v0.1.0

ui/ZoomControls

ui/ZoomControls.tsx · 74 lines
UI

Zoom-in, zoom-out, and fit-to-content buttons displayed in a compact panel. Shows the current zoom percentage.

v0.1.0

Utilities

(7 modules)

utils/colors

utils/colors.ts · 62 lines
Utilities

Colour 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.0

utils/export

utils/export.ts · 193 lines
Utilities

Export 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.

Usage
`const blob = await exportToPNG(elements, '#fff', 40, 2);`
v0.1.0

utils/id

utils/id.ts · 11 lines
Utilities

Unique ID generator for element IDs. Uses `Math.random().toString(36)` for fast, collision-resistant short IDs.

v0.1.0

utils/math

utils/math.ts · 147 lines
Utilities

Pure 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.0

utils/mermaidParser

utils/mermaidParser.ts · 580 lines
Utilities

Converts Mermaid diagram syntax into Boardier elements. parseMermaid() parses text into a graph structure; mermaidToBoardier() converts that into positioned BoardierElement arrays.

Usage
`const elements = mermaidToBoardier('graph TD; A-->B; B-->C');`
AI Integration

This module is particularly useful for LLM agents that generate diagrams from natural language.

v0.1.0

utils/renderHelpers

utils/renderHelpers.ts · 132 lines
Utilities

Shared Canvas 2D rendering helpers: applyStrokeStyle() for dash patterns and drawPatternFill() for hachure/cross-hatch/dot/zigzag fill patterns used by shape renderers.

v0.1.0

utils/roughDraw

utils/roughDraw.ts · 195 lines
Utilities

Hand-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.0

Build

(2 modules)

scripts/generateChangelog

scripts/generateChangelog.ts · 181 lines
Build

Generates 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

vand @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

scripts/parseDocsFromSource

scripts/parseDocsFromSource.ts · 207 lines
Build

Parses 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