"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});require('./assets/index.css');const a=require("vue"),S=require("lottie-web/build/player/lottie_light.min.js"),w=require("@reslear/dotlottie-player-core");function b(i){try{if(!i||typeof i!="string"&&typeof i!="object"||Array.isArray(i))return;if(typeof i=="object")return JSON.parse(JSON.stringify(i));const l=JSON.parse(i);if(typeof l=="object")return l}catch{}}const c=a.defineComponent({__name:"vue3-lottie",props:{animationData:{default:""},animationLink:{default:""},loop:{type:[Boolean,Number],default:!0},autoPlay:{type:Boolean,default:!0},renderer:{default:"svg"},rendererSettings:{default:null},width:{default:"100%"},height:{default:"100%"},speed:{default:1},delay:{default:0},direction:{default:"forward"},pauseOnHover:{type:Boolean,default:!1},playOnHover:{type:Boolean,default:!1},backgroundColor:{default:"transparent"},pauseAnimation:{type:Boolean,default:!1},fetchOptions:{default:void 0},onLoopComplete:{},onEnterFrame:{},onSegmentStart:{},onComplete:{},onAnimationLoaded:{}},emits:["complete","loop-complete","enter-frame","segment-start","animation-loaded"],setup(i,{emit:l}){const e=i,s=l;let t=null;const u=a.ref(null);let p=1;const f=a.shallowRef(null),m=async o=>{let n=e.autoPlay;e.playOnHover&&(n=!1);let r=e.loop;typeof r=="number"&&r>0&&(r=r-1),e.delay>0&&(n=!1);const H={container:o,renderer:e.renderer,rendererSettings:e.rendererSettings,loop:r,autoplay:n,animationData:f.value};t=S.loadAnimation(H),t&&(setTimeout(()=>{t&&(n=e.autoPlay,e.playOnHover?t.pause():n?t.play():t.pause(),e.onAnimationLoaded&&s("animation-loaded"))},e.delay),t.setSpeed(e.speed),e.direction==="reverse"&&t.setDirection(-1),e.direction==="normal"&&t.setDirection(1),(e.pauseAnimation||e.playOnHover)&&t.pause(),y())};function y(){t&&(e.onLoopComplete&&t.addEventListener("loopComplete",()=>{t&&(e.direction==="alternate"&&(t.stop(),p=p===-1?1:-1,t.setDirection(p),t.play()),s("loop-complete"))}),e.onComplete&&t.addEventListener("complete",()=>{s("complete")}),e.onEnterFrame&&t.addEventListener("enterFrame",()=>{s("enter-frame")}),e.onSegmentStart&&t.addEventListener("segmentStart",()=>{s("segment-start")}))}const h=a.computed(()=>{let o=e.width,n=e.height;return typeof e.width=="number"&&(o=`${e.width}px`),typeof e.height=="number"&&(n=`${e.height}px`),{"--lottie-animation-container-width":o,"--lottie-animation-container-height":n,"--lottie-animation-container-background-color":e.backgroundColor}}),v=()=>{t&&e.pauseOnHover&&t.pause(),t&&e.playOnHover&&t.play()},g=()=>{t&&e.pauseOnHover&&t.play(),t&&e.playOnHover&&t.pause()};a.watch(()=>e.pauseAnimation,()=>{if((e.pauseOnHover||e.playOnHover)&&e.pauseAnimation){console.error("If you are using pauseAnimation prop for Vue3-Lottie, please remove the props pauseOnHover and playOnHover");return}t&&(e.pauseAnimation?t.pause():t.play())});const d=()=>{t&&(t.destroy(),t=null)},O=()=>{if(e.pauseOnHover&&e.playOnHover)throw new Error("You cannot set pauseOnHover and playOnHover for Vue3-Lottie at the same time.");u.value&&m(u.value)};async function L({data:o,link:n}){const r=o?b(o):await w.fetchLottie(n,e.fetchOptions);if(!r)throw new Error("You must provide correct animationLink or animationData");f.value=r}return a.watch(()=>[e.animationData,e.animationLink],([o,n])=>{L({link:n,data:o})},{immediate:!0}),a.onMounted(()=>{a.watch(()=>f.value,(o,n)=>{o&&o!==n&&(d(),O())},{immediate:!0})}),a.onUnmounted(()=>{d()}),(o,n)=>(a.openBlock(),a.createElementBlock("div",{ref_key:"root",ref:u,class:"lottie-animation-container",style:a.normalizeStyle(h.value),onMouseenter:v,onMouseleave:g},null,36))}}),A={install(i,l){const e=(l==null?void 0:l.name)??"Vue3Lottie";i.component(e,c)}};exports.Vue3Lottie=c;exports.default=A;