@wyxos/vibe 1.6.29 → 2.0.2

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 (43) hide show
  1. package/README.md +29 -287
  2. package/lib/index.cjs +1 -0
  3. package/lib/index.js +795 -1791
  4. package/lib/logo-dark.svg +36 -36
  5. package/lib/logo-light.svg +29 -29
  6. package/lib/logo.svg +32 -32
  7. package/lib/manifest.json +1 -1
  8. package/package.json +82 -96
  9. package/LICENSE +0 -21
  10. package/lib/vibe.css +0 -1
  11. package/lib/vite.svg +0 -1
  12. package/src/App.vue +0 -35
  13. package/src/Masonry.vue +0 -1030
  14. package/src/archive/App.vue +0 -96
  15. package/src/archive/InfiniteMansonry.spec.ts +0 -10
  16. package/src/archive/InfiniteMasonry.vue +0 -218
  17. package/src/assets/vue.svg +0 -1
  18. package/src/calculateLayout.ts +0 -194
  19. package/src/components/CodeTabs.vue +0 -158
  20. package/src/components/MasonryItem.vue +0 -499
  21. package/src/components/examples/BasicExample.vue +0 -46
  22. package/src/components/examples/CustomItemExample.vue +0 -87
  23. package/src/components/examples/HeaderFooterExample.vue +0 -79
  24. package/src/components/examples/ManualInitExample.vue +0 -78
  25. package/src/components/examples/SwipeModeExample.vue +0 -40
  26. package/src/createMasonryTransitions.ts +0 -176
  27. package/src/main.ts +0 -6
  28. package/src/masonryUtils.ts +0 -96
  29. package/src/pages.json +0 -36402
  30. package/src/router/index.ts +0 -20
  31. package/src/style.css +0 -32
  32. package/src/types.ts +0 -101
  33. package/src/useMasonryDimensions.ts +0 -59
  34. package/src/useMasonryItems.ts +0 -231
  35. package/src/useMasonryLayout.ts +0 -164
  36. package/src/useMasonryPagination.ts +0 -539
  37. package/src/useMasonryScroll.ts +0 -61
  38. package/src/useMasonryVirtualization.ts +0 -140
  39. package/src/useSwipeMode.ts +0 -233
  40. package/src/utils/errorHandler.ts +0 -8
  41. package/src/views/Examples.vue +0 -323
  42. package/src/views/Home.vue +0 -321
  43. package/toggle-link.mjs +0 -92
package/lib/index.js CHANGED
@@ -1,1849 +1,853 @@
1
- import { nextTick as C, ref as D, computed as Q, defineComponent as Ge, onMounted as qe, onUnmounted as Je, watch as ae, createElementBlock as U, openBlock as _, createCommentVNode as ne, createElementVNode as X, normalizeStyle as he, renderSlot as K, normalizeClass as ie, withModifiers as Ce, toDisplayString as He, unref as J, Fragment as Oe, renderList as Ae, createVNode as ke, withCtx as ve, mergeProps as fe, TransitionGroup as Lt } from "vue";
2
- let Se = null;
3
- function kt() {
4
- if (Se != null) return Se;
5
- const e = document.createElement("div");
6
- e.style.visibility = "hidden", e.style.overflow = "scroll", e.style.msOverflowStyle = "scrollbar", e.style.width = "100px", e.style.height = "100px", document.body.appendChild(e);
7
- const n = document.createElement("div");
8
- n.style.width = "100%", e.appendChild(n);
9
- const s = e.offsetWidth - n.offsetWidth;
10
- return document.body.removeChild(e), Se = s, s;
11
- }
12
- function Ve(e, n, s, a = {}) {
13
- const {
14
- gutterX: h = 0,
15
- gutterY: g = 0,
16
- header: f = 0,
17
- footer: l = 0,
18
- paddingLeft: i = 0,
19
- paddingRight: M = 0,
20
- sizes: t = {
21
- base: 1,
22
- sm: 2,
23
- md: 3,
24
- lg: 4,
25
- xl: 5,
26
- "2xl": 6
27
- },
28
- placement: T = "masonry"
29
- } = a;
30
- let I = 0, x = 0;
31
- try {
32
- if (n && n.nodeType === 1 && typeof window < "u" && window.getComputedStyle) {
33
- const k = window.getComputedStyle(n);
34
- I = parseFloat(k.paddingLeft) || 0, x = parseFloat(k.paddingRight) || 0;
35
- }
36
- } catch {
37
- }
38
- const m = (i || 0) + I, L = (M || 0) + x, S = n.offsetWidth - n.clientWidth, d = S > 0 ? S + 2 : kt() + 2, c = n.offsetWidth - d - m - L, r = h * (s - 1), b = Math.floor((c - r) / s), P = e.map((k) => {
39
- const H = k.width, W = k.height;
40
- return Math.round(b * W / H) + l + f;
41
- });
42
- if (T === "sequential-balanced") {
43
- const k = P.length;
44
- if (k === 0) return [];
45
- const H = (w, F, B) => w + (F > 0 ? g : 0) + B;
46
- let W = Math.max(...P), E = P.reduce((w, F) => w + F, 0) + g * Math.max(0, k - 1);
47
- const N = (w) => {
48
- let F = 1, B = 0, j = 0;
49
- for (let q = 0; q < k; q++) {
50
- const le = P[q], G = H(B, j, le);
51
- if (G <= w)
52
- B = G, j++;
53
- else if (F++, B = le, j = 1, le > w || F > s) return !1;
54
- }
55
- return F <= s;
56
- };
57
- for (; W < E; ) {
58
- const w = Math.floor((W + E) / 2);
59
- N(w) ? E = w : W = w + 1;
60
- }
61
- const Z = E, o = new Array(s).fill(0);
62
- let v = s - 1, y = 0, R = 0;
63
- for (let w = k - 1; w >= 0; w--) {
64
- const F = P[w], B = w < v;
65
- !(H(y, R, F) <= Z) || B ? (o[v] = w + 1, v--, y = F, R = 1) : (y = H(y, R, F), R++);
66
- }
67
- o[0] = 0;
68
- const O = [], V = new Array(s).fill(0);
69
- for (let w = 0; w < s; w++) {
70
- const F = o[w], B = w + 1 < s ? o[w + 1] : k, j = w * (b + h);
71
- for (let q = F; q < B; q++) {
72
- const G = {
73
- ...e[q],
74
- columnWidth: b,
75
- imageHeight: 0,
76
- columnHeight: 0,
77
- left: 0,
78
- top: 0
79
- };
80
- G.imageHeight = P[q] - (l + f), G.columnHeight = P[q], G.left = j, G.top = V[w], V[w] += G.columnHeight + (q + 1 < B ? g : 0), O.push(G);
81
- }
82
- }
83
- return O;
84
- }
85
- const p = new Array(s).fill(0), z = [];
86
- for (let k = 0; k < e.length; k++) {
87
- const H = e[k], W = {
88
- ...H,
89
- columnWidth: 0,
90
- imageHeight: 0,
91
- columnHeight: 0,
92
- left: 0,
93
- top: 0
94
- }, E = p.indexOf(Math.min(...p)), N = H.width, Z = H.height;
95
- W.columnWidth = b, W.left = E * (b + h), W.imageHeight = Math.round(b * Z / N), W.columnHeight = W.imageHeight + l + f, W.top = p[E], p[E] += W.columnHeight + g, z.push(W);
96
- }
97
- return z;
98
- }
99
- var St = typeof global == "object" && global && global.Object === Object && global, Et = typeof self == "object" && self && self.Object === Object && self, Ke = St || Et || Function("return this")(), we = Ke.Symbol, Qe = Object.prototype, Ht = Qe.hasOwnProperty, $t = Qe.toString, de = we ? we.toStringTag : void 0;
100
- function Dt(e) {
101
- var n = Ht.call(e, de), s = e[de];
102
- try {
103
- e[de] = void 0;
104
- var a = !0;
105
- } catch {
106
- }
107
- var h = $t.call(e);
108
- return a && (n ? e[de] = s : delete e[de]), h;
109
- }
110
- var Nt = Object.prototype, zt = Nt.toString;
111
- function Bt(e) {
112
- return zt.call(e);
113
- }
114
- var Wt = "[object Null]", Rt = "[object Undefined]", je = we ? we.toStringTag : void 0;
115
- function Ft(e) {
116
- return e == null ? e === void 0 ? Rt : Wt : je && je in Object(e) ? Dt(e) : Bt(e);
117
- }
118
- function Ct(e) {
119
- return e != null && typeof e == "object";
120
- }
121
- var Ot = "[object Symbol]";
122
- function At(e) {
123
- return typeof e == "symbol" || Ct(e) && Ft(e) == Ot;
124
- }
125
- var Vt = /\s/;
126
- function jt(e) {
127
- for (var n = e.length; n-- && Vt.test(e.charAt(n)); )
128
- ;
129
- return n;
130
- }
131
- var Yt = /^\s+/;
132
- function Ut(e) {
133
- return e && e.slice(0, jt(e) + 1).replace(Yt, "");
134
- }
135
- function $e(e) {
136
- var n = typeof e;
137
- return e != null && (n == "object" || n == "function");
138
- }
139
- var Ye = NaN, _t = /^[-+]0x[0-9a-f]+$/i, Xt = /^0b[01]+$/i, Gt = /^0o[0-7]+$/i, qt = parseInt;
140
- function Ue(e) {
141
- if (typeof e == "number")
142
- return e;
143
- if (At(e))
144
- return Ye;
145
- if ($e(e)) {
146
- var n = typeof e.valueOf == "function" ? e.valueOf() : e;
147
- e = $e(n) ? n + "" : n;
148
- }
149
- if (typeof e != "string")
150
- return e === 0 ? e : +e;
151
- e = Ut(e);
152
- var s = Xt.test(e);
153
- return s || Gt.test(e) ? qt(e.slice(2), s ? 2 : 8) : _t.test(e) ? Ye : +e;
154
- }
155
- var Ee = function() {
156
- return Ke.Date.now();
157
- }, Jt = "Expected a function", Kt = Math.max, Qt = Math.min;
158
- function _e(e, n, s) {
159
- var a, h, g, f, l, i, M = 0, t = !1, T = !1, I = !0;
160
- if (typeof e != "function")
161
- throw new TypeError(Jt);
162
- n = Ue(n) || 0, $e(s) && (t = !!s.leading, T = "maxWait" in s, g = T ? Kt(Ue(s.maxWait) || 0, n) : g, I = "trailing" in s ? !!s.trailing : I);
163
- function x(p) {
164
- var z = a, k = h;
165
- return a = h = void 0, M = p, f = e.apply(k, z), f;
166
- }
167
- function m(p) {
168
- return M = p, l = setTimeout(d, n), t ? x(p) : f;
169
- }
170
- function L(p) {
171
- var z = p - i, k = p - M, H = n - z;
172
- return T ? Qt(H, g - k) : H;
173
- }
174
- function S(p) {
175
- var z = p - i, k = p - M;
176
- return i === void 0 || z >= n || z < 0 || T && k >= g;
177
- }
178
- function d() {
179
- var p = Ee();
180
- if (S(p))
181
- return c(p);
182
- l = setTimeout(d, L(p));
183
- }
184
- function c(p) {
185
- return l = void 0, I && a ? x(p) : (a = h = void 0, f);
186
- }
187
- function r() {
188
- l !== void 0 && clearTimeout(l), M = 0, a = i = h = l = void 0;
189
- }
190
- function b() {
191
- return l === void 0 ? f : c(Ee());
192
- }
193
- function P() {
194
- var p = Ee(), z = S(p);
195
- if (a = arguments, h = this, i = p, z) {
196
- if (l === void 0)
197
- return m(i);
198
- if (T)
199
- return clearTimeout(l), l = setTimeout(d, n), x(i);
200
- }
201
- return l === void 0 && (l = setTimeout(d, n)), f;
202
- }
203
- return P.cancel = r, P.flush = b, P;
204
- }
205
- function se(e, n) {
206
- const s = n ?? (typeof window < "u" ? window.innerWidth : 1024), a = e.sizes;
207
- return s >= 1536 && a["2xl"] ? a["2xl"] : s >= 1280 && a.xl ? a.xl : s >= 1024 && a.lg ? a.lg : s >= 768 && a.md ? a.md : s >= 640 && a.sm ? a.sm : a.base;
208
- }
209
- function Zt(e) {
210
- const n = e ?? (typeof window < "u" ? window.innerWidth : 1024);
211
- return n >= 1536 ? "2xl" : n >= 1280 ? "xl" : n >= 1024 ? "lg" : n >= 768 ? "md" : n >= 640 ? "sm" : "base";
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 = {
3
+ mode: "default",
4
+ pageSize: 20,
5
+ backfillRequestDelayMs: 2e3,
6
+ page: 1,
7
+ itemWidth: 300,
8
+ prefetchThresholdPx: 200,
9
+ gapX: 16,
10
+ gapY: 16,
11
+ headerHeight: 0,
12
+ footerHeight: 0,
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));
212
17
  }
