@hadoku/watchparty-ui 0.45.84 → 0.45.85

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,7 +1,7 @@
1
1
  import { jsx as d, jsxs as k, Fragment as ye } from "react/jsx-runtime";
2
- import Ke, { useState as $, useRef as N, useEffect as F, useCallback as j, useMemo as Me, Component as vs, useContext as Zn, createContext as er, useId as Ss, useEffectEvent as ue } from "react";
3
- import { k as ws, M as Es, m as xs, f as Ms, a as ks, C as mt, g as rn, i as _s, S as As, b as Ts, r as _t, d as E, e as ee, u as x, c as Is, h as Cs, A as vt, j as Rs, l as st, n as tr, o as nr, D as dt, w as I, p as Fs, q as Ls, s as rr, t as sr, v as ar, x as Ns, L as $s, y as Ps, z as sn, B as Ds, E as Bs, F as Os, G as ir, H as an, I as or, J as cr, K as Hs, N as Us, O as Fe, P as Sn, T as Nt, Q as js, R as lr, U as Gs, V as Ws, W as Ks, X as dr, Y as Vs, Z as Y, _ as zs, $ as ur, a0 as fr, a1 as tt, a2 as Js, a3 as Qs, a4 as qs, a5 as Ys, a6 as Xs, a7 as wn, a8 as Qe, a9 as Zs, aa as En, ab as ea, ac as ta, ad as xn, ae as na, af as ra, ag as sa, ah as aa, ai as ia, aj as Mn, ak as kn, al as oa, am as hr, an as _n, ao as ca, ap as Et, aq as la, ar as da, as as ua, at as fa, au as ha, av as pa, aw as ma, ax as ga, ay as ba, az as ya, aA as va } from "./index-BhTEvojV.js";
4
- import { createPortal as Tt } from "react-dom";
2
+ import Ke, { useState as $, useRef as L, useEffect as F, useCallback as j, useMemo as Me, Component as vs, useContext as Zn, createContext as er, useId as Ss, useEffectEvent as ue } from "react";
3
+ import { k as ws, M as Es, m as xs, f as Ms, a as ks, C as mt, g as rn, i as _s, S as As, b as Ts, r as At, d as E, e as ee, u as x, c as Is, h as Cs, A as vt, j as Rs, l as st, n as tr, o as nr, D as dt, w as I, p as Fs, q as Ns, s as rr, t as sr, v as ar, x as Ls, L as $s, y as Ps, z as sn, B as Ds, E as Bs, F as Os, G as ir, H as an, I as or, J as cr, K as Hs, N as Us, O as Fe, P as Sn, T as Lt, Q as js, R as lr, U as Gs, V as Ws, W as Ks, X as dr, Y as Vs, Z as Y, _ as zs, $ as ur, a0 as fr, a1 as tt, a2 as Js, a3 as Qs, a4 as qs, a5 as Ys, a6 as Xs, a7 as wn, a8 as Qe, a9 as Zs, aa as En, ab as ea, ac as ta, ad as xn, ae as na, af as ra, ag as sa, ah as aa, ai as ia, aj as Mn, ak as kn, al as oa, am as hr, an as _n, ao as ca, ap as xt, aq as la, ar as da, as as ua, at as fa, au as ha, av as pa, aw as ma, ax as ga, ay as ba, az as ya, aA as va } from "./index-DEctw6gT.js";
4
+ import { createPortal as It } from "react-dom";
5
5
  import { Icon as gt, THEMES as Sa, useHadokuThemeOptional as wa } from "@wolffm/themes";
6
6
  import { HadokuThemePicker as Ea, ConnectedSettings as xa } from "@wolffm/task-ui-components";
7
7
  import { createRoot as Ma } from "react-dom/client";
@@ -13,7 +13,7 @@ class pr extends Error {
13
13
  super(e), this.name = "ChatImageUploadError";
14
14
  }
15
15
  }
