@moq/watch 0.2.4 → 0.2.6

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,5 +1,5 @@
1
1
  import * as _ from "@moq/lite";
2
- import { Time as w, Path as On } from "@moq/lite";
2
+ import { Time as p, Path as zn } from "@moq/lite";
3
3
  import { Signal as h, Effect as T } from "@moq/signals";
4
4
  function v(n, e, t) {
5
5
  function s(o, c) {
@@ -40,19 +40,19 @@ class H extends Error {
40
40
  super("Encountered Promise during synchronous parse. Use .parseAsync() instead.");
41
41
  }
42
42
  }
43
- class zn extends Error {
43
+ class Nn extends Error {
44
44
  constructor(e) {
45
45
  super(`Encountered unidirectional transform during encode: ${e}`), this.name = "ZodEncodeError";
46
46
  }
47
47
  }
48
- const Nn = {};
48
+ const qn = {};
49
49
  function K(n) {
50
- return Nn;
50
+ return qn;
51
51
  }
52
- function qn(n, e) {
52
+ function Dn(n, e) {
53
53
  return typeof e == "bigint" ? e.toString() : e;
54
54
  }
55
- function $e(n) {
55
+ function je(n) {
56
56
  return {
57
57
  get value() {
58
58
  {
@@ -62,7 +62,7 @@ function $e(n) {
62
62
  }
63
63
  };
64
64
  }
65
- function je(n) {
65
+ function Ge(n) {
66
66
  const e = n.startsWith("^") ? 1 : 0, t = n.endsWith("$") ? n.length - 1 : n.length;
67
67
  return n.slice(e, t);
68
68
  }
@@ -83,12 +83,12 @@ function I(n, e, t) {
83
83
  configurable: !0
84
84
  });
85
85
  }
86
- const Ge = "captureStackTrace" in Error ? Error.captureStackTrace : (...n) => {
86
+ const Ze = "captureStackTrace" in Error ? Error.captureStackTrace : (...n) => {
87
87
  };
88
88
  function de(n) {
89
89
  return typeof n == "object" && n !== null && !Array.isArray(n);
90
90
  }
91
- function Ze(n) {
91
+ function Xe(n) {
92
92
  if (de(n) === !1)
93
93
  return !1;
94
94
  const e = n.constructor;
@@ -97,23 +97,23 @@ function Ze(n) {
97
97
  const t = e.prototype;
98
98
  return !(de(t) === !1 || Object.prototype.hasOwnProperty.call(t, "isPrototypeOf") === !1);
99
99
  }
100
- function Dn(n) {
101
- return Ze(n) ? { ...n } : Array.isArray(n) ? [...n] : n;
100
+ function xn(n) {
101
+ return Xe(n) ? { ...n } : Array.isArray(n) ? [...n] : n;
102
102
  }
103
103
  function Ae(n) {
104
104
  return n.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
105
105
  }
106
- function xn(n, e, t) {
106
+ function Cn(n, e, t) {
107
107
  const s = new n._zod.constr(e ?? n._zod.def);
108
108
  return (!e || t?.parent) && (s._zod.parent = n), s;
109
109
  }
110
- function M(n) {
110
+ function P(n) {
111
111
  return {};
112
112
  }
113
- function Cn(n) {
113
+ function Fn(n) {
114
114
  return Object.keys(n).filter((e) => n[e]._zod.optin === "optional" && n[e]._zod.optout === "optional");
115
115
  }
116
- const Fn = {
116
+ const Vn = {
117
117
  safeint: [Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER],
118
118
  int32: [-2147483648, 2147483647],
119
119
  uint32: [0, 4294967295],
@@ -145,62 +145,62 @@ function Y(n, e, t) {
145
145
  }
146
146
  return delete s.inst, delete s.continue, e?.reportInput || delete s.input, s;
147
147
  }
148
- const Xe = (n, e) => {
148
+ const He = (n, e) => {
149
149
  n.name = "$ZodError", Object.defineProperty(n, "_zod", {
150
150
  value: n._zod,
151
151
  enumerable: !1
152
152
  }), Object.defineProperty(n, "issues", {
153
153
  value: e,
154
154
  enumerable: !1
155
- }), n.message = JSON.stringify(e, qn, 2), Object.defineProperty(n, "toString", {
155
+ }), n.message = JSON.stringify(e, Dn, 2), Object.defineProperty(n, "toString", {
156
156
  value: () => n.message,
157
157
  enumerable: !1
158
158
  });
159
- }, Vn = v("$ZodError", Xe), fe = v("$ZodError", Xe, { Parent: Error }), Bn = (n) => (e, t, s, r) => {
159
+ }, Bn = v("$ZodError", He), fe = v("$ZodError", He, { Parent: Error }), Ln = (n) => (e, t, s, r) => {
160
160
  const i = s ? Object.assign(s, { async: !1 }) : { async: !1 }, a = e._zod.run({ value: t, issues: [] }, i);
161
161
  if (a instanceof Promise)
162
162
  throw new H();
163
163
  if (a.issues.length) {
164
164
  const o = new (r?.Err ?? n)(a.issues.map((c) => Y(c, i, K())));
165
- throw Ge(o, r?.callee), o;
165
+ throw Ze(o, r?.callee), o;
166
166
  }
167
167
  return a.value;
168
- }, Ln = /* @__PURE__ */ Bn(fe), $n = (n) => async (e, t, s, r) => {
168
+ }, $n = /* @__PURE__ */ Ln(fe), jn = (n) => async (e, t, s, r) => {
169
169
  const i = s ? Object.assign(s, { async: !0 }) : { async: !0 };
170
170
  let a = e._zod.run({ value: t, issues: [] }, i);
171
171
  if (a instanceof Promise && (a = await a), a.issues.length) {
172
172
  const o = new (r?.Err ?? n)(a.issues.map((c) => Y(c, i, K())));
173
- throw Ge(o, r?.callee), o;
173
+ throw Ze(o, r?.callee), o;
174
174
  }
175
175
  return a.value;
176
- }, jn = /* @__PURE__ */ $n(fe), Gn = (n) => (e, t, s) => {
176
+ }, Gn = /* @__PURE__ */ jn(fe), Zn = (n) => (e, t, s) => {
177
177
  const r = s ? { ...s, async: !1 } : { async: !1 }, i = e._zod.run({ value: t, issues: [] }, r);
178
178
  if (i instanceof Promise)
179
179
  throw new H();
180
180
  return i.issues.length ? {
181
181
  success: !1,
182
- error: new (n ?? Vn)(i.issues.map((a) => Y(a, r, K())))
182
+ error: new (n ?? Bn)(i.issues.map((a) => Y(a, r, K())))
183
183
  } : { success: !0, data: i.value };
184
- }, He = /* @__PURE__ */ Gn(fe), Zn = (n) => async (e, t, s) => {
184
+ }, We = /* @__PURE__ */ Zn(fe), Xn = (n) => async (e, t, s) => {
185
185
  const r = s ? Object.assign(s, { async: !0 }) : { async: !0 };
186
186
  let i = e._zod.run({ value: t, issues: [] }, r);
187
187
  return i instanceof Promise && (i = await i), i.issues.length ? {
188
188
  success: !1,
189
189
  error: new n(i.issues.map((a) => Y(a, r, K())))
190
190
  } : { success: !0, data: i.value };
191
- }, We = /* @__PURE__ */ Zn(fe), Xn = (n) => {
191
+ }, Ke = /* @__PURE__ */ Xn(fe), Hn = (n) => {
192
192
  const e = n ? `[\\s\\S]{${n?.minimum ?? 0},${n?.maximum ?? ""}}` : "[\\s\\S]*";
193
193
  return new RegExp(`^${e}$`);
194
- }, Hn = /^-?\d+$/, Ke = /^-?\d+(?:\.\d+)?$/, Wn = /^(?:true|false)$/i, be = /* @__PURE__ */ v("$ZodCheck", (n, e) => {
194
+ }, Wn = /^-?\d+$/, Ye = /^-?\d+(?:\.\d+)?$/, Kn = /^(?:true|false)$/i, be = /* @__PURE__ */ v("$ZodCheck", (n, e) => {
195
195
  var t;
196
196
  n._zod ?? (n._zod = {}), n._zod.def = e, (t = n._zod).onattach ?? (t.onattach = []);
197
- }), Ye = {
197
+ }), Je = {
198
198
  number: "number",
199
199
  bigint: "bigint",
200
200
  object: "date"
201
- }, Kn = /* @__PURE__ */ v("$ZodCheckLessThan", (n, e) => {
201
+ }, Yn = /* @__PURE__ */ v("$ZodCheckLessThan", (n, e) => {
202
202
  be.init(n, e);
203
- const t = Ye[typeof e.value];
203
+ const t = Je[typeof e.value];
204
204
  n._zod.onattach.push((s) => {
205
205
  const r = s._zod.bag, i = (e.inclusive ? r.maximum : r.exclusiveMaximum) ?? Number.POSITIVE_INFINITY;
206
206
  e.value < i && (e.inclusive ? r.maximum = e.value : r.exclusiveMaximum = e.value);
@@ -215,9 +215,9 @@ const Xe = (n, e) => {
215
215
  continue: !e.abort
216
216
  });
217
217
  };
218
- }), Yn = /* @__PURE__ */ v("$ZodCheckGreaterThan", (n, e) => {
218
+ }), Jn = /* @__PURE__ */ v("$ZodCheckGreaterThan", (n, e) => {
219
219
  be.init(n, e);
220
- const t = Ye[typeof e.value];
220
+ const t = Je[typeof e.value];
221
221
  n._zod.onattach.push((s) => {
222
222
  const r = s._zod.bag, i = (e.inclusive ? r.minimum : r.exclusiveMinimum) ?? Number.NEGATIVE_INFINITY;
223
223
  e.value > i && (e.inclusive ? r.minimum = e.value : r.exclusiveMinimum = e.value);
@@ -232,12 +232,12 @@ const Xe = (n, e) => {
232
232
  continue: !e.abort
233
233
  });
234
234
  };
235
- }), Jn = /* @__PURE__ */ v("$ZodCheckNumberFormat", (n, e) => {
235
+ }), Qn = /* @__PURE__ */ v("$ZodCheckNumberFormat", (n, e) => {
236
236
  be.init(n, e), e.format = e.format || "float64";
237
- const t = e.format?.includes("int"), s = t ? "int" : "number", [r, i] = Fn[e.format];
237
+ const t = e.format?.includes("int"), s = t ? "int" : "number", [r, i] = Vn[e.format];
238
238
  n._zod.onattach.push((a) => {
239
239
  const o = a._zod.bag;
240
- o.format = e.format, o.minimum = r, o.maximum = i, t && (o.pattern = Hn);
240
+ o.format = e.format, o.minimum = r, o.maximum = i, t && (o.pattern = Wn);
241
241
  }), n._zod.check = (a) => {
242
242
  const o = a.value;
243
243
  if (t) {
@@ -293,13 +293,13 @@ const Xe = (n, e) => {
293
293
  continue: !e.abort
294
294
  });
295
295
  };
296
- }), Qn = {
296
+ }), et = {
297
297
  major: 4,
298
298
  minor: 3,
299
299
  patch: 6
300
300
  }, U = /* @__PURE__ */ v("$ZodType", (n, e) => {
301
301
  var t;
302
- n ?? (n = {}), n._zod.def = e, n._zod.bag = n._zod.bag || {}, n._zod.version = Qn;
302
+ n ?? (n = {}), n._zod.def = e, n._zod.bag = n._zod.bag || {}, n._zod.version = et;
303
303
  const s = [...n._zod.def.checks ?? []];
304
304
  n._zod.traits.has("$ZodCheck") && s.unshift(n);
305
305
  for (const r of s)
@@ -318,12 +318,12 @@ const Xe = (n, e) => {
318
318
  continue;
319
319
  } else if (u)
320
320
  continue;
321
- const f = a.issues.length, p = l._zod.check(a);
322
- if (p instanceof Promise && c?.async === !1)
321
+ const f = a.issues.length, w = l._zod.check(a);
322
+ if (w instanceof Promise && c?.async === !1)
323
323
  throw new H();
324
- if (d || p instanceof Promise)
324
+ if (d || w instanceof Promise)
325
325
  d = (d ?? Promise.resolve()).then(async () => {
326
- await p, a.issues.length !== f && (u || (u = ee(a, f)));
326
+ await w, a.issues.length !== f && (u || (u = ee(a, f)));
327
327
  });
328
328
  else {
329
329
  if (a.issues.length === f)
@@ -362,17 +362,17 @@ const Xe = (n, e) => {
362
362
  I(n, "~standard", () => ({
363
363
  validate: (r) => {
364
364
  try {
365
- const i = He(n, r);
365
+ const i = We(n, r);
366
366
  return i.success ? { value: i.data } : { issues: i.error?.issues };
367
367
  } catch {
368
- return We(n, r).then((a) => a.success ? { value: a.data } : { issues: a.error?.issues });
368
+ return Ke(n, r).then((a) => a.success ? { value: a.data } : { issues: a.error?.issues });
369
369
  }
370
370
  },
371
371
  vendor: "zod",
372
372
  version: 1
373
373
  }));
374
- }), et = /* @__PURE__ */ v("$ZodString", (n, e) => {
375
- U.init(n, e), n._zod.pattern = [...n?._zod.bag?.patterns ?? []].pop() ?? Xn(n._zod.bag), n._zod.parse = (t, s) => {
374
+ }), nt = /* @__PURE__ */ v("$ZodString", (n, e) => {
375
+ U.init(n, e), n._zod.pattern = [...n?._zod.bag?.patterns ?? []].pop() ?? Hn(n._zod.bag), n._zod.parse = (t, s) => {
376
376
  if (e.coerce)
377
377
  try {
378
378
  t.value = String(t.value);
@@ -385,8 +385,8 @@ const Xe = (n, e) => {
385
385
  inst: n
386
386
  }), t;
387
387
  };
388
- }), Je = /* @__PURE__ */ v("$ZodNumber", (n, e) => {
389
- U.init(n, e), n._zod.pattern = n._zod.bag.pattern ?? Ke, n._zod.parse = (t, s) => {
388
+ }), Qe = /* @__PURE__ */ v("$ZodNumber", (n, e) => {
389
+ U.init(n, e), n._zod.pattern = n._zod.bag.pattern ?? Ye, n._zod.parse = (t, s) => {
390
390
  if (e.coerce)
391
391
  try {
392
392
  t.value = Number(t.value);
@@ -404,10 +404,10 @@ const Xe = (n, e) => {
404
404
  ...i ? { received: i } : {}
405
405
  }), t;
406
406
  };
407
- }), nt = /* @__PURE__ */ v("$ZodNumberFormat", (n, e) => {
408
- Jn.init(n, e), Je.init(n, e);
409
- }), tt = /* @__PURE__ */ v("$ZodBoolean", (n, e) => {
410
- U.init(n, e), n._zod.pattern = Wn, n._zod.parse = (t, s) => {
407
+ }), tt = /* @__PURE__ */ v("$ZodNumberFormat", (n, e) => {
408
+ Qn.init(n, e), Qe.init(n, e);
409
+ }), st = /* @__PURE__ */ v("$ZodBoolean", (n, e) => {
410
+ U.init(n, e), n._zod.pattern = Kn, n._zod.parse = (t, s) => {
411
411
  if (e.coerce)
412
412
  try {
413
413
  t.value = !!t.value;
@@ -425,7 +425,7 @@ const Xe = (n, e) => {
425
425
  function Ie(n, e, t) {
426
426
  n.issues.length && e.issues.push(...Z(t, n.issues)), e.value[t] = n.value;
427
427
  }
428
- const st = /* @__PURE__ */ v("$ZodArray", (n, e) => {
428
+ const rt = /* @__PURE__ */ v("$ZodArray", (n, e) => {
429
429
  U.init(n, e), n._zod.parse = (t, s) => {
430
430
  const r = t.value;
431
431
  if (!Array.isArray(r))
@@ -455,12 +455,12 @@ function le(n, e, t, s, r) {
455
455
  }
456
456
  n.value === void 0 ? t in s && (e.value[t] = void 0) : e.value[t] = n.value;
457
457
  }
458
- function rt(n) {
458
+ function it(n) {
459
459
  const e = Object.keys(n.shape);
460
460
  for (const s of e)
461
461
  if (!n.shape?.[s]?._zod?.traits?.has("$ZodType"))
462
462
  throw new Error(`Invalid element at key "${s}": expected a Zod schema`);
463
- const t = Cn(n.shape);
463
+ const t = Fn(n.shape);
464
464
  return {
465
465
  ...n,
466
466
  keys: e,
@@ -469,7 +469,7 @@ function rt(n) {
469
469
  optionalKeys: new Set(t)
470
470
  };
471
471
  }
472
- function it(n, e, t, s, r, i) {
472
+ function at(n, e, t, s, r, i) {
473
473
  const a = [], o = r.keySet, c = r.catchall._zod, u = c.def.type, d = c.optout === "optional";
474
474
  for (const l in e) {
475
475
  if (o.has(l))
@@ -479,7 +479,7 @@ function it(n, e, t, s, r, i) {
479
479
  continue;
480
480
  }
481
481
  const f = c.run({ value: e[l], issues: [] }, s);
482
- f instanceof Promise ? n.push(f.then((p) => le(p, t, l, e, d))) : le(f, t, l, e, d);
482
+ f instanceof Promise ? n.push(f.then((w) => le(w, t, l, e, d))) : le(f, t, l, e, d);
483
483
  }
484
484
  return a.length && t.issues.push({
485
485
  code: "unrecognized_keys",
@@ -488,7 +488,7 @@ function it(n, e, t, s, r, i) {
488
488
  inst: i
489
489
  }), n.length ? Promise.all(n).then(() => t) : t;
490
490
  }
491
- const at = /* @__PURE__ */ v("$ZodObject", (n, e) => {
491
+ const ot = /* @__PURE__ */ v("$ZodObject", (n, e) => {
492
492
  if (U.init(n, e), !Object.getOwnPropertyDescriptor(e, "shape")?.get) {
493
493
  const o = e.shape;
494
494
  Object.defineProperty(e, "shape", {
@@ -500,7 +500,7 @@ const at = /* @__PURE__ */ v("$ZodObject", (n, e) => {
500
500
  }
501
501
  });
502
502
  }
503
- const s = $e(() => rt(e));
503
+ const s = je(() => it(e));
504
504
  I(n._zod, "propValues", () => {
505
505
  const o = e.shape, c = {};
506
506
  for (const u in o) {
@@ -528,10 +528,10 @@ const at = /* @__PURE__ */ v("$ZodObject", (n, e) => {
528
528
  o.value = {};
529
529
  const d = [], l = a.shape;
530
530
  for (const f of a.keys) {
531
- const p = l[f], b = p._zod.optout === "optional", g = p._zod.run({ value: u[f], issues: [] }, c);
531
+ const w = l[f], b = w._zod.optout === "optional", g = w._zod.run({ value: u[f], issues: [] }, c);
532
532
  g instanceof Promise ? d.push(g.then((R) => le(R, o, f, u, b))) : le(g, o, f, u, b);
533
533
  }
534
- return i ? it(d, u, o, c, s.value, n) : d.length ? Promise.all(d).then(() => o) : o;
534
+ return i ? at(d, u, o, c, s.value, n) : d.length ? Promise.all(d).then(() => o) : o;
535
535
  };
536
536
  });
537
537
  function Re(n, e, t, s) {
@@ -546,14 +546,14 @@ function Re(n, e, t, s) {
546
546
  errors: n.map((i) => i.issues.map((a) => Y(a, s, K())))
547
547
  }), e);
548
548
  }
549
- const Qe = /* @__PURE__ */ v("$ZodUnion", (n, e) => {
549
+ const en = /* @__PURE__ */ v("$ZodUnion", (n, e) => {
550
550
  U.init(n, e), I(n._zod, "optin", () => e.options.some((r) => r._zod.optin === "optional") ? "optional" : void 0), I(n._zod, "optout", () => e.options.some((r) => r._zod.optout === "optional") ? "optional" : void 0), I(n._zod, "values", () => {
551
551
  if (e.options.every((r) => r._zod.values))
552
552
  return new Set(e.options.flatMap((r) => Array.from(r._zod.values)));
553
553
  }), I(n._zod, "pattern", () => {
554
554
  if (e.options.every((r) => r._zod.pattern)) {
555
555
  const r = e.options.map((i) => i._zod.pattern);
556
- return new RegExp(`^(${r.map((i) => je(i.source)).join("|")})$`);
556
+ return new RegExp(`^(${r.map((i) => Ge(i.source)).join("|")})$`);
557
557
  }
558
558
  });
559
559
  const t = e.options.length === 1, s = e.options[0]._zod.run;
@@ -577,8 +577,8 @@ const Qe = /* @__PURE__ */ v("$ZodUnion", (n, e) => {
577
577
  }
578
578
  return a ? Promise.all(o).then((c) => Re(c, r, n, i)) : Re(o, r, n, i);
579
579
  };
580
- }), ot = /* @__PURE__ */ v("$ZodDiscriminatedUnion", (n, e) => {
581
- e.inclusive = !1, Qe.init(n, e);
580
+ }), ct = /* @__PURE__ */ v("$ZodDiscriminatedUnion", (n, e) => {
581
+ e.inclusive = !1, en.init(n, e);
582
582
  const t = n._zod.parse;
583
583
  I(n._zod, "propValues", () => {
584
584
  const r = {};
@@ -594,7 +594,7 @@ const Qe = /* @__PURE__ */ v("$ZodUnion", (n, e) => {
594
594
  }
595
595
  return r;
596
596
  });
597
- const s = $e(() => {
597
+ const s = je(() => {
598
598
  const r = e.options, i = /* @__PURE__ */ new Map();
599
599
  for (const a of r) {
600
600
  const o = a._zod.propValues?.[e.discriminator];
@@ -628,10 +628,10 @@ const Qe = /* @__PURE__ */ v("$ZodUnion", (n, e) => {
628
628
  inst: n
629
629
  }), r);
630
630
  };
631
- }), ct = /* @__PURE__ */ v("$ZodRecord", (n, e) => {
631
+ }), ut = /* @__PURE__ */ v("$ZodRecord", (n, e) => {
632
632
  U.init(n, e), n._zod.parse = (t, s) => {
633
633
  const r = t.value;
634
- if (!Ze(r))
634
+ if (!Xe(r))
635
635
  return t.issues.push({
636
636
  expected: "record",
637
637
  code: "invalid_type",
@@ -667,7 +667,7 @@ const Qe = /* @__PURE__ */ v("$ZodUnion", (n, e) => {
667
667
  let c = e.keyType._zod.run({ value: o, issues: [] }, s);
668
668
  if (c instanceof Promise)
669
669
  throw new Error("Async schemas not supported in object keys currently");
670
- if (typeof o == "string" && Ke.test(o) && c.issues.length) {
670
+ if (typeof o == "string" && Ye.test(o) && c.issues.length) {
671
671
  const l = e.keyType._zod.run({ value: Number(o), issues: [] }, s);
672
672
  if (l instanceof Promise)
673
673
  throw new Error("Async schemas not supported in object keys currently");
@@ -692,7 +692,7 @@ const Qe = /* @__PURE__ */ v("$ZodUnion", (n, e) => {
692
692
  }
693
693
  return i.length ? Promise.all(i).then(() => t) : t;
694
694
  };
695
- }), ut = /* @__PURE__ */ v("$ZodLiteral", (n, e) => {
695
+ }), dt = /* @__PURE__ */ v("$ZodLiteral", (n, e) => {
696
696
  if (U.init(n, e), e.values.length === 0)
697
697
  throw new Error("Cannot create literal schema with no valid values");
698
698
  const t = new Set(e.values);
@@ -705,10 +705,10 @@ const Qe = /* @__PURE__ */ v("$ZodUnion", (n, e) => {
705
705
  inst: n
706
706
  }), s;
707
707
  };
708
- }), dt = /* @__PURE__ */ v("$ZodTransform", (n, e) => {
708
+ }), lt = /* @__PURE__ */ v("$ZodTransform", (n, e) => {
709
709
  U.init(n, e), n._zod.parse = (t, s) => {
710
710
  if (s.direction === "backward")
711
- throw new zn(n.constructor.name);
711
+ throw new Nn(n.constructor.name);
712
712
  const r = e.transform(t.value, t);
713
713
  if (s.async)
714
714
  return (r instanceof Promise ? r : Promise.resolve(r)).then((a) => (t.value = a, t));
@@ -720,10 +720,10 @@ const Qe = /* @__PURE__ */ v("$ZodUnion", (n, e) => {
720
720
  function Ee(n, e) {
721
721
  return n.issues.length && e === void 0 ? { issues: [], value: void 0 } : n;
722
722
  }
723
- const lt = /* @__PURE__ */ v("$ZodOptional", (n, e) => {
723
+ const ht = /* @__PURE__ */ v("$ZodOptional", (n, e) => {
724
724
  U.init(n, e), n._zod.optin = "optional", n._zod.optout = "optional", I(n._zod, "values", () => e.innerType._zod.values ? /* @__PURE__ */ new Set([...e.innerType._zod.values, void 0]) : void 0), I(n._zod, "pattern", () => {
725
725
  const t = e.innerType._zod.pattern;
726
- return t ? new RegExp(`^(${je(t.source)})?$`) : void 0;
726
+ return t ? new RegExp(`^(${Ge(t.source)})?$`) : void 0;
727
727
  }), n._zod.parse = (t, s) => {
728
728
  if (e.innerType._zod.optin === "optional") {
729
729
  const r = e.innerType._zod.run(t, s);
@@ -731,7 +731,7 @@ const lt = /* @__PURE__ */ v("$ZodOptional", (n, e) => {
731
731
  }
732
732
  return t.value === void 0 ? t : e.innerType._zod.run(t, s);
733
733
  };
734
- }), ht = /* @__PURE__ */ v("$ZodDefault", (n, e) => {
734
+ }), ft = /* @__PURE__ */ v("$ZodDefault", (n, e) => {
735
735
  U.init(n, e), n._zod.optin = "optional", I(n._zod, "values", () => e.innerType._zod.values), n._zod.parse = (t, s) => {
736
736
  if (s.direction === "backward")
737
737
  return e.innerType._zod.run(t, s);
@@ -744,7 +744,7 @@ const lt = /* @__PURE__ */ v("$ZodOptional", (n, e) => {
744
744
  function Te(n, e) {
745
745
  return n.value === void 0 && (n.value = e.defaultValue), n;
746
746
  }
747
- const ft = /* @__PURE__ */ v("$ZodPipe", (n, e) => {
747
+ const mt = /* @__PURE__ */ v("$ZodPipe", (n, e) => {
748
748
  U.init(n, e), I(n._zod, "values", () => e.in._zod.values), I(n._zod, "optin", () => e.in._zod.optin), I(n._zod, "optout", () => e.out._zod.optout), I(n._zod, "propValues", () => e.in._zod.propValues), n._zod.parse = (t, s) => {
749
749
  if (s.direction === "backward") {
750
750
  const i = e.out._zod.run(t, s);
@@ -758,7 +758,7 @@ function ue(n, e, t) {
758
758
  return n.issues.length ? (n.aborted = !0, n) : e._zod.run({ value: n.value, issues: n.issues }, t);
759
759
  }
760
760
  var Ue;
761
- class mt {
761
+ class pt {
762
762
  constructor() {
763
763
  this._map = /* @__PURE__ */ new WeakMap(), this._idmap = /* @__PURE__ */ new Map();
764
764
  }
@@ -787,223 +787,223 @@ class mt {
787
787
  return this._map.has(e);
788
788
  }
789
789
  }
790
- function pt() {
791
- return new mt();
790
+ function wt() {
791
+ return new pt();
792
792
  }
793
- (Ue = globalThis).__zod_globalRegistry ?? (Ue.__zod_globalRegistry = pt());
793
+ (Ue = globalThis).__zod_globalRegistry ?? (Ue.__zod_globalRegistry = wt());
794
794
  // @__NO_SIDE_EFFECTS__
795
- function wt(n, e) {
795
+ function vt(n, e) {
796
796
  return new n({
797
797
  type: "string",
798
- ...M()
798
+ ...P()
799
799
  });
800
800
  }
801
801
  // @__NO_SIDE_EFFECTS__
802
- function vt(n, e) {
802
+ function bt(n, e) {
803
803
  return new n({
804
804
  type: "number",
805
805
  checks: [],
806
- ...M()
806
+ ...P()
807
807
  });
808
808
  }
809
809
  // @__NO_SIDE_EFFECTS__
810
- function bt(n, e) {
810
+ function gt(n, e) {
811
811
  return new n({
812
812
  type: "number",
813
813
  check: "number_format",
814
814
  abort: !1,
815
815
  format: "safeint",
816
- ...M()
816
+ ...P()
817
817
  });
818
818
  }
819
819
  // @__NO_SIDE_EFFECTS__
820
- function gt(n, e) {
820
+ function yt(n, e) {
821
821
  return new n({
822
822
  type: "boolean",
823
- ...M()
823
+ ...P()
824
824
  });
825
825
  }
826
826
  // @__NO_SIDE_EFFECTS__
827
- function en(n, e) {
828
- return new Kn({
827
+ function nn(n, e) {
828
+ return new Yn({
829
829
  check: "less_than",
830
- ...M(),
830
+ ...P(),
831
831
  value: n,
832
832
  inclusive: !0
833
833
  });
834
834
  }
835
835
  // @__NO_SIDE_EFFECTS__
836
- function yt(n, e) {
837
- return new Yn({
836
+ function _t(n, e) {
837
+ return new Jn({
838
838
  check: "greater_than",
839
- ...M(),
839
+ ...P(),
840
840
  value: n,
841
841
  inclusive: !0
842
842
  });
843
843
  }
844
844
  // @__NO_SIDE_EFFECTS__
845
- function nn(n) {
846
- return /* @__PURE__ */ yt(0);
845
+ function tn(n) {
846
+ return /* @__PURE__ */ _t(0);
847
847
  }
848
- const P = /* @__PURE__ */ v("ZodMiniType", (n, e) => {
848
+ const M = /* @__PURE__ */ v("ZodMiniType", (n, e) => {
849
849
  if (!n._zod)
850
850
  throw new Error("Uninitialized schema in ZodMiniType.");
851
- U.init(n, e), n.def = e, n.type = e.type, n.parse = (t, s) => Ln(n, t, s, { callee: n.parse }), n.safeParse = (t, s) => He(n, t, s), n.parseAsync = async (t, s) => jn(n, t, s, { callee: n.parseAsync }), n.safeParseAsync = async (t, s) => We(n, t, s), n.check = (...t) => n.clone({
851
+ U.init(n, e), n.def = e, n.type = e.type, n.parse = (t, s) => $n(n, t, s, { callee: n.parse }), n.safeParse = (t, s) => We(n, t, s), n.parseAsync = async (t, s) => Gn(n, t, s, { callee: n.parseAsync }), n.safeParseAsync = async (t, s) => Ke(n, t, s), n.check = (...t) => n.clone({
852
852
  ...e,
853
853
  checks: [
854
854
  ...e.checks ?? [],
855
855
  ...t.map((s) => typeof s == "function" ? { _zod: { check: s, def: { check: "custom" }, onattach: [] } } : s)
856
856
  ]
857
- }, { parent: !0 }), n.with = n.check, n.clone = (t, s) => xn(n, t, s), n.brand = () => n, n.register = ((t, s) => (t.add(n, s), n)), n.apply = (t) => t(n);
858
- }), _t = /* @__PURE__ */ v("ZodMiniString", (n, e) => {
859
- et.init(n, e), P.init(n, e);
857
+ }, { parent: !0 }), n.with = n.check, n.clone = (t, s) => Cn(n, t, s), n.brand = () => n, n.register = ((t, s) => (t.add(n, s), n)), n.apply = (t) => t(n);
858
+ }), St = /* @__PURE__ */ v("ZodMiniString", (n, e) => {
859
+ nt.init(n, e), M.init(n, e);
860
860
  });
861
861
  // @__NO_SIDE_EFFECTS__
862
862
  function y(n) {
863
- return /* @__PURE__ */ wt(_t);
863
+ return /* @__PURE__ */ vt(St);
864
864
  }
865
- const tn = /* @__PURE__ */ v("ZodMiniNumber", (n, e) => {
866
- Je.init(n, e), P.init(n, e);
865
+ const sn = /* @__PURE__ */ v("ZodMiniNumber", (n, e) => {
866
+ Qe.init(n, e), M.init(n, e);
867
867
  });
868
868
  // @__NO_SIDE_EFFECTS__
869
869
  function B(n) {
870
- return /* @__PURE__ */ vt(tn);
870
+ return /* @__PURE__ */ bt(sn);
871
871
  }
872
- const St = /* @__PURE__ */ v("ZodMiniNumberFormat", (n, e) => {
873
- nt.init(n, e), tn.init(n, e);
872
+ const kt = /* @__PURE__ */ v("ZodMiniNumberFormat", (n, e) => {
873
+ tt.init(n, e), sn.init(n, e);
874
874
  });
875
875
  // @__NO_SIDE_EFFECTS__
876
- function sn(n) {
877
- return /* @__PURE__ */ bt(St);
876
+ function rn(n) {
877
+ return /* @__PURE__ */ gt(kt);
878
878
  }
879
- const kt = /* @__PURE__ */ v("ZodMiniBoolean", (n, e) => {
880
- tt.init(n, e), P.init(n, e);
879
+ const At = /* @__PURE__ */ v("ZodMiniBoolean", (n, e) => {
880
+ st.init(n, e), M.init(n, e);
881
881
  });
882
882
  // @__NO_SIDE_EFFECTS__
883
- function rn(n) {
884
- return /* @__PURE__ */ gt(kt);
883
+ function an(n) {
884
+ return /* @__PURE__ */ yt(At);
885
885
  }
886
- const At = /* @__PURE__ */ v("ZodMiniArray", (n, e) => {
887
- st.init(n, e), P.init(n, e);
886
+ const It = /* @__PURE__ */ v("ZodMiniArray", (n, e) => {
887
+ rt.init(n, e), M.init(n, e);
888
888
  });
889
889
  // @__NO_SIDE_EFFECTS__
890
890
  function j(n, e) {
891
- return new At({
891
+ return new It({
892
892
  type: "array",
893
893
  element: n,
894
- ...M()
894
+ ...P()
895
895
  });
896
896
  }
897
- const It = /* @__PURE__ */ v("ZodMiniObject", (n, e) => {
898
- at.init(n, e), P.init(n, e), I(n, "shape", () => e.shape);
897
+ const Rt = /* @__PURE__ */ v("ZodMiniObject", (n, e) => {
898
+ ot.init(n, e), M.init(n, e), I(n, "shape", () => e.shape);
899
899
  });
900
900
  // @__NO_SIDE_EFFECTS__
901
901
  function S(n, e) {
902
902
  const t = {
903
903
  type: "object",
904
904
  shape: n ?? {},
905
- ...M()
905
+ ...P()
906
906
  };
907
- return new It(t);
907
+ return new Rt(t);
908
908
  }
909
- const Rt = /* @__PURE__ */ v("ZodMiniUnion", (n, e) => {
910
- Qe.init(n, e), P.init(n, e);
909
+ const Et = /* @__PURE__ */ v("ZodMiniUnion", (n, e) => {
910
+ en.init(n, e), M.init(n, e);
911
911
  });
912
912
  // @__NO_SIDE_EFFECTS__
913
- function an(n, e) {
914
- return new Rt({
913
+ function on(n, e) {
914
+ return new Et({
915
915
  type: "union",
916
916
  options: n,
917
- ...M()
917
+ ...P()
918
918
  });
919
919
  }
920
- const Et = /* @__PURE__ */ v("ZodMiniDiscriminatedUnion", (n, e) => {
921
- ot.init(n, e), P.init(n, e);
920
+ const Tt = /* @__PURE__ */ v("ZodMiniDiscriminatedUnion", (n, e) => {
921
+ ct.init(n, e), M.init(n, e);
922
922
  });
923
923
  // @__NO_SIDE_EFFECTS__
924
- function Tt(n, e, t) {
925
- return new Et({
924
+ function Ut(n, e, t) {
925
+ return new Tt({
926
926
  type: "union",
927
927
  options: e,
928
928
  discriminator: n,
929
- ...M()
929
+ ...P()
930
930
  });
931
931
  }
932
- const Ut = /* @__PURE__ */ v("ZodMiniRecord", (n, e) => {
933
- ct.init(n, e), P.init(n, e);
932
+ const Mt = /* @__PURE__ */ v("ZodMiniRecord", (n, e) => {
933
+ ut.init(n, e), M.init(n, e);
934
934
  });
935
935
  // @__NO_SIDE_EFFECTS__
936
936
  function ge(n, e, t) {
937
- return new Ut({
937
+ return new Mt({
938
938
  type: "record",
939
939
  keyType: n,
940
940
  valueType: e,
941
- ...M()
941
+ ...P()
942
942
  });
943
943
  }
944
944
  const Pt = /* @__PURE__ */ v("ZodMiniLiteral", (n, e) => {
945
- ut.init(n, e), P.init(n, e);
945
+ dt.init(n, e), M.init(n, e);
946
946
  });
947
947
  // @__NO_SIDE_EFFECTS__
948
- function Pe(n, e) {
948
+ function Me(n, e) {
949
949
  return new Pt({
950
950
  type: "literal",
951
951
  values: Array.isArray(n) ? n : [n],
952
- ...M()
952
+ ...P()
953
953
  });
954
954
  }
955
- const Mt = /* @__PURE__ */ v("ZodMiniTransform", (n, e) => {
956
- dt.init(n, e), P.init(n, e);
955
+ const Ot = /* @__PURE__ */ v("ZodMiniTransform", (n, e) => {
956
+ lt.init(n, e), M.init(n, e);
957
957
  });
958
958
  // @__NO_SIDE_EFFECTS__
959
- function on(n) {
960
- return new Mt({
959
+ function cn(n) {
960
+ return new Ot({
961
961
  type: "transform",
962
962
  transform: n
963
963
  });
964
964
  }
965
- const Ot = /* @__PURE__ */ v("ZodMiniOptional", (n, e) => {
966
- lt.init(n, e), P.init(n, e);
965
+ const zt = /* @__PURE__ */ v("ZodMiniOptional", (n, e) => {
966
+ ht.init(n, e), M.init(n, e);
967
967
  });
968
968
  // @__NO_SIDE_EFFECTS__
969
969
  function m(n) {
970
- return new Ot({
970
+ return new zt({
971
971
  type: "optional",
972
972
  innerType: n
973
973
  });
974
974
  }
975
- const zt = /* @__PURE__ */ v("ZodMiniDefault", (n, e) => {
976
- ht.init(n, e), P.init(n, e);
975
+ const Nt = /* @__PURE__ */ v("ZodMiniDefault", (n, e) => {
976
+ ft.init(n, e), M.init(n, e);
977
977
  });
978
978
  // @__NO_SIDE_EFFECTS__
979
- function Nt(n, e) {
980
- return new zt({
979
+ function qt(n, e) {
980
+ return new Nt({
981
981
  type: "default",
982
982
  innerType: n,
983
983
  get defaultValue() {
984
- return typeof e == "function" ? e() : Dn(e);
984
+ return typeof e == "function" ? e() : xn(e);
985
985
  }
986
986
  });
987
987
  }
988
- const qt = /* @__PURE__ */ v("ZodMiniPipe", (n, e) => {
989
- ft.init(n, e), P.init(n, e);
988
+ const Dt = /* @__PURE__ */ v("ZodMiniPipe", (n, e) => {
989
+ mt.init(n, e), M.init(n, e);
990
990
  });
991
991
  // @__NO_SIDE_EFFECTS__
992
- function cn(n, e) {
993
- return new qt({
992
+ function un(n, e) {
993
+ return new Dt({
994
994
  type: "pipe",
995
995
  in: n,
996
996
  out: e
997
997
  });
998
998
  }
999
- (/* @__PURE__ */ B()).check(/* @__PURE__ */ sn(), /* @__PURE__ */ nn(), /* @__PURE__ */ en(255)).brand("u8");
1000
- const E = (/* @__PURE__ */ B()).check(/* @__PURE__ */ sn(), /* @__PURE__ */ nn(), /* @__PURE__ */ en(Number.MAX_SAFE_INTEGER)).brand("u53"), un = /* @__PURE__ */ Nt(
1001
- /* @__PURE__ */ Tt("kind", [
999
+ (/* @__PURE__ */ B()).check(/* @__PURE__ */ rn(), /* @__PURE__ */ tn(), /* @__PURE__ */ nn(255)).brand("u8");
1000
+ const E = (/* @__PURE__ */ B()).check(/* @__PURE__ */ rn(), /* @__PURE__ */ tn(), /* @__PURE__ */ nn(Number.MAX_SAFE_INTEGER)).brand("u53"), dn = /* @__PURE__ */ qt(
1001
+ /* @__PURE__ */ Ut("kind", [
1002
1002
  // The default hang container
1003
- /* @__PURE__ */ S({ kind: /* @__PURE__ */ Pe("legacy") }),
1003
+ /* @__PURE__ */ S({ kind: /* @__PURE__ */ Me("legacy") }),
1004
1004
  // CMAF container with timescale for timestamp conversion
1005
1005
  /* @__PURE__ */ S({
1006
- kind: /* @__PURE__ */ Pe("cmaf"),
1006
+ kind: /* @__PURE__ */ Me("cmaf"),
1007
1007
  // Time units per second
1008
1008
  timescale: E,
1009
1009
  // Track ID used in the moof/mdat fragments
@@ -1011,13 +1011,13 @@ const E = (/* @__PURE__ */ B()).check(/* @__PURE__ */ sn(), /* @__PURE__ */ nn()
1011
1011
  })
1012
1012
  ]),
1013
1013
  { kind: "legacy" }
1014
- ), Dt = /* @__PURE__ */ S({
1014
+ ), xt = /* @__PURE__ */ S({
1015
1015
  name: /* @__PURE__ */ y()
1016
- }), Me = /* @__PURE__ */ S({
1016
+ }), Pe = /* @__PURE__ */ S({
1017
1017
  // See: https://w3c.github.io/webcodecs/codec_registry.html
1018
1018
  codec: /* @__PURE__ */ y(),
1019
1019
  // The container format, used to decode the timestamp and more.
1020
- container: un,
1020
+ container: dn,
1021
1021
  // The description is used for some codecs.
1022
1022
  // If provided, we can initialize the decoder based on the catalog alone.
1023
1023
  // Otherwise, the initialization information is in-band.
@@ -1037,39 +1037,39 @@ const E = (/* @__PURE__ */ B()).check(/* @__PURE__ */ sn(), /* @__PURE__ */ nn()
1037
1037
  // NOTE: The audio "frame" duration depends on the codec, sample rate, etc.
1038
1038
  // ex: AAC often uses 1024 samples per frame, so at 44100Hz, this would be 1024/44100 = 23ms
1039
1039
  jitter: /* @__PURE__ */ m(E)
1040
- }), xt = /* @__PURE__ */ an([
1040
+ }), Ct = /* @__PURE__ */ on([
1041
1041
  /* @__PURE__ */ S({
1042
1042
  // A map of track name to rendition configuration.
1043
1043
  // This is not an array so it will work with JSON Merge Patch.
1044
- renditions: /* @__PURE__ */ ge(/* @__PURE__ */ y(), Me)
1044
+ renditions: /* @__PURE__ */ ge(/* @__PURE__ */ y(), Pe)
1045
1045
  }),
1046
1046
  // Backwards compatibility: transform old {track, config} format to new object format
1047
- /* @__PURE__ */ cn(
1047
+ /* @__PURE__ */ un(
1048
1048
  /* @__PURE__ */ S({
1049
- track: Dt,
1050
- config: Me
1049
+ track: xt,
1050
+ config: Pe
1051
1051
  }),
1052
- /* @__PURE__ */ on((n) => ({
1052
+ /* @__PURE__ */ cn((n) => ({
1053
1053
  renditions: { [n.track.name]: n.config }
1054
1054
  }))
1055
1055
  )
1056
- ]), Ct = /* @__PURE__ */ S({
1056
+ ]), Ft = /* @__PURE__ */ S({
1057
1057
  hardware: /* @__PURE__ */ m(/* @__PURE__ */ j(/* @__PURE__ */ y())),
1058
1058
  software: /* @__PURE__ */ m(/* @__PURE__ */ j(/* @__PURE__ */ y())),
1059
1059
  unsupported: /* @__PURE__ */ m(/* @__PURE__ */ j(/* @__PURE__ */ y()))
1060
- }), Ft = /* @__PURE__ */ S({
1060
+ }), Vt = /* @__PURE__ */ S({
1061
1061
  hardware: /* @__PURE__ */ m(/* @__PURE__ */ j(/* @__PURE__ */ y())),
1062
1062
  software: /* @__PURE__ */ m(/* @__PURE__ */ j(/* @__PURE__ */ y())),
1063
1063
  unsupported: /* @__PURE__ */ m(/* @__PURE__ */ j(/* @__PURE__ */ y()))
1064
- }), Vt = /* @__PURE__ */ S({
1065
- video: /* @__PURE__ */ m(Ct),
1066
- audio: /* @__PURE__ */ m(Ft)
1064
+ }), Bt = /* @__PURE__ */ S({
1065
+ video: /* @__PURE__ */ m(Ft),
1066
+ audio: /* @__PURE__ */ m(Vt)
1067
1067
  }), re = /* @__PURE__ */ S({
1068
1068
  name: /* @__PURE__ */ y()
1069
- }), Bt = /* @__PURE__ */ S({
1069
+ }), Lt = /* @__PURE__ */ S({
1070
1070
  message: /* @__PURE__ */ m(re),
1071
1071
  typing: /* @__PURE__ */ m(re)
1072
- }), dn = /* @__PURE__ */ S({
1072
+ }), ln = /* @__PURE__ */ S({
1073
1073
  // The relative X position of the broadcast, from -1 to +1.
1074
1074
  // This should be used for audio panning but can also be used for video positioning.
1075
1075
  x: /* @__PURE__ */ m(/* @__PURE__ */ B()),
@@ -1081,11 +1081,11 @@ const E = (/* @__PURE__ */ B()).check(/* @__PURE__ */ sn(), /* @__PURE__ */ nn()
1081
1081
  z: /* @__PURE__ */ m(/* @__PURE__ */ B()),
1082
1082
  // The scale of the broadcast, where 1 is 100%
1083
1083
  s: /* @__PURE__ */ m(/* @__PURE__ */ B())
1084
- }), Lt = /* @__PURE__ */ S({
1084
+ }), $t = /* @__PURE__ */ S({
1085
1085
  // The initial position of the broadcaster, from -1 to +1 in both dimensions.
1086
1086
  // If not provided, then the broadcaster is assumed to be at (0,0)
1087
1087
  // This should be used for audio panning but can also be used for video positioning.
1088
- initial: /* @__PURE__ */ m(dn),
1088
+ initial: /* @__PURE__ */ m(ln),
1089
1089
  // If provided, then updates to the position are done via a separate Moq track.
1090
1090
  // This is used to avoid a full catalog update every time we want to update a few bytes.
1091
1091
  // TODO: These updates currently use JSON for simplicity, but we should use a binary format.
@@ -1096,7 +1096,7 @@ const E = (/* @__PURE__ */ B()).check(/* @__PURE__ */ sn(), /* @__PURE__ */ nn()
1096
1096
  // If provided, this broadcaster is signaling the location of other peers.
1097
1097
  // The payload is a JSON blob keyed by handle for each peer.
1098
1098
  peers: /* @__PURE__ */ m(re)
1099
- }), fr = /* @__PURE__ */ ge(/* @__PURE__ */ y(), dn), W = {
1099
+ }), vr = /* @__PURE__ */ ge(/* @__PURE__ */ y(), ln), W = {
1100
1100
  catalog: 100,
1101
1101
  chat: 90,
1102
1102
  audio: 80,
@@ -1104,19 +1104,19 @@ const E = (/* @__PURE__ */ B()).check(/* @__PURE__ */ sn(), /* @__PURE__ */ nn()
1104
1104
  typing: 40,
1105
1105
  location: 20,
1106
1106
  preview: 10
1107
- }, $t = /* @__PURE__ */ S({
1107
+ }, jt = /* @__PURE__ */ S({
1108
1108
  id: /* @__PURE__ */ m(/* @__PURE__ */ y()),
1109
1109
  name: /* @__PURE__ */ m(/* @__PURE__ */ y()),
1110
1110
  avatar: /* @__PURE__ */ m(/* @__PURE__ */ y()),
1111
1111
  // TODO allow using a track instead of a URL?
1112
1112
  color: /* @__PURE__ */ m(/* @__PURE__ */ y())
1113
- }), jt = /* @__PURE__ */ S({
1113
+ }), Gt = /* @__PURE__ */ S({
1114
1114
  name: /* @__PURE__ */ y()
1115
1115
  }), Oe = /* @__PURE__ */ S({
1116
1116
  // See: https://w3c.github.io/webcodecs/codec_registry.html
1117
1117
  codec: /* @__PURE__ */ y(),
1118
1118
  // The container format, used to decode the timestamp and more.
1119
- container: un,
1119
+ container: dn,
1120
1120
  // The description is used for some codecs.
1121
1121
  // If provided, we can initialize the decoder based on the catalog alone.
1122
1122
  // Otherwise, the initialization information is (repeated) before each key-frame.
@@ -1138,7 +1138,7 @@ const E = (/* @__PURE__ */ B()).check(/* @__PURE__ */ sn(), /* @__PURE__ */ nn()
1138
1138
  bitrate: /* @__PURE__ */ m(E),
1139
1139
  // If true, the decoder will optimize for latency.
1140
1140
  // Default: true
1141
- optimizeForLatency: /* @__PURE__ */ m(/* @__PURE__ */ rn()),
1141
+ optimizeForLatency: /* @__PURE__ */ m(/* @__PURE__ */ an()),
1142
1142
  // The maximum jitter before the next frame is emitted in milliseconds.
1143
1143
  // The player's jitter buffer should be larger than this value.
1144
1144
  // If not provided, the player should assume each frame is flushed immediately.
@@ -1148,7 +1148,7 @@ const E = (/* @__PURE__ */ B()).check(/* @__PURE__ */ sn(), /* @__PURE__ */ nn()
1148
1148
  // - If there can be up to 3 b-frames in a row, this would be 3 * 1000/fps.
1149
1149
  // - If frames are buffered into 2s segments, this would be 2s.
1150
1150
  jitter: /* @__PURE__ */ m(E)
1151
- }), Gt = /* @__PURE__ */ an([
1151
+ }), Zt = /* @__PURE__ */ on([
1152
1152
  /* @__PURE__ */ S({
1153
1153
  // A map of track name to rendition configuration.
1154
1154
  // This is not an array in order for it to work with JSON Merge Patch.
@@ -1166,17 +1166,17 @@ const E = (/* @__PURE__ */ B()).check(/* @__PURE__ */ sn(), /* @__PURE__ */ nn()
1166
1166
  rotation: /* @__PURE__ */ m(/* @__PURE__ */ B()),
1167
1167
  // If true, the decoder will flip the video horizontally
1168
1168
  // Default: false
1169
- flip: /* @__PURE__ */ m(/* @__PURE__ */ rn())
1169
+ flip: /* @__PURE__ */ m(/* @__PURE__ */ an())
1170
1170
  }),
1171
1171
  // Backwards compatibility: transform old array of {track, config} to new object format
1172
- /* @__PURE__ */ cn(
1172
+ /* @__PURE__ */ un(
1173
1173
  /* @__PURE__ */ j(
1174
1174
  /* @__PURE__ */ S({
1175
- track: jt,
1175
+ track: Gt,
1176
1176
  config: Oe
1177
1177
  })
1178
1178
  ),
1179
- /* @__PURE__ */ on((n) => {
1179
+ /* @__PURE__ */ cn((n) => {
1180
1180
  const e = n[0]?.config;
1181
1181
  return {
1182
1182
  renditions: Object.fromEntries(n.map((t) => [t.track.name, t.config])),
@@ -1186,36 +1186,36 @@ const E = (/* @__PURE__ */ B()).check(/* @__PURE__ */ sn(), /* @__PURE__ */ nn()
1186
1186
  };
1187
1187
  })
1188
1188
  )
1189
- ]), Zt = /* @__PURE__ */ S({
1190
- video: /* @__PURE__ */ m(Gt),
1191
- audio: /* @__PURE__ */ m(xt),
1192
- location: /* @__PURE__ */ m(Lt),
1193
- user: /* @__PURE__ */ m($t),
1194
- chat: /* @__PURE__ */ m(Bt),
1195
- capabilities: /* @__PURE__ */ m(Vt),
1189
+ ]), Xt = /* @__PURE__ */ S({
1190
+ video: /* @__PURE__ */ m(Zt),
1191
+ audio: /* @__PURE__ */ m(Ct),
1192
+ location: /* @__PURE__ */ m($t),
1193
+ user: /* @__PURE__ */ m(jt),
1194
+ chat: /* @__PURE__ */ m(Lt),
1195
+ capabilities: /* @__PURE__ */ m(Bt),
1196
1196
  preview: /* @__PURE__ */ m(re)
1197
1197
  });
1198
- function Xt(n) {
1198
+ function Ht(n) {
1199
1199
  const t = new TextDecoder().decode(n);
1200
1200
  try {
1201
1201
  const s = JSON.parse(t);
1202
- return Zt.parse(s);
1202
+ return Xt.parse(s);
1203
1203
  } catch (s) {
1204
1204
  throw console.warn("invalid catalog", t), s;
1205
1205
  }
1206
1206
  }
1207
- async function Ht(n) {
1207
+ async function Wt(n) {
1208
1208
  const e = await n.readFrame();
1209
1209
  if (e)
1210
- return Xt(e);
1210
+ return Ht(e);
1211
1211
  }
1212
- function ln(n) {
1212
+ function hn(n) {
1213
1213
  return n instanceof ArrayBuffer || typeof SharedArrayBuffer < "u" && n instanceof SharedArrayBuffer;
1214
1214
  }
1215
- const Wt = "utf-16", pe = "utf-16be", ze = "utf-16le", te = "utf-8";
1216
- function hn(n, e = {}) {
1215
+ const Kt = "utf-16", pe = "utf-16be", ze = "utf-16le", te = "utf-8";
1216
+ function fn(n, e = {}) {
1217
1217
  let t;
1218
- ln(n) ? t = new DataView(n) : t = new DataView(n.buffer, n.byteOffset, n.byteLength);
1218
+ hn(n) ? t = new DataView(n) : t = new DataView(n.buffer, n.byteOffset, n.byteLength);
1219
1219
  let s = 0, { encoding: r } = e;
1220
1220
  if (!r) {
1221
1221
  const u = t.getUint8(0), d = t.getUint8(1);
@@ -1243,7 +1243,7 @@ function hn(n, e = {}) {
1243
1243
  else s++;
1244
1244
  break;
1245
1245
  case pe:
1246
- case Wt:
1246
+ case Kt:
1247
1247
  case ze:
1248
1248
  c = t.getUint16(s, a), s += 2;
1249
1249
  break;
@@ -1252,13 +1252,13 @@ function hn(n, e = {}) {
1252
1252
  }
1253
1253
  return o;
1254
1254
  }
1255
- function Kt(n) {
1255
+ function Yt(n) {
1256
1256
  return new TextEncoder().encode(n);
1257
1257
  }
1258
- function Yt(n) {
1258
+ function Jt(n) {
1259
1259
  return { writers: n?.writers ?? {} };
1260
1260
  }
1261
- const Jt = [
1261
+ const Qt = [
1262
1262
  "dinf",
1263
1263
  "edts",
1264
1264
  "grpl",
@@ -1279,8 +1279,8 @@ const Jt = [
1279
1279
  "udta",
1280
1280
  "vttc"
1281
1281
  ];
1282
- function fn(n) {
1283
- return "boxes" in n || Jt.includes(n.type);
1282
+ function mn(n) {
1283
+ return "boxes" in n || Qt.includes(n.type);
1284
1284
  }
1285
1285
  const Ne = "utf8", L = "uint", ie = "template", qe = "string", De = "int", xe = "data";
1286
1286
  var A = class {
@@ -1340,7 +1340,7 @@ var A = class {
1340
1340
  this.writeUint(0, 1);
1341
1341
  }
1342
1342
  }, this.writeUtf8TerminatedString = (t) => {
1343
- const s = Kt(t);
1343
+ const s = Yt(t);
1344
1344
  new Uint8Array(this.dataView.buffer).set(s, this.cursor), this.cursor += s.length, this.writeUint(0, 1);
1345
1345
  }, this.writeBytes = (t) => {
1346
1346
  Array.isArray(t) || (t = [t]);
@@ -1390,34 +1390,34 @@ var A = class {
1390
1390
  this.writeUint(n, 1), this.writeUint(e, 3);
1391
1391
  }
1392
1392
  };
1393
- function mn(n, e) {
1394
- return Array.from(n, (t) => es(t, e));
1393
+ function pn(n, e) {
1394
+ return Array.from(n, (t) => ns(t, e));
1395
1395
  }
1396
1396
  function ye(n, e) {
1397
- const t = mn(n, e);
1397
+ const t = pn(n, e);
1398
1398
  return {
1399
1399
  bytes: t,
1400
1400
  size: t.reduce((s, r) => s + r.byteLength, 0)
1401
1401
  };
1402
1402
  }
1403
- function Qt(n, e) {
1403
+ function es(n, e) {
1404
1404
  const { bytes: s, size: r } = ye(n.boxes, e), i = 8 + r, a = new A(n.type, i);
1405
1405
  return a.writeBytes(s), a;
1406
1406
  }
1407
- function es(n, e) {
1407
+ function ns(n, e) {
1408
1408
  let t = null;
1409
1409
  if ("type" in n) {
1410
1410
  const { type: s } = n, r = e.writers?.[s];
1411
- if (r ? t = r(n, e) : fn(n) ? t = Qt(n, e) : "view" in n && (t = n.view), !t) throw new Error(`No writer found for box type: ${s}`);
1411
+ if (r ? t = r(n, e) : mn(n) ? t = es(n, e) : "view" in n && (t = n.view), !t) throw new Error(`No writer found for box type: ${s}`);
1412
1412
  }
1413
1413
  if ("buffer" in n && (t = n), !t) throw new Error("Invalid box");
1414
1414
  return new Uint8Array(t.buffer, t.byteOffset, t.byteLength);
1415
1415
  }
1416
- function ns(n, e, t) {
1416
+ function ts(n, e, t) {
1417
1417
  const s = t > 0 ? t : n.byteLength - (e - n.byteOffset);
1418
1418
  return new Uint8Array(n.buffer, e, Math.max(s, 0));
1419
1419
  }
1420
- function ts(n, e, t) {
1420
+ function ss(n, e, t) {
1421
1421
  let s = NaN;
1422
1422
  const r = e - n.byteOffset;
1423
1423
  switch (t) {
@@ -1467,11 +1467,11 @@ function Ce(n, e, t) {
1467
1467
  }
1468
1468
  return s;
1469
1469
  }
1470
- function ss(n, e, t) {
1470
+ function rs(n, e, t) {
1471
1471
  const s = t / 2;
1472
1472
  return G(n, e, s) + G(n, e + s, s) / Math.pow(2, s);
1473
1473
  }
1474
- function rs(n, e) {
1474
+ function is(n, e) {
1475
1475
  let t = "", s = e;
1476
1476
  for (; s - n.byteOffset < n.byteLength; ) {
1477
1477
  const r = G(n, s, 1);
@@ -1480,22 +1480,22 @@ function rs(n, e) {
1480
1480
  }
1481
1481
  return t;
1482
1482
  }
1483
- function is(n, e) {
1483
+ function as(n, e) {
1484
1484
  const t = n.byteLength - (e - n.byteOffset);
1485
- return t > 0 ? hn(new DataView(n.buffer, e, t), { encoding: te }) : "";
1485
+ return t > 0 ? fn(new DataView(n.buffer, e, t), { encoding: te }) : "";
1486
1486
  }
1487
- function as(n, e) {
1487
+ function os(n, e) {
1488
1488
  const t = n.byteLength - (e - n.byteOffset);
1489
1489
  let s = "";
1490
1490
  if (t > 0) {
1491
1491
  const r = new DataView(n.buffer, e, t);
1492
1492
  let i = 0;
1493
1493
  for (; i < t && r.getUint8(i) !== 0; i++) ;
1494
- s = hn(new DataView(n.buffer, e, i), { encoding: te });
1494
+ s = fn(new DataView(n.buffer, e, i), { encoding: te });
1495
1495
  }
1496
1496
  return s;
1497
1497
  }
1498
- var os = class pn {
1498
+ var cs = class wn {
1499
1499
  /**
1500
1500
  * Creates a new IsoView instance. Similar to DataView, but with additional
1501
1501
  * methods for reading ISO BMFF data. It implements the iterator protocol,
@@ -1506,7 +1506,7 @@ var os = class pn {
1506
1506
  */
1507
1507
  constructor(e, t) {
1508
1508
  this.truncated = !1, this.slice = (s, r) => {
1509
- const i = new pn(new DataView(this.dataView.buffer, s, r), this.config), a = this.offset - s, o = r - a;
1509
+ const i = new wn(new DataView(this.dataView.buffer, s, r), this.config), a = this.offset - s, o = r - a;
1510
1510
  return this.offset += o, i.jump(a), i;
1511
1511
  }, this.read = (s, r = 0) => {
1512
1512
  const { dataView: i, offset: a } = this;
@@ -1516,19 +1516,19 @@ var os = class pn {
1516
1516
  o = G(i, a, r);
1517
1517
  break;
1518
1518
  case De:
1519
- o = ts(i, a, r);
1519
+ o = ss(i, a, r);
1520
1520
  break;
1521
1521
  case ie:
1522
- o = ss(i, a, r);
1522
+ o = rs(i, a, r);
1523
1523
  break;
1524
1524
  case qe:
1525
- r === -1 ? (o = rs(i, a), c = o.length + 1) : o = Ce(i, a, r);
1525
+ r === -1 ? (o = is(i, a), c = o.length + 1) : o = Ce(i, a, r);
1526
1526
  break;
1527
1527
  case xe:
1528
- o = ns(i, a, r), c = o.length;
1528
+ o = ts(i, a, r), c = o.length;
1529
1529
  break;
1530
1530
  case Ne:
1531
- r === -1 ? (o = as(i, a), c = o.length + 1) : o = is(i, a);
1531
+ r === -1 ? (o = os(i, a), c = o.length + 1) : o = as(i, a);
1532
1532
  break;
1533
1533
  default:
1534
1534
  o = -1;
@@ -1564,7 +1564,7 @@ var os = class pn {
1564
1564
  const i = [];
1565
1565
  for (let a = 0; a < s; a++) i.push(r());
1566
1566
  return i;
1567
- }, this.dataView = ln(e) ? new DataView(e) : e instanceof DataView ? e : new DataView(e.buffer, e.byteOffset, e.byteLength), this.offset = this.dataView.byteOffset, this.config = t || {};
1567
+ }, this.dataView = hn(e) ? new DataView(e) : e instanceof DataView ? e : new DataView(e.buffer, e.byteOffset, e.byteLength), this.offset = this.dataView.byteOffset, this.config = t || {};
1568
1568
  }
1569
1569
  /**
1570
1570
  * The buffer of the data view.
@@ -1611,7 +1611,7 @@ var os = class pn {
1611
1611
  const { readers: e = {} } = this.config;
1612
1612
  for (; !this.done; ) try {
1613
1613
  const t = this.readBox(), { type: s, view: r } = t, i = e[s] || e[s.trim()];
1614
- if (i && Object.assign(t, i(r, s)), fn(t) && !t.boxes) {
1614
+ if (i && Object.assign(t, i(r, s)), mn(t) && !t.boxes) {
1615
1615
  const a = [];
1616
1616
  for (const o of r) a.push(o);
1617
1617
  t.boxes = a;
@@ -1623,28 +1623,28 @@ var os = class pn {
1623
1623
  }
1624
1624
  }
1625
1625
  };
1626
- function wn(n, e) {
1626
+ function vn(n, e) {
1627
1627
  const t = [];
1628
- for (const s of new os(n, e)) t.push(s);
1628
+ for (const s of new cs(n, e)) t.push(s);
1629
1629
  return t;
1630
1630
  }
1631
- function cs(n, e) {
1632
- return mn(n, Yt(e));
1631
+ function us(n, e) {
1632
+ return pn(n, Jt(e));
1633
1633
  }
1634
- function us(n) {
1634
+ function ds(n) {
1635
1635
  return {
1636
1636
  type: "mdat",
1637
1637
  data: n.readData(-1)
1638
1638
  };
1639
1639
  }
1640
- function ds(n) {
1640
+ function ls(n) {
1641
1641
  return {
1642
1642
  type: "mfhd",
1643
1643
  ...n.readFullBox(),
1644
1644
  sequenceNumber: n.readUint(4)
1645
1645
  };
1646
1646
  }
1647
- function ls(n) {
1647
+ function hs(n) {
1648
1648
  const { version: e, flags: t } = n.readFullBox();
1649
1649
  return {
1650
1650
  type: "tfdt",
@@ -1653,7 +1653,7 @@ function ls(n) {
1653
1653
  baseMediaDecodeTime: n.readUint(e == 1 ? 8 : 4)
1654
1654
  };
1655
1655
  }
1656
- function hs(n) {
1656
+ function fs(n) {
1657
1657
  const { version: e, flags: t } = n.readFullBox();
1658
1658
  return {
1659
1659
  type: "tfhd",
@@ -1667,7 +1667,7 @@ function hs(n) {
1667
1667
  defaultSampleFlags: t & 32 ? n.readUint(4) : void 0
1668
1668
  };
1669
1669
  }
1670
- function fs(n) {
1670
+ function ms(n) {
1671
1671
  const { version: e, flags: t } = n.readFullBox(), s = n.readUint(4);
1672
1672
  let r, i;
1673
1673
  t & 1 && (r = n.readInt(4)), t & 4 && (i = n.readUint(4));
@@ -1685,70 +1685,70 @@ function fs(n) {
1685
1685
  samples: a
1686
1686
  };
1687
1687
  }
1688
- function ms(n, e) {
1688
+ function ps(n, e) {
1689
1689
  const i = n.entries.length, { bytes: a, size: o } = ye(n.entries, e), c = new A("dref", 16 + o);
1690
1690
  return c.writeFullBox(n.version, n.flags), c.writeUint(i, 4), c.writeBytes(a), c;
1691
1691
  }
1692
- function ps(n) {
1692
+ function ws(n) {
1693
1693
  const r = n.compatibleBrands.length * 4, i = new A("ftyp", 16 + r);
1694
1694
  i.writeString(n.majorBrand), i.writeUint(n.minorVersion, 4);
1695
1695
  for (const a of n.compatibleBrands) i.writeString(a);
1696
1696
  return i;
1697
1697
  }
1698
- function ws(n) {
1698
+ function vs(n) {
1699
1699
  const a = n.name.length + 1, o = new A("hdlr", 32 + a);
1700
1700
  return o.writeFullBox(n.version, n.flags), o.writeUint(n.preDefined, 4), o.writeString(n.handlerType), o.writeArray(n.reserved, L, 4, 3), o.writeTerminatedString(n.name), o;
1701
1701
  }
1702
- function vs(n) {
1702
+ function bs(n) {
1703
1703
  const e = new A("mdat", 8 + n.data.length);
1704
1704
  return e.writeBytes(n.data), e;
1705
1705
  }
1706
- function bs(n) {
1706
+ function gs(n) {
1707
1707
  const e = n.version === 1 ? 8 : 4, t = 8, s = 4, r = e * 3, i = new A("mdhd", t + s + r + 4 + 2 + 2);
1708
1708
  i.writeFullBox(n.version, n.flags), i.writeUint(n.creationTime, e), i.writeUint(n.modificationTime, e), i.writeUint(n.timescale, 4), i.writeUint(n.duration, e);
1709
1709
  const a = n.language.length >= 3 ? (n.language.charCodeAt(0) - 96 & 31) << 10 | (n.language.charCodeAt(1) - 96 & 31) << 5 | n.language.charCodeAt(2) - 96 & 31 : 0;
1710
1710
  return i.writeUint(a, 2), i.writeUint(n.preDefined, 2), i;
1711
1711
  }
1712
- function gs(n) {
1712
+ function ys(n) {
1713
1713
  const e = new A("mfhd", 16);
1714
1714
  return e.writeFullBox(n.version, n.flags), e.writeUint(n.sequenceNumber, 4), e;
1715
1715
  }
1716
- function ys(n) {
1716
+ function _s(n) {
1717
1717
  const e = n.version === 1 ? 8 : 4, t = 8, s = 4, r = e * 3, i = new A("mvhd", t + s + r + 4 + 4 + 2 + 2 + 8 + 36 + 24 + 4);
1718
1718
  return i.writeFullBox(n.version, n.flags), i.writeUint(n.creationTime, e), i.writeUint(n.modificationTime, e), i.writeUint(n.timescale, 4), i.writeUint(n.duration, e), i.writeTemplate(n.rate, 4), i.writeTemplate(n.volume, 2), i.writeUint(n.reserved1, 2), i.writeArray(n.reserved2, L, 4, 2), i.writeArray(n.matrix, ie, 4, 9), i.writeArray(n.preDefined, L, 4, 6), i.writeUint(n.nextTrackId, 4), i;
1719
1719
  }
1720
- function _s(n) {
1720
+ function Ss(n) {
1721
1721
  const e = new A("smhd", 16);
1722
1722
  return e.writeFullBox(n.version, n.flags), e.writeUint(n.balance, 2), e.writeUint(n.reserved, 2), e;
1723
1723
  }
1724
- function Ss(n, e) {
1724
+ function ks(n, e) {
1725
1725
  const i = n.entries.length, { bytes: a, size: o } = ye(n.entries, e), c = new A("stsd", 16 + o);
1726
1726
  return c.writeFullBox(n.version, n.flags), c.writeUint(i, 4), c.writeBytes(a), c;
1727
1727
  }
1728
- function ks(n) {
1728
+ function As(n) {
1729
1729
  const r = n.entryCount * 8, i = new A("stts", 16 + r);
1730
1730
  i.writeFullBox(n.version, n.flags), i.writeUint(n.entryCount, 4);
1731
1731
  for (const a of n.entries)
1732
1732
  i.writeUint(a.sampleCount, 4), i.writeUint(a.sampleDelta, 4);
1733
1733
  return i;
1734
1734
  }
1735
- function As(n) {
1735
+ function Is(n) {
1736
1736
  const e = n.version === 1 ? 8 : 4, t = 8, s = 4, r = e, i = new A("tfdt", t + s + r);
1737
1737
  return i.writeFullBox(n.version, n.flags), i.writeUint(n.baseMediaDecodeTime, e), i;
1738
1738
  }
1739
- function Is(n) {
1739
+ function Rs(n) {
1740
1740
  const r = n.flags & 1 ? 8 : 0, i = n.flags & 2 ? 4 : 0, a = n.flags & 8 ? 4 : 0, o = n.flags & 16 ? 4 : 0, c = n.flags & 32 ? 4 : 0, u = new A("tfhd", 16 + r + i + a + o + c);
1741
1741
  return u.writeFullBox(n.version, n.flags), u.writeUint(n.trackId, 4), n.flags & 1 && u.writeUint(n.baseDataOffset ?? 0, 8), n.flags & 2 && u.writeUint(n.sampleDescriptionIndex ?? 0, 4), n.flags & 8 && u.writeUint(n.defaultSampleDuration ?? 0, 4), n.flags & 16 && u.writeUint(n.defaultSampleSize ?? 0, 4), n.flags & 32 && u.writeUint(n.defaultSampleFlags ?? 0, 4), u;
1742
1742
  }
1743
- function Rs(n) {
1743
+ function Es(n) {
1744
1744
  const e = n.version === 1 ? 8 : 4, t = 8, s = 4, r = e * 3, i = new A("tkhd", t + s + r + 4 + 4 + 8 + 2 + 2 + 2 + 2 + 36 + 4 + 4);
1745
1745
  return i.writeFullBox(n.version, n.flags), i.writeUint(n.creationTime, e), i.writeUint(n.modificationTime, e), i.writeUint(n.trackId, 4), i.writeUint(n.reserved1, 4), i.writeUint(n.duration, e), i.writeArray(n.reserved2, L, 4, 2), i.writeUint(n.layer, 2), i.writeUint(n.alternateGroup, 2), i.writeTemplate(n.volume, 2), i.writeUint(n.reserved3, 2), i.writeArray(n.matrix, ie, 4, 9), i.writeTemplate(n.width, 4), i.writeTemplate(n.height, 4), i;
1746
1746
  }
1747
- function Es(n) {
1747
+ function Ts(n) {
1748
1748
  const e = new A("trex", 32);
1749
1749
  return e.writeFullBox(n.version, n.flags), e.writeUint(n.trackId, 4), e.writeUint(n.defaultSampleDescriptionIndex, 4), e.writeUint(n.defaultSampleDuration, 4), e.writeUint(n.defaultSampleSize, 4), e.writeUint(n.defaultSampleFlags, 4), e;
1750
1750
  }
1751
- function Ts(n) {
1751
+ function Us(n) {
1752
1752
  const r = n.flags & 1 ? 4 : 0, i = n.flags & 4 ? 4 : 0;
1753
1753
  let a = 0;
1754
1754
  n.flags & 256 && (a += 4), n.flags & 512 && (a += 4), n.flags & 1024 && (a += 4), n.flags & 2048 && (a += 4);
@@ -1758,7 +1758,7 @@ function Ts(n) {
1758
1758
  n.flags & 256 && c.writeUint(u.sampleDuration ?? 0, 4), n.flags & 512 && c.writeUint(u.sampleSize ?? 0, 4), n.flags & 1024 && c.writeUint(u.sampleFlags ?? 0, 4), n.flags & 2048 && c.writeUint(u.sampleCompositionTimeOffset ?? 0, 4);
1759
1759
  return c;
1760
1760
  }
1761
- function Us(n) {
1761
+ function Ms(n) {
1762
1762
  const s = n.location.length + 1, r = new A("url ", 12 + s);
1763
1763
  return r.writeFullBox(n.version, n.flags), r.writeTerminatedString(n.location), r;
1764
1764
  }
@@ -1766,12 +1766,12 @@ function Ps(n) {
1766
1766
  const e = new A("vmhd", 20);
1767
1767
  return e.writeFullBox(n.version, n.flags), e.writeUint(n.graphicsmode, 2), e.writeArray(n.opcolor, L, 2, 3), e;
1768
1768
  }
1769
- const vn = {
1770
- mfhd: ds,
1771
- tfhd: hs,
1772
- tfdt: ls,
1773
- trun: fs,
1774
- mdat: us
1769
+ const bn = {
1770
+ mfhd: ls,
1771
+ tfhd: fs,
1772
+ tfdt: hs,
1773
+ trun: ms,
1774
+ mdat: ds
1775
1775
  };
1776
1776
  function X(n, e) {
1777
1777
  for (const t of n) {
@@ -1784,19 +1784,19 @@ function X(n, e) {
1784
1784
  }
1785
1785
  }
1786
1786
  }
1787
- function bn(n) {
1787
+ function gn(n) {
1788
1788
  const e = new ArrayBuffer(n.byteLength);
1789
1789
  return new Uint8Array(e).set(n), e;
1790
1790
  }
1791
1791
  function ne(n) {
1792
1792
  return (e) => e.type === n;
1793
1793
  }
1794
- function gn(n, e) {
1795
- const t = wn(bn(n), { readers: vn });
1794
+ function yn(n, e) {
1795
+ const t = vn(gn(n), { readers: bn });
1796
1796
  return (X(t, ne("tfdt"))?.baseMediaDecodeTime ?? 0) * 1e6 / e;
1797
1797
  }
1798
- function yn(n, e) {
1799
- const t = wn(bn(n), { readers: vn }), r = X(t, ne("tfdt"))?.baseMediaDecodeTime ?? 0, i = X(t, ne("tfhd")), a = i?.defaultSampleDuration ?? 0, o = i?.defaultSampleSize ?? 0, c = i?.defaultSampleFlags ?? 0, u = X(t, ne("trun"));
1798
+ function _n(n, e) {
1799
+ const t = vn(gn(n), { readers: bn }), r = X(t, ne("tfdt"))?.baseMediaDecodeTime ?? 0, i = X(t, ne("tfhd")), a = i?.defaultSampleDuration ?? 0, o = i?.defaultSampleSize ?? 0, c = i?.defaultSampleFlags ?? 0, u = X(t, ne("trun"));
1800
1800
  if (!u)
1801
1801
  throw new Error("No trun box found in data segment");
1802
1802
  const d = X(t, ne("mdat"));
@@ -1806,19 +1806,19 @@ function yn(n, e) {
1806
1806
  if (!l)
1807
1807
  throw new Error("No data in mdat box");
1808
1808
  const f = [];
1809
- let p = 0, b = r;
1809
+ let w = 0, b = r;
1810
1810
  for (let g = 0; g < u.sampleCount; g++) {
1811
1811
  const R = u.samples[g] ?? {}, O = R.sampleSize ?? o, z = R.sampleDuration ?? a;
1812
1812
  if (O <= 0)
1813
1813
  throw new Error(`Invalid sample size ${O} for sample ${g} in trun`);
1814
1814
  if (z <= 0)
1815
1815
  throw new Error(`Invalid sample duration ${z} for sample ${g} in trun`);
1816
- if (p + O > l.length)
1816
+ if (w + O > l.length)
1817
1817
  throw new Error(
1818
- `Sample ${g} would overflow mdat: offset=${p}, size=${O}, mdatLength=${l.length}`
1818
+ `Sample ${g} would overflow mdat: offset=${w}, size=${O}, mdatLength=${l.length}`
1819
1819
  );
1820
- const $ = g === 0 && u.firstSampleFlags !== void 0 ? u.firstSampleFlags : R.sampleFlags ?? c, D = R.sampleCompositionTimeOffset ?? 0, x = new Uint8Array(l.slice(p, p + O));
1821
- p += O;
1820
+ const $ = g === 0 && u.firstSampleFlags !== void 0 ? u.firstSampleFlags : R.sampleFlags ?? c, D = R.sampleCompositionTimeOffset ?? 0, x = new Uint8Array(l.slice(w, w + O));
1821
+ w += O;
1822
1822
  const C = b + D, F = Math.round(C * 1e6 / e), k = $ === 0 || ($ & 65536) === 0;
1823
1823
  f.push({
1824
1824
  data: x,
@@ -1836,48 +1836,48 @@ function q(n) {
1836
1836
  throw new Error("invalid hex string format");
1837
1837
  return new Uint8Array(e.map((t) => parseInt(t, 16)));
1838
1838
  }
1839
- const he = [65536, 0, 0, 0, 65536, 0, 0, 0, 1073741824], Ms = {
1839
+ const he = [65536, 0, 0, 0, 65536, 0, 0, 0, 1073741824], Os = {
1840
1840
  // Init segment boxes
1841
- ftyp: ps,
1842
- mvhd: ys,
1843
- tkhd: Rs,
1844
- mdhd: bs,
1845
- hdlr: ws,
1841
+ ftyp: ws,
1842
+ mvhd: _s,
1843
+ tkhd: Es,
1844
+ mdhd: gs,
1845
+ hdlr: vs,
1846
1846
  vmhd: Ps,
1847
- smhd: _s,
1848
- "url ": Us,
1849
- dref: ms,
1850
- stsd: Ss,
1851
- stts: ks,
1852
- trex: Es,
1847
+ smhd: Ss,
1848
+ "url ": Ms,
1849
+ dref: ps,
1850
+ stsd: ks,
1851
+ stts: As,
1852
+ trex: Ts,
1853
1853
  // Data segment boxes
1854
- mfhd: gs,
1855
- tfhd: Is,
1856
- tfdt: As,
1857
- trun: Ts,
1858
- mdat: vs
1854
+ mfhd: ys,
1855
+ tfhd: Rs,
1856
+ tfdt: Is,
1857
+ trun: Us,
1858
+ mdat: bs
1859
1859
  // For boxes without library writers, we create them manually as Uint8Arrays
1860
1860
  };
1861
1861
  function se(n) {
1862
- return cs(n, { writers: Ms });
1862
+ return us(n, { writers: Os });
1863
1863
  }
1864
1864
  function _e(n, e, t, s) {
1865
1865
  const r = 12 + s.length, i = new Uint8Array(r), a = new DataView(i.buffer);
1866
1866
  return a.setUint32(0, r, !1), i[4] = n.charCodeAt(0), i[5] = n.charCodeAt(1), i[6] = n.charCodeAt(2), i[7] = n.charCodeAt(3), a.setUint32(8, e << 24 | t, !1), i.set(s, 12), i;
1867
1867
  }
1868
- function _n() {
1868
+ function Sn() {
1869
1869
  const n = new Uint8Array(4);
1870
1870
  return _e("stsc", 0, 0, n);
1871
1871
  }
1872
- function Sn() {
1872
+ function kn() {
1873
1873
  const n = new Uint8Array(8);
1874
1874
  return _e("stsz", 0, 0, n);
1875
1875
  }
1876
- function kn() {
1876
+ function An() {
1877
1877
  const n = new Uint8Array(4);
1878
1878
  return _e("stco", 0, 0, n);
1879
1879
  }
1880
- function Os(n, e, t) {
1880
+ function zs(n, e, t) {
1881
1881
  const s = 8 + t.length, i = 8 + (78 + s), a = new Uint8Array(i), o = new DataView(a.buffer);
1882
1882
  let c = 0;
1883
1883
  return o.setUint32(c, i, !1), c += 4, a[c++] = 97, a[c++] = 118, a[c++] = 99, a[c++] = 49, c += 6, o.setUint16(c, 1, !1), c += 2, o.setUint16(c, 0, !1), c += 2, o.setUint16(c, 0, !1), c += 2, c += 12, o.setUint16(c, n, !1), c += 2, o.setUint16(c, e, !1), c += 2, o.setUint32(c, 4718592, !1), c += 4, o.setUint32(c, 4718592, !1), c += 4, o.setUint32(c, 0, !1), c += 4, o.setUint16(c, 1, !1), c += 2, c += 32, o.setUint16(c, 24, !1), c += 2, o.setUint16(c, 65535, !1), c += 2, o.setUint32(c, s, !1), c += 4, a[c++] = 97, a[c++] = 118, a[c++] = 99, a[c++] = 67, a.set(t, c), a;
@@ -1975,14 +1975,14 @@ function Fe(n) {
1975
1975
  flags: 0,
1976
1976
  entryCount: 1,
1977
1977
  // biome-ignore lint/suspicious/noExplicitAny: Raw avc1 box since library doesn't handle avcC children
1978
- entries: [Os(e, t, q(s))]
1978
+ entries: [zs(e, t, q(s))]
1979
1979
  }, z = {
1980
1980
  type: "stts",
1981
1981
  version: 0,
1982
1982
  flags: 0,
1983
1983
  entryCount: 0,
1984
1984
  entries: []
1985
- }, $ = _n(), D = Sn(), x = kn(), me = se([o, {
1985
+ }, $ = Sn(), D = kn(), x = An(), me = se([o, {
1986
1986
  type: "moov",
1987
1987
  boxes: [c, {
1988
1988
  type: "trak",
@@ -2073,7 +2073,7 @@ function Ve(n) {
2073
2073
  handlerType: "soun",
2074
2074
  reserved: [0, 0, 0],
2075
2075
  name: "SoundHandler"
2076
- }, p = {
2076
+ }, w = {
2077
2077
  type: "smhd",
2078
2078
  version: 0,
2079
2079
  flags: 0,
@@ -2099,14 +2099,14 @@ function Ve(n) {
2099
2099
  flags: 0,
2100
2100
  entryCount: 1,
2101
2101
  // biome-ignore lint/suspicious/noExplicitAny: Raw sample entry box
2102
- entries: [zs(r, e, t, s)]
2102
+ entries: [Ns(r, e, t, s)]
2103
2103
  }, $ = {
2104
2104
  type: "stts",
2105
2105
  version: 0,
2106
2106
  flags: 0,
2107
2107
  entryCount: 0,
2108
2108
  entries: []
2109
- }, D = _n(), x = Sn(), C = kn(), ae = se([c, {
2109
+ }, D = Sn(), x = kn(), C = An(), ae = se([c, {
2110
2110
  type: "moov",
2111
2111
  boxes: [u, {
2112
2112
  type: "trak",
@@ -2114,7 +2114,7 @@ function Ve(n) {
2114
2114
  type: "mdia",
2115
2115
  boxes: [l, f, {
2116
2116
  type: "minf",
2117
- boxes: [p, R, {
2117
+ boxes: [w, R, {
2118
2118
  type: "stbl",
2119
2119
  // biome-ignore lint/suspicious/noExplicitAny: Raw boxes for types without library writers
2120
2120
  boxes: [z, $, D, x, C]
@@ -2134,30 +2134,30 @@ function Ve(n) {
2134
2134
  defaultSampleFlags: 0
2135
2135
  }]
2136
2136
  }]
2137
- }]), oe = ae.reduce((V, Mn) => V + Mn.byteLength, 0), Q = new Uint8Array(oe);
2137
+ }]), oe = ae.reduce((V, On) => V + On.byteLength, 0), Q = new Uint8Array(oe);
2138
2138
  let N = 0;
2139
2139
  for (const V of ae)
2140
2140
  Q.set(new Uint8Array(V.buffer, V.byteOffset, V.byteLength), N), N += V.byteLength;
2141
2141
  return Q;
2142
2142
  }
2143
- function zs(n, e, t, s) {
2143
+ function Ns(n, e, t, s) {
2144
2144
  if (n.startsWith("mp4a"))
2145
- return Ns(e, t, s);
2146
- if (n === "opus")
2147
2145
  return qs(e, t, s);
2146
+ if (n === "opus")
2147
+ return Ds(e, t, s);
2148
2148
  throw new Error(`Unsupported audio codec: ${n}`);
2149
2149
  }
2150
- function Ns(n, e, t) {
2151
- const s = xs(n, e, t), i = 8 + (28 + s.length), a = new Uint8Array(i), o = new DataView(a.buffer);
2150
+ function qs(n, e, t) {
2151
+ const s = Cs(n, e, t), i = 8 + (28 + s.length), a = new Uint8Array(i), o = new DataView(a.buffer);
2152
2152
  let c = 0;
2153
2153
  return o.setUint32(c, i, !1), c += 4, a[c++] = 109, a[c++] = 112, a[c++] = 52, a[c++] = 97, c += 6, o.setUint16(c, 1, !1), c += 2, c += 8, o.setUint16(c, e, !1), c += 2, o.setUint16(c, 16, !1), c += 2, o.setUint16(c, 0, !1), c += 2, o.setUint16(c, 0, !1), c += 2, o.setUint32(c, n * 65536, !1), c += 4, a.set(s, c), a;
2154
2154
  }
2155
- function qs(n, e, t) {
2156
- const s = Cs(e, n, t), i = 8 + (28 + s.length), a = new Uint8Array(i), o = new DataView(a.buffer);
2155
+ function Ds(n, e, t) {
2156
+ const s = Fs(e, n, t), i = 8 + (28 + s.length), a = new Uint8Array(i), o = new DataView(a.buffer);
2157
2157
  let c = 0;
2158
2158
  return o.setUint32(c, i, !1), c += 4, a[c++] = 79, a[c++] = 112, a[c++] = 117, a[c++] = 115, c += 6, o.setUint16(c, 1, !1), c += 2, c += 8, o.setUint16(c, e, !1), c += 2, o.setUint16(c, 16, !1), c += 2, o.setUint16(c, 0, !1), c += 2, o.setUint16(c, 0, !1), c += 2, o.setUint32(c, n * 65536, !1), c += 4, a.set(s, c), a;
2159
2159
  }
2160
- function Ds(n, e) {
2160
+ function xs(n, e) {
2161
2161
  const s = {
2162
2162
  96e3: 0,
2163
2163
  88200: 1,
@@ -2175,12 +2175,12 @@ function Ds(n, e) {
2175
2175
  }[n] ?? 4, i = 2 << 3 | s >> 1, a = (s & 1) << 7 | e << 3;
2176
2176
  return new Uint8Array([i, a]);
2177
2177
  }
2178
- function xs(n, e, t) {
2179
- const s = t ? q(t) : Ds(n, e), r = s.length, i = 15 + r, a = 5 + i + 3, o = 14 + a, c = new Uint8Array(o), u = new DataView(c.buffer);
2178
+ function Cs(n, e, t) {
2179
+ const s = t ? q(t) : xs(n, e), r = s.length, i = 15 + r, a = 5 + i + 3, o = 14 + a, c = new Uint8Array(o), u = new DataView(c.buffer);
2180
2180
  let d = 0;
2181
2181
  return u.setUint32(d, o, !1), d += 4, c[d++] = 101, c[d++] = 115, c[d++] = 100, c[d++] = 115, u.setUint32(d, 0, !1), d += 4, c[d++] = 3, c[d++] = a, u.setUint16(d, 0, !1), d += 2, c[d++] = 0, c[d++] = 4, c[d++] = i, c[d++] = 64, c[d++] = 21, c[d++] = 0, c[d++] = 0, c[d++] = 0, u.setUint32(d, 0, !1), d += 4, u.setUint32(d, 0, !1), d += 4, c[d++] = 5, c[d++] = r, c.set(s, d), d += r, c[d++] = 6, c[d++] = 1, c[d++] = 2, c;
2182
2182
  }
2183
- function Cs(n, e, t) {
2183
+ function Fs(n, e, t) {
2184
2184
  if (t) {
2185
2185
  const o = q(t), c = 8 + o.length, u = new Uint8Array(c);
2186
2186
  return new DataView(u.buffer).setUint32(0, c, !1), u[4] = 100, u[5] = 79, u[6] = 112, u[7] = 115, u.set(o, 8), u;
@@ -2189,7 +2189,7 @@ function Cs(n, e, t) {
2189
2189
  let a = 0;
2190
2190
  return i.setUint32(a, s, !1), a += 4, r[a++] = 100, r[a++] = 79, r[a++] = 112, r[a++] = 115, r[a++] = 0, r[a++] = n, i.setUint16(a, 312, !1), a += 2, i.setUint32(a, e, !1), a += 4, i.setInt16(a, 0, !1), a += 2, r[a++] = 0, r;
2191
2191
  }
2192
- function An(n) {
2192
+ function In(n) {
2193
2193
  const { data: e, timestamp: t, duration: s, keyframe: r, sequence: i, trackId: a = 1 } = n, o = r ? 33554432 : 16842752, c = {
2194
2194
  type: "mfhd",
2195
2195
  version: 0,
@@ -2220,18 +2220,18 @@ function An(n) {
2220
2220
  sampleFlags: o
2221
2221
  }
2222
2222
  ]
2223
- }, p = {
2223
+ }, w = {
2224
2224
  type: "moof",
2225
2225
  boxes: [c, {
2226
2226
  type: "traf",
2227
2227
  boxes: [u, d, l]
2228
2228
  }]
2229
- }, b = se([p]);
2229
+ }, b = se([w]);
2230
2230
  let g = 0;
2231
2231
  for (const k of b)
2232
2232
  g += k.byteLength;
2233
2233
  l.dataOffset = g + 8;
2234
- const R = se([p]);
2234
+ const R = se([w]);
2235
2235
  g = 0;
2236
2236
  for (const k of R)
2237
2237
  g += k.byteLength;
@@ -2254,17 +2254,17 @@ function An(n) {
2254
2254
  }
2255
2255
  class J {
2256
2256
  #n;
2257
- #s;
2258
- #e = [];
2259
2257
  #t;
2258
+ #e = [];
2259
+ #r;
2260
2260
  // the active group sequence number
2261
2261
  // Wake up the consumer when a new frame is available.
2262
- #r;
2262
+ #s;
2263
2263
  #i = new h([]);
2264
2264
  buffered = this.#i;
2265
2265
  #a = new T();
2266
2266
  constructor(e, t) {
2267
- this.#n = e, this.#s = h.from(t?.latency ?? _.Time.Milli.zero), this.#a.spawn(this.#o.bind(this)), this.#a.cleanup(() => {
2267
+ this.#n = e, this.#t = h.from(t?.latency ?? _.Time.Milli.zero), this.#a.spawn(this.#o.bind(this)), this.#a.cleanup(() => {
2268
2268
  this.#n.close();
2269
2269
  for (const s of this.#e)
2270
2270
  s.consumer.close();
@@ -2275,8 +2275,8 @@ class J {
2275
2275
  for (; ; ) {
2276
2276
  const e = await this.#n.nextGroup();
2277
2277
  if (!e) break;
2278
- if (this.#t === void 0 && (this.#t = e.sequence), e.sequence < this.#t) {
2279
- console.warn(`skipping old group: ${e.sequence} < ${this.#t}`), e.close();
2278
+ if (this.#r === void 0 && (this.#r = e.sequence), e.sequence < this.#r) {
2279
+ console.warn(`skipping old group: ${e.sequence} < ${this.#r}`), e.close();
2280
2280
  continue;
2281
2281
  }
2282
2282
  const t = {
@@ -2297,18 +2297,18 @@ class J {
2297
2297
  timestamp: i,
2298
2298
  keyframe: t
2299
2299
  };
2300
- t = !1, e.frames.push(a), (e.latest === void 0 || i > e.latest) && (e.latest = i), this.#u(), e.consumer.sequence === this.#t ? (this.#r?.(), this.#r = void 0) : this.#d();
2300
+ t = !1, e.frames.push(a), (e.latest === void 0 || i > e.latest) && (e.latest = i), this.#u(), e.consumer.sequence === this.#r ? (this.#s?.(), this.#s = void 0) : this.#d();
2301
2301
  }
2302
2302
  } catch {
2303
2303
  } finally {
2304
- e.done = !0, e.consumer.sequence === this.#t && (this.#t += 1), this.#u(), this.#r?.(), this.#r = void 0, e.consumer.close();
2304
+ e.done = !0, e.consumer.sequence === this.#r && (this.#r += 1), this.#u(), this.#s?.(), this.#s = void 0, e.consumer.close();
2305
2305
  }
2306
2306
  }
2307
2307
  #d() {
2308
- if (this.#t === void 0) return;
2308
+ if (this.#r === void 0) return;
2309
2309
  let e = !1;
2310
2310
  for (; this.#e.length >= 2; ) {
2311
- const t = _.Time.Micro.fromMilli(this.#s.peek());
2311
+ const t = _.Time.Micro.fromMilli(this.#t.peek());
2312
2312
  let s, r;
2313
2313
  for (const o of this.#e) {
2314
2314
  if (o.latest === void 0) continue;
@@ -2318,32 +2318,32 @@ class J {
2318
2318
  if (s === void 0 || r === void 0 || r - s <= t) break;
2319
2319
  const a = this.#e.shift();
2320
2320
  if (!a) break;
2321
- this.#t = this.#e[0]?.consumer.sequence, console.warn(`skipping slow group: ${a.consumer.sequence} -> ${this.#t}`), a.consumer.close(), a.frames.length = 0, e = !0;
2321
+ this.#r = this.#e[0]?.consumer.sequence, console.warn(`skipping slow group: ${a.consumer.sequence} -> ${this.#r}`), a.consumer.close(), a.frames.length = 0, e = !0;
2322
2322
  }
2323
- e && (this.#u(), this.#r?.(), this.#r = void 0);
2323
+ e && (this.#u(), this.#s?.(), this.#s = void 0);
2324
2324
  }
2325
2325
  // Returns the next frame in order, along with the group number.
2326
2326
  // If frame is undefined, the group is done.
2327
2327
  async next() {
2328
2328
  for (; ; ) {
2329
- if (this.#e.length > 0 && this.#t !== void 0 && this.#e[0].consumer.sequence <= this.#t) {
2329
+ if (this.#e.length > 0 && this.#r !== void 0 && this.#e[0].consumer.sequence <= this.#r) {
2330
2330
  const t = this.#e[0].frames.shift();
2331
2331
  if (t)
2332
2332
  return this.#u(), { frame: t, group: this.#e[0].consumer.sequence };
2333
- if (this.#t > this.#e[0].consumer.sequence || this.#e[0].done) {
2334
- this.#e[0].consumer.sequence === this.#t && (this.#t += 1);
2333
+ if (this.#r > this.#e[0].consumer.sequence || this.#e[0].done) {
2334
+ this.#e[0].consumer.sequence === this.#r && (this.#r += 1);
2335
2335
  const s = this.#e.shift();
2336
2336
  if (s)
2337
2337
  return this.#u(), { frame: void 0, group: s.consumer.sequence };
2338
2338
  }
2339
2339
  }
2340
- if (this.#r)
2340
+ if (this.#s)
2341
2341
  throw new Error("multiple calls to decode not supported");
2342
2342
  const e = new Promise((t) => {
2343
- this.#r = t;
2343
+ this.#s = t;
2344
2344
  }).then(() => !0);
2345
2345
  if (!await Promise.race([e, this.#a.closed])) {
2346
- this.#r = void 0;
2346
+ this.#s = void 0;
2347
2347
  return;
2348
2348
  }
2349
2349
  }
@@ -2383,7 +2383,7 @@ async function Be() {
2383
2383
  polyfill: !0
2384
2384
  }), !0))), await we);
2385
2385
  }
2386
- const Fs = `var __defProp = Object.defineProperty;
2386
+ const Vs = `var __defProp = Object.defineProperty;
2387
2387
  var __getOwnPropNames = Object.getOwnPropertyNames;
2388
2388
  var __esm = (fn, res) => function __init() {
2389
2389
  return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
@@ -5133,12 +5133,14 @@ init_stream();
5133
5133
  var Version2 = {
5134
5134
  DRAFT_01: 4279086337,
5135
5135
  DRAFT_02: 4279086338,
5136
- DRAFT_03: 4279086339
5136
+ DRAFT_03: 4279086339,
5137
+ DRAFT_04: 4279086340
5137
5138
  };
5138
5139
  var VERSION_NAMES2 = {
5139
5140
  [Version2.DRAFT_01]: "moq-lite-01",
5140
5141
  [Version2.DRAFT_02]: "moq-lite-02",
5141
- [Version2.DRAFT_03]: "moq-lite-03"
5142
+ [Version2.DRAFT_03]: "moq-lite-03",
5143
+ [Version2.DRAFT_04]: "moq-lite-04"
5142
5144
  };
5143
5145
 
5144
5146
  // ../lite/src/lite/connection.ts
@@ -5390,14 +5392,14 @@ var AudioRingBuffer = class {
5390
5392
  const dst = newBuffer[channel];
5391
5393
  for (let i = 0; i < samplesToKeep; i++) {
5392
5394
  const srcPos = (copyStart + i) % src.length;
5393
- const dstPos = i % dst.length;
5395
+ const dstPos = (copyStart + i) % dst.length;
5394
5396
  dst[dstPos] = src[srcPos];
5395
5397
  }
5396
5398
  }
5397
5399
  }
5398
5400
  this.#buffer = newBuffer;
5399
5401
  this.#readIndex = this.#writeIndex - samplesToKeep;
5400
- this.#stalled = true;
5402
+ if (samplesToKeep === 0) this.#stalled = true;
5401
5403
  }
5402
5404
  write(timestamp, data) {
5403
5405
  if (data.length !== this.channels) throw new Error("wrong number of channels");
@@ -5494,7 +5496,7 @@ var Render = class extends AudioWorkletProcessor {
5494
5496
  if (samplesRead < output[0].length) {
5495
5497
  this.#underflow += output[0].length - samplesRead;
5496
5498
  } else if (this.#underflow > 0 && this.#buffer) {
5497
- console.warn(\`audio underflow: \${Math.round(1e3 * this.#underflow / this.#buffer.rate)}ms\`);
5499
+ console.debug(\`audio underflow: \${Math.round(1e3 * this.#underflow / this.#buffer.rate)}ms\`);
5498
5500
  this.#underflow = 0;
5499
5501
  }
5500
5502
  this.#stateCounter++;
@@ -5511,23 +5513,23 @@ var Render = class extends AudioWorkletProcessor {
5511
5513
  }
5512
5514
  };
5513
5515
  registerProcessor("render", Render);
5514
- `, Vs = new Blob([Fs], { type: "application/javascript" }), Bs = URL.createObjectURL(Vs);
5515
- let Ls = class {
5516
+ `, Bs = new Blob([Vs], { type: "application/javascript" }), Ls = URL.createObjectURL(Bs);
5517
+ let $s = class {
5516
5518
  source;
5517
5519
  enabled;
5518
5520
  #n = new h(void 0);
5519
5521
  context = this.#n;
5520
5522
  // The root of the audio graph, which can be used for custom visualizations.
5521
- #s = new h(void 0);
5523
+ #t = new h(void 0);
5522
5524
  // Downcast to AudioNode so it matches Publish.Audio
5523
- root = this.#s;
5525
+ root = this.#t;
5524
5526
  #e = new h(void 0);
5525
5527
  sampleRate = this.#e;
5526
- #t = new h(void 0);
5527
- stats = this.#t;
5528
- // Current playback timestamp from worklet
5529
5528
  #r = new h(void 0);
5530
- timestamp = this.#r;
5529
+ stats = this.#r;
5530
+ // Current playback timestamp from worklet
5531
+ #s = new h(void 0);
5532
+ timestamp = this.#s;
5531
5533
  // Whether the audio buffer is stalled (waiting to fill)
5532
5534
  #i = new h(!0);
5533
5535
  stalled = this.#i;
@@ -5538,7 +5540,7 @@ let Ls = class {
5538
5540
  buffered = this.#o;
5539
5541
  #c = new T();
5540
5542
  constructor(e, t) {
5541
- this.source = e, this.source.supported.set($s), this.enabled = h.from(t?.enabled ?? !1), this.#c.run(this.#d.bind(this)), this.#c.run(this.#l.bind(this)), this.#c.run(this.#u.bind(this)), this.#c.run(this.#f.bind(this));
5543
+ this.source = e, this.source.supported.set(js), this.enabled = h.from(t?.enabled ?? !1), this.#c.run(this.#d.bind(this)), this.#c.run(this.#l.bind(this)), this.#c.run(this.#u.bind(this)), this.#c.run(this.#f.bind(this));
5542
5544
  }
5543
5545
  #d(e) {
5544
5546
  const t = e.get(this.source.config);
@@ -5549,7 +5551,7 @@ let Ls = class {
5549
5551
  sampleRate: s
5550
5552
  });
5551
5553
  e.set(this.#n, i), e.cleanup(() => i.close()), e.spawn(async () => {
5552
- if (await i.audioWorklet.addModule(Bs), i.state === "closed") return;
5554
+ if (await i.audioWorklet.addModule(Ls), i.state === "closed") return;
5553
5555
  const a = new AudioWorkletNode(i, "render", {
5554
5556
  channelCount: r,
5555
5557
  channelCountMode: "explicit"
@@ -5559,15 +5561,15 @@ let Ls = class {
5559
5561
  type: "init",
5560
5562
  rate: s,
5561
5563
  channels: r,
5562
- latency: this.source.sync.latency.peek()
5564
+ latency: this.source.sync.buffer.peek()
5563
5565
  // Updated reactively via #runLatency
5564
5566
  };
5565
5567
  a.port.postMessage(o), a.port.onmessage = (c) => {
5566
5568
  if (c.data.type === "state") {
5567
- const u = w.Milli.fromMicro(c.data.timestamp);
5568
- this.#r.set(u), this.#i.set(c.data.stalled), this.#v(u);
5569
+ const u = p.Milli.fromMicro(c.data.timestamp);
5570
+ this.#s.set(u), this.#i.set(c.data.stalled), this.#v(u);
5569
5571
  }
5570
- }, e.set(this.#s, a);
5572
+ }, e.set(this.#t, a);
5571
5573
  });
5572
5574
  }
5573
5575
  #l(e) {
@@ -5577,11 +5579,11 @@ let Ls = class {
5577
5579
  r.resume();
5578
5580
  }
5579
5581
  #u(e) {
5580
- const t = e.get(this.#s);
5582
+ const t = e.get(this.#t);
5581
5583
  if (!t) return;
5582
5584
  const r = {
5583
5585
  type: "latency",
5584
- latency: e.get(this.source.sync.latency)
5586
+ latency: e.get(this.source.sync.buffer)
5585
5587
  };
5586
5588
  t.port.postMessage(r);
5587
5589
  }
@@ -5600,11 +5602,11 @@ let Ls = class {
5600
5602
  }
5601
5603
  #m(e, t, s) {
5602
5604
  const r = new J(t, {
5603
- latency: this.source.sync.latency
5605
+ latency: this.source.sync.buffer
5604
5606
  });
5605
5607
  e.cleanup(() => r.close()), e.run((i) => {
5606
5608
  const a = i.get(r.buffered), o = i.get(this.#a);
5607
- this.#o.update(() => js(a, o));
5609
+ this.#o.update(() => Gs(a, o));
5608
5610
  }), e.spawn(async () => {
5609
5611
  if (!await Be()) return;
5610
5612
  let a = 0;
@@ -5630,9 +5632,9 @@ let Ls = class {
5630
5632
  if (!u) break;
5631
5633
  const { frame: d } = u;
5632
5634
  if (!d) continue;
5633
- const l = w.Milli.fromMicro(d.timestamp);
5634
- this.source.sync.received(l, "audio"), this.#t.update((p) => ({
5635
- bytesReceived: (p?.bytesReceived ?? 0) + d.data.byteLength
5635
+ const l = p.Milli.fromMicro(d.timestamp);
5636
+ this.source.sync.received(l, "audio"), this.#r.update((w) => ({
5637
+ bytesReceived: (w?.bytesReceived ?? 0) + d.data.byteLength
5636
5638
  }));
5637
5639
  const f = new EncodedAudioChunk({
5638
5640
  type: d.keyframe ? "key" : "delta",
@@ -5670,18 +5672,18 @@ let Ls = class {
5670
5672
  for (; ; ) {
5671
5673
  const u = await c.readFrame();
5672
5674
  if (!u) break;
5673
- const d = yn(u, r);
5675
+ const d = _n(u, r);
5674
5676
  for (const l of d) {
5675
- const f = w.Milli.fromMicro(l.timestamp);
5676
- this.source.sync.received(f, "audio"), this.#t.update((b) => ({
5677
+ const f = p.Milli.fromMicro(l.timestamp);
5678
+ this.source.sync.received(f, "audio"), this.#r.update((b) => ({
5677
5679
  bytesReceived: (b?.bytesReceived ?? 0) + l.data.byteLength
5678
5680
  }));
5679
- const p = new EncodedAudioChunk({
5681
+ const w = new EncodedAudioChunk({
5680
5682
  type: l.keyframe ? "key" : "delta",
5681
5683
  data: l.data,
5682
5684
  timestamp: l.timestamp
5683
5685
  });
5684
- o.decode(p);
5686
+ o.decode(w);
5685
5687
  }
5686
5688
  }
5687
5689
  } finally {
@@ -5692,12 +5694,12 @@ let Ls = class {
5692
5694
  });
5693
5695
  }
5694
5696
  #h(e) {
5695
- const t = e.timestamp, s = w.Milli.fromMicro(t), r = this.#s.peek();
5697
+ const t = e.timestamp, s = p.Milli.fromMicro(t), r = this.#t.peek();
5696
5698
  if (!r) {
5697
5699
  e.close();
5698
5700
  return;
5699
5701
  }
5700
- const i = e.numberOfFrames / e.sampleRate * 1e6, a = w.Milli.fromMicro(i), o = w.Milli.add(s, a);
5702
+ const i = e.numberOfFrames / e.sampleRate * 1e6, a = p.Milli.fromMicro(i), o = p.Milli.add(s, a);
5701
5703
  this.#w(s, o);
5702
5704
  const c = [];
5703
5705
  for (let d = 0; d < e.numberOfChannels; d++) {
@@ -5718,7 +5720,7 @@ let Ls = class {
5718
5720
  e > t || this.#a.mutate((s) => {
5719
5721
  for (const r of s)
5720
5722
  if (e <= r.end + 1 && t >= r.start) {
5721
- r.start = w.Milli.min(r.start, e), r.end = w.Milli.max(r.end, t);
5723
+ r.start = p.Milli.min(r.start, e), r.end = p.Milli.max(r.end, t);
5722
5724
  return;
5723
5725
  }
5724
5726
  s.push({ start: e, end: t }), s.sort((r, i) => r.start - i.start);
@@ -5728,7 +5730,7 @@ let Ls = class {
5728
5730
  this.#a.mutate((t) => {
5729
5731
  for (; t.length > 0; ) {
5730
5732
  if (t[0].end >= e) {
5731
- t[0].start = w.Milli.max(t[0].start, e);
5733
+ t[0].start = p.Milli.max(t[0].start, e);
5732
5734
  break;
5733
5735
  }
5734
5736
  t.shift();
@@ -5739,25 +5741,25 @@ let Ls = class {
5739
5741
  this.#c.close();
5740
5742
  }
5741
5743
  };
5742
- async function $s(n) {
5744
+ async function js(n) {
5743
5745
  const e = n.description ? q(n.description) : void 0;
5744
5746
  return (await AudioDecoder.isConfigSupported({
5745
5747
  ...n,
5746
5748
  description: e
5747
5749
  })).supported ?? !1;
5748
5750
  }
5749
- function js(n, e) {
5751
+ function Gs(n, e) {
5750
5752
  if (n.length === 0) return e;
5751
5753
  if (e.length === 0) return n;
5752
5754
  const t = [], s = [...n, ...e].sort((r, i) => r.start - i.start);
5753
5755
  for (const r of s) {
5754
5756
  const i = t.at(-1);
5755
- i && i.end >= r.start ? i.end = w.Milli.max(i.end, r.end) : t.push({ ...r });
5757
+ i && i.end >= r.start ? i.end = p.Milli.max(i.end, r.end) : t.push({ ...r });
5756
5758
  }
5757
5759
  return t;
5758
5760
  }
5759
5761
  const Le = 1e-3, ve = 0.2;
5760
- class Gs {
5762
+ class Zs {
5761
5763
  source;
5762
5764
  volume;
5763
5765
  muted;
@@ -5766,12 +5768,12 @@ class Gs {
5766
5768
  paused;
5767
5769
  #n = new T();
5768
5770
  // The volume to use when unmuted.
5769
- #s = 0.5;
5771
+ #t = 0.5;
5770
5772
  // The gain node used to adjust the volume.
5771
5773
  #e = new h(void 0);
5772
5774
  constructor(e, t) {
5773
5775
  this.source = e, this.volume = h.from(t?.volume ?? 0.5), this.muted = h.from(t?.muted ?? !1), this.paused = h.from(t?.paused ?? t?.muted ?? !1), this.#n.run((s) => {
5774
- s.get(this.muted) ? (this.#s = this.volume.peek() || 0.5, this.volume.set(0)) : this.volume.set(this.#s);
5776
+ s.get(this.muted) ? (this.#t = this.volume.peek() || 0.5, this.volume.set(0)) : this.volume.set(this.#t);
5775
5777
  }), this.#n.run((s) => {
5776
5778
  const r = !s.get(this.paused) && !s.get(this.muted);
5777
5779
  this.source.enabled.set(r);
@@ -5797,17 +5799,17 @@ class Gs {
5797
5799
  this.#n.close();
5798
5800
  }
5799
5801
  }
5800
- class In {
5802
+ class Rn {
5801
5803
  element;
5802
5804
  paused;
5803
5805
  #n;
5804
- #s = new h(void 0);
5805
- mediaSource = this.#s;
5806
+ #t = new h(void 0);
5807
+ mediaSource = this.#t;
5806
5808
  #e = new T();
5807
5809
  constructor(e, t) {
5808
- this.element = h.from(t?.element), this.paused = h.from(t?.paused ?? !1), this.#n = e, this.#e.run(this.#t.bind(this)), this.#e.run(this.#r.bind(this)), this.#e.run(this.#i.bind(this)), this.#e.run(this.#a.bind(this)), this.#e.run(this.#o.bind(this));
5810
+ this.element = h.from(t?.element), this.paused = h.from(t?.paused ?? !1), this.#n = e, this.#e.run(this.#r.bind(this)), this.#e.run(this.#s.bind(this)), this.#e.run(this.#i.bind(this)), this.#e.run(this.#a.bind(this)), this.#e.run(this.#o.bind(this));
5809
5811
  }
5810
- #t(e) {
5812
+ #r(e) {
5811
5813
  const t = e.get(this.element);
5812
5814
  if (!t) return;
5813
5815
  const s = new MediaSource();
@@ -5815,17 +5817,17 @@ class In {
5815
5817
  s,
5816
5818
  "sourceopen",
5817
5819
  () => {
5818
- e.set(this.#s, s);
5820
+ e.set(this.#t, s);
5819
5821
  },
5820
5822
  { once: !0 }
5821
5823
  ), e.event(s, "error", (r) => {
5822
5824
  console.error("[MSE] MediaSource error event:", r);
5823
5825
  });
5824
5826
  }
5825
- #r(e) {
5827
+ #s(e) {
5826
5828
  const t = e.get(this.element);
5827
5829
  if (!t || e.get(this.paused)) return;
5828
- const r = w.Milli.toSecond(e.get(this.#n.latency));
5830
+ const r = p.Milli.toSecond(e.get(this.#n.buffer));
5829
5831
  e.interval(() => {
5830
5832
  const i = t.buffered;
5831
5833
  if (i.length === 0) return;
@@ -5859,57 +5861,85 @@ class In {
5859
5861
  if (!t || e.get(this.paused)) return;
5860
5862
  const r = e.get(this.#n.reference);
5861
5863
  if (r === void 0) return;
5862
- const i = e.get(this.#n.latency), a = w.Milli.sub(w.Milli.sub(w.Milli.now(), r), i);
5863
- t.currentTime = w.Milli.toSecond(a);
5864
+ const i = e.get(this.#n.buffer), a = p.Milli.sub(p.Milli.sub(p.Milli.now(), r), i);
5865
+ t.currentTime = p.Milli.toSecond(a);
5864
5866
  }
5865
5867
  close() {
5866
5868
  this.#e.close();
5867
5869
  }
5868
5870
  }
5869
- const pr = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
5871
+ const gr = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
5870
5872
  __proto__: null,
5871
- Muxer: In
5872
- }, Symbol.toStringTag, { value: "Module" }));
5873
+ Muxer: Rn
5874
+ }, Symbol.toStringTag, { value: "Module" })), Xs = 10, $e = 100;
5873
5875
  class Se {
5874
5876
  // The earliest time we've received a frame, relative to its timestamp.
5875
5877
  // This will keep being updated as we catch up to the live playhead then will be relatively static.
5876
- // TODO Update this when RTT changes
5877
5878
  #n = new h(void 0);
5878
5879
  reference = this.#n;
5879
- // The minimum buffer size, to account for network jitter.
5880
+ // The latency setting: "real-time" auto-computes jitter from RTT, a number sets a fixed jitter.
5881
+ latency;
5882
+ // The jitter buffer in milliseconds (always numeric).
5883
+ // In "real-time" mode this is updated automatically from RTT.
5884
+ // When latency is a number, jitter equals that number.
5880
5885
  jitter;
5881
5886
  // Any additional delay required for audio or video.
5882
5887
  audio;
5883
5888
  video;
5884
- // The buffer required, based on both audio and video.
5885
- #s = new h(w.Milli.zero);
5886
- latency = this.#s;
5887
- // A ghetto way to learn when the reference/latency changes.
5889
+ // The total buffer required: jitter + max(audio, video).
5890
+ #t = new h(p.Milli.zero);
5891
+ buffer = this.#t;
5892
+ // A ghetto way to learn when the reference/buffer changes.
5888
5893
  // There's probably a way to use Effect, but lets keep it simple for now.
5889
5894
  #e;
5895
+ // The media timestamp of the most recently received frame.
5896
+ timestamp = new h(void 0);
5890
5897
  // Per-label late-frame tracking: accumulate count and max lateness, flush on recovery.
5891
- #t = /* @__PURE__ */ new Map();
5898
+ #r = /* @__PURE__ */ new Map();
5899
+ // RTT signal from the connection (PROBE or getStats).
5900
+ rtt;
5901
+ // Minimum RTT seen, used as the baseline for jitter calculation.
5902
+ // Avoids inflating jitter due to bufferbloat.
5903
+ #s;
5892
5904
  signals = new T();
5893
5905
  constructor(e) {
5894
- this.jitter = h.from(e?.jitter ?? 100), this.audio = h.from(e?.audio), this.video = h.from(e?.video), this.#e = Promise.withResolvers(), this.signals.run(this.#r.bind(this));
5906
+ this.latency = h.from(e?.latency ?? "real-time"), this.jitter = new h($e), this.rtt = e?.rtt, this.audio = h.from(e?.audio), this.video = h.from(e?.video), this.#e = Promise.withResolvers(), this.signals.run(this.#i.bind(this)), this.signals.run(this.#a.bind(this));
5895
5907
  }
5896
- #r(e) {
5897
- const t = e.get(this.jitter), s = e.get(this.video) ?? w.Milli.zero, r = e.get(this.audio) ?? w.Milli.zero, i = w.Milli.add(w.Milli.max(s, r), t);
5898
- this.#s.set(i), this.#e.resolve(), this.#e = Promise.withResolvers();
5908
+ #i(e) {
5909
+ const t = e.get(this.latency);
5910
+ if (typeof t == "number") {
5911
+ this.#s = void 0, this.jitter.set(t);
5912
+ return;
5913
+ }
5914
+ if (this.rtt) {
5915
+ const s = e.get(this.rtt);
5916
+ if (s !== void 0) {
5917
+ this.#s = this.#s !== void 0 ? Math.min(this.#s, s) : s;
5918
+ const r = Math.max(Xs, this.#s * 1.25);
5919
+ this.jitter.set(r);
5920
+ return;
5921
+ }
5922
+ }
5923
+ this.#s = void 0, this.jitter.set($e);
5924
+ }
5925
+ #a(e) {
5926
+ const t = e.get(this.jitter), s = e.get(this.video) ?? p.Milli.zero, r = e.get(this.audio) ?? p.Milli.zero, i = p.Milli.add(p.Milli.max(s, r), t);
5927
+ this.#t.set(i), this.#e.resolve(), this.#e = Promise.withResolvers();
5899
5928
  }
5900
5929
  // Update the reference if this is the earliest frame we've seen, relative to its timestamp.
5901
5930
  received(e, t = "") {
5902
- const s = w.Milli.now(), r = w.Milli.sub(s, e), i = this.#n.peek();
5931
+ this.timestamp.update((a) => a === void 0 || e > a ? e : a);
5932
+ const s = p.Milli.now(), r = p.Milli.sub(s, e), i = this.#n.peek();
5903
5933
  if (i !== void 0) {
5904
- const a = w.Milli.add(w.Milli.sub(i, r), this.#s.peek());
5934
+ const a = p.Milli.add(p.Milli.sub(i, r), this.#t.peek());
5905
5935
  if (a < 0) {
5906
- const o = this.#t.get(t);
5907
- o ? (o.count++, o.maxMs = Math.max(o.maxMs, -a)) : this.#t.set(t, { count: 1, maxMs: -a });
5936
+ const o = this.#r.get(t);
5937
+ o ? (o.count++, o.maxMs = Math.max(o.maxMs, -a)) : this.#r.set(t, { count: 1, maxMs: -a });
5908
5938
  } else {
5909
- const o = this.#t.get(t);
5939
+ const o = this.#r.get(t);
5910
5940
  if (o) {
5911
- const c = t ? `sync[${t}]` : "sync", u = Se.#i(o.maxMs);
5912
- console.warn(`${c}: ${o.count} late frame(s), max ${u} behind`), this.#t.delete(t);
5941
+ const c = t ? `sync[${t}]` : "sync", u = Se.#o(o.maxMs);
5942
+ console.debug(`${c}: ${o.count} late frame(s), max ${u} behind`), this.#r.delete(t);
5913
5943
  }
5914
5944
  }
5915
5945
  if (r >= i)
@@ -5922,15 +5952,15 @@ class Se {
5922
5952
  if (this.#n.peek() === void 0)
5923
5953
  throw new Error("reference not set; call update() first");
5924
5954
  for (; ; ) {
5925
- const s = w.Milli.now(), r = w.Milli.sub(s, e), i = this.#n.peek();
5955
+ const s = p.Milli.now(), r = p.Milli.sub(s, e), i = this.#n.peek();
5926
5956
  if (i === void 0) return;
5927
- const a = w.Milli.add(w.Milli.sub(i, r), this.#s.peek());
5928
- if (a <= 0) return;
5957
+ const a = p.Milli.add(p.Milli.sub(i, r), this.#t.peek());
5958
+ if (a <= 0 || a < 5) return;
5929
5959
  const o = new Promise((u) => setTimeout(u, a)).then(() => !0);
5930
5960
  if (await Promise.race([this.#e.promise, o])) return;
5931
5961
  }
5932
5962
  }
5933
- static #i(e) {
5963
+ static #o(e) {
5934
5964
  if (e = Math.round(e), e < 1e3) return `${e}ms`;
5935
5965
  const t = e / 1e3;
5936
5966
  if (t < 60) return `${Math.round(t * 10) / 10}s`;
@@ -5941,24 +5971,24 @@ class Se {
5941
5971
  this.signals.close();
5942
5972
  }
5943
5973
  }
5944
- const Zs = 500, Xs = 100;
5945
- class Hs {
5974
+ const Hs = 500, Ws = 100;
5975
+ class Ks {
5946
5976
  enabled;
5947
5977
  // Don't download any longer
5948
5978
  source;
5949
5979
  // The current track running, held so we can cancel it when the new track is ready.
5950
5980
  #n = new h(void 0);
5951
5981
  // Expose the current frame to render as a signal
5952
- #s = new h(void 0);
5953
- frame = this.#s;
5982
+ #t = new h(void 0);
5983
+ frame = this.#t;
5954
5984
  // The timestamp of the current frame.
5955
5985
  #e = new h(void 0);
5956
5986
  timestamp = this.#e;
5957
5987
  // The display size of the video in pixels, ideally sourced from the catalog.
5958
- #t = new h(void 0);
5959
- display = this.#t;
5960
- #r = new h(!1);
5961
- stalled = this.#r;
5988
+ #r = new h(void 0);
5989
+ display = this.#r;
5990
+ #s = new h(!1);
5991
+ stalled = this.#s;
5962
5992
  #i = new h(void 0);
5963
5993
  stats = this.#i;
5964
5994
  // Combined buffered ranges (network jitter + decode buffer)
@@ -5966,7 +5996,7 @@ class Hs {
5966
5996
  buffered = this.#a;
5967
5997
  #o = new T();
5968
5998
  constructor(e, t) {
5969
- this.enabled = h.from(t?.enabled ?? !1), this.source = e, this.source.supported.set(Ys), this.#o.run(this.#c.bind(this)), this.#o.run(this.#d.bind(this)), this.#o.run(this.#l.bind(this)), this.#o.run(this.#u.bind(this));
5999
+ this.enabled = h.from(t?.enabled ?? !1), this.source = e, this.source.supported.set(Qs), this.#o.run(this.#c.bind(this)), this.#o.run(this.#d.bind(this)), this.#o.run(this.#l.bind(this)), this.#o.run(this.#u.bind(this));
5970
6000
  }
5971
6001
  #c(e) {
5972
6002
  const t = e.getAll([this.enabled, this.source.broadcast, this.source.track, this.source.config]);
@@ -5976,7 +6006,7 @@ class Hs {
5976
6006
  }
5977
6007
  const [s, r, i, a] = t, o = e.get(r.active);
5978
6008
  if (!o) return;
5979
- let c = new Ws({
6009
+ let c = new Ys({
5980
6010
  source: this.source,
5981
6011
  broadcast: o,
5982
6012
  track: i,
@@ -5988,7 +6018,7 @@ class Hs {
5988
6018
  const d = u.get(this.#n);
5989
6019
  if (d) {
5990
6020
  const l = u.get(c.timestamp), f = u.get(d.timestamp);
5991
- if (!l || f && f > l + Xs) return;
6021
+ if (!l || f && f > l + Ws) return;
5992
6022
  }
5993
6023
  this.#n.set(c), c = void 0, u.close();
5994
6024
  });
@@ -6001,7 +6031,7 @@ class Hs {
6001
6031
  }
6002
6032
  e.cleanup(() => t.close()), e.run((s) => {
6003
6033
  const r = s.get(t.frame);
6004
- this.#s.update((i) => (i?.close(), r?.clone()));
6034
+ this.#t.update((i) => (i?.close(), r?.clone()));
6005
6035
  }), e.proxy(this.#e, t.timestamp), e.proxy(this.#a, t.buffered);
6006
6036
  }
6007
6037
  #l(e) {
@@ -6009,14 +6039,14 @@ class Hs {
6009
6039
  if (!t) return;
6010
6040
  const s = t.display;
6011
6041
  if (s) {
6012
- e.set(this.#t, {
6042
+ e.set(this.#r, {
6013
6043
  width: s.width,
6014
6044
  height: s.height
6015
6045
  });
6016
6046
  return;
6017
6047
  }
6018
6048
  const r = e.get(this.frame);
6019
- r && e.set(this.#t, {
6049
+ r && e.set(this.#r, {
6020
6050
  width: r.displayWidth,
6021
6051
  height: r.displayHeight
6022
6052
  });
@@ -6024,20 +6054,20 @@ class Hs {
6024
6054
  #u(e) {
6025
6055
  if (!e.get(this.enabled)) return;
6026
6056
  if (!e.get(this.frame)) {
6027
- this.#r.set(!0);
6057
+ this.#s.set(!0);
6028
6058
  return;
6029
6059
  }
6030
- this.#r.set(!1), e.timer(() => {
6031
- this.#r.set(!0);
6032
- }, Zs);
6060
+ this.#s.set(!1), e.timer(() => {
6061
+ this.#s.set(!0);
6062
+ }, Hs);
6033
6063
  }
6034
6064
  close() {
6035
- this.#s.update((e) => {
6065
+ this.#t.update((e) => {
6036
6066
  e?.close();
6037
6067
  }), this.#o.close();
6038
6068
  }
6039
6069
  }
6040
- class Ws {
6070
+ class Ys {
6041
6071
  source;
6042
6072
  broadcast;
6043
6073
  track;
@@ -6052,15 +6082,15 @@ class Ws {
6052
6082
  signals = new T();
6053
6083
  constructor(e) {
6054
6084
  const { codedWidth: t, codedHeight: s, ...r } = e.config;
6055
- this.source = e.source, this.broadcast = e.broadcast, this.track = e.track, this.config = r, this.stats = e.stats, this.signals.run(this.#s.bind(this));
6085
+ this.source = e.source, this.broadcast = e.broadcast, this.track = e.track, this.config = r, this.stats = e.stats, this.signals.run(this.#t.bind(this));
6056
6086
  }
6057
- #s(e) {
6087
+ #t(e) {
6058
6088
  const t = this.broadcast.subscribe(this.track, W.video);
6059
6089
  e.cleanup(() => t.close());
6060
6090
  const s = new VideoDecoder({
6061
6091
  output: async (r) => {
6062
6092
  try {
6063
- const i = w.Milli.fromMicro(r.timestamp);
6093
+ const i = p.Milli.fromMicro(r.timestamp);
6064
6094
  if (i < (this.timestamp.peek() ?? 0))
6065
6095
  return;
6066
6096
  this.frame.peek() === void 0 && this.frame.set(r.clone());
@@ -6079,15 +6109,15 @@ class Ws {
6079
6109
  });
6080
6110
  e.cleanup(() => {
6081
6111
  s.state !== "closed" && s.close();
6082
- }), this.config.container.kind === "cmaf" ? this.#t(e, t, s) : this.#e(e, t, s);
6112
+ }), this.config.container.kind === "cmaf" ? this.#r(e, t, s) : this.#e(e, t, s);
6083
6113
  }
6084
6114
  #e(e, t, s) {
6085
6115
  const r = new J(t, {
6086
- latency: this.source.sync.latency
6116
+ latency: this.source.sync.buffer
6087
6117
  });
6088
6118
  e.cleanup(() => r.close()), e.run((a) => {
6089
6119
  const o = a.get(r.buffered), c = a.get(this.#n);
6090
- this.buffered.update(() => Ks(o, c));
6120
+ this.buffered.update(() => Js(o, c));
6091
6121
  }), s.configure({
6092
6122
  ...this.config,
6093
6123
  description: this.config.description ? q(this.config.description) : void 0,
@@ -6105,7 +6135,7 @@ class Ws {
6105
6135
  i && (i.final = !0);
6106
6136
  continue;
6107
6137
  }
6108
- const u = w.Milli.fromMicro(o.timestamp);
6138
+ const u = p.Milli.fromMicro(o.timestamp);
6109
6139
  this.source.sync.received(u, "video");
6110
6140
  const d = new EncodedVideoChunk({
6111
6141
  type: o.keyframe ? "key" : "delta",
@@ -6116,8 +6146,8 @@ class Ws {
6116
6146
  frameCount: (l?.frameCount ?? 0) + 1,
6117
6147
  bytesReceived: (l?.bytesReceived ?? 0) + o.data.byteLength
6118
6148
  })), i?.group === c || i?.final && i.group + 1 === c) {
6119
- const l = w.Milli.fromMicro(i.timestamp), f = w.Milli.fromMicro(o.timestamp);
6120
- this.#r(l, f);
6149
+ const l = p.Milli.fromMicro(i.timestamp), f = p.Milli.fromMicro(o.timestamp);
6150
+ this.#s(l, f);
6121
6151
  }
6122
6152
  i = {
6123
6153
  timestamp: o.timestamp,
@@ -6127,7 +6157,7 @@ class Ws {
6127
6157
  }
6128
6158
  });
6129
6159
  }
6130
- #t(e, t, s) {
6160
+ #r(e, t, s) {
6131
6161
  if (this.config.container.kind !== "cmaf") return;
6132
6162
  const { timescale: r } = this.config.container, i = this.config.description ? q(this.config.description) : void 0;
6133
6163
  s.configure({
@@ -6149,19 +6179,19 @@ class Ws {
6149
6179
  for (; ; ) {
6150
6180
  const c = await Promise.race([a.readFrame(), e.cancel]);
6151
6181
  if (!c) break;
6152
- const u = yn(c, r);
6182
+ const u = _n(c, r);
6153
6183
  for (const d of u) {
6154
6184
  const l = new EncodedVideoChunk({
6155
6185
  type: d.keyframe ? "key" : "delta",
6156
6186
  data: d.data,
6157
6187
  timestamp: d.timestamp
6158
- }), f = w.Milli.fromMicro(d.timestamp);
6159
- if (this.source.sync.received(f, "video"), this.stats.update((p) => ({
6160
- frameCount: (p?.frameCount ?? 0) + 1,
6161
- bytesReceived: (p?.bytesReceived ?? 0) + d.data.byteLength
6188
+ }), f = p.Milli.fromMicro(d.timestamp);
6189
+ if (this.source.sync.received(f, "video"), this.stats.update((w) => ({
6190
+ frameCount: (w?.frameCount ?? 0) + 1,
6191
+ bytesReceived: (w?.bytesReceived ?? 0) + d.data.byteLength
6162
6192
  })), o !== void 0) {
6163
- const p = w.Milli.fromMicro(o), b = w.Milli.fromMicro(d.timestamp);
6164
- this.#r(p, b);
6193
+ const w = p.Milli.fromMicro(o), b = p.Milli.fromMicro(d.timestamp);
6194
+ this.#s(w, b);
6165
6195
  }
6166
6196
  o = d.timestamp, s.decode(l);
6167
6197
  }
@@ -6174,11 +6204,11 @@ class Ws {
6174
6204
  });
6175
6205
  }
6176
6206
  // Add a range to the decode buffer (decoded, waiting to render)
6177
- #r(e, t) {
6207
+ #s(e, t) {
6178
6208
  e > t || this.#n.mutate((s) => {
6179
6209
  for (const r of s)
6180
6210
  if (r.start <= t && r.end >= e) {
6181
- r.start = w.Milli.min(r.start, e), r.end = w.Milli.max(r.end, t);
6211
+ r.start = p.Milli.min(r.start, e), r.end = p.Milli.max(r.end, t);
6182
6212
  return;
6183
6213
  }
6184
6214
  s.push({ start: e, end: t }), s.sort((r, i) => r.start - i.start);
@@ -6189,7 +6219,7 @@ class Ws {
6189
6219
  this.#n.mutate((t) => {
6190
6220
  for (; t.length > 0; ) {
6191
6221
  if (t[0].end >= e) {
6192
- t[0].start = w.Milli.max(t[0].start, e);
6222
+ t[0].start = p.Milli.max(t[0].start, e);
6193
6223
  break;
6194
6224
  }
6195
6225
  t.shift();
@@ -6202,17 +6232,17 @@ class Ws {
6202
6232
  });
6203
6233
  }
6204
6234
  }
6205
- function Ks(n, e) {
6235
+ function Js(n, e) {
6206
6236
  if (n.length === 0) return e;
6207
6237
  if (e.length === 0) return n;
6208
6238
  const t = [], s = [...n, ...e].sort((r, i) => r.start - i.start);
6209
6239
  for (const r of s) {
6210
6240
  const i = t.at(-1);
6211
- i && i.end >= r.start ? i.end = w.Milli.max(i.end, r.end) : t.push({ ...r });
6241
+ i && i.end >= r.start ? i.end = p.Milli.max(i.end, r.end) : t.push({ ...r });
6212
6242
  }
6213
6243
  return t;
6214
6244
  }
6215
- async function Ys(n) {
6245
+ async function Qs(n) {
6216
6246
  const e = n.description ? q(n.description) : void 0, { supported: t } = await VideoDecoder.isConfigSupported({
6217
6247
  codec: n.codec,
6218
6248
  description: e,
@@ -6220,23 +6250,23 @@ async function Ys(n) {
6220
6250
  });
6221
6251
  return t ?? !1;
6222
6252
  }
6223
- let Js = class {
6253
+ let er = class {
6224
6254
  muxer;
6225
6255
  source;
6226
6256
  // TODO implement stats
6227
6257
  #n = new h(void 0);
6228
6258
  stats = this.#n;
6229
- #s = new h([]);
6230
- buffered = this.#s;
6259
+ #t = new h([]);
6260
+ buffered = this.#t;
6231
6261
  #e = new h(!1);
6232
6262
  stalled = this.#e;
6233
- #t = new h(_.Time.Milli.zero);
6234
- timestamp = this.#t;
6263
+ #r = new h(_.Time.Milli.zero);
6264
+ timestamp = this.#r;
6235
6265
  signals = new T();
6236
6266
  constructor(e, t) {
6237
- this.muxer = e, this.source = t, this.source.supported.set(Qs), this.signals.run(this.#r.bind(this)), this.signals.run(this.#c.bind(this)), this.signals.run(this.#d.bind(this));
6267
+ this.muxer = e, this.source = t, this.source.supported.set(nr), this.signals.run(this.#s.bind(this)), this.signals.run(this.#c.bind(this)), this.signals.run(this.#d.bind(this));
6238
6268
  }
6239
- #r(e) {
6269
+ #s(e) {
6240
6270
  const t = e.get(this.muxer.element);
6241
6271
  if (!t) return;
6242
6272
  const s = e.get(this.muxer.mediaSource);
@@ -6255,7 +6285,7 @@ let Js = class {
6255
6285
  }), e.event(u, "error", (d) => {
6256
6286
  console.error("[MSE] SourceBuffer error:", d);
6257
6287
  }), e.event(u, "updateend", () => {
6258
- this.#s.set(Rn(u.buffered));
6288
+ this.#t.set(En(u.buffered));
6259
6289
  }), o.container.kind === "cmaf" ? this.#a(e, i, a, o, u, t) : this.#o(e, i, a, o, u, t);
6260
6290
  }
6261
6291
  async #i(e, t) {
@@ -6274,7 +6304,7 @@ let Js = class {
6274
6304
  for (await this.#i(i, u); ; ) {
6275
6305
  const d = await o.readFrame();
6276
6306
  if (!d) return;
6277
- const l = gn(d, c);
6307
+ const l = yn(d, c);
6278
6308
  this.source.sync.received(_.Time.Milli.fromMicro(l), "video"), await this.#i(i, d), a.buffered.length > 0 && a.currentTime < a.buffered.start(0) && (a.currentTime = a.buffered.start(0));
6279
6309
  }
6280
6310
  });
@@ -6283,31 +6313,31 @@ let Js = class {
6283
6313
  const o = t.subscribe(s, W.video);
6284
6314
  e.cleanup(() => o.close());
6285
6315
  const c = new J(o, {
6286
- latency: this.source.sync.latency
6316
+ latency: this.source.sync.buffer
6287
6317
  });
6288
6318
  e.cleanup(() => c.close()), e.spawn(async () => {
6289
6319
  const u = Fe(r);
6290
6320
  await this.#i(i, u);
6291
6321
  let d = 1, l, f;
6292
6322
  for (; ; ) {
6293
- const p = await c.next();
6294
- if (!p) return;
6295
- if (!p.frame) continue;
6296
- f = p.frame;
6323
+ const w = await c.next();
6324
+ if (!w) return;
6325
+ if (!w.frame) continue;
6326
+ f = w.frame;
6297
6327
  const b = _.Time.Milli.fromMicro(f.timestamp);
6298
6328
  this.source.sync.received(b, "video");
6299
6329
  break;
6300
6330
  }
6301
6331
  for (; ; ) {
6302
- const p = await c.next();
6303
- if (p && !p.frame) continue;
6304
- const b = p?.frame;
6332
+ const w = await c.next();
6333
+ if (w && !w.frame) continue;
6334
+ const b = w?.frame;
6305
6335
  if (b) {
6306
6336
  l = _.Time.Micro.sub(b.timestamp, f.timestamp);
6307
6337
  const R = _.Time.Milli.fromMicro(b.timestamp);
6308
6338
  this.source.sync.received(R, "video");
6309
6339
  }
6310
- const g = An({
6340
+ const g = In({
6311
6341
  data: f.data,
6312
6342
  timestamp: f.timestamp,
6313
6343
  duration: l ?? 0,
@@ -6336,38 +6366,40 @@ let Js = class {
6336
6366
  let r;
6337
6367
  const i = () => {
6338
6368
  const a = _.Time.Milli.fromSecond(s.currentTime);
6339
- this.#t.set(a), r = s.requestVideoFrameCallback(i);
6369
+ this.#r.set(a), r = s.requestVideoFrameCallback(i);
6340
6370
  };
6341
6371
  r = s.requestVideoFrameCallback(i), e.cleanup(() => s.cancelVideoFrameCallback(r));
6342
6372
  } else
6343
6373
  e.event(t, "timeupdate", () => {
6344
6374
  const s = _.Time.Milli.fromSecond(t.currentTime);
6345
- this.#t.set(s);
6375
+ this.#r.set(s);
6346
6376
  });
6347
6377
  }
6348
6378
  close() {
6349
6379
  this.source.close(), this.signals.close();
6350
6380
  }
6351
6381
  };
6352
- async function Qs(n) {
6382
+ async function nr(n) {
6353
6383
  return MediaSource.isTypeSupported(`video/mp4; codecs="${n.codec}"`);
6354
6384
  }
6355
- class er {
6385
+ class tr {
6356
6386
  decoder;
6357
6387
  // The canvas to render the video to.
6358
6388
  canvas;
6359
6389
  // Whether the video is paused.
6360
6390
  paused;
6361
- // Cache the last rendered frame to keep it visible when paused
6362
- #n;
6363
- #s = new h(void 0);
6364
- #e = new h(!1);
6365
- #t = new T();
6391
+ // The most recently rendered frame, updated after each rAF paint.
6392
+ frame = new h(void 0);
6393
+ // The media timestamp of the most recently rendered frame.
6394
+ timestamp = new h(void 0);
6395
+ #n = new h(void 0);
6396
+ #t = new h(!1);
6397
+ #e = new T();
6366
6398
  constructor(e, t) {
6367
- this.decoder = e, this.canvas = h.from(t?.canvas), this.paused = h.from(t?.paused ?? !1), this.#t.run((s) => {
6399
+ this.decoder = e, this.canvas = h.from(t?.canvas), this.paused = h.from(t?.paused ?? !1), this.#e.run((s) => {
6368
6400
  const r = s.get(this.canvas);
6369
- this.#s.set(r?.getContext("2d") ?? void 0);
6370
- }), this.#t.run(this.#i.bind(this)), this.#t.run(this.#a.bind(this)), this.#t.run(this.#o.bind(this)), this.#t.run(this.#r.bind(this));
6401
+ this.#n.set(r?.getContext("2d") ?? void 0);
6402
+ }), this.#e.run(this.#s.bind(this)), this.#e.run(this.#i.bind(this)), this.#e.run(this.#a.bind(this)), this.#e.run(this.#r.bind(this));
6371
6403
  }
6372
6404
  #r(e) {
6373
6405
  const t = e.getAll([this.canvas, this.decoder.display]);
@@ -6376,15 +6408,15 @@ class er {
6376
6408
  (s.width !== r.width || s.height !== r.height) && (s.width = r.width, s.height = r.height);
6377
6409
  }
6378
6410
  // Track whether the canvas is visible in the viewport and the tab is focused.
6379
- #i(e) {
6411
+ #s(e) {
6380
6412
  const t = e.get(this.canvas);
6381
6413
  if (!t) {
6382
- this.#e.set(!1);
6414
+ this.#t.set(!1);
6383
6415
  return;
6384
6416
  }
6385
6417
  let s = !1;
6386
6418
  const r = () => {
6387
- this.#e.set(s && !document.hidden);
6419
+ this.#t.set(s && !document.hidden);
6388
6420
  }, i = new IntersectionObserver(
6389
6421
  (a) => {
6390
6422
  for (const o of a)
@@ -6392,31 +6424,33 @@ class er {
6392
6424
  },
6393
6425
  { threshold: 0.01 }
6394
6426
  );
6395
- e.event(document, "visibilitychange", r), i.observe(t), e.cleanup(() => i.disconnect()), e.cleanup(() => this.#e.set(!1));
6427
+ e.event(document, "visibilitychange", r), i.observe(t), e.cleanup(() => i.disconnect()), e.cleanup(() => this.#t.set(!1));
6396
6428
  }
6397
6429
  // Detect when video should be downloaded.
6398
- #a(e) {
6399
- const t = e.get(this.paused), s = e.get(this.#e);
6430
+ #i(e) {
6431
+ const t = e.get(this.paused), s = e.get(this.#t);
6400
6432
  if (e.cleanup(() => this.decoder.enabled.set(!1)), !t) {
6401
6433
  this.decoder.enabled.set(s);
6402
6434
  return;
6403
6435
  }
6404
- const r = e.get(this.decoder.frame);
6436
+ const r = e.get(this.frame);
6405
6437
  this.decoder.enabled.set(!r);
6406
6438
  }
6407
- #o(e) {
6408
- const t = e.get(this.#s);
6439
+ #a(e) {
6440
+ const t = e.get(this.#n);
6409
6441
  if (!t) return;
6410
- let s;
6411
- !e.get(this.paused) || !this.#n ? (s = e.get(this.decoder.frame), this.#n?.close(), this.#n = s?.clone()) : s = this.#n?.clone();
6442
+ const s = e.get(this.paused);
6443
+ let r;
6444
+ s || (r = e.get(this.decoder.frame));
6412
6445
  let i = requestAnimationFrame(() => {
6413
- this.#c(t, s), i = void 0;
6446
+ const a = r ?? this.frame.peek();
6447
+ this.#o(t, a), r && (this.frame.update((o) => (o?.close(), r.clone())), this.timestamp.set(p.Milli.fromMicro(r.timestamp))), i = void 0;
6414
6448
  });
6415
6449
  e.cleanup(() => {
6416
- s?.close(), i && cancelAnimationFrame(i);
6450
+ r?.close(), i && cancelAnimationFrame(i);
6417
6451
  });
6418
6452
  }
6419
- #c(e, t) {
6453
+ #o(e, t) {
6420
6454
  if (!t) {
6421
6455
  e.fillStyle = "#000", e.fillRect(0, 0, e.canvas.width, e.canvas.height);
6422
6456
  return;
@@ -6425,10 +6459,12 @@ class er {
6425
6459
  }
6426
6460
  // Close the track and all associated resources.
6427
6461
  close() {
6428
- this.#n?.close(), this.#n = void 0, this.#t.close();
6462
+ this.frame.update((e) => {
6463
+ e?.close();
6464
+ }), this.#e.close();
6429
6465
  }
6430
6466
  }
6431
- function nr(n) {
6467
+ function sr(n) {
6432
6468
  return (e) => {
6433
6469
  const t = [], s = [];
6434
6470
  for (const [r, i] of e)
@@ -6439,7 +6475,7 @@ function nr(n) {
6439
6475
  return t.sort((r, i) => i.size - r.size), t.length > 0 ? t.map((r) => r.name) : s.length > 0 ? (s.sort((r, i) => r.size - i.size), [s[0].name]) : e.map(([r]) => r);
6440
6476
  };
6441
6477
  }
6442
- function tr(n) {
6478
+ function rr(n) {
6443
6479
  return (e) => {
6444
6480
  const t = [], s = [];
6445
6481
  for (const [r, i] of e)
@@ -6447,7 +6483,7 @@ function tr(n) {
6447
6483
  return t.sort((r, i) => i.bitrate - r.bitrate), t.length > 0 ? t.map((r) => r.name) : s.length > 0 ? (s.sort((r, i) => r.bitrate - i.bitrate), [s[0].name]) : e.map(([r]) => r);
6448
6484
  };
6449
6485
  }
6450
- function sr(n) {
6486
+ function ir(n) {
6451
6487
  let e = n[0];
6452
6488
  for (const t of n) {
6453
6489
  const [, s] = t, [, r] = e, i = (s.codedWidth ?? 0) * (s.codedHeight ?? 0), a = (r.codedWidth ?? 0) * (r.codedHeight ?? 0);
@@ -6459,23 +6495,23 @@ function sr(n) {
6459
6495
  }
6460
6496
  return e[0];
6461
6497
  }
6462
- let rr = class {
6498
+ let ar = class {
6463
6499
  broadcast;
6464
6500
  target;
6465
6501
  #n = new h(void 0);
6466
6502
  catalog = this.#n;
6467
- #s = new h({});
6468
- available = this.#s;
6503
+ #t = new h({});
6504
+ available = this.#t;
6469
6505
  // The name of the active rendition.
6470
6506
  #e = new h(void 0);
6471
6507
  track = this.#e;
6472
- #t = new h(void 0);
6473
- config = this.#t;
6508
+ #r = new h(void 0);
6509
+ config = this.#r;
6474
6510
  sync;
6475
6511
  supported;
6476
- #r = new T();
6512
+ #s = new T();
6477
6513
  constructor(e, t) {
6478
- this.broadcast = h.from(t?.broadcast), this.target = h.from(t?.target), this.sync = e, this.supported = h.from(t?.supported), this.#r.run(this.#i.bind(this)), this.#r.run(this.#a.bind(this)), this.#r.run(this.#o.bind(this));
6514
+ this.broadcast = h.from(t?.broadcast), this.target = h.from(t?.target), this.sync = e, this.supported = h.from(t?.supported), this.#s.run(this.#i.bind(this)), this.#s.run(this.#a.bind(this)), this.#s.run(this.#o.bind(this));
6479
6515
  }
6480
6516
  #i(e) {
6481
6517
  const t = e.get(this.broadcast);
@@ -6491,16 +6527,33 @@ let rr = class {
6491
6527
  const r = {};
6492
6528
  for (const [i, a] of Object.entries(s))
6493
6529
  await t(a) && (r[i] = a);
6494
- Object.keys(r).length === 0 && Object.keys(s).length > 0 && console.warn("[Source] No supported video renditions found:", s), this.#s.set(r);
6530
+ Object.keys(r).length === 0 && Object.keys(s).length > 0 && console.warn("[Source] No supported video renditions found:", s), this.#t.set(r);
6495
6531
  });
6496
6532
  }
6497
6533
  #o(e) {
6498
- const t = e.get(this.#s);
6534
+ const t = e.get(this.#t);
6499
6535
  if (Object.keys(t).length === 0) return;
6500
- const s = e.get(this.target), r = s?.name, i = r && r in t ? r : this.#c(t, s);
6536
+ const s = e.get(this.target);
6537
+ if (s?.name && s.name in t) {
6538
+ const c = t[s.name];
6539
+ e.set(this.#e, s.name), e.set(this.#r, c), e.set(this.sync.video, c.jitter);
6540
+ return;
6541
+ }
6542
+ let r = s;
6543
+ if (!s?.bitrate) {
6544
+ const c = e.get(this.broadcast), d = (c ? e.get(c.connection) : void 0)?.recvBandwidth;
6545
+ if (d) {
6546
+ const l = e.get(d);
6547
+ if (l != null) {
6548
+ const f = Math.round(l * 0.8);
6549
+ r = { ...s, bitrate: f };
6550
+ }
6551
+ }
6552
+ }
6553
+ const i = this.#c(t, r);
6501
6554
  if (!i) return;
6502
6555
  const a = t[i];
6503
- e.set(this.#e, i), e.set(this.#t, a);
6556
+ e.set(this.#e, i), e.set(this.#r, a);
6504
6557
  const o = a.jitter ?? (a.framerate ? Math.ceil(1e3 / a.framerate) : void 0);
6505
6558
  e.set(this.sync.video, o);
6506
6559
  }
@@ -6516,8 +6569,8 @@ let rr = class {
6516
6569
  if (s.length === 0) return;
6517
6570
  if (s.length === 1) return s[0][0];
6518
6571
  const r = [];
6519
- if (t?.pixels != null && r.push(nr(t.pixels)), t?.bitrate != null && r.push(tr(t.bitrate)), r.length === 0)
6520
- return sr(s);
6572
+ if (t?.pixels != null && r.push(sr(t.pixels)), t?.bitrate != null && r.push(rr(t.bitrate)), r.length === 0)
6573
+ return ir(s);
6521
6574
  const i = r.map((o) => o(s)), a = i.map((o) => new Set(o));
6522
6575
  for (const o of i[0])
6523
6576
  if (a.every((c) => c.has(o)))
@@ -6525,10 +6578,10 @@ let rr = class {
6525
6578
  console.warn("conflicting rendition filters, no rendition satisfies all criteria");
6526
6579
  }
6527
6580
  close() {
6528
- this.#r.close();
6581
+ this.#s.close();
6529
6582
  }
6530
6583
  };
6531
- function Rn(n) {
6584
+ function En(n) {
6532
6585
  const e = [];
6533
6586
  for (let t = 0; t < n.length; t++) {
6534
6587
  const s = _.Time.Milli.fromSecond(n.start(t)), r = _.Time.Milli.fromSecond(n.end(t));
@@ -6536,7 +6589,7 @@ function Rn(n) {
6536
6589
  }
6537
6590
  return e;
6538
6591
  }
6539
- class ir {
6592
+ class or {
6540
6593
  // The source of the video.
6541
6594
  source;
6542
6595
  // The stats of the video.
@@ -6551,7 +6604,7 @@ class ir {
6551
6604
  this.source = e;
6552
6605
  }
6553
6606
  }
6554
- class ar {
6607
+ class cr {
6555
6608
  source;
6556
6609
  // The volume of the audio, between 0 and 1.
6557
6610
  volume = new h(0.5);
@@ -6565,44 +6618,45 @@ class ar {
6565
6618
  this.source = e;
6566
6619
  }
6567
6620
  }
6568
- class br {
6621
+ class Sr {
6569
6622
  element = new h(void 0);
6570
6623
  broadcast;
6624
+ latency;
6571
6625
  jitter;
6572
6626
  paused;
6573
6627
  video;
6574
6628
  #n;
6575
6629
  audio;
6576
- #s;
6630
+ #t;
6577
6631
  // Used to sync audio and video playback at a target delay.
6578
6632
  #e;
6579
6633
  signals = new T();
6580
6634
  constructor(e) {
6581
- this.element = h.from(e?.element), this.broadcast = h.from(e?.broadcast), this.jitter = h.from(e?.jitter ?? 100), this.#e = new Se({ jitter: this.jitter }), this.#n = new rr(this.#e, {
6635
+ this.element = h.from(e?.element), this.broadcast = h.from(e?.broadcast), this.#e = new Se({ latency: e?.latency, rtt: e?.rtt }), this.latency = this.#e.latency, this.jitter = this.#e.jitter, this.#n = new ar(this.#e, {
6582
6636
  broadcast: this.broadcast
6583
- }), this.#s = new ur(this.#e, {
6637
+ }), this.#t = new fr(this.#e, {
6584
6638
  broadcast: this.broadcast
6585
- }), this.video = new ir(this.#n), this.audio = new ar(this.#s), this.paused = h.from(e?.paused ?? !1), this.signals.run(this.#t.bind(this));
6639
+ }), this.video = new or(this.#n), this.audio = new cr(this.#t), this.paused = h.from(e?.paused ?? !1), this.signals.run(this.#r.bind(this));
6586
6640
  }
6587
- #t(e) {
6641
+ #r(e) {
6588
6642
  const t = e.get(this.element);
6589
- t && (t instanceof HTMLCanvasElement ? this.#r(e, t) : t instanceof HTMLVideoElement && this.#i(e, t));
6643
+ t && (t instanceof HTMLCanvasElement ? this.#s(e, t) : t instanceof HTMLVideoElement && this.#i(e, t));
6590
6644
  }
6591
- #r(e, t) {
6592
- const s = new Hs(this.#n), r = new Ls(this.#s), i = new Gs(r, {
6645
+ #s(e, t) {
6646
+ const s = new Ks(this.#n), r = new $s(this.#t), i = new Zs(r, {
6593
6647
  volume: this.audio.volume,
6594
6648
  muted: this.audio.muted,
6595
6649
  paused: this.paused
6596
- }), a = new er(s, { canvas: t, paused: this.paused });
6650
+ }), a = new tr(s, { canvas: t, paused: this.paused });
6597
6651
  e.cleanup(() => {
6598
6652
  s.close(), r.close(), i.close(), a.close();
6599
6653
  }), 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, r.stats), e.proxy(this.audio.buffered, r.buffered);
6600
6654
  }
6601
6655
  #i(e, t) {
6602
- const s = new In(this.#e, {
6656
+ const s = new Rn(this.#e, {
6603
6657
  paused: this.paused,
6604
6658
  element: t
6605
- }), r = new Js(s, this.#n), i = new or(s, this.#s, {
6659
+ }), r = new er(s, this.#n), i = new ur(s, this.#t, {
6606
6660
  volume: this.audio.volume,
6607
6661
  muted: this.audio.muted
6608
6662
  });
@@ -6614,20 +6668,20 @@ class br {
6614
6668
  this.signals.close();
6615
6669
  }
6616
6670
  }
6617
- class or {
6671
+ class ur {
6618
6672
  muxer;
6619
6673
  source;
6620
6674
  volume;
6621
6675
  muted;
6622
6676
  #n = new h(void 0);
6623
6677
  stats = this.#n;
6624
- #s = new h([]);
6625
- buffered = this.#s;
6678
+ #t = new h([]);
6679
+ buffered = this.#t;
6626
6680
  #e = new T();
6627
6681
  constructor(e, t, s) {
6628
- this.muxer = e, this.source = t, this.source.supported.set(cr), this.volume = h.from(s?.volume ?? 0.5), this.muted = h.from(s?.muted ?? !1), this.#e.run(this.#t.bind(this)), this.#e.run(this.#o.bind(this));
6682
+ this.muxer = e, this.source = t, this.source.supported.set(dr), this.volume = h.from(s?.volume ?? 0.5), this.muted = h.from(s?.muted ?? !1), this.#e.run(this.#r.bind(this)), this.#e.run(this.#o.bind(this));
6629
6683
  }
6630
- #t(e) {
6684
+ #r(e) {
6631
6685
  const t = e.get(this.muxer.element);
6632
6686
  if (!t) return;
6633
6687
  const s = e.get(this.muxer.mediaSource);
@@ -6646,12 +6700,12 @@ class or {
6646
6700
  }), e.event(u, "error", (l) => {
6647
6701
  console.error("[MSE] SourceBuffer error:", l);
6648
6702
  }), e.event(u, "updateend", () => {
6649
- this.#s.set(Rn(u.buffered));
6703
+ this.#t.set(En(u.buffered));
6650
6704
  });
6651
6705
  const d = i.subscribe(a, W.audio);
6652
6706
  e.cleanup(() => d.close()), o.container.kind === "cmaf" ? this.#i(e, d, o, u, t) : this.#a(e, d, o, u, t);
6653
6707
  }
6654
- async #r(e, t) {
6708
+ async #s(e, t) {
6655
6709
  for (; e.updating; )
6656
6710
  await new Promise((s) => e.addEventListener("updateend", s, { once: !0 }));
6657
6711
  for (e.appendBuffer(t); e.updating; )
@@ -6662,21 +6716,21 @@ class or {
6662
6716
  const a = s.container.timescale;
6663
6717
  e.spawn(async () => {
6664
6718
  const o = Ve(s);
6665
- for (await this.#r(r, o); ; ) {
6719
+ for (await this.#s(r, o); ; ) {
6666
6720
  const c = await t.readFrame();
6667
6721
  if (!c) return;
6668
- const u = gn(c, a);
6669
- this.source.sync.received(_.Time.Milli.fromMicro(u), "audio"), await this.#r(r, c), i.buffered.length > 0 && i.currentTime < i.buffered.start(0) && (i.currentTime = i.buffered.start(0));
6722
+ const u = yn(c, a);
6723
+ this.source.sync.received(_.Time.Milli.fromMicro(u), "audio"), await this.#s(r, c), i.buffered.length > 0 && i.currentTime < i.buffered.start(0) && (i.currentTime = i.buffered.start(0));
6670
6724
  }
6671
6725
  });
6672
6726
  }
6673
6727
  #a(e, t, s, r, i) {
6674
6728
  const a = new J(t, {
6675
- latency: this.source.sync.latency
6729
+ latency: this.source.sync.buffer
6676
6730
  });
6677
6731
  e.cleanup(() => a.close()), e.spawn(async () => {
6678
6732
  const o = Ve(s);
6679
- await this.#r(r, o);
6733
+ await this.#s(r, o);
6680
6734
  let c = 1, u, d;
6681
6735
  for (; ; ) {
6682
6736
  const l = await a.next();
@@ -6696,7 +6750,7 @@ class or {
6696
6750
  const b = _.Time.Milli.fromMicro(f.timestamp);
6697
6751
  this.source.sync.received(b, "audio");
6698
6752
  }
6699
- const p = An({
6753
+ const w = In({
6700
6754
  data: d.data,
6701
6755
  timestamp: d.timestamp,
6702
6756
  duration: u ?? 0,
@@ -6704,7 +6758,7 @@ class or {
6704
6758
  keyframe: d.keyframe,
6705
6759
  sequence: c++
6706
6760
  });
6707
- if (await this.#r(r, p), i.buffered.length > 0 && i.currentTime < i.buffered.start(0) && (i.currentTime = i.buffered.start(0)), !f) return;
6761
+ if (await this.#s(r, w), i.buffered.length > 0 && i.currentTime < i.buffered.start(0) && (i.currentTime = i.buffered.start(0)), !f) return;
6708
6762
  d = f;
6709
6763
  }
6710
6764
  });
@@ -6721,26 +6775,27 @@ class or {
6721
6775
  this.#e.close();
6722
6776
  }
6723
6777
  }
6724
- async function cr(n) {
6778
+ async function dr(n) {
6725
6779
  return MediaSource.isTypeSupported(`audio/mp4; codecs="${n.codec}"`);
6726
6780
  }
6727
- class ur {
6781
+ const lr = 128, hr = 10;
6782
+ class fr {
6728
6783
  broadcast;
6729
6784
  target;
6730
6785
  #n = new h(void 0);
6731
6786
  catalog = this.#n;
6732
- #s = new h({});
6733
- available = this.#s;
6787
+ #t = new h({});
6788
+ available = this.#t;
6734
6789
  #e = new h(void 0);
6735
6790
  track = this.#e;
6736
- #t = new h(void 0);
6737
- config = this.#t;
6791
+ #r = new h(void 0);
6792
+ config = this.#r;
6738
6793
  supported;
6739
6794
  // Used to target a latency and synchronize playback of video with audio.
6740
6795
  sync;
6741
- #r = new T();
6796
+ #s = new T();
6742
6797
  constructor(e, t) {
6743
- this.sync = e, this.broadcast = h.from(t?.broadcast), this.target = h.from(t?.target), this.supported = h.from(t?.supported), this.#r.run(this.#i.bind(this)), this.#r.run(this.#a.bind(this)), this.#r.run(this.#o.bind(this));
6798
+ this.sync = e, this.broadcast = h.from(t?.broadcast), this.target = h.from(t?.target), this.supported = h.from(t?.supported), this.#s.run(this.#i.bind(this)), this.#s.run(this.#a.bind(this)), this.#s.run(this.#o.bind(this));
6744
6799
  }
6745
6800
  #i(e) {
6746
6801
  const t = e.get(this.broadcast);
@@ -6754,20 +6809,20 @@ class ur {
6754
6809
  const r = {};
6755
6810
  for (const [i, a] of Object.entries(t))
6756
6811
  await s(a) && (r[i] = a);
6757
- Object.keys(r).length === 0 && Object.keys(t).length > 0 && console.warn("no supported audio renditions found:", t), this.#s.set(r);
6812
+ Object.keys(r).length === 0 && Object.keys(t).length > 0 && console.warn("no supported audio renditions found:", t), this.#t.set(r);
6758
6813
  });
6759
6814
  }
6760
6815
  #o(e) {
6761
- const t = e.get(this.#s);
6816
+ const t = e.get(this.#t);
6762
6817
  if (Object.keys(t).length === 0) return;
6763
6818
  const s = e.get(this.target);
6764
6819
  let r;
6765
6820
  if (s?.name && s.name in t)
6766
6821
  r = { track: s.name, config: t[s.name] };
6767
6822
  else if (r = this.#c(t), !r) return;
6768
- e.set(this.#e, r.track), e.set(this.#t, r.config);
6769
- const i = r.config.jitter ?? dr(r.config);
6770
- e.set(this.sync.audio, i);
6823
+ e.set(this.#e, r.track), e.set(this.#r, r.config);
6824
+ const i = r.config.jitter ?? mr(r.config) ?? 0, a = Math.ceil(lr / r.config.sampleRate * 1e3) + hr, o = i + a;
6825
+ e.set(this.sync.audio, o);
6771
6826
  }
6772
6827
  /**
6773
6828
  * Select rendition based on the configured strategy.
@@ -6784,16 +6839,16 @@ class ur {
6784
6839
  }
6785
6840
  }
6786
6841
  close() {
6787
- this.#r.close();
6842
+ this.#s.close();
6788
6843
  }
6789
6844
  }
6790
- function dr(n) {
6845
+ function mr(n) {
6791
6846
  if (n.codec.startsWith("opus"))
6792
6847
  return 20;
6793
6848
  if (n.codec.startsWith("mp4a"))
6794
6849
  return Math.ceil(1024 / n.sampleRate * 1e3);
6795
6850
  }
6796
- class gr {
6851
+ class kr {
6797
6852
  connection;
6798
6853
  enabled;
6799
6854
  name;
@@ -6801,21 +6856,21 @@ class gr {
6801
6856
  reload;
6802
6857
  #n = new h(void 0);
6803
6858
  active = this.#n;
6804
- #s = new h(void 0);
6805
- catalog = this.#s;
6859
+ #t = new h(void 0);
6860
+ catalog = this.#t;
6806
6861
  // All actively announced broadcast paths from the connection.
6807
6862
  #e;
6808
6863
  signals = new T();
6809
6864
  constructor(e) {
6810
- this.connection = h.from(e?.connection), this.name = h.from(e?.name ?? On.empty()), this.enabled = h.from(e?.enabled ?? !1), this.reload = h.from(e?.reload ?? !1), this.#e = e?.announced ?? new h(/* @__PURE__ */ new Set()), this.signals.run(this.#r.bind(this)), this.signals.run(this.#i.bind(this));
6865
+ this.connection = h.from(e?.connection), this.name = h.from(e?.name ?? zn.empty()), this.enabled = h.from(e?.enabled ?? !1), this.reload = h.from(e?.reload ?? !1), this.#e = e?.announced ?? new h(/* @__PURE__ */ new Set()), this.signals.run(this.#s.bind(this)), this.signals.run(this.#i.bind(this));
6811
6866
  }
6812
- #t(e) {
6867
+ #r(e) {
6813
6868
  if (!e.get(this.reload)) return !0;
6814
6869
  const s = e.get(this.name);
6815
6870
  return e.get(this.#e).has(s);
6816
6871
  }
6817
- #r(e) {
6818
- if (!e.get(this.enabled) || !this.#t(e)) return;
6872
+ #s(e) {
6873
+ if (!e.get(this.enabled) || !this.#r(e)) return;
6819
6874
  const s = e.get(this.connection);
6820
6875
  if (!s) return;
6821
6876
  const r = e.get(this.name), i = s.consume(r);
@@ -6830,14 +6885,14 @@ class gr {
6830
6885
  e.cleanup(() => i.close()), e.spawn(async () => {
6831
6886
  try {
6832
6887
  for (; ; ) {
6833
- const a = await Promise.race([e.cancel, Ht(i)]);
6888
+ const a = await Promise.race([e.cancel, Wt(i)]);
6834
6889
  if (!a) break;
6835
- console.debug("received catalog", this.name.peek(), a), this.#s.set(a), this.status.set("live");
6890
+ console.debug("received catalog", this.name.peek(), a), this.#t.set(a), this.status.set("live");
6836
6891
  }
6837
6892
  } catch (a) {
6838
6893
  console.warn("error fetching catalog", this.name.peek(), a);
6839
6894
  } finally {
6840
- this.#s.set(void 0), this.status.set("offline");
6895
+ this.#t.set(void 0), this.status.set("offline");
6841
6896
  }
6842
6897
  });
6843
6898
  }
@@ -6846,25 +6901,25 @@ class gr {
6846
6901
  }
6847
6902
  }
6848
6903
  export {
6849
- gr as B,
6850
- Hs as D,
6851
- Gs as E,
6852
- Js as M,
6904
+ kr as B,
6905
+ Ks as D,
6906
+ Zs as E,
6907
+ er as M,
6853
6908
  W as P,
6854
- er as R,
6855
- rr as S,
6909
+ tr as R,
6910
+ ar as S,
6856
6911
  m as a,
6857
- rn as b,
6858
- Ls as c,
6859
- or as d,
6860
- ur as e,
6861
- fr as f,
6862
- dn as g,
6863
- br as h,
6912
+ an as b,
6913
+ $s as c,
6914
+ ur as d,
6915
+ fr as e,
6916
+ vr as f,
6917
+ ln as g,
6918
+ Sr as h,
6864
6919
  Se as i,
6865
- pr as m,
6920
+ gr as m,
6866
6921
  S as o,
6867
6922
  y as s,
6868
- Rn as t
6923
+ En as t
6869
6924
  };
6870
- //# sourceMappingURL=broadcast-b-IDmAB3.js.map
6925
+ //# sourceMappingURL=broadcast-BdsV4u8m.js.map