index.0f7f0657.js 2.1 KB

1
  1. import{U as H,V as I,W as L,X as m,Y as N}from"./index.f884e450.js";import{t as v}from"./throttle.88168f2d.js";const k=(t,n)=>{if(!H||!t||!n)return!1;const e=t.getBoundingClientRect();let o;return n instanceof Element?o=n.getBoundingClientRect():o={top:0,right:window.innerWidth,bottom:window.innerHeight,left:0},e.top<o.bottom&&e.bottom>o.top&&e.right>o.left&&e.left<o.right},E=t=>{let n=0,e=t;for(;e;)n+=e.offsetTop,e=e.offsetParent;return n},O=(t,n)=>Math.abs(E(t)-E(n)),i="ElInfiniteScroll",A=50,_=200,D=0,R={delay:{type:Number,default:_},distance:{type:Number,default:D},disabled:{type:Boolean,default:!1},immediate:{type:Boolean,default:!0}},h=(t,n)=>Object.entries(R).reduce((e,[o,l])=>{var f,s;const{type:u,default:c}=l,a=t.getAttribute(`infinite-scroll-${o}`);let r=(s=(f=n[a])!=null?f:a)!=null?s:c;return r=r==="false"?!1:r,r=u(r),e[o]=Number.isNaN(r)?c:r,e},{}),T=t=>{const{observer:n}=t[i];n&&(n.disconnect(),delete t[i].observer)},B=(t,n)=>{const{container:e,containerEl:o,instance:l,observer:f,lastScrollTop:s}=t[i],{disabled:u,distance:c}=h(t,l),{clientHeight:a,scrollHeight:r,scrollTop:d}=o,S=d-s;if(t[i].lastScrollTop=d,f||u||S<0)return;let b=!1;if(e===t)b=r-(a+d)<=c;else{const{clientTop:w,scrollHeight:y}=t,C=O(t,o);b=d+a>=C+w+y-c}b&&n.call(l)};function g(t,n){const{containerEl:e,instance:o}=t[i],{disabled:l}=h(t,o);l||e.clientHeight===0||(e.scrollHeight<=e.clientHeight?n.call(o):T(t))}const F={async mounted(t,n){const{instance:e,value:o}=n;I(o)||L(i,"'v-infinite-scroll' binding value must be a function"),await m();const{delay:l,immediate:f}=h(t,e),s=N(t,!0),u=s===window?document.documentElement:s,c=v(B.bind(null,t,o),l);if(!!s){if(t[i]={instance:e,container:s,containerEl:u,delay:l,cb:o,onScroll:c,lastScrollTop:u.scrollTop},f){const a=new MutationObserver(v(g.bind(null,t,o),A));t[i].observer=a,a.observe(t,{childList:!0,subtree:!0}),g(t,o)}s.addEventListener("scroll",c)}},unmounted(t){const{container:n,onScroll:e}=t[i];n?.removeEventListener("scroll",e),T(t)},async updated(t){if(!t[i])await m();else{const{containerEl:n,cb:e,observer:o}=t[i];n.clientHeight&&o&&g(t,e)}}},p=F;p.install=t=>{t.directive("InfiniteScroll",p)};const x=p;export{x as E,k as i};