@video-editor/renderer 0.0.1-beta.22 → 0.0.1-beta.24

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/dist/index.js CHANGED
@@ -3,149 +3,152 @@ import { toRaw as De, isRef as Ne, shallowRef as se, unref as de, ref as ue, com
3
3
  import { renderTxt2ImgBitmap as Be, MP4Clip as z, Combinator as pe, OffscreenSprite as he } from "@webav/av-cliper";
4
4
  import { file as _e } from "opfs-tools";
5
5
  import { Application as we, Sprite as F, Texture as A, Graphics as me, Container as We } from "pixi.js";
6
- async function Ye(t) {
6
+ async function Ye(e) {
7
7
  const o = new we();
8
- return await o.init({ resizeTo: window, backgroundAlpha: 0, ...t }), o;
8
+ return await o.init({ resizeTo: window, backgroundAlpha: 0, ...e }), o;
9
9
  }
10
- function je(t, o, a, i, c) {
11
- const u = o || i, p = a || c;
12
- if (!u || !p)
10
+ function je(e, o, a, i, c) {
11
+ const u = o || i, f = a || c;
12
+ if (!u || !f)
13
13
  return { width: i, height: c };
14
- const s = u / p, y = i / c;
15
- switch (t) {
14
+ const s = u / f, m = i / c;
15
+ switch (e) {
16
16
  case "none":
17
- return { width: u, height: p };
17
+ return { width: u, height: f };
18
18
  case "cover":
19
- return s > y ? { width: c * s, height: c } : { width: i, height: i / s };
19
+ return s > m ? { width: c * s, height: c } : { width: i, height: i / s };
20
20
  case "stretch":
21
21
  return { width: i, height: c };
22
22
  default:
23
- return s > y ? { width: i, height: i / s } : { width: c * s, height: c };
23
+ return s > m ? { width: i, height: i / s } : { width: c * s, height: c };
24
24
  }
25
25
  }
26
- function Ke(t, o, a, i, c) {
27
- const u = "fillMode" in t ? t.fillMode : void 0, { width: p, height: s } = je(
26
+ function Ke(e, o, a, i, c) {
27
+ const u = "fillMode" in e ? e.fillMode : void 0, { width: f, height: s } = je(
28
28
  u,
29
29
  i,
30
30
  c,
31
31
  o,
32
32
  a
33
- ), y = "transform" in t ? t.transform : void 0, [E, S] = y?.position ?? [0, 0], [k, C] = y?.scale ?? [1, 1], g = y?.rotation?.[2] ?? 0, w = p * k, v = s * C, m = o / 2 + E * o / 2, R = a / 2 - S * a / 2;
33
+ ), m = "transform" in e ? e.transform : void 0, [M, g] = m?.position ?? [0, 0], [E, I] = m?.scale ?? [1, 1], S = m?.rotation?.[2] ?? 0, w = f * E, v = s * I, y = o / 2 + M * o / 2, C = a / 2 - g * a / 2;
34
34
  return {
35
35
  width: w,
36
36
  height: v,
37
- centerX: m,
38
- centerY: R,
39
- rotationRad: g / 180 * Math.PI
37
+ centerX: y,
38
+ centerY: C,
39
+ rotationRad: S / 180 * Math.PI
40
40
  };
41
41
  }
42
- function Xe(t) {
42
+ function Xe(e) {
43
43
  const o = /* @__PURE__ */ new Set();
44
- for (const a of t.tracks)
44
+ for (const a of e.tracks)
45
45
  for (const i of a.children)
46
46
  i.url && o.add(i.url);
47
47
  return o;
48
48
  }
49
- function Ge(t, o) {
49
+ function Ge(e, o) {
50
50
  const a = [];
51
- return t.tracks.forEach((i, c) => {
52
- i.children.forEach((u, p) => {
53
- u.startTime <= o && o < u.endTime && a.push({ segment: u, trackIndex: c, childIndex: p });
51
+ return e.tracks.forEach((i, c) => {
52
+ i.children.forEach((u, f) => {
53
+ u.startTime <= o && o < u.endTime && a.push({ segment: u, trackIndex: c, childIndex: f });
54
54
  });
55
- }), a.sort((i, c) => i.trackIndex === c.trackIndex ? i.childIndex - c.childIndex : i.trackIndex - c.trackIndex);
55
+ }), a.sort((i, c) => {
56
+ const u = e.tracks[i.trackIndex], f = e.tracks[c.trackIndex], s = u?.trackType === "frames" && u.isMain, m = f?.trackType === "frames" && f.isMain, M = e.tracks.length, g = s ? 0 : M - i.trackIndex, E = m ? 0 : M - c.trackIndex;
57
+ return g !== E ? g - E : i.trackIndex === c.trackIndex ? i.childIndex - c.childIndex : i.trackIndex - c.trackIndex;
58
+ });
56
59
  }
57
- function Je(t, o, a, i) {
58
- const c = Qe(o), u = t instanceof F && t.texture.width || a, p = t instanceof F && t.texture.height || i, s = Ke(o, a, i, u, p);
59
- t instanceof F ? (t.anchor.set(0.5), t.width = s.width, t.height = s.height, t.position.set(s.centerX, s.centerY), t.rotation = s.rotationRad, t.texture.source?.addEventListener?.("error", () => {
60
- t.texture = A.from(He(a, i));
61
- }, { once: !0 })) : t instanceof me && (t.clear(), t.rect(0, 0, s.width, s.height).fill({ color: ye("url" in o && typeof o.url == "string" ? o.url : o.segmentType), alpha: ve(o) ? c : 0.35 }), t.pivot.set(s.width / 2, s.height / 2), t.position.set(s.centerX, s.centerY), t.rotation = s.rotationRad), t.alpha = c;
60
+ function Je(e, o, a, i) {
61
+ const c = Qe(o), u = e instanceof F && e.texture.width || a, f = e instanceof F && e.texture.height || i, s = Ke(o, a, i, u, f);
62
+ e instanceof F ? (e.anchor.set(0.5), e.width = s.width, e.height = s.height, e.position.set(s.centerX, s.centerY), e.rotation = s.rotationRad, e.texture.source?.addEventListener?.("error", () => {
63
+ e.texture = A.from(He(a, i));
64
+ }, { once: !0 })) : e instanceof me && (e.clear(), e.rect(0, 0, s.width, s.height).fill({ color: ye("url" in o && typeof o.url == "string" ? o.url : o.segmentType), alpha: ve(o) ? c : 0.35 }), e.pivot.set(s.width / 2, s.height / 2), e.position.set(s.centerX, s.centerY), e.rotation = s.rotationRad), e.alpha = c;
62
65
  }
63
- function j(t, o) {
66
+ function j(e, o) {
64
67
  const a = new me();
65
- return a.rect(0, 0, 10, 10).fill({ color: ye(o ?? t), alpha: 1 }), a;
68
+ return a.rect(0, 0, 10, 10).fill({ color: ye(o ?? e), alpha: 1 }), a;
66
69
  }
67
- function He(t, o, a) {
68
- const i = `<svg xmlns="http://www.w3.org/2000/svg" width="${t}" height="${o}"><rect width="100%" height="100%" fill="#0f172a" fill-opacity="0.8"/></svg>`;
70
+ function He(e, o, a) {
71
+ const i = `<svg xmlns="http://www.w3.org/2000/svg" width="${e}" height="${o}"><rect width="100%" height="100%" fill="#0f172a" fill-opacity="0.8"/></svg>`;
69
72
  return `data:image/svg+xml;base64,${btoa(i)}`;
70
73
  }
71
- function ye(t) {
74
+ function ye(e) {
72
75
  let o = 0;
73
- for (let a = 0; a < t.length; a++)
74
- o = t.charCodeAt(a) + ((o << 5) - o);
76
+ for (let a = 0; a < e.length; a++)
77
+ o = e.charCodeAt(a) + ((o << 5) - o);
75
78
  return o & 16777215;
76
79
  }
77
- function X(t) {
78
- const o = t.tracks.flatMap((a) => a.children.map((i) => i.endTime));
80
+ function X(e) {
81
+ const o = e.tracks.flatMap((a) => a.children.map((i) => i.endTime));
79
82
  return o.length ? Math.max(...o) : 0;
80
83
  }
81
- function K(t, o, a) {
82
- return Math.min(Math.max(t, o), a);
84
+ function K(e, o, a) {
85
+ return Math.min(Math.max(e, o), a);
83
86
  }
84
- function le(t) {
85
- const o = De(t);
87
+ function fe(e) {
88
+ const o = De(e);
86
89
  return JSON.parse(JSON.stringify(o));
87
90
  }
88
- function ve(t) {
89
- return "opacity" in t;
91
+ function ve(e) {
92
+ return "opacity" in e;
90
93
  }
91
- function Qe(t) {
92
- return ve(t) && typeof t.opacity == "number" ? t.opacity : 1;
94
+ function Qe(e) {
95
+ return ve(e) && typeof e.opacity == "number" ? e.opacity : 1;
93
96
  }
94
97
  const Ze = 100, O = /* @__PURE__ */ new Map();
95
98
  let et = Ze;
96
- function tt(t, o) {
97
- O.delete(t), O.set(t, o);
99
+ function tt(e, o) {
100
+ O.delete(e), O.set(e, o);
98
101
  }
99
102
  function rt() {
100
103
  for (; O.size > et; ) {
101
- const [t, o] = O.entries().next().value;
102
- O.delete(t), o.close?.();
104
+ const [e, o] = O.entries().next().value;
105
+ O.delete(e), o.close?.();
103
106
  }
104
107
  }
105
- function nt(t) {
106
- return t.map((o) => o.content).filter(Boolean).join(`
108
+ function nt(e) {
109
+ return e.map((o) => o.content).filter(Boolean).join(`
107
110
  `);
108
111
  }
109
- function ot(t) {
110
- const o = Array.isArray(t.fontFamily) ? t.fontFamily.join(", ") : t.fontFamily, a = t.fontSize ?? 32, i = t.fontWeight ?? "normal", c = t.fontStyle ?? "normal", u = t.fill ?? "#ffffff", p = t.align ?? "left", s = [
112
+ function ot(e) {
113
+ const o = Array.isArray(e.fontFamily) ? e.fontFamily.join(", ") : e.fontFamily, a = e.fontSize ?? 32, i = e.fontWeight ?? "normal", c = e.fontStyle ?? "normal", u = e.fill ?? "#ffffff", f = e.align ?? "left", s = [
111
114
  `font-size: ${a}px`,
112
115
  `font-weight: ${i}`,
113
116
  `font-style: ${c}`,
114
117
  `color: ${u}`,
115
- `text-align: ${p}`,
118
+ `text-align: ${f}`,
116
119
  "white-space: pre-wrap"
117
120
  ];
118
- if (o && s.push(`font-family: ${o}`), typeof t.letterSpacing == "number" && s.push(`letter-spacing: ${t.letterSpacing}px`), typeof t.leading == "number" && s.push(`line-height: ${t.leading}px`), t.background?.color && s.push(`background: ${t.background.color}`), t.stroke?.color && typeof t.stroke.width == "number" && s.push(`-webkit-text-stroke: ${t.stroke.width}px ${t.stroke.color}`), t.underline && s.push("text-decoration: underline"), t.dropShadow?.color && typeof t.dropShadow.distance == "number") {
119
- const y = (t.dropShadow.angle ?? 45) * (Math.PI / 180), E = Math.cos(y) * t.dropShadow.distance, S = Math.sin(y) * t.dropShadow.distance, k = t.dropShadow.blur ?? 0;
120
- s.push(`text-shadow: ${E}px ${S}px ${k}px ${t.dropShadow.color}`);
121
+ if (o && s.push(`font-family: ${o}`), typeof e.letterSpacing == "number" && s.push(`letter-spacing: ${e.letterSpacing}px`), typeof e.leading == "number" && s.push(`line-height: ${e.leading}px`), e.background?.color && s.push(`background: ${e.background.color}`), e.stroke?.color && typeof e.stroke.width == "number" && s.push(`-webkit-text-stroke: ${e.stroke.width}px ${e.stroke.color}`), e.underline && s.push("text-decoration: underline"), e.dropShadow?.color && typeof e.dropShadow.distance == "number") {
122
+ const m = (e.dropShadow.angle ?? 45) * (Math.PI / 180), M = Math.cos(m) * e.dropShadow.distance, g = Math.sin(m) * e.dropShadow.distance, E = e.dropShadow.blur ?? 0;
123
+ s.push(`text-shadow: ${M}px ${g}px ${E}px ${e.dropShadow.color}`);
121
124
  }
122
125
  return s.join("; ");
123
126
  }
124
- async function it(t, o) {
125
- const a = `${o}::${t}`, i = O.get(a);
127
+ async function it(e, o) {
128
+ const a = `${o}::${e}`, i = O.get(a);
126
129
  if (i)
127
130
  return tt(a, i), i;
128
- const c = await Be(t, o);
131
+ const c = await Be(e, o);
129
132
  return O.set(a, c), rt(), c;
130
133
  }
131
134
  const at = "/video-editor-res";
132
- async function ct(t) {
133
- const o = ze(), a = Ne(t.protocol) ? t.protocol : se(t.protocol), i = se(
134
- o.verify(le(de(a)))
135
- ), c = t.app ?? await Ye(t.appOptions), u = new We();
135
+ async function ct(e) {
136
+ const o = ze(), a = Ne(e.protocol) ? e.protocol : se(e.protocol), i = se(
137
+ o.verify(fe(de(a)))
138
+ ), c = e.app ?? await Ye(e.appOptions), u = new We();
136
139
  c.stage.addChild(u);
137
- const p = Ue({ dir: t.resourceDir }), s = /* @__PURE__ */ new Set(), y = /* @__PURE__ */ new Map(), E = /* @__PURE__ */ new Map(), S = /* @__PURE__ */ new Set(), k = /* @__PURE__ */ new Set(), C = t.videoSourceMode ?? "auto", g = /* @__PURE__ */ new Map(), w = ue(0), v = ue(!1), m = qe(() => X(i.value));
138
- let R, P = 0, b = 0;
139
- async function I(e) {
140
- const n = b, { protocol: r, at: d, layer: l } = e, f = Pe(r, d), h = Ge(r, f), M = e.app.renderer.width, x = e.app.renderer.height, $ = [];
140
+ const f = Ue({ dir: e.resourceDir }), s = /* @__PURE__ */ new Set(), m = /* @__PURE__ */ new Map(), M = /* @__PURE__ */ new Map(), g = /* @__PURE__ */ new Set(), E = /* @__PURE__ */ new Set(), I = e.videoSourceMode ?? "auto", S = /* @__PURE__ */ new Map(), w = ue(0), v = ue(!1), y = qe(() => X(i.value));
141
+ let C, P = 0, b = 0;
142
+ async function R(t) {
143
+ const n = b, { protocol: r, at: d, layer: l } = t, p = Pe(r, d), h = Ge(r, p), T = t.app.renderer.width, k = t.app.renderer.height, $ = [];
141
144
  for (const { segment: V } of h) {
142
145
  if (n !== b)
143
146
  return;
144
- const N = await e.getDisplay(V);
147
+ const N = await t.getDisplay(V);
145
148
  if (n !== b)
146
149
  return;
147
150
  if (N && !N.destroyed) {
148
- if (Je(N, V, M, x), Ie(V) && await re(V, f), n !== b)
151
+ if (Je(N, V, T, k), Re(V) && await re(V, p), n !== b)
149
152
  return;
150
153
  $.push(N);
151
154
  }
@@ -154,9 +157,9 @@ async function ct(t) {
154
157
  return;
155
158
  l.removeChildren();
156
159
  const D = $.filter(Boolean);
157
- D.length && l.addChild(...D), n === b && e.app.render();
160
+ D.length && l.addChild(...D), n === b && t.app.render();
158
161
  }
159
- const T = st(() => I({
162
+ const x = st(() => R({
160
163
  app: c,
161
164
  layer: u,
162
165
  protocol: i.value,
@@ -166,171 +169,171 @@ async function ct(t) {
166
169
  J.run(() => {
167
170
  Y(
168
171
  () => de(a),
169
- (e) => {
172
+ (t) => {
170
173
  try {
171
- i.value = o.verify(le(e));
174
+ i.value = o.verify(fe(t));
172
175
  } catch (n) {
173
176
  console.error("[renderer] invalid protocol update", n);
174
177
  return;
175
178
  }
176
- b += 1, H(), t.warmUpResources !== !1 && ge(i.value), Se(i.value), q(), t.manualRender || T();
179
+ b += 1, H(), e.warmUpResources !== !1 && ge(i.value), Se(i.value), q(), e.manualRender || x();
177
180
  },
178
181
  { deep: !0, immediate: !0 }
179
- ), t.manualRender || Y(w, () => {
180
- q(), T();
181
- }), Y(m, () => q());
182
+ ), e.manualRender || Y(w, () => {
183
+ q(), x();
184
+ }), Y(y, () => q());
182
185
  });
183
186
  function q() {
184
- const e = m.value;
185
- e <= 0 ? w.value = 0 : w.value > e ? w.value = e : w.value < 0 && (w.value = 0);
187
+ const t = y.value;
188
+ t <= 0 ? w.value = 0 : w.value > t ? w.value = t : w.value < 0 && (w.value = 0);
186
189
  }
187
- function ge(e) {
188
- for (const n of Xe(e))
189
- s.has(n) || (s.add(n), ie(n) !== "video" && B(n) && p.add(n).catch(() => {
190
+ function ge(t) {
191
+ for (const n of Xe(t))
192
+ s.has(n) || (s.add(n), ie(n) !== "video" && B(n) && f.add(n).catch(() => {
190
193
  }));
191
194
  }
192
- function Se(e) {
193
- const n = new Set(e.tracks.flatMap((r) => r.children.map((d) => d.id)));
194
- for (const [r, d] of y)
195
- n.has(r) || (d.destroy(), y.delete(r));
196
- for (const [r, d] of g)
197
- n.has(r) || (ne(d), g.delete(r));
195
+ function Se(t) {
196
+ const n = new Set(t.tracks.flatMap((r) => r.children.map((d) => d.id)));
197
+ for (const [r, d] of m)
198
+ n.has(r) || (d.destroy(), m.delete(r));
199
+ for (const [r, d] of S)
200
+ n.has(r) || (ne(d), S.delete(r));
198
201
  }
199
202
  function H() {
200
203
  u.removeChildren();
201
- for (const e of y.values())
202
- e.destroy();
203
- y.clear(), E.clear();
204
- for (const e of g.values())
205
- ne(e);
206
- g.clear();
204
+ for (const t of m.values())
205
+ t.destroy();
206
+ m.clear(), M.clear();
207
+ for (const t of S.values())
208
+ ne(t);
209
+ S.clear();
207
210
  }
208
211
  function Q() {
209
- v.value || (v.value = !0, P = performance.now(), R = requestAnimationFrame(Z));
212
+ v.value || (v.value = !0, P = performance.now(), C = requestAnimationFrame(Z));
210
213
  }
211
214
  function L() {
212
- v.value = !1, R !== void 0 && cancelAnimationFrame(R), R = void 0, t.freezeOnPause !== !1 && Fe();
215
+ v.value = !1, C !== void 0 && cancelAnimationFrame(C), C = void 0, e.freezeOnPause !== !1 && Fe();
213
216
  }
214
217
  function Z() {
215
- ee(), v.value && (R = requestAnimationFrame(Z));
218
+ ee(), v.value && (C = requestAnimationFrame(Z));
216
219
  }
217
- function ee(e) {
218
- if (!v.value && e === void 0)
220
+ function ee(t) {
221
+ if (!v.value && t === void 0)
219
222
  return;
220
- const n = performance.now(), r = e ?? (P ? n - P : 0);
223
+ const n = performance.now(), r = t ?? (P ? n - P : 0);
221
224
  P = n, r !== 0 && (w.value = K(
222
225
  w.value + r,
223
226
  0,
224
- m.value || Number.POSITIVE_INFINITY
225
- ), m.value > 0 && w.value >= m.value && L());
227
+ y.value || Number.POSITIVE_INFINITY
228
+ ), y.value > 0 && w.value >= y.value && L());
226
229
  }
227
- function be(e) {
228
- w.value = K(e, 0, m.value || Number.POSITIVE_INFINITY);
230
+ function Me(t) {
231
+ w.value = K(t, 0, y.value || Number.POSITIVE_INFINITY);
229
232
  }
230
- async function Me(e) {
231
- w.value = K(e, 0, m.value || Number.POSITIVE_INFINITY), await T();
233
+ async function be(t) {
234
+ w.value = K(t, 0, y.value || Number.POSITIVE_INFINITY), await x();
232
235
  }
233
- async function Te(e) {
234
- const n = y.get(e.id);
236
+ async function Te(t) {
237
+ const n = m.get(t.id);
235
238
  if (n)
236
239
  return n;
237
- const r = E.get(e.id);
240
+ const r = M.get(t.id);
238
241
  if (r)
239
242
  return r;
240
- const d = xe(e);
241
- E.set(e.id, d);
243
+ const d = xe(t);
244
+ M.set(t.id, d);
242
245
  const l = await d;
243
- return l && y.set(e.id, l), E.delete(e.id), l;
244
- }
245
- async function xe(e) {
246
- if (e.segmentType === "frames" || e.segmentType === "sticker") {
247
- if (!e.url)
248
- return j(e.segmentType);
249
- if ("type" in e && e.type === "video" && ae(e.url)) {
250
- const r = await Ce(e);
251
- return r || j(e.segmentType, e.url);
246
+ return l && m.set(t.id, l), M.delete(t.id), l;
247
+ }
248
+ async function xe(t) {
249
+ if (t.segmentType === "frames" || t.segmentType === "sticker") {
250
+ if (!t.url)
251
+ return j(t.segmentType);
252
+ if ("type" in t && t.type === "video" && ae(t.url)) {
253
+ const r = await Ie(t);
254
+ return r || j(t.segmentType, t.url);
252
255
  }
253
- const n = await ke(e.url);
254
- return n ? new F(n) : j(e.segmentType, e.url);
256
+ const n = await Ee(t.url);
257
+ return n ? new F(n) : j(t.segmentType, t.url);
255
258
  }
256
- if (e.segmentType === "text")
257
- return await Ee(e);
258
- e.segmentType === "effect" || e.segmentType;
259
+ if (t.segmentType === "text")
260
+ return await ke(t);
261
+ t.segmentType === "effect" || t.segmentType;
259
262
  }
260
- async function Ee(e) {
261
- const n = nt(e.texts);
263
+ async function ke(t) {
264
+ const n = nt(t.texts);
262
265
  if (!n)
263
266
  return;
264
- const [r] = e.texts;
267
+ const [r] = t.texts;
265
268
  if (!r)
266
269
  return;
267
270
  const d = await it(n, ot(r)), l = A.from(d);
268
271
  return new F(l);
269
272
  }
270
- async function ke(e) {
271
- const n = e.startsWith("data:"), r = /^https?:\/\//.test(e);
273
+ async function Ee(t) {
274
+ const n = t.startsWith("data:"), r = /^https?:\/\//.test(t);
272
275
  if (!n && !r)
273
276
  try {
274
- await p.add(e);
275
- const d = await p.get(e);
277
+ await f.add(t);
278
+ const d = await f.get(t);
276
279
  if (d instanceof HTMLImageElement)
277
280
  return A.from(d);
278
281
  } catch {
279
282
  }
280
- return await Ve(e);
283
+ return await Ve(t);
281
284
  }
282
- async function Ce(e) {
283
- const n = g.get(e.id);
285
+ async function Ie(t) {
286
+ const n = S.get(t.id);
284
287
  if (n)
285
288
  return n.sprite;
286
- const r = W(e.url), d = C !== "element", l = C !== "mp4clip";
287
- if (r && S.has(r)) {
289
+ const r = W(t.url), d = I !== "element", l = I !== "mp4clip";
290
+ if (r && g.has(r)) {
288
291
  if (!l)
289
- throw new Error(`[renderer] MP4Clip unsupported for ${e.url}`);
290
- const f = await U(e.url).catch((h) => {
291
- console.warn("[renderer] failed to load video via <video>", e.url, h);
292
+ throw new Error(`[renderer] MP4Clip unsupported for ${t.url}`);
293
+ const p = await U(t.url).catch((h) => {
294
+ console.warn("[renderer] failed to load video via <video>", t.url, h);
292
295
  });
293
- return f ? (g.set(e.id, f), f.sprite) : void 0;
296
+ return p ? (S.set(t.id, p), p.sprite) : void 0;
294
297
  }
295
298
  if (d) {
296
- const f = await oe(e.url).catch((h) => {
297
- if (r && te(h) && S.add(r), (!r || !k.has(r)) && (r && k.add(r), console.warn("[renderer] failed to load video via MP4Clip", e.url, h)), !l)
299
+ const p = await oe(t.url).catch((h) => {
300
+ if (r && te(h) && g.add(r), (!r || !E.has(r)) && (r && E.add(r), console.warn("[renderer] failed to load video via MP4Clip", t.url, h)), !l)
298
301
  throw h;
299
302
  });
300
- if (f)
301
- return g.set(e.id, f), f.sprite;
303
+ if (p)
304
+ return S.set(t.id, p), p.sprite;
302
305
  }
303
306
  if (l) {
304
- const f = await U(e.url).catch((h) => {
305
- console.warn("[renderer] failed to load video via <video>", e.url, h);
307
+ const p = await U(t.url).catch((h) => {
308
+ console.warn("[renderer] failed to load video via <video>", t.url, h);
306
309
  });
307
- if (f)
308
- return g.set(e.id, f), f.sprite;
310
+ if (p)
311
+ return S.set(t.id, p), p.sprite;
309
312
  }
310
313
  }
311
- function te(e) {
312
- if (!(e instanceof Error))
314
+ function te(t) {
315
+ if (!(t instanceof Error))
313
316
  return !1;
314
- const n = e.message || "";
317
+ const n = t.message || "";
315
318
  return n.includes("stream is done") || n.includes("not emit ready");
316
319
  }
317
- async function re(e, n) {
318
- const r = g.get(e.id);
320
+ async function re(t, n) {
321
+ const r = S.get(t.id);
319
322
  if (r)
320
323
  try {
321
- const d = e.fromTime ?? 0, l = Math.max(0, n - e.startTime + d), f = Math.floor(l * 1e3);
324
+ const d = t.fromTime ?? 0, l = Math.max(0, n - t.startTime + d), p = Math.floor(l * 1e3);
322
325
  if (r.kind === "frozen") {
323
- const M = W(e.url);
324
- if (!M)
326
+ const T = W(t.url);
327
+ if (!T)
325
328
  return;
326
- const x = await Re(e.url, M, { sprite: r.sprite, oldTexture: r.texture });
327
- return x ? (g.set(e.id, x), await re(e, n)) : void 0;
329
+ const k = await Ce(t.url, T, { sprite: r.sprite, oldTexture: r.texture });
330
+ return k ? (S.set(t.id, k), await re(t, n)) : void 0;
328
331
  }
329
332
  if (r.kind === "mp4clip") {
330
- const M = await r.clip.tick(f);
331
- if (M.video) {
332
- const x = r.canvas.getContext("2d");
333
- x && (x.drawImage(M.video, 0, 0, r.canvas.width, r.canvas.height), ce(r.texture)), M.video.close();
333
+ const T = await r.clip.tick(p);
334
+ if (T.video) {
335
+ const k = r.canvas.getContext("2d");
336
+ k && (k.drawImage(T.video, 0, 0, r.canvas.width, r.canvas.height), ce(r.texture)), T.video.close();
334
337
  }
335
338
  return;
336
339
  }
@@ -339,48 +342,48 @@ async function ct(t) {
339
342
  return;
340
343
  await Oe(r, {
341
344
  targetSec: h,
342
- playbackRate: e.playRate ?? 1
345
+ playbackRate: t.playRate ?? 1
343
346
  });
344
347
  } catch (d) {
345
348
  console.warn("[renderer] update video frame failed", d);
346
349
  }
347
350
  }
348
- async function Re(e, n, r) {
349
- const d = C !== "element", l = C !== "mp4clip";
350
- if (S.has(n)) {
351
+ async function Ce(t, n, r) {
352
+ const d = I !== "element", l = I !== "mp4clip";
353
+ if (g.has(n)) {
351
354
  if (!l)
352
- throw new Error(`[renderer] MP4Clip unsupported for ${e}`);
353
- return await U(e, r).catch(() => {
355
+ throw new Error(`[renderer] MP4Clip unsupported for ${t}`);
356
+ return await U(t, r).catch(() => {
354
357
  });
355
358
  }
356
359
  if (d) {
357
- const f = await oe(e, r).catch((h) => {
358
- if (te(h) && S.add(n), !l)
360
+ const p = await oe(t, r).catch((h) => {
361
+ if (te(h) && g.add(n), !l)
359
362
  throw h;
360
363
  });
361
- if (f)
362
- return f;
364
+ if (p)
365
+ return p;
363
366
  }
364
367
  if (l)
365
- return await U(e, r).catch(() => {
368
+ return await U(t, r).catch(() => {
366
369
  });
367
370
  }
368
- function Ie(e) {
369
- return e.segmentType === "frames" && e.type === "video" && typeof e.url == "string" && ae(e.url);
371
+ function Re(t) {
372
+ return t.segmentType === "frames" && t.type === "video" && typeof t.url == "string" && ae(t.url);
370
373
  }
371
- function Pe(e, n) {
372
- const r = X(e);
374
+ function Pe(t, n) {
375
+ const r = X(t);
373
376
  if (r <= 0)
374
377
  return 0;
375
378
  if (n < r)
376
379
  return n;
377
- const d = Math.max(1e3 / Math.max(e.fps || 30, 1), 1);
380
+ const d = Math.max(1e3 / Math.max(t.fps || 30, 1), 1);
378
381
  return Math.max(r - d, 0);
379
382
  }
380
- async function $e(e) {
381
- const n = t.resourceDir ?? at;
383
+ async function $e(t) {
384
+ const n = e.resourceDir ?? at;
382
385
  try {
383
- const r = W(e);
386
+ const r = W(t);
384
387
  if (!r)
385
388
  return;
386
389
  const d = _e(`${n}/${r}`, "r");
@@ -390,13 +393,13 @@ async function ct(t) {
390
393
  return;
391
394
  }
392
395
  }
393
- function B(e) {
394
- return !(!e || e.startsWith("data:") || e.startsWith("blob:"));
396
+ function B(t) {
397
+ return !(!t || t.startsWith("data:") || t.startsWith("blob:"));
395
398
  }
396
399
  function Fe() {
397
- for (const [e, n] of g) {
400
+ for (const [t, n] of S) {
398
401
  if (n.kind === "mp4clip") {
399
- n.clip.destroy(), g.set(e, {
402
+ n.clip.destroy(), S.set(t, {
400
403
  kind: "frozen",
401
404
  canvas: n.canvas,
402
405
  texture: n.texture,
@@ -408,83 +411,83 @@ async function ct(t) {
408
411
  n.kind === "element" && n.video.pause();
409
412
  }
410
413
  }
411
- function ne(e) {
412
- if (e.kind === "mp4clip") {
413
- e.clip.destroy();
414
+ function ne(t) {
415
+ if (t.kind === "mp4clip") {
416
+ t.clip.destroy();
414
417
  return;
415
418
  }
416
- e.kind !== "frozen" && (e.video.pause(), e.video.removeAttribute("src"), e.video.load());
419
+ t.kind !== "frozen" && (t.video.pause(), t.video.removeAttribute("src"), t.video.load());
417
420
  }
418
- function _(e, n, r = 1e3) {
421
+ function _(t, n, r = 1e3) {
419
422
  return new Promise((d, l) => {
420
- const f = window.setTimeout(() => {
421
- x(), l(new Error(`Timed out waiting for media event: ${n}`));
423
+ const p = window.setTimeout(() => {
424
+ k(), l(new Error(`Timed out waiting for media event: ${n}`));
422
425
  }, r), h = () => {
423
- x(), d();
424
- }, M = () => {
425
- x();
426
- const $ = e.error ? `${e.error.code}` : "unknown";
426
+ k(), d();
427
+ }, T = () => {
428
+ k();
429
+ const $ = t.error ? `${t.error.code}` : "unknown";
427
430
  l(new Error(`Media error (${$}) while waiting for ${n}`));
428
- }, x = () => {
429
- window.clearTimeout(f), e.removeEventListener(n, h), e.removeEventListener("error", M);
431
+ }, k = () => {
432
+ window.clearTimeout(p), t.removeEventListener(n, h), t.removeEventListener("error", T);
430
433
  };
431
- e.addEventListener(n, h, { once: !0 }), e.addEventListener("error", M, { once: !0 });
434
+ t.addEventListener(n, h, { once: !0 }), t.addEventListener("error", T, { once: !0 });
432
435
  });
433
436
  }
434
- async function oe(e, n) {
437
+ async function oe(t, n) {
435
438
  let r;
436
- B(e) && (r = await $e(e));
439
+ B(t) && (r = await $e(t));
437
440
  let d;
438
441
  try {
439
442
  if (r)
440
443
  d = new z(r);
441
444
  else {
442
- const $ = await fetch(e);
445
+ const $ = await fetch(t);
443
446
  if (!$.body)
444
447
  return;
445
- if (B(e)) {
448
+ if (B(t)) {
446
449
  const [D, V] = $.body.tee();
447
- p.add(e, { body: V }).catch(() => {
450
+ f.add(t, { body: V }).catch(() => {
448
451
  }), d = new z(D);
449
452
  } else
450
453
  d = new z($.body);
451
454
  }
452
455
  await d.ready;
453
- const { width: l, height: f } = d.meta, h = document.createElement("canvas");
454
- h.width = l || 1, h.height = f || 1;
455
- const M = A.from(h), x = n?.sprite ?? new F(M);
456
- return n?.sprite && (n.sprite.texture = M, n.oldTexture?.destroy(!0)), { kind: "mp4clip", clip: d, canvas: h, texture: M, sprite: x, meta: { width: l, height: f } };
456
+ const { width: l, height: p } = d.meta, h = document.createElement("canvas");
457
+ h.width = l || 1, h.height = p || 1;
458
+ const T = A.from(h), k = n?.sprite ?? new F(T);
459
+ return n?.sprite && (n.sprite.texture = T, n.oldTexture?.destroy(!0)), { kind: "mp4clip", clip: d, canvas: h, texture: T, sprite: k, meta: { width: l, height: p } };
457
460
  } catch (l) {
458
461
  throw d?.destroy(), l;
459
462
  }
460
463
  }
461
- function ie(e) {
462
- const r = e.split("#")[0].split("?")[0].split("/").pop()?.split(".").pop()?.toLowerCase() ?? "";
464
+ function ie(t) {
465
+ const r = t.split("#")[0].split("?")[0].split("/").pop()?.split(".").pop()?.toLowerCase() ?? "";
463
466
  return ["mp4", "m4v", "mov", "webm"].includes(r) ? "video" : ["png", "jpg", "jpeg", "gif", "webp", "bmp", "svg", "avif"].includes(r) ? "image" : ["mp3", "wav", "aac", "m4a", "ogg", "flac"].includes(r) ? "audio" : "unknown";
464
467
  }
465
- function ae(e) {
466
- const n = ie(e);
468
+ function ae(t) {
469
+ const n = ie(t);
467
470
  return !(n === "image" || n === "audio");
468
471
  }
469
- async function U(e, n) {
472
+ async function U(t, n) {
470
473
  const r = document.createElement("video");
471
- r.crossOrigin = "anonymous", r.muted = !0, r.playsInline = !0, r.preload = "auto", r.src = e;
474
+ r.crossOrigin = "anonymous", r.muted = !0, r.playsInline = !0, r.preload = "auto", r.src = t;
472
475
  try {
473
476
  await _(r, "loadedmetadata", 4e3);
474
- } catch (x) {
475
- throw r.pause(), r.removeAttribute("src"), r.load(), x;
477
+ } catch (k) {
478
+ throw r.pause(), r.removeAttribute("src"), r.load(), k;
476
479
  }
477
- const d = r.videoWidth || 1, l = r.videoHeight || 1, f = document.createElement("canvas");
478
- f.width = d, f.height = l;
479
- const h = A.from(f), M = n?.sprite ?? new F(h);
480
- return n?.sprite && (n.sprite.texture = h, n.oldTexture?.destroy(!0)), { kind: "element", video: r, canvas: f, texture: h, sprite: M, meta: { width: d, height: l } };
480
+ const d = r.videoWidth || 1, l = r.videoHeight || 1, p = document.createElement("canvas");
481
+ p.width = d, p.height = l;
482
+ const h = A.from(p), T = n?.sprite ?? new F(h);
483
+ return n?.sprite && (n.sprite.texture = h, n.oldTexture?.destroy(!0)), { kind: "element", video: r, canvas: p, texture: h, sprite: T, meta: { width: d, height: l } };
481
484
  }
482
- async function Oe(e, n) {
483
- const { video: r, canvas: d, texture: l } = e;
485
+ async function Oe(t, n) {
486
+ const { video: r, canvas: d, texture: l } = t;
484
487
  r.playbackRate = Number.isFinite(n.playbackRate) && n.playbackRate > 0 ? n.playbackRate : 1, v.value ? r.play().catch(() => {
485
488
  }) : r.pause();
486
- const f = r.currentTime, h = Math.abs(f - n.targetSec), M = v.value ? 0.25 : 0.03;
487
- if (Number.isFinite(f) && h > M) {
489
+ const p = r.currentTime, h = Math.abs(p - n.targetSec), T = v.value ? 0.25 : 0.03;
490
+ if (Number.isFinite(p) && h > T) {
488
491
  try {
489
492
  r.currentTime = n.targetSec;
490
493
  } catch {
@@ -495,85 +498,85 @@ async function ct(t) {
495
498
  if (r.readyState < 2 && (await _(r, "canplay", 250).catch(() => {
496
499
  }), r.readyState < 2))
497
500
  return;
498
- const x = d.getContext("2d");
499
- x && (x.drawImage(r, 0, 0, d.width, d.height), ce(l));
501
+ const k = d.getContext("2d");
502
+ k && (k.drawImage(r, 0, 0, d.width, d.height), ce(l));
500
503
  }
501
- function Ve(e) {
504
+ function Ve(t) {
502
505
  return new Promise((n) => {
503
506
  const r = new Image();
504
507
  r.crossOrigin = "anonymous", r.onload = () => n(A.from(r)), r.onerror = () => {
505
- console.warn("[renderer] failed to load image", e), n(void 0);
506
- }, r.src = e;
508
+ console.warn("[renderer] failed to load image", t), n(void 0);
509
+ }, r.src = t;
507
510
  });
508
511
  }
509
- function ce(e) {
510
- const n = e.source;
512
+ function ce(t) {
513
+ const n = t.source;
511
514
  if ("update" in n && typeof n.update == "function") {
512
515
  n.update();
513
516
  return;
514
517
  }
515
- typeof e.update == "function" && e.update();
518
+ typeof t.update == "function" && t.update();
516
519
  }
517
520
  function Ae() {
518
- L(), b += 1, J.stop(), H(), u.destroy({ children: !0 }), y.clear(), E.clear(), s.clear(), t.app || c.destroy();
521
+ L(), b += 1, J.stop(), H(), u.destroy({ children: !0 }), m.clear(), M.clear(), s.clear(), e.app || c.destroy();
519
522
  }
520
- return t.autoPlay && Q(), {
523
+ return e.autoPlay && Q(), {
521
524
  app: c,
522
525
  layer: u,
523
526
  currentTime: w,
524
- duration: m,
527
+ duration: y,
525
528
  isPlaying: v,
526
529
  play: Q,
527
530
  pause: L,
528
531
  tick: ee,
529
- seek: be,
530
- renderAt: Me,
532
+ seek: Me,
533
+ renderAt: be,
531
534
  destroy: Ae
532
535
  };
533
536
  }
534
- function st(t) {
537
+ function st(e) {
535
538
  let o = !1, a = !1, i = null, c = null;
536
539
  return async () => {
537
540
  i || (i = new Promise((s) => {
538
541
  c = s;
539
542
  }));
540
- const p = i;
543
+ const f = i;
541
544
  if (a)
542
- return o = !0, p;
545
+ return o = !0, f;
543
546
  a = !0;
544
547
  do
545
- o = !1, await t();
548
+ o = !1, await e();
546
549
  while (o);
547
- return a = !1, c?.(), i = null, c = null, p;
550
+ return a = !1, c?.(), i = null, c = null, f;
548
551
  };
549
552
  }
550
- function dt(t) {
551
- return typeof t == "object" && t !== null && "createReader" in t && "getSize" in t;
553
+ function dt(e) {
554
+ return typeof e == "object" && e !== null && "createReader" in e && "getSize" in e;
552
555
  }
553
- function ut(t) {
554
- return typeof ReadableStream < "u" && t instanceof ReadableStream;
556
+ function ut(e) {
557
+ return typeof ReadableStream < "u" && e instanceof ReadableStream;
555
558
  }
556
- function lt(t) {
557
- return typeof t == "string" || t instanceof Blob || dt(t) || ut(t) ? { source: t } : t;
559
+ function ft(e) {
560
+ return typeof e == "string" || e instanceof Blob || dt(e) || ut(e) ? { source: e } : e;
558
561
  }
559
- async function fe(t) {
560
- if (typeof t == "string") {
561
- const o = await fetch(t);
562
+ async function le(e) {
563
+ if (typeof e == "string") {
564
+ const o = await fetch(e);
562
565
  if (!o.body)
563
566
  throw new Error("concatVideos: unable to read video stream from url");
564
567
  return o.body;
565
568
  }
566
- return t instanceof Blob ? t.stream() : t;
569
+ return e instanceof Blob ? e.stream() : e;
567
570
  }
568
- function ft(t, o) {
571
+ function lt(e, o) {
569
572
  let a = !1;
570
573
  const i = () => {
571
574
  a || (a = !0, o());
572
- }, c = t.getReader();
575
+ }, c = e.getReader();
573
576
  return new ReadableStream({
574
577
  async pull(u) {
575
- const { done: p, value: s } = await c.read();
576
- if (p) {
578
+ const { done: f, value: s } = await c.read();
579
+ if (f) {
577
580
  i(), u.close();
578
581
  return;
579
582
  }
@@ -588,54 +591,54 @@ function ft(t, o) {
588
591
  }
589
592
  });
590
593
  }
591
- async function gt(t, o = {}) {
592
- if (t.length === 0)
594
+ async function gt(e, o = {}) {
595
+ if (e.length === 0)
593
596
  throw new Error("concatVideos: expected at least one source");
594
597
  const {
595
598
  onProgress: a,
596
599
  width: i,
597
600
  height: c,
598
601
  ...u
599
- } = o, p = t.map(lt), [s, ...y] = p, E = await fe(s.source), S = new z(E);
600
- await S.ready;
601
- const k = i ?? Math.round(S.meta.width || 0), C = c ?? Math.round(S.meta.height || 0);
602
- if (!k || !C)
603
- throw S.destroy(), new Error("concatVideos: output width/height is required");
604
- const g = new pe({
602
+ } = o, f = e.map(ft), [s, ...m] = f, M = await le(s.source), g = new z(M);
603
+ await g.ready;
604
+ const E = i ?? Math.round(g.meta.width || 0), I = c ?? Math.round(g.meta.height || 0);
605
+ if (!E || !I)
606
+ throw g.destroy(), new Error("concatVideos: output width/height is required");
607
+ const S = new pe({
605
608
  ...u,
606
- width: k,
607
- height: C
609
+ width: E,
610
+ height: I
608
611
  });
609
- a && g.on("OutputProgress", a);
612
+ a && S.on("OutputProgress", a);
610
613
  let w = 0;
611
614
  const v = async (b) => {
612
- const I = b.meta.duration;
613
- if (!Number.isFinite(I) || I <= 0)
615
+ const R = b.meta.duration;
616
+ if (!Number.isFinite(R) || R <= 0)
614
617
  throw b.destroy(), new Error("concatVideos: invalid clip duration");
615
- const T = new he(b);
618
+ const x = new he(b);
616
619
  try {
617
- await T.ready, T.rect.x = 0, T.rect.y = 0, T.rect.w = k, T.rect.h = C, T.time.offset = w, T.time.duration = I, await g.addSprite(T), w += I;
620
+ await x.ready, x.rect.x = 0, x.rect.y = 0, x.rect.w = E, x.rect.h = I, x.time.offset = w, x.time.duration = R, await S.addSprite(x), w += R;
618
621
  } finally {
619
- T.destroy();
622
+ x.destroy();
620
623
  }
621
624
  };
622
625
  try {
623
- await v(S);
624
- for (const b of y) {
625
- const I = await fe(b.source), T = new z(I);
626
- await T.ready, await v(T);
626
+ await v(g);
627
+ for (const b of m) {
628
+ const R = await le(b.source), x = new z(R);
629
+ await x.ready, await v(x);
627
630
  }
628
631
  } catch (b) {
629
- throw g.destroy(), b;
632
+ throw S.destroy(), b;
630
633
  }
631
- const m = w, R = g.output({ maxTime: m }), P = () => {
632
- g.destroy();
634
+ const y = w, C = S.output({ maxTime: y }), P = () => {
635
+ S.destroy();
633
636
  };
634
637
  return {
635
- stream: ft(R, P),
636
- width: k,
637
- height: C,
638
- durationMs: Math.round(m / 1e3),
638
+ stream: lt(C, P),
639
+ width: E,
640
+ height: I,
641
+ durationMs: Math.round(y / 1e3),
639
642
  destroy: P
640
643
  };
641
644
  }
@@ -677,11 +680,11 @@ class G {
677
680
  videoSourceMode: c.videoSourceMode ?? "mp4clip"
678
681
  });
679
682
  this.renderer = u;
680
- const p = u.duration.value;
683
+ const f = u.duration.value;
681
684
  return this.meta = {
682
685
  width: i.renderer.width,
683
686
  height: i.renderer.height,
684
- duration: Math.max(0, Math.round(p * 1e3))
687
+ duration: Math.max(0, Math.round(f * 1e3))
685
688
  }, this.meta;
686
689
  }
687
690
  async tick(o) {
@@ -710,15 +713,15 @@ class G {
710
713
  this.destroyed || (this.destroyed = !0, this.renderer?.destroy(), this.app?.destroy(!0));
711
714
  }
712
715
  }
713
- function pt(t, o) {
716
+ function pt(e, o) {
714
717
  let a = !1;
715
718
  const i = () => {
716
719
  a || (a = !0, o());
717
- }, c = t.getReader();
720
+ }, c = e.getReader();
718
721
  return new ReadableStream({
719
722
  async pull(u) {
720
- const { done: p, value: s } = await c.read();
721
- if (p) {
723
+ const { done: f, value: s } = await c.read();
724
+ if (f) {
722
725
  i(), u.close();
723
726
  return;
724
727
  }
@@ -733,56 +736,56 @@ function pt(t, o) {
733
736
  }
734
737
  });
735
738
  }
736
- async function St(t, o = {}) {
739
+ async function St(e, o = {}) {
737
740
  const {
738
741
  width: a,
739
742
  height: i,
740
743
  fps: c,
741
744
  onProgress: u,
742
- clipOptions: p,
745
+ clipOptions: f,
743
746
  audioSprites: s,
744
- ...y
745
- } = o, E = a ?? t.width, S = i ?? t.height;
746
- if (!E || !S)
747
+ ...m
748
+ } = o, M = a ?? e.width, g = i ?? e.height;
749
+ if (!M || !g)
747
750
  throw new Error("composeProtocol: output width/height is required");
748
- const k = c ?? t.fps, C = typeof s == "function", g = y.audio ?? (C ? void 0 : !1), w = new pe({
749
- ...y,
750
- audio: g,
751
- width: E,
752
- height: S,
753
- fps: k
751
+ const E = c ?? e.fps, I = typeof s == "function", S = m.audio ?? (I ? void 0 : !1), w = new pe({
752
+ ...m,
753
+ audio: S,
754
+ width: M,
755
+ height: g,
756
+ fps: E
754
757
  });
755
758
  u && w.on("OutputProgress", u);
756
- let v, m;
759
+ let v, y;
757
760
  try {
758
- if (v = new G(t, {
759
- width: E,
760
- height: S,
761
- fps: k,
762
- ...p,
761
+ if (v = new G(e, {
762
+ width: M,
763
+ height: g,
764
+ fps: E,
765
+ ...f,
763
766
  rendererOptions: {
764
767
  warmUpResources: !1,
765
- ...p?.rendererOptions
768
+ ...f?.rendererOptions
766
769
  }
767
- }), await v.ready, m = new he(v), await m.ready, m.time.offset = 0, m.time.duration = v.meta.duration, m.rect.x = 0, m.rect.y = 0, m.rect.w = v.meta.width, m.rect.h = v.meta.height, await w.addSprite(m, { main: !0 }), s) {
768
- const I = await s(t);
769
- for (const T of I)
770
- await w.addSprite(T);
770
+ }), await v.ready, y = new he(v), await y.ready, y.time.offset = 0, y.time.duration = v.meta.duration, y.rect.x = 0, y.rect.y = 0, y.rect.w = v.meta.width, y.rect.h = v.meta.height, await w.addSprite(y, { main: !0 }), s) {
771
+ const R = await s(e);
772
+ for (const x of R)
773
+ await w.addSprite(x);
771
774
  }
772
- } catch (I) {
773
- throw w.destroy(), I;
775
+ } catch (R) {
776
+ throw w.destroy(), R;
774
777
  }
775
- const R = v?.meta.duration ?? 0;
776
- if (!R)
778
+ const C = v?.meta.duration ?? 0;
779
+ if (!C)
777
780
  throw new Error("composeProtocol: protocol has no duration");
778
- const P = w.output({ maxTime: R }), b = () => {
779
- m?.destroy(), v?.destroy(), w.destroy();
781
+ const P = w.output({ maxTime: C }), b = () => {
782
+ y?.destroy(), v?.destroy(), w.destroy();
780
783
  };
781
784
  return {
782
785
  stream: pt(P, b),
783
- width: E,
784
- height: S,
785
- durationMs: Math.round(R / 1e3),
786
+ width: M,
787
+ height: g,
788
+ durationMs: Math.round(C / 1e3),
786
789
  destroy: b
787
790
  };
788
791
  }