@algorisys/tinyfly 0.70.2 → 0.74.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -44,6 +44,14 @@ A lightweight, API-driven animation engine and visual editor for creating high-p
44
44
  - **Authoring kit** - `lesson()` step builder and diagram primitives (array cells, pointer, stack, queue / channel, table, pipeline) in `@algorisys/tinyfly/teach`
45
45
  - **Build tools** - `npx @algorisys/tinyfly validate` catches broken figures in CI; `render` writes a frame to static SVG for RSS, email and print
46
46
 
47
+ ### Video from Code
48
+ - **Headless MP4** - `npx tinyfly video scene.mjs` renders a scene to H.264 MP4 in Node (no browser), frame by frame at exact times, with an optional soundtrack muxed in; `--stills` writes one PNG mid-way through each caption line (or marker step) for layout checks
49
+ - **Code-drawn targets** - A `custom` canvas target draws with code (characters, charts, props) while the timeline animates its position, opacity and its own `props`, so drawing stays code and timing stays JSON
50
+ - **Immediate mode too** - A scene's `background` and `draw(ctx, { time })` functions paint each frame directly, Cairo/Processing-style, and mix freely with timeline targets
51
+ - **Timing from narration** - `planNarration()` lays spoken lines out from their clip lengths (lead, gap, tail) into cues, scene spans and markers; `voiceNarration()` measures recorded clips with ffmpeg and writes the sample-aligned narration WAV
52
+ - **Characters** - A poseable stick figure (`@algorisys/tinyfly/characters`): named poses, facial expressions (brows, eyes that widen, close and look around, mouth shapes), blending, walk cycles and talking, all driven by timeline tracks
53
+ - **Captions** - `toSRT()` / `toWebVTT()` from narration cues or from a timeline's markers
54
+
47
55
  ### Render Adapters
48
56
  - **DOM** - CSS transforms, opacity, colors, clip-path reveal, filters, shine, transform-origin, perspective
49
57
  - **Canvas** - Shapes with position, size, rotation, colors, clip reveal, filters, transform-origin pivot
@@ -120,6 +128,7 @@ A lightweight, API-driven animation engine and visual editor for creating high-p
120
128
  - [Examples](docs/examples.md) — Code examples for common animation patterns
121
129
  - [Scroll Animation](docs/scroll-animation.md) — Scroll-driven and visibility-triggered playback via drivers
122
130
  - [GSAP Compatibility](docs/gsap-compat.md) — The GSAP-flavoured API, the mapping table, and what we deliberately don't do
131
+ - [Rendering Video from Code](docs/video-rendering.md) — `tinyfly video`, custom code-drawn targets, narration timing, captions and stills, without a browser
123
132
  - [Teaching Animations](docs/teaching.md) — Step-through figures: markers, captions, the stepping player, controls, declarative embeds, scenarios the reader chooses, `tinyfly/teach`, validate and render
124
133
  - [Extending tinyfly](docs/extending.md) — Writing adapters, custom eases and stagger offsets, adding a track kind, contributing examples
125
134
  - [Deployment](docs/DEPLOYMENT.md) — Hosting, Docker, and CDN configuration
@@ -137,11 +146,12 @@ npm install @algorisys/tinyfly
137
146
 
