@canvist/web
The canvist editor for the browser. Every pixel of the document is painted on a canvas, but the browser measures the text, so the canvas wraps each line exactly where canvist’s server-rendered HTML does and hydrating moves nothing.
npm install @canvist/webimport { createEditor } from "@canvist/web";
const editor = await createEditor(document.querySelector("#editor")!, {
content: { format: "markdown", input: "Hello **world**" },
});
editor.select({ path: [0], offset: 0 }, { path: [0], offset: 5 });
editor.commands.toggleItalic();
editor.toHtml(); // what a server would send: { html, css }Using React or Vue? See @canvist/react and @canvist/vue. Rendering on a server? See @canvist/ssr.
What it does
- Editing like TipTap: typed commands and queries,
editable: falsefor read-only, aplaceholder, and menus that follow the selection from@canvist/web/menus(bubbleMenu,floatingMenu). - Collaboration:
@canvist/web/collabjoins a room on any y-websocket server withconnect(editor, { url, room }), with per-person undo. Its Yjs build is a separate module, so editors that don’t collaborate never download it.editor.caretRectAt(position)places other people’s carets. - Every extension:
createEditorfrom@canvist/web/fulltakes every extension canvist ships, from tables to math, in a larger module that StarterKit editors never download. - Server rendering: an element holding canvist’s server-rendered HTML hydrates without a layout shift.
- Small: 349.6 KB gzipped for the editor and the StarterKit, with a 350 KB budget CI enforces.
Types follow what you register
Commands, queries, and document JSON are typed from the extensions you pass, TipTap’s StarterKit by default. Plugins add their own API under editor.plugins:
import { bold, createEditor, heading } from "@canvist/web";
import { fonts } from "@canvist/web/fonts";
const editor = await createEditor(element, {
extensions: [bold, heading],
plugins: [fonts()],
});
editor.commands.setHeading({ level: 2 });
editor.commands.toggleItalic(); // type error: italic is not registered
await editor.plugins.fonts.local(); // installed fonts, where the browser allows itBuilt for real typing
- Fonts: installed fonts and the page’s web fonts work with no setup.
@canvist/web/fontsloads faces the way@font-facedoes and adds metric-compatible fallbacks, so a font swap barely moves anything. See Fonts and text rendering. - Input:
EditContextin Chromium and a hidden textarea elsewhere, so input methods, dictation, and autocorrect work as they do in a text field. See Text input on the web. - Accessibility: a visually hidden copy of the document lets screen readers read it, and every change runs an axe audit and screen reader smoke tests.
- Latency: every input event is painted in its own task, and
editor.inputLatency()reports how long that took.
Development
npm ci
npm run build:wasm # builds crates/canvist_web into wasm/
npx tsc --noEmit
npm test # unit tests in Node
npx playwright test # parity with server-rendered HTML, editing, and input latency in Chromium, Firefox, and WebKit
node scripts/parity-report.tsThe parity tests and their thresholds are described in Rendering parity.