Draft Preview — Not Published: This preview page is excluded from the public Knowledge Hub index, RSS feed, search index, and sitemap.
· 10 min read

The Composition Tax — Continuous Animation Meets Discrete State, and Nobody Talks About It

Every interactive animated tool faces the same hidden cost — composing per-frame animation with edge-triggered state transitions. Most tools handle one side well and bolt the other on as an afterthought. Here's the problem named, why it's harder than it looks, and what we tried in PinePaper.

Scope note: this post is about a canvas-rendering tool. If you're building an HTML widget with no continuous canvas animation, the right answer is plain HTML with ARIA — that's not the problem PinePaper is trying to solve. The composition described below only becomes interesting when you actually need per-frame canvas rendering to coexist with discrete interactive state.

The Hidden Cost

Imagine the demo. A solar system on a canvas. Three tabs across the top — Mercury, Venus, Earth. Click Earth: a panel reveals, the Earth orbits its sun at one rotation per six seconds. Click Mercury. Earth's panel hides, Mercury's reveals, and there's Mercury — already mid-orbit at four times Earth's speed, because its orbit relation has been computing the whole time, just hidden.

Now write that scene in your favorite tool.

In Rive, you'd express the orbits as a state machine with a Time input driving rotation — that works, but stacking a separate tablist state machine on top, where the tabs themselves are interactive and the panels reveal/conceal, requires a second state graph plus carefully-named exit transitions. Rive's state machine is good at one continuous behavior with discrete transitions between named states; it's awkward at composing a continuous orbit with an unrelated discrete interaction.

In Lottie, you'd export the orbits as keyframes. There is no state, so the tabs would have to live outside Lottie — a host page with a player and click handlers and visibility logic in JavaScript. Two languages, one for animation, one for state.

In React with Framer Motion, you'd write the tab state in React, the orbit animation in Framer Motion or CSS, the panel visibility via conditional rendering — and discover that "the orbit has to keep computing while the panel is hidden" requires either a Web Worker, an offscreen canvas, or a clever ref-based animator outside React's reconciliation cycle, because unmounting a component generally stops its animation. Three layers, manually composed.

In hand-rolled HTML+Canvas, you write all four parts (orbit RAF loop, tab click handlers, panel visibility, animation continuity across visibility) and it works. Most senior engineers can do this in an afternoon. But every part is bespoke per scene; nothing carries over to the next interactive animation you build.

The pattern across all four: per-frame continuous animation lives in one place; discrete state transitions live in another; the composition is the part the tool doesn't help with.

This is the composition tax. It's unstated in most tool comparisons because each tool optimizes for one side — animation tools for continuous, UI frameworks for state — and the composition is what you do after picking the tool.

What "Composition" Actually Means

Two operations have to compose cleanly:

  1. Continuous — per-frame procedural updates. Examples: position.x += speed * dt (orbit), opacity = 0.5 + 0.5 * sin(t) (pulse), particle physics, follows-relations, wiggles, simulations.
  2. Edge — discrete events at moments in time. Examples: click, keypress, pointer-enter, "tab activated," "tween finished," "counter passed threshold."

Composition means an edge event can affect a continuous behavior (slowing an orbit when paused), a continuous behavior can produce edge events (a counter incrementing past a threshold fires a transition), and both states are visible at the same instant. The graph of who-depends-on-what is real, not implicit.

The standard tools don't make this composition explicit. They give you a "state machine" with continuous animations as states and discrete transitions between them — a useful pattern, but it forces all continuous behavior into the state hierarchy. An orbit that should keep running regardless of which tab is active doesn't have a clean home; it lives at the root state and the state machine becomes a sibling of it, not a parent.

What you actually want is two independent layers — a continuous evaluator running every per-frame relation regardless of state, and an edge dispatcher firing on transitions — composed so they can refer to each other's outputs.

What We Tried

PinePaper started with continuous relations only — about twenty-five types covering spatial behaviors (orbits, follows, maintains_distance), procedural noise (wiggle, time_expression), parent-child rigging (bone_attached, part_of). Authors wrote one declarative line per behavior; the runtime evaluated each relation every frame. That worked for animations but had nothing to say about interactivity, which still had to be bolted on in JavaScript outside the graph.

In May 2026 we added a second relation family — event-channel relations — that handle the discrete side in the same graph:

  • A new addressable item type, pp:Event, that acts as a pulse channel. No visual content, just a routing target.
  • Pointer / keyboard producers — on_click_fire(button, eventChannel), on_key_fire(item, eventChannel, {key: 'Enter'}), on_pointer_enter_fire, on_pointer_exit_fire. When the source receives the input, pulse the target channel.
  • Event reactions — on_event_set_property, on_event_set_visibility, on_event_increment, on_event_toggle, on_event_set_active. When the channel pulses, the reaction applies a side effect to a target item.
  • exclusive_group — pairwise mutex. Members share an _isActive slot.
  • on_enter_* / on_exit_* — edge-triggered side effects fired when an exclusive_group member transitions active state.

Same registry. Same runtime. The continuous evaluator processes per-frame relations every render; the edge dispatcher processes event pulses in a frame-coherent queue drained once per frame before the per-frame callbacks. Both layers see the same items and the same state.

The Solar System scene's behavior in this language:

// Mutex covering the three tab buttons (pairwise edges form the group).
addRelation(tab_a, tab_b, 'exclusive_group', { groupName: 'planets' });
addRelation(tab_b, tab_c, 'exclusive_group', { groupName: 'planets' });

