import{a as O,v as D,i as E,O as j,P as W}from"./VImg-7a057c50.js";import{p as R,g as H,w as U,j as h,F as A,k as q,s as b,c as S,r as G,a_ as J,e as K,aU as Q,aL as k,ao as X,t as Y,a$ as Z,a as x,o as ee,b0 as le}from"./index-e5db0b73.js";import{p as te}from"./VMenu-d9833a31.js";const ae=R({renderless:Boolean,...O()},"VVirtualScrollItem"),ne=H()({name:"VVirtualScrollItem",inheritAttrs:!1,props:ae(),emits:{"update:height":t=>!0},setup(t,a){let{attrs:d,emit:u,slots:c}=a;const{resizeRef:n,contentRect:s}=D(void 0,"border");U(()=>{var r;return(r=s.value)==null?void 0:r.height},r=>{r!=null&&u("update:height",r)}),E(()=>{var r,v;return t.renderless?h(A,null,[(r=c.default)==null?void 0:r.call(c,{itemRef:n})]):h("div",q({ref:n,class:["v-virtual-scroll__item",t.class],style:t.style},d),[(v=c.default)==null?void 0:v.call(c)])})}}),z=-1,B=1,se=R({itemHeight:{type:[Number,String],default:48}},"virtual");function re(t,a,d){const u=b(0),c=b(t.itemHeight),n=S({get:()=>parseInt(c.value??0,10),set(e){c.value=e}}),s=G(),{resizeRef:r,contentRect:v}=D();J(()=>{r.value=s.value});const I=K(),f=new Map;let p=Array.from({length:a.value.length});const o=S(()=>{const e=(!v.value||s.value===document.documentElement?I.height.value:v.value.height)-((d==null?void 0:d.value)??0);return Math.ceil(e/n.value*1.7+1)});function g(e,l){n.value=Math.max(n.value,l),p[e]=l,f.set(a.value[e],l)}function m(e){return p.slice(0,e).reduce((l,i)=>l+(i||n.value),0)}function y(e){const l=a.value.length;let i=0,V=0;for(;V<e&&i<l;)V+=p[i++]||n.value;return i-1}let T=0;function C(){if(!s.value||!v.value)return;const e=v.value.height-56,l=s.value.scrollTop,i=l<T?z:B,V=y(l+e/2),_=Math.round(o.value/3),w=V-_,M=u.value+_*2-1;i===z&&V<=M?u.value=k(w,0,a.value.length):i===B&&V>=M&&(u.value=k(w,0,a.value.length-o.value)),T=l}function F(e){if(!s.value)return;const l=m(e);s.value.scrollTop=l}const P=S(()=>Math.min(a.value.length,u.value+o.value)),L=S(()=>a.value.slice(u.value,P.value).map((e,l)=>({raw:e,index:l+u.value}))),N=S(()=>m(u.value)),$=S(()=>m(a.value.length)-m(P.value));return U(()=>a.value.length,()=>{p=Q(a.value.length).map(()=>n.value),f.forEach((e,l)=>{const i=a.value.indexOf(l);i===-1?f.delete(l):p[i]=e})}),{containerRef:s,computedItems:L,itemHeight:n,paddingTop:N,paddingBottom:$,scrollToIndex:F,handleScroll:C,handleItemResize:g}}const oe=R({items:{type:Array,default:()=>[]},renderless:Boolean,...se(),...O(),...j()},"VVirtualScroll"),de=H()({name:"VVirtualScroll",props:oe(),setup(t,a){let{slots:d}=a;const u=X("VVirtualScroll"),{dimensionStyles:c}=W(t),{containerRef:n,handleScroll:s,handleItemResize:r,scrollToIndex:v,paddingTop:I,paddingBottom:f,computedItems:p}=re(t,Y(t,"items"));return Z(()=>t.renderless,()=>{ee(()=>{var o;n.value=te(u.vnode.el,!0),(o=n.value)==null||o.addEventListener("scroll",s)}),le(()=>{var o;(o=n.value)==null||o.removeEventListener("scroll",s)})}),E(()=>{const o=p.value.map(g=>h(ne,{key:g.index,renderless:t.renderless,"onUpdate:height":m=>r(g.index,m)},{default:m=>{var y;return(y=d.default)==null?void 0:y.call(d,{item:g.raw,index:g.index,...m})}}));return t.renderless?h(A,null,[h("div",{class:"v-virtual-scroll__spacer",style:{paddingTop:x(I.value)}},null),o,h("div",{class:"v-virtual-scroll__spacer",style:{paddingBottom:x(f.value)}},null)]):h("div",{ref:n,class:["v-virtual-scroll",t.class],onScroll:s,style:[c.value,t.style]},[h("div",{class:"v-virtual-scroll__container",style:{paddingTop:x(I.value),paddingBottom:x(f.value)}},[o])])}),{scrollToIndex:v}}});export{de as V};
