@algorisys/tinyfly 0.82.0 → 0.87.0

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.
Files changed (71) hide show
  1. package/README.md +13 -4
  2. package/bin/tinyfly.mjs +44 -6
  3. package/lib/addons/adapters.js +411 -248
  4. package/lib/addons/characters.js +1652 -1470
  5. package/lib/addons/dom-adapter-Cphr2HZn.js +372 -0
  6. package/lib/addons/gsap-compat.js +197 -187
  7. package/lib/addons/load-scene-vp14_Jj-.js +324 -0
  8. package/lib/addons/maps.js +1 -1
  9. package/lib/addons/scene-3d-webgl.js +240 -0
  10. package/lib/addons/scene-3d.js +306 -0
  11. package/lib/addons/shading-o5T_v9DT.js +89 -0
  12. package/lib/addons/{sketch-CA8ZXhxI.js → sketch-CYPUbk3Q.js} +2 -2
  13. package/lib/browser/tinyfly-scene-3d-webgl.iife.js +116 -0
  14. package/lib/browser/tinyfly-scene-3d.iife.js +3 -0
  15. package/lib/browser/tinyfly.iife.js +4 -4
  16. package/lib/browser/tinyfly.js +4333 -3726
  17. package/lib/browser/tinyfly.umd.js +4 -4
  18. package/lib/cli/tools.js +137 -22
  19. package/lib/embed/tinyfly-embed.iife.js +4 -4
  20. package/lib/embed/tinyfly-embed.js +921 -833
  21. package/lib/engine/tinyfly-engine.js +1022 -776
  22. package/lib/engine/tinyfly-engine.umd.cjs +2 -2
  23. package/lib/headless/headless.js +410 -8
  24. package/lib/player/tinyfly-player.es.js +459 -371
  25. package/lib/player/tinyfly-player.iife.js +2 -2
  26. package/lib/player/tinyfly-player.umd.js +2 -2
  27. package/lib/types/adapters/canvas/bloom.d.ts +33 -0
  28. package/lib/types/adapters/canvas/canvas-adapter.d.ts +36 -0
  29. package/lib/types/adapters/canvas/index.d.ts +2 -0
  30. package/lib/types/adapters/canvas/offscreen.d.ts +13 -0
  31. package/lib/types/adapters/transform-3d.d.ts +99 -0
  32. package/lib/types/adapters/webgl/webgl-adapter.d.ts +17 -0
  33. package/lib/types/browser/index.d.ts +2 -0
  34. package/lib/types/characters/character.d.ts +20 -1
  35. package/lib/types/characters/index.d.ts +2 -0
  36. package/lib/types/characters/rig/body-plan.d.ts +3 -1
  37. package/lib/types/characters/rig/skeleton.d.ts +57 -0
  38. package/lib/types/characters/scene-objects.d.ts +2 -0
  39. package/lib/types/compat/gsap/vars.d.ts +8 -0
  40. package/lib/types/engine/core/bake.d.ts +3 -1
  41. package/lib/types/engine/index.d.ts +1 -0
  42. package/lib/types/engine/interpolation/interpolators.d.ts +10 -3
  43. package/lib/types/engine/math/index.d.ts +11 -0
  44. package/lib/types/engine/math/mat4.d.ts +37 -0
  45. package/lib/types/engine/math/quat.d.ts +39 -0
  46. package/lib/types/engine/math/vec3.d.ts +16 -0
  47. package/lib/types/engine/types.d.ts +23 -2
  48. package/lib/types/headless/index.d.ts +1 -0
  49. package/lib/types/headless/loop-check.d.ts +41 -0
  50. package/lib/types/headless/node-video.d.ts +8 -0
  51. package/lib/types/headless/video-scene.d.ts +7 -1
  52. package/lib/types/scene-3d/camera.d.ts +27 -0
  53. package/lib/types/scene-3d/canvas-2d-renderer.d.ts +21 -0
  54. package/lib/types/scene-3d/geometry/extrude.d.ts +17 -0
  55. package/lib/types/scene-3d/geometry/mesh.d.ts +36 -0
  56. package/lib/types/scene-3d/geometry/primitives.d.ts +16 -0
  57. package/lib/types/scene-3d/geometry/triangulate.d.ts +24 -0
  58. package/lib/types/scene-3d/index.d.ts +20 -0
  59. package/lib/types/scene-3d/load-scene.d.ts +31 -0
  60. package/lib/types/scene-3d/object-kind.d.ts +54 -0
  61. package/lib/types/scene-3d/resolve-scene.d.ts +122 -0
  62. package/lib/types/scene-3d/scene-3d-adapter.d.ts +46 -0
  63. package/lib/types/scene-3d/scene-types.d.ts +192 -0
  64. package/lib/types/scene-3d/shading.d.ts +20 -0
  65. package/lib/types/scene-3d/validate-scene.d.ts +11 -0
  66. package/lib/types/scene-3d/webgl/gl-data.d.ts +29 -0
  67. package/lib/types/scene-3d/webgl/index.d.ts +16 -0
  68. package/lib/types/scene-3d/webgl/shaders.d.ts +29 -0
  69. package/lib/types/scene-3d/webgl/webgl2-renderer.d.ts +33 -0
  70. package/package.json +10 -2
  71. package/lib/addons/dom-adapter-CrNwoomd.js +0 -243
