You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
2 lines
1.8 KiB
2 lines
1.8 KiB
import{d as W,r as C,q as E,f as l,u as n,O as I,P as M,J as p,ax as $,b as u,aw as L,aT as V}from"./index-f4658ae7.js";const k={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:()=>[]}},f="virtual-scroll";function s(t,h="px"){if(!(t==null||t===""))return isNaN(+t)?String(t):`${Number(t)}${h}`}const q=W({name:"VirtualScroll",props:k,setup(t,{slots:h}){const c=C(null),r=E({first:0,last:0,scrollTop:0}),m=l(()=>parseInt(t.bench,10)),o=l(()=>parseInt(t.itemHeight,10)),g=l(()=>Math.max(0,r.first-n(m))),H=l(()=>Math.min((t.items||[]).length,r.last+n(m))),N=l(()=>({height:s((t.items||[]).length*n(o))})),v=l(()=>{const e={},i=s(t.height),a=s(t.minHeight),S=s(t.minWidth),b=s(t.maxHeight),x=s(t.maxWidth),y=s(t.width);return i&&(e.height=i),a&&(e.minHeight=a),S&&(e.minWidth=S),b&&(e.maxHeight=b),x&&(e.maxWidth=x),y&&(e.width=y),e});I([()=>t.itemHeight,()=>t.height],()=>{_()});function d(e){const i=n(c);if(!i)return 0;const a=parseInt(t.height||0,10)||i.clientHeight;return e+Math.ceil(a/n(o))}function w(){return Math.floor(r.scrollTop/n(o))}function _(){const e=n(c);e&&(r.scrollTop=e.scrollTop,r.first=w(),r.last=d(r.first))}function R(){const{items:e=[]}=t;return e.slice(n(g),n(H)).map(T)}function T(e,i){i+=n(g);const a=s(i*n(o));return u("div",{class:`${f}__item`,style:{top:a},key:i},[L(h,"default",{index:i,item:e})])}return M(()=>{r.last=d(0),p(()=>{const e=n(c);e&&$({el:e,name:"scroll",listener:_,wait:0})})}),()=>u("div",{class:f,style:n(v),ref:c},[u("div",{class:`${f}__container`,style:n(N)},[R()])])}});const A=V(q,[["__scopeId","data-v-745f3fb0"]]);export{A as default};
|