@aiquants/virtualscroll 1.15.0 → 1.18.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 F=require("react/jsx-runtime"),r=require("react"),Ze=require("tailwind-merge");class N{level;prefix;impl;constructor(e=2,t="[virtualscroll]",n=console){this.level=e,this.prefix=t,this.impl=n}static instance=new N(2,"[virtualscroll]");static setLevel(e){N.instance.setLevel(e)}setLevel(e){this.level=e}static setImplementation(e){N.instance.setImplementation(e)}setImplementation(e){this.impl=e}static setPrefix(e){N.instance.setPrefix(e)}setPrefix(e){this.prefix=e}formatMessage(e){return typeof e=="string"?[`${this.prefix} ${e}`]:[this.prefix,e]}static debug(e,...t){N.instance.debug(e,...t)}debug(e,...t){this.level<=0&&this.impl.debug(...this.formatMessage(e),...t)}static info(e,...t){N.instance.info(e,...t)}info(e,...t){this.level<=1&&this.impl.info(...this.formatMessage(e),...t)}static warn(e,...t){N.instance.warn(e,...t)}warn(e,...t){this.level<=2&&this.impl.warn(...this.formatMessage(e),...t)}static error(e,...t){N.instance.error(e,...t)}error(e,...t){this.level<=3&&this.impl.error(...this.formatMessage(e),...t)}}const vt={active:!1,offsetX:0,offsetY:0,distance:0,direction:0,pointerId:null},pt=6,Ot=8,Yt=({dragState:s,normalizedDistance:e})=>{const t=1+e*.18,n=.16+e*.24,o=.38+e*.28,c=s.active?"80ms ease-out":"220ms ease";return F.jsxs(F.Fragment,{children:[F.jsx("div",{className:"aqvs-tap-scroll-circle-visual-outer",style:{background:"linear-gradient(140deg, rgba(255,255,255,0.62), rgba(72,72,72,0.48))",boxShadow:`0 0 0 1px rgba(255,255,255,0.28), 0 10px 22px rgba(0,0,0,${n})`,transform:`scale(${t})`,transition:`${c}, ${s.active?"80ms":"260ms"} box-shadow ease`}}),F.jsx("div",{className:"aqvs-tap-scroll-circle-inner",style:{background:"linear-gradient(140deg, rgba(255,255,255,0.72), rgba(28,28,28,0.58))",boxShadow:"inset 0 4px 10px rgba(0,0,0,0.24), inset 0 0 2px rgba(255,255,255,0.55)",opacity:o,transition:s.active?"120ms opacity ease-out":"220ms opacity ease"}})]})},Ct=r.memo(r.forwardRef(({onDragChange:s,className:e,maxVisualDistance:t=160,size:n=40,style:o,opacity:c=1,renderVisual:u},d)=>{const[m,h]=r.useState(vt),p=r.useRef(null),b=r.useRef({x:0,y:0}),E=r.useRef(null),x=r.useRef(0),k=r.useCallback(V=>{h(V),s(V)},[s]),X=r.useCallback((V,W,G=!1)=>{const{x:U,y:L}=b.current,ve=V-U,ae=W-L,be=Math.abs(ae),I=be<pt?0:ae<0?-1:1,Se=x.current;let v=I;const Te=pt+Ot;I===0?Se!==0&&be<Te?v=Se:(v=0,G||(x.current=0)):I!==Se&&Se!==0&&be<Te?v=Se:x.current=I,k({active:G||be>=pt,offsetX:ve,offsetY:ae,distance:be,direction:v,pointerId:p.current})},[k]),q=r.useCallback(V=>{if(V===null)return;const W=E.current;W?.hasPointerCapture(V)&&W.releasePointerCapture(V)},[]),Z=r.useCallback((V=!1)=>{V&&q(p.current),p.current=null,x.current=0,k(vt)},[k,q]),ge=r.useCallback(V=>{V.preventDefault(),V.stopPropagation();const W=E.current??V.currentTarget,{left:G,top:U,width:L,height:ve}=W.getBoundingClientRect();b.current={x:G+L/2,y:U+ve/2},p.current=V.pointerId,W.setPointerCapture(V.pointerId),X(V.clientX,V.clientY,!0)},[X]),oe=r.useCallback(V=>{p.current===V.pointerId&&(V.preventDefault(),X(V.clientX,V.clientY))},[X]),re=r.useCallback(V=>{p.current===V.pointerId&&(V.preventDefault(),V.stopPropagation(),Z(!0))},[Z]);r.useImperativeHandle(d,()=>({reset:()=>{Z(!0)},getElement:()=>E.current}),[Z]);const Y=Math.min(Math.max(c,0),1),J=n/64,w=Math.min(m.distance,t)/t,j=m.direction*w*10*J,K=u??Yt,xe={dragState:m,normalizedDistance:w,sizeScale:J,size:n,opacity:Y},_={...o,width:n,height:n,transform:`translateY(${j}px)`};return _.opacity=Y,F.jsx("div",{ref:E,"data-testid":"virtual-scroll-tap-circle",className:Ze.twMerge("aqvs-tap-scroll-circle",e),style:_,tabIndex:-1,onPointerDown:ge,onPointerMove:oe,onPointerUp:re,onPointerCancel:re,role:"presentation",children:K(xe)})}));Ct.displayName="TapScrollCircle";const fe=(s,e,t)=>Math.min(t,Math.max(e,s)),bt="virtualscroll:tap-scroll-cancel",Tt=20,zt=250,qt=60,Ht=20,Bt=20,Xt=240,It={active:!1,offsetX:0,offsetY:0,distance:0,direction:0,pointerId:null},ht=2.2,jt=8,Ut=120,$t=1/60,Ye={enabled:!0,size:40,offsetX:-80,offsetY:0,className:void 0,maxVisualDistance:Xt,minSpeedMultiplier:.2,opacity:.9,renderVisual:void 0,maxSpeedCurve:void 0},Kt=s=>s?{mainSizeKey:"width",crossSizeKey:"height",positionKey:"left",selectDelta:(e,t)=>e,getPointerCoordinate:({clientX:e})=>e,arrowLabels:["Scroll left","Scroll right"],arrowIcons:["◀","▶"],directionClass:"aqvs-scrollbar-horizontal",orientation:"horizontal"}:{mainSizeKey:"height",crossSizeKey:"width",positionKey:"top",selectDelta:(e,t)=>t,getPointerCoordinate:({clientY:e})=>e,arrowLabels:["Scroll up","Scroll down"],arrowIcons:["▲","▼"],directionClass:"aqvs-scrollbar-vertical",orientation:"vertical"},Wt=(s,e)=>{const t=s?.maxSpeedMultiplier,n=typeof t=="number"?t:Jt(e);return{enabled:s?.enabled??Ye.enabled,size:s?.size??Ye.size,offsetX:s?.offsetX??Ye.offsetX,offsetY:s?.offsetY??Ye.offsetY,className:s?.className??Ye.className,maxVisualDistance:s?.maxVisualDistance??Ye.maxVisualDistance,maxSpeedMultiplier:n,minSpeedMultiplier:Math.max(s?.minSpeedMultiplier??Ye.minSpeedMultiplier,0),opacity:fe(s?.opacity??Ye.opacity,0,1),renderVisual:s?.renderVisual??Ye.renderVisual,maxSpeedCurve:s?.maxSpeedCurve??Ye.maxSpeedCurve}},Gt=({isDragging:s,isThumbHovered:e,enableThumbDrag:t})=>r.useMemo(()=>t?s?"dragging":e?"hover":"idle":"disabled",[t,s,e]),Zt=({canUseArrowButtons:s,enableArrowButtons:e,resetTapScroll:t,scrollByStep:n})=>{const o=r.useRef(null),c=r.useRef(null),u=r.useCallback(()=>{o.current!==null&&(window.clearInterval(o.current),o.current=null),c.current!==null&&(window.clearTimeout(c.current),c.current=null)},[]),d=r.useCallback(()=>{u()},[u]),m=r.useCallback(p=>b=>{s&&(b.preventDefault(),b.stopPropagation(),t(),u(),n(p),c.current=window.setTimeout(()=>{o.current=window.setInterval(()=>{n(p)},qt)},zt))},[s,u,t,n]),h=r.useCallback(p=>b=>{e&&(b.key==="Enter"||b.key===" "||b.key==="Spacebar")&&(b.preventDefault(),n(p))},[e,n]);return r.useEffect(()=>()=>{u()},[u]),{handleArrowPointerDown:m,handleArrowPointerUp:d,handleArrowKeyDown:h}},Jt=s=>{if(!s||s<=0)return ht;const e=Math.max(1,s),t=Math.log10(e),n=ht+t*jt;return fe(n,ht,Ut)},yt=({contentSize:s,viewportSize:e,scrollPosition:t,onScroll:n,enableThumbDrag:o=!0,enableTrackClick:c=!0,enableArrowButtons:u=!0,horizontal:d=!1,scrollBarWidth:m=12,className:h,ariaControls:p,tapScrollCircleOptions:b,itemCount:E,renderThumbOverlay:x,visibleStartIndex:k,visibleEndIndex:X})=>{const[q,Z]=r.useState(!1),[ge,oe]=r.useState(!1),[re,Y]=r.useState(!1),J=r.useRef(null),w=r.useRef({pointerId:null,startThumbPosition:0,startClientX:0,startClientY:0}),j=r.useRef({pointerId:null,startThumbPosition:0,startClientX:0,startClientY:0}),K=r.useRef(t),xe=r.useRef(n),_=r.useRef(It),V=r.useRef(null),W=r.useRef(null),G=r.useRef(null),U=r.useMemo(()=>Wt(b,E),[E,b]),L=r.useMemo(()=>Kt(d),[d]),{enabled:ve,size:ae,offsetX:be,offsetY:I,className:Se,maxVisualDistance:v,maxSpeedMultiplier:Te,minSpeedMultiplier:Me,opacity:Le,renderVisual:T,maxSpeedCurve:A}=U,D=r.useRef({viewportSize:e,maxScrollPosition:Math.max(s-e,0),scrollBarVisible:s>e,effectiveTapMaxDistance:Math.max(v,1),tapCircleMaxSpeedMultiplier:Te,tapCircleMinSpeedMultiplier:Me,tapCircleMaxSpeedCurve:A,tapScrollCircleOptions:b,effectiveTrackLength:0,onScroll:n,scrollPosition:t}),{mainSizeKey:Q,crossSizeKey:le,positionKey:Ee,selectDelta:de,getPointerCoordinate:ne,arrowLabels:se,arrowIcons:Ce,directionClass:ye,orientation:Pe}=L,we=Math.max(v,1),ze=e/s,me=Math.max(e-m*2,0),g=ze*me,M=Math.min(Math.max(Tt,g||0),me||Tt),$=s-e,ie=Math.max(me-M,0),ce=$<=0||ie<=0?0:t/$*ie,Fe=ce+M/2,ue=s>e||q,_e=ue&&u;r.useLayoutEffect(()=>{D.current={viewportSize:e,maxScrollPosition:$,scrollBarVisible:ue,effectiveTapMaxDistance:we,tapCircleMaxSpeedMultiplier:Te,tapCircleMinSpeedMultiplier:Me,tapCircleMaxSpeedCurve:A,tapScrollCircleOptions:b,effectiveTrackLength:ie,onScroll:n,scrollPosition:t}}),r.useLayoutEffect(()=>{K.current=t},[t]),r.useLayoutEffect(()=>{xe.current=n},[n]),r.useEffect(()=>{o||oe(!1)},[o]);const $e=Gt({isDragging:q,isThumbHovered:ge,enableThumbDrag:o}),ke=r.useCallback((a,S)=>{const C=D.current,i=S??K.current;if(xe.current){const R=xe.current(a,i);if(typeof R=="number"&&Number.isFinite(R))return K.current=R,R}const l=typeof a=="function"?a(i):a,f=Math.max(C.maxScrollPosition,0),P=C.scrollBarVisible?fe(l,0,f):0;return K.current=P,P},[]),qe=r.useCallback(a=>{const S=D.current,C=K.current;if(!S.scrollBarVisible||S.maxScrollPosition<=0){const R=ke(0,C),y=R-C;return{nextPosition:R,actualDelta:y,reachedBoundary:!0}}if(a===0)return{nextPosition:C,actualDelta:0,reachedBoundary:!1};const l=ke(R=>fe(R+a,0,S.maxScrollPosition),C),f=l-C,P=f===0||a<0&&l<=0||a>0&&l>=S.maxScrollPosition;return{nextPosition:l,actualDelta:f,reachedBoundary:P}},[ke]),Ie=r.useCallback(()=>{W.current!==null&&(window.cancelAnimationFrame(W.current),W.current=null),G.current=null},[]),Re=r.useCallback(()=>{_.current={...It},Y(!1),V.current?.reset(),Ie()},[Ie]),We=r.useCallback(a=>{const S=_.current,C=D.current;if(!S.active||S.direction===0){Ie();return}if(!C.scrollBarVisible||C.maxScrollPosition<=0){Ie();return}const i=G.current??a,l=Math.max((a-i)/1e3,0),f=Math.min(l,$t);if(G.current=a,f<=0){W.current=window.requestAnimationFrame(We);return}const P=Math.min(S.distance,C.effectiveTapMaxDistance)/C.effectiveTapMaxDistance,R=P**1.1,y=typeof C.tapScrollCircleOptions?.maxSpeedMultiplier=="number",z=Math.max(C.viewportSize*C.tapCircleMinSpeedMultiplier,40),B=y?z:1200;let H=Math.max(C.viewportSize*C.tapCircleMaxSpeedMultiplier,B);const pe=C.tapCircleMaxSpeedCurve;if(pe){const ct=Math.max(pe.exponentialSteepness,0),Nt=Math.max(pe.exponentialScale??C.tapCircleMaxSpeedMultiplier,0),Lt=ct===0?P:Math.expm1(ct*P),xt=ct===0?1:Math.expm1(ct)||1,Ft=xt===0?P:Math.min(Math.max(Lt/xt,0),1),_t=C.viewportSize*Nt*Ft;H=Math.min(H,Math.max(_t,z))}const he=Math.max(H,z),Ne=Math.max(pe?.easedOffset??0,0),Ke=Math.min(1,R+Ne),nt=z+(he-z)*Ke,st=S.direction*nt*f,{actualDelta:At,reachedBoundary:Dt}=qe(st);if(Dt||At===0){Ie();return}W.current=window.requestAnimationFrame(We)},[qe,Ie]),ee=r.useCallback(()=>{W.current===null&&(G.current=null,W.current=window.requestAnimationFrame(We))},[We]);r.useEffect(()=>()=>{Ie()},[Ie]);const ot=r.useCallback(a=>{_.current=a,Y(a.active),a.active&&a.direction!==0?ee():Ie()},[ee,Ie]);r.useEffect(()=>{ve||Re()},[Re,ve]),r.useEffect(()=>{const a=S=>{const i=S.detail?.paneId;i&&p&&i!==p||Re()};return window.addEventListener(bt,a),()=>{window.removeEventListener(bt,a)}},[p,Re]),r.useEffect(()=>{if(!ve)return;const a=S=>{if(!_.current.active||_.current.pointerId===S.pointerId)return;const C=S.target;if(!(C instanceof Node)){Re();return}V.current?.getElement()?.contains(C)||Re()};return document.addEventListener("pointerdown",a,!0),()=>{document.removeEventListener("pointerdown",a,!0)}},[Re,ve]);const rt=a=>{if(!ue||ie<=0||$<=0)return 0;const S=fe(a,0,ie);return fe(S/ie*$,0,$)},Ve=r.useCallback(a=>{const{scrollBarVisible:S,effectiveTrackLength:C,maxScrollPosition:i}=D.current;if(N.debug("[ScrollBar] calculateScrollPositionFromThumb",{thumbPos:a,trackLen:C,maxScroll:i}),C<=0||i<=0)return null;const l=fe(a,0,C);return fe(l/C*i,0,i)},[]),Je=r.useCallback(a=>{const S=w.current;if(S.pointerId!==a.pointerId)return;const C=a.clientX-S.startClientX,i=a.clientY-S.startClientY,l=de(C,i);N.debug("[ScrollBar] handleThumbPointerMove",{delta:l,startThumbPosition:S.startThumbPosition,clientY:a.clientY,startClientY:S.startClientY,metrics:D.current});const f=Ve(S.startThumbPosition+l);f!==null&&ke(f),a.cancelable&&a.preventDefault()},[de,Ve,ke]),Ge=r.useCallback(a=>{if(w.current.pointerId===a.pointerId)if(document.removeEventListener("pointermove",Je),document.removeEventListener("pointerup",Ge),document.removeEventListener("pointercancel",Ge),w.current={pointerId:null,startThumbPosition:0,startClientX:0,startClientY:0},Z(!1),J.current){const C=J.current.getBoundingClientRect();a.clientX>=C.left&&a.clientX<=C.right&&a.clientY>=C.top&&a.clientY<=C.bottom||oe(!1)}else oe(!1)},[Je]),dt=a=>{const S=Math.max(Math.round(e/Bt),Ht);qe(a*S)},{handleArrowPointerDown:Oe,handleArrowPointerUp:Ae,handleArrowKeyDown:He}=Zt({canUseArrowButtons:_e,enableArrowButtons:u,resetTapScroll:Re,scrollByStep:dt}),Be=a=>{if(ue){if(!o){a.preventDefault(),a.stopPropagation();return}a.pointerType==="mouse"&&a.button!==0||a.ctrlKey||(Re(),w.current={pointerId:a.pointerId,startThumbPosition:ce,startClientX:a.clientX,startClientY:a.clientY},document.addEventListener("pointermove",Je),document.addEventListener("pointerup",Ge),document.addEventListener("pointercancel",Ge),Z(!0),oe(!0),a.preventDefault(),a.stopPropagation())}},De=a=>{if(!ue)return;if(!c){a.preventDefault(),a.stopPropagation();return}if(a.pointerType==="mouse"&&a.button!==0||a.ctrlKey)return;const S=a.currentTarget,C=S.getBoundingClientRect(),l=ne(a)-(d?C.left:C.top);Re();const f=l-M/2,P=rt(f);ke(P),S.setPointerCapture&&S.setPointerCapture(a.pointerId),j.current={pointerId:a.pointerId,startThumbPosition:f,startClientX:a.clientX,startClientY:a.clientY},a.preventDefault(),a.stopPropagation()},Xe=a=>{const S=j.current;if(S.pointerId!==a.pointerId)return;const C=a.clientX-S.startClientX,i=a.clientY-S.startClientY,l=de(C,i),f=rt(S.startThumbPosition+l);ke(f),a.cancelable&&a.preventDefault()},je=a=>{if(j.current.pointerId!==a.pointerId)return;const S=a.currentTarget;S.hasPointerCapture(a.pointerId)&&S.releasePointerCapture(a.pointerId),j.current={pointerId:null,startThumbPosition:0,startClientX:0,startClientY:0},a.preventDefault(),a.stopPropagation()},at=a=>{if(j.current.pointerId!==a.pointerId)return;const S=a.currentTarget;S.hasPointerCapture(a.pointerId)&&S.releasePointerCapture(a.pointerId),j.current={pointerId:null,startThumbPosition:0,startClientX:0,startClientY:0}},lt=r.useMemo(()=>fe((re?1:.8)*Le,0,1),[re,Le]),mt=r.useMemo(()=>{const S=`calc(50% - ${ae/2}px + ${I}px)`;return{left:be,top:S}},[be,I,ae]),Qe=(a,S,C,i)=>F.jsx("button",{type:"button",tabIndex:-1,className:"aqvs-scrollbar-arrow-button",style:{[Q]:m,[le]:m},"aria-label":S,onMouseDown:Oe(a),onTouchStart:Oe(a),onMouseUp:Ae,onMouseLeave:Ae,onTouchEnd:Ae,onTouchCancel:Ae,onKeyDown:He(a),"aria-disabled":!u,disabled:!_e,children:F.jsx("span",{"aria-hidden":"true",children:C})},i),et=x&&ue?{orientation:Pe,scrollPosition:t,maxScrollPosition:$,contentSize:s,viewportSize:e,thumbSize:M,thumbPosition:ce,thumbCenter:Fe,trackSize:me,isDragging:q,isTapScrollActive:re,visibleStartIndex:k,visibleEndIndex:X}:null;return F.jsxs("div",{className:Ze.twMerge("aqvs-scrollbar",ye,!ue&&"pointer-events-none opacity-0",h),style:{[Q]:e,[le]:m},role:"scrollbar",tabIndex:-1,"aria-controls":p,"aria-valuenow":t,"aria-valuemin":0,"aria-valuemax":$,"aria-orientation":d?"horizontal":"vertical",children:[!d&&ue&&ve&&F.jsx(Ct,{ref:V,className:Ze.twMerge("aqvs-scrollbar-tap-circle-wrapper",Se),size:ae,maxVisualDistance:we,style:mt,opacity:lt,renderVisual:T,onDragChange:ot},"tap-circle"),Qe(-1,se[0],Ce[0],"arrow-start"),F.jsxs("div",{className:"aqvs-scrollbar-track",style:{borderRadius:m/2},onPointerDown:De,onPointerMove:Xe,onPointerUp:je,onPointerCancel:at,"aria-disabled":!c,children:[et&&F.jsx("div",{className:"aqvs-scrollbar-overlay","aria-hidden":!0,children:x?.(et)},"overlay"),F.jsx("div",{className:Ze.twMerge("aqvs-scrollbar-thumb-wrapper",!(ue||q)&&"pointer-events-none opacity-0"),style:{[Q]:M,[Ee]:ce,...d?{top:0,bottom:0}:{left:0,right:0}},onPointerDown:Be,role:"slider","aria-orientation":d?"horizontal":"vertical","aria-valuenow":t,"aria-valuemin":0,"aria-valuemax":$,"aria-disabled":!o,tabIndex:-1,children:F.jsx("div",{ref:J,className:Ze.twMerge("aqvs-scrollbar-thumb",d?"aqvs-scrollbar-thumb-horizontal":"aqvs-scrollbar-thumb-vertical"),"data-thumb-state":$e,style:{borderRadius:m-1,cursor:o?"pointer":"default"},onMouseEnter:()=>{o&&oe(!0)},onMouseLeave:()=>{o&&oe(!1)}},"thumb")},"thumb-wrapper")]},"track"),Qe(1,se[1],Ce[1],"arrow-end")]})},it={maxVelocity:6,minVelocity:.02,deceleration:.0025,velocitySampleWindow:90,startVelocityThreshold:.04},ut=(s,e,t)=>{for(const[n,o,c]of e)t==="add"?s.addEventListener(n,o,c):s.removeEventListener(n,o,c)},wt=r.forwardRef(({children:s,contentSize:e,viewportSize:t,scrollBarWidth:n=12,enableThumbDrag:o=!0,enableTrackClick:c=!0,enableArrowButtons:u=!0,enablePointerDrag:d=!0,onScroll:m,className:h,style:p,background:b,tapScrollCircleOptions:E,inertiaOptions:x,itemCount:k,renderThumbOverlay:X,wheelSpeedMultiplier:q=1,contentInsets:Z,visibleStartIndex:ge,visibleEndIndex:oe,renderOverlay:re,initialScrollPosition:Y=0},J)=>{const w=r.useRef(Y),j=r.useRef(null),K=r.useRef(null),xe=r.useRef({frame:null,velocity:0,lastTimestamp:null}),_=r.useMemo(()=>({maxVelocity:x?.maxVelocity??it.maxVelocity,minVelocity:x?.minVelocity??it.minVelocity,deceleration:x?.deceleration??it.deceleration,velocitySampleWindow:x?.velocitySampleWindow??it.velocitySampleWindow,startVelocityThreshold:x?.startVelocityThreshold??it.startVelocityThreshold}),[x]),V=r.useMemo(()=>({top:Math.max(0,Z?.top??0),bottom:Math.max(0,Z?.bottom??0)}),[Z]);N.debug("[ScrollPane] ScrollPane rendered",{contentSize:e,viewportSize:t,scrollBarWidth:n,className:h,style:p,tapScrollCircleOptions:E,inertiaOptions:x,enablePointerDrag:d,contentInsets:V});const W=r.useRef({contentSize:e,viewportSize:t});W.current={contentSize:e,viewportSize:t};const G=r.useMemo(()=>e>t,[e,t]),U=r.useCallback(T=>{const{contentSize:A,viewportSize:D}=W.current,Q=A>D,le=w.current;if(N.debug("[ScrollPane] scrollTo called",{newPosition:T,contentSize:A,viewportSize:D,currentIsScrollable:Q,prevPosition:le}),!Q)return w.current!==0&&(w.current=0,m?.(0,le)),w.current;const Ee=typeof T=="function"?T(w.current):T,de=Math.max(A-D,0),ne=fe(Ee,0,de);return w.current!==ne&&(w.current=ne,m?.(ne,le)),w.current},[m]),L=r.useCallback(()=>{const T=xe.current;T.frame!==null&&cancelAnimationFrame(T.frame),T.frame=null,T.velocity=0,T.lastTimestamp=null},[]),ve=r.useRef(L);r.useEffect(()=>{ve.current=L},[L]);const ae=r.useCallback(T=>{if(!G)return;const{maxVelocity:A,minVelocity:D,deceleration:Q,startVelocityThreshold:le}=_,Ee=fe(T,-A,A);if(Math.abs(Ee)<le)return;L(),xe.current.velocity=Ee,xe.current.lastTimestamp=null;const de=ne=>{const se=xe.current;if(se.lastTimestamp===null){se.lastTimestamp=ne,se.frame=requestAnimationFrame(de);return}const Ce=ne-se.lastTimestamp;if(se.lastTimestamp=ne,Ce<=0){se.frame=requestAnimationFrame(de);return}const ye=se.velocity;let Pe=ye;const we=Q*Ce;ye>0?Pe=Math.max(0,ye-we):ye<0&&(Pe=Math.min(0,ye+we));const me=(ye+Pe)/2*Ce,g=w.current;me!==0&&U(ue=>ue+me);const M=w.current,{contentSize:$,viewportSize:ie}=W.current,ce=Math.max($-ie,0);se.velocity=Pe;const Fe=M===g||M<=0&&Pe<=0||M>=ce&&Pe>=0;if(Math.abs(Pe)<D||Fe){L();return}se.frame=requestAnimationFrame(de)};xe.current.frame=requestAnimationFrame(de)},[G,_,U,L]),be=r.useRef(ae);r.useEffect(()=>{be.current=ae},[ae]),r.useLayoutEffect(()=>{W.current={contentSize:e,viewportSize:t}},[e,t]),r.useLayoutEffect(()=>{const T=K.current;if(!T)return;const A=()=>{T.scrollTop!==0&&(N.debug("[ScrollPane] Native scroll detected, resetting to 0",{scrollTop:T.scrollTop}),T.scrollTop=0),T.scrollLeft!==0&&(T.scrollLeft=0)};return T.addEventListener("scroll",A),()=>T.removeEventListener("scroll",A)},[]),r.useLayoutEffect(()=>{if(G){N.debug("[ScrollPane] Adjusting scroll position due to content or viewport size change",{contentSize:e,viewportSize:t,scrollPosition:w.current});const T=fe(e-t,0,e);w.current>T&&U(T)}else U(0)},[G,U,e,t]),r.useEffect(()=>{const T=D=>{if(!G)return;D.preventDefault(),L();let Q=D.deltaY;D.deltaMode===1?Q*=16:D.deltaMode===2&&(Q*=t),q!==1&&(Q*=q),N.debug("[ScrollPane] wheel event",{deltaY:Q,scrollPosition:w.current,wheelSpeedMultiplier:q,deltaMode:D.deltaMode,scrollTop:K.current?.scrollTop}),U(le=>le+Q)},A=j.current;return A&&A.addEventListener("wheel",T,{passive:!1}),()=>{A&&A.removeEventListener("wheel",T)}},[G,U,L,t,q]),r.useImperativeHandle(J,()=>({scrollTo:T=>(L(),U(T)),getScrollPosition:()=>w.current,getContentSize:()=>e,getViewportSize:()=>t}),[U,e,t,L]);const I=r.useRef(U);r.useEffect(()=>{I.current=U},[U]);const Se=r.useId(),v=r.useRef({pointerId:null,startClientY:0,startScroll:0,isDragging:!1,shouldCancelNextClick:!1,clickResetTimer:null,velocitySamples:[]}),Te=r.useRef(d);r.useEffect(()=>{Te.current=d},[d]);const Me=r.useRef(G);r.useEffect(()=>{Me.current=G},[G]);const Le=r.useRef(_);return r.useEffect(()=>{Le.current=_},[_]),r.useEffect(()=>{if(d)return;const T=K.current,A=v.current;A.pointerId!==null&&T&&T.hasPointerCapture(A.pointerId)&&T.releasePointerCapture(A.pointerId),A.clickResetTimer!==null&&(window.clearTimeout(A.clickResetTimer),A.clickResetTimer=null),A.pointerId=null,A.startClientY=0,A.startScroll=0,A.isDragging=!1,A.shouldCancelNextClick=!1,A.velocitySamples=[]},[d]),r.useEffect(()=>{const T=K.current;if(!T)return;const A=6,D=()=>typeof performance<"u"&&typeof performance.now=="function"?performance.now():Date.now(),Q=()=>{const g=v.current;g.pointerId=null,g.startClientY=0,g.startScroll=0,g.isDragging=!1,g.velocitySamples=[]},le=()=>{const g=v.current;g.clickResetTimer!==null&&(window.clearTimeout(g.clickResetTimer),g.clickResetTimer=null)},Ee=g=>{const M=v.current,$=D();M.velocitySamples.push({clientY:g,time:$});const ie=Le.current.velocitySampleWindow;M.velocitySamples=M.velocitySamples.filter(ce=>$-ce.time<=ie)},de=g=>g instanceof HTMLElement&&g.closest("[data-scrollpane-ignore-drag='true']")!==null,ne=g=>{const M=v.current;M.shouldCancelNextClick&&(g.preventDefault(),g.stopPropagation(),M.shouldCancelNextClick=!1)},se=g=>{const M=v.current;M.isDragging||(M.isDragging=!0,M.shouldCancelNextClick=!0,T.hasPointerCapture(g.pointerId)||T.setPointerCapture(g.pointerId),Ee(g.clientY))},Ce=g=>{const M=v.current;if(M.pointerId!==g.pointerId||!(Te.current&&Me.current)||!M.isDragging&&(Math.abs(g.clientY-M.startClientY)<A||(se(g),!M.isDragging)))return;Ee(g.clientY);const $=g.clientY-M.startClientY,ie=M.startScroll-$;I.current(ie),g.cancelable&&g.preventDefault()},ye=g=>{const M=v.current;if(M.pointerId!==g.pointerId)return;M.isDragging&&M.shouldCancelNextClick&&g.cancelable&&(g.preventDefault(),g.stopPropagation()),T.hasPointerCapture(g.pointerId)&&T.releasePointerCapture(g.pointerId);let $=0;if(M.isDragging&&M.velocitySamples.length>=2){const ce=M.velocitySamples,Fe=Le.current.velocitySampleWindow,ue=ce[ce.length-1],_e=ce.find($e=>ue.time-$e.time<=Fe)??ce[0];if(ue&&_e&&ue.time!==_e.time){const $e=ue.clientY-_e.clientY,ke=ue.time-_e.time;$=-($e/ke)}}le(),M.shouldCancelNextClick&&(M.clickResetTimer=window.setTimeout(()=>{const ce=v.current;ce.shouldCancelNextClick=!1,ce.clickResetTimer=null},0));const ie=Le.current.startVelocityThreshold;Q(),Math.abs($)>=ie&&be.current?.($)},Pe=g=>{if(!(Te.current&&Me.current)||g.button!==0&&g.pointerType==="mouse"||g.ctrlKey||g.metaKey||g.altKey||de(g.target))return;window.dispatchEvent(new CustomEvent(bt,{detail:{paneId:Se}})),ve.current?.();const M=v.current;le(),M.pointerId=g.pointerId,M.startClientY=g.clientY,M.startScroll=w.current,M.isDragging=!1,M.shouldCancelNextClick=!1,M.velocitySamples=[]},we=g=>{const M=v.current;M.pointerId===g.pointerId&&(M.shouldCancelNextClick=!1,T.hasPointerCapture(g.pointerId)&&T.releasePointerCapture(g.pointerId),le(),Q())},ze=[["click",ne,!0],["pointerdown",Pe,{passive:!1}],["pointermove",Ce,{passive:!1}],["pointerup",ye,void 0],["pointercancel",we,void 0]],me=[["pointermove",Ce,{passive:!1}],["pointerup",ye,void 0],["pointercancel",we,void 0]];return ut(T,ze,"add"),ut(window,me,"add"),()=>{ut(T,ze,"remove"),ut(window,me,"remove");const g=v.current;g.pointerId!==null&&T.hasPointerCapture(g.pointerId)&&T.releasePointerCapture(g.pointerId),le(),Q()}},[Se]),F.jsxs("div",{ref:j,className:Ze.twMerge("aqvs-scroll-pane",h),style:p,children:[F.jsxs("div",{ref:K,className:Ze.twMerge("aqvs-scroll-pane-content"),style:{height:t,paddingTop:V.top,paddingBottom:V.bottom,...d?{touchAction:"none"}:{}},id:Se,children:[b,s(w.current)]}),F.jsx(yt,{contentSize:e,viewportSize:t,scrollPosition:w.current,onScroll:U,enableThumbDrag:o,enableTrackClick:c,enableArrowButtons:u,scrollBarWidth:n,ariaControls:Se,tapScrollCircleOptions:E,itemCount:k,renderThumbOverlay:X,visibleStartIndex:ge,visibleEndIndex:oe},"scrollbar"),re?.()]})}),St=(s,e,t)=>Math.min(Math.max(s,e),t),Qt=({dragState:s,normalizedDistance:e,sizeScale:t,size:n})=>{const o=Math.max(n/2,1),c=1+e*.65,u=Math.max(.65,1-e*.25),d=s.direction*e*26*t,m=.8+e*.18,h=3*t,p=6*t,b=22*t,E=Math.abs(d)+p,x=d>0?h:-Math.abs(d)-h,k=Math.max(2.5,3*t),X=St(s.offsetX,-o,o),q=St(s.offsetY,-o,o),Z=o*.35,ge=X/o*Z,oe=q/o*Z,re=ge*.45,Y=oe*.45,J=Math.max(b*.38,6),w=.65+e*.2,j=s.active;return F.jsxs(F.Fragment,{children:[F.jsx("div",{className:"aqvs-tap-scroll-circle-gradient",style:{transform:`scale(${u}, ${c})`,transition:j?"40ms transform ease-out":"200ms ease transform"}}),F.jsx("div",{className:"aqvs-sample-visual-rod",style:{width:b,height:b,transform:`translate(calc(-50% + ${ge}px), calc(-50% + ${oe}px)) scale(${u}, ${m*c})`,transition:j?"70ms transform ease-out":"200ms ease transform"}}),F.jsx("div",{className:"aqvs-sample-visual-pupil",style:{width:J,height:J,transform:`translate(calc(-50% + ${re}px), calc(-50% + ${Y}px)) scale(${u}, ${c})`,opacity:w,boxShadow:"0 0 8px rgba(255,255,255,0.45)",transition:j?"120ms opacity 150ms, 120ms transform ease-out ease-out":"220ms ease transform, 240ms opacity ease"}}),F.jsx("div",{className:"aqvs-sample-visual-highlight",style:{width:k,height:E,transform:`translate(-50%, ${x}px)`,opacity:e,transition:j?"40ms height, 60ms opacity ease-out ease-out":"200ms ease height, 120ms ease opacity"}})]})},er=s=>{if(!Number.isFinite(s))return 0n;const e=Math.trunc(s);return e<=0?0n:BigInt(e)},ft=s=>{if(s<=0||!Number.isFinite(s))return 0;const e=Math.trunc(s),t=BigInt(e)&-BigInt(e);return Number(t)};class Et{tree;deltas;size;baseValue;valueFn;total;constructor(e,t,n){this.reset(e,t,n)}reset(e,t,n){if(this.size=e,this.tree=new Map,this.deltas=new Map,this.total=void 0,typeof t=="function"){if(this.valueFn=t,this.size>0){const c=n?.sampleRange??{from:0,to:Math.min(99,this.size-1)},{mode:u,materializedValues:d}=this._calculateMode(c.from,c.to);if(this.baseValue=u,n?.materialize)for(let m=0;m<d.length;m++){const h=d[m],p=c.from+m;if(p>=this.size)break;const b=h-this.baseValue;this.deltas.set(p,b),this._updateTree(p,b)}}else this.baseValue=0;this.total=this.getTotal()}else this.valueFn=void 0,this.baseValue=t,this.total=this.baseValue*this.size}setValueFn(e,t){if(t?.reset){this.reset(this.size,e);return}typeof e=="function"?this.valueFn=e:(this.valueFn=void 0,this.baseValue=e)}_calculateMode(e,t){if(!this.valueFn)return{mode:0,materializedValues:[]};const n=[];for(let h=e;h<=t&&!(h>=this.size);h++)n.push(this.valueFn(h));const o=[...n];if(n.length===0)return{mode:0,materializedValues:[]};n.sort((h,p)=>h-p);const c=Math.floor(n.length/2);let u;n.length%2===0?u=Math.floor((n[c-1]+n[c])/2):u=n[c];const d=new Map;let m=0;for(const h of n){const p=(d.get(h)??0)+1;d.set(h,p),p>m&&(m=p)}if(m>n.length*.2){const h=[];for(const[b,E]of d.entries())E===m&&h.push(b);const p=h.reduce((b,E)=>b+E,0);u=Math.floor(p/h.length)}return{mode:u,materializedValues:o}}update(e,t){return this.updates([{index:e,value:t}])}updates(e){const t=this._buildDeltaUpdates(e);return t.length>0?this.updateDeltas(t):this.total}updateDelta(e,t){return this.updateDeltas([{index:e,change:t}])}updateDeltas(e){for(const{index:t,change:n}of e){if(t<0||t>=this.size)throw new Error(`Index ${t} out of bounds`);const o=this.deltas.get(t)??0;this.deltas.set(t,o+n),this._updateTree(t,n)}return this.total}_updateTree(e,t){if(t===0)return;let n=e+1;for(;n<=this.size;){this.tree.set(n,(this.tree.get(n)??0)+t);const o=ft(n);if(o===0)break;n+=o}this.total!==void 0&&(this.total+=t)}_buildDeltaUpdates(e){const t=[];for(const{index:n,value:o}of e){if(n<0||n>=this.size)throw new Error(`Index ${n} out of bounds`);if(o<0)throw new Error("Value cannot be negative.");const c=this.deltas.has(n)?(this.deltas.get(n)??0)+this.baseValue:this.baseValue,u=o-c;u!==0&&t.push({index:n,change:u})}return t}_computeTreeTotal(){if(this.size<=0)return 0;let e=0,t=this.size;for(;t>0;){e+=this.tree.get(t)??0;const n=ft(t);if(n===0)break;t-=n}return e+this.baseValue*this.size}_materialize(e,t=!0){if(this.valueFn){const n=this.deltas.get(e)??0,c=this.valueFn(e)-this.baseValue;if(c!==n&&(this.deltas.set(e,c),t)){const u=c-n;this._updateTree(e,u)}}}_materializeRanges(e,t,n=!1){if(!(e?.materialize&&this.valueFn))return;const o=e.ranges;if(o&&o.length>0){for(const d of o){const m=d.from,h=Math.min(d.to,this.size-1);for(let p=m;p<=h;p++)this._materialize(p)}if(t===void 0)return;if(n){this._materialize(t);return}const c=o[0].from,u=o[o.length-1].to;t>=c&&t<=u&&this._materialize(t);return}t!==void 0&&this._materialize(t)}_findIndex(e,t={},n){if(this.size>2147483647)return this._findIndexLarge(e,t,n);if(this.size===0)return{index:-1,total:this.total??0,cumulative:void 0,currentValue:void 0,safeIndex:void 0};let o=0,c=0,u=1;for(;u<<1<=this.size;)u<<=1;for(;u>0;u>>=1){const h=o+u;if(h<=this.size){const b=(this.tree.get(h)??0)+this.baseValue*u;(n?c+b<e:c+b<=e)&&(o=h,c+=b)}}const d=n?o:o-1;if(d<0||d>=this.size)return{index:-1,total:this.total??this.getTotal(),cumulative:void 0,currentValue:void 0,safeIndex:void 0};const m=this.prefixSum(d,t);return{index:d,total:this.total??m.total,cumulative:m.cumulative,currentValue:m.currentValue,safeIndex:m.safeIndex}}_findIndexLarge(e,t,n){if(this.size===0)return{index:-1,total:this.total??0,cumulative:void 0,currentValue:void 0,safeIndex:void 0};const o=er(this.size);if(o===0n)return{index:-1,total:this.total??0,cumulative:void 0,currentValue:void 0,safeIndex:void 0};let c=0n,u=o-1n,d,m,h,p=this.total;for(;c<=u;){const x=c+u>>1n,k=Number(x),X=this.prefixSum(k,t);if(h=X,p=X.total,n?X.cumulative>=e:X.cumulative<=e)if(d=x,m=X,n){if(x===0n)break;u=x-1n}else c=x+1n;else if(n)c=x+1n;else{if(x===0n)break;u=x-1n}}const b=m??h;return{index:d!==void 0?Number(d):-1,total:p,cumulative:b?.cumulative,currentValue:b?.currentValue,safeIndex:b?.safeIndex}}prefixSum(e,t){if(e<0)return{cumulative:0,total:this.total,currentValue:0,safeIndex:0};const n=fe(e,0,this.size-1),o=t?.materializeOption;this._materializeRanges(o,n,!0);let c=0,u=n+1;for(;u>0;){const m=this.tree.get(u)??0;c+=m;const h=ft(u);if(h===0)break;u-=h}const d=o?.materialize?this.get(n):(this.deltas.get(n)||0)+this.baseValue;return{cumulative:c+this.baseValue*(n+1),total:this.total,currentValue:d,safeIndex:n}}get(e,t){if(e<0||e>=this.size)throw new Error("Index out of bounds");const n=t?.materializeOption;return this._materializeRanges(n,e),(this.deltas.get(e)??0)+this.baseValue}getTotal(e){const t=e?.materializeOption;if(this._materializeRanges(t),this.total===void 0)if(this.size===0)this.total=0;else{this.total=this._computeTreeTotal();const n=this.prefixSum(this.getSize()-1);n.cumulative!==n.total&&N.error("Inconsistent Fenwick Tree state")}return this.total}rebuildTree(e){if(e?.materialize&&this.valueFn){const n=this.valueFn;this.reset(this.size,o=>n(o),{materialize:!0});return}const t=new Map;for(const[n,o]of this.deltas.entries()){if(o===0)continue;let c=n+1;for(;c<=this.size;){t.set(c,(t.get(c)??0)+o);const u=ft(c);if(u===0)break;c+=u}}this.tree=t,this.total=this._computeTreeTotal()}calculateAccumulatedError(){if(this.total===void 0)return 0;let e=this.baseValue*this.size;for(const t of this.deltas.values())e+=t;return this.total-e}changeSize(e){const t=this.size;if(e===t)return;if(e<t)for(const o of this.deltas.keys())o>=e&&this.deltas.delete(o);this.size=e,this.rebuildTree();const n=this.prefixSum(this.getSize()-1);n.cumulative!==n.total&&N.error("Inconsistent Fenwick Tree state")}getSize(){return this.size}findIndexAtOrAfter(e,t){return this._findIndex(e,t??{},!0)}findIndexAtOrBefore(e,t){return this._findIndex(e,t??{},!1)}}const kt=(s,e,t)=>{const n=Math.max(0,s),o=r.useRef(null),c=r.useRef({size:n,valueOrFn:e,options:t});o.current===null&&(o.current=new Et(n,e,t));const u=o.current,d=c.current,m=d.size!==n,h=d.valueOrFn!==e,p=d.options!==t;if(h||p){const b=t?.resetOnValueFnChange??!0;p||h&&b?(t?.debug&&N.debug("[useFenwickMapTree] reset",{valueOrFnChanged:h,optionsChanged:p}),u.reset(n,e,t)):(m&&(t?.debug&&N.debug("[useFenwickMapTree] resize (with valueFn change)",{from:d.size,to:n}),u.changeSize(n)),t?.debug&&N.debug("[useFenwickMapTree] setValueFn (no reset)",{valueOrFnChanged:h}),u.setValueFn(e,{reset:!1})),c.current={size:n,valueOrFn:e,options:t}}else m&&(t?.debug&&N.debug("[useFenwickMapTree] resize",{from:d.size,to:n}),d.size===0&&n>0?u.reset(n,e,t):u.changeSize(n),c.current={size:n,valueOrFn:e,options:t});return u};class tr{key;value;prev=null;next=null;constructor(e,t){this.key=e,this.value=t}}class Mt{head=null;tail=null;addToTail(e){this.tail?(this.tail.next=e,e.prev=this.tail,this.tail=e):this.head=this.tail=e}remove(e){e.prev?e.prev.next=e.next:this.head=e.next,e.next?e.next.prev=e.prev:this.tail=e.prev,e.prev=null,e.next=null}removeHead(){const e=this.head;return e&&this.remove(e),e}moveToTail(e){this.remove(e),this.addToTail(e)}}function Vt(s){const e=r.useRef(new Map),t=r.useRef(new Mt);r.useEffect(()=>{for(;e.current.size>s;){const p=t.current.removeHead();if(p)e.current.delete(p.key);else break}},[s]);const n=r.useCallback(p=>{const b=e.current.get(p);if(b)return t.current.moveToTail(b),b.value},[]),o=r.useCallback((p,b)=>{if(s<=0)return;let E=e.current.get(p);if(E)E.value=b,t.current.moveToTail(E);else{if(e.current.size>=s){const x=t.current.removeHead();x&&e.current.delete(x.key)}E=new tr(p,b),e.current.set(p,E),t.current.addToTail(E)}},[s]),c=r.useCallback(p=>e.current.has(p),[]),u=r.useCallback(p=>{const b=e.current.get(p);b&&(t.current.remove(b),e.current.delete(p))},[]),d=r.useCallback(()=>{e.current.clear(),t.current=new Mt},[]),[m,h]=r.useState(()=>({get:n,set:o,has:c,remove:u,clear:d}));return r.useEffect(()=>h({get:n,set:o,has:c,remove:u,clear:d}),[n,o,c,u,d]),m}const rr=1e4,nr=()=>{const{get:s,set:e,has:t,clear:n}=Vt(rr);return{get:s,set:e,has:t,clear:n}},te=(s,e)=>e<=0?0:fe(s,0,e-1),Pt=s=>({top:Math.max(0,s?.top??0),bottom:Math.max(0,s?.bottom??0)}),Ue=(s,e)=>s<=e?0:s-e,tt=(s,e)=>s<=0?e:s+e,gt=s=>{if(!Number.isFinite(s))return 0n;const e=Math.trunc(s);return e<=0?0n:BigInt(e)},sr=(s,e,t,n,o,c,u,d)=>{const m=gt(n);if(m===0n)return{renderingStartIndex:0,renderingEndIndex:0,visibleStartIndex:0,visibleEndIndex:0};const h=Y=>Y<0n?0n:Y>=m?m-1n:Y,p={materializeOption:{materialize:!1}},{index:b,cumulative:E}=c.findIndexAtOrAfter(s,p);let x;b===-1?x=m-1n:(E===s?x=gt(b+1):x=gt(b),x>=m&&(x=m-1n)),s<=0&&(x=0n),d&&s>=u&&(x=m-1n);const k=Y=>{let J=0,w=Y,j=Y,K=0n;for(;w<m&&J<e;){const xe=Number(w),_=o(xe);if(J+=_,j=w,w+=1n,K+=1n,!Number.isFinite(_)||_<=0)break}return K===0n&&(j=Y),{height:J,end:j}};let{height:X,end:q}=k(x);if(X<e&&x>0n){let Y=x,J=X;for(;Y>0n&&J<e;){Y-=1n;const j=Number(Y),K=o(j);if(J+=K,!Number.isFinite(K)||K<=0)break}x=h(Y);const w=k(x);X=w.height,q=w.end}const Z=h(x),ge=h(q),oe=h(Z-BigInt(Math.max(0,t))),re=h(ge+BigInt(Math.max(0,t)));return{renderingStartIndex:te(Number(oe),n),renderingEndIndex:te(Number(re),n),visibleStartIndex:te(Number(Z),n),visibleEndIndex:te(Number(ge),n)}},ir=(s,e,t,n,o,c,u)=>{if(n===0)return{renderingStartIndex:0,renderingEndIndex:0,visibleStartIndex:0,visibleEndIndex:0};const d=Number.isFinite(u),m=d?Math.min(Math.max(0,s),u):Math.max(0,s);if(n>=Number.MAX_SAFE_INTEGER)return sr(m,e,t,n,o,c,u,d);const{index:h,cumulative:p,currentValue:b}=c.findIndexAtOrAfter(m,{materializeOption:{materialize:!1}}),E=h===-1?e<=0||(p??0)<m+(b??0)?n-1:0:h;let x=te(E,n),k=0;if(h!==-1&&p===m)x=te(h+1,n),k=0;else if(x===h&&p!==void 0&&b!==void 0)k=p-b-m;else{const{cumulative:re,currentValue:Y}=c.prefixSum(x,{materializeOption:{materialize:!1}});k=(re??0)-(Y??0)-m}const X=k;let q=x;for(;q<n&&k<e;)k+=o(q),q++;if(k<e&&x>0){let re=k+Math.abs(Math.min(0,X)),Y=x-1;for(;Y>=0&&re<e;)re+=o(Y),Y--;for(x=te(Y+1,n),k=0,q=x;q<n&&k<e;)k+=o(q),q++}const Z=te(x-t,n),ge=te(Math.max(q-1,x),n),oe=te(ge+t,n);return{renderingStartIndex:Z,renderingEndIndex:oe,visibleStartIndex:x,visibleEndIndex:ge}},Rt=(s,e,t)=>{const n=Math.max(0,e??0),o=r.useRef({last:0,id:null,arg:null}).current;return r.useEffect(()=>()=>{o.id!==null&&(cancelAnimationFrame(o.id),o.id=null)},[o]),r.useCallback(c=>{if(o.arg=c,o.id!==null)return;const u=d=>{if(o.id=null,o.arg===null)return;const m=d-o.last;if(n===0||o.last===0||m>=n){if(s.current)try{t(s.current,o.arg)}catch(h){console.error("[useThrottledInvoker] Error invoking callback",h)}o.arg=null,o.last=d}o.arg!==null&&(o.id=requestAnimationFrame(u))};o.id=requestAnimationFrame(u)},[n,t,s,o])},or=r.memo(({index:s,top:e,height:t,item:n,children:o,clipItemHeight:c,enableKeyboardNavigation:u,onKeyDown:d,onFocus:m,registerItemRef:h})=>{const p=r.useCallback(k=>h(s,k),[s,h]),b=r.useCallback(k=>d(k,s),[s,d]),E=r.useCallback(()=>m(s),[s,m]),x=r.useCallback(k=>{k.currentTarget.focus({preventScroll:!0})},[]);return F.jsx("div",{ref:p,"data-index":s,"data-virtualscroll-item":"true",className:"aqvs-item-container",style:{top:e,height:t,overflow:c?"hidden":void 0},tabIndex:u?-1:void 0,onPointerDown:u?x:void 0,onKeyDownCapture:u?b:void 0,onFocusCapture:u?E:void 0,children:o(n,s)})}),ar=({itemCount:s,getItem:e,getItemKey:t,getItemHeight:n,viewportSize:o,overscanCount:c=15,className:u,onScroll:d,onRangeChange:m,children:h,background:p,initialScrollIndex:b,initialScrollOffset:E,callbackThrottleMs:x=5,contentInsets:k,onItemFocus:X,scrollBarOptions:q,behaviorOptions:Z},ge)=>{const{width:oe,enableThumbDrag:re,enableTrackClick:Y,enableArrowButtons:J,enableScrollToTopBottomButtons:w,renderThumbOverlay:j,tapScrollCircleOptions:K}=q??{},{enablePointerDrag:xe,enableKeyboardNavigation:_=!0,wheelSpeedMultiplier:V,inertiaOptions:W,clipItemHeight:G=!1,resetOnGetItemHeightChange:U=!1}=Z??{},L=r.useRef(null),ve=r.useRef({renderingStartIndex:0,renderingEndIndex:0,visibleStartIndex:0,visibleEndIndex:0,scrollPosition:0,totalHeight:0}),ae=r.useRef(null),be=r.useRef(!1);r.useEffect(()=>{U&&(ae.current=null)},[U]);const I=r.useMemo(()=>Pt(k),[k]),Se=r.useMemo(()=>({sampleRange:{from:0,to:100},resetOnValueFnChange:U,materialize:!0}),[U]),v=kt(s,n,Se),[Te]=r.useState(()=>{let i=I.top,l=0;if(typeof b=="number"){const f=fe(b,0,s-1),P=fe(f-c*2,0,s-1),R=fe(f+c*2,0,s-1),y=b>0?{materializeOption:{materialize:!0,ranges:[{from:P,to:R}]}}:void 0,{cumulative:z,total:B,currentValue:O}=v.prefixSum(b,y),H=Math.max(z-O,0);i=tt(H,I.top),l=B??v.getTotal()}else typeof E=="number"&&(i=tt(Math.max(E,0),I.top)),l=v.getTotal();return{position:i,total:l}}),[Me,Le]=r.useState(Te.position),[T,A]=r.useState(Te.total),D=r.useRef(Te.position),Q=r.useRef(I.top),le=r.useRef(d??void 0),Ee=r.useRef(m??void 0),de=r.useRef(new Map),ne=r.useRef(null),se=r.useRef(null),[Ce,ye]=r.useState(null),[Pe,we]=r.useState(!1),ze=r.useRef(null),me=r.useRef(!1),g=r.useRef(0),M=r.useRef(!1),$=r.useRef(s);$.current!==s&&($.current=s,M.current=!0),r.useEffect(()=>{le.current=d??void 0,Ee.current=m??void 0},[m,d]);const ie=r.useCallback(i=>{if(_&&i&&typeof i.focus=="function")try{i.focus({preventScroll:!0})}catch{i.focus()}},[_]),ce=r.useCallback((i,{position:l,totalHeight:f})=>{i(l,f)},[]),Fe=Rt(le,x,ce),ue=r.useCallback((i,l)=>{i(l)},[]),_e=Rt(Ee,x,ue);r.useEffect(()=>(be.current=!0,()=>{be.current=!1}),[]),r.useEffect(()=>{_||(de.current.clear(),ne.current=null,se.current=null)},[_]);const $e=r.useCallback((i,l)=>{if(!l){de.current.delete(i);return}_&&(de.current.set(i,l),ne.current===i&&(ne.current=null,se.current=i,ie(l)))},[_,ie]),ke=.01,qe=r.useRef({rafId:null,loopActive:!1,idleFrames:0,lastRenderedPosition:Te.position}),Ie=r.useCallback(()=>{const i=qe.current;i.rafId!==null&&typeof cancelAnimationFrame=="function"&&cancelAnimationFrame(i.rafId),i.rafId=null,i.loopActive=!1,i.idleFrames=0},[]);r.useEffect(()=>()=>{Ie()},[Ie]);const Re=r.useCallback(()=>{const i=qe.current;i.rafId=null;const l=D.current,f=Ue(l,I.top),P=v.getTotal();if(Le(y=>Math.abs(y-l)<ke?y:l),Fe({position:f,totalHeight:P}),Math.abs(i.lastRenderedPosition-l)>=ke?(i.lastRenderedPosition=l,i.idleFrames=0):i.idleFrames+=1,i.idleFrames>=2){Ie();return}if(typeof requestAnimationFrame=="function"){i.rafId=requestAnimationFrame(Re);return}i.loopActive=!1},[v,I.top,Fe,Ie]),We=r.useCallback(()=>{const i=qe.current;if(i.idleFrames=0,!i.loopActive){if(i.loopActive=!0,typeof requestAnimationFrame=="function"){i.rafId=requestAnimationFrame(Re);return}i.loopActive=!1}},[Re]),ee=r.useCallback((i,l)=>{const f=l?.immediate??!1,P=Ue(i,I.top);if(D.current=i,f){qe.current.lastRenderedPosition=i,qe.current.idleFrames=0,Le(i),Fe({position:P,totalHeight:v.getTotal()});return}We()},[We,v,I.top,Fe]),ot=r.useRef(!1);r.useEffect(()=>{if(!ot.current)if(ot.current=!0,typeof E=="number"){const i=tt(Math.max(E,0),I.top),l=Math.abs(i-D.current)>.5;ee(i,{immediate:!0}),l&&L.current?.scrollTo(i)}else ee(D.current,{immediate:!0})},[E,I.top,ee]),r.useEffect(()=>{const i=v.getTotal();T!==i&&A(i)},[v,T,s]),r.useEffect(()=>{if(ae.current!==null){const{index:i,align:l,offset:f}=ae.current,P=te(i,s),{cumulative:R,currentValue:y}=v.prefixSum(P,{materializeOption:{materialize:!1}});if(R!==void 0&&y!==void 0){const z=Math.max(R-y,0);let B=z;l==="bottom"?B=R-o:l==="center"&&(B=z+y/2-o/2),f&&(B-=f),B=Math.max(0,B);const O=Math.max(0,T+I.top+I.bottom-o),H=Math.min(tt(B,I.top),O);Math.abs(H-D.current)>1&&(N.debug("[VirtualScroll] Drift correction",{from:D.current,to:H,targetIndex:P}),g.current===0&&(g.current+=1),L.current?.scrollTo(H),ee(H,{immediate:!0}))}}M.current=!1},[T,v,s,I.top,ee,o,I.bottom]),r.useEffect(()=>{const i=Q.current;if(i===I.top)return;const l=Ue(D.current,i),f=tt(l,I.top);Q.current=I.top,D.current=f,L.current?.scrollTo(f),ee(f,{immediate:!0})},[I.top,ee]);const rt=r.useCallback((i,l)=>{const f=te(i,s),P=v.get(f),R=l-P,y=v.update(f,l);y!==void 0&&A(y),N.debug("[VirtualScroll] Updated item size manually",{index:f,size:l,total:y});let z=ae.current?ae.current.index:null;if(z===null){const B=D.current,O=Pt(k).top,H=Ue(B,O),{index:pe}=v.findIndexAtOrAfter(H,{materializeOption:{materialize:!1}});z=pe}if(z!==-1&&f<z&&R!==0){const B=D.current,O=B+R;g.current+=1,ee(O,{immediate:!0}),L.current?.scrollTo(O),N.debug("[VirtualScroll] Adjusted scroll for layout shift (manual update)",{from:B,to:O,causedByIndex:f,delta:R,activeVisibleStartIndex:z})}},[v,s,ee,k]),Ve=r.useCallback((i,l)=>{if(!L.current)return;const f=te(i,s),P=te(f-c*2,s),R=te(f+c*2,s),{cumulative:y,total:z,currentValue:B}=v.prefixSum(f,{materializeOption:{materialize:!0,ranges:[{from:P,to:R}]}});if(N.debug("[VirtualScroll] Scrolling to index:",f,"ItemBottom:",y,"Total height:",z,"ItemHeight:",B,"safeIndexFrom:",P,"safeIndexTo:",R),!z)return;const O=Math.max(y-B,0);let H=O;l?.align==="bottom"?H=y-o:l?.align==="center"&&(H=O+B/2-o/2),l?.offset&&(H-=l.offset),H=Math.max(0,H);const pe=tt(H,I.top),he=L.current?.getContentSize()??z+I.top+I.bottom,Ne=Math.max(0,he-o),Ke=Math.min(pe,Ne);ae.current={index:f,align:l?.align,offset:l?.offset};const nt=L.current?.getScrollPosition()??-1,st=Math.abs(nt-Ke)>.5;me.current=!1,g.current=0,st&&(me.current=!0,g.current+=1,L.current?.scrollTo(Ke)),A(z),ee(Ke,{immediate:!0}),N.debug("[VirtualScroll] Setting scroll position to:",Ke,{original:pe,max:Ne})},[v,c,s,I.top,I.bottom,o,ee]),Je=r.useCallback(i=>{if(!L.current)return;const l=v.getTotal(),f=fe(Math.floor(i),0,l),{index:P,cumulative:R,currentValue:y}=v.findIndexAtOrAfter(f,{materializeOption:{materialize:!1}}),B=(R??0)-(y??0)-f;Ve(P,{offset:B})},[v,Ve]),Ge=r.useCallback(i=>{const l=Ue(D.current,I.top),f=typeof i=="function"?i(l):i;Je(f);const P=L.current?.getScrollPosition(),R=typeof P=="number"?P:D.current;return ee(R),R},[I.top,Je,ee]),dt=r.useCallback((i,l)=>{N.debug("[VirtualScroll] Scroll position changed:",i);const f=me.current;f&&(me.current=!1);const P=g.current>0;if(P&&(g.current=0),f||P||M.current||(ae.current=null),ee(i),w){if(f||P)return;const R=i-l;if(N.debug("[VirtualScroll] Scroll diff:",R,"New:",i,"Prev:",l),Math.abs(R)>1){const y=R>0?"down":"up";ye(y),we(!0),N.debug("[VirtualScroll] Showing scroll buttons. Direction:",y),ze.current&&clearTimeout(ze.current),ze.current=setTimeout(()=>{we(!1),N.debug("[VirtualScroll] Hiding scroll buttons")},2e3)}}},[ee,w]),Oe=r.useMemo(()=>Ue(Me,I.top),[I.top,Me]),Ae=r.useMemo(()=>{const i=v.getTotal(),l=ir(Oe,o,c,s,n,v,i);return N.debug("[VirtualScroll] Calculated rendering range:",{...l,scrollPosition:Oe,renderingContentSize:i,overscanCount:c,viewportSize:o}),l},[Oe,o,c,s,n,v]),{renderingStartIndex:He,renderingEndIndex:Be,visibleStartIndex:De,visibleEndIndex:Xe}=Ae,je=r.useCallback((i,l)=>{if(!_||s===0)return;const f=te(i,s);if(!(l?.ensureVisible??!0)){const Ne=de.current.get(f);Ne&&(ne.current=null,se.current=f,ie(Ne));return}const R=v.prefixSum(f,{materializeOption:{materialize:!1}}),y=R.currentValue,z=Math.max(R.cumulative-y,0),B=z+y,O=Ue(D.current,I.top),H=O+o;if(z<O||B>H){ne.current=f,Ve(f);return}const he=de.current.get(f);if(he){ne.current=null,se.current=f,ie(he);return}ne.current=f},[_,s,v,I.top,Ve,ie,o]),at=r.useCallback((i,l)=>{if(!_||i.defaultPrevented||i.altKey||i.metaKey||i.ctrlKey)return;const f=i.target;if(f){const P=f.tagName;if(P==="INPUT"||P==="TEXTAREA"||P==="SELECT"||f.isContentEditable)return}if(i.key==="ArrowDown"){l<s-1&&(i.preventDefault(),je(l+1));return}if(i.key==="ArrowUp"){l>0&&(i.preventDefault(),je(l-1));return}if(i.key==="PageDown"){if(l<s-1){i.preventDefault();const P=Math.max(Xe-De+1,1),R=Math.max(P,1),y=te(Math.min(l+R,s-1),s);je(y)}return}if(i.key==="PageUp"&&l>0){i.preventDefault();const P=Math.max(Xe-De+1,1),R=Math.max(P,1),y=te(l-R,s);je(y)}},[_,s,je,Xe,De]),lt=r.useCallback(i=>{if(!_)return;const l=te(i,s);ne.current=null,se.current=l,X?.(l)},[_,s,X]);r.useEffect(()=>{const i=L.current?.getScrollPosition()??0,l=D.current,f=Ue(l,I.top);N.debug("[VirtualScroll] Range change effect triggered",{renderingStartIndex:He,renderingEndIndex:Be,visibleStartIndex:De,visibleEndIndex:Xe,scrollPositionState:Me,paneScrollPosition:l,logicalScrollPosition:f,contentSize:T,scrollPaneScrollPosition:i}),_e({renderingStartIndex:He,renderingEndIndex:Be,visibleStartIndex:De,visibleEndIndex:Xe,scrollPosition:f,totalHeight:T})},[T,Be,He,I.top,_e,Me,Xe,De]);const mt=r.useCallback(()=>{if(!w)return null;const i=Pe&&Ce!==null,l=Ce==="up";return F.jsx("div",{className:"aqvs-scroll-to-edge-overlay","data-visible":i,children:l?F.jsx("div",{className:"aqvs-scroll-to-edge-button-container aqvs-scroll-to-edge-button-container-top",children:F.jsx("button",{type:"button",className:"aqvs-scroll-to-edge-button",onClick:f=>{f.stopPropagation(),me.current=!0,Ve(0),we(!1)},children:"Top"})}):F.jsx("div",{className:"aqvs-scroll-to-edge-button-container aqvs-scroll-to-edge-button-container-bottom",children:F.jsx("button",{type:"button",className:"aqvs-scroll-to-edge-button",onClick:f=>{f.stopPropagation(),me.current=!0,Ve(s-1),we(!1)},children:"Bottom"})})})},[w,Pe,Ce,Ve,s]),{visibleItems:Qe,startPosition:et}=r.useMemo(()=>{if(s===0)return{visibleItems:F.jsx("div",{className:"aqvs-no-items-container",children:F.jsx("div",{className:"aqvs-no-items-text",children:"No items"})}),startPosition:0};const i=te(He,s),l=te(Be,s),{cumulative:f,currentValue:P}=v.prefixSum(i,{materializeOption:{materialize:!1}}),R=f-P,y=[],z=[];let B=0;for(let O=i;O<=l;O++){const H=n(O),pe=v.get(O),he=H-pe;he!==0&&y.push({index:O,value:H});const{cumulative:Ne,currentValue:Ke}=v.prefixSum(O,{materializeOption:{materialize:!1}}),nt=Ne-Ke+B,st=t?t(O):O;z.push(F.jsx(or,{index:O,top:nt-R+I.top,height:H,item:e(O),clipItemHeight:G,enableKeyboardNavigation:_,onKeyDown:at,onFocus:lt,registerItemRef:$e,children:h},st)),B+=he}return y.length>0&&Promise.resolve().then(()=>{if(!be.current)return;let O=0;for(const he of y)if(he.index<De){const Ne=v.get(he.index);O+=he.value-Ne}const H=v.updates(y);if(!be.current||typeof H!="number")return;A(H),N.debug("[VirtualScroll] Updated heights for items",y,"New total height:",H);const pe=L.current?.getScrollPosition()??D.current;if(O!==0){const he=pe+O;g.current+=1,ee(he,{immediate:!0}),L.current?.scrollTo(he),N.debug("[VirtualScroll] Adjusted scroll for layout shift (auto update)",{from:pe,to:he,shiftAmount:O})}else pe!==D.current&&ee(pe)}),{visibleItems:z,startPosition:R}},[h,G,_,s,v,e,t,n,lt,at,$e,Be,He,I.top,ee,De]),a=r.useCallback(i=>{const l=(x??0)>0,f=Math.abs(i-Me),P=l&&f>.5?Me:i,R=Ue(P,I.top);if(N.debug("[VirtualScroll] Rendering visible items",{currentScrollPosition:i,effectiveScrollPosition:R,renderingStartIndex:He,renderingEndIndex:Be,itemCount:s,viewportSize:o,callbackThrottleMs:x,diff:f,rawEffectiveScrollPosition:P}),s===0)return Qe;const y=et-R,z=I.bottom>0?F.jsx("div",{className:"aqvs-bottom-inset",style:{top:v.getTotal()+I.top-et,height:I.bottom}},"virtualscroll-bottom-inset"):null;return N.debug("[VirtualScroll] Rendering items",{containerTop:y,logicalScrollPosition:Oe,resolvedInsets:I,effectiveScrollPosition:R}),F.jsxs("div",{className:"aqvs-items-wrapper",style:{top:y,position:"relative"},children:[Qe,z]})},[x,s,v,Oe,Be,He,I,Me,et,o,Qe]),S=r.useMemo(()=>({renderingStartIndex:Ae.renderingStartIndex,renderingEndIndex:Ae.renderingEndIndex,visibleStartIndex:Ae.visibleStartIndex,visibleEndIndex:Ae.visibleEndIndex,scrollPosition:Oe,totalHeight:v.getTotal()}),[Ae,Oe,v]);r.useEffect(()=>{ve.current=S},[S]),r.useImperativeHandle(ge,()=>({getScrollPosition:()=>L.current?.getScrollPosition()??-1,getContentSize:()=>L.current?.getContentSize()??-1,getViewportSize:()=>L.current?.getViewportSize()??-1,scrollTo:Ge,scrollToIndex:Ve,getFenwickTreeTotalHeight:()=>v.getTotal(),getFenwickSize:()=>v.getSize(),focusItemAtIndex:je,getRange:()=>ve.current,updateItemSize:rt}),[Ge,Ve,v,je,rt]);const C=v.getTotal()+I.top+I.bottom;return F.jsx(wt,{ref:L,contentSize:C,viewportSize:o,className:u,onScroll:dt,background:p,tapScrollCircleOptions:K,inertiaOptions:W,itemCount:s,scrollBarWidth:oe,enableThumbDrag:re,enableTrackClick:Y,enableArrowButtons:J,enablePointerDrag:xe,renderThumbOverlay:j,wheelSpeedMultiplier:V,contentInsets:I,visibleStartIndex:De,visibleEndIndex:Xe,renderOverlay:mt,initialScrollPosition:Te.position,children:a})},lr=r.forwardRef(ar);exports.FenwickMapTree=Et;exports.ScrollBar=yt;exports.ScrollPane=wt;exports.VirtualScroll=lr;exports.minmax=fe;exports.tapScrollCircleSampleVisual=Qt;exports.useFenwickMapTree=kt;exports.useHeightCache=nr;exports.useLruCache=Vt;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const F=require("react/jsx-runtime"),r=require("react"),Je=require("tailwind-merge");class N{level;prefix;impl;constructor(e=2,t="[virtualscroll]",n=console){this.level=e,this.prefix=t,this.impl=n}static instance=new N(2,"[virtualscroll]");static setLevel(e){N.instance.setLevel(e)}setLevel(e){this.level=e}static setImplementation(e){N.instance.setImplementation(e)}setImplementation(e){this.impl=e}static setPrefix(e){N.instance.setPrefix(e)}setPrefix(e){this.prefix=e}formatMessage(e){return typeof e=="string"?[`${this.prefix} ${e}`]:[this.prefix,e]}static debug(e,...t){N.instance.debug(e,...t)}debug(e,...t){this.level<=0&&this.impl.debug(...this.formatMessage(e),...t)}static info(e,...t){N.instance.info(e,...t)}info(e,...t){this.level<=1&&this.impl.info(...this.formatMessage(e),...t)}static warn(e,...t){N.instance.warn(e,...t)}warn(e,...t){this.level<=2&&this.impl.warn(...this.formatMessage(e),...t)}static error(e,...t){N.instance.error(e,...t)}error(e,...t){this.level<=3&&this.impl.error(...this.formatMessage(e),...t)}}const It={active:!1,offsetX:0,offsetY:0,distance:0,direction:0,pointerId:null},ht=6,Ot=8,Yt=({dragState:s,normalizedDistance:e})=>{const t=1+e*.18,n=.16+e*.24,i=.38+e*.28,c=s.active?"80ms ease-out":"220ms ease";return F.jsxs(F.Fragment,{children:[F.jsx("div",{className:"aqvs-tap-scroll-circle-visual-outer",style:{background:"linear-gradient(140deg, rgba(255,255,255,0.62), rgba(72,72,72,0.48))",boxShadow:`0 0 0 1px rgba(255,255,255,0.28), 0 10px 22px rgba(0,0,0,${n})`,transform:`scale(${t})`,transition:`${c}, ${s.active?"80ms":"260ms"} box-shadow ease`}}),F.jsx("div",{className:"aqvs-tap-scroll-circle-inner",style:{background:"linear-gradient(140deg, rgba(255,255,255,0.72), rgba(28,28,28,0.58))",boxShadow:"inset 0 4px 10px rgba(0,0,0,0.24), inset 0 0 2px rgba(255,255,255,0.55)",opacity:i,transition:s.active?"120ms opacity ease-out":"220ms opacity ease"}})]})},yt=r.memo(r.forwardRef(({onDragChange:s,className:e,maxVisualDistance:t=160,size:n=40,style:i,opacity:c=1,renderVisual:u},d)=>{const[m,g]=r.useState(It),p=r.useRef(null),b=r.useRef({x:0,y:0}),A=r.useRef(null),x=r.useRef(0),D=r.useCallback(T=>{g(T),s(T)},[s]),X=r.useCallback((T,U,Te=!1)=>{const{x:Ee,y:se}=b.current,k=T-Ee,K=U-se,ce=Math.abs(K),xe=ce<ht?0:K<0?-1:1,I=x.current;let Ve=xe;const S=ht+Ot;xe===0?I!==0&&ce<S?Ve=I:(Ve=0,Te||(x.current=0)):xe!==I&&I!==0&&ce<S?Ve=I:x.current=xe,D({active:Te||ce>=ht,offsetX:k,offsetY:K,distance:ce,direction:Ve,pointerId:p.current})},[D]),Y=r.useCallback(T=>{if(T===null)return;const U=A.current;U?.hasPointerCapture(T)&&U.releasePointerCapture(T)},[]),Z=r.useCallback((T=!1)=>{T&&Y(p.current),p.current=null,x.current=0,D(It)},[D,Y]),me=r.useCallback(T=>{T.preventDefault(),T.stopPropagation();const U=A.current??T.currentTarget,{left:Te,top:Ee,width:se,height:k}=U.getBoundingClientRect();b.current={x:Te+se/2,y:Ee+k/2},p.current=T.pointerId,U.setPointerCapture(T.pointerId),X(T.clientX,T.clientY,!0)},[X]),ae=r.useCallback(T=>{p.current===T.pointerId&&(T.preventDefault(),X(T.clientX,T.clientY))},[X]),ne=r.useCallback(T=>{p.current===T.pointerId&&(T.preventDefault(),T.stopPropagation(),Z(!0))},[Z]);r.useImperativeHandle(d,()=>({reset:()=>{Z(!0)},getElement:()=>A.current}),[Z]);const _=Math.min(Math.max(c,0),1),J=n/64,Q=Math.min(m.distance,t)/t,E=m.direction*Q*10*J,le=u??Yt,Ie={dragState:m,normalizedDistance:Q,sizeScale:J,size:n,opacity:_},pe={...i,width:n,height:n,transform:`translateY(${E}px)`};return pe.opacity=_,F.jsx("div",{ref:A,"data-testid":"virtual-scroll-tap-circle",className:Je.twMerge("aqvs-tap-scroll-circle",e),style:pe,tabIndex:-1,onPointerDown:me,onPointerMove:ae,onPointerUp:ne,onPointerCancel:ne,role:"presentation",children:le(Ie)})}));yt.displayName="TapScrollCircle";const de=(s,e,t)=>Math.min(t,Math.max(e,s)),xt="virtualscroll:tap-scroll-cancel",Tt=20,zt=250,qt=60,Ht=20,Xt=20,Bt=240,St={active:!1,offsetX:0,offsetY:0,distance:0,direction:0,pointerId:null},gt=2.2,jt=8,Ut=120,$t=1/60,ze={enabled:!0,size:40,offsetX:-80,offsetY:0,className:void 0,maxVisualDistance:Bt,minSpeedMultiplier:.2,opacity:.9,renderVisual:void 0,maxSpeedCurve:void 0},Kt=s=>s?{mainSizeKey:"width",crossSizeKey:"height",positionKey:"left",selectDelta:(e,t)=>e,getPointerCoordinate:({clientX:e})=>e,arrowLabels:["Scroll left","Scroll right"],arrowIcons:["◀","▶"],directionClass:"aqvs-scrollbar-horizontal",orientation:"horizontal"}:{mainSizeKey:"height",crossSizeKey:"width",positionKey:"top",selectDelta:(e,t)=>t,getPointerCoordinate:({clientY:e})=>e,arrowLabels:["Scroll up","Scroll down"],arrowIcons:["▲","▼"],directionClass:"aqvs-scrollbar-vertical",orientation:"vertical"},Wt=(s,e)=>{const t=s?.maxSpeedMultiplier,n=typeof t=="number"?t:Jt(e);return{enabled:s?.enabled??ze.enabled,size:s?.size??ze.size,offsetX:s?.offsetX??ze.offsetX,offsetY:s?.offsetY??ze.offsetY,className:s?.className??ze.className,maxVisualDistance:s?.maxVisualDistance??ze.maxVisualDistance,maxSpeedMultiplier:n,minSpeedMultiplier:Math.max(s?.minSpeedMultiplier??ze.minSpeedMultiplier,0),opacity:de(s?.opacity??ze.opacity,0,1),renderVisual:s?.renderVisual??ze.renderVisual,maxSpeedCurve:s?.maxSpeedCurve??ze.maxSpeedCurve}},Gt=({isDragging:s,isThumbHovered:e,enableThumbDrag:t})=>r.useMemo(()=>t?s?"dragging":e?"hover":"idle":"disabled",[t,s,e]),Zt=({canUseArrowButtons:s,enableArrowButtons:e,resetTapScroll:t,scrollByStep:n})=>{const i=r.useRef(null),c=r.useRef(null),u=r.useCallback(()=>{i.current!==null&&(window.clearInterval(i.current),i.current=null),c.current!==null&&(window.clearTimeout(c.current),c.current=null)},[]),d=r.useCallback(()=>{u()},[u]),m=r.useCallback(p=>b=>{s&&(b.cancelable&&b.preventDefault(),b.stopPropagation(),t(),u(),n(p),c.current=window.setTimeout(()=>{i.current=window.setInterval(()=>{n(p)},qt)},zt))},[s,u,t,n]),g=r.useCallback(p=>b=>{e&&(b.key==="Enter"||b.key===" "||b.key==="Spacebar")&&(b.preventDefault(),n(p))},[e,n]);return r.useEffect(()=>()=>{u()},[u]),{handleArrowPointerDown:m,handleArrowPointerUp:d,handleArrowKeyDown:g}},Jt=s=>{if(!s||s<=0)return gt;const e=Math.max(1,s),t=Math.log10(e),n=gt+t*jt;return de(n,gt,Ut)},wt=({contentSize:s,viewportSize:e,scrollPosition:t,onScroll:n,enableThumbDrag:i=!0,enableTrackClick:c=!0,enableArrowButtons:u=!0,horizontal:d=!1,scrollBarWidth:m=12,className:g,ariaControls:p,tapScrollCircleOptions:b,itemCount:A,renderThumbOverlay:x,visibleStartIndex:D,visibleEndIndex:X})=>{const[Y,Z]=r.useState(!1),[me,ae]=r.useState(!1),[ne,_]=r.useState(!1),J=r.useRef(null),Q=r.useRef({pointerId:null,startThumbPosition:0,startClientX:0,startClientY:0}),E=r.useRef({pointerId:null,startThumbPosition:0,startClientX:0,startClientY:0}),le=r.useRef(t),Ie=r.useRef(n),pe=r.useRef(St),T=r.useRef(null),U=r.useRef(null),Te=r.useRef(null),Ee=r.useMemo(()=>Wt(b,A),[A,b]),se=r.useMemo(()=>Kt(d),[d]),{enabled:k,size:K,offsetX:ce,offsetY:xe,className:I,maxVisualDistance:Ve,maxSpeedMultiplier:S,minSpeedMultiplier:ee,opacity:Ce,renderVisual:Ue,maxSpeedCurve:Se}=Ee,v=r.useRef({viewportSize:e,maxScrollPosition:Math.max(s-e,0),scrollBarVisible:s>e,effectiveTapMaxDistance:Math.max(Ve,1),tapCircleMaxSpeedMultiplier:S,tapCircleMinSpeedMultiplier:ee,tapCircleMaxSpeedCurve:Se,tapScrollCircleOptions:b,effectiveTrackLength:0,onScroll:n,scrollPosition:t}),{mainSizeKey:M,crossSizeKey:z,positionKey:ue,selectDelta:$,getPointerCoordinate:fe,arrowLabels:W,arrowIcons:G,directionClass:ge,orientation:Oe}=se,Me=Math.max(Ve,1),ve=e/s,ye=Math.max(e-m*2,0),Ae=ve*ye,ie=Math.min(Math.max(Tt,Ae||0),ye||Tt),h=s-e,P=Math.max(ye-ie,0),te=h<=0||P<=0?0:t/h*P,Ne=te+ie/2,q=s>e||Y,$e=q&&u;r.useLayoutEffect(()=>{v.current={viewportSize:e,maxScrollPosition:h,scrollBarVisible:q,effectiveTapMaxDistance:Me,tapCircleMaxSpeedMultiplier:S,tapCircleMinSpeedMultiplier:ee,tapCircleMaxSpeedCurve:Se,tapScrollCircleOptions:b,effectiveTrackLength:P,onScroll:n,scrollPosition:t}}),r.useLayoutEffect(()=>{le.current=t},[t]),r.useLayoutEffect(()=>{Ie.current=n},[n]),r.useEffect(()=>{i||ae(!1)},[i]);const De=Gt({isDragging:Y,isThumbHovered:me,enableThumbDrag:i}),Pe=r.useCallback((a,R)=>{const y=v.current,j=R??le.current;if(Ie.current){const C=Ie.current(a,j);if(typeof C=="number"&&Number.isFinite(C))return le.current=C,C}const o=typeof a=="function"?a(j):a,l=Math.max(y.maxScrollPosition,0),f=y.scrollBarVisible?de(o,0,l):0;return le.current=f,f},[]),Ye=r.useCallback(a=>{const R=v.current,y=le.current;if(!R.scrollBarVisible||R.maxScrollPosition<=0){const C=Pe(0,y),V=C-y;return{nextPosition:C,actualDelta:V,reachedBoundary:!0}}if(a===0)return{nextPosition:y,actualDelta:0,reachedBoundary:!1};const o=Pe(C=>de(C+a,0,R.maxScrollPosition),y),l=o-y,f=l===0||a<0&&o<=0||a>0&&o>=R.maxScrollPosition;return{nextPosition:o,actualDelta:l,reachedBoundary:f}},[Pe]),he=r.useCallback(()=>{U.current!==null&&(window.cancelAnimationFrame(U.current),U.current=null),Te.current=null},[]),Re=r.useCallback(()=>{pe.current={...St},_(!1),T.current?.reset(),he()},[he]),Ke=r.useCallback(a=>{const R=pe.current,y=v.current;if(!R.active||R.direction===0){he();return}if(!y.scrollBarVisible||y.maxScrollPosition<=0){he();return}const j=Te.current??a,o=Math.max((a-j)/1e3,0),l=Math.min(o,$t);if(Te.current=a,l<=0){U.current=window.requestAnimationFrame(Ke);return}const f=Math.min(R.distance,y.effectiveTapMaxDistance)/y.effectiveTapMaxDistance,C=f**1.1,V=typeof y.tapScrollCircleOptions?.maxSpeedMultiplier=="number",w=Math.max(y.viewportSize*y.tapCircleMinSpeedMultiplier,40),H=V?w:1200;let L=Math.max(y.viewportSize*y.tapCircleMaxSpeedMultiplier,H);const O=y.tapCircleMaxSpeedCurve;if(O){const ft=Math.max(O.exponentialSteepness,0),Nt=Math.max(O.exponentialScale??y.tapCircleMaxSpeedMultiplier,0),Lt=ft===0?f:Math.expm1(ft*f),vt=ft===0?1:Math.expm1(ft)||1,Ft=vt===0?f:Math.min(Math.max(Lt/vt,0),1),_t=y.viewportSize*Nt*Ft;L=Math.min(L,Math.max(_t,w))}const we=Math.max(L,w),be=Math.max(O?.easedOffset??0,0),_e=Math.min(1,C+be),Ge=w+(we-w)*_e,st=R.direction*Ge*l,{actualDelta:it,reachedBoundary:Dt}=Ye(st);if(Dt||it===0){he();return}U.current=window.requestAnimationFrame(Ke)},[Ye,he]),tt=r.useCallback(()=>{U.current===null&&(Te.current=null,U.current=window.requestAnimationFrame(Ke))},[Ke]);r.useEffect(()=>()=>{he()},[he]);const oe=r.useCallback(a=>{pe.current=a,_(a.active),a.active&&a.direction!==0?tt():he()},[tt,he]);r.useEffect(()=>{k||Re()},[Re,k]),r.useEffect(()=>{const a=R=>{const j=R.detail?.paneId;j&&p&&j!==p||Re()};return window.addEventListener(xt,a),()=>{window.removeEventListener(xt,a)}},[p,Re]),r.useEffect(()=>{if(!k)return;const a=R=>{if(!pe.current.active||pe.current.pointerId===R.pointerId)return;const y=R.target;if(!(y instanceof Node)){Re();return}T.current?.getElement()?.contains(y)||Re()};return document.addEventListener("pointerdown",a,!0),()=>{document.removeEventListener("pointerdown",a,!0)}},[Re,k]);const rt=a=>{if(!q||P<=0||h<=0)return 0;const R=de(a,0,P);return de(R/P*h,0,h)},nt=r.useCallback(a=>{const{scrollBarVisible:R,effectiveTrackLength:y,maxScrollPosition:j}=v.current;if(N.debug("[ScrollBar] calculateScrollPositionFromThumb",{thumbPos:a,trackLen:y,maxScroll:j}),y<=0||j<=0)return null;const o=de(a,0,y);return de(o/y*j,0,j)},[]),ke=r.useCallback(a=>{const R=Q.current;if(R.pointerId!==a.pointerId)return;const y=a.clientX-R.startClientX,j=a.clientY-R.startClientY,o=$(y,j);N.debug("[ScrollBar] handleThumbPointerMove",{delta:o,startThumbPosition:R.startThumbPosition,clientY:a.clientY,startClientY:R.startClientY,metrics:v.current});const l=nt(R.startThumbPosition+o);l!==null&&Pe(l),a.cancelable&&a.preventDefault()},[$,nt,Pe]),Ze=r.useCallback(a=>{if(Q.current.pointerId===a.pointerId)if(document.removeEventListener("pointermove",ke),document.removeEventListener("pointerup",Ze),document.removeEventListener("pointercancel",Ze),Q.current={pointerId:null,startThumbPosition:0,startClientX:0,startClientY:0},Z(!1),J.current){const y=J.current.getBoundingClientRect();a.clientX>=y.left&&a.clientX<=y.right&&a.clientY>=y.top&&a.clientY<=y.bottom||ae(!1)}else ae(!1)},[ke]),at=a=>{const R=Math.max(Math.round(e/Xt),Ht);Ye(a*R)},{handleArrowPointerDown:pt,handleArrowPointerUp:Le,handleArrowKeyDown:We}=Zt({canUseArrowButtons:$e,enableArrowButtons:u,resetTapScroll:Re,scrollByStep:at}),qe=a=>{if(q){if(!i){a.preventDefault(),a.stopPropagation();return}a.pointerType==="mouse"&&a.button!==0||a.ctrlKey||(Re(),Q.current={pointerId:a.pointerId,startThumbPosition:te,startClientX:a.clientX,startClientY:a.clientY},document.addEventListener("pointermove",ke),document.addEventListener("pointerup",Ze),document.addEventListener("pointercancel",Ze),Z(!0),ae(!0),a.preventDefault(),a.stopPropagation())}},He=a=>{if(!q)return;if(!c){a.preventDefault(),a.stopPropagation();return}if(a.pointerType==="mouse"&&a.button!==0||a.ctrlKey)return;const R=a.currentTarget,y=R.getBoundingClientRect(),o=fe(a)-(d?y.left:y.top);Re();const l=o-ie/2,f=rt(l);Pe(f),R.setPointerCapture&&R.setPointerCapture(a.pointerId),E.current={pointerId:a.pointerId,startThumbPosition:l,startClientX:a.clientX,startClientY:a.clientY},a.preventDefault(),a.stopPropagation()},Fe=a=>{const R=E.current;if(R.pointerId!==a.pointerId)return;const y=a.clientX-R.startClientX,j=a.clientY-R.startClientY,o=$(y,j),l=rt(R.startThumbPosition+o);Pe(l),a.cancelable&&a.preventDefault()},Xe=a=>{if(E.current.pointerId!==a.pointerId)return;const R=a.currentTarget;R.hasPointerCapture(a.pointerId)&&R.releasePointerCapture(a.pointerId),E.current={pointerId:null,startThumbPosition:0,startClientX:0,startClientY:0},a.preventDefault(),a.stopPropagation()},Be=a=>{if(E.current.pointerId!==a.pointerId)return;const R=a.currentTarget;R.hasPointerCapture(a.pointerId)&&R.releasePointerCapture(a.pointerId),E.current={pointerId:null,startThumbPosition:0,startClientX:0,startClientY:0}},lt=r.useMemo(()=>de((ne?1:.8)*Ce,0,1),[ne,Ce]),ct=r.useMemo(()=>{const R=`calc(50% - ${K/2}px + ${xe}px)`;return{left:ce,top:R}},[ce,xe,K]),ut=(a,R,y,j)=>F.jsx("button",{type:"button",tabIndex:-1,className:"aqvs-scrollbar-arrow-button",style:{[M]:m,[z]:m},"aria-label":R,onPointerDown:pt(a),onPointerUp:Le,onPointerLeave:Le,onPointerCancel:Le,onKeyDown:We(a),"aria-disabled":!u,disabled:!$e,children:F.jsx("span",{"aria-hidden":"true",children:y})},j),Qe=x&&q?{orientation:Oe,scrollPosition:t,maxScrollPosition:h,contentSize:s,viewportSize:e,thumbSize:ie,thumbPosition:te,thumbCenter:Ne,trackSize:ye,isDragging:Y,isTapScrollActive:ne,visibleStartIndex:D,visibleEndIndex:X}:null;return F.jsxs("div",{className:Je.twMerge("aqvs-scrollbar",ge,!q&&"pointer-events-none opacity-0",g),style:{[M]:e,[z]:m},role:"scrollbar",tabIndex:-1,"aria-controls":p,"aria-valuenow":t,"aria-valuemin":0,"aria-valuemax":h,"aria-orientation":d?"horizontal":"vertical",children:[!d&&q&&k&&F.jsx(yt,{ref:T,className:Je.twMerge("aqvs-scrollbar-tap-circle-wrapper",I),size:K,maxVisualDistance:Me,style:ct,opacity:lt,renderVisual:Ue,onDragChange:oe},"tap-circle"),ut(-1,W[0],G[0],"arrow-start"),F.jsxs("div",{className:"aqvs-scrollbar-track",style:{borderRadius:m/2},onPointerDown:He,onPointerMove:Fe,onPointerUp:Xe,onPointerCancel:Be,"aria-disabled":!c,children:[Qe&&F.jsx("div",{className:"aqvs-scrollbar-overlay","aria-hidden":!0,children:x?.(Qe)},"overlay"),F.jsx("div",{className:Je.twMerge("aqvs-scrollbar-thumb-wrapper",!(q||Y)&&"pointer-events-none opacity-0"),style:{[M]:ie,[ue]:te,...d?{top:0,bottom:0}:{left:0,right:0}},onPointerDown:qe,role:"slider","aria-orientation":d?"horizontal":"vertical","aria-valuenow":t,"aria-valuemin":0,"aria-valuemax":h,"aria-disabled":!i,tabIndex:-1,children:F.jsx("div",{ref:J,className:Je.twMerge("aqvs-scrollbar-thumb",d?"aqvs-scrollbar-thumb-horizontal":"aqvs-scrollbar-thumb-vertical"),"data-thumb-state":De,style:{borderRadius:m-1,cursor:i?"pointer":"default"},onMouseEnter:()=>{i&&ae(!0)},onMouseLeave:()=>{i&&ae(!1)}},"thumb")},"thumb-wrapper")]},"track"),ut(1,W[1],G[1],"arrow-end")]})},ot={maxVelocity:6,minVelocity:.02,deceleration:.0025,velocitySampleWindow:90,startVelocityThreshold:.04},dt=(s,e,t)=>{for(const[n,i,c]of e)t==="add"?s.addEventListener(n,i,c):s.removeEventListener(n,i,c)},Et=r.forwardRef(({children:s,contentSize:e,viewportSize:t,scrollBarWidth:n=12,enableThumbDrag:i=!0,enableTrackClick:c=!0,enableArrowButtons:u=!0,enablePointerDrag:d=!0,onScroll:m,className:g,style:p,background:b,tapScrollCircleOptions:A,inertiaOptions:x,itemCount:D,renderThumbOverlay:X,wheelSpeedMultiplier:Y=1,onWheelHorizontal:Z,contentInsets:me,visibleStartIndex:ae,visibleEndIndex:ne,renderOverlay:_,initialScrollPosition:J=0},Q)=>{const E=r.useRef(J),le=r.useRef(null),Ie=r.useRef(null),pe=r.useRef(Z);r.useEffect(()=>{pe.current=Z},[Z]);const T=r.useRef({frame:null,velocity:0,lastTimestamp:null}),U=r.useMemo(()=>({maxVelocity:x?.maxVelocity??ot.maxVelocity,minVelocity:x?.minVelocity??ot.minVelocity,deceleration:x?.deceleration??ot.deceleration,velocitySampleWindow:x?.velocitySampleWindow??ot.velocitySampleWindow,startVelocityThreshold:x?.startVelocityThreshold??ot.startVelocityThreshold}),[x]),Te=r.useMemo(()=>({top:Math.max(0,me?.top??0),bottom:Math.max(0,me?.bottom??0)}),[me]);N.debug("[ScrollPane] ScrollPane rendered",{contentSize:e,viewportSize:t,scrollBarWidth:n,className:g,style:p,tapScrollCircleOptions:A,inertiaOptions:x,enablePointerDrag:d,contentInsets:Te});const Ee=r.useRef({contentSize:e,viewportSize:t});Ee.current={contentSize:e,viewportSize:t};const se=r.useMemo(()=>e>t,[e,t]),k=r.useCallback(v=>{const{contentSize:M,viewportSize:z}=Ee.current,ue=M>z,$=E.current;if(N.debug("[ScrollPane] scrollTo called",{newPosition:v,contentSize:M,viewportSize:z,currentIsScrollable:ue,prevPosition:$}),!ue)return E.current!==0&&(E.current=0,m?.(0,$)),E.current;const fe=typeof v=="function"?v(E.current):v,W=Math.max(M-z,0),G=de(fe,0,W);return E.current!==G&&(E.current=G,m?.(G,$)),E.current},[m]),K=r.useCallback(()=>{const v=T.current;v.frame!==null&&cancelAnimationFrame(v.frame),v.frame=null,v.velocity=0,v.lastTimestamp=null},[]),ce=r.useRef(K);r.useEffect(()=>{ce.current=K},[K]);const xe=r.useCallback(v=>{if(!se)return;const{maxVelocity:M,minVelocity:z,deceleration:ue,startVelocityThreshold:$}=U,fe=de(v,-M,M);if(Math.abs(fe)<$)return;K(),T.current.velocity=fe,T.current.lastTimestamp=null;const W=G=>{const ge=T.current;if(ge.lastTimestamp===null){ge.lastTimestamp=G,ge.frame=requestAnimationFrame(W);return}const Oe=G-ge.lastTimestamp;if(ge.lastTimestamp=G,Oe<=0){ge.frame=requestAnimationFrame(W);return}const Me=ge.velocity;let ve=Me;const ye=ue*Oe;Me>0?ve=Math.max(0,Me-ye):Me<0&&(ve=Math.min(0,Me+ye));const ie=(Me+ve)/2*Oe,h=E.current;ie!==0&&k(De=>De+ie);const P=E.current,{contentSize:te,viewportSize:Ne}=Ee.current,q=Math.max(te-Ne,0);ge.velocity=ve;const $e=P===h||P<=0&&ve<=0||P>=q&&ve>=0;if(Math.abs(ve)<z||$e){K();return}ge.frame=requestAnimationFrame(W)};T.current.frame=requestAnimationFrame(W)},[se,U,k,K]),I=r.useRef(xe);r.useEffect(()=>{I.current=xe},[xe]),r.useLayoutEffect(()=>{Ee.current={contentSize:e,viewportSize:t}},[e,t]),r.useLayoutEffect(()=>{const v=Ie.current;if(!v)return;const M=()=>{v.scrollTop!==0&&(N.debug("[ScrollPane] Native scroll detected, resetting to 0",{scrollTop:v.scrollTop}),v.scrollTop=0),v.scrollLeft!==0&&(v.scrollLeft=0)};return v.addEventListener("scroll",M),()=>v.removeEventListener("scroll",M)},[]),r.useLayoutEffect(()=>{if(se){N.debug("[ScrollPane] Adjusting scroll position due to content or viewport size change",{contentSize:e,viewportSize:t,scrollPosition:E.current});const v=de(e-t,0,e);E.current>v&&k(v)}else k(0)},[se,k,e,t]),r.useEffect(()=>{const v=z=>{if(pe.current){const $=z.shiftKey&&z.deltaX===0,fe=$?z.deltaY:z.deltaX,W=$?0:z.deltaY;if(fe!==0&&Math.abs(fe)>=Math.abs(W)){z.preventDefault(),K();let G=fe;z.deltaMode===1?G*=16:z.deltaMode===2&&(G*=t),pe.current(G);return}}if(!se)return;z.preventDefault(),K();let ue=z.deltaY;z.deltaMode===1?ue*=16:z.deltaMode===2&&(ue*=t),Y!==1&&(ue*=Y),N.debug("[ScrollPane] wheel event",{deltaY:ue,scrollPosition:E.current,wheelSpeedMultiplier:Y,deltaMode:z.deltaMode,scrollTop:Ie.current?.scrollTop}),k($=>$+ue)},M=le.current;return M&&M.addEventListener("wheel",v,{passive:!1}),()=>{M&&M.removeEventListener("wheel",v)}},[se,k,K,t,Y]),r.useImperativeHandle(Q,()=>({scrollTo:v=>(K(),k(v)),getScrollPosition:()=>E.current,getContentSize:()=>e,getViewportSize:()=>t}),[k,e,t,K]);const Ve=r.useRef(k);r.useEffect(()=>{Ve.current=k},[k]);const S=r.useId(),ee=r.useRef({pointerId:null,startClientY:0,startScroll:0,isDragging:!1,shouldCancelNextClick:!1,clickResetTimer:null,velocitySamples:[]}),Ce=r.useRef(d);r.useEffect(()=>{Ce.current=d},[d]);const Ue=r.useRef(se);r.useEffect(()=>{Ue.current=se},[se]);const Se=r.useRef(U);return r.useEffect(()=>{Se.current=U},[U]),r.useEffect(()=>{if(d)return;const v=Ie.current,M=ee.current;M.pointerId&&v?.hasPointerCapture(M.pointerId)&&v.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=[]},[d]),r.useEffect(()=>{const v=Ie.current;if(!v)return;const M=6,z=()=>typeof performance<"u"&&typeof performance.now=="function"?performance.now():Date.now(),ue=()=>{const h=ee.current;h.pointerId=null,h.startClientY=0,h.startScroll=0,h.isDragging=!1,h.velocitySamples=[]},$=()=>{const h=ee.current;h.clickResetTimer!==null&&(window.clearTimeout(h.clickResetTimer),h.clickResetTimer=null)},fe=h=>{const P=ee.current,te=z();P.velocitySamples.push({clientY:h,time:te});const Ne=Se.current.velocitySampleWindow;P.velocitySamples=P.velocitySamples.filter(q=>te-q.time<=Ne)},W=h=>h instanceof HTMLElement&&h.closest("[data-scrollpane-ignore-drag='true']")!==null,G=h=>{const P=ee.current;P.shouldCancelNextClick&&(h.preventDefault(),h.stopPropagation(),P.shouldCancelNextClick=!1)},ge=h=>{const P=ee.current;P.isDragging||(P.isDragging=!0,P.shouldCancelNextClick=!0,v.hasPointerCapture(h.pointerId)||v.setPointerCapture(h.pointerId),fe(h.clientY))},Oe=h=>{const P=ee.current;if(P.pointerId!==h.pointerId||!(Ce.current&&Ue.current)||!P.isDragging&&(Math.abs(h.clientY-P.startClientY)<M||(ge(h),!P.isDragging)))return;fe(h.clientY);const te=h.clientY-P.startClientY,Ne=P.startScroll-te;Ve.current(Ne),h.cancelable&&h.preventDefault()},Me=h=>{const P=ee.current;if(P.pointerId!==h.pointerId)return;P.isDragging&&P.shouldCancelNextClick&&h.cancelable&&(h.preventDefault(),h.stopPropagation()),v.hasPointerCapture(h.pointerId)&&v.releasePointerCapture(h.pointerId);let te=0;if(P.isDragging&&P.velocitySamples.length>=2){const q=P.velocitySamples,$e=Se.current.velocitySampleWindow,De=q[q.length-1],Pe=q.find(Ye=>De.time-Ye.time<=$e)??q[0];if(De&&Pe&&De.time!==Pe.time){const Ye=De.clientY-Pe.clientY,he=De.time-Pe.time;te=-(Ye/he)}}$(),P.shouldCancelNextClick&&(P.clickResetTimer=window.setTimeout(()=>{const q=ee.current;q.shouldCancelNextClick=!1,q.clickResetTimer=null},0));const Ne=Se.current.startVelocityThreshold;ue(),Math.abs(te)>=Ne&&I.current?.(te)},ve=h=>{if(!(Ce.current&&Ue.current)||h.button!==0&&h.pointerType==="mouse"||h.ctrlKey||h.metaKey||h.altKey||W(h.target))return;window.dispatchEvent(new CustomEvent(xt,{detail:{paneId:S}})),ce.current?.();const P=ee.current;$(),P.pointerId=h.pointerId,P.startClientY=h.clientY,P.startScroll=E.current,P.isDragging=!1,P.shouldCancelNextClick=!1,P.velocitySamples=[]},ye=h=>{const P=ee.current;P.pointerId===h.pointerId&&(P.shouldCancelNextClick=!1,v.hasPointerCapture(h.pointerId)&&v.releasePointerCapture(h.pointerId),$(),ue())},Ae=[["click",G,!0],["pointerdown",ve,{passive:!1}],["pointermove",Oe,{passive:!1}],["pointerup",Me,void 0],["pointercancel",ye,void 0]],ie=[["pointermove",Oe,{passive:!1}],["pointerup",Me,void 0],["pointercancel",ye,void 0]];return dt(v,Ae,"add"),dt(window,ie,"add"),()=>{dt(v,Ae,"remove"),dt(window,ie,"remove");const h=ee.current;h.pointerId!==null&&v.hasPointerCapture(h.pointerId)&&v.releasePointerCapture(h.pointerId),$(),ue()}},[S]),F.jsxs("div",{ref:le,className:Je.twMerge("aqvs-scroll-pane",g),style:p,children:[F.jsxs("div",{ref:Ie,className:Je.twMerge("aqvs-scroll-pane-content"),style:{height:t,paddingTop:Te.top,paddingBottom:Te.bottom,...d?{touchAction:"none"}:{}},id:S,children:[b,s(E.current)]}),F.jsx(wt,{contentSize:e,viewportSize:t,scrollPosition:E.current,onScroll:k,enableThumbDrag:i,enableTrackClick:c,enableArrowButtons:u,scrollBarWidth:n,ariaControls:S,tapScrollCircleOptions:A,itemCount:D,renderThumbOverlay:X,visibleStartIndex:ae,visibleEndIndex:ne},"scrollbar"),_?.()]})}),Mt=(s,e,t)=>Math.min(Math.max(s,e),t),Qt=({dragState:s,normalizedDistance:e,sizeScale:t,size:n})=>{const i=Math.max(n/2,1),c=1+e*.65,u=Math.max(.65,1-e*.25),d=s.direction*e*26*t,m=.8+e*.18,g=3*t,p=6*t,b=22*t,A=Math.abs(d)+p,x=d>0?g:-Math.abs(d)-g,D=Math.max(2.5,3*t),X=Mt(s.offsetX,-i,i),Y=Mt(s.offsetY,-i,i),Z=i*.35,me=X/i*Z,ae=Y/i*Z,ne=me*.45,_=ae*.45,J=Math.max(b*.38,6),Q=.65+e*.2,E=s.active;return F.jsxs(F.Fragment,{children:[F.jsx("div",{className:"aqvs-tap-scroll-circle-gradient",style:{transform:`scale(${u}, ${c})`,transition:E?"40ms transform ease-out":"200ms ease transform"}}),F.jsx("div",{className:"aqvs-sample-visual-rod",style:{width:b,height:b,transform:`translate(calc(-50% + ${me}px), calc(-50% + ${ae}px)) scale(${u}, ${m*c})`,transition:E?"70ms transform ease-out":"200ms ease transform"}}),F.jsx("div",{className:"aqvs-sample-visual-pupil",style:{width:J,height:J,transform:`translate(calc(-50% + ${ne}px), calc(-50% + ${_}px)) scale(${u}, ${c})`,opacity:Q,boxShadow:"0 0 8px rgba(255,255,255,0.45)",transition:E?"120ms opacity 150ms, 120ms transform ease-out ease-out":"220ms ease transform, 240ms opacity ease"}}),F.jsx("div",{className:"aqvs-sample-visual-highlight",style:{width:D,height:A,transform:`translate(-50%, ${x}px)`,opacity:e,transition:E?"40ms height, 60ms opacity ease-out ease-out":"200ms ease height, 120ms ease opacity"}})]})},er=s=>{if(!Number.isFinite(s))return 0n;const e=Math.trunc(s);return e<=0?0n:BigInt(e)},mt=s=>{if(s<=0||!Number.isFinite(s))return 0;const e=Math.trunc(s),t=BigInt(e)&-BigInt(e);return Number(t)};class kt{tree;deltas;size;baseValue;valueFn;total;constructor(e,t,n){this.reset(e,t,n)}reset(e,t,n){if(this.size=e,this.tree=new Map,this.deltas=new Map,this.total=void 0,typeof t=="function"){if(this.valueFn=t,this.size>0){const c=n?.sampleRange??{from:0,to:Math.min(99,this.size-1)},{mode:u,materializedValues:d}=this._calculateMode(c.from,c.to);if(this.baseValue=u,n?.materialize)for(let m=0;m<d.length;m++){const g=d[m],p=c.from+m;if(p>=this.size)break;const b=g-this.baseValue;this.deltas.set(p,b),this._updateTree(p,b)}}else this.baseValue=0;this.total=this.getTotal()}else this.valueFn=void 0,this.baseValue=t,this.total=this.baseValue*this.size}setValueFn(e,t){if(t?.reset){this.reset(this.size,e);return}typeof e=="function"?this.valueFn=e:(this.valueFn=void 0,this.baseValue=e)}_calculateMode(e,t){if(!this.valueFn)return{mode:0,materializedValues:[]};const n=[];for(let g=e;g<=t&&!(g>=this.size);g++)n.push(this.valueFn(g));const i=[...n];if(n.length===0)return{mode:0,materializedValues:[]};n.sort((g,p)=>g-p);const c=Math.floor(n.length/2);let u;n.length%2===0?u=Math.floor((n[c-1]+n[c])/2):u=n[c];const d=new Map;let m=0;for(const g of n){const p=(d.get(g)??0)+1;d.set(g,p),p>m&&(m=p)}if(m>n.length*.2){const g=[];for(const[b,A]of d.entries())A===m&&g.push(b);const p=g.reduce((b,A)=>b+A,0);u=Math.floor(p/g.length)}return{mode:u,materializedValues:i}}update(e,t){return this.updates([{index:e,value:t}])}updates(e){const t=this._buildDeltaUpdates(e);return t.length>0?this.updateDeltas(t):this.total}updateDelta(e,t){return this.updateDeltas([{index:e,change:t}])}updateDeltas(e){for(const{index:t,change:n}of e){if(t<0||t>=this.size)throw new Error(`Index ${t} out of bounds`);const i=this.deltas.get(t)??0;this.deltas.set(t,i+n),this._updateTree(t,n)}return this.total}_updateTree(e,t){if(t===0)return;let n=e+1;for(;n<=this.size;){this.tree.set(n,(this.tree.get(n)??0)+t);const i=mt(n);if(i===0)break;n+=i}this.total!==void 0&&(this.total+=t)}_buildDeltaUpdates(e){const t=[];for(const{index:n,value:i}of e){if(n<0||n>=this.size)throw new Error(`Index ${n} out of bounds`);if(i<0)throw new Error("Value cannot be negative.");const c=this.deltas.has(n)?(this.deltas.get(n)??0)+this.baseValue:this.baseValue,u=i-c;u!==0&&t.push({index:n,change:u})}return t}_computeTreeTotal(){if(this.size<=0)return 0;let e=0,t=this.size;for(;t>0;){e+=this.tree.get(t)??0;const n=mt(t);if(n===0)break;t-=n}return e+this.baseValue*this.size}_materialize(e,t=!0){if(this.valueFn){const n=this.deltas.get(e)??0,c=this.valueFn(e)-this.baseValue;if(c!==n&&(this.deltas.set(e,c),t)){const u=c-n;this._updateTree(e,u)}}}_materializeRanges(e,t,n=!1){if(!(e?.materialize&&this.valueFn))return;const i=e.ranges;if(i&&i.length>0){for(const d of i){const m=d.from,g=Math.min(d.to,this.size-1);for(let p=m;p<=g;p++)this._materialize(p)}if(t===void 0)return;if(n){this._materialize(t);return}const c=i[0].from,u=i[i.length-1].to;t>=c&&t<=u&&this._materialize(t);return}t!==void 0&&this._materialize(t)}_findIndex(e,t={},n){if(this.size>2147483647)return this._findIndexLarge(e,t,n);if(this.size===0)return{index:-1,total:this.total??0,cumulative:void 0,currentValue:void 0,safeIndex:void 0};let i=0,c=0,u=1;for(;u<<1<=this.size;)u<<=1;for(;u>0;u>>=1){const g=i+u;if(g<=this.size){const b=(this.tree.get(g)??0)+this.baseValue*u;(n?c+b<e:c+b<=e)&&(i=g,c+=b)}}const d=n?i:i-1;if(d<0||d>=this.size)return{index:-1,total:this.total??this.getTotal(),cumulative:void 0,currentValue:void 0,safeIndex:void 0};const m=this.prefixSum(d,t);return{index:d,total:this.total??m.total,cumulative:m.cumulative,currentValue:m.currentValue,safeIndex:m.safeIndex}}_findIndexLarge(e,t,n){if(this.size===0)return{index:-1,total:this.total??0,cumulative:void 0,currentValue:void 0,safeIndex:void 0};const i=er(this.size);if(i===0n)return{index:-1,total:this.total??0,cumulative:void 0,currentValue:void 0,safeIndex:void 0};let c=0n,u=i-1n,d,m,g,p=this.total;for(;c<=u;){const x=c+u>>1n,D=Number(x),X=this.prefixSum(D,t);if(g=X,p=X.total,n?X.cumulative>=e:X.cumulative<=e)if(d=x,m=X,n){if(x===0n)break;u=x-1n}else c=x+1n;else if(n)c=x+1n;else{if(x===0n)break;u=x-1n}}const b=m??g;return{index:d!==void 0?Number(d):-1,total:p,cumulative:b?.cumulative,currentValue:b?.currentValue,safeIndex:b?.safeIndex}}prefixSum(e,t){if(e<0)return{cumulative:0,total:this.total,currentValue:0,safeIndex:0};const n=de(e,0,this.size-1),i=t?.materializeOption;this._materializeRanges(i,n,!0);let c=0,u=n+1;for(;u>0;){const m=this.tree.get(u)??0;c+=m;const g=mt(u);if(g===0)break;u-=g}const d=i?.materialize?this.get(n):(this.deltas.get(n)||0)+this.baseValue;return{cumulative:c+this.baseValue*(n+1),total:this.total,currentValue:d,safeIndex:n}}get(e,t){if(e<0||e>=this.size)throw new Error("Index out of bounds");const n=t?.materializeOption;return this._materializeRanges(n,e),(this.deltas.get(e)??0)+this.baseValue}getTotal(e){const t=e?.materializeOption;if(this._materializeRanges(t),this.total===void 0)if(this.size===0)this.total=0;else{this.total=this._computeTreeTotal();const n=this.prefixSum(this.getSize()-1);n.cumulative!==n.total&&N.error("Inconsistent Fenwick Tree state")}return this.total}rebuildTree(e){if(e?.materialize&&this.valueFn){const n=this.valueFn;this.reset(this.size,i=>n(i),{materialize:!0});return}const t=new Map;for(const[n,i]of this.deltas.entries()){if(i===0)continue;let c=n+1;for(;c<=this.size;){t.set(c,(t.get(c)??0)+i);const u=mt(c);if(u===0)break;c+=u}}this.tree=t,this.total=this._computeTreeTotal()}calculateAccumulatedError(){if(this.total===void 0)return 0;let e=this.baseValue*this.size;for(const t of this.deltas.values())e+=t;return this.total-e}changeSize(e){const t=this.size;if(e===t)return;if(e<t)for(const i of this.deltas.keys())i>=e&&this.deltas.delete(i);this.size=e,this.rebuildTree();const n=this.prefixSum(this.getSize()-1);n.cumulative!==n.total&&N.error("Inconsistent Fenwick Tree state")}getSize(){return this.size}findIndexAtOrAfter(e,t){return this._findIndex(e,t??{},!0)}findIndexAtOrBefore(e,t){return this._findIndex(e,t??{},!1)}}const Vt=(s,e,t)=>{const n=Math.max(0,s),i=r.useRef(null),c=r.useRef({size:n,valueOrFn:e,options:t});i.current===null&&(i.current=new kt(n,e,t));const u=i.current,d=c.current,m=d.size!==n,g=d.valueOrFn!==e,p=d.options!==t;if(g||p){const b=t?.resetOnValueFnChange??!0;p||g&&b?(t?.debug&&N.debug("[useFenwickMapTree] reset",{valueOrFnChanged:g,optionsChanged:p}),u.reset(n,e,t)):(m&&(t?.debug&&N.debug("[useFenwickMapTree] resize (with valueFn change)",{from:d.size,to:n}),u.changeSize(n)),t?.debug&&N.debug("[useFenwickMapTree] setValueFn (no reset)",{valueOrFnChanged:g}),u.setValueFn(e,{reset:!1})),c.current={size:n,valueOrFn:e,options:t}}else m&&(t?.debug&&N.debug("[useFenwickMapTree] resize",{from:d.size,to:n}),d.size===0&&n>0?u.reset(n,e,t):u.changeSize(n),c.current={size:n,valueOrFn:e,options:t});return u};class tr{key;value;prev=null;next=null;constructor(e,t){this.key=e,this.value=t}}class 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 At(s){const e=r.useRef(new Map),t=r.useRef(new Pt);r.useEffect(()=>{for(;e.current.size>s;){const p=t.current.removeHead();if(p)e.current.delete(p.key);else break}},[s]);const n=r.useCallback(p=>{const b=e.current.get(p);if(b)return t.current.moveToTail(b),b.value},[]),i=r.useCallback((p,b)=>{if(s<=0)return;let A=e.current.get(p);if(A)A.value=b,t.current.moveToTail(A);else{if(e.current.size>=s){const x=t.current.removeHead();x&&e.current.delete(x.key)}A=new tr(p,b),e.current.set(p,A),t.current.addToTail(A)}},[s]),c=r.useCallback(p=>e.current.has(p),[]),u=r.useCallback(p=>{const b=e.current.get(p);b&&(t.current.remove(b),e.current.delete(p))},[]),d=r.useCallback(()=>{e.current.clear(),t.current=new Pt},[]),[m,g]=r.useState(()=>({get:n,set:i,has:c,remove:u,clear:d}));return r.useEffect(()=>g({get:n,set:i,has:c,remove:u,clear:d}),[n,i,c,u,d]),m}const rr=1e4,nr=()=>{const{get:s,set:e,has:t,clear:n}=At(rr);return{get:s,set:e,has:t,clear:n}},re=(s,e)=>e<=0?0:de(s,0,e-1),Rt=s=>({top:Math.max(0,s?.top??0),bottom:Math.max(0,s?.bottom??0)}),je=(s,e)=>s<=e?0:s-e,et=(s,e)=>s<=0?e:s+e,bt=s=>{if(!Number.isFinite(s))return 0n;const e=Math.trunc(s);return e<=0?0n:BigInt(e)},sr=(s,e,t,n,i,c,u,d)=>{const m=bt(n);if(m===0n)return{renderingStartIndex:0,renderingEndIndex:0,visibleStartIndex:0,visibleEndIndex:0};const g=_=>_<0n?0n:_>=m?m-1n:_,p={materializeOption:{materialize:!1}},{index:b,cumulative:A}=c.findIndexAtOrAfter(s,p);let x;b===-1?x=m-1n:(A===s?x=bt(b+1):x=bt(b),x>=m&&(x=m-1n)),s<=0&&(x=0n),d&&s>=u&&(x=m-1n);const D=_=>{let J=0,Q=_,E=_,le=0n;for(;Q<m&&J<e;){const Ie=Number(Q),pe=i(Ie);if(J+=pe,E=Q,Q+=1n,le+=1n,!Number.isFinite(pe)||pe<=0)break}return le===0n&&(E=_),{height:J,end:E}};let{height:X,end:Y}=D(x);if(X<e&&x>0n){let _=x,J=X;for(;_>0n&&J<e;){_-=1n;const E=Number(_),le=i(E);if(J+=le,!Number.isFinite(le)||le<=0)break}x=g(_);const Q=D(x);X=Q.height,Y=Q.end}const Z=g(x),me=g(Y),ae=g(Z-BigInt(Math.max(0,t))),ne=g(me+BigInt(Math.max(0,t)));return{renderingStartIndex:re(Number(ae),n),renderingEndIndex:re(Number(ne),n),visibleStartIndex:re(Number(Z),n),visibleEndIndex:re(Number(me),n)}},ir=(s,e,t,n,i,c,u)=>{if(n===0)return{renderingStartIndex:0,renderingEndIndex:0,visibleStartIndex:0,visibleEndIndex:0};const d=Number.isFinite(u),m=d?Math.min(Math.max(0,s),u):Math.max(0,s);if(n>=Number.MAX_SAFE_INTEGER)return sr(m,e,t,n,i,c,u,d);const{index:g,cumulative:p,currentValue:b}=c.findIndexAtOrAfter(m,{materializeOption:{materialize:!1}}),A=g===-1?e<=0||(p??0)<m+(b??0)?n-1:0:g;let x=re(A,n),D=0;if(g!==-1&&p===m)x=re(g+1,n),D=0;else if(x===g&&p!==void 0&&b!==void 0)D=p-b-m;else{const{cumulative:ne,currentValue:_}=c.prefixSum(x,{materializeOption:{materialize:!1}});D=(ne??0)-(_??0)-m}const X=D;let Y=x;for(;Y<n&&D<e;)D+=i(Y),Y++;if(D<e&&x>0){let ne=D+Math.abs(Math.min(0,X)),_=x-1;for(;_>=0&&ne<e;)ne+=i(_),_--;for(x=re(_+1,n),D=0,Y=x;Y<n&&D<e;)D+=i(Y),Y++}const Z=re(x-t,n),me=re(Math.max(Y-1,x),n),ae=re(me+t,n);return{renderingStartIndex:Z,renderingEndIndex:ae,visibleStartIndex:x,visibleEndIndex:me}},Ct=(s,e,t)=>{const n=Math.max(0,e??0),i=r.useRef({last:0,id:null,arg:null}).current;return r.useEffect(()=>()=>{i.id!==null&&(cancelAnimationFrame(i.id),i.id=null)},[i]),r.useCallback(c=>{if(i.arg=c,i.id!==null)return;const u=d=>{if(i.id=null,i.arg===null)return;const m=d-i.last;if(n===0||i.last===0||m>=n){if(s.current)try{t(s.current,i.arg)}catch(g){console.error("[useThrottledInvoker] Error invoking callback",g)}i.arg=null,i.last=d}i.arg!==null&&(i.id=requestAnimationFrame(u))};i.id=requestAnimationFrame(u)},[n,t,s,i])},or=r.memo(({index:s,top:e,height:t,item:n,children:i,clipItemHeight:c,enableKeyboardNavigation:u,onKeyDown:d,onFocus:m,registerItemRef:g})=>{const p=r.useCallback(D=>g(s,D),[s,g]),b=r.useCallback(D=>d(D,s),[s,d]),A=r.useCallback(()=>m(s),[s,m]),x=r.useCallback(D=>{D.currentTarget.focus({preventScroll:!0})},[]);return F.jsx("div",{ref:p,"data-index":s,"data-virtualscroll-item":"true",className:"aqvs-item-container",style:{top:e,height:t,overflow:c?"hidden":void 0},tabIndex:u?-1:void 0,onPointerDown:u?x:void 0,onKeyDownCapture:u?b:void 0,onFocusCapture:u?A:void 0,children:i(n,s)})}),ar=({itemCount:s,getItem:e,getItemKey:t,getItemHeight:n,viewportSize:i,overscanCount:c=15,className:u,onScroll:d,onRangeChange:m,children:g,background:p,initialScrollIndex:b,initialScrollOffset:A,callbackThrottleMs:x=5,contentInsets:D,onItemFocus:X,scrollBarOptions:Y,behaviorOptions:Z,onWheelHorizontal:me},ae)=>{const{width:ne,enableThumbDrag:_,enableTrackClick:J,enableArrowButtons:Q,enableScrollToTopBottomButtons:E,renderThumbOverlay:le,tapScrollCircleOptions:Ie}=Y??{},{enablePointerDrag:pe,enableKeyboardNavigation:T=!0,wheelSpeedMultiplier:U,inertiaOptions:Te,clipItemHeight:Ee=!1,resetOnGetItemHeightChange:se=!1}=Z??{},k=r.useRef(null),K=r.useRef({renderingStartIndex:0,renderingEndIndex:0,visibleStartIndex:0,visibleEndIndex:0,scrollPosition:0,totalHeight:0}),ce=r.useRef(null),xe=r.useRef(!1);r.useEffect(()=>{se&&(ce.current=null)},[se]);const I=r.useMemo(()=>Rt(D),[D]),Ve=r.useMemo(()=>({sampleRange:{from:0,to:100},resetOnValueFnChange:se,materialize:!0}),[se]),S=Vt(s,n,Ve),[ee]=r.useState(()=>{let o=I.top,l=0;if(typeof b=="number"){const f=de(b,0,s-1),C=de(f-c*2,0,s-1),V=de(f+c*2,0,s-1),w=b>0?{materializeOption:{materialize:!0,ranges:[{from:C,to:V}]}}:void 0,{cumulative:H,total:B,currentValue:L}=S.prefixSum(b,w),O=Math.max(H-L,0);o=et(O,I.top),l=B??S.getTotal()}else typeof A=="number"&&(o=et(Math.max(A,0),I.top)),l=S.getTotal();return{position:o,total:l}}),[Ce,Ue]=r.useState(ee.position),[Se,v]=r.useState(ee.total),M=r.useRef(ee.position),z=r.useRef(I.top),ue=r.useRef(d??void 0),$=r.useRef(m??void 0),fe=r.useRef(new Map),W=r.useRef(null),G=r.useRef(null),[ge,Oe]=r.useState(null),[Me,ve]=r.useState(!1),ye=r.useRef(null),Ae=r.useRef(!1),ie=r.useRef(0),h=r.useRef(!1),P=r.useRef(s);P.current!==s&&(P.current=s,h.current=!0),r.useEffect(()=>{ue.current=d??void 0,$.current=m??void 0},[m,d]);const te=r.useCallback(o=>{if(T&&o&&typeof o.focus=="function")try{o.focus({preventScroll:!0})}catch{o.focus()}},[T]),Ne=r.useCallback((o,{position:l,totalHeight:f})=>{o(l,f)},[]),q=Ct(ue,x,Ne),$e=r.useCallback((o,l)=>{o(l)},[]),De=Ct($,x,$e);r.useEffect(()=>(xe.current=!0,()=>{xe.current=!1}),[]),r.useEffect(()=>{T||(fe.current.clear(),W.current=null,G.current=null)},[T]);const Pe=r.useCallback((o,l)=>{if(!l){fe.current.delete(o);return}T&&(fe.current.set(o,l),W.current===o&&(W.current=null,G.current=o,te(l)))},[T,te]),Ye=.01,he=r.useRef({rafId:null,loopActive:!1,idleFrames:0,lastRenderedPosition:ee.position}),Re=r.useCallback(()=>{const o=he.current;o.rafId!==null&&typeof cancelAnimationFrame=="function"&&cancelAnimationFrame(o.rafId),o.rafId=null,o.loopActive=!1,o.idleFrames=0},[]);r.useEffect(()=>()=>{Re()},[Re]);const Ke=r.useCallback(()=>{const o=he.current;o.rafId=null;const l=M.current,f=je(l,I.top),C=S.getTotal();if(Ue(w=>Math.abs(w-l)<Ye?w:l),q({position:f,totalHeight:C}),Math.abs(o.lastRenderedPosition-l)>=Ye?(o.lastRenderedPosition=l,o.idleFrames=0):o.idleFrames+=1,o.idleFrames>=2){Re();return}if(typeof requestAnimationFrame=="function"){o.rafId=requestAnimationFrame(Ke);return}o.loopActive=!1},[S,I.top,q,Re]),tt=r.useCallback(()=>{const o=he.current;if(o.idleFrames=0,!o.loopActive){if(o.loopActive=!0,typeof requestAnimationFrame=="function"){o.rafId=requestAnimationFrame(Ke);return}o.loopActive=!1}},[Ke]),oe=r.useCallback((o,l)=>{const f=l?.immediate??!1,C=je(o,I.top);if(M.current=o,f){he.current.lastRenderedPosition=o,he.current.idleFrames=0,Ue(o),q({position:C,totalHeight:S.getTotal()});return}tt()},[tt,S,I.top,q]),rt=r.useRef(!1);r.useEffect(()=>{if(!rt.current)if(rt.current=!0,typeof A=="number"){const o=et(Math.max(A,0),I.top),l=Math.abs(o-M.current)>.5;oe(o,{immediate:!0}),l&&k.current?.scrollTo(o)}else oe(M.current,{immediate:!0})},[A,I.top,oe]),r.useEffect(()=>{const o=S.getTotal();Se!==o&&v(o)},[S,Se,s]),r.useEffect(()=>{if(ce.current!==null){const{index:o,align:l,offset:f}=ce.current,C=re(o,s),{cumulative:V,currentValue:w}=S.prefixSum(C,{materializeOption:{materialize:!1}});if(V!==void 0&&w!==void 0){const H=Math.max(V-w,0);let B=H;l==="bottom"?B=V-i:l==="center"&&(B=H+w/2-i/2),f&&(B-=f),B=Math.max(0,B);const L=Math.max(0,Se+I.top+I.bottom-i),O=Math.min(et(B,I.top),L);Math.abs(O-M.current)>1&&(N.debug("[VirtualScroll] Drift correction",{from:M.current,to:O,targetIndex:C}),ie.current===0&&(ie.current+=1),k.current?.scrollTo(O),oe(O,{immediate:!0}))}}h.current=!1},[Se,S,s,I.top,oe,i,I.bottom]),r.useEffect(()=>{const o=z.current;if(o===I.top)return;const l=je(M.current,o),f=et(l,I.top);z.current=I.top,M.current=f,k.current?.scrollTo(f),oe(f,{immediate:!0})},[I.top,oe]);const nt=r.useCallback((o,l)=>{const f=re(o,s),C=S.get(f),V=l-C,w=S.update(f,l);w!==void 0&&v(w),N.debug("[VirtualScroll] Updated item size manually",{index:f,size:l,total:w});let H=ce.current?ce.current.index:null;if(H===null){const B=M.current,L=Rt(D).top,O=je(B,L),{index:we}=S.findIndexAtOrAfter(O,{materializeOption:{materialize:!1}});H=we}if(H!==-1&&f<H&&V!==0){const B=M.current,L=B+V;ie.current+=1,oe(L,{immediate:!0}),k.current?.scrollTo(L),N.debug("[VirtualScroll] Adjusted scroll for layout shift (manual update)",{from:B,to:L,causedByIndex:f,delta:V,activeVisibleStartIndex:H})}},[S,s,oe,D]),ke=r.useCallback((o,l)=>{if(!k.current)return;const f=re(o,s),C=re(f-c*2,s),V=re(f+c*2,s),{cumulative:w,total:H,currentValue:B}=S.prefixSum(f,{materializeOption:{materialize:!0,ranges:[{from:C,to:V}]}});if(N.debug("[VirtualScroll] Scrolling to index:",f,"ItemBottom:",w,"Total height:",H,"ItemHeight:",B,"safeIndexFrom:",C,"safeIndexTo:",V),!H)return;const L=Math.max(w-B,0);let O=L;l?.align==="bottom"?O=w-i:l?.align==="center"&&(O=L+B/2-i/2),l?.offset&&(O-=l.offset),O=Math.max(0,O);const we=et(O,I.top),be=k.current?.getContentSize()??H+I.top+I.bottom,_e=Math.max(0,be-i),Ge=Math.min(we,_e);ce.current={index:f,align:l?.align,offset:l?.offset};const st=k.current?.getScrollPosition()??-1,it=Math.abs(st-Ge)>.5;Ae.current=!1,ie.current=0,it&&(Ae.current=!0,ie.current+=1,k.current?.scrollTo(Ge)),v(H),oe(Ge,{immediate:!0}),N.debug("[VirtualScroll] Setting scroll position to:",Ge,{original:we,max:_e})},[S,c,s,I.top,I.bottom,i,oe]),Ze=r.useCallback(o=>{if(!k.current)return;const l=S.getTotal(),f=de(Math.floor(o),0,l),{index:C,cumulative:V,currentValue:w}=S.findIndexAtOrAfter(f,{materializeOption:{materialize:!1}}),B=(V??0)-(w??0)-f;ke(C,{offset:B})},[S,ke]),at=r.useCallback(o=>{const l=je(M.current,I.top),f=typeof o=="function"?o(l):o;Ze(f);const C=k.current?.getScrollPosition(),V=typeof C=="number"?C:M.current;return oe(V),V},[I.top,Ze,oe]),pt=r.useCallback((o,l)=>{N.debug("[VirtualScroll] Scroll position changed:",o);const f=Ae.current;f&&(Ae.current=!1);const C=ie.current>0;if(C&&(ie.current=0),f||C||h.current||(ce.current=null),oe(o),E){if(f||C)return;const V=o-l;if(N.debug("[VirtualScroll] Scroll diff:",V,"New:",o,"Prev:",l),Math.abs(V)>1){const w=V>0?"down":"up";Oe(w),ve(!0),N.debug("[VirtualScroll] Showing scroll buttons. Direction:",w),ye.current&&clearTimeout(ye.current),ye.current=setTimeout(()=>{ve(!1),N.debug("[VirtualScroll] Hiding scroll buttons")},2e3)}}},[oe,E]),Le=r.useMemo(()=>je(Ce,I.top),[I.top,Ce]),We=r.useMemo(()=>{const o=S.getTotal(),l=ir(Le,i,c,s,n,S,o);return N.debug("[VirtualScroll] Calculated rendering range:",{...l,scrollPosition:Le,renderingContentSize:o,overscanCount:c,viewportSize:i}),l},[Le,i,c,s,n,S]),{renderingStartIndex:qe,renderingEndIndex:He,visibleStartIndex:Fe,visibleEndIndex:Xe}=We,Be=r.useCallback((o,l)=>{if(!T||s===0)return;const f=re(o,s);if(!(l?.ensureVisible??!0)){const _e=fe.current.get(f);_e&&(W.current=null,G.current=f,te(_e));return}const V=S.prefixSum(f,{materializeOption:{materialize:!1}}),w=V.currentValue,H=Math.max(V.cumulative-w,0),B=H+w,L=je(M.current,I.top),O=L+i;if(H<L||B>O){W.current=f,ke(f);return}const be=fe.current.get(f);if(be){W.current=null,G.current=f,te(be);return}W.current=f},[T,s,S,I.top,ke,te,i]),lt=r.useCallback((o,l)=>{if(!T||o.defaultPrevented||o.altKey||o.metaKey||o.ctrlKey)return;const f=o.target;if(f){const C=f.tagName;if(C==="INPUT"||C==="TEXTAREA"||C==="SELECT"||f.isContentEditable)return}if(o.key==="ArrowDown"){l<s-1&&(o.preventDefault(),Be(l+1));return}if(o.key==="ArrowUp"){l>0&&(o.preventDefault(),Be(l-1));return}if(o.key==="PageDown"){if(l<s-1){o.preventDefault();const C=Math.max(Xe-Fe+1,1),V=Math.max(C,1),w=re(Math.min(l+V,s-1),s);Be(w)}return}if(o.key==="PageUp"&&l>0){o.preventDefault();const C=Math.max(Xe-Fe+1,1),V=Math.max(C,1),w=re(l-V,s);Be(w)}},[T,s,Be,Xe,Fe]),ct=r.useCallback(o=>{if(!T)return;const l=re(o,s);W.current=null,G.current=l,X?.(l)},[T,s,X]);r.useEffect(()=>{const o=k.current?.getScrollPosition()??0,l=M.current,f=je(l,I.top);N.debug("[VirtualScroll] Range change effect triggered",{renderingStartIndex:qe,renderingEndIndex:He,visibleStartIndex:Fe,visibleEndIndex:Xe,scrollPositionState:Ce,paneScrollPosition:l,logicalScrollPosition:f,contentSize:Se,scrollPaneScrollPosition:o}),De({renderingStartIndex:qe,renderingEndIndex:He,visibleStartIndex:Fe,visibleEndIndex:Xe,scrollPosition:f,totalHeight:Se})},[Se,He,qe,I.top,De,Ce,Xe,Fe]);const ut=r.useCallback(()=>{if(!E)return null;const o=Me&&ge!==null,l=ge==="up";return F.jsx("div",{className:"aqvs-scroll-to-edge-overlay","data-visible":o,children:l?F.jsx("div",{className:"aqvs-scroll-to-edge-button-container aqvs-scroll-to-edge-button-container-top",children:F.jsx("button",{type:"button",className:"aqvs-scroll-to-edge-button",onClick:f=>{f.stopPropagation(),Ae.current=!0,ke(0),ve(!1)},children:"Top"})}):F.jsx("div",{className:"aqvs-scroll-to-edge-button-container aqvs-scroll-to-edge-button-container-bottom",children:F.jsx("button",{type:"button",className:"aqvs-scroll-to-edge-button",onClick:f=>{f.stopPropagation(),Ae.current=!0,ke(s-1),ve(!1)},children:"Bottom"})})})},[E,Me,ge,ke,s]),{visibleItems:Qe,startPosition:a}=r.useMemo(()=>{if(s===0)return{visibleItems:F.jsx("div",{className:"aqvs-no-items-container",children:F.jsx("div",{className:"aqvs-no-items-text",children:"No items"})}),startPosition:0};const o=re(qe,s),l=re(He,s),{cumulative:f,currentValue:C}=S.prefixSum(o,{materializeOption:{materialize:!1}}),V=f-C,w=[],H=[];let B=0;for(let L=o;L<=l;L++){const O=n(L),we=S.get(L),be=O-we;be!==0&&w.push({index:L,value:O});const{cumulative:_e,currentValue:Ge}=S.prefixSum(L,{materializeOption:{materialize:!1}}),st=_e-Ge+B,it=t?t(L):L;H.push(F.jsx(or,{index:L,top:st-V+I.top,height:O,item:e(L),clipItemHeight:Ee,enableKeyboardNavigation:T,onKeyDown:lt,onFocus:ct,registerItemRef:Pe,children:g},it)),B+=be}return w.length>0&&Promise.resolve().then(()=>{if(!xe.current)return;let L=0;for(const be of w)if(be.index<Fe){const _e=S.get(be.index);L+=be.value-_e}const O=S.updates(w);if(!xe.current||typeof O!="number")return;v(O),N.debug("[VirtualScroll] Updated heights for items",w,"New total height:",O);const we=k.current?.getScrollPosition()??M.current;if(L!==0){const be=we+L;ie.current+=1,oe(be,{immediate:!0}),k.current?.scrollTo(be),N.debug("[VirtualScroll] Adjusted scroll for layout shift (auto update)",{from:we,to:be,shiftAmount:L})}else we!==M.current&&oe(we)}),{visibleItems:H,startPosition:V}},[g,Ee,T,s,S,e,t,n,ct,lt,Pe,He,qe,I.top,oe,Fe]),R=r.useCallback(o=>{const l=(x??0)>0,f=Math.abs(o-Ce),C=l&&f>.5?Ce:o,V=je(C,I.top);if(N.debug("[VirtualScroll] Rendering visible items",{currentScrollPosition:o,effectiveScrollPosition:V,renderingStartIndex:qe,renderingEndIndex:He,itemCount:s,viewportSize:i,callbackThrottleMs:x,diff:f,rawEffectiveScrollPosition:C}),s===0)return Qe;const w=a-V,H=I.bottom>0?F.jsx("div",{className:"aqvs-bottom-inset",style:{top:S.getTotal()+I.top-a,height:I.bottom}},"virtualscroll-bottom-inset"):null;return N.debug("[VirtualScroll] Rendering items",{containerTop:w,logicalScrollPosition:Le,resolvedInsets:I,effectiveScrollPosition:V}),F.jsxs("div",{className:"aqvs-items-wrapper",style:{top:w,position:"relative"},children:[Qe,H]})},[x,s,S,Le,He,qe,I,Ce,a,i,Qe]),y=r.useMemo(()=>({renderingStartIndex:We.renderingStartIndex,renderingEndIndex:We.renderingEndIndex,visibleStartIndex:We.visibleStartIndex,visibleEndIndex:We.visibleEndIndex,scrollPosition:Le,totalHeight:S.getTotal()}),[We,Le,S]);r.useEffect(()=>{K.current=y},[y]),r.useImperativeHandle(ae,()=>({getScrollPosition:()=>k.current?.getScrollPosition()??-1,getContentSize:()=>k.current?.getContentSize()??-1,getViewportSize:()=>k.current?.getViewportSize()??-1,scrollTo:at,scrollToIndex:ke,getFenwickTreeTotalHeight:()=>S.getTotal(),getFenwickSize:()=>S.getSize(),focusItemAtIndex:Be,getRange:()=>K.current,updateItemSize:nt}),[at,ke,S,Be,nt]);const j=S.getTotal()+I.top+I.bottom;return F.jsx(Et,{ref:k,contentSize:j,viewportSize:i,className:u,onScroll:pt,background:p,tapScrollCircleOptions:Ie,inertiaOptions:Te,itemCount:s,scrollBarWidth:ne,enableThumbDrag:_,enableTrackClick:J,enableArrowButtons:Q,enablePointerDrag:pe,renderThumbOverlay:le,wheelSpeedMultiplier:U,onWheelHorizontal:me,contentInsets:I,visibleStartIndex:Fe,visibleEndIndex:Xe,renderOverlay:ut,initialScrollPosition:ee.position,children:R})},lr=r.forwardRef(ar);exports.FenwickMapTree=kt;exports.ScrollBar=wt;exports.ScrollPane=Et;exports.VirtualScroll=lr;exports.minmax=de;exports.tapScrollCircleSampleVisual=Qt;exports.useFenwickMapTree=Vt;exports.useHeightCache=nr;exports.useLruCache=At;