This Site Is A Composition Of State Machines
Every interaction on this site — the scroll spy, the headings panel, the sidebar resize, the version-news tooltip, the copy-feedback flash, the keyboard navigation, the mermaid pan/zoom — is driven by one of ~40 pure state machines living under src/lib/ and wired to the DOM through adapters in src/app-shared.ts.
The diagram below proves it. It is generated at build time by walking the
TypeScript source with the compiler API, laying the result out with elkjs,
and inlining the resulting SVG straight into this page. No JavaScript is
required to see it: crawlers, RSS readers, the Firefox reader view, and
visitors with scripts disabled all see the same diagram, with every machine
name, adapter name and import edge readable as plain text.
When JavaScript is enabled, a tiny hydration adapter attaches click, hover and filter behaviour on top of the same SVG — selection, filtering and the detail panel are themselves driven by four new pure machines: explorer-selection-state, explorer-filter-state, explorer-detail-state and fsm-simulator-state. The explorer is, recursively, a composition of state machines.
Try it live. Double-click any machine node to open its own state diagram
in a popover, then click the green event buttons on the right to step
through the machine: the active state lights up, fireable transitions turn
green, history accumulates at the bottom. Reset replays from the initial
state. Drag to pan, scroll to zoom, Esc closes the popover.
How it works
scripts/extract-state-machines.tswalkssrc/lib/*.tswith the TypeScript Compiler API and extracts every exported state machine, its state union, and its public methods. It also walkssrc/app-shared.tsto find every adapter (IIFE module) and which machine factories it references, producing the directed import graph.scripts/render-state-machine-svg.tsloads the JSON, hands it toelkjsfor layered layout, then walks the result and emits a self-contained SVG fragment withdata-node-id/data-node-kind/data-edge-fromattributes on every element.scripts/lib/page-renderer.tsseesinclude: data/state-machines.svg.htmlin this page's frontmatter and substitutes the file's contents for the literal tokenabove. The SVG ships inside the static HTML.src/state-machines-explorer.tsruns in the browser, finds the inlined SVG, and attaches interactivity using four pure machines (explorer-selection-state,explorer-filter-state,explorer-detail-state,fsm-simulator-state) plus the existing pan/zoom logic fromsvg-viewport-state.tsand the modal primitives frommachine-popover-state.tsandpanel-events.ts. No third-party runtime libraries are loaded — every line of interactivity flows through the same compositional pattern as the rest of the site.src/lib/fsm-simulator-state.tsis the meta cherry: a state machine that replays other state machines. When you double-click a node,attachSimulatorreads the per-nodedata-node-transitionsattribute, hands the transition table to a freshFsmSimulatorMachine, and on everyonStateChangetick toggles.msd-state--activeon the current state bubble,.msd-transition-group--availableon the green arcs, and rebuilds the event button list. The same machine powers the unit tests undertest/unit/fsm-simulator-state.test.ts— there is no DOM code in the machine itself.