@algorisys/tinyfly 0.64.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 (140) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +672 -0
  3. package/bin/tinyfly.mjs +59 -0
  4. package/lib/addons/adapters.js +756 -0
  5. package/lib/addons/dom-adapter-ChrbtkLC.js +243 -0
  6. package/lib/addons/drivers.js +72 -0
  7. package/lib/addons/export.js +1169 -0
  8. package/lib/addons/gsap-compat.js +2576 -0
  9. package/lib/addons/interaction.js +225 -0
  10. package/lib/addons/smooth-scroll-DaSacemU.js +671 -0
  11. package/lib/addons/teach.js +215 -0
  12. package/lib/browser/tinyfly.iife.js +2 -0
  13. package/lib/browser/tinyfly.js +6372 -0
  14. package/lib/browser/tinyfly.umd.js +2 -0
  15. package/lib/cli/tools.js +2325 -0
  16. package/lib/embed/tinyfly-embed.iife.js +18 -0
  17. package/lib/embed/tinyfly-embed.js +2316 -0
  18. package/lib/engine/tinyfly-engine.js +1972 -0
  19. package/lib/engine/tinyfly-engine.umd.cjs +2 -0
  20. package/lib/frameworks/react.js +32 -0
  21. package/lib/frameworks/solid.js +27 -0
  22. package/lib/frameworks/svelte.js +15 -0
  23. package/lib/frameworks/vue.js +29 -0
  24. package/lib/player/tinyfly-player.es.js +2306 -0
  25. package/lib/player/tinyfly-player.iife.js +2 -0
  26. package/lib/player/tinyfly-player.umd.js +2 -0
  27. package/lib/types/adapters/canvas/canvas-adapter.d.ts +238 -0
  28. package/lib/types/adapters/canvas/index.d.ts +1 -0
  29. package/lib/types/adapters/dom/dom-adapter.d.ts +50 -0
  30. package/lib/types/adapters/dom/flip.d.ts +60 -0
  31. package/lib/types/adapters/dom/index.d.ts +2 -0
  32. package/lib/types/adapters/filter-utils.d.ts +32 -0
  33. package/lib/types/adapters/index.d.ts +5 -0
  34. package/lib/types/adapters/shine-utils.d.ts +26 -0
  35. package/lib/types/adapters/svg/index.d.ts +1 -0
  36. package/lib/types/adapters/svg/svg-adapter.d.ts +47 -0
  37. package/lib/types/adapters/svg-transform-box.d.ts +13 -0
  38. package/lib/types/adapters/text-content.d.ts +11 -0
  39. package/lib/types/adapters/webgl/index.d.ts +1 -0
  40. package/lib/types/adapters/webgl/webgl-adapter.d.ts +69 -0
  41. package/lib/types/browser/index.d.ts +41 -0
  42. package/lib/types/compat/gsap/custom-eases.d.ts +28 -0
  43. package/lib/types/compat/gsap/defaults.d.ts +19 -0
  44. package/lib/types/compat/gsap/draw-svg-vars.d.ts +36 -0
  45. package/lib/types/compat/gsap/ease-map.d.ts +51 -0
  46. package/lib/types/compat/gsap/image-sequence.d.ts +61 -0
  47. package/lib/types/compat/gsap/index.d.ts +65 -0
  48. package/lib/types/compat/gsap/inertia-vars.d.ts +39 -0
  49. package/lib/types/compat/gsap/keyframes-vars.d.ts +8 -0
  50. package/lib/types/compat/gsap/layout.d.ts +6 -0
  51. package/lib/types/compat/gsap/live-context.d.ts +87 -0
  52. package/lib/types/compat/gsap/live-draggable.d.ts +75 -0
  53. package/lib/types/compat/gsap/live-flip.d.ts +73 -0
  54. package/lib/types/compat/gsap/live-morph.d.ts +18 -0
  55. package/lib/types/compat/gsap/live-motion-path.d.ts +33 -0
  56. package/lib/types/compat/gsap/live-scroll-to.d.ts +52 -0
  57. package/lib/types/compat/gsap/live-scroll.d.ts +108 -0
  58. package/lib/types/compat/gsap/live-transition.d.ts +40 -0
  59. package/lib/types/compat/gsap/live.d.ts +341 -0
  60. package/lib/types/compat/gsap/morph-vars.d.ts +21 -0
  61. package/lib/types/compat/gsap/motion-path-vars.d.ts +38 -0
  62. package/lib/types/compat/gsap/playhead-crossings.d.ts +47 -0
  63. package/lib/types/compat/gsap/position.d.ts +37 -0
  64. package/lib/types/compat/gsap/quick-play.d.ts +38 -0
  65. package/lib/types/compat/gsap/split-text.d.ts +66 -0
  66. package/lib/types/compat/gsap/spring-vars.d.ts +34 -0
  67. package/lib/types/compat/gsap/stage.d.ts +182 -0
  68. package/lib/types/compat/gsap/stagger-grid.d.ts +30 -0
  69. package/lib/types/compat/gsap/text-vars.d.ts +39 -0
  70. package/lib/types/compat/gsap/timeline.d.ts +161 -0
  71. package/lib/types/compat/gsap/utils.d.ts +60 -0
  72. package/lib/types/compat/gsap/vars.d.ts +79 -0
  73. package/lib/types/drivers/index.d.ts +8 -0
  74. package/lib/types/drivers/scroll-driver.d.ts +218 -0
  75. package/lib/types/drivers/scroll-markers.d.ts +41 -0
  76. package/lib/types/drivers/scroll-math.d.ts +87 -0
  77. package/lib/types/drivers/scroll-pin.d.ts +45 -0
  78. package/lib/types/drivers/scroll-snap.d.ts +47 -0
  79. package/lib/types/drivers/smooth-scroll.d.ts +118 -0
  80. package/lib/types/drivers/types.d.ts +23 -0
  81. package/lib/types/drivers/visibility-driver.d.ts +56 -0
  82. package/lib/types/embed/controls.d.ts +46 -0
  83. package/lib/types/embed/index.d.ts +17 -0
  84. package/lib/types/embed/mount.d.ts +41 -0
  85. package/lib/types/embed/tools.d.ts +33 -0
  86. package/lib/types/engine/authoring/custom-ease.d.ts +49 -0
  87. package/lib/types/engine/authoring/index.d.ts +3 -0
  88. package/lib/types/engine/authoring/random.d.ts +38 -0
  89. package/lib/types/engine/authoring/resolve-values.d.ts +57 -0
  90. package/lib/types/engine/core/bake.d.ts +66 -0
  91. package/lib/types/engine/core/clock.d.ts +44 -0
  92. package/lib/types/engine/core/index.d.ts +8 -0
  93. package/lib/types/engine/core/inertia.d.ts +30 -0
  94. package/lib/types/engine/core/playhead-crossings.d.ts +47 -0
  95. package/lib/types/engine/core/spring.d.ts +132 -0
  96. package/lib/types/engine/core/stagger.d.ts +40 -0
  97. package/lib/types/engine/core/timeline.d.ts +203 -0
  98. package/lib/types/engine/core/track.d.ts +90 -0
  99. package/lib/types/engine/export/byte-writer.d.ts +36 -0
  100. package/lib/types/engine/export/css.d.ts +31 -0
  101. package/lib/types/engine/export/gif-decode.test-helper.d.ts +24 -0
  102. package/lib/types/engine/export/gif.d.ts +134 -0
  103. package/lib/types/engine/export/index.d.ts +9 -0
  104. package/lib/types/engine/export/lottie.d.ts +104 -0
  105. package/lib/types/engine/export/mp4.d.ts +64 -0
  106. package/lib/types/engine/export/quantize.d.ts +56 -0
  107. package/lib/types/engine/export/sprite-sheet.d.ts +46 -0
  108. package/lib/types/engine/export/video.d.ts +99 -0
  109. package/lib/types/engine/export/webp.d.ts +82 -0
  110. package/lib/types/engine/index.d.ts +7 -0
  111. package/lib/types/engine/interpolation/easing.d.ts +65 -0
  112. package/lib/types/engine/interpolation/index.d.ts +2 -0
  113. package/lib/types/engine/interpolation/interpolators.d.ts +25 -0
  114. package/lib/types/engine/path/index.d.ts +11 -0
  115. package/lib/types/engine/path/motion-path.d.ts +24 -0
  116. package/lib/types/engine/path/path-builders.d.ts +38 -0
  117. package/lib/types/engine/path/path-morph.d.ts +47 -0
  118. package/lib/types/engine/path/path-utils.d.ts +73 -0
  119. package/lib/types/engine/serialization/index.d.ts +1 -0
  120. package/lib/types/engine/serialization/json.d.ts +30 -0
  121. package/lib/types/engine/text/index.d.ts +2 -0
  122. package/lib/types/engine/text/text-value.d.ts +16 -0
  123. package/lib/types/engine/types.d.ts +401 -0
  124. package/lib/types/frameworks/react.d.ts +35 -0
  125. package/lib/types/frameworks/solid.d.ts +16 -0
  126. package/lib/types/frameworks/svelte.d.ts +19 -0
  127. package/lib/types/frameworks/vue.d.ts +27 -0
  128. package/lib/types/interaction/draggable.d.ts +133 -0
  129. package/lib/types/interaction/index.d.ts +3 -0
  130. package/lib/types/interaction/observer.d.ts +80 -0
  131. package/lib/types/interaction/snap.d.ts +30 -0
  132. package/lib/types/player/index.d.ts +7 -0
  133. package/lib/types/player/media-sync.d.ts +60 -0
  134. package/lib/types/player/player.d.ts +238 -0
  135. package/lib/types/player/sequence-types.d.ts +68 -0
  136. package/lib/types/player/sequencer.d.ts +91 -0
  137. package/lib/types/teach/diagrams.d.ts +137 -0
  138. package/lib/types/teach/index.d.ts +11 -0
  139. package/lib/types/teach/lesson.d.ts +55 -0
  140. package/package.json +170 -0
