-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathkeyframe.min.js
1 lines (1 loc) · 4.25 KB
/
keyframe.min.js
1
!function(t,n){"use strict";"function"==typeof define&&define.amd?define(n):"object"==typeof exports?module.exports=n():t.Keyframe=n()}(this,function(){"use strict";function t(t){return t[0].toUpperCase()+t.substr(1)}function n(t){return t.replace(/^(webkit|moz|ms|o)([A-Z])/,"-$1$2").replace(/([A-Z])/g,"-$1").toLowerCase()}function e(n,e,r){return r&&"moz"!==r?r+t(n)+t(e):n+e.toLowerCase()}function r(t){return t.replace(/(-[a-z])/gi,function(t){return t[1].toUpperCase()})}function o(n,e){return e?e+t(n):n}function i(t,n){var e,i;if(n=r(n),!k.hasOwnProperty(n))for(e=0;e<w.length;e++)if(i=o(n,w[e]),i in t.style){k[n]=i;break}return k[n]}function u(t){return"number"==typeof t?t+"px":t}function a(t,n){return/(delay|duration)$/.test(t)&&(n+="ms"),n}function s(n){return function(e,r,o){"number"==typeof o&&(o=a(r,o)),e.style[i(e,n+t(r))]=o||""}}function f(t){var e=[];for(var r in t)t.hasOwnProperty(r)&&e.push(n(i(O,r)));return e}function c(t,n){if(t)for(var e in n)n.hasOwnProperty(e)&&!t.hasOwnProperty(e)&&(t[e]=n[e]);else t=n;return t}function p(t,n,r,o){t.addEventListener(e(n,r,b),o,!1)}function h(t,n,r,o){t.removeEventListener(e(n,r,b),o,!1)}function d(t){var e,r,o;if(!j)throw new Error("animations not supported");this.keyframeId=++$,e="@"+(b?"-"+b+"-":"")+"keyframes keyframejs"+this.keyframeId+"{";for(r in t)if(t.hasOwnProperty(r)){e+=(/^\d+$/.test(r)?r+"%":r)+"{";for(o in t[r])t[r].hasOwnProperty(o)&&(e+=n(i(O,o))+":"+u(t[r][o])+";");e+="}"}e+="}",E.parentNode||(E.type="text/css",document.getElementsByTagName("head")[0].appendChild(E)),this.style=document.createTextNode(e),E.appendChild(this.style)}function m(t,n,e){this.node=t,this.animation=e,this.keyframeId=n.keyframeId}function y(t,n,e,r,o){function a(n){for(var e in n)n.hasOwnProperty(e)&&(t.style[i(t,e)]=u(n[e]))}function s(n,e){x(t,"property",f(n).join(","));for(var r in e)e.hasOwnProperty(r)&&x(t,r,e[r])}var c,d=e;return c=C?function(){function i(n){n.target===t&&n.propertyName&&-1!==A.call(u,n.propertyName)&&(c.cancel&&c.cancel(),"function"==typeof r&&r.apply(this,arguments))}var u=f(n);c.cancel=function(n,e){c.cancel=null,h(t,g,"end",i);for(var r=f(n),a=[],s=0;s<u.length;s++)-1!==A.call(r,u[s])&&a.push(u[s]);x(t,"property",a.join(","));for(var p in d)d.hasOwnProperty(p)&&x(t,p,e?e[p]:"");"function"==typeof o&&n&&e&&o.apply(this,arguments)},s(n,e),a(n),p(t,g,"end",i)}:function(){a(n),"function"==typeof r&&r()}}function l(t,n){this.node=t,this.opts=n||{},this.queue=[],this.current=null}var w=["","webkit","moz","ms","o"],v="animation",g="transition",k={},O=document.createElement("div"),P=i(O,v)||"",b=P.replace(/(.*)animation/i,"$1"),q=s(v),C=i(O,g)||"",x=s(g),E=document.createElement("style"),$=0,j=!!P,z=function(){return window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||function(t){window.setTimeout(t,0)}}(),A=[].indexOf||function(t){for(var n=0,e=this.length;e>n;n++)if(n in this&&this[n]===t)return n;return-1};return d.prototype.remove=function(){E.removeChild(this.style)},d.prototype.animate=function(t,n){return new m(t,this,n)},m.prototype.start=function(t,n,e){var r,o=this,i=function(){u(),"function"==typeof t&&t.apply(this,arguments)},u=function(){var t;h(o.node,v,"end",i),h(o.node,v,"iteration",e),h(o.node,v,"start",n),q(o.node,"name","");for(t in o.animation)o.animation.hasOwnProperty(t)&&q(o.node,t,"");o.node.offsetHeight};p(o.node,v,"end",i),p(o.node,v,"iteration",e),p(o.node,v,"start",n),q(o.node,"name","keyframejs"+o.keyframeId);for(r in o.animation)o.animation.hasOwnProperty(r)&&q(o.node,r,o.animation[r]);return o.node.offsetHeight,{stop:u,pause:function(){q(o.node,"playState","paused")},resume:function(){q(o.node,"playState","running")}}},l.prototype.to=function(t,n,e,r){return"function"==typeof n&&(r=e,e=n,n=null),n=c(n,this.opts),this.current&&this.current.cancel&&this.current.cancel(t,n),this.queue.length=0,this.then(t,n,e,r),this.current=this.queue.shift(),this.node.offsetHeight,this.current(),this},l.prototype.then=function(t,n,e,r){var o=this;return"function"==typeof n&&(r=e,e=n,n=null),n=c(n,this.opts),this.queue.push(y(this.node,t,n,function(){o.current=o.queue.shift(),o.current&&z(o.current),"function"==typeof e&&e.apply(this,arguments)},r)),this},{isSupported:j,keyframe:function(t){return new d(t)},transition:function(t,n){return new l(t,n)}}});