Repository navigation
developer docs canvas and sync
This page describes the current protocol. See the data model for persisted fields and the user guide for controls.
The camera maps world coordinates into a viewport-sized Konva stage. Pan/zoom updates camera state, never the stored element coordinates. Zoom centers on the cursor; rendering culls distant content and reuses decoded images.
Element bounds are centered local coordinates with rotation. Lasso containment uses transformed footprints and selects only fully enclosed elements, including groups. Snapping uses configurable world units when moving/resizing. Insertion previews are outside the document until release; their initial bounds are minimal so they do not flash default-sized content. A click without dragging uses default dimensions. Pen strokes are collected into normalized local points.
Text input uses matching Konva/textarea font metrics and wrapping. Image crop rectangles are normalized against the original; display-resolution requests account for crop fraction, zoom, and display density. Smaller variants are generated only when useful below the 0.8 scale threshold, never by replacing/upscaling the original. Jobs are bounded and deduplicated, and existing decoded content can remain visible while a better variant is generated.
Completed edits are debounced by 750ms, with a maximum five-second interval during continuous activity, excluding unfinished gestures and network/upload delays. Each page has one save in flight; later edits are coalesced. Upload local image bytes separately before sending references in the page snapshot.
Every save sends baseRevision, clientId, epoch, mutationId, and the complete versioned document. In one transaction the server verifies current workspace edit access, editor lease/epoch, expected revision, payload limits, and target-workspace asset access. It commits the document, retained asset links, new revision, and receipt before publishing invalidations.
A repeated mutation ID with the same digest returns its original acknowledgment. Reusing it for different content is rejected. Receipt access is authorized even when the caller has lost editor control; stale expected revisions still prevent replay after receipt expiry. The client tracks local generations separately from server revisions, so acknowledging one save cannot mark subsequent edits as saved.
sequenceDiagram
participant Editor
participant API
participant SQLite
participant Viewer
Editor->>API: Snapshot + base revision + epoch + mutation ID
API->>SQLite: Validate and commit document/receipt
SQLite-->>API: New revision
API-->>Editor: Acknowledgment
API-->>Viewer: Saved-page invalidation
Viewer->>API: Fetch authoritative saved document
Leases are scoped to one page and a client within an authenticated session. The lease lasts 60 seconds and an active client renews about every 15 seconds. Client IDs are not credentials. Startup expires old holders and cancels pending requests; clients must revalidate.
Acquisition grants a free lease. An active holder requires a ten-second control request: the holder may accept/deny, the requester may cancel, and server operations finalize a due request automatically. A repeated request does not extend its deadline. Transfer rechecks the requester's account/session and edit permission, then replaces the holder and advances the epoch. Owner-only force cancels pending approval and transfers immediately; administrator status does not bypass ownership.
Save/control races serialize in the database. Saves after the request deadline or from a stale epoch are rejected. Notifications are not the correctness mechanism.
One authenticated SSE stream carries minimal invalidations, not document bodies or live gestures. Recipients follow current workspace access. Clients fetch authoritative state after events/reconnect and also poll for saved revision/control changes. A lost event cannot grant access or make a stale save valid.
Loaded pages may be edited in memory while disconnected. Ambiguous saves retry the same mutation before a new one is issued. Reconnection verifies revision and control. If control is lost or content diverged, keep dirty work as a separate recovery document, show the latest server document read-only, and offer creating a recovered page. Incoming saved content never overwrites that recovery copy. Local image bytes remain available while pending uploads/recovery need them.
No persistent browser offline store is used. Page sessions retain camera, undo/redo, and drafts while mounted in the workspace; leaving/reloading invokes unsaved-work protection. Browser crashes can still lose drafts.
#/workspaces/{workspaceId}/pages/{pageId} identifies the selected page. A workspace-only route selects its first page. Routes survive sign-in, enforce workspace/page membership, and preserve unsaved-work checks across browser history.
The server identifies its executable once at startup and embeds the identifier in HTML. Clients compare it with the public, no-store /api/v1/version response every minute and on foreground events. A mismatch offers explicit reload through the normal unsaved-work guard. Direct Vite development has no production marker and does not show deployment notices.