(function(b,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],e):(b=typeof globalThis<"u"?globalThis:b||self,e(b["vue-timeline-chart"]={},b.Vue))})(this,function(b,e){"use strict";const j=i=>{const a=e.ref(0),l=e.ref(0);let o;function d(w){o=new ResizeObserver(([s])=>{const c=s==null?void 0:s.contentRect;c&&([a.value,l.value]=[c.width,c.height])}),o.observe(w)}return e.watch(i,w=>{if(w){d(w);return}o==null||o.disconnect()}),{width:a,height:l}},C=function(i){return`${i}`.trim().padStart(2,"0")};function h(i){const a=Object.prototype.toString.call(i);return i instanceof Date||typeof i=="object"&&a==="[object Date]"?new i.constructor(+i):typeof i=="number"||a==="[object Number]"||typeof i=="string"||a==="[object String]"?new Date(i):new Date(NaN)}function L(i,a){return i instanceof Date?new i.constructor(a):new Date(a)}function F(i,a){const l=+h(i);return L(i,l+a)}const Z=6e4,q=36e5;function K(i,a){return F(i,a*q)}function N(i){const a=h(i);return a.setHours(0,0,0,0),a}function A(i,a){return F(i,a*Z)}function U(i,a){const l=h(i.start),o=h(i.end);let d=+l>+o;const w=d?+l:+o,s=d?o:l;s.setHours(0,0,0,0);let c=1;const p=[];for(;+s<=w;)p.push(h(s)),s.setDate(s.getDate()+c),s.setHours(0,0,0,0);return d?p.reverse():p}function G(i,a){const l=h(i.start),o=h(i.end);let d=+l>+o;const w=d?+l:+o;let s=d?o:l;s.setMinutes(0,0,0);let c=1;const p=[];for(;+s<=w;)p.push(h(s)),s=K(s,c);return d?p.reverse():p}function J(i){const a=h(i);return a.setSeconds(0,0),a}function z(i,a){const l=J(h(i.start)),o=h(i.end);let d=+l>+o;const w=d?+l:+o;let s=d?o:l,c=1;const p=[];for(;+s<=w;)p.push(h(s)),s=A(s,c);return d?p.reverse():p}function Q(i,a){const l=h(i.start),o=h(i.end);let d=+l>+o;const w=d?+l:+o,s=d?o:l;s.setHours(0,0,0,0),s.setDate(1);let c=1;const p=[];for(;+s<=w;)p.push(h(s)),s.setMonth(s.getMonth()+c);return d?p.reverse():p}function ee(i){const a=h(i);return a.setDate(1),a.setHours(0,0,0,0),a}function te(i){const a=h(i),l=L(i,0);return l.setFullYear(a.getFullYear(),0,1),l.setHours(0,0,0,0),l}function ne(i,a){const l=h(i.start),o=h(i.end);let d=+l>+o;const w=d?+l:+o,s=d?o:l;s.setHours(0,0,0,0),s.setMonth(0,1);let c=1;const p=[];for(;+s<=w;)p.push(h(s)),s.setFullYear(s.getFullYear()+c);return d?p.reverse():p}const D={ms:1,seconds:1e3,minutes:1e3*60,hours:1e3*60*60,days:1e3*60*60*24,months:1e3*60*60*24*7*4,years:1e3*60*60*24*7*4*12},oe=(i,a,l,o)=>{const d=e.ref(l.value),w=e.ref(o.value),s=[{unit:"seconds",steps:[1,10]},{unit:"minutes",steps:[.25,.5,1,5,10]},{unit:"hours",steps:[.25,.5,1,2]},{unit:"days",steps:[1]},{unit:"months",steps:[.25,1,2]},{unit:"years",steps:[1,5,10,25,50,100,250,500,1e3]}].flatMap(m=>m.steps.map(y=>({unit:m.unit,step:y})));e.watch(l,()=>{d.value=l.value}),e.watch(o,()=>{w.value=o.value});const c=e.computed(()=>{let[m]=s;for(const[y,v]of s.entries()){const M=d.value/(D[v.unit]*(v.step??1));if(M>=1&&M<=w.value){m=v;break}if(M<1){m=s[y-1]??v;break}M>=1&&y===s.length-1&&(m=v)}return{unit:m.unit,step:m.step??1}}),p=e.computed(()=>{const m=[],y=i.value,v=a.value;let M=[];switch(c.value.unit){case"seconds":M=z({start:y,end:v}).flatMap(V=>{const x=[];for(let g=0;g<60;g++)x.push(new Date(V.valueOf()+g*D.seconds));return x});break;case"minutes":M=z({start:y,end:v});break;case"hours":M=G({start:y,end:v});break;case"days":M=U({start:y,end:v});break;case"months":M=Q({start:y,end:v});break;case"years":M=ne({start:y,end:v});break}for(const V of M)if(c.value.step&&c.value.step>1?(c.value.unit==="years"&&V.getFullYear()%c.value.step===0||c.value.unit==="months"&&V.getMonth()%c.value.step===0||V.valueOf()%(c.value.step*D[c.value.unit])===0)&&m.push(V.valueOf()):m.push(V.valueOf()),c.value.step&&c.value.step<1)for(let x=1;x<1/c.value.step;x++)m.push(V.valueOf()+x*c.value.step*D[c.value.unit]);return m});return{scale:c,baseDividers:D,visibleTimestamps:p}},re={class:"timeline-wrapper"},ie={class:"timestamps"},se={class:"groups"},ae={class:"group-items"},le=["onClick","onPointermove","onPointerdown","onPointerup","onContextmenu"],ce=["onClick","onPointermove","onPointerdown","onPointerup","onContextmenu"],ue={key:0,class:"backgrounds"},de=["onClick","onPointermove","onPointerdown","onPointerup","onContextmenu"],pe={key:1,class:"markers"},fe=((i,a)=>{const l=i.__vccOpts||i;for(const[o,d]of a)l[o]=d;return l})(e.defineComponent({__name:"Timeline",props:{groups:{default:()=>[]},items:{default:()=>[]},markers:{default:()=>[]},viewportMin:{default:void 0},viewportMax:{default:void 0},minViewportDuration:{default:1e3},maxViewportDuration:{default:void 0},initialViewportStart:{default:void 0},initialViewportEnd:{default:void 0},renderTimestampLabel:{type:Function,default:(i,a)=>{const l=new Date(i);let o="";return(!["hours","minutes","seconds","ms"].includes(a.unit)||N(l).valueOf()===i)&&(o+=`${l.toLocaleString("default",{month:a.unit!=="years"&&(ee(l).valueOf()===i||a.unit==="days"||N(l).valueOf()===i&&!(a.unit==="months"&&a.step===.25))?"short":void 0,year:te(l).valueOf()===i?"numeric":void 0,day:a.unit!=="years"&&!(a.unit==="months"&&a.step>=1)&&N(l).valueOf()===i?"numeric":void 0})} `),["hours","minutes","seconds","ms"].includes(a.unit)&&(o+=`${C(l.getHours())}:${C(l.getMinutes())}${l.getSeconds()>0?`:${C(l.getSeconds())}`:""}`),o}},fixedLabels:{type:Boolean,default:!1},minTimestampWidth:{default:100},maxZoomSpeed:{default:60},activeItems:{default:()=>[]},maxOffsetOutsideViewport:{default:50}},emits:["pointermove","pointerdown","pointerup","wheel","click","contextmenu","mousemoveTimeline","mouseleaveTimeline","changeViewport","changeScale"],setup(i,{expose:a,emit:l}){const o=i,d=l;a({onWheel:R});const w=e.ref(null),{width:s}=j(w),c=e.ref(0),p=e.ref(1e4),m=e.computed(()=>p.value-c.value);e.watch([c,p],([t,u])=>{d("changeViewport",{start:t,end:u})}),e.watchEffect(()=>{try{W(),y()}catch(t){console.error(t)}});function y(){var t,u;if(o.initialViewportStart===void 0&&o.viewportMin===void 0){const r=(t=o.items)==null?void 0:t.reduce((n,f)=>f.startf.end!==void 0&&f.end>n||f.start>n?f.end??f.start:n,-1/0);p.value=r??1e4}else p.value=o.initialViewportEnd??o.viewportMax??1e4}const v=e.computed(()=>{var t;return((t=o.items)==null?void 0:t.filter(u=>u.startc.value))||[]}),M=e.computed(()=>{var t;return((t=o.markers)==null?void 0:t.filter(u=>u.startc.value))||[]}),V=e.computed(()=>s.value/o.minTimestampWidth),{visibleTimestamps:x,scale:g}=oe(c,p,m,V);e.watch(g,(t,u)=>{t.step===u.step&&t.unit===u.unit||d("changeScale",t)});function me(t){return{"is-second":t%1e3===0,"is-minute":t%6e4===0,"is-hour":t%36e5===0,"is-day":t%864e5===0}}const B=e.computed(()=>o.maxOffsetOutsideViewport/s.value*m.value),Y=e.computed(()=>s.value+2*(B.value/m.value)*s.value);function S(t,u){if(u!==void 0&&tY.value){const k=-B.value/m.value*s.value,X=p.value+B.value;if(u>X)return k;const Me=(X-u)/m.value*s.value;return k-Me}return(t-c.value)/m.value*s.value}function T(t,u){if(isNaN(u))return null;const n=(u-t)/m.value*s.value;return Math.min(n,Y.value)}function H(t){const u=t/s.value*m.value;t>0&&p.value===o.viewportMax||t<0&&c.value===o.viewportMin||(c.value=Math.round(o.viewportMin!==void 0?Math.max(c.value+u,o.viewportMin):c.value+u),p.value=Math.round(o.viewportMax!==void 0?Math.min(p.value+u,o.viewportMax):p.value+u))}function W(){if(o.initialViewportStart!==void 0&&o.initialViewportEnd!==void 0&&o.initialViewportStart>=o.initialViewportEnd)throw new Error("[vue-timeline-chart] Invalid props: initialViewportStart must be smaller than initialViewportEnd");if(o.viewportMin!==void 0&&o.viewportMax!==void 0&&o.viewportMin>=o.viewportMax)throw new Error("[vue-timeline-chart] Invalid props: viewportMin must be smaller than viewportMax");if(o.initialViewportStart!==void 0&&o.viewportMin!==void 0&&o.initialViewportStarto.viewportMax)throw new Error("[vue-timeline-chart] Invalid props: initialViewportEnd must be smaller than or equal to viewportMax")}function R(t){if(W(),d("wheel",t),t.deltaY===0&&t.preventDefault(),t.shiftKey){t.preventDefault();const f=t.deltaY===0&&t.deltaX!==0?t.deltaX:t.deltaY;H(f*(t.deltaMode===0?1:18));return}if(t.deltaX!==0){H(t.deltaX*(t.deltaMode===0?1:18));return}if(!(t.metaKey||t.ctrlKey))return;t.preventDefault();const u=(t.clientX-w.value.getBoundingClientRect().left)/s.value,r=o.maxZoomSpeed?Math.max(-o.maxZoomSpeed,Math.min(o.maxZoomSpeed,t.deltaY*(t.deltaMode===0?1:10))):t.deltaY*(t.deltaMode===0?1:10),n=Math.round(-m.value*.01*r);we(n,u)}function we(t,u=.5){t>0?t=m.value-to.maxViewportDuration?-(o.maxViewportDuration-m.value):t);const r=t*u,n=t-r,f=c.value+r,k=p.value-n;if(f>=k){console.error(`Rounding issue probably occured while zooming. Setting different values for minViewportDuration and maxViewportDuration might help.`);return}c.value=Math.round(o.viewportMin!==void 0?Math.max(f,o.viewportMin):f),p.value=Math.round(o.viewportMax!==void 0?Math.min(k,o.viewportMax):k)}function E(t){const u=(t.clientX-w.value.getBoundingClientRect().left)/s.value;return c.value+m.value*u}function _(t,u=null){d("pointermove",{time:E(t),event:t,item:u})}function P(t,u=null){d("pointerdown",{time:E(t),event:t,item:u})}function $(t,u=null){d("pointerup",{time:E(t),event:t,item:u})}function O(t,u=null){d("click",{time:E(t),event:t,item:u})}function I(t,u=null){d("contextmenu",{time:E(t),event:t,item:u})}function he(t){d("mousemoveTimeline",{time:E(t),event:t})}function ve(t){d("mouseleaveTimeline",{event:t})}return(t,u)=>(e.openBlock(),e.createElementBlock("div",re,[e.createElementVNode("div",{ref_key:"timelineEl",ref:w,class:"timeline",onWheel:R,onClick:O,onPointermove:_,onPointerdown:P,onPointerup:$,onContextmenu:e.withModifiers(I,["prevent"]),onMousemove:he,onMouseleave:ve},[e.createElementVNode("div",ie,[e.renderSlot(t.$slots,"timestamps-before",{scale:e.unref(g)},void 0,!0),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(e.unref(x),r=>(e.openBlock(),e.createElementBlock("div",{key:r,class:e.normalizeClass(["timestamp",me(r)]),style:e.normalizeStyle({"--_left":`${S(r)}px`})},[e.renderSlot(t.$slots,"timestamp",{timestamp:r,scale:e.unref(g)},()=>[e.createTextVNode(e.toDisplayString(t.renderTimestampLabel(r,e.unref(g))),1)],!0)],6))),128)),e.renderSlot(t.$slots,"timestamps-after",{scale:e.unref(g)},void 0,!0),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(M.value.filter(r=>r.group==="_timestamps").sort((r,n)=>r.start-n.start),r=>(e.openBlock(),e.createElementBlock("div",{key:r.id??`${r.start}${r.type}`,style:e.normalizeStyle({"--_left":`${S(r.start)}px`,...r.cssVariables}),class:e.normalizeClass([r.type,r.className])},null,6))),128))]),e.createElementVNode("div",se,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(t.groups,r=>(e.openBlock(),e.createElementBlock("div",{key:r.id,class:e.normalizeClass(["group",r.className]),style:e.normalizeStyle(r.cssVariables)},[e.createElementVNode("div",{class:e.normalizeClass(["group-label",{fixed:t.fixedLabels}])},[e.renderSlot(t.$slots,"group-label",{group:r},()=>[e.createTextVNode(e.toDisplayString(r.label),1)],!0)],2),e.createElementVNode("div",ae,[e.renderSlot(t.$slots,`items-${r.id}`,{group:r,itemsInViewport:v.value.filter(n=>n.group===r.id&&n.type!="background").sort((n,f)=>n.start-f.start),viewportStart:c.value,viewportEnd:p.value},()=>[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(v.value.filter(n=>n.group===r.id&&n.type!="background").sort((n,f)=>n.start-f.start),(n,f)=>(e.openBlock(),e.createElementBlock("div",{key:n.id??f,style:e.normalizeStyle({"--_left":`${S(n.start,n.end)}px`,"--_width":n.type!=="point"?`${T(n.start,n.end)}px`:null,...n.cssVariables}),class:e.normalizeClass(["item",n.type,n.className,{active:t.activeItems.includes(n.id)}]),onClick:e.withModifiers(k=>O(k,n),["stop"]),onPointermove:e.withModifiers(k=>_(k,n),["stop"]),onPointerdown:e.withModifiers(k=>P(k,n),["stop"]),onPointerup:e.withModifiers(k=>$(k,n),["stop"]),onContextmenu:e.withModifiers(k=>I(k,n),["prevent","stop"])},[e.renderSlot(t.$slots,"item",{item:n},void 0,!0)],46,le))),128))],!0)]),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(v.value.filter(n=>n.group===r.id&&n.type==="background").sort((n,f)=>n.start-f.start),n=>(e.openBlock(),e.createElementBlock("div",{key:n.id??`${n.start}${n.type}${n.end||""}`,style:e.normalizeStyle({"--_left":`${S(n.start,n.end)}px`,"--_width":`${T(n.start,n.end)}px`,...n.cssVariables}),class:e.normalizeClass([n.type,n.className]),onClick:e.withModifiers(f=>O(f,n),["stop"]),onPointermove:e.withModifiers(f=>_(f,n),["stop"]),onPointerdown:e.withModifiers(f=>P(f,n),["stop"]),onPointerup:e.withModifiers(f=>$(f,n),["stop"]),onContextmenu:e.withModifiers(f=>I(f,n),["prevent","stop"])},null,46,ce))),128)),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(M.value.filter(n=>n.group===r.id).sort((n,f)=>n.start-f.start),n=>(e.openBlock(),e.createElementBlock("div",{key:n.id??`${n.start}${n.type}`,style:e.normalizeStyle({"--_left":`${S(n.start)}px`,...n.cssVariables}),class:e.normalizeClass([n.type,n.className])},null,6))),128))],6))),128)),v.value.some(r=>!r.group&&r.type=="background")?(e.openBlock(),e.createElementBlock("div",ue,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(v.value.filter(r=>!r.group&&r.type=="background"),r=>(e.openBlock(),e.createElementBlock("div",{key:r.id??`${r.start}${r.type}${r.end||""}`,style:e.normalizeStyle({"--_left":`${S(r.start,r.end)}px`,"--_width":`${T(r.start,r.end)}px`,...r.cssVariables}),class:e.normalizeClass([r.type,r.className]),onClick:e.withModifiers(n=>O(n,r),["stop"]),onPointermove:e.withModifiers(n=>_(n,r),["stop"]),onPointerdown:e.withModifiers(n=>P(n,r),["stop"]),onPointerup:e.withModifiers(n=>$(n,r),["stop"]),onContextmenu:e.withModifiers(n=>I(n,r),["prevent","stop"])},null,46,de))),128))])):e.createCommentVNode("",!0),M.value.length>0?(e.openBlock(),e.createElementBlock("div",pe,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(M.value.filter(r=>!r.group),r=>(e.openBlock(),e.createElementBlock("div",{key:r.id??`${r.start}${r.type}`,style:e.normalizeStyle({"--_left":`${S(r.start)}px`,...r.cssVariables}),class:e.normalizeClass([r.type,r.className])},null,6))),128))])):e.createCommentVNode("",!0)])],544)]))}}),[["__scopeId","data-v-74a4842c"]]);b.Timeline=fe,Object.defineProperty(b,Symbol.toStringTag,{value:"Module"})});