@aiquants/virtualscroll 0.4.0 → 0.5.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 +2 -2
- package/dist/cli.js +13 -22
- package/dist/index.cjs +1 -22
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +640 -919
- package/dist/index.js.map +1 -1
- package/dist/virtualscroll.css +1 -1
- package/package.json +21 -15
package/README.md
CHANGED
|
@@ -11,8 +11,8 @@ High-performance virtual scrolling component for React with variable item height
|
|
|
11
11
|
<!-- - 🔄 **LRU Caching**: Built-in cache for optimal memory usage -->
|
|
12
12
|
- 📱 **Touch Support**: Full support for touch devices
|
|
13
13
|
- 🎨 **Customizable**: Flexible styling and theming options
|
|
14
|
-
-
|
|
15
|
-
-
|
|
14
|
+
- 🌀 **Ultrafast Tap Scroll**: Adaptive tap scroll circle that scales speed up to 120× for massive datasets
|
|
15
|
+
- 🔧 **TypeScript**: Full TypeScript support with comprehensive type definitions
|
|
16
16
|
|
|
17
17
|
## Installation
|
|
18
18
|
|
package/dist/cli.js
CHANGED
|
@@ -1,28 +1,19 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { spawn } from "child_process";
|
|
3
|
-
import
|
|
4
|
-
import { fileURLToPath } from "url";
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
const args = process.argv.slice(2);
|
|
8
|
-
if (args[0] === "demo") {
|
|
2
|
+
import { spawn as t } from "child_process";
|
|
3
|
+
import s from "path";
|
|
4
|
+
import { fileURLToPath as i } from "url";
|
|
5
|
+
const l = i(import.meta.url), m = s.dirname(l), r = process.argv.slice(2);
|
|
6
|
+
if (r[0] === "demo") {
|
|
9
7
|
console.log("Starting demo server...");
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
cwd: demoPath,
|
|
8
|
+
const n = s.join(m, "..", "demo"), e = t("pnpm", ["run", "dev"], {
|
|
9
|
+
cwd: n,
|
|
13
10
|
stdio: "inherit",
|
|
14
11
|
shell: process.platform === "win32"
|
|
15
12
|
});
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
13
|
+
e.on("close", (o) => {
|
|
14
|
+
o !== 0 && console.error(`Demo server process exited with code ${o}`);
|
|
15
|
+
}), e.on("error", (o) => {
|
|
16
|
+
console.error("Failed to start demo server:", o);
|
|
20
17
|
});
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
});
|
|
24
|
-
} else {
|
|
25
|
-
console.log(`Unknown command: ${args[0]}`);
|
|
26
|
-
console.log("Usage: npx @aiquants/virtualscroll demo");
|
|
27
|
-
process.exit(1);
|
|
28
|
-
}
|
|
18
|
+
} else
|
|
19
|
+
console.log(`Unknown command: ${r[0]}`), console.log("Usage: npx @aiquants/virtualscroll demo"), process.exit(1);
|
package/dist/index.cjs
CHANGED
|
@@ -1,23 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react"),fe=require("tailwind-merge");var pe={exports:{}},le={};/**
|
|
2
|
-
* @license React
|
|
3
|
-
* react-jsx-runtime.production.js
|
|
4
|
-
*
|
|
5
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
6
|
-
*
|
|
7
|
-
* This source code is licensed under the MIT license found in the
|
|
8
|
-
* LICENSE file in the root directory of this source tree.
|
|
9
|
-
*/var ye;function Ye(){if(ye)return le;ye=1;var u=Symbol.for("react.transitional.element"),e=Symbol.for("react.fragment");function n(r,o,i){var l=null;if(i!==void 0&&(l=""+i),o.key!==void 0&&(l=""+o.key),"key"in o){i={};for(var m in o)m!=="key"&&(i[m]=o[m])}else i=o;return o=i.ref,{$$typeof:u,type:r,key:l,ref:o!==void 0?o:null,props:i}}return le.Fragment=e,le.jsx=n,le.jsxs=n,le}var ce={};/**
|
|
10
|
-
* @license React
|
|
11
|
-
* react-jsx-runtime.development.js
|
|
12
|
-
*
|
|
13
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
14
|
-
*
|
|
15
|
-
* This source code is licensed under the MIT license found in the
|
|
16
|
-
* LICENSE file in the root directory of this source tree.
|
|
17
|
-
*/var Re;function ze(){return Re||(Re=1,process.env.NODE_ENV!=="production"&&(function(){function u(t){if(t==null)return null;if(typeof t=="function")return t.$$typeof===c?null:t.displayName||t.name||null;if(typeof t=="string")return t;switch(t){case N:return"Fragment";case F:return"Profiler";case G:return"StrictMode";case C:return"Suspense";case j:return"SuspenseList";case re:return"Activity"}if(typeof t=="object")switch(typeof t.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),t.$$typeof){case se:return"Portal";case J:return(t.displayName||"Context")+".Provider";case h:return(t._context.displayName||"Context")+".Consumer";case k:var a=t.render;return t=t.displayName,t||(t=a.displayName||a.name||"",t=t!==""?"ForwardRef("+t+")":"ForwardRef"),t;case B:return a=t.displayName||null,a!==null?a:u(t.type)||"Memo";case U:a=t._payload,t=t._init;try{return u(t(a))}catch{}}return null}function e(t){return""+t}function n(t){try{e(t);var a=!1}catch{a=!0}if(a){a=console;var T=a.error,R=typeof Symbol=="function"&&Symbol.toStringTag&&t[Symbol.toStringTag]||t.constructor.name||"Object";return T.call(a,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",R),e(t)}}function r(t){if(t===N)return"<>";if(typeof t=="object"&&t!==null&&t.$$typeof===U)return"<...>";try{var a=u(t);return a?"<"+a+">":"<...>"}catch{return"<...>"}}function o(){var t=z.A;return t===null?null:t.getOwner()}function i(){return Error("react-stack-top-frame")}function l(t){if(Y.call(t,"key")){var a=Object.getOwnPropertyDescriptor(t,"key").get;if(a&&a.isReactWarning)return!1}return t.key!==void 0}function m(t,a){function T(){w||(w=!0,console.error("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",a))}T.isReactWarning=!0,Object.defineProperty(t,"key",{get:T,configurable:!0})}function g(){var t=u(this.type);return A[t]||(A[t]=!0,console.error("Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release.")),t=this.props.ref,t!==void 0?t:null}function b(t,a,T,R,S,V,D,M){return T=V.ref,t={$$typeof:te,type:t,key:a,props:V,_owner:S},(T!==void 0?T:null)!==null?Object.defineProperty(t,"ref",{enumerable:!1,get:g}):Object.defineProperty(t,"ref",{enumerable:!1,value:null}),t._store={},Object.defineProperty(t._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(t,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(t,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:D}),Object.defineProperty(t,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:M}),Object.freeze&&(Object.freeze(t.props),Object.freeze(t)),t}function x(t,a,T,R,S,V,D,M){var P=a.children;if(P!==void 0)if(R)if(L(P)){for(R=0;R<P.length;R++)_(P[R]);Object.freeze&&Object.freeze(P)}else console.error("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else _(P);if(Y.call(a,"key")){P=u(t);var X=Object.keys(a).filter(function(f){return f!=="key"});R=0<X.length?"{key: someKey, "+X.join(": ..., ")+": ...}":"{key: someKey}",I[P+R]||(X=0<X.length?"{"+X.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
|
|
18
|
-
let props = %s;
|
|
19
|
-
<%s {...props} />
|
|
20
|
-
React keys must be passed directly to JSX without using spread:
|
|
21
|
-
let props = %s;
|
|
22
|
-
<%s key={someKey} {...props} />`,R,P,X,P),I[P+R]=!0)}if(P=null,T!==void 0&&(n(T),P=""+T),l(a)&&(n(a.key),P=""+a.key),"key"in a){T={};for(var W in a)W!=="key"&&(T[W]=a[W])}else T=a;return P&&m(T,typeof t=="function"?t.displayName||t.name||"Unknown":t),b(t,P,V,S,o(),T,D,M)}function _(t){typeof t=="object"&&t!==null&&t.$$typeof===te&&t._store&&(t._store.validated=1)}var y=s,te=Symbol.for("react.transitional.element"),se=Symbol.for("react.portal"),N=Symbol.for("react.fragment"),G=Symbol.for("react.strict_mode"),F=Symbol.for("react.profiler"),h=Symbol.for("react.consumer"),J=Symbol.for("react.context"),k=Symbol.for("react.forward_ref"),C=Symbol.for("react.suspense"),j=Symbol.for("react.suspense_list"),B=Symbol.for("react.memo"),U=Symbol.for("react.lazy"),re=Symbol.for("react.activity"),c=Symbol.for("react.client.reference"),z=y.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,Y=Object.prototype.hasOwnProperty,L=Array.isArray,E=console.createTask?console.createTask:function(){return null};y={react_stack_bottom_frame:function(t){return t()}};var w,A={},p=y.react_stack_bottom_frame.bind(y,i)(),v=E(r(i)),I={};ce.Fragment=N,ce.jsx=function(t,a,T,R,S){var V=1e4>z.recentlyCreatedOwnerStacks++;return x(t,a,T,!1,R,S,V?Error("react-stack-top-frame"):p,V?E(r(t)):v)},ce.jsxs=function(t,a,T,R,S){var V=1e4>z.recentlyCreatedOwnerStacks++;return x(t,a,T,!0,R,S,V?Error("react-stack-top-frame"):p,V?E(r(t)):v)}})()),ce}var Ie;function He(){return Ie||(Ie=1,process.env.NODE_ENV==="production"?pe.exports=Ye():pe.exports=ze()),pe.exports}var $=He();const ee={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)}},H=(u,e,n)=>Math.min(n,Math.max(e,u)),Te={active:!1,offsetY:0,distance:0,direction:0},Me=6,Ve=s.forwardRef(({onDragChange:u,className:e,maxVisualDistance:n=160,size:r=64,style:o,opacity:i=1},l)=>{const[m,g]=s.useState(Te),b=s.useRef(null),x=s.useRef({x:0,y:0}),_=s.useRef(null),y=s.useCallback((E,w=!1)=>{const{y:A}=x.current,p=E-A,v=Math.abs(p),I=v<Me?0:p<0?-1:1,t={active:w||v>=Me,offsetY:p,distance:v,direction:I};g(t),u(t)},[u]),te=s.useCallback((E=!1)=>{if(E&&b.current!==null){const w=_.current;w?.hasPointerCapture(b.current)&&w.releasePointerCapture(b.current)}b.current=null,g(Te),u(Te)},[u]),se=s.useCallback(E=>{E.preventDefault(),E.stopPropagation();const w=_.current??E.currentTarget,A=w.getBoundingClientRect();x.current={x:A.left+A.width/2,y:A.top+A.height/2},b.current=E.pointerId,w.setPointerCapture(E.pointerId),y(E.clientY,!0)},[y]),N=s.useCallback(E=>{b.current===E.pointerId&&(E.preventDefault(),y(E.clientY))},[y]),G=s.useCallback(E=>{b.current===E.pointerId&&(E.preventDefault(),E.stopPropagation(),te(!0))},[te]);s.useImperativeHandle(l,()=>({reset:()=>{te(!0)},getElement:()=>_.current}),[te]);const F=s.useMemo(()=>Math.min(m.distance,n)/n,[m.distance,n]),h=s.useMemo(()=>r/64,[r]),J=s.useMemo(()=>1+F*.4,[F]),k=s.useMemo(()=>m.direction*F*10*h,[m.direction,F,h]),C=s.useMemo(()=>m.direction*F*26*h,[m.direction,F,h]),j=s.useMemo(()=>22*h,[h]),B=s.useMemo(()=>Math.max(2.5,3*h),[h]),U=s.useMemo(()=>6*h,[h]),re=s.useMemo(()=>3*h,[h]),c=s.useMemo(()=>Math.min(Math.max(i,0),1),[i]),z=s.useMemo(()=>{const E={...o,width:r,height:r,transform:`translateY(${k}px)`};return E.opacity=c,E},[c,k,r,o]),Y=s.useMemo(()=>Math.abs(C)+U,[U,C]),L=s.useMemo(()=>C>0?re:-Math.abs(C)-re,[re,C]);return $.jsxs("div",{ref:_,className:fe.twMerge("relative flex items-center justify-center touch-none select-none","transition-transform duration-100 ease-out",e),style:z,onPointerDown:se,onPointerMove:N,onPointerUp:G,onPointerCancel:G,role:"presentation",children:[$.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:m.active?"transform 40ms ease-out":"transform 200ms ease"}}),$.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:j,height:j,transform:`translate(-50%, calc(-50% + ${C*.3}px)) scale(${1+F*.2})`,transition:m.active?"transform 40ms ease-out":"transform 200ms ease"}}),$.jsx("div",{className:"absolute left-1/2 top-1/2 w-1 rounded-full bg-white/50",style:{width:B,height:Y,transform:`translate(-50%, ${L}px)`,opacity:F,transition:m.active?"height 40ms ease-out, opacity 60ms":"height 200ms ease, opacity 120ms"}})]})});Ve.displayName="TapScrollCircle";const _e=(u,e,n)=>{const r="touches"in u.nativeEvent,o=r?u.nativeEvent.touches[0]:u.nativeEvent,i=m=>{r&&m.cancelable&&m.preventDefault();const g="touches"in m?m.touches[0]:m;e({deltaX:g.clientX-o.clientX,deltaY:g.clientY-o.clientY})},l=()=>{r?(document.removeEventListener("touchmove",i),document.removeEventListener("touchend",l)):(document.removeEventListener("mousemove",i),document.removeEventListener("mouseup",l)),n?.()};r?(document.addEventListener("touchmove",i,{passive:!1}),document.addEventListener("touchend",l)):(document.addEventListener("mousemove",i),document.addEventListener("mouseup",l))},we="virtualscroll:tap-scroll-cancel",Pe=20,$e=250,Ue=60,qe=20,Xe=20,We=220,ke={active:!1,offsetY:0,distance:0,direction:0},Ee=2.2,Be=8,Ge=120,oe={enabled:!0,size:64,offsetX:-80,offsetY:0,className:void 0,maxVisualDistance:We,opacity:1},Je=u=>{if(!u||u<=0)return Ee;const e=Math.max(1,u),n=Math.log10(e),r=Ee+n*Be;return H(r,Ee,Ge)},Ce=({contentSize:u,viewportSize:e,scrollPosition:n,onScroll:r,horizontal:o=!1,scrollBarWidth:i=12,className:l,ariaControls:m,tapScrollCircleOptions:g,itemCount:b})=>{const[x,_]=s.useState(!1),[y,te]=s.useState(!1),se=s.useRef(null),N=s.useRef(n),G=s.useRef(null),F=s.useRef(null),h=s.useRef(ke),J=s.useRef(null),k=s.useRef(null),C=s.useRef(null),j=s.useMemo(()=>{const d=g?.maxSpeedMultiplier,O=typeof d=="number"?d:Je(b);return{enabled:g?.enabled??oe.enabled,size:g?.size??oe.size,offsetX:g?.offsetX??oe.offsetX,offsetY:g?.offsetY??oe.offsetY,className:g?.className??oe.className,maxVisualDistance:g?.maxVisualDistance??oe.maxVisualDistance,maxSpeedMultiplier:O,opacity:H(g?.opacity??oe.opacity,0,1)}},[b,g]),{enabled:B,size:U,offsetX:re,offsetY:c,className:z,maxVisualDistance:Y,maxSpeedMultiplier:L,opacity:E}=j,w=Math.max(Y,1),A=e/u,p=i,v=Math.max(e-p*2,0),I=A*v,t=Math.min(Math.max(Pe,I||0),v||Pe),a=u-e,T=Math.max(v-t,0),R=a<=0||T<=0?0:n/a*T,S=u>e;s.useEffect(()=>{N.current=n},[n]),s.useEffect(()=>{se.current&&(x?se.current.style.backgroundColor="#4F4F4F":se.current.style.backgroundColor="#7F7F7F")},[x]);const V=s.useCallback(()=>{G.current!==null&&(window.clearInterval(G.current),G.current=null),F.current!==null&&(window.clearTimeout(F.current),F.current=null)},[]),D=s.useCallback(()=>{k.current!==null&&(window.cancelAnimationFrame(k.current),k.current=null),C.current=null},[]),M=s.useCallback(()=>{h.current={...ke},te(!1),J.current?.reset(),D()},[D]),P=s.useCallback(d=>{const O=h.current;if(!O.active||O.direction===0){D();return}if(!S||a<=0){D();return}const Q=C.current??d,K=Math.max((d-Q)/1e3,0);if(C.current=d,K<=0){k.current=window.requestAnimationFrame(P);return}const ge=(Math.min(O.distance,w)/w)**1.1,ie=Math.max(e*.2,40),be=Math.max(e*L,1200),ve=ie+(be-ie)*ge,he=N.current,xe=H(he+O.direction*ve*K,0,a);if(xe===he){D();return}N.current=xe,r?.(xe,he),k.current=window.requestAnimationFrame(P)},[w,a,r,S,D,L,e]),X=s.useCallback(()=>{k.current===null&&(C.current=null,k.current=window.requestAnimationFrame(P))},[P]);s.useEffect(()=>()=>{V(),D()},[V,D]);const W=s.useCallback(d=>{h.current=d,te(d.active),d.active&&d.direction!==0?X():D()},[X,D]);s.useEffect(()=>{B||M()},[M,B]),s.useEffect(()=>{const d=O=>{const K=O.detail?.paneId;K&&m&&K!==m||M()};return window.addEventListener(we,d),()=>{window.removeEventListener(we,d)}},[m,M]),s.useEffect(()=>{if(!B)return;const d=O=>{if(!h.current.active)return;const Q=O.target;if(!(Q instanceof Node)){M();return}J.current?.getElement()?.contains(Q)||M()};return document.addEventListener("pointerdown",d,!0),()=>{document.removeEventListener("pointerdown",d,!0)}},[M,B]);const f=d=>{if(!S||T<=0||a<=0)return 0;const O=H(d,0,T);return H(O/T*a,0,a)},Z=d=>{if(!S||a<=0)return;const O=Math.max(Math.round(e/Xe),qe),Q=N.current,K=H(Q+d*O,0,a);K!==Q&&(N.current=K,r?.(K,Q))},q=()=>{V()},ne=d=>O=>{S&&(O.preventDefault(),O.stopPropagation(),M(),V(),Z(d),F.current=window.setTimeout(()=>{G.current=window.setInterval(()=>{Z(d)},Ue)},$e))},ae=d=>O=>{(O.key==="Enter"||O.key===" "||O.key==="Spacebar")&&(O.preventDefault(),Z(d))},de=d=>{if(!S||"button"in d&&d.button!==0||d.ctrlKey)return;d.stopPropagation(),M();const O=R;_(!0),_e(d,({deltaX:Q,deltaY:K})=>{r?.(f(O+(o?Q:K)),R)},()=>{_(!1)})},Se=d=>{if(!S||"button"in d&&d.button!==0||d.ctrlKey)return;const Q="touches"in d.nativeEvent?d.nativeEvent.touches[0]:d.nativeEvent,K=o?Q.clientX:Q.clientY,me=d.currentTarget.getBoundingClientRect(),ge=o?K-me.left:K-me.top;M();const ie=ge-t/2;r?.(f(ie),R),_e(d,({deltaX:be,deltaY:ve})=>{r?.(f(ie+(o?be:ve)),R)})},Ne=s.useMemo(()=>H((y?1:.8)*E,0,1),[y,E]),je=s.useMemo(()=>{const O=`calc(50% - ${U/2}px + ${c}px)`;return{left:re,top:O}},[re,c,U]);return $.jsxs("div",{className:fe.twMerge("group relative cursor-default select-none",o?"flex flex-row items-stretch":"flex flex-col items-stretch",l),style:{[o?"width":"height"]:e,[o?"height":"width"]:i,backgroundColor:"white",userSelect:"none",position:"relative"},role:"scrollbar",tabIndex:-1,"aria-controls":m,"aria-valuenow":n,"aria-valuemin":0,"aria-valuemax":a,"aria-orientation":o?"horizontal":"vertical",children:[!o&&S&&B&&$.jsx(Ve,{ref:J,className:fe.twMerge("pointer-events-auto absolute transition-opacity duration-150",z),size:U,maxVisualDistance:w,style:je,opacity:Ne,onDragChange:W}),$.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:{[o?"width":"height"]:p,[o?"height":"width"]:i,backgroundColor:"#E0E0E0"},"aria-label":o?"Scroll left":"Scroll up",onMouseDown:ne(-1),onTouchStart:ne(-1),onMouseUp:q,onMouseLeave:q,onTouchEnd:q,onTouchCancel:q,onKeyDown:ae(-1),disabled:!S,children:$.jsx("span",{"aria-hidden":"true",children:o?"◀":"▲"})}),$.jsx("div",{className:"relative flex-1",style:{backgroundColor:"#F5F5F5",borderRadius:i/2},onMouseDown:Se,onTouchStart:Se,children:u>e&&$.jsx("div",{className:"group absolute",style:{[o?"width":"height"]:t,[o?"left":"top"]:R,...o?{top:0,bottom:0}:{left:0,right:0}},onMouseDown:de,onTouchStart:de,role:"slider","aria-orientation":o?"horizontal":"vertical","aria-valuenow":n,"aria-valuemin":0,"aria-valuemax":a,tabIndex:0,children:$.jsx("div",{ref:se,className:fe.twMerge("absolute",o?`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:i-1,...o?{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:d=>{o?(d.currentTarget.style.top="-0.5px",d.currentTarget.style.bottom="-0.5px"):(d.currentTarget.style.left="-0.5px",d.currentTarget.style.right="-0.5px"),x||(d.currentTarget.style.backgroundColor="#5F5F5F")},onMouseLeave:d=>{o?(d.currentTarget.style.top=x?"-2px":"1.5px",d.currentTarget.style.bottom=x?"-2px":"1.5px"):(d.currentTarget.style.left=x?"-2px":"1.5px",d.currentTarget.style.right=x?"-2px":"1.5px"),x||(d.currentTarget.style.backgroundColor="#7F7F7F")}})})}),$.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:{[o?"width":"height"]:p,[o?"height":"width"]:i,backgroundColor:"#E0E0E0"},"aria-label":o?"Scroll right":"Scroll down",onMouseDown:ne(1),onTouchStart:ne(1),onMouseUp:q,onMouseLeave:q,onTouchEnd:q,onTouchCancel:q,onKeyDown:ae(1),disabled:!S,children:$.jsx("span",{"aria-hidden":"true",children:o?"▶":"▼"})})]})},ue={maxVelocity:6,minVelocity:.02,deceleration:.0025,velocitySampleWindow:90,startVelocityThreshold:.04},Le=s.forwardRef(({children:u,contentSize:e,viewportSize:n,scrollBarWidth:r=12,onScroll:o,className:i,style:l,background:m,tapScrollCircleOptions:g,inertiaOptions:b,itemCount:x},_)=>{const y=s.useRef(0),[te,se]=s.useReducer(c=>c+1,0),N=s.useRef(null),G=s.useRef(null),F=s.useRef({frame:null,velocity:0,lastTimestamp:null}),h=s.useMemo(()=>({maxVelocity:b?.maxVelocity??ue.maxVelocity,minVelocity:b?.minVelocity??ue.minVelocity,deceleration:b?.deceleration??ue.deceleration,velocitySampleWindow:b?.velocitySampleWindow??ue.velocitySampleWindow,startVelocityThreshold:b?.startVelocityThreshold??ue.startVelocityThreshold}),[b]);ee.debug("[ScrollPane] ScrollPane rendered",{contentSize:e,viewportSize:n,scrollBarWidth:r,className:i,style:l,tapScrollCircleOptions:g,inertiaOptions:b});const J=s.useRef({contentSize:e,viewportSize:n}),k=s.useMemo(()=>e>n,[e,n]),C=s.useCallback(c=>{const{contentSize:z,viewportSize:Y}=J.current,L=z>Y,E=y.current;if(ee.debug("[ScrollPane] scrollTo called",{newPosition:c,contentSize:z,viewportSize:Y,currentIsScrollable:L,prevPosition:E}),!L){y.current!==0&&(y.current=0,o?.(0,E));return}const w=typeof c=="function"?c(y.current):c,A=H(w,0,z-Y);y.current!==A&&(y.current=A,o?.(A,E))},[o]),j=s.useCallback(()=>{const c=F.current;c.frame!==null&&cancelAnimationFrame(c.frame),c.frame=null,c.velocity=0,c.lastTimestamp=null},[]),B=s.useCallback(c=>{if(!k)return;const{maxVelocity:z,minVelocity:Y,deceleration:L,startVelocityThreshold:E}=h,w=H(c,-z,z);if(Math.abs(w)<E)return;j(),F.current.velocity=w,F.current.lastTimestamp=null;const A=p=>{const v=F.current;if(v.lastTimestamp===null){v.lastTimestamp=p,v.frame=requestAnimationFrame(A);return}const I=p-v.lastTimestamp;if(v.lastTimestamp=p,I<=0){v.frame=requestAnimationFrame(A);return}const t=v.velocity;let a=t;const T=L*I;t>0?a=Math.max(0,t-T):t<0&&(a=Math.min(0,t+T));const S=(t+a)/2*I,V=y.current;S!==0&&C(f=>f+S);const D=y.current,{contentSize:M,viewportSize:P}=J.current,X=Math.max(M-P,0);v.velocity=a;const W=D===V||D<=0&&a<=0||D>=X&&a>=0;if(Math.abs(a)<Y||W){j();return}v.frame=requestAnimationFrame(A)};F.current.frame=requestAnimationFrame(A)},[k,h,C,j]);s.useLayoutEffect(()=>{J.current={contentSize:e,viewportSize:n}},[e,n]),s.useLayoutEffect(()=>{if(k){ee.debug("[ScrollPane] Adjusting scroll position due to content or viewport size change",{contentSize:e,viewportSize:n,scrollPosition:y.current});const c=H(e-n,0,e);y.current>c&&C(c)}else C(0)},[k,C,e,n]),s.useEffect(()=>{const c=Y=>{if(!k)return;Y.preventDefault(),j();let L=Y.deltaY;Y.deltaMode===1?L*=16:Y.deltaMode===2&&(L*=n),ee.debug("[ScrollPane] wheel event",{deltaY:L,scrollPosition:y.current}),C(E=>E+L)},z=N.current;return z&&z.addEventListener("wheel",c,{passive:!1}),()=>{z&&z.removeEventListener("wheel",c)}},[k,C,j,n]),s.useImperativeHandle(_,()=>({scrollTo:C,getScrollPosition:()=>y.current,getContentSize:()=>e,getViewportSize:()=>n}),[C,e,n]);const U=s.useId(),re=s.useMemo(()=>$.jsxs("div",{ref:N,className:fe.twMerge("flex",i),style:l,children:[$.jsxs("div",{ref:G,className:"relative h-full flex-1 overflow-hidden",style:{height:n,touchAction:"none"},id:U,children:[m,u(y.current)]}),k&&$.jsx(Ce,{contentSize:e,viewportSize:n,scrollPosition:y.current,onScroll:C,scrollBarWidth:r,ariaControls:U,tapScrollCircleOptions:g,itemCount:x})]}),[u,e,n,r,i,l,k,C,U,m,g,x]);return s.useEffect(()=>{const c=G.current;if(!c)return;const z=6,Y="input, textarea, select, button, a[href], [role='button']";let L=null,E=0,w=0,A=!1,p=!1,v=!1,I=null,t=[];const a=()=>{L=null,E=0,w=0,A=!1,p=!1,t=[]},T=f=>{const Z=performance.now();t.push({clientY:f,time:Z}),t=t.filter(q=>Z-q.time<=h.velocitySampleWindow)},R=f=>f instanceof HTMLElement?f.closest("[data-scrollpane-ignore-drag='true']")!==null:!1,S=f=>f instanceof HTMLElement?f.closest(Y)!==null:!1,V=f=>{v&&(f.preventDefault(),f.stopPropagation(),v=!1)},D=f=>{A||(A=!0,p=!1,v=!0,c.hasPointerCapture(f.pointerId)||c.setPointerCapture(f.pointerId),T(f.clientY))},M=f=>{if(L!==f.pointerId)return;if(!A){const ne=Math.abs(f.clientY-E);if(p&&ne<z)return;D(f)}if(!A)return;T(f.clientY);const Z=f.clientY-E,q=w-Z;C(q),f.cancelable&&f.preventDefault()},P=f=>{if(L!==f.pointerId)return;A&&v&&f.cancelable&&(f.preventDefault(),f.stopPropagation()),c.hasPointerCapture(f.pointerId)&&c.releasePointerCapture(f.pointerId);let Z=0;if(A&&t.length>=2){const q=t[t.length-1],ne=t.find(ae=>q.time-ae.time<=h.velocitySampleWindow)??t[0];if(q&&ne&&q.time!==ne.time){const ae=q.clientY-ne.clientY,de=q.time-ne.time;Z=-(ae/de)}}a(),I!==null&&window.clearTimeout(I),v&&(I=window.setTimeout(()=>{v=!1,I=null},0)),Math.abs(Z)>=h.startVelocityThreshold&&B(Z)},X=f=>{k&&(f.button!==0&&f.pointerType==="mouse"||f.ctrlKey||f.metaKey||f.altKey||R(f.target)||(window.dispatchEvent(new CustomEvent(we,{detail:{paneId:U}})),j(),L=f.pointerId,E=f.clientY,w=y.current,p=S(f.target),A=!1,v=!1,t=[],p||(v=!0,D(f),T(f.clientY),f.cancelable&&f.preventDefault())))},W=f=>{L===f.pointerId&&(v=!1,c.hasPointerCapture(f.pointerId)&&c.releasePointerCapture(f.pointerId),I!==null&&(window.clearTimeout(I),I=null),a())};return c.addEventListener("click",V,!0),c.addEventListener("pointerdown",X,{passive:!1}),c.addEventListener("pointermove",M,{passive:!1}),c.addEventListener("pointerup",P),c.addEventListener("pointercancel",W),window.addEventListener("pointermove",M,{passive:!1}),window.addEventListener("pointerup",P),window.addEventListener("pointercancel",W),()=>{c.removeEventListener("click",V,!0),c.removeEventListener("pointerdown",X),c.removeEventListener("pointermove",M),c.removeEventListener("pointerup",P),c.removeEventListener("pointercancel",W),window.removeEventListener("pointermove",M),window.removeEventListener("pointerup",P),window.removeEventListener("pointercancel",W),L!==null&&c.hasPointerCapture(L)&&c.releasePointerCapture(L),I!==null&&window.clearTimeout(I),j()}},[U,k,h,C,B,j]),re});class Oe{tree;deltas;size;baseValue;valueFn;total;constructor(e,n,r){this.reset(e,n,r)}reset(e,n,r){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 i=r?.sampleRange??{from:0,to:Math.min(99,this.size-1)},{mode:l,materializedValues:m}=this._calculateMode(i.from,i.to);if(this.baseValue=l,r?.materialize)for(let g=0;g<m.length;g++){const b=m[g],x=i.from+g;if(x>=this.size)break;const _=b-this.baseValue;this.deltas.set(x,_),this._updateTree(x,_)}}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 r=[];for(let b=e;b<=n&&!(b>=this.size);b++)r.push(this.valueFn(b));const o=[...r];if(r.length===0)return{mode:0,materializedValues:[]};r.sort((b,x)=>b-x);const i=Math.floor(r.length/2);let l;r.length%2===0?l=Math.floor((r[i-1]+r[i])/2):l=r[i];const m=new Map;let g=0;for(const b of r){const x=(m.get(b)??0)+1;m.set(b,x),x>g&&(g=x)}if(g>1){const b=[];for(const[_,y]of m.entries())y===g&&b.push(_);const x=b.reduce((_,y)=>_+y,0);l=Math.floor(x/b.length)}return{mode:l,materializedValues:o}}update(e,n){return this.updates([{index:e,value:n}])}updates(e){const n=e.map(({index:r,value:o})=>{if(r<0||r>=this.size)throw new Error(`Index ${r} out of bounds`);if(o<0)throw new Error("Value cannot be negative.");const i=this.deltas.has(r)?(this.deltas.get(r)??0)+this.baseValue:this.baseValue,l=o-i;return{index:r,change:l}}).filter(r=>r.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:r}of e){if(n<0||n>=this.size)throw new Error(`Index ${n} out of bounds`);const o=this.deltas.get(n)??0;this.deltas.set(n,o+r),this._updateTree(n,r)}return this.total}_updateTree(e,n){if(n===0)return;let r=e+1;for(;r<=this.size;)this.tree.set(r,(this.tree.get(r)??0)+n),r+=r&-r;this.total!==void 0&&(this.total+=n)}_materialize(e,n=!0){if(this.valueFn){const r=this.deltas.get(e)??0,i=this.valueFn(e)-this.baseValue;if(i!==r&&(this.deltas.set(e,i),n)){const l=i-r;this._updateTree(e,l)}}}prefixSum(e,n){if(e<0)return{cumulative:0,total:this.total,currentValue:0,safeIndex:0};const r=H(e,0,this.size-1),o=n?.materializeOption;if(o?.materialize&&this.valueFn){if(o.ranges)for(const g of o.ranges){const b=g.from,x=Math.min(g.to,this.size-1);for(let _=b;_<=x;_++)this._materialize(_)}this._materialize(r)}let i=0,l=r+1;for(;l>0;){const g=this.tree.get(l)??0;i+=g,l-=l&-l}const m=o?.materialize?this.get(r):(this.deltas.get(r)||0)+this.baseValue;return{cumulative:i+this.baseValue*(r+1),total:this.total,currentValue:m,safeIndex:r}}get(e,n){if(e<0||e>=this.size)throw new Error("Index out of bounds");const r=n?.materializeOption;if(r?.materialize&&this.valueFn)if(r.ranges){for(const o of r.ranges){const i=o.from,l=Math.min(o.to,this.size-1);for(let m=i;m<=l;m++)this._materialize(m)}e>=r.ranges[0].from&&e<=r.ranges[r.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 r of n.ranges){const o=r.from,i=Math.min(r.to,this.size-1);for(let l=o;l<=i;l++)this._materialize(l)}if(this.total===void 0)if(this.size===0)this.total=0;else{let r=this.baseValue*this.size;for(const o of this.deltas.values())r+=o;this.total=r,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 o=this.valueFn;this.reset(this.size,i=>o(i),{materialize:!0});return}const n=new Map;let r=this.baseValue*this.size;for(const[o,i]of this.deltas.entries()){if(r+=i,i===0)continue;let l=o+1;for(;l<=this.size;)n.set(l,(n.get(l)??0)+i),l+=l&-l}this.tree=n,this.total=r}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 r of this.deltas.keys())r>=e&&this.deltas.delete(r);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 r=0,o=this.size-1,i=-1,l,m=this.total;for(;r<=o;){const g=Math.floor((r+o)/2);l=this.prefixSum(g,n),m=l.total,l.cumulative>=e?(i=g,o=g-1):r=g+1}return{index:i,total:m,cumulative:l?.cumulative,currentValue:l?.currentValue,safeIndex:l?.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 r=0,o=this.size-1,i=-1,l,m=this.total;for(;r<=o;){const g=Math.floor((r+o)/2);l=this.prefixSum(g,n),m=l.total,l.cumulative<=e?(i=g,r=g+1):o=g-1}return{index:i,total:m,cumulative:l?.cumulative,currentValue:l?.currentValue,safeIndex:l?.safeIndex}}}const De=(u,e,n)=>{const r=Math.max(0,u),o=s.useRef(null),i=s.useMemo(()=>new Oe(r,e,n),[r,e,n]);return Object.is(o.current,i)||console.warn("[useFenwickMapTree] instance changed"),o.current=i,i};function Ke({itemCount:u,getItem:e,getItemHeight:n,viewportSize:r,overscanCount:o=5,className:i,onScroll:l,onRangeChange:m,children:g,background:b,initialScrollIndex:x,initialScrollOffset:_,tapScrollCircleOptions:y,inertiaOptions:te},se){const N=s.useRef(null),G=s.useRef(!1);s.useEffect(()=>(G.current=!0,()=>{G.current=!1}),[]);const F=s.useRef({size:u,valueOrFn:n,options:{sampleRange:{from:0,to:100}}}),h=De(F.current.size,F.current.valueOrFn,F.current.options),[J]=s.useState(()=>{let p=0,v=0;if(typeof x=="number"){const I=H(x,0,u-1),t=H(I-o*2,0,u-1),a=H(I+o*2,0,u-1),T=x>0?{materializeOption:{materialize:!0,ranges:[{from:t,to:a}]}}:void 0,{cumulative:R,total:S,currentValue:V}=h.prefixSum(x,T);p=R-V,v=S??h.getTotal()}else typeof _=="number"&&(p=_),v=h.getTotal();return{position:p,total:v}}),[k,C]=s.useState(J.position),[j,B]=s.useState(J.total),[U,re]=s.useState(J.position),[c,z]=s.useState(u);s.useLayoutEffect(()=>{h.setValueFn(n),c!==u&&(h.changeSize(u),z(u));const p=h.getTotal();j!==p&&B(p)},[h,c,u,j,n]),s.useLayoutEffect(()=>{U!==null&&N.current&&(ee.debug("[VirtualScroll] Scrolling to position:",U),N.current.scrollTo(U),re(null))},[U]);const Y=s.useCallback(p=>{if(N.current){ee.debug("[VirtualScroll] Scrolling to index:",p);const v=H(p,0,c-1),I=H(v-o*2,0,c-1),t=H(v+o*2,0,c-1),{cumulative:a,total:T,currentValue:R}=h.prefixSum(v,{materializeOption:{materialize:!0,ranges:[{from:I,to:t}]}});ee.debug("[VirtualScroll] Scrolling to index:",p,"Offset:",a,"Total height:",T,"Current value:",R,"safeIndex:",v,"safeIndexFrom:",I,"safeIndexTo:",t),T&&(B(T),re(a-R)),ee.debug("[VirtualScroll] Setting scroll position to:",a-R)}},[h,o,c]),L=s.useCallback(p=>{if(N.current){const v=h.getTotal(),I=H(Math.floor(p),0,v),t=h.findIndexAtOrAfter(I,{materializeOption:{materialize:!1}}).index;Y(t)}},[h,Y]),E=s.useCallback((p,v)=>{ee.debug("[VirtualScroll] Scroll position changed:",p),C(p);const I=h.getTotal();l?.(p,I)},[h,l]),w=s.useMemo(()=>{if(c===0)return{renderingStartIndex:0,renderingEndIndex:0,visibleStartIndex:0,visibleEndIndex:0};const{index:p,cumulative:v,currentValue:I}=h.findIndexAtOrAfter(k,{materializeOption:{materialize:!1}});let t=0;p===-1?t=0:(v??0)<k+(I??0)?t=1:t=0;const a=p===-1?0:p+t,T=H(a-o,0,c-1);let R=0,S=p===-1?0:p+t;for(;S<c&&R<r;){const D=n(S);R+=D,S++}S-=1;const V=H(S+o,0,c-1);return ee.debug("[VirtualScroll] Calculated rendering range:",{renderingStartIndex:T,renderingEndIndex:V,visibleStartIndex:a,visibleEndIndex:S,scrollPosition:k,renderingContentSize:h.getTotal(),overscanCount:o,viewportSize:r}),{renderingStartIndex:T,renderingEndIndex:V,visibleStartIndex:a,visibleEndIndex:S}},[k,o,r,n,h,c]);s.useEffect(()=>{const p=N.current?.getScrollPosition()??0;ee.debug("[VirtualScroll] Range change effect triggered",{renderingStartIndex:w.renderingStartIndex,renderingEndIndex:w.renderingEndIndex,visibleStartIndex:w.visibleStartIndex,visibleEndIndex:w.visibleEndIndex,scrollPosition:k,contentSize:j,scrollPaneScrollPosition:p}),m?.(w.renderingStartIndex,w.renderingEndIndex,w.visibleStartIndex,w.visibleEndIndex,k,j)},[w.renderingStartIndex,w.renderingEndIndex,w.visibleStartIndex,w.visibleEndIndex,m,k,j]);const A=s.useCallback(p=>{const{renderingStartIndex:v,renderingEndIndex:I}=w;if(ee.debug("[VirtualScroll] Rendering visible items",{currentScrollPosition:p,renderingStartIndex:v,renderingEndIndex:I,fenwickSize:c,viewportSize:r}),c===0)return $.jsx("div",{className:"absolute w-full",style:{top:0},children:$.jsx("div",{className:"text-center text-gray-500",children:"No items"})});const t=H(v,0,c-1),{cumulative:a,currentValue:T}=h.prefixSum(t,{materializeOption:{materialize:!1}}),R=a-T,S=[],V=[];for(let M=v;M<=I;M++){const P=n(M);S.push({item:e(M),height:P}),h.get(M)!==P&&V.push({index:M,value:P})}V.length>0&&Promise.resolve().then(()=>{const M=h.updates(V);M&&(B(M),ee.debug("[VirtualScroll] Updated heights for items",V,"New total height:",M))});const D=j<r?0:R-p;return ee.debug("[VirtualScroll] Rendering items",{visibleItems:S,containerTop:D}),$.jsx("div",{className:"absolute w-full",style:{top:D},children:S.map(({item:M,height:P},X)=>{const W=v+X,f=H(W,0,c-1),{cumulative:Z,currentValue:q}=h.prefixSum(f,{materializeOption:{materialize:!1}}),ne=Z-q;return $.jsx("div",{"data-index":W,style:{position:"absolute",top:ne-R,width:"100%"},children:g(M,W)},W)})})},[e,g,j,r,w,h,c,n]);return s.useImperativeHandle(se,()=>({getScrollPosition:()=>N.current?.getScrollPosition()??-1,getContentSize:()=>N.current?.getContentSize()??-1,getViewportSize:()=>N.current?.getViewportSize()??-1,scrollTo:p=>L(p),scrollToIndex:p=>Y(p),getFenwickTreeTotalHeight:()=>h.getTotal(),getFenwickSize:()=>h.getSize()}),[Y,h,L]),$.jsx(Le,{ref:N,contentSize:j,viewportSize:r,className:i,onScroll:E,background:b,tapScrollCircleOptions:y,inertiaOptions:te,itemCount:u,children:A})}const Ze=s.forwardRef(Ke);class Qe{key;value;prev=null;next=null;constructor(e,n){this.key=e,this.value=n}}class Ae{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 Fe(u){const e=s.useRef(new Map),n=s.useRef(new Ae);s.useEffect(()=>{for(;e.current.size>u;){const b=n.current.removeHead();if(b)e.current.delete(b.key);else break}},[u]);const r=s.useCallback(b=>{const x=e.current.get(b);if(x)return n.current.moveToTail(x),x.value},[]),o=s.useCallback((b,x)=>{if(u<=0)return;let _=e.current.get(b);if(_)_.value=x,n.current.moveToTail(_);else{if(e.current.size>=u){const y=n.current.removeHead();y&&e.current.delete(y.key)}_=new Qe(b,x),e.current.set(b,_),n.current.addToTail(_)}},[u]),i=s.useCallback(b=>e.current.has(b),[]),l=s.useCallback(()=>{e.current.clear(),n.current=new Ae},[]),[m,g]=s.useState(()=>({get:r,set:o,has:i,clear:l}));return s.useEffect(()=>g({get:r,set:o,has:i,clear:l}),[r,o,i,l]),m}const et=1e4,tt=()=>{const{get:u,set:e,has:n,clear:r}=Fe(et);return{get:u,set:e,has:n,clear:r}};exports.FenwickMapTree=Oe;exports.ScrollBar=Ce;exports.ScrollPane=Le;exports.VirtualScroll=Ze;exports.minmax=H;exports.useFenwickMapTree=De;exports.useHeightCache=tt;exports.useLruCache=Fe;
|
|
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;
|
|
23
2
|
//# sourceMappingURL=index.cjs.map
|