@aiquants/virtualscroll 0.1.0 → 0.2.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 ADDED
@@ -0,0 +1,1105 @@
1
+ import me, { useState as W, useRef as Y, useEffect as X, forwardRef as de, useReducer as ge, useMemo as ne, useCallback as L, useLayoutEffect as oe, useImperativeHandle as he, useId as be } from "react";
2
+ import { twMerge as ae } from "tailwind-merge";
3
+ var re = { exports: {} }, K = {};
4
+ /**
5
+ * @license React
6
+ * react-jsx-runtime.production.js
7
+ *
8
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
9
+ *
10
+ * This source code is licensed under the MIT license found in the
11
+ * LICENSE file in the root directory of this source tree.
12
+ */
13
+ var ie;
14
+ function ve() {
15
+ if (ie) return K;
16
+ ie = 1;
17
+ var u = Symbol.for("react.transitional.element"), e = Symbol.for("react.fragment");
18
+ function n(r, s, a) {
19
+ var o = null;
20
+ if (a !== void 0 && (o = "" + a), s.key !== void 0 && (o = "" + s.key), "key" in s) {
21
+ a = {};
22
+ for (var d in s)
23
+ d !== "key" && (a[d] = s[d]);
24
+ } else a = s;
25
+ return s = a.ref, {
26
+ $$typeof: u,
27
+ type: r,
28
+ key: o,
29
+ ref: s !== void 0 ? s : null,
30
+ props: a
31
+ };
32
+ }
33
+ return K.Fragment = e, K.jsx = n, K.jsxs = n, K;
34
+ }
35
+ var ee = {};
36
+ /**
37
+ * @license React
38
+ * react-jsx-runtime.development.js
39
+ *
40
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
41
+ *
42
+ * This source code is licensed under the MIT license found in the
43
+ * LICENSE file in the root directory of this source tree.
44
+ */
45
+ var le;
46
+ function pe() {
47
+ return le || (le = 1, process.env.NODE_ENV !== "production" && (function() {
48
+ function u(t) {
49
+ if (t == null) return null;
50
+ if (typeof t == "function")
51
+ return t.$$typeof === H ? null : t.displayName || t.name || null;
52
+ if (typeof t == "string") return t;
53
+ switch (t) {
54
+ case F:
55
+ return "Fragment";
56
+ case k:
57
+ return "Profiler";
58
+ case b:
59
+ return "StrictMode";
60
+ case y:
61
+ return "Suspense";
62
+ case N:
63
+ return "SuspenseList";
64
+ case J:
65
+ return "Activity";
66
+ }
67
+ if (typeof t == "object")
68
+ switch (typeof t.tag == "number" && console.error(
69
+ "Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
70
+ ), t.$$typeof) {
71
+ case I:
72
+ return "Portal";
73
+ case f:
74
+ return (t.displayName || "Context") + ".Provider";
75
+ case S:
76
+ return (t._context.displayName || "Context") + ".Consumer";
77
+ case w:
78
+ var i = t.render;
79
+ return t = t.displayName, t || (t = i.displayName || i.name || "", t = t !== "" ? "ForwardRef(" + t + ")" : "ForwardRef"), t;
80
+ case $:
81
+ return i = t.displayName || null, i !== null ? i : u(t.type) || "Memo";
82
+ case _:
83
+ i = t._payload, t = t._init;
84
+ try {
85
+ return u(t(i));
86
+ } catch {
87
+ }
88
+ }
89
+ return null;
90
+ }
91
+ function e(t) {
92
+ return "" + t;
93
+ }
94
+ function n(t) {
95
+ try {
96
+ e(t);
97
+ var i = !1;
98
+ } catch {
99
+ i = !0;
100
+ }
101
+ if (i) {
102
+ i = console;
103
+ var m = i.error, p = typeof Symbol == "function" && Symbol.toStringTag && t[Symbol.toStringTag] || t.constructor.name || "Object";
104
+ return m.call(
105
+ i,
106
+ "The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
107
+ p
108
+ ), e(t);
109
+ }
110
+ }
111
+ function r(t) {
112
+ if (t === F) return "<>";
113
+ if (typeof t == "object" && t !== null && t.$$typeof === _)
114
+ return "<...>";
115
+ try {
116
+ var i = u(t);
117
+ return i ? "<" + i + ">" : "<...>";
118
+ } catch {
119
+ return "<...>";
120
+ }
121
+ }
122
+ function s() {
123
+ var t = U.A;
124
+ return t === null ? null : t.getOwner();
125
+ }
126
+ function a() {
127
+ return Error("react-stack-top-frame");
128
+ }
129
+ function o(t) {
130
+ if (Z.call(t, "key")) {
131
+ var i = Object.getOwnPropertyDescriptor(t, "key").get;
132
+ if (i && i.isReactWarning) return !1;
133
+ }
134
+ return t.key !== void 0;
135
+ }
136
+ function d(t, i) {
137
+ function m() {
138
+ G || (G = !0, console.error(
139
+ "%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",
140
+ i
141
+ ));
142
+ }
143
+ m.isReactWarning = !0, Object.defineProperty(t, "key", {
144
+ get: m,
145
+ configurable: !0
146
+ });
147
+ }
148
+ function l() {
149
+ var t = u(this.type);
150
+ return B[t] || (B[t] = !0, console.error(
151
+ "Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release."
152
+ )), t = this.props.ref, t !== void 0 ? t : null;
153
+ }
154
+ function c(t, i, m, p, P, T, C, D) {
155
+ return m = T.ref, t = {
156
+ $$typeof: E,
157
+ type: t,
158
+ key: i,
159
+ props: T,
160
+ _owner: P
161
+ }, (m !== void 0 ? m : null) !== null ? Object.defineProperty(t, "ref", {
162
+ enumerable: !1,
163
+ get: l
164
+ }) : Object.defineProperty(t, "ref", { enumerable: !1, value: null }), t._store = {}, Object.defineProperty(t._store, "validated", {
165
+ configurable: !1,
166
+ enumerable: !1,
167
+ writable: !0,
168
+ value: 0
169
+ }), Object.defineProperty(t, "_debugInfo", {
170
+ configurable: !1,
171
+ enumerable: !1,
172
+ writable: !0,
173
+ value: null
174
+ }), Object.defineProperty(t, "_debugStack", {
175
+ configurable: !1,
176
+ enumerable: !1,
177
+ writable: !0,
178
+ value: C
179
+ }), Object.defineProperty(t, "_debugTask", {
180
+ configurable: !1,
181
+ enumerable: !1,
182
+ writable: !0,
183
+ value: D
184
+ }), Object.freeze && (Object.freeze(t.props), Object.freeze(t)), t;
185
+ }
186
+ function g(t, i, m, p, P, T, C, D) {
187
+ var V = i.children;
188
+ if (V !== void 0)
189
+ if (p)
190
+ if (j(V)) {
191
+ for (p = 0; p < V.length; p++)
192
+ x(V[p]);
193
+ Object.freeze && Object.freeze(V);
194
+ } else
195
+ console.error(
196
+ "React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."
197
+ );
198
+ else x(V);
199
+ if (Z.call(i, "key")) {
200
+ V = u(t);
201
+ var q = Object.keys(i).filter(function(se) {
202
+ return se !== "key";
203
+ });
204
+ p = 0 < q.length ? "{key: someKey, " + q.join(": ..., ") + ": ...}" : "{key: someKey}", v[V + p] || (q = 0 < q.length ? "{" + q.join(": ..., ") + ": ...}" : "{}", console.error(
205
+ `A props object containing a "key" prop is being spread into JSX:
206
+ let props = %s;
207
+ <%s {...props} />
208
+ React keys must be passed directly to JSX without using spread:
209
+ let props = %s;
210
+ <%s key={someKey} {...props} />`,
211
+ p,
212
+ V,
213
+ q,
214
+ V
215
+ ), v[V + p] = !0);
216
+ }
217
+ if (V = null, m !== void 0 && (n(m), V = "" + m), o(i) && (n(i.key), V = "" + i.key), "key" in i) {
218
+ m = {};
219
+ for (var Q in i)
220
+ Q !== "key" && (m[Q] = i[Q]);
221
+ } else m = i;
222
+ return V && d(
223
+ m,
224
+ typeof t == "function" ? t.displayName || t.name || "Unknown" : t
225
+ ), c(
226
+ t,
227
+ V,
228
+ T,
229
+ P,
230
+ s(),
231
+ m,
232
+ C,
233
+ D
234
+ );
235
+ }
236
+ function x(t) {
237
+ typeof t == "object" && t !== null && t.$$typeof === E && t._store && (t._store.validated = 1);
238
+ }
239
+ var R = me, E = Symbol.for("react.transitional.element"), I = Symbol.for("react.portal"), F = Symbol.for("react.fragment"), b = Symbol.for("react.strict_mode"), k = Symbol.for("react.profiler"), S = Symbol.for("react.consumer"), f = Symbol.for("react.context"), w = Symbol.for("react.forward_ref"), y = Symbol.for("react.suspense"), N = Symbol.for("react.suspense_list"), $ = Symbol.for("react.memo"), _ = Symbol.for("react.lazy"), J = Symbol.for("react.activity"), H = Symbol.for("react.client.reference"), U = R.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, Z = Object.prototype.hasOwnProperty, j = Array.isArray, M = console.createTask ? console.createTask : function() {
240
+ return null;
241
+ };
242
+ R = {
243
+ react_stack_bottom_frame: function(t) {
244
+ return t();
245
+ }
246
+ };
247
+ var G, B = {}, te = R.react_stack_bottom_frame.bind(
248
+ R,
249
+ a
250
+ )(), h = M(r(a)), v = {};
251
+ ee.Fragment = F, ee.jsx = function(t, i, m, p, P) {
252
+ var T = 1e4 > U.recentlyCreatedOwnerStacks++;
253
+ return g(
254
+ t,
255
+ i,
256
+ m,
257
+ !1,
258
+ p,
259
+ P,
260
+ T ? Error("react-stack-top-frame") : te,
261
+ T ? M(r(t)) : h
262
+ );
263
+ }, ee.jsxs = function(t, i, m, p, P) {
264
+ var T = 1e4 > U.recentlyCreatedOwnerStacks++;
265
+ return g(
266
+ t,
267
+ i,
268
+ m,
269
+ !0,
270
+ p,
271
+ P,
272
+ T ? Error("react-stack-top-frame") : te,
273
+ T ? M(r(t)) : h
274
+ );
275
+ };
276
+ })()), ee;
277
+ }
278
+ var ue;
279
+ function xe() {
280
+ return ue || (ue = 1, process.env.NODE_ENV === "production" ? re.exports = ve() : re.exports = pe()), re.exports;
281
+ }
282
+ var z = xe();
283
+ const A = {
284
+ debug(u, ...e) {
285
+ typeof window < "u" && window.localStorage?.getItem("debug") === "true" && console.debug(`[VirtualScroll] ${u}`, ...e);
286
+ },
287
+ warn(u, ...e) {
288
+ console.warn(`[VirtualScroll] ${u}`, ...e);
289
+ },
290
+ error(u, ...e) {
291
+ console.error(`[VirtualScroll] ${u}`, ...e);
292
+ }
293
+ }, O = (u, e, n) => Math.min(n, Math.max(e, u)), ce = (u, e, n) => {
294
+ const r = "touches" in u.nativeEvent, s = r ? u.nativeEvent.touches[0] : u.nativeEvent, a = (d) => {
295
+ r && d.cancelable && d.preventDefault();
296
+ const l = "touches" in d ? d.touches[0] : d;
297
+ e({
298
+ deltaX: l.clientX - s.clientX,
299
+ deltaY: l.clientY - s.clientY
300
+ });
301
+ }, o = () => {
302
+ r ? (document.removeEventListener("touchmove", a), document.removeEventListener("touchend", o)) : (document.removeEventListener("mousemove", a), document.removeEventListener("mouseup", o)), n?.();
303
+ };
304
+ r ? (document.addEventListener("touchmove", a, { passive: !1 }), document.addEventListener("touchend", o)) : (document.addEventListener("mousemove", a), document.addEventListener("mouseup", o));
305
+ }, Te = 20, Ee = ({ contentSize: u, viewportSize: e, scrollPosition: n, onScroll: r, horizontal: s = !1, scrollBarWidth: a = 12, className: o, ariaControls: d }) => {
306
+ const [l, c] = W(!1), g = Y(null), x = e / u, R = Math.max(Te, x * e), E = u - e, I = n / E * (e - R), F = u > e;
307
+ X(() => {
308
+ g.current && (l ? g.current.style.backgroundColor = "#4F4F4F" : g.current.style.backgroundColor = "#7F7F7F");
309
+ }, [l]);
310
+ const b = (f) => O(f / (e - R) * E, 0, E), k = (f) => {
311
+ if (!F || "button" in f && f.button !== 0 || f.ctrlKey)
312
+ return;
313
+ f.stopPropagation();
314
+ const w = I;
315
+ c(!0), ce(
316
+ f,
317
+ ({ deltaX: y, deltaY: N }) => {
318
+ r?.(b(w + (s ? y : N)), I);
319
+ },
320
+ () => {
321
+ c(!1);
322
+ }
323
+ );
324
+ }, S = (f) => {
325
+ if (!F || "button" in f && f.button !== 0 || f.ctrlKey)
326
+ return;
327
+ const y = "touches" in f.nativeEvent ? f.nativeEvent.touches[0] : f.nativeEvent, N = s ? y.clientX : y.clientY, $ = f.currentTarget.getBoundingClientRect(), J = (s ? N - $.left : N - $.top) - R / 2;
328
+ r?.(b(J), I), ce(f, ({ deltaX: H, deltaY: U }) => {
329
+ r?.(b(J + (s ? H : U)), I);
330
+ });
331
+ };
332
+ return (
333
+ // スクロールバーのコンテナ
334
+ /* @__PURE__ */ z.jsx(
335
+ "div",
336
+ {
337
+ className: ae("group relative cursor-default select-none", o),
338
+ style: {
339
+ [s ? "width" : "height"]: e,
340
+ [s ? "height" : "width"]: a,
341
+ backgroundColor: "white",
342
+ userSelect: "none"
343
+ },
344
+ onMouseDown: S,
345
+ onTouchStart: S,
346
+ role: "scrollbar",
347
+ tabIndex: -1,
348
+ "aria-controls": d,
349
+ "aria-valuenow": n,
350
+ "aria-valuemin": 0,
351
+ "aria-valuemax": E,
352
+ "aria-orientation": s ? "horizontal" : "vertical",
353
+ children: u > e && // スクロールバーのつまみの当たり判定を広げるためのラッパー
354
+ /* @__PURE__ */ z.jsx(
355
+ "div",
356
+ {
357
+ className: "group absolute",
358
+ style: {
359
+ [s ? "width" : "height"]: R,
360
+ [s ? "left" : "top"]: I,
361
+ // 当たり判定を上下または左右に広げる
362
+ ...s ? { top: 0, bottom: 0 } : { left: 0, right: 0 }
363
+ },
364
+ onMouseDown: k,
365
+ onTouchStart: k,
366
+ role: "slider",
367
+ "aria-orientation": s ? "horizontal" : "vertical",
368
+ "aria-valuenow": n,
369
+ "aria-valuemin": 0,
370
+ "aria-valuemax": E,
371
+ tabIndex: 0,
372
+ children: /* @__PURE__ */ z.jsx(
373
+ "div",
374
+ {
375
+ ref: g,
376
+ className: ae(
377
+ "absolute",
378
+ s ? `inset-x-0 inset-y-[1.5px] group-hover:inset-y-[-0.5px] ${l ? "inset-y-[-2px]" : "group-active:inset-y-[-2px]"}` : `inset-x-[1.5px] inset-y-0 group-hover:inset-x-[-0.5px] ${l ? "inset-x-[-2px]" : "group-active:inset-x-[-2px]"}`
379
+ ),
380
+ style: {
381
+ backgroundColor: "#7F7F7F",
382
+ borderRadius: a - 1,
383
+ // Tailwind が適用されない場合のフォールバック
384
+ ...s ? {
385
+ left: 0,
386
+ right: 0,
387
+ top: l ? -2 : 1.5,
388
+ bottom: l ? -2 : 1.5
389
+ } : {
390
+ top: 0,
391
+ bottom: 0,
392
+ left: l ? -2 : 1.5,
393
+ right: l ? -2 : 1.5
394
+ }
395
+ },
396
+ onMouseEnter: (f) => {
397
+ s ? (f.currentTarget.style.top = "-0.5px", f.currentTarget.style.bottom = "-0.5px") : (f.currentTarget.style.left = "-0.5px", f.currentTarget.style.right = "-0.5px"), l || (f.currentTarget.style.backgroundColor = "#5F5F5F");
398
+ },
399
+ onMouseLeave: (f) => {
400
+ s ? (f.currentTarget.style.top = l ? "-2px" : "1.5px", f.currentTarget.style.bottom = l ? "-2px" : "1.5px") : (f.currentTarget.style.left = l ? "-2px" : "1.5px", f.currentTarget.style.right = l ? "-2px" : "1.5px"), l || (f.currentTarget.style.backgroundColor = "#7F7F7F");
401
+ }
402
+ }
403
+ )
404
+ }
405
+ )
406
+ }
407
+ )
408
+ );
409
+ }, _e = de(({ children: u, contentSize: e, viewportSize: n, scrollBarWidth: r = 12, onScroll: s, className: a, style: o, background: d }, l) => {
410
+ const c = Y(0), [g, x] = ge((k) => k + 1, 0), R = Y(null);
411
+ A.debug("[ScrollPane] ScrollPane rendered", { contentSize: e, viewportSize: n, scrollBarWidth: r, className: a, style: o });
412
+ const E = ne(() => e > n, [e, n]), I = L(
413
+ (k) => {
414
+ const S = e > n, f = c.current;
415
+ if (A.debug("[ScrollPane] scrollTo called", { newPosition: k, contentSize: e, viewportSize: n, currentIsScrollable: S, prevPosition: f }), !S) {
416
+ c.current !== 0 && (c.current = 0, s?.(0, f));
417
+ return;
418
+ }
419
+ const w = typeof k == "function" ? k(c.current) : k, y = O(w, 0, e - n);
420
+ c.current !== y && (c.current = y, s?.(y, f));
421
+ },
422
+ [s, e, n]
423
+ );
424
+ oe(() => {
425
+ if (E) {
426
+ A.debug("[ScrollPane] Adjusting scroll position due to content or viewport size change", { contentSize: e, viewportSize: n, scrollPosition: c.current });
427
+ const k = O(e - n, 0, e);
428
+ c.current > k && I(k);
429
+ } else
430
+ I(0);
431
+ }, [E, I, e, n]), X(() => {
432
+ const k = (f) => {
433
+ if (!E)
434
+ return;
435
+ f.preventDefault();
436
+ let w = f.deltaY;
437
+ f.deltaMode === 1 ? w *= 16 : f.deltaMode === 2 && (w *= n), A.debug("[ScrollPane] wheel event", { deltaY: w, scrollPosition: c.current }), I((y) => y + w);
438
+ }, S = R.current;
439
+ return S && S.addEventListener("wheel", k, { passive: !1 }), () => {
440
+ S && S.removeEventListener("wheel", k);
441
+ };
442
+ }, [E, I, n]), he(
443
+ l,
444
+ () => ({
445
+ scrollTo: I,
446
+ getScrollPosition: () => c.current,
447
+ getContentSize: () => e,
448
+ getViewportSize: () => n
449
+ }),
450
+ [I, e, n]
451
+ );
452
+ const F = be();
453
+ return ne(() => /* @__PURE__ */ z.jsxs("div", { ref: R, className: ae("flex", a), style: o, children: [
454
+ /* @__PURE__ */ z.jsxs("div", { className: "relative h-full flex-1 overflow-hidden", style: { height: n }, id: F, children: [
455
+ d,
456
+ u(c.current)
457
+ ] }),
458
+ E && /* @__PURE__ */ z.jsx(Ee, { contentSize: e, viewportSize: n, scrollPosition: c.current, onScroll: I, scrollBarWidth: r, ariaControls: F })
459
+ ] }), [u, e, n, r, a, o, E, I, F, d]);
460
+ });
461
+ class Re {
462
+ /**
463
+ * @private
464
+ * @property {Map<number, number>} tree - The Map storing the Fenwick tree structure, specifically the sums of deltas. It is 1-indexed.
465
+ * @property {Map<number, number>} tree - Fenwick Tree 構造を格納する Map。特に差分の合計を保持する。1-indexed。
466
+ */
467
+ tree;
468
+ /**
469
+ * @private
470
+ * @property {Map<number, number>} deltas - The Map storing the differences (deltas) from the base value at each index.
471
+ * @property {Map<number, number>} deltas - 各インデックスにおける基準値との差分 (delta) を格納する Map。
472
+ */
473
+ deltas;
474
+ /**
475
+ * @private
476
+ * @property {number} size - The number of elements the tree manages.
477
+ * @property {number} size - ツリーが管理する要素数。
478
+ */
479
+ size;
480
+ /**
481
+ * @private
482
+ * @property {number} baseValue - The uniform base value for all elements, used to optimize memory.
483
+ * @property {number} baseValue - 全要素の均一な基準値。メモリ最適化のために使用。
484
+ */
485
+ baseValue;
486
+ /**
487
+ * @private
488
+ * @property {((index: number) => number) | undefined} valueFn - A function to generate values, stored for lazy initialization.
489
+ * @property {((index: number) => number) | undefined} valueFn - 値を生成するための関数。遅延初期化のために保存される。
490
+ */
491
+ valueFn;
492
+ total;
493
+ /**
494
+ * @constructor
495
+ * @description Initializes the Fenwick Tree.
496
+ * @description Fenwick Tree の初期化。
497
+ * @param {number} size - The total number of items.
498
+ * @param {number | ((index: number) => number)} valueOrFn - The value for all elements, or a function to generate values.
499
+ * @param {{ sampleRange?: { from: number; to: number }, materialize?: boolean }} [options] - Optional settings for initialization.
500
+ */
501
+ constructor(e, n, r) {
502
+ this.reset(e, n, r);
503
+ }
504
+ /**
505
+ * @method reset
506
+ * @description Resets the Fenwick Tree with a new size and initial values.
507
+ * @description Fenwick Tree を新しいサイズと初期値でリセット。
508
+ * @param {number} size - The total number of items.
509
+ * @param {number | ((index: number) => number)} valueOrFn - The value for all elements, or a function to generate values.
510
+ * @param {{ sampleRange?: { from: number; to: number }, materialize?: boolean }} [options] - Optional settings for initialization.
511
+ */
512
+ reset(e, n, r) {
513
+ if (this.size = e, this.tree = /* @__PURE__ */ new Map(), this.deltas = /* @__PURE__ */ new Map(), this.total = void 0, typeof n == "function") {
514
+ if (this.valueFn = n, this.size > 0) {
515
+ const a = r?.sampleRange ?? {
516
+ from: 0,
517
+ to: Math.min(99, this.size - 1)
518
+ }, { mode: o, materializedValues: d } = this._calculateMode(a.from, a.to);
519
+ if (this.baseValue = o, r?.materialize)
520
+ for (let l = 0; l < d.length; l++) {
521
+ const c = d[l], g = a.from + l;
522
+ if (g >= this.size)
523
+ break;
524
+ const x = c - this.baseValue;
525
+ this.deltas.set(g, x), this._updateTree(g, x);
526
+ }
527
+ } else
528
+ this.baseValue = 0;
529
+ this.total = this.getTotal();
530
+ } else
531
+ this.valueFn = void 0, this.baseValue = n, this.total = this.baseValue * this.size;
532
+ }
533
+ /**
534
+ * @method setValueFn
535
+ * @description Updates the value function and re-initializes the tree.
536
+ * @description 値関数を更新し、ツリーを再初期化する。
537
+ * @param {number | ((index: number) => number)} valueOrFn - The new value for all elements, or a function to generate values.
538
+ */
539
+ setValueFn(e) {
540
+ typeof e == "function" ? this.valueFn = e : (this.valueFn = void 0, this.baseValue = e);
541
+ }
542
+ /**
543
+ * @private
544
+ * @method _calculateMode
545
+ * @description Calculates the mode (most frequent value) within a given range of values generated by `valueFn`. If multiple modes exist, it returns their average. If no value appears more than once, it returns the median of the range. This approach helps determine a representative `baseValue` for the Fenwick tree, especially for data with high variance. It also returns the array of values generated within the range for reuse.
546
+ * @description `valueFn` によって生成される値の指定された範囲内の最頻値を計算する。最頻値が複数存在する場合は、それらの平均値を返す。どの値も複数回出現しない場合は、範囲の中央値を返す。このアプローチは、特に分散の大きいデータに対して、Fenwick Tree の代表的な `baseValue` を決定するのに役立つ。また、再利用のために範囲内で生成された値の配列も返す。
547
+ * @param {number} from - The starting index of the range (inclusive).
548
+ * @param {number} to - The ending index of the range (inclusive).
549
+ * @returns {{ mode: number; materializedValues: number[] }} An object containing the calculated mode and the array of generated values.
550
+ */
551
+ _calculateMode(e, n) {
552
+ if (!this.valueFn)
553
+ return { mode: 0, materializedValues: [] };
554
+ const r = [];
555
+ for (let c = e; c <= n && !(c >= this.size); c++)
556
+ r.push(this.valueFn(c));
557
+ const s = [...r];
558
+ if (r.length === 0)
559
+ return { mode: 0, materializedValues: [] };
560
+ r.sort((c, g) => c - g);
561
+ const a = Math.floor(r.length / 2);
562
+ let o;
563
+ r.length % 2 === 0 ? o = Math.floor((r[a - 1] + r[a]) / 2) : o = r[a];
564
+ const d = /* @__PURE__ */ new Map();
565
+ let l = 0;
566
+ for (const c of r) {
567
+ const g = (d.get(c) ?? 0) + 1;
568
+ d.set(c, g), g > l && (l = g);
569
+ }
570
+ if (l > 1) {
571
+ const c = [];
572
+ for (const [x, R] of d.entries())
573
+ R === l && c.push(x);
574
+ const g = c.reduce((x, R) => x + R, 0);
575
+ o = Math.floor(g / c.length);
576
+ }
577
+ return { mode: o, materializedValues: s };
578
+ }
579
+ /**
580
+ * @method update
581
+ * @description Updates the value at a given index.
582
+ * @description 指定されたインデックスの値を更新。
583
+ * @param {number} index - The 0-based index to update.
584
+ * @param {number} value - The new value.
585
+ */
586
+ update(e, n) {
587
+ return this.updates([{ index: e, value: n }]);
588
+ }
589
+ /**
590
+ * @method updates
591
+ * @description Updates the values at given indices.
592
+ * @description 指定されたインデックスの値を更新。
593
+ * @param {{ index: number; value: number }[]} updates - An array of updates, each with an index and the new value.
594
+ */
595
+ updates(e) {
596
+ const n = e.map(({ index: r, value: s }) => {
597
+ if (r < 0 || r >= this.size)
598
+ throw new Error(`Index ${r} out of bounds`);
599
+ if (s < 0)
600
+ throw new Error("Value cannot be negative.");
601
+ const a = this.deltas.has(r) ? (this.deltas.get(r) ?? 0) + this.baseValue : this.baseValue, o = s - a;
602
+ return { index: r, change: o };
603
+ }).filter((r) => r.change !== 0);
604
+ return n.length > 0 ? this.updateDeltas(n) : this.total;
605
+ }
606
+ /**
607
+ * @method updateDelta
608
+ * @description Updates the delta at a given index and propagates the change through the tree.
609
+ * @description 指定されたインデックスのデルタを更新し、変更をツリーに伝播させる。
610
+ * @param {number} index - The 0-based index to update.
611
+ * @param {number} change - The value to add to the delta at the given index.
612
+ */
613
+ updateDelta(e, n) {
614
+ return this.updateDeltas([{ index: e, change: n }]);
615
+ }
616
+ /**
617
+ * @method updateDeltas
618
+ * @description Updates the deltas at given indices and propagates the changes through the tree.
619
+ * @description 指定されたインデックスのデルタを更新し、変更をツリーに伝播させる。
620
+ * @param {{ index: number; change: number }[]} updates - An array of updates, each with an index and the change to apply.
621
+ */
622
+ updateDeltas(e) {
623
+ for (const { index: n, change: r } of e) {
624
+ if (n < 0 || n >= this.size)
625
+ throw new Error(`Index ${n} out of bounds`);
626
+ const s = this.deltas.get(n) ?? 0;
627
+ this.deltas.set(n, s + r), this._updateTree(n, r);
628
+ }
629
+ return this.total;
630
+ }
631
+ /**
632
+ * @private
633
+ * @method _updateTree
634
+ * @description Updates the Fenwick tree and the total sum with a given change.
635
+ * @description Fenwick Tree と合計値を指定された変更で更新する。
636
+ * @param {number} index - The 0-based index that changed.
637
+ * @param {number} change - The change in value.
638
+ */
639
+ _updateTree(e, n) {
640
+ if (n === 0)
641
+ return;
642
+ let r = e + 1;
643
+ for (; r <= this.size; )
644
+ this.tree.set(r, (this.tree.get(r) ?? 0) + n), r += r & -r;
645
+ this.total !== void 0 && (this.total += n);
646
+ }
647
+ /**
648
+ * @private
649
+ * @method _materialize
650
+ * @description Materializes the value at a specific index if it hasn't been already.
651
+ * @description 特定のインデックスの値がまだ具現化されていない場合に具現化する。
652
+ * @param {number} index - The 0-based index to materialize.
653
+ * @param {boolean} [updateTree=true] - Whether to update the Fenwick tree after materialization.
654
+ */
655
+ _materialize(e, n = !0) {
656
+ if (this.valueFn) {
657
+ const r = this.deltas.get(e) ?? 0, a = this.valueFn(e) - this.baseValue;
658
+ if (a !== r && (this.deltas.set(e, a), n)) {
659
+ const o = a - r;
660
+ this._updateTree(e, o);
661
+ }
662
+ }
663
+ }
664
+ /**
665
+ * @method prefixSum
666
+ * @description Calculates the cumulative sum up to a given index (inclusive) in O(log n) time.
667
+ * @description 指定されたインデックスまでの累積和を O(log n) で計算。
668
+ * @param {number} index - The 0-based index to prefixSum up to.
669
+ * @param {object} [options] - Optional settings for materializing values.
670
+ * @param {object} [options.materializeOption] - Options to control materialization.
671
+ * @param {boolean} [options.materializeOption.materialize=false] - Whether to materialize values.
672
+ * @param {object[]} [options.materializeOption.ranges] - An optional array of ranges to materialize values for.
673
+ * @param {number} options.materializeOption.ranges.from - The starting index of the range.
674
+ * @param {number} options.materializeOption.ranges.to - The ending index of the range.
675
+ * @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.
676
+ */
677
+ prefixSum(e, n) {
678
+ if (e < 0)
679
+ return { cumulative: 0, total: this.total, currentValue: 0, safeIndex: 0 };
680
+ const r = O(e, 0, this.size - 1), s = n?.materializeOption;
681
+ if (s?.materialize && this.valueFn) {
682
+ if (s.ranges)
683
+ for (const l of s.ranges) {
684
+ const c = l.from, g = Math.min(l.to, this.size - 1);
685
+ for (let x = c; x <= g; x++)
686
+ this._materialize(x);
687
+ }
688
+ this._materialize(r);
689
+ }
690
+ let a = 0, o = r + 1;
691
+ for (; o > 0; ) {
692
+ const l = this.tree.get(o) ?? 0;
693
+ a += l, o -= o & -o;
694
+ }
695
+ const d = s?.materialize ? this.get(r) : (this.deltas.get(r) || 0) + this.baseValue;
696
+ return { cumulative: a + this.baseValue * (r + 1), total: this.total, currentValue: d, safeIndex: r };
697
+ }
698
+ /**
699
+ * @method get
700
+ * @description Gets the value at a specific index.
701
+ * @description 特定のインデックスの値を取得。
702
+ * @param {number} index - The 0-based index to get.
703
+ * @param {object} [options] - Optional settings for materializing values.
704
+ * @param {object} [options.materializeOption] - Options to control materialization.
705
+ * @param {boolean} [options.materializeOption.materialize=false] - Whether to materialize values.
706
+ * @param {object[]} [options.materializeOption.ranges] - An optional array of ranges to materialize values for.
707
+ * @param {number} options.materializeOption.ranges.from - The starting index of the range.
708
+ * @param {number} options.materializeOption.ranges.to - The ending index of the range.
709
+ * @returns {number} The value at the given index.
710
+ */
711
+ get(e, n) {
712
+ if (e < 0 || e >= this.size)
713
+ throw new Error("Index out of bounds");
714
+ const r = n?.materializeOption;
715
+ if (r?.materialize && this.valueFn)
716
+ if (r.ranges) {
717
+ for (const s of r.ranges) {
718
+ const a = s.from, o = Math.min(s.to, this.size - 1);
719
+ for (let d = a; d <= o; d++)
720
+ this._materialize(d);
721
+ }
722
+ e >= r.ranges[0].from && e <= r.ranges[r.ranges.length - 1].to && this._materialize(e);
723
+ } else
724
+ this._materialize(e);
725
+ return (this.deltas.get(e) ?? 0) + this.baseValue;
726
+ }
727
+ /**
728
+ * @method getTotal
729
+ * @description Gets the total sum of all values in the tree.
730
+ * @description ツリー内のすべての値の合計を取得。
731
+ * @param {object} [options] - Optional settings for materializing values.
732
+ * @param {object} [options.materializeOption] - Options to control materialization.
733
+ * @param {boolean} [options.materializeOption.materialize=false] - Whether to materialize values.
734
+ * @param {object[]} [options.materializeOption.ranges] - An optional array of ranges to materialize values for.
735
+ * @param {number} options.materializeOption.ranges.from - The starting index of the range.
736
+ * @param {number} options.materializeOption.ranges.to - The ending index of the range.
737
+ * @returns {number} The total sum of all values.
738
+ */
739
+ getTotal(e) {
740
+ const n = e?.materializeOption;
741
+ if (n?.materialize && this.valueFn && n.ranges)
742
+ for (const r of n.ranges) {
743
+ const s = r.from, a = Math.min(r.to, this.size - 1);
744
+ for (let o = s; o <= a; o++)
745
+ this._materialize(o);
746
+ }
747
+ if (this.total === void 0)
748
+ if (this.size === 0)
749
+ this.total = 0;
750
+ else {
751
+ let r = this.baseValue * this.size;
752
+ for (const s of this.deltas.values())
753
+ r += s;
754
+ this.total = r, console.assert(this.prefixSum(this.getSize() - 1).cumulative === this.prefixSum(this.getSize() - 1).total, "Inconsistent Fenwick Tree state");
755
+ }
756
+ return this.total;
757
+ }
758
+ /**
759
+ * @method rebuildTree
760
+ * @description Rebuilds the Fenwick Tree from the existing `baseValue` and `deltas`. This corrects any discrepancies in the tree's internal state, such as those caused by floating-point errors, by recalculating the tree structure and the total sum from the source `deltas`. This method does not re-materialize values from `valueFn`.
761
+ * @description 既存の `baseValue` と `deltas` から Fenwick Tree を再構築します。これにより、`deltas` からツリー構造と合計値を再計算することで、浮動小数点誤差などによって生じた内部状態の不一致を修正します。このメソッドは `valueFn` から値を再具現化しません。
762
+ * @param {object} [options] - Optional settings for rebuilding.
763
+ * @param {boolean} [options.materialize=false] - If true and `valueFn` is provided, re-materializes all values, recalculating `deltas` and `baseValue`.
764
+ */
765
+ rebuildTree(e) {
766
+ if (e?.materialize && this.valueFn) {
767
+ const s = this.valueFn;
768
+ this.reset(this.size, (a) => s(a), { materialize: !0 });
769
+ return;
770
+ }
771
+ const n = /* @__PURE__ */ new Map();
772
+ let r = this.baseValue * this.size;
773
+ for (const [s, a] of this.deltas.entries()) {
774
+ if (r += a, a === 0)
775
+ continue;
776
+ let o = s + 1;
777
+ for (; o <= this.size; )
778
+ n.set(o, (n.get(o) ?? 0) + a), o += o & -o;
779
+ }
780
+ this.tree = n, this.total = r;
781
+ }
782
+ /**
783
+ * @method calculateAccumulatedError
784
+ * @description Compares the cached total sum with a theoretical total calculated directly from the source values (`deltas` and `baseValue`, or `valueFn`). This helps detect any discrepancy in the tree's cached state, which might be caused by floating-point errors or other inconsistencies.
785
+ * @description キャッシュされている合計値と、元の値 (`deltas` と `baseValue`、または `valueFn`) から直接計算した理論上の合計値とを比較します。これにより、浮動小数点数の累積誤差やその他の不整合によって生じる可能性のある、ツリーのキャッシュ状態の不一致を検出できます。
786
+ * @returns {number} The difference between the cached total and the theoretical total.
787
+ */
788
+ calculateAccumulatedError() {
789
+ if (this.total === void 0)
790
+ return 0;
791
+ let e = this.baseValue * this.size;
792
+ for (const n of this.deltas.values())
793
+ e += n;
794
+ return this.total - e;
795
+ }
796
+ /**
797
+ * @method changeSize
798
+ * @description Changes the size of the Fenwick Tree.
799
+ * @description Fenwick Tree のサイズを変更する。
800
+ * @param {number} newSize - The new size of the tree.
801
+ */
802
+ changeSize(e) {
803
+ const n = this.size;
804
+ if (e !== n) {
805
+ if (e < n)
806
+ for (const r of this.deltas.keys())
807
+ r >= e && this.deltas.delete(r);
808
+ this.size = e, this.rebuildTree(), console.assert(this.prefixSum(this.getSize() - 1).cumulative === this.prefixSum(this.getSize() - 1).total, "Inconsistent Fenwick Tree state");
809
+ }
810
+ }
811
+ /**
812
+ * @method getSize
813
+ * @description Gets the size of the tree.
814
+ * @description ツリーのサイズを取得。
815
+ * @returns {number} The total number of items.
816
+ */
817
+ getSize() {
818
+ return this.size;
819
+ }
820
+ /**
821
+ * @method findIndexAtOrAfter
822
+ * @description Finds the first index where the cumulative sum is greater than or equal to a target value.
823
+ * @description 累積和がターゲット値以上になる最初のインデックスを検索。
824
+ * @param {number} target - The target cumulative sum.
825
+ * @param {object} [options] - Optional settings for materializing values.
826
+ * @param {object} [options.materializeOption] - Options to control materialization.
827
+ * @param {boolean} [options.materializeOption.materialize=false] - Whether to materialize values.
828
+ * @param {object[]} [options.materializeOption.ranges] - An optional array of ranges to materialize values for.
829
+ * @param {number} options.materializeOption.ranges.from - The starting index of the range.
830
+ * @param {number} options.materializeOption.ranges.to - The ending index of the range.
831
+ * @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.
832
+ */
833
+ findIndexAtOrAfter(e, n) {
834
+ if (this.size === 0)
835
+ return { index: -1, total: this.total ?? 0, cumulative: void 0, currentValue: void 0, safeIndex: void 0 };
836
+ let r = 0, s = this.size - 1, a = -1, o, d = this.total;
837
+ for (; r <= s; ) {
838
+ const l = Math.floor((r + s) / 2);
839
+ o = this.prefixSum(l, n), d = o.total, o.cumulative >= e ? (a = l, s = l - 1) : r = l + 1;
840
+ }
841
+ return { index: a, total: d, cumulative: o?.cumulative, currentValue: o?.currentValue, safeIndex: o?.safeIndex };
842
+ }
843
+ /**
844
+ * @method findIndexAtOrBefore
845
+ * @description Finds the last index where the cumulative sum is less than or equal to a target value.
846
+ * @description 累積和がターゲット値以下になる最後のインデックスを検索。
847
+ * @param {number} target - The target cumulative sum.
848
+ * @param {object} [options] - Optional settings for materializing values.
849
+ * @param {object} [options.materializeOption] - Options to control materialization.
850
+ * @param {boolean} [options.materializeOption.materialize=false] - Whether to materialize values.
851
+ * @param {object[]} [options.materializeOption.ranges] - An optional array of ranges to materialize values for.
852
+ * @param {number} options.materializeOption.ranges.from - The starting index of the range.
853
+ * @param {number} options.materializeOption.ranges.to - The ending index of the range.
854
+ * @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.
855
+ */
856
+ findIndexAtOrBefore(e, n) {
857
+ if (this.size === 0)
858
+ return { index: -1, total: this.total ?? 0, cumulative: void 0, currentValue: void 0, safeIndex: void 0 };
859
+ let r = 0, s = this.size - 1, a = -1, o, d = this.total;
860
+ for (; r <= s; ) {
861
+ const l = Math.floor((r + s) / 2);
862
+ o = this.prefixSum(l, n), d = o.total, o.cumulative <= e ? (a = l, r = l + 1) : s = l - 1;
863
+ }
864
+ return { index: a, total: d, cumulative: o?.cumulative, currentValue: o?.currentValue, safeIndex: o?.safeIndex };
865
+ }
866
+ }
867
+ const Ie = (u, e, n) => {
868
+ const r = Math.max(0, u), s = Y(null), a = ne(() => new Re(r, e, n), [r, e, n]);
869
+ return Object.is(s.current, a) || console.warn("[useFenwickMapTree] instance changed"), s.current = a, a;
870
+ };
871
+ function ke({ itemCount: u, getItem: e, getItemHeight: n, viewportSize: r, overscanCount: s = 5, className: a, onScroll: o, onRangeChange: d, children: l, background: c, initialScrollIndex: g, initialScrollOffset: x }, R) {
872
+ const E = Y(null), I = Y(!1);
873
+ X(() => (I.current = !0, () => {
874
+ I.current = !1;
875
+ }), []);
876
+ const F = Y({ size: u, valueOrFn: n, options: { sampleRange: { from: 0, to: 100 } } }), b = Ie(F.current.size, F.current.valueOrFn, F.current.options), [k] = W(() => {
877
+ let h = 0, v = 0;
878
+ if (typeof g == "number") {
879
+ const t = O(g, 0, u - 1), i = O(t - s * 2, 0, u - 1), m = O(t + s * 2, 0, u - 1), p = g > 0 ? { materializeOption: { materialize: !0, ranges: [{ from: i, to: m }] } } : void 0, { cumulative: P, total: T, currentValue: C } = b.prefixSum(g, p);
880
+ h = P - C, v = T ?? b.getTotal();
881
+ } else typeof x == "number" && (h = x), v = b.getTotal();
882
+ return { position: h, total: v };
883
+ }), [S, f] = W(k.position), [w, y] = W(k.total), [N, $] = W(k.position), [_, J] = W(u);
884
+ oe(() => {
885
+ b.setValueFn(n), _ !== u && (b.changeSize(u), J(u));
886
+ const h = b.getTotal();
887
+ w !== h && y(h);
888
+ }, [b, _, u, w, n]), oe(() => {
889
+ N !== null && E.current && (A.debug("[VirtualScroll] Scrolling to position:", N), E.current.scrollTo(N), $(null));
890
+ }, [N]);
891
+ const H = L(
892
+ (h) => {
893
+ if (E.current) {
894
+ A.debug("[VirtualScroll] Scrolling to index:", h);
895
+ const v = O(h, 0, _ - 1), t = O(v - s * 2, 0, _ - 1), i = O(v + s * 2, 0, _ - 1), { cumulative: m, total: p, currentValue: P } = b.prefixSum(v, { materializeOption: { materialize: !0, ranges: [{ from: t, to: i }] } });
896
+ A.debug("[VirtualScroll] Scrolling to index:", h, "Offset:", m, "Total height:", p, "Current value:", P, "safeIndex:", v, "safeIndexFrom:", t, "safeIndexTo:", i), p && (y(p), $(m - P)), A.debug("[VirtualScroll] Setting scroll position to:", m - P);
897
+ }
898
+ },
899
+ [b, s, _]
900
+ ), U = L(
901
+ (h) => {
902
+ if (E.current) {
903
+ const v = b.getTotal(), t = O(Math.floor(h), 0, v), i = b.findIndexAtOrAfter(t, { materializeOption: { materialize: !1 } }).index;
904
+ H(i);
905
+ }
906
+ },
907
+ [b, H]
908
+ ), Z = L(
909
+ (h, v) => {
910
+ A.debug("[VirtualScroll] Scroll position changed:", h), f(h);
911
+ const t = b.getTotal();
912
+ o?.(h, t);
913
+ },
914
+ [b, o]
915
+ ), { renderingStartIndex: j, renderingEndIndex: M, visibleStartIndex: G, visibleEndIndex: B } = ne(() => {
916
+ if (_ === 0)
917
+ return { renderingStartIndex: 0, renderingEndIndex: 0, visibleStartIndex: 0, visibleEndIndex: 0 };
918
+ const { index: h, cumulative: v, currentValue: t } = b.findIndexAtOrAfter(S, { materializeOption: { materialize: !1 } });
919
+ let i = 0;
920
+ h === -1 ? i = 0 : (v ?? 0) < S + (t ?? 0) ? i = 1 : i = 0;
921
+ const m = h === -1 ? 0 : h + i, p = O(m - s, 0, _ - 1);
922
+ let P = 0, T = h === -1 ? 0 : h + i;
923
+ for (; T < _ && P < r; ) {
924
+ const D = n(T);
925
+ P += D, T++;
926
+ }
927
+ T -= 1;
928
+ const C = O(T + s, 0, _ - 1);
929
+ return A.debug("[VirtualScroll] Calculated rendering range:", {
930
+ renderingStartIndex: p,
931
+ renderingEndIndex: C,
932
+ visibleStartIndex: m,
933
+ visibleEndIndex: T,
934
+ scrollPosition: S,
935
+ renderingContentSize: b.getTotal(),
936
+ overscanCount: s,
937
+ viewportSize: r
938
+ }), { renderingStartIndex: p, renderingEndIndex: C, visibleStartIndex: m, visibleEndIndex: T };
939
+ }, [S, s, r, n, b, _]);
940
+ X(() => {
941
+ const h = E.current?.getScrollPosition() ?? 0;
942
+ A.debug("[VirtualScroll] Range change effect triggered", {
943
+ renderingStartIndex: j,
944
+ renderingEndIndex: M,
945
+ visibleStartIndex: G,
946
+ visibleEndIndex: B,
947
+ scrollPosition: S,
948
+ contentSize: w,
949
+ scrollPaneScrollPosition: h
950
+ }), d?.(j, M, G, B, S, w);
951
+ }, [j, M, G, B, d, S, w]), X(() => {
952
+ if (_ === 0) return;
953
+ const h = [];
954
+ for (let v = j; v <= M; v++) {
955
+ const t = n(v);
956
+ b.get(v) !== t && h.push({ index: v, value: t });
957
+ }
958
+ if (h.length > 0) {
959
+ const v = b.updates(h);
960
+ v && y((t) => v !== t && I.current ? (A.debug("[VirtualScroll] Updated heights for items", h, "New total height:", v), v) : t);
961
+ }
962
+ }, [j, M, n, b, _]);
963
+ const te = L(
964
+ (h) => {
965
+ if (A.debug("[VirtualScroll] Rendering visible items", { currentScrollPosition: h, renderingStartIndex: j, renderingEndIndex: M, fenwickSize: _, viewportSize: r }), _ === 0)
966
+ return /* @__PURE__ */ z.jsx("div", { className: "absolute w-full", style: { top: 0 }, children: /* @__PURE__ */ z.jsx("div", { className: "text-center text-gray-500", children: "No items" }) });
967
+ const v = O(j, 0, _ - 1), { cumulative: t, currentValue: i } = b.prefixSum(v, { materializeOption: { materialize: !1 } }), m = t - i, p = [];
968
+ for (let T = j; T <= M; T++)
969
+ p.push(e(T));
970
+ const P = w < r ? 0 : m - h;
971
+ return A.debug("[VirtualScroll] Rendering items", { visibleItems: p, containerTop: P }), /* @__PURE__ */ z.jsx("div", { className: "absolute w-full", style: { top: P }, children: p.map((T, C) => {
972
+ const D = j + C, V = O(D, 0, _ - 1), { cumulative: q, currentValue: Q } = b.prefixSum(V, { materializeOption: { materialize: !1 } }), se = q - Q;
973
+ return /* @__PURE__ */ z.jsx(
974
+ "div",
975
+ {
976
+ "data-index": D,
977
+ style: {
978
+ position: "absolute",
979
+ top: se - m,
980
+ width: "100%"
981
+ },
982
+ children: l(T, D)
983
+ },
984
+ D
985
+ );
986
+ }) });
987
+ },
988
+ [e, l, w, r, j, M, b, _]
989
+ );
990
+ return he(
991
+ R,
992
+ () => ({
993
+ getScrollPosition: () => E.current?.getScrollPosition() ?? -1,
994
+ getContentSize: () => E.current?.getContentSize() ?? -1,
995
+ getViewportSize: () => E.current?.getViewportSize() ?? -1,
996
+ scrollTo: (h) => U(h),
997
+ scrollToIndex: (h) => H(h),
998
+ getFenwickTreeTotalHeight: () => b.getTotal(),
999
+ getFenwickSize: () => b.getSize()
1000
+ }),
1001
+ [H, b, U]
1002
+ ), /* @__PURE__ */ z.jsx(_e, { ref: E, contentSize: w, viewportSize: r, className: a, onScroll: Z, background: c, children: te });
1003
+ }
1004
+ const Oe = de(ke);
1005
+ class Se {
1006
+ key;
1007
+ value;
1008
+ prev = null;
1009
+ next = null;
1010
+ constructor(e, n) {
1011
+ this.key = e, this.value = n;
1012
+ }
1013
+ }
1014
+ class fe {
1015
+ head = null;
1016
+ tail = null;
1017
+ /**
1018
+ * @method addToTail
1019
+ * @description Adds a node to the tail of the list, marking it as the most recently used.
1020
+ * @description ノードをリストの末尾に追加し、最も最近使用されたものとしてマークします。
1021
+ * @param {DoublyLinkedListNode<K, V>} node - The node to add.
1022
+ */
1023
+ addToTail(e) {
1024
+ this.tail ? (this.tail.next = e, e.prev = this.tail, this.tail = e) : this.head = this.tail = e;
1025
+ }
1026
+ /**
1027
+ * @method remove
1028
+ * @description Removes a given node from the list.
1029
+ * @description 指定されたノードをリストから削除します。
1030
+ * @param {DoublyLinkedListNode<K, V>} node - The node to remove.
1031
+ */
1032
+ remove(e) {
1033
+ e.prev ? e.prev.next = e.next : this.head = e.next, e.next ? e.next.prev = e.prev : this.tail = e.prev, e.prev = null, e.next = null;
1034
+ }
1035
+ /**
1036
+ * @method removeHead
1037
+ * @description Removes and returns the head of the list, which is the least recently used item.
1038
+ * @description リストの先頭(最も最近使用されていないアイテム)を削除して返します。
1039
+ * @returns {DoublyLinkedListNode<K, V> | null} The removed head node, or null if the list is empty.
1040
+ */
1041
+ removeHead() {
1042
+ const e = this.head;
1043
+ return e && this.remove(e), e;
1044
+ }
1045
+ /**
1046
+ * @method moveToTail
1047
+ * @description Moves an existing node to the tail of the list to mark it as most recently used.
1048
+ * @description 既存のノードをリストの末尾に移動し、最も最近使用されたものとしてマークします。
1049
+ * @param {DoublyLinkedListNode<K, V>} node - The node to move.
1050
+ */
1051
+ moveToTail(e) {
1052
+ this.remove(e), this.addToTail(e);
1053
+ }
1054
+ }
1055
+ function we(u) {
1056
+ const e = Y(/* @__PURE__ */ new Map()), n = Y(new fe());
1057
+ X(() => {
1058
+ for (; e.current.size > u; ) {
1059
+ const c = n.current.removeHead();
1060
+ if (c)
1061
+ e.current.delete(c.key);
1062
+ else
1063
+ break;
1064
+ }
1065
+ }, [u]);
1066
+ const r = L((c) => {
1067
+ const g = e.current.get(c);
1068
+ if (g)
1069
+ return n.current.moveToTail(g), g.value;
1070
+ }, []), s = L(
1071
+ (c, g) => {
1072
+ if (u <= 0)
1073
+ return;
1074
+ let x = e.current.get(c);
1075
+ if (x)
1076
+ x.value = g, n.current.moveToTail(x);
1077
+ else {
1078
+ if (e.current.size >= u) {
1079
+ const R = n.current.removeHead();
1080
+ R && e.current.delete(R.key);
1081
+ }
1082
+ x = new Se(c, g), e.current.set(c, x), n.current.addToTail(x);
1083
+ }
1084
+ },
1085
+ [u]
1086
+ ), a = L((c) => e.current.has(c), []), o = L(() => {
1087
+ e.current.clear(), n.current = new fe();
1088
+ }, []), [d, l] = W(() => ({ get: r, set: s, has: a, clear: o }));
1089
+ return X(() => l({ get: r, set: s, has: a, clear: o }), [r, s, a, o]), d;
1090
+ }
1091
+ const Pe = 1e4, Fe = () => {
1092
+ const { get: u, set: e, has: n, clear: r } = we(Pe);
1093
+ return { get: u, set: e, has: n, clear: r };
1094
+ };
1095
+ export {
1096
+ Re as FenwickMapTree,
1097
+ Ee as ScrollBar,
1098
+ _e as ScrollPane,
1099
+ Oe as VirtualScroll,
1100
+ O as minmax,
1101
+ Ie as useFenwickMapTree,
1102
+ Fe as useHeightCache,
1103
+ we as useLruCache
1104
+ };
1105
+ //# sourceMappingURL=index.js.map