0xBUFF / docs

React player

Render compiled traces with controls, captions, keyboard navigation, and optional sound.

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.

ThroughlinePlayer displays a compiled Trace in React 19. The compiler works without React; import the player only when you need the interactive visualization.

Install and render

npm install @0xbuff/throughline@0.0.2 react@^19 react-dom@^19
import { compile } from "@0xbuff/throughline";
import { ThroughlinePlayer } from "@0xbuff/throughline/react";
import "@0xbuff/throughline/styles/throughline.css";

const trace = compile(
  'thl flow\nnode phase "Phase" = "queued"\nstep "Start"\nset phase = "running"',
);

export function Example() {
  return <ThroughlinePlayer trace={trace} />;
}

Import the stylesheet once in your application. Compile static sources outside a component or use useMemo for changing inputs. A new trace object resets playback to frame zero.

Props

PropTypeDefaultPurpose
traceTraceRequiredCompiled frames to display
classNamestringNoneClass on the root .thl element
theme"light" | "dark" | "auto""auto"Player color scheme
sonificationSonificationOptionsOmittedInclude an optional sound toggle

The player accepts a Trace, not source text. It does not provide controlled-step or step-change callback props in v0.0.2.

Playback

The player starts paused at frame zero, at 1× speed. It includes step-back, play/pause or replay, step-forward, a timeline, speed selection (0.5×, 1×, 2×), and an expandable Inspect state panel. At 1×, it advances approximately every 1.5 seconds.

Keyboard shortcuts work when the Visualization player group itself has focus, not when a child control is focused:

KeyAction
Left / Right arrowPrevious / next frame
Home / EndFirst / last frame
SpacePlay or pause

Manual seeking pauses playback. Controls that cannot move beyond the available frames are disabled.

Accessibility

The player provides semantic buttons, a labeled timeline, a frame summary for screen readers, captions, an accessible SVG name, and a text-based state inspector. It respects reduced-motion preferences and adapts to its container width.

The scene may shorten long values to fit; Inspect state exposes their complete JSON values for visible nodes. See Accessibility for assistive-technology and customization considerations.

Themes and sound

Pass theme="light", theme="dark", or theme="auto". You can customize colors by overriding the published --thl-* CSS properties on the player root:

<ThroughlinePlayer trace={trace} className="lesson-trace" theme="dark" />

See Styling and themes for token names and examples.

Sound is off and unavailable by default. Supplying sonification exposes a toggle:

<ThroughlinePlayer trace={trace} sonification={{ enabled: false }} />

Set enabled: true to start with sound enabled, or use onTone for a custom callback:

<ThroughlinePlayer
  trace={trace}
  sonification={{
    onTone(event) {
      console.log(event.step, event.total, event.frequency, event.durationMs);
    },
  }}
/>

Sound is presentation feedback; it does not alter trace data. An omitted sonification prop removes the sound control entirely.

Server rendering

The player supports React SSR and hydration. Browser measurements and sound run after mounting, while frame compilation and reading remain framework independent. In frameworks with server and client components, render the player inside the appropriate client boundary.

For application-specific setup, see Frameworks.

On this page