0010. One canvas engine for lecture boards and whiteboards
- Status: Accepted
- Date: 2026-10-05 (recorded with
@nextgensoftwares/folio-canvas)
Context
Two products want a freeform surface. A lecture board is ink-first: a stylus or a smart board, bounded pages, recorded with voice and replayed stroke by stroke. A whiteboard (FigJam/Miro style) is object-first: an infinite canvas of stickies, shapes, text, connectors, frames and images, driven by mouse and keyboard as much as by pen. Both need the same hard parts: device input (pen/touch/palm/smart board), camera, live collaboration, undo, recording and export. Two engines would double that work and drift apart.
Decision
One scene model, @nextgensoftwares/folio-canvas, with presets on top.
- Everything is an object on a page:
stroke,sticky,shape,text,connector,frame,image; hosts register more kinds with a renderer. Common fields:id,kind,x,y,w,h,rotation,z. - Stacking order is a fractional index (
z, a sortable string). Inserting between two objects never renumbers others, so concurrent edits from peers converge on the same order without index arithmetic. - Edits are field-level operations:
create,update(a patch of fields),delete, grouped atomically bybatch. Each has an exact inverse computed against current state, which gives per-user undo and maps one to one onto attribute steps, so fields merge last-writer-wins in server order. - Collaboration is Folio's one collaboration stack, not a canvas-only sync (
@nextgensoftwares/folio-canvas-collab, revised 2026-10-20): a board is a shared document ofcanvasPage/canvasObjectnodes, each field its own attribute, so board edits travel as steps throughfolio-plugin-collab,folio-syncandfolio-server-nodewith the same server verification, roles, comments and storage as documents and decks. Strokes and laser trails in flight, and pointers, ride presence. Undo stays the board's own per-user history: an undo is a fresh local edit, so it syncs like any other. - The store's events are still one stream for rendering and recording: local and remote edits alike land on it, and a recording timestamps it. Strokes carry per-point time, so playback redraws ink as it was written; every other object appears at its creation time.
- Text is laid out by Folio's own layout (continuous mode, injected
TextMeasurer), so stickies and text boxes get bidi and Arabic shaping that match exports, and the core stays DOM-free. @nextgensoftwares/folio-inkkeeps the pure ink maths (outline, simplification, splitting for the partial eraser, point codec);@nextgensoftwares/folio-canvas-boardis the browser layer.
Consequences
- A lecture board is a whiteboard preset (bounded pages, ink tools, recording), not a fork; features land once.
- Object coordinates are page units; strokes store points relative to their object box, so moving or resizing a stroke is a field update, never a rewrite of its points.
- One collaboration engine for every document type: docs, decks and boards differ only in their binding (schema and conversion), and a server built with their schemas stores all three.
- Field-level LWW is not a text CRDT: two people typing in the same sticky at once keep the last write. Rich concurrent text editing inside an object is a later step (embed a Folio editor document per text object).