@himanshu-sorathiya/react-kit 1.0.30 → 1.0.31

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,25 +1,25 @@
1
1
  import { t as e } from "./useEventListener.js";
2
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";
3
+ import { useCallback as n, useEffect as r, useEffectEvent as i, useLayoutEffect as a, useMemo as o, useRef as s, useState as c } from "react";
4
4
  //#region src/performance/useBatcher/utils.ts
5
- function c(e) {
5
+ function l(e) {
6
6
  if (e === void 0) return;
7
7
  let t = Math.floor(Number(e));
8
8
  return Number.isFinite(t) && t >= 1 ? t : void 0;
9
9
  }
10
- function l(e) {
10
+ function u(e) {
11
11
  if (e === void 0) return;
12
12
  let t = Number(e);
13
13
  return Number.isFinite(t) && t >= 0 ? t : void 0;
14
14
  }
15
15
  //#endregion
16
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);
17
+ var d = globalThis.process?.env?.NODE_ENV !== "production";
18
+ function f(e, t = {}) {
19
+ d && typeof e != "function" && console.warn(`[useBatcher] Expected \`onFlush\` to be a function, received ${typeof e}.`);
20
+ let i = l(t?.maxSize), a = u(t?.maxWait), o = u(t?.quietPeriod);
21
+ d && t?.maxSize !== void 0 && i === void 0 && console.warn(`[useBatcher] \`maxSize\` (${String(t.maxSize)}) must be a positive integer — ignoring it.`), d && t?.maxWait !== void 0 && a === void 0 && console.warn(`[useBatcher] \`maxWait\` (${String(t.maxWait)}) must be a non-negative number — ignoring it.`), d && t?.quietPeriod !== void 0 && o === void 0 && console.warn(`[useBatcher] \`quietPeriod\` (${String(t.quietPeriod)}) must be a non-negative number — ignoring it.`), d && i === void 0 && a === void 0 && o === void 0 && console.warn("[useBatcher] No `maxSize`, `maxWait`, or `quietPeriod` configured — items will only flush when `flush()` is called manually."), d && a !== void 0 && o !== void 0 && o >= a && console.warn(`[useBatcher] \`quietPeriod\` (${o}ms) is not shorter than \`maxWait\` (${a}ms) — \`maxWait\` will almost always fire first, making \`quietPeriod\` unreachable in practice.`), d && t?.onItemsChange !== void 0 && typeof t.onItemsChange != "function" && console.warn("[useBatcher] `onItemsChange` must be a function — ignoring the provided value.");
22
+ let [f, p] = c(0), [m, h] = c(!1), g = s([]), _ = s(!1), v = s(null), y = s(null), b = s(e), x = s(typeof t?.onItemsChange == "function" ? t.onItemsChange : void 0);
23
23
  r(() => {
24
24
  b.current = e;
25
25
  }, [e]), r(() => {
@@ -47,14 +47,14 @@ function d(e, t = {}) {
47
47
  }
48
48
  a !== void 0 && (v.current = setTimeout(() => {
49
49
  v.current = null, w();
50
- }, a)), d !== void 0 && (y.current = setTimeout(() => {
50
+ }, a)), o !== void 0 && (y.current = setTimeout(() => {
51
51
  y.current = null, w();
52
- }, d));
52
+ }, o));
53
53
  }
54
54
  }, [
55
55
  i,
56
56
  a,
57
- d,
57
+ o,
58
58
  w
59
59
  ]);
60
60
  return {
@@ -67,14 +67,14 @@ function d(e, t = {}) {
67
67
  }
68
68
  t && a !== void 0 && (v.current = setTimeout(() => {
69
69
  v.current = null, w();
70
- }, a)), d !== void 0 && (y.current !== null && clearTimeout(y.current), y.current = setTimeout(() => {
70
+ }, a)), o !== void 0 && (y.current !== null && clearTimeout(y.current), y.current = setTimeout(() => {
71
71
  y.current = null, w();
72
- }, d));
72
+ }, o));
73
73
  }
74
74
  }, [
75
75
  i,
76
76
  a,
77
- d,
77
+ o,
78
78
  w,
79
79
  S
80
80
  ]),
@@ -89,35 +89,35 @@ function d(e, t = {}) {
89
89
  }
90
90
  //#endregion
91
91
  //#region src/performance/useDebouncer/useDebouncer.ts
92
- var f = globalThis.process?.env?.NODE_ENV !== "production";
93
- function p(e, t = {}) {
92
+ var p = globalThis.process?.env?.NODE_ENV !== "production";
93
+ function m(e, t = {}) {
94
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);
95
+ p && (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, o] = c(!1), l = t?.maxWait, u = !!t?.leading, d = t?.trailing ?? !0;
97
+ p && !u && !d && console.warn("[useDebouncer] Both `leading` and `trailing` are false — the debounced function will never be invoked."), p && 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 f = s(null), m = s(null), h = s(null), g = s(-1), _ = n(() => {
99
+ h.current !== null && (clearTimeout(h.current), h.current = null), g.current = -1, m.current = null, f.current = null, o(!1);
100
100
  }, []), v = n(() => {
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));
101
+ let e = f.current, t = m.current;
102
+ h.current === null || e === null || t === null || (clearTimeout(h.current), h.current = null, g.current = -1, m.current = null, f.current = null, o(!1), e(...t));
103
103
  }, []);
104
104
  return r(() => _, [_]), {
105
105
  run: n((e, ...t) => {
106
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;
107
+ if (f.current = e, m.current = t, g.current === -1 && (g.current = n, u)) {
108
+ let e = f.current, t = m.current;
109
109
  m.current = null, e(...t);
110
110
  }
111
- let r = p.current, a = m.current;
111
+ let r = f.current, a = m.current;
112
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);
113
+ h.current !== null && (clearTimeout(h.current), h.current = null), g.current = -1, m.current = null, f.current = null, o(!1), r(...a);
114
114
  return;
115
115
  }
116
116
  h.current !== null && clearTimeout(h.current), h.current = setTimeout(() => {
117
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);
118
+ let e = f.current, t = m.current;
119
+ g.current = -1, m.current = null, f.current = null, o(!1), d && e !== null && t !== null && e(...t);
120
+ }, i), o(d);
121
121
  }, [
122
122
  i,
123
123
  l,
@@ -131,18 +131,18 @@ function p(e, t = {}) {
131
131
  }
132
132
  //#endregion
133
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}.`);
137
- let a = o(e);
134
+ var h = globalThis.process?.env?.NODE_ENV !== "production";
135
+ function g(e, t, i = {}) {
136
+ h && typeof e != "function" && console.warn(`[useDebouncedCallback] Expected \`func\` to be a function, received ${typeof e}.`);
137
+ let a = s(e);
138
138
  r(() => {
139
139
  a.current = e;
140
140
  }, [e]);
141
- let { run: s, cancel: c, flush: l, isPending: u } = p(t, i);
141
+ let { run: o, cancel: c, flush: l, isPending: u } = m(t, i);
142
142
  return {
143
143
  debouncedFunc: n((...e) => {
144
- s(a.current, ...e);
145
- }, [s]),
144
+ o(a.current, ...e);
145
+ }, [o]),
146
146
  cancel: c,
147
147
  flush: l,
148
148
  isPending: u
@@ -150,32 +150,32 @@ function h(e, t, i = {}) {
150
150
  }
151
151
  //#endregion
152
152
  //#region src/shared/rateControlShared/utils.ts
153
- function g(e) {
153
+ function _(e) {
154
154
  return typeof e == "function";
155
155
  }
156
156
  //#endregion
157
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);
158
+ var v = globalThis.process?.env?.NODE_ENV !== "production";
159
+ function y(e, t, r = {}) {
160
+ v && 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, o] = c(e), l = s(a), { debouncedFunc: u, cancel: d, flush: f, isPending: p } = g(n((e) => {
162
+ o((t) => i(t, e) ? t : e);
163
163
  }, [i]), t, r);
