Search page titles, headings and text across the docs.

Reference

On this page

Browser API reference

Use this page to look up every option and method of the browser packages: @canvist/web and its /fonts, /menus, and /collab entry points, @canvist/headless/ssr, and @canvist/canvas. Each one also carries these descriptions in its TypeScript declarations, so your editor shows them on hover.

API stability

The browser packages follow semantic versioning with the rest of the SDK. Every change ships with a changeset that says what changed, and the changelog lists them. Until 1.0, a release that breaks an API raises the minor version (0.1 to 0.2) and says so under “Breaking Change”. Members marked @internal in the declarations aren’t part of the API and can change in any release.

createEditor(element, options)

From @canvist/web. It returns a promise of an Editor. @canvist/web/collab exports a createEditor with the same options, and its editors can collaborate.

OptionTypeDefaultWhat it does
extensionsExtensionDescriptor[]TipTap’s StarterKitThe extensions to register. Commands, queries, and document JSON are typed from them.
pluginsPlugin[][]Plugins such as fonts() from @canvist/web/fonts. Their APIs are on editor.plugins.
content{ format, input } or ProseMirror JSONthe element’s HTMLThe starting document. Without it, the editor reads server-rendered .cv-doc HTML inside the element, or starts empty.
themeThemeOptionsStarterKit lightscheme, bodyFamily, codeFamily, size, lineHeight, and letterSpacing. Server rendering must use the same one.
editablebooleantruefalse makes the editor read-only: selecting and copying still work, and commands still apply.
placeholderstring""Dimmed text where the first line starts while the document is empty. It’s also the field’s aria-placeholder.
labelstring"Editor"The editor’s accessible name.
input"auto", "editcontext", "textarea""auto"How text arrives: EditContext where the browser has it, or a hidden textarea. "textarea" is the kill switch for EditContext problems.
platform"apple", "other"detectedWhether Mod in key bindings is Cmd or Ctrl.
breaks"chromium", "icu"detectedWhich line-breaking tailoring layout follows, to match the browser’s own.
clientnumber1The client id new blocks are allocated under.
overscannumberone screenPixels beyond the viewport to lay out ahead of scrolling.
wasmWasmSourcenext to the moduleWhere to load the WebAssembly module from: bytes, a compiled module, a URL, or a response.

Editor

MemberWhat it does
commands.<name>(args), can.<name>(args)Run a registered command, or check whether it would apply. Both return boolean.
query.<name>(args)Answer a registered query.
run(name, args), ask(name, args)The same, for names picked at runtime.
select(anchor, head?), selectionSet or read the selection. Positions are { path, offset }, with offsets in UTF-16 code units.
insertText(text), undo(), redo()Type, undo, and redo, as the keyboard does. A shared editor undoes only its own changes.
setContent(content), export(format), toJson()Replace the document, or read it as json, html, markdown, or text.
toHtml(), toSvg()Server-rendered HTML and CSS at the editor’s width, or an SVG of the whole document.
editable, setEditable(editable)Read or change read-only mode.
setPlaceholder(text), isEmptyChange the placeholder, or check for an empty document.
focus(), focusedFocus the editor without scrolling, or check whether it has focus.
subscribe(listener)Call back after every change to the document, the selection, focus, or editable. Returns an unsubscribe function.
caretRect(), selectionRect(), toClientRect(rect)The caret’s or selection’s rectangle in document coordinates, and conversion to viewport coordinates.
blockText()The text of the block holding the selection’s head.
ready(), hydratingWait until fonts and plugins have settled and the canvas shows, or check whether server HTML still stands in.
inputLatency(), stats(), fonts(), geometry()Input-to-paint times, measurement cache statistics, used fonts, and laid-out geometry.
render(), destroy()Paint now, or remove the editor and release its memory.

@canvist/web/menus

bubbleMenu(editor, element, options) keeps element over selected text, and floatingMenu(editor, element, options) keeps it beside the caret on an empty line. Both return a Menu with visible, update(), and destroy().

OptionTypeDefaultWhat it does
placement"top", "bottom", "left", "right""top" (bubble), "left" (floating)The preferred side. The menu flips when there’s no room.
offsetnumber8The gap between the menu and the selection, in CSS pixels.
paddingnumber8The least distance from the viewport’s edges.
shouldShow(editor) => booleansee each functionReplaces the default rule for when the menu shows.

placeMenu(element, rect, { placement, offset, padding }) does the positioning on its own.

@canvist/web/collab

connect(editor, options) joins an editor from this module’s createEditor to a room, and returns a Connection. The connection has status ("connecting", "connected", or "disconnected"), synced, clientId, subscribe(listener), whenSynced(), and disconnect().

OptionTypeDefaultWhat it does
urlstring(required)The y-websocket server’s URL. The room is added as a path.
roomstring(required)Every peer in a room edits one document.
paramsRecord<string, string>noneQuery parameters, such as a short-lived token.
clientIdnumberrandomThis peer’s Yjs client id, unique in the room.
reconnectbooleantrueReconnect with backoff when the connection drops.
WebSockettypeof WebSocketthe globalThe WebSocket class to use.

@canvist/headless/ssr

createRenderer({ extensions, theme, fonts, wasm }) returns a Renderer: html(content, { width }) returns { html, css }, page(content, { width }) returns a complete page, svg(content, { width }) returns an SVG, and registerFont(bytes) adds a font for SVG text. fonts are TrueType or OpenType files. See Server-side rendering.

@canvist/canvas

mountCanvas(canvas, options) returns a CanvasHandle with backend, tools, setTool(name), tool(), toJson(), encodeState(), applyUpdate(update), frameTimes(), requestFrame(), and destroy().

OptionTypeDefaultWhat it does
sceneSceneJsonone empty pageThe starting scene. Give every peer in a room the same one.
demobooleanfalseStart from canvist’s demo scene instead.
transportTransportnoneWhere collaboration messages go, such as BroadcastTransport.
preferGpubooleantrueUse WebGPU where the browser has it.
wasmUrlURL or stringnext to the moduleWhere the WebAssembly module is.
onChange(handle) => voidnoneCalled after the canvas changes, for toolbars.
stressnumber0Extra rectangles, for measuring frame times.
Docs