import{animation_styles_default as t}from"./chunk.YL3TSWVM.js";import{animations as i}from"./chunk.TJOP7HQP.js";import{watch as a}from"./chunk.C7FWPEOY.js";import{ShoelaceElement as e}from"./chunk.Z7XDKKOD.js";import{__decorateClass as n}from"./chunk.6M63UXML.js";import{html as s}from"../../../../lit/index.js";import{property as o,queryAsync as r}from"../../../../lit/decorators.js";var h=class extends e{constructor(){super(...arguments),this.hasStarted=!1,this.name="none",this.play=!1,this.delay=0,this.direction="normal",this.duration=1e3,this.easing="linear",this.endDelay=0,this.fill="auto",this.iterations=1/0,this.iterationStart=0,this.playbackRate=1,this.handleAnimationFinish=()=>{this.play=!1,this.hasStarted=!1,this.emit("sl-finish")},this.handleAnimationCancel=()=>{this.play=!1,this.hasStarted=!1,this.emit("sl-cancel")}}get currentTime(){var t,i;return null!=(i=null==(t=this.animation)?void 0:t.currentTime)?i:0}set currentTime(t){this.animation&&(this.animation.currentTime=t)}connectedCallback(){super.connectedCallback(),this.createAnimation()}disconnectedCallback(){super.disconnectedCallback(),this.destroyAnimation()}handleSlotChange(){this.destroyAnimation(),this.createAnimation()}async createAnimation(){var t,a;const e=null!=(t=i.easings[this.easing])?t:this.easing,n=null!=(a=this.keyframes)?a:i[this.name],s=(await this.defaultSlot).assignedElements()[0];return!(!s||!n)&&(this.destroyAnimation(),this.animation=s.animate(n,{delay:this.delay,direction:this.direction,duration:this.duration,easing:e,endDelay:this.endDelay,fill:this.fill,iterationStart:this.iterationStart,iterations:this.iterations}),this.animation.playbackRate=this.playbackRate,this.animation.addEventListener("cancel",this.handleAnimationCancel),this.animation.addEventListener("finish",this.handleAnimationFinish),this.play?(this.hasStarted=!0,this.emit("sl-start")):this.animation.pause(),!0)}destroyAnimation(){this.animation&&(this.animation.cancel(),this.animation.removeEventListener("cancel",this.handleAnimationCancel),this.animation.removeEventListener("finish",this.handleAnimationFinish),this.hasStarted=!1)}handleAnimationChange(){this.hasUpdated&&this.createAnimation()}handlePlayChange(){return!!this.animation&&(this.play&&!this.hasStarted&&(this.hasStarted=!0,this.emit("sl-start")),this.play?this.animation.play():this.animation.pause(),!0)}handlePlaybackRateChange(){this.animation&&(this.animation.playbackRate=this.playbackRate)}cancel(){var t;null==(t=this.animation)||t.cancel()}finish(){var t;null==(t=this.animation)||t.finish()}render(){return s` <slot @slotchange=${this.handleSlotChange}></slot> `}};h.styles=t,n([r("slot")],h.prototype,"defaultSlot",2),n([o()],h.prototype,"name",2),n([o({type:Boolean,reflect:!0})],h.prototype,"play",2),n([o({type:Number})],h.prototype,"delay",2),n([o()],h.prototype,"direction",2),n([o({type:Number})],h.prototype,"duration",2),n([o()],h.prototype,"easing",2),n([o({attribute:"end-delay",type:Number})],h.prototype,"endDelay",2),n([o()],h.prototype,"fill",2),n([o({type:Number})],h.prototype,"iterations",2),n([o({attribute:"iteration-start",type:Number})],h.prototype,"iterationStart",2),n([o({attribute:!1})],h.prototype,"keyframes",2),n([o({attribute:"playback-rate",type:Number})],h.prototype,"playbackRate",2),n([a(["name","delay","direction","duration","easing","endDelay","fill","iterations","iterationsStart","keyframes"])],h.prototype,"handleAnimationChange",1),n([a("play")],h.prototype,"handlePlayChange",1),n([a("playbackRate")],h.prototype,"handlePlaybackRateChange",1);export{h as SlAnimation};