@anvpx/motion-scenes
v0.1.94
Published
Scene registry and browser renderer for @anvpx/motion storyboards.
Maintainers
Readme
@anvpx/motion-scenes
Scene plugins (ScenePlugin from @anvpx/motion-schema) and the shared browser runtime. Base scenes: title, bullets, stat, flow, outro. Overlay scenes: lower-third, bug, progress, countdown, chapter.
sceneRegistry/getScene(type)/sceneTypes: build consumes only this barrel.runtimeFiles(): shared modules (runtime/easing.js,timeline.js,mount.js), emitted once by build.emit(entry, ctx)returns, per scene id:scenes/<id>/fragment.html,style.css,scene.js.
Fragment root is <section id="scene-<id>"> without a clip class; build wraps timing.
Add a scene
- New folder
src/scenes/<type>/withindex.ts,style.css,scene.js,index.test.ts. - Build the plugin with
defineScene(type,configSchema,meta,style,script,render); rundescribeSceneContractin its test. - Add one import and one entry to the
pluginslist insrc/registry.ts. - Run
mk catalog --writeto refresh the rootCATALOG.md(a test fails on drift).
Overlay scenes
An overlay is a transparent layer above the base timeline (layer: "overlay" on the storyboard entry; the plugin declares layer: "overlay" in defineScene). The root has no background, ignores pointer events and keeps the 5 % safe margin as padding, so content stays inside 90 % of the frame.
Catalog metadata
Each scene passes meta: { purpose, example } to defineScene: a one-line purpose and the smallest props object that passes the schema. sceneDocs() derives everything else (layer, fields, required/optional, types, enums, defaults) from configSchema via z.toJSONSchema, so the schema stays the single source of truth. mk catalog and the generated CATALOG.md at the repo root consume it. Cross-field rules (for example bug: exactly one of text or image) are not derivable; state them in purpose.
Flow layout
flow sizes its cards from the label text with a deterministic width estimate (scenes/flow/measure.ts, no font loading): labels wrap only at spaces, into at most two lines, and a word is never broken; a card widens for a long word and the text steps down lg -> md -> sm (theme steps, so always >= 28 px) before it is declared crowded. Edge labels sit on or beside their own edge and slide along it (then to either side) until they clear every card, earlier label and other edge; the room between layers is 2.2x the longest label. planFlow is the single layout; the scene renders it and inspectFlow (exported) feeds the lint rules below.
Runtime contract
createScene(root, config, ctx) returns { seek(t), dispose(), ready }. seek(t) is a pure function of t. Config falls back to data-* attributes on the root (ease, move, focus, fps, duration). Browser code is plain ES modules (// @ts-check plus JSDoc), shipped as text. No requestAnimationFrame, Date.now or unseeded random.
Theme and text rules
CSS uses only --mk-* custom properties from @anvpx/motion-themes; text is at least 28 px and uses one theme font family; at most 40 on-screen words per scene (limitWords). Props are strict (unknown keys rejected).
Shared helpers
src/shared/ holds the helpers every scene reuses (one implementation, no per-scene copies): staggerStart/staggerDuration (offset always < item duration), countUp (ease-out, exact end), progress/scale/lerp/clamp, wipe, drawOn, revealTimings/revealProgress (word by word), fmt (locale-free tabular numbers: unit, decimals, sign, compact), fitText (deterministic width estimate, balanced wrap, never breaks a word, last line >= 35 % of the widest), sceneIcon (config error with the prop pointer and 3 suggestions), and esc/accentHtml ([x] accent markup; every character escaped, only <span class="accent"> is emitted). motion.js and format.js are plain browser ES modules (they import runtime/easing.js); emitting them next to runtime/ is wired by the first scene that needs them. @anvpx/motion-assets (a leaf) is imported only by shared/icon.ts.