213
- function ea(e) {
214
- return e.reduce((s, a) => Math.max(s, a.top + a.columnHeight), 0) + 500;
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;
215
22
  }
216
- function ta(e) {
217
- return {
218
- transform: `translate3d(${e.left}px, ${e.top}px, 0)`,
219
- top: "0px",
220
- left: "0px",
221
- width: `${e.columnWidth}px`,
222
- height: `${e.columnHeight}px`
223
- };
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;
224
26
  }
225
- function aa(e, n = 0) {
226
- return {
227
- style: ta(e),
228
- "data-top": e.top,
229
- "data-left": e.left,
230
- "data-id": `${e.page}-${e.id}`,
231
- "data-index": n
232
- };
27
+ function Ue(n) {
28
+ return Number.isFinite(n) && n > 0 ? Math.floor(n) : 1;
233
29
  }
234
- function De(e, n) {
235
- if (!e.length || n <= 0)
236
- return new Array(Math.max(1, n)).fill(0);
237
- const a = Array.from(new Set(e.map((f) => f.left))).sort((f, l) => f - l).slice(0, n), h = /* @__PURE__ */ new Map();
238
- for (let f = 0; f < a.length; f++) h.set(a[f], f);
239
- const g = new Array(a.length).fill(0);
240
- for (const f of e) {
241
- const l = h.get(f.left);
242
- l != null && (g[l] = Math.max(g[l], f.top + f.columnHeight));
243
- }
244
- for (; g.length < n; ) g.push(0);
245
- return g;
30
+ function we(n) {
31
+ return Number.isFinite(n) && n > 0 ? Math.floor(n) : 0;
246
32
  }
247
- function na(e, n) {
248
- let s = 0, a = 0;
249
- const h = 1e3;
250
- function g(t, T) {
251
- var m;
252
- const I = (m = e.container) == null ? void 0 : m.value;
253
- if (I) {
254
- const L = I.scrollTop, S = I.clientHeight;
255
- s = L - h, a = L + S + h;
256
- }
257
- return t + T >= s && t <= a;
258
- }
259
- function f(t, T) {
260
- var r;
261
- const I = parseInt(t.dataset.left || "0", 10), x = parseInt(t.dataset.top || "0", 10), m = parseInt(t.dataset.index || "0", 10), L = t.offsetHeight || parseInt(getComputedStyle(t).height || "200", 10) || 200;
262
- if ((r = n == null ? void 0 : n.virtualizing) != null && r.value) {
263
- t.style.transition = "none", t.style.opacity = "1", t.style.transform = `translate3d(${I}px, ${x}px, 0) scale(1)`, t.style.removeProperty("--masonry-opacity-delay"), t.style.transition = "", T();
264
- return;
265
- }
266
- if (!g(x, L)) {
267
- t.style.opacity = "1", t.style.transform = `translate3d(${I}px, ${x}px, 0) scale(1)`, t.style.transition = "none", T();
268
- return;
269
- }
270
- const S = Math.min(m * 20, 160), d = t.style.getPropertyValue("--masonry-opacity-delay");
271
- t.style.setProperty("--masonry-opacity-delay", `${S}ms`), t.style.opacity = "1", t.style.transform = `translate3d(${I}px, ${x}px, 0) scale(1)`;
272
- const c = () => {
273
- d ? t.style.setProperty("--masonry-opacity-delay", d) : t.style.removeProperty("--masonry-opacity-delay"), t.removeEventListener("transitionend", c), T();
33
+ function xt(n) {
34
+ async function y(l) {
35
+ const r = we(l);
36
+ if (r <= 0) return;
37
+ n.stats.value = {
38
+ ...n.stats.value,
39
+ cooldownMsTotal: r,
40
+ cooldownMsRemaining: r
274
41
  };
275
- t.addEventListener("transitionend", c);
276
- }
277
- function l(t) {
278
- var x;
279
- const T = parseInt(t.dataset.left || "0", 10), I = parseInt(t.dataset.top || "0", 10);
280
- if ((x = n == null ? void 0 : n.virtualizing) != null && x.value) {
281
- t.style.transition = "none", t.style.opacity = "1", t.style.transform = `translate3d(${T}px, ${I}px, 0) scale(1)`, t.style.removeProperty("--masonry-opacity-delay");
282
- return;
283
- }
284
- t.style.opacity = "0", t.style.transform = `translate3d(${T}px, ${I + 10}px, 0) scale(0.985)`;
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,
48
+ cooldownMsTotal: r,
49
+ cooldownMsRemaining: b
50
+ }, b <= 0 && (clearInterval(h), m());
51
+ }, w);
52
+ });
285
53
  }
286
- function i(t) {
287
- var m;
288
- const T = parseInt(t.dataset.left || "0", 10), I = parseInt(t.dataset.top || "0", 10), x = t.offsetHeight || parseInt(getComputedStyle(t).height || "200", 10) || 200;
289
- if (!((m = n == null ? void 0 : n.virtualizing) != null && m.value)) {
290
- if (!g(I, x)) {
291
- t.style.transition = "none";
292
- return;
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,
60
+ isBackfillActive: !1,
61
+ isRequestInFlight: !1,
62
+ requestPage: null,
63
+ cooldownMsTotal: w,
64
+ cooldownMsRemaining: 0,
65
+ progress: {
66
+ collected: 0,
67
+ target: 0
68
+ },
69
+ pageSize: r,
70
+ bufferSize: 0
71
+ };
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,
79
+ isBackfillActive: !0,
80
+ isRequestInFlight: !0,
81
+ requestPage: z,
82
+ progress: {
83
+ collected: Math.min(m.length, r),
84
+ target: r
85
+ },
86
+ cooldownMsTotal: w,
87
+ cooldownMsRemaining: 0,
88
+ pageSize: r
89
+ });
90
+ const I = await n.getContent(z);
91
+ p.push(z), _ && (n.stats.value = {
92
+ ...n.stats.value,
93
+ enabled: M,
94
+ isBackfillActive: !0,
95
+ isRequestInFlight: !1,
96
+ 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,
100
+ isBackfillActive: !0,
101
+ isRequestInFlight: !1,
102
+ requestPage: null,
103
+ progress: {
104
+ collected: Math.min(m.length, r),
105
+ target: r
106
+ },
107
+ cooldownMsTotal: w,
108
+ cooldownMsRemaining: 0,
109
+ pageSize: r
110
+ }) : _ && (n.stats.value = {
111
+ ...n.stats.value,
112
+ enabled: M,
113
+ isBackfillActive: !0,
114
+ progress: {
115
+ collected: Math.min(m.length, r),
116
+ target: r
117
+ }
118
+ }), _ && m.length < r && b != null && await y(w);
119
+ }
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,
124
+ isBackfillActive: !1,
125
+ isRequestInFlight: !1,
126
+ requestPage: null,
127
+ progress: {
128
+ collected: 0,
129
+ target: 0
130
+ },
131
+ cooldownMsTotal: w,
132
+ cooldownMsRemaining: 0,
133
+ pageSize: r,
134
+ bufferSize: F.length,
135
+ lastBatch: {
136
+ startPage: l,
137
+ pages: p,
138
+ usedFromBuffer: h,
139
+ fetchedFromNetwork: A,
140
+ collectedTotal: m.length,
141
+ emitted: H.length,
142
+ carried: F.length
143
+ },
144
+ totals: {
145
+ pagesFetched: n.stats.value.totals.pagesFetched + p.length,
146
+ itemsFetchedFromNetwork: n.stats.value.totals.itemsFetchedFromNetwork + A
293
147
  }
294
- t.style.transition = "none", t.style.opacity = "1", t.style.transform = `translate3d(${T}px, ${I}px, 0) scale(1)`, t.style.removeProperty("--masonry-opacity-delay"), t.style.transition = "";
295
- }
148
+ }, { batchItems: H, pages: p, nextPage: b };
296
149
  }
297
- function M(t, T) {
298
- var P;
299
- const I = parseInt(t.dataset.left || "0", 10), x = parseInt(t.dataset.top || "0", 10), m = t.offsetHeight || parseInt(getComputedStyle(t).height || "200", 10) || 200;
300
- if ((P = n == null ? void 0 : n.virtualizing) != null && P.value) {
301
- T();
302
- return;
303
- }
304
- if (!g(x, m)) {
305
- t.style.transition = "none", t.style.opacity = "0", T();
306
- return;
307
- }
308
- const L = typeof (n == null ? void 0 : n.leaveDurationMs) == "number" ? n.leaveDurationMs : Number.NaN;
309
- let S = Number.isFinite(L) && L > 0 ? L : Number.NaN;
310
- if (!Number.isFinite(S)) {
311
- const z = getComputedStyle(t).getPropertyValue("--masonry-leave-duration") || "", k = parseFloat(z);
312
- S = Number.isFinite(k) && k > 0 ? k : 200;
313
- }
314
- const d = t.style.transitionDuration, c = () => {
315
- t.removeEventListener("transitionend", r), clearTimeout(b), t.style.transitionDuration = d || "";
316
- }, r = (p) => {
317
- (!p || p.target === t) && (c(), T());
318
- }, b = setTimeout(() => {
319
- c(), T();
320
- }, S + 100);
321
- t.style.transitionDuration = `${S}ms`, t.style.opacity = "0", t.style.transform = `translate3d(${I}px, ${x + 10}px, 0) scale(0.985)`, t.addEventListener("transitionend", r);
322
- }
323
- return {
324
- onEnter: f,
325
- onBeforeEnter: l,
326
- onBeforeLeave: i,
327
- onLeave: M
328
- };
150
+ return { loadBackfillBatch: S };
329
151
  }
330
- function la({
331
- container: e,
332
- masonry: n,
333
- columns: s,
334
- containerHeight: a,
335
- isLoading: h,
336
- pageSize: g,
337
- refreshLayout: f,
338
- setItemsRaw: l,
339
- loadNext: i,
340
- loadThresholdPx: M
341
- }) {
342
- let t = 0;
343
- async function T(I, x = !1) {
344
- if (!e.value) return;
345
- const m = I ?? De(n.value, s.value), L = m.length ? Math.max(...m) : 0, S = e.value.scrollTop + e.value.clientHeight, d = e.value.scrollTop > t + 1;
346
- t = e.value.scrollTop;
347
- const c = typeof M == "number" ? M : 200, r = c >= 0 ? Math.max(0, L - c) : Math.max(0, L + c);
348
- if (S >= r && (d || x) && !h.value) {
349
- await i(), await C();
350
- return;
351
- }
352
- }
353
- return {
354
- handleScroll: T
355
- };
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]);
167
+ }
168
+ }
169
+ return { positions: p, heights: b, buckets: A, contentHeight: H, indexById: _ };
356
170
  }
