"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../frameloop/sync-time.mjs.js"),t=require("./JSAnimation.mjs.js"),i=require("./keyframes/get-final.mjs.js"),n=require("./keyframes/KeyframesResolver.mjs.js"),s=require("./NativeAnimationExtended.mjs.js"),a=require("./utils/can-animate.mjs.js"),o=require("./utils/make-animation-instant.mjs.js"),r=require("./utils/WithPromise.mjs.js"),m=require("./waapi/supports/waapi.mjs.js"),l=require("../../../../motion-utils/dist/es/global-config.mjs.js"),h=require("../../../../motion-utils/dist/es/noop.mjs.js");class p extends r.WithPromise{constructor(t){let{autoplay:i=!0,delay:s=0,type:a="keyframes",repeat:o=0,repeatDelay:r=0,repeatType:m="loop",keyframes:l,name:h,motionValue:p,element:u,...d}=t;super(),this.stop=()=>{this._animation&&(this._animation.stop(),this.stopTimeline?.()),this.keyframeResolver?.cancel()},this.createdAt=e.time.now();const y={autoplay:i,delay:s,type:a,repeat:o,repeatDelay:r,repeatType:m,name:h,motionValue:p,element:u,...d},c=u?.KeyframeResolver||n.KeyframeResolver;this.keyframeResolver=new c(l,((e,t,i)=>this.onKeyframesResolved(e,t,y,!i)),h,p,u),this.keyframeResolver?.scheduleResolve()}onKeyframesResolved(n,r,p,u){this.keyframeResolver=void 0;const{name:d,type:y,velocity:c,delay:f,isHandoff:v,onUpdate:j}=p;this.resolvedAt=e.time.now();let g=!0;a.canAnimate(n,d,y,c)||(g=!1,!l.MotionGlobalConfig.instantAnimations&&f||j?.(i.getFinalKeyframe(n,p,r)),n[0]=n[n.length-1],o.makeAnimationInstant(p),p.repeat=0);const A={startTime:u?this.resolvedAt&&this.resolvedAt-this.createdAt>40?this.resolvedAt:this.createdAt:void 0,finalKeyframe:r,...p,keyframes:n},T=g&&!v&&m.supportsBrowserAnimation(A),k=A.motionValue?.owner?.current;let R;if(T)try{R=new s.NativeAnimationExtended({...A,element:k})}catch{R=new t.JSAnimation(A)}else R=new t.JSAnimation(A);R.finished.then((()=>{this.notifyFinished()})).catch(h.noop),this.pendingTimeline&&(this.stopTimeline=R.attachTimeline(this.pendingTimeline),this.pendingTimeline=void 0),this._animation=R}get finished(){return this._animation?this.animation.finished:this._finished}then(e,t){return this.finished.finally(e).then((()=>{}))}get animation(){return this._animation||(this.keyframeResolver?.resume(),n.flushKeyframeResolvers()),this._animation}get duration(){return this.animation.duration}get iterationDuration(){return this.animation.iterationDuration}get time(){return this.animation.time}set time(e){this.animation.time=e}get speed(){return this.animation.speed}get state(){return this.animation.state}set speed(e){this.animation.speed=e}get startTime(){return this.animation.startTime}attachTimeline(e){return this._animation?this.stopTimeline=this.animation.attachTimeline(e):this.pendingTimeline=e,()=>this.stop()}play(){this.animation.play()}pause(){this.animation.pause()}complete(){this.animation.complete()}cancel(){this._animation&&this.animation.cancel(),this.keyframeResolver?.cancel()}}exports.AsyncMotionValueAnimation=p;
//# sourceMappingURL=AsyncMotionValueAnimation.mjs.js.map