138
147
  Or use it with no build step from the [GitHub CDN](#use-from-a-script-tag-no-build-step).
139
148
 
140
- It also installs a `tinyfly` command for teaching figures in build pipelines:
149
+ It also installs a `tinyfly` command for build pipelines:
141
150
 
142
151
  ```bash
143
152
  npx tinyfly validate figure.json --markup figure.svg # fails the build on broken figures
144
153
  npx tinyfly render figure.json figure.svg --at end > end.svg # a static frame for RSS, email, print
154
+ npx tinyfly video scene.mjs -o scene.mp4 --srt scene.srt # a whole video, no browser (needs ffmpeg + @napi-rs/canvas)
145
155
  ```
146
156
 
147
157
  The package ships these entry points. Each is tree-shakeable, so you pay only
@@ -151,7 +161,7 @@ for what you import:
151
161
  |---|---|---|
152
162
  | `@algorisys/tinyfly` | The engine — `Timeline`, tracks, easing, JSON | Browser, Web Worker, Node |
153
163
  | `@algorisys/tinyfly/player` | `TinyflyPlayer`, `MediaSync`, sequencer — plays editor JSON on the DOM | Browser |
154
- | `@algorisys/tinyfly/export` | `exportToCSS`, `exportToLottie`, GIF / WebP / MP4 / sprite-sheet export | Browser (CSS and Lottie anywhere) |
164
+ | `@algorisys/tinyfly/export` | `exportToCSS`, `exportToLottie`, GIF / WebP / MP4 / sprite-sheet export, SRT / WebVTT captions | Browser (CSS, Lottie and captions anywhere) |
155
165
  | `@algorisys/tinyfly/adapters` | `DOMAdapter`, `CanvasAdapter`, `SVGAdapter`, `WebGLAdapter` — apply timeline state to a render target | Browser |
156
166
  | `@algorisys/tinyfly/gsap-compat` | GSAP-style `live.to()` / `timeline()`, plus the compiling `tf` facade | Browser (`tf` anywhere) |
157
167
  | `@algorisys/tinyfly/drivers` | `ScrollDriver`, `VisibilityDriver` | Browser |
@@ -159,7 +169,9 @@ for what you import:
159
169
  | `@algorisys/tinyfly/embed` | Teaching embeds: the player with step controls, captions, scenarios and one-script `[data-tinyfly-embed]` mounting; `validateEmbed`, `validateScenarios`, `renderFrame` | Browser (tools anywhere) |
160
170
  | `@algorisys/tinyfly/teach` | `lesson()` step builder and diagram primitives (cells, pointer, stack, queue, table, pipeline) | Anywhere |
161
171
  | `@algorisys/tinyfly/react`, `@algorisys/tinyfly/vue`, `@algorisys/tinyfly/svelte`, `@algorisys/tinyfly/solid` | `useTinyfly` hooks, a Svelte action and a Solid primitive: `live` animations scoped to a component and reverted on unmount | Browser (frameworks are optional peer dependencies) |
162
- | `@algorisys/tinyfly/browser` | Everything above in one bundle | Browser |
172
+ | `@algorisys/tinyfly/characters` | Poseable stick figure: `stickFigureTarget`, `poseTracks`, `POSES`, `blendPose`, `walkPose`, `drawStickFigure` | Anywhere with a Canvas 2D context |
173
+ | `@algorisys/tinyfly/headless` | `renderVideo`, `renderStills`, `FrameRenderer`: render a scene to MP4 or PNGs (see [Rendering Video from Code](docs/video-rendering.md)) | Node (`@napi-rs/canvas` optional peer, ffmpeg) |
174
+ | `@algorisys/tinyfly/browser` | One script-tag bundle (`tinyfly.iife.js`): the engine, player, drivers, interaction, the GSAP-style `live` / `tf` facades, teaching-embed controls and mounting, and the `characters` stick figure. Not included: `export`, `adapters`, `teach`, the framework hooks, `headless` | Browser |
163
175
 
164
176
  ```js
165
177
  // The framework-agnostic engine (browser, Web Worker, or Node)
@@ -205,7 +217,7 @@ GSAP-shaped functions at the top level. Teaching embeds are included: add
205
217
  itself.
206
218
 
207
219
  ```html
208
- <script src="https://cdn.jsdelivr.net/gh/algorisys-oss/tinyfly@v0.70.2/cdn/tinyfly.iife.js"></script>
220
+ <script src="https://cdn.jsdelivr.net/gh/algorisys-oss/tinyfly@v0.74.1/cdn/tinyfly.iife.js"></script>
209
221
  <script>
210
222
  tinyfly.to('.box', { x: 200, rotate: 90, duration: 1, ease: 'power2.out' })
211
223
 
@@ -227,7 +239,7 @@ itself.
227
239
  | `cdn/tinyfly-player.iife.js` | Player only (~17 KB gzipped), for playing editor exports |
228
240
  | `cdn/tinyfly-embed.iife.js` | Only teaching figures (~19 KB gzipped): player, step controls, auto-mount |
229
241
 
230
- Replace `@v0.70.2` with the version you want. **Pin a version in production**:
242
+ Replace `@v0.71.0` with the version you want. **Pin a version in production**:
231
243
  a tag's files never change, and each release's `cdn/README.md` lists an SRI hash
232
244
  for `integrity=`. `@main` follows the latest release, which jsDelivr caches for up
233
245
  to a day. Loading more than one bundle is safe: they add to the same `tinyfly`
@@ -241,7 +253,7 @@ A teaching figure needs no code at all:
241
253
  <script type="application/json" data-tinyfly-timeline>{ …timeline JSON with markers… }</script>
242
254
  <figcaption>Appending to a full slice</figcaption>
243
255
  </figure>
244
- <script src="https://cdn.jsdelivr.net/gh/algorisys-oss/tinyfly@v0.70.2/cdn/tinyfly.iife.js" data-tinyfly-auto></script>
256
+ <script src="https://cdn.jsdelivr.net/gh/algorisys-oss/tinyfly@v0.74.1/cdn/tinyfly.iife.js" data-tinyfly-auto></script>
245
257
  ```
246
258
 
247
259
  See [Teaching Animations](docs/teaching.md).
@@ -340,7 +352,7 @@ Without a build step, the player bundle puts the same functions on a `tinyfly` g
340
352
  <div data-tinyfly="box" style="width: 60px; height: 60px; background: #4a9eff;"></div>
341
353
  </div>
342
354
 
343
- <script src="https://cdn.jsdelivr.net/gh/algorisys-oss/tinyfly@v0.70.2/cdn/tinyfly-player.iife.js"></script>
355
+ <script src="https://cdn.jsdelivr.net/gh/algorisys-oss/tinyfly@v0.74.1/cdn/tinyfly-player.iife.js"></script>
344
356
  <script>
345
357
  tinyfly.play('#animation', './animation.json', { loop: -1 })
346
358
  </script>
@@ -449,7 +461,7 @@ Or skip the code entirely with declarative embeds (see [Teaching Animations](doc
449
461
  <svg viewBox="0 0 720 200">…</svg>
450
462
  <script type="application/json" data-tinyfly-timeline>{ …timeline JSON… }</script>
451
463
  </figure>
452
- <script src="https://cdn.jsdelivr.net/gh/algorisys-oss/tinyfly@v0.70.2/cdn/tinyfly-embed.iife.js" data-tinyfly-auto></script>
464
+ <script src="https://cdn.jsdelivr.net/gh/algorisys-oss/tinyfly@v0.74.1/cdn/tinyfly-embed.iife.js" data-tinyfly-auto></script>
453
465
  ```
454
466
 
455
467
  ### Audio / Video Sync
package/bin/tinyfly.mjs CHANGED
@@ -13,8 +13,18 @@
13
13
  * tinyfly render <timeline.json> <figure.svg|.html> [--at start|end|<ms>|<marker id>]
14
14
  * Print the markup with that frame written in, for places that run no
15
15
  * JavaScript (RSS, email, print, previews).
16
+ *
17
+ * tinyfly video <scene.mjs> [-o <out.mp4>] [--stills <dir>] [--scale <n>] [--fps <n>]
18
+ * [--crf <n>] [--no-audio] [--srt <file>] [--vtt <file>]
19
+ * Render a scene module to an MP4 without a browser. The module's default
20
+ * export is a VideoScene (or a function returning one): a timeline and
21
+ * canvas targets, a draw(ctx, frame) function, or both. --stills writes
22
+ * one PNG per marker step instead of a video. Needs ffmpeg on the PATH
23
+ * and the optional package @napi-rs/canvas.
16
24
  */
17
- import { readFileSync } from 'node:fs'
25
+ import { readFileSync, writeFileSync } from 'node:fs'
26
+ import { basename, dirname, extname, join, resolve } from 'node:path'
27
+ import { pathToFileURL } from 'node:url'
18
28
  import { validateEmbed, validateScenarios, renderFrame } from '../lib/cli/tools.js'
19
29
 
20
30
  const [command, ...rest] = process.argv.slice(2)
@@ -24,9 +34,30 @@ const flag = (name) => {
24
34
  const [, value] = rest.splice(index, 2)
25
35
  return value
26
36
  }
37
+ const has = (name) => {
38
+ const index = rest.indexOf(name)
39
+ if (index === -1) return false
40
+ rest.splice(index, 1)
41
+ return true
42
+ }
43
+ const numberFlag = (name) => {
44
+ const value = flag(name)
45
+ if (value === undefined) return undefined
46
+ const number = Number(value)
47
+ if (!(number > 0 || (name === '--crf' && number === 0))) {
48
+ console.error(`tinyfly: ${name} needs a number (got ${value})`)
49
+ process.exit(2)
50
+ }
51
+ return number
52
+ }
27
53
 
28
54
  const usage = () => {
29
- console.error('Usage:\n tinyfly validate <timeline.json> [<timeline.json> …] [--markup <file>]\n tinyfly render <timeline.json> <markup file> [--at start|end|<ms>|<marker id>]')
55
+ console.error(
56
+ 'Usage:\n' +
57
+ ' tinyfly validate <timeline.json> [<timeline.json> …] [--markup <file>]\n' +
58
+ ' tinyfly render <timeline.json> <markup file> [--at start|end|<ms>|<marker id>]\n' +
59
+ ' tinyfly video <scene.mjs> [-o <out.mp4>] [--stills <dir>] [--scale <n>] [--fps <n>] [--crf <n>] [--no-audio] [--srt <file>] [--vtt <file>]'
60
+ )
30
61
  process.exit(2)
31
62
  }
32
63
 
@@ -68,6 +99,68 @@ if (command === 'validate') {
68
99
  if (!timelineFile || !markupFile) usage()
69
100
  const frame = /^\d+(\.\d+)?$/.test(at) ? Number(at) : at
70
101
  process.stdout.write(renderFrame(readFileSync(markupFile, 'utf8'), readJson(timelineFile), frame))
102
+ } else if (command === 'video') {
103
+ await video()
71
104
  } else {
72
105
  usage()
73
106
  }
107
+
108
+ async function video() {
109
+ const output = flag('-o') ?? flag('--output')
110
+ const stillsDir = flag('--stills')
111
+ const srtFile = flag('--srt')
112
+ const vttFile = flag('--vtt')
113
+ const scale = numberFlag('--scale')
114
+ const fps = numberFlag('--fps')
115
+ const crf = numberFlag('--crf')
116
+ const silent = has('--no-audio')
117
+ const [sceneFile] = rest
118
+ if (!sceneFile || rest.length > 1) usage()
119
+
120
+ const headless = await import('../lib/headless/headless.js')
121
+ const scenePath = resolve(sceneFile)
122
+ const baseDir = dirname(scenePath)
123
+ const exported = (await import(pathToFileURL(scenePath).href)).default
124
+ const scene = typeof exported === 'function' ? await exported() : exported
125
+ if (!scene || typeof scene !== 'object') {
126
+ console.error(`tinyfly: ${sceneFile} must default-export a scene (or a function returning one)`)
127
+ process.exit(2)
128
+ }
129
+
130
+ try {
131
+ if (srtFile || vttFile) {
132
+ const cues = headless.sceneCaptions(scene)
133
+ if (srtFile) writeFileSync(srtFile, headless.toSRT(cues))
134
+ if (vttFile) writeFileSync(vttFile, headless.toWebVTT(cues))
135
+ console.error(`captions: ${cues.length} cue(s)`)
136
+ }
137
+ if (stillsDir) {
138
+ const files = await headless.renderStills(scene, { dir: stillsDir, baseDir, scale })
139
+ console.error(`stills: ${files.length} PNG(s) in ${stillsDir}`)
140
+ return
141
+ }
142
+ const out = output ?? join(baseDir, `${basename(scenePath, extname(scenePath))}.mp4`)
143
+ let lastPercent = -1
144
+ const started = Date.now()
145
+ const result = await headless.renderVideo(scene, {
146
+ output: out,
147
+ baseDir,
148
+ scale,
149
+ fps,
150
+ crf,
151
+ audio: silent ? false : undefined,
152
+ onProgress: (done, total) => {
153
+ const percent = Math.floor((done / total) * 20) * 5
154
+ if (percent !== lastPercent) {
155
+ lastPercent = percent
156
+ console.error(` ${String(percent).padStart(3)}% frame ${done}/${total}`)
157
+ }
158
+ },
159
+ })
160
+ const seconds = ((Date.now() - started) / 1000).toFixed(1)
161
+ console.error(`wrote ${result.output} (${result.frames} frames, ${(result.duration / 1000).toFixed(2)} s) in ${seconds} s`)
162
+ } catch (error) {
163
+ console.error(error instanceof Error ? error.message : error)
164
+ process.exit(1)
165
+ }
166
+ }
@@ -1,4 +1,4 @@
1
- import { c as A, F as Y, s as M, e as g } from "./dom-adapter-ChrbtkLC.js";
1
+ import { c as A, F as Y, s as M, e as C } from "./dom-adapter-ChrbtkLC.js";
2
2
  import { D as Q } from "./dom-adapter-ChrbtkLC.js";
3
3
  import { createTrack as I } from "@algorisys/tinyfly";
4
4
  function B(a) {
@@ -7,7 +7,7 @@ function B(a) {
7
7
  e.set(t, _(i));
8
8
  return { measurements: e };
9
9
  }
10
- function C(a, e, t = {}) {
10
+ function g(a, e, t = {}) {
11
11
  const i = t.duration ?? 600, o = t.easing ?? "ease-out", s = t.scale !== !1, c = t.idPrefix ?? "flip", n = [];
12
12
  for (const { name: r, element: l } of e) {
13
13
  const h = a.measurements.get(r);
@@ -25,7 +25,7 @@ function C(a, e, t = {}) {
25
25
  }
26
26
  function V(a, e, t = {}) {
27
27
  const i = B(a);
28
- return e(), C(i, a, t);
28
+ return e(), g(i, a, t);
29
29
  }
30
30
  function T(a, e, t, i, o, s, c) {
31
31
  return I({
@@ -58,7 +58,7 @@ function k(a, e, t = {}) {
58
58
  function z(a) {
59
59
  return typeof a == "object" && a !== null && "type" in a;
60
60
  }
61
- class x {
61
+ class R {
62
62
  targets = /* @__PURE__ */ new Map();
63
63
  targetOrder = [];
64
64
  // Store animation offsets separately - these are applied via ctx.translate() during rendering
@@ -66,6 +66,8 @@ class x {
66
66
  animationOffsets = /* @__PURE__ */ new Map();
67
67
  // Track alias IDs that point to the same target (for lookup only, not rendering)
68
68
  aliases = /* @__PURE__ */ new Map();
69
+ // Time of the last applied state, passed to custom draw functions
70
+ time = 0;
69
71
  /**
70
72
  * Register a canvas drawing target.
71
73
  * @param id - The ID to register the target under
@@ -77,7 +79,7 @@ class x {
77
79
  this.aliases.set(e, i), this.targets.set(e, t);
78
80
  return;
79
81
  }
80
- this.targets.has(e) || this.targetOrder.push(e), this.targets.set(e, { ...t }), this.animationOffsets.set(e, { x: 0, y: 0 });
82
+ this.targets.has(e) || this.targetOrder.push(e), this.targets.set(e, t.type === "custom" ? { ...t, props: { ...t.props } } : { ...t }), this.animationOffsets.set(e, { x: 0, y: 0 });
81
83
  }
82
84
  /**
83
85
  * Unregister a target by its ID.
@@ -112,15 +114,18 @@ class x {
112
114
  * This matches how DOM/CSS transforms work (entire element moves together).
113
115
  */
114
116
  applyState(e) {
117
+ this.time = e.currentTime;
115
118
  for (const [t, i] of e.values) {
116
119
  const o = this.targets.get(t);
117
120
  if (!o) continue;
118
121
  const s = this.aliases.get(t) ?? t, c = this.animationOffsets.get(s) ?? { x: 0, y: 0 };
119
122
  for (const [n, r] of i)
120
- if (x.OFFSET_PROPERTIES.has(n) && typeof r == "number")
123
+ if (R.OFFSET_PROPERTIES.has(n) && typeof r == "number")
121
124
  n === "x" || n === "motionPathX" ? c.x = r : (n === "y" || n === "motionPathY") && (c.y = r);
125
+ else if (o.type === "custom" && o.props && n in o.props)
126
+ o.props[n] = r;
122
127
  else {
123
- const l = x.PROPERTY_MAP[n] ?? n;
128
+ const l = R.PROPERTY_MAP[n] ?? n;
124
129
  o[l] = r;
125
130
  }
126
131
  this.animationOffsets.set(s, c);
@@ -183,6 +188,9 @@ class x {
183
188
  case "image":
184
189
  this.renderImage(e, t);
185
190
  break;
191
+ case "custom":
192
+ this.renderCustom(e, t);
193
+ break;
186
194
  }
187
195
  e.restore();
188
196
  }
@@ -221,6 +229,7 @@ class x {
221
229
  switch (e.type) {
222
230
  case "rect":
223
231
  case "image":
232
+ case "custom":
224
233
  return { x: e.x, y: e.y, width: e.width, height: e.height };
225
234
  case "circle":
226
235
  return {
@@ -305,6 +314,12 @@ class x {
305
314
  }
306
315
  e.save(), e.beginPath(), r > 0 && typeof e.roundRect == "function" ? e.roundRect(i, o, s, c, r) : e.rect(i, o, s, c), e.clip(), e.drawImage(t.image, u, d, p, y), e.restore();
307
316
  }
317
+ /**
318
+ * Render a custom target by calling its draw function in local coordinates.
319
+ */
320
+ renderCustom(e, t) {
321
+ e.translate(t.x, t.y), t.draw(e, t, this.time);
322
+ }
308
323
  /**
309
324
  * Transform pivot X: the target's centre, shifted by `originX` across its
310
325
  * own width. `originX: 0` pivots on the left edge, 100 on the right.
@@ -327,6 +342,7 @@ class x {
327
342
  switch (e.type) {
328
343
  case "rect":
329
344
  case "image":
345
+ case "custom":
330
346
  return e.width;
331
347
  case "circle":
332
348
  return e.radius * 2;
@@ -343,6 +359,7 @@ class x {
343
359
  switch (e.type) {
344
360
  case "rect":
345
361
  case "image":
362
+ case "custom":
346
363
  return e.height;
347
364
  case "circle":
348
365
  return e.radius * 2;
@@ -361,6 +378,7 @@ class x {
361
378
  switch (e.type) {
362
379
  case "rect":
363
380
  case "image":
381
+ case "custom":
364
382
  return e.x + e.width / 2;
365
383
  case "circle":
366
384
  return e.x;
@@ -379,6 +397,7 @@ class x {
379
397
  switch (e.type) {
380
398
  case "rect":
381
399
  case "image":
400
+ case "custom":
382
401
  return e.y + e.height / 2;
383
402
  case "circle":
384
403
  return e.y;
@@ -421,7 +440,7 @@ const P = "http://www.w3.org/2000/svg", L = /* @__PURE__ */ new Set([
421
440
  "height",
422
441
  "viewBox",
423
442
  "preserveAspectRatio"
424
- ]), R = {
443
+ ]), x = {
425
444
  strokeWidth: "stroke-width",
426
445
  strokeLinecap: "stroke-linecap",
427
446
  strokeLinejoin: "stroke-linejoin",
@@ -497,7 +516,7 @@ class q {
497
516
  O.has(r) ? i[r] = l : r === "originX" || r === "originY" ? typeof l == "number" && (o[r] = l) : r === "perspective" ? typeof l == "number" && (i.perspective = l) : F.has(r) ? typeof l == "number" && (s[r] = l) : Y.has(r) ? (c[r] = l, n = !0) : r === "text" ? typeof l == "string" && M(e, l) : r === "shine" ? typeof l == "number" && this.applyShine(e, l) : r === "opacity" ? (e.setAttribute("fill-opacity", String(l)), e.setAttribute("stroke-opacity", String(l))) : this.applyAttribute(e, r, l);
498
517
  if (Object.keys(i).length > 0) {
499
518
  const r = this.buildCssTransformString(i);
500
- e.style.transform = r, g(e);
519
+ e.style.transform = r, C(e);
501
520
  }
502
521
  if (Object.keys(o).length > 0) {
503
522
  const r = e.style;
@@ -555,7 +574,7 @@ class q {
555
574
  }
556
575
  applyAttribute(e, t, i) {
557
576
  let o = t;
558
- R[t] ? o = R[t] : L.has(t) && (o = t);
577
+ x[t] ? o = x[t] : L.has(t) && (o = t);
559
578
  const s = Array.isArray(i) ? i.join(" ") : String(i);
560
579
  e.setAttribute(o, s);
561
580
  }
@@ -742,11 +761,11 @@ function E(a, e, t) {
742
761
  t < 0 || (a.bindBuffer(a.ARRAY_BUFFER, e), a.enableVertexAttribArray(t), a.vertexAttribPointer(t, 2, a.FLOAT, !1, 0, 0));
743
762
  }
744
763
  export {
745
- x as CanvasAdapter,
764
+ R as CanvasAdapter,
746
765
  Q as DOMAdapter,
747
766
  q as SVGAdapter,
748
767
  J as WebGLAdapter,
749
- C as buildFlipTracks,
768
+ g as buildFlipTracks,
750
769
  V as flip,
751
770
  z as isGradient,
752
771
  N as parseColor,
@@ -0,0 +1,211 @@
1
+ const k = {
2
+ lean: 0,
3
+ headTilt: 0,
4
+ leftShoulder: 18,
5
+ rightShoulder: 18,
6
+ leftElbow: -6,
7
+ rightElbow: -6,
8
+ leftHip: 8,
9
+ rightHip: 8,
10
+ leftKnee: 0,
11
+ rightKnee: 0,
12
+ mouth: 0,
13
+ smile: 0.6,
14
+ mouthWidth: 1,
15
+ blink: 0,
16
+ leftEye: 1,
17
+ rightEye: 1,
18
+ leftBrow: 0,
19
+ rightBrow: 0,
20
+ browTilt: 0,
21
+ lookX: 0,
22
+ lookY: 0
23
+ };
24
+ function p(t) {
25
+ return { ...k, ...t };
26
+ }
27
+ const v = {
28
+ mouth: 0,
29
+ smile: 0,
30
+ mouthWidth: 1,
31
+ leftEye: 1,
32
+ rightEye: 1,
33
+ leftBrow: 0,
34
+ rightBrow: 0,
35
+ browTilt: 0,
36
+ lookX: 0,
37
+ lookY: 0
38
+ }, a = (t) => ({ ...v, ...t }), b = {
39
+ neutral: v,
40
+ happy: a({ smile: 0.9, leftBrow: 0.2, rightBrow: 0.2 }),
41
+ joyful: a({ mouth: 0.6, smile: 1, mouthWidth: 1.2, leftEye: 0, rightEye: 0, leftBrow: 0.4, rightBrow: 0.4 }),
42
+ sad: a({ smile: -0.8, leftEye: 0.8, rightEye: 0.8, browTilt: 0.9, leftBrow: -0.1, rightBrow: -0.1, lookY: 0.6 }),
43
+ crying: a({ mouth: 0.45, smile: -1, leftEye: 0, rightEye: 0, browTilt: 1, lookY: 0.4 }),
44
+ surprised: a({ mouth: 0.7, mouthWidth: 0.7, leftEye: 1.5, rightEye: 1.5, leftBrow: 1, rightBrow: 1 }),
45
+ shocked: a({ mouth: 1, mouthWidth: 0.8, leftEye: 1.6, rightEye: 1.6, leftBrow: 1, rightBrow: 1, browTilt: 0.4 }),
46
+ angry: a({ smile: -0.6, mouthWidth: 0.9, leftEye: 0.8, rightEye: 0.8, leftBrow: -0.6, rightBrow: -0.6, browTilt: -1 }),
47
+ furious: a({ mouth: 0.5, smile: -1, mouthWidth: 1.3, leftEye: 0.9, rightEye: 0.9, leftBrow: -0.9, rightBrow: -0.9, browTilt: -1 }),
48
+ worried: a({ smile: -0.3, mouthWidth: 0.8, leftEye: 1.1, rightEye: 1.1, leftBrow: 0.3, rightBrow: 0.3, browTilt: 0.8, lookX: -0.5 }),
49
+ scared: a({ mouth: 0.35, smile: -0.5, mouthWidth: 0.8, leftEye: 1.45, rightEye: 1.45, leftBrow: 0.8, rightBrow: 0.8, browTilt: 0.9 }),
50
+ confused: a({ smile: -0.2, mouthWidth: 0.8, leftEye: 0.9, rightEye: 1.15, leftBrow: -0.3, rightBrow: 0.8, lookX: 0.5, lookY: -0.4 }),
51
+ skeptical: a({ smile: -0.1, leftEye: 0.6, rightEye: 1, leftBrow: -0.4, rightBrow: 0.7, lookX: 0.4 }),
52
+ thinking: a({ smile: 0, mouthWidth: 0.7, leftBrow: 0.3, rightBrow: 0.5, lookX: 0.6, lookY: -0.8 }),
53
+ sleepy: a({ smile: 0.1, leftEye: 0.25, rightEye: 0.25, leftBrow: -0.3, rightBrow: -0.3, lookY: 0.5 }),
54
+ disgusted: a({ smile: -0.7, mouthWidth: 0.9, leftEye: 0.6, rightEye: 0.75, leftBrow: -0.5, rightBrow: -0.2, browTilt: -0.4, lookX: -0.6 }),
55
+ smug: a({ smile: 0.6, mouthWidth: 0.9, leftEye: 0.6, rightEye: 0.6, leftBrow: 0.1, rightBrow: 0.5, lookX: 0.5 }),
56
+ wink: a({ smile: 0.9, leftEye: 0, rightEye: 1, leftBrow: -0.2, rightBrow: 0.3 })
57
+ };
58
+ function R(t, e) {
59
+ return { ...t, ...typeof e == "string" ? b[e] : e };
60
+ }
61
+ const A = {
62
+ rest: k,
63
+ wave: p({ rightShoulder: 135, rightElbow: 30, headTilt: 6, ...b.happy }),
64
+ cheer: p({ leftShoulder: 125, leftElbow: 20, rightShoulder: 125, rightElbow: 20, ...b.joyful }),
65
+ shrug: p({ leftShoulder: 30, leftElbow: 85, rightShoulder: 30, rightElbow: 85, headTilt: -10, ...b.confused, lookX: 0, lookY: 0 }),
66
+ point: p({ rightShoulder: 90, rightElbow: 0, lean: 4, smile: 0.4 }),
67
+ // The forearm passes 180° to fold back in, so the hand reaches the chin.
68
+ think: p({ rightShoulder: 60, rightElbow: 150, headTilt: 10, ...b.thinking }),
69
+ handsOnHips: p({ leftShoulder: 45, leftElbow: -100, rightShoulder: 45, rightElbow: -100, leftHip: 14, rightHip: 14, smile: 0.8 }),
70
+ sad: p({ leftShoulder: 14, rightShoulder: 14, leftElbow: -4, rightElbow: -4, headTilt: -14, lean: -3, ...b.sad }),
71
+ surprised: p({ leftShoulder: 70, leftElbow: 60, rightShoulder: 70, rightElbow: 60, ...b.surprised })
72
+ }, I = Object.keys(k);
73
+ function O(t, e, o) {
74
+ const l = { ...t };
75
+ for (const h of I) l[h] = t[h] + (e[h] - t[h]) * o;
76
+ return l;
77
+ }
78
+ const P = 24, _ = 40;
79
+ function F(t, e = k, o = 1) {
80
+ const l = Math.sin(t * Math.PI * 2) * o, h = Math.cos(t * Math.PI * 2) * o, u = (g) => g <= _ ? 22 * l : g;
81
+ return {
82
+ ...e,
83
+ // Left foot forward while swing > 0, right foot back; then the other way.
84
+ leftHip: -P * l,
85
+ rightHip: -P * l,
86
+ // The leg swinging forward lifts, its shin trailing backward (-x). A positive
87
+ // knee folds toward the centre, which is backward only for the right leg.
88
+ leftKnee: -30 * Math.max(0, h),
89
+ rightKnee: 30 * Math.max(0, -h),
90
+ // Arms swing against the legs: left arm back while the left foot is forward.
91
+ leftShoulder: u(e.leftShoulder),
92
+ rightShoulder: u(e.rightShoulder)
93
+ };
94
+ }
95
+ function U(t, e = 1) {
96
+ return 4 * ((Y + H) * t) * Math.sin(P * e * Math.PI / 180);
97
+ }
98
+ function K(t) {
99
+ const e = Math.abs(Math.sin(t / 65)), o = 0.55 + 0.45 * Math.sin(t / 310);
100
+ return e * o;
101
+ }
102
+ const C = 0.12, N = 0.1, L = 0.21, q = 0.19, Y = 0.24, H = 0.22, M = (t) => t * Math.PI / 180, G = (t, e) => ({ x: e * Math.sin(M(t)), y: Math.cos(M(t)) });
103
+ function j(t, e, o, l, h, u) {
104
+ const g = Math.max(1, u * 0.6), i = 0.12 * o, n = l - 0.12 * o, E = i + e.lookX * 0.08 * o, y = e.lookY * 0.07 * o, S = [
105
+ { x: -0.34 * o, open: e.leftEye, brow: e.leftBrow, side: -1 },
106
+ { x: 0.34 * o, open: e.rightEye, brow: e.rightBrow, side: 1 }
107
+ ];
108
+ t.fillStyle = h, t.strokeStyle = h, t.lineWidth = g;
109
+ for (const s of S) {
110
+ const f = Math.max(0, s.open) * (1 - Math.min(1, Math.max(0, e.blink)));
111
+ if (f < 0.2) {
112
+ const T = e.smile > 0.5 ? -0.12 * o : 0.06 * o;
113
+ t.beginPath(), t.moveTo(s.x + i - 0.12 * o, n), t.quadraticCurveTo(s.x + i, n + T, s.x + i + 0.12 * o, n), t.stroke();
114
+ } else {
115
+ if (f > 1.2) {
116
+ const W = 0.13 * o * f;
117
+ t.beginPath(), t.ellipse(s.x + i, n, W * 0.85, W, 0, 0, Math.PI * 2), t.fillStyle = "#ffffff", t.fill(), t.stroke(), t.fillStyle = h;
118
+ }
119
+ const T = f > 1.2 ? 0.075 * o : 0.1 * o;
120
+ t.beginPath(), t.ellipse(s.x + E, n + y, T, T * 1.1 * Math.min(f, 1), 0, 0, Math.PI * 2), t.fill();
121
+ }
122
+ const c = n - 0.3 * o - s.brow * 0.14 * o - Math.max(0, f - 1) * 0.12 * o, B = s.x + i - s.side * 0.13 * o, X = s.x + i + s.side * 0.13 * o;
123
+ t.beginPath(), t.moveTo(X, c), t.lineTo(B, c - e.browTilt * 0.1 * o), t.stroke();
124
+ }
125
+ const w = l + 0.4 * o, m = 0.25 * o * Math.max(0.3, e.mouthWidth), d = Math.min(1, Math.max(0, e.mouth));
126
+ if (t.beginPath(), d <= 0.05) {
127
+ t.moveTo(i - m, w), t.quadraticCurveTo(i, w + e.smile * 0.25 * o, i + m, w), t.stroke();
128
+ return;
129
+ }
130
+ const r = 0.3 * o * d;
131
+ e.smile > 0.3 ? (t.moveTo(i - m, w - 0.05 * o), t.lineTo(i + m, w - 0.05 * o), t.quadraticCurveTo(i, w + r * 2, i - m, w - 0.05 * o)) : e.smile < -0.3 ? (t.moveTo(i - m, w + r * 0.6), t.lineTo(i + m, w + r * 0.6), t.quadraticCurveTo(i, w - r * 1.4, i - m, w + r * 0.6)) : t.ellipse(i, w, m * 0.8, r, 0, 0, Math.PI * 2), t.fill();
132
+ }
133
+ function D(t, e, o = {}) {
134
+ const l = o.height ?? 300, h = o.color ?? "#1e293b", u = (o.facing ?? 1) < 0 ? -1 : 1, g = C * l, i = -0.46 * l, n = -0.76 * l;
135
+ t.save(), t.scale(u, 1), t.strokeStyle = h, t.lineWidth = o.lineWidth ?? l * 0.025, t.lineCap = "round", t.lineJoin = "round";
136
+ const E = (d, r, s, f, c) => {
137
+ const B = G(s, f);
138
+ return { x: d + B.x * c * l, y: r + B.y * c * l };
139
+ }, y = (...d) => {
140
+ t.beginPath(), t.moveTo(d[0].x, d[0].y);
141
+ for (const r of d.slice(1)) t.lineTo(r.x, r.y);
142
+ t.stroke();
143
+ };
144
+ for (const [d, r, s] of [
145
+ [-1, e.leftHip, e.leftKnee],
146
+ [1, e.rightHip, e.rightKnee]
147
+ ]) {
148
+ const f = E(0, i, r, d, Y);
149
+ y({ x: 0, y: i }, f, E(f.x, f.y, r - s, d, H));
150
+ }
151
+ t.translate(0, i), t.rotate(M(e.lean)), t.translate(0, -i), y({ x: 0, y: i }, { x: 0, y: n });
152
+ const S = n + N * l;
153
+ for (const [d, r, s] of [
154
+ [-1, e.leftShoulder, e.leftElbow],
155
+ [1, e.rightShoulder, e.rightElbow]
156
+ ]) {
157
+ const f = E(0, S, r, d, L);
158
+ y({ x: 0, y: S }, f, E(f.x, f.y, r + s, d, q));
159
+ }
160
+ t.translate(0, n), t.rotate(M(e.headTilt));
161
+ const w = -g;
162
+ t.beginPath(), t.arc(0, w, g, 0, Math.PI * 2);
163
+ const m = o.headFill ?? "#ffffff";
164
+ m !== "none" && (t.fillStyle = m, t.fill()), t.stroke(), j(t, e, g, w, h, o.lineWidth ?? l * 0.025), t.restore(), o.label && (t.save(), t.fillStyle = h, t.font = o.labelFont ?? `700 ${Math.round(l * 0.11)}px sans-serif`, t.textAlign = "center", t.textBaseline = "bottom", t.fillText(o.label, 0, -l - 0.04 * l), t.restore());
165
+ }
166
+ function $(t) {
167
+ const e = t.style ?? {}, o = e.height ?? 300, l = o * 0.8, h = { ...p(t.pose ?? {}), walk: 0, walking: 0, talk: 0 };
168
+ return {
169
+ type: "custom",
170
+ x: t.x - l / 2,
171
+ y: t.y - o,
172
+ width: l,
173
+ height: o,
174
+ props: { ...h },
175
+ draw(u, g, i) {
176
+ const n = g.props, E = { ...n };
177
+ let y = n.walking > 0 ? O(E, F(n.walk, E), n.walking) : E;
178
+ n.talk > 0 && (y = { ...y, mouth: Math.max(y.mouth, n.talk * K(i)) }), u.translate(l / 2, o), D(u, y, e);
179
+ }
180
+ };
181
+ }
182
+ function J(t, e) {
183
+ const o = [];
184
+ return e.forEach((l, h) => {
185
+ const u = h === 0 ? k : o[h - 1], g = typeof l.pose == "string" ? A[l.pose] : { ...u, ...l.pose };
186
+ o.push(l.expression ? R(g, l.expression) : g);
187
+ }), I.filter((l) => o.some((h) => h[l] !== k[l])).map((l) => ({
188
+ id: `${t}-${l}`,
189
+ target: t,
190
+ property: l,
191
+ keyframes: e.map((h, u) => ({
192
+ time: h.time,
193
+ value: o[u][l],
194
+ ...h.easing ? { easing: h.easing } : {}
195
+ }))
196
+ }));
197
+ }
198
+ export {
199
+ b as EXPRESSIONS,
200
+ A as POSES,
201
+ k as REST_POSE,
202
+ O as blendPose,
203
+ D as drawStickFigure,
204
+ p as pose,
205
+ J as poseTracks,
206
+ $ as stickFigureTarget,
207
+ U as strideLength,
208
+ K as talkingMouth,
209
+ F as walkPose,
210
+ R as withExpression
211
+ };