import{g as G,p as N,Z as J,J as A,b as X,d as V,ag as Z,ad as re,c as $,a8 as oe,I as T,a0 as K,H as W,r as D,a7 as j,d3 as ue,cG as ce,a6 as E,O as ie,M as de,cd as ve,a1 as fe,t as me,$ as he,x as ge,y as _,n as pe,e as ye,a2 as Se,a3 as we,N as Ve}from"./index-C-Ivu3jU.js";const Te=N({renderless:Boolean,...$()},"VVirtualScrollItem"),Ie=G()({name:"VVirtualScrollItem",inheritAttrs:!1,props:Te(),emits:{"update:height":l=>!0},setup(l,a){let{attrs:d,emit:s,slots:n}=a;const{resizeRef:r,contentRect:c}=J(void 0,"border");A(()=>c.value?.height,g=>{g!=null&&s("update:height",g)}),X(()=>l.renderless?V(Z,null,[n.default?.({itemRef:r})]):V("div",re({ref:r,class:["v-virtual-scroll__item",l.class],style:l.style},d),[n.default?.()]))}}),Re=-1,be=1,H=100,xe=N({itemHeight:{type:[Number,String],default:null},itemKey:{type:[String,Array,Function],default:null},height:[Number,String]},"virtual");function Oe(l,a){const d=oe(),s=T(0);K(()=>{s.value=parseFloat(l.itemHeight||0)});const n=T(0),r=T(Math.ceil((parseInt(l.height)||d.height.value)/(s.value||16))||1),c=T(0),g=T(0),u=W(),m=W();let I=0;const{resizeRef:F,contentRect:x}=J();K(()=>{F.value=u.value});const y=D(()=>u.value===document.documentElement?d.height.value:x.value?.height||parseInt(l.height)||0),M=D(()=>!!(u.value&&m.value&&y.value&&s.value));let h=Array.from({length:a.value.length}),i=Array.from({length:a.value.length});const v=T(0);let O=-1;function Q(e){return h[e]||s.value}const P=ue(()=>{const e=performance.now();i[0]=0;const t=a.value.length;for(let o=1;o<=t;o++)i[o]=(i[o-1]||0)+Q(o-1);v.value=Math.max(v.value,performance.now()-e)},v),Y=A(M,e=>{e&&(Y(),I=m.value.offsetTop,P.immediate(),S(),~O&&ie(()=>{de&&window.requestAnimationFrame(()=>{L(O),O=-1})}))});j(()=>{P.clear()});function ee(e,t){const o=h[e],f=s.value;s.value=f?Math.min(s.value,t):t,(o!==t||f!==s.value)&&(h[e]=t,P())}function p(e){e=E(e,0,a.value.length);const t=Math.floor(e),o=e%1,f=t+1,b=i[t]||0,w=i[f]||b;return b+(w-b)*o}function C(e){return Pe(i,e)}let k=0,R=0,z=0;A(y,(e,t)=>{t&&(S(),e<t&&requestAnimationFrame(()=>{R=0,S()}))});let B=-1;function te(){if(!u.value||!m.value)return;const e=u.value.scrollTop,t=performance.now();t-z>500?(R=Math.sign(e-k),I=m.value.offsetTop):R=e-k,k=e,z=t,window.clearTimeout(B),B=window.setTimeout(U,500),S()}function U(){!u.value||!m.value||(R=0,z=0,window.clearTimeout(B),S())}let q=-1;function S(){cancelAnimationFrame(q),q=requestAnimationFrame(le)}function le(){if(!u.value||!y.value||!s.value)return;const e=k-I,t=Math.sign(R),o=Math.max(0,e-H),f=E(C(o),0,a.value.length),b=e+y.value+H,w=E(C(b)+1,f+1,a.value.length);if((t!==Re||f<n.value)&&(t!==be||w>r.value)){const ne=p(n.value)-p(f),se=p(w)-p(r.value);Math.max(ne,se)>H?(n.value=f,r.value=w):(f<=0&&(n.value=f),w>=a.value.length&&(r.value=w))}c.value=p(n.value),g.value=p(a.value.length)-p(r.value)}function L(e){const t=p(e);!u.value||e&&!t?O=e:u.value.scrollTop=t}const ae=D(()=>a.value.slice(n.value,r.value).map((e,t)=>{const o=t+n.value;return{raw:e,index:o,key:ce(e,l.itemKey,o)}}));return A(a,()=>{h=Array.from({length:a.value.length}),i=Array.from({length:a.value.length}),P.immediate(),S()},{deep:1}),{calculateVisibleItems:S,containerRef:u,markerRef:m,computedItems:ae,paddingTop:c,paddingBottom:g,scrollToIndex:L,handleScroll:te,handleScrollend:U,handleItemResize:ee}}function Pe(l,a){let d=l.length-1,s=0,n=0,r=null,c=-1;if(l[d]<a)return d;for(;s<=d;)if(n=s+d>>1,r=l[n],r>a)d=n-1;else if(r<a)c=n,s=n+1;else return r===a?n:s;return c}const ke=N({items:{type:Array,default:()=>[]},renderless:Boolean,...xe(),...$(),...Se()},"VVirtualScroll"),Fe=G()({name:"VVirtualScroll",props:ke(),setup(l,a){let{slots:d}=a;const s=ve("VVirtualScroll"),{dimensionStyles:n}=fe(l),{calculateVisibleItems:r,containerRef:c,markerRef:g,handleScroll:u,handleScrollend:m,handleItemResize:I,scrollToIndex:F,paddingTop:x,paddingBottom:y,computedItems:M}=Oe(l,me(()=>l.items));return he(()=>l.renderless,()=>{function h(){const v=(arguments.length>0&&arguments[0]!==void 0?arguments[0]:!1)?"addEventListener":"removeEventListener";c.value===document.documentElement?(document[v]("scroll",u,{passive:!0}),document[v]("scrollend",m)):(c.value?.[v]("scroll",u,{passive:!0}),c.value?.[v]("scrollend",m))}we(()=>{c.value=Ve(s.vnode.el,!0),h(!0)}),j(h)}),X(()=>{const h=M.value.map(i=>ge(Ie,{key:i.key,renderless:l.renderless,"onUpdate:height":v=>I(i.index,v)},{default:v=>d.default?.({item:i.raw,index:i.index,...v})}));return l.renderless?V(Z,null,[V("div",{ref:g,class:"v-virtual-scroll__spacer",style:{paddingTop:_(x.value)}},null),h,V("div",{class:"v-virtual-scroll__spacer",style:{paddingBottom:_(y.value)}},null)]):V("div",{ref:c,class:ye(["v-virtual-scroll",l.class]),onScrollPassive:u,onScrollend:m,style:pe([n.value,l.style])},[V("div",{ref:g,class:"v-virtual-scroll__container",style:{paddingTop:_(x.value),paddingBottom:_(y.value)}},[h])])}),{calculateVisibleItems:r,scrollToIndex:F}}});export{Fe as V};
