import{d as E,f as D,r as V,e as c,u as i,w as I,o as B,n as k,k as a,U as S,a2 as M,ad as P,af as f,G as y,a4 as _,a5 as C}from"./vue-vendor-CxLCUzY4.js";import{x as L,a3 as U,_ as R,w as q}from"./index-B_2CoVdl.js";import{W as G}from"./antd-vue-vendor-CDWW6V_M.js";import{P as j}from"./index-DaObvZxT.js";import"./vxe-table-vendor-B5h3MVdD.js";import"./useContentHeight-BWLGvKEC.js";import"./useWindowSizeFn-C3WExEpc.js";import"./useContentViewHeight-DlpfApuB.js";import"./usePageContext-HMYqek-Q.js";import"./injectionKey-DPVn4AgL.js";const z={height:[Number,String],maxHeight:[Number,String],maxWidth:[Number,String],minHeight:[Number,String],minWidth:[Number,String],width:[Number,String],bench:{type:[Number,String],default:0},itemHeight:{type:[Number,String],required:!0},items:{type:Array,default:()=>[]}},w="virtual-scroll";function o(t,n="px"){if(!(t==null||t===""))return isNaN(+t)?String(t):`${Number(t)}${n}`}const J=E({name:"VirtualScroll",props:z,setup(t,{slots:n}){const u=D(null),s=V({first:0,last:0,scrollTop:0}),p=c(()=>parseInt(t.bench,10)),m=c(()=>parseInt(t.itemHeight,10)),d=c(()=>Math.max(0,s.first-i(p))),g=c(()=>Math.min((t.items||[]).length,s.last+i(p))),v=c(()=>({height:o((t.items||[]).length*i(m))})),h=c(()=>{const e={},r=o(t.height),l=o(t.minHeight),N=o(t.minWidth),b=o(t.maxHeight),F=o(t.maxWidth),W=o(t.width);return r&&(e.height=r),l&&(e.minHeight=l),N&&(e.minWidth=N),b&&(e.maxHeight=b),F&&(e.maxWidth=F),W&&(e.width=W),e});I([()=>t.itemHeight,()=>t.height],()=>{x()});function H(e){const r=i(u);if(!r)return 0;const l=parseInt(t.height||0,10)||r.clientHeight;return e+Math.ceil(l/i(m))}function T(){return Math.floor(s.scrollTop/i(m))}function x(){const e=i(u);e&&(s.scrollTop=e.scrollTop,s.first=T(),s.last=H(s.first))}function $(){const{items:e=[]}=t;return e.slice(i(d),i(g)).map(A)}function A(e,r){r+=i(d);const l=o(r*i(m));return a("div",{class:`${w}__item`,style:{top:l},key:r},[U(n,"default",{index:r,item:e})])}return B(()=>{s.last=H(0),k(()=>{const e=i(u);e&&L({el:e,name:"scroll",listener:x,wait:0})})}),()=>a("div",{class:w,style:i(h),ref:u},[a("div",{class:`${w}__container`,style:i(v)},[$()])])}}),K=R(J,[["__scopeId","data-v-f9d5e69c"]]),O=q(K),Q=(()=>{const t=[];for(let n=1;n<2e4;n++)t.push({title:"列表项"+n});return t})(),X=E({components:{VScroll:O,Divider:G,PageWrapper:j},setup(){return{data:Q}}}),Y={class:"virtual-scroll-demo-wrap"},Z={class:"virtual-scroll-demo__item"},tt={class:"virtual-scroll-demo-wrap"},et={class:"virtual-scroll-demo__item"};function it(t,n,u,s,p,m){const d=S("Divider"),g=S("VScroll"),v=S("PageWrapper");return M(),P(v,{class:"virtual-scroll-demo"},{default:f(()=>[a(d,null,{default:f(()=>n[0]||(n[0]=[y("基础滚动示例")])),_:1}),_("div",Y,[a(g,{itemHeight:41,items:t.data,height:300,width:300},{default:f(({item:h})=>[_("div",Z,C(h.title),1)]),_:1},8,["items"])]),a(d,null,{default:f(()=>n[1]||(n[1]=[y("即使不可见，也预先加载50条数据，防止空白")])),_:1}),_("div",tt,[a(g,{itemHeight:41,items:t.data,height:300,width:300,bench:50},{default:f(({item:h})=>[_("div",et,C(h.title),1)]),_:1},8,["items"])])]),_:1})}const ht=R(X,[["render",it],["__scopeId","data-v-7316c0b2"]]);export{ht as default};
