import{cl as I,au as L,bB as N,ay as h,cm as w,cn as A}from"./index.8d733f79.js";import{t as E}from"./throttle.04d7163a.js";const l="ElInfiniteScroll",D=50,O=200,_=0,C={delay:{type:Number,default:O},distance:{type:Number,default:_},disabled:{type:Boolean,default:!1},immediate:{type:Boolean,default:!0}},m=(t,n)=>Object.entries(C).reduce((o,[e,r])=>{var u,i;const{type:f,default:s}=r,a=t.getAttribute(`infinite-scroll-${e}`);let c=(i=(u=n[a])!=null?u:a)!=null?i:s;return c=c==="false"?!1:c,c=f(c),o[e]=Number.isNaN(c)?s:c,o},{}),S=t=>{const{observer:n}=t[l];n&&(n.disconnect(),delete t[l].observer)},F=(t,n)=>{const{container:o,containerEl:e,instance:r,observer:u,lastScrollTop:i}=t[l],{disabled:f,distance:s}=m(t,r),{clientHeight:a,scrollHeight:c,scrollTop:d}=e,g=d-i;if(t[l].lastScrollTop=d,u||f||g<0)return;let b=!1;if(o===t)b=c-(a+d)<=s;else{const{clientTop:T,scrollHeight:y}=t,H=A(t,e);b=d+a>=H+T+y-s}b&&n.call(r)};function p(t,n){const{containerEl:o,instance:e}=t[l],{disabled:r}=m(t,e);r||o.clientHeight===0||(o.scrollHeight<=o.clientHeight?n.call(e):S(t))}const B={async mounted(t,n){const{instance:o,value:e}=n;I({scope:l,from:"the directive v-infinite-scroll",replacement:"the el-scrollbar infinite scroll",version:"3.0.0",ref:"https://element-plus.org/en-US/component/scrollbar#infinite-scroll"},!0),L(e)||N(l,"'v-infinite-scroll' binding value must be a function"),await h();const{delay:r,immediate:u}=m(t,o),i=w(t,!0),f=i===window?document.documentElement:i,s=E(F.bind(null,t,e),r);if(!!i){if(t[l]={instance:o,container:i,containerEl:f,delay:r,cb:e,onScroll:s,lastScrollTop:f.scrollTop},u){const a=new MutationObserver(E(p.bind(null,t,e),D));t[l].observer=a,a.observe(t,{childList:!0,subtree:!0}),p(t,e)}i.addEventListener("scroll",s)}},unmounted(t){if(!t[l])return;const{container:n,onScroll:o}=t[l];n==null||n.removeEventListener("scroll",o),S(t)},async updated(t){if(!t[l])await h();else{const{containerEl:n,cb:o,observer:e}=t[l];n.clientHeight&&e&&p(t,o)}}},v=B;v.install=t=>{t.directive("InfiniteScroll",v)};const k=v;export{k as E};
