@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,1169 @@
1
+ import { toKeyframedTracks as O, isTextTrack as H, isCubicBezierEasing as G } from "@algorisys/tinyfly";
2
+ const Z = {
3
+ linear: "linear",
4
+ "ease-in": "ease-in",
5
+ "ease-out": "ease-out",
6
+ "ease-in-out": "ease-in-out",
7
+ "ease-in-quad": "cubic-bezier(0.55, 0.085, 0.68, 0.53)",
8
+ "ease-out-quad": "cubic-bezier(0.25, 0.46, 0.45, 0.94)",
9
+ "ease-in-out-quad": "cubic-bezier(0.455, 0.03, 0.515, 0.955)",
10
+ "ease-in-cubic": "cubic-bezier(0.55, 0.055, 0.675, 0.19)",
11
+ "ease-out-cubic": "cubic-bezier(0.215, 0.61, 0.355, 1)",
12
+ "ease-in-out-cubic": "cubic-bezier(0.645, 0.045, 0.355, 1)"
13
+ };
14
+ function J(n) {
15
+ if (G(n)) {
16
+ const [t, o, r, i] = n.points;
17
+ return `cubic-bezier(${t}, ${o}, ${r}, ${i})`;
18
+ }
19
+ return typeof n != "string" ? "linear" : Z[n] ?? "linear";
20
+ }
21
+ const Q = {
22
+ x: "left",
23
+ y: "top",
24
+ width: "width",
25
+ height: "height",
26
+ opacity: "opacity",
27
+ rotate: "rotate",
28
+ scale: "scale",
29
+ scaleX: "scaleX",
30
+ scaleY: "scaleY",
31
+ fill: "background-color",
32
+ stroke: "border-color",
33
+ strokeWidth: "border-width",
34
+ borderRadius: "border-radius",
35
+ fontSize: "font-size"
36
+ }, tt = /* @__PURE__ */ new Set(["x", "y", "rotate", "scale", "scaleX", "scaleY"]);
37
+ function et(n, t) {
38
+ return typeof t == "number" ? n === "opacity" || n === "scale" || n === "scaleX" || n === "scaleY" ? String(t) : n === "rotate" ? `${t}deg` : `${t}px` : String(t);
39
+ }
40
+ function nt(n) {
41
+ const t = /* @__PURE__ */ new Map();
42
+ for (const o of n) {
43
+ const r = t.get(o.target) ?? [];
44
+ r.push(o), t.set(o.target, r);
45
+ }
46
+ return t;
47
+ }
48
+ function ot(n, t) {
49
+ const o = /* @__PURE__ */ new Set();
50
+ for (const r of n)
51
+ for (const i of r.keyframes)
52
+ o.add(i.time);
53
+ return o.add(0), o.add(t), Array.from(o).sort((r, i) => r - i);
54
+ }
55
+ function rt(n, t) {
56
+ const o = n.keyframes;
57
+ if (o.length === 0) return null;
58
+ let r = null, i = null;
59
+ for (const u of o)
60
+ u.time <= t && (r = u), u.time >= t && !i && (i = u);
61
+ return r && r.time === t ? r.value : i && i.time === t ? i.value : r && !i ? r.value : !r && i ? i.value : r?.value ?? null;
62
+ }
63
+ function it(n) {
64
+ return tt.has(n);
65
+ }
66
+ function st(n, t, o, r) {
67
+ const i = { ...Q, ...r.propertyMap }, u = ot(t, o), a = [], m = r.minify ? "" : " ", d = r.minify ? "" : `
68
+ `, e = r.minify ? "" : " ";
69
+ a.push(`@keyframes ${n}${e}{`);
70
+ for (const f of u) {
71
+ const l = o > 0 ? Math.round(f / o * 100) : 0, s = [], c = [];
72
+ for (const h of t) {
73
+ const b = rt(h, f);
74
+ if (b === null) continue;
75
+ const y = i[h.property] ?? h.property, p = et(h.property, b);
76
+ if (it(h.property))
77
+ switch (h.property) {
78
+ case "x":
79
+ c.push(`translateX(${p})`);
80
+ break;
81
+ case "y":
82
+ c.push(`translateY(${p})`);
83
+ break;
84
+ case "rotate":
85
+ c.push(`rotate(${p})`);
86
+ break;
87
+ case "scale":
88
+ c.push(`scale(${b})`);
89
+ break;
90
+ case "scaleX":
91
+ c.push(`scaleX(${b})`);
92
+ break;
93
+ case "scaleY":
94
+ c.push(`scaleY(${b})`);
95
+ break;
96
+ }
97
+ else
98
+ s.push(`${y}:${e}${p}`);
99
+ }
100
+ c.length > 0 && s.push(`transform:${e}${c.join(" ")}`), s.length > 0 && a.push(`${m}${l}%${e}{${e}${s.join(`;${e}`)}${e}}`);
101
+ }
102
+ return a.push("}"), a.join(d);
103
+ }
104
+ function at(n) {
105
+ const t = /* @__PURE__ */ new Map();
106
+ for (const i of n)
107
+ for (const u of i.keyframes) {
108
+ const a = u.easing ?? "linear";
109
+ t.set(a, (t.get(a) ?? 0) + 1);
110
+ }
111
+ let o = 0, r = "linear";
112
+ for (const [i, u] of t)
113
+ u > o && (o = u, r = i);
114
+ return r;
115
+ }
116
+ function ct(n, t, o, r, i) {
117
+ const u = i.minify ? "" : " ", a = (t / 1e3).toFixed(2), m = J(at(o)), d = r.loop === -1 ? "infinite" : r.loop ? r.loop + 1 : 1, e = r.alternate ? "alternate" : "normal";
118
+ return `animation:${u}${n} ${a}s ${m} ${d} ${e}`;
119
+ }
120
+ function Lt(n, t = {}) {
121
+ const {
122
+ classPrefix: o = "tinyfly",
123
+ includeKeyframes: r = !0,
124
+ includeAnimation: i = !0,
125
+ minify: u = !1
126
+ } = t, a = /* @__PURE__ */ new Map(), m = /* @__PURE__ */ new Map(), d = [], e = u ? "" : `
127
+ `, f = u ? "" : " ", l = n.duration, s = {
128
+ loop: n._config.loop,
129
+ alternate: n._config.alternate
130
+ }, c = nt(O(n.tracks).filter((h) => !H(h)));
131
+ for (const [h, b] of c) {
132
+ const y = `${o}-${h.replace(/[^a-zA-Z0-9]/g, "-")}`;
133
+ if (r) {
134
+ const p = st(y, b, l, t);
135
+ a.set(y, p), d.push(p);
136
+ }
137
+ if (i) {
138
+ const p = ct(y, l, b, s, t), g = `${`.${o}-${h.replace(/[^a-zA-Z0-9]/g, "-")}`}${f}{${e}${u ? "" : " "}${p};${e}}`;
139
+ m.set(h, g), d.push(g);
140
+ }
141
+ }
142
+ return {
143
+ css: d.join(e + e),
144
+ keyframes: a,
145
+ selectors: m
146
+ };
147
+ }
148
+ function N(n) {
149
+ const t = {
150
+ i: { x: [0.833], y: [0.833] },
151
+ o: { x: [0.167], y: [0.167] }
152
+ };
153
+ if (G(n)) {
154
+ const [r, i, u, a] = n.points;
155
+ return {
156
+ i: { x: [r], y: [i] },
157
+ o: { x: [u], y: [a] }
158
+ };
159
+ }
160
+ const o = {
161
+ linear: t,
162
+ "ease-in": {
163
+ i: { x: [0.42], y: [0] },
164
+ o: { x: [1], y: [1] }
165
+ },
166
+ "ease-out": {
167
+ i: { x: [0], y: [0] },
168
+ o: { x: [0.58], y: [1] }
169
+ },
170
+ "ease-in-out": {
171
+ i: { x: [0.42], y: [0] },
172
+ o: { x: [0.58], y: [1] }
173
+ },
174
+ "ease-in-quad": {
175
+ i: { x: [0.55], y: [0.085] },
176
+ o: { x: [0.68], y: [0.53] }
177
+ },
178
+ "ease-out-quad": {
179
+ i: { x: [0.25], y: [0.46] },
180
+ o: { x: [0.45], y: [0.94] }
181
+ },
182
+ "ease-in-out-quad": {
183
+ i: { x: [0.455], y: [0.03] },
184
+ o: { x: [0.515], y: [0.955] }
185
+ },
186
+ "ease-in-cubic": {
187
+ i: { x: [0.55], y: [0.055] },
188
+ o: { x: [0.675], y: [0.19] }
189
+ },
190
+ "ease-out-cubic": {
191
+ i: { x: [0.215], y: [0.61] },
192
+ o: { x: [0.355], y: [1] }
193
+ },
194
+ "ease-in-out-cubic": {
195
+ i: { x: [0.645], y: [0.045] },
196
+ o: { x: [0.355], y: [1] }
197
+ }
198
+ };
199
+ return typeof n != "string" ? t : o[n] ?? t;
200
+ }
201
+ function z(n, t) {
202
+ return Math.round(n / 1e3 * t);
203
+ }
204
+ function ut(n) {
205
+ if (n.startsWith("#")) {
206
+ const t = n.slice(1);
207
+ if (t.length === 3) {
208
+ const o = parseInt(t[0] + t[0], 16) / 255, r = parseInt(t[1] + t[1], 16) / 255, i = parseInt(t[2] + t[2], 16) / 255;
209
+ return [o, r, i];
210
+ }
211
+ if (t.length === 6) {
212
+ const o = parseInt(t.slice(0, 2), 16) / 255, r = parseInt(t.slice(2, 4), 16) / 255, i = parseInt(t.slice(4, 6), 16) / 255;
213
+ return [o, r, i];
214
+ }
215
+ }
216
+ return [0, 0, 0];
217
+ }
218
+ function I(n, t, o = !1) {
219
+ if (n.length === 0)
220
+ return o ? { a: 0, k: [0, 0] } : { a: 0, k: 0 };
221
+ if (n.length === 1) {
222
+ const i = n[0].value;
223
+ return o && typeof i == "number" ? { a: 0, k: [i, i] } : { a: 0, k: i };
224
+ }
225
+ const r = [];
226
+ for (let i = 0; i < n.length; i++) {
227
+ const u = n[i], a = n[i + 1], m = z(u.time, t), d = typeof u.value == "number" ? [u.value] : [0], e = {
228
+ t: m,
229
+ s: d
230
+ };
231
+ if (a) {
232
+ const f = typeof a.value == "number" ? [a.value] : [0];
233
+ e.e = f;
234
+ const l = a.easing ?? "linear", s = N(l);
235
+ e.i = s.i, e.o = s.o;
236
+ }
237
+ r.push(e);
238
+ }
239
+ return { a: 1, k: r };
240
+ }
241
+ function ft(n) {
242
+ const t = /* @__PURE__ */ new Map();
243
+ for (const o of n) {
244
+ const r = t.get(o.target) ?? [];
245
+ r.push(o), t.set(o.target, r);
246
+ }
247
+ return t;
248
+ }
249
+ function lt(n, t) {
250
+ const o = {
251
+ o: { a: 0, k: 100 },
252
+ // Default opacity
253
+ r: { a: 0, k: 0 },
254
+ // Default rotation
255
+ p: { a: 0, k: [0, 0] },
256
+ // Default position
257
+ a: { a: 0, k: [0, 0] },
258
+ // Default anchor
259
+ s: { a: 0, k: [100, 100] }
260
+ // Default scale
261
+ };
262
+ for (const u of n) {
263
+ const a = u.keyframes;
264
+ switch (u.property) {
265
+ case "opacity":
266
+ const m = a.map((e) => ({
267
+ ...e,
268
+ value: e.value * 100
269
+ }));
270
+ o.o = I(m, t);
271
+ break;
272
+ case "rotate":
273
+ case "rotation":
274
+ o.r = I(a, t);
275
+ break;
276
+ case "scale":
277
+ const d = a.map((e) => ({
278
+ ...e,
279
+ value: e.value * 100
280
+ }));
281
+ o.s = I(d, t, !0);
282
+ break;
283
+ }
284
+ }
285
+ const r = n.find((u) => u.property === "x"), i = n.find((u) => u.property === "y");
286
+ if (r || i) {
287
+ const u = r?.keyframes ?? [{ time: 0, value: 0 }], a = i?.keyframes ?? [{ time: 0, value: 0 }], m = /* @__PURE__ */ new Set();
288
+ u.forEach((e) => m.add(e.time)), a.forEach((e) => m.add(e.time));
289
+ const d = Array.from(m).sort((e, f) => e - f);
290
+ if (d.length === 1) {
291
+ const e = u[0]?.value ?? 0, f = a[0]?.value ?? 0;
292
+ o.p = { a: 0, k: [e, f] };
293
+ } else {
294
+ const e = [];
295
+ for (let f = 0; f < d.length; f++) {
296
+ const l = d[f], s = d[f + 1], c = F(u, l), h = F(a, l), b = {
297
+ t: z(l, t),
298
+ s: [c, h]
299
+ };
300
+ if (s !== void 0) {
301
+ const y = F(u, s), p = F(a, s);
302
+ b.e = [y, p];
303
+ const g = u.find((w) => w.time === s)?.easing ?? "linear", E = N(g);
304
+ b.i = E.i, b.o = E.o;
305
+ }
306
+ e.push(b);
307
+ }
308
+ o.p = { a: 1, k: e };
309
+ }
310
+ }
311
+ return o;
312
+ }
313
+ function F(n, t) {
314
+ if (n.length === 0) return 0;
315
+ let o = n[0], r = n[n.length - 1];
316
+ for (const u of n)
317
+ if (u.time <= t && (o = u), u.time >= t) {
318
+ r = u;
319
+ break;
320
+ }
321
+ if (o.time === t) return o.value;
322
+ if (r.time === t) return r.value;
323
+ const i = (t - o.time) / (r.time - o.time);
324
+ return typeof o.value == "number" && typeof r.value == "number" ? o.value + (r.value - o.value) * i : o.value;
325
+ }
326
+ function ht(n, t, o) {
327
+ const r = ut(o);
328
+ return [
329
+ {
330
+ ty: "rc",
331
+ // Rectangle
332
+ d: 1,
333
+ s: { a: 0, k: [n, t] },
334
+ p: { a: 0, k: [0, 0] },
335
+ r: { a: 0, k: 0 }
336
+ },
337
+ {
338
+ ty: "fl",
339
+ // Fill
340
+ c: { a: 0, k: [...r, 1] },
341
+ o: { a: 0, k: 100 },
342
+ r: 1
343
+ }
344
+ ];
345
+ }
346
+ function dt(n, t = {}) {
347
+ const {
348
+ name: o = n.name || "Animation",
349
+ frameRate: r = 60,
350
+ width: i = 512,
351
+ height: u = 512
352
+ } = t, a = n.duration, m = z(a, r), d = ft(O(n.tracks).filter((l) => !H(l))), e = [];
353
+ let f = 1;
354
+ for (const [l, s] of d) {
355
+ const c = lt(s, r), b = s.find((p) => p.property === "fill")?.keyframes[0]?.value, y = {
356
+ ddd: 0,
357
+ ind: f++,
358
+ ty: 4,
359
+ // Shape layer
360
+ nm: l,
361
+ sr: 1,
362
+ ks: c,
363
+ ao: 0,
364
+ shapes: ht(100, 100, b ?? "#4a9eff"),
365
+ ip: 0,
366
+ op: m,
367
+ st: 0,
368
+ bm: 0
369
+ };
370
+ e.push(y);
371
+ }
372
+ return {
373
+ v: "5.7.4",
374
+ nm: o,
375
+ fr: r,
376
+ ip: 0,
377
+ op: m,
378
+ w: i,
379
+ h: u,
380
+ ddd: 0,
381
+ assets: [],
382
+ layers: e
383
+ };
384
+ }
385
+ function Ft(n, t = {}) {
386
+ return JSON.stringify(dt(n, t));
387
+ }
388
+ const $ = 5, P = 1 << $ * 3, U = 8 - $;
389
+ function X(n, t, o) {
390
+ return n >> U << $ * 2 | t >> U << $ | o >> U;
391
+ }
392
+ function mt(n, t) {
393
+ const o = new Uint32Array(P), r = new Uint32Array(P), i = new Uint32Array(P), u = new Uint32Array(P);
394
+ for (let f = 0; f < n.length; f += 4) {
395
+ if (n[f + 3] < 128) continue;
396
+ const l = n[f], s = n[f + 1], c = n[f + 2], h = X(l, s, c);
397
+ o[h]++, r[h] += l, i[h] += s, u[h] += c;
398
+ }
399
+ const a = [];
400
+ for (let f = 0; f < P; f++) {
401
+ const l = o[f];
402
+ l !== 0 && a.push({
403
+ r: Math.round(r[f] / l),
404
+ g: Math.round(i[f] / l),
405
+ b: Math.round(u[f] / l),
406
+ count: l
407
+ });
408
+ }
409
+ if (a.length === 0)
410
+ return { rgb: new Uint8Array(3), size: 1 };
411
+ if (a.length <= t) {
412
+ const f = new Uint8Array(a.length * 3);
413
+ return a.forEach((l, s) => {
414
+ f[s * 3] = l.r, f[s * 3 + 1] = l.g, f[s * 3 + 2] = l.b;
415
+ }), { rgb: f, size: a.length };
416
+ }
417
+ const m = (f, l) => {
418
+ let s = 0, c = 255, h = 0, b = 255, y = 0, p = 255, x = 0;
419
+ for (let g = f; g <= l; g++) {
420
+ const E = a[g];
421
+ s += E.count, E.r < c && (c = E.r), E.r > h && (h = E.r), E.g < b && (b = E.g), E.g > y && (y = E.g), E.b < p && (p = E.b), E.b > x && (x = E.b);
422
+ }
423
+ return { from: f, to: l, count: s, rMin: c, rMax: h, gMin: b, gMax: y, bMin: p, bMax: x };
424
+ }, d = [m(0, a.length - 1)];
425
+ for (; d.length < t; ) {
426
+ let f = -1, l = 0;
427
+ for (let w = 0; w < d.length; w++) {
428
+ const B = d[w];
429
+ B.to <= B.from || B.count > l && (l = B.count, f = w);
430
+ }
431
+ if (f === -1) break;
432
+ const s = d[f], c = s.rMax - s.rMin, h = s.gMax - s.gMin, b = s.bMax - s.bMin, y = c >= h && c >= b ? "r" : h >= b ? "g" : "b", p = a.slice(s.from, s.to + 1);
433
+ p.sort((w, B) => w[y] - B[y]);
434
+ for (let w = 0; w < p.length; w++) a[s.from + w] = p[w];
435
+ const x = s.count / 2;
436
+ let g = 0, E = s.from;
437
+ for (let w = s.from; w < s.to && (g += a[w].count, E = w, !(g >= x)); w++)
438
+ ;
439
+ d[f] = m(s.from, E), d.push(m(E + 1, s.to));
440
+ }
441
+ const e = new Uint8Array(d.length * 3);
442
+ return d.forEach((f, l) => {
443
+ let s = 0, c = 0, h = 0, b = 0;
444
+ for (let y = f.from; y <= f.to; y++) {
445
+ const p = a[y];
446
+ s += p.count, c += p.r * p.count, h += p.g * p.count, b += p.b * p.count;
447
+ }
448
+ s === 0 && (s = 1), e[l * 3] = Math.round(c / s), e[l * 3 + 1] = Math.round(h / s), e[l * 3 + 2] = Math.round(b / s);
449
+ }), { rgb: e, size: d.length };
450
+ }
451
+ class bt {
452
+ cache = new Int16Array(P).fill(-1);
453
+ palette;
454
+ /** Palette index `n` is written as `n + offset` (GIF reserves index 0). */
455
+ offset;
456
+ constructor(t, o = 0) {
457
+ this.palette = t, this.offset = o;
458
+ }
459
+ /** Index of the closest palette entry to the given colour. */
460
+ nearest(t, o, r) {
461
+ const i = X(t, o, r), u = this.cache[i];
462
+ if (u !== -1) return u;
463
+ const { rgb: a, size: m } = this.palette;
464
+ let d = 1 / 0, e = 0;
465
+ for (let l = 0; l < m; l++) {
466
+ const s = t - a[l * 3], c = o - a[l * 3 + 1], h = r - a[l * 3 + 2], b = s * s + c * c + h * h;
467
+ if (b < d && (d = b, e = l, b === 0))
468
+ break;
469
+ }
470
+ const f = e + this.offset;
471
+ return this.cache[i] = f, f;
472
+ }
473
+ /** The colour actually stored at a palette index produced by `nearest`. */
474
+ colorAt(t) {
475
+ const o = (t - this.offset) * 3;
476
+ return [this.palette.rgb[o], this.palette.rgb[o + 1], this.palette.rgb[o + 2]];
477
+ }
478
+ }
479
+ function pt(n, t, o, r, i = {}) {
480
+ const { dither: u = !0, transparentIndex: a = 0 } = i, m = new bt(r, a + 1), d = new Uint8Array(t * o);
481
+ let e = !1;
482
+ if (!u) {
483
+ for (let s = 0; s < t * o; s++) {
484
+ const c = s * 4;
485
+ if (n[c + 3] < 128) {
486
+ d[s] = a, e = !0;
487
+ continue;
488
+ }
489
+ d[s] = m.nearest(n[c], n[c + 1], n[c + 2]);
490
+ }
491
+ return { indices: d, hasTransparency: e };
492
+ }
493
+ const f = new Float32Array(t * o * 3);
494
+ for (let s = 0; s < t * o; s++)
495
+ f[s * 3] = n[s * 4], f[s * 3 + 1] = n[s * 4 + 1], f[s * 3 + 2] = n[s * 4 + 2];
496
+ const l = (s, c, h, b, y) => {
497
+ f[s * 3] += c * y, f[s * 3 + 1] += h * y, f[s * 3 + 2] += b * y;
498
+ };
499
+ for (let s = 0; s < o; s++)
500
+ for (let c = 0; c < t; c++) {
501
+ const h = s * t + c;
502
+ if (n[h * 4 + 3] < 128) {
503
+ d[h] = a, e = !0;
504
+ continue;
505
+ }
506
+ const b = Math.max(0, Math.min(255, f[h * 3])), y = Math.max(0, Math.min(255, f[h * 3 + 1])), p = Math.max(0, Math.min(255, f[h * 3 + 2])), x = m.nearest(b, y, p);
507
+ d[h] = x;
508
+ const [g, E, w] = m.colorAt(x), B = b - g, M = y - E, C = p - w;
509
+ c + 1 < t && l(h + 1, B, M, C, 7 / 16), s + 1 < o && (c > 0 && l(h + t - 1, B, M, C, 3 / 16), l(h + t, B, M, C, 5 / 16), c + 1 < t && l(h + t + 1, B, M, C, 1 / 16));
510
+ }
511
+ return { indices: d, hasTransparency: e };
512
+ }
513
+ class A {
514
+ buf;
515
+ len = 0;
516
+ constructor(t = 1024) {
517
+ this.buf = new Uint8Array(Math.max(16, t));
518
+ }
519
+ /** Bytes written so far — also the offset the next write lands at. */
520
+ get length() {
521
+ return this.len;
522
+ }
523
+ ensure(t) {
524
+ if (this.len + t <= this.buf.length) return;
525
+ let o = this.buf.length * 2;
526
+ for (; o < this.len + t; ) o *= 2;
527
+ const r = new Uint8Array(o);
528
+ r.set(this.buf.subarray(0, this.len)), this.buf = r;
529
+ }
530
+ byte(t) {
531
+ this.ensure(1), this.buf[this.len++] = t & 255;
532
+ }
533
+ bytes(t) {
534
+ this.ensure(t.length), this.buf.set(t, this.len), this.len += t.length;
535
+ }
536
+ /** Each character's low byte, e.g. a FourCC or an MP4 box type. */
537
+ ascii(t) {
538
+ this.ensure(t.length);
539
+ for (let o = 0; o < t.length; o++) this.buf[this.len++] = t.charCodeAt(o) & 255;
540
+ }
541
+ uint16LE(t) {
542
+ this.byte(t), this.byte(t >> 8);
543
+ }
544
+ uint24LE(t) {
545
+ this.byte(t), this.byte(t >> 8), this.byte(t >> 16);
546
+ }
547
+ uint32LE(t) {
548
+ this.byte(t), this.byte(t >> 8), this.byte(t >> 16), this.byte(t >> 24);
549
+ }
550
+ uint16BE(t) {
551
+ this.byte(t >> 8), this.byte(t);
552
+ }
553
+ uint24BE(t) {
554
+ this.byte(t >> 16), this.byte(t >> 8), this.byte(t);
555
+ }
556
+ uint32BE(t) {
557
+ this.byte(t >> 24), this.byte(t >> 16), this.byte(t >> 8), this.byte(t);
558
+ }
559
+ /** 64-bit big-endian, written as two 32-bit halves (safe up to 2^53). */
560
+ uint64BE(t) {
561
+ this.uint32BE(Math.floor(t / 2 ** 32)), this.uint32BE(t >>> 0);
562
+ }
563
+ /** Overwrite a previously written 32-bit big-endian value, e.g. a box size. */
564
+ patchUint32BE(t, o) {
565
+ this.buf[t] = o >>> 24 & 255, this.buf[t + 1] = o >>> 16 & 255, this.buf[t + 2] = o >>> 8 & 255, this.buf[t + 3] = o & 255;
566
+ }
567
+ /** Overwrite a previously written 32-bit little-endian value. */
568
+ patchUint32LE(t, o) {
569
+ this.buf[t] = o & 255, this.buf[t + 1] = o >>> 8 & 255, this.buf[t + 2] = o >>> 16 & 255, this.buf[t + 3] = o >>> 24 & 255;
570
+ }
571
+ /** A view over the written bytes. Not a copy — do not retain across writes. */
572
+ toUint8Array() {
573
+ return this.buf.subarray(0, this.len);
574
+ }
575
+ /** A standalone copy of the written bytes, safe to hand to a Blob. */
576
+ toBytes() {
577
+ return this.buf.slice(0, this.len);
578
+ }
579
+ }
580
+ function yt(n, t) {
581
+ const o = 1 << t, r = o + 1, i = new A(), u = new Uint8Array(255);
582
+ let a = 0, m = 0, d = 0;
583
+ const e = () => {
584
+ a !== 0 && (i.byte(a), i.bytes(u.subarray(0, a)), a = 0);
585
+ }, f = (b, y) => {
586
+ for (m |= b << d, d += y; d >= 8; )
587
+ u[a++] = m & 255, m >>= 8, d -= 8, a === 255 && e();
588
+ };
589
+ let l = /* @__PURE__ */ new Map();
590
+ const s = () => {
591
+ l = /* @__PURE__ */ new Map();
592
+ };
593
+ let c = t + 1, h = r + 1;
594
+ if (f(o, c), n.length > 0) {
595
+ let b = n[0];
596
+ for (let y = 1; y < n.length; y++) {
597
+ const p = n[y], x = b << 8 | p, g = l.get(x);
598
+ if (g !== void 0) {
599
+ b = g;
600
+ continue;
601
+ }
602
+ f(b, c), h < 4096 ? (l.set(x, h++), h >= 1 << c && c < 12 && c++) : (f(o, c), s(), c = t + 1, h = r + 1), b = p;
603
+ }
604
+ f(b, c);
605
+ }
606
+ return f(r, c), d > 0 && (u[a++] = m & 255), e(), i.byte(0), i.toUint8Array();
607
+ }
608
+ class _ {
609
+ width;
610
+ height;
611
+ loops;
612
+ dither;
613
+ maxColors;
614
+ /** Fully-encoded blocks (GCE + descriptor + palette + data) per frame. */
615
+ frames = [];
616
+ constructor(t, o, r = 0) {
617
+ this.width = t, this.height = o;
618
+ const i = typeof r == "number" ? { loops: r } : r;
619
+ this.loops = i.loops ?? 0, this.dither = i.dither ?? !0, this.maxColors = Math.max(2, Math.min(255, i.maxColors ?? 255));
620
+ }
621
+ /** Number of frames added so far. */
622
+ get frameCount() {
623
+ return this.frames.length;
624
+ }
625
+ /**
626
+ * Quantize and compress one frame.
627
+ *
628
+ * @param delay Frame delay in centiseconds (1/100s), as GIF stores it.
629
+ */
630
+ addFrame(t, o) {
631
+ const { data: r } = t, i = t.width || this.width, u = t.height || this.height, a = mt(r, this.maxColors), { indices: m, hasTransparency: d } = pt(r, i, u, a, {
632
+ dither: this.dither,
633
+ transparentIndex: 0
634
+ }), e = new A(), f = d ? 2 : 1;
635
+ e.bytes([33, 249, 4]), e.byte(f << 2 | (d ? 1 : 0)), e.uint16LE(Math.max(0, Math.round(o))), e.byte(0), e.byte(0), e.byte(44), e.uint16LE(0), e.uint16LE(0), e.uint16LE(i), e.uint16LE(u), e.byte(135);
636
+ const l = new Uint8Array(256 * 3);
637
+ l.set(a.rgb.subarray(0, Math.min(a.size, 255) * 3), 3), e.bytes(l), e.byte(8), e.bytes(yt(m, 8)), this.frames.push(e.toUint8Array());
638
+ }
639
+ /** Assemble the full GIF byte stream. */
640
+ encodeToBytes() {
641
+ const t = new A();
642
+ t.bytes([71, 73, 70, 56, 57, 97]), t.uint16LE(this.width), t.uint16LE(this.height), t.byte(112), t.byte(0), t.byte(0), t.bytes([33, 255, 11]), t.bytes([78, 69, 84, 83, 67, 65, 80, 69]), t.bytes([50, 46, 48]), t.bytes([3, 1]), t.uint16LE(this.loops), t.byte(0);
643
+ for (const o of this.frames) t.bytes(o);
644
+ return t.byte(59), t.toUint8Array();
645
+ }
646
+ /** Encode and return the GIF as a Blob. */
647
+ encode() {
648
+ const t = this.encodeToBytes();
649
+ return new Blob([t.slice()], { type: "image/gif" });
650
+ }
651
+ }
652
+ const $t = _;
653
+ function It(n, t) {
654
+ const { width: o, height: r, frameRate: i = 30, backgroundColor: u, renderFrame: a } = t, m = document.createElement("canvas");
655
+ m.width = o, m.height = r;
656
+ const d = m.getContext("2d");
657
+ if (!d)
658
+ throw new Error("Failed to get canvas 2D context");
659
+ const e = n.duration, f = 1e3 / i, l = Math.ceil(e / f), s = [];
660
+ for (let c = 0; c <= l; c++) {
661
+ const h = Math.min(c * f, e);
662
+ d.clearRect(0, 0, o, r), u && (d.fillStyle = u, d.fillRect(0, 0, o, r));
663
+ const b = n.getStateAtTime(h);
664
+ a?.(d, b.values, h), s.push({
665
+ time: h,
666
+ imageData: d.getImageData(0, 0, o, r),
667
+ delay: Math.round(f / 10)
668
+ });
669
+ }
670
+ return { frames: s, duration: e, frameCount: s.length };
671
+ }
672
+ async function Ut(n, t) {
673
+ const {
674
+ width: o,
675
+ height: r,
676
+ frameRate: i = 30,
677
+ loops: u = 0,
678
+ backgroundColor: a,
679
+ renderFrame: m,
680
+ dither: d,
681
+ maxColors: e,
682
+ onProgress: f,
683
+ signal: l
684
+ } = t;
685
+ if (typeof document > "u")
686
+ throw new Error("GIF export requires a DOM environment");
687
+ if (!m)
688
+ throw new Error("renderFrame function is required for GIF export");
689
+ const s = document.createElement("canvas");
690
+ s.width = o, s.height = r;
691
+ const c = s.getContext("2d", { willReadFrequently: !0 });
692
+ if (!c)
693
+ throw new Error("Failed to get canvas 2D context");
694
+ const h = new _(o, r, { loops: u, dither: d, maxColors: e }), b = n.duration, y = 1e3 / i, p = Math.max(1, Math.round(b / y)), x = Math.max(2, Math.round(y / 10));
695
+ for (let g = 0; g < p; g++) {
696
+ if (l?.aborted) throw new Error("Export aborted");
697
+ const E = Math.min(g * y, b);
698
+ c.clearRect(0, 0, o, r), a && (c.fillStyle = a, c.fillRect(0, 0, o, r));
699
+ const w = n.getStateAtTime(E);
700
+ await m(c, w.values, E), h.addFrame(c.getImageData(0, 0, o, r), x), f?.((g + 1) / p);
701
+ }
702
+ return h.encode();
703
+ }
704
+ function Rt(n, t = "animation.gif") {
705
+ const o = URL.createObjectURL(n), r = document.createElement("a");
706
+ r.href = o, r.download = t, document.body.appendChild(r), r.click(), document.body.removeChild(r), URL.revokeObjectURL(o);
707
+ }
708
+ const W = (n) => n + n % 2, j = 16, gt = 2;
709
+ function R(n, t) {
710
+ return String.fromCharCode(n[t], n[t + 1], n[t + 2], n[t + 3]);
711
+ }
712
+ function q(n, t) {
713
+ return (n[t] | n[t + 1] << 8 | n[t + 2] << 16 | n[t + 3] << 24) >>> 0;
714
+ }
715
+ function Et(n) {
716
+ if (n.length < 12 || R(n, 0) !== "RIFF" || R(n, 8) !== "WEBP")
717
+ throw new Error("Not a WebP file — the browser may not support canvas WebP encoding");
718
+ let t = null, o = null, r = 0, i = 0, u = !1, a = 12;
719
+ for (; a + 8 <= n.length; ) {
720
+ const m = R(n, a), d = q(n, a + 4), e = n.subarray(a + 8, a + 8 + d), f = n.subarray(a, a + 8 + d);
721
+ if (m === "VP8X")
722
+ u = (e[0] & j) !== 0, r = (e[4] | e[5] << 8 | e[6] << 16) + 1, i = (e[7] | e[8] << 8 | e[9] << 16) + 1;
723
+ else if (m === "ALPH")
724
+ o = f, u = !0;
725
+ else if (m === "VP8 ")
726
+ t = f, !r && e.length >= 10 && (r = (e[6] | e[7] << 8) & 16383 || r, i = (e[8] | e[9] << 8) & 16383 || i);
727
+ else if (m === "VP8L" && (t = f, !r && e.length >= 5)) {
728
+ const l = q(e, 1);
729
+ r = (l & 16383) + 1, i = (l >> 14 & 16383) + 1, u = u || (l >> 28 & 1) === 1;
730
+ }
731
+ a += 8 + W(d);
732
+ }
733
+ if (!t) throw new Error("WebP file contained no VP8 or VP8L image data");
734
+ return { image: t, alpha: o, width: r, height: i, hasAlpha: u };
735
+ }
736
+ class wt {
737
+ loops;
738
+ background;
739
+ frames = [];
740
+ hasAlpha = !1;
741
+ width;
742
+ height;
743
+ constructor(t, o, r = {}) {
744
+ this.width = t, this.height = o, this.loops = r.loops ?? 0, this.background = r.background ?? [0, 0, 0, 0];
745
+ }
746
+ get frameCount() {
747
+ return this.frames.length;
748
+ }
749
+ /**
750
+ * Add one frame from the bytes of a still WebP image.
751
+ *
752
+ * @param durationMs How long the frame is shown, in milliseconds.
753
+ */
754
+ addFrame(t, o) {
755
+ const r = Et(t);
756
+ r.hasAlpha && (this.hasAlpha = !0), this.frames.push({ bitstream: r, durationMs: o });
757
+ }
758
+ /** Assemble the animated WebP byte stream. */
759
+ encodeToBytes() {
760
+ if (this.frames.length === 0)
761
+ throw new Error("Cannot encode an animated WebP with no frames");
762
+ const t = new A();
763
+ t.ascii("RIFF");
764
+ const o = t.length;
765
+ t.uint32LE(0), t.ascii("WEBP"), t.ascii("VP8X"), t.uint32LE(10), t.byte(gt | (this.hasAlpha ? j : 0)), t.uint24LE(0), t.uint24LE(this.width - 1), t.uint24LE(this.height - 1);
766
+ const [r, i, u, a] = this.background;
767
+ t.ascii("ANIM"), t.uint32LE(6), t.bytes([u, i, r, a]), t.uint16LE(this.loops);
768
+ for (const { bitstream: m, durationMs: d } of this.frames) {
769
+ const e = 16 + W(m.alpha ? m.alpha.length : 0) + W(m.image.length);
770
+ t.ascii("ANMF"), t.uint32LE(e), t.uint24LE(0), t.uint24LE(0), t.uint24LE(this.width - 1), t.uint24LE(this.height - 1), t.uint24LE(Math.max(0, Math.round(d))), t.byte(3), m.alpha && (t.bytes(m.alpha), m.alpha.length % 2 && t.byte(0)), t.bytes(m.image), m.image.length % 2 && t.byte(0);
771
+ }
772
+ return t.patchUint32LE(o, t.length - o - 4), t.toUint8Array();
773
+ }
774
+ /** Encode and return the animated WebP as a Blob. */
775
+ encode() {
776
+ return new Blob([this.encodeToBytes().slice()], { type: "image/webp" });
777
+ }
778
+ }
779
+ function xt() {
780
+ if (typeof document > "u") return !1;
781
+ try {
782
+ const n = document.createElement("canvas");
783
+ return n.width = 1, n.height = 1, n.toDataURL("image/webp").startsWith("data:image/webp");
784
+ } catch {
785
+ return !1;
786
+ }
787
+ }
788
+ function Mt(n, t) {
789
+ return new Promise((o, r) => {
790
+ n.toBlob(
791
+ (i) => {
792
+ if (!i) return r(new Error("Canvas WebP encoding failed"));
793
+ if (i.type !== "image/webp")
794
+ return r(new Error("This browser cannot encode WebP from a canvas"));
795
+ i.arrayBuffer().then((u) => o(new Uint8Array(u))).catch(r);
796
+ },
797
+ "image/webp",
798
+ t
799
+ );
800
+ });
801
+ }
802
+ async function Vt(n, t) {
803
+ const {
804
+ width: o,
805
+ height: r,
806
+ frameRate: i = 30,
807
+ loops: u = 0,
808
+ quality: a = 0.8,
809
+ backgroundColor: m,
810
+ renderFrame: d,
811
+ onProgress: e,
812
+ signal: f
813
+ } = t;
814
+ if (typeof document > "u")
815
+ throw new Error("WebP export requires a DOM environment");
816
+ if (!xt())
817
+ throw new Error("This browser cannot encode WebP from a canvas. Try Chrome, Edge, or Firefox.");
818
+ const l = document.createElement("canvas");
819
+ l.width = o, l.height = r;
820
+ const s = l.getContext("2d");
821
+ if (!s) throw new Error("Failed to get canvas 2D context");
822
+ const c = new wt(o, r, { loops: u }), h = n.duration, b = 1e3 / i, y = Math.max(1, Math.round(h / b));
823
+ for (let p = 0; p < y; p++) {
824
+ if (f?.aborted) throw new Error("Export aborted");
825
+ const x = Math.min(p * b, h);
826
+ s.clearRect(0, 0, o, r), m && (s.fillStyle = m, s.fillRect(0, 0, o, r));
827
+ const g = n.getStateAtTime(x);
828
+ await d(s, g.values, x), c.addFrame(await Mt(l, a), Math.round(b)), e?.((p + 1) / y);
829
+ }
830
+ return c.encode();
831
+ }
832
+ function Wt(n, t = "animation.webp") {
833
+ const o = URL.createObjectURL(n), r = document.createElement("a");
834
+ r.href = o, r.download = t, document.body.appendChild(r), r.click(), r.remove(), setTimeout(() => URL.revokeObjectURL(o), 1e3);
835
+ }
836
+ const V = (n) => Math.round(n * 65536), K = [65536, 0, 0, 0, 65536, 0, 0, 0, 1073741824];
837
+ function v(n, t, o) {
838
+ const r = n.length;
839
+ n.uint32BE(0), n.ascii(t), o(), n.patchUint32BE(r, n.length - r);
840
+ }
841
+ function k(n, t, o, r, i) {
842
+ v(n, t, () => {
843
+ n.byte(o), n.uint24BE(r), i();
844
+ });
845
+ }
846
+ function Bt(n, t) {
847
+ const { width: o, height: r, timescale: i, avcC: u } = t;
848
+ if (n.length === 0)
849
+ throw new Error("Cannot mux an MP4 with no samples");
850
+ const a = n.reduce((c, h) => c + h.duration, 0), m = 1e3, d = Math.round(a / i * m), e = new A(64 * 1024);
851
+ v(e, "ftyp", () => {
852
+ e.ascii("isom"), e.uint32BE(512), e.ascii("isom"), e.ascii("iso2"), e.ascii("avc1"), e.ascii("mp41");
853
+ });
854
+ const f = e.length;
855
+ e.uint32BE(0), e.ascii("mdat");
856
+ const l = e.length;
857
+ for (const c of n) e.bytes(c.data);
858
+ const s = e.length - f;
859
+ if (s > 4294967295)
860
+ throw new Error("Exported video exceeds the 4GB limit of a 32-bit mdat box");
861
+ return e.patchUint32BE(f, s), v(e, "moov", () => {
862
+ k(e, "mvhd", 0, 0, () => {
863
+ e.uint32BE(0), e.uint32BE(0), e.uint32BE(m), e.uint32BE(d), e.uint32BE(V(1)), e.uint16BE(256), e.uint16BE(0), e.uint32BE(0), e.uint32BE(0);
864
+ for (const c of K) e.uint32BE(c);
865
+ for (let c = 0; c < 6; c++) e.uint32BE(0);
866
+ e.uint32BE(2);
867
+ }), v(e, "trak", () => {
868
+ k(e, "tkhd", 0, 3, () => {
869
+ e.uint32BE(0), e.uint32BE(0), e.uint32BE(1), e.uint32BE(0), e.uint32BE(d), e.uint32BE(0), e.uint32BE(0), e.uint16BE(0), e.uint16BE(0), e.uint16BE(0), e.uint16BE(0);
870
+ for (const c of K) e.uint32BE(c);
871
+ e.uint32BE(V(o)), e.uint32BE(V(r));
872
+ }), v(e, "mdia", () => {
873
+ k(e, "mdhd", 0, 0, () => {
874
+ e.uint32BE(0), e.uint32BE(0), e.uint32BE(i), e.uint32BE(a), e.uint16BE(21956), e.uint16BE(0);
875
+ }), k(e, "hdlr", 0, 0, () => {
876
+ e.uint32BE(0), e.ascii("vide"), e.uint32BE(0), e.uint32BE(0), e.uint32BE(0), e.ascii("VideoHandler"), e.byte(0);
877
+ }), v(e, "minf", () => {
878
+ k(e, "vmhd", 0, 1, () => {
879
+ e.uint16BE(0), e.uint16BE(0), e.uint16BE(0), e.uint16BE(0);
880
+ }), v(e, "dinf", () => {
881
+ k(e, "dref", 0, 0, () => {
882
+ e.uint32BE(1), k(e, "url ", 0, 1, () => {
883
+ });
884
+ });
885
+ }), v(e, "stbl", () => {
886
+ k(e, "stsd", 0, 0, () => {
887
+ e.uint32BE(1), v(e, "avc1", () => {
888
+ e.uint32BE(0), e.uint16BE(0), e.uint16BE(1), e.uint16BE(0), e.uint16BE(0), e.uint32BE(0), e.uint32BE(0), e.uint32BE(0), e.uint16BE(o), e.uint16BE(r), e.uint32BE(4718592), e.uint32BE(4718592), e.uint32BE(0), e.uint16BE(1), e.byte(0);
889
+ for (let b = 0; b < 31; b++) e.byte(0);
890
+ e.uint16BE(24), e.uint16BE(65535), v(e, "avcC", () => {
891
+ e.bytes(u);
892
+ });
893
+ });
894
+ });
895
+ const c = [];
896
+ for (const b of n) {
897
+ const y = c[c.length - 1];
898
+ y && y.delta === b.duration ? y.count++ : c.push({ count: 1, delta: b.duration });
899
+ }
900
+ k(e, "stts", 0, 0, () => {
901
+ e.uint32BE(c.length);
902
+ for (const b of c)
903
+ e.uint32BE(b.count), e.uint32BE(b.delta);
904
+ });
905
+ const h = [];
906
+ n.forEach((b, y) => {
907
+ b.isKeyFrame && h.push(y + 1);
908
+ }), h.length !== n.length && k(e, "stss", 0, 0, () => {
909
+ e.uint32BE(h.length);
910
+ for (const b of h) e.uint32BE(b);
911
+ }), k(e, "stsc", 0, 0, () => {
912
+ e.uint32BE(1), e.uint32BE(1), e.uint32BE(n.length), e.uint32BE(1);
913
+ }), k(e, "stsz", 0, 0, () => {
914
+ e.uint32BE(0), e.uint32BE(n.length);
915
+ for (const b of n) e.uint32BE(b.data.length);
916
+ }), k(e, "stco", 0, 0, () => {
917
+ e.uint32BE(1), e.uint32BE(l);
918
+ });
919
+ });
920
+ });
921
+ });
922
+ });
923
+ }), e.toBytes();
924
+ }
925
+ const kt = [
926
+ "avc1.42001f",
927
+ // Baseline 3.1
928
+ "avc1.4d0028",
929
+ // Main 4.0
930
+ "avc1.640028",
931
+ // High 4.0
932
+ "avc1.42E01E"
933
+ // Constrained Baseline 3.0
934
+ ];
935
+ function S() {
936
+ return typeof VideoEncoder < "u" && typeof VideoFrame < "u";
937
+ }
938
+ async function vt(n, t, o, r) {
939
+ if (!S()) return null;
940
+ for (const i of kt)
941
+ try {
942
+ if ((await VideoEncoder.isConfigSupported({
943
+ codec: i,
944
+ width: n,
945
+ height: t,
946
+ framerate: o,
947
+ bitrate: r,
948
+ avc: { format: "avc" }
949
+ })).supported) return i;
950
+ } catch {
951
+ }
952
+ return null;
953
+ }
954
+ async function Tt(n) {
955
+ const { durationMs: t, renderFrame: o, onProgress: r, signal: i } = n, u = n.fps ?? 30;
956
+ if (typeof document > "u")
957
+ throw new Error("MP4 export requires a DOM environment");
958
+ if (!S())
959
+ throw new Error("This browser has no WebCodecs VideoEncoder");
960
+ const a = Math.max(2, Math.round(n.width / 2) * 2), m = Math.max(2, Math.round(n.height / 2) * 2), d = n.bitrate ?? Math.round(a * m * u * (n.bitsPerPixel ?? 0.25)), e = await vt(a, m, u, d);
961
+ if (!e)
962
+ throw new Error("This browser cannot encode H.264 at the requested size");
963
+ const f = document.createElement("canvas");
964
+ f.width = a, f.height = m;
965
+ const l = f.getContext("2d");
966
+ if (!l) throw new Error("Failed to get canvas 2D context");
967
+ const s = [];
968
+ let c = null, h = null;
969
+ const b = u * 1e3, y = 1e3, p = new VideoEncoder({
970
+ output: (M, C) => {
971
+ const T = C?.decoderConfig?.description;
972
+ T && !c && (c = ArrayBuffer.isView(T) ? new Uint8Array(T.buffer, T.byteOffset, T.byteLength).slice() : new Uint8Array(T).slice());
973
+ const L = new Uint8Array(M.byteLength);
974
+ M.copyTo(L), s.push({
975
+ data: L,
976
+ duration: y,
977
+ isKeyFrame: M.type === "key"
978
+ });
979
+ },
980
+ error: (M) => {
981
+ h = M instanceof Error ? M : new Error(String(M));
982
+ }
983
+ });
984
+ p.configure({
985
+ codec: e,
986
+ width: a,
987
+ height: m,
988
+ framerate: u,
989
+ bitrate: d,
990
+ // 'avc' gives length-prefixed samples that match the avcC record; the
991
+ // alternative, Annex-B, is not what an MP4 sample table expects.
992
+ avc: { format: "avc" },
993
+ // We are not streaming, so let the encoder spend time on quality.
994
+ latencyMode: "quality"
995
+ });
996
+ const x = 1e6 / u, g = Math.max(1, Math.round(t / (1e3 / u))), E = n.keyFrameInterval ?? Math.max(1, Math.round(u * 2)), w = n.background === void 0 ? "#ffffff" : n.background;
997
+ try {
998
+ for (let M = 0; M < g; M++) {
999
+ if (i?.aborted) throw new Error("Export aborted");
1000
+ if (h) throw h;
1001
+ const C = Math.min(t, M * (1e3 / u));
1002
+ l.clearRect(0, 0, a, m), w && (l.fillStyle = w, l.fillRect(0, 0, a, m)), await o(l, C);
1003
+ const T = new VideoFrame(f, {
1004
+ timestamp: Math.round(M * x),
1005
+ duration: Math.round(x)
1006
+ });
1007
+ for (p.encode(T, { keyFrame: M % E === 0 }), T.close(); p.encodeQueueSize > 8; )
1008
+ if (await new Promise((L) => setTimeout(L, 0)), h) throw h;
1009
+ r?.((M + 1) / g);
1010
+ }
1011
+ if (await p.flush(), h) throw h;
1012
+ } finally {
1013
+ p.state !== "closed" && p.close();
1014
+ }
1015
+ if (!c)
1016
+ throw new Error("Encoder produced no H.264 decoder configuration");
1017
+ const B = Bt(s, { width: a, height: m, timescale: b, avcC: c });
1018
+ return new Blob([B], { type: "video/mp4" });
1019
+ }
1020
+ const Ct = [
1021
+ { mimeType: "video/mp4;codecs=avc1.42E01E", extension: "mp4", label: "MP4 (H.264)" },
1022
+ { mimeType: "video/mp4", extension: "mp4", label: "MP4" },
1023
+ { mimeType: "video/webm;codecs=vp9", extension: "webm", label: "WebM (VP9)" },
1024
+ { mimeType: "video/webm;codecs=vp8", extension: "webm", label: "WebM (VP8)" },
1025
+ { mimeType: "video/webm", extension: "webm", label: "WebM" }
1026
+ ];
1027
+ function D() {
1028
+ return typeof MediaRecorder > "u" || typeof MediaRecorder.isTypeSupported != "function" ? [] : Ct.filter((n) => MediaRecorder.isTypeSupported(n.mimeType));
1029
+ }
1030
+ function zt() {
1031
+ return typeof document > "u" ? !1 : S() || D().length > 0;
1032
+ }
1033
+ const Y = "mp4-webcodecs";
1034
+ function Pt() {
1035
+ const n = [];
1036
+ S() && n.push({
1037
+ id: Y,
1038
+ label: "MP4 (H.264)",
1039
+ extension: "mp4",
1040
+ deterministic: !0
1041
+ });
1042
+ for (const t of D())
1043
+ t.extension === "mp4" && S() || n.push({
1044
+ id: t.mimeType,
1045
+ label: `${t.label} (real-time)`,
1046
+ extension: t.extension,
1047
+ deterministic: !1
1048
+ });
1049
+ return n;
1050
+ }
1051
+ async function At(n) {
1052
+ const { width: t, height: o, durationMs: r, renderFrame: i } = n, u = n.fps ?? 30;
1053
+ if (typeof document > "u")
1054
+ throw new Error("Video export requires a DOM environment");
1055
+ const a = D(), m = n.mimeType ?? a[0]?.mimeType;
1056
+ if (!m)
1057
+ throw new Error("This browser cannot record video (MediaRecorder unavailable)");
1058
+ const d = document.createElement("canvas");
1059
+ d.width = t, d.height = o;
1060
+ const e = d.getContext("2d");
1061
+ if (!e) throw new Error("Failed to get canvas 2D context");
1062
+ const f = d.captureStream(0), l = f.getVideoTracks()[0], s = n.bitrate ?? Math.round(t * o * u * 0.25), c = new MediaRecorder(f, { mimeType: m, videoBitsPerSecond: s }), h = [];
1063
+ c.ondataavailable = (g) => {
1064
+ g.data && g.data.size > 0 && h.push(g.data);
1065
+ };
1066
+ const b = new Promise((g, E) => {
1067
+ c.onstop = () => g(), c.onerror = () => E(new Error("Recording failed"));
1068
+ });
1069
+ c.start();
1070
+ const y = 1e3 / u, p = Math.max(1, Math.round(r / y)), x = n.background === void 0 ? "#ffffff" : n.background;
1071
+ try {
1072
+ for (let g = 0; g <= p; g++) {
1073
+ if (n.signal?.aborted) throw new Error("Export aborted");
1074
+ const E = Math.min(r, g * y);
1075
+ e.clearRect(0, 0, t, o), x && (e.fillStyle = x, e.fillRect(0, 0, t, o)), await i(e, E), l?.requestFrame?.(), n.onProgress?.(g / p), await new Promise((w) => setTimeout(w, y));
1076
+ }
1077
+ } finally {
1078
+ c.state !== "inactive" && c.stop(), f.getTracks().forEach((g) => g.stop());
1079
+ }
1080
+ return await b, new Blob(h, { type: m });
1081
+ }
1082
+ async function Dt(n) {
1083
+ const t = Pt();
1084
+ if (t.length === 0)
1085
+ throw new Error("This browser cannot export video");
1086
+ const o = t.find((i) => i.id === n.format) ?? t[0];
1087
+ return o.id === Y ? { blob: await Tt({
1088
+ width: n.width,
1089
+ height: n.height,
1090
+ fps: n.fps,
1091
+ durationMs: n.durationMs,
1092
+ background: n.background,
1093
+ bitrate: n.bitrate,
1094
+ renderFrame: n.renderFrame,
1095
+ onProgress: n.onProgress,
1096
+ signal: n.signal
1097
+ }), extension: o.extension } : { blob: await At({ ...n, mimeType: o.id }), extension: o.extension };
1098
+ }
1099
+ function qt(n, t = "animation.webm") {
1100
+ const o = URL.createObjectURL(n), r = document.createElement("a");
1101
+ r.href = o, r.download = t, document.body.appendChild(r), r.click(), r.remove(), setTimeout(() => URL.revokeObjectURL(o), 1e3);
1102
+ }
1103
+ function Kt(n, t, o, r = 8) {
1104
+ const i = Math.max(1, Math.floor(n)), u = Math.max(1, Math.min(Math.floor(r) || 1, i)), a = Math.ceil(i / u);
1105
+ return {
1106
+ frames: i,
1107
+ columns: u,
1108
+ rows: a,
1109
+ frameWidth: t,
1110
+ frameHeight: o,
1111
+ sheetWidth: u * t,
1112
+ sheetHeight: a * o
1113
+ };
1114
+ }
1115
+ function Ot(n, t) {
1116
+ const o = n % t.columns, r = Math.floor(n / t.columns);
1117
+ return { index: n, col: o, row: r, x: o * t.frameWidth, y: r * t.frameHeight };
1118
+ }
1119
+ function Ht(n, t) {
1120
+ const o = Math.max(1, Math.floor(n)), r = [];
1121
+ for (let i = 0; i < o; i++) r.push(i / o * t);
1122
+ return r;
1123
+ }
1124
+ function Gt(n, t, o) {
1125
+ return {
1126
+ frameWidth: n.frameWidth,
1127
+ frameHeight: n.frameHeight,
1128
+ columns: n.columns,
1129
+ rows: n.rows,
1130
+ frames: n.frames,
1131
+ fps: t,
1132
+ durationMs: o
1133
+ };
1134
+ }
1135
+ export {
1136
+ A as ByteWriter,
1137
+ _ as GIFEncoder,
1138
+ Y as MP4_WEBCODECS,
1139
+ bt as PaletteMatcher,
1140
+ $t as SimpleGIFEncoder,
1141
+ wt as WebPEncoder,
1142
+ mt as buildPalette,
1143
+ Rt as downloadGIF,
1144
+ qt as downloadVideo,
1145
+ Wt as downloadWebP,
1146
+ Lt as exportToCSS,
1147
+ Ut as exportToGIF,
1148
+ dt as exportToLottie,
1149
+ Ft as exportToLottieJSON,
1150
+ Tt as exportToMP4,
1151
+ At as exportToVideo,
1152
+ Vt as exportToWebP,
1153
+ Dt as exportVideo,
1154
+ It as extractFrames,
1155
+ Ot as frameCell,
1156
+ D as getSupportedVideoCodecs,
1157
+ Pt as getVideoExportFormats,
1158
+ zt as isVideoExportSupported,
1159
+ S as isWebCodecsMP4Supported,
1160
+ xt as isWebPExportSupported,
1161
+ yt as lzwEncode,
1162
+ Bt as muxMP4,
1163
+ Et as parseWebPBitstream,
1164
+ vt as pickAVCCodec,
1165
+ pt as quantizeImage,
1166
+ Ht as spriteFrameTimes,
1167
+ Kt as spriteSheetLayout,
1168
+ Gt as spriteSheetMeta
1169
+ };