@aiquants/virtualscroll 1.12.0 → 1.14.0

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