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