@algorisys/tinyfly 0.82.0 → 0.86.2

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 (60) hide show
  1. package/README.md +11 -4
  2. package/lib/addons/adapters.js +363 -248
  3. package/lib/addons/characters.js +1652 -1470
  4. package/lib/addons/dom-adapter-Cphr2HZn.js +372 -0
  5. package/lib/addons/gsap-compat.js +197 -187
  6. package/lib/addons/load-scene-vp14_Jj-.js +324 -0
  7. package/lib/addons/scene-3d-webgl.js +237 -0
  8. package/lib/addons/scene-3d.js +306 -0
  9. package/lib/addons/shading-ByG9UXd0.js +85 -0
  10. package/lib/browser/tinyfly-scene-3d-webgl.iife.js +114 -0
  11. package/lib/browser/tinyfly-scene-3d.iife.js +3 -0
  12. package/lib/browser/tinyfly.iife.js +4 -4
  13. package/lib/browser/tinyfly.js +3028 -2480
  14. package/lib/browser/tinyfly.umd.js +4 -4
  15. package/lib/cli/tools.js +137 -22
  16. package/lib/embed/tinyfly-embed.iife.js +4 -4
  17. package/lib/embed/tinyfly-embed.js +921 -833
  18. package/lib/engine/tinyfly-engine.js +1022 -776
  19. package/lib/engine/tinyfly-engine.umd.cjs +2 -2
  20. package/lib/headless/headless.js +264 -7
  21. package/lib/player/tinyfly-player.es.js +459 -371
  22. package/lib/player/tinyfly-player.iife.js +2 -2
  23. package/lib/player/tinyfly-player.umd.js +2 -2
  24. package/lib/types/adapters/canvas/canvas-adapter.d.ts +36 -0
  25. package/lib/types/adapters/transform-3d.d.ts +99 -0
  26. package/lib/types/adapters/webgl/webgl-adapter.d.ts +17 -0
  27. package/lib/types/characters/character.d.ts +20 -1
  28. package/lib/types/characters/index.d.ts +2 -0
  29. package/lib/types/characters/rig/body-plan.d.ts +3 -1
  30. package/lib/types/characters/rig/skeleton.d.ts +57 -0
  31. package/lib/types/characters/scene-objects.d.ts +2 -0
  32. package/lib/types/compat/gsap/vars.d.ts +8 -0
  33. package/lib/types/engine/core/bake.d.ts +3 -1
  34. package/lib/types/engine/index.d.ts +1 -0
  35. package/lib/types/engine/interpolation/interpolators.d.ts +10 -3
  36. package/lib/types/engine/math/index.d.ts +11 -0
  37. package/lib/types/engine/math/mat4.d.ts +37 -0
  38. package/lib/types/engine/math/quat.d.ts +39 -0
  39. package/lib/types/engine/math/vec3.d.ts +16 -0
  40. package/lib/types/engine/types.d.ts +23 -2
  41. package/lib/types/scene-3d/camera.d.ts +27 -0
  42. package/lib/types/scene-3d/canvas-2d-renderer.d.ts +21 -0
  43. package/lib/types/scene-3d/geometry/extrude.d.ts +17 -0
  44. package/lib/types/scene-3d/geometry/mesh.d.ts +36 -0
  45. package/lib/types/scene-3d/geometry/primitives.d.ts +16 -0
  46. package/lib/types/scene-3d/geometry/triangulate.d.ts +24 -0
  47. package/lib/types/scene-3d/index.d.ts +20 -0
  48. package/lib/types/scene-3d/load-scene.d.ts +31 -0
  49. package/lib/types/scene-3d/object-kind.d.ts +54 -0
  50. package/lib/types/scene-3d/resolve-scene.d.ts +122 -0
  51. package/lib/types/scene-3d/scene-3d-adapter.d.ts +46 -0
  52. package/lib/types/scene-3d/scene-types.d.ts +191 -0
  53. package/lib/types/scene-3d/shading.d.ts +20 -0
  54. package/lib/types/scene-3d/validate-scene.d.ts +11 -0
  55. package/lib/types/scene-3d/webgl/gl-data.d.ts +28 -0
  56. package/lib/types/scene-3d/webgl/index.d.ts +16 -0
  57. package/lib/types/scene-3d/webgl/shaders.d.ts +29 -0
  58. package/lib/types/scene-3d/webgl/webgl2-renderer.d.ts +33 -0
  59. package/package.json +10 -2
  60. 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 F, e as _, i as Y, a as G, b as g, p as D, t as U, g as W, c as $, q as N, F as z, s as H, d as V } from "./dom-adapter-Cphr2HZn.js";
