diff --git a/packages/animate/@types/api.d.ts b/packages/animate/@types/api.d.ts index 82450ef..27bb911 100644 --- a/packages/animate/@types/api.d.ts +++ b/packages/animate/@types/api.d.ts @@ -370,6 +370,7 @@ export declare class Animate { oldCSSProperties: any; onfinish: any; oncancel: any; + timeline?: any; }, len: number): void; /** * Update the options for all targets diff --git a/packages/animate/lib/api.cjs.js b/packages/animate/lib/api.cjs.js index 6e91976..31d77d7 100644 --- a/packages/animate/lib/api.cjs.js +++ b/packages/animate/lib/api.cjs.js @@ -1 +1 @@ -var ee=Object.defineProperty;var ue=i=>ee(i,"__esModule",{value:!0});var ce=(i,e)=>{for(var t in e)ee(i,t,{get:e[t],enumerable:!0})};ue(exports);ce(exports,{Animate:()=>z,CSSArrValue:()=>L,CSSValue:()=>j,DefaultAnimationOptions:()=>le,EASINGS:()=>R,EFFECTS:()=>fe,EasingKeys:()=>oe,GetEase:()=>J,KeyframeParse:()=>_,ParseTransformableCSSKeyframes:()=>$,ParseTransformableCSSProperties:()=>G,TransformFunctionNames:()=>U,UnitDEG:()=>F,UnitDEGCSSValue:()=>A,UnitLess:()=>V,UnitLessCSSValue:()=>O,UnitPX:()=>X,UnitPXCSSValue:()=>C,addCSSUnit:()=>H,animate:()=>me,computeOption:()=>ae,createTransformProperty:()=>Z,default:()=>ye,flatten:()=>re,getElements:()=>se,getTargets:()=>q,isValid:()=>k,mapAnimationOptions:()=>B,mapObject:()=>D,omit:()=>v,parseOffset:()=>w,parseOptions:()=>pe,toArr:()=>Y,transpose:()=>ne});var M=class{constructor(e){this.map=new Map(e)}getMap(){return this.map}get(e){return this.map.get(e)}keys(){return Array.from(this.map.keys())}values(){return Array.from(this.map.values())}set(e,t){return this.map.set(e,t),this}add(e){let n=this.size;return this.set(n,e),this}get size(){return this.map.size}get length(){return this.map.size}last(e=1){let t=this.keys()[this.size-e];return this.get(t)}delete(e){return this.map.delete(e)}remove(e){return this.map.delete(e),this}clear(){return this.map.clear(),this}has(e){return this.map.has(e)}entries(){return this.map.entries()}forEach(e,t){return this.map.forEach(e,t),this}[Symbol.iterator](){return this.entries()}},te=(i,e,...t)=>{i.forEach(n=>{n[e](...t)})};var ie=({callback:i=()=>{},scope:e=null,name:t="event"})=>({callback:i,scope:e,name:t}),I=class extends M{constructor(e="event"){super();this.name=e}},W=class extends M{constructor(){super()}getEvent(e){let t=this.get(e);return t instanceof I?t:(this.set(e,new I(e)),this.get(e))}newListener(e,t,n){let s=this.getEvent(e);return s.add(ie({name:e,callback:t,scope:n})),s}on(e,t,n){if(typeof e=="undefined"||e==null)return this;typeof e=="string"&&(e=e.trim().split(/\s/g));let s,r,a=typeof e=="object"&&!Array.isArray(e),o=a?t:n;return a||(r=t),Object.keys(e).forEach(l=>{s=a?l:e[l],a&&(r=e[l]),this.newListener(s,r,o)},this),this}removeListener(e,t,n){let s=this.get(e);if(s instanceof I&&t){let r=ie({name:e,callback:t,scope:n});s.forEach((a,o)=>{if(a.callback===r.callback&&a.scope===r.scope)return s.remove(o)})}return s}off(e,t,n){if(typeof e=="undefined"||e==null)return this;typeof e=="string"&&(e=e.trim().split(/\s/g));let s,r,a=typeof e=="object"&&!Array.isArray(e),o=a?t:n;return a||(r=t),Object.keys(e).forEach(l=>{s=a?l:e[l],a&&(r=e[l]),typeof r=="function"?this.removeListener(s,r,o):this.remove(s)},this),this}once(e,t,n){if(typeof e=="undefined"||e==null)return this;typeof e=="string"&&(e=e.trim().split(/\s/g));let s=typeof e=="object"&&!Array.isArray(e);return Object.keys(e).forEach(r=>{let a=s?r:e[r],o=s?e[r]:t,l=s?t:n,p=(...y)=>{o.apply(l,y),this.removeListener(a,p,l)};this.newListener(a,p,l)},this),this}emit(e,...t){return typeof e=="undefined"||e==null?this:(typeof e=="string"&&(e=e.trim().split(/\s/g)),e.forEach(n=>{let s=this.get(n);s instanceof I&&s.forEach(r=>{let{callback:a,scope:o}=r;a.apply(o,t)})},this),this)}clear(){return te(this,"clear"),super.clear(),this}};var w=i=>typeof i=="string"?i.includes("%")?parseFloat(i)/100:i=="from"?0:i=="to"?1:parseFloat(i):i,_=i=>{let e=new Set,t=Object.keys(i),n=t.length;for(let s=0;ss.offset-r.offset)},fe={};var H=(i="")=>e=>typeof e=="string"?e:`${e}${i}`,V=H(),X=H("px"),F=H("deg"),Y=i=>Array.isArray(i)||typeof i=="string"?(typeof i=="string"&&(i=i.split(",")),i):[i],k=i=>Array.isArray(i)||typeof i=="string"?Boolean(i.length):i!=null&&i!=null,j=i=>e=>k(e)?Y(e).map(t=>{if(typeof t!="number"&&typeof t!="string")return t;let n=Number(t),s=Number.isNaN(n)?typeof t=="string"?t.trim():t:n;return i(s)}):[],ne=(...i)=>{let e=0;i=i.map(s=>{let r=Y(s),a=r.length;return a>e&&(e=a),r});let t=[],n=i.length;for(let s=0;sY(i).map(j(e)),U=["translate","translate3d","translateX","translateY","translateZ","rotate","rotate3d","rotateX","rotateY","rotateZ","scale","scale3d","scaleX","scaleY","scaleZ","skew","skewX","skewY","perspective"],Z=i=>{let e="",t=U.length;for(let n=0;n{let{perspective:e,rotate:t,rotate3d:n,rotateX:s,rotateY:r,rotateZ:a,translate:o,translate3d:l,translateX:p,translateY:y,translateZ:h,scale:b,scale3d:u,scaleX:c,scaleY:m,scaleZ:f,skew:T,skewX:g,skewY:S,...d}=i;o=L(o,X),l=L(l,X),p=C(p),y=C(y),h=C(h),t=L(t,F),n=L(n,V),s=A(s),r=A(r),a=A(a),b=L(b,V),u=L(u,V),c=O(c),m=O(m),f=O(f),T=L(T,F),g=A(g),S=A(S),e=C(e);let E=ne(o,l,p,y,h,t,n,s,r,a,b,u,c,m,f,T,g,S,e).map(Z);return d=D(d,K=>[].concat(K).map(P=>""+P)),Object.assign({},k(E)?{transform:E}:null,d)},$=i=>i.map(e=>{let{translate:t,translate3d:n,translateX:s,translateY:r,translateZ:a,rotate:o,rotate3d:l,rotateX:p,rotateY:y,rotateZ:h,scale:b,scale3d:u,scaleX:c,scaleY:m,scaleZ:f,skew:T,skewX:g,skewY:S,perspective:d,easing:E,iterations:K,offset:P,...x}=e;return t=C(t),n=C(n),s=C(s)[0],r=C(r)[0],a=C(a)[0],o=A(o),l=O(l),p=A(p)[0],y=A(y)[0],h=A(h)[0],b=O(b),u=O(u),c=O(c)[0],m=O(m)[0],f=O(f)[0],T=A(T),g=A(g)[0],S=A(S)[0],d=C(d)[0],[x,t,n,s,r,a,o,l,p,y,h,b,u,c,m,f,T,g,S,d]}).map(([e,...t])=>{let n=Z(t);return Object.assign({},k(n)?{transform:n}:null,e)});var se=i=>typeof i=="string"?Array.from(document.querySelectorAll(i)):[i],re=i=>[].concat(...i),q=i=>Array.isArray(i)?re(i.map(q)):typeof i=="string"||i instanceof Node?se(i):i instanceof NodeList||i instanceof HTMLCollection?Array.from(i):[],ae=(i,e,t)=>typeof i=="function"?i.apply(t,e):i,D=(i,e)=>{let t=Object.keys(i),n,s,r={};for(let a=0,o=t.length;aD(i,n=>ae(n,e,t)),R={in:"ease-in",out:"ease-out","in-out":"ease-in-out","in-sine":"cubic-bezier(0.47, 0, 0.745, 0.715)","out-sine":"cubic-bezier(0.39, 0.575, 0.565, 1)","in-out-sine":"cubic-bezier(0.445, 0.05, 0.55, 0.95)","in-quad":"cubic-bezier(0.55, 0.085, 0.68, 0.53)","out-quad":"cubic-bezier(0.25, 0.46, 0.45, 0.94)","in-out-quad":"cubic-bezier(0.455, 0.03, 0.515, 0.955)","in-cubic":"cubic-bezier(0.55, 0.055, 0.675, 0.19)","out-cubic":"cubic-bezier(0.215, 0.61, 0.355, 1)","in-out-cubic":"cubic-bezier(0.645, 0.045, 0.355, 1)","in-quart":"cubic-bezier(0.895, 0.03, 0.685, 0.22)","out-quart":"cubic-bezier(0.165, 0.84, 0.44, 1)","in-out-quart":"cubic-bezier(0.77, 0, 0.175, 1)","in-quint":"cubic-bezier(0.755, 0.05, 0.855, 0.06)","out-quint":"cubic-bezier(0.23, 1, 0.32, 1)","in-out-quint":"cubic-bezier(0.86, 0, 0.07, 1)","in-expo":"cubic-bezier(0.95, 0.05, 0.795, 0.035)","out-expo":"cubic-bezier(0.19, 1, 0.22, 1)","in-out-expo":"cubic-bezier(1, 0, 0, 1)","in-circ":"cubic-bezier(0.6, 0.04, 0.98, 0.335)","out-circ":"cubic-bezier(0.075, 0.82, 0.165, 1)","in-out-circ":"cubic-bezier(0.785, 0.135, 0.15, 0.86)","in-back":"cubic-bezier(0.6, -0.28, 0.735, 0.045)","out-back":"cubic-bezier(0.175, 0.885, 0.32, 1.275)","in-out-back":"cubic-bezier(0.68, -0.55, 0.265, 1.55)"},oe=Object.keys(R),J=i=>{let e=i.replace(/^ease-/,"");return oe.includes(e)?R[e]:i},le={keyframes:[],offset:[],loop:1,delay:0,speed:1,endDelay:0,easing:"ease",timelineOffset:0,autoplay:!0,duration:1e3,fillMode:"none",direction:"normal",padEndDelay:!1,extend:{}},pe=i=>{let{options:e,...t}=i,n=e instanceof z?e.options:Array.isArray(e)?e?.[0]?.options:e;return Object.assign({},n,t)},v=(i,e)=>{let t={...e};for(;i.length;){let{[i.pop()]:n,...s}=t;t=s}return t},Q=class{constructor(e){this.options={};this.properties={};this.totalDuration=0;this.emitter=new W;this.targets=new M;this.targetIndexes=new WeakMap;this.keyframeEffects=new WeakMap;this.computedOptions=new WeakMap;this.animations=new WeakMap;this.computedKeyframes=new WeakMap;this.loop=this.loop.bind(this),this.onVisibilityChange=this.onVisibilityChange.bind(this),this.on("error",t=>console.error(t)),this.updateOptions(e),this.visibilityPlayState=this.getPlayState(),Q.pauseOnPageHidden&&document.addEventListener("visibilitychange",this.onVisibilityChange,!1),this.newPromise()}onVisibilityChange(){document.hidden?(this.visibilityPlayState=this.getPlayState(),this.is("running")&&(this.loop(),this.pause())):this.visibilityPlayState=="running"&&this.is("paused")&&this.play()}newPromise(){return this.promise=new Promise((e,t)=>{this?.emitter?.once?.("finish",()=>e([this])),this?.emitter?.once?.("error",n=>t(n))}),this.promise}then(e,t){return e=e?.bind(this),t=t?.bind(this),this?.promise?.then?.(e,t),this}catch(e){return e=e?.bind(this),this.promise?.catch?.(e),this}finally(e){return e=e?.bind(this),this.promise?.finally?.(e),this}loop(){this.stopLoop(),this.animationFrame=window.requestAnimationFrame(this.loop),this.emit("update",this.getProgress(),this)}stopLoop(){window.cancelAnimationFrame(this.animationFrame)}allAnimations(e){return this.targets.forEach(t=>{let n=this.keyframeEffects.get(t),s=this.animations.get(n);return e(s,t)}),this}all(e){return this.mainAnimation&&e(this.mainAnimation,this.mainElement),this.allAnimations(e),this}beginEvent(){this.getProgress()==0&&this.emit("begin",this)}play(){let e=this.getPlayState();return this.beginEvent(),this.all(t=>t.play()),this.emit("play",e,this),this.is(e)||this.emit("playstate-change",e,this),this.loop(),this}pause(){let e=this.getPlayState();return this.all(t=>t.pause()),this.emit("pause",e,this),this.is(e)||this.emit("playstate-change",e,this),this.stopLoop(),this}reverse(){return this.all(e=>e.reverse()),this}reset(){return this.setProgress(0),this.options.autoplay?this.play():this.pause(),this}cancel(){return this.all(e=>e.cancel()),this}finish(){return this.all(e=>e.finish()),this}stop(){this.cancel(),this.stopLoop(),document.removeEventListener("visibilitychange",this.onVisibilityChange,!1),this.targets.forEach(e=>this.removeTarget(e)),this.emit("stop"),this.emitter.clear(),this.mainkeyframeEffect=null,this.mainAnimation=null,this.mainElement=null,this.promise=null,this.computedOptions=null,this.animations=null,this.keyframeEffects=null,this.emitter=null,this.targets=null,this.options=null,this.properties=null}getAnimation(e){let t=this.keyframeEffects.get(e);return this.animations.get(t)}getTiming(e){let t=this.computedOptions.get(e)??{},n=this.keyframeEffects.get(e).getTiming?.()??{};return{...t,...n}}getCurrentTime(){return this.mainAnimation.currentTime}getProgress(){return this.getCurrentTime()/this.totalDuration*100}getSpeed(){return this.mainAnimation.playbackRate}getPlayState(){return this.mainAnimation.playState}is(e){return this.getPlayState()==e}setCurrentTime(e){return this.all(t=>t.currentTime=e),this.emit("update",this.getProgress()),this}setProgress(e){let t=e/100*this.totalDuration;return this.setCurrentTime(t),this}setSpeed(e=1){return this.maxSpeed=e,this.all(t=>{t.updatePlaybackRate?t.updatePlaybackRate(e):t.playbackRate=e}),this}createArrayOfComputedOptions(e,t){let n=[];return this.targets.forEach((s,r)=>{let a=this.computedOptions.get(s)??{},o=g=>{let S=g;return g=="loop"&&(S="iterations"),g=="fillMode"&&(S="fill"),e[g]??a[S]??this.options[g]},l=Object.assign({easing:o("easing"),iterations:o("loop"),direction:o("direction"),endDelay:o("endDelay"),duration:o("duration"),speed:o("speed"),delay:o("delay"),timelineOffset:o("timelineOffset"),keyframes:o("keyframes")},o("extend")??{}),p=B(l,[r,t,s],this);typeof p.easing=="string"&&(p.easing=J(p.easing)),p.iterations===!0&&(p.iterations=Infinity),p.fill=o("fillMode");let{timelineOffset:y,speed:h,endDelay:b,delay:u,duration:c,iterations:m,...f}=p;m=Number(m),c=Number(c),b=Number(b),h=Number(h),u=Number(u)+Number(y);let T=u+c*m+b;this.totalDuration{let{speed:y,keyframes:h,tempDurations:b,...u}=n[p];s&&u.endDelay==0&&Math.abs(u.iterations)!=Math.abs(Infinity)&&(u.endDelay=this.totalDuration-b);let c,m,f=h;typeof f=="object"&&(f=_(f));let T=this.computedKeyframes.get(l)??{},g=Object.assign({},r,T),S=D(g,(K,P)=>this.properties[P]??K);if(m=k(f)?f:S,Array.isArray(m))c=m.map(K=>{let{easing:P,offset:x,...N}=v(["speed","loop"],K);return Object.assign({},N,typeof P=="string"?{easing:J(P)}:null,typeof x=="string"||typeof x=="number"?{offset:w(x)}:null)}),c=$(c);else{let K=v(["keyframes"],m),{offset:P,...x}=B(K,[p,t,l],this);x=G(x);let N=P;c=Object.assign({},x,k(N)?{offset:N.map(w)}:null)}let d,E;this.keyframeEffects.has(l)?(E=this.keyframeEffects.get(l),d=this.animations.get(E),E?.setKeyframes?.(c),E?.updateTiming?.(u)):(E=new KeyframeEffect(l,c,u),d=new Animation(E,u.timeline),this.keyframeEffects.set(l,E),this.animations.set(E,d)),d.playbackRate=y,d.onfinish=()=>{typeof a=="function"&&a.call(this,l,p,t,d)},d.oncancel=()=>{typeof o=="function"&&o.call(this,l,p,t,d)},this.computedOptions.set(l,u),this.computedKeyframes.set(l,c)})}updateOptions(e={}){try{let t=pe(e);this.options=Object.assign({},le,this.options,t);let n=["easing","loop","endDelay","duration","speed","delay","timelineOffset","direction","extend","fillMode","offset"],{padEndDelay:s,onfinish:r,oncancel:a,autoplay:o,target:l,targets:p,...y}=v(n,this.options);this.properties=v([...n,"keyframes","padEndDelay","onfinish","oncancel","autoplay","target","targets"],t);let h=this.targets.values(),b=[...new Set([...h,...q(p),...q(l)])];this.targets.clear(),b.forEach((m,f)=>{this.targets.set(f,m),this.targetIndexes.set(m,f)});let u=this.targets.size,c=this.createArrayOfComputedOptions(t,u);if(this.createAnimations({arrOfComputedOptions:c,padEndDelay:s,oldCSSProperties:y,onfinish:r,oncancel:a},u),this.maxSpeed=this.maxSpeed??this.options.speed,this.minDelay=this.minDelay??this.options.delay,this.totalDuration=this.totalDuration??this.options.duration,this.mainAnimation?(this.mainkeyframeEffect?.updateTiming?.({duration:this.totalDuration}),(!this.mainkeyframeEffect.setKeyframes||!this.mainkeyframeEffect.updateTiming)&&console.warn("@okikio/animate - `KeyframeEffect.setKeyframes` and/or `KeyframeEffect.updateTiming` are not supported in this browser.")):(this.mainkeyframeEffect=new KeyframeEffect(this.mainElement,[{opacity:"0"},{opacity:"1"}],{duration:this.totalDuration,easing:"linear"}),this.mainAnimation=new Animation(this.mainkeyframeEffect,this.options.timeline)),this.mainAnimation.playbackRate=this.maxSpeed,this.mainAnimation.onfinish=()=>{if(this.emit("finish",this),this.mainAnimation){let m=this.getPlayState();this.is(m)||this.emit("playstate-change",m,this),this.stopLoop()}},this.mainAnimation.oncancel=()=>{if(this.emit("cancel",this),this.mainAnimation){let m=this.getPlayState();this.is(m)||this.emit("playstate-change",m,this),this.stopLoop()}},o){let m=window.setTimeout(()=>{this.emit("begin",this),m=window.clearTimeout(m)},0);this.play()}else this.pause()}catch(t){this.emit("error",t)}}add(e){let t=this.getProgress(),n=this.is("running"),s=this.is("paused");this.updateOptions({target:e}),this.setProgress(t),n?this.play():s&&this.pause()}removeTarget(e){let t=this.keyframeEffects.get(e);this.animations.delete(t),t=null,this.computedKeyframes.delete(e),this.computedOptions.delete(e),this.keyframeEffects.delete(e);let n=this.targetIndexes.get(e);this.targets.delete(n),this.targetIndexes.delete(e)}remove(e){this.removeTarget(e);let t=new Set([].concat(this.targets.values()));this.options.target=[...t],this.options.targets=[],t.clear(),t=null;let n=this.getProgress(),s=this.is("running"),r=this.is("paused");this.updateOptions(),s?this.play():r&&this.pause(),this.setProgress(n)}on(e,t,n){return this?.emitter?.on(e,t,n??this),this}off(e,t,n){return this?.emitter?.off(e,t,n??this),this}emit(e,...t){return this?.emitter?.emit(e,...t),this}toJSON(){return this.options}get[Symbol.toStringTag](){return"Animate"}},z=Q;z.pauseOnPageHidden=!0;var me=(i={})=>new z(i),ye=me;0&&(module.exports={Animate,CSSArrValue,CSSValue,DefaultAnimationOptions,EASINGS,EFFECTS,EasingKeys,GetEase,KeyframeParse,ParseTransformableCSSKeyframes,ParseTransformableCSSProperties,TransformFunctionNames,UnitDEG,UnitDEGCSSValue,UnitLess,UnitLessCSSValue,UnitPX,UnitPXCSSValue,addCSSUnit,animate,computeOption,createTransformProperty,flatten,getElements,getTargets,isValid,mapAnimationOptions,mapObject,omit,parseOffset,parseOptions,toArr,transpose}); +var te=Object.defineProperty;var ce=i=>te(i,"__esModule",{value:!0});var fe=(i,e)=>{for(var t in e)te(i,t,{get:e[t],enumerable:!0})};ce(exports);fe(exports,{Animate:()=>N,CSSArrValue:()=>L,CSSValue:()=>D,DefaultAnimationOptions:()=>pe,EASINGS:()=>J,EFFECTS:()=>ye,EasingKeys:()=>le,GetEase:()=>Q,KeyframeParse:()=>U,ParseTransformableCSSKeyframes:()=>B,ParseTransformableCSSProperties:()=>$,TransformFunctionNames:()=>Z,UnitDEG:()=>Y,UnitDEGCSSValue:()=>S,UnitLess:()=>j,UnitLessCSSValue:()=>O,UnitPX:()=>F,UnitPXCSSValue:()=>C,addCSSUnit:()=>X,animate:()=>ue,computeOption:()=>oe,createTransformProperty:()=>G,default:()=>he,flatten:()=>ae,getElements:()=>re,getTargets:()=>W,isValid:()=>E,mapAnimationOptions:()=>R,mapObject:()=>v,omit:()=>z,parseOffset:()=>V,parseOptions:()=>me,toArr:()=>q,transpose:()=>se});var I=class{constructor(e){this.map=new Map(e)}getMap(){return this.map}get(e){return this.map.get(e)}keys(){return Array.from(this.map.keys())}values(){return Array.from(this.map.values())}set(e,t){return this.map.set(e,t),this}add(e){let n=this.size;return this.set(n,e),this}get size(){return this.map.size}get length(){return this.map.size}last(e=1){let t=this.keys()[this.size-e];return this.get(t)}delete(e){return this.map.delete(e)}remove(e){return this.map.delete(e),this}clear(){return this.map.clear(),this}has(e){return this.map.has(e)}entries(){return this.map.entries()}forEach(e,t){return this.map.forEach(e,t),this}[Symbol.iterator](){return this.entries()}},ie=(i,e,...t)=>{i.forEach(n=>{n[e](...t)})};var ne=({callback:i=()=>{},scope:e=null,name:t="event"})=>({callback:i,scope:e,name:t}),w=class extends I{constructor(e="event"){super();this.name=e}},_=class extends I{constructor(){super()}getEvent(e){let t=this.get(e);return t instanceof w?t:(this.set(e,new w(e)),this.get(e))}newListener(e,t,n){let s=this.getEvent(e);return s.add(ne({name:e,callback:t,scope:n})),s}on(e,t,n){if(typeof e=="undefined"||e==null)return this;typeof e=="string"&&(e=e.trim().split(/\s/g));let s,r,a=typeof e=="object"&&!Array.isArray(e),o=a?t:n;return a||(r=t),Object.keys(e).forEach(p=>{s=a?p:e[p],a&&(r=e[p]),this.newListener(s,r,o)},this),this}removeListener(e,t,n){let s=this.get(e);if(s instanceof w&&t){let r=ne({name:e,callback:t,scope:n});s.forEach((a,o)=>{if(a.callback===r.callback&&a.scope===r.scope)return s.remove(o)})}return s}off(e,t,n){if(typeof e=="undefined"||e==null)return this;typeof e=="string"&&(e=e.trim().split(/\s/g));let s,r,a=typeof e=="object"&&!Array.isArray(e),o=a?t:n;return a||(r=t),Object.keys(e).forEach(p=>{s=a?p:e[p],a&&(r=e[p]),typeof r=="function"?this.removeListener(s,r,o):this.remove(s)},this),this}once(e,t,n){if(typeof e=="undefined"||e==null)return this;typeof e=="string"&&(e=e.trim().split(/\s/g));let s=typeof e=="object"&&!Array.isArray(e);return Object.keys(e).forEach(r=>{let a=s?r:e[r],o=s?e[r]:t,p=s?t:n,l=(...f)=>{o.apply(p,f),this.removeListener(a,l,p)};this.newListener(a,l,p)},this),this}emit(e,...t){return typeof e=="undefined"||e==null?this:(typeof e=="string"&&(e=e.trim().split(/\s/g)),e.forEach(n=>{let s=this.get(n);s instanceof w&&s.forEach(r=>{let{callback:a,scope:o}=r;a.apply(o,t)})},this),this)}clear(){return ie(this,"clear"),super.clear(),this}};var V=i=>typeof i=="string"?i.includes("%")?parseFloat(i)/100:i=="from"?0:i=="to"?1:parseFloat(i):i,U=i=>{let e=new Set,t=Object.keys(i),n=t.length;for(let s=0;ss.offset-r.offset)},ye={};var X=(i="")=>e=>typeof e=="string"?e:`${e}${i}`,j=X(),F=X("px"),Y=X("deg"),q=i=>Array.isArray(i)||typeof i=="string"?(typeof i=="string"&&(i=i.split(",")),i):[i],E=i=>Array.isArray(i)||typeof i=="string"?Boolean(i.length):i!=null&&i!=null,D=i=>e=>E(e)?q(e).map(t=>{if(typeof t!="number"&&typeof t!="string")return t;let n=Number(t),s=Number.isNaN(n)?typeof t=="string"?t.trim():t:n;return i(s)}):[],se=(...i)=>{let e=0;i=i.map(s=>{let r=q(s),a=r.length;return a>e&&(e=a),r});let t=[],n=i.length;for(let s=0;sq(i).map(D(e)),Z=["translate","translate3d","translateX","translateY","translateZ","rotate","rotate3d","rotateX","rotateY","rotateZ","scale","scale3d","scaleX","scaleY","scaleZ","skew","skewX","skewY","perspective"],G=i=>{let e="",t=Z.length;for(let n=0;n{let{perspective:e,rotate:t,rotate3d:n,rotateX:s,rotateY:r,rotateZ:a,translate:o,translate3d:p,translateX:l,translateY:f,translateZ:b,scale:d,scale3d:h,scaleX:u,scaleY:c,scaleZ:m,skew:y,skewX:g,skewY:T,...P}=i;o=L(o,F),p=L(p,F),l=C(l),f=C(f),b=C(b),t=L(t,Y),n=L(n,j),s=S(s),r=S(r),a=S(a),d=L(d,j),h=L(h,j),u=O(u),c=O(c),m=O(m),y=L(y,Y),g=S(g),T=S(T),e=C(e);let A=se(o,p,l,f,b,t,n,s,r,a,d,h,u,c,m,y,g,T,e).filter(E).map(G);return P=v(P,k=>[].concat(k).map(x=>""+x)),Object.assign({},E(A)?{transform:A}:null,P)},B=i=>i.map(e=>{let{translate:t,translate3d:n,translateX:s,translateY:r,translateZ:a,rotate:o,rotate3d:p,rotateX:l,rotateY:f,rotateZ:b,scale:d,scale3d:h,scaleX:u,scaleY:c,scaleZ:m,skew:y,skewX:g,skewY:T,perspective:P,easing:A,iterations:k,offset:x,...K}=e;return t=C(t),n=C(n),s=C(s)[0],r=C(r)[0],a=C(a)[0],o=S(o),p=O(p),l=S(l)[0],f=S(f)[0],b=S(b)[0],d=O(d),h=O(h),u=O(u)[0],c=O(c)[0],m=O(m)[0],y=S(y),g=S(g)[0],T=S(T)[0],P=C(P)[0],[K,t,n,s,r,a,o,p,l,f,b,d,h,u,c,m,y,g,T,P]}).map(([e,...t])=>{let n=G(t);return Object.assign({},E(n)?{transform:n}:null,e)});var re=i=>typeof i=="string"?Array.from(document.querySelectorAll(i)):[i],ae=i=>[].concat(...i),W=i=>Array.isArray(i)?ae(i.map(W)):typeof i=="string"||i instanceof Node?re(i):i instanceof NodeList||i instanceof HTMLCollection?Array.from(i):[],oe=(i,e,t)=>typeof i=="function"?i.apply(t,e):i,v=(i,e)=>{let t=Object.keys(i),n,s,r={};for(let a=0,o=t.length;av(i,n=>oe(n,e,t)),J={in:"ease-in",out:"ease-out","in-out":"ease-in-out","in-sine":"cubic-bezier(0.47, 0, 0.745, 0.715)","out-sine":"cubic-bezier(0.39, 0.575, 0.565, 1)","in-out-sine":"cubic-bezier(0.445, 0.05, 0.55, 0.95)","in-quad":"cubic-bezier(0.55, 0.085, 0.68, 0.53)","out-quad":"cubic-bezier(0.25, 0.46, 0.45, 0.94)","in-out-quad":"cubic-bezier(0.455, 0.03, 0.515, 0.955)","in-cubic":"cubic-bezier(0.55, 0.055, 0.675, 0.19)","out-cubic":"cubic-bezier(0.215, 0.61, 0.355, 1)","in-out-cubic":"cubic-bezier(0.645, 0.045, 0.355, 1)","in-quart":"cubic-bezier(0.895, 0.03, 0.685, 0.22)","out-quart":"cubic-bezier(0.165, 0.84, 0.44, 1)","in-out-quart":"cubic-bezier(0.77, 0, 0.175, 1)","in-quint":"cubic-bezier(0.755, 0.05, 0.855, 0.06)","out-quint":"cubic-bezier(0.23, 1, 0.32, 1)","in-out-quint":"cubic-bezier(0.86, 0, 0.07, 1)","in-expo":"cubic-bezier(0.95, 0.05, 0.795, 0.035)","out-expo":"cubic-bezier(0.19, 1, 0.22, 1)","in-out-expo":"cubic-bezier(1, 0, 0, 1)","in-circ":"cubic-bezier(0.6, 0.04, 0.98, 0.335)","out-circ":"cubic-bezier(0.075, 0.82, 0.165, 1)","in-out-circ":"cubic-bezier(0.785, 0.135, 0.15, 0.86)","in-back":"cubic-bezier(0.6, -0.28, 0.735, 0.045)","out-back":"cubic-bezier(0.175, 0.885, 0.32, 1.275)","in-out-back":"cubic-bezier(0.68, -0.55, 0.265, 1.55)"},le=Object.keys(J),Q=i=>{let e=i.replace(/^ease-/,"");return le.includes(e)?J[e]:i},pe={keyframes:[],offset:[],loop:1,delay:0,speed:1,endDelay:0,easing:"ease",timelineOffset:0,autoplay:!0,duration:1e3,fillMode:"none",direction:"normal",padEndDelay:!1,timeline:document.timeline,extend:{}},me=i=>{let{options:e,...t}=i,n=e instanceof N?e.options:Array.isArray(e)?e?.[0]?.options:e;return Object.assign({},n,t)},z=(i,e)=>{let t={...e};for(;i.length;){let{[i.pop()]:n,...s}=t;t=s}return t},ee=class{constructor(e){this.options={};this.properties={};this.totalDuration=0;this.emitter=new _;this.targets=new I;this.targetIndexes=new WeakMap;this.keyframeEffects=new WeakMap;this.computedOptions=new WeakMap;this.animations=new WeakMap;this.computedKeyframes=new WeakMap;this.loop=this.loop.bind(this),this.onVisibilityChange=this.onVisibilityChange.bind(this),this.on("error",console.error),this.updateOptions(e),this.mainAnimation&&(this.visibilityPlayState=this.getPlayState(),ee.pauseOnPageHidden&&document.addEventListener("visibilitychange",this.onVisibilityChange,!1)),this.newPromise()}onVisibilityChange(){document.hidden?(this.visibilityPlayState=this.getPlayState(),this.is("running")&&(this.loop(),this.pause())):this.visibilityPlayState=="running"&&this.is("paused")&&this.play()}newPromise(){return this.promise=new Promise((e,t)=>{this?.emitter?.once?.("finish",()=>e([this])),this?.emitter?.once?.("error",n=>t(n))}),this.promise}then(e,t){return e=e?.bind(this),t=t?.bind(this),this?.promise?.then?.(e,t),this}catch(e){return e=e?.bind(this),this.promise?.catch?.(e),this}finally(e){return e=e?.bind(this),this.promise?.finally?.(e),this}loop(){this.stopLoop(),this.animationFrame=window.requestAnimationFrame(this.loop),this.emit("update",this.getProgress(),this)}stopLoop(){window.cancelAnimationFrame(this.animationFrame)}allAnimations(e){return this.targets.forEach(t=>{let n=this.keyframeEffects.get(t),s=this.animations.get(n);return e(s,t)}),this}all(e){return this.mainAnimation&&e(this.mainAnimation,this.mainElement),this.allAnimations(e),this}beginEvent(){this.getProgress()==0&&this.emit("begin",this)}play(){let e=this.getPlayState();return this.beginEvent(),this.all(t=>t.play()),this.emit("play",e,this),this.is(e)||this.emit("playstate-change",e,this),this.loop(),this}pause(){let e=this.getPlayState();return this.all(t=>t.pause()),this.emit("pause",e,this),this.is(e)||this.emit("playstate-change",e,this),this.stopLoop(),this}reverse(){return this.all(e=>e.reverse()),this}reset(){return this.setProgress(0),this.options.autoplay?this.play():this.pause(),this}cancel(){return this.all(e=>e.cancel()),this}finish(){return this.all(e=>e.finish()),this}stop(){this.cancel(),this.stopLoop(),document.removeEventListener("visibilitychange",this.onVisibilityChange,!1),this.targets.forEach(e=>this.removeTarget(e)),this.emit("stop"),this.emitter.clear(),this.mainkeyframeEffect=null,this.mainAnimation=null,this.mainElement=null,this.promise=null,this.computedOptions=null,this.animations=null,this.keyframeEffects=null,this.emitter=null,this.targets=null,this.options=null,this.properties=null}getAnimation(e){let t=this.keyframeEffects.get(e);return this.animations.get(t)}getTiming(e){let t=this.computedOptions.get(e)??{},n=this.keyframeEffects.get(e).getTiming?.()??{};return{...t,...n}}getCurrentTime(){return this.mainAnimation.currentTime}getProgress(){return this.getCurrentTime()/this.totalDuration*100}getSpeed(){return this.mainAnimation.playbackRate}getPlayState(){return this.mainAnimation.playState}is(e){return this.getPlayState()==e}setCurrentTime(e){return this.all(t=>t.currentTime=e),this.emit("update",this.getProgress()),this}setProgress(e){let t=e/100*this.totalDuration;return this.setCurrentTime(t),this}setSpeed(e=1){return this.maxSpeed=e,this.all(t=>{t.updatePlaybackRate?t.updatePlaybackRate(e):t.playbackRate=e}),this}createArrayOfComputedOptions(e,t){let n=[];return this.targets.forEach((s,r)=>{let a=this.computedOptions.get(s)??{},o=g=>{let T=g;return g=="loop"&&(T="iterations"),g=="fillMode"&&(T="fill"),e[g]??a[T]??this.options[g]},p=Object.assign({easing:o("easing"),iterations:o("loop"),direction:o("direction"),endDelay:o("endDelay"),duration:o("duration"),speed:o("speed"),delay:o("delay"),timelineOffset:o("timelineOffset"),keyframes:o("keyframes")},o("extend")??{}),l=R(p,[r,t,s],this);typeof l.easing=="string"&&(l.easing=Q(l.easing)),l.iterations===!0&&(l.iterations=Infinity),l.fill=o("fillMode");let{timelineOffset:f,speed:b,endDelay:d,delay:h,duration:u,iterations:c,...m}=l;c=Number(c),u=Number(u),d=Number(d),b=Number(b),h=Number(h)+Number(f);let y=h+u*c+d;this.totalDuration{let{speed:b,keyframes:d,tempDurations:h,...u}=n[f];s&&u.endDelay==0&&Math.abs(u.iterations)!=Math.abs(Infinity)&&(u.endDelay=this.totalDuration-h);let c,m,y=d;typeof y=="object"&&(y=U(y));let g=this.computedKeyframes.get(l)??{},T=Object.assign({},r,g),P=v(T,(x,K)=>this.properties[K]??x);if(m=E(y)?y:P,Array.isArray(m))c=m.map(x=>{let{easing:K,offset:M,...H}=z(["speed","loop"],x);return Object.assign({},H,typeof K=="string"?{easing:Q(K)}:null,typeof M=="string"||typeof M=="number"?{offset:V(M)}:null)}),c=B(c);else{let x=z(["keyframes"],m),{offset:K,...M}=R(x,[f,t,l],this);M=$(M);let H=K;c=Object.assign({},M,E(H)?{offset:H.map(V)}:null)}let A,k;this.keyframeEffects.has(l)?(k=this.keyframeEffects.get(l),A=this.animations.get(k),k?.setKeyframes?.(c),k?.updateTiming?.(u)):(k=new KeyframeEffect(l,c,u),A=new Animation(k,p),this.keyframeEffects.set(l,k),this.animations.set(k,A)),A.playbackRate=b,A.onfinish=()=>{typeof a=="function"&&a.call(this,l,f,t,A)},A.oncancel=()=>{typeof o=="function"&&o.call(this,l,f,t,A)},this.computedOptions.set(l,u),this.computedKeyframes.set(l,c)})}updateOptions(e={}){try{let t=me(e);this.options=Object.assign({},pe,this.options,t);let n=["easing","loop","endDelay","duration","speed","delay","timelineOffset","direction","extend","fillMode","offset"],{padEndDelay:s,autoplay:r,target:a,targets:o,timeline:p,onfinish:l,oncancel:f,...b}=z(n,this.options);this.properties=z([...n,"keyframes","padEndDelay","onfinish","oncancel","autoplay","target","targets","timeline"],t);let d=this.targets.values(),h=[...new Set([...d,...W(o),...W(a)])];this.targets.clear(),h.forEach((m,y)=>{this.targets.set(y,m),this.targetIndexes.set(m,y)});let u=this.targets.size,c=this.createArrayOfComputedOptions(t,u);if(this.createAnimations({arrOfComputedOptions:c,padEndDelay:s,oldCSSProperties:b,onfinish:l,oncancel:f,timeline:p},u),this.maxSpeed=this.maxSpeed??this.options.speed,this.minDelay=this.minDelay??this.options.delay,this.totalDuration=this.totalDuration??this.options.duration,this.mainAnimation?(this.mainkeyframeEffect?.updateTiming?.({duration:this.totalDuration}),(!this.mainkeyframeEffect.setKeyframes||!this.mainkeyframeEffect.updateTiming)&&console.warn("@okikio/animate - `KeyframeEffect.setKeyframes` and/or `KeyframeEffect.updateTiming` are not supported in this browser.")):(this.mainkeyframeEffect=new KeyframeEffect(this.mainElement,[{opacity:"0"},{opacity:"1"}],{duration:this.totalDuration,easing:"linear"}),this.mainAnimation=new Animation(this.mainkeyframeEffect,p)),this.mainAnimation.playbackRate=this.maxSpeed,this.mainAnimation.onfinish=()=>{if(this.emit("finish",this),this.mainAnimation){let m=this.getPlayState();this.is(m)||this.emit("playstate-change",m,this),this.stopLoop()}},this.mainAnimation.oncancel=()=>{if(this.emit("cancel",this),this.mainAnimation){let m=this.getPlayState();this.is(m)||this.emit("playstate-change",m,this),this.stopLoop()}},r){let m=window.setTimeout(()=>{this.emit("begin",this),m=window.clearTimeout(m)},0);this.play()}else this.pause()}catch(t){this.emit("error",t)}}add(e){let t=this.getProgress(),n=this.is("running"),s=this.is("paused");this.updateOptions({target:e}),this.setProgress(t),n?this.play():s&&this.pause()}removeTarget(e){let t=this.keyframeEffects.get(e);this.animations.delete(t),t=null,this.computedKeyframes.delete(e),this.computedOptions.delete(e),this.keyframeEffects.delete(e);let n=this.targetIndexes.get(e);this.targets.delete(n),this.targetIndexes.delete(e)}remove(e){this.removeTarget(e);let t=new Set([].concat(this.targets.values()));this.options.target=[...t],this.options.targets=[],t.clear(),t=null;let n=this.getProgress(),s=this.is("running"),r=this.is("paused");this.updateOptions(),s?this.play():r&&this.pause(),this.setProgress(n)}on(e,t,n){return this?.emitter?.on(e,t,n??this),this}off(e,t,n){return this?.emitter?.off(e,t,n??this),this}emit(e,...t){return this?.emitter?.emit(e,...t),this}toJSON(){return this.options}get[Symbol.toStringTag](){return"Animate"}},N=ee;N.pauseOnPageHidden=!0;var ue=(i={})=>new N(i),he=ue;0&&(module.exports={Animate,CSSArrValue,CSSValue,DefaultAnimationOptions,EASINGS,EFFECTS,EasingKeys,GetEase,KeyframeParse,ParseTransformableCSSKeyframes,ParseTransformableCSSProperties,TransformFunctionNames,UnitDEG,UnitDEGCSSValue,UnitLess,UnitLessCSSValue,UnitPX,UnitPXCSSValue,addCSSUnit,animate,computeOption,createTransformProperty,flatten,getElements,getTargets,isValid,mapAnimationOptions,mapObject,omit,parseOffset,parseOptions,toArr,transpose}); diff --git a/packages/animate/lib/api.es.js b/packages/animate/lib/api.es.js index 150a9e9..246c99f 100644 --- a/packages/animate/lib/api.es.js +++ b/packages/animate/lib/api.es.js @@ -1 +1 @@ -var M=class{constructor(e){this.map=new Map(e)}getMap(){return this.map}get(e){return this.map.get(e)}keys(){return Array.from(this.map.keys())}values(){return Array.from(this.map.values())}set(e,t){return this.map.set(e,t),this}add(e){let n=this.size;return this.set(n,e),this}get size(){return this.map.size}get length(){return this.map.size}last(e=1){let t=this.keys()[this.size-e];return this.get(t)}delete(e){return this.map.delete(e)}remove(e){return this.map.delete(e),this}clear(){return this.map.clear(),this}has(e){return this.map.has(e)}entries(){return this.map.entries()}forEach(e,t){return this.map.forEach(e,t),this}[Symbol.iterator](){return this.entries()}},U=(i,e,...t)=>{i.forEach(n=>{n[e](...t)})};var Z=({callback:i=()=>{},scope:e=null,name:t="event"})=>({callback:i,scope:e,name:t}),I=class extends M{constructor(e="event"){super();this.name=e}},H=class extends M{constructor(){super()}getEvent(e){let t=this.get(e);return t instanceof I?t:(this.set(e,new I(e)),this.get(e))}newListener(e,t,n){let s=this.getEvent(e);return s.add(Z({name:e,callback:t,scope:n})),s}on(e,t,n){if(typeof e=="undefined"||e==null)return this;typeof e=="string"&&(e=e.trim().split(/\s/g));let s,r,a=typeof e=="object"&&!Array.isArray(e),o=a?t:n;return a||(r=t),Object.keys(e).forEach(l=>{s=a?l:e[l],a&&(r=e[l]),this.newListener(s,r,o)},this),this}removeListener(e,t,n){let s=this.get(e);if(s instanceof I&&t){let r=Z({name:e,callback:t,scope:n});s.forEach((a,o)=>{if(a.callback===r.callback&&a.scope===r.scope)return s.remove(o)})}return s}off(e,t,n){if(typeof e=="undefined"||e==null)return this;typeof e=="string"&&(e=e.trim().split(/\s/g));let s,r,a=typeof e=="object"&&!Array.isArray(e),o=a?t:n;return a||(r=t),Object.keys(e).forEach(l=>{s=a?l:e[l],a&&(r=e[l]),typeof r=="function"?this.removeListener(s,r,o):this.remove(s)},this),this}once(e,t,n){if(typeof e=="undefined"||e==null)return this;typeof e=="string"&&(e=e.trim().split(/\s/g));let s=typeof e=="object"&&!Array.isArray(e);return Object.keys(e).forEach(r=>{let a=s?r:e[r],o=s?e[r]:t,l=s?t:n,p=(...y)=>{o.apply(l,y),this.removeListener(a,p,l)};this.newListener(a,p,l)},this),this}emit(e,...t){return typeof e=="undefined"||e==null?this:(typeof e=="string"&&(e=e.trim().split(/\s/g)),e.forEach(n=>{let s=this.get(n);s instanceof I&&s.forEach(r=>{let{callback:a,scope:o}=r;a.apply(o,t)})},this),this)}clear(){return U(this,"clear"),super.clear(),this}};var V=i=>typeof i=="string"?i.includes("%")?parseFloat(i)/100:i=="from"?0:i=="to"?1:parseFloat(i):i,G=i=>{let e=new Set,t=Object.keys(i),n=t.length;for(let s=0;ss.offset-r.offset)},fe={};var X=(i="")=>e=>typeof e=="string"?e:`${e}${i}`,j=X(),F=X("px"),Y=X("deg"),q=i=>Array.isArray(i)||typeof i=="string"?(typeof i=="string"&&(i=i.split(",")),i):[i],k=i=>Array.isArray(i)||typeof i=="string"?Boolean(i.length):i!=null&&i!=null,D=i=>e=>k(e)?q(e).map(t=>{if(typeof t!="number"&&typeof t!="string")return t;let n=Number(t),s=Number.isNaN(n)?typeof t=="string"?t.trim():t:n;return i(s)}):[],ie=(...i)=>{let e=0;i=i.map(s=>{let r=q(s),a=r.length;return a>e&&(e=a),r});let t=[],n=i.length;for(let s=0;sq(i).map(D(e)),$=["translate","translate3d","translateX","translateY","translateZ","rotate","rotate3d","rotateX","rotateY","rotateZ","scale","scale3d","scaleX","scaleY","scaleZ","skew","skewX","skewY","perspective"],B=i=>{let e="",t=$.length;for(let n=0;n{let{perspective:e,rotate:t,rotate3d:n,rotateX:s,rotateY:r,rotateZ:a,translate:o,translate3d:l,translateX:p,translateY:y,translateZ:h,scale:b,scale3d:u,scaleX:c,scaleY:m,scaleZ:f,skew:T,skewX:g,skewY:S,...d}=i;o=L(o,F),l=L(l,F),p=C(p),y=C(y),h=C(h),t=L(t,Y),n=L(n,j),s=E(s),r=E(r),a=E(a),b=L(b,j),u=L(u,j),c=x(c),m=x(m),f=x(f),T=L(T,Y),g=E(g),S=E(S),e=C(e);let A=ie(o,l,p,y,h,t,n,s,r,a,b,u,c,m,f,T,g,S,e).map(B);return d=v(d,K=>[].concat(K).map(O=>""+O)),Object.assign({},k(A)?{transform:A}:null,d)},J=i=>i.map(e=>{let{translate:t,translate3d:n,translateX:s,translateY:r,translateZ:a,rotate:o,rotate3d:l,rotateX:p,rotateY:y,rotateZ:h,scale:b,scale3d:u,scaleX:c,scaleY:m,scaleZ:f,skew:T,skewX:g,skewY:S,perspective:d,easing:A,iterations:K,offset:O,...P}=e;return t=C(t),n=C(n),s=C(s)[0],r=C(r)[0],a=C(a)[0],o=E(o),l=x(l),p=E(p)[0],y=E(y)[0],h=E(h)[0],b=x(b),u=x(u),c=x(c)[0],m=x(m)[0],f=x(f)[0],T=E(T),g=E(g)[0],S=E(S)[0],d=C(d)[0],[P,t,n,s,r,a,o,l,p,y,h,b,u,c,m,f,T,g,S,d]}).map(([e,...t])=>{let n=B(t);return Object.assign({},k(n)?{transform:n}:null,e)});var ne=i=>typeof i=="string"?Array.from(document.querySelectorAll(i)):[i],se=i=>[].concat(...i),W=i=>Array.isArray(i)?se(i.map(W)):typeof i=="string"||i instanceof Node?ne(i):i instanceof NodeList||i instanceof HTMLCollection?Array.from(i):[],re=(i,e,t)=>typeof i=="function"?i.apply(t,e):i,v=(i,e)=>{let t=Object.keys(i),n,s,r={};for(let a=0,o=t.length;av(i,n=>re(n,e,t)),ee={in:"ease-in",out:"ease-out","in-out":"ease-in-out","in-sine":"cubic-bezier(0.47, 0, 0.745, 0.715)","out-sine":"cubic-bezier(0.39, 0.575, 0.565, 1)","in-out-sine":"cubic-bezier(0.445, 0.05, 0.55, 0.95)","in-quad":"cubic-bezier(0.55, 0.085, 0.68, 0.53)","out-quad":"cubic-bezier(0.25, 0.46, 0.45, 0.94)","in-out-quad":"cubic-bezier(0.455, 0.03, 0.515, 0.955)","in-cubic":"cubic-bezier(0.55, 0.055, 0.675, 0.19)","out-cubic":"cubic-bezier(0.215, 0.61, 0.355, 1)","in-out-cubic":"cubic-bezier(0.645, 0.045, 0.355, 1)","in-quart":"cubic-bezier(0.895, 0.03, 0.685, 0.22)","out-quart":"cubic-bezier(0.165, 0.84, 0.44, 1)","in-out-quart":"cubic-bezier(0.77, 0, 0.175, 1)","in-quint":"cubic-bezier(0.755, 0.05, 0.855, 0.06)","out-quint":"cubic-bezier(0.23, 1, 0.32, 1)","in-out-quint":"cubic-bezier(0.86, 0, 0.07, 1)","in-expo":"cubic-bezier(0.95, 0.05, 0.795, 0.035)","out-expo":"cubic-bezier(0.19, 1, 0.22, 1)","in-out-expo":"cubic-bezier(1, 0, 0, 1)","in-circ":"cubic-bezier(0.6, 0.04, 0.98, 0.335)","out-circ":"cubic-bezier(0.075, 0.82, 0.165, 1)","in-out-circ":"cubic-bezier(0.785, 0.135, 0.15, 0.86)","in-back":"cubic-bezier(0.6, -0.28, 0.735, 0.045)","out-back":"cubic-bezier(0.175, 0.885, 0.32, 1.275)","in-out-back":"cubic-bezier(0.68, -0.55, 0.265, 1.55)"},ae=Object.keys(ee),te=i=>{let e=i.replace(/^ease-/,"");return ae.includes(e)?ee[e]:i},oe={keyframes:[],offset:[],loop:1,delay:0,speed:1,endDelay:0,easing:"ease",timelineOffset:0,autoplay:!0,duration:1e3,fillMode:"none",direction:"normal",padEndDelay:!1,extend:{}},le=i=>{let{options:e,...t}=i,n=e instanceof N?e.options:Array.isArray(e)?e?.[0]?.options:e;return Object.assign({},n,t)},z=(i,e)=>{let t={...e};for(;i.length;){let{[i.pop()]:n,...s}=t;t=s}return t},_=class{constructor(e){this.options={};this.properties={};this.totalDuration=0;this.emitter=new H;this.targets=new M;this.targetIndexes=new WeakMap;this.keyframeEffects=new WeakMap;this.computedOptions=new WeakMap;this.animations=new WeakMap;this.computedKeyframes=new WeakMap;this.loop=this.loop.bind(this),this.onVisibilityChange=this.onVisibilityChange.bind(this),this.on("error",t=>console.error(t)),this.updateOptions(e),this.visibilityPlayState=this.getPlayState(),_.pauseOnPageHidden&&document.addEventListener("visibilitychange",this.onVisibilityChange,!1),this.newPromise()}onVisibilityChange(){document.hidden?(this.visibilityPlayState=this.getPlayState(),this.is("running")&&(this.loop(),this.pause())):this.visibilityPlayState=="running"&&this.is("paused")&&this.play()}newPromise(){return this.promise=new Promise((e,t)=>{this?.emitter?.once?.("finish",()=>e([this])),this?.emitter?.once?.("error",n=>t(n))}),this.promise}then(e,t){return e=e?.bind(this),t=t?.bind(this),this?.promise?.then?.(e,t),this}catch(e){return e=e?.bind(this),this.promise?.catch?.(e),this}finally(e){return e=e?.bind(this),this.promise?.finally?.(e),this}loop(){this.stopLoop(),this.animationFrame=window.requestAnimationFrame(this.loop),this.emit("update",this.getProgress(),this)}stopLoop(){window.cancelAnimationFrame(this.animationFrame)}allAnimations(e){return this.targets.forEach(t=>{let n=this.keyframeEffects.get(t),s=this.animations.get(n);return e(s,t)}),this}all(e){return this.mainAnimation&&e(this.mainAnimation,this.mainElement),this.allAnimations(e),this}beginEvent(){this.getProgress()==0&&this.emit("begin",this)}play(){let e=this.getPlayState();return this.beginEvent(),this.all(t=>t.play()),this.emit("play",e,this),this.is(e)||this.emit("playstate-change",e,this),this.loop(),this}pause(){let e=this.getPlayState();return this.all(t=>t.pause()),this.emit("pause",e,this),this.is(e)||this.emit("playstate-change",e,this),this.stopLoop(),this}reverse(){return this.all(e=>e.reverse()),this}reset(){return this.setProgress(0),this.options.autoplay?this.play():this.pause(),this}cancel(){return this.all(e=>e.cancel()),this}finish(){return this.all(e=>e.finish()),this}stop(){this.cancel(),this.stopLoop(),document.removeEventListener("visibilitychange",this.onVisibilityChange,!1),this.targets.forEach(e=>this.removeTarget(e)),this.emit("stop"),this.emitter.clear(),this.mainkeyframeEffect=null,this.mainAnimation=null,this.mainElement=null,this.promise=null,this.computedOptions=null,this.animations=null,this.keyframeEffects=null,this.emitter=null,this.targets=null,this.options=null,this.properties=null}getAnimation(e){let t=this.keyframeEffects.get(e);return this.animations.get(t)}getTiming(e){let t=this.computedOptions.get(e)??{},n=this.keyframeEffects.get(e).getTiming?.()??{};return{...t,...n}}getCurrentTime(){return this.mainAnimation.currentTime}getProgress(){return this.getCurrentTime()/this.totalDuration*100}getSpeed(){return this.mainAnimation.playbackRate}getPlayState(){return this.mainAnimation.playState}is(e){return this.getPlayState()==e}setCurrentTime(e){return this.all(t=>t.currentTime=e),this.emit("update",this.getProgress()),this}setProgress(e){let t=e/100*this.totalDuration;return this.setCurrentTime(t),this}setSpeed(e=1){return this.maxSpeed=e,this.all(t=>{t.updatePlaybackRate?t.updatePlaybackRate(e):t.playbackRate=e}),this}createArrayOfComputedOptions(e,t){let n=[];return this.targets.forEach((s,r)=>{let a=this.computedOptions.get(s)??{},o=g=>{let S=g;return g=="loop"&&(S="iterations"),g=="fillMode"&&(S="fill"),e[g]??a[S]??this.options[g]},l=Object.assign({easing:o("easing"),iterations:o("loop"),direction:o("direction"),endDelay:o("endDelay"),duration:o("duration"),speed:o("speed"),delay:o("delay"),timelineOffset:o("timelineOffset"),keyframes:o("keyframes")},o("extend")??{}),p=Q(l,[r,t,s],this);typeof p.easing=="string"&&(p.easing=te(p.easing)),p.iterations===!0&&(p.iterations=Infinity),p.fill=o("fillMode");let{timelineOffset:y,speed:h,endDelay:b,delay:u,duration:c,iterations:m,...f}=p;m=Number(m),c=Number(c),b=Number(b),h=Number(h),u=Number(u)+Number(y);let T=u+c*m+b;this.totalDuration{let{speed:y,keyframes:h,tempDurations:b,...u}=n[p];s&&u.endDelay==0&&Math.abs(u.iterations)!=Math.abs(Infinity)&&(u.endDelay=this.totalDuration-b);let c,m,f=h;typeof f=="object"&&(f=G(f));let T=this.computedKeyframes.get(l)??{},g=Object.assign({},r,T),S=v(g,(K,O)=>this.properties[O]??K);if(m=k(f)?f:S,Array.isArray(m))c=m.map(K=>{let{easing:O,offset:P,...w}=z(["speed","loop"],K);return Object.assign({},w,typeof O=="string"?{easing:te(O)}:null,typeof P=="string"||typeof P=="number"?{offset:V(P)}:null)}),c=J(c);else{let K=z(["keyframes"],m),{offset:O,...P}=Q(K,[p,t,l],this);P=R(P);let w=O;c=Object.assign({},P,k(w)?{offset:w.map(V)}:null)}let d,A;this.keyframeEffects.has(l)?(A=this.keyframeEffects.get(l),d=this.animations.get(A),A?.setKeyframes?.(c),A?.updateTiming?.(u)):(A=new KeyframeEffect(l,c,u),d=new Animation(A,u.timeline),this.keyframeEffects.set(l,A),this.animations.set(A,d)),d.playbackRate=y,d.onfinish=()=>{typeof a=="function"&&a.call(this,l,p,t,d)},d.oncancel=()=>{typeof o=="function"&&o.call(this,l,p,t,d)},this.computedOptions.set(l,u),this.computedKeyframes.set(l,c)})}updateOptions(e={}){try{let t=le(e);this.options=Object.assign({},oe,this.options,t);let n=["easing","loop","endDelay","duration","speed","delay","timelineOffset","direction","extend","fillMode","offset"],{padEndDelay:s,onfinish:r,oncancel:a,autoplay:o,target:l,targets:p,...y}=z(n,this.options);this.properties=z([...n,"keyframes","padEndDelay","onfinish","oncancel","autoplay","target","targets"],t);let h=this.targets.values(),b=[...new Set([...h,...W(p),...W(l)])];this.targets.clear(),b.forEach((m,f)=>{this.targets.set(f,m),this.targetIndexes.set(m,f)});let u=this.targets.size,c=this.createArrayOfComputedOptions(t,u);if(this.createAnimations({arrOfComputedOptions:c,padEndDelay:s,oldCSSProperties:y,onfinish:r,oncancel:a},u),this.maxSpeed=this.maxSpeed??this.options.speed,this.minDelay=this.minDelay??this.options.delay,this.totalDuration=this.totalDuration??this.options.duration,this.mainAnimation?(this.mainkeyframeEffect?.updateTiming?.({duration:this.totalDuration}),(!this.mainkeyframeEffect.setKeyframes||!this.mainkeyframeEffect.updateTiming)&&console.warn("@okikio/animate - `KeyframeEffect.setKeyframes` and/or `KeyframeEffect.updateTiming` are not supported in this browser.")):(this.mainkeyframeEffect=new KeyframeEffect(this.mainElement,[{opacity:"0"},{opacity:"1"}],{duration:this.totalDuration,easing:"linear"}),this.mainAnimation=new Animation(this.mainkeyframeEffect,this.options.timeline)),this.mainAnimation.playbackRate=this.maxSpeed,this.mainAnimation.onfinish=()=>{if(this.emit("finish",this),this.mainAnimation){let m=this.getPlayState();this.is(m)||this.emit("playstate-change",m,this),this.stopLoop()}},this.mainAnimation.oncancel=()=>{if(this.emit("cancel",this),this.mainAnimation){let m=this.getPlayState();this.is(m)||this.emit("playstate-change",m,this),this.stopLoop()}},o){let m=window.setTimeout(()=>{this.emit("begin",this),m=window.clearTimeout(m)},0);this.play()}else this.pause()}catch(t){this.emit("error",t)}}add(e){let t=this.getProgress(),n=this.is("running"),s=this.is("paused");this.updateOptions({target:e}),this.setProgress(t),n?this.play():s&&this.pause()}removeTarget(e){let t=this.keyframeEffects.get(e);this.animations.delete(t),t=null,this.computedKeyframes.delete(e),this.computedOptions.delete(e),this.keyframeEffects.delete(e);let n=this.targetIndexes.get(e);this.targets.delete(n),this.targetIndexes.delete(e)}remove(e){this.removeTarget(e);let t=new Set([].concat(this.targets.values()));this.options.target=[...t],this.options.targets=[],t.clear(),t=null;let n=this.getProgress(),s=this.is("running"),r=this.is("paused");this.updateOptions(),s?this.play():r&&this.pause(),this.setProgress(n)}on(e,t,n){return this?.emitter?.on(e,t,n??this),this}off(e,t,n){return this?.emitter?.off(e,t,n??this),this}emit(e,...t){return this?.emitter?.emit(e,...t),this}toJSON(){return this.options}get[Symbol.toStringTag](){return"Animate"}},N=_;N.pauseOnPageHidden=!0;var pe=(i={})=>new N(i),ke=pe;export{N as Animate,L as CSSArrValue,D as CSSValue,oe as DefaultAnimationOptions,ee as EASINGS,fe as EFFECTS,ae as EasingKeys,te as GetEase,G as KeyframeParse,J as ParseTransformableCSSKeyframes,R as ParseTransformableCSSProperties,$ as TransformFunctionNames,Y as UnitDEG,E as UnitDEGCSSValue,j as UnitLess,x as UnitLessCSSValue,F as UnitPX,C as UnitPXCSSValue,X as addCSSUnit,pe as animate,re as computeOption,B as createTransformProperty,ke as default,se as flatten,ne as getElements,W as getTargets,k as isValid,Q as mapAnimationOptions,v as mapObject,z as omit,V as parseOffset,le as parseOptions,q as toArr,ie as transpose}; +var I=class{constructor(e){this.map=new Map(e)}getMap(){return this.map}get(e){return this.map.get(e)}keys(){return Array.from(this.map.keys())}values(){return Array.from(this.map.values())}set(e,t){return this.map.set(e,t),this}add(e){let n=this.size;return this.set(n,e),this}get size(){return this.map.size}get length(){return this.map.size}last(e=1){let t=this.keys()[this.size-e];return this.get(t)}delete(e){return this.map.delete(e)}remove(e){return this.map.delete(e),this}clear(){return this.map.clear(),this}has(e){return this.map.has(e)}entries(){return this.map.entries()}forEach(e,t){return this.map.forEach(e,t),this}[Symbol.iterator](){return this.entries()}},Z=(i,e,...t)=>{i.forEach(n=>{n[e](...t)})};var G=({callback:i=()=>{},scope:e=null,name:t="event"})=>({callback:i,scope:e,name:t}),w=class extends I{constructor(e="event"){super();this.name=e}},X=class extends I{constructor(){super()}getEvent(e){let t=this.get(e);return t instanceof w?t:(this.set(e,new w(e)),this.get(e))}newListener(e,t,n){let s=this.getEvent(e);return s.add(G({name:e,callback:t,scope:n})),s}on(e,t,n){if(typeof e=="undefined"||e==null)return this;typeof e=="string"&&(e=e.trim().split(/\s/g));let s,r,a=typeof e=="object"&&!Array.isArray(e),o=a?t:n;return a||(r=t),Object.keys(e).forEach(p=>{s=a?p:e[p],a&&(r=e[p]),this.newListener(s,r,o)},this),this}removeListener(e,t,n){let s=this.get(e);if(s instanceof w&&t){let r=G({name:e,callback:t,scope:n});s.forEach((a,o)=>{if(a.callback===r.callback&&a.scope===r.scope)return s.remove(o)})}return s}off(e,t,n){if(typeof e=="undefined"||e==null)return this;typeof e=="string"&&(e=e.trim().split(/\s/g));let s,r,a=typeof e=="object"&&!Array.isArray(e),o=a?t:n;return a||(r=t),Object.keys(e).forEach(p=>{s=a?p:e[p],a&&(r=e[p]),typeof r=="function"?this.removeListener(s,r,o):this.remove(s)},this),this}once(e,t,n){if(typeof e=="undefined"||e==null)return this;typeof e=="string"&&(e=e.trim().split(/\s/g));let s=typeof e=="object"&&!Array.isArray(e);return Object.keys(e).forEach(r=>{let a=s?r:e[r],o=s?e[r]:t,p=s?t:n,l=(...f)=>{o.apply(p,f),this.removeListener(a,l,p)};this.newListener(a,l,p)},this),this}emit(e,...t){return typeof e=="undefined"||e==null?this:(typeof e=="string"&&(e=e.trim().split(/\s/g)),e.forEach(n=>{let s=this.get(n);s instanceof w&&s.forEach(r=>{let{callback:a,scope:o}=r;a.apply(o,t)})},this),this)}clear(){return Z(this,"clear"),super.clear(),this}};var j=i=>typeof i=="string"?i.includes("%")?parseFloat(i)/100:i=="from"?0:i=="to"?1:parseFloat(i):i,$=i=>{let e=new Set,t=Object.keys(i),n=t.length;for(let s=0;ss.offset-r.offset)},ye={};var F=(i="")=>e=>typeof e=="string"?e:`${e}${i}`,D=F(),Y=F("px"),q=F("deg"),W=i=>Array.isArray(i)||typeof i=="string"?(typeof i=="string"&&(i=i.split(",")),i):[i],k=i=>Array.isArray(i)||typeof i=="string"?Boolean(i.length):i!=null&&i!=null,v=i=>e=>k(e)?W(e).map(t=>{if(typeof t!="number"&&typeof t!="string")return t;let n=Number(t),s=Number.isNaN(n)?typeof t=="string"?t.trim():t:n;return i(s)}):[],ne=(...i)=>{let e=0;i=i.map(s=>{let r=W(s),a=r.length;return a>e&&(e=a),r});let t=[],n=i.length;for(let s=0;sW(i).map(v(e)),B=["translate","translate3d","translateX","translateY","translateZ","rotate","rotate3d","rotateX","rotateY","rotateZ","scale","scale3d","scaleX","scaleY","scaleZ","skew","skewX","skewY","perspective"],R=i=>{let e="",t=B.length;for(let n=0;n{let{perspective:e,rotate:t,rotate3d:n,rotateX:s,rotateY:r,rotateZ:a,translate:o,translate3d:p,translateX:l,translateY:f,translateZ:b,scale:d,scale3d:h,scaleX:u,scaleY:c,scaleZ:m,skew:y,skewX:g,skewY:T,...O}=i;o=M(o,Y),p=M(p,Y),l=C(l),f=C(f),b=C(b),t=M(t,q),n=M(n,D),s=A(s),r=A(r),a=A(a),d=M(d,D),h=M(h,D),u=P(u),c=P(c),m=P(m),y=M(y,q),g=A(g),T=A(T),e=C(e);let S=ne(o,p,l,f,b,t,n,s,r,a,d,h,u,c,m,y,g,T,e).filter(k).map(R);return O=z(O,E=>[].concat(E).map(x=>""+x)),Object.assign({},k(S)?{transform:S}:null,O)},Q=i=>i.map(e=>{let{translate:t,translate3d:n,translateX:s,translateY:r,translateZ:a,rotate:o,rotate3d:p,rotateX:l,rotateY:f,rotateZ:b,scale:d,scale3d:h,scaleX:u,scaleY:c,scaleZ:m,skew:y,skewX:g,skewY:T,perspective:O,easing:S,iterations:E,offset:x,...K}=e;return t=C(t),n=C(n),s=C(s)[0],r=C(r)[0],a=C(a)[0],o=A(o),p=P(p),l=A(l)[0],f=A(f)[0],b=A(b)[0],d=P(d),h=P(h),u=P(u)[0],c=P(c)[0],m=P(m)[0],y=A(y),g=A(g)[0],T=A(T)[0],O=C(O)[0],[K,t,n,s,r,a,o,p,l,f,b,d,h,u,c,m,y,g,T,O]}).map(([e,...t])=>{let n=R(t);return Object.assign({},k(n)?{transform:n}:null,e)});var se=i=>typeof i=="string"?Array.from(document.querySelectorAll(i)):[i],re=i=>[].concat(...i),_=i=>Array.isArray(i)?re(i.map(_)):typeof i=="string"||i instanceof Node?se(i):i instanceof NodeList||i instanceof HTMLCollection?Array.from(i):[],ae=(i,e,t)=>typeof i=="function"?i.apply(t,e):i,z=(i,e)=>{let t=Object.keys(i),n,s,r={};for(let a=0,o=t.length;az(i,n=>ae(n,e,t)),te={in:"ease-in",out:"ease-out","in-out":"ease-in-out","in-sine":"cubic-bezier(0.47, 0, 0.745, 0.715)","out-sine":"cubic-bezier(0.39, 0.575, 0.565, 1)","in-out-sine":"cubic-bezier(0.445, 0.05, 0.55, 0.95)","in-quad":"cubic-bezier(0.55, 0.085, 0.68, 0.53)","out-quad":"cubic-bezier(0.25, 0.46, 0.45, 0.94)","in-out-quad":"cubic-bezier(0.455, 0.03, 0.515, 0.955)","in-cubic":"cubic-bezier(0.55, 0.055, 0.675, 0.19)","out-cubic":"cubic-bezier(0.215, 0.61, 0.355, 1)","in-out-cubic":"cubic-bezier(0.645, 0.045, 0.355, 1)","in-quart":"cubic-bezier(0.895, 0.03, 0.685, 0.22)","out-quart":"cubic-bezier(0.165, 0.84, 0.44, 1)","in-out-quart":"cubic-bezier(0.77, 0, 0.175, 1)","in-quint":"cubic-bezier(0.755, 0.05, 0.855, 0.06)","out-quint":"cubic-bezier(0.23, 1, 0.32, 1)","in-out-quint":"cubic-bezier(0.86, 0, 0.07, 1)","in-expo":"cubic-bezier(0.95, 0.05, 0.795, 0.035)","out-expo":"cubic-bezier(0.19, 1, 0.22, 1)","in-out-expo":"cubic-bezier(1, 0, 0, 1)","in-circ":"cubic-bezier(0.6, 0.04, 0.98, 0.335)","out-circ":"cubic-bezier(0.075, 0.82, 0.165, 1)","in-out-circ":"cubic-bezier(0.785, 0.135, 0.15, 0.86)","in-back":"cubic-bezier(0.6, -0.28, 0.735, 0.045)","out-back":"cubic-bezier(0.175, 0.885, 0.32, 1.275)","in-out-back":"cubic-bezier(0.68, -0.55, 0.265, 1.55)"},oe=Object.keys(te),ie=i=>{let e=i.replace(/^ease-/,"");return oe.includes(e)?te[e]:i},le={keyframes:[],offset:[],loop:1,delay:0,speed:1,endDelay:0,easing:"ease",timelineOffset:0,autoplay:!0,duration:1e3,fillMode:"none",direction:"normal",padEndDelay:!1,timeline:document.timeline,extend:{}},pe=i=>{let{options:e,...t}=i,n=e instanceof H?e.options:Array.isArray(e)?e?.[0]?.options:e;return Object.assign({},n,t)},N=(i,e)=>{let t={...e};for(;i.length;){let{[i.pop()]:n,...s}=t;t=s}return t},U=class{constructor(e){this.options={};this.properties={};this.totalDuration=0;this.emitter=new X;this.targets=new I;this.targetIndexes=new WeakMap;this.keyframeEffects=new WeakMap;this.computedOptions=new WeakMap;this.animations=new WeakMap;this.computedKeyframes=new WeakMap;this.loop=this.loop.bind(this),this.onVisibilityChange=this.onVisibilityChange.bind(this),this.on("error",console.error),this.updateOptions(e),this.mainAnimation&&(this.visibilityPlayState=this.getPlayState(),U.pauseOnPageHidden&&document.addEventListener("visibilitychange",this.onVisibilityChange,!1)),this.newPromise()}onVisibilityChange(){document.hidden?(this.visibilityPlayState=this.getPlayState(),this.is("running")&&(this.loop(),this.pause())):this.visibilityPlayState=="running"&&this.is("paused")&&this.play()}newPromise(){return this.promise=new Promise((e,t)=>{this?.emitter?.once?.("finish",()=>e([this])),this?.emitter?.once?.("error",n=>t(n))}),this.promise}then(e,t){return e=e?.bind(this),t=t?.bind(this),this?.promise?.then?.(e,t),this}catch(e){return e=e?.bind(this),this.promise?.catch?.(e),this}finally(e){return e=e?.bind(this),this.promise?.finally?.(e),this}loop(){this.stopLoop(),this.animationFrame=window.requestAnimationFrame(this.loop),this.emit("update",this.getProgress(),this)}stopLoop(){window.cancelAnimationFrame(this.animationFrame)}allAnimations(e){return this.targets.forEach(t=>{let n=this.keyframeEffects.get(t),s=this.animations.get(n);return e(s,t)}),this}all(e){return this.mainAnimation&&e(this.mainAnimation,this.mainElement),this.allAnimations(e),this}beginEvent(){this.getProgress()==0&&this.emit("begin",this)}play(){let e=this.getPlayState();return this.beginEvent(),this.all(t=>t.play()),this.emit("play",e,this),this.is(e)||this.emit("playstate-change",e,this),this.loop(),this}pause(){let e=this.getPlayState();return this.all(t=>t.pause()),this.emit("pause",e,this),this.is(e)||this.emit("playstate-change",e,this),this.stopLoop(),this}reverse(){return this.all(e=>e.reverse()),this}reset(){return this.setProgress(0),this.options.autoplay?this.play():this.pause(),this}cancel(){return this.all(e=>e.cancel()),this}finish(){return this.all(e=>e.finish()),this}stop(){this.cancel(),this.stopLoop(),document.removeEventListener("visibilitychange",this.onVisibilityChange,!1),this.targets.forEach(e=>this.removeTarget(e)),this.emit("stop"),this.emitter.clear(),this.mainkeyframeEffect=null,this.mainAnimation=null,this.mainElement=null,this.promise=null,this.computedOptions=null,this.animations=null,this.keyframeEffects=null,this.emitter=null,this.targets=null,this.options=null,this.properties=null}getAnimation(e){let t=this.keyframeEffects.get(e);return this.animations.get(t)}getTiming(e){let t=this.computedOptions.get(e)??{},n=this.keyframeEffects.get(e).getTiming?.()??{};return{...t,...n}}getCurrentTime(){return this.mainAnimation.currentTime}getProgress(){return this.getCurrentTime()/this.totalDuration*100}getSpeed(){return this.mainAnimation.playbackRate}getPlayState(){return this.mainAnimation.playState}is(e){return this.getPlayState()==e}setCurrentTime(e){return this.all(t=>t.currentTime=e),this.emit("update",this.getProgress()),this}setProgress(e){let t=e/100*this.totalDuration;return this.setCurrentTime(t),this}setSpeed(e=1){return this.maxSpeed=e,this.all(t=>{t.updatePlaybackRate?t.updatePlaybackRate(e):t.playbackRate=e}),this}createArrayOfComputedOptions(e,t){let n=[];return this.targets.forEach((s,r)=>{let a=this.computedOptions.get(s)??{},o=g=>{let T=g;return g=="loop"&&(T="iterations"),g=="fillMode"&&(T="fill"),e[g]??a[T]??this.options[g]},p=Object.assign({easing:o("easing"),iterations:o("loop"),direction:o("direction"),endDelay:o("endDelay"),duration:o("duration"),speed:o("speed"),delay:o("delay"),timelineOffset:o("timelineOffset"),keyframes:o("keyframes")},o("extend")??{}),l=ee(p,[r,t,s],this);typeof l.easing=="string"&&(l.easing=ie(l.easing)),l.iterations===!0&&(l.iterations=Infinity),l.fill=o("fillMode");let{timelineOffset:f,speed:b,endDelay:d,delay:h,duration:u,iterations:c,...m}=l;c=Number(c),u=Number(u),d=Number(d),b=Number(b),h=Number(h)+Number(f);let y=h+u*c+d;this.totalDuration{let{speed:b,keyframes:d,tempDurations:h,...u}=n[f];s&&u.endDelay==0&&Math.abs(u.iterations)!=Math.abs(Infinity)&&(u.endDelay=this.totalDuration-h);let c,m,y=d;typeof y=="object"&&(y=$(y));let g=this.computedKeyframes.get(l)??{},T=Object.assign({},r,g),O=z(T,(x,K)=>this.properties[K]??x);if(m=k(y)?y:O,Array.isArray(m))c=m.map(x=>{let{easing:K,offset:L,...V}=N(["speed","loop"],x);return Object.assign({},V,typeof K=="string"?{easing:ie(K)}:null,typeof L=="string"||typeof L=="number"?{offset:j(L)}:null)}),c=Q(c);else{let x=N(["keyframes"],m),{offset:K,...L}=ee(x,[f,t,l],this);L=J(L);let V=K;c=Object.assign({},L,k(V)?{offset:V.map(j)}:null)}let S,E;this.keyframeEffects.has(l)?(E=this.keyframeEffects.get(l),S=this.animations.get(E),E?.setKeyframes?.(c),E?.updateTiming?.(u)):(E=new KeyframeEffect(l,c,u),S=new Animation(E,p),this.keyframeEffects.set(l,E),this.animations.set(E,S)),S.playbackRate=b,S.onfinish=()=>{typeof a=="function"&&a.call(this,l,f,t,S)},S.oncancel=()=>{typeof o=="function"&&o.call(this,l,f,t,S)},this.computedOptions.set(l,u),this.computedKeyframes.set(l,c)})}updateOptions(e={}){try{let t=pe(e);this.options=Object.assign({},le,this.options,t);let n=["easing","loop","endDelay","duration","speed","delay","timelineOffset","direction","extend","fillMode","offset"],{padEndDelay:s,autoplay:r,target:a,targets:o,timeline:p,onfinish:l,oncancel:f,...b}=N(n,this.options);this.properties=N([...n,"keyframes","padEndDelay","onfinish","oncancel","autoplay","target","targets","timeline"],t);let d=this.targets.values(),h=[...new Set([...d,..._(o),..._(a)])];this.targets.clear(),h.forEach((m,y)=>{this.targets.set(y,m),this.targetIndexes.set(m,y)});let u=this.targets.size,c=this.createArrayOfComputedOptions(t,u);if(this.createAnimations({arrOfComputedOptions:c,padEndDelay:s,oldCSSProperties:b,onfinish:l,oncancel:f,timeline:p},u),this.maxSpeed=this.maxSpeed??this.options.speed,this.minDelay=this.minDelay??this.options.delay,this.totalDuration=this.totalDuration??this.options.duration,this.mainAnimation?(this.mainkeyframeEffect?.updateTiming?.({duration:this.totalDuration}),(!this.mainkeyframeEffect.setKeyframes||!this.mainkeyframeEffect.updateTiming)&&console.warn("@okikio/animate - `KeyframeEffect.setKeyframes` and/or `KeyframeEffect.updateTiming` are not supported in this browser.")):(this.mainkeyframeEffect=new KeyframeEffect(this.mainElement,[{opacity:"0"},{opacity:"1"}],{duration:this.totalDuration,easing:"linear"}),this.mainAnimation=new Animation(this.mainkeyframeEffect,p)),this.mainAnimation.playbackRate=this.maxSpeed,this.mainAnimation.onfinish=()=>{if(this.emit("finish",this),this.mainAnimation){let m=this.getPlayState();this.is(m)||this.emit("playstate-change",m,this),this.stopLoop()}},this.mainAnimation.oncancel=()=>{if(this.emit("cancel",this),this.mainAnimation){let m=this.getPlayState();this.is(m)||this.emit("playstate-change",m,this),this.stopLoop()}},r){let m=window.setTimeout(()=>{this.emit("begin",this),m=window.clearTimeout(m)},0);this.play()}else this.pause()}catch(t){this.emit("error",t)}}add(e){let t=this.getProgress(),n=this.is("running"),s=this.is("paused");this.updateOptions({target:e}),this.setProgress(t),n?this.play():s&&this.pause()}removeTarget(e){let t=this.keyframeEffects.get(e);this.animations.delete(t),t=null,this.computedKeyframes.delete(e),this.computedOptions.delete(e),this.keyframeEffects.delete(e);let n=this.targetIndexes.get(e);this.targets.delete(n),this.targetIndexes.delete(e)}remove(e){this.removeTarget(e);let t=new Set([].concat(this.targets.values()));this.options.target=[...t],this.options.targets=[],t.clear(),t=null;let n=this.getProgress(),s=this.is("running"),r=this.is("paused");this.updateOptions(),s?this.play():r&&this.pause(),this.setProgress(n)}on(e,t,n){return this?.emitter?.on(e,t,n??this),this}off(e,t,n){return this?.emitter?.off(e,t,n??this),this}emit(e,...t){return this?.emitter?.emit(e,...t),this}toJSON(){return this.options}get[Symbol.toStringTag](){return"Animate"}},H=U;H.pauseOnPageHidden=!0;var me=(i={})=>new H(i),Ce=me;export{H as Animate,M as CSSArrValue,v as CSSValue,le as DefaultAnimationOptions,te as EASINGS,ye as EFFECTS,oe as EasingKeys,ie as GetEase,$ as KeyframeParse,Q as ParseTransformableCSSKeyframes,J as ParseTransformableCSSProperties,B as TransformFunctionNames,q as UnitDEG,A as UnitDEGCSSValue,D as UnitLess,P as UnitLessCSSValue,Y as UnitPX,C as UnitPXCSSValue,F as addCSSUnit,me as animate,ae as computeOption,R as createTransformProperty,Ce as default,re as flatten,se as getElements,_ as getTargets,k as isValid,ee as mapAnimationOptions,z as mapObject,N as omit,j as parseOffset,pe as parseOptions,W as toArr,ne as transpose}; diff --git a/packages/animate/lib/api.js b/packages/animate/lib/api.js index 2c9dba7..ee00705 100644 --- a/packages/animate/lib/api.js +++ b/packages/animate/lib/api.js @@ -1 +1 @@ -var animate=(()=>{var me=Object.defineProperty;var ue=(i,e)=>{for(var t in e)me(i,t,{get:e[t],enumerable:!0})};var ye={};ue(ye,{Animate:()=>z,CSSArrValue:()=>L,CSSValue:()=>j,DefaultAnimationOptions:()=>oe,EASINGS:()=>R,EFFECTS:()=>ce,EasingKeys:()=>ae,GetEase:()=>J,KeyframeParse:()=>_,ParseTransformableCSSKeyframes:()=>$,ParseTransformableCSSProperties:()=>G,TransformFunctionNames:()=>U,UnitDEG:()=>F,UnitDEGCSSValue:()=>A,UnitLess:()=>V,UnitLessCSSValue:()=>O,UnitPX:()=>X,UnitPXCSSValue:()=>C,addCSSUnit:()=>H,animate:()=>pe,computeOption:()=>re,createTransformProperty:()=>Z,default:()=>fe,flatten:()=>se,getElements:()=>ne,getTargets:()=>q,isValid:()=>k,mapAnimationOptions:()=>B,mapObject:()=>D,omit:()=>v,parseOffset:()=>w,parseOptions:()=>le,toArr:()=>Y,transpose:()=>ie});var M=class{constructor(e){this.map=new Map(e)}getMap(){return this.map}get(e){return this.map.get(e)}keys(){return Array.from(this.map.keys())}values(){return Array.from(this.map.values())}set(e,t){return this.map.set(e,t),this}add(e){let n=this.size;return this.set(n,e),this}get size(){return this.map.size}get length(){return this.map.size}last(e=1){let t=this.keys()[this.size-e];return this.get(t)}delete(e){return this.map.delete(e)}remove(e){return this.map.delete(e),this}clear(){return this.map.clear(),this}has(e){return this.map.has(e)}entries(){return this.map.entries()}forEach(e,t){return this.map.forEach(e,t),this}[Symbol.iterator](){return this.entries()}},ee=(i,e,...t)=>{i.forEach(n=>{n[e](...t)})};var te=({callback:i=()=>{},scope:e=null,name:t="event"})=>({callback:i,scope:e,name:t}),I=class extends M{constructor(e="event"){super();this.name=e}},W=class extends M{constructor(){super()}getEvent(e){let t=this.get(e);return t instanceof I?t:(this.set(e,new I(e)),this.get(e))}newListener(e,t,n){let s=this.getEvent(e);return s.add(te({name:e,callback:t,scope:n})),s}on(e,t,n){if(typeof e=="undefined"||e==null)return this;typeof e=="string"&&(e=e.trim().split(/\s/g));let s,r,a=typeof e=="object"&&!Array.isArray(e),o=a?t:n;return a||(r=t),Object.keys(e).forEach(l=>{s=a?l:e[l],a&&(r=e[l]),this.newListener(s,r,o)},this),this}removeListener(e,t,n){let s=this.get(e);if(s instanceof I&&t){let r=te({name:e,callback:t,scope:n});s.forEach((a,o)=>{if(a.callback===r.callback&&a.scope===r.scope)return s.remove(o)})}return s}off(e,t,n){if(typeof e=="undefined"||e==null)return this;typeof e=="string"&&(e=e.trim().split(/\s/g));let s,r,a=typeof e=="object"&&!Array.isArray(e),o=a?t:n;return a||(r=t),Object.keys(e).forEach(l=>{s=a?l:e[l],a&&(r=e[l]),typeof r=="function"?this.removeListener(s,r,o):this.remove(s)},this),this}once(e,t,n){if(typeof e=="undefined"||e==null)return this;typeof e=="string"&&(e=e.trim().split(/\s/g));let s=typeof e=="object"&&!Array.isArray(e);return Object.keys(e).forEach(r=>{let a=s?r:e[r],o=s?e[r]:t,l=s?t:n,p=(...y)=>{o.apply(l,y),this.removeListener(a,p,l)};this.newListener(a,p,l)},this),this}emit(e,...t){return typeof e=="undefined"||e==null?this:(typeof e=="string"&&(e=e.trim().split(/\s/g)),e.forEach(n=>{let s=this.get(n);s instanceof I&&s.forEach(r=>{let{callback:a,scope:o}=r;a.apply(o,t)})},this),this)}clear(){return ee(this,"clear"),super.clear(),this}};var w=i=>typeof i=="string"?i.includes("%")?parseFloat(i)/100:i=="from"?0:i=="to"?1:parseFloat(i):i,_=i=>{let e=new Set,t=Object.keys(i),n=t.length;for(let s=0;ss.offset-r.offset)},ce={};var H=(i="")=>e=>typeof e=="string"?e:`${e}${i}`,V=H(),X=H("px"),F=H("deg"),Y=i=>Array.isArray(i)||typeof i=="string"?(typeof i=="string"&&(i=i.split(",")),i):[i],k=i=>Array.isArray(i)||typeof i=="string"?Boolean(i.length):i!=null&&i!=null,j=i=>e=>k(e)?Y(e).map(t=>{if(typeof t!="number"&&typeof t!="string")return t;let n=Number(t),s=Number.isNaN(n)?typeof t=="string"?t.trim():t:n;return i(s)}):[],ie=(...i)=>{let e=0;i=i.map(s=>{let r=Y(s),a=r.length;return a>e&&(e=a),r});let t=[],n=i.length;for(let s=0;sY(i).map(j(e)),U=["translate","translate3d","translateX","translateY","translateZ","rotate","rotate3d","rotateX","rotateY","rotateZ","scale","scale3d","scaleX","scaleY","scaleZ","skew","skewX","skewY","perspective"],Z=i=>{let e="",t=U.length;for(let n=0;n{let{perspective:e,rotate:t,rotate3d:n,rotateX:s,rotateY:r,rotateZ:a,translate:o,translate3d:l,translateX:p,translateY:y,translateZ:h,scale:b,scale3d:u,scaleX:c,scaleY:m,scaleZ:f,skew:T,skewX:g,skewY:S,...d}=i;o=L(o,X),l=L(l,X),p=C(p),y=C(y),h=C(h),t=L(t,F),n=L(n,V),s=A(s),r=A(r),a=A(a),b=L(b,V),u=L(u,V),c=O(c),m=O(m),f=O(f),T=L(T,F),g=A(g),S=A(S),e=C(e);let E=ie(o,l,p,y,h,t,n,s,r,a,b,u,c,m,f,T,g,S,e).map(Z);return d=D(d,K=>[].concat(K).map(P=>""+P)),Object.assign({},k(E)?{transform:E}:null,d)},$=i=>i.map(e=>{let{translate:t,translate3d:n,translateX:s,translateY:r,translateZ:a,rotate:o,rotate3d:l,rotateX:p,rotateY:y,rotateZ:h,scale:b,scale3d:u,scaleX:c,scaleY:m,scaleZ:f,skew:T,skewX:g,skewY:S,perspective:d,easing:E,iterations:K,offset:P,...x}=e;return t=C(t),n=C(n),s=C(s)[0],r=C(r)[0],a=C(a)[0],o=A(o),l=O(l),p=A(p)[0],y=A(y)[0],h=A(h)[0],b=O(b),u=O(u),c=O(c)[0],m=O(m)[0],f=O(f)[0],T=A(T),g=A(g)[0],S=A(S)[0],d=C(d)[0],[x,t,n,s,r,a,o,l,p,y,h,b,u,c,m,f,T,g,S,d]}).map(([e,...t])=>{let n=Z(t);return Object.assign({},k(n)?{transform:n}:null,e)});var ne=i=>typeof i=="string"?Array.from(document.querySelectorAll(i)):[i],se=i=>[].concat(...i),q=i=>Array.isArray(i)?se(i.map(q)):typeof i=="string"||i instanceof Node?ne(i):i instanceof NodeList||i instanceof HTMLCollection?Array.from(i):[],re=(i,e,t)=>typeof i=="function"?i.apply(t,e):i,D=(i,e)=>{let t=Object.keys(i),n,s,r={};for(let a=0,o=t.length;aD(i,n=>re(n,e,t)),R={in:"ease-in",out:"ease-out","in-out":"ease-in-out","in-sine":"cubic-bezier(0.47, 0, 0.745, 0.715)","out-sine":"cubic-bezier(0.39, 0.575, 0.565, 1)","in-out-sine":"cubic-bezier(0.445, 0.05, 0.55, 0.95)","in-quad":"cubic-bezier(0.55, 0.085, 0.68, 0.53)","out-quad":"cubic-bezier(0.25, 0.46, 0.45, 0.94)","in-out-quad":"cubic-bezier(0.455, 0.03, 0.515, 0.955)","in-cubic":"cubic-bezier(0.55, 0.055, 0.675, 0.19)","out-cubic":"cubic-bezier(0.215, 0.61, 0.355, 1)","in-out-cubic":"cubic-bezier(0.645, 0.045, 0.355, 1)","in-quart":"cubic-bezier(0.895, 0.03, 0.685, 0.22)","out-quart":"cubic-bezier(0.165, 0.84, 0.44, 1)","in-out-quart":"cubic-bezier(0.77, 0, 0.175, 1)","in-quint":"cubic-bezier(0.755, 0.05, 0.855, 0.06)","out-quint":"cubic-bezier(0.23, 1, 0.32, 1)","in-out-quint":"cubic-bezier(0.86, 0, 0.07, 1)","in-expo":"cubic-bezier(0.95, 0.05, 0.795, 0.035)","out-expo":"cubic-bezier(0.19, 1, 0.22, 1)","in-out-expo":"cubic-bezier(1, 0, 0, 1)","in-circ":"cubic-bezier(0.6, 0.04, 0.98, 0.335)","out-circ":"cubic-bezier(0.075, 0.82, 0.165, 1)","in-out-circ":"cubic-bezier(0.785, 0.135, 0.15, 0.86)","in-back":"cubic-bezier(0.6, -0.28, 0.735, 0.045)","out-back":"cubic-bezier(0.175, 0.885, 0.32, 1.275)","in-out-back":"cubic-bezier(0.68, -0.55, 0.265, 1.55)"},ae=Object.keys(R),J=i=>{let e=i.replace(/^ease-/,"");return ae.includes(e)?R[e]:i},oe={keyframes:[],offset:[],loop:1,delay:0,speed:1,endDelay:0,easing:"ease",timelineOffset:0,autoplay:!0,duration:1e3,fillMode:"none",direction:"normal",padEndDelay:!1,extend:{}},le=i=>{let{options:e,...t}=i,n=e instanceof z?e.options:Array.isArray(e)?e?.[0]?.options:e;return Object.assign({},n,t)},v=(i,e)=>{let t={...e};for(;i.length;){let{[i.pop()]:n,...s}=t;t=s}return t},Q=class{constructor(e){this.options={};this.properties={};this.totalDuration=0;this.emitter=new W;this.targets=new M;this.targetIndexes=new WeakMap;this.keyframeEffects=new WeakMap;this.computedOptions=new WeakMap;this.animations=new WeakMap;this.computedKeyframes=new WeakMap;this.loop=this.loop.bind(this),this.onVisibilityChange=this.onVisibilityChange.bind(this),this.on("error",t=>console.error(t)),this.updateOptions(e),this.visibilityPlayState=this.getPlayState(),Q.pauseOnPageHidden&&document.addEventListener("visibilitychange",this.onVisibilityChange,!1),this.newPromise()}onVisibilityChange(){document.hidden?(this.visibilityPlayState=this.getPlayState(),this.is("running")&&(this.loop(),this.pause())):this.visibilityPlayState=="running"&&this.is("paused")&&this.play()}newPromise(){return this.promise=new Promise((e,t)=>{this?.emitter?.once?.("finish",()=>e([this])),this?.emitter?.once?.("error",n=>t(n))}),this.promise}then(e,t){return e=e?.bind(this),t=t?.bind(this),this?.promise?.then?.(e,t),this}catch(e){return e=e?.bind(this),this.promise?.catch?.(e),this}finally(e){return e=e?.bind(this),this.promise?.finally?.(e),this}loop(){this.stopLoop(),this.animationFrame=window.requestAnimationFrame(this.loop),this.emit("update",this.getProgress(),this)}stopLoop(){window.cancelAnimationFrame(this.animationFrame)}allAnimations(e){return this.targets.forEach(t=>{let n=this.keyframeEffects.get(t),s=this.animations.get(n);return e(s,t)}),this}all(e){return this.mainAnimation&&e(this.mainAnimation,this.mainElement),this.allAnimations(e),this}beginEvent(){this.getProgress()==0&&this.emit("begin",this)}play(){let e=this.getPlayState();return this.beginEvent(),this.all(t=>t.play()),this.emit("play",e,this),this.is(e)||this.emit("playstate-change",e,this),this.loop(),this}pause(){let e=this.getPlayState();return this.all(t=>t.pause()),this.emit("pause",e,this),this.is(e)||this.emit("playstate-change",e,this),this.stopLoop(),this}reverse(){return this.all(e=>e.reverse()),this}reset(){return this.setProgress(0),this.options.autoplay?this.play():this.pause(),this}cancel(){return this.all(e=>e.cancel()),this}finish(){return this.all(e=>e.finish()),this}stop(){this.cancel(),this.stopLoop(),document.removeEventListener("visibilitychange",this.onVisibilityChange,!1),this.targets.forEach(e=>this.removeTarget(e)),this.emit("stop"),this.emitter.clear(),this.mainkeyframeEffect=null,this.mainAnimation=null,this.mainElement=null,this.promise=null,this.computedOptions=null,this.animations=null,this.keyframeEffects=null,this.emitter=null,this.targets=null,this.options=null,this.properties=null}getAnimation(e){let t=this.keyframeEffects.get(e);return this.animations.get(t)}getTiming(e){let t=this.computedOptions.get(e)??{},n=this.keyframeEffects.get(e).getTiming?.()??{};return{...t,...n}}getCurrentTime(){return this.mainAnimation.currentTime}getProgress(){return this.getCurrentTime()/this.totalDuration*100}getSpeed(){return this.mainAnimation.playbackRate}getPlayState(){return this.mainAnimation.playState}is(e){return this.getPlayState()==e}setCurrentTime(e){return this.all(t=>t.currentTime=e),this.emit("update",this.getProgress()),this}setProgress(e){let t=e/100*this.totalDuration;return this.setCurrentTime(t),this}setSpeed(e=1){return this.maxSpeed=e,this.all(t=>{t.updatePlaybackRate?t.updatePlaybackRate(e):t.playbackRate=e}),this}createArrayOfComputedOptions(e,t){let n=[];return this.targets.forEach((s,r)=>{let a=this.computedOptions.get(s)??{},o=g=>{let S=g;return g=="loop"&&(S="iterations"),g=="fillMode"&&(S="fill"),e[g]??a[S]??this.options[g]},l=Object.assign({easing:o("easing"),iterations:o("loop"),direction:o("direction"),endDelay:o("endDelay"),duration:o("duration"),speed:o("speed"),delay:o("delay"),timelineOffset:o("timelineOffset"),keyframes:o("keyframes")},o("extend")??{}),p=B(l,[r,t,s],this);typeof p.easing=="string"&&(p.easing=J(p.easing)),p.iterations===!0&&(p.iterations=Infinity),p.fill=o("fillMode");let{timelineOffset:y,speed:h,endDelay:b,delay:u,duration:c,iterations:m,...f}=p;m=Number(m),c=Number(c),b=Number(b),h=Number(h),u=Number(u)+Number(y);let T=u+c*m+b;this.totalDuration{let{speed:y,keyframes:h,tempDurations:b,...u}=n[p];s&&u.endDelay==0&&Math.abs(u.iterations)!=Math.abs(Infinity)&&(u.endDelay=this.totalDuration-b);let c,m,f=h;typeof f=="object"&&(f=_(f));let T=this.computedKeyframes.get(l)??{},g=Object.assign({},r,T),S=D(g,(K,P)=>this.properties[P]??K);if(m=k(f)?f:S,Array.isArray(m))c=m.map(K=>{let{easing:P,offset:x,...N}=v(["speed","loop"],K);return Object.assign({},N,typeof P=="string"?{easing:J(P)}:null,typeof x=="string"||typeof x=="number"?{offset:w(x)}:null)}),c=$(c);else{let K=v(["keyframes"],m),{offset:P,...x}=B(K,[p,t,l],this);x=G(x);let N=P;c=Object.assign({},x,k(N)?{offset:N.map(w)}:null)}let d,E;this.keyframeEffects.has(l)?(E=this.keyframeEffects.get(l),d=this.animations.get(E),E?.setKeyframes?.(c),E?.updateTiming?.(u)):(E=new KeyframeEffect(l,c,u),d=new Animation(E,u.timeline),this.keyframeEffects.set(l,E),this.animations.set(E,d)),d.playbackRate=y,d.onfinish=()=>{typeof a=="function"&&a.call(this,l,p,t,d)},d.oncancel=()=>{typeof o=="function"&&o.call(this,l,p,t,d)},this.computedOptions.set(l,u),this.computedKeyframes.set(l,c)})}updateOptions(e={}){try{let t=le(e);this.options=Object.assign({},oe,this.options,t);let n=["easing","loop","endDelay","duration","speed","delay","timelineOffset","direction","extend","fillMode","offset"],{padEndDelay:s,onfinish:r,oncancel:a,autoplay:o,target:l,targets:p,...y}=v(n,this.options);this.properties=v([...n,"keyframes","padEndDelay","onfinish","oncancel","autoplay","target","targets"],t);let h=this.targets.values(),b=[...new Set([...h,...q(p),...q(l)])];this.targets.clear(),b.forEach((m,f)=>{this.targets.set(f,m),this.targetIndexes.set(m,f)});let u=this.targets.size,c=this.createArrayOfComputedOptions(t,u);if(this.createAnimations({arrOfComputedOptions:c,padEndDelay:s,oldCSSProperties:y,onfinish:r,oncancel:a},u),this.maxSpeed=this.maxSpeed??this.options.speed,this.minDelay=this.minDelay??this.options.delay,this.totalDuration=this.totalDuration??this.options.duration,this.mainAnimation?(this.mainkeyframeEffect?.updateTiming?.({duration:this.totalDuration}),(!this.mainkeyframeEffect.setKeyframes||!this.mainkeyframeEffect.updateTiming)&&console.warn("@okikio/animate - `KeyframeEffect.setKeyframes` and/or `KeyframeEffect.updateTiming` are not supported in this browser.")):(this.mainkeyframeEffect=new KeyframeEffect(this.mainElement,[{opacity:"0"},{opacity:"1"}],{duration:this.totalDuration,easing:"linear"}),this.mainAnimation=new Animation(this.mainkeyframeEffect,this.options.timeline)),this.mainAnimation.playbackRate=this.maxSpeed,this.mainAnimation.onfinish=()=>{if(this.emit("finish",this),this.mainAnimation){let m=this.getPlayState();this.is(m)||this.emit("playstate-change",m,this),this.stopLoop()}},this.mainAnimation.oncancel=()=>{if(this.emit("cancel",this),this.mainAnimation){let m=this.getPlayState();this.is(m)||this.emit("playstate-change",m,this),this.stopLoop()}},o){let m=window.setTimeout(()=>{this.emit("begin",this),m=window.clearTimeout(m)},0);this.play()}else this.pause()}catch(t){this.emit("error",t)}}add(e){let t=this.getProgress(),n=this.is("running"),s=this.is("paused");this.updateOptions({target:e}),this.setProgress(t),n?this.play():s&&this.pause()}removeTarget(e){let t=this.keyframeEffects.get(e);this.animations.delete(t),t=null,this.computedKeyframes.delete(e),this.computedOptions.delete(e),this.keyframeEffects.delete(e);let n=this.targetIndexes.get(e);this.targets.delete(n),this.targetIndexes.delete(e)}remove(e){this.removeTarget(e);let t=new Set([].concat(this.targets.values()));this.options.target=[...t],this.options.targets=[],t.clear(),t=null;let n=this.getProgress(),s=this.is("running"),r=this.is("paused");this.updateOptions(),s?this.play():r&&this.pause(),this.setProgress(n)}on(e,t,n){return this?.emitter?.on(e,t,n??this),this}off(e,t,n){return this?.emitter?.off(e,t,n??this),this}emit(e,...t){return this?.emitter?.emit(e,...t),this}toJSON(){return this.options}get[Symbol.toStringTag](){return"Animate"}},z=Q;z.pauseOnPageHidden=!0;var pe=(i={})=>new z(i),fe=pe;return ye;})(); +var animate=(()=>{var ue=Object.defineProperty;var ce=(i,e)=>{for(var t in e)ue(i,t,{get:e[t],enumerable:!0})};var he={};ce(he,{Animate:()=>N,CSSArrValue:()=>L,CSSValue:()=>D,DefaultAnimationOptions:()=>le,EASINGS:()=>J,EFFECTS:()=>fe,EasingKeys:()=>oe,GetEase:()=>Q,KeyframeParse:()=>U,ParseTransformableCSSKeyframes:()=>B,ParseTransformableCSSProperties:()=>$,TransformFunctionNames:()=>Z,UnitDEG:()=>Y,UnitDEGCSSValue:()=>S,UnitLess:()=>j,UnitLessCSSValue:()=>O,UnitPX:()=>F,UnitPXCSSValue:()=>C,addCSSUnit:()=>X,animate:()=>me,computeOption:()=>ae,createTransformProperty:()=>G,default:()=>ye,flatten:()=>re,getElements:()=>se,getTargets:()=>W,isValid:()=>E,mapAnimationOptions:()=>R,mapObject:()=>v,omit:()=>z,parseOffset:()=>V,parseOptions:()=>pe,toArr:()=>q,transpose:()=>ne});var I=class{constructor(e){this.map=new Map(e)}getMap(){return this.map}get(e){return this.map.get(e)}keys(){return Array.from(this.map.keys())}values(){return Array.from(this.map.values())}set(e,t){return this.map.set(e,t),this}add(e){let n=this.size;return this.set(n,e),this}get size(){return this.map.size}get length(){return this.map.size}last(e=1){let t=this.keys()[this.size-e];return this.get(t)}delete(e){return this.map.delete(e)}remove(e){return this.map.delete(e),this}clear(){return this.map.clear(),this}has(e){return this.map.has(e)}entries(){return this.map.entries()}forEach(e,t){return this.map.forEach(e,t),this}[Symbol.iterator](){return this.entries()}},te=(i,e,...t)=>{i.forEach(n=>{n[e](...t)})};var ie=({callback:i=()=>{},scope:e=null,name:t="event"})=>({callback:i,scope:e,name:t}),w=class extends I{constructor(e="event"){super();this.name=e}},_=class extends I{constructor(){super()}getEvent(e){let t=this.get(e);return t instanceof w?t:(this.set(e,new w(e)),this.get(e))}newListener(e,t,n){let s=this.getEvent(e);return s.add(ie({name:e,callback:t,scope:n})),s}on(e,t,n){if(typeof e=="undefined"||e==null)return this;typeof e=="string"&&(e=e.trim().split(/\s/g));let s,r,a=typeof e=="object"&&!Array.isArray(e),o=a?t:n;return a||(r=t),Object.keys(e).forEach(p=>{s=a?p:e[p],a&&(r=e[p]),this.newListener(s,r,o)},this),this}removeListener(e,t,n){let s=this.get(e);if(s instanceof w&&t){let r=ie({name:e,callback:t,scope:n});s.forEach((a,o)=>{if(a.callback===r.callback&&a.scope===r.scope)return s.remove(o)})}return s}off(e,t,n){if(typeof e=="undefined"||e==null)return this;typeof e=="string"&&(e=e.trim().split(/\s/g));let s,r,a=typeof e=="object"&&!Array.isArray(e),o=a?t:n;return a||(r=t),Object.keys(e).forEach(p=>{s=a?p:e[p],a&&(r=e[p]),typeof r=="function"?this.removeListener(s,r,o):this.remove(s)},this),this}once(e,t,n){if(typeof e=="undefined"||e==null)return this;typeof e=="string"&&(e=e.trim().split(/\s/g));let s=typeof e=="object"&&!Array.isArray(e);return Object.keys(e).forEach(r=>{let a=s?r:e[r],o=s?e[r]:t,p=s?t:n,l=(...f)=>{o.apply(p,f),this.removeListener(a,l,p)};this.newListener(a,l,p)},this),this}emit(e,...t){return typeof e=="undefined"||e==null?this:(typeof e=="string"&&(e=e.trim().split(/\s/g)),e.forEach(n=>{let s=this.get(n);s instanceof w&&s.forEach(r=>{let{callback:a,scope:o}=r;a.apply(o,t)})},this),this)}clear(){return te(this,"clear"),super.clear(),this}};var V=i=>typeof i=="string"?i.includes("%")?parseFloat(i)/100:i=="from"?0:i=="to"?1:parseFloat(i):i,U=i=>{let e=new Set,t=Object.keys(i),n=t.length;for(let s=0;ss.offset-r.offset)},fe={};var X=(i="")=>e=>typeof e=="string"?e:`${e}${i}`,j=X(),F=X("px"),Y=X("deg"),q=i=>Array.isArray(i)||typeof i=="string"?(typeof i=="string"&&(i=i.split(",")),i):[i],E=i=>Array.isArray(i)||typeof i=="string"?Boolean(i.length):i!=null&&i!=null,D=i=>e=>E(e)?q(e).map(t=>{if(typeof t!="number"&&typeof t!="string")return t;let n=Number(t),s=Number.isNaN(n)?typeof t=="string"?t.trim():t:n;return i(s)}):[],ne=(...i)=>{let e=0;i=i.map(s=>{let r=q(s),a=r.length;return a>e&&(e=a),r});let t=[],n=i.length;for(let s=0;sq(i).map(D(e)),Z=["translate","translate3d","translateX","translateY","translateZ","rotate","rotate3d","rotateX","rotateY","rotateZ","scale","scale3d","scaleX","scaleY","scaleZ","skew","skewX","skewY","perspective"],G=i=>{let e="",t=Z.length;for(let n=0;n{let{perspective:e,rotate:t,rotate3d:n,rotateX:s,rotateY:r,rotateZ:a,translate:o,translate3d:p,translateX:l,translateY:f,translateZ:b,scale:d,scale3d:h,scaleX:u,scaleY:c,scaleZ:m,skew:y,skewX:g,skewY:T,...P}=i;o=L(o,F),p=L(p,F),l=C(l),f=C(f),b=C(b),t=L(t,Y),n=L(n,j),s=S(s),r=S(r),a=S(a),d=L(d,j),h=L(h,j),u=O(u),c=O(c),m=O(m),y=L(y,Y),g=S(g),T=S(T),e=C(e);let A=ne(o,p,l,f,b,t,n,s,r,a,d,h,u,c,m,y,g,T,e).filter(E).map(G);return P=v(P,k=>[].concat(k).map(x=>""+x)),Object.assign({},E(A)?{transform:A}:null,P)},B=i=>i.map(e=>{let{translate:t,translate3d:n,translateX:s,translateY:r,translateZ:a,rotate:o,rotate3d:p,rotateX:l,rotateY:f,rotateZ:b,scale:d,scale3d:h,scaleX:u,scaleY:c,scaleZ:m,skew:y,skewX:g,skewY:T,perspective:P,easing:A,iterations:k,offset:x,...K}=e;return t=C(t),n=C(n),s=C(s)[0],r=C(r)[0],a=C(a)[0],o=S(o),p=O(p),l=S(l)[0],f=S(f)[0],b=S(b)[0],d=O(d),h=O(h),u=O(u)[0],c=O(c)[0],m=O(m)[0],y=S(y),g=S(g)[0],T=S(T)[0],P=C(P)[0],[K,t,n,s,r,a,o,p,l,f,b,d,h,u,c,m,y,g,T,P]}).map(([e,...t])=>{let n=G(t);return Object.assign({},E(n)?{transform:n}:null,e)});var se=i=>typeof i=="string"?Array.from(document.querySelectorAll(i)):[i],re=i=>[].concat(...i),W=i=>Array.isArray(i)?re(i.map(W)):typeof i=="string"||i instanceof Node?se(i):i instanceof NodeList||i instanceof HTMLCollection?Array.from(i):[],ae=(i,e,t)=>typeof i=="function"?i.apply(t,e):i,v=(i,e)=>{let t=Object.keys(i),n,s,r={};for(let a=0,o=t.length;av(i,n=>ae(n,e,t)),J={in:"ease-in",out:"ease-out","in-out":"ease-in-out","in-sine":"cubic-bezier(0.47, 0, 0.745, 0.715)","out-sine":"cubic-bezier(0.39, 0.575, 0.565, 1)","in-out-sine":"cubic-bezier(0.445, 0.05, 0.55, 0.95)","in-quad":"cubic-bezier(0.55, 0.085, 0.68, 0.53)","out-quad":"cubic-bezier(0.25, 0.46, 0.45, 0.94)","in-out-quad":"cubic-bezier(0.455, 0.03, 0.515, 0.955)","in-cubic":"cubic-bezier(0.55, 0.055, 0.675, 0.19)","out-cubic":"cubic-bezier(0.215, 0.61, 0.355, 1)","in-out-cubic":"cubic-bezier(0.645, 0.045, 0.355, 1)","in-quart":"cubic-bezier(0.895, 0.03, 0.685, 0.22)","out-quart":"cubic-bezier(0.165, 0.84, 0.44, 1)","in-out-quart":"cubic-bezier(0.77, 0, 0.175, 1)","in-quint":"cubic-bezier(0.755, 0.05, 0.855, 0.06)","out-quint":"cubic-bezier(0.23, 1, 0.32, 1)","in-out-quint":"cubic-bezier(0.86, 0, 0.07, 1)","in-expo":"cubic-bezier(0.95, 0.05, 0.795, 0.035)","out-expo":"cubic-bezier(0.19, 1, 0.22, 1)","in-out-expo":"cubic-bezier(1, 0, 0, 1)","in-circ":"cubic-bezier(0.6, 0.04, 0.98, 0.335)","out-circ":"cubic-bezier(0.075, 0.82, 0.165, 1)","in-out-circ":"cubic-bezier(0.785, 0.135, 0.15, 0.86)","in-back":"cubic-bezier(0.6, -0.28, 0.735, 0.045)","out-back":"cubic-bezier(0.175, 0.885, 0.32, 1.275)","in-out-back":"cubic-bezier(0.68, -0.55, 0.265, 1.55)"},oe=Object.keys(J),Q=i=>{let e=i.replace(/^ease-/,"");return oe.includes(e)?J[e]:i},le={keyframes:[],offset:[],loop:1,delay:0,speed:1,endDelay:0,easing:"ease",timelineOffset:0,autoplay:!0,duration:1e3,fillMode:"none",direction:"normal",padEndDelay:!1,timeline:document.timeline,extend:{}},pe=i=>{let{options:e,...t}=i,n=e instanceof N?e.options:Array.isArray(e)?e?.[0]?.options:e;return Object.assign({},n,t)},z=(i,e)=>{let t={...e};for(;i.length;){let{[i.pop()]:n,...s}=t;t=s}return t},ee=class{constructor(e){this.options={};this.properties={};this.totalDuration=0;this.emitter=new _;this.targets=new I;this.targetIndexes=new WeakMap;this.keyframeEffects=new WeakMap;this.computedOptions=new WeakMap;this.animations=new WeakMap;this.computedKeyframes=new WeakMap;this.loop=this.loop.bind(this),this.onVisibilityChange=this.onVisibilityChange.bind(this),this.on("error",console.error),this.updateOptions(e),this.mainAnimation&&(this.visibilityPlayState=this.getPlayState(),ee.pauseOnPageHidden&&document.addEventListener("visibilitychange",this.onVisibilityChange,!1)),this.newPromise()}onVisibilityChange(){document.hidden?(this.visibilityPlayState=this.getPlayState(),this.is("running")&&(this.loop(),this.pause())):this.visibilityPlayState=="running"&&this.is("paused")&&this.play()}newPromise(){return this.promise=new Promise((e,t)=>{this?.emitter?.once?.("finish",()=>e([this])),this?.emitter?.once?.("error",n=>t(n))}),this.promise}then(e,t){return e=e?.bind(this),t=t?.bind(this),this?.promise?.then?.(e,t),this}catch(e){return e=e?.bind(this),this.promise?.catch?.(e),this}finally(e){return e=e?.bind(this),this.promise?.finally?.(e),this}loop(){this.stopLoop(),this.animationFrame=window.requestAnimationFrame(this.loop),this.emit("update",this.getProgress(),this)}stopLoop(){window.cancelAnimationFrame(this.animationFrame)}allAnimations(e){return this.targets.forEach(t=>{let n=this.keyframeEffects.get(t),s=this.animations.get(n);return e(s,t)}),this}all(e){return this.mainAnimation&&e(this.mainAnimation,this.mainElement),this.allAnimations(e),this}beginEvent(){this.getProgress()==0&&this.emit("begin",this)}play(){let e=this.getPlayState();return this.beginEvent(),this.all(t=>t.play()),this.emit("play",e,this),this.is(e)||this.emit("playstate-change",e,this),this.loop(),this}pause(){let e=this.getPlayState();return this.all(t=>t.pause()),this.emit("pause",e,this),this.is(e)||this.emit("playstate-change",e,this),this.stopLoop(),this}reverse(){return this.all(e=>e.reverse()),this}reset(){return this.setProgress(0),this.options.autoplay?this.play():this.pause(),this}cancel(){return this.all(e=>e.cancel()),this}finish(){return this.all(e=>e.finish()),this}stop(){this.cancel(),this.stopLoop(),document.removeEventListener("visibilitychange",this.onVisibilityChange,!1),this.targets.forEach(e=>this.removeTarget(e)),this.emit("stop"),this.emitter.clear(),this.mainkeyframeEffect=null,this.mainAnimation=null,this.mainElement=null,this.promise=null,this.computedOptions=null,this.animations=null,this.keyframeEffects=null,this.emitter=null,this.targets=null,this.options=null,this.properties=null}getAnimation(e){let t=this.keyframeEffects.get(e);return this.animations.get(t)}getTiming(e){let t=this.computedOptions.get(e)??{},n=this.keyframeEffects.get(e).getTiming?.()??{};return{...t,...n}}getCurrentTime(){return this.mainAnimation.currentTime}getProgress(){return this.getCurrentTime()/this.totalDuration*100}getSpeed(){return this.mainAnimation.playbackRate}getPlayState(){return this.mainAnimation.playState}is(e){return this.getPlayState()==e}setCurrentTime(e){return this.all(t=>t.currentTime=e),this.emit("update",this.getProgress()),this}setProgress(e){let t=e/100*this.totalDuration;return this.setCurrentTime(t),this}setSpeed(e=1){return this.maxSpeed=e,this.all(t=>{t.updatePlaybackRate?t.updatePlaybackRate(e):t.playbackRate=e}),this}createArrayOfComputedOptions(e,t){let n=[];return this.targets.forEach((s,r)=>{let a=this.computedOptions.get(s)??{},o=g=>{let T=g;return g=="loop"&&(T="iterations"),g=="fillMode"&&(T="fill"),e[g]??a[T]??this.options[g]},p=Object.assign({easing:o("easing"),iterations:o("loop"),direction:o("direction"),endDelay:o("endDelay"),duration:o("duration"),speed:o("speed"),delay:o("delay"),timelineOffset:o("timelineOffset"),keyframes:o("keyframes")},o("extend")??{}),l=R(p,[r,t,s],this);typeof l.easing=="string"&&(l.easing=Q(l.easing)),l.iterations===!0&&(l.iterations=Infinity),l.fill=o("fillMode");let{timelineOffset:f,speed:b,endDelay:d,delay:h,duration:u,iterations:c,...m}=l;c=Number(c),u=Number(u),d=Number(d),b=Number(b),h=Number(h)+Number(f);let y=h+u*c+d;this.totalDuration{let{speed:b,keyframes:d,tempDurations:h,...u}=n[f];s&&u.endDelay==0&&Math.abs(u.iterations)!=Math.abs(Infinity)&&(u.endDelay=this.totalDuration-h);let c,m,y=d;typeof y=="object"&&(y=U(y));let g=this.computedKeyframes.get(l)??{},T=Object.assign({},r,g),P=v(T,(x,K)=>this.properties[K]??x);if(m=E(y)?y:P,Array.isArray(m))c=m.map(x=>{let{easing:K,offset:M,...H}=z(["speed","loop"],x);return Object.assign({},H,typeof K=="string"?{easing:Q(K)}:null,typeof M=="string"||typeof M=="number"?{offset:V(M)}:null)}),c=B(c);else{let x=z(["keyframes"],m),{offset:K,...M}=R(x,[f,t,l],this);M=$(M);let H=K;c=Object.assign({},M,E(H)?{offset:H.map(V)}:null)}let A,k;this.keyframeEffects.has(l)?(k=this.keyframeEffects.get(l),A=this.animations.get(k),k?.setKeyframes?.(c),k?.updateTiming?.(u)):(k=new KeyframeEffect(l,c,u),A=new Animation(k,p),this.keyframeEffects.set(l,k),this.animations.set(k,A)),A.playbackRate=b,A.onfinish=()=>{typeof a=="function"&&a.call(this,l,f,t,A)},A.oncancel=()=>{typeof o=="function"&&o.call(this,l,f,t,A)},this.computedOptions.set(l,u),this.computedKeyframes.set(l,c)})}updateOptions(e={}){try{let t=pe(e);this.options=Object.assign({},le,this.options,t);let n=["easing","loop","endDelay","duration","speed","delay","timelineOffset","direction","extend","fillMode","offset"],{padEndDelay:s,autoplay:r,target:a,targets:o,timeline:p,onfinish:l,oncancel:f,...b}=z(n,this.options);this.properties=z([...n,"keyframes","padEndDelay","onfinish","oncancel","autoplay","target","targets","timeline"],t);let d=this.targets.values(),h=[...new Set([...d,...W(o),...W(a)])];this.targets.clear(),h.forEach((m,y)=>{this.targets.set(y,m),this.targetIndexes.set(m,y)});let u=this.targets.size,c=this.createArrayOfComputedOptions(t,u);if(this.createAnimations({arrOfComputedOptions:c,padEndDelay:s,oldCSSProperties:b,onfinish:l,oncancel:f,timeline:p},u),this.maxSpeed=this.maxSpeed??this.options.speed,this.minDelay=this.minDelay??this.options.delay,this.totalDuration=this.totalDuration??this.options.duration,this.mainAnimation?(this.mainkeyframeEffect?.updateTiming?.({duration:this.totalDuration}),(!this.mainkeyframeEffect.setKeyframes||!this.mainkeyframeEffect.updateTiming)&&console.warn("@okikio/animate - `KeyframeEffect.setKeyframes` and/or `KeyframeEffect.updateTiming` are not supported in this browser.")):(this.mainkeyframeEffect=new KeyframeEffect(this.mainElement,[{opacity:"0"},{opacity:"1"}],{duration:this.totalDuration,easing:"linear"}),this.mainAnimation=new Animation(this.mainkeyframeEffect,p)),this.mainAnimation.playbackRate=this.maxSpeed,this.mainAnimation.onfinish=()=>{if(this.emit("finish",this),this.mainAnimation){let m=this.getPlayState();this.is(m)||this.emit("playstate-change",m,this),this.stopLoop()}},this.mainAnimation.oncancel=()=>{if(this.emit("cancel",this),this.mainAnimation){let m=this.getPlayState();this.is(m)||this.emit("playstate-change",m,this),this.stopLoop()}},r){let m=window.setTimeout(()=>{this.emit("begin",this),m=window.clearTimeout(m)},0);this.play()}else this.pause()}catch(t){this.emit("error",t)}}add(e){let t=this.getProgress(),n=this.is("running"),s=this.is("paused");this.updateOptions({target:e}),this.setProgress(t),n?this.play():s&&this.pause()}removeTarget(e){let t=this.keyframeEffects.get(e);this.animations.delete(t),t=null,this.computedKeyframes.delete(e),this.computedOptions.delete(e),this.keyframeEffects.delete(e);let n=this.targetIndexes.get(e);this.targets.delete(n),this.targetIndexes.delete(e)}remove(e){this.removeTarget(e);let t=new Set([].concat(this.targets.values()));this.options.target=[...t],this.options.targets=[],t.clear(),t=null;let n=this.getProgress(),s=this.is("running"),r=this.is("paused");this.updateOptions(),s?this.play():r&&this.pause(),this.setProgress(n)}on(e,t,n){return this?.emitter?.on(e,t,n??this),this}off(e,t,n){return this?.emitter?.off(e,t,n??this),this}emit(e,...t){return this?.emitter?.emit(e,...t),this}toJSON(){return this.options}get[Symbol.toStringTag](){return"Animate"}},N=ee;N.pauseOnPageHidden=!0;var me=(i={})=>new N(i),ye=me;return he;})(); diff --git a/packages/animate/src/api.ts b/packages/animate/src/api.ts index c2a0fc0..1cfc8b4 100644 --- a/packages/animate/src/api.ts +++ b/packages/animate/src/api.ts @@ -205,6 +205,7 @@ export const DefaultAnimationOptions: IAnimationOptions = { fillMode: "none", direction: "normal", padEndDelay: false, + timeline: document.timeline, extend: {} }; @@ -337,12 +338,14 @@ export class Animate { constructor(options: IAnimationOptions) { this.loop = this.loop.bind(this); this.onVisibilityChange = this.onVisibilityChange.bind(this); - this.on("error", (err) => console.error(err)); + this.on("error", console.error); this.updateOptions(options); - this.visibilityPlayState = this.getPlayState(); - if (Animate.pauseOnPageHidden) { - document.addEventListener('visibilitychange', this.onVisibilityChange, false); + if (this.mainAnimation) { + this.visibilityPlayState = this.getPlayState(); + if (Animate.pauseOnPageHidden) { + document.addEventListener('visibilitychange', this.onVisibilityChange, false); + } } this.newPromise(); @@ -736,13 +739,14 @@ export class Animate { /** * Creates animations out of an array of computed options */ - protected createAnimations(param: { arrOfComputedOptions: any; padEndDelay: any; oldCSSProperties: any; onfinish: any; oncancel: any; }, len: number) { + protected createAnimations(param: { arrOfComputedOptions: any; padEndDelay: any; oldCSSProperties: any; onfinish: any; oncancel: any; timeline?: any; }, len: number) { let { arrOfComputedOptions, padEndDelay, oldCSSProperties, onfinish, - oncancel + oncancel, + timeline } = param; this.targets.forEach((target: HTMLElement, i) => { @@ -802,7 +806,7 @@ export class Animate { // Remove `speed` & `loop`, they are not valid CSS properties let { easing, offset, ...remaining } = omit(["speed", "loop"], keyframe); - return Object.assign({ }, + return Object.assign({}, remaining, typeof easing == "string" ? { easing: GetEase(easing) } : null, typeof offset == "string" || typeof offset == "number" @@ -825,7 +829,7 @@ export class Animate { } else { // Create animation and add it to the Animations Set keyFrameEffect = new KeyframeEffect(target, computedKeyframes, computedOptions as KeyframeAnimationOptions); - animation = new Animation(keyFrameEffect, computedOptions.timeline); + animation = new Animation(keyFrameEffect, timeline); this.keyframeEffects.set(target, keyFrameEffect); this.animations.set(keyFrameEffect, animation); @@ -866,11 +870,13 @@ export class Animate { let { // These values cannot be functions padEndDelay, - onfinish, - oncancel, autoplay, target, targets, + timeline, + + onfinish, + oncancel, /** * Theses are the CSS properties to be animated as Keyframes @@ -879,7 +885,7 @@ export class Animate { } = omit(sharedTimingKeys, this.options); // This removes all none CSS properties from `optionsFromParam` - this.properties = omit([...sharedTimingKeys, "keyframes", "padEndDelay", "onfinish", "oncancel", "autoplay", "target", "targets"], optionsFromParam); + this.properties = omit([...sharedTimingKeys, "keyframes", "padEndDelay", "onfinish", "oncancel", "autoplay", "target", "targets", "timeline"], optionsFromParam); // Avoid duplicate elements let oldTargets = this.targets.values(); @@ -897,11 +903,12 @@ export class Animate { padEndDelay, oldCSSProperties, onfinish, - oncancel + oncancel, + timeline }, len); this.maxSpeed = this.maxSpeed ?? this.options.speed as number; - this.minDelay = this.minDelay ?? this.options.delay as number; + this.minDelay = this.minDelay ?? this.options.delay as number; this.totalDuration = this.totalDuration ?? this.options.duration as number; if (!this.mainAnimation) { @@ -914,7 +921,7 @@ export class Animate { easing: "linear" }); - this.mainAnimation = new Animation(this.mainkeyframeEffect, this.options.timeline); + this.mainAnimation = new Animation(this.mainkeyframeEffect, timeline); } else { this.mainkeyframeEffect?.updateTiming?.({ duration: this.totalDuration diff --git a/packages/animate/src/css-properties.ts b/packages/animate/src/css-properties.ts index 95c6ab8..c5c0ad5 100644 --- a/packages/animate/src/css-properties.ts +++ b/packages/animate/src/css-properties.ts @@ -299,7 +299,7 @@ export const ParseTransformableCSSProperties = (properties: ICSSComputedTransfor scale, scale3d, scaleX, scaleY, scaleZ, skew, skewX, skewY, perspective - ).map(createTransformProperty); + ).filter(isValid).map(createTransformProperty); // Wrap non array CSS property values in an array rest = mapObject(rest, value => [].concat(value).map(v => `` + v)); @@ -377,6 +377,7 @@ export const ParseTransformableCSSKeyframes = (keyframes: ICSSComputedTransforma ]; }).map(([rest, ...transformFunctions]) => { let transform = createTransformProperty(transformFunctions); + return Object.assign({}, isValid(transform) ? { transform } : null, rest);