@texuli/canvas
v0.18.0
Published
Infinite canvas for Texuli: a framework-free canvas model (shapes, text, connectors, frames, transforms, snapping, an op log with undo), CRDT sync on @texuli/document/sync, an accessible Svelte 5 editor and viewer, and SVG and PNG export.
Maintainers
Readme
@texuli/canvas
An infinite canvas for Texuli,
an MIT-licensed Svelte 5 component library by Dailybot, Inc. (Small
pieces. Infinite possibilities.). Shapes, text, sticky notes, images,
frames and groups, connectors that route straight, elbow or curved,
selection, transforms with snapping and guides, alignment, z-order, a JSON
clipboard and undo through an op log, all in a framework-free model; CRDT
collaboration on @texuli/document/sync; an accessible Svelte 5 editor and
viewer; and SVG and PNG export with no HTML sinks.
In the stack: layer L4, a domain package on the @texuli/core texels, @texuli/drag, @texuli/document (sync), @texuli/deck and the texuli components. The player paints it through its canvasHost seam.
Status: in development (pre-1.0).
@texuli/canvasis published on npm as0.18.0, with provenance (first published as0.8.0; built in PLAN_010). Under 0.x a new minor (0.18.0) may contain breaking changes, so pin the exact version or use^0.18.0, which accepts only 0.18.x (see RELEASE). Agents emit canvases as data through thecanvascatalog id of blueprint spec0.8.0; the Kotlin twin validates them and does not paint them yet.
It sits on layer L4. It depends on @texuli/core (URL policy, markup
builders, motion, announcer), @texuli/deck (the schema kit),
@texuli/document (only the sync subpath, the CRDT core of ADR-010),
@texuli/drag (pan, zoom, snapping, resize and the edge curve shared with
@texuli/workflows) and texuli (the motion settings); svelte
(^5.57.2) is a peer dependency.
Install
npm install @texuli/canvasIn the Texuli workspace, depend on it as "@texuli/canvas": "workspace:*".
It has no third-party runtime dependencies; its @texuli/* and texuli
dependencies come with it. Import the token stylesheet once
(@texuli/tokens/base.css).
Quick start
<script lang="ts">
import { CanvasEditor } from '@texuli/canvas/editor';
import { loadUntrustedCanvas } from '@texuli/canvas/model';
import '@texuli/tokens/base.css';
let { json }: { json: string } = $props();
// Canvases from a file, an agent or a share link: validated first.
const loaded = loadUntrustedCanvas(json);
let canvas = $state.raw(loaded.ok ? loaded.canvas : null);
</script>
{#if canvas}
<CanvasEditor bind:canvas resolveImage={(ref) => `https://cdn.example.com/${ref}.png`} />
{/if}Subpaths
| Subpath | What it holds | Docs |
| --- | --- | --- |
| . | The model, the editor and the viewer, re-exported, and CANVAS_PACKAGE_VERSION | this page |
| ./model | Framework-free and DOM-free: the format, validateCanvas and loadUntrustedCanvas (untrusted by default), the JSON Schema spec 0.8.0 pins, bounds, hit testing and reading order, connector routing, freehand simplification, typed operations with inverses, the op-log history, and editing helpers that return operations | model |
| ./sync | Collaboration on @texuli/document/sync: the tree, register and sequence binding, a projection that is always valid, seed operations, sessions and presence (pointers and selections) | sync |
| ./export | canvasToSvg (escaped markup through @texuli/core/markup) and canvasToPng (browser) | export |
| ./editor | CanvasEditor and its parts: the toolbar, the role="application" surface, the minimap and the shape tree, over CanvasController; the keyboard model | editor |
| ./viewer | CanvasViewer: a read-only canvas with its structure as text | viewer |
| ./host | createCanvasPlayerHost: the canvasHost of @texuli/player for agent canvases | host |
CANVAS_PACKAGE_VERSION equals the package version (0.18.0).
Security
- Canvases are data.
validateCanvasrefuses unknown shapes and keys, raw CSS colors (styles are a closed token palette), control and bidi characters in text, image refs with a scheme that the URL policy refuses at the tier, unknown connector ends, and anything pastCANVAS_LIMITS, in time linear in the input. - Text paints as SVG text nodes; nothing is parsed as markup (
{@html},innerHTML,evalandnew Functionare absent). Image refs are resolved by the host and every URL passessafeImageSrcat the tier (untrustedby default). - The clipboard is untrusted JSON: size-checked, then validated.
- Remote sync batches are validated by the sync core, and the projection drops what fails the canvas schema, the same way on every replica.
Accessibility
The surface is the only role="application" region, named by the canvas
title and described by its keyboard instructions. Shapes take a roving tab
stop in reading order; the shape tree beside it (role="tree") lists every
shape and connector for screen readers; changes are announced through the
shared live region. Motion (zoom and fit) plays through texuli/motion
and is instant under reduced motion. Forced colors keep outlines, focus and
selection visible. The keyboard model is in
editor.
Contributing
Contributions are welcome; start at the GitHub repository (issues: github.com/DailybotHQ/texuli/issues).
License
MIT © Dailybot, Inc. Powered by Dailybot.
