@pdanpdan/virtual-scroll 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/README.md +292 -0
- package/dist/index.css +1 -0
- package/dist/index.js +961 -0
- package/dist/index.js.map +1 -0
- package/package.json +59 -0
- package/src/components/VirtualScroll.test.ts +912 -0
- package/src/components/VirtualScroll.vue +748 -0
- package/src/composables/useVirtualScroll.test.ts +1214 -0
- package/src/composables/useVirtualScroll.ts +1407 -0
- package/src/index.ts +4 -0
- package/src/utils/fenwick-tree.test.ts +119 -0
- package/src/utils/fenwick-tree.ts +155 -0
- package/src/utils/scroll.ts +59 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,961 @@
|
|
|
1
|
+
import { ref as P, reactive as ot, computed as E, watch as ie, getCurrentInstance as ut, onMounted as it, nextTick as Ke, onUnmounted as nt, defineComponent as rt, createBlock as xe, openBlock as se, resolveDynamicComponent as Me, unref as ye, normalizeStyle as We, normalizeClass as $e, withCtx as Ce, createCommentVNode as Ae, createElementBlock as Ze, renderSlot as Ve, createElementVNode as ct, Fragment as st, renderList as dt, toDisplayString as Je } from "vue";
|
|
2
|
+
class Qe {
|
|
3
|
+
tree;
|
|
4
|
+
values;
|
|
5
|
+
constructor(a) {
|
|
6
|
+
this.tree = new Float64Array(a + 1), this.values = new Float64Array(a);
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Update the value at a specific index and propagate changes.
|
|
10
|
+
* @param index 0-based index
|
|
11
|
+
* @param delta The change in value (new value - old value)
|
|
12
|
+
*/
|
|
13
|
+
update(a, g) {
|
|
14
|
+
if (!(a < 0 || a >= this.values.length))
|
|
15
|
+
for (this.values[a] = this.values[a] + g, a++; a < this.tree.length; )
|
|
16
|
+
this.tree[a] = this.tree[a] + g, a += a & -a;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Get the prefix sum up to a specific index (exclusive).
|
|
20
|
+
* @param index 0-based index. query(n) returns sum of values from 0 to n-1.
|
|
21
|
+
* @returns Sum of values in range [0, index)
|
|
22
|
+
*/
|
|
23
|
+
query(a) {
|
|
24
|
+
let g = 0;
|
|
25
|
+
for (; a > 0; )
|
|
26
|
+
g += this.tree[a] || 0, a -= a & -a;
|
|
27
|
+
return g;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Set the individual value at an index without updating the tree.
|
|
31
|
+
* Call rebuild() after multiple sets to update the tree efficiently.
|
|
32
|
+
*/
|
|
33
|
+
set(a, g) {
|
|
34
|
+
a < 0 || a >= this.values.length || (this.values[a] = g);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Get the number of items in the tree.
|
|
38
|
+
*/
|
|
39
|
+
get length() {
|
|
40
|
+
return this.values.length;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Get the individual value at an index.
|
|
44
|
+
*/
|
|
45
|
+
get(a) {
|
|
46
|
+
return this.values[a] || 0;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Get the underlying values array.
|
|
50
|
+
*/
|
|
51
|
+
getValues() {
|
|
52
|
+
return this.values;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Find the largest index such that the prefix sum is less than or equal to the given value.
|
|
56
|
+
* Useful for finding which item is at a specific scroll offset.
|
|
57
|
+
* @param value The prefix sum value to search for
|
|
58
|
+
* @returns The 0-based index
|
|
59
|
+
*/
|
|
60
|
+
findLowerBound(a) {
|
|
61
|
+
let g = 0;
|
|
62
|
+
const n = this.tree.length;
|
|
63
|
+
let W = 1 << Math.floor(Math.log2(n - 1));
|
|
64
|
+
for (; W > 0; ) {
|
|
65
|
+
const Z = g + W;
|
|
66
|
+
if (Z < n) {
|
|
67
|
+
const U = this.tree[Z] || 0;
|
|
68
|
+
U <= a && (g = Z, a -= U);
|
|
69
|
+
}
|
|
70
|
+
W >>= 1;
|
|
71
|
+
}
|
|
72
|
+
return g;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Rebuild the entire tree from the current values array in O(N).
|
|
76
|
+
* Useful after bulk updates to the values array.
|
|
77
|
+
*/
|
|
78
|
+
rebuild() {
|
|
79
|
+
this.tree.fill(0);
|
|
80
|
+
for (let a = 0; a < this.values.length; a++)
|
|
81
|
+
this.tree[a + 1] = this.values[a] || 0;
|
|
82
|
+
for (let a = 1; a < this.tree.length; a++) {
|
|
83
|
+
const g = a + (a & -a);
|
|
84
|
+
g < this.tree.length && (this.tree[g] = this.tree[g] + this.tree[a]);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Resize the tree while preserving existing values.
|
|
89
|
+
* @param size New size of the tree
|
|
90
|
+
*/
|
|
91
|
+
resize(a) {
|
|
92
|
+
if (a === this.values.length)
|
|
93
|
+
return;
|
|
94
|
+
const g = new Float64Array(a);
|
|
95
|
+
g.set(this.values.subarray(0, Math.min(a, this.values.length))), this.values = g, this.tree = new Float64Array(a + 1), this.rebuild();
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Shift values by a given offset and rebuild the tree.
|
|
99
|
+
* Useful when items are prepended to the list.
|
|
100
|
+
* @param offset Number of positions to shift (positive for prepending)
|
|
101
|
+
*/
|
|
102
|
+
shift(a) {
|
|
103
|
+
if (a === 0)
|
|
104
|
+
return;
|
|
105
|
+
const g = this.values.length, n = new Float64Array(g);
|
|
106
|
+
a > 0 ? n.set(this.values.subarray(0, Math.min(g - a, this.values.length)), a) : n.set(this.values.subarray(-a)), this.values = n, this.rebuild();
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
function pe(e) {
|
|
110
|
+
return !!e && "getBoundingClientRect" in e;
|
|
111
|
+
}
|
|
112
|
+
function _e(e) {
|
|
113
|
+
return !!e && "scrollLeft" in e;
|
|
114
|
+
}
|
|
115
|
+
function et(e) {
|
|
116
|
+
return typeof e == "object" && e !== null && ("align" in e || "behavior" in e || "isCorrection" in e);
|
|
117
|
+
}
|
|
118
|
+
function we(e, a) {
|
|
119
|
+
return typeof e == "object" && e !== null ? e.x || 0 : a === "horizontal" && e || 0;
|
|
120
|
+
}
|
|
121
|
+
function Se(e, a) {
|
|
122
|
+
return typeof e == "object" && e !== null ? e.y || 0 : (a === "vertical" || a === "both") && e || 0;
|
|
123
|
+
}
|
|
124
|
+
const vt = 50, tt = 150, lt = 5;
|
|
125
|
+
function ft(e) {
|
|
126
|
+
const a = P(0), g = P(0), n = P(!1), W = P(!1), Z = P(!1), U = P(!1), j = P(0), te = P(0), N = ot({ x: 0, y: 0 });
|
|
127
|
+
let ne;
|
|
128
|
+
const ce = P(!1), R = new Qe(e.value.items.length), x = new Qe(e.value.items.length), T = new Qe(e.value.columnCount || 0), L = P(0);
|
|
129
|
+
let ae = new Uint8Array(0), J = new Uint8Array(0), A = new Uint8Array(0);
|
|
130
|
+
const Q = P(null), de = P(0), ve = P(0), be = P(!1);
|
|
131
|
+
let _ = [];
|
|
132
|
+
const Ee = E(
|
|
133
|
+
() => e.value.itemSize === void 0 || e.value.itemSize === null || e.value.itemSize === 0
|
|
134
|
+
), Pe = E(
|
|
135
|
+
() => e.value.columnWidth === void 0 || e.value.columnWidth === null || e.value.columnWidth === 0
|
|
136
|
+
), D = E(
|
|
137
|
+
() => typeof e.value.itemSize == "number" && e.value.itemSize > 0 ? e.value.itemSize : null
|
|
138
|
+
), fe = E(() => D.value || e.value.defaultItemSize || vt), ze = E(
|
|
139
|
+
() => [...e.value.stickyIndices || []].sort((l, t) => l - t)
|
|
140
|
+
), p = E(() => {
|
|
141
|
+
if (L.value, !W.value && e.value.ssrRange && !U.value) {
|
|
142
|
+
const { start: l = 0, end: t = 0, colStart: u = 0, colEnd: o = 0 } = e.value.ssrRange, s = e.value.columnCount || 0;
|
|
143
|
+
if (e.value.direction === "both" && s > 0)
|
|
144
|
+
return T.query(o || s) - T.query(u);
|
|
145
|
+
if (e.value.direction === "horizontal")
|
|
146
|
+
return D.value !== null ? (t - l) * (D.value + (e.value.columnGap || 0)) : R.query(t) - R.query(l);
|
|
147
|
+
}
|
|
148
|
+
return e.value.direction === "both" && e.value.columnCount ? T.query(e.value.columnCount) : e.value.direction === "vertical" ? 0 : D.value !== null ? e.value.items.length * (D.value + (e.value.columnGap || 0)) : R.query(e.value.items.length);
|
|
149
|
+
}), oe = E(() => {
|
|
150
|
+
if (L.value, !W.value && e.value.ssrRange && !U.value) {
|
|
151
|
+
const { start: l, end: t } = e.value.ssrRange;
|
|
152
|
+
if (e.value.direction === "vertical" || e.value.direction === "both")
|
|
153
|
+
return D.value !== null ? (t - l) * (D.value + (e.value.gap || 0)) : x.query(t) - x.query(l);
|
|
154
|
+
}
|
|
155
|
+
return e.value.direction === "horizontal" ? 0 : D.value !== null ? e.value.items.length * (D.value + (e.value.gap || 0)) : x.query(e.value.items.length);
|
|
156
|
+
}), M = E(() => {
|
|
157
|
+
const t = e.value.direction === "horizontal" || e.value.direction === "both" ? we(e.value.scrollPaddingStart, e.value.direction) : 0;
|
|
158
|
+
return Math.max(0, a.value + t - N.x);
|
|
159
|
+
}), B = E(() => {
|
|
160
|
+
const t = e.value.direction === "vertical" || e.value.direction === "both" ? Se(e.value.scrollPaddingStart, e.value.direction) : 0;
|
|
161
|
+
return Math.max(0, g.value + t - N.y);
|
|
162
|
+
}), He = (l) => {
|
|
163
|
+
L.value;
|
|
164
|
+
const t = e.value.columnWidth;
|
|
165
|
+
return typeof t == "number" && t > 0 ? t : Array.isArray(t) && t.length > 0 ? t[l % t.length] || tt : typeof t == "function" ? t(l) : T.get(l) || e.value.defaultColumnWidth || tt;
|
|
166
|
+
}, ke = (l, t, u) => {
|
|
167
|
+
const o = typeof u == "object" && u !== null && "isCorrection" in u ? u.isCorrection : !1;
|
|
168
|
+
o || (Q.value = { rowIndex: l, colIndex: t, options: u });
|
|
169
|
+
const s = e.value.container || window, m = D.value, S = e.value.gap || 0, d = e.value.columnGap || 0;
|
|
170
|
+
let v, f;
|
|
171
|
+
et(u) ? (v = u.align, f = u.behavior) : v = u;
|
|
172
|
+
const y = (typeof v == "object" ? v.x : v) || "auto", b = (typeof v == "object" ? v.y : v) || "auto", w = we(e.value.scrollPaddingStart, e.value.direction), h = we(e.value.scrollPaddingEnd, e.value.direction), z = Se(e.value.scrollPaddingStart, e.value.direction), q = Se(e.value.scrollPaddingEnd, e.value.direction), X = e.value.direction === "vertical" || e.value.direction === "both", k = e.value.direction === "horizontal" || e.value.direction === "both", K = j.value - (k ? w + h : 0), ge = te.value - (X ? z + q : 0);
|
|
173
|
+
let O = M.value, I = B.value, le = 0, ue = 0;
|
|
174
|
+
if (l != null && (l >= e.value.items.length ? (I = oe.value, ue = 0) : (I = m !== null ? l * (m + S) : x.query(l), ue = m !== null ? m : x.get(l) - S), b === "start" || (b === "center" ? I -= (ge - ue) / 2 : b === "end" ? I -= ge - ue : I >= B.value && I + ue <= B.value + ge || I < B.value || (I -= ge - ue))), t != null) {
|
|
175
|
+
const V = e.value.columnCount || 0;
|
|
176
|
+
t >= V && V > 0 ? (O = p.value, le = 0) : e.value.direction === "horizontal" ? (O = m !== null ? t * (m + d) : R.query(t), le = m !== null ? m : R.get(t) - d) : (O = T.query(t), le = T.get(t)), y === "start" || (y === "center" ? O -= (K - le) / 2 : y === "end" ? O -= K - le : O >= M.value && O + le <= M.value + K || O < M.value || (O -= K - le));
|
|
177
|
+
}
|
|
178
|
+
O = Math.max(0, Math.min(O, Math.max(0, p.value - K))), I = Math.max(0, Math.min(I, Math.max(0, oe.value - ge)));
|
|
179
|
+
const F = O + N.x - (k ? w : 0), ee = I + N.y - (X ? z : 0), Y = 1;
|
|
180
|
+
let $ = t == null || Math.abs(M.value - O) < Y, re = l == null || Math.abs(B.value - I) < Y;
|
|
181
|
+
if (!$ || !re) {
|
|
182
|
+
let V = 0, Te = 0, Le = 0, De = 0, Ge = 0, Ie = 0;
|
|
183
|
+
if (typeof window < "u") {
|
|
184
|
+
if (s === window ? (V = window.scrollX, Te = window.scrollY, Le = document.documentElement.scrollWidth, De = document.documentElement.scrollHeight, Ge = window.innerWidth, Ie = window.innerHeight) : pe(s) && (V = s.scrollLeft, Te = s.scrollTop, Le = s.scrollWidth, De = s.scrollHeight, Ge = s.clientWidth, Ie = s.clientHeight), !$ && t !== null && t !== void 0) {
|
|
185
|
+
const je = V <= Y && F <= Y, Ne = V >= Le - Ge - Y && F >= Le - Ge - Y;
|
|
186
|
+
(je || Ne) && ($ = !0);
|
|
187
|
+
}
|
|
188
|
+
if (!re && l !== null && l !== void 0) {
|
|
189
|
+
const je = Te <= Y && ee <= Y, Ne = Te >= De - Ie - Y && ee >= De - Ie - Y;
|
|
190
|
+
(je || Ne) && (re = !0);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
const Oe = o ? "auto" : f || "smooth";
|
|
195
|
+
if (ce.value = !0, typeof window < "u" && s === window)
|
|
196
|
+
window.scrollTo({
|
|
197
|
+
left: t == null ? void 0 : Math.max(0, F),
|
|
198
|
+
top: l == null ? void 0 : Math.max(0, ee),
|
|
199
|
+
behavior: Oe
|
|
200
|
+
});
|
|
201
|
+
else if (_e(s)) {
|
|
202
|
+
const V = {
|
|
203
|
+
behavior: Oe
|
|
204
|
+
};
|
|
205
|
+
t != null && (V.left = Math.max(0, F)), l != null && (V.top = Math.max(0, ee)), typeof s.scrollTo == "function" ? s.scrollTo(V) : (V.left !== void 0 && (s.scrollLeft = V.left), V.top !== void 0 && (s.scrollTop = V.top));
|
|
206
|
+
}
|
|
207
|
+
(Oe === "auto" || Oe === void 0) && (t != null && (a.value = Math.max(0, F)), l != null && (g.value = Math.max(0, ee))), $ && re && !n.value && (Q.value = null);
|
|
208
|
+
}, Xe = (l, t, u) => {
|
|
209
|
+
const o = e.value.container || window;
|
|
210
|
+
ce.value = !0;
|
|
211
|
+
const s = e.value.direction === "vertical" || e.value.direction === "both", m = e.value.direction === "horizontal" || e.value.direction === "both", S = we(e.value.scrollPaddingStart, e.value.direction), d = Se(e.value.scrollPaddingStart, e.value.direction), v = typeof window < "u" && o === window ? window.scrollX : o.scrollLeft, f = typeof window < "u" && o === window ? window.scrollY : o.scrollTop, y = l != null ? l + N.x - (m ? S : 0) : v, b = t != null ? t + N.y - (s ? d : 0) : f;
|
|
212
|
+
if (typeof window < "u" && o === window)
|
|
213
|
+
window.scrollTo({
|
|
214
|
+
left: l != null ? y : void 0,
|
|
215
|
+
top: t != null ? b : void 0,
|
|
216
|
+
behavior: u?.behavior || "auto"
|
|
217
|
+
});
|
|
218
|
+
else if (_e(o)) {
|
|
219
|
+
const w = {
|
|
220
|
+
behavior: u?.behavior || "auto"
|
|
221
|
+
};
|
|
222
|
+
l != null && (w.left = y), t != null && (w.top = b), typeof o.scrollTo == "function" ? o.scrollTo(w) : (w.left !== void 0 && (o.scrollLeft = w.left), w.top !== void 0 && (o.scrollTop = w.top));
|
|
223
|
+
}
|
|
224
|
+
(u?.behavior === "auto" || u?.behavior === void 0) && (l != null && (a.value = y), t != null && (g.value = b));
|
|
225
|
+
}, Ye = () => {
|
|
226
|
+
const l = e.value.items, t = l.length, u = e.value.columnCount || 0;
|
|
227
|
+
if (R.resize(t), x.resize(t), T.resize(u), J.length !== t) {
|
|
228
|
+
const d = new Uint8Array(t);
|
|
229
|
+
d.set(J.subarray(0, Math.min(t, J.length))), J = d;
|
|
230
|
+
}
|
|
231
|
+
if (A.length !== t) {
|
|
232
|
+
const d = new Uint8Array(t);
|
|
233
|
+
d.set(A.subarray(0, Math.min(t, A.length))), A = d;
|
|
234
|
+
}
|
|
235
|
+
if (ae.length !== u) {
|
|
236
|
+
const d = new Uint8Array(u);
|
|
237
|
+
d.set(ae.subarray(0, Math.min(u, ae.length))), ae = d;
|
|
238
|
+
}
|
|
239
|
+
let o = 0;
|
|
240
|
+
if (e.value.restoreScrollOnPrepend && _.length > 0 && t > _.length) {
|
|
241
|
+
const d = _[0];
|
|
242
|
+
if (d !== void 0) {
|
|
243
|
+
for (let v = 1; v <= t - _.length; v++)
|
|
244
|
+
if (l[v] === d) {
|
|
245
|
+
o = v;
|
|
246
|
+
break;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
if (o > 0) {
|
|
251
|
+
R.shift(o), x.shift(o), Q.value && Q.value.rowIndex !== null && Q.value.rowIndex !== void 0 && (Q.value.rowIndex += o);
|
|
252
|
+
const d = new Uint8Array(t), v = new Uint8Array(t);
|
|
253
|
+
d.set(J.subarray(0, Math.min(t - o, J.length)), o), v.set(A.subarray(0, Math.min(t - o, A.length)), o), J = d, A = v;
|
|
254
|
+
const f = e.value.gap || 0, y = e.value.columnGap || 0;
|
|
255
|
+
let b = 0, w = 0;
|
|
256
|
+
for (let h = 0; h < o; h++) {
|
|
257
|
+
const z = typeof e.value.itemSize == "function" ? e.value.itemSize(l[h], h) : fe.value;
|
|
258
|
+
e.value.direction === "horizontal" ? b += z + y : w += z + f;
|
|
259
|
+
}
|
|
260
|
+
(b > 0 || w > 0) && Ke(() => {
|
|
261
|
+
Xe(
|
|
262
|
+
b > 0 ? M.value + b : null,
|
|
263
|
+
w > 0 ? B.value + w : null,
|
|
264
|
+
{ behavior: "auto" }
|
|
265
|
+
);
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
if (u > 0) {
|
|
269
|
+
const d = e.value.columnGap || 0;
|
|
270
|
+
let v = !1;
|
|
271
|
+
for (let f = 0; f < u; f++) {
|
|
272
|
+
const y = He(f), b = T.get(f);
|
|
273
|
+
if (!Pe.value || b === 0) {
|
|
274
|
+
const w = y + d;
|
|
275
|
+
Math.abs(b - w) > 0.5 && (T.set(f, w), v = !0);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
v && T.rebuild();
|
|
279
|
+
}
|
|
280
|
+
const s = e.value.gap || 0, m = e.value.columnGap || 0;
|
|
281
|
+
let S = !1;
|
|
282
|
+
for (let d = 0; d < t; d++) {
|
|
283
|
+
const v = e.value.items[d], f = R.get(d), y = x.get(d);
|
|
284
|
+
if (Ee.value && (f > 0 || y > 0))
|
|
285
|
+
continue;
|
|
286
|
+
const b = typeof e.value.itemSize == "function" ? e.value.itemSize(v, d) : fe.value, w = e.value.direction === "vertical", h = e.value.direction === "horizontal", z = e.value.direction === "both", q = h ? b + m : 0, X = w || z ? b + s : 0;
|
|
287
|
+
Math.abs(f - q) > 0.5 && (R.set(d, q), S = !0), Math.abs(y - X) > 0.5 && (x.set(d, X), S = !0);
|
|
288
|
+
const k = h ? b : z ? Math.max(b, j.value) : 0, K = w || z ? b : 0;
|
|
289
|
+
k > de.value && (de.value = k), K > ve.value && (ve.value = K);
|
|
290
|
+
}
|
|
291
|
+
S && (R.rebuild(), x.rebuild()), _ = [...l], be.value = !0, L.value++;
|
|
292
|
+
}, he = () => {
|
|
293
|
+
if (e.value.hostElement && typeof window < "u") {
|
|
294
|
+
const l = e.value.hostElement.getBoundingClientRect(), t = e.value.container || window;
|
|
295
|
+
let u = 0, o = 0;
|
|
296
|
+
if (t === window)
|
|
297
|
+
u = l.left + window.scrollX, o = l.top + window.scrollY;
|
|
298
|
+
else if (t === e.value.hostElement)
|
|
299
|
+
u = 0, o = 0;
|
|
300
|
+
else if (pe(t)) {
|
|
301
|
+
const s = t.getBoundingClientRect();
|
|
302
|
+
u = l.left - s.left + t.scrollLeft, o = l.top - s.top + t.scrollTop;
|
|
303
|
+
}
|
|
304
|
+
(Math.abs(N.x - u) > 0.1 || Math.abs(N.y - o) > 0.1) && (N.x = u, N.y = o);
|
|
305
|
+
}
|
|
306
|
+
};
|
|
307
|
+
ie([
|
|
308
|
+
() => e.value.items.length,
|
|
309
|
+
() => e.value.columnCount,
|
|
310
|
+
() => e.value.columnWidth,
|
|
311
|
+
() => e.value.itemSize,
|
|
312
|
+
() => e.value.gap,
|
|
313
|
+
() => e.value.columnGap
|
|
314
|
+
], Ye, { immediate: !0 }), ie(() => [e.value.container, e.value.hostElement], () => {
|
|
315
|
+
he();
|
|
316
|
+
});
|
|
317
|
+
const Be = E(() => {
|
|
318
|
+
if (L.value, (!W.value || Z.value) && e.value.ssrRange)
|
|
319
|
+
return {
|
|
320
|
+
start: e.value.ssrRange.start,
|
|
321
|
+
end: e.value.ssrRange.end
|
|
322
|
+
};
|
|
323
|
+
const l = e.value.direction || "vertical", t = e.value.ssrRange && !n.value ? 0 : e.value.bufferBefore ?? lt, u = e.value.bufferAfter ?? lt, o = e.value.gap || 0, s = e.value.columnGap || 0, m = D.value, S = we(e.value.scrollPaddingStart, l), d = we(e.value.scrollPaddingEnd, l), v = Se(e.value.scrollPaddingStart, l), f = Se(e.value.scrollPaddingEnd, l), y = l === "vertical" || l === "both", b = l === "horizontal" || l === "both", w = j.value - (b ? S + d : 0), h = te.value - (y ? v + f : 0);
|
|
324
|
+
let z = 0, q = e.value.items.length;
|
|
325
|
+
if (y)
|
|
326
|
+
if (m !== null)
|
|
327
|
+
z = Math.floor(B.value / (m + o)), q = Math.ceil((B.value + h) / (m + o));
|
|
328
|
+
else {
|
|
329
|
+
z = x.findLowerBound(B.value);
|
|
330
|
+
let X = x.query(z), k = z;
|
|
331
|
+
for (; k < e.value.items.length && X < B.value + h; )
|
|
332
|
+
X = x.query(++k);
|
|
333
|
+
q = k;
|
|
334
|
+
}
|
|
335
|
+
else if (m !== null)
|
|
336
|
+
z = Math.floor(M.value / (m + s)), q = Math.ceil((M.value + w) / (m + s));
|
|
337
|
+
else {
|
|
338
|
+
z = R.findLowerBound(M.value);
|
|
339
|
+
let X = R.query(z), k = z;
|
|
340
|
+
for (; k < e.value.items.length && X < M.value + w; )
|
|
341
|
+
X = R.query(++k);
|
|
342
|
+
q = k;
|
|
343
|
+
}
|
|
344
|
+
return {
|
|
345
|
+
start: Math.max(0, z - t),
|
|
346
|
+
end: Math.min(e.value.items.length, q + u)
|
|
347
|
+
};
|
|
348
|
+
}), qe = E(() => {
|
|
349
|
+
L.value;
|
|
350
|
+
const l = D.value, t = e.value.gap || 0, u = e.value.columnGap || 0;
|
|
351
|
+
return e.value.direction === "horizontal" ? l !== null ? Math.floor(M.value / (l + u)) : R.findLowerBound(M.value) : l !== null ? Math.floor(B.value / (l + t)) : x.findLowerBound(B.value);
|
|
352
|
+
}), i = E(() => {
|
|
353
|
+
L.value;
|
|
354
|
+
const { start: l, end: t } = Be.value, u = [], o = D.value, s = e.value.gap || 0, m = e.value.columnGap || 0, S = ze.value, d = /* @__PURE__ */ new Set();
|
|
355
|
+
for (let h = l; h < t; h++)
|
|
356
|
+
d.add(h);
|
|
357
|
+
if (W.value || !e.value.ssrRange) {
|
|
358
|
+
const h = qe.value;
|
|
359
|
+
let z, q = 0, X = S.length - 1;
|
|
360
|
+
for (; q <= X; ) {
|
|
361
|
+
const k = q + X >>> 1;
|
|
362
|
+
S[k] < h ? (z = S[k], q = k + 1) : X = k - 1;
|
|
363
|
+
}
|
|
364
|
+
z !== void 0 && d.add(z);
|
|
365
|
+
for (const k of S)
|
|
366
|
+
k >= l && k < t && d.add(k);
|
|
367
|
+
}
|
|
368
|
+
const v = Array.from(d).sort((h, z) => h - z), f = e.value.ssrRange?.start || 0, y = e.value.ssrRange?.colStart || 0;
|
|
369
|
+
let b = 0, w = 0;
|
|
370
|
+
!W.value && e.value.ssrRange && (w = e.value.direction === "vertical" || e.value.direction === "both" ? o !== null ? f * (o + s) : x.query(f) : 0, e.value.direction === "horizontal" ? b = o !== null ? y * (o + m) : R.query(y) : e.value.direction === "both" && (b = T.query(y)));
|
|
371
|
+
for (const h of v) {
|
|
372
|
+
const z = e.value.items[h];
|
|
373
|
+
if (z === void 0)
|
|
374
|
+
continue;
|
|
375
|
+
let q = 0, X = 0, k = 0, K = 0;
|
|
376
|
+
e.value.direction === "horizontal" ? (q = o !== null ? h * (o + m) : R.query(h), k = o !== null ? o : R.get(h) - m, K = te.value) : (X = (e.value.direction === "vertical" || e.value.direction === "both") && o !== null ? h * (o + s) : x.query(h), K = o !== null ? o : x.get(h) - s, k = e.value.direction === "both" ? p.value : j.value);
|
|
377
|
+
const ge = S.includes(h), O = q, I = X;
|
|
378
|
+
let le = !1;
|
|
379
|
+
const ue = { x: 0, y: 0 };
|
|
380
|
+
if (ge) {
|
|
381
|
+
if (e.value.direction === "vertical" || e.value.direction === "both") {
|
|
382
|
+
if (B.value > I) {
|
|
383
|
+
le = !0;
|
|
384
|
+
let F, ee = 0, Y = S.length - 1;
|
|
385
|
+
for (; ee <= Y; ) {
|
|
386
|
+
const $ = ee + Y >>> 1;
|
|
387
|
+
S[$] > h ? (F = S[$], Y = $ - 1) : ee = $ + 1;
|
|
388
|
+
}
|
|
389
|
+
if (F !== void 0) {
|
|
390
|
+
const re = (o !== null ? F * (o + s) : x.query(F)) - B.value;
|
|
391
|
+
re < K && (ue.y = -(K - re));
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
} else if (e.value.direction === "horizontal" && M.value > O) {
|
|
395
|
+
le = !0;
|
|
396
|
+
let F, ee = 0, Y = S.length - 1;
|
|
397
|
+
for (; ee <= Y; ) {
|
|
398
|
+
const $ = ee + Y >>> 1;
|
|
399
|
+
S[$] > h ? (F = S[$], Y = $ - 1) : ee = $ + 1;
|
|
400
|
+
}
|
|
401
|
+
if (F !== void 0) {
|
|
402
|
+
const re = (o !== null ? F * (o + m) : R.query(F)) - M.value;
|
|
403
|
+
re < k && (ue.x = -(k - re));
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
u.push({
|
|
408
|
+
item: z,
|
|
409
|
+
index: h,
|
|
410
|
+
offset: { x: O - b, y: I - w },
|
|
411
|
+
size: { width: k, height: K },
|
|
412
|
+
originalX: O,
|
|
413
|
+
originalY: I,
|
|
414
|
+
isSticky: ge,
|
|
415
|
+
isStickyActive: le,
|
|
416
|
+
stickyOffset: ue
|
|
417
|
+
});
|
|
418
|
+
}
|
|
419
|
+
return u;
|
|
420
|
+
}), r = E(() => {
|
|
421
|
+
L.value;
|
|
422
|
+
const l = e.value.columnCount || 0;
|
|
423
|
+
if (!l)
|
|
424
|
+
return { start: 0, end: 0, padStart: 0, padEnd: 0 };
|
|
425
|
+
if ((!W.value || Z.value) && e.value.ssrRange) {
|
|
426
|
+
const { colStart: d = 0, colEnd: v = 0 } = e.value.ssrRange, f = Math.max(0, d), y = Math.min(l, v || l);
|
|
427
|
+
return {
|
|
428
|
+
start: f,
|
|
429
|
+
end: y,
|
|
430
|
+
padStart: 0,
|
|
431
|
+
padEnd: 0
|
|
432
|
+
};
|
|
433
|
+
}
|
|
434
|
+
const t = T.findLowerBound(M.value);
|
|
435
|
+
let u = T.query(t), o = t;
|
|
436
|
+
for (; o < l && u < M.value + j.value; )
|
|
437
|
+
u = T.query(++o);
|
|
438
|
+
const s = e.value.ssrRange && !n.value ? 0 : 2, m = Math.max(0, t - s), S = Math.min(l, o + s);
|
|
439
|
+
return {
|
|
440
|
+
start: m,
|
|
441
|
+
end: S,
|
|
442
|
+
padStart: T.query(m),
|
|
443
|
+
padEnd: T.query(l) - T.query(S)
|
|
444
|
+
};
|
|
445
|
+
}), c = E(() => {
|
|
446
|
+
L.value;
|
|
447
|
+
const l = D.value, t = e.value.columnGap || 0;
|
|
448
|
+
let u = 0;
|
|
449
|
+
return (e.value.direction === "horizontal" || e.value.direction === "both") && (l !== null ? u = Math.floor(M.value / (l + t)) : u = R.findLowerBound(M.value)), {
|
|
450
|
+
items: i.value,
|
|
451
|
+
currentIndex: qe.value,
|
|
452
|
+
currentColIndex: u,
|
|
453
|
+
scrollOffset: { x: M.value, y: B.value },
|
|
454
|
+
viewportSize: { width: j.value, height: te.value },
|
|
455
|
+
totalSize: { width: p.value, height: oe.value },
|
|
456
|
+
isScrolling: n.value,
|
|
457
|
+
isProgrammaticScroll: ce.value,
|
|
458
|
+
range: Be.value,
|
|
459
|
+
columnRange: r.value
|
|
460
|
+
};
|
|
461
|
+
}), C = () => {
|
|
462
|
+
ce.value = !1, Q.value = null;
|
|
463
|
+
}, G = (l) => {
|
|
464
|
+
const t = l.target;
|
|
465
|
+
typeof window > "u" || (t === window || t === document ? (a.value = window.scrollX, g.value = window.scrollY) : _e(t) && (a.value = t.scrollLeft, g.value = t.scrollTop), n.value || (ce.value || (Q.value = null), n.value = !0), clearTimeout(ne), ne = setTimeout(() => {
|
|
466
|
+
n.value = !1, ce.value = !1;
|
|
467
|
+
}, 250));
|
|
468
|
+
}, H = (l) => {
|
|
469
|
+
let t = !1;
|
|
470
|
+
const u = e.value.gap || 0, o = e.value.columnGap || 0;
|
|
471
|
+
for (const { index: s, inlineSize: m, blockSize: S, element: d } of l) {
|
|
472
|
+
if (Ee.value) {
|
|
473
|
+
if (m > de.value && (de.value = m), S > ve.value && (ve.value = S), e.value.direction === "horizontal") {
|
|
474
|
+
const v = R.get(s), f = m + o;
|
|
475
|
+
Math.abs(v - f) > 0.5 && (f > v || !J[s]) && (R.update(s, f - v), J[s] = 1, t = !0);
|
|
476
|
+
}
|
|
477
|
+
if (e.value.direction === "vertical" || e.value.direction === "both") {
|
|
478
|
+
const v = x.get(s), f = S + u;
|
|
479
|
+
e.value.direction === "both" ? (f > v || !A[s]) && (x.update(s, f - v), A[s] = 1, t = !0) : Math.abs(v - f) > 0.5 && (f > v || !A[s]) && (x.update(s, f - v), A[s] = 1, t = !0);
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
if (e.value.direction === "both" && d && e.value.columnCount && Pe.value) {
|
|
483
|
+
const v = d.dataset.colIndex !== void 0 ? [d] : Array.from(d.querySelectorAll("[data-col-index]"));
|
|
484
|
+
for (const f of v) {
|
|
485
|
+
const y = Number.parseInt(f.dataset.colIndex, 10);
|
|
486
|
+
if (y >= 0 && y < (e.value.columnCount || 0)) {
|
|
487
|
+
const b = f.offsetWidth, w = T.get(y), h = b + o;
|
|
488
|
+
(h > w || !ae[y]) && (T.update(y, h - w), ae[y] = 1, t = !0);
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
t && L.value++;
|
|
494
|
+
}, me = (l, t, u, o) => {
|
|
495
|
+
H([{ index: l, inlineSize: t, blockSize: u, element: o }]);
|
|
496
|
+
}, Re = () => {
|
|
497
|
+
if (Q.value && !Z.value) {
|
|
498
|
+
const { rowIndex: l, colIndex: t, options: u } = Q.value, o = et(u) ? { ...u, isCorrection: !0 } : { align: u, isCorrection: !0 };
|
|
499
|
+
ke(l, t, o);
|
|
500
|
+
}
|
|
501
|
+
};
|
|
502
|
+
ie(L, Re), ie(n, (l) => {
|
|
503
|
+
l || Re();
|
|
504
|
+
});
|
|
505
|
+
let Fe = null;
|
|
506
|
+
const at = (l) => {
|
|
507
|
+
if (!l || typeof window > "u")
|
|
508
|
+
return;
|
|
509
|
+
const t = l === window ? document : l;
|
|
510
|
+
if (t.addEventListener("scroll", G, { passive: !0 }), l === window) {
|
|
511
|
+
j.value = window.innerWidth, te.value = window.innerHeight, a.value = window.scrollX, g.value = window.scrollY;
|
|
512
|
+
const u = () => {
|
|
513
|
+
j.value = window.innerWidth, te.value = window.innerHeight, he();
|
|
514
|
+
};
|
|
515
|
+
return window.addEventListener("resize", u), () => {
|
|
516
|
+
t.removeEventListener("scroll", G), window.removeEventListener("resize", u);
|
|
517
|
+
};
|
|
518
|
+
} else
|
|
519
|
+
return j.value = l.clientWidth, te.value = l.clientHeight, a.value = l.scrollLeft, g.value = l.scrollTop, Fe = new ResizeObserver((u) => {
|
|
520
|
+
for (const o of u)
|
|
521
|
+
o.target === l && (j.value = l.clientWidth, te.value = l.clientHeight, he());
|
|
522
|
+
}), Fe.observe(l), () => {
|
|
523
|
+
t.removeEventListener("scroll", G), Fe?.disconnect();
|
|
524
|
+
};
|
|
525
|
+
};
|
|
526
|
+
let Ue;
|
|
527
|
+
return ut() && (it(() => {
|
|
528
|
+
U.value = !0, ie(() => e.value.container, (l) => {
|
|
529
|
+
Ue?.(), Ue = at(l || null);
|
|
530
|
+
}, { immediate: !0 }), he(), e.value.ssrRange || e.value.initialScrollIndex !== void 0 ? Ke(() => {
|
|
531
|
+
he();
|
|
532
|
+
const l = e.value.initialScrollIndex !== void 0 ? e.value.initialScrollIndex : e.value.ssrRange?.start, t = e.value.initialScrollAlign || "start";
|
|
533
|
+
l != null && ke(l, e.value.ssrRange?.colStart, { align: t, behavior: "auto" }), W.value = !0, Z.value = !0, Ke(() => {
|
|
534
|
+
Z.value = !1;
|
|
535
|
+
});
|
|
536
|
+
}) : W.value = !0;
|
|
537
|
+
}), nt(() => {
|
|
538
|
+
Ue?.();
|
|
539
|
+
})), {
|
|
540
|
+
/**
|
|
541
|
+
* Array of items to be rendered with their calculated offsets and sizes.
|
|
542
|
+
*/
|
|
543
|
+
renderedItems: i,
|
|
544
|
+
/**
|
|
545
|
+
* Total calculated width of all items including gaps.
|
|
546
|
+
*/
|
|
547
|
+
totalWidth: p,
|
|
548
|
+
/**
|
|
549
|
+
* Total calculated height of all items including gaps.
|
|
550
|
+
*/
|
|
551
|
+
totalHeight: oe,
|
|
552
|
+
/**
|
|
553
|
+
* Detailed information about the current scroll state.
|
|
554
|
+
* Includes currentIndex, scrollOffset, viewportSize, totalSize, and isScrolling.
|
|
555
|
+
*/
|
|
556
|
+
scrollDetails: c,
|
|
557
|
+
/**
|
|
558
|
+
* Programmatically scroll to a specific row and/or column.
|
|
559
|
+
* @param rowIndex - The row index to scroll to
|
|
560
|
+
* @param colIndex - The column index to scroll to
|
|
561
|
+
* @param options - Alignment and behavior options
|
|
562
|
+
*/
|
|
563
|
+
scrollToIndex: ke,
|
|
564
|
+
/**
|
|
565
|
+
* Programmatically scroll to a specific pixel offset.
|
|
566
|
+
* @param x - The pixel offset to scroll to on the X axis
|
|
567
|
+
* @param y - The pixel offset to scroll to on the Y axis
|
|
568
|
+
* @param options - Behavior options
|
|
569
|
+
*/
|
|
570
|
+
scrollToOffset: Xe,
|
|
571
|
+
/**
|
|
572
|
+
* Stops any currently active programmatic scroll and clears pending corrections.
|
|
573
|
+
*/
|
|
574
|
+
stopProgrammaticScroll: C,
|
|
575
|
+
/**
|
|
576
|
+
* Updates the stored size of an item. Should be called when an item is measured (e.g., via ResizeObserver).
|
|
577
|
+
* @param index - The item index
|
|
578
|
+
* @param width - The measured width
|
|
579
|
+
* @param height - The measured height
|
|
580
|
+
* @param element - The measured element (optional, used for grid column detection)
|
|
581
|
+
*/
|
|
582
|
+
updateItemSize: me,
|
|
583
|
+
/**
|
|
584
|
+
* Updates the stored size of multiple items. Should be called when items are measured (e.g., via ResizeObserver).
|
|
585
|
+
* @param updates - Array of item updates
|
|
586
|
+
*/
|
|
587
|
+
updateItemSizes: H,
|
|
588
|
+
/**
|
|
589
|
+
* Recalculates the host element's offset relative to the scroll container.
|
|
590
|
+
*/
|
|
591
|
+
updateHostOffset: he,
|
|
592
|
+
/**
|
|
593
|
+
* Information about the current visible range of columns.
|
|
594
|
+
*/
|
|
595
|
+
columnRange: r,
|
|
596
|
+
/**
|
|
597
|
+
* Helper to get the width of a specific column based on current configuration.
|
|
598
|
+
* @param index - The column index
|
|
599
|
+
*/
|
|
600
|
+
getColumnWidth: He,
|
|
601
|
+
/**
|
|
602
|
+
* Resets all dynamic measurements and re-initializes from props.
|
|
603
|
+
*/
|
|
604
|
+
refresh: () => {
|
|
605
|
+
R.resize(0), x.resize(0), T.resize(0), ae.fill(0), J.fill(0), A.fill(0), de.value = 0, ve.value = 0, Ye();
|
|
606
|
+
},
|
|
607
|
+
/**
|
|
608
|
+
* Whether the component has finished its first client-side mount and hydration.
|
|
609
|
+
*/
|
|
610
|
+
isHydrated: W
|
|
611
|
+
};
|
|
612
|
+
}
|
|
613
|
+
const ht = {
|
|
614
|
+
key: 0,
|
|
615
|
+
class: "virtual-scroll-debug-info"
|
|
616
|
+
}, gt = /* @__PURE__ */ rt({
|
|
617
|
+
__name: "VirtualScroll",
|
|
618
|
+
props: {
|
|
619
|
+
items: {},
|
|
620
|
+
itemSize: {},
|
|
621
|
+
direction: { default: "vertical" },
|
|
622
|
+
bufferBefore: { default: 5 },
|
|
623
|
+
bufferAfter: { default: 5 },
|
|
624
|
+
container: {},
|
|
625
|
+
ssrRange: {},
|
|
626
|
+
columnCount: { default: 0 },
|
|
627
|
+
columnWidth: {},
|
|
628
|
+
containerTag: { default: "div" },
|
|
629
|
+
wrapperTag: { default: "div" },
|
|
630
|
+
itemTag: { default: "div" },
|
|
631
|
+
scrollPaddingStart: { default: 0 },
|
|
632
|
+
scrollPaddingEnd: { default: 0 },
|
|
633
|
+
stickyHeader: { type: Boolean, default: !1 },
|
|
634
|
+
stickyFooter: { type: Boolean, default: !1 },
|
|
635
|
+
gap: { default: 0 },
|
|
636
|
+
columnGap: { default: 0 },
|
|
637
|
+
stickyIndices: { default: () => [] },
|
|
638
|
+
loadDistance: { default: 50 },
|
|
639
|
+
loading: { type: Boolean, default: !1 },
|
|
640
|
+
restoreScrollOnPrepend: { type: Boolean, default: !1 },
|
|
641
|
+
initialScrollIndex: {},
|
|
642
|
+
initialScrollAlign: {},
|
|
643
|
+
defaultItemSize: {},
|
|
644
|
+
defaultColumnWidth: {},
|
|
645
|
+
debug: { type: Boolean, default: !1 }
|
|
646
|
+
},
|
|
647
|
+
emits: ["scroll", "load", "visibleRangeChange"],
|
|
648
|
+
setup(e, { expose: a, emit: g }) {
|
|
649
|
+
const n = e, W = g, Z = E(() => n.debug), U = P(null), j = P(null), te = P(null), N = P(null), ne = /* @__PURE__ */ new Map(), ce = P(0), R = P(0), x = E(() => {
|
|
650
|
+
const i = n.container === void 0 ? U.value : n.container;
|
|
651
|
+
return i === U.value || typeof window < "u" && (i === window || i === null);
|
|
652
|
+
}), T = E(() => {
|
|
653
|
+
const i = n.scrollPaddingStart, r = n.scrollPaddingEnd, c = typeof i == "object" ? i.x || 0 : n.direction === "horizontal" && i || 0, C = typeof i == "object" ? i.y || 0 : n.direction !== "horizontal" && i || 0, G = typeof r == "object" ? r.x || 0 : n.direction === "horizontal" && r || 0, H = typeof r == "object" ? r.y || 0 : n.direction !== "horizontal" && r || 0;
|
|
654
|
+
return {
|
|
655
|
+
items: n.items,
|
|
656
|
+
itemSize: n.itemSize,
|
|
657
|
+
direction: n.direction,
|
|
658
|
+
bufferBefore: n.bufferBefore,
|
|
659
|
+
bufferAfter: n.bufferAfter,
|
|
660
|
+
container: n.container === void 0 ? U.value : n.container,
|
|
661
|
+
hostElement: j.value,
|
|
662
|
+
ssrRange: n.ssrRange,
|
|
663
|
+
columnCount: n.columnCount,
|
|
664
|
+
columnWidth: n.columnWidth,
|
|
665
|
+
scrollPaddingStart: {
|
|
666
|
+
x: c,
|
|
667
|
+
y: C + (n.stickyHeader && x.value ? ce.value : 0)
|
|
668
|
+
},
|
|
669
|
+
scrollPaddingEnd: {
|
|
670
|
+
x: G,
|
|
671
|
+
y: H + (n.stickyFooter && x.value ? R.value : 0)
|
|
672
|
+
},
|
|
673
|
+
gap: n.gap,
|
|
674
|
+
columnGap: n.columnGap,
|
|
675
|
+
stickyIndices: n.stickyIndices,
|
|
676
|
+
loadDistance: n.loadDistance,
|
|
677
|
+
loading: n.loading,
|
|
678
|
+
restoreScrollOnPrepend: n.restoreScrollOnPrepend,
|
|
679
|
+
initialScrollIndex: n.initialScrollIndex,
|
|
680
|
+
initialScrollAlign: n.initialScrollAlign,
|
|
681
|
+
defaultItemSize: n.defaultItemSize,
|
|
682
|
+
defaultColumnWidth: n.defaultColumnWidth,
|
|
683
|
+
debug: Z.value
|
|
684
|
+
};
|
|
685
|
+
}), {
|
|
686
|
+
isHydrated: L,
|
|
687
|
+
columnRange: ae,
|
|
688
|
+
renderedItems: J,
|
|
689
|
+
scrollDetails: A,
|
|
690
|
+
totalHeight: Q,
|
|
691
|
+
totalWidth: de,
|
|
692
|
+
getColumnWidth: ve,
|
|
693
|
+
scrollToIndex: be,
|
|
694
|
+
scrollToOffset: _,
|
|
695
|
+
updateHostOffset: Ee,
|
|
696
|
+
updateItemSizes: Pe,
|
|
697
|
+
refresh: D,
|
|
698
|
+
stopProgrammaticScroll: fe
|
|
699
|
+
} = ft(T);
|
|
700
|
+
ie(A, (i, r) => {
|
|
701
|
+
L.value && (W("scroll", i), (!r || i.range.start !== r.range.start || i.range.end !== r.range.end || i.columnRange.start !== r.columnRange.start || i.columnRange.end !== r.columnRange.end) && W("visibleRangeChange", {
|
|
702
|
+
start: i.range.start,
|
|
703
|
+
end: i.range.end,
|
|
704
|
+
colStart: i.columnRange.start,
|
|
705
|
+
colEnd: i.columnRange.end
|
|
706
|
+
}), !n.loading && (n.direction !== "horizontal" && i.totalSize.height - (i.scrollOffset.y + i.viewportSize.height) <= n.loadDistance && W("load", "vertical"), n.direction !== "vertical" && i.totalSize.width - (i.scrollOffset.x + i.viewportSize.width) <= n.loadDistance && W("load", "horizontal")));
|
|
707
|
+
}), ie(L, (i) => {
|
|
708
|
+
i && W("visibleRangeChange", {
|
|
709
|
+
start: A.value.range.start,
|
|
710
|
+
end: A.value.range.end,
|
|
711
|
+
colStart: A.value.columnRange.start,
|
|
712
|
+
colEnd: A.value.columnRange.end
|
|
713
|
+
});
|
|
714
|
+
}, { once: !0 });
|
|
715
|
+
const ze = typeof window > "u" ? null : new ResizeObserver(Ee), p = typeof window > "u" ? null : new ResizeObserver((i) => {
|
|
716
|
+
const r = [];
|
|
717
|
+
for (const c of i) {
|
|
718
|
+
const C = c.target, G = Number(C.dataset.index);
|
|
719
|
+
if (C.dataset.colIndex !== void 0)
|
|
720
|
+
r.push({ index: -1, inlineSize: 0, blockSize: 0, element: C });
|
|
721
|
+
else if (!Number.isNaN(G)) {
|
|
722
|
+
let me = c.contentRect.width, Re = c.contentRect.height;
|
|
723
|
+
c.borderBoxSize && c.borderBoxSize.length > 0 ? (me = c.borderBoxSize[0].inlineSize, Re = c.borderBoxSize[0].blockSize) : (me = C.offsetWidth, Re = C.offsetHeight), r.push({ index: G, inlineSize: me, blockSize: Re, element: C });
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
r.length > 0 && Pe(r);
|
|
727
|
+
}), oe = typeof window > "u" ? null : new ResizeObserver(() => {
|
|
728
|
+
ce.value = te.value?.offsetHeight || 0, R.value = N.value?.offsetHeight || 0, Ee();
|
|
729
|
+
});
|
|
730
|
+
ie(te, (i, r) => {
|
|
731
|
+
r && oe?.unobserve(r), i && oe?.observe(i);
|
|
732
|
+
}, { immediate: !0 }), ie(N, (i, r) => {
|
|
733
|
+
r && oe?.unobserve(r), i && oe?.observe(i);
|
|
734
|
+
}, { immediate: !0 });
|
|
735
|
+
const M = E(() => J.value[0]?.index);
|
|
736
|
+
ie(M, (i, r) => {
|
|
737
|
+
if (n.direction === "both") {
|
|
738
|
+
if (r !== void 0) {
|
|
739
|
+
const c = ne.get(r);
|
|
740
|
+
c && c.querySelectorAll("[data-col-index]").forEach((C) => p?.unobserve(C));
|
|
741
|
+
}
|
|
742
|
+
if (i !== void 0) {
|
|
743
|
+
const c = ne.get(i);
|
|
744
|
+
c && c.querySelectorAll("[data-col-index]").forEach((C) => p?.observe(C));
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
}, { flush: "post" }), it(() => {
|
|
748
|
+
U.value && ze?.observe(U.value);
|
|
749
|
+
for (const i of ne.values())
|
|
750
|
+
p?.observe(i);
|
|
751
|
+
if (M.value !== void 0) {
|
|
752
|
+
const i = ne.get(M.value);
|
|
753
|
+
i && i.querySelectorAll("[data-col-index]").forEach((r) => p?.observe(r));
|
|
754
|
+
}
|
|
755
|
+
}), ie([U, j], ([i], [r]) => {
|
|
756
|
+
r && ze?.unobserve(r), i && ze?.observe(i);
|
|
757
|
+
});
|
|
758
|
+
function B(i, r) {
|
|
759
|
+
if (i)
|
|
760
|
+
ne.set(r, i), p?.observe(i);
|
|
761
|
+
else {
|
|
762
|
+
const c = ne.get(r);
|
|
763
|
+
c && (p?.unobserve(c), ne.delete(r));
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
function He(i) {
|
|
767
|
+
fe();
|
|
768
|
+
const { viewportSize: r, scrollOffset: c } = A.value, C = n.direction !== "vertical", G = n.direction !== "horizontal";
|
|
769
|
+
if (i.key === "Home") {
|
|
770
|
+
i.preventDefault(), be(0, 0, "start");
|
|
771
|
+
return;
|
|
772
|
+
}
|
|
773
|
+
if (i.key === "End") {
|
|
774
|
+
i.preventDefault();
|
|
775
|
+
const H = n.items.length - 1, me = (n.columnCount || 0) > 0 ? n.columnCount - 1 : 0;
|
|
776
|
+
C && G ? be(H, me, "end") : be(0, H, "end");
|
|
777
|
+
return;
|
|
778
|
+
}
|
|
779
|
+
if (i.key === "ArrowUp") {
|
|
780
|
+
i.preventDefault(), _(null, c.y - 40);
|
|
781
|
+
return;
|
|
782
|
+
}
|
|
783
|
+
if (i.key === "ArrowDown") {
|
|
784
|
+
i.preventDefault(), _(null, c.y + 40);
|
|
785
|
+
return;
|
|
786
|
+
}
|
|
787
|
+
if (i.key === "ArrowLeft") {
|
|
788
|
+
i.preventDefault(), _(c.x - 40, null);
|
|
789
|
+
return;
|
|
790
|
+
}
|
|
791
|
+
if (i.key === "ArrowRight") {
|
|
792
|
+
i.preventDefault(), _(c.x + 40, null);
|
|
793
|
+
return;
|
|
794
|
+
}
|
|
795
|
+
if (i.key === "PageUp") {
|
|
796
|
+
i.preventDefault(), _(
|
|
797
|
+
C ? c.x - r.width : null,
|
|
798
|
+
G ? c.y - r.height : null
|
|
799
|
+
);
|
|
800
|
+
return;
|
|
801
|
+
}
|
|
802
|
+
i.key === "PageDown" && (i.preventDefault(), _(
|
|
803
|
+
C ? c.x + r.width : null,
|
|
804
|
+
G ? c.y + r.height : null
|
|
805
|
+
));
|
|
806
|
+
}
|
|
807
|
+
nt(() => {
|
|
808
|
+
ze?.disconnect(), p?.disconnect(), oe?.disconnect();
|
|
809
|
+
});
|
|
810
|
+
const ke = E(() => {
|
|
811
|
+
const i = n.container;
|
|
812
|
+
return i === null || typeof window < "u" && i === window ? !0 : i && typeof i == "object" && "tagName" in i ? i.tagName === "BODY" : !1;
|
|
813
|
+
}), Xe = E(() => ke.value ? {
|
|
814
|
+
...n.direction !== "vertical" ? { whiteSpace: "nowrap" } : {}
|
|
815
|
+
} : n.containerTag === "table" ? {
|
|
816
|
+
minInlineSize: n.direction === "vertical" ? "100%" : "auto"
|
|
817
|
+
} : {
|
|
818
|
+
...n.direction !== "vertical" ? { whiteSpace: "nowrap" } : {}
|
|
819
|
+
}), Ye = E(() => ({
|
|
820
|
+
inlineSize: n.direction === "vertical" ? "100%" : `${de.value}px`,
|
|
821
|
+
blockSize: n.direction === "horizontal" ? "100%" : `${Q.value}px`
|
|
822
|
+
})), he = E(() => {
|
|
823
|
+
const i = n.direction === "horizontal";
|
|
824
|
+
return {
|
|
825
|
+
display: i ? "inline-block" : "block",
|
|
826
|
+
...i ? { blockSize: "100%", verticalAlign: "top" } : { inlineSize: "100%" }
|
|
827
|
+
};
|
|
828
|
+
}), Be = E(() => ({
|
|
829
|
+
inlineSize: n.direction === "vertical" ? "1px" : `${de.value}px`,
|
|
830
|
+
blockSize: n.direction === "horizontal" ? "1px" : `${Q.value}px`
|
|
831
|
+
}));
|
|
832
|
+
function qe(i) {
|
|
833
|
+
const r = n.direction === "vertical", c = n.direction === "horizontal", C = n.direction === "both", G = n.itemSize === void 0 || n.itemSize === null || n.itemSize === 0, H = {
|
|
834
|
+
blockSize: c ? "100%" : G ? "auto" : `${i.size.height}px`
|
|
835
|
+
};
|
|
836
|
+
return r && n.containerTag === "table" ? H.minInlineSize = "100%" : H.inlineSize = r ? "100%" : G ? "auto" : `${i.size.width}px`, G && (r || (H.minInlineSize = `${i.size.width}px`), c || (H.minBlockSize = `${i.size.height}px`)), L.value && (i.isStickyActive ? ((r || C) && (H.insetBlockStart = `${Se(n.scrollPaddingStart, n.direction)}px`), (c || C) && (H.insetInlineStart = `${we(n.scrollPaddingStart, n.direction)}px`), H.transform = `translate(${i.stickyOffset.x}px, ${i.stickyOffset.y}px)`) : H.transform = `translate(${i.offset.x}px, ${i.offset.y}px)`), H;
|
|
837
|
+
}
|
|
838
|
+
return a({
|
|
839
|
+
scrollDetails: A,
|
|
840
|
+
columnRange: ae,
|
|
841
|
+
getColumnWidth: ve,
|
|
842
|
+
scrollToIndex: be,
|
|
843
|
+
scrollToOffset: _,
|
|
844
|
+
refresh: D,
|
|
845
|
+
stopProgrammaticScroll: fe
|
|
846
|
+
}), (i, r) => (se(), xe(Me(e.containerTag), {
|
|
847
|
+
ref_key: "hostRef",
|
|
848
|
+
ref: U,
|
|
849
|
+
class: $e(["virtual-scroll-container", [
|
|
850
|
+
`virtual-scroll--${e.direction}`,
|
|
851
|
+
{
|
|
852
|
+
"virtual-scroll--hydrated": ye(L),
|
|
853
|
+
"virtual-scroll--window": ke.value,
|
|
854
|
+
"virtual-scroll--table": e.containerTag === "table"
|
|
855
|
+
}
|
|
856
|
+
]]),
|
|
857
|
+
style: We(Xe.value),
|
|
858
|
+
tabindex: "0",
|
|
859
|
+
onKeydown: He,
|
|
860
|
+
onWheelPassive: ye(fe),
|
|
861
|
+
onPointerdownPassive: ye(fe),
|
|
862
|
+
onTouchstartPassive: ye(fe)
|
|
863
|
+
}, {
|
|
864
|
+
default: Ce(() => [
|
|
865
|
+
i.$slots.header ? (se(), xe(Me(e.containerTag === "table" ? "thead" : "div"), {
|
|
866
|
+
key: 0,
|
|
867
|
+
ref_key: "headerRef",
|
|
868
|
+
ref: te,
|
|
869
|
+
class: $e(["virtual-scroll-header", { "virtual-scroll--sticky": e.stickyHeader }])
|
|
870
|
+
}, {
|
|
871
|
+
default: Ce(() => [
|
|
872
|
+
Ve(i.$slots, "header", {}, void 0, !0)
|
|
873
|
+
]),
|
|
874
|
+
_: 3
|
|
875
|
+
}, 8, ["class"])) : Ae("", !0),
|
|
876
|
+
(se(), xe(Me(e.wrapperTag), {
|
|
877
|
+
ref_key: "wrapperRef",
|
|
878
|
+
ref: j,
|
|
879
|
+
class: "virtual-scroll-wrapper",
|
|
880
|
+
style: We(Ye.value)
|
|
881
|
+
}, {
|
|
882
|
+
default: Ce(() => [
|
|
883
|
+
e.containerTag === "table" ? (se(), xe(Me(e.itemTag), {
|
|
884
|
+
key: 0,
|
|
885
|
+
class: "virtual-scroll-spacer",
|
|
886
|
+
style: We(Be.value)
|
|
887
|
+
}, {
|
|
888
|
+
default: Ce(() => [...r[0] || (r[0] = [
|
|
889
|
+
ct("td", { style: { padding: "0", border: "none", "block-size": "inherit" } }, null, -1)
|
|
890
|
+
])]),
|
|
891
|
+
_: 1
|
|
892
|
+
}, 8, ["style"])) : Ae("", !0),
|
|
893
|
+
(se(!0), Ze(st, null, dt(ye(J), (c) => (se(), xe(Me(e.itemTag), {
|
|
894
|
+
key: c.index,
|
|
895
|
+
ref_for: !0,
|
|
896
|
+
ref: (C) => B(C, c.index),
|
|
897
|
+
"data-index": c.index,
|
|
898
|
+
class: $e(["virtual-scroll-item", {
|
|
899
|
+
"virtual-scroll--sticky": c.isStickyActive,
|
|
900
|
+
"virtual-scroll--debug": Z.value
|
|
901
|
+
}]),
|
|
902
|
+
style: We(qe(c))
|
|
903
|
+
}, {
|
|
904
|
+
default: Ce(() => [
|
|
905
|
+
Ve(i.$slots, "item", {
|
|
906
|
+
item: c.item,
|
|
907
|
+
index: c.index,
|
|
908
|
+
columnRange: ye(ae),
|
|
909
|
+
getColumnWidth: ye(ve),
|
|
910
|
+
isSticky: c.isSticky,
|
|
911
|
+
isStickyActive: c.isStickyActive
|
|
912
|
+
}, void 0, !0),
|
|
913
|
+
Z.value ? (se(), Ze("div", ht, " #" + Je(c.index) + " (" + Je(Math.round(c.offset.x)) + ", " + Je(Math.round(c.offset.y)) + ") ", 1)) : Ae("", !0)
|
|
914
|
+
]),
|
|
915
|
+
_: 2
|
|
916
|
+
}, 1032, ["data-index", "class", "style"]))), 128))
|
|
917
|
+
]),
|
|
918
|
+
_: 3
|
|
919
|
+
}, 8, ["style"])),
|
|
920
|
+
e.loading && i.$slots.loading ? (se(), Ze("div", {
|
|
921
|
+
key: 1,
|
|
922
|
+
class: "virtual-scroll-loading",
|
|
923
|
+
style: We(he.value)
|
|
924
|
+
}, [
|
|
925
|
+
Ve(i.$slots, "loading", {}, void 0, !0)
|
|
926
|
+
], 4)) : Ae("", !0),
|
|
927
|
+
i.$slots.footer ? (se(), xe(Me(e.containerTag === "table" ? "tfoot" : "div"), {
|
|
928
|
+
key: 2,
|
|
929
|
+
ref_key: "footerRef",
|
|
930
|
+
ref: N,
|
|
931
|
+
class: $e(["virtual-scroll-footer", { "virtual-scroll--sticky": e.stickyFooter }])
|
|
932
|
+
}, {
|
|
933
|
+
default: Ce(() => [
|
|
934
|
+
Ve(i.$slots, "footer", {}, void 0, !0)
|
|
935
|
+
]),
|
|
936
|
+
_: 3
|
|
937
|
+
}, 8, ["class"])) : Ae("", !0)
|
|
938
|
+
]),
|
|
939
|
+
_: 3
|
|
940
|
+
}, 40, ["class", "style", "onWheelPassive", "onPointerdownPassive", "onTouchstartPassive"]));
|
|
941
|
+
}
|
|
942
|
+
}), mt = (e, a) => {
|
|
943
|
+
const g = e.__vccOpts || e;
|
|
944
|
+
for (const [n, W] of a)
|
|
945
|
+
g[n] = W;
|
|
946
|
+
return g;
|
|
947
|
+
}, St = /* @__PURE__ */ mt(gt, [["__scopeId", "data-v-654a1d54"]]);
|
|
948
|
+
export {
|
|
949
|
+
lt as DEFAULT_BUFFER,
|
|
950
|
+
tt as DEFAULT_COLUMN_WIDTH,
|
|
951
|
+
vt as DEFAULT_ITEM_SIZE,
|
|
952
|
+
Qe as FenwickTree,
|
|
953
|
+
St as VirtualScroll,
|
|
954
|
+
we as getPaddingX,
|
|
955
|
+
Se as getPaddingY,
|
|
956
|
+
pe as isElement,
|
|
957
|
+
et as isScrollToIndexOptions,
|
|
958
|
+
_e as isScrollableElement,
|
|
959
|
+
ft as useVirtualScroll
|
|
960
|
+
};
|
|
961
|
+
//# sourceMappingURL=index.js.map
|