@himanshu-sorathiya/react-kit 1.0.27 → 1.0.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1039 -30
- package/dist/index.js +5 -5
- package/dist/performance.d.ts +1039 -30
- package/dist/performance.js +2 -2
- package/dist/performance2.js +458 -237
- package/package.json +7 -4
package/dist/performance2.js
CHANGED
|
@@ -1,20 +1,123 @@
|
|
|
1
1
|
import { t as e } from "./useEventListener.js";
|
|
2
2
|
import { t } from "./utils.js";
|
|
3
3
|
import { useCallback as n, useEffect as r, useLayoutEffect as i, useMemo as a, useRef as o, useState as s } from "react";
|
|
4
|
-
//#region src/performance/
|
|
5
|
-
function c(e
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
//#region src/performance/useBatcher/utils.ts
|
|
5
|
+
function c(e) {
|
|
6
|
+
if (e === void 0) return;
|
|
7
|
+
let t = Math.floor(Number(e));
|
|
8
|
+
return Number.isFinite(t) && t >= 1 ? t : void 0;
|
|
9
|
+
}
|
|
10
|
+
function l(e) {
|
|
11
|
+
if (e === void 0) return;
|
|
12
|
+
let t = Number(e);
|
|
13
|
+
return Number.isFinite(t) && t >= 0 ? t : void 0;
|
|
14
|
+
}
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region src/performance/useBatcher/useBatcher.ts
|
|
17
|
+
var u = globalThis.process?.env?.NODE_ENV !== "production";
|
|
18
|
+
function d(e, t = {}) {
|
|
19
|
+
u && typeof e != "function" && console.warn(`[useBatcher] Expected \`onFlush\` to be a function, received ${typeof e}.`);
|
|
20
|
+
let i = c(t?.maxSize), a = l(t?.maxWait), d = l(t?.quietPeriod);
|
|
21
|
+
u && t?.maxSize !== void 0 && i === void 0 && console.warn(`[useBatcher] \`maxSize\` (${String(t.maxSize)}) must be a positive integer — ignoring it.`), u && t?.maxWait !== void 0 && a === void 0 && console.warn(`[useBatcher] \`maxWait\` (${String(t.maxWait)}) must be a non-negative number — ignoring it.`), u && t?.quietPeriod !== void 0 && d === void 0 && console.warn(`[useBatcher] \`quietPeriod\` (${String(t.quietPeriod)}) must be a non-negative number — ignoring it.`), u && i === void 0 && a === void 0 && d === void 0 && console.warn("[useBatcher] No `maxSize`, `maxWait`, or `quietPeriod` configured — items will only flush when `flush()` is called manually."), u && a !== void 0 && d !== void 0 && d >= a && console.warn(`[useBatcher] \`quietPeriod\` (${d}ms) is not shorter than \`maxWait\` (${a}ms) — \`maxWait\` will almost always fire first, making \`quietPeriod\` unreachable in practice.`), u && t?.onItemsChange !== void 0 && typeof t.onItemsChange != "function" && console.warn("[useBatcher] `onItemsChange` must be a function — ignoring the provided value.");
|
|
22
|
+
let [f, p] = s(0), [m, h] = s(!1), g = o([]), _ = o(!1), v = o(null), y = o(null), b = o(e), x = o(typeof t?.onItemsChange == "function" ? t.onItemsChange : void 0);
|
|
23
|
+
r(() => {
|
|
24
|
+
b.current = e;
|
|
25
|
+
}, [e]), r(() => {
|
|
26
|
+
x.current = typeof t?.onItemsChange == "function" ? t.onItemsChange : void 0;
|
|
27
|
+
}, [t?.onItemsChange]);
|
|
28
|
+
let S = n(() => {
|
|
29
|
+
x.current?.([...g.current]);
|
|
30
|
+
}, []), C = n(() => {
|
|
31
|
+
v.current !== null && (clearTimeout(v.current), v.current = null), y.current !== null && (clearTimeout(y.current), y.current = null);
|
|
32
|
+
}, []);
|
|
33
|
+
r(() => C, [C]);
|
|
34
|
+
let w = n(() => {
|
|
35
|
+
if (C(), g.current.length === 0) return;
|
|
36
|
+
let e = g.current;
|
|
37
|
+
g.current = [], p(0), S(), b.current(e);
|
|
38
|
+
}, [C, S]), T = n(() => {
|
|
39
|
+
C(), g.current = [], p(0), S();
|
|
40
|
+
}, [C, S]), E = n(() => {
|
|
41
|
+
_.current = !0, C(), h(!0);
|
|
42
|
+
}, [C]), D = n(() => {
|
|
43
|
+
if (_.current = !1, h(!1), g.current.length !== 0) {
|
|
44
|
+
if (i !== void 0 && g.current.length >= i) {
|
|
45
|
+
w();
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
a !== void 0 && (v.current = setTimeout(() => {
|
|
49
|
+
v.current = null, w();
|
|
50
|
+
}, a)), d !== void 0 && (y.current = setTimeout(() => {
|
|
51
|
+
y.current = null, w();
|
|
52
|
+
}, d));
|
|
53
|
+
}
|
|
54
|
+
}, [
|
|
55
|
+
i,
|
|
56
|
+
a,
|
|
57
|
+
d,
|
|
58
|
+
w
|
|
59
|
+
]);
|
|
60
|
+
return {
|
|
61
|
+
add: n((e) => {
|
|
62
|
+
let t = g.current.length === 0;
|
|
63
|
+
if (g.current.push(e), p(g.current.length), S(), !_.current) {
|
|
64
|
+
if (i !== void 0 && g.current.length >= i) {
|
|
65
|
+
w();
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
t && a !== void 0 && (v.current = setTimeout(() => {
|
|
69
|
+
v.current = null, w();
|
|
70
|
+
}, a)), d !== void 0 && (y.current !== null && clearTimeout(y.current), y.current = setTimeout(() => {
|
|
71
|
+
y.current = null, w();
|
|
72
|
+
}, d));
|
|
73
|
+
}
|
|
74
|
+
}, [
|
|
75
|
+
i,
|
|
76
|
+
a,
|
|
77
|
+
d,
|
|
78
|
+
w,
|
|
79
|
+
S
|
|
80
|
+
]),
|
|
81
|
+
flush: w,
|
|
82
|
+
cancel: T,
|
|
83
|
+
pause: E,
|
|
84
|
+
resume: D,
|
|
85
|
+
size: f,
|
|
86
|
+
isPending: f > 0,
|
|
87
|
+
isPaused: m
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
//#endregion
|
|
91
|
+
//#region src/performance/useDebouncer/useDebouncer.ts
|
|
92
|
+
var f = globalThis.process?.env?.NODE_ENV !== "production";
|
|
93
|
+
function p(e, t = {}) {
|
|
94
|
+
let i = Math.max(0, Number(e) || 0);
|
|
95
|
+
f && (typeof e != "number" || !Number.isFinite(e) || e < 0) && console.warn(`[useDebouncer] Received an invalid \`delay\` (${String(e)}) — falling back to ${i}ms.`);
|
|
96
|
+
let [a, c] = s(!1), l = t?.maxWait, u = !!t?.leading, d = t?.trailing ?? !0;
|
|
97
|
+
f && !u && !d && console.warn("[useDebouncer] Both `leading` and `trailing` are false — the debounced function will never be invoked."), f && l !== void 0 && l < i && console.warn(`[useDebouncer] \`maxWait\` (${l}ms) is smaller than \`delay\` (${i}ms) — the function will fire on almost every call.`);
|
|
98
|
+
let p = o(null), m = o(null), h = o(null), g = o(-1), _ = n(() => {
|
|
99
|
+
h.current !== null && (clearTimeout(h.current), h.current = null), g.current = -1, m.current = null, p.current = null, c(!1);
|
|
8
100
|
}, []), v = n(() => {
|
|
9
|
-
|
|
101
|
+
let e = p.current, t = m.current;
|
|
102
|
+
h.current === null || e === null || t === null || (clearTimeout(h.current), h.current = null, g.current = -1, m.current = null, p.current = null, c(!1), e(...t));
|
|
10
103
|
}, []);
|
|
11
|
-
return r(() =>
|
|
12
|
-
_();
|
|
13
|
-
}, [_]), {
|
|
104
|
+
return r(() => _, [_]), {
|
|
14
105
|
run: n((e, ...t) => {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
106
|
+
let n = Date.now();
|
|
107
|
+
if (p.current = e, m.current = t, g.current === -1 && (g.current = n, u)) {
|
|
108
|
+
let e = p.current, t = m.current;
|
|
109
|
+
m.current = null, e(...t);
|
|
110
|
+
}
|
|
111
|
+
let r = p.current, a = m.current;
|
|
112
|
+
if (l !== void 0 && r !== null && a !== null && n - g.current >= l) {
|
|
113
|
+
h.current !== null && (clearTimeout(h.current), h.current = null), g.current = -1, m.current = null, p.current = null, c(!1), r(...a);
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
h.current !== null && clearTimeout(h.current), h.current = setTimeout(() => {
|
|
117
|
+
h.current = null;
|
|
118
|
+
let e = p.current, t = m.current;
|
|
119
|
+
g.current = -1, m.current = null, p.current = null, c(!1), d && e !== null && t !== null && e(...t);
|
|
120
|
+
}, i), c(d);
|
|
18
121
|
}, [
|
|
19
122
|
i,
|
|
20
123
|
l,
|
|
@@ -27,121 +130,219 @@ function c(e, t = {}) {
|
|
|
27
130
|
};
|
|
28
131
|
}
|
|
29
132
|
//#endregion
|
|
30
|
-
//#region src/performance/
|
|
31
|
-
|
|
133
|
+
//#region src/performance/useDebouncer/useDebouncedCallback.ts
|
|
134
|
+
var m = globalThis.process?.env?.NODE_ENV !== "production";
|
|
135
|
+
function h(e, t, i = {}) {
|
|
136
|
+
m && typeof e != "function" && console.warn(`[useDebouncedCallback] Expected \`func\` to be a function, received ${typeof e}.`);
|
|
32
137
|
let a = o(e);
|
|
33
138
|
r(() => {
|
|
34
139
|
a.current = e;
|
|
35
140
|
}, [e]);
|
|
36
|
-
let { run: s, cancel:
|
|
141
|
+
let { run: s, cancel: c, flush: l, isPending: u } = p(t, i);
|
|
37
142
|
return {
|
|
38
143
|
debouncedFunc: n((...e) => {
|
|
39
144
|
s(a.current, ...e);
|
|
40
145
|
}, [s]),
|
|
41
|
-
cancel:
|
|
42
|
-
flush:
|
|
43
|
-
isPending:
|
|
146
|
+
cancel: c,
|
|
147
|
+
flush: l,
|
|
148
|
+
isPending: u
|
|
44
149
|
};
|
|
45
150
|
}
|
|
46
151
|
//#endregion
|
|
47
|
-
//#region src/
|
|
48
|
-
function
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
152
|
+
//#region src/shared/rateControlShared/utils.ts
|
|
153
|
+
function g(e) {
|
|
154
|
+
return typeof e == "function";
|
|
155
|
+
}
|
|
156
|
+
//#endregion
|
|
157
|
+
//#region src/performance/useDebouncer/useDebouncedState.ts
|
|
158
|
+
var _ = globalThis.process?.env?.NODE_ENV !== "production";
|
|
159
|
+
function v(e, t, r = {}) {
|
|
160
|
+
_ && r.equalityFn !== void 0 && typeof r.equalityFn != "function" && console.warn("[useDebouncedState] `equalityFn` must be a function — falling back to `Object.is`.");
|
|
161
|
+
let i = typeof r.equalityFn == "function" ? r.equalityFn : Object.is, [a, c] = s(e), l = o(a), { debouncedFunc: u, cancel: d, flush: f, isPending: p } = h(n((e) => {
|
|
162
|
+
c((t) => i(t, e) ? t : e);
|
|
163
|
+
}, [i]), t, r);
|
|
52
164
|
return [
|
|
53
|
-
r,
|
|
54
165
|
a,
|
|
166
|
+
n((e) => {
|
|
167
|
+
let t = g(e) ? e(l.current) : e;
|
|
168
|
+
l.current = t, u(t);
|
|
169
|
+
}, [u]),
|
|
55
170
|
{
|
|
56
|
-
isPending:
|
|
57
|
-
cancel:
|
|
58
|
-
|
|
59
|
-
|
|
171
|
+
isPending: p,
|
|
172
|
+
cancel: n(() => {
|
|
173
|
+
d(), c((e) => (l.current = e, e));
|
|
174
|
+
}, [d]),
|
|
175
|
+
flush: f,
|
|
176
|
+
forceSetValue: n((e) => {
|
|
177
|
+
d(), c((t) => {
|
|
178
|
+
let n = g(e) ? e(t) : e;
|
|
179
|
+
return l.current = n, n;
|
|
180
|
+
});
|
|
181
|
+
}, [d])
|
|
60
182
|
}
|
|
61
183
|
];
|
|
62
184
|
}
|
|
63
185
|
//#endregion
|
|
64
|
-
//#region src/performance/
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
186
|
+
//#region src/performance/useDebouncer/useDebouncedValue.ts
|
|
187
|
+
var y = globalThis.process?.env?.NODE_ENV !== "production";
|
|
188
|
+
function b(e, t, n = {}) {
|
|
189
|
+
y && n.equalityFn !== void 0 && typeof n.equalityFn != "function" && console.warn("[useDebouncedValue] `equalityFn` must be a function — falling back to `Object.is`.");
|
|
190
|
+
let i = typeof n.equalityFn == "function" ? n.equalityFn : Object.is, [a, o] = s(e), { debouncedFunc: c, cancel: l, flush: u, isPending: d } = h((e) => {
|
|
191
|
+
o((t) => i(t, e) ? t : e);
|
|
68
192
|
}, t, n);
|
|
69
193
|
return r(() => {
|
|
70
|
-
|
|
71
|
-
}, [e,
|
|
194
|
+
c(e);
|
|
195
|
+
}, [e, c]), [a, {
|
|
196
|
+
isPending: d,
|
|
197
|
+
cancel: l,
|
|
198
|
+
flush: u
|
|
199
|
+
}];
|
|
72
200
|
}
|
|
73
201
|
//#endregion
|
|
74
|
-
//#region src/performance/
|
|
75
|
-
|
|
76
|
-
|
|
202
|
+
//#region src/performance/useRateLimiter/useRateLimiter.ts
|
|
203
|
+
var x = globalThis.process?.env?.NODE_ENV !== "production";
|
|
204
|
+
function S(e, t, i) {
|
|
205
|
+
let a = Math.max(1, Math.floor(Number(e) || 1)), c = Math.max(0, Number(t) || 0);
|
|
206
|
+
x && (typeof e != "number" || !Number.isFinite(e) || e < 1) && console.warn(`[useRateLimiter] Received an invalid \`limit\` (${String(e)}) — falling back to ${a}.`), x && (typeof t != "number" || !Number.isFinite(t) || t < 0) && console.warn(`[useRateLimiter] Received an invalid \`windowMs\` (${String(t)}) — falling back to ${c}ms.`), x && c === 0 && console.warn("[useRateLimiter] `windowMs` is 0 — rate limiting is effectively disabled; every call will be allowed."), x && i?.refillStrategy !== void 0 && i.refillStrategy !== "burst" && i.refillStrategy !== "gradual" && console.warn(`[useRateLimiter] \`refillStrategy\` must be "burst" or "gradual", received "${String(i.refillStrategy)}" — falling back to "burst".`), x && i?.onRateLimitReached !== void 0 && typeof i.onRateLimitReached != "function" && console.warn("[useRateLimiter] `onRateLimitReached` must be a function — ignoring the provided value.");
|
|
207
|
+
let [l, u] = s(a), d = i?.refillStrategy === "gradual" ? "gradual" : "burst", f = o(typeof i?.onRateLimitReached == "function" ? i.onRateLimitReached : void 0);
|
|
77
208
|
r(() => {
|
|
78
|
-
f.current = i?.onRateLimitReached;
|
|
209
|
+
f.current = typeof i?.onRateLimitReached == "function" ? i.onRateLimitReached : void 0;
|
|
79
210
|
}, [i?.onRateLimitReached]);
|
|
80
|
-
let p = o(a),
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}, [])
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
211
|
+
let p = o(a), m = o(Date.now()), h = o(null);
|
|
212
|
+
r(() => () => {
|
|
213
|
+
h.current !== null && clearTimeout(h.current);
|
|
214
|
+
}, []);
|
|
215
|
+
let g = n(() => {
|
|
216
|
+
if (c === 0) {
|
|
217
|
+
p.current !== a && (p.current = a, u(a));
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
let e = Date.now(), t = e - m.current;
|
|
221
|
+
if (d === "burst") {
|
|
222
|
+
t >= c && p.current !== a && (p.current = a, m.current = e, u(a));
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
let n = c / a, r = Math.floor(t / n);
|
|
226
|
+
r > 0 && (p.current = Math.min(a, p.current + r), m.current += r * n, u(p.current));
|
|
227
|
+
}, [
|
|
228
|
+
d,
|
|
229
|
+
c,
|
|
230
|
+
a
|
|
231
|
+
]), _ = n(function e() {
|
|
232
|
+
if (h.current !== null && (clearTimeout(h.current), h.current = null), p.current >= a || c === 0) return;
|
|
233
|
+
let t = c / a, n = Date.now() - m.current, r = d === "burst" ? c - n : t - n;
|
|
234
|
+
h.current = setTimeout(() => {
|
|
235
|
+
h.current = null, g(), e();
|
|
236
|
+
}, Math.max(0, r));
|
|
237
|
+
}, [
|
|
238
|
+
a,
|
|
239
|
+
c,
|
|
240
|
+
d,
|
|
241
|
+
g
|
|
242
|
+
]), v = n(() => {
|
|
243
|
+
h.current !== null && (clearTimeout(h.current), h.current = null), p.current = a, m.current = Date.now(), u(a);
|
|
244
|
+
}, [a]);
|
|
245
|
+
return {
|
|
246
|
+
run: n((e, ...t) => (g(), p.current > 0 ? (--p.current, u(p.current), _(), e(...t), !0) : (f.current?.(), _(), !1)), [g, _]),
|
|
247
|
+
reset: v,
|
|
102
248
|
remaining: l,
|
|
103
249
|
isRateLimited: l === 0
|
|
104
250
|
};
|
|
105
251
|
}
|
|
106
252
|
//#endregion
|
|
107
|
-
//#region src/performance/
|
|
108
|
-
|
|
253
|
+
//#region src/performance/useRateLimiter/useRateLimitedCallback.ts
|
|
254
|
+
var C = globalThis.process?.env?.NODE_ENV !== "production";
|
|
255
|
+
function w(e, t, i, a) {
|
|
256
|
+
C && typeof e != "function" && console.warn(`[useRateLimitedCallback] Expected \`func\` to be a function, received ${typeof e}.`);
|
|
109
257
|
let s = o(e);
|
|
110
258
|
r(() => {
|
|
111
259
|
s.current = e;
|
|
112
260
|
}, [e]);
|
|
113
|
-
let { run: c,
|
|
261
|
+
let { run: c, reset: l, remaining: u, isRateLimited: d } = S(t, i, a);
|
|
114
262
|
return {
|
|
115
|
-
rateLimitedFunc: n((...e) =>
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
isRateLimited: u
|
|
263
|
+
rateLimitedFunc: n((...e) => c(s.current, ...e), [c]),
|
|
264
|
+
reset: l,
|
|
265
|
+
remaining: u,
|
|
266
|
+
isRateLimited: d
|
|
120
267
|
};
|
|
121
268
|
}
|
|
122
269
|
//#endregion
|
|
123
|
-
//#region src/performance/
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
270
|
+
//#region src/performance/useRateLimiter/useRateLimitedState.ts
|
|
271
|
+
var T = globalThis.process?.env?.NODE_ENV !== "production";
|
|
272
|
+
function E(e, t, r, i = {}) {
|
|
273
|
+
T && i.equalityFn !== void 0 && typeof i.equalityFn != "function" && console.warn("[useRateLimitedState] `equalityFn` must be a function — falling back to `Object.is`.");
|
|
274
|
+
let a = typeof i.equalityFn == "function" ? i.equalityFn : Object.is, [o, c] = s(e), l = n((e) => {
|
|
275
|
+
c((t) => {
|
|
276
|
+
let n = g(e) ? e(t) : e;
|
|
277
|
+
return a(t, n) ? t : n;
|
|
278
|
+
});
|
|
279
|
+
}, [a]), { rateLimitedFunc: u, reset: d, remaining: f, isRateLimited: p } = w(l, t, r, i);
|
|
280
|
+
return [
|
|
281
|
+
o,
|
|
282
|
+
n((e) => u(e), [u]),
|
|
283
|
+
{
|
|
284
|
+
remaining: f,
|
|
285
|
+
isRateLimited: p,
|
|
286
|
+
reset: d,
|
|
287
|
+
forceSetValue: n((e) => {
|
|
288
|
+
l(e);
|
|
289
|
+
}, [l])
|
|
290
|
+
}
|
|
291
|
+
];
|
|
292
|
+
}
|
|
293
|
+
//#endregion
|
|
294
|
+
//#region src/performance/useRateLimiter/useRateLimitedValue.ts
|
|
295
|
+
var D = globalThis.process?.env?.NODE_ENV !== "production";
|
|
296
|
+
function O(e, t, n, i = {}) {
|
|
297
|
+
D && i.equalityFn !== void 0 && typeof i.equalityFn != "function" && console.warn("[useRateLimitedValue] `equalityFn` must be a function — falling back to `Object.is`.");
|
|
298
|
+
let a = typeof i.equalityFn == "function" ? i.equalityFn : Object.is, [c, l] = s(e), { rateLimitedFunc: u, reset: d, remaining: f, isRateLimited: p } = w((e) => {
|
|
299
|
+
l((t) => a(t, e) ? t : e);
|
|
300
|
+
}, t, n, i), m = o(!0);
|
|
301
|
+
return r(() => {
|
|
302
|
+
if (m.current) {
|
|
303
|
+
m.current = !1;
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
u(e);
|
|
307
|
+
}, [e, u]), [c, {
|
|
308
|
+
remaining: f,
|
|
309
|
+
isRateLimited: p,
|
|
310
|
+
reset: d
|
|
311
|
+
}];
|
|
312
|
+
}
|
|
313
|
+
//#endregion
|
|
314
|
+
//#region src/performance/useThrottler/useThrottler.ts
|
|
315
|
+
var k = globalThis.process?.env?.NODE_ENV !== "production";
|
|
316
|
+
function A(e, t = {}) {
|
|
317
|
+
let i = Math.max(0, Number(e) || 0);
|
|
318
|
+
k && (typeof e != "number" || !Number.isFinite(e) || e < 0) && console.warn(`[useThrottler] Received an invalid \`delay\` (${String(e)}) — falling back to ${i}ms.`);
|
|
319
|
+
let [a, c] = s(!1), l = t?.leading ?? !0, u = t?.trailing ?? !0;
|
|
320
|
+
k && !l && !u && console.warn("[useThrottler] Both `leading` and `trailing` are false — the throttled function will never be invoked.");
|
|
127
321
|
let d = o(null), f = o(null), p = o(null), m = o(-1), h = n(() => {
|
|
128
|
-
p.current
|
|
322
|
+
p.current !== null && (clearTimeout(p.current), p.current = null), m.current = -1, f.current = null, d.current = null, c(!1);
|
|
129
323
|
}, []), g = n(() => {
|
|
130
|
-
|
|
324
|
+
let e = d.current, t = f.current;
|
|
325
|
+
e === null || t === null || (p.current !== null && (clearTimeout(p.current), p.current = null), m.current = l ? Date.now() : -1, f.current = null, d.current = null, c(!1), e(...t));
|
|
131
326
|
}, [l]);
|
|
132
|
-
return r(() =>
|
|
133
|
-
h();
|
|
134
|
-
}, [h]), {
|
|
327
|
+
return r(() => h, [h]), {
|
|
135
328
|
run: n((e, ...t) => {
|
|
136
|
-
|
|
329
|
+
if (!l && !u) return;
|
|
137
330
|
let n = Date.now();
|
|
138
|
-
if (f.current = t, d.current = e, m.current === -1 ? l : n - m.current >= i)
|
|
139
|
-
|
|
331
|
+
if (f.current = t, d.current = e, m.current === -1 ? l : n - m.current >= i) {
|
|
332
|
+
p.current !== null && (clearTimeout(p.current), p.current = null);
|
|
333
|
+
let e = d.current, t = f.current;
|
|
334
|
+
m.current = n, f.current = null, c(!1), e(...t);
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
if (p.current === null) {
|
|
140
338
|
let e = m.current === -1 ? 0 : n - m.current, t = i - e;
|
|
141
339
|
p.current = setTimeout(() => {
|
|
142
|
-
|
|
143
|
-
|
|
340
|
+
p.current = null;
|
|
341
|
+
let e = d.current, t = f.current;
|
|
342
|
+
f.current = null, d.current = null, c(!1), u && e !== null && t !== null ? (m.current = l ? Date.now() : -1, e(...t)) : m.current = -1;
|
|
343
|
+
}, Math.max(0, t));
|
|
144
344
|
}
|
|
345
|
+
c(u);
|
|
145
346
|
}, [
|
|
146
347
|
i,
|
|
147
348
|
l,
|
|
@@ -153,13 +354,15 @@ function m(e, t = {}) {
|
|
|
153
354
|
};
|
|
154
355
|
}
|
|
155
356
|
//#endregion
|
|
156
|
-
//#region src/performance/
|
|
157
|
-
|
|
357
|
+
//#region src/performance/useThrottler/useThrottledCallback.ts
|
|
358
|
+
var j = globalThis.process?.env?.NODE_ENV !== "production";
|
|
359
|
+
function M(e, t, i = {}) {
|
|
360
|
+
j && typeof e != "function" && console.warn(`[useThrottledCallback] Expected \`func\` to be a function, received ${typeof e}.`);
|
|
158
361
|
let a = o(e);
|
|
159
362
|
r(() => {
|
|
160
363
|
a.current = e;
|
|
161
364
|
}, [e]);
|
|
162
|
-
let { run: s, cancel: c, flush: l, isPending: u } =
|
|
365
|
+
let { run: s, cancel: c, flush: l, isPending: u } = A(t, i);
|
|
163
366
|
return {
|
|
164
367
|
throttledFunc: n((...e) => {
|
|
165
368
|
s(a.current, ...e);
|
|
@@ -170,35 +373,53 @@ function h(e, t, i = {}) {
|
|
|
170
373
|
};
|
|
171
374
|
}
|
|
172
375
|
//#endregion
|
|
173
|
-
//#region src/performance/
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
376
|
+
//#region src/performance/useThrottler/useThrottledState.ts
|
|
377
|
+
var N = globalThis.process?.env?.NODE_ENV !== "production";
|
|
378
|
+
function P(e, t, r = {}) {
|
|
379
|
+
N && r.equalityFn !== void 0 && typeof r.equalityFn != "function" && console.warn("[useThrottledState] `equalityFn` must be a function — falling back to `Object.is`.");
|
|
380
|
+
let i = typeof r.equalityFn == "function" ? r.equalityFn : Object.is, [a, c] = s(e), l = o(a), { throttledFunc: u, cancel: d, flush: f, isPending: p } = M(n((e) => {
|
|
381
|
+
c((t) => i(t, e) ? t : e);
|
|
382
|
+
}, [i]), t, r);
|
|
178
383
|
return [
|
|
179
|
-
r,
|
|
180
384
|
a,
|
|
385
|
+
n((e) => {
|
|
386
|
+
let t = g(e) ? e(l.current) : e;
|
|
387
|
+
l.current = t, u(t);
|
|
388
|
+
}, [u]),
|
|
181
389
|
{
|
|
182
|
-
isPending:
|
|
183
|
-
cancel:
|
|
184
|
-
|
|
185
|
-
|
|
390
|
+
isPending: p,
|
|
391
|
+
cancel: n(() => {
|
|
392
|
+
d(), c((e) => (l.current = e, e));
|
|
393
|
+
}, [d]),
|
|
394
|
+
flush: f,
|
|
395
|
+
forceSetValue: n((e) => {
|
|
396
|
+
d(), c((t) => {
|
|
397
|
+
let n = g(e) ? e(t) : e;
|
|
398
|
+
return l.current = n, n;
|
|
399
|
+
});
|
|
400
|
+
}, [d])
|
|
186
401
|
}
|
|
187
402
|
];
|
|
188
403
|
}
|
|
189
404
|
//#endregion
|
|
190
|
-
//#region src/performance/
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
405
|
+
//#region src/performance/useThrottler/useThrottledValue.ts
|
|
406
|
+
var F = globalThis.process?.env?.NODE_ENV !== "production";
|
|
407
|
+
function I(e, t, n = {}) {
|
|
408
|
+
F && n.equalityFn !== void 0 && typeof n.equalityFn != "function" && console.warn("[useThrottledValue] `equalityFn` must be a function — falling back to `Object.is`.");
|
|
409
|
+
let i = typeof n.equalityFn == "function" ? n.equalityFn : Object.is, [a, o] = s(e), { throttledFunc: c, cancel: l, flush: u, isPending: d } = M((e) => {
|
|
410
|
+
o((t) => i(t, e) ? t : e);
|
|
194
411
|
}, t, n);
|
|
195
412
|
return r(() => {
|
|
196
|
-
|
|
197
|
-
}, [e,
|
|
413
|
+
c(e);
|
|
414
|
+
}, [e, c]), [a, {
|
|
415
|
+
isPending: d,
|
|
416
|
+
cancel: l,
|
|
417
|
+
flush: u
|
|
418
|
+
}];
|
|
198
419
|
}
|
|
199
420
|
//#endregion
|
|
200
421
|
//#region src/shared/virtualShared/offsetCache.ts
|
|
201
|
-
var
|
|
422
|
+
var L = class {
|
|
202
423
|
_offsets = /* @__PURE__ */ new Float64Array();
|
|
203
424
|
_count = 0;
|
|
204
425
|
initializeOffsets(e, t) {
|
|
@@ -267,42 +488,42 @@ var v = class {
|
|
|
267
488
|
};
|
|
268
489
|
//#endregion
|
|
269
490
|
//#region src/shared/virtualShared/utils.ts
|
|
270
|
-
function
|
|
491
|
+
function R(e, t) {
|
|
271
492
|
let n = typeof t == "function" ? t(e) : t, r = Number(n);
|
|
272
493
|
return Number.isFinite(r) && r >= 0 ? r : 0;
|
|
273
494
|
}
|
|
274
|
-
function
|
|
495
|
+
function z(e, t, n) {
|
|
275
496
|
if (e <= 0) return 0;
|
|
276
497
|
if (typeof t == "number") return e * Math.max(0, t);
|
|
277
498
|
if (n) return n.getItemStartOffset(e);
|
|
278
499
|
let r = 0;
|
|
279
|
-
for (let n = 0; n < e; n++) r +=
|
|
500
|
+
for (let n = 0; n < e; n++) r += R(n, t);
|
|
280
501
|
return r;
|
|
281
502
|
}
|
|
282
|
-
function
|
|
503
|
+
function B(e, t, n) {
|
|
283
504
|
if (e <= 0) return 0;
|
|
284
505
|
if (typeof t == "number") return e * Math.max(0, t);
|
|
285
506
|
if (n) return n.getTotalSize();
|
|
286
507
|
let r = 0;
|
|
287
|
-
for (let n = 0; n < e; n++) r +=
|
|
508
|
+
for (let n = 0; n < e; n++) r += R(n, t);
|
|
288
509
|
return r;
|
|
289
510
|
}
|
|
290
|
-
function
|
|
511
|
+
function V(e, t) {
|
|
291
512
|
if (!e) return 0;
|
|
292
513
|
let n = t === "vertical";
|
|
293
514
|
return e instanceof Window ? n ? document.documentElement.clientHeight : document.documentElement.clientWidth : e instanceof Document ? n ? e.documentElement.clientHeight : e.documentElement.clientWidth : n ? e.clientHeight : e.clientWidth;
|
|
294
515
|
}
|
|
295
|
-
function
|
|
516
|
+
function H(e, t) {
|
|
296
517
|
if (!e) return 0;
|
|
297
518
|
let n = t === "vertical";
|
|
298
519
|
return e instanceof Window ? n ? e.scrollY : e.scrollX : e instanceof Document ? n ? e.documentElement.scrollTop : e.documentElement.scrollLeft : n ? e.scrollTop : e.scrollLeft;
|
|
299
520
|
}
|
|
300
|
-
function
|
|
521
|
+
function U(e) {
|
|
301
522
|
return e ? e instanceof Window ? document.documentElement : e instanceof Document ? e.scrollingElement ?? e.documentElement : e : null;
|
|
302
523
|
}
|
|
303
524
|
//#endregion
|
|
304
525
|
//#region src/performance/useVirtualGrid/utils.ts
|
|
305
|
-
function
|
|
526
|
+
function W(e, t, n, r, i, a) {
|
|
306
527
|
if (n <= 0 || t <= 0) return {
|
|
307
528
|
startIndex: 0,
|
|
308
529
|
endIndex: -1
|
|
@@ -318,7 +539,7 @@ function T(e, t, n, r, i, a) {
|
|
|
318
539
|
o = 0, s = -1;
|
|
319
540
|
let i = 0, a = !1;
|
|
320
541
|
for (let c = 0; c < n; c++) {
|
|
321
|
-
let n =
|
|
542
|
+
let n = R(c, r), l = i + n;
|
|
322
543
|
if (!a && l > e && (o = c, a = !0), a) if (i < e + t) s = c;
|
|
323
544
|
else break;
|
|
324
545
|
i += n;
|
|
@@ -330,8 +551,8 @@ function T(e, t, n, r, i, a) {
|
|
|
330
551
|
endIndex: s
|
|
331
552
|
};
|
|
332
553
|
}
|
|
333
|
-
function
|
|
334
|
-
let s = o ? o.getItemSize(e) :
|
|
554
|
+
function G(e, t, n, r, i, a, o) {
|
|
555
|
+
let s = o ? o.getItemSize(e) : R(e, a), c = z(e, a, o), l = c + s, u = Math.max(0, r - n), d;
|
|
335
556
|
switch (t) {
|
|
336
557
|
case "start":
|
|
337
558
|
d = c;
|
|
@@ -351,71 +572,71 @@ function E(e, t, n, r, i, a, o) {
|
|
|
351
572
|
}
|
|
352
573
|
//#endregion
|
|
353
574
|
//#region src/performance/useVirtualGrid/useVirtualGrid.ts
|
|
354
|
-
function
|
|
355
|
-
let { rowCount: c, colCount:
|
|
575
|
+
function K(t) {
|
|
576
|
+
let { rowCount: c, colCount: l, estimateRowHeight: u, estimateColumnWidth: d, getScrollElement: f, overscanRows: p = 3, overscanCols: m = 3, scrollingDelay: g = 150, initialViewportHeight: _ = 0, initialViewportWidth: v = 0, initialScrollTop: y, initialScrollLeft: b, initialScrollRow: x, initialScrollCol: S, itemKey: C } = t, w = Math.max(0, Math.trunc(Number(c)) || 0), T = Math.max(0, Math.trunc(Number(l)) || 0), E = Math.max(0, Math.trunc(Number(p)) || 0), D = Math.max(0, Math.trunc(Number(m)) || 0), O = o(t);
|
|
356
577
|
i(() => {
|
|
357
|
-
|
|
578
|
+
O.current = t;
|
|
358
579
|
});
|
|
359
|
-
let
|
|
580
|
+
let k = a(() => {
|
|
581
|
+
if (typeof u != "function") return;
|
|
582
|
+
let e = new L();
|
|
583
|
+
return e.initializeOffsets(w, u), e;
|
|
584
|
+
}, [w, u]), A = a(() => {
|
|
360
585
|
if (typeof d != "function") return;
|
|
361
|
-
let e = new
|
|
362
|
-
return e.initializeOffsets(
|
|
363
|
-
}, [
|
|
364
|
-
if (typeof f != "function") return;
|
|
365
|
-
let e = new v();
|
|
366
|
-
return e.initializeOffsets(P, f), e;
|
|
367
|
-
}, [P, f]), B = o(R), V = o(z);
|
|
586
|
+
let e = new L();
|
|
587
|
+
return e.initializeOffsets(T, d), e;
|
|
588
|
+
}, [T, d]), j = o(k), M = o(A);
|
|
368
589
|
i(() => {
|
|
369
|
-
|
|
370
|
-
}, [
|
|
371
|
-
|
|
372
|
-
}, [
|
|
373
|
-
let [
|
|
374
|
-
if (typeof
|
|
375
|
-
if (typeof
|
|
376
|
-
let e = Math.max(0, Math.min(Math.trunc(Number(
|
|
377
|
-
return
|
|
590
|
+
j.current = k;
|
|
591
|
+
}, [k]), i(() => {
|
|
592
|
+
M.current = A;
|
|
593
|
+
}, [A]);
|
|
594
|
+
let [N, P] = s(() => {
|
|
595
|
+
if (typeof y == "number") return Math.max(0, y);
|
|
596
|
+
if (typeof x == "number" && w > 0) {
|
|
597
|
+
let e = Math.max(0, Math.min(Math.trunc(Number(x)) || 0, w - 1));
|
|
598
|
+
return k ? k.getItemStartOffset(e) : z(e, u);
|
|
378
599
|
}
|
|
379
600
|
return 0;
|
|
380
|
-
}), [
|
|
381
|
-
if (typeof
|
|
382
|
-
if (typeof
|
|
383
|
-
let e = Math.max(0, Math.min(Math.trunc(Number(
|
|
384
|
-
return
|
|
601
|
+
}), [F, I] = s(() => {
|
|
602
|
+
if (typeof b == "number") return Math.max(0, b);
|
|
603
|
+
if (typeof S == "number" && T > 0) {
|
|
604
|
+
let e = Math.max(0, Math.min(Math.trunc(Number(S)) || 0, T - 1));
|
|
605
|
+
return A ? A.getItemStartOffset(e) : z(e, d);
|
|
385
606
|
}
|
|
386
607
|
return 0;
|
|
387
|
-
}), [K, q] = s(!1), [, J] = s({}), Y = o(!1), { debouncedFunc: X } =
|
|
608
|
+
}), [K, q] = s(!1), [, J] = s({}), Y = o(!1), { debouncedFunc: X } = h(() => q(!1), g), Z = f();
|
|
388
609
|
r(() => {
|
|
389
610
|
if (!Z) return;
|
|
390
611
|
if (!Y.current) {
|
|
391
612
|
Y.current = !0;
|
|
392
|
-
let e = typeof
|
|
613
|
+
let e = typeof y == "number" || typeof x == "number", t = typeof b == "number" || typeof S == "number";
|
|
393
614
|
if (e || t) {
|
|
394
|
-
let n =
|
|
615
|
+
let n = U(Z);
|
|
395
616
|
n && n.scrollTo({
|
|
396
|
-
...e && { top:
|
|
397
|
-
...t && { left:
|
|
617
|
+
...e && { top: N },
|
|
618
|
+
...t && { left: F },
|
|
398
619
|
behavior: "auto"
|
|
399
620
|
});
|
|
400
621
|
return;
|
|
401
622
|
}
|
|
402
623
|
}
|
|
403
|
-
let e =
|
|
404
|
-
|
|
624
|
+
let e = H(Z, "vertical"), t = H(Z, "horizontal");
|
|
625
|
+
P((t) => t === e ? t : e), I((e) => e === t ? e : t);
|
|
405
626
|
}, [
|
|
406
627
|
Z,
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
628
|
+
y,
|
|
629
|
+
b,
|
|
630
|
+
x,
|
|
631
|
+
S,
|
|
632
|
+
N,
|
|
633
|
+
F
|
|
413
634
|
]);
|
|
414
635
|
function ee() {
|
|
415
|
-
let { getScrollElement: e, scrollingDelay: t } =
|
|
636
|
+
let { getScrollElement: e, scrollingDelay: t } = O.current, n = e();
|
|
416
637
|
if (!n) return;
|
|
417
|
-
let r =
|
|
418
|
-
|
|
638
|
+
let r = H(n, "vertical"), i = H(n, "horizontal");
|
|
639
|
+
P(r), I(i), (t ?? 150) > 0 && (q(!0), X());
|
|
419
640
|
}
|
|
420
641
|
e("scroll", ee, {
|
|
421
642
|
target: Z,
|
|
@@ -427,13 +648,13 @@ function D(t) {
|
|
|
427
648
|
let t = new ResizeObserver(e), n = Z instanceof Document ? Z.documentElement : Z;
|
|
428
649
|
return t.observe(n), () => t.disconnect();
|
|
429
650
|
}, [Z]);
|
|
430
|
-
let te =
|
|
651
|
+
let te = V(Z, "vertical") || _, ne = V(Z, "horizontal") || v, re = B(w, u, k), ie = B(T, d, A), { startIndex: Q, endIndex: ae } = W(N, te, w, u, E, k), { startIndex: $, endIndex: oe } = W(F, ne, T, d, D, A), se = [];
|
|
431
652
|
if (Q <= ae && $ <= oe) {
|
|
432
|
-
let e =
|
|
653
|
+
let e = k ? k.getItemStartOffset(Q) : z(Q, u);
|
|
433
654
|
for (let t = Q; t <= ae; t++) {
|
|
434
|
-
let n =
|
|
655
|
+
let n = k ? k.getItemSize(t) : R(t, u), r = A ? A.getItemStartOffset($) : z($, d);
|
|
435
656
|
for (let i = $; i <= oe; i++) {
|
|
436
|
-
let a =
|
|
657
|
+
let a = A ? A.getItemSize(i) : R(i, d), o = C ? C(t, i) : `${t}:${i}`;
|
|
437
658
|
se.push({
|
|
438
659
|
key: o,
|
|
439
660
|
rowIndex: t,
|
|
@@ -453,9 +674,9 @@ function D(t) {
|
|
|
453
674
|
totalWidth: ie,
|
|
454
675
|
isScrolling: K,
|
|
455
676
|
scrollToOffset: n((e, t) => {
|
|
456
|
-
let { getScrollElement: n, initialViewportHeight: r, initialViewportWidth: i } =
|
|
677
|
+
let { getScrollElement: n, initialViewportHeight: r, initialViewportWidth: i } = O.current, a = n();
|
|
457
678
|
if (!a) return;
|
|
458
|
-
let { rowCount: o, colCount: s, estimateRowHeight: c, estimateColumnWidth: l } =
|
|
679
|
+
let { rowCount: o, colCount: s, estimateRowHeight: c, estimateColumnWidth: l } = O.current, u = Math.max(0, Math.trunc(Number(o)) || 0), d = Math.max(0, Math.trunc(Number(s)) || 0), f = B(u, c, j.current), p = B(d, l, M.current), m = V(a, "vertical") || r || 0, h = V(a, "horizontal") || i || 0, g = Math.max(0, Math.min(e.top, Math.max(0, f - m))), _ = Math.max(0, Math.min(e.left, Math.max(0, p - h))), v = U(a);
|
|
459
680
|
v && v.scrollTo({
|
|
460
681
|
top: g,
|
|
461
682
|
left: _,
|
|
@@ -463,36 +684,36 @@ function D(t) {
|
|
|
463
684
|
});
|
|
464
685
|
}, []),
|
|
465
686
|
scrollToRow: n((e, t) => {
|
|
466
|
-
let { getScrollElement: n, rowCount: r, estimateRowHeight: i, initialViewportHeight: a } =
|
|
687
|
+
let { getScrollElement: n, rowCount: r, estimateRowHeight: i, initialViewportHeight: a } = O.current, o = n();
|
|
467
688
|
if (!o) return;
|
|
468
689
|
let s = Math.max(0, Math.trunc(Number(r)) || 0);
|
|
469
690
|
if (s === 0) return;
|
|
470
|
-
let c = Math.max(0, Math.min(Math.trunc(Number(e)) || 0, s - 1)), l =
|
|
691
|
+
let c = Math.max(0, Math.min(Math.trunc(Number(e)) || 0, s - 1)), l = V(o, "vertical") || a || 0, u = B(s, i, j.current), d = H(o, "vertical"), f = G(c, t?.align ?? "auto", l, u, d, i, j.current), p = U(o);
|
|
471
692
|
p && p.scrollTo({
|
|
472
693
|
top: f,
|
|
473
694
|
behavior: t?.smooth === !0 ? "smooth" : "auto"
|
|
474
695
|
});
|
|
475
696
|
}, []),
|
|
476
697
|
scrollToColumn: n((e, t) => {
|
|
477
|
-
let { getScrollElement: n, colCount: r, estimateColumnWidth: i, initialViewportWidth: a } =
|
|
698
|
+
let { getScrollElement: n, colCount: r, estimateColumnWidth: i, initialViewportWidth: a } = O.current, o = n();
|
|
478
699
|
if (!o) return;
|
|
479
700
|
let s = Math.max(0, Math.trunc(Number(r)) || 0);
|
|
480
701
|
if (s === 0) return;
|
|
481
|
-
let c = Math.max(0, Math.min(Math.trunc(Number(e)) || 0, s - 1)), l =
|
|
702
|
+
let c = Math.max(0, Math.min(Math.trunc(Number(e)) || 0, s - 1)), l = V(o, "horizontal") || a || 0, u = B(s, i, M.current), d = H(o, "horizontal"), f = G(c, t?.align ?? "auto", l, u, d, i, M.current), p = U(o);
|
|
482
703
|
p && p.scrollTo({
|
|
483
704
|
left: f,
|
|
484
705
|
behavior: t?.smooth === !0 ? "smooth" : "auto"
|
|
485
706
|
});
|
|
486
707
|
}, []),
|
|
487
708
|
scrollToCell: n((e, t, n) => {
|
|
488
|
-
let { getScrollElement: r, rowCount: i, colCount: a, estimateRowHeight: o, estimateColumnWidth: s, initialViewportHeight: c, initialViewportWidth: l } =
|
|
709
|
+
let { getScrollElement: r, rowCount: i, colCount: a, estimateRowHeight: o, estimateColumnWidth: s, initialViewportHeight: c, initialViewportWidth: l } = O.current, u = r();
|
|
489
710
|
if (!u) return;
|
|
490
711
|
let d = Math.max(0, Math.trunc(Number(i)) || 0), f = Math.max(0, Math.trunc(Number(a)) || 0);
|
|
491
712
|
if (d === 0 || f === 0) return;
|
|
492
|
-
let p = Math.max(0, Math.min(Math.trunc(Number(e)) || 0, d - 1)), m = Math.max(0, Math.min(Math.trunc(Number(t)) || 0, f - 1)), h =
|
|
493
|
-
|
|
494
|
-
top:
|
|
495
|
-
left:
|
|
713
|
+
let p = Math.max(0, Math.min(Math.trunc(Number(e)) || 0, d - 1)), m = Math.max(0, Math.min(Math.trunc(Number(t)) || 0, f - 1)), h = V(u, "vertical") || c || 0, g = V(u, "horizontal") || l || 0, _ = B(d, o, j.current), v = B(f, s, M.current), y = H(u, "vertical"), b = H(u, "horizontal"), x = G(p, n?.rowAlign ?? "auto", h, _, y, o, j.current), S = G(m, n?.colAlign ?? "auto", g, v, b, s, M.current), C = U(u);
|
|
714
|
+
C && C.scrollTo({
|
|
715
|
+
top: x,
|
|
716
|
+
left: S,
|
|
496
717
|
behavior: n?.smooth === !0 ? "smooth" : "auto"
|
|
497
718
|
});
|
|
498
719
|
}, [])
|
|
@@ -500,13 +721,13 @@ function D(t) {
|
|
|
500
721
|
}
|
|
501
722
|
//#endregion
|
|
502
723
|
//#region src/performance/useVirtualList/utils.ts
|
|
503
|
-
function
|
|
504
|
-
return
|
|
724
|
+
function q(e, t) {
|
|
725
|
+
return V(e, t ? "horizontal" : "vertical");
|
|
505
726
|
}
|
|
506
|
-
function
|
|
507
|
-
return
|
|
727
|
+
function J(e, t) {
|
|
728
|
+
return H(e, t ? "horizontal" : "vertical");
|
|
508
729
|
}
|
|
509
|
-
function
|
|
730
|
+
function Y(e, t, n, r, i, a, o, s) {
|
|
510
731
|
if (r <= 0 || t <= 0) return {
|
|
511
732
|
startIndex: 0,
|
|
512
733
|
endIndex: -1
|
|
@@ -526,7 +747,7 @@ function A(e, t, n, r, i, a, o, s) {
|
|
|
526
747
|
c = r, l = -1;
|
|
527
748
|
let a = 0;
|
|
528
749
|
for (let o = 0; o < r; o++) {
|
|
529
|
-
let r =
|
|
750
|
+
let r = R(o, i), s = n - a - r;
|
|
530
751
|
if (n - a <= e) break;
|
|
531
752
|
s < e + t && (o < c && (c = o), l = o), a += r;
|
|
532
753
|
}
|
|
@@ -535,7 +756,7 @@ function A(e, t, n, r, i, a, o, s) {
|
|
|
535
756
|
c = 0, l = -1;
|
|
536
757
|
let n = 0, a = !1;
|
|
537
758
|
for (let o = 0; o < r; o++) {
|
|
538
|
-
let r =
|
|
759
|
+
let r = R(o, i), s = n + r;
|
|
539
760
|
if (!a && s > e && (c = o, a = !0), a) if (n < e + t) l = o;
|
|
540
761
|
else break;
|
|
541
762
|
n += r;
|
|
@@ -547,8 +768,8 @@ function A(e, t, n, r, i, a, o, s) {
|
|
|
547
768
|
endIndex: l
|
|
548
769
|
};
|
|
549
770
|
}
|
|
550
|
-
function
|
|
551
|
-
let c = s ? s.getItemSize(e) :
|
|
771
|
+
function X(e, t, n, r, i, a, o, s) {
|
|
772
|
+
let c = s ? s.getItemSize(e) : R(e, a), l = z(e, a, s), u = o ? r - l - c : l, d = u + c, f = Math.max(0, r - n), p;
|
|
552
773
|
switch (t) {
|
|
553
774
|
case "start":
|
|
554
775
|
p = o ? Math.max(0, d - n) : u;
|
|
@@ -568,79 +789,79 @@ function j(e, t, n, r, i, a, o, s) {
|
|
|
568
789
|
}
|
|
569
790
|
//#endregion
|
|
570
791
|
//#region src/performance/useVirtualList/useVirtualList.ts
|
|
571
|
-
function
|
|
572
|
-
let { count:
|
|
792
|
+
function Z(c) {
|
|
793
|
+
let { count: l, estimateSize: u, getScrollElement: d, overscan: f = 3, horizontal: p = !1, reverse: m = !1, scrollingDelay: g = 150, initialViewportSize: _ = 0, data: v, itemKey: y, initialOffset: b, initialScrollIndex: x } = c, S = Math.max(0, Math.trunc(Number(l)) || 0), C = Math.max(0, Math.trunc(Number(f)) || 0), w = o(c);
|
|
573
794
|
i(() => {
|
|
574
|
-
|
|
795
|
+
w.current = c;
|
|
575
796
|
});
|
|
576
|
-
let
|
|
577
|
-
if (typeof
|
|
578
|
-
let e = new
|
|
579
|
-
return e.initializeOffsets(
|
|
580
|
-
}, [
|
|
797
|
+
let T = a(() => {
|
|
798
|
+
if (typeof u != "function") return;
|
|
799
|
+
let e = new L();
|
|
800
|
+
return e.initializeOffsets(S, u), e;
|
|
801
|
+
}, [S, u]), E = o(T);
|
|
581
802
|
i(() => {
|
|
582
|
-
|
|
583
|
-
}, [
|
|
584
|
-
let [
|
|
585
|
-
if (typeof
|
|
586
|
-
if (typeof
|
|
587
|
-
let e = Math.max(0, Math.min(Math.trunc(Number(
|
|
588
|
-
if (
|
|
589
|
-
let n =
|
|
803
|
+
E.current = T;
|
|
804
|
+
}, [T]);
|
|
805
|
+
let [D, O] = s(() => {
|
|
806
|
+
if (typeof b == "number") return Math.max(0, b);
|
|
807
|
+
if (typeof x == "number" && S > 0) {
|
|
808
|
+
let e = Math.max(0, Math.min(Math.trunc(Number(x)) || 0, S - 1)), t = T ? T.getItemStartOffset(e) : z(e, u);
|
|
809
|
+
if (m) {
|
|
810
|
+
let n = T ? T.getItemSize(e) : R(e, u), r = B(S, u, T);
|
|
590
811
|
return Math.max(0, r - t - n);
|
|
591
812
|
}
|
|
592
813
|
return t;
|
|
593
814
|
}
|
|
594
815
|
return 0;
|
|
595
|
-
}), [
|
|
816
|
+
}), [k, A] = s(!1), [, j] = s({}), M = o(!1), { debouncedFunc: N } = h(() => A(!1), g), P = d();
|
|
596
817
|
r(() => {
|
|
597
|
-
if (!
|
|
598
|
-
if (!
|
|
599
|
-
let e =
|
|
818
|
+
if (!P) return;
|
|
819
|
+
if (!M.current && (M.current = !0, typeof b == "number" || typeof x == "number")) {
|
|
820
|
+
let e = U(P);
|
|
600
821
|
e && e.scrollTo({
|
|
601
|
-
[
|
|
822
|
+
[p ? "left" : "top"]: D,
|
|
602
823
|
behavior: "auto"
|
|
603
824
|
});
|
|
604
825
|
return;
|
|
605
826
|
}
|
|
606
|
-
let e =
|
|
607
|
-
|
|
827
|
+
let e = J(P, p);
|
|
828
|
+
O((t) => t === e ? t : e);
|
|
608
829
|
}, [
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
830
|
+
P,
|
|
831
|
+
p,
|
|
832
|
+
b,
|
|
833
|
+
x,
|
|
834
|
+
D
|
|
614
835
|
]);
|
|
615
|
-
function
|
|
616
|
-
let { getScrollElement: e, horizontal: t } =
|
|
836
|
+
function F() {
|
|
837
|
+
let { getScrollElement: e, horizontal: t } = w.current, n = e();
|
|
617
838
|
if (!n) return;
|
|
618
|
-
let r =
|
|
619
|
-
|
|
839
|
+
let r = J(n, t ?? !1);
|
|
840
|
+
O(r), (w.current.scrollingDelay ?? 150) > 0 && (A(!0), N());
|
|
620
841
|
}
|
|
621
|
-
e("scroll",
|
|
622
|
-
target:
|
|
842
|
+
e("scroll", F, {
|
|
843
|
+
target: P,
|
|
623
844
|
passive: !0
|
|
624
845
|
}), r(() => {
|
|
625
|
-
if (!
|
|
626
|
-
let e = () =>
|
|
627
|
-
if (
|
|
628
|
-
let t = new ResizeObserver(e), n =
|
|
846
|
+
if (!P) return;
|
|
847
|
+
let e = () => j({});
|
|
848
|
+
if (P instanceof Window) return P.addEventListener("resize", e), () => P.removeEventListener("resize", e);
|
|
849
|
+
let t = new ResizeObserver(e), n = P instanceof Document ? P.documentElement : P;
|
|
629
850
|
return t.observe(n), () => t.disconnect();
|
|
630
|
-
}, [
|
|
631
|
-
let
|
|
632
|
-
if (
|
|
633
|
-
let e =
|
|
634
|
-
for (let n =
|
|
635
|
-
let r =
|
|
636
|
-
if (
|
|
637
|
-
if (typeof
|
|
638
|
-
else if (
|
|
639
|
-
let e = t(
|
|
851
|
+
}, [P]);
|
|
852
|
+
let I = q(P, p) || _, V = B(S, u, T), { startIndex: H, endIndex: W } = Y(D, I, V, S, u, C, m, T), G = [];
|
|
853
|
+
if (H <= W) {
|
|
854
|
+
let e = T ? T.getItemStartOffset(H) : z(H, u);
|
|
855
|
+
for (let n = H; n <= W; n++) {
|
|
856
|
+
let r = T ? T.getItemSize(n) : R(n, u), i = m ? V - e - r : e, a = n;
|
|
857
|
+
if (y) {
|
|
858
|
+
if (typeof y == "function") a = y(n, v?.[n]);
|
|
859
|
+
else if (v && v[n] !== void 0 && v[n] !== null) {
|
|
860
|
+
let e = t(v[n], y);
|
|
640
861
|
(typeof e == "string" || typeof e == "number") && (a = e);
|
|
641
862
|
}
|
|
642
863
|
}
|
|
643
|
-
|
|
864
|
+
G.push({
|
|
644
865
|
key: a,
|
|
645
866
|
index: n,
|
|
646
867
|
size: r,
|
|
@@ -648,30 +869,30 @@ function M(c) {
|
|
|
648
869
|
}), e += r;
|
|
649
870
|
}
|
|
650
871
|
}
|
|
651
|
-
let
|
|
652
|
-
let { getScrollElement: n, horizontal: r, count: i, estimateSize: a } =
|
|
872
|
+
let K = n((e, t) => {
|
|
873
|
+
let { getScrollElement: n, horizontal: r, count: i, estimateSize: a } = w.current, o = n();
|
|
653
874
|
if (!o) return;
|
|
654
|
-
let s = r ?? !1, c =
|
|
875
|
+
let s = r ?? !1, c = q(o, s) || w.current.initialViewportSize || 0, l = E.current, u = B(Math.max(0, Math.trunc(Number(i)) || 0), a, l), d = Math.max(0, Math.min(e, Math.max(0, u - c))), f = U(o);
|
|
655
876
|
if (!f) return;
|
|
656
877
|
let p = { behavior: t?.smooth === !0 ? "smooth" : "auto" };
|
|
657
878
|
s ? p.left = d : p.top = d, f.scrollTo(p);
|
|
658
879
|
}, []);
|
|
659
880
|
return {
|
|
660
|
-
virtualItems:
|
|
661
|
-
totalSize:
|
|
662
|
-
isScrolling:
|
|
881
|
+
virtualItems: G,
|
|
882
|
+
totalSize: V,
|
|
883
|
+
isScrolling: k,
|
|
663
884
|
scrollToIndex: n((e, t) => {
|
|
664
|
-
let { getScrollElement: n, count: r, estimateSize: i, horizontal: a, reverse: o } =
|
|
885
|
+
let { getScrollElement: n, count: r, estimateSize: i, horizontal: a, reverse: o } = w.current, s = n();
|
|
665
886
|
if (!s) return;
|
|
666
887
|
let c = Math.max(0, Math.trunc(Number(r)) || 0);
|
|
667
888
|
if (c === 0) return;
|
|
668
|
-
let l = Math.max(0, Math.min(Math.trunc(Number(e)) || 0, c - 1)), u = t?.align ?? "auto", d = a ?? !1, f = o ?? !1, p =
|
|
889
|
+
let l = Math.max(0, Math.min(Math.trunc(Number(e)) || 0, c - 1)), u = t?.align ?? "auto", d = a ?? !1, f = o ?? !1, p = E.current, m = X(l, u, q(s, d) || w.current.initialViewportSize || 0, B(c, i, p), J(s, d), i, f, p), h = U(s);
|
|
669
890
|
if (!h) return;
|
|
670
891
|
let g = { behavior: t?.smooth === !0 ? "smooth" : "auto" };
|
|
671
892
|
d ? g.left = m : g.top = m, h.scrollTo(g);
|
|
672
893
|
}, []),
|
|
673
|
-
scrollToOffset:
|
|
894
|
+
scrollToOffset: K
|
|
674
895
|
};
|
|
675
896
|
}
|
|
676
897
|
//#endregion
|
|
677
|
-
export {
|
|
898
|
+
export { M as a, E as c, b as d, v as f, d as h, P as i, w as l, p as m, K as n, A as o, h as p, I as r, O as s, Z as t, S as u };
|