@algorisys/tinyfly 0.70.1 → 0.74.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.
@@ -1,5 +1,5 @@
1
- import { toKeyframedTracks as O, isTextTrack as H, isCubicBezierEasing as G } from "@algorisys/tinyfly";
2
- const Z = {
1
+ import { toKeyframedTracks as H, isTextTrack as G, isCubicBezierEasing as N, deserializeTimeline as Q } from "@algorisys/tinyfly";
2
+ const tt = {
3
3
  linear: "linear",
4
4
  "ease-in": "ease-in",
5
5
  "ease-out": "ease-out",
@@ -11,14 +11,14 @@ const Z = {
11
11
  "ease-out-cubic": "cubic-bezier(0.215, 0.61, 0.355, 1)",
12
12
  "ease-in-out-cubic": "cubic-bezier(0.645, 0.045, 0.355, 1)"
13
13
  };
14
- function J(n) {
15
- if (G(n)) {
14
+ function et(n) {
15
+ if (N(n)) {
16
16
  const [t, o, r, i] = n.points;
17
17
  return `cubic-bezier(${t}, ${o}, ${r}, ${i})`;
18
18
  }
19
- return typeof n != "string" ? "linear" : Z[n] ?? "linear";
19
+ return typeof n != "string" ? "linear" : tt[n] ?? "linear";
20
20
  }
21
- const Q = {
21
+ const nt = {
22
22
  x: "left",
23
23
  y: "top",
24
24
  width: "width",
@@ -33,11 +33,11 @@ const Q = {
33
33
  strokeWidth: "border-width",
34
34
  borderRadius: "border-radius",
35
35
  fontSize: "font-size"
36
- }, tt = /* @__PURE__ */ new Set(["x", "y", "rotate", "scale", "scaleX", "scaleY"]);
37
- function et(n, t) {
36
+ }, ot = /* @__PURE__ */ new Set(["x", "y", "rotate", "scale", "scaleX", "scaleY"]);
37
+ function rt(n, t) {
38
38
  return typeof t == "number" ? n === "opacity" || n === "scale" || n === "scaleX" || n === "scaleY" ? String(t) : n === "rotate" ? `${t}deg` : `${t}px` : String(t);
39
39
  }
40
- function nt(n) {
40
+ function it(n) {
41
41
  const t = /* @__PURE__ */ new Map();
42
42
  for (const o of n) {
43
43
  const r = t.get(o.target) ?? [];
@@ -45,116 +45,116 @@ function nt(n) {
45
45
  }
46
46
  return t;
47
47
  }
48
- function ot(n, t) {
48
+ function st(n, t) {
49
49
  const o = /* @__PURE__ */ new Set();
50
50
  for (const r of n)
51
51
  for (const i of r.keyframes)
52
52
  o.add(i.time);
53
53
  return o.add(0), o.add(t), Array.from(o).sort((r, i) => r - i);
54
54
  }
55
- function rt(n, t) {
55
+ function at(n, t) {
56
56
  const o = n.keyframes;
57
57
  if (o.length === 0) return null;
58
58
  let r = null, i = null;
59
- for (const u of o)
60
- u.time <= t && (r = u), u.time >= t && !i && (i = u);
59
+ for (const c of o)
60
+ c.time <= t && (r = c), c.time >= t && !i && (i = c);
61
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
62
  }
63
- function it(n) {
64
- return tt.has(n);
63
+ function ct(n) {
64
+ return ot.has(n);
65
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 ? "" : `
66
+ function ut(n, t, o, r) {
67
+ const i = { ...nt, ...r.propertyMap }, c = st(t, o), s = [], l = r.minify ? "" : " ", h = r.minify ? "" : `
68
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);
69
+ s.push(`@keyframes ${n}${e}{`);
70
+ for (const f of c) {
71
+ const d = o > 0 ? Math.round(f / o * 100) : 0, a = [], u = [];
72
+ for (const m of t) {
73
+ const b = at(m, f);
74
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) {
75
+ const g = i[m.property] ?? m.property, p = rt(m.property, b);
76
+ if (ct(m.property))
77
+ switch (m.property) {
78
78
  case "x":
79
- c.push(`translateX(${p})`);
79
+ u.push(`translateX(${p})`);
80
80
  break;
81
81
  case "y":
82
- c.push(`translateY(${p})`);
82
+ u.push(`translateY(${p})`);
83
83
  break;
84
84
  case "rotate":
85
- c.push(`rotate(${p})`);
85
+ u.push(`rotate(${p})`);
86
86
  break;
87
87
  case "scale":
88
- c.push(`scale(${b})`);
88
+ u.push(`scale(${b})`);
89
89
  break;
90
90
  case "scaleX":
91
- c.push(`scaleX(${b})`);
91
+ u.push(`scaleX(${b})`);
92
92
  break;
93
93
  case "scaleY":
94
- c.push(`scaleY(${b})`);
94
+ u.push(`scaleY(${b})`);
95
95
  break;
96
96
  }
97
97
  else
98
- s.push(`${y}:${e}${p}`);
98
+ a.push(`${g}:${e}${p}`);
99
99
  }
100
- c.length > 0 && s.push(`transform:${e}${c.join(" ")}`), s.length > 0 && a.push(`${m}${l}%${e}{${e}${s.join(`;${e}`)}${e}}`);
100
+ u.length > 0 && a.push(`transform:${e}${u.join(" ")}`), a.length > 0 && s.push(`${l}${d}%${e}{${e}${a.join(`;${e}`)}${e}}`);
101
101
  }
102
- return a.push("}"), a.join(d);
102
+ return s.push("}"), s.join(h);
103
103
  }
104
- function at(n) {
104
+ function ft(n) {
105
105
  const t = /* @__PURE__ */ new Map();
106
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);
107
+ for (const c of i.keyframes) {
108
+ const s = c.easing ?? "linear";
109
+ t.set(s, (t.get(s) ?? 0) + 1);
110
110
  }
111
111
  let o = 0, r = "linear";
112
- for (const [i, u] of t)
113
- u > o && (o = u, r = i);
112
+ for (const [i, c] of t)
113
+ c > o && (o = c, r = i);
114
114
  return r;
115
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}`;
116
+ function lt(n, t, o, r, i) {
117
+ const c = i.minify ? "" : " ", s = (t / 1e3).toFixed(2), l = et(ft(o)), h = r.loop === -1 ? "infinite" : r.loop ? r.loop + 1 : 1, e = r.alternate ? "alternate" : "normal";
118
+ return `animation:${c}${n} ${s}s ${l} ${h} ${e}`;
119
119
  }
120
- function Lt(n, t = {}) {
120
+ function It(n, t = {}) {
121
121
  const {
122
122
  classPrefix: o = "tinyfly",
123
123
  includeKeyframes: r = !0,
124
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 = {
125
+ minify: c = !1
126
+ } = t, s = /* @__PURE__ */ new Map(), l = /* @__PURE__ */ new Map(), h = [], e = c ? "" : `
127
+ `, f = c ? "" : " ", d = n.duration, a = {
128
128
  loop: n._config.loop,
129
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, "-")}`;
130
+ }, u = it(H(n.tracks).filter((m) => !G(m)));
131
+ for (const [m, b] of u) {
132
+ const g = `${o}-${m.replace(/[^a-zA-Z0-9]/g, "-")}`;
133
133
  if (r) {
134
- const p = st(y, b, l, t);
135
- a.set(y, p), d.push(p);
134
+ const p = ut(g, b, d, t);
135
+ s.set(g, p), h.push(p);
136
136
  }
137
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);
138
+ const p = lt(g, d, b, a, t), y = `${`.${o}-${m.replace(/[^a-zA-Z0-9]/g, "-")}`}${f}{${e}${c ? "" : " "}${p};${e}}`;
139
+ l.set(m, y), h.push(y);
140
140
  }
141
141
  }
142
142
  return {
143
- css: d.join(e + e),
144
- keyframes: a,
145
- selectors: m
143
+ css: h.join(e + e),
144
+ keyframes: s,
145
+ selectors: l
146
146
  };
147
147
  }
148
- function N(n) {
148
+ function j(n) {
149
149
  const t = {
150
150
  i: { x: [0.833], y: [0.833] },
151
151
  o: { x: [0.167], y: [0.167] }
152
152
  };
153
- if (G(n)) {
154
- const [r, i, u, a] = n.points;
153
+ if (N(n)) {
154
+ const [r, i, c, s] = n.points;
155
155
  return {
156
156
  i: { x: [r], y: [i] },
157
- o: { x: [u], y: [a] }
157
+ o: { x: [c], y: [s] }
158
158
  };
159
159
  }
160
160
  const o = {
@@ -198,10 +198,10 @@ function N(n) {
198
198
  };
199
199
  return typeof n != "string" ? t : o[n] ?? t;
200
200
  }
201
- function z(n, t) {
201
+ function D(n, t) {
202
202
  return Math.round(n / 1e3 * t);
203
203
  }
204
- function ut(n) {
204
+ function ht(n) {
205
205
  if (n.startsWith("#")) {
206
206
  const t = n.slice(1);
207
207
  if (t.length === 3) {
@@ -215,7 +215,7 @@ function ut(n) {
215
215
  }
216
216
  return [0, 0, 0];
217
217
  }
218
- function I(n, t, o = !1) {
218
+ function U(n, t, o = !1) {
219
219
  if (n.length === 0)
220
220
  return o ? { a: 0, k: [0, 0] } : { a: 0, k: 0 };
221
221
  if (n.length === 1) {
@@ -224,21 +224,21 @@ function I(n, t, o = !1) {
224
224
  }
225
225
  const r = [];
226
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
227
+ const c = n[i], s = n[i + 1], l = D(c.time, t), h = typeof c.value == "number" ? [c.value] : [0], e = {
228
+ t: l,
229
+ s: h
230
230
  };
231
- if (a) {
232
- const f = typeof a.value == "number" ? [a.value] : [0];
231
+ if (s) {
232
+ const f = typeof s.value == "number" ? [s.value] : [0];
233
233
  e.e = f;
234
- const l = a.easing ?? "linear", s = N(l);
235
- e.i = s.i, e.o = s.o;
234
+ const d = s.easing ?? "linear", a = j(d);
235
+ e.i = a.i, e.o = a.o;
236
236
  }
237
237
  r.push(e);
238
238
  }
239
239
  return { a: 1, k: r };
240
240
  }
241
- function ft(n) {
241
+ function dt(n) {
242
242
  const t = /* @__PURE__ */ new Map();
243
243
  for (const o of n) {
244
244
  const r = t.get(o.target) ?? [];
@@ -246,7 +246,7 @@ function ft(n) {
246
246
  }
247
247
  return t;
248
248
  }
249
- function lt(n, t) {
249
+ function mt(n, t) {
250
250
  const o = {
251
251
  o: { a: 0, k: 100 },
252
252
  // Default opacity
@@ -259,48 +259,48 @@ function lt(n, t) {
259
259
  s: { a: 0, k: [100, 100] }
260
260
  // Default scale
261
261
  };
262
- for (const u of n) {
263
- const a = u.keyframes;
264
- switch (u.property) {
262
+ for (const c of n) {
263
+ const s = c.keyframes;
264
+ switch (c.property) {
265
265
  case "opacity":
266
- const m = a.map((e) => ({
266
+ const l = s.map((e) => ({
267
267
  ...e,
268
268
  value: e.value * 100
269
269
  }));
270
- o.o = I(m, t);
270
+ o.o = U(l, t);
271
271
  break;
272
272
  case "rotate":
273
273
  case "rotation":
274
- o.r = I(a, t);
274
+ o.r = U(s, t);
275
275
  break;
276
276
  case "scale":
277
- const d = a.map((e) => ({
277
+ const h = s.map((e) => ({
278
278
  ...e,
279
279
  value: e.value * 100
280
280
  }));
281
- o.s = I(d, t, !0);
281
+ o.s = U(h, t, !0);
282
282
  break;
283
283
  }
284
284
  }
285
- const r = n.find((u) => u.property === "x"), i = n.find((u) => u.property === "y");
285
+ const r = n.find((c) => c.property === "x"), i = n.find((c) => c.property === "y");
286
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;
287
+ const c = r?.keyframes ?? [{ time: 0, value: 0 }], s = i?.keyframes ?? [{ time: 0, value: 0 }], l = /* @__PURE__ */ new Set();
288
+ c.forEach((e) => l.add(e.time)), s.forEach((e) => l.add(e.time));
289
+ const h = Array.from(l).sort((e, f) => e - f);
290
+ if (h.length === 1) {
291
+ const e = c[0]?.value ?? 0, f = s[0]?.value ?? 0;
292
292
  o.p = { a: 0, k: [e, f] };
293
293
  } else {
294
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]
295
+ for (let f = 0; f < h.length; f++) {
296
+ const d = h[f], a = h[f + 1], u = L(c, d), m = L(s, d), b = {
297
+ t: D(d, t),
298
+ s: [u, m]
299
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);
300
+ if (a !== void 0) {
301
+ const g = L(c, a), p = L(s, a);
302
+ b.e = [g, p];
303
+ const y = c.find((w) => w.time === a)?.easing ?? "linear", E = j(y);
304
304
  b.i = E.i, b.o = E.o;
305
305
  }
306
306
  e.push(b);
@@ -310,12 +310,12 @@ function lt(n, t) {
310
310
  }
311
311
  return o;
312
312
  }
313
- function F(n, t) {
313
+ function L(n, t) {
314
314
  if (n.length === 0) return 0;
315
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;
316
+ for (const c of n)
317
+ if (c.time <= t && (o = c), c.time >= t) {
318
+ r = c;
319
319
  break;
320
320
  }
321
321
  if (o.time === t) return o.value;
@@ -323,8 +323,8 @@ function F(n, t) {
323
323
  const i = (t - o.time) / (r.time - o.time);
324
324
  return typeof o.value == "number" && typeof r.value == "number" ? o.value + (r.value - o.value) * i : o.value;
325
325
  }
326
- function ht(n, t, o) {
327
- const r = ut(o);
326
+ function bt(n, t, o) {
327
+ const r = ht(o);
328
328
  return [
329
329
  {
330
330
  ty: "rc",
@@ -343,112 +343,112 @@ function ht(n, t, o) {
343
343
  }
344
344
  ];
345
345
  }
346
- function dt(n, t = {}) {
346
+ function pt(n, t = {}) {
347
347
  const {
348
348
  name: o = n.name || "Animation",
349
349
  frameRate: r = 60,
350
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 = [];
351
+ height: c = 512
352
+ } = t, s = n.duration, l = D(s, r), h = dt(H(n.tracks).filter((d) => !G(d))), e = [];
353
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 = {
354
+ for (const [d, a] of h) {
355
+ const u = mt(a, r), b = a.find((p) => p.property === "fill")?.keyframes[0]?.value, g = {
356
356
  ddd: 0,
357
357
  ind: f++,
358
358
  ty: 4,
359
359
  // Shape layer
360
- nm: l,
360
+ nm: d,
361
361
  sr: 1,
362
- ks: c,
362
+ ks: u,
363
363
  ao: 0,
364
- shapes: ht(100, 100, b ?? "#4a9eff"),
364
+ shapes: bt(100, 100, b ?? "#4a9eff"),
365
365
  ip: 0,
366
- op: m,
366
+ op: l,
367
367
  st: 0,
368
368
  bm: 0
369
369
  };
370
- e.push(y);
370
+ e.push(g);
371
371
  }
372
372
  return {
373
373
  v: "5.7.4",
374
374
  nm: o,
375
375
  fr: r,
376
376
  ip: 0,
377
- op: m,
377
+ op: l,
378
378
  w: i,
379
- h: u,
379
+ h: c,
380
380
  ddd: 0,
381
381
  assets: [],
382
382
  layers: e
383
383
  };
384
384
  }
385
- function Ft(n, t = {}) {
386
- return JSON.stringify(dt(n, t));
385
+ function Ut(n, t = {}) {
386
+ return JSON.stringify(pt(n, t));
387
387
  }
388
- const $ = 5, P = 1 << $ * 3, U = 8 - $;
388
+ const F = 5, P = 1 << F * 3, R = 8 - F;
389
389
  function X(n, t, o) {
390
- return n >> U << $ * 2 | t >> U << $ | o >> U;
390
+ return n >> R << F * 2 | t >> R << F | o >> R;
391
391
  }
392
- function mt(n, t) {
393
- const o = new Uint32Array(P), r = new Uint32Array(P), i = new Uint32Array(P), u = new Uint32Array(P);
392
+ function gt(n, t) {
393
+ const o = new Uint32Array(P), r = new Uint32Array(P), i = new Uint32Array(P), c = new Uint32Array(P);
394
394
  for (let f = 0; f < n.length; f += 4) {
395
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;
396
+ const d = n[f], a = n[f + 1], u = n[f + 2], m = X(d, a, u);
397
+ o[m]++, r[m] += d, i[m] += a, c[m] += u;
398
398
  }
399
- const a = [];
399
+ const s = [];
400
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
401
+ const d = o[f];
402
+ d !== 0 && s.push({
403
+ r: Math.round(r[f] / d),
404
+ g: Math.round(i[f] / d),
405
+ b: Math.round(c[f] / d),
406
+ count: d
407
407
  });
408
408
  }
409
- if (a.length === 0)
409
+ if (s.length === 0)
410
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 };
411
+ if (s.length <= t) {
412
+ const f = new Uint8Array(s.length * 3);
413
+ return s.forEach((d, a) => {
414
+ f[a * 3] = d.r, f[a * 3 + 1] = d.g, f[a * 3 + 2] = d.b;
415
+ }), { rgb: f, size: s.length };
416
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);
417
+ const l = (f, d) => {
418
+ let a = 0, u = 255, m = 0, b = 255, g = 0, p = 255, x = 0;
419
+ for (let y = f; y <= d; y++) {
420
+ const E = s[y];
421
+ a += E.count, E.r < u && (u = E.r), E.r > m && (m = E.r), E.g < b && (b = E.g), E.g > g && (g = E.g), E.b < p && (p = E.b), E.b > x && (x = E.b);
422
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);
423
+ return { from: f, to: d, count: a, rMin: u, rMax: m, gMin: b, gMax: g, bMin: p, bMax: x };
424
+ }, h = [l(0, s.length - 1)];
425
+ for (; h.length < t; ) {
426
+ let f = -1, d = 0;
427
+ for (let w = 0; w < h.length; w++) {
428
+ const B = h[w];
429
+ B.to <= B.from || B.count > d && (d = B.count, f = w);
430
430
  }
431
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++)
432
+ const a = h[f], u = a.rMax - a.rMin, m = a.gMax - a.gMin, b = a.bMax - a.bMin, g = u >= m && u >= b ? "r" : m >= b ? "g" : "b", p = s.slice(a.from, a.to + 1);
433
+ p.sort((w, B) => w[g] - B[g]);
434
+ for (let w = 0; w < p.length; w++) s[a.from + w] = p[w];
435
+ const x = a.count / 2;
436
+ let y = 0, E = a.from;
437
+ for (let w = a.from; w < a.to && (y += s[w].count, E = w, !(y >= x)); w++)
438
438
  ;
439
- d[f] = m(s.from, E), d.push(m(E + 1, s.to));
439
+ h[f] = l(a.from, E), h.push(l(E + 1, a.to));
440
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;
441
+ const e = new Uint8Array(h.length * 3);
442
+ return h.forEach((f, d) => {
443
+ let a = 0, u = 0, m = 0, b = 0;
444
+ for (let g = f.from; g <= f.to; g++) {
445
+ const p = s[g];
446
+ a += p.count, u += p.r * p.count, m += p.g * p.count, b += p.b * p.count;
447
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 };
448
+ a === 0 && (a = 1), e[d * 3] = Math.round(u / a), e[d * 3 + 1] = Math.round(m / a), e[d * 3 + 2] = Math.round(b / a);
449
+ }), { rgb: e, size: h.length };
450
450
  }
451
- class bt {
451
+ class yt {
452
452
  cache = new Int16Array(P).fill(-1);
453
453
  palette;
454
454
  /** Palette index `n` is written as `n + offset` (GIF reserves index 0). */
@@ -458,13 +458,13 @@ class bt {
458
458
  }
459
459
  /** Index of the closest palette entry to the given colour. */
460
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))
461
+ const i = X(t, o, r), c = this.cache[i];
462
+ if (c !== -1) return c;
463
+ const { rgb: s, size: l } = this.palette;
464
+ let h = 1 / 0, e = 0;
465
+ for (let d = 0; d < l; d++) {
466
+ const a = t - s[d * 3], u = o - s[d * 3 + 1], m = r - s[d * 3 + 2], b = a * a + u * u + m * m;
467
+ if (b < h && (h = b, e = d, b === 0))
468
468
  break;
469
469
  }
470
470
  const f = e + this.offset;
@@ -476,41 +476,41 @@ class bt {
476
476
  return [this.palette.rgb[o], this.palette.rgb[o + 1], this.palette.rgb[o + 2]];
477
477
  }
478
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);
479
+ function Et(n, t, o, r, i = {}) {
480
+ const { dither: c = !0, transparentIndex: s = 0 } = i, l = new yt(r, s + 1), h = new Uint8Array(t * o);
481
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;
482
+ if (!c) {
483
+ for (let a = 0; a < t * o; a++) {
484
+ const u = a * 4;
485
+ if (n[u + 3] < 128) {
486
+ h[a] = s, e = !0;
487
487
  continue;
488
488
  }
489
- d[s] = m.nearest(n[c], n[c + 1], n[c + 2]);
489
+ h[a] = l.nearest(n[u], n[u + 1], n[u + 2]);
490
490
  }
491
- return { indices: d, hasTransparency: e };
491
+ return { indices: h, hasTransparency: e };
492
492
  }
493
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;
494
+ for (let a = 0; a < t * o; a++)
495
+ f[a * 3] = n[a * 4], f[a * 3 + 1] = n[a * 4 + 1], f[a * 3 + 2] = n[a * 4 + 2];
496
+ const d = (a, u, m, b, g) => {
497
+ f[a * 3] += u * g, f[a * 3 + 1] += m * g, f[a * 3 + 2] += b * g;
498
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;
499
+ for (let a = 0; a < o; a++)
500
+ for (let u = 0; u < t; u++) {
501
+ const m = a * t + u;
502
+ if (n[m * 4 + 3] < 128) {
503
+ h[m] = s, e = !0;
504
504
  continue;
505
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));
506
+ const b = Math.max(0, Math.min(255, f[m * 3])), g = Math.max(0, Math.min(255, f[m * 3 + 1])), p = Math.max(0, Math.min(255, f[m * 3 + 2])), x = l.nearest(b, g, p);
507
+ h[m] = x;
508
+ const [y, E, w] = l.colorAt(x), B = b - y, M = g - E, C = p - w;
509
+ u + 1 < t && d(m + 1, B, M, C, 7 / 16), a + 1 < o && (u > 0 && d(m + t - 1, B, M, C, 3 / 16), d(m + t, B, M, C, 5 / 16), u + 1 < t && d(m + t + 1, B, M, C, 1 / 16));
510
510
  }
511
- return { indices: d, hasTransparency: e };
511
+ return { indices: h, hasTransparency: e };
512
512
  }
513
- class A {
513
+ class S {
514
514
  buf;
515
515
  len = 0;
516
516
  constructor(t = 1024) {
@@ -577,33 +577,33 @@ class A {
577
577
  return this.buf.slice(0, this.len);
578
578
  }
579
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;
580
+ function wt(n, t) {
581
+ const o = 1 << t, r = o + 1, i = new S(), c = new Uint8Array(255);
582
+ let s = 0, l = 0, h = 0;
583
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();
584
+ s !== 0 && (i.byte(s), i.bytes(c.subarray(0, s)), s = 0);
585
+ }, f = (b, g) => {
586
+ for (l |= b << h, h += g; h >= 8; )
587
+ c[s++] = l & 255, l >>= 8, h -= 8, s === 255 && e();
588
588
  };
589
- let l = /* @__PURE__ */ new Map();
590
- const s = () => {
591
- l = /* @__PURE__ */ new Map();
589
+ let d = /* @__PURE__ */ new Map();
590
+ const a = () => {
591
+ d = /* @__PURE__ */ new Map();
592
592
  };
593
- let c = t + 1, h = r + 1;
594
- if (f(o, c), n.length > 0) {
593
+ let u = t + 1, m = r + 1;
594
+ if (f(o, u), n.length > 0) {
595
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;
596
+ for (let g = 1; g < n.length; g++) {
597
+ const p = n[g], x = b << 8 | p, y = d.get(x);
598
+ if (y !== void 0) {
599
+ b = y;
600
600
  continue;
601
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;
602
+ f(b, u), m < 4096 ? (d.set(x, m++), m >= 1 << u && u < 12 && u++) : (f(o, u), a(), u = t + 1, m = r + 1), b = p;
603
603
  }
604
- f(b, c);
604
+ f(b, u);
605
605
  }
606
- return f(r, c), d > 0 && (u[a++] = m & 255), e(), i.byte(0), i.toUint8Array();
606
+ return f(r, u), h > 0 && (c[s++] = l & 255), e(), i.byte(0), i.toUint8Array();
607
607
  }
608
608
  class _ {
609
609
  width;
@@ -628,17 +628,17 @@ class _ {
628
628
  * @param delay Frame delay in centiseconds (1/100s), as GIF stores it.
629
629
  */
630
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, {
631
+ const { data: r } = t, i = t.width || this.width, c = t.height || this.height, s = gt(r, this.maxColors), { indices: l, hasTransparency: h } = Et(r, i, c, s, {
632
632
  dither: this.dither,
633
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());
634
+ }), e = new S(), f = h ? 2 : 1;
635
+ e.bytes([33, 249, 4]), e.byte(f << 2 | (h ? 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(c), e.byte(135);
636
+ const d = new Uint8Array(256 * 3);
637
+ d.set(s.rgb.subarray(0, Math.min(s.size, 255) * 3), 3), e.bytes(d), e.byte(8), e.bytes(wt(l, 8)), this.frames.push(e.toUint8Array());
638
638
  }
639
639
  /** Assemble the full GIF byte stream. */
640
640
  encodeToBytes() {
641
- const t = new A();
641
+ const t = new S();
642
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
643
  for (const o of this.frames) t.bytes(o);
644
644
  return t.byte(59), t.toUint8Array();
@@ -649,91 +649,91 @@ class _ {
649
649
  return new Blob([t.slice()], { type: "image/gif" });
650
650
  }
651
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)
652
+ const Rt = _;
653
+ function Vt(n, t) {
654
+ const { width: o, height: r, frameRate: i = 30, backgroundColor: c, renderFrame: s } = t, l = document.createElement("canvas");
655
+ l.width = o, l.height = r;
656
+ const h = l.getContext("2d");
657
+ if (!h)
658
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),
659
+ const e = n.duration, f = 1e3 / i, d = Math.ceil(e / f), a = [];
660
+ for (let u = 0; u <= d; u++) {
661
+ const m = Math.min(u * f, e);
662
+ h.clearRect(0, 0, o, r), c && (h.fillStyle = c, h.fillRect(0, 0, o, r));
663
+ const b = n.getStateAtTime(m);
664
+ s?.(h, b.values, m), a.push({
665
+ time: m,
666
+ imageData: h.getImageData(0, 0, o, r),
667
667
  delay: Math.round(f / 10)
668
668
  });
669
669
  }
670
- return { frames: s, duration: e, frameCount: s.length };
670
+ return { frames: a, duration: e, frameCount: a.length };
671
671
  }
672
- async function Ut(n, t) {
672
+ async function Wt(n, t) {
673
673
  const {
674
674
  width: o,
675
675
  height: r,
676
676
  frameRate: i = 30,
677
- loops: u = 0,
678
- backgroundColor: a,
679
- renderFrame: m,
680
- dither: d,
677
+ loops: c = 0,
678
+ backgroundColor: s,
679
+ renderFrame: l,
680
+ dither: h,
681
681
  maxColors: e,
682
682
  onProgress: f,
683
- signal: l
683
+ signal: d
684
684
  } = t;
685
685
  if (typeof document > "u")
686
686
  throw new Error("GIF export requires a DOM environment");
687
- if (!m)
687
+ if (!l)
688
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)
689
+ const a = document.createElement("canvas");
690
+ a.width = o, a.height = r;
691
+ const u = a.getContext("2d", { willReadFrequently: !0 });
692
+ if (!u)
693
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));
694
+ const m = new _(o, r, { loops: c, dither: h, maxColors: e }), b = n.duration, g = 1e3 / i, p = Math.max(1, Math.round(b / g)), x = Math.max(2, Math.round(g / 10));
695
+ for (let y = 0; y < p; y++) {
696
+ if (d?.aborted) throw new Error("Export aborted");
697
+ const E = Math.min(y * g, b);
698
+ u.clearRect(0, 0, o, r), s && (u.fillStyle = s, u.fillRect(0, 0, o, r));
699
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);
700
+ await l(u, w.values, E), m.addFrame(u.getImageData(0, 0, o, r), x), f?.((y + 1) / p);
701
701
  }
702
- return h.encode();
702
+ return m.encode();
703
703
  }
704
- function Rt(n, t = "animation.gif") {
704
+ function zt(n, t = "animation.gif") {
705
705
  const o = URL.createObjectURL(n), r = document.createElement("a");
706
706
  r.href = o, r.download = t, document.body.appendChild(r), r.click(), document.body.removeChild(r), URL.revokeObjectURL(o);
707
707
  }
708
- const W = (n) => n + n % 2, j = 16, gt = 2;
709
- function R(n, t) {
708
+ const z = (n) => n + n % 2, Y = 16, xt = 2;
709
+ function V(n, t) {
710
710
  return String.fromCharCode(n[t], n[t + 1], n[t + 2], n[t + 3]);
711
711
  }
712
- function q(n, t) {
712
+ function K(n, t) {
713
713
  return (n[t] | n[t + 1] << 8 | n[t + 2] << 16 | n[t + 3] << 24) >>> 0;
714
714
  }
715
- function Et(n) {
716
- if (n.length < 12 || R(n, 0) !== "RIFF" || R(n, 8) !== "WEBP")
715
+ function Mt(n) {
716
+ if (n.length < 12 || V(n, 0) !== "RIFF" || V(n, 8) !== "WEBP")
717
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 ")
718
+ let t = null, o = null, r = 0, i = 0, c = !1, s = 12;
719
+ for (; s + 8 <= n.length; ) {
720
+ const l = V(n, s), h = K(n, s + 4), e = n.subarray(s + 8, s + 8 + h), f = n.subarray(s, s + 8 + h);
721
+ if (l === "VP8X")
722
+ c = (e[0] & Y) !== 0, r = (e[4] | e[5] << 8 | e[6] << 16) + 1, i = (e[7] | e[8] << 8 | e[9] << 16) + 1;
723
+ else if (l === "ALPH")
724
+ o = f, c = !0;
725
+ else if (l === "VP8 ")
726
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;
727
+ else if (l === "VP8L" && (t = f, !r && e.length >= 5)) {
728
+ const d = K(e, 1);
729
+ r = (d & 16383) + 1, i = (d >> 14 & 16383) + 1, c = c || (d >> 28 & 1) === 1;
730
730
  }
731
- a += 8 + W(d);
731
+ s += 8 + z(h);
732
732
  }
733
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 };
734
+ return { image: t, alpha: o, width: r, height: i, hasAlpha: c };
735
735
  }
736
- class wt {
736
+ class Bt {
737
737
  loops;
738
738
  background;
739
739
  frames = [];
@@ -752,22 +752,22 @@ class wt {
752
752
  * @param durationMs How long the frame is shown, in milliseconds.
753
753
  */
754
754
  addFrame(t, o) {
755
- const r = Et(t);
755
+ const r = Mt(t);
756
756
  r.hasAlpha && (this.hasAlpha = !0), this.frames.push({ bitstream: r, durationMs: o });
757
757
  }
758
758
  /** Assemble the animated WebP byte stream. */
759
759
  encodeToBytes() {
760
760
  if (this.frames.length === 0)
761
761
  throw new Error("Cannot encode an animated WebP with no frames");
762
- const t = new A();
762
+ const t = new S();
763
763
  t.ascii("RIFF");
764
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);
765
+ t.uint32LE(0), t.ascii("WEBP"), t.ascii("VP8X"), t.uint32LE(10), t.byte(xt | (this.hasAlpha ? Y : 0)), t.uint24LE(0), t.uint24LE(this.width - 1), t.uint24LE(this.height - 1);
766
+ const [r, i, c, s] = this.background;
767
+ t.ascii("ANIM"), t.uint32LE(6), t.bytes([c, i, r, s]), t.uint16LE(this.loops);
768
+ for (const { bitstream: l, durationMs: h } of this.frames) {
769
+ const e = 16 + z(l.alpha ? l.alpha.length : 0) + z(l.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(h))), t.byte(3), l.alpha && (t.bytes(l.alpha), l.alpha.length % 2 && t.byte(0)), t.bytes(l.image), l.image.length % 2 && t.byte(0);
771
771
  }
772
772
  return t.patchUint32LE(o, t.length - o - 4), t.toUint8Array();
773
773
  }
@@ -776,7 +776,7 @@ class wt {
776
776
  return new Blob([this.encodeToBytes().slice()], { type: "image/webp" });
777
777
  }
778
778
  }
779
- function xt() {
779
+ function kt() {
780
780
  if (typeof document > "u") return !1;
781
781
  try {
782
782
  const n = document.createElement("canvas");
@@ -785,55 +785,55 @@ function xt() {
785
785
  return !1;
786
786
  }
787
787
  }
788
- function Mt(n, t) {
788
+ function vt(n, t) {
789
789
  return new Promise((o, r) => {
790
790
  n.toBlob(
791
791
  (i) => {
792
792
  if (!i) return r(new Error("Canvas WebP encoding failed"));
793
793
  if (i.type !== "image/webp")
794
794
  return r(new Error("This browser cannot encode WebP from a canvas"));
795
- i.arrayBuffer().then((u) => o(new Uint8Array(u))).catch(r);
795
+ i.arrayBuffer().then((c) => o(new Uint8Array(c))).catch(r);
796
796
  },
797
797
  "image/webp",
798
798
  t
799
799
  );
800
800
  });
801
801
  }
802
- async function Vt(n, t) {
802
+ async function Dt(n, t) {
803
803
  const {
804
804
  width: o,
805
805
  height: r,
806
806
  frameRate: i = 30,
807
- loops: u = 0,
808
- quality: a = 0.8,
809
- backgroundColor: m,
810
- renderFrame: d,
807
+ loops: c = 0,
808
+ quality: s = 0.8,
809
+ backgroundColor: l,
810
+ renderFrame: h,
811
811
  onProgress: e,
812
812
  signal: f
813
813
  } = t;
814
814
  if (typeof document > "u")
815
815
  throw new Error("WebP export requires a DOM environment");
816
- if (!xt())
816
+ if (!kt())
817
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++) {
818
+ const d = document.createElement("canvas");
819
+ d.width = o, d.height = r;
820
+ const a = d.getContext("2d");
821
+ if (!a) throw new Error("Failed to get canvas 2D context");
822
+ const u = new Bt(o, r, { loops: c }), m = n.duration, b = 1e3 / i, g = Math.max(1, Math.round(m / b));
823
+ for (let p = 0; p < g; p++) {
824
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);
825
+ const x = Math.min(p * b, m);
826
+ a.clearRect(0, 0, o, r), l && (a.fillStyle = l, a.fillRect(0, 0, o, r));
827
+ const y = n.getStateAtTime(x);
828
+ await h(a, y.values, x), u.addFrame(await vt(d, s), Math.round(b)), e?.((p + 1) / g);
829
829
  }
830
- return c.encode();
830
+ return u.encode();
831
831
  }
832
- function Wt(n, t = "animation.webp") {
832
+ function qt(n, t = "animation.webp") {
833
833
  const o = URL.createObjectURL(n), r = document.createElement("a");
834
834
  r.href = o, r.download = t, document.body.appendChild(r), r.click(), r.remove(), setTimeout(() => URL.revokeObjectURL(o), 1e3);
835
835
  }
836
- const V = (n) => Math.round(n * 65536), K = [65536, 0, 0, 0, 65536, 0, 0, 0, 1073741824];
836
+ const W = (n) => Math.round(n * 65536), O = [65536, 0, 0, 0, 65536, 0, 0, 0, 1073741824];
837
837
  function v(n, t, o) {
838
838
  const r = n.length;
839
839
  n.uint32BE(0), n.ascii(t), o(), n.patchUint32BE(r, n.length - r);
@@ -843,35 +843,35 @@ function k(n, t, o, r, i) {
843
843
  n.byte(o), n.uint24BE(r), i();
844
844
  });
845
845
  }
846
- function Bt(n, t) {
847
- const { width: o, height: r, timescale: i, avcC: u } = t;
846
+ function Tt(n, t) {
847
+ const { width: o, height: r, timescale: i, avcC: c } = t;
848
848
  if (n.length === 0)
849
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);
850
+ const s = n.reduce((u, m) => u + m.duration, 0), l = 1e3, h = Math.round(s / i * l), e = new S(64 * 1024);
851
851
  v(e, "ftyp", () => {
852
852
  e.ascii("isom"), e.uint32BE(512), e.ascii("isom"), e.ascii("iso2"), e.ascii("avc1"), e.ascii("mp41");
853
853
  });
854
854
  const f = e.length;
855
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)
856
+ const d = e.length;
857
+ for (const u of n) e.bytes(u.data);
858
+ const a = e.length - f;
859
+ if (a > 4294967295)
860
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", () => {
861
+ return e.patchUint32BE(f, a), v(e, "moov", () => {
862
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);
863
+ e.uint32BE(0), e.uint32BE(0), e.uint32BE(l), e.uint32BE(h), e.uint32BE(W(1)), e.uint16BE(256), e.uint16BE(0), e.uint32BE(0), e.uint32BE(0);
864
+ for (const u of O) e.uint32BE(u);
865
+ for (let u = 0; u < 6; u++) e.uint32BE(0);
866
866
  e.uint32BE(2);
867
867
  }), v(e, "trak", () => {
868
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));
869
+ e.uint32BE(0), e.uint32BE(0), e.uint32BE(1), e.uint32BE(0), e.uint32BE(h), e.uint32BE(0), e.uint32BE(0), e.uint16BE(0), e.uint16BE(0), e.uint16BE(0), e.uint16BE(0);
870
+ for (const u of O) e.uint32BE(u);
871
+ e.uint32BE(W(o)), e.uint32BE(W(r));
872
872
  }), v(e, "mdia", () => {
873
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);
874
+ e.uint32BE(0), e.uint32BE(0), e.uint32BE(i), e.uint32BE(s), e.uint16BE(21956), e.uint16BE(0);
875
875
  }), k(e, "hdlr", 0, 0, () => {
876
876
  e.uint32BE(0), e.ascii("vide"), e.uint32BE(0), e.uint32BE(0), e.uint32BE(0), e.ascii("VideoHandler"), e.byte(0);
877
877
  }), v(e, "minf", () => {
@@ -888,33 +888,33 @@ function Bt(n, t) {
888
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
889
  for (let b = 0; b < 31; b++) e.byte(0);
890
890
  e.uint16BE(24), e.uint16BE(65535), v(e, "avcC", () => {
891
- e.bytes(u);
891
+ e.bytes(c);
892
892
  });
893
893
  });
894
894
  });
895
- const c = [];
895
+ const u = [];
896
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 });
897
+ const g = u[u.length - 1];
898
+ g && g.delta === b.duration ? g.count++ : u.push({ count: 1, delta: b.duration });
899
899
  }
900
900
  k(e, "stts", 0, 0, () => {
901
- e.uint32BE(c.length);
902
- for (const b of c)
901
+ e.uint32BE(u.length);
902
+ for (const b of u)
903
903
  e.uint32BE(b.count), e.uint32BE(b.delta);
904
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);
905
+ const m = [];
906
+ n.forEach((b, g) => {
907
+ b.isKeyFrame && m.push(g + 1);
908
+ }), m.length !== n.length && k(e, "stss", 0, 0, () => {
909
+ e.uint32BE(m.length);
910
+ for (const b of m) e.uint32BE(b);
911
911
  }), k(e, "stsc", 0, 0, () => {
912
912
  e.uint32BE(1), e.uint32BE(1), e.uint32BE(n.length), e.uint32BE(1);
913
913
  }), k(e, "stsz", 0, 0, () => {
914
914
  e.uint32BE(0), e.uint32BE(n.length);
915
915
  for (const b of n) e.uint32BE(b.data.length);
916
916
  }), k(e, "stco", 0, 0, () => {
917
- e.uint32BE(1), e.uint32BE(l);
917
+ e.uint32BE(1), e.uint32BE(d);
918
918
  });
919
919
  });
920
920
  });
@@ -922,7 +922,7 @@ function Bt(n, t) {
922
922
  });
923
923
  }), e.toBytes();
924
924
  }
925
- const kt = [
925
+ const Ct = [
926
926
  "avc1.42001f",
927
927
  // Baseline 3.1
928
928
  "avc1.4d0028",
@@ -932,12 +932,12 @@ const kt = [
932
932
  "avc1.42E01E"
933
933
  // Constrained Baseline 3.0
934
934
  ];
935
- function S() {
935
+ function A() {
936
936
  return typeof VideoEncoder < "u" && typeof VideoFrame < "u";
937
937
  }
938
- async function vt(n, t, o, r) {
939
- if (!S()) return null;
940
- for (const i of kt)
938
+ async function Pt(n, t, o, r) {
939
+ if (!A()) return null;
940
+ for (const i of Ct)
941
941
  try {
942
942
  if ((await VideoEncoder.isConfigSupported({
943
943
  codec: i,
@@ -951,96 +951,96 @@ async function vt(n, t, o, r) {
951
951
  }
952
952
  return null;
953
953
  }
954
- async function Tt(n) {
955
- const { durationMs: t, renderFrame: o, onProgress: r, signal: i } = n, u = n.fps ?? 30;
954
+ async function St(n) {
955
+ const { durationMs: t, renderFrame: o, onProgress: r, signal: i } = n, c = n.fps ?? 30;
956
956
  if (typeof document > "u")
957
957
  throw new Error("MP4 export requires a DOM environment");
958
- if (!S())
958
+ if (!A())
959
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);
960
+ const s = Math.max(2, Math.round(n.width / 2) * 2), l = Math.max(2, Math.round(n.height / 2) * 2), h = n.bitrate ?? Math.round(s * l * c * (n.bitsPerPixel ?? 0.25)), e = await Pt(s, l, c, h);
961
961
  if (!e)
962
962
  throw new Error("This browser cannot encode H.264 at the requested size");
963
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({
964
+ f.width = s, f.height = l;
965
+ const d = f.getContext("2d");
966
+ if (!d) throw new Error("Failed to get canvas 2D context");
967
+ const a = [];
968
+ let u = null, m = null;
969
+ const b = c * 1e3, g = 1e3, p = new VideoEncoder({
970
970
  output: (M, C) => {
971
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,
972
+ T && !u && (u = ArrayBuffer.isView(T) ? new Uint8Array(T.buffer, T.byteOffset, T.byteLength).slice() : new Uint8Array(T).slice());
973
+ const $ = new Uint8Array(M.byteLength);
974
+ M.copyTo($), a.push({
975
+ data: $,
976
+ duration: g,
977
977
  isKeyFrame: M.type === "key"
978
978
  });
979
979
  },
980
980
  error: (M) => {
981
- h = M instanceof Error ? M : new Error(String(M));
981
+ m = M instanceof Error ? M : new Error(String(M));
982
982
  }
983
983
  });
984
984
  p.configure({
985
985
  codec: e,
986
- width: a,
987
- height: m,
988
- framerate: u,
989
- bitrate: d,
986
+ width: s,
987
+ height: l,
988
+ framerate: c,
989
+ bitrate: h,
990
990
  // 'avc' gives length-prefixed samples that match the avcC record; the
991
991
  // alternative, Annex-B, is not what an MP4 sample table expects.
992
992
  avc: { format: "avc" },
993
993
  // We are not streaming, so let the encoder spend time on quality.
994
994
  latencyMode: "quality"
995
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;
996
+ const x = 1e6 / c, y = Math.max(1, Math.round(t / (1e3 / c))), E = n.keyFrameInterval ?? Math.max(1, Math.round(c * 2)), w = n.background === void 0 ? "#ffffff" : n.background;
997
997
  try {
998
- for (let M = 0; M < g; M++) {
998
+ for (let M = 0; M < y; M++) {
999
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);
1000
+ if (m) throw m;
1001
+ const C = Math.min(t, M * (1e3 / c));
1002
+ d.clearRect(0, 0, s, l), w && (d.fillStyle = w, d.fillRect(0, 0, s, l)), await o(d, C);
1003
1003
  const T = new VideoFrame(f, {
1004
1004
  timestamp: Math.round(M * x),
1005
1005
  duration: Math.round(x)
1006
1006
  });
1007
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);
1008
+ if (await new Promise(($) => setTimeout($, 0)), m) throw m;
1009
+ r?.((M + 1) / y);
1010
1010
  }
1011
- if (await p.flush(), h) throw h;
1011
+ if (await p.flush(), m) throw m;
1012
1012
  } finally {
1013
1013
  p.state !== "closed" && p.close();
1014
1014
  }
1015
- if (!c)
1015
+ if (!u)
1016
1016
  throw new Error("Encoder produced no H.264 decoder configuration");
1017
- const B = Bt(s, { width: a, height: m, timescale: b, avcC: c });
1017
+ const B = Tt(a, { width: s, height: l, timescale: b, avcC: u });
1018
1018
  return new Blob([B], { type: "video/mp4" });
1019
1019
  }
1020
- const Ct = [
1020
+ const At = [
1021
1021
  { mimeType: "video/mp4;codecs=avc1.42E01E", extension: "mp4", label: "MP4 (H.264)" },
1022
1022
  { mimeType: "video/mp4", extension: "mp4", label: "MP4" },
1023
1023
  { mimeType: "video/webm;codecs=vp9", extension: "webm", label: "WebM (VP9)" },
1024
1024
  { mimeType: "video/webm;codecs=vp8", extension: "webm", label: "WebM (VP8)" },
1025
1025
  { mimeType: "video/webm", extension: "webm", label: "WebM" }
1026
1026
  ];
1027
- function D() {
1028
- return typeof MediaRecorder > "u" || typeof MediaRecorder.isTypeSupported != "function" ? [] : Ct.filter((n) => MediaRecorder.isTypeSupported(n.mimeType));
1027
+ function q() {
1028
+ return typeof MediaRecorder > "u" || typeof MediaRecorder.isTypeSupported != "function" ? [] : At.filter((n) => MediaRecorder.isTypeSupported(n.mimeType));
1029
1029
  }
1030
- function zt() {
1031
- return typeof document > "u" ? !1 : S() || D().length > 0;
1030
+ function Kt() {
1031
+ return typeof document > "u" ? !1 : A() || q().length > 0;
1032
1032
  }
1033
- const Y = "mp4-webcodecs";
1034
- function Pt() {
1033
+ const Z = "mp4-webcodecs";
1034
+ function $t() {
1035
1035
  const n = [];
1036
- S() && n.push({
1037
- id: Y,
1036
+ A() && n.push({
1037
+ id: Z,
1038
1038
  label: "MP4 (H.264)",
1039
1039
  extension: "mp4",
1040
1040
  deterministic: !0
1041
1041
  });
1042
- for (const t of D())
1043
- t.extension === "mp4" && S() || n.push({
1042
+ for (const t of q())
1043
+ t.extension === "mp4" && A() || n.push({
1044
1044
  id: t.mimeType,
1045
1045
  label: `${t.label} (real-time)`,
1046
1046
  extension: t.extension,
@@ -1048,43 +1048,43 @@ function Pt() {
1048
1048
  });
1049
1049
  return n;
1050
1050
  }
1051
- async function At(n) {
1052
- const { width: t, height: o, durationMs: r, renderFrame: i } = n, u = n.fps ?? 30;
1051
+ async function Lt(n) {
1052
+ const { width: t, height: o, durationMs: r, renderFrame: i } = n, c = n.fps ?? 30;
1053
1053
  if (typeof document > "u")
1054
1054
  throw new Error("Video export requires a DOM environment");
1055
- const a = D(), m = n.mimeType ?? a[0]?.mimeType;
1056
- if (!m)
1055
+ const s = q(), l = n.mimeType ?? s[0]?.mimeType;
1056
+ if (!l)
1057
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");
1058
+ const h = document.createElement("canvas");
1059
+ h.width = t, h.height = o;
1060
+ const e = h.getContext("2d");
1061
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);
1062
+ const f = h.captureStream(0), d = f.getVideoTracks()[0], a = n.bitrate ?? Math.round(t * o * c * 0.25), u = new MediaRecorder(f, { mimeType: l, videoBitsPerSecond: a }), m = [];
1063
+ u.ondataavailable = (y) => {
1064
+ y.data && y.data.size > 0 && m.push(y.data);
1065
1065
  };
1066
- const b = new Promise((g, E) => {
1067
- c.onstop = () => g(), c.onerror = () => E(new Error("Recording failed"));
1066
+ const b = new Promise((y, E) => {
1067
+ u.onstop = () => y(), u.onerror = () => E(new Error("Recording failed"));
1068
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;
1069
+ u.start();
1070
+ const g = 1e3 / c, p = Math.max(1, Math.round(r / g)), x = n.background === void 0 ? "#ffffff" : n.background;
1071
1071
  try {
1072
- for (let g = 0; g <= p; g++) {
1072
+ for (let y = 0; y <= p; y++) {
1073
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));
1074
+ const E = Math.min(r, y * g);
1075
+ e.clearRect(0, 0, t, o), x && (e.fillStyle = x, e.fillRect(0, 0, t, o)), await i(e, E), d?.requestFrame?.(), n.onProgress?.(y / p), await new Promise((w) => setTimeout(w, g));
1076
1076
  }
1077
1077
  } finally {
1078
- c.state !== "inactive" && c.stop(), f.getTracks().forEach((g) => g.stop());
1078
+ u.state !== "inactive" && u.stop(), f.getTracks().forEach((y) => y.stop());
1079
1079
  }
1080
- return await b, new Blob(h, { type: m });
1080
+ return await b, new Blob(m, { type: l });
1081
1081
  }
1082
- async function Dt(n) {
1083
- const t = Pt();
1082
+ async function Ot(n) {
1083
+ const t = $t();
1084
1084
  if (t.length === 0)
1085
1085
  throw new Error("This browser cannot export video");
1086
1086
  const o = t.find((i) => i.id === n.format) ?? t[0];
1087
- return o.id === Y ? { blob: await Tt({
1087
+ return o.id === Z ? { blob: await St({
1088
1088
  width: n.width,
1089
1089
  height: n.height,
1090
1090
  fps: n.fps,
@@ -1094,34 +1094,67 @@ async function Dt(n) {
1094
1094
  renderFrame: n.renderFrame,
1095
1095
  onProgress: n.onProgress,
1096
1096
  signal: n.signal
1097
- }), extension: o.extension } : { blob: await At({ ...n, mimeType: o.id }), extension: o.extension };
1097
+ }), extension: o.extension } : { blob: await Lt({ ...n, mimeType: o.id }), extension: o.extension };
1098
1098
  }
1099
- function qt(n, t = "animation.webm") {
1099
+ function Ht(n, t = "animation.webm") {
1100
1100
  const o = URL.createObjectURL(n), r = document.createElement("a");
1101
1101
  r.href = o, r.download = t, document.body.appendChild(r), r.click(), r.remove(), setTimeout(() => URL.revokeObjectURL(o), 1e3);
1102
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);
1103
+ function I(n, t) {
1104
+ const o = Math.max(0, Math.round(n)), r = Math.floor(o / 36e5), i = Math.floor(o % 36e5 / 6e4), c = Math.floor(o % 6e4 / 1e3), s = o % 1e3, l = (h, e = 2) => String(h).padStart(e, "0");
1105
+ return `${l(r)}:${l(i)}:${l(c)}${t}${l(s, 3)}`;
1106
+ }
1107
+ function J(n) {
1108
+ return n.replace(/\r\n?/g, `
1109
+ `).replace(/\n{2,}/g, `
1110
+ `).trim();
1111
+ }
1112
+ function Gt(n) {
1113
+ return n.map((t, o) => `${o + 1}
1114
+ ${I(t.start, ",")} --> ${I(t.end, ",")}
1115
+ ${J(t.text)}
1116
+ `).join(`
1117
+ `);
1118
+ }
1119
+ function Nt(n) {
1120
+ return `WEBVTT
1121
+
1122
+ ${n.map((o) => `${I(o.start, ".")} --> ${I(o.end, ".")}
1123
+ ${J(o.text)}
1124
+ `).join(`
1125
+ `)}`;
1126
+ }
1127
+ function jt(n, t = {}) {
1128
+ const o = [...n.config.markers ?? []].sort((s, l) => s.time - l.time), r = t.language ? n.captions?.[t.language] : void 0, i = Q(n).duration, c = [];
1129
+ return o.forEach((s, l) => {
1130
+ const h = r?.[s.id] ?? s.label;
1131
+ if (!h) return;
1132
+ const e = l + 1 < o.length ? o[l + 1].time : i;
1133
+ e > s.time && c.push({ start: s.time, end: e, text: h });
1134
+ }), c;
1135
+ }
1136
+ function Xt(n, t, o, r = 8) {
1137
+ const i = Math.max(1, Math.floor(n)), c = Math.max(1, Math.min(Math.floor(r) || 1, i)), s = Math.ceil(i / c);
1105
1138
  return {
1106
1139
  frames: i,
1107
- columns: u,
1108
- rows: a,
1140
+ columns: c,
1141
+ rows: s,
1109
1142
  frameWidth: t,
1110
1143
  frameHeight: o,
1111
- sheetWidth: u * t,
1112
- sheetHeight: a * o
1144
+ sheetWidth: c * t,
1145
+ sheetHeight: s * o
1113
1146
  };
1114
1147
  }
1115
- function Ot(n, t) {
1148
+ function _t(n, t) {
1116
1149
  const o = n % t.columns, r = Math.floor(n / t.columns);
1117
1150
  return { index: n, col: o, row: r, x: o * t.frameWidth, y: r * t.frameHeight };
1118
1151
  }
1119
- function Ht(n, t) {
1152
+ function Yt(n, t) {
1120
1153
  const o = Math.max(1, Math.floor(n)), r = [];
1121
1154
  for (let i = 0; i < o; i++) r.push(i / o * t);
1122
1155
  return r;
1123
1156
  }
1124
- function Gt(n, t, o) {
1157
+ function Zt(n, t, o) {
1125
1158
  return {
1126
1159
  frameWidth: n.frameWidth,
1127
1160
  frameHeight: n.frameHeight,
@@ -1133,37 +1166,40 @@ function Gt(n, t, o) {
1133
1166
  };
1134
1167
  }
1135
1168
  export {
1136
- A as ByteWriter,
1169
+ S as ByteWriter,
1137
1170
  _ 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
1171
+ Z as MP4_WEBCODECS,
1172
+ yt as PaletteMatcher,
1173
+ Rt as SimpleGIFEncoder,
1174
+ Bt as WebPEncoder,
1175
+ gt as buildPalette,
1176
+ jt as captionCuesFromTimeline,
1177
+ zt as downloadGIF,
1178
+ Ht as downloadVideo,
1179
+ qt as downloadWebP,
1180
+ It as exportToCSS,
1181
+ Wt as exportToGIF,
1182
+ pt as exportToLottie,
1183
+ Ut as exportToLottieJSON,
1184
+ St as exportToMP4,
1185
+ Lt as exportToVideo,
1186
+ Dt as exportToWebP,
1187
+ Ot as exportVideo,
1188
+ Vt as extractFrames,
1189
+ _t as frameCell,
1190
+ q as getSupportedVideoCodecs,
1191
+ $t as getVideoExportFormats,
1192
+ Kt as isVideoExportSupported,
1193
+ A as isWebCodecsMP4Supported,
1194
+ kt as isWebPExportSupported,
1195
+ wt as lzwEncode,
1196
+ Tt as muxMP4,
1197
+ Mt as parseWebPBitstream,
1198
+ Pt as pickAVCCodec,
1199
+ Et as quantizeImage,
1200
+ Yt as spriteFrameTimes,
1201
+ Xt as spriteSheetLayout,
1202
+ Zt as spriteSheetMeta,
1203
+ Gt as toSRT,
1204
+ Nt as toWebVTT
1169
1205
  };