@aiquants/virtualscroll 1.14.1 → 1.17.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/README.md CHANGED
@@ -81,7 +81,7 @@ function App() {
81
81
  ### VirtualScroll Props
82
82
 
83
83
  | Prop | Type | Required | Description |
84
- |------|------|----------|-------------|
84
+ | ------ | ------ | ---------- | ------------- |
85
85
  | `children` | `(item: T, index: number) => ReactNode` | ✅ | Render function for items |
86
86
  | `itemCount` | `number` | ✅ | Total number of items |
87
87
  | `getItem` | `(index: number) => T` | ✅ | Function to get item at index |
@@ -90,7 +90,7 @@ function App() {
90
90
  | `overscanCount` | `number` | ❌ | Number of items to render outside viewport (default: 5) |
91
91
  | `className` | `string` | ❌ | CSS class name |
92
92
  | `onScroll` | `(position: number, totalHeight: number) => void` | ❌ | Scroll event handler |
93
- | `onRangeChange` | `(start: number, end: number, visibleStart: number, visibleEnd: number, position: number, totalHeight: number) => void` | ❌ | Range change handler |
93
+ | `onRangeChange` | `(range: VirtualScrollRange) => void` | ❌ | Range change handler |
94
94
  | `background` | `ReactNode` | ❌ | Background element |
95
95
  | `initialScrollIndex` | `number` | ❌ | Initial scroll index |
96
96
  | `initialScrollOffset` | `number` | ❌ | Initial scroll offset |
@@ -103,7 +103,7 @@ function App() {
103
103
  ### VirtualScrollScrollBarOptions
104
104
 
105
105
  | Property | Type | Description |
106
- |----------|------|-------------|
106
+ | ---------- | ------ | ------------- |
107
107
  | `width` | `number` | Width of the scrollbar |
108
108
  | `enableThumbDrag` | `boolean` | Enable dragging the scrollbar thumb |
109
109
  | `enableTrackClick` | `boolean` | Enable clicking the scrollbar track |
@@ -115,7 +115,7 @@ function App() {
115
115
  ### VirtualScrollBehaviorOptions
116
116
 
117
117
  | Property | Type | Description |
118
- |----------|------|-------------|
118
+ | ---------- | ------ | ------------- |
119
119
  | `enablePointerDrag` | `boolean` | Enable dragging the content area to scroll |
120
120
  | `enableKeyboardNavigation` | `boolean` | Enable keyboard navigation (default: true) |
121
121
  | `wheelSpeedMultiplier` | `number` | Multiplier for mouse wheel scrolling speed |
@@ -126,14 +126,25 @@ function App() {
126
126
  ### VirtualScrollHandle Methods
127
127
 
128
128
  | Method | Type | Description |
129
- |--------|------|-------------|
129
+ | -------- | ------ | ------------- |
130
130
  | `scrollTo` | `(position: number) => void` | Scroll to specific position |
131
131
  | `scrollToIndex` | `(index: number, options?: { align?: "top" \| "bottom" \| "center"; offset?: number }) => void` | Scroll to specific item index with optional alignment and offset |
132
132
  | `getScrollPosition` | `() => number` | Get current scroll position |
133
- <!-- | `getContentSize` | `() => number` | Get total content size | -->
134
- <!-- | `getViewportSize` | `() => number` | Get viewport size | -->
135
- <!-- | `getFenwickTreeTotalHeight` | `() => number` | Get Fenwick tree total height | -->
136
- <!-- | `getFenwickSize` | `() => number` | Get Fenwick tree size | -->
133
+ | `getContentSize` | `() => number` | Get total content size |
134
+ | `getViewportSize` | `() => number` | Get viewport size |
135
+ | `focusItemAtIndex` | `(index: number, options?: { ensureVisible?: boolean }) => void` | Focus item at specific index |
136
+ | `getRange` | `() => VirtualScrollRange` | Get current range information |
137
+
138
+ ### VirtualScrollRange
139
+
140
+ | Property | Type | Description |
141
+ | ---------- | ------ | ------------- |
142
+ | `renderingStartIndex` | `number` | Index of the first item being rendered (including overscan) |
143
+ | `renderingEndIndex` | `number` | Index of the last item being rendered (including overscan) |
144
+ | `visibleStartIndex` | `number` | Index of the first fully or partially visible item |
145
+ | `visibleEndIndex` | `number` | Index of the last fully or partially visible item |
146
+ | `scrollPosition` | `number` | Current scroll position in pixels |
147
+ | `totalHeight` | `number` | Total height of the scroll content |
137
148
 
138
149
  ## Advanced Usage
139
150
 
package/dist/cli.js CHANGED
@@ -1,19 +1,114 @@
1
- #!/usr/bin/env node
2
- import { spawn as i } from "node:child_process";
3
- import n from "node:path";
4
- import { fileURLToPath as t } from "node:url";
5
- const m = t(import.meta.url), a = n.dirname(m), r = process.argv.slice(2);
6
- if (r[0] === "demo") {
7
- console.info("Starting demo server...");
8
- const s = n.join(a, "..", "demo"), e = i("pnpm", ["run", "dev"], {
9
- cwd: s,
1
+ import { spawn as a } from "node:child_process";
2
+ import r from "node:path";
3
+ import { fileURLToPath as l } from "node:url";
4
+ class i {
5
+ level;
6
+ prefix;
7
+ impl;
8
+ /**
9
+ * @constructor
10
+ * @param {LogLevel} [level=LogLevel.WARN] - The minimum log level to output.
11
+ * @param {string} [prefix="[virtualscroll]"] - The prefix to add to all log messages.
12
+ * @param {ILogger} [impl=console] - The implementation to use for logging.
13
+ */
14
+ constructor(e = 2, t = "[virtualscroll]", o = console) {
15
+ this.level = e, this.prefix = t, this.impl = o;
16
+ }
17
+ static instance = new i(2, "[virtualscroll]");
18
+ /**
19
+ * @method setLevel
20
+ * @description Updates the current log level for the static instance.
21
+ * @description 静的インスタンスの現在のログレベルを更新します。
22
+ * @param {LogLevel} level - The new log level.
23
+ */
24
+ static setLevel(e) {
25
+ i.instance.setLevel(e);
26
+ }
27
+ /**
28
+ * @method setLevel
29
+ * @description Updates the current log level.
30
+ * @description 現在のログレベルを更新します。
31
+ * @param {LogLevel} level - The new log level.
32
+ */
33
+ setLevel(e) {
34
+ this.level = e;
35
+ }
36
+ /**
37
+ * @method setImplementation
38
+ * @description Updates the logger implementation for the static instance.
39
+ * @description 静的インスタンスのロガーの実装を更新します。
40
+ * @param {ILogger} impl - The new logger implementation.
41
+ */
42
+ static setImplementation(e) {
43
+ i.instance.setImplementation(e);
44
+ }
45
+ /**
46
+ * @method setImplementation
47
+ * @description Updates the logger implementation.
48
+ * @description ロガーの実装を更新します。
49
+ * @param {ILogger} impl - The new logger implementation.
50
+ */
51
+ setImplementation(e) {
52
+ this.impl = e;
53
+ }
54
+ /**
55
+ * @method setPrefix
56
+ * @description Updates the log prefix for the static instance.
57
+ * @description 静的インスタンスのログのプレフィックスを更新します。
58
+ * @param {string} prefix - The new prefix.
59
+ */
60
+ static setPrefix(e) {
61
+ i.instance.setPrefix(e);
62
+ }
63
+ /**
64
+ * @method setPrefix
65
+ * @description Updates the log prefix.
66
+ * @description ログのプレフィックスを更新します。
67
+ * @param {string} prefix - The new prefix.
68
+ */
69
+ setPrefix(e) {
70
+ this.prefix = e;
71
+ }
72
+ formatMessage(e) {
73
+ return typeof e == "string" ? [`${this.prefix} ${e}`] : [this.prefix, e];
74
+ }
75
+ static debug(e, ...t) {
76
+ i.instance.debug(e, ...t);
77
+ }
78
+ debug(e, ...t) {
79
+ this.level <= 0 && this.impl.debug(...this.formatMessage(e), ...t);
80
+ }
81
+ static info(e, ...t) {
82
+ i.instance.info(e, ...t);
83
+ }
84
+ info(e, ...t) {
85
+ this.level <= 1 && this.impl.info(...this.formatMessage(e), ...t);
86
+ }
87
+ static warn(e, ...t) {
88
+ i.instance.warn(e, ...t);
89
+ }
90
+ warn(e, ...t) {
91
+ this.level <= 2 && this.impl.warn(...this.formatMessage(e), ...t);
92
+ }
93
+ static error(e, ...t) {
94
+ i.instance.error(e, ...t);
95
+ }
96
+ error(e, ...t) {
97
+ this.level <= 3 && this.impl.error(...this.formatMessage(e), ...t);
98
+ }
99
+ }
100
+ const m = l(import.meta.url), c = r.dirname(m), s = process.argv.slice(2);
101
+ if (s[0] === "demo") {
102
+ i.info("Starting demo server...");
103
+ const n = r.join(c, "..", "demo"), e = a("pnpm", ["run", "dev"], {
104
+ cwd: n,
10
105
  stdio: "inherit",
11
106
  shell: process.platform === "win32"
12
107
  });
13
- e.on("close", (o) => {
14
- o !== 0 && console.error(`Demo server process exited with code ${o}`);
15
- }), e.on("error", (o) => {
16
- console.error("Failed to start demo server:", o);
108
+ e.on("close", (t) => {
109
+ t !== 0 && i.error(`Demo server process exited with code ${t}`);
110
+ }), e.on("error", (t) => {
111
+ i.error("Failed to start demo server:", t);
17
112
  });
18
113
  } else
19
- console.warn(`Unknown command: ${r[0]}`), console.info("Usage: npx @aiquants/virtualscroll demo"), process.exit(1);
114
+ i.warn(`Unknown command: ${s[0]}`), i.info("Usage: npx @aiquants/virtualscroll demo"), process.exit(1);
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const A=require("react/jsx-runtime"),r=require("react"),Xe=require("tailwind-merge"),mt={active:!1,offsetX:0,offsetY:0,distance:0,direction:0,pointerId:null},lt=6,Ft=8,Lt=({dragState:o,normalizedDistance:e})=>{const t=1+e*.18,s=.16+e*.24,i=.38+e*.28,u=o.active?"80ms ease-out":"220ms ease";return A.jsxs(A.Fragment,{children:[A.jsx("div",{className:"absolute inset-0 rounded-full",style:{background:"linear-gradient(140deg, rgba(255,255,255,0.62), rgba(72,72,72,0.48))",boxShadow:`0 0 0 1px rgba(255,255,255,0.28), 0 10px 22px rgba(0,0,0,${s})`,transform:`scale(${t})`,transition:`${u}, ${o.active?"80ms":"260ms"} box-shadow ease`}}),A.jsx("div",{className:"aqvs:tap-scroll-circle-inner absolute rounded-full",style:{background:"linear-gradient(140deg, rgba(255,255,255,0.72), rgba(28,28,28,0.58))",boxShadow:"inset 0 4px 10px rgba(0,0,0,0.24), inset 0 0 2px rgba(255,255,255,0.55)",opacity:i,transition:o.active?"120ms opacity ease-out":"220ms opacity ease"}})]})},It=r.memo(r.forwardRef(({onDragChange:o,className:e,maxVisualDistance:t=160,size:s=40,style:i,opacity:u=1,renderVisual:f},g)=>{const[c,d]=r.useState(mt),m=r.useRef(null),h=r.useRef({x:0,y:0}),R=r.useRef(null),x=r.useRef(0),E=r.useCallback(y=>{d(y),o(y)},[o]),X=r.useCallback((y,H,B=!1)=>{const{x:O,y:se}=h.current,v=y-O,Ie=H-se,S=Math.abs(Ie),ae=S<lt?0:Ie<0?-1:1,F=x.current;let he=ae;const oe=lt+Ft;ae===0?F!==0&&S<oe?he=F:(he=0,B||(x.current=0)):ae!==F&&F!==0&&S<oe?he=F:x.current=ae,E({active:B||S>=lt,offsetX:v,offsetY:Ie,distance:S,direction:he,pointerId:m.current})},[E]),Y=r.useCallback(y=>{if(y===null)return;const H=R.current;H?.hasPointerCapture(y)&&H.releasePointerCapture(y)},[]),W=r.useCallback((y=!1)=>{y&&Y(m.current),m.current=null,x.current=0,E(mt)},[E,Y]),fe=r.useCallback(y=>{y.preventDefault(),y.stopPropagation();const H=R.current??y.currentTarget,{left:B,top:O,width:se,height:v}=H.getBoundingClientRect();h.current={x:B+se/2,y:O+v/2},m.current=y.pointerId,H.setPointerCapture(y.pointerId),X(y.clientX,y.clientY,!0)},[X]),te=r.useCallback(y=>{m.current===y.pointerId&&(y.preventDefault(),X(y.clientX,y.clientY))},[X]),J=r.useCallback(y=>{m.current===y.pointerId&&(y.preventDefault(),y.stopPropagation(),W(!0))},[W]);r.useImperativeHandle(g,()=>({reset:()=>{W(!0)},getElement:()=>R.current}),[W]);const D=Math.min(Math.max(u,0),1),M=s/64,j=Math.min(c.distance,t)/t,z=c.direction*j*10*M,G=f??Lt,N={dragState:c,normalizedDistance:j,sizeScale:M,size:s,opacity:D},de={...i,width:s,height:s,transform:`translateY(${z}px)`};return de.opacity=D,A.jsx("div",{ref:R,"data-testid":"virtual-scroll-tap-circle",className:Xe.twMerge("relative flex touch-none select-none items-center justify-center","transition-transform duration-100 ease-out",e),style:de,tabIndex:-1,onPointerDown:fe,onPointerMove:te,onPointerUp:J,onPointerCancel:J,role:"presentation",children:G(N)})}));It.displayName="TapScrollCircle";const ue=(o,e,t)=>Math.min(t,Math.max(e,o)),ft="virtualscroll:tap-scroll-cancel",pt=20,Ot=250,Yt=60,zt=20,Ht=20,qt=240,ht={active:!1,offsetX:0,offsetY:0,distance:0,direction:0,pointerId:null},ct=2.2,Xt=8,jt=120,Bt=1/60,Ve={enabled:!0,size:40,offsetX:-80,offsetY:0,className:void 0,maxVisualDistance:qt,minSpeedMultiplier:.2,opacity:.9,renderVisual:void 0,maxSpeedCurve:void 0},Ut=o=>o?{mainSizeKey:"width",crossSizeKey:"height",positionKey:"left",selectDelta:(e,t)=>e,getPointerCoordinate:({clientX:e})=>e,arrowLabels:["Scroll left","Scroll right"],arrowIcons:["◀","▶"],directionClass:"flex flex-row items-stretch",orientation:"horizontal"}:{mainSizeKey:"height",crossSizeKey:"width",positionKey:"top",selectDelta:(e,t)=>t,getPointerCoordinate:({clientY:e})=>e,arrowLabels:["Scroll up","Scroll down"],arrowIcons:["▲","▼"],directionClass:"flex flex-col items-stretch",orientation:"vertical"},$t=(o,e)=>{const t=o?.maxSpeedMultiplier,s=typeof t=="number"?t:Gt(e);return{enabled:o?.enabled??Ve.enabled,size:o?.size??Ve.size,offsetX:o?.offsetX??Ve.offsetX,offsetY:o?.offsetY??Ve.offsetY,className:o?.className??Ve.className,maxVisualDistance:o?.maxVisualDistance??Ve.maxVisualDistance,maxSpeedMultiplier:s,minSpeedMultiplier:Math.max(o?.minSpeedMultiplier??Ve.minSpeedMultiplier,0),opacity:ue(o?.opacity??Ve.opacity,0,1),renderVisual:o?.renderVisual??Ve.renderVisual,maxSpeedCurve:o?.maxSpeedCurve??Ve.maxSpeedCurve}},Kt=({isDragging:o,isThumbHovered:e,enableThumbDrag:t})=>r.useMemo(()=>t?o?"dragging":e?"hover":"idle":"disabled",[t,o,e]),Wt=({canUseArrowButtons:o,enableArrowButtons:e,resetTapScroll:t,scrollByStep:s})=>{const i=r.useRef(null),u=r.useRef(null),f=r.useCallback(()=>{i.current!==null&&(window.clearInterval(i.current),i.current=null),u.current!==null&&(window.clearTimeout(u.current),u.current=null)},[]),g=r.useCallback(()=>{f()},[f]),c=r.useCallback(m=>h=>{o&&(h.preventDefault(),h.stopPropagation(),t(),f(),s(m),u.current=window.setTimeout(()=>{i.current=window.setInterval(()=>{s(m)},Yt)},Ot))},[o,f,t,s]),d=r.useCallback(m=>h=>{e&&(h.key==="Enter"||h.key===" "||h.key==="Spacebar")&&(h.preventDefault(),s(m))},[e,s]);return r.useEffect(()=>()=>{f()},[f]),{handleArrowPointerDown:c,handleArrowPointerUp:g,handleArrowKeyDown:d}},Gt=o=>{if(!o||o<=0)return ct;const e=Math.max(1,o),t=Math.log10(e),s=ct+t*Xt;return ue(s,ct,jt)},Tt=({contentSize:o,viewportSize:e,scrollPosition:t,onScroll:s,enableThumbDrag:i=!0,enableTrackClick:u=!0,enableArrowButtons:f=!0,horizontal:g=!1,scrollBarWidth:c=12,className:d,ariaControls:m,tapScrollCircleOptions:h,itemCount:R,renderThumbOverlay:x,visibleStartIndex:E,visibleEndIndex:X})=>{const[Y,W]=r.useState(!1),[fe,te]=r.useState(!1),[J,D]=r.useState(!1),M=r.useRef(null),j=r.useRef({pointerId:null,startThumbPosition:0,startClientX:0,startClientY:0}),z=r.useRef({pointerId:null,startThumbPosition:0,startClientX:0,startClientY:0}),G=r.useRef(t),N=r.useRef(ht),de=r.useRef(null),y=r.useRef(null),H=r.useRef(null),B=r.useMemo(()=>$t(h,R),[R,h]),O=r.useMemo(()=>Ut(g),[g]),{enabled:se,size:v,offsetX:Ie,offsetY:S,className:ae,maxVisualDistance:F,maxSpeedMultiplier:he,minSpeedMultiplier:oe,opacity:ye,renderVisual:T,maxSpeedCurve:k}=B,P=r.useRef({viewportSize:e,maxScrollPosition:Math.max(o-e,0),scrollBarVisible:o>e,effectiveTapMaxDistance:Math.max(F,1),tapCircleMaxSpeedMultiplier:he,tapCircleMinSpeedMultiplier:oe,tapCircleMaxSpeedCurve:k,tapScrollCircleOptions:h}),{mainSizeKey:Q,crossSizeKey:L,positionKey:Ce,selectDelta:ge,getPointerCoordinate:be,arrowLabels:ee,arrowIcons:ie,directionClass:le,orientation:pe}=O,we=Math.max(F,1),Le=e/o,Te=c,b=Math.max(e-Te*2,0),C=Le*b,re=Math.min(Math.max(pt,C||0),b||pt),U=o-e,$=Math.max(b-re,0),Re=U<=0||$<=0?0:t/U*$,Se=Re+re/2,me=o>e,Pe=me&&f;P.current={viewportSize:e,maxScrollPosition:U,scrollBarVisible:me,effectiveTapMaxDistance:we,tapCircleMaxSpeedMultiplier:he,tapCircleMinSpeedMultiplier:oe,tapCircleMaxSpeedCurve:k,tapScrollCircleOptions:h},r.useEffect(()=>{G.current=t},[t]),r.useEffect(()=>{i||te(!1)},[i]);const Oe=Kt({isDragging:Y,isThumbHovered:fe,enableThumbDrag:i}),Ee=r.useCallback((n,l)=>{const I=P.current,w=l??G.current;if(s){const K=s(n,w);if(typeof K=="number"&&Number.isFinite(K))return G.current=K,K}const _=typeof n=="function"?n(w):n,V=Math.max(I.maxScrollPosition,0),q=I.scrollBarVisible?ue(_,0,V):0;return G.current=q,q},[s]),He=r.useCallback(n=>{const l=P.current,I=G.current;if(!l.scrollBarVisible||l.maxScrollPosition<=0){const K=Ee(0,I),Fe=K-I;return{nextPosition:K,actualDelta:Fe,reachedBoundary:!0}}if(n===0)return{nextPosition:I,actualDelta:0,reachedBoundary:!1};const _=Ee(K=>ue(K+n,0,l.maxScrollPosition),I),V=_-I,q=V===0||n<0&&_<=0||n>0&&_>=l.maxScrollPosition;return{nextPosition:_,actualDelta:V,reachedBoundary:q}},[Ee]),Z=r.useCallback(()=>{y.current!==null&&(window.cancelAnimationFrame(y.current),y.current=null),H.current=null},[]),ve=r.useCallback(()=>{N.current={...ht},D(!1),de.current?.reset(),Z()},[Z]),xe=r.useCallback(n=>{const l=N.current,I=P.current;if(!l.active||l.direction===0){Z();return}if(!I.scrollBarVisible||I.maxScrollPosition<=0){Z();return}const w=H.current??n,_=Math.max((n-w)/1e3,0),V=Math.min(_,Bt);if(H.current=n,V<=0){y.current=window.requestAnimationFrame(xe);return}const q=Math.min(l.distance,I.effectiveTapMaxDistance)/I.effectiveTapMaxDistance,K=q**1.1,Fe=typeof I.tapScrollCircleOptions?.maxSpeedMultiplier=="number",ke=Math.max(I.viewportSize*I.tapCircleMinSpeedMultiplier,40),qe=Fe?ke:1200;let at=Math.max(I.viewportSize*I.tapCircleMaxSpeedMultiplier,qe);const et=I.tapCircleMaxSpeedCurve;if(et){const tt=Math.max(et.exponentialSteepness,0),At=Math.max(et.exponentialScale??I.tapCircleMaxSpeedMultiplier,0),Dt=tt===0?q:Math.expm1(tt*q),dt=tt===0?1:Math.expm1(tt)||1,Nt=dt===0?q:Math.min(Math.max(Dt/dt,0),1),_t=I.viewportSize*At*Nt;at=Math.min(at,Math.max(_t,ke))}const Mt=Math.max(at,ke),yt=Math.max(et?.easedOffset??0,0),Rt=Math.min(1,K+yt),wt=ke+(Mt-ke)*Rt,Et=l.direction*wt*V,{actualDelta:kt,reachedBoundary:Vt}=He(Et);if(Vt||kt===0){Z();return}y.current=window.requestAnimationFrame(xe)},[He,Z]),je=r.useCallback(()=>{y.current===null&&(H.current=null,y.current=window.requestAnimationFrame(xe))},[xe]);r.useEffect(()=>()=>{Z()},[Z]);const Ge=r.useCallback(n=>{N.current=n,D(n.active),n.active&&n.direction!==0?je():Z()},[je,Z]);r.useEffect(()=>{se||ve()},[ve,se]),r.useEffect(()=>{const n=l=>{const w=l.detail?.paneId;w&&m&&w!==m||ve()};return window.addEventListener(ft,n),()=>{window.removeEventListener(ft,n)}},[m,ve]),r.useEffect(()=>{if(!se)return;const n=l=>{if(!N.current.active||N.current.pointerId===l.pointerId)return;const I=l.target;if(!(I instanceof Node)){ve();return}de.current?.getElement()?.contains(I)||ve()};return document.addEventListener("pointerdown",n,!0),()=>{document.removeEventListener("pointerdown",n,!0)}},[ve,se]);const Be=n=>{if(!me||$<=0||U<=0)return 0;const l=ue(n,0,$);return ue(l/$*U,0,U)},ze=n=>{const l=Math.max(Math.round(e/Ht),zt);He(n*l)},{handleArrowPointerDown:Ze,handleArrowPointerUp:Me,handleArrowKeyDown:Ae}=Wt({canUseArrowButtons:Pe,enableArrowButtons:f,resetTapScroll:ve,scrollByStep:ze}),De=n=>{if(!me)return;if(!i){n.preventDefault(),n.stopPropagation();return}if(n.pointerType==="mouse"&&n.button!==0||n.ctrlKey)return;ve();const l=n.currentTarget;l.setPointerCapture&&l.setPointerCapture(n.pointerId),j.current={pointerId:n.pointerId,startThumbPosition:Re,startClientX:n.clientX,startClientY:n.clientY},W(!0),te(!0),n.preventDefault(),n.stopPropagation()},Ne=n=>{const l=j.current;if(l.pointerId!==n.pointerId)return;const I=n.clientX-l.startClientX,w=n.clientY-l.startClientY,_=ge(I,w),V=Be(l.startThumbPosition+_);Ee(V),n.cancelable&&n.preventDefault()},_e=n=>{if(j.current.pointerId!==n.pointerId)return;const l=n.currentTarget;l.hasPointerCapture(n.pointerId)&&l.releasePointerCapture(n.pointerId),j.current={pointerId:null,startThumbPosition:0,startClientX:0,startClientY:0},W(!1),M.current&&!M.current.matches(":hover")&&te(!1),n.preventDefault(),n.stopPropagation()},Je=n=>{if(j.current.pointerId!==n.pointerId)return;const l=n.currentTarget;l.hasPointerCapture(n.pointerId)&&l.releasePointerCapture(n.pointerId),j.current={pointerId:null,startThumbPosition:0,startClientX:0,startClientY:0},W(!1),M.current&&!M.current.matches(":hover")&&te(!1)},Qe=n=>{if(!me)return;if(!u){n.preventDefault(),n.stopPropagation();return}if(n.pointerType==="mouse"&&n.button!==0||n.ctrlKey)return;const l=n.currentTarget,I=l.getBoundingClientRect(),_=be(n)-(g?I.left:I.top);ve();const V=_-re/2,q=Be(V);Ee(q),l.setPointerCapture&&l.setPointerCapture(n.pointerId),z.current={pointerId:n.pointerId,startThumbPosition:V,startClientX:n.clientX,startClientY:n.clientY},n.preventDefault(),n.stopPropagation()},st=n=>{const l=z.current;if(l.pointerId!==n.pointerId)return;const I=n.clientX-l.startClientX,w=n.clientY-l.startClientY,_=ge(I,w),V=Be(l.startThumbPosition+_);Ee(V),n.cancelable&&n.preventDefault()},Ue=n=>{if(z.current.pointerId!==n.pointerId)return;const l=n.currentTarget;l.hasPointerCapture(n.pointerId)&&l.releasePointerCapture(n.pointerId),z.current={pointerId:null,startThumbPosition:0,startClientX:0,startClientY:0},n.preventDefault(),n.stopPropagation()},$e=n=>{if(z.current.pointerId!==n.pointerId)return;const l=n.currentTarget;l.hasPointerCapture(n.pointerId)&&l.releasePointerCapture(n.pointerId),z.current={pointerId:null,startThumbPosition:0,startClientX:0,startClientY:0}},ot=r.useMemo(()=>ue((J?1:.8)*ye,0,1),[J,ye]),it=r.useMemo(()=>{const l=`calc(50% - ${v/2}px + ${S}px)`;return{left:Ie,top:l}},[Ie,S,v]),a=(n,l,I)=>A.jsx("button",{type:"button",tabIndex:-1,className:"aqvs:scrollbar-arrow-button flex items-center justify-center text-xs transition-colors focus:outline-none focus-visible:ring-2 focus-visible:ring-offset-1 disabled:cursor-not-allowed disabled:opacity-50",style:{[Q]:Te,[L]:c},"aria-label":l,onMouseDown:Ze(n),onTouchStart:Ze(n),onMouseUp:Me,onMouseLeave:Me,onTouchEnd:Me,onTouchCancel:Me,onKeyDown:Ae(n),"aria-disabled":!f,disabled:!Pe,children:A.jsx("span",{"aria-hidden":"true",children:I})}),p=x&&me?{orientation:pe,scrollPosition:t,maxScrollPosition:U,contentSize:o,viewportSize:e,thumbSize:re,thumbPosition:Re,thumbCenter:Se,trackSize:b,isDragging:Y,isTapScrollActive:J,visibleStartIndex:E,visibleEndIndex:X}:null;return A.jsxs("div",{className:Xe.twMerge("group relative cursor-default select-none",le,d),style:{[Q]:e,[L]:c,backgroundColor:"white",userSelect:"none",position:"relative",touchAction:"none"},role:"scrollbar",tabIndex:-1,"aria-controls":m,"aria-valuenow":t,"aria-valuemin":0,"aria-valuemax":U,"aria-orientation":g?"horizontal":"vertical",children:[!g&&me&&se&&A.jsx(It,{ref:de,className:Xe.twMerge("pointer-events-auto absolute transition-opacity duration-150",ae),size:v,maxVisualDistance:we,style:it,opacity:ot,renderVisual:T,onDragChange:Ge}),a(-1,ee[0],ie[0]),A.jsxs("div",{className:"aqvs:scrollbar-track relative flex-1",style:{borderRadius:c/2,touchAction:"none"},onPointerDown:Qe,onPointerMove:st,onPointerUp:Ue,onPointerCancel:$e,"aria-disabled":!u,children:[p&&A.jsx("div",{className:"pointer-events-none absolute inset-0","aria-hidden":!0,children:x?.(p)}),me&&A.jsx("div",{className:"group absolute",style:{[Q]:re,[Ce]:Re,...g?{top:0,bottom:0}:{left:0,right:0},touchAction:"none"},onPointerDown:De,onPointerMove:Ne,onPointerUp:_e,onPointerCancel:Je,role:"slider","aria-orientation":g?"horizontal":"vertical","aria-valuenow":t,"aria-valuemin":0,"aria-valuemax":U,"aria-disabled":!i,tabIndex:-1,children:A.jsx("div",{ref:M,className:Xe.twMerge("aqvs:scrollbar-thumb absolute",g?"aqvs:scrollbar-thumb-horizontal":"aqvs:scrollbar-thumb-vertical"),"data-thumb-state":Oe,style:{borderRadius:c-1,cursor:i?"pointer":"default"},onMouseEnter:()=>{i&&te(!0)},onMouseLeave:()=>{i&&te(!1)}})})]}),a(1,ee[1],ie[1])]})},ce={debug(o,...e){process.env.NODE_ENV==="___"&&console.debug(`[VirtualScroll] ${o}`,...e)},warn(o,...e){console.warn(`[VirtualScroll] ${o}`,...e)},error(o,...e){console.error(`[VirtualScroll] ${o}`,...e)}},Ke={maxVelocity:6,minVelocity:.02,deceleration:.0025,velocitySampleWindow:90,startVelocityThreshold:.04},rt=(o,e,t)=>{for(const[s,i,u]of e)t==="add"?o.addEventListener(s,i,u):o.removeEventListener(s,i,u)},vt=r.forwardRef(({children:o,contentSize:e,viewportSize:t,scrollBarWidth:s=12,enableThumbDrag:i=!0,enableTrackClick:u=!0,enableArrowButtons:f=!0,enablePointerDrag:g=!0,onScroll:c,className:d,style:m,background:h,tapScrollCircleOptions:R,inertiaOptions:x,itemCount:E,renderThumbOverlay:X,wheelSpeedMultiplier:Y=1,contentInsets:W,visibleStartIndex:fe,visibleEndIndex:te,renderOverlay:J},D)=>{const M=r.useRef(0),j=r.useRef(null),z=r.useRef(null),G=r.useRef({frame:null,velocity:0,lastTimestamp:null}),N=r.useMemo(()=>({maxVelocity:x?.maxVelocity??Ke.maxVelocity,minVelocity:x?.minVelocity??Ke.minVelocity,deceleration:x?.deceleration??Ke.deceleration,velocitySampleWindow:x?.velocitySampleWindow??Ke.velocitySampleWindow,startVelocityThreshold:x?.startVelocityThreshold??Ke.startVelocityThreshold}),[x]),de=r.useMemo(()=>({top:Math.max(0,W?.top??0),bottom:Math.max(0,W?.bottom??0)}),[W]);ce.debug("[ScrollPane] ScrollPane rendered",{contentSize:e,viewportSize:t,scrollBarWidth:s,className:d,style:m,tapScrollCircleOptions:R,inertiaOptions:x,enablePointerDrag:g,contentInsets:de});const y=r.useRef({contentSize:e,viewportSize:t}),H=r.useMemo(()=>e>t,[e,t]),B=r.useCallback(T=>{const{contentSize:k,viewportSize:P}=y.current,Q=k>P,L=M.current;if(ce.debug("[ScrollPane] scrollTo called",{newPosition:T,contentSize:k,viewportSize:P,currentIsScrollable:Q,prevPosition:L}),!Q)return M.current!==0&&(M.current=0,c?.(0,L)),M.current;const Ce=typeof T=="function"?T(M.current):T,ge=Math.max(k-P,0),be=ue(Ce,0,ge);return M.current!==be&&(M.current=be,c?.(be,L)),M.current},[c]),O=r.useCallback(()=>{const T=G.current;T.frame!==null&&cancelAnimationFrame(T.frame),T.frame=null,T.velocity=0,T.lastTimestamp=null},[]),se=r.useRef(O);r.useEffect(()=>{se.current=O},[O]);const v=r.useCallback(T=>{if(!H)return;const{maxVelocity:k,minVelocity:P,deceleration:Q,startVelocityThreshold:L}=N,Ce=ue(T,-k,k);if(Math.abs(Ce)<L)return;O(),G.current.velocity=Ce,G.current.lastTimestamp=null;const ge=be=>{const ee=G.current;if(ee.lastTimestamp===null){ee.lastTimestamp=be,ee.frame=requestAnimationFrame(ge);return}const ie=be-ee.lastTimestamp;if(ee.lastTimestamp=be,ie<=0){ee.frame=requestAnimationFrame(ge);return}const le=ee.velocity;let pe=le;const we=Q*ie;le>0?pe=Math.max(0,le-we):le<0&&(pe=Math.min(0,le+we));const Te=(le+pe)/2*ie,b=M.current;Te!==0&&B(Se=>Se+Te);const C=M.current,{contentSize:re,viewportSize:U}=y.current,$=Math.max(re-U,0);ee.velocity=pe;const Re=C===b||C<=0&&pe<=0||C>=$&&pe>=0;if(Math.abs(pe)<P||Re){O();return}ee.frame=requestAnimationFrame(ge)};G.current.frame=requestAnimationFrame(ge)},[H,N,B,O]),Ie=r.useRef(v);r.useEffect(()=>{Ie.current=v},[v]),r.useLayoutEffect(()=>{y.current={contentSize:e,viewportSize:t}},[e,t]),r.useLayoutEffect(()=>{const T=z.current;if(!T)return;const k=()=>{T.scrollTop!==0&&(ce.debug("[ScrollPane] Native scroll detected, resetting to 0",{scrollTop:T.scrollTop}),T.scrollTop=0),T.scrollLeft!==0&&(T.scrollLeft=0)};return T.addEventListener("scroll",k),()=>T.removeEventListener("scroll",k)},[]),r.useLayoutEffect(()=>{if(H){ce.debug("[ScrollPane] Adjusting scroll position due to content or viewport size change",{contentSize:e,viewportSize:t,scrollPosition:M.current});const T=ue(e-t,0,e);M.current>T&&B(T)}else B(0)},[H,B,e,t]),r.useEffect(()=>{const T=P=>{if(!H)return;P.preventDefault(),O();let Q=P.deltaY;P.deltaMode===1?Q*=16:P.deltaMode===2&&(Q*=t),Y!==1&&(Q*=Y),ce.debug("[ScrollPane] wheel event",{deltaY:Q,scrollPosition:M.current,wheelSpeedMultiplier:Y,deltaMode:P.deltaMode,scrollTop:z.current?.scrollTop}),B(L=>L+Q)},k=j.current;return k&&k.addEventListener("wheel",T,{passive:!1}),()=>{k&&k.removeEventListener("wheel",T)}},[H,B,O,t,Y]),r.useImperativeHandle(D,()=>({scrollTo:T=>(O(),B(T)),getScrollPosition:()=>M.current,getContentSize:()=>e,getViewportSize:()=>t}),[B,e,t,O]);const S=r.useRef(B);r.useEffect(()=>{S.current=B},[B]);const ae=r.useId(),F=r.useRef({pointerId:null,startClientY:0,startScroll:0,isDragging:!1,shouldCancelNextClick:!1,clickResetTimer:null,velocitySamples:[]}),he=r.useRef(g);r.useEffect(()=>{he.current=g},[g]);const oe=r.useRef(H);r.useEffect(()=>{oe.current=H},[H]);const ye=r.useRef(N);return r.useEffect(()=>{ye.current=N},[N]),r.useEffect(()=>{if(g)return;const T=z.current,k=F.current;k.pointerId!==null&&T&&T.hasPointerCapture(k.pointerId)&&T.releasePointerCapture(k.pointerId),k.clickResetTimer!==null&&(window.clearTimeout(k.clickResetTimer),k.clickResetTimer=null),k.pointerId=null,k.startClientY=0,k.startScroll=0,k.isDragging=!1,k.shouldCancelNextClick=!1,k.velocitySamples=[]},[g]),r.useEffect(()=>{const T=z.current;if(!T)return;const k=6,P=()=>typeof performance<"u"&&typeof performance.now=="function"?performance.now():Date.now(),Q=()=>{const b=F.current;b.pointerId=null,b.startClientY=0,b.startScroll=0,b.isDragging=!1,b.velocitySamples=[]},L=()=>{const b=F.current;b.clickResetTimer!==null&&(window.clearTimeout(b.clickResetTimer),b.clickResetTimer=null)},Ce=b=>{const C=F.current,re=P();C.velocitySamples.push({clientY:b,time:re});const U=ye.current.velocitySampleWindow;C.velocitySamples=C.velocitySamples.filter($=>re-$.time<=U)},ge=b=>b instanceof HTMLElement&&b.closest("[data-scrollpane-ignore-drag='true']")!==null,be=b=>{const C=F.current;C.shouldCancelNextClick&&(b.preventDefault(),b.stopPropagation(),C.shouldCancelNextClick=!1)},ee=b=>{const C=F.current;C.isDragging||(C.isDragging=!0,C.shouldCancelNextClick=!0,T.hasPointerCapture(b.pointerId)||T.setPointerCapture(b.pointerId),Ce(b.clientY))},ie=b=>{const C=F.current;if(C.pointerId!==b.pointerId||!(he.current&&oe.current)||!C.isDragging&&(Math.abs(b.clientY-C.startClientY)<k||(ee(b),!C.isDragging)))return;Ce(b.clientY);const re=b.clientY-C.startClientY,U=C.startScroll-re;S.current(U),b.cancelable&&b.preventDefault()},le=b=>{const C=F.current;if(C.pointerId!==b.pointerId)return;C.isDragging&&C.shouldCancelNextClick&&b.cancelable&&(b.preventDefault(),b.stopPropagation()),T.hasPointerCapture(b.pointerId)&&T.releasePointerCapture(b.pointerId);let re=0;if(C.isDragging&&C.velocitySamples.length>=2){const $=C.velocitySamples,Re=ye.current.velocitySampleWindow,Se=$[$.length-1],me=$.find(Pe=>Se.time-Pe.time<=Re)??$[0];if(Se&&me&&Se.time!==me.time){const Pe=Se.clientY-me.clientY,Oe=Se.time-me.time;re=-(Pe/Oe)}}L(),C.shouldCancelNextClick&&(C.clickResetTimer=window.setTimeout(()=>{const $=F.current;$.shouldCancelNextClick=!1,$.clickResetTimer=null},0));const U=ye.current.startVelocityThreshold;Q(),Math.abs(re)>=U&&Ie.current?.(re)},pe=b=>{if(!(he.current&&oe.current)||b.button!==0&&b.pointerType==="mouse"||b.ctrlKey||b.metaKey||b.altKey||ge(b.target))return;window.dispatchEvent(new CustomEvent(ft,{detail:{paneId:ae}})),se.current?.();const C=F.current;L(),C.pointerId=b.pointerId,C.startClientY=b.clientY,C.startScroll=M.current,C.isDragging=!1,C.shouldCancelNextClick=!1,C.velocitySamples=[]},we=b=>{const C=F.current;C.pointerId===b.pointerId&&(C.shouldCancelNextClick=!1,T.hasPointerCapture(b.pointerId)&&T.releasePointerCapture(b.pointerId),L(),Q())},Le=[["click",be,!0],["pointerdown",pe,{passive:!1}],["pointermove",ie,{passive:!1}],["pointerup",le,void 0],["pointercancel",we,void 0]],Te=[["pointermove",ie,{passive:!1}],["pointerup",le,void 0],["pointercancel",we,void 0]];return rt(T,Le,"add"),rt(window,Te,"add"),()=>{rt(T,Le,"remove"),rt(window,Te,"remove");const b=F.current;b.pointerId!==null&&T.hasPointerCapture(b.pointerId)&&T.releasePointerCapture(b.pointerId),L(),Q()}},[ae]),A.jsxs("div",{ref:j,className:Xe.twMerge("relative flex",d),style:m,children:[A.jsxs("div",{ref:z,className:Xe.twMerge("relative h-full flex-1 overflow-hidden"),style:{height:t,paddingTop:de.top,paddingBottom:de.bottom,...g?{touchAction:"none"}:{}},id:ae,children:[h,o(M.current)]}),H&&A.jsx(Tt,{contentSize:e,viewportSize:t,scrollPosition:M.current,onScroll:B,enableThumbDrag:i,enableTrackClick:u,enableArrowButtons:f,scrollBarWidth:s,ariaControls:ae,tapScrollCircleOptions:R,itemCount:E,renderThumbOverlay:X,visibleStartIndex:fe,visibleEndIndex:te}),J?.()]})}),gt=(o,e,t)=>Math.min(Math.max(o,e),t),Zt=({dragState:o,normalizedDistance:e,sizeScale:t,size:s})=>{const i=Math.max(s/2,1),u=1+e*.65,f=Math.max(.65,1-e*.25),g=o.direction*e*26*t,c=.8+e*.18,d=3*t,m=6*t,h=22*t,R=Math.abs(g)+m,x=g>0?d:-Math.abs(g)-d,E=Math.max(2.5,3*t),X=gt(o.offsetX,-i,i),Y=gt(o.offsetY,-i,i),W=i*.35,fe=X/i*W,te=Y/i*W,J=fe*.45,D=te*.45,M=Math.max(h*.38,6),j=.65+e*.2,z=o.active;return A.jsxs(A.Fragment,{children:[A.jsx("div",{className:"aqvs:tap-scroll-circle-gradient absolute inset-0 rounded-full border border-white/40 shadow-md",style:{transform:`scale(${f}, ${u})`,transition:z?"40ms transform ease-out":"200ms ease transform"}}),A.jsx("div",{className:"absolute top-1/2 left-1/2 rounded-full border border-white/50 bg-white/85",style:{width:h,height:h,transform:`translate(calc(-50% + ${fe}px), calc(-50% + ${te}px)) scale(${f}, ${c*u})`,transition:z?"70ms transform ease-out":"200ms ease transform"}}),A.jsx("div",{className:"absolute top-1/2 left-1/2 rounded-full bg-white/80",style:{width:M,height:M,transform:`translate(calc(-50% + ${J}px), calc(-50% + ${D}px)) scale(${f}, ${u})`,opacity:j,boxShadow:"0 0 8px rgba(255,255,255,0.45)",transition:z?"120ms opacity 150ms, 120ms transform ease-out ease-out":"220ms ease transform, 240ms opacity ease"}}),A.jsx("div",{className:"absolute top-1/2 left-1/2 rounded-full bg-white/50",style:{width:E,height:R,transform:`translate(-50%, ${x}px)`,opacity:e,transition:z?"40ms height, 60ms opacity ease-out ease-out":"200ms ease height, 120ms ease opacity"}})]})},Jt=o=>{if(!Number.isFinite(o))return 0n;const e=Math.trunc(o);return e<=0?0n:BigInt(e)},nt=o=>{if(o<=0||!Number.isFinite(o))return 0;const e=Math.trunc(o),t=BigInt(e)&-BigInt(e);return Number(t)};class Ct{tree;deltas;size;baseValue;valueFn;total;constructor(e,t,s){this.reset(e,t,s)}reset(e,t,s){if(this.size=e,this.tree=new Map,this.deltas=new Map,this.total=void 0,typeof t=="function"){if(this.valueFn=t,this.size>0){const u=s?.sampleRange??{from:0,to:Math.min(99,this.size-1)},{mode:f,materializedValues:g}=this._calculateMode(u.from,u.to);if(this.baseValue=f,s?.materialize)for(let c=0;c<g.length;c++){const d=g[c],m=u.from+c;if(m>=this.size)break;const h=d-this.baseValue;this.deltas.set(m,h),this._updateTree(m,h)}}else this.baseValue=0;this.total=this.getTotal()}else this.valueFn=void 0,this.baseValue=t,this.total=this.baseValue*this.size}setValueFn(e,t){if(t?.reset){this.reset(this.size,e);return}typeof e=="function"?this.valueFn=e:(this.valueFn=void 0,this.baseValue=e)}_calculateMode(e,t){if(!this.valueFn)return{mode:0,materializedValues:[]};const s=[];for(let d=e;d<=t&&!(d>=this.size);d++)s.push(this.valueFn(d));const i=[...s];if(s.length===0)return{mode:0,materializedValues:[]};s.sort((d,m)=>d-m);const u=Math.floor(s.length/2);let f;s.length%2===0?f=Math.floor((s[u-1]+s[u])/2):f=s[u];const g=new Map;let c=0;for(const d of s){const m=(g.get(d)??0)+1;g.set(d,m),m>c&&(c=m)}if(c>s.length*.2){const d=[];for(const[h,R]of g.entries())R===c&&d.push(h);const m=d.reduce((h,R)=>h+R,0);f=Math.floor(m/d.length)}return{mode:f,materializedValues:i}}update(e,t){return this.updates([{index:e,value:t}])}updates(e){const t=this._buildDeltaUpdates(e);return t.length>0?this.updateDeltas(t):this.total}updateDelta(e,t){return this.updateDeltas([{index:e,change:t}])}updateDeltas(e){for(const{index:t,change:s}of e){if(t<0||t>=this.size)throw new Error(`Index ${t} out of bounds`);const i=this.deltas.get(t)??0;this.deltas.set(t,i+s),this._updateTree(t,s)}return this.total}_updateTree(e,t){if(t===0)return;let s=e+1;for(;s<=this.size;){this.tree.set(s,(this.tree.get(s)??0)+t);const i=nt(s);if(i===0)break;s+=i}this.total!==void 0&&(this.total+=t)}_buildDeltaUpdates(e){const t=[];for(const{index:s,value:i}of e){if(s<0||s>=this.size)throw new Error(`Index ${s} out of bounds`);if(i<0)throw new Error("Value cannot be negative.");const u=this.deltas.has(s)?(this.deltas.get(s)??0)+this.baseValue:this.baseValue,f=i-u;f!==0&&t.push({index:s,change:f})}return t}_computeTreeTotal(){if(this.size<=0)return 0;let e=0,t=this.size;for(;t>0;){e+=this.tree.get(t)??0;const s=nt(t);if(s===0)break;t-=s}return e+this.baseValue*this.size}_materialize(e,t=!0){if(this.valueFn){const s=this.deltas.get(e)??0,u=this.valueFn(e)-this.baseValue;if(u!==s&&(this.deltas.set(e,u),t)){const f=u-s;this._updateTree(e,f)}}}_materializeRanges(e,t,s=!1){if(!(e?.materialize&&this.valueFn))return;const i=e.ranges;if(i&&i.length>0){for(const g of i){const c=g.from,d=Math.min(g.to,this.size-1);for(let m=c;m<=d;m++)this._materialize(m)}if(t===void 0)return;if(s){this._materialize(t);return}const u=i[0].from,f=i[i.length-1].to;t>=u&&t<=f&&this._materialize(t);return}t!==void 0&&this._materialize(t)}_findIndex(e,t={},s){if(this.size>=Number.MAX_SAFE_INTEGER)return this._findIndexLarge(e,t,s);if(this.size===0)return{index:-1,total:this.total??0,cumulative:void 0,currentValue:void 0,safeIndex:void 0};let i=0,u=0,f=1;for(;f<<1<=this.size;)f<<=1;for(;f>0;f>>=1){const d=i+f;if(d<=this.size){const h=(this.tree.get(d)??0)+this.baseValue*f;(s?u+h<e:u+h<=e)&&(i=d,u+=h)}}const g=s?i:i-1;if(g<0||g>=this.size)return{index:-1,total:this.total??this.getTotal(),cumulative:void 0,currentValue:void 0,safeIndex:void 0};const c=this.prefixSum(g,t);return{index:g,total:this.total??c.total,cumulative:c.cumulative,currentValue:c.currentValue,safeIndex:c.safeIndex}}_findIndexLarge(e,t,s){if(this.size===0)return{index:-1,total:this.total??0,cumulative:void 0,currentValue:void 0,safeIndex:void 0};const i=Jt(this.size);if(i===0n)return{index:-1,total:this.total??0,cumulative:void 0,currentValue:void 0,safeIndex:void 0};let u=0n,f=i-1n,g,c,d,m=this.total;for(;u<=f;){const x=u+f>>1n,E=Number(x),X=this.prefixSum(E,t);if(d=X,m=X.total,s?X.cumulative>=e:X.cumulative<=e)if(g=x,c=X,s){if(x===0n)break;f=x-1n}else u=x+1n;else if(s)u=x+1n;else{if(x===0n)break;f=x-1n}}const h=c??d;return{index:g!==void 0?Number(g):-1,total:m,cumulative:h?.cumulative,currentValue:h?.currentValue,safeIndex:h?.safeIndex}}prefixSum(e,t){if(e<0)return{cumulative:0,total:this.total,currentValue:0,safeIndex:0};const s=ue(e,0,this.size-1),i=t?.materializeOption;this._materializeRanges(i,s,!0);let u=0,f=s+1;for(;f>0;){const c=this.tree.get(f)??0;u+=c;const d=nt(f);if(d===0)break;f-=d}const g=i?.materialize?this.get(s):(this.deltas.get(s)||0)+this.baseValue;return{cumulative:u+this.baseValue*(s+1),total:this.total,currentValue:g,safeIndex:s}}get(e,t){if(e<0||e>=this.size)throw new Error("Index out of bounds");const s=t?.materializeOption;return this._materializeRanges(s,e),(this.deltas.get(e)??0)+this.baseValue}getTotal(e){const t=e?.materializeOption;if(this._materializeRanges(t),this.total===void 0)if(this.size===0)this.total=0;else{this.total=this._computeTreeTotal();const s=this.prefixSum(this.getSize()-1);console.assert(s.cumulative===s.total,"Inconsistent Fenwick Tree state")}return this.total}rebuildTree(e){if(e?.materialize&&this.valueFn){const s=this.valueFn;this.reset(this.size,i=>s(i),{materialize:!0});return}const t=new Map;for(const[s,i]of this.deltas.entries()){if(i===0)continue;let u=s+1;for(;u<=this.size;){t.set(u,(t.get(u)??0)+i);const f=nt(u);if(f===0)break;u+=f}}this.tree=t,this.total=this._computeTreeTotal()}calculateAccumulatedError(){if(this.total===void 0)return 0;let e=this.baseValue*this.size;for(const t of this.deltas.values())e+=t;return this.total-e}changeSize(e){const t=this.size;if(e===t)return;if(e<t)for(const i of this.deltas.keys())i>=e&&this.deltas.delete(i);this.size=e,this.rebuildTree();const s=this.prefixSum(this.getSize()-1);console.assert(s.cumulative===s.total,"Inconsistent Fenwick Tree state")}getSize(){return this.size}findIndexAtOrAfter(e,t){return this._findIndex(e,t??{},!0)}findIndexAtOrBefore(e,t){return this._findIndex(e,t??{},!1)}}const St=(o,e,t)=>{const s=Math.max(0,o),i=r.useRef(null),u=r.useMemo(()=>new Ct(s,e,t),[s,e,t]);return Object.is(i.current,u)||console.warn("[useFenwickMapTree] instance changed"),i.current=u,u};class Qt{key;value;prev=null;next=null;constructor(e,t){this.key=e,this.value=t}}class bt{head=null;tail=null;addToTail(e){this.tail?(this.tail.next=e,e.prev=this.tail,this.tail=e):this.head=this.tail=e}remove(e){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}removeHead(){const e=this.head;return e&&this.remove(e),e}moveToTail(e){this.remove(e),this.addToTail(e)}}function Pt(o){const e=r.useRef(new Map),t=r.useRef(new bt);r.useEffect(()=>{for(;e.current.size>o;){const m=t.current.removeHead();if(m)e.current.delete(m.key);else break}},[o]);const s=r.useCallback(m=>{const h=e.current.get(m);if(h)return t.current.moveToTail(h),h.value},[]),i=r.useCallback((m,h)=>{if(o<=0)return;let R=e.current.get(m);if(R)R.value=h,t.current.moveToTail(R);else{if(e.current.size>=o){const x=t.current.removeHead();x&&e.current.delete(x.key)}R=new Qt(m,h),e.current.set(m,R),t.current.addToTail(R)}},[o]),u=r.useCallback(m=>e.current.has(m),[]),f=r.useCallback(m=>{const h=e.current.get(m);h&&(t.current.remove(h),e.current.delete(m))},[]),g=r.useCallback(()=>{e.current.clear(),t.current=new bt},[]),[c,d]=r.useState(()=>({get:s,set:i,has:u,remove:f,clear:g}));return r.useEffect(()=>d({get:s,set:i,has:u,remove:f,clear:g}),[s,i,u,f,g]),c}const er=1e4,tr=()=>{const{get:o,set:e,has:t,clear:s}=Pt(er);return{get:o,set:e,has:t,clear:s}},ne=(o,e)=>e<=0?0:ue(o,0,e-1),rr=o=>({top:Math.max(0,o?.top??0),bottom:Math.max(0,o?.bottom??0)}),Ye=(o,e)=>o<=e?0:o-e,We=(o,e)=>o<=0?e:o+e,ut=o=>{if(!Number.isFinite(o))return 0n;const e=Math.trunc(o);return e<=0?0n:BigInt(e)},nr=(o,e,t,s,i,u,f,g)=>{const c=ut(s);if(c===0n)return{renderingStartIndex:0,renderingEndIndex:0,visibleStartIndex:0,visibleEndIndex:0};const d=D=>D<0n?0n:D>=c?c-1n:D,m={materializeOption:{materialize:!1}},{index:h,cumulative:R}=u.findIndexAtOrAfter(o,m);let x;h===-1?x=c-1n:(R===o?x=ut(h+1):x=ut(h),x>=c&&(x=c-1n)),o<=0&&(x=0n),g&&o>=f&&(x=c-1n);const E=D=>{let M=0,j=D,z=D,G=0n;for(;j<c&&M<e;){const N=Number(j),de=i(N);if(M+=de,z=j,j+=1n,G+=1n,!Number.isFinite(de)||de<=0)break}return G===0n&&(z=D),{height:M,end:z}};let{height:X,end:Y}=E(x);if(X<e&&x>0n){let D=x,M=X;for(;D>0n&&M<e;){D-=1n;const z=Number(D),G=i(z);if(M+=G,!Number.isFinite(G)||G<=0)break}x=d(D);const j=E(x);X=j.height,Y=j.end}const W=d(x),fe=d(Y),te=d(W-BigInt(Math.max(0,t))),J=d(fe+BigInt(Math.max(0,t)));return{renderingStartIndex:ne(Number(te),s),renderingEndIndex:ne(Number(J),s),visibleStartIndex:ne(Number(W),s),visibleEndIndex:ne(Number(fe),s)}},sr=(o,e,t,s,i,u,f)=>{if(s===0)return{renderingStartIndex:0,renderingEndIndex:0,visibleStartIndex:0,visibleEndIndex:0};const g=Number.isFinite(f),c=g?Math.min(Math.max(0,o),f):Math.max(0,o);if(s>=Number.MAX_SAFE_INTEGER)return nr(c,e,t,s,i,u,f,g);const{index:d,cumulative:m,currentValue:h}=u.findIndexAtOrAfter(c,{materializeOption:{materialize:!1}}),R=d===-1?e<=0||(m??0)<c+(h??0)?s-1:0:d;let x=ne(R,s),E=0;if(d!==-1&&m===c)x=ne(d+1,s),E=0;else if(x===d&&m!==void 0&&h!==void 0)E=m-h-c;else{const{cumulative:J,currentValue:D}=u.prefixSum(x,{materializeOption:{materialize:!1}});E=(J??0)-(D??0)-c}const X=E;let Y=x;for(;Y<s&&E<e;)E+=i(Y),Y++;if(E<e&&x>0){let J=E+Math.abs(Math.min(0,X)),D=x-1;for(;D>=0&&J<e;)J+=i(D),D--;for(x=ne(D+1,s),E=0,Y=x;Y<s&&E<e;)E+=i(Y),Y++}const W=ne(x-t,s),fe=ne(Math.max(Y-1,x),s),te=ne(fe+t,s);return{renderingStartIndex:W,renderingEndIndex:te,visibleStartIndex:x,visibleEndIndex:fe}},or=()=>typeof performance<"u"&&typeof performance.now=="function"?performance.now():Date.now(),xt=(o,e,t)=>{const s=Math.max(0,e??0),i=r.useRef({lastInvokeAt:0,rafId:null,pendingPayload:null,loopActive:!1,normalizedThrottle:s}),u=r.useCallback(()=>{const c=i.current;c.rafId!==null&&typeof cancelAnimationFrame=="function"&&cancelAnimationFrame(c.rafId),c.rafId=null,c.loopActive=!1},[]),f=r.useCallback(c=>{const d=i.current;d.rafId=null;const m=typeof c=="number"?c:or(),h=d.normalizedThrottle,R=d.pendingPayload,x=o.current;if(R!==null&&x){const E=m-d.lastInvokeAt;(h===0||d.lastInvokeAt===0||E>=h)&&(d.pendingPayload=null,d.lastInvokeAt=m,t(x,R))}if(d.pendingPayload!==null){typeof requestAnimationFrame=="function"?d.rafId=requestAnimationFrame(f):d.loopActive=!1;return}d.loopActive=!1},[o,t]),g=r.useCallback(()=>{const c=i.current;if(!c.loopActive){if(c.loopActive=!0,typeof requestAnimationFrame=="function"){c.rafId=requestAnimationFrame(f);return}c.loopActive=!1}},[f]);return r.useEffect(()=>()=>{u(),i.current.pendingPayload=null},[u]),r.useEffect(()=>{u();const c=i.current;c.lastInvokeAt=0,c.pendingPayload=null,c.normalizedThrottle=s},[s,u]),r.useCallback(c=>{const d=i.current;d.pendingPayload=c,g()},[g])},ir=r.memo(({index:o,top:e,height:t,item:s,children:i,clipItemHeight:u,enableKeyboardNavigation:f,onKeyDown:g,onFocus:c,registerItemRef:d})=>{const m=r.useCallback(E=>d(o,E),[o,d]),h=r.useCallback(E=>g(E,o),[o,g]),R=r.useCallback(()=>c(o),[o,c]),x=r.useCallback(E=>{E.currentTarget.focus({preventScroll:!0})},[]);return A.jsx("div",{ref:m,"data-index":o,"data-virtualscroll-item":"true",className:"aqvs:item-container",style:{top:e,height:t,overflow:u?"hidden":void 0},tabIndex:f?-1:void 0,onPointerDown:f?x:void 0,onKeyDownCapture:f?h:void 0,onFocusCapture:f?R:void 0,children:i(s,o)})}),ar=({itemCount:o,getItem:e,getItemHeight:t,viewportSize:s,overscanCount:i=15,className:u,onScroll:f,onRangeChange:g,children:c,background:d,initialScrollIndex:m,initialScrollOffset:h,callbackThrottleMs:R=5,contentInsets:x,onItemFocus:E,scrollBarOptions:X,behaviorOptions:Y},W)=>{const{width:fe,enableThumbDrag:te,enableTrackClick:J,enableArrowButtons:D,enableScrollToTopBottomButtons:M,renderThumbOverlay:j,tapScrollCircleOptions:z}=X??{},{enablePointerDrag:G,enableKeyboardNavigation:N=!0,wheelSpeedMultiplier:de,inertiaOptions:y,clipItemHeight:H=!1,resetOnGetItemHeightChange:B=!1}=Y??{},O=r.useRef(null),se=r.useRef(!1),v=r.useMemo(()=>rr(x),[x]),Ie=r.useRef({size:o,valueOrFn:t,options:{sampleRange:{from:0,to:100}}}),S=St(Ie.current.size,Ie.current.valueOrFn,Ie.current.options),[ae]=r.useState(()=>{let a=v.top,p=0;if(typeof m=="number"){const n=ue(m,0,o-1),l=ue(n-i*2,0,o-1),I=ue(n+i*2,0,o-1),w=m>0?{materializeOption:{materialize:!0,ranges:[{from:l,to:I}]}}:void 0,{cumulative:_,total:V,currentValue:q}=S.prefixSum(m,w),K=Math.max(_-q,0);a=We(K,v.top),p=V??S.getTotal()}else typeof h=="number"&&(a=We(Math.max(h,0),v.top)),p=S.getTotal();return{position:a,total:p}}),[F,he]=r.useState(ae.position),[oe,ye]=r.useState(ae.total),[T,k]=r.useState(ae.position),[P,Q]=r.useState(o),L=r.useRef(ae.position),Ce=r.useRef(v.top),ge=r.useRef(f??void 0),be=r.useRef(g??void 0),ee=r.useRef(new Map),ie=r.useRef(null),le=r.useRef(null),[pe,we]=r.useState(null),[Le,Te]=r.useState(!1),b=r.useRef(null),C=r.useRef(!1),re=r.useRef(t);r.useEffect(()=>{ge.current=f??void 0,be.current=g??void 0},[g,f]);const U=r.useCallback(a=>{if(N&&a&&typeof a.focus=="function")try{a.focus({preventScroll:!0})}catch{a.focus()}},[N]),$=xt(ge,R,(a,{position:p,totalHeight:n})=>{a(p,n)}),Re=xt(be,R,(a,{renderingStartIndex:p,renderingEndIndex:n,visibleStartIndex:l,visibleEndIndex:I,scrollPosition:w,totalHeight:_})=>{a(p,n,l,I,w,_)});r.useEffect(()=>(se.current=!0,()=>{se.current=!1}),[]),r.useEffect(()=>{N||(ee.current.clear(),ie.current=null,le.current=null)},[N]);const Se=r.useCallback((a,p)=>{if(!p){ee.current.delete(a);return}N&&(ee.current.set(a,p),ie.current===a&&(ie.current=null,le.current=a,U(p)))},[N,U]),me=.01,Pe=r.useRef({rafId:null,loopActive:!1,idleFrames:0,lastRenderedPosition:ae.position}),Oe=r.useCallback(()=>{const a=Pe.current;a.rafId!==null&&typeof cancelAnimationFrame=="function"&&cancelAnimationFrame(a.rafId),a.rafId=null,a.loopActive=!1,a.idleFrames=0},[]);r.useEffect(()=>()=>{Oe()},[Oe]);const Ee=r.useCallback(()=>{const a=Pe.current;a.rafId=null;const p=L.current,n=Ye(p,v.top),l=S.getTotal();if(he(w=>Math.abs(w-p)<me?w:p),$({position:n,totalHeight:l}),Math.abs(a.lastRenderedPosition-p)>=me?(a.lastRenderedPosition=p,a.idleFrames=0):a.idleFrames+=1,a.idleFrames>=2){Oe();return}if(typeof requestAnimationFrame=="function"){a.rafId=requestAnimationFrame(Ee);return}a.loopActive=!1},[S,v.top,$,Oe]),He=r.useCallback(()=>{const a=Pe.current;if(a.idleFrames=0,!a.loopActive){if(a.loopActive=!0,typeof requestAnimationFrame=="function"){a.rafId=requestAnimationFrame(Ee);return}a.loopActive=!1}},[Ee]),Z=r.useCallback((a,p)=>{const n=p?.immediate??!1,l=Ye(a,v.top);if(L.current=a,n){Pe.current.lastRenderedPosition=a,Pe.current.idleFrames=0,he(a),$({position:l,totalHeight:S.getTotal()});return}He()},[He,S,v.top,$]),ve=r.useRef(!1);r.useEffect(()=>{if(!ve.current)if(ve.current=!0,typeof h=="number"){const a=We(Math.max(h,0),v.top),p=Math.abs(a-L.current)>.5;Z(a,{immediate:!0}),p&&k(a)}else Z(L.current,{immediate:!0})},[h,v.top,Z]),r.useLayoutEffect(()=>{re.current!==t?(S.setValueFn(t,{reset:B}),re.current=t):S.setValueFn(t,{reset:!1}),P!==o&&(S.changeSize(o),Q(o));const p=S.getTotal();oe!==p&&ye(p)},[S,P,o,oe,t,B]),r.useLayoutEffect(()=>{T!==null&&O.current&&(ce.debug("[VirtualScroll] Scrolling to position:",T),O.current.scrollTo(T),k(null))},[T]),r.useEffect(()=>{const a=Ce.current;if(a===v.top)return;const p=Ye(L.current,a),n=We(p,v.top);Ce.current=v.top,L.current=n,k(n),Z(n,{immediate:!0})},[v.top,Z]);const xe=r.useCallback((a,p)=>{if(!O.current)return;const n=ne(a,P),l=ne(n-i*2,P),I=ne(n+i*2,P),{cumulative:w,total:_,currentValue:V}=S.prefixSum(n,{materializeOption:{materialize:!0,ranges:[{from:l,to:I}]}});if(ce.debug("[VirtualScroll] Scrolling to index:",n,"ItemBottom:",w,"Total height:",_,"ItemHeight:",V,"safeIndexFrom:",l,"safeIndexTo:",I),!_)return;const q=Math.max(w-V,0);let K=q;p?.align==="bottom"?K=w-s:p?.align==="center"&&(K=q+V/2-s/2),p?.offset&&(K-=p.offset),K=Math.max(0,K);const Fe=We(K,v.top);ye(_),k(Fe),ce.debug("[VirtualScroll] Setting scroll position to:",Fe)},[S,i,P,v.top,s]),je=r.useCallback(a=>{if(!O.current)return;const p=S.getTotal(),n=ue(Math.floor(a),0,p),l=S.findIndexAtOrAfter(n,{materializeOption:{materialize:!1}}).index;xe(l)},[S,xe]),Ge=r.useCallback(a=>{const p=Ye(L.current,v.top),n=typeof a=="function"?a(p):a;je(n);const l=O.current?.getScrollPosition(),I=typeof l=="number"?l:L.current;return Z(I),I},[v.top,je,Z]),Be=r.useCallback((a,p)=>{if(ce.debug("[VirtualScroll] Scroll position changed:",a),Z(a),M){if(C.current){C.current=!1;return}const n=a-p;if(ce.debug("[VirtualScroll] Scroll diff:",n,"New:",a,"Prev:",p),Math.abs(n)>1){const l=n>0?"down":"up";we(l),Te(!0),ce.debug("[VirtualScroll] Showing scroll buttons. Direction:",l),b.current&&clearTimeout(b.current),b.current=setTimeout(()=>{Te(!1),ce.debug("[VirtualScroll] Hiding scroll buttons")},2e3)}}},[Z,M]),ze=r.useMemo(()=>Ye(F,v.top),[v.top,F]),Ze=r.useMemo(()=>{const a=sr(ze,s,i,P,t,S,oe);return ce.debug("[VirtualScroll] Calculated rendering range:",{...a,scrollPosition:ze,renderingContentSize:S.getTotal(),overscanCount:i,viewportSize:s}),a},[ze,s,i,P,t,S,oe]),{renderingStartIndex:Me,renderingEndIndex:Ae,visibleStartIndex:De,visibleEndIndex:Ne}=Ze,_e=r.useCallback((a,p)=>{if(!N||P===0)return;const n=ne(a,P);if(!(p?.ensureVisible??!0)){const qe=ee.current.get(n);qe&&(ie.current=null,le.current=n,U(qe));return}const I=S.prefixSum(n,{materializeOption:{materialize:!1}}),w=I.currentValue,_=Math.max(I.cumulative-w,0),V=_+w,q=Ye(L.current,v.top),K=q+s;if(_<q||V>K){ie.current=n,xe(n);return}const ke=ee.current.get(n);if(ke){ie.current=null,le.current=n,U(ke);return}ie.current=n},[N,P,S,v.top,xe,U,s]),Je=r.useCallback((a,p)=>{if(!N||a.defaultPrevented||a.altKey||a.metaKey||a.ctrlKey)return;const n=a.target;if(n){const l=n.tagName;if(l==="INPUT"||l==="TEXTAREA"||l==="SELECT"||n.isContentEditable)return}if(a.key==="ArrowDown"){p<P-1&&(a.preventDefault(),_e(p+1));return}if(a.key==="ArrowUp"){p>0&&(a.preventDefault(),_e(p-1));return}if(a.key==="PageDown"){if(p<P-1){a.preventDefault();const l=Math.max(Ne-De+1,1),I=Math.max(l,1),w=ne(Math.min(p+I,P-1),P);_e(w)}return}if(a.key==="PageUp"&&p>0){a.preventDefault();const l=Math.max(Ne-De+1,1),I=Math.max(l,1),w=ne(p-I,P);_e(w)}},[N,P,_e,Ne,De]),Qe=r.useCallback(a=>{if(!N)return;const p=ne(a,P);ie.current=null,le.current=p,E?.(p)},[N,P,E]);r.useEffect(()=>{const a=O.current?.getScrollPosition()??0,p=L.current,n=Ye(p,v.top);ce.debug("[VirtualScroll] Range change effect triggered",{renderingStartIndex:Me,renderingEndIndex:Ae,visibleStartIndex:De,visibleEndIndex:Ne,scrollPositionState:F,paneScrollPosition:p,logicalScrollPosition:n,contentSize:oe,scrollPaneScrollPosition:a}),Re({renderingStartIndex:Me,renderingEndIndex:Ae,visibleStartIndex:De,visibleEndIndex:Ne,scrollPosition:n,totalHeight:oe})},[oe,Ae,Me,v.top,Re,F,Ne,De]);const st=r.useCallback(()=>{if(!M)return null;const a=Le&&pe!==null,p=pe==="up";return A.jsx("div",{className:"aqvs:scroll-to-edge-overlay","data-visible":a,children:p?A.jsx("div",{className:"aqvs:scroll-to-edge-button-container aqvs:scroll-to-edge-button-container-top",children:A.jsx("button",{type:"button",className:"aqvs:scroll-to-edge-button",onClick:n=>{n.stopPropagation(),C.current=!0,xe(0),Te(!1)},children:"Top"})}):A.jsx("div",{className:"aqvs:scroll-to-edge-button-container aqvs:scroll-to-edge-button-container-bottom",children:A.jsx("button",{type:"button",className:"aqvs:scroll-to-edge-button",onClick:n=>{n.stopPropagation(),C.current=!0,xe(o-1),Te(!1)},children:"Bottom"})})})},[M,Le,pe,xe,o]),{visibleItems:Ue,startPosition:$e}=r.useMemo(()=>{if(P===0)return{visibleItems:A.jsx("div",{className:"aqvs:no-items-container",children:A.jsx("div",{className:"aqvs:no-items-text",children:"No items"})}),startPosition:0};const a=ne(Me,P),p=ne(Ae,P),{cumulative:n,currentValue:l}=S.prefixSum(a,{materializeOption:{materialize:!1}}),I=n-l,w=[],_=[];for(let V=a;V<=p;V++){const q=t(V);S.get(V)!==q&&w.push({index:V,value:q});const{cumulative:Fe,currentValue:ke}=S.prefixSum(V,{materializeOption:{materialize:!1}}),qe=Fe-ke;_.push(A.jsx(ir,{index:V,top:qe-I+v.top,height:q,item:e(V),children:c,clipItemHeight:H,enableKeyboardNavigation:N,onKeyDown:Je,onFocus:Qe,registerItemRef:Se},V))}return w.length>0&&Promise.resolve().then(()=>{if(!se.current)return;const V=S.updates(w);if(!se.current||typeof V!="number")return;ye(V),ce.debug("[VirtualScroll] Updated heights for items",w,"New total height:",V);const q=O.current?.getScrollPosition()??L.current;q===L.current||!se.current||Z(q)}),{visibleItems:_,startPosition:I}},[c,H,N,P,S,e,t,Qe,Je,Se,Ae,Me,v.top,Z]),ot=r.useCallback(a=>{const p=(R??0)>0,n=Math.abs(a-F),l=p&&n>.5?F:a,I=Ye(l,v.top);if(ce.debug("[VirtualScroll] Rendering visible items",{currentScrollPosition:a,effectiveScrollPosition:I,renderingStartIndex:Me,renderingEndIndex:Ae,fenwickSize:P,viewportSize:s,callbackThrottleMs:R,diff:n,rawEffectiveScrollPosition:l}),P===0)return Ue;const w=$e-I,_=v.bottom>0?A.jsx("div",{className:"aqvs:bottom-inset",style:{top:S.getTotal()+v.top-$e,height:v.bottom}},"virtualscroll-bottom-inset"):null;return ce.debug("[VirtualScroll] Rendering items",{containerTop:w,logicalScrollPosition:ze,resolvedInsets:v,effectiveScrollPosition:I}),A.jsxs("div",{className:"aqvs:items-wrapper",style:{top:w},children:[Ue,_]})},[R,P,S,ze,Ae,Me,v,F,$e,s,Ue]);r.useImperativeHandle(W,()=>({getScrollPosition:()=>O.current?.getScrollPosition()??-1,getContentSize:()=>O.current?.getContentSize()??-1,getViewportSize:()=>O.current?.getViewportSize()??-1,scrollTo:Ge,scrollToIndex:xe,getFenwickTreeTotalHeight:()=>S.getTotal(),getFenwickSize:()=>S.getSize(),focusItemAtIndex:_e}),[Ge,xe,S,_e]);const it=oe+v.top+v.bottom;return A.jsx(vt,{ref:O,contentSize:it,viewportSize:s,className:u,onScroll:Be,background:d,tapScrollCircleOptions:z,inertiaOptions:y,itemCount:o,scrollBarWidth:fe,enableThumbDrag:te,enableTrackClick:J,enableArrowButtons:D,enablePointerDrag:G,renderThumbOverlay:j,wheelSpeedMultiplier:de,contentInsets:v,visibleStartIndex:De,visibleEndIndex:Ne,renderOverlay:st,children:ot})},lr=r.forwardRef(ar);exports.FenwickMapTree=Ct;exports.ScrollBar=Tt;exports.ScrollPane=vt;exports.VirtualScroll=lr;exports.minmax=ue;exports.tapScrollCircleSampleVisual=Zt;exports.useFenwickMapTree=St;exports.useHeightCache=tr;exports.useLruCache=Pt;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const F=require("react/jsx-runtime"),r=require("react"),Ze=require("tailwind-merge");class N{level;prefix;impl;constructor(e=2,t="[virtualscroll]",n=console){this.level=e,this.prefix=t,this.impl=n}static instance=new N(2,"[virtualscroll]");static setLevel(e){N.instance.setLevel(e)}setLevel(e){this.level=e}static setImplementation(e){N.instance.setImplementation(e)}setImplementation(e){this.impl=e}static setPrefix(e){N.instance.setPrefix(e)}setPrefix(e){this.prefix=e}formatMessage(e){return typeof e=="string"?[`${this.prefix} ${e}`]:[this.prefix,e]}static debug(e,...t){N.instance.debug(e,...t)}debug(e,...t){this.level<=0&&this.impl.debug(...this.formatMessage(e),...t)}static info(e,...t){N.instance.info(e,...t)}info(e,...t){this.level<=1&&this.impl.info(...this.formatMessage(e),...t)}static warn(e,...t){N.instance.warn(e,...t)}warn(e,...t){this.level<=2&&this.impl.warn(...this.formatMessage(e),...t)}static error(e,...t){N.instance.error(e,...t)}error(e,...t){this.level<=3&&this.impl.error(...this.formatMessage(e),...t)}}const vt={active:!1,offsetX:0,offsetY:0,distance:0,direction:0,pointerId:null},pt=6,Ot=8,Yt=({dragState:s,normalizedDistance:e})=>{const t=1+e*.18,n=.16+e*.24,o=.38+e*.28,c=s.active?"80ms ease-out":"220ms ease";return F.jsxs(F.Fragment,{children:[F.jsx("div",{className:"aqvs-tap-scroll-circle-visual-outer",style:{background:"linear-gradient(140deg, rgba(255,255,255,0.62), rgba(72,72,72,0.48))",boxShadow:`0 0 0 1px rgba(255,255,255,0.28), 0 10px 22px rgba(0,0,0,${n})`,transform:`scale(${t})`,transition:`${c}, ${s.active?"80ms":"260ms"} box-shadow ease`}}),F.jsx("div",{className:"aqvs-tap-scroll-circle-inner",style:{background:"linear-gradient(140deg, rgba(255,255,255,0.72), rgba(28,28,28,0.58))",boxShadow:"inset 0 4px 10px rgba(0,0,0,0.24), inset 0 0 2px rgba(255,255,255,0.55)",opacity:o,transition:s.active?"120ms opacity ease-out":"220ms opacity ease"}})]})},Ct=r.memo(r.forwardRef(({onDragChange:s,className:e,maxVisualDistance:t=160,size:n=40,style:o,opacity:c=1,renderVisual:u},d)=>{const[m,h]=r.useState(vt),p=r.useRef(null),b=r.useRef({x:0,y:0}),E=r.useRef(null),x=r.useRef(0),k=r.useCallback(V=>{h(V),s(V)},[s]),X=r.useCallback((V,W,G=!1)=>{const{x:U,y:L}=b.current,ve=V-U,ae=W-L,be=Math.abs(ae),I=be<pt?0:ae<0?-1:1,Se=x.current;let v=I;const Ie=pt+Ot;I===0?Se!==0&&be<Ie?v=Se:(v=0,G||(x.current=0)):I!==Se&&Se!==0&&be<Ie?v=Se:x.current=I,k({active:G||be>=pt,offsetX:ve,offsetY:ae,distance:be,direction:v,pointerId:p.current})},[k]),q=r.useCallback(V=>{if(V===null)return;const W=E.current;W?.hasPointerCapture(V)&&W.releasePointerCapture(V)},[]),Z=r.useCallback((V=!1)=>{V&&q(p.current),p.current=null,x.current=0,k(vt)},[k,q]),ge=r.useCallback(V=>{V.preventDefault(),V.stopPropagation();const W=E.current??V.currentTarget,{left:G,top:U,width:L,height:ve}=W.getBoundingClientRect();b.current={x:G+L/2,y:U+ve/2},p.current=V.pointerId,W.setPointerCapture(V.pointerId),X(V.clientX,V.clientY,!0)},[X]),oe=r.useCallback(V=>{p.current===V.pointerId&&(V.preventDefault(),X(V.clientX,V.clientY))},[X]),re=r.useCallback(V=>{p.current===V.pointerId&&(V.preventDefault(),V.stopPropagation(),Z(!0))},[Z]);r.useImperativeHandle(d,()=>({reset:()=>{Z(!0)},getElement:()=>E.current}),[Z]);const Y=Math.min(Math.max(c,0),1),J=n/64,w=Math.min(m.distance,t)/t,j=m.direction*w*10*J,K=u??Yt,xe={dragState:m,normalizedDistance:w,sizeScale:J,size:n,opacity:Y},_={...o,width:n,height:n,transform:`translateY(${j}px)`};return _.opacity=Y,F.jsx("div",{ref:E,"data-testid":"virtual-scroll-tap-circle",className:Ze.twMerge("aqvs-tap-scroll-circle",e),style:_,tabIndex:-1,onPointerDown:ge,onPointerMove:oe,onPointerUp:re,onPointerCancel:re,role:"presentation",children:K(xe)})}));Ct.displayName="TapScrollCircle";const fe=(s,e,t)=>Math.min(t,Math.max(e,s)),bt="virtualscroll:tap-scroll-cancel",It=20,zt=250,qt=60,Ht=20,Bt=20,Xt=240,Tt={active:!1,offsetX:0,offsetY:0,distance:0,direction:0,pointerId:null},ht=2.2,jt=8,Ut=120,$t=1/60,Oe={enabled:!0,size:40,offsetX:-80,offsetY:0,className:void 0,maxVisualDistance:Xt,minSpeedMultiplier:.2,opacity:.9,renderVisual:void 0,maxSpeedCurve:void 0},Kt=s=>s?{mainSizeKey:"width",crossSizeKey:"height",positionKey:"left",selectDelta:(e,t)=>e,getPointerCoordinate:({clientX:e})=>e,arrowLabels:["Scroll left","Scroll right"],arrowIcons:["◀","▶"],directionClass:"aqvs-scrollbar-horizontal",orientation:"horizontal"}:{mainSizeKey:"height",crossSizeKey:"width",positionKey:"top",selectDelta:(e,t)=>t,getPointerCoordinate:({clientY:e})=>e,arrowLabels:["Scroll up","Scroll down"],arrowIcons:["▲","▼"],directionClass:"aqvs-scrollbar-vertical",orientation:"vertical"},Wt=(s,e)=>{const t=s?.maxSpeedMultiplier,n=typeof t=="number"?t:Jt(e);return{enabled:s?.enabled??Oe.enabled,size:s?.size??Oe.size,offsetX:s?.offsetX??Oe.offsetX,offsetY:s?.offsetY??Oe.offsetY,className:s?.className??Oe.className,maxVisualDistance:s?.maxVisualDistance??Oe.maxVisualDistance,maxSpeedMultiplier:n,minSpeedMultiplier:Math.max(s?.minSpeedMultiplier??Oe.minSpeedMultiplier,0),opacity:fe(s?.opacity??Oe.opacity,0,1),renderVisual:s?.renderVisual??Oe.renderVisual,maxSpeedCurve:s?.maxSpeedCurve??Oe.maxSpeedCurve}},Gt=({isDragging:s,isThumbHovered:e,enableThumbDrag:t})=>r.useMemo(()=>t?s?"dragging":e?"hover":"idle":"disabled",[t,s,e]),Zt=({canUseArrowButtons:s,enableArrowButtons:e,resetTapScroll:t,scrollByStep:n})=>{const o=r.useRef(null),c=r.useRef(null),u=r.useCallback(()=>{o.current!==null&&(window.clearInterval(o.current),o.current=null),c.current!==null&&(window.clearTimeout(c.current),c.current=null)},[]),d=r.useCallback(()=>{u()},[u]),m=r.useCallback(p=>b=>{s&&(b.cancelable&&b.preventDefault(),b.stopPropagation(),t(),u(),n(p),c.current=window.setTimeout(()=>{o.current=window.setInterval(()=>{n(p)},qt)},zt))},[s,u,t,n]),h=r.useCallback(p=>b=>{e&&(b.key==="Enter"||b.key===" "||b.key==="Spacebar")&&(b.preventDefault(),n(p))},[e,n]);return r.useEffect(()=>()=>{u()},[u]),{handleArrowPointerDown:m,handleArrowPointerUp:d,handleArrowKeyDown:h}},Jt=s=>{if(!s||s<=0)return ht;const e=Math.max(1,s),t=Math.log10(e),n=ht+t*jt;return fe(n,ht,Ut)},yt=({contentSize:s,viewportSize:e,scrollPosition:t,onScroll:n,enableThumbDrag:o=!0,enableTrackClick:c=!0,enableArrowButtons:u=!0,horizontal:d=!1,scrollBarWidth:m=12,className:h,ariaControls:p,tapScrollCircleOptions:b,itemCount:E,renderThumbOverlay:x,visibleStartIndex:k,visibleEndIndex:X})=>{const[q,Z]=r.useState(!1),[ge,oe]=r.useState(!1),[re,Y]=r.useState(!1),J=r.useRef(null),w=r.useRef({pointerId:null,startThumbPosition:0,startClientX:0,startClientY:0}),j=r.useRef({pointerId:null,startThumbPosition:0,startClientX:0,startClientY:0}),K=r.useRef(t),xe=r.useRef(n),_=r.useRef(Tt),V=r.useRef(null),W=r.useRef(null),G=r.useRef(null),U=r.useMemo(()=>Wt(b,E),[E,b]),L=r.useMemo(()=>Kt(d),[d]),{enabled:ve,size:ae,offsetX:be,offsetY:I,className:Se,maxVisualDistance:v,maxSpeedMultiplier:Ie,minSpeedMultiplier:Me,opacity:Ne,renderVisual:T,maxSpeedCurve:A}=U,D=r.useRef({viewportSize:e,maxScrollPosition:Math.max(s-e,0),scrollBarVisible:s>e,effectiveTapMaxDistance:Math.max(v,1),tapCircleMaxSpeedMultiplier:Ie,tapCircleMinSpeedMultiplier:Me,tapCircleMaxSpeedCurve:A,tapScrollCircleOptions:b,effectiveTrackLength:0,onScroll:n,scrollPosition:t}),{mainSizeKey:Q,crossSizeKey:le,positionKey:Ee,selectDelta:de,getPointerCoordinate:ne,arrowLabels:se,arrowIcons:Ce,directionClass:ye,orientation:Pe}=L,we=Math.max(v,1),Ye=e/s,me=Math.max(e-m*2,0),g=Ye*me,M=Math.min(Math.max(It,g||0),me||It),$=s-e,ie=Math.max(me-M,0),ce=$<=0||ie<=0?0:t/$*ie,Le=ce+M/2,ue=s>e||q,Fe=ue&&u;r.useLayoutEffect(()=>{D.current={viewportSize:e,maxScrollPosition:$,scrollBarVisible:ue,effectiveTapMaxDistance:we,tapCircleMaxSpeedMultiplier:Ie,tapCircleMinSpeedMultiplier:Me,tapCircleMaxSpeedCurve:A,tapScrollCircleOptions:b,effectiveTrackLength:ie,onScroll:n,scrollPosition:t}}),r.useLayoutEffect(()=>{K.current=t},[t]),r.useLayoutEffect(()=>{xe.current=n},[n]),r.useEffect(()=>{o||oe(!1)},[o]);const $e=Gt({isDragging:q,isThumbHovered:ge,enableThumbDrag:o}),ke=r.useCallback((a,S)=>{const C=D.current,i=S??K.current;if(xe.current){const R=xe.current(a,i);if(typeof R=="number"&&Number.isFinite(R))return K.current=R,R}const l=typeof a=="function"?a(i):a,f=Math.max(C.maxScrollPosition,0),P=C.scrollBarVisible?fe(l,0,f):0;return K.current=P,P},[]),ze=r.useCallback(a=>{const S=D.current,C=K.current;if(!S.scrollBarVisible||S.maxScrollPosition<=0){const R=ke(0,C),y=R-C;return{nextPosition:R,actualDelta:y,reachedBoundary:!0}}if(a===0)return{nextPosition:C,actualDelta:0,reachedBoundary:!1};const l=ke(R=>fe(R+a,0,S.maxScrollPosition),C),f=l-C,P=f===0||a<0&&l<=0||a>0&&l>=S.maxScrollPosition;return{nextPosition:l,actualDelta:f,reachedBoundary:P}},[ke]),Te=r.useCallback(()=>{W.current!==null&&(window.cancelAnimationFrame(W.current),W.current=null),G.current=null},[]),Re=r.useCallback(()=>{_.current={...Tt},Y(!1),V.current?.reset(),Te()},[Te]),We=r.useCallback(a=>{const S=_.current,C=D.current;if(!S.active||S.direction===0){Te();return}if(!C.scrollBarVisible||C.maxScrollPosition<=0){Te();return}const i=G.current??a,l=Math.max((a-i)/1e3,0),f=Math.min(l,$t);if(G.current=a,f<=0){W.current=window.requestAnimationFrame(We);return}const P=Math.min(S.distance,C.effectiveTapMaxDistance)/C.effectiveTapMaxDistance,R=P**1.1,y=typeof C.tapScrollCircleOptions?.maxSpeedMultiplier=="number",z=Math.max(C.viewportSize*C.tapCircleMinSpeedMultiplier,40),B=y?z:1200;let H=Math.max(C.viewportSize*C.tapCircleMaxSpeedMultiplier,B);const pe=C.tapCircleMaxSpeedCurve;if(pe){const ct=Math.max(pe.exponentialSteepness,0),Nt=Math.max(pe.exponentialScale??C.tapCircleMaxSpeedMultiplier,0),Lt=ct===0?P:Math.expm1(ct*P),xt=ct===0?1:Math.expm1(ct)||1,Ft=xt===0?P:Math.min(Math.max(Lt/xt,0),1),_t=C.viewportSize*Nt*Ft;H=Math.min(H,Math.max(_t,z))}const he=Math.max(H,z),De=Math.max(pe?.easedOffset??0,0),Ke=Math.min(1,R+De),nt=z+(he-z)*Ke,st=S.direction*nt*f,{actualDelta:At,reachedBoundary:Dt}=ze(st);if(Dt||At===0){Te();return}W.current=window.requestAnimationFrame(We)},[ze,Te]),ee=r.useCallback(()=>{W.current===null&&(G.current=null,W.current=window.requestAnimationFrame(We))},[We]);r.useEffect(()=>()=>{Te()},[Te]);const ot=r.useCallback(a=>{_.current=a,Y(a.active),a.active&&a.direction!==0?ee():Te()},[ee,Te]);r.useEffect(()=>{ve||Re()},[Re,ve]),r.useEffect(()=>{const a=S=>{const i=S.detail?.paneId;i&&p&&i!==p||Re()};return window.addEventListener(bt,a),()=>{window.removeEventListener(bt,a)}},[p,Re]),r.useEffect(()=>{if(!ve)return;const a=S=>{if(!_.current.active||_.current.pointerId===S.pointerId)return;const C=S.target;if(!(C instanceof Node)){Re();return}V.current?.getElement()?.contains(C)||Re()};return document.addEventListener("pointerdown",a,!0),()=>{document.removeEventListener("pointerdown",a,!0)}},[Re,ve]);const rt=a=>{if(!ue||ie<=0||$<=0)return 0;const S=fe(a,0,ie);return fe(S/ie*$,0,$)},Ve=r.useCallback(a=>{const{scrollBarVisible:S,effectiveTrackLength:C,maxScrollPosition:i}=D.current;if(N.debug("[ScrollBar] calculateScrollPositionFromThumb",{thumbPos:a,trackLen:C,maxScroll:i}),C<=0||i<=0)return null;const l=fe(a,0,C);return fe(l/C*i,0,i)},[]),Je=r.useCallback(a=>{const S=w.current;if(S.pointerId!==a.pointerId)return;const C=a.clientX-S.startClientX,i=a.clientY-S.startClientY,l=de(C,i);N.debug("[ScrollBar] handleThumbPointerMove",{delta:l,startThumbPosition:S.startThumbPosition,clientY:a.clientY,startClientY:S.startClientY,metrics:D.current});const f=Ve(S.startThumbPosition+l);f!==null&&ke(f),a.cancelable&&a.preventDefault()},[de,Ve,ke]),Ge=r.useCallback(a=>{if(w.current.pointerId===a.pointerId)if(document.removeEventListener("pointermove",Je),document.removeEventListener("pointerup",Ge),document.removeEventListener("pointercancel",Ge),w.current={pointerId:null,startThumbPosition:0,startClientX:0,startClientY:0},Z(!1),J.current){const C=J.current.getBoundingClientRect();a.clientX>=C.left&&a.clientX<=C.right&&a.clientY>=C.top&&a.clientY<=C.bottom||oe(!1)}else oe(!1)},[Je]),dt=a=>{const S=Math.max(Math.round(e/Bt),Ht);ze(a*S)},{handleArrowPointerDown:qe,handleArrowPointerUp:_e,handleArrowKeyDown:He}=Zt({canUseArrowButtons:Fe,enableArrowButtons:u,resetTapScroll:Re,scrollByStep:dt}),Be=a=>{if(ue){if(!o){a.preventDefault(),a.stopPropagation();return}a.pointerType==="mouse"&&a.button!==0||a.ctrlKey||(Re(),w.current={pointerId:a.pointerId,startThumbPosition:ce,startClientX:a.clientX,startClientY:a.clientY},document.addEventListener("pointermove",Je),document.addEventListener("pointerup",Ge),document.addEventListener("pointercancel",Ge),Z(!0),oe(!0),a.preventDefault(),a.stopPropagation())}},Ae=a=>{if(!ue)return;if(!c){a.preventDefault(),a.stopPropagation();return}if(a.pointerType==="mouse"&&a.button!==0||a.ctrlKey)return;const S=a.currentTarget,C=S.getBoundingClientRect(),l=ne(a)-(d?C.left:C.top);Re();const f=l-M/2,P=rt(f);ke(P),S.setPointerCapture&&S.setPointerCapture(a.pointerId),j.current={pointerId:a.pointerId,startThumbPosition:f,startClientX:a.clientX,startClientY:a.clientY},a.preventDefault(),a.stopPropagation()},Xe=a=>{const S=j.current;if(S.pointerId!==a.pointerId)return;const C=a.clientX-S.startClientX,i=a.clientY-S.startClientY,l=de(C,i),f=rt(S.startThumbPosition+l);ke(f),a.cancelable&&a.preventDefault()},je=a=>{if(j.current.pointerId!==a.pointerId)return;const S=a.currentTarget;S.hasPointerCapture(a.pointerId)&&S.releasePointerCapture(a.pointerId),j.current={pointerId:null,startThumbPosition:0,startClientX:0,startClientY:0},a.preventDefault(),a.stopPropagation()},at=a=>{if(j.current.pointerId!==a.pointerId)return;const S=a.currentTarget;S.hasPointerCapture(a.pointerId)&&S.releasePointerCapture(a.pointerId),j.current={pointerId:null,startThumbPosition:0,startClientX:0,startClientY:0}},lt=r.useMemo(()=>fe((re?1:.8)*Ne,0,1),[re,Ne]),mt=r.useMemo(()=>{const S=`calc(50% - ${ae/2}px + ${I}px)`;return{left:be,top:S}},[be,I,ae]),Qe=(a,S,C,i)=>F.jsx("button",{type:"button",tabIndex:-1,className:"aqvs-scrollbar-arrow-button",style:{[Q]:m,[le]:m},"aria-label":S,onPointerDown:qe(a),onPointerUp:_e,onPointerLeave:_e,onPointerCancel:_e,onKeyDown:He(a),"aria-disabled":!u,disabled:!Fe,children:F.jsx("span",{"aria-hidden":"true",children:C})},i),et=x&&ue?{orientation:Pe,scrollPosition:t,maxScrollPosition:$,contentSize:s,viewportSize:e,thumbSize:M,thumbPosition:ce,thumbCenter:Le,trackSize:me,isDragging:q,isTapScrollActive:re,visibleStartIndex:k,visibleEndIndex:X}:null;return F.jsxs("div",{className:Ze.twMerge("aqvs-scrollbar",ye,!ue&&"pointer-events-none opacity-0",h),style:{[Q]:e,[le]:m},role:"scrollbar",tabIndex:-1,"aria-controls":p,"aria-valuenow":t,"aria-valuemin":0,"aria-valuemax":$,"aria-orientation":d?"horizontal":"vertical",children:[!d&&ue&&ve&&F.jsx(Ct,{ref:V,className:Ze.twMerge("aqvs-scrollbar-tap-circle-wrapper",Se),size:ae,maxVisualDistance:we,style:mt,opacity:lt,renderVisual:T,onDragChange:ot},"tap-circle"),Qe(-1,se[0],Ce[0],"arrow-start"),F.jsxs("div",{className:"aqvs-scrollbar-track",style:{borderRadius:m/2},onPointerDown:Ae,onPointerMove:Xe,onPointerUp:je,onPointerCancel:at,"aria-disabled":!c,children:[et&&F.jsx("div",{className:"aqvs-scrollbar-overlay","aria-hidden":!0,children:x?.(et)},"overlay"),F.jsx("div",{className:Ze.twMerge("aqvs-scrollbar-thumb-wrapper",!(ue||q)&&"pointer-events-none opacity-0"),style:{[Q]:M,[Ee]:ce,...d?{top:0,bottom:0}:{left:0,right:0}},onPointerDown:Be,role:"slider","aria-orientation":d?"horizontal":"vertical","aria-valuenow":t,"aria-valuemin":0,"aria-valuemax":$,"aria-disabled":!o,tabIndex:-1,children:F.jsx("div",{ref:J,className:Ze.twMerge("aqvs-scrollbar-thumb",d?"aqvs-scrollbar-thumb-horizontal":"aqvs-scrollbar-thumb-vertical"),"data-thumb-state":$e,style:{borderRadius:m-1,cursor:o?"pointer":"default"},onMouseEnter:()=>{o&&oe(!0)},onMouseLeave:()=>{o&&oe(!1)}},"thumb")},"thumb-wrapper")]},"track"),Qe(1,se[1],Ce[1],"arrow-end")]})},it={maxVelocity:6,minVelocity:.02,deceleration:.0025,velocitySampleWindow:90,startVelocityThreshold:.04},ut=(s,e,t)=>{for(const[n,o,c]of e)t==="add"?s.addEventListener(n,o,c):s.removeEventListener(n,o,c)},wt=r.forwardRef(({children:s,contentSize:e,viewportSize:t,scrollBarWidth:n=12,enableThumbDrag:o=!0,enableTrackClick:c=!0,enableArrowButtons:u=!0,enablePointerDrag:d=!0,onScroll:m,className:h,style:p,background:b,tapScrollCircleOptions:E,inertiaOptions:x,itemCount:k,renderThumbOverlay:X,wheelSpeedMultiplier:q=1,contentInsets:Z,visibleStartIndex:ge,visibleEndIndex:oe,renderOverlay:re,initialScrollPosition:Y=0},J)=>{const w=r.useRef(Y),j=r.useRef(null),K=r.useRef(null),xe=r.useRef({frame:null,velocity:0,lastTimestamp:null}),_=r.useMemo(()=>({maxVelocity:x?.maxVelocity??it.maxVelocity,minVelocity:x?.minVelocity??it.minVelocity,deceleration:x?.deceleration??it.deceleration,velocitySampleWindow:x?.velocitySampleWindow??it.velocitySampleWindow,startVelocityThreshold:x?.startVelocityThreshold??it.startVelocityThreshold}),[x]),V=r.useMemo(()=>({top:Math.max(0,Z?.top??0),bottom:Math.max(0,Z?.bottom??0)}),[Z]);N.debug("[ScrollPane] ScrollPane rendered",{contentSize:e,viewportSize:t,scrollBarWidth:n,className:h,style:p,tapScrollCircleOptions:E,inertiaOptions:x,enablePointerDrag:d,contentInsets:V});const W=r.useRef({contentSize:e,viewportSize:t});W.current={contentSize:e,viewportSize:t};const G=r.useMemo(()=>e>t,[e,t]),U=r.useCallback(T=>{const{contentSize:A,viewportSize:D}=W.current,Q=A>D,le=w.current;if(N.debug("[ScrollPane] scrollTo called",{newPosition:T,contentSize:A,viewportSize:D,currentIsScrollable:Q,prevPosition:le}),!Q)return w.current!==0&&(w.current=0,m?.(0,le)),w.current;const Ee=typeof T=="function"?T(w.current):T,de=Math.max(A-D,0),ne=fe(Ee,0,de);return w.current!==ne&&(w.current=ne,m?.(ne,le)),w.current},[m]),L=r.useCallback(()=>{const T=xe.current;T.frame!==null&&cancelAnimationFrame(T.frame),T.frame=null,T.velocity=0,T.lastTimestamp=null},[]),ve=r.useRef(L);r.useEffect(()=>{ve.current=L},[L]);const ae=r.useCallback(T=>{if(!G)return;const{maxVelocity:A,minVelocity:D,deceleration:Q,startVelocityThreshold:le}=_,Ee=fe(T,-A,A);if(Math.abs(Ee)<le)return;L(),xe.current.velocity=Ee,xe.current.lastTimestamp=null;const de=ne=>{const se=xe.current;if(se.lastTimestamp===null){se.lastTimestamp=ne,se.frame=requestAnimationFrame(de);return}const Ce=ne-se.lastTimestamp;if(se.lastTimestamp=ne,Ce<=0){se.frame=requestAnimationFrame(de);return}const ye=se.velocity;let Pe=ye;const we=Q*Ce;ye>0?Pe=Math.max(0,ye-we):ye<0&&(Pe=Math.min(0,ye+we));const me=(ye+Pe)/2*Ce,g=w.current;me!==0&&U(ue=>ue+me);const M=w.current,{contentSize:$,viewportSize:ie}=W.current,ce=Math.max($-ie,0);se.velocity=Pe;const Le=M===g||M<=0&&Pe<=0||M>=ce&&Pe>=0;if(Math.abs(Pe)<D||Le){L();return}se.frame=requestAnimationFrame(de)};xe.current.frame=requestAnimationFrame(de)},[G,_,U,L]),be=r.useRef(ae);r.useEffect(()=>{be.current=ae},[ae]),r.useLayoutEffect(()=>{W.current={contentSize:e,viewportSize:t}},[e,t]),r.useLayoutEffect(()=>{const T=K.current;if(!T)return;const A=()=>{T.scrollTop!==0&&(N.debug("[ScrollPane] Native scroll detected, resetting to 0",{scrollTop:T.scrollTop}),T.scrollTop=0),T.scrollLeft!==0&&(T.scrollLeft=0)};return T.addEventListener("scroll",A),()=>T.removeEventListener("scroll",A)},[]),r.useLayoutEffect(()=>{if(G){N.debug("[ScrollPane] Adjusting scroll position due to content or viewport size change",{contentSize:e,viewportSize:t,scrollPosition:w.current});const T=fe(e-t,0,e);w.current>T&&U(T)}else U(0)},[G,U,e,t]),r.useEffect(()=>{const T=D=>{if(!G)return;D.preventDefault(),L();let Q=D.deltaY;D.deltaMode===1?Q*=16:D.deltaMode===2&&(Q*=t),q!==1&&(Q*=q),N.debug("[ScrollPane] wheel event",{deltaY:Q,scrollPosition:w.current,wheelSpeedMultiplier:q,deltaMode:D.deltaMode,scrollTop:K.current?.scrollTop}),U(le=>le+Q)},A=j.current;return A&&A.addEventListener("wheel",T,{passive:!1}),()=>{A&&A.removeEventListener("wheel",T)}},[G,U,L,t,q]),r.useImperativeHandle(J,()=>({scrollTo:T=>(L(),U(T)),getScrollPosition:()=>w.current,getContentSize:()=>e,getViewportSize:()=>t}),[U,e,t,L]);const I=r.useRef(U);r.useEffect(()=>{I.current=U},[U]);const Se=r.useId(),v=r.useRef({pointerId:null,startClientY:0,startScroll:0,isDragging:!1,shouldCancelNextClick:!1,clickResetTimer:null,velocitySamples:[]}),Ie=r.useRef(d);r.useEffect(()=>{Ie.current=d},[d]);const Me=r.useRef(G);r.useEffect(()=>{Me.current=G},[G]);const Ne=r.useRef(_);return r.useEffect(()=>{Ne.current=_},[_]),r.useEffect(()=>{if(d)return;const T=K.current,A=v.current;A.pointerId&&T?.hasPointerCapture(A.pointerId)&&T.releasePointerCapture(A.pointerId),A.clickResetTimer!==null&&(window.clearTimeout(A.clickResetTimer),A.clickResetTimer=null),A.pointerId=null,A.startClientY=0,A.startScroll=0,A.isDragging=!1,A.shouldCancelNextClick=!1,A.velocitySamples=[]},[d]),r.useEffect(()=>{const T=K.current;if(!T)return;const A=6,D=()=>typeof performance<"u"&&typeof performance.now=="function"?performance.now():Date.now(),Q=()=>{const g=v.current;g.pointerId=null,g.startClientY=0,g.startScroll=0,g.isDragging=!1,g.velocitySamples=[]},le=()=>{const g=v.current;g.clickResetTimer!==null&&(window.clearTimeout(g.clickResetTimer),g.clickResetTimer=null)},Ee=g=>{const M=v.current,$=D();M.velocitySamples.push({clientY:g,time:$});const ie=Ne.current.velocitySampleWindow;M.velocitySamples=M.velocitySamples.filter(ce=>$-ce.time<=ie)},de=g=>g instanceof HTMLElement&&g.closest("[data-scrollpane-ignore-drag='true']")!==null,ne=g=>{const M=v.current;M.shouldCancelNextClick&&(g.preventDefault(),g.stopPropagation(),M.shouldCancelNextClick=!1)},se=g=>{const M=v.current;M.isDragging||(M.isDragging=!0,M.shouldCancelNextClick=!0,T.hasPointerCapture(g.pointerId)||T.setPointerCapture(g.pointerId),Ee(g.clientY))},Ce=g=>{const M=v.current;if(M.pointerId!==g.pointerId||!(Ie.current&&Me.current)||!M.isDragging&&(Math.abs(g.clientY-M.startClientY)<A||(se(g),!M.isDragging)))return;Ee(g.clientY);const $=g.clientY-M.startClientY,ie=M.startScroll-$;I.current(ie),g.cancelable&&g.preventDefault()},ye=g=>{const M=v.current;if(M.pointerId!==g.pointerId)return;M.isDragging&&M.shouldCancelNextClick&&g.cancelable&&(g.preventDefault(),g.stopPropagation()),T.hasPointerCapture(g.pointerId)&&T.releasePointerCapture(g.pointerId);let $=0;if(M.isDragging&&M.velocitySamples.length>=2){const ce=M.velocitySamples,Le=Ne.current.velocitySampleWindow,ue=ce[ce.length-1],Fe=ce.find($e=>ue.time-$e.time<=Le)??ce[0];if(ue&&Fe&&ue.time!==Fe.time){const $e=ue.clientY-Fe.clientY,ke=ue.time-Fe.time;$=-($e/ke)}}le(),M.shouldCancelNextClick&&(M.clickResetTimer=window.setTimeout(()=>{const ce=v.current;ce.shouldCancelNextClick=!1,ce.clickResetTimer=null},0));const ie=Ne.current.startVelocityThreshold;Q(),Math.abs($)>=ie&&be.current?.($)},Pe=g=>{if(!(Ie.current&&Me.current)||g.button!==0&&g.pointerType==="mouse"||g.ctrlKey||g.metaKey||g.altKey||de(g.target))return;window.dispatchEvent(new CustomEvent(bt,{detail:{paneId:Se}})),ve.current?.();const M=v.current;le(),M.pointerId=g.pointerId,M.startClientY=g.clientY,M.startScroll=w.current,M.isDragging=!1,M.shouldCancelNextClick=!1,M.velocitySamples=[]},we=g=>{const M=v.current;M.pointerId===g.pointerId&&(M.shouldCancelNextClick=!1,T.hasPointerCapture(g.pointerId)&&T.releasePointerCapture(g.pointerId),le(),Q())},Ye=[["click",ne,!0],["pointerdown",Pe,{passive:!1}],["pointermove",Ce,{passive:!1}],["pointerup",ye,void 0],["pointercancel",we,void 0]],me=[["pointermove",Ce,{passive:!1}],["pointerup",ye,void 0],["pointercancel",we,void 0]];return ut(T,Ye,"add"),ut(window,me,"add"),()=>{ut(T,Ye,"remove"),ut(window,me,"remove");const g=v.current;g.pointerId!==null&&T.hasPointerCapture(g.pointerId)&&T.releasePointerCapture(g.pointerId),le(),Q()}},[Se]),F.jsxs("div",{ref:j,className:Ze.twMerge("aqvs-scroll-pane",h),style:p,children:[F.jsxs("div",{ref:K,className:Ze.twMerge("aqvs-scroll-pane-content"),style:{height:t,paddingTop:V.top,paddingBottom:V.bottom,...d?{touchAction:"none"}:{}},id:Se,children:[b,s(w.current)]}),F.jsx(yt,{contentSize:e,viewportSize:t,scrollPosition:w.current,onScroll:U,enableThumbDrag:o,enableTrackClick:c,enableArrowButtons:u,scrollBarWidth:n,ariaControls:Se,tapScrollCircleOptions:E,itemCount:k,renderThumbOverlay:X,visibleStartIndex:ge,visibleEndIndex:oe},"scrollbar"),re?.()]})}),St=(s,e,t)=>Math.min(Math.max(s,e),t),Qt=({dragState:s,normalizedDistance:e,sizeScale:t,size:n})=>{const o=Math.max(n/2,1),c=1+e*.65,u=Math.max(.65,1-e*.25),d=s.direction*e*26*t,m=.8+e*.18,h=3*t,p=6*t,b=22*t,E=Math.abs(d)+p,x=d>0?h:-Math.abs(d)-h,k=Math.max(2.5,3*t),X=St(s.offsetX,-o,o),q=St(s.offsetY,-o,o),Z=o*.35,ge=X/o*Z,oe=q/o*Z,re=ge*.45,Y=oe*.45,J=Math.max(b*.38,6),w=.65+e*.2,j=s.active;return F.jsxs(F.Fragment,{children:[F.jsx("div",{className:"aqvs-tap-scroll-circle-gradient",style:{transform:`scale(${u}, ${c})`,transition:j?"40ms transform ease-out":"200ms ease transform"}}),F.jsx("div",{className:"aqvs-sample-visual-rod",style:{width:b,height:b,transform:`translate(calc(-50% + ${ge}px), calc(-50% + ${oe}px)) scale(${u}, ${m*c})`,transition:j?"70ms transform ease-out":"200ms ease transform"}}),F.jsx("div",{className:"aqvs-sample-visual-pupil",style:{width:J,height:J,transform:`translate(calc(-50% + ${re}px), calc(-50% + ${Y}px)) scale(${u}, ${c})`,opacity:w,boxShadow:"0 0 8px rgba(255,255,255,0.45)",transition:j?"120ms opacity 150ms, 120ms transform ease-out ease-out":"220ms ease transform, 240ms opacity ease"}}),F.jsx("div",{className:"aqvs-sample-visual-highlight",style:{width:k,height:E,transform:`translate(-50%, ${x}px)`,opacity:e,transition:j?"40ms height, 60ms opacity ease-out ease-out":"200ms ease height, 120ms ease opacity"}})]})},er=s=>{if(!Number.isFinite(s))return 0n;const e=Math.trunc(s);return e<=0?0n:BigInt(e)},ft=s=>{if(s<=0||!Number.isFinite(s))return 0;const e=Math.trunc(s),t=BigInt(e)&-BigInt(e);return Number(t)};class Et{tree;deltas;size;baseValue;valueFn;total;constructor(e,t,n){this.reset(e,t,n)}reset(e,t,n){if(this.size=e,this.tree=new Map,this.deltas=new Map,this.total=void 0,typeof t=="function"){if(this.valueFn=t,this.size>0){const c=n?.sampleRange??{from:0,to:Math.min(99,this.size-1)},{mode:u,materializedValues:d}=this._calculateMode(c.from,c.to);if(this.baseValue=u,n?.materialize)for(let m=0;m<d.length;m++){const h=d[m],p=c.from+m;if(p>=this.size)break;const b=h-this.baseValue;this.deltas.set(p,b),this._updateTree(p,b)}}else this.baseValue=0;this.total=this.getTotal()}else this.valueFn=void 0,this.baseValue=t,this.total=this.baseValue*this.size}setValueFn(e,t){if(t?.reset){this.reset(this.size,e);return}typeof e=="function"?this.valueFn=e:(this.valueFn=void 0,this.baseValue=e)}_calculateMode(e,t){if(!this.valueFn)return{mode:0,materializedValues:[]};const n=[];for(let h=e;h<=t&&!(h>=this.size);h++)n.push(this.valueFn(h));const o=[...n];if(n.length===0)return{mode:0,materializedValues:[]};n.sort((h,p)=>h-p);const c=Math.floor(n.length/2);let u;n.length%2===0?u=Math.floor((n[c-1]+n[c])/2):u=n[c];const d=new Map;let m=0;for(const h of n){const p=(d.get(h)??0)+1;d.set(h,p),p>m&&(m=p)}if(m>n.length*.2){const h=[];for(const[b,E]of d.entries())E===m&&h.push(b);const p=h.reduce((b,E)=>b+E,0);u=Math.floor(p/h.length)}return{mode:u,materializedValues:o}}update(e,t){return this.updates([{index:e,value:t}])}updates(e){const t=this._buildDeltaUpdates(e);return t.length>0?this.updateDeltas(t):this.total}updateDelta(e,t){return this.updateDeltas([{index:e,change:t}])}updateDeltas(e){for(const{index:t,change:n}of e){if(t<0||t>=this.size)throw new Error(`Index ${t} out of bounds`);const o=this.deltas.get(t)??0;this.deltas.set(t,o+n),this._updateTree(t,n)}return this.total}_updateTree(e,t){if(t===0)return;let n=e+1;for(;n<=this.size;){this.tree.set(n,(this.tree.get(n)??0)+t);const o=ft(n);if(o===0)break;n+=o}this.total!==void 0&&(this.total+=t)}_buildDeltaUpdates(e){const t=[];for(const{index:n,value:o}of e){if(n<0||n>=this.size)throw new Error(`Index ${n} out of bounds`);if(o<0)throw new Error("Value cannot be negative.");const c=this.deltas.has(n)?(this.deltas.get(n)??0)+this.baseValue:this.baseValue,u=o-c;u!==0&&t.push({index:n,change:u})}return t}_computeTreeTotal(){if(this.size<=0)return 0;let e=0,t=this.size;for(;t>0;){e+=this.tree.get(t)??0;const n=ft(t);if(n===0)break;t-=n}return e+this.baseValue*this.size}_materialize(e,t=!0){if(this.valueFn){const n=this.deltas.get(e)??0,c=this.valueFn(e)-this.baseValue;if(c!==n&&(this.deltas.set(e,c),t)){const u=c-n;this._updateTree(e,u)}}}_materializeRanges(e,t,n=!1){if(!(e?.materialize&&this.valueFn))return;const o=e.ranges;if(o&&o.length>0){for(const d of o){const m=d.from,h=Math.min(d.to,this.size-1);for(let p=m;p<=h;p++)this._materialize(p)}if(t===void 0)return;if(n){this._materialize(t);return}const c=o[0].from,u=o[o.length-1].to;t>=c&&t<=u&&this._materialize(t);return}t!==void 0&&this._materialize(t)}_findIndex(e,t={},n){if(this.size>2147483647)return this._findIndexLarge(e,t,n);if(this.size===0)return{index:-1,total:this.total??0,cumulative:void 0,currentValue:void 0,safeIndex:void 0};let o=0,c=0,u=1;for(;u<<1<=this.size;)u<<=1;for(;u>0;u>>=1){const h=o+u;if(h<=this.size){const b=(this.tree.get(h)??0)+this.baseValue*u;(n?c+b<e:c+b<=e)&&(o=h,c+=b)}}const d=n?o:o-1;if(d<0||d>=this.size)return{index:-1,total:this.total??this.getTotal(),cumulative:void 0,currentValue:void 0,safeIndex:void 0};const m=this.prefixSum(d,t);return{index:d,total:this.total??m.total,cumulative:m.cumulative,currentValue:m.currentValue,safeIndex:m.safeIndex}}_findIndexLarge(e,t,n){if(this.size===0)return{index:-1,total:this.total??0,cumulative:void 0,currentValue:void 0,safeIndex:void 0};const o=er(this.size);if(o===0n)return{index:-1,total:this.total??0,cumulative:void 0,currentValue:void 0,safeIndex:void 0};let c=0n,u=o-1n,d,m,h,p=this.total;for(;c<=u;){const x=c+u>>1n,k=Number(x),X=this.prefixSum(k,t);if(h=X,p=X.total,n?X.cumulative>=e:X.cumulative<=e)if(d=x,m=X,n){if(x===0n)break;u=x-1n}else c=x+1n;else if(n)c=x+1n;else{if(x===0n)break;u=x-1n}}const b=m??h;return{index:d!==void 0?Number(d):-1,total:p,cumulative:b?.cumulative,currentValue:b?.currentValue,safeIndex:b?.safeIndex}}prefixSum(e,t){if(e<0)return{cumulative:0,total:this.total,currentValue:0,safeIndex:0};const n=fe(e,0,this.size-1),o=t?.materializeOption;this._materializeRanges(o,n,!0);let c=0,u=n+1;for(;u>0;){const m=this.tree.get(u)??0;c+=m;const h=ft(u);if(h===0)break;u-=h}const d=o?.materialize?this.get(n):(this.deltas.get(n)||0)+this.baseValue;return{cumulative:c+this.baseValue*(n+1),total:this.total,currentValue:d,safeIndex:n}}get(e,t){if(e<0||e>=this.size)throw new Error("Index out of bounds");const n=t?.materializeOption;return this._materializeRanges(n,e),(this.deltas.get(e)??0)+this.baseValue}getTotal(e){const t=e?.materializeOption;if(this._materializeRanges(t),this.total===void 0)if(this.size===0)this.total=0;else{this.total=this._computeTreeTotal();const n=this.prefixSum(this.getSize()-1);n.cumulative!==n.total&&N.error("Inconsistent Fenwick Tree state")}return this.total}rebuildTree(e){if(e?.materialize&&this.valueFn){const n=this.valueFn;this.reset(this.size,o=>n(o),{materialize:!0});return}const t=new Map;for(const[n,o]of this.deltas.entries()){if(o===0)continue;let c=n+1;for(;c<=this.size;){t.set(c,(t.get(c)??0)+o);const u=ft(c);if(u===0)break;c+=u}}this.tree=t,this.total=this._computeTreeTotal()}calculateAccumulatedError(){if(this.total===void 0)return 0;let e=this.baseValue*this.size;for(const t of this.deltas.values())e+=t;return this.total-e}changeSize(e){const t=this.size;if(e===t)return;if(e<t)for(const o of this.deltas.keys())o>=e&&this.deltas.delete(o);this.size=e,this.rebuildTree();const n=this.prefixSum(this.getSize()-1);n.cumulative!==n.total&&N.error("Inconsistent Fenwick Tree state")}getSize(){return this.size}findIndexAtOrAfter(e,t){return this._findIndex(e,t??{},!0)}findIndexAtOrBefore(e,t){return this._findIndex(e,t??{},!1)}}const kt=(s,e,t)=>{const n=Math.max(0,s),o=r.useRef(null),c=r.useRef({size:n,valueOrFn:e,options:t});o.current===null&&(o.current=new Et(n,e,t));const u=o.current,d=c.current,m=d.size!==n,h=d.valueOrFn!==e,p=d.options!==t;if(h||p){const b=t?.resetOnValueFnChange??!0;p||h&&b?(t?.debug&&N.debug("[useFenwickMapTree] reset",{valueOrFnChanged:h,optionsChanged:p}),u.reset(n,e,t)):(m&&(t?.debug&&N.debug("[useFenwickMapTree] resize (with valueFn change)",{from:d.size,to:n}),u.changeSize(n)),t?.debug&&N.debug("[useFenwickMapTree] setValueFn (no reset)",{valueOrFnChanged:h}),u.setValueFn(e,{reset:!1})),c.current={size:n,valueOrFn:e,options:t}}else m&&(t?.debug&&N.debug("[useFenwickMapTree] resize",{from:d.size,to:n}),d.size===0&&n>0?u.reset(n,e,t):u.changeSize(n),c.current={size:n,valueOrFn:e,options:t});return u};class tr{key;value;prev=null;next=null;constructor(e,t){this.key=e,this.value=t}}class Mt{head=null;tail=null;addToTail(e){this.tail?(this.tail.next=e,e.prev=this.tail,this.tail=e):this.head=this.tail=e}remove(e){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}removeHead(){const e=this.head;return e&&this.remove(e),e}moveToTail(e){this.remove(e),this.addToTail(e)}}function Vt(s){const e=r.useRef(new Map),t=r.useRef(new Mt);r.useEffect(()=>{for(;e.current.size>s;){const p=t.current.removeHead();if(p)e.current.delete(p.key);else break}},[s]);const n=r.useCallback(p=>{const b=e.current.get(p);if(b)return t.current.moveToTail(b),b.value},[]),o=r.useCallback((p,b)=>{if(s<=0)return;let E=e.current.get(p);if(E)E.value=b,t.current.moveToTail(E);else{if(e.current.size>=s){const x=t.current.removeHead();x&&e.current.delete(x.key)}E=new tr(p,b),e.current.set(p,E),t.current.addToTail(E)}},[s]),c=r.useCallback(p=>e.current.has(p),[]),u=r.useCallback(p=>{const b=e.current.get(p);b&&(t.current.remove(b),e.current.delete(p))},[]),d=r.useCallback(()=>{e.current.clear(),t.current=new Mt},[]),[m,h]=r.useState(()=>({get:n,set:o,has:c,remove:u,clear:d}));return r.useEffect(()=>h({get:n,set:o,has:c,remove:u,clear:d}),[n,o,c,u,d]),m}const rr=1e4,nr=()=>{const{get:s,set:e,has:t,clear:n}=Vt(rr);return{get:s,set:e,has:t,clear:n}},te=(s,e)=>e<=0?0:fe(s,0,e-1),Pt=s=>({top:Math.max(0,s?.top??0),bottom:Math.max(0,s?.bottom??0)}),Ue=(s,e)=>s<=e?0:s-e,tt=(s,e)=>s<=0?e:s+e,gt=s=>{if(!Number.isFinite(s))return 0n;const e=Math.trunc(s);return e<=0?0n:BigInt(e)},sr=(s,e,t,n,o,c,u,d)=>{const m=gt(n);if(m===0n)return{renderingStartIndex:0,renderingEndIndex:0,visibleStartIndex:0,visibleEndIndex:0};const h=Y=>Y<0n?0n:Y>=m?m-1n:Y,p={materializeOption:{materialize:!1}},{index:b,cumulative:E}=c.findIndexAtOrAfter(s,p);let x;b===-1?x=m-1n:(E===s?x=gt(b+1):x=gt(b),x>=m&&(x=m-1n)),s<=0&&(x=0n),d&&s>=u&&(x=m-1n);const k=Y=>{let J=0,w=Y,j=Y,K=0n;for(;w<m&&J<e;){const xe=Number(w),_=o(xe);if(J+=_,j=w,w+=1n,K+=1n,!Number.isFinite(_)||_<=0)break}return K===0n&&(j=Y),{height:J,end:j}};let{height:X,end:q}=k(x);if(X<e&&x>0n){let Y=x,J=X;for(;Y>0n&&J<e;){Y-=1n;const j=Number(Y),K=o(j);if(J+=K,!Number.isFinite(K)||K<=0)break}x=h(Y);const w=k(x);X=w.height,q=w.end}const Z=h(x),ge=h(q),oe=h(Z-BigInt(Math.max(0,t))),re=h(ge+BigInt(Math.max(0,t)));return{renderingStartIndex:te(Number(oe),n),renderingEndIndex:te(Number(re),n),visibleStartIndex:te(Number(Z),n),visibleEndIndex:te(Number(ge),n)}},ir=(s,e,t,n,o,c,u)=>{if(n===0)return{renderingStartIndex:0,renderingEndIndex:0,visibleStartIndex:0,visibleEndIndex:0};const d=Number.isFinite(u),m=d?Math.min(Math.max(0,s),u):Math.max(0,s);if(n>=Number.MAX_SAFE_INTEGER)return sr(m,e,t,n,o,c,u,d);const{index:h,cumulative:p,currentValue:b}=c.findIndexAtOrAfter(m,{materializeOption:{materialize:!1}}),E=h===-1?e<=0||(p??0)<m+(b??0)?n-1:0:h;let x=te(E,n),k=0;if(h!==-1&&p===m)x=te(h+1,n),k=0;else if(x===h&&p!==void 0&&b!==void 0)k=p-b-m;else{const{cumulative:re,currentValue:Y}=c.prefixSum(x,{materializeOption:{materialize:!1}});k=(re??0)-(Y??0)-m}const X=k;let q=x;for(;q<n&&k<e;)k+=o(q),q++;if(k<e&&x>0){let re=k+Math.abs(Math.min(0,X)),Y=x-1;for(;Y>=0&&re<e;)re+=o(Y),Y--;for(x=te(Y+1,n),k=0,q=x;q<n&&k<e;)k+=o(q),q++}const Z=te(x-t,n),ge=te(Math.max(q-1,x),n),oe=te(ge+t,n);return{renderingStartIndex:Z,renderingEndIndex:oe,visibleStartIndex:x,visibleEndIndex:ge}},Rt=(s,e,t)=>{const n=Math.max(0,e??0),o=r.useRef({last:0,id:null,arg:null}).current;return r.useEffect(()=>()=>{o.id!==null&&(cancelAnimationFrame(o.id),o.id=null)},[o]),r.useCallback(c=>{if(o.arg=c,o.id!==null)return;const u=d=>{if(o.id=null,o.arg===null)return;const m=d-o.last;if(n===0||o.last===0||m>=n){if(s.current)try{t(s.current,o.arg)}catch(h){console.error("[useThrottledInvoker] Error invoking callback",h)}o.arg=null,o.last=d}o.arg!==null&&(o.id=requestAnimationFrame(u))};o.id=requestAnimationFrame(u)},[n,t,s,o])},or=r.memo(({index:s,top:e,height:t,item:n,children:o,clipItemHeight:c,enableKeyboardNavigation:u,onKeyDown:d,onFocus:m,registerItemRef:h})=>{const p=r.useCallback(k=>h(s,k),[s,h]),b=r.useCallback(k=>d(k,s),[s,d]),E=r.useCallback(()=>m(s),[s,m]),x=r.useCallback(k=>{k.currentTarget.focus({preventScroll:!0})},[]);return F.jsx("div",{ref:p,"data-index":s,"data-virtualscroll-item":"true",className:"aqvs-item-container",style:{top:e,height:t,overflow:c?"hidden":void 0},tabIndex:u?-1:void 0,onPointerDown:u?x:void 0,onKeyDownCapture:u?b:void 0,onFocusCapture:u?E:void 0,children:o(n,s)})}),ar=({itemCount:s,getItem:e,getItemKey:t,getItemHeight:n,viewportSize:o,overscanCount:c=15,className:u,onScroll:d,onRangeChange:m,children:h,background:p,initialScrollIndex:b,initialScrollOffset:E,callbackThrottleMs:x=5,contentInsets:k,onItemFocus:X,scrollBarOptions:q,behaviorOptions:Z},ge)=>{const{width:oe,enableThumbDrag:re,enableTrackClick:Y,enableArrowButtons:J,enableScrollToTopBottomButtons:w,renderThumbOverlay:j,tapScrollCircleOptions:K}=q??{},{enablePointerDrag:xe,enableKeyboardNavigation:_=!0,wheelSpeedMultiplier:V,inertiaOptions:W,clipItemHeight:G=!1,resetOnGetItemHeightChange:U=!1}=Z??{},L=r.useRef(null),ve=r.useRef({renderingStartIndex:0,renderingEndIndex:0,visibleStartIndex:0,visibleEndIndex:0,scrollPosition:0,totalHeight:0}),ae=r.useRef(null),be=r.useRef(!1);r.useEffect(()=>{U&&(ae.current=null)},[U]);const I=r.useMemo(()=>Pt(k),[k]),Se=r.useMemo(()=>({sampleRange:{from:0,to:100},resetOnValueFnChange:U,materialize:!0}),[U]),v=kt(s,n,Se),[Ie]=r.useState(()=>{let i=I.top,l=0;if(typeof b=="number"){const f=fe(b,0,s-1),P=fe(f-c*2,0,s-1),R=fe(f+c*2,0,s-1),y=b>0?{materializeOption:{materialize:!0,ranges:[{from:P,to:R}]}}:void 0,{cumulative:z,total:B,currentValue:O}=v.prefixSum(b,y),H=Math.max(z-O,0);i=tt(H,I.top),l=B??v.getTotal()}else typeof E=="number"&&(i=tt(Math.max(E,0),I.top)),l=v.getTotal();return{position:i,total:l}}),[Me,Ne]=r.useState(Ie.position),[T,A]=r.useState(Ie.total),D=r.useRef(Ie.position),Q=r.useRef(I.top),le=r.useRef(d??void 0),Ee=r.useRef(m??void 0),de=r.useRef(new Map),ne=r.useRef(null),se=r.useRef(null),[Ce,ye]=r.useState(null),[Pe,we]=r.useState(!1),Ye=r.useRef(null),me=r.useRef(!1),g=r.useRef(0),M=r.useRef(!1),$=r.useRef(s);$.current!==s&&($.current=s,M.current=!0),r.useEffect(()=>{le.current=d??void 0,Ee.current=m??void 0},[m,d]);const ie=r.useCallback(i=>{if(_&&i&&typeof i.focus=="function")try{i.focus({preventScroll:!0})}catch{i.focus()}},[_]),ce=r.useCallback((i,{position:l,totalHeight:f})=>{i(l,f)},[]),Le=Rt(le,x,ce),ue=r.useCallback((i,l)=>{i(l)},[]),Fe=Rt(Ee,x,ue);r.useEffect(()=>(be.current=!0,()=>{be.current=!1}),[]),r.useEffect(()=>{_||(de.current.clear(),ne.current=null,se.current=null)},[_]);const $e=r.useCallback((i,l)=>{if(!l){de.current.delete(i);return}_&&(de.current.set(i,l),ne.current===i&&(ne.current=null,se.current=i,ie(l)))},[_,ie]),ke=.01,ze=r.useRef({rafId:null,loopActive:!1,idleFrames:0,lastRenderedPosition:Ie.position}),Te=r.useCallback(()=>{const i=ze.current;i.rafId!==null&&typeof cancelAnimationFrame=="function"&&cancelAnimationFrame(i.rafId),i.rafId=null,i.loopActive=!1,i.idleFrames=0},[]);r.useEffect(()=>()=>{Te()},[Te]);const Re=r.useCallback(()=>{const i=ze.current;i.rafId=null;const l=D.current,f=Ue(l,I.top),P=v.getTotal();if(Ne(y=>Math.abs(y-l)<ke?y:l),Le({position:f,totalHeight:P}),Math.abs(i.lastRenderedPosition-l)>=ke?(i.lastRenderedPosition=l,i.idleFrames=0):i.idleFrames+=1,i.idleFrames>=2){Te();return}if(typeof requestAnimationFrame=="function"){i.rafId=requestAnimationFrame(Re);return}i.loopActive=!1},[v,I.top,Le,Te]),We=r.useCallback(()=>{const i=ze.current;if(i.idleFrames=0,!i.loopActive){if(i.loopActive=!0,typeof requestAnimationFrame=="function"){i.rafId=requestAnimationFrame(Re);return}i.loopActive=!1}},[Re]),ee=r.useCallback((i,l)=>{const f=l?.immediate??!1,P=Ue(i,I.top);if(D.current=i,f){ze.current.lastRenderedPosition=i,ze.current.idleFrames=0,Ne(i),Le({position:P,totalHeight:v.getTotal()});return}We()},[We,v,I.top,Le]),ot=r.useRef(!1);r.useEffect(()=>{if(!ot.current)if(ot.current=!0,typeof E=="number"){const i=tt(Math.max(E,0),I.top),l=Math.abs(i-D.current)>.5;ee(i,{immediate:!0}),l&&L.current?.scrollTo(i)}else ee(D.current,{immediate:!0})},[E,I.top,ee]),r.useEffect(()=>{const i=v.getTotal();T!==i&&A(i)},[v,T,s]),r.useEffect(()=>{if(ae.current!==null){const{index:i,align:l,offset:f}=ae.current,P=te(i,s),{cumulative:R,currentValue:y}=v.prefixSum(P,{materializeOption:{materialize:!1}});if(R!==void 0&&y!==void 0){const z=Math.max(R-y,0);let B=z;l==="bottom"?B=R-o:l==="center"&&(B=z+y/2-o/2),f&&(B-=f),B=Math.max(0,B);const O=Math.max(0,T+I.top+I.bottom-o),H=Math.min(tt(B,I.top),O);Math.abs(H-D.current)>1&&(N.debug("[VirtualScroll] Drift correction",{from:D.current,to:H,targetIndex:P}),g.current===0&&(g.current+=1),L.current?.scrollTo(H),ee(H,{immediate:!0}))}}M.current=!1},[T,v,s,I.top,ee,o,I.bottom]),r.useEffect(()=>{const i=Q.current;if(i===I.top)return;const l=Ue(D.current,i),f=tt(l,I.top);Q.current=I.top,D.current=f,L.current?.scrollTo(f),ee(f,{immediate:!0})},[I.top,ee]);const rt=r.useCallback((i,l)=>{const f=te(i,s),P=v.get(f),R=l-P,y=v.update(f,l);y!==void 0&&A(y),N.debug("[VirtualScroll] Updated item size manually",{index:f,size:l,total:y});let z=ae.current?ae.current.index:null;if(z===null){const B=D.current,O=Pt(k).top,H=Ue(B,O),{index:pe}=v.findIndexAtOrAfter(H,{materializeOption:{materialize:!1}});z=pe}if(z!==-1&&f<z&&R!==0){const B=D.current,O=B+R;g.current+=1,ee(O,{immediate:!0}),L.current?.scrollTo(O),N.debug("[VirtualScroll] Adjusted scroll for layout shift (manual update)",{from:B,to:O,causedByIndex:f,delta:R,activeVisibleStartIndex:z})}},[v,s,ee,k]),Ve=r.useCallback((i,l)=>{if(!L.current)return;const f=te(i,s),P=te(f-c*2,s),R=te(f+c*2,s),{cumulative:y,total:z,currentValue:B}=v.prefixSum(f,{materializeOption:{materialize:!0,ranges:[{from:P,to:R}]}});if(N.debug("[VirtualScroll] Scrolling to index:",f,"ItemBottom:",y,"Total height:",z,"ItemHeight:",B,"safeIndexFrom:",P,"safeIndexTo:",R),!z)return;const O=Math.max(y-B,0);let H=O;l?.align==="bottom"?H=y-o:l?.align==="center"&&(H=O+B/2-o/2),l?.offset&&(H-=l.offset),H=Math.max(0,H);const pe=tt(H,I.top),he=L.current?.getContentSize()??z+I.top+I.bottom,De=Math.max(0,he-o),Ke=Math.min(pe,De);ae.current={index:f,align:l?.align,offset:l?.offset};const nt=L.current?.getScrollPosition()??-1,st=Math.abs(nt-Ke)>.5;me.current=!1,g.current=0,st&&(me.current=!0,g.current+=1,L.current?.scrollTo(Ke)),A(z),ee(Ke,{immediate:!0}),N.debug("[VirtualScroll] Setting scroll position to:",Ke,{original:pe,max:De})},[v,c,s,I.top,I.bottom,o,ee]),Je=r.useCallback(i=>{if(!L.current)return;const l=v.getTotal(),f=fe(Math.floor(i),0,l),{index:P,cumulative:R,currentValue:y}=v.findIndexAtOrAfter(f,{materializeOption:{materialize:!1}}),B=(R??0)-(y??0)-f;Ve(P,{offset:B})},[v,Ve]),Ge=r.useCallback(i=>{const l=Ue(D.current,I.top),f=typeof i=="function"?i(l):i;Je(f);const P=L.current?.getScrollPosition(),R=typeof P=="number"?P:D.current;return ee(R),R},[I.top,Je,ee]),dt=r.useCallback((i,l)=>{N.debug("[VirtualScroll] Scroll position changed:",i);const f=me.current;f&&(me.current=!1);const P=g.current>0;if(P&&(g.current=0),f||P||M.current||(ae.current=null),ee(i),w){if(f||P)return;const R=i-l;if(N.debug("[VirtualScroll] Scroll diff:",R,"New:",i,"Prev:",l),Math.abs(R)>1){const y=R>0?"down":"up";ye(y),we(!0),N.debug("[VirtualScroll] Showing scroll buttons. Direction:",y),Ye.current&&clearTimeout(Ye.current),Ye.current=setTimeout(()=>{we(!1),N.debug("[VirtualScroll] Hiding scroll buttons")},2e3)}}},[ee,w]),qe=r.useMemo(()=>Ue(Me,I.top),[I.top,Me]),_e=r.useMemo(()=>{const i=v.getTotal(),l=ir(qe,o,c,s,n,v,i);return N.debug("[VirtualScroll] Calculated rendering range:",{...l,scrollPosition:qe,renderingContentSize:i,overscanCount:c,viewportSize:o}),l},[qe,o,c,s,n,v]),{renderingStartIndex:He,renderingEndIndex:Be,visibleStartIndex:Ae,visibleEndIndex:Xe}=_e,je=r.useCallback((i,l)=>{if(!_||s===0)return;const f=te(i,s);if(!(l?.ensureVisible??!0)){const De=de.current.get(f);De&&(ne.current=null,se.current=f,ie(De));return}const R=v.prefixSum(f,{materializeOption:{materialize:!1}}),y=R.currentValue,z=Math.max(R.cumulative-y,0),B=z+y,O=Ue(D.current,I.top),H=O+o;if(z<O||B>H){ne.current=f,Ve(f);return}const he=de.current.get(f);if(he){ne.current=null,se.current=f,ie(he);return}ne.current=f},[_,s,v,I.top,Ve,ie,o]),at=r.useCallback((i,l)=>{if(!_||i.defaultPrevented||i.altKey||i.metaKey||i.ctrlKey)return;const f=i.target;if(f){const P=f.tagName;if(P==="INPUT"||P==="TEXTAREA"||P==="SELECT"||f.isContentEditable)return}if(i.key==="ArrowDown"){l<s-1&&(i.preventDefault(),je(l+1));return}if(i.key==="ArrowUp"){l>0&&(i.preventDefault(),je(l-1));return}if(i.key==="PageDown"){if(l<s-1){i.preventDefault();const P=Math.max(Xe-Ae+1,1),R=Math.max(P,1),y=te(Math.min(l+R,s-1),s);je(y)}return}if(i.key==="PageUp"&&l>0){i.preventDefault();const P=Math.max(Xe-Ae+1,1),R=Math.max(P,1),y=te(l-R,s);je(y)}},[_,s,je,Xe,Ae]),lt=r.useCallback(i=>{if(!_)return;const l=te(i,s);ne.current=null,se.current=l,X?.(l)},[_,s,X]);r.useEffect(()=>{const i=L.current?.getScrollPosition()??0,l=D.current,f=Ue(l,I.top);N.debug("[VirtualScroll] Range change effect triggered",{renderingStartIndex:He,renderingEndIndex:Be,visibleStartIndex:Ae,visibleEndIndex:Xe,scrollPositionState:Me,paneScrollPosition:l,logicalScrollPosition:f,contentSize:T,scrollPaneScrollPosition:i}),Fe({renderingStartIndex:He,renderingEndIndex:Be,visibleStartIndex:Ae,visibleEndIndex:Xe,scrollPosition:f,totalHeight:T})},[T,Be,He,I.top,Fe,Me,Xe,Ae]);const mt=r.useCallback(()=>{if(!w)return null;const i=Pe&&Ce!==null,l=Ce==="up";return F.jsx("div",{className:"aqvs-scroll-to-edge-overlay","data-visible":i,children:l?F.jsx("div",{className:"aqvs-scroll-to-edge-button-container aqvs-scroll-to-edge-button-container-top",children:F.jsx("button",{type:"button",className:"aqvs-scroll-to-edge-button",onClick:f=>{f.stopPropagation(),me.current=!0,Ve(0),we(!1)},children:"Top"})}):F.jsx("div",{className:"aqvs-scroll-to-edge-button-container aqvs-scroll-to-edge-button-container-bottom",children:F.jsx("button",{type:"button",className:"aqvs-scroll-to-edge-button",onClick:f=>{f.stopPropagation(),me.current=!0,Ve(s-1),we(!1)},children:"Bottom"})})})},[w,Pe,Ce,Ve,s]),{visibleItems:Qe,startPosition:et}=r.useMemo(()=>{if(s===0)return{visibleItems:F.jsx("div",{className:"aqvs-no-items-container",children:F.jsx("div",{className:"aqvs-no-items-text",children:"No items"})}),startPosition:0};const i=te(He,s),l=te(Be,s),{cumulative:f,currentValue:P}=v.prefixSum(i,{materializeOption:{materialize:!1}}),R=f-P,y=[],z=[];let B=0;for(let O=i;O<=l;O++){const H=n(O),pe=v.get(O),he=H-pe;he!==0&&y.push({index:O,value:H});const{cumulative:De,currentValue:Ke}=v.prefixSum(O,{materializeOption:{materialize:!1}}),nt=De-Ke+B,st=t?t(O):O;z.push(F.jsx(or,{index:O,top:nt-R+I.top,height:H,item:e(O),clipItemHeight:G,enableKeyboardNavigation:_,onKeyDown:at,onFocus:lt,registerItemRef:$e,children:h},st)),B+=he}return y.length>0&&Promise.resolve().then(()=>{if(!be.current)return;let O=0;for(const he of y)if(he.index<Ae){const De=v.get(he.index);O+=he.value-De}const H=v.updates(y);if(!be.current||typeof H!="number")return;A(H),N.debug("[VirtualScroll] Updated heights for items",y,"New total height:",H);const pe=L.current?.getScrollPosition()??D.current;if(O!==0){const he=pe+O;g.current+=1,ee(he,{immediate:!0}),L.current?.scrollTo(he),N.debug("[VirtualScroll] Adjusted scroll for layout shift (auto update)",{from:pe,to:he,shiftAmount:O})}else pe!==D.current&&ee(pe)}),{visibleItems:z,startPosition:R}},[h,G,_,s,v,e,t,n,lt,at,$e,Be,He,I.top,ee,Ae]),a=r.useCallback(i=>{const l=(x??0)>0,f=Math.abs(i-Me),P=l&&f>.5?Me:i,R=Ue(P,I.top);if(N.debug("[VirtualScroll] Rendering visible items",{currentScrollPosition:i,effectiveScrollPosition:R,renderingStartIndex:He,renderingEndIndex:Be,itemCount:s,viewportSize:o,callbackThrottleMs:x,diff:f,rawEffectiveScrollPosition:P}),s===0)return Qe;const y=et-R,z=I.bottom>0?F.jsx("div",{className:"aqvs-bottom-inset",style:{top:v.getTotal()+I.top-et,height:I.bottom}},"virtualscroll-bottom-inset"):null;return N.debug("[VirtualScroll] Rendering items",{containerTop:y,logicalScrollPosition:qe,resolvedInsets:I,effectiveScrollPosition:R}),F.jsxs("div",{className:"aqvs-items-wrapper",style:{top:y,position:"relative"},children:[Qe,z]})},[x,s,v,qe,Be,He,I,Me,et,o,Qe]),S=r.useMemo(()=>({renderingStartIndex:_e.renderingStartIndex,renderingEndIndex:_e.renderingEndIndex,visibleStartIndex:_e.visibleStartIndex,visibleEndIndex:_e.visibleEndIndex,scrollPosition:qe,totalHeight:v.getTotal()}),[_e,qe,v]);r.useEffect(()=>{ve.current=S},[S]),r.useImperativeHandle(ge,()=>({getScrollPosition:()=>L.current?.getScrollPosition()??-1,getContentSize:()=>L.current?.getContentSize()??-1,getViewportSize:()=>L.current?.getViewportSize()??-1,scrollTo:Ge,scrollToIndex:Ve,getFenwickTreeTotalHeight:()=>v.getTotal(),getFenwickSize:()=>v.getSize(),focusItemAtIndex:je,getRange:()=>ve.current,updateItemSize:rt}),[Ge,Ve,v,je,rt]);const C=v.getTotal()+I.top+I.bottom;return F.jsx(wt,{ref:L,contentSize:C,viewportSize:o,className:u,onScroll:dt,background:p,tapScrollCircleOptions:K,inertiaOptions:W,itemCount:s,scrollBarWidth:oe,enableThumbDrag:re,enableTrackClick:Y,enableArrowButtons:J,enablePointerDrag:xe,renderThumbOverlay:j,wheelSpeedMultiplier:V,contentInsets:I,visibleStartIndex:Ae,visibleEndIndex:Xe,renderOverlay:mt,initialScrollPosition:Ie.position,children:a})},lr=r.forwardRef(ar);exports.FenwickMapTree=Et;exports.ScrollBar=yt;exports.ScrollPane=wt;exports.VirtualScroll=lr;exports.minmax=fe;exports.tapScrollCircleSampleVisual=Qt;exports.useFenwickMapTree=kt;exports.useHeightCache=nr;exports.useLruCache=Vt;