@@ -0,0 +1,756 @@
1
+ import { c as A, F as Y, s as M, e as g } from "./dom-adapter-ChrbtkLC.js";
2
+ import { D as Q } from "./dom-adapter-ChrbtkLC.js";
3
+ import { createTrack as I } from "@algorisys/tinyfly";
4
+ function B(a) {
5
+ const e = /* @__PURE__ */ new Map();
6
+ for (const { name: t, element: i } of a)
7
+ e.set(t, _(i));
8
+ return { measurements: e };
9
+ }
10
+ function C(a, e, t = {}) {
11
+ const i = t.duration ?? 600, o = t.easing ?? "ease-out", s = t.scale !== !1, c = t.idPrefix ?? "flip", n = [];
12
+ for (const { name: r, element: l } of e) {
13
+ const h = a.measurements.get(r);
14
+ if (!h) continue;
15
+ const f = _(l), u = h.left + h.width / 2 - (f.left + f.width / 2), d = h.top + h.height / 2 - (f.top + f.height / 2);
16
+ if ((u !== 0 || d !== 0) && n.push(
17
+ T(`${c}-${r}-x`, r, "x", u, 0, i, o),
18
+ T(`${c}-${r}-y`, r, "y", d, 0, i, o)
19
+ ), s && f.width > 0 && f.height > 0) {
20
+ const p = h.width / f.width, y = h.height / f.height;
21
+ p !== 1 && n.push(T(`${c}-${r}-sx`, r, "scaleX", p, 1, i, o)), y !== 1 && n.push(T(`${c}-${r}-sy`, r, "scaleY", y, 1, i, o));
22
+ }
23
+ }
24
+ return n;
25
+ }
26
+ function V(a, e, t = {}) {
27
+ const i = B(a);
28
+ return e(), C(i, a, t);
29
+ }
30
+ function T(a, e, t, i, o, s, c) {
31
+ return I({
32
+ id: a,
33
+ target: e,
34
+ property: t,
35
+ keyframes: [
36
+ { time: 0, value: i },
37
+ { time: s, value: o, easing: c }
38
+ ]
39
+ });
40
+ }
41
+ function _(a) {
42
+ const e = a;
43
+ if (typeof e.getBoundingClientRect != "function")
44
+ return { left: 0, top: 0, width: 0, height: 0 };
45
+ const t = e.getBoundingClientRect();
46
+ return { left: t.left, top: t.top, width: t.width, height: t.height };
47
+ }
48
+ function k(a, e, t = {}) {
49
+ const i = t.highlight ?? "#ffffff", o = t.halfWidth ?? 0.12, s = -0.2 + a * 1.4, c = [{ offset: 0, color: e }], n = [
50
+ { offset: s - o, color: e },
51
+ { offset: s, color: i },
52
+ { offset: s + o, color: e }
53
+ ];
54
+ for (const r of n)
55
+ r.offset > 0 && r.offset < 1 && c.push(r);
56
+ return c.push({ offset: 1, color: e }), c.sort((r, l) => r.offset - l.offset), c;
57
+ }
58
+ function z(a) {
59
+ return typeof a == "object" && a !== null && "type" in a;
60
+ }
61
+ class x {
62
+ targets = /* @__PURE__ */ new Map();
63
+ targetOrder = [];
64
+ // Store animation offsets separately - these are applied via ctx.translate() during rendering
65
+ // This ensures that entire elements (including line x2/y2) move together like CSS transforms
66
+ animationOffsets = /* @__PURE__ */ new Map();
67
+ // Track alias IDs that point to the same target (for lookup only, not rendering)
68
+ aliases = /* @__PURE__ */ new Map();
69
+ /**
70
+ * Register a canvas drawing target.
71
+ * @param id - The ID to register the target under
72
+ * @param target - The canvas target to register
73
+ * @param aliasFor - If provided, this ID is an alias for another target (won't render separately)
74
+ */
75
+ registerTarget(e, t, i) {
76
+ if (i) {
77
+ this.aliases.set(e, i), this.targets.set(e, t);
78
+ return;
79
+ }
80
+ this.targets.has(e) || this.targetOrder.push(e), this.targets.set(e, { ...t }), this.animationOffsets.set(e, { x: 0, y: 0 });
81
+ }
82
+ /**
83
+ * Unregister a target by its ID.
84
+ */
85
+ unregisterTarget(e) {
86
+ this.targets.delete(e), this.animationOffsets.delete(e), this.aliases.delete(e), this.targetOrder = this.targetOrder.filter((t) => t !== e);
87
+ }
88
+ /**
89
+ * Get a registered target.
90
+ */
91
+ getTarget(e) {
92
+ return this.targets.get(e);
93
+ }
94
+ /**
95
+ * Clear all registered targets.
96
+ */
97
+ clearTargets() {
98
+ this.targets.clear(), this.animationOffsets.clear(), this.aliases.clear(), this.targetOrder = [];
99
+ }
100
+ // Map animation property names to canvas target property names
101
+ static PROPERTY_MAP = {
102
+ fill: "fillStyle",
103
+ stroke: "strokeStyle",
104
+ strokeWidth: "lineWidth",
105
+ motionPathRotate: "rotate"
106
+ };
107
+ // Properties that are position offsets (applied via ctx.translate)
108
+ static OFFSET_PROPERTIES = /* @__PURE__ */ new Set(["x", "y", "motionPathX", "motionPathY"]);
109
+ /**
110
+ * Apply animation state to all registered targets.
111
+ * Position properties (x, y) are treated as offsets applied via ctx.translate().
112
+ * This matches how DOM/CSS transforms work (entire element moves together).
113
+ */
114
+ applyState(e) {
115
+ for (const [t, i] of e.values) {
116
+ const o = this.targets.get(t);
117
+ if (!o) continue;
118
+ const s = this.aliases.get(t) ?? t, c = this.animationOffsets.get(s) ?? { x: 0, y: 0 };
119
+ for (const [n, r] of i)
120
+ if (x.OFFSET_PROPERTIES.has(n) && typeof r == "number")
121
+ n === "x" || n === "motionPathX" ? c.x = r : (n === "y" || n === "motionPathY") && (c.y = r);
122
+ else {
123
+ const l = x.PROPERTY_MAP[n] ?? n;
124
+ o[l] = r;
125
+ }
126
+ this.animationOffsets.set(s, c);
127
+ }
128
+ }
129
+ /**
130
+ * Get animation offset for a target (for testing).
131
+ */
132
+ getAnimationOffset(e) {
133
+ return this.animationOffsets.get(e);
134
+ }
135
+ /**
136
+ * Render all targets to the provided canvas context.
137
+ * Call this in your animation loop after applyState().
138
+ */
139
+ render(e) {
140
+ for (const t of this.targetOrder) {
141
+ const i = this.targets.get(t);
142
+ if (!i) continue;
143
+ const o = this.animationOffsets.get(t) ?? { x: 0, y: 0 };
144
+ this.renderTarget(e, i, o);
145
+ }
146
+ }
147
+ /**
148
+ * Render a single target.
149
+ */
150
+ renderTarget(e, t, i) {
151
+ 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) {
152
+ const c = this.getPivotX(t), n = this.getPivotY(t);
153
+ e.translate(c, n), t.rotate !== void 0 && e.rotate(t.rotate * Math.PI / 180);
154
+ let r = t.scaleX ?? 1, l = t.scaleY ?? 1;
155
+ 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) {
156
+ const h = (t.skewX ?? 0) * Math.PI / 180, f = (t.skewY ?? 0) * Math.PI / 180;
157
+ e.transform(1, Math.tan(f), Math.tan(h), 1, 0, 0);
158
+ }
159
+ e.translate(-c, -n);
160
+ }
161
+ t.fillStyle && (e.fillStyle = this.resolveFillStyle(e, t)), t.strokeStyle && (e.strokeStyle = t.strokeStyle), t.lineWidth !== void 0 && (e.lineWidth = t.lineWidth);
162
+ const s = A(t);
163
+ if (s && (e.filter = s), t.clipTop !== void 0 || t.clipRight !== void 0 || t.clipBottom !== void 0 || t.clipLeft !== void 0) {
164
+ const c = this.getTargetBounds(t), n = c.x + (t.clipLeft ?? 0) / 100 * c.width, r = c.x + c.width - (t.clipRight ?? 0) / 100 * c.width, l = c.y + (t.clipTop ?? 0) / 100 * c.height, h = c.y + c.height - (t.clipBottom ?? 0) / 100 * c.height;
165
+ e.beginPath(), e.rect(n, l, Math.max(0, r - n), Math.max(0, h - l)), e.clip();
166
+ }
167
+ switch (t.type) {
168
+ case "rect":
169
+ this.renderRect(e, t);
170
+ break;
171
+ case "circle":
172
+ this.renderCircle(e, t);
173
+ break;
174
+ case "text":
175
+ this.renderText(e, t);
176
+ break;
177
+ case "line":
178
+ this.renderLine(e, t);
179
+ break;
180
+ case "path":
181
+ this.renderPath(e, t);
182
+ break;
183
+ case "image":
184
+ this.renderImage(e, t);
185
+ break;
186
+ }
187
+ e.restore();
188
+ }
189
+ /**
190
+ * Resolve a fill style to a canvas-compatible value.
191
+ */
192
+ resolveFillStyle(e, t) {
193
+ const i = t.fillStyle;
194
+ if (!i) return "transparent";
195
+ if (typeof i == "string") return i;
196
+ const o = this.getTargetBounds(t);
197
+ return i.type === "linear" ? this.createLinearGradient(e, i, o) : this.createRadialGradient(e, i, o);
198
+ }
199
+ /**
200
+ * Create a canvas linear gradient from a LinearGradient definition.
201
+ */
202
+ createLinearGradient(e, t, i) {
203
+ const o = (t.angle - 90) * (Math.PI / 180), s = i.x + i.width / 2, c = i.y + i.height / 2, n = Math.max(i.width, i.height), r = s - Math.cos(o) * n / 2, l = c - Math.sin(o) * n / 2, h = s + Math.cos(o) * n / 2, f = c + Math.sin(o) * n / 2, u = e.createLinearGradient(r, l, h, f);
204
+ for (const d of t.stops)
205
+ u.addColorStop(d.offset, d.color);
206
+ return u;
207
+ }
208
+ /**
209
+ * Create a canvas radial gradient from a RadialGradient definition.
210
+ */
211
+ createRadialGradient(e, t, i) {
212
+ const o = i.x + i.width * t.centerX, s = i.y + i.height * t.centerY, c = Math.max(i.width, i.height) * t.radius, n = e.createRadialGradient(o, s, 0, o, s, c);
213
+ for (const r of t.stops)
214
+ n.addColorStop(r.offset, r.color);
215
+ return n;
216
+ }
217
+ /**
218
+ * Get target bounding box for gradient calculations.
219
+ */
220
+ getTargetBounds(e) {
221
+ switch (e.type) {
222
+ case "rect":
223
+ case "image":
224
+ return { x: e.x, y: e.y, width: e.width, height: e.height };
225
+ case "circle":
226
+ return {
227
+ x: e.x - e.radius,
228
+ y: e.y - e.radius,
229
+ width: e.radius * 2,
230
+ height: e.radius * 2
231
+ };
232
+ case "text":
233
+ return { x: e.x, y: e.y - (e.fontSize ?? 16), width: 100, height: e.fontSize ?? 16 };
234
+ case "line":
235
+ return {
236
+ x: Math.min(e.x, e.x2),
237
+ y: Math.min(e.y, e.y2),
238
+ width: Math.abs(e.x2 - e.x),
239
+ height: Math.abs(e.y2 - e.y)
240
+ };
241
+ case "path":
242
+ return { x: e.x, y: e.y, width: 100, height: 100 };
243
+ }
244
+ }
245
+ /**
246
+ * Render a rectangle.
247
+ */
248
+ renderRect(e, t) {
249
+ 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();
250
+ }
251
+ /**
252
+ * Draw a rounded rectangle path.
253
+ */
254
+ roundRect(e, t, i, o, s, c) {
255
+ const n = Math.min(c, o / 2, s / 2);
256
+ 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);
257
+ }
258
+ /**
259
+ * Render a circle.
260
+ */
261
+ renderCircle(e, t) {
262
+ e.beginPath(), e.arc(t.x, t.y, t.radius, 0, Math.PI * 2), t.fillStyle && e.fill(), t.strokeStyle && e.stroke(), e.closePath();
263
+ }
264
+ /**
265
+ * Render text.
266
+ */
267
+ renderText(e, t) {
268
+ const i = t.fontSize ?? 16, o = t.fontFamily ?? "sans-serif", s = t.fontWeight ?? 400;
269
+ if (e.font = `${s} ${i}px ${o}`, e.textAlign = t.textAlign ?? "left", e.textBaseline = t.textBaseline ?? "top", t.fillStyle) {
270
+ if (t.shine !== void 0 && typeof t.fillStyle == "string") {
271
+ const c = e.measureText(t.text).width, n = t.textAlign ?? "left", r = n === "center" ? t.x - c / 2 : n === "right" ? t.x - c : t.x, l = e.createLinearGradient(r, t.y, r + c, t.y);
272
+ for (const h of k(t.shine, t.fillStyle))
273
+ l.addColorStop(h.offset, h.color);
274
+ e.fillStyle = l;
275
+ }
276
+ e.fillText(t.text, t.x, t.y);
277
+ }
278
+ t.strokeStyle && e.strokeText(t.text, t.x, t.y);
279
+ }
280
+ /**
281
+ * Render a line.
282
+ */
283
+ renderLine(e, t) {
284
+ t.lineCap && (e.lineCap = t.lineCap), e.beginPath(), e.moveTo(t.x, t.y), e.lineTo(t.x2, t.y2), t.strokeStyle && e.stroke(), e.closePath();
285
+ }
286
+ /**
287
+ * Render an SVG path.
288
+ */
289
+ renderPath(e, t) {
290
+ t.lineCap && (e.lineCap = t.lineCap), t.lineJoin && (e.lineJoin = t.lineJoin);
291
+ const i = new Path2D(t.d);
292
+ e.translate(t.x, t.y), t.fillStyle && e.fill(i), t.strokeStyle && e.stroke(i);
293
+ }
294
+ /**
295
+ * Render an image.
296
+ */
297
+ renderImage(e, t) {
298
+ if (!t.image) return;
299
+ t.opacity !== void 0 && (e.globalAlpha = t.opacity);
300
+ const { x: i, y: o, width: s, height: c } = 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 || c;
301
+ let u = i, d = o, p = s, y = c;
302
+ if (n !== "fill" && h > 0 && f > 0) {
303
+ const m = n === "cover" ? Math.max(s / h, c / f) : Math.min(s / h, c / f);
304
+ p = h * m, y = f * m, u = i + (s - p) / 2, d = o + (c - y) / 2;
305
+ }
306
+ e.save(), e.beginPath(), r > 0 && typeof e.roundRect == "function" ? e.roundRect(i, o, s, c, r) : e.rect(i, o, s, c), e.clip(), e.drawImage(t.image, u, d, p, y), e.restore();
307
+ }
308
+ /**
309
+ * Transform pivot X: the target's centre, shifted by `originX` across its
310
+ * own width. `originX: 0` pivots on the left edge, 100 on the right.
311
+ */
312
+ getPivotX(e) {
313
+ const t = this.getCenterX(e);
314
+ return e.originX === void 0 ? t : t + (e.originX - 50) / 100 * this.getBoundsWidth(e);
315
+ }
316
+ /** Transform pivot Y — see `getPivotX`. */
317
+ getPivotY(e) {
318
+ const t = this.getCenterY(e);
319
+ return e.originY === void 0 ? t : t + (e.originY - 50) / 100 * this.getBoundsHeight(e);
320
+ }
321
+ /**
322
+ * Bounding-box width used to resolve `originX`. Circles use their diameter;
323
+ * text is approximated from its font size, since measuring it would need the
324
+ * context and the pivot only has to be stable, not typographically exact.
325
+ */
326
+ getBoundsWidth(e) {
327
+ switch (e.type) {
328
+ case "rect":
329
+ case "image":
330
+ return e.width;
331
+ case "circle":
332
+ return e.radius * 2;
333
+ case "text":
334
+ return (e.text?.length ?? 0) * (e.fontSize ?? 16) * 0.6;
335
+ case "line":
336
+ return Math.abs(e.x2 - e.x);
337
+ case "path":
338
+ return 100;
339
+ }
340
+ }
341
+ /** Bounding-box height used to resolve `originY`. See `getBoundsWidth`. */
342
+ getBoundsHeight(e) {
343
+ switch (e.type) {
344
+ case "rect":
345
+ case "image":
346
+ return e.height;
347
+ case "circle":
348
+ return e.radius * 2;
349
+ case "text":
350
+ return e.fontSize ?? 16;
351
+ case "line":
352
+ return Math.abs(e.y2 - e.y);
353
+ case "path":
354
+ return 100;
355
+ }
356
+ }
357
+ /**
358
+ * Get the center X coordinate of a target.
359
+ */
360
+ getCenterX(e) {
361
+ switch (e.type) {
362
+ case "rect":
363
+ case "image":
364
+ return e.x + e.width / 2;
365
+ case "circle":
366
+ return e.x;
367
+ case "text":
368
+ return e.x;
369
+ case "line":
370
+ return (e.x + e.x2) / 2;
371
+ case "path":
372
+ return e.x + 50;
373
+ }
374
+ }
375
+ /**
376
+ * Get the center Y coordinate of a target.
377
+ */
378
+ getCenterY(e) {
379
+ switch (e.type) {
380
+ case "rect":
381
+ case "image":
382
+ return e.y + e.height / 2;
383
+ case "circle":
384
+ return e.y;
385
+ case "text":
386
+ return e.y + (e.fontSize ?? 16) / 2;
387
+ case "line":
388
+ return (e.y + e.y2) / 2;
389
+ case "path":
390
+ return e.y + 50;
391
+ }
392
+ }
393
+ /**
394
+ * Load an image and return a promise that resolves to the image.
395
+ * Useful for creating ImageTarget objects.
396
+ */
397
+ static loadImage(e) {
398
+ return new Promise((t, i) => {
399
+ const o = new Image();
400
+ o.onload = () => t(o), o.onerror = i, o.src = e;
401
+ });
402
+ }
403
+ }
404
+ const P = "http://www.w3.org/2000/svg", L = /* @__PURE__ */ new Set([
405
+ "fill",
406
+ "stroke",
407
+ "d",
408
+ "points",
409
+ "x",
410
+ "y",
411
+ "x1",
412
+ "y1",
413
+ "x2",
414
+ "y2",
415
+ "cx",
416
+ "cy",
417
+ "r",
418
+ "rx",
419
+ "ry",
420
+ "width",
421
+ "height",
422
+ "viewBox",
423
+ "preserveAspectRatio"
424
+ ]), R = {
425
+ strokeWidth: "stroke-width",
426
+ strokeLinecap: "stroke-linecap",
427
+ strokeLinejoin: "stroke-linejoin",
428
+ strokeDasharray: "stroke-dasharray",
429
+ strokeDashoffset: "stroke-dashoffset",
430
+ fillRule: "fill-rule",
431
+ fillOpacity: "fill-opacity",
432
+ strokeOpacity: "stroke-opacity",
433
+ borderRadius: "rx"
434
+ // Map CSS borderRadius to SVG rx
435
+ }, O = /* @__PURE__ */ new Set([
436
+ "x",
437
+ // Position x treated as translateX
438
+ "y",
439
+ // Position y treated as translateY
440
+ "translateX",
441
+ "translateY",
442
+ "rotate",
443
+ "rotateX",
444
+ "rotateY",
445
+ "scale",
446
+ "scaleX",
447
+ "scaleY",
448
+ "skewX",
449
+ "skewY",
450
+ // Motion path properties (treated like x/y/rotate)
451
+ "motionPathX",
452
+ "motionPathY",
453
+ "motionPathRotate"
454
+ ]), F = /* @__PURE__ */ new Set(["clipTop", "clipRight", "clipBottom", "clipLeft"]);
455
+ class q {
456
+ targets = /* @__PURE__ */ new Map();
457
+ /**
458
+ * Register an SVG element as an animation target.
459
+ */
460
+ registerTarget(e, t) {
461
+ this.targets.set(e, t);
462
+ }
463
+ /**
464
+ * Unregister a target by its ID.
465
+ */
466
+ unregisterTarget(e) {
467
+ this.targets.delete(e);
468
+ }
469
+ /**
470
+ * Get a registered target element.
471
+ */
472
+ getTarget(e) {
473
+ return this.targets.get(e);
474
+ }
475
+ /**
476
+ * Clear all registered targets.
477
+ */
478
+ clearTargets() {
479
+ this.targets.clear();
480
+ }
481
+ /**
482
+ * Apply animation state to all registered targets.
483
+ */
484
+ applyState(e) {
485
+ for (const [t, i] of e.values) {
486
+ const o = this.targets.get(t);
487
+ o && this.applyProperties(o, i);
488
+ }
489
+ }
490
+ /**
491
+ * Apply properties to a single SVG element.
492
+ */
493
+ applyProperties(e, t) {
494
+ const i = {}, o = {}, s = {}, c = {};
495
+ let n = !1;
496
+ for (const [r, l] of t)
497
+ O.has(r) ? i[r] = l : r === "originX" || r === "originY" ? typeof l == "number" && (o[r] = l) : r === "perspective" ? typeof l == "number" && (i.perspective = l) : F.has(r) ? typeof l == "number" && (s[r] = l) : Y.has(r) ? (c[r] = l, n = !0) : r === "text" ? typeof l == "string" && M(e, l) : r === "shine" ? typeof l == "number" && this.applyShine(e, l) : r === "opacity" ? (e.setAttribute("fill-opacity", String(l)), e.setAttribute("stroke-opacity", String(l))) : this.applyAttribute(e, r, l);
498
+ if (Object.keys(i).length > 0) {
499
+ const r = this.buildCssTransformString(i);
500
+ e.style.transform = r, g(e);
501
+ }
502
+ if (Object.keys(o).length > 0) {
503
+ const r = e.style;
504
+ r.transformBox = "fill-box", r.transformOrigin = `${o.originX ?? 50}% ${o.originY ?? 50}%`;
505
+ }
506
+ if (Object.keys(s).length > 0) {
507
+ const r = s.clipTop ?? 0, l = s.clipRight ?? 0, h = s.clipBottom ?? 0, f = s.clipLeft ?? 0;
508
+ e.style.clipPath = `inset(${r}% ${l}% ${h}% ${f}%)`;
509
+ }
510
+ if (n) {
511
+ const r = A(c);
512
+ r && (e.style.filter = r);
513
+ }
514
+ }
515
+ /**
516
+ * Build a CSS transform string (for use with transform-origin).
517
+ */
518
+ buildCssTransformString(e) {
519
+ const t = [];
520
+ e.perspective !== void 0 && t.push(`perspective(${e.perspective}px)`);
521
+ const i = e.motionPathX ?? e.x ?? e.translateX, o = e.motionPathY ?? e.y ?? e.translateY;
522
+ (i !== void 0 || o !== void 0) && t.push(`translate(${i ?? 0}px, ${o ?? 0}px)`);
523
+ const s = e.motionPathRotate ?? e.rotate;
524
+ 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)
525
+ t.push(`scale(${e.scale})`);
526
+ else if (e.scaleX !== void 0 || e.scaleY !== void 0) {
527
+ const c = e.scaleX ?? 1, n = e.scaleY ?? 1;
528
+ t.push(`scale(${c}, ${n})`);
529
+ }
530
+ return e.skewX !== void 0 && t.push(`skewX(${e.skewX}deg)`), e.skewY !== void 0 && t.push(`skewY(${e.skewY}deg)`), t.join(" ");
531
+ }
532
+ /**
533
+ * Apply a single attribute to an SVG element.
534
+ */
535
+ /**
536
+ * Apply a shine sweep to an SVG (text) element by filling it with an injected
537
+ * linear gradient whose highlight band moves with `progress` (0..1). The
538
+ * gradient lives in the owner SVG's <defs> and is reused across frames.
539
+ */
540
+ applyShine(e, t) {
541
+ const i = e.ownerSVGElement, o = e.ownerDocument;
542
+ if (!i || !o) return;
543
+ const s = e;
544
+ s.dataset.shineBase || (s.dataset.shineBase = e.getAttribute("fill") || "#000000");
545
+ const c = s.dataset.shineBase;
546
+ let n = i.querySelector("defs");
547
+ n || (n = o.createElementNS(P, "defs"), i.insertBefore(n, i.firstChild));
548
+ let r = s.dataset.shineGrad, l = r ? n.querySelector(`#${r}`) : null;
549
+ for (l || (r = `tinyfly-shine-${Math.random().toString(36).slice(2, 9)}`, s.dataset.shineGrad = r, l = o.createElementNS(P, "linearGradient"), l.setAttribute("id", r), n.appendChild(l)); l.firstChild; ) l.removeChild(l.firstChild);
550
+ for (const h of k(t, c)) {
551
+ const f = o.createElementNS(P, "stop");
552
+ f.setAttribute("offset", String(h.offset)), f.setAttribute("stop-color", h.color), l.appendChild(f);
553
+ }
554
+ e.setAttribute("fill", `url(#${r})`);
555
+ }
556
+ applyAttribute(e, t, i) {
557
+ let o = t;
558
+ R[t] ? o = R[t] : L.has(t) && (o = t);
559
+ const s = Array.isArray(i) ? i.join(" ") : String(i);
560
+ e.setAttribute(o, s);
561
+ }
562
+ }
563
+ const $ = `
564
+ attribute vec2 a_position;
565
+ attribute vec2 a_texCoord;
566
+ uniform mat3 u_matrix;
567
+ varying vec2 v_texCoord;
568
+ void main() {
569
+ vec3 position = u_matrix * vec3(a_position, 1.0);
570
+ gl_Position = vec4(position.xy, 0.0, 1.0);
571
+ v_texCoord = a_texCoord;
572
+ }
573
+ `, G = `
574
+ precision mediump float;
575
+ uniform vec4 u_color;
576
+ uniform sampler2D u_texture;
577
+ uniform bool u_useTexture;
578
+ uniform float u_opacity;
579
+ varying vec2 v_texCoord;
580
+ void main() {
581
+ vec4 color = u_useTexture ? texture2D(u_texture, v_texCoord) : u_color;
582
+ gl_FragColor = vec4(color.rgb, color.a * u_opacity);
583
+ }
584
+ `, D = /* @__PURE__ */ new Set([
585
+ "x",
586
+ "y",
587
+ "width",
588
+ "height",
589
+ "opacity",
590
+ "rotate",
591
+ "rotateZ",
592
+ "scale",
593
+ "scaleX",
594
+ "scaleY",
595
+ "originX",
596
+ "originY",
597
+ "motionPathX",
598
+ "motionPathY",
599
+ "motionPathRotate"
600
+ ]);
601
+ class J {
602
+ gl;
603
+ program;
604
+ positionBuffer;
605
+ texCoordBuffer;
606
+ textures = /* @__PURE__ */ new Map();
607
+ targets = /* @__PURE__ */ new Map();
608
+ /** Base positions, so x/y animate as offsets like the other adapters */
609
+ basePositions = /* @__PURE__ */ new Map();
610
+ locations;
611
+ constructor(e) {
612
+ this.gl = e, this.program = W(e, $, G), this.locations = {
613
+ position: e.getAttribLocation(this.program, "a_position"),
614
+ texCoord: e.getAttribLocation(this.program, "a_texCoord"),
615
+ matrix: e.getUniformLocation(this.program, "u_matrix"),
616
+ color: e.getUniformLocation(this.program, "u_color"),
617
+ texture: e.getUniformLocation(this.program, "u_texture"),
618
+ useTexture: e.getUniformLocation(this.program, "u_useTexture"),
619
+ opacity: e.getUniformLocation(this.program, "u_opacity")
620
+ }, this.positionBuffer = b(e, [0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1]), this.texCoordBuffer = b(e, [0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1]);
621
+ }
622
+ registerTarget(e, t) {
623
+ this.targets.set(e, t), this.basePositions.set(e, { x: t.x, y: t.y });
624
+ }
625
+ unregisterTarget(e) {
626
+ this.targets.delete(e), this.basePositions.delete(e);
627
+ const t = this.textures.get(e);
628
+ t && (this.gl.deleteTexture(t), this.textures.delete(e));
629
+ }
630
+ getTarget(e) {
631
+ return this.targets.get(e);
632
+ }
633
+ clearTargets() {
634
+ for (const e of [...this.targets.keys()]) this.unregisterTarget(e);
635
+ }
636
+ /** Apply engine state to the registered targets. */
637
+ applyState(e) {
638
+ for (const [t, i] of e.values) {
639
+ const o = this.targets.get(t);
640
+ if (!o) continue;
641
+ const s = this.basePositions.get(t) ?? { x: 0, y: 0 };
642
+ for (const [c, n] of i)
643
+ this.applyProperty(o, s, c, n);
644
+ }
645
+ }
646
+ applyProperty(e, t, i, o) {
647
+ if (typeof o == "number") {
648
+ if (i === "x" || i === "motionPathX") {
649
+ e.x = t.x + o;
650
+ return;
651
+ }
652
+ if (i === "y" || i === "motionPathY") {
653
+ e.y = t.y + o;
654
+ return;
655
+ }
656
+ if (i === "rotateZ" || i === "motionPathRotate") {
657
+ e.rotate = o;
658
+ return;
659
+ }
660
+ if (D.has(i)) {
661
+ e[i] = o;
662
+ return;
663
+ }
664
+ }
665
+ typeof o == "string" && i === "fill" && (e.fill = o);
666
+ }
667
+ /** Draw every registered target. */
668
+ render() {
669
+ const e = this.gl, { width: t, height: i } = e.canvas;
670
+ 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(e, this.positionBuffer, this.locations.position), E(e, this.texCoordBuffer, this.locations.texCoord);
671
+ for (const [o, s] of this.targets)
672
+ this.drawTarget(o, s, t, i);
673
+ }
674
+ drawTarget(e, t, i, o) {
675
+ const s = this.gl, c = U(t, i, o);
676
+ if (s.uniformMatrix3fv(this.locations.matrix, !1, c), s.uniform1f(this.locations.opacity, t.opacity ?? 1), t.texture)
677
+ s.bindTexture(s.TEXTURE_2D, this.textureFor(e, t.texture)), s.uniform1i(this.locations.useTexture, 1), s.uniform1i(this.locations.texture, 0);
678
+ else {
679
+ s.uniform1i(this.locations.useTexture, 0);
680
+ const [n, r, l] = N(t.fill ?? "#ffffff");
681
+ s.uniform4f(this.locations.color, n, r, l, 1);
682
+ }
683
+ s.drawArrays(s.TRIANGLES, 0, 6);
684
+ }
685
+ textureFor(e, t) {
686
+ const i = this.textures.get(e);
687
+ if (i) return i;
688
+ const o = this.gl, s = o.createTexture();
689
+ 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;
690
+ }
691
+ /** Release GL resources. */
692
+ destroy() {
693
+ this.clearTargets(), this.gl.deleteProgram(this.program), this.gl.deleteBuffer(this.positionBuffer), this.gl.deleteBuffer(this.texCoordBuffer);
694
+ }
695
+ }
696
+ function U(a, e, t) {
697
+ const i = (a.scale ?? a.scaleX ?? 1) * a.width, o = (a.scale ?? a.scaleY ?? 1) * a.height, s = (a.originX ?? 50) / 100, c = (a.originY ?? 50) / 100, n = (a.rotate ?? 0) * Math.PI / 180, r = Math.cos(n), l = Math.sin(n), h = -s, f = -c, u = r * i, d = l * i, p = -l * o, y = r * o, m = a.x + u * h + p * f, X = a.y + d * h + y * f, S = 2 / e, w = -2 / t;
698
+ return new Float32Array([
699
+ u * S,
700
+ d * w,
701
+ 0,
702
+ p * S,
703
+ y * w,
704
+ 0,
705
+ m * S - 1,
706
+ X * w + 1,
707
+ 1
708
+ ]);
709
+ }
710
+ function N(a) {
711
+ const e = a.trim().replace("#", "");
712
+ return e.length === 3 ? [
713
+ Number.parseInt(e[0] + e[0], 16) / 255,
714
+ Number.parseInt(e[1] + e[1], 16) / 255,
715
+ Number.parseInt(e[2] + e[2], 16) / 255
716
+ ] : e.length === 6 ? [
717
+ Number.parseInt(e.slice(0, 2), 16) / 255,
718
+ Number.parseInt(e.slice(2, 4), 16) / 255,
719
+ Number.parseInt(e.slice(4, 6), 16) / 255
720
+ ] : [1, 1, 1];
721
+ }
722
+ function W(a, e, t) {
723
+ const i = a.createProgram();
724
+ if (!i) throw new Error("WebGLAdapter: could not create a program");
725
+ if (a.attachShader(i, v(a, a.VERTEX_SHADER, e)), a.attachShader(i, v(a, a.FRAGMENT_SHADER, t)), a.linkProgram(i), !a.getProgramParameter(i, a.LINK_STATUS))
726
+ throw new Error(`WebGLAdapter: program link failed — ${a.getProgramInfoLog(i)}`);
727
+ return i;
728
+ }
729
+ function v(a, e, t) {
730
+ const i = a.createShader(e);
731
+ if (!i) throw new Error("WebGLAdapter: could not create a shader");
732
+ if (a.shaderSource(i, t), a.compileShader(i), !a.getShaderParameter(i, a.COMPILE_STATUS))
733
+ throw new Error(`WebGLAdapter: shader compile failed — ${a.getShaderInfoLog(i)}`);
734
+ return i;
735
+ }
736
+ function b(a, e) {
737
+ const t = a.createBuffer();
738
+ if (!t) throw new Error("WebGLAdapter: could not create a buffer");
739
+ return a.bindBuffer(a.ARRAY_BUFFER, t), a.bufferData(a.ARRAY_BUFFER, new Float32Array(e), a.STATIC_DRAW), t;
740
+ }
741
+ function E(a, e, t) {
742
+ t < 0 || (a.bindBuffer(a.ARRAY_BUFFER, e), a.enableVertexAttribArray(t), a.vertexAttribPointer(t, 2, a.FLOAT, !1, 0, 0));
743
+ }
744
+ export {
745
+ x as CanvasAdapter,
746
+ Q as DOMAdapter,
747
+ q as SVGAdapter,
748
+ J as WebGLAdapter,
749
+ C as buildFlipTracks,
750
+ V as flip,
751
+ z as isGradient,
752
+ N as parseColor,
753
+ U as quadMatrix,
754
+ B as recordFlipState,
755
+ M as setTextContent
756
+ };