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