@video-editor/renderer 0.0.1-beta.31 → 0.0.1-beta.33

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
@@ -1,100 +1,100 @@
1
- import { createValidator as De, createResourceManager as Ne, getResourceKey as _ } from "@video-editor/protocol";
2
- import { toRaw as Ge, isRef as Ke, shallowRef as pe, unref as he, ref as me, computed as qe, effectScope as Be, watch as Q } from "@vue/reactivity";
3
- import { AudioClip as je, renderTxt2ImgBitmap as _e, MP4Clip as B, Combinator as ve, OffscreenSprite as Me } from "@webav/av-cliper";
4
- import { file as We } from "opfs-tools";
5
- import { Application as Se, Sprite as $, Texture as G, Graphics as ge, Container as Ye } from "pixi.js";
6
- async function Xe(o) {
7
- const e = new Se();
8
- return await e.init({ resizeTo: window, backgroundAlpha: 0, ...o }), e;
1
+ import { createValidator as Wt, createResourceManager as Yt, getResourceKey as W } from "@video-editor/protocol";
2
+ import { toRaw as Xt, isRef as Jt, shallowRef as vt, unref as Mt, ref as gt, computed as Ht, effectScope as Qt, watch as Z } from "@vue/reactivity";
3
+ import { AudioClip as Tt, renderTxt2ImgBitmap as Zt, MP4Clip as K, Combinator as bt, OffscreenSprite as nt } from "@webav/av-cliper";
4
+ import { file as te } from "opfs-tools";
5
+ import { Application as kt, Sprite as V, Texture as G, Graphics as Ct, Container as ee } from "pixi.js";
6
+ async function oe(e) {
7
+ const t = new kt();
8
+ return await t.init({ resizeTo: window, backgroundAlpha: 0, ...e }), t;
9
9
  }
10
- function Je(o, e, r, i, n) {
11
- const d = e || i, c = r || n;
12
- if (!d || !c)
10
+ function ie(e, t, o, i, n) {
11
+ const a = t || i, c = o || n;
12
+ if (!a || !c)
13
13
  return { width: i, height: n };
14
- const s = d / c, l = i / n;
15
- switch (o) {
14
+ const u = a / c, d = i / n;
15
+ switch (e) {
16
16
  case "none":
17
- return { width: d, height: c };
17
+ return { width: a, height: c };
18
18
  case "cover":
19
- return s > l ? { width: n * s, height: n } : { width: i, height: i / s };
19
+ return u > d ? { width: n * u, height: n } : { width: i, height: i / u };
20
20
  case "stretch":
21
21
  return { width: i, height: n };
22
22
  default:
23
- return s > l ? { width: i, height: i / s } : { width: n * s, height: n };
23
+ return u > d ? { width: i, height: i / u } : { width: n * u, height: n };
24
24
  }
25
25
  }
26
- function He(o, e, r, i, n) {
27
- const d = "fillMode" in o ? o.fillMode : void 0, { width: c, height: s } = Je(
28
- d,
26
+ function re(e, t, o, i, n) {
27
+ const a = "fillMode" in e ? e.fillMode : void 0, { width: c, height: u } = ie(
28
+ a,
29
29
  i,
30
30
  n,
31
- e,
32
- r
33
- ), l = "transform" in o ? o.transform : void 0, [m, p] = l?.position ?? [0, 0], [w, T] = l?.scale ?? [1, 1], h = l?.rotation?.[2] ?? 0, v = c * w, y = s * T, g = e / 2 + m * e / 2, R = r / 2 - p * r / 2;
31
+ t,
32
+ o
33
+ ), d = "transform" in e ? e.transform : void 0, [y, h] = d?.position ?? [0, 0], [w, M] = d?.scale ?? [1, 1], p = d?.rotation?.[2] ?? 0, v = c * w, m = u * M, g = t / 2 + y * t / 2, R = o / 2 - h * o / 2;
34
34
  return {
35
35
  width: v,
36
- height: y,
36
+ height: m,
37
37
  centerX: g,
38
38
  centerY: R,
39
- rotationRad: h / 180 * Math.PI
39
+ rotationRad: p / 180 * Math.PI
40
40
  };
41
41
  }
42
- function Qe(o) {
43
- const e = /* @__PURE__ */ new Set();
44
- for (const r of o.tracks)
45
- for (const i of r.children)
46
- i.url && e.add(i.url);
47
- return e;
42
+ function ne(e) {
43
+ const t = /* @__PURE__ */ new Set();
44
+ for (const o of e.tracks)
45
+ for (const i of o.children)
46
+ i.url && t.add(i.url);
47
+ return t;
48
48
  }
49
- function xe(o, e) {
50
- const r = [];
51
- return o.tracks.forEach((i, n) => {
52
- i.children.forEach((d, c) => {
53
- d.startTime <= e && e < d.endTime && r.push({ segment: d, trackIndex: n, childIndex: c });
49
+ function Rt(e, t) {
50
+ const o = [];
51
+ return e.tracks.forEach((i, n) => {
52
+ i.children.forEach((a, c) => {
53
+ a.startTime <= t && t < a.endTime && o.push({ segment: a, trackIndex: n, childIndex: c });
54
54
  });
55
- }), r.sort((i, n) => {
56
- const d = o.tracks[i.trackIndex], c = o.tracks[n.trackIndex], s = d?.trackType === "frames" && d.isMain, l = c?.trackType === "frames" && c.isMain, m = o.tracks.length, p = s ? 0 : m - i.trackIndex, w = l ? 0 : m - n.trackIndex;
57
- return p !== w ? p - w : i.trackIndex === n.trackIndex ? i.childIndex - n.childIndex : i.trackIndex - n.trackIndex;
55
+ }), o.sort((i, n) => {
56
+ const a = e.tracks[i.trackIndex], c = e.tracks[n.trackIndex], u = a?.trackType === "frames" && a.isMain, d = c?.trackType === "frames" && c.isMain, y = e.tracks.length, h = u ? 0 : y - i.trackIndex, w = d ? 0 : y - n.trackIndex;
57
+ return h !== w ? h - w : i.trackIndex === n.trackIndex ? i.childIndex - n.childIndex : i.trackIndex - n.trackIndex;
58
58
  });
59
59
  }
60
- function Ze(o, e, r, i) {
61
- const n = tt(e), d = o instanceof $ && o.texture.width || r, c = o instanceof $ && o.texture.height || i, s = He(e, r, i, d, c);
62
- o instanceof $ ? (o.anchor.set(0.5), o.width = s.width, o.height = s.height, o.position.set(s.centerX, s.centerY), o.rotation = s.rotationRad, o.texture.source?.addEventListener?.("error", () => {
63
- o.texture = G.from(et(r, i));
64
- }, { once: !0 })) : o instanceof ge && (o.clear(), o.rect(0, 0, s.width, s.height).fill({ color: Te("url" in e && typeof e.url == "string" ? e.url : e.segmentType), alpha: be(e) ? n : 0.35 }), o.pivot.set(s.width / 2, s.height / 2), o.position.set(s.centerX, s.centerY), o.rotation = s.rotationRad), o.alpha = n;
60
+ function ae(e, t, o, i) {
61
+ const n = ce(t), a = e instanceof V && e.texture.width || o, c = e instanceof V && e.texture.height || i, u = re(t, o, i, a, c);
62
+ e instanceof V ? (e.anchor.set(0.5), e.width = u.width, e.height = u.height, e.position.set(u.centerX, u.centerY), e.rotation = u.rotationRad, e.texture.source?.addEventListener?.("error", () => {
63
+ e.texture = G.from(se(o, i));
64
+ }, { once: !0 })) : e instanceof Ct && (e.clear(), e.rect(0, 0, u.width, u.height).fill({ color: At("url" in t && typeof t.url == "string" ? t.url : t.segmentType), alpha: Et(t) ? n : 0.35 }), e.pivot.set(u.width / 2, u.height / 2), e.position.set(u.centerX, u.centerY), e.rotation = u.rotationRad), e.alpha = n;
65
65
  }
66
- function Z(o, e) {
67
- const r = new ge();
68
- return r.rect(0, 0, 10, 10).fill({ color: Te(e ?? o), alpha: 1 }), r;
66
+ function tt(e, t) {
67
+ const o = new Ct();
68
+ return o.rect(0, 0, 10, 10).fill({ color: At(t ?? e), alpha: 1 }), o;
69
69
  }
70
- function et(o, e, r) {
71
- const i = `<svg xmlns="http://www.w3.org/2000/svg" width="${o}" height="${e}"><rect width="100%" height="100%" fill="#0f172a" fill-opacity="0.8"/></svg>`;
70
+ function se(e, t, o) {
71
+ const i = `<svg xmlns="http://www.w3.org/2000/svg" width="${e}" height="${t}"><rect width="100%" height="100%" fill="#0f172a" fill-opacity="0.8"/></svg>`;
72
72
  return `data:image/svg+xml;base64,${btoa(i)}`;
73
73
  }
74
- function Te(o) {
75
- let e = 0;
76
- for (let r = 0; r < o.length; r++)
77
- e = o.charCodeAt(r) + ((e << 5) - e);
78
- return e & 16777215;
74
+ function At(e) {
75
+ let t = 0;
76
+ for (let o = 0; o < e.length; o++)
77
+ t = e.charCodeAt(o) + ((t << 5) - t);
78
+ return t & 16777215;
79
79
  }
80
- function te(o) {
81
- const e = o.tracks.flatMap((r) => r.children.map((i) => i.endTime));
82
- return e.length ? Math.max(...e) : 0;
80
+ function it(e) {
81
+ const t = e.tracks.flatMap((o) => o.children.map((i) => i.endTime));
82
+ return t.length ? Math.max(...t) : 0;
83
83
  }
84
- function ee(o, e, r) {
85
- return Math.min(Math.max(o, e), r);
84
+ function et(e, t, o) {
85
+ return Math.min(Math.max(e, t), o);
86
86
  }
87
- function ye(o) {
88
- const e = Ge(o);
89
- return JSON.parse(JSON.stringify(e));
87
+ function St(e) {
88
+ const t = Xt(e);
89
+ return JSON.parse(JSON.stringify(t));
90
90
  }
91
- function be(o) {
92
- return "opacity" in o;
91
+ function Et(e) {
92
+ return "opacity" in e;
93
93
  }
94
- function tt(o) {
95
- return be(o) && typeof o.opacity == "number" ? o.opacity : 1;
94
+ function ce(e) {
95
+ return Et(e) && typeof e.opacity == "number" ? e.opacity : 1;
96
96
  }
97
- class ot {
97
+ class ue {
98
98
  protocol;
99
99
  clips = /* @__PURE__ */ new Map();
100
100
  loadingClips = /* @__PURE__ */ new Map();
@@ -108,91 +108,91 @@ class ot {
108
108
  useMediaElementForAudio = !0;
109
109
  ctx;
110
110
  lastTime = 0;
111
- constructor(e) {
112
- this.protocol = e, this.ctx = new (window.AudioContext || window.webkitAudioContext)();
111
+ constructor(t) {
112
+ this.protocol = t, this.ctx = new (window.AudioContext || window.webkitAudioContext)();
113
113
  }
114
- setProtocol(e) {
115
- this.protocol = e;
114
+ setProtocol(t) {
115
+ this.protocol = t;
116
116
  }
117
- async sync(e, r) {
118
- if (!r) {
119
- this.stopAll(), this.lastTime = e;
117
+ async sync(t, o) {
118
+ if (!o) {
119
+ this.stopAll(), this.lastTime = t;
120
120
  return;
121
121
  }
122
122
  this.ctx.state === "suspended" && await this.ctx.resume().catch(() => {
123
- }), Math.abs(e - this.lastTime) > 1e3 && this.stopAll(), this.lastTime = e;
124
- const i = xe(this.protocol, e), n = /* @__PURE__ */ new Set(), d = /* @__PURE__ */ new Set();
123
+ }), Math.abs(t - this.lastTime) > 1e3 && this.stopAll(), this.lastTime = t;
124
+ const i = Rt(this.protocol, t), n = /* @__PURE__ */ new Set(), a = /* @__PURE__ */ new Set();
125
125
  for (const { segment: c } of i)
126
126
  if (c.segmentType === "audio") {
127
- const s = this.audioKey(c.id);
128
- n.add(s), this.useMediaElementForAudio ? this.syncAudioElement(c, e) : this.ensureAudioLoop(c, e);
127
+ const u = this.audioKey(c.id);
128
+ n.add(u), this.useMediaElementForAudio ? this.syncAudioElement(c, t) : this.ensureAudioLoop(c, t);
129
129
  } else if (c.segmentType === "frames" && "type" in c && c.type === "video") {
130
- const s = this.videoKey(c.id);
131
- d.add(s);
130
+ const u = this.videoKey(c.id);
131
+ a.add(u);
132
132
  }
133
- for (const [c, s] of this.audioLoops)
133
+ for (const [c, u] of this.audioLoops)
134
134
  if (!n.has(c)) {
135
- s.stop();
136
- for (const l of s.sources)
135
+ u.stop();
136
+ for (const d of u.sources)
137
137
  try {
138
- l.stop(), l.disconnect();
138
+ d.stop(), d.disconnect();
139
139
  } catch {
140
140
  }
141
141
  this.audioLoops.delete(c), this.audioLoopContexts.delete(c), this.audioGains.delete(c);
142
142
  }
143
- for (const [c, s] of this.audioElements)
143
+ for (const [c, u] of this.audioElements)
144
144
  if (!n.has(c)) {
145
145
  try {
146
- s.el.pause(), s.pendingPlay = void 0, s.lastTimelineMs = void 0, s.lastSourceSec = void 0, s.lastSeekTimelineMs = void 0;
146
+ u.el.pause(), u.pendingPlay = void 0, u.lastTimelineMs = void 0, u.lastSourceSec = void 0, u.lastSeekTimelineMs = void 0;
147
147
  } catch {
148
148
  }
149
- this.findSegmentInProtocol(s.segmentId) || (this.destroyAudioElement(s.el), this.audioElements.delete(c));
149
+ this.findSegmentInProtocol(u.segmentId) || (this.destroyAudioElement(u.el), this.audioElements.delete(c));
150
150
  }
151
- for (const [c, s] of this.mp4Loops)
152
- if (!d.has(c)) {
153
- s.stop();
154
- for (const l of s.sources)
151
+ for (const [c, u] of this.mp4Loops)
152
+ if (!a.has(c)) {
153
+ u.stop();
154
+ for (const d of u.sources)
155
155
  try {
156
- l.stop(), l.disconnect();
156
+ d.stop(), d.disconnect();
157
157
  } catch {
158
158
  }
159
159
  this.mp4Loops.delete(c), this.mp4States.delete(c), this.mp4Gains.delete(c);
160
160
  }
161
161
  for (const c of this.mp4States.keys())
162
- !d.has(c) && !this.mp4Loops.has(c) && (this.mp4States.delete(c), this.mp4Gains.delete(c));
162
+ !a.has(c) && !this.mp4Loops.has(c) && (this.mp4States.delete(c), this.mp4Gains.delete(c));
163
163
  }
164
164
  /**
165
165
  * Play audio frames from MP4 video directly.
166
166
  * Called by renderer after it gets audio data from clip.tick()
167
167
  */
168
- playMp4AudioFrames(e, r, i) {
169
- if (!r || r.length === 0 || !r[0]?.length)
168
+ playMp4AudioFrames(t, o, i) {
169
+ if (!o || o.length === 0 || !o[0]?.length)
170
170
  return;
171
- const n = this.videoKey(e), d = this.getSegmentVolume(e), c = this.getOrCreateGain(this.mp4Gains, n, d);
171
+ const n = this.videoKey(t), a = this.getSegmentVolume(t), c = this.getOrCreateGain(this.mp4Gains, n, a);
172
172
  this.ctx.state === "suspended" && this.ctx.resume().catch(() => {
173
173
  });
174
- let s = this.mp4States.get(n);
175
- s || (s = {
174
+ let u = this.mp4States.get(n);
175
+ u || (u = {
176
176
  loop: { stop: () => {
177
177
  }, sources: [], isStopped: () => !1 },
178
178
  startUs: 0,
179
179
  startCtxTime: this.ctx.currentTime,
180
180
  fps: 30,
181
181
  nextStartAt: 0
182
- }, this.mp4States.set(n, s)), s.nextStartAt = this.playFrames(r, i, s.nextStartAt ?? 0, c, s.loop.sources);
182
+ }, this.mp4States.set(n, u)), u.nextStartAt = this.playFrames(o, i, u.nextStartAt ?? 0, c, u.loop.sources);
183
183
  }
184
184
  /**
185
185
  * Reset MP4 audio playback state (call when seeking or pausing)
186
186
  */
187
- resetMp4Audio(e) {
188
- const r = this.videoKey(e), i = this.mp4States.get(r);
187
+ resetMp4Audio(t) {
188
+ const o = this.videoKey(t), i = this.mp4States.get(o);
189
189
  i && (i.nextStartAt = 0);
190
190
  }
191
191
  /**
192
192
  * Stop and clean up MP4 audio for a video segment
193
193
  */
194
- stopMp4Audio(e) {
195
- const r = this.videoKey(e), i = this.mp4States.get(r);
194
+ stopMp4Audio(t) {
195
+ const o = this.videoKey(t), i = this.mp4States.get(o);
196
196
  if (i) {
197
197
  i.loop.stop();
198
198
  for (const n of i.loop.sources)
@@ -200,32 +200,32 @@ class ot {
200
200
  n.stop(), n.disconnect();
201
201
  } catch {
202
202
  }
203
- this.mp4Loops.delete(r), this.mp4States.delete(r), this.mp4Gains.delete(r);
203
+ this.mp4Loops.delete(o), this.mp4States.delete(o), this.mp4Gains.delete(o);
204
204
  }
205
205
  }
206
206
  /**
207
207
  * @deprecated Use playMp4AudioFrames instead
208
208
  */
209
- ensureMp4Audio(e, r, i, n) {
210
- const d = this.videoKey(e), c = this.getSegmentVolume(e), s = this.getOrCreateGain(this.mp4Gains, d, c), l = this.mp4States.get(d);
211
- if (l) {
212
- s.gain.value = Math.max(0, c);
213
- const p = (this.ctx.currentTime - l.startCtxTime) * 1e6, w = l.startUs + p;
214
- if (Math.abs(w - i) < 15e4 && l.fps === n)
209
+ ensureMp4Audio(t, o, i, n) {
210
+ const a = this.videoKey(t), c = this.getSegmentVolume(t), u = this.getOrCreateGain(this.mp4Gains, a, c), d = this.mp4States.get(a);
211
+ if (d) {
212
+ u.gain.value = Math.max(0, c);
213
+ const h = (this.ctx.currentTime - d.startCtxTime) * 1e6, w = d.startUs + h;
214
+ if (Math.abs(w - i) < 15e4 && d.fps === n)
215
215
  return;
216
- l.loop.stop();
217
- for (const T of l.loop.sources)
216
+ d.loop.stop();
217
+ for (const M of d.loop.sources)
218
218
  try {
219
- T.stop(), T.disconnect();
219
+ M.stop(), M.disconnect();
220
220
  } catch {
221
221
  }
222
- this.mp4Loops.delete(d), this.mp4States.delete(d);
222
+ this.mp4Loops.delete(a), this.mp4States.delete(a);
223
223
  }
224
224
  this.ctx.state === "suspended" && this.ctx.resume().catch(() => {
225
225
  });
226
- const m = this.startMp4Loop(r, i, n, s);
227
- this.mp4Loops.set(d, m), this.mp4States.set(d, {
228
- loop: m,
226
+ const y = this.startMp4Loop(o, i, n, u);
227
+ this.mp4Loops.set(a, y), this.mp4States.set(a, {
228
+ loop: y,
229
229
  startUs: i,
230
230
  startCtxTime: this.ctx.currentTime,
231
231
  fps: n
@@ -233,87 +233,87 @@ class ot {
233
233
  }
234
234
  destroy() {
235
235
  this.stopAll();
236
- for (const e of this.clips.values())
237
- e.clip.destroy();
236
+ for (const t of this.clips.values())
237
+ t.clip.destroy();
238
238
  this.clips.clear();
239
- for (const e of this.audioElements.values())
240
- this.destroyAudioElement(e.el);
239
+ for (const t of this.audioElements.values())
240
+ this.destroyAudioElement(t.el);
241
241
  this.audioElements.clear();
242
242
  }
243
243
  stopAll() {
244
- for (const e of this.audioElements.values())
244
+ for (const t of this.audioElements.values())
245
245
  try {
246
- e.el.pause(), e.pendingPlay = void 0, e.lastTimelineMs = void 0, e.lastSourceSec = void 0, e.lastSeekTimelineMs = void 0;
246
+ t.el.pause(), t.pendingPlay = void 0, t.lastTimelineMs = void 0, t.lastSourceSec = void 0, t.lastSeekTimelineMs = void 0;
247
247
  } catch {
248
248
  }
249
- for (const e of this.audioLoops.values()) {
250
- e.stop();
251
- for (const r of e.sources)
249
+ for (const t of this.audioLoops.values()) {
250
+ t.stop();
251
+ for (const o of t.sources)
252
252
  try {
253
- r.stop(0), r.disconnect();
253
+ o.stop(0), o.disconnect();
254
254
  } catch {
255
255
  }
256
- e.sources.length = 0;
256
+ t.sources.length = 0;
257
257
  }
258
- for (const e of this.mp4Loops.values()) {
259
- e.stop();
260
- for (const r of e.sources)
258
+ for (const t of this.mp4Loops.values()) {
259
+ t.stop();
260
+ for (const o of t.sources)
261
261
  try {
262
- r.stop(0), r.disconnect();
262
+ o.stop(0), o.disconnect();
263
263
  } catch {
264
264
  }
265
- e.sources.length = 0;
265
+ t.sources.length = 0;
266
266
  }
267
- for (const e of this.audioGains.values())
267
+ for (const t of this.audioGains.values())
268
268
  try {
269
- e.disconnect();
269
+ t.disconnect();
270
270
  } catch {
271
271
  }
272
- for (const e of this.mp4Gains.values())
272
+ for (const t of this.mp4Gains.values())
273
273
  try {
274
- e.disconnect();
274
+ t.disconnect();
275
275
  } catch {
276
276
  }
277
277
  this.audioLoops.clear(), this.audioLoopContexts.clear(), this.audioGains.clear(), this.mp4Loops.clear(), this.mp4States.clear(), this.mp4Gains.clear();
278
278
  }
279
- async ensureAudioLoop(e, r) {
280
- const i = this.audioKey(e.id), n = await this.loadClip(e);
279
+ async ensureAudioLoop(t, o) {
280
+ const i = this.audioKey(t.id), n = await this.loadClip(t);
281
281
  if (!n)
282
282
  return;
283
- const d = e.fromTime ?? 0, c = this.normalizePlayRate(e.playRate), s = r - e.startTime, l = d + s * c, m = this.getOrCreateGain(this.audioGains, i, e.volume);
284
- this.applyFadeToGain(e, s, m);
285
- const p = this.audioLoops.get(i);
286
- if (p && !p.isStopped())
283
+ const a = t.fromTime ?? 0, c = this.normalizePlayRate(t.playRate), u = o - t.startTime, d = a + u * c, y = this.getOrCreateGain(this.audioGains, i, t.volume);
284
+ this.applyFadeToGain(t, u, y);
285
+ const h = this.audioLoops.get(i);
286
+ if (h && !h.isStopped())
287
287
  return;
288
- p && (this.audioLoops.delete(i), this.audioLoopContexts.delete(i));
289
- const T = (e.endTime - e.startTime) * c, h = d + T, v = this.startAudioLoop(n.clip, Math.max(0, l) * 1e3, m, c, h * 1e3);
288
+ h && (this.audioLoops.delete(i), this.audioLoopContexts.delete(i));
289
+ const M = (t.endTime - t.startTime) * c, p = a + M, v = this.startAudioLoop(n.clip, Math.max(0, d) * 1e3, y, c, p * 1e3);
290
290
  this.audioLoops.set(i, v), this.audioLoopContexts.set(i, {
291
- segment: e,
291
+ segment: t,
292
292
  startedAt: this.ctx.currentTime,
293
- segmentRelativeMs: s
293
+ segmentRelativeMs: u
294
294
  });
295
295
  }
296
- syncAudioElement(e, r) {
297
- const i = this.audioKey(e.id), n = this.getOrCreateAudioElementState(i, e), d = r - e.startTime, c = this.normalizePlayRate(e.playRate), s = e.fromTime ?? 0, l = s + d * c, p = Math.max(0, e.endTime - e.startTime) * c, w = s + p, T = Math.max(0, w) / 1e3, h = Number.isFinite(n.el.duration) ? Math.max(0, n.el.duration) : void 0, v = h === void 0 ? T : Math.min(T, h), y = Math.max(0, Math.min(l / 1e3, v)), g = l / 1e3 >= v - 0.01;
296
+ syncAudioElement(t, o) {
297
+ const i = this.audioKey(t.id), n = this.getOrCreateAudioElementState(i, t), a = o - t.startTime, c = this.normalizePlayRate(t.playRate), u = t.fromTime ?? 0, d = u + a * c, h = Math.max(0, t.endTime - t.startTime) * c, w = u + h, M = Math.max(0, w) / 1e3, p = Number.isFinite(n.el.duration) ? Math.max(0, n.el.duration) : void 0, v = p === void 0 ? M : Math.min(M, p), m = Math.max(0, Math.min(d / 1e3, v)), g = d / 1e3 >= v - 0.01;
298
298
  Math.abs(n.el.playbackRate - c) > 1e-3 && (n.el.playbackRate = c);
299
- const R = this.computeSegmentVolume(e, d);
299
+ const R = this.computeSegmentVolume(t, a);
300
300
  Math.abs(n.el.volume - R) > 1e-3 && (n.el.volume = R);
301
- const I = 0.24, E = 500, A = 300, k = -40, K = n.lastTimelineMs, z = n.lastSourceSec, D = K === void 0 ? 0 : r - K;
301
+ const P = 0.24, A = 500, E = 300, b = -40, q = n.lastTimelineMs, D = n.lastSourceSec, z = q === void 0 ? 0 : o - q;
302
302
  let O = !1;
303
- if (K === void 0)
303
+ if (q === void 0)
304
304
  O = !0;
305
- else if (D < k || D > A)
305
+ else if (z < b || z > E)
306
306
  O = !0;
307
- else if (z !== void 0) {
308
- const L = z + D * c / 1e3, W = Math.abs(L - y), j = n.lastSeekTimelineMs === void 0 || r - n.lastSeekTimelineMs >= E;
309
- W > I && j && (O = !0);
307
+ else if (D !== void 0) {
308
+ const F = D + z * c / 1e3, Y = Math.abs(F - m), _ = n.lastSeekTimelineMs === void 0 || o - n.lastSeekTimelineMs >= A;
309
+ Y > P && _ && (O = !0);
310
310
  }
311
- if (O && Math.abs(n.el.currentTime - y) > 0.06)
311
+ if (O && Math.abs(n.el.currentTime - m) > 0.06)
312
312
  try {
313
- n.el.currentTime = y, n.lastSeekTimelineMs = r;
313
+ n.el.currentTime = m, n.lastSeekTimelineMs = o;
314
314
  } catch {
315
315
  }
316
- if (n.lastTimelineMs = r, n.lastSourceSec = y, g) {
316
+ if (n.lastTimelineMs = o, n.lastSourceSec = m, g) {
317
317
  if (!n.el.paused)
318
318
  try {
319
319
  n.el.pause();
@@ -323,59 +323,59 @@ class ot {
323
323
  return;
324
324
  }
325
325
  if (n.el.paused && !n.pendingPlay) {
326
- const L = n.el.play();
327
- L && typeof L.then == "function" && (n.pendingPlay = L.catch(() => {
326
+ const F = n.el.play();
327
+ F && typeof F.then == "function" && (n.pendingPlay = F.catch(() => {
328
328
  }).finally(() => {
329
329
  n.pendingPlay = void 0;
330
330
  }));
331
331
  }
332
332
  }
333
- applyFadeToGain(e, r, i) {
334
- i.gain.value = this.computeSegmentVolume(e, r);
333
+ applyFadeToGain(t, o, i) {
334
+ i.gain.value = this.computeSegmentVolume(t, o);
335
335
  }
336
- startMp4Loop(e, r, i, n) {
337
- let d = !1, c = r, s = 0, l = !0;
338
- const m = Math.round(1e3 / Math.max(i || 30, 1) * 1e3), p = this.getClipSampleRate(e), w = [], T = window.setInterval(async () => {
339
- if (d)
336
+ startMp4Loop(t, o, i, n) {
337
+ let a = !1, c = o, u = 0, d = !0;
338
+ const y = Math.round(1e3 / Math.max(i || 30, 1) * 1e3), h = this.getClipSampleRate(t), w = [], M = window.setInterval(async () => {
339
+ if (a)
340
340
  return;
341
- const { audio: h, state: v } = await e.tick(Math.round(c));
342
- if (c += m, v === "done")
341
+ const { audio: p, state: v } = await t.tick(Math.round(c));
342
+ if (c += y, v === "done")
343
343
  return;
344
- if (l) {
345
- l = !1;
344
+ if (d) {
345
+ d = !1;
346
346
  return;
347
347
  }
348
- (h?.[0]?.length ?? 0) !== 0 && (s = this.playFrames(h, p, s, n, w));
348
+ (p?.[0]?.length ?? 0) !== 0 && (u = this.playFrames(p, h, u, n, w));
349
349
  }, Math.round(1e3 / Math.max(i || 30, 1)));
350
350
  return {
351
351
  sources: w,
352
352
  stop: () => {
353
- d = !0, window.clearInterval(T);
353
+ a = !0, window.clearInterval(M);
354
354
  },
355
- isStopped: () => d
355
+ isStopped: () => a
356
356
  };
357
357
  }
358
- startAudioLoop(e, r, i, n = 1, d) {
359
- let c = !1, s = r, l = 0, m = !1;
360
- const p = this.getClipSampleRate(e), w = [], h = Math.round(1e5 * n), v = async () => {
358
+ startAudioLoop(t, o, i, n = 1, a) {
359
+ let c = !1, u = o, d = 0, y = !1;
360
+ const h = this.getClipSampleRate(t), w = [], p = Math.round(1e5 * n), v = async () => {
361
361
  if (c)
362
362
  return;
363
- if (m || (r > 0 && await e.tick(r), m = !0), s += h, d !== void 0 && s > d) {
363
+ if (y || (o > 0 && await t.tick(o), y = !0), u += p, a !== void 0 && u > a) {
364
364
  c = !0;
365
365
  return;
366
366
  }
367
- const { audio: y, state: g } = await e.tick(s);
367
+ const { audio: m, state: g } = await t.tick(u);
368
368
  if (c)
369
369
  return;
370
370
  if (g === "done") {
371
371
  c = !0;
372
372
  return;
373
373
  }
374
- if ((y?.[0]?.length ?? 0) === 0) {
374
+ if ((m?.[0]?.length ?? 0) === 0) {
375
375
  c = !0;
376
376
  return;
377
377
  }
378
- l = this.playFrames(y, p, l, i, w, n), c || setTimeout(() => v(), 0);
378
+ d = this.playFrames(m, h, d, i, w, n), c || setTimeout(() => v(), 0);
379
379
  };
380
380
  return v(), {
381
381
  sources: w,
@@ -386,714 +386,714 @@ class ot {
386
386
  isStopped: () => c && w.length === 0
387
387
  };
388
388
  }
389
- playFrames(e, r, i, n, d, c = 1) {
390
- const s = Math.max(e.length, 1), l = e[0]?.length ?? 0;
391
- if (l === 0)
389
+ playFrames(t, o, i, n, a, c = 1) {
390
+ const u = Math.max(t.length, 1), d = t[0]?.length ?? 0;
391
+ if (d === 0)
392
392
  return i;
393
- const m = this.ctx.createBuffer(s, l, r);
394
- for (let h = 0; h < s; h++) {
395
- const v = e[h] ?? new Float32Array(l);
396
- m.copyToChannel(new Float32Array(v), h);
393
+ const y = this.ctx.createBuffer(u, d, o);
394
+ for (let p = 0; p < u; p++) {
395
+ const v = t[p] ?? new Float32Array(d);
396
+ y.copyToChannel(new Float32Array(v), p);
397
397
  }
398
- const p = this.ctx.createBufferSource();
399
- p.buffer = m;
398
+ const h = this.ctx.createBufferSource();
399
+ h.buffer = y;
400
400
  const w = Math.max(0.1, c);
401
- p.playbackRate.value = w, p.connect(n);
402
- const T = Math.max(this.ctx.currentTime, i);
403
- if (p.start(T), d) {
404
- d.push(p);
405
- const h = m.duration / w * 1e3;
401
+ h.playbackRate.value = w, h.connect(n);
402
+ const M = Math.max(this.ctx.currentTime, i);
403
+ if (h.start(M), a) {
404
+ a.push(h);
405
+ const p = y.duration / w * 1e3;
406
406
  setTimeout(() => {
407
- const v = d.indexOf(p);
408
- v > -1 && d.splice(v, 1);
409
- }, h + 100);
407
+ const v = a.indexOf(h);
408
+ v > -1 && a.splice(v, 1);
409
+ }, p + 100);
410
410
  }
411
- return T + m.duration / w;
411
+ return M + y.duration / w;
412
412
  }
413
- getOrCreateGain(e, r, i) {
414
- const n = e.get(r);
413
+ getOrCreateGain(t, o, i) {
414
+ const n = t.get(o);
415
415
  if (n)
416
416
  return typeof i == "number" && (n.gain.value = this.normalizeVolume(i)), n;
417
- const d = this.ctx.createGain();
418
- return d.gain.value = this.normalizeVolume(i), d.connect(this.ctx.destination), e.set(r, d), d;
417
+ const a = this.ctx.createGain();
418
+ return a.gain.value = this.normalizeVolume(i), a.connect(this.ctx.destination), t.set(o, a), a;
419
419
  }
420
- getOrCreateAudioElementState(e, r) {
421
- const i = this.audioElements.get(e);
420
+ getOrCreateAudioElementState(t, o) {
421
+ const i = this.audioElements.get(t);
422
422
  if (i)
423
- return i.url !== r.url && (i.el.pause(), i.el.src = r.url, i.el.currentTime = 0, i.url = r.url, i.pendingPlay = void 0, i.lastTimelineMs = void 0, i.lastSourceSec = void 0, i.lastSeekTimelineMs = void 0), i;
424
- const n = new Audio(r.url);
425
- n.preload = "auto", n.loop = !1, n.volume = this.normalizeVolume(r.volume), n.playbackRate = this.normalizePlayRate(r.playRate);
426
- const d = {
427
- segmentId: r.id,
428
- url: r.url,
423
+ return i.url !== o.url && (i.el.pause(), i.el.src = o.url, i.el.currentTime = 0, i.url = o.url, i.pendingPlay = void 0, i.lastTimelineMs = void 0, i.lastSourceSec = void 0, i.lastSeekTimelineMs = void 0), i;
424
+ const n = new Audio(o.url);
425
+ n.preload = "auto", n.loop = !1, n.volume = this.normalizeVolume(o.volume), n.playbackRate = this.normalizePlayRate(o.playRate);
426
+ const a = {
427
+ segmentId: o.id,
428
+ url: o.url,
429
429
  el: n
430
430
  };
431
- return this.audioElements.set(e, d), d;
431
+ return this.audioElements.set(t, a), a;
432
432
  }
433
- destroyAudioElement(e) {
433
+ destroyAudioElement(t) {
434
434
  try {
435
- e.pause();
435
+ t.pause();
436
436
  } catch {
437
437
  }
438
- e.removeAttribute("src");
438
+ t.removeAttribute("src");
439
439
  try {
440
- e.load();
440
+ t.load();
441
441
  } catch {
442
442
  }
443
443
  }
444
- normalizePlayRate(e) {
445
- return typeof e != "number" || !Number.isFinite(e) ? 1 : Math.max(0.1, Math.min(100, e));
444
+ normalizePlayRate(t) {
445
+ return typeof t != "number" || !Number.isFinite(t) ? 1 : Math.max(0.1, Math.min(100, t));
446
446
  }
447
- normalizeVolume(e) {
448
- return typeof e != "number" || !Number.isFinite(e) ? 1 : Math.max(0, Math.min(1, e));
447
+ normalizeVolume(t) {
448
+ return typeof t != "number" || !Number.isFinite(t) ? 1 : Math.max(0, Math.min(1, t));
449
449
  }
450
- computeSegmentVolume(e, r) {
451
- const i = this.normalizeVolume(e.volume), n = Math.max(0, e.endTime - e.startTime), d = Math.max(0, e.fadeInDuration ?? 0), c = Math.max(0, e.fadeOutDuration ?? 0);
452
- let s = 1;
453
- d > 0 && r < d && (s = Math.max(0, r / d));
454
- const l = n - r;
455
- return c > 0 && l < c && (s = Math.min(s, Math.max(0, l / c))), i * s;
450
+ computeSegmentVolume(t, o) {
451
+ const i = this.normalizeVolume(t.volume), n = Math.max(0, t.endTime - t.startTime), a = Math.max(0, t.fadeInDuration ?? 0), c = Math.max(0, t.fadeOutDuration ?? 0);
452
+ let u = 1;
453
+ a > 0 && o < a && (u = Math.max(0, o / a));
454
+ const d = n - o;
455
+ return c > 0 && d < c && (u = Math.min(u, Math.max(0, d / c))), i * u;
456
456
  }
457
- audioKey(e) {
458
- return `audio:${e}`;
457
+ audioKey(t) {
458
+ return `audio:${t}`;
459
459
  }
460
- videoKey(e) {
461
- return `video:${e}`;
460
+ videoKey(t) {
461
+ return `video:${t}`;
462
462
  }
463
- async loadClip(e) {
464
- const r = this.clips.get(e.id);
465
- if (r)
466
- return r;
467
- const i = this.loadingClips.get(e.id);
463
+ async loadClip(t) {
464
+ const o = this.clips.get(t.id);
465
+ if (o)
466
+ return o;
467
+ const i = this.loadingClips.get(t.id);
468
468
  if (i)
469
469
  return i;
470
470
  const n = (async () => {
471
471
  try {
472
- const d = await fetch(e.url);
473
- if (!d.body) {
474
- this.loadingClips.delete(e.id);
472
+ const a = await fetch(t.url);
473
+ if (!a.body) {
474
+ this.loadingClips.delete(t.id);
475
475
  return;
476
476
  }
477
- const c = new je(d.body), s = { clip: c, ready: c.ready };
478
- if (await c.ready, !this.findSegmentInProtocol(e.id)) {
479
- c.destroy(), this.loadingClips.delete(e.id);
477
+ const c = new Tt(a.body), u = { clip: c, ready: c.ready };
478
+ if (await c.ready, !this.findSegmentInProtocol(t.id)) {
479
+ c.destroy(), this.loadingClips.delete(t.id);
480
480
  return;
481
481
  }
482
- return this.clips.set(e.id, s), this.loadingClips.delete(e.id), s;
483
- } catch (d) {
484
- console.error(`[AudioManager] Failed to load audio ${e.url}`, d), this.loadingClips.delete(e.id);
482
+ return this.clips.set(t.id, u), this.loadingClips.delete(t.id), u;
483
+ } catch (a) {
484
+ console.error(`[AudioManager] Failed to load audio ${t.url}`, a), this.loadingClips.delete(t.id);
485
485
  return;
486
486
  }
487
487
  })();
488
- return this.loadingClips.set(e.id, n), n;
488
+ return this.loadingClips.set(t.id, n), n;
489
489
  }
490
- findSegmentInProtocol(e) {
491
- for (const r of this.protocol.tracks)
492
- for (const i of r.children)
493
- if (i.id === e) return !0;
490
+ findSegmentInProtocol(t) {
491
+ for (const o of this.protocol.tracks)
492
+ for (const i of o.children)
493
+ if (i.id === t) return !0;
494
494
  return !1;
495
495
  }
496
- getSegmentVolume(e) {
497
- for (const r of this.protocol.tracks)
498
- for (const i of r.children) {
499
- if (i.id !== e)
496
+ getSegmentVolume(t) {
497
+ for (const o of this.protocol.tracks)
498
+ for (const i of o.children) {
499
+ if (i.id !== t)
500
500
  continue;
501
501
  const n = i.volume;
502
502
  return this.normalizeVolume(n);
503
503
  }
504
504
  return 1;
505
505
  }
506
- getClipSampleRate(e) {
507
- const r = e.meta;
508
- if (!r)
506
+ getClipSampleRate(t) {
507
+ const o = t.meta;
508
+ if (!o)
509
509
  return 48e3;
510
- const i = r.audioSampleRate;
510
+ const i = o.audioSampleRate;
511
511
  if (typeof i == "number" && i > 0)
512
512
  return i;
513
- const n = r.sampleRate;
513
+ const n = o.sampleRate;
514
514
  return typeof n == "number" && n > 0 ? n : 48e3;
515
515
  }
516
516
  }
517
- const it = 100, U = /* @__PURE__ */ new Map();
518
- let rt = it;
519
- function nt(o, e) {
520
- U.delete(o), U.set(o, e);
517
+ const le = 100, $ = /* @__PURE__ */ new Map();
518
+ let de = le;
519
+ function fe(e, t) {
520
+ $.delete(e), $.set(e, t);
521
521
  }
522
- function at() {
523
- for (; U.size > rt; ) {
524
- const [o, e] = U.entries().next().value;
525
- U.delete(o), e.close?.();
522
+ function he() {
523
+ for (; $.size > de; ) {
524
+ const [e, t] = $.entries().next().value;
525
+ $.delete(e), t.close?.();
526
526
  }
527
527
  }
528
- function st(o) {
529
- return o.map((e) => e.content).filter(Boolean).join(`
528
+ function pe(e) {
529
+ return e.map((t) => t.content).filter(Boolean).join(`
530
530
  `);
531
531
  }
532
- function ct(o) {
533
- const e = Array.isArray(o.fontFamily) ? o.fontFamily.join(", ") : o.fontFamily, r = o.fontSize ?? 32, i = o.fontWeight ?? "normal", n = o.fontStyle ?? "normal", d = o.fill ?? "#ffffff", c = o.align ?? "left", s = [
534
- `font-size: ${r}px`,
532
+ function me(e) {
533
+ const t = Array.isArray(e.fontFamily) ? e.fontFamily.join(", ") : e.fontFamily, o = e.fontSize ?? 32, i = e.fontWeight ?? "normal", n = e.fontStyle ?? "normal", a = e.fill ?? "#ffffff", c = e.align ?? "left", u = [
534
+ `font-size: ${o}px`,
535
535
  `font-weight: ${i}`,
536
536
  `font-style: ${n}`,
537
- `color: ${d}`,
537
+ `color: ${a}`,
538
538
  `text-align: ${c}`,
539
539
  "white-space: pre-wrap"
540
540
  ];
541
- if (e && s.push(`font-family: ${e}`), typeof o.letterSpacing == "number" && s.push(`letter-spacing: ${o.letterSpacing}px`), typeof o.leading == "number" && s.push(`line-height: ${o.leading}px`), o.background?.color && s.push(`background: ${o.background.color}`), o.stroke?.color && typeof o.stroke.width == "number" && s.push(`-webkit-text-stroke: ${o.stroke.width}px ${o.stroke.color}`), o.underline && s.push("text-decoration: underline"), o.dropShadow?.color && typeof o.dropShadow.distance == "number") {
542
- const l = (o.dropShadow.angle ?? 45) * (Math.PI / 180), m = Math.cos(l) * o.dropShadow.distance, p = Math.sin(l) * o.dropShadow.distance, w = o.dropShadow.blur ?? 0;
543
- s.push(`text-shadow: ${m}px ${p}px ${w}px ${o.dropShadow.color}`);
541
+ if (t && u.push(`font-family: ${t}`), typeof e.letterSpacing == "number" && u.push(`letter-spacing: ${e.letterSpacing}px`), typeof e.leading == "number" && u.push(`line-height: ${e.leading}px`), e.background?.color && u.push(`background: ${e.background.color}`), e.stroke?.color && typeof e.stroke.width == "number" && u.push(`-webkit-text-stroke: ${e.stroke.width}px ${e.stroke.color}`), e.underline && u.push("text-decoration: underline"), e.dropShadow?.color && typeof e.dropShadow.distance == "number") {
542
+ const d = (e.dropShadow.angle ?? 45) * (Math.PI / 180), y = Math.cos(d) * e.dropShadow.distance, h = Math.sin(d) * e.dropShadow.distance, w = e.dropShadow.blur ?? 0;
543
+ u.push(`text-shadow: ${y}px ${h}px ${w}px ${e.dropShadow.color}`);
544
544
  }
545
- return s.join("; ");
545
+ return u.join("; ");
546
546
  }
547
- async function ut(o, e) {
548
- const r = `${e}::${o}`, i = U.get(r);
547
+ async function ye(e, t) {
548
+ const o = `${t}::${e}`, i = $.get(o);
549
549
  if (i)
550
- return nt(r, i), i;
551
- const n = await _e(o, e);
552
- return U.set(r, n), at(), n;
550
+ return fe(o, i), i;
551
+ const n = await Zt(e, t);
552
+ return $.set(o, n), he(), n;
553
553
  }
554
- const dt = "/video-editor-res";
555
- async function lt(o) {
556
- const e = De(), r = Ke(o.protocol) ? o.protocol : pe(o.protocol), i = pe(
557
- e.verify(ye(he(r)))
558
- ), n = o.app ?? await Xe(o.appOptions), d = new Ye();
559
- n.stage.addChild(d);
560
- const c = Ne({ dir: o.resourceDir }), s = /* @__PURE__ */ new Set(), l = /* @__PURE__ */ new Map(), m = /* @__PURE__ */ new Map(), p = /* @__PURE__ */ new Set(), w = /* @__PURE__ */ new Set(), T = o.videoSourceMode ?? "auto", h = /* @__PURE__ */ new Map(), v = /* @__PURE__ */ new Map(), y = me(0), g = me(!1), R = qe(() => te(i.value)), I = new ot(i.value);
561
- let E, A = 0, k = 0;
562
- async function K(t) {
563
- const u = k, { protocol: a, at: f, layer: M } = t, S = Oe(a, f), x = xe(a, S), b = t.app.renderer.width, C = t.app.renderer.height;
564
- I.sync(f, g.value);
565
- const P = [];
566
- for (const { segment: N } of x) {
567
- if (u !== k)
554
+ const we = "/video-editor-res";
555
+ async function ve(e) {
556
+ const t = Wt(), o = Jt(e.protocol) ? e.protocol : vt(e.protocol), i = vt(
557
+ t.verify(St(Mt(o)))
558
+ ), n = e.app ?? await oe(e.appOptions), a = new ee();
559
+ n.stage.addChild(a);
560
+ const c = Yt({ dir: e.resourceDir }), u = /* @__PURE__ */ new Set(), d = /* @__PURE__ */ new Map(), y = /* @__PURE__ */ new Map(), h = /* @__PURE__ */ new Set(), w = /* @__PURE__ */ new Set(), M = e.videoSourceMode ?? "auto", p = /* @__PURE__ */ new Map(), v = /* @__PURE__ */ new Map(), m = gt(0), g = gt(!1), R = Ht(() => it(i.value)), P = new ue(i.value);
561
+ let A, E = 0, b = 0;
562
+ async function q(r) {
563
+ const l = b, { protocol: s, at: f, layer: S } = r, x = Kt(s, f), T = Rt(s, x), k = r.app.renderer.width, C = r.app.renderer.height;
564
+ P.sync(f, g.value);
565
+ const I = [];
566
+ for (const { segment: N } of T) {
567
+ if (l !== b)
568
568
  return;
569
- const V = await t.getDisplay(N);
570
- if (u !== k)
569
+ const L = await r.getDisplay(N);
570
+ if (l !== b)
571
571
  return;
572
- if (V && !V.destroyed) {
573
- if (Ze(V, N, b, C), Fe(N) && await J(N, S), u !== k)
572
+ if (L && !L.destroyed) {
573
+ if (ae(L, N, k, C), Gt(N) && await H(N, x), l !== b)
574
574
  return;
575
- P.push(V);
575
+ I.push(L);
576
576
  }
577
577
  }
578
- if (u !== k)
578
+ if (l !== b)
579
579
  return;
580
- M.removeChildren();
581
- const F = P.filter(Boolean);
582
- F.length && M.addChild(...F), u === k && t.app.render();
580
+ S.removeChildren();
581
+ const U = I.filter(Boolean);
582
+ U.length && S.addChild(...U), l === b && r.app.render();
583
583
  }
584
- const z = ft(() => K({
584
+ const D = Me(() => q({
585
585
  app: n,
586
- layer: d,
586
+ layer: a,
587
587
  protocol: i.value,
588
- at: y.value,
589
- getDisplay: Re
590
- })), D = Be();
591
- D.run(() => {
592
- Q(
593
- () => he(r),
594
- (t) => {
588
+ at: m.value,
589
+ getDisplay: Lt
590
+ })), z = Qt();
591
+ z.run(() => {
592
+ Z(
593
+ () => Mt(o),
594
+ (r) => {
595
595
  try {
596
- i.value = e.verify(ye(t));
597
- } catch (u) {
598
- console.error("[renderer] invalid protocol update", u);
596
+ i.value = t.verify(St(r));
597
+ } catch (l) {
598
+ console.error("[renderer] invalid protocol update", l);
599
599
  return;
600
600
  }
601
- I.setProtocol(i.value), k += 1, j(), o.warmUpResources !== !1 && L(i.value), W(i.value), O(), o.manualRender || z();
601
+ P.setProtocol(i.value), b += 1, _(), e.warmUpResources !== !1 && F(i.value), Y(i.value), O(), e.manualRender || D();
602
602
  },
603
603
  { deep: !0, immediate: !0 }
604
- ), o.manualRender || Q(y, () => {
605
- O(), z();
606
- }), Q(R, () => O());
604
+ ), e.manualRender || Z(m, () => {
605
+ O(), D();
606
+ }), Z(R, () => O());
607
607
  });
608
608
  function O() {
609
- const t = R.value;
610
- t <= 0 ? y.value = 0 : y.value > t ? y.value = t : y.value < 0 && (y.value = 0);
609
+ const r = R.value;
610
+ r <= 0 ? m.value = 0 : m.value > r ? m.value = r : m.value < 0 && (m.value = 0);
611
611
  }
612
- function L(t) {
613
- for (const u of Qe(t))
614
- s.has(u) || (s.add(u), de(u) !== "video" && se(u) && c.add(u).catch(() => {
612
+ function F(r) {
613
+ for (const l of ne(r))
614
+ u.has(l) || (u.add(l), mt(l) !== "video" && ft(l) && c.add(l).catch(() => {
615
615
  }));
616
616
  }
617
- function W(t) {
618
- const u = /* @__PURE__ */ new Set();
619
- for (const a of t.tracks)
620
- for (const f of a.children)
621
- u.add(f.id);
622
- for (const [a, f] of l)
623
- u.has(a) || (f.destroy(), l.delete(a));
624
- for (const [a, f] of h)
625
- u.has(a) || (ce(f), h.delete(a));
626
- }
627
- function j() {
628
- d.removeChildren();
629
- for (const t of l.values())
630
- t.destroy();
631
- l.clear(), m.clear();
632
- for (const t of h.values())
633
- ce(t);
634
- h.clear();
635
- }
636
- function ie() {
637
- g.value || (g.value = !0, A = performance.now(), E = requestAnimationFrame(re));
638
- }
639
- function Y() {
640
- g.value = !1, E !== void 0 && cancelAnimationFrame(E), E = void 0, I.sync(y.value, !1), o.freezeOnPause !== !1 && Ve();
641
- }
642
- function re() {
643
- ne(), g.value && (E = requestAnimationFrame(re));
644
- }
645
- function ne(t) {
646
- if (!g.value && t === void 0)
617
+ function Y(r) {
618
+ const l = /* @__PURE__ */ new Set();
619
+ for (const s of r.tracks)
620
+ for (const f of s.children)
621
+ l.add(f.id);
622
+ for (const [s, f] of d)
623
+ l.has(s) || (f.destroy(), d.delete(s));
624
+ for (const [s, f] of p)
625
+ l.has(s) || (ht(f), p.delete(s));
626
+ }
627
+ function _() {
628
+ a.removeChildren();
629
+ for (const r of d.values())
630
+ r.destroy();
631
+ d.clear(), y.clear();
632
+ for (const r of p.values())
633
+ ht(r);
634
+ p.clear();
635
+ }
636
+ function ct() {
637
+ g.value || (g.value = !0, E = performance.now(), A = requestAnimationFrame(ut));
638
+ }
639
+ function X() {
640
+ g.value = !1, A !== void 0 && cancelAnimationFrame(A), A = void 0, P.sync(m.value, !1), e.freezeOnPause !== !1 && qt();
641
+ }
642
+ function ut() {
643
+ lt(), g.value && (A = requestAnimationFrame(ut));
644
+ }
645
+ function lt(r) {
646
+ if (!g.value && r === void 0)
647
647
  return;
648
- const u = performance.now(), a = t ?? (A ? u - A : 0);
649
- A = u, a !== 0 && (y.value = ee(
650
- y.value + a,
648
+ const l = performance.now(), s = r ?? (E ? l - E : 0);
649
+ E = l, s !== 0 && (m.value = et(
650
+ m.value + s,
651
651
  0,
652
652
  R.value || Number.POSITIVE_INFINITY
653
- ), R.value > 0 && y.value >= R.value && Y());
654
- }
655
- function ke(t) {
656
- y.value = ee(t, 0, R.value || Number.POSITIVE_INFINITY);
657
- }
658
- async function Ce(t) {
659
- y.value = ee(t, 0, R.value || Number.POSITIVE_INFINITY), await z();
660
- }
661
- async function Re(t) {
662
- const u = l.get(t.id);
663
- if (u)
664
- return u;
665
- const a = m.get(t.id);
666
- if (a)
667
- return a;
668
- const f = Ee(t);
669
- m.set(t.id, f);
670
- const M = await f;
671
- return M && l.set(t.id, M), m.delete(t.id), M;
672
- }
673
- async function Ee(t) {
674
- if (t.segmentType === "frames" || t.segmentType === "sticker") {
675
- if (!t.url)
676
- return Z(t.segmentType);
677
- if ("type" in t && t.type === "video" && le(t.url)) {
678
- const a = await Ie(t);
679
- return a || Z(t.segmentType, t.url);
653
+ ), R.value > 0 && m.value >= R.value && X());
654
+ }
655
+ function Ut(r) {
656
+ m.value = et(r, 0, R.value || Number.POSITIVE_INFINITY);
657
+ }
658
+ async function Ot(r) {
659
+ m.value = et(r, 0, R.value || Number.POSITIVE_INFINITY), await D();
660
+ }
661
+ async function Lt(r) {
662
+ const l = d.get(r.id);
663
+ if (l)
664
+ return l;
665
+ const s = y.get(r.id);
666
+ if (s)
667
+ return s;
668
+ const f = Vt(r);
669
+ y.set(r.id, f);
670
+ const S = await f;
671
+ return S && d.set(r.id, S), y.delete(r.id), S;
672
+ }
673
+ async function Vt(r) {
674
+ if (r.segmentType === "frames" || r.segmentType === "sticker") {
675
+ if (!r.url)
676
+ return tt(r.segmentType);
677
+ if ("type" in r && r.type === "video" && yt(r.url)) {
678
+ const s = await zt(r);
679
+ return s || tt(r.segmentType, r.url);
680
680
  }
681
- const u = await Pe(t.url);
682
- return u ? new $(u) : Z(t.segmentType, t.url);
681
+ const l = await Dt(r.url);
682
+ return l ? new V(l) : tt(r.segmentType, r.url);
683
683
  }
684
- if (t.segmentType === "text")
685
- return await Ae(t);
686
- t.segmentType === "effect" || t.segmentType;
684
+ if (r.segmentType === "text")
685
+ return await $t(r);
686
+ r.segmentType === "effect" || r.segmentType;
687
687
  }
688
- async function Ae(t) {
689
- const u = st(t.texts);
690
- if (!u)
688
+ async function $t(r) {
689
+ const l = pe(r.texts);
690
+ if (!l)
691
691
  return;
692
- const [a] = t.texts;
693
- if (!a)
692
+ const [s] = r.texts;
693
+ if (!s)
694
694
  return;
695
- const f = await ut(u, ct(a)), M = G.from(f);
696
- return new $(M);
695
+ const f = await ye(l, me(s)), S = G.from(f);
696
+ return new V(S);
697
697
  }
698
- async function Pe(t) {
699
- const u = t.startsWith("data:"), a = /^https?:\/\//.test(t);
700
- if (!u && !a)
698
+ async function Dt(r) {
699
+ const l = r.startsWith("data:"), s = /^https?:\/\//.test(r);
700
+ if (!l && !s)
701
701
  try {
702
- await c.add(t);
703
- const f = await c.get(t);
702
+ await c.add(r);
703
+ const f = await c.get(r);
704
704
  if (f instanceof HTMLImageElement)
705
705
  return G.from(f);
706
706
  } catch {
707
707
  }
708
- return await Ue(t);
709
- }
710
- async function Ie(t) {
711
- const u = h.get(t.id);
712
- if (u)
713
- return u.sprite;
714
- const a = _(t.url), f = T !== "element", M = T !== "mp4clip";
715
- if (a && p.has(a)) {
716
- if (!M)
717
- throw new Error(`[renderer] MP4Clip unsupported for ${t.url}`);
718
- const S = await q(t.url).catch((x) => {
719
- console.warn("[renderer] failed to load video via <video>", t.url, x);
708
+ return await jt(r);
709
+ }
710
+ async function zt(r) {
711
+ const l = p.get(r.id);
712
+ if (l)
713
+ return l.sprite;
714
+ const s = W(r.url), f = M !== "element", S = M !== "mp4clip";
715
+ if (s && h.has(s)) {
716
+ if (!S)
717
+ throw new Error(`[renderer] MP4Clip unsupported for ${r.url}`);
718
+ const x = await B(r.url).catch((T) => {
719
+ console.warn("[renderer] failed to load video via <video>", r.url, T);
720
720
  });
721
- return S ? (h.set(t.id, S), S.sprite) : void 0;
721
+ return x ? (p.set(r.id, x), x.sprite) : void 0;
722
722
  }
723
723
  if (f) {
724
- const S = await ue(t.url).catch((x) => {
725
- if (a && X(x) && p.add(a), (!a || !w.has(a)) && (a && w.add(a), console.warn("[renderer] failed to load video via MP4Clip", t.url, x)), !M)
726
- throw x;
724
+ const x = await pt(r.url).catch((T) => {
725
+ if (s && J(T) && h.add(s), (!s || !w.has(s)) && (s && w.add(s), console.warn("[renderer] failed to load video via MP4Clip", r.url, T)), !S)
726
+ throw T;
727
727
  });
728
- if (S)
729
- return console.info("[renderer] video source: mp4clip", t.url), h.set(t.id, S), S.sprite;
728
+ if (x)
729
+ return console.info("[renderer] video source: mp4clip", r.url), p.set(r.id, x), x.sprite;
730
730
  }
731
- if (M) {
732
- const S = await q(t.url).catch((x) => {
733
- console.warn("[renderer] failed to load video via <video>", t.url, x);
731
+ if (S) {
732
+ const x = await B(r.url).catch((T) => {
733
+ console.warn("[renderer] failed to load video via <video>", r.url, T);
734
734
  });
735
- if (S)
736
- return console.info("[renderer] video source: element", t.url), h.set(t.id, S), S.sprite;
735
+ if (x)
736
+ return console.info("[renderer] video source: element", r.url), p.set(r.id, x), x.sprite;
737
737
  }
738
738
  }
739
- function X(t) {
740
- if (!(t instanceof Error))
739
+ function J(r) {
740
+ if (!(r instanceof Error))
741
741
  return !1;
742
- const u = t.message || "";
743
- return u.includes("stream is done") || u.includes("not emit ready") || u.includes("tick video timeout");
742
+ const l = r.message || "";
743
+ return l.includes("stream is done") || l.includes("not emit ready") || l.includes("tick video timeout");
744
744
  }
745
- async function J(t, u) {
746
- const a = h.get(t.id);
747
- if (a)
745
+ async function H(r, l) {
746
+ const s = p.get(r.id);
747
+ if (s)
748
748
  try {
749
- const f = t.fromTime ?? 0, M = Math.max(0, u - t.startTime + f), S = Math.floor(M * 1e3);
750
- if (a.kind === "frozen") {
751
- const b = _(t.url);
752
- if (!b)
749
+ const f = r.fromTime ?? 0, S = Math.max(0, l - r.startTime + f), x = Math.floor(S * 1e3);
750
+ if (s.kind === "frozen") {
751
+ const k = W(r.url);
752
+ if (!k)
753
753
  return;
754
- const C = await Le(t.url, b, { sprite: a.sprite, oldTexture: a.texture });
755
- return C ? (h.set(t.id, C), await J(t, u)) : void 0;
754
+ const C = await Nt(r.url, k, { sprite: s.sprite, oldTexture: s.texture });
755
+ return C ? (p.set(r.id, C), await H(r, l)) : void 0;
756
756
  }
757
- if (a.kind === "mp4clip")
757
+ if (s.kind === "mp4clip")
758
758
  try {
759
- const b = await a.clip.tick(S);
760
- if (b.video) {
761
- const C = a.canvas.getContext("2d");
762
- C && (C.drawImage(b.video, 0, 0, a.canvas.width, a.canvas.height), fe(a.texture)), b.video.close();
759
+ const k = await s.clip.tick(x);
760
+ if (k.video) {
761
+ const C = s.canvas.getContext("2d");
762
+ C && (C.drawImage(k.video, 0, 0, s.canvas.width, s.canvas.height), wt(s.texture)), k.video.close();
763
763
  }
764
- if (g.value && b.audio && b.audio.length > 0) {
765
- const C = a.clip.meta?.audioSampleRate ?? 48e3;
766
- I.playMp4AudioFrames(t.id, b.audio, C);
764
+ if (g.value && k.audio && k.audio.length > 0) {
765
+ const C = s.clip.meta?.audioSampleRate ?? 48e3;
766
+ P.playMp4AudioFrames(r.id, k.audio, C);
767
767
  }
768
768
  return;
769
- } catch (b) {
770
- const C = _(t.url);
771
- if (C && X(b) && (p.add(C), a.clip.destroy(), T !== "mp4clip")) {
772
- const P = await q(t.url, { sprite: a.sprite, oldTexture: a.texture }).catch((F) => {
773
- console.warn("[renderer] failed to fallback to <video> after MP4Clip error", t.url, F);
769
+ } catch (k) {
770
+ const C = W(r.url);
771
+ if (C && J(k) && (h.add(C), s.clip.destroy(), M !== "mp4clip")) {
772
+ const I = await B(r.url, { sprite: s.sprite, oldTexture: s.texture }).catch((U) => {
773
+ console.warn("[renderer] failed to fallback to <video> after MP4Clip error", r.url, U);
774
774
  });
775
- if (P)
776
- return h.set(t.id, P), await J(t, u);
775
+ if (I)
776
+ return p.set(r.id, I), await H(r, l);
777
777
  }
778
- C && !w.has(C) && (w.add(C), console.warn("[renderer] MP4Clip tick failed", t.url, b));
778
+ C && !w.has(C) && (w.add(C), console.warn("[renderer] MP4Clip tick failed", r.url, k));
779
779
  return;
780
780
  }
781
- const x = M / 1e3;
782
- if (!Number.isFinite(x) || a.kind !== "element")
781
+ const T = S / 1e3;
782
+ if (!Number.isFinite(T) || s.kind !== "element")
783
783
  return;
784
- await $e(a, {
785
- targetSec: x,
786
- playbackRate: t.playRate ?? 1,
787
- volume: t.volume ?? 1
784
+ await Bt(s, {
785
+ targetSec: T,
786
+ playbackRate: r.playRate ?? 1,
787
+ volume: r.volume ?? 1
788
788
  });
789
789
  } catch (f) {
790
790
  console.warn("[renderer] update video frame failed", f);
791
791
  }
792
792
  }
793
- async function Le(t, u, a) {
794
- const f = T !== "element", M = T !== "mp4clip";
795
- if (p.has(u)) {
796
- if (!M)
797
- throw new Error(`[renderer] MP4Clip unsupported for ${t}`);
798
- return await q(t, a).catch(() => {
793
+ async function Nt(r, l, s) {
794
+ const f = M !== "element", S = M !== "mp4clip";
795
+ if (h.has(l)) {
796
+ if (!S)
797
+ throw new Error(`[renderer] MP4Clip unsupported for ${r}`);
798
+ return await B(r, s).catch(() => {
799
799
  });
800
800
  }
801
801
  if (f) {
802
- const S = await ue(t, a).catch((x) => {
803
- if (X(x) && p.add(u), !M)
804
- throw x;
802
+ const x = await pt(r, s).catch((T) => {
803
+ if (J(T) && h.add(l), !S)
804
+ throw T;
805
805
  });
806
- if (S)
807
- return S;
806
+ if (x)
807
+ return x;
808
808
  }
809
- if (M)
810
- return await q(t, a).catch(() => {
809
+ if (S)
810
+ return await B(r, s).catch(() => {
811
811
  });
812
812
  }
813
- function Fe(t) {
814
- return t.segmentType === "frames" && t.type === "video" && typeof t.url == "string" && le(t.url);
813
+ function Gt(r) {
814
+ return r.segmentType === "frames" && r.type === "video" && typeof r.url == "string" && yt(r.url);
815
815
  }
816
- function Oe(t, u) {
817
- const a = te(t);
818
- if (a <= 0)
816
+ function Kt(r, l) {
817
+ const s = it(r);
818
+ if (s <= 0)
819
819
  return 0;
820
- if (u < a)
821
- return u;
822
- const f = Math.max(1e3 / Math.max(t.fps || 30, 1), 1);
823
- return Math.max(a - f, 0);
820
+ if (l < s)
821
+ return l;
822
+ const f = Math.max(1e3 / Math.max(r.fps || 30, 1), 1);
823
+ return Math.max(s - f, 0);
824
824
  }
825
- async function ae(t) {
826
- const u = o.resourceDir ?? dt;
825
+ async function dt(r) {
826
+ const l = e.resourceDir ?? we;
827
827
  try {
828
- const a = _(t);
829
- if (!a)
828
+ const s = W(r);
829
+ if (!s)
830
830
  return;
831
- const f = We(`${u}/${a}`, "r");
831
+ const f = te(`${l}/${s}`, "r");
832
832
  if (await f.exists())
833
833
  return f;
834
834
  } catch {
835
835
  return;
836
836
  }
837
837
  }
838
- function se(t) {
839
- return !(!t || t.startsWith("data:") || t.startsWith("blob:"));
838
+ function ft(r) {
839
+ return !(!r || r.startsWith("data:") || r.startsWith("blob:"));
840
840
  }
841
- function Ve() {
842
- for (const [t, u] of h) {
843
- if (u.kind === "mp4clip") {
844
- u.clip.destroy(), h.set(t, {
841
+ function qt() {
842
+ for (const [r, l] of p) {
843
+ if (l.kind === "mp4clip") {
844
+ l.clip.destroy(), p.set(r, {
845
845
  kind: "frozen",
846
- canvas: u.canvas,
847
- texture: u.texture,
848
- sprite: u.sprite,
849
- meta: u.meta
846
+ canvas: l.canvas,
847
+ texture: l.texture,
848
+ sprite: l.sprite,
849
+ meta: l.meta
850
850
  });
851
851
  continue;
852
852
  }
853
- u.kind === "element" && u.video.pause();
853
+ l.kind === "element" && l.video.pause();
854
854
  }
855
855
  }
856
- function ce(t) {
857
- if (t.kind === "mp4clip") {
858
- t.clip.destroy();
856
+ function ht(r) {
857
+ if (r.kind === "mp4clip") {
858
+ r.clip.destroy();
859
859
  return;
860
860
  }
861
- if (t.kind === "frozen")
861
+ if (r.kind === "frozen")
862
862
  return;
863
- t.video.pause();
864
- const u = v.get(t.video);
865
- u && (URL.revokeObjectURL(u), v.delete(t.video)), t.video.removeAttribute("src"), t.video.load();
866
- }
867
- function H(t, u, a = 1e3) {
868
- return new Promise((f, M) => {
869
- const S = window.setTimeout(() => {
870
- C(), M(new Error(`Timed out waiting for media event: ${u}`));
871
- }, a), x = () => {
863
+ r.video.pause();
864
+ const l = v.get(r.video);
865
+ l && (URL.revokeObjectURL(l), v.delete(r.video)), r.video.removeAttribute("src"), r.video.load();
866
+ }
867
+ function Q(r, l, s = 1e3) {
868
+ return new Promise((f, S) => {
869
+ const x = window.setTimeout(() => {
870
+ C(), S(new Error(`Timed out waiting for media event: ${l}`));
871
+ }, s), T = () => {
872
872
  C(), f();
873
- }, b = () => {
873
+ }, k = () => {
874
874
  C();
875
- const P = t.error ? `${t.error.code}` : "unknown";
876
- M(new Error(`Media error (${P}) while waiting for ${u}`));
875
+ const I = r.error ? `${r.error.code}` : "unknown";
876
+ S(new Error(`Media error (${I}) while waiting for ${l}`));
877
877
  }, C = () => {
878
- window.clearTimeout(S), t.removeEventListener(u, x), t.removeEventListener("error", b);
878
+ window.clearTimeout(x), r.removeEventListener(l, T), r.removeEventListener("error", k);
879
879
  };
880
- t.addEventListener(u, x, { once: !0 }), t.addEventListener("error", b, { once: !0 });
880
+ r.addEventListener(l, T, { once: !0 }), r.addEventListener("error", k, { once: !0 });
881
881
  });
882
882
  }
883
- async function ue(t, u) {
884
- let a;
885
- se(t) && (a = await ae(t), a || (await c.add(t).catch(() => {
886
- }), a = await ae(t)));
883
+ async function pt(r, l) {
884
+ let s;
885
+ ft(r) && (s = await dt(r), s || (await c.add(r).catch(() => {
886
+ }), s = await dt(r)));
887
887
  let f;
888
888
  try {
889
- if (a)
890
- f = new B(a);
889
+ if (s)
890
+ f = new K(s);
891
891
  else {
892
- const P = await fetch(t);
893
- if (P.body)
894
- f = new B(P.body);
892
+ const I = await fetch(r);
893
+ if (I.body)
894
+ f = new K(I.body);
895
895
  else {
896
- const F = await P.arrayBuffer(), N = new ReadableStream({
897
- start(V) {
898
- V.enqueue(new Uint8Array(F)), V.close();
896
+ const U = await I.arrayBuffer(), N = new ReadableStream({
897
+ start(L) {
898
+ L.enqueue(new Uint8Array(U)), L.close();
899
899
  }
900
900
  });
901
- f = new B(N);
901
+ f = new K(N);
902
902
  }
903
903
  }
904
904
  await f.ready;
905
- const { width: M, height: S } = f.meta, x = document.createElement("canvas");
906
- x.width = M || 1, x.height = S || 1;
907
- const b = G.from(x), C = u?.sprite ?? new $(b);
908
- return u?.sprite && (u.sprite.texture = b, u.oldTexture?.destroy(!0)), { kind: "mp4clip", clip: f, canvas: x, texture: b, sprite: C, meta: { width: M, height: S } };
909
- } catch (M) {
910
- throw f?.destroy(), M;
905
+ const { width: S, height: x } = f.meta, T = document.createElement("canvas");
906
+ T.width = S || 1, T.height = x || 1;
907
+ const k = G.from(T), C = l?.sprite ?? new V(k);
908
+ return l?.sprite && (l.sprite.texture = k, l.oldTexture?.destroy(!0)), { kind: "mp4clip", clip: f, canvas: T, texture: k, sprite: C, meta: { width: S, height: x } };
909
+ } catch (S) {
910
+ throw f?.destroy(), S;
911
911
  }
912
912
  }
913
- function de(t) {
914
- const a = t.split("#")[0].split("?")[0].split("/").pop()?.split(".").pop()?.toLowerCase() ?? "";
915
- return ["mp4", "m4v", "mov", "webm"].includes(a) ? "video" : ["png", "jpg", "jpeg", "gif", "webp", "bmp", "svg", "avif"].includes(a) ? "image" : ["mp3", "wav", "aac", "m4a", "ogg", "flac"].includes(a) ? "audio" : "unknown";
913
+ function mt(r) {
914
+ const s = r.split("#")[0].split("?")[0].split("/").pop()?.split(".").pop()?.toLowerCase() ?? "";
915
+ return ["mp4", "m4v", "mov", "webm"].includes(s) ? "video" : ["png", "jpg", "jpeg", "gif", "webp", "bmp", "svg", "avif"].includes(s) ? "image" : ["mp3", "wav", "aac", "m4a", "ogg", "flac"].includes(s) ? "audio" : "unknown";
916
916
  }
917
- function le(t) {
918
- const u = de(t);
919
- return !(u === "image" || u === "audio");
917
+ function yt(r) {
918
+ const l = mt(r);
919
+ return !(l === "image" || l === "audio");
920
920
  }
921
- async function q(t, u) {
922
- const a = document.createElement("video");
923
- a.crossOrigin = "anonymous", a.muted = !1, a.playsInline = !0, a.preload = "metadata", a.src = t, a.load();
921
+ async function B(r, l) {
922
+ const s = document.createElement("video");
923
+ s.crossOrigin = "anonymous", s.muted = !1, s.playsInline = !0, s.preload = "metadata", s.src = r, s.load();
924
924
  try {
925
- await H(a, "loadedmetadata", 15e3);
925
+ await Q(s, "loadedmetadata", 15e3);
926
926
  } catch (C) {
927
- a.pause();
928
- const P = v.get(a);
929
- throw P && (URL.revokeObjectURL(P), v.delete(a)), a.removeAttribute("src"), a.load(), C;
927
+ s.pause();
928
+ const I = v.get(s);
929
+ throw I && (URL.revokeObjectURL(I), v.delete(s)), s.removeAttribute("src"), s.load(), C;
930
930
  }
931
- const f = a.videoWidth || 1, M = a.videoHeight || 1, S = document.createElement("canvas");
932
- S.width = f, S.height = M;
933
- const x = G.from(S), b = u?.sprite ?? new $(x);
934
- return u?.sprite && (u.sprite.texture = x, u.oldTexture?.destroy(!0)), { kind: "element", video: a, canvas: S, texture: x, sprite: b, meta: { width: f, height: M } };
935
- }
936
- async function $e(t, u) {
937
- const { video: a, canvas: f, texture: M } = t;
938
- a.playbackRate = Number.isFinite(u.playbackRate) && u.playbackRate > 0 ? u.playbackRate : 1, a.volume = Math.max(0, Math.min(1, u.volume ?? 1)), g.value ? a.play().catch(() => {
939
- }) : a.pause();
940
- const S = Number.isFinite(a.duration) && a.duration > 0 ? a.duration : null, x = S ? Math.min(u.targetSec, Math.max(S - 0.03, 0)) : u.targetSec, b = a.currentTime, C = Math.abs(b - x), P = g.value ? 0.25 : 0.03;
941
- if (Number.isFinite(b) && C > P) {
931
+ const f = s.videoWidth || 1, S = s.videoHeight || 1, x = document.createElement("canvas");
932
+ x.width = f, x.height = S;
933
+ const T = G.from(x), k = l?.sprite ?? new V(T);
934
+ return l?.sprite && (l.sprite.texture = T, l.oldTexture?.destroy(!0)), { kind: "element", video: s, canvas: x, texture: T, sprite: k, meta: { width: f, height: S } };
935
+ }
936
+ async function Bt(r, l) {
937
+ const { video: s, canvas: f, texture: S } = r;
938
+ s.playbackRate = Number.isFinite(l.playbackRate) && l.playbackRate > 0 ? l.playbackRate : 1, s.volume = Math.max(0, Math.min(1, l.volume ?? 1)), g.value ? s.play().catch(() => {
939
+ }) : s.pause();
940
+ const x = Number.isFinite(s.duration) && s.duration > 0 ? s.duration : null, T = x ? Math.min(l.targetSec, Math.max(x - 0.03, 0)) : l.targetSec, k = s.currentTime, C = Math.abs(k - T), I = g.value ? 0.25 : 0.03;
941
+ if (Number.isFinite(k) && C > I) {
942
942
  try {
943
- a.currentTime = x;
943
+ s.currentTime = T;
944
944
  } catch {
945
945
  }
946
- await H(a, "seeked", 250).catch(() => {
946
+ await Q(s, "seeked", 250).catch(() => {
947
947
  });
948
948
  }
949
- if (a.readyState < 2 && (await H(a, "canplay", 250).catch(() => {
950
- }), a.readyState < 2))
949
+ if (s.readyState < 2 && (await Q(s, "canplay", 250).catch(() => {
950
+ }), s.readyState < 2))
951
951
  return;
952
- const F = f.getContext("2d");
953
- F && (F.drawImage(a, 0, 0, f.width, f.height), fe(M));
954
- }
955
- function Ue(t) {
956
- return new Promise((u) => {
957
- const a = new Image();
958
- a.crossOrigin = "anonymous", a.onload = () => u(G.from(a)), a.onerror = () => {
959
- console.warn("[renderer] failed to load image", t), u(void 0);
960
- }, a.src = t;
952
+ const U = f.getContext("2d");
953
+ U && (U.drawImage(s, 0, 0, f.width, f.height), wt(S));
954
+ }
955
+ function jt(r) {
956
+ return new Promise((l) => {
957
+ const s = new Image();
958
+ s.crossOrigin = "anonymous", s.onload = () => l(G.from(s)), s.onerror = () => {
959
+ console.warn("[renderer] failed to load image", r), l(void 0);
960
+ }, s.src = r;
961
961
  });
962
962
  }
963
- function fe(t) {
964
- const u = t.source;
965
- if ("update" in u && typeof u.update == "function") {
966
- u.update();
963
+ function wt(r) {
964
+ const l = r.source;
965
+ if ("update" in l && typeof l.update == "function") {
966
+ l.update();
967
967
  return;
968
968
  }
969
- typeof t.update == "function" && t.update();
969
+ typeof r.update == "function" && r.update();
970
970
  }
971
- function ze() {
972
- Y(), k += 1, D.stop(), j(), d.destroy({ children: !0 }), l.clear(), m.clear(), s.clear(), o.app || n.destroy(), I.destroy();
971
+ function _t() {
972
+ X(), b += 1, z.stop(), _(), a.destroy({ children: !0 }), d.clear(), y.clear(), u.clear(), e.app || n.destroy(), P.destroy();
973
973
  }
974
- return o.autoPlay && ie(), {
974
+ return e.autoPlay && ct(), {
975
975
  app: n,
976
- layer: d,
977
- currentTime: y,
976
+ layer: a,
977
+ currentTime: m,
978
978
  duration: R,
979
979
  isPlaying: g,
980
- play: ie,
981
- pause: Y,
982
- tick: ne,
983
- seek: ke,
984
- renderAt: Ce,
985
- destroy: ze
980
+ play: ct,
981
+ pause: X,
982
+ tick: lt,
983
+ seek: Ut,
984
+ renderAt: Ot,
985
+ destroy: _t
986
986
  };
987
987
  }
988
- function ft(o) {
989
- let e = !1, r = !1, i = null, n = null;
988
+ function Me(e) {
989
+ let t = !1, o = !1, i = null, n = null;
990
990
  return async () => {
991
- i || (i = new Promise((s) => {
992
- n = s;
991
+ i || (i = new Promise((u) => {
992
+ n = u;
993
993
  }));
994
994
  const c = i;
995
- if (r)
996
- return e = !0, c;
997
- r = !0;
995
+ if (o)
996
+ return t = !0, c;
997
+ o = !0;
998
998
  do
999
- e = !1, await o();
1000
- while (e);
1001
- return r = !1, n?.(), i = null, n = null, c;
999
+ t = !1, await e();
1000
+ while (t);
1001
+ return o = !1, n?.(), i = null, n = null, c;
1002
1002
  };
1003
1003
  }
1004
- function pt(o) {
1005
- return typeof o == "object" && o !== null && "createReader" in o && "getSize" in o;
1004
+ function ge(e) {
1005
+ return typeof e == "object" && e !== null && "createReader" in e && "getSize" in e;
1006
1006
  }
1007
- function ht(o) {
1008
- return typeof ReadableStream < "u" && o instanceof ReadableStream;
1007
+ function Se(e) {
1008
+ return typeof ReadableStream < "u" && e instanceof ReadableStream;
1009
1009
  }
1010
- function mt(o) {
1011
- return typeof o == "string" || o instanceof Blob || pt(o) || ht(o) ? { source: o } : o;
1010
+ function xe(e) {
1011
+ return typeof e == "string" || e instanceof Blob || ge(e) || Se(e) ? { source: e } : e;
1012
1012
  }
1013
- async function we(o) {
1014
- if (typeof o == "string") {
1015
- const e = await fetch(o);
1016
- if (!e.body)
1013
+ async function xt(e) {
1014
+ if (typeof e == "string") {
1015
+ const t = await fetch(e);
1016
+ if (!t.body)
1017
1017
  throw new Error("concatVideos: unable to read video stream from url");
1018
- return e.body;
1018
+ return t.body;
1019
1019
  }
1020
- return o instanceof Blob ? o.stream() : o;
1020
+ return e instanceof Blob ? e.stream() : e;
1021
1021
  }
1022
- function yt(o, e) {
1023
- let r = !1;
1022
+ function Te(e, t) {
1023
+ let o = !1;
1024
1024
  const i = () => {
1025
- r || (r = !0, e());
1026
- }, n = o.getReader();
1025
+ o || (o = !0, t());
1026
+ }, n = e.getReader();
1027
1027
  return new ReadableStream({
1028
- async pull(d) {
1029
- const { done: c, value: s } = await n.read();
1028
+ async pull(a) {
1029
+ const { done: c, value: u } = await n.read();
1030
1030
  if (c) {
1031
- i(), d.close();
1031
+ i(), a.close();
1032
1032
  return;
1033
1033
  }
1034
- d.enqueue(s);
1034
+ a.enqueue(u);
1035
1035
  },
1036
- async cancel(d) {
1036
+ async cancel(a) {
1037
1037
  try {
1038
- await n.cancel(d);
1038
+ await n.cancel(a);
1039
1039
  } finally {
1040
1040
  i();
1041
1041
  }
1042
1042
  }
1043
1043
  });
1044
1044
  }
1045
- async function Tt(o, e = {}) {
1046
- if (o.length === 0)
1045
+ async function Ne(e, t = {}) {
1046
+ if (e.length === 0)
1047
1047
  throw new Error("concatVideos: expected at least one source");
1048
1048
  const {
1049
- onProgress: r,
1049
+ onProgress: o,
1050
1050
  width: i,
1051
1051
  height: n,
1052
- ...d
1053
- } = e, c = o.map(mt), [s, ...l] = c, m = await we(s.source), p = new B(m);
1054
- await p.ready;
1055
- const w = i ?? Math.round(p.meta.width || 0), T = n ?? Math.round(p.meta.height || 0);
1056
- if (!w || !T)
1057
- throw p.destroy(), new Error("concatVideos: output width/height is required");
1058
- const h = new ve({
1059
- ...d,
1052
+ ...a
1053
+ } = t, c = e.map(xe), [u, ...d] = c, y = await xt(u.source), h = new K(y);
1054
+ await h.ready;
1055
+ const w = i ?? Math.round(h.meta.width || 0), M = n ?? Math.round(h.meta.height || 0);
1056
+ if (!w || !M)
1057
+ throw h.destroy(), new Error("concatVideos: output width/height is required");
1058
+ const p = new bt({
1059
+ ...a,
1060
1060
  width: w,
1061
- height: T
1061
+ height: M
1062
1062
  });
1063
- r && h.on("OutputProgress", r);
1063
+ o && p.on("OutputProgress", o);
1064
1064
  let v = 0;
1065
- const y = async (E) => {
1066
- const A = E.meta.duration;
1067
- if (!Number.isFinite(A) || A <= 0)
1068
- throw E.destroy(), new Error("concatVideos: invalid clip duration");
1069
- const k = new Me(E);
1065
+ const m = async (A) => {
1066
+ const E = A.meta.duration;
1067
+ if (!Number.isFinite(E) || E <= 0)
1068
+ throw A.destroy(), new Error("concatVideos: invalid clip duration");
1069
+ const b = new nt(A);
1070
1070
  try {
1071
- await k.ready, k.rect.x = 0, k.rect.y = 0, k.rect.w = w, k.rect.h = T, k.time.offset = v, k.time.duration = A, await h.addSprite(k), v += A;
1071
+ await b.ready, b.rect.x = 0, b.rect.y = 0, b.rect.w = w, b.rect.h = M, b.time.offset = v, b.time.duration = E, await p.addSprite(b), v += E;
1072
1072
  } finally {
1073
- k.destroy();
1073
+ b.destroy();
1074
1074
  }
1075
1075
  };
1076
1076
  try {
1077
- await y(p);
1078
- for (const E of l) {
1079
- const A = await we(E.source), k = new B(A);
1080
- await k.ready, await y(k);
1077
+ await m(h);
1078
+ for (const A of d) {
1079
+ const E = await xt(A.source), b = new K(E);
1080
+ await b.ready, await m(b);
1081
1081
  }
1082
- } catch (E) {
1083
- throw h.destroy(), E;
1082
+ } catch (A) {
1083
+ throw p.destroy(), A;
1084
1084
  }
1085
- const g = v, R = h.output({ maxTime: g }), I = () => {
1086
- h.destroy();
1085
+ const g = v, R = p.output({ maxTime: g }), P = () => {
1086
+ p.destroy();
1087
1087
  };
1088
1088
  return {
1089
- stream: yt(R, I),
1089
+ stream: Te(R, P),
1090
1090
  width: w,
1091
- height: T,
1091
+ height: M,
1092
1092
  durationMs: Math.round(g / 1e3),
1093
- destroy: I
1093
+ destroy: P
1094
1094
  };
1095
1095
  }
1096
- class oe {
1096
+ class at {
1097
1097
  ready;
1098
1098
  meta;
1099
1099
  protocol;
@@ -1101,27 +1101,27 @@ class oe {
1101
1101
  renderer;
1102
1102
  app;
1103
1103
  destroyed = !1;
1104
- constructor(e, r = {}) {
1105
- this.protocol = e, this.options = r;
1106
- const i = r.width ?? e.width, n = r.height ?? e.height, d = te(e);
1104
+ constructor(t, o = {}) {
1105
+ this.protocol = t, this.options = o;
1106
+ const i = o.width ?? t.width, n = o.height ?? t.height, a = it(t);
1107
1107
  this.meta = {
1108
1108
  width: i,
1109
1109
  height: n,
1110
- duration: Math.max(0, Math.round(d * 1e3))
1110
+ duration: Math.max(0, Math.round(a * 1e3))
1111
1111
  }, this.ready = this.init();
1112
1112
  }
1113
1113
  async init() {
1114
- const e = this.options.width ?? this.protocol.width, r = this.options.height ?? this.protocol.height;
1115
- if (!e || !r)
1114
+ const t = this.options.width ?? this.protocol.width, o = this.options.height ?? this.protocol.height;
1115
+ if (!t || !o)
1116
1116
  throw new Error("ProtocolVideoClip: output width/height is required");
1117
- const i = new Se();
1117
+ const i = new kt();
1118
1118
  await i.init({
1119
- width: e,
1120
- height: r,
1119
+ width: t,
1120
+ height: o,
1121
1121
  backgroundAlpha: 0,
1122
1122
  ...this.options.appOptions
1123
1123
  }), i.ticker.stop(), this.app = i;
1124
- const n = this.options.rendererOptions ?? {}, d = await lt({
1124
+ const n = this.options.rendererOptions ?? {}, a = await ve({
1125
1125
  protocol: this.protocol,
1126
1126
  app: i,
1127
1127
  ...n,
@@ -1130,120 +1130,285 @@ class oe {
1130
1130
  manualRender: !0,
1131
1131
  videoSourceMode: n.videoSourceMode ?? "mp4clip"
1132
1132
  });
1133
- this.renderer = d;
1134
- const c = d.duration.value;
1133
+ this.renderer = a;
1134
+ const c = a.duration.value;
1135
1135
  return this.meta = {
1136
1136
  width: i.renderer.width,
1137
1137
  height: i.renderer.height,
1138
1138
  duration: Math.max(0, Math.round(c * 1e3))
1139
1139
  }, this.meta;
1140
1140
  }
1141
- async tick(e) {
1142
- const r = [];
1141
+ async tick(t) {
1142
+ const o = [];
1143
1143
  if (this.destroyed)
1144
- return { audio: r, state: "done" };
1144
+ return { audio: o, state: "done" };
1145
1145
  if (await this.ready, !this.renderer)
1146
- return { audio: r, state: "done" };
1146
+ return { audio: o, state: "done" };
1147
1147
  const i = this.meta.duration;
1148
- if (e >= i)
1149
- return { audio: r, state: "done" };
1150
- const n = Math.max(0, Math.min(e, i));
1148
+ if (t >= i)
1149
+ return { audio: o, state: "done" };
1150
+ const n = Math.max(0, Math.min(t, i));
1151
1151
  return await this.renderer.renderAt(n / 1e3), {
1152
1152
  video: new VideoFrame(this.renderer.app.canvas, {
1153
- timestamp: e
1153
+ timestamp: t
1154
1154
  }),
1155
- audio: r,
1155
+ audio: o,
1156
1156
  state: "success"
1157
1157
  };
1158
1158
  }
1159
1159
  async clone() {
1160
- const e = new oe(this.protocol, this.options);
1161
- return await e.ready, e;
1160
+ const t = new at(this.protocol, this.options);
1161
+ return await t.ready, t;
1162
1162
  }
1163
1163
  destroy() {
1164
1164
  this.destroyed || (this.destroyed = !0, this.renderer?.destroy(), this.app?.destroy(!0));
1165
1165
  }
1166
1166
  }
1167
- function wt(o, e) {
1168
- let r = !1;
1167
+ const It = 12e3;
1168
+ function be(e, t, o) {
1169
+ return new Promise((i, n) => {
1170
+ const a = globalThis.setTimeout(() => {
1171
+ n(new Error(`composeProtocol: ${o} timed out (${t}ms)`));
1172
+ }, t);
1173
+ e.then((c) => {
1174
+ globalThis.clearTimeout(a), i(c);
1175
+ }).catch((c) => {
1176
+ globalThis.clearTimeout(a), n(c);
1177
+ });
1178
+ });
1179
+ }
1180
+ class st {
1181
+ constructor(t, o) {
1182
+ this.sourceClip = t, this.config = o, this.ready = this.sourceClip.ready.then((i) => {
1183
+ const n = Math.round(this.config.segmentDurationUs * this.config.playRate), a = Math.max(0, i.duration - this.config.fromUs);
1184
+ return this.clipMeta = {
1185
+ width: i.width,
1186
+ height: i.height,
1187
+ duration: Math.max(0, Math.min(n, a))
1188
+ }, this.meta;
1189
+ });
1190
+ }
1191
+ ready;
1192
+ clipMeta = {
1193
+ width: 0,
1194
+ height: 0,
1195
+ duration: 0
1196
+ };
1197
+ get meta() {
1198
+ return { ...this.clipMeta };
1199
+ }
1200
+ async tick(t) {
1201
+ const o = Math.max(0, Math.round(t)), i = Math.round(o / this.config.playRate);
1202
+ if (i >= this.config.segmentDurationUs)
1203
+ return {
1204
+ audio: [],
1205
+ state: "done"
1206
+ };
1207
+ const n = this.config.fromUs + o, a = await this.sourceClip.tick(n);
1208
+ ke(a.video);
1209
+ const c = this.resolveGain(i);
1210
+ return {
1211
+ audio: Ce(a.audio ?? [], c),
1212
+ state: a.state
1213
+ };
1214
+ }
1215
+ async clone() {
1216
+ const t = await this.sourceClip.clone(), o = new st(t, this.config);
1217
+ return await o.ready, o;
1218
+ }
1219
+ destroy() {
1220
+ this.sourceClip.destroy();
1221
+ }
1222
+ resolveGain(t) {
1223
+ let o = 1;
1224
+ this.config.fadeInUs > 0 && t < this.config.fadeInUs && (o = Math.max(0, t / this.config.fadeInUs));
1225
+ const i = this.config.segmentDurationUs - t;
1226
+ return this.config.fadeOutUs > 0 && i < this.config.fadeOutUs && (o = Math.min(o, Math.max(0, i / this.config.fadeOutUs))), this.config.baseVolume * o;
1227
+ }
1228
+ }
1229
+ function ke(e) {
1230
+ if (!e || typeof e != "object")
1231
+ return;
1232
+ const t = e.close;
1233
+ typeof t == "function" && t.call(e);
1234
+ }
1235
+ function Ce(e, t) {
1236
+ return !e.length || t >= 0.999 ? e : t <= 0 ? e.map((o) => new Float32Array(o.length)) : e.map((o) => {
1237
+ const i = new Float32Array(o.length);
1238
+ for (let n = 0; n < o.length; n++)
1239
+ i[n] = o[n] * t;
1240
+ return i;
1241
+ });
1242
+ }
1243
+ function j(e) {
1244
+ return Number.isFinite(e) ? Math.max(0, Math.round(e * 1e3)) : 0;
1245
+ }
1246
+ function rt(e) {
1247
+ return typeof e != "number" || !Number.isFinite(e) ? 1 : Math.max(0, Math.min(1, e));
1248
+ }
1249
+ function Re(e) {
1250
+ return typeof e != "number" || !Number.isFinite(e) ? 1 : Math.max(0.1, Math.min(100, e));
1251
+ }
1252
+ function Ae(e) {
1253
+ const t = Math.max(0, e.endTime - e.startTime), o = Math.max(0, Math.min(e.fadeInDuration ?? 0, t)), i = Math.max(0, Math.min(e.fadeOutDuration ?? 0, t));
1254
+ return {
1255
+ fromUs: j(e.fromTime ?? 0),
1256
+ segmentDurationUs: j(t),
1257
+ playRate: Re(e.playRate),
1258
+ baseVolume: rt(e.volume),
1259
+ fadeInUs: j(o),
1260
+ fadeOutUs: j(i)
1261
+ };
1262
+ }
1263
+ function Ee(e) {
1264
+ return e.segmentType === "audio";
1265
+ }
1266
+ function Ie(e) {
1267
+ return e.segmentType === "frames" && e.type === "video";
1268
+ }
1269
+ async function Pt(e, t = It) {
1270
+ const o = new AbortController(), i = globalThis.setTimeout(() => o.abort(), t);
1271
+ try {
1272
+ const n = await fetch(e, { signal: o.signal });
1273
+ if (!n.body)
1274
+ throw new Error(`composeProtocol: unable to read resource stream: ${e}`);
1275
+ return n.body;
1276
+ } catch (n) {
1277
+ throw o.signal.aborted ? new Error(`composeProtocol: loading resource timed out (${t}ms): ${e}`) : n;
1278
+ } finally {
1279
+ globalThis.clearTimeout(i);
1280
+ }
1281
+ }
1282
+ async function Ft(e, t) {
1283
+ const o = Ae(t), i = new st(e, o), n = new nt(i);
1284
+ try {
1285
+ await be(n.ready, It, "prepare audio sprite");
1286
+ } catch (a) {
1287
+ throw n.destroy(), a;
1288
+ }
1289
+ return n.time.offset = j(t.startTime), n.time.duration = o.segmentDurationUs, n.time.playbackRate = o.playRate, n;
1290
+ }
1291
+ async function Pe(e) {
1292
+ const t = await Pt(e.url), o = new Tt(t);
1293
+ return await Ft(o, e);
1294
+ }
1295
+ async function Fe(e) {
1296
+ const t = await Pt(e.url), o = new K(t, { audio: !0 });
1297
+ return await Ft(o, e);
1298
+ }
1299
+ async function Ue(e) {
1300
+ const t = [];
1301
+ for (const n of e.tracks)
1302
+ for (const a of n.children)
1303
+ if (!(a.endTime <= a.startTime)) {
1304
+ if (Ee(a)) {
1305
+ if (rt(a.volume) <= 0)
1306
+ continue;
1307
+ t.push(Pe(a));
1308
+ continue;
1309
+ }
1310
+ if (Ie(a)) {
1311
+ if (rt(a.volume) <= 0)
1312
+ continue;
1313
+ t.push(Fe(a));
1314
+ }
1315
+ }
1316
+ if (!t.length)
1317
+ return [];
1318
+ const o = await Promise.allSettled(t), i = [];
1319
+ for (const n of o) {
1320
+ if (n.status === "fulfilled") {
1321
+ i.push(n.value);
1322
+ continue;
1323
+ }
1324
+ console.warn("[compose] skip audio sprite due to load failure", n.reason);
1325
+ }
1326
+ return i;
1327
+ }
1328
+ function ot(e) {
1329
+ for (const t of e)
1330
+ t.destroy();
1331
+ }
1332
+ function Oe(e, t) {
1333
+ let o = !1;
1169
1334
  const i = () => {
1170
- r || (r = !0, e());
1171
- }, n = o.getReader();
1335
+ o || (o = !0, t());
1336
+ }, n = e.getReader();
1172
1337
  return new ReadableStream({
1173
- async pull(d) {
1174
- const { done: c, value: s } = await n.read();
1338
+ async pull(a) {
1339
+ const { done: c, value: u } = await n.read();
1175
1340
  if (c) {
1176
- i(), d.close();
1341
+ i(), a.close();
1177
1342
  return;
1178
1343
  }
1179
- d.enqueue(s);
1344
+ a.enqueue(u);
1180
1345
  },
1181
- async cancel(d) {
1346
+ async cancel(a) {
1182
1347
  try {
1183
- await n.cancel(d);
1348
+ await n.cancel(a);
1184
1349
  } finally {
1185
1350
  i();
1186
1351
  }
1187
1352
  }
1188
1353
  });
1189
1354
  }
1190
- async function bt(o, e = {}) {
1355
+ async function Ge(e, t = {}) {
1191
1356
  const {
1192
- width: r,
1357
+ width: o,
1193
1358
  height: i,
1194
1359
  fps: n,
1195
- onProgress: d,
1360
+ onProgress: a,
1196
1361
  clipOptions: c,
1197
- audioSprites: s,
1198
- ...l
1199
- } = e, m = r ?? o.width, p = i ?? o.height;
1200
- if (!m || !p)
1362
+ audioSprites: u,
1363
+ ...d
1364
+ } = t, y = o ?? e.width, h = i ?? e.height;
1365
+ if (!y || !h)
1201
1366
  throw new Error("composeProtocol: output width/height is required");
1202
- const w = n ?? o.fps, T = typeof s == "function", h = l.audio ?? (T ? void 0 : !1), v = new ve({
1203
- ...l,
1204
- audio: h,
1205
- width: m,
1206
- height: p,
1367
+ const w = n ?? e.fps, M = d.audio === !1 ? [] : typeof u == "function" ? await u(e) : await Ue(e), p = d.audio ?? (M.length > 0 ? void 0 : !1), v = new bt({
1368
+ ...d,
1369
+ audio: p,
1370
+ width: y,
1371
+ height: h,
1207
1372
  fps: w
1208
1373
  });
1209
- d && v.on("OutputProgress", d);
1210
- let y, g;
1374
+ a && v.on("OutputProgress", a);
1375
+ let m, g;
1211
1376
  try {
1212
- if (y = new oe(o, {
1213
- width: m,
1214
- height: p,
1377
+ m = new at(e, {
1378
+ width: y,
1379
+ height: h,
1215
1380
  fps: w,
1216
1381
  ...c,
1217
1382
  rendererOptions: {
1218
1383
  warmUpResources: !1,
1219
1384
  ...c?.rendererOptions
1220
1385
  }
1221
- }), await y.ready, g = new Me(y), await g.ready, g.time.offset = 0, g.time.duration = y.meta.duration, g.rect.x = 0, g.rect.y = 0, g.rect.w = y.meta.width, g.rect.h = y.meta.height, await v.addSprite(g, { main: !0 }), s) {
1222
- const A = await s(o);
1223
- for (const k of A)
1224
- await v.addSprite(k);
1225
- }
1226
- } catch (A) {
1227
- throw v.destroy(), A;
1386
+ }), await m.ready, g = new nt(m), await g.ready, g.time.offset = 0, g.time.duration = m.meta.duration, g.rect.x = 0, g.rect.y = 0, g.rect.w = m.meta.width, g.rect.h = m.meta.height, await v.addSprite(g, { main: !0 });
1387
+ for (const b of M)
1388
+ await v.addSprite(b);
1389
+ } catch (b) {
1390
+ throw ot(M), g?.destroy(), m?.destroy(), v.destroy(), b;
1228
1391
  }
1229
- const R = y?.meta.duration ?? 0;
1392
+ const R = m?.meta.duration ?? 0;
1230
1393
  if (!R)
1231
- throw new Error("composeProtocol: protocol has no duration");
1232
- const I = v.output({ maxTime: R }), E = () => {
1233
- g?.destroy(), y?.destroy(), v.destroy();
1394
+ throw ot(M), g?.destroy(), m?.destroy(), v.destroy(), new Error("composeProtocol: protocol has no duration");
1395
+ const P = v.output({ maxTime: R });
1396
+ let A = !1;
1397
+ const E = () => {
1398
+ A || (A = !0, ot(M), g?.destroy(), m?.destroy(), v.destroy());
1234
1399
  };
1235
1400
  return {
1236
- stream: wt(I, E),
1237
- width: m,
1238
- height: p,
1401
+ stream: Oe(P, E),
1402
+ width: y,
1403
+ height: h,
1239
1404
  durationMs: Math.round(R / 1e3),
1240
1405
  destroy: E
1241
1406
  };
1242
1407
  }
1243
1408
  export {
1244
- oe as ProtocolVideoClip,
1245
- bt as composeProtocol,
1246
- Tt as concatVideos,
1247
- lt as createRenderer
1409
+ at as ProtocolVideoClip,
1410
+ Ge as composeProtocol,
1411
+ Ne as concatVideos,
1412
+ ve as createRenderer
1248
1413
  };
1249
1414
  //# sourceMappingURL=index.js.map