@aiquants/virtualscroll 0.2.0 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("react"),te=require("tailwind-merge");var K={exports:{}},B={};/**
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("react"),te=require("tailwind-merge");var K={exports:{}},Z={};/**
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 re;function de(){if(re)return B;re=1;var u=Symbol.for("react.transitional.element"),e=Symbol.for("react.fragment");function n(r,s,o){var a=null;if(o!==void 0&&(a=""+o),s.key!==void 0&&(a=""+s.key),"key"in s){o={};for(var h in s)h!=="key"&&(o[h]=s[h])}else o=s;return s=o.ref,{$$typeof:u,type:r,key:a,ref:s!==void 0?s:null,props:o}}return B.Fragment=e,B.jsx=n,B.jsxs=n,B}var Z={};/**
9
+ */var re;function he(){if(re)return Z;re=1;var l=Symbol.for("react.transitional.element"),e=Symbol.for("react.fragment");function r(t,s,o){var a=null;if(o!==void 0&&(a=""+o),s.key!==void 0&&(a=""+s.key),"key"in s){o={};for(var h in s)h!=="key"&&(o[h]=s[h])}else o=s;return s=o.ref,{$$typeof:l,type:t,key:a,ref:s!==void 0?s:null,props:o}}return Z.Fragment=e,Z.jsx=r,Z.jsxs=r,Z}var Q={};/**
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 ne;function he(){return ne||(ne=1,process.env.NODE_ENV!=="production"&&(function(){function u(t){if(t==null)return null;if(typeof t=="function")return t.$$typeof===$?null:t.displayName||t.name||null;if(typeof t=="string")return t;switch(t){case M:return"Fragment";case w:return"Profiler";case v:return"StrictMode";case F:return"Suspense";case N:return"SuspenseList";case q: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 k:return"Portal";case d:return(t.displayName||"Context")+".Provider";case I:return(t._context.displayName||"Context")+".Consumer";case P:var i=t.render;return t=t.displayName,t||(t=i.displayName||i.name||"",t=t!==""?"ForwardRef("+t+")":"ForwardRef"),t;case Y:return i=t.displayName||null,i!==null?i:u(t.type)||"Memo";case _:i=t._payload,t=t._init;try{return u(t(i))}catch{}}return null}function e(t){return""+t}function n(t){try{e(t);var i=!1}catch{i=!0}if(i){i=console;var g=i.error,x=typeof Symbol=="function"&&Symbol.toStringTag&&t[Symbol.toStringTag]||t.constructor.name||"Object";return g.call(i,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",x),e(t)}}function r(t){if(t===M)return"<>";if(typeof t=="object"&&t!==null&&t.$$typeof===_)return"<...>";try{var i=u(t);return i?"<"+i+">":"<...>"}catch{return"<...>"}}function s(){var t=H.A;return t===null?null:t.getOwner()}function o(){return Error("react-stack-top-frame")}function a(t){if(J.call(t,"key")){var i=Object.getOwnPropertyDescriptor(t,"key").get;if(i&&i.isReactWarning)return!1}return t.key!==void 0}function h(t,i){function g(){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)",i))}g.isReactWarning=!0,Object.defineProperty(t,"key",{get:g,configurable:!0})}function l(){var t=u(this.type);return X[t]||(X[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 c(t,i,g,x,y,E,L,D){return g=E.ref,t={$$typeof:R,type:t,key:i,props:E,_owner:y},(g!==void 0?g:null)!==null?Object.defineProperty(t,"ref",{enumerable:!1,get:l}):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:L}),Object.defineProperty(t,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:D}),Object.freeze&&(Object.freeze(t.props),Object.freeze(t)),t}function b(t,i,g,x,y,E,L,D){var V=i.children;if(V!==void 0)if(x)if(j(V)){for(x=0;x<V.length;x++)T(V[x]);Object.freeze&&Object.freeze(V)}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 T(V);if(J.call(i,"key")){V=u(t);var U=Object.keys(i).filter(function(ee){return ee!=="key"});x=0<U.length?"{key: someKey, "+U.join(": ..., ")+": ...}":"{key: someKey}",p[V+x]||(U=0<U.length?"{"+U.join(": ..., ")+": ...}":"{}",console.error(`A props object containing a "key" prop is being spread into JSX:
17
+ */var ne;function me(){return ne||(ne=1,process.env.NODE_ENV!=="production"&&(function(){function l(n){if(n==null)return null;if(typeof n=="function")return n.$$typeof===$?null:n.displayName||n.name||null;if(typeof n=="string")return n;switch(n){case j:return"Fragment";case _:return"Profiler";case v:return"StrictMode";case V:return"Suspense";case L:return"SuspenseList";case W:return"Activity"}if(typeof n=="object")switch(typeof n.tag=="number"&&console.error("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),n.$$typeof){case I:return"Portal";case d:return(n.displayName||"Context")+".Provider";case w:return(n._context.displayName||"Context")+".Consumer";case P:var u=n.render;return n=n.displayName,n||(n=u.displayName||u.name||"",n=n!==""?"ForwardRef("+n+")":"ForwardRef"),n;case Y:return u=n.displayName||null,u!==null?u:l(n.type)||"Memo";case y:u=n._payload,n=n._init;try{return l(n(u))}catch{}}return null}function e(n){return""+n}function r(n){try{e(n);var u=!1}catch{u=!0}if(u){u=console;var m=u.error,p=typeof Symbol=="function"&&Symbol.toStringTag&&n[Symbol.toStringTag]||n.constructor.name||"Object";return m.call(u,"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",p),e(n)}}function t(n){if(n===j)return"<>";if(typeof n=="object"&&n!==null&&n.$$typeof===y)return"<...>";try{var u=l(n);return u?"<"+u+">":"<...>"}catch{return"<...>"}}function s(){var n=H.A;return n===null?null:n.getOwner()}function o(){return Error("react-stack-top-frame")}function a(n){if(J.call(n,"key")){var u=Object.getOwnPropertyDescriptor(n,"key").get;if(u&&u.isReactWarning)return!1}return n.key!==void 0}function h(n,u){function m(){b||(b=!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)",u))}m.isReactWarning=!0,Object.defineProperty(n,"key",{get:m,configurable:!0})}function i(){var n=l(this.type);return R[n]||(R[n]=!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.")),n=this.props.ref,n!==void 0?n:null}function c(n,u,m,p,z,E,U,X){return m=E.ref,n={$$typeof:T,type:n,key:u,props:E,_owner:z},(m!==void 0?m:null)!==null?Object.defineProperty(n,"ref",{enumerable:!1,get:i}):Object.defineProperty(n,"ref",{enumerable:!1,value:null}),n._store={},Object.defineProperty(n._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:0}),Object.defineProperty(n,"_debugInfo",{configurable:!1,enumerable:!1,writable:!0,value:null}),Object.defineProperty(n,"_debugStack",{configurable:!1,enumerable:!1,writable:!0,value:U}),Object.defineProperty(n,"_debugTask",{configurable:!1,enumerable:!1,writable:!0,value:X}),Object.freeze&&(Object.freeze(n.props),Object.freeze(n)),n}function g(n,u,m,p,z,E,U,X){var k=u.children;if(k!==void 0)if(p)if(M(k)){for(p=0;p<k.length;p++)x(k[p]);Object.freeze&&Object.freeze(k)}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 x(k);if(J.call(u,"key")){k=l(n);var q=Object.keys(u).filter(function(ee){return ee!=="key"});p=0<q.length?"{key: someKey, "+q.join(": ..., ")+": ...}":"{key: someKey}",C[k+p]||(q=0<q.length?"{"+q.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} />`,x,V,U,V),p[V+x]=!0)}if(V=null,g!==void 0&&(n(g),V=""+g),a(i)&&(n(i.key),V=""+i.key),"key"in i){g={};for(var G in i)G!=="key"&&(g[G]=i[G])}else g=i;return V&&h(g,typeof t=="function"?t.displayName||t.name||"Unknown":t),c(t,V,E,y,s(),g,L,D)}function T(t){typeof t=="object"&&t!==null&&t.$$typeof===R&&t._store&&(t._store.validated=1)}var S=f,R=Symbol.for("react.transitional.element"),k=Symbol.for("react.portal"),M=Symbol.for("react.fragment"),v=Symbol.for("react.strict_mode"),w=Symbol.for("react.profiler"),I=Symbol.for("react.consumer"),d=Symbol.for("react.context"),P=Symbol.for("react.forward_ref"),F=Symbol.for("react.suspense"),N=Symbol.for("react.suspense_list"),Y=Symbol.for("react.memo"),_=Symbol.for("react.lazy"),q=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,j=Array.isArray,C=console.createTask?console.createTask:function(){return null};S={react_stack_bottom_frame:function(t){return t()}};var W,X={},Q=S.react_stack_bottom_frame.bind(S,o)(),m=C(r(o)),p={};Z.Fragment=M,Z.jsx=function(t,i,g,x,y){var E=1e4>H.recentlyCreatedOwnerStacks++;return b(t,i,g,!1,x,y,E?Error("react-stack-top-frame"):Q,E?C(r(t)):m)},Z.jsxs=function(t,i,g,x,y){var E=1e4>H.recentlyCreatedOwnerStacks++;return b(t,i,g,!0,x,y,E?Error("react-stack-top-frame"):Q,E?C(r(t)):m)}})()),Z}var se;function me(){return se||(se=1,process.env.NODE_ENV==="production"?K.exports=de():K.exports=he()),K.exports}var z=me();const A={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)}},O=(u,e,n)=>Math.min(n,Math.max(e,u)),ae=(u,e,n)=>{const r="touches"in u.nativeEvent,s=r?u.nativeEvent.touches[0]:u.nativeEvent,o=h=>{r&&h.cancelable&&h.preventDefault();const l="touches"in h?h.touches[0]:h;e({deltaX:l.clientX-s.clientX,deltaY:l.clientY-s.clientY})},a=()=>{r?(document.removeEventListener("touchmove",o),document.removeEventListener("touchend",a)):(document.removeEventListener("mousemove",o),document.removeEventListener("mouseup",a)),n?.()};r?(document.addEventListener("touchmove",o,{passive:!1}),document.addEventListener("touchend",a)):(document.addEventListener("mousemove",o),document.addEventListener("mouseup",a))},ge=20,ie=({contentSize:u,viewportSize:e,scrollPosition:n,onScroll:r,horizontal:s=!1,scrollBarWidth:o=12,className:a,ariaControls:h})=>{const[l,c]=f.useState(!1),b=f.useRef(null),T=e/u,S=Math.max(ge,T*e),R=u-e,k=n/R*(e-S),M=u>e;f.useEffect(()=>{b.current&&(l?b.current.style.backgroundColor="#4F4F4F":b.current.style.backgroundColor="#7F7F7F")},[l]);const v=d=>O(d/(e-S)*R,0,R),w=d=>{if(!M||"button"in d&&d.button!==0||d.ctrlKey)return;d.stopPropagation();const P=k;c(!0),ae(d,({deltaX:F,deltaY:N})=>{r?.(v(P+(s?F:N)),k)},()=>{c(!1)})},I=d=>{if(!M||"button"in d&&d.button!==0||d.ctrlKey)return;const F="touches"in d.nativeEvent?d.nativeEvent.touches[0]:d.nativeEvent,N=s?F.clientX:F.clientY,Y=d.currentTarget.getBoundingClientRect(),q=(s?N-Y.left:N-Y.top)-S/2;r?.(v(q),k),ae(d,({deltaX:$,deltaY:H})=>{r?.(v(q+(s?$:H)),k)})};return z.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:I,onTouchStart:I,role:"scrollbar",tabIndex:-1,"aria-controls":h,"aria-valuenow":n,"aria-valuemin":0,"aria-valuemax":R,"aria-orientation":s?"horizontal":"vertical",children:u>e&&z.jsx("div",{className:"group absolute",style:{[s?"width":"height"]:S,[s?"left":"top"]:k,...s?{top:0,bottom:0}:{left:0,right:0}},onMouseDown:w,onTouchStart:w,role:"slider","aria-orientation":s?"horizontal":"vertical","aria-valuenow":n,"aria-valuemin":0,"aria-valuemax":R,tabIndex:0,children:z.jsx("div",{ref:b,className:te.twMerge("absolute",s?`inset-x-0 inset-y-[1.5px] group-hover:inset-y-[-0.5px] ${l?"inset-y-[-2px]":"group-active:inset-y-[-2px]"}`:`inset-x-[1.5px] inset-y-0 group-hover:inset-x-[-0.5px] ${l?"inset-x-[-2px]":"group-active:inset-x-[-2px]"}`),style:{backgroundColor:"#7F7F7F",borderRadius:o-1,...s?{left:0,right:0,top:l?-2:1.5,bottom:l?-2:1.5}:{top:0,bottom:0,left:l?-2:1.5,right:l?-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"),l||(d.currentTarget.style.backgroundColor="#5F5F5F")},onMouseLeave:d=>{s?(d.currentTarget.style.top=l?"-2px":"1.5px",d.currentTarget.style.bottom=l?"-2px":"1.5px"):(d.currentTarget.style.left=l?"-2px":"1.5px",d.currentTarget.style.right=l?"-2px":"1.5px"),l||(d.currentTarget.style.backgroundColor="#7F7F7F")}})})})},le=f.forwardRef(({children:u,contentSize:e,viewportSize:n,scrollBarWidth:r=12,onScroll:s,className:o,style:a,background:h},l)=>{const c=f.useRef(0),[b,T]=f.useReducer(w=>w+1,0),S=f.useRef(null);A.debug("[ScrollPane] ScrollPane rendered",{contentSize:e,viewportSize:n,scrollBarWidth:r,className:o,style:a});const R=f.useMemo(()=>e>n,[e,n]),k=f.useCallback(w=>{const I=e>n,d=c.current;if(A.debug("[ScrollPane] scrollTo called",{newPosition:w,contentSize:e,viewportSize:n,currentIsScrollable:I,prevPosition:d}),!I){c.current!==0&&(c.current=0,s?.(0,d));return}const P=typeof w=="function"?w(c.current):w,F=O(P,0,e-n);c.current!==F&&(c.current=F,s?.(F,d))},[s,e,n]);f.useLayoutEffect(()=>{if(R){A.debug("[ScrollPane] Adjusting scroll position due to content or viewport size change",{contentSize:e,viewportSize:n,scrollPosition:c.current});const w=O(e-n,0,e);c.current>w&&k(w)}else k(0)},[R,k,e,n]),f.useEffect(()=>{const w=d=>{if(!R)return;d.preventDefault();let P=d.deltaY;d.deltaMode===1?P*=16:d.deltaMode===2&&(P*=n),A.debug("[ScrollPane] wheel event",{deltaY:P,scrollPosition:c.current}),k(F=>F+P)},I=S.current;return I&&I.addEventListener("wheel",w,{passive:!1}),()=>{I&&I.removeEventListener("wheel",w)}},[R,k,n]),f.useImperativeHandle(l,()=>({scrollTo:k,getScrollPosition:()=>c.current,getContentSize:()=>e,getViewportSize:()=>n}),[k,e,n]);const M=f.useId();return f.useMemo(()=>z.jsxs("div",{ref:S,className:te.twMerge("flex",o),style:a,children:[z.jsxs("div",{className:"relative h-full flex-1 overflow-hidden",style:{height:n},id:M,children:[h,u(c.current)]}),R&&z.jsx(ie,{contentSize:e,viewportSize:n,scrollPosition:c.current,onScroll:k,scrollBarWidth:r,ariaControls:M})]}),[u,e,n,r,o,a,R,k,M,h])});class ue{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 o=r?.sampleRange??{from:0,to:Math.min(99,this.size-1)},{mode:a,materializedValues:h}=this._calculateMode(o.from,o.to);if(this.baseValue=a,r?.materialize)for(let l=0;l<h.length;l++){const c=h[l],b=o.from+l;if(b>=this.size)break;const T=c-this.baseValue;this.deltas.set(b,T),this._updateTree(b,T)}}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 c=e;c<=n&&!(c>=this.size);c++)r.push(this.valueFn(c));const s=[...r];if(r.length===0)return{mode:0,materializedValues:[]};r.sort((c,b)=>c-b);const o=Math.floor(r.length/2);let a;r.length%2===0?a=Math.floor((r[o-1]+r[o])/2):a=r[o];const h=new Map;let l=0;for(const c of r){const b=(h.get(c)??0)+1;h.set(c,b),b>l&&(l=b)}if(l>1){const c=[];for(const[T,S]of h.entries())S===l&&c.push(T);const b=c.reduce((T,S)=>T+S,0);a=Math.floor(b/c.length)}return{mode:a,materializedValues:s}}update(e,n){return this.updates([{index:e,value:n}])}updates(e){const n=e.map(({index:r,value:s})=>{if(r<0||r>=this.size)throw new Error(`Index ${r} out of bounds`);if(s<0)throw new Error("Value cannot be negative.");const o=this.deltas.has(r)?(this.deltas.get(r)??0)+this.baseValue:this.baseValue,a=s-o;return{index:r,change:a}}).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 s=this.deltas.get(n)??0;this.deltas.set(n,s+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,o=this.valueFn(e)-this.baseValue;if(o!==r&&(this.deltas.set(e,o),n)){const a=o-r;this._updateTree(e,a)}}}prefixSum(e,n){if(e<0)return{cumulative:0,total:this.total,currentValue:0,safeIndex:0};const r=O(e,0,this.size-1),s=n?.materializeOption;if(s?.materialize&&this.valueFn){if(s.ranges)for(const l of s.ranges){const c=l.from,b=Math.min(l.to,this.size-1);for(let T=c;T<=b;T++)this._materialize(T)}this._materialize(r)}let o=0,a=r+1;for(;a>0;){const l=this.tree.get(a)??0;o+=l,a-=a&-a}const h=s?.materialize?this.get(r):(this.deltas.get(r)||0)+this.baseValue;return{cumulative:o+this.baseValue*(r+1),total:this.total,currentValue:h,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 s of r.ranges){const o=s.from,a=Math.min(s.to,this.size-1);for(let h=o;h<=a;h++)this._materialize(h)}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 s=r.from,o=Math.min(r.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 r=this.baseValue*this.size;for(const s of this.deltas.values())r+=s;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 s=this.valueFn;this.reset(this.size,o=>s(o),{materialize:!0});return}const n=new Map;let r=this.baseValue*this.size;for(const[s,o]of this.deltas.entries()){if(r+=o,o===0)continue;let a=s+1;for(;a<=this.size;)n.set(a,(n.get(a)??0)+o),a+=a&-a}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,s=this.size-1,o=-1,a,h=this.total;for(;r<=s;){const l=Math.floor((r+s)/2);a=this.prefixSum(l,n),h=a.total,a.cumulative>=e?(o=l,s=l-1):r=l+1}return{index:o,total:h,cumulative:a?.cumulative,currentValue:a?.currentValue,safeIndex:a?.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,s=this.size-1,o=-1,a,h=this.total;for(;r<=s;){const l=Math.floor((r+s)/2);a=this.prefixSum(l,n),h=a.total,a.cumulative<=e?(o=l,r=l+1):s=l-1}return{index:o,total:h,cumulative:a?.cumulative,currentValue:a?.currentValue,safeIndex:a?.safeIndex}}}const ce=(u,e,n)=>{const r=Math.max(0,u),s=f.useRef(null),o=f.useMemo(()=>new ue(r,e,n),[r,e,n]);return Object.is(s.current,o)||console.warn("[useFenwickMapTree] instance changed"),s.current=o,o};function be({itemCount:u,getItem:e,getItemHeight:n,viewportSize:r,overscanCount:s=5,className:o,onScroll:a,onRangeChange:h,children:l,background:c,initialScrollIndex:b,initialScrollOffset:T},S){const R=f.useRef(null),k=f.useRef(!1);f.useEffect(()=>(k.current=!0,()=>{k.current=!1}),[]);const M=f.useRef({size:u,valueOrFn:n,options:{sampleRange:{from:0,to:100}}}),v=ce(M.current.size,M.current.valueOrFn,M.current.options),[w]=f.useState(()=>{let m=0,p=0;if(typeof b=="number"){const t=O(b,0,u-1),i=O(t-s*2,0,u-1),g=O(t+s*2,0,u-1),x=b>0?{materializeOption:{materialize:!0,ranges:[{from:i,to:g}]}}:void 0,{cumulative:y,total:E,currentValue:L}=v.prefixSum(b,x);m=y-L,p=E??v.getTotal()}else typeof T=="number"&&(m=T),p=v.getTotal();return{position:m,total:p}}),[I,d]=f.useState(w.position),[P,F]=f.useState(w.total),[N,Y]=f.useState(w.position),[_,q]=f.useState(u);f.useLayoutEffect(()=>{v.setValueFn(n),_!==u&&(v.changeSize(u),q(u));const m=v.getTotal();P!==m&&F(m)},[v,_,u,P,n]),f.useLayoutEffect(()=>{N!==null&&R.current&&(A.debug("[VirtualScroll] Scrolling to position:",N),R.current.scrollTo(N),Y(null))},[N]);const $=f.useCallback(m=>{if(R.current){A.debug("[VirtualScroll] Scrolling to index:",m);const p=O(m,0,_-1),t=O(p-s*2,0,_-1),i=O(p+s*2,0,_-1),{cumulative:g,total:x,currentValue:y}=v.prefixSum(p,{materializeOption:{materialize:!0,ranges:[{from:t,to:i}]}});A.debug("[VirtualScroll] Scrolling to index:",m,"Offset:",g,"Total height:",x,"Current value:",y,"safeIndex:",p,"safeIndexFrom:",t,"safeIndexTo:",i),x&&(F(x),Y(g-y)),A.debug("[VirtualScroll] Setting scroll position to:",g-y)}},[v,s,_]),H=f.useCallback(m=>{if(R.current){const p=v.getTotal(),t=O(Math.floor(m),0,p),i=v.findIndexAtOrAfter(t,{materializeOption:{materialize:!1}}).index;$(i)}},[v,$]),J=f.useCallback((m,p)=>{A.debug("[VirtualScroll] Scroll position changed:",m),d(m);const t=v.getTotal();a?.(m,t)},[v,a]),{renderingStartIndex:j,renderingEndIndex:C,visibleStartIndex:W,visibleEndIndex:X}=f.useMemo(()=>{if(_===0)return{renderingStartIndex:0,renderingEndIndex:0,visibleStartIndex:0,visibleEndIndex:0};const{index:m,cumulative:p,currentValue:t}=v.findIndexAtOrAfter(I,{materializeOption:{materialize:!1}});let i=0;m===-1?i=0:(p??0)<I+(t??0)?i=1:i=0;const g=m===-1?0:m+i,x=O(g-s,0,_-1);let y=0,E=m===-1?0:m+i;for(;E<_&&y<r;){const D=n(E);y+=D,E++}E-=1;const L=O(E+s,0,_-1);return A.debug("[VirtualScroll] Calculated rendering range:",{renderingStartIndex:x,renderingEndIndex:L,visibleStartIndex:g,visibleEndIndex:E,scrollPosition:I,renderingContentSize:v.getTotal(),overscanCount:s,viewportSize:r}),{renderingStartIndex:x,renderingEndIndex:L,visibleStartIndex:g,visibleEndIndex:E}},[I,s,r,n,v,_]);f.useEffect(()=>{const m=R.current?.getScrollPosition()??0;A.debug("[VirtualScroll] Range change effect triggered",{renderingStartIndex:j,renderingEndIndex:C,visibleStartIndex:W,visibleEndIndex:X,scrollPosition:I,contentSize:P,scrollPaneScrollPosition:m}),h?.(j,C,W,X,I,P)},[j,C,W,X,h,I,P]),f.useEffect(()=>{if(_===0)return;const m=[];for(let p=j;p<=C;p++){const t=n(p);v.get(p)!==t&&m.push({index:p,value:t})}if(m.length>0){const p=v.updates(m);p&&F(t=>p!==t&&k.current?(A.debug("[VirtualScroll] Updated heights for items",m,"New total height:",p),p):t)}},[j,C,n,v,_]);const Q=f.useCallback(m=>{if(A.debug("[VirtualScroll] Rendering visible items",{currentScrollPosition:m,renderingStartIndex:j,renderingEndIndex:C,fenwickSize:_,viewportSize:r}),_===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 p=O(j,0,_-1),{cumulative:t,currentValue:i}=v.prefixSum(p,{materializeOption:{materialize:!1}}),g=t-i,x=[];for(let E=j;E<=C;E++)x.push(e(E));const y=P<r?0:g-m;return A.debug("[VirtualScroll] Rendering items",{visibleItems:x,containerTop:y}),z.jsx("div",{className:"absolute w-full",style:{top:y},children:x.map((E,L)=>{const D=j+L,V=O(D,0,_-1),{cumulative:U,currentValue:G}=v.prefixSum(V,{materializeOption:{materialize:!1}}),ee=U-G;return z.jsx("div",{"data-index":D,style:{position:"absolute",top:ee-g,width:"100%"},children:l(E,D)},D)})})},[e,l,P,r,j,C,v,_]);return f.useImperativeHandle(S,()=>({getScrollPosition:()=>R.current?.getScrollPosition()??-1,getContentSize:()=>R.current?.getContentSize()??-1,getViewportSize:()=>R.current?.getViewportSize()??-1,scrollTo:m=>H(m),scrollToIndex:m=>$(m),getFenwickTreeTotalHeight:()=>v.getTotal(),getFenwickSize:()=>v.getSize()}),[$,v,H]),z.jsx(le,{ref:R,contentSize:P,viewportSize:r,className:o,onScroll:J,background:c,children:Q})}const ve=f.forwardRef(be);class pe{key;value;prev=null;next=null;constructor(e,n){this.key=e,this.value=n}}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(u){const e=f.useRef(new Map),n=f.useRef(new oe);f.useEffect(()=>{for(;e.current.size>u;){const c=n.current.removeHead();if(c)e.current.delete(c.key);else break}},[u]);const r=f.useCallback(c=>{const b=e.current.get(c);if(b)return n.current.moveToTail(b),b.value},[]),s=f.useCallback((c,b)=>{if(u<=0)return;let T=e.current.get(c);if(T)T.value=b,n.current.moveToTail(T);else{if(e.current.size>=u){const S=n.current.removeHead();S&&e.current.delete(S.key)}T=new pe(c,b),e.current.set(c,T),n.current.addToTail(T)}},[u]),o=f.useCallback(c=>e.current.has(c),[]),a=f.useCallback(()=>{e.current.clear(),n.current=new oe},[]),[h,l]=f.useState(()=>({get:r,set:s,has:o,clear:a}));return f.useEffect(()=>l({get:r,set:s,has:o,clear:a}),[r,s,o,a]),h}const xe=1e4,Te=()=>{const{get:u,set:e,has:n,clear:r}=fe(xe);return{get:u,set:e,has:n,clear:r}};exports.FenwickMapTree=ue;exports.ScrollBar=ie;exports.ScrollPane=le;exports.VirtualScroll=ve;exports.minmax=O;exports.useFenwickMapTree=ce;exports.useHeightCache=Te;exports.useLruCache=fe;
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;
23
23
  //# sourceMappingURL=index.cjs.map