16
- function kt(t) {
16
+ function _t(t) {
17
17
  switch (t) {
18
18
  case "unauthenticated":
19
19
  return "Sign in to paste images";
@@ -34,11 +34,11 @@ function kt(t) {
34
34
  }
35
35
  }
36
36
  function _a(t) {
37
- return t instanceof mt ? kt(t.reason) : t instanceof pr ? t.message : "Image upload failed";
37
+ return t instanceof mt ? _t(t.reason) : t instanceof pr ? t.message : "Image upload failed";
38
38
  }
39
39
  function Aa(t) {
40
40
  const e = t.type.toLowerCase().split(";")[0].trim();
41
- return e && ws(e) !== "image" ? kt("unsupported-type") : t.size > Es.image ? kt("too-large") : t.size === 0 ? kt("invalid") : null;
41
+ return e && ws(e) !== "image" ? _t("unsupported-type") : t.size > Es.image ? _t("too-large") : t.size === 0 ? _t("invalid") : null;
42
42
  }
43
43
  function Ta(t) {
44
44
  return Ms(t);
@@ -68,7 +68,7 @@ async function Fa(t, e = {}) {
68
68
  }
69
69
  return n;
70
70
  }
71
- function La(t) {
71
+ function Na(t) {
72
72
  return {
73
73
  error: t instanceof Error ? t.message : String(t),
74
74
  name: t instanceof Error ? t.name : typeof t,
@@ -76,14 +76,14 @@ function La(t) {
76
76
  status: t instanceof mt ? t.status : void 0
77
77
  };
78
78
  }
79
- function Na(t) {
80
- const e = N(t);
79
+ function La(t) {
80
+ const e = L(t);
81
81
  return F(() => {
82
82
  e.current = t;
83
83
  }), [e, `${t.cdnBase}|${t.uploadPath}`];
84
84
  }
85
85
  function $a(t, e, n, r = {}) {
86
- const { limit: s, debounceMs: i = As } = r, [a, c] = Na(t), [l, o] = $([]), [u, f] = $(null), [h, g] = $(!1), [b, p] = $(null), [v, S] = $(0), A = N(null);
86
+ const { limit: s, debounceMs: i = As } = r, [a, l] = La(t), [o, c] = $([]), [u, f] = $(null), [p, g] = $(!1), [b, h] = $(null), [v, S] = $(0), A = L(null);
87
87
  F(() => {
88
88
  S(0), f(null);
89
89
  }, [n, e]), F(() => {
@@ -91,7 +91,7 @@ function $a(t, e, n, r = {}) {
91
91
  const m = v === 0, T = async () => {
92
92
  A.current?.abort();
93
93
  const y = new AbortController();
94
- A.current = y, g(!0), p(null);
94
+ A.current = y, g(!0), h(null);
95
95
  try {
96
96
  const w = await a.current.catalogue(e).search({
97
97
  query: n,
@@ -100,14 +100,14 @@ function $a(t, e, n, r = {}) {
100
100
  signal: y.signal
101
101
  });
102
102
  if (_) return;
103
- o((C) => m ? w.results : [...C, ...w.results]), f(w.next);
103
+ c((C) => m ? w.results : [...C, ...w.results]), f(w.next);
104
104
  } catch (w) {
105
105
  if (_ || w instanceof Error && w.name === "AbortError") return;
106
- p(w instanceof mt ? w : new mt("unknown", String(w)));
106
+ h(w instanceof mt ? w : new mt("unknown", String(w)));
107
107
  } finally {
108
108
  _ || g(!1);
109
109
  }
110
- }, L = setTimeout(
110
+ }, N = setTimeout(
111
111
  // A block body, not `() => void run()`: `no-void` is configured with
112
112
  // allowAsStatement, so the discard is fine as a statement and an
113
113
  // error as an expression body.
@@ -119,13 +119,13 @@ function $a(t, e, n, r = {}) {
119
119
  m ? i : 0
120
120
  );
121
121
  return () => {
122
- _ = !0, clearTimeout(L);
122
+ _ = !0, clearTimeout(N);
123
123
  };
124
- }, [a, c, e, n, s, i, v]);
124
+ }, [a, l, e, n, s, i, v]);
125
125
  const R = j(() => {
126
- h || !u || S((_) => _ + 1);
127
- }, [h, u]);
128
- return { items: l, loading: h, error: b, hasMore: u !== null, loadMore: R };
126
+ p || !u || S((_) => _ + 1);
127
+ }, [p, u]);
128
+ return { items: o, loading: p, error: b, hasMore: u !== null, loadMore: R };
129
129
  }
130
130
  function Ve(t) {
131
131
  return t.key === "Escape" || t.key === "GoBack" || t.key === "BrowserBack" || t.key === "XF86Back" || t.keyCode === 461 || t.keyCode === 10009;
@@ -190,14 +190,14 @@ function Ua(t, e, n) {
190
190
  }
191
191
  const Sr = "/dataplatform/api/memes", ja = 120;
192
192
  function Ga({ onClose: t, onPick: e, onUnavailable: n }) {
193
- const [r, s] = $(""), i = N(null), a = N(null), c = rn(), { items: l, loading: o, error: u, hasMore: f, loadMore: h } = $a(
194
- c,
193
+ const [r, s] = $(""), i = L(null), a = L(null), l = rn(), { items: o, loading: c, error: u, hasMore: f, loadMore: p } = $a(
194
+ l,
195
195
  Sr,
196
196
  r.trim()
197
197
  ), g = u?.reason ?? null, b = Me(() => {
198
198
  const y = /* @__PURE__ */ new Set();
199
- return l.filter((w) => y.has(w.key) ? !1 : (y.add(w.key), !0));
200
- }, [l]), [p, v] = $(null), S = N(null), A = j(() => {
199
+ return o.filter((w) => y.has(w.key) ? !1 : (y.add(w.key), !0));
200
+ }, [o]), [h, v] = $(null), S = L(null), A = j(() => {
201
201
  S.current !== null && (window.clearTimeout(S.current), S.current = null);
202
202
  }, []), R = j(() => {
203
203
  A(), v(null);
@@ -232,7 +232,7 @@ function Ga({ onClose: t, onPick: e, onUnavailable: n }) {
232
232
  }, [t]);
233
233
  const T = j((y) => {
234
234
  e(y), t();
235
- }, [e, t]), L = !o && !u && b.length === 0;
235
+ }, [e, t]), N = !c && !u && b.length === 0;
236
236
  return /* @__PURE__ */ k(
237
237
  "div",
238
238
  {
@@ -274,9 +274,9 @@ function Ga({ onClose: t, onPick: e, onUnavailable: n }) {
274
274
  ] }) : g === "forbidden" ? "Your account can't browse the meme library" : "Meme library is unavailable"
275
275
  }
276
276
  ),
277
- L && /* @__PURE__ */ d("p", { className: "p-4 text-center text-sm text-text-secondary", children: r.trim() ? `No memes match "${r.trim()}"` : "The meme library is empty" }),
277
+ N && /* @__PURE__ */ d("p", { className: "p-4 text-center text-sm text-text-secondary", children: r.trim() ? `No memes match "${r.trim()}"` : "The meme library is empty" }),
278
278
  b.length > 0 && /* @__PURE__ */ d("div", { className: "grid grid-cols-3 gap-1.5 sm:grid-cols-4", children: b.map((y) => {
279
- const w = _t(y.key);
279
+ const w = At(y.key);
280
280
  return w ? /* @__PURE__ */ d(
281
281
  "button",
282
282
  {
@@ -305,12 +305,12 @@ function Ga({ onClose: t, onPick: e, onUnavailable: n }) {
305
305
  y.key
306
306
  ) : null;
307
307
  }) }),
308
- o && /* @__PURE__ */ d("p", { className: "p-2 text-center text-xs text-text-secondary", children: "Loading…" }),
309
- f && !o && /* @__PURE__ */ d(
308
+ c && /* @__PURE__ */ d("p", { className: "p-2 text-center text-xs text-text-secondary", children: "Loading…" }),
309
+ f && !c && /* @__PURE__ */ d(
310
310
  "button",
311
311
  {
312
312
  type: "button",
313
- onClick: h,
313
+ onClick: p,
314
314
  "data-testid": "meme-load-more",
315
315
  className: "mt-2 w-full rounded border border-border-light py-1 text-xs text-text-secondary hover:text-text hover:border-primary",
316
316
  children: "Load more"
@@ -319,14 +319,14 @@ function Ga({ onClose: t, onPick: e, onUnavailable: n }) {
319
319
  ]
320
320
  }
321
321
  ),
322
- p && /* @__PURE__ */ k(
322
+ h && /* @__PURE__ */ k(
323
323
  "div",
324
324
  {
325
325
  "data-testid": "meme-preview",
326
326
  className: "fixed z-50 flex flex-col gap-1 rounded border border-border-light bg-bg-card p-1.5 shadow-2xl",
327
327
  style: {
328
- left: p.left,
329
- top: p.top,
328
+ left: h.left,
329
+ top: h.top,
330
330
  width: qt,
331
331
  /* The placement maths reserves exactly PREVIEW_PX of width.
332
332
  Without border-box the padding and border sit OUTSIDE that
@@ -341,15 +341,15 @@ function Ga({ onClose: t, onPick: e, onUnavailable: n }) {
341
341
  /* @__PURE__ */ d(
342
342
  "img",
343
343
  {
344
- src: _t(p.item.key) ?? void 0,
344
+ src: At(h.item.key) ?? void 0,
345
345
  alt: "",
346
346
  className: "block w-full rounded bg-bg object-contain",
347
347
  style: { height: "auto", maxHeight: vr }
348
348
  }
349
349
  ),
350
- p.item.title && /* One line. A long title must not change the box height, because
350
+ h.item.title && /* One line. A long title must not change the box height, because
351
351
  the box height is what the placement maths clamped against. */
352
- /* @__PURE__ */ d("span", { className: "overflow-hidden text-ellipsis whitespace-nowrap text-center text-[10px] text-text-secondary", children: p.item.title })
352
+ /* @__PURE__ */ d("span", { className: "overflow-hidden text-ellipsis whitespace-nowrap text-center text-[10px] text-text-secondary", children: h.item.title })
353
353
  ]
354
354
  }
355
355
  )
@@ -394,58 +394,58 @@ function Ja(t, e) {
394
394
  const qe = (t) => t instanceof Error ? t.message : String(t);
395
395
  function Qa(t) {
396
396
  let e = t.ctx, n = null, r = !1, s = !1;
397
- const i = /* @__PURE__ */ new Set(), a = (h, g) => t.onSettingsError?.(h, g), c = (h) => {
398
- if (i.delete(h))
397
+ const i = /* @__PURE__ */ new Set(), a = (p, g) => t.onSettingsError?.(p, g), l = (p) => {
398
+ if (i.delete(p))
399
399
  try {
400
- h.cleanup();
400
+ p.cleanup();
401
401
  } catch (g) {
402
402
  a(`the game's settings failed to close: ${qe(g)}`, g);
403
403
  }
404
- }, l = (h) => {
404
+ }, o = (p) => {
405
405
  for (const g of [...i])
406
- c(g);
407
- h.mountSettings && t.onSettingsAvailable?.(!1);
408
- }, o = (h) => {
409
- l(h);
406
+ l(g);
407
+ p.mountSettings && t.onSettingsAvailable?.(!1);
408
+ }, c = (p) => {
409
+ o(p);
410
410
  try {
411
- h.unmount();
411
+ p.unmount();
412
412
  } catch (g) {
413
413
  s || t.onError(`unmount threw: ${qe(g)}`, g);
414
414
  }
415
- }, u = (h, g) => {
415
+ }, u = (p, g) => {
416
416
  if (s || r)
417
417
  return;
418
418
  s = !0;
419
419
  const b = n;
420
- n = null, b && o(b), t.onError(h, g);
421
- }, f = (h) => {
422
- if (e = h, !(!n || r))
420
+ n = null, b && c(b), t.onError(p, g);
421
+ }, f = (p) => {
422
+ if (e = p, !(!n || r))
423
423
  try {
424
- n.update(h);
424
+ n.update(p);
425
425
  } catch (g) {
426
426
  u(`the game failed to update: ${qe(g)}`, g);
427
427
  }
428
428
  };
429
429
  return (async () => {
430
- let h;
430
+ let p;
431
431
  try {
432
- h = await t.load();
433
- } catch (p) {
434
- u(`could not load the game: ${qe(p)}`, p);
432
+ p = await t.load();
433
+ } catch (h) {
434
+ u(`could not load the game: ${qe(h)}`, h);
435
435
  return;
436
436
  }
437
437
  if (r)
438
438
  return;
439
- if (!Wa(h)) {
439
+ if (!Wa(p)) {
440
440
  u("the game module does not export mount()");
441
441
  return;
442
442
  }
443
443
  const g = e;
444
444
  let b;
445
445
  try {
446
- b = await h.mount(t.el, g);
447
- } catch (p) {
448
- u(`the game failed to start: ${qe(p)}`, p);
446
+ b = await p.mount(t.el, g);
447
+ } catch (h) {
448
+ u(`the game failed to start: ${qe(h)}`, h);
449
449
  return;
450
450
  }
451
451
  if (!Ka(b)) {
@@ -453,29 +453,29 @@ function Qa(t) {
453
453
  return;
454
454
  }
455
455
  if (r) {
456
- o(b);
456
+ c(b);
457
457
  return;
458
458
  }
459
459
  n = b, b.mountSettings && t.onSettingsAvailable?.(!0), e !== g && f(e);
460
460
  })(), {
461
461
  update: f,
462
462
  dispose() {
463
- r || (r = !0, n && o(n), n = null);
463
+ r || (r = !0, n && c(n), n = null);
464
464
  },
465
- mountSettings(h) {
465
+ mountSettings(p) {
466
466
  const g = n;
467
467
  if (!g?.mountSettings || r)
468
468
  return null;
469
469
  let b;
470
470
  try {
471
- b = g.mountSettings(h);
471
+ b = g.mountSettings(p);
472
472
  } catch (v) {
473
473
  return a(`the game's settings failed to open: ${qe(v)}`, v), null;
474
474
  }
475
475
  if (typeof b != "function")
476
476
  return a("the game's mountSettings() did not return a cleanup function"), null;
477
- const p = { cleanup: b };
478
- return i.add(p), () => c(p);
477
+ const h = { cleanup: b };
478
+ return i.add(h), () => l(h);
479
479
  }
480
480
  };
481
481
  }
@@ -505,7 +505,7 @@ class xr extends vs {
505
505
  ] }) : this.props.children;
506
506
  }
507
507
  }
508
- function It() {
508
+ function St() {
509
509
  const [t, e] = $(
510
510
  () => typeof document < "u" && !!document.fullscreenElement
511
511
  );
@@ -612,7 +612,7 @@ function si({ src: t, title: e, onClose: n }) {
612
612
  return document.addEventListener("keydown", i, !0), () => document.removeEventListener("keydown", i, !0);
613
613
  }, [n]);
614
614
  const r = ri(), s = typeof document > "u" ? null : document.fullscreenElement ?? r ?? document.body;
615
- return s ? Tt(
615
+ return s ? It(
616
616
  /* @__PURE__ */ k(
617
617
  "div",
618
618
  {
@@ -652,7 +652,7 @@ function si({ src: t, title: e, onClose: n }) {
652
652
  }
653
653
  const $t = 240, ai = 320;
654
654
  function ii({ image: t }) {
655
- const [e, n] = $(!1), r = _t(t.key);
655
+ const [e, n] = $(!1), r = At(t.key);
656
656
  if (!r) return null;
657
657
  const s = t.w > 0 && t.h > 0, i = s ? Math.min(1, ai / t.w, $t / t.h) : 1;
658
658
  return /* @__PURE__ */ k(ye, { children: [
@@ -705,10 +705,10 @@ const ci = Ke.memo(function({ message: e }) {
705
705
  const n = x((u) => u.me.clientId), r = x((u) => u.me.clientId ? u.roster[u.me.clientId]?.author : void 0), s = oi(e, { clientId: n, author: r }), i = _r(
706
706
  { clientId: e.clientId, author: e.author },
707
707
  { name: e.name, sprite: e.sprite }
708
- ), a = st(i.sprite, i.pictureUrl), c = e.isSystem ? void 0 : i.cosmetics, l = N(null);
709
- ei(l, !!c);
710
- const [o] = $(
711
- () => e.live && e.text ? tr(e.text, c) : null
708
+ ), a = st(i.sprite, i.pictureUrl), l = e.isSystem ? void 0 : i.cosmetics, o = L(null);
709
+ ei(o, !!l);
710
+ const [c] = $(
711
+ () => e.live && e.text ? tr(e.text, l) : null
712
712
  );
713
713
  return e.isSystem && e.systemType === "recap" ? /* @__PURE__ */ d("div", { className: "px-2 py-1.5", children: /* @__PURE__ */ k("div", { className: "border-l-2 border-border-light pl-2.5 py-0.5", children: [
714
714
  /* @__PURE__ */ k("div", { className: "text-[10px] uppercase tracking-wide text-text-muted mb-0.5", children: [
@@ -719,23 +719,23 @@ const ci = Ke.memo(function({ message: e }) {
719
719
  ] }) }) : e.isSystem ? /* @__PURE__ */ k("div", { className: "px-2 py-0.5 text-[11px] text-text-muted italic text-center leading-tight", children: [
720
720
  Xa(e.text, e.template, i),
721
721
  /* @__PURE__ */ d("span", { className: "ml-1 text-[10px] opacity-50", children: Pt(e.ts) })
722
- ] }) : /* @__PURE__ */ k("div", { ref: l, style: Tr(a), className: `flex items-start gap-2 px-2 py-1 hover:bg-bg-card/20 ${s ? "bg-bg-card/30" : ""}`, children: [
723
- /* @__PURE__ */ d(Ir, { sprite: i.sprite, url: i.pictureUrl, alt: i.name, worn: c }),
722
+ ] }) : /* @__PURE__ */ k("div", { ref: o, style: Tr(a), className: `flex items-start gap-2 px-2 py-1 hover:bg-bg-card/20 ${s ? "bg-bg-card/30" : ""}`, children: [
723
+ /* @__PURE__ */ d(Ir, { sprite: i.sprite, url: i.pictureUrl, alt: i.name, worn: l }),
724
724
  /* @__PURE__ */ k("div", { className: "flex-1 min-w-0 -mt-0.5", children: [
725
- c ? /* @__PURE__ */ d(bt, { html: nr(i.name, c), className: "text-[13px]", style: { color: a } }) : /* @__PURE__ */ d("span", { className: "font-medium text-[13px]", style: { color: a }, children: i.name }),
725
+ l ? /* @__PURE__ */ d(bt, { html: nr(i.name, l), className: "text-[13px]", style: { color: a } }) : /* @__PURE__ */ d("span", { className: "font-medium text-[13px]", style: { color: a }, children: i.name }),
726
726
  /* @__PURE__ */ d("span", { className: "text-[10px] text-text-muted opacity-60 ml-1.5", children: Pt(e.ts) }),
727
- e.text && (o ? /* @__PURE__ */ d(bt, { as: "p", html: o, className: "text-[13px] text-text break-words leading-snug m-0" }) : /* @__PURE__ */ d("p", { className: "text-[13px] text-text break-words leading-snug m-0", children: e.text })),
727
+ e.text && (c ? /* @__PURE__ */ d(bt, { as: "p", html: c, className: "text-[13px] text-text break-words leading-snug m-0" }) : /* @__PURE__ */ d("p", { className: "text-[13px] text-text break-words leading-snug m-0", children: e.text })),
728
728
  /* @__PURE__ */ d(Cr, { images: e.images })
729
729
  ] })
730
730
  ] });
731
731
  });
732
732
  function li() {
733
733
  Ar();
734
- const t = x((s) => s.chat), e = N(null), n = N(!1), r = j(() => {
734
+ const t = x((s) => s.chat), e = L(null), n = L(!1), r = j(() => {
735
735
  const s = e.current;
736
736
  if (!s) return;
737
- const { scrollHeight: i, scrollTop: a, clientHeight: c } = s, l = i - a - c;
738
- n.current = l > 40;
737
+ const { scrollHeight: i, scrollTop: a, clientHeight: l } = s, o = i - a - l;
738
+ n.current = o > 40;
739
739
  }, []);
740
740
  return F(() => {
741
741
  const s = e.current;
@@ -747,9 +747,9 @@ function li() {
747
747
  onScroll: r,
748
748
  className: "flex-1 overflow-y-auto overflow-x-hidden chat-messages",
749
749
  children: t.length === 0 ? /* @__PURE__ */ d("div", { className: "p-4 text-xs text-text-muted text-center", children: "No messages yet. Be the first to say something!" }) : /* @__PURE__ */ d(ye, { children: t.map((s, i) => {
750
- const a = i > 0 ? t[i - 1] : null, c = a && s.ts - a.ts > 1440 * 60 * 1e3;
750
+ const a = i > 0 ? t[i - 1] : null, l = a && s.ts - a.ts > 1440 * 60 * 1e3;
751
751
  return /* @__PURE__ */ k(Ke.Fragment, { children: [
752
- c && /* @__PURE__ */ k("div", { className: "flex items-center gap-2 px-4 py-2 my-1", children: [
752
+ l && /* @__PURE__ */ k("div", { className: "flex items-center gap-2 px-4 py-2 my-1", children: [
753
753
  /* @__PURE__ */ d("div", { className: "flex-1 h-px bg-border" }),
754
754
  /* @__PURE__ */ d("span", { className: "text-[10px] text-text-muted whitespace-nowrap", children: new Date(s.ts).toLocaleDateString([], { weekday: "short", month: "short", day: "numeric" }) }),
755
755
  /* @__PURE__ */ d("div", { className: "flex-1 h-px bg-border" })
@@ -806,8 +806,8 @@ function hi(t, e = cn) {
806
806
  const n = t.trim();
807
807
  if (!n) return null;
808
808
  if (!n.startsWith(rt)) return { kind: "chat", text: n };
809
- const r = n.slice(rt.length), s = r.search(/\s/), i = (s === -1 ? r : r.slice(0, s)).toLowerCase(), a = s === -1 ? "" : r.slice(s).trim(), c = e.find((l) => l.name.toLowerCase() === i);
810
- return c ? { kind: "command", command: c, args: a } : { kind: "chat", text: n };
809
+ const r = n.slice(rt.length), s = r.search(/\s/), i = (s === -1 ? r : r.slice(0, s)).toLowerCase(), a = s === -1 ? "" : r.slice(s).trim(), l = e.find((o) => o.name.toLowerCase() === i);
810
+ return l ? { kind: "command", command: l, args: a } : { kind: "chat", text: n };
811
811
  }
812
812
  function pi(t, e) {
813
813
  return t.requiresMedia && !e.hasMedia ? `${rt}${t.name} needs an episode loaded.` : null;
@@ -829,23 +829,23 @@ function mi({
829
829
  className: `absolute bottom-full left-0 right-0 z-30 max-h-56 overflow-y-auto
830
830
  bg-bg-card border border-border-light rounded shadow-lg
831
831
  list-none m-0 p-0 py-1 mb-1`,
832
- children: t.map((a, c) => {
833
- const l = !!a.requiresMedia && !n, o = c === e;
832
+ children: t.map((a, l) => {
833
+ const o = !!a.requiresMedia && !n, c = l === e;
834
834
  return /* @__PURE__ */ k(
835
835
  "li",
836
836
  {
837
837
  id: `${i}-opt-${a.name}`,
838
838
  role: "option",
839
- "aria-selected": o,
840
- "aria-disabled": l,
839
+ "aria-selected": c,
840
+ "aria-disabled": o,
841
841
  onMouseDown: (u) => {
842
842
  u.preventDefault(), r(a);
843
843
  },
844
- onMouseEnter: () => s(c),
845
- className: `px-3 py-1.5 cursor-pointer flex items-baseline gap-2 ${o ? "bg-bg-alt" : ""} ${l ? "opacity-50" : ""}`,
844
+ onMouseEnter: () => s(l),
845
+ className: `px-3 py-1.5 cursor-pointer flex items-baseline gap-2 ${c ? "bg-bg-alt" : ""} ${o ? "opacity-50" : ""}`,
846
846
  children: [
847
847
  /* @__PURE__ */ d("span", { className: "text-sm font-semibold text-text shrink-0", children: a.usage }),
848
- /* @__PURE__ */ d("span", { className: "text-xs text-text-secondary truncate", children: l ? "needs an episode loaded" : a.description })
848
+ /* @__PURE__ */ d("span", { className: "text-xs text-text-secondary truncate", children: o ? "needs an episode loaded" : a.description })
849
849
  ]
850
850
  },
851
851
  a.name
@@ -882,17 +882,17 @@ function Rr({
882
882
  ] }, r.id)) }) : null;
883
883
  }
884
884
  function Fr() {
885
- const [t, e] = $([]), [n, r] = $(!1), s = x((p) => p.pushToast), i = N(/* @__PURE__ */ new Set());
885
+ const [t, e] = $([]), [n, r] = $(!1), s = x((h) => h.pushToast), i = L(/* @__PURE__ */ new Set());
886
886
  F(() => () => {
887
- for (const p of i.current) URL.revokeObjectURL(p);
887
+ for (const h of i.current) URL.revokeObjectURL(h);
888
888
  i.current.clear();
889
889
  }, []);
890
- const a = j((p) => {
891
- ka(p) && (URL.revokeObjectURL(p.previewUrl), i.current.delete(p.previewUrl));
892
- }, []), c = j(async (p) => {
893
- if (!p.length) return;
890
+ const a = j((h) => {
891
+ ka(h) && (URL.revokeObjectURL(h.previewUrl), i.current.delete(h.previewUrl));
892
+ }, []), l = j(async (h) => {
893
+ if (!h.length) return;
894
894
  const v = [];
895
- for (const S of p) {
895
+ for (const S of h) {
896
896
  const A = Aa(S);
897
897
  if (A) {
898
898
  s("error", A);
@@ -921,44 +921,44 @@ function Fr() {
921
921
  }
922
922
  return [...S, ...v.slice(0, A)];
923
923
  });
924
- }, [s, a]), l = j((p) => {
925
- const v = _t(p.key);
924
+ }, [s, a]), o = j((h) => {
925
+ const v = At(h.key);
926
926
  v && (e((S) => S.length >= dt ? (s("info", `Up to ${dt} images per message`), S) : [...S, {
927
927
  kind: "remote",
928
928
  id: `${Date.now()}-${Math.random().toString(36).slice(2, 8)}`,
929
- key: p.key,
929
+ key: h.key,
930
930
  previewUrl: v,
931
931
  // The catalogue spells "unknown" as null; the wire schema spells it
932
932
  // as 0, and the renderer falls back to natural flow on that.
933
- w: p.width ?? 0,
934
- h: p.height ?? 0,
935
- title: p.title || void 0
936
- }]), rn().catalogue(Sr).recordUse(p.key));
937
- }, [s]), o = j((p) => {
933
+ w: h.width ?? 0,
934
+ h: h.height ?? 0,
935
+ title: h.title || void 0
936
+ }]), rn().catalogue(Sr).recordUse(h.key));
937
+ }, [s]), c = j((h) => {
938
938
  e((v) => {
939
- const S = v.find((A) => A.id === p);
940
- return S && a(S), v.filter((A) => A.id !== p);
939
+ const S = v.find((A) => A.id === h);
940
+ return S && a(S), v.filter((A) => A.id !== h);
941
941
  });
942
942
  }, [a]), u = j(() => {
943
- e((p) => {
944
- for (const v of p) a(v);
943
+ e((h) => {
944
+ for (const v of h) a(v);
945
945
  return [];
946
946
  });
947
- }, [a]), f = j((p) => {
948
- const v = Ta(p.clipboardData);
949
- v.length && (p.preventDefault(), c(v));
950
- }, [c]), h = j((p) => {
951
- const v = Ia(p.dataTransfer);
952
- v.length && (p.preventDefault(), c(v));
953
- }, [c]), g = j((p) => {
954
- p.dataTransfer?.types?.includes("Files") && p.preventDefault();
947
+ }, [a]), f = j((h) => {
948
+ const v = Ta(h.clipboardData);
949
+ v.length && (h.preventDefault(), l(v));
950
+ }, [l]), p = j((h) => {
951
+ const v = Ia(h.dataTransfer);
952
+ v.length && (h.preventDefault(), l(v));
953
+ }, [l]), g = j((h) => {
954
+ h.dataTransfer?.types?.includes("Files") && h.preventDefault();
955
955
  }, []), b = j(async () => {
956
956
  if (!t.length) return [];
957
957
  r(!0);
958
958
  try {
959
959
  return await Fa(t);
960
- } catch (p) {
961
- return I("chat", "Image upload failed", La(p)), s("error", _a(p)), null;
960
+ } catch (h) {
961
+ return I("chat", "Image upload failed", Na(h)), s("error", _a(h)), null;
962
962
  } finally {
963
963
  r(!1);
964
964
  }
@@ -966,22 +966,22 @@ function Fr() {
966
966
  return {
967
967
  pending: t,
968
968
  uploading: n,
969
- addFiles: c,
970
- addMeme: l,
971
- remove: o,
969
+ addFiles: l,
970
+ addMeme: o,
971
+ remove: c,
972
972
  clear: u,
973
973
  uploadPending: b,
974
974
  onPaste: f,
975
- onDrop: h,
975
+ onDrop: p,
976
976
  onDragOver: g
977
977
  };
978
978
  }
979
979
  const An = ar, gi = sr;
980
980
  function bi({ commands: t = cn }) {
981
- const [e, n] = $(""), [r, s] = $(!1), [i, a] = $({ q: null, i: 0 }), [c, l] = $(!1), o = N(null), u = Ss(), [f, h] = $(!1), [g, b] = $(!1), p = Fr(), v = x((D) => D.snapshot.mediaId), S = x((D) => D.pushToast), A = x((D) => D.setTierlistOpen), R = !!v, _ = di(e), m = Me(
981
+ const [e, n] = $(""), [r, s] = $(!1), [i, a] = $({ q: null, i: 0 }), [l, o] = $(!1), c = L(null), u = Ss(), [f, p] = $(!1), [g, b] = $(!1), h = Fr(), v = x((D) => D.snapshot.mediaId), S = x((D) => D.pushToast), A = x((D) => D.setTierlistOpen), R = !!v, _ = di(e), m = Me(
982
982
  () => _ === null ? [] : ui(_, t),
983
983
  [_, t]
984
- ), T = _ !== null && !c && m.length > 0, L = i.q === _ ? Dt(i.i, m.length) : 0, y = j(
984
+ ), T = _ !== null && !l && m.length > 0, N = i.q === _ ? Dt(i.i, m.length) : 0, y = j(
985
985
  (D) => a({ q: _, i: D }),
986
986
  [_]
987
987
  ), w = j((D, W) => {
@@ -995,7 +995,7 @@ function bi({ commands: t = cn }) {
995
995
  S("info", t.map((U) => U.usage).join(" "));
996
996
  break;
997
997
  case "recap":
998
- Ls();
998
+ Ns();
999
999
  break;
1000
1000
  case "tierlist":
1001
1001
  Fs(), A(!0);
@@ -1004,67 +1004,67 @@ function bi({ commands: t = cn }) {
1004
1004
  S("info", `${D.usage} is not implemented yet.`);
1005
1005
  }
1006
1006
  }, [R, S, t, A]), C = j((D) => {
1007
- n(fi(D)), l(!1), o.current?.focus();
1007
+ n(fi(D)), o(!1), c.current?.focus();
1008
1008
  }, []), P = j(async (D) => {
1009
- if (D.preventDefault(), r || p.uploading) return;
1009
+ if (D.preventDefault(), r || h.uploading) return;
1010
1010
  const W = hi(e, t);
1011
- if (!W && !p.pending.length) return;
1012
- if (W?.kind === "command" && p.pending.length) {
1011
+ if (!W && !h.pending.length) return;
1012
+ if (W?.kind === "command" && h.pending.length) {
1013
1013
  S("info", "Send images on their own, not with a command.");
1014
1014
  return;
1015
1015
  }
1016
1016
  if (W?.kind === "command") {
1017
- w(W.command, W.args), n(""), !document.hidden && document.hasFocus() && o.current?.focus();
1017
+ w(W.command, W.args), n(""), !document.hidden && document.hasFocus() && c.current?.focus();
1018
1018
  return;
1019
1019
  }
1020
- const X = await p.uploadPending();
1021
- X !== null && (rr(W?.text ?? "", X), n(""), p.clear(), s(!0), setTimeout(() => s(!1), gi), !document.hidden && document.hasFocus() && o.current?.focus());
1022
- }, [e, r, w, p, S, t]), O = j((D) => {
1020
+ const X = await h.uploadPending();
1021
+ X !== null && (rr(W?.text ?? "", X), n(""), h.clear(), s(!0), setTimeout(() => s(!1), gi), !document.hidden && document.hasFocus() && c.current?.focus());
1022
+ }, [e, r, w, h, S, t]), O = j((D) => {
1023
1023
  if (D.key === "Escape" && T) {
1024
- D.preventDefault(), l(!0);
1024
+ D.preventDefault(), o(!0);
1025
1025
  return;
1026
1026
  }
1027
1027
  if (T) {
1028
1028
  if (D.key === "ArrowDown")
1029
- D.preventDefault(), y(Dt(L + 1, m.length));
1029
+ D.preventDefault(), y(Dt(N + 1, m.length));
1030
1030
  else if (D.key === "ArrowUp")
1031
- D.preventDefault(), y(Dt(L - 1, m.length));
1031
+ D.preventDefault(), y(Dt(N - 1, m.length));
1032
1032
  else if (D.key === "Tab") {
1033
1033
  D.preventDefault();
1034
- const W = m[L];
1034
+ const W = m[N];
1035
1035
  W && C(W);
1036
1036
  } else if (D.key === "Enter") {
1037
1037
  D.preventDefault();
1038
- const W = m[L];
1038
+ const W = m[N];
1039
1039
  W && C(W);
1040
1040
  }
1041
1041
  }
1042
- }, [T, m, L, C, y]);
1042
+ }, [T, m, N, C, y]);
1043
1043
  F(() => {
1044
1044
  const D = () => {
1045
- document.hidden || !document.hasFocus() || (o.current?.focus(), o.current?.scrollIntoView({ block: "nearest" }));
1045
+ document.hidden || !document.hasFocus() || (c.current?.focus(), c.current?.scrollIntoView({ block: "nearest" }));
1046
1046
  };
1047
1047
  return window.addEventListener("watchparty:focus-chat-input", D), () => window.removeEventListener("watchparty:focus-chat-input", D);
1048
1048
  }, []);
1049
- const H = An - e.length, G = H <= 100, J = T ? m[L] : void 0;
1049
+ const H = An - e.length, G = H <= 100, J = T ? m[N] : void 0;
1050
1050
  return /* @__PURE__ */ k(
1051
1051
  "form",
1052
1052
  {
1053
1053
  onSubmit: (D) => {
1054
1054
  P(D);
1055
1055
  },
1056
- onPaste: p.onPaste,
1057
- onDrop: p.onDrop,
1058
- onDragOver: p.onDragOver,
1056
+ onPaste: h.onPaste,
1057
+ onDrop: h.onDrop,
1058
+ onDragOver: h.onDragOver,
1059
1059
  className: "p-2 border-t border-border",
1060
1060
  children: [
1061
- /* @__PURE__ */ d(Rr, { pending: p.pending, uploading: p.uploading, onRemove: p.remove }),
1061
+ /* @__PURE__ */ d(Rr, { pending: h.pending, uploading: h.uploading, onRemove: h.remove }),
1062
1062
  /* @__PURE__ */ k("div", { className: "relative", children: [
1063
1063
  T && /* @__PURE__ */ d(
1064
1064
  mi,
1065
1065
  {
1066
1066
  commands: m,
1067
- activeIndex: L,
1067
+ activeIndex: N,
1068
1068
  hasMedia: R,
1069
1069
  onPick: C,
1070
1070
  onHover: y,
@@ -1075,10 +1075,10 @@ function bi({ commands: t = cn }) {
1075
1075
  wr,
1076
1076
  {
1077
1077
  open: f,
1078
- onClose: () => h(!1),
1079
- onPick: p.addMeme,
1078
+ onClose: () => p(!1),
1079
+ onPick: h.addMeme,
1080
1080
  onUnavailable: () => {
1081
- b(!0), h(!1);
1081
+ b(!0), p(!1);
1082
1082
  }
1083
1083
  }
1084
1084
  ),
@@ -1087,11 +1087,11 @@ function bi({ commands: t = cn }) {
1087
1087
  /* @__PURE__ */ d(
1088
1088
  "input",
1089
1089
  {
1090
- ref: o,
1090
+ ref: c,
1091
1091
  type: "text",
1092
1092
  value: e,
1093
1093
  onChange: (D) => {
1094
- n(D.target.value), l(!1);
1094
+ n(D.target.value), o(!1);
1095
1095
  },
1096
1096
  onKeyDown: O,
1097
1097
  maxLength: An,
@@ -1110,7 +1110,7 @@ function bi({ commands: t = cn }) {
1110
1110
  "button",
1111
1111
  {
1112
1112
  type: "button",
1113
- onClick: () => h((D) => !D),
1113
+ onClick: () => p((D) => !D),
1114
1114
  "aria-label": "Add a meme",
1115
1115
  "aria-expanded": f,
1116
1116
  title: "Add a meme",
@@ -1147,14 +1147,14 @@ function vi({ u: t }) {
1147
1147
  ] });
1148
1148
  }
1149
1149
  function Si() {
1150
- const t = x((i) => Object.keys(i.roster).length), [e, n] = $(!1), r = N(null), s = N(null);
1150
+ const t = x((i) => Object.keys(i.roster).length), [e, n] = $(!1), r = L(null), s = L(null);
1151
1151
  return F(() => {
1152
1152
  if (!e) return;
1153
- function i(c) {
1154
- r.current && !r.current.contains(c.target) && n(!1);
1153
+ function i(l) {
1154
+ r.current && !r.current.contains(l.target) && n(!1);
1155
1155
  }
1156
- function a(c) {
1157
- Ve(c) && (c.stopPropagation(), n(!1), s.current?.focus());
1156
+ function a(l) {
1157
+ Ve(l) && (l.stopPropagation(), n(!1), s.current?.focus());
1158
1158
  }
1159
1159
  return document.addEventListener("mousedown", i), document.addEventListener("keydown", a, !0), () => {
1160
1160
  document.removeEventListener("mousedown", i), document.removeEventListener("keydown", a, !0);
@@ -1210,7 +1210,7 @@ function ze() {
1210
1210
  return x((t) => !!t.snapshot.leaderId && t.snapshot.leaderId === t.me.clientId);
1211
1211
  }
1212
1212
  function Rt() {
1213
- const t = x((n) => n.activeGameId), e = Ns();
1213
+ const t = x((n) => n.activeGameId), e = Ls();
1214
1214
  return t ? e.find((n) => n.id === t) ?? null : null;
1215
1215
  }
1216
1216
  function ln() {
@@ -1220,15 +1220,15 @@ function ln() {
1220
1220
  keyType: _i(ki(globalThis.location?.pathname), t.roomKeyType)
1221
1221
  }));
1222
1222
  }
1223
- function Lr() {
1223
+ function Nr() {
1224
1224
  return x((t) => t.readiness);
1225
1225
  }
1226
1226
  function Ai() {
1227
1227
  return x((t) => t.snapshot);
1228
1228
  }
1229
1229
  const Ti = 3e4;
1230
- function Nr() {
1231
- const t = Lr(), [e, n] = $(!1), [r, s] = $({ mediaId: t.mediaId, ready: t.ready });
1230
+ function Lr() {
1231
+ const t = Nr(), [e, n] = $(!1), [r, s] = $({ mediaId: t.mediaId, ready: t.ready });
1232
1232
  return (r.mediaId !== t.mediaId || r.ready !== t.ready) && (s({ mediaId: t.mediaId, ready: t.ready }), n(!1)), F(() => {
1233
1233
  if (t.ready) return;
1234
1234
  const i = setTimeout(() => n(!0), Ti);
@@ -1236,17 +1236,17 @@ function Nr() {
1236
1236
  }, [t.mediaId, t.ready]), e;
1237
1237
  }
1238
1238
  function Ii({ draw: t }) {
1239
- const e = N(null);
1239
+ const e = L(null);
1240
1240
  return F(() => {
1241
1241
  const n = e.current;
1242
1242
  if (n)
1243
1243
  return t(n) ?? void 0;
1244
1244
  }, [t]), /* @__PURE__ */ d("div", { ref: e, "data-testid": "game-settings" });
1245
1245
  }
1246
- const Ci = sn(() => import("./AdminPanel-rpVTvC5k.js")), Ri = sn(() => import("./PlaylistPanel-B2JA2RPM.js"));
1246
+ const Ci = sn(() => import("./AdminPanel-C-uakHiU.js")), Ri = sn(() => import("./PlaylistPanel-D_UOoMki.js"));
1247
1247
  function Fi() {
1248
- const t = x((h) => h.chatCollapsed), e = It(), n = x((h) => h.sidebarTab), r = x((h) => h.setSidebarTab), s = x((h) => h.healthSnapshot?.clients.length ?? 0), i = x((h) => !!h.playlist), a = ze(), c = ln(), l = x((h) => h.gameSettings), o = x((h) => h.snapshot.mediaId), u = Rt() !== null;
1249
- if (Ct({ hasMedia: !!o, chatCollapsed: t, isFullscreen: e }))
1248
+ const t = x((p) => p.chatCollapsed), e = St(), n = x((p) => p.sidebarTab), r = x((p) => p.setSidebarTab), s = x((p) => p.healthSnapshot?.clients.length ?? 0), i = x((p) => !!p.playlist), a = ze(), l = ln(), o = x((p) => p.gameSettings), c = x((p) => p.snapshot.mediaId), u = Rt() !== null;
1249
+ if (Ct({ hasMedia: !!c, chatCollapsed: t, isFullscreen: e }))
1250
1250
  return null;
1251
1251
  const f = n === "health" && !a || n === "playlist" && !i ? "chat" : n;
1252
1252
  return /* @__PURE__ */ k("aside", { className: "wp-chat-panel w-80 self-stretch border-l border-border flex flex-col bg-bg relative z-10", children: [
@@ -1264,7 +1264,7 @@ function Fi() {
1264
1264
  children: /* @__PURE__ */ d("svg", { className: "w-4 h-4", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", strokeWidth: 2, children: /* @__PURE__ */ d("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M3 12l2-2m0 0l7-7 7 7M5 10v10a1 1 0 001 1h3m10-11l2 2m-2-2v10a1 1 0 01-1 1h-3m-6 0a1 1 0 001-1v-4a1 1 0 011-1h2a1 1 0 011 1v4a1 1 0 001 1m-6 0h6" }) })
1265
1265
  }
1266
1266
  ),
1267
- on({ isLeader: c, hasMedia: !!o, chatCollapsed: t, isFullscreen: e, gameOverlay: u }) === "chat-toolbar" && /* @__PURE__ */ d(
1267
+ on({ isLeader: l, hasMedia: !!c, chatCollapsed: t, isFullscreen: e, gameOverlay: u }) === "chat-toolbar" && /* @__PURE__ */ d(
1268
1268
  "button",
1269
1269
  {
1270
1270
  onClick: () => Er("chat toolbar"),
@@ -1275,7 +1275,7 @@ function Fi() {
1275
1275
  }
1276
1276
  ),
1277
1277
  /* @__PURE__ */ d(Ea, {}),
1278
- /* @__PURE__ */ d(xa, { children: l ? /* @__PURE__ */ d(Ii, { draw: l }) : null }),
1278
+ /* @__PURE__ */ d(xa, { children: o ? /* @__PURE__ */ d(Ii, { draw: o }) : null }),
1279
1279
  /* @__PURE__ */ d(Si, {})
1280
1280
  ] }),
1281
1281
  (a || i) && /* @__PURE__ */ k("div", { role: "tablist", "aria-label": "Sidebar", className: "flex border-b border-border shrink-0", children: [
@@ -1320,49 +1320,49 @@ function Fi() {
1320
1320
  ] });
1321
1321
  }
1322
1322
  const Tn = (t) => typeof t == "string" && Sa.includes(t);
1323
- function Li(t, e, n) {
1323
+ function Ni(t, e, n) {
1324
1324
  return Tn(e) ? e : Tn(n) ? n : "dark";
1325
1325
  }
1326
1326
  function In({ activity: t, roomKey: e, layer: n }) {
1327
- const r = N(null), s = N(null), [i, a] = $(null), [c, l] = $(!1), o = x((_) => _.snapshot.leaderId), u = x((_) => _.me.clientId), f = !!o && o === u, h = x((_) => _.name), g = wa()?.theme, b = Li(void 0, g, Ds().theme), p = Me(() => ({
1327
+ const r = L(null), s = L(null), [i, a] = $(null), [l, o] = $(!1), c = x((_) => _.snapshot.leaderId), u = x((_) => _.me.clientId), f = !!c && c === u, p = x((_) => _.name), g = wa()?.theme, b = Ni(void 0, g, Ds().theme), h = Me(() => ({
1328
1328
  roomKey: e,
1329
1329
  identity: {
1330
1330
  // The registry userId — what RoomChrome's `userId` prop is.
1331
1331
  userId: Os(),
1332
1332
  userType: Bs(),
1333
- name: h || null
1333
+ name: p || null
1334
1334
  },
1335
1335
  theme: b,
1336
1336
  isLeader: f,
1337
1337
  close: () => {
1338
- E("game", "bundle close", { gameId: t.id, isLeader: f, layer: n }), n !== "base" && (f ? ir(null) : l(!0));
1338
+ E("game", "bundle close", { gameId: t.id, isLeader: f, layer: n }), n !== "base" && (f ? ir(null) : o(!0));
1339
1339
  }
1340
- }), [e, h, b, f, t.id, n]), v = ue(() => p), S = ue((_, m) => {
1340
+ }), [e, p, b, f, t.id, n]), v = ue(() => h), S = ue((_, m) => {
1341
1341
  I("game", "bundle failed", { gameId: t.id, message: _, cause: String(m) }), a(_);
1342
1342
  }), A = ue((_, m) => {
1343
1343
  I("game", "bundle settings failed", { gameId: t.id, message: _, cause: String(m) });
1344
1344
  });
1345
1345
  if (F(() => {
1346
1346
  const _ = r.current, m = t.load;
1347
- if (!_ || !m || c) return;
1347
+ if (!_ || !m || l) return;
1348
1348
  E("game", "bundle mount", { gameId: t.id });
1349
- const { setGameSettings: T } = x.getState(), L = (w) => y.mountSettings(w), y = Qa({
1349
+ const { setGameSettings: T } = x.getState(), N = (w) => y.mountSettings(w), y = Qa({
1350
1350
  load: m,
1351
1351
  el: _,
1352
1352
  ctx: v(),
1353
1353
  onError: S,
1354
1354
  onSettingsAvailable: n === "overlay" ? (w) => {
1355
1355
  const C = x.getState().gameSettings;
1356
- w ? T(L) : C === L && T(null);
1356
+ w ? T(N) : C === N && T(null);
1357
1357
  } : void 0,
1358
1358
  onSettingsError: A
1359
1359
  });
1360
1360
  return s.current = y, () => {
1361
1361
  y.dispose(), s.current = null;
1362
1362
  };
1363
- }, [t.id, t.load, c, n]), F(() => {
1364
- s.current?.update(p);
1365
- }, [p]), c) return null;
1363
+ }, [t.id, t.load, l, n]), F(() => {
1364
+ s.current?.update(h);
1365
+ }, [h]), l) return null;
1366
1366
  const R = t.load ? i : "This game is not served from this site.";
1367
1367
  return /* @__PURE__ */ k(
1368
1368
  "div",
@@ -1378,19 +1378,19 @@ function In({ activity: t, roomKey: e, layer: n }) {
1378
1378
  " could not start"
1379
1379
  ] }),
1380
1380
  /* @__PURE__ */ d("div", { className: "text-text-secondary text-sm", children: R }),
1381
- n === "overlay" && /* @__PURE__ */ d("button", { type: "button", className: "drawer-btn", onClick: () => p.close(), children: "Close" })
1381
+ n === "overlay" && /* @__PURE__ */ d("button", { type: "button", className: "drawer-btn", onClick: () => h.close(), children: "Close" })
1382
1382
  ] })
1383
1383
  ]
1384
1384
  }
1385
1385
  );
1386
1386
  }
1387
- const Ni = "drawer-btn";
1387
+ const Li = "drawer-btn";
1388
1388
  function $i({ open: t, onClose: e, header: n, footer: r, children: s }) {
1389
- const i = N(null);
1389
+ const i = L(null);
1390
1390
  return F(() => {
1391
1391
  if (!t) return;
1392
- function a(c) {
1393
- Ve(c) && e();
1392
+ function a(l) {
1393
+ Ve(l) && e();
1394
1394
  }
1395
1395
  return window.addEventListener("keydown", a), () => window.removeEventListener("keydown", a);
1396
1396
  }, [t, e]), F(() => {
@@ -1408,7 +1408,7 @@ function $i({ open: t, onClose: e, header: n, footer: r, children: s }) {
1408
1408
  onClick: (a) => a.stopPropagation(),
1409
1409
  children: [
1410
1410
  /* @__PURE__ */ k("div", { className: "p-3 border-b border-border flex items-center gap-2 text-sm", children: [
1411
- /* @__PURE__ */ d("button", { ref: i, onClick: e, className: Ni, children: "Close" }),
1411
+ /* @__PURE__ */ d("button", { ref: i, onClick: e, className: Li, children: "Close" }),
1412
1412
  n
1413
1413
  ] }),
1414
1414
  s,
@@ -1436,59 +1436,51 @@ function Bi({ message: t, age: e, ccStyle: n }) {
1436
1436
  const i = Di[n], a = _r(
1437
1437
  { clientId: t.clientId, author: t.author },
1438
1438
  { name: t.name, sprite: t.sprite }
1439
- ), c = st(a.sprite, a.pictureUrl), l = a.cosmetics, [o] = $(
1440
- () => t.live && t.text ? tr(t.text, l) : null
1439
+ ), l = st(a.sprite, a.pictureUrl), o = a.cosmetics, [c] = $(
1440
+ () => t.live && t.text ? tr(t.text, o) : null
1441
1441
  );
1442
1442
  return /* @__PURE__ */ k(
1443
1443
  "div",
1444
1444
  {
1445
1445
  className: `flex items-start gap-2 py-1 ${i}`,
1446
- style: { opacity: s, transition: "opacity 0.15s ease-out", ...Tr(c) },
1446
+ style: { opacity: s, transition: "opacity 0.15s ease-out", ...Tr(l) },
1447
1447
  children: [
1448
- /* @__PURE__ */ d(Ir, { sprite: a.sprite, url: a.pictureUrl, worn: l }),
1448
+ /* @__PURE__ */ d(Ir, { sprite: a.sprite, url: a.pictureUrl, worn: o }),
1449
1449
  /* @__PURE__ */ k("div", { className: "min-w-0 flex-1", children: [
1450
- l ? /* @__PURE__ */ d(bt, { html: nr(a.name, l), className: "text-sm mr-2", style: { color: c, ...Fn } }) : /* @__PURE__ */ d("span", { className: "font-medium text-sm mr-2", style: { color: c, ...Rn }, children: a.name }),
1451
- o ? /* @__PURE__ */ d(bt, { html: o, className: "text-sm text-white break-words", style: Fn }) : /* @__PURE__ */ d("span", { className: "text-sm text-white break-words", style: Rn, children: t.text }),
1450
+ o ? /* @__PURE__ */ d(bt, { html: nr(a.name, o), className: "text-sm mr-2", style: { color: l, ...Fn } }) : /* @__PURE__ */ d("span", { className: "font-medium text-sm mr-2", style: { color: l, ...Rn }, children: a.name }),
1451
+ c ? /* @__PURE__ */ d(bt, { html: c, className: "text-sm text-white break-words", style: Fn }) : /* @__PURE__ */ d("span", { className: "text-sm text-white break-words", style: Rn, children: t.text }),
1452
1452
  /* @__PURE__ */ d(Cr, { images: t.images })
1453
1453
  ] })
1454
1454
  ]
1455
1455
  }
1456
1456
  );
1457
1457
  }
1458
- function Oi() {
1458
+ function Oi({ shown: t, className: e }) {
1459
1459
  Ar();
1460
- const t = x((h) => h.chat), e = x((h) => h.chatCollapsed), n = x((h) => h.snapshot.mediaId), r = x((h) => h.floatingChatEnabled), s = x((h) => h.mediaPrefs.subtitleStyle), [i, a] = $(!1), [c, l] = $(() => Date.now());
1461
- F(() => {
1462
- const h = () => {
1463
- a(!!document.fullscreenElement);
1464
- };
1465
- return document.addEventListener("fullscreenchange", h), h(), () => document.removeEventListener("fullscreenchange", h);
1466
- }, []);
1467
- const o = t.length > 0;
1460
+ const n = x((o) => o.chat), r = x((o) => o.mediaPrefs.subtitleStyle), [s, i] = $(() => Date.now()), a = n.length > 0;
1468
1461
  F(() => {
1469
- const h = setInterval(() => {
1470
- o && l(Date.now());
1462
+ const o = setInterval(() => {
1463
+ a && i(Date.now());
1471
1464
  }, 200);
1472
- return () => clearInterval(h);
1473
- }, [o]);
1474
- const u = qa(r, { hasMedia: !!n, chatCollapsed: e, isFullscreen: i }), f = Me(() => {
1475
- const h = c - $r;
1476
- return t.filter((g) => !g.isSystem && g.ts > h).slice(-12);
1477
- }, [t, c]);
1478
- return !u || f.length === 0 ? null : /* @__PURE__ */ d(
1465
+ return () => clearInterval(o);
1466
+ }, [a]);
1467
+ const l = Me(() => {
1468
+ const o = s - $r;
1469
+ return n.filter((c) => !c.isSystem && c.ts > o).slice(-12);
1470
+ }, [n, s]);
1471
+ return !t || l.length === 0 ? null : /* @__PURE__ */ d(
1479
1472
  "div",
1480
1473
  {
1481
- className: "wp-floating-chat absolute right-4 w-80 z-20 pointer-events-none flex flex-col",
1482
- style: { bottom: "35%" },
1474
+ className: `wp-floating-chat pointer-events-none flex flex-col ${e}`,
1483
1475
  "data-testid": "floating-chat",
1484
- children: f.map((h) => /* @__PURE__ */ d(
1476
+ children: l.map((o) => /* @__PURE__ */ d(
1485
1477
  Bi,
1486
1478
  {
1487
- message: h,
1488
- age: c - h.ts,
1489
- ccStyle: s
1479
+ message: o,
1480
+ age: s - o.ts,
1481
+ ccStyle: r
1490
1482
  },
1491
- h.id
1483
+ o.id
1492
1484
  ))
1493
1485
  }
1494
1486
  );
@@ -1501,25 +1493,25 @@ function Dr(t) {
1501
1493
  const e = t.video_ready_state ?? -1;
1502
1494
  return e < 0 ? !0 : !(e <= Hi && t.buffered_ahead_ms > an);
1503
1495
  }
1504
- function fl(t) {
1496
+ function hl(t) {
1505
1497
  return t.playhead_ms === 0 && !t.is_buffering && t.buffered_ahead_ms === 0 ? "idle" : t.is_buffering ? "buffering" : Pr(t) ? "healthy" : !Dr(t) || t.buffered_ahead_ms <= or ? "critical" : t.buffered_ahead_ms <= an ? "warning" : "healthy";
1506
1498
  }
1507
- const hl = {
1499
+ const pl = {
1508
1500
  idle: "Idle",
1509
1501
  buffering: "Buffering",
1510
1502
  critical: "Critical",
1511
1503
  warning: "Low Buffer",
1512
1504
  healthy: "Healthy"
1513
1505
  };
1514
- let xt = null;
1506
+ let Mt = null;
1515
1507
  function Br() {
1516
- if (xt) return xt;
1508
+ if (Mt) return Mt;
1517
1509
  try {
1518
1510
  const t = window.AudioContext ?? window.webkitAudioContext;
1519
- t && (xt = new t());
1511
+ t && (Mt = new t());
1520
1512
  } catch {
1521
1513
  }
1522
- return xt;
1514
+ return Mt;
1523
1515
  }
1524
1516
  function Or(t) {
1525
1517
  t.state === "suspended" && t.resume().catch(() => {
@@ -1532,15 +1524,15 @@ function We(t, e, n = 0.15, r = 0) {
1532
1524
  const s = Br();
1533
1525
  if (!s) return;
1534
1526
  Or(s);
1535
- const i = s.currentTime + r, a = s.createOscillator(), c = s.createGain();
1536
- a.type = "sine", a.frequency.value = t, Hr(c, i, n, e / 1e3), a.connect(c).connect(s.destination), a.start(i), a.stop(i + e / 1e3 + 0.05);
1527
+ const i = s.currentTime + r, a = s.createOscillator(), l = s.createGain();
1528
+ a.type = "sine", a.frequency.value = t, Hr(l, i, n, e / 1e3), a.connect(l).connect(s.destination), a.start(i), a.stop(i + e / 1e3 + 0.05);
1537
1529
  }
1538
1530
  function Bt(t, e, n, r, s = 0.15, i = 0) {
1539
1531
  const a = Br();
1540
1532
  if (!a) return;
1541
1533
  Or(a);
1542
- const c = a.currentTime + i, l = a.createOscillator(), o = a.createOscillator(), u = a.createGain(), f = a.createGain();
1543
- l.type = "sine", l.frequency.value = t, o.type = "sine", o.frequency.value = e, u.gain.value = n * e, o.connect(u).connect(l.frequency), Hr(f, c, s, r / 1e3), l.connect(f).connect(a.destination), l.start(c), l.stop(c + r / 1e3 + 0.05), o.start(c), o.stop(c + r / 1e3 + 0.05);
1534
+ const l = a.currentTime + i, o = a.createOscillator(), c = a.createOscillator(), u = a.createGain(), f = a.createGain();
1535
+ o.type = "sine", o.frequency.value = t, c.type = "sine", c.frequency.value = e, u.gain.value = n * e, c.connect(u).connect(o.frequency), Hr(f, l, s, r / 1e3), o.connect(f).connect(a.destination), o.start(l), o.stop(l + r / 1e3 + 0.05), c.start(l), c.stop(l + r / 1e3 + 0.05);
1544
1536
  }
1545
1537
  function Ur() {
1546
1538
  We(700, 60, 0.14, 0), We(700, 60, 0.14, 0.1), We(932, 120, 0.17, 0.2);
@@ -1560,17 +1552,17 @@ cr("__WP_SOUNDS__", {
1560
1552
  on: jr,
1561
1553
  off: Gr
1562
1554
  });
1563
- const Ln = { on: 0, off: 0 };
1555
+ const Nn = { on: 0, off: 0 };
1564
1556
  function Ui(t, e, n, r) {
1565
- if (!n || !r) return Ln;
1557
+ if (!n || !r) return Nn;
1566
1558
  const s = new Set(t), i = new Set(e);
1567
1559
  let a = 0;
1568
- for (const l of i) s.has(l) || a++;
1569
- let c = 0;
1570
- for (const l of s) i.has(l) || c++;
1571
- return a === 0 && c === 0 ? Ln : { on: a, off: c };
1560
+ for (const o of i) s.has(o) || a++;
1561
+ let l = 0;
1562
+ for (const o of s) i.has(o) || l++;
1563
+ return a === 0 && l === 0 ? Nn : { on: a, off: l };
1572
1564
  }
1573
- const ji = 1200, be = 52, At = 4, Xt = (be - At) / 2, Nn = 2 * Math.PI * Xt, De = be - At * 2 - 4;
1565
+ const ji = 1200, be = 52, Tt = 4, Xt = (be - Tt) / 2, Ln = 2 * Math.PI * Xt, De = be - Tt * 2 - 4;
1574
1566
  function Gi(t) {
1575
1567
  return Pr(t) ? !0 : Dr(t) ? t.buffered_ahead_ms >= Fe : !1;
1576
1568
  }
@@ -1578,7 +1570,7 @@ function Wi(t) {
1578
1570
  return `hsl(${Math.round(t * 120)}, 90%, 55%)`;
1579
1571
  }
1580
1572
  function Ki({ client: t, look: e, fading: n, onFadeEnd: r }) {
1581
- const s = Math.min(1, t.buffered_ahead_ms / Fe), i = Nn * (1 - s), a = Wi(s), c = st(e.sprite, e.pictureUrl);
1573
+ const s = Math.min(1, t.buffered_ahead_ms / Fe), i = Ln * (1 - s), a = Wi(s), l = st(e.sprite, e.pictureUrl);
1582
1574
  return /* @__PURE__ */ k(
1583
1575
  "div",
1584
1576
  {
@@ -1607,7 +1599,7 @@ function Ki({ client: t, look: e, fading: n, onFadeEnd: r }) {
1607
1599
  r: Xt,
1608
1600
  fill: "none",
1609
1601
  stroke: "rgba(255,255,255,0.15)",
1610
- strokeWidth: At
1602
+ strokeWidth: Tt
1611
1603
  }
1612
1604
  ),
1613
1605
  /* @__PURE__ */ d(
@@ -1618,9 +1610,9 @@ function Ki({ client: t, look: e, fading: n, onFadeEnd: r }) {
1618
1610
  r: Xt,
1619
1611
  fill: "none",
1620
1612
  stroke: a,
1621
- strokeWidth: At,
1613
+ strokeWidth: Tt,
1622
1614
  strokeLinecap: "round",
1623
- strokeDasharray: Nn,
1615
+ strokeDasharray: Ln,
1624
1616
  strokeDashoffset: i,
1625
1617
  style: { transition: "stroke-dashoffset 0.4s ease, stroke 0.4s ease" }
1626
1618
  }
@@ -1635,12 +1627,12 @@ function Ki({ client: t, look: e, fading: n, onFadeEnd: r }) {
1635
1627
  url: e.pictureUrl,
1636
1628
  alt: e.name,
1637
1629
  className: "rounded-full object-cover flex-shrink-0",
1638
- style: { width: De, height: De, border: `2px solid ${c}` },
1630
+ style: { width: De, height: De, border: `2px solid ${l}` },
1639
1631
  fallback: /* @__PURE__ */ d(
1640
1632
  "div",
1641
1633
  {
1642
1634
  className: "rounded-full bg-bg-alt flex-shrink-0",
1643
- style: { width: De, height: De, border: `2px solid ${c}` }
1635
+ style: { width: De, height: De, border: `2px solid ${l}` }
1644
1636
  }
1645
1637
  )
1646
1638
  }
@@ -1651,7 +1643,7 @@ function Ki({ client: t, look: e, fading: n, onFadeEnd: r }) {
1651
1643
  {
1652
1644
  className: "text-xs font-medium leading-none",
1653
1645
  style: {
1654
- color: c,
1646
+ color: l,
1655
1647
  textShadow: "-1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000, 1px 1px 0 #000",
1656
1648
  maxWidth: 64,
1657
1649
  overflow: "hidden",
@@ -1666,7 +1658,7 @@ function Ki({ client: t, look: e, fading: n, onFadeEnd: r }) {
1666
1658
  );
1667
1659
  }
1668
1660
  function Vi({ clientId: t, sprite: e, pictureUrl: n, name: r, isReady: s, isSelf: i, onToggle: a }) {
1669
- const c = st(e, n), l = s ? "success" : "neutral", o = s ? /* @__PURE__ */ d(gt, { name: "tick" }) : /* @__PURE__ */ d(gt, { name: "hourglass" });
1661
+ const l = st(e, n), o = s ? "success" : "neutral", c = s ? /* @__PURE__ */ d(gt, { name: "tick" }) : /* @__PURE__ */ d(gt, { name: "hourglass" });
1670
1662
  return /* @__PURE__ */ k(
1671
1663
  "button",
1672
1664
  {
@@ -1689,12 +1681,12 @@ function Vi({ clientId: t, sprite: e, pictureUrl: n, name: r, isReady: s, isSelf
1689
1681
  url: n,
1690
1682
  alt: r,
1691
1683
  className: "rounded-full object-cover flex-shrink-0",
1692
- style: { width: De, height: De, border: `2px solid ${c}`, opacity: s ? 1 : 0.55 },
1684
+ style: { width: De, height: De, border: `2px solid ${l}`, opacity: s ? 1 : 0.55 },
1693
1685
  fallback: /* @__PURE__ */ d(
1694
1686
  "div",
1695
1687
  {
1696
1688
  className: "rounded-full bg-bg-alt flex-shrink-0",
1697
- style: { width: De, height: De, border: `2px solid ${c}` }
1689
+ style: { width: De, height: De, border: `2px solid ${l}` }
1698
1690
  }
1699
1691
  )
1700
1692
  }
@@ -1705,8 +1697,8 @@ function Vi({ clientId: t, sprite: e, pictureUrl: n, name: r, isReady: s, isSelf
1705
1697
  "aria-label": s ? "ready" : "pending",
1706
1698
  className: "absolute -bottom-1 -right-1 text-xs font-bold rounded-full",
1707
1699
  style: {
1708
- background: `var(--color-${l})`,
1709
- color: `var(--color-on-${l})`,
1700
+ background: `var(--color-${o})`,
1701
+ color: `var(--color-on-${o})`,
1710
1702
  width: 20,
1711
1703
  height: 20,
1712
1704
  display: "flex",
@@ -1714,7 +1706,7 @@ function Vi({ clientId: t, sprite: e, pictureUrl: n, name: r, isReady: s, isSelf
1714
1706
  justifyContent: "center",
1715
1707
  lineHeight: 1
1716
1708
  },
1717
- children: o
1709
+ children: c
1718
1710
  }
1719
1711
  )
1720
1712
  ] }),
@@ -1723,7 +1715,7 @@ function Vi({ clientId: t, sprite: e, pictureUrl: n, name: r, isReady: s, isSelf
1723
1715
  {
1724
1716
  className: "text-xs font-medium leading-none",
1725
1717
  style: {
1726
- color: c,
1718
+ color: l,
1727
1719
  textShadow: "-1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000, 1px 1px 0 #000",
1728
1720
  maxWidth: 64,
1729
1721
  overflow: "hidden",
@@ -1748,20 +1740,20 @@ function $n(t, e) {
1748
1740
  return { status: e, entries: s, completed: n, below: r };
1749
1741
  }
1750
1742
  function Ji() {
1751
- const t = x((m) => m.bufferStatus), e = x((m) => m.readyCheck), n = x((m) => m.roster), r = x((m) => m.me.clientId), s = x((m) => m.snapshot.playing), i = ze(), [a, c] = $(() => $n(zi, t));
1752
- a.status !== t && c($n(a, t));
1753
- const l = a.entries, o = (m) => {
1754
- c((T) => {
1755
- const L = new Set(T.completed), y = new Set(T.below);
1756
- return L.delete(m), y.delete(m), { ...T, completed: L, below: y, entries: T.entries.filter((w) => w.client.client_id !== m) };
1743
+ const t = x((m) => m.bufferStatus), e = x((m) => m.readyCheck), n = x((m) => m.roster), r = x((m) => m.me.clientId), s = x((m) => m.snapshot.playing), i = ze(), [a, l] = $(() => $n(zi, t));
1744
+ a.status !== t && l($n(a, t));
1745
+ const o = a.entries, c = (m) => {
1746
+ l((T) => {
1747
+ const N = new Set(T.completed), y = new Set(T.below);
1748
+ return N.delete(m), y.delete(m), { ...T, completed: N, below: y, entries: T.entries.filter((w) => w.client.client_id !== m) };
1757
1749
  });
1758
- }, u = new Set(e.ready), f = Object.values(n), h = !!r && u.has(r), g = e.active && f.length > 0 && e.ready.length >= f.length, b = N(e.active), p = N(g);
1750
+ }, u = new Set(e.ready), f = Object.values(n), p = !!r && u.has(r), g = e.active && f.length > 0 && e.ready.length >= f.length, b = L(e.active), h = L(g);
1759
1751
  F(() => {
1760
1752
  !b.current && e.active && Ur(), b.current = e.active;
1761
1753
  }, [e.active]), F(() => {
1762
- !p.current && g && Wr(), p.current = g;
1754
+ !h.current && g && Wr(), h.current = g;
1763
1755
  }, [g]);
1764
- const v = N(e.ready), S = N(e.active);
1756
+ const v = L(e.ready), S = L(e.active);
1765
1757
  F(() => {
1766
1758
  const { on: m, off: T } = Ui(
1767
1759
  v.current,
@@ -1771,7 +1763,7 @@ function Ji() {
1771
1763
  );
1772
1764
  m > 0 && jr(), T > 0 && Gr(), v.current = e.ready, S.current = e.active;
1773
1765
  }, [e.ready, e.active]);
1774
- const A = e.active, R = !A && l.length > 0, _ = !A && !R && i && f.length > 0 && !s;
1766
+ const A = e.active, R = !A && o.length > 0, _ = !A && !R && i && f.length > 0 && !s;
1775
1767
  return !A && !R && !_ ? null : /* @__PURE__ */ k(ye, { children: [
1776
1768
  /* @__PURE__ */ d("style", { children: `
1777
1769
  @keyframes bufferFadeOut {
@@ -1810,18 +1802,18 @@ function Ji() {
1810
1802
  name: m.name || "Anon",
1811
1803
  isReady: u.has(m.clientId),
1812
1804
  isSelf: m.clientId === r,
1813
- onToggle: () => Hs(!h)
1805
+ onToggle: () => Hs(!p)
1814
1806
  },
1815
1807
  m.clientId
1816
1808
  )) })
1817
1809
  ] }),
1818
- R && l.map(({ client: m, completed: T }) => /* @__PURE__ */ d(
1810
+ R && o.map(({ client: m, completed: T }) => /* @__PURE__ */ d(
1819
1811
  Ki,
1820
1812
  {
1821
1813
  client: m,
1822
1814
  look: kr(n, { clientId: m.client_id }, { name: m.name, sprite: m.sprite_id ?? null }),
1823
1815
  fading: T,
1824
- onFadeEnd: () => o(m.client_id)
1816
+ onFadeEnd: () => c(m.client_id)
1825
1817
  },
1826
1818
  m.client_id
1827
1819
  )),
@@ -1918,18 +1910,18 @@ function qi({
1918
1910
  itemId: e,
1919
1911
  snap: n
1920
1912
  }) {
1921
- const r = N(null), [s, i] = $(null), a = n.placed.find((l) => l.mediaId === e);
1913
+ const r = L(null), [s, i] = $(null), a = n.placed.find((o) => o.mediaId === e);
1922
1914
  if (F(() => {
1923
- const l = r.current;
1924
- if (!l) return;
1925
- const o = l.getBoundingClientRect();
1926
- let u = t.left + t.width / 2 - o.width / 2;
1927
- u = Math.max(8, Math.min(u, window.innerWidth - o.width - 8));
1928
- let f = t.top - o.height - 8;
1915
+ const o = r.current;
1916
+ if (!o) return;
1917
+ const c = o.getBoundingClientRect();
1918
+ let u = t.left + t.width / 2 - c.width / 2;
1919
+ u = Math.max(8, Math.min(u, window.innerWidth - c.width - 8));
1920
+ let f = t.top - c.height - 8;
1929
1921
  f < 8 && (f = t.bottom + 8), i({ left: Math.round(u), top: Math.round(f) });
1930
1922
  }, [t, e]), !a) return null;
1931
- const c = n.items.find((l) => l.id === e)?.displayName ?? e;
1932
- return Tt(
1923
+ const l = n.items.find((o) => o.id === e)?.displayName ?? e;
1924
+ return It(
1933
1925
  /* @__PURE__ */ k(
1934
1926
  "div",
1935
1927
  {
@@ -1938,19 +1930,19 @@ function qi({
1938
1930
  style: { position: "fixed", left: s?.left ?? -9999, top: s?.top ?? -9999, visibility: s ? "visible" : "hidden" },
1939
1931
  className: "z-[70] w-[220px] pointer-events-none rounded-md border border-border bg-bg-card shadow-lg px-2.5 py-2",
1940
1932
  children: [
1941
- /* @__PURE__ */ d("div", { className: "text-[11px] font-semibold text-text leading-snug pb-1.5 mb-1.5 border-b border-border", children: c }),
1942
- Object.entries(a.votes).map(([l, o]) => /* @__PURE__ */ k("div", { className: "flex items-center gap-2 py-0.5", children: [
1943
- /* @__PURE__ */ d(Qi, { sprite: n.sprites[l], url: n.pictures?.[l] }),
1944
- /* @__PURE__ */ d("span", { className: "flex-1 text-[11px] text-text-secondary truncate", children: n.names[l] ?? "viewer" }),
1933
+ /* @__PURE__ */ d("div", { className: "text-[11px] font-semibold text-text leading-snug pb-1.5 mb-1.5 border-b border-border", children: l }),
1934
+ Object.entries(a.votes).map(([o, c]) => /* @__PURE__ */ k("div", { className: "flex items-center gap-2 py-0.5", children: [
1935
+ /* @__PURE__ */ d(Qi, { sprite: n.sprites[o], url: n.pictures?.[o] }),
1936
+ /* @__PURE__ */ d("span", { className: "flex-1 text-[11px] text-text-secondary truncate", children: n.names[o] ?? "viewer" }),
1945
1937
  /* @__PURE__ */ d(
1946
1938
  "span",
1947
1939
  {
1948
1940
  className: "w-5 h-4 grid place-items-center rounded text-[10px] font-bold shrink-0",
1949
- style: { background: Zt[o], color: "var(--color-tier-ink)" },
1950
- children: o
1941
+ style: { background: Zt[c], color: "var(--color-tier-ink)" },
1942
+ children: c
1951
1943
  }
1952
1944
  )
1953
- ] }, l))
1945
+ ] }, o))
1954
1946
  ]
1955
1947
  }
1956
1948
  ),
@@ -1958,7 +1950,7 @@ function qi({
1958
1950
  );
1959
1951
  }
1960
1952
  function Yi() {
1961
- const t = x((y) => y.tierlistOpen), e = x((y) => y.setTierlistOpen), n = x((y) => y.tierlist), r = x((y) => y.tierlistDraft), s = x((y) => y.tierlistSaving), i = x((y) => y.moveTierlistItem), [a, c] = $(null), [l, o] = $(null), [u, f] = $(null), [h, g] = $(null), [b, p] = $("mine");
1953
+ const t = x((y) => y.tierlistOpen), e = x((y) => y.setTierlistOpen), n = x((y) => y.tierlist), r = x((y) => y.tierlistDraft), s = x((y) => y.tierlistSaving), i = x((y) => y.moveTierlistItem), [a, l] = $(null), [o, c] = $(null), [u, f] = $(null), [p, g] = $(null), [b, h] = $("mine");
1962
1954
  F(() => {
1963
1955
  Sn(!0);
1964
1956
  }, []), F(() => {
@@ -1972,7 +1964,7 @@ function Yi() {
1972
1964
  }, [t, e]);
1973
1965
  const v = Me(() => new Map((n?.items ?? []).map((y) => [y.id, y])), [n]), S = Me(() => {
1974
1966
  const y = { S: [], A: [], B: [], C: [], D: [], F: [], [Ge]: [] }, w = /* @__PURE__ */ new Set();
1975
- for (const C of Nt)
1967
+ for (const C of Lt)
1976
1968
  for (const P of r[C] ?? []) {
1977
1969
  const O = v.get(P);
1978
1970
  O && (y[C].push(O), w.add(P));
@@ -1989,27 +1981,27 @@ function Yi() {
1989
1981
  return O;
1990
1982
  }, R = (y) => ({
1991
1983
  onDragOver: (w) => {
1992
- w.preventDefault(), w.dataTransfer.dropEffect = "move", o(y);
1984
+ w.preventDefault(), w.dataTransfer.dropEffect = "move", c(y);
1993
1985
  },
1994
- onDragLeave: () => o((w) => w === y ? null : w),
1986
+ onDragLeave: () => c((w) => w === y ? null : w),
1995
1987
  onDrop: (w) => {
1996
- w.preventDefault(), o(null);
1988
+ w.preventDefault(), c(null);
1997
1989
  const C = w.dataTransfer.getData("text/plain");
1998
1990
  C && i(C, y === Ge ? null : y, A(w.currentTarget, w.clientX, C));
1999
1991
  },
2000
1992
  onClick: () => {
2001
- a && (i(a, y === Ge ? null : y), c(null));
1993
+ a && (i(a, y === Ge ? null : y), l(null));
2002
1994
  }
2003
1995
  }), _ = j(async () => {
2004
1996
  await js(x.getState().tierlistDraft) && g(Date.now());
2005
1997
  }, []);
2006
1998
  if (F(() => {
2007
- if (h === null) return;
1999
+ if (p === null) return;
2008
2000
  const y = setTimeout(() => g(null), 2500);
2009
2001
  return () => clearTimeout(y);
2010
- }, [h]), !t) return null;
2011
- const m = JSON.stringify(r) !== JSON.stringify(n?.myBoard ?? {}), T = Object.values(n?.myBoard ?? {}).some((y) => (y?.length ?? 0) > 0), L = T ? b : "mine";
2012
- return Tt(
2002
+ }, [p]), !t) return null;
2003
+ const m = JSON.stringify(r) !== JSON.stringify(n?.myBoard ?? {}), T = Object.values(n?.myBoard ?? {}).some((y) => (y?.length ?? 0) > 0), N = T ? b : "mine";
2004
+ return It(
2013
2005
  /* @__PURE__ */ k(
2014
2006
  "div",
2015
2007
  {
@@ -2032,30 +2024,30 @@ function Yi() {
2032
2024
  "button",
2033
2025
  {
2034
2026
  role: "tab",
2035
- "aria-selected": L === y,
2027
+ "aria-selected": N === y,
2036
2028
  className: "tl-tab",
2037
- onClick: () => p(y),
2029
+ onClick: () => h(y),
2038
2030
  children: w
2039
2031
  },
2040
2032
  y
2041
2033
  )) }),
2042
2034
  /* @__PURE__ */ d("div", { className: "flex-1" }),
2043
- h !== null && /* @__PURE__ */ d("span", { className: "text-[11px] bg-success-bg text-on-success-bg px-1.5 py-1 rounded leading-none", children: "Saved" }),
2035
+ p !== null && /* @__PURE__ */ d("span", { className: "text-[11px] bg-success-bg text-on-success-bg px-1.5 py-1 rounded leading-none", children: "Saved" }),
2044
2036
  /* @__PURE__ */ d("button", { className: "tl-save", disabled: s || !m, onClick: () => {
2045
2037
  _();
2046
2038
  }, children: s ? "Saving…" : "Save" }),
2047
2039
  /* @__PURE__ */ d("button", { className: "tl-close", onClick: () => e(!1), "aria-label": "Close tierlist", children: /* @__PURE__ */ d("svg", { className: "w-4 h-4", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", strokeWidth: 2, children: /* @__PURE__ */ d("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "M6 18L18 6M6 6l12 12" }) }) })
2048
2040
  ] }),
2049
2041
  /* @__PURE__ */ k("div", { className: "flex-1 overflow-y-auto", children: [
2050
- L === "mine" && /* @__PURE__ */ k(ye, { children: [
2051
- Nt.map((y) => /* @__PURE__ */ k("div", { className: "grid grid-cols-[56px_1fr] border-b border-border/50 min-h-[86px]", children: [
2042
+ N === "mine" && /* @__PURE__ */ k(ye, { children: [
2043
+ Lt.map((y) => /* @__PURE__ */ k("div", { className: "grid grid-cols-[56px_1fr] border-b border-border/50 min-h-[86px]", children: [
2052
2044
  /* @__PURE__ */ d(
2053
2045
  "div",
2054
2046
  {
2055
2047
  className: "grid place-items-center select-none cursor-pointer",
2056
2048
  style: { background: Zt[y], color: "var(--color-tier-ink)" },
2057
2049
  onClick: () => {
2058
- a && (i(a, y), c(null));
2050
+ a && (i(a, y), l(null));
2059
2051
  },
2060
2052
  title: `Move the picked item to ${y}`,
2061
2053
  children: /* @__PURE__ */ d("span", { className: "text-2xl font-bold leading-none", children: y })
@@ -2065,15 +2057,15 @@ function Yi() {
2065
2057
  "div",
2066
2058
  {
2067
2059
  ...R(y),
2068
- className: `flex items-center gap-2 p-2 overflow-x-auto transition-colors ${l === y ? "bg-primary/15 ring-1 ring-inset ring-primary" : "bg-bg-card"}`,
2060
+ className: `flex items-center gap-2 p-2 overflow-x-auto transition-colors ${o === y ? "bg-primary/15 ring-1 ring-inset ring-primary" : "bg-bg-card"}`,
2069
2061
  children: S[y].map((w) => /* @__PURE__ */ d(
2070
2062
  Pn,
2071
2063
  {
2072
2064
  entry: w,
2073
2065
  draggable: !0,
2074
2066
  picked: a === w.id,
2075
- onPick: () => c((C) => C === w.id ? null : w.id),
2076
- onDragStart: () => c(null)
2067
+ onPick: () => l((C) => C === w.id ? null : w.id),
2068
+ onDragStart: () => l(null)
2077
2069
  },
2078
2070
  w.id
2079
2071
  ))
@@ -2084,22 +2076,22 @@ function Yi() {
2084
2076
  "div",
2085
2077
  {
2086
2078
  ...R(Ge),
2087
- className: `flex items-center gap-2 p-2 overflow-x-auto min-h-[96px] border-t border-dashed border-border transition-colors ${l === Ge ? "bg-primary/15 ring-1 ring-inset ring-primary" : "bg-bg"}`,
2079
+ className: `flex items-center gap-2 p-2 overflow-x-auto min-h-[96px] border-t border-dashed border-border transition-colors ${o === Ge ? "bg-primary/15 ring-1 ring-inset ring-primary" : "bg-bg"}`,
2088
2080
  children: S[Ge].map((y) => /* @__PURE__ */ d(
2089
2081
  Pn,
2090
2082
  {
2091
2083
  entry: y,
2092
2084
  draggable: !0,
2093
2085
  picked: a === y.id,
2094
- onPick: () => c((w) => w === y.id ? null : y.id),
2095
- onDragStart: () => c(null)
2086
+ onPick: () => l((w) => w === y.id ? null : y.id),
2087
+ onDragStart: () => l(null)
2096
2088
  },
2097
2089
  y.id
2098
2090
  ))
2099
2091
  }
2100
2092
  )
2101
2093
  ] }),
2102
- L === "everyone" && n && /* @__PURE__ */ d(ye, { children: Nt.map((y) => {
2094
+ N === "everyone" && n && /* @__PURE__ */ d(ye, { children: Lt.map((y) => {
2103
2095
  const w = n.placed.filter((C) => C.tier === y);
2104
2096
  return /* @__PURE__ */ k("div", { className: "grid grid-cols-[56px_1fr] border-b border-border/50 min-h-[86px]", children: [
2105
2097
  /* @__PURE__ */ d(
@@ -2168,9 +2160,9 @@ function Xi({ children: t }) {
2168
2160
  return F(() => {
2169
2161
  const r = () => n(document.fullscreenElement);
2170
2162
  return r(), document.addEventListener("fullscreenchange", r), () => document.removeEventListener("fullscreenchange", r);
2171
- }, []), e ? Tt(t, e) : /* @__PURE__ */ d(ye, { children: t });
2163
+ }, []), e ? It(t, e) : /* @__PURE__ */ d(ye, { children: t });
2172
2164
  }
2173
- function pl({ className: t = "w-5 h-5" }) {
2165
+ function ml({ className: t = "w-5 h-5" }) {
2174
2166
  return /* @__PURE__ */ d("svg", { className: t, fill: "currentColor", viewBox: "0 0 24 24", "aria-hidden": "true", children: /* @__PURE__ */ d("path", { d: "M12 17.27L18.18 21l-1.64-7.03L22 9.24l-7.19-.61L12 2 9.19 8.63 2 9.24l5.46 4.73L5.82 21z" }) });
2175
2167
  }
2176
2168
  function Zi({ className: t = "w-5 h-5" }) {
@@ -2246,7 +2238,7 @@ function Vr({ site: t = "control bar", className: e = "ctr-btn" }) {
2246
2238
  );
2247
2239
  }
2248
2240
  function po() {
2249
- const t = x((a) => a.chatCollapsed), e = x((a) => a.toggleChatCollapsed), n = x((a) => !!a.snapshot.mediaId), r = It(), s = Ct({ hasMedia: n, chatCollapsed: t, isFullscreen: r });
2241
+ const t = x((a) => a.chatCollapsed), e = x((a) => a.toggleChatCollapsed), n = x((a) => !!a.snapshot.mediaId), r = St(), s = Ct({ hasMedia: n, chatCollapsed: t, isFullscreen: r });
2250
2242
  return { panelHidden: s, toggle: () => {
2251
2243
  if (E("chat", s ? "Show chat" : "Hide chat", { isFullscreen: r, chatCollapsed: t }), !s) {
2252
2244
  e();
@@ -2273,22 +2265,22 @@ function zr({ className: t }) {
2273
2265
  );
2274
2266
  }
2275
2267
  function mo() {
2276
- const t = x((u) => u.chatCollapsed), e = x((u) => !!u.snapshot.mediaId), n = It(), r = Rt(), s = ze(), i = ln(), a = on({
2268
+ const t = x((u) => u.chatCollapsed), e = x((u) => !!u.snapshot.mediaId), n = St(), r = Rt(), s = ze(), i = ln(), a = on({
2277
2269
  isLeader: i,
2278
2270
  hasMedia: e,
2279
2271
  chatCollapsed: t,
2280
2272
  isFullscreen: n,
2281
2273
  gameOverlay: r !== null
2282
- }) === "room-corner", c = s && r !== null && !n, l = Mr({ hasMedia: e, isFullscreen: n, gameOverlay: r !== null }) === "room-corner";
2283
- return !a && !c && !l ? null : /* @__PURE__ */ k("div", { className: "absolute top-2 right-2 z-40 flex items-center gap-2", "data-testid": "room-corner-controls", children: [
2274
+ }) === "room-corner", l = s && r !== null && !n, o = Mr({ hasMedia: e, isFullscreen: n, gameOverlay: r !== null }) === "room-corner";
2275
+ return !a && !l && !o ? null : /* @__PURE__ */ k("div", { className: "absolute top-2 right-2 z-40 flex items-center gap-2", "data-testid": "room-corner-controls", children: [
2284
2276
  a && /* @__PURE__ */ d(Vr, { site: "room corner", className: "corner-btn" }),
2285
- c && /* @__PURE__ */ d("button", { type: "button", onClick: () => {
2277
+ l && /* @__PURE__ */ d("button", { type: "button", onClick: () => {
2286
2278
  E("game", "game_select", { gameId: null, source: "room corner" }), ir(null);
2287
2279
  }, className: "corner-btn", title: "Stop game", "aria-label": "Stop game", children: /* @__PURE__ */ d(uo, {}) }),
2288
- l && /* @__PURE__ */ d(zr, { className: "corner-btn" })
2280
+ o && /* @__PURE__ */ d(zr, { className: "corner-btn" })
2289
2281
  ] });
2290
2282
  }
2291
- const en = "hadoku:avatar", tn = "hadoku:name", go = "hadoku:identity", Mt = /* @__PURE__ */ Symbol.for("hadoku:identity-relay"), Dn = /* @__PURE__ */ Symbol.for("hadoku:identity-relayed");
2283
+ const en = "hadoku:avatar", tn = "hadoku:name", go = "hadoku:identity", kt = /* @__PURE__ */ Symbol.for("hadoku:identity-relay"), Dn = /* @__PURE__ */ Symbol.for("hadoku:identity-relayed");
2292
2284
  function bo() {
2293
2285
  return typeof globalThis.BroadcastChannel > "u" ? null : new globalThis.BroadcastChannel(go);
2294
2286
  }
@@ -2314,18 +2306,18 @@ function vo(t = typeof window > "u" ? void 0 : window, e = bo) {
2314
2306
  if (!t) return () => {
2315
2307
  };
2316
2308
  const n = t;
2317
- let r = n[Mt];
2309
+ let r = n[kt];
2318
2310
  if (!r) {
2319
2311
  const a = e();
2320
2312
  if (!a) return () => {
2321
2313
  };
2322
- r = { count: 0, stop: yo(t, a) }, n[Mt] = r;
2314
+ r = { count: 0, stop: yo(t, a) }, n[kt] = r;
2323
2315
  }
2324
2316
  r.count++;
2325
2317
  const s = r;
2326
2318
  let i = !1;
2327
2319
  return () => {
2328
- i || (i = !0, !(--s.count > 0) && (s.stop(), n[Mt] === s && delete n[Mt]));
2320
+ i || (i = !0, !(--s.count > 0) && (s.stop(), n[kt] === s && delete n[kt]));
2329
2321
  };
2330
2322
  }
2331
2323
  function So() {
@@ -2400,18 +2392,18 @@ async function To(t) {
2400
2392
  I("room", "Room key type probe failed, falling back to socket truth", Y(n));
2401
2393
  }
2402
2394
  }
2403
- function Le(t, e) {
2395
+ function Ne(t, e) {
2404
2396
  const r = x.getState().allocateClientSeq(), s = { kind: t, client_seq: r, ...e || {} };
2405
2397
  return ur().emit(fr.CONTROL, s), r;
2406
2398
  }
2407
- function ml(t) {
2408
- return Le("load", { media_id: t });
2399
+ function gl(t) {
2400
+ return Ne("load", { media_id: t });
2409
2401
  }
2410
2402
  function Io() {
2411
- return Le("home");
2403
+ return Ne("home");
2412
2404
  }
2413
2405
  function Co() {
2414
- const t = Ai(), e = Lr(), n = ze(), r = Nr(), s = n && r && !e.ready, i = !e.ready && !s;
2406
+ const t = Ai(), e = Nr(), n = ze(), r = Lr(), s = n && r && !e.ready, i = !e.ready && !s;
2415
2407
  return /* @__PURE__ */ d(
2416
2408
  "button",
2417
2409
  {
@@ -2427,7 +2419,7 @@ function Co() {
2427
2419
  I("controls", "Play/pause click blocked: not ready", { readyCount: e.readyCount, total: e.total });
2428
2420
  return;
2429
2421
  }
2430
- s && I("controls", "Play/pause: leader overriding stuck readiness gate", { readyCount: e.readyCount, total: e.total }), E("controls", "Play/pause clicked", { action: t.playing ? "pause" : "play" }), Le(t.playing ? "pause" : "play");
2422
+ s && I("controls", "Play/pause: leader overriding stuck readiness gate", { readyCount: e.readyCount, total: e.total }), E("controls", "Play/pause clicked", { action: t.playing ? "pause" : "play" }), Ne(t.playing ? "pause" : "play");
2431
2423
  },
2432
2424
  className: "ctr-btn",
2433
2425
  title: s ? "Some viewers still loading — play anyway" : i ? "Waiting for sync..." : n ? t.playing ? "Pause" : "Play" : "Only the leader can control playback",
@@ -2455,10 +2447,10 @@ function Ro() {
2455
2447
  function Fo(t) {
2456
2448
  return !t.isLeader || t.durationMs === 0 ? !0 : !t.ready && !t.canOverride;
2457
2449
  }
2458
- function Lo(t) {
2450
+ function No(t) {
2459
2451
  return t.localValue !== null ? t.localValue : t.displayPlayheadMs ?? t.snapshotPlayheadMs;
2460
2452
  }
2461
- function No(t, e) {
2453
+ function Lo(t, e) {
2462
2454
  return e <= 0 ? 0 : t / e;
2463
2455
  }
2464
2456
  const Hn = 1e4, Un = 6e4;
@@ -2495,36 +2487,36 @@ function Ut(t) {
2495
2487
  return n > 0 ? `${n}:${r.toString().padStart(2, "0")}:${s.toString().padStart(2, "0")}` : `${r}:${s.toString().padStart(2, "0")}`;
2496
2488
  }
2497
2489
  function Do({ durationMs: t, displayPlayheadMs: e }) {
2498
- const n = x((P) => P.snapshot), r = x((P) => P.readiness), s = ze(), i = Nr(), a = s && i && !r.ready, c = N(null), [l, o] = $(null), [u, f] = $(0), [h, g] = $(!1), [b, p] = $(null), v = N(0), [S, A] = $(n.mediaId);
2499
- S !== n.mediaId && (A(n.mediaId), p(null), g(!1));
2490
+ const n = x((P) => P.snapshot), r = x((P) => P.readiness), s = ze(), i = Lr(), a = s && i && !r.ready, l = L(null), [o, c] = $(null), [u, f] = $(0), [p, g] = $(!1), [b, h] = $(null), v = L(0), [S, A] = $(n.mediaId);
2491
+ S !== n.mediaId && (A(n.mediaId), h(null), g(!1));
2500
2492
  const R = e ?? n.playheadMs;
2501
- !h && b !== null && Math.abs(R - b) < or && p(null);
2502
- const _ = t || 0, m = Lo({ localValue: b, displayPlayheadMs: e, snapshotPlayheadMs: n.playheadMs }), T = N(0);
2493
+ !p && b !== null && Math.abs(R - b) < or && h(null);
2494
+ const _ = t || 0, m = No({ localValue: b, displayPlayheadMs: e, snapshotPlayheadMs: n.playheadMs }), T = L(0);
2503
2495
  F(() => {
2504
- if (h || b === null) return;
2496
+ if (p || b === null) return;
2505
2497
  const P = 1e4 - (Date.now() - T.current), O = setTimeout(() => {
2506
2498
  I("seek", "SeekBar local override timed out — seek never completed", {
2507
2499
  target: Math.round(b),
2508
2500
  actual: Math.round(R),
2509
2501
  delta: Math.round(Math.abs(R - b))
2510
- }), p(null);
2502
+ }), h(null);
2511
2503
  }, Math.max(0, P));
2512
2504
  return () => clearTimeout(O);
2513
- }, [R, h, b]);
2514
- const L = j((P) => {
2505
+ }, [R, p, b]);
2506
+ const N = j((P) => {
2515
2507
  const O = P.currentTarget.getBoundingClientRect(), H = P.clientX - O.left, G = H / O.width, J = Math.round(G * _);
2516
- o(H), f(Math.max(0, Math.min(J, _)));
2508
+ c(H), f(Math.max(0, Math.min(J, _)));
2517
2509
  }, [_]), y = j(() => {
2518
- o(null);
2519
- }, []), w = N(null);
2510
+ c(null);
2511
+ }, []), w = L(null);
2520
2512
  F(() => () => {
2521
2513
  w.current && clearTimeout(w.current);
2522
2514
  }, []);
2523
2515
  const C = j((P) => {
2524
2516
  if (P.defaultPrevented) return;
2525
2517
  const O = $o(P.key, m, _);
2526
- O !== null && (P.preventDefault(), p(O), T.current = Date.now(), w.current && clearTimeout(w.current), w.current = setTimeout(() => {
2527
- w.current = null, E("seek", "Keyboard seek", { to_ms: O }), Le("seek", { to_ms: O }), v.current = O;
2518
+ O !== null && (P.preventDefault(), h(O), T.current = Date.now(), w.current && clearTimeout(w.current), w.current = setTimeout(() => {
2519
+ w.current = null, E("seek", "Keyboard seek", { to_ms: O }), Ne("seek", { to_ms: O }), v.current = O;
2528
2520
  }, Po));
2529
2521
  }, [m, _]);
2530
2522
  return /* @__PURE__ */ k("div", { className: "flex items-center gap-2 flex-1", children: [
@@ -2538,32 +2530,32 @@ function Do({ durationMs: t, displayPlayheadMs: e }) {
2538
2530
  max: _,
2539
2531
  value: m,
2540
2532
  disabled: Fo({ isLeader: s, ready: r.ready, canOverride: a, durationMs: _ }),
2541
- style: { "--progress": `${No(m, _) * 100}%` },
2533
+ style: { "--progress": `${Lo(m, _) * 100}%` },
2542
2534
  onChange: (P) => {
2543
2535
  const O = Number(P.target.value);
2544
- p(O), T.current = Date.now();
2536
+ h(O), T.current = Date.now();
2545
2537
  },
2546
2538
  onMouseDown: () => {
2547
2539
  g(!0), v.current = e ?? n.playheadMs;
2548
2540
  },
2549
2541
  onMouseUp: () => {
2550
- g(!1), b !== null && b !== v.current && (E("seek", "Final seek on mouseup", { to_ms: b }), Le("seek", { to_ms: b }), v.current = b);
2542
+ g(!1), b !== null && b !== v.current && (E("seek", "Final seek on mouseup", { to_ms: b }), Ne("seek", { to_ms: b }), v.current = b);
2551
2543
  },
2552
2544
  onKeyDown: C,
2553
- onMouseMove: L,
2545
+ onMouseMove: N,
2554
2546
  onMouseLeave: () => {
2555
- y(), h && b !== null && b !== v.current && (g(!1), E("seek", "Final seek on mouseleave-while-dragging", { to_ms: b }), Le("seek", { to_ms: b }), v.current = b);
2547
+ y(), p && b !== null && b !== v.current && (g(!1), E("seek", "Final seek on mouseleave-while-dragging", { to_ms: b }), Ne("seek", { to_ms: b }), v.current = b);
2556
2548
  },
2557
2549
  className: "w-full range-fill",
2558
- ref: c,
2550
+ ref: l,
2559
2551
  "aria-label": "Seek bar"
2560
2552
  }
2561
2553
  ),
2562
- l !== null && /* @__PURE__ */ d(
2554
+ o !== null && /* @__PURE__ */ d(
2563
2555
  "div",
2564
2556
  {
2565
2557
  className: "absolute bottom-full mb-2 px-2 py-1 bg-bg-card text-white text-xs rounded pointer-events-none transform -translate-x-1/2 whitespace-nowrap",
2566
- style: { left: l },
2558
+ style: { left: o },
2567
2559
  children: Ut(u)
2568
2560
  }
2569
2561
  )
@@ -2582,7 +2574,7 @@ function Bo({ videoRef: t }) {
2582
2574
  r(f), f > 0 && n && s(!1);
2583
2575
  }, a = () => {
2584
2576
  s(!n);
2585
- }, c = () => n || e === 0 ? /* @__PURE__ */ d(to, {}) : e < 0.5 ? /* @__PURE__ */ d(no, {}) : /* @__PURE__ */ d(ro, {}), l = n ? 0 : e, o = Math.round(l * 100);
2577
+ }, l = () => n || e === 0 ? /* @__PURE__ */ d(to, {}) : e < 0.5 ? /* @__PURE__ */ d(no, {}) : /* @__PURE__ */ d(ro, {}), o = n ? 0 : e, c = Math.round(o * 100);
2586
2578
  return /* @__PURE__ */ k("div", { className: "flex items-center gap-2", children: [
2587
2579
  /* @__PURE__ */ d(
2588
2580
  "button",
@@ -2591,7 +2583,7 @@ function Bo({ videoRef: t }) {
2591
2583
  className: "hover:opacity-80 transition-opacity",
2592
2584
  title: n ? "Unmute" : "Mute",
2593
2585
  "aria-label": n ? "Unmute" : "Mute",
2594
- children: c()
2586
+ children: l()
2595
2587
  }
2596
2588
  ),
2597
2589
  /* @__PURE__ */ d(
@@ -2601,16 +2593,16 @@ function Bo({ videoRef: t }) {
2601
2593
  min: "0",
2602
2594
  max: "1",
2603
2595
  step: "0.05",
2604
- value: l,
2596
+ value: o,
2605
2597
  onChange: i,
2606
- style: { "--progress": `${o}%` },
2598
+ style: { "--progress": `${c}%` },
2607
2599
  className: "range-fill volume-slider",
2608
- title: `Volume: ${o}%`,
2600
+ title: `Volume: ${c}%`,
2609
2601
  "aria-label": "Volume"
2610
2602
  }
2611
2603
  ),
2612
2604
  /* @__PURE__ */ k("span", { className: "text-[10px] opacity-60 w-8 text-right", children: [
2613
- o,
2605
+ c,
2614
2606
  "%"
2615
2607
  ] })
2616
2608
  ] });
@@ -2740,24 +2732,24 @@ function Wo({
2740
2732
  audioTracks: s,
2741
2733
  selectedAudioIndex: i,
2742
2734
  onAudioSelect: a,
2743
- subtitleTracks: c,
2744
- selectedSubtitleIndex: l,
2745
- onSubtitleSelect: o,
2735
+ subtitleTracks: l,
2736
+ selectedSubtitleIndex: o,
2737
+ onSubtitleSelect: c,
2746
2738
  subtitlesEnabled: u,
2747
2739
  onSubtitlesToggle: f,
2748
- subtitleStyle: h,
2740
+ subtitleStyle: p,
2749
2741
  onSubtitleStyleChange: g,
2750
2742
  displayPlayheadMs: b,
2751
- onChatActivity: p,
2743
+ onChatActivity: h,
2752
2744
  onMenuHeld: v
2753
2745
  }) {
2754
- const S = ze(), A = x((z) => z.chatCollapsed), R = It(), _ = ln(), m = Rt() !== null, T = on({
2746
+ const S = ze(), A = x((z) => z.chatCollapsed), R = St(), _ = ln(), m = Rt() !== null, T = on({
2755
2747
  isLeader: _,
2756
2748
  hasMedia: !0,
2757
2749
  chatCollapsed: A,
2758
2750
  isFullscreen: R,
2759
2751
  gameOverlay: m
2760
- }) === "control-bar", L = Mr({ hasMedia: !0, isFullscreen: R, gameOverlay: m }) === "control-bar", y = x((z) => z.floatingChatEnabled), w = N(null), C = N(null), [P, O] = $(!1), [H, G] = $(!1), [J, D] = $(""), [W, X] = $(!1), U = Fr(), [he, ie] = $(!1), [ke, ve] = $(!1), at = j(async (z) => {
2752
+ }) === "control-bar", N = Mr({ hasMedia: !0, isFullscreen: R, gameOverlay: m }) === "control-bar", y = x((z) => z.floatingChatEnabled), w = L(null), C = L(null), [P, O] = $(!1), [H, G] = $(!1), [J, D] = $(""), [W, X] = $(!1), U = Fr(), [he, ie] = $(!1), [ke, ve] = $(!1), at = j(async (z) => {
2761
2753
  if (z.key !== "Enter") return;
2762
2754
  const te = J.trim();
2763
2755
  if (!te && !U.pending.length || W || U.uploading) return;
@@ -2780,7 +2772,7 @@ function Wo({
2780
2772
  z.removeEventListener("scroll", _e), te.disconnect();
2781
2773
  };
2782
2774
  }, [_e, Je]);
2783
- const St = j((z) => {
2775
+ const wt = j((z) => {
2784
2776
  const te = w.current;
2785
2777
  if (!te) return;
2786
2778
  const we = z === "left" ? -200 : 200;
@@ -2827,13 +2819,13 @@ function Wo({
2827
2819
  )
2828
2820
  ] })
2829
2821
  ] }),
2830
- c.length > 0 && /* @__PURE__ */ k("div", { className: "cluster", children: [
2822
+ l.length > 0 && /* @__PURE__ */ k("div", { className: "cluster", children: [
2831
2823
  /* @__PURE__ */ d(
2832
2824
  Ho,
2833
2825
  {
2834
- tracks: c,
2835
- selectedIndex: l,
2836
- onSelect: o,
2826
+ tracks: l,
2827
+ selectedIndex: o,
2828
+ onSelect: c,
2837
2829
  enabled: u,
2838
2830
  onToggle: f
2839
2831
  }
@@ -2841,7 +2833,7 @@ function Wo({
2841
2833
  /* @__PURE__ */ d(
2842
2834
  jo,
2843
2835
  {
2844
- style: h,
2836
+ style: p,
2845
2837
  onStyleChange: g,
2846
2838
  enabled: u
2847
2839
  }
@@ -2874,7 +2866,7 @@ function Wo({
2874
2866
  type: "text",
2875
2867
  value: J,
2876
2868
  onChange: (z) => {
2877
- D(z.target.value.slice(0, ar)), p?.();
2869
+ D(z.target.value.slice(0, ar)), h?.();
2878
2870
  },
2879
2871
  onKeyDown: (z) => {
2880
2872
  at(z);
@@ -2901,7 +2893,7 @@ function Wo({
2901
2893
  }
2902
2894
  ),
2903
2895
  /* @__PURE__ */ k("div", { className: "cluster cluster-tight", children: [
2904
- L && /* @__PURE__ */ d(zr, { className: "ctr-btn" }),
2896
+ N && /* @__PURE__ */ d(zr, { className: "ctr-btn" }),
2905
2897
  /* @__PURE__ */ d(Go, { videoRef: t })
2906
2898
  ] })
2907
2899
  ] }),
@@ -2910,7 +2902,7 @@ function Wo({
2910
2902
  "button",
2911
2903
  {
2912
2904
  className: `ctr-scroll-btn ${P ? "visible" : ""}`,
2913
- onClick: () => St("left"),
2905
+ onClick: () => wt("left"),
2914
2906
  tabIndex: -1,
2915
2907
  "aria-label": "Scroll left",
2916
2908
  children: /* @__PURE__ */ d(io, {})
@@ -2920,7 +2912,7 @@ function Wo({
2920
2912
  "button",
2921
2913
  {
2922
2914
  className: `ctr-scroll-btn ${H ? "visible" : ""}`,
2923
- onClick: () => St("right"),
2915
+ onClick: () => wt("right"),
2924
2916
  tabIndex: -1,
2925
2917
  "aria-label": "Scroll right",
2926
2918
  children: /* @__PURE__ */ d(oo, {})
@@ -3026,8 +3018,8 @@ function Gn(t, e) {
3026
3018
  function ic(t, e, n, r) {
3027
3019
  const s = t * 1e3 - 100, i = e * 1e3 + 100;
3028
3020
  for (const a of r) {
3029
- const c = n[a];
3030
- if (c && c.start_ms < i && c.end_ms > s)
3021
+ const l = n[a];
3022
+ if (l && l.start_ms < i && l.end_ms > s)
3031
3023
  return !0;
3032
3024
  }
3033
3025
  return !1;
@@ -3042,37 +3034,37 @@ function oc(t) {
3042
3034
  for (; r < n.length; ) {
3043
3035
  const s = n[r].trim();
3044
3036
  if (s.includes("-->")) {
3045
- const i = s.split("-->"), a = Wn(i[0].trim()), c = i[1].trim().split(/\s+/), l = Wn(c[0]);
3046
- let o, u, f;
3047
- for (let g = 1; g < c.length; g++) {
3048
- const b = c[g];
3037
+ const i = s.split("-->"), a = Wn(i[0].trim()), l = i[1].trim().split(/\s+/), o = Wn(l[0]);
3038
+ let c, u, f;
3039
+ for (let g = 1; g < l.length; g++) {
3040
+ const b = l[g];
3049
3041
  if (b.startsWith("line:")) {
3050
- const p = b.slice(5);
3051
- if (p.endsWith("%")) {
3052
- const v = parseFloat(p.slice(0, -1));
3053
- isNaN(v) || (o = v / 100);
3042
+ const h = b.slice(5);
3043
+ if (h.endsWith("%")) {
3044
+ const v = parseFloat(h.slice(0, -1));
3045
+ isNaN(v) || (c = v / 100);
3054
3046
  }
3055
3047
  } else if (b.startsWith("position:")) {
3056
- const p = b.slice(9);
3057
- if (p.endsWith("%")) {
3058
- const v = parseFloat(p.slice(0, -1));
3048
+ const h = b.slice(9);
3049
+ if (h.endsWith("%")) {
3050
+ const v = parseFloat(h.slice(0, -1));
3059
3051
  isNaN(v) || (u = v / 100);
3060
3052
  }
3061
3053
  } else if (b.startsWith("align:")) {
3062
- const p = b.slice(6);
3063
- (p === "start" || p === "center" || p === "end") && (f = p);
3054
+ const h = b.slice(6);
3055
+ (h === "start" || h === "center" || h === "end") && (f = h);
3064
3056
  }
3065
3057
  }
3066
- const h = [];
3058
+ const p = [];
3067
3059
  for (r++; r < n.length && n[r].trim() !== ""; )
3068
- h.push(n[r].trim()), r++;
3069
- a !== null && l !== null && h.length > 0 && e.push({
3060
+ p.push(n[r].trim()), r++;
3061
+ a !== null && o !== null && p.length > 0 && e.push({
3070
3062
  id: `cue-${e.length}`,
3071
3063
  startTime: a,
3072
- endTime: l,
3073
- text: h.join(`
3064
+ endTime: o,
3065
+ text: p.join(`
3074
3066
  `),
3075
- linePercent: o,
3067
+ linePercent: c,
3076
3068
  positionPercent: u,
3077
3069
  align: f
3078
3070
  });
@@ -3101,13 +3093,13 @@ const lc = {
3101
3093
  contrast: "text-white font-bold bg-black px-3 py-1"
3102
3094
  };
3103
3095
  function dc({ subtitleUrl: t, videoRef: e, style: n, enabled: r }) {
3104
- const [s, i] = $([]), [a, c] = $([]), l = N(null), [o, u] = $(40), [f, h] = $(18), [g, b] = $(t);
3096
+ const [s, i] = $([]), [a, l] = $([]), o = L(null), [c, u] = $(40), [f, p] = $(18), [g, b] = $(t);
3105
3097
  g !== t && (b(t), t || i([])), F(() => {
3106
3098
  if (!t) return;
3107
3099
  let m = !1;
3108
3100
  const T = 2;
3109
3101
  return (async () => {
3110
- for (let L = 0; L <= T; L++) {
3102
+ for (let N = 0; N <= T; N++) {
3111
3103
  if (m) return;
3112
3104
  try {
3113
3105
  const y = await fetch(t);
@@ -3119,53 +3111,53 @@ function dc({ subtitleUrl: t, videoRef: e, style: n, enabled: r }) {
3119
3111
  return;
3120
3112
  } catch (y) {
3121
3113
  if (m) return;
3122
- if (L < T) {
3123
- const w = ht(L + 1, { baseMs: 1e3, capMs: 2e3, jitter: 0 });
3124
- I("subtitles", `Fetch failed, retrying in ${w}ms (attempt ${L + 1}/${T + 1})`, { error: y?.message }), await new Promise((C) => setTimeout(C, w));
3114
+ if (N < T) {
3115
+ const w = ht(N + 1, { baseMs: 1e3, capMs: 2e3, jitter: 0 });
3116
+ I("subtitles", `Fetch failed, retrying in ${w}ms (attempt ${N + 1}/${T + 1})`, { error: y?.message }), await new Promise((C) => setTimeout(C, w));
3125
3117
  } else
3126
3118
  I("subtitles", "All fetch attempts failed", { error: y?.message }), i([]);
3127
3119
  }
3128
3120
  }
3129
- })().catch((L) => ee("subtitles", "Subtitle load threw", Y(L))), () => {
3121
+ })().catch((N) => ee("subtitles", "Subtitle load threw", Y(N))), () => {
3130
3122
  m = !0;
3131
3123
  };
3132
3124
  }, [t]);
3133
- const p = j(() => {
3125
+ const h = j(() => {
3134
3126
  const m = e.current;
3135
3127
  if (!m || !r || s.length === 0) {
3136
- c([]);
3128
+ l([]);
3137
3129
  return;
3138
3130
  }
3139
- const T = m.currentTime, L = s.filter(
3131
+ const T = m.currentTime, N = s.filter(
3140
3132
  (y) => T >= y.startTime && T < y.endTime
3141
3133
  );
3142
- c(L);
3134
+ l(N);
3143
3135
  }, [e, r, s]);
3144
3136
  F(() => {
3145
3137
  const m = e.current;
3146
3138
  if (!m) return;
3147
- const T = () => p();
3139
+ const T = () => h();
3148
3140
  return m.addEventListener("timeupdate", T), m.addEventListener("seeked", T), () => {
3149
3141
  m.removeEventListener("timeupdate", T), m.removeEventListener("seeked", T);
3150
3142
  };
3151
- }, [e, p]);
3143
+ }, [e, h]);
3152
3144
  const v = a.length > 0;
3153
3145
  if (F(() => {
3154
- const m = e.current, T = l.current?.parentElement;
3146
+ const m = e.current, T = o.current?.parentElement;
3155
3147
  if (!m || !T) return;
3156
- const L = () => {
3148
+ const N = () => {
3157
3149
  const y = T.clientHeight, w = T.clientWidth, C = m.videoWidth || 1920, P = m.videoHeight || 1080, O = Math.min(w / C, y / P), H = P * O, G = (y - H) / 2, J = Math.max(16, H * 0.035), D = Math.max(J * 0.8, H * 0.055);
3158
- u(Math.max(G + D, 40)), h(J);
3150
+ u(Math.max(G + D, 40)), p(J);
3159
3151
  };
3160
- return L(), window.addEventListener("resize", L), m.addEventListener("loadedmetadata", L), () => {
3161
- window.removeEventListener("resize", L), m.removeEventListener("loadedmetadata", L);
3152
+ return N(), window.addEventListener("resize", N), m.addEventListener("loadedmetadata", N), () => {
3153
+ window.removeEventListener("resize", N), m.removeEventListener("loadedmetadata", N);
3162
3154
  };
3163
3155
  }, [e, v]), !r || a.length === 0)
3164
3156
  return null;
3165
3157
  function S(m) {
3166
3158
  const T = m.linePercent !== void 0 && m.linePercent <= 0.5;
3167
- let L = "c";
3168
- return m.align === "start" ? L = "l" : m.align === "end" ? L = "r" : m.positionPercent !== void 0 && (m.positionPercent < 0.3 ? L = "l" : m.positionPercent > 0.7 && (L = "r")), (T ? "t" : "b") + L;
3159
+ let N = "c";
3160
+ return m.align === "start" ? N = "l" : m.align === "end" ? N = "r" : m.positionPercent !== void 0 && (m.positionPercent < 0.3 ? N = "l" : m.positionPercent > 0.7 && (N = "r")), (T ? "t" : "b") + N;
3169
3161
  }
3170
3162
  const A = {
3171
3163
  tl: [],
@@ -3176,7 +3168,7 @@ function dc({ subtitleUrl: t, videoRef: e, style: n, enabled: r }) {
3176
3168
  br: []
3177
3169
  };
3178
3170
  for (const m of a) A[S(m)].push(m);
3179
- const R = (m, T, L) => m.map((y) => /* @__PURE__ */ d(
3171
+ const R = (m, T, N) => m.map((y) => /* @__PURE__ */ d(
3180
3172
  "div",
3181
3173
  {
3182
3174
  className: `flex flex-col ${T} w-full`,
@@ -3184,13 +3176,13 @@ function dc({ subtitleUrl: t, videoRef: e, style: n, enabled: r }) {
3184
3176
  children: /* @__PURE__ */ d(
3185
3177
  "div",
3186
3178
  {
3187
- className: `${L} font-medium max-w-[95%] inline-block antialiased ${lc[n]}`,
3179
+ className: `${N} font-medium max-w-[95%] inline-block antialiased ${lc[n]}`,
3188
3180
  children: cc(y.text)
3189
3181
  }
3190
3182
  )
3191
3183
  },
3192
3184
  y.id
3193
- )), _ = (m, T, L, y, w) => /* @__PURE__ */ k(ye, { children: [
3185
+ )), _ = (m, T, N, y, w) => /* @__PURE__ */ k(ye, { children: [
3194
3186
  m.length > 0 && /* @__PURE__ */ d(
3195
3187
  "div",
3196
3188
  {
@@ -3208,18 +3200,18 @@ function dc({ subtitleUrl: t, videoRef: e, style: n, enabled: r }) {
3208
3200
  children: R(T, "items-center", "text-center")
3209
3201
  }
3210
3202
  ),
3211
- L.length > 0 && /* @__PURE__ */ d(
3203
+ N.length > 0 && /* @__PURE__ */ d(
3212
3204
  "div",
3213
3205
  {
3214
3206
  className: "absolute right-0 flex flex-col items-end gap-2 pointer-events-none z-10 px-3 max-w-[35%]",
3215
3207
  style: y,
3216
- children: R(L, "items-end", "text-right")
3208
+ children: R(N, "items-end", "text-right")
3217
3209
  }
3218
3210
  )
3219
3211
  ] });
3220
3212
  return /* @__PURE__ */ k(ye, { children: [
3221
- _(A.tl, A.tc, A.tr, { top: `${o}px` }),
3222
- _(A.bl, A.bc, A.br, { bottom: `${o}px` }, l)
3213
+ _(A.tl, A.tc, A.tr, { top: `${c}px` }),
3214
+ _(A.bl, A.bc, A.br, { bottom: `${c}px` }, o)
3223
3215
  ] });
3224
3216
  }
3225
3217
  const uc = 300, fc = 50, hc = 100, pc = 100, mc = 100, gc = 100;
@@ -3342,11 +3334,11 @@ class bc {
3342
3334
  }
3343
3335
  // ── Reporting ─────────────────────────────────────────────────────────────
3344
3336
  report() {
3345
- const e = this._fetches.map((o) => o.durationMs), n = this._fetches.filter((o) => o.bytes > 0 && o.durationMs > 0).map((o) => Math.round(o.bytes / o.durationMs * 1e3)), r = this._appends.map((o) => o.latencyMs), s = this._appends.map((o) => o.queueDepth), i = this._seeks.map((o) => o.durationMs), a = this._stalls.map((o) => o.durationMs), c = {};
3346
- for (const o of this._seeks)
3347
- (c[o.caller] ??= []).push(o.durationMs);
3348
- const l = Object.fromEntries(
3349
- Object.entries(c).map(([o, u]) => [o, $e(u)])
3337
+ const e = this._fetches.map((c) => c.durationMs), n = this._fetches.filter((c) => c.bytes > 0 && c.durationMs > 0).map((c) => Math.round(c.bytes / c.durationMs * 1e3)), r = this._appends.map((c) => c.latencyMs), s = this._appends.map((c) => c.queueDepth), i = this._seeks.map((c) => c.durationMs), a = this._stalls.map((c) => c.durationMs), l = {};
3338
+ for (const c of this._seeks)
3339
+ (l[c.caller] ??= []).push(c.durationMs);
3340
+ const o = Object.fromEntries(
3341
+ Object.entries(l).map(([c, u]) => [c, $e(u)])
3350
3342
  );
3351
3343
  return {
3352
3344
  fetch: {
@@ -3359,22 +3351,22 @@ class bc {
3359
3351
  queueDepth: $e(s),
3360
3352
  latencyMs: $e(r),
3361
3353
  timeoutCount: this._appendTimeouts.length,
3362
- timeouts: this._appendTimeouts.slice(-10).map((o) => ({
3363
- index: o.index,
3364
- timeoutMs: o.timeoutMs,
3365
- queueDepth: o.queueDepth
3354
+ timeouts: this._appendTimeouts.slice(-10).map((c) => ({
3355
+ index: c.index,
3356
+ timeoutMs: c.timeoutMs,
3357
+ queueDepth: c.queueDepth
3366
3358
  }))
3367
3359
  },
3368
3360
  seek: {
3369
3361
  count: this._seeks.length,
3370
3362
  durationMs: $e(i),
3371
- byCaller: l,
3363
+ byCaller: o,
3372
3364
  waitForSeekedTimeouts: this._waitForSeekedTimeouts
3373
3365
  },
3374
3366
  audio: {
3375
3367
  driftMs: $e(this._audioDrifts),
3376
- highDriftCount: this._audioDrifts.filter((o) => o > gc).length,
3377
- samples: this._audioDrifts.slice(-20).map((o) => Math.round(o))
3368
+ highDriftCount: this._audioDrifts.filter((c) => c > gc).length,
3369
+ samples: this._audioDrifts.slice(-20).map((c) => Math.round(c))
3378
3370
  },
3379
3371
  stalls: {
3380
3372
  count: this._stalls.length + (this._stallStart ? 1 : 0),
@@ -3388,32 +3380,32 @@ class bc {
3388
3380
  evictions: { ...this._evictCounts },
3389
3381
  browserEviction: {
3390
3382
  detectionCount: this._browserEvictions.length,
3391
- fragmentsAffected: this._browserEvictions.reduce((o, u) => o + u.fragmentCount, 0),
3392
- recent: this._browserEvictions.slice(-10).map((o) => ({
3393
- fragmentCount: o.fragmentCount,
3394
- survivingRanges: o.survivingRanges
3383
+ fragmentsAffected: this._browserEvictions.reduce((c, u) => c + u.fragmentCount, 0),
3384
+ recent: this._browserEvictions.slice(-10).map((c) => ({
3385
+ fragmentCount: c.fragmentCount,
3386
+ survivingRanges: c.survivingRanges
3395
3387
  }))
3396
3388
  },
3397
3389
  raw: {
3398
- fetches: this._fetches.slice(-20).map((o) => ({
3399
- index: o.index,
3400
- bytes: o.bytes,
3401
- durationMs: Math.round(o.durationMs)
3390
+ fetches: this._fetches.slice(-20).map((c) => ({
3391
+ index: c.index,
3392
+ bytes: c.bytes,
3393
+ durationMs: Math.round(c.durationMs)
3402
3394
  })),
3403
- seeks: this._seeks.slice(-10).map((o) => ({
3404
- caller: o.caller,
3405
- targetMs: Math.round(o.targetMs),
3406
- durationMs: o.durationMs
3395
+ seeks: this._seeks.slice(-10).map((c) => ({
3396
+ caller: c.caller,
3397
+ targetMs: Math.round(c.targetMs),
3398
+ durationMs: c.durationMs
3407
3399
  })),
3408
- audioDrifts: this._audioDrifts.slice(-10).map((o) => Math.round(o)),
3409
- stalls: this._stalls.slice(-5).map((o) => ({
3410
- currentMs: Math.round(o.currentMs),
3411
- aheadMs: Math.round(o.aheadMs),
3412
- durationMs: o.durationMs
3400
+ audioDrifts: this._audioDrifts.slice(-10).map((c) => Math.round(c)),
3401
+ stalls: this._stalls.slice(-5).map((c) => ({
3402
+ currentMs: Math.round(c.currentMs),
3403
+ aheadMs: Math.round(c.aheadMs),
3404
+ durationMs: c.durationMs
3413
3405
  })),
3414
- evictions: this._evicts.slice(-10).map((o) => ({
3415
- reason: o.reason,
3416
- range: `${o.start.toFixed(1)}-${o.end.toFixed(1)}`
3406
+ evictions: this._evicts.slice(-10).map((c) => ({
3407
+ reason: c.reason,
3408
+ range: `${c.start.toFixed(1)}-${c.end.toFixed(1)}`
3417
3409
  }))
3418
3410
  }
3419
3411
  };
@@ -3560,20 +3552,20 @@ class Sc {
3560
3552
  if (!n || n.updating || this.deps.isDisposed() || !xe(r) || this.clearIfStuck()) return;
3561
3553
  this.pendingEvictionMs = e;
3562
3554
  const s = e / 1e3, i = n.buffered;
3563
- for (let c = 0; c < i.length; c++) {
3564
- const l = i.end(c);
3565
- if (!(l >= s - 5 || (c < i.length - 1 ? i.start(c + 1) : 1 / 0) - l <= Z.RANGE)) {
3566
- E("buffer", `EVICT-SEEK-GAP [backward] range=${i.start(c).toFixed(2)}-${l.toFixed(2)} targetSec=${s.toFixed(2)}`), this._doEvict(i.start(c), l, "seek-gap-backward");
3555
+ for (let l = 0; l < i.length; l++) {
3556
+ const o = i.end(l);
3557
+ if (!(o >= s - 5 || (l < i.length - 1 ? i.start(l + 1) : 1 / 0) - o <= Z.RANGE)) {
3558
+ E("buffer", `EVICT-SEEK-GAP [backward] range=${i.start(l).toFixed(2)}-${o.toFixed(2)} targetSec=${s.toFixed(2)}`), this._doEvict(i.start(l), o, "seek-gap-backward");
3567
3559
  return;
3568
3560
  }
3569
3561
  }
3570
3562
  const a = s + tt / 1e3;
3571
- for (let c = 0; c < i.length; c++) {
3572
- const l = i.start(c);
3573
- if (l <= a) continue;
3574
- const o = c > 0 ? i.end(c - 1) : 0;
3575
- if (!(l - o <= Z.FALLBACK)) {
3576
- E("buffer", `EVICT-SEEK-GAP [forward] range=${l.toFixed(2)}-${i.end(c).toFixed(2)} threshold=${a.toFixed(2)}`), this._doEvict(l, i.end(c), "seek-gap-forward");
3563
+ for (let l = 0; l < i.length; l++) {
3564
+ const o = i.start(l);
3565
+ if (o <= a) continue;
3566
+ const c = l > 0 ? i.end(l - 1) : 0;
3567
+ if (!(o - c <= Z.FALLBACK)) {
3568
+ E("buffer", `EVICT-SEEK-GAP [forward] range=${o.toFixed(2)}-${i.end(l).toFixed(2)} threshold=${a.toFixed(2)}`), this._doEvict(o, i.end(l), "seek-gap-forward");
3577
3569
  return;
3578
3570
  }
3579
3571
  }
@@ -3584,19 +3576,19 @@ class Sc {
3584
3576
  this.pendingEvictionMs = e;
3585
3577
  const n = this.deps.getSourceBuffer(), r = this.deps.getMediaSource();
3586
3578
  if (!n || n.updating || this.deps.isDisposed() || !xe(r) || this.clearIfStuck()) return;
3587
- const s = e / 1e3, i = n.buffered, a = this.deps.getPendingSeekTargetMs(), c = a === null ? null : a / 1e3;
3588
- for (let l = 0; l < i.length; l++) {
3589
- const o = i.start(l), u = i.end(l);
3590
- if (o < s - Kn && u > s) {
3579
+ const s = e / 1e3, i = n.buffered, a = this.deps.getPendingSeekTargetMs(), l = a === null ? null : a / 1e3;
3580
+ for (let o = 0; o < i.length; o++) {
3581
+ const c = i.start(o), u = i.end(o);
3582
+ if (c < s - Kn && u > s) {
3591
3583
  const v = s - Kn;
3592
- E("buffer", `EVICT-START [behind-tail-trim] range=${o.toFixed(2)}-${u.toFixed(2)} → trim [${o.toFixed(2)}-${v.toFixed(2)}] playhead=${s.toFixed(2)}`), this._doEvict(o, v, "behind-tail-trim");
3584
+ E("buffer", `EVICT-START [behind-tail-trim] range=${c.toFixed(2)}-${u.toFixed(2)} → trim [${c.toFixed(2)}-${v.toFixed(2)}] playhead=${s.toFixed(2)}`), this._doEvict(c, v, "behind-tail-trim");
3593
3585
  return;
3594
3586
  }
3595
- if (o < 0.5 && u > s || c !== null && u > c - Z.FALLBACK && o < c + tt / 1e3) continue;
3596
- const f = u < s - 25, h = o > s + 4 * tt / 1e3, g = l < i.length - 1 ? i.start(l + 1) - u : 0, b = u < s - 25 && g > 5, p = o > s + tt / 1e3 && (l === 0 || i.end(l - 1) < o - Z.FALLBACK);
3597
- if (f || h || b || p) {
3598
- const v = f ? "behind" : h ? "far-ahead-island" : b ? "orphaned-gap" : "forward-orphan";
3599
- E("buffer", `EVICT-START [${v}] range=${o.toFixed(2)}-${u.toFixed(2)} playhead=${s.toFixed(2)}`), this._doEvict(o, u, v);
3587
+ if (c < 0.5 && u > s || l !== null && u > l - Z.FALLBACK && c < l + tt / 1e3) continue;
3588
+ const f = u < s - 25, p = c > s + 4 * tt / 1e3, g = o < i.length - 1 ? i.start(o + 1) - u : 0, b = u < s - 25 && g > 5, h = c > s + tt / 1e3 && (o === 0 || i.end(o - 1) < c - Z.FALLBACK);
3589
+ if (f || p || b || h) {
3590
+ const v = f ? "behind" : p ? "far-ahead-island" : b ? "orphaned-gap" : "forward-orphan";
3591
+ E("buffer", `EVICT-START [${v}] range=${c.toFixed(2)}-${u.toFixed(2)} playhead=${s.toFixed(2)}`), this._doEvict(c, u, v);
3600
3592
  return;
3601
3593
  }
3602
3594
  }
@@ -3609,10 +3601,10 @@ class Sc {
3609
3601
  if (!s) return;
3610
3602
  de.recordEvict(r, e, n);
3611
3603
  const i = this.deps.getFragments();
3612
- for (const [a, c] of this.deps.fragmentStates) {
3613
- if (c !== "loaded") continue;
3614
- const l = i[a];
3615
- l && l.start_ms / 1e3 < n + Z.RANGE && l.end_ms / 1e3 > e - Z.RANGE && this.deps.fragmentStates.set(a, "pending");
3604
+ for (const [a, l] of this.deps.fragmentStates) {
3605
+ if (l !== "loaded") continue;
3606
+ const o = i[a];
3607
+ o && o.start_ms / 1e3 < n + Z.RANGE && o.end_ms / 1e3 > e - Z.RANGE && this.deps.fragmentStates.set(a, "pending");
3616
3608
  }
3617
3609
  this._isEvicting = !0, this.evictStartedAt = Date.now();
3618
3610
  try {
@@ -3824,12 +3816,12 @@ class nt {
3824
3816
  const i = performance.now(), a = await fetch(s, {
3825
3817
  headers: { "X-Buffer-Ahead-Ms": String(Math.round(this.getBufferedAheadMs(this.currentPlayheadMs))) },
3826
3818
  signal: r
3827
- }), c = Math.round(performance.now() - i);
3819
+ }), l = Math.round(performance.now() - i);
3828
3820
  if (a.status !== 200)
3829
3821
  return await a.body?.cancel().catch(() => {
3830
3822
  }), this.disableFragmentRoute(e, `HTTP ${a.status}`), null;
3831
- const l = await a.arrayBuffer();
3832
- return l.byteLength !== n ? (this.disableFragmentRoute(e, `length ${l.byteLength} != expected ${n}`), null) : (this.fragmentRouteHits++, { buf: l, ttfbMs: c, cfStatus: a.headers.get("cf-cache-status") || a.headers.get("x-cache") || "" });
3823
+ const o = await a.arrayBuffer();
3824
+ return o.byteLength !== n ? (this.disableFragmentRoute(e, `length ${o.byteLength} != expected ${n}`), null) : (this.fragmentRouteHits++, { buf: o, ttfbMs: l, cfStatus: a.headers.get("cf-cache-status") || a.headers.get("x-cache") || "" });
3833
3825
  } catch (i) {
3834
3826
  return i?.name === "AbortError" || this.disableFragmentRoute(e, i?.message || "fetch threw"), null;
3835
3827
  }
@@ -3846,7 +3838,7 @@ class nt {
3846
3838
  this.currentPlayheadMs = e;
3847
3839
  }
3848
3840
  setIndex(e, n, r, s = "", i = null) {
3849
- this.fragments = e, this.mediaUrl = n, this.mediaId = s, this.delivery = i, this.fragmentRouteDisabled = !1, this.fragmentRouteHits = 0, this.fragmentStates.clear(), this.errorTimestamps.clear(), this.discardCounts.clear(), this.fetchErrorCycles.clear(), this.appendHold = null, e.forEach((a, c) => this.fragmentStates.set(c, "pending")), this.initRange = r ?? null, this.initState = "pending", this.initRetryCount = 0, this.initFailed = !1, this.loadStartTs = performance.now(), this.initFetchStart = 0, this.initFetchEnd = 0, this.initAppendDone = 0, this.initTtfbMs = -1, this.initCfStatus = "", this.fragInitTimings.clear(), this.initHoldCounts = { byPendingFetch: 0, byInProgressAppend: 0, byInit: 0 }, this.initDigestEmitted = !1;
3841
+ this.fragments = e, this.mediaUrl = n, this.mediaId = s, this.delivery = i, this.fragmentRouteDisabled = !1, this.fragmentRouteHits = 0, this.fragmentStates.clear(), this.errorTimestamps.clear(), this.discardCounts.clear(), this.fetchErrorCycles.clear(), this.appendHold = null, e.forEach((a, l) => this.fragmentStates.set(l, "pending")), this.initRange = r ?? null, this.initState = "pending", this.initRetryCount = 0, this.initFailed = !1, this.loadStartTs = performance.now(), this.initFetchStart = 0, this.initFetchEnd = 0, this.initAppendDone = 0, this.initTtfbMs = -1, this.initCfStatus = "", this.fragInitTimings.clear(), this.initHoldCounts = { byPendingFetch: 0, byInProgressAppend: 0, byInit: 0 }, this.initDigestEmitted = !1;
3850
3842
  }
3851
3843
  /** True while we should record per-fragment init timings. We track only the
3852
3844
  * first INIT_TRACK_FRAGS distinct indices and stop after the digest fires
@@ -3888,26 +3880,26 @@ class nt {
3888
3880
  this.initState = "loading", this.initFetchStart = performance.now();
3889
3881
  const { start_byte: e, end_byte: n } = this.initRange, r = this.mediaId, s = this.mediaUrl, i = this.sourceBuffer, a = () => this.disposed || this.mediaId !== r || this.mediaUrl !== s || this.sourceBuffer !== i;
3890
3882
  try {
3891
- let c;
3892
- const l = r ? Se.getInit(r) : void 0;
3893
- if (l)
3894
- E("buffer", `INIT-CACHE-HIT bytes=${e}-${n}`), c = l;
3883
+ let l;
3884
+ const o = r ? Se.getInit(r) : void 0;
3885
+ if (o)
3886
+ E("buffer", `INIT-CACHE-HIT bytes=${e}-${n}`), l = o;
3895
3887
  else {
3896
3888
  E("buffer", `INIT-FETCH bytes=${e}-${n} (${n - e + 1}B)`);
3897
- const o = await this.tryFragmentRoute(
3889
+ const c = await this.tryFragmentRoute(
3898
3890
  "init",
3899
3891
  n - e + 1,
3900
3892
  AbortSignal.timeout(ut(this.getAverageDownloadRate()))
3901
3893
  );
3902
- if (o) {
3903
- if (this.initTtfbMs = o.ttfbMs, this.initCfStatus = o.cfStatus, c = o.buf, a()) {
3894
+ if (c) {
3895
+ if (this.initTtfbMs = c.ttfbMs, this.initCfStatus = c.cfStatus, l = c.buf, a()) {
3904
3896
  I("buffer", "INIT-FETCH stale on completion, discarding bytes", {
3905
3897
  expectedMediaId: r,
3906
3898
  currentMediaId: this.mediaId
3907
3899
  });
3908
3900
  return;
3909
3901
  }
3910
- r && Se.storeInit(r, c);
3902
+ r && Se.storeInit(r, l);
3911
3903
  } else {
3912
3904
  const u = performance.now(), f = await fetch(s, {
3913
3905
  headers: { Range: `bytes=${e}-${n}` },
@@ -3917,39 +3909,39 @@ class nt {
3917
3909
  if (f.status !== 206)
3918
3910
  throw await f.body?.cancel().catch(() => {
3919
3911
  }), new Error(`init expected 206, got ${f.status}`);
3920
- if (c = await f.arrayBuffer(), a()) {
3912
+ if (l = await f.arrayBuffer(), a()) {
3921
3913
  I("buffer", "INIT-FETCH stale on completion, discarding bytes", {
3922
3914
  expectedMediaId: r,
3923
3915
  currentMediaId: this.mediaId
3924
3916
  });
3925
3917
  return;
3926
3918
  }
3927
- r && Se.storeInit(r, c);
3919
+ r && Se.storeInit(r, l);
3928
3920
  }
3929
3921
  }
3930
3922
  if (this.initFetchEnd = performance.now(), a()) {
3931
3923
  E("buffer", "INIT skip append — media drifted before sb.appendBuffer");
3932
3924
  return;
3933
3925
  }
3934
- if (await new Promise((o, u) => {
3935
- const f = i, h = () => {
3936
- f.removeEventListener("updateend", h), f.removeEventListener("error", g), o();
3926
+ if (await new Promise((c, u) => {
3927
+ const f = i, p = () => {
3928
+ f.removeEventListener("updateend", p), f.removeEventListener("error", g), c();
3937
3929
  }, g = (b) => {
3938
- f.removeEventListener("updateend", h), f.removeEventListener("error", g), u(b);
3930
+ f.removeEventListener("updateend", p), f.removeEventListener("error", g), u(b);
3939
3931
  };
3940
- f.addEventListener("updateend", h), f.addEventListener("error", g), f.appendBuffer(c);
3932
+ f.addEventListener("updateend", p), f.addEventListener("error", g), f.appendBuffer(l);
3941
3933
  }), a()) {
3942
3934
  E("buffer", "INIT append completed for stale media, ignoring");
3943
3935
  return;
3944
3936
  }
3945
3937
  this.initAppendDone = performance.now(), this.initState = "loaded", this.initRetryCount = 0, E("buffer", `INIT-LOADED sbRanges=[${ge(this.sourceBuffer?.buffered).join(", ")}]`), this.processAppendQueue();
3946
- } catch (c) {
3947
- ee("buffer", "Init segment fetch/append failed", { error: c.message }), a() || (this.initState = "pending", this.initRetryCount += 1, this.initRetryCount >= Ys ? (this.initFailed = !0, I("buffer", "INIT-GIVE-UP — init segment failed repeatedly; rejecting waiters for fast recovery", {
3938
+ } catch (l) {
3939
+ ee("buffer", "Init segment fetch/append failed", { error: l.message }), a() || (this.initState = "pending", this.initRetryCount += 1, this.initRetryCount >= Ys ? (this.initFailed = !0, I("buffer", "INIT-GIVE-UP — init segment failed repeatedly; rejecting waiters for fast recovery", {
3948
3940
  attempts: this.initRetryCount,
3949
- error: c.message
3941
+ error: l.message
3950
3942
  }), this.rejectAllWaiters(new Error("init segment failed after repeated retries"))) : this.disposed || setTimeout(() => {
3951
- !this.disposed && this.initState === "pending" && this.fetchInit().catch((l) => {
3952
- ee("buffer", "INIT-RETRY failed", Y(l));
3943
+ !this.disposed && this.initState === "pending" && this.fetchInit().catch((o) => {
3944
+ ee("buffer", "INIT-RETRY failed", Y(o));
3953
3945
  });
3954
3946
  }, Xs));
3955
3947
  }
@@ -3983,9 +3975,9 @@ class nt {
3983
3975
  break;
3984
3976
  }
3985
3977
  if (!s) {
3986
- const a = r.start_ms / 1e3, c = r.end_ms / 1e3;
3987
- for (let l = 0; l < e.buffered.length; l++)
3988
- if (e.buffered.start(l) <= a + Z.RANGE && e.buffered.end(l) >= c - Z.RANGE) {
3978
+ const a = r.start_ms / 1e3, l = r.end_ms / 1e3;
3979
+ for (let o = 0; o < e.buffered.length; o++)
3980
+ if (e.buffered.start(o) <= a + Z.RANGE && e.buffered.end(o) >= l - Z.RANGE) {
3989
3981
  s = !0;
3990
3982
  break;
3991
3983
  }
@@ -3994,16 +3986,16 @@ class nt {
3994
3986
  if (s) {
3995
3987
  if (this.fragmentStates.set(n, "loaded"), this.discardCounts.delete(n), this.fetchErrorCycles.delete(n), de.recordAppendLanded(n), this.isInInitPhase() && this.recordInitFragEvent(n, { appendDone: performance.now() }), E("buffer", `APPEND-DONE #${n} sbRanges=[${ge(e.buffered).join(", ")}] queueLen=${this.appendQueue.length}`), n === this.fragments.length - 1 && this.appendQueue.length === 0 && !this.suppressEndOfStream) {
3996
3988
  const i = this.fragments[n].end_ms / 1e3, a = (this.fragments[n].end_ms - this.fragments[0].start_ms) / 1e3;
3997
- let c = 0;
3998
- for (let o = e.buffered.length - 1; o >= 0; o--) {
3999
- const u = e.buffered.start(o), f = e.buffered.end(o);
3989
+ let l = 0;
3990
+ for (let c = e.buffered.length - 1; c >= 0; c--) {
3991
+ const u = e.buffered.start(c), f = e.buffered.end(c);
4000
3992
  if (f >= i - Z.RANGE) {
4001
- c = f - u;
3993
+ l = f - u;
4002
3994
  break;
4003
3995
  }
4004
3996
  }
4005
- const l = Math.min(8, a * 0.5);
4006
- c < l ? I("buffer", `EOS-SKIP — last frag appended but buffered span ${c.toFixed(2)}s < ${l.toFixed(2)}s threshold; mid-join, not end-of-clip ${JSON.stringify({
3997
+ const o = Math.min(8, a * 0.5);
3998
+ l < o ? I("buffer", `EOS-SKIP — last frag appended but buffered span ${l.toFixed(2)}s < ${o.toFixed(2)}s threshold; mid-join, not end-of-clip ${JSON.stringify({
4007
3999
  appendedIdx: n,
4008
4000
  mediaDurationSec: a.toFixed(1),
4009
4001
  sbRanges: ge(e.buffered)
@@ -4034,12 +4026,12 @@ class nt {
4034
4026
  return;
4035
4027
  }
4036
4028
  const n = /* @__PURE__ */ new Set([
4037
- ...this.appendQueue.map((c) => c.index),
4029
+ ...this.appendQueue.map((l) => l.index),
4038
4030
  ...this.pendingFetchIndices
4039
4031
  ]), r = [], s = this.currentPlayheadMs / 1e3;
4040
- for (let c = 1; c < e.buffered.length; c++) {
4041
- const l = e.buffered.end(c - 1), o = e.buffered.start(c);
4042
- o <= s || ic(l, o, this.fragments, n) || r.push(`${l.toFixed(2)}-${o.toFixed(2)}`);
4032
+ for (let l = 1; l < e.buffered.length; l++) {
4033
+ const o = e.buffered.end(l - 1), c = e.buffered.start(l);
4034
+ c <= s || ic(o, c, this.fragments, n) || r.push(`${o.toFixed(2)}-${c.toFixed(2)}`);
4043
4035
  }
4044
4036
  if (r.length === 0) {
4045
4037
  this.stableGapSignature = null, this.stableGapSince = 0;
@@ -4050,8 +4042,8 @@ class nt {
4050
4042
  ranges: ge(e.buffered),
4051
4043
  unfillableGaps: r,
4052
4044
  stableForMs: a - this.stableGapSince,
4053
- appendQueue: this.appendQueue.map((c) => c.index),
4054
- pending: Array.from(this.pendingFetchIndices).sort((c, l) => c - l)
4045
+ appendQueue: this.appendQueue.map((l) => l.index),
4046
+ pending: Array.from(this.pendingFetchIndices).sort((l, o) => l - o)
4055
4047
  })}`));
4056
4048
  }
4057
4049
  checkAppendWaiters() {
@@ -4073,7 +4065,7 @@ class nt {
4073
4065
  const r = n ?? ut(this.getAverageDownloadRate());
4074
4066
  return new Promise((s, i) => {
4075
4067
  const a = setTimeout(() => {
4076
- this.appendWaiters = this.appendWaiters.filter((c) => c.index !== e), de.recordAppendTimeout(e, r, this.appendQueue.length), I("buffer", "waitForAppend timeout", {
4068
+ this.appendWaiters = this.appendWaiters.filter((l) => l.index !== e), de.recordAppendTimeout(e, r, this.appendQueue.length), I("buffer", "waitForAppend timeout", {
4077
4069
  track: this.label,
4078
4070
  index: e,
4079
4071
  timeoutMs: r,
@@ -4087,8 +4079,8 @@ class nt {
4087
4079
  resolve: () => {
4088
4080
  clearTimeout(a), s();
4089
4081
  },
4090
- reject: (c) => {
4091
- clearTimeout(a), i(c);
4082
+ reject: (l) => {
4083
+ clearTimeout(a), i(l);
4092
4084
  }
4093
4085
  });
4094
4086
  });
@@ -4213,8 +4205,8 @@ class nt {
4213
4205
  if (r) return { status: "loading", fragmentIndex: n, existingPromise: r.promise };
4214
4206
  const s = Math.max(0, n - jn), i = Math.min(this.fragments.length - 1, n + jn);
4215
4207
  for (let a = s; a <= i; a++) {
4216
- const c = this.fragmentStates.get(a);
4217
- if (c === "loaded" || c === "loading") return { status: "nearby-pending", fragmentIndex: n };
4208
+ const l = this.fragmentStates.get(a);
4209
+ if (l === "loaded" || l === "loading") return { status: "nearby-pending", fragmentIndex: n };
4218
4210
  }
4219
4211
  return { status: "far", fragmentIndex: n };
4220
4212
  }
@@ -4234,33 +4226,33 @@ class nt {
4234
4226
  if (this.disposed || !this.sourceBuffer || !this.fragments.length || this.hasDataAhead(e) || !xe(this.mediaSource)) return;
4235
4227
  const { abort: r = !1, minimal: s = !1, signal: i, caller: a = "unknown" } = n;
4236
4228
  r && this.abortAllJobs(a);
4237
- const c = Re(this.fragments, e);
4229
+ const l = Re(this.fragments, e);
4238
4230
  if (r) {
4239
- const p = Re(this.fragments, e + tt);
4240
- for (let v = c; v <= p; v++)
4231
+ const h = Re(this.fragments, e + tt);
4232
+ for (let v = l; v <= h; v++)
4241
4233
  this.discardCounts.delete(v), this.fetchErrorCycles.delete(v);
4242
4234
  }
4243
- const l = dn(this.fragments, e), o = this.fragments[l], u = o && this.sourceBuffer?.buffered && Kt(this.sourceBuffer.buffered, o.start_ms, o.end_ms), f = u ? c : l, h = s ? Math.min(this.fragments.length - 1, c + 1) : Re(this.fragments, e + Fe);
4235
+ const o = dn(this.fragments, e), c = this.fragments[o], u = c && this.sourceBuffer?.buffered && Kt(this.sourceBuffer.buffered, c.start_ms, c.end_ms), f = u ? l : o, p = s ? Math.min(this.fragments.length - 1, l + 1) : Re(this.fragments, e + Fe);
4244
4236
  this.initRange && this.initState !== "loaded" && await this.fetchInit();
4245
4237
  const g = [], b = [];
4246
- for (let p = f; p <= h; p++) {
4247
- const v = this.fragmentStates.get(p);
4238
+ for (let h = f; h <= p; h++) {
4239
+ const v = this.fragmentStates.get(h);
4248
4240
  if (v === "loaded") {
4249
- b.push(`#${p}=${v}`);
4241
+ b.push(`#${h}=${v}`);
4250
4242
  continue;
4251
4243
  }
4252
- if (v === "loading" && this.isFragmentInFlight(p)) {
4253
- b.push(`#${p}=${v}`);
4244
+ if (v === "loading" && this.isFragmentInFlight(h)) {
4245
+ b.push(`#${h}=${v}`);
4254
4246
  continue;
4255
4247
  }
4256
- v === "loading" && b.push(`#${p}=loading-abandoned→refetch`), g.push(p);
4248
+ v === "loading" && b.push(`#${h}=loading-abandoned→refetch`), g.push(h);
4257
4249
  }
4258
4250
  if (E("buffer", `FETCH-RANGE [${a}] ${JSON.stringify({
4259
4251
  targetMs: Math.round(e),
4260
- targetFrag: c,
4261
- keyframeFrag: l !== c ? l : void 0,
4262
- kfInSb: l !== c ? u : void 0,
4263
- range: [f, h],
4252
+ targetFrag: l,
4253
+ keyframeFrag: o !== l ? o : void 0,
4254
+ kfInSb: o !== l ? u : void 0,
4255
+ range: [f, p],
4264
4256
  abort: r,
4265
4257
  minimal: s,
4266
4258
  toFetch: g,
@@ -4268,10 +4260,10 @@ class nt {
4268
4260
  activeJobs: Array.from(this.currentJobs.keys()),
4269
4261
  sbRanges: ge(this.sourceBuffer?.buffered)
4270
4262
  })}`), g.length === 0) {
4271
- if (this.fragmentStates.get(c) === "loading") {
4272
- E("buffer", `FETCH-RANGE [${a}] target #${c} already loading, awaiting`);
4273
- const p = this.currentJobs.get(c);
4274
- p && await p.promise, await this.waitForAppend(c);
4263
+ if (this.fragmentStates.get(l) === "loading") {
4264
+ E("buffer", `FETCH-RANGE [${a}] target #${l} already loading, awaiting`);
4265
+ const h = this.currentJobs.get(l);
4266
+ h && await h.promise, await this.waitForAppend(l);
4275
4267
  }
4276
4268
  return;
4277
4269
  }
@@ -4279,7 +4271,7 @@ class nt {
4279
4271
  !r && this.currentJobs.size >= Qe && this.evictFurthestJob(e), this.onBufferingChange?.(!0), this.pendingSeekTargetMs = e, this.pendingSeekSetAtMs = Date.now();
4280
4272
  try {
4281
4273
  if (await this.fetchFragments(g), i?.aborted) throw new DOMException("Aborted", "AbortError");
4282
- await this.waitForAppend(c);
4274
+ await this.waitForAppend(l);
4283
4275
  } finally {
4284
4276
  this.onBufferingChange?.(!1);
4285
4277
  }
@@ -4292,21 +4284,21 @@ class nt {
4292
4284
  const r = [...e].sort((s, i) => s - i);
4293
4285
  E("buffer", `FETCH-BATCH-START total=${r.length} concurrency=${n} indices=[${r.join(",")}]`);
4294
4286
  for (let s = 0; s < r.length && !this.disposed; s += n) {
4295
- const i = r.slice(s, s + n), a = [], c = [];
4296
- for (const l of i) {
4297
- if (this.fragmentStates.get(l) === "loaded") {
4298
- a.push(`#${l}=loaded`);
4287
+ const i = r.slice(s, s + n), a = [], l = [];
4288
+ for (const o of i) {
4289
+ if (this.fragmentStates.get(o) === "loaded") {
4290
+ a.push(`#${o}=loaded`);
4299
4291
  continue;
4300
4292
  }
4301
4293
  if (this.currentJobs.size >= Qe) {
4302
- a.push(`#${l}=max-jobs`);
4294
+ a.push(`#${o}=max-jobs`);
4303
4295
  continue;
4304
4296
  }
4305
- c.push(this.fetchFragment(l).catch((o) => {
4306
- I("buffer", "Fragment fetch failed in batch", { index: l, error: o.message });
4297
+ l.push(this.fetchFragment(o).catch((c) => {
4298
+ I("buffer", "Fragment fetch failed in batch", { index: o, error: c.message });
4307
4299
  }));
4308
4300
  }
4309
- E("buffer", `FETCH-BATCH [${s / n + 1}/${Math.ceil(r.length / n)}] launching=[${i.filter((l) => !a.some((o) => o.startsWith(`#${l}`))).join(",")}] skipped=[${a.join(",")}]`), c.length > 0 && await Promise.allSettled(c);
4301
+ E("buffer", `FETCH-BATCH [${s / n + 1}/${Math.ceil(r.length / n)}] launching=[${i.filter((o) => !a.some((c) => c.startsWith(`#${o}`))).join(",")}] skipped=[${a.join(",")}]`), l.length > 0 && await Promise.allSettled(l);
4310
4302
  }
4311
4303
  E("buffer", `FETCH-BATCH-END indices=[${r.join(",")}] states=${JSON.stringify(r.map((s) => `#${s}=${this.fragmentStates.get(s)}`))}`);
4312
4304
  }
@@ -4317,42 +4309,42 @@ class nt {
4317
4309
  const r = this.currentJobs.get(e);
4318
4310
  if (r) return r.promise;
4319
4311
  this.fragmentStates.set(e, "loading"), this.pendingFetchIndices.add(e);
4320
- const s = new AbortController(), i = `${(n.start_ms / 1e3).toFixed(1)}-${(n.end_ms / 1e3).toFixed(1)}s`, a = n.end_byte - n.start_byte + 1, c = (async () => {
4312
+ const s = new AbortController(), i = `${(n.start_ms / 1e3).toFixed(1)}-${(n.end_ms / 1e3).toFixed(1)}s`, a = n.end_byte - n.start_byte + 1, l = (async () => {
4321
4313
  if (await Promise.resolve(), this.disposed || s.signal.aborted) {
4322
4314
  this.resetFragmentState(e);
4323
4315
  return;
4324
4316
  }
4325
4317
  try {
4326
4318
  if (this.mediaId) {
4327
- const l = Se.getFragment(this.mediaId, e);
4328
- if (l) {
4319
+ const o = Se.getFragment(this.mediaId, e);
4320
+ if (o) {
4329
4321
  if (E("buffer", `FETCH-CACHE-HIT #${e} [${i}]`), this.isInInitPhase()) {
4330
- const o = performance.now();
4331
- this.recordInitFragEvent(e, { fetchStart: o, fetchEnd: o, src: "cache", bytes: l.byteLength });
4322
+ const c = performance.now();
4323
+ this.recordInitFragEvent(e, { fetchStart: c, fetchEnd: c, src: "cache", bytes: o.byteLength });
4332
4324
  }
4333
- this.disposed || this.queueAppend(e, l);
4325
+ this.disposed || this.queueAppend(e, o);
4334
4326
  return;
4335
4327
  }
4336
4328
  }
4337
- for (let l = 1; l <= Xe; l++) {
4329
+ for (let o = 1; o <= Xe; o++) {
4338
4330
  if (this.disposed) return;
4339
- E("buffer", `FETCH-START #${e} [${i}] attempt=${l} bytes=${a} pending=${JSON.stringify(Array.from(this.pendingFetchIndices).sort((o, u) => o - u))}`);
4331
+ E("buffer", `FETCH-START #${e} [${i}] attempt=${o} bytes=${a} pending=${JSON.stringify(Array.from(this.pendingFetchIndices).sort((c, u) => c - u))}`);
4340
4332
  try {
4341
- const o = performance.now();
4342
- this.isInInitPhase() && l === 1 && this.recordInitFragEvent(e, { fetchStart: o, src: "net" });
4343
- const u = n.end_byte - n.start_byte + 1, f = this.mediaUrl, h = await this.tryFragmentRoute(e, u, s.signal);
4344
- if (h) {
4345
- const _ = performance.now() - o;
4333
+ const c = performance.now();
4334
+ this.isInInitPhase() && o === 1 && this.recordInitFragEvent(e, { fetchStart: c, src: "net" });
4335
+ const u = n.end_byte - n.start_byte + 1, f = this.mediaUrl, p = await this.tryFragmentRoute(e, u, s.signal);
4336
+ if (p) {
4337
+ const _ = performance.now() - c;
4346
4338
  if (this.isInInitPhase() && this.recordInitFragEvent(e, {
4347
4339
  fetchEnd: performance.now(),
4348
- bytes: h.buf.byteLength,
4349
- ttfbMs: h.ttfbMs,
4350
- cf: h.cfStatus
4351
- }), E("buffer", `FETCH-OK #${e} [${i}] ${h.buf.byteLength}B in ${Math.round(_)}ms via=frag-route (ttfb=${h.ttfbMs}ms cf=${h.cfStatus || "-"})`), _ > 0 && (this.downloadSamples.push({ bytes: h.buf.byteLength, durationMs: _ }), this.downloadSamples.length > Wt && this.downloadSamples.shift(), de.recordFetch(e, h.buf.byteLength, _)), this.disposed || this.mediaUrl !== f) {
4340
+ bytes: p.buf.byteLength,
4341
+ ttfbMs: p.ttfbMs,
4342
+ cf: p.cfStatus
4343
+ }), E("buffer", `FETCH-OK #${e} [${i}] ${p.buf.byteLength}B in ${Math.round(_)}ms via=frag-route (ttfb=${p.ttfbMs}ms cf=${p.cfStatus || "-"})`), _ > 0 && (this.downloadSamples.push({ bytes: p.buf.byteLength, durationMs: _ }), this.downloadSamples.length > Wt && this.downloadSamples.shift(), de.recordFetch(e, p.buf.byteLength, _)), this.disposed || this.mediaUrl !== f) {
4352
4344
  E("buffer", `FETCH-STALE #${e} discarding frag-route bytes (mediaUrl changed)`);
4353
4345
  return;
4354
4346
  }
4355
- this.mediaId && Se.storeFragment(this.mediaId, e, h.buf), this.disposed || this.queueAppend(e, h.buf);
4347
+ this.mediaId && Se.storeFragment(this.mediaId, e, p.buf), this.disposed || this.queueAppend(e, p.buf);
4356
4348
  return;
4357
4349
  }
4358
4350
  const g = this.mediaUrl, b = await fetch(g, {
@@ -4361,7 +4353,7 @@ class nt {
4361
4353
  "X-Buffer-Ahead-Ms": String(Math.round(this.getBufferedAheadMs(this.currentPlayheadMs)))
4362
4354
  },
4363
4355
  signal: AbortSignal.any([s.signal, AbortSignal.timeout(ut(this.getAverageDownloadRate()))])
4364
- }), p = Math.round(performance.now() - o), v = b.headers.get("cf-cache-status") || b.headers.get("x-cache") || "";
4356
+ }), h = Math.round(performance.now() - c), v = b.headers.get("cf-cache-status") || b.headers.get("x-cache") || "";
4365
4357
  if (!b.ok) throw new Error(`HTTP ${b.status}`);
4366
4358
  const S = n.end_byte - n.start_byte + 1;
4367
4359
  if (b.status !== 206) {
@@ -4371,8 +4363,8 @@ class nt {
4371
4363
  contentLength: b.headers.get("content-length"),
4372
4364
  cfCacheStatus: v,
4373
4365
  expectedBytes: S
4374
- }), this.fragmentStates.set(e, "pending"), l < Xe) {
4375
- await new Promise((_) => setTimeout(_, ht(l)));
4366
+ }), this.fragmentStates.set(e, "pending"), o < Xe) {
4367
+ await new Promise((_) => setTimeout(_, ht(o)));
4376
4368
  continue;
4377
4369
  }
4378
4370
  throw new Error(`fragment expected 206, got ${b.status}`);
@@ -4383,44 +4375,44 @@ class nt {
4383
4375
  expectedBytes: S,
4384
4376
  actualBytes: A.byteLength
4385
4377
  }), A.byteLength === 0 || A.byteLength !== S) {
4386
- if (this.fragmentStates.set(e, "pending"), l < Xe) {
4387
- await new Promise((_) => setTimeout(_, ht(l)));
4378
+ if (this.fragmentStates.set(e, "pending"), o < Xe) {
4379
+ await new Promise((_) => setTimeout(_, ht(o)));
4388
4380
  continue;
4389
4381
  }
4390
4382
  ee("buffer", `Fragment #${e} bad response after ${Xe} retries`, { expected: S, actual: A.byteLength }), this.fragmentStates.set(e, "error"), this.errorTimestamps.set(e, Date.now()), this.fetchErrorCycles.set(e, (this.fetchErrorCycles.get(e) ?? 0) + 1), de.recordFetchError(e);
4391
4383
  return;
4392
4384
  }
4393
- const R = performance.now() - o;
4394
- if (this.isInInitPhase() && this.recordInitFragEvent(e, { fetchEnd: performance.now(), bytes: A.byteLength, ttfbMs: p, cf: v }), E("buffer", `FETCH-OK #${e} [${i}] ${A.byteLength}B in ${Math.round(R)}ms (ttfb=${p}ms cf=${v || "-"}) (${(A.byteLength / R * 1e3 / 1024).toFixed(0)} KB/s)`), R > 0 && (this.downloadSamples.push({ bytes: A.byteLength, durationMs: R }), this.downloadSamples.length > Wt && this.downloadSamples.shift(), de.recordFetch(e, A.byteLength, R)), this.disposed || this.mediaUrl !== g) {
4385
+ const R = performance.now() - c;
4386
+ if (this.isInInitPhase() && this.recordInitFragEvent(e, { fetchEnd: performance.now(), bytes: A.byteLength, ttfbMs: h, cf: v }), E("buffer", `FETCH-OK #${e} [${i}] ${A.byteLength}B in ${Math.round(R)}ms (ttfb=${h}ms cf=${v || "-"}) (${(A.byteLength / R * 1e3 / 1024).toFixed(0)} KB/s)`), R > 0 && (this.downloadSamples.push({ bytes: A.byteLength, durationMs: R }), this.downloadSamples.length > Wt && this.downloadSamples.shift(), de.recordFetch(e, A.byteLength, R)), this.disposed || this.mediaUrl !== g) {
4395
4387
  E("buffer", `FETCH-STALE #${e} discarding (mediaUrl changed)`);
4396
4388
  return;
4397
4389
  }
4398
4390
  this.mediaId && Se.storeFragment(this.mediaId, e, A), this.disposed || this.queueAppend(e, A);
4399
4391
  return;
4400
- } catch (o) {
4401
- if (o.name === "AbortError" && s.signal.aborted) {
4392
+ } catch (c) {
4393
+ if (c.name === "AbortError" && s.signal.aborted) {
4402
4394
  E("buffer", `FETCH-ABORT #${e} [${i}] seek-abort, resetting to pending`), this.fragmentStates.set(e, "pending");
4403
4395
  return;
4404
4396
  }
4405
- if ((o.name === "TimeoutError" || o.message?.includes("signal timed out") || o.message?.includes("The operation was aborted")) && o.name !== "AbortError") {
4397
+ if ((c.name === "TimeoutError" || c.message?.includes("signal timed out") || c.message?.includes("The operation was aborted")) && c.name !== "AbortError") {
4406
4398
  const f = ut(this.getAverageDownloadRate());
4407
- this.downloadSamples.push({ bytes: 0, durationMs: f }), this.downloadSamples.length > Wt && this.downloadSamples.shift(), de.recordFetchTimeout(e), I("buffer", `FETCH-ERR #${e} [${i}] attempt=${l} timeout=${f}ms avgRate=${Math.round(this.getAverageDownloadRate())}Bps error=${o.message}`);
4399
+ this.downloadSamples.push({ bytes: 0, durationMs: f }), this.downloadSamples.length > Wt && this.downloadSamples.shift(), de.recordFetchTimeout(e), I("buffer", `FETCH-ERR #${e} [${i}] attempt=${o} timeout=${f}ms avgRate=${Math.round(this.getAverageDownloadRate())}Bps error=${c.message}`);
4408
4400
  } else
4409
- I("buffer", `FETCH-ERR #${e} [${i}] attempt=${l} error=${o.message}`);
4410
- if (this.isInInitPhase() && this.recordInitFragEvent(e, { err: (o.name === "TimeoutError" ? "timeout" : o.message?.slice(0, 40)) || "err" }), this.fragmentStates.set(e, "pending"), l < Xe) {
4411
- await new Promise((f) => setTimeout(f, ht(l)));
4401
+ I("buffer", `FETCH-ERR #${e} [${i}] attempt=${o} error=${c.message}`);
4402
+ if (this.isInInitPhase() && this.recordInitFragEvent(e, { err: (c.name === "TimeoutError" ? "timeout" : c.message?.slice(0, 40)) || "err" }), this.fragmentStates.set(e, "pending"), o < Xe) {
4403
+ await new Promise((f) => setTimeout(f, ht(o)));
4412
4404
  continue;
4413
4405
  }
4414
- throw ee("buffer", `Fragment #${e} failed after ${Xe} retries`, { error: o.message }), this.fragmentStates.set(e, "error"), this.errorTimestamps.set(e, Date.now()), this.fetchErrorCycles.set(e, (this.fetchErrorCycles.get(e) ?? 0) + 1), de.recordFetchError(e), o;
4406
+ throw ee("buffer", `Fragment #${e} failed after ${Xe} retries`, { error: c.message }), this.fragmentStates.set(e, "error"), this.errorTimestamps.set(e, Date.now()), this.fetchErrorCycles.set(e, (this.fetchErrorCycles.get(e) ?? 0) + 1), de.recordFetchError(e), c;
4415
4407
  }
4416
4408
  }
4417
4409
  } finally {
4418
4410
  this.currentJobs.delete(e);
4419
- const l = this.appendQueue.some((o) => o.index === e) || this.appendingIndex === e;
4420
- l || this.pendingFetchIndices.delete(e), E("buffer", `FETCH-DONE #${e} state=${this.fragmentStates.get(e)} queued=${l} remainingJobs=${this.currentJobs.size} pendingFetches=${JSON.stringify(Array.from(this.pendingFetchIndices).sort((o, u) => o - u))}`), this.processAppendQueue();
4411
+ const o = this.appendQueue.some((c) => c.index === e) || this.appendingIndex === e;
4412
+ o || this.pendingFetchIndices.delete(e), E("buffer", `FETCH-DONE #${e} state=${this.fragmentStates.get(e)} queued=${o} remainingJobs=${this.currentJobs.size} pendingFetches=${JSON.stringify(Array.from(this.pendingFetchIndices).sort((c, u) => c - u))}`), this.processAppendQueue();
4421
4413
  }
4422
4414
  })();
4423
- return this.currentJobs.set(e, { index: e, abortController: s, promise: c }), c;
4415
+ return this.currentJobs.set(e, { index: e, abortController: s, promise: l }), l;
4424
4416
  }
4425
4417
  /** If the head of the queue is a non-keyframe fragment whose IDR predecessor
4426
4418
  * is in permanent error AND not present in the SourceBuffer, drop every
@@ -4440,26 +4432,26 @@ class nt {
4440
4432
  if (r < 0 || this.fragmentStates.get(r) !== "error") return !1;
4441
4433
  const s = this.fragments[r];
4442
4434
  if (this.sourceBuffer ? Kt(this.sourceBuffer.buffered, s.start_ms, s.end_ms) : !1) return !1;
4443
- const a = [], c = [];
4444
- for (const l of this.appendQueue) {
4445
- const o = this.fragments[l.index];
4446
- if (!o || o.keyframe) {
4447
- c.push(l);
4435
+ const a = [], l = [];
4436
+ for (const o of this.appendQueue) {
4437
+ const c = this.fragments[o.index];
4438
+ if (!c || c.keyframe) {
4439
+ l.push(o);
4448
4440
  continue;
4449
4441
  }
4450
- Gn(this.fragments, l.index - 1) === r ? (a.push(l.index), this.fragmentStates.set(l.index, "pending")) : c.push(l);
4442
+ Gn(this.fragments, o.index - 1) === r ? (a.push(o.index), this.fragmentStates.set(o.index, "pending")) : l.push(o);
4451
4443
  }
4452
- return a.length === 0 ? !1 : (this.appendQueue = c, I("buffer", `APPEND-DROP-DEPENDENT [${a.join(",")}] — keyframe #${r} in error, not in SB`, {
4444
+ return a.length === 0 ? !1 : (this.appendQueue = l, I("buffer", `APPEND-DROP-DEPENDENT [${a.join(",")}] — keyframe #${r} in error, not in SB`, {
4453
4445
  kfIdx: r,
4454
4446
  dropped: a,
4455
- remainingQueue: this.appendQueue.map((l) => l.index)
4447
+ remainingQueue: this.appendQueue.map((o) => o.index)
4456
4448
  }), !0);
4457
4449
  }
4458
4450
  queueAppend(e, n) {
4459
4451
  const r = this.appendQueue.findIndex((a) => a.index > e);
4460
4452
  r === -1 ? this.appendQueue.push({ index: e, buffer: n }) : this.appendQueue.splice(r, 0, { index: e, buffer: n }), this.isInInitPhase() && this.recordInitFragEvent(e, { queued: performance.now() }), de.recordAppendQueued(e, this.appendQueue.length);
4461
4453
  const i = this.fragments[e]?.keyframe;
4462
- E("buffer", `QUEUE-APPEND #${e} ${n.byteLength}B pos=${r === -1 ? this.appendQueue.length - 1 : r} queueLen=${this.appendQueue.length} keyframe=${i ?? "unknown"} pending=${JSON.stringify(Array.from(this.pendingFetchIndices).sort((a, c) => a - c))}`), this.processAppendQueue();
4454
+ E("buffer", `QUEUE-APPEND #${e} ${n.byteLength}B pos=${r === -1 ? this.appendQueue.length - 1 : r} queueLen=${this.appendQueue.length} keyframe=${i ?? "unknown"} pending=${JSON.stringify(Array.from(this.pendingFetchIndices).sort((a, l) => a - l))}`), this.processAppendQueue();
4463
4455
  }
4464
4456
  /** Bounds the sequential-append hold. Returns true when the hold has lasted
4465
4457
  * longer than APPEND_HOLD_MAX_MS and the blocking fetches have been declared
@@ -4545,11 +4537,11 @@ class nt {
4545
4537
  this.fragmentStates.get(a) === "error" && s - (this.errorTimestamps.get(a) ?? 0) >= ea && ((this.fetchErrorCycles.get(a) ?? 0) >= En ? E("buffer", `PREFETCH-DEAD #${a} cycles=${this.fetchErrorCycles.get(a)} not resetting`) : (this.fragmentStates.set(a, "pending"), this.errorTimestamps.delete(a)));
4546
4538
  let i = 0;
4547
4539
  for (let a = n; a <= r && i < Qe - this.currentJobs.size; a++) {
4548
- const c = this.fragmentStates.get(a);
4549
- if (!(c !== "pending" && c !== "error") && !((this.discardCounts.get(a) ?? 0) >= 2) && !((this.fetchErrorCycles.get(a) ?? 0) >= 3)) {
4540
+ const l = this.fragmentStates.get(a);
4541
+ if (!(l !== "pending" && l !== "error") && !((this.discardCounts.get(a) ?? 0) >= 2) && !((this.fetchErrorCycles.get(a) ?? 0) >= 3)) {
4550
4542
  if (a > n) {
4551
- const l = this.fragmentStates.get(a - 1), o = (this.discardCounts.get(a - 1) ?? 0) >= 2 || (this.fetchErrorCycles.get(a - 1) ?? 0) >= 3;
4552
- if (l !== "loaded" && l !== "loading" && !o) break;
4543
+ const o = this.fragmentStates.get(a - 1), c = (this.discardCounts.get(a - 1) ?? 0) >= 2 || (this.fetchErrorCycles.get(a - 1) ?? 0) >= 3;
4544
+ if (o !== "loaded" && o !== "loading" && !c) break;
4553
4545
  }
4554
4546
  this.fetchFragment(a).catch(() => {
4555
4547
  }), i++;
@@ -4557,9 +4549,9 @@ class nt {
4557
4549
  }
4558
4550
  if (i === 0 && n <= r) {
4559
4551
  const a = {};
4560
- for (let l = n; l <= r; l++) {
4561
- const o = this.fragmentStates.get(l) ?? "pending";
4562
- a[o] = (a[o] ?? 0) + 1;
4552
+ for (let o = n; o <= r; o++) {
4553
+ const c = this.fragmentStates.get(o) ?? "pending";
4554
+ a[c] = (a[c] ?? 0) + 1;
4563
4555
  }
4564
4556
  ((a.pending ?? 0) > 0 || (a.error ?? 0) > 0) && I("buffer", "PREFETCH-STALL no new fetches launched", {
4565
4557
  stateMap: a,
@@ -4593,21 +4585,21 @@ class nt {
4593
4585
  }
4594
4586
  abortAllJobs(e) {
4595
4587
  if (this.generationAbort.abort(), this.generationAbort = new AbortController(), this.currentJobs.size === 0 && this.appendQueue.length === 0) return;
4596
- const r = Array.from(this.currentJobs.keys()).sort((l, o) => l - o).map((l) => `#${l}=${this.fragmentStates.get(l) || "?"}`), s = this.appendQueue.map((l) => l.index), i = Array.from(this.pendingFetchIndices).sort((l, o) => l - o), a = this.appendWaiters.map((l) => l.index);
4588
+ const r = Array.from(this.currentJobs.keys()).sort((o, c) => o - c).map((o) => `#${o}=${this.fragmentStates.get(o) || "?"}`), s = this.appendQueue.map((o) => o.index), i = Array.from(this.pendingFetchIndices).sort((o, c) => o - c), a = this.appendWaiters.map((o) => o.index);
4597
4589
  I("buffer", `ABORT-ALL [${e || "unknown"}] ${JSON.stringify({
4598
4590
  killedJobs: r,
4599
4591
  queuedAppends: s,
4600
4592
  pendingFetches: i,
4601
4593
  waiters: a
4602
4594
  })}`);
4603
- for (const [l, o] of this.currentJobs)
4604
- o.abortController.abort(), this.fragmentStates.get(l) === "loading" && this.fragmentStates.set(l, "pending");
4595
+ for (const [o, c] of this.currentJobs)
4596
+ c.abortController.abort(), this.fragmentStates.get(o) === "loading" && this.fragmentStates.set(o, "pending");
4605
4597
  this.currentJobs.clear(), this.pendingFetchIndices.clear(), this.appendHold = null, this.discardCounts.clear();
4606
- for (const l of this.appendQueue)
4607
- this.fragmentStates.get(l.index) === "loading" && this.fragmentStates.set(l.index, "pending");
4598
+ for (const o of this.appendQueue)
4599
+ this.fragmentStates.get(o.index) === "loading" && this.fragmentStates.set(o.index, "pending");
4608
4600
  this.appendQueue = [];
4609
- const c = new Error("Seek aborted pending append");
4610
- for (const l of this.appendWaiters) l.reject(c);
4601
+ const l = new Error("Seek aborted pending append");
4602
+ for (const o of this.appendWaiters) o.reject(l);
4611
4603
  this.appendWaiters = [];
4612
4604
  }
4613
4605
  /** True when fragment `index` will still arrive on its own — an in-flight
@@ -4654,28 +4646,28 @@ class nt {
4654
4646
  append: Math.round(this.initAppendDone - this.initFetchEnd),
4655
4647
  ...this.initTtfbMs >= 0 ? { ttfb: this.initTtfbMs } : {},
4656
4648
  ...this.initCfStatus ? { cf: this.initCfStatus } : {}
4657
- } : null, a = [], c = Array.from(this.fragInitTimings.entries()).sort((o, u) => o[0] - u[0]);
4658
- for (const [o, u] of c) {
4659
- const f = { i: o, src: u.src ?? "?" };
4649
+ } : null, a = [], l = Array.from(this.fragInitTimings.entries()).sort((c, u) => c[0] - u[0]);
4650
+ for (const [c, u] of l) {
4651
+ const f = { i: c, src: u.src ?? "?" };
4660
4652
  u.fetchStart && (f.fs = Math.round(u.fetchStart - this.loadStartTs)), u.fetchStart && u.fetchEnd && (f.fM = Math.round(u.fetchEnd - u.fetchStart)), u.queued && u.fetchEnd && (f.qD = Math.round(u.queued - u.fetchEnd)), u.queued && u.appendDone && (f.aM = Math.round(u.appendDone - u.queued)), u.bytes && (f.B = u.bytes), u.ttfbMs !== void 0 && (f.tt = u.ttfbMs), u.cf && (f.cf = u.cf), u.err && (f.e = u.err), a.push(f);
4661
4653
  }
4662
- const l = this.getLoadedCount();
4654
+ const o = this.getLoadedCount();
4663
4655
  I("buffer", `INIT-DIGEST [${e}] reason=${n} ${JSON.stringify({
4664
4656
  loadMs: s,
4665
4657
  initMs: i,
4666
- loaded: l,
4658
+ loaded: o,
4667
4659
  gateBufAheadMs: Math.round(this.getBufferedAheadMs(this.currentPlayheadMs)),
4668
4660
  holds: this.initHoldCounts,
4669
- pending: Array.from(this.pendingFetchIndices).sort((o, u) => o - u),
4670
- queue: this.appendQueue.map((o) => o.index),
4661
+ pending: Array.from(this.pendingFetchIndices).sort((c, u) => c - u),
4662
+ queue: this.appendQueue.map((c) => c.index),
4671
4663
  frags: a
4672
4664
  })}`);
4673
4665
  }
4674
4666
  dumpBufferDiagnostics(e, n) {
4675
4667
  const r = Re(this.fragments, e), s = Math.max(0, r - 3), i = Math.min(this.fragments.length - 1, r + 6), a = [];
4676
- for (let c = s; c <= i; c++) {
4677
- const l = this.fragments[c], o = this.fragmentStates.get(c) || "unknown";
4678
- a.push(`#${c}[${(l.start_ms / 1e3).toFixed(1)}-${(l.end_ms / 1e3).toFixed(1)}s]=${o}${this.currentJobs.has(c) ? "+job" : ""}${c === r ? " <<PLAYHEAD" : ""}`);
4668
+ for (let l = s; l <= i; l++) {
4669
+ const o = this.fragments[l], c = this.fragmentStates.get(l) || "unknown";
4670
+ a.push(`#${l}[${(o.start_ms / 1e3).toFixed(1)}-${(o.end_ms / 1e3).toFixed(1)}s]=${c}${this.currentJobs.has(l) ? "+job" : ""}${l === r ? " <<PLAYHEAD" : ""}`);
4679
4671
  }
4680
4672
  I("buffer", `BUFFER-DIAG [${n}] ${JSON.stringify({
4681
4673
  playheadMs: Math.round(e),
@@ -4684,8 +4676,8 @@ class nt {
4684
4676
  sbRanges: ge(this.sourceBuffer?.buffered),
4685
4677
  fragments: a,
4686
4678
  activeJobs: Array.from(this.currentJobs.keys()),
4687
- appendQueue: this.appendQueue.map((c) => c.index),
4688
- pendingFetchIndices: Array.from(this.pendingFetchIndices).sort((c, l) => c - l),
4679
+ appendQueue: this.appendQueue.map((l) => l.index),
4680
+ pendingFetchIndices: Array.from(this.pendingFetchIndices).sort((l, o) => l - o),
4689
4681
  isAppending: this.isAppending,
4690
4682
  appendingIndex: this.appendingIndex
4691
4683
  })}`);
@@ -4739,10 +4731,10 @@ class nt {
4739
4731
  const r = e / 1e3, s = this.sourceBuffer.buffered, i = Ze(s, r, Z.RANGE);
4740
4732
  if (i >= 0 && s.end(i) - r > jt) return null;
4741
4733
  const a = i >= 0 ? Math.max(r, s.end(i)) : r;
4742
- for (let c = 0; c < s.length; c++) {
4743
- const l = s.start(c);
4744
- if (l > a && (l - a) * 1e3 <= n)
4745
- return l * 1e3;
4734
+ for (let l = 0; l < s.length; l++) {
4735
+ const o = s.start(l);
4736
+ if (o > a && (o - a) * 1e3 <= n)
4737
+ return o * 1e3;
4746
4738
  }
4747
4739
  return null;
4748
4740
  }
@@ -4758,17 +4750,17 @@ class nt {
4758
4750
  getForwardGapDiag(e) {
4759
4751
  if (!this.sourceBuffer?.buffered || !xe(this.mediaSource)) return null;
4760
4752
  const n = e / 1e3, r = this.sourceBuffer.buffered, s = Ze(r, n, Z.RANGE), i = s >= 0 ? Math.max(0, r.end(s) - n) : 0, a = s >= 0 ? Math.max(n, r.end(s)) : n;
4761
- let c = null;
4762
- for (let l = 0; l < r.length; l++)
4763
- if (r.start(l) > a) {
4764
- c = r.start(l);
4753
+ let l = null;
4754
+ for (let o = 0; o < r.length; o++)
4755
+ if (r.start(o) > a) {
4756
+ l = r.start(o);
4765
4757
  break;
4766
4758
  }
4767
4759
  return {
4768
4760
  atEdge: s >= 0 && i <= jt,
4769
4761
  aheadInRangeMs: i * 1e3,
4770
- nextRangeStartMs: c !== null ? c * 1e3 : null,
4771
- gapMs: c !== null ? (c - a) * 1e3 : null
4762
+ nextRangeStartMs: l !== null ? l * 1e3 : null,
4763
+ gapMs: l !== null ? (l - a) * 1e3 : null
4772
4764
  };
4773
4765
  }
4774
4766
  /** Best-effort attempt to signal end of stream on the MediaSource.
@@ -4979,26 +4971,26 @@ class Ac {
4979
4971
  async _execute(e) {
4980
4972
  const n = new AbortController();
4981
4973
  this._currentAbort = n, this._seekInFlight = !0, this._currentPriority = e.priority, this._currentCaller = e.caller, this._currentTargetMs = e.targetMs;
4982
- const { targetMs: r, caller: s } = e, i = e.pauseSeekResume ?? !0, a = this.deps.videoRef.current, c = this.deps.fragmentManagerRef.current;
4983
- if (!a || !c)
4974
+ const { targetMs: r, caller: s } = e, i = e.pauseSeekResume ?? !0, a = this.deps.videoRef.current, l = this.deps.fragmentManagerRef.current;
4975
+ if (!a || !l)
4984
4976
  return I("seek-coord", `EXECUTE bail — missing ${a ? "fragmentManager" : "video"}`, { caller: s }), this._clear(n), null;
4985
- const l = performance.now(), o = !a.paused;
4977
+ const o = performance.now(), c = !a.paused;
4986
4978
  try {
4987
- i && o && this._pause(a), this._checkAborted(n);
4979
+ i && c && this._pause(a), this._checkAborted(n);
4988
4980
  const u = this.deps.audioFragmentManagersRef.current ?? [];
4989
- if (!c.isBuffered(r) || u.some((A) => !A.isBuffered(r))) {
4981
+ if (!l.isBuffered(r) || u.some((A) => !A.isBuffered(r))) {
4990
4982
  const A = performance.now();
4991
4983
  E("seek-coord", `BUFFERING [${s}] target=${Math.round(r)}ms`, {
4992
4984
  videoTime: Math.round(a.currentTime * 1e3),
4993
4985
  videoReady: a.readyState,
4994
4986
  videoPaused: a.paused,
4995
4987
  audioFmCount: u.length
4996
- }), await this._smartBufferAll(c, u, r, s, n), this._checkAborted(n), E("seek-coord", `BUFFERED [${s}] took ${Math.round(performance.now() - A)}ms`);
4988
+ }), await this._smartBufferAll(l, u, r, s, n), this._checkAborted(n), E("seek-coord", `BUFFERED [${s}] took ${Math.round(performance.now() - A)}ms`);
4997
4989
  } else
4998
4990
  E("seek-coord", `ALREADY BUFFERED [${s}] target=${Math.round(r)}ms`);
4999
- const h = r / 1e3;
5000
- a.currentTime = h, await Zr(a), this._checkAborted(n);
5001
- const g = a.currentTime * 1e3, b = Math.round(performance.now() - l);
4991
+ const p = r / 1e3;
4992
+ a.currentTime = p, await Zr(a), this._checkAborted(n);
4993
+ const g = a.currentTime * 1e3, b = Math.round(performance.now() - o);
5002
4994
  I("seek-coord", `SEEK-DIGEST [${s}] route=${this._lastSeekRoute} ${b}ms`, {
5003
4995
  targetMs: Math.round(r),
5004
4996
  actualMs: Math.round(g),
@@ -5013,7 +5005,7 @@ class Ac {
5013
5005
  for (const A of S) A.prefetchAround(g);
5014
5006
  return { actualMs: g };
5015
5007
  } catch (u) {
5016
- const f = Math.round(performance.now() - l);
5008
+ const f = Math.round(performance.now() - o);
5017
5009
  return u.name === "AbortError" ? (E("seek-coord", `PREEMPTED [${s}] after ${f}ms`, {
5018
5010
  targetMs: Math.round(r),
5019
5011
  videoTime: Math.round(a.currentTime * 1e3)
@@ -5083,17 +5075,17 @@ class Ac {
5083
5075
  * non-fatal: we log and move on so the video doesn't stall on an audio
5084
5076
  * hiccup. */
5085
5077
  async _smartBufferAll(e, n, r, s, i) {
5086
- const a = !e.isBuffered(r), c = [];
5087
- a && c.push(this._smartBuffer(e, r, s, i));
5088
- for (const l of n)
5089
- l.isBuffered(r) || c.push(
5090
- this._smartBuffer(l, r, `${s}-audio`, i).catch((o) => {
5091
- o.name !== "AbortError" && I("seek-coord", `Audio FM buffer failed during ${s}`, {
5092
- error: o?.message
5078
+ const a = !e.isBuffered(r), l = [];
5079
+ a && l.push(this._smartBuffer(e, r, s, i));
5080
+ for (const o of n)
5081
+ o.isBuffered(r) || l.push(
5082
+ this._smartBuffer(o, r, `${s}-audio`, i).catch((c) => {
5083
+ c.name !== "AbortError" && I("seek-coord", `Audio FM buffer failed during ${s}`, {
5084
+ error: c?.message
5093
5085
  });
5094
5086
  })
5095
5087
  );
5096
- c.length !== 0 && await Promise.all(c);
5088
+ l.length !== 0 && await Promise.all(l);
5097
5089
  }
5098
5090
  // ── Playback helpers ──
5099
5091
  _pause(e) {
@@ -5127,18 +5119,18 @@ function Jn() {
5127
5119
  E("health", "skip report — FM mediaId mismatch", { fmKey: n.cacheKey, snapMedia: e.snapshot.mediaId });
5128
5120
  return;
5129
5121
  }
5130
- const r = document.querySelector("video"), s = r ? Math.round(r.currentTime * 1e3) : e.snapshot.playheadMs, i = n.getBufferState(), a = n.getBufferedEnd(s), c = window.__AUDIO_FRAGMENT_MANAGERS__;
5131
- let l = -1;
5132
- for (const h of c ?? []) {
5133
- if (!h.hasIndex) continue;
5134
- const g = h.getBufferedAheadMs(s);
5135
- (l < 0 || g < l) && (l = g);
5122
+ const r = document.querySelector("video"), s = r ? Math.round(r.currentTime * 1e3) : e.snapshot.playheadMs, i = n.getBufferState(), a = n.getBufferedEnd(s), l = window.__AUDIO_FRAGMENT_MANAGERS__;
5123
+ let o = -1;
5124
+ for (const p of l ?? []) {
5125
+ if (!p.hasIndex) continue;
5126
+ const g = p.getBufferedAheadMs(s);
5127
+ (o < 0 || g < o) && (o = g);
5136
5128
  }
5137
- const o = Math.max(0, a - s), u = l < 0 ? o : Math.min(o, l), f = e.drift.rtts.length > 0 ? e.drift.rtts.reduce((h, g) => h + g, 0) / e.drift.rtts.length : 0;
5129
+ const c = Math.max(0, a - s), u = o < 0 ? c : Math.min(c, o), f = e.drift.rtts.length > 0 ? e.drift.rtts.reduce((p, g) => p + g, 0) / e.drift.rtts.length : 0;
5138
5130
  t.emit(fr.HEALTH_REPORT, {
5139
5131
  avg_download_rate_bps: n.getAverageDownloadRate(),
5140
5132
  buffered_ahead_ms: u,
5141
- audio_buffered_ahead_ms: l < 0 ? -1 : Math.round(l),
5133
+ audio_buffered_ahead_ms: o < 0 ? -1 : Math.round(o),
5142
5134
  rtt_ms: f,
5143
5135
  playhead_ms: s,
5144
5136
  is_buffering: e.bufferState.isBuffering,
@@ -5167,27 +5159,27 @@ function Cc(t) {
5167
5159
  }
5168
5160
  const Rc = 3e3;
5169
5161
  function Fc() {
5170
- const [t, e] = $(!1), n = N(null), r = N(!1), s = () => {
5162
+ const [t, e] = $(!1), n = L(null), r = L(!1), s = () => {
5171
5163
  n.current && (clearTimeout(n.current), n.current = null);
5172
- }, i = j((l = 3e3) => {
5173
- s(), e(!0), l > 0 && (n.current = setTimeout(() => {
5164
+ }, i = j((o = 3e3) => {
5165
+ s(), e(!0), o > 0 && (n.current = setTimeout(() => {
5174
5166
  r.current || e(!1);
5175
- }, l));
5167
+ }, o));
5176
5168
  }, []), a = j(() => {
5177
5169
  r.current || (s(), e(!1));
5178
- }, []), c = j((l) => {
5179
- r.current !== l && (r.current = l, l ? (s(), e(!0)) : i(Rc));
5170
+ }, []), l = j((o) => {
5171
+ r.current !== o && (r.current = o, o ? (s(), e(!0)) : i(Rc));
5180
5172
  }, [i]);
5181
5173
  return F(() => {
5182
- const l = () => {
5174
+ const o = () => {
5183
5175
  i(4e3);
5184
5176
  };
5185
- return window.addEventListener("resize", l), () => {
5186
- window.removeEventListener("resize", l), s();
5177
+ return window.addEventListener("resize", o), () => {
5178
+ window.removeEventListener("resize", o), s();
5187
5179
  };
5188
- }, [i]), { controlsVisible: t, showControls: i, hideControls: a, setControlsHeld: c };
5180
+ }, [i]), { controlsVisible: t, showControls: i, hideControls: a, setControlsHeld: l };
5189
5181
  }
5190
- const es = [], ts = [], Lc = {
5182
+ const es = [], ts = [], Nc = {
5191
5183
  fragments: es,
5192
5184
  durationMs: null,
5193
5185
  mseCodec: null,
@@ -5195,8 +5187,8 @@ const es = [], ts = [], Lc = {
5195
5187
  audioTracks: ts,
5196
5188
  contentToken: null
5197
5189
  };
5198
- function Nc(t, e) {
5199
- if (!t || t.url !== e) return Lc;
5190
+ function Lc(t, e) {
5191
+ if (!t || t.url !== e) return Nc;
5200
5192
  const n = t.data;
5201
5193
  return {
5202
5194
  fragments: n.fragments || es,
@@ -5233,52 +5225,52 @@ function $c(t) {
5233
5225
  let i = 0;
5234
5226
  const a = 1e4;
5235
5227
  for (; !r.signal.aborted; ) {
5236
- const c = performance.now();
5228
+ const l = performance.now();
5237
5229
  try {
5238
- const l = await fetch(t, {
5230
+ const o = await fetch(t, {
5239
5231
  cache: "no-store",
5240
5232
  signal: r.signal,
5241
5233
  // High priority: index.json is ~120KB but critical for all
5242
5234
  // playback. Without it, MSE can never create a SourceBuffer.
5243
5235
  priority: "high"
5244
- }), o = Math.round(performance.now() - c);
5245
- if (!l.ok) throw new Error(`HTTP ${l.status}`);
5246
- const u = await l.text(), f = Math.round(performance.now() - c) - o, h = JSON.parse(u), g = Math.round(performance.now() - c) - o - f, b = o + f + g;
5236
+ }), c = Math.round(performance.now() - l);
5237
+ if (!o.ok) throw new Error(`HTTP ${o.status}`);
5238
+ const u = await o.text(), f = Math.round(performance.now() - l) - c, p = JSON.parse(u), g = Math.round(performance.now() - l) - c - f, b = c + f + g;
5247
5239
  if (r.signal.aborted) return;
5248
- n({ url: t, data: h });
5249
- const p = Qn(t);
5240
+ n({ url: t, data: p });
5241
+ const h = Qn(t);
5250
5242
  E("mse", "Index loaded", {
5251
5243
  attempt: i + 1,
5252
- headerMs: o,
5244
+ headerMs: c,
5253
5245
  downloadMs: f,
5254
5246
  parseMs: g,
5255
5247
  totalMs: b,
5256
- count: h.fragments?.length,
5257
- duration: h.duration_ms,
5258
- codec: h.mse_codec,
5259
- initSegment: h.init_segment,
5260
- audioTrackCount: h.audio_tracks?.length || 0,
5261
- ...p && { timing: p }
5248
+ count: p.fragments?.length,
5249
+ duration: p.duration_ms,
5250
+ codec: p.mse_codec,
5251
+ initSegment: p.init_segment,
5252
+ audioTrackCount: p.audio_tracks?.length || 0,
5253
+ ...h && { timing: h }
5262
5254
  });
5263
5255
  return;
5264
- } catch (l) {
5256
+ } catch (o) {
5265
5257
  if (r.signal.aborted) return;
5266
5258
  i++;
5267
- const o = Math.round(performance.now() - c), u = Qn(t);
5268
- I("mse", `Index fetch attempt ${i} failed (${o}ms)`, {
5269
- error: l?.message,
5270
- elapsedMs: o,
5259
+ const c = Math.round(performance.now() - l), u = Qn(t);
5260
+ I("mse", `Index fetch attempt ${i} failed (${c}ms)`, {
5261
+ error: o?.message,
5262
+ elapsedMs: c,
5271
5263
  ...u && { timing: u }
5272
5264
  });
5273
5265
  const f = i <= 1 ? 0 : ht(i - 1, { baseMs: 500, capMs: a, jitter: 0 });
5274
- f > 0 && await new Promise((h) => setTimeout(h, f));
5266
+ f > 0 && await new Promise((p) => setTimeout(p, f));
5275
5267
  }
5276
5268
  }
5277
5269
  }
5278
5270
  return s(), () => {
5279
5271
  r.abort();
5280
5272
  };
5281
- }, [t]), Me(() => Nc(e, t), [e, t]);
5273
+ }, [t]), Me(() => Lc(e, t), [e, t]);
5282
5274
  }
5283
5275
  const zt = {
5284
5276
  audioTracks: [],
@@ -5289,37 +5281,37 @@ const zt = {
5289
5281
  function Pc(t) {
5290
5282
  const [e, n] = $(zt), r = aa(), s = x((u) => u.mediaPrefs.preferredAudioLang), [i, a] = $(t);
5291
5283
  i !== t && (a(t), t && n(zt));
5292
- const c = ue(() => ({ origin: ia(r), preferredAudioLang: s }));
5284
+ const l = ue(() => ({ origin: ia(r), preferredAudioLang: s }));
5293
5285
  F(() => {
5294
5286
  if (!t) return;
5295
- const u = new AbortController(), { origin: f, preferredAudioLang: h } = c();
5287
+ const u = new AbortController(), { origin: f, preferredAudioLang: p } = l();
5296
5288
  let g;
5297
5289
  return (async () => {
5298
5290
  try {
5299
5291
  if (g = await fetch(`${f}/api/media/${encodeURIComponent(t)}/tracks`, { signal: u.signal }), !g.ok) throw new Error("Failed to fetch tracks");
5300
- const b = await g.json(), p = (T) => T.startsWith("/") ? `${f}${T}` : T, v = (b.audio || []).map((T) => ({ ...T, url: p(T.url) })), S = (b.subtitles || []).map((T) => ({ ...T, url: p(T.url) })), A = v.findIndex((T) => T.lang === h), R = A >= 0 ? A : 0, _ = S.findIndex((T) => T.lang === "eng"), m = _ >= 0 ? _ : 0;
5292
+ const b = await g.json(), h = (T) => T.startsWith("/") ? `${f}${T}` : T, v = (b.audio || []).map((T) => ({ ...T, url: h(T.url) })), S = (b.subtitles || []).map((T) => ({ ...T, url: h(T.url) })), A = v.findIndex((T) => T.lang === p), R = A >= 0 ? A : 0, _ = S.findIndex((T) => T.lang === "eng"), m = _ >= 0 ? _ : 0;
5301
5293
  n({ audioTracks: v, subtitleTracks: S, selectedAudioIndex: R, selectedSubtitleIndex: m }), E("mse", "Tracks loaded", { audio: v.length, subs: S.length });
5302
5294
  } catch (b) {
5303
- const p = Y(b);
5304
- if (p.name === "AbortError") return;
5305
- I("mse", "Tracks fetch error", { mediaId: t, status: g?.status, ...p }), n(zt);
5295
+ const h = Y(b);
5296
+ if (h.name === "AbortError") return;
5297
+ I("mse", "Tracks fetch error", { mediaId: t, status: g?.status, ...h }), n(zt);
5306
5298
  }
5307
5299
  })().catch((b) => ee("mse", "Tracks load threw", { mediaId: t, ...Y(b) })), () => {
5308
5300
  u.abort();
5309
5301
  };
5310
5302
  }, [t]);
5311
- const l = j((u) => {
5303
+ const o = j((u) => {
5312
5304
  n((f) => ({ ...f, selectedAudioIndex: u }));
5313
- }, []), o = j((u) => {
5305
+ }, []), c = j((u) => {
5314
5306
  n((f) => ({ ...f, selectedSubtitleIndex: u }));
5315
5307
  }, []);
5316
5308
  return {
5317
5309
  audioTracks: e.audioTracks,
5318
5310
  subtitleTracks: e.subtitleTracks,
5319
5311
  selectedAudioIndex: e.selectedAudioIndex,
5320
- setSelectedAudioIndex: l,
5312
+ setSelectedAudioIndex: o,
5321
5313
  selectedSubtitleIndex: e.selectedSubtitleIndex,
5322
- setSelectedSubtitleIndex: o
5314
+ setSelectedSubtitleIndex: c
5323
5315
  };
5324
5316
  }
5325
5317
  const Dc = 100;
@@ -5333,7 +5325,7 @@ function Hc(t, e, n, r, s, i) {
5333
5325
  return (i?.current ?? []).forEach((_, m) => {
5334
5326
  _.hasIndex && (A[`audio:${m}`] = _.getTrackDiag(S));
5335
5327
  }), A;
5336
- }), c = ue((S, A) => {
5328
+ }), l = ue((S, A) => {
5337
5329
  for (const R of i?.current ?? [])
5338
5330
  R.hasIndex && (R.reconcileLoadedStates(), R.fetchNearby(S).catch((_) => {
5339
5331
  _?.name !== "AbortError" && I("sync", "audio FM recovery fetchNearby failed", {
@@ -5342,7 +5334,7 @@ function Hc(t, e, n, r, s, i) {
5342
5334
  error: _?.message
5343
5335
  });
5344
5336
  }));
5345
- }), l = ue((S) => s(S)), o = N(null), u = N(!1), f = N(null), h = N(null), g = N(0), b = N(null), p = N(0), v = N(null);
5337
+ }), o = ue((S) => s(S)), c = L(null), u = L(!1), f = L(null), p = L(null), g = L(0), b = L(null), h = L(0), v = L(null);
5346
5338
  F(() => {
5347
5339
  const S = t.current;
5348
5340
  if (!S || !r) return;
@@ -5352,7 +5344,7 @@ function Hc(t, e, n, r, s, i) {
5352
5344
  function R() {
5353
5345
  A();
5354
5346
  const w = t.current;
5355
- w && (p.current = w.currentTime, b.current = setTimeout(_, Oc));
5347
+ w && (h.current = w.currentTime, b.current = setTimeout(_, Oc));
5356
5348
  }
5357
5349
  function _() {
5358
5350
  b.current = null;
@@ -5362,7 +5354,7 @@ function Hc(t, e, n, r, s, i) {
5362
5354
  roomPlaying: C.snapshot.playing,
5363
5355
  videoPaused: w.paused,
5364
5356
  seekInFlight: !!P?.seekInFlight,
5365
- advancedMs: (w.currentTime - p.current) * 1e3
5357
+ advancedMs: (w.currentTime - h.current) * 1e3
5366
5358
  });
5367
5359
  if (O !== "stalled") {
5368
5360
  v.current = null, O !== "not-playing" && R();
@@ -5383,7 +5375,7 @@ function Hc(t, e, n, r, s, i) {
5383
5375
  // the playhead is the one that stopped the playhead.
5384
5376
  video: G?.getTrackDiag(H),
5385
5377
  ...a(H)
5386
- }), c(H, "silent-stall"), G) {
5378
+ }), l(H, "silent-stall"), G) {
5387
5379
  G.reconcileLoadedStates();
5388
5380
  const W = G.findNextRangeStart(H, Gt);
5389
5381
  W !== null && P ? (I("sync", "SILENT-STALL gap-skip", {
@@ -5436,7 +5428,7 @@ function Hc(t, e, n, r, s, i) {
5436
5428
  ...W
5437
5429
  });
5438
5430
  }
5439
- if (P && !J?.seekInFlight && w > 0 && c(w, "waiting"), P && G && !J?.seekInFlight && w > 0) {
5431
+ if (P && !J?.seekInFlight && w > 0 && l(w, "waiting"), P && G && !J?.seekInFlight && w > 0) {
5440
5432
  G.reconcileLoadedStates();
5441
5433
  const W = G.getBufferedAheadMs(w), X = G.findNextRangeStart(w, Gt);
5442
5434
  if (X !== null && J)
@@ -5467,12 +5459,12 @@ function Hc(t, e, n, r, s, i) {
5467
5459
  });
5468
5460
  }
5469
5461
  }
5470
- O && P && !o.current && (o.current = setTimeout(() => {
5471
- o.current = null;
5462
+ O && P && !c.current && (c.current = setTimeout(() => {
5463
+ c.current = null;
5472
5464
  const W = x.getState(), X = !!W.snapshot.leaderId && W.snapshot.leaderId === W.me.clientId, U = !!n.current?.seekInFlight;
5473
- X && !S.paused && S.readyState < 3 && !U && (I("sync", "Leader stall threshold reached — pausing room", { stallMs: Mn }), u.current = !0, Le("pause"));
5474
- }, Mn)), P && !h.current && (g.current = S.currentTime, h.current = setTimeout(() => {
5475
- h.current = null;
5465
+ X && !S.paused && S.readyState < 3 && !U && (I("sync", "Leader stall threshold reached — pausing room", { stallMs: Mn }), u.current = !0, Ne("pause"));
5466
+ }, Mn)), P && !p.current && (g.current = S.currentTime, p.current = setTimeout(() => {
5467
+ p.current = null;
5476
5468
  const W = t.current;
5477
5469
  if (!W) return;
5478
5470
  const U = x.getState().snapshot.playing, he = e.current, ie = he?.getBufferedAheadMs(W.currentTime * 1e3) ?? -1, ke = W.currentTime - g.current;
@@ -5495,10 +5487,10 @@ function Hc(t, e, n, r, s, i) {
5495
5487
  });
5496
5488
  }, Jt));
5497
5489
  }
5498
- function L() {
5499
- de.recordStallEnd(), o.current && (clearTimeout(o.current), o.current = null), h.current && (clearTimeout(h.current), h.current = null), v.current = null, R();
5490
+ function N() {
5491
+ de.recordStallEnd(), c.current && (clearTimeout(c.current), c.current = null), p.current && (clearTimeout(p.current), p.current = null), v.current = null, R();
5500
5492
  const w = x.getState(), C = w.snapshot.playing, P = !!w.snapshot.leaderId && w.snapshot.leaderId === w.me.clientId;
5501
- !C && !S.paused && l(S), P && u.current && !C && (u.current = !1, I("sync", "Leader stall recovered — resuming room", { currentTime: S.currentTime.toFixed(2) }), Le("play"));
5493
+ !C && !S.paused && o(S), P && u.current && !C && (u.current = !1, I("sync", "Leader stall recovered — resuming room", { currentTime: S.currentTime.toFixed(2) }), Ne("play"));
5502
5494
  const O = f.current !== null ? Date.now() - f.current : null;
5503
5495
  f.current = null;
5504
5496
  const H = x.getState(), G = H.snapshot.playheadMs + (H.snapshot.playing ? Date.now() - H.snapshotReceivedAt : 0), J = S.currentTime * 1e3;
@@ -5513,73 +5505,73 @@ function Hc(t, e, n, r, s, i) {
5513
5505
  function y() {
5514
5506
  v.current = null, A();
5515
5507
  }
5516
- return S.addEventListener("waiting", T), S.addEventListener("playing", L), S.addEventListener("timeupdate", m), S.addEventListener("pause", y), S.paused || R(), () => {
5517
- S.removeEventListener("waiting", T), S.removeEventListener("playing", L), S.removeEventListener("timeupdate", m), S.removeEventListener("pause", y), o.current && (clearTimeout(o.current), o.current = null), h.current && (clearTimeout(h.current), h.current = null), A(), v.current = null;
5508
+ return S.addEventListener("waiting", T), S.addEventListener("playing", N), S.addEventListener("timeupdate", m), S.addEventListener("pause", y), S.paused || R(), () => {
5509
+ S.removeEventListener("waiting", T), S.removeEventListener("playing", N), S.removeEventListener("timeupdate", m), S.removeEventListener("pause", y), c.current && (clearTimeout(c.current), c.current = null), p.current && (clearTimeout(p.current), p.current = null), A(), v.current = null;
5518
5510
  };
5519
5511
  }, [r, t, e, n]);
5520
5512
  }
5521
5513
  const Uc = 1.5;
5522
5514
  function jc(t, e, n, r, s, i) {
5523
- const a = N(null), c = N(null), l = j(() => {
5524
- a.current && (clearInterval(a.current), a.current = null), c.current?.(), c.current = null;
5515
+ const a = L(null), l = L(null), o = j(() => {
5516
+ a.current && (clearInterval(a.current), a.current = null), l.current?.(), l.current = null;
5525
5517
  }, []);
5526
5518
  return F(() => {
5527
- const o = t.current, u = e.current;
5519
+ const c = t.current, u = e.current;
5528
5520
  if (!r || !u) {
5529
- l();
5521
+ o();
5530
5522
  return;
5531
5523
  }
5532
- const f = (p) => {
5524
+ const f = (h) => {
5533
5525
  const v = i?.current;
5534
5526
  if (v)
5535
5527
  for (const S of v)
5536
- S.prefetchAround(p), S.evictBefore(p);
5528
+ S.prefetchAround(h), S.evictBefore(h);
5537
5529
  };
5538
- let h = 0;
5530
+ let p = 0;
5539
5531
  const g = () => {
5540
- if (o && u) {
5532
+ if (c && u) {
5541
5533
  if (n.current?.seekInFlight) return;
5542
- h = performance.now();
5543
- const p = o.currentTime * 1e3;
5544
- u.prefetchAround(p), u.evictBefore(p), f(p);
5545
- const v = u.getBufferedEnd(p);
5534
+ p = performance.now();
5535
+ const h = c.currentTime * 1e3;
5536
+ u.prefetchAround(h), u.evictBefore(h), f(h);
5537
+ const v = u.getBufferedEnd(h);
5546
5538
  s({ bufferedEndMs: v });
5547
5539
  }
5548
5540
  };
5549
5541
  a.current = setInterval(g, kn);
5550
5542
  const b = () => {
5551
- performance.now() - h >= kn * Uc && g();
5543
+ performance.now() - p >= kn * Uc && g();
5552
5544
  };
5553
- if (o && (o.addEventListener("timeupdate", b), c.current = () => o.removeEventListener("timeupdate", b)), o && !n.current?.seekInFlight) {
5554
- h = performance.now();
5555
- const p = o.currentTime * 1e3;
5556
- u.prefetchAround(p), f(p);
5545
+ if (c && (c.addEventListener("timeupdate", b), l.current = () => c.removeEventListener("timeupdate", b)), c && !n.current?.seekInFlight) {
5546
+ p = performance.now();
5547
+ const h = c.currentTime * 1e3;
5548
+ u.prefetchAround(h), f(h);
5557
5549
  }
5558
- return l;
5559
- }, [r, s, t, e, n, i, l]), { stopPrefetch: l };
5550
+ return o;
5551
+ }, [r, s, t, e, n, i, o]), { stopPrefetch: o };
5560
5552
  }
5561
5553
  function Gc(t, e, n, r, s, i) {
5562
- const a = x((f) => f.snapshot), c = x((f) => f.loadGeneration), l = N(c), o = ue((f) => s(f)), u = ue((f) => i(f));
5554
+ const a = x((f) => f.snapshot), l = x((f) => f.loadGeneration), o = L(l), c = ue((f) => s(f)), u = ue((f) => i(f));
5563
5555
  F(() => {
5564
5556
  const f = t.current;
5565
5557
  if (!f || !r) return;
5566
- const h = a.playheadMs, g = n.current, b = c !== l.current;
5567
- l.current = c, !(!b && Math.abs(h - g) <= oa) && (E("buffer", "Seek triggered", {
5568
- targetMs: h,
5558
+ const p = a.playheadMs, g = n.current, b = l !== o.current;
5559
+ o.current = l, !(!b && Math.abs(p - g) <= oa) && (E("buffer", "Seek triggered", {
5560
+ targetMs: p,
5569
5561
  lastApplied: g,
5570
- delta: Math.round(h - g),
5562
+ delta: Math.round(p - g),
5571
5563
  genChanged: b
5572
- }), n.current = h, f.submit({
5573
- targetMs: h,
5564
+ }), n.current = p, f.submit({
5565
+ targetMs: p,
5574
5566
  priority: yt.SEEK_EFFECT,
5575
5567
  caller: "seek-effect",
5576
5568
  pauseSeekResume: !0
5577
- }).catch((p) => ee("buffer", "Seek effect submit threw", Y(p))));
5578
- }, [a.playheadMs, r, c, t, n]), F(() => {
5569
+ }).catch((h) => ee("buffer", "Seek effect submit threw", Y(h))));
5570
+ }, [a.playheadMs, r, l, t, n]), F(() => {
5579
5571
  const f = e.current;
5580
5572
  if (!f || !r || t.current?.seekInFlight) return;
5581
- const h = a.playing, g = f.paused;
5582
- h && g ? (E("sync", "Play/pause sync", { playing: h, videoPaused: g, currentTime: Math.round(f.currentTime * 1e3) }), o(f)) : !h && !g && (E("sync", "Play/pause sync", { playing: h, videoPaused: g, currentTime: Math.round(f.currentTime * 1e3) }), u(f));
5573
+ const p = a.playing, g = f.paused;
5574
+ p && g ? (E("sync", "Play/pause sync", { playing: p, videoPaused: g, currentTime: Math.round(f.currentTime * 1e3) }), c(f)) : !p && !g && (E("sync", "Play/pause sync", { playing: p, videoPaused: g, currentTime: Math.round(f.currentTime * 1e3) }), u(f));
5583
5575
  }, [a.playing, r, t, e]);
5584
5576
  }
5585
5577
  function qn(t, e) {
@@ -5594,49 +5586,49 @@ function Wc(t) {
5594
5586
  const e = x((a) => a.playlist), n = x((a) => a.activePlaylistIndex), r = x((a) => a.snapshot.mediaId), s = e?.id, i = ue(() => e);
5595
5587
  F(() => {
5596
5588
  const a = i();
5597
- if (!a || !a.videos.some((l) => l.mediaId === r)) return;
5598
- const c = new AbortController();
5589
+ if (!a || !a.videos.some((o) => o.mediaId === r)) return;
5590
+ const l = new AbortController();
5599
5591
  return E("prebuffer", "Pre-buffer started", { playlistId: a.id, activeIndex: n, videoCount: a.videos.length }), (async () => {
5600
- for (let l = 0; l < a.videos.length; l++) {
5601
- if (c.signal.aborted) return;
5602
- if (l === n) continue;
5603
- const o = a.videos[l], { mediaUrl: u, indexUrl: f } = hr(o.mediaId), h = 3e3, g = async () => {
5604
- for (; !c.signal.aborted && (t.current?.getPendingCount() ?? 0) !== 0; )
5592
+ for (let o = 0; o < a.videos.length; o++) {
5593
+ if (l.signal.aborted) return;
5594
+ if (o === n) continue;
5595
+ const c = a.videos[o], { mediaUrl: u, indexUrl: f } = hr(c.mediaId), p = 3e3, g = async () => {
5596
+ for (; !l.signal.aborted && (t.current?.getPendingCount() ?? 0) !== 0; )
5605
5597
  try {
5606
- await qn(2e3, c.signal);
5598
+ await qn(2e3, l.signal);
5607
5599
  } catch {
5608
5600
  return !1;
5609
5601
  }
5610
- if (c.signal.aborted) return !1;
5602
+ if (l.signal.aborted) return !1;
5611
5603
  try {
5612
- await qn(h, c.signal);
5604
+ await qn(p, l.signal);
5613
5605
  } catch {
5614
5606
  return !1;
5615
5607
  }
5616
- return !c.signal.aborted;
5608
+ return !l.signal.aborted;
5617
5609
  };
5618
5610
  if (!await g()) return;
5619
5611
  let b;
5620
5612
  try {
5621
- const m = await fetch(f, { signal: c.signal });
5613
+ const m = await fetch(f, { signal: l.signal });
5622
5614
  if (!m.ok) {
5623
- I("prebuffer", `index.json fetch failed for ${o.mediaId}: HTTP ${m.status}`);
5615
+ I("prebuffer", `index.json fetch failed for ${c.mediaId}: HTTP ${m.status}`);
5624
5616
  continue;
5625
5617
  }
5626
5618
  b = await m.json();
5627
5619
  } catch (m) {
5628
- if (c.signal.aborted) return;
5629
- I("prebuffer", `index.json fetch error for ${o.mediaId}`, Y(m));
5620
+ if (l.signal.aborted) return;
5621
+ I("prebuffer", `index.json fetch error for ${c.mediaId}`, Y(m));
5630
5622
  continue;
5631
5623
  }
5632
- const { fragments: p, init_segment: v } = b;
5633
- if (!p?.length) continue;
5634
- const S = dn(p, 0), A = Re(p, Fe), R = Se.getInit(o.mediaId) !== void 0, _ = Se.getBufferedMs(o.mediaId, p) >= Fe;
5624
+ const { fragments: h, init_segment: v } = b;
5625
+ if (!h?.length) continue;
5626
+ const S = dn(h, 0), A = Re(h, Fe), R = Se.getInit(c.mediaId) !== void 0, _ = Se.getBufferedMs(c.mediaId, h) >= Fe;
5635
5627
  if (R && _) {
5636
- E("prebuffer", `${o.mediaId} already fully pre-buffered, skipping`);
5628
+ E("prebuffer", `${c.mediaId} already fully pre-buffered, skipping`);
5637
5629
  continue;
5638
5630
  }
5639
- if (E("prebuffer", `Pre-buffering ${o.mediaId} frags ${S}-${A}`), !R && v) {
5631
+ if (E("prebuffer", `Pre-buffering ${c.mediaId} frags ${S}-${A}`), !R && v) {
5640
5632
  if (!await g()) return;
5641
5633
  try {
5642
5634
  const m = await fetch(u, {
@@ -5645,46 +5637,46 @@ function Wc(t) {
5645
5637
  "X-Buffer-Ahead-Ms": String(_n)
5646
5638
  // background fetch — low priority
5647
5639
  },
5648
- signal: c.signal
5640
+ signal: l.signal
5649
5641
  });
5650
5642
  if (m.ok) {
5651
5643
  const T = await m.arrayBuffer();
5652
- Se.storeInit(o.mediaId, T), E("prebuffer", `Init cached for ${o.mediaId} (${T.byteLength}B)`);
5644
+ Se.storeInit(c.mediaId, T), E("prebuffer", `Init cached for ${c.mediaId} (${T.byteLength}B)`);
5653
5645
  }
5654
5646
  } catch (m) {
5655
- if (c.signal.aborted) return;
5656
- I("prebuffer", `Init fetch failed for ${o.mediaId}`, Y(m));
5647
+ if (l.signal.aborted) return;
5648
+ I("prebuffer", `Init fetch failed for ${c.mediaId}`, Y(m));
5657
5649
  }
5658
5650
  }
5659
5651
  for (let m = S; m <= A; m++) {
5660
- if (c.signal.aborted) return;
5661
- if (Se.hasFragment(o.mediaId, m)) continue;
5652
+ if (l.signal.aborted) return;
5653
+ if (Se.hasFragment(c.mediaId, m)) continue;
5662
5654
  if (!await g()) return;
5663
- const T = p[m];
5655
+ const T = h[m];
5664
5656
  try {
5665
- const L = await fetch(u, {
5657
+ const N = await fetch(u, {
5666
5658
  headers: {
5667
5659
  Range: `bytes=${T.start_byte}-${T.end_byte}`,
5668
5660
  "X-Buffer-Ahead-Ms": String(_n)
5669
5661
  },
5670
- signal: c.signal
5662
+ signal: l.signal
5671
5663
  });
5672
- if (L.ok) {
5673
- const y = await L.arrayBuffer();
5674
- Se.storeFragment(o.mediaId, m, y);
5664
+ if (N.ok) {
5665
+ const y = await N.arrayBuffer();
5666
+ Se.storeFragment(c.mediaId, m, y);
5675
5667
  }
5676
- } catch (L) {
5677
- if (c.signal.aborted) return;
5678
- I("prebuffer", `Fragment #${m} fetch failed for ${o.mediaId}`, Y(L));
5668
+ } catch (N) {
5669
+ if (l.signal.aborted) return;
5670
+ I("prebuffer", `Fragment #${m} fetch failed for ${c.mediaId}`, Y(N));
5679
5671
  }
5680
5672
  }
5681
- E("prebuffer", `Pre-buffer complete for ${o.mediaId}`);
5673
+ E("prebuffer", `Pre-buffer complete for ${c.mediaId}`);
5682
5674
  }
5683
5675
  E("prebuffer", "All playlist videos pre-buffered");
5684
- })().catch((l) => {
5685
- l?.name !== "AbortError" && I("prebuffer", `Pre-buffer loop error: ${l?.message}`);
5676
+ })().catch((o) => {
5677
+ o?.name !== "AbortError" && I("prebuffer", `Pre-buffer loop error: ${o?.message}`);
5686
5678
  }), () => {
5687
- E("prebuffer", "Pre-buffer aborted", { playlistId: a.id }), c.abort();
5679
+ E("prebuffer", "Pre-buffer aborted", { playlistId: a.id }), l.abort();
5688
5680
  };
5689
5681
  }, [s, n, r, t]);
5690
5682
  }
@@ -5703,23 +5695,23 @@ function Vc(t) {
5703
5695
  );
5704
5696
  }
5705
5697
  function zc(t, e, n, r, s, i) {
5706
- const a = N(!1), c = N(0), l = ue((u) => i(u)), o = ue((u) => {
5707
- const f = t.current, h = e.current;
5698
+ const a = L(!1), l = L(0), o = ue((u) => i(u)), c = ue((u) => {
5699
+ const f = t.current, p = e.current;
5708
5700
  if (!f || !s) return;
5709
- const g = x.getState(), b = f.currentTime * 1e3, p = qo(g.snapshot, g.snapshotReceivedAt, Date.now()), v = Qo({
5701
+ const g = x.getState(), b = f.currentTime * 1e3, h = qo(g.snapshot, g.snapshotReceivedAt, Date.now()), v = Qo({
5710
5702
  roomPlaying: g.snapshot.playing,
5711
- seekInFlight: !!h?.seekInFlight,
5703
+ seekInFlight: !!p?.seekInFlight,
5712
5704
  elementPaused: f.paused,
5713
5705
  elementMs: b,
5714
- roomMs: p,
5706
+ roomMs: h,
5715
5707
  durationMs: r,
5716
5708
  driftToleranceMs: Jo
5717
- }), S = Math.round(p - b);
5709
+ }), S = Math.round(h - b);
5718
5710
  if (v.kind === "none") {
5719
5711
  E(Ce, "resync not needed", { reason: u, driftMs: S });
5720
5712
  return;
5721
5713
  }
5722
- v.kind === "seek" ? I(Ce, "BG-RESYNC seek", { reason: u, driftMs: S, elementMs: Math.round(b) }) : E(Ce, "resync", { reason: u, plan: v.kind, driftMs: S }), v.kind === "resume" ? i(f) : h && h.submit({ targetMs: v.targetMs, priority: yt.SEEK_EFFECT, caller: `bg-resync:${u}` });
5714
+ v.kind === "seek" ? I(Ce, "BG-RESYNC seek", { reason: u, driftMs: S, elementMs: Math.round(b) }) : E(Ce, "resync", { reason: u, plan: v.kind, driftMs: S }), v.kind === "resume" ? i(f) : p && p.submit({ targetMs: v.targetMs, priority: yt.SEEK_EFFECT, caller: `bg-resync:${u}` });
5723
5715
  });
5724
5716
  F(() => {
5725
5717
  const u = t.current;
@@ -5732,43 +5724,43 @@ function zc(t, e, n, r, s, i) {
5732
5724
  seekInFlight: !!e.current?.seekInFlight,
5733
5725
  ended: u.ended,
5734
5726
  localPause: a.current,
5735
- sinceUserPauseMs: c.current ? Date.now() - c.current : 1 / 0
5736
- }) && (E(Ce, "keep-alive: browser paused a hidden video, resuming", { currentMs: Math.round(u.currentTime * 1e3) }), l(u));
5737
- }, h = () => {
5738
- document.visibilityState === "visible" && (a.current = !1, o("visible"));
5727
+ sinceUserPauseMs: l.current ? Date.now() - l.current : 1 / 0
5728
+ }) && (E(Ce, "keep-alive: browser paused a hidden video, resuming", { currentMs: Math.round(u.currentTime * 1e3) }), o(u));
5729
+ }, p = () => {
5730
+ document.visibilityState === "visible" && (a.current = !1, c("visible"));
5739
5731
  };
5740
- return u.addEventListener("pause", f), document.addEventListener("visibilitychange", h), () => {
5741
- u.removeEventListener("pause", f), document.removeEventListener("visibilitychange", h);
5732
+ return u.addEventListener("pause", f), document.addEventListener("visibilitychange", p), () => {
5733
+ u.removeEventListener("pause", f), document.removeEventListener("visibilitychange", p);
5742
5734
  };
5743
5735
  }, [s, t, e]), F(() => {
5744
5736
  const u = t.current;
5745
5737
  if (!u || typeof navigator > "u" || !("mediaSession" in navigator)) return;
5746
5738
  const f = navigator.mediaSession;
5747
- let h = !1;
5739
+ let p = !1;
5748
5740
  const g = Qr(n), b = (_) => {
5749
- h || typeof MediaMetadata > "u" || (f.metadata = new MediaMetadata({
5741
+ p || typeof MediaMetadata > "u" || (f.metadata = new MediaMetadata({
5750
5742
  title: g,
5751
5743
  artist: "Watch Party",
5752
5744
  artwork: _ ? [{ src: _ }] : []
5753
5745
  }));
5754
5746
  };
5755
5747
  b(null), Vc(Yo(n).map(ca)).then(b);
5756
- const p = (_) => () => {
5748
+ const h = (_) => () => {
5757
5749
  const m = x.getState(), T = zo(_, { isLeader: Kc(), roomPlaying: m.snapshot.playing });
5758
- switch (E(Ce, "media session press", { action: _, result: T.kind }), _ === "pause" && (c.current = Date.now()), T.kind) {
5750
+ switch (E(Ce, "media session press", { action: _, result: T.kind }), _ === "pause" && (l.current = Date.now()), T.kind) {
5759
5751
  case "control":
5760
- Le(T.control), T.control === "pause" && u.pause();
5752
+ Ne(T.control), T.control === "pause" && u.pause();
5761
5753
  break;
5762
5754
  case "local-pause":
5763
5755
  a.current = !0, u.pause();
5764
5756
  break;
5765
5757
  case "resync":
5766
- a.current = !1, o("media-session");
5758
+ a.current = !1, c("media-session");
5767
5759
  break;
5768
5760
  }
5769
5761
  }, v = [
5770
- ["play", p("play")],
5771
- ["pause", p("pause")],
5762
+ ["play", h("play")],
5763
+ ["pause", h("pause")],
5772
5764
  // Seeking from the lock screen is not a room control; show no seek buttons.
5773
5765
  ["seekbackward", null],
5774
5766
  ["seekforward", null],
@@ -5794,7 +5786,7 @@ function zc(t, e, n, r, s, i) {
5794
5786
  f.playbackState = "paused", S();
5795
5787
  };
5796
5788
  return u.addEventListener("play", A), u.addEventListener("pause", R), u.addEventListener("seeked", S), u.addEventListener("ratechange", S), S(), () => {
5797
- h = !0, u.removeEventListener("play", A), u.removeEventListener("pause", R), u.removeEventListener("seeked", S), u.removeEventListener("ratechange", S);
5789
+ p = !0, u.removeEventListener("play", A), u.removeEventListener("pause", R), u.removeEventListener("seeked", S), u.removeEventListener("ratechange", S);
5798
5790
  for (const [_] of v)
5799
5791
  try {
5800
5792
  f.setActionHandler(_, null);
@@ -5805,34 +5797,34 @@ function zc(t, e, n, r, s, i) {
5805
5797
  }, [n, r, t]), F(() => {
5806
5798
  const u = t.current;
5807
5799
  if (!u || typeof navigator > "u" || !("wakeLock" in navigator)) return;
5808
- let f = null, h = !1, g = !1;
5800
+ let f = null, p = !1, g = !1;
5809
5801
  const b = () => {
5810
5802
  const v = f;
5811
5803
  f = null, v && v.release().catch((S) => E(Ce, "wake lock release failed", Y(S)));
5812
- }, p = () => {
5804
+ }, h = () => {
5813
5805
  if (!(!g && !u.paused && !u.ended && document.visibilityState === "visible")) {
5814
5806
  b();
5815
5807
  return;
5816
5808
  }
5817
- f || h || (h = !0, navigator.wakeLock.request("screen").then((S) => {
5818
- h = !1, f = S, S.addEventListener("release", () => {
5809
+ f || p || (p = !0, navigator.wakeLock.request("screen").then((S) => {
5810
+ p = !1, f = S, S.addEventListener("release", () => {
5819
5811
  f === S && (f = null);
5820
5812
  }), (g || u.paused || document.visibilityState !== "visible") && b();
5821
5813
  }).catch((S) => {
5822
- h = !1, E(Ce, "wake lock refused", Y(S));
5814
+ p = !1, E(Ce, "wake lock refused", Y(S));
5823
5815
  }));
5824
5816
  };
5825
- return u.addEventListener("play", p), u.addEventListener("pause", p), u.addEventListener("ended", p), document.addEventListener("visibilitychange", p), p(), () => {
5826
- g = !0, u.removeEventListener("play", p), u.removeEventListener("pause", p), u.removeEventListener("ended", p), document.removeEventListener("visibilitychange", p), b();
5817
+ return u.addEventListener("play", h), u.addEventListener("pause", h), u.addEventListener("ended", h), document.addEventListener("visibilitychange", h), h(), () => {
5818
+ g = !0, u.removeEventListener("play", h), u.removeEventListener("pause", h), u.removeEventListener("ended", h), document.removeEventListener("visibilitychange", h), b();
5827
5819
  };
5828
5820
  }, [t]);
5829
5821
  }
5830
5822
  const ft = 5e3, Yn = ".ctr-bar-wrapper";
5831
5823
  function Jc(t, e, n, r) {
5832
5824
  const s = ue((a) => {
5833
- const c = t.current;
5834
- if (!c) return;
5835
- const l = c.querySelector(Yn), o = document.activeElement, u = yr(o) ? "text" : l && o && l.contains(o) ? "bar" : !o || o === document.body || o === c ? "idle" : "elsewhere", f = Da({
5825
+ const l = t.current;
5826
+ if (!l) return;
5827
+ const o = l.querySelector(Yn), c = document.activeElement, u = yr(c) ? "text" : o && c && o.contains(c) ? "bar" : !c || c === document.body || c === l ? "idle" : "elsewhere", f = Da({
5836
5828
  key: a.key,
5837
5829
  back: Ve(a),
5838
5830
  modifier: a.ctrlKey || a.metaKey || a.altKey,
@@ -5840,45 +5832,45 @@ function Jc(t, e, n, r) {
5840
5832
  focus: u
5841
5833
  });
5842
5834
  if (f === "ignore") {
5843
- u === "text" && l && o && l.contains(o) && (n(ft), Xn(a, l, o));
5835
+ u === "text" && o && c && o.contains(c) && (n(ft), Xn(a, o, c));
5844
5836
  return;
5845
5837
  }
5846
- const h = o?.hasAttribute(et) ?? !1;
5838
+ const p = c?.hasAttribute(et) ?? !1;
5847
5839
  if (f === "leave-bar") {
5848
- if (a.preventDefault(), h) {
5849
- o?.removeAttribute(et), n(ft);
5840
+ if (a.preventDefault(), p) {
5841
+ c?.removeAttribute(et), n(ft);
5850
5842
  return;
5851
5843
  }
5852
- c.focus({ preventScroll: !0 }), r();
5844
+ l.focus({ preventScroll: !0 }), r();
5853
5845
  return;
5854
5846
  }
5855
5847
  if (n(ft), f === "show") {
5856
- if (u !== "bar" || !l || !o) return;
5857
- if (a.key === "Enter" && mr(o) === "range") {
5858
- a.preventDefault(), h ? o.removeAttribute(et) : o.setAttribute(et, "");
5848
+ if (u !== "bar" || !o || !c) return;
5849
+ if (a.key === "Enter" && mr(c) === "range") {
5850
+ a.preventDefault(), p ? c.removeAttribute(et) : c.setAttribute(et, "");
5859
5851
  return;
5860
5852
  }
5861
- Xn(a, l, o);
5853
+ Xn(a, o, c);
5862
5854
  return;
5863
5855
  }
5864
- a.preventDefault(), E("controls", `remote key ${f}`, { key: a.key }), f === "enter-bar" && l && br(l)?.focus({ preventScroll: !0 });
5856
+ a.preventDefault(), E("controls", `remote key ${f}`, { key: a.key }), f === "enter-bar" && o && br(o)?.focus({ preventScroll: !0 });
5865
5857
  });
5866
5858
  F(() => {
5867
- const a = (c) => s(c);
5859
+ const a = (l) => s(l);
5868
5860
  return window.addEventListener("keydown", a, !0), () => window.removeEventListener("keydown", a, !0);
5869
5861
  }, []);
5870
5862
  const i = ue((a) => {
5871
- const c = t.current?.querySelector(Yn);
5872
- c && a.target instanceof Node && c.contains(a.target) && n(ft);
5863
+ const l = t.current?.querySelector(Yn);
5864
+ l && a.target instanceof Node && l.contains(a.target) && n(ft);
5873
5865
  });
5874
5866
  F(() => {
5875
5867
  const a = t.current;
5876
5868
  if (!a) return;
5877
- const c = (o) => i(o), l = (o) => {
5878
- o.target instanceof Element && o.target.removeAttribute(et);
5869
+ const l = (c) => i(c), o = (c) => {
5870
+ c.target instanceof Element && c.target.removeAttribute(et);
5879
5871
  };
5880
- return a.addEventListener("focusin", c), a.addEventListener("focusout", l), () => {
5881
- a.removeEventListener("focusin", c), a.removeEventListener("focusout", l);
5872
+ return a.addEventListener("focusin", l), a.addEventListener("focusout", o), () => {
5873
+ a.removeEventListener("focusin", l), a.removeEventListener("focusout", o);
5882
5874
  };
5883
5875
  }, [t]);
5884
5876
  }
@@ -5886,40 +5878,40 @@ function Xn(t, e, n) {
5886
5878
  const r = n instanceof HTMLInputElement && n.type !== "range" ? n : null, s = r ? { atStart: (r.selectionEnd ?? 0) === 0, atEnd: (r.selectionStart ?? 0) === r.value.length } : void 0, i = Ba(t.key, mr(n), n.hasAttribute(et), s);
5887
5879
  if (i === null) return;
5888
5880
  t.preventDefault();
5889
- const a = gr(e), c = a.indexOf(n);
5890
- a[Math.min(a.length - 1, Math.max(0, c + i))]?.focus({ preventScroll: !1 });
5881
+ const a = gr(e), l = a.indexOf(n);
5882
+ a[Math.min(a.length - 1, Math.max(0, l + i))]?.focus({ preventScroll: !1 });
5891
5883
  }
5892
5884
  const Qc = 3e5, qc = 1, Yc = 1;
5893
5885
  function Qt(t) {
5894
5886
  ee("buffer", "initializePlayback threw", Y(t));
5895
5887
  }
5896
5888
  function Xc({ mediaUrl: t, indexUrl: e, mediaId: n }) {
5897
- const r = N(null), s = N(null), [i, a] = $(!1), [c, l] = $(!1), { controlsVisible: o, showControls: u, hideControls: f, setControlsHeld: h } = Fc();
5898
- Jc(s, o, u, f), F(() => {
5899
- const M = () => l(!!document.fullscreenElement);
5889
+ const r = L(null), s = L(null), [i, a] = $(!1), [l, o] = $(!1), { controlsVisible: c, showControls: u, hideControls: f, setControlsHeld: p } = Fc();
5890
+ Jc(s, c, u, f), F(() => {
5891
+ const M = () => o(!!document.fullscreenElement);
5900
5892
  return document.addEventListener("fullscreenchange", M), () => document.removeEventListener("fullscreenchange", M);
5901
5893
  }, []);
5902
5894
  const {
5903
5895
  fragments: g,
5904
5896
  durationMs: b,
5905
- mseCodec: p,
5897
+ mseCodec: h,
5906
5898
  initSegment: v,
5907
5899
  audioTracks: S,
5908
5900
  contentToken: A
5909
5901
  } = $c(e), R = j((M) => {
5910
5902
  if (!A) return null;
5911
- const B = t.replace(new RegExp(`/${Et.replace(/\./g, "\\.")}$`), "");
5903
+ const B = t.replace(new RegExp(`/${xt.replace(/\./g, "\\.")}$`), "");
5912
5904
  return B === t ? null : { baseUrl: B, token: A, trackId: M };
5913
- }, [A, t]), m = p !== null && S.length > 0, T = x((M) => M.readiness), L = la(), y = ze();
5905
+ }, [A, t]), m = h !== null && S.length > 0, T = x((M) => M.readiness), N = la(), y = ze();
5914
5906
  F(() => {
5915
5907
  const M = s.current;
5916
5908
  if (!M) return;
5917
5909
  const B = document.activeElement;
5918
5910
  if (B && B !== document.body && B !== M) return;
5919
- const oe = M.querySelector(".ctr-bar-wrapper"), V = oe?.querySelector("[data-remote-primary]"), ce = L && oe && !V?.disabled ? br(oe) : null;
5911
+ const oe = M.querySelector(".ctr-bar-wrapper"), V = oe?.querySelector("[data-remote-primary]"), ce = N && oe && !V?.disabled ? br(oe) : null;
5920
5912
  ce ? (u(ft), ce.focus({ preventScroll: !0 })) : B !== M && M.focus({ preventScroll: !0 });
5921
- }, [L, T.ready, y, u]);
5922
- const w = N(!1), C = N(!1), P = N(null), O = N(null), H = N(null), G = N(0), J = N(0), D = N(null), [W, X] = $(0), U = N([]), he = N([]), ie = N(-1), ke = N(!1), ve = N(null), at = N(0), Je = N(null), _e = N(0), St = x((M) => M.bufferState), it = x((M) => M.setBufferState), {
5913
+ }, [N, T.ready, y, u]);
5914
+ const w = L(!1), C = L(!1), P = L(null), O = L(null), H = L(null), G = L(0), J = L(0), D = L(null), [W, X] = $(0), U = L([]), he = L([]), ie = L(-1), ke = L(!1), ve = L(null), at = L(0), Je = L(null), _e = L(0), wt = x((M) => M.bufferState), it = x((M) => M.setBufferState), {
5923
5915
  audioTracks: Be,
5924
5916
  subtitleTracks: z,
5925
5917
  selectedAudioIndex: te,
@@ -5934,7 +5926,7 @@ function Xc({ mediaUrl: t, indexUrl: e, mediaId: n }) {
5934
5926
  }), ds = j(() => {
5935
5927
  const M = !ct;
5936
5928
  mn(M), hn(M);
5937
- }, [ct, hn]), wt = j((M) => {
5929
+ }, [ct, hn]), Et = j((M) => {
5938
5930
  const B = x.getState();
5939
5931
  Xr(M, {
5940
5932
  userWantsMuted: B.mediaPrefs.muted,
@@ -5965,7 +5957,7 @@ function Xc({ mediaUrl: t, indexUrl: e, mediaId: n }) {
5965
5957
  attempt: J.current
5966
5958
  }), X((B) => B + 1);
5967
5959
  }, [n]);
5968
- async function Lt() {
5960
+ async function Nt() {
5969
5961
  const M = H.current, B = r.current;
5970
5962
  if (!M || !g.length || C.current) return;
5971
5963
  const oe = x.getState().snapshot, V = oe.playheadMs || 0;
@@ -6023,7 +6015,7 @@ function Xc({ mediaUrl: t, indexUrl: e, mediaId: n }) {
6023
6015
  initDurationMs: Math.round(performance.now() - ce)
6024
6016
  });
6025
6017
  const He = x.getState().snapshot;
6026
- if (B && He.playing && B.paused && (E("buffer", "initializePlayback: calling play()", { playing: He.playing }), wt(B)), M.isDisposed) return;
6018
+ if (B && He.playing && B.paused && (E("buffer", "initializePlayback: calling play()", { playing: He.playing }), Et(B)), M.isDisposed) return;
6027
6019
  const fe = x.getState();
6028
6020
  if (!(!!fe.snapshot.leaderId && fe.snapshot.leaderId === fe.me.clientId) && fe.snapshot.playing)
6029
6021
  try {
@@ -6044,17 +6036,17 @@ function Xc({ mediaUrl: t, indexUrl: e, mediaId: n }) {
6044
6036
  priority: yt.VIEWER_CORRECTION,
6045
6037
  caller: "viewer-correction",
6046
6038
  pauseSeekResume: !0,
6047
- onComplete: (Ne) => {
6048
- at.current = Ne, E("buffer", "Viewer correction applied", {
6039
+ onComplete: (Le) => {
6040
+ at.current = Le, E("buffer", "Viewer correction applied", {
6049
6041
  startMs: V,
6050
6042
  correctedMs: se,
6051
6043
  seekTarget: Ie,
6052
- actualMs: Ne,
6044
+ actualMs: Le,
6053
6045
  totalInitMs: Math.round(performance.now() - ce)
6054
6046
  });
6055
6047
  },
6056
- onAborted: (Ne) => {
6057
- Ne === null ? I("buffer", "Viewer correction preempted by sync seek — OK") : I("buffer", "Viewer correction aborted", { error: Ne?.message });
6048
+ onAborted: (Le) => {
6049
+ Le === null ? I("buffer", "Viewer correction preempted by sync seek — OK") : I("buffer", "Viewer correction aborted", { error: Le?.message });
6058
6050
  }
6059
6051
  });
6060
6052
  }
@@ -6071,7 +6063,7 @@ function Xc({ mediaUrl: t, indexUrl: e, mediaId: n }) {
6071
6063
  error: le?.message
6072
6064
  }), a(!0), C.current = !0;
6073
6065
  const ne = x.getState().snapshot;
6074
- B && ne.playing && B.paused && wt(B);
6066
+ B && ne.playing && B.paused && Et(B);
6075
6067
  } else {
6076
6068
  const ne = le?.message || "";
6077
6069
  if (M.isDisposed || ne.includes("FragmentManager disposed")) {
@@ -6092,7 +6084,7 @@ function Xc({ mediaUrl: t, indexUrl: e, mediaId: n }) {
6092
6084
  mediaId: n,
6093
6085
  attempt: G.current
6094
6086
  }), setTimeout(() => {
6095
- H.current && !M.isDisposed && !C.current && (E("buffer", "Retrying initializePlayback"), Lt().catch(Qt));
6087
+ H.current && !M.isDisposed && !C.current && (E("buffer", "Retrying initializePlayback"), Nt().catch(Qt));
6096
6088
  }, 3e3));
6097
6089
  }
6098
6090
  }
@@ -6103,10 +6095,10 @@ function Xc({ mediaUrl: t, indexUrl: e, mediaId: n }) {
6103
6095
  mseAudioTracks: S,
6104
6096
  fragments: g,
6105
6097
  deliveryFor: R,
6106
- initializePlayback: Lt
6098
+ initializePlayback: Nt
6107
6099
  }));
6108
6100
  F(() => {
6109
- if (!p) return;
6101
+ if (!h) return;
6110
6102
  const {
6111
6103
  useMseAudio: M,
6112
6104
  selectedAudioIndex: B,
@@ -6142,9 +6134,9 @@ function Xc({ mediaUrl: t, indexUrl: e, mediaId: n }) {
6142
6134
  networkState: q.networkState,
6143
6135
  readyState: q.readyState
6144
6136
  }), x.getState().pushToast("error", "Video playback error. Try reloading."));
6145
- }, fe = t.replace(new RegExp(`/${Et.replace(/\./g, "\\.")}$`), ""), Te = () => {
6137
+ }, fe = t.replace(new RegExp(`/${xt.replace(/\./g, "\\.")}$`), ""), Te = () => {
6146
6138
  try {
6147
- const K = `video/mp4; codecs="${p}"`;
6139
+ const K = `video/mp4; codecs="${h}"`;
6148
6140
  MediaSource.isTypeSupported(K) || (I("mse", `Codec not supported by browser MSE: ${K}`), x.getState().pushToast("error", "Video codec not supported by your browser.")), E("mse", `addSourceBuffer: ${K}`);
6149
6141
  const se = Q.addSourceBuffer(K);
6150
6142
  if (P.current = se, se.addEventListener("error", () => {
@@ -6168,11 +6160,11 @@ function Xc({ mediaUrl: t, indexUrl: e, mediaId: n }) {
6168
6160
  updating: Ie.updating
6169
6161
  });
6170
6162
  });
6171
- const Ne = new nt(
6163
+ const Le = new nt(
6172
6164
  lt,
6173
6165
  { suppressEndOfStream: !0, label: `audio:${pe.track_id}` }
6174
6166
  );
6175
- Ne.setSourceBuffer(Ie, Q), U.current.push(Ne), he.current.push(Ie), ie.current = ae, E("mse", `Audio SB added: codec=${me} track=${pe.track_id} lang=${pe.lang} idx=${ae}`);
6167
+ Le.setSourceBuffer(Ie, Q), U.current.push(Le), he.current.push(Ie), ie.current = ae, E("mse", `Audio SB added: codec=${me} track=${pe.track_id} lang=${pe.lang} idx=${ae}`);
6176
6168
  } catch (Ie) {
6177
6169
  I("mse", `Audio SB creation failed for track ${pe.track_id}`, { error: Ie?.message });
6178
6170
  }
@@ -6217,13 +6209,13 @@ function Xc({ mediaUrl: t, indexUrl: e, mediaId: n }) {
6217
6209
  }
6218
6210
  Je.current?.(), C.current = !1, w.current = !1, P.current = null, a(!1);
6219
6211
  };
6220
- }, [t, n, p, v, lt, W]);
6212
+ }, [t, n, h, v, lt, W]);
6221
6213
  const ms = ue(() => {
6222
6214
  const M = H.current, B = _e.current;
6223
6215
  if (O.current?.readyState === "open" && P.current && g.length && M) {
6224
6216
  if (M.hasIndex && M.epoch === B) return;
6225
6217
  if (M.setIndex(g, t, v, n, R()), M.epoch = B, m) {
6226
- const oe = t.replace(new RegExp(`/${Et.replace(/\./g, "\\.")}$`), ""), V = ie.current, ce = U.current[0], le = V >= 0 ? S[V] : void 0;
6218
+ const oe = t.replace(new RegExp(`/${xt.replace(/\./g, "\\.")}$`), ""), V = ie.current, ce = U.current[0], le = V >= 0 ? S[V] : void 0;
6227
6219
  if (ce && le && !(ce.hasIndex && ce.epoch === B)) {
6228
6220
  const ne = `${oe}/${le.path}`.replace(/\\/g, "/");
6229
6221
  ce.setIndex(
@@ -6235,7 +6227,7 @@ function Xc({ mediaUrl: t, indexUrl: e, mediaId: n }) {
6235
6227
  ), ce.epoch = B;
6236
6228
  }
6237
6229
  }
6238
- C.current || Lt().catch(Qt);
6230
+ C.current || Nt().catch(Qt);
6239
6231
  }
6240
6232
  });
6241
6233
  F(() => {
@@ -6298,7 +6290,7 @@ function Xc({ mediaUrl: t, indexUrl: e, mediaId: n }) {
6298
6290
  { suppressEndOfStream: !0, label: `audio:${V.track_id}` }
6299
6291
  );
6300
6292
  Q.setSourceBuffer(re, M);
6301
- const Oe = `${t.replace(new RegExp(`/${Et.replace(/\./g, "\\.")}$`), "")}/${V.path}`.replace(/\\/g, "/");
6293
+ const Oe = `${t.replace(new RegExp(`/${xt.replace(/\./g, "\\.")}$`), "")}/${V.path}`.replace(/\\/g, "/");
6302
6294
  Q.setIndex(
6303
6295
  V.fragments,
6304
6296
  Oe,
@@ -6317,7 +6309,7 @@ function Xc({ mediaUrl: t, indexUrl: e, mediaId: n }) {
6317
6309
  ke.current = !1;
6318
6310
  }
6319
6311
  })().catch((ne) => ee("audio", "MSE audio swap failed", Y(ne)));
6320
- }, [m, i, te, S, n, t, lt, R]), Gc(ve, r, at, i, wt, gn), Hc(r, H, ve, i, gn, U), zc(r, ve, n, b ?? 0, i, wt);
6312
+ }, [m, i, te, S, n, t, lt, R]), Gc(ve, r, at, i, Et, gn), Hc(r, H, ve, i, gn, U), zc(r, ve, n, b ?? 0, i, Et);
6321
6313
  const { stopPrefetch: vn } = jc(r, H, ve, i, it, U);
6322
6314
  Wc(H), F(() => {
6323
6315
  Je.current = vn;
@@ -6334,7 +6326,7 @@ function Xc({ mediaUrl: t, indexUrl: e, mediaId: n }) {
6334
6326
  ref: s,
6335
6327
  tabIndex: -1,
6336
6328
  "data-testid": "media-player",
6337
- className: `relative w-full h-full bg-black outline-none ${c && !o ? "cursor-none" : ""}`,
6329
+ className: `relative w-full h-full bg-black outline-none ${l && !c ? "cursor-none" : ""}`,
6338
6330
  onMouseEnter: () => u(3e3),
6339
6331
  onMouseMove: () => u(3e3),
6340
6332
  onMouseLeave: f,
@@ -6358,14 +6350,14 @@ function Xc({ mediaUrl: t, indexUrl: e, mediaId: n }) {
6358
6350
  enabled: ct
6359
6351
  }
6360
6352
  ),
6361
- /* @__PURE__ */ d(Xo, { mediaId: n, visible: o }),
6353
+ /* @__PURE__ */ d(Xo, { mediaId: n, visible: c }),
6362
6354
  /* @__PURE__ */ d(
6363
6355
  Wo,
6364
6356
  {
6365
6357
  videoRef: r,
6366
6358
  mediaId: n,
6367
6359
  durationMs: b || void 0,
6368
- visible: o,
6360
+ visible: c,
6369
6361
  displayPlayheadMs: us,
6370
6362
  audioTracks: Be,
6371
6363
  selectedAudioIndex: te,
@@ -6382,7 +6374,7 @@ function Xc({ mediaUrl: t, indexUrl: e, mediaId: n }) {
6382
6374
  subtitleStyle: pn,
6383
6375
  onSubtitleStyleChange: as,
6384
6376
  onChatActivity: () => u(5e3),
6385
- onMenuHeld: h
6377
+ onMenuHeld: p
6386
6378
  }
6387
6379
  ),
6388
6380
  rs && /* @__PURE__ */ k(
@@ -6400,7 +6392,7 @@ function Xc({ mediaUrl: t, indexUrl: e, mediaId: n }) {
6400
6392
  ]
6401
6393
  }
6402
6394
  ),
6403
- St.isBuffering && T.ready && /* @__PURE__ */ d("div", { className: "absolute inset-0 flex items-center justify-center pointer-events-none", children: /* @__PURE__ */ k("div", { className: "flex flex-col items-center gap-2", children: [
6395
+ wt.isBuffering && T.ready && /* @__PURE__ */ d("div", { className: "absolute inset-0 flex items-center justify-center pointer-events-none", children: /* @__PURE__ */ k("div", { className: "flex flex-col items-center gap-2", children: [
6404
6396
  /* @__PURE__ */ d("div", { className: "w-8 h-8 border-2 border-text border-t-transparent rounded-full animate-spin" }),
6405
6397
  /* @__PURE__ */ d("div", { className: "px-4 py-2 rounded bg-wp-surface-2/80 text-xs font-medium", children: "Buffering…" })
6406
6398
  ] }) })
@@ -6433,19 +6425,19 @@ const el = (t) => {
6433
6425
  id: "player",
6434
6426
  name: "Media player",
6435
6427
  load: () => Promise.resolve(tl)
6436
- }, rl = sn(() => import("./MediaDrawer-uvZch1sP.js"));
6428
+ }, rl = sn(() => import("./MediaDrawer-Dml5XUN3.js"));
6437
6429
  function sl() {
6438
6430
  const t = x((u) => u.snapshot), e = x((u) => u.ensureAutoIdentity), n = Rt(), r = Me(
6439
6431
  () => n ? Ja(n, window.location.origin) : null,
6440
6432
  [n]
6441
- ), s = ma(), i = N(!1), [a, c] = $(!1), l = s.roomKey || null;
6433
+ ), s = ma(), i = L(!1), [a, l] = $(!1), o = s.roomKey || null;
6442
6434
  So(), F(() => wo(), []), F(() => Mo(), []), F(() => {
6443
- l && To(l);
6444
- }, [l]), F(() => {
6445
- const u = () => c(!0);
6435
+ o && To(o);
6436
+ }, [o]), F(() => {
6437
+ const u = () => l(!0);
6446
6438
  return window.addEventListener(Yt, u), () => window.removeEventListener(Yt, u);
6447
6439
  }, []), F(() => {
6448
- if (!l || i.current) return;
6440
+ if (!o || i.current) return;
6449
6441
  let u = !1;
6450
6442
  const f = 1500;
6451
6443
  return (async () => {
@@ -6462,56 +6454,66 @@ function sl() {
6462
6454
  I("room", "pre-join wait threw, proceeding anyway", { err: b?.message });
6463
6455
  }
6464
6456
  if (u) return;
6465
- const h = x.getState();
6466
- E("room", "Joining room", { roomKey: l, name: h.name, sprite: h.sprite }), e();
6457
+ const p = x.getState();
6458
+ E("room", "Joining room", { roomKey: o, name: p.name, sprite: p.sprite }), e();
6467
6459
  const g = x.getState();
6468
6460
  va({
6469
- room_key: l,
6461
+ room_key: o,
6470
6462
  name: g.name || void 0,
6471
6463
  sprite: g.sprite || void 0
6472
6464
  }), i.current = !0;
6473
6465
  })(), () => {
6474
6466
  u = !0;
6475
6467
  };
6476
- }, [l, e]);
6477
- function o() {
6478
- E("room", "Closing media drawer"), c(!1);
6468
+ }, [o, e]);
6469
+ function c() {
6470
+ E("room", "Closing media drawer"), l(!1);
6479
6471
  }
6480
- return l ? /* @__PURE__ */ k("div", { className: "relative flex-1 flex overflow-hidden min-h-0", children: [
6472
+ return o ? /* @__PURE__ */ k("div", { className: "relative flex-1 flex overflow-hidden min-h-0", children: [
6481
6473
  /* @__PURE__ */ k("div", { className: "flex-1 relative bg-black overflow-hidden min-w-0", children: [
6482
6474
  /* @__PURE__ */ d(In, { activity: nl, roomKey: t.roomId ?? "", layer: "base" }),
6483
6475
  r && t.roomId && /* @__PURE__ */ d(xr, { children: /* @__PURE__ */ d(In, { activity: r, roomKey: t.roomId, layer: "overlay" }, r.id) }),
6484
6476
  /* @__PURE__ */ k(Xi, { children: [
6485
- /* @__PURE__ */ d(Oi, {}),
6477
+ /* @__PURE__ */ d(al, {}),
6486
6478
  /* @__PURE__ */ d(Ji, {}),
6487
6479
  /* @__PURE__ */ d(mo, {}),
6488
6480
  /* @__PURE__ */ d(Yi, {})
6489
6481
  ] })
6490
6482
  ] }),
6491
6483
  /* @__PURE__ */ d(Fi, {}),
6492
- /* @__PURE__ */ d(Ke.Suspense, { fallback: /* @__PURE__ */ d(Pi, { open: a, onClose: o }), children: /* @__PURE__ */ d(rl, { open: a, onClose: o }) })
6484
+ /* @__PURE__ */ d(Ke.Suspense, { fallback: /* @__PURE__ */ d(Pi, { open: a, onClose: c }), children: /* @__PURE__ */ d(rl, { open: a, onClose: c }) })
6493
6485
  ] }) : (I("room", "No room key provided"), /* @__PURE__ */ d("div", { className: "flex-1 flex items-center justify-center p-6", children: /* @__PURE__ */ k("div", { className: "text-text-secondary", children: [
6494
6486
  "No room key provided. Go to the ",
6495
6487
  /* @__PURE__ */ d("a", { href: "/", className: "underline", children: "home page" }),
6496
6488
  " to select a room."
6497
6489
  ] }) }));
6498
6490
  }
6499
- const gl = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
6491
+ function al() {
6492
+ const t = x((s) => s.floatingChatEnabled), e = x((s) => s.chatCollapsed), n = x((s) => !!s.snapshot.mediaId), r = St();
6493
+ return /* @__PURE__ */ d(
6494
+ Oi,
6495
+ {
6496
+ shown: qa(t, { hasMedia: n, chatCollapsed: e, isFullscreen: r }),
6497
+ className: "absolute right-4 bottom-[35%] w-80 z-20"
6498
+ }
6499
+ );
6500
+ }
6501
+ const bl = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
6500
6502
  __proto__: null,
6501
6503
  default: sl
6502
6504
  }, Symbol.toStringTag, { value: "Module" }));
6503
6505
  export {
6504
- hl as B,
6506
+ pl as B,
6505
6507
  $i as D,
6506
- gl as R,
6507
- pl as S,
6508
- Ni as a,
6508
+ bl as R,
6509
+ ml as S,
6510
+ Li as a,
6509
6511
  Io as b,
6510
- fl as c,
6512
+ hl as c,
6511
6513
  ze as d,
6512
6514
  Ve as i,
6513
6515
  kr as p,
6514
- ml as s,
6516
+ gl as s,
6515
6517
  ln as u
6516
6518
  };
6517
- //# sourceMappingURL=Room-DYGrZm4g.js.map
6519
+ //# sourceMappingURL=Room-BM4nddV8.js.map