164
164
  return [
165
165
  a,
166
166
  n((e) => {
167
- let t = g(e) ? e(l.current) : e;
167
+ let t = _(e) ? e(l.current) : e;
168
168
  l.current = t, u(t);
169
169
  }, [u]),
170
170
  {
171
171
  isPending: p,
172
172
  cancel: n(() => {
173
- d(), c((e) => (l.current = e, e));
173
+ d(), o((e) => (l.current = e, e));
174
174
  }, [d]),
175
175
  flush: f,
176
176
  forceSetValue: n((e) => {
177
- d(), c((t) => {
178
- let n = g(e) ? e(t) : e;
177
+ d(), o((t) => {
178
+ let n = _(e) ? e(t) : e;
179
179
  return l.current = n, n;
180
180
  });
181
181
  }, [d])
@@ -184,15 +184,15 @@ function v(e, t, r = {}) {
184
184
  }
185
185
  //#endregion
186
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) => {
187
+ var b = globalThis.process?.env?.NODE_ENV !== "production";
188
+ function x(e, t, n = {}) {
189
+ b && 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] = c(e), { debouncedFunc: s, cancel: l, flush: u, isPending: d } = g((e) => {
191
191
  o((t) => i(t, e) ? t : e);
192
192
  }, t, n);
193
193
  return r(() => {
194
- c(e);
195
- }, [e, c]), [a, {
194
+ s(e);
195
+ }, [e, s]), [a, {
196
196
  isPending: d,
197
197
  cancel: l,
198
198
  flush: u
@@ -200,43 +200,43 @@ function b(e, t, n = {}) {
200
200
  }
201
201
  //#endregion
202
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);
203
+ var S = globalThis.process?.env?.NODE_ENV !== "production";
204
+ function C(e, t, i) {
205
+ let a = Math.max(1, Math.floor(Number(e) || 1)), o = Math.max(0, Number(t) || 0);
206
+ S && (typeof e != "number" || !Number.isFinite(e) || e < 1) && console.warn(`[useRateLimiter] Received an invalid \`limit\` (${String(e)}) — falling back to ${a}.`), S && (typeof t != "number" || !Number.isFinite(t) || t < 0) && console.warn(`[useRateLimiter] Received an invalid \`windowMs\` (${String(t)}) — falling back to ${o}ms.`), S && o === 0 && console.warn("[useRateLimiter] `windowMs` is 0 — rate limiting is effectively disabled; every call will be allowed."), S && 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".`), S && i?.onRateLimitReached !== void 0 && typeof i.onRateLimitReached != "function" && console.warn("[useRateLimiter] `onRateLimitReached` must be a function — ignoring the provided value.");
207
+ let [l, u] = c(a), d = i?.refillStrategy === "gradual" ? "gradual" : "burst", f = s(typeof i?.onRateLimitReached == "function" ? i.onRateLimitReached : void 0);
208
208
  r(() => {
209
209
  f.current = typeof i?.onRateLimitReached == "function" ? i.onRateLimitReached : void 0;
210
210
  }, [i?.onRateLimitReached]);
211
- let p = o(a), m = o(Date.now()), h = o(null);
211
+ let p = s(a), m = s(Date.now()), h = s(null);
212
212
  r(() => () => {
213
213
  h.current !== null && clearTimeout(h.current);
214
214
  }, []);
215
215
  let g = n(() => {
216
- if (c === 0) {
216
+ if (o === 0) {
217
217
  p.current !== a && (p.current = a, u(a));
218
218
  return;
219
219
  }
220
220
  let e = Date.now(), t = e - m.current;
221
221
  if (d === "burst") {
222
- t >= c && p.current !== a && (p.current = a, m.current = e, u(a));
222
+ t >= o && p.current !== a && (p.current = a, m.current = e, u(a));
223
223
  return;
224
224
  }
225
- let n = c / a, r = Math.floor(t / n);
225
+ let n = o / a, r = Math.floor(t / n);
226
226
  r > 0 && (p.current = Math.min(a, p.current + r), m.current += r * n, u(p.current));
227
227
  }, [
228
228
  d,
229
- c,
229
+ o,
230
230
  a
231
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;
232
+ if (h.current !== null && (clearTimeout(h.current), h.current = null), p.current >= a || o === 0) return;
233
+ let t = o / a, n = Date.now() - m.current, r = d === "burst" ? o - n : t - n;
234
234
  h.current = setTimeout(() => {
235
235
  h.current = null, g(), e();
236
236
  }, Math.max(0, r));
237
237
  }, [
238
238
  a,
239
- c,
239
+ o,
240
240
  d,
241
241
  g
242
242
  ]), v = n(() => {
@@ -251,16 +251,16 @@ function S(e, t, i) {
251
251
  }
252
252
  //#endregion
253
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}.`);
257
- let s = o(e);
254
+ var w = globalThis.process?.env?.NODE_ENV !== "production";
255
+ function T(e, t, i, a) {
256
+ w && typeof e != "function" && console.warn(`[useRateLimitedCallback] Expected \`func\` to be a function, received ${typeof e}.`);
257
+ let o = s(e);
258
258
  r(() => {
259
- s.current = e;
259
+ o.current = e;
260
260
  }, [e]);
261
- let { run: c, reset: l, remaining: u, isRateLimited: d } = S(t, i, a);
261
+ let { run: c, reset: l, remaining: u, isRateLimited: d } = C(t, i, a);
262
262
  return {
263
- rateLimitedFunc: n((...e) => c(s.current, ...e), [c]),
263
+ rateLimitedFunc: n((...e) => c(o.current, ...e), [c]),
264
264
  reset: l,
265
265
  remaining: u,
266
266
  isRateLimited: d
@@ -268,15 +268,15 @@ function w(e, t, i, a) {
268
268
  }
269
269
  //#endregion
270
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;
271
+ var E = globalThis.process?.env?.NODE_ENV !== "production";
272
+ function D(e, t, r, i = {}) {
273
+ E && 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, s] = c(e), l = n((e) => {
275
+ s((t) => {
276
+ let n = _(e) ? e(t) : e;
277
277
  return a(t, n) ? t : n;
278
278
  });
279
- }, [a]), { rateLimitedFunc: u, reset: d, remaining: f, isRateLimited: p } = w(l, t, r, i);
279
+ }, [a]), { rateLimitedFunc: u, reset: d, remaining: f, isRateLimited: p } = T(l, t, r, i);
280
280
  return [
281
281
  o,
282
282
  n((e) => u(e), [u]),
@@ -292,19 +292,19 @@ function E(e, t, r, i = {}) {
292
292
  }
293
293
  //#endregion
294
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) => {
295
+ var O = globalThis.process?.env?.NODE_ENV !== "production";
296
+ function k(e, t, n, i = {}) {
297
+ O && 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, [o, l] = c(e), { rateLimitedFunc: u, reset: d, remaining: f, isRateLimited: p } = T((e) => {
299
299
  l((t) => a(t, e) ? t : e);
300
- }, t, n, i), m = o(!0);
300
+ }, t, n, i), m = s(!0);
301
301
  return r(() => {
302
302
  if (m.current) {
303
303
  m.current = !1;
304
304
  return;
305
305
  }
306
306
  u(e);
307
- }, [e, u]), [c, {
307
+ }, [e, u]), [o, {
308
308
  remaining: f,
309
309
  isRateLimited: p,
310
310
  reset: d
@@ -312,17 +312,17 @@ function O(e, t, n, i = {}) {
312
312
  }
313
313
  //#endregion
314
314
  //#region src/performance/useThrottler/useThrottler.ts
315
- var k = globalThis.process?.env?.NODE_ENV !== "production";
316
- function A(e, t = {}) {
315
+ var A = globalThis.process?.env?.NODE_ENV !== "production";
316
+ function j(e, t = {}) {
317
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.");
321
- let d = o(null), f = o(null), p = o(null), m = o(-1), h = n(() => {
322
- p.current !== null && (clearTimeout(p.current), p.current = null), m.current = -1, f.current = null, d.current = null, c(!1);
318
+ A && (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, o] = c(!1), l = t?.leading ?? !0, u = t?.trailing ?? !0;
320
+ A && !l && !u && console.warn("[useThrottler] Both `leading` and `trailing` are false — the throttled function will never be invoked.");
321
+ let d = s(null), f = s(null), p = s(null), m = s(-1), h = n(() => {
322
+ p.current !== null && (clearTimeout(p.current), p.current = null), m.current = -1, f.current = null, d.current = null, o(!1);
323
323
  }, []), g = n(() => {
324
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));
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, o(!1), e(...t));
326
326
  }, [l]);
327
327
  return r(() => h, [h]), {
328
328
  run: n((e, ...t) => {
@@ -331,7 +331,7 @@ function A(e, t = {}) {
331
331
  if (f.current = t, d.current = e, m.current === -1 ? l : n - m.current >= i) {
332
332
  p.current !== null && (clearTimeout(p.current), p.current = null);
333
333
  let e = d.current, t = f.current;
334
- m.current = n, f.current = null, c(!1), e(...t);
334
+ m.current = n, f.current = null, o(!1), e(...t);
335
335
  return;
336
336
  }
337
337
  if (p.current === null) {
@@ -339,10 +339,10 @@ function A(e, t = {}) {
339
339
  p.current = setTimeout(() => {
340
340
  p.current = null;
341
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;
342
+ f.current = null, d.current = null, o(!1), u && e !== null && t !== null ? (m.current = l ? Date.now() : -1, e(...t)) : m.current = -1;
343
343
  }, Math.max(0, t));
344
344
  }
345
- c(u);
345
+ o(u);
346
346
  }, [
347
347
  i,
348
348
  l,
@@ -355,18 +355,18 @@ function A(e, t = {}) {
355
355
  }
356
356
  //#endregion
357
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}.`);
361
- let a = o(e);
358
+ var M = globalThis.process?.env?.NODE_ENV !== "production";
359
+ function N(e, t, i = {}) {
360
+ M && typeof e != "function" && console.warn(`[useThrottledCallback] Expected \`func\` to be a function, received ${typeof e}.`);
361
+ let a = s(e);
362
362
  r(() => {
363
363
  a.current = e;
364
364
  }, [e]);
365
- let { run: s, cancel: c, flush: l, isPending: u } = A(t, i);
365
+ let { run: o, cancel: c, flush: l, isPending: u } = j(t, i);
366
366
  return {
367
367
  throttledFunc: n((...e) => {
368
- s(a.current, ...e);
369
- }, [s]),
368
+ o(a.current, ...e);
369
+ }, [o]),
370
370
  cancel: c,
371
371
  flush: l,
372
372
  isPending: u
@@ -374,27 +374,27 @@ function M(e, t, i = {}) {
374
374
  }
375
375
  //#endregion
376
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);
377
+ var P = globalThis.process?.env?.NODE_ENV !== "production";
378
+ function ee(e, t, r = {}) {
379
+ P && 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, o] = c(e), l = s(a), { throttledFunc: u, cancel: d, flush: f, isPending: p } = N(n((e) => {
381
+ o((t) => i(t, e) ? t : e);
382
382
  }, [i]), t, r);
383
383
  return [
384
384
  a,
385
385
  n((e) => {
386
- let t = g(e) ? e(l.current) : e;
386
+ let t = _(e) ? e(l.current) : e;
387
387
  l.current = t, u(t);
388
388
  }, [u]),
389
389
  {
390
390
  isPending: p,
391
391
  cancel: n(() => {
392
- d(), c((e) => (l.current = e, e));
392
+ d(), o((e) => (l.current = e, e));
393
393
  }, [d]),
394
394
  flush: f,
395
395
  forceSetValue: n((e) => {
396
- d(), c((t) => {
397
- let n = g(e) ? e(t) : e;
396
+ d(), o((t) => {
397
+ let n = _(e) ? e(t) : e;
398
398
  return l.current = n, n;
399
399
  });
400
400
  }, [d])
@@ -403,44 +403,265 @@ function P(e, t, r = {}) {
403
403
  }
404
404
  //#endregion
405
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) => {
406
+ var te = globalThis.process?.env?.NODE_ENV !== "production";
407
+ function F(e, t, n = {}) {
408
+ te && 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] = c(e), { throttledFunc: s, cancel: l, flush: u, isPending: d } = N((e) => {
410
410
  o((t) => i(t, e) ? t : e);
411
411
  }, t, n);
412
412
  return r(() => {
413
- c(e);
414
- }, [e, c]), [a, {
413
+ s(e);
414
+ }, [e, s]), [a, {
415
415
  isPending: d,
416
416
  cancel: l,
417
417
  flush: u
418
418
  }];
419
419
  }
420
420
  //#endregion
421
+ //#region src/performance/useIntersectionObserver/utils.ts
422
+ function I(e) {
423
+ return e ? typeof e == "function" ? e() : "current" in e ? e.current : e : null;
424
+ }
425
+ //#endregion
426
+ //#region src/performance/useIntersectionObserver/useIntersectionObserver.ts
427
+ function ne(e = {}) {
428
+ let { target: t, root: r = null, rootMargin: l = "0px", threshold: u = 0, enabled: d = !0, freezeOnceVisible: f = !1, initialIsIntersecting: p = !1, debounceMs: m = 0, onChange: h } = e, [_, v] = c(null), y = n((e) => {
429
+ v(e);
430
+ }, []), b = t === void 0 ? void 0 : I(t), x = b === void 0 ? _ : b, [S, C] = c(p), [w, T] = c(0), [E, D] = c(void 0), O = s(!1), k = s({
431
+ freezeOnceVisible: f,
432
+ onChange: h
433
+ });
434
+ a(() => {
435
+ k.current = {
436
+ freezeOnceVisible: f,
437
+ onChange: h
438
+ };
439
+ });
440
+ let A = n((e) => {
441
+ if (O.current) return;
442
+ let { freezeOnceVisible: t, onChange: n } = k.current, r = e.isIntersecting;
443
+ D(e), C((e) => e === r ? e : r), T((t) => t === e.intersectionRatio ? t : e.intersectionRatio), n?.(r, e), t && r && (O.current = !0);
444
+ }, []), { debouncedFunc: j } = g(A, m), M = i((e) => {
445
+ m > 0 ? j(e) : A(e);
446
+ });
447
+ a(() => {
448
+ O.current = !1;
449
+ }, [x]);
450
+ let N = o(() => u, [JSON.stringify(u)]);
451
+ return a(() => {
452
+ if (!x || !d || typeof IntersectionObserver > "u" || O.current) return;
453
+ let e = new IntersectionObserver((e) => {
454
+ let t = e[e.length - 1];
455
+ t && M(t);
456
+ }, {
457
+ root: r,
458
+ rootMargin: l,
459
+ threshold: N
460
+ });
461
+ return e.observe(x), () => e.disconnect();
462
+ }, [
463
+ x,
464
+ r,
465
+ l,
466
+ N,
467
+ d
468
+ ]), {
469
+ ref: y,
470
+ isIntersecting: S,
471
+ intersectionRatio: w,
472
+ entry: E
473
+ };
474
+ }
475
+ //#endregion
476
+ //#region src/performance/useMutationObserver/constants.ts
477
+ var re = [];
478
+ //#endregion
479
+ //#region src/performance/useMutationObserver/utils.ts
480
+ function ie(e) {
481
+ return e ? typeof e == "function" ? e() : "current" in e ? e.current : e : null;
482
+ }
483
+ //#endregion
484
+ //#region src/performance/useMutationObserver/useMutationObserver.ts
485
+ function L(e = {}) {
486
+ let { target: t, enabled: r = !0, debounceMs: l = 0, onMutate: u, childList: d = !0, attributes: f = !1, attributeFilter: p, attributeOldValue: m = !1, characterData: h = !1, characterDataOldValue: _ = !1, subtree: v = !1 } = e, [y, b] = c(null), x = n((e) => {
487
+ b(e);
488
+ }, []), S = t === void 0 ? void 0 : ie(t), C = S === void 0 ? y : S, [w, T] = c(re), E = s(null), D = s(u);
489
+ a(() => {
490
+ D.current = u;
491
+ });
492
+ let O = n((e, t) => {
493
+ T(e), D.current?.(e, t);
494
+ }, []), { debouncedFunc: k } = g(O, l), A = i((e, t) => {
495
+ l > 0 ? k(e, t) : O(e, t);
496
+ }), j = o(() => p, [JSON.stringify(p)]);
497
+ return a(() => {
498
+ if (!C || !r || typeof MutationObserver > "u") return;
499
+ let e = new MutationObserver((e, t) => {
500
+ A(e, t);
501
+ });
502
+ return E.current = e, e.observe(C, {
503
+ childList: d,
504
+ attributes: f,
505
+ attributeOldValue: m,
506
+ characterData: h,
507
+ characterDataOldValue: _,
508
+ subtree: v,
509
+ ...j === void 0 ? {} : { attributeFilter: j }
510
+ }), () => {
511
+ e.disconnect(), E.current = null;
512
+ };
513
+ }, [
514
+ C,
515
+ r,
516
+ d,
517
+ f,
518
+ m,
519
+ h,
520
+ _,
521
+ v,
522
+ j
523
+ ]), {
524
+ ref: x,
525
+ records: w,
526
+ takeRecords: n(() => E.current?.takeRecords() ?? [], [])
527
+ };
528
+ }
529
+ //#endregion
530
+ //#region src/performance/useResizeObserver/constants.ts
531
+ var R = {
532
+ width: 0,
533
+ height: 0
534
+ };
535
+ //#endregion
536
+ //#region src/performance/useResizeObserver/utils.ts
537
+ function z(e) {
538
+ return e ? typeof e == "function" ? e() : "current" in e ? e.current : e : null;
539
+ }
540
+ function B(e) {
541
+ return e instanceof Document ? e.scrollingElement ?? e.documentElement : e;
542
+ }
543
+ function V(e, t) {
544
+ if (t === "border-box") {
545
+ let t = e.borderBoxSize?.[0];
546
+ if (t) return {
547
+ width: t.inlineSize,
548
+ height: t.blockSize
549
+ };
550
+ }
551
+ if (t === "device-pixel-content-box") {
552
+ let t = e.devicePixelContentBoxSize?.[0];
553
+ if (t) return {
554
+ width: t.inlineSize,
555
+ height: t.blockSize
556
+ };
557
+ }
558
+ let n = e.contentBoxSize?.[0];
559
+ return n ? {
560
+ width: n.inlineSize,
561
+ height: n.blockSize
562
+ } : {
563
+ width: e.contentRect.width,
564
+ height: e.contentRect.height
565
+ };
566
+ }
567
+ function ae() {
568
+ return {
569
+ width: document.documentElement.clientWidth,
570
+ height: document.documentElement.clientHeight
571
+ };
572
+ }
573
+ function oe(e, t) {
574
+ return e.width === t.width && e.height === t.height;
575
+ }
576
+ //#endregion
577
+ //#region src/performance/useResizeObserver/useResizeObserver.ts
578
+ function se(e = {}) {
579
+ let { target: t, box: r = "content-box", enabled: o = !0, round: l = !1, debounceMs: u = 0, initialSize: d, onResize: f } = e, [p, m] = c(null), h = n((e) => {
580
+ m(e);
581
+ }, []), _ = t === void 0 ? void 0 : z(t), v = _ === void 0 ? p : _, [y, b] = c(() => d ?? R), [x, S] = c(void 0), C = s(null), w = s({
582
+ round: l,
583
+ onResize: f
584
+ });
585
+ a(() => {
586
+ w.current = {
587
+ round: l,
588
+ onResize: f
589
+ };
590
+ });
591
+ let T = n((e, t) => {
592
+ let { round: n, onResize: r } = w.current, i = n ? {
593
+ width: Math.round(e.width),
594
+ height: Math.round(e.height)
595
+ } : e;
596
+ (!C.current || !oe(C.current, i)) && (C.current = i, b(i), S(t)), r?.(i, t);
597
+ }, []), { debouncedFunc: E } = g(T, u), D = i((e, t) => {
598
+ u > 0 ? E(e, t) : T(e, t);
599
+ });
600
+ return a(() => {
601
+ if (!v || !o || typeof ResizeObserver > "u") return;
602
+ if (v instanceof Window) {
603
+ let e = () => {
604
+ D(ae(), void 0);
605
+ };
606
+ return e(), v.addEventListener("resize", e, { passive: !0 }), () => v.removeEventListener("resize", e);
607
+ }
608
+ let e = B(v);
609
+ if (!e) return;
610
+ let t = new ResizeObserver((e) => {
611
+ let t = e[e.length - 1];
612
+ t && D(V(t, r), t);
613
+ });
614
+ return t.observe(e, { box: r }), () => t.disconnect();
615
+ }, [
616
+ v,
617
+ r,
618
+ o
619
+ ]), {
620
+ ref: h,
621
+ width: y.width,
622
+ height: y.height,
623
+ entry: x
624
+ };
625
+ }
626
+ //#endregion
421
627
  //#region src/shared/virtualShared/offsetCache.ts
422
- var L = class {
628
+ var ce = class {
423
629
  _offsets = /* @__PURE__ */ new Float64Array();
424
630
  _count = 0;
425
- initializeOffsets(e, t) {
426
- this._count = e, this._offsets = new Float64Array(e + 1);
427
- let n = 0;
428
- for (let r = 0; r < e; r++) {
429
- this._offsets[r] = n;
430
- let e = t(r);
431
- n += Number.isFinite(e) && e >= 0 ? e : 0;
631
+ _gap = 0;
632
+ initializeOffsets(e, t, n = 0) {
633
+ this._count = e, this._gap = Math.max(0, n), this._offsets = new Float64Array(e + 1);
634
+ let r = 0;
635
+ for (let n = 0; n < e; n++) {
636
+ this._offsets[n] = r;
637
+ let i = t(n);
638
+ r += (Number.isFinite(i) && i >= 0 ? i : 0) + (n < e - 1 ? this._gap : 0);
432
639
  }
433
- this._offsets[e] = n;
640
+ this._offsets[e] = r;
434
641
  }
435
642
  getItemStartOffset(e) {
436
643
  return e <= 0 ? 0 : e >= this._count ? this._offsets[this._count] ?? 0 : this._offsets[e] ?? 0;
437
644
  }
438
645
  getItemSize(e) {
439
- return e < 0 || e >= this._count ? 0 : (this._offsets[e + 1] ?? 0) - (this._offsets[e] ?? 0);
646
+ if (e < 0 || e >= this._count) return 0;
647
+ let t = e < this._count - 1 ? this._gap : 0;
648
+ return (this._offsets[e + 1] ?? 0) - (this._offsets[e] ?? 0) - t;
440
649
  }
441
650
  getTotalSize() {
442
651
  return this._offsets[this._count] ?? 0;
443
652
  }
653
+ applyMeasurements(e) {
654
+ if (e.size === 0 || this._count === 0) return !1;
655
+ let t = this._count;
656
+ for (let n of e.keys()) n >= 0 && n < this._count && n < t && (t = n);
657
+ if (t >= this._count) return !1;
658
+ let n = !1, r = this._offsets[t] ?? 0;
659
+ for (let i = t; i < this._count; i++) {
660
+ let t = i < this._count - 1 ? this._gap : 0, a = (this._offsets[i + 1] ?? 0) - (this._offsets[i] ?? 0) - t, o = e.get(i), s = o === void 0 ? a : Number.isFinite(o) && o >= 0 ? o : 0;
661
+ (this._offsets[i] ?? 0) !== r && (n = !0), s !== a && (n = !0), this._offsets[i] = r, r += s + t;
662
+ }
663
+ return (this._offsets[this._count] ?? 0) !== r && (n = !0), this._offsets[this._count] = r, n;
664
+ }
444
665
  updateItemSize(e, t) {
445
666
  if (e < 0 || e >= this._count) return;
446
667
  let n = (Number.isFinite(t) && t >= 0 ? t : 0) - this.getItemSize(e);
@@ -465,9 +686,9 @@ var L = class {
465
686
  return t;
466
687
  }
467
688
  getPhysicalStartReverse(e, t) {
468
- return t - (this._offsets[e + 1] ?? 0);
689
+ return t - ((this._offsets[e] ?? 0) + this.getItemSize(e));
469
690
  }
470
- findStartIndexReverse(e, t) {
691
+ findTopIndexReverse(e, t) {
471
692
  if (this._count === 0) return 0;
472
693
  let n = t - e, r = 0, i = this._count - 1;
473
694
  for (; r < i;) {
@@ -476,7 +697,7 @@ var L = class {
476
697
  }
477
698
  return (this._offsets[r] ?? 0) >= n ? 0 : r;
478
699
  }
479
- findEndIndexReverse(e, t) {
700
+ findBottomIndexReverse(e, t) {
480
701
  if (this._count === 0) return -1;
481
702
  let n = t - e, r = 0, i = this._count - 1;
482
703
  for (; r < i;) {
@@ -488,288 +709,438 @@ var L = class {
488
709
  };
489
710
  //#endregion
490
711
  //#region src/shared/virtualShared/utils.ts
491
- function R(e, t) {
712
+ function H(e, t) {
492
713
  let n = typeof t == "function" ? t(e) : t, r = Number(n);
493
714
  return Number.isFinite(r) && r >= 0 ? r : 0;
494
715
  }
495
- function z(e, t, n) {
716
+ function le(e, t, n, r = 0) {
496
717
  if (e <= 0) return 0;
497
- if (typeof t == "number") return e * Math.max(0, t);
718
+ let i = Math.max(0, r);
719
+ if (typeof t == "number") return e * (Math.max(0, t) + i);
498
720
  if (n) return n.getItemStartOffset(e);
499
- let r = 0;
500
- for (let n = 0; n < e; n++) r += R(n, t);
501
- return r;
721
+ let a = 0;
722
+ for (let n = 0; n < e; n++) a += H(n, t) + i;
723
+ return a;
502
724
  }
503
- function B(e, t, n) {
725
+ function U(e, t, n, r = 0) {
504
726
  if (e <= 0) return 0;
505
- if (typeof t == "number") return e * Math.max(0, t);
727
+ let i = Math.max(0, r);
728
+ if (typeof t == "number") return e * Math.max(0, t) + (e - 1) * i;
506
729
  if (n) return n.getTotalSize();
507
- let r = 0;
508
- for (let n = 0; n < e; n++) r += R(n, t);
509
- return r;
730
+ let a = 0;
731
+ for (let n = 0; n < e; n++) a += H(n, t);
732
+ return a + (e - 1) * i;
510
733
  }
511
- function V(e, t) {
734
+ function ue(e, t) {
512
735
  if (!e) return 0;
513
736
  let n = t === "vertical";
514
737
  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;
515
738
  }
516
- function H(e, t) {
739
+ function de(e, t) {
517
740
  if (!e) return 0;
518
741
  let n = t === "vertical";
519
742
  return e instanceof Window ? n ? e.scrollY : e.scrollX : e instanceof Document ? n ? e.documentElement.scrollTop : e.documentElement.scrollLeft : n ? e.scrollTop : e.scrollLeft;
520
743
  }
521
- function U(e) {
744
+ function W(e) {
522
745
  return e ? e instanceof Window ? document.documentElement : e instanceof Document ? e.scrollingElement ?? e.documentElement : e : null;
523
746
  }
524
747
  //#endregion
525
748
  //#region src/performance/useVirtualGrid/utils.ts
526
- function W(e, t, n, r, i, a) {
749
+ function fe(e, t, n, r, i, a, o = 0) {
527
750
  if (n <= 0 || t <= 0) return {
528
751
  startIndex: 0,
529
752
  endIndex: -1
530
753
  };
531
- let o, s;
754
+ let s = Math.max(0, o), c, l;
532
755
  if (typeof r == "number") {
533
- let i = Math.max(0, r);
534
- 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));
756
+ let i = Math.max(0, r) + s;
757
+ i === 0 ? (c = 0, l = n - 1) : (c = Math.max(0, Math.floor(e / i)), l = Math.min(n - 1, Math.ceil((e + t) / i) - 1));
535
758
  } else if (a) {
536
759
  let n = e + t;
537
- o = a.findStartIndex(e), s = a.findEndIndex(n);
760
+ c = a.findStartIndex(e), l = a.findEndIndex(n);
538
761
  } else {
539
- o = 0, s = -1;
762
+ c = 0, l = -1;
540
763
  let i = 0, a = !1;
541
- for (let c = 0; c < n; c++) {
542
- let n = R(c, r), l = i + n;
543
- if (!a && l > e && (o = c, a = !0), a) if (i < e + t) s = c;
764
+ for (let o = 0; o < n; o++) {
765
+ let u = H(o, r), d = i + u;
766
+ if (!a && d > e && (c = o, a = !0), a) if (i < e + t) l = o;
544
767
  else break;
545
- i += n;
768
+ i += u + (o < n - 1 ? s : 0);
546
769
  }
547
- a || (o = 0, s = -1);
770
+ a || (c = 0, l = -1);
548
771
  }
549
- return o = Math.max(0, o - i), s = Math.min(n - 1, s + i), {
550
- startIndex: o,
551
- endIndex: s
552
- };
772
+ return l < c ? {
773
+ startIndex: 0,
774
+ endIndex: -1
775
+ } : (c = Math.max(0, c - i), l = Math.min(n - 1, l + i), {
776
+ startIndex: c,
777
+ endIndex: l
778
+ });
553
779
  }
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;
780
+ function G(e, t, n, r, i, a, o, s = 0) {
781
+ let c = o ? o.getItemSize(e) : H(e, a), l = le(e, a, o, s), u = l + c, d = Math.max(0, r - n), f;
556
782
  switch (t) {
557
783
  case "start":
558
- d = c;
784
+ f = l;
559
785
  break;
560
786
  case "end":
561
- d = Math.max(0, l - n);
787
+ f = Math.max(0, u - n);
562
788
  break;
563
789
  case "center":
564
- d = Math.max(0, c + s / 2 - n / 2);
790
+ f = Math.max(0, l + c / 2 - n / 2);
565
791
  break;
566
792
  default:
567
- if (c >= i && l <= i + n) return i;
568
- d = c < i ? c : Math.max(0, l - n);
793
+ if (l >= i && u <= i + n) return i;
794
+ f = l < i ? l : Math.max(0, u - n);
569
795
  break;
570
796
  }
571
- return Math.max(0, Math.min(d, u));
797
+ return Math.max(0, Math.min(f, d));
572
798
  }
573
799
  //#endregion
574
800
  //#region src/performance/useVirtualGrid/useVirtualGrid.ts
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);
577
- i(() => {
578
- O.current = t;
801
+ function K(e) {
802
+ return Number.isFinite(e) ? Math.max(0, Math.trunc(e)) : 0;
803
+ }
804
+ function q(e) {
805
+ return e !== void 0 && Number.isFinite(e) ? Math.max(0, e) : 0;
806
+ }
807
+ function J(e, t, n, r) {
808
+ let i = de(e, t);
809
+ return Math.max(0, (n && t === "horizontal" ? Math.abs(i) : i) - r);
810
+ }
811
+ function Y(e, t, n, r) {
812
+ let i = e + r;
813
+ return n && t === "horizontal" ? -i : i;
814
+ }
815
+ function pe(e) {
816
+ let t;
817
+ for (let n of e.values()) (t === void 0 || n > t) && (t = n);
818
+ return t;
819
+ }
820
+ function X(t) {
821
+ let { rowCount: i, colCount: l, estimateRowHeight: u, estimateColumnWidth: d, getScrollElement: f, overscanRows: p = 3, overscanCols: m = 3, rowGap: h = 0, columnGap: _ = 0, scrollMarginTop: v = 0, scrollMarginLeft: y = 0, isRtl: b = !1, enabled: x = !0, pauseWhenOffscreen: S = !1, scrollingDelay: C = 150, initialViewportHeight: w = 0, initialViewportWidth: T = 0, initialScrollTop: E, initialScrollLeft: D, initialScrollRow: O, initialScrollCol: k, initialRowAlign: A = "start", initialColAlign: j = "start", itemKey: M } = t, N = K(i), P = K(l), ee = K(p), te = K(m), F = q(h), I = q(_), re = q(v), ie = q(y), L = s(t);
822
+ a(() => {
823
+ L.current = t;
579
824
  });
580
- let k = a(() => {
825
+ let R = o(() => {
581
826
  if (typeof u != "function") return;
582
- let e = new L();
583
- return e.initializeOffsets(w, u), e;
584
- }, [w, u]), A = a(() => {
827
+ let e = new ce();
828
+ return e.initializeOffsets(N, u, F), e;
829
+ }, [
830
+ N,
831
+ u,
832
+ F
833
+ ]), z = o(() => {
585
834
  if (typeof d != "function") return;
586
- let e = new L();
587
- return e.initializeOffsets(T, d), e;
588
- }, [T, d]), j = o(k), M = o(A);
589
- i(() => {
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);
835
+ let e = new ce();
836
+ return e.initializeOffsets(P, d, I), e;
837
+ }, [
838
+ P,
839
+ d,
840
+ I
841
+ ]), B = s(R), V = s(z);
842
+ a(() => {
843
+ B.current = R;
844
+ }, [R]), a(() => {
845
+ V.current = z;
846
+ }, [z]);
847
+ let [ae, oe] = c(() => {
848
+ if (typeof E == "number") return Math.max(0, E);
849
+ if (typeof O == "number" && N > 0) {
850
+ let e = Math.max(0, Math.min(K(O), N - 1)), t = U(N, u, R, F);
851
+ return G(e, A, w, t, 0, u, R, F);
599
852
  }
600
853
  return 0;
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);
854
+ }), [de, X] = c(() => {
855
+ if (typeof D == "number") return Math.max(0, D);
856
+ if (typeof k == "number" && P > 0) {
857
+ let e = Math.max(0, Math.min(K(k), P - 1)), t = U(P, d, z, I);
858
+ return G(e, j, T, t, 0, d, z, I);
606
859
  }
607
860
  return 0;
608
- }), [K, q] = s(!1), [, J] = s({}), Y = o(!1), { debouncedFunc: X } = h(() => q(!1), g), Z = f();
609
- r(() => {
861
+ }), [me, he] = c(!1), [, ge] = c(0), _e = s(!1), { debouncedFunc: ve } = g(() => he(!1), C), Z = f();
862
+ a(() => {
610
863
  if (!Z) return;
611
- if (!Y.current) {
612
- Y.current = !0;
613
- let e = typeof y == "number" || typeof x == "number", t = typeof b == "number" || typeof S == "number";
864
+ if (!_e.current) {
865
+ _e.current = !0;
866
+ let e = typeof E == "number" || typeof O == "number", t = typeof D == "number" || typeof k == "number";
614
867
  if (e || t) {
615
- let n = U(Z);
616
- n && n.scrollTo({
617
- ...e && { top: N },
618
- ...t && { left: F },
619
- behavior: "auto"
620
- });
868
+ let n = W(Z);
869
+ if (n) {
870
+ let r = { behavior: "auto" };
871
+ e && (r.top = Y(ae, "vertical", b, re)), t && (r.left = Y(de, "horizontal", b, ie)), n.scrollTo(r);
872
+ }
621
873
  return;
622
874
  }
623
875
  }
624
- let e = H(Z, "vertical"), t = H(Z, "horizontal");
625
- P((t) => t === e ? t : e), I((e) => e === t ? e : t);
876
+ let e = J(Z, "vertical", b, re), t = J(Z, "horizontal", b, ie);
877
+ oe((t) => t === e ? t : e), X((e) => e === t ? e : t);
626
878
  }, [
627
879
  Z,
628
- y,
629
880
  b,
630
- x,
631
- S,
632
- N,
633
- F
881
+ re,
882
+ ie
634
883
  ]);
635
- function ee() {
636
- let { getScrollElement: e, scrollingDelay: t } = O.current, n = e();
637
- if (!n) return;
638
- let r = H(n, "vertical"), i = H(n, "horizontal");
639
- P(r), I(i), (t ?? 150) > 0 && (q(!0), X());
884
+ function ye() {
885
+ let { getScrollElement: e, isRtl: t, scrollMarginTop: n, scrollMarginLeft: r } = L.current, i = e();
886
+ if (!i) return;
887
+ let a = J(i, "vertical", t ?? !1, q(n)), o = J(i, "horizontal", t ?? !1, q(r));
888
+ oe(a), X(o), he(!0), ve();
889
+ }
890
+ let be = S === !1 ? null : S === !0 ? {} : S;
891
+ function xe() {
892
+ let e = f();
893
+ return e instanceof Window || e instanceof Document ? null : e;
640
894
  }
641
- e("scroll", ee, {
642
- target: Z,
895
+ let { isIntersecting: Se } = ne({
896
+ target: xe,
897
+ enabled: be !== null,
898
+ root: be?.root,
899
+ rootMargin: be?.rootMargin,
900
+ initialIsIntersecting: !0
901
+ }), Ce = x && (be === null || Se);
902
+ e("scroll", ye, {
903
+ target: Ce ? Z : null,
643
904
  passive: !0
644
- }), r(() => {
645
- if (!Z) return;
646
- let e = () => J({});
647
- if (Z instanceof Window) return Z.addEventListener("resize", e), () => Z.removeEventListener("resize", e);
648
- let t = new ResizeObserver(e), n = Z instanceof Document ? Z.documentElement : Z;
649
- return t.observe(n), () => t.disconnect();
650
- }, [Z]);
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 = [];
652
- if (Q <= ae && $ <= oe) {
653
- let e = k ? k.getItemStartOffset(Q) : z(Q, u);
654
- for (let t = Q; t <= ae; t++) {
655
- let n = k ? k.getItemSize(t) : R(t, u), r = A ? A.getItemStartOffset($) : z($, d);
656
- for (let i = $; i <= oe; i++) {
657
- let a = A ? A.getItemSize(i) : R(i, d), o = C ? C(t, i) : `${t}:${i}`;
658
- se.push({
659
- key: o,
905
+ });
906
+ let { width: we, height: Te } = se({
907
+ target: f,
908
+ enabled: Ce
909
+ }), Ee = Te || w, De = we || T, Oe = U(N, u, R, F), ke = U(P, d, z, I), { startIndex: Q, endIndex: Ae } = fe(ae, Ee, N, u, ee, R, F), { startIndex: $, endIndex: je } = fe(de, De, P, d, te, z, I), Me = [];
910
+ if (Q <= Ae && $ <= je) {
911
+ let e = R ? R.getItemStartOffset(Q) : le(Q, u, void 0, F);
912
+ for (let t = Q; t <= Ae; t++) {
913
+ let n = R ? R.getItemSize(t) : H(t, u), r = e + n, i = z ? z.getItemStartOffset($) : le($, d, void 0, I);
914
+ for (let a = $; a <= je; a++) {
915
+ let o = z ? z.getItemSize(a) : H(a, d), s = i + o, c = M ? M(t, a) : `${t}:${a}`;
916
+ Me.push({
917
+ key: c,
660
918
  rowIndex: t,
661
- colIndex: i,
919
+ colIndex: a,
662
920
  height: n,
663
- width: a,
921
+ width: o,
664
922
  top: e,
665
- left: r
666
- }), r += a;
923
+ left: i,
924
+ bottom: r,
925
+ right: s
926
+ }), i += o + (a < P - 1 ? I : 0);
667
927
  }
668
- e += n;
928
+ e += n + (t < N - 1 ? F : 0);
669
929
  }
670
930
  }
671
- return {
672
- virtualCells: se,
673
- totalHeight: re,
674
- totalWidth: ie,
675
- isScrolling: K,
931
+ let Ne = s(/* @__PURE__ */ new Map()), Pe = s(/* @__PURE__ */ new Map()), Fe = s(/* @__PURE__ */ new Map()), Ie = s(/* @__PURE__ */ new Map()), Le = s(/* @__PURE__ */ new WeakMap()), Re = s(null), ze = s({
932
+ startIndex: Q,
933
+ endIndex: Ae
934
+ }), Be = s({
935
+ startIndex: $,
936
+ endIndex: je
937
+ });
938
+ r(() => () => {
939
+ Re.current?.disconnect(), Re.current = null;
940
+ }, []);
941
+ function Ve(e, t, n) {
942
+ let r = n.getBoundingClientRect(), i = Fe.current.get(e);
943
+ i || (i = /* @__PURE__ */ new Map(), Fe.current.set(e, i)), i.set(t, r.height);
944
+ let a = Ie.current.get(t);
945
+ a || (a = /* @__PURE__ */ new Map(), Ie.current.set(t, a)), a.set(e, r.width);
946
+ let o = pe(i), s = pe(a);
947
+ o !== void 0 && Ne.current.set(e, o), s !== void 0 && Pe.current.set(t, s);
948
+ }
949
+ function He(e, t) {
950
+ let n = Fe.current.get(e);
951
+ if (n) if (n.delete(t), n.size === 0) Fe.current.delete(e);
952
+ else {
953
+ let t = pe(n);
954
+ t !== void 0 && Ne.current.set(e, t);
955
+ }
956
+ let r = Ie.current.get(t);
957
+ if (r) if (r.delete(e), r.size === 0) Ie.current.delete(t);
958
+ else {
959
+ let e = pe(r);
960
+ e !== void 0 && Pe.current.set(t, e);
961
+ }
962
+ }
963
+ function Ue(e, t, n) {
964
+ if (e.size === 0 || !t) return 0;
965
+ let r = 0;
966
+ for (let [i, a] of e) i < n.startIndex && (r += a - t.getItemSize(i));
967
+ return r;
968
+ }
969
+ function We() {
970
+ let e = Ne.current.size > 0, t = Pe.current.size > 0;
971
+ if (!e && !t) return;
972
+ let n = Ue(Ne.current, B.current, ze.current), r = Ue(Pe.current, V.current, Be.current), i = !1, a = !1;
973
+ if (B.current && e && (i = B.current.applyMeasurements(Ne.current)), V.current && t && (a = V.current.applyMeasurements(Pe.current)), Ne.current.clear(), Pe.current.clear(), (L.current.adjustScrollOnMeasure ?? !0) && (n !== 0 || r !== 0)) {
974
+ let e = L.current.getScrollElement(), t = L.current.isRtl ?? !1, i = q(L.current.scrollMarginTop), a = q(L.current.scrollMarginLeft);
975
+ if (e) {
976
+ let o = W(e), s = { behavior: "auto" }, c, l;
977
+ if (n !== 0) {
978
+ let r = J(e, "vertical", t, i);
979
+ c = Math.max(0, r + n), s.top = Y(c, "vertical", t, i);
980
+ }
981
+ if (r !== 0) {
982
+ let n = J(e, "horizontal", t, a);
983
+ l = Math.max(0, n + r), s.left = Y(l, "horizontal", t, a);
984
+ }
985
+ o && o.scrollTo(s), c !== void 0 && oe(c), l !== void 0 && X(l);
986
+ return;
987
+ }
988
+ }
989
+ (i || a) && ge((e) => e + 1);
990
+ }
991
+ function Ge() {
992
+ return Re.current ? Re.current : typeof ResizeObserver > "u" ? null : (Re.current = new ResizeObserver((e) => {
993
+ for (let t of e) {
994
+ let e = Le.current.get(t.target);
995
+ e && Ve(e.row, e.col, t.target);
996
+ }
997
+ We();
998
+ }), Re.current);
999
+ }
1000
+ let Ke = n((e) => {
1001
+ if (!e) return;
1002
+ let { estimateRowHeight: t, estimateColumnWidth: n } = L.current;
1003
+ if (typeof t != "function" && typeof n != "function") return;
1004
+ let r = e.getAttribute("data-row-index"), i = e.getAttribute("data-col-index"), a = r === null ? NaN : Number(r), o = i === null ? NaN : Number(i);
1005
+ if (!Number.isFinite(a) || !Number.isFinite(o)) return;
1006
+ Le.current.set(e, {
1007
+ row: a,
1008
+ col: o
1009
+ }), Ve(a, o, e);
1010
+ let s = Ge();
1011
+ return s?.observe(e), () => {
1012
+ s?.unobserve(e), Le.current.delete(e), He(a, o);
1013
+ };
1014
+ }, []);
1015
+ return a(() => {
1016
+ We();
1017
+ }), a(() => {
1018
+ let e = ze.current, t = Be.current, n = e.startIndex !== Q || e.endIndex !== Ae, r = t.startIndex !== $ || t.endIndex !== je;
1019
+ if (n || r) {
1020
+ ze.current = {
1021
+ startIndex: Q,
1022
+ endIndex: Ae
1023
+ }, Be.current = {
1024
+ startIndex: $,
1025
+ endIndex: je
1026
+ };
1027
+ let e = {
1028
+ rowStartIndex: Q,
1029
+ rowEndIndex: Ae,
1030
+ colStartIndex: $,
1031
+ colEndIndex: je
1032
+ };
1033
+ L.current.onRangeChange?.(e);
1034
+ }
1035
+ }, [
1036
+ Q,
1037
+ Ae,
1038
+ $,
1039
+ je
1040
+ ]), {
1041
+ virtualCells: Me,
1042
+ totalHeight: Oe,
1043
+ totalWidth: ke,
1044
+ isScrolling: me,
676
1045
  scrollToOffset: n((e, t) => {
677
- let { getScrollElement: n, initialViewportHeight: r, initialViewportWidth: i } = O.current, a = n();
678
- if (!a) return;
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);
680
- v && v.scrollTo({
681
- top: g,
682
- left: _,
683
- behavior: t?.smooth === !0 ? "smooth" : "auto"
684
- });
1046
+ let { getScrollElement: n, initialViewportHeight: r, initialViewportWidth: i, rowCount: a, colCount: o, estimateRowHeight: s, estimateColumnWidth: c, rowGap: l, columnGap: u, isRtl: d, scrollMarginTop: f, scrollMarginLeft: p } = L.current, m = n();
1047
+ if (!m) return;
1048
+ let h = d ?? !1, g = q(f), _ = q(p), v = q(l), y = q(u), b = K(a), x = K(o), S = U(b, s, B.current, v), C = U(x, c, V.current, y), w = ue(m, "vertical") || r || 0, T = ue(m, "horizontal") || i || 0, E = Math.max(0, Math.min(e.top, Math.max(0, S - w))), D = Math.max(0, Math.min(e.left, Math.max(0, C - T))), O = W(m);
1049
+ if (!O) return;
1050
+ let k = {
1051
+ behavior: t?.smooth === !0 ? "smooth" : "auto",
1052
+ top: Y(E, "vertical", h, g),
1053
+ left: Y(D, "horizontal", h, _)
1054
+ };
1055
+ O.scrollTo(k);
685
1056
  }, []),
686
1057
  scrollToRow: n((e, t) => {
687
- let { getScrollElement: n, rowCount: r, estimateRowHeight: i, initialViewportHeight: a } = O.current, o = n();
688
- if (!o) return;
689
- let s = Math.max(0, Math.trunc(Number(r)) || 0);
690
- if (s === 0) return;
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);
692
- p && p.scrollTo({
693
- top: f,
1058
+ let { getScrollElement: n, rowCount: r, estimateRowHeight: i, initialViewportHeight: a, rowGap: o, isRtl: s, scrollMarginTop: c } = L.current, l = n();
1059
+ if (!l) return;
1060
+ let u = K(r);
1061
+ if (u === 0) return;
1062
+ let d = Math.max(0, Math.min(K(e), u - 1)), f = s ?? !1, p = q(c), m = q(o), h = ue(l, "vertical") || a || 0, g = U(u, i, B.current, m), _ = J(l, "vertical", f, p), v = G(d, t?.align ?? "auto", h, g, _, i, B.current, m), y = W(l);
1063
+ y && y.scrollTo({
1064
+ top: Y(v, "vertical", f, p),
694
1065
  behavior: t?.smooth === !0 ? "smooth" : "auto"
695
1066
  });
696
1067
  }, []),
697
1068
  scrollToColumn: n((e, t) => {
698
- let { getScrollElement: n, colCount: r, estimateColumnWidth: i, initialViewportWidth: a } = O.current, o = n();
699
- if (!o) return;
700
- let s = Math.max(0, Math.trunc(Number(r)) || 0);
701
- if (s === 0) return;
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);
703
- p && p.scrollTo({
704
- left: f,
1069
+ let { getScrollElement: n, colCount: r, estimateColumnWidth: i, initialViewportWidth: a, columnGap: o, isRtl: s, scrollMarginLeft: c } = L.current, l = n();
1070
+ if (!l) return;
1071
+ let u = K(r);
1072
+ if (u === 0) return;
1073
+ let d = Math.max(0, Math.min(K(e), u - 1)), f = s ?? !1, p = q(c), m = q(o), h = ue(l, "horizontal") || a || 0, g = U(u, i, V.current, m), _ = J(l, "horizontal", f, p), v = G(d, t?.align ?? "auto", h, g, _, i, V.current, m), y = W(l);
1074
+ y && y.scrollTo({
1075
+ left: Y(v, "horizontal", f, p),
705
1076
  behavior: t?.smooth === !0 ? "smooth" : "auto"
706
1077
  });
707
1078
  }, []),
708
1079
  scrollToCell: n((e, t, n) => {
709
- let { getScrollElement: r, rowCount: i, colCount: a, estimateRowHeight: o, estimateColumnWidth: s, initialViewportHeight: c, initialViewportWidth: l } = O.current, u = r();
710
- if (!u) return;
711
- let d = Math.max(0, Math.trunc(Number(i)) || 0), f = Math.max(0, Math.trunc(Number(a)) || 0);
712
- if (d === 0 || f === 0) return;
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,
1080
+ let { getScrollElement: r, rowCount: i, colCount: a, estimateRowHeight: o, estimateColumnWidth: s, initialViewportHeight: c, initialViewportWidth: l, rowGap: u, columnGap: d, isRtl: f, scrollMarginTop: p, scrollMarginLeft: m } = L.current, h = r();
1081
+ if (!h) return;
1082
+ let g = K(i), _ = K(a);
1083
+ if (g === 0 || _ === 0) return;
1084
+ let v = Math.max(0, Math.min(K(e), g - 1)), y = Math.max(0, Math.min(K(t), _ - 1)), b = f ?? !1, x = q(p), S = q(m), C = q(u), w = q(d), T = ue(h, "vertical") || c || 0, E = ue(h, "horizontal") || l || 0, D = U(g, o, B.current, C), O = U(_, s, V.current, w), k = J(h, "vertical", b, x), A = J(h, "horizontal", b, S), j = G(v, n?.rowAlign ?? "auto", T, D, k, o, B.current, C), M = G(y, n?.colAlign ?? "auto", E, O, A, s, V.current, w), N = W(h);
1085
+ N && N.scrollTo({
1086
+ top: Y(j, "vertical", b, x),
1087
+ left: Y(M, "horizontal", b, S),
717
1088
  behavior: n?.smooth === !0 ? "smooth" : "auto"
718
1089
  });
719
- }, [])
1090
+ }, []),
1091
+ measureElement: Ke
720
1092
  };
721
1093
  }
722
1094
  //#endregion
723
1095
  //#region src/performance/useVirtualList/utils.ts
724
- function q(e, t) {
725
- return V(e, t ? "horizontal" : "vertical");
1096
+ function me(e, t) {
1097
+ return ue(e, t ? "horizontal" : "vertical");
726
1098
  }
727
- function J(e, t) {
728
- return H(e, t ? "horizontal" : "vertical");
1099
+ function he(e, t) {
1100
+ return de(e, t ? "horizontal" : "vertical");
729
1101
  }
730
- function Y(e, t, n, r, i, a, o, s) {
1102
+ function ge(e, t, n, r, i, a, o, s, c = 0) {
731
1103
  if (r <= 0 || t <= 0) return {
732
1104
  startIndex: 0,
733
1105
  endIndex: -1
734
1106
  };
735
- let c, l;
1107
+ let l = Math.max(0, c), u, d;
736
1108
  if (typeof i == "number") {
737
- let a = Math.max(0, i);
738
- 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));
739
- } else if (s) if (o) {
1109
+ let a = Math.max(0, i) + l;
1110
+ a === 0 ? (u = 0, d = r - 1) : o ? (u = Math.max(0, Math.floor((n - e - t) / a)), d = Math.min(r - 1, Math.ceil((n - e) / a) - 1)) : (u = Math.max(0, Math.floor(e / a)), d = Math.min(r - 1, Math.ceil((e + t) / a) - 1));
1111
+ } else if (s) {
740
1112
  let r = e + t;
741
- c = s.findStartIndexReverse(e, n), l = s.findEndIndexReverse(r, n);
742
- } else {
743
- let n = e + t;
744
- c = s.findStartIndex(e), l = s.findEndIndex(n);
745
- }
746
- else if (o) {
747
- c = r, l = -1;
1113
+ o ? (u = s.findBottomIndexReverse(r, n), d = s.findTopIndexReverse(e, n)) : (u = s.findStartIndex(e), d = s.findEndIndex(r));
1114
+ } else if (o) {
1115
+ u = r, d = -1;
748
1116
  let a = 0;
749
1117
  for (let o = 0; o < r; o++) {
750
- let r = R(o, i), s = n - a - r;
1118
+ let s = H(o, i), c = n - a - s;
751
1119
  if (n - a <= e) break;
752
- s < e + t && (o < c && (c = o), l = o), a += r;
1120
+ c < e + t && (o < u && (u = o), d = o), a += s + (o < r - 1 ? l : 0);
753
1121
  }
754
- c === r && (c = 0, l = -1);
1122
+ u === r && (u = 0, d = -1);
755
1123
  } else {
756
- c = 0, l = -1;
1124
+ u = 0, d = -1;
757
1125
  let n = 0, a = !1;
758
1126
  for (let o = 0; o < r; o++) {
759
- let r = R(o, i), s = n + r;
760
- if (!a && s > e && (c = o, a = !0), a) if (n < e + t) l = o;
1127
+ let s = H(o, i), c = n + s;
1128
+ if (!a && c > e && (u = o, a = !0), a) if (n < e + t) d = o;
761
1129
  else break;
762
- n += r;
1130
+ n += s + (o < r - 1 ? l : 0);
763
1131
  }
764
- a || (c = 0, l = -1);
1132
+ a || (u = 0, d = -1);
765
1133
  }
766
- return c = Math.max(0, c - a), l = Math.min(r - 1, l + a), {
767
- startIndex: c,
768
- endIndex: l
769
- };
1134
+ return d < u ? {
1135
+ startIndex: 0,
1136
+ endIndex: -1
1137
+ } : (u = Math.max(0, u - a), d = Math.min(r - 1, d + a), {
1138
+ startIndex: u,
1139
+ endIndex: d
1140
+ });
770
1141
  }
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;
1142
+ function _e(e, t, n, r, i, a, o, s, c = 0) {
1143
+ let l = s ? s.getItemSize(e) : H(e, a), u = o ? s ? s.getPhysicalStartReverse(e, r) : r - le(e, a, void 0, c) - l : le(e, a, s, c), d = u + l, f = Math.max(0, r - n), p;
773
1144
  switch (t) {
774
1145
  case "start":
775
1146
  p = o ? Math.max(0, d - n) : u;
@@ -778,121 +1149,211 @@ function X(e, t, n, r, i, a, o, s) {
778
1149
  p = o ? u : Math.max(0, d - n);
779
1150
  break;
780
1151
  case "center":
781
- p = Math.max(0, u + c / 2 - n / 2);
1152
+ p = Math.max(0, u + l / 2 - n / 2);
782
1153
  break;
783
1154
  default:
784
1155
  if (u >= i && d <= i + n) return i;
785
- p = u < i ? o ? Math.max(0, d - n) : u : o ? u : Math.max(0, d - n);
1156
+ p = u < i ? u : Math.max(0, d - n);
786
1157
  break;
787
1158
  }
788
1159
  return Math.max(0, Math.min(p, f));
789
1160
  }
790
1161
  //#endregion
791
1162
  //#region src/performance/useVirtualList/useVirtualList.ts
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);
794
- i(() => {
795
- w.current = c;
1163
+ function ve(e) {
1164
+ return Number.isFinite(e) ? Math.max(0, Math.trunc(e)) : 0;
1165
+ }
1166
+ function Z(e) {
1167
+ return e !== void 0 && Number.isFinite(e) ? Math.max(0, e) : 0;
1168
+ }
1169
+ function ye(e, t, n, r) {
1170
+ let i = he(e, t);
1171
+ return Math.max(0, (n && t ? Math.abs(i) : i) - r);
1172
+ }
1173
+ function be(e, t, n, r) {
1174
+ let i = e + r;
1175
+ return n && t ? -i : i;
1176
+ }
1177
+ function xe(i) {
1178
+ let { count: l, estimateSize: u, getScrollElement: d, overscan: f = 3, horizontal: p = !1, reverse: m = !1, isRtl: h = !1, gap: _ = 0, scrollMargin: v = 0, enabled: y = !0, pauseWhenOffscreen: b = !1, scrollingDelay: x = 150, initialViewportSize: S = 0, data: C, itemKey: w, initialOffset: T, initialScrollIndex: E, initialScrollAlign: D = "start" } = i, O = ve(l), k = ve(f), A = Z(_), j = Z(v), M = s(i);
1179
+ a(() => {
1180
+ M.current = i;
796
1181
  });
797
- let T = a(() => {
1182
+ let N = o(() => {
798
1183
  if (typeof u != "function") return;
799
- let e = new L();
800
- return e.initializeOffsets(S, u), e;
801
- }, [S, u]), E = o(T);
802
- i(() => {
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);
811
- return Math.max(0, r - t - n);
812
- }
813
- return t;
1184
+ let e = new ce();
1185
+ return e.initializeOffsets(O, u, A), e;
1186
+ }, [
1187
+ O,
1188
+ u,
1189
+ A
1190
+ ]), P = s(N);
1191
+ a(() => {
1192
+ P.current = N;
1193
+ }, [N]);
1194
+ let [ee, te] = c(() => {
1195
+ if (typeof T == "number") return Math.max(0, T);
1196
+ if (typeof E == "number" && O > 0) {
1197
+ let e = Math.max(0, Math.min(ve(E), O - 1)), t = U(O, u, N, A);
1198
+ return _e(e, D, S, t, 0, u, m, N, A);
814
1199
  }
815
1200
  return 0;
816
- }), [k, A] = s(!1), [, j] = s({}), M = o(!1), { debouncedFunc: N } = h(() => A(!1), g), P = d();
817
- r(() => {
818
- if (!P) return;
819
- if (!M.current && (M.current = !0, typeof b == "number" || typeof x == "number")) {
820
- let e = U(P);
821
- e && e.scrollTo({
822
- [p ? "left" : "top"]: D,
823
- behavior: "auto"
824
- });
1201
+ }), [F, I] = c(!1), [, re] = c(0), ie = s(!1), { debouncedFunc: L } = g(() => I(!1), x), R = d();
1202
+ a(() => {
1203
+ if (!R) return;
1204
+ if (!ie.current && (ie.current = !0, typeof T == "number" || typeof E == "number")) {
1205
+ let e = W(R);
1206
+ if (e) {
1207
+ let t = be(ee, p, h, j), n = { behavior: "auto" };
1208
+ p ? n.left = t : n.top = t, e.scrollTo(n);
1209
+ }
825
1210
  return;
826
1211
  }
827
- let e = J(P, p);
828
- O((t) => t === e ? t : e);
1212
+ let e = ye(R, p, h, j);
1213
+ te((t) => t === e ? t : e);
829
1214
  }, [
830
- P,
1215
+ R,
831
1216
  p,
832
- b,
833
- x,
834
- D
1217
+ h,
1218
+ j
835
1219
  ]);
836
- function F() {
837
- let { getScrollElement: e, horizontal: t } = w.current, n = e();
838
- if (!n) return;
839
- let r = J(n, t ?? !1);
840
- O(r), (w.current.scrollingDelay ?? 150) > 0 && (A(!0), N());
1220
+ function z() {
1221
+ let { getScrollElement: e, horizontal: t, isRtl: n, scrollMargin: r } = M.current, i = e();
1222
+ if (!i) return;
1223
+ let a = ye(i, t ?? !1, n ?? !1, Z(r));
1224
+ te(a), I(!0), L();
1225
+ }
1226
+ let B = b === !1 ? null : b === !0 ? {} : b;
1227
+ function V() {
1228
+ let e = d();
1229
+ return e instanceof Window || e instanceof Document ? null : e;
841
1230
  }
842
- e("scroll", F, {
843
- target: P,
1231
+ let { isIntersecting: ae } = ne({
1232
+ target: V,
1233
+ enabled: B !== null,
1234
+ root: B?.root,
1235
+ rootMargin: B?.rootMargin,
1236
+ initialIsIntersecting: !0
1237
+ }), oe = y && (B === null || ae);
1238
+ e("scroll", z, {
1239
+ target: oe ? R : null,
844
1240
  passive: !0
845
- }), r(() => {
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;
850
- return t.observe(n), () => t.disconnect();
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);
861
- (typeof e == "string" || typeof e == "number") && (a = e);
1241
+ });
1242
+ let { width: ue, height: de } = se({
1243
+ target: d,
1244
+ enabled: oe
1245
+ }), fe = (p ? ue : de) || S, G = U(O, u, N, A), { startIndex: K, endIndex: q } = ge(ee, fe, G, O, u, k, m, N, A), J = [];
1246
+ if (K <= q) {
1247
+ let e = N ? N.getItemStartOffset(K) : le(K, u, void 0, A);
1248
+ for (let n = K; n <= q; n++) {
1249
+ let r = N ? N.getItemSize(n) : H(n, u), i = m ? G - e - r : e, a = i + r, o = n;
1250
+ if (w) {
1251
+ if (typeof w == "function") o = w(n, C?.[n]);
1252
+ else if (C && C[n] !== void 0 && C[n] !== null) {
1253
+ let e = t(C[n], w);
1254
+ (typeof e == "string" || typeof e == "number") && (o = e);
862
1255
  }
863
1256
  }
864
- G.push({
865
- key: a,
1257
+ J.push({
1258
+ key: o,
866
1259
  index: n,
867
1260
  size: r,
868
- start: i
869
- }), e += r;
1261
+ start: i,
1262
+ end: a
1263
+ }), e += r + (n < O - 1 ? A : 0);
870
1264
  }
871
1265
  }
872
- let K = n((e, t) => {
873
- let { getScrollElement: n, horizontal: r, count: i, estimateSize: a } = w.current, o = n();
874
- if (!o) return;
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);
876
- if (!f) return;
877
- let p = { behavior: t?.smooth === !0 ? "smooth" : "auto" };
878
- s ? p.left = d : p.top = d, f.scrollTo(p);
1266
+ let Y = s(/* @__PURE__ */ new Map()), pe = s(/* @__PURE__ */ new WeakMap()), X = s(null), he = s({
1267
+ startIndex: K,
1268
+ endIndex: q
1269
+ });
1270
+ r(() => () => {
1271
+ X.current?.disconnect(), X.current = null;
1272
+ }, []);
1273
+ function xe(e, t) {
1274
+ let n = M.current.horizontal ?? !1, r = t.getBoundingClientRect(), i = n ? r.width : r.height;
1275
+ Y.current.set(e, i);
1276
+ }
1277
+ function Se() {
1278
+ if (Y.current.size === 0) return;
1279
+ let e = P.current;
1280
+ if (!e) {
1281
+ Y.current.clear();
1282
+ return;
1283
+ }
1284
+ let t = M.current.reverse ?? !1, n = he.current, r = 0;
1285
+ for (let [i, a] of Y.current) (t ? i > n.endIndex : i < n.startIndex) && (r += a - e.getItemSize(i));
1286
+ let i = e.applyMeasurements(Y.current);
1287
+ if (Y.current.clear(), (M.current.adjustScrollOnMeasure ?? !0) && r !== 0) {
1288
+ let e = M.current.getScrollElement(), t = M.current.horizontal ?? !1, n = M.current.isRtl ?? !1, i = Z(M.current.scrollMargin);
1289
+ if (e) {
1290
+ let a = ye(e, t, n, i), o = Math.max(0, a + r), s = be(o, t, n, i), c = W(e);
1291
+ if (c) {
1292
+ let e = { behavior: "auto" };
1293
+ t ? e.left = s : e.top = s, c.scrollTo(e);
1294
+ }
1295
+ te(o);
1296
+ return;
1297
+ }
1298
+ }
1299
+ i && re((e) => e + 1);
1300
+ }
1301
+ function Ce() {
1302
+ return X.current ? X.current : typeof ResizeObserver > "u" ? null : (X.current = new ResizeObserver((e) => {
1303
+ for (let t of e) {
1304
+ let e = pe.current.get(t.target);
1305
+ e !== void 0 && xe(e, t.target);
1306
+ }
1307
+ Se();
1308
+ }), X.current);
1309
+ }
1310
+ let we = n((e) => {
1311
+ if (!e || typeof M.current.estimateSize != "function") return;
1312
+ let t = e.getAttribute("data-index"), n = t === null ? NaN : Number(t);
1313
+ if (!Number.isFinite(n)) return;
1314
+ pe.current.set(e, n), xe(n, e);
1315
+ let r = Ce();
1316
+ return r?.observe(e), () => {
1317
+ r?.unobserve(e), pe.current.delete(e);
1318
+ };
1319
+ }, []);
1320
+ a(() => {
1321
+ Se();
1322
+ }), a(() => {
1323
+ let e = he.current;
1324
+ (e.startIndex !== K || e.endIndex !== q) && (he.current = {
1325
+ startIndex: K,
1326
+ endIndex: q
1327
+ }, M.current.onRangeChange?.({
1328
+ startIndex: K,
1329
+ endIndex: q
1330
+ }));
1331
+ }, [K, q]);
1332
+ let Te = n((e, t) => {
1333
+ let { getScrollElement: n, horizontal: r, count: i, estimateSize: a, gap: o, isRtl: s, scrollMargin: c } = M.current, l = n();
1334
+ if (!l) return;
1335
+ let u = r ?? !1, d = s ?? !1, f = Z(c), p = Z(o), m = me(l, u) || M.current.initialViewportSize || 0, h = P.current, g = U(ve(i), a, h, p), _ = be(Math.max(0, Math.min(e, Math.max(0, g - m))), u, d, f), v = W(l);
1336
+ if (!v) return;
1337
+ let y = { behavior: t?.smooth === !0 ? "smooth" : "auto" };
1338
+ u ? y.left = _ : y.top = _, v.scrollTo(y);
879
1339
  }, []);
880
1340
  return {
881
- virtualItems: G,
882
- totalSize: V,
883
- isScrolling: k,
1341
+ virtualItems: J,
1342
+ totalSize: G,
1343
+ isScrolling: F,
884
1344
  scrollToIndex: n((e, t) => {
885
- let { getScrollElement: n, count: r, estimateSize: i, horizontal: a, reverse: o } = w.current, s = n();
886
- if (!s) return;
887
- let c = Math.max(0, Math.trunc(Number(r)) || 0);
888
- if (c === 0) return;
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);
890
- if (!h) return;
891
- let g = { behavior: t?.smooth === !0 ? "smooth" : "auto" };
892
- d ? g.left = m : g.top = m, h.scrollTo(g);
1345
+ let { getScrollElement: n, count: r, estimateSize: i, horizontal: a, reverse: o, gap: s, isRtl: c, scrollMargin: l } = M.current, u = n();
1346
+ if (!u) return;
1347
+ let d = ve(r);
1348
+ if (d === 0) return;
1349
+ let f = Math.max(0, Math.min(ve(e), d - 1)), p = t?.align ?? "auto", m = a ?? !1, h = o ?? !1, g = c ?? !1, _ = Z(l), v = Z(s), y = P.current, b = be(_e(f, p, me(u, m) || M.current.initialViewportSize || 0, U(d, i, y, v), ye(u, m, g, _), i, h, y, v), m, g, _), x = W(u);
1350
+ if (!x) return;
1351
+ let S = { behavior: t?.smooth === !0 ? "smooth" : "auto" };
1352
+ m ? S.left = b : S.top = b, x.scrollTo(S);
893
1353
  }, []),
894
- scrollToOffset: K
1354
+ scrollToOffset: Te,
1355
+ measureElement: we
895
1356
  };
896
1357
  }
897
1358
  //#endregion
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 };
1359
+ export { m as _, ne as a, N as c, D as d, T as f, g, y as h, L as i, j as l, x as m, X as n, F as o, C as p, se as r, ee as s, xe as t, k as u, f as v };