@glhrmoura/vue-virtualize 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs ADDED
@@ -0,0 +1,974 @@
1
+ import { shallowRef as xe, ref as L, toValue as l, watch as me, onBeforeUnmount as ge, computed as b, defineComponent as ee, openBlock as R, createBlock as j, resolveDynamicComponent as q, normalizeStyle as V, withCtx as Y, renderSlot as A, createElementBlock as C, Fragment as H, renderList as P, unref as B, mergeProps as te, createElementVNode as oe, toDisplayString as le, createTextVNode as pe } from "vue";
2
+ function U(e) {
3
+ return !Number.isFinite(e) || e < 0 ? 0 : e;
4
+ }
5
+ class be {
6
+ sizes = /* @__PURE__ */ new Map();
7
+ divergent = !1;
8
+ get(t) {
9
+ return this.sizes.get(t);
10
+ }
11
+ set(t, i, n) {
12
+ this.sizes.set(t, i), n !== null && Math.abs(i - n) >= 0.5 && (this.divergent = !0);
13
+ }
14
+ get hasDivergent() {
15
+ return this.divergent;
16
+ }
17
+ clear() {
18
+ this.sizes.clear(), this.divergent = !1;
19
+ }
20
+ trim(t, i) {
21
+ let n = !1;
22
+ for (const r of this.sizes.keys())
23
+ r >= t && (this.sizes.delete(r), n = !0);
24
+ if (n && (this.divergent = !1, i !== null)) {
25
+ for (const r of this.sizes.values())
26
+ if (Math.abs(r - i) >= 0.5) {
27
+ this.divergent = !0;
28
+ return;
29
+ }
30
+ }
31
+ }
32
+ }
33
+ function ve(e, t, i) {
34
+ return Math.min(i, Math.max(t, e));
35
+ }
36
+ function Q(e, t, i) {
37
+ const n = Math.max(0, t - Math.max(0, i));
38
+ return ve(Number.isFinite(e) ? e : 0, 0, n);
39
+ }
40
+ function Ie(e, t, i) {
41
+ if (e <= 0) return 0;
42
+ let n = 0, r = e - 1, s = e - 1;
43
+ for (; n <= r; ) {
44
+ const f = n + r >>> 1;
45
+ i(f) > t ? (s = f, r = f - 1) : n = f + 1;
46
+ }
47
+ return s;
48
+ }
49
+ function Oe(e, t, i) {
50
+ if (e <= 0) return 0;
51
+ let n = 0, r = e - 1, s = 0;
52
+ for (; n <= r; ) {
53
+ const f = n + r >>> 1;
54
+ i(f) < t ? (s = f, n = f + 1) : r = f - 1;
55
+ }
56
+ return s;
57
+ }
58
+ function Re(e) {
59
+ const t = e.start + e.size;
60
+ let i = e.align;
61
+ if (i === "auto") {
62
+ const n = e.current + e.viewport;
63
+ if (e.start >= e.current && t <= n) return e.current;
64
+ i = e.start < e.current ? "start" : "end";
65
+ }
66
+ return i === "center" ? e.start - (e.viewport - e.size) / 2 : i === "end" ? t - e.viewport : e.start;
67
+ }
68
+ class Te {
69
+ count = 0;
70
+ estimateSize = () => 0;
71
+ overscan = 0;
72
+ gap = 0;
73
+ paddingStart = 0;
74
+ paddingEnd = 0;
75
+ lanes = 1;
76
+ itemSize = null;
77
+ viewportSize = 0;
78
+ scrollOffset = 0;
79
+ getItemKey = (t) => t;
80
+ measurements = new be();
81
+ built = 0;
82
+ offsets = [];
83
+ laneCursor = [];
84
+ laneEnd = [];
85
+ setOptions(t) {
86
+ const i = Math.max(1, Math.floor(t.lanes ?? 1)), n = t.gap ?? 0, r = t.paddingStart ?? 0, s = t.paddingEnd ?? 0, f = Math.max(0, Math.floor(t.count)), m = t.itemSize === void 0 || t.itemSize === null ? null : U(t.itemSize), y = this.itemSize, p = i !== this.lanes || n !== this.gap || r !== this.paddingStart || s !== this.paddingEnd || t.estimateSize !== this.estimateSize || m !== this.itemSize;
87
+ this.count = f, this.lanes = i, this.gap = n, this.paddingStart = r, this.paddingEnd = s, this.overscan = Math.max(0, Math.floor(t.overscan ?? 0)), this.estimateSize = t.estimateSize, this.itemSize = m, this.getItemKey = t.getItemKey ?? ((v) => v), t.viewportSize !== void 0 && (this.viewportSize = Math.max(0, t.viewportSize)), m !== y && this.measurements.clear(), this.measurements.trim(this.count, this.itemSize), (p || this.built > this.count) && this.resetGeometry();
88
+ }
89
+ setScrollOffset(t) {
90
+ this.scrollOffset = Number.isFinite(t) ? t : 0;
91
+ }
92
+ getScrollOffset() {
93
+ return this.scrollOffset;
94
+ }
95
+ getViewportSize() {
96
+ return this.viewportSize;
97
+ }
98
+ measure(t, i) {
99
+ if (t < 0 || t >= this.count) return !1;
100
+ const n = U(i), r = this.measurements.get(t);
101
+ if (r !== void 0 && Math.abs(r - n) < 0.5) return !1;
102
+ const s = this.getItemSize(t);
103
+ return this.measurements.set(t, n, this.itemSize), Math.abs(s - n) < 0.5 ? !1 : (this.resetGeometry(), !0);
104
+ }
105
+ clearMeasurements() {
106
+ this.measurements.clear(), this.resetGeometry();
107
+ }
108
+ getItemSize(t) {
109
+ const i = this.measurements.get(t);
110
+ return i !== void 0 ? i : this.itemSize !== null ? this.itemSize : U(this.estimateSize(t));
111
+ }
112
+ getItemOffset(t) {
113
+ if (t <= 0 || this.count <= 0) return this.paddingStart;
114
+ const i = Math.min(t, this.count - 1);
115
+ if (this.usesFixedPath()) {
116
+ const n = Math.floor(i / this.lanes);
117
+ return this.paddingStart + n * ((this.itemSize ?? 0) + this.gap);
118
+ }
119
+ return this.ensure(i), this.offsets[i] ?? this.paddingStart;
120
+ }
121
+ getTotalSize() {
122
+ if (this.count <= 0) return this.paddingStart + this.paddingEnd;
123
+ if (this.usesFixedPath()) {
124
+ let i = this.paddingStart;
125
+ const n = this.itemSize ?? 0;
126
+ for (let r = 0; r < this.lanes && r < this.count; r += 1) {
127
+ const s = this.laneLength(r), f = this.paddingStart + s * n + Math.max(0, s - 1) * this.gap;
128
+ f > i && (i = f);
129
+ }
130
+ return i + this.paddingEnd;
131
+ }
132
+ this.ensure(this.count - 1);
133
+ let t = this.paddingStart;
134
+ for (let i = 0; i < this.lanes && i < this.count; i += 1) {
135
+ const n = this.laneEnd[i] ?? this.paddingStart;
136
+ n > t && (t = n);
137
+ }
138
+ return t + this.paddingEnd;
139
+ }
140
+ getVirtualItems() {
141
+ if (this.count <= 0 || this.viewportSize <= 0) return [];
142
+ const t = Q(this.scrollOffset, this.getTotalSize(), this.viewportSize), i = t + this.viewportSize, n = [];
143
+ for (let r = 0; r < this.lanes; r += 1) {
144
+ const s = this.laneLength(r);
145
+ if (s <= 0) continue;
146
+ const f = Ie(s, t, (v) => {
147
+ const w = this.ordinalIndex(r, v);
148
+ return this.getItemOffset(w) + this.getItemSize(w);
149
+ }), m = Oe(
150
+ s,
151
+ i,
152
+ (v) => this.getItemOffset(this.ordinalIndex(r, v))
153
+ ), y = Math.max(0, Math.min(f, m) - this.overscan), p = Math.min(s - 1, Math.max(f, m) + this.overscan);
154
+ for (let v = y; v <= p; v += 1) {
155
+ const w = this.ordinalIndex(r, v), E = this.getItemOffset(w), k = this.getItemSize(w);
156
+ n.push({
157
+ index: w,
158
+ key: this.getItemKey(w),
159
+ start: E,
160
+ size: k,
161
+ end: E + k,
162
+ lane: r
163
+ });
164
+ }
165
+ }
166
+ return n.sort((r, s) => r.index - s.index), n;
167
+ }
168
+ getOffsetForIndex(t, i = "auto") {
169
+ if (this.count <= 0) return 0;
170
+ const n = ve(t, 0, this.count - 1), r = this.getItemOffset(n), s = this.getItemSize(n), f = Re({
171
+ start: r,
172
+ size: s,
173
+ viewport: this.viewportSize,
174
+ current: this.scrollOffset,
175
+ align: i
176
+ });
177
+ return Q(f, this.getTotalSize(), this.viewportSize);
178
+ }
179
+ usesFixedPath() {
180
+ return this.itemSize !== null && !this.measurements.hasDivergent;
181
+ }
182
+ ordinalIndex(t, i) {
183
+ return t + i * this.lanes;
184
+ }
185
+ laneLength(t) {
186
+ return t < 0 || t >= this.lanes || t >= this.count ? 0 : Math.floor((this.count - t - 1) / this.lanes) + 1;
187
+ }
188
+ ensure(t) {
189
+ if (t < this.built) return;
190
+ const i = Math.min(t, this.count - 1);
191
+ for (; this.built <= i; ) {
192
+ const n = this.built % this.lanes, r = this.laneCursor[n] ?? this.paddingStart;
193
+ this.offsets[this.built] = r;
194
+ const s = r + this.getItemSize(this.built);
195
+ this.laneEnd[n] = s, this.laneCursor[n] = s + this.gap, this.built += 1;
196
+ }
197
+ }
198
+ resetGeometry() {
199
+ this.built = 0, this.offsets = [], this.laneCursor = Array.from({ length: this.lanes }, () => this.paddingStart), this.laneEnd = Array.from({ length: this.lanes }, () => this.paddingStart);
200
+ }
201
+ }
202
+ function W() {
203
+ return typeof window < "u" && typeof document < "u";
204
+ }
205
+ function Se(e) {
206
+ return typeof Element > "u" ? null : e instanceof Element ? e : null;
207
+ }
208
+ function X(e, t, i, n) {
209
+ if (n === "smooth" && typeof e.scrollTo == "function") {
210
+ e.scrollTo({
211
+ top: i ? e.scrollTop : t,
212
+ left: i ? t : e.scrollLeft,
213
+ behavior: n
214
+ });
215
+ return;
216
+ }
217
+ i ? e.scrollLeft = t : e.scrollTop = t;
218
+ }
219
+ function J(e, t) {
220
+ return t ? e.scrollLeft : e.scrollTop;
221
+ }
222
+ function ue(e, t) {
223
+ return t ? e.clientWidth : e.clientHeight;
224
+ }
225
+ function ce(e) {
226
+ return typeof requestAnimationFrame == "function" ? requestAnimationFrame(e) : setTimeout(e, 0);
227
+ }
228
+ function fe(e) {
229
+ e && (typeof cancelAnimationFrame == "function" ? cancelAnimationFrame(e) : clearTimeout(e));
230
+ }
231
+ function Ee(e, t) {
232
+ if (e.length !== t.length) return !1;
233
+ for (let i = 0; i < e.length; i += 1) {
234
+ const n = e[i], r = t[i];
235
+ if (!n || !r || n.index !== r.index || n.start !== r.start || n.size !== r.size || n.end !== r.end || n.lane !== r.lane || n.key !== r.key)
236
+ return !1;
237
+ }
238
+ return !0;
239
+ }
240
+ function Z(e) {
241
+ const t = new Te(), i = xe([]), n = L(0), r = L(0), s = L(!1), f = (c) => e.estimateSize(c);
242
+ let m = null, y = null, p = null, v = 0, w = 0, E = 0, k = l(e.revision);
243
+ const o = /* @__PURE__ */ new Map(), u = /* @__PURE__ */ new Map(), a = [];
244
+ function d() {
245
+ const c = l(e.container);
246
+ return typeof HTMLElement > "u" ? null : c instanceof HTMLElement ? c : null;
247
+ }
248
+ function S() {
249
+ return l(e.horizontal) ?? !1;
250
+ }
251
+ function K() {
252
+ const c = l(e.initialRect);
253
+ return c ? S() ? c.width : c.height : 0;
254
+ }
255
+ function M() {
256
+ const c = l(e.revision);
257
+ Object.is(c, k) || (k = c, t.clearMeasurements());
258
+ const z = d(), x = z ? ue(z, S()) : 0, O = l(e.viewportInset) ?? 0, T = Math.max(0, (x > 0 ? x : K()) - O), F = l(e.itemSize);
259
+ t.setOptions({
260
+ count: l(e.count),
261
+ estimateSize: f,
262
+ overscan: l(e.overscan) ?? 5,
263
+ gap: l(e.gap) ?? 0,
264
+ paddingStart: l(e.paddingStart) ?? 0,
265
+ paddingEnd: l(e.paddingEnd) ?? 0,
266
+ lanes: l(e.lanes) ?? 1,
267
+ itemSize: F ?? null,
268
+ getItemKey: e.getItemKey,
269
+ viewportSize: T
270
+ });
271
+ const G = Math.max(0, t.getTotalSize() - T);
272
+ t.getScrollOffset() > G && (t.setScrollOffset(G), z && J(z, S()) !== G && X(z, G, S(), "auto"));
273
+ const re = t.getVirtualItems();
274
+ Ee(i.value, re) || (i.value = re);
275
+ const se = t.getTotalSize();
276
+ n.value !== se && (n.value = se);
277
+ const ae = t.getScrollOffset();
278
+ r.value !== ae && (r.value = ae);
279
+ }
280
+ function _() {
281
+ if (!W()) {
282
+ M();
283
+ return;
284
+ }
285
+ v || (v = ce(() => {
286
+ v = 0, s.value = !0, M(), typeof window < "u" && (window.clearTimeout(E), E = window.setTimeout(() => {
287
+ s.value = !1;
288
+ }, 150));
289
+ }));
290
+ }
291
+ function h() {
292
+ const c = d();
293
+ c && (t.setScrollOffset(J(c, S())), _());
294
+ }
295
+ function I() {
296
+ const c = d();
297
+ if (c === m || (m && (m.removeEventListener("scroll", h), y?.disconnect(), y = null), m = c, !c || !W())) return;
298
+ const z = S();
299
+ t.getScrollOffset() > 0 ? X(c, t.getScrollOffset(), z, "auto") : t.setScrollOffset(J(c, z)), c.addEventListener("scroll", h, { passive: !0 }), typeof ResizeObserver < "u" && (y = new ResizeObserver(() => M()), y.observe(c));
300
+ }
301
+ function g() {
302
+ return !W() || typeof ResizeObserver > "u" ? null : (p || (p = new ResizeObserver((c) => {
303
+ const z = S();
304
+ let x = !1;
305
+ for (const O of c) {
306
+ const T = o.get(O.target);
307
+ if (T === void 0) continue;
308
+ const F = O.borderBoxSize?.[0], G = z ? F?.inlineSize ?? O.contentRect.width : F?.blockSize ?? O.contentRect.height;
309
+ G > 0 && t.measure(T, G) && (x = !0);
310
+ }
311
+ x && M();
312
+ })), p);
313
+ }
314
+ function $() {
315
+ w = 0;
316
+ const c = a.splice(0, a.length), z = S();
317
+ let x = !1;
318
+ for (const O of c) {
319
+ if (!O.element.isConnected) continue;
320
+ const T = O.element.getBoundingClientRect(), F = z ? T.width : T.height;
321
+ F > 0 && t.measure(O.index, F) && (x = !0);
322
+ }
323
+ x && M();
324
+ }
325
+ function D(c, z) {
326
+ const x = Se(c), O = g(), T = u.get(z);
327
+ T && T !== x && (O?.unobserve(T), o.delete(T), u.delete(z)), x && (u.set(z, x), o.set(x, z), O?.observe(x), a.push({ element: x, index: z }), !w && (w = ce($)));
328
+ }
329
+ function ne(c, z = "auto") {
330
+ const x = d(), O = x ? ue(x, S()) : 0, T = O > 0 ? O : t.getViewportSize(), F = Q(c, t.getTotalSize(), T);
331
+ t.setScrollOffset(F), x && X(x, F, S(), z), M();
332
+ }
333
+ function ye(c, z) {
334
+ const x = t.getOffsetForIndex(c, z?.align ?? "auto");
335
+ ne(x, z?.behavior ?? "auto");
336
+ }
337
+ function we(c, z) {
338
+ t.measure(c, z) && M();
339
+ }
340
+ return M(), me(
341
+ () => [
342
+ l(e.count),
343
+ l(e.overscan),
344
+ l(e.gap),
345
+ l(e.paddingStart),
346
+ l(e.paddingEnd),
347
+ l(e.lanes),
348
+ l(e.horizontal),
349
+ l(e.itemSize),
350
+ l(e.viewportInset),
351
+ l(e.revision),
352
+ l(e.container),
353
+ l(e.initialRect)?.width,
354
+ l(e.initialRect)?.height
355
+ ],
356
+ () => {
357
+ I(), M();
358
+ },
359
+ { flush: "post" }
360
+ ), ge(() => {
361
+ m && m.removeEventListener("scroll", h), y?.disconnect(), p?.disconnect(), fe(v), fe(w), typeof window < "u" && window.clearTimeout(E), o.clear(), u.clear(), a.length = 0;
362
+ }), {
363
+ virtualItems: b(() => i.value),
364
+ totalSize: b(() => n.value),
365
+ scrollOffset: b(() => r.value),
366
+ isScrolling: b(() => s.value),
367
+ scrollToIndex: ye,
368
+ scrollToOffset: ne,
369
+ measure: we,
370
+ measureElement: D
371
+ };
372
+ }
373
+ function Me(e, t, i) {
374
+ return typeof e == "function" ? e(t, i) : typeof e == "number" ? e : 48;
375
+ }
376
+ function ze(e) {
377
+ const t = Z({
378
+ count: () => l(e.items).length,
379
+ estimateSize: (n) => {
380
+ const r = l(e.items);
381
+ return Me(e.estimateSize, n, r[n]);
382
+ },
383
+ getItemKey: (n) => {
384
+ const s = l(e.items)[n];
385
+ return e.getItemKey?.(s, n) ?? n;
386
+ },
387
+ itemSize: () => e.itemSize !== void 0 ? l(e.itemSize) : typeof e.estimateSize == "number" ? e.estimateSize : void 0,
388
+ container: e.container,
389
+ horizontal: e.horizontal,
390
+ overscan: e.overscan,
391
+ gap: e.gap,
392
+ paddingStart: e.paddingStart,
393
+ paddingEnd: e.paddingEnd,
394
+ initialRect: e.initialRect,
395
+ viewportInset: e.viewportInset,
396
+ revision: e.revision
397
+ });
398
+ return {
399
+ virtualItems: b(() => {
400
+ const n = l(e.items);
401
+ return t.virtualItems.value.map((r) => {
402
+ const s = n[r.index];
403
+ return {
404
+ ...r,
405
+ item: s,
406
+ key: e.getItemKey?.(s, r.index) ?? r.key
407
+ };
408
+ });
409
+ }),
410
+ totalSize: t.totalSize,
411
+ scrollOffset: t.scrollOffset,
412
+ isScrolling: t.isScrolling,
413
+ scrollToIndex: t.scrollToIndex,
414
+ scrollToOffset: t.scrollToOffset,
415
+ measure: t.measure,
416
+ measureElement: t.measureElement
417
+ };
418
+ }
419
+ function de(e, t, i) {
420
+ return typeof e == "function" ? e(t) : typeof e == "number" ? e : i;
421
+ }
422
+ function ke(e) {
423
+ const t = b(() => Math.max(1, Math.floor(l(e.columnCount) || 1))), i = b(() => Math.ceil(l(e.items).length / t.value)), n = /* @__PURE__ */ new Map(), r = Z({
424
+ count: () => i.value,
425
+ estimateSize: (o) => de(l(e.estimateRowSize), o, 48),
426
+ itemSize: () => {
427
+ const o = l(e.estimateRowSize);
428
+ return typeof o == "number" ? o : void 0;
429
+ },
430
+ overscan: () => l(e.overscanRows) ?? l(e.overscan) ?? 2,
431
+ gap: () => l(e.rowGap) ?? 0,
432
+ horizontal: !1,
433
+ container: e.container,
434
+ initialRect: e.initialRect,
435
+ revision: e.revision
436
+ }), s = Z({
437
+ count: () => t.value,
438
+ estimateSize: (o) => de(l(e.estimateColumnSize), o, 160),
439
+ itemSize: () => {
440
+ const o = l(e.estimateColumnSize);
441
+ return typeof o == "number" ? o : void 0;
442
+ },
443
+ overscan: () => l(e.overscanColumns) ?? l(e.overscan) ?? 1,
444
+ gap: () => l(e.columnGap) ?? 0,
445
+ horizontal: !0,
446
+ container: e.container,
447
+ initialRect: e.initialRect,
448
+ revision: e.revision
449
+ }), f = b(() => {
450
+ const o = l(e.items), u = t.value, a = [];
451
+ for (const d of r.virtualItems.value)
452
+ for (const S of s.virtualItems.value) {
453
+ const K = d.index * u + S.index;
454
+ if (K >= o.length) continue;
455
+ const M = o[K];
456
+ a.push({
457
+ index: K,
458
+ key: e.getItemKey?.(M, K) ?? K,
459
+ item: M,
460
+ row: d,
461
+ column: S
462
+ });
463
+ }
464
+ return a;
465
+ });
466
+ function m(o, u) {
467
+ const a = l(e.items);
468
+ if (!a.length) return;
469
+ const d = Math.min(Math.max(o, 0), a.length - 1), S = t.value;
470
+ r.scrollToIndex(Math.floor(d / S), u), s.scrollToIndex(d % S, u);
471
+ }
472
+ function y(o, u = "auto") {
473
+ o.top !== void 0 && r.scrollToOffset(o.top, u), o.left !== void 0 && s.scrollToOffset(o.left, u);
474
+ }
475
+ function p(o, u) {
476
+ const a = Math.max(n.get(o) ?? 0, u);
477
+ a <= 0 || a === n.get(o) || (n.set(o, a), r.measure(o, a));
478
+ }
479
+ let v = null;
480
+ const w = /* @__PURE__ */ new Map();
481
+ function E() {
482
+ return !W() || typeof ResizeObserver > "u" ? null : (v || (v = new ResizeObserver((o) => {
483
+ for (const u of o) {
484
+ const a = w.get(u.target);
485
+ if (a === void 0) continue;
486
+ const S = u.borderBoxSize?.[0]?.blockSize ?? u.contentRect.height;
487
+ S > 0 && p(a, S);
488
+ }
489
+ })), v);
490
+ }
491
+ function k(o, u) {
492
+ const a = Se(o), d = E();
493
+ if (!a) return;
494
+ w.set(a, u), d?.observe(a);
495
+ const S = a.getBoundingClientRect().height;
496
+ S > 0 && p(u, S);
497
+ }
498
+ return ge(() => {
499
+ v?.disconnect(), w.clear();
500
+ }), {
501
+ virtualRows: r.virtualItems,
502
+ virtualColumns: s.virtualItems,
503
+ virtualCells: f,
504
+ totalHeight: r.totalSize,
505
+ totalWidth: s.totalSize,
506
+ scrollToIndex: m,
507
+ scrollToOffset: y,
508
+ measureRow: p,
509
+ measureRowElement: k,
510
+ measureColumn: s.measure
511
+ };
512
+ }
513
+ function Ce(e) {
514
+ const t = ze({
515
+ items: e.rows,
516
+ estimateSize: e.estimateRowSize,
517
+ container: e.container,
518
+ overscan: e.overscan,
519
+ getItemKey: e.getRowKey,
520
+ initialRect: e.initialRect,
521
+ viewportInset: e.viewportInset,
522
+ revision: e.revision,
523
+ itemSize: e.itemSize
524
+ }), i = b(() => {
525
+ const s = l(e.columns);
526
+ let f = 0;
527
+ return s.map((m) => {
528
+ const y = m.width ?? m.minWidth ?? 160, p = {
529
+ ...m,
530
+ start: f,
531
+ size: y,
532
+ end: f + y
533
+ };
534
+ return f += y, p;
535
+ });
536
+ }), n = b(() => {
537
+ const s = i.value;
538
+ return s.length ? s[s.length - 1]?.end ?? 0 : 0;
539
+ });
540
+ return {
541
+ virtualRows: b(() => t.virtualItems.value),
542
+ columns: i,
543
+ totalHeight: t.totalSize,
544
+ totalWidth: n,
545
+ scrollOffset: t.scrollOffset,
546
+ isScrolling: t.isScrolling,
547
+ scrollToIndex: t.scrollToIndex,
548
+ scrollToOffset: t.scrollToOffset,
549
+ measure: t.measure,
550
+ measureElement: t.measureElement
551
+ };
552
+ }
553
+ function he(e) {
554
+ if (typeof e == "number" && Number.isFinite(e)) return `${e}px`;
555
+ if (typeof e == "string" && e.trim()) return e;
556
+ }
557
+ function N(e) {
558
+ if (typeof e == "number" && Number.isFinite(e)) return e;
559
+ if (typeof e != "string") return 0;
560
+ const t = /^(-?\d+(?:\.\d+)?)px$/.exec(e.trim());
561
+ if (!t?.[1]) return 0;
562
+ const i = Number(t[1]);
563
+ return Number.isFinite(i) ? i : 0;
564
+ }
565
+ function ie(e) {
566
+ return {
567
+ overflow: "auto",
568
+ position: "relative",
569
+ height: he(e.height) ?? (e.horizontal ? "100%" : void 0),
570
+ width: he(e.width) ?? (e.horizontal ? void 0 : "100%"),
571
+ overflowAnchor: "none"
572
+ };
573
+ }
574
+ function $e(e, t) {
575
+ return {
576
+ position: "relative",
577
+ width: t ? `${e}px` : "100%",
578
+ height: t ? "100%" : `${e}px`
579
+ };
580
+ }
581
+ function Fe(e, t) {
582
+ return {
583
+ position: "absolute",
584
+ top: 0,
585
+ left: 0,
586
+ width: t ? void 0 : "100%",
587
+ height: t ? "100%" : void 0,
588
+ transform: t ? `translateX(${e}px)` : `translateY(${e}px)`
589
+ };
590
+ }
591
+ const Ae = /* @__PURE__ */ ee({
592
+ __name: "VirtualList",
593
+ props: {
594
+ items: {},
595
+ estimateSize: { type: [Number, Function], default: 48 },
596
+ height: {},
597
+ width: {},
598
+ horizontal: { type: Boolean, default: !1 },
599
+ overscan: { default: 5 },
600
+ gap: { default: 0 },
601
+ paddingStart: { default: 0 },
602
+ paddingEnd: { default: 0 },
603
+ getItemKey: {},
604
+ tag: { default: "div" },
605
+ itemTag: { default: "div" },
606
+ itemAttrs: {},
607
+ revision: {}
608
+ },
609
+ setup(e, { expose: t }) {
610
+ const i = e, n = L(null), { virtualItems: r, totalSize: s, scrollToIndex: f, scrollToOffset: m, measure: y, measureElement: p } = ze({
611
+ items: () => i.items,
612
+ estimateSize: (o, u) => {
613
+ const a = i.estimateSize;
614
+ return typeof a == "number" ? a : a(o, u);
615
+ },
616
+ itemSize: () => typeof i.estimateSize == "number" ? i.estimateSize : void 0,
617
+ container: n,
618
+ horizontal: () => i.horizontal,
619
+ overscan: () => i.overscan,
620
+ gap: () => i.gap,
621
+ paddingStart: () => i.paddingStart,
622
+ paddingEnd: () => i.paddingEnd,
623
+ getItemKey: (o, u) => i.getItemKey?.(o, u) ?? u,
624
+ initialRect: () => ({
625
+ width: N(i.width),
626
+ height: N(i.height)
627
+ }),
628
+ revision: () => i.revision
629
+ }), v = b(
630
+ () => ie({
631
+ height: i.height,
632
+ width: i.width,
633
+ horizontal: i.horizontal
634
+ })
635
+ ), w = b(() => $e(s.value, i.horizontal));
636
+ function E(o) {
637
+ return Fe(o, i.horizontal);
638
+ }
639
+ function k(o) {
640
+ return (u) => {
641
+ p(u, o);
642
+ };
643
+ }
644
+ return t({
645
+ scrollToIndex: f,
646
+ scrollToOffset: m,
647
+ measure: y
648
+ }), (o, u) => (R(), j(q(e.tag), {
649
+ ref_key: "container",
650
+ ref: n,
651
+ "data-virtual-container": "",
652
+ role: "list",
653
+ style: V(v.value)
654
+ }, {
655
+ default: Y(() => [
656
+ e.items.length ? (R(), C("div", {
657
+ key: 1,
658
+ "data-virtual-spacer": "",
659
+ style: V(w.value)
660
+ }, [
661
+ (R(!0), C(H, null, P(B(r), (a) => (R(), j(q(e.itemTag), te({
662
+ key: a.key,
663
+ ref_for: !0,
664
+ ref: k(a.index),
665
+ role: "listitem",
666
+ "data-index": a.index,
667
+ "data-key": String(a.key),
668
+ "aria-setsize": e.items.length,
669
+ "aria-posinset": a.index + 1,
670
+ style: E(a.start)
671
+ }, { ref_for: !0 }, e.itemAttrs), {
672
+ default: Y(() => [
673
+ A(o.$slots, "default", {
674
+ item: a.item,
675
+ index: a.index,
676
+ start: a.start,
677
+ size: a.size,
678
+ end: a.end
679
+ })
680
+ ]),
681
+ _: 2
682
+ }, 1040, ["data-index", "data-key", "aria-setsize", "aria-posinset", "style"]))), 128))
683
+ ], 4)) : A(o.$slots, "empty", {}, void 0, void 0, 0)
684
+ ]),
685
+ _: 3
686
+ }, 8, ["style"]));
687
+ }
688
+ }), Ve = ["data-index", "data-key"], Be = /* @__PURE__ */ ee({
689
+ __name: "VirtualGrid",
690
+ props: {
691
+ items: {},
692
+ columnCount: { default: 1 },
693
+ estimateRowSize: { type: [Number, Function], default: 48 },
694
+ estimateColumnSize: { type: [Number, Function], default: 160 },
695
+ height: {},
696
+ width: {},
697
+ overscan: { default: 2 },
698
+ overscanRows: {},
699
+ overscanColumns: {},
700
+ rowGap: { default: 0 },
701
+ columnGap: { default: 0 },
702
+ getItemKey: {},
703
+ tag: { default: "div" },
704
+ itemAttrs: {},
705
+ revision: {}
706
+ },
707
+ setup(e, { expose: t }) {
708
+ const i = e, n = L(null), {
709
+ virtualCells: r,
710
+ totalWidth: s,
711
+ totalHeight: f,
712
+ scrollToIndex: m,
713
+ scrollToOffset: y,
714
+ measureRow: p,
715
+ measureRowElement: v
716
+ } = ke({
717
+ items: () => i.items,
718
+ columnCount: () => i.columnCount,
719
+ estimateRowSize: () => i.estimateRowSize,
720
+ estimateColumnSize: () => i.estimateColumnSize,
721
+ container: n,
722
+ overscan: () => i.overscan,
723
+ overscanRows: () => i.overscanRows,
724
+ overscanColumns: () => i.overscanColumns,
725
+ rowGap: () => i.rowGap,
726
+ columnGap: () => i.columnGap,
727
+ getItemKey: (u, a) => i.getItemKey?.(u, a) ?? a,
728
+ initialRect: () => ({
729
+ width: N(i.width),
730
+ height: N(i.height)
731
+ }),
732
+ revision: () => i.revision
733
+ }), w = b(
734
+ () => ie({
735
+ height: i.height,
736
+ width: i.width,
737
+ horizontal: !1
738
+ })
739
+ ), E = b(() => ({
740
+ position: "relative",
741
+ width: `${s.value}px`,
742
+ height: `${f.value}px`
743
+ }));
744
+ function k(u) {
745
+ return (a) => {
746
+ v(a, u);
747
+ };
748
+ }
749
+ function o(u, a, d) {
750
+ return {
751
+ position: "absolute",
752
+ top: 0,
753
+ left: 0,
754
+ width: `${a}px`,
755
+ transform: `translate(${u}px, ${d}px)`
756
+ };
757
+ }
758
+ return t({
759
+ scrollToIndex: m,
760
+ scrollToOffset: y,
761
+ measureRow: p
762
+ }), (u, a) => (R(), j(q(e.tag), {
763
+ ref_key: "container",
764
+ ref: n,
765
+ "data-virtual-container": "",
766
+ role: "grid",
767
+ style: V(w.value)
768
+ }, {
769
+ default: Y(() => [
770
+ e.items.length ? (R(), C("div", {
771
+ key: 1,
772
+ "data-virtual-spacer": "",
773
+ style: V(E.value)
774
+ }, [
775
+ (R(!0), C(H, null, P(B(r), (d) => (R(), C("div", te({
776
+ key: d.key,
777
+ ref_for: !0,
778
+ ref: k(d.row.index),
779
+ role: "gridcell",
780
+ "data-index": d.index,
781
+ "data-key": String(d.key),
782
+ style: o(d.column.start, d.column.size, d.row.start)
783
+ }, { ref_for: !0 }, e.itemAttrs), [
784
+ A(u.$slots, "default", {
785
+ item: d.item,
786
+ index: d.index,
787
+ rowIndex: d.row.index,
788
+ columnIndex: d.column.index,
789
+ row: d.row,
790
+ column: d.column
791
+ })
792
+ ], 16, Ve))), 128))
793
+ ], 4)) : A(u.$slots, "empty", {}, void 0, void 0, 0)
794
+ ]),
795
+ _: 3
796
+ }, 8, ["style"]));
797
+ }
798
+ }), Ke = ["data-index", "data-key", "aria-rowindex"], Ne = /* @__PURE__ */ ee({
799
+ __name: "VirtualTable",
800
+ props: {
801
+ rows: {},
802
+ columns: {},
803
+ estimateRowSize: { type: [Number, Function], default: 44 },
804
+ height: {},
805
+ width: {},
806
+ overscan: { default: 5 },
807
+ getRowKey: {},
808
+ stickyHeader: { type: Boolean, default: !0 },
809
+ tag: { default: "div" },
810
+ rowAttrs: {},
811
+ revision: {}
812
+ },
813
+ setup(e, { expose: t }) {
814
+ const i = e, n = L(null), r = L(null), s = L(0), {
815
+ virtualRows: f,
816
+ columns: m,
817
+ totalWidth: y,
818
+ totalHeight: p,
819
+ scrollToIndex: v,
820
+ scrollToOffset: w,
821
+ measure: E,
822
+ measureElement: k
823
+ } = Ce({
824
+ rows: () => i.rows,
825
+ columns: () => i.columns,
826
+ estimateRowSize: (h, I) => {
827
+ const g = i.estimateRowSize;
828
+ return typeof g == "number" ? g : g(h, I);
829
+ },
830
+ container: n,
831
+ overscan: () => i.overscan,
832
+ getRowKey: (h, I) => i.getRowKey?.(h, I) ?? I,
833
+ initialRect: () => ({
834
+ width: N(i.width),
835
+ height: N(i.height)
836
+ }),
837
+ viewportInset: s,
838
+ revision: () => i.revision,
839
+ itemSize: () => typeof i.estimateRowSize == "number" ? i.estimateRowSize : void 0
840
+ });
841
+ me(r, (h, I, g) => {
842
+ if (I === h && !h || !h || !W() || typeof ResizeObserver > "u") return;
843
+ const $ = () => {
844
+ s.value = h.getBoundingClientRect().height;
845
+ }, D = new ResizeObserver($);
846
+ D.observe(h), $(), g(() => D.disconnect());
847
+ });
848
+ const o = b(
849
+ () => ie({
850
+ height: i.height,
851
+ width: i.width,
852
+ horizontal: !1
853
+ })
854
+ ), u = b(() => ({
855
+ minWidth: `${y.value}px`
856
+ })), a = b(() => ({
857
+ position: i.stickyHeader ? "sticky" : "relative",
858
+ top: i.stickyHeader ? "0px" : void 0,
859
+ zIndex: 1,
860
+ display: "flex",
861
+ width: `${y.value}px`
862
+ })), d = b(() => ({
863
+ position: "relative",
864
+ height: `${p.value}px`,
865
+ width: `${y.value}px`
866
+ }));
867
+ function S(h) {
868
+ return {
869
+ width: `${h.size}px`,
870
+ minWidth: `${h.size}px`,
871
+ flex: "0 0 auto",
872
+ textAlign: h.align ?? "left"
873
+ };
874
+ }
875
+ function K(h) {
876
+ return {
877
+ position: "absolute",
878
+ top: 0,
879
+ left: 0,
880
+ width: "100%",
881
+ display: "flex",
882
+ transform: `translateY(${h}px)`
883
+ };
884
+ }
885
+ function M(h) {
886
+ return (I) => {
887
+ k(I, h);
888
+ };
889
+ }
890
+ function _(h, I, g) {
891
+ return I.accessor ? I.accessor(h, g) : h && typeof h == "object" && I.id in h ? h[I.id] : "";
892
+ }
893
+ return t({
894
+ scrollToIndex: v,
895
+ scrollToOffset: w,
896
+ measure: E
897
+ }), (h, I) => (R(), j(q(e.tag), {
898
+ ref_key: "container",
899
+ ref: n,
900
+ "data-virtual-container": "",
901
+ role: "table",
902
+ style: V(o.value)
903
+ }, {
904
+ default: Y(() => [
905
+ oe("div", {
906
+ style: V(u.value)
907
+ }, [
908
+ oe("div", {
909
+ ref_key: "header",
910
+ ref: r,
911
+ role: "row",
912
+ style: V(a.value)
913
+ }, [
914
+ A(h.$slots, "header", { columns: B(m) }, () => [
915
+ (R(!0), C(H, null, P(B(m), (g) => (R(), C("div", {
916
+ key: g.id,
917
+ role: "columnheader",
918
+ style: V(S(g))
919
+ }, le(g.header), 5))), 128))
920
+ ])
921
+ ], 4),
922
+ e.rows.length ? (R(), C("div", {
923
+ key: 1,
924
+ "data-virtual-spacer": "",
925
+ role: "rowgroup",
926
+ style: V(d.value)
927
+ }, [
928
+ (R(!0), C(H, null, P(B(f), (g) => (R(), C("div", te({
929
+ key: g.key,
930
+ ref_for: !0,
931
+ ref: M(g.index),
932
+ role: "row",
933
+ "data-index": g.index,
934
+ "data-key": String(g.key),
935
+ "aria-rowindex": g.index + 1,
936
+ style: K(g.start)
937
+ }, { ref_for: !0 }, e.rowAttrs), [
938
+ (R(!0), C(H, null, P(B(m), ($) => (R(), C("div", {
939
+ key: $.id,
940
+ role: "cell",
941
+ style: V(S($))
942
+ }, [
943
+ A(h.$slots, "cell", {
944
+ row: g.item,
945
+ column: $,
946
+ rowIndex: g.index,
947
+ value: _(g.item, $, g.index)
948
+ }, () => [
949
+ pe(le(_(g.item, $, g.index)), 1)
950
+ ])
951
+ ], 4))), 128))
952
+ ], 16, Ke))), 128))
953
+ ], 4)) : A(h.$slots, "empty", {}, void 0, void 0, 0)
954
+ ], 4)
955
+ ]),
956
+ _: 3
957
+ }, 8, ["style"]));
958
+ }
959
+ });
960
+ export {
961
+ be as MeasurementCache,
962
+ Be as VirtualGrid,
963
+ Ae as VirtualList,
964
+ Ne as VirtualTable,
965
+ Te as Virtualizer,
966
+ Q as clampScrollOffset,
967
+ U as normalizeSize,
968
+ Re as resolveScrollOffset,
969
+ ke as useVirtualGrid,
970
+ ze as useVirtualList,
971
+ Ce as useVirtualTable,
972
+ Z as useVirtualizer
973
+ };
974
+ //# sourceMappingURL=index.mjs.map