API reference (Core)
The full Core surface. It flags the methods that look callable but are
stubs.
VFS
| method | notes |
|---|---|
create(path, mime, data) | add a file. data is string or Uint8Array. mime for Typst is text/x-typst. |
edit(path, edits) | apply { range: { start, end }, replacement }[] - UTF-8 byte offsets. |
move(from, to, mime?) | rename/move a file. |
delete(path) | remove a file. |
clear() | wipe the VFS. |
After the main file is set, any create/edit/move/delete to it or a
dependency triggers a recompile automatically.
Compile & layout
| method | notes |
|---|---|
setMain(path, silent?) | set the document root; triggers the first compile. |
setTarget(target) | 'pdf' | 'svg' | 'png' | 'html' | 'none'. Independent of the canvas path - use 'svg' for a canvas-only preview. |
Notifications
on(name, fn) returns an unsubscribe function. Convenience wrappers:
onPages, onDiagnostics, onStatus, onOutline.
| channel | payload | notes |
|---|---|---|
pages | { pages: PageInfo[] } | fires on every layout change. PageInfo = { width, height } in points. |
diagnostics | { diagnostics: Diagnostic[] } | errors + warnings; spelling uses a 'misspelling' severity. |
status | { status: 'ok'|'busy'|'error'|'crashed', message? } | |
outline | { entries: OutlineEntry[] } | heading outline; position.page is 0-based. See Rendering. |
Render & export
| method | notes |
|---|---|
render(index, zoom) | returns { data: Uint8ClampedArray, width } for one page. |
export(args) | typed ExportArgs union -> { data, mime }. See Rendering. |
ExportArgs:
PdfStandard is a version string ('1.4'..'2.0') or a conformance level
('a-1b', 'a-2b', ..., 'a-4', 'ua-1'). See Rendering.
IDE features
| method | notes |
|---|---|
tags() | highlight tag table (typ-strong, typ-emph, ...). Used by the editor bindings. |
highlight(path) | flat Uint32Array of [start, end, tagIndex] triples. |
autocomplete(path, cursor, explicit?) | { from, completions } or null. |
tooltip(path, cursor, side?) | { html } or null. |
definition(path, cursor, side?) | source location or null. |
jumpFromCursor(path, cursor) | source -> preview positions. |
jumpFromClick({ index, x, y }) | preview click -> source/url/position. |
syntaxTree(path) | raw parse tree. |
configureSpellCheck(enabled, dict?) | toggles the feature; the actual check is delegated to JS - see CodeMirror spellcheck. |
Fonts & packages
addFont, addFonts, addFontStubs (Fonts); setRemotePackages
(Packages).
Lifecycle
| method | notes |
|---|---|
destroy() | tear down the worker. |
revive() | rebuild the worker and replay all stateful ops (files, fonts, target, main) and re-subscribe. Use after a 'crashed' status. |
Not implemented (these throw / no-op - don't build on them)
| method | behavior |
|---|---|
eval(expr) | throws eval not implemented. |
archive('zip') | throws archive not implemented. |
references(...) | returns null. |
| font index decoder | JSON only. |