@aiquants/virtualscroll 1.8.0 → 1.10.0

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