357
- function oa(e) {
358
- const { useSwipeMode: n, masonry: s, isLoading: a, loadNext: h, loadPage: g, paginationHistory: f } = e, l = D(0), i = D(0), M = D(!1), t = D(0), T = D(0), I = D(null), x = Q(() => {
359
- if (!n.value || s.value.length === 0) return null;
360
- const E = Math.max(0, Math.min(l.value, s.value.length - 1));
361
- return s.value[E] || null;
362
- }), m = Q(() => {
363
- if (!n.value || !x.value) return null;
364
- const E = l.value + 1;
365
- return E >= s.value.length ? null : s.value[E] || null;
366
- }), L = Q(() => {
367
- if (!n.value || !x.value) return null;
368
- const E = l.value - 1;
369
- return E < 0 ? null : s.value[E] || null;
370
- });
371
- function S() {
372
- if (!I.value) return;
373
- const E = I.value.clientHeight;
374
- i.value = -l.value * E;
375
- }
376
- function d() {
377
- if (!m.value) {
378
- h();
379
- return;
380
- }
381
- l.value++, S(), l.value >= s.value.length - 5 && h();
382
- }
383
- function c() {
384
- L.value && (l.value--, S());
385
- }
386
- function r(E) {
387
- n.value && (M.value = !0, t.value = E.touches[0].clientY, T.value = i.value, E.preventDefault());
388
- }
389
- function b(E) {
390
- if (!n.value || !M.value) return;
391
- const N = E.touches[0].clientY - t.value;
392
- i.value = T.value + N, E.preventDefault();
393
- }
394
- function P(E) {
395
- if (!n.value || !M.value) return;
396
- M.value = !1;
397
- const N = i.value - T.value;
398
- Math.abs(N) > 100 ? N > 0 && L.value ? c() : N < 0 && m.value ? d() : S() : S(), E.preventDefault();
399
- }
400
- function p(E) {
401
- n.value && (M.value = !0, t.value = E.clientY, T.value = i.value, E.preventDefault());
402
- }
403
- function z(E) {
404
- if (!n.value || !M.value) return;
405
- const N = E.clientY - t.value;
406
- i.value = T.value + N, E.preventDefault();
407
- }
408
- function k(E) {
409
- if (!n.value || !M.value) return;
410
- M.value = !1;
411
- const N = i.value - T.value;
412
- Math.abs(N) > 100 ? N > 0 && L.value ? c() : N < 0 && m.value ? d() : S() : S(), E.preventDefault();
413
- }
414
- function H() {
415
- !n.value && l.value > 0 && (l.value = 0, i.value = 0), n.value && s.value.length === 0 && !a.value && g(f.value[0]), n.value && S();
416
- }
417
- function W() {
418
- l.value = 0, i.value = 0, M.value = !1;
419
- }
420
- return {
421
- // State
422
- currentSwipeIndex: l,
423
- swipeOffset: i,
424
- isDragging: M,
425
- swipeContainer: I,
426
- // Computed
427
- currentItem: x,
428
- nextItem: m,
429
- previousItem: L,
430
- // Functions
431
- handleTouchStart: r,
432
- handleTouchMove: b,
433
- handleTouchEnd: P,
434
- handleMouseDown: p,
435
- handleMouseMove: z,
436
- handleMouseUp: k,
437
- goToNextItem: d,
438
- goToPreviousItem: c,
439
- snapToCurrentItem: S,
440
- handleWindowResize: H,
441
- reset: W
442
- };
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);
180
+ }
181
+ const m = Array.from(w);
182
+ return m.sort((h, p) => h - p), m;
443
183
  }
444
- function ge(e) {
445
- return e instanceof Error ? e : new Error(String(e));
446
- }
447
- function ra(e) {
448
- const {
449
- getPage: n,
450
- context: s,
451
- masonry: a,
452
- isLoading: h,
453
- hasReachedEnd: g,
454
- loadError: f,
455
- currentPage: l,
456
- paginationHistory: i,
457
- refreshLayout: M,
458
- retryMaxAttempts: t,
459
- retryInitialDelayMs: T,
460
- retryBackoffStepMs: I,
461
- mode: x,
462
- backfillDelayMs: m,
463
- backfillMaxCalls: L,
464
- pageSize: S,
465
- emits: d
466
- } = e, c = typeof x == "string" ? D(x) : x, r = D(!1);
467
- let b = !1;
468
- function P(o) {
469
- return a.value.filter((v) => v.page === o).length;
470
- }
471
- function p(o, v) {
472
- return new Promise((y) => {
473
- const R = Math.max(0, o | 0), O = Date.now();
474
- v(R, R);
475
- const V = setInterval(() => {
476
- if (r.value) {
477
- clearInterval(V), y();
478
- return;
479
- }
480
- const w = Date.now() - O, F = Math.max(0, R - w);
481
- v(F, R), F <= 0 && (clearInterval(V), y());
482
- }, 100);
483
- });
484
- }
485
- async function z(o) {
486
- let v = 0;
487
- const y = t;
488
- let R = T;
489
- for (; ; )
490
- try {
491
- const O = await o();
492
- return v > 0 && d("retry:stop", { attempt: v, success: !0 }), O;
493
- } catch (O) {
494
- if (v++, v > y)
495
- throw d("retry:stop", { attempt: v - 1, success: !1 }), O;
496
- d("retry:start", { attempt: v, max: y, totalMs: R }), await p(R, (V, w) => {
497
- d("retry:tick", { attempt: v, remainingMs: V, totalMs: w });
498
- }), R += I;
184
+ const It = {
185
+ key: 0,
186
+ class: "flex h-full items-center justify-center"
187
+ }, St = {
188
+ key: 1,
189
+ 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 = {
191
+ key: 0,
192
+ 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({
194
+ inheritAttrs: !1,
195
+ __name: "Masonry",
196
+ props: /* @__PURE__ */ ct({
197
+ getContent: {},
198
+ mode: {},
199
+ pageSize: {},
200
+ backfillRequestDelayMs: {},
201
+ items: {},
202
+ page: {},
203
+ itemWidth: {},
204
+ prefetchThresholdPx: {},
205
+ gapX: {},
206
+ gapY: {},
207
+ headerHeight: {},
208
+ footerHeight: {},
209
+ overscanPx: {}
210
+ }, pt),
211
+ 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) {
220
+ 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 };
237
+ }
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`;
241
+ }
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)`;
245
+ }
246
+ function W(e) {
247
+ (typeof requestAnimationFrame == "function" ? requestAnimationFrame : (t) => setTimeout(() => t(0), 0))(() => e());
248
+ }
249
+ function Qe(e) {
250
+ W(() => W(e));
251
+ }
252
+ function ce(e) {
253
+ if (!Array.isArray(e) || e.length === 0) return;
254
+ const a = new Set(j.value);
255
+ let t = !1;
256
+ for (const s of e) {
257
+ const i = s?.id;
258
+ i && (a.has(i) || (a.add(i), t = !0));
499
259
  }
500
- }
501
- async function k(o) {
502
- try {
503
- const v = await z(() => n(o, s == null ? void 0 : s.value)), y = [...a.value, ...v.items];
504
- return a.value = y, await C(), await C(), await C(), M(y), v;
505
- } catch (v) {
506
- throw v;
507
- }
508
- }
509
- async function H(o, v = !1) {
510
- if (!v && c.value !== "backfill" || b || r.value || g.value) return;
511
- const y = (o || 0) + (S || 0);
512
- if (!S || S <= 0) return;
513
- if (i.value[i.value.length - 1] == null) {
514
- g.value = !0;
515
- return;
516
- }
517
- if (!(a.value.length >= y)) {
518
- b = !0, h.value || (h.value = !0, d("loading:start"));
519
- try {
520
- let O = 0;
521
- const V = l.value, w = i.value[i.value.length - 1];
522
- for (d("backfill:start", {
523
- target: y,
524
- fetched: a.value.length,
525
- calls: O,
526
- currentPage: V,
527
- nextPage: w
528
- }); a.value.length < y && O < L && i.value[i.value.length - 1] != null && !r.value && !g.value && b; ) {
529
- const j = l.value, q = i.value[i.value.length - 1];
530
- if (await p(m, (G, be) => {
531
- d("backfill:tick", {
532
- fetched: a.value.length,
533
- target: y,
534
- calls: O,
535
- remainingMs: G,
536
- totalMs: be,
537
- currentPage: j,
538
- nextPage: q
539
- });
540
- }), r.value || !b) break;
541
- const le = i.value[i.value.length - 1];
542
- if (le == null) {
543
- g.value = !0;
544
- break;
545
- }
546
- try {
547
- if (r.value || !b) break;
548
- const G = await k(le);
549
- if (r.value || !b) break;
550
- f.value = null, l.value = le, i.value.push(G.nextPage), G.nextPage == null && (g.value = !0);
551
- } catch (G) {
552
- if (r.value || !b) break;
553
- f.value = ge(G);
554
- }
555
- O++;
556
- }
557
- const F = l.value, B = i.value[i.value.length - 1];
558
- d("backfill:stop", {
559
- fetched: a.value.length,
560
- calls: O,
561
- currentPage: F,
562
- nextPage: B
563
- });
564
- } finally {
565
- b = !1, h.value = !1;
566
- const O = l.value, V = i.value[i.value.length - 1];
567
- d("loading:stop", {
568
- fetched: a.value.length,
569
- currentPage: O,
570
- nextPage: V
571
- });
260
+ t && (j.value = a);
261
+ }
262
+ function Me() {
263
+ 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 });
572
269
  }
573
- }
574
- }
575
- async function W(o) {
576
- if (!h.value) {
577
- r.value = !1, h.value || (h.value = !0, d("loading:start")), g.value = !1, f.value = null;
578
- try {
579
- const v = a.value.length;
580
- if (r.value) return;
581
- const y = await k(o);
582
- return r.value ? void 0 : (f.value = null, l.value = o, i.value.push(y.nextPage), y.nextPage == null && (g.value = !0), await H(v), y);
583
- } catch (v) {
584
- throw f.value = ge(v), v;
585
- } finally {
586
- h.value = !1;
587
- const v = l.value, y = i.value[i.value.length - 1];
588
- d("loading:stop", {
589
- fetched: a.value.length,
590
- currentPage: v,
591
- nextPage: y
592
- });
270
+ return e;
271
+ }
272
+ function Ie(e, a) {
273
+ 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));
593
283
  }
594
- }
595
- }
596
- async function E() {
597
- if (!h.value && !g.value) {
598
- r.value = !1, h.value || (h.value = !0, d("loading:start")), f.value = null;
599
- try {
600
- const o = a.value.length;
601
- if (r.value) return;
602
- if (c.value === "refresh" && l.value != null && P(l.value) < S) {
603
- const O = await z(() => n(l.value, s == null ? void 0 : s.value));
604
- if (r.value) return;
605
- const V = [...a.value], w = O.items.filter((B) => !B || B.id == null || B.page == null ? !1 : !V.some((j) => j && j.id === B.id && j.page === B.page));
606
- if (w.length > 0) {
607
- const B = [...a.value, ...w];
608
- a.value = B, await C(), await C(), await C(), M(B);
609
- }
610
- if (f.value = null, w.length === 0) {
611
- const B = i.value[i.value.length - 1];
612
- if (B == null) {
613
- g.value = !0;
614
- return;
615
- }
616
- const j = await k(B);
617
- return r.value ? void 0 : (f.value = null, l.value = B, i.value.push(j.nextPage), j.nextPage == null && (g.value = !0), await H(o), j);
618
- }
619
- if (P(l.value) >= S) {
620
- const B = i.value[i.value.length - 1];
621
- if (B == null) {
622
- g.value = !0;
623
- return;
624
- }
625
- const j = await k(B);
626
- return r.value ? void 0 : (f.value = null, l.value = B, i.value.push(j.nextPage), j.nextPage == null && (g.value = !0), await H(o), j);
627
- } else
628
- return O;
629
- }
630
- const v = i.value[i.value.length - 1];
631
- if (v == null) {
632
- g.value = !0;
633
- return;
634
- }
635
- const y = await k(v);
636
- return r.value ? void 0 : (f.value = null, l.value = v, i.value.push(y.nextPage), y.nextPage == null && (g.value = !0), await H(o), y);
637
- } catch (o) {
638
- throw f.value = ge(o), o;
639
- } finally {
640
- h.value = !1;
641
- const o = l.value, v = i.value[i.value.length - 1];
642
- d("loading:stop", {
643
- fetched: a.value.length,
644
- currentPage: o,
645
- nextPage: v
284
+ 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();
646
291
  });
292
+ }), 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) {
306
+ return typeof e == "number" && Number.isFinite(e);
307
+ }
308
+ function Ze(e, a) {
309
+ if (!a.length) return e;
310
+ const t = /* @__PURE__ */ new Set();
311
+ for (const d of e) {
312
+ const c = d?.id;
313
+ c && t.add(c);
647
314
  }
648
- }
649
- }
650
- async function N() {
651
- if (!h.value) {
652
- r.value = !1, h.value = !0, d("loading:start");
653
- try {
654
- const o = l.value;
655
- if (o == null) {
656
- console.warn("[Masonry] No current page to refresh - currentPage:", l.value, "paginationHistory:", i.value);
657
- return;
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)));
319
+ }
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);
329
+ continue;
658
330
  }
659
- a.value = [], g.value = !1, f.value = null, i.value = [o];
660
- const v = await k(o);
661
- if (r.value) return;
662
- f.value = null, l.value = o, i.value.push(v.nextPage), v.nextPage == null && (g.value = !0);
663
- const y = a.value.length;
664
- return await H(y), v;
665
- } catch (o) {
666
- throw f.value = ge(o), o;
667
- } finally {
668
- h.value = !1;
669
- const o = l.value, v = i.value[i.value.length - 1];
670
- d("loading:stop", {
671
- fetched: a.value.length,
672
- currentPage: o,
673
- nextPage: v
674
- });
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;
335
+ }
336
+ v.splice(f, 0, d);
675
337
  }
