UNPKG

@infinityfx/lively

Version:

Feature complete, lightweight react animation library.

3 lines (2 loc) 1.57 kB
import t from"./action.js";import{isLink as e}from"./link.js";import{normalizeAnimatableKeyframes as i,createDynamic as s,distributeAnimatableKeyframes as r,merge as n}from"./utils.js";class a{constructor({duration:t=1,delay:a=0,repeat:o=1,alternate:h=!1,easing:l="ease",reverse:c=!1,composite:m="none",...f},y={}){this.dynamic={};const d={};for(let t in f){let n=f[t],a=y[t];if(n instanceof Function){e(n)||(this.dynamic[t]=n);continue}const o=Array.isArray(n)?n:[n];o.length<2&&void 0!==a&&o.unshift(a),null===o[0]&&(void 0!==a?o[0]=a:o.splice(0,1)),i(o)&&("borderRadius"!==t?r(t,o,d):this.dynamic[t]=s(t,Object.values(r(t,o)),l))}this.keyframes=Object.values(d).sort(((t,e)=>t.offset-e.offset)),this.initial=n({},y,this.keyframes.length?this.keyframes[0]:{}),delete this.initial.offset,this.isEmpty=!this.keyframes.length&&!Object.keys(this.dynamic).length,this.duration=this.isEmpty?0:t,this.delay=a,this.repeat=o,this.alternate=h,this.easing=l,this.reverse=c,this.composite=m}static from(t,e){return t instanceof a?t:new a(t||{},e)}unique(t){const e=new a({});for(const i in this)this.hasOwnProperty(i)&&(e[i]=i in t?t[i]:this[i]);return e}play(e,{composite:i=this.composite,reverse:s=this.reverse,commit:r=!0,delay:n=0}){if(this.isEmpty)return;const a=new t(e,this.keyframes,{duration:1e3*this.duration,delay:1e3*(n+this.delay),iterations:this.repeat,direction:this.alternate?s?"alternate-reverse":"alternate":s?"reverse":"normal",fill:"both",easing:this.easing,composite:i},this.dynamic);a.commit=r,e.push(a)}}export{a as default}; //# sourceMappingURL=clip.js.map