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