@@ -1,113 +1,126 @@
1
- import { c as _, F as O, s as C, e as I } from "./dom-adapter-CrNwoomd.js";
2
- import { D as ae } from "./dom-adapter-CrNwoomd.js";
3
- import { createTrack as B, parsePath as L } from "@algorisys/tinyfly";
4
- import { p as F, s as G } from "./sketch-CA8ZXhxI.js";
5
- import { b as le, a as he, c as fe } from "./sketch-CA8ZXhxI.js";
6
- function g(c) {
1
+ import { h as D, e as C, i as I, a as U, b as W, p as N, t as H, g as V, c as O, q, F as z, s as j, d as Z } from "./dom-adapter-Cphr2HZn.js";
2
+ import { D as xe } from "./dom-adapter-Cphr2HZn.js";
3
+ import { createTrack as J, parsePath as B, mat4 as T } from "@algorisys/tinyfly";
4
+ import { p as K, s as Q } from "./sketch-CYPUbk3Q.js";
5
+ import { c as Ae, a as ke, b as Ee } from "./sketch-CYPUbk3Q.js";
6
+ function ee(r) {
7
7
  const e = /* @__PURE__ */ new Map();
8
- for (const { name: t, element: i } of c)
9
- e.set(t, X(i));
8
+ for (const { name: t, element: i } of r)
9
+ e.set(t, g(i));
10
10
  return { measurements: e };
11
11
  }
12
- function U(c, e, t = {}) {
13
- const i = t.duration ?? 600, o = t.easing ?? "ease-out", s = t.scale !== !1, a = t.idPrefix ?? "flip", n = [];
14
- for (const { name: r, element: l } of e) {
15
- const h = c.measurements.get(r);
12
+ function te(r, e, t = {}) {
13
+ const i = t.duration ?? 600, s = t.easing ?? "ease-out", o = t.scale !== !1, a = t.idPrefix ?? "flip", n = [];
14
+ for (const { name: c, element: l } of e) {
15
+ const h = r.measurements.get(c);
16
16
  if (!h) continue;
17
- const f = X(l), p = h.left + h.width / 2 - (f.left + f.width / 2), u = h.top + h.height / 2 - (f.top + f.height / 2);
17
+ const f = g(l), p = h.left + h.width / 2 - (f.left + f.width / 2), u = h.top + h.height / 2 - (f.top + f.height / 2);
18
18
  if ((p !== 0 || u !== 0) && n.push(
19
- T(`${a}-${r}-x`, r, "x", p, 0, i, o),
20
- T(`${a}-${r}-y`, r, "y", u, 0, i, o)
21
- ), s && f.width > 0 && f.height > 0) {
19
+ v(`${a}-${c}-x`, c, "x", p, 0, i, s),
20
+ v(`${a}-${c}-y`, c, "y", u, 0, i, s)
21
+ ), o && f.width > 0 && f.height > 0) {
22
22
  const d = h.width / f.width, m = h.height / f.height;
23
- d !== 1 && n.push(T(`${a}-${r}-sx`, r, "scaleX", d, 1, i, o)), m !== 1 && n.push(T(`${a}-${r}-sy`, r, "scaleY", m, 1, i, o));
23
+ d !== 1 && n.push(v(`${a}-${c}-sx`, c, "scaleX", d, 1, i, s)), m !== 1 && n.push(v(`${a}-${c}-sy`, c, "scaleY", m, 1, i, s));
24
24
  }
25
25
  }
26
26
  return n;
27
27
  }
28
- function te(c, e, t = {}) {
29
- const i = g(c);
30
- return e(), U(i, c, t);
28
+ function ye(r, e, t = {}) {
29
+ const i = ee(r);
30
+ return e(), te(i, r, t);
31
31
  }
32
- function T(c, e, t, i, o, s, a) {
33
- return B({
34
- id: c,
32
+ function v(r, e, t, i, s, o, a) {
33
+ return J({
34
+ id: r,
35
35
  target: e,
36
36
  property: t,
37
37
  keyframes: [
38
38
  { time: 0, value: i },
39
- { time: s, value: o, easing: a }
39
+ { time: o, value: s, easing: a }
40
40
  ]
41
41
  });
42
42
  }
43
- function X(c) {
44
- const e = c;
43
+ function g(r) {
44
+ const e = r;
45
45
  if (typeof e.getBoundingClientRect != "function")
46
46
  return { left: 0, top: 0, width: 0, height: 0 };
47
47
  const t = e.getBoundingClientRect();
48
48
  return { left: t.left, top: t.top, width: t.width, height: t.height };
49
49
  }
50
- function Y(c, e, t = {}) {
51
- const i = t.highlight ?? "#ffffff", o = t.halfWidth ?? 0.12, s = -0.2 + c * 1.4, a = [{ offset: 0, color: e }], n = [
52
- { offset: s - o, color: e },
53
- { offset: s, color: i },
54
- { offset: s + o, color: e }
50
+ function L(r, e, t = {}) {
51
+ const i = t.highlight ?? "#ffffff", s = t.halfWidth ?? 0.12, o = -0.2 + r * 1.4, a = [{ offset: 0, color: e }], n = [
52
+ { offset: o - s, color: e },
53
+ { offset: o, color: i },
54
+ { offset: o + s, color: e }
55
55
  ];
56
- for (const r of n)
57
- r.offset > 0 && r.offset < 1 && a.push(r);
58
- return a.push({ offset: 1, color: e }), a.sort((r, l) => r.offset - l.offset), a;
56
+ for (const c of n)
57
+ c.offset > 0 && c.offset < 1 && a.push(c);
58
+ return a.push({ offset: 1, color: e }), a.sort((c, l) => c.offset - l.offset), a;
59
59
  }
60
- const x = 12;
61
- function R(c) {
60
+ const A = 12;
61
+ function x(r) {
62
62
  const e = [];
63
63
  let t, i = -1;
64
- for (const o of L(c).segments) {
65
- if (o.type === "L") {
66
- (!t || i !== o.subpath) && (t = { kind: "line", points: [{ x: o.startX, y: o.startY }], length: 0 }, i = o.subpath, e.push(t)), t.points.push({ x: o.endX, y: o.endY }), t.length += o.length;
64
+ for (const s of B(r).segments) {
65
+ if (s.type === "L") {
66
+ (!t || i !== s.subpath) && (t = { kind: "line", points: [{ x: s.startX, y: s.startY }], length: 0 }, i = s.subpath, e.push(t)), t.points.push({ x: s.endX, y: s.endY }), t.length += s.length;
67
67
  continue;
68
68
  }
69
69
  t = void 0;
70
- const [s, a, n, r, l, h] = o.points, f = [];
71
- for (let p = 0; p <= x; p++) {
72
- const u = p / x, d = 1 - u;
70
+ const [o, a, n, c, l, h] = s.points, f = [];
71
+ for (let p = 0; p <= A; p++) {
72
+ const u = p / A, d = 1 - u;
73
73
  f.push({
74
- x: d * d * d * o.startX + 3 * d * d * u * s + 3 * d * u * u * n + u * u * u * l,
75
- y: d * d * d * o.startY + 3 * d * d * u * a + 3 * d * u * u * r + u * u * u * h
74
+ x: d * d * d * s.startX + 3 * d * d * u * o + 3 * d * u * u * n + u * u * u * l,
75
+ y: d * d * d * s.startY + 3 * d * d * u * a + 3 * d * u * u * c + u * u * u * h
76
76
  });
77
77
  }
78
- e.push({ kind: "curve", points: f, length: o.length });
78
+ e.push({ kind: "curve", points: f, length: s.length });
79
79
  }
80
80
  return e;
81
81
  }
82
- function D(c, e, t, i, o = 0) {
83
- const s = Math.max(0, Math.min(o, t / 2, i / 2));
84
- if (s === 0) return R(`M${c},${e} H${c + t} V${e + i} H${c} Z`);
85
- const a = c + t, n = e + i;
86
- return R(
87
- `M${c + s},${e} H${a - s} A${s},${s} 0 0 1 ${a},${e + s} V${n - s} A${s},${s} 0 0 1 ${a - s},${n} H${c + s} A${s},${s} 0 0 1 ${c},${n - s} V${e + s} A${s},${s} 0 0 1 ${c + s},${e} Z`
82
+ function ie(r, e, t, i, s = 0) {
83
+ const o = Math.max(0, Math.min(s, t / 2, i / 2));
84
+ if (o === 0) return x(`M${r},${e} H${r + t} V${e + i} H${r} Z`);
85
+ const a = r + t, n = e + i;
86
+ return x(
87
+ `M${r + o},${e} H${a - o} A${o},${o} 0 0 1 ${a},${e + o} V${n - o} A${o},${o} 0 0 1 ${a - o},${n} H${r + o} A${o},${o} 0 0 1 ${r},${n - o} V${e + o} A${o},${o} 0 0 1 ${r + o},${e} Z`
88
88
  );
89
89
  }
90
- function S(c, e, t, i) {
91
- const s = e.reduce((n, r) => n + r.length, 0) * Math.min(1, Math.max(0, t));
90
+ function S(r, e, t, i) {
91
+ const o = e.reduce((n, c) => n + c.length, 0) * Math.min(1, Math.max(0, t));
92
92
  let a = 0;
93
- i || c.beginPath();
93
+ i || r.beginPath();
94
94
  for (const n of e) {
95
- const r = n.length === 0 ? s >= a ? 1 : 0 : Math.min(1, Math.max(0, (s - a) / n.length));
95
+ const c = n.length === 0 ? o >= a ? 1 : 0 : Math.min(1, Math.max(0, (o - a) / n.length));
96
96
  if (a += n.length, i) {
97
- n.kind === "curve" ? i.curve(n.points, r) : i.line(n.points, r);
97
+ n.kind === "curve" ? i.curve(n.points, c) : i.line(n.points, c);
98
98
  continue;
99
99
  }
100
- if (r <= 0) continue;
101
- const l = F(n.points, r);
102
- c.moveTo(l[0].x, l[0].y);
103
- for (const h of l.slice(1)) c.lineTo(h.x, h.y);
100
+ if (c <= 0) continue;
101
+ const l = K(n.points, c);
102
+ r.moveTo(l[0].x, l[0].y);
103
+ for (const h of l.slice(1)) r.lineTo(h.x, h.y);
104
104
  }
105
- i || c.stroke();
105
+ i || r.stroke();
106
106
  }
107
- function ie(c) {
108
- return typeof c == "object" && c !== null && "type" in c;
107
+ function F(r, e, t) {
108
+ if (typeof OffscreenCanvas < "u") return new OffscreenCanvas(e, t);
109
+ const i = r.canvas;
110
+ if (i?.ownerDocument) {
111
+ const s = i.ownerDocument.createElement("canvas");
112
+ return s.width = e, s.height = t, s;
113
+ }
114
+ try {
115
+ return i?.constructor ? new i.constructor(e, t) : null;
116
+ } catch {
117
+ return null;
118
+ }
119
+ }
120
+ function we(r) {
121
+ return typeof r == "object" && r !== null && "type" in r;
109
122
  }
110
- class v {
123
+ class R {
111
124
  targets = /* @__PURE__ */ new Map();
112
125
  targetOrder = [];
113
126
  // Store animation offsets separately - these are applied via ctx.translate() during rendering
@@ -117,6 +130,8 @@ class v {
117
130
  aliases = /* @__PURE__ */ new Map();
118
131
  // Time of the last applied state, passed to custom draw functions
119
132
  time = 0;
133
+ /** Offscreen layer for see-through targets in perspective (see `drawInPerspective`) */
134
+ layer = null;
120
135
  /**
121
136
  * Register a canvas drawing target.
122
137
  * @param id - The ID to register the target under
@@ -153,7 +168,8 @@ class v {
153
168
  fill: "fillStyle",
154
169
  stroke: "strokeStyle",
155
170
  strokeWidth: "lineWidth",
156
- motionPathRotate: "rotate"
171
+ motionPathRotate: "rotate",
172
+ rotateZ: "rotate"
157
173
  };
158
174
  // Properties that are position offsets (applied via ctx.translate)
159
175
  static OFFSET_PROPERTIES = /* @__PURE__ */ new Set(["x", "y", "motionPathX", "motionPathY"]);
@@ -165,19 +181,19 @@ class v {
165
181
  applyState(e) {
166
182
  this.time = e.currentTime;
167
183
  for (const [t, i] of e.values) {
168
- const o = this.targets.get(t);
169
- if (!o) continue;
170
- const s = this.aliases.get(t) ?? t, a = this.animationOffsets.get(s) ?? { x: 0, y: 0 };
171
- for (const [n, r] of i)
172
- if (v.OFFSET_PROPERTIES.has(n) && typeof r == "number")
173
- n === "x" || n === "motionPathX" ? a.x = r : (n === "y" || n === "motionPathY") && (a.y = r);
174
- else if (o.type === "custom" && o.props && n in o.props)
175
- o.props[n] = r;
184
+ const s = this.targets.get(t);
185
+ if (!s) continue;
186
+ const o = this.aliases.get(t) ?? t, a = this.animationOffsets.get(o) ?? { x: 0, y: 0 };
187
+ for (const [n, c] of i)
188
+ if (R.OFFSET_PROPERTIES.has(n) && typeof c == "number")
189
+ n === "x" || n === "motionPathX" ? a.x = c : (n === "y" || n === "motionPathY") && (a.y = c);
190
+ else if (s.type === "custom" && s.props && (n in s.props || s.acceptsProp?.(n)))
191
+ s.props[n] = c;
176
192
  else {
177
- const l = v.PROPERTY_MAP[n] ?? n;
178
- o[l] = r;
193
+ const l = R.PROPERTY_MAP[n] ?? n;
194
+ s[l] = c;
179
195
  }
180
- this.animationOffsets.set(s, a);
196
+ this.animationOffsets.set(o, a);
181
197
  }
182
198
  }
183
199
  /**
@@ -194,29 +210,107 @@ class v {
194
210
  for (const t of this.targetOrder) {
195
211
  const i = this.targets.get(t);
196
212
  if (!i) continue;
197
- const o = this.animationOffsets.get(t) ?? { x: 0, y: 0 };
198
- this.renderTarget(e, i, o);
213
+ const s = this.animationOffsets.get(t) ?? { x: 0, y: 0 };
214
+ this.renderTarget(e, i, s);
199
215
  }
200
216
  }
201
217
  /**
202
218
  * Render a single target.
203
219
  */
204
220
  renderTarget(e, t, i) {
205
- if (e.save(), (i.x !== 0 || i.y !== 0) && e.translate(i.x, i.y), t.opacity !== void 0 && (e.globalAlpha = t.opacity), t.rotate !== void 0 || t.rotateX !== void 0 || t.rotateY !== void 0 || t.scale !== void 0 || t.scaleX !== void 0 || t.scaleY !== void 0 || t.skewX !== void 0 || t.skewY !== void 0) {
206
- const a = this.getPivotX(t), n = this.getPivotY(t);
207
- e.translate(a, n), t.rotate !== void 0 && e.rotate(t.rotate * Math.PI / 180);
208
- let r = t.scaleX ?? 1, l = t.scaleY ?? 1;
209
- if (t.rotateX !== void 0 && (l *= Math.cos(t.rotateX * Math.PI / 180)), t.rotateY !== void 0 && (r *= Math.cos(t.rotateY * Math.PI / 180)), t.scale !== void 0 ? e.scale(t.scale, t.scale) : (r !== 1 || l !== 1) && e.scale(r, l), t.skewX !== void 0 || t.skewY !== void 0) {
210
- const h = (t.skewX ?? 0) * Math.PI / 180, f = (t.skewY ?? 0) * Math.PI / 180;
211
- e.transform(1, Math.tan(f), Math.tan(h), 1, 0, 0);
221
+ if (e.save(), t.opacity !== void 0 && (e.globalAlpha = t.opacity), D(t)) {
222
+ const o = C(t, i, { x: this.getPivotX(t), y: this.getPivotY(t) });
223
+ if (t.backfaceVisibility === "hidden" && I(o)) {
224
+ e.restore();
225
+ return;
212
226
  }
213
- e.translate(-a, -n);
227
+ U(o) ? (e.transform(...W(o)), this.drawContent(e, t)) : this.drawInPerspective(e, t, o), e.restore();
228
+ return;
214
229
  }
230
+ if ((i.x !== 0 || i.y !== 0) && e.translate(i.x, i.y), t.rotate !== void 0 || t.rotateX !== void 0 || t.rotateY !== void 0 || t.scale !== void 0 || t.scaleX !== void 0 || t.scaleY !== void 0 || t.skewX !== void 0 || t.skewY !== void 0) {
231
+ const o = this.getPivotX(t), a = this.getPivotY(t);
232
+ e.translate(o, a), t.rotate !== void 0 && e.rotate(t.rotate * Math.PI / 180);
233
+ let n = t.scaleX ?? 1, c = t.scaleY ?? 1;
234
+ if (t.rotateX !== void 0 && (c *= Math.cos(t.rotateX * Math.PI / 180)), t.rotateY !== void 0 && (n *= Math.cos(t.rotateY * Math.PI / 180)), t.scale !== void 0 ? e.scale(t.scale, t.scale) : (n !== 1 || c !== 1) && e.scale(n, c), t.skewX !== void 0 || t.skewY !== void 0) {
235
+ const l = (t.skewX ?? 0) * Math.PI / 180, h = (t.skewY ?? 0) * Math.PI / 180;
236
+ e.transform(1, Math.tan(h), Math.tan(l), 1, 0, 0);
237
+ }
238
+ e.translate(-o, -a);
239
+ }
240
+ this.drawContent(e, t), e.restore();
241
+ }
242
+ /**
243
+ * Draw a target in perspective: each triangle of a mesh over its bounds is
244
+ * clipped on the canvas and drawn with the 2D transform that carries it
245
+ * there. The triangles overlap by a pixel so no anti-aliased seam shows.
246
+ */
247
+ drawInPerspective(e, t, i) {
248
+ const o = e.globalAlpha < 1 ? this.perspectiveLayer(e) : null;
249
+ if (o) {
250
+ o.ctx.setTransform(e.getTransform()), this.drawMesh(o.ctx, t, i), e.save(), e.setTransform(1, 0, 0, 1, 0, 0), e.drawImage(o.canvas, 0, 0), e.restore();
251
+ return;
252
+ }
253
+ this.drawMesh(e, t, i);
254
+ }
255
+ drawMesh(e, t, i) {
256
+ const s = this.contentBounds(e, t);
257
+ for (const o of N(i, s)) {
258
+ const a = H(o.source, o.target);
259
+ if (!a) continue;
260
+ const [n, c, l] = V(o.target, 1);
261
+ e.save(), e.beginPath(), e.moveTo(n.x, n.y), e.lineTo(c.x, c.y), e.lineTo(l.x, l.y), e.closePath(), e.clip(), e.transform(...a), this.drawContent(e, t), e.restore();
262
+ }
263
+ }
264
+ /** A cleared offscreen canvas the size of `ctx`'s, reused frame to frame; null where none can be made. */
265
+ perspectiveLayer(e) {
266
+ const t = e.canvas?.width ?? 0, i = e.canvas?.height ?? 0;
267
+ if (!(t > 0 && i > 0)) return null;
268
+ if (!this.layer || this.layer.width !== t || this.layer.height !== i) {
269
+ const o = F(e, t, i), a = o?.getContext("2d");
270
+ if (this.layer = o && a ? { canvas: o, ctx: a, width: t, height: i } : null, !this.layer) return null;
271
+ }
272
+ const s = this.layer.ctx;
273
+ return s.setTransform(1, 0, 0, 1, 0, 0), s.globalAlpha = 1, s.clearRect(0, 0, t, i), this.layer;
274
+ }
275
+ /**
276
+ * Everything a target paints, generously: its box, measured text, a path's
277
+ * control points, plus room for its stroke, blur and glow. The perspective
278
+ * mesh covers this, so nothing it draws falls outside.
279
+ */
280
+ contentBounds(e, t) {
281
+ let i = this.getTargetBounds(t);
282
+ if (t.type === "text") {
283
+ const o = t.fontSize ?? 16;
284
+ e.save(), e.font = `${t.fontWeight ?? 400} ${o}px ${t.fontFamily ?? "sans-serif"}`;
285
+ const a = e.measureText(t.text).width;
286
+ e.restore();
287
+ const n = t.textAlign ?? "left", c = n === "center" ? t.x - a / 2 : n === "right" ? t.x - a : t.x, l = (t.textBaseline ?? "top") === "top" ? t.y : t.y - o;
288
+ i = { x: c, y: l, width: a, height: o * 1.4 };
289
+ } else if (t.type === "path") {
290
+ const o = [], a = [];
291
+ for (const n of B(t.d).segments) {
292
+ o.push(n.startX, n.endX), a.push(n.startY, n.endY);
293
+ for (let c = 0; c + 1 < n.points.length; c += 2)
294
+ o.push(n.points[c]), a.push(n.points[c + 1]);
295
+ }
296
+ if (o.length > 0) {
297
+ const n = Math.min(...o), c = Math.min(...a);
298
+ i = { x: t.x + n, y: t.y + c, width: Math.max(...o) - n, height: Math.max(...a) - c };
299
+ }
300
+ }
301
+ const s = (t.lineWidth ?? 1) + 2 + 3 * Math.max(t.blur ?? 0, t.glow ?? 0, t.shadowBlur ?? 0) + Math.max(Math.abs(t.shadowX ?? 0), Math.abs(t.shadowY ?? 0));
302
+ return { x: i.x - s, y: i.y - s, width: i.width + 2 * s, height: i.height + 2 * s };
303
+ }
304
+ /**
305
+ * Paint a target in the current transform: its fill and stroke styles,
306
+ * filter and clip, then its shape.
307
+ */
308
+ drawContent(e, t) {
215
309
  t.fillStyle && (e.fillStyle = this.resolveFillStyle(e, t)), t.strokeStyle && (e.strokeStyle = t.strokeStyle), t.lineWidth !== void 0 && (e.lineWidth = t.lineWidth);
216
- const s = _(t);
217
- if (s && (e.filter = s), t.clipTop !== void 0 || t.clipRight !== void 0 || t.clipBottom !== void 0 || t.clipLeft !== void 0) {
218
- const a = this.getTargetBounds(t), n = a.x + (t.clipLeft ?? 0) / 100 * a.width, r = a.x + a.width - (t.clipRight ?? 0) / 100 * a.width, l = a.y + (t.clipTop ?? 0) / 100 * a.height, h = a.y + a.height - (t.clipBottom ?? 0) / 100 * a.height;
219
- e.beginPath(), e.rect(n, l, Math.max(0, r - n), Math.max(0, h - l)), e.clip();
310
+ const i = O(t);
311
+ if (i && (e.filter = i), t.clipTop !== void 0 || t.clipRight !== void 0 || t.clipBottom !== void 0 || t.clipLeft !== void 0) {
312
+ const s = this.getTargetBounds(t), o = s.x + (t.clipLeft ?? 0) / 100 * s.width, a = s.x + s.width - (t.clipRight ?? 0) / 100 * s.width, n = s.y + (t.clipTop ?? 0) / 100 * s.height, c = s.y + s.height - (t.clipBottom ?? 0) / 100 * s.height;
313
+ e.beginPath(), e.rect(o, n, Math.max(0, a - o), Math.max(0, c - n)), e.clip();
220
314
  }
221
315
  switch (t.type) {
222
316
  case "rect":
@@ -241,7 +335,6 @@ class v {
241
335
  this.renderCustom(e, t);
242
336
  break;
243
337
  }
244
- e.restore();
245
338
  }
246
339
  /**
247
340
  * Resolve a fill style to a canvas-compatible value.
@@ -250,14 +343,14 @@ class v {
250
343
  const i = t.fillStyle;
251
344
  if (!i) return "transparent";
252
345
  if (typeof i == "string") return i;
253
- const o = this.getTargetBounds(t);
254
- return i.type === "linear" ? this.createLinearGradient(e, i, o) : this.createRadialGradient(e, i, o);
346
+ const s = this.getTargetBounds(t);
347
+ return i.type === "linear" ? this.createLinearGradient(e, i, s) : this.createRadialGradient(e, i, s);
255
348
  }
256
349
  /**
257
350
  * Create a canvas linear gradient from a LinearGradient definition.
258
351
  */
259
352
  createLinearGradient(e, t, i) {
260
- const o = (t.angle - 90) * (Math.PI / 180), s = i.x + i.width / 2, a = i.y + i.height / 2, n = Math.max(i.width, i.height), r = s - Math.cos(o) * n / 2, l = a - Math.sin(o) * n / 2, h = s + Math.cos(o) * n / 2, f = a + Math.sin(o) * n / 2, p = e.createLinearGradient(r, l, h, f);
353
+ const s = (t.angle - 90) * (Math.PI / 180), o = i.x + i.width / 2, a = i.y + i.height / 2, n = Math.max(i.width, i.height), c = o - Math.cos(s) * n / 2, l = a - Math.sin(s) * n / 2, h = o + Math.cos(s) * n / 2, f = a + Math.sin(s) * n / 2, p = e.createLinearGradient(c, l, h, f);
261
354
  for (const u of t.stops)
262
355
  p.addColorStop(u.offset, u.color);
263
356
  return p;
@@ -266,9 +359,9 @@ class v {
266
359
  * Create a canvas radial gradient from a RadialGradient definition.
267
360
  */
268
361
  createRadialGradient(e, t, i) {
269
- const o = i.x + i.width * t.centerX, s = i.y + i.height * t.centerY, a = Math.max(i.width, i.height) * t.radius, n = e.createRadialGradient(o, s, 0, o, s, a);
270
- for (const r of t.stops)
271
- n.addColorStop(r.offset, r.color);
362
+ const s = i.x + i.width * t.centerX, o = i.y + i.height * t.centerY, a = Math.max(i.width, i.height) * t.radius, n = e.createRadialGradient(s, o, 0, s, o, a);
363
+ for (const c of t.stops)
364
+ n.addColorStop(c.offset, c.color);
272
365
  return n;
273
366
  }
274
367
  /**
@@ -308,25 +401,25 @@ class v {
308
401
  * Draw a shape outline-first: the fill (clean) once the outline is complete,
309
402
  * then the outline up to `drawOn`, in pencil strokes when sketched.
310
403
  */
311
- renderOutlined(e, t, i, o) {
312
- const s = Math.min(1, Math.max(0, t.drawOn ?? 1));
313
- if (i && t.fillStyle && s >= 1 && i(), !t.strokeStyle || s <= 0) return;
314
- const a = t.sketch ? G(e, t.sketch, this.time) : void 0;
315
- a && (e.lineCap = t.lineCap ?? "round", e.lineJoin = t.lineJoin ?? "round"), o(s, a);
404
+ renderOutlined(e, t, i, s) {
405
+ const o = Math.min(1, Math.max(0, t.drawOn ?? 1));
406
+ if (i && t.fillStyle && o >= 1 && i(), !t.strokeStyle || o <= 0) return;
407
+ const a = t.sketch ? Q(e, t.sketch, this.time) : void 0;
408
+ a && (e.lineCap = t.lineCap ?? "round", e.lineJoin = t.lineJoin ?? "round"), s(o, a);
316
409
  }
317
410
  /**
318
411
  * Render a rectangle.
319
412
  */
320
413
  renderRect(e, t) {
321
414
  if (this.drawsOutline(t)) {
322
- const { x: i, y: o, width: s, height: a } = t;
415
+ const { x: i, y: s, width: o, height: a } = t;
323
416
  return this.renderOutlined(
324
417
  e,
325
418
  t,
326
419
  () => {
327
- e.beginPath(), t.borderRadius && t.borderRadius > 0 ? this.roundRect(e, i, o, s, a, t.borderRadius) : e.rect(i, o, s, a), e.fill();
420
+ e.beginPath(), t.borderRadius && t.borderRadius > 0 ? this.roundRect(e, i, s, o, a, t.borderRadius) : e.rect(i, s, o, a), e.fill();
328
421
  },
329
- (n, r) => S(e, D(i, o, s, a, t.borderRadius), n, r)
422
+ (n, c) => S(e, ie(i, s, o, a, t.borderRadius), n, c)
330
423
  );
331
424
  }
332
425
  e.beginPath(), t.borderRadius && t.borderRadius > 0 ? this.roundRect(e, t.x, t.y, t.width, t.height, t.borderRadius) : e.rect(t.x, t.y, t.width, t.height), t.fillStyle && e.fill(), t.strokeStyle && e.stroke(), e.closePath();
@@ -334,25 +427,25 @@ class v {
334
427
  /**
335
428
  * Draw a rounded rectangle path.
336
429
  */
337
- roundRect(e, t, i, o, s, a) {
338
- const n = Math.min(a, o / 2, s / 2);
339
- e.moveTo(t + n, i), e.lineTo(t + o - n, i), e.arcTo(t + o, i, t + o, i + n, n), e.lineTo(t + o, i + s - n), e.arcTo(t + o, i + s, t + o - n, i + s, n), e.lineTo(t + n, i + s), e.arcTo(t, i + s, t, i + s - n, n), e.lineTo(t, i + n), e.arcTo(t, i, t + n, i, n);
430
+ roundRect(e, t, i, s, o, a) {
431
+ const n = Math.min(a, s / 2, o / 2);
432
+ e.moveTo(t + n, i), e.lineTo(t + s - n, i), e.arcTo(t + s, i, t + s, i + n, n), e.lineTo(t + s, i + o - n), e.arcTo(t + s, i + o, t + s - n, i + o, n), e.lineTo(t + n, i + o), e.arcTo(t, i + o, t, i + o - n, n), e.lineTo(t, i + n), e.arcTo(t, i, t + n, i, n);
340
433
  }
341
434
  /**
342
435
  * Render a circle.
343
436
  */
344
437
  renderCircle(e, t) {
345
438
  if (this.drawsOutline(t)) {
346
- const { x: i, y: o, radius: s } = t;
439
+ const { x: i, y: s, radius: o } = t;
347
440
  return this.renderOutlined(
348
441
  e,
349
442
  t,
350
443
  () => {
351
- e.beginPath(), e.arc(i, o, s, 0, Math.PI * 2), e.fill();
444
+ e.beginPath(), e.arc(i, s, o, 0, Math.PI * 2), e.fill();
352
445
  },
353
446
  (a, n) => {
354
- if (n) return n.circle(i, o, s, a);
355
- e.beginPath(), e.arc(i, o, s, -Math.PI / 2, -Math.PI / 2 + Math.PI * 2 * a), e.stroke();
447
+ if (n) return n.circle(i, s, o, a);
448
+ e.beginPath(), e.arc(i, s, o, -Math.PI / 2, -Math.PI / 2 + Math.PI * 2 * a), e.stroke();
356
449
  }
357
450
  );
358
451
  }
@@ -362,11 +455,11 @@ class v {
362
455
  * Render text.
363
456
  */
364
457
  renderText(e, t) {
365
- const i = t.fontSize ?? 16, o = t.fontFamily ?? "sans-serif", s = t.fontWeight ?? 400;
366
- if (e.font = `${s} ${i}px ${o}`, e.textAlign = t.textAlign ?? "left", e.textBaseline = t.textBaseline ?? "top", t.fillStyle) {
458
+ const i = t.fontSize ?? 16, s = t.fontFamily ?? "sans-serif", o = t.fontWeight ?? 400;
459
+ if (e.font = `${o} ${i}px ${s}`, e.textAlign = t.textAlign ?? "left", e.textBaseline = t.textBaseline ?? "top", t.fillStyle) {
367
460
  if (t.shine !== void 0 && typeof t.fillStyle == "string") {
368
- const a = e.measureText(t.text).width, n = t.textAlign ?? "left", r = n === "center" ? t.x - a / 2 : n === "right" ? t.x - a : t.x, l = e.createLinearGradient(r, t.y, r + a, t.y);
369
- for (const h of Y(t.shine, t.fillStyle))
461
+ const a = e.measureText(t.text).width, n = t.textAlign ?? "left", c = n === "center" ? t.x - a / 2 : n === "right" ? t.x - a : t.x, l = e.createLinearGradient(c, t.y, c + a, t.y);
462
+ for (const h of L(t.shine, t.fillStyle))
370
463
  l.addColorStop(h.offset, h.color);
371
464
  e.fillStyle = l;
372
465
  }
@@ -382,12 +475,12 @@ class v {
382
475
  const i = [
383
476
  { x: t.x, y: t.y },
384
477
  { x: t.x2, y: t.y2 }
385
- ], o = Math.hypot(t.x2 - t.x, t.y2 - t.y);
478
+ ], s = Math.hypot(t.x2 - t.x, t.y2 - t.y);
386
479
  return this.renderOutlined(
387
480
  e,
388
481
  t,
389
482
  void 0,
390
- (s, a) => S(e, [{ kind: "line", points: i, length: o }], s, a)
483
+ (o, a) => S(e, [{ kind: "line", points: i, length: s }], o, a)
391
484
  );
392
485
  }
393
486
  e.beginPath(), e.moveTo(t.x, t.y), e.lineTo(t.x2, t.y2), t.strokeStyle && e.stroke(), e.closePath();
@@ -403,7 +496,7 @@ class v {
403
496
  e,
404
497
  t,
405
498
  () => e.fill(i),
406
- (o, s) => S(e, R(t.d), o, s)
499
+ (s, o) => S(e, x(t.d), s, o)
407
500
  );
408
501
  t.fillStyle && e.fill(i), t.strokeStyle && e.stroke(i);
409
502
  }
@@ -413,13 +506,13 @@ class v {
413
506
  renderImage(e, t) {
414
507
  if (!t.image) return;
415
508
  t.opacity !== void 0 && (e.globalAlpha = t.opacity);
416
- const { x: i, y: o, width: s, height: a } = t, n = t.objectFit ?? "fill", r = t.borderRadius ?? 0, l = t.image, h = l.naturalWidth || l.videoWidth || l.width || s, f = l.naturalHeight || l.videoHeight || l.height || a;
417
- let p = i, u = o, d = s, m = a;
509
+ const { x: i, y: s, width: o, height: a } = t, n = t.objectFit ?? "fill", c = t.borderRadius ?? 0, l = t.image, h = l.naturalWidth || l.videoWidth || l.width || o, f = l.naturalHeight || l.videoHeight || l.height || a;
510
+ let p = i, u = s, d = o, m = a;
418
511
  if (n !== "fill" && h > 0 && f > 0) {
419
- const y = n === "cover" ? Math.max(s / h, a / f) : Math.min(s / h, a / f);
420
- d = h * y, m = f * y, p = i + (s - d) / 2, u = o + (a - m) / 2;
512
+ const y = n === "cover" ? Math.max(o / h, a / f) : Math.min(o / h, a / f);
513
+ d = h * y, m = f * y, p = i + (o - d) / 2, u = s + (a - m) / 2;
421
514
  }
422
- e.save(), e.beginPath(), r > 0 && typeof e.roundRect == "function" ? e.roundRect(i, o, s, a, r) : e.rect(i, o, s, a), e.clip(), e.drawImage(t.image, p, u, d, m), e.restore();
515
+ e.save(), e.beginPath(), c > 0 && typeof e.roundRect == "function" ? e.roundRect(i, s, o, a, c) : e.rect(i, s, o, a), e.clip(), e.drawImage(t.image, p, u, d, m), e.restore();
423
516
  }
424
517
  /**
425
518
  * Render a custom target by calling its draw function in local coordinates.
@@ -522,12 +615,56 @@ class v {
522
615
  */
523
616
  static loadImage(e) {
524
617
  return new Promise((t, i) => {
525
- const o = new Image();
526
- o.onload = () => t(o), o.onerror = i, o.src = e;
618
+ const s = new Image();
619
+ s.onload = () => t(s), s.onerror = i, s.src = e;
527
620
  });
528
621
  }
529
622
  }
530
- const b = "http://www.w3.org/2000/svg", N = /* @__PURE__ */ new Set([
623
+ function se(r, e) {
624
+ const t = r.length / 4, i = new Float32Array(t * 3), s = Math.min(0.999, Math.max(0, e));
625
+ for (let o = 0; o < t; o++) {
626
+ const a = r[o * 4] / 255, n = r[o * 4 + 1] / 255, c = r[o * 4 + 2] / 255, l = r[o * 4 + 3] / 255, h = Math.max(a, n, c);
627
+ if (h <= s) continue;
628
+ const f = (h - s) / (1 - s) * l / h;
629
+ i[o * 3] = a * f, i[o * 3 + 1] = n * f, i[o * 3 + 2] = c * f;
630
+ }
631
+ return i;
632
+ }
633
+ function k(r, e, t, i, s) {
634
+ const o = new Float32Array(r.length), a = s ? t : e, n = s ? e : t, c = (h, f) => (s ? h * e + f : f * e + h) * 3, l = i * 2 + 1;
635
+ for (let h = 0; h < a; h++)
636
+ for (let f = 0; f < 3; f++) {
637
+ let p = 0;
638
+ for (let u = -i; u <= i; u++) p += r[c(h, Math.min(n - 1, Math.max(0, u))) + f];
639
+ for (let u = 0; u < n; u++) {
640
+ o[c(h, u) + f] = p / l;
641
+ const d = r[c(h, Math.max(0, u - i)) + f], m = r[c(h, Math.min(n - 1, u + i + 1)) + f];
642
+ p += m - d;
643
+ }
644
+ }
645
+ return o;
646
+ }
647
+ function E(r, e, t, i) {
648
+ const s = Math.max(1, Math.round(i / Math.sqrt(3)));
649
+ let o = r;
650
+ for (let a = 0; a < 3; a++)
651
+ o = k(o, e, t, s, !0), o = k(o, e, t, s, !1);
652
+ return o;
653
+ }
654
+ function Te(r, e = {}) {
655
+ const t = r.canvas, i = t.width, s = t.height;
656
+ if (!(i > 0 && s > 0)) return;
657
+ const o = Math.max(1, Math.round(e.downsample ?? 4)), a = Math.max(1, Math.ceil(i / o)), n = Math.max(1, Math.ceil(s / o)), c = F(r, a, n), l = c?.getContext("2d");
658
+ if (!c || !l) return;
659
+ l.imageSmoothingEnabled = !0, l.drawImage(r.canvas, 0, 0, a, n);
660
+ const h = se(l.getImageData(0, 0, a, n).data, e.threshold ?? 0.55), f = (e.radius ?? Math.max(i, s) * 0.02) / o, p = E(h, a, n, f), u = E(h, a, n, f * 3), d = e.halo ?? 0.6, m = l.createImageData(a, n);
661
+ for (let y = 0; y < a * n; y++) {
662
+ for (let w = 0; w < 3; w++) m.data[y * 4 + w] = Math.round(Math.min(1, p[y * 3 + w] + u[y * 3 + w] * d) * 255);
663
+ m.data[y * 4 + 3] = 255;
664
+ }
665
+ l.putImageData(m, 0, 0), r.save(), r.setTransform(1, 0, 0, 1, 0, 0), r.globalCompositeOperation = "lighter", r.globalAlpha = Math.max(0, e.strength ?? 0.9), r.imageSmoothingEnabled = !0, r.drawImage(c, 0, 0, i, s), r.restore();
666
+ }
667
+ const M = "http://www.w3.org/2000/svg", oe = /* @__PURE__ */ new Set([
531
668
  "fill",
532
669
  "stroke",
533
670
  "d",
@@ -547,7 +684,7 @@ const b = "http://www.w3.org/2000/svg", N = /* @__PURE__ */ new Set([
547
684
  "height",
548
685
  "viewBox",
549
686
  "preserveAspectRatio"
550
- ]), k = {
687
+ ]), X = {
551
688
  strokeWidth: "stroke-width",
552
689
  strokeLinecap: "stroke-linecap",
553
690
  strokeLinejoin: "stroke-linejoin",
@@ -558,7 +695,7 @@ const b = "http://www.w3.org/2000/svg", N = /* @__PURE__ */ new Set([
558
695
  strokeOpacity: "stroke-opacity",
559
696
  borderRadius: "rx"
560
697
  // Map CSS borderRadius to SVG rx
561
- }, W = /* @__PURE__ */ new Set([
698
+ }, ne = /* @__PURE__ */ new Set([
562
699
  "x",
563
700
  // Position x treated as translateX
564
701
  "y",
@@ -566,8 +703,10 @@ const b = "http://www.w3.org/2000/svg", N = /* @__PURE__ */ new Set([
566
703
  "translateX",
567
704
  "translateY",
568
705
  "rotate",
706
+ "rotateZ",
569
707
  "rotateX",
570
708
  "rotateY",
709
+ "z",
571
710
  "scale",
572
711
  "scaleX",
573
712
  "scaleY",
@@ -577,8 +716,8 @@ const b = "http://www.w3.org/2000/svg", N = /* @__PURE__ */ new Set([
577
716
  "motionPathX",
578
717
  "motionPathY",
579
718
  "motionPathRotate"
580
- ]), H = /* @__PURE__ */ new Set(["clipTop", "clipRight", "clipBottom", "clipLeft"]);
581
- class oe {
719
+ ]), re = /* @__PURE__ */ new Set(["clipTop", "clipRight", "clipBottom", "clipLeft"]);
720
+ class ve {
582
721
  targets = /* @__PURE__ */ new Map();
583
722
  /**
584
723
  * Register an SVG element as an animation target.
@@ -609,51 +748,53 @@ class oe {
609
748
  */
610
749
  applyState(e) {
611
750
  for (const [t, i] of e.values) {
612
- const o = this.targets.get(t);
613
- o && this.applyProperties(o, i);
751
+ const s = this.targets.get(t);
752
+ s && this.applyProperties(s, i);
614
753
  }
615
754
  }
616
755
  /**
617
756
  * Apply properties to a single SVG element.
618
757
  */
619
758
  applyProperties(e, t) {
620
- const i = {}, o = {}, s = {}, a = {};
621
- let n = !1;
622
- for (const [r, l] of t)
623
- r !== "drawOn" && (W.has(r) ? i[r] = l : r === "originX" || r === "originY" ? typeof l == "number" && (o[r] = l) : r === "perspective" ? typeof l == "number" && (i.perspective = l) : H.has(r) ? typeof l == "number" && (s[r] = l) : O.has(r) ? (a[r] = l, n = !0) : r === "text" ? typeof l == "string" && C(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));
624
- if (Object.keys(i).length > 0) {
625
- const r = this.buildCssTransformString(i);
626
- e.style.transform = r, I(e);
759
+ const i = {};
760
+ let s = null;
761
+ const o = {}, a = {}, n = {};
762
+ let c = !1;
763
+ for (const [l, h] of t)
764
+ l !== "drawOn" && (ne.has(l) ? i[l] = h : l === "quaternion" ? s = q(h) : l === "originX" || l === "originY" ? typeof h == "number" && (o[l] = h) : l === "perspective" ? typeof h == "number" && (i.perspective = h) : re.has(l) ? typeof h == "number" && (a[l] = h) : z.has(l) ? (n[l] = h, c = !0) : l === "text" ? typeof h == "string" && j(e, h) : l === "shine" ? typeof h == "number" && this.applyShine(e, h) : l === "opacity" ? (e.setAttribute("fill-opacity", String(h)), e.setAttribute("stroke-opacity", String(h))) : this.applyAttribute(e, l, h));
765
+ if (Object.keys(i).length > 0 || s) {
766
+ const l = this.buildCssTransformString(i, s);
767
+ e.style.transform = l, Z(e);
627
768
  }
628
769
  if (Object.keys(o).length > 0) {
629
- const r = e.style;
630
- r.transformBox = "fill-box", r.transformOrigin = `${o.originX ?? 50}% ${o.originY ?? 50}%`;
770
+ const l = e.style;
771
+ l.transformBox = "fill-box", l.transformOrigin = `${o.originX ?? 50}% ${o.originY ?? 50}%`;
631
772
  }
632
- if (Object.keys(s).length > 0) {
633
- const r = s.clipTop ?? 0, l = s.clipRight ?? 0, h = s.clipBottom ?? 0, f = s.clipLeft ?? 0;
634
- e.style.clipPath = `inset(${r}% ${l}% ${h}% ${f}%)`;
773
+ if (Object.keys(a).length > 0) {
774
+ const l = a.clipTop ?? 0, h = a.clipRight ?? 0, f = a.clipBottom ?? 0, p = a.clipLeft ?? 0;
775
+ e.style.clipPath = `inset(${l}% ${h}% ${f}% ${p}%)`;
635
776
  }
636
- if (n) {
637
- const r = _(a);
638
- r && (e.style.filter = r);
777
+ if (c) {
778
+ const l = O(n);
779
+ l && (e.style.filter = l);
639
780
  }
640
781
  }
641
782
  /**
642
783
  * Build a CSS transform string (for use with transform-origin).
643
784
  */
644
- buildCssTransformString(e) {
645
- const t = [];
646
- e.perspective !== void 0 && t.push(`perspective(${e.perspective}px)`);
647
- const i = e.motionPathX ?? e.x ?? e.translateX, o = e.motionPathY ?? e.y ?? e.translateY;
648
- (i !== void 0 || o !== void 0) && t.push(`translate(${i ?? 0}px, ${o ?? 0}px)`);
649
- const s = e.motionPathRotate ?? e.rotate;
650
- if (s !== void 0 && t.push(`rotate(${s}deg)`), e.rotateX !== void 0 && t.push(`rotateX(${e.rotateX}deg)`), e.rotateY !== void 0 && t.push(`rotateY(${e.rotateY}deg)`), e.scale !== void 0)
651
- t.push(`scale(${e.scale})`);
785
+ buildCssTransformString(e, t = null) {
786
+ const i = [];
787
+ e.perspective !== void 0 && e.perspective > 0 && i.push(`perspective(${e.perspective}px)`);
788
+ const s = e.motionPathX ?? e.x ?? e.translateX, o = e.motionPathY ?? e.y ?? e.translateY;
789
+ e.z !== void 0 ? i.push(`translate3d(${s ?? 0}px, ${o ?? 0}px, ${e.z}px)`) : (s !== void 0 || o !== void 0) && i.push(`translate(${s ?? 0}px, ${o ?? 0}px)`);
790
+ const a = e.motionPathRotate ?? e.rotate ?? e.rotateZ;
791
+ if (a !== void 0 && i.push(`rotate(${a}deg)`), e.rotateX !== void 0 && i.push(`rotateX(${e.rotateX}deg)`), e.rotateY !== void 0 && i.push(`rotateY(${e.rotateY}deg)`), t && i.push(t), e.scale !== void 0)
792
+ i.push(`scale(${e.scale})`);
652
793
  else if (e.scaleX !== void 0 || e.scaleY !== void 0) {
653
- const a = e.scaleX ?? 1, n = e.scaleY ?? 1;
654
- t.push(`scale(${a}, ${n})`);
794
+ const n = e.scaleX ?? 1, c = e.scaleY ?? 1;
795
+ i.push(`scale(${n}, ${c})`);
655
796
  }
656
- return e.skewX !== void 0 && t.push(`skewX(${e.skewX}deg)`), e.skewY !== void 0 && t.push(`skewY(${e.skewY}deg)`), t.join(" ");
797
+ return e.skewX !== void 0 && i.push(`skewX(${e.skewX}deg)`), e.skewY !== void 0 && i.push(`skewY(${e.skewY}deg)`), i.join(" ");
657
798
  }
658
799
  /**
659
800
  * Apply a single attribute to an SVG element.
@@ -664,39 +805,39 @@ class oe {
664
805
  * gradient lives in the owner SVG's <defs> and is reused across frames.
665
806
  */
666
807
  applyShine(e, t) {
667
- const i = e.ownerSVGElement, o = e.ownerDocument;
668
- if (!i || !o) return;
669
- const s = e;
670
- s.dataset.shineBase || (s.dataset.shineBase = e.getAttribute("fill") || "#000000");
671
- const a = s.dataset.shineBase;
808
+ const i = e.ownerSVGElement, s = e.ownerDocument;
809
+ if (!i || !s) return;
810
+ const o = e;
811
+ o.dataset.shineBase || (o.dataset.shineBase = e.getAttribute("fill") || "#000000");
812
+ const a = o.dataset.shineBase;
672
813
  let n = i.querySelector("defs");
673
- n || (n = o.createElementNS(b, "defs"), i.insertBefore(n, i.firstChild));
674
- let r = s.dataset.shineGrad, l = r ? n.querySelector(`#${r}`) : null;
675
- for (l || (r = `tinyfly-shine-${Math.random().toString(36).slice(2, 9)}`, s.dataset.shineGrad = r, l = o.createElementNS(b, "linearGradient"), l.setAttribute("id", r), n.appendChild(l)); l.firstChild; ) l.removeChild(l.firstChild);
676
- for (const h of Y(t, a)) {
677
- const f = o.createElementNS(b, "stop");
814
+ n || (n = s.createElementNS(M, "defs"), i.insertBefore(n, i.firstChild));
815
+ let c = o.dataset.shineGrad, l = c ? n.querySelector(`#${c}`) : null;
816
+ for (l || (c = `tinyfly-shine-${Math.random().toString(36).slice(2, 9)}`, o.dataset.shineGrad = c, l = s.createElementNS(M, "linearGradient"), l.setAttribute("id", c), n.appendChild(l)); l.firstChild; ) l.removeChild(l.firstChild);
817
+ for (const h of L(t, a)) {
818
+ const f = s.createElementNS(M, "stop");
678
819
  f.setAttribute("offset", String(h.offset)), f.setAttribute("stop-color", h.color), l.appendChild(f);
679
820
  }
680
- e.setAttribute("fill", `url(#${r})`);
821
+ e.setAttribute("fill", `url(#${c})`);
681
822
  }
682
823
  applyAttribute(e, t, i) {
683
- let o = t;
684
- k[t] ? o = k[t] : N.has(t) && (o = t);
685
- const s = Array.isArray(i) ? i.join(" ") : String(i);
686
- e.setAttribute(o, s);
824
+ let s = t;
825
+ X[t] ? s = X[t] : oe.has(t) && (s = t);
826
+ const o = Array.isArray(i) ? i.join(" ") : String(i);
827
+ e.setAttribute(s, o);
687
828
  }
688
829
  }
689
- const V = `
830
+ const ae = `
690
831
  attribute vec2 a_position;
691
832
  attribute vec2 a_texCoord;
692
- uniform mat3 u_matrix;
833
+ uniform mat4 u_matrix;
693
834
  varying vec2 v_texCoord;
694
835
  void main() {
695
- vec3 position = u_matrix * vec3(a_position, 1.0);
696
- gl_Position = vec4(position.xy, 0.0, 1.0);
836
+ // w carries the perspective, so textures are interpolated perspective-correct.
837
+ gl_Position = u_matrix * vec4(a_position, 0.0, 1.0);
697
838
  v_texCoord = a_texCoord;
698
839
  }
699
- `, j = `
840
+ `, ce = `
700
841
  precision mediump float;
701
842
  uniform vec4 u_color;
702
843
  uniform sampler2D u_texture;
@@ -707,7 +848,7 @@ void main() {
707
848
  vec4 color = u_useTexture ? texture2D(u_texture, v_texCoord) : u_color;
708
849
  gl_FragColor = vec4(color.rgb, color.a * u_opacity);
709
850
  }
710
- `, z = /* @__PURE__ */ new Set([
851
+ `, le = /* @__PURE__ */ new Set([
711
852
  "x",
712
853
  "y",
713
854
  "width",
@@ -715,6 +856,10 @@ void main() {
715
856
  "opacity",
716
857
  "rotate",
717
858
  "rotateZ",
859
+ "rotateX",
860
+ "rotateY",
861
+ "z",
862
+ "perspective",
718
863
  "scale",
719
864
  "scaleX",
720
865
  "scaleY",
@@ -724,7 +869,7 @@ void main() {
724
869
  "motionPathY",
725
870
  "motionPathRotate"
726
871
  ]);
727
- class se {
872
+ class be {
728
873
  gl;
729
874
  program;
730
875
  positionBuffer;
@@ -735,7 +880,7 @@ class se {
735
880
  basePositions = /* @__PURE__ */ new Map();
736
881
  locations;
737
882
  constructor(e) {
738
- this.gl = e, this.program = q(e, V, j), this.locations = {
883
+ this.gl = e, this.program = ue(e, ae, ce), this.locations = {
739
884
  position: e.getAttribLocation(this.program, "a_position"),
740
885
  texCoord: e.getAttribLocation(this.program, "a_texCoord"),
741
886
  matrix: e.getUniformLocation(this.program, "u_matrix"),
@@ -743,7 +888,7 @@ class se {
743
888
  texture: e.getUniformLocation(this.program, "u_texture"),
744
889
  useTexture: e.getUniformLocation(this.program, "u_useTexture"),
745
890
  opacity: e.getUniformLocation(this.program, "u_opacity")
746
- }, this.positionBuffer = E(e, [0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1]), this.texCoordBuffer = E(e, [0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1]);
891
+ }, this.positionBuffer = Y(e, [0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1]), this.texCoordBuffer = Y(e, [0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1]);
747
892
  }
748
893
  registerTarget(e, t) {
749
894
  this.targets.set(e, t), this.basePositions.set(e, { x: t.x, y: t.y });
@@ -762,79 +907,92 @@ class se {
762
907
  /** Apply engine state to the registered targets. */
763
908
  applyState(e) {
764
909
  for (const [t, i] of e.values) {
765
- const o = this.targets.get(t);
766
- if (!o) continue;
767
- const s = this.basePositions.get(t) ?? { x: 0, y: 0 };
910
+ const s = this.targets.get(t);
911
+ if (!s) continue;
912
+ const o = this.basePositions.get(t) ?? { x: 0, y: 0 };
768
913
  for (const [a, n] of i)
769
- this.applyProperty(o, s, a, n);
914
+ this.applyProperty(s, o, a, n);
770
915
  }
771
916
  }
772
- applyProperty(e, t, i, o) {
773
- if (typeof o == "number") {
917
+ applyProperty(e, t, i, s) {
918
+ if (typeof s == "number") {
774
919
  if (i === "x" || i === "motionPathX") {
775
- e.x = t.x + o;
920
+ e.x = t.x + s;
776
921
  return;
777
922
  }
778
923
  if (i === "y" || i === "motionPathY") {
779
- e.y = t.y + o;
924
+ e.y = t.y + s;
780
925
  return;
781
926
  }
782
927
  if (i === "rotateZ" || i === "motionPathRotate") {
783
- e.rotate = o;
928
+ e.rotate = s;
784
929
  return;
785
930
  }
786
- if (z.has(i)) {
787
- e[i] = o;
931
+ if (le.has(i)) {
932
+ e[i] = s;
788
933
  return;
789
934
  }
790
935
  }
791
- typeof o == "string" && i === "fill" && (e.fill = o);
936
+ typeof s == "string" && i === "fill" && (e.fill = s), i === "quaternion" && Array.isArray(s) && (e.quaternion = s);
792
937
  }
793
938
  /** Draw every registered target. */
794
939
  render() {
795
940
  const e = this.gl, { width: t, height: i } = e.canvas;
796
- e.viewport(0, 0, t, i), e.clearColor(0, 0, 0, 0), e.clear(e.COLOR_BUFFER_BIT), e.enable(e.BLEND), e.blendFunc(e.SRC_ALPHA, e.ONE_MINUS_SRC_ALPHA), e.useProgram(this.program), M(e, this.positionBuffer, this.locations.position), M(e, this.texCoordBuffer, this.locations.texCoord);
797
- for (const [o, s] of this.targets)
798
- this.drawTarget(o, s, t, i);
799
- }
800
- drawTarget(e, t, i, o) {
801
- const s = this.gl, a = J(t, i, o);
802
- if (s.uniformMatrix3fv(this.locations.matrix, !1, a), s.uniform1f(this.locations.opacity, t.opacity ?? 1), t.texture)
803
- s.bindTexture(s.TEXTURE_2D, this.textureFor(e, t.texture)), s.uniform1i(this.locations.useTexture, 1), s.uniform1i(this.locations.texture, 0);
941
+ e.viewport(0, 0, t, i), e.clearColor(0, 0, 0, 0), e.clear(e.COLOR_BUFFER_BIT), e.enable(e.BLEND), e.blendFunc(e.SRC_ALPHA, e.ONE_MINUS_SRC_ALPHA), e.useProgram(this.program), $(e, this.positionBuffer, this.locations.position), $(e, this.texCoordBuffer, this.locations.texCoord);
942
+ for (const [s, o] of this.targets)
943
+ this.drawTarget(s, o, t, i);
944
+ }
945
+ drawTarget(e, t, i, s) {
946
+ const o = this.gl;
947
+ if (t.backfaceVisibility === "hidden" && I(G(t))) return;
948
+ const a = he(t, i, s);
949
+ if (o.uniformMatrix4fv(this.locations.matrix, !1, a), o.uniform1f(this.locations.opacity, t.opacity ?? 1), t.texture)
950
+ o.bindTexture(o.TEXTURE_2D, this.textureFor(e, t.texture)), o.uniform1i(this.locations.useTexture, 1), o.uniform1i(this.locations.texture, 0);
804
951
  else {
805
- s.uniform1i(this.locations.useTexture, 0);
806
- const [n, r, l] = Z(t.fill ?? "#ffffff");
807
- s.uniform4f(this.locations.color, n, r, l, 1);
952
+ o.uniform1i(this.locations.useTexture, 0);
953
+ const [n, c, l] = fe(t.fill ?? "#ffffff");
954
+ o.uniform4f(this.locations.color, n, c, l, 1);
808
955
  }
809
- s.drawArrays(s.TRIANGLES, 0, 6);
956
+ o.drawArrays(o.TRIANGLES, 0, 6);
810
957
  }
811
958
  textureFor(e, t) {
812
959
  const i = this.textures.get(e);
813
960
  if (i) return i;
814
- const o = this.gl, s = o.createTexture();
815
- return o.bindTexture(o.TEXTURE_2D, s), o.texParameteri(o.TEXTURE_2D, o.TEXTURE_WRAP_S, o.CLAMP_TO_EDGE), o.texParameteri(o.TEXTURE_2D, o.TEXTURE_WRAP_T, o.CLAMP_TO_EDGE), o.texParameteri(o.TEXTURE_2D, o.TEXTURE_MIN_FILTER, o.LINEAR), o.texImage2D(o.TEXTURE_2D, 0, o.RGBA, o.RGBA, o.UNSIGNED_BYTE, t), this.textures.set(e, s), s;
961
+ const s = this.gl, o = s.createTexture();
962
+ return s.bindTexture(s.TEXTURE_2D, o), s.texParameteri(s.TEXTURE_2D, s.TEXTURE_WRAP_S, s.CLAMP_TO_EDGE), s.texParameteri(s.TEXTURE_2D, s.TEXTURE_WRAP_T, s.CLAMP_TO_EDGE), s.texParameteri(s.TEXTURE_2D, s.TEXTURE_MIN_FILTER, s.LINEAR), s.texImage2D(s.TEXTURE_2D, 0, s.RGBA, s.RGBA, s.UNSIGNED_BYTE, t), this.textures.set(e, o), o;
816
963
  }
817
964
  /** Release GL resources. */
818
965
  destroy() {
819
966
  this.clearTargets(), this.gl.deleteProgram(this.program), this.gl.deleteBuffer(this.positionBuffer), this.gl.deleteBuffer(this.texCoordBuffer);
820
967
  }
821
968
  }
822
- function J(c, e, t) {
823
- const i = (c.scale ?? c.scaleX ?? 1) * c.width, o = (c.scale ?? c.scaleY ?? 1) * c.height, s = (c.originX ?? 50) / 100, a = (c.originY ?? 50) / 100, n = (c.rotate ?? 0) * Math.PI / 180, r = Math.cos(n), l = Math.sin(n), h = -s, f = -a, p = r * i, u = l * i, d = -l * o, m = r * o, y = c.x + p * h + d * f, $ = c.y + u * h + m * f, w = 2 / e, P = -2 / t;
969
+ function Pe(r, e, t) {
970
+ const i = (r.scale ?? r.scaleX ?? 1) * r.width, s = (r.scale ?? r.scaleY ?? 1) * r.height, o = (r.originX ?? 50) / 100, a = (r.originY ?? 50) / 100, n = (r.rotate ?? 0) * Math.PI / 180, c = Math.cos(n), l = Math.sin(n), h = -o, f = -a, p = c * i, u = l * i, d = -l * s, m = c * s, y = r.x + p * h + d * f, w = r.y + u * h + m * f, b = 2 / e, P = -2 / t;
824
971
  return new Float32Array([
825
- p * w,
972
+ p * b,
826
973
  u * P,
827
974
  0,
828
- d * w,
975
+ d * b,
829
976
  m * P,
830
977
  0,
831
- y * w - 1,
832
- $ * P + 1,
978
+ y * b - 1,
979
+ w * P + 1,
833
980
  1
834
981
  ]);
835
982
  }
836
- function Z(c) {
837
- const e = c.trim().replace("#", "");
983
+ function G(r) {
984
+ const e = (r.originX ?? 50) / 100, t = (r.originY ?? 50) / 100, i = { x: r.x, y: r.y }, s = T.multiply(
985
+ T.translation([r.x, r.y, 0]),
986
+ T.multiply(T.scaling([r.width, r.height, 1]), T.translation([-e, -t, 0]))
987
+ );
988
+ return T.multiply(C(r, { x: 0, y: 0 }, i), s);
989
+ }
990
+ function he(r, e, t) {
991
+ const i = [2 / e, 0, 0, 0, 0, -2 / t, 0, 0, 0, 0, 0, 0, -1, 1, 0, 1];
992
+ return new Float32Array(T.multiply(i, G(r)));
993
+ }
994
+ function fe(r) {
995
+ const e = r.trim().replace("#", "");
838
996
  return e.length === 3 ? [
839
997
  Number.parseInt(e[0] + e[0], 16) / 255,
840
998
  Number.parseInt(e[1] + e[1], 16) / 255,
@@ -845,46 +1003,51 @@ function Z(c) {
845
1003
  Number.parseInt(e.slice(4, 6), 16) / 255
846
1004
  ] : [1, 1, 1];
847
1005
  }
848
- function q(c, e, t) {
849
- const i = c.createProgram();
1006
+ function ue(r, e, t) {
1007
+ const i = r.createProgram();
850
1008
  if (!i) throw new Error("WebGLAdapter: could not create a program");
851
- if (c.attachShader(i, A(c, c.VERTEX_SHADER, e)), c.attachShader(i, A(c, c.FRAGMENT_SHADER, t)), c.linkProgram(i), !c.getProgramParameter(i, c.LINK_STATUS))
852
- throw new Error(`WebGLAdapter: program link failed — ${c.getProgramInfoLog(i)}`);
1009
+ if (r.attachShader(i, _(r, r.VERTEX_SHADER, e)), r.attachShader(i, _(r, r.FRAGMENT_SHADER, t)), r.linkProgram(i), !r.getProgramParameter(i, r.LINK_STATUS))
1010
+ throw new Error(`WebGLAdapter: program link failed — ${r.getProgramInfoLog(i)}`);
853
1011
  return i;
854
1012
  }
855
- function A(c, e, t) {
856
- const i = c.createShader(e);
1013
+ function _(r, e, t) {
1014
+ const i = r.createShader(e);
857
1015
  if (!i) throw new Error("WebGLAdapter: could not create a shader");
858
- if (c.shaderSource(i, t), c.compileShader(i), !c.getShaderParameter(i, c.COMPILE_STATUS))
859
- throw new Error(`WebGLAdapter: shader compile failed — ${c.getShaderInfoLog(i)}`);
1016
+ if (r.shaderSource(i, t), r.compileShader(i), !r.getShaderParameter(i, r.COMPILE_STATUS))
1017
+ throw new Error(`WebGLAdapter: shader compile failed — ${r.getShaderInfoLog(i)}`);
860
1018
  return i;
861
1019
  }
862
- function E(c, e) {
863
- const t = c.createBuffer();
1020
+ function Y(r, e) {
1021
+ const t = r.createBuffer();
864
1022
  if (!t) throw new Error("WebGLAdapter: could not create a buffer");
865
- return c.bindBuffer(c.ARRAY_BUFFER, t), c.bufferData(c.ARRAY_BUFFER, new Float32Array(e), c.STATIC_DRAW), t;
1023
+ return r.bindBuffer(r.ARRAY_BUFFER, t), r.bufferData(r.ARRAY_BUFFER, new Float32Array(e), r.STATIC_DRAW), t;
866
1024
  }
867
- function M(c, e, t) {
868
- t < 0 || (c.bindBuffer(c.ARRAY_BUFFER, e), c.enableVertexAttribArray(t), c.vertexAttribPointer(t, 2, c.FLOAT, !1, 0, 0));
1025
+ function $(r, e, t) {
1026
+ t < 0 || (r.bindBuffer(r.ARRAY_BUFFER, e), r.enableVertexAttribArray(t), r.vertexAttribPointer(t, 2, r.FLOAT, !1, 0, 0));
869
1027
  }
870
1028
  export {
871
- v as CanvasAdapter,
872
- ae as DOMAdapter,
873
- oe as SVGAdapter,
874
- se as WebGLAdapter,
875
- le as boilFrame,
876
- U as buildFlipTracks,
1029
+ R as CanvasAdapter,
1030
+ xe as DOMAdapter,
1031
+ ve as SVGAdapter,
1032
+ be as WebGLAdapter,
1033
+ Te as applyBloom,
1034
+ Ae as boilFrame,
1035
+ E as boxBlur,
1036
+ se as brightPass,
1037
+ te as buildFlipTracks,
1038
+ F as canvasLike,
877
1039
  S as drawOutline,
878
- te as flip,
879
- ie as isGradient,
880
- Z as parseColor,
881
- F as partialPath,
882
- he as pathLength,
883
- R as pathOutline,
884
- fe as pointAlong,
885
- J as quadMatrix,
886
- g as recordFlipState,
887
- D as rectOutline,
888
- C as setTextContent,
889
- G as sketchPen
1040
+ ye as flip,
1041
+ we as isGradient,
1042
+ fe as parseColor,
1043
+ K as partialPath,
1044
+ ke as pathLength,
1045
+ x as pathOutline,
1046
+ Ee as pointAlong,
1047
+ Pe as quadMatrix,
1048
+ he as quadMatrix3d,
1049
+ ee as recordFlipState,
1050
+ ie as rectOutline,
1051
+ j as setTextContent,
1052
+ Q as sketchPen
890
1053
  };