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