forked from daniel-lundin/snabbt.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
snabbt.min.js
2 lines (2 loc) · 13.4 KB
/
snabbt.min.js
1
2
/*! snabbt.js v0.5.6 built: 2015-07-17 (c)2015 Daniel Lundin @license MIT */
!function(a,b){var c=b();"object"==typeof exports?module.exports=c:"function"==typeof define&&define.amd?define([],function(){return a.returnExportsGlobal=c}):a.snabbt=c}(this,function(){var a=[],b=[],c=[],d="transform",e=window.getComputedStyle(document.documentElement,""),f=(Array.prototype.slice.call(e).join("").match(/-(moz|webkit|ms)-/)||""===e.OLink&&["","o"])[1];"webkit"===f&&(d="webkitTransform");var g=function(a,b,c){var d=a;if(void 0!==d.length){for(var e={chainers:[],then:function(a){return console.log("DeprecationWarning: then() is renamed to snabbt()"),this.snabbt(a)},snabbt:function(a){var b=this.chainers.length;return this.chainers.forEach(function(c,d){c.snabbt(h(a,d,b))}),e},setValue:function(a){return this.chainers.forEach(function(b){b.setValue(a)}),e},finish:function(){return this.chainers.forEach(function(a){a.finish()}),e},rollback:function(){return this.chainers.forEach(function(a){a.rollback()}),e}},f=0,g=d.length;g>f;++f)e.chainers.push("string"==typeof b?i(d[f],b,h(c,f,g)):i(d[f],h(b,f,g),c));return e}return"string"==typeof b?i(d,b,h(c,0,1)):i(d,h(b,0,1),c)},h=function(a,b,c){if(!a)return a;var d=U(a);T(a.delay)&&(d.delay=a.delay(b,c)),T(a.callback)&&(console.log("DeprecationWarning: callback is renamed to complete"),d.complete=function(){a.callback.call(this,b,c)});var e=T(a.allDone),f=T(a.complete);(f||e)&&(d.complete=function(){f&&a.complete.call(this,b,c),e&&b==c-1&&a.allDone()}),T(a.valueFeeder)&&(d.valueFeeder=function(d,e){return a.valueFeeder(d,e,b,c)}),T(a.easing)&&(d.easing=function(d){return a.easing(d,b,c)});var g=["position","rotation","skew","rotationPost","scale","width","height","opacity","fromPosition","fromRotation","fromSkew","fromRotationPost","fromScale","fromWidth","fromHeight","fromOpacity","transformOrigin","duration","delay"];return g.forEach(function(e){T(a[e])&&(d[e]=a[e](b,c))}),d},i=function(a,c,d){function e(c){return r.tick(c),r.updateElement(a),r.isStopped()?void 0:r.completed()?void(f.loop>1&&!r.isStopped()?(f.loop-=1,r.restart(),s(e)):(f.complete&&f.complete.call(a),t.length&&(f=t.pop(),i=p(f,l,!0),l=p(f,U(l)),f=q(i,l,f),r=u(f),b.push([a,r]),r.tick(c),s(e)))):s(e)}if("attention"===c)return j(a,d);if("stop"===c)return k(a);var f=c;m();var g=o(a),i=g;i=p(f,i,!0);var l=U(g);l=p(f,l);var n=q(i,l,f),r=u(n);b.push([a,r]),r.updateElement(a,!0);var t=[],v={snabbt:function(a){return t.unshift(h(a,0,1)),v},then:function(a){return console.log("DeprecationWarning: then() is renamed to snabbt()"),this.snabbt(a)}};return s(e),f.manual?r:v},j=function(a,c){function d(b){f.tick(b),f.updateElement(a),f.completed()?(c.callback&&c.callback(a),c.loop&&c.loop>1&&(c.loop--,f.restart(),s(d))):s(d)}var e=p(c,N({}));c.movement=e;var f=v(c);b.push([a,f]),s(d)},k=function(a){for(var c=0,d=b.length;d>c;++c){var e=b[c],f=e[0],g=e[1];f===a&&g.stop()}},l=function(a,b){for(var c=0,d=a.length;d>c;++c){var e=a[c],f=e[0],g=e[1];if(f===b){var h=g.getCurrentState();return g.stop(),h}}},m=function(){c=c.filter(function(a){return n(a[0]).body})},n=function(a){for(var b=a;b.parentNode;)b=b.parentNode;return b},o=function(a){var d=l(b,a);return d?d:l(c,a)},p=function(a,b,c){b||(b=N({position:[0,0,0],rotation:[0,0,0],rotationPost:[0,0,0],scale:[1,1],skew:[0,0]}));var d="position",e="rotation",f="skew",g="rotationPost",h="scale",i="scalePost",j="width",k="height",l="opacity";return c&&(d="fromPosition",e="fromRotation",f="fromSkew",g="fromRotationPost",h="fromScale",i="fromScalePost",j="fromWidth",k="fromHeight",l="fromOpacity"),b.position=Q(a[d],b.position),b.rotation=Q(a[e],b.rotation),b.rotationPost=Q(a[g],b.rotationPost),b.skew=Q(a[f],b.skew),b.scale=Q(a[h],b.scale),b.scalePost=Q(a[i],b.scalePost),b.opacity=a[l],b.width=a[j],b.height=a[k],b},q=function(a,b,c){return c.startState=a,c.endState=b,c},r=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.msRequestAnimationFrame||function(a){return setTimeout(a,1e3/60)},s=function(b){0===a.length&&r(t),a.push(b)},t=function(d){for(var e=a.length,f=0;e>f;++f)a[f](d);a.splice(0,e);var g=b.filter(function(a){return a[1].completed()});c=c.filter(function(a){for(var b=0,c=g.length;c>b;++b)if(a[0]===g[b][0])return!1;return!0}),c=c.concat(g),b=b.filter(function(a){return!a[1].completed()}),0!==a.length&&r(t)},u=function(a){{var b=a.startState,c=a.endState,d=Q(a.duration,500),e=Q(a.delay,0),f=a.perspective,g=C(Q(a.easing,"linear"),a),h=0===d?c.clone():b.clone();a.transformOrigin}h.transformOrigin=a.transformOrigin;var i,j,k=0,l=0,m=!1,n=!1,o=a.manual,p=0,q=e/d;return j=a.valueFeeder?P(a.valueFeeder,b,c,h):O(b,c,h),{stop:function(){m=!0},isStopped:function(){return m},finish:function(a){o=!1;var b=d*p;k=l-b,i=a,g.resetFrom=p},rollback:function(a){o=!1,j.setReverse();var b=d*(1-p);k=l-b,i=a,g.resetFrom=p},restart:function(){k=void 0,g.resetFrom(0)},tick:function(a){if(!m){if(o)return l=a,void this.updateCurrentTransform();if(k||(k=a),a-k>e){n=!0,l=a-e;var b=Math.min(Math.max(0,l-k),d);g.tick(b/d),this.updateCurrentTransform(),this.completed()&&i&&i()}}},getCurrentState:function(){return h},setValue:function(a){n=!0,p=Math.min(Math.max(a,1e-4),1+q)},updateCurrentTransform:function(){var a=g.getValue();if(o){var b=Math.max(1e-5,p-q);g.tick(b),a=g.getValue()}j.tween(a)},completed:function(){return m?!0:0===k?!1:g.completed()},updateElement:function(a,b){if(n||b){var c=j.asMatrix(),d=j.getProperties();R(a,c,f),S(a,d)}}}},v=function(a){var b=a.movement;a.initialVelocity=.1,a.equilibriumPosition=0;var c=A(a),d=!1,e=b.position,f=b.rotation,g=b.rotationPost,h=b.scale,i=b.skew,j=N({position:e?[0,0,0]:void 0,rotation:f?[0,0,0]:void 0,rotationPost:g?[0,0,0]:void 0,scale:h?[0,0]:void 0,skew:i?[0,0]:void 0});return{stop:function(){d=!0},isStopped:function(){return d},tick:function(){d||c.equilibrium||(c.tick(),this.updateMovement())},updateMovement:function(){var a=c.getValue();e&&(j.position[0]=b.position[0]*a,j.position[1]=b.position[1]*a,j.position[2]=b.position[2]*a),f&&(j.rotation[0]=b.rotation[0]*a,j.rotation[1]=b.rotation[1]*a,j.rotation[2]=b.rotation[2]*a),g&&(j.rotationPost[0]=b.rotationPost[0]*a,j.rotationPost[1]=b.rotationPost[1]*a,j.rotationPost[2]=b.rotationPost[2]*a),h&&(j.scale[0]=1+b.scale[0]*a,j.scale[1]=1+b.scale[1]*a),i&&(j.skew[0]=b.skew[0]*a,j.skew[1]=b.skew[1]*a)},updateElement:function(a){R(a,j.asMatrix()),S(a,j.getProperties())},getCurrentState:function(){return j},completed:function(){return c.equilibrium||d},restart:function(){c=A(a)}}},w=function(a){return a},x=function(a){return(Math.cos(a*Math.PI+Math.PI)+1)/2},y=function(a){return a*a},z=function(a){return-Math.pow(a-1,2)+1},A=function(a){var b=Q(a.startPosition,0),c=Q(a.equilibriumPosition,1),d=Q(a.initialVelocity,0),e=Q(a.springConstant,.8),f=Q(a.springDeceleration,.9),g=Q(a.springMass,10),h=!1;return{tick:function(a){if(0!==a&&!h){var i=-(b-c)*e,j=i/g;d+=j,b+=d,d*=f,Math.abs(b-c)<.001&&Math.abs(d)<.001&&(h=!0)}},resetFrom:function(a){b=a,d=0},getValue:function(){return h?c:b},completed:function(){return h}}},B={linear:w,ease:x,easeIn:y,easeOut:z},C=function(a,b){if("spring"==a)return A(b);var c=a;T(a)||(c=B[a]);var d,e=c,f=0;return{tick:function(a){f=e(a),d=a},resetFrom:function(){d=0},getValue:function(){return f},completed:function(){return d>=1?d:!1}}},D=function(a,b,c,d){a[0]=1,a[1]=0,a[2]=0,a[3]=0,a[4]=0,a[5]=1,a[6]=0,a[7]=0,a[8]=0,a[9]=0,a[10]=1,a[11]=0,a[12]=b,a[13]=c,a[14]=d,a[15]=1},E=function(a,b){a[0]=1,a[1]=0,a[2]=0,a[3]=0,a[4]=0,a[5]=Math.cos(b),a[6]=-Math.sin(b),a[7]=0,a[8]=0,a[9]=Math.sin(b),a[10]=Math.cos(b),a[11]=0,a[12]=0,a[13]=0,a[14]=0,a[15]=1},F=function(a,b){a[0]=Math.cos(b),a[1]=0,a[2]=Math.sin(b),a[3]=0,a[4]=0,a[5]=1,a[6]=0,a[7]=0,a[8]=-Math.sin(b),a[9]=0,a[10]=Math.cos(b),a[11]=0,a[12]=0,a[13]=0,a[14]=0,a[15]=1},G=function(a,b){a[0]=Math.cos(b),a[1]=-Math.sin(b),a[2]=0,a[3]=0,a[4]=Math.sin(b),a[5]=Math.cos(b),a[6]=0,a[7]=0,a[8]=0,a[9]=0,a[10]=1,a[11]=0,a[12]=0,a[13]=0,a[14]=0,a[15]=1},H=function(a,b,c){a[0]=1,a[1]=Math.tan(b),a[2]=0,a[3]=0,a[4]=Math.tan(c),a[5]=1,a[6]=0,a[7]=0,a[8]=0,a[9]=0,a[10]=1,a[11]=0,a[12]=0,a[13]=0,a[14]=0,a[15]=1},I=function(a,b,c){a[0]=b,a[1]=0,a[2]=0,a[3]=0,a[4]=0,a[5]=c,a[6]=0,a[7]=0,a[8]=0,a[9]=0,a[10]=1,a[11]=0,a[12]=0,a[13]=0,a[14]=0,a[15]=1},J=function(a){a[0]=1,a[1]=0,a[2]=0,a[3]=0,a[4]=0,a[5]=1,a[6]=0,a[7]=0,a[8]=0,a[9]=0,a[10]=1,a[11]=0,a[12]=0,a[13]=0,a[14]=0,a[15]=1},K=function(a,b){b[0]=a[0],b[1]=a[1],b[2]=a[2],b[3]=a[3],b[4]=a[4],b[5]=a[5],b[6]=a[6],b[7]=a[7],b[8]=a[8],b[9]=a[9],b[10]=a[10],b[11]=a[11],b[12]=a[12],b[13]=a[13],b[14]=a[14],b[15]=a[15]},L=function(){var a=new Float32Array(16),b=new Float32Array(16),c=new Float32Array(16);return J(a),{data:a,asCSS:function(){for(var b="matrix3d(",c=0;15>c;++c)b+=Math.abs(a[c])<1e-4?"0,":a[c].toFixed(10)+",";return b+=Math.abs(a[15])<1e-4?"0)":a[15].toFixed(10)+")"},clear:function(){J(a)},translate:function(d,e,f){return K(a,b),D(c,d,e,f),M(b,c,a),this},rotateX:function(d){return K(a,b),E(c,d),M(b,c,a),this},rotateY:function(d){return K(a,b),F(c,d),M(b,c,a),this},rotateZ:function(d){return K(a,b),G(c,d),M(b,c,a),this},scale:function(d,e){return K(a,b),I(c,d,e),M(b,c,a),this},skew:function(d,e){return K(a,b),H(c,d,e),M(b,c,a),this}}},M=function(a,b,c){return c[0]=a[0]*b[0]+a[1]*b[4]+a[2]*b[8]+a[3]*b[12],c[1]=a[0]*b[1]+a[1]*b[5]+a[2]*b[9]+a[3]*b[13],c[2]=a[0]*b[2]+a[1]*b[6]+a[2]*b[10]+a[3]*b[14],c[3]=a[0]*b[3]+a[1]*b[7]+a[2]*b[11]+a[3]*b[15],c[4]=a[4]*b[0]+a[5]*b[4]+a[6]*b[8]+a[7]*b[12],c[5]=a[4]*b[1]+a[5]*b[5]+a[6]*b[9]+a[7]*b[13],c[6]=a[4]*b[2]+a[5]*b[6]+a[6]*b[10]+a[7]*b[14],c[7]=a[4]*b[3]+a[5]*b[7]+a[6]*b[11]+a[7]*b[15],c[8]=a[8]*b[0]+a[9]*b[4]+a[10]*b[8]+a[11]*b[12],c[9]=a[8]*b[1]+a[9]*b[5]+a[10]*b[9]+a[11]*b[13],c[10]=a[8]*b[2]+a[9]*b[6]+a[10]*b[10]+a[11]*b[14],c[11]=a[8]*b[3]+a[9]*b[7]+a[10]*b[11]+a[11]*b[15],c[12]=a[12]*b[0]+a[13]*b[4]+a[14]*b[8]+a[15]*b[12],c[13]=a[12]*b[1]+a[13]*b[5]+a[14]*b[9]+a[15]*b[13],c[14]=a[12]*b[2]+a[13]*b[6]+a[14]*b[10]+a[15]*b[14],c[15]=a[12]*b[3]+a[13]*b[7]+a[14]*b[11]+a[15]*b[15],c},N=function(a){var b=L(),c={opacity:void 0,width:void 0,height:void 0};return{position:a.position,rotation:a.rotation,rotationPost:a.rotationPost,skew:a.skew,scale:a.scale,scalePost:a.scalePost,opacity:a.opacity,width:a.width,height:a.height,clone:function(){return N({position:this.position?this.position.slice(0):void 0,rotation:this.rotation?this.rotation.slice(0):void 0,rotationPost:this.rotationPost?this.rotationPost.slice(0):void 0,skew:this.skew?this.skew.slice(0):void 0,scale:this.scale?this.scale.slice(0):void 0,scalePost:this.scalePost?this.scalePost.slice(0):void 0,height:this.height,width:this.width,opacity:this.opacity})},asMatrix:function(){var a=b;return a.clear(),this.transformOrigin&&a.translate(-this.transformOrigin[0],-this.transformOrigin[1],-this.transformOrigin[2]),this.scale&&a.scale(this.scale[0],this.scale[1]),this.skew&&a.skew(this.skew[0],this.skew[1]),this.rotation&&(a.rotateX(this.rotation[0]),a.rotateY(this.rotation[1]),a.rotateZ(this.rotation[2])),this.position&&a.translate(this.position[0],this.position[1],this.position[2]),this.rotationPost&&(a.rotateX(this.rotationPost[0]),a.rotateY(this.rotationPost[1]),a.rotateZ(this.rotationPost[2])),this.scalePost&&a.scale(this.scalePost[0],this.scalePost[1]),this.transformOrigin&&a.translate(this.transformOrigin[0],this.transformOrigin[1],this.transformOrigin[2]),a},getProperties:function(){return c.opacity=this.opacity,c.width=this.width+"px",c.height=this.height+"px",c}}},O=function(a,b,c){var d=a,e=b,f=c,g=void 0!==e.position,h=void 0!==e.rotation,i=void 0!==e.rotationPost,j=void 0!==e.scale,k=void 0!==e.skew,l=void 0!==e.width,m=void 0!==e.height,n=void 0!==e.opacity;return{tween:function(a){if(g){var b=e.position[0]-d.position[0],c=e.position[1]-d.position[1],o=e.position[2]-d.position[2];f.position[0]=d.position[0]+a*b,f.position[1]=d.position[1]+a*c,f.position[2]=d.position[2]+a*o}if(h){var p=e.rotation[0]-d.rotation[0],q=e.rotation[1]-d.rotation[1],r=e.rotation[2]-d.rotation[2];f.rotation[0]=d.rotation[0]+a*p,f.rotation[1]=d.rotation[1]+a*q,f.rotation[2]=d.rotation[2]+a*r}if(i){var s=e.rotationPost[0]-d.rotationPost[0],t=e.rotationPost[1]-d.rotationPost[1],u=e.rotationPost[2]-d.rotationPost[2];f.rotationPost[0]=d.rotationPost[0]+a*s,f.rotationPost[1]=d.rotationPost[1]+a*t,f.rotationPost[2]=d.rotationPost[2]+a*u}if(k){var v=e.scale[0]-d.scale[0],w=e.scale[1]-d.scale[1];f.scale[0]=d.scale[0]+a*v,f.scale[1]=d.scale[1]+a*w}if(j){var x=e.skew[0]-d.skew[0],y=e.skew[1]-d.skew[1];f.skew[0]=d.skew[0]+a*x,f.skew[1]=d.skew[1]+a*y}if(l){var z=e.width-d.width;f.width=d.width+a*z}if(m){var A=e.height-d.height;f.height=d.height+a*A}if(n){var B=e.opacity-d.opacity;f.opacity=d.opacity+a*B}},asMatrix:function(){return f.asMatrix()},getProperties:function(){return f.getProperties()},setReverse:function(){var a=d;d=e,e=a}}},P=function(a,b,c,d){var e=a(0,L()),f=b,g=c,h=d,i=!1;return{tween:function(b){i&&(b=1-b),e.clear(),e=a(b,e);var c=g.width-f.width,d=g.height-f.height,j=g.opacity-f.opacity;void 0!==g.width&&(h.width=f.width+b*c),void 0!==g.height&&(h.height=f.height+b*d),void 0!==g.opacity&&(h.opacity=f.opacity+b*j)},asMatrix:function(){return e},getProperties:function(){return h.getProperties()},setReverse:function(){i=!0}}},Q=function(a,b){return"undefined"==typeof a?b:a},R=function(a,b,c){var e="";c&&(e="perspective("+c+"px) ");var f=b.asCSS();a.style[d]=e+f},S=function(a,b){for(var c in b)a.style[c]=b[c]},T=function(a){return"function"==typeof a},U=function(a){if(!a)return a;var b={};for(var c in a)b[c]=a[c];return b};return window.jQuery&&!function(a){a.fn.snabbt=function(a,b){return g(this.get(),a,b)}}(jQuery),g.createMatrix=L,g.setElementTransform=R,g});