UNPKG

@zoff-tech/zt-bottom-drawer

Version:
2 lines 2.5 kB
import{r as t,d as s,w as i,i as e,h,e as n,H as o}from"./p-f6c816ce.js";import{findClosestIonContent as r,printIonContentErrorMsg as a,getScrollElement as l}from"@utils/content";import{g as c}from"./p-0b9b2444.js";const f="ion-infinite-scroll{display:none;width:100%}.infinite-scroll-enabled{display:block}";const d=class{constructor(i){t(this,i);this.ionInfinite=s(this,"ionInfinite",7);this.thrPx=0;this.thrPc=0;this.didFire=false;this.isBusy=false;this.onScroll=()=>{const t=this.scrollEl;if(!t||!this.canStart()){return 1}const s=this.el.offsetHeight;if(s===0){return 2}const i=t.scrollTop;const e=t.scrollHeight;const h=t.offsetHeight;const n=this.thrPc!==0?h*this.thrPc:this.thrPx;const o=this.position==="bottom"?e-s-i-n-h:i-s-n;if(o<0){if(!this.didFire){this.isLoading=true;this.didFire=true;this.ionInfinite.emit();return 3}}else{this.didFire=false}return 4};this.isLoading=false;this.threshold="15%";this.disabled=false;this.position="bottom"}thresholdChanged(){const t=this.threshold;if(t.lastIndexOf("%")>-1){this.thrPx=0;this.thrPc=parseFloat(t)/100}else{this.thrPx=parseFloat(t);this.thrPc=0}}disabledChanged(){const t=this.disabled;if(t){this.isLoading=false;this.isBusy=false}this.enableScrollEvents(!t)}async connectedCallback(){const t=r(this.el);if(!t){a(this.el);return}this.scrollEl=await l(t);this.thresholdChanged();this.disabledChanged();if(this.position==="top"){i((()=>{if(this.scrollEl){this.scrollEl.scrollTop=this.scrollEl.scrollHeight-this.scrollEl.clientHeight}}))}}disconnectedCallback(){this.enableScrollEvents(false);this.scrollEl=undefined}async complete(){const t=this.scrollEl;if(!this.isLoading||!t){return}this.isLoading=false;if(this.position==="top"){this.isBusy=true;const s=t.scrollHeight-t.scrollTop;requestAnimationFrame((()=>{e((()=>{const e=t.scrollHeight;const h=e-s;requestAnimationFrame((()=>{i((()=>{t.scrollTop=h;this.isBusy=false}))}))}))}))}}canStart(){return!this.disabled&&!this.isBusy&&!!this.scrollEl&&!this.isLoading}enableScrollEvents(t){if(this.scrollEl){if(t){this.scrollEl.addEventListener("scroll",this.onScroll)}else{this.scrollEl.removeEventListener("scroll",this.onScroll)}}}render(){const t=c(this);const s=this.disabled;return h(o,{class:{[t]:true,"infinite-scroll-loading":this.isLoading,"infinite-scroll-enabled":!s}})}get el(){return n(this)}static get watchers(){return{threshold:["thresholdChanged"],disabled:["disabledChanged"]}}};d.style=f;export{d as ion_infinite_scroll}; //# sourceMappingURL=p-268a7fef.entry.js.map