@aiquants/virtualscroll 0.6.1 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +8 -8
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +931 -839
- package/dist/index.js.map +1 -1
- package/dist/src/ScrollBar.d.ts +11 -1
- package/dist/src/ScrollBar.d.ts.map +1 -1
- package/dist/src/ScrollPane.d.ts +8 -0
- package/dist/src/ScrollPane.d.ts.map +1 -1
- package/dist/src/TapScrollCircle.d.ts +17 -1
- package/dist/src/TapScrollCircle.d.ts.map +1 -1
- package/dist/src/VirtualScroll.d.ts +5 -0
- package/dist/src/VirtualScroll.d.ts.map +1 -1
- package/dist/src/index.d.ts +6 -4
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/tapScrollCircleSampleVisual.d.ts +3 -0
- package/dist/src/tapScrollCircleSampleVisual.d.ts.map +1 -0
- package/dist/src/useFenwickMapTree.d.ts +70 -85
- package/dist/src/useFenwickMapTree.d.ts.map +1 -1
- package/dist/virtualscroll.css +1 -1
- package/package.json +2 -2
package/dist/cli.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { spawn as
|
|
3
|
-
import
|
|
4
|
-
import { fileURLToPath as
|
|
5
|
-
const
|
|
2
|
+
import { spawn as i } from "node:child_process";
|
|
3
|
+
import n from "node:path";
|
|
4
|
+
import { fileURLToPath as t } from "node:url";
|
|
5
|
+
const m = t(import.meta.url), a = n.dirname(m), r = process.argv.slice(2);
|
|
6
6
|
if (r[0] === "demo") {
|
|
7
|
-
console.
|
|
8
|
-
const
|
|
9
|
-
cwd:
|
|
7
|
+
console.info("Starting demo server...");
|
|
8
|
+
const s = n.join(a, "..", "demo"), e = i("pnpm", ["run", "dev"], {
|
|
9
|
+
cwd: s,
|
|
10
10
|
stdio: "inherit",
|
|
11
11
|
shell: process.platform === "win32"
|
|
12
12
|
});
|
|
@@ -16,4 +16,4 @@ if (r[0] === "demo") {
|
|
|
16
16
|
console.error("Failed to start demo server:", o);
|
|
17
17
|
});
|
|
18
18
|
} else
|
|
19
|
-
console.
|
|
19
|
+
console.warn(`Unknown command: ${r[0]}`), console.info("Usage: npx @aiquants/virtualscroll demo"), process.exit(1);
|
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const z=require("react/jsx-runtime"),r=require("react"),ce=require("tailwind-merge"),G={debug(u,...e){typeof window<"u"&&window.localStorage?.getItem("debug")==="true"&&console.debug(`[VirtualScroll] ${u}`,...e)},warn(u,...e){console.warn(`[VirtualScroll] ${u}`,...e)},error(u,...e){console.error(`[VirtualScroll] ${u}`,...e)}},D=(u,e,n)=>Math.min(n,Math.max(e,u)),xe={active:!1,offsetY:0,distance:0,direction:0},we=6,Ee=r.forwardRef(({onDragChange:u,className:e,maxVisualDistance:n=160,size:t=64,style:s,opacity:a=1},i)=>{const[p,f]=r.useState(xe),h=r.useRef(null),x=r.useRef({x:0,y:0}),I=r.useRef(null),S=r.useCallback((b,T=!1)=>{const{y:P}=x.current,m=b-P,g=Math.abs(m),y=g<we?0:m<0?-1:1,v={active:T||g>=we,offsetY:m,distance:g,direction:y};f(v),u(v)},[u]),ne=r.useCallback((b=!1)=>{if(b&&h.current!==null){const T=I.current;T?.hasPointerCapture(h.current)&&T.releasePointerCapture(h.current)}h.current=null,f(xe),u(xe)},[u]),se=r.useCallback(b=>{b.preventDefault(),b.stopPropagation();const T=I.current??b.currentTarget,P=T.getBoundingClientRect();x.current={x:P.left+P.width/2,y:P.top+P.height/2},h.current=b.pointerId,T.setPointerCapture(b.pointerId),S(b.clientY,!0)},[S]),O=r.useCallback(b=>{h.current===b.pointerId&&(b.preventDefault(),S(b.clientY))},[S]),Z=r.useCallback(b=>{h.current===b.pointerId&&(b.preventDefault(),b.stopPropagation(),ne(!0))},[ne]);r.useImperativeHandle(i,()=>({reset:()=>{ne(!0)},getElement:()=>I.current}),[ne]);const C=r.useMemo(()=>Math.min(p.distance,n)/n,[p.distance,n]),d=r.useMemo(()=>t/64,[t]),J=r.useMemo(()=>1+C*.4,[C]),E=r.useMemo(()=>p.direction*C*10*d,[p.direction,C,d]),R=r.useMemo(()=>p.direction*C*26*d,[p.direction,C,d]),_=r.useMemo(()=>22*d,[d]),K=r.useMemo(()=>Math.max(2.5,3*d),[d]),$=r.useMemo(()=>6*d,[d]),te=r.useMemo(()=>3*d,[d]),o=r.useMemo(()=>Math.min(Math.max(a,0),1),[a]),j=r.useMemo(()=>{const b={...s,width:t,height:t,transform:`translateY(${E}px)`};return b.opacity=o,b},[o,E,t,s]),N=r.useMemo(()=>Math.abs(R)+$,[$,R]),A=r.useMemo(()=>R>0?te:-Math.abs(R)-te,[te,R]);return z.jsxs("div",{ref:I,className:ce.twMerge("relative flex items-center justify-center touch-none select-none","transition-transform duration-100 ease-out",e),style:j,onPointerDown:se,onPointerMove:O,onPointerUp:Z,onPointerCancel:Z,role:"presentation",children:[z.jsx("div",{className:"absolute inset-0 rounded-full border border-white/40 bg-gradient-to-br from-[#1d4ed8]/60 via-[#60a5fa]/55 to-[#bfdbfe]/40 shadow-md",style:{transform:`scaleY(${J})`,transition:p.active?"transform 40ms ease-out":"transform 200ms ease"}}),z.jsx("div",{className:"absolute left-1/2 top-1/2 h-6 w-6 -translate-x-1/2 -translate-y-1/2 rounded-full border border-white/50 bg-white/85",style:{width:_,height:_,transform:`translate(-50%, calc(-50% + ${R*.3}px)) scale(${1+C*.2})`,transition:p.active?"transform 40ms ease-out":"transform 200ms ease"}}),z.jsx("div",{className:"absolute left-1/2 top-1/2 w-1 rounded-full bg-white/50",style:{width:K,height:N,transform:`translate(-50%, ${A}px)`,opacity:C,transition:p.active?"height 40ms ease-out, opacity 60ms":"height 200ms ease, opacity 120ms"}})]})});Ee.displayName="TapScrollCircle";const Se=(u,e,n)=>{const t="touches"in u.nativeEvent,s=t?u.nativeEvent.touches[0]:u.nativeEvent,a=p=>{t&&p.cancelable&&p.preventDefault();const f="touches"in p?p.touches[0]:p;e({deltaX:f.clientX-s.clientX,deltaY:f.clientY-s.clientY})},i=()=>{t?(document.removeEventListener("touchmove",a),document.removeEventListener("touchend",i)):(document.removeEventListener("mousemove",a),document.removeEventListener("mouseup",i)),n?.()};t?(document.addEventListener("touchmove",a,{passive:!1}),document.addEventListener("touchend",i)):(document.addEventListener("mousemove",a),document.addEventListener("mouseup",i))},ve="virtualscroll:tap-scroll-cancel",ye=20,De=250,_e=60,Fe=20,Ne=20,ze=220,Ie={active:!1,offsetY:0,distance:0,direction:0},be=2.2,Oe=8,Ye=120,ie={enabled:!0,size:64,offsetX:-80,offsetY:0,className:void 0,maxVisualDistance:ze,opacity:1},He=u=>{if(!u||u<=0)return be;const e=Math.max(1,u),n=Math.log10(e),t=be+n*Oe;return D(t,be,Ye)},Ve=({contentSize:u,viewportSize:e,scrollPosition:n,onScroll:t,horizontal:s=!1,scrollBarWidth:a=12,className:i,ariaControls:p,tapScrollCircleOptions:f,itemCount:h})=>{const[x,I]=r.useState(!1),[S,ne]=r.useState(!1),se=r.useRef(null),O=r.useRef(n),Z=r.useRef(null),C=r.useRef(null),d=r.useRef(Ie),J=r.useRef(null),E=r.useRef(null),R=r.useRef(null),_=r.useMemo(()=>{const c=f?.maxSpeedMultiplier,L=typeof c=="number"?c:He(h);return{enabled:f?.enabled??ie.enabled,size:f?.size??ie.size,offsetX:f?.offsetX??ie.offsetX,offsetY:f?.offsetY??ie.offsetY,className:f?.className??ie.className,maxVisualDistance:f?.maxVisualDistance??ie.maxVisualDistance,maxSpeedMultiplier:L,opacity:D(f?.opacity??ie.opacity,0,1)}},[h,f]),{enabled:K,size:$,offsetX:te,offsetY:o,className:j,maxVisualDistance:N,maxSpeedMultiplier:A,opacity:b}=_,T=Math.max(N,1),P=e/u,m=a,g=Math.max(e-m*2,0),y=P*g,v=Math.min(Math.max(ye,y||0),g||ye),w=u-e,k=Math.max(g-v,0),Y=w<=0||k<=0?0:n/w*k,V=u>e;r.useEffect(()=>{O.current=n},[n]),r.useEffect(()=>{se.current&&(x?se.current.style.backgroundColor="#4F4F4F":se.current.style.backgroundColor="#7F7F7F")},[x]);const U=r.useCallback(()=>{Z.current!==null&&(window.clearInterval(Z.current),Z.current=null),C.current!==null&&(window.clearTimeout(C.current),C.current=null)},[]),F=r.useCallback(()=>{E.current!==null&&(window.cancelAnimationFrame(E.current),E.current=null),R.current=null},[]),M=r.useCallback(()=>{d.current={...Ie},ne(!1),J.current?.reset(),F()},[F]),q=r.useCallback(c=>{const L=d.current;if(!L.active||L.direction===0){F();return}if(!V||w<=0){F();return}const W=R.current??c,X=Math.max((c-W)/1e3,0);if(R.current=c,X<=0){E.current=window.requestAnimationFrame(q);return}const he=(Math.min(L.distance,T)/T)**1.1,ae=Math.max(e*.2,40),me=Math.max(e*A,1200),pe=ae+(me-ae)*he,fe=O.current,ge=D(fe+L.direction*pe*X,0,w);if(ge===fe){F();return}O.current=ge,t?.(ge,fe),E.current=window.requestAnimationFrame(q)},[T,w,t,V,F,A,e]),re=r.useCallback(()=>{E.current===null&&(R.current=null,E.current=window.requestAnimationFrame(q))},[q]);r.useEffect(()=>()=>{U(),F()},[U,F]);const Q=r.useCallback(c=>{d.current=c,ne(c.active),c.active&&c.direction!==0?re():F()},[re,F]);r.useEffect(()=>{K||M()},[M,K]),r.useEffect(()=>{const c=L=>{const X=L.detail?.paneId;X&&p&&X!==p||M()};return window.addEventListener(ve,c),()=>{window.removeEventListener(ve,c)}},[p,M]),r.useEffect(()=>{if(!K)return;const c=L=>{if(!d.current.active)return;const W=L.target;if(!(W instanceof Node)){M();return}J.current?.getElement()?.contains(W)||M()};return document.addEventListener("pointerdown",c,!0),()=>{document.removeEventListener("pointerdown",c,!0)}},[M,K]);const l=c=>{if(!V||k<=0||w<=0)return 0;const L=D(c,0,k);return D(L/k*w,0,w)},B=c=>{if(!V||w<=0)return;const L=Math.max(Math.round(e/Ne),Fe),W=O.current,X=D(W+c*L,0,w);X!==W&&(O.current=X,t?.(X,W))},H=()=>{U()},ee=c=>L=>{V&&(L.preventDefault(),L.stopPropagation(),M(),U(),B(c),C.current=window.setTimeout(()=>{Z.current=window.setInterval(()=>{B(c)},_e)},De))},oe=c=>L=>{(L.key==="Enter"||L.key===" "||L.key==="Spacebar")&&(L.preventDefault(),B(c))},ue=c=>{if(!V||"button"in c&&c.button!==0||c.ctrlKey)return;c.stopPropagation(),M();const L=Y;I(!0),Se(c,({deltaX:W,deltaY:X})=>{t?.(l(L+(s?W:X)),Y)},()=>{I(!1)})},Te=c=>{if(!V||"button"in c&&c.button!==0||c.ctrlKey)return;const W="touches"in c.nativeEvent?c.nativeEvent.touches[0]:c.nativeEvent,X=s?W.clientX:W.clientY,de=c.currentTarget.getBoundingClientRect(),he=s?X-de.left:X-de.top;M();const ae=he-v/2;t?.(l(ae),Y),Se(c,({deltaX:me,deltaY:pe})=>{t?.(l(ae+(s?me:pe)),Y)})},Ce=r.useMemo(()=>D((S?1:.8)*b,0,1),[S,b]),ke=r.useMemo(()=>{const L=`calc(50% - ${$/2}px + ${o}px)`;return{left:te,top:L}},[te,o,$]);return z.jsxs("div",{className:ce.twMerge("group relative cursor-default select-none",s?"flex flex-row items-stretch":"flex flex-col items-stretch",i),style:{[s?"width":"height"]:e,[s?"height":"width"]:a,backgroundColor:"white",userSelect:"none",position:"relative"},role:"scrollbar",tabIndex:-1,"aria-controls":p,"aria-valuenow":n,"aria-valuemin":0,"aria-valuemax":w,"aria-orientation":s?"horizontal":"vertical",children:[!s&&V&&K&&z.jsx(Ee,{ref:J,className:ce.twMerge("pointer-events-auto absolute transition-opacity duration-150",j),size:$,maxVisualDistance:T,style:ke,opacity:Ce,onDragChange:Q}),z.jsx("button",{type:"button",className:"flex items-center justify-center text-xs text-[#313131] transition-colors focus:outline-none focus-visible:ring-2 focus-visible:ring-[#60a5fa] focus-visible:ring-offset-1 disabled:cursor-not-allowed disabled:opacity-50",style:{[s?"width":"height"]:m,[s?"height":"width"]:a,backgroundColor:"#E0E0E0"},"aria-label":s?"Scroll left":"Scroll up",onMouseDown:ee(-1),onTouchStart:ee(-1),onMouseUp:H,onMouseLeave:H,onTouchEnd:H,onTouchCancel:H,onKeyDown:oe(-1),disabled:!V,children:z.jsx("span",{"aria-hidden":"true",children:s?"◀":"▲"})}),z.jsx("div",{className:"relative flex-1",style:{backgroundColor:"#F5F5F5",borderRadius:a/2},onMouseDown:Te,onTouchStart:Te,children:u>e&&z.jsx("div",{className:"group absolute",style:{[s?"width":"height"]:v,[s?"left":"top"]:Y,...s?{top:0,bottom:0}:{left:0,right:0}},onMouseDown:ue,onTouchStart:ue,role:"slider","aria-orientation":s?"horizontal":"vertical","aria-valuenow":n,"aria-valuemin":0,"aria-valuemax":w,tabIndex:0,children:z.jsx("div",{ref:se,className:ce.twMerge("absolute",s?`inset-x-0 inset-y-[1.5px] group-hover:inset-y-[-0.5px] ${x?"inset-y-[-2px]":"group-active:inset-y-[-2px]"}`:`inset-x-[1.5px] inset-y-0 group-hover:inset-x-[-0.5px] ${x?"inset-x-[-2px]":"group-active:inset-x-[-2px]"}`),style:{backgroundColor:"#7F7F7F",borderRadius:a-1,...s?{left:0,right:0,top:x?-2:1.5,bottom:x?-2:1.5}:{top:0,bottom:0,left:x?-2:1.5,right:x?-2:1.5}},onMouseEnter:c=>{s?(c.currentTarget.style.top="-0.5px",c.currentTarget.style.bottom="-0.5px"):(c.currentTarget.style.left="-0.5px",c.currentTarget.style.right="-0.5px"),x||(c.currentTarget.style.backgroundColor="#5F5F5F")},onMouseLeave:c=>{s?(c.currentTarget.style.top=x?"-2px":"1.5px",c.currentTarget.style.bottom=x?"-2px":"1.5px"):(c.currentTarget.style.left=x?"-2px":"1.5px",c.currentTarget.style.right=x?"-2px":"1.5px"),x||(c.currentTarget.style.backgroundColor="#7F7F7F")}})})}),z.jsx("button",{type:"button",className:"flex items-center justify-center text-xs text-[#313131] transition-colors focus:outline-none focus-visible:ring-2 focus-visible:ring-[#60a5fa] focus-visible:ring-offset-1 disabled:cursor-not-allowed disabled:opacity-50",style:{[s?"width":"height"]:m,[s?"height":"width"]:a,backgroundColor:"#E0E0E0"},"aria-label":s?"Scroll right":"Scroll down",onMouseDown:ee(1),onTouchStart:ee(1),onMouseUp:H,onMouseLeave:H,onTouchEnd:H,onTouchCancel:H,onKeyDown:oe(1),disabled:!V,children:z.jsx("span",{"aria-hidden":"true",children:s?"▶":"▼"})})]})},le={maxVelocity:6,minVelocity:.02,deceleration:.0025,velocitySampleWindow:90,startVelocityThreshold:.04},Pe=r.forwardRef(({children:u,contentSize:e,viewportSize:n,scrollBarWidth:t=12,onScroll:s,className:a,style:i,background:p,tapScrollCircleOptions:f,inertiaOptions:h,itemCount:x},I)=>{const S=r.useRef(0),[ne,se]=r.useReducer(o=>o+1,0),O=r.useRef(null),Z=r.useRef(null),C=r.useRef({frame:null,velocity:0,lastTimestamp:null}),d=r.useMemo(()=>({maxVelocity:h?.maxVelocity??le.maxVelocity,minVelocity:h?.minVelocity??le.minVelocity,deceleration:h?.deceleration??le.deceleration,velocitySampleWindow:h?.velocitySampleWindow??le.velocitySampleWindow,startVelocityThreshold:h?.startVelocityThreshold??le.startVelocityThreshold}),[h]);G.debug("[ScrollPane] ScrollPane rendered",{contentSize:e,viewportSize:n,scrollBarWidth:t,className:a,style:i,tapScrollCircleOptions:f,inertiaOptions:h});const J=r.useRef({contentSize:e,viewportSize:n}),E=r.useMemo(()=>e>n,[e,n]),R=r.useCallback(o=>{const{contentSize:j,viewportSize:N}=J.current,A=j>N,b=S.current;if(G.debug("[ScrollPane] scrollTo called",{newPosition:o,contentSize:j,viewportSize:N,currentIsScrollable:A,prevPosition:b}),!A){S.current!==0&&(S.current=0,s?.(0,b));return}const T=typeof o=="function"?o(S.current):o,P=D(T,0,j-N);S.current!==P&&(S.current=P,s?.(P,b))},[s]),_=r.useCallback(()=>{const o=C.current;o.frame!==null&&cancelAnimationFrame(o.frame),o.frame=null,o.velocity=0,o.lastTimestamp=null},[]),K=r.useCallback(o=>{if(!E)return;const{maxVelocity:j,minVelocity:N,deceleration:A,startVelocityThreshold:b}=d,T=D(o,-j,j);if(Math.abs(T)<b)return;_(),C.current.velocity=T,C.current.lastTimestamp=null;const P=m=>{const g=C.current;if(g.lastTimestamp===null){g.lastTimestamp=m,g.frame=requestAnimationFrame(P);return}const y=m-g.lastTimestamp;if(g.lastTimestamp=m,y<=0){g.frame=requestAnimationFrame(P);return}const v=g.velocity;let w=v;const k=A*y;v>0?w=Math.max(0,v-k):v<0&&(w=Math.min(0,v+k));const V=(v+w)/2*y,U=S.current;V!==0&&R(l=>l+V);const F=S.current,{contentSize:M,viewportSize:q}=J.current,re=Math.max(M-q,0);g.velocity=w;const Q=F===U||F<=0&&w<=0||F>=re&&w>=0;if(Math.abs(w)<N||Q){_();return}g.frame=requestAnimationFrame(P)};C.current.frame=requestAnimationFrame(P)},[E,d,R,_]);r.useLayoutEffect(()=>{J.current={contentSize:e,viewportSize:n}},[e,n]),r.useLayoutEffect(()=>{if(E){G.debug("[ScrollPane] Adjusting scroll position due to content or viewport size change",{contentSize:e,viewportSize:n,scrollPosition:S.current});const o=D(e-n,0,e);S.current>o&&R(o)}else R(0)},[E,R,e,n]),r.useEffect(()=>{const o=N=>{if(!E)return;N.preventDefault(),_();let A=N.deltaY;N.deltaMode===1?A*=16:N.deltaMode===2&&(A*=n),G.debug("[ScrollPane] wheel event",{deltaY:A,scrollPosition:S.current}),R(b=>b+A)},j=O.current;return j&&j.addEventListener("wheel",o,{passive:!1}),()=>{j&&j.removeEventListener("wheel",o)}},[E,R,_,n]),r.useImperativeHandle(I,()=>({scrollTo:R,getScrollPosition:()=>S.current,getContentSize:()=>e,getViewportSize:()=>n}),[R,e,n]);const $=r.useId(),te=r.useMemo(()=>z.jsxs("div",{ref:O,className:ce.twMerge("flex",a),style:i,children:[z.jsxs("div",{ref:Z,className:"relative h-full flex-1 overflow-hidden",style:{height:n,touchAction:"none"},id:$,children:[p,u(S.current)]}),E&&z.jsx(Ve,{contentSize:e,viewportSize:n,scrollPosition:S.current,onScroll:R,scrollBarWidth:t,ariaControls:$,tapScrollCircleOptions:f,itemCount:x})]}),[u,e,n,t,a,i,E,R,$,p,f,x]);return r.useEffect(()=>{const o=Z.current;if(!o)return;const j=6,N="input, textarea, select, button, a[href], [role='button']";let A=null,b=0,T=0,P=!1,m=!1,g=!1,y=null,v=[];const w=()=>{A=null,b=0,T=0,P=!1,m=!1,v=[]},k=l=>{const B=performance.now();v.push({clientY:l,time:B}),v=v.filter(H=>B-H.time<=d.velocitySampleWindow)},Y=l=>l instanceof HTMLElement?l.closest("[data-scrollpane-ignore-drag='true']")!==null:!1,V=l=>l instanceof HTMLElement?l.closest(N)!==null:!1,U=l=>{g&&(l.preventDefault(),l.stopPropagation(),g=!1)},F=l=>{P||(P=!0,m=!1,g=!0,o.hasPointerCapture(l.pointerId)||o.setPointerCapture(l.pointerId),k(l.clientY))},M=l=>{if(A!==l.pointerId)return;if(!P){const ee=Math.abs(l.clientY-b);if(m&&ee<j)return;F(l)}if(!P)return;k(l.clientY);const B=l.clientY-b,H=T-B;R(H),l.cancelable&&l.preventDefault()},q=l=>{if(A!==l.pointerId)return;P&&g&&l.cancelable&&(l.preventDefault(),l.stopPropagation()),o.hasPointerCapture(l.pointerId)&&o.releasePointerCapture(l.pointerId);let B=0;if(P&&v.length>=2){const H=v[v.length-1],ee=v.find(oe=>H.time-oe.time<=d.velocitySampleWindow)??v[0];if(H&&ee&&H.time!==ee.time){const oe=H.clientY-ee.clientY,ue=H.time-ee.time;B=-(oe/ue)}}w(),y!==null&&window.clearTimeout(y),g&&(y=window.setTimeout(()=>{g=!1,y=null},0)),Math.abs(B)>=d.startVelocityThreshold&&K(B)},re=l=>{E&&(l.button!==0&&l.pointerType==="mouse"||l.ctrlKey||l.metaKey||l.altKey||Y(l.target)||(window.dispatchEvent(new CustomEvent(ve,{detail:{paneId:$}})),_(),A=l.pointerId,b=l.clientY,T=S.current,m=V(l.target),P=!1,g=!1,v=[],m||(g=!0,F(l),k(l.clientY),l.cancelable&&l.preventDefault())))},Q=l=>{A===l.pointerId&&(g=!1,o.hasPointerCapture(l.pointerId)&&o.releasePointerCapture(l.pointerId),y!==null&&(window.clearTimeout(y),y=null),w())};return o.addEventListener("click",U,!0),o.addEventListener("pointerdown",re,{passive:!1}),o.addEventListener("pointermove",M,{passive:!1}),o.addEventListener("pointerup",q),o.addEventListener("pointercancel",Q),window.addEventListener("pointermove",M,{passive:!1}),window.addEventListener("pointerup",q),window.addEventListener("pointercancel",Q),()=>{o.removeEventListener("click",U,!0),o.removeEventListener("pointerdown",re),o.removeEventListener("pointermove",M),o.removeEventListener("pointerup",q),o.removeEventListener("pointercancel",Q),window.removeEventListener("pointermove",M),window.removeEventListener("pointerup",q),window.removeEventListener("pointercancel",Q),A!==null&&o.hasPointerCapture(A)&&o.releasePointerCapture(A),y!==null&&window.clearTimeout(y),_()}},[$,E,d,R,K,_]),te});class Re{tree;deltas;size;baseValue;valueFn;total;constructor(e,n,t){this.reset(e,n,t)}reset(e,n,t){if(this.size=e,this.tree=new Map,this.deltas=new Map,this.total=void 0,typeof n=="function"){if(this.valueFn=n,this.size>0){const a=t?.sampleRange??{from:0,to:Math.min(99,this.size-1)},{mode:i,materializedValues:p}=this._calculateMode(a.from,a.to);if(this.baseValue=i,t?.materialize)for(let f=0;f<p.length;f++){const h=p[f],x=a.from+f;if(x>=this.size)break;const I=h-this.baseValue;this.deltas.set(x,I),this._updateTree(x,I)}}else this.baseValue=0;this.total=this.getTotal()}else this.valueFn=void 0,this.baseValue=n,this.total=this.baseValue*this.size}setValueFn(e){typeof e=="function"?this.valueFn=e:(this.valueFn=void 0,this.baseValue=e)}_calculateMode(e,n){if(!this.valueFn)return{mode:0,materializedValues:[]};const t=[];for(let h=e;h<=n&&!(h>=this.size);h++)t.push(this.valueFn(h));const s=[...t];if(t.length===0)return{mode:0,materializedValues:[]};t.sort((h,x)=>h-x);const a=Math.floor(t.length/2);let i;t.length%2===0?i=Math.floor((t[a-1]+t[a])/2):i=t[a];const p=new Map;let f=0;for(const h of t){const x=(p.get(h)??0)+1;p.set(h,x),x>f&&(f=x)}if(f>1){const h=[];for(const[I,S]of p.entries())S===f&&h.push(I);const x=h.reduce((I,S)=>I+S,0);i=Math.floor(x/h.length)}return{mode:i,materializedValues:s}}update(e,n){return this.updates([{index:e,value:n}])}updates(e){const n=e.map(({index:t,value:s})=>{if(t<0||t>=this.size)throw new Error(`Index ${t} out of bounds`);if(s<0)throw new Error("Value cannot be negative.");const a=this.deltas.has(t)?(this.deltas.get(t)??0)+this.baseValue:this.baseValue,i=s-a;return{index:t,change:i}}).filter(t=>t.change!==0);return n.length>0?this.updateDeltas(n):this.total}updateDelta(e,n){return this.updateDeltas([{index:e,change:n}])}updateDeltas(e){for(const{index:n,change:t}of e){if(n<0||n>=this.size)throw new Error(`Index ${n} out of bounds`);const s=this.deltas.get(n)??0;this.deltas.set(n,s+t),this._updateTree(n,t)}return this.total}_updateTree(e,n){if(n===0)return;let t=e+1;for(;t<=this.size;)this.tree.set(t,(this.tree.get(t)??0)+n),t+=t&-t;this.total!==void 0&&(this.total+=n)}_materialize(e,n=!0){if(this.valueFn){const t=this.deltas.get(e)??0,a=this.valueFn(e)-this.baseValue;if(a!==t&&(this.deltas.set(e,a),n)){const i=a-t;this._updateTree(e,i)}}}prefixSum(e,n){if(e<0)return{cumulative:0,total:this.total,currentValue:0,safeIndex:0};const t=D(e,0,this.size-1),s=n?.materializeOption;if(s?.materialize&&this.valueFn){if(s.ranges)for(const f of s.ranges){const h=f.from,x=Math.min(f.to,this.size-1);for(let I=h;I<=x;I++)this._materialize(I)}this._materialize(t)}let a=0,i=t+1;for(;i>0;){const f=this.tree.get(i)??0;a+=f,i-=i&-i}const p=s?.materialize?this.get(t):(this.deltas.get(t)||0)+this.baseValue;return{cumulative:a+this.baseValue*(t+1),total:this.total,currentValue:p,safeIndex:t}}get(e,n){if(e<0||e>=this.size)throw new Error("Index out of bounds");const t=n?.materializeOption;if(t?.materialize&&this.valueFn)if(t.ranges){for(const s of t.ranges){const a=s.from,i=Math.min(s.to,this.size-1);for(let p=a;p<=i;p++)this._materialize(p)}e>=t.ranges[0].from&&e<=t.ranges[t.ranges.length-1].to&&this._materialize(e)}else this._materialize(e);return(this.deltas.get(e)??0)+this.baseValue}getTotal(e){const n=e?.materializeOption;if(n?.materialize&&this.valueFn&&n.ranges)for(const t of n.ranges){const s=t.from,a=Math.min(t.to,this.size-1);for(let i=s;i<=a;i++)this._materialize(i)}if(this.total===void 0)if(this.size===0)this.total=0;else{let t=this.baseValue*this.size;for(const s of this.deltas.values())t+=s;this.total=t,console.assert(this.prefixSum(this.getSize()-1).cumulative===this.prefixSum(this.getSize()-1).total,"Inconsistent Fenwick Tree state")}return this.total}rebuildTree(e){if(e?.materialize&&this.valueFn){const s=this.valueFn;this.reset(this.size,a=>s(a),{materialize:!0});return}const n=new Map;let t=this.baseValue*this.size;for(const[s,a]of this.deltas.entries()){if(t+=a,a===0)continue;let i=s+1;for(;i<=this.size;)n.set(i,(n.get(i)??0)+a),i+=i&-i}this.tree=n,this.total=t}calculateAccumulatedError(){if(this.total===void 0)return 0;let e=this.baseValue*this.size;for(const n of this.deltas.values())e+=n;return this.total-e}changeSize(e){const n=this.size;if(e!==n){if(e<n)for(const t of this.deltas.keys())t>=e&&this.deltas.delete(t);this.size=e,this.rebuildTree(),console.assert(this.prefixSum(this.getSize()-1).cumulative===this.prefixSum(this.getSize()-1).total,"Inconsistent Fenwick Tree state")}}getSize(){return this.size}findIndexAtOrAfter(e,n){if(this.size===0)return{index:-1,total:this.total??0,cumulative:void 0,currentValue:void 0,safeIndex:void 0};let t=0,s=this.size-1,a=-1,i,p=this.total;for(;t<=s;){const f=Math.floor((t+s)/2);i=this.prefixSum(f,n),p=i.total,i.cumulative>=e?(a=f,s=f-1):t=f+1}return{index:a,total:p,cumulative:i?.cumulative,currentValue:i?.currentValue,safeIndex:i?.safeIndex}}findIndexAtOrBefore(e,n){if(this.size===0)return{index:-1,total:this.total??0,cumulative:void 0,currentValue:void 0,safeIndex:void 0};let t=0,s=this.size-1,a=-1,i,p=this.total;for(;t<=s;){const f=Math.floor((t+s)/2);i=this.prefixSum(f,n),p=i.total,i.cumulative<=e?(a=f,t=f+1):s=f-1}return{index:a,total:p,cumulative:i?.cumulative,currentValue:i?.currentValue,safeIndex:i?.safeIndex}}}const Le=(u,e,n)=>{const t=Math.max(0,u),s=r.useRef(null),a=r.useMemo(()=>new Re(t,e,n),[t,e,n]);return Object.is(s.current,a)||console.warn("[useFenwickMapTree] instance changed"),s.current=a,a};function je({itemCount:u,getItem:e,getItemHeight:n,viewportSize:t,overscanCount:s=5,className:a,onScroll:i,onRangeChange:p,children:f,background:h,initialScrollIndex:x,initialScrollOffset:I,tapScrollCircleOptions:S,inertiaOptions:ne},se){const O=r.useRef(null),Z=r.useRef(!1);r.useEffect(()=>(Z.current=!0,()=>{Z.current=!1}),[]);const C=r.useRef({size:u,valueOrFn:n,options:{sampleRange:{from:0,to:100}}}),d=Le(C.current.size,C.current.valueOrFn,C.current.options),[J]=r.useState(()=>{let m=0,g=0;if(typeof x=="number"){const y=D(x,0,u-1),v=D(y-s*2,0,u-1),w=D(y+s*2,0,u-1),k=x>0?{materializeOption:{materialize:!0,ranges:[{from:v,to:w}]}}:void 0,{cumulative:Y,total:V,currentValue:U}=d.prefixSum(x,k);m=Y-U,g=V??d.getTotal()}else typeof I=="number"&&(m=I),g=d.getTotal();return{position:m,total:g}}),[E,R]=r.useState(J.position),[_,K]=r.useState(J.total),[$,te]=r.useState(J.position),[o,j]=r.useState(u);r.useLayoutEffect(()=>{d.setValueFn(n),o!==u&&(d.changeSize(u),j(u));const m=d.getTotal();_!==m&&K(m)},[d,o,u,_,n]),r.useLayoutEffect(()=>{$!==null&&O.current&&(G.debug("[VirtualScroll] Scrolling to position:",$),O.current.scrollTo($),te(null))},[$]);const N=r.useCallback(m=>{if(O.current){G.debug("[VirtualScroll] Scrolling to index:",m);const g=D(m,0,o-1),y=D(g-s*2,0,o-1),v=D(g+s*2,0,o-1),{cumulative:w,total:k,currentValue:Y}=d.prefixSum(g,{materializeOption:{materialize:!0,ranges:[{from:y,to:v}]}});G.debug("[VirtualScroll] Scrolling to index:",m,"Offset:",w,"Total height:",k,"Current value:",Y,"safeIndex:",g,"safeIndexFrom:",y,"safeIndexTo:",v),k&&(K(k),te(w-Y)),G.debug("[VirtualScroll] Setting scroll position to:",w-Y)}},[d,s,o]),A=r.useCallback(m=>{if(O.current){const g=d.getTotal(),y=D(Math.floor(m),0,g),v=d.findIndexAtOrAfter(y,{materializeOption:{materialize:!1}}).index;N(v)}},[d,N]),b=r.useCallback((m,g)=>{G.debug("[VirtualScroll] Scroll position changed:",m),R(m);const y=d.getTotal();i?.(m,y)},[d,i]),T=r.useMemo(()=>{if(o===0)return{renderingStartIndex:0,renderingEndIndex:0,visibleStartIndex:0,visibleEndIndex:0};const{index:m,cumulative:g,currentValue:y}=d.findIndexAtOrAfter(E,{materializeOption:{materialize:!1}});let v=0;m===-1?v=0:(g??0)<E+(y??0)?v=1:v=0;const w=m===-1?0:m+v,k=D(w-s,0,o-1);let Y=0,V=m===-1?0:m+v;for(;V<o&&Y<t;){const F=n(V);Y+=F,V++}V-=1;const U=D(V+s,0,o-1);return G.debug("[VirtualScroll] Calculated rendering range:",{renderingStartIndex:k,renderingEndIndex:U,visibleStartIndex:w,visibleEndIndex:V,scrollPosition:E,renderingContentSize:d.getTotal(),overscanCount:s,viewportSize:t}),{renderingStartIndex:k,renderingEndIndex:U,visibleStartIndex:w,visibleEndIndex:V}},[E,s,t,n,d,o]);r.useEffect(()=>{const m=O.current?.getScrollPosition()??0;G.debug("[VirtualScroll] Range change effect triggered",{renderingStartIndex:T.renderingStartIndex,renderingEndIndex:T.renderingEndIndex,visibleStartIndex:T.visibleStartIndex,visibleEndIndex:T.visibleEndIndex,scrollPosition:E,contentSize:_,scrollPaneScrollPosition:m}),p?.(T.renderingStartIndex,T.renderingEndIndex,T.visibleStartIndex,T.visibleEndIndex,E,_)},[T.renderingStartIndex,T.renderingEndIndex,T.visibleStartIndex,T.visibleEndIndex,p,E,_]);const P=r.useCallback(m=>{const{renderingStartIndex:g,renderingEndIndex:y}=T;if(G.debug("[VirtualScroll] Rendering visible items",{currentScrollPosition:m,renderingStartIndex:g,renderingEndIndex:y,fenwickSize:o,viewportSize:t}),o===0)return z.jsx("div",{className:"absolute w-full",style:{top:0},children:z.jsx("div",{className:"text-center text-gray-500",children:"No items"})});const v=D(g,0,o-1),{cumulative:w,currentValue:k}=d.prefixSum(v,{materializeOption:{materialize:!1}}),Y=w-k,V=[],U=[];for(let M=g;M<=y;M++){const q=n(M);V.push({item:e(M),height:q}),d.get(M)!==q&&U.push({index:M,value:q})}U.length>0&&Promise.resolve().then(()=>{const M=d.updates(U);M&&(K(M),G.debug("[VirtualScroll] Updated heights for items",U,"New total height:",M))});const F=_<t?0:Y-m;return G.debug("[VirtualScroll] Rendering items",{visibleItems:V,containerTop:F}),z.jsx("div",{className:"absolute w-full",style:{top:F},children:V.map(({item:M,height:q},re)=>{const Q=g+re,l=D(Q,0,o-1),{cumulative:B,currentValue:H}=d.prefixSum(l,{materializeOption:{materialize:!1}}),ee=B-H;return z.jsx("div",{"data-index":Q,style:{position:"absolute",top:ee-Y,width:"100%"},children:f(M,Q)},Q)})})},[e,f,_,t,T,d,o,n]);return r.useImperativeHandle(se,()=>({getScrollPosition:()=>O.current?.getScrollPosition()??-1,getContentSize:()=>O.current?.getContentSize()??-1,getViewportSize:()=>O.current?.getViewportSize()??-1,scrollTo:m=>A(m),scrollToIndex:m=>N(m),getFenwickTreeTotalHeight:()=>d.getTotal(),getFenwickSize:()=>d.getSize()}),[N,d,A]),z.jsx(Pe,{ref:O,contentSize:_,viewportSize:t,className:a,onScroll:b,background:h,tapScrollCircleOptions:S,inertiaOptions:ne,itemCount:u,children:P})}const Ue=r.forwardRef(je);class $e{key;value;prev=null;next=null;constructor(e,n){this.key=e,this.value=n}}class Me{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 Ae(u){const e=r.useRef(new Map),n=r.useRef(new Me);r.useEffect(()=>{for(;e.current.size>u;){const h=n.current.removeHead();if(h)e.current.delete(h.key);else break}},[u]);const t=r.useCallback(h=>{const x=e.current.get(h);if(x)return n.current.moveToTail(x),x.value},[]),s=r.useCallback((h,x)=>{if(u<=0)return;let I=e.current.get(h);if(I)I.value=x,n.current.moveToTail(I);else{if(e.current.size>=u){const S=n.current.removeHead();S&&e.current.delete(S.key)}I=new $e(h,x),e.current.set(h,I),n.current.addToTail(I)}},[u]),a=r.useCallback(h=>e.current.has(h),[]),i=r.useCallback(()=>{e.current.clear(),n.current=new Me},[]),[p,f]=r.useState(()=>({get:t,set:s,has:a,clear:i}));return r.useEffect(()=>f({get:t,set:s,has:a,clear:i}),[t,s,a,i]),p}const qe=1e4,Xe=()=>{const{get:u,set:e,has:n,clear:t}=Ae(qe);return{get:u,set:e,has:n,clear:t}};exports.FenwickMapTree=Re;exports.ScrollBar=Ve;exports.ScrollPane=Pe;exports.VirtualScroll=Ue;exports.minmax=D;exports.useFenwickMapTree=Le;exports.useHeightCache=Xe;exports.useLruCache=Ae;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const E=require("react/jsx-runtime"),n=require("react"),be=require("tailwind-merge"),Ne={active:!1,offsetX:0,offsetY:0,distance:0,direction:0},Oe=6,et=({dragState:a,normalizedDistance:e})=>{const t=1+e*.18,s=.16+e*.24,r=.38+e*.28,i=a.active?"80ms ease-out":"220ms ease";return E.jsxs(E.Fragment,{children:[E.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:`${i}, ${a.active?"80ms":"260ms"} box-shadow ease`}}),E.jsx("div",{className:"absolute inset-[18%] rounded-full",style:{background:"linear-gradient(140deg, rgba(255,255,255,0.72), rgba(28,28,28,0.58))",boxShadow:"inset 0 4px 10px rgba(0,0,0,0.24), inset 0 0 2px rgba(255,255,255,0.55)",opacity:r,transition:a.active?"120ms opacity ease-out":"220ms opacity ease"}})]})},Xe=n.forwardRef(({onDragChange:a,className:e,maxVisualDistance:t=160,size:s=40,style:r,opacity:i=1,renderVisual:c},l)=>{const[m,d]=n.useState(Ne),f=n.useRef(null),g=n.useRef({x:0,y:0}),A=n.useRef(null),V=n.useCallback(p=>{d(p),a(p)},[a]),H=n.useCallback((p,D,h=!1)=>{const{x:k,y:x}=g.current,N=p-k,L=D-x,F=Math.abs(L),R=F<Oe?0:L<0?-1:1;V({active:h||F>=Oe,offsetX:N,offsetY:L,distance:F,direction:R})},[V]),Q=n.useCallback(p=>{if(p===null)return;const D=A.current;D?.hasPointerCapture(p)&&D.releasePointerCapture(p)},[]),T=n.useCallback((p=!1)=>{p&&Q(f.current),f.current=null,V(Ne)},[V,Q]),oe=n.useCallback(p=>{p.preventDefault(),p.stopPropagation();const D=A.current??p.currentTarget,{left:h,top:k,width:x,height:N}=D.getBoundingClientRect();g.current={x:h+x/2,y:k+N/2},f.current=p.pointerId,D.setPointerCapture(p.pointerId),H(p.clientX,p.clientY,!0)},[H]),ae=n.useCallback(p=>{f.current===p.pointerId&&(p.preventDefault(),H(p.clientX,p.clientY))},[H]),G=n.useCallback(p=>{f.current===p.pointerId&&(p.preventDefault(),p.stopPropagation(),T(!0))},[T]);n.useImperativeHandle(l,()=>({reset:()=>{T(!0)},getElement:()=>A.current}),[T]);const _=Math.min(Math.max(i,0),1),$=s/64,O=Math.min(m.distance,t)/t,b=m.direction*O*10*$,P=c??et,S={dragState:m,normalizedDistance:O,sizeScale:$,size:s,opacity:_},j={...r,width:s,height:s,transform:`translateY(${b}px)`};return j.opacity=_,E.jsx("div",{ref:A,className:be.twMerge("relative flex touch-none select-none items-center justify-center","transition-transform duration-100 ease-out",e),style:j,onPointerDown:oe,onPointerMove:ae,onPointerUp:G,onPointerCancel:G,role:"presentation",children:P(S)})});Xe.displayName="TapScrollCircle";const U=(a,e,t)=>Math.min(t,Math.max(e,a)),Ye=(a,e,t)=>{const s="touches"in a.nativeEvent,r=s?a.nativeEvent.touches[0]:a.nativeEvent,i=l=>{s&&l.cancelable&&l.preventDefault();const m="touches"in l?l.touches[0]:l;e({deltaX:m.clientX-r.clientX,deltaY:m.clientY-r.clientY})},c=()=>{s?(document.removeEventListener("touchmove",i),document.removeEventListener("touchend",c)):(document.removeEventListener("mousemove",i),document.removeEventListener("mouseup",c)),t?.()};s?(document.addEventListener("touchmove",i,{passive:!1}),document.addEventListener("touchend",c)):(document.addEventListener("mousemove",i),document.addEventListener("mouseup",c))},Ce="virtualscroll:tap-scroll-cancel",ze=20,tt=250,st=60,nt=20,rt=20,ot=220,je={active:!1,offsetX:0,offsetY:0,distance:0,direction:0},Re=2.2,at=8,it=120,fe={enabled:!0,size:40,offsetX:-80,offsetY:0,className:void 0,maxVisualDistance:ot,opacity:1,renderVisual:void 0},lt=a=>{if(!a||a<=0)return Re;const e=Math.max(1,a),t=Math.log10(e),s=Re+t*at;return U(s,Re,it)},Ue=({contentSize:a,viewportSize:e,scrollPosition:t,onScroll:s,enableThumbDrag:r=!0,enableTrackClick:i=!0,enableArrowButtons:c=!0,horizontal:l=!1,scrollBarWidth:m=12,className:d,ariaControls:f,tapScrollCircleOptions:g,itemCount:A})=>{const[V,H]=n.useState(!1),[Q,T]=n.useState(!1),[oe,ae]=n.useState(!1),G=n.useRef(null),_=n.useRef(t),$=n.useRef(null),O=n.useRef(null),b=n.useRef(je),P=n.useRef(null),S=n.useRef(null),j=n.useRef(null),p=n.useMemo(()=>{const o=g?.maxSpeedMultiplier,v=typeof o=="number"?o:lt(A);return{enabled:g?.enabled??fe.enabled,size:g?.size??fe.size,offsetX:g?.offsetX??fe.offsetX,offsetY:g?.offsetY??fe.offsetY,className:g?.className??fe.className,maxVisualDistance:g?.maxVisualDistance??fe.maxVisualDistance,maxSpeedMultiplier:v,opacity:U(g?.opacity??fe.opacity,0,1),renderVisual:g?.renderVisual??fe.renderVisual}},[A,g]),{enabled:D,size:h,offsetX:k,offsetY:x,className:N,maxVisualDistance:L,maxSpeedMultiplier:F,opacity:R,renderVisual:w}=p,M=l?"width":"height",y=l?"height":"width",I=l?"left":"top",C=l?"clientX":"clientY",q=(o,v)=>l?o:v,ne=o=>o[C],K=l?["Scroll left","Scroll right"]:["Scroll up","Scroll down"],W=l?["◀","▶"]:["▲","▼"],te=l?"flex flex-row items-stretch":"flex flex-col items-stretch",B=Math.max(L,1),ce=e/a,Y=m,u=Math.max(e-Y*2,0),Z=ce*u,J=Math.min(Math.max(ze,Z||0),u||ze),z=a-e,re=Math.max(u-J,0),he=z<=0||re<=0?0:t/z*re,ue=a>e,Ae=ue&&c;n.useEffect(()=>{_.current=t},[t]),n.useEffect(()=>{r||T(!1)},[r]),n.useEffect(()=>{const o=G.current;if(!o)return;const v=l?"scaleY(1.06)":"scaleX(1.06)",X=l?"scaleY(1.12)":"scaleX(1.12)";if(!r){o.style.removeProperty("transform"),o.style.backgroundColor="#7F7F7F",o.style.removeProperty("transition");return}if(V){o.style.transform=X,o.style.backgroundColor="#4F4F4F",o.style.transition="transform 60ms ease-out";return}o.style.transition="transform 80ms ease-out",Q?(o.style.transform=v,o.style.backgroundColor="#5F5F5F"):(o.style.removeProperty("transform"),o.style.backgroundColor="#7F7F7F")},[r,l,V,Q]);const ve=n.useCallback(()=>{$.current!==null&&(window.clearInterval($.current),$.current=null),O.current!==null&&(window.clearTimeout(O.current),O.current=null)},[]),ie=n.useCallback(()=>{S.current!==null&&(window.cancelAnimationFrame(S.current),S.current=null),j.current=null},[]),le=n.useCallback(()=>{b.current={...je},ae(!1),P.current?.reset(),ie()},[ie]),Te=n.useCallback(o=>{const v=b.current;if(!v.active||v.direction===0){ie();return}if(!ue||z<=0){ie();return}const X=j.current??o,ee=Math.max((o-X)/1e3,0);if(j.current=o,ee<=0){S.current=window.requestAnimationFrame(Te);return}const Me=(Math.min(v.distance,B)/B)**1.1,pe=Math.max(e*.2,40),Ee=Math.max(e*F,1200),Ve=pe+(Ee-pe)*Me,ge=_.current,Pe=U(ge+v.direction*Ve*ee,0,z);if(Pe===ge){ie();return}_.current=Pe,s?.(Pe,ge),S.current=window.requestAnimationFrame(Te)},[B,z,s,ue,ie,F,e]),_e=n.useCallback(()=>{S.current===null&&(j.current=null,S.current=window.requestAnimationFrame(Te))},[Te]);n.useEffect(()=>()=>{ve(),ie()},[ve,ie]);const Ge=n.useCallback(o=>{b.current=o,ae(o.active),o.active&&o.direction!==0?_e():ie()},[_e,ie]);n.useEffect(()=>{D||le()},[le,D]),n.useEffect(()=>{const o=v=>{const ee=v.detail?.paneId;ee&&f&&ee!==f||le()};return window.addEventListener(Ce,o),()=>{window.removeEventListener(Ce,o)}},[f,le]),n.useEffect(()=>{if(!D)return;const o=v=>{if(!b.current.active)return;const X=v.target;if(!(X instanceof Node)){le();return}P.current?.getElement()?.contains(X)||le()};return document.addEventListener("pointerdown",o,!0),()=>{document.removeEventListener("pointerdown",o,!0)}},[le,D]);const Se=o=>{if(!ue||re<=0||z<=0)return 0;const v=U(o,0,re);return U(v/re*z,0,z)},Ie=o=>{if(!ue||z<=0)return;const v=Math.max(Math.round(e/rt),nt),X=_.current,ee=U(X+o*v,0,z);ee!==X&&(_.current=ee,s?.(ee,X))},ye=()=>{ve()},ke=o=>v=>{Ae&&(v.preventDefault(),v.stopPropagation(),le(),ve(),Ie(o),O.current=window.setTimeout(()=>{$.current=window.setInterval(()=>{Ie(o)},st)},tt))},Ze=o=>v=>{c&&(v.key==="Enter"||v.key===" "||v.key==="Spacebar")&&(v.preventDefault(),Ie(o))},Le=o=>{if(!ue)return;if(!r){o.preventDefault(),o.stopPropagation();return}if("button"in o&&o.button!==0||o.ctrlKey)return;o.stopPropagation(),le();const v=he;H(!0),T(!0),Ye(o,({deltaX:X,deltaY:ee})=>{const me=q(X,ee);s?.(Se(v+me),he)},()=>{H(!1),G.current&&!G.current.matches(":hover")&&T(!1)})},Fe=o=>{if(!ue)return;if(!i){o.preventDefault(),o.stopPropagation();return}if("button"in o&&o.button!==0||o.ctrlKey)return;const X="touches"in o.nativeEvent?o.nativeEvent.touches[0]:o.nativeEvent,ee=ne(X),me=o.currentTarget.getBoundingClientRect(),Me=ee-(l?me.left:me.top);le();const pe=Me-J/2;s?.(Se(pe),he),Ye(o,({deltaX:Ee,deltaY:Ve})=>{const ge=q(Ee,Ve);s?.(Se(pe+ge),he)})},Je=n.useMemo(()=>U((oe?1:.8)*R,0,1),[oe,R]),Qe=n.useMemo(()=>{const v=`calc(50% - ${h/2}px + ${x}px)`;return{left:k,top:v}},[k,x,h]),De=(o,v,X)=>E.jsx("button",{type:"button",className:"flex items-center justify-center text-[#313131] text-xs transition-colors focus:outline-none focus-visible:ring-2 focus-visible:ring-[#60a5fa] focus-visible:ring-offset-1 disabled:cursor-not-allowed disabled:opacity-50",style:{[M]:Y,[y]:m,backgroundColor:"#E0E0E0"},"aria-label":v,onMouseDown:ke(o),onTouchStart:ke(o),onMouseUp:ye,onMouseLeave:ye,onTouchEnd:ye,onTouchCancel:ye,onKeyDown:Ze(o),"aria-disabled":!c,disabled:!Ae,children:E.jsx("span",{"aria-hidden":"true",children:X})});return E.jsxs("div",{className:be.twMerge("group relative cursor-default select-none",te,d),style:{[M]:e,[y]:m,backgroundColor:"white",userSelect:"none",position:"relative"},role:"scrollbar",tabIndex:-1,"aria-controls":f,"aria-valuenow":t,"aria-valuemin":0,"aria-valuemax":z,"aria-orientation":l?"horizontal":"vertical",children:[!l&&ue&&D&&E.jsx(Xe,{ref:P,className:be.twMerge("pointer-events-auto absolute transition-opacity duration-150",N),size:h,maxVisualDistance:B,style:Qe,opacity:Je,renderVisual:w,onDragChange:Ge}),De(-1,K[0],W[0]),E.jsx("div",{className:"relative flex-1",style:{backgroundColor:"#F5F5F5",borderRadius:m/2},onMouseDown:Fe,onTouchStart:Fe,"aria-disabled":!i,children:ue&&E.jsx("div",{className:"group absolute",style:{[M]:J,[I]:he,...l?{top:0,bottom:0}:{left:0,right:0}},onMouseDown:Le,onTouchStart:Le,role:"slider","aria-orientation":l?"horizontal":"vertical","aria-valuenow":t,"aria-valuemin":0,"aria-valuemax":z,"aria-disabled":!r,tabIndex:r?0:-1,children:E.jsx("div",{ref:G,className:be.twMerge("absolute",l?`inset-x-0 inset-y-[1.5px] group-hover:inset-y-[-0.5px] ${V?"-inset-y-0.5":"group-active:-inset-y-0.5"}`:`inset-x-[1.5px] inset-y-0 group-hover:inset-x-[-0.5px] ${V?"-inset-x-0.5":"group-active:-inset-x-0.5"}`),style:{backgroundColor:"#7F7F7F",borderRadius:m-1,cursor:r?"pointer":"default",...l?{left:0,right:0,top:1.5,bottom:1.5}:{top:0,bottom:0,left:1.5,right:1.5}},onMouseEnter:()=>{r&&T(!0)},onMouseLeave:()=>{r&&T(!1)}})})}),De(1,K[1],W[1])]})},se={debug(a,...e){typeof window<"u"&&window.localStorage?.getItem("debug")==="true"&&console.debug(`[VirtualScroll] ${a}`,...e)},warn(a,...e){console.warn(`[VirtualScroll] ${a}`,...e)},error(a,...e){console.error(`[VirtualScroll] ${a}`,...e)}},xe={maxVelocity:6,minVelocity:.02,deceleration:.0025,velocitySampleWindow:90,startVelocityThreshold:.04},we=(a,e,t)=>{for(const[s,r,i]of e)t==="add"?a.addEventListener(s,r,i):a.removeEventListener(s,r,i)},qe=n.forwardRef(({children:a,contentSize:e,viewportSize:t,scrollBarWidth:s=12,enableThumbDrag:r=!0,enableTrackClick:i=!0,enableArrowButtons:c=!0,enablePointerDrag:l=!0,onScroll:m,className:d,style:f,background:g,tapScrollCircleOptions:A,inertiaOptions:V,itemCount:H},Q)=>{const T=n.useRef(0),[oe,ae]=n.useReducer(h=>h+1,0),G=n.useRef(null),_=n.useRef(null),$=n.useRef({frame:null,velocity:0,lastTimestamp:null}),O=n.useMemo(()=>({maxVelocity:V?.maxVelocity??xe.maxVelocity,minVelocity:V?.minVelocity??xe.minVelocity,deceleration:V?.deceleration??xe.deceleration,velocitySampleWindow:V?.velocitySampleWindow??xe.velocitySampleWindow,startVelocityThreshold:V?.startVelocityThreshold??xe.startVelocityThreshold}),[V]);se.debug("[ScrollPane] ScrollPane rendered",{contentSize:e,viewportSize:t,scrollBarWidth:s,className:d,style:f,tapScrollCircleOptions:A,inertiaOptions:V,enablePointerDrag:l});const b=n.useRef({contentSize:e,viewportSize:t}),P=n.useMemo(()=>e>t,[e,t]),S=n.useCallback(h=>{const{contentSize:k,viewportSize:x}=b.current,N=k>x,L=T.current;if(se.debug("[ScrollPane] scrollTo called",{newPosition:h,contentSize:k,viewportSize:x,currentIsScrollable:N,prevPosition:L}),!N){T.current!==0&&(T.current=0,m?.(0,L));return}const F=typeof h=="function"?h(T.current):h,R=U(F,0,k-x);T.current!==R&&(T.current=R,m?.(R,L))},[m]),j=n.useCallback(()=>{const h=$.current;h.frame!==null&&cancelAnimationFrame(h.frame),h.frame=null,h.velocity=0,h.lastTimestamp=null},[]),p=n.useCallback(h=>{if(!P)return;const{maxVelocity:k,minVelocity:x,deceleration:N,startVelocityThreshold:L}=O,F=U(h,-k,k);if(Math.abs(F)<L)return;j(),$.current.velocity=F,$.current.lastTimestamp=null;const R=w=>{const M=$.current;if(M.lastTimestamp===null){M.lastTimestamp=w,M.frame=requestAnimationFrame(R);return}const y=w-M.lastTimestamp;if(M.lastTimestamp=w,y<=0){M.frame=requestAnimationFrame(R);return}const I=M.velocity;let C=I;const q=N*y;I>0?C=Math.max(0,I-q):I<0&&(C=Math.min(0,I+q));const K=(I+C)/2*y,W=T.current;K!==0&&S(Z=>Z+K);const te=T.current,{contentSize:B,viewportSize:ce}=b.current,Y=Math.max(B-ce,0);M.velocity=C;const u=te===W||te<=0&&C<=0||te>=Y&&C>=0;if(Math.abs(C)<x||u){j();return}M.frame=requestAnimationFrame(R)};$.current.frame=requestAnimationFrame(R)},[P,O,S,j]);n.useLayoutEffect(()=>{b.current={contentSize:e,viewportSize:t}},[e,t]),n.useLayoutEffect(()=>{if(P){se.debug("[ScrollPane] Adjusting scroll position due to content or viewport size change",{contentSize:e,viewportSize:t,scrollPosition:T.current});const h=U(e-t,0,e);T.current>h&&S(h)}else S(0)},[P,S,e,t]),n.useEffect(()=>{const h=x=>{if(!P)return;x.preventDefault(),j();let N=x.deltaY;x.deltaMode===1?N*=16:x.deltaMode===2&&(N*=t),se.debug("[ScrollPane] wheel event",{deltaY:N,scrollPosition:T.current}),S(L=>L+N)},k=G.current;return k&&k.addEventListener("wheel",h,{passive:!1}),()=>{k&&k.removeEventListener("wheel",h)}},[P,S,j,t]),n.useImperativeHandle(Q,()=>({scrollTo:S,getScrollPosition:()=>T.current,getContentSize:()=>e,getViewportSize:()=>t}),[S,e,t]);const D=n.useId();return n.useEffect(()=>{const h=_.current;if(!h)return;if(!l){j();return}const k=6;let x=null,N=0,L=0,F=!1,R=!1,w=null,M=[];const y=()=>{x=null,N=0,L=0,F=!1,M=[]},I=u=>{const Z=performance.now();M.push({clientY:u,time:Z}),M=M.filter(J=>Z-J.time<=O.velocitySampleWindow)},C=u=>u instanceof HTMLElement&&u.closest("[data-scrollpane-ignore-drag='true']")!==null,q=u=>{R&&(u.preventDefault(),u.stopPropagation(),R=!1)},ne=u=>{F||(F=!0,R=!0,h.hasPointerCapture(u.pointerId)||h.setPointerCapture(u.pointerId),I(u.clientY))},K=u=>{if(x!==u.pointerId||!F&&(Math.abs(u.clientY-N)<k||(ne(u),!F)))return;I(u.clientY);const Z=u.clientY-N,J=L-Z;S(J),u.cancelable&&u.preventDefault()},W=u=>{if(x!==u.pointerId)return;F&&R&&u.cancelable&&(u.preventDefault(),u.stopPropagation()),h.hasPointerCapture(u.pointerId)&&h.releasePointerCapture(u.pointerId);let Z=0;if(F&&M.length>=2){const J=M[M.length-1],z=M.find(re=>J.time-re.time<=O.velocitySampleWindow)??M[0];if(J&&z&&J.time!==z.time){const re=J.clientY-z.clientY,he=J.time-z.time;Z=-(re/he)}}y(),w!==null&&window.clearTimeout(w),R&&(w=window.setTimeout(()=>{R=!1,w=null},0)),Math.abs(Z)>=O.startVelocityThreshold&&p(Z)},te=u=>{P&&(u.button!==0&&u.pointerType==="mouse"||u.ctrlKey||u.metaKey||u.altKey||C(u.target)||(window.dispatchEvent(new CustomEvent(Ce,{detail:{paneId:D}})),j(),x=u.pointerId,N=u.clientY,L=T.current,F=!1,R=!1,M=[]))},B=u=>{x===u.pointerId&&(R=!1,h.hasPointerCapture(u.pointerId)&&h.releasePointerCapture(u.pointerId),w!==null&&(window.clearTimeout(w),w=null),y())},ce=[["click",q,!0],["pointerdown",te,{passive:!1}],["pointermove",K,{passive:!1}],["pointerup",W,void 0],["pointercancel",B,void 0]],Y=[["pointermove",K,{passive:!1}],["pointerup",W,void 0],["pointercancel",B,void 0]];return we(h,ce,"add"),we(window,Y,"add"),()=>{we(h,ce,"remove"),we(window,Y,"remove"),x!==null&&h.hasPointerCapture(x)&&h.releasePointerCapture(x),w!==null&&window.clearTimeout(w),j()}},[l,D,P,O,S,p,j]),E.jsxs("div",{ref:G,className:be.twMerge("flex",d),style:f,children:[E.jsxs("div",{ref:_,className:"relative h-full flex-1 overflow-hidden",style:{height:t,...l?{touchAction:"none"}:{}},id:D,children:[g,a(T.current)]}),P&&E.jsx(Ue,{contentSize:e,viewportSize:t,scrollPosition:T.current,onScroll:S,enableThumbDrag:r,enableTrackClick:i,enableArrowButtons:c,scrollBarWidth:s,ariaControls:D,tapScrollCircleOptions:A,itemCount:H})]})}),He=(a,e,t)=>Math.min(Math.max(a,e),t),ct=({dragState:a,normalizedDistance:e,sizeScale:t,size:s})=>{const r=Math.max(s/2,1),i=1+e*.65,c=Math.max(.65,1-e*.25),l=a.direction*e*26*t,m=.8+e*.18,d=3*t,f=6*t,g=22*t,A=Math.abs(l)+f,V=l>0?d:-Math.abs(l)-d,H=Math.max(2.5,3*t),Q=He(a.offsetX,-r,r),T=He(a.offsetY,-r,r),oe=r*.35,ae=Q/r*oe,G=T/r*oe,_=ae*.45,$=G*.45,O=Math.max(g*.38,6),b=.65+e*.2,P=a.active;return E.jsxs(E.Fragment,{children:[E.jsx("div",{className:"absolute inset-0 rounded-full border border-white/40 bg-linear-to-br from-[#1d4ed8]/60 via-[#60a5fa]/55 to-[#bfdbfe]/40 shadow-md",style:{transform:`scale(${c}, ${i})`,transition:P?"40ms transform ease-out":"200ms ease transform"}}),E.jsx("div",{className:"absolute top-1/2 left-1/2 rounded-full border border-white/50 bg-white/85",style:{width:g,height:g,transform:`translate(calc(-50% + ${ae}px), calc(-50% + ${G}px)) scale(${c}, ${m*i})`,transition:P?"70ms transform ease-out":"200ms ease transform"}}),E.jsx("div",{className:"absolute top-1/2 left-1/2 rounded-full bg-white/80",style:{width:O,height:O,transform:`translate(calc(-50% + ${_}px), calc(-50% + ${$}px)) scale(${c}, ${i})`,opacity:b,boxShadow:"0 0 8px rgba(255,255,255,0.45)",transition:P?"120ms opacity 150ms, 120ms transform ease-out ease-out":"220ms ease transform, 240ms opacity ease"}}),E.jsx("div",{className:"absolute top-1/2 left-1/2 rounded-full bg-white/50",style:{width:H,height:A,transform:`translate(-50%, ${V}px)`,opacity:e,transition:P?"40ms height, 60ms opacity ease-out ease-out":"200ms ease height, 120ms ease opacity"}})]})};class Ke{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 i=s?.sampleRange??{from:0,to:Math.min(99,this.size-1)},{mode:c,materializedValues:l}=this._calculateMode(i.from,i.to);if(this.baseValue=c,s?.materialize)for(let m=0;m<l.length;m++){const d=l[m],f=i.from+m;if(f>=this.size)break;const g=d-this.baseValue;this.deltas.set(f,g),this._updateTree(f,g)}}else this.baseValue=0;this.total=this.getTotal()}else this.valueFn=void 0,this.baseValue=t,this.total=this.baseValue*this.size}setValueFn(e){typeof e=="function"?this.valueFn=e:(this.valueFn=void 0,this.baseValue=e)}_calculateMode(e,t){if(!this.valueFn)return{mode:0,materializedValues:[]};const s=[];for(let d=e;d<=t&&!(d>=this.size);d++)s.push(this.valueFn(d));const r=[...s];if(s.length===0)return{mode:0,materializedValues:[]};s.sort((d,f)=>d-f);const i=Math.floor(s.length/2);let c;s.length%2===0?c=Math.floor((s[i-1]+s[i])/2):c=s[i];const l=new Map;let m=0;for(const d of s){const f=(l.get(d)??0)+1;l.set(d,f),f>m&&(m=f)}if(m>1){const d=[];for(const[g,A]of l.entries())A===m&&d.push(g);const f=d.reduce((g,A)=>g+A,0);c=Math.floor(f/d.length)}return{mode:c,materializedValues:r}}update(e,t){return this.updates([{index:e,value:t}])}updates(e){const t=this._buildDeltaUpdates(e);return t.length>0?this.updateDeltas(t):this.total}updateDelta(e,t){return this.updateDeltas([{index:e,change:t}])}updateDeltas(e){for(const{index:t,change:s}of e){if(t<0||t>=this.size)throw new Error(`Index ${t} out of bounds`);const r=this.deltas.get(t)??0;this.deltas.set(t,r+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),s+=s&-s;this.total!==void 0&&(this.total+=t)}_buildDeltaUpdates(e){const t=[];for(const{index:s,value:r}of e){if(s<0||s>=this.size)throw new Error(`Index ${s} out of bounds`);if(r<0)throw new Error("Value cannot be negative.");const i=this.deltas.has(s)?(this.deltas.get(s)??0)+this.baseValue:this.baseValue,c=r-i;c!==0&&t.push({index:s,change:c})}return t}_materialize(e,t=!0){if(this.valueFn){const s=this.deltas.get(e)??0,i=this.valueFn(e)-this.baseValue;if(i!==s&&(this.deltas.set(e,i),t)){const c=i-s;this._updateTree(e,c)}}}_materializeRanges(e,t,s=!1){if(!(e?.materialize&&this.valueFn))return;const r=e.ranges;if(r&&r.length>0){for(const l of r){const m=l.from,d=Math.min(l.to,this.size-1);for(let f=m;f<=d;f++)this._materialize(f)}if(t===void 0)return;if(s){this._materialize(t);return}const i=r[0].from,c=r[r.length-1].to;t>=i&&t<=c&&this._materialize(t);return}t!==void 0&&this._materialize(t)}_findIndex(e,t={},s){if(this.size===0)return{index:-1,total:this.total??0,cumulative:void 0,currentValue:void 0,safeIndex:void 0};let r=0,i=this.size-1,c=-1,l,m=this.total;for(;r<=i;){const d=Math.floor((r+i)/2);l=this.prefixSum(d,t),m=l.total,(s?l.cumulative>=e:l.cumulative<=e)?(c=d,s?i=d-1:r=d+1):s?r=d+1:i=d-1}return{index:c,total:m,cumulative:l?.cumulative,currentValue:l?.currentValue,safeIndex:l?.safeIndex}}prefixSum(e,t){if(e<0)return{cumulative:0,total:this.total,currentValue:0,safeIndex:0};const s=U(e,0,this.size-1),r=t?.materializeOption;this._materializeRanges(r,s,!0);let i=0,c=s+1;for(;c>0;){const m=this.tree.get(c)??0;i+=m,c-=c&-c}const l=r?.materialize?this.get(s):(this.deltas.get(s)||0)+this.baseValue;return{cumulative:i+this.baseValue*(s+1),total:this.total,currentValue:l,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{let s=this.baseValue*this.size;for(const i of this.deltas.values())s+=i;this.total=s;const r=this.prefixSum(this.getSize()-1);console.assert(r.cumulative===r.total,"Inconsistent Fenwick Tree state")}return this.total}rebuildTree(e){if(e?.materialize&&this.valueFn){const r=this.valueFn;this.reset(this.size,i=>r(i),{materialize:!0});return}const t=new Map;let s=this.baseValue*this.size;for(const[r,i]of this.deltas.entries()){if(s+=i,i===0)continue;let c=r+1;for(;c<=this.size;)t.set(c,(t.get(c)??0)+i),c+=c&-c}this.tree=t,this.total=s}calculateAccumulatedError(){if(this.total===void 0)return 0;let e=this.baseValue*this.size;for(const t of this.deltas.values())e+=t;return this.total-e}changeSize(e){const t=this.size;if(e===t)return;if(e<t)for(const r of this.deltas.keys())r>=e&&this.deltas.delete(r);this.size=e,this.rebuildTree();const 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 We=(a,e,t)=>{const s=Math.max(0,a),r=n.useRef(null),i=n.useMemo(()=>new Ke(s,e,t),[s,e,t]);return Object.is(r.current,i)||console.warn("[useFenwickMapTree] instance changed"),r.current=i,i};class ut{key;value;prev=null;next=null;constructor(e,t){this.key=e,this.value=t}}class $e{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 Be(a){const e=n.useRef(new Map),t=n.useRef(new $e);n.useEffect(()=>{for(;e.current.size>a;){const d=t.current.removeHead();if(d)e.current.delete(d.key);else break}},[a]);const s=n.useCallback(d=>{const f=e.current.get(d);if(f)return t.current.moveToTail(f),f.value},[]),r=n.useCallback((d,f)=>{if(a<=0)return;let g=e.current.get(d);if(g)g.value=f,t.current.moveToTail(g);else{if(e.current.size>=a){const A=t.current.removeHead();A&&e.current.delete(A.key)}g=new ut(d,f),e.current.set(d,g),t.current.addToTail(g)}},[a]),i=n.useCallback(d=>e.current.has(d),[]),c=n.useCallback(()=>{e.current.clear(),t.current=new $e},[]),[l,m]=n.useState(()=>({get:s,set:r,has:i,clear:c}));return n.useEffect(()=>m({get:s,set:r,has:i,clear:c}),[s,r,i,c]),l}const dt=1e4,ft=()=>{const{get:a,set:e,has:t,clear:s}=Be(dt);return{get:a,set:e,has:t,clear:s}},de=(a,e)=>e<=0?0:U(a,0,e-1),ht=(a,e,t,s,r,i)=>{if(s===0)return{renderingStartIndex:0,renderingEndIndex:0,visibleStartIndex:0,visibleEndIndex:0};const{index:c,cumulative:l,currentValue:m}=i.findIndexAtOrAfter(a,{materializeOption:{materialize:!1}}),d=c===-1?0:c,f=c!==-1&&(l??0)<a+(m??0)?d+1:d,g=de(f,s),A=de(g-t,s);let V=0,H=g;for(;H<s&&V<e;)V+=r(H),H++;const Q=de(H-1,s),T=de(Q+t,s);return{renderingStartIndex:A,renderingEndIndex:T,visibleStartIndex:g,visibleEndIndex:Q}};function mt({itemCount:a,getItem:e,getItemHeight:t,viewportSize:s,overscanCount:r=5,className:i,onScroll:c,onRangeChange:l,children:m,background:d,initialScrollIndex:f,initialScrollOffset:g,tapScrollCircleOptions:A,scrollBarWidth:V,enableThumbDrag:H,enableTrackClick:Q,enableArrowButtons:T,enablePointerDrag:oe,inertiaOptions:ae},G){const _=n.useRef(null),$=n.useRef(!1);n.useEffect(()=>($.current=!0,()=>{$.current=!1}),[]);const O=n.useRef({size:a,valueOrFn:t,options:{sampleRange:{from:0,to:100}}}),b=We(O.current.size,O.current.valueOrFn,O.current.options),[P]=n.useState(()=>{let y=0,I=0;if(typeof f=="number"){const C=U(f,0,a-1),q=U(C-r*2,0,a-1),ne=U(C+r*2,0,a-1),K=f>0?{materializeOption:{materialize:!0,ranges:[{from:q,to:ne}]}}:void 0,{cumulative:W,total:te,currentValue:B}=b.prefixSum(f,K);y=W-B,I=te??b.getTotal()}else typeof g=="number"&&(y=g),I=b.getTotal();return{position:y,total:I}}),[S,j]=n.useState(P.position),[p,D]=n.useState(P.total),[h,k]=n.useState(P.position),[x,N]=n.useState(a);n.useLayoutEffect(()=>{b.setValueFn(t),x!==a&&(b.changeSize(a),N(a));const y=b.getTotal();p!==y&&D(y)},[b,x,a,p,t]),n.useLayoutEffect(()=>{h!==null&&_.current&&(se.debug("[VirtualScroll] Scrolling to position:",h),_.current.scrollTo(h),k(null))},[h]);const L=n.useCallback(y=>{if(!_.current)return;const I=de(y,x),C=de(I-r*2,x),q=de(I+r*2,x),{cumulative:ne,total:K,currentValue:W}=b.prefixSum(I,{materializeOption:{materialize:!0,ranges:[{from:C,to:q}]}});se.debug("[VirtualScroll] Scrolling to index:",I,"Offset:",ne,"Total height:",K,"Current value:",W,"safeIndexFrom:",C,"safeIndexTo:",q),K&&(D(K),k(ne-W),se.debug("[VirtualScroll] Setting scroll position to:",ne-W))},[b,r,x]),F=n.useCallback(y=>{if(!_.current)return;const I=b.getTotal(),C=U(Math.floor(y),0,I),q=b.findIndexAtOrAfter(C,{materializeOption:{materialize:!1}}).index;L(q)},[b,L]),R=n.useCallback((y,I)=>{se.debug("[VirtualScroll] Scroll position changed:",y),j(y);const C=b.getTotal();c?.(y,C)},[b,c]),w=n.useMemo(()=>{const y=ht(S,s,r,x,t,b);return se.debug("[VirtualScroll] Calculated rendering range:",{...y,scrollPosition:S,renderingContentSize:b.getTotal(),overscanCount:r,viewportSize:s}),y},[S,s,r,x,t,b]);n.useEffect(()=>{const y=_.current?.getScrollPosition()??0;se.debug("[VirtualScroll] Range change effect triggered",{renderingStartIndex:w.renderingStartIndex,renderingEndIndex:w.renderingEndIndex,visibleStartIndex:w.visibleStartIndex,visibleEndIndex:w.visibleEndIndex,scrollPosition:S,contentSize:p,scrollPaneScrollPosition:y}),l?.(w.renderingStartIndex,w.renderingEndIndex,w.visibleStartIndex,w.visibleEndIndex,S,p)},[w.renderingStartIndex,w.renderingEndIndex,w.visibleStartIndex,w.visibleEndIndex,l,S,p]);const M=n.useCallback(y=>{const{renderingStartIndex:I,renderingEndIndex:C}=w;if(se.debug("[VirtualScroll] Rendering visible items",{currentScrollPosition:y,renderingStartIndex:I,renderingEndIndex:C,fenwickSize:x,viewportSize:s}),x===0)return E.jsx("div",{className:"absolute w-full",style:{top:0},children:E.jsx("div",{className:"text-center text-gray-500",children:"No items"})});const q=de(I,x),{cumulative:ne,currentValue:K}=b.prefixSum(q,{materializeOption:{materialize:!1}}),W=ne-K,te=[],B=[];for(let Y=I;Y<=C;Y++){const u=t(Y);te.push({item:e(Y),height:u,index:Y}),b.get(Y)!==u&&B.push({index:Y,value:u})}B.length>0&&Promise.resolve().then(()=>{const Y=b.updates(B);Y&&(D(Y),se.debug("[VirtualScroll] Updated heights for items",B,"New total height:",Y))});const ce=p<s?0:W-y;return se.debug("[VirtualScroll] Rendering items",{visibleItems:te,containerTop:ce}),E.jsx("div",{className:"absolute w-full",style:{top:ce},children:te.map(({item:Y,index:u})=>{const Z=de(u,x),{cumulative:J,currentValue:z}=b.prefixSum(Z,{materializeOption:{materialize:!1}}),re=J-z;return E.jsx("div",{"data-index":u,style:{position:"absolute",top:re-W,width:"100%"},children:m(Y,u)},u)})})},[e,m,p,s,w,b,x,t]);return n.useImperativeHandle(G,()=>({getScrollPosition:()=>_.current?.getScrollPosition()??-1,getContentSize:()=>_.current?.getContentSize()??-1,getViewportSize:()=>_.current?.getViewportSize()??-1,scrollTo:F,scrollToIndex:L,getFenwickTreeTotalHeight:()=>b.getTotal(),getFenwickSize:()=>b.getSize()}),[F,L,b]),E.jsx(qe,{ref:_,contentSize:p,viewportSize:s,className:i,onScroll:R,background:d,tapScrollCircleOptions:A,inertiaOptions:ae,itemCount:a,scrollBarWidth:V,enableThumbDrag:H,enableTrackClick:Q,enableArrowButtons:T,enablePointerDrag:oe,children:M})}const pt=n.forwardRef(mt);exports.FenwickMapTree=Ke;exports.ScrollBar=Ue;exports.ScrollPane=qe;exports.VirtualScroll=pt;exports.minmax=U;exports.tapScrollCircleSampleVisual=ct;exports.useFenwickMapTree=We;exports.useHeightCache=ft;exports.useLruCache=Be;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|