@aiquants/virtualscroll 1.7.0 → 1.9.0

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