@moq/watch 0.2.15 → 0.2.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/README.md +21 -9
  2. package/backend.d.ts +2 -0
  3. package/backend.d.ts.map +1 -1
  4. package/broadcast-80k1hgfM.js +1680 -0
  5. package/broadcast-80k1hgfM.js.map +1 -0
  6. package/broadcast.d.ts +30 -1
  7. package/broadcast.d.ts.map +1 -1
  8. package/element.d.ts +6 -2
  9. package/element.d.ts.map +1 -1
  10. package/element.js +23 -7
  11. package/element.js.map +1 -1
  12. package/index.d.ts +1 -0
  13. package/index.d.ts.map +1 -1
  14. package/index.js +5 -4
  15. package/package.json +6 -6
  16. package/support/element.js +39 -39
  17. package/support/element.js.map +1 -1
  18. package/ui/components/button.d.ts +3 -0
  19. package/ui/components/button.d.ts.map +1 -0
  20. package/ui/components/center-play.d.ts +5 -0
  21. package/ui/components/center-play.d.ts.map +1 -0
  22. package/ui/components/control-bar.d.ts +6 -0
  23. package/ui/components/control-bar.d.ts.map +1 -0
  24. package/ui/components/fullscreen-button.d.ts +2 -1
  25. package/ui/components/fullscreen-button.d.ts.map +1 -1
  26. package/ui/components/latency.d.ts +5 -0
  27. package/ui/components/latency.d.ts.map +1 -0
  28. package/ui/components/live-badge.d.ts +9 -0
  29. package/ui/components/live-badge.d.ts.map +1 -0
  30. package/ui/components/play-pause.d.ts +1 -0
  31. package/ui/components/play-pause.d.ts.map +1 -1
  32. package/ui/components/quality.d.ts +5 -0
  33. package/ui/components/quality.d.ts.map +1 -0
  34. package/ui/components/settings-button.d.ts +5 -0
  35. package/ui/components/settings-button.d.ts.map +1 -0
  36. package/ui/components/settings-panel.d.ts +6 -0
  37. package/ui/components/settings-panel.d.ts.map +1 -0
  38. package/ui/components/volume-slider.d.ts +1 -0
  39. package/ui/components/volume-slider.d.ts.map +1 -1
  40. package/ui/element.d.ts.map +1 -1
  41. package/ui/element.js +577 -260
  42. package/ui/element.js.map +1 -1
  43. package/ui/format.d.ts +11 -0
  44. package/ui/format.d.ts.map +1 -0
  45. package/ui/fullscreen.d.ts +16 -0
  46. package/ui/fullscreen.d.ts.map +1 -0
  47. package/ui/graph.d.ts +18 -0
  48. package/ui/graph.d.ts.map +1 -0
  49. package/ui/icons.d.ts +5 -1
  50. package/ui/icons.d.ts.map +1 -1
  51. package/ui/state.d.ts +9 -0
  52. package/ui/state.d.ts.map +1 -0
  53. package/ui/stats.d.ts +3 -2
  54. package/ui/stats.d.ts.map +1 -1
  55. package/video/renderer.d.ts +18 -0
  56. package/video/renderer.d.ts.map +1 -1
  57. package/broadcast-jtLUfuyL.js +0 -4291
  58. package/broadcast-jtLUfuyL.js.map +0 -1
  59. package/dom-Yz3UT5ap.js +0 -29
  60. package/dom-Yz3UT5ap.js.map +0 -1
  61. package/libav-opus-af-CzuaKpJb.js +0 -252
  62. package/libav-opus-af-CzuaKpJb.js.map +0 -1
  63. package/main-bFFHfuX4.js +0 -1999
  64. package/main-bFFHfuX4.js.map +0 -1
  65. package/ui/components/quality-selector.d.ts +0 -4
  66. package/ui/components/quality-selector.d.ts.map +0 -1
  67. package/ui/components/stats-button.d.ts +0 -3
  68. package/ui/components/stats-button.d.ts.map +0 -1
  69. package/ui/components/watch-status-indicator.d.ts +0 -4
  70. package/ui/components/watch-status-indicator.d.ts.map +0 -1
