@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/cli.js +8 -8
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +931 -839
- package/dist/index.js.map +1 -1
- package/dist/src/ScrollBar.d.ts +11 -1
- package/dist/src/ScrollBar.d.ts.map +1 -1
- package/dist/src/ScrollPane.d.ts +8 -0
- package/dist/src/ScrollPane.d.ts.map +1 -1
- package/dist/src/TapScrollCircle.d.ts +17 -1
- package/dist/src/TapScrollCircle.d.ts.map +1 -1
- package/dist/src/VirtualScroll.d.ts +5 -0
- package/dist/src/VirtualScroll.d.ts.map +1 -1
- package/dist/src/index.d.ts +6 -4
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/tapScrollCircleSampleVisual.d.ts +3 -0
- package/dist/src/tapScrollCircleSampleVisual.d.ts.map +1 -0
- package/dist/src/useFenwickMapTree.d.ts +70 -85
- package/dist/src/useFenwickMapTree.d.ts.map +1 -1
- package/dist/virtualscroll.css +1 -1
- package/package.json +2 -1
package/dist/index.js
CHANGED
|
@@ -1,426 +1,449 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import { forwardRef as
|
|
3
|
-
import { twMerge as
|
|
4
|
-
const
|
|
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
|
-
},
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
-
|
|
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
|
-
[
|
|
40
|
-
),
|
|
41
|
-
(
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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
|
-
[
|
|
50
|
-
),
|
|
51
|
-
(
|
|
52
|
-
|
|
69
|
+
[X]
|
|
70
|
+
), le = A(
|
|
71
|
+
(m) => {
|
|
72
|
+
d.current === m.pointerId && (m.preventDefault(), X(m.clientX, m.clientY));
|
|
53
73
|
},
|
|
54
|
-
[
|
|
55
|
-
),
|
|
56
|
-
(
|
|
57
|
-
|
|
74
|
+
[X]
|
|
75
|
+
), Z = A(
|
|
76
|
+
(m) => {
|
|
77
|
+
d.current === m.pointerId && (m.preventDefault(), m.stopPropagation(), b(!0));
|
|
58
78
|
},
|
|
59
|
-
[
|
|
79
|
+
[b]
|
|
60
80
|
);
|
|
61
|
-
|
|
62
|
-
|
|
81
|
+
Oe(
|
|
82
|
+
a,
|
|
63
83
|
() => ({
|
|
64
84
|
reset: () => {
|
|
65
|
-
|
|
85
|
+
b(!0);
|
|
66
86
|
},
|
|
67
|
-
getElement: () =>
|
|
87
|
+
getElement: () => R.current
|
|
68
88
|
}),
|
|
69
|
-
[
|
|
89
|
+
[b]
|
|
70
90
|
);
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
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:
|
|
84
|
-
className:
|
|
85
|
-
"relative flex items-center justify-center
|
|
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:
|
|
92
|
-
onPointerUp:
|
|
93
|
-
onPointerCancel:
|
|
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
|
-
|
|
136
|
-
const
|
|
137
|
-
const
|
|
138
|
-
|
|
139
|
-
const
|
|
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:
|
|
142
|
-
deltaY:
|
|
128
|
+
deltaX: h.clientX - r.clientX,
|
|
129
|
+
deltaY: h.clientY - r.clientY
|
|
143
130
|
});
|
|
144
|
-
},
|
|
145
|
-
|
|
131
|
+
}, l = () => {
|
|
132
|
+
n ? (document.removeEventListener("touchmove", i), document.removeEventListener("touchend", l)) : (document.removeEventListener("mousemove", i), document.removeEventListener("mouseup", l)), t?.();
|
|
146
133
|
};
|
|
147
|
-
|
|
148
|
-
},
|
|
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:
|
|
137
|
+
size: 40,
|
|
151
138
|
offsetX: -80,
|
|
152
139
|
offsetY: 0,
|
|
153
140
|
className: void 0,
|
|
154
|
-
maxVisualDistance:
|
|
155
|
-
opacity: 1
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
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:
|
|
166
|
-
size:
|
|
167
|
-
offsetX:
|
|
168
|
-
offsetY:
|
|
169
|
-
className:
|
|
170
|
-
maxVisualDistance:
|
|
171
|
-
maxSpeedMultiplier:
|
|
172
|
-
opacity:
|
|
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
|
-
}, [
|
|
175
|
-
enabled:
|
|
176
|
-
size:
|
|
177
|
-
offsetX:
|
|
178
|
-
offsetY:
|
|
179
|
-
className:
|
|
180
|
-
maxVisualDistance:
|
|
181
|
-
maxSpeedMultiplier:
|
|
182
|
-
opacity:
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
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 (!
|
|
203
|
-
|
|
206
|
+
if (!he || z <= 0) {
|
|
207
|
+
ce();
|
|
204
208
|
return;
|
|
205
209
|
}
|
|
206
|
-
const
|
|
207
|
-
if (
|
|
208
|
-
|
|
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
|
|
212
|
-
if (
|
|
213
|
-
|
|
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
|
-
|
|
220
|
+
_.current = Ce, n?.(Ce, Te), w.current = window.requestAnimationFrame(Ve);
|
|
217
221
|
},
|
|
218
|
-
[
|
|
219
|
-
),
|
|
220
|
-
|
|
221
|
-
}, [
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
}, [
|
|
225
|
-
const
|
|
226
|
-
(
|
|
227
|
-
|
|
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
|
-
[
|
|
233
|
+
[ze, ce]
|
|
230
234
|
);
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
}, [
|
|
234
|
-
const
|
|
235
|
-
const
|
|
236
|
-
|
|
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(
|
|
239
|
-
window.removeEventListener(
|
|
242
|
+
return window.addEventListener(Ne, s), () => {
|
|
243
|
+
window.removeEventListener(Ne, s);
|
|
240
244
|
};
|
|
241
|
-
}, [
|
|
242
|
-
if (!
|
|
245
|
+
}, [d, ue]), se(() => {
|
|
246
|
+
if (!D)
|
|
243
247
|
return;
|
|
244
|
-
const
|
|
245
|
-
if (!
|
|
248
|
+
const s = (v) => {
|
|
249
|
+
if (!x.current.active)
|
|
246
250
|
return;
|
|
247
|
-
const
|
|
248
|
-
if (!(
|
|
249
|
-
|
|
251
|
+
const K = v.target;
|
|
252
|
+
if (!(K instanceof Node)) {
|
|
253
|
+
ue();
|
|
250
254
|
return;
|
|
251
255
|
}
|
|
252
|
-
|
|
256
|
+
P.current?.getElement()?.contains(K) || ue();
|
|
253
257
|
};
|
|
254
|
-
return document.addEventListener("pointerdown",
|
|
255
|
-
document.removeEventListener("pointerdown",
|
|
258
|
+
return document.addEventListener("pointerdown", s, !0), () => {
|
|
259
|
+
document.removeEventListener("pointerdown", s, !0);
|
|
256
260
|
};
|
|
257
|
-
}, [
|
|
258
|
-
const
|
|
259
|
-
if (!
|
|
261
|
+
}, [ue, D]);
|
|
262
|
+
const Ae = (s) => {
|
|
263
|
+
if (!he || ie <= 0 || z <= 0)
|
|
260
264
|
return 0;
|
|
261
|
-
const
|
|
262
|
-
return
|
|
263
|
-
},
|
|
264
|
-
if (!
|
|
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
|
-
|
|
267
|
-
|
|
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
|
-
|
|
282
|
-
const
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
({ deltaX:
|
|
286
|
-
|
|
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
|
-
|
|
300
|
+
X(!1), Z.current && !Z.current.matches(":hover") && b(!1);
|
|
290
301
|
}
|
|
291
302
|
);
|
|
292
|
-
},
|
|
293
|
-
if (!
|
|
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
|
|
296
|
-
|
|
297
|
-
const
|
|
298
|
-
|
|
299
|
-
|
|
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
|
-
},
|
|
302
|
-
const
|
|
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:
|
|
305
|
-
top:
|
|
322
|
+
left: F,
|
|
323
|
+
top: v
|
|
306
324
|
};
|
|
307
|
-
}, [
|
|
308
|
-
|
|
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:
|
|
351
|
+
className: we(
|
|
312
352
|
"group relative cursor-default select-none",
|
|
313
|
-
|
|
314
|
-
|
|
353
|
+
ne,
|
|
354
|
+
u
|
|
315
355
|
),
|
|
316
356
|
style: {
|
|
317
|
-
[
|
|
318
|
-
[
|
|
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":
|
|
326
|
-
"aria-valuenow":
|
|
365
|
+
"aria-controls": d,
|
|
366
|
+
"aria-valuenow": t,
|
|
327
367
|
"aria-valuemin": 0,
|
|
328
|
-
"aria-valuemax":
|
|
329
|
-
"aria-orientation":
|
|
368
|
+
"aria-valuemax": z,
|
|
369
|
+
"aria-orientation": a ? "horizontal" : "vertical",
|
|
330
370
|
children: [
|
|
331
|
-
!
|
|
332
|
-
|
|
371
|
+
!a && he && D && /* @__PURE__ */ $(
|
|
372
|
+
Qe,
|
|
333
373
|
{
|
|
334
|
-
ref:
|
|
335
|
-
className:
|
|
374
|
+
ref: P,
|
|
375
|
+
className: we(
|
|
336
376
|
"pointer-events-auto absolute transition-opacity duration-150",
|
|
337
|
-
|
|
377
|
+
N
|
|
338
378
|
),
|
|
339
|
-
size:
|
|
340
|
-
maxVisualDistance:
|
|
341
|
-
style:
|
|
342
|
-
opacity:
|
|
343
|
-
|
|
379
|
+
size: f,
|
|
380
|
+
maxVisualDistance: B,
|
|
381
|
+
style: rt,
|
|
382
|
+
opacity: nt,
|
|
383
|
+
renderVisual: y,
|
|
384
|
+
onDragChange: et
|
|
344
385
|
}
|
|
345
386
|
),
|
|
346
|
-
|
|
347
|
-
|
|
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:
|
|
394
|
+
borderRadius: h / 2
|
|
375
395
|
},
|
|
376
|
-
onMouseDown:
|
|
377
|
-
onTouchStart:
|
|
378
|
-
|
|
379
|
-
|
|
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
|
-
[
|
|
385
|
-
[
|
|
386
|
-
...
|
|
405
|
+
[I]: Q,
|
|
406
|
+
[S]: ge,
|
|
407
|
+
...a ? { top: 0, bottom: 0 } : { left: 0, right: 0 }
|
|
387
408
|
},
|
|
388
|
-
onMouseDown:
|
|
389
|
-
onTouchStart:
|
|
409
|
+
onMouseDown: $e,
|
|
410
|
+
onTouchStart: $e,
|
|
390
411
|
role: "slider",
|
|
391
|
-
"aria-orientation":
|
|
392
|
-
"aria-valuenow":
|
|
412
|
+
"aria-orientation": a ? "horizontal" : "vertical",
|
|
413
|
+
"aria-valuenow": t,
|
|
393
414
|
"aria-valuemin": 0,
|
|
394
|
-
"aria-valuemax":
|
|
395
|
-
|
|
396
|
-
|
|
415
|
+
"aria-valuemax": z,
|
|
416
|
+
"aria-disabled": !r,
|
|
417
|
+
tabIndex: r ? 0 : -1,
|
|
418
|
+
children: /* @__PURE__ */ $(
|
|
397
419
|
"div",
|
|
398
420
|
{
|
|
399
|
-
ref:
|
|
400
|
-
className:
|
|
421
|
+
ref: Z,
|
|
422
|
+
className: we(
|
|
401
423
|
"absolute",
|
|
402
|
-
|
|
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:
|
|
407
|
-
|
|
428
|
+
borderRadius: h - 1,
|
|
429
|
+
cursor: r ? "pointer" : "default",
|
|
430
|
+
...a ? {
|
|
408
431
|
left: 0,
|
|
409
432
|
right: 0,
|
|
410
|
-
top:
|
|
411
|
-
bottom:
|
|
433
|
+
top: 1.5,
|
|
434
|
+
bottom: 1.5
|
|
412
435
|
} : {
|
|
413
436
|
top: 0,
|
|
414
437
|
bottom: 0,
|
|
415
|
-
left:
|
|
416
|
-
right:
|
|
438
|
+
left: 1.5,
|
|
439
|
+
right: 1.5
|
|
417
440
|
}
|
|
418
441
|
},
|
|
419
|
-
onMouseEnter: (
|
|
420
|
-
r
|
|
442
|
+
onMouseEnter: () => {
|
|
443
|
+
r && b(!0);
|
|
421
444
|
},
|
|
422
|
-
onMouseLeave: (
|
|
423
|
-
r
|
|
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
|
-
|
|
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
|
-
},
|
|
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
|
-
},
|
|
463
|
-
|
|
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
|
-
}),
|
|
482
|
+
}), O = xe(
|
|
468
483
|
() => ({
|
|
469
|
-
maxVelocity:
|
|
470
|
-
minVelocity:
|
|
471
|
-
deceleration:
|
|
472
|
-
velocitySampleWindow:
|
|
473
|
-
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
|
-
[
|
|
490
|
+
[V]
|
|
476
491
|
);
|
|
477
|
-
|
|
478
|
-
const
|
|
479
|
-
(
|
|
480
|
-
const { contentSize:
|
|
481
|
-
if (
|
|
482
|
-
|
|
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
|
|
486
|
-
|
|
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
|
-
[
|
|
489
|
-
),
|
|
490
|
-
const
|
|
491
|
-
|
|
492
|
-
}, []),
|
|
493
|
-
(
|
|
494
|
-
if (!
|
|
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:
|
|
497
|
-
if (Math.abs(
|
|
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
|
-
|
|
500
|
-
const M = (
|
|
501
|
-
const
|
|
502
|
-
if (
|
|
503
|
-
|
|
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
|
|
507
|
-
if (
|
|
508
|
-
|
|
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
|
|
512
|
-
let
|
|
513
|
-
const
|
|
514
|
-
|
|
515
|
-
const
|
|
516
|
-
|
|
517
|
-
const
|
|
518
|
-
|
|
519
|
-
const
|
|
520
|
-
if (Math.abs(
|
|
521
|
-
|
|
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
|
-
|
|
539
|
+
I.frame = requestAnimationFrame(M);
|
|
525
540
|
};
|
|
526
|
-
|
|
541
|
+
U.current.frame = requestAnimationFrame(M);
|
|
527
542
|
},
|
|
528
|
-
[
|
|
543
|
+
[P, O, w, H]
|
|
529
544
|
);
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
}, [e,
|
|
533
|
-
if (
|
|
534
|
-
|
|
535
|
-
const
|
|
536
|
-
|
|
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
|
-
|
|
539
|
-
}, [
|
|
540
|
-
const
|
|
541
|
-
if (!
|
|
553
|
+
w(0);
|
|
554
|
+
}, [P, w, e, t]), se(() => {
|
|
555
|
+
const f = (g) => {
|
|
556
|
+
if (!P)
|
|
542
557
|
return;
|
|
543
|
-
|
|
544
|
-
let
|
|
545
|
-
|
|
546
|
-
},
|
|
547
|
-
return
|
|
548
|
-
|
|
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
|
-
}, [
|
|
551
|
-
|
|
565
|
+
}, [P, w, H, t]), Oe(
|
|
566
|
+
ee,
|
|
552
567
|
() => ({
|
|
553
|
-
scrollTo:
|
|
554
|
-
getScrollPosition: () =>
|
|
568
|
+
scrollTo: w,
|
|
569
|
+
getScrollPosition: () => b.current,
|
|
555
570
|
getContentSize: () => e,
|
|
556
|
-
getViewportSize: () =>
|
|
571
|
+
getViewportSize: () => t
|
|
557
572
|
}),
|
|
558
|
-
[
|
|
573
|
+
[w, e, t]
|
|
559
574
|
);
|
|
560
|
-
const
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
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:
|
|
570
|
-
scrollPosition:
|
|
571
|
-
onScroll:
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
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
|
-
] })
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
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
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
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
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
}
|
|
633
|
-
|
|
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,
|
|
674
|
-
this.reset(e,
|
|
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,
|
|
685
|
-
if (this.size = e, this.tree = /* @__PURE__ */ new Map(), this.deltas = /* @__PURE__ */ new Map(), this.total = void 0, typeof
|
|
686
|
-
if (this.valueFn =
|
|
687
|
-
const
|
|
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:
|
|
691
|
-
if (this.baseValue =
|
|
692
|
-
for (let
|
|
693
|
-
const
|
|
694
|
-
if (
|
|
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
|
|
697
|
-
this.deltas.set(
|
|
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 =
|
|
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,
|
|
809
|
+
_calculateMode(e, t) {
|
|
724
810
|
if (!this.valueFn)
|
|
725
811
|
return { mode: 0, materializedValues: [] };
|
|
726
|
-
const
|
|
727
|
-
for (let
|
|
728
|
-
|
|
729
|
-
const r = [...
|
|
730
|
-
if (
|
|
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
|
-
|
|
733
|
-
const
|
|
734
|
-
let
|
|
735
|
-
|
|
736
|
-
const
|
|
737
|
-
let
|
|
738
|
-
for (const
|
|
739
|
-
const
|
|
740
|
-
|
|
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 (
|
|
743
|
-
const
|
|
744
|
-
for (const [
|
|
745
|
-
|
|
746
|
-
const
|
|
747
|
-
|
|
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:
|
|
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,
|
|
759
|
-
return this.updates([{ index: e, value:
|
|
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
|
-
|
|
851
|
+
* @param {ValueUpdate[]} updates - An array of updates, each with an index and the new value.
|
|
766
852
|
*/
|
|
767
853
|
updates(e) {
|
|
768
|
-
const
|
|
769
|
-
|
|
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,
|
|
786
|
-
return this.updateDeltas([{ index: e, change:
|
|
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
|
-
|
|
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:
|
|
796
|
-
if (
|
|
797
|
-
throw new Error(`Index ${
|
|
798
|
-
const r = this.deltas.get(
|
|
799
|
-
this.deltas.set(
|
|
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,
|
|
812
|
-
if (
|
|
890
|
+
_updateTree(e, t) {
|
|
891
|
+
if (t === 0)
|
|
813
892
|
return;
|
|
814
|
-
let
|
|
815
|
-
for (;
|
|
816
|
-
this.tree.set(
|
|
817
|
-
this.total !== void 0 && (this.total +=
|
|
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,
|
|
926
|
+
_materialize(e, t = !0) {
|
|
828
927
|
if (this.valueFn) {
|
|
829
|
-
const
|
|
830
|
-
if (
|
|
831
|
-
const
|
|
832
|
-
this._updateTree(e,
|
|
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 {
|
|
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,
|
|
994
|
+
prefixSum(e, t) {
|
|
850
995
|
if (e < 0)
|
|
851
996
|
return { cumulative: 0, total: this.total, currentValue: 0, safeIndex: 0 };
|
|
852
|
-
const
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
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
|
|
868
|
-
return { cumulative:
|
|
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 {
|
|
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,
|
|
1015
|
+
get(e, t) {
|
|
884
1016
|
if (e < 0 || e >= this.size)
|
|
885
1017
|
throw new Error("Index out of bounds");
|
|
886
|
-
const
|
|
887
|
-
|
|
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 {
|
|
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
|
|
913
|
-
if (
|
|
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
|
|
924
|
-
for (const
|
|
925
|
-
|
|
926
|
-
this.total =
|
|
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, (
|
|
1053
|
+
this.reset(this.size, (i) => r(i), { materialize: !0 });
|
|
941
1054
|
return;
|
|
942
1055
|
}
|
|
943
|
-
const
|
|
944
|
-
let
|
|
945
|
-
for (const [r,
|
|
946
|
-
if (
|
|
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
|
|
949
|
-
for (;
|
|
950
|
-
|
|
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 =
|
|
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
|
|
965
|
-
e +=
|
|
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
|
|
976
|
-
if (e
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
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
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
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,
|
|
1006
|
-
|
|
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
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
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,
|
|
1029
|
-
|
|
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
|
|
1040
|
-
const
|
|
1041
|
-
return Object.is(r.current,
|
|
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
|
-
|
|
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,
|
|
1193
|
-
this.key = e, this.value =
|
|
1145
|
+
constructor(e, t) {
|
|
1146
|
+
this.key = e, this.value = t;
|
|
1194
1147
|
}
|
|
1195
1148
|
}
|
|
1196
|
-
class
|
|
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
|
|
1238
|
-
const e =
|
|
1239
|
-
|
|
1240
|
-
for (; e.current.size >
|
|
1241
|
-
const
|
|
1242
|
-
if (
|
|
1243
|
-
e.current.delete(
|
|
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
|
-
}, [
|
|
1248
|
-
const
|
|
1249
|
-
const
|
|
1250
|
-
if (
|
|
1251
|
-
return
|
|
1252
|
-
}, []), r =
|
|
1253
|
-
(
|
|
1254
|
-
if (
|
|
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
|
|
1257
|
-
if (
|
|
1258
|
-
|
|
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 >=
|
|
1261
|
-
const
|
|
1262
|
-
|
|
1213
|
+
if (e.current.size >= o) {
|
|
1214
|
+
const R = t.current.removeHead();
|
|
1215
|
+
R && e.current.delete(R.key);
|
|
1263
1216
|
}
|
|
1264
|
-
|
|
1217
|
+
p = new bt(u, d), e.current.set(u, p), t.current.addToTail(p);
|
|
1265
1218
|
}
|
|
1266
1219
|
},
|
|
1267
|
-
[
|
|
1268
|
-
),
|
|
1269
|
-
e.current.clear(),
|
|
1270
|
-
}, []), [
|
|
1271
|
-
return
|
|
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
|
|
1274
|
-
const { get:
|
|
1275
|
-
return { get:
|
|
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
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
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
|