forked from ded/morpheus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
morpheus.min.js
6 lines (6 loc) · 5.27 KB
/
morpheus.min.js
1
2
3
4
5
6
/*!
* Morpheus - A Brilliant Animator
* https://github.com/ded/morpheus - (c) Dustin Diaz 2011
* License MIT
*/
!function(e,t){typeof define=="function"?define(t):typeof module!="undefined"?module.exports=t():this[e]=t()}("morpheus",function(){function E(e,t,n){if(Array.prototype.indexOf)return e.indexOf(t);for(n=0;n<e.length;++n)if(e[n]===t)return n}function S(e){var t,n=w.length;s&&(e=i());for(t=n;t--;)w[t](e);w.length&&b(S)}function x(e){w.push(e)===1&&b(S)}function T(e){var t,n=E(w,e);n>=0&&(t=w.slice(n+1),w.length=n,w=w.concat(t))}function N(e,t){var n={},r;if(r=e.match(c))n.rotate=B(r[1],t?t.rotate:null);if(r=e.match(h))n.scale=B(r[1],t?t.scale:null);if(r=e.match(p))n.skewx=B(r[1],t?t.skewx:null),n.skewy=B(r[3],t?t.skewy:null);if(r=e.match(d))n.translatex=B(r[1],t?t.translatex:null),n.translatey=B(r[3],t?t.translatey:null);return n}function C(e){var t="";return"rotate"in e&&(t+="rotate("+e.rotate+"deg) "),"scale"in e&&(t+="scale("+e.scale+") "),"translatex"in e&&(t+="translate("+e.translatex+"px,"+e.translatey+"px) "),"skewx"in e&&(t+="skew("+e.skewx+"deg,"+e.skewy+"deg)"),t}function k(e,t,n){return"#"+(1<<24|e<<16|t<<8|n).toString(16).slice(1)}function L(e){var t=e.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)/);return(t?k(t[1],t[2],t[3]):e).replace(/#(\w)(\w)(\w)$/,"#$1$1$2$2$3$3")}function A(e){return e.replace(/-(.)/g,function(e,t){return t.toUpperCase()})}function O(e){return typeof e=="function"}function M(e){return Math.sin(e*Math.PI/2)}function _(e,t,n,r,s,o){function d(e){var i=e-c;if(i>a||h)return o=isFinite(o)?o:1,h?p&&t(o):t(o),T(d),n&&n.apply(f);isFinite(o)?t(l*r(i/a)+s):t(r(i/a))}r=O(r)?r:j.easings[r]||M;var a=e||u,f=this,l=o-s,c=i(),h=0,p=0;return x(d),{stop:function(e){h=1,p=e,e||(n=null)}}}function D(e,t){var n=e.length,r=[],i,s;for(i=0;i<n;++i)r[i]=[e[i][0],e[i][1]];for(s=1;s<n;++s)for(i=0;i<n-s;++i)r[i][0]=(1-t)*r[i][0]+t*r[parseInt(i+1,10)][0],r[i][1]=(1-t)*r[i][1]+t*r[parseInt(i+1,10)][1];return[r[0][0],r[0][1]]}function P(e,t,n){var r=[],i,s,o,u;for(i=0;i<6;i++)o=Math.min(15,parseInt(t.charAt(i),16)),u=Math.min(15,parseInt(n.charAt(i),16)),s=Math.floor((u-o)*e+o),s=s>15?15:s<0?0:s,r[i]=s.toString(16);return"#"+r.join("")}function H(e,t,n,r,i,s,o){if(i=="transform"){o={};for(var a in n[s][i])o[a]=a in r[s][i]?Math.round(((r[s][i][a]-n[s][i][a])*e+n[s][i][a])*u)/u:n[s][i][a];return o}return typeof n[s][i]=="string"?P(e,n[s][i],r[s][i]):(o=Math.round(((r[s][i]-n[s][i])*e+n[s][i])*u)/u,i in v||(o+=t[s][i]||"px"),o)}function B(e,t,n,r,i){return(n=f.exec(e))?(i=parseFloat(n[2]))&&t+(n[1]=="+"?1:-1)*i:parseFloat(e)}function j(e,t){var n=e?n=isFinite(e.length)?e:[e]:[],r,i=t.complete,s=t.duration,o=t.easing,u=t.bezier,f=[],c=[],h=[],p=[],d,v;u&&(d=t.left,v=t.top,delete t.right,delete t.bottom,delete t.left,delete t.top);for(r=n.length;r--;){f[r]={},c[r]={},h[r]={};if(u){var b=y(n[r],"left"),w=y(n[r],"top"),E=[B(O(d)?d(n[r]):d||0,parseFloat(b)),B(O(v)?v(n[r]):v||0,parseFloat(w))];p[r]=O(u)?u(n[r],E):u,p[r].push(E),p[r].unshift([parseInt(b,10),parseInt(w,10)])}for(var S in t){switch(S){case"complete":case"duration":case"easing":case"bezier":continue}var x=y(n[r],S),T,k=O(t[S])?t[S](n[r]):t[S];if(typeof k=="string"&&a.test(k)&&!a.test(x)){delete t[S];continue}f[r][S]=S=="transform"?N(x):typeof k=="string"&&a.test(k)?L(x).slice(1):parseFloat(x),c[r][S]=S=="transform"?N(k,f[r][S]):typeof k=="string"&&k.charAt(0)=="#"?L(k).slice(1):B(k,parseFloat(x)),typeof k=="string"&&(T=k.match(l))&&(h[r][S]=T[1])}}return _.apply(n,[s,function(e,i,s){for(r=n.length;r--;){u&&(s=D(p[r],e),n[r].style.left=s[0]+"px",n[r].style.top=s[1]+"px");for(var o in t)i=H(e,h,f,c,o,r),o=="transform"?n[r].style[m]=C(i):o=="opacity"&&!g?n[r].style.filter="alpha(opacity="+i*100+")":n[r].style[A(o)]=i}},i,o])}var e=document,t=window,n=t.performance,r=n&&(n.now||n.webkitNow||n.msNow||n.mozNow),i=r?function(){return r.call(n)}:function(){return+(new Date)},s=!1,o=e.documentElement,u=1e3,a=/^rgb\(|#/,f=/^([+\-])=([\d\.]+)/,l=/^(?:[\+\-]=?)?\d+(?:\.\d+)?(%|in|cm|mm|em|ex|pt|pc|px)$/,c=/rotate\(((?:[+\-]=)?([\-\d\.]+))deg\)/,h=/scale\(((?:[+\-]=)?([\d\.]+))\)/,p=/skew\(((?:[+\-]=)?([\-\d\.]+))deg, ?((?:[+\-]=)?([\-\d\.]+))deg\)/,d=/translate\(((?:[+\-]=)?([\-\d\.]+))px, ?((?:[+\-]=)?([\-\d\.]+))px\)/,v={lineHeight:1,zoom:1,zIndex:1,opacity:1,transform:1},m=function(){var t=e.createElement("a").style,n=["webkitTransform","MozTransform","OTransform","msTransform","Transform"],r;for(r=0;r<n.length;r++)if(n[r]in t)return n[r]}(),g=function(){return typeof e.createElement("a").style.opacity!="undefined"}(),y=e.defaultView&&e.defaultView.getComputedStyle?function(t,n){n=n=="transform"?m:n,n=A(n);var r=null,i=e.defaultView.getComputedStyle(t,"");return i&&(r=i[n]),t.style[n]||r}:o.currentStyle?function(e,t){t=A(t);if(t=="opacity"){var n=100;try{n=e.filters["DXImageTransform.Microsoft.Alpha"].opacity}catch(r){try{n=e.filters("alpha").opacity}catch(i){}}return n/100}var s=e.currentStyle?e.currentStyle[t]:null;return e.style[t]||s}:function(e,t){return e.style[A(t)]},b=function(){return t.requestAnimationFrame||t.webkitRequestAnimationFrame||t.mozRequestAnimationFrame||t.msRequestAnimationFrame||t.oRequestAnimationFrame||function(e){t.setTimeout(function(){e(+(new Date))},17)}}();b(function(e){s=e>1e12!=i()>1e12});var w=[];return j.tween=_,j.getStyle=y,j.bezier=D,j.transform=m,j.parseTransform=N,j.formatTransform=C,j.easings={},j})