676
- }
677
- }
678
- function Z() {
679
- const o = b;
680
- r.value = !0, h.value = !1, b = !1;
681
- const v = l.value, y = i.value[i.value.length - 1];
682
- o && d("backfill:stop", {
683
- fetched: a.value.length,
684
- calls: 0,
685
- cancelled: !0,
686
- currentPage: v,
687
- nextPage: y
688
- }), d("loading:stop", {
689
- fetched: a.value.length,
690
- currentPage: v,
691
- nextPage: y
692
- });
693
- }
694
- return {
695
- loadPage: W,
696
- loadNext: E,
697
- refreshCurrentPage: N,
698
- cancelLoad: Z,
699
- maybeBackfillToTarget: H,
700
- getContent: k
701
- };
702
- }
703
- function ia(e) {
704
- const {
705
- masonry: n,
706
- useSwipeMode: s,
707
- refreshLayout: a,
708
- loadNext: h,
709
- maybeBackfillToTarget: g,
710
- paginationHistory: f
711
- } = e;
712
- let l = /* @__PURE__ */ new Set(), i = null, M = !1;
713
- async function t() {
714
- if (l.size === 0 || M) return;
715
- M = !0;
716
- const d = Array.from(l);
717
- l.clear(), i = null, await I(d), M = !1;
718
- }
719
- async function T(d) {
720
- l.add(d), i && clearTimeout(i), i = setTimeout(() => {
721
- t();
722
- }, 16);
723
- }
724
- async function I(d) {
725
- if (!d || d.length === 0) return;
726
- const c = new Set(d.map((b) => b.id)), r = n.value.filter((b) => !c.has(b.id));
727
- if (n.value = r, await C(), r.length === 0 && f.value.length > 0) {
728
- try {
729
- await h(), await g(0, !0);
730
- } catch {
338
+ return v;
339
+ }
340
+ async function Be(e) {
341
+ if (!e.length) return;
342
+ ce(e);
343
+ const a = Me();
344
+ o.value = Ze(o.value, e), await Oe(), Ie(a);
345
+ }
346
+ async function Fe(e) {
347
+ const t = (Array.isArray(e) ? e : [e]).map(me).filter(Boolean);
348
+ if (!t.length) return;
349
+ const s = [];
350
+ for (const i of t) {
351
+ const v = O.get(i);
352
+ v && s.push(v);
731
353
  }
732
- return;
733
- }
734
- await C(), await C(), a(r);
735
- }
736
- async function x(d) {
737
- !d || d.length === 0 || (d.forEach((c) => l.add(c)), i && clearTimeout(i), i = setTimeout(() => {
738
- t();
739
- }, 16));
740
- }
741
- async function m(d, c) {
742
- if (!d) return;
743
- const r = n.value;
744
- if (r.findIndex((z) => z.id === d.id) !== -1) return;
745
- const P = [...r], p = Math.min(c, P.length);
746
- P.splice(p, 0, d), n.value = P, await C(), s.value || (await C(), await C(), a(P));
747
- }
748
- async function L(d, c) {
749
- var E;
750
- if (!d || d.length === 0) return;
751
- if (!c || c.length !== d.length) {
752
- console.warn("[Masonry] restoreMany: items and indices arrays must have the same length");
753
- return;
754
- }
755
- const r = n.value, b = new Set(r.map((N) => N.id)), P = [];
756
- for (let N = 0; N < d.length; N++)
757
- b.has((E = d[N]) == null ? void 0 : E.id) || P.push({ item: d[N], index: c[N] });
758
- if (P.length === 0) return;
759
- const p = /* @__PURE__ */ new Map();
760
- for (const { item: N, index: Z } of P)
761
- p.set(Z, N);
762
- const z = P.length > 0 ? Math.max(...P.map(({ index: N }) => N)) : -1, k = Math.max(r.length - 1, z), H = [];
763
- let W = 0;
764
- for (let N = 0; N <= k; N++)
765
- p.has(N) ? H.push(p.get(N)) : W < r.length && (H.push(r[W]), W++);
766
- for (; W < r.length; )
767
- H.push(r[W]), W++;
768
- n.value = H, await C(), s.value || (await C(), await C(), a(H));
769
- }
770
- async function S() {
771
- n.value = [];
772
- }
773
- return {
774
- remove: T,
775
- removeMany: x,
776
- restore: m,
777
- restoreMany: L,
778
- removeAll: S
779
- };
780
- }
781
- function sa(e) {
782
- const {
783
- masonry: n,
784
- useSwipeMode: s,
785
- container: a,
786
- columns: h,
787
- containerWidth: g,
788
- masonryContentHeight: f,
789
- layout: l,
790
- fixedDimensions: i,
791
- checkItemDimensions: M
792
- } = e;
793
- let t = [];
794
- function T(L) {
795
- const S = ea(L);
796
- let d = 0;
797
- if (a.value) {
798
- const { scrollTop: c, clientHeight: r } = a.value;
799
- d = c + r + 100;
800
- }
801
- f.value = Math.max(S, d);
802
- }
803
- function I(L) {
804
- var r, b;
805
- if (s.value) {
806
- n.value = L;
807
- return;
808
- }
809
- if (n.value = L, !a.value) return;
810
- if (M(L, "refreshLayout"), L.length > 1e3 && t.length > L.length && t.length - L.length < 100) {
811
- let P = !0;
812
- for (let p = 0; p < L.length; p++)
813
- if (((r = L[p]) == null ? void 0 : r.id) !== ((b = t[p]) == null ? void 0 : b.id)) {
814
- P = !1;
815
- break;
816
- }
817
- if (P) {
818
- const p = L.map((z, k) => ({
819
- ...t[k],
820
- originalIndex: k
821
- }));
822
- T(p), n.value = p, t = p;
823
- return;
354
+ if (s.length) {
355
+ await Be(s);
356
+ for (const i of s)
357
+ i?.id && O.delete(i.id);
824
358
  }
825
359
  }
826
- const d = L.map((P, p) => ({
827
- ...P,
828
- originalIndex: p
829
- })), c = a.value;
830
- if (i.value && i.value.width !== void 0) {
831
- const P = c.style.width, p = c.style.boxSizing;
832
- c.style.boxSizing = "border-box", c.style.width = `${i.value.width}px`, c.offsetWidth;
833
- const z = Ve(d, c, h.value, l.value);
834
- c.style.width = P, c.style.boxSizing = p, T(z), n.value = z, t = z;
835
- } else {
836
- const P = Ve(d, c, h.value, l.value);
837
- T(P), n.value = P, t = P;
838
- }
839
- }
840
- function x(L, S) {
841
- i.value = L, L && (L.width !== void 0 && (g.value = L.width), !s.value && a.value && n.value.length > 0 && C(() => {
842
- h.value = se(l.value, g.value), I(n.value), S && S();
843
- }));
844
- }
845
- function m() {
846
- h.value = se(l.value, g.value), I(n.value);
847
- }
848
- return {
849
- refreshLayout: I,
850
- setFixedDimensions: x,
851
- onResize: m,
852
- calculateHeight: T
853
- };
854
- }
855
- function ua(e) {
856
- const {
857
- masonry: n,
858
- container: s,
859
- columns: a,
860
- virtualBufferPx: h,
861
- loadThresholdPx: g
862
- } = e, f = D(e.handleScroll), l = D(0), i = D(0), M = h, t = D(!1), T = D({
863
- distanceToTrigger: 0,
864
- isNearTrigger: !1
865
- }), I = Q(() => {
866
- const S = l.value - M, d = l.value + i.value + M, c = n.value;
867
- return !c || c.length === 0 ? [] : c.filter((b) => {
868
- if (typeof b.top != "number" || typeof b.columnHeight != "number")
869
- return !0;
870
- const P = b.top;
871
- return b.top + b.columnHeight >= S && P <= d;
872
- });
873
- });
874
- function x(S) {
875
- if (!s.value) return;
876
- const { scrollTop: d, clientHeight: c } = s.value, r = d + c, b = S ?? De(n.value, a.value), P = b.length ? Math.max(...b) : 0, p = typeof g == "number" ? g : 200, z = p >= 0 ? Math.max(0, P - p) : Math.max(0, P + p), k = Math.max(0, z - r), H = k <= 100;
877
- T.value = {
878
- distanceToTrigger: Math.round(k),
879
- isNearTrigger: H
880
- };
881
- }
882
- async function m() {
883
- if (s.value) {
884
- const d = s.value.scrollTop, c = s.value.clientHeight || window.innerHeight, r = c > 0 ? c : window.innerHeight;
885
- l.value = d, i.value = r;
886
- }
887
- t.value = !0, await C(), await C(), t.value = !1;
888
- const S = De(n.value, a.value);
889
- f.value(S), x(S);
890
- }
891
- function L() {
892
- l.value = 0, i.value = 0, t.value = !1, T.value = {
893
- distanceToTrigger: 0,
894
- isNearTrigger: !1
895
- };
896
- }
897
- return {
898
- viewportTop: l,
899
- viewportHeight: i,
900
- virtualizing: t,
901
- scrollProgress: T,
902
- visibleMasonry: I,
903
- updateScrollProgress: x,
904
- updateViewport: m,
905
- reset: L,
906
- handleScroll: f
907
- };
908
- }
909
- function ca(e) {
910
- const { masonry: n } = e, s = D(/* @__PURE__ */ new Set());
911
- function a(f) {
912
- return typeof f == "number" && f > 0 && Number.isFinite(f);
913
- }
914
- function h(f, l) {
915
- try {
916
- if (!Array.isArray(f) || f.length === 0) return;
917
- const i = f.filter((t) => !a(t == null ? void 0 : t.width) || !a(t == null ? void 0 : t.height));
918
- if (i.length === 0) return;
919
- const M = [];
920
- for (const t of i) {
921
- const T = (t == null ? void 0 : t.id) ?? `idx:${n.value.indexOf(t)}`;
922
- s.value.has(T) || (s.value.add(T), M.push(T));
360
+ async function Pe() {
361
+ const e = X.pop();
362
+ if (!e?.length) return;
363
+ const a = [];
364
+ for (const t of e) {
365
+ const s = O.get(t);
366
+ s && a.push(s);
923
367
  }
924
- if (M.length > 0) {
925
- const t = M.slice(0, 10);
926
- console.warn(
927
- "[Masonry] Items missing width/height detected:",
928
- {
929
- context: l,
930
- count: M.length,
931
- sampleIds: t,
932
- hint: "Ensure each item has positive width and height. Consider providing fallbacks (e.g., 512x512) at the data layer."
933
- }
934
- );
368
+ if (a.length) {
369
+ await Be(a);
370
+ for (const t of a)
371
+ t?.id && O.delete(t.id);
935
372
  }
936
- } catch {
937
- }
938
- }
939
- function g() {
940
- s.value.clear();
941
- }
942
- return {
943
- checkItemDimensions: h,
944
- invalidDimensionIds: s,
945
- reset: g
946
- };
947
- }
948
- const va = { class: "flex-1 relative min-h-0" }, fa = { class: "w-full h-full rounded-xl overflow-hidden shadow-sm transition-all duration-300 bg-white relative" }, da = {
949
- key: 0,
950
- class: "absolute inset-0 flex flex-col items-center justify-center bg-slate-100 text-slate-400 text-sm p-4 text-center"
951
- }, ga = {
952
- key: 1,
953
- class: "relative w-full h-full"
954
- }, ha = ["src"], ma = ["src", "autoplay", "controls"], pa = { class: "w-12 h-12 rounded-full bg-white/80 backdrop-blur-sm flex items-center justify-center shadow-sm" }, ya = {
955
- key: 3,
956
- class: "absolute bottom-2 left-1/2 transform -translate-x-1/2 flex items-center justify-center z-10"
957
- }, wa = {
958
- key: 4,
959
- class: "absolute inset-0 flex flex-col items-center justify-center bg-slate-50 text-slate-400 text-sm p-4 text-center"
960
- }, xe = /* @__PURE__ */ Ge({
961
- __name: "MasonryItem",
962
- props: {
963
- item: {},
964
- remove: {},
965
- type: { default: void 0 },
966
- notFound: { type: Boolean, default: void 0 },
967
- headerHeight: { default: 0 },
968
- footerHeight: { default: 0 },
969
- isActive: { type: Boolean, default: !1 },
970
- inSwipeMode: { type: Boolean, default: !1 },
971
- preloadThreshold: { default: 1 }
972
- },
973
- emits: ["preload:success", "preload:error", "mouse-enter", "mouse-leave", "in-view", "in-view-and-loaded"],
974
- setup(e, { emit: n }) {
975
- const s = e, a = n, h = D(!1), g = D(!1), f = D(null), l = D(!1), i = D(!1), M = D(null), t = D(!1), T = D(!1), I = D(!1), x = D(!1), m = D(!1), L = D(null), S = D(null);
976
- let d = null;
977
- const c = Q(() => {
978
- var o;
979
- return s.type ?? ((o = s.item) == null ? void 0 : o.type) ?? "image";
980
- }), r = Q(() => {
981
- var o;
982
- return s.notFound ?? ((o = s.item) == null ? void 0 : o.notFound) ?? !1;
983
- }), b = Q(() => !!s.inSwipeMode);
984
- function P(o, v) {
985
- const y = o === "image" ? h.value : l.value;
986
- T.value && y && !I.value && (I.value = !0, a("in-view-and-loaded", { item: s.item, type: o, src: v }));
987
- }
988
- function p(o) {
989
- a("mouse-enter", { item: s.item, type: o });
990
- }
991
- function z(o) {
992
- a("mouse-leave", { item: s.item, type: o });
993
373
  }
994
- function k(o) {
995
- if (b.value) return;
996
- const v = o.target;
997
- v && (v.paused ? v.play() : v.pause());
374
+ async function et(e) {
375
+ return Fe(e);
998
376
  }
999
- function H(o) {
1000
- const v = o.target;
1001
- v && (b.value || v.play(), p("video"));
377
+ async function tt() {
378
+ return Pe();
1002
379
  }
1003
- function W(o) {
1004
- const v = o.target;
1005
- v && (b.value || v.pause(), z("video"));
1006
- }
1007
- function E(o) {
1008
- return new Promise((v, y) => {
1009
- if (!o) {
1010
- const w = new Error("No image source provided");
1011
- a("preload:error", { item: s.item, type: "image", src: o, error: w }), y(w);
1012
- return;
1013
- }
1014
- const R = new Image(), O = Date.now(), V = 300;
1015
- R.onload = () => {
1016
- const w = Date.now() - O, F = Math.max(0, V - w);
1017
- setTimeout(async () => {
1018
- h.value = !0, g.value = !1, x.value = !1, await C(), await new Promise((B) => setTimeout(B, 100)), m.value = !0, a("preload:success", { item: s.item, type: "image", src: o }), P("image", o), v();
1019
- }, F);
1020
- }, R.onerror = () => {
1021
- g.value = !0, h.value = !1, x.value = !1;
1022
- const w = new Error("Failed to load image");
1023
- a("preload:error", { item: s.item, type: "image", src: o, error: w }), y(w);
1024
- }, R.src = o;
1025
- });
1026
- }
1027
- function N(o) {
1028
- return new Promise((v, y) => {
1029
- if (!o) {
1030
- const w = new Error("No video source provided");
1031
- a("preload:error", { item: s.item, type: "video", src: o, error: w }), y(w);
1032
- return;
1033
- }
1034
- const R = document.createElement("video"), O = Date.now(), V = 300;
1035
- R.preload = "metadata", R.muted = !0, R.onloadedmetadata = () => {
1036
- const w = Date.now() - O, F = Math.max(0, V - w);
1037
- setTimeout(async () => {
1038
- l.value = !0, i.value = !1, x.value = !1, await C(), await new Promise((B) => setTimeout(B, 100)), m.value = !0, a("preload:success", { item: s.item, type: "video", src: o }), P("video", o), v();
1039
- }, F);
1040
- }, R.onerror = () => {
1041
- i.value = !0, l.value = !1, x.value = !1;
1042
- const w = new Error("Failed to load video");
1043
- a("preload:error", { item: s.item, type: "video", src: o, error: w }), y(w);
1044
- }, R.src = o;
1045
- });
1046
- }
1047
- async function Z() {
1048
- var v;
1049
- if (!t.value || x.value || r.value || c.value === "video" && l.value || c.value === "image" && h.value)
1050
- return;
1051
- const o = (v = s.item) == null ? void 0 : v.src;
1052
- if (o)
1053
- if (x.value = !0, m.value = !1, c.value === "video") {
1054
- M.value = o, l.value = !1, i.value = !1;
1055
- try {
1056
- await N(o);
1057
- } catch {
1058
- }
1059
- } else {
1060
- f.value = o, h.value = !1, g.value = !1;
1061
- try {
1062
- await E(o);
1063
- } catch {
1064
- }
1065
- }
380
+ function Te(e) {
381
+ const t = (Array.isArray(e) ? e : [e]).map(me).filter(Boolean);
382
+ 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);
388
+ }
1066
389
  }
1067
- return qe(async () => {
1068
- if (!L.value) return;
1069
- const o = [s.preloadThreshold, 1].filter((y, R, O) => O.indexOf(y) === R).sort((y, R) => y - R);
1070
- d = new IntersectionObserver(
1071
- (y) => {
1072
- y.forEach((R) => {
1073
- const O = R.intersectionRatio, V = O >= 1, w = O >= s.preloadThreshold;
1074
- if (V && !T.value) {
1075
- T.value = !0, a("in-view", { item: s.item, type: c.value });
1076
- const F = c.value === "image" ? f.value : M.value, B = c.value === "image" ? h.value : l.value;
1077
- F && B && P(c.value, F);
1078
- }
1079
- w && !t.value ? (t.value = !0, Z()) : R.isIntersecting;
1080
- });
1081
- },
1082
- {
1083
- // Trigger at both preloadThreshold and 1.0 (fully in view)
1084
- threshold: o
1085
- }
1086
- ), d.observe(L.value), await C(), await C(), await C(), v(), setTimeout(() => {
1087
- v();
1088
- }, 100);
1089
- function v() {
1090
- if (!L.value || T.value) return;
1091
- const y = L.value.getBoundingClientRect(), R = window.innerHeight, O = window.innerWidth;
1092
- if (y.top >= 0 && y.bottom <= R && y.left >= 0 && y.right <= O && y.height > 0 && y.width > 0) {
1093
- T.value = !0, a("in-view", { item: s.item, type: c.value });
1094
- const w = c.value === "image" ? f.value : M.value, F = c.value === "image" ? h.value : l.value;
1095
- w && F && P(c.value, w);
1096
- }
390
+ const he = vt({
391
+ enabled: !1,
392
+ isBackfillActive: !1,
393
+ isRequestInFlight: !1,
394
+ requestPage: null,
395
+ progress: {
396
+ collected: 0,
397
+ target: 0
398
+ },
399
+ cooldownMsRemaining: 0,
400
+ cooldownMsTotal: 2e3,
401
+ pageSize: 20,
402
+ bufferSize: 0,
403
+ lastBatch: null,
404
+ totals: {
405
+ pagesFetched: 0,
406
+ itemsFetchedFromNetwork: 0
1097
407
  }
1098
- }), Je(() => {
1099
- d && (d.disconnect(), d = null);
1100
- }), ae(
1101
- () => {
1102
- var o;
1103
- return (o = s.item) == null ? void 0 : o.src;
408
+ }), _e = xt({
409
+ getContent: (e) => l.getContent(e),
410
+ markEnterFromLeft: ce,
411
+ buffer: de,
412
+ stats: he,
413
+ isEnabled: () => l.mode === "backfill",
414
+ getPageSize: () => l.pageSize,
415
+ getRequestDelayMs: () => l.backfillRequestDelayMs
416
+ }), ge = B(() => l.items !== void 0);
417
+ G(
418
+ () => l.items,
419
+ (e) => {
420
+ ge.value && (fe.value = Array.isArray(e) ? e : []);
1104
421
  },
1105
- async (o) => {
1106
- if (!(!o || r.value)) {
1107
- if (c.value === "video") {
1108
- if (o !== M.value && (l.value = !1, i.value = !1, M.value = o, t.value)) {
1109
- x.value = !0;
1110
- try {
1111
- await N(o);
1112
- } catch {
1113
- }
1114
- }
1115
- } else if (o !== f.value && (h.value = !1, g.value = !1, f.value = o, t.value)) {
1116
- x.value = !0;
1117
- try {
1118
- await E(o);
1119
- } catch {
1120
- }
1121
- }
1122
- }
422
+ { immediate: !0 }
423
+ );
424
+ const o = B({
425
+ get() {
426
+ return ge.value ? fe.value : Se.value;
427
+ },
428
+ set(e) {
429
+ ge.value ? (fe.value = e, r("update:items", e)) : Se.value = e;
1123
430
  }
1124
- ), ae(
1125
- () => s.isActive,
1126
- (o) => {
1127
- !b.value || !S.value || (o ? S.value.play() : S.value.pause());
431
+ });
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 };
435
+ }
436
+ function me(e) {
437
+ return e ? typeof e == "string" ? e : e?.id : null;
438
+ }
439
+ async function Re(e) {
440
+ const t = (Array.isArray(e) ? e : [e]).map(me).filter(Boolean);
441
+ 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));
1128
448
  }
1129
- ), (o, v) => (_(), U("div", {
1130
- ref_key: "containerRef",
1131
- ref: L,
1132
- class: "relative w-full h-full flex flex-col"
1133
- }, [
1134
- o.headerHeight > 0 ? (_(), U("div", {
1135
- key: 0,
1136
- class: "relative z-10",
1137
- style: he({ height: `${o.headerHeight}px` })
1138
- }, [
1139
- K(o.$slots, "header", {
1140
- item: o.item,
1141
- remove: o.remove,
1142
- imageLoaded: h.value,
1143
- imageError: g.value,
1144
- videoLoaded: l.value,
1145
- videoError: i.value,
1146
- showNotFound: r.value,
1147
- isLoading: x.value,
1148
- mediaType: c.value,
1149
- isFullyInView: T.value
1150
- })
1151
- ], 4)) : ne("", !0),
1152
- X("div", va, [
1153
- K(o.$slots, "default", {
1154
- item: o.item,
1155
- remove: o.remove,
1156
- imageLoaded: h.value,
1157
- imageError: g.value,
1158
- videoLoaded: l.value,
1159
- videoError: i.value,
1160
- showNotFound: r.value,
1161
- isLoading: x.value,
1162
- mediaType: c.value,
1163
- imageSrc: f.value,
1164
- videoSrc: M.value,
1165
- showMedia: m.value,
1166
- isFullyInView: T.value
1167
- }, () => [
1168
- X("div", fa, [
1169
- r.value ? (_(), U("div", da, v[3] || (v[3] = [
1170
- X("i", { class: "fas fa-search text-3xl mb-3 opacity-50" }, null, -1),
1171
- X("span", { class: "font-medium" }, "Not Found", -1),
1172
- X("span", { class: "text-xs mt-1 opacity-75" }, "This item could not be located", -1)
1173
- ]))) : (_(), U("div", ga, [
1174
- c.value === "image" && f.value ? (_(), U("img", {
1175
- key: 0,
1176
- src: f.value,
1177
- class: ie([
1178
- "w-full h-full object-cover transition-opacity duration-700 ease-in-out",
1179
- h.value && m.value ? "opacity-100" : "opacity-0"
1180
- ]),
1181
- style: { position: "absolute", top: "0", left: "0" },
1182
- loading: "lazy",
1183
- decoding: "async",
1184
- alt: "",
1185
- onMouseenter: v[0] || (v[0] = (y) => p("image")),
1186
- onMouseleave: v[1] || (v[1] = (y) => z("image"))
1187
- }, null, 42, ha)) : ne("", !0),
1188
- c.value === "video" && M.value ? (_(), U("video", {
1189
- key: 1,
1190
- ref_key: "videoEl",
1191
- ref: S,
1192
- src: M.value,
1193
- class: ie([
1194
- "w-full h-full object-cover transition-opacity duration-700 ease-in-out",
1195
- l.value && m.value ? "opacity-100" : "opacity-0"
1196
- ]),
1197
- style: { position: "absolute", top: "0", left: "0" },
1198
- muted: "",
1199
- loop: "",
1200
- playsinline: "",
1201
- autoplay: b.value && s.isActive,
1202
- controls: b.value,
1203
- onClick: Ce(k, ["stop"]),
1204
- onTouchend: Ce(k, ["stop", "prevent"]),
1205
- onMouseenter: H,
1206
- onMouseleave: W,
1207
- onError: v[2] || (v[2] = (y) => i.value = !0)
1208
- }, null, 42, ma)) : ne("", !0),
1209
- !h.value && !l.value && !g.value && !i.value ? (_(), U("div", {
1210
- key: 2,
1211
- class: ie([
1212
- "absolute inset-0 bg-slate-100 flex items-center justify-center transition-opacity duration-500",
1213
- m.value ? "opacity-0 pointer-events-none" : "opacity-100"
1214
- ])
1215
- }, [
1216
- X("div", pa, [
1217
- K(o.$slots, "placeholder-icon", { mediaType: c.value }, () => [
1218
- X("i", {
1219
- class: ie(c.value === "video" ? "fas fa-video text-xl text-slate-400" : "fas fa-image text-xl text-slate-400")
1220
- }, null, 2)
1221
- ])
1222
- ])
1223
- ], 2)) : ne("", !0),
1224
- x.value ? (_(), U("div", ya, v[4] || (v[4] = [
1225
- X("div", { class: "bg-white/90 backdrop-blur-sm rounded-full px-3 py-1.5 shadow-sm" }, [
1226
- X("div", { class: "animate-spin rounded-full h-4 w-4 border-b-2 border-blue-500" })
1227
- ], -1)
1228
- ]))) : ne("", !0),
1229
- c.value === "image" && g.value || c.value === "video" && i.value ? (_(), U("div", wa, [
1230
- X("i", {
1231
- class: ie(c.value === "video" ? "fas fa-video text-2xl mb-2 opacity-50" : "fas fa-image text-2xl mb-2 opacity-50")
1232
- }, null, 2),
1233
- X("span", null, "Failed to load " + He(c.value), 1)
1234
- ])) : ne("", !0)
1235
- ]))
1236
- ])
1237
- ])
1238
- ]),
1239
- o.footerHeight > 0 ? (_(), U("div", {
1240
- key: 1,
1241
- class: "relative z-10",
1242
- style: he({ height: `${o.footerHeight}px` })
1243
- }, [
1244
- K(o.$slots, "footer", {
1245
- item: o.item,
1246
- remove: o.remove,
1247
- imageLoaded: h.value,
1248
- imageError: g.value,
1249
- videoLoaded: l.value,
1250
- videoError: i.value,
1251
- showNotFound: r.value,
1252
- isLoading: x.value,
1253
- mediaType: c.value,
1254
- isFullyInView: T.value
1255
- })
1256
- ], 4)) : ne("", !0)
1257
- ], 512));
1258
- }
1259
- }), xa = {
1260
- key: 0,
1261
- class: "w-full h-full flex items-center justify-center"
1262
- }, ba = { class: "w-full h-full flex items-center justify-center p-4" }, Ma = { class: "w-full h-full max-w-full max-h-full relative" }, Ta = {
1263
- key: 0,
1264
- class: "w-full py-8 text-center"
1265
- }, Pa = {
1266
- key: 1,
1267
- class: "w-full py-8 text-center"
1268
- }, Ia = { class: "text-red-500 dark:text-red-400" }, La = {
1269
- key: 0,
1270
- class: "w-full py-8 text-center"
1271
- }, ka = {
1272
- key: 1,
1273
- class: "w-full py-8 text-center"
1274
- }, Sa = { class: "text-red-500 dark:text-red-400" }, Ea = /* @__PURE__ */ Ge({
1275
- __name: "Masonry",
1276
- props: {
1277
- getPage: {
1278
- type: Function,
1279
- default: () => {
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,
464
+ leaving: !0
465
+ });
1280
466
  }
1281
- },
1282
- loadAtPage: {
1283
- type: [Number, String],
1284
- default: null
1285
- },
1286
- items: {
1287
- type: Array,
1288
- default: () => []
1289
- },
1290
- // Opaque caller-owned context passed through to getPage(page, context).
1291
- // Useful for including filters, service selection, tabId, etc.
1292
- context: {
1293
- type: Object,
1294
- default: null
1295
- },
1296
- layout: {
1297
- type: Object
1298
- },
1299
- paginationType: {
1300
- type: String,
1301
- default: "page",
1302
- // or 'cursor'
1303
- validator: (e) => ["page", "cursor"].includes(e)
1304
- },
1305
- init: {
1306
- type: String,
1307
- default: "manual",
1308
- validator: (e) => ["auto", "manual"].includes(e)
1309
- },
1310
- pageSize: {
1311
- type: Number,
1312
- default: 40
1313
- },
1314
- // Backfill configuration
1315
- mode: {
1316
- type: String,
1317
- default: "backfill",
1318
- validator: (e) => ["backfill", "none", "refresh"].includes(e)
1319
- },
1320
- backfillDelayMs: {
1321
- type: Number,
1322
- default: 2e3
1323
- },
1324
- backfillMaxCalls: {
1325
- type: Number,
1326
- default: 10
1327
- },
1328
- // Retry configuration
1329
- retryMaxAttempts: {
1330
- type: Number,
1331
- default: 3
1332
- },
1333
- retryInitialDelayMs: {
1334
- type: Number,
1335
- default: 2e3
1336
- },
1337
- retryBackoffStepMs: {
1338
- type: Number,
1339
- default: 2e3
1340
- },
1341
- transitionDurationMs: {
1342
- type: Number,
1343
- default: 450
1344
- },
1345
- // Shorter, snappier duration specifically for item removal (leave)
1346
- leaveDurationMs: {
1347
- type: Number,
1348
- default: 160
1349
- },
1350
- transitionEasing: {
1351
- type: String,
1352
- default: "cubic-bezier(.22,.61,.36,1)"
1353
- },
1354
- // Force motion even when user has reduced-motion enabled
1355
- forceMotion: {
1356
- type: Boolean,
1357
- default: !1
1358
- },
1359
- virtualBufferPx: {
1360
- type: Number,
1361
- default: 600
1362
- },
1363
- loadThresholdPx: {
1364
- type: Number,
1365
- default: 200
1366
- },
1367
- // Layout mode: 'auto' (detect from screen size), 'masonry', or 'swipe'
1368
- layoutMode: {
1369
- type: String,
1370
- default: "auto",
1371
- validator: (e) => ["auto", "masonry", "swipe"].includes(e)
1372
- },
1373
- // Breakpoint for switching to swipe mode (in pixels or Tailwind breakpoint name)
1374
- mobileBreakpoint: {
1375
- type: [Number, String],
1376
- default: 768
1377
- // 'md' breakpoint
1378
- }
1379
- },
1380
- emits: [
1381
- "update:items",
1382
- "loading:start",
1383
- "backfill:start",
1384
- "backfill:tick",
1385
- "backfill:stop",
1386
- "retry:start",
1387
- "retry:tick",
1388
- "retry:stop",
1389
- "loading:stop",
1390
- "remove-all:complete",
1391
- // Re-emit item-level preload events from the default MasonryItem
1392
- "item:preload:success",
1393
- "item:preload:error",
1394
- // Mouse events from MasonryItem content
1395
- "item:mouse-enter",
1396
- "item:mouse-leave",
1397
- "update:context"
1398
- ],
1399
- setup(e, { expose: n, emit: s }) {
1400
- const a = e, h = {
1401
- sizes: { base: 1, sm: 2, md: 3, lg: 4, xl: 5, "2xl": 6 },
1402
- gutterX: 10,
1403
- gutterY: 10,
1404
- header: 0,
1405
- footer: 0,
1406
- paddingLeft: 0,
1407
- paddingRight: 0,
1408
- placement: "masonry"
1409
- }, g = Q(() => {
1410
- var u;
1411
- return {
1412
- ...h,
1413
- ...a.layout,
1414
- sizes: {
1415
- ...h.sizes,
1416
- ...((u = a.layout) == null ? void 0 : u.sizes) || {}
1417
- }
1418
- };
1419
- }), f = D(null), l = D(typeof window < "u" ? window.innerWidth : 1024), i = D(typeof window < "u" ? window.innerHeight : 768), M = D(null);
1420
- let t = null;
1421
- function T(u) {
1422
- return {
1423
- sm: 640,
1424
- md: 768,
1425
- lg: 1024,
1426
- xl: 1280,
1427
- "2xl": 1536
1428
- }[u] || 768;
1429
- }
1430
- const I = Q(() => {
1431
- if (a.layoutMode === "masonry") return !1;
1432
- if (a.layoutMode === "swipe") return !0;
1433
- const u = typeof a.mobileBreakpoint == "string" ? T(a.mobileBreakpoint) : a.mobileBreakpoint;
1434
- return l.value < u;
1435
- }), x = s, m = Q({
1436
- get: () => a.items,
1437
- set: (u) => x("update:items", u)
1438
- }), L = Q({
1439
- get: () => a.context,
1440
- set: (u) => x("update:context", u)
1441
- });
1442
- function S(u) {
1443
- L.value = u;
1444
- }
1445
- const d = Q(() => {
1446
- const u = m.value;
1447
- return (u == null ? void 0 : u.length) ?? 0;
1448
- }), c = D(7), r = D(null), b = D([]), P = D(null), p = D(!1), z = D(0), k = D(!1), H = D(null), W = D(!1), E = Q(() => Zt(l.value)), N = ca({
1449
- masonry: m
1450
- }), { checkItemDimensions: Z, reset: o } = N, v = sa({
1451
- masonry: m,
1452
- useSwipeMode: I,
1453
- container: r,
1454
- columns: c,
1455
- containerWidth: l,
1456
- masonryContentHeight: z,
1457
- layout: g,
1458
- fixedDimensions: M,
1459
- checkItemDimensions: Z
1460
- }), { refreshLayout: y, setFixedDimensions: R, onResize: O } = v, V = ua({
1461
- masonry: m,
1462
- container: r,
1463
- columns: c,
1464
- virtualBufferPx: a.virtualBufferPx,
1465
- loadThresholdPx: a.loadThresholdPx,
1466
- handleScroll: () => {
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
475
+ ), setTimeout(() => {
476
+ Y.value = Y.value.filter((u) => !f.has(u.id));
477
+ }, We);
478
+ });
1467
479
  }
1468
- // Will be set after pagination is initialized
1469
- }), { viewportTop: w, viewportHeight: F, virtualizing: B, visibleMasonry: j, updateScrollProgress: q, updateViewport: le, reset: G } = V, { onEnter: be, onBeforeEnter: Ze, onBeforeLeave: et, onLeave: tt } = na(
1470
- { container: r },
1471
- { leaveDurationMs: a.leaveDurationMs, virtualizing: B }
1472
- ), at = be, nt = Ze, lt = et, ot = tt, rt = Q(() => a.mode), it = ra({
1473
- getPage: a.getPage,
1474
- context: L,
1475
- masonry: m,
1476
- isLoading: p,
1477
- hasReachedEnd: k,
1478
- loadError: H,
1479
- currentPage: P,
1480
- paginationHistory: b,
1481
- refreshLayout: y,
1482
- retryMaxAttempts: a.retryMaxAttempts,
1483
- retryInitialDelayMs: a.retryInitialDelayMs,
1484
- retryBackoffStepMs: a.retryBackoffStepMs,
1485
- mode: rt,
1486
- backfillDelayMs: a.backfillDelayMs,
1487
- backfillMaxCalls: a.backfillMaxCalls,
1488
- pageSize: a.pageSize,
1489
- emits: x
1490
- }), { loadPage: Me, loadNext: me, refreshCurrentPage: st, cancelLoad: Te, maybeBackfillToTarget: ut } = it, ee = oa({
1491
- useSwipeMode: I,
1492
- masonry: m,
1493
- isLoading: p,
1494
- loadNext: me,
1495
- loadPage: Me,
1496
- paginationHistory: b
1497
- }), { handleScroll: ct } = la({
1498
- container: r,
1499
- masonry: m,
1500
- columns: c,
1501
- containerHeight: z,
1502
- isLoading: p,
1503
- pageSize: a.pageSize,
1504
- refreshLayout: y,
1505
- setItemsRaw: (u) => {
1506
- m.value = u;
1507
- },
1508
- loadNext: me,
1509
- loadThresholdPx: a.loadThresholdPx
1510
- });
1511
- V.handleScroll.value = ct;
1512
- const vt = ia({
1513
- masonry: m,
1514
- useSwipeMode: I,
1515
- refreshLayout: y,
1516
- loadNext: me,
1517
- maybeBackfillToTarget: ut,
1518
- paginationHistory: b
1519
- }), { remove: ue, removeMany: ft, restore: dt, restoreMany: gt, removeAll: ht } = vt;
1520
- function mt(u) {
1521
- R(u, q), !u && f.value && (l.value = f.value.clientWidth, i.value = f.value.clientHeight);
1522
480
  }
1523
- n({
1524
- // Cancels any ongoing load operations (page loads, backfills, etc.)
1525
- cancelLoad: Te,
1526
- // Opaque caller context passed through to getPage(page, context). Useful for including filters, service selection, tabId, etc.
1527
- context: L,
1528
- // Container height (wrapper element) in pixels
1529
- containerHeight: i,
1530
- // Container width (wrapper element) in pixels
1531
- containerWidth: l,
1532
- // Current Tailwind breakpoint name (base, sm, md, lg, xl, 2xl) based on containerWidth
1533
- currentBreakpoint: E,
1534
- // Current page number or cursor being displayed
1535
- currentPage: P,
1536
- // Completely destroys the component, clearing all state and resetting to initial state
1537
- destroy: Pt,
1538
- // Boolean indicating if the end of the list has been reached (no more pages to load)
1539
- hasReachedEnd: k,
1540
- // Initializes the component with items, page, and next page cursor. Use this for manual init mode.
1541
- initialize: It,
1542
- // Boolean indicating if the component has been initialized (first content has loaded)
1543
- isInitialized: W,
1544
- // Boolean indicating if a page load or backfill operation is currently in progress
1545
- isLoading: p,
1546
- // Error object if the last load operation failed, null otherwise
1547
- loadError: H,
1548
- // Loads the next page of items asynchronously
1549
- loadNext: me,
1550
- // Loads a specific page number or cursor asynchronously
1551
- loadPage: Me,
1552
- // Array tracking pagination history (pages/cursors that have been loaded)
1553
- paginationHistory: b,
1554
- // Refreshes the current page by clearing items and reloading from the current page
1555
- refreshCurrentPage: st,
1556
- // Recalculates the layout positions for all items. Call this after manually modifying items.
1557
- refreshLayout: y,
1558
- // Removes a single item from the masonry
1559
- remove: ue,
1560
- // Removes all items from the masonry
1561
- removeAll: ht,
1562
- // Clears all items and pagination history (useful when applying filters)
1563
- clear: Mt,
1564
- // Removes multiple items from the masonry in a single operation
1565
- removeMany: ft,
1566
- // Resets the component to initial state (clears items, resets pagination, scrolls to top)
1567
- reset: Tt,
1568
- // Restores a single item at its original index (useful for undo operations)
1569
- restore: dt,
1570
- // Restores multiple items at their original indices (useful for undo operations)
1571
- restoreMany: gt,
1572
- // Scrolls the container to a specific position
1573
- scrollTo: xt,
1574
- // Scrolls the container to the top
1575
- scrollToTop: wt,
1576
- // Sets the opaque caller context (alternative to v-model:context)
1577
- setContext: S,
1578
- // Sets fixed dimensions for the container, overriding ResizeObserver. Pass null to restore automatic sizing.
1579
- setFixedDimensions: mt,
1580
- // Computed property returning the total number of items currently in the masonry
1581
- totalItems: Q(() => m.value.length)
481
+ async function Ae(e) {
482
+ return Re(e);
483
+ }
484
+ y({
485
+ remove: Re,
486
+ restore: et,
487
+ undo: tt,
488
+ forget: Te,
489
+ // 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
1582
494
  });
1583
- const ce = ee.currentSwipeIndex, pe = ee.swipeOffset, ye = ee.isDragging, oe = ee.swipeContainer, Ne = ee.handleTouchStart, ze = ee.handleTouchMove, Be = ee.handleTouchEnd, We = ee.handleMouseDown, Pe = ee.handleMouseMove, Ie = ee.handleMouseUp, Le = ee.snapToCurrentItem;
1584
- function pt(u) {
1585
- const $ = d.value, Y = typeof u == "string" ? parseInt(u, 10) : u;
1586
- return $ > 0 ? `${Y * (100 / $)}%` : "0%";
1587
- }
1588
- function yt() {
1589
- const u = d.value;
1590
- return u > 0 ? `${100 / u}%` : "0%";
1591
- }
1592
- function wt(u) {
1593
- r.value && r.value.scrollTo({
1594
- top: 0,
1595
- behavior: (u == null ? void 0 : u.behavior) ?? "smooth",
1596
- ...u
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
1597
505
  });
506
+ P.value = e.positions, $.value = e.heights, be.value = e.buckets, xe.value = e.contentHeight, ae.value = e.indexById;
507
+ }
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,
512
+ overscanPx: l.overscanPx,
513
+ bucketPx: Xe,
514
+ buckets: be.value
515
+ }));
516
+ G(
517
+ pe,
518
+ (e) => {
519
+ if (!e?.length) return;
520
+ const a = [];
521
+ 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)));
524
+ }
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);
538
+ }));
539
+ },
540
+ { flush: "post" }
541
+ );
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))
544
+ 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;
548
+ return;
549
+ }
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);
556
+ } finally {
557
+ J.value = !1;
558
+ }
1598
559
  }
