Use Throughline in applications
Compile visualizations at build time or runtime and display them in your application.
Version scope — v0.0.2 (historical schema 1). This page and its examples use @0xbuff/throughline@0.0.2, the version pinned by this documentation app. They do not describe the unreleased schema-2 API intended for v0.2.0. See compatibility and upgrading.
Throughline compiles one trace block at a time. Your host application decides where blocks come from and how to display the results.
Choose an approach
| Use case | Recommended approach |
|---|---|
| Documentation or lessons | Extract thl fences and validate them when content is built |
| React application | Compile the source and pass a stable Trace to ThroughlinePlayer |
| Interactive editor | Compile submitted input, catch ProgramError, and show diagnostics |
| CLI or content pipeline | Import only the core compiler; read or serialize Trace data |
| Non-React UI | Read the trace frames and supply your own renderer |
See Markdown and MDX for code-fence processing and Frameworks for specific hosts.
Compile extracted Markdown
A Markdown parser should identify the fence and domain. Pass the extracted block to compileAst, retaining its source line for useful errors:
import { compileAst, ProgramError } from "@0xbuff/throughline";
try {
const trace = compileAst({
kind: "flow",
lines: ['node n "Number" = 0', 'step "Set"', "set n = 1"],
source: { line: 12 },
});
console.log(trace.frames.length);
} catch (error) {
if (error instanceof ProgramError) {
console.error(error.diagnostics);
} else {
throw error;
}
}Do not pass an entire Markdown article to compile(). If a host already parses the document, use its code nodes instead of searching raw text for fences.
Choose when to compile
Build time is usually best for published content: a malformed trace fails the content build instead of breaking a reader's page. The generated trace can be serialized for later rendering.
Runtime is appropriate for interactive input. Catch validation errors outside the player, avoid compiling unchanged sources on every render, and apply the host's own resource controls.
Throughline does not execute authored JavaScript, fetch content, or store traces. Labels and notes should be rendered as text. For diagnostic messages and resource ceilings, see Errors and limits.