UNPKG

@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) 12.7 kB
import"./chunk-L67DAW3A.js";var I=function(n,t){var i,e={passive:!0},r=function(){i&&i()},s=function(a){n===a.target&&(r(),t(a))};return n&&(n.addEventListener("webkitTransitionEnd",s,e),n.addEventListener("transitionend",s,e),i=function(){n.removeEventListener("webkitTransitionEnd",s,e),n.removeEventListener("transitionend",s,e)}),r},O=/(^-?\d*\.?\d*)(.*)/,D=32,N=400,B={translateX:1,translateY:1,translateZ:1,scale:1,scaleX:1,scaleY:1,scaleZ:1,rotate:1,rotateX:1,rotateY:1,rotateZ:1,skewX:1,skewY:1,perspective:1},k=typeof window<"u"?window:{},C=k.requestAnimationFrame?k.requestAnimationFrame.bind(k):function(n){return n(Date.now())},P=function(){function n(){this._hasDur=!1,this._hasTweenEffect=!1,this._isAsync=!1,this._isReverse=!1,this._destroyed=!1,this.hasChildren=!1,this.isPlaying=!1,this.hasCompleted=!1}return n.prototype.addElement=function(t){if(t!=null)if(t.length>0)for(var i=0;i<t.length;i++)this._addEl(t[i]);else this._addEl(t);return this},n.prototype._addEl=function(t){t.nodeType===1&&(this._elements=this._elements||[]).push(t)},n.prototype.add=function(t){return t.parent=this,this.hasChildren=!0,(this._childAnimations=this._childAnimations||[]).push(t),this},n.prototype.getDuration=function(t){return t&&t.duration!==void 0?t.duration:this._duration!==void 0?this._duration:this.parent?this.parent.getDuration():0},n.prototype.isRoot=function(){return!this.parent},n.prototype.duration=function(t){return this._duration=t,this},n.prototype.getEasing=function(){return this._isReverse&&this._reversedEasingName!==void 0?this._reversedEasingName:this._easingName!==void 0?this._easingName:this.parent&&this.parent.getEasing()||null},n.prototype.easing=function(t){return this._easingName=t,this},n.prototype.easingReverse=function(t){return this._reversedEasingName=t,this},n.prototype.from=function(t,i){return this._addProp("from",t,i),this},n.prototype.to=function(t,i,e){e===void 0&&(e=!1);var r=this._addProp("to",t,i);return e&&this.afterClearStyles(r.trans?["transform","-webkit-transform"]:[t]),this},n.prototype.fromTo=function(t,i,e,r){return this.from(t,i).to(t,e,r)},n.prototype._getProp=function(t){if(this._fxProperties)return this._fxProperties.find(function(i){return i.effectName===t})},n.prototype._addProp=function(t,i,e){var r=this._getProp(i);if(!r){var s=B[i]===1;r={effectName:i,trans:s,wc:s?"transform":i},(this._fxProperties=this._fxProperties||[]).push(r)}var a={val:e,num:0,effectUnit:""};if(r[t]=a,typeof e=="string"&&e.indexOf(" ")<0){var o=e.match(O);if(o){var h=parseFloat(o[1]);isNaN(h)||(a.num=h),a.effectUnit=o[0]!==o[2]?o[2]:""}}else typeof e=="number"&&(a.num=e);return r},n.prototype.beforeAddClass=function(t){return(this._beforeAddClasses=this._beforeAddClasses||[]).push(t),this},n.prototype.beforeRemoveClass=function(t){return(this._beforeRemoveClasses=this._beforeRemoveClasses||[]).push(t),this},n.prototype.beforeStyles=function(t){return this._beforeStyles=t,this},n.prototype.beforeClearStyles=function(t){this._beforeStyles=this._beforeStyles||{};for(var i=0,e=t;i<e.length;i++){var r=e[i];this._beforeStyles[r]=""}return this},n.prototype.beforeAddRead=function(t){return(this._readCallbacks=this._readCallbacks||[]).push(t),this},n.prototype.beforeAddWrite=function(t){return(this._writeCallbacks=this._writeCallbacks||[]).push(t),this},n.prototype.afterAddClass=function(t){return(this._afterAddClasses=this._afterAddClasses||[]).push(t),this},n.prototype.afterRemoveClass=function(t){return(this._afterRemoveClasses=this._afterRemoveClasses||[]).push(t),this},n.prototype.afterStyles=function(t){return this._afterStyles=t,this},n.prototype.afterClearStyles=function(t){this._afterStyles=this._afterStyles||{};for(var i=0,e=t;i<e.length;i++){var r=e[i];this._afterStyles[r]=""}return this},n.prototype.play=function(t){var i=this;this._destroyed||(this._isAsync=this._hasDuration(t),this._clearAsync(),this._playInit(t),C(function(){C(function(){i._playDomInspect(t)})}))},n.prototype.playAsync=function(t){var i=this;return new Promise(function(e){return i.onFinish(e,{oneTimeCallback:!0,clearExistingCallbacks:!0}),i.play(t),i})},n.prototype.playSync=function(){if(!this._destroyed){var t={duration:0};this._isAsync=!1,this._clearAsync(),this._playInit(t),this._playDomInspect(t)}},n.prototype._playInit=function(t){this._hasTweenEffect=!1,this.isPlaying=!0,this.hasCompleted=!1,this._hasDur=this.getDuration(t)>D;var i=this._childAnimations;if(i)for(var e=0,r=i;e<r.length;e++){var s=r[e];s._playInit(t)}this._hasDur&&(this._progress(0),this._willChange(!0))},n.prototype._playDomInspect=function(t){var i=this;this._beforeAnimation();var e=this.getDuration(t);this._isAsync&&this._asyncEnd(e,!0),this._playProgress(t),this._isAsync&&!this._destroyed&&C(function(){i._playToStep(1)})},n.prototype._playProgress=function(t){var i=this._childAnimations;if(i)for(var e=0,r=i;e<r.length;e++){var s=r[e];s._playProgress(t)}this._hasDur?this._setTrans(this.getDuration(t),!1):(this._progress(1),this._setAfterStyles(),this._didFinish(!0))},n.prototype._playToStep=function(t){if(!this._destroyed){var i=this._childAnimations;if(i)for(var e=0,r=i;e<r.length;e++){var s=r[e];s._playToStep(t)}this._hasDur&&this._progress(t)}},n.prototype._asyncEnd=function(t,i){var e=this,r=function(){e._clearAsync(),e._playEnd(),e._didFinishAll(i,!0,!1)},s=function(){e._timerId=void 0,e._clearAsync(),e._playEnd(i?1:0),e._didFinishAll(i,!0,!1)};e._unregisterTrnsEnd=I(e._transEl(),r),e._timerId=setTimeout(s,t+N)},n.prototype._playEnd=function(t){var i=this._childAnimations;if(i)for(var e=0,r=i;e<r.length;e++){var s=r[e];s._playEnd(t)}this._hasDur&&(t!==void 0&&(this._setTrans(0,!0),this._progress(t)),this._setAfterStyles(),this._willChange(!1))},n.prototype._hasDuration=function(t){if(this.getDuration(t)>D)return!0;var i=this._childAnimations;if(i)for(var e=0,r=i;e<r.length;e++){var s=r[e];if(s._hasDuration(t))return!0}return!1},n.prototype._hasDomReads=function(){if(this._readCallbacks&&this._readCallbacks.length>0)return!0;var t=this._childAnimations;if(t)for(var i=0,e=t;i<e.length;i++){var r=e[i];if(r._hasDomReads())return!0}return!1},n.prototype.stop=function(t){t===void 0&&(t=1),this._clearAsync(),this._hasDur=!0,this._playEnd(t)},n.prototype._clearAsync=function(){this._unregisterTrnsEnd&&this._unregisterTrnsEnd(),this._timerId&&clearTimeout(this._timerId),this._timerId=this._unregisterTrnsEnd=void 0},n.prototype._progress=function(t){var i,e=this._elements,r=this._fxProperties;if(!(!e||e.length===0||!r||this._destroyed)){this._isReverse&&(t=1-t);var s=0,a=0,o="",h;for(s=0;s<r.length;s++)if(h=r[s],h.from&&h.to){var f=h.from.num,l=h.to.num,u=f!==l;if(u&&(this._hasTweenEffect=!0),t===0)i=h.from.val;else if(t===1)i=h.to.val;else if(u){var c=(l-f)*t+f,d=h.to.effectUnit;i=c+d}if(i!==null){var v=h.effectName;if(h.trans)o+=v+"("+i+") ";else for(a=0;a<e.length;a++)e[a].style.setProperty(v,i)}}if(o.length>0)for((!this._isReverse&&t!==1||this._isReverse&&t!==0)&&(o+="translateZ(0px)"),s=0;s<e.length;s++)e[s].style.setProperty("transform",o),e[s].style.setProperty("-webkit-transform",o)}},n.prototype._setTrans=function(t,i){var e=this._elements;if(!(!e||e.length===0||!this._fxProperties))for(var r=i?"linear":this.getEasing(),s=t+"ms",a=0,o=e;a<o.length;a++){var h=o[a].style;t>0?(h.transitionDuration=s,r!==null&&(h.transitionTimingFunction=r)):h.transitionDuration="0"}},n.prototype._beforeAnimation=function(){this._fireBeforeReadFunc(),this._fireBeforeWriteFunc(),this._setBeforeStyles()},n.prototype._setBeforeStyles=function(){var t=this._childAnimations;if(t)for(var i=0,e=t;i<e.length;i++){var r=e[i];r._setBeforeStyles()}var s=this._elements;if(!(!s||s.length===0||this._isReverse))for(var a=this._beforeAddClasses,o=this._beforeRemoveClasses,h=0,f=s;h<f.length;h++){var l=f[h],u=l.classList;if(a)for(var c=0,d=a;c<d.length;c++){var v=d[c];u.add(v)}if(o)for(var p=0,A=o;p<A.length;p++){var v=A[p];u.remove(v)}if(this._beforeStyles)for(var y=0,_=Object.entries(this._beforeStyles);y<_.length;y++){var g=_[y],b=g[0],m=g[1];l.style.setProperty(b,m)}}},n.prototype._fireBeforeReadFunc=function(){var t=this._childAnimations;if(t)for(var i=0,e=t;i<e.length;i++){var r=e[i];r._fireBeforeReadFunc()}var s=this._readCallbacks;if(s)for(var a=0,o=s;a<o.length;a++){var h=o[a];h()}},n.prototype._fireBeforeWriteFunc=function(){var t=this._childAnimations;if(t)for(var i=0,e=t;i<e.length;i++){var r=e[i];r._fireBeforeWriteFunc()}var s=this._writeCallbacks;if(s)for(var a=0,o=s;a<o.length;a++){var h=o[a];h()}},n.prototype._setAfterStyles=function(){var t=this._elements;if(t)for(var i=0,e=t;i<e.length;i++){var r=e[i],s=r.classList;if(r.style.transitionDuration=r.style.transitionTimingFunction="",this._isReverse){var a=this._beforeAddClasses;if(a)for(var o=0,h=a;o<h.length;o++){var f=h[o];s.remove(f)}var l=this._beforeRemoveClasses;if(l)for(var u=0,c=l;u<c.length;u++){var f=c[u];s.add(f)}var d=this._beforeStyles;if(d)for(var v=0,p=Object.keys(d);v<p.length;v++){var A=p[v];r.style.removeProperty(A)}}else{var y=this._afterAddClasses;if(y)for(var _=0,g=y;_<g.length;_++){var f=g[_];s.add(f)}var b=this._afterRemoveClasses;if(b)for(var m=0,T=b;m<T.length;m++){var f=T[m];s.remove(f)}var F=this._afterStyles;if(F)for(var E=0,S=Object.entries(F);E<S.length;E++){var w=S[E],R=w[0],x=w[1];r.style.setProperty(R,x)}}}},n.prototype._willChange=function(t){var i,e=this._fxProperties,r;if(t&&e){i=[];for(var s=0,a=e;s<a.length;s++){var o=a[s],h=o.wc;h==="webkitTransform"?i.push("transform","-webkit-transform"):h!==void 0&&i.push(h)}r=i.join(",")}else r="";var f=this._elements;if(f)for(var l=0,u=f;l<u.length;l++){var c=u[l];c.style.setProperty("will-change",r)}},n.prototype.progressStart=function(){this._clearAsync(),this._beforeAnimation(),this._progressStart()},n.prototype._progressStart=function(){var t=this._childAnimations;if(t)for(var i=0,e=t;i<e.length;i++){var r=e[i];r._progressStart()}this._setTrans(0,!0),this._willChange(!0)},n.prototype.progressStep=function(t){t=Math.min(1,Math.max(0,t));var i=this._childAnimations;if(i)for(var e=0,r=i;e<r.length;e++){var s=r[e];s.progressStep(t)}this._progress(t)},n.prototype.progressEnd=function(t,i,e){var r=this;e===void 0&&(e=-1),this._isReverse&&(i=1-i);var s=t?1:0,a=Math.abs(i-s);e<0?e=this._duration||0:a<.05&&(e=0),this._isAsync=e>30,this._progressEnd(t,s,e,this._isAsync),this._isAsync&&(this._asyncEnd(e,t),this._destroyed||C(function(){r._playToStep(s)}))},n.prototype._progressEnd=function(t,i,e,r){var s=this._childAnimations;if(s)for(var a=0,o=s;a<o.length;a++){var h=o[a];h._progressEnd(t,i,e,r)}r?(this.isPlaying=!0,this.hasCompleted=!1,this._hasDur=!0,this._willChange(!0),this._setTrans(e,!1)):(this._progress(i),this._willChange(!1),this._setAfterStyles(),this._didFinish(t))},n.prototype.onFinish=function(t,i){return i&&i.clearExistingCallbacks&&(this._onFinishCallbacks=this._onFinishOneTimeCallbacks=void 0),i&&i.oneTimeCallback?(this._onFinishOneTimeCallbacks=this._onFinishOneTimeCallbacks||[],this._onFinishOneTimeCallbacks.push(t)):(this._onFinishCallbacks=this._onFinishCallbacks||[],this._onFinishCallbacks.push(t)),this},n.prototype._didFinishAll=function(t,i,e){var r=this._childAnimations;if(r)for(var s=0,a=r;s<a.length;s++){var o=a[s];o._didFinishAll(t,i,e)}(i&&this._isAsync||e&&!this._isAsync)&&this._didFinish(t)},n.prototype._didFinish=function(t){if(this.isPlaying=!1,this.hasCompleted=t,this._onFinishCallbacks)for(var i=0,e=this._onFinishCallbacks;i<e.length;i++){var r=e[i];r(this)}if(this._onFinishOneTimeCallbacks){for(var s=0,a=this._onFinishOneTimeCallbacks;s<a.length;s++){var r=a[s];r(this)}this._onFinishOneTimeCallbacks.length=0}},n.prototype.reverse=function(t){t===void 0&&(t=!0);var i=this._childAnimations;if(i)for(var e=0,r=i;e<r.length;e++){var s=r[e];s.reverse(t)}return this._isReverse=!!t,this},n.prototype.destroy=function(){this._didFinish(!1),this._destroyed=!0;var t=this._childAnimations;if(t)for(var i=0,e=t;i<e.length;i++){var r=e[i];r.destroy()}this._clearAsync(),this._elements&&(this._elements.length=0),this._readCallbacks&&(this._readCallbacks.length=0),this._writeCallbacks&&(this._writeCallbacks.length=0),this.parent=void 0,this._childAnimations&&(this._childAnimations.length=0),this._onFinishCallbacks&&(this._onFinishCallbacks.length=0),this._onFinishOneTimeCallbacks&&(this._onFinishOneTimeCallbacks.length=0)},n.prototype._transEl=function(){var t=this._childAnimations;if(t)for(var i=0,e=t;i<e.length;i++){var r=e[i],s=r._transEl();if(s)return s}return this._hasTweenEffect&&this._hasDur&&this._elements!==void 0&&this._elements.length>0?this._elements[0]:null},n}(),M=function(n,t,i){return n?n(P,t,i):Promise.resolve(new P)};export{M as create};