"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),F=require("./useNestedProp-DmS8KxmW.cjs"),w=require("./index-7N8NxNg5.cjs"),z=require("./useResponsive-B3TrDDIG.cjs"),b=require("./BaseIcon-3dGIQkTt.cjs"),H=require("./Title-CRj-Ysyr.cjs"),A=require("./_plugin-vue_export-helper-BHFhmbuH.cjs");class L{constructor(N,p,_,T=!0,g=!0){this.interval=p,this.elapsed=0,this.isPaused=!1;const C=`
            let interval;
            let elapsed = 0;
            let paused = false;
            let startTime;
            let tickInterval;

            onmessage = function(e) {
                const { action, data } = e.data;

                switch(action) {
                    case 'start':
                        startTime = Date.now();
                        tickInterval = data.interval;
                        elapsed = 0;
                        paused = false;
                        interval = setInterval(() => {
                            elapsed += tickInterval;
                            postMessage({ elapsed, timestamp: Date.now() });
                        }, tickInterval);
                        break;
                    
                    case 'pause':
                        paused = true;
                        clearInterval(interval);
                        elapsed = Date.now() - startTime;
                        break;

                    case 'resume':
                        if (paused) {
                            startTime = Date.now() - elapsed;
                            interval = setInterval(() => {
                                elapsed += tickInterval;
                                postMessage({ elapsed, timestamp: Date.now() });
                            }, tickInterval);
                        }
                        paused = false;
                        break;

                    case 'stop':
                        clearInterval(interval);
                        elapsed = 0;
                        postMessage({ elapsed });
                        break;

                    case 'reset':
                        elapsed = 0;
                        clearInterval(interval);
                        postMessage({ elapsed });
                        break;

                    case 'lap':
                        postMessage({
                            elapsed,
                            timestamp: Date.now(),
                            action: 'lap'
                        });
                        break;

                    default:
                        break;
                }
            };
        `,B=new Blob([C],{type:"application/javascript"}),k=URL.createObjectURL(B),u=new Worker(k);function t(c){let a=Math.floor(c/1e3),n=Math.floor(c%1e3/10),d=Math.floor(a/3600),v=Math.floor(a%3600/60),l=a%60,o="";return g&&(o+=String(d).padStart(2,"0")+":"),o+=String(v).padStart(2,"0")+":",o+=String(l).padStart(2,"0"),T&&(o+="."+String(n).padStart(2,"0")),o}this.start=()=>{this.isPaused=!1,u.postMessage({action:"start",data:{interval:this.interval}})},this.pause=()=>{this.isPaused?this.resume():(this.isPaused=!0,u.postMessage({action:"pause"}))},this.resume=()=>{this.isPaused&&(u.postMessage({action:"resume"}),this.isPaused=!1)},this.stop=()=>{u.postMessage({action:"stop"}),this.isPaused=!1},this.reset=()=>{u.postMessage({action:"reset"}),this.elapsed=0,this.isPaused=!1},this.restart=()=>{this.stop(),this.start()},this.lap=()=>new Promise(c=>{u.postMessage({action:"lap"});const a=n=>{const{elapsed:d,timestamp:v,action:l}=n.data;if(l==="lap"){const o=t(d);c({timestamp:v||0,elapsed:d,formatted:o})}};u.addEventListener("message",a,{once:!0})}),u.onmessage=c=>{const{elapsed:a,timestamp:n}=c.data;this.elapsed=a,N({timestamp:n||0,elapsed:this.elapsed,formatted:t(this.elapsed)})},u.onerror=c=>{_&&_(c)}}}const j=["xmlns","viewBox"],O={key:0},q=["id"],U=["stop-color"],W=["stop-color"],G=["cx","cy","r","fill","stroke","stroke-width"],X=["d","stroke","stroke-width"],J=["r","fill","stroke","stroke-width"],K=["r","fill","stroke","stroke-width"],Q=["x","y"],Y=["x","y","font-size","fill","font-weight"],Z={key:0,class:"vue-ui-timer-controls"},ee=["title"],te=["title"],ae=["title"],le=["title"],se=["title"],oe={__name:"vue-ui-timer",props:{config:{type:Object,default(){return{}}}},emits:["start","pause","reset","restart","lap"],setup(V,{expose:N,emit:p}){const _=V,{vue_ui_timer:T}=w.useConfig(),g=e.ref(null),C=e.ref(null),B=e.ref(null),k=e.ref(null),u=e.ref(w.createUid());e.onMounted(()=>{if(t.value.responsive){const s=z.throttle(()=>{const{width:r,height:i}=z.useResponsive({chart:g.value,title:t.value.style.title.text?C.value:null,legend:B.value});a.value.width=r,a.value.height=i,a.value.tracker.core=w.translateSize({relator:Math.min(r,i),adjuster:t.value.style.width,source:6*t.value.stopwatch.tracker.radiusRatio,threshold:1,fallback:1}),a.value.tracker.aura=w.translateSize({relator:Math.min(r,i),adjuster:t.value.style.width,source:12*t.value.stopwatch.tracker.aura.radiusRatio,threshold:1,fallback:1}),a.value.label=w.translateSize({relator:Math.min(r,i),adjuster:t.value.style.width,source:t.value.stopwatch.label.fontSize,threshold:10,fallback:10})});k.value=new ResizeObserver(s),k.value.observe(g.value.parentNode)}}),e.onBeforeUnmount(()=>{k.value&&k.value.disconnect()});const t=e.computed(()=>F.useNestedProp({userConfig:_.config,defaultConfig:T})),c=e.computed(()=>{if(t.value.stopwatch.showHours&&t.value.stopwatch.showHundredth)return"00:00:00.00";if(t.value.stopwatch.showHours&&!t.value.stopwatch.showHundredth)return"00:00:00";if(!t.value.stopwatch.showHours&&t.value.stopwatch.showHundredth)return"00:00.00";if(!t.value.stopwatch.showHours&&!t.value.stopwatch.showHundredth)return"00:00"}),a=e.ref({height:t.value.style.height,width:t.value.style.width,tracker:{core:6*t.value.stopwatch.tracker.radiusRatio,aura:12*t.value.stopwatch.tracker.aura.radiusRatio},label:t.value.stopwatch.label.fontSize}),n=e.ref(0),d=new L(s=>I(s),10,"",t.value.stopwatch.showHundredth,t.value.stopwatch.showHours),v=e.ref(!0),l=e.ref(!1),o=e.ref(!1);function S(){p("start"),v.value&&d.start(),v.value=!1,l.value=!0}function P(){l.value&&(p("reset"),d.stop(),m.value=[],v.value=!0,l.value=!1)}function E(){o.value=!o.value,p("pause",n.value),d.pause()}function x(){l.value&&(o.value=!1,p("restart"),m.value=[],d.restart())}const m=e.ref([]);async function M(){if(!l.value||o.value)return;const s=await d.lap();s&&(m.value.push(s),p("lap",m.value))}function I({timestamp:s,elapsed:r,formatted:i}){n.value={timestamp:s,elapsed:r,formatted:i}}const h=e.computed(()=>Math.min(a.value.width,a.value.height)/2.5*t.value.stopwatch.track.radiusRatio);function R(s,r){const y=360/(r*1e3);return s*y%360}function $(s){let r=s*(Math.PI/180),i=a.value.width/2+h.value*Math.cos(r),y=a.value.height/2+h.value*Math.sin(r);return{cx:i,cy:y}}const f=e.computed(()=>{const s=R(n.value.elapsed,t.value.stopwatch.cycleSeconds),{cx:r,cy:i}=$(s-90),y=s>180?1:0;return{cx:r||a.value.width/2,cy:i||a.value.height/2-h.value,largeArcFlag:y,sweepFlag:1}});return N({start:S,pause:E,reset:P,restart:x,lap:M}),(s,r)=>(e.openBlock(),e.createElementBlock("div",{ref_key:"timerChart",ref:g,class:"vue-ui-timer",style:e.normalizeStyle({fontFamily:t.value.style.fontFamily,width:"100%",height:t.value.responsive?"100%":"auto",textAlign:"center"})},[t.value.style.title.text?(e.openBlock(),e.createElementBlock("div",{key:0,ref_key:"chartTitle",ref:C,style:e.normalizeStyle({width:"100%",background:t.value.style.backgroundColor})},[e.createVNode(H._sfc_main,{config:{title:{cy:"title",...t.value.style.title},subtitle:{cy:"subtitle",...t.value.style.title.subtitle}}},null,8,["config"])],4)):e.createCommentVNode("",!0),(e.openBlock(),e.createElementBlock("svg",{xmlns:e.unref(w.XMLNS),viewBox:`0 0 ${a.value.width<=0?10:a.value.width} ${a.value.height<=0?10:a.value.height}`,style:e.normalizeStyle({maxWidth:"100%",overflow:"visible",background:t.value.style.backgroundColor})},[t.value.stopwatch.tracker.gradient.show?(e.openBlock(),e.createElementBlock("defs",O,[e.createElementVNode("radialGradient",{id:`tracker_gradient_${u.value}`,cx:"50%",cy:"50%",r:"50%",fx:"50%",fy:"50%"},[e.createElementVNode("stop",{offset:"0%","stop-color":t.value.stopwatch.tracker.gradient.color},null,8,U),e.createElementVNode("stop",{offset:"100%","stop-color":t.value.stopwatch.tracker.fill},null,8,W)],8,q)])):e.createCommentVNode("",!0),e.createElementVNode("circle",{cx:a.value.width/2,cy:a.value.height/2,r:h.value,fill:t.value.stopwatch.track.fill,stroke:t.value.stopwatch.track.stroke,"stroke-width":t.value.stopwatch.track.strokeWidth},null,8,G),t.value.stopwatch.cycleTrack.show?(e.openBlock(),e.createElementBlock("path",{key:1,d:`M ${a.value.width/2},${a.value.height/2-h.value} A ${h.value},${h.value} 0 ${f.value.largeArcFlag},${f.value.sweepFlag} ${f.value.cx},${f.value.cy}`,stroke:t.value.stopwatch.cycleTrack.stroke,"stroke-width":t.value.stopwatch.cycleTrack.strokeWidth,"stroke-linecap":"round",fill:"none"},null,8,X)):e.createCommentVNode("",!0),e.createElementVNode("circle",e.mergeProps(f.value,{r:a.value.tracker.core,fill:t.value.stopwatch.tracker.gradient.show?`url(#tracker_gradient_${u.value})`:t.value.stopwatch.tracker.fill,stroke:t.value.stopwatch.tracker.stroke,"stroke-width":t.value.stopwatch.tracker.strokeWidth}),null,16,J),t.value.stopwatch.tracker.aura.show?(e.openBlock(),e.createElementBlock("circle",e.mergeProps({key:2},f.value,{r:a.value.tracker.aura,fill:`${t.value.stopwatch.tracker.aura.fill}20`,stroke:t.value.stopwatch.tracker.aura.stroke,"stroke-width":t.value.stopwatch.tracker.aura.strokeWidth}),null,16,K)):e.createCommentVNode("",!0),s.$slots.time?(e.openBlock(),e.createElementBlock("foreignObject",{key:3,x:a.value.width/2,y:a.value.height/2,height:"0.1",width:"0.1",style:{overflow:"visible"}},[e.renderSlot(s.$slots,"time",e.normalizeProps(e.guardReactiveProps({...n.value})),void 0,!0)],8,Q)):(e.openBlock(),e.createElementBlock("text",{key:4,x:a.value.width/2,y:a.value.height/2+a.value.label/4,"font-size":a.value.label,"text-anchor":"middle",fill:t.value.stopwatch.label.color,"font-weight":t.value.stopwatch.label.bold?"bold":"normal",style:{"font-variant-numeric":"tabular-nums !important"}},e.toDisplayString(n.value.formatted||c.value),9,Y))],12,j)),e.createElementVNode("div",{ref_key:"chartLegend",ref:B,style:e.normalizeStyle({width:"100%",backgroundColor:t.value.stopwatch.legend.backgroundColor})},[s.$slots.controls?e.createCommentVNode("",!0):(e.openBlock(),e.createElementBlock("div",Z,[t.value.stopwatch.legend.buttons.start?(e.openBlock(),e.createElementBlock("button",{key:0,title:t.value.stopwatch.legend.buttonTitles.start,onClick:S,class:"vue-ui-timer-button",style:e.normalizeStyle({opacity:l.value?.2:1,cursor:l.value?"default":"pointer"})},[e.createVNode(b.default,{name:"play",stroke:t.value.stopwatch.legend.buttons.iconColor},null,8,["stroke"])],12,ee)):e.createCommentVNode("",!0),t.value.stopwatch.legend.buttons.pause?(e.openBlock(),e.createElementBlock("button",{key:1,title:o.value?t.value.stopwatch.legend.buttonTitles.resume:t.value.stopwatch.legend.buttonTitles.pause,onClick:E,class:"vue-ui-timer-button",style:e.normalizeStyle({opacity:l.value?1:.2,cursor:l.value?"pointer":"default"})},[e.createVNode(b.default,{name:"pause",stroke:t.value.stopwatch.legend.buttons.iconColor},null,8,["stroke"])],12,te)):e.createCommentVNode("",!0),t.value.stopwatch.legend.buttons.reset?(e.openBlock(),e.createElementBlock("button",{key:2,title:t.value.stopwatch.legend.buttonTitles.reset,onClick:P,class:"vue-ui-timer-button",style:e.normalizeStyle({opacity:l.value?1:.2,cursor:l.value?"pointer":"default"})},[e.createVNode(b.default,{name:"stop",stroke:t.value.stopwatch.legend.buttons.iconColor},null,8,["stroke"])],12,ae)):e.createCommentVNode("",!0),t.value.stopwatch.legend.buttons.restart?(e.openBlock(),e.createElementBlock("button",{key:3,title:t.value.stopwatch.legend.buttonTitles.restart,onClick:x,class:"vue-ui-timer-button",style:e.normalizeStyle({opacity:l.value?1:.2,cursor:l.value?"pointer":"default"})},[e.createVNode(b.default,{name:"restart",stroke:t.value.stopwatch.legend.buttons.iconColor},null,8,["stroke"])],12,le)):e.createCommentVNode("",!0),t.value.stopwatch.legend.buttons.lap?(e.openBlock(),e.createElementBlock("button",{key:4,title:t.value.stopwatch.legend.buttonTitles.lap,onClick:M,class:"vue-ui-timer-button",style:e.normalizeStyle({opacity:l.value&&!o.value?1:.2,cursor:l.value&&!o.value?"pointer":"default"})},[e.createVNode(b.default,{name:"lap",stroke:t.value.stopwatch.legend.buttons.iconColor},null,8,["stroke"])],12,se)):e.createCommentVNode("",!0)])),e.renderSlot(s.$slots,"controls",e.normalizeProps(e.guardReactiveProps({start:S,pause:E,reset:P,restart:x,lap:M,laps:m.value,isRunning:l.value,isPaused:o.value,...n.value})),void 0,!0),e.renderSlot(s.$slots,"laps",e.normalizeProps(e.guardReactiveProps({laps:m.value,lap:M,isRunning:l.value,isPaused:o.value,...n.value})),void 0,!0)],4)],4))}},re=A._export_sfc(oe,[["__scopeId","data-v-1e579c02"]]);exports.default=re;
