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