Skip to content
SnapDOMTry SnapStudioGitHub★ 8K
Labs Experiment

You choose the frames

Pose an actor, press the shutter, move on. The sequence is the poses you kept, like a physical stop-motion rig.

TL;DR

A small plugin's afterRender hook fires once per capture and hands back ctx.dataURL. The plugin collects those URLs into an ordered array; the player sets the rhythm.

What you're looking at

Three sliders pose an actor on a small stage. Capture pose captures the stage and appends it to a filmstrip. Play flips through the filmstrip at a fixed interval.

Try it

Pose the actor, capture a few poses, then press Play. Each thumbnail is a separate SVG snapshot.

Pose playback
Capture at least two poses.

How it works

  1. The plugin factory closes over a counter

    frameCollector(onFrame) returns a plugin with one private index: the frame count, no clone or DOM reference.

  2. Moving a slider captures nothing

    The sliders update inline styles and a CSS custom property on the live #actor. SnapDOM is not involved yet.

  3. Capture pose runs one capture

    The button calls snapdom(poseScene, { plugins: [collector] }) against the live stage, in whatever pose the sliders show.

  4. afterRender fires with the finished context

    Once SnapDOM renders the SVG, afterRender(ctx) increments the counter and calls back with { index, url: ctx.dataURL }.

  5. The page pushes the URL into an array

    capturedFrames.push(frame.url), plus a thumbnail in the filmstrip. The plugin knows nothing about the filmstrip.

  6. Play iterates the array on a timer

    Play walks capturedFrames for a few loops, swapping <img id="playback">.src on an interval. The plugin is not involved.

Why this needed a plugin

In the paint-canvas and target-range labs a plugin mutates ctx.clone and persists it, so each capture builds on the last. Here ctx.clone is left alone and each pose is a self-contained render.

The afterRender hook centralizes frame collection via ctx.dataURL. An application could instead read result.url after awaiting snapdom(); the callback keeps the bookkeeping in one place.

Copy-paste example

The plugin factory. It collects dataURLs and nothing else:

function frameCollector (onFrame) {
  let index = 0

  return {
    name: 'frame-collector',
    afterRender (ctx) {
      index += 1
      onFrame({ index, url: ctx.dataURL })
    },
    reset () { index = 0 }
  }
}

The usage: capture a pose, read the frame back through the callback:

const capturedFrames = []

const collector = frameCollector(frame => {
  capturedFrames.push(frame.url)
})

// runs once per "Capture pose" click, against whatever
// pose the sliders are showing at that moment
await snapdom(poseScene, { plugins: [collector] })
slider input live style change (no capture) Capture pose snapdom() afterRender (ctx.dataURL) capturedFrames.push()

Limits and things to watch

The collector's afterRender hook is stateful, so in v3 each pose runs a fresh capture; resource caches can still be reused. Each SVG data URL stays in memory, so the filmstrip grows with frame count and content.

Hook contracts and custom exports: plugin API and PLUGIN_SPEC.md.