forked from pbakaus/scroller
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.es.js
2 lines (2 loc) · 7.37 KB
/
index.es.js
1
2
const t="undefined"==typeof window?{}:window;let n={},i=1;const e=t.requestAnimationFrame||t.webkitRequestAnimationFrame||t.mozRequestAnimationFrame||t.oRequestAnimationFrame;function o(t){var i=null!=n[t];return i&&(n[t]=null),i}function r(t,o,r,l,a){var h=Date.now(),s=h,u=0,c=0,f=i++;if(f%20==0){var _={};for(var v in n)_[v]=!0;n=_}var M=function(i){var _=!0!==i,v=Date.now();if(!n[f]||o&&!o(f))return n[f]=null,void(r&&r(60-c/((v-h)/1e3),f,!1));if(_)for(var m=Math.round((v-s)/(1e3/60))-1,p=0;p<Math.min(m,4);p++)M(!0),c++;l&&(u=(v-h)/l)>1&&(u=1);var d=a?a(u):u;!1!==t(d,v,_)&&1!==u||!_?_&&(s=v,e(M)):(n[f]=null,r&&r(60-c/((v-h)/1e3),f,1===u||null==l))};return n[f]=!0,e(M),f}function l(t){return Math.pow(t-1,3)+1}function a(t){return(t/=.5)<1?.5*Math.pow(t,3):.5*(Math.pow(t-2,3)+2)}const h={scrollingX:!0,scrollingY:!0,animating:!0,animationDuration:250,bouncing:!0,locking:!0,paging:!1,snapping:!1,zooming:!1,minZoom:.5,maxZoom:3,speedMultiplier:1,scrollingComplete:function(){},penetrationDeceleration:.03,penetrationAcceleration:.08,centering:!0};function s(t,n){this.t=t,this.options=Object.assign({},h,n)}s.prototype={i:!1,o:!1,l:!1,h:!1,u:!1,_:!1,v:!1,M:0,m:0,p:0,g:0,T:0,D:0,S:100,L:100,Z:null,I:!1,P:null,A:null,H:null,V:1,C:0,O:0,R:0,W:0,k:0,B:0,X:0,Y:0,j:0,G:null,q:null,F:null,J:null,K:null,N:null,U:null,$:null,tt:null,nt:null,setDimensions:function(t,n,i,e){var o=this;t===+t&&(o.p=t),n===+n&&(o.g=n),i===+i&&(o.T=i),e===+e&&(o.D=e),o.it(),o.scrollTo(o.C,o.O,!0)},setPosition:function(t,n){this.M=t||0,this.m=n||0},setSnapSize:function(t,n){this.S=t,this.L=n},activatePullToRefresh:function(t,n,i,e){var o=this;o.Z=t,o.P=n,o.A=i,o.H=e},triggerPullToRefresh:function(){this.et(this.C,-this.Z,this.V,!0),this.H&&this.H()},finishPullToRefresh:function(){var t=this;t.I=!1,t.A&&t.A(),t.scrollTo(t.C,t.O,!0)},getValues:function(){var t=this;return{left:t.C-(t.options.centering?t.Y:0),top:t.O-(t.options.centering?t.j:0),zoom:t.V}},getScrollMax:function(){return{left:this.R,top:this.W}},zoomTo:function(t,n,i,e,r){var l=this;if(!l.options.zooming)throw new Error("Zooming is not enabled!");r&&(l.ot=r),l._&&(o(l._),l._=!1);var a=l.V;null==i&&(i=l.p/2),null==e&&(e=l.g/2),t=Math.max(Math.min(t,l.options.maxZoom),l.options.minZoom),l.it(t);var h=(i+l.C)*t/a-i,s=(e+l.O)*t/a-e;h>l.R?h=l.R:h<0&&(h=0),s>l.W?s=l.W:s<0&&(s=0),l.et(h,s,t,n)},zoomBy:function(t,n,i,e,o){this.zoomTo(this.V*t,n,i,e,o)},scrollTo:function(t,n,i,e){var r=this;if(r._&&(o(r._),r._=!1),null!=e&&e!==r.V){if(!r.options.zooming)throw new Error("Zooming is not enabled!");t*=e,n*=e,r.it(e)}else e=r.V;r.options.scrollingX?r.options.paging?t=Math.round(t/r.p)*r.p:r.options.snapping&&(t=Math.round(t/r.S)*r.S):t=r.C,r.options.scrollingY?r.options.paging?n=Math.round(n/r.g)*r.g:r.options.snapping&&(n=Math.round(n/r.L)*r.L):n=r.O,t=Math.max(Math.min(r.R,t),0),n=Math.max(Math.min(r.W,n),0),t===r.C&&n===r.O&&(i=!1),r.o||r.et(t,n,e,i)},scrollToViewportCenter(t,n,i,e){e=null==e?this.V:e,this.zoomTo(e,!1),this.scrollTo(t*e-.5*this.p,n*e-.5*this.g,i)},scrollBy:function(t,n,i){var e=this,o=e.v?e.k:e.C,r=e.v?e.B:e.O;e.scrollTo(o+(t||0),r+(n||0),i)},containsPoint:(t,n)=>!(t<0)&&(!(t>self.T)&&(!(n<0)&&!(n>self.D))),doMouseZoom:function(t,n,i,e){var o=this,r=t>0?.97:1.03;return o.zoomTo(o.V*r,!1,i-o.M,e-o.m)},doTouchStart:function(t,n){if(null==t.length)throw new Error("Invalid touch list: "+t);if(n instanceof Date&&(n=n.valueOf()),"number"!=typeof n)throw new Error("Invalid timestamp value: "+n);var i,e,r=this;r.rt=!0,r._&&(o(r._),r._=!1,r.rt=!0),r.v&&(o(r.v),r.v=!1,r.rt=!0);var l=1===t.length;l?(i=t[0].pageX,e=t[0].pageY):(i=Math.abs(t[0].pageX+t[1].pageX)/2,e=Math.abs(t[0].pageY+t[1].pageY)/2),r.lt=i,r.ht=e,r.st=r.V,r.G=i,r.q=e,r.F=n,r.ut=1,r.ct=!l&&r.options.scrollingX,r.ft=!l&&r.options.scrollingY,r.o=!0,r.l=!1,r.u=!l,r.i=l,r.J=[]},doTouchMove:function(t,n,i){if(null==t.length)throw new Error("Invalid touch list: "+t);if(n instanceof Date&&(n=n.valueOf()),"number"!=typeof n)throw new Error("Invalid timestamp value: "+n);var e=this;if(e.o){var o,r;2===t.length?(o=Math.abs(t[0].pageX+t[1].pageX)/2,r=Math.abs(t[0].pageY+t[1].pageY)/2):(o=t[0].pageX,r=t[0].pageY);var l=e.J;if(e.u){var a=o-e.G,h=r-e.q,s=e.C,u=e.O,c=e.V;if(null!=i&&e.options.zooming){var f=c;if(c=c/e.ut*i,f!==(c=Math.max(Math.min(c,e.options.maxZoom),e.options.minZoom))){var _=o-e.M,v=r-e.m;s=(_+s)*c/f-_,u=(v+u)*c/f-v,e.it(c)}}if(e.ct){s-=a*this.options.speedMultiplier;var M=e.R;(s>M||s<0)&&(e.options.bouncing?s+=a/2*this.options.speedMultiplier:s=s>M?M:0)}if(e.ft){u-=h*this.options.speedMultiplier;var m=e.W;(u>m||u<0)&&(e.options.bouncing?(u+=h/2*this.options.speedMultiplier,e.ct||null==e.Z||(!e.I&&u<=-e.Z?(e.I=!0,e.P&&e.P()):e.I&&u>-e.Z&&(e.I=!1,e.A&&e.A()))):u=u>m?m:0)}l.length>60&&l.splice(0,30),l.push(s,u,n),e.et(s,u,c)}else{var p=e.options.locking?3:0,d=Math.abs(o-e.lt),g=Math.abs(r-e.ht);e.ct=e.options.scrollingX&&d>=p,e.ft=e.options.scrollingY&&g>=p,l.push(e.C,e.O,n),e.u=(e.ct||e.ft)&&(d>=5||g>=5),e.u&&(e.rt=!1)}e.G=o,e.q=r,e.F=n,e.ut=i}},doTouchEnd:function(t){if(t instanceof Date&&(t=t.valueOf()),"number"!=typeof t)throw new Error("Invalid timestamp value: "+t);var n=this;if(n.o){if(n.o=!1,n.u)if(n.u=!1,n.i&&n.options.animating&&t-n.F<=100){for(var i=n.J,e=i.length-1,o=e,r=e;r>0&&i[r]>n.F-100;r-=3)o=r;if(o!==e){var l=i[e]-i[o],a=n.C-i[o-2],h=n.O-i[o-1];n.tt=a/l*(1e3/60),n.nt=h/l*(1e3/60);var s=n.options.paging||n.options.snapping?4:1;Math.abs(n.tt)>s||Math.abs(n.nt)>s?n.I||n._t(t):n.options.scrollingComplete()}else n.options.scrollingComplete()}else t-n.F>100&&n.options.scrollingComplete();n._||(n.I&&n.H?(n.et(n.C,-n.Z,n.V,!0),n.H&&n.H()):((n.rt||n.u)&&n.options.scrollingComplete(),n.scrollTo(n.C,n.O,!0,n.V),n.I&&(n.I=!1,n.A&&n.A()))),n.J.length=0}},et:function(t,n,i,e){var h=this,s=h.v;if(s&&(o(s),h.v=!1),e&&h.options.animating){h.k=t,h.B=n,h.X=i;var u=h.C,c=h.O,f=h.V,_=t-u,v=n-c,M=i-f;h.v=r((function(t,n,i){i&&(h.C=u+_*t,h.O=c+v*t,h.V=f+M*t,h.t&&h.t(h.C-h.Y,h.O-h.j,h.V))}),(function(t){return h.v===t}),(function(t,n,i){n===h.v&&(h.v=!1),(h.l||i)&&h.options.scrollingComplete(),h.options.zooming&&(h.it(),h.ot&&(h.ot(),h.ot=null))}),h.options.animationDuration,s?l:a)}else h.k=h.C=t,h.B=h.O=n,h.X=h.V=i,h.t&&h.t(t-h.Y,n-h.j,i),h.options.zooming&&(h.it(),h.ot&&(h.ot(),h.ot=null))},it:function(t){var n=this;null==t&&(t=n.V),n.R=Math.max(n.T*t-n.p,0),n.W=Math.max(n.D*t-n.g,0);var i=0,e=0;n.options.centering&&(i=n.p>n.T*n.V?(n.p-n.T*n.V)/2:0,e=n.g>n.D*n.V?(n.g-n.D*n.V)/2:0),n.Y=i,n.j=e},_t:function(t){var n=this;if(n.options.paging){var i=Math.max(Math.min(n.C,n.R),0),e=Math.max(Math.min(n.O,n.W),0),o=n.p,l=n.g;n.K=Math.floor(i/o)*o,n.N=Math.floor(e/l)*l,n.U=Math.ceil(i/o)*o,n.$=Math.ceil(e/l)*l}else n.K=0,n.N=0,n.U=n.R,n.$=n.W;var a=n.options.snapping?4:.001;n._=r((function(t,i,e){n.vt(e)}),(function(){var t=Math.abs(n.tt)>=a||Math.abs(n.nt)>=a;return t||(n.l=!0),t}),(function(t,i,e){n._=!1,n.l&&n.options.scrollingComplete(),n.scrollTo(n.C,n.O,n.options.snapping)}))},vt:function(t){var n=this,i=n.C+n.tt,e=n.O+n.nt;if(!n.options.bouncing){var o=Math.max(Math.min(n.U,i),n.K);o!==i&&(i=o,n.tt=0);var r=Math.max(Math.min(n.$,e),n.N);r!==e&&(e=r,n.nt=0)}if(t?n.et(i,e,n.V):(n.C=i,n.O=e),!n.options.paging){n.tt*=.95,n.nt*=.95}if(n.options.bouncing){var l=0,a=0,h=n.options.penetrationDeceleration,s=n.options.penetrationAcceleration;i<n.K?l=n.K-i:i>n.U&&(l=n.U-i),e<n.N?a=n.N-e:e>n.$&&(a=n.$-e),0!==l&&(l*n.tt<=0?n.tt+=l*h:n.tt=l*s),0!==a&&(a*n.nt<=0?n.nt+=a*h:n.nt=a*s)}}};export default s;
//# sourceMappingURL=index.es.js.map