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