UNPKG

just-animate

Version:
45 lines (44 loc) 4.18 kB
!function(){"use strict" function W(e){return!!e||0===e||!1===e}var _=void 0,n=/^([+|-]*[0-9]*[.]*?[0-9]+)([a-z%]+)*$/i,s=Math.abs function e(e){return e.split(",")}var v="running",x="px",k="deg",t="translate",z="transform",B=e("rotateX,rotateY,rotateZ,rotate"),r=e("scaleX,scaleY,scaleZ,scale"),L=e("perspective,x,y,z"),G=B.concat(r,L),j={x:t+"X",y:t+"Y",z:t+"Z"},o=e("backgroundSize,border,borderBottom,borderBottomLeftRadius,borderBottomRightRadius,borderBottomWidth,borderLeft,borderLeftWidth,borderRadius,borderRight,borderRightWidth,borderTop,borderTopLeftRadius,borderTopRightRadius,borderTopWidth,borderWidth,bottom,columnGap,columnRuleWidth,columnWidth,columns,flexBasis,font,fontSize,gridColumnGap,gridGap,gridRowGap,height,left,letterSpacing,lineHeight,margin,marginBottom,marginLeft,marginRight,marginTop,maskSize,maxHeight,maxWidth,minHeight,minWidth,outline,outlineOffset,outlineWidth,padding,paddingBottom,paddingLeft,paddingRight,paddingTop,perspective,right,shapeMargin,tabSize,top,width,wordSpacing") var d=17 function H(e,t){return-1!==(r=t,e.indexOf(r)) var r}function i(e){return W(e)?(t=e)&&isFinite(t.length)&&"string"!=typeof t&&"function"!=typeof t?e:[e]:[] var t}function N(e,t){var r,n return H(e,t)||(r=e,(n=t)!==_&&Array.prototype.push.call(r,n)),t}function X(e,t){for(var r=i(e),n=0,a=r.length;n<a;n++)t(r[n],n,a)}function Y(e){var t={unit:_,value:_} if(!W(e))return t if(Number(e))return t.value=+e,t var r=n.exec(e) return r&&(t.unit=r[2]||_,t.value=r[1]?parseFloat(r[1]):_),t}function a(e,a,t){var i=e.propNames.filter(function(e){return H(G,e)}) if(i.length){if(H(e.propNames,z))throw new Error("transform + shorthand is not allowed") var r=[],o={} X(i,function(e){var t=a[e] t&&X(t,function(e){o[e.offset]=e.easing,N(r,e.offset)})}),r.sort() for(var n=r.map(function(r){var n={} return X(i,function(e){var t=function(e,t,r){var n=e&&e.length if(!n)return _ if(t===_)return e[r?n-1:0] if(r){for(var a=n-1;-1<a;a--)if(t(e[a]))return e[a]}else for(a=0;a<n;a++)if(t(e[a]))return e[a] return _}(a[e],function(e){return e.offset===r}) n[e]=t?t.value:_}),{offset:r,easing:o[r],values:n}}),u=n.length,f=u-1;-1<f;--f){var l=n[f] for(var s in l.values){if(!W(l.values[s])){for(var v=_,d=f-1;-1<d;d--)if(W(n[d].values[s])){v=d break}for(var p=_,c=f+1;c<u;c++)if(W(n[c].values[s])){p=c break}var g=v!==_ if(g&&p!==_)for(var m=n[v],h=n[p],b=Y(m.values[s]),y=Y(h.values[s]),R=v+1;R<p;R++){var w=(r[R]-m.offset)/(h.offset-m.offset),S=b.value+(y.value-b.value)*w+(y.unit||b.unit||"") n[R].values[s]=S}else if(g)for(R=v+1;R<u;R++)n[R].values[s]=n[v].values[s]}}}if(n.length){X(i,function(e){a[e]=_}) var T=[] X(n,function(e){var t=_ for(var r in e.values){var n=Y(e.values[r]) n.value!==_&&(n.unit||(n.unit=H(L,r)?x:H(B,r)?k:""),t=(t?t+" ":"")+(j[r]||r)+"("+n.value+n.unit+")")}T.push({offset:e.offset,value:t,easing:e.easing,interpolate:_})}),a[z]=T,t[z]="web"}}}var u={name:"web",animate:function(e){var f,l,r=e.keyframes,i=e.prop,t=e.from,n=e.to,a=e.target,o=n-t,u=(f=function(){var e=r.map(function(e){var t,r=e.offset,n=e.value,a=e.easing return(t={offset:r})[i]=n,t.easing=a,t}),t=a.animate(e,{duration:o,fill:"both"}) return t.pause(),t},l=[],function(){for(var e=arguments,t=0,r=l.length;t<r;t++){var n=l[t].args,a=e.length if(n.length===a){for(var i=0,o=0;o<a&&n[o]===e[o];o++)++i if(i===a)return l[t].value}}var u=f.apply(_,e) return l.push({args:e,value:u}),u}) return{cancel:function(){u().cancel()},update:function(e,t,r){var n=u(),a=o*e if(1<s(n.currentTime-a)&&(n.currentTime=a),r&&n.playbackRate!==t){var i=n.currentTime i<1?n.currentTime=1:i<o-1||(n.currentTime=o-1),n.playbackRate=t}r&&!(n.playState===v||"finish"===n.playState)&&!(t<0&&a<d)&&!(0<=t&&o-d<a)&&n.play(),!r&&(n.playState===v||"pending"===n.playState)&&n.pause()}}},getValue:function(e,t){return getComputedStyle(e)[t]},onWillAnimate:function(e,t,r){var n;((n=e.target).nodeType||n instanceof SVGElement)&&(!function(e){for(var t in e)if(H(o,t)){var r=e[t] for(var n in r){var a=r[n] if(W(a)){var i=a.value "number"==typeof i&&(a.value+=x)}}}}(t),a(e,t,r))}} "undefined"!=typeof window&&"undefined"!=typeof window.just?window.just.addPlugin(u):require("just-animate").addPlugin(u)}()