@aiquants/virtualscroll 1.18.2 → 1.18.3

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.
Files changed (56) hide show
  1. package/README.md +30 -16
  2. package/dist/ScrollBar.d.cts +100 -0
  3. package/dist/ScrollBar.d.ts.map +1 -0
  4. package/dist/ScrollPane.d.cts +93 -0
  5. package/dist/ScrollPane.d.ts.map +1 -0
  6. package/dist/TapScrollCircle.d.cts +62 -0
  7. package/dist/TapScrollCircle.d.ts.map +1 -0
  8. package/dist/VirtualScroll.d.cts +155 -0
  9. package/dist/{src/VirtualScroll.d.ts → VirtualScroll.d.ts} +46 -3
  10. package/dist/VirtualScroll.d.ts.map +1 -0
  11. package/dist/cli.js +97 -24
  12. package/dist/cli.server.d.cts +13 -0
  13. package/dist/cli.server.d.ts +14 -0
  14. package/dist/cli.server.d.ts.map +1 -0
  15. package/dist/index.cjs +1 -1
  16. package/dist/{src/index.d.ts → index.d.cts} +9 -10
  17. package/dist/index.d.ts +10 -2
  18. package/dist/index.d.ts.map +1 -0
  19. package/dist/index.js +1862 -1352
  20. package/dist/{src/logger.d.ts → logger.d.cts} +48 -1
  21. package/dist/logger.d.ts +146 -0
  22. package/dist/logger.d.ts.map +1 -0
  23. package/dist/tapScrollCircleSampleVisual.d.cts +2 -0
  24. package/dist/tapScrollCircleSampleVisual.d.ts.map +1 -0
  25. package/dist/{src/useFenwickMapTree.d.ts → useFenwickMapTree.d.cts} +138 -16
  26. package/dist/useFenwickMapTree.d.ts +451 -0
  27. package/dist/useFenwickMapTree.d.ts.map +1 -0
  28. package/dist/useHeightCache.d.cts +15 -0
  29. package/dist/useHeightCache.d.ts.map +1 -0
  30. package/dist/{src/useLruCache.d.ts → useLruCache.d.cts} +8 -2
  31. package/dist/useLruCache.d.ts +24 -0
  32. package/dist/useLruCache.d.ts.map +1 -0
  33. package/dist/{src/utils.d.ts → utils.d.cts} +3 -1
  34. package/dist/utils.d.ts +15 -0
  35. package/dist/{src/utils.d.ts.map → utils.d.ts.map} +1 -1
  36. package/package.json +12 -6
  37. package/dist/src/ScrollBar.d.ts.map +0 -1
  38. package/dist/src/ScrollPane.d.ts.map +0 -1
  39. package/dist/src/TapScrollCircle.d.ts.map +0 -1
  40. package/dist/src/VirtualScroll.d.ts.map +0 -1
  41. package/dist/src/cli.server.d.ts +0 -2
  42. package/dist/src/cli.server.d.ts.map +0 -1
  43. package/dist/src/index.d.ts.map +0 -1
  44. package/dist/src/logger.d.ts.map +0 -1
  45. package/dist/src/tapScrollCircleSampleVisual.d.ts.map +0 -1
  46. package/dist/src/useFenwickMapTree.d.ts.map +0 -1
  47. package/dist/src/useHeightCache.d.ts.map +0 -1
  48. package/dist/src/useLruCache.d.ts.map +0 -1
  49. package/dist/virtualscroll.css +0 -1
  50. package/dist/vite.config.d.ts +0 -3
  51. package/dist/vite.config.d.ts.map +0 -1
  52. /package/dist/{src/ScrollBar.d.ts → ScrollBar.d.ts} +0 -0
  53. /package/dist/{src/ScrollPane.d.ts → ScrollPane.d.ts} +0 -0
  54. /package/dist/{src/TapScrollCircle.d.ts → TapScrollCircle.d.ts} +0 -0
  55. /package/dist/{src/tapScrollCircleSampleVisual.d.ts → tapScrollCircleSampleVisual.d.ts} +0 -0
  56. /package/dist/{src/useHeightCache.d.ts → useHeightCache.d.ts} +0 -0
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
- import { jsx as $, jsxs as ne, Fragment as _e } from "react/jsx-runtime";
2
- import He, { memo as Xe, forwardRef as ye, useState as Bt, useRef as T, useCallback as P, useImperativeHandle as we, useMemo as At, useLayoutEffect as oe, useEffect as Y, useId as Be } from "react";
3
- import { twMerge as re } from "tailwind-merge";
4
- class _ {
1
+ import { jsx as et, jsxs as le, Fragment as Ke } from "react/jsx-runtime";
2
+ import Qe, { memo as tr, forwardRef as Fe, useState as Ut, useRef as b, useCallback as y, useImperativeHandle as ke, useMemo as yt, useLayoutEffect as pe, useEffect as X, useId as er } from "react";
3
+ import { twMerge as ae } from "tailwind-merge";
4
+ class V {
5
5
  level;
6
6
  prefix;
7
7
  impl;
@@ -14,7 +14,7 @@ class _ {
14
14
  constructor(t = 2, e = "[virtualscroll]", r = console) {
15
15
  this.level = t, this.prefix = e, this.impl = r;
16
16
  }
17
- static instance = new _(2, "[virtualscroll]");
17
+ static instance = new V(2, "[virtualscroll]");
18
18
  /**
19
19
  * @method setLevel
20
20
  * @description Updates the current log level for the static instance.
@@ -22,7 +22,7 @@ class _ {
22
22
  * @param {LogLevel} level - The new log level.
23
23
  */
24
24
  static setLevel(t) {
25
- _.instance.setLevel(t);
25
+ V.instance.setLevel(t);
26
26
  }
27
27
  /**
28
28
  * @method setLevel
@@ -40,7 +40,7 @@ class _ {
40
40
  * @param {ILogger} impl - The new logger implementation.
41
41
  */
42
42
  static setImplementation(t) {
43
- _.instance.setImplementation(t);
43
+ V.instance.setImplementation(t);
44
44
  }
45
45
  /**
46
46
  * @method setImplementation
@@ -58,7 +58,7 @@ class _ {
58
58
  * @param {string} prefix - The new prefix.
59
59
  */
60
60
  static setPrefix(t) {
61
- _.instance.setPrefix(t);
61
+ V.instance.setPrefix(t);
62
62
  }
63
63
  /**
64
64
  * @method setPrefix
@@ -69,45 +69,94 @@ class _ {
69
69
  setPrefix(t) {
70
70
  this.prefix = t;
71
71
  }
72
+ /**
73
+ * @method isEnabled
74
+ * @description Returns whether the given level would be emitted at the current level (static instance).
75
+ * @description 指定したレベルが現在のログレベルで出力されるかどうかを返します(静的インスタンス)。
76
+ * @param {LogLevel} level - The level to query. / 問い合わせるレベル。
77
+ * @returns {boolean} True if a message at `level` would be emitted. / `level` のメッセージが出力されるなら true。
78
+ */
79
+ static isEnabled(t) {
80
+ return V.instance.isEnabled(t);
81
+ }
82
+ /**
83
+ * @method isEnabled
84
+ * @description Returns whether the given level would be emitted at the current level.
85
+ * @description 指定したレベルが現在のログレベルで出力されるかどうかを返します。
86
+ *
87
+ * ホットパスで呼び出し側が引数(オブジェクト生成・DOM 読み取り等)を組み立てる前に
88
+ * ガードするために使う。抑制時は引数評価を丸ごと省ける。
89
+ *
90
+ * @param {LogLevel} level - The level to query. / 問い合わせるレベル。
91
+ * @returns {boolean} True if a message at `level` would be emitted. / `level` のメッセージが出力されるなら true。
92
+ */
93
+ isEnabled(t) {
94
+ return this.level <= t;
95
+ }
96
+ /**
97
+ * Resolves a possibly-lazy log argument.
98
+ * If the argument is a function it is treated as a thunk and invoked only when the
99
+ * level is enabled; if the invocation throws (class constructors cannot be called
100
+ * without `new`, or the thunk itself fails), the original function value is
101
+ * returned as-is so the log call never crashes the caller and still emits something.
102
+ * To log a function as a value, wrap it as `() => fn`.
103
+ * 遅延評価される可能性のあるログ引数を解決する処理。
104
+ *
105
+ * 関数が渡された場合はサンク (thunk) とみなし、レベルが有効なとき「だけ」呼び出す。
106
+ * これにより呼び出し側は `logger.debug(() => ({ ...expensive }))` のように書け、
107
+ * レベル抑制時にはオブジェクト生成や DOM 読み取りを回避できる。
108
+ * 呼び出しが throw した場合 (class は `new` なしで呼べず TypeError、または thunk 自体の失敗) は、
109
+ * ログ呼び出しが呼び出し元をクラッシュさせないよう元の関数値をそのまま返す (握り潰さず出力は残る)。
110
+ * 関数を値としてログしたい場合は `() => fn` とラップする。非関数値はそのまま素通しするため後方互換。
111
+ */
112
+ static resolveLazy(t) {
113
+ if (typeof t != "function")
114
+ return t;
115
+ try {
116
+ return t();
117
+ } catch {
118
+ return t;
119
+ }
120
+ }
72
121
  formatMessage(t) {
73
122
  return typeof t == "string" ? [`${this.prefix} ${t}`] : [this.prefix, t];
74
123
  }
75
124
  static debug(t, ...e) {
76
- _.instance.debug(t, ...e);
125
+ V.instance.debug(t, ...e);
77
126
  }
78
127
  debug(t, ...e) {
79
- this.level <= 0 && this.impl.debug(...this.formatMessage(t), ...e);
128
+ this.level <= 0 && this.impl.debug(...this.formatMessage(V.resolveLazy(t)), ...e.map(V.resolveLazy));
80
129
  }
81
130
  static info(t, ...e) {
82
- _.instance.info(t, ...e);
131
+ V.instance.info(t, ...e);
83
132
  }
84
133
  info(t, ...e) {
85
- this.level <= 1 && this.impl.info(...this.formatMessage(t), ...e);
134
+ this.level <= 1 && this.impl.info(...this.formatMessage(V.resolveLazy(t)), ...e.map(V.resolveLazy));
86
135
  }
87
136
  static warn(t, ...e) {
88
- _.instance.warn(t, ...e);
137
+ V.instance.warn(t, ...e);
89
138
  }
90
139
  warn(t, ...e) {
91
- this.level <= 2 && this.impl.warn(...this.formatMessage(t), ...e);
140
+ this.level <= 2 && this.impl.warn(...this.formatMessage(V.resolveLazy(t)), ...e.map(V.resolveLazy));
92
141
  }
93
142
  static error(t, ...e) {
94
- _.instance.error(t, ...e);
143
+ V.instance.error(t, ...e);
95
144
  }
96
145
  error(t, ...e) {
97
- this.level <= 3 && this.impl.error(...this.formatMessage(t), ...e);
146
+ this.level <= 3 && this.impl.error(...this.formatMessage(V.resolveLazy(t)), ...e.map(V.resolveLazy));
98
147
  }
99
148
  }
100
- const Ve = {
149
+ const Ye = {
101
150
  active: !1,
102
151
  offsetX: 0,
103
152
  offsetY: 0,
104
153
  distance: 0,
105
154
  direction: 0,
106
155
  pointerId: null
107
- }, Te = 6, Ue = 8, $e = ({ dragState: n, normalizedDistance: t }) => {
108
- const e = 1 + t * 0.18, r = 0.16 + t * 0.24, i = 0.38 + t * 0.28, l = n.active ? "80ms ease-out" : "220ms ease";
109
- return /* @__PURE__ */ ne(_e, { children: [
110
- /* @__PURE__ */ $(
156
+ }, Ae = 6, rr = 8, nr = ({ dragState: i, normalizedDistance: t }) => {
157
+ const e = 1 + t * 0.18, r = 0.16 + t * 0.24, n = 0.38 + t * 0.28, s = i.active ? "80ms ease-out" : "220ms ease";
158
+ return /* @__PURE__ */ le(Ke, { children: [
159
+ /* @__PURE__ */ et(
111
160
  "div",
112
161
  {
113
162
  className: "aqvs-tap-scroll-circle-visual-outer",
@@ -115,126 +164,166 @@ const Ve = {
115
164
  background: "linear-gradient(140deg, rgba(255,255,255,0.62), rgba(72,72,72,0.48))",
116
165
  boxShadow: `0 0 0 1px rgba(255,255,255,0.28), 0 10px 22px rgba(0,0,0,${r})`,
117
166
  transform: `scale(${e})`,
118
- transition: `${l}, ${n.active ? "80ms" : "260ms"} box-shadow ease`
167
+ transition: `${s}, ${i.active ? "80ms" : "260ms"} box-shadow ease`
119
168
  }
120
169
  }
121
170
  ),
122
- /* @__PURE__ */ $(
171
+ /* @__PURE__ */ et(
123
172
  "div",
124
173
  {
125
174
  className: "aqvs-tap-scroll-circle-inner",
126
175
  style: {
127
176
  background: "linear-gradient(140deg, rgba(255,255,255,0.72), rgba(28,28,28,0.58))",
128
177
  boxShadow: "inset 0 4px 10px rgba(0,0,0,0.24), inset 0 0 2px rgba(255,255,255,0.55)",
129
- opacity: i,
130
- transition: n.active ? "120ms opacity ease-out" : "220ms opacity ease"
178
+ opacity: n,
179
+ transition: i.active ? "120ms opacity ease-out" : "220ms opacity ease"
131
180
  }
132
181
  }
133
182
  )
134
183
  ] });
135
- }, Fe = Xe(
136
- ye(({ onDragChange: n, className: t, maxVisualDistance: e = 160, size: r = 40, style: i, opacity: l = 1, renderVisual: c }, d) => {
137
- const [f, h] = Bt(Ve), m = T(null), g = T({ x: 0, y: 0 }), N = T(null), x = T(0), k = P(
138
- (I) => {
139
- h(I), n(I);
184
+ }, We = tr(
185
+ Fe(({ onDragChange: i, className: t, maxVisualDistance: e = 160, size: r = 40, style: n, opacity: s = 1, renderVisual: l }, u) => {
186
+ const [f, I] = Ut(Ye), v = b(null), T = b(null), D = b({ x: 0, y: 0 }), p = b(null), z = b(0), rt = y(
187
+ (S) => {
188
+ I(S), i(S);
140
189
  },
141
- [n]
142
- ), B = P(
143
- (I, W, St = !1) => {
144
- const { x: Dt, y: ot } = g.current, A = I - Dt, G = W - ot, dt = Math.abs(G), It = dt < Te ? 0 : G < 0 ? -1 : 1, v = x.current;
145
- let kt = It;
146
- const S = Te + Ue;
147
- It === 0 ? v !== 0 && dt < S ? kt = v : (kt = 0, St || (x.current = 0)) : It !== v && v !== 0 && dt < S ? kt = v : x.current = It, k({
148
- active: St || dt >= Te,
149
- offsetX: A,
150
- offsetY: G,
151
- distance: dt,
152
- direction: kt,
153
- pointerId: m.current
190
+ [i]
191
+ ), W = y(
192
+ (S, U, j = !1) => {
193
+ const { x: k, y: G } = D.current, st = S - k, Mt = U - G, R = Math.abs(Mt), Dt = R < Ae ? 0 : Mt < 0 ? -1 : 1, Vt = z.current;
194
+ let x = Dt;
195
+ const Rt = Ae + rr;
196
+ Dt === 0 ? Vt !== 0 && R < Rt ? x = Vt : (x = 0, j || (z.current = 0)) : Dt !== Vt && Vt !== 0 && R < Rt ? x = Vt : z.current = Dt, rt({
197
+ active: j || R >= Ae,
198
+ offsetX: st,
199
+ offsetY: Mt,
200
+ distance: R,
201
+ direction: x,
202
+ pointerId: v.current
154
203
  });
155
204
  },
156
- [k]
157
- ), z = P((I) => {
158
- if (I === null)
205
+ [rt]
206
+ ), ot = y((S) => {
207
+ if (S === null)
159
208
  return;
160
- const W = N.current;
161
- W?.hasPointerCapture(I) && W.releasePointerCapture(I);
162
- }, []), Q = P(
163
- (I = !1) => {
164
- I && z(m.current), m.current = null, x.current = 0, k(Ve);
209
+ const U = p.current;
210
+ U?.hasPointerCapture(S) && U.releasePointerCapture(S);
211
+ }, []), nt = y(
212
+ (S = !1) => {
213
+ S && ot(v.current), v.current = null, T.current = null, z.current = 0, rt(Ye);
165
214
  },
166
- [k, z]
167
- ), pt = P(
168
- (I) => {
169
- I.preventDefault(), I.stopPropagation();
170
- const W = N.current ?? I.currentTarget, { left: St, top: Dt, width: ot, height: A } = W.getBoundingClientRect();
171
- g.current = { x: St + ot / 2, y: Dt + A / 2 }, m.current = I.pointerId, W.setPointerCapture(I.pointerId), B(I.clientX, I.clientY, !0);
215
+ [rt, ot]
216
+ ), ft = y(
217
+ (S) => {
218
+ if (v.current !== null && v.current !== S.pointerId) {
219
+ T.current = { pointerId: S.pointerId, clientX: S.clientX, clientY: S.clientY }, S.preventDefault(), S.stopPropagation();
220
+ return;
221
+ }
222
+ S.preventDefault(), S.stopPropagation();
223
+ const U = p.current ?? S.currentTarget, { left: j, top: k, width: G, height: st } = U.getBoundingClientRect();
224
+ D.current = { x: j + G / 2, y: k + st / 2 }, v.current = S.pointerId;
225
+ try {
226
+ U.setPointerCapture(S.pointerId);
227
+ } catch {
228
+ }
229
+ W(S.clientX, S.clientY, !0);
230
+ },
231
+ [W]
232
+ ), St = y(
233
+ (S) => {
234
+ if (v.current !== S.pointerId) {
235
+ T.current !== null && T.current.pointerId === S.pointerId && (T.current = { pointerId: S.pointerId, clientX: S.clientX, clientY: S.clientY });
236
+ return;
237
+ }
238
+ S.preventDefault(), W(S.clientX, S.clientY);
172
239
  },
173
- [B]
174
- ), ct = P(
175
- (I) => {
176
- m.current === I.pointerId && (I.preventDefault(), B(I.clientX, I.clientY));
240
+ [W]
241
+ ), wt = y(
242
+ (S) => {
243
+ if (v.current !== S.pointerId) {
244
+ T.current !== null && T.current.pointerId === S.pointerId && (T.current = null);
245
+ return;
246
+ }
247
+ S.preventDefault(), S.stopPropagation();
248
+ const U = T.current;
249
+ if (T.current = null, U !== null) {
250
+ ot(S.pointerId);
251
+ const j = p.current;
252
+ let k = !0;
253
+ if (j !== null && typeof j.setPointerCapture == "function")
254
+ try {
255
+ j.setPointerCapture(U.pointerId);
256
+ } catch (G) {
257
+ (typeof G == "object" && G !== null && "name" in G ? G.name : void 0) === "NotFoundError" && (k = !1);
258
+ }
259
+ if (k) {
260
+ v.current = U.pointerId, W(U.clientX, U.clientY, !0);
261
+ return;
262
+ }
263
+ }
264
+ nt(!0);
177
265
  },
178
- [B]
179
- ), st = P(
180
- (I) => {
181
- m.current === I.pointerId && (I.preventDefault(), I.stopPropagation(), Q(!0));
266
+ [nt, ot, W]
267
+ ), L = y(
268
+ (S) => {
269
+ v.current === S.pointerId && nt(!1);
182
270
  },
183
- [Q]
271
+ [nt]
184
272
  );
185
- we(
186
- d,
273
+ ke(
274
+ u,
187
275
  () => ({
188
276
  reset: () => {
189
- Q(!0);
277
+ nt(!0);
190
278
  },
191
- getElement: () => N.current
279
+ getElement: () => p.current
192
280
  }),
193
- [Q]
281
+ [nt]
194
282
  );
195
- const L = Math.min(Math.max(l, 0), 1), tt = r / 64, et = Math.min(f.distance, e) / e, E = f.direction * et * 10 * tt, ut = c ?? $e, Pt = {
283
+ const F = Math.min(Math.max(s, 0), 1), h = r / 64, $ = Math.min(f.distance, e) / e, q = f.direction * $ * 10 * h, H = l ?? nr, O = {
196
284
  dragState: f,
197
- normalizedDistance: et,
198
- sizeScale: tt,
285
+ normalizedDistance: $,
286
+ sizeScale: h,
199
287
  size: r,
200
- opacity: L
201
- }, ht = {
202
- ...i,
288
+ opacity: F
289
+ }, K = {
290
+ ...n,
203
291
  width: r,
204
292
  height: r,
205
- transform: `translateY(${E}px)`
293
+ transform: `translateY(${q}px)`
206
294
  };
207
- return ht.opacity = L, /* @__PURE__ */ $(
295
+ return K.opacity = F, /* @__PURE__ */ et(
208
296
  "div",
209
297
  {
210
- ref: N,
298
+ ref: p,
211
299
  "data-testid": "virtual-scroll-tap-circle",
212
- className: re("aqvs-tap-scroll-circle", t),
213
- style: ht,
300
+ className: ae("aqvs-tap-scroll-circle", t),
301
+ style: K,
214
302
  tabIndex: -1,
215
- onPointerDown: pt,
216
- onPointerMove: ct,
217
- onPointerUp: st,
218
- onPointerCancel: st,
303
+ onPointerDown: ft,
304
+ onPointerMove: St,
305
+ onPointerUp: wt,
306
+ onPointerCancel: wt,
307
+ onLostPointerCapture: L,
219
308
  role: "presentation",
220
- children: ut(Pt)
309
+ children: H(O)
221
310
  }
222
311
  );
223
312
  })
224
313
  );
225
- Fe.displayName = "TapScrollCircle";
226
- const xt = (n, t, e) => Math.min(e, Math.max(t, n)), Me = "virtualscroll:tap-scroll-cancel", Ce = 20, Ke = 250, We = 60, je = 20, Ge = 20, Ze = 240, Ee = { active: !1, offsetX: 0, offsetY: 0, distance: 0, direction: 0, pointerId: null }, Pe = 2.2, Je = 8, Qe = 120, tr = 1 / 60, Xt = {
314
+ We.displayName = "TapScrollCircle";
315
+ const mt = (i, t, e) => Math.max(t, Math.min(e, i)), Oe = "virtualscroll:tap-scroll-cancel", Be = 20, ir = 250, or = 60, sr = 20, ar = 20, lr = 240, qe = { active: !1, offsetX: 0, offsetY: 0, distance: 0, direction: 0, pointerId: null }, De = 2.2, cr = 8, ur = 120, dr = 1 / 10, $t = {
227
316
  enabled: !0,
228
317
  size: 40,
229
318
  offsetX: -80,
230
319
  offsetY: 0,
231
320
  className: void 0,
232
- maxVisualDistance: Ze,
321
+ maxVisualDistance: lr,
233
322
  minSpeedMultiplier: 0.2,
234
323
  opacity: 0.9,
235
324
  renderVisual: void 0,
236
325
  maxSpeedCurve: void 0
237
- }, er = (n) => n ? {
326
+ }, fr = (i) => i ? {
238
327
  mainSizeKey: "width",
239
328
  crossSizeKey: "height",
240
329
  positionKey: "left",
@@ -254,421 +343,493 @@ const xt = (n, t, e) => Math.min(e, Math.max(t, n)), Me = "virtualscroll:tap-scr
254
343
  arrowIcons: ["▲", "▼"],
255
344
  directionClass: "aqvs-scrollbar-vertical",
256
345
  orientation: "vertical"
257
- }, rr = (n, t) => {
258
- const e = n?.maxSpeedMultiplier, r = typeof e == "number" ? e : sr(t);
346
+ }, mr = (i, t) => {
347
+ const e = i?.maxSpeedMultiplier, r = typeof e == "number" ? e : gr(t);
259
348
  return {
260
- enabled: n?.enabled ?? Xt.enabled,
261
- size: n?.size ?? Xt.size,
262
- offsetX: n?.offsetX ?? Xt.offsetX,
263
- offsetY: n?.offsetY ?? Xt.offsetY,
264
- className: n?.className ?? Xt.className,
265
- maxVisualDistance: n?.maxVisualDistance ?? Xt.maxVisualDistance,
349
+ enabled: i?.enabled ?? $t.enabled,
350
+ size: i?.size ?? $t.size,
351
+ offsetX: i?.offsetX ?? $t.offsetX,
352
+ offsetY: i?.offsetY ?? $t.offsetY,
353
+ className: i?.className ?? $t.className,
354
+ maxVisualDistance: i?.maxVisualDistance ?? $t.maxVisualDistance,
266
355
  maxSpeedMultiplier: r,
267
- minSpeedMultiplier: Math.max(n?.minSpeedMultiplier ?? Xt.minSpeedMultiplier, 0),
268
- opacity: xt(n?.opacity ?? Xt.opacity, 0, 1),
269
- renderVisual: n?.renderVisual ?? Xt.renderVisual,
270
- maxSpeedCurve: n?.maxSpeedCurve ?? Xt.maxSpeedCurve
356
+ minSpeedMultiplier: Math.max(i?.minSpeedMultiplier ?? $t.minSpeedMultiplier, 0),
357
+ opacity: mt(i?.opacity ?? $t.opacity, 0, 1),
358
+ renderVisual: i?.renderVisual ?? $t.renderVisual,
359
+ maxSpeedCurve: i?.maxSpeedCurve ?? $t.maxSpeedCurve
271
360
  };
272
- }, nr = ({ isDragging: n, isThumbHovered: t, enableThumbDrag: e }) => At(() => e ? n ? "dragging" : t ? "hover" : "idle" : "disabled", [e, n, t]), ir = ({ canUseArrowButtons: n, enableArrowButtons: t, resetTapScroll: e, scrollByStep: r }) => {
273
- const i = T(null), l = T(null), c = P(() => {
274
- i.current !== null && (window.clearInterval(i.current), i.current = null), l.current !== null && (window.clearTimeout(l.current), l.current = null);
275
- }, []), d = P(() => {
276
- c();
277
- }, [c]), f = P(
278
- (m) => (g) => {
279
- n && (g.cancelable && g.preventDefault(), g.stopPropagation(), e(), c(), r(m), l.current = window.setTimeout(() => {
280
- i.current = window.setInterval(() => {
281
- r(m);
282
- }, We);
283
- }, Ke));
361
+ }, pr = ({ isDragging: i, isThumbHovered: t, enableThumbDrag: e }) => yt(() => e ? i ? "dragging" : t ? "hover" : "idle" : "disabled", [e, i, t]), hr = ({ canUseArrowButtons: i, enableArrowButtons: t, resetTapScroll: e, scrollByStep: r }) => {
362
+ const n = b(null), s = b(null), l = b(null), u = y(() => {
363
+ n.current !== null && (window.clearInterval(n.current), n.current = null), s.current !== null && (window.clearTimeout(s.current), s.current = null), l.current !== null && (window.removeEventListener("pointerup", l.current), window.removeEventListener("pointercancel", l.current), window.removeEventListener("blur", l.current), l.current = null);
364
+ }, []), f = y(() => {
365
+ u();
366
+ }, [u]), I = y(
367
+ (T) => (D) => {
368
+ if (!i)
369
+ return;
370
+ D.cancelable && D.preventDefault(), D.stopPropagation(), e(), u(), r(T), s.current = window.setTimeout(() => {
371
+ n.current = window.setInterval(() => {
372
+ r(T);
373
+ }, or);
374
+ }, ir);
375
+ const p = () => u();
376
+ l.current = p, window.addEventListener("pointerup", p), window.addEventListener("pointercancel", p), window.addEventListener("blur", p);
284
377
  },
285
- [n, c, e, r]
286
- ), h = P(
287
- (m) => (g) => {
288
- t && (g.key === "Enter" || g.key === " " || g.key === "Spacebar") && (g.preventDefault(), r(m));
378
+ [i, u, e, r]
379
+ ), v = y(
380
+ (T) => (D) => {
381
+ t && (D.key === "Enter" || D.key === " " || D.key === "Spacebar") && (D.preventDefault(), r(T));
289
382
  },
290
383
  [t, r]
291
384
  );
292
- return Y(() => () => {
293
- c();
294
- }, [c]), { handleArrowPointerDown: f, handleArrowPointerUp: d, handleArrowKeyDown: h };
295
- }, sr = (n) => {
296
- if (!n || n <= 0)
297
- return Pe;
298
- const t = Math.max(1, n), e = Math.log10(t), r = Pe + e * Je;
299
- return xt(r, Pe, Qe);
300
- }, or = ({
301
- contentSize: n,
385
+ return X(() => {
386
+ i || u();
387
+ }, [i, u]), X(() => () => {
388
+ u();
389
+ }, [u]), { handleArrowPointerDown: I, handleArrowPointerUp: f, handleArrowKeyDown: v };
390
+ }, gr = (i) => {
391
+ if (!i || i <= 0)
392
+ return De;
393
+ const t = Math.max(1, i), e = Math.log10(t), r = De + e * cr;
394
+ return mt(r, De, ur);
395
+ }, br = ({
396
+ contentSize: i,
302
397
  viewportSize: t,
303
398
  scrollPosition: e,
304
399
  onScroll: r,
305
- enableThumbDrag: i = !0,
306
- enableTrackClick: l = !0,
307
- enableArrowButtons: c = !0,
308
- horizontal: d = !1,
400
+ enableThumbDrag: n = !0,
401
+ enableTrackClick: s = !0,
402
+ enableArrowButtons: l = !0,
403
+ horizontal: u = !1,
309
404
  scrollBarWidth: f = 12,
310
- className: h,
311
- ariaControls: m,
312
- tapScrollCircleOptions: g,
313
- itemCount: N,
314
- renderThumbOverlay: x,
315
- visibleStartIndex: k,
316
- visibleEndIndex: B
405
+ className: I,
406
+ ariaControls: v,
407
+ tapScrollCircleOptions: T,
408
+ itemCount: D,
409
+ renderThumbOverlay: p,
410
+ visibleStartIndex: z,
411
+ visibleEndIndex: rt
317
412
  }) => {
318
- const [z, Q] = Bt(!1), [pt, ct] = Bt(!1), [st, L] = Bt(!1), tt = T(null), et = T({ pointerId: null, startThumbPosition: 0, startClientX: 0, startClientY: 0 }), E = T({ pointerId: null, startThumbPosition: 0, startClientX: 0, startClientY: 0 }), ut = T(e), Pt = T(r), ht = T(Ee), I = T(null), W = T(null), St = T(null), Dt = At(() => rr(g, N), [N, g]), ot = At(() => er(d), [d]), {
319
- enabled: A,
320
- size: G,
321
- offsetX: dt,
322
- offsetY: It,
323
- className: v,
324
- maxVisualDistance: kt,
325
- maxSpeedMultiplier: S,
326
- minSpeedMultiplier: rt,
327
- opacity: Vt,
328
- renderVisual: Gt,
329
- maxSpeedCurve: Mt
330
- } = Dt, b = T({
413
+ const [W, ot] = Ut(!1), [nt, ft] = Ut(!1), [St, wt] = Ut(!1), L = b(null), F = b({
414
+ pointerId: null,
415
+ startThumbPosition: 0,
416
+ startClientX: 0,
417
+ startClientY: 0,
418
+ scale: 1,
419
+ captureTarget: null
420
+ }), h = b({ pointerId: null, startThumbPosition: 0, startClientX: 0, startClientY: 0, scale: 1 }), $ = b(e), q = b(r), H = b(qe), O = b(null), K = b(null), S = b(null), U = b(0), j = b(0), k = yt(() => mr(T, D), [D, T]), G = yt(() => fr(u), [u]), {
421
+ enabled: st,
422
+ size: Mt,
423
+ offsetX: R,
424
+ offsetY: Dt,
425
+ className: Vt,
426
+ maxVisualDistance: x,
427
+ maxSpeedMultiplier: Rt,
428
+ minSpeedMultiplier: At,
429
+ opacity: qt,
430
+ renderVisual: M,
431
+ maxSpeedCurve: Y
432
+ } = k, C = b({
331
433
  viewportSize: t,
332
- maxScrollPosition: Math.max(n - t, 0),
333
- scrollBarVisible: n > t,
334
- effectiveTapMaxDistance: Math.max(kt, 1),
335
- tapCircleMaxSpeedMultiplier: S,
336
- tapCircleMinSpeedMultiplier: rt,
337
- tapCircleMaxSpeedCurve: Mt,
338
- tapScrollCircleOptions: g,
434
+ maxScrollPosition: Math.max(i - t, 0),
435
+ scrollBarVisible: i > t,
436
+ effectiveTapMaxDistance: Math.max(x, 1),
437
+ tapCircleMaxSpeedMultiplier: Rt,
438
+ tapCircleMinSpeedMultiplier: At,
439
+ tapCircleMaxSpeedCurve: Y,
440
+ tapScrollCircleOptions: T,
339
441
  effectiveTrackLength: 0,
340
442
  onScroll: r,
341
443
  scrollPosition: e
342
- }), { mainSizeKey: M, crossSizeKey: q, positionKey: ft, selectDelta: j, getPointerCoordinate: mt, arrowLabels: Z, arrowIcons: J, directionClass: bt, orientation: qt } = ot, yt = Math.max(kt, 1), Tt = t / n, Ct = Math.max(t - f * 2, 0), _t = Tt * Ct, at = Math.min(Math.max(Ce, _t || 0), Ct || Ce), p = n - t, y = Math.max(Ct - at, 0), nt = p <= 0 || y <= 0 ? 0 : e / p * y, Lt = nt + at / 2, H = n > t || z, Zt = H && c;
343
- oe(() => {
344
- b.current = {
444
+ }), { mainSizeKey: ct, crossSizeKey: at, positionKey: pt, selectDelta: ht, getPointerCoordinate: J, arrowLabels: Ct, arrowIcons: ut, directionClass: Kt, orientation: Lt } = G, xt = Math.max(x, 1), _t = t / i, Ot = Math.max(t - f * 2, 0), It = _t * Ot, Et = Math.min(Math.max(Be, It || 0), Ot || Be), m = i - t, E = Math.max(Ot - Et, 0), lt = m <= 0 || E <= 0 ? 0 : mt(e / m * E, 0, E), zt = lt + Et / 2, Z = i > t || W, re = Z && l;
445
+ pe(() => {
446
+ C.current = {
345
447
  viewportSize: t,
346
- maxScrollPosition: p,
347
- scrollBarVisible: H,
348
- effectiveTapMaxDistance: yt,
349
- tapCircleMaxSpeedMultiplier: S,
350
- tapCircleMinSpeedMultiplier: rt,
351
- tapCircleMaxSpeedCurve: Mt,
352
- tapScrollCircleOptions: g,
353
- effectiveTrackLength: y,
448
+ maxScrollPosition: m,
449
+ scrollBarVisible: Z,
450
+ effectiveTapMaxDistance: xt,
451
+ tapCircleMaxSpeedMultiplier: Rt,
452
+ tapCircleMinSpeedMultiplier: At,
453
+ tapCircleMaxSpeedCurve: Y,
454
+ tapScrollCircleOptions: T,
455
+ effectiveTrackLength: E,
354
456
  onScroll: r,
355
457
  scrollPosition: e
356
458
  };
357
- }), oe(() => {
358
- ut.current = e;
359
- }, [e]), oe(() => {
360
- Pt.current = r;
361
- }, [r]), Y(() => {
362
- i || ct(!1);
363
- }, [i]);
364
- const Ft = nr({ isDragging: z, isThumbHovered: pt, enableThumbDrag: i }), wt = P((o, w) => {
365
- const V = b.current, K = w ?? ut.current;
366
- if (Pt.current) {
367
- const R = Pt.current(o, K);
368
- if (typeof R == "number" && Number.isFinite(R))
369
- return ut.current = R, R;
459
+ }), pe(() => {
460
+ $.current = e;
461
+ }, [e]), pe(() => {
462
+ q.current = r;
463
+ }, [r]), X(() => {
464
+ n || ft(!1);
465
+ }, [n]);
466
+ const Ht = pr({ isDragging: W, isThumbHovered: nt, enableThumbDrag: n }), Nt = y((a, g) => {
467
+ const w = C.current, o = g ?? $.current;
468
+ if (q.current) {
469
+ const N = q.current(a, o);
470
+ if (typeof N == "number" && Number.isFinite(N))
471
+ return $.current = N, N;
370
472
  }
371
- const s = typeof o == "function" ? o(K) : o, a = Math.max(V.maxScrollPosition, 0), u = V.scrollBarVisible ? xt(s, 0, a) : 0;
372
- return ut.current = u, u;
373
- }, []), Ht = P(
374
- (o) => {
375
- const w = b.current, V = ut.current;
376
- if (!w.scrollBarVisible || w.maxScrollPosition <= 0) {
377
- const R = wt(0, V), D = R - V;
378
- return { nextPosition: R, actualDelta: D, reachedBoundary: !0 };
473
+ const c = typeof a == "function" ? a(o) : a, d = Math.max(w.maxScrollPosition, 0), P = w.scrollBarVisible ? mt(c, 0, d) : 0;
474
+ return $.current = P, P;
475
+ }, []), Wt = y(
476
+ (a) => {
477
+ const g = C.current, w = $.current;
478
+ if (!g.scrollBarVisible || g.maxScrollPosition <= 0) {
479
+ const A = Nt(0, w), B = A - w;
480
+ return { nextPosition: A, actualDelta: B, reachedBoundary: !0 };
379
481
  }
380
- if (o === 0)
381
- return { nextPosition: V, actualDelta: 0, reachedBoundary: !1 };
382
- const s = wt((R) => xt(R + o, 0, w.maxScrollPosition), V), a = s - V, u = a === 0 || o < 0 && s <= 0 || o > 0 && s >= w.maxScrollPosition;
383
- return { nextPosition: s, actualDelta: a, reachedBoundary: u };
482
+ if (a === 0)
483
+ return { nextPosition: w, actualDelta: 0, reachedBoundary: !1 };
484
+ const c = Nt((A) => mt(A + a, 0, g.maxScrollPosition), w), d = c - w, P = a < 0 && w + a <= 0, N = a > 0 && w + a >= g.maxScrollPosition, _ = a < 0 && (c <= 0 || P && d === 0) || a > 0 && (c >= g.maxScrollPosition || N && d === 0);
485
+ return { nextPosition: c, actualDelta: d, reachedBoundary: _ };
384
486
  },
385
- [wt]
386
- ), gt = P(() => {
387
- W.current !== null && (window.cancelAnimationFrame(W.current), W.current = null), St.current = null;
388
- }, []), Rt = P(() => {
389
- ht.current = { ...Ee }, L(!1), I.current?.reset(), gt();
390
- }, [gt]), Jt = P(
391
- (o) => {
392
- const w = ht.current, V = b.current;
393
- if (!w.active || w.direction === 0) {
394
- gt();
487
+ [Nt]
488
+ ), jt = y(
489
+ (a, g) => {
490
+ a.current += g;
491
+ const w = Math.max(C.current.maxScrollPosition, 0);
492
+ w > 0 && (a.current = mt(a.current, -w, w));
493
+ const o = Wt(a.current);
494
+ return a.current -= o.actualDelta, o.reachedBoundary && (a.current = 0), o;
495
+ },
496
+ [Wt]
497
+ ), Ft = y(() => {
498
+ K.current !== null && (window.cancelAnimationFrame(K.current), K.current = null), S.current = null, U.current = 0, j.current = 0;
499
+ }, []), Pt = y(() => {
500
+ H.current = { ...qe }, wt(!1), O.current?.reset(), Ft();
501
+ }, [Ft]), Gt = y(
502
+ (a) => {
503
+ const g = H.current, w = C.current;
504
+ if (!g.active || g.direction === 0) {
505
+ Ft();
395
506
  return;
396
507
  }
397
- if (!V.scrollBarVisible || V.maxScrollPosition <= 0) {
398
- gt();
508
+ if (!w.scrollBarVisible || w.maxScrollPosition <= 0) {
509
+ Ft();
399
510
  return;
400
511
  }
401
- const K = St.current ?? o, s = Math.max((o - K) / 1e3, 0), a = Math.min(s, tr);
402
- if (St.current = o, a <= 0) {
403
- W.current = window.requestAnimationFrame(Jt);
512
+ const o = S.current ?? a, c = Math.max((a - o) / 1e3, 0), d = Math.min(c, dr);
513
+ if (S.current = a, d <= 0) {
514
+ K.current = window.requestAnimationFrame(Gt);
404
515
  return;
405
516
  }
406
- const u = Math.min(w.distance, V.effectiveTapMaxDistance) / V.effectiveTapMaxDistance, R = u ** 1.1, D = typeof V.tapScrollCircleOptions?.maxSpeedMultiplier == "number", C = Math.max(V.viewportSize * V.tapCircleMinSpeedMultiplier, 40), X = D ? C : 1200;
407
- let F = Math.max(V.viewportSize * V.tapCircleMaxSpeedMultiplier, X);
408
- const O = V.tapCircleMaxSpeedCurve;
409
- if (O) {
410
- const xe = Math.max(O.exponentialSteepness, 0), Oe = Math.max(O.exponentialScale ?? V.tapCircleMaxSpeedMultiplier, 0), Ye = xe === 0 ? u : Math.expm1(xe * u), Re = xe === 0 ? 1 : Math.expm1(xe) || 1, ze = Re === 0 ? u : Math.min(Math.max(Ye / Re, 0), 1), qe = V.viewportSize * Oe * ze;
411
- F = Math.min(F, Math.max(qe, C));
517
+ const P = Math.min(g.distance, w.effectiveTapMaxDistance) / w.effectiveTapMaxDistance, N = P ** 1.1, _ = typeof w.tapScrollCircleOptions?.maxSpeedMultiplier == "number", A = Math.max(w.viewportSize * w.tapCircleMinSpeedMultiplier, 40), B = _ ? A : 1200;
518
+ let tt = Math.max(w.viewportSize * w.tapCircleMaxSpeedMultiplier, B);
519
+ const Q = w.tapCircleMaxSpeedCurve;
520
+ if (Q) {
521
+ const we = Math.max(Q.exponentialSteepness, 0), je = Math.max(Q.exponentialScale ?? w.tapCircleMaxSpeedMultiplier, 0), Ge = we === 0 ? P : Math.expm1(we * P), ze = we === 0 ? 1 : Math.expm1(we) || 1, Ze = ze === 0 ? P : Math.min(Math.max(Ge / ze, 0), 1), Je = w.viewportSize * je * Ze;
522
+ tt = Math.min(tt, Math.max(Je, A));
412
523
  }
413
- const Et = Math.max(F, C), vt = Math.max(O?.easedOffset ?? 0, 0), zt = Math.min(1, R + vt), te = C + (Et - C) * zt, ue = w.direction * te * a, { actualDelta: de, reachedBoundary: Le } = Ht(ue);
414
- if (Le || de === 0) {
415
- gt();
524
+ const vt = Math.max(tt, A), bt = Math.max(Q?.easedOffset ?? 0, 0), Tt = Math.min(1, N + bt), se = A + (vt - A) * Tt;
525
+ j.current !== g.direction && (j.current = g.direction, U.current = 0);
526
+ const { reachedBoundary: ve } = jt(U, g.direction * se * d);
527
+ if (ve) {
528
+ Ft();
416
529
  return;
417
530
  }
418
- W.current = window.requestAnimationFrame(Jt);
531
+ K.current = window.requestAnimationFrame(Gt);
419
532
  },
420
- [Ht, gt]
421
- ), ae = P(() => {
422
- W.current === null && (St.current = null, W.current = window.requestAnimationFrame(Jt));
423
- }, [Jt]);
424
- Y(() => () => {
425
- gt();
426
- }, [gt]);
427
- const lt = P(
428
- (o) => {
429
- ht.current = o, L(o.active), o.active && o.direction !== 0 ? ae() : gt();
533
+ [jt, Ft]
534
+ ), he = y(() => {
535
+ K.current === null && (S.current = null, U.current = 0, K.current = window.requestAnimationFrame(Gt));
536
+ }, [Gt]);
537
+ X(() => () => {
538
+ Ft();
539
+ }, [Ft]);
540
+ const ge = y(
541
+ (a) => {
542
+ H.current = a, wt(a.active), a.active && a.direction !== 0 ? he() : Ft();
430
543
  },
431
- [ae, gt]
544
+ [he, Ft]
432
545
  );
433
- Y(() => {
434
- A || Rt();
435
- }, [Rt, A]), Y(() => {
436
- const o = (w) => {
437
- const K = w.detail?.paneId;
438
- K && m && K !== m || Rt();
546
+ X(() => {
547
+ st || Pt();
548
+ }, [Pt, st]), X(() => {
549
+ const a = (g) => {
550
+ const o = g.detail?.paneId;
551
+ o && v && o !== v || Pt();
439
552
  };
440
- return window.addEventListener(Me, o), () => {
441
- window.removeEventListener(Me, o);
553
+ return window.addEventListener(Oe, a), () => {
554
+ window.removeEventListener(Oe, a);
442
555
  };
443
- }, [m, Rt]), Y(() => {
444
- if (!A)
556
+ }, [v, Pt]), X(() => {
557
+ if (!st)
445
558
  return;
446
- const o = (w) => {
447
- if (!ht.current.active || ht.current.pointerId === w.pointerId)
559
+ const a = (g) => {
560
+ if (!H.current.active || H.current.pointerId === g.pointerId)
448
561
  return;
449
- const V = w.target;
450
- if (!(V instanceof Node)) {
451
- Rt();
562
+ const w = g.target;
563
+ if (!(w instanceof Node)) {
564
+ Pt();
452
565
  return;
453
566
  }
454
- I.current?.getElement()?.contains(V) || Rt();
567
+ O.current?.getElement()?.contains(w) || Pt();
455
568
  };
456
- return document.addEventListener("pointerdown", o, !0), () => {
457
- document.removeEventListener("pointerdown", o, !0);
569
+ return document.addEventListener("pointerdown", a, !0), () => {
570
+ document.removeEventListener("pointerdown", a, !0);
458
571
  };
459
- }, [Rt, A]);
460
- const le = (o) => {
461
- if (!H || y <= 0 || p <= 0)
572
+ }, [Pt, st]);
573
+ const be = (a) => {
574
+ if (!Z || E <= 0 || m <= 0)
462
575
  return 0;
463
- const w = xt(o, 0, y);
464
- return xt(w / y * p, 0, p);
465
- }, ce = P((o) => {
466
- const { scrollBarVisible: w, effectiveTrackLength: V, maxScrollPosition: K } = b.current;
467
- if (_.debug("[ScrollBar] calculateScrollPositionFromThumb", { thumbPos: o, trackLen: V, maxScroll: K }), V <= 0 || K <= 0)
576
+ const g = mt(a, 0, E);
577
+ return mt(g / E * m, 0, m);
578
+ }, it = y((a) => {
579
+ const { scrollBarVisible: g, effectiveTrackLength: w, maxScrollPosition: o } = C.current;
580
+ if (V.debug("[ScrollBar] calculateScrollPositionFromThumb", () => ({ thumbPos: a, trackLen: w, maxScroll: o })), w <= 0 || o <= 0)
468
581
  return null;
469
- const s = xt(o, 0, V);
470
- return xt(s / V * K, 0, K);
471
- }, []), Nt = P(
472
- (o) => {
473
- const w = et.current;
474
- if (w.pointerId !== o.pointerId)
475
- return;
476
- const V = o.clientX - w.startClientX, K = o.clientY - w.startClientY, s = j(V, K);
477
- _.debug("[ScrollBar] handleThumbPointerMove", {
478
- delta: s,
479
- startThumbPosition: w.startThumbPosition,
480
- clientY: o.clientY,
481
- startClientY: w.startClientY,
482
- metrics: b.current
483
- });
484
- const a = ce(w.startThumbPosition + s);
485
- a !== null && wt(a), o.cancelable && o.preventDefault();
582
+ const c = mt(a, 0, w);
583
+ return mt(c / w * o, 0, o);
584
+ }, []), Zt = y(
585
+ (a) => {
586
+ const g = a.getBoundingClientRect(), w = u ? g.width : g.height, o = (_) => {
587
+ const A = Number.parseFloat(_);
588
+ return Number.isFinite(A) ? A : 0;
589
+ }, c = window.getComputedStyle(a), d = o(u ? c.width : c.height), P = d > 0 ? d + o(u ? c.paddingLeft : c.paddingTop) + o(u ? c.paddingRight : c.paddingBottom) + o(u ? c.borderLeftWidth : c.borderTopWidth) + o(u ? c.borderRightWidth : c.borderBottomWidth) : 0, N = P > 0 ? P : u ? a.offsetWidth : a.offsetHeight;
590
+ return N <= 0 || w <= 0 ? 1 : w / N;
486
591
  },
487
- [j, ce, wt]
488
- ), ee = P(
489
- (o) => {
490
- if (et.current.pointerId === o.pointerId)
491
- if (document.removeEventListener("pointermove", Nt), document.removeEventListener("pointerup", ee), document.removeEventListener("pointercancel", ee), et.current = { pointerId: null, startThumbPosition: 0, startClientX: 0, startClientY: 0 }, Q(!1), tt.current) {
492
- const V = tt.current.getBoundingClientRect();
493
- o.clientX >= V.left && o.clientX <= V.right && o.clientY >= V.top && o.clientY <= V.bottom || ct(!1);
494
- } else
495
- ct(!1);
592
+ [u]
593
+ ), ne = y(
594
+ (a) => {
595
+ const g = F.current;
596
+ if (g.pointerId !== a.pointerId)
597
+ return;
598
+ const w = a.clientX - g.startClientX, o = a.clientY - g.startClientY, c = ht(w, o) / (g.scale || 1);
599
+ V.debug("[ScrollBar] handleThumbPointerMove", () => ({
600
+ delta: c,
601
+ startThumbPosition: g.startThumbPosition,
602
+ clientY: a.clientY,
603
+ startClientY: g.startClientY,
604
+ metrics: C.current
605
+ }));
606
+ const d = it(g.startThumbPosition + c);
607
+ d !== null && Nt(d), a.cancelable && a.preventDefault();
496
608
  },
497
- [Nt]
498
- ), me = (o) => {
499
- const w = Math.max(Math.round(t / Ge), je);
500
- Ht(o * w);
501
- }, { handleArrowPointerDown: Ie, handleArrowPointerUp: Ot, handleArrowKeyDown: Qt } = ir({
502
- canUseArrowButtons: Zt,
503
- enableArrowButtons: c,
504
- resetTapScroll: Rt,
505
- scrollByStep: me
506
- }), Ut = (o) => {
507
- if (H) {
508
- if (!i) {
509
- o.preventDefault(), o.stopPropagation();
609
+ [ht, it, Nt]
610
+ ), Xt = y(
611
+ (a) => {
612
+ const g = F.current;
613
+ if (g.pointerId !== a.pointerId)
510
614
  return;
511
- }
512
- o.pointerType === "mouse" && o.button !== 0 || o.ctrlKey || (Rt(), et.current = {
513
- pointerId: o.pointerId,
514
- startThumbPosition: nt,
515
- startClientX: o.clientX,
516
- startClientY: o.clientY
517
- }, document.addEventListener("pointermove", Nt), document.addEventListener("pointerup", ee), document.addEventListener("pointercancel", ee), Q(!0), ct(!0), o.preventDefault(), o.stopPropagation());
615
+ document.removeEventListener("pointermove", ne), document.removeEventListener("pointerup", Xt), document.removeEventListener("pointercancel", Xt);
616
+ const w = g.captureTarget;
617
+ if (w?.hasPointerCapture?.(a.pointerId) && w.releasePointerCapture(a.pointerId), F.current = { pointerId: null, startThumbPosition: 0, startClientX: 0, startClientY: 0, scale: 1, captureTarget: null }, ot(!1), L.current) {
618
+ const o = L.current.getBoundingClientRect();
619
+ a.clientX >= o.left && a.clientX <= o.right && a.clientY >= o.top && a.clientY <= o.bottom || ft(!1);
620
+ } else
621
+ ft(!1);
622
+ },
623
+ [ne]
624
+ );
625
+ X(() => () => {
626
+ document.removeEventListener("pointermove", ne), document.removeEventListener("pointerup", Xt), document.removeEventListener("pointercancel", Xt);
627
+ }, [ne, Xt]);
628
+ const kt = b(0), xe = b(0), Me = y(
629
+ (a) => {
630
+ const g = Math.max(Math.round(C.current.viewportSize / ar), sr);
631
+ xe.current !== a && (xe.current = a, kt.current = 0), jt(kt, a * g);
632
+ },
633
+ [jt]
634
+ ), { handleArrowPointerDown: Ne, handleArrowPointerUp: Yt, handleArrowKeyDown: ie } = hr({
635
+ canUseArrowButtons: re,
636
+ enableArrowButtons: l,
637
+ resetTapScroll: Pt,
638
+ scrollByStep: Me
639
+ }), Jt = (a) => {
640
+ if (!Z)
641
+ return;
642
+ if (!n) {
643
+ a.preventDefault(), a.stopPropagation();
644
+ return;
518
645
  }
519
- }, $t = (o) => {
520
- if (!H)
646
+ if (a.pointerType === "mouse" && a.button !== 0 || a.ctrlKey)
521
647
  return;
522
- if (!l) {
523
- o.preventDefault(), o.stopPropagation();
648
+ Pt();
649
+ const g = a.currentTarget, w = Zt(g);
650
+ let o = null;
651
+ if (g.setPointerCapture)
652
+ try {
653
+ g.setPointerCapture(a.pointerId), o = g;
654
+ } catch {
655
+ o = null;
656
+ }
657
+ F.current = {
658
+ pointerId: a.pointerId,
659
+ startThumbPosition: lt,
660
+ startClientX: a.clientX,
661
+ startClientY: a.clientY,
662
+ scale: w,
663
+ captureTarget: o
664
+ }, document.addEventListener("pointermove", ne), document.addEventListener("pointerup", Xt), document.addEventListener("pointercancel", Xt), ot(!0), ft(!0), a.preventDefault(), a.stopPropagation();
665
+ }, Qt = (a) => {
666
+ if (!Z)
667
+ return;
668
+ if (!s) {
669
+ a.preventDefault(), a.stopPropagation();
524
670
  return;
525
671
  }
526
- if (o.pointerType === "mouse" && o.button !== 0 || o.ctrlKey)
672
+ if (a.pointerType === "mouse" && a.button !== 0 || a.ctrlKey)
673
+ return;
674
+ const g = a.currentTarget, w = g.getBoundingClientRect(), o = J(a), c = Zt(g), d = (o - (u ? w.left : w.top)) / c;
675
+ Pt();
676
+ const P = d - Et / 2, N = be(P);
677
+ if (Nt(N), g.setPointerCapture)
678
+ try {
679
+ g.setPointerCapture(a.pointerId);
680
+ } catch {
681
+ }
682
+ h.current = {
683
+ pointerId: a.pointerId,
684
+ startThumbPosition: P,
685
+ startClientX: a.clientX,
686
+ startClientY: a.clientY,
687
+ scale: c
688
+ }, a.preventDefault(), a.stopPropagation();
689
+ }, Bt = () => {
690
+ h.current = { pointerId: null, startThumbPosition: 0, startClientX: 0, startClientY: 0, scale: 1 };
691
+ }, ce = (a) => {
692
+ const g = h.current;
693
+ if (g.pointerId !== a.pointerId)
527
694
  return;
528
- const w = o.currentTarget, V = w.getBoundingClientRect(), s = mt(o) - (d ? V.left : V.top);
529
- Rt();
530
- const a = s - at / 2, u = le(a);
531
- wt(u), w.setPointerCapture && w.setPointerCapture(o.pointerId), E.current = {
532
- pointerId: o.pointerId,
533
- startThumbPosition: a,
534
- startClientX: o.clientX,
535
- startClientY: o.clientY
536
- }, o.preventDefault(), o.stopPropagation();
537
- }, Yt = (o) => {
538
- const w = E.current;
539
- if (w.pointerId !== o.pointerId)
695
+ if (a.pointerType === "mouse" && a.buttons === 0) {
696
+ Bt();
540
697
  return;
541
- const V = o.clientX - w.startClientX, K = o.clientY - w.startClientY, s = j(V, K), a = le(w.startThumbPosition + s);
542
- wt(a), o.cancelable && o.preventDefault();
543
- }, Kt = (o) => {
544
- if (E.current.pointerId !== o.pointerId)
698
+ }
699
+ const w = a.clientX - g.startClientX, o = a.clientY - g.startClientY, c = ht(w, o) / (g.scale || 1), d = be(g.startThumbPosition + c);
700
+ Nt(d), a.cancelable && a.preventDefault();
701
+ }, te = (a) => {
702
+ if (h.current.pointerId !== a.pointerId)
545
703
  return;
546
- const w = o.currentTarget;
547
- w.hasPointerCapture(o.pointerId) && w.releasePointerCapture(o.pointerId), E.current = { pointerId: null, startThumbPosition: 0, startClientX: 0, startClientY: 0 }, o.preventDefault(), o.stopPropagation();
548
- }, Wt = (o) => {
549
- if (E.current.pointerId !== o.pointerId)
704
+ const g = a.currentTarget;
705
+ g.hasPointerCapture?.(a.pointerId) && g.releasePointerCapture(a.pointerId), Bt(), a.preventDefault(), a.stopPropagation();
706
+ }, Pe = (a) => {
707
+ if (h.current.pointerId !== a.pointerId)
550
708
  return;
551
- const w = o.currentTarget;
552
- w.hasPointerCapture(o.pointerId) && w.releasePointerCapture(o.pointerId), E.current = { pointerId: null, startThumbPosition: 0, startClientX: 0, startClientY: 0 };
553
- }, pe = At(() => xt((st ? 1 : 0.8) * Vt, 0, 1), [st, Vt]), he = At(() => {
554
- const w = `calc(50% - ${G / 2}px + ${It}px)`;
709
+ const g = a.currentTarget;
710
+ g.hasPointerCapture?.(a.pointerId) && g.releasePointerCapture(a.pointerId), Bt();
711
+ }, ye = (a) => {
712
+ h.current.pointerId === a.pointerId && Bt();
713
+ }, Ve = yt(() => mt((St ? 1 : 0.8) * qt, 0, 1), [St, qt]), Ie = yt(() => {
714
+ const g = `calc(50% - ${Mt / 2}px + ${Dt}px)`;
555
715
  return {
556
- left: dt,
557
- top: w
716
+ left: R,
717
+ top: g
558
718
  };
559
- }, [dt, It, G]), ge = (o, w, V, K) => /* @__PURE__ */ $(
719
+ }, [R, Dt, Mt]), ue = (a, g, w, o) => /* @__PURE__ */ et(
560
720
  "button",
561
721
  {
562
722
  type: "button",
563
- tabIndex: -1,
723
+ tabIndex: 0,
564
724
  className: "aqvs-scrollbar-arrow-button",
565
725
  style: {
566
- [M]: f,
567
- [q]: f
726
+ [ct]: f,
727
+ [at]: f
568
728
  },
569
- "aria-label": w,
570
- onPointerDown: Ie(o),
571
- onPointerUp: Ot,
572
- onPointerLeave: Ot,
573
- onPointerCancel: Ot,
574
- onKeyDown: Qt(o),
575
- "aria-disabled": !c,
576
- disabled: !Zt,
577
- children: /* @__PURE__ */ $("span", { "aria-hidden": "true", children: V })
729
+ "aria-label": g,
730
+ onPointerDown: Ne(a),
731
+ onPointerUp: Yt,
732
+ onPointerLeave: Yt,
733
+ onPointerCancel: Yt,
734
+ onKeyDown: ie(a),
735
+ "aria-disabled": !l,
736
+ disabled: !re,
737
+ children: /* @__PURE__ */ et("span", { "aria-hidden": "true", children: w })
578
738
  },
579
- K
580
- ), ie = x && H ? {
581
- orientation: qt,
739
+ o
740
+ ), de = p && Z ? {
741
+ orientation: Lt,
582
742
  scrollPosition: e,
583
- maxScrollPosition: p,
584
- contentSize: n,
743
+ maxScrollPosition: m,
744
+ contentSize: i,
585
745
  viewportSize: t,
586
- thumbSize: at,
587
- thumbPosition: nt,
588
- thumbCenter: Lt,
589
- trackSize: Ct,
590
- isDragging: z,
591
- isTapScrollActive: st,
592
- visibleStartIndex: k,
593
- visibleEndIndex: B
746
+ thumbSize: Et,
747
+ thumbPosition: lt,
748
+ thumbCenter: zt,
749
+ trackSize: Ot,
750
+ isDragging: W,
751
+ isTapScrollActive: St,
752
+ visibleStartIndex: z,
753
+ visibleEndIndex: rt
594
754
  } : null;
595
- return /* @__PURE__ */ ne(
755
+ return /* @__PURE__ */ le(
596
756
  "div",
597
757
  {
598
- className: re("aqvs-scrollbar", bt, !H && "pointer-events-none opacity-0", h),
758
+ className: ae("aqvs-scrollbar", Kt, !Z && "pointer-events-none opacity-0", I),
599
759
  style: {
600
- [M]: t,
601
- [q]: f
760
+ [ct]: t,
761
+ [at]: f
602
762
  },
603
763
  role: "scrollbar",
604
764
  tabIndex: -1,
605
- "aria-controls": m,
765
+ "aria-controls": v,
606
766
  "aria-valuenow": e,
607
767
  "aria-valuemin": 0,
608
- "aria-valuemax": p,
609
- "aria-orientation": d ? "horizontal" : "vertical",
768
+ "aria-valuemax": m,
769
+ "aria-orientation": u ? "horizontal" : "vertical",
610
770
  children: [
611
- !d && H && A && /* @__PURE__ */ $(
612
- Fe,
771
+ !u && Z && st && /* @__PURE__ */ et(
772
+ We,
613
773
  {
614
- ref: I,
615
- className: re("aqvs-scrollbar-tap-circle-wrapper", v),
616
- size: G,
617
- maxVisualDistance: yt,
618
- style: he,
619
- opacity: pe,
620
- renderVisual: Gt,
621
- onDragChange: lt
774
+ ref: O,
775
+ className: ae("aqvs-scrollbar-tap-circle-wrapper", Vt),
776
+ size: Mt,
777
+ maxVisualDistance: xt,
778
+ style: Ie,
779
+ opacity: Ve,
780
+ renderVisual: M,
781
+ onDragChange: ge
622
782
  },
623
783
  "tap-circle"
624
784
  ),
625
- ge(-1, Z[0], J[0], "arrow-start"),
626
- /* @__PURE__ */ ne(
785
+ ue(-1, Ct[0], ut[0], "arrow-start"),
786
+ /* @__PURE__ */ le(
627
787
  "div",
628
788
  {
629
789
  className: "aqvs-scrollbar-track",
630
790
  style: {
631
791
  borderRadius: f / 2
632
792
  },
633
- onPointerDown: $t,
634
- onPointerMove: Yt,
635
- onPointerUp: Kt,
636
- onPointerCancel: Wt,
637
- "aria-disabled": !l,
793
+ onPointerDown: Qt,
794
+ onPointerMove: ce,
795
+ onPointerUp: te,
796
+ onPointerCancel: Pe,
797
+ onLostPointerCapture: ye,
798
+ "aria-disabled": !s,
638
799
  children: [
639
- ie && /* @__PURE__ */ $("div", { className: "aqvs-scrollbar-overlay", "aria-hidden": !0, children: x?.(ie) }, "overlay"),
640
- /* @__PURE__ */ $(
800
+ de && /* @__PURE__ */ et("div", { className: "aqvs-scrollbar-overlay", "aria-hidden": !0, children: p?.(de) }, "overlay"),
801
+ /* @__PURE__ */ et(
641
802
  "div",
642
803
  {
643
- className: re("aqvs-scrollbar-thumb-wrapper", !(H || z) && "pointer-events-none opacity-0"),
804
+ className: ae("aqvs-scrollbar-thumb-wrapper", !(Z || W) && "pointer-events-none opacity-0"),
644
805
  style: {
645
- [M]: at,
646
- [ft]: nt,
647
- ...d ? { top: 0, bottom: 0 } : { left: 0, right: 0 }
806
+ [ct]: Et,
807
+ [pt]: lt,
808
+ ...u ? { top: 0, bottom: 0 } : { left: 0, right: 0 }
648
809
  },
649
- onPointerDown: Ut,
810
+ onPointerDown: Jt,
650
811
  role: "slider",
651
- "aria-orientation": d ? "horizontal" : "vertical",
812
+ "aria-orientation": u ? "horizontal" : "vertical",
652
813
  "aria-valuenow": e,
653
814
  "aria-valuemin": 0,
654
- "aria-valuemax": p,
655
- "aria-disabled": !i,
815
+ "aria-valuemax": m,
816
+ "aria-disabled": !n,
656
817
  tabIndex: -1,
657
- children: /* @__PURE__ */ $(
818
+ children: /* @__PURE__ */ et(
658
819
  "div",
659
820
  {
660
- ref: tt,
661
- className: re("aqvs-scrollbar-thumb", d ? "aqvs-scrollbar-thumb-horizontal" : "aqvs-scrollbar-thumb-vertical"),
662
- "data-thumb-state": Ft,
821
+ ref: L,
822
+ className: ae("aqvs-scrollbar-thumb", u ? "aqvs-scrollbar-thumb-horizontal" : "aqvs-scrollbar-thumb-vertical"),
823
+ "data-thumb-state": Ht,
663
824
  style: {
664
825
  borderRadius: f - 1,
665
- cursor: i ? "pointer" : "default"
826
+ cursor: n ? "pointer" : "default"
666
827
  },
667
828
  onMouseEnter: () => {
668
- i && ct(!0);
829
+ n && ft(!0);
669
830
  },
670
831
  onMouseLeave: () => {
671
- i && ct(!1);
832
+ n && ft(!1);
672
833
  }
673
834
  },
674
835
  "thumb"
@@ -680,186 +841,195 @@ const xt = (n, t, e) => Math.min(e, Math.max(t, n)), Me = "virtualscroll:tap-scr
680
841
  },
681
842
  "track"
682
843
  ),
683
- ge(1, Z[1], J[1], "arrow-end")
844
+ ue(1, Ct[1], ut[1], "arrow-end")
684
845
  ]
685
846
  }
686
847
  );
687
- }, fe = {
848
+ }, Te = {
688
849
  maxVelocity: 6,
689
850
  minVelocity: 0.02,
690
851
  deceleration: 25e-4,
691
852
  velocitySampleWindow: 90,
692
853
  startVelocityThreshold: 0.04
693
- }, be = (n, t, e) => {
694
- for (const [r, i, l] of t)
695
- e === "add" ? n.addEventListener(r, i, l) : n.removeEventListener(r, i, l);
696
- }, ar = ye(
854
+ }, Re = (i, t, e) => {
855
+ for (const [r, n, s] of t)
856
+ e === "add" ? i.addEventListener(r, n, s) : i.removeEventListener(r, n, s);
857
+ }, xr = Fe(
697
858
  ({
698
- children: n,
859
+ children: i,
699
860
  contentSize: t,
700
861
  viewportSize: e,
701
862
  scrollBarWidth: r = 12,
702
- enableThumbDrag: i = !0,
703
- enableTrackClick: l = !0,
704
- enableArrowButtons: c = !0,
705
- enablePointerDrag: d = !0,
863
+ enableThumbDrag: n = !0,
864
+ enableTrackClick: s = !0,
865
+ enableArrowButtons: l = !0,
866
+ enablePointerDrag: u = !0,
706
867
  onScroll: f,
707
- className: h,
708
- style: m,
709
- background: g,
710
- tapScrollCircleOptions: N,
711
- inertiaOptions: x,
712
- itemCount: k,
713
- renderThumbOverlay: B,
714
- wheelSpeedMultiplier: z = 1,
715
- onWheelHorizontal: Q,
716
- contentInsets: pt,
717
- visibleStartIndex: ct,
718
- visibleEndIndex: st,
719
- renderOverlay: L,
720
- initialScrollPosition: tt = 0
721
- }, et) => {
722
- const E = T(tt), ut = T(null), Pt = T(null), ht = T(Q);
723
- Y(() => {
724
- ht.current = Q;
725
- }, [Q]);
726
- const I = T({
868
+ className: I,
869
+ style: v,
870
+ background: T,
871
+ tapScrollCircleOptions: D,
872
+ inertiaOptions: p,
873
+ itemCount: z,
874
+ renderThumbOverlay: rt,
875
+ wheelSpeedMultiplier: W = 1,
876
+ onWheelHorizontal: ot,
877
+ contentInsets: nt,
878
+ visibleStartIndex: ft,
879
+ visibleEndIndex: St,
880
+ renderOverlay: wt,
881
+ initialScrollPosition: L = 0
882
+ }, F) => {
883
+ const h = b(Number.isFinite(L) ? Math.max(0, L) : 0), $ = b(null), q = b(null), H = b(ot);
884
+ X(() => {
885
+ H.current = ot;
886
+ }, [ot]);
887
+ const O = b({
727
888
  frame: null,
728
889
  velocity: 0,
729
- lastTimestamp: null
730
- }), W = At(
890
+ lastTimestamp: null,
891
+ generation: 0
892
+ }), K = yt(
731
893
  () => ({
732
- maxVelocity: x?.maxVelocity ?? fe.maxVelocity,
733
- minVelocity: x?.minVelocity ?? fe.minVelocity,
734
- deceleration: x?.deceleration ?? fe.deceleration,
735
- velocitySampleWindow: x?.velocitySampleWindow ?? fe.velocitySampleWindow,
736
- startVelocityThreshold: x?.startVelocityThreshold ?? fe.startVelocityThreshold
894
+ maxVelocity: p?.maxVelocity ?? Te.maxVelocity,
895
+ minVelocity: p?.minVelocity ?? Te.minVelocity,
896
+ deceleration: p?.deceleration ?? Te.deceleration,
897
+ velocitySampleWindow: p?.velocitySampleWindow ?? Te.velocitySampleWindow,
898
+ startVelocityThreshold: p?.startVelocityThreshold ?? Te.startVelocityThreshold
737
899
  }),
738
- [x]
739
- ), St = At(() => ({
740
- top: Math.max(0, pt?.top ?? 0),
741
- bottom: Math.max(0, pt?.bottom ?? 0)
742
- }), [pt]);
743
- _.debug("[ScrollPane] ScrollPane rendered", {
900
+ [p]
901
+ ), S = yt(() => ({
902
+ top: Math.max(0, nt?.top ?? 0),
903
+ bottom: Math.max(0, nt?.bottom ?? 0)
904
+ }), [nt]);
905
+ V.debug("[ScrollPane] ScrollPane rendered", () => ({
744
906
  contentSize: t,
745
907
  viewportSize: e,
746
908
  scrollBarWidth: r,
747
- className: h,
748
- style: m,
749
- tapScrollCircleOptions: N,
750
- inertiaOptions: x,
751
- enablePointerDrag: d,
752
- contentInsets: St
753
- });
754
- const Dt = T({ contentSize: t, viewportSize: e });
755
- Dt.current = { contentSize: t, viewportSize: e };
756
- const ot = At(() => t > e, [t, e]), A = P(
757
- (b) => {
758
- const { contentSize: M, viewportSize: q } = Dt.current, ft = M > q, j = E.current;
759
- if (_.debug("[ScrollPane] scrollTo called", { newPosition: b, contentSize: M, viewportSize: q, currentIsScrollable: ft, prevPosition: j }), !ft)
760
- return E.current !== 0 && (E.current = 0, f?.(0, j)), E.current;
761
- const mt = typeof b == "function" ? b(E.current) : b, Z = Math.max(M - q, 0), J = xt(mt, 0, Z);
762
- return E.current !== J && (E.current = J, f?.(J, j)), E.current;
909
+ className: I,
910
+ style: v,
911
+ tapScrollCircleOptions: D,
912
+ inertiaOptions: p,
913
+ enablePointerDrag: u,
914
+ contentInsets: S
915
+ }));
916
+ const U = b({ contentSize: t, viewportSize: e });
917
+ U.current = { contentSize: t, viewportSize: e };
918
+ const j = yt(() => t > e, [t, e]), k = y(
919
+ (M) => {
920
+ const { contentSize: Y, viewportSize: C } = U.current, ct = Y > C, at = h.current;
921
+ if (V.debug("[ScrollPane] scrollTo called", () => ({ newPosition: M, contentSize: Y, viewportSize: C, currentIsScrollable: ct, prevPosition: at })), !ct)
922
+ return h.current !== 0 && (h.current = 0, f?.(0, at)), h.current;
923
+ const pt = typeof M == "function" ? M(h.current) : M;
924
+ if (!Number.isFinite(pt))
925
+ return V.warn("[ScrollPane] scrollTo received a non-finite position; keeping the current position", { nextPosition: pt }), h.current;
926
+ const ht = Math.max(Y - C, 0), J = mt(pt, 0, ht);
927
+ return h.current !== J && (h.current = J, f?.(J, at)), h.current;
763
928
  },
764
929
  [f]
765
- ), G = P(() => {
766
- const b = I.current;
767
- b.frame !== null && cancelAnimationFrame(b.frame), b.frame = null, b.velocity = 0, b.lastTimestamp = null;
768
- }, []), dt = T(G);
769
- Y(() => {
770
- dt.current = G;
771
- }, [G]);
772
- const It = P(
773
- (b) => {
774
- if (!ot)
930
+ ), G = y(() => {
931
+ const M = O.current;
932
+ M.generation += 1, M.frame !== null && cancelAnimationFrame(M.frame), M.frame = null, M.velocity = 0, M.lastTimestamp = null;
933
+ }, []), st = b(G);
934
+ X(() => {
935
+ st.current = G;
936
+ }, [G]), X(() => () => {
937
+ st.current();
938
+ }, []);
939
+ const Mt = y(
940
+ (M) => {
941
+ if (!j)
775
942
  return;
776
- const { maxVelocity: M, minVelocity: q, deceleration: ft, startVelocityThreshold: j } = W, mt = xt(b, -M, M);
777
- if (Math.abs(mt) < j)
943
+ const { maxVelocity: Y, minVelocity: C, deceleration: ct, startVelocityThreshold: at } = K, pt = mt(M, -Y, Y);
944
+ if (Math.abs(pt) < at)
778
945
  return;
779
- G(), I.current.velocity = mt, I.current.lastTimestamp = null;
780
- const Z = (J) => {
781
- const bt = I.current;
782
- if (bt.lastTimestamp === null) {
783
- bt.lastTimestamp = J, bt.frame = requestAnimationFrame(Z);
946
+ G(), O.current.velocity = pt, O.current.lastTimestamp = null;
947
+ const ht = O.current.generation, J = (Ct) => {
948
+ const ut = O.current;
949
+ if (ut.generation !== ht)
950
+ return;
951
+ if (ut.lastTimestamp === null) {
952
+ ut.lastTimestamp = Ct, ut.frame = requestAnimationFrame(J);
784
953
  return;
785
954
  }
786
- const qt = J - bt.lastTimestamp;
787
- if (bt.lastTimestamp = J, qt <= 0) {
788
- bt.frame = requestAnimationFrame(Z);
955
+ const Kt = Ct - ut.lastTimestamp;
956
+ if (ut.lastTimestamp = Ct, Kt <= 0) {
957
+ ut.frame = requestAnimationFrame(J);
789
958
  return;
790
959
  }
791
- const yt = bt.velocity;
792
- let Tt = yt;
793
- const Ct = ft * qt;
794
- yt > 0 ? Tt = Math.max(0, yt - Ct) : yt < 0 && (Tt = Math.min(0, yt + Ct));
795
- const at = (yt + Tt) / 2 * qt, p = E.current;
796
- at !== 0 && A((Ft) => Ft + at);
797
- const y = E.current, { contentSize: nt, viewportSize: Lt } = Dt.current, H = Math.max(nt - Lt, 0);
798
- bt.velocity = Tt;
799
- const Zt = y === p || y <= 0 && Tt <= 0 || y >= H && Tt >= 0;
800
- if (Math.abs(Tt) < q || Zt) {
960
+ const Lt = ut.velocity;
961
+ let xt = Lt;
962
+ const _t = ct * Kt;
963
+ Lt > 0 ? xt = Math.max(0, Lt - _t) : Lt < 0 && (xt = Math.min(0, Lt + _t));
964
+ const It = (Lt + xt) / 2 * Kt, Et = h.current;
965
+ if (It !== 0 && k((re) => re + It), O.current.generation !== ht)
966
+ return;
967
+ const m = h.current, { contentSize: E, viewportSize: lt } = U.current, zt = Math.max(E - lt, 0);
968
+ ut.velocity = xt;
969
+ const Z = m === Et || m <= 0 && xt <= 0 || m >= zt && xt >= 0;
970
+ if (Math.abs(xt) < C || Z) {
801
971
  G();
802
972
  return;
803
973
  }
804
- bt.frame = requestAnimationFrame(Z);
974
+ ut.frame = requestAnimationFrame(J);
805
975
  };
806
- I.current.frame = requestAnimationFrame(Z);
976
+ O.current.frame = requestAnimationFrame(J);
807
977
  },
808
- [ot, W, A, G]
809
- ), v = T(It);
810
- Y(() => {
811
- v.current = It;
812
- }, [It]), oe(() => {
813
- Dt.current = { contentSize: t, viewportSize: e };
814
- }, [t, e]), oe(() => {
815
- const b = Pt.current;
816
- if (!b) return;
817
- const M = () => {
818
- b.scrollTop !== 0 && (_.debug("[ScrollPane] Native scroll detected, resetting to 0", { scrollTop: b.scrollTop }), b.scrollTop = 0), b.scrollLeft !== 0 && (b.scrollLeft = 0);
978
+ [j, K, k, G]
979
+ ), R = b(Mt);
980
+ X(() => {
981
+ R.current = Mt;
982
+ }, [Mt]), pe(() => {
983
+ U.current = { contentSize: t, viewportSize: e };
984
+ }, [t, e]), pe(() => {
985
+ const M = q.current;
986
+ if (!M) return;
987
+ const Y = () => {
988
+ M.scrollTop !== 0 && (V.debug("[ScrollPane] Native scroll detected, resetting to 0", () => ({ scrollTop: M.scrollTop })), M.scrollTop = 0), M.scrollLeft !== 0 && (M.scrollLeft = 0);
819
989
  };
820
- return b.addEventListener("scroll", M), () => b.removeEventListener("scroll", M);
821
- }, []), oe(() => {
822
- if (ot) {
823
- _.debug("[ScrollPane] Adjusting scroll position due to content or viewport size change", { contentSize: t, viewportSize: e, scrollPosition: E.current });
824
- const b = xt(t - e, 0, t);
825
- E.current > b && A(b);
990
+ return M.addEventListener("scroll", Y), () => M.removeEventListener("scroll", Y);
991
+ }, []), pe(() => {
992
+ if (j) {
993
+ V.debug("[ScrollPane] Adjusting scroll position due to content or viewport size change", () => ({ contentSize: t, viewportSize: e, scrollPosition: h.current }));
994
+ const M = mt(t - e, 0, t);
995
+ h.current > M && k(M);
826
996
  } else
827
- A(0);
828
- }, [ot, A, t, e]), Y(() => {
829
- const b = (q) => {
830
- if (ht.current) {
831
- const j = q.shiftKey && q.deltaX === 0, mt = j ? q.deltaY : q.deltaX, Z = j ? 0 : q.deltaY;
832
- if (mt !== 0 && Math.abs(mt) >= Math.abs(Z)) {
833
- q.preventDefault(), G();
834
- let J = mt;
835
- q.deltaMode === 1 ? J *= 16 : q.deltaMode === 2 && (J *= e), ht.current(J);
997
+ k(0);
998
+ }, [j, k, t, e]), X(() => {
999
+ const M = (C) => {
1000
+ if (H.current && !C.ctrlKey) {
1001
+ const at = C.shiftKey && C.deltaX === 0, pt = at ? C.deltaY : C.deltaX, ht = at ? 0 : C.deltaY;
1002
+ if (pt !== 0 && Math.abs(pt) >= Math.abs(ht)) {
1003
+ C.preventDefault(), G();
1004
+ let J = pt;
1005
+ C.deltaMode === 1 ? J *= 16 : C.deltaMode === 2 && (J *= e), H.current(J);
836
1006
  return;
837
1007
  }
838
1008
  }
839
- if (!ot)
1009
+ if (!j || C.ctrlKey || C.deltaY === 0)
840
1010
  return;
841
- q.preventDefault(), G();
842
- let ft = q.deltaY;
843
- q.deltaMode === 1 ? ft *= 16 : q.deltaMode === 2 && (ft *= e), z !== 1 && (ft *= z), _.debug("[ScrollPane] wheel event", { deltaY: ft, scrollPosition: E.current, wheelSpeedMultiplier: z, deltaMode: q.deltaMode, scrollTop: Pt.current?.scrollTop }), A((j) => j + ft);
844
- }, M = ut.current;
845
- return M && M.addEventListener("wheel", b, { passive: !1 }), () => {
846
- M && M.removeEventListener("wheel", b);
1011
+ C.preventDefault(), G();
1012
+ let ct = C.deltaY;
1013
+ C.deltaMode === 1 ? ct *= 16 : C.deltaMode === 2 && (ct *= e), W !== 1 && (ct *= W), V.debug("[ScrollPane] wheel event", () => ({ deltaY: ct, scrollPosition: h.current, wheelSpeedMultiplier: W, deltaMode: C.deltaMode, scrollTop: q.current?.scrollTop })), k((at) => at + ct);
1014
+ }, Y = $.current;
1015
+ return Y && Y.addEventListener("wheel", M, { passive: !1 }), () => {
1016
+ Y && Y.removeEventListener("wheel", M);
847
1017
  };
848
- }, [ot, A, G, e, z]), we(
849
- et,
1018
+ }, [j, k, G, e, W]), ke(
1019
+ F,
850
1020
  () => ({
851
- scrollTo: (b) => (G(), A(b)),
852
- getScrollPosition: () => E.current,
1021
+ scrollTo: (M) => (G(), k(M)),
1022
+ getScrollPosition: () => h.current,
853
1023
  getContentSize: () => t,
854
1024
  getViewportSize: () => e
855
1025
  }),
856
- [A, t, e, G]
1026
+ [k, t, e, G]
857
1027
  );
858
- const kt = T(A);
859
- Y(() => {
860
- kt.current = A;
861
- }, [A]);
862
- const S = Be(), rt = T({
1028
+ const Dt = b(k);
1029
+ X(() => {
1030
+ Dt.current = k;
1031
+ }, [k]);
1032
+ const Vt = er(), x = b({
863
1033
  pointerId: null,
864
1034
  startClientY: 0,
865
1035
  startScroll: 0,
@@ -867,201 +1037,225 @@ const xt = (n, t, e) => Math.min(e, Math.max(t, n)), Me = "virtualscroll:tap-scr
867
1037
  shouldCancelNextClick: !1,
868
1038
  clickResetTimer: null,
869
1039
  velocitySamples: []
870
- }), Vt = T(d);
871
- Y(() => {
872
- Vt.current = d;
873
- }, [d]);
874
- const Gt = T(ot);
875
- Y(() => {
876
- Gt.current = ot;
877
- }, [ot]);
878
- const Mt = T(W);
879
- return Y(() => {
880
- Mt.current = W;
881
- }, [W]), Y(() => {
882
- if (d)
1040
+ }), Rt = b(u);
1041
+ X(() => {
1042
+ Rt.current = u;
1043
+ }, [u]);
1044
+ const At = b(j);
1045
+ X(() => {
1046
+ At.current = j;
1047
+ }, [j]);
1048
+ const qt = b(K);
1049
+ return X(() => {
1050
+ qt.current = K;
1051
+ }, [K]), X(() => {
1052
+ if (u)
883
1053
  return;
884
- const b = Pt.current, M = rt.current;
885
- M.pointerId && b?.hasPointerCapture(M.pointerId) && b.releasePointerCapture(M.pointerId), M.clickResetTimer !== null && (window.clearTimeout(M.clickResetTimer), M.clickResetTimer = null), M.pointerId = null, M.startClientY = 0, M.startScroll = 0, M.isDragging = !1, M.shouldCancelNextClick = !1, M.velocitySamples = [];
886
- }, [d]), Y(() => {
887
- const b = Pt.current;
888
- if (!b)
1054
+ const M = q.current, Y = x.current;
1055
+ Y.pointerId !== null && M?.hasPointerCapture(Y.pointerId) && M.releasePointerCapture(Y.pointerId), Y.clickResetTimer !== null && (window.clearTimeout(Y.clickResetTimer), Y.clickResetTimer = null), Y.pointerId = null, Y.startClientY = 0, Y.startScroll = 0, Y.isDragging = !1, Y.shouldCancelNextClick = !1, Y.velocitySamples = [];
1056
+ }, [u]), X(() => {
1057
+ const M = q.current;
1058
+ if (!M)
889
1059
  return;
890
- const M = 6, q = () => typeof performance < "u" && typeof performance.now == "function" ? performance.now() : Date.now(), ft = () => {
891
- const p = rt.current;
892
- p.pointerId = null, p.startClientY = 0, p.startScroll = 0, p.isDragging = !1, p.velocitySamples = [];
893
- }, j = () => {
894
- const p = rt.current;
895
- p.clickResetTimer !== null && (window.clearTimeout(p.clickResetTimer), p.clickResetTimer = null);
896
- }, mt = (p) => {
897
- const y = rt.current, nt = q();
898
- y.velocitySamples.push({ clientY: p, time: nt });
899
- const Lt = Mt.current.velocitySampleWindow;
900
- y.velocitySamples = y.velocitySamples.filter((H) => nt - H.time <= Lt);
901
- }, Z = (p) => p instanceof HTMLElement && p.closest("[data-scrollpane-ignore-drag='true']") !== null, J = (p) => {
902
- const y = rt.current;
903
- y.shouldCancelNextClick && (p.preventDefault(), p.stopPropagation(), y.shouldCancelNextClick = !1);
904
- }, bt = (p) => {
905
- const y = rt.current;
906
- y.isDragging || (y.isDragging = !0, y.shouldCancelNextClick = !0, b.hasPointerCapture(p.pointerId) || b.setPointerCapture(p.pointerId), mt(p.clientY));
907
- }, qt = (p) => {
908
- const y = rt.current;
909
- if (y.pointerId !== p.pointerId || !(Vt.current && Gt.current) || !y.isDragging && (Math.abs(p.clientY - y.startClientY) < M || (bt(p), !y.isDragging)))
1060
+ const Y = 6, C = () => typeof performance < "u" && typeof performance.now == "function" ? performance.now() : Date.now(), ct = () => {
1061
+ const m = x.current;
1062
+ m.pointerId = null, m.startClientY = 0, m.startScroll = 0, m.isDragging = !1, m.velocitySamples = [];
1063
+ }, at = () => {
1064
+ const m = x.current;
1065
+ m.clickResetTimer !== null && (window.clearTimeout(m.clickResetTimer), m.clickResetTimer = null);
1066
+ }, pt = (m) => {
1067
+ const E = x.current, lt = C();
1068
+ E.velocitySamples.push({ clientY: m, time: lt });
1069
+ const zt = qt.current.velocitySampleWindow;
1070
+ E.velocitySamples = E.velocitySamples.filter((Z) => lt - Z.time <= zt);
1071
+ }, ht = (m) => m instanceof HTMLElement && m.closest("[data-scrollpane-ignore-drag='true']") !== null, J = (m) => {
1072
+ const E = x.current;
1073
+ E.shouldCancelNextClick && (m.preventDefault(), m.stopPropagation(), E.shouldCancelNextClick = !1);
1074
+ }, Ct = (m) => {
1075
+ const E = x.current;
1076
+ if (!E.isDragging) {
1077
+ if (E.isDragging = !0, E.shouldCancelNextClick = !0, !M.hasPointerCapture(m.pointerId))
1078
+ try {
1079
+ M.setPointerCapture(m.pointerId);
1080
+ } catch {
1081
+ }
1082
+ pt(m.clientY);
1083
+ }
1084
+ }, ut = (m) => {
1085
+ const E = x.current;
1086
+ M.hasPointerCapture(m) && M.releasePointerCapture(m), E.shouldCancelNextClick = !1, at(), ct();
1087
+ }, Kt = (m) => {
1088
+ const E = x.current;
1089
+ if (E.pointerId !== m.pointerId)
910
1090
  return;
911
- mt(p.clientY);
912
- const nt = p.clientY - y.startClientY, Lt = y.startScroll - nt;
913
- kt.current(Lt), p.cancelable && p.preventDefault();
914
- }, yt = (p) => {
915
- const y = rt.current;
916
- if (y.pointerId !== p.pointerId)
1091
+ if (m.buttons === 0) {
1092
+ ut(m.pointerId);
917
1093
  return;
918
- y.isDragging && y.shouldCancelNextClick && p.cancelable && (p.preventDefault(), p.stopPropagation()), b.hasPointerCapture(p.pointerId) && b.releasePointerCapture(p.pointerId);
919
- let nt = 0;
920
- if (y.isDragging && y.velocitySamples.length >= 2) {
921
- const H = y.velocitySamples, Zt = Mt.current.velocitySampleWindow, Ft = H[H.length - 1], wt = H.find((Ht) => Ft.time - Ht.time <= Zt) ?? H[0];
922
- if (Ft && wt && Ft.time !== wt.time) {
923
- const Ht = Ft.clientY - wt.clientY, gt = Ft.time - wt.time;
924
- nt = -(Ht / gt);
1094
+ }
1095
+ if (!(Rt.current && At.current) || !E.isDragging && (Math.abs(m.clientY - E.startClientY) < Y || (Ct(m), !E.isDragging)))
1096
+ return;
1097
+ pt(m.clientY);
1098
+ const lt = m.clientY - E.startClientY, zt = E.startScroll - lt;
1099
+ Dt.current(zt), m.cancelable && m.preventDefault();
1100
+ }, Lt = (m) => {
1101
+ const E = x.current;
1102
+ if (E.pointerId !== m.pointerId)
1103
+ return;
1104
+ E.isDragging && E.shouldCancelNextClick && m.cancelable && (m.preventDefault(), m.stopPropagation()), E.isDragging && pt(m.clientY);
1105
+ let lt = 0;
1106
+ if (E.isDragging && E.velocitySamples.length >= 2) {
1107
+ const Z = E.velocitySamples, re = qt.current.velocitySampleWindow, Ht = Z[Z.length - 1], Nt = Z.find((Wt) => Ht.time - Wt.time <= re) ?? Z[0];
1108
+ if (Ht && Nt && Ht.time !== Nt.time) {
1109
+ const Wt = Ht.clientY - Nt.clientY, jt = Ht.time - Nt.time;
1110
+ lt = -(Wt / jt);
925
1111
  }
926
1112
  }
927
- j(), y.shouldCancelNextClick && (y.clickResetTimer = window.setTimeout(() => {
928
- const H = rt.current;
929
- H.shouldCancelNextClick = !1, H.clickResetTimer = null;
1113
+ at(), E.shouldCancelNextClick && (E.clickResetTimer = window.setTimeout(() => {
1114
+ const Z = x.current;
1115
+ Z.shouldCancelNextClick = !1, Z.clickResetTimer = null;
930
1116
  }, 0));
931
- const Lt = Mt.current.startVelocityThreshold;
932
- ft(), Math.abs(nt) >= Lt && v.current?.(nt);
933
- }, Tt = (p) => {
934
- if (!(Vt.current && Gt.current) || p.button !== 0 && p.pointerType === "mouse" || p.ctrlKey || p.metaKey || p.altKey || Z(p.target))
1117
+ const zt = qt.current.startVelocityThreshold;
1118
+ ct(), M.hasPointerCapture(m.pointerId) && M.releasePointerCapture(m.pointerId), Math.abs(lt) >= zt && R.current?.(lt);
1119
+ }, xt = (m) => {
1120
+ if (x.current.pointerId !== null || !(Rt.current && At.current) || m.button !== 0 && m.pointerType === "mouse" || m.ctrlKey || m.metaKey || m.altKey || ht(m.target))
935
1121
  return;
936
- window.dispatchEvent(new CustomEvent(Me, { detail: { paneId: S } })), dt.current?.();
937
- const y = rt.current;
938
- j(), y.pointerId = p.pointerId, y.startClientY = p.clientY, y.startScroll = E.current, y.isDragging = !1, y.shouldCancelNextClick = !1, y.velocitySamples = [];
939
- }, Ct = (p) => {
940
- const y = rt.current;
941
- y.pointerId === p.pointerId && (y.shouldCancelNextClick = !1, b.hasPointerCapture(p.pointerId) && b.releasePointerCapture(p.pointerId), j(), ft());
942
- }, _t = [
1122
+ window.dispatchEvent(new CustomEvent(Oe, { detail: { paneId: Vt } })), st.current?.();
1123
+ const E = x.current;
1124
+ at(), E.pointerId = m.pointerId, E.startClientY = m.clientY, E.startScroll = h.current, E.isDragging = !1, E.shouldCancelNextClick = !1, E.velocitySamples = [];
1125
+ }, _t = (m) => {
1126
+ x.current.pointerId === m.pointerId && ut(m.pointerId);
1127
+ }, It = [
943
1128
  ["click", J, !0],
944
- ["pointerdown", Tt, { passive: !1 }],
945
- ["pointermove", qt, { passive: !1 }],
946
- ["pointerup", yt, void 0],
947
- ["pointercancel", Ct, void 0]
948
- ], at = [
949
- ["pointermove", qt, { passive: !1 }],
950
- ["pointerup", yt, void 0],
951
- ["pointercancel", Ct, void 0]
1129
+ ["pointerdown", xt, { passive: !1 }],
1130
+ ["lostpointercapture", (m) => {
1131
+ x.current.pointerId === m.pointerId && ut(m.pointerId);
1132
+ }, void 0]
1133
+ ], Et = [
1134
+ ["pointermove", Kt, { passive: !1 }],
1135
+ ["pointerup", Lt, void 0],
1136
+ ["pointercancel", _t, void 0]
952
1137
  ];
953
- return be(b, _t, "add"), be(window, at, "add"), () => {
954
- be(b, _t, "remove"), be(window, at, "remove");
955
- const p = rt.current;
956
- p.pointerId !== null && b.hasPointerCapture(p.pointerId) && b.releasePointerCapture(p.pointerId), j(), ft();
1138
+ return Re(M, It, "add"), Re(window, Et, "add"), () => {
1139
+ Re(M, It, "remove"), Re(window, Et, "remove");
1140
+ const m = x.current;
1141
+ m.pointerId !== null && M.hasPointerCapture(m.pointerId) && M.releasePointerCapture(m.pointerId), at(), ct();
957
1142
  };
958
- }, [S]), /* @__PURE__ */ ne("div", { ref: ut, className: re("aqvs-scroll-pane", h), style: m, children: [
959
- /* @__PURE__ */ ne(
1143
+ }, [Vt]), /* @__PURE__ */ le("div", { ref: $, className: ae("aqvs-scroll-pane", I), style: v, children: [
1144
+ /* @__PURE__ */ le(
960
1145
  "div",
961
1146
  {
962
- ref: Pt,
963
- className: re("aqvs-scroll-pane-content"),
1147
+ ref: q,
1148
+ className: ae("aqvs-scroll-pane-content"),
964
1149
  style: {
965
1150
  height: e,
966
- paddingTop: St.top,
967
- paddingBottom: St.bottom,
968
- ...d ? { touchAction: "none" } : {}
1151
+ paddingTop: S.top,
1152
+ paddingBottom: S.bottom,
1153
+ // スクロール不能時 (contentSize <= viewportSize) touch-action を通常に戻し、
1154
+ // 短いリスト上のタッチがページ全体のパンを妨げるデッドゾーン化を防ぐ
1155
+ ...u && j ? { touchAction: "none" } : {}
969
1156
  },
970
- id: S,
1157
+ id: Vt,
971
1158
  children: [
972
- g,
973
- n(E.current)
1159
+ T,
1160
+ i(h.current)
974
1161
  ]
975
1162
  }
976
1163
  ),
977
- /* @__PURE__ */ $(
978
- or,
1164
+ /* @__PURE__ */ et(
1165
+ br,
979
1166
  {
980
1167
  contentSize: t,
981
1168
  viewportSize: e,
982
- scrollPosition: E.current,
983
- onScroll: A,
984
- enableThumbDrag: i,
985
- enableTrackClick: l,
986
- enableArrowButtons: c,
1169
+ scrollPosition: h.current,
1170
+ onScroll: k,
1171
+ enableThumbDrag: n,
1172
+ enableTrackClick: s,
1173
+ enableArrowButtons: l,
987
1174
  scrollBarWidth: r,
988
- ariaControls: S,
989
- tapScrollCircleOptions: N,
990
- itemCount: k,
991
- renderThumbOverlay: B,
992
- visibleStartIndex: ct,
993
- visibleEndIndex: st
1175
+ ariaControls: Vt,
1176
+ tapScrollCircleOptions: D,
1177
+ itemCount: z,
1178
+ renderThumbOverlay: rt,
1179
+ visibleStartIndex: ft,
1180
+ visibleEndIndex: St
994
1181
  },
995
1182
  "scrollbar"
996
1183
  ),
997
- L?.()
1184
+ wt?.()
998
1185
  ] });
999
1186
  }
1000
- ), Ae = (n, t, e) => Math.min(Math.max(n, t), e), Tr = ({ dragState: n, normalizedDistance: t, sizeScale: e, size: r }) => {
1001
- const i = Math.max(r / 2, 1), l = 1 + t * 0.65, c = Math.max(0.65, 1 - t * 0.25), d = n.direction * t * 26 * e, f = 0.8 + t * 0.18, h = 3 * e, m = 6 * e, g = 22 * e, N = Math.abs(d) + m, x = d > 0 ? h : -Math.abs(d) - h, k = Math.max(2.5, 3 * e), B = Ae(n.offsetX, -i, i), z = Ae(n.offsetY, -i, i), Q = i * 0.35, pt = B / i * Q, ct = z / i * Q, st = pt * 0.45, L = ct * 0.45, tt = Math.max(g * 0.38, 6), et = 0.65 + t * 0.2, E = n.active;
1002
- return /* @__PURE__ */ ne(_e, { children: [
1003
- /* @__PURE__ */ $(
1187
+ ), He = (i, t, e) => Math.min(Math.max(i, t), e), Dr = ({ dragState: i, normalizedDistance: t, sizeScale: e, size: r }) => {
1188
+ const n = Math.max(r / 2, 1), s = 1 + t * 0.65, l = Math.max(0.65, 1 - t * 0.25), u = i.direction * t * 26 * e, f = 0.8 + t * 0.18, I = 3 * e, v = 6 * e, T = 22 * e, D = Math.abs(u) + v, p = u > 0 ? I : -Math.abs(u) - I, z = Math.max(2.5, 3 * e), rt = He(i.offsetX, -n, n), W = He(i.offsetY, -n, n), ot = n * 0.35, nt = rt / n * ot, ft = W / n * ot, St = nt * 0.45, wt = ft * 0.45, L = Math.max(T * 0.38, 6), F = 0.65 + t * 0.2, h = i.active;
1189
+ return /* @__PURE__ */ le(Ke, { children: [
1190
+ /* @__PURE__ */ et(
1004
1191
  "div",
1005
1192
  {
1006
1193
  className: "aqvs-tap-scroll-circle-gradient",
1007
1194
  style: {
1008
- transform: `scale(${c}, ${l})`,
1009
- transition: E ? "40ms transform ease-out" : "200ms ease transform"
1195
+ transform: `scale(${l}, ${s})`,
1196
+ transition: h ? "40ms transform ease-out" : "200ms ease transform"
1010
1197
  }
1011
1198
  }
1012
1199
  ),
1013
- /* @__PURE__ */ $(
1200
+ /* @__PURE__ */ et(
1014
1201
  "div",
1015
1202
  {
1016
1203
  className: "aqvs-sample-visual-rod",
1017
1204
  style: {
1018
- width: g,
1019
- height: g,
1020
- transform: `translate(calc(-50% + ${pt}px), calc(-50% + ${ct}px)) scale(${c}, ${f * l})`,
1021
- transition: E ? "70ms transform ease-out" : "200ms ease transform"
1205
+ width: T,
1206
+ height: T,
1207
+ transform: `translate(calc(-50% + ${nt}px), calc(-50% + ${ft}px)) scale(${l}, ${f * s})`,
1208
+ transition: h ? "70ms transform ease-out" : "200ms ease transform"
1022
1209
  }
1023
1210
  }
1024
1211
  ),
1025
- /* @__PURE__ */ $(
1212
+ /* @__PURE__ */ et(
1026
1213
  "div",
1027
1214
  {
1028
1215
  className: "aqvs-sample-visual-pupil",
1029
1216
  style: {
1030
- width: tt,
1031
- height: tt,
1032
- transform: `translate(calc(-50% + ${st}px), calc(-50% + ${L}px)) scale(${c}, ${l})`,
1033
- opacity: et,
1217
+ width: L,
1218
+ height: L,
1219
+ transform: `translate(calc(-50% + ${St}px), calc(-50% + ${wt}px)) scale(${l}, ${s})`,
1220
+ opacity: F,
1034
1221
  boxShadow: "0 0 8px rgba(255,255,255,0.45)",
1035
- transition: E ? "120ms opacity 150ms, 120ms transform ease-out ease-out" : "220ms ease transform, 240ms opacity ease"
1222
+ transition: h ? "120ms opacity 150ms, 120ms transform ease-out ease-out" : "220ms ease transform, 240ms opacity ease"
1036
1223
  }
1037
1224
  }
1038
1225
  ),
1039
- /* @__PURE__ */ $(
1226
+ /* @__PURE__ */ et(
1040
1227
  "div",
1041
1228
  {
1042
1229
  className: "aqvs-sample-visual-highlight",
1043
1230
  style: {
1044
- width: k,
1045
- height: N,
1046
- transform: `translate(-50%, ${x}px)`,
1231
+ width: z,
1232
+ height: D,
1233
+ transform: `translate(-50%, ${p}px)`,
1047
1234
  opacity: t,
1048
- transition: E ? "40ms height, 60ms opacity ease-out ease-out" : "200ms ease height, 120ms ease opacity"
1235
+ transition: h ? "40ms height, 60ms opacity ease-out ease-out" : "200ms ease height, 120ms ease opacity"
1049
1236
  }
1050
1237
  }
1051
1238
  )
1052
1239
  ] });
1053
- }, lr = (n) => {
1054
- if (!Number.isFinite(n))
1240
+ }, Ce = 100, Ir = (i) => {
1241
+ if (!Number.isFinite(i))
1055
1242
  return 0n;
1056
- const t = Math.trunc(n);
1243
+ const t = Math.trunc(i);
1057
1244
  return t <= 0 ? 0n : BigInt(t);
1058
- }, ve = (n) => {
1059
- if (n <= 0 || !Number.isFinite(n))
1245
+ }, Le = (i, t) => {
1246
+ if (!Number.isFinite(i))
1247
+ throw new Error(`valueFn returned a non-finite value at index ${t}: ${i}`);
1248
+ return i;
1249
+ }, fe = (i) => {
1250
+ if (i <= 0 || !Number.isFinite(i))
1060
1251
  return 0;
1061
- const t = Math.trunc(n), e = BigInt(t) & -BigInt(t);
1252
+ const t = Math.trunc(i);
1253
+ if (t <= 2147483647)
1254
+ return t & -t;
1255
+ const e = BigInt(t) & -BigInt(t);
1062
1256
  return Number(e);
1063
1257
  };
1064
- class cr {
1258
+ class oe {
1065
1259
  /**
1066
1260
  * @private
1067
1261
  * @property {Map<number, number>} tree - The Map storing the Fenwick tree structure, specifically the sums of deltas. It is 1-indexed.
@@ -1106,32 +1300,48 @@ class cr {
1106
1300
  }
1107
1301
  /**
1108
1302
  * @method reset
1109
- * @description Resets the Fenwick Tree with a new size and initial values.
1110
- * @description Fenwick Tree を新しいサイズと初期値でリセット。
1303
+ * @description Resets the Fenwick Tree with a new size and initial values. The size is
1304
+ * normalized on entry (non-finite/negative sizes collapse to 0, fractions are truncated).
1305
+ * When `valueOrFn` is a function, all sampling/materialization values are computed and
1306
+ * validated (finite-only) before the tree state is mutated, so a `valueFn` returning
1307
+ * NaN/Infinity throws while leaving the previous tree state intact instead of a half-built one.
1308
+ * @description Fenwick Tree を新しいサイズと初期値でリセット。size は入口で正規化する
1309
+ * (非有限/負は 0 に縮退、小数は切り捨て)。`valueOrFn` が関数の場合、サンプリング/具現化の値は
1310
+ * 木の状態を変異させる前に計算・検証 (有限数のみ) するため、NaN/Infinity を返す `valueFn` は
1311
+ * throw しつつ木を半構築で残さず直前の状態を無傷に保つ方針。
1111
1312
  * @param {number} size - The total number of items.
1112
1313
  * @param {number | ((index: number) => number)} valueOrFn - The value for all elements, or a function to generate values.
1113
1314
  * @param {{ sampleRange?: { from: number; to: number }, materialize?: boolean }} [options] - Optional settings for initialization.
1114
1315
  */
1115
1316
  reset(t, e, r) {
1116
- if (this.size = t, this.tree = /* @__PURE__ */ new Map(), this.deltas = /* @__PURE__ */ new Map(), this.total = void 0, typeof e == "function") {
1117
- if (this.valueFn = e, this.size > 0) {
1118
- const l = r?.sampleRange ?? {
1119
- from: 0,
1120
- to: Math.min(99, this.size - 1)
1121
- }, { mode: c, materializedValues: d } = this._calculateMode(l.from, l.to);
1122
- if (this.baseValue = c, r?.materialize)
1123
- for (let f = 0; f < d.length; f++) {
1124
- const h = d[f], m = l.from + f;
1125
- if (m >= this.size)
1126
- break;
1127
- const g = h - this.baseValue;
1128
- this.deltas.set(m, g), this._updateTree(m, g);
1129
- }
1130
- } else
1131
- this.baseValue = 0;
1132
- this.total = this.getTotal();
1133
- } else
1134
- this.valueFn = void 0, this.baseValue = e, this.total = this.baseValue * this.size;
1317
+ const n = Number.isFinite(t) && t > 0 ? Math.trunc(t) : 0;
1318
+ if (typeof e != "function") {
1319
+ this.size = n, this.tree = /* @__PURE__ */ new Map(), this.deltas = /* @__PURE__ */ new Map(), this.valueFn = void 0, this.baseValue = e, this.total = this.baseValue * this.size;
1320
+ return;
1321
+ }
1322
+ let s = 0, l;
1323
+ if (n > 0) {
1324
+ const u = r?.sampleRange ?? {
1325
+ from: 0,
1326
+ to: Math.min(Ce - 1, n - 1)
1327
+ };
1328
+ let f = Math.max(0, Math.trunc(u.from)), I = Math.min(Math.trunc(u.to), n - 1);
1329
+ if (f > I && (f = 0, I = Math.min(Ce - 1, n - 1)), n > Ce)
1330
+ s = oe._sampleBaseValueStrided(e, n, Ce), r?.materialize && (l = { from: f, values: oe._collectValidatedValues(e, f, I) });
1331
+ else {
1332
+ const v = oe._collectValidatedValues(e, f, I);
1333
+ s = oe._modeOrMedian([...v]), r?.materialize && (l = { from: f, values: v });
1334
+ }
1335
+ }
1336
+ if (this.size = n, this.tree = /* @__PURE__ */ new Map(), this.deltas = /* @__PURE__ */ new Map(), this.total = void 0, this.valueFn = e, this.baseValue = s, l)
1337
+ for (let u = 0; u < l.values.length; u++) {
1338
+ const f = l.from + u;
1339
+ if (f >= this.size)
1340
+ break;
1341
+ const I = l.values[u] - this.baseValue;
1342
+ I !== 0 && (this.deltas.set(f, I), this._updateTree(f, I));
1343
+ }
1344
+ this.total = this.getTotal();
1135
1345
  }
1136
1346
  /**
1137
1347
  * @method setValueFn
@@ -1145,44 +1355,73 @@ class cr {
1145
1355
  this.reset(this.size, t);
1146
1356
  return;
1147
1357
  }
1148
- typeof t == "function" ? this.valueFn = t : (this.valueFn = void 0, this.baseValue = t);
1358
+ typeof t == "function" ? this.valueFn = t : (this.valueFn = void 0, this.baseValue = t, this.total = this._computeTreeTotal());
1149
1359
  }
1150
1360
  /**
1151
1361
  * @private
1152
- * @method _calculateMode
1153
- * @description Calculates the mode (most frequent value) within a given range of values generated by `valueFn`. If multiple modes exist, it returns their average. If no value appears more than once, it returns the median of the range. This approach helps determine a representative `baseValue` for the Fenwick tree, especially for data with high variance. It also returns the array of values generated within the range for reuse.
1154
- * @description `valueFn` によって生成される値の指定された範囲内の最頻値を計算する。最頻値が複数存在する場合は、それらの平均値を返す。どの値も複数回出現しない場合は、範囲の中央値を返す。このアプローチは、特に分散の大きいデータに対して、Fenwick Tree の代表的な `baseValue` を決定するのに役立つ。また、再利用のために範囲内で生成された値の配列も返す。
1362
+ * @method _collectValidatedValues
1363
+ * @description Evaluates `valueFn` over the inclusive `[from, to]` range and returns the values, throwing on any non-finite result. Validation happens here, before any tree mutation, so a poisoned `valueFn` can never leave the tree half-built.
1364
+ * @description `valueFn` を閉区間 `[from, to]` で評価して値配列を返す。非有限値は throw で拒否。検証を木の変異前 (このメソッド内) で行うことで、汚染された `valueFn` が木を半構築のまま残す事態の防止。
1365
+ * @param {(index: number) => number} valueFn - The value-generating function to evaluate.
1155
1366
  * @param {number} from - The starting index of the range (inclusive).
1156
1367
  * @param {number} to - The ending index of the range (inclusive).
1157
- * @returns {{ mode: number; materializedValues: number[] }} An object containing the calculated mode and the array of generated values.
1368
+ * @returns {number[]} The validated (finite-only) values in index order.
1369
+ */
1370
+ static _collectValidatedValues(t, e, r) {
1371
+ const n = [];
1372
+ for (let s = e; s <= r; s++)
1373
+ n.push(Le(t(s), s));
1374
+ return n;
1375
+ }
1376
+ /**
1377
+ * @private
1378
+ * @method _modeOrMedian
1379
+ * @description Reduces a sample of generated values to a single representative height: the mode when it is frequent enough to be trustworthy, otherwise the median. A value is only accepted as the mode when its frequency exceeds 20% of the sample; this prevents periodic or near-uniform data (where sampling bias can make an arbitrary value momentarily frequent) from picking an unrepresentative base. Multiple co-modes are averaged.
1380
+ * @description サンプル値を 1 つの代表的な高さへ縮約する。信頼できるほど頻出する場合は最頻値を、そうでなければ中央値を返す。最頻値はサンプルの 20% を超える頻度のときのみ採用し、周期的/ほぼ一様なデータ (サンプリング偏りで任意の値が一時的に頻出しうる) が非代表値を選ぶのを防ぐ。同率最頻値が複数ある場合は平均する。
1381
+ * @param {number[]} values - The sampled values (mutated in place by sorting).
1382
+ * @returns {number} The representative base value.
1158
1383
  */
1159
- _calculateMode(t, e) {
1160
- if (!this.valueFn)
1161
- return { mode: 0, materializedValues: [] };
1162
- const r = [];
1163
- for (let h = t; h <= e && !(h >= this.size); h++)
1164
- r.push(this.valueFn(h));
1165
- const i = [...r];
1166
- if (r.length === 0)
1167
- return { mode: 0, materializedValues: [] };
1168
- r.sort((h, m) => h - m);
1169
- const l = Math.floor(r.length / 2);
1170
- let c;
1171
- r.length % 2 === 0 ? c = Math.floor((r[l - 1] + r[l]) / 2) : c = r[l];
1172
- const d = /* @__PURE__ */ new Map();
1173
- let f = 0;
1174
- for (const h of r) {
1175
- const m = (d.get(h) ?? 0) + 1;
1176
- d.set(h, m), m > f && (f = m);
1384
+ static _modeOrMedian(t) {
1385
+ if (t.length === 0)
1386
+ return 0;
1387
+ t.sort((l, u) => l - u);
1388
+ const e = Math.floor(t.length / 2);
1389
+ let r;
1390
+ t.length % 2 === 0 ? r = Math.floor((t[e - 1] + t[e]) / 2) : r = t[e];
1391
+ const n = /* @__PURE__ */ new Map();
1392
+ let s = 0;
1393
+ for (const l of t) {
1394
+ const u = (n.get(l) ?? 0) + 1;
1395
+ n.set(l, u), u > s && (s = u);
1177
1396
  }
1178
- if (f > r.length * 0.2) {
1179
- const h = [];
1180
- for (const [g, N] of d.entries())
1181
- N === f && h.push(g);
1182
- const m = h.reduce((g, N) => g + N, 0);
1183
- c = Math.floor(m / h.length);
1397
+ if (s > t.length * 0.2) {
1398
+ const l = [];
1399
+ for (const [f, I] of n.entries())
1400
+ I === s && l.push(f);
1401
+ const u = l.reduce((f, I) => f + I, 0);
1402
+ r = Math.floor(u / l.length);
1184
1403
  }
1185
- return { mode: c, materializedValues: i };
1404
+ return r;
1405
+ }
1406
+ /**
1407
+ * @private
1408
+ * @method _sampleBaseValueStrided
1409
+ * @description Estimates `baseValue` by evaluating `valueFn` at up to `sampleCount` points spread across the entire `[0, size-1]` range, then reducing them via `_modeOrMedian`. Spanning the whole list (rather than a fixed head window) makes the majority height win even when the first items are atypical (hero/heading rows). The stride uses `ceil(size / sampleCount)` so the samples always span the whole range — `floor` would collapse to stride 1 for `sampleCount < size < 2 * sampleCount` and only ever look at the head. The stride is also forced odd to avoid aliasing against common even-period layouts (e.g. alternating or 20-row cycles), which a stride that shares a factor with the period would otherwise collapse into a single residue. For a uniform list every sample is identical, so the estimate is unchanged. Non-finite sample values throw before any state is touched.
1410
+ * @description `valueFn` を `[0, size-1]` 全域に散らした最大 `sampleCount` 点で評価し、`_modeOrMedian` で縮約して `baseValue` を推定する。先頭固定ウィンドウではなくリスト全体を跨ぐことで、先頭が非典型 (ヒーロー/見出し行) でも多数派の高さが選ばれる。ストライドは `ceil(size / sampleCount)` を用いて常に全域を跨がせる (`floor` だと `sampleCount < size < 2 * sampleCount` で stride=1 に潰れ先頭しか見ない盲点が生じる)。さらに奇数へ強制し、周期と公約数を持つストライドがサンプルを 1 剰余類へ潰してしまう周期レイアウト (交互・20行周期など) とのエイリアシングを避ける。一様リストでは全サンプルが同一なので推定値は不変。非有限のサンプル値は状態を変異させる前に throw で拒否。
1411
+ * @param {(index: number) => number} valueFn - The value-generating function to sample.
1412
+ * @param {number} size - The total number of items the tree will manage.
1413
+ * @param {number} sampleCount - Maximum number of points to evaluate.
1414
+ * @returns {number} The estimated base value.
1415
+ */
1416
+ static _sampleBaseValueStrided(t, e, r) {
1417
+ if (e <= 0)
1418
+ return 0;
1419
+ let n = Math.max(1, Math.ceil(e / r));
1420
+ n % 2 === 0 && (n += 1);
1421
+ const s = [];
1422
+ for (let l = 0; l < e && s.length < r; l += n)
1423
+ s.push(Le(t(l), l));
1424
+ return oe._modeOrMedian(s);
1186
1425
  }
1187
1426
  /**
1188
1427
  * @method update
@@ -1206,8 +1445,8 @@ class cr {
1206
1445
  }
1207
1446
  /**
1208
1447
  * @method updateDelta
1209
- * @description Updates the delta at a given index and propagates the change through the tree.
1210
- * @description 指定されたインデックスのデルタを更新し、変更をツリーに伝播させる。
1448
+ * @description Updates the delta at a given index and propagates the change through the tree. A change that would make the effective value (`baseValue` + delta) negative is rejected with an error, mirroring the negative-value rejection of `update`/`updates`.
1449
+ * @description 指定されたインデックスのデルタを更新し、変更をツリーに伝播させる。適用後の実効値 (`baseValue` + delta) が負になる変更は `update`/`updates` の負値拒否と対称に throw で拒否する方針。
1211
1450
  * @param {number} index - The 0-based index to update.
1212
1451
  * @param {number} change - The value to add to the delta at the given index.
1213
1452
  */
@@ -1216,16 +1455,27 @@ class cr {
1216
1455
  }
1217
1456
  /**
1218
1457
  * @method updateDeltas
1219
- * @description Updates the deltas at given indices and propagates the changes through the tree.
1220
- * @description 指定されたインデックスのデルタを更新し、変更をツリーに伝播させる。
1458
+ * @description Updates the deltas at given indices and propagates the changes through the tree. All entries are validated up front (atomicity): out-of-range or non-integer indices, non-finite changes, and changes whose resulting effective value (`baseValue` + delta) would turn negative are rejected with an error before anything is applied. Negative effective values would break the monotonic prefix sums that `_descend`/`_findIndexLarge` rely on.
1459
+ * @description 指定されたインデックスのデルタを更新し、変更をツリーに伝播させる。全件を先に検証してから適用する (アトミック性): 範囲外/非整数の index、非有限の change、適用後の実効値 (`baseValue` + delta) が負になる変更はいずれも適用前に throw で拒否。負の実効値は `_descend`/`_findIndexLarge` が前提とする累積和の単調性を破壊するため。
1221
1460
  * @param {DeltaUpdate[]} updates - An array of updates, each with an index and the change to apply.
1222
1461
  */
1223
1462
  updateDeltas(t) {
1224
- for (const { index: e, change: r } of t) {
1225
- if (e < 0 || e >= this.size)
1226
- throw new Error(`Index ${e} out of bounds`);
1227
- const i = this.deltas.get(e) ?? 0;
1228
- this.deltas.set(e, i + r), this._updateTree(e, r);
1463
+ const e = /* @__PURE__ */ new Map();
1464
+ for (const { index: r, change: n } of t) {
1465
+ if (r < 0 || r >= this.size)
1466
+ throw new Error(`Index ${r} out of bounds`);
1467
+ if (!Number.isInteger(r))
1468
+ throw new Error(`Index must be an integer: ${r}`);
1469
+ if (!Number.isFinite(n))
1470
+ throw new Error(`Change must be a finite number: ${n}`);
1471
+ const l = (e.get(r) ?? this.deltas.get(r) ?? 0) + n;
1472
+ if (l + this.baseValue < -1e-9)
1473
+ throw new Error(`Change would make the value at index ${r} negative: ${l + this.baseValue}`);
1474
+ e.set(r, l);
1475
+ }
1476
+ for (const { index: r, change: n } of t) {
1477
+ const l = (this.deltas.get(r) ?? 0) + n;
1478
+ l === 0 ? this.deltas.delete(r) : this.deltas.set(r, l), this._updateTree(r, n);
1229
1479
  }
1230
1480
  return this.total;
1231
1481
  }
@@ -1243,10 +1493,10 @@ class cr {
1243
1493
  let r = t + 1;
1244
1494
  for (; r <= this.size; ) {
1245
1495
  this.tree.set(r, (this.tree.get(r) ?? 0) + e);
1246
- const i = ve(r);
1247
- if (i === 0)
1496
+ const n = fe(r);
1497
+ if (n === 0)
1248
1498
  break;
1249
- r += i;
1499
+ r += n;
1250
1500
  }
1251
1501
  this.total !== void 0 && (this.total += e);
1252
1502
  }
@@ -1259,14 +1509,18 @@ class cr {
1259
1509
  * @returns {DeltaUpdate[]} Sanitized delta updates ready to apply.
1260
1510
  */
1261
1511
  _buildDeltaUpdates(t) {
1262
- const e = [];
1263
- for (const { index: r, value: i } of t) {
1264
- if (r < 0 || r >= this.size)
1265
- throw new Error(`Index ${r} out of bounds`);
1266
- if (i < 0)
1512
+ const e = [], r = /* @__PURE__ */ new Map();
1513
+ for (const { index: n, value: s } of t) {
1514
+ if (n < 0 || n >= this.size)
1515
+ throw new Error(`Index ${n} out of bounds`);
1516
+ if (!Number.isInteger(n))
1517
+ throw new Error(`Index must be an integer: ${n}`);
1518
+ if (!Number.isFinite(s))
1519
+ throw new Error(`Value must be a finite number: ${s}`);
1520
+ if (s < 0)
1267
1521
  throw new Error("Value cannot be negative.");
1268
- const l = this.deltas.has(r) ? (this.deltas.get(r) ?? 0) + this.baseValue : this.baseValue, c = i - l;
1269
- c !== 0 && e.push({ index: r, change: c });
1522
+ const l = r.has(n) ? r.get(n) ?? 0 : this.deltas.get(n) ?? 0, u = l + this.baseValue, f = s - u;
1523
+ f !== 0 && e.push({ index: n, change: f }), r.set(n, l + f);
1270
1524
  }
1271
1525
  return e;
1272
1526
  }
@@ -1283,7 +1537,7 @@ class cr {
1283
1537
  let t = 0, e = this.size;
1284
1538
  for (; e > 0; ) {
1285
1539
  t += this.tree.get(e) ?? 0;
1286
- const r = ve(e);
1540
+ const r = fe(e);
1287
1541
  if (r === 0)
1288
1542
  break;
1289
1543
  e -= r;
@@ -1293,17 +1547,17 @@ class cr {
1293
1547
  /**
1294
1548
  * @private
1295
1549
  * @method _materialize
1296
- * @description Materializes the value at a specific index if it hasn't been already.
1297
- * @description 特定のインデックスの値がまだ具現化されていない場合に具現化する。
1550
+ * @description Materializes the value at a specific index if it hasn't been already. A non-finite `valueFn` result throws before any mutation, symmetric with the update-path validation, so the tree is never poisoned.
1551
+ * @description 特定のインデックスの値がまだ具現化されていない場合に具現化する。`valueFn` の非有限な返値は変異前に throw で拒否 (update 系の検証と対称) し、木を汚染させない方針。
1298
1552
  * @param {number} index - The 0-based index to materialize.
1299
1553
  * @param {boolean} [updateTree=true] - Whether to update the Fenwick tree after materialization.
1300
1554
  */
1301
1555
  _materialize(t, e = !0) {
1302
1556
  if (this.valueFn) {
1303
- const r = this.deltas.get(t) ?? 0, l = this.valueFn(t) - this.baseValue;
1304
- if (l !== r && (this.deltas.set(t, l), e)) {
1305
- const c = l - r;
1306
- this._updateTree(t, c);
1557
+ const r = this.deltas.get(t) ?? 0, s = Le(this.valueFn(t), t) - this.baseValue;
1558
+ if (s !== r && (s === 0 ? this.deltas.delete(t) : this.deltas.set(t, s), e)) {
1559
+ const l = s - r;
1560
+ this._updateTree(t, l);
1307
1561
  }
1308
1562
  }
1309
1563
  }
@@ -1319,12 +1573,12 @@ class cr {
1319
1573
  _materializeRanges(t, e, r = !1) {
1320
1574
  if (!(t?.materialize && this.valueFn))
1321
1575
  return;
1322
- const i = t.ranges;
1323
- if (i && i.length > 0) {
1324
- for (const d of i) {
1325
- const f = d.from, h = Math.min(d.to, this.size - 1);
1326
- for (let m = f; m <= h; m++)
1327
- this._materialize(m);
1576
+ const n = t.ranges;
1577
+ if (n && n.length > 0) {
1578
+ for (const u of n) {
1579
+ const f = Math.max(0, Math.trunc(u.from)), I = Math.min(Math.trunc(u.to), this.size - 1);
1580
+ for (let v = f; v <= I; v++)
1581
+ this._materialize(v);
1328
1582
  }
1329
1583
  if (e === void 0)
1330
1584
  return;
@@ -1332,8 +1586,8 @@ class cr {
1332
1586
  this._materialize(e);
1333
1587
  return;
1334
1588
  }
1335
- const l = i[0].from, c = i[i.length - 1].to;
1336
- e >= l && e <= c && this._materialize(e);
1589
+ const s = n[0].from, l = n[n.length - 1].to;
1590
+ e >= s && e <= l && this._materialize(e);
1337
1591
  return;
1338
1592
  }
1339
1593
  e !== void 0 && this._materialize(e);
@@ -1349,32 +1603,53 @@ class cr {
1349
1603
  * @returns {{ index: number; total: number | undefined; cumulative: number | undefined; currentValue: number | undefined; safeIndex: number | undefined }} Binary search result.
1350
1604
  */
1351
1605
  _findIndex(t, e = {}, r) {
1352
- if (this.size > 2147483647)
1606
+ if (this.size >= 1073741824)
1353
1607
  return this._findIndexLarge(t, e, r);
1354
1608
  if (this.size === 0)
1355
1609
  return { index: -1, total: this.total ?? 0, cumulative: void 0, currentValue: void 0, safeIndex: void 0 };
1356
- let i = 0, l = 0, c = 1;
1357
- for (; c << 1 <= this.size; )
1358
- c <<= 1;
1359
- for (; c > 0; c >>= 1) {
1360
- const h = i + c;
1361
- if (h <= this.size) {
1362
- const g = (this.tree.get(h) ?? 0) + this.baseValue * c;
1363
- (r ? l + g < t : l + g <= t) && (i = h, l += g);
1364
- }
1610
+ this._materializeRanges(e.materializeOption);
1611
+ const n = e.materializeOption?.materialize === !0;
1612
+ let s;
1613
+ for (; ; ) {
1614
+ if (s = this._descend(t, r), s < 0 || s >= this.size)
1615
+ return { index: -1, total: this.total ?? this.getTotal(), cumulative: void 0, currentValue: void 0, safeIndex: void 0 };
1616
+ if (!n)
1617
+ break;
1618
+ const u = this.deltas.get(s) ?? 0;
1619
+ if (this._materialize(s), (this.deltas.get(s) ?? 0) === u)
1620
+ break;
1365
1621
  }
1366
- const d = r ? i : i - 1;
1367
- if (d < 0 || d >= this.size)
1368
- return { index: -1, total: this.total ?? this.getTotal(), cumulative: void 0, currentValue: void 0, safeIndex: void 0 };
1369
- const f = this.prefixSum(d, e);
1622
+ const l = this.prefixSum(s);
1370
1623
  return {
1371
- index: d,
1372
- total: this.total ?? f.total,
1373
- cumulative: f.cumulative,
1374
- currentValue: f.currentValue,
1375
- safeIndex: f.safeIndex
1624
+ index: s,
1625
+ total: this.total ?? l.total,
1626
+ cumulative: l.cumulative,
1627
+ currentValue: l.currentValue,
1628
+ safeIndex: l.safeIndex
1376
1629
  };
1377
1630
  }
1631
+ /**
1632
+ * @private
1633
+ * @method _descend
1634
+ * @description Performs a single bitwise descent over the current tree state, returning the candidate index for the boundary condition without mutating the tree.
1635
+ * @description 現在の木の状態に対してビット降下を 1 回実行し、木を変異させずに境界条件の候補インデックスを返す。
1636
+ * @param {number} target - Target cumulative value.
1637
+ * @param {boolean} chooseLowerBound - When true, finds the smallest index meeting or exceeding the target; otherwise finds the largest index not exceeding it.
1638
+ * @returns {number} The candidate index (may be out of range when no index satisfies the condition).
1639
+ */
1640
+ _descend(t, e) {
1641
+ let r = 0, n = 0, s = 1;
1642
+ for (; s << 1 <= this.size; )
1643
+ s <<= 1;
1644
+ for (; s > 0; s >>= 1) {
1645
+ const l = r + s;
1646
+ if (l <= this.size) {
1647
+ const f = (this.tree.get(l) ?? 0) + this.baseValue * s;
1648
+ (e ? n + f < t : n + f <= t) && (r = l, n += f);
1649
+ }
1650
+ }
1651
+ return e ? r : r - 1;
1652
+ }
1378
1653
  /**
1379
1654
  * Executes a binary search using bigint arithmetic for extremely large sizes.
1380
1655
  *
@@ -1383,35 +1658,44 @@ class cr {
1383
1658
  _findIndexLarge(t, e, r) {
1384
1659
  if (this.size === 0)
1385
1660
  return { index: -1, total: this.total ?? 0, cumulative: void 0, currentValue: void 0, safeIndex: void 0 };
1386
- const i = lr(this.size);
1387
- if (i === 0n)
1661
+ const n = Ir(this.size);
1662
+ if (n === 0n)
1388
1663
  return { index: -1, total: this.total ?? 0, cumulative: void 0, currentValue: void 0, safeIndex: void 0 };
1389
- let l = 0n, c = i - 1n, d, f, h, m = this.total;
1390
- for (; l <= c; ) {
1391
- const x = l + c >> 1n, k = Number(x), B = this.prefixSum(k, e);
1392
- if (h = B, m = B.total, r ? B.cumulative >= t : B.cumulative <= t)
1393
- if (d = x, f = B, r) {
1394
- if (x === 0n)
1664
+ this._materializeRanges(e.materializeOption);
1665
+ const s = e.materializeOption?.materialize === !0;
1666
+ for (; ; ) {
1667
+ let l = 0n, u = n - 1n, f, I, v = this.total;
1668
+ for (; l <= u; ) {
1669
+ const p = l + u >> 1n, z = Number(p), rt = this.prefixSum(z);
1670
+ if (v = rt.total, r ? rt.cumulative >= t : rt.cumulative <= t)
1671
+ if (f = p, I = rt, r) {
1672
+ if (p === 0n)
1673
+ break;
1674
+ u = p - 1n;
1675
+ } else
1676
+ l = p + 1n;
1677
+ else if (r)
1678
+ l = p + 1n;
1679
+ else {
1680
+ if (p === 0n)
1395
1681
  break;
1396
- c = x - 1n;
1397
- } else
1398
- l = x + 1n;
1399
- else if (r)
1400
- l = x + 1n;
1401
- else {
1402
- if (x === 0n)
1403
- break;
1404
- c = x - 1n;
1682
+ u = p - 1n;
1683
+ }
1405
1684
  }
1685
+ const T = I, D = f !== void 0 ? Number(f) : -1;
1686
+ if (s && D >= 0) {
1687
+ const p = this.deltas.get(D) ?? 0;
1688
+ if (this._materialize(D), (this.deltas.get(D) ?? 0) !== p)
1689
+ continue;
1690
+ }
1691
+ return {
1692
+ index: D,
1693
+ total: v,
1694
+ cumulative: T?.cumulative,
1695
+ currentValue: T?.currentValue,
1696
+ safeIndex: T?.safeIndex
1697
+ };
1406
1698
  }
1407
- const g = f ?? h;
1408
- return {
1409
- index: d !== void 0 ? Number(d) : -1,
1410
- total: m,
1411
- cumulative: g?.cumulative,
1412
- currentValue: g?.currentValue,
1413
- safeIndex: g?.safeIndex
1414
- };
1415
1699
  }
1416
1700
  /**
1417
1701
  * @method prefixSum
@@ -1422,21 +1706,23 @@ class cr {
1422
1706
  * @returns {{ cumulative: number; total: number | undefined; currentValue: number; safeIndex: number }} The cumulative sum of values from index 0 to the given index, the total sum, and the value at the given index.
1423
1707
  */
1424
1708
  prefixSum(t, e) {
1425
- if (t < 0)
1709
+ if (t < 0 || Number.isNaN(t))
1426
1710
  return { cumulative: 0, total: this.total, currentValue: 0, safeIndex: 0 };
1427
- const r = xt(t, 0, this.size - 1), i = e?.materializeOption;
1428
- this._materializeRanges(i, r, !0);
1429
- let l = 0, c = r + 1;
1430
- for (; c > 0; ) {
1431
- const f = this.tree.get(c) ?? 0;
1432
- l += f;
1433
- const h = ve(c);
1434
- if (h === 0)
1711
+ if (this.size === 0)
1712
+ return { cumulative: 0, total: this.total ?? 0, currentValue: 0, safeIndex: 0 };
1713
+ const r = mt(Math.trunc(t), 0, this.size - 1), n = e?.materializeOption;
1714
+ this._materializeRanges(n, r, !0);
1715
+ let s = 0, l = r + 1;
1716
+ for (; l > 0; ) {
1717
+ const f = this.tree.get(l) ?? 0;
1718
+ s += f;
1719
+ const I = fe(l);
1720
+ if (I === 0)
1435
1721
  break;
1436
- c -= h;
1722
+ l -= I;
1437
1723
  }
1438
- const d = i?.materialize ? this.get(r) : (this.deltas.get(r) || 0) + this.baseValue;
1439
- return { cumulative: l + this.baseValue * (r + 1), total: this.total, currentValue: d, safeIndex: r };
1724
+ const u = n?.materialize ? this.get(r) : (this.deltas.get(r) || 0) + this.baseValue;
1725
+ return { cumulative: s + this.baseValue * (r + 1), total: this.total, currentValue: u, safeIndex: r };
1440
1726
  }
1441
1727
  /**
1442
1728
  * @method get
@@ -1447,7 +1733,9 @@ class cr {
1447
1733
  * @returns {number} The value at the given index.
1448
1734
  */
1449
1735
  get(t, e) {
1450
- if (t < 0 || t >= this.size)
1736
+ if (this.size === 0)
1737
+ return 0;
1738
+ if (!Number.isInteger(t) || t < 0 || t >= this.size)
1451
1739
  throw new Error("Index out of bounds");
1452
1740
  const r = e?.materializeOption;
1453
1741
  return this._materializeRanges(r, t), (this.deltas.get(t) ?? 0) + this.baseValue;
@@ -1467,7 +1755,7 @@ class cr {
1467
1755
  else {
1468
1756
  this.total = this._computeTreeTotal();
1469
1757
  const r = this.prefixSum(this.getSize() - 1);
1470
- r.cumulative !== r.total && _.error("Inconsistent Fenwick Tree state");
1758
+ r.cumulative !== r.total && V.error("Inconsistent Fenwick Tree state");
1471
1759
  }
1472
1760
  return this.total;
1473
1761
  }
@@ -1481,20 +1769,20 @@ class cr {
1481
1769
  rebuildTree(t) {
1482
1770
  if (t?.materialize && this.valueFn) {
1483
1771
  const r = this.valueFn;
1484
- this.reset(this.size, (i) => r(i), { materialize: !0 });
1772
+ this.reset(this.size, (n) => r(n), { materialize: !0 });
1485
1773
  return;
1486
1774
  }
1487
1775
  const e = /* @__PURE__ */ new Map();
1488
- for (const [r, i] of this.deltas.entries()) {
1489
- if (i === 0)
1776
+ for (const [r, n] of this.deltas.entries()) {
1777
+ if (n === 0)
1490
1778
  continue;
1491
- let l = r + 1;
1492
- for (; l <= this.size; ) {
1493
- e.set(l, (e.get(l) ?? 0) + i);
1494
- const c = ve(l);
1495
- if (c === 0)
1779
+ let s = r + 1;
1780
+ for (; s <= this.size; ) {
1781
+ e.set(s, (e.get(s) ?? 0) + n);
1782
+ const l = fe(s);
1783
+ if (l === 0)
1496
1784
  break;
1497
- l += c;
1785
+ s += l;
1498
1786
  }
1499
1787
  }
1500
1788
  this.tree = e, this.total = this._computeTreeTotal();
@@ -1515,20 +1803,110 @@ class cr {
1515
1803
  }
1516
1804
  /**
1517
1805
  * @method changeSize
1518
- * @description Changes the size of the Fenwick Tree.
1519
- * @description Fenwick Tree のサイズを変更する。
1806
+ * @description Changes the size of the Fenwick Tree. Only tail growth/shrink is modelled: this
1807
+ * method receives a size delta, not an index mapping, so it assumes items are appended to or
1808
+ * removed from the tail. Existing rows keep their index-to-height association. It therefore
1809
+ * cannot represent a middle insertion/deletion — after such a structural change the index↔height
1810
+ * mapping is no longer preserved and the tree's deltas would apply to the wrong rows. Consumers
1811
+ * that insert or remove items in the middle must instead reset the tree (see
1812
+ * `useFenwickMapTree`'s `resetOnValueFnChange`, surfaced as `resetOnGetItemHeightChange` in
1813
+ * VirtualScroll) or remount the component with a new `key`.
1814
+ * @description Fenwick Tree のサイズを変更する。モデル化するのは末尾の伸長/縮小のみ: 本メソッドは
1815
+ * サイズ差分のみを受け取りインデックスの対応表は受け取らないため、要素は末尾に追加/末尾から削除
1816
+ * されると仮定する。既存行は index↔高さ の対応を保つ。したがって中間挿入/削除は表現できず、その
1817
+ * ような構造変更の後は index↔高さ の対応が保存されず、木の delta が誤った行へ適用されてしまう。
1818
+ * 中間で要素を挿入/削除する消費側は、代わりに木をリセットするか (`useFenwickMapTree` の
1819
+ * `resetOnValueFnChange`。VirtualScroll では `resetOnGetItemHeightChange` として公開) 、新しい
1820
+ * `key` でコンポーネントを再マウントすること。
1821
+ * @remarks Validation: a non-finite `newSize` (NaN/Infinity) throws because it would poison
1822
+ * `size`/`total` irrecoverably. Fractional sizes are truncated and negative sizes collapse to 0,
1823
+ * matching the normalization rule of `reset`.
1824
+ * @remarks 検証: 非有限の `newSize` (NaN/Infinity) は `size`/`total` を復旧不能に汚染するため
1825
+ * throw。小数は切り捨て、負値は 0 に縮退 (`reset` の正規化規則と同一)。
1520
1826
  * @param {number} newSize - The new size of the tree.
1521
1827
  */
1522
1828
  changeSize(t) {
1523
- const e = this.size;
1524
- if (t === e)
1829
+ if (!Number.isFinite(t))
1830
+ throw new Error(`Size must be a finite number: ${t}`);
1831
+ const e = Math.max(0, Math.trunc(t)), r = this.size;
1832
+ if (e === r)
1525
1833
  return;
1526
- if (t < e)
1527
- for (const i of this.deltas.keys())
1528
- i >= t && this.deltas.delete(i);
1529
- this.size = t, this.rebuildTree();
1530
- const r = this.prefixSum(this.getSize() - 1);
1531
- r.cumulative !== r.total && _.error("Inconsistent Fenwick Tree state");
1834
+ if (e > r)
1835
+ this._growSize(r, e);
1836
+ else {
1837
+ for (const s of this.deltas.keys())
1838
+ s >= e && this.deltas.delete(s);
1839
+ this.size = e, this.rebuildTree();
1840
+ }
1841
+ const n = this.prefixSum(this.getSize() - 1);
1842
+ n.cumulative !== n.total && V.error("Inconsistent Fenwick Tree state");
1843
+ }
1844
+ /**
1845
+ * @private
1846
+ * @method _minCoveredLowBound
1847
+ * @description Computes `min(t - lowestSetBit(t))` over the newly-activated node range `t in (oldSize, newSize]`. Any delta whose 1-based tree index is at or below this bound cannot be covered by any newly-activated node and can be skipped during an incremental grow.
1848
+ * @description 新規有効化ノード範囲 `t in (oldSize, newSize]` にわたる `min(t - lowestSetBit(t))` を算出する。1 始まりの木インデックスがこの下限以下の delta はどの新規ノードにも覆われないため、増分伸長時にスキップできる。
1849
+ * @param {number} oldSize - The previous size (exclusive lower bound of the new node range).
1850
+ * @param {number} newSize - The new size (inclusive upper bound of the new node range).
1851
+ * @returns {number} The minimum left boundary `t - lowestSetBit(t)` of the newly-activated nodes.
1852
+ */
1853
+ static _minCoveredLowBound(t, e) {
1854
+ let r = 1;
1855
+ for (; ; ) {
1856
+ const n = r * 2;
1857
+ if (Math.floor(e / n) * n <= t)
1858
+ break;
1859
+ r = n;
1860
+ }
1861
+ return r * Math.floor(t / r);
1862
+ }
1863
+ /**
1864
+ * @private
1865
+ * @method _propagateDeltaToGrownNodes
1866
+ * @description Propagates a single delta into the tree nodes newly activated by a tail growth, i.e. parent-chain nodes in `(oldSize, newSize]`.
1867
+ * @description 末尾伸長で新規有効化されたノード ((oldSize, newSize] にある親チェーンノード) へ単一 delta を伝播する。
1868
+ * @param {number} index - The 0-based delta index.
1869
+ * @param {number} delta - The delta value to propagate.
1870
+ * @param {number} oldSize - The previous size.
1871
+ * @param {number} newSize - The new (larger) size.
1872
+ */
1873
+ _propagateDeltaToGrownNodes(t, e, r, n) {
1874
+ let s = t + 1;
1875
+ for (; s <= r; ) {
1876
+ const l = fe(s);
1877
+ if (l === 0)
1878
+ break;
1879
+ s += l;
1880
+ }
1881
+ for (; s <= n; ) {
1882
+ this.tree.set(s, (this.tree.get(s) ?? 0) + e);
1883
+ const l = fe(s);
1884
+ if (l === 0)
1885
+ break;
1886
+ s += l;
1887
+ }
1888
+ }
1889
+ /**
1890
+ * @private
1891
+ * @method _growSize
1892
+ * @description Extends the tree to a larger size incrementally, propagating existing deltas into newly-activated higher-order tree nodes only. Candidate deltas are narrowed via `_minCoveredLowBound`, so a typical `+1` tail append costs amortized O(log n) instead of O(D log n) (D = number of materialized deltas).
1893
+ * @description ツリーを末尾方向に増分的に拡張する。既存 delta を新たに有効化された上位ノードにのみ伝播する。候補 delta は `_minCoveredLowBound` で絞り込むため、通常の +1 末尾追記は O(D log n) (D = 具現化済み delta 数) ではなく償却 O(log n) で済む。
1894
+ * @param {number} oldSize - The previous size.
1895
+ * @param {number} newSize - The new (larger) size.
1896
+ */
1897
+ _growSize(t, e) {
1898
+ if (this.size = e, this.deltas.size > 0) {
1899
+ const r = oe._minCoveredLowBound(t, e);
1900
+ if (t - r < this.deltas.size)
1901
+ for (let s = r; s < t; s++) {
1902
+ const l = this.deltas.get(s);
1903
+ l === void 0 || l === 0 || this._propagateDeltaToGrownNodes(s, l, t, e);
1904
+ }
1905
+ else
1906
+ for (const [s, l] of this.deltas.entries())
1907
+ l === 0 || s < r || this._propagateDeltaToGrownNodes(s, l, t, e);
1908
+ }
1909
+ this.total = this._computeTreeTotal();
1532
1910
  }
1533
1911
  /**
1534
1912
  * @method getSize
@@ -1568,17 +1946,20 @@ class cr {
1568
1946
  return this._findIndex(t, e ?? {}, !1);
1569
1947
  }
1570
1948
  }
1571
- const ur = (n, t, e) => {
1572
- const r = Math.max(0, n), i = T(null), l = T({ size: r, valueOrFn: t, options: e });
1573
- i.current === null && (i.current = new cr(r, t, e));
1574
- const c = i.current, d = l.current, f = d.size !== r, h = d.valueOrFn !== t, m = d.options !== e;
1575
- if (h || m) {
1576
- const g = e?.resetOnValueFnChange ?? !0;
1577
- m || h && g ? (e?.debug && _.debug("[useFenwickMapTree] reset", { valueOrFnChanged: h, optionsChanged: m }), c.reset(r, t, e)) : (f && (e?.debug && _.debug("[useFenwickMapTree] resize (with valueFn change)", { from: d.size, to: r }), c.changeSize(r)), e?.debug && _.debug("[useFenwickMapTree] setValueFn (no reset)", { valueOrFnChanged: h }), c.setValueFn(t, { reset: !1 })), l.current = { size: r, valueOrFn: t, options: e };
1578
- } else f && (e?.debug && _.debug("[useFenwickMapTree] resize", { from: d.size, to: r }), d.size === 0 && r > 0 ? c.reset(r, t, e) : c.changeSize(r), l.current = { size: r, valueOrFn: t, options: e });
1579
- return c;
1949
+ const vr = (i, t) => {
1950
+ const e = i?.sampleRange, r = t?.sampleRange;
1951
+ return e === r ? !1 : e && r ? e.from !== r.from || e.to !== r.to : !0;
1952
+ }, Tr = (i, t, e) => {
1953
+ const r = Number.isFinite(i) && i > 0 ? Math.trunc(i) : 0, n = b(null), s = b({ size: r, valueOrFn: t, options: e });
1954
+ n.current === null && (n.current = new oe(r, t, e));
1955
+ const l = n.current, u = s.current, f = u.size !== r, I = u.valueOrFn !== t, v = vr(u.options, e), T = u.size === 0 && r > 0;
1956
+ if (I || v) {
1957
+ const D = e?.resetOnValueFnChange ?? !0;
1958
+ v || I && D || T ? (e?.debug && V.debug("[useFenwickMapTree] reset", { valueOrFnChanged: I, optionsChanged: v }), l.reset(r, t, e)) : (f && (e?.debug && V.debug("[useFenwickMapTree] resize (with valueFn change)", { from: u.size, to: r }), l.changeSize(r)), e?.debug && V.debug("[useFenwickMapTree] setValueFn (no reset)", { valueOrFnChanged: I }), l.setValueFn(t, { reset: !1 })), s.current = { size: r, valueOrFn: t, options: e };
1959
+ } else f && (e?.debug && V.debug("[useFenwickMapTree] resize", { from: u.size, to: r }), T ? l.reset(r, t, e) : l.changeSize(r), s.current = { size: r, valueOrFn: t, options: e });
1960
+ return l;
1580
1961
  };
1581
- class dr {
1962
+ class Sr {
1582
1963
  key;
1583
1964
  value;
1584
1965
  prev = null;
@@ -1587,7 +1968,7 @@ class dr {
1587
1968
  this.key = t, this.value = e;
1588
1969
  }
1589
1970
  }
1590
- class De {
1971
+ class _e {
1591
1972
  head = null;
1592
1973
  tail = null;
1593
1974
  /**
@@ -1628,689 +2009,818 @@ class De {
1628
2009
  this.remove(t), this.addToTail(t);
1629
2010
  }
1630
2011
  }
1631
- function fr(n) {
1632
- const t = T(/* @__PURE__ */ new Map()), e = T(new De());
1633
- Y(() => {
1634
- for (; t.current.size > n; ) {
1635
- const m = e.current.removeHead();
1636
- if (m)
1637
- t.current.delete(m.key);
1638
- else
1639
- break;
2012
+ function Mr(i) {
2013
+ const t = b(/* @__PURE__ */ new Map()), e = b(new _e()), r = Math.floor(i), n = b(r);
2014
+ X(() => {
2015
+ if (n.current = r, Number.isNaN(r) || r < 0) {
2016
+ V.warn(`useLruCache: invalid capacity ${i}; the cache will not store any entries.`), t.current.clear(), e.current = new _e();
2017
+ return;
1640
2018
  }
1641
- }, [n]);
1642
- const r = P((m) => {
1643
- const g = t.current.get(m);
1644
- if (g)
1645
- return e.current.moveToTail(g), g.value;
1646
- }, []), i = P(
1647
- (m, g) => {
1648
- if (n <= 0)
1649
- return;
1650
- let N = t.current.get(m);
1651
- if (N)
1652
- N.value = g, e.current.moveToTail(N);
1653
- else {
1654
- if (t.current.size >= n) {
1655
- const x = e.current.removeHead();
1656
- x && t.current.delete(x.key);
1657
- }
1658
- N = new dr(m, g), t.current.set(m, N), e.current.addToTail(N);
2019
+ if (Number.isFinite(r))
2020
+ for (; t.current.size > r; ) {
2021
+ const v = e.current.removeHead();
2022
+ if (v)
2023
+ t.current.delete(v.key);
2024
+ else
2025
+ break;
1659
2026
  }
1660
- },
1661
- [n]
1662
- ), l = P((m) => t.current.has(m), []), c = P((m) => {
1663
- const g = t.current.get(m);
1664
- g && (e.current.remove(g), t.current.delete(m));
1665
- }, []), d = P(() => {
1666
- t.current.clear(), e.current = new De();
1667
- }, []), [f, h] = Bt(() => ({ get: r, set: i, has: l, remove: c, clear: d }));
1668
- return Y(() => h({ get: r, set: i, has: l, remove: c, clear: d }), [r, i, l, c, d]), f;
2027
+ }, [i, r]);
2028
+ const s = y((v) => {
2029
+ const T = t.current.get(v);
2030
+ if (T)
2031
+ return e.current.moveToTail(T), T.value;
2032
+ }, []), l = y((v, T) => {
2033
+ const D = n.current;
2034
+ if (Number.isNaN(D) || D <= 0)
2035
+ return;
2036
+ let p = t.current.get(v);
2037
+ if (p)
2038
+ p.value = T, e.current.moveToTail(p);
2039
+ else {
2040
+ if (t.current.size >= D) {
2041
+ const z = e.current.removeHead();
2042
+ z && t.current.delete(z.key);
2043
+ }
2044
+ p = new Sr(v, T), t.current.set(v, p), e.current.addToTail(p);
2045
+ }
2046
+ }, []), u = y((v) => t.current.has(v), []), f = y((v) => {
2047
+ const T = t.current.get(v);
2048
+ T && (e.current.remove(T), t.current.delete(v));
2049
+ }, []), I = y(() => {
2050
+ t.current.clear(), e.current = new _e();
2051
+ }, []);
2052
+ return yt(() => ({ get: s, set: l, has: u, remove: f, clear: I }), [s, l, u, f, I]);
1669
2053
  }
1670
- const mr = 1e4, Pr = () => {
1671
- const { get: n, set: t, has: e, clear: r } = fr(mr);
1672
- return { get: n, set: t, has: e, clear: r };
1673
- }, it = (n, t) => t <= 0 ? 0 : xt(n, 0, t - 1), Ne = (n) => ({
1674
- top: Math.max(0, n?.top ?? 0),
1675
- bottom: Math.max(0, n?.bottom ?? 0)
1676
- }), jt = (n, t) => n <= t ? 0 : n - t, se = (n, t) => n <= 0 ? t : n + t, Se = (n) => {
1677
- if (!Number.isFinite(n)) return 0n;
1678
- const t = Math.trunc(n);
2054
+ const Pr = 1e4, Lr = () => {
2055
+ const { get: i, set: t, has: e, clear: r } = Mr(Pr);
2056
+ return yt(() => ({ get: i, set: t, has: e, clear: r }), [i, t, e, r]);
2057
+ }, dt = (i, t) => t <= 0 ? 0 : mt(i, 0, t - 1), Xe = (i) => ({
2058
+ top: Math.max(0, i?.top ?? 0),
2059
+ bottom: Math.max(0, i?.bottom ?? 0)
2060
+ }), ee = (i, t) => i <= t ? 0 : i - t, me = (i, t) => i <= 0 ? t : i + t, Ee = 1e3, $e = 2e3, yr = 1048576, Se = (i) => {
2061
+ if (!Number.isFinite(i)) return 0n;
2062
+ const t = Math.trunc(i);
1679
2063
  return t <= 0 ? 0n : BigInt(t);
1680
- }, pr = (n, t, e, r, i, l, c, d) => {
2064
+ }, wr = (i, t, e, r, n, s, l, u) => {
1681
2065
  const f = Se(r);
1682
2066
  if (f === 0n)
1683
2067
  return { renderingStartIndex: 0, renderingEndIndex: 0, visibleStartIndex: 0, visibleEndIndex: 0 };
1684
- const h = (L) => L < 0n ? 0n : L >= f ? f - 1n : L, m = { materializeOption: { materialize: !1 } }, { index: g, cumulative: N } = l.findIndexAtOrAfter(n, m);
1685
- let x;
1686
- g === -1 ? x = f - 1n : (N === n ? x = Se(g + 1) : x = Se(g), x >= f && (x = f - 1n)), n <= 0 && (x = 0n), d && n >= c && (x = f - 1n);
1687
- const k = (L) => {
1688
- let tt = 0, et = L, E = L, ut = 0n;
1689
- for (; et < f && tt < t; ) {
1690
- const Pt = Number(et), ht = i(Pt);
1691
- if (tt += ht, E = et, et += 1n, ut += 1n, !Number.isFinite(ht) || ht <= 0)
2068
+ const I = (L) => L < 0n ? 0n : L >= f ? f - 1n : L, v = { materializeOption: { materialize: !1 } }, { index: T, cumulative: D } = s.findIndexAtOrAfter(i, v);
2069
+ let p;
2070
+ T === -1 ? p = f - 1n : (D === i ? p = Se(T + 1) : p = Se(T), p >= f && (p = f - 1n)), i <= 0 && (p = 0n), u && i >= l && (p = f - 1n);
2071
+ const z = (L) => {
2072
+ const F = Number(L);
2073
+ if (!Number.isSafeInteger(F))
2074
+ return null;
2075
+ const { cumulative: h } = s.prefixSum(F, { materializeOption: { materialize: !1 } });
2076
+ if (!Number.isFinite(h))
2077
+ return null;
2078
+ const { index: $ } = s.findIndexAtOrAfter(h + 0.5, { materializeOption: { materialize: !1 } });
2079
+ if ($ === -1)
2080
+ return null;
2081
+ const q = Se($);
2082
+ return q > L ? q : null;
2083
+ }, rt = (L) => {
2084
+ let F = 0, h = L, $ = L, q = 0n, H = 0;
2085
+ for (; h < f && F < t; ) {
2086
+ const O = Number(h), K = n(O);
2087
+ if (F += K, $ = h, h += 1n, q += 1n, !Number.isFinite(K) || K < 0)
1692
2088
  break;
2089
+ if (K === 0) {
2090
+ if (H += 1, H > Ee) {
2091
+ const S = z($);
2092
+ if (S !== null && S > h)
2093
+ h = S, H = 0;
2094
+ else if (S !== null && S === h && n(Number(h)) > 0)
2095
+ H = 0;
2096
+ else
2097
+ break;
2098
+ }
2099
+ } else
2100
+ H = 0;
1693
2101
  }
1694
- return ut === 0n && (E = L), { height: tt, end: E };
2102
+ return q === 0n && ($ = L), { height: F, end: $ };
1695
2103
  };
1696
- let { height: B, end: z } = k(x);
1697
- if (B < t && x > 0n) {
1698
- let L = x, tt = B;
1699
- for (; L > 0n && tt < t; ) {
2104
+ let { height: W, end: ot } = rt(p);
2105
+ if (W < t && p > 0n) {
2106
+ let L = p, F = W, h = 0;
2107
+ for (; L > 0n && F < t; ) {
1700
2108
  L -= 1n;
1701
- const E = Number(L), ut = i(E);
1702
- if (tt += ut, !Number.isFinite(ut) || ut <= 0)
2109
+ const q = Number(L), H = n(q);
2110
+ if (F += H, !Number.isFinite(H) || H < 0)
1703
2111
  break;
2112
+ if (H === 0) {
2113
+ if (h += 1, h > Ee) {
2114
+ const O = Number(L);
2115
+ if (!Number.isSafeInteger(O))
2116
+ break;
2117
+ const { cumulative: K } = s.prefixSum(O, { materializeOption: { materialize: !1 } });
2118
+ if (!Number.isFinite(K))
2119
+ break;
2120
+ const { index: S } = s.findIndexAtOrAfter(K - 0.5, { materializeOption: { materialize: !1 } }), U = S === -1 ? -1n : Se(S);
2121
+ if (U >= 0n && U < L)
2122
+ L = U + 1n, h = 0;
2123
+ else if (U === L && L >= 1n && n(Number(L - 1n)) > 0)
2124
+ h = 0;
2125
+ else
2126
+ break;
2127
+ }
2128
+ } else
2129
+ h = 0;
1704
2130
  }
1705
- x = h(L);
1706
- const et = k(x);
1707
- B = et.height, z = et.end;
2131
+ p = I(L);
2132
+ const $ = rt(p);
2133
+ W = $.height, ot = $.end;
1708
2134
  }
1709
- const Q = h(x), pt = h(z), ct = h(Q - BigInt(Math.max(0, e))), st = h(pt + BigInt(Math.max(0, e)));
2135
+ const nt = I(p), ft = I(ot), St = I(nt - BigInt(Math.max(0, e))), wt = I(ft + BigInt(Math.max(0, e)));
1710
2136
  return {
1711
- renderingStartIndex: it(Number(ct), r),
1712
- renderingEndIndex: it(Number(st), r),
1713
- visibleStartIndex: it(Number(Q), r),
1714
- visibleEndIndex: it(Number(pt), r)
2137
+ renderingStartIndex: dt(Number(St), r),
2138
+ renderingEndIndex: dt(Number(wt), r),
2139
+ visibleStartIndex: dt(Number(nt), r),
2140
+ visibleEndIndex: dt(Number(ft), r)
1715
2141
  };
1716
- }, hr = (n, t, e, r, i, l, c) => {
2142
+ }, Rr = (i, t, e, r, n, s, l) => {
1717
2143
  if (r === 0)
1718
2144
  return { renderingStartIndex: 0, renderingEndIndex: 0, visibleStartIndex: 0, visibleEndIndex: 0 };
1719
- const d = Number.isFinite(c), f = d ? Math.min(Math.max(0, n), c) : Math.max(0, n);
2145
+ const u = Number.isFinite(l), f = u ? Math.min(Math.max(0, i), l) : Math.max(0, i);
1720
2146
  if (r >= Number.MAX_SAFE_INTEGER)
1721
- return pr(f, t, e, r, i, l, c, d);
1722
- const { index: h, cumulative: m, currentValue: g } = l.findIndexAtOrAfter(f, { materializeOption: { materialize: !1 } }), N = h === -1 ? t <= 0 || (m ?? 0) < f + (g ?? 0) ? r - 1 : 0 : h;
1723
- let x = it(N, r), k = 0;
1724
- if (h !== -1 && m === f)
1725
- x = it(h + 1, r), k = 0;
1726
- else if (x === h && m !== void 0 && g !== void 0)
1727
- k = m - g - f;
2147
+ return wr(f, t, e, r, n, s, l, u);
2148
+ const { index: I, cumulative: v, currentValue: T } = s.findIndexAtOrAfter(f, { materializeOption: { materialize: !1 } }), D = I === -1 ? t <= 0 || (v ?? 0) < f + (T ?? 0) ? r - 1 : 0 : I;
2149
+ let p = dt(D, r), z = 0;
2150
+ if (I !== -1 && v === f)
2151
+ p = dt(I + 1, r), z = 0;
2152
+ else if (p === I && v !== void 0 && T !== void 0)
2153
+ z = v - T - f;
1728
2154
  else {
1729
- const { cumulative: st, currentValue: L } = l.prefixSum(x, { materializeOption: { materialize: !1 } });
1730
- k = (st ?? 0) - (L ?? 0) - f;
2155
+ const { cumulative: L, currentValue: F } = s.prefixSum(p, { materializeOption: { materialize: !1 } });
2156
+ z = (L ?? 0) - (F ?? 0) - f;
1731
2157
  }
1732
- const B = k;
1733
- let z = x;
1734
- for (; z < r && k < t; )
1735
- k += i(z), z++;
1736
- if (k < t && x > 0) {
1737
- let st = k + Math.abs(Math.min(0, B)), L = x - 1;
1738
- for (; L >= 0 && st < t; )
1739
- st += i(L), L--;
1740
- for (x = it(L + 1, r), k = 0, z = x; z < r && k < t; )
1741
- k += i(z), z++;
2158
+ const rt = z, W = (L, F) => {
2159
+ let h = L, $ = F, q = 0;
2160
+ for (; h < r && $ < t; ) {
2161
+ const H = n(h);
2162
+ if ($ += H, h++, !Number.isFinite(H) || H < 0)
2163
+ break;
2164
+ if (H === 0) {
2165
+ if (q++, q > Ee) {
2166
+ const { cumulative: O } = s.prefixSum(h - 1, { materializeOption: { materialize: !1 } }), { index: K } = Number.isFinite(O) ? s.findIndexAtOrAfter(O + 0.5, { materializeOption: { materialize: !1 } }) : { index: -1 };
2167
+ if (K > h)
2168
+ h = K, q = 0;
2169
+ else if (K === h && n(h) > 0)
2170
+ q = 0;
2171
+ else
2172
+ break;
2173
+ }
2174
+ } else
2175
+ q = 0;
2176
+ }
2177
+ return { cursor: h, height: $ };
2178
+ }, ot = W(p, z);
2179
+ let nt = ot.cursor;
2180
+ if (z = ot.height, z < t && p > 0) {
2181
+ let L = z + Math.abs(Math.min(0, rt)), F = p - 1, h = 0;
2182
+ for (; F >= 0 && L < t; ) {
2183
+ const q = n(F);
2184
+ if (L += q, !Number.isFinite(q) || q < 0) {
2185
+ F--;
2186
+ break;
2187
+ }
2188
+ if (q === 0) {
2189
+ if (h++, h > Ee) {
2190
+ const { cumulative: H } = s.prefixSum(F, { materializeOption: { materialize: !1 } }), { index: O } = Number.isFinite(H) ? s.findIndexAtOrAfter(H - 0.5, { materializeOption: { materialize: !1 } }) : { index: -1 };
2191
+ if (O !== -1 && O < F) {
2192
+ F = O, h = 0;
2193
+ continue;
2194
+ }
2195
+ if (O === F && F >= 1 && n(F - 1) > 0)
2196
+ h = 0;
2197
+ else {
2198
+ F--;
2199
+ break;
2200
+ }
2201
+ }
2202
+ } else
2203
+ h = 0;
2204
+ F--;
2205
+ }
2206
+ p = dt(F + 1, r);
2207
+ const $ = W(p, 0);
2208
+ nt = $.cursor, z = $.height;
1742
2209
  }
1743
- const Q = it(x - e, r), pt = it(Math.max(z - 1, x), r), ct = it(pt + e, r);
1744
- return { renderingStartIndex: Q, renderingEndIndex: ct, visibleStartIndex: x, visibleEndIndex: pt };
1745
- }, ke = (n, t, e) => {
1746
- const r = Math.max(0, t ?? 0), i = T({ last: 0, id: null, arg: null }).current;
1747
- return Y(
2210
+ const ft = dt(p - e, r), St = dt(Math.max(nt - 1, p), r), wt = dt(St + e, r);
2211
+ return { renderingStartIndex: ft, renderingEndIndex: wt, visibleStartIndex: p, visibleEndIndex: St };
2212
+ }, Ue = (i, t, e) => {
2213
+ const r = Math.max(0, t ?? 0), n = b({ last: 0, id: null, arg: null }).current;
2214
+ return X(
1748
2215
  () => () => {
1749
- i.id !== null && (cancelAnimationFrame(i.id), i.id = null);
2216
+ n.id !== null && (cancelAnimationFrame(n.id), n.id = null);
1750
2217
  },
1751
- [i]
1752
- ), P(
1753
- (l) => {
1754
- if (i.arg = l, i.id !== null) return;
1755
- const c = (d) => {
1756
- if (i.id = null, i.arg === null) return;
1757
- const f = d - i.last;
1758
- if (r === 0 || i.last === 0 || f >= r) {
1759
- if (n.current)
2218
+ [n]
2219
+ ), y(
2220
+ (s) => {
2221
+ if (n.arg = s, n.id !== null) return;
2222
+ const l = (u) => {
2223
+ if (n.id = null, n.arg === null) return;
2224
+ const f = u - n.last;
2225
+ if (r === 0 || n.last === 0 || f >= r) {
2226
+ if (i.current)
1760
2227
  try {
1761
- e(n.current, i.arg);
1762
- } catch (h) {
1763
- console.error("[useThrottledInvoker] Error invoking callback", h);
2228
+ e(i.current, n.arg);
2229
+ } catch (I) {
2230
+ console.error("[useThrottledInvoker] Error invoking callback", I);
1764
2231
  }
1765
- i.arg = null, i.last = d;
2232
+ n.arg = null, n.last = u;
1766
2233
  }
1767
- i.arg !== null && (i.id = requestAnimationFrame(c));
2234
+ n.arg !== null && (n.id = requestAnimationFrame(l));
1768
2235
  };
1769
- i.id = requestAnimationFrame(c);
2236
+ n.id = requestAnimationFrame(l);
1770
2237
  },
1771
- [r, e, n, i]
2238
+ [r, e, i, n]
1772
2239
  );
1773
- }, gr = He.memo(({ index: n, top: t, height: e, item: r, children: i, clipItemHeight: l, enableKeyboardNavigation: c, onKeyDown: d, onFocus: f, registerItemRef: h }) => {
1774
- const m = P((k) => h(n, k), [n, h]), g = P((k) => d(k, n), [n, d]), N = P(() => f(n), [n, f]), x = P((k) => {
1775
- k.currentTarget.focus({ preventScroll: !0 });
2240
+ }, Cr = Qe.memo(({ index: i, top: t, height: e, item: r, children: n, clipItemHeight: s, enableKeyboardNavigation: l, onKeyDown: u, onFocus: f, registerItemRef: I }) => {
2241
+ const v = y((z) => I(i, z), [i, I]), T = y((z) => u(z, i), [i, u]), D = y(() => f(i), [i, f]), p = y((z) => {
2242
+ z.currentTarget.focus({ preventScroll: !0 });
1776
2243
  }, []);
1777
- return /* @__PURE__ */ $(
2244
+ return /* @__PURE__ */ et(
1778
2245
  "div",
1779
2246
  {
1780
- ref: m,
1781
- "data-index": n,
2247
+ ref: v,
2248
+ "data-index": i,
1782
2249
  "data-virtualscroll-item": "true",
1783
2250
  className: "aqvs-item-container",
1784
2251
  style: {
1785
2252
  top: t,
1786
2253
  height: e,
1787
- overflow: l ? "hidden" : void 0
2254
+ overflow: s ? "hidden" : void 0
1788
2255
  },
1789
- tabIndex: c ? -1 : void 0,
1790
- onPointerDown: c ? x : void 0,
1791
- onKeyDownCapture: c ? g : void 0,
1792
- onFocusCapture: c ? N : void 0,
1793
- children: i(r, n)
2256
+ tabIndex: l ? -1 : void 0,
2257
+ onPointerDown: l ? p : void 0,
2258
+ onKeyDownCapture: l ? T : void 0,
2259
+ onFocusCapture: l ? D : void 0,
2260
+ children: n(r, i)
1794
2261
  }
1795
2262
  );
1796
- }), xr = ({
1797
- itemCount: n,
2263
+ }), Er = ({
2264
+ itemCount: i,
1798
2265
  getItem: t,
1799
2266
  getItemKey: e,
1800
2267
  getItemHeight: r,
1801
- viewportSize: i,
1802
- overscanCount: l = 15,
1803
- className: c,
1804
- onScroll: d,
2268
+ viewportSize: n,
2269
+ overscanCount: s = 15,
2270
+ className: l,
2271
+ onScroll: u,
1805
2272
  onRangeChange: f,
1806
- children: h,
1807
- background: m,
1808
- initialScrollIndex: g,
1809
- initialScrollOffset: N,
1810
- callbackThrottleMs: x = 5,
1811
- contentInsets: k,
1812
- onItemFocus: B,
1813
- scrollBarOptions: z,
1814
- behaviorOptions: Q,
1815
- onWheelHorizontal: pt
1816
- }, ct) => {
1817
- const { width: st, enableThumbDrag: L, enableTrackClick: tt, enableArrowButtons: et, enableScrollToTopBottomButtons: E, renderThumbOverlay: ut, tapScrollCircleOptions: Pt } = z ?? {}, { enablePointerDrag: ht, enableKeyboardNavigation: I = !0, wheelSpeedMultiplier: W, inertiaOptions: St, clipItemHeight: Dt = !1, resetOnGetItemHeightChange: ot = !1 } = Q ?? {}, A = T(null), G = T({
2273
+ children: I,
2274
+ background: v,
2275
+ initialScrollIndex: T,
2276
+ initialScrollOffset: D,
2277
+ callbackThrottleMs: p = 5,
2278
+ contentInsets: z,
2279
+ onItemFocus: rt,
2280
+ scrollBarOptions: W,
2281
+ behaviorOptions: ot,
2282
+ onWheelHorizontal: nt
2283
+ }, ft) => {
2284
+ const { width: St, enableThumbDrag: wt, enableTrackClick: L, enableArrowButtons: F, enableScrollToTopBottomButtons: h, renderThumbOverlay: $, tapScrollCircleOptions: q } = W ?? {}, { enablePointerDrag: H, enableKeyboardNavigation: O = !0, wheelSpeedMultiplier: K, inertiaOptions: S, clipItemHeight: U = !1, resetOnGetItemHeightChange: j = !1 } = ot ?? {}, k = b(null), G = b({
1818
2285
  renderingStartIndex: 0,
1819
2286
  renderingEndIndex: 0,
1820
2287
  visibleStartIndex: 0,
1821
2288
  visibleEndIndex: 0,
1822
2289
  scrollPosition: 0,
1823
2290
  totalHeight: 0
1824
- }), dt = T(null), It = T(!1);
1825
- Y(() => {
1826
- ot && (dt.current = null);
1827
- }, [ot]);
1828
- const v = At(() => Ne(k), [k]), kt = At(
2291
+ }), st = b(null), Mt = b(!1);
2292
+ X(() => {
2293
+ j && (st.current = null);
2294
+ }, [j, r]);
2295
+ const R = yt(() => Xe(z), [z]), [Dt] = Ut(() => {
2296
+ const c = typeof T == "number" && Number.isFinite(T) ? Math.max(0, Math.trunc(T)) : 0;
2297
+ return { from: Math.max(0, c - 50), to: c + 50 };
2298
+ }), Vt = yt(
1829
2299
  // 目的: Fenwick Tree のオプション設定
1830
- // 依存関係: resetOnGetItemHeightChange
2300
+ // 依存関係: resetOnGetItemHeightChange, initialSampleRange (マウント時固定)
2301
+ // itemCount には依存させない (依存させると追記のたびに options 参照が変わり、計測済み高さが全消去される)。
2302
+ // この useMemo により sampleRange を毎レンダー新規生成しない = 参照同一性由来の破壊的 reset を防ぐ。
1831
2303
  () => ({
1832
- sampleRange: { from: 0, to: 100 },
1833
- resetOnValueFnChange: ot,
2304
+ sampleRange: Dt,
2305
+ resetOnValueFnChange: j,
1834
2306
  materialize: !0
1835
2307
  }),
1836
- [ot]
1837
- ), S = ur(n, r, kt), [rt] = Bt(() => {
1838
- let s = v.top, a = 0;
1839
- if (typeof g == "number") {
1840
- const u = xt(g, 0, n - 1), R = xt(u - l * 2, 0, n - 1), D = xt(u + l * 2, 0, n - 1), C = g > 0 ? { materializeOption: { materialize: !0, ranges: [{ from: R, to: D }] } } : void 0, { cumulative: X, total: U, currentValue: F } = S.prefixSum(g, C), O = Math.max(X - F, 0);
1841
- s = se(O, v.top), a = U ?? S.getTotal();
1842
- } else typeof N == "number" && (s = se(Math.max(N, 0), v.top)), a = S.getTotal();
1843
- return { position: s, total: a };
1844
- }), [Vt, Gt] = Bt(rt.position), [Mt, b] = Bt(rt.total), M = T(rt.position), q = T(v.top), ft = T(d ?? void 0), j = T(f ?? void 0), mt = T(/* @__PURE__ */ new Map()), Z = T(null), J = T(null), [bt, qt] = Bt(null), [yt, Tt] = Bt(!1), Ct = T(null), _t = T(!1), at = T(0), p = T(!1), y = T(n);
1845
- y.current !== n && (y.current = n, p.current = !0), Y(() => {
1846
- ft.current = d ?? void 0, j.current = f ?? void 0;
1847
- }, [f, d]);
1848
- const nt = P(
1849
- (s) => {
1850
- if (I && s && typeof s.focus == "function")
2308
+ [j, Dt]
2309
+ ), x = Tr(i, r, Vt), [Rt] = Ut(() => {
2310
+ let o = R.top, c = 0;
2311
+ if (typeof T == "number") {
2312
+ const d = mt(T, 0, i - 1), P = mt(d - s * 2, 0, i - 1), N = mt(d + s * 2, 0, i - 1), _ = T > 0 ? { materializeOption: { materialize: !0, ranges: [{ from: P, to: N }] } } : void 0, { cumulative: A, total: B, currentValue: gt } = x.prefixSum(T, _), tt = Math.max(A - gt, 0);
2313
+ o = me(tt, R.top), c = B ?? x.getTotal();
2314
+ } else typeof D == "number" && (o = me(Math.max(D, 0), R.top)), c = x.getTotal();
2315
+ return { position: o, total: c };
2316
+ }), [At, qt] = Ut(Rt.position), [M, Y] = Ut(Rt.total), C = b(Rt.position), ct = b(R.top), at = b(u ?? void 0), pt = b(f ?? void 0), ht = b(/* @__PURE__ */ new Map()), J = b(null), Ct = b(null), [ut, Kt] = Ut(null), [Lt, xt] = Ut(!1), _t = b(null), Ot = b(!1), It = b(0), Et = b(!1), m = b(!1), E = b(i);
2317
+ E.current !== i && (E.current = i, m.current = !0), X(() => {
2318
+ at.current = u ?? void 0, pt.current = f ?? void 0;
2319
+ }, [f, u]);
2320
+ const lt = y(
2321
+ (o) => {
2322
+ if (O && o && typeof o.focus == "function")
1851
2323
  try {
1852
- s.focus({ preventScroll: !0 });
2324
+ o.focus({ preventScroll: !0 });
1853
2325
  } catch {
1854
- s.focus();
2326
+ o.focus();
1855
2327
  }
1856
2328
  },
1857
- [I]
1858
- ), Lt = P((s, { position: a, totalHeight: u }) => {
1859
- s(a, u);
1860
- }, []), H = ke(ft, x, Lt), Zt = P((s, a) => {
1861
- s(a);
1862
- }, []), Ft = ke(j, x, Zt);
1863
- Y(() => (It.current = !0, () => {
1864
- It.current = !1;
1865
- }), []), Y(() => {
1866
- I || (mt.current.clear(), Z.current = null, J.current = null);
1867
- }, [I]);
1868
- const wt = P(
1869
- (s, a) => {
1870
- if (!a) {
1871
- mt.current.delete(s);
2329
+ [O]
2330
+ ), zt = y((o, { position: c, totalHeight: d }) => {
2331
+ o(c, d);
2332
+ }, []), Z = Ue(at, p, zt), re = y((o, c) => {
2333
+ o(c);
2334
+ }, []), Ht = Ue(pt, p, re), Nt = b(R.top);
2335
+ Nt.current = R.top;
2336
+ const Wt = b(Z);
2337
+ Wt.current = Z, X(() => (Mt.current = !1, () => {
2338
+ Mt.current = !0, _t.current && (clearTimeout(_t.current), _t.current = null);
2339
+ }), []), X(() => {
2340
+ O || (ht.current.clear(), J.current = null, Ct.current = null);
2341
+ }, [O]);
2342
+ const jt = y(
2343
+ (o, c) => {
2344
+ if (!c) {
2345
+ ht.current.delete(o);
1872
2346
  return;
1873
2347
  }
1874
- I && (mt.current.set(s, a), Z.current === s && (Z.current = null, J.current = s, nt(a)));
2348
+ O && (ht.current.set(o, c), J.current === o && (J.current = null, Ct.current = o, lt(c)));
1875
2349
  },
1876
- [I, nt]
1877
- ), Ht = 0.01, gt = T({
2350
+ [O, lt]
2351
+ ), Ft = 0.01, Pt = b({
1878
2352
  rafId: null,
1879
2353
  loopActive: !1,
1880
2354
  idleFrames: 0,
1881
- lastRenderedPosition: rt.position
1882
- }), Rt = P(() => {
1883
- const s = gt.current;
1884
- s.rafId !== null && typeof cancelAnimationFrame == "function" && cancelAnimationFrame(s.rafId), s.rafId = null, s.loopActive = !1, s.idleFrames = 0;
2355
+ lastRenderedPosition: Rt.position
2356
+ }), Gt = y(() => {
2357
+ const o = Pt.current;
2358
+ o.rafId !== null && typeof cancelAnimationFrame == "function" && cancelAnimationFrame(o.rafId), o.rafId = null, o.loopActive = !1, o.idleFrames = 0;
1885
2359
  }, []);
1886
- Y(
2360
+ X(
1887
2361
  () => () => {
1888
- Rt();
2362
+ Gt();
1889
2363
  },
1890
- [Rt]
2364
+ [Gt]
1891
2365
  );
1892
- const Jt = P(() => {
1893
- const s = gt.current;
1894
- s.rafId = null;
1895
- const a = M.current, u = jt(a, v.top), R = S.getTotal();
1896
- if (Gt((C) => Math.abs(C - a) < Ht ? C : a), H({ position: u, totalHeight: R }), Math.abs(s.lastRenderedPosition - a) >= Ht ? (s.lastRenderedPosition = a, s.idleFrames = 0) : s.idleFrames += 1, s.idleFrames >= 2) {
1897
- Rt();
2366
+ const he = b(() => {
2367
+ }), ge = y(() => {
2368
+ const o = Pt.current;
2369
+ o.rafId = null;
2370
+ const c = C.current, d = ee(c, Nt.current), P = x.getTotal();
2371
+ if (qt((_) => Math.abs(_ - c) < Ft ? _ : c), Math.abs(o.lastRenderedPosition - c) >= Ft ? (Wt.current({ position: d, totalHeight: P }), o.lastRenderedPosition = c, o.idleFrames = 0) : o.idleFrames += 1, o.idleFrames >= 2) {
2372
+ Gt();
1898
2373
  return;
1899
2374
  }
1900
2375
  if (typeof requestAnimationFrame == "function") {
1901
- s.rafId = requestAnimationFrame(Jt);
2376
+ o.rafId = requestAnimationFrame((_) => he.current(_));
1902
2377
  return;
1903
2378
  }
1904
- s.loopActive = !1;
1905
- }, [S, v.top, H, Rt]), ae = P(() => {
1906
- const s = gt.current;
1907
- if (s.idleFrames = 0, !s.loopActive) {
1908
- if (s.loopActive = !0, typeof requestAnimationFrame == "function") {
1909
- s.rafId = requestAnimationFrame(Jt);
2379
+ o.loopActive = !1;
2380
+ }, [x, Gt]);
2381
+ he.current = ge;
2382
+ const be = y(() => {
2383
+ const o = Pt.current;
2384
+ if (o.idleFrames = 0, !o.loopActive) {
2385
+ if (o.loopActive = !0, typeof requestAnimationFrame == "function") {
2386
+ o.rafId = requestAnimationFrame(ge);
1910
2387
  return;
1911
2388
  }
1912
- s.loopActive = !1;
2389
+ o.loopActive = !1;
1913
2390
  }
1914
- }, [Jt]), lt = P(
1915
- (s, a) => {
1916
- const u = a?.immediate ?? !1, R = jt(s, v.top);
1917
- if (M.current = s, u) {
1918
- gt.current.lastRenderedPosition = s, gt.current.idleFrames = 0, Gt(s), H({ position: R, totalHeight: S.getTotal() });
2391
+ }, [ge]), it = y(
2392
+ (o, c) => {
2393
+ const d = c?.immediate ?? !1, P = ee(o, R.top);
2394
+ if (C.current = o, d) {
2395
+ Pt.current.lastRenderedPosition = o, Pt.current.idleFrames = 0, qt(o), Z({ position: P, totalHeight: x.getTotal() });
1919
2396
  return;
1920
2397
  }
1921
- ae();
2398
+ be();
1922
2399
  },
1923
- [ae, S, v.top, H]
1924
- ), le = T(!1);
1925
- Y(() => {
1926
- if (!le.current)
1927
- if (le.current = !0, typeof N == "number") {
1928
- const s = se(Math.max(N, 0), v.top), a = Math.abs(s - M.current) > 0.5;
1929
- lt(s, { immediate: !0 }), a && A.current?.scrollTo(s);
2400
+ [be, x, R.top, Z]
2401
+ ), Zt = y((o) => {
2402
+ const c = k.current;
2403
+ if (!c)
2404
+ return o;
2405
+ const d = c.getScrollPosition();
2406
+ It.current += 1;
2407
+ const P = c.scrollTo(o);
2408
+ return P === d && (It.current = Math.max(0, It.current - 1)), Math.abs(P - o) > 0.5 && (Et.current = !0), P;
2409
+ }, []), ne = b(!1);
2410
+ X(() => {
2411
+ if (!ne.current)
2412
+ if (ne.current = !0, typeof D == "number") {
2413
+ const o = me(Math.max(D, 0), R.top), c = Math.abs(o - C.current) > 0.5;
2414
+ it(o, { immediate: !0 }), c && k.current?.scrollTo(o);
1930
2415
  } else
1931
- lt(M.current, { immediate: !0 });
1932
- }, [N, v.top, lt]), Y(() => {
1933
- const s = S.getTotal();
1934
- Mt !== s && b(s);
1935
- }, [S, Mt, n]), Y(() => {
1936
- if (dt.current !== null) {
1937
- const { index: s, align: a, offset: u } = dt.current, R = it(s, n), { cumulative: D, currentValue: C } = S.prefixSum(R, { materializeOption: { materialize: !1 } });
1938
- if (D !== void 0 && C !== void 0) {
1939
- const X = Math.max(D - C, 0);
1940
- let U = X;
1941
- a === "bottom" ? U = D - i : a === "center" && (U = X + C / 2 - i / 2), u && (U -= u), U = Math.max(0, U);
1942
- const F = Math.max(0, Mt + v.top + v.bottom - i), O = Math.min(se(U, v.top), F);
1943
- Math.abs(O - M.current) > 1 && (_.debug("[VirtualScroll] Drift correction", {
1944
- from: M.current,
1945
- to: O,
1946
- targetIndex: R
1947
- }), at.current === 0 && (at.current += 1), A.current?.scrollTo(O), lt(O, { immediate: !0 }));
2416
+ it(C.current, { immediate: !0 });
2417
+ }, [D, R.top, it]), X(() => {
2418
+ const o = x.getTotal();
2419
+ if (M !== o) {
2420
+ Y(o);
2421
+ return;
2422
+ }
2423
+ if (Et.current) {
2424
+ Et.current = !1;
2425
+ const c = k.current;
2426
+ if (c && Math.abs(c.getScrollPosition() - C.current) > 0.5) {
2427
+ const d = Zt(C.current);
2428
+ Et.current = !1, it(d, { immediate: !0 });
2429
+ }
2430
+ }
2431
+ }, [x, M, i, Zt, it]), X(() => {
2432
+ if (st.current !== null) {
2433
+ const { index: o, align: c, offset: d } = st.current, P = dt(o, i), { cumulative: N, currentValue: _ } = x.prefixSum(P, { materializeOption: { materialize: !1 } });
2434
+ if (N !== void 0 && _ !== void 0) {
2435
+ const A = Math.max(N - _, 0);
2436
+ let B = A;
2437
+ c === "bottom" ? B = N - n : c === "center" && (B = A + _ / 2 - n / 2), d && (B -= d), B = Math.max(0, B);
2438
+ const gt = Math.max(0, M + R.top + R.bottom - n), tt = Math.min(me(B, R.top), gt);
2439
+ Math.abs(tt - C.current) > 1 && (V.debug("[VirtualScroll] Drift correction", {
2440
+ from: C.current,
2441
+ to: tt,
2442
+ targetIndex: P
2443
+ }), It.current === 0 && (It.current += 1), k.current?.scrollTo(tt), it(tt, { immediate: !0 }));
1948
2444
  }
1949
2445
  }
1950
- p.current = !1;
1951
- }, [Mt, S, n, v.top, lt, i, v.bottom]), Y(() => {
1952
- const s = q.current;
1953
- if (s === v.top) return;
1954
- const a = jt(M.current, s), u = se(a, v.top);
1955
- q.current = v.top, M.current = u, A.current?.scrollTo(u), lt(u, { immediate: !0 });
1956
- }, [v.top, lt]);
1957
- const ce = P(
1958
- (s, a) => {
1959
- const u = it(s, n), R = S.get(u), D = a - R, C = S.update(u, a);
1960
- C !== void 0 && b(C), _.debug("[VirtualScroll] Updated item size manually", { index: u, size: a, total: C });
1961
- let X = dt.current ? dt.current.index : null;
1962
- if (X === null) {
1963
- const U = M.current, F = Ne(k).top, O = jt(U, F), { index: Et } = S.findIndexAtOrAfter(O, { materializeOption: { materialize: !1 } });
1964
- X = Et;
2446
+ m.current = !1;
2447
+ }, [M, x, i, R.top, it, n, R.bottom]), X(() => {
2448
+ const o = ct.current;
2449
+ if (o === R.top) return;
2450
+ const c = ee(C.current, o), d = me(c, R.top);
2451
+ ct.current = R.top, C.current = d, k.current?.scrollTo(d), it(d, { immediate: !0 });
2452
+ }, [R.top, it]);
2453
+ const Xt = y(
2454
+ (o, c) => {
2455
+ if (i === 0)
2456
+ return;
2457
+ const d = dt(o, i), P = x.get(d), N = c - P, _ = x.update(d, c);
2458
+ _ !== void 0 && Y(_), V.debug("[VirtualScroll] Updated item size manually", { index: d, size: c, total: _ });
2459
+ let A = st.current ? st.current.index : null;
2460
+ if (A === null) {
2461
+ const B = C.current, gt = Xe(z).top, tt = ee(B, gt), { index: Q, cumulative: vt } = x.findIndexAtOrAfter(tt, { materializeOption: { materialize: !1 } });
2462
+ A = vt !== void 0 && vt === tt ? Q + 1 : Q;
1965
2463
  }
1966
- if (X !== -1 && u < X && D !== 0) {
1967
- const U = M.current, F = U + D;
1968
- at.current += 1, lt(F, { immediate: !0 }), A.current?.scrollTo(F), _.debug("[VirtualScroll] Adjusted scroll for layout shift (manual update)", { from: U, to: F, causedByIndex: u, delta: D, activeVisibleStartIndex: X });
2464
+ if (A !== -1 && d < A && N !== 0) {
2465
+ const B = C.current, gt = B + N;
2466
+ Zt(gt), it(gt, { immediate: !0 }), V.debug("[VirtualScroll] Adjusted scroll for layout shift (manual update)", { from: B, to: gt, causedByIndex: d, delta: N, activeVisibleStartIndex: A });
1969
2467
  }
1970
2468
  },
1971
- [S, n, lt, k]
1972
- ), Nt = P(
1973
- (s, a) => {
1974
- if (!A.current)
2469
+ [x, i, Zt, it, z]
2470
+ ), kt = y(
2471
+ (o, c) => {
2472
+ if (!k.current || i === 0)
1975
2473
  return;
1976
- const u = it(s, n), R = it(u - l * 2, n), D = it(u + l * 2, n), { cumulative: C, total: X, currentValue: U } = S.prefixSum(u, { materializeOption: { materialize: !0, ranges: [{ from: R, to: D }] } });
1977
- if (_.debug("[VirtualScroll] Scrolling to index:", u, "ItemBottom:", C, "Total height:", X, "ItemHeight:", U, "safeIndexFrom:", R, "safeIndexTo:", D), !X)
2474
+ const d = dt(o, i), P = dt(d - s * 2, i), N = dt(d + s * 2, i), { cumulative: _, total: A, currentValue: B } = x.prefixSum(d, { materializeOption: { materialize: !0, ranges: [{ from: P, to: N }] } });
2475
+ if (V.debug("[VirtualScroll] Scrolling to index:", d, "ItemBottom:", _, "Total height:", A, "ItemHeight:", B, "safeIndexFrom:", P, "safeIndexTo:", N), !A)
1978
2476
  return;
1979
- const F = Math.max(C - U, 0);
1980
- let O = F;
1981
- a?.align === "bottom" ? O = C - i : a?.align === "center" && (O = F + U / 2 - i / 2), a?.offset && (O -= a.offset), O = Math.max(0, O);
1982
- const Et = se(O, v.top), vt = A.current?.getContentSize() ?? X + v.top + v.bottom, zt = Math.max(0, vt - i), te = Math.min(Et, zt);
1983
- dt.current = {
1984
- index: u,
1985
- align: a?.align,
1986
- offset: a?.offset
2477
+ const gt = Math.max(_ - B, 0);
2478
+ let tt = gt;
2479
+ c?.align === "bottom" ? tt = _ - n : c?.align === "center" && (tt = gt + B / 2 - n / 2), c?.offset && (tt -= c.offset), tt = Math.max(0, tt);
2480
+ const Q = me(tt, R.top), vt = k.current?.getContentSize() ?? A + R.top + R.bottom, bt = Math.max(0, vt - n), Tt = Math.min(Q, bt);
2481
+ st.current = {
2482
+ index: d,
2483
+ align: c?.align,
2484
+ offset: c?.offset
1987
2485
  };
1988
- const ue = A.current?.getScrollPosition() ?? -1, de = Math.abs(ue - te) > 0.5;
1989
- _t.current = !1, at.current = 0, de && (_t.current = !0, at.current += 1, A.current?.scrollTo(te)), b(X), lt(te, { immediate: !0 }), _.debug("[VirtualScroll] Setting scroll position to:", te, { original: Et, max: zt });
2486
+ const se = k.current?.getScrollPosition() ?? -1, ve = Math.abs(se - Tt) > 0.5;
2487
+ Ot.current = !1, It.current = 0, ve && (Ot.current = !0, It.current += 1, k.current?.scrollTo(Tt)), Y(A), it(Tt, { immediate: !0 }), V.debug("[VirtualScroll] Setting scroll position to:", Tt, { original: Q, max: bt });
1990
2488
  },
1991
- [S, l, n, v.top, v.bottom, i, lt]
1992
- ), ee = P(
1993
- (s) => {
1994
- if (!A.current)
2489
+ [x, s, i, R.top, R.bottom, n, it]
2490
+ ), xe = y(
2491
+ (o) => {
2492
+ if (!k.current || i === 0)
1995
2493
  return;
1996
- const a = S.getTotal(), u = xt(Math.floor(s), 0, a), { index: R, cumulative: D, currentValue: C } = S.findIndexAtOrAfter(u, { materializeOption: { materialize: !1 } }), U = (D ?? 0) - (C ?? 0) - u;
1997
- Nt(R, { offset: U });
2494
+ const c = x.getTotal(), d = mt(Math.floor(o), 0, c), { index: P, cumulative: N, currentValue: _ } = x.findIndexAtOrAfter(d, { materializeOption: { materialize: !1 } }), B = (N ?? 0) - (_ ?? 0) - d;
2495
+ kt(P, { offset: B });
1998
2496
  },
1999
- [S, Nt]
2000
- ), me = P(
2001
- (s) => {
2002
- const a = jt(M.current, v.top), u = typeof s == "function" ? s(a) : s;
2003
- ee(u);
2004
- const R = A.current?.getScrollPosition(), D = typeof R == "number" ? R : M.current;
2005
- return lt(D), D;
2497
+ [x, i, kt]
2498
+ ), Me = y(
2499
+ (o) => {
2500
+ const c = ee(C.current, R.top), d = typeof o == "function" ? o(c) : o;
2501
+ xe(d);
2502
+ const P = k.current?.getScrollPosition(), N = typeof P == "number" ? P : C.current;
2503
+ return it(N), N;
2006
2504
  },
2007
- [v.top, ee, lt]
2008
- ), Ie = P(
2009
- (s, a) => {
2010
- _.debug("[VirtualScroll] Scroll position changed:", s);
2011
- const u = _t.current;
2012
- u && (_t.current = !1);
2013
- const R = at.current > 0;
2014
- if (R && (at.current = 0), u || R || p.current || (dt.current = null), lt(s), E) {
2015
- if (u || R)
2505
+ [R.top, xe, it]
2506
+ ), Ne = y(
2507
+ (o, c) => {
2508
+ V.debug("[VirtualScroll] Scroll position changed:", o);
2509
+ const d = Ot.current;
2510
+ d && (Ot.current = !1);
2511
+ const P = It.current > 0;
2512
+ if (P && (It.current = 0), d || P || m.current || (st.current = null), it(o), h) {
2513
+ if (d || P)
2016
2514
  return;
2017
- const D = s - a;
2018
- if (_.debug("[VirtualScroll] Scroll diff:", D, "New:", s, "Prev:", a), Math.abs(D) > 1) {
2019
- const C = D > 0 ? "down" : "up";
2020
- qt(C), Tt(!0), _.debug("[VirtualScroll] Showing scroll buttons. Direction:", C), Ct.current && clearTimeout(Ct.current), Ct.current = setTimeout(() => {
2021
- Tt(!1), _.debug("[VirtualScroll] Hiding scroll buttons");
2515
+ const N = o - c;
2516
+ if (V.debug("[VirtualScroll] Scroll diff:", N, "New:", o, "Prev:", c), Math.abs(N) > 1) {
2517
+ const _ = N > 0 ? "down" : "up";
2518
+ Kt(_), xt(!0), V.debug("[VirtualScroll] Showing scroll buttons. Direction:", _), _t.current && clearTimeout(_t.current), _t.current = setTimeout(() => {
2519
+ xt(!1), V.debug("[VirtualScroll] Hiding scroll buttons");
2022
2520
  }, 2e3);
2023
2521
  }
2024
2522
  }
2025
2523
  },
2026
- [lt, E]
2027
- ), Ot = At(() => jt(Vt, v.top), [v.top, Vt]), Qt = At(() => {
2028
- const s = S.getTotal(), a = hr(Ot, i, l, n, r, S, s);
2029
- return _.debug("[VirtualScroll] Calculated rendering range:", {
2030
- ...a,
2031
- scrollPosition: Ot,
2032
- renderingContentSize: s,
2033
- overscanCount: l,
2034
- viewportSize: i
2035
- }), a;
2036
- }, [Ot, i, l, n, r, S]), { renderingStartIndex: Ut, renderingEndIndex: $t, visibleStartIndex: Yt, visibleEndIndex: Kt } = Qt, Wt = P(
2037
- (s, a) => {
2038
- if (!I || n === 0)
2524
+ [it, h]
2525
+ ), Yt = yt(() => ee(At, R.top), [R.top, At]), ie = yt(() => {
2526
+ const o = x.getTotal(), c = Rr(Yt, n, s, i, r, x, o);
2527
+ return V.debug("[VirtualScroll] Calculated rendering range:", () => ({
2528
+ ...c,
2529
+ scrollPosition: Yt,
2530
+ renderingContentSize: o,
2531
+ overscanCount: s,
2532
+ viewportSize: n
2533
+ })), c;
2534
+ }, [Yt, n, s, i, r, x]), { renderingStartIndex: Jt, renderingEndIndex: Qt, visibleStartIndex: Bt, visibleEndIndex: ce } = ie, te = y(
2535
+ (o, c) => {
2536
+ if (!O || i === 0)
2039
2537
  return;
2040
- const u = it(s, n);
2041
- if (!(a?.ensureVisible ?? !0)) {
2042
- const zt = mt.current.get(u);
2043
- zt && (Z.current = null, J.current = u, nt(zt));
2538
+ const d = dt(o, i);
2539
+ if (!(c?.ensureVisible ?? !0)) {
2540
+ const bt = ht.current.get(d);
2541
+ bt && (J.current = null, Ct.current = d, lt(bt));
2044
2542
  return;
2045
2543
  }
2046
- const D = S.prefixSum(u, { materializeOption: { materialize: !1 } }), C = D.currentValue, X = Math.max(D.cumulative - C, 0), U = X + C, F = jt(M.current, v.top), O = F + i;
2047
- if (X < F || U > O) {
2048
- Z.current = u, Nt(u);
2544
+ const N = x.prefixSum(d, { materializeOption: { materialize: !1 } }), _ = N.currentValue, A = Math.max(N.cumulative - _, 0), B = A + _, gt = ee(C.current, R.top), tt = gt + n;
2545
+ if (A < gt || B > tt) {
2546
+ kt(d);
2547
+ const bt = ht.current.get(d);
2548
+ bt ? (J.current = null, Ct.current = d, lt(bt)) : J.current = d;
2049
2549
  return;
2050
2550
  }
2051
- const vt = mt.current.get(u);
2551
+ const vt = ht.current.get(d);
2052
2552
  if (vt) {
2053
- Z.current = null, J.current = u, nt(vt);
2553
+ J.current = null, Ct.current = d, lt(vt);
2054
2554
  return;
2055
2555
  }
2056
- Z.current = u;
2556
+ J.current = d;
2057
2557
  },
2058
- [I, n, S, v.top, Nt, nt, i]
2059
- ), pe = P(
2060
- (s, a) => {
2061
- if (!I || s.defaultPrevented || s.altKey || s.metaKey || s.ctrlKey)
2558
+ [O, i, x, R.top, kt, lt, n]
2559
+ ), Pe = y(
2560
+ (o, c) => {
2561
+ if (!O || o.defaultPrevented || o.altKey || o.metaKey || o.ctrlKey)
2062
2562
  return;
2063
- const u = s.target;
2064
- if (u) {
2065
- const R = u.tagName;
2066
- if (R === "INPUT" || R === "TEXTAREA" || R === "SELECT" || u.isContentEditable)
2563
+ const d = o.target;
2564
+ if (d) {
2565
+ const P = d.tagName;
2566
+ if (P === "INPUT" || P === "TEXTAREA" || P === "SELECT" || d.isContentEditable)
2067
2567
  return;
2068
2568
  }
2069
- if (s.key === "ArrowDown") {
2070
- a < n - 1 && (s.preventDefault(), Wt(a + 1));
2569
+ if (o.key === "ArrowDown") {
2570
+ c < i - 1 && (o.preventDefault(), te(c + 1));
2071
2571
  return;
2072
2572
  }
2073
- if (s.key === "ArrowUp") {
2074
- a > 0 && (s.preventDefault(), Wt(a - 1));
2573
+ if (o.key === "ArrowUp") {
2574
+ c > 0 && (o.preventDefault(), te(c - 1));
2075
2575
  return;
2076
2576
  }
2077
- if (s.key === "PageDown") {
2078
- if (a < n - 1) {
2079
- s.preventDefault();
2080
- const R = Math.max(Kt - Yt + 1, 1), D = Math.max(R, 1), C = it(Math.min(a + D, n - 1), n);
2081
- Wt(C);
2577
+ if (o.key === "PageDown") {
2578
+ if (c < i - 1) {
2579
+ o.preventDefault();
2580
+ const { visibleStartIndex: P, visibleEndIndex: N } = G.current, _ = Math.max(N - P + 1, 1), A = Math.max(_, 1), B = dt(Math.min(c + A, i - 1), i);
2581
+ te(B);
2082
2582
  }
2083
2583
  return;
2084
2584
  }
2085
- if (s.key === "PageUp" && a > 0) {
2086
- s.preventDefault();
2087
- const R = Math.max(Kt - Yt + 1, 1), D = Math.max(R, 1), C = it(a - D, n);
2088
- Wt(C);
2585
+ if (o.key === "PageUp" && c > 0) {
2586
+ o.preventDefault();
2587
+ const { visibleStartIndex: P, visibleEndIndex: N } = G.current, _ = Math.max(N - P + 1, 1), A = Math.max(_, 1), B = dt(c - A, i);
2588
+ te(B);
2089
2589
  }
2090
2590
  },
2091
- [I, n, Wt, Kt, Yt]
2092
- ), he = P(
2093
- (s) => {
2094
- if (!I)
2591
+ [O, i, te]
2592
+ ), ye = y(
2593
+ (o) => {
2594
+ if (!O)
2095
2595
  return;
2096
- const a = it(s, n);
2097
- Z.current = null, J.current = a, B?.(a);
2596
+ const c = dt(o, i);
2597
+ J.current = null, Ct.current = c, rt?.(c);
2098
2598
  },
2099
- [I, n, B]
2599
+ [O, i, rt]
2100
2600
  );
2101
- Y(() => {
2102
- const s = A.current?.getScrollPosition() ?? 0, a = M.current, u = jt(a, v.top);
2103
- _.debug("[VirtualScroll] Range change effect triggered", {
2104
- renderingStartIndex: Ut,
2105
- renderingEndIndex: $t,
2106
- visibleStartIndex: Yt,
2107
- visibleEndIndex: Kt,
2108
- scrollPositionState: Vt,
2109
- paneScrollPosition: a,
2110
- logicalScrollPosition: u,
2111
- contentSize: Mt,
2112
- scrollPaneScrollPosition: s
2113
- }), Ft({
2114
- renderingStartIndex: Ut,
2115
- renderingEndIndex: $t,
2116
- visibleStartIndex: Yt,
2117
- visibleEndIndex: Kt,
2118
- scrollPosition: u,
2119
- totalHeight: Mt
2601
+ X(() => {
2602
+ const o = k.current?.getScrollPosition() ?? 0, c = C.current, d = ee(c, R.top);
2603
+ V.debug("[VirtualScroll] Range change effect triggered", () => ({
2604
+ renderingStartIndex: Jt,
2605
+ renderingEndIndex: Qt,
2606
+ visibleStartIndex: Bt,
2607
+ visibleEndIndex: ce,
2608
+ scrollPositionState: At,
2609
+ paneScrollPosition: c,
2610
+ logicalScrollPosition: d,
2611
+ contentSize: M,
2612
+ scrollPaneScrollPosition: o
2613
+ })), Ht({
2614
+ renderingStartIndex: Jt,
2615
+ renderingEndIndex: Qt,
2616
+ visibleStartIndex: Bt,
2617
+ visibleEndIndex: ce,
2618
+ scrollPosition: d,
2619
+ totalHeight: M
2120
2620
  });
2121
- }, [Mt, $t, Ut, v.top, Ft, Vt, Kt, Yt]);
2122
- const ge = P(() => E ? /* @__PURE__ */ $("div", { className: "aqvs-scroll-to-edge-overlay", "data-visible": yt && bt !== null, children: bt === "up" ? /* @__PURE__ */ $("div", { className: "aqvs-scroll-to-edge-button-container aqvs-scroll-to-edge-button-container-top", children: /* @__PURE__ */ $(
2621
+ }, [M, Qt, Jt, R.top, Ht, At, ce, Bt]);
2622
+ const Ve = y(() => h ? /* @__PURE__ */ et("div", { className: "aqvs-scroll-to-edge-overlay", "data-visible": Lt && ut !== null, children: ut === "up" ? /* @__PURE__ */ et("div", { className: "aqvs-scroll-to-edge-button-container aqvs-scroll-to-edge-button-container-top", children: /* @__PURE__ */ et(
2123
2623
  "button",
2124
2624
  {
2125
2625
  type: "button",
2126
2626
  className: "aqvs-scroll-to-edge-button",
2127
- onClick: (u) => {
2128
- u.stopPropagation(), _t.current = !0, Nt(0), Tt(!1);
2627
+ onClick: (d) => {
2628
+ d.stopPropagation(), Ot.current = !0, kt(0), xt(!1);
2129
2629
  },
2130
2630
  children: "Top"
2131
2631
  }
2132
- ) }) : /* @__PURE__ */ $("div", { className: "aqvs-scroll-to-edge-button-container aqvs-scroll-to-edge-button-container-bottom", children: /* @__PURE__ */ $(
2632
+ ) }) : /* @__PURE__ */ et("div", { className: "aqvs-scroll-to-edge-button-container aqvs-scroll-to-edge-button-container-bottom", children: /* @__PURE__ */ et(
2133
2633
  "button",
2134
2634
  {
2135
2635
  type: "button",
2136
2636
  className: "aqvs-scroll-to-edge-button",
2137
- onClick: (u) => {
2138
- u.stopPropagation(), _t.current = !0, Nt(n - 1), Tt(!1);
2637
+ onClick: (d) => {
2638
+ d.stopPropagation(), Ot.current = !0, kt(i - 1), xt(!1);
2139
2639
  },
2140
2640
  children: "Bottom"
2141
2641
  }
2142
- ) }) }) : null, [E, yt, bt, Nt, n]), { visibleItems: ie, startPosition: o } = At(() => {
2143
- if (n === 0)
2642
+ ) }) }) : null, [h, Lt, ut, kt, i]), Ie = b(0), { visibleItems: ue, renderAnchor: de } = yt(() => {
2643
+ if (i === 0)
2144
2644
  return {
2145
- visibleItems: /* @__PURE__ */ $("div", { className: "aqvs-no-items-container", children: /* @__PURE__ */ $("div", { className: "aqvs-no-items-text", children: "No items" }) }),
2146
- startPosition: 0
2645
+ visibleItems: /* @__PURE__ */ et("div", { className: "aqvs-no-items-container", children: /* @__PURE__ */ et("div", { className: "aqvs-no-items-text", children: "No items" }) }),
2646
+ renderAnchor: 0
2147
2647
  };
2148
- const s = it(Ut, n), a = it($t, n), { cumulative: u, currentValue: R } = S.prefixSum(s, { materializeOption: { materialize: !1 } }), D = u - R, C = [], X = [];
2149
- let U = 0;
2150
- for (let F = s; F <= a; F++) {
2151
- const O = r(F), Et = S.get(F), vt = O - Et;
2152
- vt !== 0 && C.push({ index: F, value: O });
2153
- const { cumulative: zt, currentValue: te } = S.prefixSum(F, { materializeOption: { materialize: !1 } }), ue = zt - te + U, de = e ? e(F) : F;
2154
- X.push(
2155
- /* @__PURE__ */ $(
2156
- gr,
2648
+ const o = dt(Jt, i), c = dt(Qt, i), { cumulative: d, currentValue: P } = x.prefixSum(o, { materializeOption: { materialize: !1 } }), N = d - P;
2649
+ Number.isFinite(N) && Math.abs(N - Ie.current) > yr && (Ie.current = N);
2650
+ const _ = Ie.current, A = [], B = [];
2651
+ let gt = 0, tt = N;
2652
+ for (let Q = o; Q <= c; Q++) {
2653
+ if (B.length >= $e) {
2654
+ V.warn("[VirtualScroll] Rendered item count reached the safety cap; truncating render window.", { cap: $e, safeRenderingStartIndex: o, safeRenderingEndIndex: c });
2655
+ break;
2656
+ }
2657
+ const vt = r(Q), bt = x.get(Q), Tt = vt - bt;
2658
+ Tt !== 0 && A.push({ index: Q, value: vt });
2659
+ const se = tt + gt, ve = e ? e(Q) : Q;
2660
+ B.push(
2661
+ /* @__PURE__ */ et(
2662
+ Cr,
2157
2663
  {
2158
- index: F,
2159
- top: ue - D + v.top,
2160
- height: O,
2161
- item: t(F),
2162
- clipItemHeight: Dt,
2163
- enableKeyboardNavigation: I,
2164
- onKeyDown: pe,
2165
- onFocus: he,
2166
- registerItemRef: wt,
2167
- children: h
2664
+ index: Q,
2665
+ top: se - _,
2666
+ height: vt,
2667
+ item: t(Q),
2668
+ clipItemHeight: U,
2669
+ enableKeyboardNavigation: O,
2670
+ onKeyDown: Pe,
2671
+ onFocus: ye,
2672
+ registerItemRef: jt,
2673
+ children: I
2168
2674
  },
2169
- de
2675
+ ve
2170
2676
  )
2171
- ), U += vt;
2677
+ ), gt += Tt, tt += bt;
2172
2678
  }
2173
- return C.length > 0 && Promise.resolve().then(() => {
2174
- if (!It.current)
2679
+ return A.length > 0 && Promise.resolve().then(() => {
2680
+ if (Mt.current)
2175
2681
  return;
2176
- let F = 0;
2177
- for (const vt of C)
2178
- if (vt.index < Yt) {
2179
- const zt = S.get(vt.index);
2180
- F += vt.value - zt;
2682
+ let Q = 0;
2683
+ for (const Tt of A)
2684
+ if (Tt.index < Bt) {
2685
+ const se = x.get(Tt.index);
2686
+ Q += Tt.value - se;
2181
2687
  }
2182
- const O = S.updates(C);
2183
- if (!It.current || typeof O != "number")
2688
+ const vt = x.updates(A);
2689
+ if (Mt.current || typeof vt != "number")
2184
2690
  return;
2185
- b(O), _.debug("[VirtualScroll] Updated heights for items", C, "New total height:", O);
2186
- const Et = A.current?.getScrollPosition() ?? M.current;
2187
- if (F !== 0) {
2188
- const vt = Et + F;
2189
- at.current += 1, lt(vt, { immediate: !0 }), A.current?.scrollTo(vt), _.debug("[VirtualScroll] Adjusted scroll for layout shift (auto update)", { from: Et, to: vt, shiftAmount: F });
2190
- } else Et !== M.current && lt(Et);
2191
- }), { visibleItems: X, startPosition: D };
2691
+ Y(vt), V.debug("[VirtualScroll] Updated heights for items", A, "New total height:", vt);
2692
+ const bt = k.current?.getScrollPosition() ?? C.current;
2693
+ if (Q !== 0) {
2694
+ const Tt = bt + Q;
2695
+ Zt(Tt), it(Tt, { immediate: !0 }), V.debug("[VirtualScroll] Adjusted scroll for layout shift (auto update)", { from: bt, to: Tt, shiftAmount: Q });
2696
+ } else bt !== C.current && it(bt);
2697
+ }), { visibleItems: B, renderAnchor: _ };
2192
2698
  }, [
2193
- h,
2194
- Dt,
2195
2699
  I,
2196
- n,
2197
- S,
2700
+ U,
2701
+ M,
2702
+ O,
2703
+ i,
2704
+ x,
2198
2705
  t,
2199
2706
  e,
2200
2707
  r,
2201
- he,
2202
- pe,
2203
- wt,
2204
- $t,
2205
- Ut,
2206
- v.top,
2207
- lt,
2208
- Yt
2209
- ]), w = P(
2210
- (s) => {
2211
- const a = (x ?? 0) > 0, u = Math.abs(s - Vt), R = a && u > 0.5 ? Vt : s, D = jt(R, v.top);
2212
- if (_.debug("[VirtualScroll] Rendering visible items", {
2213
- currentScrollPosition: s,
2214
- effectiveScrollPosition: D,
2215
- renderingStartIndex: Ut,
2216
- renderingEndIndex: $t,
2217
- itemCount: n,
2218
- viewportSize: i,
2219
- callbackThrottleMs: x,
2220
- diff: u,
2221
- rawEffectiveScrollPosition: R
2222
- }), n === 0)
2223
- return ie;
2224
- const C = o - D, X = v.bottom > 0 ? /* @__PURE__ */ $(
2708
+ ye,
2709
+ Pe,
2710
+ Zt,
2711
+ jt,
2712
+ Qt,
2713
+ Jt,
2714
+ it,
2715
+ Bt
2716
+ ]), a = y(
2717
+ (o) => {
2718
+ const c = (p ?? 0) > 0, d = Math.abs(o - At), P = c && d > 0.5 ? At : o, N = ee(P, R.top);
2719
+ if (V.debug("[VirtualScroll] Rendering visible items", () => ({
2720
+ currentScrollPosition: o,
2721
+ effectiveScrollPosition: N,
2722
+ renderingStartIndex: Jt,
2723
+ renderingEndIndex: Qt,
2724
+ itemCount: i,
2725
+ viewportSize: n,
2726
+ callbackThrottleMs: p,
2727
+ diff: d,
2728
+ rawEffectiveScrollPosition: P
2729
+ })), i === 0)
2730
+ return ue;
2731
+ const _ = R.top + de - P, A = R.bottom > 0 ? /* @__PURE__ */ et(
2225
2732
  "div",
2226
2733
  {
2227
2734
  className: "aqvs-bottom-inset",
2228
2735
  style: {
2229
- top: S.getTotal() + v.top - o,
2230
- height: v.bottom
2736
+ // ラッパー座標での bottom インセット位置 = コンテンツ総高さ (最終行の下端) - アンカー。
2737
+ top: x.getTotal() - de,
2738
+ height: R.bottom
2231
2739
  }
2232
2740
  },
2233
2741
  "virtualscroll-bottom-inset"
2234
2742
  ) : null;
2235
- return _.debug("[VirtualScroll] Rendering items", {
2236
- containerTop: C,
2237
- logicalScrollPosition: Ot,
2238
- resolvedInsets: v,
2239
- effectiveScrollPosition: D
2240
- }), /* @__PURE__ */ ne("div", { className: "aqvs-items-wrapper", style: { top: C, position: "relative" }, children: [
2241
- ie,
2242
- X
2743
+ return V.debug("[VirtualScroll] Rendering items", () => ({
2744
+ containerTop: _,
2745
+ logicalScrollPosition: Yt,
2746
+ resolvedInsets: R,
2747
+ effectiveScrollPosition: N
2748
+ })), /* @__PURE__ */ le("div", { className: "aqvs-items-wrapper", style: { top: 0, transform: `translateY(${_}px)`, willChange: "transform" }, children: [
2749
+ ue,
2750
+ A
2243
2751
  ] });
2244
2752
  },
2245
- [x, n, S, Ot, $t, Ut, v, Vt, o, i, ie]
2246
- ), V = At(
2753
+ [p, i, x, Yt, de, Qt, Jt, R, At, n, ue]
2754
+ ), g = yt(
2247
2755
  () => ({
2248
- renderingStartIndex: Qt.renderingStartIndex,
2249
- renderingEndIndex: Qt.renderingEndIndex,
2250
- visibleStartIndex: Qt.visibleStartIndex,
2251
- visibleEndIndex: Qt.visibleEndIndex,
2252
- scrollPosition: Ot,
2253
- totalHeight: S.getTotal()
2756
+ renderingStartIndex: ie.renderingStartIndex,
2757
+ renderingEndIndex: ie.renderingEndIndex,
2758
+ visibleStartIndex: ie.visibleStartIndex,
2759
+ visibleEndIndex: ie.visibleEndIndex,
2760
+ scrollPosition: Yt,
2761
+ totalHeight: x.getTotal()
2254
2762
  // contentSize (State) ではなく最新値を反映
2255
2763
  }),
2256
- [Qt, Ot, S]
2764
+ // contentSize を依存に含めることで、updateItemSize/updates 等で木の総高さが変わった際に
2765
+ // (fenwickTree は安定参照のため getTotal() の変化だけでは再計算されない) 総高さを再取得する。
2766
+ [ie, Yt, x, M]
2257
2767
  );
2258
- Y(() => {
2259
- G.current = V;
2260
- }, [V]), we(
2261
- ct,
2768
+ X(() => {
2769
+ G.current = g;
2770
+ }, [g]), ke(
2771
+ ft,
2262
2772
  () => ({
2263
- getScrollPosition: () => A.current?.getScrollPosition() ?? -1,
2264
- getContentSize: () => A.current?.getContentSize() ?? -1,
2265
- getViewportSize: () => A.current?.getViewportSize() ?? -1,
2266
- scrollTo: me,
2267
- scrollToIndex: Nt,
2268
- getFenwickTreeTotalHeight: () => S.getTotal(),
2269
- getFenwickSize: () => S.getSize(),
2270
- focusItemAtIndex: Wt,
2773
+ getScrollPosition: () => k.current?.getScrollPosition() ?? -1,
2774
+ getContentSize: () => k.current?.getContentSize() ?? -1,
2775
+ getViewportSize: () => k.current?.getViewportSize() ?? -1,
2776
+ scrollTo: Me,
2777
+ scrollToIndex: kt,
2778
+ getFenwickTreeTotalHeight: () => x.getTotal(),
2779
+ getFenwickSize: () => x.getSize(),
2780
+ focusItemAtIndex: te,
2271
2781
  getRange: () => G.current,
2272
- updateItemSize: ce
2782
+ updateItemSize: Xt
2273
2783
  }),
2274
- [me, Nt, S, Wt, ce]
2784
+ [Me, kt, x, te, Xt]
2275
2785
  );
2276
- const K = S.getTotal() + v.top + v.bottom;
2277
- return /* @__PURE__ */ $(
2278
- ar,
2786
+ const w = x.getTotal() + R.top + R.bottom;
2787
+ return /* @__PURE__ */ et(
2788
+ xr,
2279
2789
  {
2280
- ref: A,
2281
- contentSize: K,
2282
- viewportSize: i,
2283
- className: c,
2284
- onScroll: Ie,
2285
- background: m,
2286
- tapScrollCircleOptions: Pt,
2287
- inertiaOptions: St,
2288
- itemCount: n,
2289
- scrollBarWidth: st,
2290
- enableThumbDrag: L,
2291
- enableTrackClick: tt,
2292
- enableArrowButtons: et,
2293
- enablePointerDrag: ht,
2294
- renderThumbOverlay: ut,
2295
- wheelSpeedMultiplier: W,
2296
- onWheelHorizontal: pt,
2297
- contentInsets: v,
2298
- visibleStartIndex: Yt,
2299
- visibleEndIndex: Kt,
2300
- renderOverlay: ge,
2301
- initialScrollPosition: rt.position,
2302
- children: w
2790
+ ref: k,
2791
+ contentSize: w,
2792
+ viewportSize: n,
2793
+ className: l,
2794
+ onScroll: Ne,
2795
+ background: v,
2796
+ tapScrollCircleOptions: q,
2797
+ inertiaOptions: S,
2798
+ itemCount: i,
2799
+ scrollBarWidth: St,
2800
+ enableThumbDrag: wt,
2801
+ enableTrackClick: L,
2802
+ enableArrowButtons: F,
2803
+ enablePointerDrag: H,
2804
+ renderThumbOverlay: $,
2805
+ wheelSpeedMultiplier: K,
2806
+ onWheelHorizontal: nt,
2807
+ contentInsets: R,
2808
+ visibleStartIndex: Bt,
2809
+ visibleEndIndex: ce,
2810
+ renderOverlay: Ve,
2811
+ initialScrollPosition: Rt.position,
2812
+ children: a
2303
2813
  }
2304
2814
  );
2305
- }, Sr = ye(xr);
2815
+ }, _r = Fe(Er);
2306
2816
  export {
2307
- cr as FenwickMapTree,
2308
- or as ScrollBar,
2309
- ar as ScrollPane,
2310
- Sr as VirtualScroll,
2311
- xt as minmax,
2312
- Tr as tapScrollCircleSampleVisual,
2313
- ur as useFenwickMapTree,
2314
- Pr as useHeightCache,
2315
- fr as useLruCache
2817
+ oe as FenwickMapTree,
2818
+ br as ScrollBar,
2819
+ xr as ScrollPane,
2820
+ _r as VirtualScroll,
2821
+ mt as minmax,
2822
+ Dr as tapScrollCircleSampleVisual,
2823
+ Tr as useFenwickMapTree,
2824
+ Lr as useHeightCache,
2825
+ Mr as useLruCache
2316
2826
  };