@aiquants/virtualscroll 0.2.2 → 0.4.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 +41 -1
- package/dist/index.cjs +4 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1037 -572
- package/dist/index.js.map +1 -1
- package/dist/src/ScrollBar.d.ts +30 -1
- package/dist/src/ScrollBar.d.ts.map +1 -1
- package/dist/src/ScrollPane.d.ts +19 -0
- package/dist/src/ScrollPane.d.ts.map +1 -1
- package/dist/src/TapScrollCircle.d.ts +45 -0
- package/dist/src/TapScrollCircle.d.ts.map +1 -0
- package/dist/src/VirtualScroll.d.ts +3 -1
- package/dist/src/VirtualScroll.d.ts.map +1 -1
- package/dist/src/index.d.ts +2 -8
- package/dist/src/index.d.ts.map +1 -1
- package/dist/virtualscroll.css +1 -0
- package/dist/vite.config.d.ts.map +1 -1
- package/package.json +5 -2
package/README.md
CHANGED
|
@@ -11,7 +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
|
-
-
|
|
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
|
|
15
16
|
|
|
16
17
|
## Installation
|
|
17
18
|
|
|
@@ -93,6 +94,8 @@ function App() {
|
|
|
93
94
|
| `background` | `ReactNode` | ❌ | Background element |
|
|
94
95
|
| `initialScrollIndex` | `number` | ❌ | Initial scroll index |
|
|
95
96
|
| `initialScrollOffset` | `number` | ❌ | Initial scroll offset |
|
|
97
|
+
| `tapScrollCircleOptions` | `ScrollBarTapCircleOptions` | ❌ | Customization for the auxiliary tap scroll circle |
|
|
98
|
+
| `inertiaOptions` | `ScrollPaneInertiaOptions` | ❌ | Physics tuning for drag inertia |
|
|
96
99
|
|
|
97
100
|
### VirtualScrollHandle Methods
|
|
98
101
|
|
|
@@ -173,6 +176,43 @@ function AdvancedExample() {
|
|
|
173
176
|
</style>
|
|
174
177
|
```
|
|
175
178
|
|
|
179
|
+
### Tap Scroll Circle Configuration
|
|
180
|
+
|
|
181
|
+
The auxiliary tap scroll circle can replace the native scrollbar for large datasets while remaining easy to control:
|
|
182
|
+
|
|
183
|
+
- **Adaptive speed scaling** automatically ramps up to a `120×` multiplier as `itemCount` grows (trillions supported).
|
|
184
|
+
- **Manual overrides** let you clamp or extend speed via `maxSpeedMultiplier` when you need deterministic behavior.
|
|
185
|
+
- **Full layout control** (`size`, `offsetX`, `offsetY`) keeps the circle accessible on both desktop and touch devices.
|
|
186
|
+
- **Visibility tuning** exposes an `opacity` knob so you can match subdued or high-contrast UI themes.
|
|
187
|
+
|
|
188
|
+
```tsx
|
|
189
|
+
import { VirtualScroll } from "@aiquants/virtualscroll"
|
|
190
|
+
|
|
191
|
+
const items = Array.from({ length: 1_000_000_000_000 }, (_, index) => ({
|
|
192
|
+
id: index,
|
|
193
|
+
text: `Record ${index}`,
|
|
194
|
+
height: 42,
|
|
195
|
+
}))
|
|
196
|
+
|
|
197
|
+
export function UltraFastExample() {
|
|
198
|
+
return (
|
|
199
|
+
<VirtualScroll
|
|
200
|
+
itemCount={items.length}
|
|
201
|
+
getItem={(index) => items[index]}
|
|
202
|
+
getItemHeight={() => 42}
|
|
203
|
+
viewportSize={480}
|
|
204
|
+
tapScrollCircleOptions={{
|
|
205
|
+
maxSpeedMultiplier: 80, // Optional: override adaptive speed when needed
|
|
206
|
+
offsetX: -96,
|
|
207
|
+
opacity: 0.85,
|
|
208
|
+
}}
|
|
209
|
+
>
|
|
210
|
+
{(item) => <div style={{ height: item.height }}>{item.text}</div>}
|
|
211
|
+
</VirtualScroll>
|
|
212
|
+
)
|
|
213
|
+
}
|
|
214
|
+
```
|
|
215
|
+
|
|
176
216
|
## Performance Tips
|
|
177
217
|
|
|
178
218
|
1. **Memoize callback functions**: Use `useCallback` for `getItem` and `getItemHeight`
|
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react"),fe=require("tailwind-merge");var pe={exports:{}},le={};/**
|
|
2
2
|
* @license React
|
|
3
3
|
* react-jsx-runtime.production.js
|
|
4
4
|
*
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* This source code is licensed under the MIT license found in the
|
|
8
8
|
* LICENSE file in the root directory of this source tree.
|
|
9
|
-
*/var
|
|
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
10
|
* @license React
|
|
11
11
|
* react-jsx-runtime.development.js
|
|
12
12
|
*
|
|
@@ -14,10 +14,10 @@
|
|
|
14
14
|
*
|
|
15
15
|
* This source code is licensed under the MIT license found in the
|
|
16
16
|
* LICENSE file in the root directory of this source tree.
|
|
17
|
-
*/var
|
|
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
18
|
let props = %s;
|
|
19
19
|
<%s {...props} />
|
|
20
20
|
React keys must be passed directly to JSX without using spread:
|
|
21
21
|
let props = %s;
|
|
22
|
-
<%s key={someKey} {...props} />`,p,k,q,k),C[k+p]=!0)}if(k=null,m!==void 0&&(r(m),k=""+m),a(u)&&(r(u.key),k=""+u.key),"key"in u){m={};for(var B in u)B!=="key"&&(m[B]=u[B])}else m=u;return k&&h(m,typeof n=="function"?n.displayName||n.name||"Unknown":n),c(n,k,E,z,s(),m,U,X)}function x(n){typeof n=="object"&&n!==null&&n.$$typeof===T&&n._store&&(n._store.validated=1)}var S=f,T=Symbol.for("react.transitional.element"),I=Symbol.for("react.portal"),j=Symbol.for("react.fragment"),v=Symbol.for("react.strict_mode"),_=Symbol.for("react.profiler"),w=Symbol.for("react.consumer"),d=Symbol.for("react.context"),P=Symbol.for("react.forward_ref"),V=Symbol.for("react.suspense"),L=Symbol.for("react.suspense_list"),Y=Symbol.for("react.memo"),y=Symbol.for("react.lazy"),W=Symbol.for("react.activity"),$=Symbol.for("react.client.reference"),H=S.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,J=Object.prototype.hasOwnProperty,M=Array.isArray,G=console.createTask?console.createTask:function(){return null};S={react_stack_bottom_frame:function(n){return n()}};var b,R={},F=S.react_stack_bottom_frame.bind(S,o)(),O=G(t(o)),C={};Q.Fragment=j,Q.jsx=function(n,u,m,p,z){var E=1e4>H.recentlyCreatedOwnerStacks++;return g(n,u,m,!1,p,z,E?Error("react-stack-top-frame"):F,E?G(t(n)):O)},Q.jsxs=function(n,u,m,p,z){var E=1e4>H.recentlyCreatedOwnerStacks++;return g(n,u,m,!0,p,z,E?Error("react-stack-top-frame"):F,E?G(t(n)):O)}})()),Q}var se;function ge(){return se||(se=1,process.env.NODE_ENV==="production"?K.exports=he():K.exports=me()),K.exports}var D=ge();const N={debug(l,...e){typeof window<"u"&&window.localStorage?.getItem("debug")==="true"&&console.debug(`[VirtualScroll] ${l}`,...e)},warn(l,...e){console.warn(`[VirtualScroll] ${l}`,...e)},error(l,...e){console.error(`[VirtualScroll] ${l}`,...e)}},A=(l,e,r)=>Math.min(r,Math.max(e,l)),ae=(l,e,r)=>{const t="touches"in l.nativeEvent,s=t?l.nativeEvent.touches[0]:l.nativeEvent,o=h=>{t&&h.cancelable&&h.preventDefault();const i="touches"in h?h.touches[0]:h;e({deltaX:i.clientX-s.clientX,deltaY:i.clientY-s.clientY})},a=()=>{t?(document.removeEventListener("touchmove",o),document.removeEventListener("touchend",a)):(document.removeEventListener("mousemove",o),document.removeEventListener("mouseup",a)),r?.()};t?(document.addEventListener("touchmove",o,{passive:!1}),document.addEventListener("touchend",a)):(document.addEventListener("mousemove",o),document.addEventListener("mouseup",a))},be=20,ie=({contentSize:l,viewportSize:e,scrollPosition:r,onScroll:t,horizontal:s=!1,scrollBarWidth:o=12,className:a,ariaControls:h})=>{const[i,c]=f.useState(!1),g=f.useRef(null),x=e/l,S=Math.max(be,x*e),T=l-e,I=r/T*(e-S),j=l>e;f.useEffect(()=>{g.current&&(i?g.current.style.backgroundColor="#4F4F4F":g.current.style.backgroundColor="#7F7F7F")},[i]);const v=d=>A(d/(e-S)*T,0,T),_=d=>{if(!j||"button"in d&&d.button!==0||d.ctrlKey)return;d.stopPropagation();const P=I;c(!0),ae(d,({deltaX:V,deltaY:L})=>{t?.(v(P+(s?V:L)),I)},()=>{c(!1)})},w=d=>{if(!j||"button"in d&&d.button!==0||d.ctrlKey)return;const V="touches"in d.nativeEvent?d.nativeEvent.touches[0]:d.nativeEvent,L=s?V.clientX:V.clientY,Y=d.currentTarget.getBoundingClientRect(),W=(s?L-Y.left:L-Y.top)-S/2;t?.(v(W),I),ae(d,({deltaX:$,deltaY:H})=>{t?.(v(W+(s?$:H)),I)})};return D.jsx("div",{className:te.twMerge("group relative cursor-default select-none",a),style:{[s?"width":"height"]:e,[s?"height":"width"]:o,backgroundColor:"white",userSelect:"none"},onMouseDown:w,onTouchStart:w,role:"scrollbar",tabIndex:-1,"aria-controls":h,"aria-valuenow":r,"aria-valuemin":0,"aria-valuemax":T,"aria-orientation":s?"horizontal":"vertical",children:l>e&&D.jsx("div",{className:"group absolute",style:{[s?"width":"height"]:S,[s?"left":"top"]:I,...s?{top:0,bottom:0}:{left:0,right:0}},onMouseDown:_,onTouchStart:_,role:"slider","aria-orientation":s?"horizontal":"vertical","aria-valuenow":r,"aria-valuemin":0,"aria-valuemax":T,tabIndex:0,children:D.jsx("div",{ref:g,className:te.twMerge("absolute",s?`inset-x-0 inset-y-[1.5px] group-hover:inset-y-[-0.5px] ${i?"inset-y-[-2px]":"group-active:inset-y-[-2px]"}`:`inset-x-[1.5px] inset-y-0 group-hover:inset-x-[-0.5px] ${i?"inset-x-[-2px]":"group-active:inset-x-[-2px]"}`),style:{backgroundColor:"#7F7F7F",borderRadius:o-1,...s?{left:0,right:0,top:i?-2:1.5,bottom:i?-2:1.5}:{top:0,bottom:0,left:i?-2:1.5,right:i?-2:1.5}},onMouseEnter:d=>{s?(d.currentTarget.style.top="-0.5px",d.currentTarget.style.bottom="-0.5px"):(d.currentTarget.style.left="-0.5px",d.currentTarget.style.right="-0.5px"),i||(d.currentTarget.style.backgroundColor="#5F5F5F")},onMouseLeave:d=>{s?(d.currentTarget.style.top=i?"-2px":"1.5px",d.currentTarget.style.bottom=i?"-2px":"1.5px"):(d.currentTarget.style.left=i?"-2px":"1.5px",d.currentTarget.style.right=i?"-2px":"1.5px"),i||(d.currentTarget.style.backgroundColor="#7F7F7F")}})})})},le=f.forwardRef(({children:l,contentSize:e,viewportSize:r,scrollBarWidth:t=12,onScroll:s,className:o,style:a,background:h},i)=>{const c=f.useRef(0),[g,x]=f.useReducer(_=>_+1,0),S=f.useRef(null);N.debug("[ScrollPane] ScrollPane rendered",{contentSize:e,viewportSize:r,scrollBarWidth:t,className:o,style:a});const T=f.useMemo(()=>e>r,[e,r]),I=f.useCallback(_=>{const w=e>r,d=c.current;if(N.debug("[ScrollPane] scrollTo called",{newPosition:_,contentSize:e,viewportSize:r,currentIsScrollable:w,prevPosition:d}),!w){c.current!==0&&(c.current=0,s?.(0,d));return}const P=typeof _=="function"?_(c.current):_,V=A(P,0,e-r);c.current!==V&&(c.current=V,s?.(V,d))},[s,e,r]);f.useLayoutEffect(()=>{if(T){N.debug("[ScrollPane] Adjusting scroll position due to content or viewport size change",{contentSize:e,viewportSize:r,scrollPosition:c.current});const _=A(e-r,0,e);c.current>_&&I(_)}else I(0)},[T,I,e,r]),f.useEffect(()=>{const _=d=>{if(!T)return;d.preventDefault();let P=d.deltaY;d.deltaMode===1?P*=16:d.deltaMode===2&&(P*=r),N.debug("[ScrollPane] wheel event",{deltaY:P,scrollPosition:c.current}),I(V=>V+P)},w=S.current;return w&&w.addEventListener("wheel",_,{passive:!1}),()=>{w&&w.removeEventListener("wheel",_)}},[T,I,r]),f.useImperativeHandle(i,()=>({scrollTo:I,getScrollPosition:()=>c.current,getContentSize:()=>e,getViewportSize:()=>r}),[I,e,r]);const j=f.useId();return f.useMemo(()=>D.jsxs("div",{ref:S,className:te.twMerge("flex",o),style:a,children:[D.jsxs("div",{className:"relative h-full flex-1 overflow-hidden",style:{height:r},id:j,children:[h,l(c.current)]}),T&&D.jsx(ie,{contentSize:e,viewportSize:r,scrollPosition:c.current,onScroll:I,scrollBarWidth:t,ariaControls:j})]}),[l,e,r,t,o,a,T,I,j,h])});class ue{tree;deltas;size;baseValue;valueFn;total;constructor(e,r,t){this.reset(e,r,t)}reset(e,r,t){if(this.size=e,this.tree=new Map,this.deltas=new Map,this.total=void 0,typeof r=="function"){if(this.valueFn=r,this.size>0){const o=t?.sampleRange??{from:0,to:Math.min(99,this.size-1)},{mode:a,materializedValues:h}=this._calculateMode(o.from,o.to);if(this.baseValue=a,t?.materialize)for(let i=0;i<h.length;i++){const c=h[i],g=o.from+i;if(g>=this.size)break;const x=c-this.baseValue;this.deltas.set(g,x),this._updateTree(g,x)}}else this.baseValue=0;this.total=this.getTotal()}else this.valueFn=void 0,this.baseValue=r,this.total=this.baseValue*this.size}setValueFn(e){typeof e=="function"?this.valueFn=e:(this.valueFn=void 0,this.baseValue=e)}_calculateMode(e,r){if(!this.valueFn)return{mode:0,materializedValues:[]};const t=[];for(let c=e;c<=r&&!(c>=this.size);c++)t.push(this.valueFn(c));const s=[...t];if(t.length===0)return{mode:0,materializedValues:[]};t.sort((c,g)=>c-g);const o=Math.floor(t.length/2);let a;t.length%2===0?a=Math.floor((t[o-1]+t[o])/2):a=t[o];const h=new Map;let i=0;for(const c of t){const g=(h.get(c)??0)+1;h.set(c,g),g>i&&(i=g)}if(i>1){const c=[];for(const[x,S]of h.entries())S===i&&c.push(x);const g=c.reduce((x,S)=>x+S,0);a=Math.floor(g/c.length)}return{mode:a,materializedValues:s}}update(e,r){return this.updates([{index:e,value:r}])}updates(e){const r=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 o=this.deltas.has(t)?(this.deltas.get(t)??0)+this.baseValue:this.baseValue,a=s-o;return{index:t,change:a}}).filter(t=>t.change!==0);return r.length>0?this.updateDeltas(r):this.total}updateDelta(e,r){return this.updateDeltas([{index:e,change:r}])}updateDeltas(e){for(const{index:r,change:t}of e){if(r<0||r>=this.size)throw new Error(`Index ${r} out of bounds`);const s=this.deltas.get(r)??0;this.deltas.set(r,s+t),this._updateTree(r,t)}return this.total}_updateTree(e,r){if(r===0)return;let t=e+1;for(;t<=this.size;)this.tree.set(t,(this.tree.get(t)??0)+r),t+=t&-t;this.total!==void 0&&(this.total+=r)}_materialize(e,r=!0){if(this.valueFn){const t=this.deltas.get(e)??0,o=this.valueFn(e)-this.baseValue;if(o!==t&&(this.deltas.set(e,o),r)){const a=o-t;this._updateTree(e,a)}}}prefixSum(e,r){if(e<0)return{cumulative:0,total:this.total,currentValue:0,safeIndex:0};const t=A(e,0,this.size-1),s=r?.materializeOption;if(s?.materialize&&this.valueFn){if(s.ranges)for(const i of s.ranges){const c=i.from,g=Math.min(i.to,this.size-1);for(let x=c;x<=g;x++)this._materialize(x)}this._materialize(t)}let o=0,a=t+1;for(;a>0;){const i=this.tree.get(a)??0;o+=i,a-=a&-a}const h=s?.materialize?this.get(t):(this.deltas.get(t)||0)+this.baseValue;return{cumulative:o+this.baseValue*(t+1),total:this.total,currentValue:h,safeIndex:t}}get(e,r){if(e<0||e>=this.size)throw new Error("Index out of bounds");const t=r?.materializeOption;if(t?.materialize&&this.valueFn)if(t.ranges){for(const s of t.ranges){const o=s.from,a=Math.min(s.to,this.size-1);for(let h=o;h<=a;h++)this._materialize(h)}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 r=e?.materializeOption;if(r?.materialize&&this.valueFn&&r.ranges)for(const t of r.ranges){const s=t.from,o=Math.min(t.to,this.size-1);for(let a=s;a<=o;a++)this._materialize(a)}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,o=>s(o),{materialize:!0});return}const r=new Map;let t=this.baseValue*this.size;for(const[s,o]of this.deltas.entries()){if(t+=o,o===0)continue;let a=s+1;for(;a<=this.size;)r.set(a,(r.get(a)??0)+o),a+=a&-a}this.tree=r,this.total=t}calculateAccumulatedError(){if(this.total===void 0)return 0;let e=this.baseValue*this.size;for(const r of this.deltas.values())e+=r;return this.total-e}changeSize(e){const r=this.size;if(e!==r){if(e<r)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,r){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,o=-1,a,h=this.total;for(;t<=s;){const i=Math.floor((t+s)/2);a=this.prefixSum(i,r),h=a.total,a.cumulative>=e?(o=i,s=i-1):t=i+1}return{index:o,total:h,cumulative:a?.cumulative,currentValue:a?.currentValue,safeIndex:a?.safeIndex}}findIndexAtOrBefore(e,r){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,o=-1,a,h=this.total;for(;t<=s;){const i=Math.floor((t+s)/2);a=this.prefixSum(i,r),h=a.total,a.cumulative<=e?(o=i,t=i+1):s=i-1}return{index:o,total:h,cumulative:a?.cumulative,currentValue:a?.currentValue,safeIndex:a?.safeIndex}}}const ce=(l,e,r)=>{const t=Math.max(0,l),s=f.useRef(null),o=f.useMemo(()=>new ue(t,e,r),[t,e,r]);return Object.is(s.current,o)||console.warn("[useFenwickMapTree] instance changed"),s.current=o,o};function ve({itemCount:l,getItem:e,getItemHeight:r,viewportSize:t,overscanCount:s=5,className:o,onScroll:a,onRangeChange:h,children:i,background:c,initialScrollIndex:g,initialScrollOffset:x},S){const T=f.useRef(null),I=f.useRef(!1);f.useEffect(()=>(I.current=!0,()=>{I.current=!1}),[]);const j=f.useRef({size:l,valueOrFn:r,options:{sampleRange:{from:0,to:100}}}),v=ce(j.current.size,j.current.valueOrFn,j.current.options),[_]=f.useState(()=>{let b=0,R=0;if(typeof g=="number"){const F=A(g,0,l-1),O=A(F-s*2,0,l-1),C=A(F+s*2,0,l-1),n=g>0?{materializeOption:{materialize:!0,ranges:[{from:O,to:C}]}}:void 0,{cumulative:u,total:m,currentValue:p}=v.prefixSum(g,n);b=u-p,R=m??v.getTotal()}else typeof x=="number"&&(b=x),R=v.getTotal();return{position:b,total:R}}),[w,d]=f.useState(_.position),[P,V]=f.useState(_.total),[L,Y]=f.useState(_.position),[y,W]=f.useState(l);f.useLayoutEffect(()=>{v.setValueFn(r),y!==l&&(v.changeSize(l),W(l));const b=v.getTotal();P!==b&&V(b)},[v,y,l,P,r]),f.useLayoutEffect(()=>{L!==null&&T.current&&(N.debug("[VirtualScroll] Scrolling to position:",L),T.current.scrollTo(L),Y(null))},[L]);const $=f.useCallback(b=>{if(T.current){N.debug("[VirtualScroll] Scrolling to index:",b);const R=A(b,0,y-1),F=A(R-s*2,0,y-1),O=A(R+s*2,0,y-1),{cumulative:C,total:n,currentValue:u}=v.prefixSum(R,{materializeOption:{materialize:!0,ranges:[{from:F,to:O}]}});N.debug("[VirtualScroll] Scrolling to index:",b,"Offset:",C,"Total height:",n,"Current value:",u,"safeIndex:",R,"safeIndexFrom:",F,"safeIndexTo:",O),n&&(V(n),Y(C-u)),N.debug("[VirtualScroll] Setting scroll position to:",C-u)}},[v,s,y]),H=f.useCallback(b=>{if(T.current){const R=v.getTotal(),F=A(Math.floor(b),0,R),O=v.findIndexAtOrAfter(F,{materializeOption:{materialize:!1}}).index;$(O)}},[v,$]),J=f.useCallback((b,R)=>{N.debug("[VirtualScroll] Scroll position changed:",b),d(b);const F=v.getTotal();a?.(b,F)},[v,a]),M=f.useMemo(()=>{if(y===0)return{renderingStartIndex:0,renderingEndIndex:0,visibleStartIndex:0,visibleEndIndex:0};const{index:b,cumulative:R,currentValue:F}=v.findIndexAtOrAfter(w,{materializeOption:{materialize:!1}});let O=0;b===-1?O=0:(R??0)<w+(F??0)?O=1:O=0;const C=b===-1?0:b+O,n=A(C-s,0,y-1);let u=0,m=b===-1?0:b+O;for(;m<y&&u<t;){const z=r(m);u+=z,m++}m-=1;const p=A(m+s,0,y-1);return N.debug("[VirtualScroll] Calculated rendering range:",{renderingStartIndex:n,renderingEndIndex:p,visibleStartIndex:C,visibleEndIndex:m,scrollPosition:w,renderingContentSize:v.getTotal(),overscanCount:s,viewportSize:t}),{renderingStartIndex:n,renderingEndIndex:p,visibleStartIndex:C,visibleEndIndex:m}},[w,s,t,r,v,y]);f.useEffect(()=>{const b=T.current?.getScrollPosition()??0;N.debug("[VirtualScroll] Range change effect triggered",{renderingStartIndex:M.renderingStartIndex,renderingEndIndex:M.renderingEndIndex,visibleStartIndex:M.visibleStartIndex,visibleEndIndex:M.visibleEndIndex,scrollPosition:w,contentSize:P,scrollPaneScrollPosition:b}),h?.(M.renderingStartIndex,M.renderingEndIndex,M.visibleStartIndex,M.visibleEndIndex,w,P)},[M.renderingStartIndex,M.renderingEndIndex,M.visibleStartIndex,M.visibleEndIndex,h,w,P]);const G=f.useCallback(b=>{const{renderingStartIndex:R,renderingEndIndex:F}=M;if(N.debug("[VirtualScroll] Rendering visible items",{currentScrollPosition:b,renderingStartIndex:R,renderingEndIndex:F,fenwickSize:y,viewportSize:t}),y===0)return D.jsx("div",{className:"absolute w-full",style:{top:0},children:D.jsx("div",{className:"text-center text-gray-500",children:"No items"})});const O=A(R,0,y-1),{cumulative:C,currentValue:n}=v.prefixSum(O,{materializeOption:{materialize:!1}}),u=C-n,m=[],p=[];for(let E=R;E<=F;E++){const U=r(E);m.push({item:e(E),height:U}),v.get(E)!==U&&p.push({index:E,value:U})}p.length>0&&Promise.resolve().then(()=>{const E=v.updates(p);E&&(V(E),N.debug("[VirtualScroll] Updated heights for items",p,"New total height:",E))});const z=P<t?0:u-b;return N.debug("[VirtualScroll] Rendering items",{visibleItems:m,containerTop:z}),D.jsx("div",{className:"absolute w-full",style:{top:z},children:m.map(({item:E,height:U},X)=>{const k=R+X,q=A(k,0,y-1),{cumulative:B,currentValue:ee}=v.prefixSum(q,{materializeOption:{materialize:!1}}),de=B-ee;return D.jsx("div",{"data-index":k,style:{position:"absolute",top:de-u,width:"100%"},children:i(E,k)},k)})})},[e,i,P,t,M,v,y,r]);return f.useImperativeHandle(S,()=>({getScrollPosition:()=>T.current?.getScrollPosition()??-1,getContentSize:()=>T.current?.getContentSize()??-1,getViewportSize:()=>T.current?.getViewportSize()??-1,scrollTo:b=>H(b),scrollToIndex:b=>$(b),getFenwickTreeTotalHeight:()=>v.getTotal(),getFenwickSize:()=>v.getSize()}),[$,v,H]),D.jsx(le,{ref:T,contentSize:P,viewportSize:t,className:o,onScroll:J,background:c,children:G})}const xe=f.forwardRef(ve);class pe{key;value;prev=null;next=null;constructor(e,r){this.key=e,this.value=r}}class oe{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(l){const e=f.useRef(new Map),r=f.useRef(new oe);f.useEffect(()=>{for(;e.current.size>l;){const c=r.current.removeHead();if(c)e.current.delete(c.key);else break}},[l]);const t=f.useCallback(c=>{const g=e.current.get(c);if(g)return r.current.moveToTail(g),g.value},[]),s=f.useCallback((c,g)=>{if(l<=0)return;let x=e.current.get(c);if(x)x.value=g,r.current.moveToTail(x);else{if(e.current.size>=l){const S=r.current.removeHead();S&&e.current.delete(S.key)}x=new pe(c,g),e.current.set(c,x),r.current.addToTail(x)}},[l]),o=f.useCallback(c=>e.current.has(c),[]),a=f.useCallback(()=>{e.current.clear(),r.current=new oe},[]),[h,i]=f.useState(()=>({get:t,set:s,has:o,clear:a}));return f.useEffect(()=>i({get:t,set:s,has:o,clear:a}),[t,s,o,a]),h}const Te=1e4,Ee=()=>{const{get:l,set:e,has:r,clear:t}=fe(Te);return{get:l,set:e,has:r,clear:t}};exports.FenwickMapTree=ue;exports.ScrollBar=ie;exports.ScrollPane=le;exports.VirtualScroll=xe;exports.minmax=A;exports.useFenwickMapTree=ce;exports.useHeightCache=Ee;exports.useLruCache=fe;
|
|
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;
|
|
23
23
|
//# sourceMappingURL=index.cjs.map
|