@wyxos/vibe 5.5.4 → 5.5.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js CHANGED
@@ -2394,34 +2394,37 @@ function Z(e, t) {
2394
2394
  let n = new Set(e.map((e) => e.postId));
2395
2395
  return [...e, ...t.filter((e) => n.has(e.postId) ? !1 : (n.add(e.postId), !0))];
2396
2396
  }
2397
+ function Vt(e) {
2398
+ return Object.prototype.hasOwnProperty.call(e, "current") ? e.current ?? null : e.next;
2399
+ }
2397
2400
  //#endregion
2398
2401
  //#region src/core/requestDelay.ts
2399
- var Vt = 2e3, Ht = 1e4, Ut = 250, Wt = {
2402
+ var Ht = 2e3, Ut = 1e4, Wt = 250, Gt = {
2400
2403
  delayRemainingMs: null,
2401
2404
  nextRequestAt: null
2402
2405
  };
2403
- function Gt(e, t) {
2406
+ function Kt(e, t) {
2404
2407
  return e === void 0 ? t : Math.floor(e);
2405
2408
  }
2406
- function Kt(e, t) {
2409
+ function qt(e, t) {
2407
2410
  for (let [n, r] of [["delayStepMs", e.delayStepMs], ["delayMaxMs", e.delayMaxMs]]) if (r !== void 0 && (!Number.isFinite(r) || r < 0)) throw TypeError(`Vibe ${t} ${n} must be a non-negative number.`);
2408
2411
  }
2409
- function qt(e, t = {}) {
2410
- let n = Gt(t.delayStepMs, Vt), r = Gt(t.delayMaxMs, Ht);
2412
+ function Jt(e, t = {}) {
2413
+ let n = Kt(t.delayStepMs, Ht), r = Kt(t.delayMaxMs, Ut);
2411
2414
  return Math.min(Math.max(0, e) * n, r);
2412
2415
  }
2413
2416
  function Q(e) {
2414
- if (e == null || !Number.isFinite(e)) return { ...Wt };
2417
+ if (e == null || !Number.isFinite(e)) return { ...Gt };
2415
2418
  let t = Math.max(0, Math.floor(e - Date.now()));
2416
2419
  return t > 0 ? {
2417
2420
  delayRemainingMs: t,
2418
2421
  nextRequestAt: e
2419
- } : { ...Wt };
2422
+ } : { ...Gt };
2420
2423
  }
2421
- async function Jt({ delayMs: e, onChange: t, signal: n }) {
2424
+ async function Yt({ delayMs: e, onChange: t, signal: n }) {
2422
2425
  if (n.aborted) throw new DOMException("Aborted", "AbortError");
2423
2426
  if (e <= 0) {
2424
- t({ ...Wt });
2427
+ t({ ...Gt });
2425
2428
  return;
2426
2429
  }
2427
2430
  let r = Date.now() + e;
@@ -2429,9 +2432,9 @@ async function Jt({ delayMs: e, onChange: t, signal: n }) {
2429
2432
  delayRemainingMs: e,
2430
2433
  nextRequestAt: r
2431
2434
  }), await new Promise((i, a) => {
2432
- let o = !1, s = setInterval(f, Ut), c = setTimeout(() => u(), e);
2435
+ let o = !1, s = setInterval(f, Wt), c = setTimeout(() => u(), e);
2433
2436
  function l() {
2434
- clearInterval(s), clearTimeout(c), n.removeEventListener("abort", d), t({ ...Wt });
2437
+ clearInterval(s), clearTimeout(c), n.removeEventListener("abort", d), t({ ...Gt });
2435
2438
  }
2436
2439
  function u(e) {
2437
2440
  o || (o = !0, l(), e ? a(e) : i());
@@ -2446,13 +2449,13 @@ async function Jt({ delayMs: e, onChange: t, signal: n }) {
2446
2449
  n.addEventListener("abort", d, { once: !0 });
2447
2450
  });
2448
2451
  }
2449
- var Yt = class {
2452
+ var Xt = class {
2450
2453
  interval = null;
2451
2454
  constructor(e) {
2452
2455
  this.onChange = e;
2453
2456
  }
2454
2457
  clear() {
2455
- this.interval !== null && clearInterval(this.interval), this.interval = null, this.onChange({ ...Wt });
2458
+ this.interval !== null && clearInterval(this.interval), this.interval = null, this.onChange({ ...Gt });
2456
2459
  }
2457
2460
  sync(e) {
2458
2461
  this.clear();
@@ -2460,22 +2463,22 @@ var Yt = class {
2460
2463
  this.onChange(t), t.delayRemainingMs !== null && (this.interval = setInterval(() => {
2461
2464
  let t = Q(e);
2462
2465
  this.onChange(t), t.delayRemainingMs === null && this.clear();
2463
- }, Ut));
2466
+ }, Wt));
2464
2467
  }
2465
2468
  };
2466
- function Xt(e, t = !0) {
2469
+ function Zt(e, t = !0) {
2467
2470
  return e.maxAdditionalPages === "unlimited" ? Infinity : (e.maxAdditionalPages ?? 10) + (t ? 1 : 0);
2468
2471
  }
2469
- function Zt(e) {
2472
+ function Qt(e) {
2470
2473
  return `${typeof e}:${String(e)}`;
2471
2474
  }
2472
- function Qt(e, t) {
2475
+ function $t(e, t) {
2473
2476
  if (!Number.isInteger(e) || e <= 0) throw TypeError(`Vibe ${t} must be a positive integer.`);
2474
2477
  }
2475
- function $t(e) {
2478
+ function en(e) {
2476
2479
  if (!e) return;
2477
- if (Qt(e.pageSize, "autofill pageSize"), e.strategy === "frontend") {
2478
- Kt(e, "frontend autofill");
2480
+ if ($t(e.pageSize, "autofill pageSize"), e.strategy === "frontend") {
2481
+ qt(e, "frontend autofill");
2479
2482
  let t = e.maxAdditionalPages;
2480
2483
  if (t !== void 0 && t !== "unlimited" && (!Number.isInteger(t) || t < 0)) throw TypeError("Vibe autofill maxAdditionalPages must be a non-negative integer or \"unlimited\".");
2481
2484
  return;
@@ -2487,7 +2490,7 @@ function $t(e) {
2487
2490
  if (t.pageSize !== e.pageSize) throw TypeError("Vibe backend autofill initialSession pageSize must match autofill pageSize.");
2488
2491
  }
2489
2492
  }
2490
- function en(e, t, n = !0) {
2493
+ function tn(e, t, n = !0) {
2491
2494
  if (!e) return {
2492
2495
  cycleId: null,
2493
2496
  delayRemainingMs: null,
@@ -2521,7 +2524,7 @@ function en(e, t, n = !0) {
2521
2524
  strategy: e.strategy
2522
2525
  };
2523
2526
  }
2524
- function tn(e) {
2527
+ function nn(e) {
2525
2528
  return [
2526
2529
  "cancelling",
2527
2530
  "filling",
@@ -2529,9 +2532,9 @@ function tn(e) {
2529
2532
  "waiting"
2530
2533
  ].includes(e.status);
2531
2534
  }
2532
- async function nn(e, t, n) {
2535
+ async function rn(e, t, n) {
2533
2536
  let r = t.autofill;
2534
- if (!tn(r) || !r.cycleId) return;
2537
+ if (!nn(r) || !r.cycleId) return;
2535
2538
  let i = {
2536
2539
  cycleId: r.cycleId,
2537
2540
  feedKey: r.feedKey ?? "",
@@ -2544,16 +2547,16 @@ async function nn(e, t, n) {
2544
2547
  throw r.error = e, r.status = "error", e;
2545
2548
  }
2546
2549
  }
2547
- function rn(e, t, n) {
2550
+ function an(e, t, n) {
2548
2551
  return e?.strategy === "backend" && t.feedKey === e.feedKey && t.sessionId === n.sessionId;
2549
2552
  }
2550
- async function an({ existingItems: e, initialCursor: t, loadPage: n, maximumRequests: r, onCollection: i, onDelayChange: a, onProgress: o, options: s, receivedOffset: c = 0, requestOffset: l = 0, shouldPause: u = () => !1, signal: d }) {
2551
- let f = [], p = [...e], m = /* @__PURE__ */ new Set(), h = r ?? Xt(s), g = t, _ = t, v = t, y = 0, b = [], x;
2553
+ async function on({ existingItems: e, initialCursor: t, loadPage: n, maximumRequests: r, onCollection: i, onDelayChange: a, onProgress: o, options: s, receivedOffset: c = 0, requestOffset: l = 0, shouldPause: u = () => !1, signal: d }) {
2554
+ let f = [], p = [...e], m = /* @__PURE__ */ new Set(), h = r ?? Zt(s), g = t, _ = t, v = t, y = 0, b = [], x;
2552
2555
  for (; y < h;) {
2553
- let e = Zt(g);
2556
+ let e = Qt(g);
2554
2557
  if (m.has(e)) throw Error("Vibe autofill received a repeated cursor.");
2555
- if (m.add(e), await Jt({
2556
- delayMs: qt(l + y, s),
2558
+ if (m.add(e), await Yt({
2559
+ delayMs: Jt(l + y, s),
2557
2560
  onChange: a,
2558
2561
  signal: d
2559
2562
  }), y > 0 && u()) return {
@@ -2624,12 +2627,12 @@ async function an({ existingItems: e, initialCursor: t, loadPage: n, maximumRequ
2624
2627
  }
2625
2628
  //#endregion
2626
2629
  //#region src/core/autofillController.ts
2627
- var on = class {
2630
+ var sn = class {
2628
2631
  collection = null;
2629
2632
  cycle = 0;
2630
2633
  delayCountdown;
2631
2634
  constructor(e) {
2632
- this.context = e, this.delayCountdown = new Yt((t) => Object.assign(e.state.autofill, t)), this.syncCountdown();
2635
+ this.context = e, this.delayCountdown = new Xt((t) => Object.assign(e.state.autofill, t)), this.syncCountdown();
2633
2636
  }
2634
2637
  beginCycle() {
2635
2638
  let { options: e, state: t } = this.context;
@@ -2637,14 +2640,14 @@ var on = class {
2637
2640
  this.clear();
2638
2641
  let n = `vibe-autofill-${Date.now().toString(36)}-${++this.cycle}`;
2639
2642
  return t.autofill = {
2640
- ...en(e, void 0, !1),
2643
+ ...tn(e, void 0, !1),
2641
2644
  cycleId: n,
2642
2645
  status: "filling"
2643
2646
  }, n;
2644
2647
  }
2645
2648
  async cancel() {
2646
2649
  let { cancelRequest: e, options: t, state: n } = this.context;
2647
- await nn(t, n, e), this.commitCollection();
2650
+ await rn(t, n, e), this.commitCollection();
2648
2651
  }
2649
2652
  captureCollection(e, t) {
2650
2653
  t && (this.collection = e);
@@ -2672,30 +2675,30 @@ var on = class {
2672
2675
  requests: r.requests
2673
2676
  }), !0) : !1;
2674
2677
  }
2675
- }, sn = 100;
2676
- function cn(e, t) {
2678
+ }, cn = 100;
2679
+ function ln(e, t) {
2677
2680
  if (!Number.isFinite(t) || t <= 0) throw TypeError(`Vibe ${e} must be a positive number.`);
2678
2681
  }
2679
- function ln(e, t, n) {
2682
+ function un(e, t, n) {
2680
2683
  return Math.min(n, Math.max(t, e));
2681
2684
  }
2682
- function un(e) {
2685
+ function dn(e) {
2683
2686
  if (!e) return;
2684
2687
  let t = e.minSpeedPxPerSecond ?? 20, n = e.maxSpeedPxPerSecond ?? 240;
2685
- if (cn("autoScroll.minSpeedPxPerSecond", t), cn("autoScroll.maxSpeedPxPerSecond", n), t > n) throw TypeError("Vibe autoScroll.minSpeedPxPerSecond cannot exceed maxSpeedPxPerSecond.");
2686
- e.speedPxPerSecond !== void 0 && cn("autoScroll.speedPxPerSecond", e.speedPxPerSecond);
2688
+ if (ln("autoScroll.minSpeedPxPerSecond", t), ln("autoScroll.maxSpeedPxPerSecond", n), t > n) throw TypeError("Vibe autoScroll.minSpeedPxPerSecond cannot exceed maxSpeedPxPerSecond.");
2689
+ e.speedPxPerSecond !== void 0 && ln("autoScroll.speedPxPerSecond", e.speedPxPerSecond);
2687
2690
  }
2688
- function dn(e) {
2691
+ function fn(e) {
2689
2692
  let t = e?.minSpeedPxPerSecond ?? 20, n = e?.maxSpeedPxPerSecond ?? 240;
2690
2693
  return {
2691
2694
  enabled: e?.enabled ?? !1,
2692
2695
  maxSpeedPxPerSecond: n,
2693
2696
  minSpeedPxPerSecond: t,
2694
2697
  paused: !1,
2695
- speedPxPerSecond: ln(e?.speedPxPerSecond ?? 80, t, n)
2698
+ speedPxPerSecond: un(e?.speedPxPerSecond ?? 80, t, n)
2696
2699
  };
2697
2700
  }
2698
- var fn = class {
2701
+ var pn = class {
2699
2702
  frame = null;
2700
2703
  lastTimestamp = null;
2701
2704
  mounted = !1;
@@ -2715,9 +2718,9 @@ var fn = class {
2715
2718
  this.options.state.enabled && (this.options.state.paused = e, this.lastTimestamp = null, e ? this.cancelFrame() : this.schedule());
2716
2719
  }
2717
2720
  setSpeed(e) {
2718
- cn("auto-scroll speed", e);
2721
+ ln("auto-scroll speed", e);
2719
2722
  let t = this.options.state;
2720
- t.speedPxPerSecond = ln(e, t.minSpeedPxPerSecond, t.maxSpeedPxPerSecond);
2723
+ t.speedPxPerSecond = un(e, t.minSpeedPxPerSecond, t.maxSpeedPxPerSecond);
2721
2724
  }
2722
2725
  tick = (e) => {
2723
2726
  this.frame = null;
@@ -2729,7 +2732,7 @@ var fn = class {
2729
2732
  return;
2730
2733
  }
2731
2734
  if (this.lastTimestamp !== null) {
2732
- let r = Math.min(sn, Math.max(0, e - this.lastTimestamp)), i = Math.max(0, n.scrollHeight - n.clientHeight);
2735
+ let r = Math.min(cn, Math.max(0, e - this.lastTimestamp)), i = Math.max(0, n.scrollHeight - n.clientHeight);
2733
2736
  n.scrollTop = Math.min(i, n.scrollTop + t.speedPxPerSecond * r / 1e3);
2734
2737
  }
2735
2738
  this.lastTimestamp = e, this.schedule();
@@ -2743,7 +2746,7 @@ var fn = class {
2743
2746
  };
2744
2747
  //#endregion
2745
2748
  //#region src/core/backendAutofill.ts
2746
- async function pn(e, t, n, r) {
2749
+ async function mn(e, t, n, r) {
2747
2750
  let i = await e.onUnderfilled(n);
2748
2751
  if (!r()) return;
2749
2752
  if (!i.sessionId.trim()) throw TypeError("Vibe backend autofill requires a sessionId.");
@@ -2757,19 +2760,19 @@ async function pn(e, t, n, r) {
2757
2760
  status: "waiting"
2758
2761
  });
2759
2762
  }
2760
- function mn(e, t) {
2763
+ function hn(e, t) {
2761
2764
  ["complete", "exhausted"].includes(t.status) && t.items && (e.items = Z(e.items, t.items)), t.next !== void 0 && (e.next = t.next), t.total !== void 0 && (e.total = t.total);
2762
2765
  }
2763
- function hn(e, t, n) {
2766
+ function gn(e, t, n) {
2764
2767
  let r = t.autofill;
2765
- return !rn(e, n, r) || n.sequence <= r.sequence || ["cancelled", "cancelling"].includes(r.status) || ["complete", "exhausted"].includes(n.status) && n.next === void 0 ? !1 : (mn(t, n), Object.assign(r, Q(n.status === "waiting" ? n.nextRequestAt : null)), r.error = n.error ?? null, r.missing = Math.max(0, (r.pageSize ?? 0) - n.received), r.received = n.received, n.requests !== void 0 && (r.requests = n.requests), r.sequence = n.sequence, r.status = n.status, !0);
2768
+ return !an(e, n, r) || n.sequence <= r.sequence || ["cancelled", "cancelling"].includes(r.status) || ["complete", "exhausted"].includes(n.status) && n.next === void 0 ? !1 : (hn(t, n), Object.assign(r, Q(n.status === "waiting" ? n.nextRequestAt : null)), r.error = n.error ?? null, r.missing = Math.max(0, (r.pageSize ?? 0) - n.received), r.received = n.received, n.requests !== void 0 && (r.requests = n.requests), r.sequence = n.sequence, r.status = n.status, !0);
2766
2769
  }
2767
- function gn(e, t, n) {
2768
- return e?.strategy !== "backend" || n.feedKey !== e.feedKey || n.pageSize !== e.pageSize ? !1 : (t.autofill = en(e, n), mn(t, n), !0);
2770
+ function _n(e, t, n) {
2771
+ return e?.strategy !== "backend" || n.feedKey !== e.feedKey || n.pageSize !== e.pageSize ? !1 : (t.autofill = tn(e, n), hn(t, n), !0);
2769
2772
  }
2770
2773
  //#endregion
2771
2774
  //#region src/core/initialAutofill.ts
2772
- async function _n({ cycleId: e, isCurrent: t, onCollection: n, onLastCursor: r, onPages: i, options: a, signal: o, state: s }) {
2775
+ async function vn({ cycleId: e, isCurrent: t, onCollection: n, onLastCursor: r, onPages: i, options: a, signal: o, state: s }) {
2773
2776
  let c = a.autofill;
2774
2777
  if (!c) return;
2775
2778
  let l = s.items.length;
@@ -2782,7 +2785,7 @@ async function _n({ cycleId: e, isCurrent: t, onCollection: n, onLastCursor: r,
2782
2785
  return;
2783
2786
  }
2784
2787
  if (c.strategy === "backend") {
2785
- await pn(c, s, {
2788
+ await mn(c, s, {
2786
2789
  cycleId: e,
2787
2790
  feedKey: c.feedKey,
2788
2791
  items: [...s.items],
@@ -2799,11 +2802,11 @@ async function _n({ cycleId: e, isCurrent: t, onCollection: n, onLastCursor: r,
2799
2802
  s.autofill.status = "exhausted";
2800
2803
  return;
2801
2804
  }
2802
- let u = await an({
2805
+ let u = await on({
2803
2806
  existingItems: s.items,
2804
2807
  initialCursor: s.next,
2805
2808
  loadPage: a.loadPage,
2806
- maximumRequests: Xt(c, !1),
2809
+ maximumRequests: Zt(c, !1),
2807
2810
  onCollection: n,
2808
2811
  onDelayChange: (e) => {
2809
2812
  t() && Object.assign(s.autofill, e);
@@ -2826,13 +2829,13 @@ async function _n({ cycleId: e, isCurrent: t, onCollection: n, onLastCursor: r,
2826
2829
  }
2827
2830
  //#endregion
2828
2831
  //#region src/core/fill.ts
2829
- function vn(e) {
2832
+ function yn(e) {
2830
2833
  return "pages" in e ? { pages: e.pages } : { until: "end" };
2831
2834
  }
2832
- function yn(e) {
2835
+ function bn(e) {
2833
2836
  return `${typeof e}:${String(e)}`;
2834
2837
  }
2835
- function bn(e) {
2838
+ function xn(e) {
2836
2839
  if (!e || typeof e != "object") throw TypeError("Vibe fill target must be an object.");
2837
2840
  if ("pages" in e) {
2838
2841
  if (!Number.isInteger(e.pages) || e.pages <= 0) throw TypeError("Vibe fill pages must be a positive integer.");
@@ -2841,20 +2844,20 @@ function bn(e) {
2841
2844
  if ("until" in e && e.until === "end") return { until: "end" };
2842
2845
  throw TypeError("Vibe fill target must be { pages } or { until: 'end' }.");
2843
2846
  }
2844
- function xn(e) {
2847
+ function Sn(e) {
2845
2848
  if (!e) return;
2846
2849
  if (e.strategy === "frontend") {
2847
- Kt(e, "frontend fill");
2850
+ qt(e, "frontend fill");
2848
2851
  return;
2849
2852
  }
2850
2853
  if (!e.feedKey.trim()) throw TypeError("Vibe backend fill requires a feedKey.");
2851
2854
  let t = e.initialSession;
2852
2855
  if (t) {
2853
2856
  if (t.feedKey !== e.feedKey) throw TypeError("Vibe backend fill initialSession feedKey must match fill feedKey.");
2854
- bn(t.target);
2857
+ xn(t.target);
2855
2858
  }
2856
2859
  }
2857
- function Sn(e, t, n = !0) {
2860
+ function Cn(e, t, n = !0) {
2858
2861
  let r = e?.strategy === "backend" && n ? e.initialSession : void 0, i = t ?? r, a = Q(i?.nextRequestAt);
2859
2862
  return {
2860
2863
  completedPages: i?.completedPages ?? 0,
@@ -2868,10 +2871,10 @@ function Sn(e, t, n = !0) {
2868
2871
  sessionId: i?.sessionId ?? null,
2869
2872
  status: i?.status ?? "idle",
2870
2873
  strategy: e?.strategy ?? null,
2871
- target: i ? vn(i.target) : null
2874
+ target: i ? yn(i.target) : null
2872
2875
  };
2873
2876
  }
2874
- function Cn(e) {
2877
+ function wn(e) {
2875
2878
  return [
2876
2879
  "cancelling",
2877
2880
  "filling",
@@ -2879,13 +2882,13 @@ function Cn(e) {
2879
2882
  "waiting"
2880
2883
  ].includes(e.status);
2881
2884
  }
2882
- async function wn({ existingItems: e, initialCursor: t, loadPage: n, onCollection: r = () => void 0, onDelayChange: i, onProgress: a, options: o, shouldPause: s = () => !1, signal: c, target: l }) {
2885
+ async function Tn({ existingItems: e, initialCursor: t, loadPage: n, onCollection: r = () => void 0, onDelayChange: i, onProgress: a, options: o, shouldPause: s = () => !1, signal: c, target: l }) {
2883
2886
  let u = [], d = [], f = [...e], p = /* @__PURE__ */ new Set(), m = 0, h = t, g = t, _ = t, v = 0, y;
2884
2887
  for (; _ !== null;) {
2885
- let e = yn(h);
2888
+ let e = bn(h);
2886
2889
  if (p.has(e)) throw Error("Vibe fill received a repeated cursor.");
2887
- if (p.add(e), await Jt({
2888
- delayMs: qt(m, o),
2890
+ if (p.add(e), await Yt({
2891
+ delayMs: Jt(m, o),
2889
2892
  onChange: i,
2890
2893
  signal: c
2891
2894
  }), m > 0 && s()) return {
@@ -2966,7 +2969,7 @@ async function wn({ existingItems: e, initialCursor: t, loadPage: n, onCollectio
2966
2969
  }
2967
2970
  //#endregion
2968
2971
  //#region src/core/backendFill.ts
2969
- async function Tn(e, t, n, r) {
2972
+ async function En(e, t, n, r) {
2970
2973
  let i = await e.onStart(n);
2971
2974
  if (r()) {
2972
2975
  if (!i.sessionId.trim()) throw TypeError("Vibe backend fill requires a sessionId.");
@@ -2980,22 +2983,22 @@ async function Tn(e, t, n, r) {
2980
2983
  });
2981
2984
  }
2982
2985
  }
2983
- function En(e, t, n) {
2986
+ function Dn(e, t, n) {
2984
2987
  return e?.strategy === "backend" && n.feedKey === e.feedKey && n.sessionId === t.fill.sessionId;
2985
2988
  }
2986
- function Dn(e) {
2989
+ function On(e) {
2987
2990
  return Number.isInteger(e.completedPages) && e.completedPages >= 0 && Number.isInteger(e.received) && e.received >= 0 && Number.isInteger(e.sequence) && e.sequence >= 0;
2988
2991
  }
2989
- function On(e, t) {
2992
+ function kn(e, t) {
2990
2993
  if (!["complete", "exhausted"].includes(t.status)) return !0;
2991
2994
  let n = e.fill.target;
2992
2995
  return !n || !Array.isArray(t.items) || t.next === void 0 || t.lastCursor === void 0 ? !1 : t.status === "exhausted" ? "pages" in n && t.completedPages < n.pages && t.next === null : "pages" in n ? t.completedPages === n.pages : t.next === null;
2993
2996
  }
2994
- function kn(e, t, n) {
2997
+ function An(e, t, n) {
2995
2998
  t.total !== void 0 && (e.total = t.total), ["complete", "exhausted"].includes(t.status) && (e.items = Z(e.items, t.items ?? []), e.next = t.next ?? null, n(t.lastCursor ?? null));
2996
2999
  }
2997
- function An(e, t, n, r) {
2998
- return !En(e, t, n) || !Dn(n) || n.sequence <= t.fill.sequence || ["cancelled", "cancelling"].includes(t.fill.status) || !On(t, n) ? !1 : (kn(t, n, r), Object.assign(t.fill, {
3000
+ function jn(e, t, n, r) {
3001
+ return !Dn(e, t, n) || !On(n) || n.sequence <= t.fill.sequence || ["cancelled", "cancelling"].includes(t.fill.status) || !kn(t, n) ? !1 : (An(t, n, r), Object.assign(t.fill, {
2999
3002
  ...Q(n.status === "waiting" ? n.nextRequestAt : null),
3000
3003
  completedPages: n.completedPages,
3001
3004
  error: n.error ?? null,
@@ -3004,45 +3007,45 @@ function An(e, t, n, r) {
3004
3007
  status: n.status
3005
3008
  }), !0);
3006
3009
  }
3007
- function jn(e, t, n, r) {
3010
+ function Mn(e, t, n, r) {
3008
3011
  if (e?.strategy !== "backend" || n.feedKey !== e.feedKey) return !1;
3009
3012
  let i = t.fill;
3010
- return t.fill = Sn(e, n), !Dn(n) || !On(t, n) ? (t.fill = i, !1) : (kn(t, n, r), !0);
3013
+ return t.fill = Cn(e, n), !On(n) || !kn(t, n) ? (t.fill = i, !1) : (An(t, n, r), !0);
3011
3014
  }
3012
3015
  //#endregion
3013
3016
  //#region src/core/fillController.ts
3014
- var Mn = class {
3017
+ var Nn = class {
3015
3018
  abortController = null;
3016
3019
  cycle = 0;
3017
3020
  delayCountdown;
3018
3021
  requestVersion = 0;
3019
3022
  collection = null;
3020
3023
  constructor(e) {
3021
- this.options = e, this.delayCountdown = new Yt((e) => {
3024
+ this.options = e, this.delayCountdown = new Xt((e) => {
3022
3025
  Object.assign(this.options.state.fill, e);
3023
3026
  }), this.syncBackendCountdown();
3024
3027
  }
3025
3028
  isActive() {
3026
- return Cn(this.options.state.fill);
3029
+ return wn(this.options.state.fill);
3027
3030
  }
3028
3031
  applyUpdate(e) {
3029
- let t = An(this.options.fill, this.options.state, e, this.options.onLastCursor);
3032
+ let t = jn(this.options.fill, this.options.state, e, this.options.onLastCursor);
3030
3033
  return t && this.syncBackendCountdown(), t;
3031
3034
  }
3032
3035
  restoreSession(e) {
3033
- let t = jn(this.options.fill, this.options.state, e, this.options.onLastCursor);
3036
+ let t = Mn(this.options.fill, this.options.state, e, this.options.onLastCursor);
3034
3037
  return t && this.syncBackendCountdown(), t;
3035
3038
  }
3036
3039
  async start(e, t = {}) {
3037
3040
  let n = this.options.fill;
3038
3041
  if (!n) throw Error("Vibe fill is not configured.");
3039
3042
  if (this.isActive()) throw Error("Vibe fill is already active.");
3040
- let r = bn(e), i = bn(t.target ?? r), a = t.progressOffset ?? {
3043
+ let r = xn(e), i = xn(t.target ?? r), a = t.progressOffset ?? {
3041
3044
  completedPages: 0,
3042
3045
  received: 0
3043
3046
  }, o = t.cycleId ?? `vibe-fill-${Date.now().toString(36)}-${++this.cycle}`;
3044
3047
  if (this.options.state.fill = {
3045
- ...Sn(n, void 0, !1),
3048
+ ...Cn(n, void 0, !1),
3046
3049
  completedPages: a.completedPages,
3047
3050
  cycleId: o,
3048
3051
  received: a.received,
@@ -3055,7 +3058,7 @@ var Mn = class {
3055
3058
  let s = ++this.requestVersion, c = new AbortController();
3056
3059
  this.abortController = c;
3057
3060
  try {
3058
- n.strategy === "frontend" ? await this.startFrontend(n, r, c, s, t.prepareFrontend !== !1, a) : (await Tn(n, this.options.state, {
3061
+ n.strategy === "frontend" ? await this.startFrontend(n, r, c, s, t.prepareFrontend !== !1, a) : (await En(n, this.options.state, {
3059
3062
  cycleId: o,
3060
3063
  feedKey: n.feedKey,
3061
3064
  items: [...this.options.state.items],
@@ -3073,7 +3076,7 @@ var Mn = class {
3073
3076
  }
3074
3077
  async cancel() {
3075
3078
  let { fill: e, state: t } = this.options;
3076
- if (!Cn(t.fill) || !t.fill.cycleId) return;
3079
+ if (!wn(t.fill) || !t.fill.cycleId) return;
3077
3080
  let n = {
3078
3081
  cycleId: t.fill.cycleId,
3079
3082
  feedKey: t.fill.feedKey ?? "",
@@ -3103,7 +3106,7 @@ var Mn = class {
3103
3106
  });
3104
3107
  }
3105
3108
  reset() {
3106
- this.abortLocalRequest(), this.delayCountdown.clear(), this.options.state.fill = Sn(this.options.fill, void 0, !1), this.collection = null;
3109
+ this.abortLocalRequest(), this.delayCountdown.clear(), this.options.state.fill = Cn(this.options.fill, void 0, !1), this.collection = null;
3107
3110
  }
3108
3111
  destroy() {
3109
3112
  this.abortLocalRequest(), this.delayCountdown.clear();
@@ -3138,7 +3141,7 @@ var Mn = class {
3138
3141
  s.fill.status = "pages" in t ? "exhausted" : "complete";
3139
3142
  return;
3140
3143
  }
3141
- let c = await wn({
3144
+ let c = await Tn({
3142
3145
  existingItems: s.items,
3143
3146
  initialCursor: s.next,
3144
3147
  loadPage: o,
@@ -3186,7 +3189,7 @@ var Mn = class {
3186
3189
  };
3187
3190
  //#endregion
3188
3191
  //#region src/core/fillReconciliation.ts
3189
- async function Nn({ controller: e, isCurrent: t, loadPage: n, onDelayChange: r, setLastCursor: i, signal: a, state: o }) {
3192
+ async function Pn({ controller: e, isCurrent: t, loadPage: n, onDelayChange: r, setLastCursor: i, signal: a, state: o }) {
3190
3193
  if (!e.needsReconciliation(o.items)) return "skipped";
3191
3194
  let s = await e.reconcile({
3192
3195
  existingItems: o.items,
@@ -3199,7 +3202,7 @@ async function Nn({ controller: e, isCurrent: t, loadPage: n, onDelayChange: r,
3199
3202
  }
3200
3203
  //#endregion
3201
3204
  //#region src/core/feedFooter.ts
3202
- function Pn(e) {
3205
+ function Fn(e) {
3203
3206
  return {
3204
3207
  cancelAutofill: () => e.cancelAutofill(),
3205
3208
  loadMore: () => e.loadNext(),
@@ -3210,46 +3213,46 @@ function Pn(e) {
3210
3213
  retryEnd: () => e.retryEnd()
3211
3214
  };
3212
3215
  }
3213
- function Fn(e) {
3214
- if (!Number.isFinite(e) || e <= 0) throw TypeError("Vibe reelAutoAdvance.intervalMs must be a positive number.");
3215
- }
3216
3216
  function In(e) {
3217
- e?.intervalMs !== void 0 && Fn(e.intervalMs);
3217
+ if (!Number.isFinite(e) || e <= 0) throw TypeError("Vibe reelAutoAdvance.intervalMs must be a positive number.");
3218
3218
  }
3219
3219
  function Ln(e) {
3220
+ e?.intervalMs !== void 0 && In(e.intervalMs);
3221
+ }
3222
+ function Rn(e) {
3220
3223
  return {
3221
3224
  enabled: e?.enabled ?? !1,
3222
3225
  includePostItems: e?.includePostItems ?? !1,
3223
3226
  intervalMs: e?.intervalMs ?? 5e3
3224
3227
  };
3225
3228
  }
3226
- function Rn(e, t) {
3229
+ function zn(e, t) {
3227
3230
  if (typeof t == "boolean") {
3228
3231
  e.enabled = t;
3229
3232
  return;
3230
3233
  }
3231
- In(t), t.enabled !== void 0 && (e.enabled = t.enabled), t.includePostItems !== void 0 && (e.includePostItems = t.includePostItems), t.intervalMs !== void 0 && (e.intervalMs = t.intervalMs);
3234
+ Ln(t), t.enabled !== void 0 && (e.enabled = t.enabled), t.includePostItems !== void 0 && (e.includePostItems = t.includePostItems), t.intervalMs !== void 0 && (e.intervalMs = t.intervalMs);
3232
3235
  }
3233
3236
  //#endregion
3234
3237
  //#region src/core/reelInfoSheet.ts
3235
- function zn(e) {
3238
+ function Bn(e) {
3236
3239
  return { enabled: e?.enabled ?? !1 };
3237
3240
  }
3238
- function Bn(e, t, n) {
3241
+ function Vn(e, t, n) {
3239
3242
  if (n && !t) throw Error("Vibe cannot enable reelInfoSheet without a configured component.");
3240
3243
  e.enabled = n;
3241
3244
  }
3242
3245
  //#endregion
3243
3246
  //#region src/core/initialRuntimeState.ts
3244
- function Vn(e, t) {
3247
+ function Hn(e, t) {
3245
3248
  let n = e.initialPage;
3246
3249
  return {
3247
3250
  activeReelPostId: null,
3248
- autoScroll: dn(e.autoScroll),
3249
- autofill: en(e.autofill),
3251
+ autoScroll: fn(e.autoScroll),
3252
+ autofill: tn(e.autofill),
3250
3253
  current: n?.current ?? null,
3251
3254
  error: null,
3252
- fill: Sn(e.fill),
3255
+ fill: Cn(e.fill),
3253
3256
  infiniteScroll: e.infiniteScroll ?? !0,
3254
3257
  isLoading: !n,
3255
3258
  isLoadingMore: !1,
@@ -3260,14 +3263,14 @@ function Vn(e, t) {
3260
3263
  next: n?.next ?? null,
3261
3264
  nextPageError: null,
3262
3265
  phoneMode: !1,
3263
- reelAutoAdvance: Ln(e.reelAutoAdvance),
3266
+ reelAutoAdvance: Rn(e.reelAutoAdvance),
3264
3267
  reelForward: {
3265
3268
  error: null,
3266
3269
  status: "idle"
3267
3270
  },
3268
3271
  reelForwardIndex: null,
3269
3272
  reelForwardItem: null,
3270
- reelInfoSheet: zn(e.reelInfoSheet),
3273
+ reelInfoSheet: Bn(e.reelInfoSheet),
3271
3274
  reelInfoSheetOverlay: !1,
3272
3275
  reelMediaSource: "original",
3273
3276
  reelOrigin: null,
@@ -3276,20 +3279,20 @@ function Vn(e, t) {
3276
3279
  }
3277
3280
  //#endregion
3278
3281
  //#region src/core/options.ts
3279
- function Hn(e, t) {
3282
+ function Un(e, t) {
3280
3283
  if (t) {
3281
3284
  if (!Number.isFinite(t.height) || t.height <= 0) throw TypeError(`Vibe ${e} height must be a positive number.`);
3282
3285
  if (t.background !== void 0 && t.background !== "default" && t.background !== "transparent") throw TypeError(`Vibe ${e} background must be "default" or "transparent".`);
3283
3286
  }
3284
3287
  }
3285
- function Un(e, t) {
3288
+ function Wn(e, t) {
3286
3289
  if (t) {
3287
3290
  if (t.background !== void 0 && t.background !== "default" && t.background !== "transparent") throw TypeError(`Vibe mediaCard ${e} background must be "default" or "transparent".`);
3288
3291
  for (let [n, r] of [["paddingX", t.paddingX], ["paddingY", t.paddingY]]) if (r !== void 0 && (!Number.isFinite(r) || r < 0)) throw TypeError(`Vibe mediaCard ${e} ${n} must be a non-negative number.`);
3289
3292
  }
3290
3293
  }
3291
- function Wn(e) {
3292
- if (un(e.autoScroll), Hn("cardHeader", e.cardHeader), Hn("cardFooter", e.cardFooter), Un("header", e.mediaCard?.header), Un("footer", e.mediaCard?.footer), $t(e.autofill), xn(e.fill), J(e.masonry), In(e.reelAutoAdvance), e.removalReconciliation) {
3294
+ function Gn(e) {
3295
+ if (dn(e.autoScroll), Un("cardHeader", e.cardHeader), Un("cardFooter", e.cardFooter), Wn("header", e.mediaCard?.header), Wn("footer", e.mediaCard?.footer), en(e.autofill), Sn(e.fill), J(e.masonry), Ln(e.reelAutoAdvance), e.removalReconciliation) {
3293
3296
  if (!Number.isInteger(e.removalReconciliation.pageSize) || e.removalReconciliation.pageSize <= 0) throw TypeError("Vibe removalReconciliation pageSize must be a positive integer.");
3294
3297
  let t = e.removalReconciliation.maxReplayPages ?? 5;
3295
3298
  if (!Number.isInteger(t) || t <= 0) throw TypeError("Vibe removalReconciliation maxReplayPages must be a positive integer.");
@@ -3304,7 +3307,7 @@ function Wn(e) {
3304
3307
  if (e.fill?.strategy === "frontend" && !e.loadPage) throw TypeError("Vibe frontend fill requires loadPage.");
3305
3308
  if (e.fill?.strategy === "backend" && e.fill.initialSession && !e.initialPage) throw TypeError("Vibe backend fill restoration requires initialPage.");
3306
3309
  }
3307
- function Gn(e) {
3310
+ function Kn(e) {
3308
3311
  if (typeof e != "string") return e;
3309
3312
  if (typeof document > "u") throw Error("Vibe cannot resolve a selector without a document.");
3310
3313
  let t = document.querySelector(e);
@@ -3313,7 +3316,7 @@ function Gn(e) {
3313
3316
  }
3314
3317
  //#endregion
3315
3318
  //#region src/core/pageRequest.ts
3316
- async function Kn({ append: e, autofillController: t, cursor: n, isCurrent: r, loadPage: i, onLastCursor: a, onPages: o, options: s, signal: c, state: l }) {
3319
+ async function qn({ append: e, autofillController: t, cursor: n, isCurrent: r, loadPage: i, onLastCursor: a, onPages: o, options: s, signal: c, state: l }) {
3317
3320
  let u = s.autofill, d = e && u?.strategy === "frontend" && (l.autofill.status === "paused" || l.autofill.status === "error"), f = d ? {
3318
3321
  received: l.autofill.received,
3319
3322
  requests: l.autofill.requests
@@ -3325,11 +3328,11 @@ async function Kn({ append: e, autofillController: t, cursor: n, isCurrent: r, l
3325
3328
  let m = !1;
3326
3329
  try {
3327
3330
  if (u?.strategy === "frontend") {
3328
- let s = await an({
3331
+ let s = await on({
3329
3332
  existingItems: e ? l.items : [],
3330
3333
  initialCursor: n,
3331
3334
  loadPage: i,
3332
- maximumRequests: f ? Math.max(0, Xt(u) - f.requests) : void 0,
3335
+ maximumRequests: f ? Math.max(0, Zt(u) - f.requests) : void 0,
3333
3336
  onCollection: (e) => t.captureCollection(e, r()),
3334
3337
  onDelayChange: (e) => {
3335
3338
  r() && Object.assign(l.autofill, e);
@@ -3372,7 +3375,7 @@ async function Kn({ append: e, autofillController: t, cursor: n, isCurrent: r, l
3372
3375
  l.autofill.status = "complete";
3373
3376
  return;
3374
3377
  }
3375
- await pn(u, l, {
3378
+ await mn(u, l, {
3376
3379
  cycleId: p,
3377
3380
  feedKey: u.feedKey,
3378
3381
  items: h.slice(d.length),
@@ -3397,13 +3400,13 @@ async function Kn({ append: e, autofillController: t, cursor: n, isCurrent: r, l
3397
3400
  function $(e) {
3398
3401
  return `${typeof e}:${String(e)}`;
3399
3402
  }
3400
- function qn(e) {
3403
+ function Jn(e) {
3401
3404
  return `${typeof e}:${String(e)}`;
3402
3405
  }
3403
- function Jn(e) {
3406
+ function Yn(e) {
3404
3407
  return e.map(({ postId: e }) => e);
3405
3408
  }
3406
- var Yn = class {
3409
+ var Xn = class {
3407
3410
  delay;
3408
3411
  enabled;
3409
3412
  maxReplayPages;
@@ -3435,10 +3438,10 @@ var Yn = class {
3435
3438
  }
3436
3439
  recordInitialPage(e) {
3437
3440
  e && this.recordPages([{
3438
- contributionIds: Jn(e.items),
3439
- cursor: e.current ?? null,
3441
+ contributionIds: Yn(e.items),
3442
+ cursor: Vt(e),
3440
3443
  next: e.next,
3441
- returnedIds: Jn(e.items)
3444
+ returnedIds: Yn(e.items)
3442
3445
  }]);
3443
3446
  }
3444
3447
  remove(e) {
@@ -3453,10 +3456,10 @@ var Yn = class {
3453
3456
  async reconcile({ existingItems: e, loadPage: t, onDelayChange: n = () => void 0, shouldPause: r = () => !1, signal: i }) {
3454
3457
  let a = this.pending ?? this.createSession(e);
3455
3458
  for (this.pending = a; a.remainingRequests > 0;) {
3456
- let e = qn(a.cursor);
3459
+ let e = Jn(a.cursor);
3457
3460
  if (a.seenCursors.has(e)) throw Error("Vibe removal reconciliation received a repeated cursor.");
3458
- if (await Jt({
3459
- delayMs: qt(a.pages.length, this.delay),
3461
+ if (await Yt({
3462
+ delayMs: Jt(a.pages.length, this.delay),
3460
3463
  onChange: n,
3461
3464
  signal: i
3462
3465
  }), a.pages.length > 0 && r()) return this.result(a, "paused");
@@ -3473,7 +3476,7 @@ var Yn = class {
3473
3476
  contributionIds: c,
3474
3477
  cursor: a.cursor,
3475
3478
  next: o.next,
3476
- returnedIds: Jn(s)
3479
+ returnedIds: Yn(s)
3477
3480
  }), a.lastCursor = a.cursor, a.next = o.next, --a.remainingRequests, o.total !== void 0 && (a.total = o.total), a.next === null ? a.remainingRequests = 0 : a.cursor = a.next, a.remainingRequests > 0 && r()) return this.result(a, "paused");
3478
3481
  }
3479
3482
  return this.result(a, "complete");
@@ -3512,7 +3515,7 @@ var Yn = class {
3512
3515
  return this.pages.findIndex(({ contributionIds: e }) => e.filter((e) => t.has($(e))).length < this.pageSize);
3513
3516
  }
3514
3517
  recordPage(e) {
3515
- let t = qn(e.cursor), n = this.pages.findIndex(({ cursor: e }) => qn(e) === t);
3518
+ let t = Jn(e.cursor), n = this.pages.findIndex(({ cursor: e }) => Jn(e) === t);
3516
3519
  n >= 0 && (this.pages = this.pages.slice(0, n)), this.pages.push({
3517
3520
  ...e,
3518
3521
  contributionIds: [...e.contributionIds],
@@ -3522,7 +3525,7 @@ var Yn = class {
3522
3525
  };
3523
3526
  //#endregion
3524
3527
  //#region src/core/activeItemRemoval.ts
3525
- function Xn(e, t, n, r, i) {
3528
+ function Zn(e, t, n, r, i) {
3526
3529
  let a = new Set(t.map(({ item: e }) => e.postId));
3527
3530
  if (e.activeReelPostId === null || !a.has(e.activeReelPostId)) return;
3528
3531
  let o = e.items[Math.max(n, 0)];
@@ -3535,7 +3538,7 @@ function Xn(e, t, n, r, i) {
3535
3538
  }
3536
3539
  //#endregion
3537
3540
  //#region src/core/exactMediaRemovalController.ts
3538
- function Zn(e, t) {
3541
+ function Qn(e, t) {
3539
3542
  let [n, ...r] = t;
3540
3543
  if (!n) throw Error("Vibe items must contain at least one media asset.");
3541
3544
  return {
@@ -3544,10 +3547,10 @@ function Zn(e, t) {
3544
3547
  items: r
3545
3548
  };
3546
3549
  }
3547
- function Qn(e) {
3550
+ function $n(e) {
3548
3551
  if (!Number.isInteger(e.mediaIndex) || e.mediaIndex < 0) throw TypeError("Vibe mediaIndex must be a non-negative integer.");
3549
3552
  }
3550
- var $n = class {
3553
+ var er = class {
3551
3554
  generation = 0;
3552
3555
  metadata = /* @__PURE__ */ new WeakMap();
3553
3556
  state;
@@ -3555,7 +3558,7 @@ var $n = class {
3555
3558
  this.options = e, this.state = e.state;
3556
3559
  }
3557
3560
  remove(e) {
3558
- Qn(e);
3561
+ $n(e);
3559
3562
  let t = this.state.items.findIndex(({ postId: t }) => t === e.postId), n = this.state.items[t];
3560
3563
  if (!n) return null;
3561
3564
  let r = [...M(n)], i = r[e.mediaIndex];
@@ -3572,7 +3575,7 @@ var $n = class {
3572
3575
  restored: !1
3573
3576
  });
3574
3577
  let o = this.state.mediaIndices.get(n.postId) ?? 0, s = this.isReelOpen() && this.state.activeReelPostId === n.postId, c = s && o === e.mediaIndex;
3575
- return r.splice(e.mediaIndex, 1), r.length > 0 ? (this.state.items[t] = Zn(n, r), this.updateMediaIndexAfterRemoval(n.postId, e.mediaIndex, c), a) : (this.state.items.splice(t, 1), this.options.onPostRemoved(n.postId), this.state.mediaIndices.delete(n.postId), s && this.advanceFromRemovedPost(a, n), a);
3578
+ return r.splice(e.mediaIndex, 1), r.length > 0 ? (this.state.items[t] = Qn(n, r), this.updateMediaIndexAfterRemoval(n.postId, e.mediaIndex, c), a) : (this.state.items.splice(t, 1), this.options.onPostRemoved(n.postId), this.state.mediaIndices.delete(n.postId), s && this.advanceFromRemovedPost(a, n), a);
3576
3579
  }
3577
3580
  reset() {
3578
3581
  this.generation += 1;
@@ -3598,7 +3601,7 @@ var $n = class {
3598
3601
  }
3599
3602
  restoreIntoPost(e, t) {
3600
3603
  let n = this.state.items[e], r = [...M(n)], i = Math.min(t.mediaIndex, r.length);
3601
- if (r.splice(i, 0, t.media), this.state.items[e] = Zn(n, r), this.state.activeReelPostId !== t.postId) return;
3604
+ if (r.splice(i, 0, t.media), this.state.items[e] = Qn(n, r), this.state.activeReelPostId !== t.postId) return;
3602
3605
  let a = this.state.mediaIndices.get(t.postId) ?? 0;
3603
3606
  a >= i && this.state.mediaIndices.set(t.postId, a + 1);
3604
3607
  }
@@ -3611,18 +3614,18 @@ var $n = class {
3611
3614
  };
3612
3615
  //#endregion
3613
3616
  //#region src/core/itemPlacement.ts
3614
- function er(e, t) {
3617
+ function tr(e, t) {
3615
3618
  let n = new Set(t);
3616
3619
  return e.flatMap((e, t) => n.has(e.postId) ? [{
3617
3620
  index: t,
3618
3621
  item: e
3619
3622
  }] : []);
3620
3623
  }
3621
- function tr(e, t) {
3624
+ function nr(e, t) {
3622
3625
  let n = new Set(t.map(({ item: e }) => e.postId));
3623
3626
  return e.filter((e) => !n.has(e.postId));
3624
3627
  }
3625
- function nr(e, t) {
3628
+ function rr(e, t) {
3626
3629
  t.forEach(({ index: e }) => {
3627
3630
  if (!Number.isInteger(e) || e < 0) throw Error("Vibe item restore indexes must be non-negative integers.");
3628
3631
  });
@@ -3633,7 +3636,7 @@ function nr(e, t) {
3633
3636
  }
3634
3637
  //#endregion
3635
3638
  //#region src/core/itemRemovalController.ts
3636
- var rr = 20, ir = class {
3639
+ var ir = 20, ar = class {
3637
3640
  generation = 0;
3638
3641
  historyLimit;
3639
3642
  metadata = /* @__PURE__ */ new WeakMap();
@@ -3642,7 +3645,7 @@ var rr = 20, ir = class {
3642
3645
  itemOrder;
3643
3646
  stopItemsWatcher;
3644
3647
  constructor(e) {
3645
- this.options = e, this.historyLimit = e.historyLimit ?? rr, this.state = e.state, this.itemOrder = this.state.items.map(({ postId: e }) => e), this.stopItemsWatcher = O(() => this.state.items, (e) => this.appendUnknownItems(e), { flush: "sync" });
3648
+ this.options = e, this.historyLimit = e.historyLimit ?? ir, this.state = e.state, this.itemOrder = this.state.items.map(({ postId: e }) => e), this.stopItemsWatcher = O(() => this.state.items, (e) => this.appendUnknownItems(e), { flush: "sync" });
3646
3649
  }
3647
3650
  destroy() {
3648
3651
  this.reset(), this.stopItemsWatcher();
@@ -3656,7 +3659,7 @@ var rr = 20, ir = class {
3656
3659
  let a = this.options.startRemoval(i, t);
3657
3660
  if (a > 0 && await new Promise((e) => setTimeout(e, a)), this.metadata.get(r)?.generation !== this.generation) return r;
3658
3661
  let o = this.state.items.findIndex((e) => e.postId === this.state.activeReelPostId), s = new Set(n.map(({ item: e }) => e.postId)), c = o < 0 ? 0 : this.state.items.slice(0, o).filter(({ postId: e }) => s.has(e)).length, l = Math.max(o - c, 0);
3659
- return this.state.items = tr(this.state.items, n), this.options.onItemsRemoved(r, n, l), this.record(r), r;
3662
+ return this.state.items = nr(this.state.items, n), this.options.onItemsRemoved(r, n, l), this.record(r), r;
3660
3663
  }
3661
3664
  reset() {
3662
3665
  this.generation += 1, this.history = [], this.itemOrder = [];
@@ -3667,7 +3670,7 @@ var rr = 20, ir = class {
3667
3670
  this.restoreRemoval(t);
3668
3671
  return;
3669
3672
  }
3670
- let n = new Set(this.state.items.map(({ postId: e }) => e)), r = e.filter(({ item: e }) => n.has(e.postId) ? !1 : (n.add(e.postId), !0)), i = nr(this.state.items, r);
3673
+ let n = new Set(this.state.items.map(({ postId: e }) => e)), r = e.filter(({ item: e }) => n.has(e.postId) ? !1 : (n.add(e.postId), !0)), i = rr(this.state.items, r);
3671
3674
  this.registerExternalPlacements(r), this.state.items = i, r.length > 0 && this.options.onRemovalRestored(r);
3672
3675
  }
3673
3676
  restoreRemoval(e) {
@@ -3693,7 +3696,7 @@ var rr = 20, ir = class {
3693
3696
  }
3694
3697
  collectOrderedPlacements(e) {
3695
3698
  let t = new Map(this.itemOrder.map((e, t) => [e, t]));
3696
- return er(this.state.items, e).map((e) => ({
3699
+ return tr(this.state.items, e).map((e) => ({
3697
3700
  index: t.get(e.item.postId) ?? e.index,
3698
3701
  item: e.item
3699
3702
  }));
@@ -3724,7 +3727,7 @@ var rr = 20, ir = class {
3724
3727
  let r = new Map(this.itemOrder.map((e, t) => [e, t]));
3725
3728
  return this.state.items = [...this.state.items, ...n].sort((e, t) => (r.get(e.postId) ?? 2 ** 53 - 1) - (r.get(t.postId) ?? 2 ** 53 - 1)), !0;
3726
3729
  }
3727
- }, ar = class {
3730
+ }, or = class {
3728
3731
  forward = null;
3729
3732
  forwardPromise = null;
3730
3733
  forwardVersion = 0;
@@ -3811,7 +3814,7 @@ var rr = 20, ir = class {
3811
3814
  }
3812
3815
  }
3813
3816
  }
3814
- }, or = class {
3817
+ }, sr = class {
3815
3818
  generation = 0;
3816
3819
  pending = Promise.resolve();
3817
3820
  constructor(e) {
@@ -3861,24 +3864,24 @@ var rr = 20, ir = class {
3861
3864
  };
3862
3865
  //#endregion
3863
3866
  //#region src/core/removalControllers.ts
3864
- function sr(e) {
3865
- let t = new ar(e), n = new or({
3867
+ function cr(e) {
3868
+ let t = new or(e), n = new sr({
3866
3869
  state: e.state,
3867
3870
  transitionMedia: (t) => e.surface()?.transitionActiveReelMedia(t) ?? Promise.resolve(!1),
3868
3871
  transitionPost: (t) => e.surface()?.transitionActiveReelPost(t) ?? Promise.resolve(!1)
3869
3872
  });
3870
3873
  return {
3871
- exactMediaRemoval: new $n({
3874
+ exactMediaRemoval: new er({
3872
3875
  onActivate: e.onActivate,
3873
3876
  onPostRemoved: (t) => e.onItemsRemoved([t]),
3874
3877
  onPostRestored: (t) => e.onItemsRestored([t]),
3875
3878
  reelForward: t,
3876
3879
  state: e.state
3877
3880
  }),
3878
- itemRemoval: new ir({
3881
+ itemRemoval: new ar({
3879
3882
  historyLimit: e.historyLimit,
3880
3883
  onItemsRemoved: (n, r, i) => {
3881
- e.onItemsRemoved(r.map(({ item: e }) => e.postId)), Xn(e.state, r, i, e.onActivate, (e, r) => t.start(n, e, r));
3884
+ e.onItemsRemoved(r.map(({ item: e }) => e.postId)), Zn(e.state, r, i, e.onActivate, (e, r) => t.start(n, e, r));
3882
3885
  },
3883
3886
  onRemovalRestored: (n) => {
3884
3887
  e.onItemsRestored(n.map(({ item: e }) => e.postId));
@@ -3893,17 +3896,17 @@ function sr(e) {
3893
3896
  reelRemoval: n
3894
3897
  };
3895
3898
  }
3896
- var cr = 1.5;
3897
- function lr(e) {
3899
+ var lr = 1.5;
3900
+ function ur(e) {
3898
3901
  let t = Math.min(e.screenWidth, e.screenHeight);
3899
3902
  if (t > 0 && t < 600) return !0;
3900
- let n = Math.min(e.viewportWidth, e.viewportHeight), r = t >= n * cr;
3903
+ let n = Math.min(e.viewportWidth, e.viewportHeight), r = t >= n * lr;
3901
3904
  return !e.hasHover && n > 0 && n < 600 && r;
3902
3905
  }
3903
- function ur(e) {
3904
- return lr(e) ? "reel" : "masonry";
3905
- }
3906
3906
  function dr(e) {
3907
+ return ur(e) ? "reel" : "masonry";
3908
+ }
3909
+ function fr(e) {
3907
3910
  let t = e.ownerDocument.defaultView, n = e.ownerDocument.documentElement;
3908
3911
  return {
3909
3912
  hasHover: typeof t?.matchMedia == "function" && t.matchMedia("(hover: hover)").matches,
@@ -3913,15 +3916,15 @@ function dr(e) {
3913
3916
  viewportWidth: n.clientWidth
3914
3917
  };
3915
3918
  }
3916
- function fr(e) {
3917
- return lr(dr(e));
3918
- }
3919
3919
  function pr(e) {
3920
- return ur(dr(e));
3920
+ return ur(fr(e));
3921
+ }
3922
+ function mr(e) {
3923
+ return dr(fr(e));
3921
3924
  }
3922
3925
  //#endregion
3923
3926
  //#region src/core/responsiveLayoutController.ts
3924
- var mr = class {
3927
+ var hr = class {
3925
3928
  layoutMode;
3926
3929
  resizeObserver = null;
3927
3930
  target = null;
@@ -3946,10 +3949,10 @@ var mr = class {
3946
3949
  }
3947
3950
  handleResponsiveLayout = () => {
3948
3951
  if (!this.target) return;
3949
- let e = pr(this.target);
3950
- this.state.phoneMode = fr(this.target), this.state.reelInfoSheetOverlay = this.state.phoneMode, this.state.reelMediaSource = e === "reel" ? "preview" : "original", this.layoutMode === "responsive" && this.applyLayout(e);
3952
+ let e = mr(this.target);
3953
+ this.state.phoneMode = pr(this.target), this.state.reelInfoSheetOverlay = this.state.phoneMode, this.state.reelMediaSource = e === "reel" ? "preview" : "original", this.layoutMode === "responsive" && this.applyLayout(e);
3951
3954
  };
3952
- }, hr = class {
3955
+ }, gr = class {
3953
3956
  routedReelPostId = null;
3954
3957
  reelRouteIsActive = !1;
3955
3958
  constructor(e, t) {
@@ -3976,7 +3979,7 @@ var mr = class {
3976
3979
  let i = this.reelRouteIsActive ? "replace" : "push";
3977
3980
  this.reelRouteIsActive = !0, this.routedReelPostId = e, this.options.router[i](r);
3978
3981
  }
3979
- }, gr = class {
3982
+ }, _r = class {
3980
3983
  app = null;
3981
3984
  autoScroll;
3982
3985
  autofillController;
@@ -3997,24 +4000,24 @@ var mr = class {
3997
4000
  notificationItems;
3998
4001
  state;
3999
4002
  constructor(e) {
4000
- this.options = e, Wn(e);
4003
+ this.options = e, Gn(e);
4001
4004
  let t = e.layout ?? "masonry";
4002
- this.state = x(Vn(e, t)), this.lastLoadedCursor = e.initialPage?.current ?? e.initialPage?.next ?? null, this.notificationItems = I(this.state), this.autoScroll = new fn({
4005
+ this.state = x(Hn(e, t)), this.lastLoadedCursor = e.initialPage ? Vt(e.initialPage) : null, this.notificationItems = I(this.state), this.autoScroll = new pn({
4003
4006
  getScrollElement: () => this.surface?.getAutoScrollElement() ?? null,
4004
4007
  state: this.state.autoScroll
4005
- }), this.autofillController = new on({
4008
+ }), this.autofillController = new sn({
4006
4009
  cancelRequest: () => this.cancelRequest(),
4007
4010
  onLastCursor: (e) => this.setCurrentCursor(e),
4008
4011
  onPages: (e) => this.removalReconciliation.recordPages(e),
4009
4012
  options: e.autofill,
4010
4013
  state: this.state
4011
- }), this.removalReconciliation = new Yn(e), this.removalReconciliation.recordInitialPage(e.initialPage), this.fillController = new Mn({
4014
+ }), this.removalReconciliation = new Xn(e), this.removalReconciliation.recordInitialPage(e.initialPage), this.fillController = new Nn({
4012
4015
  fill: e.fill,
4013
4016
  loadPage: e.loadPage ? (e) => this.loadFilteredPage(e) : void 0,
4014
4017
  needsFrontendPreparation: () => this.removalReconciliation.needsReconciliation(this.state.items),
4015
4018
  onLastCursor: (e) => this.setCurrentCursor(e),
4016
4019
  onPages: (e) => this.removalReconciliation.recordPages(e),
4017
- prepareFrontend: ({ isCurrent: t, onDelayChange: n, signal: r }) => Nn({
4020
+ prepareFrontend: ({ isCurrent: t, onDelayChange: n, signal: r }) => Pn({
4018
4021
  controller: this.removalReconciliation,
4019
4022
  isCurrent: t,
4020
4023
  loadPage: e.loadPage,
@@ -4024,8 +4027,8 @@ var mr = class {
4024
4027
  state: this.state
4025
4028
  }),
4026
4029
  state: this.state
4027
- }), this.routing = new hr(e.routing, this.state);
4028
- let n = sr({
4030
+ }), this.routing = new gr(e.routing, this.state);
4031
+ let n = cr({
4029
4032
  historyLimit: e.removalHistoryLimit,
4030
4033
  onActivate: (e) => this.setActiveReelPost(e),
4031
4034
  onItemsRemoved: (e) => this.removalReconciliation.remove(e),
@@ -4034,20 +4037,20 @@ var mr = class {
4034
4037
  state: this.state,
4035
4038
  surface: () => this.surface
4036
4039
  });
4037
- this.exactMediaRemoval = n.exactMediaRemoval, this.itemRemoval = n.itemRemoval, this.reelForward = n.reelForward, this.reelRemoval = n.reelRemoval, this.responsiveLayout = new mr(t, this.state, () => {
4040
+ this.exactMediaRemoval = n.exactMediaRemoval, this.itemRemoval = n.itemRemoval, this.reelForward = n.reelForward, this.reelRemoval = n.reelRemoval, this.responsiveLayout = new hr(t, this.state, () => {
4038
4041
  this.routing.syncFeed();
4039
4042
  }), this.startStateNotifications();
4040
4043
  }
4041
4044
  async mount() {
4042
4045
  if (this.app) throw Error("Vibe is already mounted.");
4043
4046
  this.startStateNotifications();
4044
- let e = Gn(this.options.target);
4047
+ let e = Kn(this.options.target);
4045
4048
  this.responsiveLayout.mount(e), this.app = i(zt, {
4046
4049
  canRetryEnd: !!this.options.loadPage,
4047
4050
  cardFooter: this.options.cardFooter,
4048
4051
  cardHeader: this.options.cardHeader,
4049
4052
  feedFooter: this.options.feedFooter,
4050
- feedFooterActions: Pn(this),
4053
+ feedFooterActions: Fn(this),
4051
4054
  mediaCard: this.options.mediaCard,
4052
4055
  masonry: this.options.masonry,
4053
4056
  onMediaReady: this.options.onMediaReady,
@@ -4130,7 +4133,7 @@ var mr = class {
4130
4133
  this.autoScroll.setSpeed(e);
4131
4134
  }
4132
4135
  applyAutofillUpdate(e) {
4133
- let t = hn(this.options.autofill, this.state, e);
4136
+ let t = gn(this.options.autofill, this.state, e);
4134
4137
  return t && this.autofillController.syncCountdown(), t;
4135
4138
  }
4136
4139
  cancelAutofill() {
@@ -4141,7 +4144,7 @@ var mr = class {
4141
4144
  await this.cancelFill();
4142
4145
  return;
4143
4146
  }
4144
- if (tn(this.state.autofill)) {
4147
+ if (nn(this.state.autofill)) {
4145
4148
  await this.cancelAutofill();
4146
4149
  return;
4147
4150
  }
@@ -4155,12 +4158,12 @@ var mr = class {
4155
4158
  }
4156
4159
  async fill(e) {
4157
4160
  if (!this.state.loadMoreLocked) {
4158
- if (this.pendingRequest || tn(this.state.autofill)) throw Error("Vibe cannot fill while another page operation is active.");
4161
+ if (this.pendingRequest || nn(this.state.autofill)) throw Error("Vibe cannot fill while another page operation is active.");
4159
4162
  await this.fillController.start(e);
4160
4163
  }
4161
4164
  }
4162
4165
  restoreAutofillSession(e) {
4163
- let t = gn(this.options.autofill, this.state, e);
4166
+ let t = _n(this.options.autofill, this.state, e);
4164
4167
  return t && this.autofillController.syncCountdown(), t;
4165
4168
  }
4166
4169
  restoreFillSession(e) {
@@ -4174,7 +4177,7 @@ var mr = class {
4174
4177
  }
4175
4178
  async startLoadMore(e) {
4176
4179
  if (this.pendingRequest) return this.pendingRequest;
4177
- if (this.state.loadMoreLocked || tn(this.state.autofill) || this.fillController.isActive() || !this.options.loadPage || this.state.next === null && !this.removalReconciliation.needsReconciliation(this.state.items)) return;
4180
+ if (this.state.loadMoreLocked || nn(this.state.autofill) || this.fillController.isActive() || !this.options.loadPage || this.state.next === null && !this.removalReconciliation.needsReconciliation(this.state.items)) return;
4178
4181
  this.state.isLoadingMore = !0, this.state.nextPageError = null;
4179
4182
  let t = e();
4180
4183
  return this.pendingRequest = t, t.finally(() => {
@@ -4189,7 +4192,7 @@ var mr = class {
4189
4192
  }
4190
4193
  async replaceFeed(e, t) {
4191
4194
  if (!this.options.loadPage) throw Error(`Vibe cannot ${t} without loadPage.`);
4192
- return tn(this.state.autofill) && await this.cancelAutofill(), this.fillController.isActive() && await this.cancelFill(), this.cancelRequest(), this.state.autofill = en(this.options.autofill, void 0, !1), this.fillController.reset(), this.reelForward.reset(), this.reelRemoval.reset(), this.exactMediaRemoval.reset(), this.itemRemoval.reset(), this.removalReconciliation.reset(), this.state.error = null, this.state.current = null, this.state.isLoading = !0, this.state.items = [], this.state.next = null, this.state.nextPageError = null, this.state.total = null, this.startRequest(e, !1);
4195
+ return nn(this.state.autofill) && await this.cancelAutofill(), this.fillController.isActive() && await this.cancelFill(), this.cancelRequest(), this.state.autofill = tn(this.options.autofill, void 0, !1), this.fillController.reset(), this.reelForward.reset(), this.reelRemoval.reset(), this.exactMediaRemoval.reset(), this.itemRemoval.reset(), this.removalReconciliation.reset(), this.state.error = null, this.state.current = null, this.state.isLoading = !0, this.state.items = [], this.state.next = null, this.state.nextPageError = null, this.state.total = null, this.startRequest(e, !1);
4193
4196
  }
4194
4197
  async loadFilteredPage(e) {
4195
4198
  let t = this.options.loadPage;
@@ -4213,7 +4216,7 @@ var mr = class {
4213
4216
  let t = ++this.requestVersion, n = new AbortController();
4214
4217
  this.abortController = n;
4215
4218
  try {
4216
- let r = await Nn({
4219
+ let r = await Pn({
4217
4220
  controller: this.removalReconciliation,
4218
4221
  isCurrent: () => t === this.requestVersion,
4219
4222
  loadPage: e,
@@ -4231,7 +4234,7 @@ var mr = class {
4231
4234
  }
4232
4235
  async retryEnd() {
4233
4236
  if (this.pendingRequest) return this.pendingRequest;
4234
- if (!this.state.loadMoreLocked && !(tn(this.state.autofill) || this.fillController.isActive()) && !(this.state.next !== null || !this.options.loadPage)) return this.state.isLoadingMore = !0, this.state.nextPageError = null, this.startRequest(this.lastLoadedCursor, !0);
4237
+ if (!this.state.loadMoreLocked && !(nn(this.state.autofill) || this.fillController.isActive()) && !(this.state.next !== null || !this.options.loadPage)) return this.state.isLoadingMore = !0, this.state.nextPageError = null, this.startRequest(this.lastLoadedCursor, !0);
4235
4238
  }
4236
4239
  setInfiniteScroll(e) {
4237
4240
  this.state.infiniteScroll = e, e && m(() => this.surface?.loadIfNearBottom());
@@ -4255,10 +4258,10 @@ var mr = class {
4255
4258
  this.state.total = e;
4256
4259
  }
4257
4260
  setReelAutoAdvance(e) {
4258
- Rn(this.state.reelAutoAdvance, e);
4261
+ zn(this.state.reelAutoAdvance, e);
4259
4262
  }
4260
4263
  setReelInfoSheet(e) {
4261
- Bn(this.state.reelInfoSheet, this.options.reelInfoSheet, e);
4264
+ Vn(this.state.reelInfoSheet, this.options.reelInfoSheet, e);
4262
4265
  }
4263
4266
  setLayout(e) {
4264
4267
  this.responsiveLayout.setLayout(e);
@@ -4278,7 +4281,7 @@ var mr = class {
4278
4281
  async fetchPage(e, t) {
4279
4282
  if (!this.options.loadPage) return;
4280
4283
  let n = ++this.requestVersion, r = new AbortController();
4281
- this.abortController = r, await Kn({
4284
+ this.abortController = r, await qn({
4282
4285
  append: t,
4283
4286
  autofillController: this.autofillController,
4284
4287
  cursor: e,
@@ -4300,7 +4303,7 @@ var mr = class {
4300
4303
  startInitialAutofill() {
4301
4304
  let e = ++this.requestVersion, t = new AbortController(), n = this.autofillController.beginCycle();
4302
4305
  this.abortController = t, this.state.isLoadingMore = !0;
4303
- let r = _n({
4306
+ let r = vn({
4304
4307
  cycleId: n,
4305
4308
  isCurrent: () => e === this.requestVersion,
4306
4309
  onCollection: (t) => this.autofillController.captureCollection(t, e === this.requestVersion),
@@ -4327,8 +4330,8 @@ var mr = class {
4327
4330
  this.lastLoadedCursor = e, this.state.current = e;
4328
4331
  }
4329
4332
  };
4330
- function _r(e) {
4331
- return new gr(e);
4333
+ function vr(e) {
4334
+ return new _r(e);
4332
4335
  }
4333
4336
  //#endregion
4334
- export { _r as createVibe };
4337
+ export { vr as createVibe };