import{r as f,c as I}from"./vendor-react-BUCujlKS.js";import{V as R,e as b,o as E,a as w}from"./vendor-tanstack-virtual-core-Dubg10g5.js";const x=typeof document<"u"?f.useLayoutEffect:f.useEffect;function V({useFlushSync:p=!0,directDomUpdates:m=!1,directDomUpdatesMode:h="transform",...g}){const z=f.useReducer(e=>e+1,0)[1],a=f.useRef({enabled:m,mode:h,container:null,lastSize:null,lastPositions:new WeakMap,prevRange:null});a.current.enabled=m,a.current.mode=h;const S=e=>{const t=a.current;if(!t.enabled||!t.container)return;const n=e.getTotalSize();if(n!==t.lastSize){t.lastSize=n;const d=e.options.horizontal?"width":"height";t.container.style[d]=`${n}px`}const s=!!e.options.horizontal,r=t.mode==="transform",o=s?"left":"top",l=e.options.scrollMargin,y=e.getVirtualItems();for(const d of y){const c=d.start-l,u=e.elementsCache.get(d.key);u&&t.lastPositions.get(u)!==c&&(t.lastPositions.set(u,c),r?u.style.transform=s?`translate3d(${c}px, 0, 0)`:`translate3d(0, ${c}px, 0)`:u.style[o]=`${c}px`)}},v={...g,onChange:(e,t)=>{var n;const s=a.current;let r=!0;if(s.enabled){S(e);const o=e.range,l=s.prevRange;r=!l||l.isScrolling!==e.isScrolling||l.startIndex!==o?.startIndex||l.endIndex!==o?.endIndex,r&&(s.prevRange=o?{startIndex:o.startIndex,endIndex:o.endIndex,isScrolling:e.isScrolling}:null)}r&&(p&&t?I.flushSync(z):z()),(n=g.onChange)==null||n.call(g,e,t)}},[i]=f.useState(()=>{const e=new R(v);return Object.assign(e,{containerRef:t=>{const n=a.current;if(n.container=t,n.lastSize=null,t&&n.enabled){const s=e.getTotalSize();n.lastSize=s;const r=e.options.horizontal?"width":"height";t.style[r]=`${s}px`}}})});return i.setOptions(v),x(()=>i._didMount(),[]),x(()=>i._willUpdate()),x(()=>{S(i)}),i}function T(p){return V({observeElementRect:w,observeElementOffset:E,scrollToFn:b,...p})}export{T as u};
