"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var i=require("../render/dom/style-set.mjs.js"),t=require("../utils/supports/scroll-timeline.mjs.js"),e=require("./keyframes/get-final.mjs.js"),s=require("./utils/WithPromise.mjs.js"),n=require("./waapi/start-waapi-animation.mjs.js"),a=require("./waapi/utils/apply-generator.mjs.js"),o=require("../../../../motion-utils/dist/es/errors.mjs.js"),m=require("../../../../motion-utils/dist/es/time-conversion.mjs.js"),r=require("../../../../motion-utils/dist/es/noop.mjs.js");class l extends s.WithPromise{constructor(t){if(super(),this.finishedTime=null,this.isStopped=!1,this.manualStartTime=null,!t)return;const{element:s,name:m,keyframes:r,pseudoElement:l,allowFlatten:h=!1,finalKeyframe:u,onComplete:p}=t;this.isPseudoElement=Boolean(l),this.allowFlatten=h,this.options=t,o.invariant("string"!=typeof t.type,'Mini animate() doesn\'t support "type" as a string.',"mini-spring");const d=a.applyGeneratorOptions(t);this.animation=n.startWaapiAnimation(s,m,r,d,l),!1===d.autoplay&&this.animation.pause(),this.animation.onfinish=()=>{if(this.finishedTime=this.time,!l){const t=e.getFinalKeyframe(r,this.options,u,this.speed);this.updateMotionValue&&this.updateMotionValue(t),i.setStyle(s,m,t),this.animation.cancel()}p?.(),this.notifyFinished()}}play(){this.isStopped||(this.manualStartTime=null,this.animation.play(),"finished"===this.state&&this.updateFinished())}pause(){this.animation.pause()}complete(){this.animation.finish?.()}cancel(){try{this.animation.cancel()}catch(i){}}stop(){if(this.isStopped)return;this.isStopped=!0;const{state:i}=this;"idle"!==i&&"finished"!==i&&(this.updateMotionValue?this.updateMotionValue():this.commitStyles(),this.isPseudoElement||this.cancel())}commitStyles(){const i=this.options?.element;!this.isPseudoElement&&i?.isConnected&&this.animation.commitStyles?.()}get duration(){const i=this.animation.effect?.getComputedTiming?.().duration||0;return m.millisecondsToSeconds(Number(i))}get iterationDuration(){const{delay:i=0}=this.options||{};return this.duration+m.millisecondsToSeconds(i)}get time(){return m.millisecondsToSeconds(Number(this.animation.currentTime)||0)}set time(i){const t=null!==this.finishedTime;this.manualStartTime=null,this.finishedTime=null,this.animation.currentTime=m.secondsToMilliseconds(i),t&&this.animation.pause()}get speed(){return this.animation.playbackRate}set speed(i){i<0&&(this.finishedTime=null),this.animation.playbackRate=i}get state(){return null!==this.finishedTime?"finished":this.animation.playState}get startTime(){return this.manualStartTime??Number(this.animation.startTime)}set startTime(i){this.manualStartTime=this.animation.startTime=i}attachTimeline(i){let{timeline:e,rangeStart:s,rangeEnd:n,observe:a}=i;return this.allowFlatten&&this.animation.effect?.updateTiming({easing:"linear"}),this.animation.onfinish=null,e&&t.supportsScrollTimeline()?(this.animation.timeline=e,s&&(this.animation.rangeStart=s),n&&(this.animation.rangeEnd=n),r.noop):a(this)}}exports.NativeAnimation=l;
//# sourceMappingURL=NativeAnimation.mjs.js.map
