@arena.ai/faster-latex-dom
v0.2.1
Published
Framework-neutral DOM controller for faster-latex: WASM loading, worker lifecycle, incremental block patching, deduplicated styles, and server-side render-to-string.
Maintainers
Readme
@arena.ai/faster-latex-dom
Framework-neutral DOM controller for @arena.ai/faster-latex.
It owns everything a live LaTeX preview needs so a framework adapter (see
@arena.ai/faster-latex-react) can be a thin
shell:
- WASM loading + worker lifecycle, with an automatic main-thread fallback.
- Incremental block patching — applies the engine's per-keystroke splice to
the host's children instead of reassigning
innerHTML, so the browser relays out one block, not the whole document. - Resynchronisation — if a patch cannot be applied (the host DOM diverged), it forces a full repaint rather than corrupting the tree.
- Deduplicated styles and observable render state.
import { createRenderer } from "@arena.ai/faster-latex-dom";
const renderer = createRenderer(document.getElementById("preview"), {
execution: "auto", // "auto" (worker, falling back to main) | "worker" | "main"
options: { packages: shimMap },
});
renderer.subscribe((state) => {
// state: { status, version, warnings, packages, total, error, execution }
});
textarea.addEventListener("input", () => renderer.update(textarea.value));
// on teardown:
renderer.dispose();The controller owns the host's children — never render into the host yourself.
API
createRenderer(host, config?) → Renderer
config.execution—"auto"(default),"worker", or"main".config.options— faster-latexRenderOptions, set once (not per keystroke).config.styles—"auto"(default, installs the deduplicated article stylesheet) or"none".config.styleTarget— where"auto"styles go (default: the host's root node, so shadow-DOM hosts are styled correctly).config.onPatch(nodes, { full })— post-paint hook (e.g. dark-mode colour adaptation) called with the freshly inserted top-level elements.config.loadWorkerSession/config.loadEngine— override the default@arena.ai/faster-latex/worker/@arena.ai/faster-latex/webloaders (pinned build, CDN, mock).
Renderer: update(source), reset(), subscribe(fn) → off, getState(),
dispose().
CSP / SSR: static stylesheet
For applications that install CSS out of band (a strict Content-Security-Policy, or server-side rendering), the article stylesheet is exported as a static string — no engine initialisation required:
import { articleStylesheet } from "@arena.ai/faster-latex-dom/styles";License
Apache-2.0
