Canvas

An infinite canvas: pan and zoom, shapes, selection with resize and rotate handles, smart guides, drawing tools, cursors and comment pins.

Small steps, every day

Track three habits and watch your streaks grow.

Get started

Onboarding / 1 Welcome
Nothing selected

Installation

pnpm dlx shadcn@latest add checkfu/uicontext/canvas-viewport

Usage

import { answerCanvas, type CanvasState } from "./ui/uicontext/components/canvas/Editor.ts"import { CanvasViewport, CanvasViewportEvents } from "./ui/uicontext/components/canvas/Viewport.ts"
const Message = UiSchema.TaggedEnum({ RequestedCanvas: { event: CanvasViewportEvents } })// The app keeps the scene, the selection and the tool; `answerCanvas` applies each request with undo.export const Board = (h: Html.H<typeof Message.Type>, canvas: CanvasState) =>	CanvasViewport(h, {		props: { label: "Flows", shapes: canvas.shapes, selection: canvas.selection, tool: "select" },		onEmit: (event) => Message.RequestedCanvas({ event }),	})export const reduce = (canvas: CanvasState, event: typeof CanvasViewportEvents.Type) => answerCanvas(canvas, event, "shape")

Examples

A whiteboard

Notes, ink, shapes and connectors with the board's tools, and a minimap.

Release train left on time

Pairing on the importer

Fewer pages at night

Went well
Nothing selected

Review with others

Collaborators' cursors and selections, comment pins, and a canvas that only views and comments.

Small steps, every day

Track three habits and watch your streaks grow.

Get started

Onboarding / 1 Welcome
Priya
Tom
Nothing selected

API reference

Props

CanvasViewport props
NameTypeDefaultDescription
labelrequiredstring—The canvas's accessible name: "Habit app — v2, Flows"
shapesrequiredShape[]——
selectionrequiredstring[]——
toolrequiredCanvasTool——
modeCanvasMode—Design edits; prototype draws and links wires; inspect only selects and measures
canCan(["edit", "comment"])—Edit and comment by default; leave "edit" out for view and comment only
peersCanvasPeer[]——
pinsCanvasPin[]——
activePinstring | null—The open pin: drawn raised
wiresCanvasWire[]——
drawStyleDrawStyle—The style new shapes take; design defaults when absent
background"dots" | "plain"——
snapbooleanonSnap to edges, centres and equal gaps while moving and resizing; on by default
minimapboolean——
revealstring | null—Fit a shape (its id) or everything ("all") into view. Each new value moves the camera once; add a suffix after a colon ("home:2") to ask again for the same shape.
reportPointerboolean—Report MovedPointer for presence
idPrefixstring—Prefix for the ids of new shapes
agentIdstring——

Events

CanvasViewport events
EventPayloadDescription
RequestedSelect{ ids: string[] }Select these shapes, in order (empty clears)
RequestedChange{ changes: CanvasChangeSchema[]; group?: string }Apply these changes as one undo step; edits sharing a group (a burst of nudges) may merge
RequestedCommand{ command: CanvasCommand }—
RequestedTool{ tool: CanvasTool }—
RequestedUndo{}—
RequestedRedo{}—
RequestedComment{ x: number; y: number; shape: string | null }Start a comment thread at a world point, on the shape there if any
RequestedOpenPin{ id: string }—
RequestedLink{ from: string; to: string }Link a prototype hotspot to a frame
MovedPointer{ x: number; y: number }Where the pointer is, for presence; only with reportPointer
LeftPointer{}—
MovedCamera{ camera: Camera }The camera settled after a pan or zoom

Agent actions

What agents can do with CanvasViewport
ActionDescription
PickedShapesSelect shapes by id (an empty list clears the selection)
PickedCommandRun a command on the selection: delete, duplicate, group, ungroup, frame, forward, backward, front, back, hide, lock, flip-x, flip-y
AddedShapeAdd a shape: kind is frame, rect, ellipse, text, sticky; x, y, w, h in canvas units; text for text and sticky notes; parent is a frame id
NudgedSelectionMove the selection by dx, dy canvas units
PickedZoomZoom: in, out, fit (everything), selection, or a factor such as 1 for 100%

Source