"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),L=require("./useNestedProp-DO3dp1MP.cjs"),g=require("./index-BCDlAguz.cjs"),R=require("./useResponsive-BJ7DTGpm.cjs"),B=require("./BaseIcon-C2QCjRyr.cjs"),j=require("./Title-BfJpPrNN.cjs"),q=require("./PackageVersion-D_1AMUyo.cjs"),O=require("./_plugin-vue_export-helper-BHFhmbuH.cjs");class U{constructor(P,p,y,T=!0,b=!0){this.interval=p,this.elapsed=0,this.isPaused=!1;const S=`
            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;
                }
            };
        `,M=new Blob([S],{type:"application/javascript"}),k=URL.createObjectURL(M),n=new Worker(k);function _(u){let t=Math.floor(u/1e3),h=Math.floor(u%1e3/10),f=Math.floor(t/3600),a=Math.floor(t%3600/60),i=t%60,r="";return b&&(r+=String(f).padStart(2,"0")+":"),r+=String(a).padStart(2,"0")+":",r+=String(i).padStart(2,"0"),T&&(r+="."+String(h).padStart(2,"0")),r}this.start=()=>{this.isPaused=!1,n.postMessage({action:"start",data:{interval:this.interval}})},this.pause=()=>{this.isPaused?this.resume():(this.isPaused=!0,n.postMessage({action:"pause"}))},this.resume=()=>{this.isPaused&&(n.postMessage({action:"resume"}),this.isPaused=!1)},this.stop=()=>{n.postMessage({action:"stop"}),this.isPaused=!1},this.reset=()=>{n.postMessage({action:"reset"}),this.elapsed=0,this.isPaused=!1},this.restart=()=>{this.stop(),this.start()},this.lap=()=>new Promise(u=>{n.postMessage({action:"lap"});const t=h=>{const{elapsed:f,timestamp:a,action:i}=h.data;if(i==="lap"){const r=_(f);u({timestamp:a||0,elapsed:f,formatted:r})}};n.addEventListener("message",t,{once:!0})}),n.onmessage=u=>{const{elapsed:t,timestamp:h}=u.data;this.elapsed=t,P({timestamp:h||0,elapsed:this.elapsed,formatted:_(this.elapsed)})},n.onerror=u=>{y&&y(u)}}}const W=["xmlns","viewBox"],G=["width","height"],X={key:1},J=["id"],K=["stop-color"],Q=["stop-color"],Y=["cx","cy","r","fill","stroke","stroke-width"],Z=["d","stroke","stroke-width"],ee=["r","fill","stroke","stroke-width"],te=["r","fill","stroke","stroke-width"],ae=["x","y"],le=["x","y","font-size","fill","font-weight"],se={key:0,class:"vue-ui-timer-controls"},oe=["title"],re=["title"],ne=["title"],ue=["title"],ie=["title"],ce={__name:"vue-ui-timer",props:{config:{type:Object,default(){return{}}}},emits:["start","pause","reset","restart","lap"],setup($,{expose:P,emit:p}){const y=$,{vue_ui_timer:T}=g.useConfig(),b=e.ref(null),S=e.ref(null),M=e.ref(null),k=e.ref(null),n=e.ref(g.createUid()),_=e.ref(0);e.onMounted(()=>{u()});function u(){if(t.value.responsive){const l=R.throttle(()=>{const{width:o,height:c}=R.useResponsive({chart:b.value,title:t.value.style.title.text?S.value:null,legend:M.value});requestAnimationFrame(()=>{a.value.width=o,a.value.height=c,a.value.tracker.core=g.translateSize({relator:Math.min(o,c),adjuster:t.value.style.width,source:6*t.value.stopwatch.tracker.radiusRatio,threshold:1,fallback:1}),a.value.tracker.aura=g.translateSize({relator:Math.min(o,c),adjuster:t.value.style.width,source:12*t.value.stopwatch.tracker.aura.radiusRatio,threshold:1,fallback:1}),a.value.label=g.translateSize({relator:Math.min(o,c),adjuster:t.value.style.width,source:t.value.stopwatch.label.fontSize,threshold:10,fallback:10})})});k.value=new ResizeObserver(l),k.value.observe(b.value.parentNode)}}e.onBeforeUnmount(()=>{k.value&&k.value.disconnect()});const t=e.computed({get:()=>h(),set:l=>l});function h(){return L.useNestedProp({userConfig:y.config,defaultConfig:T})}e.watch(()=>y.config,l=>{t.value=h(),u(),_.value+=1},{deep:!0});const f=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}),i=e.ref(0),r=new U(l=>D(l),10,"",t.value.stopwatch.showHundredth,t.value.stopwatch.showHours),N=e.ref(!0),s=e.ref(!1),d=e.ref(!1);function V(){p("start"),N.value&&r.start(),N.value=!1,s.value=!0}function x(){s.value&&(p("reset"),r.stop(),m.value=[],N.value=!0,s.value=!1)}function z(){d.value=!d.value,p("pause",i.value),r.pause()}function I(){s.value&&(d.value=!1,p("restart"),m.value=[],r.restart())}const m=e.ref([]);async function E(){if(!s.value||d.value)return;const l=await r.lap();l&&(m.value.push(l),p("lap",m.value))}function D({timestamp:l,elapsed:o,formatted:c}){i.value={timestamp:l,elapsed:o,formatted:c}}const v=e.computed(()=>Math.min(a.value.width,a.value.height)/2.5*t.value.stopwatch.track.radiusRatio);function F(l,o){const C=360/(o*1e3);return l*C%360}function A(l){let o=l*(Math.PI/180),c=a.value.width/2+v.value*Math.cos(o),C=a.value.height/2+v.value*Math.sin(o);return{cx:c,cy:C}}const w=e.computed(()=>{const l=F(i.value.elapsed,t.value.stopwatch.cycleSeconds),{cx:o,cy:c}=A(l-90),C=l>180?1:0;return{cx:o||a.value.width/2,cy:c||a.value.height/2-v.value,largeArcFlag:C,sweepFlag:1}});return P({start:V,pause:z,reset:x,restart:I,lap:E}),(l,o)=>(e.openBlock(),e.createElementBlock("div",{ref_key:"timerChart",ref:b,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:S,style:e.normalizeStyle({width:"100%",background:t.value.style.backgroundColor})},[(e.openBlock(),e.createBlock(j._sfc_main,{key:`title_${_.value}`,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(g.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})},[e.createVNode(q._sfc_main),l.$slots["chart-background"]?(e.openBlock(),e.createElementBlock("foreignObject",{key:0,x:0,y:0,width:a.value.width<=0?10:a.value.width,height:a.value.height<=0?10:a.value.height,style:{pointerEvents:"none"}},[e.renderSlot(l.$slots,"chart-background",{},void 0,!0)],8,G)):e.createCommentVNode("",!0),t.value.stopwatch.tracker.gradient.show?(e.openBlock(),e.createElementBlock("defs",X,[e.createElementVNode("radialGradient",{id:`tracker_gradient_${n.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,K),e.createElementVNode("stop",{offset:"100%","stop-color":t.value.stopwatch.tracker.fill},null,8,Q)],8,J)])):e.createCommentVNode("",!0),e.createElementVNode("circle",{cx:a.value.width/2,cy:a.value.height/2,r:v.value,fill:t.value.stopwatch.track.fill,stroke:t.value.stopwatch.track.stroke,"stroke-width":t.value.stopwatch.track.strokeWidth},null,8,Y),t.value.stopwatch.cycleTrack.show?(e.openBlock(),e.createElementBlock("path",{key:2,d:`M ${a.value.width/2},${a.value.height/2-v.value} A ${v.value},${v.value} 0 ${w.value.largeArcFlag},${w.value.sweepFlag} ${w.value.cx},${w.value.cy}`,stroke:t.value.stopwatch.cycleTrack.stroke,"stroke-width":t.value.stopwatch.cycleTrack.strokeWidth,"stroke-linecap":"round",fill:"none"},null,8,Z)):e.createCommentVNode("",!0),e.createElementVNode("circle",e.mergeProps(w.value,{r:a.value.tracker.core,fill:t.value.stopwatch.tracker.gradient.show?`url(#tracker_gradient_${n.value})`:t.value.stopwatch.tracker.fill,stroke:t.value.stopwatch.tracker.stroke,"stroke-width":t.value.stopwatch.tracker.strokeWidth}),null,16,ee),t.value.stopwatch.tracker.aura.show?(e.openBlock(),e.createElementBlock("circle",e.mergeProps({key:3},w.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,te)):e.createCommentVNode("",!0),l.$slots.time?(e.openBlock(),e.createElementBlock("foreignObject",{key:4,x:a.value.width/2,y:a.value.height/2,height:"0.1",width:"0.1",style:{overflow:"visible"}},[e.renderSlot(l.$slots,"time",e.normalizeProps(e.guardReactiveProps({...i.value})),void 0,!0)],8,ae)):(e.openBlock(),e.createElementBlock("text",{key:5,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(i.value.formatted||f.value),9,le))],12,W)),e.createElementVNode("div",{ref_key:"chartLegend",ref:M,style:e.normalizeStyle({width:"100%",backgroundColor:t.value.stopwatch.legend.backgroundColor})},[l.$slots.controls?e.createCommentVNode("",!0):(e.openBlock(),e.createElementBlock("div",se,[t.value.stopwatch.legend.buttons.start?(e.openBlock(),e.createElementBlock("button",{key:0,title:t.value.stopwatch.legend.buttonTitles.start,onClick:V,class:"vue-ui-timer-button",style:e.normalizeStyle({opacity:s.value?.2:1,cursor:s.value?"default":"pointer"})},[e.createVNode(B.default,{name:"play",stroke:t.value.stopwatch.legend.buttons.iconColor},null,8,["stroke"])],12,oe)):e.createCommentVNode("",!0),t.value.stopwatch.legend.buttons.pause?(e.openBlock(),e.createElementBlock("button",{key:1,title:d.value?t.value.stopwatch.legend.buttonTitles.resume:t.value.stopwatch.legend.buttonTitles.pause,onClick:z,class:"vue-ui-timer-button",style:e.normalizeStyle({opacity:s.value?1:.2,cursor:s.value?"pointer":"default"})},[e.createVNode(B.default,{name:"pause",stroke:t.value.stopwatch.legend.buttons.iconColor},null,8,["stroke"])],12,re)):e.createCommentVNode("",!0),t.value.stopwatch.legend.buttons.reset?(e.openBlock(),e.createElementBlock("button",{key:2,title:t.value.stopwatch.legend.buttonTitles.reset,onClick:x,class:"vue-ui-timer-button",style:e.normalizeStyle({opacity:s.value?1:.2,cursor:s.value?"pointer":"default"})},[e.createVNode(B.default,{name:"stop",stroke:t.value.stopwatch.legend.buttons.iconColor},null,8,["stroke"])],12,ne)):e.createCommentVNode("",!0),t.value.stopwatch.legend.buttons.restart?(e.openBlock(),e.createElementBlock("button",{key:3,title:t.value.stopwatch.legend.buttonTitles.restart,onClick:I,class:"vue-ui-timer-button",style:e.normalizeStyle({opacity:s.value?1:.2,cursor:s.value?"pointer":"default"})},[e.createVNode(B.default,{name:"restart",stroke:t.value.stopwatch.legend.buttons.iconColor},null,8,["stroke"])],12,ue)):e.createCommentVNode("",!0),t.value.stopwatch.legend.buttons.lap?(e.openBlock(),e.createElementBlock("button",{key:4,title:t.value.stopwatch.legend.buttonTitles.lap,onClick:E,class:"vue-ui-timer-button",style:e.normalizeStyle({opacity:s.value&&!d.value?1:.2,cursor:s.value&&!d.value?"pointer":"default"})},[e.createVNode(B.default,{name:"lap",stroke:t.value.stopwatch.legend.buttons.iconColor},null,8,["stroke"])],12,ie)):e.createCommentVNode("",!0)])),e.renderSlot(l.$slots,"controls",e.normalizeProps(e.guardReactiveProps({start:V,pause:z,reset:x,restart:I,lap:E,laps:m.value,isRunning:s.value,isPaused:d.value,...i.value})),void 0,!0),e.renderSlot(l.$slots,"laps",e.normalizeProps(e.guardReactiveProps({laps:m.value,lap:E,isRunning:s.value,isPaused:d.value,...i.value})),void 0,!0)],4)],4))}},de=O._export_sfc(ce,[["__scopeId","data-v-be90052b"]]);exports.default=de;
