@algorisys/tinyfly 0.70.2 → 0.74.1
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.
- package/README.md +20 -8
- package/bin/tinyfly.mjs +95 -2
- package/lib/addons/adapters.js +31 -12
- package/lib/addons/characters.js +211 -0
- package/lib/addons/export.js +476 -440
- package/lib/browser/tinyfly.iife.js +4 -4
- package/lib/browser/tinyfly.js +1339 -1095
- package/lib/browser/tinyfly.umd.js +4 -4
- package/lib/engine/tinyfly-engine.js +313 -277
- package/lib/engine/tinyfly-engine.umd.cjs +2 -2
- package/lib/headless/headless.js +947 -0
- package/lib/types/adapters/canvas/canvas-adapter.d.ts +32 -2
- package/lib/types/browser/index.d.ts +3 -1
- package/lib/types/characters/index.d.ts +5 -0
- package/lib/types/characters/stick-figure.d.ts +174 -0
- package/lib/types/engine/authoring/index.d.ts +1 -0
- package/lib/types/engine/authoring/narration.d.ts +80 -0
- package/lib/types/engine/export/captions.d.ts +31 -0
- package/lib/types/engine/export/index.d.ts +1 -0
- package/lib/types/headless/ffmpeg-args.d.ts +28 -0
- package/lib/types/headless/frame-renderer.d.ts +45 -0
- package/lib/types/headless/index.d.ts +12 -0
- package/lib/types/headless/narration-audio.d.ts +13 -0
- package/lib/types/headless/node-audio.d.ts +46 -0
- package/lib/types/headless/node-video.d.ts +48 -0
- package/lib/types/headless/scene-captions.d.ts +4 -0
- package/lib/types/headless/video-scene.d.ts +57 -0
- package/package.json +19 -4
package/lib/addons/export.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { toKeyframedTracks as
|
|
2
|
-
const
|
|
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
|
|
15
|
-
if (
|
|
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" :
|
|
19
|
+
return typeof n != "string" ? "linear" : tt[n] ?? "linear";
|
|
20
20
|
}
|
|
21
|
-
const
|
|
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
|
-
},
|
|
37
|
-
function
|
|
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
|
|
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
|
|
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
|
|
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
|
|
60
|
-
|
|
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
|
|
64
|
-
return
|
|
63
|
+
function ct(n) {
|
|
64
|
+
return ot.has(n);
|
|
65
65
|
}
|
|
66
|
-
function
|
|
67
|
-
const i = { ...
|
|
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
|
-
|
|
70
|
-
for (const f of
|
|
71
|
-
const
|
|
72
|
-
for (const
|
|
73
|
-
const b =
|
|
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
|
|
76
|
-
if (
|
|
77
|
-
switch (
|
|
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
|
-
|
|
79
|
+
u.push(`translateX(${p})`);
|
|
80
80
|
break;
|
|
81
81
|
case "y":
|
|
82
|
-
|
|
82
|
+
u.push(`translateY(${p})`);
|
|
83
83
|
break;
|
|
84
84
|
case "rotate":
|
|
85
|
-
|
|
85
|
+
u.push(`rotate(${p})`);
|
|
86
86
|
break;
|
|
87
87
|
case "scale":
|
|
88
|
-
|
|
88
|
+
u.push(`scale(${b})`);
|
|
89
89
|
break;
|
|
90
90
|
case "scaleX":
|
|
91
|
-
|
|
91
|
+
u.push(`scaleX(${b})`);
|
|
92
92
|
break;
|
|
93
93
|
case "scaleY":
|
|
94
|
-
|
|
94
|
+
u.push(`scaleY(${b})`);
|
|
95
95
|
break;
|
|
96
96
|
}
|
|
97
97
|
else
|
|
98
|
-
|
|
98
|
+
a.push(`${g}:${e}${p}`);
|
|
99
99
|
}
|
|
100
|
-
|
|
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
|
|
102
|
+
return s.push("}"), s.join(h);
|
|
103
103
|
}
|
|
104
|
-
function
|
|
104
|
+
function ft(n) {
|
|
105
105
|
const t = /* @__PURE__ */ new Map();
|
|
106
106
|
for (const i of n)
|
|
107
|
-
for (const
|
|
108
|
-
const
|
|
109
|
-
t.set(
|
|
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,
|
|
113
|
-
|
|
112
|
+
for (const [i, c] of t)
|
|
113
|
+
c > o && (o = c, r = i);
|
|
114
114
|
return r;
|
|
115
115
|
}
|
|
116
|
-
function
|
|
117
|
-
const
|
|
118
|
-
return `animation:${
|
|
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
|
|
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:
|
|
126
|
-
} = t,
|
|
127
|
-
`, f =
|
|
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
|
-
},
|
|
131
|
-
for (const [
|
|
132
|
-
const
|
|
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 =
|
|
135
|
-
|
|
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 =
|
|
139
|
-
|
|
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:
|
|
144
|
-
keyframes:
|
|
145
|
-
selectors:
|
|
143
|
+
css: h.join(e + e),
|
|
144
|
+
keyframes: s,
|
|
145
|
+
selectors: l
|
|
146
146
|
};
|
|
147
147
|
}
|
|
148
|
-
function
|
|
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 (
|
|
154
|
-
const [r, i,
|
|
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: [
|
|
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
|
|
201
|
+
function D(n, t) {
|
|
202
202
|
return Math.round(n / 1e3 * t);
|
|
203
203
|
}
|
|
204
|
-
function
|
|
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
|
|
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
|
|
228
|
-
t:
|
|
229
|
-
s:
|
|
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 (
|
|
232
|
-
const f = typeof
|
|
231
|
+
if (s) {
|
|
232
|
+
const f = typeof s.value == "number" ? [s.value] : [0];
|
|
233
233
|
e.e = f;
|
|
234
|
-
const
|
|
235
|
-
e.i =
|
|
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
|
|
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
|
|
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
|
|
263
|
-
const
|
|
264
|
-
switch (
|
|
262
|
+
for (const c of n) {
|
|
263
|
+
const s = c.keyframes;
|
|
264
|
+
switch (c.property) {
|
|
265
265
|
case "opacity":
|
|
266
|
-
const
|
|
266
|
+
const l = s.map((e) => ({
|
|
267
267
|
...e,
|
|
268
268
|
value: e.value * 100
|
|
269
269
|
}));
|
|
270
|
-
o.o =
|
|
270
|
+
o.o = U(l, t);
|
|
271
271
|
break;
|
|
272
272
|
case "rotate":
|
|
273
273
|
case "rotation":
|
|
274
|
-
o.r =
|
|
274
|
+
o.r = U(s, t);
|
|
275
275
|
break;
|
|
276
276
|
case "scale":
|
|
277
|
-
const
|
|
277
|
+
const h = s.map((e) => ({
|
|
278
278
|
...e,
|
|
279
279
|
value: e.value * 100
|
|
280
280
|
}));
|
|
281
|
-
o.s =
|
|
281
|
+
o.s = U(h, t, !0);
|
|
282
282
|
break;
|
|
283
283
|
}
|
|
284
284
|
}
|
|
285
|
-
const r = n.find((
|
|
285
|
+
const r = n.find((c) => c.property === "x"), i = n.find((c) => c.property === "y");
|
|
286
286
|
if (r || i) {
|
|
287
|
-
const
|
|
288
|
-
|
|
289
|
-
const
|
|
290
|
-
if (
|
|
291
|
-
const e =
|
|
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 <
|
|
296
|
-
const
|
|
297
|
-
t:
|
|
298
|
-
s: [
|
|
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 (
|
|
301
|
-
const
|
|
302
|
-
b.e = [
|
|
303
|
-
const
|
|
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
|
|
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
|
|
317
|
-
if (
|
|
318
|
-
r =
|
|
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
|
|
327
|
-
const r =
|
|
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
|
|
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:
|
|
352
|
-
} = t,
|
|
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 [
|
|
355
|
-
const
|
|
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:
|
|
360
|
+
nm: d,
|
|
361
361
|
sr: 1,
|
|
362
|
-
ks:
|
|
362
|
+
ks: u,
|
|
363
363
|
ao: 0,
|
|
364
|
-
shapes:
|
|
364
|
+
shapes: bt(100, 100, b ?? "#4a9eff"),
|
|
365
365
|
ip: 0,
|
|
366
|
-
op:
|
|
366
|
+
op: l,
|
|
367
367
|
st: 0,
|
|
368
368
|
bm: 0
|
|
369
369
|
};
|
|
370
|
-
e.push(
|
|
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:
|
|
377
|
+
op: l,
|
|
378
378
|
w: i,
|
|
379
|
-
h:
|
|
379
|
+
h: c,
|
|
380
380
|
ddd: 0,
|
|
381
381
|
assets: [],
|
|
382
382
|
layers: e
|
|
383
383
|
};
|
|
384
384
|
}
|
|
385
|
-
function
|
|
386
|
-
return JSON.stringify(
|
|
385
|
+
function Ut(n, t = {}) {
|
|
386
|
+
return JSON.stringify(pt(n, t));
|
|
387
387
|
}
|
|
388
|
-
const
|
|
388
|
+
const F = 5, P = 1 << F * 3, R = 8 - F;
|
|
389
389
|
function X(n, t, o) {
|
|
390
|
-
return n >>
|
|
390
|
+
return n >> R << F * 2 | t >> R << F | o >> R;
|
|
391
391
|
}
|
|
392
|
-
function
|
|
393
|
-
const o = new Uint32Array(P), r = new Uint32Array(P), i = 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
|
|
397
|
-
o[
|
|
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
|
|
399
|
+
const s = [];
|
|
400
400
|
for (let f = 0; f < P; f++) {
|
|
401
|
-
const
|
|
402
|
-
|
|
403
|
-
r: Math.round(r[f] /
|
|
404
|
-
g: Math.round(i[f] /
|
|
405
|
-
b: Math.round(
|
|
406
|
-
count:
|
|
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 (
|
|
409
|
+
if (s.length === 0)
|
|
410
410
|
return { rgb: new Uint8Array(3), size: 1 };
|
|
411
|
-
if (
|
|
412
|
-
const f = new Uint8Array(
|
|
413
|
-
return
|
|
414
|
-
f[
|
|
415
|
-
}), { rgb: f, size:
|
|
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
|
|
418
|
-
let
|
|
419
|
-
for (let
|
|
420
|
-
const E =
|
|
421
|
-
|
|
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:
|
|
424
|
-
},
|
|
425
|
-
for (;
|
|
426
|
-
let f = -1,
|
|
427
|
-
for (let w = 0; w <
|
|
428
|
-
const B =
|
|
429
|
-
B.to <= B.from || B.count >
|
|
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
|
|
433
|
-
p.sort((w, B) => w[
|
|
434
|
-
for (let w = 0; w < p.length; w++) a
|
|
435
|
-
const x =
|
|
436
|
-
let
|
|
437
|
-
for (let 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
|
-
|
|
439
|
+
h[f] = l(a.from, E), h.push(l(E + 1, a.to));
|
|
440
440
|
}
|
|
441
|
-
const e = new Uint8Array(
|
|
442
|
-
return
|
|
443
|
-
let
|
|
444
|
-
for (let
|
|
445
|
-
const p =
|
|
446
|
-
|
|
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
|
-
|
|
449
|
-
}), { rgb: e, size:
|
|
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
|
|
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),
|
|
462
|
-
if (
|
|
463
|
-
const { rgb:
|
|
464
|
-
let
|
|
465
|
-
for (let
|
|
466
|
-
const
|
|
467
|
-
if (b <
|
|
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
|
|
480
|
-
const { dither:
|
|
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 (!
|
|
483
|
-
for (let
|
|
484
|
-
const
|
|
485
|
-
if (n[
|
|
486
|
-
|
|
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
|
-
|
|
489
|
+
h[a] = l.nearest(n[u], n[u + 1], n[u + 2]);
|
|
490
490
|
}
|
|
491
|
-
return { indices:
|
|
491
|
+
return { indices: h, hasTransparency: e };
|
|
492
492
|
}
|
|
493
493
|
const f = new Float32Array(t * o * 3);
|
|
494
|
-
for (let
|
|
495
|
-
f[
|
|
496
|
-
const
|
|
497
|
-
f[
|
|
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
|
|
500
|
-
for (let
|
|
501
|
-
const
|
|
502
|
-
if (n[
|
|
503
|
-
|
|
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[
|
|
507
|
-
|
|
508
|
-
const [
|
|
509
|
-
|
|
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:
|
|
511
|
+
return { indices: h, hasTransparency: e };
|
|
512
512
|
}
|
|
513
|
-
class
|
|
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
|
|
581
|
-
const o = 1 << t, r = o + 1, i = new
|
|
582
|
-
let
|
|
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
|
-
|
|
585
|
-
}, f = (b,
|
|
586
|
-
for (
|
|
587
|
-
|
|
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
|
|
590
|
-
const
|
|
591
|
-
|
|
589
|
+
let d = /* @__PURE__ */ new Map();
|
|
590
|
+
const a = () => {
|
|
591
|
+
d = /* @__PURE__ */ new Map();
|
|
592
592
|
};
|
|
593
|
-
let
|
|
594
|
-
if (f(o,
|
|
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
|
|
597
|
-
const p = n[
|
|
598
|
-
if (
|
|
599
|
-
b =
|
|
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,
|
|
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,
|
|
604
|
+
f(b, u);
|
|
605
605
|
}
|
|
606
|
-
return f(r,
|
|
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,
|
|
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
|
|
635
|
-
e.bytes([33, 249, 4]), e.byte(f << 2 | (
|
|
636
|
-
const
|
|
637
|
-
|
|
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
|
|
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
|
|
653
|
-
function
|
|
654
|
-
const { width: o, height: r, frameRate: i = 30, backgroundColor:
|
|
655
|
-
|
|
656
|
-
const
|
|
657
|
-
if (!
|
|
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,
|
|
660
|
-
for (let
|
|
661
|
-
const
|
|
662
|
-
|
|
663
|
-
const b = n.getStateAtTime(
|
|
664
|
-
|
|
665
|
-
time:
|
|
666
|
-
imageData:
|
|
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:
|
|
670
|
+
return { frames: a, duration: e, frameCount: a.length };
|
|
671
671
|
}
|
|
672
|
-
async function
|
|
672
|
+
async function Wt(n, t) {
|
|
673
673
|
const {
|
|
674
674
|
width: o,
|
|
675
675
|
height: r,
|
|
676
676
|
frameRate: i = 30,
|
|
677
|
-
loops:
|
|
678
|
-
backgroundColor:
|
|
679
|
-
renderFrame:
|
|
680
|
-
dither:
|
|
677
|
+
loops: c = 0,
|
|
678
|
+
backgroundColor: s,
|
|
679
|
+
renderFrame: l,
|
|
680
|
+
dither: h,
|
|
681
681
|
maxColors: e,
|
|
682
682
|
onProgress: f,
|
|
683
|
-
signal:
|
|
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 (!
|
|
687
|
+
if (!l)
|
|
688
688
|
throw new Error("renderFrame function is required for GIF export");
|
|
689
|
-
const
|
|
690
|
-
|
|
691
|
-
const
|
|
692
|
-
if (!
|
|
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
|
|
695
|
-
for (let
|
|
696
|
-
if (
|
|
697
|
-
const E = Math.min(
|
|
698
|
-
|
|
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
|
|
700
|
+
await l(u, w.values, E), m.addFrame(u.getImageData(0, 0, o, r), x), f?.((y + 1) / p);
|
|
701
701
|
}
|
|
702
|
-
return
|
|
702
|
+
return m.encode();
|
|
703
703
|
}
|
|
704
|
-
function
|
|
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
|
|
709
|
-
function
|
|
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
|
|
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
|
|
716
|
-
if (n.length < 12 ||
|
|
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,
|
|
719
|
-
for (;
|
|
720
|
-
const
|
|
721
|
-
if (
|
|
722
|
-
|
|
723
|
-
else if (
|
|
724
|
-
o = f,
|
|
725
|
-
else if (
|
|
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 (
|
|
728
|
-
const
|
|
729
|
-
r = (
|
|
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
|
-
|
|
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:
|
|
734
|
+
return { image: t, alpha: o, width: r, height: i, hasAlpha: c };
|
|
735
735
|
}
|
|
736
|
-
class
|
|
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 =
|
|
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
|
|
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(
|
|
766
|
-
const [r, i,
|
|
767
|
-
t.ascii("ANIM"), t.uint32LE(6), t.bytes([
|
|
768
|
-
for (const { bitstream:
|
|
769
|
-
const e = 16 +
|
|
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(
|
|
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
|
|
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
|
|
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((
|
|
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
|
|
802
|
+
async function Dt(n, t) {
|
|
803
803
|
const {
|
|
804
804
|
width: o,
|
|
805
805
|
height: r,
|
|
806
806
|
frameRate: i = 30,
|
|
807
|
-
loops:
|
|
808
|
-
quality:
|
|
809
|
-
backgroundColor:
|
|
810
|
-
renderFrame:
|
|
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 (!
|
|
816
|
+
if (!kt())
|
|
817
817
|
throw new Error("This browser cannot encode WebP from a canvas. Try Chrome, Edge, or Firefox.");
|
|
818
|
-
const
|
|
819
|
-
|
|
820
|
-
const
|
|
821
|
-
if (!
|
|
822
|
-
const
|
|
823
|
-
for (let p = 0; 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,
|
|
826
|
-
|
|
827
|
-
const
|
|
828
|
-
await
|
|
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
|
|
830
|
+
return u.encode();
|
|
831
831
|
}
|
|
832
|
-
function
|
|
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
|
|
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
|
|
847
|
-
const { width: o, height: r, timescale: i, avcC:
|
|
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
|
|
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
|
|
857
|
-
for (const
|
|
858
|
-
const
|
|
859
|
-
if (
|
|
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,
|
|
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(
|
|
864
|
-
for (const
|
|
865
|
-
for (let
|
|
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(
|
|
870
|
-
for (const
|
|
871
|
-
e.uint32BE(
|
|
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(
|
|
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(
|
|
891
|
+
e.bytes(c);
|
|
892
892
|
});
|
|
893
893
|
});
|
|
894
894
|
});
|
|
895
|
-
const
|
|
895
|
+
const u = [];
|
|
896
896
|
for (const b of n) {
|
|
897
|
-
const
|
|
898
|
-
|
|
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(
|
|
902
|
-
for (const b of
|
|
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
|
|
906
|
-
n.forEach((b,
|
|
907
|
-
b.isKeyFrame &&
|
|
908
|
-
}),
|
|
909
|
-
e.uint32BE(
|
|
910
|
-
for (const b of
|
|
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(
|
|
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
|
|
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
|
|
935
|
+
function A() {
|
|
936
936
|
return typeof VideoEncoder < "u" && typeof VideoFrame < "u";
|
|
937
937
|
}
|
|
938
|
-
async function
|
|
939
|
-
if (!
|
|
940
|
-
for (const i of
|
|
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
|
|
955
|
-
const { durationMs: t, renderFrame: o, onProgress: r, signal: i } = n,
|
|
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 (!
|
|
958
|
+
if (!A())
|
|
959
959
|
throw new Error("This browser has no WebCodecs VideoEncoder");
|
|
960
|
-
const
|
|
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 =
|
|
965
|
-
const
|
|
966
|
-
if (!
|
|
967
|
-
const
|
|
968
|
-
let
|
|
969
|
-
const b =
|
|
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 && !
|
|
973
|
-
const
|
|
974
|
-
M.copyTo(
|
|
975
|
-
data:
|
|
976
|
-
duration:
|
|
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
|
-
|
|
981
|
+
m = M instanceof Error ? M : new Error(String(M));
|
|
982
982
|
}
|
|
983
983
|
});
|
|
984
984
|
p.configure({
|
|
985
985
|
codec: e,
|
|
986
|
-
width:
|
|
987
|
-
height:
|
|
988
|
-
framerate:
|
|
989
|
-
bitrate:
|
|
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 /
|
|
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 <
|
|
998
|
+
for (let M = 0; M < y; M++) {
|
|
999
999
|
if (i?.aborted) throw new Error("Export aborted");
|
|
1000
|
-
if (
|
|
1001
|
-
const C = Math.min(t, M * (1e3 /
|
|
1002
|
-
|
|
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((
|
|
1009
|
-
r?.((M + 1) /
|
|
1008
|
+
if (await new Promise(($) => setTimeout($, 0)), m) throw m;
|
|
1009
|
+
r?.((M + 1) / y);
|
|
1010
1010
|
}
|
|
1011
|
-
if (await p.flush(),
|
|
1011
|
+
if (await p.flush(), m) throw m;
|
|
1012
1012
|
} finally {
|
|
1013
1013
|
p.state !== "closed" && p.close();
|
|
1014
1014
|
}
|
|
1015
|
-
if (!
|
|
1015
|
+
if (!u)
|
|
1016
1016
|
throw new Error("Encoder produced no H.264 decoder configuration");
|
|
1017
|
-
const B =
|
|
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
|
|
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
|
|
1028
|
-
return typeof MediaRecorder > "u" || typeof MediaRecorder.isTypeSupported != "function" ? [] :
|
|
1027
|
+
function q() {
|
|
1028
|
+
return typeof MediaRecorder > "u" || typeof MediaRecorder.isTypeSupported != "function" ? [] : At.filter((n) => MediaRecorder.isTypeSupported(n.mimeType));
|
|
1029
1029
|
}
|
|
1030
|
-
function
|
|
1031
|
-
return typeof document > "u" ? !1 :
|
|
1030
|
+
function Kt() {
|
|
1031
|
+
return typeof document > "u" ? !1 : A() || q().length > 0;
|
|
1032
1032
|
}
|
|
1033
|
-
const
|
|
1034
|
-
function
|
|
1033
|
+
const Z = "mp4-webcodecs";
|
|
1034
|
+
function $t() {
|
|
1035
1035
|
const n = [];
|
|
1036
|
-
|
|
1037
|
-
id:
|
|
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
|
|
1043
|
-
t.extension === "mp4" &&
|
|
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
|
|
1052
|
-
const { width: t, height: o, durationMs: r, renderFrame: i } = n,
|
|
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
|
|
1056
|
-
if (!
|
|
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
|
|
1059
|
-
|
|
1060
|
-
const e =
|
|
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 =
|
|
1063
|
-
|
|
1064
|
-
|
|
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((
|
|
1067
|
-
|
|
1066
|
+
const b = new Promise((y, E) => {
|
|
1067
|
+
u.onstop = () => y(), u.onerror = () => E(new Error("Recording failed"));
|
|
1068
1068
|
});
|
|
1069
|
-
|
|
1070
|
-
const
|
|
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
|
|
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,
|
|
1075
|
-
e.clearRect(0, 0, t, o), x && (e.fillStyle = x, e.fillRect(0, 0, t, o)), await i(e, E),
|
|
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
|
-
|
|
1078
|
+
u.state !== "inactive" && u.stop(), f.getTracks().forEach((y) => y.stop());
|
|
1079
1079
|
}
|
|
1080
|
-
return await b, new Blob(
|
|
1080
|
+
return await b, new Blob(m, { type: l });
|
|
1081
1081
|
}
|
|
1082
|
-
async function
|
|
1083
|
-
const t =
|
|
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 ===
|
|
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
|
|
1097
|
+
}), extension: o.extension } : { blob: await Lt({ ...n, mimeType: o.id }), extension: o.extension };
|
|
1098
1098
|
}
|
|
1099
|
-
function
|
|
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
|
|
1104
|
-
const
|
|
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:
|
|
1108
|
-
rows:
|
|
1140
|
+
columns: c,
|
|
1141
|
+
rows: s,
|
|
1109
1142
|
frameWidth: t,
|
|
1110
1143
|
frameHeight: o,
|
|
1111
|
-
sheetWidth:
|
|
1112
|
-
sheetHeight:
|
|
1144
|
+
sheetWidth: c * t,
|
|
1145
|
+
sheetHeight: s * o
|
|
1113
1146
|
};
|
|
1114
1147
|
}
|
|
1115
|
-
function
|
|
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
|
|
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
|
|
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
|
-
|
|
1169
|
+
S as ByteWriter,
|
|
1137
1170
|
_ as GIFEncoder,
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
Dt as
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
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
|
};
|