@@ -1,4291 +0,0 @@
1
- import * as e from "@moq/net";
2
- import { Path as t, Time as n } from "@moq/net";
3
- import { Effect as r, Signal as i } from "@moq/signals";
4
- //#region \0rolldown/runtime.js
5
- var a = Object.defineProperty, o = (e, t) => {
6
- let n = {};
7
- for (var r in e) a(n, r, {
8
- get: e[r],
9
- enumerable: !0
10
- });
11
- return t || a(n, Symbol.toStringTag, { value: "Module" }), n;
12
- }, s = /* @__PURE__ */ ((e) => typeof require < "u" ? require : typeof Proxy < "u" ? new Proxy(e, { get: (e, t) => (typeof require < "u" ? require : e)[t] }) : e)(function(e) {
13
- if (typeof require < "u") return require.apply(this, arguments);
14
- throw Error("Calling `require` for \"" + e + "\" in an environment that doesn't expose the `require` function. See https://rolldown.rs/in-depth/bundling-cjs#require-external-modules for more details.");
15
- }), c;
16
- function l(e, t, n) {
17
- function r(n, r) {
18
- if (n._zod || Object.defineProperty(n, "_zod", {
19
- value: {
20
- def: r,
21
- constr: o,
22
- traits: /* @__PURE__ */ new Set()
23
- },
24
- enumerable: !1
25
- }), n._zod.traits.has(e)) return;
26
- n._zod.traits.add(e), t(n, r);
27
- let i = o.prototype, a = Object.keys(i);
28
- for (let e = 0; e < a.length; e++) {
29
- let t = a[e];
30
- t in n || (n[t] = i[t].bind(n));
31
- }
32
- }
33
- let i = n?.Parent ?? Object;
34
- class a extends i {}
35
- Object.defineProperty(a, "name", { value: e });
36
- function o(e) {
37
- var t;
38
- let i = n?.Parent ? new a() : this;
39
- r(i, e), (t = i._zod).deferred ?? (t.deferred = []);
40
- for (let e of i._zod.deferred) e();
41
- return i;
42
- }
43
- return Object.defineProperty(o, "init", { value: r }), Object.defineProperty(o, Symbol.hasInstance, { value: (t) => n?.Parent && t instanceof n.Parent ? !0 : t?._zod?.traits?.has(e) }), Object.defineProperty(o, "name", { value: e }), o;
44
- }
45
- var u = class extends Error {
46
- constructor() {
47
- super("Encountered Promise during synchronous parse. Use .parseAsync() instead.");
48
- }
49
- }, d = class extends Error {
50
- constructor(e) {
51
- super(`Encountered unidirectional transform during encode: ${e}`), this.name = "ZodEncodeError";
52
- }
53
- };
54
- (c = globalThis).__zod_globalConfig ?? (c.__zod_globalConfig = {});
55
- var f = globalThis.__zod_globalConfig;
56
- function p(e) {
57
- return e && Object.assign(f, e), f;
58
- }
59
- //#endregion
60
- //#region ../../node_modules/zod/v4/core/util.js
61
- function m(e) {
62
- let t = Object.values(e).filter((e) => typeof e == "number");
63
- return Object.entries(e).filter(([e, n]) => t.indexOf(+e) === -1).map(([e, t]) => t);
64
- }
65
- function ee(e, t) {
66
- return typeof t == "bigint" ? t.toString() : t;
67
- }
68
- function te(e) {
69
- return { get value() {
70
- {
71
- let t = e();
72
- return Object.defineProperty(this, "value", { value: t }), t;
73
- }
74
- throw Error("cached value already set");
75
- } };
76
- }
77
- function h(e) {
78
- let t = +!!e.startsWith("^"), n = e.endsWith("$") ? e.length - 1 : e.length;
79
- return e.slice(t, n);
80
- }
81
- var g = /* @__PURE__ */ Symbol("evaluating");
82
- function _(e, t, n) {
83
- let r;
84
- Object.defineProperty(e, t, {
85
- get() {
86
- if (r !== g) return r === void 0 && (r = g, r = n()), r;
87
- },
88
- set(n) {
89
- Object.defineProperty(e, t, { value: n });
90
- },
91
- configurable: !0
92
- });
93
- }
94
- var v = "captureStackTrace" in Error ? Error.captureStackTrace : (...e) => {};
95
- function y(e) {
96
- return typeof e == "object" && !!e && !Array.isArray(e);
97
- }
98
- function ne(e) {
99
- if (y(e) === !1) return !1;
100
- let t = e.constructor;
101
- if (t === void 0 || typeof t != "function") return !0;
102
- let n = t.prototype;
103
- return !(y(n) === !1 || Object.prototype.hasOwnProperty.call(n, "isPrototypeOf") === !1);
104
- }
105
- function re(e) {
106
- return ne(e) ? { ...e } : Array.isArray(e) ? [...e] : e instanceof Map ? new Map(e) : e instanceof Set ? new Set(e) : e;
107
- }
108
- var ie = /* @__PURE__ */ new Set([
109
- "string",
110
- "number",
111
- "symbol"
112
- ]);
113
- function ae(e) {
114
- return e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
115
- }
116
- function oe(e, t, n) {
117
- let r = new e._zod.constr(t ?? e._zod.def);
118
- return (!t || n?.parent) && (r._zod.parent = e), r;
119
- }
120
- function b(e) {
121
- let t = e;
122
- if (!t) return {};
123
- if (typeof t == "string") return { error: () => t };
124
- if (t?.message !== void 0) {
125
- if (t?.error !== void 0) throw Error("Cannot specify both `message` and `error` params");
126
- t.error = t.message;
127
- }
128
- return delete t.message, typeof t.error == "string" ? {
129
- ...t,
130
- error: () => t.error
131
- } : t;
132
- }
133
- function se(e) {
134
- return Object.keys(e).filter((t) => e[t]._zod.optin === "optional" && e[t]._zod.optout === "optional");
135
- }
136
- var ce = {
137
- safeint: [-(2 ** 53 - 1), 2 ** 53 - 1],
138
- int32: [-2147483648, 2147483647],
139
- uint32: [0, 4294967295],
140
- float32: [-34028234663852886e22, 34028234663852886e22],
141
- float64: [-Number.MAX_VALUE, Number.MAX_VALUE]
142
- };
143
- function x(e, t = 0) {
144
- if (e.aborted === !0) return !0;
145
- for (let n = t; n < e.issues.length; n++) if (e.issues[n]?.continue !== !0) return !0;
146
- return !1;
147
- }
148
- function le(e, t = 0) {
149
- if (e.aborted === !0) return !0;
150
- for (let n = t; n < e.issues.length; n++) if (e.issues[n]?.continue === !1) return !0;
151
- return !1;
152
- }
153
- function S(e, t) {
154
- return t.map((t) => {
155
- var n;
156
- return (n = t).path ?? (n.path = []), t.path.unshift(e), t;
157
- });
158
- }
159
- function C(e) {
160
- return typeof e == "string" ? e : e?.message;
161
- }
162
- function w(e, t, n) {
163
- let r = e.message ? e.message : C(e.inst?._zod.def?.error?.(e)) ?? C(t?.error?.(e)) ?? C(n.customError?.(e)) ?? C(n.localeError?.(e)) ?? "Invalid input", { inst: i, continue: a, input: o, ...s } = e;
164
- return s.path ??= [], s.message = r, t?.reportInput && (s.input = o), s;
165
- }
166
- //#endregion
167
- //#region ../../node_modules/zod/v4/core/errors.js
168
- var ue = (e, t) => {
169
- e.name = "$ZodError", Object.defineProperty(e, "_zod", {
170
- value: e._zod,
171
- enumerable: !1
172
- }), Object.defineProperty(e, "issues", {
173
- value: t,
174
- enumerable: !1
175
- }), e.message = JSON.stringify(t, ee, 2), Object.defineProperty(e, "toString", {
176
- value: () => e.message,
177
- enumerable: !1
178
- });
179
- }, de = l("$ZodError", ue), fe = l("$ZodError", ue, { Parent: Error }), pe = /* @__PURE__ */ ((e) => (t, n, r, i) => {
180
- let a = r ? {
181
- ...r,
182
- async: !1
183
- } : { async: !1 }, o = t._zod.run({
184
- value: n,
185
- issues: []
186
- }, a);
187
- if (o instanceof Promise) throw new u();
188
- if (o.issues.length) {
189
- let t = new (i?.Err ?? e)(o.issues.map((e) => w(e, a, p())));
190
- throw v(t, i?.callee), t;
191
- }
192
- return o.value;
193
- })(fe), me = /* @__PURE__ */ ((e) => async (t, n, r, i) => {
194
- let a = r ? {
195
- ...r,
196
- async: !0
197
- } : { async: !0 }, o = t._zod.run({
198
- value: n,
199
- issues: []
200
- }, a);
201
- if (o instanceof Promise && (o = await o), o.issues.length) {
202
- let t = new (i?.Err ?? e)(o.issues.map((e) => w(e, a, p())));
203
- throw v(t, i?.callee), t;
204
- }
205
- return o.value;
206
- })(fe), he = /* @__PURE__ */ ((e) => (t, n, r) => {
207
- let i = r ? {
208
- ...r,
209
- async: !1
210
- } : { async: !1 }, a = t._zod.run({
211
- value: n,
212
- issues: []
213
- }, i);
214
- if (a instanceof Promise) throw new u();
215
- return a.issues.length ? {
216
- success: !1,
217
- error: new (e ?? de)(a.issues.map((e) => w(e, i, p())))
218
- } : {
219
- success: !0,
220
- data: a.value
221
- };
222
- })(fe), ge = /* @__PURE__ */ ((e) => async (t, n, r) => {
223
- let i = r ? {
224
- ...r,
225
- async: !0
226
- } : { async: !0 }, a = t._zod.run({
227
- value: n,
228
- issues: []
229
- }, i);
230
- return a instanceof Promise && (a = await a), a.issues.length ? {
231
- success: !1,
232
- error: new e(a.issues.map((e) => w(e, i, p())))
233
- } : {
234
- success: !0,
235
- data: a.value
236
- };
237
- })(fe), _e = /^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/, ve = (e) => {
238
- let t = e ? `[\\s\\S]{${e?.minimum ?? 0},${e?.maximum ?? ""}}` : "[\\s\\S]*";
239
- return RegExp(`^${t}$`);
240
- }, ye = /^-?\d+$/, be = /^-?\d+(?:\.\d+)?$/, xe = /^(?:true|false)$/i, Se = /* @__PURE__ */ l("$ZodCheck", (e, t) => {
241
- var n;
242
- e._zod ??= {}, e._zod.def = t, (n = e._zod).onattach ?? (n.onattach = []);
243
- }), Ce = {
244
- number: "number",
245
- bigint: "bigint",
246
- object: "date"
247
- }, we = /* @__PURE__ */ l("$ZodCheckLessThan", (e, t) => {
248
- Se.init(e, t);
249
- let n = Ce[typeof t.value];
250
- e._zod.onattach.push((e) => {
251
- let n = e._zod.bag, r = (t.inclusive ? n.maximum : n.exclusiveMaximum) ?? Infinity;
252
- t.value < r && (t.inclusive ? n.maximum = t.value : n.exclusiveMaximum = t.value);
253
- }), e._zod.check = (r) => {
254
- (t.inclusive ? r.value <= t.value : r.value < t.value) || r.issues.push({
255
- origin: n,
256
- code: "too_big",
257
- maximum: typeof t.value == "object" ? t.value.getTime() : t.value,
258
- input: r.value,
259
- inclusive: t.inclusive,
260
- inst: e,
261
- continue: !t.abort
262
- });
263
- };
264
- }), Te = /* @__PURE__ */ l("$ZodCheckGreaterThan", (e, t) => {
265
- Se.init(e, t);
266
- let n = Ce[typeof t.value];
267
- e._zod.onattach.push((e) => {
268
- let n = e._zod.bag, r = (t.inclusive ? n.minimum : n.exclusiveMinimum) ?? -Infinity;
269
- t.value > r && (t.inclusive ? n.minimum = t.value : n.exclusiveMinimum = t.value);
270
- }), e._zod.check = (r) => {
271
- (t.inclusive ? r.value >= t.value : r.value > t.value) || r.issues.push({
272
- origin: n,
273
- code: "too_small",
274
- minimum: typeof t.value == "object" ? t.value.getTime() : t.value,
275
- input: r.value,
276
- inclusive: t.inclusive,
277
- inst: e,
278
- continue: !t.abort
279
- });
280
- };
281
- }), Ee = /* @__PURE__ */ l("$ZodCheckNumberFormat", (e, t) => {
282
- Se.init(e, t), t.format = t.format || "float64";
283
- let n = t.format?.includes("int"), r = n ? "int" : "number", [i, a] = ce[t.format];
284
- e._zod.onattach.push((e) => {
285
- let r = e._zod.bag;
286
- r.format = t.format, r.minimum = i, r.maximum = a, n && (r.pattern = ye);
287
- }), e._zod.check = (o) => {
288
- let s = o.value;
289
- if (n) {
290
- if (!Number.isInteger(s)) {
291
- o.issues.push({
292
- expected: r,
293
- format: t.format,
294
- code: "invalid_type",
295
- continue: !1,
296
- input: s,
297
- inst: e
298
- });
299
- return;
300
- }
301
- if (!Number.isSafeInteger(s)) {
302
- s > 0 ? o.issues.push({
303
- input: s,
304
- code: "too_big",
305
- maximum: 2 ** 53 - 1,
306
- note: "Integers must be within the safe integer range.",
307
- inst: e,
308
- origin: r,
309
- inclusive: !0,
310
- continue: !t.abort
311
- }) : o.issues.push({
312
- input: s,
313
- code: "too_small",
314
- minimum: -(2 ** 53 - 1),
315
- note: "Integers must be within the safe integer range.",
316
- inst: e,
317
- origin: r,
318
- inclusive: !0,
319
- continue: !t.abort
320
- });
321
- return;
322
- }
323
- }
324
- s < i && o.issues.push({
325
- origin: "number",
326
- input: s,
327
- code: "too_small",
328
- minimum: i,
329
- inclusive: !0,
330
- inst: e,
331
- continue: !t.abort
332
- }), s > a && o.issues.push({
333
- origin: "number",
334
- input: s,
335
- code: "too_big",
336
- maximum: a,
337
- inclusive: !0,
338
- inst: e,
339
- continue: !t.abort
340
- });
341
- };
342
- }), De = /* @__PURE__ */ l("$ZodCheckStringFormat", (e, t) => {
343
- var n, r;
344
- Se.init(e, t), e._zod.onattach.push((e) => {
345
- let n = e._zod.bag;
346
- n.format = t.format, t.pattern && (n.patterns ??= /* @__PURE__ */ new Set(), n.patterns.add(t.pattern));
347
- }), t.pattern ? (n = e._zod).check ?? (n.check = (n) => {
348
- t.pattern.lastIndex = 0, !t.pattern.test(n.value) && n.issues.push({
349
- origin: "string",
350
- code: "invalid_format",
351
- format: t.format,
352
- input: n.value,
353
- ...t.pattern ? { pattern: t.pattern.toString() } : {},
354
- inst: e,
355
- continue: !t.abort
356
- });
357
- }) : (r = e._zod).check ?? (r.check = () => {});
358
- }), Oe = {
359
- major: 4,
360
- minor: 4,
361
- patch: 3
362
- }, T = /* @__PURE__ */ l("$ZodType", (e, t) => {
363
- var n;
364
- e ??= {}, e._zod.def = t, e._zod.bag = e._zod.bag || {}, e._zod.version = Oe;
365
- let r = [...e._zod.def.checks ?? []];
366
- e._zod.traits.has("$ZodCheck") && r.unshift(e);
367
- for (let t of r) for (let n of t._zod.onattach) n(e);
368
- if (r.length === 0) (n = e._zod).deferred ?? (n.deferred = []), e._zod.deferred?.push(() => {
369
- e._zod.run = e._zod.parse;
370
- });
371
- else {
372
- let t = (e, t, n) => {
373
- let r = x(e), i;
374
- for (let a of t) {
375
- if (a._zod.def.when) {
376
- if (le(e) || !a._zod.def.when(e)) continue;
377
- } else if (r) continue;
378
- let t = e.issues.length, o = a._zod.check(e);
379
- if (o instanceof Promise && n?.async === !1) throw new u();
380
- if (i || o instanceof Promise) i = (i ?? Promise.resolve()).then(async () => {
381
- await o, e.issues.length !== t && (r ||= x(e, t));
382
- });
383
- else {
384
- if (e.issues.length === t) continue;
385
- r ||= x(e, t);
386
- }
387
- }
388
- return i ? i.then(() => e) : e;
389
- }, n = (n, i, a) => {
390
- if (x(n)) return n.aborted = !0, n;
391
- let o = t(i, r, a);
392
- if (o instanceof Promise) {
393
- if (a.async === !1) throw new u();
394
- return o.then((t) => e._zod.parse(t, a));
395
- }
396
- return e._zod.parse(o, a);
397
- };
398
- e._zod.run = (i, a) => {
399
- if (a.skipChecks) return e._zod.parse(i, a);
400
- if (a.direction === "backward") {
401
- let t = e._zod.parse({
402
- value: i.value,
403
- issues: []
404
- }, {
405
- ...a,
406
- skipChecks: !0
407
- });
408
- return t instanceof Promise ? t.then((e) => n(e, i, a)) : n(t, i, a);
409
- }
410
- let o = e._zod.parse(i, a);
411
- if (o instanceof Promise) {
412
- if (a.async === !1) throw new u();
413
- return o.then((e) => t(e, r, a));
414
- }
415
- return t(o, r, a);
416
- };
417
- }
418
- _(e, "~standard", () => ({
419
- validate: (t) => {
420
- try {
421
- let n = he(e, t);
422
- return n.success ? { value: n.data } : { issues: n.error?.issues };
423
- } catch {
424
- return ge(e, t).then((e) => e.success ? { value: e.data } : { issues: e.error?.issues });
425
- }
426
- },
427
- vendor: "zod",
428
- version: 1
429
- }));
430
- }), ke = /* @__PURE__ */ l("$ZodString", (e, t) => {
431
- T.init(e, t), e._zod.pattern = [...e?._zod.bag?.patterns ?? []].pop() ?? ve(e._zod.bag), e._zod.parse = (n, r) => {
432
- if (t.coerce) try {
433
- n.value = String(n.value);
434
- } catch {}
435
- return typeof n.value == "string" || n.issues.push({
436
- expected: "string",
437
- code: "invalid_type",
438
- input: n.value,
439
- inst: e
440
- }), n;
441
- };
442
- }), Ae = /* @__PURE__ */ l("$ZodStringFormat", (e, t) => {
443
- De.init(e, t), ke.init(e, t);
444
- });
445
- function je(e) {
446
- if (e === "") return !0;
447
- if (/\s/.test(e) || e.length % 4 != 0) return !1;
448
- try {
449
- return atob(e), !0;
450
- } catch {
451
- return !1;
452
- }
453
- }
454
- var Me = /* @__PURE__ */ l("$ZodBase64", (e, t) => {
455
- t.pattern ??= _e, Ae.init(e, t), e._zod.bag.contentEncoding = "base64", e._zod.check = (n) => {
456
- je(n.value) || n.issues.push({
457
- code: "invalid_format",
458
- format: "base64",
459
- input: n.value,
460
- inst: e,
461
- continue: !t.abort
462
- });
463
- };
464
- }), Ne = /* @__PURE__ */ l("$ZodNumber", (e, t) => {
465
- T.init(e, t), e._zod.pattern = e._zod.bag.pattern ?? be, e._zod.parse = (n, r) => {
466
- if (t.coerce) try {
467
- n.value = Number(n.value);
468
- } catch {}
469
- let i = n.value;
470
- if (typeof i == "number" && !Number.isNaN(i) && Number.isFinite(i)) return n;
471
- let a = typeof i == "number" ? Number.isNaN(i) ? "NaN" : Number.isFinite(i) ? void 0 : "Infinity" : void 0;
472
- return n.issues.push({
473
- expected: "number",
474
- code: "invalid_type",
475
- input: i,
476
- inst: e,
477
- ...a ? { received: a } : {}
478
- }), n;
479
- };
480
- }), Pe = /* @__PURE__ */ l("$ZodNumberFormat", (e, t) => {
481
- Ee.init(e, t), Ne.init(e, t);
482
- }), Fe = /* @__PURE__ */ l("$ZodBoolean", (e, t) => {
483
- T.init(e, t), e._zod.pattern = xe, e._zod.parse = (n, r) => {
484
- if (t.coerce) try {
485
- n.value = !!n.value;
486
- } catch {}
487
- let i = n.value;
488
- return typeof i == "boolean" || n.issues.push({
489
- expected: "boolean",
490
- code: "invalid_type",
491
- input: i,
492
- inst: e
493
- }), n;
494
- };
495
- }), Ie = /* @__PURE__ */ l("$ZodUnknown", (e, t) => {
496
- T.init(e, t), e._zod.parse = (e) => e;
497
- });
498
- function Le(e, t, n) {
499
- e.issues.length && t.issues.push(...S(n, e.issues)), t.value[n] = e.value;
500
- }
501
- var Re = /* @__PURE__ */ l("$ZodArray", (e, t) => {
502
- T.init(e, t), e._zod.parse = (n, r) => {
503
- let i = n.value;
504
- if (!Array.isArray(i)) return n.issues.push({
505
- expected: "array",
506
- code: "invalid_type",
507
- input: i,
508
- inst: e
509
- }), n;
510
- n.value = Array(i.length);
511
- let a = [];
512
- for (let e = 0; e < i.length; e++) {
513
- let o = i[e], s = t.element._zod.run({
514
- value: o,
515
- issues: []
516
- }, r);
517
- s instanceof Promise ? a.push(s.then((t) => Le(t, n, e))) : Le(s, n, e);
518
- }
519
- return a.length ? Promise.all(a).then(() => n) : n;
520
- };
521
- });
522
- function E(e, t, n, r, i, a) {
523
- let o = n in r;
524
- if (e.issues.length) {
525
- if (i && a && !o) return;
526
- t.issues.push(...S(n, e.issues));
527
- }
528
- if (!o && !i) {
529
- e.issues.length || t.issues.push({
530
- code: "invalid_type",
531
- expected: "nonoptional",
532
- input: void 0,
533
- path: [n]
534
- });
535
- return;
536
- }
537
- e.value === void 0 ? o && (t.value[n] = void 0) : t.value[n] = e.value;
538
- }
539
- function ze(e) {
540
- let t = Object.keys(e.shape);
541
- for (let n of t) if (!e.shape?.[n]?._zod?.traits?.has("$ZodType")) throw Error(`Invalid element at key "${n}": expected a Zod schema`);
542
- let n = se(e.shape);
543
- return {
544
- ...e,
545
- keys: t,
546
- keySet: new Set(t),
547
- numKeys: t.length,
548
- optionalKeys: new Set(n)
549
- };
550
- }
551
- function Be(e, t, n, r, i, a) {
552
- let o = [], s = i.keySet, c = i.catchall._zod, l = c.def.type, u = c.optin === "optional", d = c.optout === "optional";
553
- for (let i in t) {
554
- if (i === "__proto__" || s.has(i)) continue;
555
- if (l === "never") {
556
- o.push(i);
557
- continue;
558
- }
559
- let a = c.run({
560
- value: t[i],
561
- issues: []
562
- }, r);
563
- a instanceof Promise ? e.push(a.then((e) => E(e, n, i, t, u, d))) : E(a, n, i, t, u, d);
564
- }
565
- return o.length && n.issues.push({
566
- code: "unrecognized_keys",
567
- keys: o,
568
- input: t,
569
- inst: a
570
- }), e.length ? Promise.all(e).then(() => n) : n;
571
- }
572
- var Ve = /* @__PURE__ */ l("$ZodObject", (e, t) => {
573
- if (T.init(e, t), !Object.getOwnPropertyDescriptor(t, "shape")?.get) {
574
- let e = t.shape;
575
- Object.defineProperty(t, "shape", { get: () => {
576
- let n = { ...e };
577
- return Object.defineProperty(t, "shape", { value: n }), n;
578
- } });
579
- }
580
- let n = te(() => ze(t));
581
- _(e._zod, "propValues", () => {
582
- let e = t.shape, n = {};
583
- for (let t in e) {
584
- let r = e[t]._zod;
585
- if (r.values) {
586
- n[t] ?? (n[t] = /* @__PURE__ */ new Set());
587
- for (let e of r.values) n[t].add(e);
588
- }
589
- }
590
- return n;
591
- });
592
- let r = y, i = t.catchall, a;
593
- e._zod.parse = (t, o) => {
594
- a ??= n.value;
595
- let s = t.value;
596
- if (!r(s)) return t.issues.push({
597
- expected: "object",
598
- code: "invalid_type",
599
- input: s,
600
- inst: e
601
- }), t;
602
- t.value = {};
603
- let c = [], l = a.shape;
604
- for (let e of a.keys) {
605
- let n = l[e], r = n._zod.optin === "optional", i = n._zod.optout === "optional", a = n._zod.run({
606
- value: s[e],
607
- issues: []
608
- }, o);
609
- a instanceof Promise ? c.push(a.then((n) => E(n, t, e, s, r, i))) : E(a, t, e, s, r, i);
610
- }
611
- return i ? Be(c, s, t, o, n.value, e) : c.length ? Promise.all(c).then(() => t) : t;
612
- };
613
- });
614
- function He(e, t, n, r) {
615
- for (let n of e) if (n.issues.length === 0) return t.value = n.value, t;
616
- let i = e.filter((e) => !x(e));
617
- return i.length === 1 ? (t.value = i[0].value, i[0]) : (t.issues.push({
618
- code: "invalid_union",
619
- input: t.value,
620
- inst: n,
621
- errors: e.map((e) => e.issues.map((e) => w(e, r, p())))
622
- }), t);
623
- }
624
- var Ue = /* @__PURE__ */ l("$ZodUnion", (e, t) => {
625
- T.init(e, t), _(e._zod, "optin", () => t.options.some((e) => e._zod.optin === "optional") ? "optional" : void 0), _(e._zod, "optout", () => t.options.some((e) => e._zod.optout === "optional") ? "optional" : void 0), _(e._zod, "values", () => {
626
- if (t.options.every((e) => e._zod.values)) return new Set(t.options.flatMap((e) => Array.from(e._zod.values)));
627
- }), _(e._zod, "pattern", () => {
628
- if (t.options.every((e) => e._zod.pattern)) {
629
- let e = t.options.map((e) => e._zod.pattern);
630
- return RegExp(`^(${e.map((e) => h(e.source)).join("|")})$`);
631
- }
632
- });
633
- let n = t.options.length === 1 ? t.options[0]._zod.run : null;
634
- e._zod.parse = (r, i) => {
635
- if (n) return n(r, i);
636
- let a = !1, o = [];
637
- for (let e of t.options) {
638
- let t = e._zod.run({
639
- value: r.value,
640
- issues: []
641
- }, i);
642
- if (t instanceof Promise) o.push(t), a = !0;
643
- else {
644
- if (t.issues.length === 0) return t;
645
- o.push(t);
646
- }
647
- }
648
- return a ? Promise.all(o).then((t) => He(t, r, e, i)) : He(o, r, e, i);
649
- };
650
- }), We = /* @__PURE__ */ l("$ZodDiscriminatedUnion", (e, t) => {
651
- t.inclusive = !1, Ue.init(e, t);
652
- let n = e._zod.parse;
653
- _(e._zod, "propValues", () => {
654
- let e = {};
655
- for (let n of t.options) {
656
- let r = n._zod.propValues;
657
- if (!r || Object.keys(r).length === 0) throw Error(`Invalid discriminated union option at index "${t.options.indexOf(n)}"`);
658
- for (let [t, n] of Object.entries(r)) {
659
- e[t] || (e[t] = /* @__PURE__ */ new Set());
660
- for (let r of n) e[t].add(r);
661
- }
662
- }
663
- return e;
664
- });
665
- let r = te(() => {
666
- let e = t.options, n = /* @__PURE__ */ new Map();
667
- for (let r of e) {
668
- let e = r._zod.propValues?.[t.discriminator];
669
- if (!e || e.size === 0) throw Error(`Invalid discriminated union option at index "${t.options.indexOf(r)}"`);
670
- for (let t of e) {
671
- if (n.has(t)) throw Error(`Duplicate discriminator value "${String(t)}"`);
672
- n.set(t, r);
673
- }
674
- }
675
- return n;
676
- });
677
- e._zod.parse = (i, a) => {
678
- let o = i.value;
679
- if (!y(o)) return i.issues.push({
680
- code: "invalid_type",
681
- expected: "object",
682
- input: o,
683
- inst: e
684
- }), i;
685
- let s = r.value.get(o?.[t.discriminator]);
686
- return s ? s._zod.run(i, a) : t.unionFallback || a.direction === "backward" ? n(i, a) : (i.issues.push({
687
- code: "invalid_union",
688
- errors: [],
689
- note: "No matching discriminator",
690
- discriminator: t.discriminator,
691
- options: Array.from(r.value.keys()),
692
- input: o,
693
- path: [t.discriminator],
694
- inst: e
695
- }), i);
696
- };
697
- }), Ge = /* @__PURE__ */ l("$ZodRecord", (e, t) => {
698
- T.init(e, t), e._zod.parse = (n, r) => {
699
- let i = n.value;
700
- if (!ne(i)) return n.issues.push({
701
- expected: "record",
702
- code: "invalid_type",
703
- input: i,
704
- inst: e
705
- }), n;
706
- let a = [], o = t.keyType._zod.values;
707
- if (o) {
708
- n.value = {};
709
- let s = /* @__PURE__ */ new Set();
710
- for (let c of o) if (typeof c == "string" || typeof c == "number" || typeof c == "symbol") {
711
- s.add(typeof c == "number" ? c.toString() : c);
712
- let o = t.keyType._zod.run({
713
- value: c,
714
- issues: []
715
- }, r);
716
- if (o instanceof Promise) throw Error("Async schemas not supported in object keys currently");
717
- if (o.issues.length) {
718
- n.issues.push({
719
- code: "invalid_key",
720
- origin: "record",
721
- issues: o.issues.map((e) => w(e, r, p())),
722
- input: c,
723
- path: [c],
724
- inst: e
725
- });
726
- continue;
727
- }
728
- let l = o.value, u = t.valueType._zod.run({
729
- value: i[c],
730
- issues: []
731
- }, r);
732
- u instanceof Promise ? a.push(u.then((e) => {
733
- e.issues.length && n.issues.push(...S(c, e.issues)), n.value[l] = e.value;
734
- })) : (u.issues.length && n.issues.push(...S(c, u.issues)), n.value[l] = u.value);
735
- }
736
- let c;
737
- for (let e in i) s.has(e) || (c ??= [], c.push(e));
738
- c && c.length > 0 && n.issues.push({
739
- code: "unrecognized_keys",
740
- input: i,
741
- inst: e,
742
- keys: c
743
- });
744
- } else {
745
- n.value = {};
746
- for (let o of Reflect.ownKeys(i)) {
747
- if (o === "__proto__" || !Object.prototype.propertyIsEnumerable.call(i, o)) continue;
748
- let s = t.keyType._zod.run({
749
- value: o,
750
- issues: []
751
- }, r);
752
- if (s instanceof Promise) throw Error("Async schemas not supported in object keys currently");
753
- if (typeof o == "string" && be.test(o) && s.issues.length) {
754
- let e = t.keyType._zod.run({
755
- value: Number(o),
756
- issues: []
757
- }, r);
758
- if (e instanceof Promise) throw Error("Async schemas not supported in object keys currently");
759
- e.issues.length === 0 && (s = e);
760
- }
761
- if (s.issues.length) {
762
- t.mode === "loose" ? n.value[o] = i[o] : n.issues.push({
763
- code: "invalid_key",
764
- origin: "record",
765
- issues: s.issues.map((e) => w(e, r, p())),
766
- input: o,
767
- path: [o],
768
- inst: e
769
- });
770
- continue;
771
- }
772
- let c = t.valueType._zod.run({
773
- value: i[o],
774
- issues: []
775
- }, r);
776
- c instanceof Promise ? a.push(c.then((e) => {
777
- e.issues.length && n.issues.push(...S(o, e.issues)), n.value[s.value] = e.value;
778
- })) : (c.issues.length && n.issues.push(...S(o, c.issues)), n.value[s.value] = c.value);
779
- }
780
- }
781
- return a.length ? Promise.all(a).then(() => n) : n;
782
- };
783
- }), Ke = /* @__PURE__ */ l("$ZodEnum", (e, t) => {
784
- T.init(e, t);
785
- let n = m(t.entries), r = new Set(n);
786
- e._zod.values = r, e._zod.pattern = RegExp(`^(${n.filter((e) => ie.has(typeof e)).map((e) => typeof e == "string" ? ae(e) : e.toString()).join("|")})$`), e._zod.parse = (t, i) => {
787
- let a = t.value;
788
- return r.has(a) || t.issues.push({
789
- code: "invalid_value",
790
- values: n,
791
- input: a,
792
- inst: e
793
- }), t;
794
- };
795
- }), qe = /* @__PURE__ */ l("$ZodLiteral", (e, t) => {
796
- if (T.init(e, t), t.values.length === 0) throw Error("Cannot create literal schema with no valid values");
797
- let n = new Set(t.values);
798
- e._zod.values = n, e._zod.pattern = RegExp(`^(${t.values.map((e) => typeof e == "string" ? ae(e) : e ? ae(e.toString()) : String(e)).join("|")})$`), e._zod.parse = (r, i) => {
799
- let a = r.value;
800
- return n.has(a) || r.issues.push({
801
- code: "invalid_value",
802
- values: t.values,
803
- input: a,
804
- inst: e
805
- }), r;
806
- };
807
- }), Je = /* @__PURE__ */ l("$ZodTransform", (e, t) => {
808
- T.init(e, t), e._zod.optin = "optional", e._zod.parse = (n, r) => {
809
- if (r.direction === "backward") throw new d(e.constructor.name);
810
- let i = t.transform(n.value, n);
811
- if (r.async) return (i instanceof Promise ? i : Promise.resolve(i)).then((e) => (n.value = e, n.fallback = !0, n));
812
- if (i instanceof Promise) throw new u();
813
- return n.value = i, n.fallback = !0, n;
814
- };
815
- });
816
- function Ye(e, t) {
817
- return t === void 0 && (e.issues.length || e.fallback) ? {
818
- issues: [],
819
- value: void 0
820
- } : e;
821
- }
822
- var Xe = /* @__PURE__ */ l("$ZodOptional", (e, t) => {
823
- T.init(e, t), e._zod.optin = "optional", e._zod.optout = "optional", _(e._zod, "values", () => t.innerType._zod.values ? new Set([...t.innerType._zod.values, void 0]) : void 0), _(e._zod, "pattern", () => {
824
- let e = t.innerType._zod.pattern;
825
- return e ? RegExp(`^(${h(e.source)})?$`) : void 0;
826
- }), e._zod.parse = (e, n) => {
827
- if (t.innerType._zod.optin === "optional") {
828
- let r = e.value, i = t.innerType._zod.run(e, n);
829
- return i instanceof Promise ? i.then((e) => Ye(e, r)) : Ye(i, r);
830
- }
831
- return e.value === void 0 ? e : t.innerType._zod.run(e, n);
832
- };
833
- }), Ze = /* @__PURE__ */ l("$ZodDefault", (e, t) => {
834
- T.init(e, t), e._zod.optin = "optional", _(e._zod, "values", () => t.innerType._zod.values), e._zod.parse = (e, n) => {
835
- if (n.direction === "backward") return t.innerType._zod.run(e, n);
836
- if (e.value === void 0) return e.value = t.defaultValue, e;
837
- let r = t.innerType._zod.run(e, n);
838
- return r instanceof Promise ? r.then((e) => Qe(e, t)) : Qe(r, t);
839
- };
840
- });
841
- function Qe(e, t) {
842
- return e.value === void 0 && (e.value = t.defaultValue), e;
843
- }
844
- var $e = /* @__PURE__ */ l("$ZodPipe", (e, t) => {
845
- T.init(e, t), _(e._zod, "values", () => t.in._zod.values), _(e._zod, "optin", () => t.in._zod.optin), _(e._zod, "optout", () => t.out._zod.optout), _(e._zod, "propValues", () => t.in._zod.propValues), e._zod.parse = (e, n) => {
846
- if (n.direction === "backward") {
847
- let r = t.out._zod.run(e, n);
848
- return r instanceof Promise ? r.then((e) => et(e, t.in, n)) : et(r, t.in, n);
849
- }
850
- let r = t.in._zod.run(e, n);
851
- return r instanceof Promise ? r.then((e) => et(e, t.out, n)) : et(r, t.out, n);
852
- };
853
- });
854
- function et(e, t, n) {
855
- return e.issues.length ? (e.aborted = !0, e) : t._zod.run({
856
- value: e.value,
857
- issues: e.issues,
858
- fallback: e.fallback
859
- }, n);
860
- }
861
- //#endregion
862
- //#region ../../node_modules/zod/v4/core/api.js
863
- /* @__NO_SIDE_EFFECTS__ */
864
- function tt(e, t) {
865
- return new e({
866
- type: "string",
867
- ...b(t)
868
- });
869
- }
870
- /* @__NO_SIDE_EFFECTS__ */
871
- function nt(e, t) {
872
- return new e({
873
- type: "string",
874
- format: "base64",
875
- check: "string_format",
876
- abort: !1,
877
- ...b(t)
878
- });
879
- }
880
- /* @__NO_SIDE_EFFECTS__ */
881
- function rt(e, t) {
882
- return new e({
883
- type: "number",
884
- checks: [],
885
- ...b(t)
886
- });
887
- }
888
- /* @__NO_SIDE_EFFECTS__ */
889
- function it(e, t) {
890
- return new e({
891
- type: "number",
892
- check: "number_format",
893
- abort: !1,
894
- format: "safeint",
895
- ...b(t)
896
- });
897
- }
898
- /* @__NO_SIDE_EFFECTS__ */
899
- function at(e, t) {
900
- return new e({
901
- type: "boolean",
902
- ...b(t)
903
- });
904
- }
905
- /* @__NO_SIDE_EFFECTS__ */
906
- function ot(e) {
907
- return new e({ type: "unknown" });
908
- }
909
- /* @__NO_SIDE_EFFECTS__ */
910
- function st(e, t) {
911
- return new we({
912
- check: "less_than",
913
- ...b(t),
914
- value: e,
915
- inclusive: !0
916
- });
917
- }
918
- /* @__NO_SIDE_EFFECTS__ */
919
- function ct(e, t) {
920
- return new Te({
921
- check: "greater_than",
922
- ...b(t),
923
- value: e,
924
- inclusive: !0
925
- });
926
- }
927
- /* @__NO_SIDE_EFFECTS__ */
928
- function lt(e) {
929
- return /* @__PURE__ */ ct(0, e);
930
- }
931
- //#endregion
932
- //#region ../../node_modules/zod/v4/mini/schemas.js
933
- var D = /* @__PURE__ */ l("ZodMiniType", (e, t) => {
934
- if (!e._zod) throw Error("Uninitialized schema in ZodMiniType.");
935
- T.init(e, t), e.def = t, e.type = t.type, e.parse = (t, n) => pe(e, t, n, { callee: e.parse }), e.safeParse = (t, n) => he(e, t, n), e.parseAsync = async (t, n) => me(e, t, n, { callee: e.parseAsync }), e.safeParseAsync = async (t, n) => ge(e, t, n), e.check = (...n) => e.clone({
936
- ...t,
937
- checks: [...t.checks ?? [], ...n.map((e) => typeof e == "function" ? { _zod: {
938
- check: e,
939
- def: { check: "custom" },
940
- onattach: []
941
- } } : e)]
942
- }, { parent: !0 }), e.with = e.check, e.clone = (t, n) => oe(e, t, n), e.brand = () => e, e.register = ((t, n) => (t.add(e, n), e)), e.apply = (t) => t(e);
943
- }), ut = /* @__PURE__ */ l("ZodMiniString", (e, t) => {
944
- ke.init(e, t), D.init(e, t);
945
- });
946
- /* @__NO_SIDE_EFFECTS__ */
947
- function O(e) {
948
- return /* @__PURE__ */ tt(ut, e);
949
- }
950
- var dt = /* @__PURE__ */ l("ZodMiniStringFormat", (e, t) => {
951
- Ae.init(e, t), ut.init(e, t);
952
- }), ft = /* @__PURE__ */ l("ZodMiniBase64", (e, t) => {
953
- Me.init(e, t), dt.init(e, t);
954
- });
955
- /* @__NO_SIDE_EFFECTS__ */
956
- function pt(e) {
957
- return /* @__PURE__ */ nt(ft, e);
958
- }
959
- var mt = /* @__PURE__ */ l("ZodMiniNumber", (e, t) => {
960
- Ne.init(e, t), D.init(e, t);
961
- });
962
- /* @__NO_SIDE_EFFECTS__ */
963
- function k(e) {
964
- return /* @__PURE__ */ rt(mt, e);
965
- }
966
- var ht = /* @__PURE__ */ l("ZodMiniNumberFormat", (e, t) => {
967
- Pe.init(e, t), mt.init(e, t);
968
- });
969
- /* @__NO_SIDE_EFFECTS__ */
970
- function gt(e) {
971
- return /* @__PURE__ */ it(ht, e);
972
- }
973
- var _t = /* @__PURE__ */ l("ZodMiniBoolean", (e, t) => {
974
- Fe.init(e, t), D.init(e, t);
975
- });
976
- /* @__NO_SIDE_EFFECTS__ */
977
- function vt(e) {
978
- return /* @__PURE__ */ at(_t, e);
979
- }
980
- var yt = /* @__PURE__ */ l("ZodMiniUnknown", (e, t) => {
981
- Ie.init(e, t), D.init(e, t);
982
- });
983
- /* @__NO_SIDE_EFFECTS__ */
984
- function bt() {
985
- return /* @__PURE__ */ ot(yt);
986
- }
987
- var xt = /* @__PURE__ */ l("ZodMiniArray", (e, t) => {
988
- Re.init(e, t), D.init(e, t);
989
- });
990
- /* @__NO_SIDE_EFFECTS__ */
991
- function St(e, t) {
992
- return new xt({
993
- type: "array",
994
- element: e,
995
- ...b(t)
996
- });
997
- }
998
- var Ct = /* @__PURE__ */ l("ZodMiniObject", (e, t) => {
999
- Ve.init(e, t), D.init(e, t), _(e, "shape", () => t.shape);
1000
- });
1001
- /* @__NO_SIDE_EFFECTS__ */
1002
- function A(e, t) {
1003
- return new Ct({
1004
- type: "object",
1005
- shape: e ?? {},
1006
- ...b(t)
1007
- });
1008
- }
1009
- /* @__NO_SIDE_EFFECTS__ */
1010
- function wt(e, t) {
1011
- return new Ct({
1012
- type: "object",
1013
- shape: e,
1014
- catchall: /* @__PURE__ */ bt(),
1015
- ...b(t)
1016
- });
1017
- }
1018
- var Tt = /* @__PURE__ */ l("ZodMiniUnion", (e, t) => {
1019
- Ue.init(e, t), D.init(e, t);
1020
- });
1021
- /* @__NO_SIDE_EFFECTS__ */
1022
- function Et(e, t) {
1023
- return new Tt({
1024
- type: "union",
1025
- options: e,
1026
- ...b(t)
1027
- });
1028
- }
1029
- var Dt = /* @__PURE__ */ l("ZodMiniDiscriminatedUnion", (e, t) => {
1030
- We.init(e, t), D.init(e, t);
1031
- });
1032
- /* @__NO_SIDE_EFFECTS__ */
1033
- function Ot(e, t, n) {
1034
- return new Dt({
1035
- type: "union",
1036
- options: t,
1037
- discriminator: e,
1038
- ...b(n)
1039
- });
1040
- }
1041
- var kt = /* @__PURE__ */ l("ZodMiniRecord", (e, t) => {
1042
- Ge.init(e, t), D.init(e, t);
1043
- });
1044
- /* @__NO_SIDE_EFFECTS__ */
1045
- function At(e, t, n) {
1046
- return !t || !t._zod ? new kt({
1047
- type: "record",
1048
- keyType: /* @__PURE__ */ O(),
1049
- valueType: e,
1050
- ...b(t)
1051
- }) : new kt({
1052
- type: "record",
1053
- keyType: e,
1054
- valueType: t,
1055
- ...b(n)
1056
- });
1057
- }
1058
- var jt = /* @__PURE__ */ l("ZodMiniEnum", (e, t) => {
1059
- Ke.init(e, t), D.init(e, t), e.options = Object.values(t.entries);
1060
- });
1061
- /* @__NO_SIDE_EFFECTS__ */
1062
- function Mt(e, t) {
1063
- return new jt({
1064
- type: "enum",
1065
- entries: Array.isArray(e) ? Object.fromEntries(e.map((e) => [e, e])) : e,
1066
- ...b(t)
1067
- });
1068
- }
1069
- var Nt = /* @__PURE__ */ l("ZodMiniLiteral", (e, t) => {
1070
- qe.init(e, t), D.init(e, t);
1071
- });
1072
- /* @__NO_SIDE_EFFECTS__ */
1073
- function j(e, t) {
1074
- return new Nt({
1075
- type: "literal",
1076
- values: Array.isArray(e) ? e : [e],
1077
- ...b(t)
1078
- });
1079
- }
1080
- var Pt = /* @__PURE__ */ l("ZodMiniTransform", (e, t) => {
1081
- Je.init(e, t), D.init(e, t);
1082
- });
1083
- /* @__NO_SIDE_EFFECTS__ */
1084
- function Ft(e) {
1085
- return new Pt({
1086
- type: "transform",
1087
- transform: e
1088
- });
1089
- }
1090
- var It = /* @__PURE__ */ l("ZodMiniOptional", (e, t) => {
1091
- Xe.init(e, t), D.init(e, t);
1092
- });
1093
- /* @__NO_SIDE_EFFECTS__ */
1094
- function M(e) {
1095
- return new It({
1096
- type: "optional",
1097
- innerType: e
1098
- });
1099
- }
1100
- var Lt = /* @__PURE__ */ l("ZodMiniDefault", (e, t) => {
1101
- Ze.init(e, t), D.init(e, t);
1102
- });
1103
- /* @__NO_SIDE_EFFECTS__ */
1104
- function Rt(e, t) {
1105
- return new Lt({
1106
- type: "default",
1107
- innerType: e,
1108
- get defaultValue() {
1109
- return typeof t == "function" ? t() : re(t);
1110
- }
1111
- });
1112
- }
1113
- var zt = /* @__PURE__ */ l("ZodMiniPipe", (e, t) => {
1114
- $e.init(e, t), D.init(e, t);
1115
- });
1116
- /* @__NO_SIDE_EFFECTS__ */
1117
- function Bt(e, t) {
1118
- return new zt({
1119
- type: "pipe",
1120
- in: e,
1121
- out: t
1122
- });
1123
- }
1124
- (/* @__PURE__ */ k()).check(/* @__PURE__ */ gt(), /* @__PURE__ */ lt(), /* @__PURE__ */ st(255)).brand("u8");
1125
- var N = (/* @__PURE__ */ k()).check(/* @__PURE__ */ gt(), /* @__PURE__ */ lt(), /* @__PURE__ */ st(2 ** 53 - 1)).brand("u53");
1126
- function P(e) {
1127
- return N.parse(e);
1128
- }
1129
- //#endregion
1130
- //#region ../hang/src/catalog/container.ts
1131
- var Vt = /* @__PURE__ */ Rt(/* @__PURE__ */ Ot("kind", [
1132
- /* @__PURE__ */ A({ kind: /* @__PURE__ */ j("legacy") }),
1133
- /* @__PURE__ */ A({
1134
- kind: /* @__PURE__ */ j("cmaf"),
1135
- init: /* @__PURE__ */ pt(),
1136
- timescale: /* @__PURE__ */ M(N),
1137
- trackId: /* @__PURE__ */ M(N)
1138
- }),
1139
- /* @__PURE__ */ A({ kind: /* @__PURE__ */ j("loc") })
1140
- ]), { kind: "legacy" }), Ht = /* @__PURE__ */ A({ name: /* @__PURE__ */ O() }), Ut = /* @__PURE__ */ A({
1141
- codec: /* @__PURE__ */ O(),
1142
- container: Vt,
1143
- description: /* @__PURE__ */ M(/* @__PURE__ */ O()),
1144
- sampleRate: N,
1145
- numberOfChannels: N,
1146
- bitrate: /* @__PURE__ */ M(N),
1147
- jitter: /* @__PURE__ */ M(N)
1148
- }), Wt = /* @__PURE__ */ Et([/* @__PURE__ */ A({ renditions: /* @__PURE__ */ At(/* @__PURE__ */ O(), Ut) }), /* @__PURE__ */ Bt(/* @__PURE__ */ A({
1149
- track: Ht,
1150
- config: Ut
1151
- }), /* @__PURE__ */ Ft((e) => ({ renditions: { [e.track.name]: e.config } })))]), Gt = ["hang", "msf"];
1152
- function Kt(e) {
1153
- for (let t of Gt) if (e.endsWith(`.${t}`)) return t;
1154
- }
1155
- //#endregion
1156
- //#region ../hang/src/catalog/priority.ts
1157
- var F = {
1158
- catalog: 100,
1159
- audio: 80,
1160
- video: 60
1161
- }, qt = /* @__PURE__ */ A({ name: /* @__PURE__ */ O() }), Jt = /* @__PURE__ */ A({
1162
- codec: /* @__PURE__ */ O(),
1163
- container: Vt,
1164
- description: /* @__PURE__ */ M(/* @__PURE__ */ O()),
1165
- codedWidth: /* @__PURE__ */ M(N),
1166
- codedHeight: /* @__PURE__ */ M(N),
1167
- displayAspectWidth: /* @__PURE__ */ M(N),
1168
- displayAspectHeight: /* @__PURE__ */ M(N),
1169
- framerate: /* @__PURE__ */ M(/* @__PURE__ */ k()),
1170
- bitrate: /* @__PURE__ */ M(N),
1171
- optimizeForLatency: /* @__PURE__ */ M(/* @__PURE__ */ vt()),
1172
- jitter: /* @__PURE__ */ M(N)
1173
- }), Yt = /* @__PURE__ */ wt({
1174
- video: /* @__PURE__ */ M(/* @__PURE__ */ Et([/* @__PURE__ */ A({
1175
- renditions: /* @__PURE__ */ At(/* @__PURE__ */ O(), Jt),
1176
- display: /* @__PURE__ */ M(/* @__PURE__ */ A({
1177
- width: N,
1178
- height: N
1179
- })),
1180
- rotation: /* @__PURE__ */ M(/* @__PURE__ */ k()),
1181
- flip: /* @__PURE__ */ M(/* @__PURE__ */ vt())
1182
- }), /* @__PURE__ */ Bt(/* @__PURE__ */ St(/* @__PURE__ */ A({
1183
- track: qt,
1184
- config: Jt
1185
- })), /* @__PURE__ */ Ft((e) => {
1186
- let t = e[0]?.config;
1187
- return {
1188
- renditions: Object.fromEntries(e.map((e) => [e.track.name, e.config])),
1189
- display: t?.displayAspectWidth !== void 0 && t?.displayAspectHeight !== void 0 ? {
1190
- width: t.displayAspectWidth,
1191
- height: t.displayAspectHeight
1192
- } : void 0,
1193
- rotation: void 0,
1194
- flip: void 0
1195
- };
1196
- }))])),
1197
- audio: /* @__PURE__ */ M(Wt)
1198
- }), Xt = 6, Zt = 8, Qt = 1e6, $t = class {
1199
- decode(t) {
1200
- let [n, r] = e.Varint.decode(t);
1201
- if (r.byteLength < n) throw Error("loc: properties_length exceeds frame size");
1202
- let i = r.subarray(0, n), a = r.subarray(n), o, s, c = 0, l = !0, u = i;
1203
- for (; u.byteLength > 0;) {
1204
- let [t, n] = e.Varint.decode(u), r = l ? t : c + t;
1205
- if (l = !1, c = r, u = n, r % 2 == 0) {
1206
- let [t, n] = e.Varint.decode(u);
1207
- if (u = n, r === Xt) o = t;
1208
- else if (r === Zt) {
1209
- if (t === 0) throw Error("loc: timescale property must be non-zero");
1210
- s = t;
1211
- }
1212
- } else {
1213
- let [t, n] = e.Varint.decode(u);
1214
- if (n.byteLength < t) throw Error("loc: property length exceeds remaining bytes");
1215
- u = n.subarray(t);
1216
- }
1217
- }
1218
- if (o === void 0) throw Error("loc: frame missing required timestamp property");
1219
- let d = s ?? Qt;
1220
- return [{
1221
- data: a,
1222
- timestamp: Math.round(o * Qt / d),
1223
- keyframe: !1
1224
- }];
1225
- }
1226
- };
1227
- //#endregion
1228
- //#region ../../node_modules/@svta/cml-utils/dist/index.js
1229
- function en(e) {
1230
- return e instanceof ArrayBuffer || typeof SharedArrayBuffer < "u" && e instanceof SharedArrayBuffer;
1231
- }
1232
- var tn = "utf-16", nn = "utf-16be", rn = "utf-16le", I = "utf-8";
1233
- function an(e, t = {}) {
1234
- let n;
1235
- n = en(e) ? new DataView(e) : new DataView(e.buffer, e.byteOffset, e.byteLength);
1236
- let r = 0, { encoding: i } = t;
1237
- if (!i) {
1238
- let e = n.getUint8(0), t = n.getUint8(1);
1239
- e == 239 && t == 187 && n.getUint8(2) == 191 ? (i = I, r = 3) : e == 254 && t == 255 ? (i = nn, r = 2) : e == 255 && t == 254 ? (i = rn, r = 2) : i = I;
1240
- }
1241
- if (typeof TextDecoder < "u") return new TextDecoder(i).decode(n);
1242
- let { byteLength: a } = n, o = i !== nn, s = "", c;
1243
- for (; r < a;) {
1244
- switch (i) {
1245
- case I:
1246
- if (c = n.getUint8(r), c < 128) r++;
1247
- else if (c >= 194 && c <= 223) if (r + 1 < a) {
1248
- let e = n.getUint8(r + 1);
1249
- e >= 128 && e <= 191 ? (c = (c & 31) << 6 | e & 63, r += 2) : r++;
1250
- } else r++;
1251
- else if (c >= 224 && c <= 239) if (r + 2 <= a - 1) {
1252
- let e = n.getUint8(r + 1), t = n.getUint8(r + 2);
1253
- e >= 128 && e <= 191 && t >= 128 && t <= 191 ? (c = (c & 15) << 12 | (e & 63) << 6 | t & 63, r += 3) : r++;
1254
- } else r++;
1255
- else if (c >= 240 && c <= 244) if (r + 3 <= a - 1) {
1256
- let e = n.getUint8(r + 1), t = n.getUint8(r + 2), i = n.getUint8(r + 3);
1257
- e >= 128 && e <= 191 && t >= 128 && t <= 191 && i >= 128 && i <= 191 ? (c = (c & 7) << 18 | (e & 63) << 12 | (t & 63) << 6 | i & 63, r += 4) : r++;
1258
- } else r++;
1259
- else r++;
1260
- break;
1261
- case nn:
1262
- case tn:
1263
- case rn:
1264
- c = n.getUint16(r, o), r += 2;
1265
- break;
1266
- }
1267
- s += String.fromCodePoint(c);
1268
- }
1269
- return s;
1270
- }
1271
- function on(e) {
1272
- return new TextEncoder().encode(e);
1273
- }
1274
- //#endregion
1275
- //#region ../../node_modules/@svta/cml-iso-bmff/dist/index.js
1276
- function sn(e) {
1277
- return { writers: e?.writers ?? {} };
1278
- }
1279
- var cn = [
1280
- "dinf",
1281
- "edts",
1282
- "grpl",
1283
- "mdia",
1284
- "meco",
1285
- "mfra",
1286
- "minf",
1287
- "moof",
1288
- "moov",
1289
- "mvex",
1290
- "schi",
1291
- "sinf",
1292
- "stbl",
1293
- "strk",
1294
- "traf",
1295
- "trak",
1296
- "tref",
1297
- "udta",
1298
- "vttc"
1299
- ];
1300
- function ln(e) {
1301
- return "boxes" in e || cn.includes(e.type);
1302
- }
1303
- var un = "utf8", L = "uint", R = "template", dn = "string", fn = "data", z = class {
1304
- constructor(e, t) {
1305
- this.writeUint = (e, t) => {
1306
- let { dataView: n, cursor: r } = this;
1307
- switch (t) {
1308
- case 1:
1309
- n.setUint8(r, e);
1310
- break;
1311
- case 2:
1312
- n.setUint16(r, e);
1313
- break;
1314
- case 3: {
1315
- let t = (e & 16776960) >> 8, i = e & 255;
1316
- n.setUint16(r, t), n.setUint8(r + 2, i);
1317
- break;
1318
- }
1319
- case 4:
1320
- n.setUint32(r, e);
1321
- break;
1322
- case 8: {
1323
- let t = Math.floor(e / 2 ** 32), i = e - t * 2 ** 32;
1324
- n.setUint32(r, t), n.setUint32(r + 4, i);
1325
- break;
1326
- }
1327
- }
1328
- this.cursor += t;
1329
- }, this.writeInt = (e, t) => {
1330
- let { dataView: n, cursor: r } = this;
1331
- switch (t) {
1332
- case 1:
1333
- n.setInt8(r, e);
1334
- break;
1335
- case 2:
1336
- n.setInt16(r, e);
1337
- break;
1338
- case 4:
1339
- n.setInt32(r, e);
1340
- break;
1341
- case 8:
1342
- let t = Math.floor(e / 2 ** 32), i = e - t * 2 ** 32;
1343
- n.setUint32(r, t), n.setUint32(r + 4, i);
1344
- break;
1345
- }
1346
- this.cursor += t;
1347
- }, this.writeString = (e) => {
1348
- for (let t = 0, n = e.length; t < n; t++) this.writeUint(e.charCodeAt(t), 1);
1349
- }, this.writeTerminatedString = (e) => {
1350
- if (e.length !== 0) {
1351
- for (let t = 0, n = e.length; t < n; t++) this.writeUint(e.charCodeAt(t), 1);
1352
- this.writeUint(0, 1);
1353
- }
1354
- }, this.writeUtf8TerminatedString = (e) => {
1355
- let t = on(e);
1356
- new Uint8Array(this.dataView.buffer).set(t, this.cursor), this.cursor += t.length, this.writeUint(0, 1);
1357
- }, this.writeBytes = (e) => {
1358
- Array.isArray(e) || (e = [e]);
1359
- for (let t of e) new Uint8Array(this.dataView.buffer).set(t, this.cursor), this.cursor += t.length;
1360
- }, this.writeArray = (e, t, n, r) => {
1361
- let i = t === "uint" ? this.writeUint : t === "template" ? this.writeTemplate : this.writeInt;
1362
- for (let t = 0; t < r; t++) i(e[t] ?? 0, n);
1363
- }, this.writeTemplate = (e, t) => {
1364
- let n = Math.round(e * 2 ** (t === 4 ? 16 : 8));
1365
- this.writeUint(n, t);
1366
- }, this.writeBoxHeader = (e, t) => {
1367
- t > 4294967295 ? (this.writeUint(1, 4), this.writeString(e), this.writeUint(t, 8)) : (this.writeUint(t, 4), this.writeString(e));
1368
- }, this.dataView = new DataView(new ArrayBuffer(t)), this.cursor = 0, this.writeBoxHeader(e, t);
1369
- }
1370
- get buffer() {
1371
- return this.dataView.buffer;
1372
- }
1373
- get byteLength() {
1374
- return this.dataView.byteLength;
1375
- }
1376
- get byteOffset() {
1377
- return this.dataView.byteOffset;
1378
- }
1379
- writeFullBox(e, t) {
1380
- this.writeUint(e, 1), this.writeUint(t, 3);
1381
- }
1382
- };
1383
- function pn(e, t) {
1384
- return Array.from(e, (e) => gn(e, t));
1385
- }
1386
- function mn(e, t) {
1387
- let n = pn(e, t);
1388
- return {
1389
- bytes: n,
1390
- size: n.reduce((e, t) => e + t.byteLength, 0)
1391
- };
1392
- }
1393
- function hn(e, t) {
1394
- let { bytes: n, size: r } = mn(e.boxes, t), i = 8 + r, a = new z(e.type, i);
1395
- return a.writeBytes(n), a;
1396
- }
1397
- function gn(e, t) {
1398
- let n = null;
1399
- if ("type" in e) {
1400
- let { type: r } = e, i = t.writers?.[r];
1401
- if (i ? n = i(e, t) : ln(e) ? n = hn(e, t) : "view" in e && (n = e.view), !n) throw Error(`No writer found for box type: ${r}`);
1402
- }
1403
- if ("buffer" in e && (n = e), !n) throw Error("Invalid box");
1404
- return new Uint8Array(n.buffer, n.byteOffset, n.byteLength);
1405
- }
1406
- function _n(e, t, n) {
1407
- let r = n > 0 ? n : e.byteLength - (t - e.byteOffset);
1408
- return new Uint8Array(e.buffer, t, Math.max(r, 0));
1409
- }
1410
- function vn(e, t, n) {
1411
- let r = NaN, i = t - e.byteOffset;
1412
- switch (n) {
1413
- case 1:
1414
- r = e.getInt8(i);
1415
- break;
1416
- case 2:
1417
- r = e.getInt16(i);
1418
- break;
1419
- case 4:
1420
- r = e.getInt32(i);
1421
- break;
1422
- case 8:
1423
- let t = e.getInt32(i), n = e.getInt32(i + 4);
1424
- r = t * 2 ** 32 + n;
1425
- break;
1426
- }
1427
- return r;
1428
- }
1429
- function B(e, t, n) {
1430
- let r = t - e.byteOffset, i = NaN, a, o;
1431
- switch (n) {
1432
- case 1:
1433
- i = e.getUint8(r);
1434
- break;
1435
- case 2:
1436
- i = e.getUint16(r);
1437
- break;
1438
- case 3:
1439
- a = e.getUint16(r), o = e.getUint8(r + 2), i = (a << 8) + o;
1440
- break;
1441
- case 4:
1442
- i = e.getUint32(r);
1443
- break;
1444
- case 8:
1445
- a = e.getUint32(r), o = e.getUint32(r + 4), i = a * 2 ** 32 + o;
1446
- break;
1447
- }
1448
- return i;
1449
- }
1450
- function yn(e, t, n) {
1451
- let r = "";
1452
- for (let i = 0; i < n; i++) {
1453
- let n = B(e, t + i, 1);
1454
- r += String.fromCharCode(n);
1455
- }
1456
- return r;
1457
- }
1458
- function bn(e, t, n) {
1459
- let r = n / 2;
1460
- return B(e, t, r) + B(e, t + r, r) / 2 ** r;
1461
- }
1462
- function xn(e, t) {
1463
- let n = "", r = t;
1464
- for (; r - e.byteOffset < e.byteLength;) {
1465
- let t = B(e, r, 1);
1466
- if (t === 0) break;
1467
- n += String.fromCharCode(t), r++;
1468
- }
1469
- return n;
1470
- }
1471
- function Sn(e, t) {
1472
- let n = e.byteLength - (t - e.byteOffset);
1473
- return n > 0 ? an(new DataView(e.buffer, t, n), { encoding: I }) : "";
1474
- }
1475
- function Cn(e, t) {
1476
- let n = e.byteLength - (t - e.byteOffset), r = "";
1477
- if (n > 0) {
1478
- let i = new DataView(e.buffer, t, n), a = 0;
1479
- for (; a < n && i.getUint8(a) !== 0; a++);
1480
- r = an(new DataView(e.buffer, t, a), { encoding: I });
1481
- }
1482
- return r;
1483
- }
1484
- var wn = class e {
1485
- constructor(t, n) {
1486
- this.truncated = !1, this.slice = (t, n) => {
1487
- let r = new e(new DataView(this.dataView.buffer, t, n), this.config), i = this.offset - t, a = n - i;
1488
- return this.offset += a, r.jump(i), r;
1489
- }, this.read = (e, t = 0) => {
1490
- let { dataView: n, offset: r } = this, i, a = t;
1491
- switch (e) {
1492
- case L:
1493
- i = B(n, r, t);
1494
- break;
1495
- case "int":
1496
- i = vn(n, r, t);
1497
- break;
1498
- case R:
1499
- i = bn(n, r, t);
1500
- break;
1501
- case dn:
1502
- t === -1 ? (i = xn(n, r), a = i.length + 1) : i = yn(n, r, t);
1503
- break;
1504
- case fn:
1505
- i = _n(n, r, t), a = i.length;
1506
- break;
1507
- case un:
1508
- t === -1 ? (i = Cn(n, r), a = i.length + 1) : i = Sn(n, r);
1509
- break;
1510
- default: i = -1;
1511
- }
1512
- return this.offset += a, i;
1513
- }, this.readUint = (e) => this.read(L, e), this.readInt = (e) => this.read("int", e), this.readString = (e) => this.read(dn, e), this.readTemplate = (e) => this.read(R, e), this.readData = (e) => this.read(fn, e), this.readUtf8 = (e) => this.read(un, e), this.readFullBox = () => ({
1514
- version: this.readUint(1),
1515
- flags: this.readUint(3)
1516
- }), this.readArray = (e, t, n) => {
1517
- let r = [];
1518
- for (let i = 0; i < n; i++) r.push(this.read(e, t));
1519
- return r;
1520
- }, this.jump = (e) => {
1521
- this.offset += e;
1522
- }, this.readBox = () => {
1523
- let { dataView: e, offset: t } = this, n = 0, r = B(e, t, 4), i = yn(e, t + 4, 4), a = {
1524
- size: r,
1525
- type: i
1526
- };
1527
- n += 8, a.size === 1 && (a.largesize = B(e, t + n, 8), n += 8);
1528
- let o = a.size === 0 ? this.bytesRemaining : a.largesize ?? a.size;
1529
- if (this.cursor + o > e.byteLength) throw this.truncated = !0, Error("Truncated box");
1530
- return this.jump(n), i === "uuid" && (a.usertype = this.readArray("uint", 1, 16)), a.view = this.slice(t, o), a;
1531
- }, this.readBoxes = (e = -1) => {
1532
- let t = [];
1533
- for (let n of this) if (t.push(n), e > 0 && t.length >= e) break;
1534
- return t;
1535
- }, this.readEntries = (e, t) => {
1536
- let n = [];
1537
- for (let r = 0; r < e; r++) n.push(t());
1538
- return n;
1539
- }, this.dataView = en(t) ? new DataView(t) : t instanceof DataView ? t : new DataView(t.buffer, t.byteOffset, t.byteLength), this.offset = this.dataView.byteOffset, this.config = n || {};
1540
- }
1541
- get buffer() {
1542
- return this.dataView.buffer;
1543
- }
1544
- get byteOffset() {
1545
- return this.dataView.byteOffset;
1546
- }
1547
- get byteLength() {
1548
- return this.dataView.byteLength;
1549
- }
1550
- get cursor() {
1551
- return this.offset - this.dataView.byteOffset;
1552
- }
1553
- get done() {
1554
- return this.cursor >= this.dataView.byteLength || this.truncated;
1555
- }
1556
- get bytesRemaining() {
1557
- return this.dataView.byteLength - this.cursor;
1558
- }
1559
- *[Symbol.iterator]() {
1560
- let { readers: e = {} } = this.config;
1561
- for (; !this.done;) try {
1562
- let t = this.readBox(), { type: n, view: r } = t, i = e[n] || e[n.trim()];
1563
- if (i && Object.assign(t, i(r, n)), ln(t) && !t.boxes) {
1564
- let e = [];
1565
- for (let t of r) e.push(t);
1566
- t.boxes = e;
1567
- }
1568
- yield t;
1569
- } catch (e) {
1570
- if (e instanceof Error && e.message === "Truncated box") break;
1571
- throw e;
1572
- }
1573
- }
1574
- };
1575
- function Tn(e, t) {
1576
- let n = [];
1577
- for (let r of new wn(e, t)) n.push(r);
1578
- return n;
1579
- }
1580
- function En(e, t) {
1581
- return pn(e, sn(t));
1582
- }
1583
- function Dn(e, t) {
1584
- let { readArray: n, readUint: r, readTemplate: i, readBoxes: a } = t;
1585
- return {
1586
- type: e,
1587
- reserved1: n(L, 1, 6),
1588
- dataReferenceIndex: r(2),
1589
- reserved2: n(L, 4, 2),
1590
- channelcount: r(2),
1591
- samplesize: r(2),
1592
- preDefined: r(2),
1593
- reserved3: r(2),
1594
- samplerate: i(4),
1595
- boxes: a()
1596
- };
1597
- }
1598
- function On(e, t) {
1599
- let { readArray: n, readUint: r, readInt: i, readTemplate: a, readBoxes: o } = t;
1600
- return {
1601
- type: e,
1602
- reserved1: n(L, 1, 6),
1603
- dataReferenceIndex: r(2),
1604
- preDefined1: r(2),
1605
- reserved2: r(2),
1606
- preDefined2: n(L, 4, 3),
1607
- width: r(2),
1608
- height: r(2),
1609
- horizresolution: a(4),
1610
- vertresolution: a(4),
1611
- reserved3: r(4),
1612
- frameCount: r(2),
1613
- compressorName: n(L, 1, 32),
1614
- depth: r(2),
1615
- preDefined3: i(2),
1616
- boxes: o()
1617
- };
1618
- }
1619
- function kn(e) {
1620
- return On("avc1", e);
1621
- }
1622
- function An(e) {
1623
- return On("hev1", e);
1624
- }
1625
- function jn(e) {
1626
- return On("hvc1", e);
1627
- }
1628
- function Mn(e) {
1629
- return {
1630
- type: "mdat",
1631
- data: e.readData(-1)
1632
- };
1633
- }
1634
- function Nn(e) {
1635
- let { version: t, flags: n } = e.readFullBox(), r = e.readUint(t == 1 ? 8 : 4), i = e.readUint(t == 1 ? 8 : 4), a = e.readUint(4), o = e.readUint(t == 1 ? 8 : 4), s = e.readUint(2);
1636
- return {
1637
- type: "mdhd",
1638
- version: t,
1639
- flags: n,
1640
- creationTime: r,
1641
- modificationTime: i,
1642
- timescale: a,
1643
- duration: o,
1644
- language: String.fromCharCode((s >> 10 & 31) + 96, (s >> 5 & 31) + 96, (s & 31) + 96),
1645
- preDefined: e.readUint(2)
1646
- };
1647
- }
1648
- function Pn(e) {
1649
- return {
1650
- type: "mfhd",
1651
- ...e.readFullBox(),
1652
- sequenceNumber: e.readUint(4)
1653
- };
1654
- }
1655
- function Fn(e) {
1656
- return Dn("mp4a", e);
1657
- }
1658
- function In(e) {
1659
- let { version: t, flags: n } = e.readFullBox(), r = e.readUint(4);
1660
- return {
1661
- type: "stsd",
1662
- version: t,
1663
- flags: n,
1664
- entryCount: r,
1665
- entries: e.readBoxes(r)
1666
- };
1667
- }
1668
- function Ln(e) {
1669
- let { version: t, flags: n } = e.readFullBox();
1670
- return {
1671
- type: "tfdt",
1672
- version: t,
1673
- flags: n,
1674
- baseMediaDecodeTime: e.readUint(t == 1 ? 8 : 4)
1675
- };
1676
- }
1677
- function Rn(e) {
1678
- let { version: t, flags: n } = e.readFullBox();
1679
- return {
1680
- type: "tfhd",
1681
- version: t,
1682
- flags: n,
1683
- trackId: e.readUint(4),
1684
- baseDataOffset: n & 1 ? e.readUint(8) : void 0,
1685
- sampleDescriptionIndex: n & 2 ? e.readUint(4) : void 0,
1686
- defaultSampleDuration: n & 8 ? e.readUint(4) : void 0,
1687
- defaultSampleSize: n & 16 ? e.readUint(4) : void 0,
1688
- defaultSampleFlags: n & 32 ? e.readUint(4) : void 0
1689
- };
1690
- }
1691
- function zn(e) {
1692
- let { version: t, flags: n } = e.readFullBox(), r = t === 1 ? 8 : 4;
1693
- return {
1694
- type: "tkhd",
1695
- version: t,
1696
- flags: n,
1697
- creationTime: e.readUint(r),
1698
- modificationTime: e.readUint(r),
1699
- trackId: e.readUint(4),
1700
- reserved1: e.readUint(4),
1701
- duration: e.readUint(r),
1702
- reserved2: e.readArray(L, 4, 2),
1703
- layer: e.readUint(2),
1704
- alternateGroup: e.readUint(2),
1705
- volume: e.readTemplate(2),
1706
- reserved3: e.readUint(2),
1707
- matrix: e.readArray(R, 4, 9),
1708
- width: e.readTemplate(4),
1709
- height: e.readTemplate(4)
1710
- };
1711
- }
1712
- function Bn(e) {
1713
- return {
1714
- type: "trex",
1715
- ...e.readFullBox(),
1716
- trackId: e.readUint(4),
1717
- defaultSampleDescriptionIndex: e.readUint(4),
1718
- defaultSampleDuration: e.readUint(4),
1719
- defaultSampleSize: e.readUint(4),
1720
- defaultSampleFlags: e.readUint(4)
1721
- };
1722
- }
1723
- function Vn(e) {
1724
- let { version: t, flags: n } = e.readFullBox(), r = e.readUint(4), i, a;
1725
- n & 1 && (i = e.readInt(4)), n & 4 && (a = e.readUint(4));
1726
- let o = e.readEntries(r, () => {
1727
- let r = {};
1728
- return n & 256 && (r.sampleDuration = e.readUint(4)), n & 512 && (r.sampleSize = e.readUint(4)), n & 1024 && (r.sampleFlags = e.readUint(4)), n & 2048 && (r.sampleCompositionTimeOffset = t === 1 ? e.readInt(4) : e.readUint(4)), r;
1729
- });
1730
- return {
1731
- type: "trun",
1732
- version: t,
1733
- flags: n,
1734
- sampleCount: r,
1735
- dataOffset: i,
1736
- firstSampleFlags: a,
1737
- samples: o
1738
- };
1739
- }
1740
- function Hn(e, t) {
1741
- let n = e.entries.length, { bytes: r, size: i } = mn(e.entries, t), a = new z("dref", 16 + i);
1742
- return a.writeFullBox(e.version, e.flags), a.writeUint(n, 4), a.writeBytes(r), a;
1743
- }
1744
- function Un(e) {
1745
- let t = new z("ftyp", 16 + e.compatibleBrands.length * 4);
1746
- t.writeString(e.majorBrand), t.writeUint(e.minorVersion, 4);
1747
- for (let n of e.compatibleBrands) t.writeString(n);
1748
- return t;
1749
- }
1750
- function Wn(e) {
1751
- let t = new z("hdlr", 32 + (e.name.length + 1));
1752
- return t.writeFullBox(e.version, e.flags), t.writeUint(e.preDefined, 4), t.writeString(e.handlerType), t.writeArray(e.reserved, L, 4, 3), t.writeTerminatedString(e.name), t;
1753
- }
1754
- function Gn(e) {
1755
- let t = new z("mdat", 8 + e.data.length);
1756
- return t.writeBytes(e.data), t;
1757
- }
1758
- function Kn(e) {
1759
- let t = e.version === 1 ? 8 : 4, n = new z("mdhd", 12 + t * 3 + 4 + 2 + 2);
1760
- n.writeFullBox(e.version, e.flags), n.writeUint(e.creationTime, t), n.writeUint(e.modificationTime, t), n.writeUint(e.timescale, 4), n.writeUint(e.duration, t);
1761
- let r = e.language.length >= 3 ? (e.language.charCodeAt(0) - 96 & 31) << 10 | (e.language.charCodeAt(1) - 96 & 31) << 5 | e.language.charCodeAt(2) - 96 & 31 : 0;
1762
- return n.writeUint(r, 2), n.writeUint(e.preDefined, 2), n;
1763
- }
1764
- function qn(e) {
1765
- let t = new z("mfhd", 16);
1766
- return t.writeFullBox(e.version, e.flags), t.writeUint(e.sequenceNumber, 4), t;
1767
- }
1768
- function Jn(e) {
1769
- let t = e.version === 1 ? 8 : 4, n = new z("mvhd", 12 + t * 3 + 4 + 4 + 2 + 2 + 8 + 36 + 24 + 4);
1770
- return n.writeFullBox(e.version, e.flags), n.writeUint(e.creationTime, t), n.writeUint(e.modificationTime, t), n.writeUint(e.timescale, 4), n.writeUint(e.duration, t), n.writeTemplate(e.rate, 4), n.writeTemplate(e.volume, 2), n.writeUint(e.reserved1, 2), n.writeArray(e.reserved2, L, 4, 2), n.writeArray(e.matrix, R, 4, 9), n.writeArray(e.preDefined, L, 4, 6), n.writeUint(e.nextTrackId, 4), n;
1771
- }
1772
- function Yn(e) {
1773
- let t = new z("smhd", 16);
1774
- return t.writeFullBox(e.version, e.flags), t.writeUint(e.balance, 2), t.writeUint(e.reserved, 2), t;
1775
- }
1776
- function Xn(e, t) {
1777
- let n = e.entries.length, { bytes: r, size: i } = mn(e.entries, t), a = new z("stsd", 16 + i);
1778
- return a.writeFullBox(e.version, e.flags), a.writeUint(n, 4), a.writeBytes(r), a;
1779
- }
1780
- function Zn(e) {
1781
- let t = new z("stts", 16 + e.entryCount * 8);
1782
- t.writeFullBox(e.version, e.flags), t.writeUint(e.entryCount, 4);
1783
- for (let n of e.entries) t.writeUint(n.sampleCount, 4), t.writeUint(n.sampleDelta, 4);
1784
- return t;
1785
- }
1786
- function Qn(e) {
1787
- let t = e.version === 1 ? 8 : 4, n = new z("tfdt", 12 + t);
1788
- return n.writeFullBox(e.version, e.flags), n.writeUint(e.baseMediaDecodeTime, t), n;
1789
- }
1790
- function $n(e) {
1791
- let t = e.flags & 1 ? 8 : 0, n = e.flags & 2 ? 4 : 0, r = e.flags & 8 ? 4 : 0, i = e.flags & 16 ? 4 : 0, a = e.flags & 32 ? 4 : 0, o = new z("tfhd", 16 + t + n + r + i + a);
1792
- return o.writeFullBox(e.version, e.flags), o.writeUint(e.trackId, 4), e.flags & 1 && o.writeUint(e.baseDataOffset ?? 0, 8), e.flags & 2 && o.writeUint(e.sampleDescriptionIndex ?? 0, 4), e.flags & 8 && o.writeUint(e.defaultSampleDuration ?? 0, 4), e.flags & 16 && o.writeUint(e.defaultSampleSize ?? 0, 4), e.flags & 32 && o.writeUint(e.defaultSampleFlags ?? 0, 4), o;
1793
- }
1794
- function er(e) {
1795
- let t = e.version === 1 ? 8 : 4, n = new z("tkhd", 12 + t * 3 + 4 + 4 + 8 + 2 + 2 + 2 + 2 + 36 + 4 + 4);
1796
- return n.writeFullBox(e.version, e.flags), n.writeUint(e.creationTime, t), n.writeUint(e.modificationTime, t), n.writeUint(e.trackId, 4), n.writeUint(e.reserved1, 4), n.writeUint(e.duration, t), n.writeArray(e.reserved2, L, 4, 2), n.writeUint(e.layer, 2), n.writeUint(e.alternateGroup, 2), n.writeTemplate(e.volume, 2), n.writeUint(e.reserved3, 2), n.writeArray(e.matrix, R, 4, 9), n.writeTemplate(e.width, 4), n.writeTemplate(e.height, 4), n;
1797
- }
1798
- function tr(e) {
1799
- let t = new z("trex", 32);
1800
- return t.writeFullBox(e.version, e.flags), t.writeUint(e.trackId, 4), t.writeUint(e.defaultSampleDescriptionIndex, 4), t.writeUint(e.defaultSampleDuration, 4), t.writeUint(e.defaultSampleSize, 4), t.writeUint(e.defaultSampleFlags, 4), t;
1801
- }
1802
- function nr(e) {
1803
- let t = e.flags & 1 ? 4 : 0, n = e.flags & 4 ? 4 : 0, r = 0;
1804
- e.flags & 256 && (r += 4), e.flags & 512 && (r += 4), e.flags & 1024 && (r += 4), e.flags & 2048 && (r += 4);
1805
- let i = r * e.sampleCount, a = new z("trun", 16 + t + n + i);
1806
- a.writeFullBox(e.version, e.flags), a.writeUint(e.sampleCount, 4), e.flags & 1 && a.writeUint(e.dataOffset ?? 0, 4), e.flags & 4 && a.writeUint(e.firstSampleFlags ?? 0, 4);
1807
- for (let t of e.samples) e.flags & 256 && a.writeUint(t.sampleDuration ?? 0, 4), e.flags & 512 && a.writeUint(t.sampleSize ?? 0, 4), e.flags & 1024 && a.writeUint(t.sampleFlags ?? 0, 4), e.flags & 2048 && a.writeUint(t.sampleCompositionTimeOffset ?? 0, 4);
1808
- return a;
1809
- }
1810
- function rr(e) {
1811
- let t = new z("url ", 12 + (e.location.length + 1));
1812
- return t.writeFullBox(e.version, e.flags), t.writeTerminatedString(e.location), t;
1813
- }
1814
- function ir(e) {
1815
- let t = new z("vmhd", 20);
1816
- return t.writeFullBox(e.version, e.flags), t.writeUint(e.graphicsmode, 2), t.writeArray(e.opcolor, L, 2, 3), t;
1817
- }
1818
- //#endregion
1819
- //#region ../hang/src/container/cmaf/decode.ts
1820
- var ar = {
1821
- avc1: kn,
1822
- avc3: kn,
1823
- hvc1: jn,
1824
- hev1: An,
1825
- mp4a: Fn,
1826
- stsd: In,
1827
- mdhd: Nn,
1828
- tkhd: zn,
1829
- trex: Bn
1830
- }, or = {
1831
- mfhd: Pn,
1832
- tfhd: Rn,
1833
- tfdt: Ln,
1834
- trun: Vn,
1835
- mdat: Mn
1836
- };
1837
- function V(e, t) {
1838
- for (let n of e) {
1839
- if (t(n)) return n;
1840
- let e = n.boxes;
1841
- if (e && Array.isArray(e)) {
1842
- let n = V(e, t);
1843
- if (n) return n;
1844
- }
1845
- }
1846
- }
1847
- function sr(e) {
1848
- let t = new ArrayBuffer(e.byteLength);
1849
- return new Uint8Array(t).set(e), t;
1850
- }
1851
- function H(e) {
1852
- return (t) => t.type === e;
1853
- }
1854
- function U(e) {
1855
- let t = Tn(sr(e), { readers: ar }), n = V(t, H("mdhd"));
1856
- if (!n) throw Error("No mdhd box found in init segment");
1857
- let r = V(t, H("tkhd"))?.trackId ?? 1, i = V(t, H("stsd"));
1858
- if (!i?.entries || i.entries.length === 0) throw Error("No stsd box found in init segment");
1859
- let a = i.entries[0], o = cr(a), s = V(t, (e) => e.type === "trex" && e.trackId === r);
1860
- return {
1861
- description: o,
1862
- timescale: n.timescale,
1863
- trackId: r,
1864
- defaultSampleDuration: s?.defaultSampleDuration ?? 0,
1865
- defaultSampleSize: s?.defaultSampleSize ?? 0,
1866
- defaultSampleFlags: s?.defaultSampleFlags ?? 0
1867
- };
1868
- }
1869
- function cr(e) {
1870
- if (!(!e.boxes || !Array.isArray(e.boxes))) for (let t of e.boxes) {
1871
- if (t instanceof Uint8Array) {
1872
- if (t.length > 8) {
1873
- let e = String.fromCharCode(t[4], t[5], t[6], t[7]);
1874
- if (e === "avcC" || e === "hvcC" || e === "dOps") return new Uint8Array(t.slice(8));
1875
- if (e === "esds") return lr(new Uint8Array(t.slice(8)));
1876
- }
1877
- continue;
1878
- }
1879
- let e = t.type;
1880
- if (e === "avcC" || e === "hvcC" || e === "dOps") {
1881
- if (t.view) {
1882
- let e = t.view, n = e.byteOffset + 8, r = t.size - 8;
1883
- return new Uint8Array(e.buffer, n, r);
1884
- }
1885
- if (t.data instanceof Uint8Array) return new Uint8Array(t.data);
1886
- if (t.raw instanceof Uint8Array) return new Uint8Array(t.raw.slice(8));
1887
- }
1888
- if (e === "esds") {
1889
- let e;
1890
- if (t.view) {
1891
- let n = t.view;
1892
- e = new Uint8Array(n.buffer, n.byteOffset + 8, t.size - 8);
1893
- } else t.data instanceof Uint8Array ? e = new Uint8Array(t.data) : t.raw instanceof Uint8Array && (e = new Uint8Array(t.raw.slice(8)));
1894
- if (e) return lr(e);
1895
- }
1896
- }
1897
- }
1898
- function lr(e) {
1899
- let t = 4;
1900
- for (; t < e.length;) {
1901
- let n = e[t++], r = 0;
1902
- for (let n = 0; n < 4 && t < e.length; n++) {
1903
- let n = e[t++];
1904
- if (r = r << 7 | n & 127, !(n & 128)) break;
1905
- }
1906
- if (n === 5) return t + r <= e.length ? new Uint8Array(e.buffer, e.byteOffset + t, r) : void 0;
1907
- n === 3 ? t += 3 : n === 4 ? t += 13 : t += r;
1908
- }
1909
- }
1910
- function ur(e, t) {
1911
- return (V(Tn(sr(e), { readers: or }), H("tfdt"))?.baseMediaDecodeTime ?? 0) * 1e6 / t.timescale;
1912
- }
1913
- function dr(e, t) {
1914
- let n = Tn(sr(e), { readers: or }), r = V(n, H("tfdt"))?.baseMediaDecodeTime ?? 0, i = V(n, H("tfhd")), a = i?.defaultSampleDuration ?? t.defaultSampleDuration, o = i?.defaultSampleSize ?? t.defaultSampleSize, s = i?.defaultSampleFlags ?? t.defaultSampleFlags, c = V(n, H("trun"));
1915
- if (!c) throw Error("No trun box found in data segment");
1916
- let l = V(n, H("mdat"));
1917
- if (!l) throw Error("No mdat box found in data segment");
1918
- let u = l.data;
1919
- if (!u) throw Error("No data in mdat box");
1920
- let d = [], f = 0, p = r;
1921
- for (let e = 0; e < c.sampleCount; e++) {
1922
- let n = c.samples[e] ?? {}, r = n.sampleSize ?? o, i = n.sampleDuration ?? a;
1923
- if (r <= 0) throw Error(`Invalid sample size ${r} for sample ${e} in trun`);
1924
- if (i < 0) throw Error(`Invalid sample duration ${i} for sample ${e} in trun`);
1925
- if (f + r > u.length) throw Error(`Sample ${e} would overflow mdat: offset=${f}, size=${r}, mdatLength=${u.length}`);
1926
- let l = e === 0 && c.firstSampleFlags !== void 0 ? c.firstSampleFlags : n.sampleFlags ?? s, m = n.sampleCompositionTimeOffset ?? 0, ee = new Uint8Array(u.slice(f, f + r));
1927
- f += r;
1928
- let te = p + m, h = Math.round(te * 1e6 / t.timescale), g = l === 0 || (l & 65536) == 0;
1929
- d.push({
1930
- data: ee,
1931
- timestamp: h,
1932
- keyframe: g
1933
- }), p += i;
1934
- }
1935
- return d;
1936
- }
1937
- //#endregion
1938
- //#region ../hang/src/util/hex.ts
1939
- function W(e) {
1940
- if (e = e.startsWith("0x") ? e.slice(2) : e, e.length % 2) throw Error("invalid hex string length");
1941
- let t = e.match(/.{2}/g);
1942
- if (!t) throw Error("invalid hex string format");
1943
- return new Uint8Array(t.map((e) => parseInt(e, 16)));
1944
- }
1945
- //#endregion
1946
- //#region ../hang/src/container/cmaf/encode.ts
1947
- var fr = [
1948
- 65536,
1949
- 0,
1950
- 0,
1951
- 0,
1952
- 65536,
1953
- 0,
1954
- 0,
1955
- 0,
1956
- 1073741824
1957
- ], pr = {
1958
- ftyp: Un,
1959
- mvhd: Jn,
1960
- tkhd: er,
1961
- mdhd: Kn,
1962
- hdlr: Wn,
1963
- vmhd: ir,
1964
- smhd: Yn,
1965
- "url ": rr,
1966
- dref: Hn,
1967
- stsd: Xn,
1968
- stts: Zn,
1969
- trex: tr,
1970
- mfhd: qn,
1971
- tfhd: $n,
1972
- tfdt: Qn,
1973
- trun: nr,
1974
- mdat: Gn
1975
- };
1976
- function G(e) {
1977
- return En(e, { writers: pr });
1978
- }
1979
- function mr(e, t, n, r) {
1980
- let i = 12 + r.length, a = new Uint8Array(i), o = new DataView(a.buffer);
1981
- return o.setUint32(0, i, !1), a[4] = e.charCodeAt(0), a[5] = e.charCodeAt(1), a[6] = e.charCodeAt(2), a[7] = e.charCodeAt(3), o.setUint32(8, t << 24 | n, !1), a.set(r, 12), a;
1982
- }
1983
- function hr() {
1984
- return mr("stsc", 0, 0, new Uint8Array(4));
1985
- }
1986
- function gr() {
1987
- return mr("stsz", 0, 0, new Uint8Array(8));
1988
- }
1989
- function _r() {
1990
- return mr("stco", 0, 0, new Uint8Array(4));
1991
- }
1992
- function vr(e, t, n) {
1993
- let r = 8 + n.length, i = 8 + (78 + r), a = new Uint8Array(i), o = new DataView(a.buffer), s = 0;
1994
- return o.setUint32(s, i, !1), s += 4, a[s++] = 97, a[s++] = 118, a[s++] = 99, a[s++] = 49, s += 6, o.setUint16(s, 1, !1), s += 2, o.setUint16(s, 0, !1), s += 2, o.setUint16(s, 0, !1), s += 2, s += 12, o.setUint16(s, e, !1), s += 2, o.setUint16(s, t, !1), s += 2, o.setUint32(s, 4718592, !1), s += 4, o.setUint32(s, 4718592, !1), s += 4, o.setUint32(s, 0, !1), s += 4, o.setUint16(s, 1, !1), s += 2, s += 32, o.setUint16(s, 24, !1), s += 2, o.setUint16(s, 65535, !1), s += 2, o.setUint32(s, r, !1), s += 4, a[s++] = 97, a[s++] = 118, a[s++] = 99, a[s++] = 67, a.set(n, s), a;
1995
- }
1996
- function yr(e) {
1997
- let { codedWidth: t, codedHeight: n, description: r } = e;
1998
- if (!t || !n || !r) throw Error("Missing required fields to create video init segment");
1999
- let i = 1e6, a = G([{
2000
- type: "ftyp",
2001
- majorBrand: "isom",
2002
- minorVersion: 512,
2003
- compatibleBrands: [
2004
- "isom",
2005
- "iso6",
2006
- "mp41"
2007
- ]
2008
- }, {
2009
- type: "moov",
2010
- boxes: [
2011
- {
2012
- type: "mvhd",
2013
- version: 0,
2014
- flags: 0,
2015
- creationTime: 0,
2016
- modificationTime: 0,
2017
- timescale: i,
2018
- duration: 0,
2019
- rate: 65536,
2020
- volume: 256,
2021
- reserved1: 0,
2022
- reserved2: [0, 0],
2023
- matrix: fr,
2024
- preDefined: [
2025
- 0,
2026
- 0,
2027
- 0,
2028
- 0,
2029
- 0,
2030
- 0
2031
- ],
2032
- nextTrackId: 2
2033
- },
2034
- {
2035
- type: "trak",
2036
- boxes: [{
2037
- type: "tkhd",
2038
- version: 0,
2039
- flags: 3,
2040
- creationTime: 0,
2041
- modificationTime: 0,
2042
- trackId: 1,
2043
- reserved1: 0,
2044
- duration: 0,
2045
- reserved2: [0, 0],
2046
- layer: 0,
2047
- alternateGroup: 0,
2048
- volume: 0,
2049
- reserved3: 0,
2050
- matrix: fr,
2051
- width: t * 65536,
2052
- height: n * 65536
2053
- }, {
2054
- type: "mdia",
2055
- boxes: [
2056
- {
2057
- type: "mdhd",
2058
- version: 0,
2059
- flags: 0,
2060
- creationTime: 0,
2061
- modificationTime: 0,
2062
- timescale: i,
2063
- duration: 0,
2064
- language: "und",
2065
- preDefined: 0
2066
- },
2067
- {
2068
- type: "hdlr",
2069
- version: 0,
2070
- flags: 0,
2071
- preDefined: 0,
2072
- handlerType: "vide",
2073
- reserved: [
2074
- 0,
2075
- 0,
2076
- 0
2077
- ],
2078
- name: "VideoHandler"
2079
- },
2080
- {
2081
- type: "minf",
2082
- boxes: [
2083
- {
2084
- type: "vmhd",
2085
- version: 0,
2086
- flags: 1,
2087
- graphicsmode: 0,
2088
- opcolor: [
2089
- 0,
2090
- 0,
2091
- 0
2092
- ]
2093
- },
2094
- {
2095
- type: "dinf",
2096
- boxes: [{
2097
- type: "dref",
2098
- version: 0,
2099
- flags: 0,
2100
- entryCount: 1,
2101
- entries: [{
2102
- type: "url ",
2103
- version: 0,
2104
- flags: 1,
2105
- location: ""
2106
- }]
2107
- }]
2108
- },
2109
- {
2110
- type: "stbl",
2111
- boxes: [
2112
- {
2113
- type: "stsd",
2114
- version: 0,
2115
- flags: 0,
2116
- entryCount: 1,
2117
- entries: [vr(t, n, W(r))]
2118
- },
2119
- {
2120
- type: "stts",
2121
- version: 0,
2122
- flags: 0,
2123
- entryCount: 0,
2124
- entries: []
2125
- },
2126
- hr(),
2127
- gr(),
2128
- _r()
2129
- ]
2130
- }
2131
- ]
2132
- }
2133
- ]
2134
- }]
2135
- },
2136
- {
2137
- type: "mvex",
2138
- boxes: [{
2139
- type: "trex",
2140
- version: 0,
2141
- flags: 0,
2142
- trackId: 1,
2143
- defaultSampleDescriptionIndex: 1,
2144
- defaultSampleDuration: 0,
2145
- defaultSampleSize: 0,
2146
- defaultSampleFlags: 0
2147
- }]
2148
- }
2149
- ]
2150
- }]), o = a.reduce((e, t) => e + t.byteLength, 0), s = new Uint8Array(o), c = 0;
2151
- for (let e of a) s.set(new Uint8Array(e.buffer, e.byteOffset, e.byteLength), c), c += e.byteLength;
2152
- return s;
2153
- }
2154
- function br(e) {
2155
- let { sampleRate: t, numberOfChannels: n, description: r, codec: i } = e, a = 1e6, o = G([{
2156
- type: "ftyp",
2157
- majorBrand: "isom",
2158
- minorVersion: 512,
2159
- compatibleBrands: [
2160
- "isom",
2161
- "iso6",
2162
- "mp41"
2163
- ]
2164
- }, {
2165
- type: "moov",
2166
- boxes: [
2167
- {
2168
- type: "mvhd",
2169
- version: 0,
2170
- flags: 0,
2171
- creationTime: 0,
2172
- modificationTime: 0,
2173
- timescale: a,
2174
- duration: 0,
2175
- rate: 65536,
2176
- volume: 256,
2177
- reserved1: 0,
2178
- reserved2: [0, 0],
2179
- matrix: fr,
2180
- preDefined: [
2181
- 0,
2182
- 0,
2183
- 0,
2184
- 0,
2185
- 0,
2186
- 0
2187
- ],
2188
- nextTrackId: 2
2189
- },
2190
- {
2191
- type: "trak",
2192
- boxes: [{
2193
- type: "tkhd",
2194
- version: 0,
2195
- flags: 3,
2196
- creationTime: 0,
2197
- modificationTime: 0,
2198
- trackId: 1,
2199
- reserved1: 0,
2200
- duration: 0,
2201
- reserved2: [0, 0],
2202
- layer: 0,
2203
- alternateGroup: 0,
2204
- volume: 256,
2205
- reserved3: 0,
2206
- matrix: fr,
2207
- width: 0,
2208
- height: 0
2209
- }, {
2210
- type: "mdia",
2211
- boxes: [
2212
- {
2213
- type: "mdhd",
2214
- version: 0,
2215
- flags: 0,
2216
- creationTime: 0,
2217
- modificationTime: 0,
2218
- timescale: a,
2219
- duration: 0,
2220
- language: "und",
2221
- preDefined: 0
2222
- },
2223
- {
2224
- type: "hdlr",
2225
- version: 0,
2226
- flags: 0,
2227
- preDefined: 0,
2228
- handlerType: "soun",
2229
- reserved: [
2230
- 0,
2231
- 0,
2232
- 0
2233
- ],
2234
- name: "SoundHandler"
2235
- },
2236
- {
2237
- type: "minf",
2238
- boxes: [
2239
- {
2240
- type: "smhd",
2241
- version: 0,
2242
- flags: 0,
2243
- balance: 0,
2244
- reserved: 0
2245
- },
2246
- {
2247
- type: "dinf",
2248
- boxes: [{
2249
- type: "dref",
2250
- version: 0,
2251
- flags: 0,
2252
- entryCount: 1,
2253
- entries: [{
2254
- type: "url ",
2255
- version: 0,
2256
- flags: 1,
2257
- location: ""
2258
- }]
2259
- }]
2260
- },
2261
- {
2262
- type: "stbl",
2263
- boxes: [
2264
- {
2265
- type: "stsd",
2266
- version: 0,
2267
- flags: 0,
2268
- entryCount: 1,
2269
- entries: [xr(i, t, n, r)]
2270
- },
2271
- {
2272
- type: "stts",
2273
- version: 0,
2274
- flags: 0,
2275
- entryCount: 0,
2276
- entries: []
2277
- },
2278
- hr(),
2279
- gr(),
2280
- _r()
2281
- ]
2282
- }
2283
- ]
2284
- }
2285
- ]
2286
- }]
2287
- },
2288
- {
2289
- type: "mvex",
2290
- boxes: [{
2291
- type: "trex",
2292
- version: 0,
2293
- flags: 0,
2294
- trackId: 1,
2295
- defaultSampleDescriptionIndex: 1,
2296
- defaultSampleDuration: 0,
2297
- defaultSampleSize: 0,
2298
- defaultSampleFlags: 0
2299
- }]
2300
- }
2301
- ]
2302
- }]), s = o.reduce((e, t) => e + t.byteLength, 0), c = new Uint8Array(s), l = 0;
2303
- for (let e of o) c.set(new Uint8Array(e.buffer, e.byteOffset, e.byteLength), l), l += e.byteLength;
2304
- return c;
2305
- }
2306
- function xr(e, t, n, r) {
2307
- if (e.startsWith("mp4a")) return Sr(t, n, r);
2308
- if (e === "opus") return Cr(t, n, r);
2309
- throw Error(`Unsupported audio codec: ${e}`);
2310
- }
2311
- function Sr(e, t, n) {
2312
- let r = Tr(e, t, n), i = 8 + (28 + r.length), a = new Uint8Array(i), o = new DataView(a.buffer), s = 0;
2313
- return o.setUint32(s, i, !1), s += 4, a[s++] = 109, a[s++] = 112, a[s++] = 52, a[s++] = 97, s += 6, o.setUint16(s, 1, !1), s += 2, s += 8, o.setUint16(s, t, !1), s += 2, o.setUint16(s, 16, !1), s += 2, o.setUint16(s, 0, !1), s += 2, o.setUint16(s, 0, !1), s += 2, o.setUint32(s, e * 65536, !1), s += 4, a.set(r, s), a;
2314
- }
2315
- function Cr(e, t, n) {
2316
- let r = Er(t, e, n), i = 8 + (28 + r.length), a = new Uint8Array(i), o = new DataView(a.buffer), s = 0;
2317
- return o.setUint32(s, i, !1), s += 4, a[s++] = 79, a[s++] = 112, a[s++] = 117, a[s++] = 115, s += 6, o.setUint16(s, 1, !1), s += 2, s += 8, o.setUint16(s, t, !1), s += 2, o.setUint16(s, 16, !1), s += 2, o.setUint16(s, 0, !1), s += 2, o.setUint16(s, 0, !1), s += 2, o.setUint32(s, e * 65536, !1), s += 4, a.set(r, s), a;
2318
- }
2319
- function wr(e, t) {
2320
- let n = {
2321
- 96e3: 0,
2322
- 88200: 1,
2323
- 64e3: 2,
2324
- 48e3: 3,
2325
- 44100: 4,
2326
- 32e3: 5,
2327
- 24e3: 6,
2328
- 22050: 7,
2329
- 16e3: 8,
2330
- 12e3: 9,
2331
- 11025: 10,
2332
- 8e3: 11,
2333
- 7350: 12
2334
- }[e] ?? 4, r = 16 | n >> 1, i = (n & 1) << 7 | t << 3;
2335
- return new Uint8Array([r, i]);
2336
- }
2337
- function Tr(e, t, n) {
2338
- let r = n ? W(n) : wr(e, t), i = r.length, a = 15 + i, o = 5 + a + 3, s = 14 + o, c = new Uint8Array(s), l = new DataView(c.buffer), u = 0;
2339
- return l.setUint32(u, s, !1), u += 4, c[u++] = 101, c[u++] = 115, c[u++] = 100, c[u++] = 115, l.setUint32(u, 0, !1), u += 4, c[u++] = 3, c[u++] = o, l.setUint16(u, 0, !1), u += 2, c[u++] = 0, c[u++] = 4, c[u++] = a, c[u++] = 64, c[u++] = 21, c[u++] = 0, c[u++] = 0, c[u++] = 0, l.setUint32(u, 0, !1), u += 4, l.setUint32(u, 0, !1), u += 4, c[u++] = 5, c[u++] = i, c.set(r, u), u += i, c[u++] = 6, c[u++] = 1, c[u++] = 2, c;
2340
- }
2341
- function Er(e, t, n) {
2342
- if (n) {
2343
- let e = W(n), t = 8 + e.length, r = new Uint8Array(t);
2344
- return new DataView(r.buffer).setUint32(0, t, !1), r[4] = 100, r[5] = 79, r[6] = 112, r[7] = 115, r.set(e, 8), r;
2345
- }
2346
- let r = new Uint8Array(19), i = new DataView(r.buffer), a = 0;
2347
- return i.setUint32(a, 19, !1), a += 4, r[a++] = 100, r[a++] = 79, r[a++] = 112, r[a++] = 115, r[a++] = 0, r[a++] = e, i.setUint16(a, 312, !1), a += 2, i.setUint32(a, t, !1), a += 4, i.setInt16(a, 0, !1), a += 2, r[a++] = 0, r;
2348
- }
2349
- function Dr(e) {
2350
- let { data: t, timestamp: n, duration: r, keyframe: i, sequence: a, trackId: o = 1 } = e, s = i ? 33554432 : 16842752, c = {
2351
- type: "mfhd",
2352
- version: 0,
2353
- flags: 0,
2354
- sequenceNumber: a
2355
- }, l = {
2356
- type: "tfhd",
2357
- version: 0,
2358
- flags: 131072,
2359
- trackId: o
2360
- }, u = {
2361
- type: "tfdt",
2362
- version: 1,
2363
- flags: 0,
2364
- baseMediaDecodeTime: n
2365
- }, d = {
2366
- type: "trun",
2367
- version: 0,
2368
- flags: 1793,
2369
- sampleCount: 1,
2370
- dataOffset: 0,
2371
- samples: [{
2372
- sampleDuration: r,
2373
- sampleSize: t.byteLength,
2374
- sampleFlags: s
2375
- }]
2376
- }, f = {
2377
- type: "moof",
2378
- boxes: [c, {
2379
- type: "traf",
2380
- boxes: [
2381
- l,
2382
- u,
2383
- d
2384
- ]
2385
- }]
2386
- }, p = G([f]), m = 0;
2387
- for (let e of p) m += e.byteLength;
2388
- d.dataOffset = m + 8;
2389
- let ee = G([f]);
2390
- m = 0;
2391
- for (let e of ee) m += e.byteLength;
2392
- let te = new ArrayBuffer(t.byteLength), h = new Uint8Array(te);
2393
- h.set(t);
2394
- let g = G([{
2395
- type: "mdat",
2396
- data: h
2397
- }]), _ = 0;
2398
- for (let e of g) _ += e.byteLength;
2399
- let v = new Uint8Array(m + _), y = 0;
2400
- for (let e of ee) v.set(new Uint8Array(e.buffer, e.byteOffset, e.byteLength), y), y += e.byteLength;
2401
- for (let e of g) v.set(new Uint8Array(e.buffer, e.byteOffset, e.byteLength), y), y += e.byteLength;
2402
- return v;
2403
- }
2404
- //#endregion
2405
- //#region ../hang/src/container/cmaf/format.ts
2406
- var Or = class {
2407
- #e;
2408
- constructor(e) {
2409
- this.#e = e;
2410
- }
2411
- decode(e) {
2412
- return dr(e, this.#e).map((e) => ({
2413
- data: e.data,
2414
- timestamp: e.timestamp,
2415
- keyframe: e.keyframe
2416
- }));
2417
- }
2418
- }, K = class {
2419
- #e;
2420
- #t;
2421
- #n;
2422
- #r = [];
2423
- #i;
2424
- #a;
2425
- #o = new i([]);
2426
- buffered = this.#o;
2427
- #s = new r();
2428
- constructor(t, n) {
2429
- this.#e = t, this.#t = n.format, this.#n = i.from(n.latency ?? e.Time.Milli.zero), this.#s.spawn(this.#c.bind(this)), this.#s.cleanup(() => {
2430
- this.#e.close();
2431
- for (let e of this.#r) e.consumer.close();
2432
- this.#r.length = 0;
2433
- });
2434
- }
2435
- async #c() {
2436
- for (;;) {
2437
- let e = await this.#e.recvGroup();
2438
- if (!e) break;
2439
- if (this.#i === void 0 && (this.#i = e.sequence), e.sequence < this.#i) {
2440
- console.warn(`skipping old group: ${e.sequence} < ${this.#i}`), e.close();
2441
- continue;
2442
- }
2443
- let t = {
2444
- consumer: e,
2445
- frames: []
2446
- };
2447
- this.#r.push(t), this.#r.sort((e, t) => e.consumer.sequence - t.consumer.sequence), this.#s.spawn(this.#l.bind(this, t));
2448
- }
2449
- }
2450
- async #l(e) {
2451
- try {
2452
- let t = 0;
2453
- for (;;) {
2454
- let n = await e.consumer.readFrame();
2455
- if (!n) break;
2456
- let r = this.#t.decode(n);
2457
- for (let n of r) {
2458
- let r = {
2459
- data: n.data,
2460
- timestamp: n.timestamp,
2461
- keyframe: t === 0 ? !0 : n.keyframe
2462
- };
2463
- t++, e.frames.push(r), (e.latest === void 0 || r.timestamp > e.latest) && (e.latest = r.timestamp), this.#d(), e.consumer.sequence === this.#i ? (this.#a?.(), this.#a = void 0) : this.#u();
2464
- }
2465
- }
2466
- } catch {} finally {
2467
- e.done = !0, e.consumer.sequence === this.#i && (this.#i += 1), this.#d(), this.#a?.(), this.#a = void 0, e.consumer.close();
2468
- }
2469
- }
2470
- #u() {
2471
- if (this.#i === void 0) return;
2472
- let t = !1;
2473
- for (; this.#r.length >= 2;) {
2474
- let n = e.Time.Micro.fromMilli(this.#n.peek()), r, i;
2475
- for (let e of this.#r) {
2476
- if (e.latest === void 0) continue;
2477
- let t = e.frames.at(0)?.timestamp ?? e.latest;
2478
- (r === void 0 || t < r) && (r = t), (i === void 0 || e.latest > i) && (i = e.latest);
2479
- }
2480
- if (r === void 0 || i === void 0 || i - r <= n) break;
2481
- let a = this.#r.shift();
2482
- if (!a) break;
2483
- this.#i = this.#r[0]?.consumer.sequence, console.warn(`skipping slow group: ${a.consumer.sequence} -> ${this.#i}`), a.consumer.close(), a.frames.length = 0, t = !0;
2484
- }
2485
- t && (this.#d(), this.#a?.(), this.#a = void 0);
2486
- }
2487
- async next() {
2488
- for (;;) {
2489
- if (this.#r.length > 0 && this.#i !== void 0 && this.#r[0].consumer.sequence <= this.#i) {
2490
- let e = this.#r[0].frames.shift();
2491
- if (e) return this.#d(), {
2492
- frame: e,
2493
- group: this.#r[0].consumer.sequence
2494
- };
2495
- if (this.#i > this.#r[0].consumer.sequence || this.#r[0].done) {
2496
- this.#r[0].consumer.sequence === this.#i && (this.#i += 1);
2497
- let e = this.#r.shift();
2498
- if (e) return this.#d(), {
2499
- frame: void 0,
2500
- group: e.consumer.sequence
2501
- };
2502
- }
2503
- }
2504
- if (this.#a) throw Error("multiple calls to next not supported");
2505
- let e = this.#s.abort;
2506
- if (e.aborted) return;
2507
- let t = await new Promise((t) => {
2508
- let n = () => t(!0);
2509
- e.addEventListener("abort", n, { once: !0 }), this.#a = () => {
2510
- e.removeEventListener("abort", n), t(!1);
2511
- };
2512
- });
2513
- if (this.#a = void 0, t) return;
2514
- }
2515
- }
2516
- #d() {
2517
- let t = [], n;
2518
- for (let r of this.#r) {
2519
- let i = r.frames.at(0);
2520
- if (!i || r.latest === void 0) continue;
2521
- let a = e.Time.Milli.fromMicro(i.timestamp), o = e.Time.Milli.fromMicro(r.latest), s = t.at(-1), c = n?.done && n.consumer.sequence + 1 === r.consumer.sequence;
2522
- s && (s.end >= a || c) ? s.end = e.Time.Milli.max(s.end, o) : t.push({
2523
- start: a,
2524
- end: o
2525
- }), n = r;
2526
- }
2527
- this.#o.set(t);
2528
- }
2529
- close() {
2530
- this.#s.close();
2531
- }
2532
- }, q = class {
2533
- decode(t) {
2534
- let [n, r] = e.Varint.decode(t);
2535
- return [{
2536
- data: r,
2537
- timestamp: n,
2538
- keyframe: !1
2539
- }];
2540
- }
2541
- };
2542
- //#endregion
2543
- //#region ../hang/src/container/types.ts
2544
- function kr(e, t) {
2545
- if (e.length === 0) return t;
2546
- if (t.length === 0) return e;
2547
- let r = [], i = [...e, ...t].sort((e, t) => e.start - t.start);
2548
- for (let e of i) {
2549
- let t = r.at(-1);
2550
- t && t.end >= e.start ? t.end = n.Milli.max(t.end, e.end) : r.push({ ...e });
2551
- }
2552
- return r;
2553
- }
2554
- //#endregion
2555
- //#region ../hang/src/util/libav.ts
2556
- var Ar;
2557
- async function jr() {
2558
- return globalThis.AudioEncoder && globalThis.AudioDecoder ? !0 : (Ar ||= (console.warn("using Opus polyfill; performance may be degraded"), Promise.all([import("./libav-opus-af-CzuaKpJb.js"), import("./main-bFFHfuX4.js")]).then(async ([e, t]) => (await t.load({
2559
- LibAV: e,
2560
- polyfill: !0
2561
- }), !0))), await Ar);
2562
- }
2563
- //#endregion
2564
- //#region src/base64.ts
2565
- function J(e) {
2566
- let t = atob(e), n = new Uint8Array(t.length);
2567
- for (let e = 0; e < t.length; e++) n[e] = t.charCodeAt(e);
2568
- return n;
2569
- }
2570
- //#endregion
2571
- //#region src/audio/shared-ring-buffer.ts
2572
- var Y = 0, X = 1, Z = 2, Q = 3, Mr = 4;
2573
- function Nr(e, t, n) {
2574
- if (e <= 0) throw Error("invalid channels");
2575
- if (t <= 0) throw Error("invalid capacity");
2576
- if (n <= 0) throw Error("invalid sample rate");
2577
- let r = new SharedArrayBuffer(e * t * Float32Array.BYTES_PER_ELEMENT), i = new SharedArrayBuffer(Mr * Int32Array.BYTES_PER_ELEMENT), a = new Int32Array(i);
2578
- return Atomics.store(a, Q, 1), {
2579
- channels: e,
2580
- capacity: t,
2581
- rate: n,
2582
- samples: r,
2583
- control: i
2584
- };
2585
- }
2586
- function Pr(e, t) {
2587
- return (e - t | 0) > 0 ? e : t;
2588
- }
2589
- function $(e, t) {
2590
- return (e % t + t) % t;
2591
- }
2592
- function Fr(e, t, n) {
2593
- for (;;) {
2594
- let r = Atomics.load(e, t);
2595
- if ((n - r | 0) <= 0) return r;
2596
- if (Atomics.compareExchange(e, t, r, n) === r) return n;
2597
- }
2598
- }
2599
- var Ir = class e {
2600
- channels;
2601
- capacity;
2602
- rate;
2603
- init;
2604
- #e;
2605
- #t;
2606
- constructor(e) {
2607
- this.channels = e.channels, this.capacity = e.capacity, this.rate = e.rate, this.init = e, this.#e = new Int32Array(e.control), this.#t = [];
2608
- for (let t = 0; t < this.channels; t++) this.#t.push(new Float32Array(e.samples, t * this.capacity * Float32Array.BYTES_PER_ELEMENT, this.capacity));
2609
- }
2610
- insert(e, t) {
2611
- if (t.length !== this.channels) throw Error("wrong number of channels");
2612
- let r = Math.round(n.Second.fromMicro(e) * this.rate), i = t[0].length, a = 0, o = r + i | 0, s = Atomics.load(this.#e, X), c = s - r | 0;
2613
- if (c > 0) {
2614
- if (c >= i) return;
2615
- a = c, r = r + c | 0;
2616
- }
2617
- let l = i - a;
2618
- (o - s | 0) > this.capacity && Fr(this.#e, X, o - this.capacity | 0);
2619
- let u = Atomics.load(this.#e, Y), d = r - u | 0;
2620
- if (d > 0) {
2621
- let e = Math.min(d, this.capacity);
2622
- for (let t = 0; t < this.channels; t++) {
2623
- let n = this.#t[t];
2624
- for (let t = 0; t < e; t++) n[$(u + t | 0, this.capacity)] = 0;
2625
- }
2626
- }
2627
- for (let e = 0; e < this.channels; e++) {
2628
- let n = t[e], i = this.#t[e];
2629
- for (let e = 0; e < l; e++) i[$(r + e | 0, this.capacity)] = n[a + e];
2630
- }
2631
- Atomics.store(this.#e, Y, Pr(Atomics.load(this.#e, Y), o));
2632
- let f = Atomics.load(this.#e, X), p = Atomics.load(this.#e, Y), m = Atomics.load(this.#e, Z);
2633
- (p - f | 0) >= m && m > 0 && Atomics.store(this.#e, Q, 0);
2634
- }
2635
- read(e) {
2636
- if (Atomics.load(this.#e, Q) === 1) return 0;
2637
- let t = Atomics.load(this.#e, X), n = Atomics.load(this.#e, Y), r = Atomics.load(this.#e, Z), i = n - t | 0;
2638
- if (r > 0 && i > r) {
2639
- let e = n - r | 0;
2640
- t = Fr(this.#e, X, e);
2641
- }
2642
- let a = n - t | 0, o = Math.min(a, e[0].length);
2643
- if (o <= 0) return 0;
2644
- for (let n = 0; n < this.channels; n++) {
2645
- let r = this.#t[n], i = e[n];
2646
- for (let e = 0; e < o; e++) i[e] = r[$(t + e | 0, this.capacity)];
2647
- }
2648
- return Fr(this.#e, X, t + o | 0), o;
2649
- }
2650
- setLatency(e) {
2651
- Atomics.store(this.#e, Z, e);
2652
- }
2653
- resize(t) {
2654
- let n = new e(Nr(this.channels, t, this.rate)), r = Atomics.load(this.#e, X), i = Atomics.load(this.#e, Y), a = Atomics.load(this.#e, Z), o = Atomics.load(this.#e, Q), s = i - r | 0, c = Math.max(0, Math.min(s, n.capacity)), l = i - c | 0;
2655
- for (let e = 0; e < this.channels; e++) {
2656
- let t = this.#t[e], r = n.#t[e];
2657
- for (let e = 0; e < c; e++) {
2658
- let i = l + e | 0;
2659
- r[$(i, n.capacity)] = t[$(i, this.capacity)];
2660
- }
2661
- }
2662
- return Atomics.store(n.#e, X, l), Atomics.store(n.#e, Y, i), Atomics.store(n.#e, Z, a), Atomics.store(n.#e, Q, o), n;
2663
- }
2664
- get timestamp() {
2665
- let e = Atomics.load(this.#e, X);
2666
- return n.Micro.fromSecond(e / this.rate);
2667
- }
2668
- get stalled() {
2669
- return Atomics.load(this.#e, Q) === 1;
2670
- }
2671
- get length() {
2672
- return Atomics.load(this.#e, Y) - Atomics.load(this.#e, X) | 0;
2673
- }
2674
- };
2675
- //#endregion
2676
- //#region src/audio/buffer.ts
2677
- function Lr() {
2678
- return !(typeof SharedArrayBuffer > "u" || typeof crossOriginIsolated < "u" && !crossOriginIsolated);
2679
- }
2680
- function Rr(e, t, n, r) {
2681
- return Lr() ? (console.log("[audio] using SharedArrayBuffer audio buffer"), new zr(e, t, n, r)) : (console.log("[audio] using postMessage audio buffer (SharedArrayBuffer unavailable)"), new Br(e, t, n, r));
2682
- }
2683
- var zr = class {
2684
- rate;
2685
- channels;
2686
- #e;
2687
- #t;
2688
- #n = new i(0);
2689
- timestamp = this.#n;
2690
- #r = new i(!0);
2691
- stalled = this.#r;
2692
- #i = new r();
2693
- constructor(e, t, n, r) {
2694
- this.#e = e, this.channels = t, this.rate = n;
2695
- let i = Nr(t, Math.max(n, r * 2), n);
2696
- this.#t = new Ir(i), this.#t.setLatency(r);
2697
- let a = {
2698
- type: "init-shared",
2699
- ...i
2700
- };
2701
- e.port.postMessage(a), this.#i.interval(() => {
2702
- this.#n.set(this.#t.timestamp), this.#r.set(this.#t.stalled);
2703
- }, 50);
2704
- }
2705
- insert(e, t) {
2706
- this.#t.insert(e, t);
2707
- }
2708
- setLatency(e) {
2709
- if (this.#t.capacity < e * 1.5) {
2710
- let t = Math.max(this.rate, e * 2);
2711
- this.#t = this.#t.resize(t), this.#t.setLatency(e);
2712
- let n = {
2713
- type: "init-shared",
2714
- ...this.#t.init
2715
- };
2716
- this.#e.port.postMessage(n);
2717
- } else this.#t.setLatency(e);
2718
- }
2719
- close() {
2720
- this.#i.close();
2721
- }
2722
- }, Br = class {
2723
- rate;
2724
- channels;
2725
- #e;
2726
- #t = new i(0);
2727
- timestamp = this.#t;
2728
- #n = new i(!0);
2729
- stalled = this.#n;
2730
- #r = new r();
2731
- constructor(e, t, r, i) {
2732
- this.#e = e, this.channels = t, this.rate = r;
2733
- let a = {
2734
- type: "init-post",
2735
- channels: t,
2736
- rate: r,
2737
- latency: n.Milli.fromSecond(i / r)
2738
- };
2739
- e.port.postMessage(a), this.#r.event(e.port, "message", (e) => {
2740
- let t = e.data;
2741
- t?.type === "state" && (this.#t.set(t.timestamp), this.#n.set(t.stalled));
2742
- }), e.port.start();
2743
- }
2744
- insert(e, t) {
2745
- let n = {
2746
- type: "data",
2747
- data: t,
2748
- timestamp: e
2749
- };
2750
- this.#e.port.postMessage(n, t.map((e) => e.buffer));
2751
- }
2752
- setLatency(e) {
2753
- let t = {
2754
- type: "latency",
2755
- latency: n.Milli.fromSecond(e / this.rate)
2756
- };
2757
- this.#e.port.postMessage(t);
2758
- }
2759
- close() {
2760
- this.#r.close();
2761
- }
2762
- }, Vr = new Blob(["var __defProp = Object.defineProperty;\nvar __getOwnPropNames = Object.getOwnPropertyNames;\nvar __esm = (fn, res) => function __init() {\n return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;\n};\nvar __export = (target, all) => {\n for (var name in all)\n __defProp(target, name, { get: all[name], enumerable: true });\n};\n\n// ../net/src/path.ts\nvar init_path = __esm({\n \"../net/src/path.ts\"() {\n \"use strict\";\n }\n});\n\n// ../net/src/varint.ts\nvar MAX_U6, MAX_U14, MAX_U30, MAX_U53, MAX_U64, MAX_U62;\nvar init_varint = __esm({\n \"../net/src/varint.ts\"() {\n \"use strict\";\n MAX_U6 = 2 ** 6 - 1;\n MAX_U14 = 2 ** 14 - 1;\n MAX_U30 = 2 ** 30 - 1;\n MAX_U53 = Number.MAX_SAFE_INTEGER;\n MAX_U64 = (1n << 64n) - 1n;\n MAX_U62 = 2n ** 62n - 1n;\n }\n});\n\n// ../net/src/index.ts\ninit_path();\n\n// ../net/src/time.ts\nvar time_exports = {};\n__export(time_exports, {\n Micro: () => Micro,\n Milli: () => Milli,\n Nano: () => Nano,\n Second: () => Second\n});\nvar Nano = {\n zero: 0,\n fromMicro: (us) => us * 1e3,\n fromMilli: (ms) => ms * 1e6,\n fromSecond: (s) => s * 1e9,\n toMicro: (ns) => ns / 1e3,\n toMilli: (ns) => ns / 1e6,\n toSecond: (ns) => ns / 1e9,\n now: () => performance.now() * 1e6,\n add: (a, b) => a + b,\n sub: (a, b) => a - b,\n mul: (a, b) => a * b,\n div: (a, b) => a / b,\n max: (a, b) => Math.max(a, b),\n min: (a, b) => Math.min(a, b)\n};\nvar Micro = {\n zero: 0,\n fromNano: (ns) => ns / 1e3,\n fromMilli: (ms) => ms * 1e3,\n fromSecond: (s) => s * 1e6,\n toNano: (us) => us * 1e3,\n toMilli: (us) => us / 1e3,\n toSecond: (us) => us / 1e6,\n now: () => performance.now() * 1e3,\n add: (a, b) => a + b,\n sub: (a, b) => a - b,\n mul: (a, b) => a * b,\n div: (a, b) => a / b,\n max: (a, b) => Math.max(a, b),\n min: (a, b) => Math.min(a, b)\n};\nvar Milli = {\n zero: 0,\n fromNano: (ns) => ns / 1e6,\n fromMicro: (us) => us / 1e3,\n fromSecond: (s) => s * 1e3,\n toNano: (ms) => ms * 1e6,\n toMicro: (ms) => ms * 1e3,\n toSecond: (ms) => ms / 1e3,\n now: () => performance.now(),\n add: (a, b) => a + b,\n sub: (a, b) => a - b,\n mul: (a, b) => a * b,\n div: (a, b) => a / b,\n max: (a, b) => Math.max(a, b),\n min: (a, b) => Math.min(a, b)\n};\nvar Second = {\n zero: 0,\n fromNano: (ns) => ns / 1e9,\n fromMicro: (us) => us / 1e6,\n fromMilli: (ms) => ms / 1e3,\n toNano: (s) => s * 1e9,\n toMicro: (s) => s * 1e6,\n toMilli: (s) => s * 1e3,\n now: () => performance.now() / 1e3,\n add: (a, b) => a + b,\n sub: (a, b) => a - b,\n mul: (a, b) => a * b,\n div: (a, b) => a / b,\n max: (a, b) => Math.max(a, b),\n min: (a, b) => Math.min(a, b)\n};\n\n// ../net/src/index.ts\ninit_varint();\n\n// src/audio/ring-buffer.ts\nvar AudioRingBuffer = class {\n #buffer;\n #writeIndex = 0;\n #readIndex = 0;\n rate;\n channels;\n #stalled = true;\n constructor(props) {\n if (props.channels <= 0) throw new Error(\"invalid channels\");\n if (props.rate <= 0) throw new Error(\"invalid sample rate\");\n if (props.latency <= 0) throw new Error(\"invalid latency\");\n const samples = Math.ceil(props.rate * time_exports.Second.fromMilli(props.latency));\n if (samples === 0) throw new Error(\"empty buffer\");\n this.rate = props.rate;\n this.channels = props.channels;\n this.#buffer = [];\n for (let i = 0; i < this.channels; i++) {\n this.#buffer[i] = new Float32Array(samples);\n }\n }\n get stalled() {\n return this.#stalled;\n }\n get timestamp() {\n return time_exports.Micro.fromSecond(this.#readIndex / this.rate);\n }\n get length() {\n return this.#writeIndex - this.#readIndex;\n }\n get capacity() {\n return this.#buffer[0]?.length;\n }\n resize(latency) {\n const newCapacity = Math.ceil(this.rate * time_exports.Second.fromMilli(latency));\n if (newCapacity === this.capacity) return;\n if (newCapacity === 0) throw new Error(\"empty buffer\");\n const newBuffer = [];\n for (let i = 0; i < this.channels; i++) {\n newBuffer[i] = new Float32Array(newCapacity);\n }\n const samplesToKeep = Math.min(this.length, newCapacity);\n if (samplesToKeep > 0) {\n const copyStart = this.#writeIndex - samplesToKeep;\n for (let channel = 0; channel < this.channels; channel++) {\n const src = this.#buffer[channel];\n const dst = newBuffer[channel];\n for (let i = 0; i < samplesToKeep; i++) {\n const srcPos = (copyStart + i) % src.length;\n const dstPos = (copyStart + i) % dst.length;\n dst[dstPos] = src[srcPos];\n }\n }\n }\n this.#buffer = newBuffer;\n this.#readIndex = this.#writeIndex - samplesToKeep;\n if (samplesToKeep === 0) this.#stalled = true;\n }\n write(timestamp, data) {\n if (data.length !== this.channels) throw new Error(\"wrong number of channels\");\n let start = Math.round(time_exports.Second.fromMicro(timestamp) * this.rate);\n let samples = data[0].length;\n let offset = this.#readIndex - start;\n if (offset > samples) {\n return;\n } else if (offset > 0) {\n samples -= offset;\n start += offset;\n } else {\n offset = 0;\n }\n const end = start + samples;\n const overflow = end - this.#readIndex - this.#buffer[0].length;\n if (overflow >= 0) {\n this.#stalled = false;\n this.#readIndex += overflow;\n }\n if (start > this.#writeIndex) {\n const gapSize = Math.min(start - this.#writeIndex, this.#buffer[0].length);\n if (gapSize === 1) {\n console.warn(\"floating point inaccuracy detected\");\n }\n for (let channel = 0; channel < this.channels; channel++) {\n const dst = this.#buffer[channel];\n for (let i = 0; i < gapSize; i++) {\n const writePos = (this.#writeIndex + i) % dst.length;\n dst[writePos] = 0;\n }\n }\n }\n for (let channel = 0; channel < this.channels; channel++) {\n let src = data[channel];\n src = src.subarray(src.length - samples);\n const dst = this.#buffer[channel];\n if (src.length !== samples) throw new Error(\"mismatching number of samples\");\n for (let i = 0; i < samples; i++) {\n const writePos = (start + i) % dst.length;\n dst[writePos] = src[i];\n }\n }\n if (end > this.#writeIndex) {\n this.#writeIndex = end;\n }\n }\n read(output) {\n if (output.length !== this.channels) throw new Error(\"wrong number of channels\");\n if (this.#stalled) return 0;\n const samples = Math.min(this.#writeIndex - this.#readIndex, output[0].length);\n if (samples === 0) return 0;\n for (let channel = 0; channel < this.channels; channel++) {\n const dst = output[channel];\n const src = this.#buffer[channel];\n if (dst.length !== output[0].length) throw new Error(\"mismatching number of samples\");\n for (let i = 0; i < samples; i++) {\n const readPos = (this.#readIndex + i) % src.length;\n dst[i] = src[readPos];\n }\n }\n this.#readIndex += samples;\n return samples;\n }\n};\n\n// src/audio/shared-ring-buffer.ts\nvar WRITE = 0;\nvar READ = 1;\nvar LATENCY = 2;\nvar STALLED = 3;\nvar CONTROL_SLOTS = 4;\nfunction allocSharedRingBuffer(channels, capacity, rate) {\n if (channels <= 0) throw new Error(\"invalid channels\");\n if (capacity <= 0) throw new Error(\"invalid capacity\");\n if (rate <= 0) throw new Error(\"invalid sample rate\");\n const samples = new SharedArrayBuffer(channels * capacity * Float32Array.BYTES_PER_ELEMENT);\n const control = new SharedArrayBuffer(CONTROL_SLOTS * Int32Array.BYTES_PER_ELEMENT);\n const ctrl = new Int32Array(control);\n Atomics.store(ctrl, STALLED, 1);\n return { channels, capacity, rate, samples, control };\n}\nfunction i32Max(a, b) {\n return (a - b | 0) > 0 ? a : b;\n}\nfunction slot(idx, capacity) {\n return (idx % capacity + capacity) % capacity;\n}\nfunction casAdvance(arr, idx, candidate) {\n for (; ; ) {\n const current = Atomics.load(arr, idx);\n if ((candidate - current | 0) <= 0) return current;\n const witnessed = Atomics.compareExchange(arr, idx, current, candidate);\n if (witnessed === current) return candidate;\n }\n}\nvar SharedRingBuffer = class _SharedRingBuffer {\n channels;\n capacity;\n rate;\n init;\n #control;\n #samples;\n constructor(init) {\n this.channels = init.channels;\n this.capacity = init.capacity;\n this.rate = init.rate;\n this.init = init;\n this.#control = new Int32Array(init.control);\n this.#samples = [];\n for (let i = 0; i < this.channels; i++) {\n this.#samples.push(\n new Float32Array(init.samples, i * this.capacity * Float32Array.BYTES_PER_ELEMENT, this.capacity)\n );\n }\n }\n /**\n * Insert audio samples at the given timestamp.\n * Main thread only. Handles out-of-order writes, gap filling, and overflow.\n */\n insert(timestamp, data) {\n if (data.length !== this.channels) throw new Error(\"wrong number of channels\");\n let start = Math.round(time_exports.Second.fromMicro(timestamp) * this.rate);\n const originalLength = data[0].length;\n let offset = 0;\n const end = start + originalLength | 0;\n const read = Atomics.load(this.#control, READ);\n const behind = read - start | 0;\n if (behind > 0) {\n if (behind >= originalLength) {\n return;\n }\n offset = behind;\n start = start + behind | 0;\n }\n const samples = originalLength - offset;\n if ((end - read | 0) > this.capacity) {\n casAdvance(this.#control, READ, end - this.capacity | 0);\n }\n const write = Atomics.load(this.#control, WRITE);\n const gap = start - write | 0;\n if (gap > 0) {\n const gapSize = Math.min(gap, this.capacity);\n for (let channel = 0; channel < this.channels; channel++) {\n const dst = this.#samples[channel];\n for (let i = 0; i < gapSize; i++) {\n dst[slot(write + i | 0, this.capacity)] = 0;\n }\n }\n }\n for (let channel = 0; channel < this.channels; channel++) {\n const src = data[channel];\n const dst = this.#samples[channel];\n for (let i = 0; i < samples; i++) {\n dst[slot(start + i | 0, this.capacity)] = src[offset + i];\n }\n }\n Atomics.store(this.#control, WRITE, i32Max(Atomics.load(this.#control, WRITE), end));\n const currentRead = Atomics.load(this.#control, READ);\n const currentWrite = Atomics.load(this.#control, WRITE);\n const latency = Atomics.load(this.#control, LATENCY);\n if ((currentWrite - currentRead | 0) >= latency && latency > 0) {\n Atomics.store(this.#control, STALLED, 0);\n }\n }\n /**\n * Read audio samples into the output buffers.\n * AudioWorklet only. Returns the number of samples read.\n */\n read(output) {\n if (Atomics.load(this.#control, STALLED) === 1) return 0;\n let read = Atomics.load(this.#control, READ);\n const write = Atomics.load(this.#control, WRITE);\n const latency = Atomics.load(this.#control, LATENCY);\n const buffered = write - read | 0;\n if (latency > 0 && buffered > latency) {\n const skipTo = write - latency | 0;\n read = casAdvance(this.#control, READ, skipTo);\n }\n const available = write - read | 0;\n const count = Math.min(available, output[0].length);\n if (count <= 0) return 0;\n for (let channel = 0; channel < this.channels; channel++) {\n const src = this.#samples[channel];\n const dst = output[channel];\n for (let i = 0; i < count; i++) {\n dst[i] = src[slot(read + i | 0, this.capacity)];\n }\n }\n casAdvance(this.#control, READ, read + count | 0);\n return count;\n }\n /** Update the target latency in samples. */\n setLatency(samples) {\n Atomics.store(this.#control, LATENCY, samples);\n }\n /**\n * Allocate a new ring with `newCapacity` samples and copy the unread window\n * [READ, WRITE) plus control state into it. Used when growing capacity so\n * we don't drop buffered audio. If `newCapacity` is smaller than the unread\n * span, the oldest samples are truncated.\n *\n * Main thread only. `resize()` reads from the source `SharedRingBuffer` and\n * writes into a freshly allocated buffer from `allocSharedRingBuffer`, so it\n * relies on the same invariant as `insert()`: no concurrent main-thread\n * writers. The AudioWorklet reader is tolerated via the CAS discipline used\n * by READ/WRITE elsewhere.\n */\n resize(newCapacity) {\n const init = allocSharedRingBuffer(this.channels, newCapacity, this.rate);\n const dst = new _SharedRingBuffer(init);\n const read = Atomics.load(this.#control, READ);\n const write = Atomics.load(this.#control, WRITE);\n const latency = Atomics.load(this.#control, LATENCY);\n const stalled = Atomics.load(this.#control, STALLED);\n const available = write - read | 0;\n const copyCount = Math.max(0, Math.min(available, dst.capacity));\n const copyStart = write - copyCount | 0;\n for (let channel = 0; channel < this.channels; channel++) {\n const src = this.#samples[channel];\n const out = dst.#samples[channel];\n for (let i = 0; i < copyCount; i++) {\n const idx = copyStart + i | 0;\n out[slot(idx, dst.capacity)] = src[slot(idx, this.capacity)];\n }\n }\n Atomics.store(dst.#control, READ, copyStart);\n Atomics.store(dst.#control, WRITE, write);\n Atomics.store(dst.#control, LATENCY, latency);\n Atomics.store(dst.#control, STALLED, stalled);\n return dst;\n }\n /** Current playback timestamp derived from READ position. */\n get timestamp() {\n const read = Atomics.load(this.#control, READ);\n return time_exports.Micro.fromSecond(read / this.rate);\n }\n /** Whether the buffer is stalled (waiting to fill). */\n get stalled() {\n return Atomics.load(this.#control, STALLED) === 1;\n }\n /**\n * Number of buffered samples (WRITE - READ).\n *\n * Non-atomic: WRITE and READ are loaded separately, so a concurrent\n * writer/reader can make the two loads inconsistent. Intended for\n * tests and diagnostics, not control-flow decisions.\n */\n get length() {\n return Atomics.load(this.#control, WRITE) - Atomics.load(this.#control, READ) | 0;\n }\n};\n\n// src/audio/render-worklet.ts\nvar Render = class extends AudioWorkletProcessor {\n // Set after init, depending on which path the main thread chose.\n #backend;\n #underflow = 0;\n #stateCounter = 0;\n constructor() {\n super();\n this.port.onmessage = (event) => {\n const msg = event.data;\n if (msg.type === \"init-shared\") {\n console.log(\"[audio-worklet] init-shared: using SharedArrayBuffer path\");\n this.#backend = new SharedRingBuffer(msg);\n this.#underflow = 0;\n } else if (msg.type === \"init-post\") {\n console.log(\"[audio-worklet] init-post: using postMessage path\");\n this.#backend = new AudioRingBuffer(msg);\n this.#underflow = 0;\n } else if (msg.type === \"data\") {\n if (this.#backend instanceof AudioRingBuffer) this.#backend.write(msg.timestamp, msg.data);\n } else if (msg.type === \"latency\") {\n if (this.#backend instanceof AudioRingBuffer) this.#backend.resize(msg.latency);\n }\n };\n }\n process(_inputs, outputs, _parameters) {\n const output = outputs[0];\n const backend = this.#backend;\n const samplesRead = backend?.read(output) ?? 0;\n if (samplesRead < output[0].length) {\n this.#underflow += output[0].length - samplesRead;\n } else if (this.#underflow > 0 && backend) {\n console.debug(`audio underflow: ${Math.round(1e3 * this.#underflow / backend.rate)}ms`);\n this.#underflow = 0;\n }\n if (backend instanceof AudioRingBuffer) {\n this.#stateCounter++;\n if (this.#stateCounter >= 5) {\n this.#stateCounter = 0;\n const state = {\n type: \"state\",\n timestamp: backend.timestamp,\n stalled: backend.stalled\n };\n this.port.postMessage(state);\n }\n }\n return true;\n }\n};\nregisterProcessor(\"render\", Render);\n"], { type: "application/javascript" }), Hr = URL.createObjectURL(Vr), Ur = class {
2763
- source;
2764
- enabled;
2765
- #e = new i(void 0);
2766
- context = this.#e;
2767
- #t = new i(void 0);
2768
- root = this.#t;
2769
- #n = new i(void 0);
2770
- sampleRate = this.#n;
2771
- #r = new i(void 0);
2772
- stats = this.#r;
2773
- #i = new i(void 0);
2774
- timestamp = this.#i;
2775
- #a = new i(!0);
2776
- stalled = this.#a;
2777
- #o = new i([]);
2778
- #s = new i([]);
2779
- buffered = this.#s;
2780
- #c;
2781
- #l = new r();
2782
- constructor(e, t) {
2783
- this.source = e, this.source.supported.set(Wr), this.enabled = i.from(t?.enabled ?? !1), this.#l.run(this.#u.bind(this)), this.#l.run(this.#d.bind(this)), this.#l.run(this.#f.bind(this)), this.#l.run(this.#p.bind(this));
2784
- }
2785
- #u(e) {
2786
- let t = e.get(this.source.config);
2787
- if (!t) return;
2788
- let r = t.sampleRate, i = t.numberOfChannels, a = new AudioContext({
2789
- latencyHint: "interactive",
2790
- sampleRate: r
2791
- });
2792
- e.set(this.#e, a), e.cleanup(() => a.close()), e.spawn(async () => {
2793
- if (await a.audioWorklet.addModule(Hr), a.state === "closed") return;
2794
- let t = new AudioWorkletNode(a, "render", {
2795
- channelCount: i,
2796
- channelCountMode: "explicit",
2797
- outputChannelCount: [i]
2798
- });
2799
- e.cleanup(() => t.disconnect());
2800
- let o = this.source.sync.buffer.peek(), s = Rr(t, i, r, Math.ceil(r * n.Second.fromMilli(o)));
2801
- this.#c = s, e.cleanup(() => {
2802
- s.close(), this.#c = void 0;
2803
- }), e.run((e) => {
2804
- let t = n.Milli.fromMicro(e.get(s.timestamp));
2805
- this.#i.set(t), this.#v(t);
2806
- }), e.run((e) => {
2807
- this.#a.set(e.get(s.stalled));
2808
- }), e.set(this.#t, t);
2809
- });
2810
- }
2811
- #d(e) {
2812
- let t = e.getAll([this.enabled, this.#e]);
2813
- if (!t) return;
2814
- let [n, r] = t;
2815
- r.resume();
2816
- }
2817
- #f(e) {
2818
- if (!e.get(this.#t)) return;
2819
- let t = this.#c;
2820
- if (!t) return;
2821
- let r = e.get(this.source.sync.buffer), i = Math.ceil(t.rate * n.Second.fromMilli(r));
2822
- t.setLatency(i);
2823
- }
2824
- #p(e) {
2825
- if (!e.get(this.enabled)) return;
2826
- let t = e.get(this.source.broadcast);
2827
- if (!t) return;
2828
- let n = e.get(this.source.track);
2829
- if (!n) return;
2830
- let r = e.get(this.source.config);
2831
- if (!r) return;
2832
- let i = e.get(t.active);
2833
- if (!i) return;
2834
- let a = i.subscribe(n, F.audio);
2835
- e.cleanup(() => a.close()), r.container.kind === "cmaf" ? this.#h(e, a, r) : this.#m(e, a, r);
2836
- }
2837
- #m(e, t, r) {
2838
- let i = new K(t, {
2839
- format: r.container.kind === "loc" ? new $t() : new q(),
2840
- latency: this.source.sync.buffer
2841
- });
2842
- e.cleanup(() => i.close()), e.run((e) => {
2843
- let t = e.get(i.buffered), n = e.get(this.#o);
2844
- this.#s.update(() => kr(t, n));
2845
- }), e.spawn(async () => {
2846
- if (!await jr()) return;
2847
- let t = 0, a = new AudioDecoder({
2848
- output: (e) => {
2849
- if (t++, t <= 3) {
2850
- e.close();
2851
- return;
2852
- }
2853
- this.#g(e);
2854
- },
2855
- error: (e) => console.error(e)
2856
- });
2857
- e.cleanup(() => {
2858
- a.state !== "closed" && a.close();
2859
- });
2860
- let o = r.codec === "opus" ? void 0 : r.description ? W(r.description) : void 0;
2861
- for (a.configure({
2862
- ...r,
2863
- description: o
2864
- });;) {
2865
- let e = await i.next();
2866
- if (!e) break;
2867
- let { frame: t } = e;
2868
- if (!t) continue;
2869
- let r = n.Milli.fromMicro(t.timestamp);
2870
- this.source.sync.received(r, "audio"), this.#r.update((e) => ({ bytesReceived: (e?.bytesReceived ?? 0) + t.data.byteLength }));
2871
- let o = new EncodedAudioChunk({
2872
- type: t.keyframe ? "key" : "delta",
2873
- data: t.data,
2874
- timestamp: t.timestamp
2875
- });
2876
- a.decode(o);
2877
- }
2878
- });
2879
- }
2880
- #h(e, t, r) {
2881
- if (r.container.kind !== "cmaf") return;
2882
- let i = U(J(r.container.init)), a = r.codec === "opus" ? void 0 : r.description ? W(r.description) : i.description, o = new K(t, {
2883
- format: new Or(i),
2884
- latency: this.source.sync.buffer
2885
- });
2886
- e.cleanup(() => o.close()), e.run((e) => {
2887
- let t = e.get(o.buffered), n = e.get(this.#o);
2888
- this.#s.update(() => kr(t, n));
2889
- }), e.spawn(async () => {
2890
- if (!await jr()) return;
2891
- let t = new AudioDecoder({
2892
- output: (e) => this.#g(e),
2893
- error: (e) => console.error(e)
2894
- });
2895
- for (e.cleanup(() => {
2896
- t.state !== "closed" && t.close();
2897
- }), t.configure({
2898
- codec: r.codec,
2899
- sampleRate: r.sampleRate,
2900
- numberOfChannels: r.numberOfChannels,
2901
- description: a
2902
- });;) {
2903
- let e = await o.next();
2904
- if (!e) break;
2905
- let { frame: r } = e;
2906
- if (!r) continue;
2907
- let i = n.Milli.fromMicro(r.timestamp);
2908
- if (this.source.sync.received(i, "audio"), this.#r.update((e) => ({ bytesReceived: (e?.bytesReceived ?? 0) + r.data.byteLength })), t.state === "closed") break;
2909
- t.decode(new EncodedAudioChunk({
2910
- type: r.keyframe ? "key" : "delta",
2911
- data: r.data,
2912
- timestamp: r.timestamp
2913
- }));
2914
- }
2915
- });
2916
- }
2917
- #g(e) {
2918
- let t = e.timestamp, r = n.Milli.fromMicro(t), i = this.#c;
2919
- if (!i) {
2920
- e.close();
2921
- return;
2922
- }
2923
- let a = e.numberOfFrames / e.sampleRate * 1e6, o = n.Milli.fromMicro(a), s = n.Milli.add(r, o);
2924
- this.#_(r, s);
2925
- let c = Math.min(e.numberOfChannels, i.channels), l = [];
2926
- for (let t = 0; t < c; t++) {
2927
- let n = new Float32Array(e.numberOfFrames);
2928
- e.copyTo(n, {
2929
- format: "f32-planar",
2930
- planeIndex: t
2931
- }), l.push(n);
2932
- }
2933
- i.insert(t, l), e.close();
2934
- }
2935
- #_(e, t) {
2936
- e > t || this.#o.mutate((r) => {
2937
- for (let i of r) if (e <= i.end + 1 && t >= i.start) {
2938
- i.start = n.Milli.min(i.start, e), i.end = n.Milli.max(i.end, t);
2939
- return;
2940
- }
2941
- r.push({
2942
- start: e,
2943
- end: t
2944
- }), r.sort((e, t) => e.start - t.start);
2945
- });
2946
- }
2947
- #v(e) {
2948
- this.#o.mutate((t) => {
2949
- for (; t.length > 0;) {
2950
- if (t[0].end >= e) {
2951
- t[0].start = n.Milli.max(t[0].start, e);
2952
- break;
2953
- }
2954
- t.shift();
2955
- }
2956
- });
2957
- }
2958
- close() {
2959
- this.#l.close();
2960
- }
2961
- };
2962
- async function Wr(e) {
2963
- let t;
2964
- if (e.codec !== "opus") {
2965
- if (e.description) t = W(e.description);
2966
- else if (e.container.kind === "cmaf") try {
2967
- t = U(J(e.container.init)).description;
2968
- } catch (t) {
2969
- return console.warn(`audio: malformed CMAF init segment for codec ${e.codec}`, t), !1;
2970
- }
2971
- }
2972
- return (await AudioDecoder.isConfigSupported({
2973
- ...e,
2974
- description: t
2975
- })).supported ?? !1;
2976
- }
2977
- //#endregion
2978
- //#region src/audio/emitter.ts
2979
- var Gr = .001, Kr = .2, qr = class {
2980
- source;
2981
- volume;
2982
- muted;
2983
- paused;
2984
- #e = new r();
2985
- #t = .5;
2986
- #n = new i(void 0);
2987
- constructor(e, t) {
2988
- this.source = e, this.volume = i.from(t?.volume ?? .5), this.muted = i.from(t?.muted ?? !1), this.paused = i.from(t?.paused ?? t?.muted ?? !1), this.#e.run((e) => {
2989
- e.get(this.muted) ? (this.#t = this.volume.peek() || .5, this.volume.set(0)) : this.volume.set(this.#t);
2990
- }), this.#e.run((e) => {
2991
- let t = !e.get(this.paused) && !e.get(this.muted);
2992
- this.source.enabled.set(t);
2993
- }), this.#e.run((e) => {
2994
- let t = e.get(this.volume);
2995
- this.muted.set(t === 0);
2996
- }), this.#e.run((e) => {
2997
- let t = e.get(this.source.root);
2998
- if (!t) return;
2999
- let n = new GainNode(t.context, { gain: e.get(this.volume) });
3000
- t.connect(n), e.set(this.#n, n), e.run((e) => {
3001
- e.get(this.source.enabled) && (n.connect(t.context.destination), e.cleanup(() => n.disconnect()));
3002
- });
3003
- }), this.#e.run((e) => {
3004
- let t = e.get(this.#n);
3005
- if (!t) return;
3006
- e.cleanup(() => t.gain.cancelScheduledValues(t.context.currentTime));
3007
- let n = e.get(this.volume);
3008
- n < Gr ? (t.gain.exponentialRampToValueAtTime(Gr, t.context.currentTime + Kr), t.gain.setValueAtTime(0, t.context.currentTime + Kr + .01)) : t.gain.exponentialRampToValueAtTime(n, t.context.currentTime + Kr);
3009
- });
3010
- }
3011
- close() {
3012
- this.#e.close();
3013
- }
3014
- }, Jr = /* @__PURE__ */ o({ Muxer: () => Yr }), Yr = class {
3015
- element;
3016
- paused;
3017
- #e;
3018
- #t = new i(void 0);
3019
- mediaSource = this.#t;
3020
- #n = new r();
3021
- constructor(e, t) {
3022
- this.element = i.from(t?.element), this.paused = i.from(t?.paused ?? !1), this.#e = e, this.#n.run(this.#r.bind(this)), this.#n.run(this.#i.bind(this)), this.#n.run(this.#a.bind(this)), this.#n.run(this.#o.bind(this)), this.#n.run(this.#s.bind(this));
3023
- }
3024
- #r(e) {
3025
- let t = e.get(this.element);
3026
- if (!t) return;
3027
- let n = new MediaSource();
3028
- t.src = URL.createObjectURL(n), e.cleanup(() => URL.revokeObjectURL(t.src)), e.event(n, "sourceopen", () => {
3029
- e.set(this.#t, n);
3030
- }, { once: !0 }), e.event(n, "error", (e) => {
3031
- console.error("[MSE] MediaSource error event:", e);
3032
- });
3033
- }
3034
- #i(e) {
3035
- let t = e.get(this.element);
3036
- if (!t || e.get(this.paused)) return;
3037
- let r = n.Milli.toSecond(e.get(this.#e.buffer));
3038
- e.interval(() => {
3039
- let e = t.buffered;
3040
- if (e.length === 0) return;
3041
- let n = e.end(e.length - 1) - r, i = n - t.currentTime;
3042
- (i > .1 || i < -.1) && (console.warn("seeking", i > 0 ? "forward" : "backward", Math.abs(i).toFixed(3), "seconds"), t.currentTime = n);
3043
- }, 100);
3044
- }
3045
- #a(e) {
3046
- let t = e.get(this.element);
3047
- if (!t) return;
3048
- let n = e.get(this.mediaSource);
3049
- n && e.interval(async () => {
3050
- for (let e of n.sourceBuffers) {
3051
- for (; e.updating;) await new Promise((t) => e.addEventListener("updateend", t, { once: !0 }));
3052
- t.currentTime > 10 && e.remove(0, t.currentTime - 10);
3053
- }
3054
- }, 1e3);
3055
- }
3056
- #o(e) {
3057
- let t = e.get(this.element);
3058
- if (!t) return;
3059
- let n = e.get(this.paused);
3060
- n && !t.paused ? t.pause() : !n && t.paused && t.play().catch((e) => {
3061
- console.error("[MSE] MediaElement play error:", e);
3062
- });
3063
- }
3064
- #s(e) {
3065
- let t = e.get(this.element);
3066
- if (!t || e.get(this.paused)) return;
3067
- let r = e.get(this.#e.reference);
3068
- if (r === void 0) return;
3069
- let i = e.get(this.#e.buffer), a = n.Milli.sub(n.Milli.sub(n.Milli.now(), r), i);
3070
- t.currentTime = n.Milli.toSecond(a);
3071
- }
3072
- close() {
3073
- this.#n.close();
3074
- }
3075
- }, Xr = 20, Zr = 100, Qr = class e {
3076
- #e = new i(void 0);
3077
- reference = this.#e;
3078
- latency;
3079
- jitter;
3080
- audio;
3081
- video;
3082
- #t = new i(n.Milli.zero);
3083
- buffer = this.#t;
3084
- #n;
3085
- timestamp = new i(void 0);
3086
- #r = /* @__PURE__ */ new Map();
3087
- #i;
3088
- #a;
3089
- signals = new r();
3090
- constructor(e) {
3091
- this.latency = i.from(e?.latency ?? "real-time"), this.jitter = new i(Zr), this.#i = e?.connection, this.audio = i.from(e?.audio), this.video = i.from(e?.video), this.#n = Promise.withResolvers(), this.signals.run(this.#o.bind(this)), this.signals.run(this.#s.bind(this));
3092
- }
3093
- #o(e) {
3094
- let t = e.get(this.latency);
3095
- if (typeof t == "number") {
3096
- this.#a = void 0, this.jitter.set(t);
3097
- return;
3098
- }
3099
- let n = (this.#i ? e.get(this.#i) : void 0)?.rtt, r = n ? e.get(n) : void 0;
3100
- if (r !== void 0) {
3101
- this.#a = this.#a === void 0 ? r : Math.min(this.#a, r);
3102
- let e = Math.max(Xr, this.#a * 1.25);
3103
- this.jitter.set(e);
3104
- return;
3105
- }
3106
- this.#a = void 0, this.jitter.set(Zr);
3107
- }
3108
- #s(e) {
3109
- let t = e.get(this.jitter), r = e.get(this.video) ?? n.Milli.zero, i = e.get(this.audio) ?? n.Milli.zero, a = n.Milli.add(n.Milli.max(r, i), t);
3110
- this.#t.set(a), this.#n.resolve(), this.#n = Promise.withResolvers();
3111
- }
3112
- received(t, r = "") {
3113
- this.timestamp.update((e) => e === void 0 || t > e ? t : e);
3114
- let i = n.Milli.now(), a = n.Milli.sub(i, t), o = this.#e.peek();
3115
- if (o !== void 0) {
3116
- let t = n.Milli.add(n.Milli.sub(o, a), this.#t.peek());
3117
- if (t < 0) {
3118
- let e = this.#r.get(r);
3119
- e ? (e.count++, e.maxMs = Math.max(e.maxMs, -t)) : this.#r.set(r, {
3120
- count: 1,
3121
- maxMs: -t
3122
- });
3123
- } else {
3124
- let t = this.#r.get(r);
3125
- if (t) {
3126
- let n = r ? `sync[${r}]` : "sync", i = e.#c(t.maxMs);
3127
- console.debug(`${n}: ${t.count} late frame(s), max ${i} behind`), this.#r.delete(r);
3128
- }
3129
- }
3130
- if (a >= o) return;
3131
- }
3132
- this.#e.set(a), this.#n.resolve(), this.#n = Promise.withResolvers();
3133
- }
3134
- now() {
3135
- let e = this.#e.peek();
3136
- if (e !== void 0) return n.Milli.sub(n.Milli.sub(n.Milli.now(), e), this.#t.peek());
3137
- }
3138
- async wait(e) {
3139
- if (this.#e.peek() === void 0) throw Error("reference not set; call update() first");
3140
- for (;;) {
3141
- let t = n.Milli.now(), r = n.Milli.sub(t, e), i = this.#e.peek();
3142
- if (i === void 0) return;
3143
- let a = n.Milli.add(n.Milli.sub(i, r), this.#t.peek());
3144
- if (a <= 0 || a < 5) return;
3145
- let o = new Promise((e) => setTimeout(e, a)).then(() => !0);
3146
- if (await Promise.race([this.#n.promise, o])) return;
3147
- }
3148
- }
3149
- static #c(e) {
3150
- if (e = Math.round(e), e < 1e3) return `${e}ms`;
3151
- let t = e / 1e3;
3152
- if (t < 60) return `${Math.round(t * 10) / 10}s`;
3153
- let n = t / 60;
3154
- return `${Math.round(n * 10) / 10}m`;
3155
- }
3156
- close() {
3157
- this.signals.close();
3158
- }
3159
- }, $r = 500, ei = 100, ti = class {
3160
- enabled;
3161
- source;
3162
- #e = new i(void 0);
3163
- #t = new i(void 0);
3164
- frame = this.#t;
3165
- #n = new i(void 0);
3166
- timestamp = this.#n;
3167
- #r = new i(void 0);
3168
- display = this.#r;
3169
- #i = new i(!1);
3170
- stalled = this.#i;
3171
- #a = new i(void 0);
3172
- stats = this.#a;
3173
- #o = new i([]);
3174
- buffered = this.#o;
3175
- #s = new r();
3176
- #c() {
3177
- this.#t.update((e) => {
3178
- e?.close();
3179
- }), this.#n.set(void 0);
3180
- }
3181
- constructor(e, t) {
3182
- this.enabled = i.from(t?.enabled ?? !1), this.source = e, this.source.supported.set(ri), this.#s.run(this.#l.bind(this)), this.#s.run(this.#u.bind(this)), this.#s.run(this.#d.bind(this)), this.#s.run(this.#f.bind(this));
3183
- }
3184
- #l(e) {
3185
- let t = e.getAll([
3186
- this.enabled,
3187
- this.source.broadcast,
3188
- this.source.track,
3189
- this.source.config
3190
- ]);
3191
- if (!t) {
3192
- this.#e.set(void 0);
3193
- return;
3194
- }
3195
- let [n, r, i, a] = t, o = e.get(r.active);
3196
- if (!o) {
3197
- this.#e.set(void 0), this.#c(), this.#o.set([]);
3198
- return;
3199
- }
3200
- let s = new ni({
3201
- source: this.source,
3202
- broadcast: o,
3203
- track: i,
3204
- config: a,
3205
- stats: this.#a
3206
- });
3207
- e.cleanup(() => s?.close()), e.run((e) => {
3208
- if (!s) return;
3209
- let t = e.get(this.#e);
3210
- if (t) {
3211
- let n = e.get(s.timestamp), r = e.get(t.timestamp);
3212
- if (!n || r && r > n + ei) return;
3213
- }
3214
- this.#e.set(s), s = void 0, e.close();
3215
- });
3216
- }
3217
- #u(e) {
3218
- let t = e.get(this.#e);
3219
- if (!t) {
3220
- this.#o.set([]);
3221
- return;
3222
- }
3223
- e.cleanup(() => t.close()), e.run((e) => {
3224
- let n = e.get(t.frame);
3225
- this.#t.update((e) => (e?.close(), n?.clone()));
3226
- }), e.proxy(this.#n, t.timestamp), e.proxy(this.#o, t.buffered);
3227
- }
3228
- #d(e) {
3229
- let t = e.get(this.source.catalog);
3230
- if (!t) return;
3231
- let n = t.display;
3232
- if (n) {
3233
- e.set(this.#r, {
3234
- width: n.width,
3235
- height: n.height
3236
- });
3237
- return;
3238
- }
3239
- let r = e.get(this.frame);
3240
- r && e.set(this.#r, {
3241
- width: r.displayWidth,
3242
- height: r.displayHeight
3243
- });
3244
- }
3245
- #f(e) {
3246
- if (e.get(this.enabled)) {
3247
- if (!e.get(this.frame)) {
3248
- this.#i.set(!0);
3249
- return;
3250
- }
3251
- this.#i.set(!1), e.timer(() => {
3252
- this.#i.set(!0);
3253
- }, $r);
3254
- }
3255
- }
3256
- close() {
3257
- this.#c(), this.#s.close();
3258
- }
3259
- }, ni = class {
3260
- source;
3261
- broadcast;
3262
- track;
3263
- config;
3264
- stats;
3265
- timestamp = new i(void 0);
3266
- frame = new i(void 0);
3267
- buffered = new i([]);
3268
- #e = new i([]);
3269
- signals = new r();
3270
- constructor(e) {
3271
- let { codedWidth: t, codedHeight: n, ...r } = e.config;
3272
- this.source = e.source, this.broadcast = e.broadcast, this.track = e.track, this.config = r, this.stats = e.stats, this.signals.run(this.#t.bind(this));
3273
- }
3274
- #t(e) {
3275
- let t = this.broadcast.subscribe(this.track, F.video);
3276
- e.cleanup(() => t.close());
3277
- let r = new VideoDecoder({
3278
- output: async (t) => {
3279
- try {
3280
- let r = n.Milli.fromMicro(t.timestamp);
3281
- if (r < (this.timestamp.peek() ?? 0)) return;
3282
- this.frame.peek() === void 0 && this.frame.set(t.clone());
3283
- let i = this.source.sync.wait(r).then(() => !0);
3284
- if (!await Promise.race([i, e.cancel]) || r < (this.timestamp.peek() ?? 0)) return;
3285
- this.timestamp.set(r), this.#a(r), this.frame.update((e) => (e?.close(), t.clone()));
3286
- } finally {
3287
- t.close();
3288
- }
3289
- },
3290
- error: (t) => {
3291
- console.error(t), e.close();
3292
- }
3293
- });
3294
- e.cleanup(() => {
3295
- r.state !== "closed" && r.close();
3296
- }), this.config.container.kind === "cmaf" ? this.#r(e, t, r) : this.#n(e, t, r);
3297
- }
3298
- #n(e, t, r) {
3299
- let i = new K(t, {
3300
- format: this.config.container.kind === "loc" ? new $t() : new q(),
3301
- latency: this.source.sync.buffer
3302
- });
3303
- e.cleanup(() => i.close()), e.run((e) => {
3304
- let t = e.get(i.buffered), n = e.get(this.#e);
3305
- this.buffered.update(() => kr(t, n));
3306
- }), r.configure({
3307
- ...this.config,
3308
- description: this.config.description ? W(this.config.description) : void 0,
3309
- optimizeForLatency: this.config.optimizeForLatency ?? !0,
3310
- flip: !1
3311
- });
3312
- let a;
3313
- e.spawn(async () => {
3314
- for (;;) {
3315
- let e = await i.next();
3316
- if (!e) break;
3317
- let { frame: t, group: o } = e;
3318
- if (!t) {
3319
- a && (a.final = !0);
3320
- continue;
3321
- }
3322
- let s = n.Milli.fromMicro(t.timestamp);
3323
- this.source.sync.received(s, "video");
3324
- let c = new EncodedVideoChunk({
3325
- type: t.keyframe ? "key" : "delta",
3326
- data: t.data,
3327
- timestamp: t.timestamp
3328
- });
3329
- this.stats.update((e) => ({
3330
- frameCount: (e?.frameCount ?? 0) + 1,
3331
- bytesReceived: (e?.bytesReceived ?? 0) + t.data.byteLength
3332
- }));
3333
- let l = a;
3334
- if (l && (l.group === o || l.final && l.group + 1 === o)) {
3335
- let e = n.Milli.fromMicro(l.timestamp), r = n.Milli.fromMicro(t.timestamp);
3336
- this.#i(e, r);
3337
- }
3338
- a = {
3339
- timestamp: t.timestamp,
3340
- group: o,
3341
- final: !1
3342
- }, r.decode(c);
3343
- }
3344
- });
3345
- }
3346
- #r(e, t, r) {
3347
- if (this.config.container.kind !== "cmaf") return;
3348
- let i = U(J(this.config.container.init)), a = this.config.description ? W(this.config.description) : i.description, o = new K(t, {
3349
- format: new Or(i),
3350
- latency: this.source.sync.buffer
3351
- });
3352
- e.cleanup(() => o.close()), e.run((e) => {
3353
- let t = e.get(o.buffered), n = e.get(this.#e);
3354
- this.buffered.update(() => kr(t, n));
3355
- }), r.configure({
3356
- codec: this.config.codec,
3357
- description: a,
3358
- optimizeForLatency: this.config.optimizeForLatency ?? !0,
3359
- flip: !1
3360
- });
3361
- let s;
3362
- e.spawn(async () => {
3363
- for (;;) {
3364
- let e = await o.next();
3365
- if (!e) break;
3366
- let { frame: t, group: i } = e;
3367
- if (!t) {
3368
- s && (s.final = !0);
3369
- continue;
3370
- }
3371
- let a = n.Milli.fromMicro(t.timestamp);
3372
- this.source.sync.received(a, "video"), this.stats.update((e) => ({
3373
- frameCount: (e?.frameCount ?? 0) + 1,
3374
- bytesReceived: (e?.bytesReceived ?? 0) + t.data.byteLength
3375
- }));
3376
- let c = s;
3377
- if (c && (c.group === i || c.final && c.group + 1 === i)) {
3378
- let e = n.Milli.fromMicro(c.timestamp), r = n.Milli.fromMicro(t.timestamp);
3379
- this.#i(e, r);
3380
- }
3381
- if (s = {
3382
- timestamp: t.timestamp,
3383
- group: i,
3384
- final: !1
3385
- }, r.state === "closed") break;
3386
- r.decode(new EncodedVideoChunk({
3387
- type: t.keyframe ? "key" : "delta",
3388
- data: t.data,
3389
- timestamp: t.timestamp
3390
- }));
3391
- }
3392
- });
3393
- }
3394
- #i(e, t) {
3395
- e > t || this.#e.mutate((r) => {
3396
- for (let i of r) if (i.start <= t && i.end >= e) {
3397
- i.start = n.Milli.min(i.start, e), i.end = n.Milli.max(i.end, t);
3398
- return;
3399
- }
3400
- r.push({
3401
- start: e,
3402
- end: t
3403
- }), r.sort((e, t) => e.start - t.start);
3404
- });
3405
- }
3406
- #a(e) {
3407
- this.#e.mutate((t) => {
3408
- for (; t.length > 0;) {
3409
- if (t[0].end >= e) {
3410
- t[0].start = n.Milli.max(t[0].start, e);
3411
- break;
3412
- }
3413
- t.shift();
3414
- }
3415
- });
3416
- }
3417
- close() {
3418
- this.signals.close(), this.frame.update((e) => {
3419
- e?.close();
3420
- });
3421
- }
3422
- };
3423
- async function ri(e) {
3424
- let t;
3425
- if (e.description) t = W(e.description);
3426
- else if (e.container.kind === "cmaf") try {
3427
- t = U(J(e.container.init)).description;
3428
- } catch (t) {
3429
- return console.warn(`video: malformed CMAF init segment for codec ${e.codec}`, t), !1;
3430
- }
3431
- let { supported: n } = await VideoDecoder.isConfigSupported({
3432
- codec: e.codec,
3433
- description: t,
3434
- optimizeForLatency: e.optimizeForLatency ?? !0
3435
- });
3436
- if (n) return !0;
3437
- if (e.codec.startsWith("avc3.")) {
3438
- let n = `avc1.${e.codec.slice(5)}`;
3439
- if ((await VideoDecoder.isConfigSupported({
3440
- codec: n,
3441
- description: t,
3442
- optimizeForLatency: e.optimizeForLatency ?? !0
3443
- })).supported) return e.codec = n, !0;
3444
- }
3445
- return !1;
3446
- }
3447
- //#endregion
3448
- //#region src/video/mse.ts
3449
- var ii = class {
3450
- muxer;
3451
- source;
3452
- #e = new i(void 0);
3453
- stats = this.#e;
3454
- #t = new i([]);
3455
- buffered = this.#t;
3456
- #n = new i(!1);
3457
- stalled = this.#n;
3458
- #r = new i(e.Time.Milli.zero);
3459
- timestamp = this.#r;
3460
- signals = new r();
3461
- constructor(e, t) {
3462
- this.muxer = e, this.source = t, this.source.supported.set(ai), this.signals.run(this.#i.bind(this)), this.signals.run(this.#c.bind(this)), this.signals.run(this.#l.bind(this));
3463
- }
3464
- #i(e) {
3465
- let t = e.get(this.muxer.element);
3466
- if (!t) return;
3467
- let n = e.get(this.muxer.mediaSource);
3468
- if (!n) return;
3469
- let r = e.get(this.source.broadcast);
3470
- if (!r) return;
3471
- let i = e.get(r.active);
3472
- if (!i) return;
3473
- let a = e.get(this.source.track);
3474
- if (!a) return;
3475
- let o = e.get(this.source.config);
3476
- if (!o) return;
3477
- let s = `video/mp4; codecs="${o.codec}"`, c = n.addSourceBuffer(s);
3478
- e.cleanup(() => {
3479
- n.removeSourceBuffer(c), c.abort();
3480
- }), e.event(c, "error", (e) => {
3481
- console.error("[MSE] SourceBuffer error:", e);
3482
- }), e.event(c, "updateend", () => {
3483
- this.#t.set(pi(c.buffered));
3484
- }), o.container.kind === "cmaf" ? this.#o(e, i, a, o, c, t) : this.#s(e, i, a, o, c, t);
3485
- }
3486
- async #a(e, t) {
3487
- for (; e.updating;) await new Promise((t) => e.addEventListener("updateend", t, { once: !0 }));
3488
- for (e.appendBuffer(t); e.updating;) await new Promise((t) => e.addEventListener("updateend", t, { once: !0 }));
3489
- }
3490
- #o(t, n, r, i, a, o) {
3491
- if (i.container.kind !== "cmaf") throw Error("unreachable");
3492
- let s = n.subscribe(r, F.video);
3493
- t.cleanup(() => s.close());
3494
- let c = J(i.container.init), l = U(c);
3495
- t.spawn(async () => {
3496
- for (await this.#a(a, c);;) {
3497
- let t = await s.readFrame();
3498
- if (!t) return;
3499
- let n = ur(t, l);
3500
- this.source.sync.received(e.Time.Milli.fromMicro(n), "video"), await this.#a(a, t), o.buffered.length > 0 && o.currentTime < o.buffered.start(0) && (o.currentTime = o.buffered.start(0));
3501
- }
3502
- });
3503
- }
3504
- #s(t, n, r, i, a, o) {
3505
- let s = n.subscribe(r, F.video);
3506
- t.cleanup(() => s.close());
3507
- let c = new K(s, {
3508
- format: i.container.kind === "loc" ? new $t() : new q(),
3509
- latency: this.source.sync.buffer
3510
- });
3511
- t.cleanup(() => c.close()), t.spawn(async () => {
3512
- let t = yr(i);
3513
- await this.#a(a, t);
3514
- let n = 1, r, s;
3515
- for (;;) {
3516
- let t = await c.next();
3517
- if (!t) return;
3518
- if (!t.frame) continue;
3519
- s = t.frame;
3520
- let n = e.Time.Milli.fromMicro(s.timestamp);
3521
- this.source.sync.received(n, "video");
3522
- break;
3523
- }
3524
- for (;;) {
3525
- let t = await c.next();
3526
- if (t && !t.frame) continue;
3527
- let i = t?.frame;
3528
- if (i) {
3529
- r = e.Time.Micro.sub(i.timestamp, s.timestamp);
3530
- let t = e.Time.Milli.fromMicro(i.timestamp);
3531
- this.source.sync.received(t, "video");
3532
- }
3533
- let l = Dr({
3534
- data: s.data,
3535
- timestamp: s.timestamp,
3536
- duration: r ?? 0,
3537
- keyframe: s.keyframe,
3538
- sequence: n++
3539
- });
3540
- if (await this.#a(a, l), o.buffered.length > 0 && o.currentTime < o.buffered.start(0) && (o.currentTime = o.buffered.start(0)), !i) return;
3541
- s = i;
3542
- }
3543
- });
3544
- }
3545
- #c(e) {
3546
- let t = e.get(this.muxer.element);
3547
- if (!t) return;
3548
- let n = () => {
3549
- this.#n.set(t.readyState <= HTMLMediaElement.HAVE_CURRENT_DATA);
3550
- };
3551
- n(), e.event(t, "waiting", n), e.event(t, "playing", n), e.event(t, "seeking", n);
3552
- }
3553
- #l(t) {
3554
- let n = t.get(this.muxer.element);
3555
- if (n) if ("requestVideoFrameCallback" in n) {
3556
- let r = n, i, a = () => {
3557
- let t = e.Time.Milli.fromSecond(r.currentTime);
3558
- this.#r.set(t), i = r.requestVideoFrameCallback(a);
3559
- };
3560
- i = r.requestVideoFrameCallback(a), t.cleanup(() => r.cancelVideoFrameCallback(i));
3561
- } else t.event(n, "timeupdate", () => {
3562
- let t = e.Time.Milli.fromSecond(n.currentTime);
3563
- this.#r.set(t);
3564
- });
3565
- }
3566
- close() {
3567
- this.source.close(), this.signals.close();
3568
- }
3569
- };
3570
- async function ai(e) {
3571
- return MediaSource.isTypeSupported(`video/mp4; codecs="${e.codec}"`);
3572
- }
3573
- //#endregion
3574
- //#region src/video/renderer.ts
3575
- var oi = class {
3576
- decoder;
3577
- canvas;
3578
- paused;
3579
- frame = new i(void 0);
3580
- timestamp = new i(void 0);
3581
- #e = new i(void 0);
3582
- #t = new i(!1);
3583
- #n = new r();
3584
- constructor(e, t) {
3585
- this.decoder = e, this.canvas = i.from(t?.canvas), this.paused = i.from(t?.paused ?? !1), this.#n.run((e) => {
3586
- let t = e.get(this.canvas);
3587
- this.#e.set(t?.getContext("2d") ?? void 0);
3588
- }), this.#n.run(this.#i.bind(this)), this.#n.run(this.#a.bind(this)), this.#n.run(this.#o.bind(this)), this.#n.run(this.#r.bind(this));
3589
- }
3590
- #r(e) {
3591
- let t = e.getAll([this.canvas, this.decoder.display]);
3592
- if (!t) return;
3593
- let [n, r] = t;
3594
- (n.width !== r.width || n.height !== r.height) && (n.width = r.width, n.height = r.height);
3595
- }
3596
- #i(e) {
3597
- let t = e.get(this.canvas);
3598
- if (!t) {
3599
- this.#t.set(!1);
3600
- return;
3601
- }
3602
- let n = !1, r = () => {
3603
- this.#t.set(n && !document.hidden);
3604
- }, i = new IntersectionObserver((e) => {
3605
- for (let t of e) n = t.isIntersecting, r();
3606
- }, { threshold: .01 });
3607
- e.event(document, "visibilitychange", r), i.observe(t), e.cleanup(() => i.disconnect()), e.cleanup(() => this.#t.set(!1));
3608
- }
3609
- #a(e) {
3610
- let t = e.get(this.paused), n = e.get(this.#t);
3611
- if (e.cleanup(() => this.decoder.enabled.set(!1)), !t) {
3612
- this.decoder.enabled.set(n);
3613
- return;
3614
- }
3615
- let r = e.get(this.decoder.frame);
3616
- this.decoder.enabled.set(!r);
3617
- }
3618
- #o(e) {
3619
- let t = e.get(this.#e);
3620
- if (!t) return;
3621
- let r = e.get(this.decoder.frame), i = requestAnimationFrame(() => {
3622
- this.#s(t, r), r ? (this.frame.update((e) => (e?.close(), r.clone())), this.timestamp.set(n.Milli.fromMicro(r.timestamp))) : (this.frame.update((e) => {
3623
- e?.close();
3624
- }), this.timestamp.set(void 0)), i = void 0;
3625
- });
3626
- e.cleanup(() => {
3627
- i && cancelAnimationFrame(i);
3628
- });
3629
- }
3630
- #s(e, t) {
3631
- if (!t) {
3632
- e.fillStyle = "#000", e.fillRect(0, 0, e.canvas.width, e.canvas.height);
3633
- return;
3634
- }
3635
- e.save(), e.fillStyle = "#000", e.fillRect(0, 0, e.canvas.width, e.canvas.height), this.decoder.source.catalog.peek()?.flip && (e.scale(-1, 1), e.translate(-e.canvas.width, 0)), e.drawImage(t, 0, 0, e.canvas.width, e.canvas.height), e.restore();
3636
- }
3637
- close() {
3638
- this.frame.update((e) => {
3639
- e?.close();
3640
- }), this.timestamp.set(void 0), this.#n.close();
3641
- }
3642
- };
3643
- //#endregion
3644
- //#region src/video/source.ts
3645
- function si(e) {
3646
- return (t) => {
3647
- let n = [], r = [];
3648
- for (let [i, a] of t) if (a.codedWidth && a.codedHeight) {
3649
- let t = a.codedWidth * a.codedHeight;
3650
- t <= e ? n.push({
3651
- name: i,
3652
- size: t
3653
- }) : r.push({
3654
- name: i,
3655
- size: t
3656
- });
3657
- }
3658
- return n.sort((e, t) => t.size - e.size), n.length > 0 ? n.map((e) => e.name) : r.length > 0 ? (r.sort((e, t) => e.size - t.size), [r[0].name]) : t.map(([e]) => e);
3659
- };
3660
- }
3661
- function ci(e, t) {
3662
- return (n) => {
3663
- let r = [], i = [];
3664
- for (let [a, o] of n) {
3665
- if (!o.codedWidth || !o.codedHeight) continue;
3666
- let n = o.codedWidth * o.codedHeight, s = e == null || o.codedWidth <= e, c = t == null || o.codedHeight <= t;
3667
- s && c ? r.push({
3668
- name: a,
3669
- size: n
3670
- }) : i.push({
3671
- name: a,
3672
- size: n
3673
- });
3674
- }
3675
- return r.sort((e, t) => t.size - e.size), r.length > 0 ? r.map((e) => e.name) : i.length > 0 ? (i.sort((e, t) => e.size - t.size), [i[0].name]) : n.map(([e]) => e);
3676
- };
3677
- }
3678
- function li(e) {
3679
- return (t) => {
3680
- let n = [], r = [];
3681
- for (let [i, a] of t) a.bitrate != null && a.bitrate <= e ? n.push({
3682
- name: i,
3683
- bitrate: a.bitrate
3684
- }) : a.bitrate != null && r.push({
3685
- name: i,
3686
- bitrate: a.bitrate
3687
- });
3688
- return n.sort((e, t) => t.bitrate - e.bitrate), n.length > 0 ? n.map((e) => e.name) : r.length > 0 ? (r.sort((e, t) => e.bitrate - t.bitrate), [r[0].name]) : t.map(([e]) => e);
3689
- };
3690
- }
3691
- function ui(e) {
3692
- let t = e[0];
3693
- for (let n of e) {
3694
- let [, e] = n, [, r] = t, i = (e.codedWidth ?? 0) * (e.codedHeight ?? 0), a = (r.codedWidth ?? 0) * (r.codedHeight ?? 0);
3695
- if (i !== a) {
3696
- i > a && (t = n);
3697
- continue;
3698
- }
3699
- (e.bitrate ?? 0) > (r.bitrate ?? 0) && (t = n);
3700
- }
3701
- return t[0];
3702
- }
3703
- var di = class {
3704
- broadcast;
3705
- target;
3706
- catalog;
3707
- #e = new i({});
3708
- available = this.#e;
3709
- #t = new i(void 0);
3710
- track = this.#t;
3711
- #n = new i(void 0);
3712
- config = this.#n;
3713
- sync;
3714
- supported;
3715
- #r = new r();
3716
- constructor(e, t) {
3717
- this.broadcast = i.from(t?.broadcast), this.target = i.from(t?.target), this.sync = e, this.supported = i.from(t?.supported), this.catalog = this.#r.computed((e) => {
3718
- let t = e.get(this.broadcast);
3719
- return t ? e.get(t.catalog)?.video : void 0;
3720
- }), this.#r.run(this.#i.bind(this)), this.#r.run(this.#a.bind(this));
3721
- }
3722
- #i(e) {
3723
- let t = e.get(this.supported);
3724
- if (!t) return;
3725
- let n = e.get(this.catalog)?.renditions ?? {};
3726
- e.spawn(async () => {
3727
- let e = {};
3728
- for (let [r, i] of Object.entries(n)) await t(i) && (e[r] = i);
3729
- Object.keys(e).length === 0 && Object.keys(n).length > 0 && console.warn("[Source] No supported video renditions found:", n), this.#e.set(e);
3730
- });
3731
- }
3732
- #a(e) {
3733
- let t = e.get(this.#e);
3734
- if (Object.keys(t).length === 0) return;
3735
- let n = e.get(this.target);
3736
- if (n?.name && n.name in t) {
3737
- let r = t[n.name];
3738
- e.set(this.#t, n.name), e.set(this.#n, r), e.set(this.sync.video, r.jitter);
3739
- return;
3740
- }
3741
- let r = n;
3742
- if (!n?.bitrate) {
3743
- let t = e.get(this.broadcast), i = (t ? e.get(t.connection) : void 0)?.recvBandwidth;
3744
- if (i) {
3745
- let t = e.get(i);
3746
- if (t != null) {
3747
- let e = Math.round(t * .8);
3748
- r = {
3749
- ...n,
3750
- bitrate: e
3751
- };
3752
- }
3753
- }
3754
- }
3755
- let i = this.#o(t, r);
3756
- if (!i) return;
3757
- let a = t[i];
3758
- e.set(this.#t, i), e.set(this.#n, a);
3759
- let o = a.jitter ?? (a.framerate ? Math.ceil(1e3 / a.framerate) : void 0);
3760
- e.set(this.sync.video, o);
3761
- }
3762
- #o(e, t) {
3763
- let n = Object.entries(e);
3764
- if (n.length === 0) return;
3765
- if (n.length === 1) return n[0][0];
3766
- let r = [];
3767
- if (t?.pixels != null && r.push(si(t.pixels)), (t?.width != null || t?.height != null) && r.push(ci(t.width, t.height)), t?.bitrate != null && r.push(li(t.bitrate)), r.length === 0) return ui(n);
3768
- let i = r.map((e) => e(n)), a = i.map((e) => new Set(e));
3769
- for (let e of i[0]) if (a.every((t) => t.has(e))) return e;
3770
- console.warn("conflicting rendition filters, no rendition satisfies all criteria");
3771
- }
3772
- close() {
3773
- this.#r.close();
3774
- }
3775
- }, fi = /* @__PURE__ */ o({
3776
- Decoder: () => ti,
3777
- Mse: () => ii,
3778
- Renderer: () => oi,
3779
- Source: () => di
3780
- });
3781
- //#endregion
3782
- //#region src/backend.ts
3783
- function pi(t) {
3784
- let n = [];
3785
- for (let r = 0; r < t.length; r++) {
3786
- let i = e.Time.Milli.fromSecond(t.start(r)), a = e.Time.Milli.fromSecond(t.end(r));
3787
- n.push({
3788
- start: i,
3789
- end: a
3790
- });
3791
- }
3792
- return n;
3793
- }
3794
- var mi = class {
3795
- source;
3796
- stats = new i(void 0);
3797
- stalled = new i(!1);
3798
- buffered = new i([]);
3799
- timestamp = new i(e.Time.Milli.zero);
3800
- constructor(e) {
3801
- this.source = e;
3802
- }
3803
- }, hi = class {
3804
- source;
3805
- volume = new i(.5);
3806
- muted = new i(!1);
3807
- stats = new i(void 0);
3808
- buffered = new i([]);
3809
- context = new i(void 0);
3810
- constructor(e) {
3811
- this.source = e;
3812
- }
3813
- }, gi = class {
3814
- element = new i(void 0);
3815
- broadcast;
3816
- latency;
3817
- jitter;
3818
- paused;
3819
- video;
3820
- #e;
3821
- audio;
3822
- #t;
3823
- sync;
3824
- signals = new r();
3825
- constructor(e) {
3826
- this.element = i.from(e?.element), this.broadcast = i.from(e?.broadcast), this.sync = new Qr({
3827
- latency: e?.latency,
3828
- connection: e?.connection
3829
- }), this.latency = this.sync.latency, this.jitter = this.sync.jitter, this.#e = new di(this.sync, { broadcast: this.broadcast }), this.#t = new bi(this.sync, { broadcast: this.broadcast }), this.video = new mi(this.#e), this.audio = new hi(this.#t), this.paused = i.from(e?.paused ?? !1), this.signals.run(this.#n.bind(this));
3830
- }
3831
- #n(e) {
3832
- let t = e.get(this.element);
3833
- t && (t instanceof HTMLCanvasElement ? this.#r(e, t) : t instanceof HTMLVideoElement && this.#i(e, t));
3834
- }
3835
- #r(e, t) {
3836
- let n = new ti(this.#e), r = new Ur(this.#t), i = new qr(r, {
3837
- volume: this.audio.volume,
3838
- muted: this.audio.muted,
3839
- paused: this.paused
3840
- }), a = new oi(n, {
3841
- canvas: t,
3842
- paused: this.paused
3843
- });
3844
- e.cleanup(() => {
3845
- n.close(), r.close(), i.close(), a.close();
3846
- }), e.proxy(this.video.stats, n.stats), e.proxy(this.video.buffered, n.buffered), e.proxy(this.video.stalled, n.stalled), e.proxy(this.video.timestamp, n.timestamp), e.proxy(this.audio.stats, r.stats), e.proxy(this.audio.buffered, r.buffered), e.proxy(this.audio.context, r.context);
3847
- }
3848
- #i(e, t) {
3849
- let n = new Yr(this.sync, {
3850
- paused: this.paused,
3851
- element: t
3852
- }), r = new ii(n, this.#e), i = new _i(n, this.#t, {
3853
- volume: this.audio.volume,
3854
- muted: this.audio.muted
3855
- });
3856
- e.cleanup(() => {
3857
- r.close(), i.close(), n.close();
3858
- }), e.proxy(this.video.stats, r.stats), e.proxy(this.video.buffered, r.buffered), e.proxy(this.video.stalled, r.stalled), e.proxy(this.video.timestamp, r.timestamp), e.proxy(this.audio.stats, i.stats), e.proxy(this.audio.buffered, i.buffered), e.proxy(this.audio.context, i.context);
3859
- }
3860
- close() {
3861
- this.signals.close(), this.#e.close(), this.#t.close(), this.sync.close();
3862
- }
3863
- }, _i = class {
3864
- muxer;
3865
- source;
3866
- volume;
3867
- muted;
3868
- #e = new i(void 0);
3869
- stats = this.#e;
3870
- #t = new i([]);
3871
- buffered = this.#t;
3872
- context = new i(void 0);
3873
- #n = new r();
3874
- constructor(e, t, n) {
3875
- this.muxer = e, this.source = t, this.source.supported.set(vi), this.volume = i.from(n?.volume ?? .5), this.muted = i.from(n?.muted ?? !1), this.#n.run(this.#r.bind(this)), this.#n.run(this.#s.bind(this));
3876
- }
3877
- #r(e) {
3878
- let t = e.get(this.muxer.element);
3879
- if (!t) return;
3880
- let n = e.get(this.muxer.mediaSource);
3881
- if (!n) return;
3882
- let r = e.get(this.source.broadcast);
3883
- if (!r) return;
3884
- let i = e.get(r.active);
3885
- if (!i) return;
3886
- let a = e.get(this.source.track);
3887
- if (!a) return;
3888
- let o = e.get(this.source.config);
3889
- if (!o) return;
3890
- let s = `audio/mp4; codecs="${o.codec}"`, c = n.addSourceBuffer(s);
3891
- e.cleanup(() => {
3892
- n.removeSourceBuffer(c), c.abort();
3893
- }), e.event(c, "error", (e) => {
3894
- console.error("[MSE] SourceBuffer error:", e);
3895
- }), e.event(c, "updateend", () => {
3896
- this.#t.set(pi(c.buffered));
3897
- });
3898
- let l = i.subscribe(a, F.audio);
3899
- e.cleanup(() => l.close()), o.container.kind === "cmaf" ? this.#a(e, l, o, c, t) : this.#o(e, l, o, c, t);
3900
- }
3901
- async #i(e, t) {
3902
- for (; e.updating;) await new Promise((t) => e.addEventListener("updateend", t, { once: !0 }));
3903
- for (e.appendBuffer(t); e.updating;) await new Promise((t) => e.addEventListener("updateend", t, { once: !0 }));
3904
- }
3905
- #a(t, n, r, i, a) {
3906
- if (r.container.kind !== "cmaf") throw Error("unreachable");
3907
- let o = J(r.container.init), s = U(o);
3908
- t.spawn(async () => {
3909
- for (await this.#i(i, o);;) {
3910
- let t = await n.readFrame();
3911
- if (!t) return;
3912
- let r = ur(t, s);
3913
- this.source.sync.received(e.Time.Milli.fromMicro(r), "audio"), await this.#i(i, t), a.buffered.length > 0 && a.currentTime < a.buffered.start(0) && (a.currentTime = a.buffered.start(0));
3914
- }
3915
- });
3916
- }
3917
- #o(t, n, r, i, a) {
3918
- let o = new K(n, {
3919
- format: r.container.kind === "loc" ? new $t() : new q(),
3920
- latency: this.source.sync.buffer
3921
- });
3922
- t.cleanup(() => o.close()), t.spawn(async () => {
3923
- let t = br(r);
3924
- await this.#i(i, t);
3925
- let n = 1, s, c;
3926
- for (;;) {
3927
- let t = await o.next();
3928
- if (!t) return;
3929
- if (!t.frame) continue;
3930
- c = t.frame;
3931
- let n = e.Time.Milli.fromMicro(c.timestamp);
3932
- this.source.sync.received(n, "audio");
3933
- break;
3934
- }
3935
- for (;;) {
3936
- let t = await o.next();
3937
- if (t && !t.frame) continue;
3938
- let r = t?.frame;
3939
- if (r) {
3940
- s = e.Time.Micro.sub(r.timestamp, c.timestamp);
3941
- let t = e.Time.Milli.fromMicro(r.timestamp);
3942
- this.source.sync.received(t, "audio");
3943
- }
3944
- let l = Dr({
3945
- data: c.data,
3946
- timestamp: c.timestamp,
3947
- duration: s ?? 0,
3948
- keyframe: c.keyframe,
3949
- sequence: n++
3950
- });
3951
- if (await this.#i(i, l), a.buffered.length > 0 && a.currentTime < a.buffered.start(0) && (a.currentTime = a.buffered.start(0)), !r) return;
3952
- c = r;
3953
- }
3954
- });
3955
- }
3956
- #s(e) {
3957
- let t = e.get(this.muxer.element);
3958
- if (!t) return;
3959
- let n = e.get(this.volume), r = e.get(this.muted);
3960
- r && !t.muted ? t.muted = !0 : !r && t.muted && (t.muted = !1), n !== t.volume && (t.volume = n), e.event(t, "volumechange", () => {
3961
- this.volume.set(t.volume);
3962
- });
3963
- }
3964
- close() {
3965
- this.#n.close();
3966
- }
3967
- };
3968
- async function vi(e) {
3969
- return MediaSource.isTypeSupported(`audio/mp4; codecs="${e.codec}"`);
3970
- }
3971
- //#endregion
3972
- //#region src/audio/source.ts
3973
- var yi = 128, bi = class {
3974
- broadcast;
3975
- target;
3976
- catalog;
3977
- #e = new i({});
3978
- available = this.#e;
3979
- #t = new i(void 0);
3980
- track = this.#t;
3981
- #n = new i(void 0);
3982
- config = this.#n;
3983
- supported;
3984
- sync;
3985
- #r = new r();
3986
- constructor(e, t) {
3987
- this.sync = e, this.broadcast = i.from(t?.broadcast), this.target = i.from(t?.target), this.supported = i.from(t?.supported), this.catalog = this.#r.computed((e) => {
3988
- let t = e.get(this.broadcast);
3989
- return t ? e.get(t.catalog)?.audio : void 0;
3990
- }), this.#r.run(this.#i.bind(this)), this.#r.run(this.#a.bind(this));
3991
- }
3992
- #i(e) {
3993
- let t = e.get(this.catalog)?.renditions ?? {}, n = e.get(this.supported);
3994
- n && e.spawn(async () => {
3995
- let e = {};
3996
- for (let [r, i] of Object.entries(t)) await n(i) && (e[r] = i);
3997
- Object.keys(e).length === 0 && Object.keys(t).length > 0 && console.warn("no supported audio renditions found:", t), this.#e.set(e);
3998
- });
3999
- }
4000
- #a(e) {
4001
- let t = e.get(this.#e);
4002
- if (Object.keys(t).length === 0) return;
4003
- let n = e.get(this.target), r;
4004
- if (n?.name && n.name in t) r = {
4005
- track: n.name,
4006
- config: t[n.name]
4007
- };
4008
- else if (r = this.#o(t), !r) return;
4009
- e.set(this.#t, r.track), e.set(this.#n, r.config);
4010
- let i = (r.config.jitter ?? xi(r.config) ?? 0) + Math.ceil(yi / r.config.sampleRate * 1e3);
4011
- e.set(this.sync.audio, i);
4012
- }
4013
- #o(e) {
4014
- let t = Object.entries(e);
4015
- if (t.length !== 0) {
4016
- for (let [e, n] of t) if (n.container.kind === "legacy") return {
4017
- track: e,
4018
- config: n
4019
- };
4020
- for (let [e, n] of t) if (n.container.kind === "loc") return {
4021
- track: e,
4022
- config: n
4023
- };
4024
- for (let [e, n] of t) if (n.container.kind === "cmaf") return {
4025
- track: e,
4026
- config: n
4027
- };
4028
- }
4029
- }
4030
- close() {
4031
- this.#r.close();
4032
- }
4033
- };
4034
- function xi(e) {
4035
- if (e.codec.startsWith("opus")) return 20;
4036
- if (e.codec.startsWith("mp4a")) return Math.ceil(1024 / e.sampleRate * 1e3);
4037
- }
4038
- //#endregion
4039
- //#region src/audio/index.ts
4040
- var Si = /* @__PURE__ */ o({
4041
- Decoder: () => Ur,
4042
- Emitter: () => qr,
4043
- Mse: () => _i,
4044
- Source: () => bi
4045
- });
4046
- //#endregion
4047
- //#region ../json/src/diff.ts
4048
- function Ci(e) {
4049
- return typeof e == "object" && !!e && !Array.isArray(e);
4050
- }
4051
- function wi(e, t) {
4052
- if (!Ci(t)) return t;
4053
- let n = Ci(e) ? { ...e } : {};
4054
- for (let [e, r] of Object.entries(t)) r === null ? delete n[e] : n[e] = wi(n[e], r);
4055
- return n;
4056
- }
4057
- //#endregion
4058
- //#region ../json/src/consumer.ts
4059
- var Ti = class {
4060
- #e;
4061
- #t;
4062
- #n;
4063
- #r;
4064
- #i = 0;
4065
- constructor(e, t = {}) {
4066
- this.#e = e, this.#t = t.schema;
4067
- }
4068
- async next() {
4069
- for (;;) {
4070
- if (!this.#n) {
4071
- if (this.#n = await this.#e.nextGroupOrdered(), !this.#n) return;
4072
- this.#r = void 0, this.#i = 0;
4073
- }
4074
- let e = await this.#n.readFrame();
4075
- if (e === void 0) {
4076
- this.#n = void 0;
4077
- continue;
4078
- }
4079
- return this.#a(e);
4080
- }
4081
- }
4082
- async *[Symbol.asyncIterator]() {
4083
- for (;;) {
4084
- let e = await this.next();
4085
- if (e === void 0) return;
4086
- yield e;
4087
- }
4088
- }
4089
- #a(e) {
4090
- let t = JSON.parse(new TextDecoder().decode(e));
4091
- return this.#i === 0 ? this.#r = t : this.#r = wi(this.#r, t), this.#i += 1, this.#t ? this.#t.parse(this.#r) : this.#r;
4092
- }
4093
- }, Ei = /* @__PURE__ */ A({
4094
- version: /* @__PURE__ */ j(1),
4095
- tracks: /* @__PURE__ */ St(/* @__PURE__ */ A({
4096
- name: /* @__PURE__ */ O(),
4097
- packaging: /* @__PURE__ */ Et([/* @__PURE__ */ Mt([
4098
- "loc",
4099
- "cmaf",
4100
- "legacy",
4101
- "mediatimeline",
4102
- "eventtimeline"
4103
- ]), /* @__PURE__ */ O()]),
4104
- isLive: /* @__PURE__ */ vt(),
4105
- role: /* @__PURE__ */ M(/* @__PURE__ */ Et([/* @__PURE__ */ Mt([
4106
- "video",
4107
- "audio",
4108
- "audiodescription",
4109
- "caption",
4110
- "subtitle",
4111
- "signlanguage"
4112
- ]), /* @__PURE__ */ O()])),
4113
- codec: /* @__PURE__ */ M(/* @__PURE__ */ O()),
4114
- width: /* @__PURE__ */ M(/* @__PURE__ */ k()),
4115
- height: /* @__PURE__ */ M(/* @__PURE__ */ k()),
4116
- framerate: /* @__PURE__ */ M(/* @__PURE__ */ k()),
4117
- samplerate: /* @__PURE__ */ M(/* @__PURE__ */ k()),
4118
- channelConfig: /* @__PURE__ */ M(/* @__PURE__ */ O()),
4119
- bitrate: /* @__PURE__ */ M(/* @__PURE__ */ k()),
4120
- initData: /* @__PURE__ */ M(/* @__PURE__ */ O()),
4121
- renderGroup: /* @__PURE__ */ M(/* @__PURE__ */ k()),
4122
- altGroup: /* @__PURE__ */ M(/* @__PURE__ */ k()),
4123
- jitter: /* @__PURE__ */ M(/* @__PURE__ */ k())
4124
- }))
4125
- });
4126
- function Di(e) {
4127
- let t = new TextDecoder().decode(e);
4128
- try {
4129
- let e = JSON.parse(t);
4130
- return Ei.parse(e);
4131
- } catch (e) {
4132
- throw console.warn("invalid MSF catalog", t), e;
4133
- }
4134
- }
4135
- async function Oi(e) {
4136
- let t = await e.readFrame();
4137
- if (t) return Di(t);
4138
- }
4139
- //#endregion
4140
- //#region src/msf.ts
4141
- var ki = 48e3, Ai = 2;
4142
- function ji(e) {
4143
- let t = "";
4144
- for (let n = 0; n < e.length; n++) t += e[n].toString(16).padStart(2, "0");
4145
- return t;
4146
- }
4147
- function Mi(e) {
4148
- let t;
4149
- try {
4150
- t = e.initData ? J(e.initData) : void 0;
4151
- } catch {
4152
- t = void 0;
4153
- }
4154
- return e.packaging === "cmaf" && e.initData && t ? {
4155
- container: {
4156
- kind: "cmaf",
4157
- init: e.initData
4158
- },
4159
- description: void 0
4160
- } : {
4161
- container: { kind: "legacy" },
4162
- description: t ? ji(t) : void 0
4163
- };
4164
- }
4165
- function Ni(e) {
4166
- if (!e.codec) return;
4167
- let { container: t, description: n } = Mi(e);
4168
- return {
4169
- codec: e.codec,
4170
- container: t,
4171
- description: n,
4172
- codedWidth: e.width == null ? void 0 : P(e.width),
4173
- codedHeight: e.height == null ? void 0 : P(e.height),
4174
- framerate: e.framerate,
4175
- bitrate: e.bitrate == null ? void 0 : P(e.bitrate),
4176
- jitter: e.jitter == null ? void 0 : P(e.jitter)
4177
- };
4178
- }
4179
- function Pi(e) {
4180
- if (!e.codec) return;
4181
- let t = (() => {
4182
- if (!e.channelConfig) return Ai;
4183
- let t = Number.parseInt(e.channelConfig, 10);
4184
- return Number.isFinite(t) ? t : Ai;
4185
- })(), { container: n, description: r } = Mi(e);
4186
- return {
4187
- codec: e.codec,
4188
- container: n,
4189
- description: r,
4190
- sampleRate: P(e.samplerate ?? ki),
4191
- numberOfChannels: P(t),
4192
- bitrate: e.bitrate == null ? void 0 : P(e.bitrate),
4193
- jitter: e.jitter == null ? void 0 : P(e.jitter)
4194
- };
4195
- }
4196
- function Fi(e) {
4197
- let t = {}, n = {};
4198
- for (let r of e.tracks) if (r.role === "video") {
4199
- let e = Ni(r);
4200
- e && (t[r.name] = e);
4201
- } else if (r.role === "audio") {
4202
- let e = Pi(r);
4203
- e && (n[r.name] = e);
4204
- }
4205
- let r = {};
4206
- return Object.keys(t).length > 0 && (r.video = { renditions: t }), Object.keys(n).length > 0 && (r.audio = { renditions: n }), r;
4207
- }
4208
- //#endregion
4209
- //#region src/broadcast.ts
4210
- var Ii = [...Gt, "manual"];
4211
- function Li(e) {
4212
- if (e !== null) return Ii.find((t) => t === e);
4213
- }
4214
- var Ri = class {
4215
- connection;
4216
- enabled;
4217
- name;
4218
- status = new i("offline");
4219
- reload;
4220
- catalogFormat;
4221
- #e = new i(void 0);
4222
- active = this.#e;
4223
- catalog;
4224
- #t;
4225
- #n = new i(!1);
4226
- signals = new r();
4227
- constructor(e) {
4228
- this.connection = i.from(e?.connection), this.name = i.from(e?.name ?? t.empty()), this.enabled = i.from(e?.enabled ?? !1), this.reload = i.from(e?.reload ?? !1), this.catalogFormat = i.from(e?.catalogFormat), this.catalog = i.from(e?.catalog), this.#t = e?.announced ?? new i(/* @__PURE__ */ new Set()), this.signals.run(this.#r.bind(this)), this.signals.run(this.#i.bind(this)), this.signals.run(this.#a.bind(this));
4229
- }
4230
- #r(e) {
4231
- if (!e.get(this.reload)) {
4232
- this.#n.set(!0);
4233
- return;
4234
- }
4235
- if (e.get(this.connection)?.url.hostname.endsWith("mediaoverquic.com")) {
4236
- console.warn("Cloudflare relay does not support broadcast discovery yet; ignoring reload signal."), this.#n.set(!0);
4237
- return;
4238
- }
4239
- let t = e.get(this.name), n = e.get(this.#t);
4240
- this.#n.set(n.has(t));
4241
- }
4242
- #i(e) {
4243
- if (!e.get(this.enabled) || !e.get(this.#n)) return;
4244
- let t = e.get(this.connection);
4245
- if (!t) return;
4246
- let n = e.get(this.name), r = t.consume(n);
4247
- e.cleanup(() => r.close()), e.set(this.#e, r, void 0);
4248
- }
4249
- #a(e) {
4250
- if (!e.get(this.enabled)) return;
4251
- let t = e.get(this.catalogFormat), n = e.get(this.name), r = t ?? Kt(n) ?? "hang";
4252
- if (r === "manual") {
4253
- let t = e.get(this.catalog);
4254
- this.status.set(t ? "live" : "loading");
4255
- return;
4256
- }
4257
- let i = e.get(this.active);
4258
- if (!i) return;
4259
- this.status.set("loading");
4260
- let a = r === "hang" ? "catalog.json" : "catalog", o = i.subscribe(a, F.catalog);
4261
- e.cleanup(() => o.close());
4262
- let s;
4263
- if (r === "hang") {
4264
- let e = new Ti(o, { schema: Yt });
4265
- s = () => e.next();
4266
- } else s = async () => {
4267
- let e = await Oi(o);
4268
- return e ? Fi(e) : void 0;
4269
- };
4270
- e.spawn(async () => {
4271
- try {
4272
- for (;;) {
4273
- let t = await Promise.race([e.cancel, s()]);
4274
- if (!t) break;
4275
- console.debug("received catalog", r, this.name.peek(), t), this.catalog.set(t), this.status.set("live");
4276
- }
4277
- } catch (e) {
4278
- console.warn("error fetching catalog", this.name.peek(), e);
4279
- } finally {
4280
- this.catalog.set(void 0), this.status.set("offline");
4281
- }
4282
- });
4283
- }
4284
- close() {
4285
- this.signals.close();
4286
- }
4287
- };
4288
- //#endregion
4289
- export { gi as a, Qr as c, Si as i, Jr as l, Ii as n, pi as o, Li as r, fi as s, Ri as t, s as u };
4290
-
4291
- //# sourceMappingURL=broadcast-jtLUfuyL.js.map