@himanshu-sorathiya/react-kit 1.0.22 → 1.0.24

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.
@@ -1,41 +1,43 @@
1
- import { useCallback as e, useEffect as t, useRef as n, useState as r } from "react";
1
+ import { t as e } from "./useEventListener.js";
2
+ import { t } from "./utils.js";
3
+ import { useCallback as n, useEffect as r, useLayoutEffect as i, useMemo as a, useRef as o, useState as s } from "react";
2
4
  //#region src/performance/useDebounce/useDebounce.ts
3
- function i(i, a = {}) {
4
- let o = Math.max(0, Number(i) || 0), [s, c] = r(!1), l = a?.maxWait, u = !!a?.leading, d = !u && a?.trailing === !1 ? !0 : a?.trailing ?? !u, f = n(null), p = n(null), m = n(null), h = n(-1), g = n(-1), _ = e(() => {
5
+ function c(e, t = {}) {
6
+ let i = Math.max(0, Number(e) || 0), [a, c] = s(!1), l = t?.maxWait, u = !!t?.leading, d = !u && t?.trailing === !1 ? !0 : t?.trailing ?? !u, f = o(null), p = o(null), m = o(null), h = o(-1), g = o(-1), _ = n(() => {
5
7
  m.current &&= (clearTimeout(m.current), null), h.current = -1, g.current = -1, p.current = null, f.current = null, c(!1);
6
- }, []), v = e(() => {
8
+ }, []), v = n(() => {
7
9
  m.current && f.current && p.current && (clearTimeout(m.current), m.current = null, f.current(...p.current), h.current = Date.now(), g.current = -1, p.current = null, f.current = null, c(!1));
8
10
  }, []);
9
- return t(() => () => {
11
+ return r(() => () => {
10
12
  _();
11
13
  }, [_]), {
12
- run: e((e, ...t) => {
14
+ run: n((e, ...t) => {
13
15
  c(!0), g.current = Date.now(), p.current = t, f.current = e, h.current === -1 && (h.current = Date.now(), u === !0 && f.current(...t)), l !== void 0 && Date.now() - h.current >= l ? (m.current && clearTimeout(m.current), f.current && f.current(...t), h.current = -1, c(!1)) : (m.current && clearTimeout(m.current), m.current = setTimeout(() => {
14
16
  g.current !== h.current && d !== !1 && f.current && p.current && f.current(...p.current), h.current = -1, c(!1);
15
- }, o));
17
+ }, i));
16
18
  }, [
17
- o,
19
+ i,
18
20
  l,
19
21
  d,
20
22
  u
21
23
  ]),
22
24
  cancel: _,
23
25
  flush: v,
24
- isPending: s
26
+ isPending: a
25
27
  };
26
28
  }
27
29
  //#endregion
28
30
  //#region src/performance/useDebounce/useDebouncedCallback.ts
29
- function a(r, a, o = {}) {
30
- let s = n(r);
31
- t(() => {
32
- s.current = r;
33
- }, [r]);
34
- let { run: c, cancel: l, flush: u, isPending: d } = i(a, o);
31
+ function l(e, t, i = {}) {
32
+ let a = o(e);
33
+ r(() => {
34
+ a.current = e;
35
+ }, [e]);
36
+ let { run: s, cancel: l, flush: u, isPending: d } = c(t, i);
35
37
  return {
36
- debouncedFunc: e((...e) => {
37
- c(s.current, ...e);
38
- }, [c]),
38
+ debouncedFunc: n((...e) => {
39
+ s(a.current, ...e);
40
+ }, [s]),
39
41
  cancel: l,
40
42
  flush: u,
41
43
  isPending: d
@@ -43,57 +45,57 @@ function a(r, a, o = {}) {
43
45
  }
44
46
  //#endregion
45
47
  //#region src/performance/useDebounce/useDebouncedState.ts
46
- function o(e, t, n = {}) {
47
- let [i, o] = r(e), { debouncedFunc: s, cancel: c, flush: l, isPending: u } = a((e) => {
48
- o(e);
48
+ function u(e, t, n = {}) {
49
+ let [r, i] = s(e), { debouncedFunc: a, cancel: o, flush: c, isPending: u } = l((e) => {
50
+ i(e);
49
51
  }, t, n);
50
52
  return [
51
- i,
52
- s,
53
+ r,
54
+ a,
53
55
  {
54
56
  isPending: u,
55
- cancel: c,
56
- flush: l,
57
- forceSetValue: o
57
+ cancel: o,
58
+ flush: c,
59
+ forceSetValue: i
58
60
  }
59
61
  ];
60
62
  }
61
63
  //#endregion
62
64
  //#region src/performance/useDebounce/useDebouncedValue.ts
63
- function s(e, n, i = {}) {
64
- let [o, s] = r(e), { debouncedFunc: c } = a((e) => {
65
- s(e);
66
- }, n, i);
67
- return t(() => {
68
- c(e);
69
- }, [e, c]), o;
65
+ function d(e, t, n = {}) {
66
+ let [i, a] = s(e), { debouncedFunc: o } = l((e) => {
67
+ a(e);
68
+ }, t, n);
69
+ return r(() => {
70
+ o(e);
71
+ }, [e, o]), i;
70
72
  }
71
73
  //#endregion
72
74
  //#region src/performance/useRateLimit/useRateLimit.ts
73
- function c(i, a, o) {
74
- let s = Math.max(1, Number(i) || 1), c = Math.max(0, Number(a) || 0), [l, u] = r(s), d = o?.refillStrategy ?? "burst", f = n(o?.onRateLimitReached);
75
- t(() => {
76
- f.current = o?.onRateLimitReached;
77
- }, [o?.onRateLimitReached]);
78
- let p = n(s), [m] = r(() => Date.now()), h = n(m), g = n(null);
79
- return t(() => () => {
75
+ function f(e, t, i) {
76
+ let a = Math.max(1, Number(e) || 1), c = Math.max(0, Number(t) || 0), [l, u] = s(a), d = i?.refillStrategy ?? "burst", f = o(i?.onRateLimitReached);
77
+ r(() => {
78
+ f.current = i?.onRateLimitReached;
79
+ }, [i?.onRateLimitReached]);
80
+ let p = o(a), [m] = s(() => Date.now()), h = o(m), g = o(null);
81
+ return r(() => () => {
80
82
  g.current && clearTimeout(g.current);
81
83
  }, []), {
82
- run: e((e, ...t) => {
84
+ run: n((e, ...t) => {
83
85
  let n = Date.now(), r = n - h.current;
84
- if (d === "burst") r >= c && (p.current = s, h.current = n);
86
+ if (d === "burst") r >= c && (p.current = a, h.current = n);
85
87
  else {
86
- let e = c / s, t = Math.floor(r / e);
87
- t > 0 && (p.current = Math.min(s, p.current + t), h.current += t * e);
88
+ let e = c / a, t = Math.floor(r / e);
89
+ t > 0 && (p.current = Math.min(a, p.current + t), h.current += t * e);
88
90
  }
89
- if (p.current > 0 ? (--p.current, u(p.current), e(...t)) : f.current && f.current(), g.current && clearTimeout(g.current), p.current < s) {
90
- let e = c / s, t = d === "burst" ? c - (Date.now() - h.current) : e - (Date.now() - h.current);
91
+ if (p.current > 0 ? (--p.current, u(p.current), e(...t)) : f.current && f.current(), g.current && clearTimeout(g.current), p.current < a) {
92
+ let e = c / a, t = d === "burst" ? c - (Date.now() - h.current) : e - (Date.now() - h.current);
91
93
  g.current = setTimeout(() => {
92
- u((e) => Math.min(s, e + 1)), h.current = Date.now(), p.current = Math.min(s, p.current + 1);
94
+ u((e) => Math.min(a, e + 1)), h.current = Date.now(), p.current = Math.min(a, p.current + 1);
93
95
  }, Math.max(0, t));
94
96
  }
95
97
  }, [
96
- s,
98
+ a,
97
99
  c,
98
100
  d
99
101
  ]),
@@ -103,96 +105,573 @@ function c(i, a, o) {
103
105
  }
104
106
  //#endregion
105
107
  //#region src/performance/useRateLimit/useRateLimitedCallback.ts
106
- function l(r, i, a, o) {
107
- let s = n(r);
108
- t(() => {
109
- s.current = r;
110
- }, [r]);
111
- let { run: l, remaining: u, isRateLimited: d } = c(i, a, o);
108
+ function p(e, t, i, a) {
109
+ let s = o(e);
110
+ r(() => {
111
+ s.current = e;
112
+ }, [e]);
113
+ let { run: c, remaining: l, isRateLimited: u } = f(t, i, a);
112
114
  return {
113
- rateLimitedFunc: e((...e) => {
114
- l(s.current, ...e);
115
- }, [l]),
116
- remaining: u,
117
- isRateLimited: d
115
+ rateLimitedFunc: n((...e) => {
116
+ c(s.current, ...e);
117
+ }, [c]),
118
+ remaining: l,
119
+ isRateLimited: u
118
120
  };
119
121
  }
120
122
  //#endregion
121
123
  //#region src/performance/useThrottle/useThrottle.ts
122
- function u(i, a = {}) {
123
- let o = Math.max(0, Number(i) || 0), [s, c] = r(!1), l = a?.leading ?? !0, u = a?.trailing ?? !0;
124
+ function m(e, t = {}) {
125
+ let i = Math.max(0, Number(e) || 0), [a, c] = s(!1), l = t?.leading ?? !0, u = t?.trailing ?? !0;
124
126
  l === !1 && u === !1 && (l = !0, u = !0);
125
- let d = n(null), f = n(null), p = n(null), m = n(-1), h = e(() => {
127
+ let d = o(null), f = o(null), p = o(null), m = o(-1), h = n(() => {
126
128
  p.current &&= (clearTimeout(p.current), null), m.current = -1, f.current = null, d.current = null, c(!1);
127
- }, []), g = e(() => {
129
+ }, []), g = n(() => {
128
130
  f.current && d.current && (p.current &&= (clearTimeout(p.current), null), d.current(...f.current), m.current = l ? Date.now() : -1, f.current = null, d.current = null, c(!1));
129
131
  }, [l]);
130
- return t(() => () => {
132
+ return r(() => () => {
131
133
  h();
132
134
  }, [h]), {
133
- run: e((e, ...t) => {
135
+ run: n((e, ...t) => {
134
136
  c(!0);
135
137
  let n = Date.now();
136
- if (f.current = t, d.current = e, m.current === -1 ? l : n - m.current >= o) p.current &&= (clearTimeout(p.current), null), d.current(...t), m.current = n, f.current = null, c(!1);
138
+ if (f.current = t, d.current = e, m.current === -1 ? l : n - m.current >= i) p.current &&= (clearTimeout(p.current), null), d.current(...t), m.current = n, f.current = null, c(!1);
137
139
  else if (!p.current) {
138
- let e = m.current === -1 ? 0 : n - m.current, t = o - e;
140
+ let e = m.current === -1 ? 0 : n - m.current, t = i - e;
139
141
  p.current = setTimeout(() => {
140
142
  u && f.current && d.current ? (d.current(...f.current), m.current = l ? Date.now() : -1) : m.current = -1, f.current = null, d.current = null, p.current = null, c(!1);
141
143
  }, t);
142
144
  }
143
145
  }, [
144
- o,
146
+ i,
145
147
  l,
146
148
  u
147
149
  ]),
148
150
  cancel: h,
149
151
  flush: g,
150
- isPending: s
152
+ isPending: a
151
153
  };
152
154
  }
153
155
  //#endregion
154
156
  //#region src/performance/useThrottle/useThrottledCallback.ts
155
- function d(r, i, a = {}) {
156
- let o = n(r);
157
- t(() => {
158
- o.current = r;
159
- }, [r]);
160
- let { run: s, cancel: c, flush: l, isPending: d } = u(i, a);
157
+ function h(e, t, i = {}) {
158
+ let a = o(e);
159
+ r(() => {
160
+ a.current = e;
161
+ }, [e]);
162
+ let { run: s, cancel: c, flush: l, isPending: u } = m(t, i);
161
163
  return {
162
- throttledFunc: e((...e) => {
163
- s(o.current, ...e);
164
+ throttledFunc: n((...e) => {
165
+ s(a.current, ...e);
164
166
  }, [s]),
165
167
  cancel: c,
166
168
  flush: l,
167
- isPending: d
169
+ isPending: u
168
170
  };
169
171
  }
170
172
  //#endregion
171
173
  //#region src/performance/useThrottle/useThrottledState.ts
172
- function f(e, t, n = {}) {
173
- let [i, a] = r(e), { throttledFunc: o, isPending: s, cancel: c, flush: l } = d((e) => {
174
- a(e);
174
+ function g(e, t, n = {}) {
175
+ let [r, i] = s(e), { throttledFunc: a, isPending: o, cancel: c, flush: l } = h((e) => {
176
+ i(e);
175
177
  }, t, n);
176
178
  return [
177
- i,
178
- o,
179
+ r,
180
+ a,
179
181
  {
180
- isPending: s,
182
+ isPending: o,
181
183
  cancel: c,
182
184
  flush: l,
183
- forceSetValue: a
185
+ forceSetValue: i
184
186
  }
185
187
  ];
186
188
  }
187
189
  //#endregion
188
190
  //#region src/performance/useThrottle/useThrottledValue.ts
189
- function p(e, n, i = {}) {
190
- let [a, o] = r(e), { throttledFunc: s } = d((e) => {
191
+ function _(e, t, n = {}) {
192
+ let [i, a] = s(e), { throttledFunc: o } = h((e) => {
193
+ a(e);
194
+ }, t, n);
195
+ return r(() => {
191
196
  o(e);
192
- }, n, i);
193
- return t(() => {
194
- s(e);
195
- }, [e, s]), a;
197
+ }, [e, o]), i;
198
+ }
199
+ //#endregion
200
+ //#region src/shared/virtualShared/offsetCache.ts
201
+ var v = class {
202
+ _offsets = /* @__PURE__ */ new Float64Array();
203
+ _count = 0;
204
+ initializeOffsets(e, t) {
205
+ this._count = e, this._offsets = new Float64Array(e + 1);
206
+ let n = 0;
207
+ for (let r = 0; r < e; r++) {
208
+ this._offsets[r] = n;
209
+ let e = t(r);
210
+ n += Number.isFinite(e) && e >= 0 ? e : 0;
211
+ }
212
+ this._offsets[e] = n;
213
+ }
214
+ getItemStartOffset(e) {
215
+ return e <= 0 ? 0 : e >= this._count ? this._offsets[this._count] ?? 0 : this._offsets[e] ?? 0;
216
+ }
217
+ getItemSize(e) {
218
+ return e < 0 || e >= this._count ? 0 : (this._offsets[e + 1] ?? 0) - (this._offsets[e] ?? 0);
219
+ }
220
+ getTotalSize() {
221
+ return this._offsets[this._count] ?? 0;
222
+ }
223
+ updateItemSize(e, t) {
224
+ if (e < 0 || e >= this._count) return;
225
+ let n = (Number.isFinite(t) && t >= 0 ? t : 0) - this.getItemSize(e);
226
+ if (n !== 0) for (let t = e + 1; t <= this._count; t++) this._offsets[t] = (this._offsets[t] ?? 0) + n;
227
+ }
228
+ findStartIndex(e) {
229
+ if (this._count === 0) return 0;
230
+ let t = 0, n = this._count - 1;
231
+ for (; t < n;) {
232
+ let r = t + n >>> 1;
233
+ (this._offsets[r + 1] ?? 0) <= e ? t = r + 1 : n = r;
234
+ }
235
+ return t;
236
+ }
237
+ findEndIndex(e) {
238
+ if (this._count === 0) return -1;
239
+ let t = 0, n = this._count - 1;
240
+ for (; t < n;) {
241
+ let r = (t + n >>> 1) + 1;
242
+ (this._offsets[r] ?? 0) < e ? t = r : n = r - 1;
243
+ }
244
+ return t;
245
+ }
246
+ getPhysicalStartReverse(e, t) {
247
+ return t - (this._offsets[e + 1] ?? 0);
248
+ }
249
+ findStartIndexReverse(e, t) {
250
+ if (this._count === 0) return 0;
251
+ let n = t - e, r = 0, i = this._count - 1;
252
+ for (; r < i;) {
253
+ let e = (r + i >>> 1) + 1;
254
+ (this._offsets[e] ?? 0) < n ? r = e : i = e - 1;
255
+ }
256
+ return (this._offsets[r] ?? 0) >= n ? 0 : r;
257
+ }
258
+ findEndIndexReverse(e, t) {
259
+ if (this._count === 0) return -1;
260
+ let n = t - e, r = 0, i = this._count - 1;
261
+ for (; r < i;) {
262
+ let e = r + i >>> 1;
263
+ (this._offsets[e + 1] ?? 0) > n ? i = e : r = e + 1;
264
+ }
265
+ return (this._offsets[r + 1] ?? 0) <= n ? -1 : r;
266
+ }
267
+ };
268
+ //#endregion
269
+ //#region src/shared/virtualShared/utils.ts
270
+ function y(e, t) {
271
+ let n = typeof t == "function" ? t(e) : t, r = Number(n);
272
+ return Number.isFinite(r) && r >= 0 ? r : 0;
273
+ }
274
+ function b(e, t, n) {
275
+ if (e <= 0) return 0;
276
+ if (typeof t == "number") return e * Math.max(0, t);
277
+ if (n) return n.getItemStartOffset(e);
278
+ let r = 0;
279
+ for (let n = 0; n < e; n++) r += y(n, t);
280
+ return r;
281
+ }
282
+ function x(e, t, n) {
283
+ if (e <= 0) return 0;
284
+ if (typeof t == "number") return e * Math.max(0, t);
285
+ if (n) return n.getTotalSize();
286
+ let r = 0;
287
+ for (let n = 0; n < e; n++) r += y(n, t);
288
+ return r;
289
+ }
290
+ function S(e, t) {
291
+ if (!e) return 0;
292
+ let n = t === "vertical";
293
+ 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
+ }
295
+ function C(e, t) {
296
+ if (!e) return 0;
297
+ let n = t === "vertical";
298
+ 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
+ }
300
+ function w(e) {
301
+ return e ? e instanceof Window ? document.documentElement : e instanceof Document ? e.scrollingElement ?? e.documentElement : e : null;
302
+ }
303
+ //#endregion
304
+ //#region src/performance/useVirtualGrid/utils.ts
305
+ function T(e, t, n, r, i, a) {
306
+ if (n <= 0 || t <= 0) return {
307
+ startIndex: 0,
308
+ endIndex: -1
309
+ };
310
+ let o, s;
311
+ if (typeof r == "number") {
312
+ let i = Math.max(0, r);
313
+ i === 0 ? (o = 0, s = n - 1) : (o = Math.max(0, Math.floor(e / i)), s = Math.min(n - 1, Math.ceil((e + t) / i) - 1));
314
+ } else if (a) {
315
+ let n = e + t;
316
+ o = a.findStartIndex(e), s = a.findEndIndex(n);
317
+ } else {
318
+ o = 0, s = -1;
319
+ let i = 0, a = !1;
320
+ for (let c = 0; c < n; c++) {
321
+ let n = y(c, r), l = i + n;
322
+ if (!a && l > e && (o = c, a = !0), a) if (i < e + t) s = c;
323
+ else break;
324
+ i += n;
325
+ }
326
+ a || (o = 0, s = -1);
327
+ }
328
+ return o = Math.max(0, o - i), s = Math.min(n - 1, s + i), {
329
+ startIndex: o,
330
+ endIndex: s
331
+ };
332
+ }
333
+ function E(e, t, n, r, i, a, o) {
334
+ let s = o ? o.getItemSize(e) : y(e, a), c = b(e, a, o), l = c + s, u = Math.max(0, r - n), d;
335
+ switch (t) {
336
+ case "start":
337
+ d = c;
338
+ break;
339
+ case "end":
340
+ d = Math.max(0, l - n);
341
+ break;
342
+ case "center":
343
+ d = Math.max(0, c + s / 2 - n / 2);
344
+ break;
345
+ default:
346
+ if (c >= i && l <= i + n) return i;
347
+ d = c < i ? c : Math.max(0, l - n);
348
+ break;
349
+ }
350
+ return Math.max(0, Math.min(d, u));
351
+ }
352
+ //#endregion
353
+ //#region src/performance/useVirtualGrid/useVirtualGrid.ts
354
+ function D(t) {
355
+ let { rowCount: c, colCount: u, estimateRowHeight: d, estimateColumnWidth: f, getScrollElement: p, overscanRows: m = 3, overscanCols: h = 3, scrollingDelay: g = 150, initialViewportHeight: _ = 0, initialViewportWidth: D = 0, initialScrollTop: O, initialScrollLeft: k, initialScrollRow: A, initialScrollCol: j, itemKey: M } = t, N = Math.max(0, Math.trunc(Number(c)) || 0), P = Math.max(0, Math.trunc(Number(u)) || 0), F = Math.max(0, Math.trunc(Number(m)) || 0), I = Math.max(0, Math.trunc(Number(h)) || 0), L = o(t);
356
+ i(() => {
357
+ L.current = t;
358
+ });
359
+ let R = a(() => {
360
+ if (typeof d != "function") return;
361
+ let e = new v();
362
+ return e.initializeOffsets(N, d), e;
363
+ }, [N, d]), z = a(() => {
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);
368
+ i(() => {
369
+ B.current = R;
370
+ }, [R]), i(() => {
371
+ V.current = z;
372
+ }, [z]);
373
+ let [H, U] = s(() => {
374
+ if (typeof O == "number") return Math.max(0, O);
375
+ if (typeof A == "number" && N > 0) {
376
+ let e = Math.max(0, Math.min(Math.trunc(Number(A)) || 0, N - 1));
377
+ return R ? R.getItemStartOffset(e) : b(e, d);
378
+ }
379
+ return 0;
380
+ }), [W, G] = s(() => {
381
+ if (typeof k == "number") return Math.max(0, k);
382
+ if (typeof j == "number" && P > 0) {
383
+ let e = Math.max(0, Math.min(Math.trunc(Number(j)) || 0, P - 1));
384
+ return z ? z.getItemStartOffset(e) : b(e, f);
385
+ }
386
+ return 0;
387
+ }), [K, q] = s(!1), [, J] = s({}), Y = o(!1), { debouncedFunc: X } = l(() => q(!1), g), Z = p();
388
+ r(() => {
389
+ if (!Z) return;
390
+ if (!Y.current) {
391
+ Y.current = !0;
392
+ let e = typeof O == "number" || typeof A == "number", t = typeof k == "number" || typeof j == "number";
393
+ if (e || t) {
394
+ let n = w(Z);
395
+ n && n.scrollTo({
396
+ ...e && { top: H },
397
+ ...t && { left: W },
398
+ behavior: "auto"
399
+ });
400
+ return;
401
+ }
402
+ }
403
+ let e = C(Z, "vertical"), t = C(Z, "horizontal");
404
+ U((t) => t === e ? t : e), G((e) => e === t ? e : t);
405
+ }, [
406
+ Z,
407
+ O,
408
+ k,
409
+ A,
410
+ j,
411
+ H,
412
+ W
413
+ ]);
414
+ function ee() {
415
+ let { getScrollElement: e, scrollingDelay: t } = L.current, n = e();
416
+ if (!n) return;
417
+ let r = C(n, "vertical"), i = C(n, "horizontal");
418
+ U(r), G(i), (t ?? 150) > 0 && (q(!0), X());
419
+ }
420
+ e("scroll", ee, {
421
+ target: Z,
422
+ passive: !0
423
+ }), r(() => {
424
+ if (!Z) return;
425
+ let e = () => J({});
426
+ if (Z instanceof Window) return Z.addEventListener("resize", e), () => Z.removeEventListener("resize", e);
427
+ let t = new ResizeObserver(e), n = Z instanceof Document ? Z.documentElement : Z;
428
+ return t.observe(n), () => t.disconnect();
429
+ }, [Z]);
430
+ let te = S(Z, "vertical") || _, ne = S(Z, "horizontal") || D, re = x(N, d, R), ie = x(P, f, z), { startIndex: Q, endIndex: ae } = T(H, te, N, d, F, R), { startIndex: $, endIndex: oe } = T(W, ne, P, f, I, z), se = [];
431
+ if (Q <= ae && $ <= oe) {
432
+ let e = R ? R.getItemStartOffset(Q) : b(Q, d);
433
+ for (let t = Q; t <= ae; t++) {
434
+ let n = R ? R.getItemSize(t) : y(t, d), r = z ? z.getItemStartOffset($) : b($, f);
435
+ for (let i = $; i <= oe; i++) {
436
+ let a = z ? z.getItemSize(i) : y(i, f), o = M ? M(t, i) : `${t}:${i}`;
437
+ se.push({
438
+ key: o,
439
+ rowIndex: t,
440
+ colIndex: i,
441
+ height: n,
442
+ width: a,
443
+ top: e,
444
+ left: r
445
+ }), r += a;
446
+ }
447
+ e += n;
448
+ }
449
+ }
450
+ return {
451
+ virtualCells: se,
452
+ totalHeight: re,
453
+ totalWidth: ie,
454
+ isScrolling: K,
455
+ scrollToOffset: n((e, t) => {
456
+ let { getScrollElement: n, initialViewportHeight: r, initialViewportWidth: i } = L.current, a = n();
457
+ if (!a) return;
458
+ let { rowCount: o, colCount: s, estimateRowHeight: c, estimateColumnWidth: l } = L.current, u = Math.max(0, Math.trunc(Number(o)) || 0), d = Math.max(0, Math.trunc(Number(s)) || 0), f = x(u, c, B.current), p = x(d, l, V.current), m = S(a, "vertical") || r || 0, h = S(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 = w(a);
459
+ v && v.scrollTo({
460
+ top: g,
461
+ left: _,
462
+ behavior: t?.smooth === !0 ? "smooth" : "auto"
463
+ });
464
+ }, []),
465
+ scrollToRow: n((e, t) => {
466
+ let { getScrollElement: n, rowCount: r, estimateRowHeight: i, initialViewportHeight: a } = L.current, o = n();
467
+ if (!o) return;
468
+ let s = Math.max(0, Math.trunc(Number(r)) || 0);
469
+ if (s === 0) return;
470
+ let c = Math.max(0, Math.min(Math.trunc(Number(e)) || 0, s - 1)), l = S(o, "vertical") || a || 0, u = x(s, i, B.current), d = C(o, "vertical"), f = E(c, t?.align ?? "auto", l, u, d, i, B.current), p = w(o);
471
+ p && p.scrollTo({
472
+ top: f,
473
+ behavior: t?.smooth === !0 ? "smooth" : "auto"
474
+ });
475
+ }, []),
476
+ scrollToColumn: n((e, t) => {
477
+ let { getScrollElement: n, colCount: r, estimateColumnWidth: i, initialViewportWidth: a } = L.current, o = n();
478
+ if (!o) return;
479
+ let s = Math.max(0, Math.trunc(Number(r)) || 0);
480
+ if (s === 0) return;
481
+ let c = Math.max(0, Math.min(Math.trunc(Number(e)) || 0, s - 1)), l = S(o, "horizontal") || a || 0, u = x(s, i, V.current), d = C(o, "horizontal"), f = E(c, t?.align ?? "auto", l, u, d, i, V.current), p = w(o);
482
+ p && p.scrollTo({
483
+ left: f,
484
+ behavior: t?.smooth === !0 ? "smooth" : "auto"
485
+ });
486
+ }, []),
487
+ scrollToCell: n((e, t, n) => {
488
+ let { getScrollElement: r, rowCount: i, colCount: a, estimateRowHeight: o, estimateColumnWidth: s, initialViewportHeight: c, initialViewportWidth: l } = L.current, u = r();
489
+ if (!u) return;
490
+ let d = Math.max(0, Math.trunc(Number(i)) || 0), f = Math.max(0, Math.trunc(Number(a)) || 0);
491
+ 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 = S(u, "vertical") || c || 0, g = S(u, "horizontal") || l || 0, _ = x(d, o, B.current), v = x(f, s, V.current), y = C(u, "vertical"), b = C(u, "horizontal"), T = E(p, n?.rowAlign ?? "auto", h, _, y, o, B.current), D = E(m, n?.colAlign ?? "auto", g, v, b, s, V.current), O = w(u);
493
+ O && O.scrollTo({
494
+ top: T,
495
+ left: D,
496
+ behavior: n?.smooth === !0 ? "smooth" : "auto"
497
+ });
498
+ }, [])
499
+ };
500
+ }
501
+ //#endregion
502
+ //#region src/performance/useVirtualList/utils.ts
503
+ function O(e, t) {
504
+ return S(e, t ? "horizontal" : "vertical");
505
+ }
506
+ function k(e, t) {
507
+ return C(e, t ? "horizontal" : "vertical");
508
+ }
509
+ function A(e, t, n, r, i, a, o, s) {
510
+ if (r <= 0 || t <= 0) return {
511
+ startIndex: 0,
512
+ endIndex: -1
513
+ };
514
+ let c, l;
515
+ if (typeof i == "number") {
516
+ let a = Math.max(0, i);
517
+ a === 0 ? (c = 0, l = r - 1) : o ? (c = Math.max(0, Math.floor((n - e - t) / a)), l = Math.min(r - 1, Math.ceil((n - e) / a) - 1)) : (c = Math.max(0, Math.floor(e / a)), l = Math.min(r - 1, Math.ceil((e + t) / a) - 1));
518
+ } else if (s) if (o) {
519
+ let r = e + t;
520
+ c = s.findStartIndexReverse(e, n), l = s.findEndIndexReverse(r, n);
521
+ } else {
522
+ let n = e + t;
523
+ c = s.findStartIndex(e), l = s.findEndIndex(n);
524
+ }
525
+ else if (o) {
526
+ c = r, l = -1;
527
+ let a = 0;
528
+ for (let o = 0; o < r; o++) {
529
+ let r = y(o, i), s = n - a - r;
530
+ if (n - a <= e) break;
531
+ s < e + t && (o < c && (c = o), l = o), a += r;
532
+ }
533
+ c === r && (c = 0, l = -1);
534
+ } else {
535
+ c = 0, l = -1;
536
+ let n = 0, a = !1;
537
+ for (let o = 0; o < r; o++) {
538
+ let r = y(o, i), s = n + r;
539
+ if (!a && s > e && (c = o, a = !0), a) if (n < e + t) l = o;
540
+ else break;
541
+ n += r;
542
+ }
543
+ a || (c = 0, l = -1);
544
+ }
545
+ return c = Math.max(0, c - a), l = Math.min(r - 1, l + a), {
546
+ startIndex: c,
547
+ endIndex: l
548
+ };
549
+ }
550
+ function j(e, t, n, r, i, a, o, s) {
551
+ let c = s ? s.getItemSize(e) : y(e, a), l = b(e, a, s), u = o ? r - l - c : l, d = u + c, f = Math.max(0, r - n), p;
552
+ switch (t) {
553
+ case "start":
554
+ p = o ? Math.max(0, d - n) : u;
555
+ break;
556
+ case "end":
557
+ p = o ? u : Math.max(0, d - n);
558
+ break;
559
+ case "center":
560
+ p = Math.max(0, u + c / 2 - n / 2);
561
+ break;
562
+ default:
563
+ if (u >= i && d <= i + n) return i;
564
+ p = u < i ? o ? Math.max(0, d - n) : u : o ? u : Math.max(0, d - n);
565
+ break;
566
+ }
567
+ return Math.max(0, Math.min(p, f));
568
+ }
569
+ //#endregion
570
+ //#region src/performance/useVirtualList/useVirtualList.ts
571
+ function M(c) {
572
+ let { count: u, estimateSize: d, getScrollElement: f, overscan: p = 3, horizontal: m = !1, reverse: h = !1, scrollingDelay: g = 150, initialViewportSize: _ = 0, data: S, itemKey: C, initialOffset: T, initialScrollIndex: E } = c, D = Math.max(0, Math.trunc(Number(u)) || 0), M = Math.max(0, Math.trunc(Number(p)) || 0), N = o(c);
573
+ i(() => {
574
+ N.current = c;
575
+ });
576
+ let P = a(() => {
577
+ if (typeof d != "function") return;
578
+ let e = new v();
579
+ return e.initializeOffsets(D, d), e;
580
+ }, [D, d]), F = o(P);
581
+ i(() => {
582
+ F.current = P;
583
+ }, [P]);
584
+ let [I, L] = s(() => {
585
+ if (typeof T == "number") return Math.max(0, T);
586
+ if (typeof E == "number" && D > 0) {
587
+ let e = Math.max(0, Math.min(Math.trunc(Number(E)) || 0, D - 1)), t = P ? P.getItemStartOffset(e) : b(e, d);
588
+ if (h) {
589
+ let n = P ? P.getItemSize(e) : y(e, d), r = x(D, d, P);
590
+ return Math.max(0, r - t - n);
591
+ }
592
+ return t;
593
+ }
594
+ return 0;
595
+ }), [R, z] = s(!1), [, B] = s({}), V = o(!1), { debouncedFunc: H } = l(() => z(!1), g), U = f();
596
+ r(() => {
597
+ if (!U) return;
598
+ if (!V.current && (V.current = !0, typeof T == "number" || typeof E == "number")) {
599
+ let e = w(U);
600
+ e && e.scrollTo({
601
+ [m ? "left" : "top"]: I,
602
+ behavior: "auto"
603
+ });
604
+ return;
605
+ }
606
+ let e = k(U, m);
607
+ L((t) => t === e ? t : e);
608
+ }, [
609
+ U,
610
+ m,
611
+ T,
612
+ E,
613
+ I
614
+ ]);
615
+ function W() {
616
+ let { getScrollElement: e, horizontal: t } = N.current, n = e();
617
+ if (!n) return;
618
+ let r = k(n, t ?? !1);
619
+ L(r), (N.current.scrollingDelay ?? 150) > 0 && (z(!0), H());
620
+ }
621
+ e("scroll", W, {
622
+ target: U,
623
+ passive: !0
624
+ }), r(() => {
625
+ if (!U) return;
626
+ let e = () => B({});
627
+ if (U instanceof Window) return U.addEventListener("resize", e), () => U.removeEventListener("resize", e);
628
+ let t = new ResizeObserver(e), n = U instanceof Document ? U.documentElement : U;
629
+ return t.observe(n), () => t.disconnect();
630
+ }, [U]);
631
+ let G = O(U, m) || _, K = x(D, d, P), { startIndex: q, endIndex: J } = A(I, G, K, D, d, M, h, P), Y = [];
632
+ if (q <= J) {
633
+ let e = P ? P.getItemStartOffset(q) : b(q, d);
634
+ for (let n = q; n <= J; n++) {
635
+ let r = P ? P.getItemSize(n) : y(n, d), i = h ? K - e - r : e, a = n;
636
+ if (C) {
637
+ if (typeof C == "function") a = C(n, S?.[n]);
638
+ else if (S && S[n] !== void 0 && S[n] !== null) {
639
+ let e = t(S[n], C);
640
+ (typeof e == "string" || typeof e == "number") && (a = e);
641
+ }
642
+ }
643
+ Y.push({
644
+ key: a,
645
+ index: n,
646
+ size: r,
647
+ start: i
648
+ }), e += r;
649
+ }
650
+ }
651
+ let X = n((e, t) => {
652
+ let { getScrollElement: n, horizontal: r, count: i, estimateSize: a } = N.current, o = n();
653
+ if (!o) return;
654
+ let s = r ?? !1, c = O(o, s) || N.current.initialViewportSize || 0, l = F.current, u = x(Math.max(0, Math.trunc(Number(i)) || 0), a, l), d = Math.max(0, Math.min(e, Math.max(0, u - c))), f = w(o);
655
+ if (!f) return;
656
+ let p = { behavior: t?.smooth === !0 ? "smooth" : "auto" };
657
+ s ? p.left = d : p.top = d, f.scrollTo(p);
658
+ }, []);
659
+ return {
660
+ virtualItems: Y,
661
+ totalSize: K,
662
+ isScrolling: R,
663
+ scrollToIndex: n((e, t) => {
664
+ let { getScrollElement: n, count: r, estimateSize: i, horizontal: a, reverse: o } = N.current, s = n();
665
+ if (!s) return;
666
+ let c = Math.max(0, Math.trunc(Number(r)) || 0);
667
+ 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 = F.current, m = j(l, u, O(s, d) || N.current.initialViewportSize || 0, x(c, i, p), k(s, d), i, f, p), h = w(s);
669
+ if (!h) return;
670
+ let g = { behavior: t?.smooth === !0 ? "smooth" : "auto" };
671
+ d ? g.left = m : g.top = m, h.scrollTo(g);
672
+ }, []),
673
+ scrollToOffset: X
674
+ };
196
675
  }
197
676
  //#endregion
198
- export { l as a, o as c, u as i, a as l, f as n, c as o, d as r, s, p as t, i as u };
677
+ export { h as a, f as c, l as d, c as f, g as i, d as l, D as n, m as o, _ as r, p as s, M as t, u };