@aiquants/virtualscroll 0.5.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,426 +1,449 @@
1
- import { jsxs as xe, jsx as j } from "react/jsx-runtime";
2
- import { forwardRef as Ve, useState as le, useRef as N, useCallback as z, useImperativeHandle as Me, useMemo as O, useEffect as re, useReducer as ze, useLayoutEffect as ve, useId as ke } from "react";
3
- import { twMerge as he } from "tailwind-merge";
4
- const J = {
5
- debug(c, ...e) {
6
- typeof window < "u" && window.localStorage?.getItem("debug") === "true" && console.debug(`[VirtualScroll] ${c}`, ...e);
7
- },
8
- warn(c, ...e) {
9
- console.warn(`[VirtualScroll] ${c}`, ...e);
10
- },
11
- error(c, ...e) {
12
- console.error(`[VirtualScroll] ${c}`, ...e);
13
- }
14
- }, C = (c, e, n) => Math.min(n, Math.max(e, c)), ye = {
1
+ import { jsx as $, jsxs as Se, Fragment as Je } from "react/jsx-runtime";
2
+ import { forwardRef as ke, useState as de, useRef as k, useCallback as A, useImperativeHandle as Oe, useMemo as xe, useEffect as se, useReducer as st, useLayoutEffect as Ee, useId as ot } from "react";
3
+ import { twMerge as we } from "tailwind-merge";
4
+ const Ke = {
15
5
  active: !1,
6
+ offsetX: 0,
16
7
  offsetY: 0,
17
8
  distance: 0,
18
9
  direction: 0
19
- }, Le = 6, Re = Ve(({ onDragChange: c, className: e, maxVisualDistance: n = 160, size: t = 64, style: r, opacity: o = 1 }, s) => {
20
- const [m, d] = le(ye), f = N(null), g = N({ x: 0, y: 0 }), y = N(null), w = z(
21
- (x, T = !1) => {
22
- const { y: M } = g.current, h = x - M, p = Math.abs(h), I = p < Le ? 0 : h < 0 ? -1 : 1, v = {
23
- active: T || p >= Le,
24
- offsetY: h,
25
- distance: p,
26
- direction: I
27
- };
28
- d(v), c(v);
29
- },
30
- [c]
31
- ), ie = z(
32
- (x = !1) => {
33
- if (x && f.current !== null) {
34
- const T = y.current;
35
- T?.hasPointerCapture(f.current) && T.releasePointerCapture(f.current);
10
+ }, qe = 6, it = ({ dragState: o, normalizedDistance: e }) => {
11
+ const t = 1 + e * 0.18, n = 0.16 + e * 0.24, r = 0.38 + e * 0.28, i = o.active ? "80ms ease-out" : "220ms ease";
12
+ return /* @__PURE__ */ Se(Je, { children: [
13
+ /* @__PURE__ */ $(
14
+ "div",
15
+ {
16
+ className: "absolute inset-0 rounded-full",
17
+ style: {
18
+ background: "linear-gradient(140deg, rgba(255,255,255,0.62), rgba(72,72,72,0.48))",
19
+ boxShadow: `0 0 0 1px rgba(255,255,255,0.28), 0 10px 22px rgba(0,0,0,${n})`,
20
+ transform: `scale(${t})`,
21
+ transition: `${i}, ${o.active ? "80ms" : "260ms"} box-shadow ease`
22
+ }
23
+ }
24
+ ),
25
+ /* @__PURE__ */ $(
26
+ "div",
27
+ {
28
+ className: "absolute inset-[18%] rounded-full",
29
+ style: {
30
+ background: "linear-gradient(140deg, rgba(255,255,255,0.72), rgba(28,28,28,0.58))",
31
+ boxShadow: "inset 0 4px 10px rgba(0,0,0,0.24), inset 0 0 2px rgba(255,255,255,0.55)",
32
+ opacity: r,
33
+ transition: o.active ? "120ms opacity ease-out" : "220ms opacity ease"
34
+ }
36
35
  }
37
- f.current = null, d(ye), c(ye);
36
+ )
37
+ ] });
38
+ }, Qe = ke(({ onDragChange: o, className: e, maxVisualDistance: t = 160, size: n = 40, style: r, opacity: i = 1, renderVisual: l }, a) => {
39
+ const [h, u] = de(Ke), d = k(null), p = k({ x: 0, y: 0 }), R = k(null), V = A((m) => {
40
+ u(m), o(m);
41
+ }, [o]), X = A(
42
+ (m, D, f = !1) => {
43
+ const { x: F, y: g } = p.current, N = m - F, L = D - g, C = Math.abs(L), M = C < qe ? 0 : L < 0 ? -1 : 1;
44
+ V({
45
+ active: f || C >= qe,
46
+ offsetX: N,
47
+ offsetY: L,
48
+ distance: C,
49
+ direction: M
50
+ });
38
51
  },
39
- [c]
40
- ), ae = z(
41
- (x) => {
42
- x.preventDefault(), x.stopPropagation();
43
- const T = y.current ?? x.currentTarget, M = T.getBoundingClientRect();
44
- g.current = {
45
- x: M.left + M.width / 2,
46
- y: M.top + M.height / 2
47
- }, f.current = x.pointerId, T.setPointerCapture(x.pointerId), w(x.clientY, !0);
52
+ [V]
53
+ ), ee = A((m) => {
54
+ if (m === null)
55
+ return;
56
+ const D = R.current;
57
+ D?.hasPointerCapture(m) && D.releasePointerCapture(m);
58
+ }, []), b = A(
59
+ (m = !1) => {
60
+ m && ee(d.current), d.current = null, V(Ke);
61
+ },
62
+ [V, ee]
63
+ ), ae = A(
64
+ (m) => {
65
+ m.preventDefault(), m.stopPropagation();
66
+ const D = R.current ?? m.currentTarget, { left: f, top: F, width: g, height: N } = D.getBoundingClientRect();
67
+ p.current = { x: f + g / 2, y: F + N / 2 }, d.current = m.pointerId, D.setPointerCapture(m.pointerId), X(m.clientX, m.clientY, !0);
48
68
  },
49
- [w]
50
- ), Y = z(
51
- (x) => {
52
- f.current === x.pointerId && (x.preventDefault(), w(x.clientY));
69
+ [X]
70
+ ), le = A(
71
+ (m) => {
72
+ d.current === m.pointerId && (m.preventDefault(), X(m.clientX, m.clientY));
53
73
  },
54
- [w]
55
- ), Q = z(
56
- (x) => {
57
- f.current === x.pointerId && (x.preventDefault(), x.stopPropagation(), ie(!0));
74
+ [X]
75
+ ), Z = A(
76
+ (m) => {
77
+ d.current === m.pointerId && (m.preventDefault(), m.stopPropagation(), b(!0));
58
78
  },
59
- [ie]
79
+ [b]
60
80
  );
61
- Me(
62
- s,
81
+ Oe(
82
+ a,
63
83
  () => ({
64
84
  reset: () => {
65
- ie(!0);
85
+ b(!0);
66
86
  },
67
- getElement: () => y.current
87
+ getElement: () => R.current
68
88
  }),
69
- [ie]
89
+ [b]
70
90
  );
71
- const D = O(() => Math.min(m.distance, n) / n, [m.distance, n]), u = O(() => t / 64, [t]), ee = O(() => 1 + D * 0.4, [D]), E = O(() => m.direction * D * 10 * u, [m.direction, D, u]), P = O(() => m.direction * D * 26 * u, [m.direction, D, u]), F = O(() => 22 * u, [u]), W = O(() => Math.max(2.5, 3 * u), [u]), q = O(() => 6 * u, [u]), se = O(() => 3 * u, [u]), i = O(() => Math.min(Math.max(o, 0), 1), [o]), $ = O(() => {
72
- const x = {
73
- ...r,
74
- width: t,
75
- height: t,
76
- transform: `translateY(${E}px)`
77
- };
78
- return x.opacity = i, x;
79
- }, [i, E, t, r]), k = O(() => Math.abs(P) + q, [q, P]), A = O(() => P > 0 ? se : -Math.abs(P) - se, [se, P]);
80
- return /* @__PURE__ */ xe(
91
+ const _ = Math.min(Math.max(i, 0), 1), U = n / 64, O = Math.min(h.distance, t) / t, x = h.direction * O * 10 * U, P = l ?? it, w = {
92
+ dragState: h,
93
+ normalizedDistance: O,
94
+ sizeScale: U,
95
+ size: n,
96
+ opacity: _
97
+ }, H = {
98
+ ...r,
99
+ width: n,
100
+ height: n,
101
+ transform: `translateY(${x}px)`
102
+ };
103
+ return H.opacity = _, /* @__PURE__ */ $(
81
104
  "div",
82
105
  {
83
- ref: y,
84
- className: he(
85
- "relative flex items-center justify-center touch-none select-none",
106
+ ref: R,
107
+ className: we(
108
+ "relative flex touch-none select-none items-center justify-center",
86
109
  "transition-transform duration-100 ease-out",
87
110
  e
88
111
  ),
89
- style: $,
112
+ style: H,
90
113
  onPointerDown: ae,
91
- onPointerMove: Y,
92
- onPointerUp: Q,
93
- onPointerCancel: Q,
114
+ onPointerMove: le,
115
+ onPointerUp: Z,
116
+ onPointerCancel: Z,
94
117
  role: "presentation",
95
- children: [
96
- /* @__PURE__ */ j(
97
- "div",
98
- {
99
- className: "absolute inset-0 rounded-full border border-white/40 bg-gradient-to-br from-[#1d4ed8]/60 via-[#60a5fa]/55 to-[#bfdbfe]/40 shadow-md",
100
- style: {
101
- transform: `scaleY(${ee})`,
102
- transition: m.active ? "transform 40ms ease-out" : "transform 200ms ease"
103
- }
104
- }
105
- ),
106
- /* @__PURE__ */ j(
107
- "div",
108
- {
109
- className: "absolute left-1/2 top-1/2 h-6 w-6 -translate-x-1/2 -translate-y-1/2 rounded-full border border-white/50 bg-white/85",
110
- style: {
111
- width: F,
112
- height: F,
113
- transform: `translate(-50%, calc(-50% + ${P * 0.3}px)) scale(${1 + D * 0.2})`,
114
- transition: m.active ? "transform 40ms ease-out" : "transform 200ms ease"
115
- }
116
- }
117
- ),
118
- /* @__PURE__ */ j(
119
- "div",
120
- {
121
- className: "absolute left-1/2 top-1/2 w-1 rounded-full bg-white/50",
122
- style: {
123
- width: W,
124
- height: k,
125
- transform: `translate(-50%, ${A}px)`,
126
- opacity: D,
127
- transition: m.active ? "height 40ms ease-out, opacity 60ms" : "height 200ms ease, opacity 120ms"
128
- }
129
- }
130
- )
131
- ]
118
+ children: P(w)
132
119
  }
133
120
  );
134
121
  });
135
- Re.displayName = "TapScrollCircle";
136
- const Ae = (c, e, n) => {
137
- const t = "touches" in c.nativeEvent, r = t ? c.nativeEvent.touches[0] : c.nativeEvent, o = (m) => {
138
- t && m.cancelable && m.preventDefault();
139
- const d = "touches" in m ? m.touches[0] : m;
122
+ Qe.displayName = "TapScrollCircle";
123
+ const G = (o, e, t) => Math.min(t, Math.max(e, o)), je = (o, e, t) => {
124
+ const n = "touches" in o.nativeEvent, r = n ? o.nativeEvent.touches[0] : o.nativeEvent, i = (a) => {
125
+ n && a.cancelable && a.preventDefault();
126
+ const h = "touches" in a ? a.touches[0] : a;
140
127
  e({
141
- deltaX: d.clientX - r.clientX,
142
- deltaY: d.clientY - r.clientY
128
+ deltaX: h.clientX - r.clientX,
129
+ deltaY: h.clientY - r.clientY
143
130
  });
144
- }, s = () => {
145
- t ? (document.removeEventListener("touchmove", o), document.removeEventListener("touchend", s)) : (document.removeEventListener("mousemove", o), document.removeEventListener("mouseup", s)), n?.();
131
+ }, l = () => {
132
+ n ? (document.removeEventListener("touchmove", i), document.removeEventListener("touchend", l)) : (document.removeEventListener("mousemove", i), document.removeEventListener("mouseup", l)), t?.();
146
133
  };
147
- t ? (document.addEventListener("touchmove", o, { passive: !1 }), document.addEventListener("touchend", s)) : (document.addEventListener("mousemove", o), document.addEventListener("mouseup", s));
148
- }, Ee = "virtualscroll:tap-scroll-cancel", De = 20, Oe = 250, Ye = 60, He = 20, Ue = 20, $e = 220, _e = { active: !1, offsetY: 0, distance: 0, direction: 0 }, Se = 2.2, Xe = 8, qe = 120, ce = {
134
+ n ? (document.addEventListener("touchmove", i, { passive: !1 }), document.addEventListener("touchend", l)) : (document.addEventListener("mousemove", i), document.addEventListener("mouseup", l));
135
+ }, Ne = "virtualscroll:tap-scroll-cancel", We = 20, at = 250, lt = 60, ct = 20, ut = 20, dt = 220, Be = { active: !1, offsetX: 0, offsetY: 0, distance: 0, direction: 0 }, De = 2.2, ft = 8, ht = 120, pe = {
149
136
  enabled: !0,
150
- size: 64,
137
+ size: 40,
151
138
  offsetX: -80,
152
139
  offsetY: 0,
153
140
  className: void 0,
154
- maxVisualDistance: $e,
155
- opacity: 1
156
- }, je = (c) => {
157
- if (!c || c <= 0)
158
- return Se;
159
- const e = Math.max(1, c), n = Math.log10(e), t = Se + n * Xe;
160
- return C(t, Se, qe);
161
- }, Ke = ({ contentSize: c, viewportSize: e, scrollPosition: n, onScroll: t, horizontal: r = !1, scrollBarWidth: o = 12, className: s, ariaControls: m, tapScrollCircleOptions: d, itemCount: f }) => {
162
- const [g, y] = le(!1), [w, ie] = le(!1), ae = N(null), Y = N(n), Q = N(null), D = N(null), u = N(_e), ee = N(null), E = N(null), P = N(null), F = O(() => {
163
- const l = d?.maxSpeedMultiplier, L = typeof l == "number" ? l : je(f);
141
+ maxVisualDistance: dt,
142
+ opacity: 1,
143
+ renderVisual: void 0
144
+ }, mt = (o) => {
145
+ if (!o || o <= 0)
146
+ return De;
147
+ const e = Math.max(1, o), t = Math.log10(e), n = De + t * ft;
148
+ return G(n, De, ht);
149
+ }, pt = ({ contentSize: o, viewportSize: e, scrollPosition: t, onScroll: n, enableThumbDrag: r = !0, enableTrackClick: i = !0, enableArrowButtons: l = !0, horizontal: a = !1, scrollBarWidth: h = 12, className: u, ariaControls: d, tapScrollCircleOptions: p, itemCount: R }) => {
150
+ const [V, X] = de(!1), [ee, b] = de(!1), [ae, le] = de(!1), Z = k(null), _ = k(t), U = k(null), O = k(null), x = k(Be), P = k(null), w = k(null), H = k(null), m = xe(() => {
151
+ const s = p?.maxSpeedMultiplier, v = typeof s == "number" ? s : mt(R);
164
152
  return {
165
- enabled: d?.enabled ?? ce.enabled,
166
- size: d?.size ?? ce.size,
167
- offsetX: d?.offsetX ?? ce.offsetX,
168
- offsetY: d?.offsetY ?? ce.offsetY,
169
- className: d?.className ?? ce.className,
170
- maxVisualDistance: d?.maxVisualDistance ?? ce.maxVisualDistance,
171
- maxSpeedMultiplier: L,
172
- opacity: C(d?.opacity ?? ce.opacity, 0, 1)
153
+ enabled: p?.enabled ?? pe.enabled,
154
+ size: p?.size ?? pe.size,
155
+ offsetX: p?.offsetX ?? pe.offsetX,
156
+ offsetY: p?.offsetY ?? pe.offsetY,
157
+ className: p?.className ?? pe.className,
158
+ maxVisualDistance: p?.maxVisualDistance ?? pe.maxVisualDistance,
159
+ maxSpeedMultiplier: v,
160
+ opacity: G(p?.opacity ?? pe.opacity, 0, 1),
161
+ renderVisual: p?.renderVisual ?? pe.renderVisual
173
162
  };
174
- }, [f, d]), {
175
- enabled: W,
176
- size: q,
177
- offsetX: se,
178
- offsetY: i,
179
- className: $,
180
- maxVisualDistance: k,
181
- maxSpeedMultiplier: A,
182
- opacity: x
183
- } = F, T = Math.max(k, 1), M = e / c, h = o, p = Math.max(e - h * 2, 0), I = M * p, v = Math.min(Math.max(De, I || 0), p || De), b = c - e, _ = Math.max(p - v, 0), H = b <= 0 || _ <= 0 ? 0 : n / b * _, V = c > e;
184
- re(() => {
185
- Y.current = n;
186
- }, [n]), re(() => {
187
- ae.current && (g ? ae.current.style.backgroundColor = "#4F4F4F" : ae.current.style.backgroundColor = "#7F7F7F");
188
- }, [g]);
189
- const X = z(() => {
190
- Q.current !== null && (window.clearInterval(Q.current), Q.current = null), D.current !== null && (window.clearTimeout(D.current), D.current = null);
191
- }, []), R = z(() => {
192
- E.current !== null && (window.cancelAnimationFrame(E.current), E.current = null), P.current = null;
193
- }, []), S = z(() => {
194
- u.current = { ..._e }, ie(!1), ee.current?.reset(), R();
195
- }, [R]), K = z(
196
- (l) => {
197
- const L = u.current;
198
- if (!L.active || L.direction === 0) {
199
- R();
163
+ }, [R, p]), {
164
+ enabled: D,
165
+ size: f,
166
+ offsetX: F,
167
+ offsetY: g,
168
+ className: N,
169
+ maxVisualDistance: L,
170
+ maxSpeedMultiplier: C,
171
+ opacity: M,
172
+ renderVisual: y
173
+ } = m, I = a ? "width" : "height", T = a ? "height" : "width", S = a ? "left" : "top", E = a ? "clientX" : "clientY", q = (s, v) => a ? s : v, oe = (s) => s[E], j = a ? ["Scroll left", "Scroll right"] : ["Scroll up", "Scroll down"], W = a ? ["◀", "▶"] : ["▲", "▼"], ne = a ? "flex flex-row items-stretch" : "flex flex-col items-stretch", B = Math.max(L, 1), fe = e / o, Y = h, c = Math.max(e - Y * 2, 0), J = fe * c, Q = Math.min(Math.max(We, J || 0), c || We), z = o - e, ie = Math.max(c - Q, 0), ge = z <= 0 || ie <= 0 ? 0 : t / z * ie, he = o > e, Ye = he && l;
174
+ se(() => {
175
+ _.current = t;
176
+ }, [t]), se(() => {
177
+ r || b(!1);
178
+ }, [r]), se(() => {
179
+ const s = Z.current;
180
+ if (!s)
181
+ return;
182
+ const v = a ? "scaleY(1.06)" : "scaleX(1.06)", K = a ? "scaleY(1.12)" : "scaleX(1.12)";
183
+ if (!r) {
184
+ s.style.removeProperty("transform"), s.style.backgroundColor = "#7F7F7F", s.style.removeProperty("transition");
185
+ return;
186
+ }
187
+ if (V) {
188
+ s.style.transform = K, s.style.backgroundColor = "#4F4F4F", s.style.transition = "transform 60ms ease-out";
189
+ return;
190
+ }
191
+ s.style.transition = "transform 80ms ease-out", ee ? (s.style.transform = v, s.style.backgroundColor = "#5F5F5F") : (s.style.removeProperty("transform"), s.style.backgroundColor = "#7F7F7F");
192
+ }, [r, a, V, ee]);
193
+ const Ie = A(() => {
194
+ U.current !== null && (window.clearInterval(U.current), U.current = null), O.current !== null && (window.clearTimeout(O.current), O.current = null);
195
+ }, []), ce = A(() => {
196
+ w.current !== null && (window.cancelAnimationFrame(w.current), w.current = null), H.current = null;
197
+ }, []), ue = A(() => {
198
+ x.current = { ...Be }, le(!1), P.current?.reset(), ce();
199
+ }, [ce]), Ve = A(
200
+ (s) => {
201
+ const v = x.current;
202
+ if (!v.active || v.direction === 0) {
203
+ ce();
200
204
  return;
201
205
  }
202
- if (!V || b <= 0) {
203
- R();
206
+ if (!he || z <= 0) {
207
+ ce();
204
208
  return;
205
209
  }
206
- const Z = P.current ?? l, B = Math.max((l - Z) / 1e3, 0);
207
- if (P.current = l, B <= 0) {
208
- E.current = window.requestAnimationFrame(K);
210
+ const K = H.current ?? s, te = Math.max((s - K) / 1e3, 0);
211
+ if (H.current = s, te <= 0) {
212
+ w.current = window.requestAnimationFrame(Ve);
209
213
  return;
210
214
  }
211
- const Te = (Math.min(L.distance, T) / T) ** 1.1, de = Math.max(e * 0.2, 40), be = Math.max(e * A, 1200), we = de + (be - de) * Te, ge = Y.current, Ie = C(ge + L.direction * we * B, 0, b);
212
- if (Ie === ge) {
213
- R();
215
+ const _e = (Math.min(v.distance, B) / B) ** 1.1, be = Math.max(e * 0.2, 40), Fe = Math.max(e * C, 1200), Le = be + (Fe - be) * _e, Te = _.current, Ce = G(Te + v.direction * Le * te, 0, z);
216
+ if (Ce === Te) {
217
+ ce();
214
218
  return;
215
219
  }
216
- Y.current = Ie, t?.(Ie, ge), E.current = window.requestAnimationFrame(K);
220
+ _.current = Ce, n?.(Ce, Te), w.current = window.requestAnimationFrame(Ve);
217
221
  },
218
- [T, b, t, V, R, A, e]
219
- ), oe = z(() => {
220
- E.current === null && (P.current = null, E.current = window.requestAnimationFrame(K));
221
- }, [K]);
222
- re(() => () => {
223
- X(), R();
224
- }, [X, R]);
225
- const te = z(
226
- (l) => {
227
- u.current = l, ie(l.active), l.active && l.direction !== 0 ? oe() : R();
222
+ [B, z, n, he, ce, C, e]
223
+ ), ze = A(() => {
224
+ w.current === null && (H.current = null, w.current = window.requestAnimationFrame(Ve));
225
+ }, [Ve]);
226
+ se(() => () => {
227
+ Ie(), ce();
228
+ }, [Ie, ce]);
229
+ const et = A(
230
+ (s) => {
231
+ x.current = s, le(s.active), s.active && s.direction !== 0 ? ze() : ce();
228
232
  },
229
- [oe, R]
233
+ [ze, ce]
230
234
  );
231
- re(() => {
232
- W || S();
233
- }, [S, W]), re(() => {
234
- const l = (L) => {
235
- const B = L.detail?.paneId;
236
- B && m && B !== m || S();
235
+ se(() => {
236
+ D || ue();
237
+ }, [ue, D]), se(() => {
238
+ const s = (v) => {
239
+ const te = v.detail?.paneId;
240
+ te && d && te !== d || ue();
237
241
  };
238
- return window.addEventListener(Ee, l), () => {
239
- window.removeEventListener(Ee, l);
242
+ return window.addEventListener(Ne, s), () => {
243
+ window.removeEventListener(Ne, s);
240
244
  };
241
- }, [m, S]), re(() => {
242
- if (!W)
245
+ }, [d, ue]), se(() => {
246
+ if (!D)
243
247
  return;
244
- const l = (L) => {
245
- if (!u.current.active)
248
+ const s = (v) => {
249
+ if (!x.current.active)
246
250
  return;
247
- const Z = L.target;
248
- if (!(Z instanceof Node)) {
249
- S();
251
+ const K = v.target;
252
+ if (!(K instanceof Node)) {
253
+ ue();
250
254
  return;
251
255
  }
252
- ee.current?.getElement()?.contains(Z) || S();
256
+ P.current?.getElement()?.contains(K) || ue();
253
257
  };
254
- return document.addEventListener("pointerdown", l, !0), () => {
255
- document.removeEventListener("pointerdown", l, !0);
258
+ return document.addEventListener("pointerdown", s, !0), () => {
259
+ document.removeEventListener("pointerdown", s, !0);
256
260
  };
257
- }, [S, W]);
258
- const a = (l) => {
259
- if (!V || _ <= 0 || b <= 0)
261
+ }, [ue, D]);
262
+ const Ae = (s) => {
263
+ if (!he || ie <= 0 || z <= 0)
260
264
  return 0;
261
- const L = C(l, 0, _);
262
- return C(L / _ * b, 0, b);
263
- }, G = (l) => {
264
- if (!V || b <= 0)
265
+ const v = G(s, 0, ie);
266
+ return G(v / ie * z, 0, z);
267
+ }, Re = (s) => {
268
+ if (!he || z <= 0)
269
+ return;
270
+ const v = Math.max(Math.round(e / ut), ct), K = _.current, te = G(K + s * v, 0, z);
271
+ te !== K && (_.current = te, n?.(te, K));
272
+ }, Pe = () => {
273
+ Ie();
274
+ }, He = (s) => (v) => {
275
+ Ye && (v.preventDefault(), v.stopPropagation(), ue(), Ie(), Re(s), O.current = window.setTimeout(() => {
276
+ U.current = window.setInterval(() => {
277
+ Re(s);
278
+ }, lt);
279
+ }, at));
280
+ }, tt = (s) => (v) => {
281
+ l && (v.key === "Enter" || v.key === " " || v.key === "Spacebar") && (v.preventDefault(), Re(s));
282
+ }, $e = (s) => {
283
+ if (!he)
284
+ return;
285
+ if (!r) {
286
+ s.preventDefault(), s.stopPropagation();
265
287
  return;
266
- const L = Math.max(Math.round(e / Ue), He), Z = Y.current, B = C(Z + l * L, 0, b);
267
- B !== Z && (Y.current = B, t?.(B, Z));
268
- }, U = () => {
269
- X();
270
- }, ne = (l) => (L) => {
271
- V && (L.preventDefault(), L.stopPropagation(), S(), X(), G(l), D.current = window.setTimeout(() => {
272
- Q.current = window.setInterval(() => {
273
- G(l);
274
- }, Ye);
275
- }, Oe));
276
- }, ue = (l) => (L) => {
277
- (L.key === "Enter" || L.key === " " || L.key === "Spacebar") && (L.preventDefault(), G(l));
278
- }, me = (l) => {
279
- if (!V || "button" in l && l.button !== 0 || l.ctrlKey)
288
+ }
289
+ if ("button" in s && s.button !== 0 || s.ctrlKey)
280
290
  return;
281
- l.stopPropagation(), S();
282
- const L = H;
283
- y(!0), Ae(
284
- l,
285
- ({ deltaX: Z, deltaY: B }) => {
286
- t?.(a(L + (r ? Z : B)), H);
291
+ s.stopPropagation(), ue();
292
+ const v = ge;
293
+ X(!0), b(!0), je(
294
+ s,
295
+ ({ deltaX: K, deltaY: te }) => {
296
+ const ve = q(K, te);
297
+ n?.(Ae(v + ve), ge);
287
298
  },
288
299
  () => {
289
- y(!1);
300
+ X(!1), Z.current && !Z.current.matches(":hover") && b(!1);
290
301
  }
291
302
  );
292
- }, Pe = (l) => {
293
- if (!V || "button" in l && l.button !== 0 || l.ctrlKey)
303
+ }, Xe = (s) => {
304
+ if (!he)
305
+ return;
306
+ if (!i) {
307
+ s.preventDefault(), s.stopPropagation();
308
+ return;
309
+ }
310
+ if ("button" in s && s.button !== 0 || s.ctrlKey)
294
311
  return;
295
- const Z = "touches" in l.nativeEvent ? l.nativeEvent.touches[0] : l.nativeEvent, B = r ? Z.clientX : Z.clientY, pe = l.currentTarget.getBoundingClientRect(), Te = r ? B - pe.left : B - pe.top;
296
- S();
297
- const de = Te - v / 2;
298
- t?.(a(de), H), Ae(l, ({ deltaX: be, deltaY: we }) => {
299
- t?.(a(de + (r ? be : we)), H);
312
+ const K = "touches" in s.nativeEvent ? s.nativeEvent.touches[0] : s.nativeEvent, te = oe(K), ve = s.currentTarget.getBoundingClientRect(), _e = te - (a ? ve.left : ve.top);
313
+ ue();
314
+ const be = _e - Q / 2;
315
+ n?.(Ae(be), ge), je(s, ({ deltaX: Fe, deltaY: Le }) => {
316
+ const Te = q(Fe, Le);
317
+ n?.(Ae(be + Te), ge);
300
318
  });
301
- }, Ce = O(() => C((w ? 1 : 0.8) * x, 0, 1), [w, x]), Ne = O(() => {
302
- const L = `calc(50% - ${q / 2}px + ${i}px)`;
319
+ }, nt = xe(() => G((ae ? 1 : 0.8) * M, 0, 1), [ae, M]), rt = xe(() => {
320
+ const v = `calc(50% - ${f / 2}px + ${g}px)`;
303
321
  return {
304
- left: se,
305
- top: L
322
+ left: F,
323
+ top: v
306
324
  };
307
- }, [se, i, q]);
308
- return /* @__PURE__ */ xe(
325
+ }, [F, g, f]), Ue = (s, v, K) => /* @__PURE__ */ $(
326
+ "button",
327
+ {
328
+ type: "button",
329
+ className: "flex items-center justify-center text-[#313131] text-xs transition-colors focus:outline-none focus-visible:ring-2 focus-visible:ring-[#60a5fa] focus-visible:ring-offset-1 disabled:cursor-not-allowed disabled:opacity-50",
330
+ style: {
331
+ [I]: Y,
332
+ [T]: h,
333
+ backgroundColor: "#E0E0E0"
334
+ },
335
+ "aria-label": v,
336
+ onMouseDown: He(s),
337
+ onTouchStart: He(s),
338
+ onMouseUp: Pe,
339
+ onMouseLeave: Pe,
340
+ onTouchEnd: Pe,
341
+ onTouchCancel: Pe,
342
+ onKeyDown: tt(s),
343
+ "aria-disabled": !l,
344
+ disabled: !Ye,
345
+ children: /* @__PURE__ */ $("span", { "aria-hidden": "true", children: K })
346
+ }
347
+ );
348
+ return /* @__PURE__ */ Se(
309
349
  "div",
310
350
  {
311
- className: he(
351
+ className: we(
312
352
  "group relative cursor-default select-none",
313
- r ? "flex flex-row items-stretch" : "flex flex-col items-stretch",
314
- s
353
+ ne,
354
+ u
315
355
  ),
316
356
  style: {
317
- [r ? "width" : "height"]: e,
318
- [r ? "height" : "width"]: o,
357
+ [I]: e,
358
+ [T]: h,
319
359
  backgroundColor: "white",
320
360
  userSelect: "none",
321
361
  position: "relative"
322
362
  },
323
363
  role: "scrollbar",
324
364
  tabIndex: -1,
325
- "aria-controls": m,
326
- "aria-valuenow": n,
365
+ "aria-controls": d,
366
+ "aria-valuenow": t,
327
367
  "aria-valuemin": 0,
328
- "aria-valuemax": b,
329
- "aria-orientation": r ? "horizontal" : "vertical",
368
+ "aria-valuemax": z,
369
+ "aria-orientation": a ? "horizontal" : "vertical",
330
370
  children: [
331
- !r && V && W && /* @__PURE__ */ j(
332
- Re,
371
+ !a && he && D && /* @__PURE__ */ $(
372
+ Qe,
333
373
  {
334
- ref: ee,
335
- className: he(
374
+ ref: P,
375
+ className: we(
336
376
  "pointer-events-auto absolute transition-opacity duration-150",
337
- $
377
+ N
338
378
  ),
339
- size: q,
340
- maxVisualDistance: T,
341
- style: Ne,
342
- opacity: Ce,
343
- onDragChange: te
379
+ size: f,
380
+ maxVisualDistance: B,
381
+ style: rt,
382
+ opacity: nt,
383
+ renderVisual: y,
384
+ onDragChange: et
344
385
  }
345
386
  ),
346
- /* @__PURE__ */ j(
347
- "button",
348
- {
349
- type: "button",
350
- className: "flex items-center justify-center text-xs text-[#313131] transition-colors focus:outline-none focus-visible:ring-2 focus-visible:ring-[#60a5fa] focus-visible:ring-offset-1 disabled:cursor-not-allowed disabled:opacity-50",
351
- style: {
352
- [r ? "width" : "height"]: h,
353
- [r ? "height" : "width"]: o,
354
- backgroundColor: "#E0E0E0"
355
- },
356
- "aria-label": r ? "Scroll left" : "Scroll up",
357
- onMouseDown: ne(-1),
358
- onTouchStart: ne(-1),
359
- onMouseUp: U,
360
- onMouseLeave: U,
361
- onTouchEnd: U,
362
- onTouchCancel: U,
363
- onKeyDown: ue(-1),
364
- disabled: !V,
365
- children: /* @__PURE__ */ j("span", { "aria-hidden": "true", children: r ? "◀" : "▲" })
366
- }
367
- ),
368
- /* @__PURE__ */ j(
387
+ Ue(-1, j[0], W[0]),
388
+ /* @__PURE__ */ $(
369
389
  "div",
370
390
  {
371
391
  className: "relative flex-1",
372
392
  style: {
373
393
  backgroundColor: "#F5F5F5",
374
- borderRadius: o / 2
394
+ borderRadius: h / 2
375
395
  },
376
- onMouseDown: Pe,
377
- onTouchStart: Pe,
378
- children: c > e && // スクロールバーのつまみの当たり判定を広げるためのラッパー
379
- /* @__PURE__ */ j(
396
+ onMouseDown: Xe,
397
+ onTouchStart: Xe,
398
+ "aria-disabled": !i,
399
+ children: he && // スクロールバーのつまみの当たり判定を広げるためのラッパー
400
+ /* @__PURE__ */ $(
380
401
  "div",
381
402
  {
382
403
  className: "group absolute",
383
404
  style: {
384
- [r ? "width" : "height"]: v,
385
- [r ? "left" : "top"]: H,
386
- ...r ? { top: 0, bottom: 0 } : { left: 0, right: 0 }
405
+ [I]: Q,
406
+ [S]: ge,
407
+ ...a ? { top: 0, bottom: 0 } : { left: 0, right: 0 }
387
408
  },
388
- onMouseDown: me,
389
- onTouchStart: me,
409
+ onMouseDown: $e,
410
+ onTouchStart: $e,
390
411
  role: "slider",
391
- "aria-orientation": r ? "horizontal" : "vertical",
392
- "aria-valuenow": n,
412
+ "aria-orientation": a ? "horizontal" : "vertical",
413
+ "aria-valuenow": t,
393
414
  "aria-valuemin": 0,
394
- "aria-valuemax": b,
395
- tabIndex: 0,
396
- children: /* @__PURE__ */ j(
415
+ "aria-valuemax": z,
416
+ "aria-disabled": !r,
417
+ tabIndex: r ? 0 : -1,
418
+ children: /* @__PURE__ */ $(
397
419
  "div",
398
420
  {
399
- ref: ae,
400
- className: he(
421
+ ref: Z,
422
+ className: we(
401
423
  "absolute",
402
- r ? `inset-x-0 inset-y-[1.5px] group-hover:inset-y-[-0.5px] ${g ? "inset-y-[-2px]" : "group-active:inset-y-[-2px]"}` : `inset-x-[1.5px] inset-y-0 group-hover:inset-x-[-0.5px] ${g ? "inset-x-[-2px]" : "group-active:inset-x-[-2px]"}`
424
+ a ? `inset-x-0 inset-y-[1.5px] group-hover:inset-y-[-0.5px] ${V ? "-inset-y-0.5" : "group-active:-inset-y-0.5"}` : `inset-x-[1.5px] inset-y-0 group-hover:inset-x-[-0.5px] ${V ? "-inset-x-0.5" : "group-active:-inset-x-0.5"}`
403
425
  ),
404
426
  style: {
405
427
  backgroundColor: "#7F7F7F",
406
- borderRadius: o - 1,
407
- ...r ? {
428
+ borderRadius: h - 1,
429
+ cursor: r ? "pointer" : "default",
430
+ ...a ? {
408
431
  left: 0,
409
432
  right: 0,
410
- top: g ? -2 : 1.5,
411
- bottom: g ? -2 : 1.5
433
+ top: 1.5,
434
+ bottom: 1.5
412
435
  } : {
413
436
  top: 0,
414
437
  bottom: 0,
415
- left: g ? -2 : 1.5,
416
- right: g ? -2 : 1.5
438
+ left: 1.5,
439
+ right: 1.5
417
440
  }
418
441
  },
419
- onMouseEnter: (l) => {
420
- r ? (l.currentTarget.style.top = "-0.5px", l.currentTarget.style.bottom = "-0.5px") : (l.currentTarget.style.left = "-0.5px", l.currentTarget.style.right = "-0.5px"), g || (l.currentTarget.style.backgroundColor = "#5F5F5F");
442
+ onMouseEnter: () => {
443
+ r && b(!0);
421
444
  },
422
- onMouseLeave: (l) => {
423
- r ? (l.currentTarget.style.top = g ? "-2px" : "1.5px", l.currentTarget.style.bottom = g ? "-2px" : "1.5px") : (l.currentTarget.style.left = g ? "-2px" : "1.5px", l.currentTarget.style.right = g ? "-2px" : "1.5px"), g || (l.currentTarget.style.backgroundColor = "#7F7F7F");
445
+ onMouseLeave: () => {
446
+ r && b(!1);
424
447
  }
425
448
  }
426
449
  )
@@ -428,209 +451,272 @@ const Ae = (c, e, n) => {
428
451
  )
429
452
  }
430
453
  ),
431
- /* @__PURE__ */ j(
432
- "button",
433
- {
434
- type: "button",
435
- className: "flex items-center justify-center text-xs text-[#313131] transition-colors focus:outline-none focus-visible:ring-2 focus-visible:ring-[#60a5fa] focus-visible:ring-offset-1 disabled:cursor-not-allowed disabled:opacity-50",
436
- style: {
437
- [r ? "width" : "height"]: h,
438
- [r ? "height" : "width"]: o,
439
- backgroundColor: "#E0E0E0"
440
- },
441
- "aria-label": r ? "Scroll right" : "Scroll down",
442
- onMouseDown: ne(1),
443
- onTouchStart: ne(1),
444
- onMouseUp: U,
445
- onMouseLeave: U,
446
- onTouchEnd: U,
447
- onTouchCancel: U,
448
- onKeyDown: ue(1),
449
- disabled: !V,
450
- children: /* @__PURE__ */ j("span", { "aria-hidden": "true", children: r ? "▶" : "▼" })
451
- }
452
- )
454
+ Ue(1, j[1], W[1])
453
455
  ]
454
456
  }
455
457
  );
456
- }, fe = {
458
+ }, re = {
459
+ debug(o, ...e) {
460
+ typeof window < "u" && window.localStorage?.getItem("debug") === "true" && console.debug(`[VirtualScroll] ${o}`, ...e);
461
+ },
462
+ warn(o, ...e) {
463
+ console.warn(`[VirtualScroll] ${o}`, ...e);
464
+ },
465
+ error(o, ...e) {
466
+ console.error(`[VirtualScroll] ${o}`, ...e);
467
+ }
468
+ }, ye = {
457
469
  maxVelocity: 6,
458
470
  minVelocity: 0.02,
459
471
  deceleration: 25e-4,
460
472
  velocitySampleWindow: 90,
461
473
  startVelocityThreshold: 0.04
462
- }, Be = Ve(({ children: c, contentSize: e, viewportSize: n, scrollBarWidth: t = 12, onScroll: r, className: o, style: s, background: m, tapScrollCircleOptions: d, inertiaOptions: f, itemCount: g }, y) => {
463
- const w = N(0), [ie, ae] = ze((i) => i + 1, 0), Y = N(null), Q = N(null), D = N({
474
+ }, Me = (o, e, t) => {
475
+ for (const [n, r, i] of e)
476
+ t === "add" ? o.addEventListener(n, r, i) : o.removeEventListener(n, r, i);
477
+ }, gt = ke(({ children: o, contentSize: e, viewportSize: t, scrollBarWidth: n = 12, enableThumbDrag: r = !0, enableTrackClick: i = !0, enableArrowButtons: l = !0, enablePointerDrag: a = !0, onScroll: h, className: u, style: d, background: p, tapScrollCircleOptions: R, inertiaOptions: V, itemCount: X }, ee) => {
478
+ const b = k(0), [ae, le] = st((f) => f + 1, 0), Z = k(null), _ = k(null), U = k({
464
479
  frame: null,
465
480
  velocity: 0,
466
481
  lastTimestamp: null
467
- }), u = O(
482
+ }), O = xe(
468
483
  () => ({
469
- maxVelocity: f?.maxVelocity ?? fe.maxVelocity,
470
- minVelocity: f?.minVelocity ?? fe.minVelocity,
471
- deceleration: f?.deceleration ?? fe.deceleration,
472
- velocitySampleWindow: f?.velocitySampleWindow ?? fe.velocitySampleWindow,
473
- startVelocityThreshold: f?.startVelocityThreshold ?? fe.startVelocityThreshold
484
+ maxVelocity: V?.maxVelocity ?? ye.maxVelocity,
485
+ minVelocity: V?.minVelocity ?? ye.minVelocity,
486
+ deceleration: V?.deceleration ?? ye.deceleration,
487
+ velocitySampleWindow: V?.velocitySampleWindow ?? ye.velocitySampleWindow,
488
+ startVelocityThreshold: V?.startVelocityThreshold ?? ye.startVelocityThreshold
474
489
  }),
475
- [f]
490
+ [V]
476
491
  );
477
- J.debug("[ScrollPane] ScrollPane rendered", { contentSize: e, viewportSize: n, scrollBarWidth: t, className: o, style: s, tapScrollCircleOptions: d, inertiaOptions: f });
478
- const ee = N({ contentSize: e, viewportSize: n }), E = O(() => e > n, [e, n]), P = z(
479
- (i) => {
480
- const { contentSize: $, viewportSize: k } = ee.current, A = $ > k, x = w.current;
481
- if (J.debug("[ScrollPane] scrollTo called", { newPosition: i, contentSize: $, viewportSize: k, currentIsScrollable: A, prevPosition: x }), !A) {
482
- w.current !== 0 && (w.current = 0, r?.(0, x));
492
+ re.debug("[ScrollPane] ScrollPane rendered", { contentSize: e, viewportSize: t, scrollBarWidth: n, className: u, style: d, tapScrollCircleOptions: R, inertiaOptions: V, enablePointerDrag: a });
493
+ const x = k({ contentSize: e, viewportSize: t }), P = xe(() => e > t, [e, t]), w = A(
494
+ (f) => {
495
+ const { contentSize: F, viewportSize: g } = x.current, N = F > g, L = b.current;
496
+ if (re.debug("[ScrollPane] scrollTo called", { newPosition: f, contentSize: F, viewportSize: g, currentIsScrollable: N, prevPosition: L }), !N) {
497
+ b.current !== 0 && (b.current = 0, h?.(0, L));
483
498
  return;
484
499
  }
485
- const T = typeof i == "function" ? i(w.current) : i, M = C(T, 0, $ - k);
486
- w.current !== M && (w.current = M, r?.(M, x));
500
+ const C = typeof f == "function" ? f(b.current) : f, M = G(C, 0, F - g);
501
+ b.current !== M && (b.current = M, h?.(M, L));
487
502
  },
488
- [r]
489
- ), F = z(() => {
490
- const i = D.current;
491
- i.frame !== null && cancelAnimationFrame(i.frame), i.frame = null, i.velocity = 0, i.lastTimestamp = null;
492
- }, []), W = z(
493
- (i) => {
494
- if (!E)
503
+ [h]
504
+ ), H = A(() => {
505
+ const f = U.current;
506
+ f.frame !== null && cancelAnimationFrame(f.frame), f.frame = null, f.velocity = 0, f.lastTimestamp = null;
507
+ }, []), m = A(
508
+ (f) => {
509
+ if (!P)
495
510
  return;
496
- const { maxVelocity: $, minVelocity: k, deceleration: A, startVelocityThreshold: x } = u, T = C(i, -$, $);
497
- if (Math.abs(T) < x)
511
+ const { maxVelocity: F, minVelocity: g, deceleration: N, startVelocityThreshold: L } = O, C = G(f, -F, F);
512
+ if (Math.abs(C) < L)
498
513
  return;
499
- F(), D.current.velocity = T, D.current.lastTimestamp = null;
500
- const M = (h) => {
501
- const p = D.current;
502
- if (p.lastTimestamp === null) {
503
- p.lastTimestamp = h, p.frame = requestAnimationFrame(M);
514
+ H(), U.current.velocity = C, U.current.lastTimestamp = null;
515
+ const M = (y) => {
516
+ const I = U.current;
517
+ if (I.lastTimestamp === null) {
518
+ I.lastTimestamp = y, I.frame = requestAnimationFrame(M);
504
519
  return;
505
520
  }
506
- const I = h - p.lastTimestamp;
507
- if (p.lastTimestamp = h, I <= 0) {
508
- p.frame = requestAnimationFrame(M);
521
+ const T = y - I.lastTimestamp;
522
+ if (I.lastTimestamp = y, T <= 0) {
523
+ I.frame = requestAnimationFrame(M);
509
524
  return;
510
525
  }
511
- const v = p.velocity;
512
- let b = v;
513
- const _ = A * I;
514
- v > 0 ? b = Math.max(0, v - _) : v < 0 && (b = Math.min(0, v + _));
515
- const V = (v + b) / 2 * I, X = w.current;
516
- V !== 0 && P((a) => a + V);
517
- const R = w.current, { contentSize: S, viewportSize: K } = ee.current, oe = Math.max(S - K, 0);
518
- p.velocity = b;
519
- const te = R === X || R <= 0 && b <= 0 || R >= oe && b >= 0;
520
- if (Math.abs(b) < k || te) {
521
- F();
526
+ const S = I.velocity;
527
+ let E = S;
528
+ const q = N * T;
529
+ S > 0 ? E = Math.max(0, S - q) : S < 0 && (E = Math.min(0, S + q));
530
+ const j = (S + E) / 2 * T, W = b.current;
531
+ j !== 0 && w((J) => J + j);
532
+ const ne = b.current, { contentSize: B, viewportSize: fe } = x.current, Y = Math.max(B - fe, 0);
533
+ I.velocity = E;
534
+ const c = ne === W || ne <= 0 && E <= 0 || ne >= Y && E >= 0;
535
+ if (Math.abs(E) < g || c) {
536
+ H();
522
537
  return;
523
538
  }
524
- p.frame = requestAnimationFrame(M);
539
+ I.frame = requestAnimationFrame(M);
525
540
  };
526
- D.current.frame = requestAnimationFrame(M);
541
+ U.current.frame = requestAnimationFrame(M);
527
542
  },
528
- [E, u, P, F]
543
+ [P, O, w, H]
529
544
  );
530
- ve(() => {
531
- ee.current = { contentSize: e, viewportSize: n };
532
- }, [e, n]), ve(() => {
533
- if (E) {
534
- J.debug("[ScrollPane] Adjusting scroll position due to content or viewport size change", { contentSize: e, viewportSize: n, scrollPosition: w.current });
535
- const i = C(e - n, 0, e);
536
- w.current > i && P(i);
545
+ Ee(() => {
546
+ x.current = { contentSize: e, viewportSize: t };
547
+ }, [e, t]), Ee(() => {
548
+ if (P) {
549
+ re.debug("[ScrollPane] Adjusting scroll position due to content or viewport size change", { contentSize: e, viewportSize: t, scrollPosition: b.current });
550
+ const f = G(e - t, 0, e);
551
+ b.current > f && w(f);
537
552
  } else
538
- P(0);
539
- }, [E, P, e, n]), re(() => {
540
- const i = (k) => {
541
- if (!E)
553
+ w(0);
554
+ }, [P, w, e, t]), se(() => {
555
+ const f = (g) => {
556
+ if (!P)
542
557
  return;
543
- k.preventDefault(), F();
544
- let A = k.deltaY;
545
- k.deltaMode === 1 ? A *= 16 : k.deltaMode === 2 && (A *= n), J.debug("[ScrollPane] wheel event", { deltaY: A, scrollPosition: w.current }), P((x) => x + A);
546
- }, $ = Y.current;
547
- return $ && $.addEventListener("wheel", i, { passive: !1 }), () => {
548
- $ && $.removeEventListener("wheel", i);
558
+ g.preventDefault(), H();
559
+ let N = g.deltaY;
560
+ g.deltaMode === 1 ? N *= 16 : g.deltaMode === 2 && (N *= t), re.debug("[ScrollPane] wheel event", { deltaY: N, scrollPosition: b.current }), w((L) => L + N);
561
+ }, F = Z.current;
562
+ return F && F.addEventListener("wheel", f, { passive: !1 }), () => {
563
+ F && F.removeEventListener("wheel", f);
549
564
  };
550
- }, [E, P, F, n]), Me(
551
- y,
565
+ }, [P, w, H, t]), Oe(
566
+ ee,
552
567
  () => ({
553
- scrollTo: P,
554
- getScrollPosition: () => w.current,
568
+ scrollTo: w,
569
+ getScrollPosition: () => b.current,
555
570
  getContentSize: () => e,
556
- getViewportSize: () => n
571
+ getViewportSize: () => t
557
572
  }),
558
- [P, e, n]
573
+ [w, e, t]
559
574
  );
560
- const q = ke(), se = O(() => /* @__PURE__ */ xe("div", { ref: Y, className: he("flex", o), style: s, children: [
561
- /* @__PURE__ */ xe("div", { ref: Q, className: "relative h-full flex-1 overflow-hidden", style: { height: n, touchAction: "none" }, id: q, children: [
562
- m,
563
- c(w.current)
564
- ] }),
565
- E && /* @__PURE__ */ j(
566
- Ke,
575
+ const D = ot();
576
+ return se(() => {
577
+ const f = _.current;
578
+ if (!f)
579
+ return;
580
+ if (!a) {
581
+ H();
582
+ return;
583
+ }
584
+ const F = 6;
585
+ let g = null, N = 0, L = 0, C = !1, M = !1, y = null, I = [];
586
+ const T = () => {
587
+ g = null, N = 0, L = 0, C = !1, I = [];
588
+ }, S = (c) => {
589
+ const J = performance.now();
590
+ I.push({ clientY: c, time: J }), I = I.filter((Q) => J - Q.time <= O.velocitySampleWindow);
591
+ }, E = (c) => c instanceof HTMLElement && c.closest("[data-scrollpane-ignore-drag='true']") !== null, q = (c) => {
592
+ M && (c.preventDefault(), c.stopPropagation(), M = !1);
593
+ }, oe = (c) => {
594
+ C || (C = !0, M = !0, f.hasPointerCapture(c.pointerId) || f.setPointerCapture(c.pointerId), S(c.clientY));
595
+ }, j = (c) => {
596
+ if (g !== c.pointerId || !C && (Math.abs(c.clientY - N) < F || (oe(c), !C)))
597
+ return;
598
+ S(c.clientY);
599
+ const J = c.clientY - N, Q = L - J;
600
+ w(Q), c.cancelable && c.preventDefault();
601
+ }, W = (c) => {
602
+ if (g !== c.pointerId)
603
+ return;
604
+ C && M && c.cancelable && (c.preventDefault(), c.stopPropagation()), f.hasPointerCapture(c.pointerId) && f.releasePointerCapture(c.pointerId);
605
+ let J = 0;
606
+ if (C && I.length >= 2) {
607
+ const Q = I[I.length - 1], z = I.find((ie) => Q.time - ie.time <= O.velocitySampleWindow) ?? I[0];
608
+ if (Q && z && Q.time !== z.time) {
609
+ const ie = Q.clientY - z.clientY, ge = Q.time - z.time;
610
+ J = -(ie / ge);
611
+ }
612
+ }
613
+ T(), y !== null && window.clearTimeout(y), M && (y = window.setTimeout(() => {
614
+ M = !1, y = null;
615
+ }, 0)), Math.abs(J) >= O.startVelocityThreshold && m(J);
616
+ }, ne = (c) => {
617
+ P && (c.button !== 0 && c.pointerType === "mouse" || c.ctrlKey || c.metaKey || c.altKey || E(c.target) || (window.dispatchEvent(new CustomEvent(Ne, { detail: { paneId: D } })), H(), g = c.pointerId, N = c.clientY, L = b.current, C = !1, M = !1, I = []));
618
+ }, B = (c) => {
619
+ g === c.pointerId && (M = !1, f.hasPointerCapture(c.pointerId) && f.releasePointerCapture(c.pointerId), y !== null && (window.clearTimeout(y), y = null), T());
620
+ }, fe = [
621
+ ["click", q, !0],
622
+ ["pointerdown", ne, { passive: !1 }],
623
+ ["pointermove", j, { passive: !1 }],
624
+ ["pointerup", W, void 0],
625
+ ["pointercancel", B, void 0]
626
+ ], Y = [
627
+ ["pointermove", j, { passive: !1 }],
628
+ ["pointerup", W, void 0],
629
+ ["pointercancel", B, void 0]
630
+ ];
631
+ return Me(f, fe, "add"), Me(window, Y, "add"), () => {
632
+ Me(f, fe, "remove"), Me(window, Y, "remove"), g !== null && f.hasPointerCapture(g) && f.releasePointerCapture(g), y !== null && window.clearTimeout(y), H();
633
+ };
634
+ }, [a, D, P, O, w, m, H]), /* @__PURE__ */ Se("div", { ref: Z, className: we("flex", u), style: d, children: [
635
+ /* @__PURE__ */ Se(
636
+ "div",
637
+ {
638
+ ref: _,
639
+ className: "relative h-full flex-1 overflow-hidden",
640
+ style: { height: t, ...a ? { touchAction: "none" } : {} },
641
+ id: D,
642
+ children: [
643
+ p,
644
+ o(b.current)
645
+ ]
646
+ }
647
+ ),
648
+ P && /* @__PURE__ */ $(
649
+ pt,
567
650
  {
568
651
  contentSize: e,
569
- viewportSize: n,
570
- scrollPosition: w.current,
571
- onScroll: P,
572
- scrollBarWidth: t,
573
- ariaControls: q,
574
- tapScrollCircleOptions: d,
575
- itemCount: g
652
+ viewportSize: t,
653
+ scrollPosition: b.current,
654
+ onScroll: w,
655
+ enableThumbDrag: r,
656
+ enableTrackClick: i,
657
+ enableArrowButtons: l,
658
+ scrollBarWidth: n,
659
+ ariaControls: D,
660
+ tapScrollCircleOptions: R,
661
+ itemCount: X
576
662
  }
577
663
  )
578
- ] }), [c, e, n, t, o, s, E, P, q, m, d, g]);
579
- return re(() => {
580
- const i = Q.current;
581
- if (!i)
582
- return;
583
- const $ = 6, k = "input, textarea, select, button, a[href], [role='button']";
584
- let A = null, x = 0, T = 0, M = !1, h = !1, p = !1, I = null, v = [];
585
- const b = () => {
586
- A = null, x = 0, T = 0, M = !1, h = !1, v = [];
587
- }, _ = (a) => {
588
- const G = performance.now();
589
- v.push({ clientY: a, time: G }), v = v.filter((U) => G - U.time <= u.velocitySampleWindow);
590
- }, H = (a) => a instanceof HTMLElement ? a.closest("[data-scrollpane-ignore-drag='true']") !== null : !1, V = (a) => a instanceof HTMLElement ? a.closest(k) !== null : !1, X = (a) => {
591
- p && (a.preventDefault(), a.stopPropagation(), p = !1);
592
- }, R = (a) => {
593
- M || (M = !0, h = !1, p = !0, i.hasPointerCapture(a.pointerId) || i.setPointerCapture(a.pointerId), _(a.clientY));
594
- }, S = (a) => {
595
- if (A !== a.pointerId)
596
- return;
597
- if (!M) {
598
- const ne = Math.abs(a.clientY - x);
599
- if (h && ne < $)
600
- return;
601
- R(a);
664
+ ] });
665
+ }), Ge = (o, e, t) => Math.min(Math.max(o, e), t), Mt = ({ dragState: o, normalizedDistance: e, sizeScale: t, size: n }) => {
666
+ const r = Math.max(n / 2, 1), i = 1 + e * 0.65, l = Math.max(0.65, 1 - e * 0.25), a = o.direction * e * 26 * t, h = 0.8 + e * 0.18, u = 3 * t, d = 6 * t, p = 22 * t, R = Math.abs(a) + d, V = a > 0 ? u : -Math.abs(a) - u, X = Math.max(2.5, 3 * t), ee = Ge(o.offsetX, -r, r), b = Ge(o.offsetY, -r, r), ae = r * 0.35, le = ee / r * ae, Z = b / r * ae, _ = le * 0.45, U = Z * 0.45, O = Math.max(p * 0.38, 6), x = 0.65 + e * 0.2, P = o.active;
667
+ return /* @__PURE__ */ Se(Je, { children: [
668
+ /* @__PURE__ */ $(
669
+ "div",
670
+ {
671
+ className: "absolute inset-0 rounded-full border border-white/40 bg-linear-to-br from-[#1d4ed8]/60 via-[#60a5fa]/55 to-[#bfdbfe]/40 shadow-md",
672
+ style: {
673
+ transform: `scale(${l}, ${i})`,
674
+ transition: P ? "40ms transform ease-out" : "200ms ease transform"
675
+ }
602
676
  }
603
- if (!M)
604
- return;
605
- _(a.clientY);
606
- const G = a.clientY - x, U = T - G;
607
- P(U), a.cancelable && a.preventDefault();
608
- }, K = (a) => {
609
- if (A !== a.pointerId)
610
- return;
611
- M && p && a.cancelable && (a.preventDefault(), a.stopPropagation()), i.hasPointerCapture(a.pointerId) && i.releasePointerCapture(a.pointerId);
612
- let G = 0;
613
- if (M && v.length >= 2) {
614
- const U = v[v.length - 1], ne = v.find((ue) => U.time - ue.time <= u.velocitySampleWindow) ?? v[0];
615
- if (U && ne && U.time !== ne.time) {
616
- const ue = U.clientY - ne.clientY, me = U.time - ne.time;
617
- G = -(ue / me);
677
+ ),
678
+ /* @__PURE__ */ $(
679
+ "div",
680
+ {
681
+ className: "absolute top-1/2 left-1/2 rounded-full border border-white/50 bg-white/85",
682
+ style: {
683
+ width: p,
684
+ height: p,
685
+ transform: `translate(calc(-50% + ${le}px), calc(-50% + ${Z}px)) scale(${l}, ${h * i})`,
686
+ transition: P ? "70ms transform ease-out" : "200ms ease transform"
618
687
  }
619
688
  }
620
- b(), I !== null && window.clearTimeout(I), p && (I = window.setTimeout(() => {
621
- p = !1, I = null;
622
- }, 0)), Math.abs(G) >= u.startVelocityThreshold && W(G);
623
- }, oe = (a) => {
624
- E && (a.button !== 0 && a.pointerType === "mouse" || a.ctrlKey || a.metaKey || a.altKey || H(a.target) || (window.dispatchEvent(new CustomEvent(Ee, { detail: { paneId: q } })), F(), A = a.pointerId, x = a.clientY, T = w.current, h = V(a.target), M = !1, p = !1, v = [], h || (p = !0, R(a), _(a.clientY), a.cancelable && a.preventDefault())));
625
- }, te = (a) => {
626
- A === a.pointerId && (p = !1, i.hasPointerCapture(a.pointerId) && i.releasePointerCapture(a.pointerId), I !== null && (window.clearTimeout(I), I = null), b());
627
- };
628
- return i.addEventListener("click", X, !0), i.addEventListener("pointerdown", oe, { passive: !1 }), i.addEventListener("pointermove", S, { passive: !1 }), i.addEventListener("pointerup", K), i.addEventListener("pointercancel", te), window.addEventListener("pointermove", S, { passive: !1 }), window.addEventListener("pointerup", K), window.addEventListener("pointercancel", te), () => {
629
- i.removeEventListener("click", X, !0), i.removeEventListener("pointerdown", oe), i.removeEventListener("pointermove", S), i.removeEventListener("pointerup", K), i.removeEventListener("pointercancel", te), window.removeEventListener("pointermove", S), window.removeEventListener("pointerup", K), window.removeEventListener("pointercancel", te), A !== null && i.hasPointerCapture(A) && i.releasePointerCapture(A), I !== null && window.clearTimeout(I), F();
630
- };
631
- }, [q, E, u, P, W, F]), se;
632
- });
633
- class We {
689
+ ),
690
+ /* @__PURE__ */ $(
691
+ "div",
692
+ {
693
+ className: "absolute top-1/2 left-1/2 rounded-full bg-white/80",
694
+ style: {
695
+ width: O,
696
+ height: O,
697
+ transform: `translate(calc(-50% + ${_}px), calc(-50% + ${U}px)) scale(${l}, ${i})`,
698
+ opacity: x,
699
+ boxShadow: "0 0 8px rgba(255,255,255,0.45)",
700
+ transition: P ? "120ms opacity 150ms, 120ms transform ease-out ease-out" : "220ms ease transform, 240ms opacity ease"
701
+ }
702
+ }
703
+ ),
704
+ /* @__PURE__ */ $(
705
+ "div",
706
+ {
707
+ className: "absolute top-1/2 left-1/2 rounded-full bg-white/50",
708
+ style: {
709
+ width: X,
710
+ height: R,
711
+ transform: `translate(-50%, ${V}px)`,
712
+ opacity: e,
713
+ transition: P ? "40ms height, 60ms opacity ease-out ease-out" : "200ms ease height, 120ms ease opacity"
714
+ }
715
+ }
716
+ )
717
+ ] });
718
+ };
719
+ class xt {
634
720
  /**
635
721
  * @private
636
722
  * @property {Map<number, number>} tree - The Map storing the Fenwick tree structure, specifically the sums of deltas. It is 1-indexed.
@@ -670,8 +756,8 @@ class We {
670
756
  * @param {number | ((index: number) => number)} valueOrFn - The value for all elements, or a function to generate values.
671
757
  * @param {{ sampleRange?: { from: number; to: number }, materialize?: boolean }} [options] - Optional settings for initialization.
672
758
  */
673
- constructor(e, n, t) {
674
- this.reset(e, n, t);
759
+ constructor(e, t, n) {
760
+ this.reset(e, t, n);
675
761
  }
676
762
  /**
677
763
  * @method reset
@@ -681,26 +767,26 @@ class We {
681
767
  * @param {number | ((index: number) => number)} valueOrFn - The value for all elements, or a function to generate values.
682
768
  * @param {{ sampleRange?: { from: number; to: number }, materialize?: boolean }} [options] - Optional settings for initialization.
683
769
  */
684
- reset(e, n, t) {
685
- if (this.size = e, this.tree = /* @__PURE__ */ new Map(), this.deltas = /* @__PURE__ */ new Map(), this.total = void 0, typeof n == "function") {
686
- if (this.valueFn = n, this.size > 0) {
687
- const o = t?.sampleRange ?? {
770
+ reset(e, t, n) {
771
+ if (this.size = e, this.tree = /* @__PURE__ */ new Map(), this.deltas = /* @__PURE__ */ new Map(), this.total = void 0, typeof t == "function") {
772
+ if (this.valueFn = t, this.size > 0) {
773
+ const i = n?.sampleRange ?? {
688
774
  from: 0,
689
775
  to: Math.min(99, this.size - 1)
690
- }, { mode: s, materializedValues: m } = this._calculateMode(o.from, o.to);
691
- if (this.baseValue = s, t?.materialize)
692
- for (let d = 0; d < m.length; d++) {
693
- const f = m[d], g = o.from + d;
694
- if (g >= this.size)
776
+ }, { mode: l, materializedValues: a } = this._calculateMode(i.from, i.to);
777
+ if (this.baseValue = l, n?.materialize)
778
+ for (let h = 0; h < a.length; h++) {
779
+ const u = a[h], d = i.from + h;
780
+ if (d >= this.size)
695
781
  break;
696
- const y = f - this.baseValue;
697
- this.deltas.set(g, y), this._updateTree(g, y);
782
+ const p = u - this.baseValue;
783
+ this.deltas.set(d, p), this._updateTree(d, p);
698
784
  }
699
785
  } else
700
786
  this.baseValue = 0;
701
787
  this.total = this.getTotal();
702
788
  } else
703
- this.valueFn = void 0, this.baseValue = n, this.total = this.baseValue * this.size;
789
+ this.valueFn = void 0, this.baseValue = t, this.total = this.baseValue * this.size;
704
790
  }
705
791
  /**
706
792
  * @method setValueFn
@@ -720,33 +806,33 @@ class We {
720
806
  * @param {number} to - The ending index of the range (inclusive).
721
807
  * @returns {{ mode: number; materializedValues: number[] }} An object containing the calculated mode and the array of generated values.
722
808
  */
723
- _calculateMode(e, n) {
809
+ _calculateMode(e, t) {
724
810
  if (!this.valueFn)
725
811
  return { mode: 0, materializedValues: [] };
726
- const t = [];
727
- for (let f = e; f <= n && !(f >= this.size); f++)
728
- t.push(this.valueFn(f));
729
- const r = [...t];
730
- if (t.length === 0)
812
+ const n = [];
813
+ for (let u = e; u <= t && !(u >= this.size); u++)
814
+ n.push(this.valueFn(u));
815
+ const r = [...n];
816
+ if (n.length === 0)
731
817
  return { mode: 0, materializedValues: [] };
732
- t.sort((f, g) => f - g);
733
- const o = Math.floor(t.length / 2);
734
- let s;
735
- t.length % 2 === 0 ? s = Math.floor((t[o - 1] + t[o]) / 2) : s = t[o];
736
- const m = /* @__PURE__ */ new Map();
737
- let d = 0;
738
- for (const f of t) {
739
- const g = (m.get(f) ?? 0) + 1;
740
- m.set(f, g), g > d && (d = g);
818
+ n.sort((u, d) => u - d);
819
+ const i = Math.floor(n.length / 2);
820
+ let l;
821
+ n.length % 2 === 0 ? l = Math.floor((n[i - 1] + n[i]) / 2) : l = n[i];
822
+ const a = /* @__PURE__ */ new Map();
823
+ let h = 0;
824
+ for (const u of n) {
825
+ const d = (a.get(u) ?? 0) + 1;
826
+ a.set(u, d), d > h && (h = d);
741
827
  }
742
- if (d > 1) {
743
- const f = [];
744
- for (const [y, w] of m.entries())
745
- w === d && f.push(y);
746
- const g = f.reduce((y, w) => y + w, 0);
747
- s = Math.floor(g / f.length);
828
+ if (h > 1) {
829
+ const u = [];
830
+ for (const [p, R] of a.entries())
831
+ R === h && u.push(p);
832
+ const d = u.reduce((p, R) => p + R, 0);
833
+ l = Math.floor(d / u.length);
748
834
  }
749
- return { mode: s, materializedValues: r };
835
+ return { mode: l, materializedValues: r };
750
836
  }
751
837
  /**
752
838
  * @method update
@@ -755,25 +841,18 @@ class We {
755
841
  * @param {number} index - The 0-based index to update.
756
842
  * @param {number} value - The new value.
757
843
  */
758
- update(e, n) {
759
- return this.updates([{ index: e, value: n }]);
844
+ update(e, t) {
845
+ return this.updates([{ index: e, value: t }]);
760
846
  }
761
847
  /**
762
848
  * @method updates
763
849
  * @description Updates the values at given indices.
764
850
  * @description 指定されたインデックスの値を更新。
765
- * @param {{ index: number; value: number }[]} updates - An array of updates, each with an index and the new value.
851
+ * @param {ValueUpdate[]} updates - An array of updates, each with an index and the new value.
766
852
  */
767
853
  updates(e) {
768
- const n = e.map(({ index: t, value: r }) => {
769
- if (t < 0 || t >= this.size)
770
- throw new Error(`Index ${t} out of bounds`);
771
- if (r < 0)
772
- throw new Error("Value cannot be negative.");
773
- const o = this.deltas.has(t) ? (this.deltas.get(t) ?? 0) + this.baseValue : this.baseValue, s = r - o;
774
- return { index: t, change: s };
775
- }).filter((t) => t.change !== 0);
776
- return n.length > 0 ? this.updateDeltas(n) : this.total;
854
+ const t = this._buildDeltaUpdates(e);
855
+ return t.length > 0 ? this.updateDeltas(t) : this.total;
777
856
  }
778
857
  /**
779
858
  * @method updateDelta
@@ -782,21 +861,21 @@ class We {
782
861
  * @param {number} index - The 0-based index to update.
783
862
  * @param {number} change - The value to add to the delta at the given index.
784
863
  */
785
- updateDelta(e, n) {
786
- return this.updateDeltas([{ index: e, change: n }]);
864
+ updateDelta(e, t) {
865
+ return this.updateDeltas([{ index: e, change: t }]);
787
866
  }
788
867
  /**
789
868
  * @method updateDeltas
790
869
  * @description Updates the deltas at given indices and propagates the changes through the tree.
791
870
  * @description 指定されたインデックスのデルタを更新し、変更をツリーに伝播させる。
792
- * @param {{ index: number; change: number }[]} updates - An array of updates, each with an index and the change to apply.
871
+ * @param {DeltaUpdate[]} updates - An array of updates, each with an index and the change to apply.
793
872
  */
794
873
  updateDeltas(e) {
795
- for (const { index: n, change: t } of e) {
796
- if (n < 0 || n >= this.size)
797
- throw new Error(`Index ${n} out of bounds`);
798
- const r = this.deltas.get(n) ?? 0;
799
- this.deltas.set(n, r + t), this._updateTree(n, t);
874
+ for (const { index: t, change: n } of e) {
875
+ if (t < 0 || t >= this.size)
876
+ throw new Error(`Index ${t} out of bounds`);
877
+ const r = this.deltas.get(t) ?? 0;
878
+ this.deltas.set(t, r + n), this._updateTree(t, n);
800
879
  }
801
880
  return this.total;
802
881
  }
@@ -808,13 +887,33 @@ class We {
808
887
  * @param {number} index - The 0-based index that changed.
809
888
  * @param {number} change - The change in value.
810
889
  */
811
- _updateTree(e, n) {
812
- if (n === 0)
890
+ _updateTree(e, t) {
891
+ if (t === 0)
813
892
  return;
814
- let t = e + 1;
815
- for (; t <= this.size; )
816
- this.tree.set(t, (this.tree.get(t) ?? 0) + n), t += t & -t;
817
- this.total !== void 0 && (this.total += n);
893
+ let n = e + 1;
894
+ for (; n <= this.size; )
895
+ this.tree.set(n, (this.tree.get(n) ?? 0) + t), n += n & -n;
896
+ this.total !== void 0 && (this.total += t);
897
+ }
898
+ /**
899
+ * @private
900
+ * @method _buildDeltaUpdates
901
+ * @description Converts value updates into delta updates while preserving validation logic.
902
+ * @description 値更新入力を検証しつつデルタ更新へ変換する。
903
+ * @param {ValueUpdate[]} updates - Requested value updates.
904
+ * @returns {DeltaUpdate[]} Sanitized delta updates ready to apply.
905
+ */
906
+ _buildDeltaUpdates(e) {
907
+ const t = [];
908
+ for (const { index: n, value: r } of e) {
909
+ if (n < 0 || n >= this.size)
910
+ throw new Error(`Index ${n} out of bounds`);
911
+ if (r < 0)
912
+ throw new Error("Value cannot be negative.");
913
+ const i = this.deltas.has(n) ? (this.deltas.get(n) ?? 0) + this.baseValue : this.baseValue, l = r - i;
914
+ l !== 0 && t.push({ index: n, change: l });
915
+ }
916
+ return t;
818
917
  }
819
918
  /**
820
919
  * @private
@@ -824,106 +923,120 @@ class We {
824
923
  * @param {number} index - The 0-based index to materialize.
825
924
  * @param {boolean} [updateTree=true] - Whether to update the Fenwick tree after materialization.
826
925
  */
827
- _materialize(e, n = !0) {
926
+ _materialize(e, t = !0) {
828
927
  if (this.valueFn) {
829
- const t = this.deltas.get(e) ?? 0, o = this.valueFn(e) - this.baseValue;
830
- if (o !== t && (this.deltas.set(e, o), n)) {
831
- const s = o - t;
832
- this._updateTree(e, s);
928
+ const n = this.deltas.get(e) ?? 0, i = this.valueFn(e) - this.baseValue;
929
+ if (i !== n && (this.deltas.set(e, i), t)) {
930
+ const l = i - n;
931
+ this._updateTree(e, l);
833
932
  }
834
933
  }
835
934
  }
935
+ /**
936
+ * @private
937
+ * @method _materializeRanges
938
+ * @description Materializes values for provided ranges and optionally a target index, keeping existing semantics for each caller.
939
+ * @description 指定された範囲とターゲットインデックスを既存仕様通りに具現化する。
940
+ * @param {MaterializeOption | undefined} option - Materialization option wrapper.
941
+ * @param {number | undefined} index - Target index for materialization.
942
+ * @param {boolean} [forceIndex=false] - When true, materializes the index even if it is outside the provided ranges.
943
+ */
944
+ _materializeRanges(e, t, n = !1) {
945
+ if (!(e?.materialize && this.valueFn))
946
+ return;
947
+ const r = e.ranges;
948
+ if (r && r.length > 0) {
949
+ for (const a of r) {
950
+ const h = a.from, u = Math.min(a.to, this.size - 1);
951
+ for (let d = h; d <= u; d++)
952
+ this._materialize(d);
953
+ }
954
+ if (t === void 0)
955
+ return;
956
+ if (n) {
957
+ this._materialize(t);
958
+ return;
959
+ }
960
+ const i = r[0].from, l = r[r.length - 1].to;
961
+ t >= i && t <= l && this._materialize(t);
962
+ return;
963
+ }
964
+ t !== void 0 && this._materialize(t);
965
+ }
966
+ /**
967
+ * @private
968
+ * @method _findIndex
969
+ * @description Executes a binary search over prefix sums to find the first index satisfying a boundary condition.
970
+ * @description 累積和に対する二分探索を行い、境界条件を満たす最初のインデックスを求める。
971
+ * @param {number} target - Target cumulative value.
972
+ * @param {MaterializeConfig} options - Materialization setting wrapper.
973
+ * @param {boolean} chooseLowerBound - When true, finds the smallest index meeting or exceeding the target; otherwise finds the largest index not exceeding it.
974
+ * @returns {{ index: number; total: number | undefined; cumulative: number | undefined; currentValue: number | undefined; safeIndex: number | undefined }} Binary search result.
975
+ */
976
+ _findIndex(e, t = {}, n) {
977
+ if (this.size === 0)
978
+ return { index: -1, total: this.total ?? 0, cumulative: void 0, currentValue: void 0, safeIndex: void 0 };
979
+ let r = 0, i = this.size - 1, l = -1, a, h = this.total;
980
+ for (; r <= i; ) {
981
+ const u = Math.floor((r + i) / 2);
982
+ a = this.prefixSum(u, t), h = a.total, (n ? a.cumulative >= e : a.cumulative <= e) ? (l = u, n ? i = u - 1 : r = u + 1) : n ? r = u + 1 : i = u - 1;
983
+ }
984
+ return { index: l, total: h, cumulative: a?.cumulative, currentValue: a?.currentValue, safeIndex: a?.safeIndex };
985
+ }
836
986
  /**
837
987
  * @method prefixSum
838
988
  * @description Calculates the cumulative sum up to a given index (inclusive) in O(log n) time.
839
989
  * @description 指定されたインデックスまでの累積和を O(log n) で計算。
840
990
  * @param {number} index - The 0-based index to prefixSum up to.
841
- * @param {object} [options] - Optional settings for materializing values.
842
- * @param {object} [options.materializeOption] - Options to control materialization.
843
- * @param {boolean} [options.materializeOption.materialize=false] - Whether to materialize values.
844
- * @param {object[]} [options.materializeOption.ranges] - An optional array of ranges to materialize values for.
845
- * @param {number} options.materializeOption.ranges.from - The starting index of the range.
846
- * @param {number} options.materializeOption.ranges.to - The ending index of the range.
991
+ * @param {MaterializeConfig} [options] - Optional settings for materializing values.
847
992
  * @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.
848
993
  */
849
- prefixSum(e, n) {
994
+ prefixSum(e, t) {
850
995
  if (e < 0)
851
996
  return { cumulative: 0, total: this.total, currentValue: 0, safeIndex: 0 };
852
- const t = C(e, 0, this.size - 1), r = n?.materializeOption;
853
- if (r?.materialize && this.valueFn) {
854
- if (r.ranges)
855
- for (const d of r.ranges) {
856
- const f = d.from, g = Math.min(d.to, this.size - 1);
857
- for (let y = f; y <= g; y++)
858
- this._materialize(y);
859
- }
860
- this._materialize(t);
861
- }
862
- let o = 0, s = t + 1;
863
- for (; s > 0; ) {
864
- const d = this.tree.get(s) ?? 0;
865
- o += d, s -= s & -s;
997
+ const n = G(e, 0, this.size - 1), r = t?.materializeOption;
998
+ this._materializeRanges(r, n, !0);
999
+ let i = 0, l = n + 1;
1000
+ for (; l > 0; ) {
1001
+ const h = this.tree.get(l) ?? 0;
1002
+ i += h, l -= l & -l;
866
1003
  }
867
- const m = r?.materialize ? this.get(t) : (this.deltas.get(t) || 0) + this.baseValue;
868
- return { cumulative: o + this.baseValue * (t + 1), total: this.total, currentValue: m, safeIndex: t };
1004
+ const a = r?.materialize ? this.get(n) : (this.deltas.get(n) || 0) + this.baseValue;
1005
+ return { cumulative: i + this.baseValue * (n + 1), total: this.total, currentValue: a, safeIndex: n };
869
1006
  }
870
1007
  /**
871
1008
  * @method get
872
1009
  * @description Gets the value at a specific index.
873
1010
  * @description 特定のインデックスの値を取得。
874
1011
  * @param {number} index - The 0-based index to get.
875
- * @param {object} [options] - Optional settings for materializing values.
876
- * @param {object} [options.materializeOption] - Options to control materialization.
877
- * @param {boolean} [options.materializeOption.materialize=false] - Whether to materialize values.
878
- * @param {object[]} [options.materializeOption.ranges] - An optional array of ranges to materialize values for.
879
- * @param {number} options.materializeOption.ranges.from - The starting index of the range.
880
- * @param {number} options.materializeOption.ranges.to - The ending index of the range.
1012
+ * @param {MaterializeConfig} [options] - Optional settings for materializing values.
881
1013
  * @returns {number} The value at the given index.
882
1014
  */
883
- get(e, n) {
1015
+ get(e, t) {
884
1016
  if (e < 0 || e >= this.size)
885
1017
  throw new Error("Index out of bounds");
886
- const t = n?.materializeOption;
887
- if (t?.materialize && this.valueFn)
888
- if (t.ranges) {
889
- for (const r of t.ranges) {
890
- const o = r.from, s = Math.min(r.to, this.size - 1);
891
- for (let m = o; m <= s; m++)
892
- this._materialize(m);
893
- }
894
- e >= t.ranges[0].from && e <= t.ranges[t.ranges.length - 1].to && this._materialize(e);
895
- } else
896
- this._materialize(e);
897
- return (this.deltas.get(e) ?? 0) + this.baseValue;
1018
+ const n = t?.materializeOption;
1019
+ return this._materializeRanges(n, e), (this.deltas.get(e) ?? 0) + this.baseValue;
898
1020
  }
899
1021
  /**
900
1022
  * @method getTotal
901
1023
  * @description Gets the total sum of all values in the tree.
902
1024
  * @description ツリー内のすべての値の合計を取得。
903
- * @param {object} [options] - Optional settings for materializing values.
904
- * @param {object} [options.materializeOption] - Options to control materialization.
905
- * @param {boolean} [options.materializeOption.materialize=false] - Whether to materialize values.
906
- * @param {object[]} [options.materializeOption.ranges] - An optional array of ranges to materialize values for.
907
- * @param {number} options.materializeOption.ranges.from - The starting index of the range.
908
- * @param {number} options.materializeOption.ranges.to - The ending index of the range.
1025
+ * @param {MaterializeConfig} [options] - Optional settings for materializing values.
909
1026
  * @returns {number} The total sum of all values.
910
1027
  */
911
1028
  getTotal(e) {
912
- const n = e?.materializeOption;
913
- if (n?.materialize && this.valueFn && n.ranges)
914
- for (const t of n.ranges) {
915
- const r = t.from, o = Math.min(t.to, this.size - 1);
916
- for (let s = r; s <= o; s++)
917
- this._materialize(s);
918
- }
919
- if (this.total === void 0)
1029
+ const t = e?.materializeOption;
1030
+ if (this._materializeRanges(t), this.total === void 0)
920
1031
  if (this.size === 0)
921
1032
  this.total = 0;
922
1033
  else {
923
- let t = this.baseValue * this.size;
924
- for (const r of this.deltas.values())
925
- t += r;
926
- this.total = t, console.assert(this.prefixSum(this.getSize() - 1).cumulative === this.prefixSum(this.getSize() - 1).total, "Inconsistent Fenwick Tree state");
1034
+ let n = this.baseValue * this.size;
1035
+ for (const i of this.deltas.values())
1036
+ n += i;
1037
+ this.total = n;
1038
+ const r = this.prefixSum(this.getSize() - 1);
1039
+ console.assert(r.cumulative === r.total, "Inconsistent Fenwick Tree state");
927
1040
  }
928
1041
  return this.total;
929
1042
  }
@@ -937,19 +1050,19 @@ class We {
937
1050
  rebuildTree(e) {
938
1051
  if (e?.materialize && this.valueFn) {
939
1052
  const r = this.valueFn;
940
- this.reset(this.size, (o) => r(o), { materialize: !0 });
1053
+ this.reset(this.size, (i) => r(i), { materialize: !0 });
941
1054
  return;
942
1055
  }
943
- const n = /* @__PURE__ */ new Map();
944
- let t = this.baseValue * this.size;
945
- for (const [r, o] of this.deltas.entries()) {
946
- if (t += o, o === 0)
1056
+ const t = /* @__PURE__ */ new Map();
1057
+ let n = this.baseValue * this.size;
1058
+ for (const [r, i] of this.deltas.entries()) {
1059
+ if (n += i, i === 0)
947
1060
  continue;
948
- let s = r + 1;
949
- for (; s <= this.size; )
950
- n.set(s, (n.get(s) ?? 0) + o), s += s & -s;
1061
+ let l = r + 1;
1062
+ for (; l <= this.size; )
1063
+ t.set(l, (t.get(l) ?? 0) + i), l += l & -l;
951
1064
  }
952
- this.tree = n, this.total = t;
1065
+ this.tree = t, this.total = n;
953
1066
  }
954
1067
  /**
955
1068
  * @method calculateAccumulatedError
@@ -961,8 +1074,8 @@ class We {
961
1074
  if (this.total === void 0)
962
1075
  return 0;
963
1076
  let e = this.baseValue * this.size;
964
- for (const n of this.deltas.values())
965
- e += n;
1077
+ for (const t of this.deltas.values())
1078
+ e += t;
966
1079
  return this.total - e;
967
1080
  }
968
1081
  /**
@@ -972,13 +1085,15 @@ class We {
972
1085
  * @param {number} newSize - The new size of the tree.
973
1086
  */
974
1087
  changeSize(e) {
975
- const n = this.size;
976
- if (e !== n) {
977
- if (e < n)
978
- for (const t of this.deltas.keys())
979
- t >= e && this.deltas.delete(t);
980
- this.size = e, this.rebuildTree(), console.assert(this.prefixSum(this.getSize() - 1).cumulative === this.prefixSum(this.getSize() - 1).total, "Inconsistent Fenwick Tree state");
981
- }
1088
+ const t = this.size;
1089
+ if (e === t)
1090
+ return;
1091
+ if (e < t)
1092
+ for (const r of this.deltas.keys())
1093
+ r >= e && this.deltas.delete(r);
1094
+ this.size = e, this.rebuildTree();
1095
+ const n = this.prefixSum(this.getSize() - 1);
1096
+ console.assert(n.cumulative === n.total, "Inconsistent Fenwick Tree state");
982
1097
  }
983
1098
  /**
984
1099
  * @method getSize
@@ -994,206 +1109,44 @@ class We {
994
1109
  * @description Finds the first index where the cumulative sum is greater than or equal to a target value.
995
1110
  * @description 累積和がターゲット値以上になる最初のインデックスを検索。
996
1111
  * @param {number} target - The target cumulative sum.
997
- * @param {object} [options] - Optional settings for materializing values.
998
- * @param {object} [options.materializeOption] - Options to control materialization.
999
- * @param {boolean} [options.materializeOption.materialize=false] - Whether to materialize values.
1000
- * @param {object[]} [options.materializeOption.ranges] - An optional array of ranges to materialize values for.
1001
- * @param {number} options.materializeOption.ranges.from - The starting index of the range.
1002
- * @param {number} options.materializeOption.ranges.to - The ending index of the range.
1112
+ * @param {MaterializeConfig} [options] - Optional settings for materializing values.
1113
+ * @param {MaterializeOption} [options.materializeOption] - Options to control materialization.
1114
+ * @param {boolean} [options.materializeOption.materialize=false] - Whether to materialize values.
1115
+ * @param {MaterializeRange[]} [options.materializeOption.ranges] - Optional ranges for eager materialization.
1003
1116
  * @returns {{ index: number, total: number | undefined, cumulative: number | undefined, currentValue: number | undefined, safeIndex: number | undefined }} The 0-based index and the total sum, or -1 if not found.
1004
1117
  */
1005
- findIndexAtOrAfter(e, n) {
1006
- if (this.size === 0)
1007
- return { index: -1, total: this.total ?? 0, cumulative: void 0, currentValue: void 0, safeIndex: void 0 };
1008
- let t = 0, r = this.size - 1, o = -1, s, m = this.total;
1009
- for (; t <= r; ) {
1010
- const d = Math.floor((t + r) / 2);
1011
- s = this.prefixSum(d, n), m = s.total, s.cumulative >= e ? (o = d, r = d - 1) : t = d + 1;
1012
- }
1013
- return { index: o, total: m, cumulative: s?.cumulative, currentValue: s?.currentValue, safeIndex: s?.safeIndex };
1118
+ findIndexAtOrAfter(e, t) {
1119
+ return this._findIndex(e, t ?? {}, !0);
1014
1120
  }
1015
1121
  /**
1016
1122
  * @method findIndexAtOrBefore
1017
1123
  * @description Finds the last index where the cumulative sum is less than or equal to a target value.
1018
1124
  * @description 累積和がターゲット値以下になる最後のインデックスを検索。
1019
1125
  * @param {number} target - The target cumulative sum.
1020
- * @param {object} [options] - Optional settings for materializing values.
1021
- * @param {object} [options.materializeOption] - Options to control materialization.
1022
- * @param {boolean} [options.materializeOption.materialize=false] - Whether to materialize values.
1023
- * @param {object[]} [options.materializeOption.ranges] - An optional array of ranges to materialize values for.
1024
- * @param {number} options.materializeOption.ranges.from - The starting index of the range.
1025
- * @param {number} options.materializeOption.ranges.to - The ending index of the range.
1126
+ * @param {MaterializeConfig} [options] - Optional settings for materializing values.
1127
+ * @param {MaterializeOption} [options.materializeOption] - Options to control materialization
1128
+ * @param {boolean} [options.materializeOption.materialize=false] - Whether to materialize values
1129
+ * @param {MaterializeRange[]} [options.materializeOption.ranges] - Optional ranges for eager materialization。
1026
1130
  * @returns {{ index: number, total: number | undefined, cumulative: number | undefined, currentValue: number | undefined, safeIndex: number | undefined }} The 0-based index and the total sum, or -1 if not found.
1027
1131
  */
1028
- findIndexAtOrBefore(e, n) {
1029
- if (this.size === 0)
1030
- return { index: -1, total: this.total ?? 0, cumulative: void 0, currentValue: void 0, safeIndex: void 0 };
1031
- let t = 0, r = this.size - 1, o = -1, s, m = this.total;
1032
- for (; t <= r; ) {
1033
- const d = Math.floor((t + r) / 2);
1034
- s = this.prefixSum(d, n), m = s.total, s.cumulative <= e ? (o = d, t = d + 1) : r = d - 1;
1035
- }
1036
- return { index: o, total: m, cumulative: s?.cumulative, currentValue: s?.currentValue, safeIndex: s?.safeIndex };
1132
+ findIndexAtOrBefore(e, t) {
1133
+ return this._findIndex(e, t ?? {}, !1);
1037
1134
  }
1038
1135
  }
1039
- const Ge = (c, e, n) => {
1040
- const t = Math.max(0, c), r = N(null), o = O(() => new We(t, e, n), [t, e, n]);
1041
- return Object.is(r.current, o) || console.warn("[useFenwickMapTree] instance changed"), r.current = o, o;
1136
+ const vt = (o, e, t) => {
1137
+ const n = Math.max(0, o), r = k(null), i = xe(() => new xt(n, e, t), [n, e, t]);
1138
+ return Object.is(r.current, i) || console.warn("[useFenwickMapTree] instance changed"), r.current = i, i;
1042
1139
  };
1043
- function Ze({ itemCount: c, getItem: e, getItemHeight: n, viewportSize: t, overscanCount: r = 5, className: o, onScroll: s, onRangeChange: m, children: d, background: f, initialScrollIndex: g, initialScrollOffset: y, tapScrollCircleOptions: w, inertiaOptions: ie }, ae) {
1044
- const Y = N(null), Q = N(!1);
1045
- re(() => (Q.current = !0, () => {
1046
- Q.current = !1;
1047
- }), []);
1048
- const D = N({ size: c, valueOrFn: n, options: { sampleRange: { from: 0, to: 100 } } }), u = Ge(D.current.size, D.current.valueOrFn, D.current.options), [ee] = le(() => {
1049
- let h = 0, p = 0;
1050
- if (typeof g == "number") {
1051
- const I = C(g, 0, c - 1), v = C(I - r * 2, 0, c - 1), b = C(I + r * 2, 0, c - 1), _ = g > 0 ? { materializeOption: { materialize: !0, ranges: [{ from: v, to: b }] } } : void 0, { cumulative: H, total: V, currentValue: X } = u.prefixSum(g, _);
1052
- h = H - X, p = V ?? u.getTotal();
1053
- } else typeof y == "number" && (h = y), p = u.getTotal();
1054
- return { position: h, total: p };
1055
- }), [E, P] = le(ee.position), [F, W] = le(ee.total), [q, se] = le(ee.position), [i, $] = le(c);
1056
- ve(() => {
1057
- u.setValueFn(n), i !== c && (u.changeSize(c), $(c));
1058
- const h = u.getTotal();
1059
- F !== h && W(h);
1060
- }, [u, i, c, F, n]), ve(() => {
1061
- q !== null && Y.current && (J.debug("[VirtualScroll] Scrolling to position:", q), Y.current.scrollTo(q), se(null));
1062
- }, [q]);
1063
- const k = z(
1064
- (h) => {
1065
- if (Y.current) {
1066
- J.debug("[VirtualScroll] Scrolling to index:", h);
1067
- const p = C(h, 0, i - 1), I = C(p - r * 2, 0, i - 1), v = C(p + r * 2, 0, i - 1), { cumulative: b, total: _, currentValue: H } = u.prefixSum(p, { materializeOption: { materialize: !0, ranges: [{ from: I, to: v }] } });
1068
- J.debug("[VirtualScroll] Scrolling to index:", h, "Offset:", b, "Total height:", _, "Current value:", H, "safeIndex:", p, "safeIndexFrom:", I, "safeIndexTo:", v), _ && (W(_), se(b - H)), J.debug("[VirtualScroll] Setting scroll position to:", b - H);
1069
- }
1070
- },
1071
- [u, r, i]
1072
- ), A = z(
1073
- (h) => {
1074
- if (Y.current) {
1075
- const p = u.getTotal(), I = C(Math.floor(h), 0, p), v = u.findIndexAtOrAfter(I, { materializeOption: { materialize: !1 } }).index;
1076
- k(v);
1077
- }
1078
- },
1079
- [u, k]
1080
- ), x = z(
1081
- (h, p) => {
1082
- J.debug("[VirtualScroll] Scroll position changed:", h), P(h);
1083
- const I = u.getTotal();
1084
- s?.(h, I);
1085
- },
1086
- [u, s]
1087
- ), T = O(() => {
1088
- if (i === 0)
1089
- return { renderingStartIndex: 0, renderingEndIndex: 0, visibleStartIndex: 0, visibleEndIndex: 0 };
1090
- const { index: h, cumulative: p, currentValue: I } = u.findIndexAtOrAfter(E, { materializeOption: { materialize: !1 } });
1091
- let v = 0;
1092
- h === -1 ? v = 0 : (p ?? 0) < E + (I ?? 0) ? v = 1 : v = 0;
1093
- const b = h === -1 ? 0 : h + v, _ = C(b - r, 0, i - 1);
1094
- let H = 0, V = h === -1 ? 0 : h + v;
1095
- for (; V < i && H < t; ) {
1096
- const R = n(V);
1097
- H += R, V++;
1098
- }
1099
- V -= 1;
1100
- const X = C(V + r, 0, i - 1);
1101
- return J.debug("[VirtualScroll] Calculated rendering range:", {
1102
- renderingStartIndex: _,
1103
- renderingEndIndex: X,
1104
- visibleStartIndex: b,
1105
- visibleEndIndex: V,
1106
- scrollPosition: E,
1107
- renderingContentSize: u.getTotal(),
1108
- overscanCount: r,
1109
- viewportSize: t
1110
- }), { renderingStartIndex: _, renderingEndIndex: X, visibleStartIndex: b, visibleEndIndex: V };
1111
- }, [E, r, t, n, u, i]);
1112
- re(() => {
1113
- const h = Y.current?.getScrollPosition() ?? 0;
1114
- J.debug("[VirtualScroll] Range change effect triggered", {
1115
- renderingStartIndex: T.renderingStartIndex,
1116
- renderingEndIndex: T.renderingEndIndex,
1117
- visibleStartIndex: T.visibleStartIndex,
1118
- visibleEndIndex: T.visibleEndIndex,
1119
- scrollPosition: E,
1120
- contentSize: F,
1121
- scrollPaneScrollPosition: h
1122
- }), m?.(T.renderingStartIndex, T.renderingEndIndex, T.visibleStartIndex, T.visibleEndIndex, E, F);
1123
- }, [T.renderingStartIndex, T.renderingEndIndex, T.visibleStartIndex, T.visibleEndIndex, m, E, F]);
1124
- const M = z(
1125
- (h) => {
1126
- const { renderingStartIndex: p, renderingEndIndex: I } = T;
1127
- if (J.debug("[VirtualScroll] Rendering visible items", { currentScrollPosition: h, renderingStartIndex: p, renderingEndIndex: I, fenwickSize: i, viewportSize: t }), i === 0)
1128
- return /* @__PURE__ */ j("div", { className: "absolute w-full", style: { top: 0 }, children: /* @__PURE__ */ j("div", { className: "text-center text-gray-500", children: "No items" }) });
1129
- const v = C(p, 0, i - 1), { cumulative: b, currentValue: _ } = u.prefixSum(v, { materializeOption: { materialize: !1 } }), H = b - _, V = [], X = [];
1130
- for (let S = p; S <= I; S++) {
1131
- const K = n(S);
1132
- V.push({ item: e(S), height: K }), u.get(S) !== K && X.push({ index: S, value: K });
1133
- }
1134
- X.length > 0 && Promise.resolve().then(() => {
1135
- const S = u.updates(X);
1136
- S && (W(S), J.debug("[VirtualScroll] Updated heights for items", X, "New total height:", S));
1137
- });
1138
- const R = F < t ? 0 : H - h;
1139
- return J.debug("[VirtualScroll] Rendering items", { visibleItems: V, containerTop: R }), /* @__PURE__ */ j("div", { className: "absolute w-full", style: { top: R }, children: V.map(({ item: S, height: K }, oe) => {
1140
- const te = p + oe, a = C(te, 0, i - 1), { cumulative: G, currentValue: U } = u.prefixSum(a, { materializeOption: { materialize: !1 } }), ne = G - U;
1141
- return /* @__PURE__ */ j(
1142
- "div",
1143
- {
1144
- "data-index": te,
1145
- style: {
1146
- position: "absolute",
1147
- top: ne - H,
1148
- width: "100%"
1149
- },
1150
- children: d(S, te)
1151
- },
1152
- te
1153
- );
1154
- }) });
1155
- },
1156
- [e, d, F, t, T, u, i, n]
1157
- );
1158
- return Me(
1159
- ae,
1160
- () => ({
1161
- getScrollPosition: () => Y.current?.getScrollPosition() ?? -1,
1162
- getContentSize: () => Y.current?.getContentSize() ?? -1,
1163
- getViewportSize: () => Y.current?.getViewportSize() ?? -1,
1164
- scrollTo: (h) => A(h),
1165
- scrollToIndex: (h) => k(h),
1166
- getFenwickTreeTotalHeight: () => u.getTotal(),
1167
- getFenwickSize: () => u.getSize()
1168
- }),
1169
- [k, u, A]
1170
- ), /* @__PURE__ */ j(
1171
- Be,
1172
- {
1173
- ref: Y,
1174
- contentSize: F,
1175
- viewportSize: t,
1176
- className: o,
1177
- onScroll: x,
1178
- background: f,
1179
- tapScrollCircleOptions: w,
1180
- inertiaOptions: ie,
1181
- itemCount: c,
1182
- children: M
1183
- }
1184
- );
1185
- }
1186
- const st = Ve(Ze);
1187
- class Je {
1140
+ class bt {
1188
1141
  key;
1189
1142
  value;
1190
1143
  prev = null;
1191
1144
  next = null;
1192
- constructor(e, n) {
1193
- this.key = e, this.value = n;
1145
+ constructor(e, t) {
1146
+ this.key = e, this.value = t;
1194
1147
  }
1195
1148
  }
1196
- class Fe {
1149
+ class Ze {
1197
1150
  head = null;
1198
1151
  tail = null;
1199
1152
  /**
@@ -1234,54 +1187,193 @@ class Fe {
1234
1187
  this.remove(e), this.addToTail(e);
1235
1188
  }
1236
1189
  }
1237
- function Qe(c) {
1238
- const e = N(/* @__PURE__ */ new Map()), n = N(new Fe());
1239
- re(() => {
1240
- for (; e.current.size > c; ) {
1241
- const f = n.current.removeHead();
1242
- if (f)
1243
- e.current.delete(f.key);
1190
+ function Tt(o) {
1191
+ const e = k(/* @__PURE__ */ new Map()), t = k(new Ze());
1192
+ se(() => {
1193
+ for (; e.current.size > o; ) {
1194
+ const u = t.current.removeHead();
1195
+ if (u)
1196
+ e.current.delete(u.key);
1244
1197
  else
1245
1198
  break;
1246
1199
  }
1247
- }, [c]);
1248
- const t = z((f) => {
1249
- const g = e.current.get(f);
1250
- if (g)
1251
- return n.current.moveToTail(g), g.value;
1252
- }, []), r = z(
1253
- (f, g) => {
1254
- if (c <= 0)
1200
+ }, [o]);
1201
+ const n = A((u) => {
1202
+ const d = e.current.get(u);
1203
+ if (d)
1204
+ return t.current.moveToTail(d), d.value;
1205
+ }, []), r = A(
1206
+ (u, d) => {
1207
+ if (o <= 0)
1255
1208
  return;
1256
- let y = e.current.get(f);
1257
- if (y)
1258
- y.value = g, n.current.moveToTail(y);
1209
+ let p = e.current.get(u);
1210
+ if (p)
1211
+ p.value = d, t.current.moveToTail(p);
1259
1212
  else {
1260
- if (e.current.size >= c) {
1261
- const w = n.current.removeHead();
1262
- w && e.current.delete(w.key);
1213
+ if (e.current.size >= o) {
1214
+ const R = t.current.removeHead();
1215
+ R && e.current.delete(R.key);
1263
1216
  }
1264
- y = new Je(f, g), e.current.set(f, y), n.current.addToTail(y);
1217
+ p = new bt(u, d), e.current.set(u, p), t.current.addToTail(p);
1265
1218
  }
1266
1219
  },
1267
- [c]
1268
- ), o = z((f) => e.current.has(f), []), s = z(() => {
1269
- e.current.clear(), n.current = new Fe();
1270
- }, []), [m, d] = le(() => ({ get: t, set: r, has: o, clear: s }));
1271
- return re(() => d({ get: t, set: r, has: o, clear: s }), [t, r, o, s]), m;
1220
+ [o]
1221
+ ), i = A((u) => e.current.has(u), []), l = A(() => {
1222
+ e.current.clear(), t.current = new Ze();
1223
+ }, []), [a, h] = de(() => ({ get: n, set: r, has: i, clear: l }));
1224
+ return se(() => h({ get: n, set: r, has: i, clear: l }), [n, r, i, l]), a;
1272
1225
  }
1273
- const et = 1e4, it = () => {
1274
- const { get: c, set: e, has: n, clear: t } = Qe(et);
1275
- return { get: c, set: e, has: n, clear: t };
1226
+ const yt = 1e4, Et = () => {
1227
+ const { get: o, set: e, has: t, clear: n } = Tt(yt);
1228
+ return { get: o, set: e, has: t, clear: n };
1229
+ }, me = (o, e) => e <= 0 ? 0 : G(o, 0, e - 1), wt = (o, e, t, n, r, i) => {
1230
+ if (n === 0)
1231
+ return { renderingStartIndex: 0, renderingEndIndex: 0, visibleStartIndex: 0, visibleEndIndex: 0 };
1232
+ const { index: l, cumulative: a, currentValue: h } = i.findIndexAtOrAfter(o, { materializeOption: { materialize: !1 } }), u = l === -1 ? 0 : l, d = l !== -1 && (a ?? 0) < o + (h ?? 0) ? u + 1 : u, p = me(d, n), R = me(p - t, n);
1233
+ let V = 0, X = p;
1234
+ for (; X < n && V < e; )
1235
+ V += r(X), X++;
1236
+ const ee = me(X - 1, n), b = me(ee + t, n);
1237
+ return { renderingStartIndex: R, renderingEndIndex: b, visibleStartIndex: p, visibleEndIndex: ee };
1276
1238
  };
1239
+ function St({ itemCount: o, getItem: e, getItemHeight: t, viewportSize: n, overscanCount: r = 5, className: i, onScroll: l, onRangeChange: a, children: h, background: u, initialScrollIndex: d, initialScrollOffset: p, tapScrollCircleOptions: R, scrollBarWidth: V, enableThumbDrag: X, enableTrackClick: ee, enableArrowButtons: b, enablePointerDrag: ae, inertiaOptions: le }, Z) {
1240
+ const _ = k(null), U = k(!1);
1241
+ se(() => (U.current = !0, () => {
1242
+ U.current = !1;
1243
+ }), []);
1244
+ const O = k({ size: o, valueOrFn: t, options: { sampleRange: { from: 0, to: 100 } } }), x = vt(O.current.size, O.current.valueOrFn, O.current.options), [P] = de(() => {
1245
+ let T = 0, S = 0;
1246
+ if (typeof d == "number") {
1247
+ const E = G(d, 0, o - 1), q = G(E - r * 2, 0, o - 1), oe = G(E + r * 2, 0, o - 1), j = d > 0 ? { materializeOption: { materialize: !0, ranges: [{ from: q, to: oe }] } } : void 0, { cumulative: W, total: ne, currentValue: B } = x.prefixSum(d, j);
1248
+ T = W - B, S = ne ?? x.getTotal();
1249
+ } else typeof p == "number" && (T = p), S = x.getTotal();
1250
+ return { position: T, total: S };
1251
+ }), [w, H] = de(P.position), [m, D] = de(P.total), [f, F] = de(P.position), [g, N] = de(o);
1252
+ Ee(() => {
1253
+ x.setValueFn(t), g !== o && (x.changeSize(o), N(o));
1254
+ const T = x.getTotal();
1255
+ m !== T && D(T);
1256
+ }, [x, g, o, m, t]), Ee(() => {
1257
+ f !== null && _.current && (re.debug("[VirtualScroll] Scrolling to position:", f), _.current.scrollTo(f), F(null));
1258
+ }, [f]);
1259
+ const L = A(
1260
+ (T) => {
1261
+ if (!_.current)
1262
+ return;
1263
+ const S = me(T, g), E = me(S - r * 2, g), q = me(S + r * 2, g), { cumulative: oe, total: j, currentValue: W } = x.prefixSum(S, { materializeOption: { materialize: !0, ranges: [{ from: E, to: q }] } });
1264
+ re.debug("[VirtualScroll] Scrolling to index:", S, "Offset:", oe, "Total height:", j, "Current value:", W, "safeIndexFrom:", E, "safeIndexTo:", q), j && (D(j), F(oe - W), re.debug("[VirtualScroll] Setting scroll position to:", oe - W));
1265
+ },
1266
+ [x, r, g]
1267
+ ), C = A(
1268
+ (T) => {
1269
+ if (!_.current)
1270
+ return;
1271
+ const S = x.getTotal(), E = G(Math.floor(T), 0, S), q = x.findIndexAtOrAfter(E, { materializeOption: { materialize: !1 } }).index;
1272
+ L(q);
1273
+ },
1274
+ [x, L]
1275
+ ), M = A(
1276
+ (T, S) => {
1277
+ re.debug("[VirtualScroll] Scroll position changed:", T), H(T);
1278
+ const E = x.getTotal();
1279
+ l?.(T, E);
1280
+ },
1281
+ [x, l]
1282
+ ), y = xe(() => {
1283
+ const T = wt(w, n, r, g, t, x);
1284
+ return re.debug("[VirtualScroll] Calculated rendering range:", {
1285
+ ...T,
1286
+ scrollPosition: w,
1287
+ renderingContentSize: x.getTotal(),
1288
+ overscanCount: r,
1289
+ viewportSize: n
1290
+ }), T;
1291
+ }, [w, n, r, g, t, x]);
1292
+ se(() => {
1293
+ const T = _.current?.getScrollPosition() ?? 0;
1294
+ re.debug("[VirtualScroll] Range change effect triggered", {
1295
+ renderingStartIndex: y.renderingStartIndex,
1296
+ renderingEndIndex: y.renderingEndIndex,
1297
+ visibleStartIndex: y.visibleStartIndex,
1298
+ visibleEndIndex: y.visibleEndIndex,
1299
+ scrollPosition: w,
1300
+ contentSize: m,
1301
+ scrollPaneScrollPosition: T
1302
+ }), a?.(y.renderingStartIndex, y.renderingEndIndex, y.visibleStartIndex, y.visibleEndIndex, w, m);
1303
+ }, [y.renderingStartIndex, y.renderingEndIndex, y.visibleStartIndex, y.visibleEndIndex, a, w, m]);
1304
+ const I = A(
1305
+ (T) => {
1306
+ const { renderingStartIndex: S, renderingEndIndex: E } = y;
1307
+ if (re.debug("[VirtualScroll] Rendering visible items", { currentScrollPosition: T, renderingStartIndex: S, renderingEndIndex: E, fenwickSize: g, viewportSize: n }), g === 0)
1308
+ return /* @__PURE__ */ $("div", { className: "absolute w-full", style: { top: 0 }, children: /* @__PURE__ */ $("div", { className: "text-center text-gray-500", children: "No items" }) });
1309
+ const q = me(S, g), { cumulative: oe, currentValue: j } = x.prefixSum(q, { materializeOption: { materialize: !1 } }), W = oe - j, ne = [], B = [];
1310
+ for (let Y = S; Y <= E; Y++) {
1311
+ const c = t(Y);
1312
+ ne.push({ item: e(Y), height: c, index: Y }), x.get(Y) !== c && B.push({ index: Y, value: c });
1313
+ }
1314
+ B.length > 0 && Promise.resolve().then(() => {
1315
+ const Y = x.updates(B);
1316
+ Y && (D(Y), re.debug("[VirtualScroll] Updated heights for items", B, "New total height:", Y));
1317
+ });
1318
+ const fe = m < n ? 0 : W - T;
1319
+ return re.debug("[VirtualScroll] Rendering items", { visibleItems: ne, containerTop: fe }), /* @__PURE__ */ $("div", { className: "absolute w-full", style: { top: fe }, children: ne.map(({ item: Y, index: c }) => {
1320
+ const J = me(c, g), { cumulative: Q, currentValue: z } = x.prefixSum(J, { materializeOption: { materialize: !1 } }), ie = Q - z;
1321
+ return /* @__PURE__ */ $(
1322
+ "div",
1323
+ {
1324
+ "data-index": c,
1325
+ style: {
1326
+ position: "absolute",
1327
+ top: ie - W,
1328
+ width: "100%"
1329
+ },
1330
+ children: h(Y, c)
1331
+ },
1332
+ c
1333
+ );
1334
+ }) });
1335
+ },
1336
+ [e, h, m, n, y, x, g, t]
1337
+ );
1338
+ return Oe(Z, () => ({
1339
+ getScrollPosition: () => _.current?.getScrollPosition() ?? -1,
1340
+ getContentSize: () => _.current?.getContentSize() ?? -1,
1341
+ getViewportSize: () => _.current?.getViewportSize() ?? -1,
1342
+ scrollTo: C,
1343
+ scrollToIndex: L,
1344
+ getFenwickTreeTotalHeight: () => x.getTotal(),
1345
+ getFenwickSize: () => x.getSize()
1346
+ }), [C, L, x]), /* @__PURE__ */ $(
1347
+ gt,
1348
+ {
1349
+ ref: _,
1350
+ contentSize: m,
1351
+ viewportSize: n,
1352
+ className: i,
1353
+ onScroll: M,
1354
+ background: u,
1355
+ tapScrollCircleOptions: R,
1356
+ inertiaOptions: le,
1357
+ itemCount: o,
1358
+ scrollBarWidth: V,
1359
+ enableThumbDrag: X,
1360
+ enableTrackClick: ee,
1361
+ enableArrowButtons: b,
1362
+ enablePointerDrag: ae,
1363
+ children: I
1364
+ }
1365
+ );
1366
+ }
1367
+ const At = ke(St);
1277
1368
  export {
1278
- We as FenwickMapTree,
1279
- Ke as ScrollBar,
1280
- Be as ScrollPane,
1281
- st as VirtualScroll,
1282
- C as minmax,
1283
- Ge as useFenwickMapTree,
1284
- it as useHeightCache,
1285
- Qe as useLruCache
1369
+ xt as FenwickMapTree,
1370
+ pt as ScrollBar,
1371
+ gt as ScrollPane,
1372
+ At as VirtualScroll,
1373
+ G as minmax,
1374
+ Mt as tapScrollCircleSampleVisual,
1375
+ vt as useFenwickMapTree,
1376
+ Et as useHeightCache,
1377
+ Tt as useLruCache
1286
1378
  };
1287
1379
  //# sourceMappingURL=index.js.map