2
+ import { D as Pe } from "./dom-adapter-Cphr2HZn.js";
3
+ import { createTrack as q, parsePath as C, mat4 as m } from "@algorisys/tinyfly";
4
+ import { p as j, s as Z } from "./sketch-CA8ZXhxI.js";
5
+ import { b as Se, a as Re, c as xe } from "./sketch-CA8ZXhxI.js";
6
+ function J(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, O(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 K(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 = O(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) {
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));
19
+ T(`${a}-${c}-x`, c, "x", p, 0, i, s),
20
+ T(`${a}-${c}-y`, c, "y", u, 0, i, s)
21
+ ), o && f.width > 0 && f.height > 0) {
22
+ const d = h.width / f.width, y = h.height / f.height;
23
+ d !== 1 && n.push(T(`${a}-${c}-sx`, c, "scaleX", d, 1, i, s)), y !== 1 && n.push(T(`${a}-${c}-sy`, c, "scaleY", y, 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 de(r, e, t = {}) {
29
+ const i = J(r);
30
+ return e(), K(i, r, t);
31
31
  }
32
- function T(c, e, t, i, o, s, a) {
33
- return B({
34
- id: c,
32
+ function T(r, e, t, i, s, o, a) {
33
+ return q({
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 O(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 I(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 M = 12;
61
+ function R(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 C(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 <= M; p++) {
72
+ const u = p / M, 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;
82
+ function Q(r, e, t, i, s = 0) {
83
+ const o = Math.max(0, Math.min(s, t / 2, i / 2));
84
+ if (o === 0) return R(`M${r},${e} H${r + t} V${e + i} H${r} Z`);
85
+ const a = r + t, n = e + i;
86
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`
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 b(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 = j(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 pe(r) {
108
+ return typeof r == "object" && r !== null && "type" in r;
109
109
  }
110
- class v {
110
+ function ee(r, e, t) {
111
+ if (typeof OffscreenCanvas < "u") return new OffscreenCanvas(e, t);
112
+ const i = r.canvas;
113
+ if (i?.ownerDocument) {
114
+ const s = i.ownerDocument.createElement("canvas");
115
+ return s.width = e, s.height = t, s;
116
+ }
117
+ try {
118
+ return i?.constructor ? new i.constructor(e, t) : null;
119
+ } catch {
120
+ return null;
121
+ }
122
+ }
123
+ class x {
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 (x.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 = x.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), F(t)) {
222
+ const o = _(t, i, { x: this.getPivotX(t), y: this.getPivotY(t) });
223
+ if (t.backfaceVisibility === "hidden" && Y(o)) {
224
+ e.restore();
225
+ return;
226
+ }
227
+ G(o) ? (e.transform(...g(o)), this.drawContent(e, t)) : this.drawInPerspective(e, t, o), e.restore();
228
+ return;
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 D(i, s)) {
258
+ const a = U(o.source, o.target);
259
+ if (!a) continue;
260
+ const [n, c, l] = W(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 = ee(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 C(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 };
212
299
  }
213
- e.translate(-a, -n);
214
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 = $(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 ? Z(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) => b(e, Q(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 I(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) => b(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) => b(e, R(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, y = 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 w = n === "cover" ? Math.max(o / h, a / f) : Math.min(o / h, a / f);
513
+ d = h * w, y = f * w, p = i + (o - d) / 2, u = s + (a - y) / 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, y), e.restore();
423
516
  }
424
517
  /**
425
518
  * Render a custom target by calling its draw function in local coordinates.
@@ -522,12 +615,12 @@ 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
+ const S = "http://www.w3.org/2000/svg", te = /* @__PURE__ */ new Set([
531
624
  "fill",
532
625
  "stroke",
533
626
  "d",
@@ -547,7 +640,7 @@ const b = "http://www.w3.org/2000/svg", N = /* @__PURE__ */ new Set([
547
640
  "height",
548
641
  "viewBox",
549
642
  "preserveAspectRatio"
550
- ]), k = {
643
+ ]), A = {
551
644
  strokeWidth: "stroke-width",
552
645
  strokeLinecap: "stroke-linecap",
553
646
  strokeLinejoin: "stroke-linejoin",
@@ -558,7 +651,7 @@ const b = "http://www.w3.org/2000/svg", N = /* @__PURE__ */ new Set([
558
651
  strokeOpacity: "stroke-opacity",
559
652
  borderRadius: "rx"
560
653
  // Map CSS borderRadius to SVG rx
561
- }, W = /* @__PURE__ */ new Set([
654
+ }, ie = /* @__PURE__ */ new Set([
562
655
  "x",
563
656
  // Position x treated as translateX
564
657
  "y",
@@ -566,8 +659,10 @@ const b = "http://www.w3.org/2000/svg", N = /* @__PURE__ */ new Set([
566
659
  "translateX",
567
660
  "translateY",
568
661
  "rotate",
662
+ "rotateZ",
569
663
  "rotateX",
570
664
  "rotateY",
665
+ "z",
571
666
  "scale",
572
667
  "scaleX",
573
668
  "scaleY",
@@ -577,8 +672,8 @@ const b = "http://www.w3.org/2000/svg", N = /* @__PURE__ */ new Set([
577
672
  "motionPathX",
578
673
  "motionPathY",
579
674
  "motionPathRotate"
580
- ]), H = /* @__PURE__ */ new Set(["clipTop", "clipRight", "clipBottom", "clipLeft"]);
581
- class oe {
675
+ ]), se = /* @__PURE__ */ new Set(["clipTop", "clipRight", "clipBottom", "clipLeft"]);
676
+ class ye {
582
677
  targets = /* @__PURE__ */ new Map();
583
678
  /**
584
679
  * Register an SVG element as an animation target.
@@ -609,51 +704,53 @@ class oe {
609
704
  */
610
705
  applyState(e) {
611
706
  for (const [t, i] of e.values) {
612
- const o = this.targets.get(t);
613
- o && this.applyProperties(o, i);
707
+ const s = this.targets.get(t);
708
+ s && this.applyProperties(s, i);
614
709
  }
615
710
  }
616
711
  /**
617
712
  * Apply properties to a single SVG element.
618
713
  */
619
714
  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);
715
+ const i = {};
716
+ let s = null;
717
+ const o = {}, a = {}, n = {};
718
+ let c = !1;
719
+ for (const [l, h] of t)
720
+ l !== "drawOn" && (ie.has(l) ? i[l] = h : l === "quaternion" ? s = N(h) : l === "originX" || l === "originY" ? typeof h == "number" && (o[l] = h) : l === "perspective" ? typeof h == "number" && (i.perspective = h) : se.has(l) ? typeof h == "number" && (a[l] = h) : z.has(l) ? (n[l] = h, c = !0) : l === "text" ? typeof h == "string" && H(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));
721
+ if (Object.keys(i).length > 0 || s) {
722
+ const l = this.buildCssTransformString(i, s);
723
+ e.style.transform = l, V(e);
627
724
  }
628
725
  if (Object.keys(o).length > 0) {
629
- const r = e.style;
630
- r.transformBox = "fill-box", r.transformOrigin = `${o.originX ?? 50}% ${o.originY ?? 50}%`;
726
+ const l = e.style;
727
+ l.transformBox = "fill-box", l.transformOrigin = `${o.originX ?? 50}% ${o.originY ?? 50}%`;
631
728
  }
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}%)`;
729
+ if (Object.keys(a).length > 0) {
730
+ const l = a.clipTop ?? 0, h = a.clipRight ?? 0, f = a.clipBottom ?? 0, p = a.clipLeft ?? 0;
731
+ e.style.clipPath = `inset(${l}% ${h}% ${f}% ${p}%)`;
635
732
  }
636
- if (n) {
637
- const r = _(a);
638
- r && (e.style.filter = r);
733
+ if (c) {
734
+ const l = $(n);
735
+ l && (e.style.filter = l);
639
736
  }
640
737
  }
641
738
  /**
642
739
  * Build a CSS transform string (for use with transform-origin).
643
740
  */
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})`);
741
+ buildCssTransformString(e, t = null) {
742
+ const i = [];
743
+ e.perspective !== void 0 && e.perspective > 0 && i.push(`perspective(${e.perspective}px)`);
744
+ const s = e.motionPathX ?? e.x ?? e.translateX, o = e.motionPathY ?? e.y ?? e.translateY;
745
+ 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)`);
746
+ const a = e.motionPathRotate ?? e.rotate ?? e.rotateZ;
747
+ 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)
748
+ i.push(`scale(${e.scale})`);
652
749
  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})`);
750
+ const n = e.scaleX ?? 1, c = e.scaleY ?? 1;
751
+ i.push(`scale(${n}, ${c})`);
655
752
  }
656
- return e.skewX !== void 0 && t.push(`skewX(${e.skewX}deg)`), e.skewY !== void 0 && t.push(`skewY(${e.skewY}deg)`), t.join(" ");
753
+ return e.skewX !== void 0 && i.push(`skewX(${e.skewX}deg)`), e.skewY !== void 0 && i.push(`skewY(${e.skewY}deg)`), i.join(" ");
657
754
  }
658
755
  /**
659
756
  * Apply a single attribute to an SVG element.
@@ -664,39 +761,39 @@ class oe {
664
761
  * gradient lives in the owner SVG's <defs> and is reused across frames.
665
762
  */
666
763
  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;
764
+ const i = e.ownerSVGElement, s = e.ownerDocument;
765
+ if (!i || !s) return;
766
+ const o = e;
767
+ o.dataset.shineBase || (o.dataset.shineBase = e.getAttribute("fill") || "#000000");
768
+ const a = o.dataset.shineBase;
672
769
  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");
770
+ n || (n = s.createElementNS(S, "defs"), i.insertBefore(n, i.firstChild));
771
+ let c = o.dataset.shineGrad, l = c ? n.querySelector(`#${c}`) : null;
772
+ for (l || (c = `tinyfly-shine-${Math.random().toString(36).slice(2, 9)}`, o.dataset.shineGrad = c, l = s.createElementNS(S, "linearGradient"), l.setAttribute("id", c), n.appendChild(l)); l.firstChild; ) l.removeChild(l.firstChild);
773
+ for (const h of I(t, a)) {
774
+ const f = s.createElementNS(S, "stop");
678
775
  f.setAttribute("offset", String(h.offset)), f.setAttribute("stop-color", h.color), l.appendChild(f);
679
776
  }
680
- e.setAttribute("fill", `url(#${r})`);
777
+ e.setAttribute("fill", `url(#${c})`);
681
778
  }
682
779
  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);
780
+ let s = t;
781
+ A[t] ? s = A[t] : te.has(t) && (s = t);
782
+ const o = Array.isArray(i) ? i.join(" ") : String(i);
783
+ e.setAttribute(s, o);
687
784
  }
688
785
  }
689
- const V = `
786
+ const oe = `
690
787
  attribute vec2 a_position;
691
788
  attribute vec2 a_texCoord;
692
- uniform mat3 u_matrix;
789
+ uniform mat4 u_matrix;
693
790
  varying vec2 v_texCoord;
694
791
  void main() {
695
- vec3 position = u_matrix * vec3(a_position, 1.0);
696
- gl_Position = vec4(position.xy, 0.0, 1.0);
792
+ // w carries the perspective, so textures are interpolated perspective-correct.
793
+ gl_Position = u_matrix * vec4(a_position, 0.0, 1.0);
697
794
  v_texCoord = a_texCoord;
698
795
  }
699
- `, j = `
796
+ `, ne = `
700
797
  precision mediump float;
701
798
  uniform vec4 u_color;
702
799
  uniform sampler2D u_texture;
@@ -707,7 +804,7 @@ void main() {
707
804
  vec4 color = u_useTexture ? texture2D(u_texture, v_texCoord) : u_color;
708
805
  gl_FragColor = vec4(color.rgb, color.a * u_opacity);
709
806
  }
710
- `, z = /* @__PURE__ */ new Set([
807
+ `, re = /* @__PURE__ */ new Set([
711
808
  "x",
712
809
  "y",
713
810
  "width",
@@ -715,6 +812,10 @@ void main() {
715
812
  "opacity",
716
813
  "rotate",
717
814
  "rotateZ",
815
+ "rotateX",
816
+ "rotateY",
817
+ "z",
818
+ "perspective",
718
819
  "scale",
719
820
  "scaleX",
720
821
  "scaleY",
@@ -724,7 +825,7 @@ void main() {
724
825
  "motionPathY",
725
826
  "motionPathRotate"
726
827
  ]);
727
- class se {
828
+ class me {
728
829
  gl;
729
830
  program;
730
831
  positionBuffer;
@@ -735,7 +836,7 @@ class se {
735
836
  basePositions = /* @__PURE__ */ new Map();
736
837
  locations;
737
838
  constructor(e) {
738
- this.gl = e, this.program = q(e, V, j), this.locations = {
839
+ this.gl = e, this.program = le(e, oe, ne), this.locations = {
739
840
  position: e.getAttribLocation(this.program, "a_position"),
740
841
  texCoord: e.getAttribLocation(this.program, "a_texCoord"),
741
842
  matrix: e.getUniformLocation(this.program, "u_matrix"),
@@ -762,79 +863,92 @@ class se {
762
863
  /** Apply engine state to the registered targets. */
763
864
  applyState(e) {
764
865
  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 };
866
+ const s = this.targets.get(t);
867
+ if (!s) continue;
868
+ const o = this.basePositions.get(t) ?? { x: 0, y: 0 };
768
869
  for (const [a, n] of i)
769
- this.applyProperty(o, s, a, n);
870
+ this.applyProperty(s, o, a, n);
770
871
  }
771
872
  }
772
- applyProperty(e, t, i, o) {
773
- if (typeof o == "number") {
873
+ applyProperty(e, t, i, s) {
874
+ if (typeof s == "number") {
774
875
  if (i === "x" || i === "motionPathX") {
775
- e.x = t.x + o;
876
+ e.x = t.x + s;
776
877
  return;
777
878
  }
778
879
  if (i === "y" || i === "motionPathY") {
779
- e.y = t.y + o;
880
+ e.y = t.y + s;
780
881
  return;
781
882
  }
782
883
  if (i === "rotateZ" || i === "motionPathRotate") {
783
- e.rotate = o;
884
+ e.rotate = s;
784
885
  return;
785
886
  }
786
- if (z.has(i)) {
787
- e[i] = o;
887
+ if (re.has(i)) {
888
+ e[i] = s;
788
889
  return;
789
890
  }
790
891
  }
791
- typeof o == "string" && i === "fill" && (e.fill = o);
892
+ typeof s == "string" && i === "fill" && (e.fill = s), i === "quaternion" && Array.isArray(s) && (e.quaternion = s);
792
893
  }
793
894
  /** Draw every registered target. */
794
895
  render() {
795
896
  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);
897
+ 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), X(e, this.positionBuffer, this.locations.position), X(e, this.texCoordBuffer, this.locations.texCoord);
898
+ for (const [s, o] of this.targets)
899
+ this.drawTarget(s, o, t, i);
900
+ }
901
+ drawTarget(e, t, i, s) {
902
+ const o = this.gl;
903
+ if (t.backfaceVisibility === "hidden" && Y(B(t))) return;
904
+ const a = ae(t, i, s);
905
+ if (o.uniformMatrix4fv(this.locations.matrix, !1, a), o.uniform1f(this.locations.opacity, t.opacity ?? 1), t.texture)
906
+ o.bindTexture(o.TEXTURE_2D, this.textureFor(e, t.texture)), o.uniform1i(this.locations.useTexture, 1), o.uniform1i(this.locations.texture, 0);
804
907
  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);
908
+ o.uniform1i(this.locations.useTexture, 0);
909
+ const [n, c, l] = ce(t.fill ?? "#ffffff");
910
+ o.uniform4f(this.locations.color, n, c, l, 1);
808
911
  }
809
- s.drawArrays(s.TRIANGLES, 0, 6);
912
+ o.drawArrays(o.TRIANGLES, 0, 6);
810
913
  }
811
914
  textureFor(e, t) {
812
915
  const i = this.textures.get(e);
813
916
  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;
917
+ const s = this.gl, o = s.createTexture();
918
+ 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
919
  }
817
920
  /** Release GL resources. */
818
921
  destroy() {
819
922
  this.clearTargets(), this.gl.deleteProgram(this.program), this.gl.deleteBuffer(this.positionBuffer), this.gl.deleteBuffer(this.texCoordBuffer);
820
923
  }
821
924
  }
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;
925
+ function we(r, e, t) {
926
+ 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, y = c * s, w = r.x + p * h + d * f, L = r.y + u * h + y * f, v = 2 / e, P = -2 / t;
824
927
  return new Float32Array([
825
- p * w,
928
+ p * v,
826
929
  u * P,
827
930
  0,
828
- d * w,
829
- m * P,
931
+ d * v,
932
+ y * P,
830
933
  0,
831
- y * w - 1,
832
- $ * P + 1,
934
+ w * v - 1,
935
+ L * P + 1,
833
936
  1
834
937
  ]);
835
938
  }
836
- function Z(c) {
837
- const e = c.trim().replace("#", "");
939
+ function B(r) {
940
+ const e = (r.originX ?? 50) / 100, t = (r.originY ?? 50) / 100, i = { x: r.x, y: r.y }, s = m.multiply(
941
+ m.translation([r.x, r.y, 0]),
942
+ m.multiply(m.scaling([r.width, r.height, 1]), m.translation([-e, -t, 0]))
943
+ );
944
+ return m.multiply(_(r, { x: 0, y: 0 }, i), s);
945
+ }
946
+ function ae(r, e, t) {
947
+ const i = [2 / e, 0, 0, 0, 0, -2 / t, 0, 0, 0, 0, 0, 0, -1, 1, 0, 1];
948
+ return new Float32Array(m.multiply(i, B(r)));
949
+ }
950
+ function ce(r) {
951
+ const e = r.trim().replace("#", "");
838
952
  return e.length === 3 ? [
839
953
  Number.parseInt(e[0] + e[0], 16) / 255,
840
954
  Number.parseInt(e[1] + e[1], 16) / 255,
@@ -845,46 +959,47 @@ function Z(c) {
845
959
  Number.parseInt(e.slice(4, 6), 16) / 255
846
960
  ] : [1, 1, 1];
847
961
  }
848
- function q(c, e, t) {
849
- const i = c.createProgram();
962
+ function le(r, e, t) {
963
+ const i = r.createProgram();
850
964
  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)}`);
965
+ if (r.attachShader(i, k(r, r.VERTEX_SHADER, e)), r.attachShader(i, k(r, r.FRAGMENT_SHADER, t)), r.linkProgram(i), !r.getProgramParameter(i, r.LINK_STATUS))
966
+ throw new Error(`WebGLAdapter: program link failed — ${r.getProgramInfoLog(i)}`);
853
967
  return i;
854
968
  }
855
- function A(c, e, t) {
856
- const i = c.createShader(e);
969
+ function k(r, e, t) {
970
+ const i = r.createShader(e);
857
971
  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)}`);
972
+ if (r.shaderSource(i, t), r.compileShader(i), !r.getShaderParameter(i, r.COMPILE_STATUS))
973
+ throw new Error(`WebGLAdapter: shader compile failed — ${r.getShaderInfoLog(i)}`);
860
974
  return i;
861
975
  }
862
- function E(c, e) {
863
- const t = c.createBuffer();
976
+ function E(r, e) {
977
+ const t = r.createBuffer();
864
978
  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;
979
+ return r.bindBuffer(r.ARRAY_BUFFER, t), r.bufferData(r.ARRAY_BUFFER, new Float32Array(e), r.STATIC_DRAW), t;
866
980
  }
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));
981
+ function X(r, e, t) {
982
+ t < 0 || (r.bindBuffer(r.ARRAY_BUFFER, e), r.enableVertexAttribArray(t), r.vertexAttribPointer(t, 2, r.FLOAT, !1, 0, 0));
869
983
  }
870
984
  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,
877
- S as drawOutline,
878
- te as flip,
879
- ie as isGradient,
880
- Z as parseColor,
881
- F as partialPath,
882
- he as pathLength,
985
+ x as CanvasAdapter,
986
+ Pe as DOMAdapter,
987
+ ye as SVGAdapter,
988
+ me as WebGLAdapter,
989
+ Se as boilFrame,
990
+ K as buildFlipTracks,
991
+ b as drawOutline,
992
+ de as flip,
993
+ pe as isGradient,
994
+ ce as parseColor,
995
+ j as partialPath,
996
+ Re as pathLength,
883
997
  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
998
+ xe as pointAlong,
999
+ we as quadMatrix,
1000
+ ae as quadMatrix3d,
1001
+ J as recordFlipState,
1002
+ Q as rectOutline,
1003
+ H as setTextContent,
1004
+ Z as sketchPen
890
1005
  };