var Gantt=function(){"use strict";const t="year",e="month",s="day",i="hour",n="minute",a="second",o="millisecond";var r={parse(t,e="-",s=/[.:]/){if(t instanceof Date)return t;if("string"==typeof t){let i,n;const a=t.split(" ");i=a[0].split(e).map((t=>parseInt(t,10))),n=a[1]&&a[1].split(s),i[1]=i[1]-1;let o=i;return n&&n.length&&(4==n.length&&(n[3]="0."+n[3],n[3]=1e3*parseFloat(n[3])),o=o.concat(n)),new Date(...o)}},to_string(t,e=!1){if(!(t instanceof Date))throw new TypeError("Invalid argument type");const s=this.get_date_values(t).map(((t,e)=>(1===e&&(t+=1),h(t+"",6===e?3:2,"0")))),i=`${s[0]}-${s[1]}-${s[2]}`,n=`${s[3]}:${s[4]}:${s[5]}.${s[6]}`;return i+(e?" "+n:"")},format(t,e="YYYY-MM-DD HH:mm:ss.SSS",s="ko"){const i=new Intl.DateTimeFormat(s,{month:"long"}).format(t),n=i.charAt(0).toUpperCase()+i.slice(1),a=this.get_date_values(t).map((t=>h(t,2,0))),o={YYYY:a[0],MM:h(+a[1]+1,2,0),DD:a[2],HH:a[3],mm:a[4],ss:a[5],SSS:a[6],D:a[2],MMMM:n,MMM:n};let r=e;const d=[];return Object.keys(o).sort(((t,e)=>e.length-t.length)).forEach((t=>{r.includes(t)&&(r=r.replace(t,`$${d.length}`),d.push(o[t]))})),d.forEach(((t,e)=>{r=r.replace(`$${e}`,t)})),r},diff(t,e,i=s){let n,a,o,r,h,d,l;return n=t-e,a=n/1e3,r=a/60,o=r/60,h=o/24,d=h/30,l=d/12,i.endsWith("s")||(i+="s"),Math.floor({milliseconds:n,seconds:a,minutes:r,hours:o,days:h,months:d,years:l}[i])},today(){const t=this.get_date_values(new Date).slice(0,3);return new Date(...t)},now:()=>new Date,add(r,h,d){h=parseInt(h,10);const l=[r.getFullYear()+(d===t?h:0),r.getMonth()+(d===e?h:0),r.getDate()+(d===s?h:0),r.getHours()+(d===i?h:0),r.getMinutes()+(d===n?h:0),r.getSeconds()+(d===a?h:0),r.getMilliseconds()+(d===o?h:0)];return new Date(...l)},start_of(r,h){const d={[t]:6,[e]:5,[s]:4,[i]:3,[n]:2,[a]:1,[o]:0};function l(t){return d[t]<=d[h]}const p=[r.getFullYear(),l(t)?0:r.getMonth(),l(e)?1:r.getDate(),l(s)?0:r.getHours(),l(i)?0:r.getMinutes(),l(n)?0:r.getSeconds(),l(a)?0:r.getMilliseconds()];return new Date(...p)},clone(t){return new Date(...this.get_date_values(t))},get_date_values:t=>[t.getFullYear(),t.getMonth(),t.getDate(),t.getHours(),t.getMinutes(),t.getSeconds(),t.getMilliseconds()],get_days_in_month(t){const e=[31,28,31,30,31,30,31,31,30,31,30,31],s=t.getMonth();if(1!==s)return e[s];const i=t.getFullYear();return i%4==0&&i%100!=0||i%400==0?29:28}};function h(t,e,s){return t+="",e>>=0,s=String(void 0!==s?s:" "),t.length>e?String(t):((e-=t.length)>s.length&&(s+=s.repeat(e/s.length)),s.slice(0,e)+String(t))}function d(t,e){return"string"==typeof t?(e||document).querySelector(t):t||null}function l(t,e){const s=document.createElementNS("http://www.w3.org/2000/svg",t);for(let t in e)if("append_to"===t){e.append_to.appendChild(s)}else"innerHTML"===t?s.innerHTML=e.innerHTML:s.setAttribute(t,e[t]);return s}function p(t,e,s,i){const n=function(t,e,s,i,n="0.4s",a="0.1s"){const o=t.querySelector("animate");if(o)return d.attr(o,{attributeName:e,from:s,to:i,dur:n,begin:"click + "+a}),t;const r=l("animate",{attributeName:e,from:s,to:i,dur:n,begin:a,calcMode:"spline",values:s+";"+i,keyTimes:"0; 1",keySplines:_("ease-out")});return t.appendChild(r),t}(t,e,s,i);if(n===t){const t=document.createEvent("HTMLEvents");t.initEvent("click",!0,!0),t.eventName="click",n.dispatchEvent(t)}}function _(t){return{ease:".25 .1 .25 1",linear:"0 0 1 1","ease-in":".42 0 1 1","ease-out":"0 0 .58 1","ease-in-out":".42 0 .58 1"}[t]}d.on=(t,e,s,i)=>{i?d.delegate(t,e,s,i):(i=s,d.bind(t,e,i))},d.off=(t,e,s)=>{t.removeEventListener(e,s)},d.bind=(t,e,s)=>{e.split(/\s+/).forEach((function(e){t.addEventListener(e,s)}))},d.delegate=(t,e,s,i)=>{t.addEventListener(e,(function(t){const e=t.target.closest(s);e&&(t.delegatedTarget=e,i.call(this,t,e))}))},d.closest=(t,e)=>e?e.matches(t)?e:d.closest(t,e.parentNode):null,d.attr=(t,e,s)=>{if(!s&&"string"==typeof e)return t.getAttribute(e);if("object"!=typeof e)t.setAttribute(e,s);else for(let s in e)d.attr(t,s,e[s])},d.style=(t,e,s)=>{if(!s&&"string"==typeof e)return t.getAttribute(e);if("object"!=typeof e)t.style[e]=s;else for(let s in e)d.style(t,s,e[s])};class g{constructor(t,e){this.set_defaults(t,e),this.prepare(),this.draw(),this.bind()}set_defaults(t,e){this.action_completed=!1,this.gantt=t,this.task=e}prepare(){this.prepare_values(),this.prepare_helpers()}prepare_values(){this.invalid=this.task.invalid,this.height=this.gantt.options.bar_height,this.x=this.compute_x(),this.y=this.compute_y(),this.corner_radius=this.gantt.options.bar_corner_radius,this.duration=r.diff(this.task._end,this.task._start,"hour")/this.gantt.options.step,this.width=this.gantt.options.column_width*this.duration,this.progress_width=this.gantt.options.column_width*this.duration*(this.task.progress/100)||0,this.group=l("g",{class:"bar-wrapper "+(this.task.custom_class||""),"data-id":this.task.id}),this.bar_group=l("g",{class:"bar-group",append_to:this.group}),this.handle_group=l("g",{class:"handle-group",append_to:this.group})}prepare_helpers(){SVGElement.prototype.getX=function(){return+this.getAttribute("x")},SVGElement.prototype.getY=function(){return+this.getAttribute("y")},SVGElement.prototype.getWidth=function(){return+this.getAttribute("width")},SVGElement.prototype.getHeight=function(){return+this.getAttribute("height")},SVGElement.prototype.getEndX=function(){return this.getX()+this.getWidth()}}draw(){this.draw_bar(),this.draw_progress_bar(),this.draw_label(),this.draw_resize_handles()}draw_bar(){this.$bar=l("rect",{x:this.x,y:this.y,width:this.width,height:this.height,rx:this.corner_radius,ry:this.corner_radius,class:"bar",append_to:this.bar_group}),p(this.$bar,"width",0,this.width),this.invalid&&this.$bar.classList.add("bar-invalid")}draw_progress_bar(){this.invalid||(this.$bar_progress=l("rect",{x:this.x,y:this.y,width:this.progress_width,height:this.height,rx:this.corner_radius,ry:this.corner_radius,class:"bar-progress",append_to:this.bar_group}),p(this.$bar_progress,"width",0,this.progress_width))}draw_label(){l("text",{x:this.x+this.width/2,y:this.y+this.height/2,innerHTML:this.task.name,class:"bar-label",append_to:this.bar_group}),requestAnimationFrame((()=>this.update_label_position()))}draw_resize_handles(){if(this.invalid)return;const t=this.$bar;l("rect",{x:t.getX()+t.getWidth()-9,y:t.getY()+1,width:8,height:this.height-2,rx:this.corner_radius,ry:this.corner_radius,class:"handle right",append_to:this.handle_group}),l("rect",{x:t.getX()+1,y:t.getY()+1,width:8,height:this.height-2,rx:this.corner_radius,ry:this.corner_radius,class:"handle left",append_to:this.handle_group}),this.task.progress&&this.task.progress<100&&(this.$handle_progress=l("polygon",{points:this.get_progress_polygon_points().join(","),class:"handle progress",append_to:this.handle_group}))}get_progress_polygon_points(){const t=this.$bar_progress;return[t.getEndX()-5,t.getY()+t.getHeight(),t.getEndX()+5,t.getY()+t.getHeight(),t.getEndX(),t.getY()+t.getHeight()-8.66]}bind(){this.invalid||this.setup_click_event()}setup_click_event(){d.on(this.group,"focus "+this.gantt.options.popup_trigger,(t=>{this.action_completed||(this.show_popup(),this.gantt.unselect_all(),this.group.classList.add("active"))})),d.on(this.group,"dblclick",(t=>{this.action_completed||this.gantt.trigger_event("click",[this.task])}))}show_popup(){if(this.gantt.bar_being_dragged)return;const t=r.format(this.task._start,"MMM D",this.gantt.options.language)+" - "+r.format(r.add(this.task._end,-1,"second"),"MMM D",this.gantt.options.language);this.gantt.show_popup({target_element:this.$bar,title:this.task.name,subtitle:t,task:this.task}),this.gantt.handle_selected(this.task)}update_bar_position({x:t=null,width:e=null}){const s=this.$bar;t&&this.update_attr(s,"x",t),e&&e>=this.gantt.options.column_width&&this.update_attr(s,"width",e),this.update_label_position(),this.update_handle_position(),this.update_progressbar_position(),this.update_arrow_position()}date_changed(){let t=!1;const{new_start_date:e,new_end_date:s}=this.compute_start_end_date();Number(this.task._start)!==Number(e)&&(t=!0,this.task._start=e),Number(this.task._end)!==Number(s)&&(t=!0,this.task._end=s),t&&this.gantt.trigger_event("date_change",[this.task,e,r.add(s,-1,"second")])}progress_changed(){const t=this.compute_progress();this.task.progress=t,this.gantt.trigger_event("progress_change",[this.task,t])}set_action_completed(){this.action_completed=!0,setTimeout((()=>this.action_completed=!1),1e3)}compute_start_end_date(){const t=this.$bar,e=t.getX()/this.gantt.options.column_width,s=r.add(this.gantt.gantt_start,e*this.gantt.options.step,"hour"),i=t.getWidth()/this.gantt.options.column_width;return{new_start_date:s,new_end_date:r.add(s,i*this.gantt.options.step,"hour")}}compute_progress(){const t=this.$bar_progress.getWidth()/this.$bar.getWidth()*100;return parseInt(t,10)}compute_x(){const{step:t,column_width:e}=this.gantt.options,s=this.task._start,i=this.gantt.gantt_start;let n=r.diff(s,i,"hour")/t*e;if(this.gantt.view_is("Month")){n=r.diff(s,i,"day")*e/30}return n}compute_y(){return this.gantt.options.header_height+this.gantt.options.padding+this.task._index*(this.height+this.gantt.options.padding)}get_snap_position(t){let e,s,i=t;return this.gantt.view_is("Week")?(e=t%(this.gantt.options.column_width/7),s=i-e+(et.getWidth()?(e.classList.add("big"),e.setAttribute("x",t.getX()+t.getWidth()+5)):(e.classList.remove("big"),e.setAttribute("x",t.getX()+t.getWidth()/2))}update_handle_position(){if(this.invalid)return;const t=this.$bar;this.handle_group.querySelector(".handle.left").setAttribute("x",t.getX()+1),this.handle_group.querySelector(".handle.right").setAttribute("x",t.getEndX()-9);const e=this.group.querySelector(".handle.progress");e&&e.setAttribute("points",this.get_progress_polygon_points())}update_arrow_position(){this.arrows=this.arrows||[];for(let t of this.arrows)t.update()}}class c{constructor(t,e,s){this.gantt=t,this.from_task=e,this.to_task=s,this.calculate_path(),this.draw()}calculate_path(){let t=this.from_task.$bar.getX()+this.from_task.$bar.getWidth()/2;const e=()=>this.to_task.$bar.getX()this.from_task.$bar.getX()+this.gantt.options.padding;for(;e();)t-=10;const s=this.gantt.options.header_height+this.gantt.options.bar_height+(this.gantt.options.padding+this.gantt.options.bar_height)*this.from_task.task._index+this.gantt.options.padding,i=this.to_task.$bar.getX()-this.gantt.options.padding/2,n=this.gantt.options.header_height+this.gantt.options.bar_height/2+(this.gantt.options.padding+this.gantt.options.bar_height)*this.to_task.task._index+this.gantt.options.padding,a=this.from_task.task._index>this.to_task.task._index,o=this.gantt.options.arrow_curve,r=a?1:0,h=a?-o:o,d=a?n+this.gantt.options.arrow_curve:n-this.gantt.options.arrow_curve;if(this.path=`\n M ${t} ${s}\n V ${d}\n a ${o} ${o} 0 0 ${r} ${o} ${h}\n L ${i} ${n}\n m -5 -5\n l 5 5\n l -5 5`,this.to_task.$bar.getX()\n
\n
\n ',this.hide(),this.title=this.parent.querySelector(".title"),this.subtitle=this.parent.querySelector(".subtitle"),this.pointer=this.parent.querySelector(".pointer")}show(t){if(!t.target_element)throw new Error("target_element is required to show popup");t.position||(t.position="left");const e=t.target_element;if(this.custom_html){let e=this.custom_html(t.task);e+='
',this.parent.innerHTML=e,this.pointer=this.parent.querySelector(".pointer")}else this.title.innerHTML=t.title,this.subtitle.innerHTML=t.subtitle,this.parent.style.width=this.parent.clientWidth+"px";let s;e instanceof HTMLElement?s=e.getBoundingClientRect():e instanceof SVGElement&&(s=t.target_element.getBBox()),"left"===t.position&&(this.parent.style.left=s.x+(s.width+10)+"px",this.parent.style.top=s.y+"px",this.pointer.style.transform="rotateZ(90deg)",this.pointer.style.left="-7px",this.pointer.style.top="2px"),this.parent.style.opacity=1}hide(){this.parent.style.opacity=0,this.parent.style.left=0}}class m{dragStartY=0;constructor(t,e){console.log("[Table :: constructor]"),console.table(t),console.table(e),this.set_defaults(t,e)}set_defaults(t,e){console.log("[Table :: set_defaults]"),console.table(t),console.table(e),this.gantt=t,this.columns=e}draw_table_header(){console.log("[Table :: draw_table_header]");const t=document.createElement("thead"),e=document.createElement("tr");return this.columns.forEach((t=>{const s=document.createElement("th");s.textContent=t.title,e.appendChild(s)})),t.appendChild(e),t.classList.add("table-header"),d.style(e,"height",this.gantt.options.header_height+9+"px"),t}get_parentNode(t,e){return console.log("[Table :: get_parentNode]"),console.table(t),console.table(e),e.tagName===t.toUpperCase()?e:this.get_parentNode(t,e.parentNode)}draw_table_body(t){console.log("[Table :: draw_table_body]"),console.table(t),this.tasks=this.gantt.setGroupPosition(t);const e=document.createElement("tbody");return e.classList.add("table-body"),this.make_table_row().forEach((t=>e.append(t))),e.addEventListener("mousedown",(t=>{this.get_parentNode("td",t.target).classList.contains("draggable-item")&&this.bind_draggable_event(e)})),e}isRowLine(t){if(console.log("[Table :: isRowLine]"),console.table(t),t<=2)return!1;return!this.tasks.find((e=>e.id===`${t}`)).groupPosition.includes("last")}make_table_row(){return console.log("[Table :: make_table_row]"),this.tasks.map(((t,e)=>{const s=t.level-1,i=document.createElement("tr");return i.setAttribute("draggable","true"),i.setAttribute("data-id",t.id),d.style(i,{height:this.gantt.options.bar_height+this.gantt.options.padding+"px"}),1===s&&t.groupPosition.includes("last")&&i.classList.add("root-last"),this.columns.forEach((e=>{const n=document.createElement("td"),{data:a,render:o}=e;if("drag"===a)return n.innerHTML='',n.className="draggable-item",void i.append(n);if("wbs"===a&&(n.className=a),"name"===a&&t.level>1){n.setAttribute("rel",t.type),n.className=`work-name indent-${s} indent-${s}-${t.groupPosition[0]}`,t.groupPosition[1]&&n.classList.add(`indent-${s}-${t.groupPosition[1]}`),"default"!==t.type&&n.classList.add(t.closed?"closed":"opened");for(let e=0;e1&&i.classList.add("row-line"),n.append(i);break}n.append(i)}}if(o){const e=o(t[a],t);n.append(e)}else{const e=document.createTextNode(t[a]??"");n.append(e)}i.append(n)})),i.addEventListener("mousedown",(t=>{this.get_parentNode("td",t.target).classList.contains("draggable-item")&&(i.addEventListener("dragstart",(t=>{t.target.classList.add("dragging")})),i.addEventListener("dragend",(t=>{t.target.classList.remove("dragging")})))})),i}))}get_drag_after_element(t,e){console.log("[Table :: get_drag_after_element]"),console.table(t),console.table(e);return[...t.querySelectorAll("tr:not(.dragging)")].reduce(((t,s)=>{const i=s.getBoundingClientRect(),n=e-i.top-i.height/2;return n<0&&n>t.offset?{offset:n,element:s}:t}),{offset:Number.NEGATIVE_INFINITY}).element}find_task_item(t){return console.log("[Table :: find_task_item]"),console.table(t),this.tasks.find((e=>e.id===t))}bind_draggable_event(t){console.log("[Table :: bind_draggable_event]"),console.table(t),t.addEventListener("dragover",(e=>{e.preventDefault(),this.dragStartY||(this.dragStartY=e.clientY),this.draggableEl=document.querySelector(".dragging"),this.afterElement=this.get_drag_after_element(t,e.clientY),t.insertBefore(this.draggableEl,this.afterElement)})),t.addEventListener("drop",(async t=>{t.preventDefault();const e=this.find_task_item(this.get_parentNode("tr",t.target).getAttribute("data-id")),s=this.find_task_item(this.draggableEl.getAttribute("data-id")),i=this.find_task_item(this.afterElement.getAttribute("data-id")),n={c_id:s.id,ref:i.parentId,c_position:t.clientY>this.dragStartY?i.position-1:i.position,level:i.level,p_position:s.position,p_parentId:s.parentId};if("default"!==e.type){const t=this.tasks.filter((t=>t.parentId===Number(e.id))).length;n.ref=e.id,n.level=e.level+1,n.c_position=t||0}this.dragStartY=0,this.gantt.draggble_rerender(n),this.gantt.trigger_event("drag_row",[n])}))}}class w{constructor(t){this.draw_split_bar(t)}draw_split_bar(t){const e=document.createElement("div");e.classList.add("split-bar");let s=0;const i=function(i){const n=e.previousElementSibling,a=e.nextSibling,o=i.clientX-s,r=Math.max(0,Math.min(e.offsetLeft+o,t.clientWidth))/t.clientWidth*100;d.style(e,{left:`${r}%`}),d.style(n,{"flex-basis":`${r}%`}),d.style(a,{"flex-basis":100-r+"%"}),d.style(n,{"overflow-x":"hidden"}),d.style(a,{"overflow-x":"hidden"}),s=i.clientX},n=function(){const t=e.previousElementSibling,s=e.nextSibling;document.removeEventListener("mousemove",i),document.removeEventListener("mouseup",n),d.style(t,{"overflow-x":"auto"}),d.style(s,{"overflow-x":"auto"})};e.addEventListener("mousedown",(function(t){s=t.clientX,document.addEventListener("mousemove",i),document.addEventListener("mouseup",n)})),t.prepend(e)}}const f={QUARTER_DAY:"Quarter Day",HALF_DAY:"Half Day",DAY:"Day",WEEK:"Week",MONTH:"Month",YEAR:"Year"};class b{constructor(t,e,s,i){this.originTasks=e,this.setup_options(s),this.setup_tasks(e),this.setup_wrapper(t),this.change_view_mode(),this.setup_split_bar(),this.setup_table(i),this.bind_events()}setup_wrapper(t){let e,s;if("string"==typeof t&&(t=document.querySelector(t)),t instanceof HTMLElement)s=t,e=t.querySelector("svg");else{if(!(t instanceof SVGElement))throw new TypeError("Frappé Gantt only supports usage of a string CSS selector, HTML DOM element or SVG DOM element for the 'element' parameter");e=t}e?(this.$svg=e,this.$svg.classList.add("gantt")):this.$svg=l("svg",{append_to:s,class:"gantt"}),this.$wrapper=document.createElement("div"),this.$wrapper.classList.add("wrapper"),this.$container=document.createElement("div"),this.$container.classList.add("gantt-container");const i=this.$svg.parentElement;t.appendChild(this.setup_mode_handler()),i.appendChild(this.$wrapper),this.$wrapper.appendChild(this.$container),this.$container.appendChild(this.$svg),this.popup_wrapper=document.createElement("div"),this.popup_wrapper.classList.add("popup-wrapper"),this.$container.appendChild(this.popup_wrapper)}setup_mode_handler(){const t=document.createElement("div"),e=document.createElement("button"),s=document.createElement("div");return t.className="mt well well-sm clearfix",e.className="btn btn-default btn-sm mr-xs",e.innerText="Excel",d.style(s,{float:"right"}),Object.keys(f).forEach((t=>{const e=document.createElement("button");e.className="btn btn-default btn-sm mr-xs "+(f[t]===this.options.view_mode?"active":""),e.innerText=f[t],e.addEventListener("click",(e=>{e.target.classList.add("active"),e.target.parentNode.childNodes.forEach((t=>t.classList.remove("active"))),this.change_view_mode(f[t])})),s.appendChild(e)})),t.append(e),t.append(s),t}setup_options(t){const e={header_height:50,column_width:30,step:24,view_modes:[...Object.values(f)],bar_height:20,bar_corner_radius:3,arrow_curve:5,padding:18,view_mode:"Day",date_format:"YYYY-MM-DD",popup_trigger:"click",custom_popup_html:null,language:"ko"};this.options=Object.assign({},e,t)}setup_tasks(t){this.tasks=this.sort_tasks(t).map(((t,e)=>{if(t._start=r.parse(t.start),t._end=r.parse(t.end),r.diff(t._end,t._start,"year")>10&&(t.end=null),t._index=e,!t.start&&!t.end){const e=r.today();t._start=e,t._end=r.add(e,2,"day")}!t.start&&t.end&&(t._start=r.add(t._end,-2,"day")),t.start&&!t.end&&(t._end=r.add(t._start,2,"day"));if(r.get_date_values(t._end).slice(3).every((t=>0===t))&&(t._end=r.add(t._end,24,"hour")),t.start&&t.end||(t.invalid=!0),"string"==typeof t.dependencies||!t.dependencies){let e=[];t.dependencies&&(e=t.dependencies.split(",").map((t=>t.trim())).filter((t=>t))),t.dependencies=e}return t.id||(t.id=function(t){return t.name+"_"+Math.random().toString(36).slice(2,12)}(t)),t})),this.setup_dependencies()}setup_dependencies(){this.dependency_map={};for(let t of this.tasks)for(let e of t.dependencies)this.dependency_map[e]=this.dependency_map[e]||[],this.dependency_map[e].push(t.id)}refresh(t){this.setup_tasks(t),this.change_view_mode(),this.rerender_table(),this.originTasks=t}change_view_mode(t=this.options.view_mode){this.update_view_scale(t),this.setup_dates(),this.render(),this.trigger_event("view_change",[t])}update_view_scale(t){this.options.view_mode=t,t===f.DAY?(this.options.step=24,this.options.column_width=38):t===f.HALF_DAY?(this.options.step=12,this.options.column_width=38):t===f.QUARTER_DAY?(this.options.step=6,this.options.column_width=38):t===f.WEEK?(this.options.step=168,this.options.column_width=140):t===f.MONTH?(this.options.step=720,this.options.column_width=120):t===f.YEAR&&(this.options.step=8760,this.options.column_width=120)}setup_dates(){this.setup_gantt_dates(),this.setup_date_values()}setup_gantt_dates(){this.gantt_start=this.gantt_end=null;for(let t of this.tasks)(!this.gantt_start||t._startthis.gantt_end)&&(this.gantt_end=t._end);this.gantt_start=r.start_of(this.gantt_start,"day"),this.gantt_end=r.start_of(this.gantt_end,"day"),this.view_is([f.QUARTER_DAY,f.HALF_DAY])?(this.gantt_start=r.add(this.gantt_start,-7,"day"),this.gantt_end=r.add(this.gantt_end,7,"day")):this.view_is(f.MONTH)?(this.gantt_start=r.start_of(this.gantt_start,"year"),this.gantt_end=r.add(this.gantt_end,1,"year")):this.view_is(f.YEAR)?(this.gantt_start=r.add(this.gantt_start,-2,"year"),this.gantt_end=r.add(this.gantt_end,2,"year")):(this.gantt_start=r.add(this.gantt_start,-1,"month"),this.gantt_end=r.add(this.gantt_end,1,"month"))}setup_date_values(){this.dates=[];let t=null;for(;null===t||tthis.bind_table_event(t)))}draggble_rerender(t){this.update_origin_tasks(t),this.render(),this.rerender_table()}sort_tasks(t){const e=[...t],s={};return e.sort(((t,e)=>t.level-e.level||t.position-e.position)).forEach(((t,i)=>{if(2!==t.parentId){s.hasOwnProperty(t.parentId)?s[t.parentId].push(i):s[t.parentId]=[i];const n=e.findIndex((e=>+e.id===t.parentId));e.splice(i,1),e.splice(n+s[t.parentId].length,0,t)}}),[]),e}setGroupPosition(t){return t.reduce(((e,s)=>{const i=t.filter((t=>t.parentId===s.parentId));return s.groupPosition=[],i[0].id===s.id&&s.groupPosition.push("first"),i[i.length-1].id===s.id&&s.groupPosition.push("last"),s.groupPosition.length||s.groupPosition.push("middle"),e.push(s),e}),[])}update_dependecies(t){if(2===t)return[];const e=this.tasks.find((e=>e.id===t)).dependencies;return e.length?[...e,t]:[t]}update_origin_tasks(t){let e=this.tasks.reduce(((e,s)=>{if(s.id===t.c_id){const e=this.update_dependecies(t.ref);s={...s,parentId:Number(t.ref),dependencies:e,position:t.c_position,level:t.level,wbs:e.length?`${e.join("-")}-${t.c_id}`:`${t.c_id}`}}else{if(s.parentId===Number(t.ref)&&t.c_position===t.p_position)return e.push(s),e;s.parentId===Number(t.ref)?s.position=t.c_position>t.p_position?s.positiont.p_position?s.position:s.position>=t.c_position?s.position+1:s.position:s.parentId===t.p_parentId&&(s.position=s.position{if(s.id===e)return delete s.closed,t.splice(s._index,1,s);s.dependencies.includes(e)&&t.splice(s._index,0,s)})):t=this.tasks.reduce(((t,s)=>s.id===e?[...t,{...s,closed:!0}]:s.dependencies.includes(e)?t:[...t,s]),[]),this.setup_tasks(t),this.render(),this.rerender_table()}}make_table(){const t=document.createElement("div"),e=document.createElement("table");t.className="table-container";const s=this.table.draw_table_header(),i=this.table.draw_table_body(this.tasks);e.append(s),e.append(i),i.addEventListener("click",(t=>this.bind_table_event(t))),t.append(e),this.$wrapper.prepend(t)}make_grid(){this.make_grid_background(),this.make_grid_rows(),this.make_grid_ticks(),this.make_grid_highlights()}handle_selected(t){const e=this.$wrapper.querySelectorAll("tr")[t._index+1],s=this.$wrapper.querySelectorAll(".grid-row")[t._index];e.classList.contains("selected")||Array.prototype.forEach.call(this.$wrapper.querySelectorAll(".selected"),(t=>t.classList.remove("selected"))),e?.classList.toggle("selected"),s?.classList.toggle("selected")}make_grid_background(){const t=this.dates.length*this.options.column_width,e=this.options.header_height+this.options.padding+(this.options.bar_height+this.options.padding)*this.tasks.length;l("rect",{x:0,y:0,width:t,height:e,class:"grid-background",append_to:this.layers.grid}),d.attr(this.$svg,{height:e,width:"100%"})}make_grid_rows(){const t=l("g",{append_to:this.layers.grid}),e=this.dates.length*this.options.column_width,s=this.options.bar_height+this.options.padding;let i=this.options.header_height+this.options.padding/2;for(let n of this.tasks)l("rect",{x:0,y:i,width:e,height:s,class:"grid-row",append_to:t}),i+=this.options.bar_height+this.options.padding}make_grid_header(){const t=this.dates.length*this.options.column_width,e=this.options.header_height+10,s=window.scrollY,i=s+this.$wrapper.getBoundingClientRect().top;i<=s&&(this.layers.header.style.transform=`translate(0px, ${Math.floor(window.scrollY-i)}px)`),l("rect",{x:0,y:0,width:t,height:e,class:"grid-header",append_to:this.layers.header})}make_grid_ticks(){let t=0,e=this.options.header_height+this.options.padding/2,s=(this.options.bar_height+this.options.padding)*this.tasks.length;for(let i of this.dates){let n="tick";this.view_is(f.DAY)&&1===i.getDate()&&(n+=" thick"),this.view_is(f.WEEK)&&i.getDate()>=1&&i.getDate()<8&&(n+=" thick"),this.view_is(f.MONTH)&&i.getMonth()%3==0&&(n+=" thick"),l("path",{d:`M ${t} ${e} v ${s}`,class:n,append_to:this.layers.grid}),this.view_is(f.MONTH)?t+=r.get_days_in_month(i)*this.options.column_width/30:t+=this.options.column_width}}make_grid_highlights(){if(this.view_is(f.DAY)){l("rect",{x:r.diff(r.today(),this.gantt_start,"hour")/this.options.step*this.options.column_width,y:0,width:this.options.column_width,height:(this.options.bar_height+this.options.padding)*this.tasks.length+this.options.header_height+this.options.padding/2,class:"today-highlight",append_to:this.layers.grid})}}make_dates(){const t=window.scrollY,e=t+this.$wrapper.getBoundingClientRect().top;e<=t&&(this.layers.date.style.transform=`translate(0px, ${Math.floor(window.scrollY-e)}px)`);for(let t of this.get_dates_to_draw())if(l("text",{x:t.lower_x,y:t.lower_y,innerHTML:t.lower_text,class:"lower-text",append_to:this.layers.date}),t.upper_text){const e=l("text",{x:t.upper_x,y:t.upper_y,innerHTML:t.upper_text,class:"upper-text",append_to:this.layers.date});e.getBBox().x2>this.layers.grid.getBBox().width&&e.remove()}}get_dates_to_draw(){let t=null;return this.dates.map(((e,s)=>{const i=this.get_date_info(e,t,s);return t=e,i}))}get_date_info(t,e,s){e||(e=r.add(t,1,"year"));const i={"Quarter Day_lower":r.format(t,"HH",this.options.language),"Half Day_lower":r.format(t,"HH",this.options.language),Day_lower:t.getDate()!==e.getDate()?r.format(t,"D",this.options.language):"",Week_lower:t.getMonth()!==e.getMonth()?r.format(t,"D MMM",this.options.language):r.format(t,"D",this.options.language),Month_lower:r.format(t,"MMMM",this.options.language),Year_lower:r.format(t,"YYYY",this.options.language),"Quarter Day_upper":t.getDate()!==e.getDate()?r.format(t,"D MMM",this.options.language):"","Half Day_upper":t.getDate()!==e.getDate()?t.getMonth()!==e.getMonth()?r.format(t,"D MMM",this.options.language):r.format(t,"D",this.options.language):"",Day_upper:t.getMonth()!==e.getMonth()?r.format(t,"MMMM",this.options.language):"",Week_upper:t.getMonth()!==e.getMonth()?r.format(t,"MMMM",this.options.language):"",Month_upper:t.getFullYear()!==e.getFullYear()?r.format(t,"YYYY",this.options.language):"",Year_upper:t.getFullYear()!==e.getFullYear()?r.format(t,"YYYY",this.options.language):""},n={x:s*this.options.column_width,lower_y:this.options.header_height,upper_y:this.options.header_height-25},a={"Quarter Day_lower":4*this.options.column_width/2,"Quarter Day_upper":0,"Half Day_lower":2*this.options.column_width/2,"Half Day_upper":0,Day_lower:this.options.column_width/2,Day_upper:30*this.options.column_width/2,Week_lower:0,Week_upper:4*this.options.column_width/2,Month_lower:this.options.column_width/2,Month_upper:12*this.options.column_width/2,Year_lower:this.options.column_width/2,Year_upper:30*this.options.column_width/2};return{upper_text:i[`${this.options.view_mode}_upper`],lower_text:i[`${this.options.view_mode}_lower`],upper_x:n.x+a[`${this.options.view_mode}_upper`],upper_y:n.upper_y,lower_x:n.x+a[`${this.options.view_mode}_lower`],lower_y:n.lower_y}}make_bars(){this.bars=this.tasks.map((t=>{const e=new g(this,t);return this.layers.bar.appendChild(e.group),e}))}make_arrows(){this.arrows=[];for(let t of this.tasks){let e=[];e=t.dependencies.map((e=>{const s=this.get_task(e);if(!s)return;const i=new c(this,this.bars[s._index],this.bars[t._index]);return this.layers.arrow.appendChild(i.element),i})).filter(Boolean),this.arrows=this.arrows.concat(e)}}map_arrows_on_bars(){for(let t of this.bars)t.arrows=this.arrows.filter((e=>e.from_task.task.id===t.task.id||e.to_task.task.id===t.task.id))}set_width(){const t=this.$svg.getBoundingClientRect().width,e=this.$svg.querySelector(".grid .grid-row").getAttribute("width");t{const i=window.scrollY;s||(s=!0,window.requestAnimationFrame((()=>{t<=i?(e.style.top=`${Math.floor(i-t)}px`,this.layers.header.style.transform=`translate(0px, ${Math.floor(i-t)}px)`,this.layers.date.style.transform=`translate(0px, ${Math.floor(i-t)}px)`):(e.style.top="0px",this.layers.header.style.transform="translate(0px, 0px)",this.layers.date.style.transform="translate(0px, 0px)"),s=!1})))}),{passive:!0})}bind_grid_click(){d.on(this.$svg,this.options.popup_trigger,".grid-row, .grid-header",(()=>{this.unselect_all(),this.hide_popup()}))}bind_bar_events(){let t=!1,e=0,s=0,i=!1,n=!1,a=null,o=[];this.bar_being_dragged=null,d.on(this.$svg,"mousedown",".bar-wrapper, .handle",((r,h)=>{console.log("[gantt-0.6.1 :: mousedown]");const l=d.closest(".bar-wrapper",h);h.classList.contains("left")?i=!0:h.classList.contains("right")?n=!0:h.classList.contains("bar-wrapper")&&(t=!0),l.classList.add("active"),e=r.offsetX,s=r.offsetY,a=l.getAttribute("data-id");o=[a].map((t=>this.get_bar(t))),this.bar_being_dragged=a,o.forEach((t=>{const e=t.$bar;e.ox=e.getX(),e.oy=e.getY(),e.owidth=e.getWidth(),e.finaldx=0}))})),d.on(this.$svg,"mousemove",(s=>{if(console.log("[gantt-0.6.1 :: mousemove]"),!(t||i||n))return;const r=s.offsetX-e;s.offsetY,o.forEach((e=>{const s=e.$bar;s.finaldx=this.get_snap_position(r),this.hide_popup(),i?a===e.task.id?e.update_bar_position({x:s.ox+s.finaldx,width:s.owidth-s.finaldx}):e.update_bar_position({x:s.ox+s.finaldx}):n?a===e.task.id&&e.update_bar_position({width:s.owidth+s.finaldx}):t&&e.update_bar_position({x:s.ox+s.finaldx})}))})),document.addEventListener("mouseup",(e=>{(t||i||n)&&o.forEach((t=>t.group.classList.remove("active"))),t=!1,i=!1,n=!1})),d.on(this.$svg,"mouseup",(t=>{this.bar_being_dragged=null,o.forEach((t=>{t.$bar.finaldx&&(t.date_changed(),t.set_action_completed())}))})),this.bind_bar_progress()}bind_bar_progress(){let t=0,e=0,s=null,i=null,n=null,a=null;d.on(this.$svg,"mousedown",".handle.progress",((o,r)=>{s=!0,t=o.offsetX,e=o.offsetY;const h=d.closest(".bar-wrapper",r).getAttribute("data-id");i=this.get_bar(h),n=i.$bar_progress,a=i.$bar,n.finaldx=0,n.owidth=n.getWidth(),n.min_dx=-n.getWidth(),n.max_dx=a.getWidth()-n.getWidth()})),d.on(this.$svg,"mousemove",(e=>{if(!s)return;let a=e.offsetX-t;e.offsetY,a>n.max_dx&&(a=n.max_dx),a{s=!1,n&&n.finaldx&&(i.progress_changed(),i.set_action_completed())}))}get_all_dependent_tasks(t){let e=[],s=[t];for(;s.length;){const t=s.reduce(((t,e)=>t=t.concat(this.dependency_map[e])),[]);e=e.concat(t),s=t.filter((t=>!s.includes(t)))}return e.filter(Boolean)}get_snap_position(t){let e,s,i=t;return this.view_is(f.WEEK)?(e=t%(this.options.column_width/7),s=i-e+(e{t.classList.remove("active")}))}view_is(t){return"string"==typeof t?this.options.view_mode===t:!!Array.isArray(t)&&t.some((t=>this.options.view_mode===t))}get_task(t){return this.tasks.find((e=>e.id===t))}get_bar(t){return this.bars.find((e=>e.task.id===t))}show_popup(t){this.popup||(this.popup=new u(this.popup_wrapper,this.options.custom_popup_html)),this.popup.show(t)}hide_popup(){this.popup&&this.popup.hide()}trigger_event(t,e){this.options["on_"+t]&&this.options["on_"+t].apply(null,e)}get_oldest_starting_date(){return this.tasks.map((t=>t._start)).reduce(((t,e)=>e<=t?e:t))}clear(){this.$svg.innerHTML=""}}return b.VIEW_MODE=f,b}(); //# sourceMappingURL=frappe-gantt.min.js.map