(function(B,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue"),require("dayjs")):typeof define=="function"&&define.amd?define(["exports","vue","dayjs"],e):(B=typeof globalThis<"u"?globalThis:B||self,e(B.VueGanttastic={},B.Vue,B.dayjs))})(this,function(B,e,x){"use strict";const I=Symbol("COLS"),R=Symbol("CONFIG"),F=Symbol("EMIT_BAR_EVENT"),O=Symbol("EMIT_ROW_EVENT");function M(){const n=e.inject(I);if(!n)throw Error("Failed to inject work days!");return n}function S(){const n=e.inject(R);if(!n)throw Error("Failed to inject config!");return n}const Q=e.defineComponent({__name:"TimeHead",setup(n){const l=M(),{headHeight:t,colWidth:r,cellUnit:a}=S();return(i,c)=>(e.openBlock(),e.createElementBlock("div",{class:"relative w-fit flex border-b z-[999] bg-white",style:e.normalizeStyle({height:`${e.unref(t)}px`})},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(e.unref(l),(o,u)=>(e.openBlock(),e.createElementBlock("div",{key:u,class:e.normalizeClass(["h-full flex-shrink-0 overflow-visible transition-width duration-500",{"border-r":e.unref(a)==="month"}]),style:e.normalizeStyle({width:`${e.unref(r)}px`})},[e.renderSlot(i.$slots,"gantt-head-cell",{cell:o},()=>[e.unref(a)==="day"&&o.day()===1?(e.openBlock(),e.createElementBlock("span",{key:0,class:"text-zinc-400 text-sm px-2",style:e.normalizeStyle({lineHeight:`${e.unref(t)}px`})},e.toDisplayString(o.format("MM/DD")),5)):e.createCommentVNode("",!0),e.unref(a)==="month"?(e.openBlock(),e.createElementBlock("span",{key:1,class:"text-zinc-400 text-sm leading-8 px-2",style:e.normalizeStyle({lineHeight:`${e.unref(t)}px`})},e.toDisplayString(u===0||o.month()===0?o.format("YYYY-MM"):o.format("MM")),5)):e.createCommentVNode("",!0)])],6))),128))],4))}}),Z={class:"size-full flex flex-col overflow-hidden text-zinc-400 text-sm z-[999] bg-white"},ee={class:"flex-1 overflow-hidden"},te=e.defineComponent({__name:"Left",props:{scrolledY:{}},setup(n){const{rowHeight:l,headHeight:t,data:r}=S(),a=n;return(i,c)=>(e.openBlock(),e.createElementBlock("div",Z,[e.createElementVNode("div",{class:"w-full border-b px-2 whitespace-nowrap overflow-hidden text-ellipsis",style:e.normalizeStyle({height:`${e.unref(t)}px`,lineHeight:`${e.unref(t)}px`})},[e.renderSlot(i.$slots,"gantt-left-head",{},()=>[c[0]||(c[0]=e.createTextVNode(" Name "))])],4),e.createElementVNode("div",ee,[e.createElementVNode("div",{style:e.normalizeStyle({transform:`translateY(-${a.scrolledY}px)`})},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(e.unref(r),(o,u)=>(e.openBlock(),e.createElementBlock("div",{class:"w-full border-b px-2 whitespace-nowrap overflow-hidden text-ellipsis",style:e.normalizeStyle({height:`${e.unref(l)}px`,lineHeight:`${e.unref(l)}px`}),key:u},[e.renderSlot(i.$slots,"gantt-left-row",{row:o},()=>[e.createTextVNode(e.toDisplayString(o.name),1)])],4))),128))],4)])]))}}),ne=e.defineComponent({__name:"VerticalDivider",setup(n){const l=M(),{colWidth:t}=S(),r=e.computed(()=>{const a=[];for(let i=0;i(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(r.value,c=>(e.openBlock(),e.createElementBlock("div",{class:"w-[1px] border-r absolute top-0 bottom-0",key:c,style:e.normalizeStyle({left:`${(c+1)*e.unref(t)}px`})},null,4))),128))}});function G(){const{colWidth:n,startDate:l,cellUnit:t}=S();return{time2position:(i,c)=>{if(t.value==="day"){let o=oe(l.value,i);return o>0?o=c?o-1:o:o=c?o+1:o,Math.ceil(o*n.value)}else{const o=c?x(i).diff(l.value,"month",!0):x(i).add(1,"day").diff(l.value,"month",!0);return Math.ceil(o*n.value)}},position2time:(i,c)=>{if(t.value==="day"){let o=Math.floor(i/n.value);return c||(o=o-1),le(l.value,o)}else{const o=i/n.value,u=Math.floor(o),y=o-u;let w=x(l.value).add(u,"month");const h=w.daysInMonth(),k=Math.round(y*h);return w=w.add(k,"day"),c||(w=w.subtract(1,"day")),w.format("YYYY-MM-DD")}}}}function oe(n,l){let t=x(n),r=x(l),a=!1;t.isAfter(r)&&(a=!0,t=x(l),r=x(n));let i=0;for(;t.isBefore(r)||t.isSame(r,"day");){const c=t.day();c!==0&&c!==6&&i++,t=t.add(1,"day")}return a?-i:i}function le(n,l){let t=x(n),r=0;if(l>=0)for(;rl;){t=t.subtract(1,"day");const a=t.day();a!==0&&a!==6&&r--}return t.format("YYYY-MM-DD")}function re(){const n=e.inject(O);if(!n)throw Error("Failed to inject emitRowEvent!");return n}const U=[{background:"#d4b9b0",color:"#4a2d2b"},{background:"#b8a59d",color:"#3b2a27"},{background:"#9ea19e",color:"#2e3532"},{background:"#c8c1b7",color:"#463f36"},{background:"#c5a59f",color:"#4d3532"},{background:"#8c9d9b",color:"#2d3735"},{background:"#d2b4a1",color:"#4b362d"},{background:"#afa294",color:"#3c332d"},{background:"#bdbdb6",color:"#4a4a44"},{background:"#938b80",color:"#2f2d28"},{background:"#d5cdc5",color:"#504944"},{background:"#b5aba3",color:"#3b332d"},{background:"#c6bab4",color:"#463f39"},{background:"#bcae9e",color:"#3f332a"},{background:"#a0938b",color:"#322d28"},{background:"#d9d2ca",color:"#544e47"},{background:"#d0c6c0",color:"#4e4741"},{background:"#a59a8f",color:"#352e28"},{background:"#c3b7ae",color:"#4c423b"},{background:"#bfb0a4",color:"#463b34"}];function ae(){const n=Math.floor(Math.random()*U.length);return U[n]}function ie(n){const l=n.day();return l!==0&&l!==6}function A(n){return x(n).startOf("month").format("YYYY-MM-DD")}function D(n,l){const t=e.ref(0);return function(...r){const a=Date.now();a-t.value>=l&&(n(...r),t.value=a)}}function ce(){const n=e.inject(F);if(!n)throw Error("Failed to inject emitBarEvent!");return n}const se=["id"],de={class:"text-sm px-2"},z=16.666,fe=e.defineComponent({__name:"GanttBar",props:{project:{},rowIndex:{},index:{}},emits:["dragging-start","dragging-end","dragging"],setup(n,{emit:l}){const t=n,r=l,a=S(),i=ce(),{startDate:c,endDate:o,colWidth:u,rowHeight:y,cellUnit:w}=a,{project:h}=e.toRefs(t),k=e.ref(0),b=e.ref(0),d=e.ref(""),p=e.ref(""),s=e.ref(!1),g=e.ref(0),{time2position:E,position2time:$}=G();e.watch([h,c,o,u],()=>{k.value=E(h.value.startDate,!0),b.value=E(h.value.endDate,!1)},{deep:!0,immediate:!0}),e.onMounted(()=>{if(!h.value.background||!h.value.color){const m=ae();d.value=m.background,p.value=m.color}});const _=m=>{if(m.preventDefault(),m.type==="mousedown"){g.value=m.clientX;let f;const C=m.target.className;C.includes("bar-handle-right")?f=Ce:C.includes("bar-handle-left")?f=De:f=_e,window.addEventListener("mousemove",f),window.addEventListener("mouseup",V=>{window.removeEventListener("mousemove",f),w.value==="day"&&(k.value=P(k.value),b.value=P(b.value));const L=q($(k.value,!0)),N=q($(b.value,!1));s.value&&i("dragend-bar",V,{...h.value,startDate:L,endDate:N},t.index,t.rowIndex),s.value=!1,r("dragging-end")},{once:!0})}},$e=m=>{m.stopPropagation(),i("click-bar",m,{...h.value},t.index,t.rowIndex)},_e=D(m=>{s.value||(s.value=!0,r("dragging-start"));const f=m.clientX-g.value;Y(f)&&(k.value+=f,b.value+=f,r("dragging",{xStart:k.value,xEnd:b.value})),g.value=m.clientX},z),De=D(m=>{s.value||(s.value=!0,r("dragging-start"));const f=m.clientX-g.value;Y(f)&&b.value-(k.value+f)>u.value&&(k.value+=f,r("dragging",{xStart:k.value,xEnd:b.value})),g.value=m.clientX},z),Ce=D(m=>{s.value||(s.value=!0,r("dragging-start"));const f=m.clientX-g.value;Y(f)&&b.value+f-k.value>u.value&&(b.value+=f,r("dragging",{xStart:k.value,xEnd:b.value})),g.value=m.clientX},z),Y=m=>{var J;let f=!0;const C=document.getElementById(`gantt-row-${t.rowIndex}-bar-${t.index}`),V=C.offsetLeft,L=V+C.offsetWidth,N=V+m,v=L+m,T=(J=document.getElementById(`gantt-row-${t.rowIndex}`))==null?void 0:J.children;if(T)for(let W=0;WX||v>X&&NMath.round(m/u.value)*u.value,q=m=>{let f=x(m);for(;f.day()===0||f.day()===6;)f=f.add(1,"day");return f.format("YYYY-MM-DD")};return(m,f)=>e.unref(h).startDate&&e.unref(h).endDate&&e.unref(h).endDate>e.unref(c)&&e.unref(h).startDate[e.createElementVNode("span",de,e.toDisplayString(e.unref(h).name),1)]),f[0]||(f[0]=e.createElementVNode("div",{class:"bar-handle-left absolute left-0 top-0 bottom-0 w-2 bg-white opacity-50 cursor-ew-resize"},null,-1)),f[1]||(f[1]=e.createElementVNode("div",{class:"bar-handle-right absolute right-0 top-0 bottom-0 w-2 bg-white opacity-50 cursor-ew-resize"},null,-1))],44,se)):e.createCommentVNode("",!0)}}),me={key:0,class:"size-full flex"},ue=["id"],ge=e.defineComponent({__name:"GanttRow",props:{gantt:{},index:{}},setup(n){const l=n,t=e.ref(!1),r=e.ref(!1),a=e.ref(0),i=e.ref(0),c=e.computed(()=>w.value?Math.floor(a.value/w.value):0),o=e.computed(()=>w.value?Math.floor(i.value/w.value):0),{position2time:u}=G(),{rowHeight:y,colWidth:w,rowActiveBackgroundColor:h,rowActiveBorderColor:k}=S(),b=M(),d=re(),p=s=>{s.stopPropagation();const g=u(s.offsetX,!0);d(s,l.gantt,g,l.index)};return(s,g)=>(e.openBlock(),e.createElementBlock("div",{class:"w-full relative transition-colors duration-500",style:e.normalizeStyle({height:`${e.unref(y)}px`,backgroundColor:r.value?e.unref(h):"unset"}),onClick:p,onMouseenter:g[3]||(g[3]=E=>r.value=!0),onMouseleave:g[4]||(g[4]=E=>r.value=!1)},[e.createVNode(e.Transition,null,{default:e.withCtx(()=>[t.value?(e.openBlock(),e.createElementBlock("div",me,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(e.unref(b),(E,$)=>(e.openBlock(),e.createElementBlock("div",{key:`${$}-${E.toString()}`,class:"pointer-events-none h-full flex-shrink-0 border-l-2 transition-colors duration-500",style:e.normalizeStyle({width:`${e.unref(w)}px`,backgroundColor:$>=c.value&&$<=o.value?e.unref(k):e.unref(h),borderColor:e.unref(k)})},null,4))),128))])):e.createCommentVNode("",!0)]),_:1}),e.createElementVNode("div",{id:`gantt-row-${s.index}`},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(l.gantt.projects,(E,$)=>(e.openBlock(),e.createBlock(fe,{project:E,"row-index":l.index,index:$,key:$,onDraggingStart:g[0]||(g[0]=_=>t.value=!0),onDraggingEnd:g[1]||(g[1]=_=>{t.value=!1,a.value=0,i.value=0}),onDragging:g[2]||(g[2]=_=>{a.value=_.xStart,i.value=_.xEnd})},{"gantt-bar-content":e.withCtx(({project:_})=>[e.renderSlot(s.$slots,"gantt-bar-content",{project:_})]),_:2},1032,["project","row-index","index"]))),128))],8,ue)],36))}}),pe=e.defineComponent({__name:"index",props:{scrolledY:{}},setup(n){const{data:l,cellUnit:t}=S(),r=n;return(a,i)=>(e.openBlock(),e.createElementBlock("div",{class:"w-full",style:e.normalizeStyle({transform:`translateY(-${r.scrolledY}px)`})},[e.unref(t)==="day"?(e.openBlock(),e.createBlock(ne,{key:0})):e.createCommentVNode("",!0),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(e.unref(l),(c,o)=>(e.openBlock(),e.createBlock(ge,{key:o,index:o,gantt:c},{"gantt-bar-content":e.withCtx(({project:u})=>[e.renderSlot(a.$slots,"gantt-bar-content",{project:u})]),_:2},1032,["index","gantt"]))),128))],4))}}),he=16.666,we=e.defineComponent({__name:"VerticalScrollBar",emits:["scroll"],setup(n,{emit:l}){const t=l,{data:r,rowHeight:a,headHeight:i}=S(),c=e.ref(null),o=D(()=>{if(c.value){const u=c.value.scrollTop;t("scroll",u)}},he);return(u,y)=>(e.openBlock(),e.createElementBlock("div",{class:"w-[17px] h-full overflow-y-auto overflow-x-hidden",ref_key:"scrollContainer",ref:c,onScroll:y[0]||(y[0]=(...w)=>e.unref(o)&&e.unref(o)(...w))},[e.createElementVNode("div",{style:e.normalizeStyle({height:`${e.unref(r).length*e.unref(a)+e.unref(i)}px`})},null,4)],544))}}),ke=16.666,be=e.defineComponent({__name:"HorizontalScrollBar",props:{leftWidth:{}},emits:["scroll"],setup(n,{emit:l}){const t=n,r=l,a=M(),{colWidth:i}=S(),c=e.ref(null),o=D(()=>{if(c.value){const u=c.value.scrollLeft;r("scroll",u)}},ke);return(u,y)=>(e.openBlock(),e.createElementBlock("div",{class:"h-[17px] w-full overflow-x-auto overflow-y-hidden",ref_key:"scrollContainer",ref:c,onScroll:y[0]||(y[0]=(...w)=>e.unref(o)&&e.unref(o)(...w))},[e.createElementVNode("div",{style:e.normalizeStyle({width:`${e.unref(a).length*e.unref(i)+t.leftWidth-17}px`})},null,4)],544))}}),ye={class:"size-full flex flex-col overflow-hidden bg-white"},xe={class:"flex-1 overflow-hidden flex select-none"},Ee={class:"flex-1 overflow-hidden"},Be=16.666,Se=e.defineComponent({__name:"Gantt",props:{data:{},startDate:{},endDate:{},rowHeight:{default:36},headHeight:{default:32},colWidth:{default:32},rowActiveBackgroundColor:{default:"#cbe3f1"},rowActiveBorderColor:{default:"#a4cee7"},cellUnit:{default:"day"},leftWidth:{default:200}},emits:["dragend-bar","click-bar","click-row"],setup(n,{emit:l}){const t=n,r=l,a=e.ref(t.leftWidth),i=e.ref(!1),c=e.ref(0),o=e.ref(0),u=e.ref(0),y=e.computed(()=>{let d=t.cellUnit==="day"?x(t.startDate):x(A(t.startDate));const p=t.cellUnit==="day"?x(t.endDate):x(A(t.endDate)),s=[];if(t.cellUnit==="day")for(;d.isBefore(p)||d.isSame(p,"day");)ie(d)&&s.push(d),d=d.add(1,"day");else for(;d.isBefore(p)||d.isSame(p,"day");)s.push(d),d=d.add(1,"month");return s}),w=d=>{d.preventDefault(),d.type==="mousedown"&&(u.value=d.clientX,window.addEventListener("mousemove",h),window.addEventListener("mouseup",()=>{window.removeEventListener("mousemove",h),i.value=!1},{once:!0}))},h=D(d=>{i.value||(i.value=!0);const p=d.clientX-u.value;a.value+p>200&&(a.value+=p),u.value=d.clientX},Be),k=(d,p,s,g,E)=>{switch(d){case"dragend-bar":r(d,{e:p,bar:s,barIndex:g,rowIndex:E});break;case"click-bar":r(d,{e:p,bar:s,barIndex:g,rowIndex:E});break}},b=(d,p,s,g)=>{r("click-row",{e:d,row:p,time:s,rowIndex:g})};return e.provide(I,y),e.provide(R,{...e.toRefs(t)}),e.provide(F,k),e.provide(O,b),(d,p)=>(e.openBlock(),e.createElementBlock("div",ye,[e.createElementVNode("div",xe,[e.createElementVNode("div",{class:"h-full overflow-hidden",style:e.normalizeStyle({width:`${a.value}px`})},[e.createVNode(te,{"scrolled-y":c.value},{"gantt-left-head":e.withCtx(()=>[e.renderSlot(d.$slots,"gantt-left-head")]),"gantt-left-row":e.withCtx(({row:s})=>[e.renderSlot(d.$slots,"gantt-left-row",{row:s})]),_:3},8,["scrolled-y"])],4),e.createElementVNode("div",{class:"w-[1px] h-full border-r relative overflow-visible cursor-ew-resize",onMousedown:w},p[2]||(p[2]=[e.createElementVNode("div",{class:"absolute -left-3 top-0 -right-3 bottom-0"},null,-1)]),32),e.createElementVNode("div",Ee,[e.createElementVNode("div",{class:"w-fit h-full relative overflow-hidden",style:e.normalizeStyle({transform:`translateX(-${o.value}px)`})},[e.createVNode(Q,null,{"gantt-head-cell":e.withCtx(({cell:s})=>[e.renderSlot(d.$slots,"gantt-head-cell",{cell:s})]),_:3}),e.createVNode(pe,{"scrolled-y":c.value},{"gantt-bar-content":e.withCtx(({project:s})=>[e.renderSlot(d.$slots,"gantt-bar-content",{project:s})]),_:3},8,["scrolled-y"])],4)]),e.createVNode(we,{onScroll:p[0]||(p[0]=s=>c.value=s)})]),e.createVNode(be,{"left-width":a.value,onScroll:p[1]||(p[1]=s=>o.value=s)},null,8,["left-width"])]))}}),j={install(n){n.component("VueGantt",Se)}};B.default=j,B.vueGantt=j,Object.defineProperties(B,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});