import{q as e,c as a,bW as t,V as u,bX as l,S as s,U as r,t as i,v as n,G as v,K as d,X as o}from"./vendor-core-Di0OO4oJ.js";const f="easeOutExpo",p=e({__name:"index",props:{target:{default:0},duration:{default:2e3},autoStart:{type:Boolean,default:!0},decimals:{default:0},decimal:{default:"."},separator:{default:""},prefix:{default:""},suffix:{default:""},easing:{default:f},disabled:{type:Boolean,default:!1}},emits:["started","finished","paused","reset"],setup(e,{expose:p,emit:c}){const m=Number.EPSILON,b=e,g=c,x=(e,a,t)=>Number.isFinite(e)?e:t,h=(e,a,t)=>Math.max(a,Math.min(e,t)),S=a(()=>x(b.target,0,0)),F=a(()=>h(x(b.duration,0,2e3),100,6e4)),N=a(()=>h(x(b.decimals,0,0),0,10)),M=a(()=>{const e=b.easing;return e in t?e:f}),$=u(0),y=u(S.value),B=u(!1),V=u(!1),_=u(0),j=l($,{duration:F,transition:a(()=>t[M.value]),onStarted:()=>{B.value=!0,V.value=!1,g("started",y.value)},onFinished:()=>{B.value=!1,V.value=!1,g("finished",y.value)}}),E=a(()=>{const e=V.value?_.value:j.value;if(!Number.isFinite(e))return`${b.prefix}0${b.suffix}`;const a=((e,a,t,u)=>{let l=a>0?e.toFixed(a):Math.floor(e).toString();if("."!==t&&l.includes(".")&&(l=l.replace(".",t)),u){const e=l.split(t);e[0]=e[0].replace(/\B(?=(\d{3})+(?!\d))/g,u),l=e.join(t)}return l})(e,N.value,b.decimal,b.separator);return`${b.prefix}${a}${b.suffix}`}),O=()=>{V.value=!1,_.value=0},P=e=>{if(b.disabled)return;const a=void 0!==e?e:y.value;Number.isFinite(a)&&(y.value=a,(e=>{const a=V.value?_.value:j.value;return Math.abs(a-e)<m})(a)||(V.value&&($.value=_.value,O()),o(()=>{$.value=a})))},X=()=>{(B.value||V.value)&&($.value=0,O(),g("paused",0))};return s(S,e=>{b.autoStart&&!b.disabled?P(e):y.value=e},{immediate:b.autoStart&&!b.disabled}),s(()=>b.disabled,e=>{e&&B.value&&X()}),r(()=>{B.value&&X()}),p({start:P,pause:()=>{B.value&&!V.value&&(V.value=!0,_.value=j.value,$.value=_.value,g("paused",_.value))},reset:(e=0)=>{const a=x(e,0,0);$.value=a,y.value=a,O(),g("reset")},stop:X,setTarget:e=>{Number.isFinite(e)&&(y.value=e,!B.value&&!b.autoStart||b.disabled||P(e))},get isRunning(){return B.value},get isPaused(){return V.value},get currentValue(){return V.value?_.value:j.value},get targetValue(){return y.value},get progress(){const e=V.value?_.value:j.value,a=y.value;return 0===a?0===e?1:0:Math.abs(e/a)}}),(e,a)=>(n(),i("span",{class:v(["text-g-900 tabular-nums",B.value?"transition-opacity duration-300 ease-in-out":""])},d(E.value),3))}});export{p as _};
