@tindtechnologies/universalviewer
Version:
The Universal Viewer is a community-developed open source project on a mission to help you share your 📚📜📰📽️📻🗿 with the 🌎
2 lines (1 loc) • 4.26 kB
JavaScript
import{a as f,b as d,c as u,e as b,f as v,i as g,l as p,o as y}from"./chunk-VNJCZCB4.js";import"./chunk-L67DAW3A.js";var E=function(l,n,t,r){return new(t||(t=Promise))(function(s,i){function o(e){try{h(r.next(e))}catch(a){i(a)}}function c(e){try{h(r.throw(e))}catch(a){i(a)}}function h(e){e.done?s(e.value):new t(function(a){a(e.value)}).then(o,c)}h((r=r.apply(l,n||[])).next())})},m=function(l,n){var t={label:0,sent:function(){if(i[0]&1)throw i[1];return i[1]},trys:[],ops:[]},r,s,i,o;return o={next:c(0),throw:c(1),return:c(2)},typeof Symbol=="function"&&(o[Symbol.iterator]=function(){return this}),o;function c(e){return function(a){return h([e,a])}}function h(e){if(r)throw new TypeError("Generator is already executing.");for(;t;)try{if(r=1,s&&(i=e[0]&2?s.return:e[0]?s.throw||((i=s.return)&&i.call(s),0):s.next)&&!(i=i.call(s,e[1])).done)return i;switch(s=0,i&&(e=[e[0]&2,i.value]),e[0]){case 0:case 1:i=e;break;case 4:return t.label++,{value:e[1],done:!1};case 5:t.label++,s=e[1],e=[0];continue;case 7:e=t.ops.pop(),t.trys.pop();continue;default:if(i=t.trys,!(i=i.length>0&&i[i.length-1])&&(e[0]===6||e[0]===2)){t=0;continue}if(e[0]===3&&(!i||e[1]>i[0]&&e[1]<i[3])){t.label=e[1];break}if(e[0]===6&&t.label<i[1]){t.label=i[1],i=e;break}if(i&&t.label<i[2]){t.label=i[2],t.ops.push(e);break}i[2]&&t.ops.pop(),t.trys.pop();continue}e=n.call(l,t)}catch(a){e=[6,a],s=0}finally{r=i=0}if(e[0]&5)throw e[1];return{value:e[0]?e[1]:void 0,done:!0}}},_=function(){function l(n){var t=this;f(this,n),this.thrPx=0,this.thrPc=0,this.didFire=!1,this.isBusy=!1,this.isLoading=!1,this.threshold="15%",this.disabled=!1,this.position="bottom",this.onScroll=function(){var r=t.scrollEl;if(!r||!t.canStart())return 1;var s=t.el.offsetHeight;if(s===0)return 2;var i=r.scrollTop,o=r.scrollHeight,c=r.offsetHeight,h=t.thrPc!==0?c*t.thrPc:t.thrPx,e=t.position==="bottom"?o-s-i-h-c:i-s-h;if(e<0){if(!t.didFire)return t.isLoading=!0,t.didFire=!0,t.ionInfinite.emit(),3}else t.didFire=!1;return 4},this.ionInfinite=g(this,"ionInfinite",7)}return l.prototype.thresholdChanged=function(){var n=this.threshold;n.lastIndexOf("%")>-1?(this.thrPx=0,this.thrPc=parseFloat(n)/100):(this.thrPx=parseFloat(n),this.thrPc=0)},l.prototype.disabledChanged=function(){var n=this.disabled;n&&(this.isLoading=!1,this.isBusy=!1),this.enableScrollEvents(!n)},l.prototype.connectedCallback=function(){return E(this,void 0,void 0,function(){var n,t,r=this;return m(this,function(s){switch(s.label){case 0:return n=this.el.closest("ion-content"),n?(t=this,[4,n.getScrollElement()]):(console.error("<ion-infinite-scroll> must be used inside an <ion-content>"),[2]);case 1:return t.scrollEl=s.sent(),this.thresholdChanged(),this.disabledChanged(),this.position==="top"&&u(function(){r.scrollEl&&(r.scrollEl.scrollTop=r.scrollEl.scrollHeight-r.scrollEl.clientHeight)}),[2]}})})},l.prototype.disconnectedCallback=function(){this.enableScrollEvents(!1),this.scrollEl=void 0},l.prototype.complete=function(){return E(this,void 0,void 0,function(){var n,t,r=this;return m(this,function(s){return n=this.scrollEl,!this.isLoading||!n?[2]:(this.isLoading=!1,this.position==="top"&&(this.isBusy=!0,t=n.scrollHeight-n.scrollTop,requestAnimationFrame(function(){d(function(){var i=n.scrollHeight,o=i-t;requestAnimationFrame(function(){u(function(){n.scrollTop=o,r.isBusy=!1})})})})),[2])})})},l.prototype.canStart=function(){return!this.disabled&&!this.isBusy&&!!this.scrollEl&&!this.isLoading},l.prototype.enableScrollEvents=function(n){this.scrollEl&&(n?this.scrollEl.addEventListener("scroll",this.onScroll):this.scrollEl.removeEventListener("scroll",this.onScroll))},l.prototype.render=function(){var n,t=y(this),r=this.disabled;return b(v,{class:(n={},n[t]=!0,n["infinite-scroll-loading"]=this.isLoading,n["infinite-scroll-enabled"]=!r,n)})},Object.defineProperty(l.prototype,"el",{get:function(){return p(this)},enumerable:!0,configurable:!0}),Object.defineProperty(l,"watchers",{get:function(){return{threshold:["thresholdChanged"],disabled:["disabledChanged"]}},enumerable:!0,configurable:!0}),Object.defineProperty(l,"style",{get:function(){return"ion-infinite-scroll{display:none;width:100%}.infinite-scroll-enabled{display:block}"},enumerable:!0,configurable:!0}),l}();export{_ as ion_infinite_scroll};