@wyxos/vibe 2.0.3 → 2.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/lib/index.cjs +1 -1
  2. package/lib/index.js +644 -519
  3. package/package.json +3 -2
package/lib/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import { defineComponent as wt, mergeDefaults as yt, useAttrs as bt, useSlots as xt, computed as B, ref as g, shallowRef as kt, watch as Z, onMounted as Mt, onUnmounted as St, createElementBlock as x, openBlock as k, mergeProps as It, createElementVNode as _, normalizeStyle as z, toDisplayString as Ge, Fragment as Ue, renderList as Ke, createCommentVNode as fe, renderSlot as de, nextTick as Je } from "vue";
2
- const Bt = {
1
+ import { defineComponent as it, ref as h, computed as T, onMounted as ut, onUnmounted as ct, createElementBlock as S, openBlock as P, normalizeStyle as $, createCommentVNode as te, createElementVNode as R, normalizeClass as Je, mergeDefaults as Tt, useAttrs as Rt, useSlots as At, shallowRef as Et, watch as W, mergeProps as _t, toDisplayString as Qe, Fragment as Ze, renderList as et, createVNode as tt, renderSlot as ve, nextTick as nt } from "vue";
2
+ const Nt = {
3
3
  mode: "default",
4
4
  pageSize: 20,
5
5
  backfillRequestDelayMs: 2e3,
@@ -11,56 +11,174 @@ const Bt = {
11
11
  headerHeight: 0,
12
12
  footerHeight: 0,
13
13
  overscanPx: 600
14
- };
15
- function Ft(n, w) {
16
- return !n || n <= 0 || !w || w <= 0 ? 1 : Math.max(1, Math.floor(n / w));
14
+ }, Ct = {
15
+ key: 0,
16
+ "data-testid": "masonry-loader-spinner",
17
+ class: "absolute inset-0 flex items-center justify-center"
18
+ }, Ht = {
19
+ key: 1,
20
+ "data-testid": "masonry-loader-error",
21
+ class: "absolute inset-0 flex flex-col items-center justify-center gap-2 p-3"
22
+ }, Lt = ["src", "width", "height", "alt"], zt = ["poster"], qt = ["src"], at = /* @__PURE__ */ it({
23
+ __name: "MasonryLoader",
24
+ props: {
25
+ item: {}
26
+ },
27
+ emits: ["success", "error"],
28
+ setup(o, { emit: k }) {
29
+ const u = o, l = k, r = h(null), p = h(!1), d = h(!1), i = h(!1), g = h(0), b = T(() => {
30
+ const x = u.item?.width, M = u.item?.height;
31
+ return { aspectRatio: `${x} / ${M}` };
32
+ }), I = T(() => u.item?.type === "image");
33
+ let F = null;
34
+ function A() {
35
+ p.value || (p.value = !0, d.value = !1, i.value = !1);
36
+ }
37
+ ut(() => {
38
+ if (typeof IntersectionObserver > "u") {
39
+ A();
40
+ return;
41
+ }
42
+ F = new IntersectionObserver(
43
+ (x) => {
44
+ for (const M of x)
45
+ if (M.isIntersecting && !((M.intersectionRatio ?? 0) < 0.5)) {
46
+ A(), F?.disconnect(), F = null;
47
+ return;
48
+ }
49
+ },
50
+ { threshold: [0, 0.5, 1] }
51
+ ), r.value && F.observe(r.value);
52
+ }), ct(() => {
53
+ F?.disconnect(), F = null;
54
+ });
55
+ function E() {
56
+ d.value || (d.value = !0, i.value = !1, l("success", u.item));
57
+ }
58
+ function B(x) {
59
+ i.value || (d.value = !1, i.value = !0, l("error", { item: u.item, error: x }));
60
+ }
61
+ function H() {
62
+ p.value && (d.value = !1, i.value = !1, g.value += 1);
63
+ }
64
+ return (x, M) => (P(), S("div", {
65
+ ref_key: "rootEl",
66
+ ref: r,
67
+ class: "relative bg-slate-100",
68
+ style: $(b.value)
69
+ }, [
70
+ p.value && !d.value && !i.value ? (P(), S("div", Ct, M[2] || (M[2] = [
71
+ R("svg", {
72
+ class: "h-5 w-5 animate-spin text-slate-500",
73
+ viewBox: "0 0 24 24",
74
+ "aria-hidden": "true"
75
+ }, [
76
+ R("circle", {
77
+ class: "opacity-25",
78
+ cx: "12",
79
+ cy: "12",
80
+ r: "10",
81
+ fill: "none",
82
+ stroke: "currentColor",
83
+ "stroke-width": "4"
84
+ }),
85
+ R("path", {
86
+ class: "opacity-75",
87
+ fill: "currentColor",
88
+ d: "M4 12a8 8 0 0 1 8-8v4a4 4 0 0 0-4 4H4z"
89
+ })
90
+ ], -1)
91
+ ]))) : p.value && i.value ? (P(), S("div", Ht, [
92
+ M[3] || (M[3] = R("p", { class: "text-center text-xs font-medium text-red-700" }, "Failed to load", -1)),
93
+ R("button", {
94
+ type: "button",
95
+ "data-testid": "masonry-loader-retry",
96
+ class: "inline-flex items-center rounded-md border border-slate-200 bg-white px-2 py-1 text-xs font-medium text-slate-700",
97
+ onClick: H
98
+ }, " Retry ")
99
+ ])) : te("", !0),
100
+ p.value && I.value && !i.value ? (P(), S("img", {
101
+ key: u.item.id + ":img:" + g.value,
102
+ class: Je([
103
+ "h-full w-full object-cover transition-opacity duration-300",
104
+ d.value ? "opacity-100" : "opacity-0"
105
+ ]),
106
+ src: u.item.preview,
107
+ width: u.item.width,
108
+ height: u.item.height,
109
+ loading: "lazy",
110
+ alt: u.item.id,
111
+ onLoad: E,
112
+ onError: M[0] || (M[0] = (L) => B(L))
113
+ }, null, 42, Lt)) : p.value && !i.value ? (P(), S("video", {
114
+ key: u.item.id + ":vid:" + g.value,
115
+ class: Je([
116
+ "h-full w-full object-cover transition-opacity duration-300",
117
+ d.value ? "opacity-100" : "opacity-0"
118
+ ]),
119
+ poster: u.item.preview,
120
+ controls: "",
121
+ preload: "metadata",
122
+ onLoadedmetadata: E,
123
+ onError: M[1] || (M[1] = (L) => B(L))
124
+ }, [
125
+ R("source", {
126
+ src: u.item.original,
127
+ type: "video/mp4"
128
+ }, null, 8, qt)
129
+ ], 42, zt)) : te("", !0)
130
+ ], 4));
131
+ }
132
+ });
133
+ function $t(o, k) {
134
+ return !o || o <= 0 || !k || k <= 0 ? 1 : Math.max(1, Math.floor(o / k));
17
135
  }
18
- function Pt(n, w, I, o = 0) {
19
- if (!n || n <= 0 || !w || w <= 0) return I;
20
- const r = typeof o == "number" && o > 0 ? o : 0, M = Math.max(0, w - 1) * r, y = n - M;
21
- return !y || y <= 0 ? I : y / w;
136
+ function Ot(o, k, u, l = 0) {
137
+ if (!o || o <= 0 || !k || k <= 0) return u;
138
+ const r = typeof l == "number" && l > 0 ? l : 0, p = Math.max(0, k - 1) * r, d = o - p;
139
+ return !d || d <= 0 ? u : d / k;
22
140
  }
23
- function Tt(n, w) {
24
- const I = n?.width, o = n?.height;
25
- return typeof I == "number" && typeof o == "number" && I > 0 && o > 0 ? o / I * w : w;
141
+ function Vt(o, k) {
142
+ const u = o?.width, l = o?.height;
143
+ return typeof u == "number" && typeof l == "number" && u > 0 && l > 0 ? l / u * k : k;
26
144
  }
27
- function nt(n) {
28
- return Number.isFinite(n) && n > 0 ? Math.floor(n) : 1;
145
+ function ft(o) {
146
+ return Number.isFinite(o) && o > 0 ? Math.floor(o) : 1;
29
147
  }
30
- function ke(n) {
31
- return Number.isFinite(n) && n > 0 ? Math.floor(n) : 0;
148
+ function ke(o) {
149
+ return Number.isFinite(o) && o > 0 ? Math.floor(o) : 0;
32
150
  }
33
- function _t(n) {
34
- async function w(o) {
35
- const r = ke(o);
151
+ function Yt(o) {
152
+ async function k(l) {
153
+ const r = ke(l);
36
154
  if (r <= 0) return;
37
- n.stats.value = {
38
- ...n.stats.value,
155
+ o.stats.value = {
156
+ ...o.stats.value,
39
157
  cooldownMsTotal: r,
40
158
  cooldownMsRemaining: r
41
159
  };
42
- const M = Date.now(), y = 100;
43
- await new Promise((m) => {
44
- const h = setInterval(() => {
45
- const p = Date.now() - M, b = Math.max(0, r - p);
46
- n.stats.value = {
47
- ...n.stats.value,
160
+ const p = Date.now(), d = 100;
161
+ await new Promise((i) => {
162
+ const g = setInterval(() => {
163
+ const b = Date.now() - p, I = Math.max(0, r - b);
164
+ o.stats.value = {
165
+ ...o.stats.value,
48
166
  cooldownMsTotal: r,
49
- cooldownMsRemaining: b
50
- }, b <= 0 && (clearInterval(h), m());
51
- }, y);
167
+ cooldownMsRemaining: I
168
+ }, I <= 0 && (clearInterval(g), i());
169
+ }, d);
52
170
  });
53
171
  }
54
- async function I(o) {
55
- const r = nt(n.getPageSize()), M = n.isEnabled(), y = ke(n.getRequestDelayMs()), m = [];
56
- let h = 0;
57
- n.buffer.value.length && (h = n.buffer.value.length, m.push(...n.buffer.value), n.buffer.value = []), n.stats.value = {
58
- ...n.stats.value,
59
- enabled: M,
172
+ async function u(l) {
173
+ const r = ft(o.getPageSize()), p = o.isEnabled(), d = ke(o.getRequestDelayMs()), i = [];
174
+ let g = 0;
175
+ o.buffer.value.length && (g = o.buffer.value.length, i.push(...o.buffer.value), o.buffer.value = []), o.stats.value = {
176
+ ...o.stats.value,
177
+ enabled: p,
60
178
  isBackfillActive: !1,
61
179
  isRequestInFlight: !1,
62
180
  requestPage: null,
63
- cooldownMsTotal: y,
181
+ cooldownMsTotal: d,
64
182
  cooldownMsRemaining: 0,
65
183
  progress: {
66
184
  collected: 0,
@@ -69,58 +187,58 @@ function _t(n) {
69
187
  pageSize: r,
70
188
  bufferSize: 0
71
189
  };
72
- const p = [];
73
- let b = o, H = 0, A = !1;
74
- for (; m.length < r && b != null; ) {
75
- const N = b;
76
- A && (n.stats.value = {
77
- ...n.stats.value,
78
- enabled: M,
190
+ const b = [];
191
+ let I = l, F = 0, A = !1;
192
+ for (; i.length < r && I != null; ) {
193
+ const H = I;
194
+ A && (o.stats.value = {
195
+ ...o.stats.value,
196
+ enabled: p,
79
197
  isBackfillActive: !0,
80
198
  isRequestInFlight: !0,
81
- requestPage: N,
199
+ requestPage: H,
82
200
  progress: {
83
- collected: Math.min(m.length, r),
201
+ collected: Math.min(i.length, r),
84
202
  target: r
85
203
  },
86
- cooldownMsTotal: y,
204
+ cooldownMsTotal: d,
87
205
  cooldownMsRemaining: 0,
88
206
  pageSize: r
89
207
  });
90
- const S = await n.getContent(N);
91
- p.push(N), A && (n.stats.value = {
92
- ...n.stats.value,
93
- enabled: M,
208
+ const x = await o.getContent(H);
209
+ b.push(H), A && (o.stats.value = {
210
+ ...o.stats.value,
211
+ enabled: p,
94
212
  isBackfillActive: !0,
95
213
  isRequestInFlight: !1,
96
214
  requestPage: null
97
- }), H += S.items.length, n.markEnterFromLeft(S.items), m.push(...S.items), b = S.nextPage, !A && m.length < r && b != null ? (A = !0, n.stats.value = {
98
- ...n.stats.value,
99
- enabled: M,
215
+ }), F += x.items.length, o.markEnterFromLeft(x.items), i.push(...x.items), I = x.nextPage, !A && i.length < r && I != null ? (A = !0, o.stats.value = {
216
+ ...o.stats.value,
217
+ enabled: p,
100
218
  isBackfillActive: !0,
101
219
  isRequestInFlight: !1,
102
220
  requestPage: null,
103
221
  progress: {
104
- collected: Math.min(m.length, r),
222
+ collected: Math.min(i.length, r),
105
223
  target: r
106
224
  },
107
- cooldownMsTotal: y,
225
+ cooldownMsTotal: d,
108
226
  cooldownMsRemaining: 0,
109
227
  pageSize: r
110
- }) : A && (n.stats.value = {
111
- ...n.stats.value,
112
- enabled: M,
228
+ }) : A && (o.stats.value = {
229
+ ...o.stats.value,
230
+ enabled: p,
113
231
  isBackfillActive: !0,
114
232
  progress: {
115
- collected: Math.min(m.length, r),
233
+ collected: Math.min(i.length, r),
116
234
  target: r
117
235
  }
118
- }), A && m.length < r && b != null && await w(y);
236
+ }), A && i.length < r && I != null && await k(d);
119
237
  }
120
- const R = m.slice(0, r), F = m.slice(r);
121
- return n.buffer.value = F, n.stats.value = {
122
- ...n.stats.value,
123
- enabled: M,
238
+ const E = i.slice(0, r), B = i.slice(r);
239
+ return o.buffer.value = B, o.stats.value = {
240
+ ...o.stats.value,
241
+ enabled: p,
124
242
  isBackfillActive: !1,
125
243
  isRequestInFlight: !1,
126
244
  requestPage: null,
@@ -128,78 +246,79 @@ function _t(n) {
128
246
  collected: 0,
129
247
  target: 0
130
248
  },
131
- cooldownMsTotal: y,
249
+ cooldownMsTotal: d,
132
250
  cooldownMsRemaining: 0,
133
251
  pageSize: r,
134
- bufferSize: F.length,
252
+ bufferSize: B.length,
135
253
  lastBatch: {
136
- startPage: o,
137
- pages: p,
138
- usedFromBuffer: h,
139
- fetchedFromNetwork: H,
140
- collectedTotal: m.length,
141
- emitted: R.length,
142
- carried: F.length
254
+ startPage: l,
255
+ pages: b,
256
+ usedFromBuffer: g,
257
+ fetchedFromNetwork: F,
258
+ collectedTotal: i.length,
259
+ emitted: E.length,
260
+ carried: B.length
143
261
  },
144
262
  totals: {
145
- pagesFetched: n.stats.value.totals.pagesFetched + p.length,
146
- itemsFetchedFromNetwork: n.stats.value.totals.itemsFetchedFromNetwork + H
263
+ pagesFetched: o.stats.value.totals.pagesFetched + b.length,
264
+ itemsFetchedFromNetwork: o.stats.value.totals.itemsFetchedFromNetwork + F
147
265
  }
148
- }, { batchItems: R, pages: p, nextPage: b };
266
+ }, { batchItems: E, pages: b, nextPage: I };
149
267
  }
150
- return { loadBackfillBatch: I };
268
+ return { loadBackfillBatch: u };
151
269
  }
152
- function At(n) {
153
- const w = n.columnCount, I = n.columnWidth, o = n.gapX, r = n.gapY, M = n.headerHeight, y = n.footerHeight, m = n.bucketPx, h = Array.from({ length: w }, () => 0), p = new Array(n.items.length), b = new Array(n.items.length), H = /* @__PURE__ */ new Map(), A = /* @__PURE__ */ new Map();
154
- let R = 0;
155
- for (let F = 0; F < n.items.length; F += 1) {
156
- const N = n.items[F];
157
- N?.id && A.set(N.id, F);
158
- let S = 0;
159
- for (let P = 1; P < h.length; P += 1)
160
- h[P] < h[S] && (S = P);
161
- const q = S * (I + o), L = h[S], V = Tt(N, I) + M + y;
162
- p[F] = { x: q, y: L }, b[F] = V, h[S] = L + V + r, R = Math.max(R, L + V);
163
- const le = Math.floor(L / m), se = Math.floor((L + V) / m);
164
- for (let P = le; P <= se; P += 1) {
165
- const W = H.get(P);
166
- W ? W.push(F) : H.set(P, [F]);
270
+ function Dt(o) {
271
+ const k = o.columnCount, u = o.columnWidth, l = o.gapX, r = o.gapY, p = o.headerHeight, d = o.footerHeight, i = o.bucketPx, g = Array.from({ length: k }, () => 0), b = new Array(o.items.length), I = new Array(o.items.length), F = /* @__PURE__ */ new Map(), A = /* @__PURE__ */ new Map();
272
+ let E = 0;
273
+ for (let B = 0; B < o.items.length; B += 1) {
274
+ const H = o.items[B];
275
+ H?.id && A.set(H.id, B);
276
+ let x = 0;
277
+ for (let _ = 1; _ < g.length; _ += 1)
278
+ g[_] < g[x] && (x = _);
279
+ const M = x * (u + l), L = g[x], Y = Vt(H, u) + p + d;
280
+ b[B] = { x: M, y: L }, I[B] = Y, g[x] = L + Y + r, E = Math.max(E, L + Y);
281
+ const re = Math.floor(L / i), ie = Math.floor((L + Y) / i);
282
+ for (let _ = re; _ <= ie; _ += 1) {
283
+ const G = F.get(_);
284
+ G ? G.push(B) : F.set(_, [B]);
167
285
  }
168
286
  }
169
- return { positions: p, heights: b, buckets: H, contentHeight: R, indexById: A };
287
+ return { positions: b, heights: I, buckets: F, contentHeight: E, indexById: A };
170
288
  }
171
- function Rt(n) {
172
- const w = n.itemCount;
173
- if (!w) return [];
174
- if (n.viewportHeight <= 0) return Array.from({ length: w }, (h, p) => p);
175
- const I = Math.max(0, n.scrollTop - n.overscanPx), o = n.scrollTop + n.viewportHeight + n.overscanPx, r = Math.floor(I / n.bucketPx), M = Math.floor(o / n.bucketPx), y = /* @__PURE__ */ new Set();
176
- for (let h = r; h <= M; h += 1) {
177
- const p = n.buckets.get(h);
178
- if (p)
179
- for (const b of p) y.add(b);
289
+ function Xt(o) {
290
+ const k = o.itemCount;
291
+ if (!k) return [];
292
+ if (o.viewportHeight <= 0) return Array.from({ length: k }, (g, b) => b);
293
+ const u = Math.max(0, o.scrollTop - o.overscanPx), l = o.scrollTop + o.viewportHeight + o.overscanPx, r = Math.floor(u / o.bucketPx), p = Math.floor(l / o.bucketPx), d = /* @__PURE__ */ new Set();
294
+ for (let g = r; g <= p; g += 1) {
295
+ const b = o.buckets.get(g);
296
+ if (b)
297
+ for (const I of b) d.add(I);
180
298
  }
181
- const m = Array.from(y);
182
- return m.sort((h, p) => h - p), m;
299
+ const i = Array.from(d);
300
+ return i.sort((g, b) => g - b), i;
183
301
  }
184
- const Et = {
302
+ const jt = {
185
303
  key: 0,
186
304
  class: "flex h-full items-center justify-center"
187
- }, Ht = {
305
+ }, Wt = {
188
306
  key: 1,
189
307
  class: "text-sm font-medium text-red-700"
190
- }, Ct = ["src", "width", "height", "alt"], Nt = ["poster"], zt = ["src"], qt = ["src", "width", "height", "alt"], Lt = ["poster"], Yt = ["src"], Dt = { class: "mt-4 pb-2 text-center text-xs text-slate-600" }, Vt = {
308
+ }, Gt = { class: "mt-4 pb-2 text-center text-xs text-slate-600" }, Ut = {
191
309
  key: 0,
192
310
  class: "inline-flex items-center justify-center gap-2"
193
- }, Ot = { key: 1 }, $t = { key: 2 }, Xt = 200, Qe = 600, Ze = 300, et = 600, tt = 600, jt = 5, Wt = 1e3, Gt = /* @__PURE__ */ wt({
311
+ }, Kt = { key: 1 }, Jt = { key: 2 }, Qt = 200, ot = 600, st = 300, lt = 600, rt = 600, Zt = 5, en = 1e3, tn = /* @__PURE__ */ it({
194
312
  inheritAttrs: !1,
195
313
  __name: "Masonry",
196
- props: /* @__PURE__ */ yt({
314
+ props: /* @__PURE__ */ Tt({
197
315
  getContent: {},
198
316
  mode: {},
199
317
  pageSize: {},
200
318
  backfillRequestDelayMs: {},
201
319
  items: {},
202
320
  page: {},
321
+ restoredPagesLoaded: {},
203
322
  itemWidth: {},
204
323
  prefetchThresholdPx: {},
205
324
  gapX: {},
@@ -207,226 +326,234 @@ const Et = {
207
326
  headerHeight: {},
208
327
  footerHeight: {},
209
328
  overscanPx: {}
210
- }, Bt),
329
+ }, Nt),
211
330
  emits: ["update:items"],
212
- setup(n, { expose: w, emit: I }) {
213
- const o = n, r = I, M = bt(), y = xt(), m = B(() => {
214
- const { class: e, ...a } = M;
215
- return a;
216
- }), h = g(null), p = g(0), b = g(0), H = g(0);
331
+ setup(o, { expose: k, emit: u }) {
332
+ const l = o, r = u, p = Rt(), d = At(), i = T(() => {
333
+ const { class: e, ...n } = p;
334
+ return n;
335
+ }), g = h(null), b = h(0), I = h(0), F = h(0);
217
336
  let A;
218
- const R = B(() => o.gapX), F = B(() => o.gapY);
219
- function N(e) {
337
+ const E = T(() => l.gapX), B = T(() => l.gapY);
338
+ function H(e) {
220
339
  if (!e) return 0;
221
- const a = Math.max(0, R.value);
222
- return Math.max(0, e.clientWidth - a);
223
- }
224
- const S = B(() => o.headerHeight), q = B(() => o.footerHeight), L = B(() => !!y.itemHeader), V = B(() => !!y.itemFooter), le = B(() => {
225
- if (S.value > 0) return { height: `${S.value}px` };
226
- }), se = B(() => {
227
- if (q.value > 0) return { height: `${q.value}px` };
228
- }), P = g([]), W = g([]), Me = g(/* @__PURE__ */ new Map()), Se = g(0), oe = g(/* @__PURE__ */ new Map());
229
- function Ie(e) {
230
- const a = typeof e == "number" && Number.isFinite(e) ? e : 0;
231
- return -Math.max(0, a);
232
- }
233
- const O = g(/* @__PURE__ */ new Set()), G = g(/* @__PURE__ */ new Set()), ie = /* @__PURE__ */ new Set(), re = g(/* @__PURE__ */ new Map()), Y = g(/* @__PURE__ */ new Set()), D = g([]);
234
- function at(e) {
235
- const a = re.value.get(e);
236
- return a || { dx: 0, dy: 0 };
237
- }
238
- function lt(e) {
239
- if (G.value.has(e)) return `transform ${et}ms ease-out`;
240
- if (Y.value.has(e)) return `transform ${Ze}ms ease-out`;
241
- }
242
- function st(e) {
243
- const t = i.value[e]?.id, l = P.value[e] ?? { x: 0, y: 0 }, s = W.value[e] ?? 0, f = s > 0 ? s : ne.value, u = l.x, d = t && O.value.has(t) ? Ie(f) : l.y, v = t ? at(t) : { dx: 0, dy: 0 };
244
- return `translate3d(${u + v.dx}px,${d + v.dy}px,0)`;
245
- }
246
- function U(e) {
340
+ const n = Math.max(0, E.value);
341
+ return Math.max(0, e.clientWidth - n);
342
+ }
343
+ const x = T(() => l.headerHeight), M = T(() => l.footerHeight), L = T(() => !!d.itemHeader), Y = T(() => !!d.itemFooter), re = T(() => {
344
+ if (x.value > 0) return { height: `${x.value}px` };
345
+ }), ie = T(() => {
346
+ if (M.value > 0) return { height: `${M.value}px` };
347
+ }), _ = h([]), G = h([]), Me = h(/* @__PURE__ */ new Map()), Ie = h(0), ue = h(/* @__PURE__ */ new Map());
348
+ function Se(e) {
349
+ const n = typeof e == "number" && Number.isFinite(e) ? e : 0;
350
+ return Ye.value + Math.max(0, n);
351
+ }
352
+ const D = h(/* @__PURE__ */ new Set()), U = h(/* @__PURE__ */ new Set()), ce = /* @__PURE__ */ new Set(), fe = h(/* @__PURE__ */ new Map()), O = h(/* @__PURE__ */ new Set()), V = h([]);
353
+ function dt(e) {
354
+ const n = fe.value.get(e);
355
+ return n || { dx: 0, dy: 0 };
356
+ }
357
+ function vt(e) {
358
+ if (U.value.has(e)) return `transform ${lt}ms ease-out`;
359
+ if (O.value.has(e)) return `transform ${st}ms ease-out`;
360
+ }
361
+ function mt(e) {
362
+ const t = c.value[e]?.id, a = _.value[e] ?? { x: 0, y: 0 }, s = G.value[e] ?? 0, f = s > 0 ? s : se.value, v = a.x, y = t && D.value.has(t) ? Se(f) : a.y, w = t ? dt(t) : { dx: 0, dy: 0 };
363
+ return `translate3d(${v + w.dx}px,${y + w.dy}px,0)`;
364
+ }
365
+ function K(e) {
247
366
  (typeof requestAnimationFrame == "function" ? requestAnimationFrame : (t) => setTimeout(() => t(0), 0))(() => e());
248
367
  }
249
- function ot(e) {
250
- U(() => U(e));
368
+ function ht(e) {
369
+ K(() => K(e));
251
370
  }
252
- const Be = /* @__PURE__ */ new Set();
371
+ const Pe = /* @__PURE__ */ new Set();
253
372
  function Fe(e) {
254
373
  return typeof e == "number" && Number.isFinite(e) && e > 0;
255
374
  }
256
- function ve(e) {
375
+ function me(e) {
257
376
  if (!Array.isArray(e) || e.length === 0) return;
258
- const a = new Set(O.value);
377
+ const n = new Set(D.value);
259
378
  let t = !1;
260
- for (const l of e) {
261
- const s = l?.id;
379
+ for (const a of e) {
380
+ const s = a?.id;
262
381
  if (s) {
263
- if (!Be.has(s)) {
264
- const f = l?.width, u = l?.height;
265
- (!Fe(f) || !Fe(u)) && (Be.add(s), console.warn(
382
+ if (!Pe.has(s)) {
383
+ const f = a?.width, v = a?.height;
384
+ (!Fe(f) || !Fe(v)) && (Pe.add(s), console.warn(
266
385
  `[Masonry] Item "${s}" has invalid dimensions (width=${String(f)}, height=${String(
267
- u
386
+ v
268
387
  )}); layout expects { id, width, height }.`
269
388
  ));
270
389
  }
271
- a.has(s) || (a.add(s), t = !0);
390
+ n.has(s) || (n.add(s), t = !0);
272
391
  }
273
392
  }
274
- t && (O.value = a);
393
+ t && (D.value = n);
275
394
  }
276
- function Pe() {
395
+ function Be() {
277
396
  const e = /* @__PURE__ */ new Map();
278
- for (const a of be.value) {
279
- const l = i.value[a]?.id;
280
- if (!l) continue;
281
- const s = P.value[a];
282
- s && e.set(l, { x: s.x, y: s.y });
397
+ for (const n of xe.value) {
398
+ const a = c.value[n]?.id;
399
+ if (!a) continue;
400
+ const s = _.value[n];
401
+ s && e.set(a, { x: s.x, y: s.y });
283
402
  }
284
403
  return e;
285
404
  }
286
- function Te(e, a) {
405
+ function Te(e, n) {
287
406
  if (!e.size) return;
288
- const t = /* @__PURE__ */ new Map(), l = [];
289
- for (const [f, u] of e.entries()) {
290
- if (a?.has(f)) continue;
291
- const d = oe.value.get(f);
292
- if (d == null) continue;
293
- const v = P.value[d];
294
- if (!v) continue;
295
- const c = u.x - v.x, E = u.y - v.y;
296
- (c || E) && (t.set(f, { dx: c, dy: E }), l.push(f));
407
+ const t = /* @__PURE__ */ new Map(), a = [];
408
+ for (const [f, v] of e.entries()) {
409
+ if (n?.has(f)) continue;
410
+ const y = ue.value.get(f);
411
+ if (y == null) continue;
412
+ const w = _.value[y];
413
+ if (!w) continue;
414
+ const m = v.x - w.x, z = v.y - w.y;
415
+ (m || z) && (t.set(f, { dx: m, dy: z }), a.push(f));
297
416
  }
298
417
  if (!t.size) return;
299
- re.value = t;
300
- const s = new Set(Y.value);
301
- for (const f of l) s.delete(f);
302
- Y.value = s, U(() => {
303
- Y.value = /* @__PURE__ */ new Set([...Y.value, ...l]), U(() => {
304
- re.value = /* @__PURE__ */ new Map();
418
+ fe.value = t;
419
+ const s = new Set(O.value);
420
+ for (const f of a) s.delete(f);
421
+ O.value = s, K(() => {
422
+ O.value = /* @__PURE__ */ new Set([...O.value, ...a]), K(() => {
423
+ fe.value = /* @__PURE__ */ new Map();
305
424
  });
306
425
  }), setTimeout(() => {
307
- const f = new Set(Y.value);
308
- for (const u of l) f.delete(u);
309
- Y.value = f;
310
- }, Ze);
311
- }
312
- const ue = g(!0), ee = g(!1), K = g("");
313
- let T = 0;
314
- function _e(e) {
426
+ const f = new Set(O.value);
427
+ for (const v of a) f.delete(v);
428
+ O.value = f;
429
+ }, st);
430
+ }
431
+ const ne = h(!0), ae = h(!1), J = h("");
432
+ let N = 0;
433
+ function Re(e) {
315
434
  return e instanceof Error && e.name === "AbortError";
316
435
  }
317
436
  function Ae() {
318
437
  const e = new Error("aborted");
319
438
  return e.name = "AbortError", e;
320
439
  }
321
- function it(e) {
322
- return new Promise((a) => setTimeout(a, e));
440
+ function gt(e) {
441
+ return new Promise((n) => setTimeout(n, e));
323
442
  }
324
- async function Re(e, a) {
443
+ async function Ee(e, n) {
325
444
  let t = 0;
326
445
  for (; ; ) {
327
- if (a !== T) throw Ae();
446
+ if (n !== N) throw Ae();
328
447
  try {
329
- return await o.getContent(e);
330
- } catch (l) {
331
- if (a !== T) throw Ae();
332
- if (t >= jt) throw l;
333
- t += 1, await it(t * Wt);
448
+ return await l.getContent(e);
449
+ } catch (a) {
450
+ if (n !== N) throw Ae();
451
+ if (t >= Zt) throw a;
452
+ t += 1, await gt(t * en);
334
453
  }
335
454
  }
336
455
  }
337
- const $ = g([]), Ee = g([]), he = g([]), C = g(o.page), ge = g([]);
338
- let J = null, Q = null, me = 0;
339
- function te(e) {
340
- for (const a of e)
341
- !a || typeof a != "object" || a.id && a.originalIndex == null && (a.originalIndex = me, me += 1);
456
+ const q = h([]), _e = h([]), he = h([]), C = h(l.page), ge = h([]);
457
+ let Q = null, Z = null, de = 0;
458
+ function pt(e) {
459
+ let n = -1;
460
+ for (const t of e) {
461
+ const a = t?.originalIndex;
462
+ oe(a) && a > n && (n = a);
463
+ }
464
+ de = n + 1;
465
+ }
466
+ function ee(e) {
467
+ for (const n of e)
468
+ !n || typeof n != "object" || n.id && n.originalIndex == null && (n.originalIndex = de, de += 1);
342
469
  }
343
470
  const X = /* @__PURE__ */ new Map(), j = [];
344
- function ce(e) {
471
+ function oe(e) {
345
472
  return typeof e == "number" && Number.isFinite(e);
346
473
  }
347
- function rt(e, a) {
348
- if (!a.length) return e;
474
+ function yt(e, n) {
475
+ if (!n.length) return e;
349
476
  const t = /* @__PURE__ */ new Set();
350
- for (const u of e) {
351
- const d = u?.id;
352
- d && t.add(d);
477
+ for (const v of e) {
478
+ const y = v?.id;
479
+ y && t.add(y);
353
480
  }
354
- const l = [];
355
- for (const u of a) {
356
- const d = u?.id;
357
- d && (t.has(d) || (l.push(u), t.add(d)));
481
+ const a = [];
482
+ for (const v of n) {
483
+ const y = v?.id;
484
+ y && (t.has(y) || (a.push(v), t.add(y)));
358
485
  }
359
- if (!l.length) return e;
360
- const s = l.slice().sort((u, d) => {
361
- const v = ce(u.originalIndex) ? u.originalIndex : Number.POSITIVE_INFINITY, c = ce(d.originalIndex) ? d.originalIndex : Number.POSITIVE_INFINITY;
362
- return v - c;
486
+ if (!a.length) return e;
487
+ const s = a.slice().sort((v, y) => {
488
+ const w = oe(v.originalIndex) ? v.originalIndex : Number.POSITIVE_INFINITY, m = oe(y.originalIndex) ? y.originalIndex : Number.POSITIVE_INFINITY;
489
+ return w - m;
363
490
  }), f = e.slice();
364
- for (const u of s) {
365
- const d = u.originalIndex;
366
- if (!ce(d)) {
367
- f.push(u);
491
+ for (const v of s) {
492
+ const y = v.originalIndex;
493
+ if (!oe(y)) {
494
+ f.push(v);
368
495
  continue;
369
496
  }
370
- let v = 0, c = f.length;
371
- for (; v < c; ) {
372
- const E = v + c >> 1, ae = f[E]?.originalIndex;
373
- (ce(ae) ? ae : Number.POSITIVE_INFINITY) <= d ? v = E + 1 : c = E;
497
+ let w = 0, m = f.length;
498
+ for (; w < m; ) {
499
+ const z = w + m >> 1, le = f[z]?.originalIndex;
500
+ (oe(le) ? le : Number.POSITIVE_INFINITY) <= y ? w = z + 1 : m = z;
374
501
  }
375
- f.splice(v, 0, u);
502
+ f.splice(w, 0, v);
376
503
  }
377
504
  return f;
378
505
  }
379
- async function He(e) {
506
+ async function Ne(e) {
380
507
  if (!e.length) return;
381
- ve(e);
382
- const a = Pe();
383
- i.value = rt(i.value, e), await Je(), Te(a);
508
+ me(e);
509
+ const n = Be();
510
+ c.value = yt(c.value, e), await nt(), Te(n);
384
511
  }
385
512
  async function Ce(e) {
386
- const t = (Array.isArray(e) ? e : [e]).map(ye).filter(Boolean);
513
+ const t = (Array.isArray(e) ? e : [e]).map(we).filter(Boolean);
387
514
  if (!t.length) return;
388
- const l = [];
515
+ const a = [];
389
516
  for (const s of t) {
390
517
  const f = X.get(s);
391
- f && l.push(f);
518
+ f && a.push(f);
392
519
  }
393
- if (l.length) {
394
- await He(l);
395
- for (const s of l)
520
+ if (a.length) {
521
+ await Ne(a);
522
+ for (const s of a)
396
523
  s?.id && X.delete(s.id);
397
524
  }
398
525
  }
399
- async function Ne() {
526
+ async function He() {
400
527
  const e = j.pop();
401
528
  if (!e?.length) return;
402
- const a = [];
529
+ const n = [];
403
530
  for (const t of e) {
404
- const l = X.get(t);
405
- l && a.push(l);
531
+ const a = X.get(t);
532
+ a && n.push(a);
406
533
  }
407
- if (a.length) {
408
- await He(a);
409
- for (const t of a)
534
+ if (n.length) {
535
+ await Ne(n);
536
+ for (const t of n)
410
537
  t?.id && X.delete(t.id);
411
538
  }
412
539
  }
413
- async function ut(e) {
540
+ async function wt(e) {
414
541
  return Ce(e);
415
542
  }
416
- async function ct() {
417
- return Ne();
543
+ async function xt() {
544
+ return He();
418
545
  }
419
- function ze(e) {
420
- const t = (Array.isArray(e) ? e : [e]).map(ye).filter(Boolean);
546
+ function Le(e) {
547
+ const t = (Array.isArray(e) ? e : [e]).map(we).filter(Boolean);
421
548
  if (!t.length) return;
422
- const l = new Set(t);
423
- for (const s of l) X.delete(s);
549
+ const a = new Set(t);
550
+ for (const s of a) X.delete(s);
424
551
  for (let s = j.length - 1; s >= 0; s -= 1) {
425
- const u = j[s].filter((d) => !l.has(d));
426
- u.length ? j[s] = u : j.splice(s, 1);
552
+ const v = j[s].filter((y) => !a.has(y));
553
+ v.length ? j[s] = v : j.splice(s, 1);
427
554
  }
428
555
  }
429
- const pe = kt({
556
+ const pe = Et({
430
557
  enabled: !1,
431
558
  isBackfillActive: !1,
432
559
  isRequestInFlight: !1,
@@ -444,187 +571,189 @@ const Et = {
444
571
  pagesFetched: 0,
445
572
  itemsFetchedFromNetwork: 0
446
573
  }
447
- }), qe = _t({
448
- getContent: (e) => Re(e, T),
449
- markEnterFromLeft: ve,
574
+ }), ze = Yt({
575
+ getContent: (e) => Ee(e, N),
576
+ markEnterFromLeft: me,
450
577
  buffer: ge,
451
578
  stats: pe,
452
- isEnabled: () => o.mode === "backfill",
453
- getPageSize: () => o.pageSize,
454
- getRequestDelayMs: () => o.backfillRequestDelayMs
455
- }), we = B(() => o.items !== void 0);
456
- Z(
457
- () => o.items,
579
+ isEnabled: () => l.mode === "backfill",
580
+ getPageSize: () => l.pageSize,
581
+ getRequestDelayMs: () => l.backfillRequestDelayMs
582
+ }), ye = T(() => l.items !== void 0);
583
+ W(
584
+ () => l.items,
458
585
  (e) => {
459
- we.value && (he.value = Array.isArray(e) ? e : []);
586
+ ye.value && (he.value = Array.isArray(e) ? e : []);
460
587
  },
461
588
  { immediate: !0 }
462
589
  );
463
- const i = B({
590
+ const c = T({
464
591
  get() {
465
- return we.value ? he.value : Ee.value;
592
+ return ye.value ? he.value : _e.value;
466
593
  },
467
594
  set(e) {
468
- we.value ? (he.value = e, r("update:items", e)) : Ee.value = e;
595
+ ye.value ? (he.value = e, r("update:items", e)) : _e.value = e;
469
596
  }
470
597
  });
471
- async function Le(e) {
472
- const a = await Re(e, T);
473
- return te(a.items), ve(a.items), { items: a.items, nextPage: a.nextPage };
598
+ async function qe(e) {
599
+ const n = await Ee(e, N);
600
+ return ee(n.items), me(n.items), { items: n.items, nextPage: n.nextPage };
474
601
  }
475
- function ye(e) {
602
+ function we(e) {
476
603
  return e ? typeof e == "string" ? e : e?.id : null;
477
604
  }
478
- async function Ye(e) {
479
- const t = (Array.isArray(e) ? e : [e]).map(ye).filter(Boolean);
605
+ async function $e(e) {
606
+ const t = (Array.isArray(e) ? e : [e]).map(we).filter(Boolean);
480
607
  if (!t.length) return;
481
- const l = new Set(t), s = [];
482
- for (const v of l) {
483
- const c = oe.value.get(v);
484
- if (c == null) continue;
485
- const E = i.value[c];
486
- E && (X.set(v, E), s.push(v));
608
+ const a = new Set(t), s = [];
609
+ for (const w of a) {
610
+ const m = ue.value.get(w);
611
+ if (m == null) continue;
612
+ const z = c.value[m];
613
+ z && (X.set(w, z), s.push(w));
487
614
  }
488
615
  s.length && j.push(s);
489
- const f = Pe(), u = ne.value, d = [];
490
- for (const v of l) {
491
- const c = oe.value.get(v);
492
- if (c == null) continue;
493
- const E = i.value[c];
494
- if (!E) continue;
495
- const ae = P.value[c] ?? { x: 0, y: 0 }, We = W.value[c] ?? u;
496
- d.push({
497
- id: v,
498
- item: E,
499
- fromX: ae.x,
500
- fromY: ae.y,
501
- width: u,
502
- height: We,
616
+ const f = Be(), v = se.value, y = [];
617
+ for (const w of a) {
618
+ const m = ue.value.get(w);
619
+ if (m == null) continue;
620
+ const z = c.value[m];
621
+ if (!z) continue;
622
+ const le = _.value[m] ?? { x: 0, y: 0 }, Ke = G.value[m] ?? v;
623
+ y.push({
624
+ id: w,
625
+ item: z,
626
+ fromX: le.x,
627
+ fromY: le.y,
628
+ width: v,
629
+ height: Ke,
503
630
  leaving: !0
504
631
  });
505
632
  }
506
- if (d.length && (D.value = [...D.value, ...d]), i.value = i.value.filter((v) => {
507
- const c = v?.id;
508
- return !c || !l.has(c);
509
- }), await Je(), Te(f, l), d.length) {
510
- const v = new Set(d.map((c) => c.id));
511
- U(() => {
512
- D.value = D.value.map(
513
- (c) => v.has(c.id) ? { ...c, leaving: !1 } : c
633
+ if (y.length && (V.value = [...V.value, ...y]), c.value = c.value.filter((w) => {
634
+ const m = w?.id;
635
+ return !m || !a.has(m);
636
+ }), await nt(), Te(f, a), y.length) {
637
+ const w = new Set(y.map((m) => m.id));
638
+ K(() => {
639
+ V.value = V.value.map(
640
+ (m) => w.has(m.id) ? { ...m, leaving: !1 } : m
514
641
  ), setTimeout(() => {
515
- D.value = D.value.filter((c) => !v.has(c.id));
516
- }, tt);
642
+ V.value = V.value.filter((m) => !w.has(m.id));
643
+ }, rt);
517
644
  });
518
645
  }
519
646
  }
520
- async function De(e) {
521
- return Ye(e);
647
+ async function Oe(e) {
648
+ return $e(e);
522
649
  }
523
- w({
524
- remove: Ye,
525
- restore: ut,
526
- undo: ct,
527
- forget: ze,
650
+ k({
651
+ remove: $e,
652
+ restore: wt,
653
+ undo: xt,
654
+ forget: Le,
655
+ pagesLoaded: q,
656
+ nextPage: C,
528
657
  // Aliases (kept for now; can be removed if you want strictly short API only).
529
658
  restoreRemoved: Ce,
530
- undoLastRemoval: Ne,
531
- forgetRemoved: ze,
659
+ undoLastRemoval: He,
660
+ forgetRemoved: Le,
532
661
  backfillStats: pe
533
662
  });
534
663
  function Ve() {
535
- const e = At({
536
- items: i.value,
537
- columnCount: xe.value,
538
- columnWidth: ne.value,
539
- gapX: R.value,
540
- gapY: F.value,
541
- headerHeight: S.value,
542
- footerHeight: q.value,
543
- bucketPx: Qe
664
+ const e = Dt({
665
+ items: c.value,
666
+ columnCount: be.value,
667
+ columnWidth: se.value,
668
+ gapX: E.value,
669
+ gapY: B.value,
670
+ headerHeight: x.value,
671
+ footerHeight: M.value,
672
+ bucketPx: ot
544
673
  });
545
- P.value = e.positions, W.value = e.heights, Me.value = e.buckets, Se.value = e.contentHeight, oe.value = e.indexById;
546
- }
547
- const ft = B(() => Math.max(Se.value, b.value) + Xt), be = B(() => Rt({
548
- itemCount: i.value.length,
549
- viewportHeight: b.value,
550
- scrollTop: H.value,
551
- overscanPx: o.overscanPx,
552
- bucketPx: Qe,
674
+ _.value = e.positions, G.value = e.heights, Me.value = e.buckets, Ie.value = e.contentHeight, ue.value = e.indexById;
675
+ }
676
+ const Ye = T(() => Math.max(Ie.value, I.value) + Qt), xe = T(() => Xt({
677
+ itemCount: c.value.length,
678
+ viewportHeight: I.value,
679
+ scrollTop: F.value,
680
+ overscanPx: l.overscanPx,
681
+ bucketPx: ot,
553
682
  buckets: Me.value
554
683
  }));
555
- Z(
556
- be,
684
+ W(
685
+ xe,
557
686
  (e) => {
558
687
  if (!e?.length) return;
559
- const a = [];
688
+ const n = [];
560
689
  for (const t of e) {
561
- const l = i.value[t]?.id;
562
- l && O.value.has(l) && (ie.has(l) || (ie.add(l), a.push(l)));
690
+ const a = c.value[t]?.id;
691
+ a && D.value.has(a) && (ce.has(a) || (ce.add(a), n.push(a)));
563
692
  }
564
- a.length && (U(() => {
565
- const t = new Set(G.value);
566
- for (const l of a) t.add(l);
567
- G.value = t;
568
- }), ot(() => {
569
- const t = new Set(O.value);
570
- for (const l of a) t.delete(l);
571
- O.value = t, setTimeout(() => {
572
- const l = new Set(G.value);
573
- for (const s of a)
574
- l.delete(s), ie.delete(s);
575
- G.value = l;
576
- }, et);
693
+ n.length && (K(() => {
694
+ const t = new Set(U.value);
695
+ for (const a of n) t.add(a);
696
+ U.value = t;
697
+ }), ht(() => {
698
+ const t = new Set(D.value);
699
+ for (const a of n) t.delete(a);
700
+ D.value = t, setTimeout(() => {
701
+ const a = new Set(U.value);
702
+ for (const s of n)
703
+ a.delete(s), ce.delete(s);
704
+ U.value = a;
705
+ }, lt);
577
706
  }));
578
707
  },
579
708
  { flush: "post" }
580
709
  );
581
- async function dt() {
582
- if (J) return J;
583
- if (ue.value || ee.value || o.mode !== "backfill" && C.value == null || o.mode === "backfill" && C.value == null && ge.value.length === 0)
710
+ async function bt() {
711
+ if (Q) return Q;
712
+ if (ne.value || ae.value || l.mode !== "backfill" && C.value == null || l.mode === "backfill" && C.value == null && ge.value.length === 0)
584
713
  return;
585
- const e = T;
586
- let a = null;
587
- return a = (async () => {
714
+ const e = N;
715
+ let n = null;
716
+ return n = (async () => {
588
717
  try {
589
- if (ee.value = !0, K.value = "", o.mode === "backfill") {
590
- const s = await qe.loadBackfillBatch(C.value);
591
- if (e !== T) return;
592
- s.pages.length && ($.value = [...$.value, ...s.pages]), te(s.batchItems), i.value = [...i.value, ...s.batchItems], C.value = s.nextPage;
718
+ if (ae.value = !0, J.value = "", l.mode === "backfill") {
719
+ const s = await ze.loadBackfillBatch(C.value);
720
+ if (e !== N) return;
721
+ s.pages.length && (q.value = [...q.value, ...s.pages]), ee(s.batchItems), c.value = [...c.value, ...s.batchItems], C.value = s.nextPage;
593
722
  return;
594
723
  }
595
724
  const t = C.value;
596
725
  if (t == null) return;
597
- const l = await Le(t);
598
- if (e !== T) return;
599
- $.value = [...$.value, t], te(l.items), i.value = [...i.value, ...l.items], C.value = l.nextPage;
726
+ const a = await qe(t);
727
+ if (e !== N) return;
728
+ q.value = [...q.value, t], ee(a.items), c.value = [...c.value, ...a.items], C.value = a.nextPage;
600
729
  } catch (t) {
601
- if (e !== T || _e(t)) return;
602
- K.value = t instanceof Error ? t.message : String(t);
730
+ if (e !== N || Re(t)) return;
731
+ J.value = t instanceof Error ? t.message : String(t);
603
732
  } finally {
604
- e === T && (ee.value = !1), J === a && (J = null);
733
+ e === N && (ae.value = !1), Q === n && (Q = null);
605
734
  }
606
- })(), J = a, a;
735
+ })(), Q = n, n;
607
736
  }
608
- function vt() {
609
- const e = h.value;
737
+ function kt() {
738
+ const e = g.value;
610
739
  if (!e) return;
611
- H.value = e.scrollTop, b.value = e.clientHeight, e.scrollHeight - (e.scrollTop + e.clientHeight) <= o.prefetchThresholdPx && dt();
740
+ F.value = e.scrollTop, I.value = e.clientHeight, e.scrollHeight - (e.scrollTop + e.clientHeight) <= l.prefetchThresholdPx && bt();
612
741
  }
613
- function Oe() {
614
- return h.value;
742
+ function De() {
743
+ return g.value;
615
744
  }
616
- function $e(e) {
617
- p.value = N(e), b.value = e.clientHeight;
745
+ function Xe(e) {
746
+ b.value = H(e), I.value = e.clientHeight;
618
747
  }
619
- function ht() {
748
+ function Mt() {
620
749
  typeof ResizeObserver > "u" || (A = new ResizeObserver(() => {
621
- const e = Oe();
622
- e && $e(e);
750
+ const e = De();
751
+ e && Xe(e);
623
752
  }));
624
753
  }
625
- function gt() {
754
+ function It() {
626
755
  return {
627
- enabled: o.mode === "backfill",
756
+ enabled: l.mode === "backfill",
628
757
  isBackfillActive: !1,
629
758
  isRequestInFlight: !1,
630
759
  requestPage: null,
@@ -633,8 +762,8 @@ const Et = {
633
762
  target: 0
634
763
  },
635
764
  cooldownMsRemaining: 0,
636
- cooldownMsTotal: ke(o.backfillRequestDelayMs),
637
- pageSize: nt(o.pageSize),
765
+ cooldownMsTotal: ke(l.backfillRequestDelayMs),
766
+ pageSize: ft(l.pageSize),
638
767
  bufferSize: 0,
639
768
  lastBatch: null,
640
769
  totals: {
@@ -643,92 +772,132 @@ const Et = {
643
772
  }
644
773
  };
645
774
  }
646
- function Xe(e) {
647
- T += 1, J = null, Q = null, me = 0, X.clear(), j.length = 0, O.value = /* @__PURE__ */ new Set(), G.value = /* @__PURE__ */ new Set(), ie.clear(), re.value = /* @__PURE__ */ new Map(), Y.value = /* @__PURE__ */ new Set(), D.value = [], $.value = [], i.value = [], C.value = e, ge.value = [], pe.value = gt(), ue.value = !0, ee.value = !1, K.value = "";
775
+ function je() {
776
+ N += 1, Q = null, Z = null, de = 0, X.clear(), j.length = 0, D.value = /* @__PURE__ */ new Set(), U.value = /* @__PURE__ */ new Set(), ce.clear(), fe.value = /* @__PURE__ */ new Map(), O.value = /* @__PURE__ */ new Set(), V.value = [], q.value = [], C.value = null, ge.value = [], pe.value = It(), ne.value = !0, ae.value = !1, J.value = "";
648
777
  }
649
- async function je(e) {
650
- if (Q) return Q;
651
- const a = T;
778
+ function We(e) {
779
+ je(), c.value = [], C.value = e;
780
+ }
781
+ function St(e) {
782
+ const n = Array.isArray(e) ? e : [e], t = [], a = /* @__PURE__ */ new Set();
783
+ for (const s of n) {
784
+ if (s == null) continue;
785
+ const f = typeof s == "string" ? `s:${s}` : `n:${String(s)}`;
786
+ a.has(f) || (a.add(f), t.push(s));
787
+ }
788
+ return t;
789
+ }
790
+ function Pt(e) {
791
+ const n = [];
792
+ for (const t of e) {
793
+ if (typeof t == "number" && Number.isFinite(t)) {
794
+ n.push(t);
795
+ continue;
796
+ }
797
+ if (typeof t == "string") {
798
+ const a = Number.parseInt(t, 10);
799
+ Number.isFinite(a) && n.push(a);
800
+ }
801
+ }
802
+ return n.length ? Math.max(...n) + 1 : null;
803
+ }
804
+ function Ge(e) {
805
+ je();
806
+ const n = St(e);
807
+ q.value = n, C.value = Pt(n), ne.value = !1, pt(c.value), ee(c.value);
808
+ }
809
+ async function Ue(e) {
810
+ if (Z) return Z;
811
+ const n = N;
652
812
  let t = null;
653
813
  return t = (async () => {
654
814
  try {
655
- if (o.mode === "backfill") {
656
- const l = await qe.loadBackfillBatch(e);
657
- if (a !== T) return;
658
- $.value = l.pages.length ? l.pages : [e], te(l.batchItems), i.value = l.batchItems, C.value = l.nextPage;
815
+ if (l.mode === "backfill") {
816
+ const a = await ze.loadBackfillBatch(e);
817
+ if (n !== N) return;
818
+ q.value = a.pages.length ? a.pages : [e], ee(a.batchItems), c.value = a.batchItems, C.value = a.nextPage;
659
819
  } else {
660
- const l = await Le(e);
661
- if (a !== T) return;
662
- $.value = [e], te(l.items), i.value = l.items, C.value = l.nextPage;
820
+ const a = await qe(e);
821
+ if (n !== N) return;
822
+ q.value = [e], ee(a.items), c.value = a.items, C.value = a.nextPage;
663
823
  }
664
- } catch (l) {
665
- if (a !== T || _e(l)) return;
666
- K.value = l instanceof Error ? l.message : String(l);
824
+ } catch (a) {
825
+ if (n !== N || Re(a)) return;
826
+ J.value = a instanceof Error ? a.message : String(a);
667
827
  } finally {
668
- a === T && (ue.value = !1), Q === t && (Q = null);
828
+ n === N && (ne.value = !1), Z === t && (Z = null);
669
829
  }
670
- })(), Q = t, t;
830
+ })(), Z = t, t;
671
831
  }
672
- function mt() {
673
- const e = Oe();
674
- e && ($e(e), H.value = e.scrollTop, A?.observe(e));
832
+ function Ft() {
833
+ const e = De();
834
+ e && (Xe(e), F.value = e.scrollTop, A?.observe(e));
675
835
  }
676
- Mt(async () => {
677
- ht(), mt(), Xe(o.page), await je(o.page);
678
- }), St(() => {
836
+ ut(async () => {
837
+ if (Mt(), Ft(), l.restoredPagesLoaded != null) {
838
+ Ge(l.restoredPagesLoaded);
839
+ return;
840
+ }
841
+ We(l.page), await Ue(l.page);
842
+ }), ct(() => {
679
843
  A?.disconnect();
680
- }), Z(
681
- () => o.page,
844
+ }), W(
845
+ () => l.page,
682
846
  async (e) => {
683
- Xe(e), await je(e);
847
+ l.restoredPagesLoaded == null && (We(e), await Ue(e));
848
+ }
849
+ ), W(
850
+ () => l.restoredPagesLoaded,
851
+ (e) => {
852
+ e && Ge(e);
684
853
  }
685
- ), Z(
686
- R,
854
+ ), W(
855
+ E,
687
856
  () => {
688
- const e = h.value;
689
- e && (p.value = N(e));
857
+ const e = g.value;
858
+ e && (b.value = H(e));
690
859
  },
691
860
  { immediate: !1 }
692
861
  );
693
- const xe = B(() => Ft(p.value, o.itemWidth)), ne = B(
694
- () => Pt(p.value, xe.value, o.itemWidth, R.value)
862
+ const be = T(() => $t(b.value, l.itemWidth)), se = T(
863
+ () => Ot(b.value, be.value, l.itemWidth, E.value)
695
864
  );
696
- Z(
697
- [xe, ne, R, F, S, q],
865
+ W(
866
+ [be, se, E, B, x, M],
698
867
  () => {
699
868
  Ve();
700
869
  },
701
870
  { immediate: !0 }
702
- ), Z(
871
+ ), W(
703
872
  // Performance note: this component targets very large arrays (e.g. 10k items).
704
873
  // Avoid deep watchers over items; rebuild layout only when the list structure
705
874
  // changes (new array reference or length change). This keeps metadata-only
706
875
  // updates (e.g. reactions) cheap.
707
- () => [i.value, i.value.length],
876
+ () => [c.value, c.value.length],
708
877
  () => Ve(),
709
878
  { immediate: !0 }
710
879
  );
711
- const pt = B(() => [
880
+ const Bt = T(() => [
712
881
  "mt-8 flex min-h-0 flex-1 flex-col rounded-2xl border border-slate-200/70 bg-white/70 p-5 shadow-sm backdrop-blur",
713
- M.class
882
+ p.class
714
883
  ]);
715
- return (e, a) => (k(), x("section", It(m.value, { class: pt.value }), [
716
- _("div", {
884
+ return (e, n) => (P(), S("section", _t(i.value, { class: Bt.value }), [
885
+ R("div", {
717
886
  ref_key: "scrollViewportRef",
718
- ref: h,
887
+ ref: g,
719
888
  "data-testid": "items-scroll-container",
720
889
  class: "mt-4 min-h-0 flex-1 overflow-auto",
721
- style: z({ paddingRight: R.value + "px" }),
722
- onScroll: vt
890
+ style: $({ paddingRight: E.value + "px" }),
891
+ onScroll: kt
723
892
  }, [
724
- ue.value ? (k(), x("div", Et, a[0] || (a[0] = [
725
- _("div", { class: "inline-flex items-center gap-3 text-sm text-slate-600" }, [
726
- _("svg", {
893
+ ne.value ? (P(), S("div", jt, n[0] || (n[0] = [
894
+ R("div", { class: "inline-flex items-center gap-3 text-sm text-slate-600" }, [
895
+ R("svg", {
727
896
  class: "h-5 w-5 animate-spin text-slate-500",
728
897
  viewBox: "0 0 24 24",
729
898
  "aria-hidden": "true"
730
899
  }, [
731
- _("circle", {
900
+ R("circle", {
732
901
  class: "opacity-25",
733
902
  cx: "12",
734
903
  cy: "12",
@@ -737,146 +906,102 @@ const Et = {
737
906
  stroke: "currentColor",
738
907
  "stroke-width": "4"
739
908
  }),
740
- _("path", {
909
+ R("path", {
741
910
  class: "opacity-75",
742
911
  fill: "currentColor",
743
912
  d: "M4 12a8 8 0 0 1 8-8v4a4 4 0 0 0-4 4H4z"
744
913
  })
745
914
  ]),
746
- _("span", null, "Loading…")
915
+ R("span", null, "Loading…")
747
916
  ], -1)
748
- ]))) : K.value ? (k(), x("p", Ht, "Error: " + Ge(K.value), 1)) : (k(), x("div", {
917
+ ]))) : J.value ? (P(), S("p", Wt, "Error: " + Qe(J.value), 1)) : (P(), S("div", {
749
918
  key: 2,
750
919
  class: "relative",
751
- style: z({ height: ft.value + "px" })
920
+ style: $({ height: Ye.value + "px" })
752
921
  }, [
753
- (k(!0), x(Ue, null, Ke(be.value, (t) => (k(), x("article", {
754
- key: i.value[t].id,
922
+ (P(!0), S(Ze, null, et(xe.value, (t) => (P(), S("article", {
923
+ key: c.value[t].id,
755
924
  "data-testid": "item-card",
756
925
  class: "absolute overflow-hidden rounded-xl border border-slate-200/60 bg-white shadow-sm",
757
- style: z({
758
- width: ne.value + "px",
759
- transition: lt(i.value[t].id),
760
- transform: st(t)
926
+ style: $({
927
+ width: se.value + "px",
928
+ transition: vt(c.value[t].id),
929
+ transform: mt(t)
761
930
  })
762
931
  }, [
763
- L.value || S.value > 0 ? (k(), x("div", {
932
+ L.value || x.value > 0 ? (P(), S("div", {
764
933
  key: 0,
765
934
  "data-testid": "item-header-container",
766
935
  class: "w-full",
767
- style: z(le.value)
936
+ style: $(re.value)
768
937
  }, [
769
- de(e.$slots, "itemHeader", {
770
- item: i.value[t],
771
- remove: () => De(i.value[t])
938
+ ve(e.$slots, "itemHeader", {
939
+ item: c.value[t],
940
+ remove: () => Oe(c.value[t])
772
941
  })
773
- ], 4)) : fe("", !0),
774
- _("div", {
775
- class: "bg-slate-100",
776
- style: z({ aspectRatio: i.value[t].width + " / " + i.value[t].height })
777
- }, [
778
- i.value[t].type === "image" ? (k(), x("img", {
779
- key: 0,
780
- class: "h-full w-full object-cover",
781
- src: i.value[t].preview,
782
- width: i.value[t].width,
783
- height: i.value[t].height,
784
- loading: "lazy",
785
- alt: i.value[t].id
786
- }, null, 8, Ct)) : (k(), x("video", {
787
- key: 1,
788
- class: "h-full w-full object-cover",
789
- poster: i.value[t].preview,
790
- controls: "",
791
- preload: "metadata"
792
- }, [
793
- _("source", {
794
- src: i.value[t].original,
795
- type: "video/mp4"
796
- }, null, 8, zt)
797
- ], 8, Nt))
798
- ], 4),
799
- V.value || q.value > 0 ? (k(), x("div", {
942
+ ], 4)) : te("", !0),
943
+ tt(at, {
944
+ item: c.value[t]
945
+ }, null, 8, ["item"]),
946
+ Y.value || M.value > 0 ? (P(), S("div", {
800
947
  key: 1,
801
948
  "data-testid": "item-footer-container",
802
949
  class: "w-full",
803
- style: z(se.value)
950
+ style: $(ie.value)
804
951
  }, [
805
- de(e.$slots, "itemFooter", {
806
- item: i.value[t],
807
- remove: () => De(i.value[t])
952
+ ve(e.$slots, "itemFooter", {
953
+ item: c.value[t],
954
+ remove: () => Oe(c.value[t])
808
955
  })
809
- ], 4)) : fe("", !0)
956
+ ], 4)) : te("", !0)
810
957
  ], 4))), 128)),
811
- (k(!0), x(Ue, null, Ke(D.value, (t) => (k(), x("article", {
958
+ (P(!0), S(Ze, null, et(V.value, (t) => (P(), S("article", {
812
959
  key: t.id + ":leaving",
813
960
  "data-testid": "item-card-leaving",
814
961
  class: "pointer-events-none absolute overflow-hidden rounded-xl border border-slate-200/60 bg-white shadow-sm",
815
- style: z({
962
+ style: $({
816
963
  width: t.width + "px",
817
- transition: "transform " + tt + "ms ease-out",
818
- transform: t.leaving ? "translate3d(" + t.fromX + "px," + t.fromY + "px,0)" : "translate3d(" + t.fromX + "px," + Ie(t.height) + "px,0)"
964
+ transition: "transform " + rt + "ms ease-out",
965
+ transform: t.leaving ? "translate3d(" + t.fromX + "px," + t.fromY + "px,0)" : "translate3d(" + t.fromX + "px," + Se(t.height) + "px,0)"
819
966
  })
820
967
  }, [
821
- L.value || S.value > 0 ? (k(), x("div", {
968
+ L.value || x.value > 0 ? (P(), S("div", {
822
969
  key: 0,
823
970
  "data-testid": "item-header-container",
824
971
  class: "w-full",
825
- style: z(le.value)
972
+ style: $(re.value)
826
973
  }, [
827
- de(e.$slots, "itemHeader", {
974
+ ve(e.$slots, "itemHeader", {
828
975
  item: t.item,
829
976
  remove: () => {
830
977
  }
831
978
  })
832
- ], 4)) : fe("", !0),
833
- _("div", {
834
- class: "bg-slate-100",
835
- style: z({ aspectRatio: t.item.width + " / " + t.item.height })
836
- }, [
837
- t.item.type === "image" ? (k(), x("img", {
838
- key: 0,
839
- class: "h-full w-full object-cover",
840
- src: t.item.preview,
841
- width: t.item.width,
842
- height: t.item.height,
843
- loading: "lazy",
844
- alt: t.item.id
845
- }, null, 8, qt)) : (k(), x("video", {
846
- key: 1,
847
- class: "h-full w-full object-cover",
848
- poster: t.item.preview,
849
- controls: "",
850
- preload: "metadata"
851
- }, [
852
- _("source", {
853
- src: t.item.original,
854
- type: "video/mp4"
855
- }, null, 8, Yt)
856
- ], 8, Lt))
857
- ], 4),
858
- V.value || q.value > 0 ? (k(), x("div", {
979
+ ], 4)) : te("", !0),
980
+ tt(at, {
981
+ item: t.item
982
+ }, null, 8, ["item"]),
983
+ Y.value || M.value > 0 ? (P(), S("div", {
859
984
  key: 1,
860
985
  "data-testid": "item-footer-container",
861
986
  class: "w-full",
862
- style: z(se.value)
987
+ style: $(ie.value)
863
988
  }, [
864
- de(e.$slots, "itemFooter", {
989
+ ve(e.$slots, "itemFooter", {
865
990
  item: t.item,
866
991
  remove: () => {
867
992
  }
868
993
  })
869
- ], 4)) : fe("", !0)
994
+ ], 4)) : te("", !0)
870
995
  ], 4))), 128))
871
996
  ], 4)),
872
- _("div", Dt, [
873
- ee.value ? (k(), x("span", Vt, a[1] || (a[1] = [
874
- _("svg", {
997
+ R("div", Gt, [
998
+ ae.value ? (P(), S("span", Ut, n[1] || (n[1] = [
999
+ R("svg", {
875
1000
  class: "h-4 w-4 animate-spin text-slate-500",
876
1001
  viewBox: "0 0 24 24",
877
1002
  "aria-hidden": "true"
878
1003
  }, [
879
- _("circle", {
1004
+ R("circle", {
880
1005
  class: "opacity-25",
881
1006
  cx: "12",
882
1007
  cy: "12",
@@ -885,25 +1010,25 @@ const Et = {
885
1010
  stroke: "currentColor",
886
1011
  "stroke-width": "4"
887
1012
  }),
888
- _("path", {
1013
+ R("path", {
889
1014
  class: "opacity-75",
890
1015
  fill: "currentColor",
891
1016
  d: "M4 12a8 8 0 0 1 8-8v4a4 4 0 0 0-4 4H4z"
892
1017
  })
893
1018
  ], -1),
894
- _("span", null, "Loading more…", -1)
895
- ]))) : C.value == null ? (k(), x("span", Ot, "End of list")) : (k(), x("span", $t, "Scroll to load page " + Ge(C.value), 1))
1019
+ R("span", null, "Loading more…", -1)
1020
+ ]))) : C.value == null ? (P(), S("span", Kt, "End of list")) : (P(), S("span", Jt, "Scroll to load page " + Qe(C.value), 1))
896
1021
  ])
897
1022
  ], 36)
898
1023
  ], 16));
899
1024
  }
900
- }), Kt = {
901
- install(n) {
902
- n.component("Masonry", Gt);
1025
+ }), an = {
1026
+ install(o) {
1027
+ o.component("Masonry", tn);
903
1028
  }
904
1029
  };
905
1030
  export {
906
- Gt as Masonry,
907
- Kt as VibePlugin,
908
- Bt as masonryDefaults
1031
+ tn as Masonry,
1032
+ an as VibePlugin,
1033
+ Nt as masonryDefaults
909
1034
  };