@wyxos/vibe 2.0.2 → 2.1.0

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