@moq/watch 0.2.10 → 0.2.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,38 +1,38 @@
1
1
  import * as _ from "@moq/lite";
2
- import { Time as p, Path as Ht } from "@moq/lite";
3
- import { Signal as h, Effect as U } from "@moq/signals";
4
- function w(t, e, n) {
5
- function s(a, c) {
6
- if (a._zod || Object.defineProperty(a, "_zod", {
2
+ import { Time as p, Path as Kt } from "@moq/lite";
3
+ import { Signal as h, Effect as E } from "@moq/signals";
4
+ function g(t, e, n) {
5
+ function s(c, a) {
6
+ if (c._zod || Object.defineProperty(c, "_zod", {
7
7
  value: {
8
- def: c,
8
+ def: a,
9
9
  constr: o,
10
10
  traits: /* @__PURE__ */ new Set()
11
11
  },
12
12
  enumerable: !1
13
- }), a._zod.traits.has(t))
13
+ }), c._zod.traits.has(t))
14
14
  return;
15
- a._zod.traits.add(t), e(a, c);
15
+ c._zod.traits.add(t), e(c, a);
16
16
  const u = o.prototype, l = Object.keys(u);
17
17
  for (let d = 0; d < l.length; d++) {
18
18
  const f = l[d];
19
- f in a || (a[f] = u[f].bind(a));
19
+ f in c || (c[f] = u[f].bind(c));
20
20
  }
21
21
  }
22
22
  const i = n?.Parent ?? Object;
23
23
  class r extends i {
24
24
  }
25
25
  Object.defineProperty(r, "name", { value: t });
26
- function o(a) {
27
- var c;
26
+ function o(c) {
27
+ var a;
28
28
  const u = n?.Parent ? new r() : this;
29
- s(u, a), (c = u._zod).deferred ?? (c.deferred = []);
29
+ s(u, c), (a = u._zod).deferred ?? (a.deferred = []);
30
30
  for (const l of u._zod.deferred)
31
31
  l();
32
32
  return u;
33
33
  }
34
34
  return Object.defineProperty(o, "init", { value: s }), Object.defineProperty(o, Symbol.hasInstance, {
35
- value: (a) => n?.Parent && a instanceof n.Parent ? !0 : a?._zod?.traits?.has(t)
35
+ value: (c) => n?.Parent && c instanceof n.Parent ? !0 : c?._zod?.traits?.has(t)
36
36
  }), Object.defineProperty(o, "name", { value: t }), o;
37
37
  }
38
38
  class Q extends Error {
@@ -40,23 +40,23 @@ class Q extends Error {
40
40
  super("Encountered Promise during synchronous parse. Use .parseAsync() instead.");
41
41
  }
42
42
  }
43
- class Gt extends Error {
43
+ class Jt extends Error {
44
44
  constructor(e) {
45
45
  super(`Encountered unidirectional transform during encode: ${e}`), this.name = "ZodEncodeError";
46
46
  }
47
47
  }
48
- const Xt = {};
49
- function ne(t) {
50
- return Xt;
48
+ const Qt = {};
49
+ function se(t) {
50
+ return Qt;
51
51
  }
52
- function Yt(t) {
52
+ function en(t) {
53
53
  const e = Object.values(t).filter((s) => typeof s == "number");
54
54
  return Object.entries(t).filter(([s, i]) => e.indexOf(+s) === -1).map(([s, i]) => i);
55
55
  }
56
- function Kt(t, e) {
56
+ function tn(t, e) {
57
57
  return typeof e == "bigint" ? e.toString() : e;
58
58
  }
59
- function ot(t) {
59
+ function ct(t) {
60
60
  return {
61
61
  get value() {
62
62
  {
@@ -66,17 +66,17 @@ function ot(t) {
66
66
  }
67
67
  };
68
68
  }
69
- function at(t) {
69
+ function ut(t) {
70
70
  const e = t.startsWith("^") ? 1 : 0, n = t.endsWith("$") ? t.length - 1 : t.length;
71
71
  return t.slice(e, n);
72
72
  }
73
- const Pe = /* @__PURE__ */ Symbol("evaluating");
74
- function R(t, e, n) {
73
+ const je = /* @__PURE__ */ Symbol("evaluating");
74
+ function x(t, e, n) {
75
75
  let s;
76
76
  Object.defineProperty(t, e, {
77
77
  get() {
78
- if (s !== Pe)
79
- return s === void 0 && (s = Pe, s = n()), s;
78
+ if (s !== je)
79
+ return s === void 0 && (s = je, s = n()), s;
80
80
  },
81
81
  set(i) {
82
82
  Object.defineProperty(t, e, {
@@ -87,38 +87,38 @@ function R(t, e, n) {
87
87
  configurable: !0
88
88
  });
89
89
  }
90
- const ct = "captureStackTrace" in Error ? Error.captureStackTrace : (...t) => {
90
+ const lt = "captureStackTrace" in Error ? Error.captureStackTrace : (...t) => {
91
91
  };
92
- function ge(t) {
92
+ function we(t) {
93
93
  return typeof t == "object" && t !== null && !Array.isArray(t);
94
94
  }
95
- function ut(t) {
96
- if (ge(t) === !1)
95
+ function dt(t) {
96
+ if (we(t) === !1)
97
97
  return !1;
98
98
  const e = t.constructor;
99
99
  if (e === void 0 || typeof e != "function")
100
100
  return !0;
101
101
  const n = e.prototype;
102
- return !(ge(n) === !1 || Object.prototype.hasOwnProperty.call(n, "isPrototypeOf") === !1);
102
+ return !(we(n) === !1 || Object.prototype.hasOwnProperty.call(n, "isPrototypeOf") === !1);
103
103
  }
104
- function Jt(t) {
105
- return ut(t) ? { ...t } : Array.isArray(t) ? [...t] : t;
104
+ function nn(t) {
105
+ return dt(t) ? { ...t } : Array.isArray(t) ? [...t] : t;
106
106
  }
107
- const Qt = /* @__PURE__ */ new Set(["string", "number", "symbol"]);
108
- function ke(t) {
107
+ const sn = /* @__PURE__ */ new Set(["string", "number", "symbol"]);
108
+ function Be(t) {
109
109
  return t.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
110
110
  }
111
- function en(t, e, n) {
111
+ function rn(t, e, n) {
112
112
  const s = new t._zod.constr(e ?? t._zod.def);
113
113
  return (!e || n?.parent) && (s._zod.parent = t), s;
114
114
  }
115
- function O(t) {
115
+ function R(t) {
116
116
  return {};
117
117
  }
118
- function tn(t) {
118
+ function on(t) {
119
119
  return Object.keys(t).filter((e) => t[e]._zod.optin === "optional" && t[e]._zod.optout === "optional");
120
120
  }
121
- const nn = {
121
+ const an = {
122
122
  safeint: [Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER],
123
123
  int32: [-2147483648, 2147483647],
124
124
  uint32: [0, 4294967295],
@@ -139,73 +139,73 @@ function J(t, e) {
139
139
  return (s = n).path ?? (s.path = []), n.path.unshift(t), n;
140
140
  });
141
141
  }
142
- function me(t) {
142
+ function pe(t) {
143
143
  return typeof t == "string" ? t : t?.message;
144
144
  }
145
- function se(t, e, n) {
145
+ function ie(t, e, n) {
146
146
  const s = { ...t, path: t.path ?? [] };
147
147
  if (!t.message) {
148
- const i = me(t.inst?._zod.def?.error?.(t)) ?? me(e?.error?.(t)) ?? me(n.customError?.(t)) ?? me(n.localeError?.(t)) ?? "Invalid input";
148
+ const i = pe(t.inst?._zod.def?.error?.(t)) ?? pe(e?.error?.(t)) ?? pe(n.customError?.(t)) ?? pe(n.localeError?.(t)) ?? "Invalid input";
149
149
  s.message = i;
150
150
  }
151
151
  return delete s.inst, delete s.continue, e?.reportInput || delete s.input, s;
152
152
  }
153
- const lt = (t, e) => {
153
+ const ht = (t, e) => {
154
154
  t.name = "$ZodError", Object.defineProperty(t, "_zod", {
155
155
  value: t._zod,
156
156
  enumerable: !1
157
157
  }), Object.defineProperty(t, "issues", {
158
158
  value: e,
159
159
  enumerable: !1
160
- }), t.message = JSON.stringify(e, Kt, 2), Object.defineProperty(t, "toString", {
160
+ }), t.message = JSON.stringify(e, tn, 2), Object.defineProperty(t, "toString", {
161
161
  value: () => t.message,
162
162
  enumerable: !1
163
163
  });
164
- }, sn = w("$ZodError", lt), ve = w("$ZodError", lt, { Parent: Error }), rn = (t) => (e, n, s, i) => {
164
+ }, cn = g("$ZodError", ht), Se = g("$ZodError", ht, { Parent: Error }), un = (t) => (e, n, s, i) => {
165
165
  const r = s ? Object.assign(s, { async: !1 }) : { async: !1 }, o = e._zod.run({ value: n, issues: [] }, r);
166
166
  if (o instanceof Promise)
167
167
  throw new Q();
168
168
  if (o.issues.length) {
169
- const a = new (i?.Err ?? t)(o.issues.map((c) => se(c, r, ne())));
170
- throw ct(a, i?.callee), a;
169
+ const c = new (i?.Err ?? t)(o.issues.map((a) => ie(a, r, se())));
170
+ throw lt(c, i?.callee), c;
171
171
  }
172
172
  return o.value;
173
- }, on = /* @__PURE__ */ rn(ve), an = (t) => async (e, n, s, i) => {
173
+ }, ln = /* @__PURE__ */ un(Se), dn = (t) => async (e, n, s, i) => {
174
174
  const r = s ? Object.assign(s, { async: !0 }) : { async: !0 };
175
175
  let o = e._zod.run({ value: n, issues: [] }, r);
176
176
  if (o instanceof Promise && (o = await o), o.issues.length) {
177
- const a = new (i?.Err ?? t)(o.issues.map((c) => se(c, r, ne())));
178
- throw ct(a, i?.callee), a;
177
+ const c = new (i?.Err ?? t)(o.issues.map((a) => ie(a, r, se())));
178
+ throw lt(c, i?.callee), c;
179
179
  }
180
180
  return o.value;
181
- }, cn = /* @__PURE__ */ an(ve), un = (t) => (e, n, s) => {
181
+ }, hn = /* @__PURE__ */ dn(Se), fn = (t) => (e, n, s) => {
182
182
  const i = s ? { ...s, async: !1 } : { async: !1 }, r = e._zod.run({ value: n, issues: [] }, i);
183
183
  if (r instanceof Promise)
184
184
  throw new Q();
185
185
  return r.issues.length ? {
186
186
  success: !1,
187
- error: new (t ?? sn)(r.issues.map((o) => se(o, i, ne())))
187
+ error: new (t ?? cn)(r.issues.map((o) => ie(o, i, se())))
188
188
  } : { success: !0, data: r.value };
189
- }, dt = /* @__PURE__ */ un(ve), ln = (t) => async (e, n, s) => {
189
+ }, ft = /* @__PURE__ */ fn(Se), mn = (t) => async (e, n, s) => {
190
190
  const i = s ? Object.assign(s, { async: !0 }) : { async: !0 };
191
191
  let r = e._zod.run({ value: n, issues: [] }, i);
192
192
  return r instanceof Promise && (r = await r), r.issues.length ? {
193
193
  success: !1,
194
- error: new t(r.issues.map((o) => se(o, i, ne())))
194
+ error: new t(r.issues.map((o) => ie(o, i, se())))
195
195
  } : { success: !0, data: r.value };
196
- }, ht = /* @__PURE__ */ ln(ve), dn = (t) => {
196
+ }, mt = /* @__PURE__ */ mn(Se), pn = /^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/, gn = (t) => {
197
197
  const e = t ? `[\\s\\S]{${t?.minimum ?? 0},${t?.maximum ?? ""}}` : "[\\s\\S]*";
198
198
  return new RegExp(`^${e}$`);
199
- }, hn = /^-?\d+$/, ft = /^-?\d+(?:\.\d+)?$/, fn = /^(?:true|false)$/i, Ue = /* @__PURE__ */ w("$ZodCheck", (t, e) => {
199
+ }, wn = /^-?\d+$/, pt = /^-?\d+(?:\.\d+)?$/, yn = /^(?:true|false)$/i, Ae = /* @__PURE__ */ g("$ZodCheck", (t, e) => {
200
200
  var n;
201
201
  t._zod ?? (t._zod = {}), t._zod.def = e, (n = t._zod).onattach ?? (n.onattach = []);
202
- }), mt = {
202
+ }), gt = {
203
203
  number: "number",
204
204
  bigint: "bigint",
205
205
  object: "date"
206
- }, mn = /* @__PURE__ */ w("$ZodCheckLessThan", (t, e) => {
207
- Ue.init(t, e);
208
- const n = mt[typeof e.value];
206
+ }, bn = /* @__PURE__ */ g("$ZodCheckLessThan", (t, e) => {
207
+ Ae.init(t, e);
208
+ const n = gt[typeof e.value];
209
209
  t._zod.onattach.push((s) => {
210
210
  const i = s._zod.bag, r = (e.inclusive ? i.maximum : i.exclusiveMaximum) ?? Number.POSITIVE_INFINITY;
211
211
  e.value < r && (e.inclusive ? i.maximum = e.value : i.exclusiveMaximum = e.value);
@@ -220,9 +220,9 @@ const lt = (t, e) => {
220
220
  continue: !e.abort
221
221
  });
222
222
  };
223
- }), pn = /* @__PURE__ */ w("$ZodCheckGreaterThan", (t, e) => {
224
- Ue.init(t, e);
225
- const n = mt[typeof e.value];
223
+ }), vn = /* @__PURE__ */ g("$ZodCheckGreaterThan", (t, e) => {
224
+ Ae.init(t, e);
225
+ const n = gt[typeof e.value];
226
226
  t._zod.onattach.push((s) => {
227
227
  const i = s._zod.bag, r = (e.inclusive ? i.minimum : i.exclusiveMinimum) ?? Number.NEGATIVE_INFINITY;
228
228
  e.value > r && (e.inclusive ? i.minimum = e.value : i.exclusiveMinimum = e.value);
@@ -237,29 +237,29 @@ const lt = (t, e) => {
237
237
  continue: !e.abort
238
238
  });
239
239
  };
240
- }), gn = /* @__PURE__ */ w("$ZodCheckNumberFormat", (t, e) => {
241
- Ue.init(t, e), e.format = e.format || "float64";
242
- const n = e.format?.includes("int"), s = n ? "int" : "number", [i, r] = nn[e.format];
240
+ }), Sn = /* @__PURE__ */ g("$ZodCheckNumberFormat", (t, e) => {
241
+ Ae.init(t, e), e.format = e.format || "float64";
242
+ const n = e.format?.includes("int"), s = n ? "int" : "number", [i, r] = an[e.format];
243
243
  t._zod.onattach.push((o) => {
244
- const a = o._zod.bag;
245
- a.format = e.format, a.minimum = i, a.maximum = r, n && (a.pattern = hn);
244
+ const c = o._zod.bag;
245
+ c.format = e.format, c.minimum = i, c.maximum = r, n && (c.pattern = wn);
246
246
  }), t._zod.check = (o) => {
247
- const a = o.value;
247
+ const c = o.value;
248
248
  if (n) {
249
- if (!Number.isInteger(a)) {
249
+ if (!Number.isInteger(c)) {
250
250
  o.issues.push({
251
251
  expected: s,
252
252
  format: e.format,
253
253
  code: "invalid_type",
254
254
  continue: !1,
255
- input: a,
255
+ input: c,
256
256
  inst: t
257
257
  });
258
258
  return;
259
259
  }
260
- if (!Number.isSafeInteger(a)) {
261
- a > 0 ? o.issues.push({
262
- input: a,
260
+ if (!Number.isSafeInteger(c)) {
261
+ c > 0 ? o.issues.push({
262
+ input: c,
263
263
  code: "too_big",
264
264
  maximum: Number.MAX_SAFE_INTEGER,
265
265
  note: "Integers must be within the safe integer range.",
@@ -268,7 +268,7 @@ const lt = (t, e) => {
268
268
  inclusive: !0,
269
269
  continue: !e.abort
270
270
  }) : o.issues.push({
271
- input: a,
271
+ input: c,
272
272
  code: "too_small",
273
273
  minimum: Number.MIN_SAFE_INTEGER,
274
274
  note: "Integers must be within the safe integer range.",
@@ -280,17 +280,17 @@ const lt = (t, e) => {
280
280
  return;
281
281
  }
282
282
  }
283
- a < i && o.issues.push({
283
+ c < i && o.issues.push({
284
284
  origin: "number",
285
- input: a,
285
+ input: c,
286
286
  code: "too_small",
287
287
  minimum: i,
288
288
  inclusive: !0,
289
289
  inst: t,
290
290
  continue: !e.abort
291
- }), a > r && o.issues.push({
291
+ }), c > r && o.issues.push({
292
292
  origin: "number",
293
- input: a,
293
+ input: c,
294
294
  code: "too_big",
295
295
  maximum: r,
296
296
  inclusive: !0,
@@ -298,13 +298,30 @@ const lt = (t, e) => {
298
298
  continue: !e.abort
299
299
  });
300
300
  };
301
- }), wn = {
301
+ }), An = /* @__PURE__ */ g("$ZodCheckStringFormat", (t, e) => {
302
+ var n, s;
303
+ Ae.init(t, e), t._zod.onattach.push((i) => {
304
+ const r = i._zod.bag;
305
+ r.format = e.format, e.pattern && (r.patterns ?? (r.patterns = /* @__PURE__ */ new Set()), r.patterns.add(e.pattern));
306
+ }), e.pattern ? (n = t._zod).check ?? (n.check = (i) => {
307
+ e.pattern.lastIndex = 0, !e.pattern.test(i.value) && i.issues.push({
308
+ origin: "string",
309
+ code: "invalid_format",
310
+ format: e.format,
311
+ input: i.value,
312
+ ...e.pattern ? { pattern: e.pattern.toString() } : {},
313
+ inst: t,
314
+ continue: !e.abort
315
+ });
316
+ }) : (s = t._zod).check ?? (s.check = () => {
317
+ });
318
+ }), _n = {
302
319
  major: 4,
303
320
  minor: 3,
304
321
  patch: 6
305
- }, C = /* @__PURE__ */ w("$ZodType", (t, e) => {
322
+ }, C = /* @__PURE__ */ g("$ZodType", (t, e) => {
306
323
  var n;
307
- t ?? (t = {}), t._zod.def = e, t._zod.bag = t._zod.bag || {}, t._zod.version = wn;
324
+ t ?? (t = {}), t._zod.def = e, t._zod.bag = t._zod.bag || {}, t._zod.version = _n;
308
325
  const s = [...t._zod.def.checks ?? []];
309
326
  t._zod.traits.has("$ZodCheck") && s.unshift(t);
310
327
  for (const i of s)
@@ -315,20 +332,20 @@ const lt = (t, e) => {
315
332
  t._zod.run = t._zod.parse;
316
333
  });
317
334
  else {
318
- const i = (o, a, c) => {
335
+ const i = (o, c, a) => {
319
336
  let u = ce(o), l;
320
- for (const d of a) {
337
+ for (const d of c) {
321
338
  if (d._zod.def.when) {
322
339
  if (!d._zod.def.when(o))
323
340
  continue;
324
341
  } else if (u)
325
342
  continue;
326
- const f = o.issues.length, g = d._zod.check(o);
327
- if (g instanceof Promise && c?.async === !1)
343
+ const f = o.issues.length, w = d._zod.check(o);
344
+ if (w instanceof Promise && a?.async === !1)
328
345
  throw new Q();
329
- if (l || g instanceof Promise)
346
+ if (l || w instanceof Promise)
330
347
  l = (l ?? Promise.resolve()).then(async () => {
331
- await g, o.issues.length !== f && (u || (u = ce(o, f)));
348
+ await w, o.issues.length !== f && (u || (u = ce(o, f)));
332
349
  });
333
350
  else {
334
351
  if (o.issues.length === f)
@@ -337,47 +354,47 @@ const lt = (t, e) => {
337
354
  }
338
355
  }
339
356
  return l ? l.then(() => o) : o;
340
- }, r = (o, a, c) => {
357
+ }, r = (o, c, a) => {
341
358
  if (ce(o))
342
359
  return o.aborted = !0, o;
343
- const u = i(a, s, c);
360
+ const u = i(c, s, a);
344
361
  if (u instanceof Promise) {
345
- if (c.async === !1)
362
+ if (a.async === !1)
346
363
  throw new Q();
347
- return u.then((l) => t._zod.parse(l, c));
364
+ return u.then((l) => t._zod.parse(l, a));
348
365
  }
349
- return t._zod.parse(u, c);
366
+ return t._zod.parse(u, a);
350
367
  };
351
- t._zod.run = (o, a) => {
352
- if (a.skipChecks)
353
- return t._zod.parse(o, a);
354
- if (a.direction === "backward") {
355
- const u = t._zod.parse({ value: o.value, issues: [] }, { ...a, skipChecks: !0 });
356
- return u instanceof Promise ? u.then((l) => r(l, o, a)) : r(u, o, a);
368
+ t._zod.run = (o, c) => {
369
+ if (c.skipChecks)
370
+ return t._zod.parse(o, c);
371
+ if (c.direction === "backward") {
372
+ const u = t._zod.parse({ value: o.value, issues: [] }, { ...c, skipChecks: !0 });
373
+ return u instanceof Promise ? u.then((l) => r(l, o, c)) : r(u, o, c);
357
374
  }
358
- const c = t._zod.parse(o, a);
359
- if (c instanceof Promise) {
360
- if (a.async === !1)
375
+ const a = t._zod.parse(o, c);
376
+ if (a instanceof Promise) {
377
+ if (c.async === !1)
361
378
  throw new Q();
362
- return c.then((u) => i(u, s, a));
379
+ return a.then((u) => i(u, s, c));
363
380
  }
364
- return i(c, s, a);
381
+ return i(a, s, c);
365
382
  };
366
383
  }
367
- R(t, "~standard", () => ({
384
+ x(t, "~standard", () => ({
368
385
  validate: (i) => {
369
386
  try {
370
- const r = dt(t, i);
387
+ const r = ft(t, i);
371
388
  return r.success ? { value: r.data } : { issues: r.error?.issues };
372
389
  } catch {
373
- return ht(t, i).then((o) => o.success ? { value: o.data } : { issues: o.error?.issues });
390
+ return mt(t, i).then((o) => o.success ? { value: o.data } : { issues: o.error?.issues });
374
391
  }
375
392
  },
376
393
  vendor: "zod",
377
394
  version: 1
378
395
  }));
379
- }), yn = /* @__PURE__ */ w("$ZodString", (t, e) => {
380
- C.init(t, e), t._zod.pattern = [...t?._zod.bag?.patterns ?? []].pop() ?? dn(t._zod.bag), t._zod.parse = (n, s) => {
396
+ }), wt = /* @__PURE__ */ g("$ZodString", (t, e) => {
397
+ C.init(t, e), t._zod.pattern = [...t?._zod.bag?.patterns ?? []].pop() ?? gn(t._zod.bag), t._zod.parse = (n, s) => {
381
398
  if (e.coerce)
382
399
  try {
383
400
  n.value = String(n.value);
@@ -390,8 +407,32 @@ const lt = (t, e) => {
390
407
  inst: t
391
408
  }), n;
392
409
  };
393
- }), pt = /* @__PURE__ */ w("$ZodNumber", (t, e) => {
394
- C.init(t, e), t._zod.pattern = t._zod.bag.pattern ?? ft, t._zod.parse = (n, s) => {
410
+ }), yt = /* @__PURE__ */ g("$ZodStringFormat", (t, e) => {
411
+ An.init(t, e), wt.init(t, e);
412
+ });
413
+ function zn(t) {
414
+ if (t === "")
415
+ return !0;
416
+ if (t.length % 4 !== 0)
417
+ return !1;
418
+ try {
419
+ return atob(t), !0;
420
+ } catch {
421
+ return !1;
422
+ }
423
+ }
424
+ const Mn = /* @__PURE__ */ g("$ZodBase64", (t, e) => {
425
+ e.pattern ?? (e.pattern = pn), yt.init(t, e), t._zod.bag.contentEncoding = "base64", t._zod.check = (n) => {
426
+ zn(n.value) || n.issues.push({
427
+ code: "invalid_format",
428
+ format: "base64",
429
+ input: n.value,
430
+ inst: t,
431
+ continue: !e.abort
432
+ });
433
+ };
434
+ }), bt = /* @__PURE__ */ g("$ZodNumber", (t, e) => {
435
+ C.init(t, e), t._zod.pattern = t._zod.bag.pattern ?? pt, t._zod.parse = (n, s) => {
395
436
  if (e.coerce)
396
437
  try {
397
438
  n.value = Number(n.value);
@@ -409,10 +450,10 @@ const lt = (t, e) => {
409
450
  ...r ? { received: r } : {}
410
451
  }), n;
411
452
  };
412
- }), vn = /* @__PURE__ */ w("$ZodNumberFormat", (t, e) => {
413
- gn.init(t, e), pt.init(t, e);
414
- }), bn = /* @__PURE__ */ w("$ZodBoolean", (t, e) => {
415
- C.init(t, e), t._zod.pattern = fn, t._zod.parse = (n, s) => {
453
+ }), kn = /* @__PURE__ */ g("$ZodNumberFormat", (t, e) => {
454
+ Sn.init(t, e), bt.init(t, e);
455
+ }), Tn = /* @__PURE__ */ g("$ZodBoolean", (t, e) => {
456
+ C.init(t, e), t._zod.pattern = yn, t._zod.parse = (n, s) => {
416
457
  if (e.coerce)
417
458
  try {
418
459
  n.value = !!n.value;
@@ -427,10 +468,10 @@ const lt = (t, e) => {
427
468
  }), n;
428
469
  };
429
470
  });
430
- function Ne(t, e, n) {
471
+ function Ze(t, e, n) {
431
472
  t.issues.length && e.issues.push(...J(n, t.issues)), e.value[n] = t.value;
432
473
  }
433
- const Sn = /* @__PURE__ */ w("$ZodArray", (t, e) => {
474
+ const Un = /* @__PURE__ */ g("$ZodArray", (t, e) => {
434
475
  C.init(t, e), t._zod.parse = (n, s) => {
435
476
  const i = n.value;
436
477
  if (!Array.isArray(i))
@@ -443,16 +484,16 @@ const Sn = /* @__PURE__ */ w("$ZodArray", (t, e) => {
443
484
  n.value = Array(i.length);
444
485
  const r = [];
445
486
  for (let o = 0; o < i.length; o++) {
446
- const a = i[o], c = e.element._zod.run({
447
- value: a,
487
+ const c = i[o], a = e.element._zod.run({
488
+ value: c,
448
489
  issues: []
449
490
  }, s);
450
- c instanceof Promise ? r.push(c.then((u) => Ne(u, n, o))) : Ne(c, n, o);
491
+ a instanceof Promise ? r.push(a.then((u) => Ze(u, n, o))) : Ze(a, n, o);
451
492
  }
452
493
  return r.length ? Promise.all(r).then(() => n) : n;
453
494
  };
454
495
  });
455
- function we(t, e, n, s, i) {
496
+ function ye(t, e, n, s, i) {
456
497
  if (t.issues.length) {
457
498
  if (i && !(n in s))
458
499
  return;
@@ -460,12 +501,12 @@ function we(t, e, n, s, i) {
460
501
  }
461
502
  t.value === void 0 ? n in s && (e.value[n] = void 0) : e.value[n] = t.value;
462
503
  }
463
- function An(t) {
504
+ function En(t) {
464
505
  const e = Object.keys(t.shape);
465
506
  for (const s of e)
466
507
  if (!t.shape?.[s]?._zod?.traits?.has("$ZodType"))
467
508
  throw new Error(`Invalid element at key "${s}": expected a Zod schema`);
468
- const n = tn(t.shape);
509
+ const n = on(t.shape);
469
510
  return {
470
511
  ...t,
471
512
  keys: e,
@@ -474,17 +515,17 @@ function An(t) {
474
515
  optionalKeys: new Set(n)
475
516
  };
476
517
  }
477
- function _n(t, e, n, s, i, r) {
478
- const o = [], a = i.keySet, c = i.catchall._zod, u = c.def.type, l = c.optout === "optional";
518
+ function xn(t, e, n, s, i, r) {
519
+ const o = [], c = i.keySet, a = i.catchall._zod, u = a.def.type, l = a.optout === "optional";
479
520
  for (const d in e) {
480
- if (a.has(d))
521
+ if (c.has(d))
481
522
  continue;
482
523
  if (u === "never") {
483
524
  o.push(d);
484
525
  continue;
485
526
  }
486
- const f = c.run({ value: e[d], issues: [] }, s);
487
- f instanceof Promise ? t.push(f.then((g) => we(g, n, d, e, l))) : we(f, n, d, e, l);
527
+ const f = a.run({ value: e[d], issues: [] }, s);
528
+ f instanceof Promise ? t.push(f.then((w) => ye(w, n, d, e, l))) : ye(f, n, d, e, l);
488
529
  }
489
530
  return o.length && n.issues.push({
490
531
  code: "unrecognized_keys",
@@ -493,53 +534,53 @@ function _n(t, e, n, s, i, r) {
493
534
  inst: r
494
535
  }), t.length ? Promise.all(t).then(() => n) : n;
495
536
  }
496
- const Mn = /* @__PURE__ */ w("$ZodObject", (t, e) => {
537
+ const Bn = /* @__PURE__ */ g("$ZodObject", (t, e) => {
497
538
  if (C.init(t, e), !Object.getOwnPropertyDescriptor(e, "shape")?.get) {
498
- const a = e.shape;
539
+ const c = e.shape;
499
540
  Object.defineProperty(e, "shape", {
500
541
  get: () => {
501
- const c = { ...a };
542
+ const a = { ...c };
502
543
  return Object.defineProperty(e, "shape", {
503
- value: c
504
- }), c;
544
+ value: a
545
+ }), a;
505
546
  }
506
547
  });
507
548
  }
508
- const s = ot(() => An(e));
509
- R(t._zod, "propValues", () => {
510
- const a = e.shape, c = {};
511
- for (const u in a) {
512
- const l = a[u]._zod;
549
+ const s = ct(() => En(e));
550
+ x(t._zod, "propValues", () => {
551
+ const c = e.shape, a = {};
552
+ for (const u in c) {
553
+ const l = c[u]._zod;
513
554
  if (l.values) {
514
- c[u] ?? (c[u] = /* @__PURE__ */ new Set());
555
+ a[u] ?? (a[u] = /* @__PURE__ */ new Set());
515
556
  for (const d of l.values)
516
- c[u].add(d);
557
+ a[u].add(d);
517
558
  }
518
559
  }
519
- return c;
560
+ return a;
520
561
  });
521
- const i = ge, r = e.catchall;
562
+ const i = we, r = e.catchall;
522
563
  let o;
523
- t._zod.parse = (a, c) => {
564
+ t._zod.parse = (c, a) => {
524
565
  o ?? (o = s.value);
525
- const u = a.value;
566
+ const u = c.value;
526
567
  if (!i(u))
527
- return a.issues.push({
568
+ return c.issues.push({
528
569
  expected: "object",
529
570
  code: "invalid_type",
530
571
  input: u,
531
572
  inst: t
532
- }), a;
533
- a.value = {};
573
+ }), c;
574
+ c.value = {};
534
575
  const l = [], d = o.shape;
535
576
  for (const f of o.keys) {
536
- const g = d[f], y = g._zod.optout === "optional", v = g._zod.run({ value: u[f], issues: [] }, c);
537
- v instanceof Promise ? l.push(v.then((A) => we(A, a, f, u, y))) : we(v, a, f, u, y);
577
+ const w = d[f], y = w._zod.optout === "optional", b = w._zod.run({ value: u[f], issues: [] }, a);
578
+ b instanceof Promise ? l.push(b.then((A) => ye(A, c, f, u, y))) : ye(b, c, f, u, y);
538
579
  }
539
- return r ? _n(l, u, a, c, s.value, t) : l.length ? Promise.all(l).then(() => a) : a;
580
+ return r ? xn(l, u, c, a, s.value, t) : l.length ? Promise.all(l).then(() => c) : c;
540
581
  };
541
582
  });
542
- function Fe(t, e, n, s) {
583
+ function Ve(t, e, n, s) {
543
584
  for (const r of t)
544
585
  if (r.issues.length === 0)
545
586
  return e.value = r.value, e;
@@ -548,17 +589,17 @@ function Fe(t, e, n, s) {
548
589
  code: "invalid_union",
549
590
  input: e.value,
550
591
  inst: n,
551
- errors: t.map((r) => r.issues.map((o) => se(o, s, ne())))
592
+ errors: t.map((r) => r.issues.map((o) => ie(o, s, se())))
552
593
  }), e);
553
594
  }
554
- const gt = /* @__PURE__ */ w("$ZodUnion", (t, e) => {
555
- C.init(t, e), R(t._zod, "optin", () => e.options.some((i) => i._zod.optin === "optional") ? "optional" : void 0), R(t._zod, "optout", () => e.options.some((i) => i._zod.optout === "optional") ? "optional" : void 0), R(t._zod, "values", () => {
595
+ const vt = /* @__PURE__ */ g("$ZodUnion", (t, e) => {
596
+ C.init(t, e), x(t._zod, "optin", () => e.options.some((i) => i._zod.optin === "optional") ? "optional" : void 0), x(t._zod, "optout", () => e.options.some((i) => i._zod.optout === "optional") ? "optional" : void 0), x(t._zod, "values", () => {
556
597
  if (e.options.every((i) => i._zod.values))
557
598
  return new Set(e.options.flatMap((i) => Array.from(i._zod.values)));
558
- }), R(t._zod, "pattern", () => {
599
+ }), x(t._zod, "pattern", () => {
559
600
  if (e.options.every((i) => i._zod.pattern)) {
560
601
  const i = e.options.map((r) => r._zod.pattern);
561
- return new RegExp(`^(${i.map((r) => at(r.source)).join("|")})$`);
602
+ return new RegExp(`^(${i.map((r) => ut(r.source)).join("|")})$`);
562
603
  }
563
604
  });
564
605
  const n = e.options.length === 1, s = e.options[0]._zod.run;
@@ -566,64 +607,64 @@ const gt = /* @__PURE__ */ w("$ZodUnion", (t, e) => {
566
607
  if (n)
567
608
  return s(i, r);
568
609
  let o = !1;
569
- const a = [];
570
- for (const c of e.options) {
571
- const u = c._zod.run({
610
+ const c = [];
611
+ for (const a of e.options) {
612
+ const u = a._zod.run({
572
613
  value: i.value,
573
614
  issues: []
574
615
  }, r);
575
616
  if (u instanceof Promise)
576
- a.push(u), o = !0;
617
+ c.push(u), o = !0;
577
618
  else {
578
619
  if (u.issues.length === 0)
579
620
  return u;
580
- a.push(u);
621
+ c.push(u);
581
622
  }
582
623
  }
583
- return o ? Promise.all(a).then((c) => Fe(c, i, t, r)) : Fe(a, i, t, r);
624
+ return o ? Promise.all(c).then((a) => Ve(a, i, t, r)) : Ve(c, i, t, r);
584
625
  };
585
- }), zn = /* @__PURE__ */ w("$ZodDiscriminatedUnion", (t, e) => {
586
- e.inclusive = !1, gt.init(t, e);
626
+ }), Rn = /* @__PURE__ */ g("$ZodDiscriminatedUnion", (t, e) => {
627
+ e.inclusive = !1, vt.init(t, e);
587
628
  const n = t._zod.parse;
588
- R(t._zod, "propValues", () => {
629
+ x(t._zod, "propValues", () => {
589
630
  const i = {};
590
631
  for (const r of e.options) {
591
632
  const o = r._zod.propValues;
592
633
  if (!o || Object.keys(o).length === 0)
593
634
  throw new Error(`Invalid discriminated union option at index "${e.options.indexOf(r)}"`);
594
- for (const [a, c] of Object.entries(o)) {
595
- i[a] || (i[a] = /* @__PURE__ */ new Set());
596
- for (const u of c)
597
- i[a].add(u);
635
+ for (const [c, a] of Object.entries(o)) {
636
+ i[c] || (i[c] = /* @__PURE__ */ new Set());
637
+ for (const u of a)
638
+ i[c].add(u);
598
639
  }
599
640
  }
600
641
  return i;
601
642
  });
602
- const s = ot(() => {
643
+ const s = ct(() => {
603
644
  const i = e.options, r = /* @__PURE__ */ new Map();
604
645
  for (const o of i) {
605
- const a = o._zod.propValues?.[e.discriminator];
606
- if (!a || a.size === 0)
646
+ const c = o._zod.propValues?.[e.discriminator];
647
+ if (!c || c.size === 0)
607
648
  throw new Error(`Invalid discriminated union option at index "${e.options.indexOf(o)}"`);
608
- for (const c of a) {
609
- if (r.has(c))
610
- throw new Error(`Duplicate discriminator value "${String(c)}"`);
611
- r.set(c, o);
649
+ for (const a of c) {
650
+ if (r.has(a))
651
+ throw new Error(`Duplicate discriminator value "${String(a)}"`);
652
+ r.set(a, o);
612
653
  }
613
654
  }
614
655
  return r;
615
656
  });
616
657
  t._zod.parse = (i, r) => {
617
658
  const o = i.value;
618
- if (!ge(o))
659
+ if (!we(o))
619
660
  return i.issues.push({
620
661
  code: "invalid_type",
621
662
  expected: "object",
622
663
  input: o,
623
664
  inst: t
624
665
  }), i;
625
- const a = s.value.get(o?.[e.discriminator]);
626
- return a ? a._zod.run(i, r) : e.unionFallback ? n(i, r) : (i.issues.push({
666
+ const c = s.value.get(o?.[e.discriminator]);
667
+ return c ? c._zod.run(i, r) : e.unionFallback ? n(i, r) : (i.issues.push({
627
668
  code: "invalid_union",
628
669
  errors: [],
629
670
  note: "No matching discriminator",
@@ -633,10 +674,10 @@ const gt = /* @__PURE__ */ w("$ZodUnion", (t, e) => {
633
674
  inst: t
634
675
  }), i);
635
676
  };
636
- }), kn = /* @__PURE__ */ w("$ZodRecord", (t, e) => {
677
+ }), Cn = /* @__PURE__ */ g("$ZodRecord", (t, e) => {
637
678
  C.init(t, e), t._zod.parse = (n, s) => {
638
679
  const i = n.value;
639
- if (!ut(i))
680
+ if (!dt(i))
640
681
  return n.issues.push({
641
682
  expected: "record",
642
683
  code: "invalid_type",
@@ -646,61 +687,61 @@ const gt = /* @__PURE__ */ w("$ZodUnion", (t, e) => {
646
687
  const r = [], o = e.keyType._zod.values;
647
688
  if (o) {
648
689
  n.value = {};
649
- const a = /* @__PURE__ */ new Set();
690
+ const c = /* @__PURE__ */ new Set();
650
691
  for (const u of o)
651
692
  if (typeof u == "string" || typeof u == "number" || typeof u == "symbol") {
652
- a.add(typeof u == "number" ? u.toString() : u);
693
+ c.add(typeof u == "number" ? u.toString() : u);
653
694
  const l = e.valueType._zod.run({ value: i[u], issues: [] }, s);
654
695
  l instanceof Promise ? r.push(l.then((d) => {
655
696
  d.issues.length && n.issues.push(...J(u, d.issues)), n.value[u] = d.value;
656
697
  })) : (l.issues.length && n.issues.push(...J(u, l.issues)), n.value[u] = l.value);
657
698
  }
658
- let c;
699
+ let a;
659
700
  for (const u in i)
660
- a.has(u) || (c = c ?? [], c.push(u));
661
- c && c.length > 0 && n.issues.push({
701
+ c.has(u) || (a = a ?? [], a.push(u));
702
+ a && a.length > 0 && n.issues.push({
662
703
  code: "unrecognized_keys",
663
704
  input: i,
664
705
  inst: t,
665
- keys: c
706
+ keys: a
666
707
  });
667
708
  } else {
668
709
  n.value = {};
669
- for (const a of Reflect.ownKeys(i)) {
670
- if (a === "__proto__")
710
+ for (const c of Reflect.ownKeys(i)) {
711
+ if (c === "__proto__")
671
712
  continue;
672
- let c = e.keyType._zod.run({ value: a, issues: [] }, s);
673
- if (c instanceof Promise)
713
+ let a = e.keyType._zod.run({ value: c, issues: [] }, s);
714
+ if (a instanceof Promise)
674
715
  throw new Error("Async schemas not supported in object keys currently");
675
- if (typeof a == "string" && ft.test(a) && c.issues.length) {
676
- const d = e.keyType._zod.run({ value: Number(a), issues: [] }, s);
716
+ if (typeof c == "string" && pt.test(c) && a.issues.length) {
717
+ const d = e.keyType._zod.run({ value: Number(c), issues: [] }, s);
677
718
  if (d instanceof Promise)
678
719
  throw new Error("Async schemas not supported in object keys currently");
679
- d.issues.length === 0 && (c = d);
720
+ d.issues.length === 0 && (a = d);
680
721
  }
681
- if (c.issues.length) {
682
- e.mode === "loose" ? n.value[a] = i[a] : n.issues.push({
722
+ if (a.issues.length) {
723
+ e.mode === "loose" ? n.value[c] = i[c] : n.issues.push({
683
724
  code: "invalid_key",
684
725
  origin: "record",
685
- issues: c.issues.map((d) => se(d, s, ne())),
686
- input: a,
687
- path: [a],
726
+ issues: a.issues.map((d) => ie(d, s, se())),
727
+ input: c,
728
+ path: [c],
688
729
  inst: t
689
730
  });
690
731
  continue;
691
732
  }
692
- const l = e.valueType._zod.run({ value: i[a], issues: [] }, s);
733
+ const l = e.valueType._zod.run({ value: i[c], issues: [] }, s);
693
734
  l instanceof Promise ? r.push(l.then((d) => {
694
- d.issues.length && n.issues.push(...J(a, d.issues)), n.value[c.value] = d.value;
695
- })) : (l.issues.length && n.issues.push(...J(a, l.issues)), n.value[c.value] = l.value);
735
+ d.issues.length && n.issues.push(...J(c, d.issues)), n.value[a.value] = d.value;
736
+ })) : (l.issues.length && n.issues.push(...J(c, l.issues)), n.value[a.value] = l.value);
696
737
  }
697
738
  }
698
739
  return r.length ? Promise.all(r).then(() => n) : n;
699
740
  };
700
- }), Tn = /* @__PURE__ */ w("$ZodEnum", (t, e) => {
741
+ }), In = /* @__PURE__ */ g("$ZodEnum", (t, e) => {
701
742
  C.init(t, e);
702
- const n = Yt(e.entries), s = new Set(n);
703
- t._zod.values = s, t._zod.pattern = new RegExp(`^(${n.filter((i) => Qt.has(typeof i)).map((i) => typeof i == "string" ? ke(i) : i.toString()).join("|")})$`), t._zod.parse = (i, r) => {
743
+ const n = en(e.entries), s = new Set(n);
744
+ t._zod.values = s, t._zod.pattern = new RegExp(`^(${n.filter((i) => sn.has(typeof i)).map((i) => typeof i == "string" ? Be(i) : i.toString()).join("|")})$`), t._zod.parse = (i, r) => {
704
745
  const o = i.value;
705
746
  return s.has(o) || i.issues.push({
706
747
  code: "invalid_value",
@@ -709,11 +750,11 @@ const gt = /* @__PURE__ */ w("$ZodUnion", (t, e) => {
709
750
  inst: t
710
751
  }), i;
711
752
  };
712
- }), Un = /* @__PURE__ */ w("$ZodLiteral", (t, e) => {
753
+ }), Dn = /* @__PURE__ */ g("$ZodLiteral", (t, e) => {
713
754
  if (C.init(t, e), e.values.length === 0)
714
755
  throw new Error("Cannot create literal schema with no valid values");
715
756
  const n = new Set(e.values);
716
- t._zod.values = n, t._zod.pattern = new RegExp(`^(${e.values.map((s) => typeof s == "string" ? ke(s) : s ? ke(s.toString()) : String(s)).join("|")})$`), t._zod.parse = (s, i) => {
757
+ t._zod.values = n, t._zod.pattern = new RegExp(`^(${e.values.map((s) => typeof s == "string" ? Be(s) : s ? Be(s.toString()) : String(s)).join("|")})$`), t._zod.parse = (s, i) => {
717
758
  const r = s.value;
718
759
  return n.has(r) || s.issues.push({
719
760
  code: "invalid_value",
@@ -722,10 +763,10 @@ const gt = /* @__PURE__ */ w("$ZodUnion", (t, e) => {
722
763
  inst: t
723
764
  }), s;
724
765
  };
725
- }), En = /* @__PURE__ */ w("$ZodTransform", (t, e) => {
766
+ }), On = /* @__PURE__ */ g("$ZodTransform", (t, e) => {
726
767
  C.init(t, e), t._zod.parse = (n, s) => {
727
768
  if (s.direction === "backward")
728
- throw new Gt(t.constructor.name);
769
+ throw new Jt(t.constructor.name);
729
770
  const i = e.transform(n.value, n);
730
771
  if (s.async)
731
772
  return (i instanceof Promise ? i : Promise.resolve(i)).then((o) => (n.value = o, n));
@@ -734,48 +775,48 @@ const gt = /* @__PURE__ */ w("$ZodUnion", (t, e) => {
734
775
  return n.value = i, n;
735
776
  };
736
777
  });
737
- function $e(t, e) {
778
+ function We(t, e) {
738
779
  return t.issues.length && e === void 0 ? { issues: [], value: void 0 } : t;
739
780
  }
740
- const xn = /* @__PURE__ */ w("$ZodOptional", (t, e) => {
741
- C.init(t, e), t._zod.optin = "optional", t._zod.optout = "optional", R(t._zod, "values", () => e.innerType._zod.values ? /* @__PURE__ */ new Set([...e.innerType._zod.values, void 0]) : void 0), R(t._zod, "pattern", () => {
781
+ const Ln = /* @__PURE__ */ g("$ZodOptional", (t, e) => {
782
+ C.init(t, e), t._zod.optin = "optional", t._zod.optout = "optional", x(t._zod, "values", () => e.innerType._zod.values ? /* @__PURE__ */ new Set([...e.innerType._zod.values, void 0]) : void 0), x(t._zod, "pattern", () => {
742
783
  const n = e.innerType._zod.pattern;
743
- return n ? new RegExp(`^(${at(n.source)})?$`) : void 0;
784
+ return n ? new RegExp(`^(${ut(n.source)})?$`) : void 0;
744
785
  }), t._zod.parse = (n, s) => {
745
786
  if (e.innerType._zod.optin === "optional") {
746
787
  const i = e.innerType._zod.run(n, s);
747
- return i instanceof Promise ? i.then((r) => $e(r, n.value)) : $e(i, n.value);
788
+ return i instanceof Promise ? i.then((r) => We(r, n.value)) : We(i, n.value);
748
789
  }
749
790
  return n.value === void 0 ? n : e.innerType._zod.run(n, s);
750
791
  };
751
- }), Rn = /* @__PURE__ */ w("$ZodDefault", (t, e) => {
752
- C.init(t, e), t._zod.optin = "optional", R(t._zod, "values", () => e.innerType._zod.values), t._zod.parse = (n, s) => {
792
+ }), Fn = /* @__PURE__ */ g("$ZodDefault", (t, e) => {
793
+ C.init(t, e), t._zod.optin = "optional", x(t._zod, "values", () => e.innerType._zod.values), t._zod.parse = (n, s) => {
753
794
  if (s.direction === "backward")
754
795
  return e.innerType._zod.run(n, s);
755
796
  if (n.value === void 0)
756
797
  return n.value = e.defaultValue, n;
757
798
  const i = e.innerType._zod.run(n, s);
758
- return i instanceof Promise ? i.then((r) => je(r, e)) : je(i, e);
799
+ return i instanceof Promise ? i.then((r) => qe(r, e)) : qe(i, e);
759
800
  };
760
801
  });
761
- function je(t, e) {
802
+ function qe(t, e) {
762
803
  return t.value === void 0 && (t.value = e.defaultValue), t;
763
804
  }
764
- const Bn = /* @__PURE__ */ w("$ZodPipe", (t, e) => {
765
- C.init(t, e), R(t._zod, "values", () => e.in._zod.values), R(t._zod, "optin", () => e.in._zod.optin), R(t._zod, "optout", () => e.out._zod.optout), R(t._zod, "propValues", () => e.in._zod.propValues), t._zod.parse = (n, s) => {
805
+ const Nn = /* @__PURE__ */ g("$ZodPipe", (t, e) => {
806
+ C.init(t, e), x(t._zod, "values", () => e.in._zod.values), x(t._zod, "optin", () => e.in._zod.optin), x(t._zod, "optout", () => e.out._zod.optout), x(t._zod, "propValues", () => e.in._zod.propValues), t._zod.parse = (n, s) => {
766
807
  if (s.direction === "backward") {
767
808
  const r = e.out._zod.run(n, s);
768
- return r instanceof Promise ? r.then((o) => pe(o, e.in, s)) : pe(r, e.in, s);
809
+ return r instanceof Promise ? r.then((o) => ge(o, e.in, s)) : ge(r, e.in, s);
769
810
  }
770
811
  const i = e.in._zod.run(n, s);
771
- return i instanceof Promise ? i.then((r) => pe(r, e.out, s)) : pe(i, e.out, s);
812
+ return i instanceof Promise ? i.then((r) => ge(r, e.out, s)) : ge(i, e.out, s);
772
813
  };
773
814
  });
774
- function pe(t, e, n) {
815
+ function ge(t, e, n) {
775
816
  return t.issues.length ? (t.aborted = !0, t) : e._zod.run({ value: t.value, issues: t.issues }, n);
776
817
  }
777
- var Ze;
778
- class Cn {
818
+ var He;
819
+ class Pn {
779
820
  constructor() {
780
821
  this._map = /* @__PURE__ */ new WeakMap(), this._idmap = /* @__PURE__ */ new Map();
781
822
  }
@@ -804,332 +845,350 @@ class Cn {
804
845
  return this._map.has(e);
805
846
  }
806
847
  }
807
- function In() {
808
- return new Cn();
848
+ function $n() {
849
+ return new Pn();
809
850
  }
810
- (Ze = globalThis).__zod_globalRegistry ?? (Ze.__zod_globalRegistry = In());
851
+ (He = globalThis).__zod_globalRegistry ?? (He.__zod_globalRegistry = $n());
811
852
  // @__NO_SIDE_EFFECTS__
812
- function On(t, e) {
853
+ function jn(t, e) {
813
854
  return new t({
814
855
  type: "string",
815
- ...O()
856
+ ...R()
816
857
  });
817
858
  }
818
859
  // @__NO_SIDE_EFFECTS__
819
- function Dn(t, e) {
860
+ function Zn(t, e) {
861
+ return new t({
862
+ type: "string",
863
+ format: "base64",
864
+ check: "string_format",
865
+ abort: !1,
866
+ ...R()
867
+ });
868
+ }
869
+ // @__NO_SIDE_EFFECTS__
870
+ function Vn(t, e) {
820
871
  return new t({
821
872
  type: "number",
822
873
  checks: [],
823
- ...O()
874
+ ...R()
824
875
  });
825
876
  }
826
877
  // @__NO_SIDE_EFFECTS__
827
- function Ln(t, e) {
878
+ function Wn(t, e) {
828
879
  return new t({
829
880
  type: "number",
830
881
  check: "number_format",
831
882
  abort: !1,
832
883
  format: "safeint",
833
- ...O()
884
+ ...R()
834
885
  });
835
886
  }
836
887
  // @__NO_SIDE_EFFECTS__
837
- function Pn(t, e) {
888
+ function qn(t, e) {
838
889
  return new t({
839
890
  type: "boolean",
840
- ...O()
891
+ ...R()
841
892
  });
842
893
  }
843
894
  // @__NO_SIDE_EFFECTS__
844
- function wt(t, e) {
845
- return new mn({
895
+ function St(t, e) {
896
+ return new bn({
846
897
  check: "less_than",
847
- ...O(),
898
+ ...R(),
848
899
  value: t,
849
900
  inclusive: !0
850
901
  });
851
902
  }
852
903
  // @__NO_SIDE_EFFECTS__
853
- function Nn(t, e) {
854
- return new pn({
904
+ function Hn(t, e) {
905
+ return new vn({
855
906
  check: "greater_than",
856
- ...O(),
907
+ ...R(),
857
908
  value: t,
858
909
  inclusive: !0
859
910
  });
860
911
  }
861
912
  // @__NO_SIDE_EFFECTS__
862
- function yt(t) {
863
- return /* @__PURE__ */ Nn(0);
913
+ function At(t) {
914
+ return /* @__PURE__ */ Hn(0);
864
915
  }
865
- const I = /* @__PURE__ */ w("ZodMiniType", (t, e) => {
916
+ const I = /* @__PURE__ */ g("ZodMiniType", (t, e) => {
866
917
  if (!t._zod)
867
918
  throw new Error("Uninitialized schema in ZodMiniType.");
868
- C.init(t, e), t.def = e, t.type = e.type, t.parse = (n, s) => on(t, n, s, { callee: t.parse }), t.safeParse = (n, s) => dt(t, n, s), t.parseAsync = async (n, s) => cn(t, n, s, { callee: t.parseAsync }), t.safeParseAsync = async (n, s) => ht(t, n, s), t.check = (...n) => t.clone({
919
+ C.init(t, e), t.def = e, t.type = e.type, t.parse = (n, s) => ln(t, n, s, { callee: t.parse }), t.safeParse = (n, s) => ft(t, n, s), t.parseAsync = async (n, s) => hn(t, n, s, { callee: t.parseAsync }), t.safeParseAsync = async (n, s) => mt(t, n, s), t.check = (...n) => t.clone({
869
920
  ...e,
870
921
  checks: [
871
922
  ...e.checks ?? [],
872
923
  ...n.map((s) => typeof s == "function" ? { _zod: { check: s, def: { check: "custom" }, onattach: [] } } : s)
873
924
  ]
874
- }, { parent: !0 }), t.with = t.check, t.clone = (n, s) => en(t, n, s), t.brand = () => t, t.register = ((n, s) => (n.add(t, s), t)), t.apply = (n) => n(t);
875
- }), Fn = /* @__PURE__ */ w("ZodMiniString", (t, e) => {
876
- yn.init(t, e), I.init(t, e);
925
+ }, { parent: !0 }), t.with = t.check, t.clone = (n, s) => rn(t, n, s), t.brand = () => t, t.register = ((n, s) => (n.add(t, s), t)), t.apply = (n) => n(t);
926
+ }), _t = /* @__PURE__ */ g("ZodMiniString", (t, e) => {
927
+ wt.init(t, e), I.init(t, e);
877
928
  });
878
929
  // @__NO_SIDE_EFFECTS__
879
- function b(t) {
880
- return /* @__PURE__ */ On(Fn);
930
+ function v(t) {
931
+ return /* @__PURE__ */ jn(_t);
881
932
  }
882
- const vt = /* @__PURE__ */ w("ZodMiniNumber", (t, e) => {
883
- pt.init(t, e), I.init(t, e);
933
+ const Gn = /* @__PURE__ */ g("ZodMiniStringFormat", (t, e) => {
934
+ yt.init(t, e), _t.init(t, e);
935
+ }), Xn = /* @__PURE__ */ g("ZodMiniBase64", (t, e) => {
936
+ Mn.init(t, e), Gn.init(t, e);
884
937
  });
885
938
  // @__NO_SIDE_EFFECTS__
886
- function T(t) {
887
- return /* @__PURE__ */ Dn(vt);
939
+ function Yn(t) {
940
+ return /* @__PURE__ */ Zn(Xn);
888
941
  }
889
- const $n = /* @__PURE__ */ w("ZodMiniNumberFormat", (t, e) => {
890
- vn.init(t, e), vt.init(t, e);
942
+ const zt = /* @__PURE__ */ g("ZodMiniNumber", (t, e) => {
943
+ bt.init(t, e), I.init(t, e);
891
944
  });
892
945
  // @__NO_SIDE_EFFECTS__
893
- function bt(t) {
894
- return /* @__PURE__ */ Ln($n);
946
+ function U(t) {
947
+ return /* @__PURE__ */ Vn(zt);
895
948
  }
896
- const jn = /* @__PURE__ */ w("ZodMiniBoolean", (t, e) => {
897
- bn.init(t, e), I.init(t, e);
949
+ const Kn = /* @__PURE__ */ g("ZodMiniNumberFormat", (t, e) => {
950
+ kn.init(t, e), zt.init(t, e);
898
951
  });
899
952
  // @__NO_SIDE_EFFECTS__
900
- function Ee(t) {
901
- return /* @__PURE__ */ Pn(jn);
953
+ function Mt(t) {
954
+ return /* @__PURE__ */ Wn(Kn);
902
955
  }
903
- const Zn = /* @__PURE__ */ w("ZodMiniArray", (t, e) => {
904
- Sn.init(t, e), I.init(t, e);
956
+ const Jn = /* @__PURE__ */ g("ZodMiniBoolean", (t, e) => {
957
+ Tn.init(t, e), I.init(t, e);
905
958
  });
906
959
  // @__NO_SIDE_EFFECTS__
907
- function G(t, e) {
908
- return new Zn({
960
+ function Ce(t) {
961
+ return /* @__PURE__ */ qn(Jn);
962
+ }
963
+ const Qn = /* @__PURE__ */ g("ZodMiniArray", (t, e) => {
964
+ Un.init(t, e), I.init(t, e);
965
+ });
966
+ // @__NO_SIDE_EFFECTS__
967
+ function q(t, e) {
968
+ return new Qn({
909
969
  type: "array",
910
970
  element: t,
911
- ...O()
971
+ ...R()
912
972
  });
913
973
  }
914
- const Vn = /* @__PURE__ */ w("ZodMiniObject", (t, e) => {
915
- Mn.init(t, e), I.init(t, e), R(t, "shape", () => e.shape);
974
+ const es = /* @__PURE__ */ g("ZodMiniObject", (t, e) => {
975
+ Bn.init(t, e), I.init(t, e), x(t, "shape", () => e.shape);
916
976
  });
917
977
  // @__NO_SIDE_EFFECTS__
918
978
  function S(t, e) {
919
979
  const n = {
920
980
  type: "object",
921
981
  shape: t ?? {},
922
- ...O()
982
+ ...R()
923
983
  };
924
- return new Vn(n);
984
+ return new es(n);
925
985
  }
926
- const Wn = /* @__PURE__ */ w("ZodMiniUnion", (t, e) => {
927
- gt.init(t, e), I.init(t, e);
986
+ const ts = /* @__PURE__ */ g("ZodMiniUnion", (t, e) => {
987
+ vt.init(t, e), I.init(t, e);
928
988
  });
929
989
  // @__NO_SIDE_EFFECTS__
930
- function be(t, e) {
931
- return new Wn({
990
+ function _e(t, e) {
991
+ return new ts({
932
992
  type: "union",
933
993
  options: t,
934
- ...O()
994
+ ...R()
935
995
  });
936
996
  }
937
- const qn = /* @__PURE__ */ w("ZodMiniDiscriminatedUnion", (t, e) => {
938
- zn.init(t, e), I.init(t, e);
997
+ const ns = /* @__PURE__ */ g("ZodMiniDiscriminatedUnion", (t, e) => {
998
+ Rn.init(t, e), I.init(t, e);
939
999
  });
940
1000
  // @__NO_SIDE_EFFECTS__
941
- function Hn(t, e, n) {
942
- return new qn({
1001
+ function ss(t, e, n) {
1002
+ return new ns({
943
1003
  type: "union",
944
1004
  options: e,
945
1005
  discriminator: t,
946
- ...O()
1006
+ ...R()
947
1007
  });
948
1008
  }
949
- const Gn = /* @__PURE__ */ w("ZodMiniRecord", (t, e) => {
950
- kn.init(t, e), I.init(t, e);
1009
+ const is = /* @__PURE__ */ g("ZodMiniRecord", (t, e) => {
1010
+ Cn.init(t, e), I.init(t, e);
951
1011
  });
952
1012
  // @__NO_SIDE_EFFECTS__
953
- function xe(t, e, n) {
954
- return new Gn({
1013
+ function Ie(t, e, n) {
1014
+ return new is({
955
1015
  type: "record",
956
1016
  keyType: t,
957
1017
  valueType: e,
958
- ...O()
1018
+ ...R()
959
1019
  });
960
1020
  }
961
- const Xn = /* @__PURE__ */ w("ZodMiniEnum", (t, e) => {
962
- Tn.init(t, e), I.init(t, e), t.options = Object.values(e.entries);
1021
+ const rs = /* @__PURE__ */ g("ZodMiniEnum", (t, e) => {
1022
+ In.init(t, e), I.init(t, e), t.options = Object.values(e.entries);
963
1023
  });
964
1024
  // @__NO_SIDE_EFFECTS__
965
- function St(t, e) {
1025
+ function kt(t, e) {
966
1026
  const n = Array.isArray(t) ? Object.fromEntries(t.map((s) => [s, s])) : t;
967
- return new Xn({
1027
+ return new rs({
968
1028
  type: "enum",
969
1029
  entries: n,
970
- ...O()
1030
+ ...R()
971
1031
  });
972
1032
  }
973
- const Yn = /* @__PURE__ */ w("ZodMiniLiteral", (t, e) => {
974
- Un.init(t, e), I.init(t, e);
1033
+ const os = /* @__PURE__ */ g("ZodMiniLiteral", (t, e) => {
1034
+ Dn.init(t, e), I.init(t, e);
975
1035
  });
976
1036
  // @__NO_SIDE_EFFECTS__
977
- function Te(t, e) {
978
- return new Yn({
1037
+ function Re(t, e) {
1038
+ return new os({
979
1039
  type: "literal",
980
1040
  values: Array.isArray(t) ? t : [t],
981
- ...O()
1041
+ ...R()
982
1042
  });
983
1043
  }
984
- const Kn = /* @__PURE__ */ w("ZodMiniTransform", (t, e) => {
985
- En.init(t, e), I.init(t, e);
1044
+ const as = /* @__PURE__ */ g("ZodMiniTransform", (t, e) => {
1045
+ On.init(t, e), I.init(t, e);
986
1046
  });
987
1047
  // @__NO_SIDE_EFFECTS__
988
- function At(t) {
989
- return new Kn({
1048
+ function Tt(t) {
1049
+ return new as({
990
1050
  type: "transform",
991
1051
  transform: t
992
1052
  });
993
1053
  }
994
- const Jn = /* @__PURE__ */ w("ZodMiniOptional", (t, e) => {
995
- xn.init(t, e), I.init(t, e);
1054
+ const cs = /* @__PURE__ */ g("ZodMiniOptional", (t, e) => {
1055
+ Ln.init(t, e), I.init(t, e);
996
1056
  });
997
1057
  // @__NO_SIDE_EFFECTS__
998
1058
  function m(t) {
999
- return new Jn({
1059
+ return new cs({
1000
1060
  type: "optional",
1001
1061
  innerType: t
1002
1062
  });
1003
1063
  }
1004
- const Qn = /* @__PURE__ */ w("ZodMiniDefault", (t, e) => {
1005
- Rn.init(t, e), I.init(t, e);
1064
+ const us = /* @__PURE__ */ g("ZodMiniDefault", (t, e) => {
1065
+ Fn.init(t, e), I.init(t, e);
1006
1066
  });
1007
1067
  // @__NO_SIDE_EFFECTS__
1008
- function es(t, e) {
1009
- return new Qn({
1068
+ function ls(t, e) {
1069
+ return new us({
1010
1070
  type: "default",
1011
1071
  innerType: t,
1012
1072
  get defaultValue() {
1013
- return typeof e == "function" ? e() : Jt(e);
1073
+ return typeof e == "function" ? e() : nn(e);
1014
1074
  }
1015
1075
  });
1016
1076
  }
1017
- const ts = /* @__PURE__ */ w("ZodMiniPipe", (t, e) => {
1018
- Bn.init(t, e), I.init(t, e);
1077
+ const ds = /* @__PURE__ */ g("ZodMiniPipe", (t, e) => {
1078
+ Nn.init(t, e), I.init(t, e);
1019
1079
  });
1020
1080
  // @__NO_SIDE_EFFECTS__
1021
- function _t(t, e) {
1022
- return new ts({
1081
+ function Ut(t, e) {
1082
+ return new ds({
1023
1083
  type: "pipe",
1024
1084
  in: t,
1025
1085
  out: e
1026
1086
  });
1027
1087
  }
1028
- (/* @__PURE__ */ T()).check(/* @__PURE__ */ bt(), /* @__PURE__ */ yt(), /* @__PURE__ */ wt(255)).brand("u8");
1029
- const x = (/* @__PURE__ */ T()).check(/* @__PURE__ */ bt(), /* @__PURE__ */ yt(), /* @__PURE__ */ wt(Number.MAX_SAFE_INTEGER)).brand("u53");
1030
- function L(t) {
1031
- return x.parse(t);
1032
- }
1033
- const Mt = /* @__PURE__ */ es(
1034
- /* @__PURE__ */ Hn("kind", [
1088
+ const Et = /* @__PURE__ */ ls(
1089
+ /* @__PURE__ */ ss("kind", [
1035
1090
  // The default hang container
1036
- /* @__PURE__ */ S({ kind: /* @__PURE__ */ Te("legacy") }),
1037
- // CMAF container with timescale for timestamp conversion
1091
+ /* @__PURE__ */ S({ kind: /* @__PURE__ */ Re("legacy") }),
1092
+ // CMAF container with base64-encoded init segment (ftyp+moov)
1038
1093
  /* @__PURE__ */ S({
1039
- kind: /* @__PURE__ */ Te("cmaf"),
1040
- // Time units per second
1041
- timescale: x,
1042
- // Track ID used in the moof/mdat fragments
1043
- trackId: x
1094
+ kind: /* @__PURE__ */ Re("cmaf"),
1095
+ // Base64-encoded init segment (ftyp+moov)
1096
+ init: /* @__PURE__ */ Yn()
1044
1097
  })
1045
1098
  ]),
1046
1099
  { kind: "legacy" }
1047
- ), ns = /* @__PURE__ */ S({
1048
- name: /* @__PURE__ */ b()
1049
- }), Ve = /* @__PURE__ */ S({
1100
+ );
1101
+ (/* @__PURE__ */ U()).check(/* @__PURE__ */ Mt(), /* @__PURE__ */ At(), /* @__PURE__ */ St(255)).brand("u8");
1102
+ const D = (/* @__PURE__ */ U()).check(/* @__PURE__ */ Mt(), /* @__PURE__ */ At(), /* @__PURE__ */ St(Number.MAX_SAFE_INTEGER)).brand("u53");
1103
+ function V(t) {
1104
+ return D.parse(t);
1105
+ }
1106
+ const hs = /* @__PURE__ */ S({
1107
+ name: /* @__PURE__ */ v()
1108
+ }), Ge = /* @__PURE__ */ S({
1050
1109
  // See: https://w3c.github.io/webcodecs/codec_registry.html
1051
- codec: /* @__PURE__ */ b(),
1110
+ codec: /* @__PURE__ */ v(),
1052
1111
  // The container format, used to decode the timestamp and more.
1053
- container: Mt,
1112
+ container: Et,
1054
1113
  // The description is used for some codecs.
1055
1114
  // If provided, we can initialize the decoder based on the catalog alone.
1056
1115
  // Otherwise, the initialization information is in-band.
1057
- description: /* @__PURE__ */ m(/* @__PURE__ */ b()),
1116
+ description: /* @__PURE__ */ m(/* @__PURE__ */ v()),
1058
1117
  // hex encoded TODO use base64
1059
1118
  // The sample rate of the audio in Hz
1060
- sampleRate: x,
1119
+ sampleRate: D,
1061
1120
  // The number of channels in the audio
1062
- numberOfChannels: x,
1121
+ numberOfChannels: D,
1063
1122
  // The bitrate of the audio in bits per second
1064
1123
  // TODO: Support up to Number.MAX_SAFE_INTEGER
1065
- bitrate: /* @__PURE__ */ m(x),
1124
+ bitrate: /* @__PURE__ */ m(D),
1066
1125
  // The maximum jitter before the next frame is emitted in milliseconds.
1067
1126
  // The player's jitter buffer should be larger than this value.
1068
1127
  // If not provided, the player should assume each frame is flushed immediately.
1069
1128
  //
1070
1129
  // NOTE: The audio "frame" duration depends on the codec, sample rate, etc.
1071
1130
  // ex: AAC often uses 1024 samples per frame, so at 44100Hz, this would be 1024/44100 = 23ms
1072
- jitter: /* @__PURE__ */ m(x)
1073
- }), ss = /* @__PURE__ */ be([
1131
+ jitter: /* @__PURE__ */ m(D)
1132
+ }), fs = /* @__PURE__ */ _e([
1074
1133
  /* @__PURE__ */ S({
1075
1134
  // A map of track name to rendition configuration.
1076
1135
  // This is not an array so it will work with JSON Merge Patch.
1077
- renditions: /* @__PURE__ */ xe(/* @__PURE__ */ b(), Ve)
1136
+ renditions: /* @__PURE__ */ Ie(/* @__PURE__ */ v(), Ge)
1078
1137
  }),
1079
1138
  // Backwards compatibility: transform old {track, config} format to new object format
1080
- /* @__PURE__ */ _t(
1139
+ /* @__PURE__ */ Ut(
1081
1140
  /* @__PURE__ */ S({
1082
- track: ns,
1083
- config: Ve
1141
+ track: hs,
1142
+ config: Ge
1084
1143
  }),
1085
- /* @__PURE__ */ At((t) => ({
1144
+ /* @__PURE__ */ Tt((t) => ({
1086
1145
  renditions: { [t.track.name]: t.config }
1087
1146
  }))
1088
1147
  )
1089
- ]), is = /* @__PURE__ */ S({
1090
- hardware: /* @__PURE__ */ m(/* @__PURE__ */ G(/* @__PURE__ */ b())),
1091
- software: /* @__PURE__ */ m(/* @__PURE__ */ G(/* @__PURE__ */ b())),
1092
- unsupported: /* @__PURE__ */ m(/* @__PURE__ */ G(/* @__PURE__ */ b()))
1093
- }), rs = /* @__PURE__ */ S({
1094
- hardware: /* @__PURE__ */ m(/* @__PURE__ */ G(/* @__PURE__ */ b())),
1095
- software: /* @__PURE__ */ m(/* @__PURE__ */ G(/* @__PURE__ */ b())),
1096
- unsupported: /* @__PURE__ */ m(/* @__PURE__ */ G(/* @__PURE__ */ b()))
1097
- }), os = /* @__PURE__ */ S({
1098
- video: /* @__PURE__ */ m(is),
1099
- audio: /* @__PURE__ */ m(rs)
1148
+ ]), ms = /* @__PURE__ */ S({
1149
+ hardware: /* @__PURE__ */ m(/* @__PURE__ */ q(/* @__PURE__ */ v())),
1150
+ software: /* @__PURE__ */ m(/* @__PURE__ */ q(/* @__PURE__ */ v())),
1151
+ unsupported: /* @__PURE__ */ m(/* @__PURE__ */ q(/* @__PURE__ */ v()))
1152
+ }), ps = /* @__PURE__ */ S({
1153
+ hardware: /* @__PURE__ */ m(/* @__PURE__ */ q(/* @__PURE__ */ v())),
1154
+ software: /* @__PURE__ */ m(/* @__PURE__ */ q(/* @__PURE__ */ v())),
1155
+ unsupported: /* @__PURE__ */ m(/* @__PURE__ */ q(/* @__PURE__ */ v()))
1156
+ }), gs = /* @__PURE__ */ S({
1157
+ video: /* @__PURE__ */ m(ms),
1158
+ audio: /* @__PURE__ */ m(ps)
1100
1159
  }), de = /* @__PURE__ */ S({
1101
- name: /* @__PURE__ */ b()
1102
- }), as = /* @__PURE__ */ S({
1160
+ name: /* @__PURE__ */ v()
1161
+ }), ws = /* @__PURE__ */ S({
1103
1162
  message: /* @__PURE__ */ m(de),
1104
1163
  typing: /* @__PURE__ */ m(de)
1105
- }), zt = /* @__PURE__ */ S({
1164
+ }), xt = /* @__PURE__ */ S({
1106
1165
  // The relative X position of the broadcast, from -1 to +1.
1107
1166
  // This should be used for audio panning but can also be used for video positioning.
1108
- x: /* @__PURE__ */ m(/* @__PURE__ */ T()),
1167
+ x: /* @__PURE__ */ m(/* @__PURE__ */ U()),
1109
1168
  // The relative Y position of the broadcast, from -1 to +1.
1110
1169
  // This can be used for video positioning, and maybe audio panning.
1111
- y: /* @__PURE__ */ m(/* @__PURE__ */ T()),
1170
+ y: /* @__PURE__ */ m(/* @__PURE__ */ U()),
1112
1171
  // The relative Z index of the broadcast, where larger values are closer to the viewer.
1113
1172
  // This is used to break ties when there are multiple broadcasts at the same position.
1114
- z: /* @__PURE__ */ m(/* @__PURE__ */ T()),
1173
+ z: /* @__PURE__ */ m(/* @__PURE__ */ U()),
1115
1174
  // The scale of the broadcast, where 1 is 100%
1116
- s: /* @__PURE__ */ m(/* @__PURE__ */ T())
1117
- }), cs = /* @__PURE__ */ S({
1175
+ s: /* @__PURE__ */ m(/* @__PURE__ */ U())
1176
+ }), ys = /* @__PURE__ */ S({
1118
1177
  // The initial position of the broadcaster, from -1 to +1 in both dimensions.
1119
1178
  // If not provided, then the broadcaster is assumed to be at (0,0)
1120
1179
  // This should be used for audio panning but can also be used for video positioning.
1121
- initial: /* @__PURE__ */ m(zt),
1180
+ initial: /* @__PURE__ */ m(xt),
1122
1181
  // If provided, then updates to the position are done via a separate Moq track.
1123
1182
  // This is used to avoid a full catalog update every time we want to update a few bytes.
1124
1183
  // TODO: These updates currently use JSON for simplicity, but we should use a binary format.
1125
1184
  track: /* @__PURE__ */ m(de),
1126
1185
  // If set, then this broadcaster allows other peers to request position updates via this handle.
1127
1186
  // We will have to discover and subscribe to their position updates.
1128
- handle: /* @__PURE__ */ m(/* @__PURE__ */ b()),
1187
+ handle: /* @__PURE__ */ m(/* @__PURE__ */ v()),
1129
1188
  // If provided, this broadcaster is signaling the location of other peers.
1130
1189
  // The payload is a JSON blob keyed by handle for each peer.
1131
1190
  peers: /* @__PURE__ */ m(de)
1132
- }), cr = /* @__PURE__ */ xe(/* @__PURE__ */ b(), zt), ee = {
1191
+ }), br = /* @__PURE__ */ Ie(/* @__PURE__ */ v(), xt), ee = {
1133
1192
  catalog: 100,
1134
1193
  chat: 90,
1135
1194
  audio: 80,
@@ -1137,41 +1196,41 @@ const Mt = /* @__PURE__ */ es(
1137
1196
  typing: 40,
1138
1197
  location: 20,
1139
1198
  preview: 10
1140
- }, us = /* @__PURE__ */ S({
1141
- id: /* @__PURE__ */ m(/* @__PURE__ */ b()),
1142
- name: /* @__PURE__ */ m(/* @__PURE__ */ b()),
1143
- avatar: /* @__PURE__ */ m(/* @__PURE__ */ b()),
1199
+ }, bs = /* @__PURE__ */ S({
1200
+ id: /* @__PURE__ */ m(/* @__PURE__ */ v()),
1201
+ name: /* @__PURE__ */ m(/* @__PURE__ */ v()),
1202
+ avatar: /* @__PURE__ */ m(/* @__PURE__ */ v()),
1144
1203
  // TODO allow using a track instead of a URL?
1145
- color: /* @__PURE__ */ m(/* @__PURE__ */ b())
1146
- }), ls = /* @__PURE__ */ S({
1147
- name: /* @__PURE__ */ b()
1148
- }), We = /* @__PURE__ */ S({
1204
+ color: /* @__PURE__ */ m(/* @__PURE__ */ v())
1205
+ }), vs = /* @__PURE__ */ S({
1206
+ name: /* @__PURE__ */ v()
1207
+ }), Xe = /* @__PURE__ */ S({
1149
1208
  // See: https://w3c.github.io/webcodecs/codec_registry.html
1150
- codec: /* @__PURE__ */ b(),
1209
+ codec: /* @__PURE__ */ v(),
1151
1210
  // The container format, used to decode the timestamp and more.
1152
- container: Mt,
1211
+ container: Et,
1153
1212
  // The description is used for some codecs.
1154
1213
  // If provided, we can initialize the decoder based on the catalog alone.
1155
1214
  // Otherwise, the initialization information is (repeated) before each key-frame.
1156
- description: /* @__PURE__ */ m(/* @__PURE__ */ b()),
1215
+ description: /* @__PURE__ */ m(/* @__PURE__ */ v()),
1157
1216
  // hex encoded TODO use base64
1158
1217
  // The width and height of the video in pixels.
1159
1218
  // NOTE: formats that don't use a description can adjust these values in-band.
1160
- codedWidth: /* @__PURE__ */ m(x),
1161
- codedHeight: /* @__PURE__ */ m(x),
1219
+ codedWidth: /* @__PURE__ */ m(D),
1220
+ codedHeight: /* @__PURE__ */ m(D),
1162
1221
  // Ratio of display width/height to coded width/height
1163
1222
  // Allows stretching/squishing individual "pixels" of the video
1164
1223
  // If not provided, the display ratio is 1:1
1165
- displayAspectWidth: /* @__PURE__ */ m(x),
1166
- displayAspectHeight: /* @__PURE__ */ m(x),
1224
+ displayAspectWidth: /* @__PURE__ */ m(D),
1225
+ displayAspectHeight: /* @__PURE__ */ m(D),
1167
1226
  // The frame rate of the video in frames per second
1168
- framerate: /* @__PURE__ */ m(/* @__PURE__ */ T()),
1227
+ framerate: /* @__PURE__ */ m(/* @__PURE__ */ U()),
1169
1228
  // The bitrate of the video in bits per second
1170
1229
  // TODO: Support up to Number.MAX_SAFE_INTEGER
1171
- bitrate: /* @__PURE__ */ m(x),
1230
+ bitrate: /* @__PURE__ */ m(D),
1172
1231
  // If true, the decoder will optimize for latency.
1173
1232
  // Default: true
1174
- optimizeForLatency: /* @__PURE__ */ m(/* @__PURE__ */ Ee()),
1233
+ optimizeForLatency: /* @__PURE__ */ m(/* @__PURE__ */ Ce()),
1175
1234
  // The maximum jitter before the next frame is emitted in milliseconds.
1176
1235
  // The player's jitter buffer should be larger than this value.
1177
1236
  // If not provided, the player should assume each frame is flushed immediately.
@@ -1180,36 +1239,36 @@ const Mt = /* @__PURE__ */ es(
1180
1239
  // - If each frame is flushed immediately, this would be 1000/fps.
1181
1240
  // - If there can be up to 3 b-frames in a row, this would be 3 * 1000/fps.
1182
1241
  // - If frames are buffered into 2s segments, this would be 2s.
1183
- jitter: /* @__PURE__ */ m(x)
1184
- }), ds = /* @__PURE__ */ be([
1242
+ jitter: /* @__PURE__ */ m(D)
1243
+ }), Ss = /* @__PURE__ */ _e([
1185
1244
  /* @__PURE__ */ S({
1186
1245
  // A map of track name to rendition configuration.
1187
1246
  // This is not an array in order for it to work with JSON Merge Patch.
1188
- renditions: /* @__PURE__ */ xe(/* @__PURE__ */ b(), We),
1247
+ renditions: /* @__PURE__ */ Ie(/* @__PURE__ */ v(), Xe),
1189
1248
  // Render the video at this size in pixels.
1190
1249
  // This is separate from the display aspect ratio because it does not require reinitialization.
1191
1250
  display: /* @__PURE__ */ m(
1192
1251
  /* @__PURE__ */ S({
1193
- width: x,
1194
- height: x
1252
+ width: D,
1253
+ height: D
1195
1254
  })
1196
1255
  ),
1197
1256
  // The rotation of the video in degrees.
1198
1257
  // Default: 0
1199
- rotation: /* @__PURE__ */ m(/* @__PURE__ */ T()),
1258
+ rotation: /* @__PURE__ */ m(/* @__PURE__ */ U()),
1200
1259
  // If true, the decoder will flip the video horizontally
1201
1260
  // Default: false
1202
- flip: /* @__PURE__ */ m(/* @__PURE__ */ Ee())
1261
+ flip: /* @__PURE__ */ m(/* @__PURE__ */ Ce())
1203
1262
  }),
1204
1263
  // Backwards compatibility: transform old array of {track, config} to new object format
1205
- /* @__PURE__ */ _t(
1206
- /* @__PURE__ */ G(
1264
+ /* @__PURE__ */ Ut(
1265
+ /* @__PURE__ */ q(
1207
1266
  /* @__PURE__ */ S({
1208
- track: ls,
1209
- config: We
1267
+ track: vs,
1268
+ config: Xe
1210
1269
  })
1211
1270
  ),
1212
- /* @__PURE__ */ At((t) => {
1271
+ /* @__PURE__ */ Tt((t) => {
1213
1272
  const e = t[0]?.config;
1214
1273
  return {
1215
1274
  renditions: Object.fromEntries(t.map((n) => [n.track.name, n.config])),
@@ -1219,79 +1278,79 @@ const Mt = /* @__PURE__ */ es(
1219
1278
  };
1220
1279
  })
1221
1280
  )
1222
- ]), hs = /* @__PURE__ */ S({
1223
- video: /* @__PURE__ */ m(ds),
1224
- audio: /* @__PURE__ */ m(ss),
1225
- location: /* @__PURE__ */ m(cs),
1226
- user: /* @__PURE__ */ m(us),
1227
- chat: /* @__PURE__ */ m(as),
1228
- capabilities: /* @__PURE__ */ m(os),
1281
+ ]), As = /* @__PURE__ */ S({
1282
+ video: /* @__PURE__ */ m(Ss),
1283
+ audio: /* @__PURE__ */ m(fs),
1284
+ location: /* @__PURE__ */ m(ys),
1285
+ user: /* @__PURE__ */ m(bs),
1286
+ chat: /* @__PURE__ */ m(ws),
1287
+ capabilities: /* @__PURE__ */ m(gs),
1229
1288
  preview: /* @__PURE__ */ m(de)
1230
1289
  });
1231
- function fs(t) {
1290
+ function _s(t) {
1232
1291
  const n = new TextDecoder().decode(t);
1233
1292
  try {
1234
1293
  const s = JSON.parse(n);
1235
- return hs.parse(s);
1294
+ return As.parse(s);
1236
1295
  } catch (s) {
1237
1296
  throw console.warn("invalid catalog", n), s;
1238
1297
  }
1239
1298
  }
1240
- async function ms(t) {
1299
+ async function zs(t) {
1241
1300
  const e = await t.readFrame();
1242
1301
  if (e)
1243
- return fs(e);
1302
+ return _s(e);
1244
1303
  }
1245
- function kt(t) {
1304
+ function Bt(t) {
1246
1305
  return t instanceof ArrayBuffer || typeof SharedArrayBuffer < "u" && t instanceof SharedArrayBuffer;
1247
1306
  }
1248
- const ps = "utf-16", Ae = "utf-16be", qe = "utf-16le", ue = "utf-8";
1249
- function Tt(t, e = {}) {
1307
+ const Ms = "utf-16", Te = "utf-16be", Ye = "utf-16le", ue = "utf-8";
1308
+ function Rt(t, e = {}) {
1250
1309
  let n;
1251
- kt(t) ? n = new DataView(t) : n = new DataView(t.buffer, t.byteOffset, t.byteLength);
1310
+ Bt(t) ? n = new DataView(t) : n = new DataView(t.buffer, t.byteOffset, t.byteLength);
1252
1311
  let s = 0, { encoding: i } = e;
1253
1312
  if (!i) {
1254
1313
  const u = n.getUint8(0), l = n.getUint8(1);
1255
- u == 239 && l == 187 && n.getUint8(2) == 191 ? (i = ue, s = 3) : u == 254 && l == 255 ? (i = Ae, s = 2) : u == 255 && l == 254 ? (i = qe, s = 2) : i = ue;
1314
+ u == 239 && l == 187 && n.getUint8(2) == 191 ? (i = ue, s = 3) : u == 254 && l == 255 ? (i = Te, s = 2) : u == 255 && l == 254 ? (i = Ye, s = 2) : i = ue;
1256
1315
  }
1257
1316
  if (typeof TextDecoder < "u") return new TextDecoder(i).decode(n);
1258
- const { byteLength: r } = n, o = i !== Ae;
1259
- let a = "", c;
1317
+ const { byteLength: r } = n, o = i !== Te;
1318
+ let c = "", a;
1260
1319
  for (; s < r; ) {
1261
1320
  switch (i) {
1262
1321
  case ue:
1263
- if (c = n.getUint8(s), c < 128) s++;
1264
- else if (c >= 194 && c <= 223) if (s + 1 < r) {
1322
+ if (a = n.getUint8(s), a < 128) s++;
1323
+ else if (a >= 194 && a <= 223) if (s + 1 < r) {
1265
1324
  const u = n.getUint8(s + 1);
1266
- u >= 128 && u <= 191 ? (c = (c & 31) << 6 | u & 63, s += 2) : s++;
1325
+ u >= 128 && u <= 191 ? (a = (a & 31) << 6 | u & 63, s += 2) : s++;
1267
1326
  } else s++;
1268
- else if (c >= 224 && c <= 239) if (s + 2 <= r - 1) {
1327
+ else if (a >= 224 && a <= 239) if (s + 2 <= r - 1) {
1269
1328
  const u = n.getUint8(s + 1), l = n.getUint8(s + 2);
1270
- u >= 128 && u <= 191 && l >= 128 && l <= 191 ? (c = (c & 15) << 12 | (u & 63) << 6 | l & 63, s += 3) : s++;
1329
+ u >= 128 && u <= 191 && l >= 128 && l <= 191 ? (a = (a & 15) << 12 | (u & 63) << 6 | l & 63, s += 3) : s++;
1271
1330
  } else s++;
1272
- else if (c >= 240 && c <= 244) if (s + 3 <= r - 1) {
1331
+ else if (a >= 240 && a <= 244) if (s + 3 <= r - 1) {
1273
1332
  const u = n.getUint8(s + 1), l = n.getUint8(s + 2), d = n.getUint8(s + 3);
1274
- u >= 128 && u <= 191 && l >= 128 && l <= 191 && d >= 128 && d <= 191 ? (c = (c & 7) << 18 | (u & 63) << 12 | (l & 63) << 6 | d & 63, s += 4) : s++;
1333
+ u >= 128 && u <= 191 && l >= 128 && l <= 191 && d >= 128 && d <= 191 ? (a = (a & 7) << 18 | (u & 63) << 12 | (l & 63) << 6 | d & 63, s += 4) : s++;
1275
1334
  } else s++;
1276
1335
  else s++;
1277
1336
  break;
1278
- case Ae:
1279
- case ps:
1280
- case qe:
1281
- c = n.getUint16(s, o), s += 2;
1337
+ case Te:
1338
+ case Ms:
1339
+ case Ye:
1340
+ a = n.getUint16(s, o), s += 2;
1282
1341
  break;
1283
1342
  }
1284
- a += String.fromCodePoint(c);
1343
+ c += String.fromCodePoint(a);
1285
1344
  }
1286
- return a;
1345
+ return c;
1287
1346
  }
1288
- function gs(t) {
1347
+ function ks(t) {
1289
1348
  return new TextEncoder().encode(t);
1290
1349
  }
1291
- function ws(t) {
1350
+ function Ts(t) {
1292
1351
  return { writers: t?.writers ?? {} };
1293
1352
  }
1294
- const ys = [
1353
+ const Us = [
1295
1354
  "dinf",
1296
1355
  "edts",
1297
1356
  "grpl",
@@ -1312,10 +1371,10 @@ const ys = [
1312
1371
  "udta",
1313
1372
  "vttc"
1314
1373
  ];
1315
- function Ut(t) {
1316
- return "boxes" in t || ys.includes(t.type);
1374
+ function Ct(t) {
1375
+ return "boxes" in t || Us.includes(t.type);
1317
1376
  }
1318
- const He = "utf8", B = "uint", te = "template", Ge = "string", Xe = "int", Ye = "data";
1377
+ const Ke = "utf8", B = "uint", te = "template", Je = "string", Qe = "int", et = "data";
1319
1378
  var k = class {
1320
1379
  /**
1321
1380
  * Constructs a new IsoBoxWriteView.
@@ -1333,16 +1392,16 @@ var k = class {
1333
1392
  i.setUint16(r, n);
1334
1393
  break;
1335
1394
  case 3: {
1336
- const o = (n & 16776960) >> 8, a = n & 255;
1337
- i.setUint16(r, o), i.setUint8(r + 2, a);
1395
+ const o = (n & 16776960) >> 8, c = n & 255;
1396
+ i.setUint16(r, o), i.setUint8(r + 2, c);
1338
1397
  break;
1339
1398
  }
1340
1399
  case 4:
1341
1400
  i.setUint32(r, n);
1342
1401
  break;
1343
1402
  case 8: {
1344
- const o = Math.floor(n / Math.pow(2, 32)), a = n - o * Math.pow(2, 32);
1345
- i.setUint32(r, o), i.setUint32(r + 4, a);
1403
+ const o = Math.floor(n / Math.pow(2, 32)), c = n - o * Math.pow(2, 32);
1404
+ i.setUint32(r, o), i.setUint32(r + 4, c);
1346
1405
  break;
1347
1406
  }
1348
1407
  }
@@ -1360,8 +1419,8 @@ var k = class {
1360
1419
  i.setInt32(r, n);
1361
1420
  break;
1362
1421
  case 8:
1363
- const o = Math.floor(n / Math.pow(2, 32)), a = n - o * Math.pow(2, 32);
1364
- i.setUint32(r, o), i.setUint32(r + 4, a);
1422
+ const o = Math.floor(n / Math.pow(2, 32)), c = n - o * Math.pow(2, 32);
1423
+ i.setUint32(r, o), i.setUint32(r + 4, c);
1365
1424
  break;
1366
1425
  }
1367
1426
  this.cursor += s;
@@ -1373,7 +1432,7 @@ var k = class {
1373
1432
  this.writeUint(0, 1);
1374
1433
  }
1375
1434
  }, this.writeUtf8TerminatedString = (n) => {
1376
- const s = gs(n);
1435
+ const s = ks(n);
1377
1436
  new Uint8Array(this.dataView.buffer).set(s, this.cursor), this.cursor += s.length, this.writeUint(0, 1);
1378
1437
  }, this.writeBytes = (n) => {
1379
1438
  Array.isArray(n) || (n = [n]);
@@ -1381,7 +1440,7 @@ var k = class {
1381
1440
  new Uint8Array(this.dataView.buffer).set(s, this.cursor), this.cursor += s.length;
1382
1441
  }, this.writeArray = (n, s, i, r) => {
1383
1442
  const o = s === B ? this.writeUint : s === te ? this.writeTemplate : this.writeInt;
1384
- for (let a = 0; a < r; a++) o(n[a] ?? 0, i);
1443
+ for (let c = 0; c < r; c++) o(n[c] ?? 0, i);
1385
1444
  }, this.writeTemplate = (n, s) => {
1386
1445
  const r = Math.round(n * Math.pow(2, s === 4 ? 16 : 8));
1387
1446
  this.writeUint(r, s);
@@ -1423,34 +1482,34 @@ var k = class {
1423
1482
  this.writeUint(t, 1), this.writeUint(e, 3);
1424
1483
  }
1425
1484
  };
1426
- function Et(t, e) {
1427
- return Array.from(t, (n) => bs(n, e));
1485
+ function It(t, e) {
1486
+ return Array.from(t, (n) => xs(n, e));
1428
1487
  }
1429
- function Re(t, e) {
1430
- const n = Et(t, e);
1488
+ function De(t, e) {
1489
+ const n = It(t, e);
1431
1490
  return {
1432
1491
  bytes: n,
1433
1492
  size: n.reduce((s, i) => s + i.byteLength, 0)
1434
1493
  };
1435
1494
  }
1436
- function vs(t, e) {
1437
- const { bytes: s, size: i } = Re(t.boxes, e), r = 8 + i, o = new k(t.type, r);
1495
+ function Es(t, e) {
1496
+ const { bytes: s, size: i } = De(t.boxes, e), r = 8 + i, o = new k(t.type, r);
1438
1497
  return o.writeBytes(s), o;
1439
1498
  }
1440
- function bs(t, e) {
1499
+ function xs(t, e) {
1441
1500
  let n = null;
1442
1501
  if ("type" in t) {
1443
1502
  const { type: s } = t, i = e.writers?.[s];
1444
- if (i ? n = i(t, e) : Ut(t) ? n = vs(t, e) : "view" in t && (n = t.view), !n) throw new Error(`No writer found for box type: ${s}`);
1503
+ if (i ? n = i(t, e) : Ct(t) ? n = Es(t, e) : "view" in t && (n = t.view), !n) throw new Error(`No writer found for box type: ${s}`);
1445
1504
  }
1446
1505
  if ("buffer" in t && (n = t), !n) throw new Error("Invalid box");
1447
1506
  return new Uint8Array(n.buffer, n.byteOffset, n.byteLength);
1448
1507
  }
1449
- function Ss(t, e, n) {
1508
+ function Bs(t, e, n) {
1450
1509
  const s = n > 0 ? n : t.byteLength - (e - t.byteOffset);
1451
1510
  return new Uint8Array(t.buffer, e, Math.max(s, 0));
1452
1511
  }
1453
- function As(t, e, n) {
1512
+ function Rs(t, e, n) {
1454
1513
  let s = NaN;
1455
1514
  const i = e - t.byteOffset;
1456
1515
  switch (n) {
@@ -1492,7 +1551,7 @@ function Y(t, e, n) {
1492
1551
  }
1493
1552
  return i;
1494
1553
  }
1495
- function Ke(t, e, n) {
1554
+ function tt(t, e, n) {
1496
1555
  let s = "";
1497
1556
  for (let i = 0; i < n; i++) {
1498
1557
  const r = Y(t, e + i, 1);
@@ -1500,11 +1559,11 @@ function Ke(t, e, n) {
1500
1559
  }
1501
1560
  return s;
1502
1561
  }
1503
- function _s(t, e, n) {
1562
+ function Cs(t, e, n) {
1504
1563
  const s = n / 2;
1505
1564
  return Y(t, e, s) + Y(t, e + s, s) / Math.pow(2, s);
1506
1565
  }
1507
- function Ms(t, e) {
1566
+ function Is(t, e) {
1508
1567
  let n = "", s = e;
1509
1568
  for (; s - t.byteOffset < t.byteLength; ) {
1510
1569
  const i = Y(t, s, 1);
@@ -1513,22 +1572,22 @@ function Ms(t, e) {
1513
1572
  }
1514
1573
  return n;
1515
1574
  }
1516
- function zs(t, e) {
1575
+ function Ds(t, e) {
1517
1576
  const n = t.byteLength - (e - t.byteOffset);
1518
- return n > 0 ? Tt(new DataView(t.buffer, e, n), { encoding: ue }) : "";
1577
+ return n > 0 ? Rt(new DataView(t.buffer, e, n), { encoding: ue }) : "";
1519
1578
  }
1520
- function ks(t, e) {
1579
+ function Os(t, e) {
1521
1580
  const n = t.byteLength - (e - t.byteOffset);
1522
1581
  let s = "";
1523
1582
  if (n > 0) {
1524
1583
  const i = new DataView(t.buffer, e, n);
1525
1584
  let r = 0;
1526
1585
  for (; r < n && i.getUint8(r) !== 0; r++) ;
1527
- s = Tt(new DataView(t.buffer, e, r), { encoding: ue });
1586
+ s = Rt(new DataView(t.buffer, e, r), { encoding: ue });
1528
1587
  }
1529
1588
  return s;
1530
1589
  }
1531
- var Ts = class xt {
1590
+ var Ls = class Dt {
1532
1591
  /**
1533
1592
  * Creates a new IsoView instance. Similar to DataView, but with additional
1534
1593
  * methods for reading ISO BMFF data. It implements the iterator protocol,
@@ -1539,55 +1598,55 @@ var Ts = class xt {
1539
1598
  */
1540
1599
  constructor(e, n) {
1541
1600
  this.truncated = !1, this.slice = (s, i) => {
1542
- const r = new xt(new DataView(this.dataView.buffer, s, i), this.config), o = this.offset - s, a = i - o;
1543
- return this.offset += a, r.jump(o), r;
1601
+ const r = new Dt(new DataView(this.dataView.buffer, s, i), this.config), o = this.offset - s, c = i - o;
1602
+ return this.offset += c, r.jump(o), r;
1544
1603
  }, this.read = (s, i = 0) => {
1545
1604
  const { dataView: r, offset: o } = this;
1546
- let a, c = i;
1605
+ let c, a = i;
1547
1606
  switch (s) {
1548
1607
  case B:
1549
- a = Y(r, o, i);
1608
+ c = Y(r, o, i);
1550
1609
  break;
1551
- case Xe:
1552
- a = As(r, o, i);
1610
+ case Qe:
1611
+ c = Rs(r, o, i);
1553
1612
  break;
1554
1613
  case te:
1555
- a = _s(r, o, i);
1614
+ c = Cs(r, o, i);
1556
1615
  break;
1557
- case Ge:
1558
- i === -1 ? (a = Ms(r, o), c = a.length + 1) : a = Ke(r, o, i);
1616
+ case Je:
1617
+ i === -1 ? (c = Is(r, o), a = c.length + 1) : c = tt(r, o, i);
1559
1618
  break;
1560
- case Ye:
1561
- a = Ss(r, o, i), c = a.length;
1619
+ case et:
1620
+ c = Bs(r, o, i), a = c.length;
1562
1621
  break;
1563
- case He:
1564
- i === -1 ? (a = ks(r, o), c = a.length + 1) : a = zs(r, o);
1622
+ case Ke:
1623
+ i === -1 ? (c = Os(r, o), a = c.length + 1) : c = Ds(r, o);
1565
1624
  break;
1566
1625
  default:
1567
- a = -1;
1626
+ c = -1;
1568
1627
  }
1569
- return this.offset += c, a;
1570
- }, this.readUint = (s) => this.read(B, s), this.readInt = (s) => this.read(Xe, s), this.readString = (s) => this.read(Ge, s), this.readTemplate = (s) => this.read(te, s), this.readData = (s) => this.read(Ye, s), this.readUtf8 = (s) => this.read(He, s), this.readFullBox = () => ({
1628
+ return this.offset += a, c;
1629
+ }, this.readUint = (s) => this.read(B, s), this.readInt = (s) => this.read(Qe, s), this.readString = (s) => this.read(Je, s), this.readTemplate = (s) => this.read(te, s), this.readData = (s) => this.read(et, s), this.readUtf8 = (s) => this.read(Ke, s), this.readFullBox = () => ({
1571
1630
  version: this.readUint(1),
1572
1631
  flags: this.readUint(3)
1573
1632
  }), this.readArray = (s, i, r) => {
1574
1633
  const o = [];
1575
- for (let a = 0; a < r; a++) o.push(this.read(s, i));
1634
+ for (let c = 0; c < r; c++) o.push(this.read(s, i));
1576
1635
  return o;
1577
1636
  }, this.jump = (s) => {
1578
1637
  this.offset += s;
1579
1638
  }, this.readBox = () => {
1580
1639
  const { dataView: s, offset: i } = this;
1581
1640
  let r = 0;
1582
- const o = Y(s, i, 4), a = Ke(s, i + 4, 4), c = {
1641
+ const o = Y(s, i, 4), c = tt(s, i + 4, 4), a = {
1583
1642
  size: o,
1584
- type: a
1643
+ type: c
1585
1644
  };
1586
- r += 8, c.size === 1 && (c.largesize = Y(s, i + r, 8), r += 8);
1587
- const u = c.size === 0 ? this.bytesRemaining : c.largesize ?? c.size;
1645
+ r += 8, a.size === 1 && (a.largesize = Y(s, i + r, 8), r += 8);
1646
+ const u = a.size === 0 ? this.bytesRemaining : a.largesize ?? a.size;
1588
1647
  if (this.cursor + u > s.byteLength)
1589
1648
  throw this.truncated = !0, new Error("Truncated box");
1590
- return this.jump(r), a === "uuid" && (c.usertype = this.readArray("uint", 1, 16)), c.view = this.slice(i, u), c;
1649
+ return this.jump(r), c === "uuid" && (a.usertype = this.readArray("uint", 1, 16)), a.view = this.slice(i, u), a;
1591
1650
  }, this.readBoxes = (s = -1) => {
1592
1651
  const i = [];
1593
1652
  for (const r of this)
@@ -1597,7 +1656,7 @@ var Ts = class xt {
1597
1656
  const r = [];
1598
1657
  for (let o = 0; o < s; o++) r.push(i());
1599
1658
  return r;
1600
- }, this.dataView = kt(e) ? new DataView(e) : e instanceof DataView ? e : new DataView(e.buffer, e.byteOffset, e.byteLength), this.offset = this.dataView.byteOffset, this.config = n || {};
1659
+ }, this.dataView = Bt(e) ? new DataView(e) : e instanceof DataView ? e : new DataView(e.buffer, e.byteOffset, e.byteLength), this.offset = this.dataView.byteOffset, this.config = n || {};
1601
1660
  }
1602
1661
  /**
1603
1662
  * The buffer of the data view.
@@ -1644,9 +1703,9 @@ var Ts = class xt {
1644
1703
  const { readers: e = {} } = this.config;
1645
1704
  for (; !this.done; ) try {
1646
1705
  const n = this.readBox(), { type: s, view: i } = n, r = e[s] || e[s.trim()];
1647
- if (r && Object.assign(n, r(i, s)), Ut(n) && !n.boxes) {
1706
+ if (r && Object.assign(n, r(i, s)), Ct(n) && !n.boxes) {
1648
1707
  const o = [];
1649
- for (const a of i) o.push(a);
1708
+ for (const c of i) o.push(c);
1650
1709
  n.boxes = o;
1651
1710
  }
1652
1711
  yield n;
@@ -1656,15 +1715,15 @@ var Ts = class xt {
1656
1715
  }
1657
1716
  }
1658
1717
  };
1659
- function Be(t, e) {
1718
+ function Oe(t, e) {
1660
1719
  const n = [];
1661
- for (const s of new Ts(t, e)) n.push(s);
1720
+ for (const s of new Ls(t, e)) n.push(s);
1662
1721
  return n;
1663
1722
  }
1664
- function Us(t, e) {
1665
- return Et(t, ws(e));
1723
+ function Fs(t, e) {
1724
+ return It(t, Ts(e));
1666
1725
  }
1667
- function Es(t, e) {
1726
+ function Ns(t, e) {
1668
1727
  const { readArray: n, readUint: s, readTemplate: i, readBoxes: r } = e;
1669
1728
  return {
1670
1729
  type: t,
@@ -1679,7 +1738,7 @@ function Es(t, e) {
1679
1738
  boxes: r()
1680
1739
  };
1681
1740
  }
1682
- function Ce(t, e) {
1741
+ function Le(t, e) {
1683
1742
  const { readArray: n, readUint: s, readInt: i, readTemplate: r, readBoxes: o } = e;
1684
1743
  return {
1685
1744
  type: t,
@@ -1700,23 +1759,23 @@ function Ce(t, e) {
1700
1759
  boxes: o()
1701
1760
  };
1702
1761
  }
1703
- function Je(t) {
1704
- return Ce("avc1", t);
1762
+ function nt(t) {
1763
+ return Le("avc1", t);
1705
1764
  }
1706
- function xs(t) {
1707
- return Ce("hev1", t);
1765
+ function Ps(t) {
1766
+ return Le("hev1", t);
1708
1767
  }
1709
- function Rs(t) {
1710
- return Ce("hvc1", t);
1768
+ function $s(t) {
1769
+ return Le("hvc1", t);
1711
1770
  }
1712
- function Bs(t) {
1771
+ function js(t) {
1713
1772
  return {
1714
1773
  type: "mdat",
1715
1774
  data: t.readData(-1)
1716
1775
  };
1717
1776
  }
1718
- function Cs(t) {
1719
- const { version: e, flags: n } = t.readFullBox(), s = t.readUint(e == 1 ? 8 : 4), i = t.readUint(e == 1 ? 8 : 4), r = t.readUint(4), o = t.readUint(e == 1 ? 8 : 4), a = t.readUint(2);
1777
+ function Zs(t) {
1778
+ const { version: e, flags: n } = t.readFullBox(), s = t.readUint(e == 1 ? 8 : 4), i = t.readUint(e == 1 ? 8 : 4), r = t.readUint(4), o = t.readUint(e == 1 ? 8 : 4), c = t.readUint(2);
1720
1779
  return {
1721
1780
  type: "mdhd",
1722
1781
  version: e,
@@ -1725,21 +1784,21 @@ function Cs(t) {
1725
1784
  modificationTime: i,
1726
1785
  timescale: r,
1727
1786
  duration: o,
1728
- language: String.fromCharCode((a >> 10 & 31) + 96, (a >> 5 & 31) + 96, (a & 31) + 96),
1787
+ language: String.fromCharCode((c >> 10 & 31) + 96, (c >> 5 & 31) + 96, (c & 31) + 96),
1729
1788
  preDefined: t.readUint(2)
1730
1789
  };
1731
1790
  }
1732
- function Is(t) {
1791
+ function Vs(t) {
1733
1792
  return {
1734
1793
  type: "mfhd",
1735
1794
  ...t.readFullBox(),
1736
1795
  sequenceNumber: t.readUint(4)
1737
1796
  };
1738
1797
  }
1739
- function Os(t) {
1740
- return Es("mp4a", t);
1798
+ function Ws(t) {
1799
+ return Ns("mp4a", t);
1741
1800
  }
1742
- function Ds(t) {
1801
+ function qs(t) {
1743
1802
  const { version: e, flags: n } = t.readFullBox(), s = t.readUint(4);
1744
1803
  return {
1745
1804
  type: "stsd",
@@ -1749,7 +1808,7 @@ function Ds(t) {
1749
1808
  entries: t.readBoxes(s)
1750
1809
  };
1751
1810
  }
1752
- function Ls(t) {
1811
+ function Hs(t) {
1753
1812
  const { version: e, flags: n } = t.readFullBox();
1754
1813
  return {
1755
1814
  type: "tfdt",
@@ -1758,7 +1817,7 @@ function Ls(t) {
1758
1817
  baseMediaDecodeTime: t.readUint(e == 1 ? 8 : 4)
1759
1818
  };
1760
1819
  }
1761
- function Ps(t) {
1820
+ function Gs(t) {
1762
1821
  const { version: e, flags: n } = t.readFullBox();
1763
1822
  return {
1764
1823
  type: "tfhd",
@@ -1772,7 +1831,7 @@ function Ps(t) {
1772
1831
  defaultSampleFlags: n & 32 ? t.readUint(4) : void 0
1773
1832
  };
1774
1833
  }
1775
- function Ns(t) {
1834
+ function Xs(t) {
1776
1835
  const { version: e, flags: n } = t.readFullBox(), s = e === 1 ? 8 : 4;
1777
1836
  return {
1778
1837
  type: "tkhd",
@@ -1793,13 +1852,24 @@ function Ns(t) {
1793
1852
  height: t.readTemplate(4)
1794
1853
  };
1795
1854
  }
1796
- function Fs(t) {
1855
+ function Ys(t) {
1856
+ return {
1857
+ type: "trex",
1858
+ ...t.readFullBox(),
1859
+ trackId: t.readUint(4),
1860
+ defaultSampleDescriptionIndex: t.readUint(4),
1861
+ defaultSampleDuration: t.readUint(4),
1862
+ defaultSampleSize: t.readUint(4),
1863
+ defaultSampleFlags: t.readUint(4)
1864
+ };
1865
+ }
1866
+ function Ks(t) {
1797
1867
  const { version: e, flags: n } = t.readFullBox(), s = t.readUint(4);
1798
1868
  let i, r;
1799
1869
  n & 1 && (i = t.readInt(4)), n & 4 && (r = t.readUint(4));
1800
1870
  const o = t.readEntries(s, () => {
1801
- const a = {};
1802
- return n & 256 && (a.sampleDuration = t.readUint(4)), n & 512 && (a.sampleSize = t.readUint(4)), n & 1024 && (a.sampleFlags = t.readUint(4)), n & 2048 && (a.sampleCompositionTimeOffset = e === 1 ? t.readInt(4) : t.readUint(4)), a;
1871
+ const c = {};
1872
+ return n & 256 && (c.sampleDuration = t.readUint(4)), n & 512 && (c.sampleSize = t.readUint(4)), n & 1024 && (c.sampleFlags = t.readUint(4)), n & 2048 && (c.sampleCompositionTimeOffset = e === 1 ? t.readInt(4) : t.readUint(4)), c;
1803
1873
  });
1804
1874
  return {
1805
1875
  type: "trun",
@@ -1811,149 +1881,158 @@ function Fs(t) {
1811
1881
  samples: o
1812
1882
  };
1813
1883
  }
1814
- function $s(t, e) {
1815
- const r = t.entries.length, { bytes: o, size: a } = Re(t.entries, e), c = new k("dref", 16 + a);
1816
- return c.writeFullBox(t.version, t.flags), c.writeUint(r, 4), c.writeBytes(o), c;
1884
+ function Js(t, e) {
1885
+ const r = t.entries.length, { bytes: o, size: c } = De(t.entries, e), a = new k("dref", 16 + c);
1886
+ return a.writeFullBox(t.version, t.flags), a.writeUint(r, 4), a.writeBytes(o), a;
1817
1887
  }
1818
- function js(t) {
1888
+ function Qs(t) {
1819
1889
  const i = t.compatibleBrands.length * 4, r = new k("ftyp", 16 + i);
1820
1890
  r.writeString(t.majorBrand), r.writeUint(t.minorVersion, 4);
1821
1891
  for (const o of t.compatibleBrands) r.writeString(o);
1822
1892
  return r;
1823
1893
  }
1824
- function Zs(t) {
1825
- const o = t.name.length + 1, a = new k("hdlr", 32 + o);
1826
- return a.writeFullBox(t.version, t.flags), a.writeUint(t.preDefined, 4), a.writeString(t.handlerType), a.writeArray(t.reserved, B, 4, 3), a.writeTerminatedString(t.name), a;
1894
+ function ei(t) {
1895
+ const o = t.name.length + 1, c = new k("hdlr", 32 + o);
1896
+ return c.writeFullBox(t.version, t.flags), c.writeUint(t.preDefined, 4), c.writeString(t.handlerType), c.writeArray(t.reserved, B, 4, 3), c.writeTerminatedString(t.name), c;
1827
1897
  }
1828
- function Vs(t) {
1898
+ function ti(t) {
1829
1899
  const e = new k("mdat", 8 + t.data.length);
1830
1900
  return e.writeBytes(t.data), e;
1831
1901
  }
1832
- function Ws(t) {
1902
+ function ni(t) {
1833
1903
  const e = t.version === 1 ? 8 : 4, n = 8, s = 4, i = e * 3, r = new k("mdhd", n + s + i + 4 + 2 + 2);
1834
1904
  r.writeFullBox(t.version, t.flags), r.writeUint(t.creationTime, e), r.writeUint(t.modificationTime, e), r.writeUint(t.timescale, 4), r.writeUint(t.duration, e);
1835
1905
  const o = t.language.length >= 3 ? (t.language.charCodeAt(0) - 96 & 31) << 10 | (t.language.charCodeAt(1) - 96 & 31) << 5 | t.language.charCodeAt(2) - 96 & 31 : 0;
1836
1906
  return r.writeUint(o, 2), r.writeUint(t.preDefined, 2), r;
1837
1907
  }
1838
- function qs(t) {
1908
+ function si(t) {
1839
1909
  const e = new k("mfhd", 16);
1840
1910
  return e.writeFullBox(t.version, t.flags), e.writeUint(t.sequenceNumber, 4), e;
1841
1911
  }
1842
- function Hs(t) {
1912
+ function ii(t) {
1843
1913
  const e = t.version === 1 ? 8 : 4, n = 8, s = 4, i = e * 3, r = new k("mvhd", n + s + i + 4 + 4 + 2 + 2 + 8 + 36 + 24 + 4);
1844
1914
  return r.writeFullBox(t.version, t.flags), r.writeUint(t.creationTime, e), r.writeUint(t.modificationTime, e), r.writeUint(t.timescale, 4), r.writeUint(t.duration, e), r.writeTemplate(t.rate, 4), r.writeTemplate(t.volume, 2), r.writeUint(t.reserved1, 2), r.writeArray(t.reserved2, B, 4, 2), r.writeArray(t.matrix, te, 4, 9), r.writeArray(t.preDefined, B, 4, 6), r.writeUint(t.nextTrackId, 4), r;
1845
1915
  }
1846
- function Gs(t) {
1916
+ function ri(t) {
1847
1917
  const e = new k("smhd", 16);
1848
1918
  return e.writeFullBox(t.version, t.flags), e.writeUint(t.balance, 2), e.writeUint(t.reserved, 2), e;
1849
1919
  }
1850
- function Xs(t, e) {
1851
- const r = t.entries.length, { bytes: o, size: a } = Re(t.entries, e), c = new k("stsd", 16 + a);
1852
- return c.writeFullBox(t.version, t.flags), c.writeUint(r, 4), c.writeBytes(o), c;
1920
+ function oi(t, e) {
1921
+ const r = t.entries.length, { bytes: o, size: c } = De(t.entries, e), a = new k("stsd", 16 + c);
1922
+ return a.writeFullBox(t.version, t.flags), a.writeUint(r, 4), a.writeBytes(o), a;
1853
1923
  }
1854
- function Ys(t) {
1924
+ function ai(t) {
1855
1925
  const i = t.entryCount * 8, r = new k("stts", 16 + i);
1856
1926
  r.writeFullBox(t.version, t.flags), r.writeUint(t.entryCount, 4);
1857
1927
  for (const o of t.entries)
1858
1928
  r.writeUint(o.sampleCount, 4), r.writeUint(o.sampleDelta, 4);
1859
1929
  return r;
1860
1930
  }
1861
- function Ks(t) {
1931
+ function ci(t) {
1862
1932
  const e = t.version === 1 ? 8 : 4, n = 8, s = 4, i = e, r = new k("tfdt", n + s + i);
1863
1933
  return r.writeFullBox(t.version, t.flags), r.writeUint(t.baseMediaDecodeTime, e), r;
1864
1934
  }
1865
- function Js(t) {
1866
- const i = t.flags & 1 ? 8 : 0, r = t.flags & 2 ? 4 : 0, o = t.flags & 8 ? 4 : 0, a = t.flags & 16 ? 4 : 0, c = t.flags & 32 ? 4 : 0, u = new k("tfhd", 16 + i + r + o + a + c);
1935
+ function ui(t) {
1936
+ const i = t.flags & 1 ? 8 : 0, r = t.flags & 2 ? 4 : 0, o = t.flags & 8 ? 4 : 0, c = t.flags & 16 ? 4 : 0, a = t.flags & 32 ? 4 : 0, u = new k("tfhd", 16 + i + r + o + c + a);
1867
1937
  return u.writeFullBox(t.version, t.flags), u.writeUint(t.trackId, 4), t.flags & 1 && u.writeUint(t.baseDataOffset ?? 0, 8), t.flags & 2 && u.writeUint(t.sampleDescriptionIndex ?? 0, 4), t.flags & 8 && u.writeUint(t.defaultSampleDuration ?? 0, 4), t.flags & 16 && u.writeUint(t.defaultSampleSize ?? 0, 4), t.flags & 32 && u.writeUint(t.defaultSampleFlags ?? 0, 4), u;
1868
1938
  }
1869
- function Qs(t) {
1939
+ function li(t) {
1870
1940
  const e = t.version === 1 ? 8 : 4, n = 8, s = 4, i = e * 3, r = new k("tkhd", n + s + i + 4 + 4 + 8 + 2 + 2 + 2 + 2 + 36 + 4 + 4);
1871
1941
  return r.writeFullBox(t.version, t.flags), r.writeUint(t.creationTime, e), r.writeUint(t.modificationTime, e), r.writeUint(t.trackId, 4), r.writeUint(t.reserved1, 4), r.writeUint(t.duration, e), r.writeArray(t.reserved2, B, 4, 2), r.writeUint(t.layer, 2), r.writeUint(t.alternateGroup, 2), r.writeTemplate(t.volume, 2), r.writeUint(t.reserved3, 2), r.writeArray(t.matrix, te, 4, 9), r.writeTemplate(t.width, 4), r.writeTemplate(t.height, 4), r;
1872
1942
  }
1873
- function ei(t) {
1943
+ function di(t) {
1874
1944
  const e = new k("trex", 32);
1875
1945
  return e.writeFullBox(t.version, t.flags), e.writeUint(t.trackId, 4), e.writeUint(t.defaultSampleDescriptionIndex, 4), e.writeUint(t.defaultSampleDuration, 4), e.writeUint(t.defaultSampleSize, 4), e.writeUint(t.defaultSampleFlags, 4), e;
1876
1946
  }
1877
- function ti(t) {
1947
+ function hi(t) {
1878
1948
  const i = t.flags & 1 ? 4 : 0, r = t.flags & 4 ? 4 : 0;
1879
1949
  let o = 0;
1880
1950
  t.flags & 256 && (o += 4), t.flags & 512 && (o += 4), t.flags & 1024 && (o += 4), t.flags & 2048 && (o += 4);
1881
- const a = o * t.sampleCount, c = new k("trun", 16 + i + r + a);
1882
- c.writeFullBox(t.version, t.flags), c.writeUint(t.sampleCount, 4), t.flags & 1 && c.writeUint(t.dataOffset ?? 0, 4), t.flags & 4 && c.writeUint(t.firstSampleFlags ?? 0, 4);
1951
+ const c = o * t.sampleCount, a = new k("trun", 16 + i + r + c);
1952
+ a.writeFullBox(t.version, t.flags), a.writeUint(t.sampleCount, 4), t.flags & 1 && a.writeUint(t.dataOffset ?? 0, 4), t.flags & 4 && a.writeUint(t.firstSampleFlags ?? 0, 4);
1883
1953
  for (const u of t.samples)
1884
- t.flags & 256 && c.writeUint(u.sampleDuration ?? 0, 4), t.flags & 512 && c.writeUint(u.sampleSize ?? 0, 4), t.flags & 1024 && c.writeUint(u.sampleFlags ?? 0, 4), t.flags & 2048 && c.writeUint(u.sampleCompositionTimeOffset ?? 0, 4);
1885
- return c;
1954
+ t.flags & 256 && a.writeUint(u.sampleDuration ?? 0, 4), t.flags & 512 && a.writeUint(u.sampleSize ?? 0, 4), t.flags & 1024 && a.writeUint(u.sampleFlags ?? 0, 4), t.flags & 2048 && a.writeUint(u.sampleCompositionTimeOffset ?? 0, 4);
1955
+ return a;
1886
1956
  }
1887
- function ni(t) {
1957
+ function fi(t) {
1888
1958
  const s = t.location.length + 1, i = new k("url ", 12 + s);
1889
1959
  return i.writeFullBox(t.version, t.flags), i.writeTerminatedString(t.location), i;
1890
1960
  }
1891
- function si(t) {
1961
+ function mi(t) {
1892
1962
  const e = new k("vmhd", 20);
1893
1963
  return e.writeFullBox(t.version, t.flags), e.writeUint(t.graphicsmode, 2), e.writeArray(t.opcolor, B, 2, 3), e;
1894
1964
  }
1895
- const ii = {
1896
- avc1: Je,
1897
- avc3: Je,
1965
+ const pi = {
1966
+ avc1: nt,
1967
+ avc3: nt,
1898
1968
  // avc3 has same structure
1899
- hvc1: Rs,
1900
- hev1: xs,
1901
- mp4a: Os,
1902
- stsd: Ds,
1903
- mdhd: Cs,
1904
- tkhd: Ns
1905
- }, Rt = {
1906
- mfhd: Is,
1907
- tfhd: Ps,
1908
- tfdt: Ls,
1909
- trun: Fs,
1910
- mdat: Bs
1969
+ hvc1: $s,
1970
+ hev1: Ps,
1971
+ mp4a: Ws,
1972
+ stsd: qs,
1973
+ mdhd: Zs,
1974
+ tkhd: Xs,
1975
+ trex: Ys
1976
+ }, Ot = {
1977
+ mfhd: Vs,
1978
+ tfhd: Gs,
1979
+ tfdt: Hs,
1980
+ trun: Ks,
1981
+ mdat: js
1911
1982
  };
1912
- function N(t, e) {
1983
+ function L(t, e) {
1913
1984
  for (const n of t) {
1914
1985
  if (e(n))
1915
1986
  return n;
1916
1987
  const s = n.boxes;
1917
1988
  if (s && Array.isArray(s)) {
1918
- const i = N(s, e);
1989
+ const i = L(s, e);
1919
1990
  if (i) return i;
1920
1991
  }
1921
1992
  }
1922
1993
  }
1923
- function Ie(t) {
1994
+ function Fe(t) {
1924
1995
  const e = new ArrayBuffer(t.byteLength);
1925
1996
  return new Uint8Array(e).set(t), e;
1926
1997
  }
1927
- function H(t) {
1998
+ function W(t) {
1928
1999
  return (e) => e.type === t;
1929
2000
  }
1930
- function ri(t) {
1931
- const e = Be(Ie(t), { readers: ii }), n = N(e, H("mdhd"));
2001
+ function ze(t) {
2002
+ const e = Oe(Fe(t), { readers: pi }), n = L(e, W("mdhd"));
1932
2003
  if (!n)
1933
2004
  throw new Error("No mdhd box found in init segment");
1934
- const i = N(e, H("tkhd"))?.trackId ?? 1, r = N(e, H("stsd"));
2005
+ const i = L(e, W("tkhd"))?.trackId ?? 1, r = L(e, W("stsd"));
1935
2006
  if (!r?.entries || r.entries.length === 0)
1936
2007
  throw new Error("No stsd box found in init segment");
1937
- const o = r.entries[0];
2008
+ const o = r.entries[0], c = gi(o), a = L(
2009
+ e,
2010
+ (u) => u.type === "trex" && u.trackId === i
2011
+ );
1938
2012
  return {
1939
- description: oi(o),
2013
+ description: c,
1940
2014
  timescale: n.timescale,
1941
- trackId: i
2015
+ trackId: i,
2016
+ defaultSampleDuration: a?.defaultSampleDuration ?? 0,
2017
+ defaultSampleSize: a?.defaultSampleSize ?? 0,
2018
+ defaultSampleFlags: a?.defaultSampleFlags ?? 0
1942
2019
  };
1943
2020
  }
1944
- function oi(t) {
2021
+ function gi(t) {
1945
2022
  if (!(!t.boxes || !Array.isArray(t.boxes)))
1946
2023
  for (const e of t.boxes) {
1947
2024
  if (e instanceof Uint8Array) {
1948
2025
  if (e.length > 8) {
1949
2026
  const s = String.fromCharCode(e[4], e[5], e[6], e[7]);
1950
- if (s === "avcC" || s === "hvcC" || s === "esds" || s === "dOps")
2027
+ if (s === "avcC" || s === "hvcC" || s === "dOps")
1951
2028
  return new Uint8Array(e.slice(8));
2029
+ if (s === "esds")
2030
+ return st(new Uint8Array(e.slice(8)));
1952
2031
  }
1953
2032
  continue;
1954
2033
  }
1955
2034
  const n = e.type;
1956
- if (n === "avcC" || n === "hvcC" || n === "esds" || n === "dOps") {
2035
+ if (n === "avcC" || n === "hvcC" || n === "dOps") {
1957
2036
  if (e.view) {
1958
2037
  const s = e.view, i = 8, r = s.byteOffset + i, o = e.size - i;
1959
2038
  return new Uint8Array(s.buffer, r, o);
@@ -1963,46 +2042,68 @@ function oi(t) {
1963
2042
  if (e.raw instanceof Uint8Array)
1964
2043
  return new Uint8Array(e.raw.slice(8));
1965
2044
  }
2045
+ if (n === "esds") {
2046
+ let s;
2047
+ if (e.view) {
2048
+ const i = e.view, r = 8;
2049
+ s = new Uint8Array(i.buffer, i.byteOffset + r, e.size - r);
2050
+ } else e.data instanceof Uint8Array ? s = new Uint8Array(e.data) : e.raw instanceof Uint8Array && (s = new Uint8Array(e.raw.slice(8)));
2051
+ if (s) return st(s);
2052
+ }
1966
2053
  }
1967
2054
  }
1968
- function Bt(t, e) {
1969
- const n = Be(Ie(t), { readers: Rt });
1970
- return (N(n, H("tfdt"))?.baseMediaDecodeTime ?? 0) * 1e6 / e;
2055
+ function st(t) {
2056
+ let e = 4;
2057
+ for (; e < t.length; ) {
2058
+ const n = t[e++];
2059
+ let s = 0;
2060
+ for (let i = 0; i < 4 && e < t.length; i++) {
2061
+ const r = t[e++];
2062
+ if (s = s << 7 | r & 127, (r & 128) === 0) break;
2063
+ }
2064
+ if (n === 5)
2065
+ return e + s <= t.length ? new Uint8Array(t.buffer, t.byteOffset + e, s) : void 0;
2066
+ n === 3 ? e += 3 : n === 4 ? e += 13 : e += s;
2067
+ }
2068
+ }
2069
+ function Lt(t, e) {
2070
+ const n = Oe(Fe(t), { readers: Ot });
2071
+ return (L(n, W("tfdt"))?.baseMediaDecodeTime ?? 0) * 1e6 / e.timescale;
1971
2072
  }
1972
- function Ct(t, e) {
1973
- const n = Be(Ie(t), { readers: Rt }), i = N(n, H("tfdt"))?.baseMediaDecodeTime ?? 0, r = N(n, H("tfhd")), o = r?.defaultSampleDuration ?? 0, a = r?.defaultSampleSize ?? 0, c = r?.defaultSampleFlags ?? 0, u = N(n, H("trun"));
2073
+ function wi(t, e) {
2074
+ const n = Oe(Fe(t), { readers: Ot }), i = L(n, W("tfdt"))?.baseMediaDecodeTime ?? 0, r = L(n, W("tfhd")), o = r?.defaultSampleDuration ?? e.defaultSampleDuration, c = r?.defaultSampleSize ?? e.defaultSampleSize, a = r?.defaultSampleFlags ?? e.defaultSampleFlags, u = L(n, W("trun"));
1974
2075
  if (!u)
1975
2076
  throw new Error("No trun box found in data segment");
1976
- const l = N(n, H("mdat"));
2077
+ const l = L(n, W("mdat"));
1977
2078
  if (!l)
1978
2079
  throw new Error("No mdat box found in data segment");
1979
2080
  const d = l.data;
1980
2081
  if (!d)
1981
2082
  throw new Error("No data in mdat box");
1982
2083
  const f = [];
1983
- let g = 0, y = i;
1984
- for (let v = 0; v < u.sampleCount; v++) {
1985
- const A = u.samples[v] ?? {}, E = A.sampleSize ?? a, M = A.sampleDuration ?? o;
1986
- if (E <= 0)
1987
- throw new Error(`Invalid sample size ${E} for sample ${v} in trun`);
1988
- if (M <= 0)
1989
- throw new Error(`Invalid sample duration ${M} for sample ${v} in trun`);
1990
- if (g + E > d.length)
2084
+ let w = 0, y = i;
2085
+ for (let b = 0; b < u.sampleCount; b++) {
2086
+ const A = u.samples[b] ?? {}, T = A.sampleSize ?? c, z = A.sampleDuration ?? o;
2087
+ if (T <= 0)
2088
+ throw new Error(`Invalid sample size ${T} for sample ${b} in trun`);
2089
+ if (z < 0)
2090
+ throw new Error(`Invalid sample duration ${z} for sample ${b} in trun`);
2091
+ if (w + T > d.length)
1991
2092
  throw new Error(
1992
- `Sample ${v} would overflow mdat: offset=${g}, size=${E}, mdatLength=${d.length}`
2093
+ `Sample ${b} would overflow mdat: offset=${w}, size=${T}, mdatLength=${d.length}`
1993
2094
  );
1994
- const X = v === 0 && u.firstSampleFlags !== void 0 ? u.firstSampleFlags : A.sampleFlags ?? c, $ = A.sampleCompositionTimeOffset ?? 0, j = new Uint8Array(d.slice(g, g + E));
1995
- g += E;
1996
- const Z = y + $, V = Math.round(Z * 1e6 / e), z = X === 0 || (X & 65536) === 0;
2095
+ const H = b === 0 && u.firstSampleFlags !== void 0 ? u.firstSampleFlags : A.sampleFlags ?? a, P = A.sampleCompositionTimeOffset ?? 0, G = new Uint8Array(d.slice(w, w + T));
2096
+ w += T;
2097
+ const X = y + P, $ = Math.round(X * 1e6 / e.timescale), M = H === 0 || (H & 65536) === 0;
1997
2098
  f.push({
1998
- data: j,
1999
- timestamp: V,
2000
- keyframe: z
2001
- }), y += M;
2099
+ data: G,
2100
+ timestamp: $,
2101
+ keyframe: M
2102
+ }), y += z;
2002
2103
  }
2003
2104
  return f;
2004
2105
  }
2005
- function F(t) {
2106
+ function N(t) {
2006
2107
  if (t = t.startsWith("0x") ? t.slice(2) : t, t.length % 2)
2007
2108
  throw new Error("invalid hex string length");
2008
2109
  const e = t.match(/.{2}/g);
@@ -2010,57 +2111,57 @@ function F(t) {
2010
2111
  throw new Error("invalid hex string format");
2011
2112
  return new Uint8Array(e.map((n) => parseInt(n, 16)));
2012
2113
  }
2013
- const ye = [65536, 0, 0, 0, 65536, 0, 0, 0, 1073741824], ai = {
2114
+ const be = [65536, 0, 0, 0, 65536, 0, 0, 0, 1073741824], yi = {
2014
2115
  // Init segment boxes
2015
- ftyp: js,
2016
- mvhd: Hs,
2017
- tkhd: Qs,
2018
- mdhd: Ws,
2019
- hdlr: Zs,
2020
- vmhd: si,
2021
- smhd: Gs,
2022
- "url ": ni,
2023
- dref: $s,
2024
- stsd: Xs,
2025
- stts: Ys,
2026
- trex: ei,
2116
+ ftyp: Qs,
2117
+ mvhd: ii,
2118
+ tkhd: li,
2119
+ mdhd: ni,
2120
+ hdlr: ei,
2121
+ vmhd: mi,
2122
+ smhd: ri,
2123
+ "url ": fi,
2124
+ dref: Js,
2125
+ stsd: oi,
2126
+ stts: ai,
2127
+ trex: di,
2027
2128
  // Data segment boxes
2028
- mfhd: qs,
2029
- tfhd: Js,
2030
- tfdt: Ks,
2031
- trun: ti,
2032
- mdat: Vs
2129
+ mfhd: si,
2130
+ tfhd: ui,
2131
+ tfdt: ci,
2132
+ trun: hi,
2133
+ mdat: ti
2033
2134
  // For boxes without library writers, we create them manually as Uint8Arrays
2034
2135
  };
2035
2136
  function le(t) {
2036
- return Us(t, { writers: ai });
2137
+ return Fs(t, { writers: yi });
2037
2138
  }
2038
- function Oe(t, e, n, s) {
2139
+ function Ne(t, e, n, s) {
2039
2140
  const i = 12 + s.length, r = new Uint8Array(i), o = new DataView(r.buffer);
2040
2141
  return o.setUint32(0, i, !1), r[4] = t.charCodeAt(0), r[5] = t.charCodeAt(1), r[6] = t.charCodeAt(2), r[7] = t.charCodeAt(3), o.setUint32(8, e << 24 | n, !1), r.set(s, 12), r;
2041
2142
  }
2042
- function It() {
2143
+ function Ft() {
2043
2144
  const t = new Uint8Array(4);
2044
- return Oe("stsc", 0, 0, t);
2145
+ return Ne("stsc", 0, 0, t);
2045
2146
  }
2046
- function Ot() {
2147
+ function Nt() {
2047
2148
  const t = new Uint8Array(8);
2048
- return Oe("stsz", 0, 0, t);
2149
+ return Ne("stsz", 0, 0, t);
2049
2150
  }
2050
- function Dt() {
2151
+ function Pt() {
2051
2152
  const t = new Uint8Array(4);
2052
- return Oe("stco", 0, 0, t);
2153
+ return Ne("stco", 0, 0, t);
2053
2154
  }
2054
- function ci(t, e, n) {
2055
- const s = 8 + n.length, r = 8 + (78 + s), o = new Uint8Array(r), a = new DataView(o.buffer);
2056
- let c = 0;
2057
- return a.setUint32(c, r, !1), c += 4, o[c++] = 97, o[c++] = 118, o[c++] = 99, o[c++] = 49, c += 6, a.setUint16(c, 1, !1), c += 2, a.setUint16(c, 0, !1), c += 2, a.setUint16(c, 0, !1), c += 2, c += 12, a.setUint16(c, t, !1), c += 2, a.setUint16(c, e, !1), c += 2, a.setUint32(c, 4718592, !1), c += 4, a.setUint32(c, 4718592, !1), c += 4, a.setUint32(c, 0, !1), c += 4, a.setUint16(c, 1, !1), c += 2, c += 32, a.setUint16(c, 24, !1), c += 2, a.setUint16(c, 65535, !1), c += 2, a.setUint32(c, s, !1), c += 4, o[c++] = 97, o[c++] = 118, o[c++] = 99, o[c++] = 67, o.set(n, c), o;
2155
+ function bi(t, e, n) {
2156
+ const s = 8 + n.length, r = 8 + (78 + s), o = new Uint8Array(r), c = new DataView(o.buffer);
2157
+ let a = 0;
2158
+ return c.setUint32(a, r, !1), a += 4, o[a++] = 97, o[a++] = 118, o[a++] = 99, o[a++] = 49, a += 6, c.setUint16(a, 1, !1), a += 2, c.setUint16(a, 0, !1), a += 2, c.setUint16(a, 0, !1), a += 2, a += 12, c.setUint16(a, t, !1), a += 2, c.setUint16(a, e, !1), a += 2, c.setUint32(a, 4718592, !1), a += 4, c.setUint32(a, 4718592, !1), a += 4, c.setUint32(a, 0, !1), a += 4, c.setUint16(a, 1, !1), a += 2, a += 32, c.setUint16(a, 24, !1), a += 2, c.setUint16(a, 65535, !1), a += 2, c.setUint32(a, s, !1), a += 4, o[a++] = 97, o[a++] = 118, o[a++] = 99, o[a++] = 67, o.set(n, a), o;
2058
2159
  }
2059
- function Qe(t) {
2060
- const { codedWidth: e, codedHeight: n, description: s, container: i } = t;
2160
+ function vi(t) {
2161
+ const { codedWidth: e, codedHeight: n, description: s } = t;
2061
2162
  if (!e || !n || !s)
2062
2163
  throw new Error("Missing required fields to create video init segment");
2063
- const r = i.kind === "cmaf" ? i.timescale : 1e6, o = i.kind === "cmaf" ? i.trackId : 1, a = {
2164
+ const i = 1e6, r = 1, o = {
2064
2165
  type: "ftyp",
2065
2166
  majorBrand: "isom",
2066
2167
  minorVersion: 512,
@@ -2071,7 +2172,7 @@ function Qe(t) {
2071
2172
  flags: 0,
2072
2173
  creationTime: 0,
2073
2174
  modificationTime: 0,
2074
- timescale: r,
2175
+ timescale: i,
2075
2176
  duration: 0,
2076
2177
  // Unknown/fragmented
2077
2178
  rate: 65536,
@@ -2080,17 +2181,17 @@ function Qe(t) {
2080
2181
  // 1.0 in 8.8 fixed point
2081
2182
  reserved1: 0,
2082
2183
  reserved2: [0, 0],
2083
- matrix: ye,
2184
+ matrix: be,
2084
2185
  preDefined: [0, 0, 0, 0, 0, 0],
2085
- nextTrackId: o + 1
2086
- }, u = {
2186
+ nextTrackId: r + 1
2187
+ }, a = {
2087
2188
  type: "tkhd",
2088
2189
  version: 0,
2089
2190
  flags: 3,
2090
2191
  // Track enabled + in movie
2091
2192
  creationTime: 0,
2092
2193
  modificationTime: 0,
2093
- trackId: o,
2194
+ trackId: r,
2094
2195
  reserved1: 0,
2095
2196
  duration: 0,
2096
2197
  reserved2: [0, 0],
@@ -2099,21 +2200,21 @@ function Qe(t) {
2099
2200
  volume: 0,
2100
2201
  // Video tracks have 0 volume
2101
2202
  reserved3: 0,
2102
- matrix: ye,
2203
+ matrix: be,
2103
2204
  width: e * 65536,
2104
2205
  // 16.16 fixed point (avoid << which produces signed int)
2105
2206
  height: n * 65536
2106
- }, l = {
2207
+ }, u = {
2107
2208
  type: "mdhd",
2108
2209
  version: 0,
2109
2210
  flags: 0,
2110
2211
  creationTime: 0,
2111
2212
  modificationTime: 0,
2112
- timescale: r,
2213
+ timescale: i,
2113
2214
  duration: 0,
2114
2215
  language: "und",
2115
2216
  preDefined: 0
2116
- }, d = {
2217
+ }, l = {
2117
2218
  type: "hdlr",
2118
2219
  version: 0,
2119
2220
  flags: 0,
@@ -2121,14 +2222,14 @@ function Qe(t) {
2121
2222
  handlerType: "vide",
2122
2223
  reserved: [0, 0, 0],
2123
2224
  name: "VideoHandler"
2124
- }, f = {
2225
+ }, d = {
2125
2226
  type: "vmhd",
2126
2227
  version: 0,
2127
2228
  flags: 1,
2128
2229
  // Required to be 1
2129
2230
  graphicsmode: 0,
2130
2231
  opcolor: [0, 0, 0]
2131
- }, v = {
2232
+ }, y = {
2132
2233
  type: "dinf",
2133
2234
  boxes: [{
2134
2235
  type: "dref",
@@ -2143,31 +2244,31 @@ function Qe(t) {
2143
2244
  location: ""
2144
2245
  }]
2145
2246
  }]
2146
- }, E = {
2247
+ }, A = {
2147
2248
  type: "stsd",
2148
2249
  version: 0,
2149
2250
  flags: 0,
2150
2251
  entryCount: 1,
2151
2252
  // biome-ignore lint/suspicious/noExplicitAny: Raw avc1 box since library doesn't handle avcC children
2152
- entries: [ci(e, n, F(s))]
2153
- }, M = {
2253
+ entries: [bi(e, n, N(s))]
2254
+ }, T = {
2154
2255
  type: "stts",
2155
2256
  version: 0,
2156
2257
  flags: 0,
2157
2258
  entryCount: 0,
2158
2259
  entries: []
2159
- }, X = It(), $ = Ot(), j = Dt(), Se = le([a, {
2260
+ }, z = Ft(), H = Nt(), P = Pt(), ke = le([o, {
2160
2261
  type: "moov",
2161
2262
  boxes: [c, {
2162
2263
  type: "trak",
2163
- boxes: [u, {
2264
+ boxes: [a, {
2164
2265
  type: "mdia",
2165
- boxes: [l, d, {
2266
+ boxes: [u, l, {
2166
2267
  type: "minf",
2167
- boxes: [f, v, {
2268
+ boxes: [d, y, {
2168
2269
  type: "stbl",
2169
2270
  // biome-ignore lint/suspicious/noExplicitAny: Raw boxes for types without library writers
2170
- boxes: [E, M, X, $, j]
2271
+ boxes: [A, T, z, H, P]
2171
2272
  }]
2172
2273
  }]
2173
2274
  }]
@@ -2177,47 +2278,47 @@ function Qe(t) {
2177
2278
  type: "trex",
2178
2279
  version: 0,
2179
2280
  flags: 0,
2180
- trackId: o,
2281
+ trackId: r,
2181
2282
  defaultSampleDescriptionIndex: 1,
2182
2283
  defaultSampleDuration: 0,
2183
2284
  defaultSampleSize: 0,
2184
2285
  defaultSampleFlags: 0
2185
2286
  }]
2186
2287
  }]
2187
- }]), he = Se.reduce((P, W) => P + W.byteLength, 0), fe = new Uint8Array(he);
2288
+ }]), fe = ke.reduce((F, j) => F + j.byteLength, 0), me = new Uint8Array(fe);
2188
2289
  let re = 0;
2189
- for (const P of Se)
2190
- fe.set(new Uint8Array(P.buffer, P.byteOffset, P.byteLength), re), re += P.byteLength;
2191
- return fe;
2290
+ for (const F of ke)
2291
+ me.set(new Uint8Array(F.buffer, F.byteOffset, F.byteLength), re), re += F.byteLength;
2292
+ return me;
2192
2293
  }
2193
- function et(t) {
2194
- const { sampleRate: e, numberOfChannels: n, description: s, codec: i, container: r } = t, o = r.kind === "cmaf" ? r.timescale : 1e6, a = r.kind === "cmaf" ? r.trackId : 1, c = {
2294
+ function Si(t) {
2295
+ const { sampleRate: e, numberOfChannels: n, description: s, codec: i } = t, r = 1e6, o = 1, c = {
2195
2296
  type: "ftyp",
2196
2297
  majorBrand: "isom",
2197
2298
  minorVersion: 512,
2198
2299
  compatibleBrands: ["isom", "iso6", "mp41"]
2199
- }, u = {
2300
+ }, a = {
2200
2301
  type: "mvhd",
2201
2302
  version: 0,
2202
2303
  flags: 0,
2203
2304
  creationTime: 0,
2204
2305
  modificationTime: 0,
2205
- timescale: o,
2306
+ timescale: r,
2206
2307
  duration: 0,
2207
2308
  rate: 65536,
2208
2309
  volume: 256,
2209
2310
  reserved1: 0,
2210
2311
  reserved2: [0, 0],
2211
- matrix: ye,
2312
+ matrix: be,
2212
2313
  preDefined: [0, 0, 0, 0, 0, 0],
2213
- nextTrackId: a + 1
2214
- }, l = {
2314
+ nextTrackId: o + 1
2315
+ }, u = {
2215
2316
  type: "tkhd",
2216
2317
  version: 0,
2217
2318
  flags: 3,
2218
2319
  creationTime: 0,
2219
2320
  modificationTime: 0,
2220
- trackId: a,
2321
+ trackId: o,
2221
2322
  reserved1: 0,
2222
2323
  duration: 0,
2223
2324
  reserved2: [0, 0],
@@ -2226,20 +2327,20 @@ function et(t) {
2226
2327
  volume: 256,
2227
2328
  // Audio tracks have volume (1.0 in 8.8 fixed point)
2228
2329
  reserved3: 0,
2229
- matrix: ye,
2330
+ matrix: be,
2230
2331
  width: 0,
2231
2332
  height: 0
2232
- }, d = {
2333
+ }, l = {
2233
2334
  type: "mdhd",
2234
2335
  version: 0,
2235
2336
  flags: 0,
2236
2337
  creationTime: 0,
2237
2338
  modificationTime: 0,
2238
- timescale: o,
2339
+ timescale: r,
2239
2340
  duration: 0,
2240
2341
  language: "und",
2241
2342
  preDefined: 0
2242
- }, f = {
2343
+ }, d = {
2243
2344
  type: "hdlr",
2244
2345
  version: 0,
2245
2346
  flags: 0,
@@ -2247,13 +2348,13 @@ function et(t) {
2247
2348
  handlerType: "soun",
2248
2349
  reserved: [0, 0, 0],
2249
2350
  name: "SoundHandler"
2250
- }, g = {
2351
+ }, f = {
2251
2352
  type: "smhd",
2252
2353
  version: 0,
2253
2354
  flags: 0,
2254
2355
  balance: 0,
2255
2356
  reserved: 0
2256
- }, A = {
2357
+ }, b = {
2257
2358
  type: "dinf",
2258
2359
  boxes: [{
2259
2360
  type: "dref",
@@ -2267,31 +2368,31 @@ function et(t) {
2267
2368
  location: ""
2268
2369
  }]
2269
2370
  }]
2270
- }, M = {
2371
+ }, T = {
2271
2372
  type: "stsd",
2272
2373
  version: 0,
2273
2374
  flags: 0,
2274
2375
  entryCount: 1,
2275
2376
  // biome-ignore lint/suspicious/noExplicitAny: Raw sample entry box
2276
- entries: [ui(i, e, n, s)]
2277
- }, X = {
2377
+ entries: [Ai(i, e, n, s)]
2378
+ }, z = {
2278
2379
  type: "stts",
2279
2380
  version: 0,
2280
2381
  flags: 0,
2281
2382
  entryCount: 0,
2282
2383
  entries: []
2283
- }, $ = It(), j = Ot(), Z = Dt(), he = le([c, {
2384
+ }, H = Ft(), P = Nt(), G = Pt(), fe = le([c, {
2284
2385
  type: "moov",
2285
- boxes: [u, {
2386
+ boxes: [a, {
2286
2387
  type: "trak",
2287
- boxes: [l, {
2388
+ boxes: [u, {
2288
2389
  type: "mdia",
2289
- boxes: [d, f, {
2390
+ boxes: [l, d, {
2290
2391
  type: "minf",
2291
- boxes: [g, A, {
2392
+ boxes: [f, b, {
2292
2393
  type: "stbl",
2293
2394
  // biome-ignore lint/suspicious/noExplicitAny: Raw boxes for types without library writers
2294
- boxes: [M, X, $, j, Z]
2395
+ boxes: [T, z, H, P, G]
2295
2396
  }]
2296
2397
  }]
2297
2398
  }]
@@ -2301,37 +2402,37 @@ function et(t) {
2301
2402
  type: "trex",
2302
2403
  version: 0,
2303
2404
  flags: 0,
2304
- trackId: a,
2405
+ trackId: o,
2305
2406
  defaultSampleDescriptionIndex: 1,
2306
2407
  defaultSampleDuration: 0,
2307
2408
  defaultSampleSize: 0,
2308
2409
  defaultSampleFlags: 0
2309
2410
  }]
2310
2411
  }]
2311
- }]), fe = he.reduce((W, qt) => W + qt.byteLength, 0), re = new Uint8Array(fe);
2312
- let P = 0;
2313
- for (const W of he)
2314
- re.set(new Uint8Array(W.buffer, W.byteOffset, W.byteLength), P), P += W.byteLength;
2412
+ }]), me = fe.reduce((j, Yt) => j + Yt.byteLength, 0), re = new Uint8Array(me);
2413
+ let F = 0;
2414
+ for (const j of fe)
2415
+ re.set(new Uint8Array(j.buffer, j.byteOffset, j.byteLength), F), F += j.byteLength;
2315
2416
  return re;
2316
2417
  }
2317
- function ui(t, e, n, s) {
2418
+ function Ai(t, e, n, s) {
2318
2419
  if (t.startsWith("mp4a"))
2319
- return li(e, n, s);
2420
+ return _i(e, n, s);
2320
2421
  if (t === "opus")
2321
- return di(e, n, s);
2422
+ return zi(e, n, s);
2322
2423
  throw new Error(`Unsupported audio codec: ${t}`);
2323
2424
  }
2324
- function li(t, e, n) {
2325
- const s = fi(t, e, n), r = 8 + (28 + s.length), o = new Uint8Array(r), a = new DataView(o.buffer);
2326
- let c = 0;
2327
- return a.setUint32(c, r, !1), c += 4, o[c++] = 109, o[c++] = 112, o[c++] = 52, o[c++] = 97, c += 6, a.setUint16(c, 1, !1), c += 2, c += 8, a.setUint16(c, e, !1), c += 2, a.setUint16(c, 16, !1), c += 2, a.setUint16(c, 0, !1), c += 2, a.setUint16(c, 0, !1), c += 2, a.setUint32(c, t * 65536, !1), c += 4, o.set(s, c), o;
2425
+ function _i(t, e, n) {
2426
+ const s = ki(t, e, n), r = 8 + (28 + s.length), o = new Uint8Array(r), c = new DataView(o.buffer);
2427
+ let a = 0;
2428
+ return c.setUint32(a, r, !1), a += 4, o[a++] = 109, o[a++] = 112, o[a++] = 52, o[a++] = 97, a += 6, c.setUint16(a, 1, !1), a += 2, a += 8, c.setUint16(a, e, !1), a += 2, c.setUint16(a, 16, !1), a += 2, c.setUint16(a, 0, !1), a += 2, c.setUint16(a, 0, !1), a += 2, c.setUint32(a, t * 65536, !1), a += 4, o.set(s, a), o;
2328
2429
  }
2329
- function di(t, e, n) {
2330
- const s = mi(e, t, n), r = 8 + (28 + s.length), o = new Uint8Array(r), a = new DataView(o.buffer);
2331
- let c = 0;
2332
- return a.setUint32(c, r, !1), c += 4, o[c++] = 79, o[c++] = 112, o[c++] = 117, o[c++] = 115, c += 6, a.setUint16(c, 1, !1), c += 2, c += 8, a.setUint16(c, e, !1), c += 2, a.setUint16(c, 16, !1), c += 2, a.setUint16(c, 0, !1), c += 2, a.setUint16(c, 0, !1), c += 2, a.setUint32(c, t * 65536, !1), c += 4, o.set(s, c), o;
2430
+ function zi(t, e, n) {
2431
+ const s = Ti(e, t, n), r = 8 + (28 + s.length), o = new Uint8Array(r), c = new DataView(o.buffer);
2432
+ let a = 0;
2433
+ return c.setUint32(a, r, !1), a += 4, o[a++] = 79, o[a++] = 112, o[a++] = 117, o[a++] = 115, a += 6, c.setUint16(a, 1, !1), a += 2, a += 8, c.setUint16(a, e, !1), a += 2, c.setUint16(a, 16, !1), a += 2, c.setUint16(a, 0, !1), a += 2, c.setUint16(a, 0, !1), a += 2, c.setUint32(a, t * 65536, !1), a += 4, o.set(s, a), o;
2333
2434
  }
2334
- function hi(t, e) {
2435
+ function Mi(t, e) {
2335
2436
  const s = {
2336
2437
  96e3: 0,
2337
2438
  88200: 1,
@@ -2349,22 +2450,22 @@ function hi(t, e) {
2349
2450
  }[t] ?? 4, r = 2 << 3 | s >> 1, o = (s & 1) << 7 | e << 3;
2350
2451
  return new Uint8Array([r, o]);
2351
2452
  }
2352
- function fi(t, e, n) {
2353
- const s = n ? F(n) : hi(t, e), i = s.length, r = 15 + i, o = 5 + r + 3, a = 14 + o, c = new Uint8Array(a), u = new DataView(c.buffer);
2453
+ function ki(t, e, n) {
2454
+ const s = n ? N(n) : Mi(t, e), i = s.length, r = 15 + i, o = 5 + r + 3, c = 14 + o, a = new Uint8Array(c), u = new DataView(a.buffer);
2354
2455
  let l = 0;
2355
- return u.setUint32(l, a, !1), l += 4, c[l++] = 101, c[l++] = 115, c[l++] = 100, c[l++] = 115, u.setUint32(l, 0, !1), l += 4, c[l++] = 3, c[l++] = o, u.setUint16(l, 0, !1), l += 2, c[l++] = 0, c[l++] = 4, c[l++] = r, c[l++] = 64, c[l++] = 21, c[l++] = 0, c[l++] = 0, c[l++] = 0, u.setUint32(l, 0, !1), l += 4, u.setUint32(l, 0, !1), l += 4, c[l++] = 5, c[l++] = i, c.set(s, l), l += i, c[l++] = 6, c[l++] = 1, c[l++] = 2, c;
2456
+ return u.setUint32(l, c, !1), l += 4, a[l++] = 101, a[l++] = 115, a[l++] = 100, a[l++] = 115, u.setUint32(l, 0, !1), l += 4, a[l++] = 3, a[l++] = o, u.setUint16(l, 0, !1), l += 2, a[l++] = 0, a[l++] = 4, a[l++] = r, a[l++] = 64, a[l++] = 21, a[l++] = 0, a[l++] = 0, a[l++] = 0, u.setUint32(l, 0, !1), l += 4, u.setUint32(l, 0, !1), l += 4, a[l++] = 5, a[l++] = i, a.set(s, l), l += i, a[l++] = 6, a[l++] = 1, a[l++] = 2, a;
2356
2457
  }
2357
- function mi(t, e, n) {
2458
+ function Ti(t, e, n) {
2358
2459
  if (n) {
2359
- const a = F(n), c = 8 + a.length, u = new Uint8Array(c);
2360
- return new DataView(u.buffer).setUint32(0, c, !1), u[4] = 100, u[5] = 79, u[6] = 112, u[7] = 115, u.set(a, 8), u;
2460
+ const c = N(n), a = 8 + c.length, u = new Uint8Array(a);
2461
+ return new DataView(u.buffer).setUint32(0, a, !1), u[4] = 100, u[5] = 79, u[6] = 112, u[7] = 115, u.set(c, 8), u;
2361
2462
  }
2362
2463
  const s = 19, i = new Uint8Array(s), r = new DataView(i.buffer);
2363
2464
  let o = 0;
2364
2465
  return r.setUint32(o, s, !1), o += 4, i[o++] = 100, i[o++] = 79, i[o++] = 112, i[o++] = 115, i[o++] = 0, i[o++] = t, r.setUint16(o, 312, !1), o += 2, r.setUint32(o, e, !1), o += 4, r.setInt16(o, 0, !1), o += 2, i[o++] = 0, i;
2365
2466
  }
2366
- function Lt(t) {
2367
- const { data: e, timestamp: n, duration: s, keyframe: i, sequence: r, trackId: o = 1 } = t, a = i ? 33554432 : 16842752, c = {
2467
+ function $t(t) {
2468
+ const { data: e, timestamp: n, duration: s, keyframe: i, sequence: r, trackId: o = 1 } = t, c = i ? 33554432 : 16842752, a = {
2368
2469
  type: "mfhd",
2369
2470
  version: 0,
2370
2471
  flags: 0,
@@ -2391,192 +2492,225 @@ function Lt(t) {
2391
2492
  {
2392
2493
  sampleDuration: s,
2393
2494
  sampleSize: e.byteLength,
2394
- sampleFlags: a
2495
+ sampleFlags: c
2395
2496
  }
2396
2497
  ]
2397
- }, g = {
2498
+ }, w = {
2398
2499
  type: "moof",
2399
- boxes: [c, {
2500
+ boxes: [a, {
2400
2501
  type: "traf",
2401
2502
  boxes: [u, l, d]
2402
2503
  }]
2403
- }, y = le([g]);
2404
- let v = 0;
2405
- for (const z of y)
2406
- v += z.byteLength;
2407
- d.dataOffset = v + 8;
2408
- const A = le([g]);
2409
- v = 0;
2410
- for (const z of A)
2411
- v += z.byteLength;
2412
- const E = new ArrayBuffer(e.byteLength), M = new Uint8Array(E);
2413
- M.set(e);
2414
- const $ = le([{
2504
+ }, y = le([w]);
2505
+ let b = 0;
2506
+ for (const M of y)
2507
+ b += M.byteLength;
2508
+ d.dataOffset = b + 8;
2509
+ const A = le([w]);
2510
+ b = 0;
2511
+ for (const M of A)
2512
+ b += M.byteLength;
2513
+ const T = new ArrayBuffer(e.byteLength), z = new Uint8Array(T);
2514
+ z.set(e);
2515
+ const P = le([{
2415
2516
  type: "mdat",
2416
- data: M
2517
+ data: z
2417
2518
  }]);
2418
- let j = 0;
2419
- for (const z of $)
2420
- j += z.byteLength;
2421
- const Z = new Uint8Array(v + j);
2422
- let V = 0;
2423
- for (const z of A)
2424
- Z.set(new Uint8Array(z.buffer, z.byteOffset, z.byteLength), V), V += z.byteLength;
2425
- for (const z of $)
2426
- Z.set(new Uint8Array(z.buffer, z.byteOffset, z.byteLength), V), V += z.byteLength;
2427
- return Z;
2428
- }
2429
- class ie {
2519
+ let G = 0;
2520
+ for (const M of P)
2521
+ G += M.byteLength;
2522
+ const X = new Uint8Array(b + G);
2523
+ let $ = 0;
2524
+ for (const M of A)
2525
+ X.set(new Uint8Array(M.buffer, M.byteOffset, M.byteLength), $), $ += M.byteLength;
2526
+ for (const M of P)
2527
+ X.set(new Uint8Array(M.buffer, M.byteOffset, M.byteLength), $), $ += M.byteLength;
2528
+ return X;
2529
+ }
2530
+ let jt = class {
2531
+ #e;
2532
+ constructor(e) {
2533
+ this.#e = e;
2534
+ }
2535
+ decode(e) {
2536
+ return wi(e, this.#e).map((n) => ({
2537
+ data: n.data,
2538
+ timestamp: n.timestamp,
2539
+ keyframe: n.keyframe
2540
+ }));
2541
+ }
2542
+ };
2543
+ class ne {
2430
2544
  #e;
2431
2545
  #t;
2432
- #n = [];
2433
- #s;
2546
+ #n;
2547
+ #s = [];
2548
+ #i;
2434
2549
  // the active group sequence number
2435
2550
  // Wake up the consumer when a new frame is available.
2436
- #i;
2437
- #r = new h([]);
2438
- buffered = this.#r;
2439
- #o = new U();
2551
+ #r;
2552
+ #a = new h([]);
2553
+ buffered = this.#a;
2554
+ #o = new E();
2440
2555
  constructor(e, n) {
2441
- this.#e = e, this.#t = h.from(n?.latency ?? _.Time.Milli.zero), this.#o.spawn(this.#a.bind(this)), this.#o.cleanup(() => {
2556
+ this.#e = e, this.#t = n.format, this.#n = h.from(n.latency ?? _.Time.Milli.zero), this.#o.spawn(this.#c.bind(this)), this.#o.cleanup(() => {
2442
2557
  this.#e.close();
2443
- for (const s of this.#n)
2558
+ for (const s of this.#s)
2444
2559
  s.consumer.close();
2445
- this.#n.length = 0;
2560
+ this.#s.length = 0;
2446
2561
  });
2447
2562
  }
2448
- async #a() {
2563
+ async #c() {
2449
2564
  for (; ; ) {
2450
2565
  const e = await this.#e.recvGroup();
2451
2566
  if (!e) break;
2452
- if (this.#s === void 0 && (this.#s = e.sequence), e.sequence < this.#s) {
2453
- console.warn(`skipping old group: ${e.sequence} < ${this.#s}`), e.close();
2567
+ if (this.#i === void 0 && (this.#i = e.sequence), e.sequence < this.#i) {
2568
+ console.warn(`skipping old group: ${e.sequence} < ${this.#i}`), e.close();
2454
2569
  continue;
2455
2570
  }
2456
2571
  const n = {
2457
2572
  consumer: e,
2458
2573
  frames: []
2459
2574
  };
2460
- this.#n.push(n), this.#n.sort((s, i) => s.consumer.sequence - i.consumer.sequence), this.#o.spawn(this.#c.bind(this, n));
2575
+ this.#s.push(n), this.#s.sort((s, i) => s.consumer.sequence - i.consumer.sequence), this.#o.spawn(this.#u.bind(this, n));
2461
2576
  }
2462
2577
  }
2463
- async #c(e) {
2578
+ async #u(e) {
2464
2579
  try {
2465
- let n = !0;
2580
+ let n = 0;
2466
2581
  for (; ; ) {
2467
2582
  const s = await e.consumer.readFrame();
2468
2583
  if (!s) break;
2469
- const { data: i, timestamp: r } = ie.#d(s), o = {
2470
- data: i,
2471
- timestamp: r,
2472
- keyframe: n
2473
- };
2474
- n = !1, e.frames.push(o), (e.latest === void 0 || r > e.latest) && (e.latest = r), this.#l(), e.consumer.sequence === this.#s ? (this.#i?.(), this.#i = void 0) : this.#u();
2584
+ const i = this.#t.decode(s);
2585
+ for (const r of i) {
2586
+ const o = {
2587
+ data: r.data,
2588
+ timestamp: r.timestamp,
2589
+ // Protocol invariant: groups always start at a keyframe.
2590
+ // For index 0, we enforce this regardless of what the format reports.
2591
+ // For index > 0, we trust the format's keyframe detection.
2592
+ keyframe: n === 0 ? !0 : r.keyframe
2593
+ };
2594
+ n++, e.frames.push(o), (e.latest === void 0 || o.timestamp > e.latest) && (e.latest = o.timestamp), this.#l(), e.consumer.sequence === this.#i ? (this.#r?.(), this.#r = void 0) : this.#d();
2595
+ }
2475
2596
  }
2476
2597
  } catch {
2477
2598
  } finally {
2478
- e.done = !0, e.consumer.sequence === this.#s && (this.#s += 1), this.#l(), this.#i?.(), this.#i = void 0, e.consumer.close();
2599
+ e.done = !0, e.consumer.sequence === this.#i && (this.#i += 1), this.#l(), this.#r?.(), this.#r = void 0, e.consumer.close();
2479
2600
  }
2480
2601
  }
2481
- #u() {
2482
- if (this.#s === void 0) return;
2602
+ #d() {
2603
+ if (this.#i === void 0) return;
2483
2604
  let e = !1;
2484
- for (; this.#n.length >= 2; ) {
2485
- const n = _.Time.Micro.fromMilli(this.#t.peek());
2605
+ for (; this.#s.length >= 2; ) {
2606
+ const n = _.Time.Micro.fromMilli(this.#n.peek());
2486
2607
  let s, i;
2487
- for (const a of this.#n) {
2488
- if (a.latest === void 0) continue;
2489
- const c = a.frames.at(0)?.timestamp ?? a.latest;
2490
- (s === void 0 || c < s) && (s = c), (i === void 0 || a.latest > i) && (i = a.latest);
2608
+ for (const c of this.#s) {
2609
+ if (c.latest === void 0) continue;
2610
+ const a = c.frames.at(0)?.timestamp ?? c.latest;
2611
+ (s === void 0 || a < s) && (s = a), (i === void 0 || c.latest > i) && (i = c.latest);
2491
2612
  }
2492
2613
  if (s === void 0 || i === void 0 || i - s <= n) break;
2493
- const o = this.#n.shift();
2614
+ const o = this.#s.shift();
2494
2615
  if (!o) break;
2495
- this.#s = this.#n[0]?.consumer.sequence, console.warn(`skipping slow group: ${o.consumer.sequence} -> ${this.#s}`), o.consumer.close(), o.frames.length = 0, e = !0;
2616
+ this.#i = this.#s[0]?.consumer.sequence, console.warn(`skipping slow group: ${o.consumer.sequence} -> ${this.#i}`), o.consumer.close(), o.frames.length = 0, e = !0;
2496
2617
  }
2497
- e && (this.#l(), this.#i?.(), this.#i = void 0);
2618
+ e && (this.#l(), this.#r?.(), this.#r = void 0);
2498
2619
  }
2499
2620
  // Returns the next frame in order, along with the group number.
2500
2621
  // If frame is undefined, the group is done.
2501
2622
  async next() {
2502
2623
  for (; ; ) {
2503
- if (this.#n.length > 0 && this.#s !== void 0 && this.#n[0].consumer.sequence <= this.#s) {
2504
- const n = this.#n[0].frames.shift();
2624
+ if (this.#s.length > 0 && this.#i !== void 0 && this.#s[0].consumer.sequence <= this.#i) {
2625
+ const n = this.#s[0].frames.shift();
2505
2626
  if (n)
2506
- return this.#l(), { frame: n, group: this.#n[0].consumer.sequence };
2507
- if (this.#s > this.#n[0].consumer.sequence || this.#n[0].done) {
2508
- this.#n[0].consumer.sequence === this.#s && (this.#s += 1);
2509
- const s = this.#n.shift();
2627
+ return this.#l(), { frame: n, group: this.#s[0].consumer.sequence };
2628
+ if (this.#i > this.#s[0].consumer.sequence || this.#s[0].done) {
2629
+ this.#s[0].consumer.sequence === this.#i && (this.#i += 1);
2630
+ const s = this.#s.shift();
2510
2631
  if (s)
2511
2632
  return this.#l(), { frame: void 0, group: s.consumer.sequence };
2512
2633
  }
2513
2634
  }
2514
- if (this.#i)
2515
- throw new Error("multiple calls to decode not supported");
2635
+ if (this.#r)
2636
+ throw new Error("multiple calls to next not supported");
2516
2637
  const e = new Promise((n) => {
2517
- this.#i = n;
2638
+ this.#r = n;
2518
2639
  }).then(() => !0);
2519
2640
  if (!await Promise.race([e, this.#o.closed])) {
2520
- this.#i = void 0;
2641
+ this.#r = void 0;
2521
2642
  return;
2522
2643
  }
2523
2644
  }
2524
2645
  }
2525
- // NOTE: A keyframe is always the first frame in a group, so it's not encoded on the wire.
2526
- static #d(e) {
2527
- const [n, s] = _.Varint.decode(e);
2528
- return { timestamp: n, data: s };
2529
- }
2530
2646
  #l() {
2531
2647
  const e = [];
2532
2648
  let n;
2533
- for (const s of this.#n) {
2649
+ for (const s of this.#s) {
2534
2650
  const i = s.frames.at(0);
2535
2651
  if (!i || s.latest === void 0) continue;
2536
- const r = _.Time.Milli.fromMicro(i.timestamp), o = _.Time.Milli.fromMicro(s.latest), a = e.at(-1), c = n?.done && n.consumer.sequence + 1 === s.consumer.sequence;
2537
- a && (a.end >= r || c) ? a.end = _.Time.Milli.max(a.end, o) : e.push({ start: r, end: o }), n = s;
2652
+ const r = _.Time.Milli.fromMicro(i.timestamp), o = _.Time.Milli.fromMicro(s.latest), c = e.at(-1), a = n?.done && n.consumer.sequence + 1 === s.consumer.sequence;
2653
+ c && (c.end >= r || a) ? c.end = _.Time.Milli.max(c.end, o) : e.push({ start: r, end: o }), n = s;
2538
2654
  }
2539
- this.#r.set(e);
2655
+ this.#a.set(e);
2540
2656
  }
2541
2657
  close() {
2542
2658
  this.#o.close();
2543
- for (const e of this.#n)
2544
- e.consumer.close(), e.frames.length = 0;
2545
- this.#n.length = 0;
2546
2659
  }
2547
2660
  }
2548
- let _e;
2549
- async function tt() {
2550
- return globalThis.AudioEncoder && globalThis.AudioDecoder ? !0 : (_e || (console.warn("using Opus polyfill; performance may be degraded"), _e = Promise.all([
2661
+ class Me {
2662
+ decode(e) {
2663
+ const [n, s] = _.Varint.decode(e);
2664
+ return [{ data: s, timestamp: n, keyframe: !1 }];
2665
+ }
2666
+ }
2667
+ function ve(t, e) {
2668
+ if (t.length === 0) return e;
2669
+ if (e.length === 0) return t;
2670
+ const n = [], s = [...t, ...e].sort((i, r) => i.start - r.start);
2671
+ for (const i of s) {
2672
+ const r = n.at(-1);
2673
+ r && r.end >= i.start ? r.end = p.Milli.max(r.end, i.end) : n.push({ ...i });
2674
+ }
2675
+ return n;
2676
+ }
2677
+ let Ue;
2678
+ async function it() {
2679
+ return globalThis.AudioEncoder && globalThis.AudioDecoder ? !0 : (Ue || (console.warn("using Opus polyfill; performance may be degraded"), Ue = Promise.all([
2551
2680
  import("./libav-opus-af-BlMWboA7.js"),
2552
2681
  import("./main-DGBFe0O7.js")
2553
2682
  ]).then(async ([t, e]) => (await e.load({
2554
2683
  LibAV: t,
2555
2684
  polyfill: !0
2556
- }), !0))), await _e);
2685
+ }), !0))), await Ue);
2686
+ }
2687
+ function he(t) {
2688
+ const e = atob(t), n = new Uint8Array(e.length);
2689
+ for (let s = 0; s < e.length; s++) n[s] = e.charCodeAt(s);
2690
+ return n;
2557
2691
  }
2558
- const q = 0, D = 1, oe = 2, K = 3, pi = 4;
2559
- function Pt(t, e, n) {
2692
+ const Z = 0, O = 1, oe = 2, K = 3, Ui = 4;
2693
+ function Zt(t, e, n) {
2560
2694
  if (t <= 0) throw new Error("invalid channels");
2561
2695
  if (e <= 0) throw new Error("invalid capacity");
2562
2696
  if (n <= 0) throw new Error("invalid sample rate");
2563
- const s = new SharedArrayBuffer(t * e * Float32Array.BYTES_PER_ELEMENT), i = new SharedArrayBuffer(pi * Int32Array.BYTES_PER_ELEMENT), r = new Int32Array(i);
2697
+ const s = new SharedArrayBuffer(t * e * Float32Array.BYTES_PER_ELEMENT), i = new SharedArrayBuffer(Ui * Int32Array.BYTES_PER_ELEMENT), r = new Int32Array(i);
2564
2698
  return Atomics.store(r, K, 1), { channels: t, capacity: e, rate: n, samples: s, control: i };
2565
2699
  }
2566
- function gi(t, e) {
2700
+ function Ei(t, e) {
2567
2701
  return (t - e | 0) > 0 ? t : e;
2568
2702
  }
2569
2703
  function ae(t, e) {
2570
2704
  return (t % e + e) % e;
2571
2705
  }
2572
- function Me(t, e, n) {
2706
+ function Ee(t, e, n) {
2573
2707
  for (; ; ) {
2574
2708
  const s = Atomics.load(t, e);
2575
2709
  if ((n - s | 0) <= 0) return s;
2576
2710
  if (Atomics.compareExchange(t, e, s, n) === s) return n;
2577
2711
  }
2578
2712
  }
2579
- class De {
2713
+ class Pe {
2580
2714
  channels;
2581
2715
  capacity;
2582
2716
  rate;
@@ -2599,31 +2733,31 @@ class De {
2599
2733
  let s = Math.round(p.Second.fromMicro(e) * this.rate);
2600
2734
  const i = n[0].length;
2601
2735
  let r = 0;
2602
- const o = s + i | 0, a = Atomics.load(this.#e, D), c = a - s | 0;
2603
- if (c > 0) {
2604
- if (c >= i)
2736
+ const o = s + i | 0, c = Atomics.load(this.#e, O), a = c - s | 0;
2737
+ if (a > 0) {
2738
+ if (a >= i)
2605
2739
  return;
2606
- r = c, s = s + c | 0;
2740
+ r = a, s = s + a | 0;
2607
2741
  }
2608
2742
  const u = i - r;
2609
- (o - a | 0) > this.capacity && Me(this.#e, D, o - this.capacity | 0);
2610
- const l = Atomics.load(this.#e, q), d = s - l | 0;
2743
+ (o - c | 0) > this.capacity && Ee(this.#e, O, o - this.capacity | 0);
2744
+ const l = Atomics.load(this.#e, Z), d = s - l | 0;
2611
2745
  if (d > 0) {
2612
- const v = Math.min(d, this.capacity);
2746
+ const b = Math.min(d, this.capacity);
2613
2747
  for (let A = 0; A < this.channels; A++) {
2614
- const E = this.#t[A];
2615
- for (let M = 0; M < v; M++)
2616
- E[ae(l + M | 0, this.capacity)] = 0;
2748
+ const T = this.#t[A];
2749
+ for (let z = 0; z < b; z++)
2750
+ T[ae(l + z | 0, this.capacity)] = 0;
2617
2751
  }
2618
2752
  }
2619
- for (let v = 0; v < this.channels; v++) {
2620
- const A = n[v], E = this.#t[v];
2621
- for (let M = 0; M < u; M++)
2622
- E[ae(s + M | 0, this.capacity)] = A[r + M];
2753
+ for (let b = 0; b < this.channels; b++) {
2754
+ const A = n[b], T = this.#t[b];
2755
+ for (let z = 0; z < u; z++)
2756
+ T[ae(s + z | 0, this.capacity)] = A[r + z];
2623
2757
  }
2624
- Atomics.store(this.#e, q, gi(Atomics.load(this.#e, q), o));
2625
- const f = Atomics.load(this.#e, D), g = Atomics.load(this.#e, q), y = Atomics.load(this.#e, oe);
2626
- (g - f | 0) >= y && y > 0 && Atomics.store(this.#e, K, 0);
2758
+ Atomics.store(this.#e, Z, Ei(Atomics.load(this.#e, Z), o));
2759
+ const f = Atomics.load(this.#e, O), w = Atomics.load(this.#e, Z), y = Atomics.load(this.#e, oe);
2760
+ (w - f | 0) >= y && y > 0 && Atomics.store(this.#e, K, 0);
2627
2761
  }
2628
2762
  /**
2629
2763
  * Read audio samples into the output buffers.
@@ -2631,20 +2765,20 @@ class De {
2631
2765
  */
2632
2766
  read(e) {
2633
2767
  if (Atomics.load(this.#e, K) === 1) return 0;
2634
- let n = Atomics.load(this.#e, D);
2635
- const s = Atomics.load(this.#e, q), i = Atomics.load(this.#e, oe), r = s - n | 0;
2768
+ let n = Atomics.load(this.#e, O);
2769
+ const s = Atomics.load(this.#e, Z), i = Atomics.load(this.#e, oe), r = s - n | 0;
2636
2770
  if (i > 0 && r > i) {
2637
- const c = s - i | 0;
2638
- n = Me(this.#e, D, c);
2771
+ const a = s - i | 0;
2772
+ n = Ee(this.#e, O, a);
2639
2773
  }
2640
- const o = s - n | 0, a = Math.min(o, e[0].length);
2641
- if (a <= 0) return 0;
2642
- for (let c = 0; c < this.channels; c++) {
2643
- const u = this.#t[c], l = e[c];
2644
- for (let d = 0; d < a; d++)
2774
+ const o = s - n | 0, c = Math.min(o, e[0].length);
2775
+ if (c <= 0) return 0;
2776
+ for (let a = 0; a < this.channels; a++) {
2777
+ const u = this.#t[a], l = e[a];
2778
+ for (let d = 0; d < c; d++)
2645
2779
  l[d] = u[ae(n + d | 0, this.capacity)];
2646
2780
  }
2647
- return Me(this.#e, D, n + a | 0), a;
2781
+ return Ee(this.#e, O, n + c | 0), c;
2648
2782
  }
2649
2783
  /** Update the target latency in samples. */
2650
2784
  setLatency(e) {
@@ -2663,19 +2797,19 @@ class De {
2663
2797
  * by READ/WRITE elsewhere.
2664
2798
  */
2665
2799
  resize(e) {
2666
- const n = Pt(this.channels, e, this.rate), s = new De(n), i = Atomics.load(this.#e, D), r = Atomics.load(this.#e, q), o = Atomics.load(this.#e, oe), a = Atomics.load(this.#e, K), c = r - i | 0, u = Math.max(0, Math.min(c, s.capacity)), l = r - u | 0;
2800
+ const n = Zt(this.channels, e, this.rate), s = new Pe(n), i = Atomics.load(this.#e, O), r = Atomics.load(this.#e, Z), o = Atomics.load(this.#e, oe), c = Atomics.load(this.#e, K), a = r - i | 0, u = Math.max(0, Math.min(a, s.capacity)), l = r - u | 0;
2667
2801
  for (let d = 0; d < this.channels; d++) {
2668
- const f = this.#t[d], g = s.#t[d];
2802
+ const f = this.#t[d], w = s.#t[d];
2669
2803
  for (let y = 0; y < u; y++) {
2670
- const v = l + y | 0;
2671
- g[ae(v, s.capacity)] = f[ae(v, this.capacity)];
2804
+ const b = l + y | 0;
2805
+ w[ae(b, s.capacity)] = f[ae(b, this.capacity)];
2672
2806
  }
2673
2807
  }
2674
- return Atomics.store(s.#e, D, l), Atomics.store(s.#e, q, r), Atomics.store(s.#e, oe, o), Atomics.store(s.#e, K, a), s;
2808
+ return Atomics.store(s.#e, O, l), Atomics.store(s.#e, Z, r), Atomics.store(s.#e, oe, o), Atomics.store(s.#e, K, c), s;
2675
2809
  }
2676
2810
  /** Current playback timestamp derived from READ position. */
2677
2811
  get timestamp() {
2678
- const e = Atomics.load(this.#e, D);
2812
+ const e = Atomics.load(this.#e, O);
2679
2813
  return p.Micro.fromSecond(e / this.rate);
2680
2814
  }
2681
2815
  /** Whether the buffer is stalled (waiting to fill). */
@@ -2690,16 +2824,16 @@ class De {
2690
2824
  * tests and diagnostics, not control-flow decisions.
2691
2825
  */
2692
2826
  get length() {
2693
- return Atomics.load(this.#e, q) - Atomics.load(this.#e, D) | 0;
2827
+ return Atomics.load(this.#e, Z) - Atomics.load(this.#e, O) | 0;
2694
2828
  }
2695
2829
  }
2696
- function wi() {
2830
+ function xi() {
2697
2831
  return !(typeof SharedArrayBuffer > "u" || typeof crossOriginIsolated < "u" && !crossOriginIsolated);
2698
2832
  }
2699
- function yi(t, e, n, s) {
2700
- return wi() ? (console.log("[audio] using SharedArrayBuffer audio buffer"), new vi(t, e, n, s)) : (console.log("[audio] using postMessage audio buffer (SharedArrayBuffer unavailable)"), new bi(t, e, n, s));
2833
+ function Bi(t, e, n, s) {
2834
+ return xi() ? (console.log("[audio] using SharedArrayBuffer audio buffer"), new Ri(t, e, n, s)) : (console.log("[audio] using postMessage audio buffer (SharedArrayBuffer unavailable)"), new Ci(t, e, n, s));
2701
2835
  }
2702
- class vi {
2836
+ class Ri {
2703
2837
  rate;
2704
2838
  channels;
2705
2839
  #e;
@@ -2708,13 +2842,13 @@ class vi {
2708
2842
  timestamp = this.#n;
2709
2843
  #s = new h(!0);
2710
2844
  stalled = this.#s;
2711
- #i = new U();
2845
+ #i = new E();
2712
2846
  constructor(e, n, s, i) {
2713
2847
  this.#e = e, this.channels = n, this.rate = s;
2714
- const r = Math.max(s, i * 2), o = Pt(n, r, s);
2715
- this.#t = new De(o), this.#t.setLatency(i);
2716
- const a = { type: "init-shared", ...o };
2717
- e.port.postMessage(a), this.#i.interval(() => {
2848
+ const r = Math.max(s, i * 2), o = Zt(n, r, s);
2849
+ this.#t = new Pe(o), this.#t.setLatency(i);
2850
+ const c = { type: "init-shared", ...o };
2851
+ e.port.postMessage(c), this.#i.interval(() => {
2718
2852
  this.#n.set(this.#t.timestamp), this.#s.set(this.#t.stalled);
2719
2853
  }, 50);
2720
2854
  }
@@ -2734,7 +2868,7 @@ class vi {
2734
2868
  this.#i.close();
2735
2869
  }
2736
2870
  }
2737
- class bi {
2871
+ class Ci {
2738
2872
  rate;
2739
2873
  channels;
2740
2874
  #e;
@@ -2742,13 +2876,13 @@ class bi {
2742
2876
  timestamp = this.#t;
2743
2877
  #n = new h(!0);
2744
2878
  stalled = this.#n;
2745
- #s = new U();
2879
+ #s = new E();
2746
2880
  constructor(e, n, s, i) {
2747
2881
  this.#e = e, this.channels = n, this.rate = s;
2748
2882
  const r = p.Milli.fromSecond(i / s), o = { type: "init-post", channels: n, rate: s, latency: r };
2749
- e.port.postMessage(o), this.#s.event(e.port, "message", (a) => {
2750
- const c = a.data;
2751
- c?.type === "state" && (this.#t.set(c.timestamp), this.#n.set(c.stalled));
2883
+ e.port.postMessage(o), this.#s.event(e.port, "message", (c) => {
2884
+ const a = c.data;
2885
+ a?.type === "state" && (this.#t.set(a.timestamp), this.#n.set(a.stalled));
2752
2886
  }), e.port.start();
2753
2887
  }
2754
2888
  insert(e, n) {
@@ -2766,7 +2900,7 @@ class bi {
2766
2900
  this.#s.close();
2767
2901
  }
2768
2902
  }
2769
- const Si = `var __defProp = Object.defineProperty;
2903
+ const Ii = `var __defProp = Object.defineProperty;
2770
2904
  var __getOwnPropNames = Object.getOwnPropertyNames;
2771
2905
  var __esm = (fn, res) => function __init() {
2772
2906
  return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
@@ -3237,8 +3371,8 @@ var Render = class extends AudioWorkletProcessor {
3237
3371
  }
3238
3372
  };
3239
3373
  registerProcessor("render", Render);
3240
- `, Ai = new Blob([Si], { type: "application/javascript" }), _i = URL.createObjectURL(Ai);
3241
- let Mi = class {
3374
+ `, Di = new Blob([Ii], { type: "application/javascript" }), Oi = URL.createObjectURL(Di);
3375
+ let Li = class {
3242
3376
  source;
3243
3377
  enabled;
3244
3378
  #e = new h(void 0);
@@ -3258,15 +3392,15 @@ let Mi = class {
3258
3392
  #r = new h(!0);
3259
3393
  stalled = this.#r;
3260
3394
  // Decode buffer: audio sent to worklet but not yet played
3261
- #o = new h([]);
3262
- // Combined buffered ranges (network jitter + decode buffer)
3263
3395
  #a = new h([]);
3264
- buffered = this.#a;
3396
+ // Combined buffered ranges (network jitter + decode buffer)
3397
+ #o = new h([]);
3398
+ buffered = this.#o;
3265
3399
  // Audio ring bridging main thread and worklet (shared memory or postMessage transport).
3266
3400
  #c;
3267
- #u = new U();
3401
+ #u = new E();
3268
3402
  constructor(e, n) {
3269
- this.source = e, this.source.supported.set(zi), this.enabled = h.from(n?.enabled ?? !1), this.#u.run(this.#d.bind(this)), this.#u.run(this.#l.bind(this)), this.#u.run(this.#f.bind(this)), this.#u.run(this.#m.bind(this));
3403
+ this.source = e, this.source.supported.set(Fi), this.enabled = h.from(n?.enabled ?? !1), this.#u.run(this.#d.bind(this)), this.#u.run(this.#l.bind(this)), this.#u.run(this.#f.bind(this)), this.#u.run(this.#m.bind(this));
3270
3404
  }
3271
3405
  #d(e) {
3272
3406
  const n = e.get(this.source.config);
@@ -3277,14 +3411,14 @@ let Mi = class {
3277
3411
  sampleRate: s
3278
3412
  });
3279
3413
  e.set(this.#e, r), e.cleanup(() => r.close()), e.spawn(async () => {
3280
- if (await r.audioWorklet.addModule(_i), r.state === "closed") return;
3414
+ if (await r.audioWorklet.addModule(Oi), r.state === "closed") return;
3281
3415
  const o = new AudioWorkletNode(r, "render", {
3282
3416
  channelCount: i,
3283
3417
  channelCountMode: "explicit",
3284
3418
  outputChannelCount: [i]
3285
3419
  });
3286
3420
  e.cleanup(() => o.disconnect());
3287
- const a = this.source.sync.buffer.peek(), c = Math.ceil(s * p.Second.fromMilli(a)), u = yi(o, i, s, c);
3421
+ const c = this.source.sync.buffer.peek(), a = Math.ceil(s * p.Second.fromMilli(c)), u = Bi(o, i, s, a);
3288
3422
  this.#c = u, e.cleanup(() => {
3289
3423
  u.close(), this.#c = void 0;
3290
3424
  }), e.run((l) => {
@@ -3318,20 +3452,21 @@ let Mi = class {
3318
3452
  if (!r) return;
3319
3453
  const o = e.get(s.active);
3320
3454
  if (!o) return;
3321
- const a = o.subscribe(i, ee.audio);
3322
- e.cleanup(() => a.close()), r.container.kind === "cmaf" ? this.#g(e, a, r) : this.#p(e, a, r);
3455
+ const c = o.subscribe(i, ee.audio);
3456
+ e.cleanup(() => c.close()), r.container.kind === "cmaf" ? this.#g(e, c, r) : this.#p(e, c, r);
3323
3457
  }
3324
3458
  #p(e, n, s) {
3325
- const i = new ie(n, {
3459
+ const i = new ne(n, {
3460
+ format: new Me(),
3326
3461
  latency: this.source.sync.buffer
3327
3462
  });
3328
3463
  e.cleanup(() => i.close()), e.run((r) => {
3329
- const o = r.get(i.buffered), a = r.get(this.#o);
3330
- this.#a.update(() => ki(o, a));
3464
+ const o = r.get(i.buffered), c = r.get(this.#a);
3465
+ this.#o.update(() => ve(o, c));
3331
3466
  }), e.spawn(async () => {
3332
- if (!await tt()) return;
3467
+ if (!await it()) return;
3333
3468
  let o = 0;
3334
- const a = new AudioDecoder({
3469
+ const c = new AudioDecoder({
3335
3470
  output: (u) => {
3336
3471
  if (o++, o <= 3) {
3337
3472
  u.close();
@@ -3342,75 +3477,68 @@ let Mi = class {
3342
3477
  error: (u) => console.error(u)
3343
3478
  });
3344
3479
  e.cleanup(() => {
3345
- a.state !== "closed" && a.close();
3480
+ c.state !== "closed" && c.close();
3346
3481
  });
3347
- const c = s.description ? F(s.description) : void 0;
3348
- for (a.configure({
3482
+ const a = s.codec === "opus" ? void 0 : s.description ? N(s.description) : void 0;
3483
+ for (c.configure({
3349
3484
  ...s,
3350
- description: c
3485
+ description: a
3351
3486
  }); ; ) {
3352
3487
  const u = await i.next();
3353
3488
  if (!u) break;
3354
3489
  const { frame: l } = u;
3355
3490
  if (!l) continue;
3356
3491
  const d = p.Milli.fromMicro(l.timestamp);
3357
- this.source.sync.received(d, "audio"), this.#s.update((g) => ({
3358
- bytesReceived: (g?.bytesReceived ?? 0) + l.data.byteLength
3492
+ this.source.sync.received(d, "audio"), this.#s.update((w) => ({
3493
+ bytesReceived: (w?.bytesReceived ?? 0) + l.data.byteLength
3359
3494
  }));
3360
3495
  const f = new EncodedAudioChunk({
3361
3496
  type: l.keyframe ? "key" : "delta",
3362
3497
  data: l.data,
3363
3498
  timestamp: l.timestamp
3364
3499
  });
3365
- a.decode(f);
3500
+ c.decode(f);
3366
3501
  }
3367
3502
  });
3368
3503
  }
3369
3504
  #g(e, n, s) {
3370
3505
  if (s.container.kind !== "cmaf") return;
3371
- const { timescale: i } = s.container, r = s.description ? F(s.description) : void 0;
3372
- e.run((o) => {
3373
- const a = o.get(this.#o);
3374
- this.#a.update(() => a);
3506
+ const i = he(s.container.init), r = ze(i), o = s.codec === "opus" ? void 0 : s.description ? N(s.description) : void 0, c = new ne(n, {
3507
+ format: new jt(r),
3508
+ latency: this.source.sync.buffer
3509
+ });
3510
+ e.cleanup(() => c.close()), e.run((a) => {
3511
+ const u = a.get(c.buffered), l = a.get(this.#a);
3512
+ this.#o.update(() => ve(u, l));
3375
3513
  }), e.spawn(async () => {
3376
- if (!await tt()) return;
3377
- const a = new AudioDecoder({
3378
- output: (c) => this.#h(c),
3379
- error: (c) => console.error(c)
3514
+ if (!await it()) return;
3515
+ const u = new AudioDecoder({
3516
+ output: (l) => this.#h(l),
3517
+ error: (l) => console.error(l)
3380
3518
  });
3381
3519
  for (e.cleanup(() => {
3382
- a.state !== "closed" && a.close();
3383
- }), a.configure({
3520
+ u.state !== "closed" && u.close();
3521
+ }), u.configure({
3384
3522
  codec: s.codec,
3385
3523
  sampleRate: s.sampleRate,
3386
3524
  numberOfChannels: s.numberOfChannels,
3387
- description: r
3525
+ description: o
3388
3526
  }); ; ) {
3389
- const c = await n.recvGroup();
3390
- if (!c) break;
3391
- e.spawn(async () => {
3392
- try {
3393
- for (; ; ) {
3394
- const u = await c.readFrame();
3395
- if (!u) break;
3396
- const l = Ct(u, i);
3397
- for (const d of l) {
3398
- const f = p.Milli.fromMicro(d.timestamp);
3399
- this.source.sync.received(f, "audio"), this.#s.update((y) => ({
3400
- bytesReceived: (y?.bytesReceived ?? 0) + d.data.byteLength
3401
- }));
3402
- const g = new EncodedAudioChunk({
3403
- type: d.keyframe ? "key" : "delta",
3404
- data: d.data,
3405
- timestamp: d.timestamp
3406
- });
3407
- a.decode(g);
3408
- }
3409
- }
3410
- } finally {
3411
- c.close();
3412
- }
3413
- });
3527
+ const l = await Promise.race([c.next(), e.cancel]);
3528
+ if (!l) break;
3529
+ const { frame: d } = l;
3530
+ if (!d) continue;
3531
+ const f = p.Milli.fromMicro(d.timestamp);
3532
+ if (this.source.sync.received(f, "audio"), this.#s.update((w) => ({
3533
+ bytesReceived: (w?.bytesReceived ?? 0) + d.data.byteLength
3534
+ })), u.state === "closed") break;
3535
+ u.decode(
3536
+ new EncodedAudioChunk({
3537
+ type: d.keyframe ? "key" : "delta",
3538
+ data: d.data,
3539
+ timestamp: d.timestamp
3540
+ })
3541
+ );
3414
3542
  }
3415
3543
  });
3416
3544
  }
@@ -3420,17 +3548,17 @@ let Mi = class {
3420
3548
  e.close();
3421
3549
  return;
3422
3550
  }
3423
- const r = e.numberOfFrames / e.sampleRate * 1e6, o = p.Milli.fromMicro(r), a = p.Milli.add(s, o);
3424
- this.#w(s, a);
3425
- const c = Math.min(e.numberOfChannels, i.channels), u = [];
3426
- for (let l = 0; l < c; l++) {
3551
+ const r = e.numberOfFrames / e.sampleRate * 1e6, o = p.Milli.fromMicro(r), c = p.Milli.add(s, o);
3552
+ this.#w(s, c);
3553
+ const a = Math.min(e.numberOfChannels, i.channels), u = [];
3554
+ for (let l = 0; l < a; l++) {
3427
3555
  const d = new Float32Array(e.numberOfFrames);
3428
3556
  e.copyTo(d, { format: "f32-planar", planeIndex: l }), u.push(d);
3429
3557
  }
3430
3558
  i.insert(n, u), e.close();
3431
3559
  }
3432
3560
  #w(e, n) {
3433
- e > n || this.#o.mutate((s) => {
3561
+ e > n || this.#a.mutate((s) => {
3434
3562
  for (const i of s)
3435
3563
  if (e <= i.end + 1 && n >= i.start) {
3436
3564
  i.start = p.Milli.min(i.start, e), i.end = p.Milli.max(i.end, n);
@@ -3440,7 +3568,7 @@ let Mi = class {
3440
3568
  });
3441
3569
  }
3442
3570
  #y(e) {
3443
- this.#o.mutate((n) => {
3571
+ this.#a.mutate((n) => {
3444
3572
  for (; n.length > 0; ) {
3445
3573
  if (n[0].end >= e) {
3446
3574
  n[0].start = p.Milli.max(n[0].start, e);
@@ -3454,32 +3582,22 @@ let Mi = class {
3454
3582
  this.#u.close();
3455
3583
  }
3456
3584
  };
3457
- async function zi(t) {
3458
- const e = t.description ? F(t.description) : void 0;
3585
+ async function Fi(t) {
3586
+ const e = t.codec === "opus" ? void 0 : t.description ? N(t.description) : void 0;
3459
3587
  return (await AudioDecoder.isConfigSupported({
3460
3588
  ...t,
3461
3589
  description: e
3462
3590
  })).supported ?? !1;
3463
3591
  }
3464
- function ki(t, e) {
3465
- if (t.length === 0) return e;
3466
- if (e.length === 0) return t;
3467
- const n = [], s = [...t, ...e].sort((i, r) => i.start - r.start);
3468
- for (const i of s) {
3469
- const r = n.at(-1);
3470
- r && r.end >= i.start ? r.end = p.Milli.max(r.end, i.end) : n.push({ ...i });
3471
- }
3472
- return n;
3473
- }
3474
- const nt = 1e-3, ze = 0.2;
3475
- class Ti {
3592
+ const rt = 1e-3, xe = 0.2;
3593
+ class Ni {
3476
3594
  source;
3477
3595
  volume;
3478
3596
  muted;
3479
3597
  // Similar to muted, but controls whether we download audio at all.
3480
3598
  // That way we can be "muted" but also download audio for visualizations.
3481
3599
  paused;
3482
- #e = new U();
3600
+ #e = new E();
3483
3601
  // The volume to use when unmuted.
3484
3602
  #t = 0.5;
3485
3603
  // The gain node used to adjust the volume.
@@ -3505,22 +3623,22 @@ class Ti {
3505
3623
  if (!i) return;
3506
3624
  s.cleanup(() => i.gain.cancelScheduledValues(i.context.currentTime));
3507
3625
  const r = s.get(this.volume);
3508
- r < nt ? (i.gain.exponentialRampToValueAtTime(nt, i.context.currentTime + ze), i.gain.setValueAtTime(0, i.context.currentTime + ze + 0.01)) : i.gain.exponentialRampToValueAtTime(r, i.context.currentTime + ze);
3626
+ r < rt ? (i.gain.exponentialRampToValueAtTime(rt, i.context.currentTime + xe), i.gain.setValueAtTime(0, i.context.currentTime + xe + 0.01)) : i.gain.exponentialRampToValueAtTime(r, i.context.currentTime + xe);
3509
3627
  });
3510
3628
  }
3511
3629
  close() {
3512
3630
  this.#e.close();
3513
3631
  }
3514
3632
  }
3515
- class Nt {
3633
+ class Vt {
3516
3634
  element;
3517
3635
  paused;
3518
3636
  #e;
3519
3637
  #t = new h(void 0);
3520
3638
  mediaSource = this.#t;
3521
- #n = new U();
3639
+ #n = new E();
3522
3640
  constructor(e, n) {
3523
- this.element = h.from(n?.element), this.paused = h.from(n?.paused ?? !1), this.#e = e, this.#n.run(this.#s.bind(this)), this.#n.run(this.#i.bind(this)), this.#n.run(this.#r.bind(this)), this.#n.run(this.#o.bind(this)), this.#n.run(this.#a.bind(this));
3641
+ this.element = h.from(n?.element), this.paused = h.from(n?.paused ?? !1), this.#e = e, this.#n.run(this.#s.bind(this)), this.#n.run(this.#i.bind(this)), this.#n.run(this.#r.bind(this)), this.#n.run(this.#a.bind(this)), this.#n.run(this.#o.bind(this));
3524
3642
  }
3525
3643
  #s(e) {
3526
3644
  const n = e.get(this.element);
@@ -3544,8 +3662,8 @@ class Nt {
3544
3662
  e.interval(() => {
3545
3663
  const r = n.buffered;
3546
3664
  if (r.length === 0) return;
3547
- const a = r.end(r.length - 1) - i, c = a - n.currentTime;
3548
- (c > 0.1 || c < -0.1) && (console.warn("seeking", c > 0 ? "forward" : "backward", Math.abs(c).toFixed(3), "seconds"), n.currentTime = a);
3665
+ const c = r.end(r.length - 1) - i, a = c - n.currentTime;
3666
+ (a > 0.1 || a < -0.1) && (console.warn("seeking", a > 0 ? "forward" : "backward", Math.abs(a).toFixed(3), "seconds"), n.currentTime = c);
3549
3667
  }, 100);
3550
3668
  }
3551
3669
  #r(e) {
@@ -3560,7 +3678,7 @@ class Nt {
3560
3678
  }
3561
3679
  }, 1e3);
3562
3680
  }
3563
- #o(e) {
3681
+ #a(e) {
3564
3682
  const n = e.get(this.element);
3565
3683
  if (!n) return;
3566
3684
  const s = e.get(this.paused);
@@ -3569,7 +3687,7 @@ class Nt {
3569
3687
  });
3570
3688
  }
3571
3689
  // Seek to the target position based on the reference and latency.
3572
- #a(e) {
3690
+ #o(e) {
3573
3691
  const n = e.get(this.element);
3574
3692
  if (!n || e.get(this.paused)) return;
3575
3693
  const i = e.get(this.#e.reference);
@@ -3581,11 +3699,11 @@ class Nt {
3581
3699
  this.#n.close();
3582
3700
  }
3583
3701
  }
3584
- const lr = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
3702
+ const Ar = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
3585
3703
  __proto__: null,
3586
- Muxer: Nt
3587
- }, Symbol.toStringTag, { value: "Module" })), Ui = 20, st = 100;
3588
- class Le {
3704
+ Muxer: Vt
3705
+ }, Symbol.toStringTag, { value: "Module" })), Pi = 20, ot = 100;
3706
+ class $e {
3589
3707
  // The earliest time we've received a frame, relative to its timestamp.
3590
3708
  // This will keep being updated as we catch up to the live playhead then will be relatively static.
3591
3709
  #e = new h(void 0);
@@ -3609,31 +3727,29 @@ class Le {
3609
3727
  timestamp = new h(void 0);
3610
3728
  // Per-label late-frame tracking: accumulate count and max lateness, flush on recovery.
3611
3729
  #s = /* @__PURE__ */ new Map();
3612
- // RTT signal from the connection (PROBE or getStats).
3613
- rtt;
3730
+ // The connection used for "real-time" jitter: PROBE supplies RTT.
3731
+ #i;
3614
3732
  // Minimum RTT seen, used as the baseline for jitter calculation.
3615
3733
  // Avoids inflating jitter due to bufferbloat.
3616
- #i;
3617
- signals = new U();
3734
+ #r;
3735
+ signals = new E();
3618
3736
  constructor(e) {
3619
- this.latency = h.from(e?.latency ?? "real-time"), this.jitter = new h(st), this.rtt = e?.rtt, this.audio = h.from(e?.audio), this.video = h.from(e?.video), this.#n = Promise.withResolvers(), this.signals.run(this.#r.bind(this)), this.signals.run(this.#o.bind(this));
3737
+ this.latency = h.from(e?.latency ?? "real-time"), this.jitter = new h(ot), this.#i = e?.connection, this.audio = h.from(e?.audio), this.video = h.from(e?.video), this.#n = Promise.withResolvers(), this.signals.run(this.#a.bind(this)), this.signals.run(this.#o.bind(this));
3620
3738
  }
3621
- #r(e) {
3739
+ #a(e) {
3622
3740
  const n = e.get(this.latency);
3623
3741
  if (typeof n == "number") {
3624
- this.#i = void 0, this.jitter.set(n);
3742
+ this.#r = void 0, this.jitter.set(n);
3625
3743
  return;
3626
3744
  }
3627
- if (this.rtt) {
3628
- const s = e.get(this.rtt);
3629
- if (s !== void 0) {
3630
- this.#i = this.#i !== void 0 ? Math.min(this.#i, s) : s;
3631
- const i = Math.max(Ui, this.#i * 1.25);
3632
- this.jitter.set(i);
3633
- return;
3634
- }
3745
+ const i = (this.#i ? e.get(this.#i) : void 0)?.rtt, r = i ? e.get(i) : void 0;
3746
+ if (r !== void 0) {
3747
+ this.#r = this.#r !== void 0 ? Math.min(this.#r, r) : r;
3748
+ const o = Math.max(Pi, this.#r * 1.25);
3749
+ this.jitter.set(o);
3750
+ return;
3635
3751
  }
3636
- this.#i = void 0, this.jitter.set(st);
3752
+ this.#r = void 0, this.jitter.set(ot);
3637
3753
  }
3638
3754
  #o(e) {
3639
3755
  const n = e.get(this.jitter), s = e.get(this.video) ?? p.Milli.zero, i = e.get(this.audio) ?? p.Milli.zero, r = p.Milli.add(p.Milli.max(s, i), n);
@@ -3646,13 +3762,13 @@ class Le {
3646
3762
  if (r !== void 0) {
3647
3763
  const o = p.Milli.add(p.Milli.sub(r, i), this.#t.peek());
3648
3764
  if (o < 0) {
3649
- const a = this.#s.get(n);
3650
- a ? (a.count++, a.maxMs = Math.max(a.maxMs, -o)) : this.#s.set(n, { count: 1, maxMs: -o });
3765
+ const c = this.#s.get(n);
3766
+ c ? (c.count++, c.maxMs = Math.max(c.maxMs, -o)) : this.#s.set(n, { count: 1, maxMs: -o });
3651
3767
  } else {
3652
- const a = this.#s.get(n);
3653
- if (a) {
3654
- const c = n ? `sync[${n}]` : "sync", u = Le.#a(a.maxMs);
3655
- console.debug(`${c}: ${a.count} late frame(s), max ${u} behind`), this.#s.delete(n);
3768
+ const c = this.#s.get(n);
3769
+ if (c) {
3770
+ const a = n ? `sync[${n}]` : "sync", u = $e.#c(c.maxMs);
3771
+ console.debug(`${a}: ${c.count} late frame(s), max ${u} behind`), this.#s.delete(n);
3656
3772
  }
3657
3773
  }
3658
3774
  if (i >= r)
@@ -3676,11 +3792,11 @@ class Le {
3676
3792
  if (r === void 0) return;
3677
3793
  const o = p.Milli.add(p.Milli.sub(r, i), this.#t.peek());
3678
3794
  if (o <= 0 || o < 5) return;
3679
- const a = new Promise((u) => setTimeout(u, o)).then(() => !0);
3680
- if (await Promise.race([this.#n.promise, a])) return;
3795
+ const c = new Promise((u) => setTimeout(u, o)).then(() => !0);
3796
+ if (await Promise.race([this.#n.promise, c])) return;
3681
3797
  }
3682
3798
  }
3683
- static #a(e) {
3799
+ static #c(e) {
3684
3800
  if (e = Math.round(e), e < 1e3) return `${e}ms`;
3685
3801
  const n = e / 1e3;
3686
3802
  if (n < 60) return `${Math.round(n * 10) / 10}s`;
@@ -3691,8 +3807,8 @@ class Le {
3691
3807
  this.signals.close();
3692
3808
  }
3693
3809
  }
3694
- const Ei = 500, xi = 100;
3695
- class Ri {
3810
+ const $i = 500, ji = 100;
3811
+ class Zi {
3696
3812
  enabled;
3697
3813
  // Don't download any longer
3698
3814
  source;
@@ -3712,11 +3828,11 @@ class Ri {
3712
3828
  #r = new h(void 0);
3713
3829
  stats = this.#r;
3714
3830
  // Combined buffered ranges (network jitter + decode buffer)
3715
- #o = new h([]);
3716
- buffered = this.#o;
3717
- #a = new U();
3831
+ #a = new h([]);
3832
+ buffered = this.#a;
3833
+ #o = new E();
3718
3834
  constructor(e, n) {
3719
- this.enabled = h.from(n?.enabled ?? !1), this.source = e, this.source.supported.set(Ii), this.#a.run(this.#c.bind(this)), this.#a.run(this.#u.bind(this)), this.#a.run(this.#d.bind(this)), this.#a.run(this.#l.bind(this));
3835
+ this.enabled = h.from(n?.enabled ?? !1), this.source = e, this.source.supported.set(Wi), this.#o.run(this.#c.bind(this)), this.#o.run(this.#u.bind(this)), this.#o.run(this.#d.bind(this)), this.#o.run(this.#l.bind(this));
3720
3836
  }
3721
3837
  #c(e) {
3722
3838
  const n = e.getAll([this.enabled, this.source.broadcast, this.source.track, this.source.config]);
@@ -3724,35 +3840,35 @@ class Ri {
3724
3840
  this.#e.set(void 0);
3725
3841
  return;
3726
3842
  }
3727
- const [s, i, r, o] = n, a = e.get(i.active);
3728
- if (!a) return;
3729
- let c = new Bi({
3843
+ const [s, i, r, o] = n, c = e.get(i.active);
3844
+ if (!c) return;
3845
+ let a = new Vi({
3730
3846
  source: this.source,
3731
- broadcast: a,
3847
+ broadcast: c,
3732
3848
  track: r,
3733
3849
  config: o,
3734
3850
  stats: this.#r
3735
3851
  });
3736
- e.cleanup(() => c?.close()), e.run((u) => {
3737
- if (!c) return;
3852
+ e.cleanup(() => a?.close()), e.run((u) => {
3853
+ if (!a) return;
3738
3854
  const l = u.get(this.#e);
3739
3855
  if (l) {
3740
- const d = u.get(c.timestamp), f = u.get(l.timestamp);
3741
- if (!d || f && f > d + xi) return;
3856
+ const d = u.get(a.timestamp), f = u.get(l.timestamp);
3857
+ if (!d || f && f > d + ji) return;
3742
3858
  }
3743
- this.#e.set(c), c = void 0, u.close();
3859
+ this.#e.set(a), a = void 0, u.close();
3744
3860
  });
3745
3861
  }
3746
3862
  #u(e) {
3747
3863
  const n = e.get(this.#e);
3748
3864
  if (!n) {
3749
- this.#o.set([]);
3865
+ this.#a.set([]);
3750
3866
  return;
3751
3867
  }
3752
3868
  e.cleanup(() => n.close()), e.run((s) => {
3753
3869
  const i = s.get(n.frame);
3754
3870
  this.#t.update((r) => (r?.close(), i?.clone()));
3755
- }), e.proxy(this.#n, n.timestamp), e.proxy(this.#o, n.buffered);
3871
+ }), e.proxy(this.#n, n.timestamp), e.proxy(this.#a, n.buffered);
3756
3872
  }
3757
3873
  #d(e) {
3758
3874
  const n = e.get(this.source.catalog);
@@ -3779,15 +3895,15 @@ class Ri {
3779
3895
  }
3780
3896
  this.#i.set(!1), e.timer(() => {
3781
3897
  this.#i.set(!0);
3782
- }, Ei);
3898
+ }, $i);
3783
3899
  }
3784
3900
  close() {
3785
3901
  this.#t.update((e) => {
3786
3902
  e?.close();
3787
- }), this.#a.close();
3903
+ }), this.#o.close();
3788
3904
  }
3789
3905
  }
3790
- class Bi {
3906
+ class Vi {
3791
3907
  source;
3792
3908
  broadcast;
3793
3909
  track;
@@ -3799,7 +3915,7 @@ class Bi {
3799
3915
  buffered = new h([]);
3800
3916
  // Decoded frames waiting to be rendered.
3801
3917
  #e = new h([]);
3802
- signals = new U();
3918
+ signals = new E();
3803
3919
  constructor(e) {
3804
3920
  const { codedWidth: n, codedHeight: s, ...i } = e.config;
3805
3921
  this.source = e.source, this.broadcast = e.broadcast, this.track = e.track, this.config = i, this.stats = e.stats, this.signals.run(this.#t.bind(this));
@@ -3817,7 +3933,7 @@ class Bi {
3817
3933
  const o = this.source.sync.wait(r).then(() => !0);
3818
3934
  if (!await Promise.race([o, e.cancel]) || r < (this.timestamp.peek() ?? 0))
3819
3935
  return;
3820
- this.timestamp.set(r), this.#r(r), this.frame.update((c) => (c?.close(), i.clone()));
3936
+ this.timestamp.set(r), this.#r(r), this.frame.update((a) => (a?.close(), i.clone()));
3821
3937
  } finally {
3822
3938
  i.close();
3823
3939
  }
@@ -3832,15 +3948,16 @@ class Bi {
3832
3948
  }), this.config.container.kind === "cmaf" ? this.#s(e, n, s) : this.#n(e, n, s);
3833
3949
  }
3834
3950
  #n(e, n, s) {
3835
- const i = new ie(n, {
3951
+ const i = new ne(n, {
3952
+ format: new Me(),
3836
3953
  latency: this.source.sync.buffer
3837
3954
  });
3838
3955
  e.cleanup(() => i.close()), e.run((o) => {
3839
- const a = o.get(i.buffered), c = o.get(this.#e);
3840
- this.buffered.update(() => Ci(a, c));
3956
+ const c = o.get(i.buffered), a = o.get(this.#e);
3957
+ this.buffered.update(() => ve(c, a));
3841
3958
  }), s.configure({
3842
3959
  ...this.config,
3843
- description: this.config.description ? F(this.config.description) : void 0,
3960
+ description: this.config.description ? N(this.config.description) : void 0,
3844
3961
  optimizeForLatency: this.config.optimizeForLatency ?? !0,
3845
3962
  // @ts-expect-error Only supported by Chrome, so the renderer has to flip manually.
3846
3963
  flip: !1
@@ -3850,28 +3967,28 @@ class Bi {
3850
3967
  for (; ; ) {
3851
3968
  const o = await Promise.race([i.next(), e.cancel]);
3852
3969
  if (!o) break;
3853
- const { frame: a, group: c } = o;
3854
- if (!a) {
3970
+ const { frame: c, group: a } = o;
3971
+ if (!c) {
3855
3972
  r && (r.final = !0);
3856
3973
  continue;
3857
3974
  }
3858
- const u = p.Milli.fromMicro(a.timestamp);
3975
+ const u = p.Milli.fromMicro(c.timestamp);
3859
3976
  this.source.sync.received(u, "video");
3860
3977
  const l = new EncodedVideoChunk({
3861
- type: a.keyframe ? "key" : "delta",
3862
- data: a.data,
3863
- timestamp: a.timestamp
3978
+ type: c.keyframe ? "key" : "delta",
3979
+ data: c.data,
3980
+ timestamp: c.timestamp
3864
3981
  });
3865
3982
  if (this.stats.update((d) => ({
3866
3983
  frameCount: (d?.frameCount ?? 0) + 1,
3867
- bytesReceived: (d?.bytesReceived ?? 0) + a.data.byteLength
3868
- })), r?.group === c || r?.final && r.group + 1 === c) {
3869
- const d = p.Milli.fromMicro(r.timestamp), f = p.Milli.fromMicro(a.timestamp);
3984
+ bytesReceived: (d?.bytesReceived ?? 0) + c.data.byteLength
3985
+ })), r?.group === a || r?.final && r.group + 1 === a) {
3986
+ const d = p.Milli.fromMicro(r.timestamp), f = p.Milli.fromMicro(c.timestamp);
3870
3987
  this.#i(d, f);
3871
3988
  }
3872
3989
  r = {
3873
- timestamp: a.timestamp,
3874
- group: c,
3990
+ timestamp: c.timestamp,
3991
+ group: a,
3875
3992
  final: !1
3876
3993
  }, s.decode(l);
3877
3994
  }
@@ -3879,47 +3996,50 @@ class Bi {
3879
3996
  }
3880
3997
  #s(e, n, s) {
3881
3998
  if (this.config.container.kind !== "cmaf") return;
3882
- const { timescale: i } = this.config.container, r = this.config.description ? F(this.config.description) : void 0;
3883
- s.configure({
3999
+ const i = he(this.config.container.init), r = ze(i), o = this.config.description ? N(this.config.description) : void 0, c = new ne(n, {
4000
+ format: new jt(r),
4001
+ latency: this.source.sync.buffer
4002
+ });
4003
+ e.cleanup(() => c.close()), e.run((u) => {
4004
+ const l = u.get(c.buffered), d = u.get(this.#e);
4005
+ this.buffered.update(() => ve(l, d));
4006
+ }), s.configure({
3884
4007
  codec: this.config.codec,
3885
- description: r,
4008
+ description: o,
3886
4009
  optimizeForLatency: this.config.optimizeForLatency ?? !0,
3887
4010
  // @ts-expect-error Only supported by Chrome, so the renderer has to flip manually.
3888
4011
  flip: !1
3889
- }), e.run((o) => {
3890
- const a = o.get(this.#e);
3891
- this.buffered.update(() => a);
3892
- }), e.spawn(async () => {
4012
+ });
4013
+ let a;
4014
+ e.spawn(async () => {
3893
4015
  for (; ; ) {
3894
- const o = await Promise.race([n.recvGroup(), e.cancel]);
3895
- if (!o) break;
3896
- e.spawn(async () => {
3897
- let a;
3898
- try {
3899
- for (; ; ) {
3900
- const c = await Promise.race([o.readFrame(), e.cancel]);
3901
- if (!c) break;
3902
- const u = Ct(c, i);
3903
- for (const l of u) {
3904
- const d = new EncodedVideoChunk({
3905
- type: l.keyframe ? "key" : "delta",
3906
- data: l.data,
3907
- timestamp: l.timestamp
3908
- }), f = p.Milli.fromMicro(l.timestamp);
3909
- if (this.source.sync.received(f, "video"), this.stats.update((g) => ({
3910
- frameCount: (g?.frameCount ?? 0) + 1,
3911
- bytesReceived: (g?.bytesReceived ?? 0) + l.data.byteLength
3912
- })), a !== void 0) {
3913
- const g = p.Milli.fromMicro(a), y = p.Milli.fromMicro(l.timestamp);
3914
- this.#i(g, y);
3915
- }
3916
- a = l.timestamp, s.decode(d);
3917
- }
3918
- }
3919
- } finally {
3920
- o.close();
3921
- }
3922
- });
4016
+ const u = await Promise.race([c.next(), e.cancel]);
4017
+ if (!u) break;
4018
+ const { frame: l, group: d } = u;
4019
+ if (!l) {
4020
+ a && (a.final = !0);
4021
+ continue;
4022
+ }
4023
+ const f = p.Milli.fromMicro(l.timestamp);
4024
+ if (this.source.sync.received(f, "video"), this.stats.update((w) => ({
4025
+ frameCount: (w?.frameCount ?? 0) + 1,
4026
+ bytesReceived: (w?.bytesReceived ?? 0) + l.data.byteLength
4027
+ })), a?.group === d || a?.final && a.group + 1 === d) {
4028
+ const w = p.Milli.fromMicro(a.timestamp), y = p.Milli.fromMicro(l.timestamp);
4029
+ this.#i(w, y);
4030
+ }
4031
+ if (a = {
4032
+ timestamp: l.timestamp,
4033
+ group: d,
4034
+ final: !1
4035
+ }, s.state === "closed") break;
4036
+ s.decode(
4037
+ new EncodedVideoChunk({
4038
+ type: l.keyframe ? "key" : "delta",
4039
+ data: l.data,
4040
+ timestamp: l.timestamp
4041
+ })
4042
+ );
3923
4043
  }
3924
4044
  });
3925
4045
  }
@@ -3952,18 +4072,8 @@ class Bi {
3952
4072
  });
3953
4073
  }
3954
4074
  }
3955
- function Ci(t, e) {
3956
- if (t.length === 0) return e;
3957
- if (e.length === 0) return t;
3958
- const n = [], s = [...t, ...e].sort((i, r) => i.start - r.start);
3959
- for (const i of s) {
3960
- const r = n.at(-1);
3961
- r && r.end >= i.start ? r.end = p.Milli.max(r.end, i.end) : n.push({ ...i });
3962
- }
3963
- return n;
3964
- }
3965
- async function Ii(t) {
3966
- const e = t.description ? F(t.description) : void 0, { supported: n } = await VideoDecoder.isConfigSupported({
4075
+ async function Wi(t) {
4076
+ const e = t.description ? N(t.description) : void 0, { supported: n } = await VideoDecoder.isConfigSupported({
3967
4077
  codec: t.codec,
3968
4078
  description: e,
3969
4079
  optimizeForLatency: t.optimizeForLatency ?? !0
@@ -3980,7 +4090,7 @@ async function Ii(t) {
3980
4090
  }
3981
4091
  return !1;
3982
4092
  }
3983
- let Oi = class {
4093
+ let qi = class {
3984
4094
  muxer;
3985
4095
  source;
3986
4096
  // TODO implement stats
@@ -3992,9 +4102,9 @@ let Oi = class {
3992
4102
  stalled = this.#n;
3993
4103
  #s = new h(_.Time.Milli.zero);
3994
4104
  timestamp = this.#s;
3995
- signals = new U();
4105
+ signals = new E();
3996
4106
  constructor(e, n) {
3997
- this.muxer = e, this.source = n, this.source.supported.set(Di), this.signals.run(this.#i.bind(this)), this.signals.run(this.#c.bind(this)), this.signals.run(this.#u.bind(this));
4107
+ this.muxer = e, this.source = n, this.source.supported.set(Hi), this.signals.run(this.#i.bind(this)), this.signals.run(this.#c.bind(this)), this.signals.run(this.#u.bind(this));
3998
4108
  }
3999
4109
  #i(e) {
4000
4110
  const n = e.get(this.muxer.element);
@@ -4007,16 +4117,16 @@ let Oi = class {
4007
4117
  if (!r) return;
4008
4118
  const o = e.get(this.source.track);
4009
4119
  if (!o) return;
4010
- const a = e.get(this.source.config);
4011
- if (!a) return;
4012
- const c = `video/mp4; codecs="${a.codec}"`, u = s.addSourceBuffer(c);
4120
+ const c = e.get(this.source.config);
4121
+ if (!c) return;
4122
+ const a = `video/mp4; codecs="${c.codec}"`, u = s.addSourceBuffer(a);
4013
4123
  e.cleanup(() => {
4014
4124
  s.removeSourceBuffer(u), u.abort();
4015
4125
  }), e.event(u, "error", (l) => {
4016
4126
  console.error("[MSE] SourceBuffer error:", l);
4017
4127
  }), e.event(u, "updateend", () => {
4018
- this.#t.set(Ft(u.buffered));
4019
- }), a.container.kind === "cmaf" ? this.#o(e, r, o, a, u, n) : this.#a(e, r, o, a, u, n);
4128
+ this.#t.set(Wt(u.buffered));
4129
+ }), c.container.kind === "cmaf" ? this.#a(e, r, o, c, u, n) : this.#o(e, r, o, c, u, n);
4020
4130
  }
4021
4131
  async #r(e, n) {
4022
4132
  for (; e.updating; )
@@ -4024,50 +4134,50 @@ let Oi = class {
4024
4134
  for (e.appendBuffer(n); e.updating; )
4025
4135
  await new Promise((s) => e.addEventListener("updateend", s, { once: !0 }));
4026
4136
  }
4027
- #o(e, n, s, i, r, o) {
4137
+ #a(e, n, s, i, r, o) {
4028
4138
  if (i.container.kind !== "cmaf") throw new Error("unreachable");
4029
- const a = n.subscribe(s, ee.video);
4030
- e.cleanup(() => a.close());
4031
- const c = i.container.timescale;
4139
+ const c = n.subscribe(s, ee.video);
4140
+ e.cleanup(() => c.close());
4141
+ const a = he(i.container.init), u = ze(a);
4032
4142
  e.spawn(async () => {
4033
- const u = Qe(i);
4034
- for (await this.#r(r, u); ; ) {
4035
- const l = await a.readFrame();
4143
+ for (await this.#r(r, a); ; ) {
4144
+ const l = await c.readFrame();
4036
4145
  if (!l) return;
4037
- const d = Bt(l, c);
4146
+ const d = Lt(l, u);
4038
4147
  this.source.sync.received(_.Time.Milli.fromMicro(d), "video"), await this.#r(r, l), o.buffered.length > 0 && o.currentTime < o.buffered.start(0) && (o.currentTime = o.buffered.start(0));
4039
4148
  }
4040
4149
  });
4041
4150
  }
4042
- #a(e, n, s, i, r, o) {
4043
- const a = n.subscribe(s, ee.video);
4044
- e.cleanup(() => a.close());
4045
- const c = new ie(a, {
4151
+ #o(e, n, s, i, r, o) {
4152
+ const c = n.subscribe(s, ee.video);
4153
+ e.cleanup(() => c.close());
4154
+ const a = new ne(c, {
4155
+ format: new Me(),
4046
4156
  latency: this.source.sync.buffer
4047
4157
  });
4048
- e.cleanup(() => c.close()), e.spawn(async () => {
4049
- const u = Qe(i);
4158
+ e.cleanup(() => a.close()), e.spawn(async () => {
4159
+ const u = vi(i);
4050
4160
  await this.#r(r, u);
4051
4161
  let l = 1, d, f;
4052
4162
  for (; ; ) {
4053
- const g = await c.next();
4054
- if (!g) return;
4055
- if (!g.frame) continue;
4056
- f = g.frame;
4163
+ const w = await a.next();
4164
+ if (!w) return;
4165
+ if (!w.frame) continue;
4166
+ f = w.frame;
4057
4167
  const y = _.Time.Milli.fromMicro(f.timestamp);
4058
4168
  this.source.sync.received(y, "video");
4059
4169
  break;
4060
4170
  }
4061
4171
  for (; ; ) {
4062
- const g = await c.next();
4063
- if (g && !g.frame) continue;
4064
- const y = g?.frame;
4172
+ const w = await a.next();
4173
+ if (w && !w.frame) continue;
4174
+ const y = w?.frame;
4065
4175
  if (y) {
4066
4176
  d = _.Time.Micro.sub(y.timestamp, f.timestamp);
4067
4177
  const A = _.Time.Milli.fromMicro(y.timestamp);
4068
4178
  this.source.sync.received(A, "video");
4069
4179
  }
4070
- const v = Lt({
4180
+ const b = $t({
4071
4181
  data: f.data,
4072
4182
  timestamp: f.timestamp,
4073
4183
  duration: d ?? 0,
@@ -4075,7 +4185,7 @@ let Oi = class {
4075
4185
  keyframe: f.keyframe,
4076
4186
  sequence: l++
4077
4187
  });
4078
- if (await this.#r(r, v), o.buffered.length > 0 && o.currentTime < o.buffered.start(0) && (o.currentTime = o.buffered.start(0)), !y) return;
4188
+ if (await this.#r(r, b), o.buffered.length > 0 && o.currentTime < o.buffered.start(0) && (o.currentTime = o.buffered.start(0)), !y) return;
4079
4189
  f = y;
4080
4190
  }
4081
4191
  });
@@ -4109,10 +4219,10 @@ let Oi = class {
4109
4219
  this.source.close(), this.signals.close();
4110
4220
  }
4111
4221
  };
4112
- async function Di(t) {
4222
+ async function Hi(t) {
4113
4223
  return MediaSource.isTypeSupported(`video/mp4; codecs="${t.codec}"`);
4114
4224
  }
4115
- class Li {
4225
+ class Gi {
4116
4226
  decoder;
4117
4227
  // The canvas to render the video to.
4118
4228
  canvas;
@@ -4124,12 +4234,12 @@ class Li {
4124
4234
  timestamp = new h(void 0);
4125
4235
  #e = new h(void 0);
4126
4236
  #t = new h(!1);
4127
- #n = new U();
4237
+ #n = new E();
4128
4238
  constructor(e, n) {
4129
4239
  this.decoder = e, this.canvas = h.from(n?.canvas), this.paused = h.from(n?.paused ?? !1), this.#n.run((s) => {
4130
4240
  const i = s.get(this.canvas);
4131
4241
  this.#e.set(i?.getContext("2d") ?? void 0);
4132
- }), this.#n.run(this.#i.bind(this)), this.#n.run(this.#r.bind(this)), this.#n.run(this.#o.bind(this)), this.#n.run(this.#s.bind(this));
4242
+ }), this.#n.run(this.#i.bind(this)), this.#n.run(this.#r.bind(this)), this.#n.run(this.#a.bind(this)), this.#n.run(this.#s.bind(this));
4133
4243
  }
4134
4244
  #s(e) {
4135
4245
  const n = e.getAll([this.canvas, this.decoder.display]);
@@ -4149,8 +4259,8 @@ class Li {
4149
4259
  this.#t.set(s && !document.hidden);
4150
4260
  }, r = new IntersectionObserver(
4151
4261
  (o) => {
4152
- for (const a of o)
4153
- s = a.isIntersecting, i();
4262
+ for (const c of o)
4263
+ s = c.isIntersecting, i();
4154
4264
  },
4155
4265
  { threshold: 0.01 }
4156
4266
  );
@@ -4166,7 +4276,7 @@ class Li {
4166
4276
  const i = e.get(this.frame);
4167
4277
  this.decoder.enabled.set(!i);
4168
4278
  }
4169
- #o(e) {
4279
+ #a(e) {
4170
4280
  const n = e.get(this.#e);
4171
4281
  if (!n) return;
4172
4282
  const s = e.get(this.paused);
@@ -4174,13 +4284,13 @@ class Li {
4174
4284
  s || (i = e.get(this.decoder.frame));
4175
4285
  let r = requestAnimationFrame(() => {
4176
4286
  const o = i ?? this.frame.peek();
4177
- this.#a(n, o), i && (this.frame.update((a) => (a?.close(), i.clone())), this.timestamp.set(p.Milli.fromMicro(i.timestamp))), r = void 0;
4287
+ this.#o(n, o), i && (this.frame.update((c) => (c?.close(), i.clone())), this.timestamp.set(p.Milli.fromMicro(i.timestamp))), r = void 0;
4178
4288
  });
4179
4289
  e.cleanup(() => {
4180
4290
  i?.close(), r && cancelAnimationFrame(r);
4181
4291
  });
4182
4292
  }
4183
- #a(e, n) {
4293
+ #o(e, n) {
4184
4294
  if (!n) {
4185
4295
  e.fillStyle = "#000", e.fillRect(0, 0, e.canvas.width, e.canvas.height);
4186
4296
  return;
@@ -4194,7 +4304,7 @@ class Li {
4194
4304
  }), this.#n.close();
4195
4305
  }
4196
4306
  }
4197
- function Pi(t) {
4307
+ function Xi(t) {
4198
4308
  return (e) => {
4199
4309
  const n = [], s = [];
4200
4310
  for (const [i, r] of e)
@@ -4205,7 +4315,7 @@ function Pi(t) {
4205
4315
  return n.sort((i, r) => r.size - i.size), n.length > 0 ? n.map((i) => i.name) : s.length > 0 ? (s.sort((i, r) => i.size - r.size), [s[0].name]) : e.map(([i]) => i);
4206
4316
  };
4207
4317
  }
4208
- function Ni(t) {
4318
+ function Yi(t) {
4209
4319
  return (e) => {
4210
4320
  const n = [], s = [];
4211
4321
  for (const [i, r] of e)
@@ -4213,7 +4323,7 @@ function Ni(t) {
4213
4323
  return n.sort((i, r) => r.bitrate - i.bitrate), n.length > 0 ? n.map((i) => i.name) : s.length > 0 ? (s.sort((i, r) => i.bitrate - r.bitrate), [s[0].name]) : e.map(([i]) => i);
4214
4324
  };
4215
4325
  }
4216
- function Fi(t) {
4326
+ function Ki(t) {
4217
4327
  let e = t[0];
4218
4328
  for (const n of t) {
4219
4329
  const [, s] = n, [, i] = e, r = (s.codedWidth ?? 0) * (s.codedHeight ?? 0), o = (i.codedWidth ?? 0) * (i.codedHeight ?? 0);
@@ -4225,7 +4335,7 @@ function Fi(t) {
4225
4335
  }
4226
4336
  return e[0];
4227
4337
  }
4228
- let $i = class {
4338
+ let Ji = class {
4229
4339
  broadcast;
4230
4340
  target;
4231
4341
  #e = new h(void 0);
@@ -4239,9 +4349,9 @@ let $i = class {
4239
4349
  config = this.#s;
4240
4350
  sync;
4241
4351
  supported;
4242
- #i = new U();
4352
+ #i = new E();
4243
4353
  constructor(e, n) {
4244
- this.broadcast = h.from(n?.broadcast), this.target = h.from(n?.target), this.sync = e, this.supported = h.from(n?.supported), this.#i.run(this.#r.bind(this)), this.#i.run(this.#o.bind(this)), this.#i.run(this.#a.bind(this));
4354
+ this.broadcast = h.from(n?.broadcast), this.target = h.from(n?.target), this.sync = e, this.supported = h.from(n?.supported), this.#i.run(this.#r.bind(this)), this.#i.run(this.#a.bind(this)), this.#i.run(this.#o.bind(this));
4245
4355
  }
4246
4356
  #r(e) {
4247
4357
  const n = e.get(this.broadcast);
@@ -4249,7 +4359,7 @@ let $i = class {
4249
4359
  const s = e.get(n.catalog)?.video;
4250
4360
  s && e.set(this.#e, s);
4251
4361
  }
4252
- #o(e) {
4362
+ #a(e) {
4253
4363
  const n = e.get(this.supported);
4254
4364
  if (!n) return;
4255
4365
  const s = e.get(this.#e)?.renditions ?? {};
@@ -4260,18 +4370,18 @@ let $i = class {
4260
4370
  Object.keys(i).length === 0 && Object.keys(s).length > 0 && console.warn("[Source] No supported video renditions found:", s), this.#t.set(i);
4261
4371
  });
4262
4372
  }
4263
- #a(e) {
4373
+ #o(e) {
4264
4374
  const n = e.get(this.#t);
4265
4375
  if (Object.keys(n).length === 0) return;
4266
4376
  const s = e.get(this.target);
4267
4377
  if (s?.name && s.name in n) {
4268
- const c = n[s.name];
4269
- e.set(this.#n, s.name), e.set(this.#s, c), e.set(this.sync.video, c.jitter);
4378
+ const a = n[s.name];
4379
+ e.set(this.#n, s.name), e.set(this.#s, a), e.set(this.sync.video, a.jitter);
4270
4380
  return;
4271
4381
  }
4272
4382
  let i = s;
4273
4383
  if (!s?.bitrate) {
4274
- const c = e.get(this.broadcast), l = (c ? e.get(c.connection) : void 0)?.recvBandwidth;
4384
+ const a = e.get(this.broadcast), l = (a ? e.get(a.connection) : void 0)?.recvBandwidth;
4275
4385
  if (l) {
4276
4386
  const d = e.get(l);
4277
4387
  if (d != null) {
@@ -4284,8 +4394,8 @@ let $i = class {
4284
4394
  if (!r) return;
4285
4395
  const o = n[r];
4286
4396
  e.set(this.#n, r), e.set(this.#s, o);
4287
- const a = o.jitter ?? (o.framerate ? Math.ceil(1e3 / o.framerate) : void 0);
4288
- e.set(this.sync.video, a);
4397
+ const c = o.jitter ?? (o.framerate ? Math.ceil(1e3 / o.framerate) : void 0);
4398
+ e.set(this.sync.video, c);
4289
4399
  }
4290
4400
  /**
4291
4401
  * Select the best rendition using a generic filter system.
@@ -4299,19 +4409,19 @@ let $i = class {
4299
4409
  if (s.length === 0) return;
4300
4410
  if (s.length === 1) return s[0][0];
4301
4411
  const i = [];
4302
- if (n?.pixels != null && i.push(Pi(n.pixels)), n?.bitrate != null && i.push(Ni(n.bitrate)), i.length === 0)
4303
- return Fi(s);
4304
- const r = i.map((a) => a(s)), o = r.map((a) => new Set(a));
4305
- for (const a of r[0])
4306
- if (o.every((c) => c.has(a)))
4307
- return a;
4412
+ if (n?.pixels != null && i.push(Xi(n.pixels)), n?.bitrate != null && i.push(Yi(n.bitrate)), i.length === 0)
4413
+ return Ki(s);
4414
+ const r = i.map((c) => c(s)), o = r.map((c) => new Set(c));
4415
+ for (const c of r[0])
4416
+ if (o.every((a) => a.has(c)))
4417
+ return c;
4308
4418
  console.warn("conflicting rendition filters, no rendition satisfies all criteria");
4309
4419
  }
4310
4420
  close() {
4311
4421
  this.#i.close();
4312
4422
  }
4313
4423
  };
4314
- function Ft(t) {
4424
+ function Wt(t) {
4315
4425
  const e = [];
4316
4426
  for (let n = 0; n < t.length; n++) {
4317
4427
  const s = _.Time.Milli.fromSecond(t.start(n)), i = _.Time.Milli.fromSecond(t.end(n));
@@ -4319,7 +4429,7 @@ function Ft(t) {
4319
4429
  }
4320
4430
  return e;
4321
4431
  }
4322
- class ji {
4432
+ class Qi {
4323
4433
  // The source of the video.
4324
4434
  source;
4325
4435
  // The stats of the video.
@@ -4334,7 +4444,7 @@ class ji {
4334
4444
  this.source = e;
4335
4445
  }
4336
4446
  }
4337
- class Zi {
4447
+ class er {
4338
4448
  source;
4339
4449
  // The volume of the audio, between 0 and 1.
4340
4450
  volume = new h(0.5);
@@ -4344,11 +4454,13 @@ class Zi {
4344
4454
  stats = new h(void 0);
4345
4455
  // Buffered time ranges
4346
4456
  buffered = new h([]);
4457
+ // The AudioContext used for playback (set by the WebCodecs backend; undefined under MSE).
4458
+ context = new h(void 0);
4347
4459
  constructor(e) {
4348
4460
  this.source = e;
4349
4461
  }
4350
4462
  }
4351
- class fr {
4463
+ class Mr {
4352
4464
  element = new h(void 0);
4353
4465
  broadcast;
4354
4466
  latency;
@@ -4360,45 +4472,45 @@ class fr {
4360
4472
  #t;
4361
4473
  // Used to sync audio and video playback at a target delay.
4362
4474
  sync;
4363
- signals = new U();
4475
+ signals = new E();
4364
4476
  constructor(e) {
4365
- this.element = h.from(e?.element), this.broadcast = h.from(e?.broadcast), this.sync = new Le({ latency: e?.latency, rtt: e?.rtt }), this.latency = this.sync.latency, this.jitter = this.sync.jitter, this.#e = new $i(this.sync, {
4477
+ this.element = h.from(e?.element), this.broadcast = h.from(e?.broadcast), this.sync = new $e({ latency: e?.latency, connection: e?.connection }), this.latency = this.sync.latency, this.jitter = this.sync.jitter, this.#e = new Ji(this.sync, {
4366
4478
  broadcast: this.broadcast
4367
- }), this.#t = new Hi(this.sync, {
4479
+ }), this.#t = new ir(this.sync, {
4368
4480
  broadcast: this.broadcast
4369
- }), this.video = new ji(this.#e), this.audio = new Zi(this.#t), this.paused = h.from(e?.paused ?? !1), this.signals.run(this.#n.bind(this));
4481
+ }), this.video = new Qi(this.#e), this.audio = new er(this.#t), this.paused = h.from(e?.paused ?? !1), this.signals.run(this.#n.bind(this));
4370
4482
  }
4371
4483
  #n(e) {
4372
4484
  const n = e.get(this.element);
4373
4485
  n && (n instanceof HTMLCanvasElement ? this.#s(e, n) : n instanceof HTMLVideoElement && this.#i(e, n));
4374
4486
  }
4375
4487
  #s(e, n) {
4376
- const s = new Ri(this.#e), i = new Mi(this.#t), r = new Ti(i, {
4488
+ const s = new Zi(this.#e), i = new Li(this.#t), r = new Ni(i, {
4377
4489
  volume: this.audio.volume,
4378
4490
  muted: this.audio.muted,
4379
4491
  paused: this.paused
4380
- }), o = new Li(s, { canvas: n, paused: this.paused });
4492
+ }), o = new Gi(s, { canvas: n, paused: this.paused });
4381
4493
  e.cleanup(() => {
4382
4494
  s.close(), i.close(), r.close(), o.close();
4383
- }), e.proxy(this.video.stats, s.stats), e.proxy(this.video.buffered, s.buffered), e.proxy(this.video.stalled, s.stalled), e.proxy(this.video.timestamp, s.timestamp), e.proxy(this.audio.stats, i.stats), e.proxy(this.audio.buffered, i.buffered);
4495
+ }), e.proxy(this.video.stats, s.stats), e.proxy(this.video.buffered, s.buffered), e.proxy(this.video.stalled, s.stalled), e.proxy(this.video.timestamp, s.timestamp), e.proxy(this.audio.stats, i.stats), e.proxy(this.audio.buffered, i.buffered), e.proxy(this.audio.context, i.context);
4384
4496
  }
4385
4497
  #i(e, n) {
4386
- const s = new Nt(this.sync, {
4498
+ const s = new Vt(this.sync, {
4387
4499
  paused: this.paused,
4388
4500
  element: n
4389
- }), i = new Oi(s, this.#e), r = new Vi(s, this.#t, {
4501
+ }), i = new qi(s, this.#e), r = new tr(s, this.#t, {
4390
4502
  volume: this.audio.volume,
4391
4503
  muted: this.audio.muted
4392
4504
  });
4393
4505
  e.cleanup(() => {
4394
4506
  i.close(), r.close(), s.close();
4395
- }), e.proxy(this.video.stats, i.stats), e.proxy(this.video.buffered, i.buffered), e.proxy(this.video.stalled, i.stalled), e.proxy(this.video.timestamp, i.timestamp), e.proxy(this.audio.stats, r.stats), e.proxy(this.audio.buffered, r.buffered);
4507
+ }), e.proxy(this.video.stats, i.stats), e.proxy(this.video.buffered, i.buffered), e.proxy(this.video.stalled, i.stalled), e.proxy(this.video.timestamp, i.timestamp), e.proxy(this.audio.stats, r.stats), e.proxy(this.audio.buffered, r.buffered), e.proxy(this.audio.context, r.context);
4396
4508
  }
4397
4509
  close() {
4398
4510
  this.signals.close();
4399
4511
  }
4400
4512
  }
4401
- class Vi {
4513
+ class tr {
4402
4514
  muxer;
4403
4515
  source;
4404
4516
  volume;
@@ -4407,9 +4519,11 @@ class Vi {
4407
4519
  stats = this.#e;
4408
4520
  #t = new h([]);
4409
4521
  buffered = this.#t;
4410
- #n = new U();
4522
+ // MSE plays through the <video> element, not WebAudio.
4523
+ context = new h(void 0);
4524
+ #n = new E();
4411
4525
  constructor(e, n, s) {
4412
- this.muxer = e, this.source = n, this.source.supported.set(Wi), this.volume = h.from(s?.volume ?? 0.5), this.muted = h.from(s?.muted ?? !1), this.#n.run(this.#s.bind(this)), this.#n.run(this.#a.bind(this));
4526
+ this.muxer = e, this.source = n, this.source.supported.set(nr), this.volume = h.from(s?.volume ?? 0.5), this.muted = h.from(s?.muted ?? !1), this.#n.run(this.#s.bind(this)), this.#n.run(this.#o.bind(this));
4413
4527
  }
4414
4528
  #s(e) {
4415
4529
  const n = e.get(this.muxer.element);
@@ -4422,18 +4536,18 @@ class Vi {
4422
4536
  if (!r) return;
4423
4537
  const o = e.get(this.source.track);
4424
4538
  if (!o) return;
4425
- const a = e.get(this.source.config);
4426
- if (!a) return;
4427
- const c = `audio/mp4; codecs="${a.codec}"`, u = s.addSourceBuffer(c);
4539
+ const c = e.get(this.source.config);
4540
+ if (!c) return;
4541
+ const a = `audio/mp4; codecs="${c.codec}"`, u = s.addSourceBuffer(a);
4428
4542
  e.cleanup(() => {
4429
4543
  s.removeSourceBuffer(u), u.abort();
4430
4544
  }), e.event(u, "error", (d) => {
4431
4545
  console.error("[MSE] SourceBuffer error:", d);
4432
4546
  }), e.event(u, "updateend", () => {
4433
- this.#t.set(Ft(u.buffered));
4547
+ this.#t.set(Wt(u.buffered));
4434
4548
  });
4435
4549
  const l = r.subscribe(o, ee.audio);
4436
- e.cleanup(() => l.close()), a.container.kind === "cmaf" ? this.#r(e, l, a, u, n) : this.#o(e, l, a, u, n);
4550
+ e.cleanup(() => l.close()), c.container.kind === "cmaf" ? this.#r(e, l, c, u, n) : this.#a(e, l, c, u, n);
4437
4551
  }
4438
4552
  async #i(e, n) {
4439
4553
  for (; e.updating; )
@@ -4443,25 +4557,25 @@ class Vi {
4443
4557
  }
4444
4558
  #r(e, n, s, i, r) {
4445
4559
  if (s.container.kind !== "cmaf") throw new Error("unreachable");
4446
- const o = s.container.timescale;
4560
+ const o = he(s.container.init), c = ze(o);
4447
4561
  e.spawn(async () => {
4448
- const a = et(s);
4449
- for (await this.#i(i, a); ; ) {
4450
- const c = await n.readFrame();
4451
- if (!c) return;
4452
- const u = Bt(c, o);
4453
- this.source.sync.received(_.Time.Milli.fromMicro(u), "audio"), await this.#i(i, c), r.buffered.length > 0 && r.currentTime < r.buffered.start(0) && (r.currentTime = r.buffered.start(0));
4562
+ for (await this.#i(i, o); ; ) {
4563
+ const a = await n.readFrame();
4564
+ if (!a) return;
4565
+ const u = Lt(a, c);
4566
+ this.source.sync.received(_.Time.Milli.fromMicro(u), "audio"), await this.#i(i, a), r.buffered.length > 0 && r.currentTime < r.buffered.start(0) && (r.currentTime = r.buffered.start(0));
4454
4567
  }
4455
4568
  });
4456
4569
  }
4457
- #o(e, n, s, i, r) {
4458
- const o = new ie(n, {
4570
+ #a(e, n, s, i, r) {
4571
+ const o = new ne(n, {
4572
+ format: new Me(),
4459
4573
  latency: this.source.sync.buffer
4460
4574
  });
4461
4575
  e.cleanup(() => o.close()), e.spawn(async () => {
4462
- const a = et(s);
4463
- await this.#i(i, a);
4464
- let c = 1, u, l;
4576
+ const c = Si(s);
4577
+ await this.#i(i, c);
4578
+ let a = 1, u, l;
4465
4579
  for (; ; ) {
4466
4580
  const d = await o.next();
4467
4581
  if (!d) return;
@@ -4480,20 +4594,20 @@ class Vi {
4480
4594
  const y = _.Time.Milli.fromMicro(f.timestamp);
4481
4595
  this.source.sync.received(y, "audio");
4482
4596
  }
4483
- const g = Lt({
4597
+ const w = $t({
4484
4598
  data: l.data,
4485
4599
  timestamp: l.timestamp,
4486
4600
  duration: u ?? 0,
4487
4601
  // Default to 0 duration if there's literally one frame then stream FIN.
4488
4602
  keyframe: l.keyframe,
4489
- sequence: c++
4603
+ sequence: a++
4490
4604
  });
4491
- if (await this.#i(i, g), r.buffered.length > 0 && r.currentTime < r.buffered.start(0) && (r.currentTime = r.buffered.start(0)), !f) return;
4605
+ if (await this.#i(i, w), r.buffered.length > 0 && r.currentTime < r.buffered.start(0) && (r.currentTime = r.buffered.start(0)), !f) return;
4492
4606
  l = f;
4493
4607
  }
4494
4608
  });
4495
4609
  }
4496
- #a(e) {
4610
+ #o(e) {
4497
4611
  const n = e.get(this.muxer.element);
4498
4612
  if (!n) return;
4499
4613
  const s = e.get(this.volume), i = e.get(this.muted);
@@ -4505,11 +4619,11 @@ class Vi {
4505
4619
  this.#n.close();
4506
4620
  }
4507
4621
  }
4508
- async function Wi(t) {
4622
+ async function nr(t) {
4509
4623
  return MediaSource.isTypeSupported(`audio/mp4; codecs="${t.codec}"`);
4510
4624
  }
4511
- const qi = 128;
4512
- class Hi {
4625
+ const sr = 128;
4626
+ class ir {
4513
4627
  broadcast;
4514
4628
  target;
4515
4629
  #e = new h(void 0);
@@ -4523,9 +4637,9 @@ class Hi {
4523
4637
  supported;
4524
4638
  // Used to target a latency and synchronize playback of video with audio.
4525
4639
  sync;
4526
- #i = new U();
4640
+ #i = new E();
4527
4641
  constructor(e, n) {
4528
- this.sync = e, this.broadcast = h.from(n?.broadcast), this.target = h.from(n?.target), this.supported = h.from(n?.supported), this.#i.run(this.#r.bind(this)), this.#i.run(this.#o.bind(this)), this.#i.run(this.#a.bind(this));
4642
+ this.sync = e, this.broadcast = h.from(n?.broadcast), this.target = h.from(n?.target), this.supported = h.from(n?.supported), this.#i.run(this.#r.bind(this)), this.#i.run(this.#a.bind(this)), this.#i.run(this.#o.bind(this));
4529
4643
  }
4530
4644
  #r(e) {
4531
4645
  const n = e.get(this.broadcast);
@@ -4533,7 +4647,7 @@ class Hi {
4533
4647
  const s = e.get(n.catalog)?.audio;
4534
4648
  s && e.set(this.#e, s);
4535
4649
  }
4536
- #o(e) {
4650
+ #a(e) {
4537
4651
  const n = e.get(this.#e)?.renditions ?? {}, s = e.get(this.supported);
4538
4652
  s && e.spawn(async () => {
4539
4653
  const i = {};
@@ -4542,7 +4656,7 @@ class Hi {
4542
4656
  Object.keys(i).length === 0 && Object.keys(n).length > 0 && console.warn("no supported audio renditions found:", n), this.#t.set(i);
4543
4657
  });
4544
4658
  }
4545
- #a(e) {
4659
+ #o(e) {
4546
4660
  const n = e.get(this.#t);
4547
4661
  if (Object.keys(n).length === 0) return;
4548
4662
  const s = e.get(this.target);
@@ -4551,8 +4665,8 @@ class Hi {
4551
4665
  i = { track: s.name, config: n[s.name] };
4552
4666
  else if (i = this.#c(n), !i) return;
4553
4667
  e.set(this.#n, i.track), e.set(this.#s, i.config);
4554
- const r = i.config.jitter ?? Gi(i.config) ?? 0, o = Math.ceil(qi / i.config.sampleRate * 1e3), a = r + o;
4555
- e.set(this.sync.audio, a);
4668
+ const r = i.config.jitter ?? rr(i.config) ?? 0, o = Math.ceil(sr / i.config.sampleRate * 1e3), c = r + o;
4669
+ e.set(this.sync.audio, c);
4556
4670
  }
4557
4671
  /**
4558
4672
  * Select rendition based on the configured strategy.
@@ -4572,132 +4686,124 @@ class Hi {
4572
4686
  this.#i.close();
4573
4687
  }
4574
4688
  }
4575
- function Gi(t) {
4689
+ function rr(t) {
4576
4690
  if (t.codec.startsWith("opus"))
4577
4691
  return 20;
4578
4692
  if (t.codec.startsWith("mp4a"))
4579
4693
  return Math.ceil(1024 / t.sampleRate * 1e3);
4580
4694
  }
4581
- const Xi = /* @__PURE__ */ be([
4582
- /* @__PURE__ */ St(["loc", "cmaf", "legacy", "mediatimeline", "eventtimeline"]),
4583
- /* @__PURE__ */ b()
4584
- ]), Yi = /* @__PURE__ */ be([
4585
- /* @__PURE__ */ St(["video", "audio", "audiodescription", "caption", "subtitle", "signlanguage"]),
4586
- /* @__PURE__ */ b()
4587
- ]), Ki = /* @__PURE__ */ S({
4588
- name: /* @__PURE__ */ b(),
4589
- packaging: Xi,
4590
- isLive: /* @__PURE__ */ Ee(),
4591
- role: /* @__PURE__ */ m(Yi),
4592
- codec: /* @__PURE__ */ m(/* @__PURE__ */ b()),
4593
- width: /* @__PURE__ */ m(/* @__PURE__ */ T()),
4594
- height: /* @__PURE__ */ m(/* @__PURE__ */ T()),
4595
- framerate: /* @__PURE__ */ m(/* @__PURE__ */ T()),
4596
- samplerate: /* @__PURE__ */ m(/* @__PURE__ */ T()),
4597
- channelConfig: /* @__PURE__ */ m(/* @__PURE__ */ b()),
4598
- bitrate: /* @__PURE__ */ m(/* @__PURE__ */ T()),
4599
- initData: /* @__PURE__ */ m(/* @__PURE__ */ b()),
4600
- renderGroup: /* @__PURE__ */ m(/* @__PURE__ */ T()),
4601
- altGroup: /* @__PURE__ */ m(/* @__PURE__ */ T()),
4695
+ const or = /* @__PURE__ */ _e([
4696
+ /* @__PURE__ */ kt(["loc", "cmaf", "legacy", "mediatimeline", "eventtimeline"]),
4697
+ /* @__PURE__ */ v()
4698
+ ]), ar = /* @__PURE__ */ _e([
4699
+ /* @__PURE__ */ kt(["video", "audio", "audiodescription", "caption", "subtitle", "signlanguage"]),
4700
+ /* @__PURE__ */ v()
4701
+ ]), cr = /* @__PURE__ */ S({
4702
+ name: /* @__PURE__ */ v(),
4703
+ packaging: or,
4704
+ isLive: /* @__PURE__ */ Ce(),
4705
+ role: /* @__PURE__ */ m(ar),
4706
+ codec: /* @__PURE__ */ m(/* @__PURE__ */ v()),
4707
+ width: /* @__PURE__ */ m(/* @__PURE__ */ U()),
4708
+ height: /* @__PURE__ */ m(/* @__PURE__ */ U()),
4709
+ framerate: /* @__PURE__ */ m(/* @__PURE__ */ U()),
4710
+ samplerate: /* @__PURE__ */ m(/* @__PURE__ */ U()),
4711
+ channelConfig: /* @__PURE__ */ m(/* @__PURE__ */ v()),
4712
+ bitrate: /* @__PURE__ */ m(/* @__PURE__ */ U()),
4713
+ initData: /* @__PURE__ */ m(/* @__PURE__ */ v()),
4714
+ renderGroup: /* @__PURE__ */ m(/* @__PURE__ */ U()),
4715
+ altGroup: /* @__PURE__ */ m(/* @__PURE__ */ U()),
4602
4716
  // Non-standard: maximum delay (ms) between consecutive frames on this track.
4603
4717
  // The player's buffer must be at least this large to avoid underruns.
4604
4718
  // Mirrors the `jitter` field in the hang catalog.
4605
- jitter: /* @__PURE__ */ m(/* @__PURE__ */ T())
4606
- }), Ji = /* @__PURE__ */ S({
4607
- version: /* @__PURE__ */ Te(1),
4608
- tracks: /* @__PURE__ */ G(Ki)
4719
+ jitter: /* @__PURE__ */ m(/* @__PURE__ */ U())
4720
+ }), ur = /* @__PURE__ */ S({
4721
+ version: /* @__PURE__ */ Re(1),
4722
+ tracks: /* @__PURE__ */ q(cr)
4609
4723
  });
4610
- function Qi(t) {
4724
+ function lr(t) {
4611
4725
  const n = new TextDecoder().decode(t);
4612
4726
  try {
4613
4727
  const s = JSON.parse(n);
4614
- return Ji.parse(s);
4728
+ return ur.parse(s);
4615
4729
  } catch (s) {
4616
4730
  throw console.warn("invalid MSF catalog", n), s;
4617
4731
  }
4618
4732
  }
4619
- async function er(t) {
4733
+ async function dr(t) {
4620
4734
  const e = await t.readFrame();
4621
4735
  if (e)
4622
- return Qi(e);
4736
+ return lr(e);
4623
4737
  }
4624
- const tr = 48e3, it = 2;
4625
- function nr(t) {
4626
- try {
4627
- const e = atob(t), n = new Uint8Array(e.length);
4628
- for (let s = 0; s < e.length; s++) n[s] = e.charCodeAt(s);
4629
- return n;
4630
- } catch {
4631
- return;
4632
- }
4633
- }
4634
- function rt(t) {
4738
+ const hr = 48e3, at = 2;
4739
+ function fr(t) {
4635
4740
  let e = "";
4636
4741
  for (let n = 0; n < t.length; n++) e += t[n].toString(16).padStart(2, "0");
4637
4742
  return e;
4638
4743
  }
4639
- function $t(t) {
4640
- const e = t.initData ? nr(t.initData) : void 0;
4641
- if (t.packaging === "cmaf" && e)
4642
- try {
4643
- const n = ri(e);
4644
- return {
4645
- container: { kind: "cmaf", timescale: L(n.timescale), trackId: L(n.trackId) },
4646
- description: n.description ? rt(n.description) : void 0
4647
- };
4648
- } catch (n) {
4649
- console.warn("failed to parse MSF cmaf initData, falling back to legacy", n);
4650
- }
4651
- return {
4744
+ function qt(t) {
4745
+ let e;
4746
+ try {
4747
+ e = t.initData ? he(t.initData) : void 0;
4748
+ } catch {
4749
+ e = void 0;
4750
+ }
4751
+ return t.packaging === "cmaf" && t.initData && e ? {
4752
+ container: { kind: "cmaf", init: t.initData },
4753
+ // hang's CMAF path reads codec metadata from the init segment, so we
4754
+ // don't need to surface a separate description here.
4755
+ description: void 0
4756
+ } : {
4652
4757
  container: { kind: "legacy" },
4653
- description: e ? rt(e) : void 0
4758
+ description: e ? fr(e) : void 0
4654
4759
  };
4655
4760
  }
4656
- function sr(t) {
4761
+ function mr(t) {
4657
4762
  if (!t.codec) return;
4658
- const { container: e, description: n } = $t(t);
4763
+ const { container: e, description: n } = qt(t);
4659
4764
  return {
4660
4765
  codec: t.codec,
4661
4766
  container: e,
4662
4767
  description: n,
4663
- codedWidth: t.width != null ? L(t.width) : void 0,
4664
- codedHeight: t.height != null ? L(t.height) : void 0,
4768
+ codedWidth: t.width != null ? V(t.width) : void 0,
4769
+ codedHeight: t.height != null ? V(t.height) : void 0,
4665
4770
  framerate: t.framerate,
4666
- bitrate: t.bitrate != null ? L(t.bitrate) : void 0,
4667
- jitter: t.jitter != null ? L(t.jitter) : void 0
4771
+ bitrate: t.bitrate != null ? V(t.bitrate) : void 0,
4772
+ jitter: t.jitter != null ? V(t.jitter) : void 0
4668
4773
  };
4669
4774
  }
4670
- function ir(t) {
4775
+ function pr(t) {
4671
4776
  if (!t.codec) return;
4672
4777
  const e = (() => {
4673
- if (!t.channelConfig) return it;
4778
+ if (!t.channelConfig) return at;
4674
4779
  const i = Number.parseInt(t.channelConfig, 10);
4675
- return Number.isFinite(i) ? i : it;
4676
- })(), { container: n, description: s } = $t(t);
4780
+ return Number.isFinite(i) ? i : at;
4781
+ })(), { container: n, description: s } = qt(t);
4677
4782
  return {
4678
4783
  codec: t.codec,
4679
4784
  container: n,
4680
4785
  description: s,
4681
- sampleRate: L(t.samplerate ?? tr),
4682
- numberOfChannels: L(e),
4683
- bitrate: t.bitrate != null ? L(t.bitrate) : void 0,
4684
- jitter: t.jitter != null ? L(t.jitter) : void 0
4786
+ sampleRate: V(t.samplerate ?? hr),
4787
+ numberOfChannels: V(e),
4788
+ bitrate: t.bitrate != null ? V(t.bitrate) : void 0,
4789
+ jitter: t.jitter != null ? V(t.jitter) : void 0
4685
4790
  };
4686
4791
  }
4687
- function rr(t) {
4792
+ function gr(t) {
4688
4793
  const e = {}, n = {};
4689
4794
  for (const i of t.tracks)
4690
4795
  if (i.role === "video") {
4691
- const r = sr(i);
4796
+ const r = mr(i);
4692
4797
  r && (e[i.name] = r);
4693
4798
  } else if (i.role === "audio") {
4694
- const r = ir(i);
4799
+ const r = pr(i);
4695
4800
  r && (n[i.name] = r);
4696
4801
  }
4697
4802
  const s = {};
4698
4803
  return Object.keys(e).length > 0 && (s.video = { renditions: e }), Object.keys(n).length > 0 && (s.audio = { renditions: n }), s;
4699
4804
  }
4700
- class mr {
4805
+ const kr = ["hang", "msf", "manual"];
4806
+ class Tr {
4701
4807
  connection;
4702
4808
  enabled;
4703
4809
  name;
@@ -4706,48 +4812,66 @@ class mr {
4706
4812
  catalogFormat;
4707
4813
  #e = new h(void 0);
4708
4814
  active = this.#e;
4709
- #t = new h(void 0);
4710
- catalog = this.#t;
4815
+ // The active catalog. Writable so users can supply it directly when
4816
+ // catalogFormat is "manual"; otherwise the fetch loop owns writes.
4817
+ catalog;
4711
4818
  // All actively announced broadcast paths from the connection.
4712
- #n;
4713
- signals = new U();
4819
+ #t;
4820
+ // Whether `name` is currently in the announced set (or skipping the check).
4821
+ // Derived in its own effect so that flaps for unrelated broadcasts don't
4822
+ // retrigger the broadcast/catalog subscriptions.
4823
+ #n = new h(!1);
4824
+ signals = new E();
4714
4825
  constructor(e) {
4715
- this.connection = h.from(e?.connection), this.name = h.from(e?.name ?? Ht.empty()), this.enabled = h.from(e?.enabled ?? !1), this.reload = h.from(e?.reload ?? !1), this.catalogFormat = h.from(e?.catalogFormat ?? "hang"), this.#n = e?.announced ?? new h(/* @__PURE__ */ new Set()), this.signals.run(this.#i.bind(this)), this.signals.run(this.#r.bind(this));
4826
+ this.connection = h.from(e?.connection), this.name = h.from(e?.name ?? Kt.empty()), this.enabled = h.from(e?.enabled ?? !1), this.reload = h.from(e?.reload ?? !1), this.catalogFormat = h.from(e?.catalogFormat ?? "hang"), this.catalog = h.from(e?.catalog), this.#t = e?.announced ?? new h(/* @__PURE__ */ new Set()), this.signals.run(this.#s.bind(this)), this.signals.run(this.#i.bind(this)), this.signals.run(this.#r.bind(this));
4716
4827
  }
4717
4828
  #s(e) {
4718
- if (!e.get(this.reload)) return !0;
4719
- const s = e.get(this.name);
4720
- return e.get(this.#n).has(s);
4829
+ if (!e.get(this.reload)) {
4830
+ this.#n.set(!0);
4831
+ return;
4832
+ }
4833
+ if (e.get(this.connection)?.url.hostname.endsWith("mediaoverquic.com")) {
4834
+ console.warn("Cloudflare relay does not support broadcast discovery yet; ignoring reload signal."), this.#n.set(!0);
4835
+ return;
4836
+ }
4837
+ const i = e.get(this.name), r = e.get(this.#t);
4838
+ this.#n.set(r.has(i));
4721
4839
  }
4722
4840
  #i(e) {
4723
- if (!e.get(this.enabled) || !this.#s(e)) return;
4841
+ if (!e.get(this.enabled) || !e.get(this.#n)) return;
4724
4842
  const s = e.get(this.connection);
4725
4843
  if (!s) return;
4726
4844
  const i = e.get(this.name), r = s.consume(i);
4727
4845
  e.cleanup(() => r.close()), e.set(this.#e, r, void 0);
4728
4846
  }
4729
4847
  #r(e) {
4730
- const n = e.getAll([this.enabled, this.active]);
4731
- if (!n) return;
4732
- const [s, i] = n, r = e.get(this.catalogFormat);
4848
+ if (!e.get(this.enabled)) return;
4849
+ const s = e.get(this.catalogFormat);
4850
+ if (s === "manual") {
4851
+ const a = e.get(this.catalog);
4852
+ this.status.set(a ? "live" : "loading");
4853
+ return;
4854
+ }
4855
+ const i = e.get(this.active);
4856
+ if (!i) return;
4733
4857
  this.status.set("loading");
4734
- const o = r === "hang" ? "catalog.json" : "catalog", a = i.subscribe(o, ee.catalog);
4735
- e.cleanup(() => a.close());
4736
- const c = r === "hang" ? async () => ms(a) : async () => {
4737
- const u = await er(a);
4738
- return u ? rr(u) : void 0;
4858
+ const r = s === "hang" ? "catalog.json" : "catalog", o = i.subscribe(r, ee.catalog);
4859
+ e.cleanup(() => o.close());
4860
+ const c = s === "hang" ? async () => zs(o) : async () => {
4861
+ const a = await dr(o);
4862
+ return a ? gr(a) : void 0;
4739
4863
  };
4740
4864
  e.spawn(async () => {
4741
4865
  try {
4742
4866
  for (; ; ) {
4743
- const u = await Promise.race([e.cancel, c()]);
4744
- if (!u) break;
4745
- console.debug("received catalog", r, this.name.peek(), u), this.#t.set(u), this.status.set("live");
4867
+ const a = await Promise.race([e.cancel, c()]);
4868
+ if (!a) break;
4869
+ console.debug("received catalog", s, this.name.peek(), a), this.catalog.set(a), this.status.set("live");
4746
4870
  }
4747
- } catch (u) {
4748
- console.warn("error fetching catalog", this.name.peek(), u);
4871
+ } catch (a) {
4872
+ console.warn("error fetching catalog", this.name.peek(), a);
4749
4873
  } finally {
4750
- this.#t.set(void 0), this.status.set("offline");
4874
+ this.catalog.set(void 0), this.status.set("offline");
4751
4875
  }
4752
4876
  });
4753
4877
  }
@@ -4756,25 +4880,26 @@ class mr {
4756
4880
  }
4757
4881
  }
4758
4882
  export {
4759
- mr as B,
4760
- Ri as D,
4761
- Ti as E,
4762
- Oi as M,
4883
+ Tr as B,
4884
+ kr as C,
4885
+ Zi as D,
4886
+ Ni as E,
4887
+ qi as M,
4763
4888
  ee as P,
4764
- Li as R,
4765
- $i as S,
4889
+ Gi as R,
4890
+ Ji as S,
4766
4891
  m as a,
4767
- Ee as b,
4768
- Mi as c,
4769
- Vi as d,
4770
- Hi as e,
4771
- cr as f,
4772
- zt as g,
4773
- fr as h,
4774
- Le as i,
4775
- lr as m,
4892
+ Ce as b,
4893
+ Li as c,
4894
+ tr as d,
4895
+ ir as e,
4896
+ br as f,
4897
+ xt as g,
4898
+ Mr as h,
4899
+ $e as i,
4900
+ Ar as m,
4776
4901
  S as o,
4777
- b as s,
4778
- Ft as t
4902
+ v as s,
4903
+ Wt as t
4779
4904
  };
4780
- //# sourceMappingURL=broadcast-BImEYz4N.js.map
4905
+ //# sourceMappingURL=broadcast-b74Ew4Ql.js.map