// Click fires each tab's event; the event activates the source tab.
// Mutex deactivates the others. on_enter / on_exit reveal / hide panels.
for (let i = 0; i < 3; i++) {
  addRelation(tabs[i], events[i], 'on_click_fire');
  addRelation(events[i], tabs[i], 'on_event_set_active');
  addRelation(tabs[i], panels[i], 'on_enter_set_visibility', { visible: true });
  addRelation(tabs[i], panels[i], 'on_exit_set_visibility',  { visible: false });
}

// And the orbiting planets — continuous, every frame, irrespective of which tab is active.
addRelation(planet_a, sun_a, 'orbits', { radius: 55,  speed: 0.62 });
addRelation(planet_b, sun_b, 'orbits', { radius: 90,  speed: 0.24 });
addRelation(planet_c, sun_c, 'orbits', { radius: 130, speed: 0.15 });

The interesting part is that the orbits relations don't know or care about the tab state machine. They evaluate every frame regardless. When you switch from Earth's tab to Mercury's, Earth's orbit keeps computing — its position advances during the seconds the panel is hidden — and when you flip back, Earth is exactly where physics says it should be, not reset to where you left it.

That phase continuity isn't a feature we added. It's what happens when continuous evaluation isn't gated by state.

Other Things This Composition Buys

Beyond the Solar System demo, the same composition handles things that are awkward in the standard split:

Idle behavior under interactive control. A rigged character breathes (continuous bone animation) and walks (continuous pose cycle on a tween) — both run in the relation graph. Arrow keys fire on_key_fire(stage, walk_event, {key: 'ArrowRight'}). The walk event activates a "walking" state in the rig; the breathing keeps going underneath. No special state hierarchy. The continuous and the edge-driven coexist as siblings, not as nested layers.

Continuous feedback for discrete events. A counter increments on every click via on_event_increment(click_event, counter). A meter's fill ratio is a continuous binding: addRelation(counter, meter, 'driven_by', { property: 'value', map: x => x / 100 }). Click → counter advances by 1 (discrete) → meter's fill follows continuously every frame, even though the underlying value only changed once. The discrete event drives the continuous animation; both live in the graph.

Particles that respond to state. Particles emit continuously from an item via a generator. Clicking the item pulses an event that fires a burst (different particle parameters for one beat). The burst runs in parallel with the continuous emission; they don't conflict because the burst is a transient overlay, not a state change.

The pattern: continuous behaviors persist regardless of state, edge events trigger discrete effects without halting the continuous layer, and both refer to the same items.

The Costs, Honestly

Three real tradeoffs the architecture makes:

Continuous + edge composition has surprises. An orbits relation runs every frame on an item even when the item is hidden. That's correct behavior — the planet keeps its phase across reveals — but it's a CPU cost. We don't yet stop computation for hidden subtrees. A scene with thirty hidden animated items pays for all thirty. Future optimization, not a current blocker.

The frame-coherent event queue adds one frame of latency. A pulse from setActive doesn't fire its listeners until the next render. For 60Hz this is 16ms — imperceptible — but if you chain six pulses each one queues into the next frame, so the visible state takes ~100ms to settle. We chose this over synchronous dispatch because deterministic ordering matters more than immediacy for state-machine semantics. Other tools (Rive, for instance) make the opposite tradeoff.

Graphs require thinking in graphs. The relation language is unfamiliar to authors who haven't internalized declarative graphs — "the meter is driven_by the counter" is a sentence about a binding, not a function call. The mental model is closer to Excel formulas than to imperative JS. For some authors that's natural; for others it's friction. We don't have a fix for that besides documentation and template-by-example learning.

What This Isn't

This post is not selling a replacement for HTML+ARIA widgets — for tab UIs in plain web apps, plain HTML with proper ARIA attributes is shorter, has zero runtime dependency, and ships in every browser. PinePaper's relation graph becomes interesting only when you actually need canvas rendering: animated charts, illustrated explainables, game-like UIs, scrollytelling, character rigs, generative backgrounds. If your scene doesn't have a continuous canvas component, the standard web stack is the right tool.

This post is also not claiming the graph approach is general across every interactive-animation problem. It's claiming specifically that composing continuous animation with discrete state in one declarative source is a real architectural problem nobody talks about, and the relation graph is one way to address it. Other tools have made other choices — Rive's state-machine-first posture, Lottie's animation-only posture, Framer Motion's React-integrated posture. Each has its own composition story; ours is "the graph is the single source for both."

The win is narrow. The Solar System demo isn't impressive because the tabs work — tabs work in HTML. It's impressive because the orbits keep computing across tab transitions without the author writing any code to make that happen. That's the composition the graph makes free.

A Closing Word

The state-machine-via-relations work landed across roughly twenty commits in May 2026. The graph primitives — pp:Event, on_click_fire, exclusive_group, on_enter_* / on_exit_*, the seven on_event_* reactions — are the meaningful additions. A separate experiment, the WAI-ARIA pattern matcher in A11yShadowTree.js, sits on top and tries to derive screen-reader semantics from relation shapes; that one is off by default as of this writing because the canvas-widget-with-ARIA use case is narrower than we initially scoped it. The graph primitives stand on their own — they earn their keep for canvas state machines independent of any a11y bet.

We're publishing this post less as a launch and more as a problem statement. The composition tax exists in every animation tool that also handles interaction. We took one shot at addressing it. If you're working on a similar tool, or building something where canvas animation has to coexist with discrete state, the way you handle this composition is worth being explicit about.


Relevant files: js/RelationRegistry.js (rule registration), js/PinePaper.js (event channel + binding hooks), js/templates/relation-demos.js (canonical demos including the Solar System scene). See the GitHub repository for full source.

Ready to create?

Start making animated GIFs, videos, and graphics — free, no signup.

Open PinePaper Editor