1599
- function xt(u) {
1600
- r.value && (r.value.scrollTo({
1601
- top: u.top ?? r.value.scrollTop,
1602
- left: u.left ?? r.value.scrollLeft,
1603
- behavior: u.behavior ?? "auto"
1604
- }), r.value && (w.value = r.value.scrollTop, F.value = r.value.clientHeight || window.innerHeight));
560
+ function st() {
561
+ const e = h.value;
562
+ if (!e) return;
563
+ A.value = e.scrollTop, b.value = e.clientHeight, e.scrollHeight - (e.scrollTop + e.clientHeight) <= l.prefetchThresholdPx && at();
1605
564
  }
1606
- function bt() {
1607
- O(), r.value && (w.value = r.value.scrollTop, F.value = r.value.clientHeight);
565
+ function ze() {
566
+ return h.value;
1608
567
  }
1609
- function Mt() {
1610
- m.value = [], b.value = [];
568
+ function Ne(e) {
569
+ p.value = z(e), b.value = e.clientHeight;
1611
570
  }
1612
- function Tt() {
1613
- Te(), r.value && r.value.scrollTo({
1614
- top: 0,
1615
- behavior: "smooth"
1616
- }), m.value = [], i.value = 0, P.value = a.loadAtPage, b.value = [a.loadAtPage], k.value = !1, H.value = null, W.value = !1, G();
571
+ function lt() {
572
+ typeof ResizeObserver > "u" || (_ = new ResizeObserver(() => {
573
+ const e = ze();
574
+ e && Ne(e);
575
+ }));
1617
576
  }
1618
- function Pt() {
1619
- Te(), m.value = [], z.value = 0, P.value = null, b.value = [], k.value = !1, H.value = null, p.value = !1, W.value = !1, ce.value = 0, pe.value = 0, ye.value = !1, G(), o(), r.value && r.value.scrollTo({
1620
- top: 0,
1621
- behavior: "auto"
1622
- // Instant scroll for destroy
1623
- });
577
+ function ot() {
578
+ return {
579
+ enabled: l.mode === "backfill",
580
+ isBackfillActive: !1,
581
+ isRequestInFlight: !1,
582
+ requestPage: null,
583
+ progress: {
584
+ collected: 0,
585
+ target: 0
586
+ },
587
+ cooldownMsRemaining: 0,
588
+ cooldownMsTotal: we(l.backfillRequestDelayMs),
589
+ pageSize: Ue(l.pageSize),
590
+ bufferSize: 0,
591
+ lastBatch: null,
592
+ totals: {
593
+ pagesFetched: 0,
594
+ itemsFetchedFromNetwork: 0
595
+ }
596
+ };
1624
597
  }
1625
- const re = _e(async () => {
1626
- I.value || await le();
1627
- }, 200), Re = _e(bt, 200);
1628
- function Fe() {
1629
- ee.handleWindowResize();
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 = "";
1630
600
  }
1631
- async function It(u, $, Y) {
1632
- P.value = $, b.value = [$], Y != null && b.value.push(Y), k.value = Y === null, Z(u, "initialize");
1633
- const te = m.value, A = te.length === 0 ? u : [...te, ...u];
1634
- m.value = A, await C(), I.value ? ce.value === 0 && m.value.length > 0 && (pe.value = 0) : (await C(), await C(), y(A), r.value && (w.value = r.value.scrollTop, F.value = r.value.clientHeight || window.innerHeight), C(() => {
1635
- r.value && (w.value = r.value.scrollTop, F.value = r.value.clientHeight || window.innerHeight, q());
1636
- })), u && u.length > 0 && (W.value = !0);
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;
609
+ }
610
+ } catch (a) {
611
+ U.value = a instanceof Error ? a.message : String(a);
612
+ } finally {
613
+ se.value = !1;
614
+ }
1637
615
  }
1638
- return ae(
1639
- g,
616
+ function it() {
617
+ const e = ze();
618
+ e && (Ne(e), A.value = e.scrollTop, _?.observe(e));
619
+ }
620
+ ht(async () => {
621
+ lt(), it(), qe(l.page), await Ee(l.page);
622
+ }), gt(() => {
623
+ _?.disconnect();
624
+ }), G(
625
+ () => l.page,
626
+ async (e) => {
627
+ qe(e), await Ee(e);
628
+ }
629
+ ), G(
630
+ H,
1640
631
  () => {
1641
- I.value || r.value && (c.value = se(g.value, l.value), y(m.value));
1642
- },
1643
- { deep: !0 }
1644
- ), ae(() => a.layoutMode, () => {
1645
- M.value && M.value.width !== void 0 ? l.value = M.value.width : f.value && (l.value = f.value.clientWidth);
1646
- }), ae(r, (u) => {
1647
- u && !I.value ? (u.removeEventListener("scroll", re), u.addEventListener("scroll", re, { passive: !0 })) : u && u.removeEventListener("scroll", re);
1648
- }, { immediate: !0 }), ae(
1649
- () => m.value.length,
1650
- (u, $) => {
1651
- a.init === "manual" && !W.value && u > 0 && $ === 0 && (W.value = !0);
632
+ const e = h.value;
633
+ e && (p.value = z(e));
1652
634
  },
1653
635
  { immediate: !1 }
1654
- ), ae(I, (u, $) => {
1655
- $ === void 0 && u === !1 || C(() => {
1656
- u ? (document.addEventListener("mousemove", Pe), document.addEventListener("mouseup", Ie), r.value && r.value.removeEventListener("scroll", re), ce.value = 0, pe.value = 0, m.value.length > 0 && Le()) : (document.removeEventListener("mousemove", Pe), document.removeEventListener("mouseup", Ie), r.value && f.value && (M.value && M.value.width !== void 0 ? l.value = M.value.width : l.value = f.value.clientWidth, r.value.removeEventListener("scroll", re), r.value.addEventListener("scroll", re, { passive: !0 }), m.value.length > 0 && (c.value = se(g.value, l.value), y(m.value), w.value = r.value.scrollTop, F.value = r.value.clientHeight, q())));
1657
- });
1658
- }, { immediate: !0 }), ae(oe, (u) => {
1659
- u && (u.addEventListener("touchstart", Ne, { passive: !1 }), u.addEventListener("touchmove", ze, { passive: !1 }), u.addEventListener("touchend", Be), u.addEventListener("mousedown", We));
1660
- }), ae(() => m.value.length, (u, $) => {
1661
- I.value && u > 0 && $ === 0 && (ce.value = 0, C(() => Le()));
1662
- }), ae(f, (u) => {
1663
- t && (t.disconnect(), t = null), u && typeof ResizeObserver < "u" ? (t = new ResizeObserver(($) => {
1664
- if (!M.value)
1665
- for (const Y of $) {
1666
- const te = Y.contentRect.width, A = Y.contentRect.height;
1667
- l.value !== te && (l.value = te), i.value !== A && (i.value = A);
1668
- }
1669
- }), t.observe(u), M.value || (l.value = u.clientWidth, i.value = u.clientHeight)) : u && (M.value || (l.value = u.clientWidth, i.value = u.clientHeight));
1670
- }, { immediate: !0 }), ae(l, (u, $) => {
1671
- u !== $ && u > 0 && !I.value && r.value && m.value.length > 0 && C(() => {
1672
- c.value = se(g.value, u), y(m.value), q();
1673
- });
1674
- }), qe(async () => {
1675
- try {
1676
- await C(), f.value && !t && (l.value = f.value.clientWidth, i.value = f.value.clientHeight), I.value || (c.value = se(g.value, l.value), r.value && (w.value = r.value.scrollTop, F.value = r.value.clientHeight));
1677
- const u = a.loadAtPage;
1678
- if (a.init === "auto" && b.value.length === 0 && (b.value = [u]), a.init === "auto") {
1679
- W.value = !0, await C();
1680
- try {
1681
- await Me(u);
1682
- } catch {
1683
- }
1684
- }
1685
- I.value ? C(() => Le()) : q();
1686
- } catch (u) {
1687
- H.value || (console.error("Error during component initialization:", u), H.value = ge(u)), p.value = !1;
1688
- }
1689
- window.addEventListener("resize", Re), window.addEventListener("resize", Fe);
1690
- }), Je(() => {
1691
- var u;
1692
- t && (t.disconnect(), t = null), (u = r.value) == null || u.removeEventListener("scroll", re), window.removeEventListener("resize", Re), window.removeEventListener("resize", Fe), oe.value && (oe.value.removeEventListener("touchstart", Ne), oe.value.removeEventListener("touchmove", ze), oe.value.removeEventListener("touchend", Be), oe.value.removeEventListener("mousedown", We)), document.removeEventListener("mousemove", Pe), document.removeEventListener("mouseup", Ie);
1693
- }), (u, $) => (_(), U("div", {
1694
- ref_key: "wrapper",
1695
- ref: f,
1696
- class: "w-full h-full flex flex-col relative"
1697
- }, [
1698
- W.value ? I.value ? (_(), U("div", {
1699
- key: 1,
1700
- class: ie(["overflow-hidden w-full flex-1 swipe-container touch-none select-none", { "force-motion": a.forceMotion, "cursor-grab": !J(ye), "cursor-grabbing": J(ye) }]),
1701
- ref_key: "swipeContainer",
1702
- ref: oe,
1703
- style: { height: "100%", "max-height": "100%", position: "relative" }
636
+ );
637
+ const ye = B(() => yt(p.value, l.itemWidth)), Z = B(
638
+ () => wt(p.value, ye.value, l.itemWidth, H.value)
639
+ );
640
+ G(
641
+ [ye, Z, H, F, I, q],
642
+ () => {
643
+ Ce();
644
+ },
645
+ { immediate: !0 }
646
+ ), G(
647
+ // Performance note: this component targets very large arrays (e.g. 10k items).
648
+ // Avoid deep watchers over items; rebuild layout only when the list structure
649
+ // changes (new array reference or length change). This keeps metadata-only
650
+ // updates (e.g. reactions) cheap.
651
+ () => [o.value, o.value.length],
652
+ () => Ce(),
653
+ { immediate: !0 }
654
+ );
655
+ const rt = B(() => [
656
+ "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
658
+ ]);
659
+ return (e, a) => (k(), x("section", mt(m.value, { class: rt.value }), [
660
+ T("div", {
661
+ ref_key: "scrollViewportRef",
662
+ ref: h,
663
+ "data-testid": "items-scroll-container",
664
+ class: "mt-4 min-h-0 flex-1 overflow-auto",
665
+ style: N({ paddingRight: H.value + "px" }),
666
+ onScroll: st
1704
667
  }, [
1705
- X("div", {
1706
- class: "relative w-full",
1707
- style: he({
1708
- transform: `translateY(${J(pe)}px)`,
1709
- transition: J(ye) ? "none" : `transform ${e.transitionDurationMs}ms ${e.transitionEasing}`,
1710
- height: `${d.value * 100}%`
1711
- })
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", {
671
+ class: "h-5 w-5 animate-spin text-slate-500",
672
+ viewBox: "0 0 24 24",
673
+ "aria-hidden": "true"
674
+ }, [
675
+ T("circle", {
676
+ class: "opacity-25",
677
+ cx: "12",
678
+ cy: "12",
679
+ r: "10",
680
+ fill: "none",
681
+ stroke: "currentColor",
682
+ "stroke-width": "4"
683
+ }),
684
+ T("path", {
685
+ class: "opacity-75",
686
+ fill: "currentColor",
687
+ d: "M4 12a8 8 0 0 1 8-8v4a4 4 0 0 0-4 4H4z"
688
+ })
689
+ ]),
690
+ T("span", null, "Loading…")
691
+ ], -1)
692
+ ]))) : U.value ? (k(), x("p", St, "Error: " + Ve(U.value), 1)) : (k(), x("div", {
693
+ key: 2,
694
+ class: "relative",
695
+ style: N({ height: nt.value + "px" })
1712
696
  }, [
1713
- (_(!0), U(Oe, null, Ae(m.value, (Y, te) => (_(), U("div", {
1714
- key: `${Y.page}-${Y.id}`,
1715
- class: "absolute top-0 left-0 w-full",
1716
- style: he({
1717
- top: pt(te),
1718
- height: yt()
697
+ (k(!0), x(Ye, null, De(pe.value, (t) => (k(), x("article", {
698
+ key: o.value[t].id,
699
+ "data-testid": "item-card",
700
+ 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)
1719
705
  })
1720
706
  }, [
1721
- X("div", ba, [
1722
- X("div", Ma, [
1723
- K(u.$slots, "default", {
1724
- item: Y,
1725
- remove: J(ue),
1726
- index: Y.originalIndex ?? te
1727
- }, () => [
1728
- ke(xe, {
1729
- item: Y,
1730
- remove: J(ue),
1731
- "header-height": g.value.header,
1732
- "footer-height": g.value.footer,
1733
- "in-swipe-mode": !0,
1734
- "is-active": te === J(ce),
1735
- "onPreload:success": $[0] || ($[0] = (A) => x("item:preload:success", A)),
1736
- "onPreload:error": $[1] || ($[1] = (A) => x("item:preload:error", A)),
1737
- onMouseEnter: $[2] || ($[2] = (A) => x("item:mouse-enter", A)),
1738
- onMouseLeave: $[3] || ($[3] = (A) => x("item:mouse-leave", A))
1739
- }, {
1740
- header: ve((A) => [
1741
- K(u.$slots, "item-header", fe({ ref_for: !0 }, A), void 0, !0)
1742
- ]),
1743
- footer: ve((A) => [
1744
- K(u.$slots, "item-footer", fe({ ref_for: !0 }, A), void 0, !0)
1745
- ]),
1746
- _: 2
1747
- }, 1032, ["item", "remove", "header-height", "footer-height", "is-active"])
1748
- ], !0)
1749
- ])
1750
- ])
707
+ E.value || I.value > 0 ? (k(), x("div", {
708
+ key: 0,
709
+ "data-testid": "item-header-container",
710
+ class: "w-full",
711
+ style: N(te.value)
712
+ }, [
713
+ ie(e.$slots, "itemHeader", {
714
+ item: o.value[t],
715
+ remove: () => Ae(o.value[t])
716
+ })
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", {
744
+ key: 1,
745
+ "data-testid": "item-footer-container",
746
+ class: "w-full",
747
+ style: N(ne.value)
748
+ }, [
749
+ ie(e.$slots, "itemFooter", {
750
+ item: o.value[t],
751
+ remove: () => Ae(o.value[t])
752
+ })
753
+ ], 4)) : oe("", !0)
754
+ ], 4))), 128)),
755
+ (k(!0), x(Ye, null, De(Y.value, (t) => (k(), x("article", {
756
+ key: t.id + ":leaving",
757
+ "data-testid": "item-card-leaving",
758
+ class: "pointer-events-none absolute overflow-hidden rounded-xl border border-slate-200/60 bg-white shadow-sm",
759
+ style: N({
760
+ 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)"
763
+ })
764
+ }, [
765
+ E.value || I.value > 0 ? (k(), x("div", {
766
+ key: 0,
767
+ "data-testid": "item-header-container",
768
+ class: "w-full",
769
+ style: N(te.value)
770
+ }, [
771
+ ie(e.$slots, "itemHeader", {
772
+ item: t.item,
773
+ remove: () => {
774
+ }
775
+ })
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", {
803
+ key: 1,
804
+ "data-testid": "item-footer-container",
805
+ class: "w-full",
806
+ style: N(ne.value)
807
+ }, [
808
+ ie(e.$slots, "itemFooter", {
809
+ item: t.item,
810
+ remove: () => {
811
+ }
812
+ })
813
+ ], 4)) : oe("", !0)
1751
814
  ], 4))), 128))
1752
- ], 4),
1753
- k.value && m.value.length > 0 ? (_(), U("div", Ta, [
1754
- K(u.$slots, "end-message", {}, () => [
1755
- $[9] || ($[9] = X("p", { class: "text-gray-500 dark:text-gray-400" }, "You've reached the end", -1))
1756
- ], !0)
1757
- ])) : ne("", !0),
1758
- H.value && m.value.length > 0 ? (_(), U("div", Pa, [
1759
- K(u.$slots, "error-message", { error: H.value }, () => [
1760
- X("p", Ia, "Failed to load content: " + He(H.value.message), 1)
1761
- ], !0)
1762
- ])) : ne("", !0)
1763
- ], 2)) : (_(), U("div", {
1764
- key: 2,
1765
- class: ie(["overflow-auto w-full flex-1 masonry-container", { "force-motion": a.forceMotion }]),
1766
- ref_key: "container",
1767
- ref: r
1768
- }, [
1769
- X("div", {
1770
- class: "relative",
1771
- style: he({ height: `${z.value}px`, "--masonry-duration": `${e.transitionDurationMs}ms`, "--masonry-leave-duration": `${e.leaveDurationMs}ms`, "--masonry-ease": e.transitionEasing })
1772
- }, [
1773
- ke(Lt, {
1774
- name: "masonry",
1775
- css: !1,
1776
- onEnter: J(at),
1777
- onBeforeEnter: J(nt),
1778
- onLeave: J(ot),
1779
- onBeforeLeave: J(lt)
1780
- }, {
1781
- default: ve(() => [
1782
- (_(!0), U(Oe, null, Ae(J(j), (Y, te) => (_(), U("div", fe({
1783
- key: `${Y.page}-${Y.id}`,
1784
- class: "absolute masonry-item",
1785
- ref_for: !0
1786
- }, J(aa)(Y, te)), [
1787
- K(u.$slots, "default", {
1788
- item: Y,
1789
- remove: J(ue),
1790
- index: Y.originalIndex ?? te
1791
- }, () => [
1792
- ke(xe, {
1793
- item: Y,
1794
- remove: J(ue),
1795
- "header-height": g.value.header,
1796
- "footer-height": g.value.footer,
1797
- "in-swipe-mode": !1,
1798
- "is-active": !1,
1799
- "onPreload:success": $[4] || ($[4] = (A) => x("item:preload:success", A)),
1800
- "onPreload:error": $[5] || ($[5] = (A) => x("item:preload:error", A)),
1801
- onMouseEnter: $[6] || ($[6] = (A) => x("item:mouse-enter", A)),
1802
- onMouseLeave: $[7] || ($[7] = (A) => x("item:mouse-leave", A))
1803
- }, {
1804
- header: ve((A) => [
1805
- K(u.$slots, "item-header", fe({ ref_for: !0 }, A), void 0, !0)
1806
- ]),
1807
- footer: ve((A) => [
1808
- K(u.$slots, "item-footer", fe({ ref_for: !0 }, A), void 0, !0)
1809
- ]),
1810
- _: 2
1811
- }, 1032, ["item", "remove", "header-height", "footer-height"])
1812
- ], !0)
1813
- ], 16))), 128))
1814
- ]),
1815
- _: 3
1816
- }, 8, ["onEnter", "onBeforeEnter", "onLeave", "onBeforeLeave"])
1817
- ], 4),
1818
- k.value && m.value.length > 0 ? (_(), U("div", La, [
1819
- K(u.$slots, "end-message", {}, () => [
1820
- $[10] || ($[10] = X("p", { class: "text-gray-500 dark:text-gray-400" }, "You've reached the end", -1))
1821
- ], !0)
1822
- ])) : ne("", !0),
1823
- H.value && m.value.length > 0 ? (_(), U("div", ka, [
1824
- K(u.$slots, "error-message", { error: H.value }, () => [
1825
- X("p", Sa, "Failed to load content: " + He(H.value.message), 1)
1826
- ], !0)
1827
- ])) : ne("", !0)
1828
- ], 2)) : (_(), U("div", xa, [
1829
- K(u.$slots, "loading-message", {}, () => [
1830
- $[8] || ($[8] = X("p", { class: "text-gray-500 dark:text-gray-400" }, "Waiting for content to load...", -1))
1831
- ], !0)
1832
- ]))
1833
- ], 512));
815
+ ], 4)),
816
+ T("div", Rt, [
817
+ J.value ? (k(), x("span", At, a[1] || (a[1] = [
818
+ T("svg", {
819
+ class: "h-4 w-4 animate-spin text-slate-500",
820
+ viewBox: "0 0 24 24",
821
+ "aria-hidden": "true"
822
+ }, [
823
+ T("circle", {
824
+ class: "opacity-25",
825
+ cx: "12",
826
+ cy: "12",
827
+ r: "10",
828
+ fill: "none",
829
+ stroke: "currentColor",
830
+ "stroke-width": "4"
831
+ }),
832
+ T("path", {
833
+ class: "opacity-75",
834
+ fill: "currentColor",
835
+ d: "M4 12a8 8 0 0 1 8-8v4a4 4 0 0 0-4 4H4z"
836
+ })
837
+ ], -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))
840
+ ])
841
+ ], 36)
842
+ ], 16));
1834
843
  }
1835
- }), Ha = (e, n) => {
1836
- const s = e.__vccOpts || e;
1837
- for (const [a, h] of n)
1838
- s[a] = h;
1839
- return s;
1840
- }, Xe = /* @__PURE__ */ Ha(Ea, [["__scopeId", "data-v-3ebb00d9"]]), Da = {
1841
- install(e) {
1842
- e.component("WyxosMasonry", Xe), e.component("WMasonry", Xe), e.component("WyxosMasonryItem", xe), e.component("WMasonryItem", xe);
844
+ }), Lt = {
845
+ install(n) {
846
+ n.component("Masonry", qt);
1843
847
  }
1844
848
  };
1845
849
  export {
1846
- Xe as Masonry,
1847
- xe as MasonryItem,
1848
- Da as default
850
+ qt as Masonry,
851
+ Lt as VibePlugin,
852
+ pt as masonryDefaults
1849
853
  };