@aiquants/virtualscroll 1.10.0 → 1.12.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 +28 -4
- package/dist/cli.js +0 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +1160 -1148
- package/dist/src/VirtualScroll.d.ts +20 -13
- package/dist/src/VirtualScroll.d.ts.map +1 -1
- package/dist/src/useFenwickMapTree.d.ts +4 -1
- package/dist/src/useFenwickMapTree.d.ts.map +1 -1
- package/dist/styles/virtualscroll.css +2 -2
- package/dist/virtualscroll.css +1 -1
- package/package.json +16 -15
package/README.md
CHANGED
|
@@ -94,10 +94,34 @@ function App() {
|
|
|
94
94
|
| `background` | `ReactNode` | ❌ | Background element |
|
|
95
95
|
| `initialScrollIndex` | `number` | ❌ | Initial scroll index |
|
|
96
96
|
| `initialScrollOffset` | `number` | ❌ | Initial scroll offset |
|
|
97
|
-
| `
|
|
98
|
-
| `
|
|
99
|
-
| `
|
|
100
|
-
| `
|
|
97
|
+
| `contentInsets` | `ScrollPaneContentInsets` | ❌ | Insets for the content area |
|
|
98
|
+
| `callbackThrottleMs` | `number` | ❌ | Throttle time for scroll callbacks (default: 5ms) |
|
|
99
|
+
| `onItemFocus` | `(index: number) => void` | ❌ | Callback when an item is focused |
|
|
100
|
+
| `scrollBarOptions` | `VirtualScrollScrollBarOptions` | ❌ | Options for the scrollbar |
|
|
101
|
+
| `behaviorOptions` | `VirtualScrollBehaviorOptions` | ❌ | Options for scrolling behavior |
|
|
102
|
+
|
|
103
|
+
### VirtualScrollScrollBarOptions
|
|
104
|
+
|
|
105
|
+
| Property | Type | Description |
|
|
106
|
+
|----------|------|-------------|
|
|
107
|
+
| `width` | `number` | Width of the scrollbar |
|
|
108
|
+
| `enableThumbDrag` | `boolean` | Enable dragging the scrollbar thumb |
|
|
109
|
+
| `enableTrackClick` | `boolean` | Enable clicking the scrollbar track |
|
|
110
|
+
| `enableArrowButtons` | `boolean` | Enable arrow buttons on the scrollbar |
|
|
111
|
+
| `enableScrollToTopBottomButtons` | `boolean` | Enable "Scroll to Top" and "Scroll to Bottom" buttons |
|
|
112
|
+
| `renderThumbOverlay` | `(props: ScrollBarThumbOverlayRenderProps) => ReactNode` | Render prop to anchor custom UI near the scrollbar thumb |
|
|
113
|
+
| `tapScrollCircleOptions` | `ScrollBarTapCircleOptions` | Customization for the auxiliary tap scroll circle |
|
|
114
|
+
|
|
115
|
+
### VirtualScrollBehaviorOptions
|
|
116
|
+
|
|
117
|
+
| Property | Type | Description |
|
|
118
|
+
|----------|------|-------------|
|
|
119
|
+
| `enablePointerDrag` | `boolean` | Enable dragging the content area to scroll |
|
|
120
|
+
| `enableKeyboardNavigation` | `boolean` | Enable keyboard navigation (default: true) |
|
|
121
|
+
| `wheelSpeedMultiplier` | `number` | Multiplier for mouse wheel scrolling speed |
|
|
122
|
+
| `inertiaOptions` | `ScrollPaneInertiaOptions` | Physics tuning for drag inertia |
|
|
123
|
+
| `clipItemHeight` | `boolean` | Whether to clip item height (default: false) |
|
|
124
|
+
| `resetOnGetItemHeightChange` | `boolean` | Whether to reset internal height cache when `getItemHeight` changes (default: false) |
|
|
101
125
|
|
|
102
126
|
### VirtualScrollHandle Methods
|
|
103
127
|
|
package/dist/cli.js
CHANGED
|
File without changes
|
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"),Ke=require("tailwind-merge"),pt={active:!1,offsetX:0,offsetY:0,distance:0,direction:0,pointerId:null},ct=6,Lt=8,Ot=({dragState:s,normalizedDistance:e})=>{const t=1+e*.18,n=.16+e*.24,i=.38+e*.28,l=s.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,${n})`,transform:`scale(${t})`,transition:`${l}, ${s.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:s.active?"120ms opacity ease-out":"220ms opacity ease"}})]})},Tt=r.memo(r.forwardRef(({onDragChange:s,className:e,maxVisualDistance:t=160,size:n=40,style:i,opacity:l=1,renderVisual:f},h)=>{const[c,d]=r.useState(pt),u=r.useRef(null),p=r.useRef({x:0,y:0}),v=r.useRef(null),S=r.useRef(0),_=r.useCallback(I=>{d(I),s(I)},[s]),X=r.useCallback((I,L,b=!1)=>{const{x:Q,y}=p.current,le=I-Q,ce=L-y,be=Math.abs(ce),ee=be<ct?0:ce<0?-1:1,z=S.current;let pe=ee;const Ie=ct+Lt;ee===0?z!==0&&be<Ie?pe=z:(pe=0,b||(S.current=0)):ee!==z&&z!==0&&be<Ie?pe=z:S.current=ee,_({active:b||be>=ct,offsetX:le,offsetY:ce,distance:be,direction:pe,pointerId:u.current})},[_]),O=r.useCallback(I=>{if(I===null)return;const L=v.current;L?.hasPointerCapture(I)&&L.releasePointerCapture(I)},[]),B=r.useCallback((I=!1)=>{I&&O(u.current),u.current=null,S.current=0,_(pt)},[_,O]),ge=r.useCallback(I=>{I.preventDefault(),I.stopPropagation();const L=v.current??I.currentTarget,{left:b,top:Q,width:y,height:le}=L.getBoundingClientRect();p.current={x:b+y/2,y:Q+le/2},u.current=I.pointerId,L.setPointerCapture(I.pointerId),X(I.clientX,I.clientY,!0)},[X]),H=r.useCallback(I=>{u.current===I.pointerId&&(I.preventDefault(),X(I.clientX,I.clientY))},[X]),N=r.useCallback(I=>{u.current===I.pointerId&&(I.preventDefault(),I.stopPropagation(),B(!0))},[B]);r.useImperativeHandle(h,()=>({reset:()=>{B(!0)},getElement:()=>v.current}),[B]);const Y=Math.min(Math.max(l,0),1),R=n/64,E=Math.min(c.distance,t)/t,F=c.direction*E*10*R,oe=f??Ot,W={dragState:c,normalizedDistance:E,sizeScale:R,size:n,opacity:Y},Pe={...i,width:n,height:n,transform:`translateY(${F}px)`};return Pe.opacity=Y,A.jsx("div",{ref:v,"data-testid":"virtual-scroll-tap-circle",className:Ke.twMerge("relative flex touch-none select-none items-center justify-center","transition-transform duration-100 ease-out",e),style:Pe,tabIndex:-1,onPointerDown:ge,onPointerMove:H,onPointerUp:N,onPointerCancel:N,role:"presentation",children:oe(W)})}));Tt.displayName="TapScrollCircle";const de=(s,e,t)=>Math.min(t,Math.max(e,s)),ft="virtualscroll:tap-scroll-cancel",mt=20,Yt=250,zt=60,jt=20,Xt=20,Ht=240,ht={active:!1,offsetX:0,offsetY:0,distance:0,direction:0,pointerId:null},ut=2.2,qt=8,Ut=120,$t=1/60,Le={enabled:!0,size:40,offsetX:-80,offsetY:0,className:void 0,maxVisualDistance:Ht,minSpeedMultiplier:.2,opacity:.9,renderVisual:void 0,maxSpeedCurve:void 0},Bt=s=>s?{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"},Wt=(s,e)=>{const t=s?.maxSpeedMultiplier,n=typeof t=="number"?t:Zt(e);return{enabled:s?.enabled??Le.enabled,size:s?.size??Le.size,offsetX:s?.offsetX??Le.offsetX,offsetY:s?.offsetY??Le.offsetY,className:s?.className??Le.className,maxVisualDistance:s?.maxVisualDistance??Le.maxVisualDistance,maxSpeedMultiplier:n,minSpeedMultiplier:Math.max(s?.minSpeedMultiplier??Le.minSpeedMultiplier,0),opacity:de(s?.opacity??Le.opacity,0,1),renderVisual:s?.renderVisual??Le.renderVisual,maxSpeedCurve:s?.maxSpeedCurve??Le.maxSpeedCurve}},Kt=({isDragging:s,isThumbHovered:e,enableThumbDrag:t})=>r.useMemo(()=>t?s?"dragging":e?"hover":"idle":"disabled",[t,s,e]),Gt=({canUseArrowButtons:s,enableArrowButtons:e,resetTapScroll:t,scrollByStep:n})=>{const i=r.useRef(null),l=r.useRef(null),f=r.useCallback(()=>{i.current!==null&&(window.clearInterval(i.current),i.current=null),l.current!==null&&(window.clearTimeout(l.current),l.current=null)},[]),h=r.useCallback(()=>{f()},[f]),c=r.useCallback(u=>p=>{s&&(p.preventDefault(),p.stopPropagation(),t(),f(),n(u),l.current=window.setTimeout(()=>{i.current=window.setInterval(()=>{n(u)},zt)},Yt))},[s,f,t,n]),d=r.useCallback(u=>p=>{e&&(p.key==="Enter"||p.key===" "||p.key==="Spacebar")&&(p.preventDefault(),n(u))},[e,n]);return r.useEffect(()=>()=>{f()},[f]),{handleArrowPointerDown:c,handleArrowPointerUp:h,handleArrowKeyDown:d}},Zt=s=>{if(!s||s<=0)return ut;const e=Math.max(1,s),t=Math.log10(e),n=ut+t*qt;return de(n,ut,Ut)},Ct=({contentSize:s,viewportSize:e,scrollPosition:t,onScroll:n,enableThumbDrag:i=!0,enableTrackClick:l=!0,enableArrowButtons:f=!0,horizontal:h=!1,scrollBarWidth:c=12,className:d,ariaControls:u,tapScrollCircleOptions:p,itemCount:v,renderThumbOverlay:S,visibleStartIndex:_,visibleEndIndex:X})=>{const[O,B]=r.useState(!1),[ge,H]=r.useState(!1),[N,Y]=r.useState(!1),R=r.useRef(null),E=r.useRef({pointerId:null,startThumbPosition:0,startClientX:0,startClientY:0}),F=r.useRef({pointerId:null,startThumbPosition:0,startClientX:0,startClientY:0}),oe=r.useRef(t),W=r.useRef(ht),Pe=r.useRef(null),I=r.useRef(null),L=r.useRef(null),b=r.useMemo(()=>Wt(p,v),[v,p]),Q=r.useMemo(()=>Bt(h),[h]),{enabled:y,size:le,offsetX:ce,offsetY:be,className:ee,maxVisualDistance:z,maxSpeedMultiplier:pe,minSpeedMultiplier:Ie,opacity:V,renderVisual:C,maxSpeedCurve:M}=b,G=r.useRef({viewportSize:e,maxScrollPosition:Math.max(s-e,0),scrollBarVisible:s>e,effectiveTapMaxDistance:Math.max(z,1),tapCircleMaxSpeedMultiplier:pe,tapCircleMinSpeedMultiplier:Ie,tapCircleMaxSpeedCurve:M,tapScrollCircleOptions:p}),{mainSizeKey:Z,crossSizeKey:ne,positionKey:xe,selectDelta:te,getPointerCoordinate:ue,arrowLabels:ie,arrowIcons:Ve,directionClass:Te,orientation:me}=Q,ye=Math.max(z,1),_e=e/s,Ce=c,m=Math.max(e-Ce*2,0),P=_e*m,se=Math.min(Math.max(mt,P||0),m||mt),q=s-e,U=Math.max(m-se,0),we=q<=0||U<=0?0:t/q*U,Re=we+se/2,j=s>e,Oe=j&&f;G.current={viewportSize:e,maxScrollPosition:q,scrollBarVisible:j,effectiveTapMaxDistance:ye,tapCircleMaxSpeedMultiplier:pe,tapCircleMinSpeedMultiplier:Ie,tapCircleMaxSpeedCurve:M,tapScrollCircleOptions:p},r.useEffect(()=>{oe.current=t},[t]),r.useEffect(()=>{i||H(!1)},[i]);const Se=Kt({isDragging:O,isThumbHovered:ge,enableThumbDrag:i}),Ye=r.useCallback((o,g)=>{const w=G.current,re=g??oe.current;if(n){const Me=n(o,re);if(typeof Me=="number"&&Number.isFinite(Me))return oe.current=Me,Me}const k=typeof o=="function"?o(re):o,J=Math.max(w.maxScrollPosition,0),Ae=w.scrollBarVisible?de(k,0,J):0;return oe.current=Ae,Ae},[n]),Be=r.useCallback(o=>{const g=G.current,w=oe.current;if(!g.scrollBarVisible||g.maxScrollPosition<=0){const Me=Ye(0,w),Ge=Me-w;return{nextPosition:Me,actualDelta:Ge,reachedBoundary:!0}}if(o===0)return{nextPosition:w,actualDelta:0,reachedBoundary:!1};const k=Ye(Me=>de(Me+o,0,g.maxScrollPosition),w),J=k-w,Ae=J===0||o<0&&k<=0||o>0&&k>=g.maxScrollPosition;return{nextPosition:k,actualDelta:J,reachedBoundary:Ae}},[Ye]),Ee=r.useCallback(()=>{I.current!==null&&(window.cancelAnimationFrame(I.current),I.current=null),L.current=null},[]),he=r.useCallback(()=>{W.current={...ht},Y(!1),Pe.current?.reset(),Ee()},[Ee]),We=r.useCallback(o=>{const g=W.current,w=G.current;if(!g.active||g.direction===0){Ee();return}if(!w.scrollBarVisible||w.maxScrollPosition<=0){Ee();return}const re=L.current??o,k=Math.max((o-re)/1e3,0),J=Math.min(k,$t);if(L.current=o,J<=0){I.current=window.requestAnimationFrame(We);return}const Ae=Math.min(g.distance,w.effectiveTapMaxDistance)/w.effectiveTapMaxDistance,Me=Ae**1.1,Ge=typeof w.tapScrollCircleOptions?.maxSpeedMultiplier=="number",$e=Math.max(w.viewportSize*w.tapCircleMinSpeedMultiplier,40),at=Ge?$e:1200;let lt=Math.max(w.viewportSize*w.tapCircleMaxSpeedMultiplier,at);const et=w.tapCircleMaxSpeedCurve;if(et){const tt=Math.max(et.exponentialSteepness,0),Dt=Math.max(et.exponentialScale??w.tapCircleMaxSpeedMultiplier,0),_t=tt===0?Ae:Math.expm1(tt*Ae),dt=tt===0?1:Math.expm1(tt)||1,Nt=dt===0?Ae:Math.min(Math.max(_t/dt,0),1),Ft=w.viewportSize*Dt*Nt;lt=Math.min(lt,Math.max(Ft,$e))}const yt=Math.max(lt,$e),wt=Math.max(et?.easedOffset??0,0),Rt=Math.min(1,Me+wt),Et=$e+(yt-$e)*Rt,kt=g.direction*Et*J,{actualDelta:At,reachedBoundary:Vt}=Be(kt);if(Vt||At===0){Ee();return}I.current=window.requestAnimationFrame(We)},[Be,Ee]),ze=r.useCallback(()=>{I.current===null&&(L.current=null,I.current=window.requestAnimationFrame(We))},[We]);r.useEffect(()=>()=>{Ee()},[Ee]);const Xe=r.useCallback(o=>{W.current=o,Y(o.active),o.active&&o.direction!==0?ze():Ee()},[ze,Ee]);r.useEffect(()=>{y||he()},[he,y]),r.useEffect(()=>{const o=g=>{const re=g.detail?.paneId;re&&u&&re!==u||he()};return window.addEventListener(ft,o),()=>{window.removeEventListener(ft,o)}},[u,he]),r.useEffect(()=>{if(!y)return;const o=g=>{if(!W.current.active||W.current.pointerId===g.pointerId)return;const w=g.target;if(!(w instanceof Node)){he();return}Pe.current?.getElement()?.contains(w)||he()};return document.addEventListener("pointerdown",o,!0),()=>{document.removeEventListener("pointerdown",o,!0)}},[he,y]);const De=o=>{if(!j||U<=0||q<=0)return 0;const g=de(o,0,U);return de(g/U*q,0,q)},je=o=>{const g=Math.max(Math.round(e/Xt),jt);Be(o*g)},{handleArrowPointerDown:Ne,handleArrowPointerUp:Ue,handleArrowKeyDown:Qe}=Gt({canUseArrowButtons:Oe,enableArrowButtons:f,resetTapScroll:he,scrollByStep:je}),st=o=>{if(!j)return;if(!i){o.preventDefault(),o.stopPropagation();return}if(o.pointerType==="mouse"&&o.button!==0||o.ctrlKey)return;he();const g=o.currentTarget;g.setPointerCapture&&g.setPointerCapture(o.pointerId),E.current={pointerId:o.pointerId,startThumbPosition:we,startClientX:o.clientX,startClientY:o.clientY},B(!0),H(!0),o.preventDefault(),o.stopPropagation()},ot=o=>{const g=E.current;if(g.pointerId!==o.pointerId)return;const w=o.clientX-g.startClientX,re=o.clientY-g.startClientY,k=te(w,re),J=De(g.startThumbPosition+k);Ye(J),o.cancelable&&o.preventDefault()},it=o=>{if(E.current.pointerId!==o.pointerId)return;const g=o.currentTarget;g.hasPointerCapture(o.pointerId)&&g.releasePointerCapture(o.pointerId),E.current={pointerId:null,startThumbPosition:0,startClientX:0,startClientY:0},B(!1),R.current&&!R.current.matches(":hover")&&H(!1),o.preventDefault(),o.stopPropagation()},a=o=>{if(E.current.pointerId!==o.pointerId)return;const g=o.currentTarget;g.hasPointerCapture(o.pointerId)&&g.releasePointerCapture(o.pointerId),E.current={pointerId:null,startThumbPosition:0,startClientX:0,startClientY:0},B(!1),R.current&&!R.current.matches(":hover")&&H(!1)},x=o=>{if(!j)return;if(!l){o.preventDefault(),o.stopPropagation();return}if(o.pointerType==="mouse"&&o.button!==0||o.ctrlKey)return;const g=o.currentTarget,w=g.getBoundingClientRect(),k=ue(o)-(h?w.left:w.top);he();const J=k-se/2,Ae=De(J);Ye(Ae),g.setPointerCapture&&g.setPointerCapture(o.pointerId),F.current={pointerId:o.pointerId,startThumbPosition:J,startClientX:o.clientX,startClientY:o.clientY},o.preventDefault(),o.stopPropagation()},T=o=>{const g=F.current;if(g.pointerId!==o.pointerId)return;const w=o.clientX-g.startClientX,re=o.clientY-g.startClientY,k=te(w,re),J=De(g.startThumbPosition+k);Ye(J),o.cancelable&&o.preventDefault()},D=o=>{if(F.current.pointerId!==o.pointerId)return;const g=o.currentTarget;g.hasPointerCapture(o.pointerId)&&g.releasePointerCapture(o.pointerId),F.current={pointerId:null,startThumbPosition:0,startClientX:0,startClientY:0},o.preventDefault(),o.stopPropagation()},$=o=>{if(F.current.pointerId!==o.pointerId)return;const g=o.currentTarget;g.hasPointerCapture(o.pointerId)&&g.releasePointerCapture(o.pointerId),F.current={pointerId:null,startThumbPosition:0,startClientX:0,startClientY:0}},K=r.useMemo(()=>de((N?1:.8)*V,0,1),[N,V]),ve=r.useMemo(()=>{const g=`calc(50% - ${le/2}px + ${be}px)`;return{left:ce,top:g}},[ce,be,le]),Fe=(o,g,w)=>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:{[Z]:Ce,[ne]:c},"aria-label":g,onMouseDown:Ne(o),onTouchStart:Ne(o),onMouseUp:Ue,onMouseLeave:Ue,onTouchEnd:Ue,onTouchCancel:Ue,onKeyDown:Qe(o),"aria-disabled":!f,disabled:!Oe,children:A.jsx("span",{"aria-hidden":"true",children:w})}),ke=S&&j?{orientation:me,scrollPosition:t,maxScrollPosition:q,contentSize:s,viewportSize:e,thumbSize:se,thumbPosition:we,thumbCenter:Re,trackSize:m,isDragging:O,isTapScrollActive:N,visibleStartIndex:_,visibleEndIndex:X}:null;return A.jsxs("div",{className:Ke.twMerge("group relative cursor-default select-none",Te,d),style:{[Z]:e,[ne]:c,backgroundColor:"white",userSelect:"none",position:"relative",touchAction:"none"},role:"scrollbar",tabIndex:-1,"aria-controls":u,"aria-valuenow":t,"aria-valuemin":0,"aria-valuemax":q,"aria-orientation":h?"horizontal":"vertical",children:[!h&&j&&y&&A.jsx(Tt,{ref:Pe,className:Ke.twMerge("pointer-events-auto absolute transition-opacity duration-150",ee),size:le,maxVisualDistance:ye,style:ve,opacity:K,renderVisual:C,onDragChange:Xe}),Fe(-1,ie[0],Ve[0]),A.jsxs("div",{className:"aqvs:scrollbar-track relative flex-1",style:{borderRadius:c/2,touchAction:"none"},onPointerDown:x,onPointerMove:T,onPointerUp:D,onPointerCancel:$,"aria-disabled":!l,children:[ke&&A.jsx("div",{className:"pointer-events-none absolute inset-0","aria-hidden":!0,children:S?.(ke)}),j&&A.jsx("div",{className:"group absolute",style:{[Z]:se,[xe]:we,...h?{top:0,bottom:0}:{left:0,right:0},touchAction:"none"},onPointerDown:st,onPointerMove:ot,onPointerUp:it,onPointerCancel:a,role:"slider","aria-orientation":h?"horizontal":"vertical","aria-valuenow":t,"aria-valuemin":0,"aria-valuemax":q,"aria-disabled":!i,tabIndex:-1,children:A.jsx("div",{ref:R,className:Ke.twMerge("aqvs:scrollbar-thumb absolute",h?"aqvs:scrollbar-thumb-horizontal":"aqvs:scrollbar-thumb-vertical"),"data-thumb-state":Se,style:{borderRadius:c-1,cursor:i?"pointer":"default"},onMouseEnter:()=>{i&&H(!0)},onMouseLeave:()=>{i&&H(!1)}})})]}),Fe(1,ie[1],Ve[1])]})},fe={debug(s,...e){process.env.NODE_ENV==="___"&&console.debug(`[VirtualScroll] ${s}`,...e)},warn(s,...e){console.warn(`[VirtualScroll] ${s}`,...e)},error(s,...e){console.error(`[VirtualScroll] ${s}`,...e)}},Ze={maxVelocity:6,minVelocity:.02,deceleration:.0025,velocitySampleWindow:90,startVelocityThreshold:.04},rt=(s,e,t)=>{for(const[n,i,l]of e)t==="add"?s.addEventListener(n,i,l):s.removeEventListener(n,i,l)},St=r.forwardRef(({children:s,contentSize:e,viewportSize:t,scrollBarWidth:n=12,enableThumbDrag:i=!0,enableTrackClick:l=!0,enableArrowButtons:f=!0,enablePointerDrag:h=!0,onScroll:c,className:d,style:u,background:p,tapScrollCircleOptions:v,inertiaOptions:S,itemCount:_,renderThumbOverlay:X,wheelSpeedMultiplier:O=1,contentInsets:B,visibleStartIndex:ge,visibleEndIndex:H,renderOverlay:N},Y)=>{const R=r.useRef(0),E=r.useRef(null),F=r.useRef(null),oe=r.useRef({frame:null,velocity:0,lastTimestamp:null}),W=r.useMemo(()=>({maxVelocity:S?.maxVelocity??Ze.maxVelocity,minVelocity:S?.minVelocity??Ze.minVelocity,deceleration:S?.deceleration??Ze.deceleration,velocitySampleWindow:S?.velocitySampleWindow??Ze.velocitySampleWindow,startVelocityThreshold:S?.startVelocityThreshold??Ze.startVelocityThreshold}),[S]),Pe=r.useMemo(()=>({top:Math.max(0,B?.top??0),bottom:Math.max(0,B?.bottom??0)}),[B]);fe.debug("[ScrollPane] ScrollPane rendered",{contentSize:e,viewportSize:t,scrollBarWidth:n,className:d,style:u,tapScrollCircleOptions:v,inertiaOptions:S,enablePointerDrag:h,contentInsets:Pe});const I=r.useRef({contentSize:e,viewportSize:t}),L=r.useMemo(()=>e>t,[e,t]),b=r.useCallback(C=>{const{contentSize:M,viewportSize:G}=I.current,Z=M>G,ne=R.current;if(fe.debug("[ScrollPane] scrollTo called",{newPosition:C,contentSize:M,viewportSize:G,currentIsScrollable:Z,prevPosition:ne}),!Z)return R.current!==0&&(R.current=0,c?.(0,ne)),R.current;const xe=typeof C=="function"?C(R.current):C,te=Math.max(M-G,0),ue=de(xe,0,te);return R.current!==ue&&(R.current=ue,c?.(ue,ne)),R.current},[c]),Q=r.useCallback(()=>{const C=oe.current;C.frame!==null&&cancelAnimationFrame(C.frame),C.frame=null,C.velocity=0,C.lastTimestamp=null},[]),y=r.useRef(Q);r.useEffect(()=>{y.current=Q},[Q]);const le=r.useCallback(C=>{if(!L)return;const{maxVelocity:M,minVelocity:G,deceleration:Z,startVelocityThreshold:ne}=W,xe=de(C,-M,M);if(Math.abs(xe)<ne)return;Q(),oe.current.velocity=xe,oe.current.lastTimestamp=null;const te=ue=>{const ie=oe.current;if(ie.lastTimestamp===null){ie.lastTimestamp=ue,ie.frame=requestAnimationFrame(te);return}const Ve=ue-ie.lastTimestamp;if(ie.lastTimestamp=ue,Ve<=0){ie.frame=requestAnimationFrame(te);return}const Te=ie.velocity;let me=Te;const ye=Z*Ve;Te>0?me=Math.max(0,Te-ye):Te<0&&(me=Math.min(0,Te+ye));const Ce=(Te+me)/2*Ve,m=R.current;Ce!==0&&b(Re=>Re+Ce);const P=R.current,{contentSize:se,viewportSize:q}=I.current,U=Math.max(se-q,0);ie.velocity=me;const we=P===m||P<=0&&me<=0||P>=U&&me>=0;if(Math.abs(me)<G||we){Q();return}ie.frame=requestAnimationFrame(te)};oe.current.frame=requestAnimationFrame(te)},[L,W,b,Q]),ce=r.useRef(le);r.useEffect(()=>{ce.current=le},[le]),r.useLayoutEffect(()=>{I.current={contentSize:e,viewportSize:t}},[e,t]),r.useLayoutEffect(()=>{const C=F.current;if(!C)return;const M=()=>{C.scrollTop!==0&&(fe.debug("[ScrollPane] Native scroll detected, resetting to 0",{scrollTop:C.scrollTop}),C.scrollTop=0),C.scrollLeft!==0&&(C.scrollLeft=0)};return C.addEventListener("scroll",M),()=>C.removeEventListener("scroll",M)},[]),r.useLayoutEffect(()=>{if(L){fe.debug("[ScrollPane] Adjusting scroll position due to content or viewport size change",{contentSize:e,viewportSize:t,scrollPosition:R.current});const C=de(e-t,0,e);R.current>C&&b(C)}else b(0)},[L,b,e,t]),r.useEffect(()=>{const C=G=>{if(!L)return;G.preventDefault(),Q();let Z=G.deltaY;G.deltaMode===1?Z*=16:G.deltaMode===2&&(Z*=t),O!==1&&(Z*=O),fe.debug("[ScrollPane] wheel event",{deltaY:Z,scrollPosition:R.current,wheelSpeedMultiplier:O,deltaMode:G.deltaMode,scrollTop:F.current?.scrollTop}),b(ne=>ne+Z)},M=E.current;return M&&M.addEventListener("wheel",C,{passive:!1}),()=>{M&&M.removeEventListener("wheel",C)}},[L,b,Q,t,O]),r.useImperativeHandle(Y,()=>({scrollTo:C=>(Q(),b(C)),getScrollPosition:()=>R.current,getContentSize:()=>e,getViewportSize:()=>t}),[b,e,t,Q]);const be=r.useRef(b);r.useEffect(()=>{be.current=b},[b]);const ee=r.useId(),z=r.useRef({pointerId:null,startClientY:0,startScroll:0,isDragging:!1,shouldCancelNextClick:!1,clickResetTimer:null,velocitySamples:[]}),pe=r.useRef(h);r.useEffect(()=>{pe.current=h},[h]);const Ie=r.useRef(L);r.useEffect(()=>{Ie.current=L},[L]);const V=r.useRef(W);return r.useEffect(()=>{V.current=W},[W]),r.useEffect(()=>{if(h)return;const C=F.current,M=z.current;M.pointerId!==null&&C&&C.hasPointerCapture(M.pointerId)&&C.releasePointerCapture(M.pointerId),M.clickResetTimer!==null&&(window.clearTimeout(M.clickResetTimer),M.clickResetTimer=null),M.pointerId=null,M.startClientY=0,M.startScroll=0,M.isDragging=!1,M.shouldCancelNextClick=!1,M.velocitySamples=[]},[h]),r.useEffect(()=>{const C=F.current;if(!C)return;const M=6,G=()=>typeof performance<"u"&&typeof performance.now=="function"?performance.now():Date.now(),Z=()=>{const m=z.current;m.pointerId=null,m.startClientY=0,m.startScroll=0,m.isDragging=!1,m.velocitySamples=[]},ne=()=>{const m=z.current;m.clickResetTimer!==null&&(window.clearTimeout(m.clickResetTimer),m.clickResetTimer=null)},xe=m=>{const P=z.current,se=G();P.velocitySamples.push({clientY:m,time:se});const q=V.current.velocitySampleWindow;P.velocitySamples=P.velocitySamples.filter(U=>se-U.time<=q)},te=m=>m instanceof HTMLElement&&m.closest("[data-scrollpane-ignore-drag='true']")!==null,ue=m=>{const P=z.current;P.shouldCancelNextClick&&(m.preventDefault(),m.stopPropagation(),P.shouldCancelNextClick=!1)},ie=m=>{const P=z.current;P.isDragging||(P.isDragging=!0,P.shouldCancelNextClick=!0,C.hasPointerCapture(m.pointerId)||C.setPointerCapture(m.pointerId),xe(m.clientY))},Ve=m=>{const P=z.current;if(P.pointerId!==m.pointerId||!(pe.current&&Ie.current)||!P.isDragging&&(Math.abs(m.clientY-P.startClientY)<M||(ie(m),!P.isDragging)))return;xe(m.clientY);const se=m.clientY-P.startClientY,q=P.startScroll-se;be.current(q),m.cancelable&&m.preventDefault()},Te=m=>{const P=z.current;if(P.pointerId!==m.pointerId)return;P.isDragging&&P.shouldCancelNextClick&&m.cancelable&&(m.preventDefault(),m.stopPropagation()),C.hasPointerCapture(m.pointerId)&&C.releasePointerCapture(m.pointerId);let se=0;if(P.isDragging&&P.velocitySamples.length>=2){const U=P.velocitySamples,we=V.current.velocitySampleWindow,Re=U[U.length-1],j=U.find(Oe=>Re.time-Oe.time<=we)??U[0];if(Re&&j&&Re.time!==j.time){const Oe=Re.clientY-j.clientY,Se=Re.time-j.time;se=-(Oe/Se)}}ne(),P.shouldCancelNextClick&&(P.clickResetTimer=window.setTimeout(()=>{const U=z.current;U.shouldCancelNextClick=!1,U.clickResetTimer=null},0));const q=V.current.startVelocityThreshold;Z(),Math.abs(se)>=q&&ce.current?.(se)},me=m=>{if(!(pe.current&&Ie.current)||m.button!==0&&m.pointerType==="mouse"||m.ctrlKey||m.metaKey||m.altKey||te(m.target))return;window.dispatchEvent(new CustomEvent(ft,{detail:{paneId:ee}})),y.current?.();const P=z.current;ne(),P.pointerId=m.pointerId,P.startClientY=m.clientY,P.startScroll=R.current,P.isDragging=!1,P.shouldCancelNextClick=!1,P.velocitySamples=[]},ye=m=>{const P=z.current;P.pointerId===m.pointerId&&(P.shouldCancelNextClick=!1,C.hasPointerCapture(m.pointerId)&&C.releasePointerCapture(m.pointerId),ne(),Z())},_e=[["click",ue,!0],["pointerdown",me,{passive:!1}],["pointermove",Ve,{passive:!1}],["pointerup",Te,void 0],["pointercancel",ye,void 0]],Ce=[["pointermove",Ve,{passive:!1}],["pointerup",Te,void 0],["pointercancel",ye,void 0]];return rt(C,_e,"add"),rt(window,Ce,"add"),()=>{rt(C,_e,"remove"),rt(window,Ce,"remove");const m=z.current;m.pointerId!==null&&C.hasPointerCapture(m.pointerId)&&C.releasePointerCapture(m.pointerId),ne(),Z()}},[ee]),A.jsxs("div",{ref:E,className:Ke.twMerge("relative flex",d),style:u,children:[A.jsxs("div",{ref:F,className:Ke.twMerge("relative h-full flex-1 overflow-hidden"),style:{height:t,paddingTop:Pe.top,paddingBottom:Pe.bottom,...h?{touchAction:"none"}:{}},id:ee,children:[p,s(R.current)]}),L&&A.jsx(Ct,{contentSize:e,viewportSize:t,scrollPosition:R.current,onScroll:b,enableThumbDrag:i,enableTrackClick:l,enableArrowButtons:f,scrollBarWidth:n,ariaControls:ee,tapScrollCircleOptions:v,itemCount:_,renderThumbOverlay:X,visibleStartIndex:ge,visibleEndIndex:H}),N?.()]})}),gt=(s,e,t)=>Math.min(Math.max(s,e),t),Jt=({dragState:s,normalizedDistance:e,sizeScale:t,size:n})=>{const i=Math.max(n/2,1),l=1+e*.65,f=Math.max(.65,1-e*.25),h=s.direction*e*26*t,c=.8+e*.18,d=3*t,u=6*t,p=22*t,v=Math.abs(h)+u,S=h>0?d:-Math.abs(h)-d,_=Math.max(2.5,3*t),X=gt(s.offsetX,-i,i),O=gt(s.offsetY,-i,i),B=i*.35,ge=X/i*B,H=O/i*B,N=ge*.45,Y=H*.45,R=Math.max(p*.38,6),E=.65+e*.2,F=s.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}, ${l})`,transition:F?"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:p,height:p,transform:`translate(calc(-50% + ${ge}px), calc(-50% + ${H}px)) scale(${f}, ${c*l})`,transition:F?"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:R,height:R,transform:`translate(calc(-50% + ${N}px), calc(-50% + ${Y}px)) scale(${f}, ${l})`,opacity:E,boxShadow:"0 0 8px rgba(255,255,255,0.45)",transition:F?"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:_,height:v,transform:`translate(-50%, ${S}px)`,opacity:e,transition:F?"40ms height, 60ms opacity ease-out ease-out":"200ms ease height, 120ms ease opacity"}})]})},Qt=s=>{if(!Number.isFinite(s))return 0n;const e=Math.trunc(s);return e<=0?0n:BigInt(e)},nt=s=>{if(s<=0||!Number.isFinite(s))return 0;const e=Math.trunc(s),t=BigInt(e)&-BigInt(e);return Number(t)};class vt{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 l=n?.sampleRange??{from:0,to:Math.min(99,this.size-1)},{mode:f,materializedValues:h}=this._calculateMode(l.from,l.to);if(this.baseValue=f,n?.materialize)for(let c=0;c<h.length;c++){const d=h[c],u=l.from+c;if(u>=this.size)break;const p=d-this.baseValue;this.deltas.set(u,p),this._updateTree(u,p)}}else this.baseValue=0;this.total=this.getTotal()}else this.valueFn=void 0,this.baseValue=t,this.total=this.baseValue*this.size}setValueFn(e){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 d=e;d<=t&&!(d>=this.size);d++)n.push(this.valueFn(d));const i=[...n];if(n.length===0)return{mode:0,materializedValues:[]};n.sort((d,u)=>d-u);const l=Math.floor(n.length/2);let f;n.length%2===0?f=Math.floor((n[l-1]+n[l])/2):f=n[l];const h=new Map;let c=0;for(const d of n){const u=(h.get(d)??0)+1;h.set(d,u),u>c&&(c=u)}if(c>n.length*.2){const d=[];for(const[p,v]of h.entries())v===c&&d.push(p);const u=d.reduce((p,v)=>p+v,0);f=Math.floor(u/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:n}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+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 i=nt(n);if(i===0)break;n+=i}this.total!==void 0&&(this.total+=t)}_buildDeltaUpdates(e){const t=[];for(const{index:n,value:i}of e){if(n<0||n>=this.size)throw new Error(`Index ${n} out of bounds`);if(i<0)throw new Error("Value cannot be negative.");const l=this.deltas.has(n)?(this.deltas.get(n)??0)+this.baseValue:this.baseValue,f=i-l;f!==0&&t.push({index:n,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 n=nt(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,l=this.valueFn(e)-this.baseValue;if(l!==n&&(this.deltas.set(e,l),t)){const f=l-n;this._updateTree(e,f)}}}_materializeRanges(e,t,n=!1){if(!(e?.materialize&&this.valueFn))return;const i=e.ranges;if(i&&i.length>0){for(const h of i){const c=h.from,d=Math.min(h.to,this.size-1);for(let u=c;u<=d;u++)this._materialize(u)}if(t===void 0)return;if(n){this._materialize(t);return}const l=i[0].from,f=i[i.length-1].to;t>=l&&t<=f&&this._materialize(t);return}t!==void 0&&this._materialize(t)}_findIndex(e,t={},n){if(this.size>=Number.MAX_SAFE_INTEGER)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 i=0,l=this.size-1,f=-1,h,c,d=this.total;for(;i<=l;){const p=Math.floor((i+l)/2);h=this.prefixSum(p,t),d=h.total,(n?h.cumulative>=e:h.cumulative<=e)?(f=p,c=h,n?l=p-1:i=p+1):n?i=p+1:l=p-1}const u=c??h;return{index:f,total:d,cumulative:u?.cumulative,currentValue:u?.currentValue,safeIndex:u?.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 i=Qt(this.size);if(i===0n)return{index:-1,total:this.total??0,cumulative:void 0,currentValue:void 0,safeIndex:void 0};let l=0n,f=i-1n,h,c,d,u=this.total;for(;l<=f;){const S=l+f>>1n,_=Number(S),X=this.prefixSum(_,t);if(d=X,u=X.total,n?X.cumulative>=e:X.cumulative<=e)if(h=S,c=X,n){if(S===0n)break;f=S-1n}else l=S+1n;else if(n)l=S+1n;else{if(S===0n)break;f=S-1n}}const p=c??d;return{index:h!==void 0?Number(h):-1,total:u,cumulative:p?.cumulative,currentValue:p?.currentValue,safeIndex:p?.safeIndex}}prefixSum(e,t){if(e<0)return{cumulative:0,total:this.total,currentValue:0,safeIndex:0};const n=de(e,0,this.size-1),i=t?.materializeOption;this._materializeRanges(i,n,!0);let l=0,f=n+1;for(;f>0;){const c=this.tree.get(f)??0;l+=c;const d=nt(f);if(d===0)break;f-=d}const h=i?.materialize?this.get(n):(this.deltas.get(n)||0)+this.baseValue;return{cumulative:l+this.baseValue*(n+1),total:this.total,currentValue:h,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);console.assert(n.cumulative===n.total,"Inconsistent Fenwick Tree state")}return this.total}rebuildTree(e){if(e?.materialize&&this.valueFn){const n=this.valueFn;this.reset(this.size,i=>n(i),{materialize:!0});return}const t=new Map;for(const[n,i]of this.deltas.entries()){if(i===0)continue;let l=n+1;for(;l<=this.size;){t.set(l,(t.get(l)??0)+i);const f=nt(l);if(f===0)break;l+=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 n=this.prefixSum(this.getSize()-1);console.assert(n.cumulative===n.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 Mt=(s,e,t)=>{const n=Math.max(0,s),i=r.useRef(null),l=r.useMemo(()=>new vt(n,e,t),[n,e,t]);return Object.is(i.current,l)||console.warn("[useFenwickMapTree] instance changed"),i.current=l,l};class er{key;value;prev=null;next=null;constructor(e,t){this.key=e,this.value=t}}class xt{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(s){const e=r.useRef(new Map),t=r.useRef(new xt);r.useEffect(()=>{for(;e.current.size>s;){const u=t.current.removeHead();if(u)e.current.delete(u.key);else break}},[s]);const n=r.useCallback(u=>{const p=e.current.get(u);if(p)return t.current.moveToTail(p),p.value},[]),i=r.useCallback((u,p)=>{if(s<=0)return;let v=e.current.get(u);if(v)v.value=p,t.current.moveToTail(v);else{if(e.current.size>=s){const S=t.current.removeHead();S&&e.current.delete(S.key)}v=new er(u,p),e.current.set(u,v),t.current.addToTail(v)}},[s]),l=r.useCallback(u=>e.current.has(u),[]),f=r.useCallback(u=>{const p=e.current.get(u);p&&(t.current.remove(p),e.current.delete(u))},[]),h=r.useCallback(()=>{e.current.clear(),t.current=new xt},[]),[c,d]=r.useState(()=>({get:n,set:i,has:l,remove:f,clear:h}));return r.useEffect(()=>d({get:n,set:i,has:l,remove:f,clear:h}),[n,i,l,f,h]),c}const tr=1e4,rr=()=>{const{get:s,set:e,has:t,clear:n}=Pt(tr);return{get:s,set:e,has:t,clear:n}},ae=(s,e)=>e<=0?0:de(s,0,e-1),nr=s=>({top:Math.max(0,s?.top??0),bottom:Math.max(0,s?.bottom??0)}),qe=(s,e)=>s<=e?0:s-e,Je=(s,e)=>s<=0?e:s+e,bt=s=>{if(!Number.isFinite(s))return 0n;const e=Math.trunc(s);return e<=0?0n:BigInt(e)},sr=(s,e,t,n,i,l,f,h)=>{const c=bt(n);if(c===0n)return{renderingStartIndex:0,renderingEndIndex:0,visibleStartIndex:0,visibleEndIndex:0};const d=N=>N<0n?0n:N>=c?c-1n:N,u={materializeOption:{materialize:!1}},{index:p}=l.findIndexAtOrAfter(s,u);let v;p===-1?v=c-1n:(v=bt(p),v>=c&&(v=c-1n)),s<=0&&(v=0n),h&&s>=f&&(v=c-1n);const S=N=>{let Y=0,R=N,E=N,F=0n;for(;R<c&&Y<e;){const oe=Number(R),W=i(oe);if(Y+=W,E=R,R+=1n,F+=1n,!Number.isFinite(W)||W<=0)break}return F===0n&&(E=N),{height:Y,end:E}};let{height:_,end:X}=S(v);if(_<e&&v>0n){let N=v,Y=_;for(;N>0n&&Y<e;){N-=1n;const E=Number(N),F=i(E);if(Y+=F,!Number.isFinite(F)||F<=0)break}v=d(N);const R=S(v);_=R.height,X=R.end}const O=d(v),B=d(X),ge=d(O-BigInt(Math.max(0,t))),H=d(B+BigInt(Math.max(0,t)));return{renderingStartIndex:ae(Number(ge),n),renderingEndIndex:ae(Number(H),n),visibleStartIndex:ae(Number(O),n),visibleEndIndex:ae(Number(B),n)}},or=(s,e,t,n,i,l,f)=>{if(n===0)return{renderingStartIndex:0,renderingEndIndex:0,visibleStartIndex:0,visibleEndIndex:0};const h=Number.isFinite(f),c=h?Math.min(Math.max(0,s),f):Math.max(0,s);if(n>=Number.MAX_SAFE_INTEGER)return sr(c,e,t,n,i,l,f,h);const{index:d,cumulative:u,currentValue:p}=l.findIndexAtOrAfter(c,{materializeOption:{materialize:!1}}),v=d===-1?e<=0||(u??0)<c+(p??0)?n-1:0:d;let S=ae(v,n),_=0;if(S===d&&u!==void 0&&p!==void 0)_=u-p-c;else{const{cumulative:N,currentValue:Y}=l.prefixSum(S,{materializeOption:{materialize:!1}});_=(N??0)-(Y??0)-c}const X=_;let O=S;for(;O<n&&_<e;)_+=i(O),O++;if(_<e&&S>0){let N=_+Math.abs(Math.min(0,X)),Y=S-1;for(;Y>=0&&N<e;)N+=i(Y),Y--;for(S=ae(Y+1,n),_=0,O=S;O<n&&_<e;)_+=i(O),O++}const B=ae(S-t,n),ge=ae(Math.max(O-1,S),n),H=ae(ge+t,n);return{renderingStartIndex:B,renderingEndIndex:H,visibleStartIndex:S,visibleEndIndex:ge}},ir=()=>typeof performance<"u"&&typeof performance.now=="function"?performance.now():Date.now(),It=(s,e,t)=>{const n=Math.max(0,e??0),i=r.useRef({lastInvokeAt:0,rafId:null,pendingPayload:null,loopActive:!1,normalizedThrottle:n}),l=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 u=typeof c=="number"?c:ir(),p=d.normalizedThrottle,v=d.pendingPayload,S=s.current;if(v!==null&&S){const _=u-d.lastInvokeAt;(p===0||d.lastInvokeAt===0||_>=p)&&(d.pendingPayload=null,d.lastInvokeAt=u,t(S,v))}if(d.pendingPayload!==null){typeof requestAnimationFrame=="function"?d.rafId=requestAnimationFrame(f):d.loopActive=!1;return}d.loopActive=!1},[s,t]),h=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(()=>()=>{l(),i.current.pendingPayload=null},[l]),r.useEffect(()=>{l();const c=i.current;c.lastInvokeAt=0,c.pendingPayload=null,c.normalizedThrottle=n},[n,l]),r.useCallback(c=>{const d=i.current;d.pendingPayload=c,h()},[h])},ar=({itemCount:s,getItem:e,getItemHeight:t,viewportSize:n,overscanCount:i=15,className:l,onScroll:f,onRangeChange:h,children:c,background:d,initialScrollIndex:u,initialScrollOffset:p,tapScrollCircleOptions:v,scrollBarWidth:S,enableThumbDrag:_,enableTrackClick:X,enableArrowButtons:O,enablePointerDrag:B,inertiaOptions:ge,callbackThrottleMs:H=5,renderThumbOverlay:N,wheelSpeedMultiplier:Y,contentInsets:R,enableKeyboardNavigation:E=!0,onItemFocus:F,clipItemHeight:oe=!1,enableScrollToTopBottomButtons:W},Pe)=>{const I=r.useRef(null),L=r.useRef(!1),b=r.useMemo(()=>nr(R),[R]),Q=r.useRef({size:s,valueOrFn:t,options:{sampleRange:{from:0,to:100}}}),y=Mt(Q.current.size,Q.current.valueOrFn,Q.current.options),[le]=r.useState(()=>{let a=b.top,x=0;if(typeof u=="number"){const T=de(u,0,s-1),D=de(T-i*2,0,s-1),$=de(T+i*2,0,s-1),K=u>0?{materializeOption:{materialize:!0,ranges:[{from:D,to:$}]}}:void 0,{cumulative:ve,total:Fe,currentValue:ke}=y.prefixSum(u,K),o=Math.max(ve-ke,0);a=Je(o,b.top),x=Fe??y.getTotal()}else typeof p=="number"&&(a=Je(Math.max(p,0),b.top)),x=y.getTotal();return{position:a,total:x}}),[ce,be]=r.useState(le.position),[ee,z]=r.useState(le.total),[pe,Ie]=r.useState(le.position),[V,C]=r.useState(s),M=r.useRef(le.position),G=r.useRef(b.top),Z=r.useRef(f??void 0),ne=r.useRef(h??void 0),xe=r.useRef(new Map),te=r.useRef(null),ue=r.useRef(null),[ie,Ve]=r.useState(null),[Te,me]=r.useState(!1),ye=r.useRef(null),_e=r.useRef(!1);r.useEffect(()=>{Z.current=f??void 0,ne.current=h??void 0},[h,f]);const Ce=r.useCallback(a=>{if(E&&a&&typeof a.focus=="function")try{a.focus({preventScroll:!0})}catch{a.focus()}},[E]),m=It(Z,H,(a,{position:x,totalHeight:T})=>{a(x,T)}),P=It(ne,H,(a,{renderingStartIndex:x,renderingEndIndex:T,visibleStartIndex:D,visibleEndIndex:$,scrollPosition:K,totalHeight:ve})=>{a(x,T,D,$,K,ve)});r.useEffect(()=>(L.current=!0,()=>{L.current=!1}),[]),r.useEffect(()=>{E||(xe.current.clear(),te.current=null,ue.current=null)},[E]);const se=.01,q=r.useRef({rafId:null,loopActive:!1,idleFrames:0,lastRenderedPosition:le.position}),U=r.useCallback(()=>{const a=q.current;a.rafId!==null&&typeof cancelAnimationFrame=="function"&&cancelAnimationFrame(a.rafId),a.rafId=null,a.loopActive=!1,a.idleFrames=0},[]);r.useEffect(()=>()=>{U()},[U]);const we=r.useCallback(()=>{const a=q.current;a.rafId=null;const x=M.current,T=qe(x,b.top),D=y.getTotal();if(be(K=>Math.abs(K-x)<se?K:x),m({position:T,totalHeight:D}),Math.abs(a.lastRenderedPosition-x)>=se?(a.lastRenderedPosition=x,a.idleFrames=0):a.idleFrames+=1,a.idleFrames>=2){U();return}if(typeof requestAnimationFrame=="function"){a.rafId=requestAnimationFrame(we);return}a.loopActive=!1},[y,b.top,m,U]),Re=r.useCallback(()=>{const a=q.current;if(a.idleFrames=0,!a.loopActive){if(a.loopActive=!0,typeof requestAnimationFrame=="function"){a.rafId=requestAnimationFrame(we);return}a.loopActive=!1}},[we]),j=r.useCallback((a,x)=>{const T=x?.immediate??!1,D=qe(a,b.top);if(M.current=a,T){q.current.lastRenderedPosition=a,q.current.idleFrames=0,be(a),m({position:D,totalHeight:y.getTotal()});return}Re()},[Re,y,b.top,m]),Oe=r.useRef(!1);r.useEffect(()=>{if(!Oe.current)if(Oe.current=!0,typeof p=="number"){const a=Je(Math.max(p,0),b.top),x=Math.abs(a-M.current)>.5;j(a,{immediate:!0}),x&&Ie(a)}else j(M.current,{immediate:!0})},[p,b.top,j]),r.useLayoutEffect(()=>{y.setValueFn(t),V!==s&&(y.changeSize(s),C(s));const a=y.getTotal();ee!==a&&z(a)},[y,V,s,ee,t]),r.useLayoutEffect(()=>{pe!==null&&I.current&&(fe.debug("[VirtualScroll] Scrolling to position:",pe),I.current.scrollTo(pe),Ie(null))},[pe]),r.useEffect(()=>{const a=G.current;if(a===b.top)return;const x=qe(M.current,a),T=Je(x,b.top);G.current=b.top,M.current=T,Ie(T),j(T,{immediate:!0})},[b.top,j]);const Se=r.useCallback(a=>{if(!I.current)return;const x=ae(a,V),T=ae(x-i*2,V),D=ae(x+i*2,V),{cumulative:$,total:K,currentValue:ve}=y.prefixSum(x,{materializeOption:{materialize:!0,ranges:[{from:T,to:D}]}});if(fe.debug("[VirtualScroll] Scrolling to index:",x,"Offset:",$,"Total height:",K,"Current value:",ve,"safeIndexFrom:",T,"safeIndexTo:",D),!K)return;const Fe=Math.max($-ve,0),ke=Je(Fe,b.top);z(K),Ie(ke),fe.debug("[VirtualScroll] Setting scroll position to:",ke)},[y,i,V,b.top]),Ye=r.useCallback(a=>{if(!I.current)return;const x=y.getTotal(),T=de(Math.floor(a),0,x),D=y.findIndexAtOrAfter(T,{materializeOption:{materialize:!1}}).index;Se(D)},[y,Se]),Be=r.useCallback(a=>{const x=qe(M.current,b.top),T=typeof a=="function"?a(x):a;Ye(T);const D=I.current?.getScrollPosition(),$=typeof D=="number"?D:M.current;return j($),$},[b.top,Ye,j]),Ee=r.useCallback((a,x)=>{if(fe.debug("[VirtualScroll] Scroll position changed:",a),j(a),W){if(_e.current){_e.current=!1;return}const T=a-x;if(fe.debug("[VirtualScroll] Scroll diff:",T,"New:",a,"Prev:",x),Math.abs(T)>1){const D=T>0?"down":"up";Ve(D),me(!0),fe.debug("[VirtualScroll] Showing scroll buttons. Direction:",D),ye.current&&clearTimeout(ye.current),ye.current=setTimeout(()=>{me(!1),fe.debug("[VirtualScroll] Hiding scroll buttons")},2e3)}}},[j,W]),he=r.useMemo(()=>qe(ce,b.top),[b.top,ce]),We=r.useMemo(()=>{const a=or(he,n,i,V,t,y,ee);return fe.debug("[VirtualScroll] Calculated rendering range:",{...a,scrollPosition:he,renderingContentSize:y.getTotal(),overscanCount:i,viewportSize:n}),a},[he,n,i,V,t,y,ee]),{renderingStartIndex:ze,renderingEndIndex:Xe,visibleStartIndex:De,visibleEndIndex:je}=We,Ne=r.useCallback((a,x)=>{if(!E||V===0)return;const T=ae(a,V);if(!(x?.ensureVisible??!0)){const re=xe.current.get(T);re&&(te.current=null,ue.current=T,Ce(re));return}const $=y.prefixSum(T,{materializeOption:{materialize:!1}}),K=$.currentValue,ve=Math.max($.cumulative-K,0),Fe=ve+K,ke=qe(M.current,b.top),o=ke+n;if(ve<ke||Fe>o){te.current=T,Se(T);return}const w=xe.current.get(T);if(w){te.current=null,ue.current=T,Ce(w);return}te.current=T},[E,V,y,b.top,Se,Ce,n]),Ue=r.useCallback((a,x)=>{if(!E||a.defaultPrevented||a.altKey||a.metaKey||a.ctrlKey)return;const T=a.target;if(T){const D=T.tagName;if(D==="INPUT"||D==="TEXTAREA"||D==="SELECT"||T.isContentEditable)return}if(a.key==="ArrowDown"){x<V-1&&(a.preventDefault(),Ne(x+1));return}if(a.key==="ArrowUp"){x>0&&(a.preventDefault(),Ne(x-1));return}if(a.key==="PageDown"){if(x<V-1){a.preventDefault();const D=Math.max(je-De+1,1),$=Math.max(D,1),K=ae(Math.min(x+$,V-1),V);Ne(K)}return}if(a.key==="PageUp"&&x>0){a.preventDefault();const D=Math.max(je-De+1,1),$=Math.max(D,1),K=ae(x-$,V);Ne(K)}},[E,V,Ne,je,De]),Qe=r.useCallback(a=>{if(!E)return;const x=ae(a,V);te.current=null,ue.current=x,F?.(x)},[E,V,F]);r.useEffect(()=>{const a=I.current?.getScrollPosition()??0,x=M.current,T=qe(x,b.top);fe.debug("[VirtualScroll] Range change effect triggered",{renderingStartIndex:ze,renderingEndIndex:Xe,visibleStartIndex:De,visibleEndIndex:je,scrollPositionState:ce,paneScrollPosition:x,logicalScrollPosition:T,contentSize:ee,scrollPaneScrollPosition:a}),P({renderingStartIndex:ze,renderingEndIndex:Xe,visibleStartIndex:De,visibleEndIndex:je,scrollPosition:T,totalHeight:ee})},[ee,Xe,ze,b.top,P,ce,je,De]);const st=r.useCallback(()=>{if(!W)return null;const a=Te&&ie!==null,x=ie==="up";return A.jsx("div",{className:`pointer-events-none absolute inset-0 transition-opacity duration-500 ${a?"opacity-100":"opacity-0"}`,style:{zIndex:10},children:x?A.jsx("div",{className:"absolute top-2 right-0 left-0 flex justify-center",children:A.jsx("button",{type:"button",className:"pointer-events-auto transform rounded-full bg-gray-800/80 px-12 py-1 font-medium text-[10px] text-white uppercase tracking-wider shadow-md backdrop-blur-sm transition-transform hover:bg-gray-700 active:scale-95",onClick:T=>{T.stopPropagation(),_e.current=!0,Se(0),me(!1)},children:"Top"})}):A.jsx("div",{className:"absolute right-0 bottom-2 left-0 flex justify-center",children:A.jsx("button",{type:"button",className:"pointer-events-auto transform rounded-full bg-gray-800/80 px-12 py-1 font-medium text-[10px] text-white uppercase tracking-wider shadow-md backdrop-blur-sm transition-transform hover:bg-gray-700 active:scale-95",onClick:T=>{T.stopPropagation(),_e.current=!0,Se(s-1),me(!1)},children:"Bottom"})})})},[W,Te,ie,Se,s]),ot=r.useCallback(a=>{const x=(H??0)>0,T=Math.abs(a-ce),D=x&&T>.5?ce:a,$=qe(D,b.top);if(fe.debug("[VirtualScroll] Rendering visible items",{currentScrollPosition:a,effectiveScrollPosition:$,renderingStartIndex:ze,renderingEndIndex:Xe,fenwickSize:V,viewportSize:n,callbackThrottleMs:H,diff:T,rawEffectiveScrollPosition:D}),V===0)return A.jsx("div",{className:"absolute w-full",style:{top:0},children:A.jsx("div",{className:"text-center text-gray-500",children:"No items"})});const K=ae(ze,V),ve=ae(Xe,V),{cumulative:Fe,currentValue:ke}=y.prefixSum(K,{materializeOption:{materialize:!1}}),o=Fe-ke,g=[],w=[];for(let k=K;k<=ve;k++){const J=t(k);y.get(k)!==J&&g.push({index:k,value:J});const{cumulative:Me,currentValue:Ge}=y.prefixSum(k,{materializeOption:{materialize:!1}}),$e=Me-Ge,at=He=>{if(!He){xe.current.delete(k);return}E&&(xe.current.set(k,He),te.current===k&&(te.current=null,ue.current=k,Ce(He)))};w.push(A.jsx("div",{ref:at,"data-index":k,"data-virtualscroll-item":"true",style:{position:"absolute",top:$e-o+b.top,width:"100%",height:J,overflow:oe?"hidden":void 0},tabIndex:E?-1:void 0,onPointerDown:E?He=>{He.currentTarget.focus({preventScroll:!0})}:void 0,onKeyDownCapture:E?He=>Ue(He,k):void 0,onFocusCapture:E?()=>Qe(k):void 0,children:c(e(k),k)},k))}g.length>0&&Promise.resolve().then(()=>{if(!L.current)return;const k=y.updates(g);if(!L.current||typeof k!="number")return;z(k),fe.debug("[VirtualScroll] Updated heights for items",g,"New total height:",k);const J=I.current?.getScrollPosition()??M.current;J===M.current||!L.current||j(J)});const re=o-$;if(b.bottom>0){const k=y.getTotal()+b.top-o;w.push(A.jsx("div",{style:{position:"absolute",top:k,height:b.bottom,width:"100%"}},"virtualscroll-bottom-inset"))}return fe.debug("[VirtualScroll] Rendering items",{nodeCount:w.length,containerTop:re,logicalScrollPosition:he,resolvedInsets:b,effectiveScrollPosition:$}),A.jsx("div",{className:"absolute w-full",style:{top:re},children:w})},[H,c,E,y,V,e,t,Qe,Ue,he,Xe,ze,b,ce,Ce,j,n,oe]);r.useImperativeHandle(Pe,()=>({getScrollPosition:()=>I.current?.getScrollPosition()??-1,getContentSize:()=>I.current?.getContentSize()??-1,getViewportSize:()=>I.current?.getViewportSize()??-1,scrollTo:Be,scrollToIndex:Se,getFenwickTreeTotalHeight:()=>y.getTotal(),getFenwickSize:()=>y.getSize(),focusItemAtIndex:Ne}),[Be,Se,y,Ne]);const it=ee+b.top+b.bottom;return A.jsx(St,{ref:I,contentSize:it,viewportSize:n,className:l,onScroll:Ee,background:d,tapScrollCircleOptions:v,inertiaOptions:ge,itemCount:s,scrollBarWidth:S,enableThumbDrag:_,enableTrackClick:X,enableArrowButtons:O,enablePointerDrag:B,renderThumbOverlay:N,wheelSpeedMultiplier:Y,contentInsets:b,visibleStartIndex:De,visibleEndIndex:je,renderOverlay:st,children:ot})},lr=r.forwardRef(ar);exports.FenwickMapTree=vt;exports.ScrollBar=Ct;exports.ScrollPane=St;exports.VirtualScroll=lr;exports.minmax=de;exports.tapScrollCircleSampleVisual=Jt;exports.useFenwickMapTree=Mt;exports.useHeightCache=rr;exports.useLruCache=Pt;
|
|
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,q,B=!1)=>{const{x:O,y:ne}=h.current,v=y-O,Ie=q-ne,S=Math.abs(Ie),ie=S<lt?0:Ie<0?-1:1,_=x.current;let he=ie;const se=lt+Ft;ie===0?_!==0&&S<se?he=_:(he=0,B||(x.current=0)):ie!==_&&_!==0&&S<se?he=_:x.current=ie,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 q=R.current;q?.hasPointerCapture(y)&&q.releasePointerCapture(y)},[]),K=r.useCallback((y=!1)=>{y&&Y(m.current),m.current=null,x.current=0,E(mt)},[E,Y]),ue=r.useCallback(y=>{y.preventDefault(),y.stopPropagation();const q=R.current??y.currentTarget,{left:B,top:O,width:ne,height:v}=q.getBoundingClientRect();h.current={x:B+ne/2,y:O+v/2},m.current=y.pointerId,q.setPointerCapture(y.pointerId),X(y.clientX,y.clientY,!0)},[X]),ee=r.useCallback(y=>{m.current===y.pointerId&&(y.preventDefault(),X(y.clientX,y.clientY))},[X]),Z=r.useCallback(y=>{m.current===y.pointerId&&(y.preventDefault(),y.stopPropagation(),K(!0))},[K]);r.useImperativeHandle(g,()=>({reset:()=>{K(!0)},getElement:()=>R.current}),[K]);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,W=f??Lt,N={dragState:c,normalizedDistance:j,sizeScale:M,size:s,opacity:D},fe={...i,width:s,height:s,transform:`translateY(${z}px)`};return fe.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:fe,tabIndex:-1,onPointerDown:ue,onPointerMove:ee,onPointerUp:Z,onPointerCancel:Z,role:"presentation",children:W(N)})}));It.displayName="TapScrollCircle";const ce=(o,e,t)=>Math.min(t,Math.max(e,o)),ft="virtualscroll:tap-scroll-cancel",pt=20,Ot=250,Yt=60,zt=20,qt=20,Ht=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:Ht,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:ce(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 ce(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,K]=r.useState(!1),[ue,ee]=r.useState(!1),[Z,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}),W=r.useRef(t),N=r.useRef(ht),fe=r.useRef(null),y=r.useRef(null),q=r.useRef(null),B=r.useMemo(()=>$t(h,R),[R,h]),O=r.useMemo(()=>Ut(g),[g]),{enabled:ne,size:v,offsetX:Ie,offsetY:S,className:ie,maxVisualDistance:_,maxSpeedMultiplier:he,minSpeedMultiplier:se,opacity:ye,renderVisual:T,maxSpeedCurve:k}=B,P=r.useRef({viewportSize:e,maxScrollPosition:Math.max(o-e,0),scrollBarVisible:o>e,effectiveTapMaxDistance:Math.max(_,1),tapCircleMaxSpeedMultiplier:he,tapCircleMinSpeedMultiplier:se,tapCircleMaxSpeedCurve:k,tapScrollCircleOptions:h}),{mainSizeKey:J,crossSizeKey:F,positionKey:Ce,selectDelta:ge,getPointerCoordinate:be,arrowLabels:Q,arrowIcons:oe,directionClass:ae,orientation:pe}=O,we=Math.max(_,1),Fe=e/o,Te=c,b=Math.max(e-Te*2,0),C=Fe*b,te=Math.min(Math.max(pt,C||0),b||pt),U=o-e,$=Math.max(b-te,0),Re=U<=0||$<=0?0:t/U*$,Se=Re+te/2,de=o>e,Pe=de&&f;P.current={viewportSize:e,maxScrollPosition:U,scrollBarVisible:de,effectiveTapMaxDistance:we,tapCircleMaxSpeedMultiplier:he,tapCircleMinSpeedMultiplier:se,tapCircleMaxSpeedCurve:k,tapScrollCircleOptions:h},r.useEffect(()=>{W.current=t},[t]),r.useEffect(()=>{i||ee(!1)},[i]);const Le=Kt({isDragging:Y,isThumbHovered:ue,enableThumbDrag:i}),Ee=r.useCallback((n,l)=>{const I=P.current,w=l??W.current;if(s){const me=s(n,w);if(typeof me=="number"&&Number.isFinite(me))return W.current=me,me}const L=typeof n=="function"?n(w):n,V=Math.max(I.maxScrollPosition,0),H=I.scrollBarVisible?ce(L,0,V):0;return W.current=H,H},[s]),ze=r.useCallback(n=>{const l=P.current,I=W.current;if(!l.scrollBarVisible||l.maxScrollPosition<=0){const me=Ee(0,I),qe=me-I;return{nextPosition:me,actualDelta:qe,reachedBoundary:!0}}if(n===0)return{nextPosition:I,actualDelta:0,reachedBoundary:!1};const L=Ee(me=>ce(me+n,0,l.maxScrollPosition),I),V=L-I,H=V===0||n<0&&L<=0||n>0&&L>=l.maxScrollPosition;return{nextPosition:L,actualDelta:V,reachedBoundary:H}},[Ee]),G=r.useCallback(()=>{y.current!==null&&(window.cancelAnimationFrame(y.current),y.current=null),q.current=null},[]),ve=r.useCallback(()=>{N.current={...ht},D(!1),fe.current?.reset(),G()},[G]),xe=r.useCallback(n=>{const l=N.current,I=P.current;if(!l.active||l.direction===0){G();return}if(!I.scrollBarVisible||I.maxScrollPosition<=0){G();return}const w=q.current??n,L=Math.max((n-w)/1e3,0),V=Math.min(L,Bt);if(q.current=n,V<=0){y.current=window.requestAnimationFrame(xe);return}const H=Math.min(l.distance,I.effectiveTapMaxDistance)/I.effectiveTapMaxDistance,me=H**1.1,qe=typeof I.tapScrollCircleOptions?.maxSpeedMultiplier=="number",ke=Math.max(I.viewportSize*I.tapCircleMinSpeedMultiplier,40),He=qe?ke:1200;let at=Math.max(I.viewportSize*I.tapCircleMaxSpeedMultiplier,He);const et=I.tapCircleMaxSpeedCurve;if(et){const tt=Math.max(et.exponentialSteepness,0),At=Math.max(et.exponentialScale??I.tapCircleMaxSpeedMultiplier,0),Dt=tt===0?H:Math.expm1(tt*H),dt=tt===0?1:Math.expm1(tt)||1,Nt=dt===0?H: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,me+yt),wt=ke+(Mt-ke)*Rt,Et=l.direction*wt*V,{actualDelta:kt,reachedBoundary:Vt}=ze(Et);if(Vt||kt===0){G();return}y.current=window.requestAnimationFrame(xe)},[ze,G]),je=r.useCallback(()=>{y.current===null&&(q.current=null,y.current=window.requestAnimationFrame(xe))},[xe]);r.useEffect(()=>()=>{G()},[G]);const Ge=r.useCallback(n=>{N.current=n,D(n.active),n.active&&n.direction!==0?je():G()},[je,G]);r.useEffect(()=>{ne||ve()},[ve,ne]),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(!ne)return;const n=l=>{if(!N.current.active||N.current.pointerId===l.pointerId)return;const I=l.target;if(!(I instanceof Node)){ve();return}fe.current?.getElement()?.contains(I)||ve()};return document.addEventListener("pointerdown",n,!0),()=>{document.removeEventListener("pointerdown",n,!0)}},[ve,ne]);const Be=n=>{if(!de||$<=0||U<=0)return 0;const l=ce(n,0,$);return ce(l/$*U,0,U)},Ye=n=>{const l=Math.max(Math.round(e/qt),zt);ze(n*l)},{handleArrowPointerDown:Ze,handleArrowPointerUp:Me,handleArrowKeyDown:Ae}=Wt({canUseArrowButtons:Pe,enableArrowButtons:f,resetTapScroll:ve,scrollByStep:Ye}),De=n=>{if(!de)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},K(!0),ee(!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,L=ge(I,w),V=Be(l.startThumbPosition+L);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},K(!1),M.current&&!M.current.matches(":hover")&&ee(!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},K(!1),M.current&&!M.current.matches(":hover")&&ee(!1)},Qe=n=>{if(!de)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(),L=be(n)-(g?I.left:I.top);ve();const V=L-te/2,H=Be(V);Ee(H),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,L=ge(I,w),V=Be(l.startThumbPosition+L);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(()=>ce((Z?1:.8)*ye,0,1),[Z,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:{[J]:Te,[F]: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&&de?{orientation:pe,scrollPosition:t,maxScrollPosition:U,contentSize:o,viewportSize:e,thumbSize:te,thumbPosition:Re,thumbCenter:Se,trackSize:b,isDragging:Y,isTapScrollActive:Z,visibleStartIndex:E,visibleEndIndex:X}:null;return A.jsxs("div",{className:Xe.twMerge("group relative cursor-default select-none",ae,d),style:{[J]:e,[F]: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&&de&&ne&&A.jsx(It,{ref:fe,className:Xe.twMerge("pointer-events-auto absolute transition-opacity duration-150",ie),size:v,maxVisualDistance:we,style:it,opacity:ot,renderVisual:T,onDragChange:Ge}),a(-1,Q[0],oe[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)}),de&&A.jsx("div",{className:"group absolute",style:{[J]:te,[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":Le,style:{borderRadius:c-1,cursor:i?"pointer":"default"},onMouseEnter:()=>{i&&ee(!0)},onMouseLeave:()=>{i&&ee(!1)}})})]}),a(1,Q[1],oe[1])]})},le={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:K,visibleStartIndex:ue,visibleEndIndex:ee,renderOverlay:Z},D)=>{const M=r.useRef(0),j=r.useRef(null),z=r.useRef(null),W=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]),fe=r.useMemo(()=>({top:Math.max(0,K?.top??0),bottom:Math.max(0,K?.bottom??0)}),[K]);le.debug("[ScrollPane] ScrollPane rendered",{contentSize:e,viewportSize:t,scrollBarWidth:s,className:d,style:m,tapScrollCircleOptions:R,inertiaOptions:x,enablePointerDrag:g,contentInsets:fe});const y=r.useRef({contentSize:e,viewportSize:t}),q=r.useMemo(()=>e>t,[e,t]),B=r.useCallback(T=>{const{contentSize:k,viewportSize:P}=y.current,J=k>P,F=M.current;if(le.debug("[ScrollPane] scrollTo called",{newPosition:T,contentSize:k,viewportSize:P,currentIsScrollable:J,prevPosition:F}),!J)return M.current!==0&&(M.current=0,c?.(0,F)),M.current;const Ce=typeof T=="function"?T(M.current):T,ge=Math.max(k-P,0),be=ce(Ce,0,ge);return M.current!==be&&(M.current=be,c?.(be,F)),M.current},[c]),O=r.useCallback(()=>{const T=W.current;T.frame!==null&&cancelAnimationFrame(T.frame),T.frame=null,T.velocity=0,T.lastTimestamp=null},[]),ne=r.useRef(O);r.useEffect(()=>{ne.current=O},[O]);const v=r.useCallback(T=>{if(!q)return;const{maxVelocity:k,minVelocity:P,deceleration:J,startVelocityThreshold:F}=N,Ce=ce(T,-k,k);if(Math.abs(Ce)<F)return;O(),W.current.velocity=Ce,W.current.lastTimestamp=null;const ge=be=>{const Q=W.current;if(Q.lastTimestamp===null){Q.lastTimestamp=be,Q.frame=requestAnimationFrame(ge);return}const oe=be-Q.lastTimestamp;if(Q.lastTimestamp=be,oe<=0){Q.frame=requestAnimationFrame(ge);return}const ae=Q.velocity;let pe=ae;const we=J*oe;ae>0?pe=Math.max(0,ae-we):ae<0&&(pe=Math.min(0,ae+we));const Te=(ae+pe)/2*oe,b=M.current;Te!==0&&B(Se=>Se+Te);const C=M.current,{contentSize:te,viewportSize:U}=y.current,$=Math.max(te-U,0);Q.velocity=pe;const Re=C===b||C<=0&&pe<=0||C>=$&&pe>=0;if(Math.abs(pe)<P||Re){O();return}Q.frame=requestAnimationFrame(ge)};W.current.frame=requestAnimationFrame(ge)},[q,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&&(le.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(q){le.debug("[ScrollPane] Adjusting scroll position due to content or viewport size change",{contentSize:e,viewportSize:t,scrollPosition:M.current});const T=ce(e-t,0,e);M.current>T&&B(T)}else B(0)},[q,B,e,t]),r.useEffect(()=>{const T=P=>{if(!q)return;P.preventDefault(),O();let J=P.deltaY;P.deltaMode===1?J*=16:P.deltaMode===2&&(J*=t),Y!==1&&(J*=Y),le.debug("[ScrollPane] wheel event",{deltaY:J,scrollPosition:M.current,wheelSpeedMultiplier:Y,deltaMode:P.deltaMode,scrollTop:z.current?.scrollTop}),B(F=>F+J)},k=j.current;return k&&k.addEventListener("wheel",T,{passive:!1}),()=>{k&&k.removeEventListener("wheel",T)}},[q,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 ie=r.useId(),_=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 se=r.useRef(q);r.useEffect(()=>{se.current=q},[q]);const ye=r.useRef(N);return r.useEffect(()=>{ye.current=N},[N]),r.useEffect(()=>{if(g)return;const T=z.current,k=_.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(),J=()=>{const b=_.current;b.pointerId=null,b.startClientY=0,b.startScroll=0,b.isDragging=!1,b.velocitySamples=[]},F=()=>{const b=_.current;b.clickResetTimer!==null&&(window.clearTimeout(b.clickResetTimer),b.clickResetTimer=null)},Ce=b=>{const C=_.current,te=P();C.velocitySamples.push({clientY:b,time:te});const U=ye.current.velocitySampleWindow;C.velocitySamples=C.velocitySamples.filter($=>te-$.time<=U)},ge=b=>b instanceof HTMLElement&&b.closest("[data-scrollpane-ignore-drag='true']")!==null,be=b=>{const C=_.current;C.shouldCancelNextClick&&(b.preventDefault(),b.stopPropagation(),C.shouldCancelNextClick=!1)},Q=b=>{const C=_.current;C.isDragging||(C.isDragging=!0,C.shouldCancelNextClick=!0,T.hasPointerCapture(b.pointerId)||T.setPointerCapture(b.pointerId),Ce(b.clientY))},oe=b=>{const C=_.current;if(C.pointerId!==b.pointerId||!(he.current&&se.current)||!C.isDragging&&(Math.abs(b.clientY-C.startClientY)<k||(Q(b),!C.isDragging)))return;Ce(b.clientY);const te=b.clientY-C.startClientY,U=C.startScroll-te;S.current(U),b.cancelable&&b.preventDefault()},ae=b=>{const C=_.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 te=0;if(C.isDragging&&C.velocitySamples.length>=2){const $=C.velocitySamples,Re=ye.current.velocitySampleWindow,Se=$[$.length-1],de=$.find(Pe=>Se.time-Pe.time<=Re)??$[0];if(Se&&de&&Se.time!==de.time){const Pe=Se.clientY-de.clientY,Le=Se.time-de.time;te=-(Pe/Le)}}F(),C.shouldCancelNextClick&&(C.clickResetTimer=window.setTimeout(()=>{const $=_.current;$.shouldCancelNextClick=!1,$.clickResetTimer=null},0));const U=ye.current.startVelocityThreshold;J(),Math.abs(te)>=U&&Ie.current?.(te)},pe=b=>{if(!(he.current&&se.current)||b.button!==0&&b.pointerType==="mouse"||b.ctrlKey||b.metaKey||b.altKey||ge(b.target))return;window.dispatchEvent(new CustomEvent(ft,{detail:{paneId:ie}})),ne.current?.();const C=_.current;F(),C.pointerId=b.pointerId,C.startClientY=b.clientY,C.startScroll=M.current,C.isDragging=!1,C.shouldCancelNextClick=!1,C.velocitySamples=[]},we=b=>{const C=_.current;C.pointerId===b.pointerId&&(C.shouldCancelNextClick=!1,T.hasPointerCapture(b.pointerId)&&T.releasePointerCapture(b.pointerId),F(),J())},Fe=[["click",be,!0],["pointerdown",pe,{passive:!1}],["pointermove",oe,{passive:!1}],["pointerup",ae,void 0],["pointercancel",we,void 0]],Te=[["pointermove",oe,{passive:!1}],["pointerup",ae,void 0],["pointercancel",we,void 0]];return rt(T,Fe,"add"),rt(window,Te,"add"),()=>{rt(T,Fe,"remove"),rt(window,Te,"remove");const b=_.current;b.pointerId!==null&&T.hasPointerCapture(b.pointerId)&&T.releasePointerCapture(b.pointerId),F(),J()}},[ie]),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:fe.top,paddingBottom:fe.bottom,...g?{touchAction:"none"}:{}},id:ie,children:[h,o(M.current)]}),q&&A.jsx(Tt,{contentSize:e,viewportSize:t,scrollPosition:M.current,onScroll:B,enableThumbDrag:i,enableTrackClick:u,enableArrowButtons:f,scrollBarWidth:s,ariaControls:ie,tapScrollCircleOptions:R,itemCount:E,renderThumbOverlay:X,visibleStartIndex:ue,visibleEndIndex:ee}),Z?.()]})}),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),K=i*.35,ue=X/i*K,ee=Y/i*K,Z=ue*.45,D=ee*.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% + ${ue}px), calc(-50% + ${ee}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% + ${Z}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=ce(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}},re=(o,e)=>e<=0?0:ce(o,0,e-1),rr=o=>({top:Math.max(0,o?.top??0),bottom:Math.max(0,o?.bottom??0)}),Oe=(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,W=0n;for(;j<c&&M<e;){const N=Number(j),fe=i(N);if(M+=fe,z=j,j+=1n,W+=1n,!Number.isFinite(fe)||fe<=0)break}return W===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),W=i(z);if(M+=W,!Number.isFinite(W)||W<=0)break}x=d(D);const j=E(x);X=j.height,Y=j.end}const K=d(x),ue=d(Y),ee=d(K-BigInt(Math.max(0,t))),Z=d(ue+BigInt(Math.max(0,t)));return{renderingStartIndex:re(Number(ee),s),renderingEndIndex:re(Number(Z),s),visibleStartIndex:re(Number(K),s),visibleEndIndex:re(Number(ue),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=re(R,s),E=0;if(d!==-1&&m===c)x=re(d+1,s),E=0;else if(x===d&&m!==void 0&&h!==void 0)E=m-h-c;else{const{cumulative:Z,currentValue:D}=u.prefixSum(x,{materializeOption:{materialize:!1}});E=(Z??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 Z=E+Math.abs(Math.min(0,X)),D=x-1;for(;D>=0&&Z<e;)Z+=i(D),D--;for(x=re(D+1,s),E=0,Y=x;Y<s&&E<e;)E+=i(Y),Y++}const K=re(x-t,s),ue=re(Math.max(Y-1,x),s),ee=re(ue+t,s);return{renderingStartIndex:K,renderingEndIndex:ee,visibleStartIndex:x,visibleEndIndex:ue}},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},K)=>{const{width:ue,enableThumbDrag:ee,enableTrackClick:Z,enableArrowButtons:D,enableScrollToTopBottomButtons:M,renderThumbOverlay:j,tapScrollCircleOptions:z}=X??{},{enablePointerDrag:W,enableKeyboardNavigation:N=!0,wheelSpeedMultiplier:fe,inertiaOptions:y,clipItemHeight:q=!1,resetOnGetItemHeightChange:B=!1}=Y??{},O=r.useRef(null),ne=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),[ie]=r.useState(()=>{let a=v.top,p=0;if(typeof m=="number"){const n=ce(m,0,o-1),l=ce(n-i*2,0,o-1),I=ce(n+i*2,0,o-1),w=m>0?{materializeOption:{materialize:!0,ranges:[{from:l,to:I}]}}:void 0,{cumulative:L,total:V,currentValue:H}=S.prefixSum(m,w),me=Math.max(L-H,0);a=We(me,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}}),[_,he]=r.useState(ie.position),[se,ye]=r.useState(ie.total),[T,k]=r.useState(ie.position),[P,J]=r.useState(o),F=r.useRef(ie.position),Ce=r.useRef(v.top),ge=r.useRef(f??void 0),be=r.useRef(g??void 0),Q=r.useRef(new Map),oe=r.useRef(null),ae=r.useRef(null),[pe,we]=r.useState(null),[Fe,Te]=r.useState(!1),b=r.useRef(null),C=r.useRef(!1),te=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:L})=>{a(p,n,l,I,w,L)});r.useEffect(()=>(ne.current=!0,()=>{ne.current=!1}),[]),r.useEffect(()=>{N||(Q.current.clear(),oe.current=null,ae.current=null)},[N]);const Se=r.useCallback((a,p)=>{if(!p){Q.current.delete(a);return}N&&(Q.current.set(a,p),oe.current===a&&(oe.current=null,ae.current=a,U(p)))},[N,U]),de=.01,Pe=r.useRef({rafId:null,loopActive:!1,idleFrames:0,lastRenderedPosition:ie.position}),Le=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(()=>()=>{Le()},[Le]);const Ee=r.useCallback(()=>{const a=Pe.current;a.rafId=null;const p=F.current,n=Oe(p,v.top),l=S.getTotal();if(he(w=>Math.abs(w-p)<de?w:p),$({position:n,totalHeight:l}),Math.abs(a.lastRenderedPosition-p)>=de?(a.lastRenderedPosition=p,a.idleFrames=0):a.idleFrames+=1,a.idleFrames>=2){Le();return}if(typeof requestAnimationFrame=="function"){a.rafId=requestAnimationFrame(Ee);return}a.loopActive=!1},[S,v.top,$,Le]),ze=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]),G=r.useCallback((a,p)=>{const n=p?.immediate??!1,l=Oe(a,v.top);if(F.current=a,n){Pe.current.lastRenderedPosition=a,Pe.current.idleFrames=0,he(a),$({position:l,totalHeight:S.getTotal()});return}ze()},[ze,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-F.current)>.5;G(a,{immediate:!0}),p&&k(a)}else G(F.current,{immediate:!0})},[h,v.top,G]),r.useLayoutEffect(()=>{te.current!==t?(S.setValueFn(t,{reset:B}),te.current=t):S.setValueFn(t,{reset:!1}),P!==o&&(S.changeSize(o),J(o));const p=S.getTotal();se!==p&&ye(p)},[S,P,o,se,t,B]),r.useLayoutEffect(()=>{T!==null&&O.current&&(le.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=Oe(F.current,a),n=We(p,v.top);Ce.current=v.top,F.current=n,k(n),G(n,{immediate:!0})},[v.top,G]);const xe=r.useCallback(a=>{if(!O.current)return;const p=re(a,P),n=re(p-i*2,P),l=re(p+i*2,P),{cumulative:I,total:w,currentValue:L}=S.prefixSum(p,{materializeOption:{materialize:!0,ranges:[{from:n,to:l}]}});if(le.debug("[VirtualScroll] Scrolling to index:",p,"Offset:",I,"Total height:",w,"Current value:",L,"safeIndexFrom:",n,"safeIndexTo:",l),!w)return;const V=Math.max(I-L,0),H=We(V,v.top);ye(w),k(H),le.debug("[VirtualScroll] Setting scroll position to:",H)},[S,i,P,v.top]),je=r.useCallback(a=>{if(!O.current)return;const p=S.getTotal(),n=ce(Math.floor(a),0,p),l=S.findIndexAtOrAfter(n,{materializeOption:{materialize:!1}}).index;xe(l)},[S,xe]),Ge=r.useCallback(a=>{const p=Oe(F.current,v.top),n=typeof a=="function"?a(p):a;je(n);const l=O.current?.getScrollPosition(),I=typeof l=="number"?l:F.current;return G(I),I},[v.top,je,G]),Be=r.useCallback((a,p)=>{if(le.debug("[VirtualScroll] Scroll position changed:",a),G(a),M){if(C.current){C.current=!1;return}const n=a-p;if(le.debug("[VirtualScroll] Scroll diff:",n,"New:",a,"Prev:",p),Math.abs(n)>1){const l=n>0?"down":"up";we(l),Te(!0),le.debug("[VirtualScroll] Showing scroll buttons. Direction:",l),b.current&&clearTimeout(b.current),b.current=setTimeout(()=>{Te(!1),le.debug("[VirtualScroll] Hiding scroll buttons")},2e3)}}},[G,M]),Ye=r.useMemo(()=>Oe(_,v.top),[v.top,_]),Ze=r.useMemo(()=>{const a=sr(Ye,s,i,P,t,S,se);return le.debug("[VirtualScroll] Calculated rendering range:",{...a,scrollPosition:Ye,renderingContentSize:S.getTotal(),overscanCount:i,viewportSize:s}),a},[Ye,s,i,P,t,S,se]),{renderingStartIndex:Me,renderingEndIndex:Ae,visibleStartIndex:De,visibleEndIndex:Ne}=Ze,_e=r.useCallback((a,p)=>{if(!N||P===0)return;const n=re(a,P);if(!(p?.ensureVisible??!0)){const He=Q.current.get(n);He&&(oe.current=null,ae.current=n,U(He));return}const I=S.prefixSum(n,{materializeOption:{materialize:!1}}),w=I.currentValue,L=Math.max(I.cumulative-w,0),V=L+w,H=Oe(F.current,v.top),me=H+s;if(L<H||V>me){oe.current=n,xe(n);return}const ke=Q.current.get(n);if(ke){oe.current=null,ae.current=n,U(ke);return}oe.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=re(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=re(p-I,P);_e(w)}},[N,P,_e,Ne,De]),Qe=r.useCallback(a=>{if(!N)return;const p=re(a,P);oe.current=null,ae.current=p,E?.(p)},[N,P,E]);r.useEffect(()=>{const a=O.current?.getScrollPosition()??0,p=F.current,n=Oe(p,v.top);le.debug("[VirtualScroll] Range change effect triggered",{renderingStartIndex:Me,renderingEndIndex:Ae,visibleStartIndex:De,visibleEndIndex:Ne,scrollPositionState:_,paneScrollPosition:p,logicalScrollPosition:n,contentSize:se,scrollPaneScrollPosition:a}),Re({renderingStartIndex:Me,renderingEndIndex:Ae,visibleStartIndex:De,visibleEndIndex:Ne,scrollPosition:n,totalHeight:se})},[se,Ae,Me,v.top,Re,_,Ne,De]);const st=r.useCallback(()=>{if(!M)return null;const a=Fe&&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,Fe,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=re(Me,P),p=re(Ae,P),{cumulative:n,currentValue:l}=S.prefixSum(a,{materializeOption:{materialize:!1}}),I=n-l,w=[],L=[];for(let V=a;V<=p;V++){const H=t(V);S.get(V)!==H&&w.push({index:V,value:H});const{cumulative:qe,currentValue:ke}=S.prefixSum(V,{materializeOption:{materialize:!1}}),He=qe-ke;L.push(A.jsx(ir,{index:V,top:He-I+v.top,height:H,item:e(V),children:c,clipItemHeight:q,enableKeyboardNavigation:N,onKeyDown:Je,onFocus:Qe,registerItemRef:Se},V))}return w.length>0&&Promise.resolve().then(()=>{if(!ne.current)return;const V=S.updates(w);if(!ne.current||typeof V!="number")return;ye(V),le.debug("[VirtualScroll] Updated heights for items",w,"New total height:",V);const H=O.current?.getScrollPosition()??F.current;H===F.current||!ne.current||G(H)}),{visibleItems:L,startPosition:I}},[c,q,N,P,S,e,t,Qe,Je,Se,Ae,Me,v.top,G]),ot=r.useCallback(a=>{const p=(R??0)>0,n=Math.abs(a-_),l=p&&n>.5?_:a,I=Oe(l,v.top);if(le.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,L=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 le.debug("[VirtualScroll] Rendering items",{containerTop:w,logicalScrollPosition:Ye,resolvedInsets:v,effectiveScrollPosition:I}),A.jsxs("div",{className:"aqvs:items-wrapper",style:{top:w},children:[Ue,L]})},[R,P,S,Ye,Ae,Me,v,_,$e,s,Ue]);r.useImperativeHandle(K,()=>({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=se+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:ue,enableThumbDrag:ee,enableTrackClick:Z,enableArrowButtons:D,enablePointerDrag:W,renderThumbOverlay:j,wheelSpeedMultiplier:fe,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=ce;exports.tapScrollCircleSampleVisual=Zt;exports.useFenwickMapTree=St;exports.useHeightCache=tr;exports.useLruCache=Pt;
|