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) • 6.54 kB
JavaScript
var x=function(){function t(){this.gestureId=0,this.requestedStart=new Map,this.disabledGestures=new Map,this.disabledScroll=new Set}return t.prototype.createGesture=function(e){return new q(this,this.newID(),e.name,e.priority||0,!!e.disableScroll)},t.prototype.createBlocker=function(e){return e===void 0&&(e={}),new z(this,this.newID(),e.disable,!!e.disableScroll)},t.prototype.start=function(e,r,a){return this.canStart(e)?(this.requestedStart.set(r,a),!0):(this.requestedStart.delete(r),!1)},t.prototype.capture=function(e,r,a){if(!this.start(e,r,a))return!1;var s=this.requestedStart,n=-1e4;if(s.forEach(function(c){n=Math.max(n,c)}),n===a){this.capturedId=r,s.clear();var u=new CustomEvent("ionGestureCaptured",{detail:{gestureName:e}});return document.dispatchEvent(u),!0}return s.delete(r),!1},t.prototype.release=function(e){this.requestedStart.delete(e),this.capturedId===e&&(this.capturedId=void 0)},t.prototype.disableGesture=function(e,r){var a=this.disabledGestures.get(e);a===void 0&&(a=new Set,this.disabledGestures.set(e,a)),a.add(r)},t.prototype.enableGesture=function(e,r){var a=this.disabledGestures.get(e);a!==void 0&&a.delete(r)},t.prototype.disableScroll=function(e){this.disabledScroll.add(e),this.disabledScroll.size===1&&document.body.classList.add(T)},t.prototype.enableScroll=function(e){this.disabledScroll.delete(e),this.disabledScroll.size===0&&document.body.classList.remove(T)},t.prototype.canStart=function(e){return!(this.capturedId!==void 0||this.isDisabled(e))},t.prototype.isCaptured=function(){return this.capturedId!==void 0},t.prototype.isScrollDisabled=function(){return this.disabledScroll.size>0},t.prototype.isDisabled=function(e){var r=this.disabledGestures.get(e);return!!(r&&r.size>0)},t.prototype.newID=function(){return this.gestureId++,this.gestureId},t}(),q=function(){function t(e,r,a,s,n){this.id=r,this.name=a,this.disableScroll=n,this.priority=s*1e6+r,this.ctrl=e}return t.prototype.canStart=function(){return this.ctrl?this.ctrl.canStart(this.name):!1},t.prototype.start=function(){return this.ctrl?this.ctrl.start(this.name,this.id,this.priority):!1},t.prototype.capture=function(){if(!this.ctrl)return!1;var e=this.ctrl.capture(this.name,this.id,this.priority);return e&&this.disableScroll&&this.ctrl.disableScroll(this.id),e},t.prototype.release=function(){this.ctrl&&(this.ctrl.release(this.id),this.disableScroll&&this.ctrl.enableScroll(this.id))},t.prototype.destroy=function(){this.release(),this.ctrl=void 0},t}(),z=function(){function t(e,r,a,s){this.id=r,this.disable=a,this.disableScroll=s,this.ctrl=e}return t.prototype.block=function(){if(this.ctrl){if(this.disable)for(var e=0,r=this.disable;e<r.length;e++){var a=r[e];this.ctrl.disableGesture(a,this.id)}this.disableScroll&&this.ctrl.disableScroll(this.id)}},t.prototype.unblock=function(){if(this.ctrl){if(this.disable)for(var e=0,r=this.disable;e<r.length;e++){var a=r[e];this.ctrl.enableGesture(a,this.id)}this.disableScroll&&this.ctrl.enableScroll(this.id)}},t.prototype.destroy=function(){this.unblock(),this.ctrl=void 0},t}(),T="backdrop-no-scroll",k=new x,y=function(t,e,r,a){var s=R(t)?{capture:!!a.capture,passive:!!a.passive}:!!a.capture,n,u;return t.__zone_symbol__addEventListener?(n="__zone_symbol__addEventListener",u="__zone_symbol__removeEventListener"):(n="addEventListener",u="removeEventListener"),t[n](e,r,s),function(){t[u](e,r,s)}},R=function(t){if(E===void 0)try{var e=Object.defineProperty({},"passive",{get:function(){E=!0}});t.addEventListener("optsTest",function(){},e)}catch{E=!1}return!!E},E,A=2e3,B=function(t,e,r,a,s){var n,u,c,l,f,o,d,S=0,i=function(h){S=Date.now()+A,e(h)&&(!u&&r&&(u=y(t,"touchmove",r,s)),c||(c=y(t,"touchend",v,s)),l||(l=y(t,"touchcancel",v,s)))},m=function(h){S>Date.now()||e(h)&&(!o&&r&&(o=y(P(t),"mousemove",r,s)),d||(d=y(P(t),"mouseup",X,s)))},v=function(h){b(),a&&a(h)},X=function(h){G(),a&&a(h)},b=function(){u&&u(),c&&c(),l&&l(),u=c=l=void 0},G=function(){o&&o(),d&&d(),o=d=void 0},D=function(){b(),G()},Y=function(h){h?(n&&n(),f&&f(),n=f=void 0,D()):(n||(n=y(t,"touchstart",i,s)),f||(f=y(t,"mousedown",m,s)))},g=function(){Y(!0),a=r=e=void 0};return{setDisabled:Y,stop:D,destroy:g}},P=function(t){return t instanceof Document?t:t.ownerDocument},F=function(t,e,r){var a=r*(Math.PI/180),s=t==="x",n=Math.cos(a),u=e*e,c=0,l=0,f=!1,o=0;return{start:function(d,S){c=d,l=S,o=0,f=!0},detect:function(d,S){if(!f)return!1;var i=d-c,m=S-l,v=i*i+m*m;if(v<u)return!1;var X=Math.sqrt(v),b=(s?i:m)/X;return b>n?o=1:b<-n?o=-1:o=0,f=!1,!0},isGesture:function(){return o!==0},getDirection:function(){return o}}},W=function(t){var e=!1,r=!1,a=!0,s=!1,n=Object.assign({disableScroll:!1,direction:"x",gesturePriority:0,passive:!0,maxAngle:40,threshold:10},t),u=n.canStart,c=n.onWillStart,l=n.onStart,f=n.onEnd,o=n.notCaptured,d=n.onMove,S=n.threshold,i={type:"pan",startX:0,startY:0,startTimeStamp:0,currentX:0,currentY:0,velocityX:0,velocityY:0,deltaX:0,deltaY:0,timeStamp:0,event:void 0,data:void 0},m=F(n.direction,n.threshold,n.maxAngle),v=k.createGesture({name:t.gestureName,priority:t.gesturePriority,disableScroll:t.disableScroll}),X=function(p){var C=I(p);return r||!a||(_(p,i),i.startX=i.currentX,i.startY=i.currentY,i.startTimeStamp=i.timeStamp=C,i.velocityX=i.velocityY=i.deltaX=i.deltaY=0,i.event=p,u&&u(i)===!1)||(v.release(),!v.start())?!1:(r=!0,S===0?D():(m.start(i.startX,i.startY),!0))},b=function(p){if(e){!s&&a&&(s=!0,M(i,p),requestAnimationFrame(G));return}M(i,p),m.detect(i.currentX,i.currentY)&&(!m.isGesture()||!D())&&L()},G=function(){e&&(s=!1,d&&d(i))},D=function(){return v&&!v.capture()?!1:(e=!0,a=!1,i.startX=i.currentX,i.startY=i.currentY,i.startTimeStamp=i.timeStamp,c?c(i).then(Y):Y(),!0)},Y=function(){l&&l(i),a=!0},g=function(){e=!1,r=!1,s=!1,a=!0,v.release()},h=function(p){var C=e,O=a;if(g(),!!O){if(M(i,p),C){f&&f(i);return}o&&o(i)}},w=B(n.el,X,b,h,{capture:!1}),L=function(){g(),w.stop(),o&&o(i)};return{setDisabled:function(p){p&&e&&h(void 0),w.setDisabled(p)},destroy:function(){v.destroy(),w.destroy()}}},M=function(t,e){if(e){var r=t.currentX,a=t.currentY,s=t.timeStamp;_(e,t);var n=t.currentX,u=t.currentY,c=t.timeStamp=I(e),l=c-s;if(l>0&&l<100){var f=(n-r)/l,o=(u-a)/l;t.velocityX=f*.7+t.velocityX*.3,t.velocityY=o*.7+t.velocityY*.3}t.deltaX=n-t.startX,t.deltaY=u-t.startY,t.event=e}},_=function(t,e){var r=0,a=0;if(t){var s=t.changedTouches;if(s&&s.length>0){var n=s[0];r=n.clientX,a=n.clientY}else t.pageX!==void 0&&(r=t.pageX,a=t.pageY)}e.currentX=r,e.currentY=a},I=function(t){return t.timeStamp||Date.now()};export{k as a,W as b};