@workiom/frappe-gantt 1.0.19 → 1.0.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,29 +1,54 @@
1
- (function(v,x){typeof exports=="object"&&typeof module<"u"?module.exports=x():typeof define=="function"&&define.amd?define(x):(v=typeof globalThis<"u"?globalThis:v||self,v.Gantt=x())})(this,function(){"use strict";const v="year",x="month",L="day",T="hour",A="minute",Y="second",H="millisecond",c={parse_duration(r){const e=/([0-9]+)(y|m|d|h|min|s|ms)/gm.exec(r);if(e!==null){if(e[2]==="y")return{duration:parseInt(e[1]),scale:"year"};if(e[2]==="m")return{duration:parseInt(e[1]),scale:"month"};if(e[2]==="d")return{duration:parseInt(e[1]),scale:"day"};if(e[2]==="h")return{duration:parseInt(e[1]),scale:"hour"};if(e[2]==="min")return{duration:parseInt(e[1]),scale:"minute"};if(e[2]==="s")return{duration:parseInt(e[1]),scale:"second"};if(e[2]==="ms")return{duration:parseInt(e[1]),scale:"millisecond"}}},parse(r,t="-",e=/[.:]/){if(r instanceof Date)return r;if(typeof r=="string"){let i,n;const s=r.split(" ");i=s[0].split(t).map(a=>parseInt(a,10)),n=s[1]&&s[1].split(e),i[1]=i[1]?i[1]-1:0;let o=i;return n&&n.length&&(n.length===4&&(n[3]="0."+n[3],n[3]=parseFloat(n[3])*1e3),o=o.concat(n)),new Date(...o)}},to_string(r,t=!1){if(!(r instanceof Date))throw new TypeError("Invalid argument type");const e=this.get_date_values(r).map((s,o)=>(o===1&&(s=s+1),o===6?M(s+"",3,"0"):M(s+"",2,"0"))),i=`${e[0]}-${e[1]}-${e[2]}`,n=`${e[3]}:${e[4]}:${e[5]}.${e[6]}`;return i+(t?" "+n:"")},format(r,t="YYYY-MM-DD HH:mm:ss.SSS",e="en"){const i=new Intl.DateTimeFormat(e,{month:"long"}),n=new Intl.DateTimeFormat(e,{month:"short"}),s=i.format(r),o=s.charAt(0).toUpperCase()+s.slice(1),a=this.get_date_values(r).map(l=>M(l,2,0)),h={YYYY:a[0],MM:M(+a[1]+1,2,0),DD:a[2],HH:a[3],mm:a[4],ss:a[5],SSS:a[6],D:a[2],MMMM:o,MMM:n.format(r)};let d=t;const _=[];return Object.keys(h).sort((l,g)=>g.length-l.length).forEach(l=>{d.includes(l)&&(d=d.replaceAll(l,`$${_.length}`),_.push(h[l]))}),_.forEach((l,g)=>{d=d.replaceAll(`$${g}`,l)}),d},diff(r,t,e="day"){let i,n,s,o,a,h,d;i=r-t+(t.getTimezoneOffset()-r.getTimezoneOffset())*6e4,n=i/1e3,o=n/60,s=o/60,a=s/24;let _=r.getFullYear()-t.getFullYear(),l=r.getMonth()-t.getMonth();return l+=a%30/30,h=_*12+l,r.getDate()<t.getDate()&&h--,d=h/12,e.endsWith("s")||(e+="s"),Math.round({milliseconds:i,seconds:n,minutes:o,hours:s,days:a,months:h,years:d}[e]*100)/100},today(){const r=this.get_date_values(new Date).slice(0,3);return new Date(...r)},now(){return new Date},add(r,t,e){t=parseInt(t,10);const i=[r.getFullYear()+(e===v?t:0),r.getMonth()+(e===x?t:0),r.getDate()+(e===L?t:0),r.getHours()+(e===T?t:0),r.getMinutes()+(e===A?t:0),r.getSeconds()+(e===Y?t:0),r.getMilliseconds()+(e===H?t:0)];return new Date(...i)},start_of(r,t){const e={[v]:6,[x]:5,[L]:4,[T]:3,[A]:2,[Y]:1,[H]:0};function i(s){const o=e[t];return e[s]<=o}const n=[r.getFullYear(),i(v)?0:r.getMonth(),i(x)?1:r.getDate(),i(L)?0:r.getHours(),i(T)?0:r.getMinutes(),i(A)?0:r.getSeconds(),i(Y)?0:r.getMilliseconds()];return new Date(...n)},clone(r){return new Date(...this.get_date_values(r))},get_date_values(r){return[r.getFullYear(),r.getMonth(),r.getDate(),r.getHours(),r.getMinutes(),r.getSeconds(),r.getMilliseconds()]},convert_scales(r,t){const e={millisecond:11574074074074074e-24,second:11574074074074073e-21,minute:.0006944444444444445,hour:.041666666666666664,day:1,month:30,year:365},{duration:i,scale:n}=this.parse_duration(r);return i*e[n]/e[t]},get_days_in_month(r){const t=[31,28,31,30,31,30,31,31,30,31,30,31],e=r.getMonth();if(e!==1)return t[e];const i=r.getFullYear();return i%4===0&&i%100!=0||i%400===0?29:28},get_days_in_year(r){return r.getFullYear()%4?365:366}};function M(r,t,e){return r=r+"",t=t>>0,e=String(typeof e<"u"?e:" "),r.length>t?String(r):(t=t-r.length,t>e.length&&(e+=e.repeat(t/e.length)),e.slice(0,t)+String(r))}function u(r,t){return typeof r=="string"?(t||document).querySelector(r):r||null}function m(r,t){const e=document.createElementNS("http://www.w3.org/2000/svg",r);for(let i in t)i==="append_to"?t.append_to.appendChild(e):i==="innerHTML"?e.innerHTML=t.innerHTML:i==="clipPath"?e.setAttribute("clip-path","url(#"+t[i]+")"):e.setAttribute(i,t[i]);return e}function E(r,t,e,i){const n=z(r,t,e,i);if(n===r){const s=document.createEvent("HTMLEvents");s.initEvent("click",!0,!0),s.eventName="click",n.dispatchEvent(s)}}function z(r,t,e,i,n="0.4s",s="0.1s"){const o=r.querySelector("animate");if(o)return u.attr(o,{attributeName:t,from:e,to:i,dur:n,begin:"click + "+s}),r;const a=m("animate",{attributeName:t,from:e,to:i,dur:n,begin:s,calcMode:"spline",values:e+";"+i,keyTimes:"0; 1",keySplines:C("ease-out")});return r.appendChild(a),r}function C(r){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"}[r]}u.on=(r,t,e,i)=>{i?u.delegate(r,t,e,i):(i=e,u.bind(r,t,i))},u.off=(r,t,e)=>{r.removeEventListener(t,e)},u.bind=(r,t,e)=>{t.split(/\s+/).forEach(function(i){r.addEventListener(i,e)})},u.delegate=(r,t,e,i)=>{r.addEventListener(t,function(n){const s=n.target.closest(e);s&&(n.delegatedTarget=s,i.call(this,n,s))})},u.closest=(r,t)=>t?t.matches(r)?t:u.closest(r,t.parentNode):null,u.attr=(r,t,e)=>{if(!e&&typeof t=="string")return r.getAttribute(t);if(typeof t=="object"){for(let i in t)u.attr(r,i,t[i]);return}r.setAttribute(t,e)};class W{constructor(t,e,i){this.gantt=t,this.from_task=e,this.to_task=i,this.is_critical=this.check_critical_path(),this.is_invalid=this.check_invalid_dependency(),this.calculate_path(),this.draw()}check_critical_path(){return this.gantt.options.critical_path?this.from_task.task._is_critical===!0&&this.to_task.task._is_critical===!0:!1}check_invalid_dependency(){const t=this.to_task.task.dependencies_type||this.gantt.options.dependencies_type;if(t==="fixed")return this.to_task.$bar.getX()<this.from_task.$bar.getX();const e=this.from_task.task,i=this.to_task.task;switch(t){case"finish-to-start":return i._start<e._end;case"start-to-start":return i._start<e._start;case"finish-to-finish":return i._end<e._end;case"start-to-finish":return i._end<e._start}return!1}calculate_path(){let t=this.from_task.$bar.getX()+this.from_task.$bar.getWidth()/2;const e=()=>this.to_task.$bar.getX()<t+this.gantt.options.padding&&t>this.from_task.$bar.getX()+this.gantt.options.padding;for(;e();)t-=10;t-=10;let i=this.gantt.config.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/2,n=this.to_task.$bar.getX()-13,s=this.gantt.config.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/2;const o=this.from_task.task._index>this.to_task.task._index;let a=this.gantt.options.arrow_curve;const h=o?1:0;let d=o?-a:a;if(this.to_task.$bar.getX()<=this.from_task.$bar.getX()+this.gantt.options.padding){let _=this.gantt.options.padding/2-a;_<0&&(_=0,a=this.gantt.options.padding/2,d=o?-a:a);const l=this.to_task.$bar.getY()+this.to_task.$bar.getHeight()/2-d,g=this.to_task.$bar.getX()-this.gantt.options.padding;this.path=`
2
- M ${t} ${i}
3
- v ${_}
4
- a ${a} ${a} 0 0 1 ${-a} ${a}
5
- H ${g}
6
- a ${a} ${a} 0 0 ${h} ${-a} ${d}
7
- V ${l}
8
- a ${a} ${a} 0 0 ${h} ${a} ${d}
9
- L ${n} ${s}
10
- m -5 -5
11
- l 5 5
12
- l -5 5`}else{n<t+a&&(a=n-t);let _=o?s+a:s-a;this.path=`
13
- M ${t} ${i}
14
- V ${_}
15
- a ${a} ${a} 0 0 ${h} ${a} ${a}
16
- L ${n} ${s}
17
- m -5 -5
18
- l 5 5
19
- l -5 5`}}draw(){let t="";this.is_invalid?t="arrow-invalid":this.is_critical&&(t="arrow-critical"),this.element=m("path",{d:this.path,"data-from":this.from_task.task.id,"data-to":this.to_task.task.id,class:t})}update(){this.calculate_path(),this.element.setAttribute("d",this.path),this.is_invalid=this.check_invalid_dependency();let t="";this.is_invalid?t="arrow-invalid":this.is_critical&&(t="arrow-critical"),this.element.setAttribute("class",t)}}class q{constructor(t,e){this.set_defaults(t,e),this.prepare_wrappers(),this.prepare_helpers(),this.refresh()}refresh(){this.bar_group.innerHTML="",this.handle_group.innerHTML="",this.task.custom_class?this.group.classList.add(this.task.custom_class):this.group.classList=["bar-wrapper"],this.unbind(),this.prepare_values(),this.draw(),this.bind()}set_defaults(t,e){this.action_completed=!1,this.gantt=t,this.task=e,this.name=this.name||"",this.is_dragging=!1,this.is_hovering_bar=!1,this.is_hovering_icon=!1,this.add_icon_hide_timeout=null}prepare_wrappers(){this.group=m("g",{class:"bar-wrapper"+(this.task.custom_class?" "+this.task.custom_class:""),"data-id":this.task.id}),this.bar_group=m("g",{class:"bar-group",append_to:this.group}),this.handle_group=m("g",{class:"handle-group",append_to:this.group})}prepare_values(){this.invalid=this.task.invalid,this.height=this.gantt.options.bar_height,this.image_size=this.height-5,(!this.task._start||!(this.task._start instanceof Date))&&(this.task._start=new Date(this.task.start)),(!this.task._end||!(this.task._end instanceof Date))&&(this.task._end=new Date(this.task.end)),this.compute_x(),this.compute_y(),this.compute_duration(),this.corner_radius=this.gantt.options.bar_corner_radius,this.width=this.gantt.config.column_width*this.duration,(!this.task.progress||this.task.progress<0)&&(this.task.progress=0),this.task.progress>100&&(this.task.progress=100)}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()}}prepare_expected_progress_values(){this.compute_expected_progress(),this.expected_progress_width=this.gantt.options.column_width*this.duration*(this.expected_progress/100)||0}draw(){this.draw_bar(),this.draw_progress_bar(),this.gantt.options.show_expected_progress&&(this.prepare_expected_progress_values(),this.draw_expected_progress_bar()),this.draw_label(),this.draw_resize_handles(),this.task.thumbnail&&this.draw_thumbnail(),this.gantt.options.task_add_icon_position&&this.draw_add_task_icon()}draw_bar(){this.$bar=m("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}),this.task.color&&(this.$bar.style.fill=this.task.color),E(this.$bar,"width",0,this.width),this.invalid&&this.$bar.classList.add("bar-invalid")}draw_expected_progress_bar(){this.invalid||(this.$expected_bar_progress=m("rect",{x:this.x,y:this.y,width:this.expected_progress_width,height:this.height,rx:this.corner_radius,ry:this.corner_radius,class:"bar-expected-progress",append_to:this.bar_group}),E(this.$expected_bar_progress,"width",0,this.expected_progress_width))}draw_progress_bar(){if(this.invalid)return;this.progress_width=this.calculate_progress_width();let t=this.corner_radius;/^((?!chrome|android).)*safari/i.test(navigator.userAgent)||(t=this.corner_radius+2),this.$bar_progress=m("rect",{x:this.x,y:this.y,width:this.progress_width,height:this.height,rx:t,ry:t,class:"bar-progress",append_to:this.bar_group}),this.task.color_progress&&(this.$bar_progress.style.fill=this.task.color_progress);const e=c.diff(this.task._start,this.gantt.gantt_start,this.gantt.config.unit)/this.gantt.config.step*this.gantt.config.column_width;this.$date_highlight&&this.$date_highlight.parentNode&&this.$date_highlight.parentNode.removeChild(this.$date_highlight);let i=this.gantt.create_el({classes:`date-range-highlight hide highlight-${CSS.escape(this.task.id)}`,width:this.width,left:e});this.$date_highlight=i,this.gantt.$lower_header.prepend(this.$date_highlight),E(this.$bar_progress,"width",0,this.progress_width)}calculate_progress_width(){const t=this.$bar.getWidth(),e=this.x+t,i=this.gantt.config.ignored_positions.reduce((h,d)=>h+(d>=this.x&&d<e),0)*this.gantt.config.column_width;let n=(t-i)*this.task.progress/100;const s=this.x+n,o=this.gantt.config.ignored_positions.reduce((h,d)=>h+(d>=this.x&&d<s),0)*this.gantt.config.column_width;n+=o;let a=this.gantt.get_ignored_region(this.x+n);for(;a.length;)n+=this.gantt.config.column_width,a=this.gantt.get_ignored_region(this.x+n);return this.progress_width=n,n}draw_label(){let t=this.x+this.$bar.getWidth()/2;this.task.thumbnail&&(t=this.x+this.image_size+5);const e=this.gantt.options.task_column.enabled?"":this.task.name;this.$bar_label=m("text",{x:t,y:this.y+this.height/2,innerHTML:e,class:"bar-label",append_to:this.bar_group}),this.task.color_text&&(this.$bar_label.style.fill=this.task.color_text),requestAnimationFrame(()=>this.update_label_position())}draw_thumbnail(){let t=10,e=2,i,n;i=m("defs",{append_to:this.bar_group}),m("rect",{id:"rect_"+this.task.id,x:this.x+t,y:this.y+e,width:this.image_size,height:this.image_size,rx:"15",class:"img_mask",append_to:i}),n=m("clipPath",{id:"clip_"+this.task.id,append_to:i}),m("use",{href:"#rect_"+this.task.id,append_to:n}),m("image",{x:this.x+t,y:this.y+e,width:this.image_size,height:this.image_size,class:"bar-img",href:this.task.thumbnail,clipPath:"clip_"+this.task.id,append_to:this.bar_group})}draw_add_task_icon(){this.icon_size=20,this.icon_padding=5;let i;if(this.gantt.options.task_add_icon_position==="before")i=this.x-20-5;else if(this.gantt.options.task_add_icon_position==="after")i=this.x+this.$bar.getWidth()+5;else return;const n=this.y+(this.height-20)/2;this.$add_icon_group=m("g",{class:"add-task-icon hide",append_to:this.handle_group}),this.$add_icon_circle=m("circle",{cx:i+20/2,cy:n+20/2,r:20/2,class:"add-task-icon-bg",append_to:this.$add_icon_group}),this.$add_icon_vertical=m("line",{x1:i+20/2,y1:n+5,x2:i+20/2,y2:n+20-5,class:"add-task-icon-plus",append_to:this.$add_icon_group}),this.$add_icon_horizontal=m("line",{x1:i+5,y1:n+20/2,x2:i+20-5,y2:n+20/2,class:"add-task-icon-plus",append_to:this.$add_icon_group}),u.on(this.$add_icon_group,"mousedown",s=>{s.stopPropagation()}),u.on(this.$add_icon_group,"mouseup",s=>{s.stopPropagation()}),u.on(this.$add_icon_group,"click",s=>{s.stopPropagation(),this.gantt.trigger_event("task_add",[this.task])}),u.on(this.$add_icon_group,"mouseenter",s=>{this.is_hovering_icon=!0,this.add_icon_hide_timeout&&(clearTimeout(this.add_icon_hide_timeout),this.add_icon_hide_timeout=null),this.$add_icon_group.classList.add("active"),this.$add_icon_group.classList.remove("hide"),s.stopPropagation()}),u.on(this.$add_icon_group,"mouseleave",()=>{this.is_hovering_icon=!1,this.$add_icon_group.classList.remove("active"),this.is_hovering_bar||this.$add_icon_group.classList.add("hide")})}draw_resize_handles(){if(this.invalid||this.gantt.options.readonly)return;const t=this.$bar,e=8;if(this.handles=[],this.gantt.options.readonly_dates||(this.handles.push(m("rect",{x:t.getEndX()-e,y:t.getY()+(this.height-this.height*.8)/2,width:e,height:this.height*.8,rx:2,ry:2,class:"handle right",append_to:this.handle_group})),this.handles.push(m("rect",{x:t.getX()-e,y:t.getY()+(this.height-this.height*.8)/2,width:e,height:this.height*.8,rx:2,ry:2,class:"handle left",append_to:this.handle_group}))),!this.gantt.options.readonly_progress){const i=this.$bar_progress;this.$handle_progress=m("circle",{cx:i.getEndX(),cy:i.getY()+i.getHeight()/2,r:4.5,class:"handle progress",append_to:this.handle_group}),this.handles.push(this.$handle_progress)}for(let i of this.handles)u.on(i,"mouseenter",()=>i.classList.add("active")),u.on(i,"mouseleave",()=>i.classList.remove("active"))}bind(){this.invalid||this.setup_click_event()}unbind(){this.invalid||this.group&&this.event_listeners&&(this.event_listeners.forEach(({event:t,handler:e})=>{u.off(this.group,t,e)}),this.event_listeners=[])}setup_click_event(){this.event_listeners=[];let t=this.task.id;const e=g=>{this.gantt.trigger_event("hover",[this.task,g.screenX,g.screenY,g])};if(u.on(this.group,"mouseover",e),this.event_listeners.push({event:"mouseover",handler:e}),this.gantt.options.popup_on==="click"){const g=p=>{const w=p.offsetX||p.layerX;if(this.$handle_progress){const f=+this.$handle_progress.getAttribute("cx");if(f>w-1&&f<w+1||this.gantt.bar_being_dragged)return}this.gantt.show_popup({x:p.offsetX||p.layerX,y:p.offsetY||p.layerY,task:this.task,target:this.$bar})};u.on(this.group,"click",g),this.event_listeners.push({event:"click",handler:g})}let i;const n=g=>{i=setTimeout(()=>{this.gantt.options.popup_on==="hover"&&this.gantt.show_popup({x:g.offsetX||g.layerX,y:g.offsetY||g.layerY,task:this.task,target:this.$bar});const p=this.gantt.$container.querySelector(`.highlight-${CSS.escape(t)}`);p&&p.classList.remove("hide")},200),this.$add_icon_group&&(this.is_hovering_bar=!0,this.add_icon_hide_timeout&&(clearTimeout(this.add_icon_hide_timeout),this.add_icon_hide_timeout=null),this.is_dragging||this.$add_icon_group.classList.remove("hide"))};u.on(this.group,"mouseenter",n),this.event_listeners.push({event:"mouseenter",handler:n});const s=()=>{var p,w;clearTimeout(i),this.gantt.options.popup_on==="hover"&&((w=(p=this.gantt.popup)==null?void 0:p.hide)==null||w.call(p));const g=this.gantt.$container.querySelector(`.highlight-${CSS.escape(t)}`);g&&g.classList.add("hide"),this.$add_icon_group&&(this.is_hovering_bar=!1,this.add_icon_hide_timeout&&clearTimeout(this.add_icon_hide_timeout),this.add_icon_hide_timeout=setTimeout(()=>{this.is_hovering_icon||this.$add_icon_group.classList.add("hide")},200))};u.on(this.group,"mouseleave",s),this.event_listeners.push({event:"mouseleave",handler:s});const o=()=>{this.is_dragging=!0,this.hide_add_icon()};u.on(this.group,"mousedown",o),this.event_listeners.push({event:"mousedown",handler:o});const a=()=>{setTimeout(()=>{this.gantt.bar_being_dragged!==!0&&(this.is_dragging=!1,this.$add_icon_group&&this.is_hovering_bar&&this.$add_icon_group.classList.remove("hide"))},0)};u.on(this.group,"mouseup",a),this.event_listeners.push({event:"mouseup",handler:a});const h=()=>{this.action_completed||this.gantt.bar_being_dragged||this.gantt.trigger_event("click",[this.task])};u.on(this.group,"click",h),this.event_listeners.push({event:"click",handler:h});const d=()=>{this.action_completed||(this.group.classList.remove("active"),this.gantt.popup&&this.gantt.popup.parent.classList.remove("hide"),this.gantt.trigger_event("double_click",[this.task]))};u.on(this.group,"dblclick",d),this.event_listeners.push({event:"dblclick",handler:d});let _=!1;const l=g=>{if(!_)return _=!0,setTimeout(function(){_=!1},300),!1;g.preventDefault(),!this.action_completed&&(this.group.classList.remove("active"),this.gantt.popup&&this.gantt.popup.parent.classList.remove("hide"),this.gantt.trigger_event("double_click",[this.task]))};u.on(this.group,"touchstart",l),this.event_listeners.push({event:"touchstart",handler:l})}update_bar_position({x:t=null,width:e=null}){const i=this.$bar;t&&(this.update_attr(i,"x",t),this.x=t,this.$date_highlight.style.left=t+"px"),e>0&&(this.update_attr(i,"width",e),this.$date_highlight.style.width=e+"px"),this.update_label_position(),this.update_handle_position(),this.update_add_icon_position(),this.date_changed(),this.compute_duration(),this.gantt.options.show_expected_progress&&this.update_expected_progressbar_position(),this.update_progressbar_position(),this.update_arrow_position()}validate_dependency_constraints(t,e=null){const i=this.task.dependencies_type||this.gantt.options.dependencies_type;if(i==="fixed")return this.task.dependencies.map(_=>this.gantt.get_bar(_).$bar.getX()).reduce((_,l)=>_&&t>=l,!0);const n=t/this.gantt.config.column_width,s=c.add(this.gantt.gantt_start,n*this.gantt.config.step,this.gantt.config.unit),a=(e||this.$bar.getWidth())/this.gantt.config.column_width,h=c.add(s,a*this.gantt.config.step,this.gantt.config.unit);for(const d of this.task.dependencies){const _=this.gantt.get_bar(d);if(!_)continue;const l=_.task;switch(i){case"finish-to-start":if(s<l._end)return!1;break;case"start-to-start":if(s<l._start)return!1;break;case"finish-to-finish":if(h<l._end)return!1;break;case"start-to-finish":if(h<l._start)return!1;break}}return!0}update_label_position_on_horizontal_scroll({x:t,sx:e}){const i=this.gantt.$container,n=this.group.querySelector(".bar-label"),s=this.group.querySelector(".bar-img")||"",o=this.bar_group.querySelector(".img_mask")||"";let a=this.$bar.getX()+this.$bar.getWidth(),h=n.getX()+t,d=s&&s.getX()+t||0,_=s&&s.getBBox().width+7||7,l=h+n.getBBox().width+7,g=e+i.clientWidth/2;n.classList.contains("big")||(l<a&&t>0&&l<g||h-_>this.$bar.getX()&&t<0&&l>g)&&(n.setAttribute("x",h),s&&(s.setAttribute("x",d),o.setAttribute("x",d)))}date_changed(){let t=!1;const{new_start_date:e,new_end_date:i}=this.compute_start_end_date();Number(this.task._start)!==Number(e)&&(t=!0,this.task._start=e),Number(this.task._end)!==Number(i)&&(t=!0,this.task._end=i),t&&this.gantt.trigger_event("date_change",[this.task,e,c.add(i,-1,"second")])}progress_changed(){this.task.progress=this.compute_progress(),this.gantt.trigger_event("progress_change",[this.task,this.task.progress])}set_action_completed(){this.action_completed=!0,setTimeout(()=>this.action_completed=!1,10),this.is_dragging=!1,this.$add_icon_group&&this.is_hovering_bar&&this.$add_icon_group.classList.remove("hide")}compute_start_end_date(){const t=this.$bar,e=t.getX()/this.gantt.config.column_width;let i=c.add(this.gantt.gantt_start,e*this.gantt.config.step,this.gantt.config.unit);const n=t.getWidth()/this.gantt.config.column_width,s=c.add(i,n*this.gantt.config.step,this.gantt.config.unit);return{new_start_date:i,new_end_date:s}}compute_progress(){this.progress_width=this.$bar_progress.getWidth(),this.x=this.$bar_progress.getBBox().x;const t=this.x+this.progress_width,e=this.progress_width-this.gantt.config.ignored_positions.reduce((n,s)=>n+(s>=this.x&&s<=t),0)*this.gantt.config.column_width;if(e<0)return 0;const i=this.$bar.getWidth()-this.ignored_duration_raw*this.gantt.config.column_width;return parseInt(e/i*100,10)}compute_expected_progress(){this.expected_progress=c.diff(c.today(),this.task._start,"hour")/this.gantt.config.step,this.expected_progress=(this.expected_progress<this.duration?this.expected_progress:this.duration)*100/this.duration}compute_x(){const{column_width:t}=this.gantt.config,e=this.task._start,i=this.gantt.gantt_start;let s=c.diff(e,i,this.gantt.config.unit)/this.gantt.config.step*t;this.x=s}compute_y(){this.y=this.gantt.config.header_height+this.gantt.options.padding/2+this.task._index*(this.height+this.gantt.options.padding)}compute_duration(){let t=0,e=0;for(let i=new Date(this.task._start);i<this.task._end;i.setDate(i.getDate()+1))e++,!this.gantt.config.ignored_dates.find(n=>n.getTime()===i.getTime())&&(!this.gantt.config.ignored_function||!this.gantt.config.ignored_function(i))&&t++;this.task.actual_duration=t,this.task.ignored_duration=e-t,this.duration=c.convert_scales(e+"d",this.gantt.config.unit)/this.gantt.config.step,this.actual_duration_raw=c.convert_scales(t+"d",this.gantt.config.unit)/this.gantt.config.step,this.ignored_duration_raw=this.duration-this.actual_duration_raw}update_attr(t,e,i){return i=+i,isNaN(i)||t.setAttribute(e,i),t}update_expected_progressbar_position(){this.invalid||(this.$expected_bar_progress.setAttribute("x",this.$bar.getX()),this.compute_expected_progress(),this.$expected_bar_progress.setAttribute("width",this.gantt.config.column_width*this.actual_duration_raw*(this.expected_progress/100)||0))}update_progressbar_position(){this.invalid||this.gantt.options.readonly||(this.$bar_progress.setAttribute("x",this.$bar.getX()),this.$bar_progress.setAttribute("width",this.calculate_progress_width()))}update_label_position(){const t=this.bar_group.querySelector(".img_mask")||"",e=this.$bar,i=this.group.querySelector(".bar-label"),n=this.group.querySelector(".bar-img");let s=5,o=this.image_size+10;const a=i.getBBox().width,h=e.getWidth();a>h?(i.classList.add("big"),n?(n.setAttribute("x",e.getEndX()+s),t.setAttribute("x",e.getEndX()+s),i.setAttribute("x",e.getEndX()+o)):i.setAttribute("x",e.getEndX()+s)):(i.classList.remove("big"),n?(n.setAttribute("x",e.getX()+s),t.setAttribute("x",e.getX()+s),i.setAttribute("x",e.getX()+h/2+o)):i.setAttribute("x",e.getX()+h/2-a/2))}update_handle_position(){if(this.invalid||this.gantt.options.readonly)return;const t=this.$bar;this.handle_group.querySelector(".handle.left").setAttribute("x",t.getX()),this.handle_group.querySelector(".handle.right").setAttribute("x",t.getEndX());const e=this.group.querySelector(".handle.progress");e&&e.setAttribute("cx",this.$bar_progress.getEndX())}update_add_icon_position(){if(!this.$add_icon_group)return;const t=this.icon_size,e=this.icon_padding;let i;if(this.gantt.options.task_add_icon_position==="before")i=this.x-t-e;else if(this.gantt.options.task_add_icon_position==="after")i=this.x+this.$bar.getWidth()+e;else return;const n=this.y+(this.height-t)/2;this.$add_icon_circle.setAttribute("cx",i+t/2),this.$add_icon_circle.setAttribute("cy",n+t/2),this.$add_icon_vertical.setAttribute("x1",i+t/2),this.$add_icon_vertical.setAttribute("y1",n+5),this.$add_icon_vertical.setAttribute("x2",i+t/2),this.$add_icon_vertical.setAttribute("y2",n+t-5),this.$add_icon_horizontal.setAttribute("x1",i+5),this.$add_icon_horizontal.setAttribute("y1",n+t/2),this.$add_icon_horizontal.setAttribute("x2",i+t-5),this.$add_icon_horizontal.setAttribute("y2",n+t/2)}hide_add_icon(){this.$add_icon_group&&this.$add_icon_group.classList.add("hide")}update_arrow_position(){this.arrows=this.arrows||[];for(let t of this.arrows)t.update()}}class F{constructor(t,e,i){this.parent=t,this.popup_func=e,this.gantt=i,this.make()}make(){this.parent.innerHTML=`
1
+ (function(v,M){typeof exports=="object"&&typeof module<"u"?module.exports=M():typeof define=="function"&&define.amd?define(M):(v=typeof globalThis<"u"?globalThis:v||self,v.Gantt=M())})(this,function(){"use strict";const v="year",M="month",E="day",Y="hour",S="minute",H="second",W="millisecond",g={parse_duration(o){const e=/([0-9]+)(y|m|d|h|min|s|ms)/gm.exec(o);if(e!==null){if(e[2]==="y")return{duration:parseInt(e[1]),scale:"year"};if(e[2]==="m")return{duration:parseInt(e[1]),scale:"month"};if(e[2]==="d")return{duration:parseInt(e[1]),scale:"day"};if(e[2]==="h")return{duration:parseInt(e[1]),scale:"hour"};if(e[2]==="min")return{duration:parseInt(e[1]),scale:"minute"};if(e[2]==="s")return{duration:parseInt(e[1]),scale:"second"};if(e[2]==="ms")return{duration:parseInt(e[1]),scale:"millisecond"}}},parse(o,t="-",e=/[.:]/){if(o instanceof Date)return o;if(typeof o=="string"){let i,s;const n=o.split(" ");i=n[0].split(t).map(a=>parseInt(a,10)),s=n[1]&&n[1].split(e),i[1]=i[1]?i[1]-1:0;let r=i;return s&&s.length&&(s.length===4&&(s[3]="0."+s[3],s[3]=parseFloat(s[3])*1e3),r=r.concat(s)),new Date(...r)}},to_string(o,t=!1){if(!(o instanceof Date))throw new TypeError("Invalid argument type");const e=this.get_date_values(o).map((n,r)=>(r===1&&(n=n+1),r===6?L(n+"",3,"0"):L(n+"",2,"0"))),i=`${e[0]}-${e[1]}-${e[2]}`,s=`${e[3]}:${e[4]}:${e[5]}.${e[6]}`;return i+(t?" "+s:"")},format(o,t="YYYY-MM-DD HH:mm:ss.SSS",e="en"){const i=new Intl.DateTimeFormat(e,{month:"long"}),s=new Intl.DateTimeFormat(e,{month:"short"}),n=i.format(o),r=n.charAt(0).toUpperCase()+n.slice(1),a=this.get_date_values(o).map(c=>L(c,2,0)),h={YYYY:a[0],MM:L(+a[1]+1,2,0),DD:a[2],HH:a[3],mm:a[4],ss:a[5],SSS:a[6],D:a[2],MMMM:r,MMM:s.format(o)};let d=t;const _=[];return Object.keys(h).sort((c,p)=>p.length-c.length).forEach(c=>{d.includes(c)&&(d=d.replaceAll(c,`$${_.length}`),_.push(h[c]))}),_.forEach((c,p)=>{d=d.replaceAll(`$${p}`,c)}),d},diff(o,t,e="day"){let i,s,n,r,a,h,d;i=o-t+(t.getTimezoneOffset()-o.getTimezoneOffset())*6e4,s=i/1e3,r=s/60,n=r/60,a=n/24;let _=o.getFullYear()-t.getFullYear(),c=o.getMonth()-t.getMonth();return c+=a%30/30,h=_*12+c,o.getDate()<t.getDate()&&h--,d=h/12,e.endsWith("s")||(e+="s"),Math.round({milliseconds:i,seconds:s,minutes:r,hours:n,days:a,months:h,years:d}[e]*100)/100},today(){const o=this.get_date_values(new Date).slice(0,3);return new Date(...o)},now(){return new Date},add(o,t,e){t=parseInt(t,10);const i=[o.getFullYear()+(e===v?t:0),o.getMonth()+(e===M?t:0),o.getDate()+(e===E?t:0),o.getHours()+(e===Y?t:0),o.getMinutes()+(e===S?t:0),o.getSeconds()+(e===H?t:0),o.getMilliseconds()+(e===W?t:0)];return new Date(...i)},start_of(o,t){const e={[v]:6,[M]:5,[E]:4,[Y]:3,[S]:2,[H]:1,[W]:0};function i(n){const r=e[t];return e[n]<=r}const s=[o.getFullYear(),i(v)?0:o.getMonth(),i(M)?1:o.getDate(),i(E)?0:o.getHours(),i(Y)?0:o.getMinutes(),i(S)?0:o.getSeconds(),i(H)?0:o.getMilliseconds()];return new Date(...s)},clone(o){return new Date(...this.get_date_values(o))},get_date_values(o){return[o.getFullYear(),o.getMonth(),o.getDate(),o.getHours(),o.getMinutes(),o.getSeconds(),o.getMilliseconds()]},convert_scales(o,t){const e={millisecond:11574074074074074e-24,second:11574074074074073e-21,minute:.0006944444444444445,hour:.041666666666666664,day:1,month:30,year:365},{duration:i,scale:s}=this.parse_duration(o);return i*e[s]/e[t]},get_days_in_month(o){const t=[31,28,31,30,31,30,31,31,30,31,30,31],e=o.getMonth();if(e!==1)return t[e];const i=o.getFullYear();return i%4===0&&i%100!=0||i%400===0?29:28},get_days_in_year(o){return o.getFullYear()%4?365:366}};function L(o,t,e){return o=o+"",t=t>>0,e=String(typeof e<"u"?e:" "),o.length>t?String(o):(t=t-o.length,t>e.length&&(e+=e.repeat(t/e.length)),e.slice(0,t)+String(o))}function m(o,t){return typeof o=="string"?(t||document).querySelector(o):o||null}function w(o,t){const e=document.createElementNS("http://www.w3.org/2000/svg",o);for(let i in t)i==="append_to"?t.append_to.appendChild(e):i==="innerHTML"?e.innerHTML=t.innerHTML:i==="clipPath"?e.setAttribute("clip-path","url(#"+t[i]+")"):e.setAttribute(i,t[i]);return e}function X(o,t,e,i){const s=O(o,t,e,i);if(s===o){const n=document.createEvent("HTMLEvents");n.initEvent("click",!0,!0),n.eventName="click",s.dispatchEvent(n)}}function O(o,t,e,i,s="0.4s",n="0.1s"){const r=o.querySelector("animate");if(r)return m.attr(r,{attributeName:t,from:e,to:i,dur:s,begin:"click + "+n}),o;const a=w("animate",{attributeName:t,from:e,to:i,dur:s,begin:n,calcMode:"spline",values:e+";"+i,keyTimes:"0; 1",keySplines:j("ease-out")});return o.appendChild(a),o}function j(o){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"}[o]}m.on=(o,t,e,i)=>{i?m.delegate(o,t,e,i):(i=e,m.bind(o,t,i))},m.off=(o,t,e)=>{o.removeEventListener(t,e)},m.bind=(o,t,e)=>{t.split(/\s+/).forEach(function(i){o.addEventListener(i,e)})},m.delegate=(o,t,e,i)=>{o.addEventListener(t,function(s){const n=s.target.closest(e);n&&(s.delegatedTarget=n,i.call(this,s,n))})},m.closest=(o,t)=>t?t.matches(o)?t:m.closest(o,t.parentNode):null,m.attr=(o,t,e)=>{if(!e&&typeof t=="string")return o.getAttribute(t);if(typeof t=="object"){for(let i in t)m.attr(o,i,t[i]);return}o.setAttribute(t,e)};function N(o,t,e,i,s="downstream"){if(i==="none"||e===0)return new Map;["upstream","downstream","both"].includes(s)||(console.warn(`[frappe-gantt] compute_dependency_shifts: unknown direction "${s}", falling back to "downstream"`),s="downstream");const n=new Map,r=new Map,a=new Map;for(const h of o)h._has_no_dates||(n.set(h.id,h),r.set(h.id,[]),a.set(h.id,[]));for(const h of o)if(!h._has_no_dates)for(const d of h.dependencies||[]){if(!n.has(d.id))continue;const _=d.type||"finish-to-start";r.get(h.id).push({id:d.id,type:_}),a.get(d.id).push({id:h.id,type:_})}return i==="maintain_buffer_all"||i==="maintain_buffer_downstream"?q(t,e,r,a,s==="both",s==="upstream"):i==="consume_buffer"?V(t,e,n,r,a,s):new Map}function q(o,t,e,i,s,n){const r=new Map,a=new Set([o]),h=[],d=_=>{for(const{id:c}of _)a.has(c)||(a.add(c),h.push(c))};for(n&&!s?d(e.get(o)||[]):(d(i.get(o)||[]),s&&d(e.get(o)||[]));h.length>0;){const _=h.shift();r.set(_,t),n&&!s?d(e.get(_)||[]):(d(i.get(_)||[]),s&&d(e.get(_)||[]))}return r}function V(o,t,e,i,s,n){const r=new Map;for(const[l]of e)r.set(l,(i.get(l)||[]).length);const a=[],h=[];for(const[l,f]of r)f===0&&h.push(l);for(;h.length>0;){const l=h.shift();a.push(l);for(const{id:f}of s.get(l)||[]){const u=r.get(f)-1;r.set(f,u),u===0&&h.push(f)}}const d=new Map([[o,0]]),_=l=>e.get(l)._start.getTime()+(d.get(l)||0),c=l=>e.get(l)._end.getTime()+(d.get(l)||0);if(n==="downstream"||n==="both")for(const l of a){if(l===o)continue;let f=0;for(const{id:u,type:b}of i.get(l)||[]){const y=F(u,l,b,_,c);y>f&&(f=y)}f>0&&d.set(l,(d.get(l)||0)+f)}if(n==="upstream"||n==="both")for(let l=a.length-1;l>=0;l--){const f=a[l];if(f===o)continue;let u=0;for(const{id:b,type:y}of s.get(f)||[]){const k=F(f,b,y,_,c);if(k>0){const $=-k;$<u&&(u=$)}}u<0&&d.set(f,(d.get(f)||0)+u)}const p=new Map;for(const[l,f]of d)l!==o&&f!==0&&p.set(l,f);return p}function F(o,t,e,i,s){const n=i(o),r=s(o),a=i(t),h=s(t);switch(e){case"finish-to-start":return r>a?r-a:0;case"start-to-start":return n>a?n-a:0;case"finish-to-finish":return r>h?r-h:0;case"start-to-finish":return n>h?n-h:0;default:return r>a?r-a:0}}class B{constructor(t,e,i,s){this.gantt=t,this.from_task=e,this.to_task=i,this.dependency_type=s,this.is_critical=this.check_critical_path(),this.is_invalid=this.check_invalid_dependency(),this.is_hovered=!1,this.calculate_path(),this.draw()}check_critical_path(){return this.gantt.options.critical_path?this.from_task.task._is_critical===!0&&this.to_task.task._is_critical===!0:!1}check_invalid_dependency(){const t=this.dependency_type,e=this.from_task.task,i=this.to_task.task;switch(t){case"finish-to-start":return i._start<e._end;case"start-to-start":return i._start<e._start;case"finish-to-finish":return i._end<e._end;case"start-to-finish":return i._end<e._start}return!1}calculate_path(){const t=this.gantt.options,e=this.gantt.config,i=t.arrow_curve,s=t.padding,n=this.from_task.$bar.getX()+this.from_task.$bar.getWidth(),r=this.from_task.$bar.getX(),a=this.to_task.$bar.getX()+this.to_task.$bar.getWidth(),h=this.to_task.$bar.getX(),d=l=>e.header_height+t.bar_height/2+(t.padding+t.bar_height)*l.task._index+t.padding/2,_=d(this.from_task),c=d(this.to_task),p=(_+c)/2;switch(this.dependency_type){case"finish-to-start":this.path=this._path_finish_to_start(n,r,a,h,_,c,p,s,i);break;case"start-to-start":this.path=this._path_start_to_start(r,h,_,c,s,i);break;case"finish-to-finish":this.path=this._path_finish_to_finish(n,a,_,c,s,i);break;case"start-to-finish":this.path=this._path_start_to_finish(r,a,_,c,p,s,i);break;default:this.path=this._path_finish_to_start(n,r,a,h,_,c,p,s,i)}}_path_finish_to_start(t,e,i,s,n,r,a,h,d){const _=t+h;if(_<s)return`
2
+ M ${t} ${n}
3
+ H ${_-d}
4
+ a ${d} ${d} 0 0 1 ${d} ${d}
5
+ V ${r-d}
6
+ a ${d} ${d} 0 0 0 ${d} ${d}
7
+ H ${s}
8
+ m -5 -5 l 5 5 l -5 5`;const c=s-h;return`
9
+ M ${t} ${n}
10
+ H ${_-d}
11
+ a ${d} ${d} 0 0 1 ${d} ${d}
12
+ V ${a-d}
13
+ a ${d} ${d} 0 0 1 ${-d} ${d}
14
+ H ${c+d}
15
+ a ${d} ${d} 0 0 0 ${-d} ${d}
16
+ V ${r-d}
17
+ a ${d} ${d} 0 0 0 ${d} ${d}
18
+ H ${s}
19
+ m -5 -5 l 5 5 l -5 5`}_path_start_to_start(t,e,i,s,n,r){const a=Math.min(t,e)-n;return`
20
+ M ${t} ${i}
21
+ H ${a+r}
22
+ a ${r} ${r} 0 0 0 ${-r} ${r}
23
+ V ${s-r}
24
+ a ${r} ${r} 0 0 0 ${r} ${r}
25
+ H ${e}
26
+ m -5 -5 l 5 5 l -5 5`}_path_finish_to_finish(t,e,i,s,n,r){const a=Math.max(t,e)+n;return`
27
+ M ${t} ${i}
28
+ H ${a-r}
29
+ a ${r} ${r} 0 0 1 ${r} ${r}
30
+ V ${s-r}
31
+ a ${r} ${r} 0 0 1 ${-r} ${r}
32
+ H ${e}
33
+ m 5 -5 l -5 5 l 5 5`}_path_start_to_finish(t,e,i,s,n,r,a){const h=t-r,d=e+r;return`
34
+ M ${t} ${i}
35
+ H ${h+a}
36
+ a ${a} ${a} 0 0 0 ${-a} ${a}
37
+ V ${n-a}
38
+ a ${a} ${a} 0 0 0 ${a} ${a}
39
+ H ${d-a}
40
+ a ${a} ${a} 0 0 1 ${a} ${a}
41
+ V ${s-a}
42
+ a ${a} ${a} 0 0 1 ${-a} ${a}
43
+ H ${e}
44
+ m 5 -5 l -5 5 l 5 5`}_get_connected_bars(){const t=this.from_task.task.id,e=this.to_task.task.id;return Array.from(this.gantt.$svg.querySelectorAll(`[data-id="${CSS.escape(t)}"], [data-id="${CSS.escape(e)}"]`))}draw(){let t="";this.is_invalid?t="arrow-invalid":this.is_critical&&(t="arrow-critical"),this.element=w("path",{d:this.path,"data-from":this.from_task.task.id,"data-to":this.to_task.task.id,class:t}),this.hit_element=w("path",{d:this.path,stroke:"transparent","stroke-width":15,fill:"none",style:"pointer-events: stroke; cursor: pointer;"}),this.hit_element.addEventListener("mouseenter",()=>{this.is_hovered=!0,this.element.classList.add("arrow-hover");const e=this.is_invalid?"bar-arrow-invalid":this.is_critical?"bar-arrow-critical":"bar-arrow-hover";this._get_connected_bars().forEach(i=>{const s=i.querySelector(".bar");s&&s.classList.add(e)})}),this.hit_element.addEventListener("mouseleave",()=>{this.is_hovered=!1,this.element.classList.remove("arrow-hover"),this._get_connected_bars().forEach(e=>{const i=e.querySelector(".bar");i&&i.classList.remove("bar-arrow-hover","bar-arrow-critical","bar-arrow-invalid")})})}update(){this.calculate_path(),this.element.setAttribute("d",this.path),this.hit_element.setAttribute("d",this.path),this.is_invalid=this.check_invalid_dependency();let t="";this.is_invalid?t="arrow-invalid":this.is_critical&&(t="arrow-critical"),this.is_hovered&&(t+=" arrow-hover"),this.element.setAttribute("class",t.trim())}}class G{constructor(t,e){this.set_defaults(t,e),this.prepare_wrappers(),this.prepare_helpers(),this.refresh()}refresh(){this.bar_group.innerHTML="",this.handle_group.innerHTML="",this.task.custom_class?this.group.classList.add(this.task.custom_class):this.group.classList=["bar-wrapper"],this.unbind(),this.prepare_values(),this.draw(),this.bind()}set_defaults(t,e){this.action_completed=!1,this.gantt=t,this.task=e,this.name=this.name||"",this.is_dragging=!1,this.is_hovering_bar=!1,this.is_hovering_icon=!1,this.add_icon_hide_timeout=null}prepare_wrappers(){this.group=w("g",{class:"bar-wrapper"+(this.task.custom_class?" "+this.task.custom_class:""),"data-id":this.task.id}),this.bar_group=w("g",{class:"bar-group",append_to:this.group}),this.handle_group=w("g",{class:"handle-group",append_to:this.group})}prepare_values(){this.invalid=this.task.invalid,this.height=this.gantt.options.bar_height,this.image_size=this.height-5,(!this.task._start||!(this.task._start instanceof Date))&&(this.task._start=new Date(this.task.start)),(!this.task._end||!(this.task._end instanceof Date))&&(this.task._end=new Date(this.task.end)),this.compute_x(),this.compute_y(),this.compute_duration(),this.corner_radius=this.gantt.options.bar_corner_radius,this.width=this.gantt.config.column_width*this.duration,(!this.task.progress||this.task.progress<0)&&(this.task.progress=0),this.task.progress>100&&(this.task.progress=100)}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()}}prepare_expected_progress_values(){this.compute_expected_progress(),this.expected_progress_width=this.gantt.options.column_width*this.duration*(this.expected_progress/100)||0}draw(){this.draw_bar(),this.draw_progress_bar(),this.gantt.options.show_expected_progress&&(this.prepare_expected_progress_values(),this.draw_expected_progress_bar()),this.draw_label(),this.draw_resize_handles(),this.task.thumbnail&&this.draw_thumbnail(),this.gantt.options.task_add_icon_position&&this.draw_add_task_icon()}draw_bar(){this.$bar=w("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}),this.task.color&&(this.$bar.style.fill=this.task.color),X(this.$bar,"width",0,this.width),this.invalid&&this.$bar.classList.add("bar-invalid")}draw_expected_progress_bar(){this.invalid||(this.$expected_bar_progress=w("rect",{x:this.x,y:this.y,width:this.expected_progress_width,height:this.height,rx:this.corner_radius,ry:this.corner_radius,class:"bar-expected-progress",append_to:this.bar_group}),X(this.$expected_bar_progress,"width",0,this.expected_progress_width))}draw_progress_bar(){if(this.invalid)return;this.progress_width=this.calculate_progress_width();let t=this.corner_radius;/^((?!chrome|android).)*safari/i.test(navigator.userAgent)||(t=this.corner_radius+2),this.$bar_progress=w("rect",{x:this.x,y:this.y,width:this.progress_width,height:this.height,rx:t,ry:t,class:"bar-progress",append_to:this.bar_group}),this.task.color_progress&&(this.$bar_progress.style.fill=this.task.color_progress);const e=g.diff(this.task._start,this.gantt.gantt_start,this.gantt.config.unit)/this.gantt.config.step*this.gantt.config.column_width;this.$date_highlight&&this.$date_highlight.parentNode&&this.$date_highlight.parentNode.removeChild(this.$date_highlight);let i=this.gantt.create_el({classes:`date-range-highlight hide highlight-${CSS.escape(this.task.id)}`,width:this.width,left:e});this.$date_highlight=i,this.gantt.$lower_header.prepend(this.$date_highlight),X(this.$bar_progress,"width",0,this.progress_width)}calculate_progress_width(){const t=this.$bar.getWidth(),e=this.x+t,i=this.gantt.config.ignored_positions.reduce((h,d)=>h+(d>=this.x&&d<e),0)*this.gantt.config.column_width;let s=(t-i)*this.task.progress/100;const n=this.x+s,r=this.gantt.config.ignored_positions.reduce((h,d)=>h+(d>=this.x&&d<n),0)*this.gantt.config.column_width;s+=r;let a=this.gantt.get_ignored_region(this.x+s);for(;a.length;)s+=this.gantt.config.column_width,a=this.gantt.get_ignored_region(this.x+s);return this.progress_width=s,s}draw_label(){let t=this.x+this.$bar.getWidth()/2;this.task.thumbnail&&(t=this.x+this.image_size+5);const e=this.gantt.options.task_column.enabled?"":this.task.name;this.$bar_label=w("text",{x:t,y:this.y+this.height/2,innerHTML:e,class:"bar-label",append_to:this.bar_group}),this.task.color_text&&(this.$bar_label.style.fill=this.task.color_text),requestAnimationFrame(()=>this.update_label_position())}draw_thumbnail(){let t=10,e=2,i,s;i=w("defs",{append_to:this.bar_group}),w("rect",{id:"rect_"+this.task.id,x:this.x+t,y:this.y+e,width:this.image_size,height:this.image_size,rx:"15",class:"img_mask",append_to:i}),s=w("clipPath",{id:"clip_"+this.task.id,append_to:i}),w("use",{href:"#rect_"+this.task.id,append_to:s}),w("image",{x:this.x+t,y:this.y+e,width:this.image_size,height:this.image_size,class:"bar-img",href:this.task.thumbnail,clipPath:"clip_"+this.task.id,append_to:this.bar_group})}draw_add_task_icon(){this.icon_size=20,this.icon_padding=5;let i;if(this.gantt.options.task_add_icon_position==="before")i=this.x-20-5;else if(this.gantt.options.task_add_icon_position==="after")i=this.x+this.$bar.getWidth()+5;else return;const s=this.y+(this.height-20)/2;this.$add_icon_group=w("g",{class:"add-task-icon hide",append_to:this.handle_group}),this.$add_icon_circle=w("circle",{cx:i+20/2,cy:s+20/2,r:20/2,class:"add-task-icon-bg",append_to:this.$add_icon_group}),this.$add_icon_vertical=w("line",{x1:i+20/2,y1:s+5,x2:i+20/2,y2:s+20-5,class:"add-task-icon-plus",append_to:this.$add_icon_group}),this.$add_icon_horizontal=w("line",{x1:i+5,y1:s+20/2,x2:i+20-5,y2:s+20/2,class:"add-task-icon-plus",append_to:this.$add_icon_group}),m.on(this.$add_icon_group,"mousedown",n=>{n.stopPropagation()}),m.on(this.$add_icon_group,"mouseup",n=>{n.stopPropagation()}),m.on(this.$add_icon_group,"click",n=>{n.stopPropagation(),this.gantt.trigger_event("task_add",[this.task])}),m.on(this.$add_icon_group,"mouseenter",n=>{this.is_hovering_icon=!0,this.add_icon_hide_timeout&&(clearTimeout(this.add_icon_hide_timeout),this.add_icon_hide_timeout=null),this.$add_icon_group.classList.add("active"),this.$add_icon_group.classList.remove("hide"),n.stopPropagation()}),m.on(this.$add_icon_group,"mouseleave",()=>{this.is_hovering_icon=!1,this.$add_icon_group.classList.remove("active"),this.is_hovering_bar||this.$add_icon_group.classList.add("hide")})}draw_resize_handles(){if(this.invalid||this.gantt.options.readonly)return;const t=this.$bar,e=8;if(this.handles=[],this.gantt.options.readonly_dates||(this.handles.push(w("rect",{x:t.getEndX()-e,y:t.getY()+(this.height-this.height*.8)/2,width:e,height:this.height*.8,rx:2,ry:2,class:"handle right",append_to:this.handle_group})),this.handles.push(w("rect",{x:t.getX()-e,y:t.getY()+(this.height-this.height*.8)/2,width:e,height:this.height*.8,rx:2,ry:2,class:"handle left",append_to:this.handle_group}))),!this.gantt.options.readonly_progress){const i=this.$bar_progress;this.$handle_progress=w("circle",{cx:i.getEndX(),cy:i.getY()+i.getHeight()/2,r:4.5,class:"handle progress",append_to:this.handle_group}),this.handles.push(this.$handle_progress)}for(let i of this.handles)m.on(i,"mouseenter",()=>i.classList.add("active")),m.on(i,"mouseleave",()=>i.classList.remove("active"))}bind(){this.invalid||this.setup_click_event()}unbind(){this.invalid||this.group&&this.event_listeners&&(this.event_listeners.forEach(({event:t,handler:e})=>{m.off(this.group,t,e)}),this.event_listeners=[])}setup_click_event(){this.event_listeners=[];let t=this.task.id;const e=p=>{this.gantt.trigger_event("hover",[this.task,p.screenX,p.screenY,p])};if(m.on(this.group,"mouseover",e),this.event_listeners.push({event:"mouseover",handler:e}),this.gantt.options.popup_on==="click"){const p=l=>{const f=l.offsetX||l.layerX;if(this.$handle_progress){const u=+this.$handle_progress.getAttribute("cx");if(u>f-1&&u<f+1||this.gantt.bar_being_dragged)return}this.gantt.show_popup({x:l.offsetX||l.layerX,y:l.offsetY||l.layerY,task:this.task,target:this.$bar})};m.on(this.group,"click",p),this.event_listeners.push({event:"click",handler:p})}let i;const s=p=>{i=setTimeout(()=>{this.gantt.options.popup_on==="hover"&&this.gantt.show_popup({x:p.offsetX||p.layerX,y:p.offsetY||p.layerY,task:this.task,target:this.$bar});const l=this.gantt.$container.querySelector(`.highlight-${CSS.escape(t)}`);l&&l.classList.remove("hide")},200),this.$add_icon_group&&(this.is_hovering_bar=!0,this.add_icon_hide_timeout&&(clearTimeout(this.add_icon_hide_timeout),this.add_icon_hide_timeout=null),this.is_dragging||this.$add_icon_group.classList.remove("hide"))};m.on(this.group,"mouseenter",s),this.event_listeners.push({event:"mouseenter",handler:s});const n=()=>{var l,f;clearTimeout(i),this.gantt.options.popup_on==="hover"&&((f=(l=this.gantt.popup)==null?void 0:l.hide)==null||f.call(l));const p=this.gantt.$container.querySelector(`.highlight-${CSS.escape(t)}`);p&&p.classList.add("hide"),this.$add_icon_group&&(this.is_hovering_bar=!1,this.add_icon_hide_timeout&&clearTimeout(this.add_icon_hide_timeout),this.add_icon_hide_timeout=setTimeout(()=>{this.is_hovering_icon||this.$add_icon_group.classList.add("hide")},200))};m.on(this.group,"mouseleave",n),this.event_listeners.push({event:"mouseleave",handler:n});const r=()=>{this.is_dragging=!0,this.hide_add_icon()};m.on(this.group,"mousedown",r),this.event_listeners.push({event:"mousedown",handler:r});const a=()=>{setTimeout(()=>{this.gantt.bar_being_dragged!==!0&&(this.is_dragging=!1,this.$add_icon_group&&this.is_hovering_bar&&this.$add_icon_group.classList.remove("hide"))},0)};m.on(this.group,"mouseup",a),this.event_listeners.push({event:"mouseup",handler:a});const h=()=>{this.action_completed||this.gantt.bar_being_dragged||this.gantt.trigger_event("click",[this.task])};m.on(this.group,"click",h),this.event_listeners.push({event:"click",handler:h});const d=()=>{this.action_completed||(this.group.classList.remove("active"),this.gantt.popup&&this.gantt.popup.parent.classList.remove("hide"),this.gantt.trigger_event("double_click",[this.task]))};m.on(this.group,"dblclick",d),this.event_listeners.push({event:"dblclick",handler:d});let _=!1;const c=p=>{if(!_)return _=!0,setTimeout(function(){_=!1},300),!1;p.preventDefault(),!this.action_completed&&(this.group.classList.remove("active"),this.gantt.popup&&this.gantt.popup.parent.classList.remove("hide"),this.gantt.trigger_event("double_click",[this.task]))};m.on(this.group,"touchstart",c),this.event_listeners.push({event:"touchstart",handler:c})}update_bar_position({x:t=null,width:e=null}){const i=this.$bar;t&&(this.update_attr(i,"x",t),this.x=t,this.$date_highlight.style.left=t+"px"),e>0&&(this.update_attr(i,"width",e),this.$date_highlight.style.width=e+"px"),this.update_label_position(),this.update_handle_position(),this.update_add_icon_position(),this.date_changed(),this.compute_duration(),this.gantt.options.show_expected_progress&&this.update_expected_progressbar_position(),this.update_progressbar_position(),this.update_arrow_position()}update_label_position_on_horizontal_scroll({x:t,sx:e}){const i=this.gantt.$container,s=this.group.querySelector(".bar-label"),n=this.group.querySelector(".bar-img")||"",r=this.bar_group.querySelector(".img_mask")||"";let a=this.$bar.getX()+this.$bar.getWidth(),h=s.getX()+t,d=n&&n.getX()+t||0,_=n&&n.getBBox().width+7||7,c=h+s.getBBox().width+7,p=e+i.clientWidth/2;s.classList.contains("big")||(c<a&&t>0&&c<p||h-_>this.$bar.getX()&&t<0&&c>p)&&(s.setAttribute("x",h),n&&(n.setAttribute("x",d),r.setAttribute("x",d)))}date_changed(){let t=!1;const{new_start_date:e,new_end_date:i}=this.compute_start_end_date();Number(this.task._start)!==Number(e)&&(t=!0,this.task._start=e),Number(this.task._end)!==Number(i)&&(t=!0,this.task._end=i),t&&this.gantt.trigger_event("date_change",[this.task,e,g.add(i,-1,"second")])}progress_changed(){this.task.progress=this.compute_progress(),this.gantt.trigger_event("progress_change",[this.task,this.task.progress])}set_action_completed(){this.action_completed=!0,setTimeout(()=>this.action_completed=!1,10),this.is_dragging=!1,this.$add_icon_group&&this.is_hovering_bar&&this.$add_icon_group.classList.remove("hide")}compute_start_end_date(){const t=this.$bar,e=t.getX()/this.gantt.config.column_width;let i=g.add(this.gantt.gantt_start,e*this.gantt.config.step,this.gantt.config.unit);const s=t.getWidth()/this.gantt.config.column_width,n=g.add(i,s*this.gantt.config.step,this.gantt.config.unit);return{new_start_date:i,new_end_date:n}}compute_progress(){this.progress_width=this.$bar_progress.getWidth(),this.x=this.$bar_progress.getBBox().x;const t=this.x+this.progress_width,e=this.progress_width-this.gantt.config.ignored_positions.reduce((s,n)=>s+(n>=this.x&&n<=t),0)*this.gantt.config.column_width;if(e<0)return 0;const i=this.$bar.getWidth()-this.ignored_duration_raw*this.gantt.config.column_width;return parseInt(e/i*100,10)}compute_expected_progress(){this.expected_progress=g.diff(g.today(),this.task._start,"hour")/this.gantt.config.step,this.expected_progress=(this.expected_progress<this.duration?this.expected_progress:this.duration)*100/this.duration}compute_x(){const{column_width:t}=this.gantt.config,e=this.task._start,i=this.gantt.gantt_start;let n=g.diff(e,i,this.gantt.config.unit)/this.gantt.config.step*t;this.x=n}compute_y(){this.y=this.gantt.config.header_height+this.gantt.options.padding/2+this.task._index*(this.height+this.gantt.options.padding)}compute_duration(){let t=0,e=0;for(let i=new Date(this.task._start);i<this.task._end;i.setDate(i.getDate()+1))e++,!this.gantt.config.ignored_dates.find(s=>s.getTime()===i.getTime())&&(!this.gantt.config.ignored_function||!this.gantt.config.ignored_function(i))&&t++;this.task.actual_duration=t,this.task.ignored_duration=e-t,this.duration=g.convert_scales(e+"d",this.gantt.config.unit)/this.gantt.config.step,this.actual_duration_raw=g.convert_scales(t+"d",this.gantt.config.unit)/this.gantt.config.step,this.ignored_duration_raw=this.duration-this.actual_duration_raw}update_attr(t,e,i){return i=+i,isNaN(i)||t.setAttribute(e,i),t}update_expected_progressbar_position(){this.invalid||(this.$expected_bar_progress.setAttribute("x",this.$bar.getX()),this.compute_expected_progress(),this.$expected_bar_progress.setAttribute("width",this.gantt.config.column_width*this.actual_duration_raw*(this.expected_progress/100)||0))}update_progressbar_position(){this.invalid||this.gantt.options.readonly||(this.$bar_progress.setAttribute("x",this.$bar.getX()),this.$bar_progress.setAttribute("width",this.calculate_progress_width()))}update_label_position(){const t=this.bar_group.querySelector(".img_mask")||"",e=this.$bar,i=this.group.querySelector(".bar-label"),s=this.group.querySelector(".bar-img");let n=5,r=this.image_size+10;const a=i.getBBox().width,h=e.getWidth();a>h?(i.classList.add("big"),s?(s.setAttribute("x",e.getEndX()+n),t.setAttribute("x",e.getEndX()+n),i.setAttribute("x",e.getEndX()+r)):i.setAttribute("x",e.getEndX()+n)):(i.classList.remove("big"),s?(s.setAttribute("x",e.getX()+n),t.setAttribute("x",e.getX()+n),i.setAttribute("x",e.getX()+h/2+r)):i.setAttribute("x",e.getX()+h/2-a/2))}update_handle_position(){if(this.invalid||this.gantt.options.readonly)return;const t=this.$bar;this.handle_group.querySelector(".handle.left").setAttribute("x",t.getX()),this.handle_group.querySelector(".handle.right").setAttribute("x",t.getEndX());const e=this.group.querySelector(".handle.progress");e&&e.setAttribute("cx",this.$bar_progress.getEndX())}update_add_icon_position(){if(!this.$add_icon_group)return;const t=this.icon_size,e=this.icon_padding;let i;if(this.gantt.options.task_add_icon_position==="before")i=this.x-t-e;else if(this.gantt.options.task_add_icon_position==="after")i=this.x+this.$bar.getWidth()+e;else return;const s=this.y+(this.height-t)/2;this.$add_icon_circle.setAttribute("cx",i+t/2),this.$add_icon_circle.setAttribute("cy",s+t/2),this.$add_icon_vertical.setAttribute("x1",i+t/2),this.$add_icon_vertical.setAttribute("y1",s+5),this.$add_icon_vertical.setAttribute("x2",i+t/2),this.$add_icon_vertical.setAttribute("y2",s+t-5),this.$add_icon_horizontal.setAttribute("x1",i+5),this.$add_icon_horizontal.setAttribute("y1",s+t/2),this.$add_icon_horizontal.setAttribute("x2",i+t-5),this.$add_icon_horizontal.setAttribute("y2",s+t/2)}hide_add_icon(){this.$add_icon_group&&this.$add_icon_group.classList.add("hide")}update_arrow_position(){this.arrows=this.arrows||[];for(let t of this.arrows)t.update()}}class I{constructor(t,e,i){this.parent=t,this.popup_func=e,this.gantt=i,this.make()}make(){this.parent.innerHTML=`
20
45
  <div class="title"></div>
21
46
  <div class="subtitle"></div>
22
47
  <div class="details"></div>
23
48
  <div class="actions"></div>
24
- `,this.hide(),this.title=this.parent.querySelector(".title"),this.subtitle=this.parent.querySelector(".subtitle"),this.details=this.parent.querySelector(".details"),this.actions=this.parent.querySelector(".actions")}show({x:t,y:e,task:i,target:n}){this.actions.innerHTML="";let s=this.popup_func({task:i,chart:this.gantt,get_title:()=>this.title,set_title:o=>this.title.innerHTML=o,get_subtitle:()=>this.subtitle,set_subtitle:o=>this.subtitle.innerHTML=o,get_details:()=>this.details,set_details:o=>this.details.innerHTML=o,add_action:(o,a)=>{let h=this.gantt.create_el({classes:"action-btn",type:"button",append_to:this.actions});typeof o=="function"&&(o=o(i)),h.innerHTML=o,h.onclick=d=>a(i,this.gantt,d)}});s!==!1&&(s&&(this.parent.innerHTML=s),this.actions.innerHTML===""?this.actions.remove():this.parent.appendChild(this.actions),this.parent.style.left=t+10+"px",this.parent.style.top=e-10+"px",this.parent.classList.remove("hide"))}hide(){this.parent.classList.add("hide")}}function S(r){const t=r.getFullYear();return t-t%10+""}function P(r,t,e){let i=c.add(r,6,"day"),n=i.getMonth()!==r.getMonth()?"D MMM":"D",s=!t||r.getMonth()!==t.getMonth()?"D MMM":"D";return`${c.format(r,s,e)} - ${c.format(i,n,e)}`}const y=[{name:"Hour",padding:"7d",step:"1h",date_format:"YYYY-MM-DD HH:",lower_text:"HH",upper_text:(r,t,e)=>!t||r.getDate()!==t.getDate()?c.format(r,"D MMMM",e):"",upper_text_frequency:24},{name:"Quarter Day",padding:"7d",step:"6h",date_format:"YYYY-MM-DD HH:",lower_text:"HH",upper_text:(r,t,e)=>!t||r.getDate()!==t.getDate()?c.format(r,"D MMM",e):"",upper_text_frequency:4},{name:"Half Day",padding:"14d",step:"12h",date_format:"YYYY-MM-DD HH:",lower_text:"HH",upper_text:(r,t,e)=>!t||r.getDate()!==t.getDate()?r.getMonth()!==r.getMonth()?c.format(r,"D MMM",e):c.format(r,"D",e):"",upper_text_frequency:2},{name:"Day",padding:"7d",date_format:"YYYY-MM-DD",step:"1d",lower_text:(r,t,e)=>!t||r.getDate()!==t.getDate()?c.format(r,"D",e):"",upper_text:(r,t,e)=>!t||r.getMonth()!==t.getMonth()?c.format(r,"MMMM",e):"",thick_line:r=>r.getDay()===1},{name:"Week",padding:"1m",step:"7d",date_format:"YYYY-MM-DD",column_width:140,lower_text:P,upper_text:(r,t,e)=>!t||r.getMonth()!==t.getMonth()?c.format(r,"MMMM",e):"",thick_line:r=>r.getDate()>=1&&r.getDate()<=7,upper_text_frequency:4},{name:"Month",padding:"2m",step:"1m",column_width:120,date_format:"YYYY-MM",lower_text:"MMMM",upper_text:(r,t,e)=>!t||r.getFullYear()!==t.getFullYear()?c.format(r,"YYYY",e):"",thick_line:r=>r.getMonth()%3===0,snap_at:"7d"},{name:"Year",padding:"2y",step:"1y",column_width:120,date_format:"YYYY",upper_text:(r,t,e)=>!t||S(r)!==S(t)?S(r):"",lower_text:"YYYY",snap_at:"30d"}],O={arrow_curve:5,auto_move_label:!1,bar_corner_radius:3,bar_height:30,container_height:"auto",column_width:null,critical_path:!1,date_format:"YYYY-MM-DD HH:mm",dependencies_type:"fixed",upper_header_height:45,lower_header_height:30,snap_at:null,infinite_padding:!0,holidays:{"var(--g-weekend-highlight-color)":"weekend"},ignore:[],isRTL:!1,language:"en",lines:"both",move_dependencies:!0,padding:18,popup:r=>{r.set_title(r.task.name),r.task.description?r.set_subtitle(r.task.description):r.set_subtitle("");const t=c.format(r.task._start,"MMM D",r.chart.options.language),e=c.format(c.add(r.task._end,-1,"second"),"MMM D",r.chart.options.language);r.set_details(`${t} - ${e} (${r.task.actual_duration} days${r.task.ignored_duration?" + "+r.task.ignored_duration+" excluded":""})<br/>Progress: ${Math.floor(r.task.progress*100)/100}%`)},popup_on:"click",readonly_progress:!1,readonly_dates:!1,readonly:!1,scroll_to:"today",show_expected_progress:!1,task_add_icon_position:null,today_button:!0,view_mode:"Day",view_mode_select:!1,view_modes:y,is_weekend:r=>r.getDay()===0||r.getDay()===6,task_column:{enabled:!1,width:200,header_text:"Task Name",content:null}};class X{constructor(t,e,i){this.setup_wrapper(t),this.setup_options(i),this.apply_rtl_direction(),this.setup_tasks(e),this.change_view_mode(),this.bind_events()}setup_wrapper(t){let e,i;if(typeof t=="string"){let n=document.querySelector(t);if(!n)throw new ReferenceError(`CSS selector "${t}" could not be found in DOM`);t=n}if(t instanceof HTMLElement)i=t,e=t.querySelector("svg");else if(t instanceof SVGElement)e=t;else throw new TypeError("Frappe Gantt only supports usage of a string CSS selector, HTML DOM element or SVG DOM element for the 'element' parameter");e?(this.$svg=e,this.$svg.classList.add("gantt")):this.$svg=m("svg",{append_to:i,class:"gantt"}),this.$wrapper=this.create_el({classes:"gantt-wrapper",append_to:this.$svg.parentElement}),this.$container=this.create_el({classes:"gantt-container",append_to:this.$wrapper}),this.$container.appendChild(this.$svg),this.$popup_wrapper=this.create_el({classes:"popup-wrapper",append_to:this.$container})}apply_rtl_direction(){this.options.isRTL&&(this.$container.style.direction="ltr")}setup_options(t){var i;this.original_options=t,t!=null&&t.view_modes&&(t.view_modes=t.view_modes.map(n=>{if(typeof n=="string"){const s=y.find(o=>o.name===n);return s||console.error(`The view mode "${n}" is not predefined in Frappe Gantt. Please define the view mode object instead.`),s}return n}),t.view_mode=t.view_modes[0]),this.options={...O,...t};const e={"grid-height":"container_height","bar-height":"bar_height","lower-header-height":"lower_header_height","upper-header-height":"upper_header_height"};for(let n in e){let s=this.options[e[n]];s!=="auto"&&(this.$wrapper.style.setProperty("--gv-"+n,s+"px"),this.$container.style.setProperty("--gv-"+n,s+"px"))}if((i=this.options.task_column)!=null&&i.enabled&&(this.$wrapper.style.setProperty("--gv-task-column-width",this.options.task_column.width+"px"),this.$container.style.setProperty("--gv-task-column-width",this.options.task_column.width+"px")),this.config={ignored_dates:[],ignored_positions:[],extend_by_units:10},typeof this.options.ignore!="function"){typeof this.options.ignore=="string"&&(this.options.ignore=[this.options.ignore]);for(let n of this.options.ignore){if(typeof n=="function"){this.config.ignored_function=n;continue}typeof n=="string"&&(n==="weekend"?this.config.ignored_function=s=>s.getDay()==6||s.getDay()==0:this.config.ignored_dates.push(new Date(n+" ")))}}else this.config.ignored_function=this.options.ignore}update_options(t){this.setup_options({...this.original_options,...t}),this.apply_rtl_direction(),this.change_view_mode(void 0,!0)}setup_tasks(t){this.tasks=t.map((e,i)=>{var n;if(!e.start||!e.end)if(!e.start&&!e.end){if(!((n=this.options.task_column)!=null&&n.enabled))return console.warn(`task "${e.id||e.name}" has no dates and will be hidden (task column is disabled)`),!1;e._has_no_dates=!0,e._start=new Date,e._end=new Date,e._index=i}else{if(!e.start)return console.error(`task "${e.id}" doesn't have a start date`),!1;if(!e.end&&!e.duration)return console.error(`task "${e.id}" doesn't have an end date`),!1}if(!e._has_no_dates){if(e._start=c.parse(e.start),e.end===void 0&&e.duration!==void 0&&(e.end=e._start,e.duration.split(" ").forEach(h=>{let{duration:d,scale:_}=c.parse_duration(h);e.end=c.add(e.end,d,_)})),e._end=c.parse(e.end),c.diff(e._end,e._start,"year")<0)return console.error(`start of task can't be after end of task: in task "${e.id}"`),!1;if(c.diff(e._end,e._start,"year")>10)return console.error(`the duration of task "${e.id}" is too long (above ten years)`),!1;e._index=i,c.get_date_values(e._end).slice(3).every(a=>a===0)&&(e._end=c.add(e._end,24,"hour"))}if(typeof e.dependencies=="string"||!e.dependencies){let s=[];e.dependencies&&(s=e.dependencies.split(",").map(o=>o.trim().replaceAll(" ","_")).filter(o=>o)),e.dependencies=s}return e.id?typeof e.id=="string"?e.id=e.id.replaceAll(" ","_"):e.id=`${e.id}`:e.id=I(e),e}).filter(e=>e).map((e,i)=>(e._index=i,e)),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,e=!1){this.setup_tasks(t),this.change_view_mode(this.options.view_mode,e)}update_task(t,e){let i=this.tasks.find(s=>s.id===t),n=this.bars[i._index];Object.assign(i,e),n.refresh()}change_view_mode(t=this.options.view_mode,e=!1){typeof t=="string"&&(t=this.options.view_modes.find(s=>s.name===t));let i,n;e&&(i=this.$container.scrollLeft,n=this.options.scroll_to,this.options.scroll_to=null),this.options.view_mode=t.name,this.config.view_mode=t,this.update_view_scale(t),this.setup_dates(e),this.render(),e&&(this.$container.scrollLeft=i,this.options.scroll_to=n),this.trigger_event("view_change",[t])}update_view_scale(t){let{duration:e,scale:i}=c.parse_duration(t.step);this.config.step=e,this.config.unit=i,this.config.column_width=this.options.column_width||t.column_width||45,this.$container.style.setProperty("--gv-column-width",this.config.column_width+"px"),this.config.header_height=this.options.lower_header_height+this.options.upper_header_height+10}setup_dates(t=!1){this.setup_gantt_dates(t),this.setup_date_values()}setup_gantt_dates(t){let e,i;this.tasks.length||(e=new Date,i=new Date);for(let n of this.tasks)(!e||n._start<e)&&(e=n._start),(!i||n._end>i)&&(i=n._end);if(e=c.start_of(e,this.config.unit),i=c.start_of(i,this.config.unit),!t)if(this.options.infinite_padding)this.gantt_start=c.add(e,-this.config.extend_by_units*3,this.config.unit),this.gantt_end=c.add(i,this.config.extend_by_units*3,this.config.unit);else{typeof this.config.view_mode.padding=="string"&&(this.config.view_mode.padding=[this.config.view_mode.padding,this.config.view_mode.padding]);let[n,s]=this.config.view_mode.padding.map(c.parse_duration);this.gantt_start=c.add(e,-n.duration,n.scale),this.gantt_end=c.add(i,s.duration,s.scale)}this.config.date_format=this.config.view_mode.date_format||this.options.date_format,this.gantt_start.setHours(0,0,0,0)}setup_date_values(){let t=this.gantt_start;for(this.dates=[t];t<this.gantt_end;)t=c.add(t,this.config.step,this.config.unit),this.dates.push(t)}bind_events(){this.bind_grid_click(),this.bind_holiday_labels(),this.bind_bar_events(),this.bind_task_column_resize(),this.bind_task_column_scroll()}render(){this.clear(),this.setup_layers(),this.make_grid(),this.make_dates(),this.make_grid_extras(),this.make_bars(),this.make_arrows(),this.map_arrows_on_bars(),this.set_dimensions(),this.set_scroll_position(this.options.scroll_to)}setup_layers(){this.layers={};const t=["grid","arrow","progress","bar"];for(let e of t)this.layers[e]=m("g",{class:e,append_to:this.$svg});this.$extras=this.create_el({classes:"extras",append_to:this.$container}),this.$adjust=this.create_el({classes:"adjust hide",append_to:this.$extras,type:"button"}),this.$adjust.innerHTML="&larr;"}make_grid(){this.make_grid_background(),this.make_grid_rows(),this.make_grid_header(),this.make_side_header(),this.make_task_column()}make_grid_extras(){this.make_grid_highlights(),this.make_grid_ticks()}make_grid_background(){const t=this.dates.length*this.config.column_width,e=Math.max(this.config.header_height+this.options.padding+(this.options.bar_height+this.options.padding)*this.tasks.length-10,this.options.container_height!=="auto"?this.options.container_height:0);m("rect",{x:0,y:0,width:t,height:e,class:"grid-background",append_to:this.$svg}),u.attr(this.$svg,{height:e,width:"100%"}),this.grid_height=e,this.options.container_height==="auto"&&(this.$container.style.height=e+"px")}make_grid_rows(){const t=m("g",{append_to:this.layers.grid}),e=this.dates.length*this.config.column_width,i=this.options.bar_height+this.options.padding;this.config.header_height;for(let n=this.config.header_height;n<this.grid_height;n+=i)m("rect",{x:0,y:n,width:e,height:i,class:"grid-row",append_to:t})}make_grid_header(){this.$header=this.create_el({width:this.dates.length*this.config.column_width,classes:"grid-header",append_to:this.$container}),this.$upper_header=this.create_el({classes:"upper-header",append_to:this.$header}),this.$lower_header=this.create_el({classes:"lower-header",append_to:this.$header})}make_side_header(){if(this.$side_header=this.create_el({classes:"side-header"}),this.$upper_header.prepend(this.$side_header),this.options.view_mode_select){const t=document.createElement("select");t.classList.add("viewmode-select");const e=document.createElement("option");e.selected=!0,e.disabled=!0,e.textContent="Mode",t.appendChild(e);for(const i of this.options.view_modes){const n=document.createElement("option");n.value=i.name,n.textContent=i.name,i.name===this.config.view_mode.name&&(n.selected=!0),t.appendChild(n)}t.addEventListener("change",(function(){this.change_view_mode(t.value,!0)}).bind(this)),this.$side_header.appendChild(t)}if(this.options.today_button){let t=document.createElement("button");t.classList.add("today-button"),t.textContent="Today",t.onclick=this.scroll_current.bind(this),this.$side_header.prepend(t),this.$today_button=t}}make_task_column(){var i,n,s,o,a,h,d,_,l,g;if((i=this.$task_column)==null||i.remove(),!((n=this.options.task_column)!=null&&n.enabled)){(o=(s=this.$wrapper)==null?void 0:s.classList)==null||o.remove("has-task-column");return}(h=(a=this.$wrapper)==null?void 0:a.classList)==null||h.add("has-task-column"),this.$task_column=this.create_el({classes:"task-column",append_to:this.$wrapper}),this.$wrapper.insertBefore(this.$task_column,this.$container),this.$task_column_header=this.create_el({classes:"task-column-header",append_to:this.$task_column}),this.$task_column_header.textContent=this.options.task_column.header_text||"Task Name",this.$task_column_content=this.create_el({classes:"task-column-content",append_to:this.$task_column});const t=this.options.bar_height+this.options.padding,e=Math.max(this.tasks.length*t,this.grid_height-this.config.header_height);this.$task_column_content.style.minHeight=e+"px",this.$wrapper.style.setProperty("--gv-task-column-content-height",e+"px"),this.$container.style.setProperty("--gv-task-column-content-height",e+"px"),this.tasks.forEach(p=>{const w=this.options.bar_height+this.options.padding,f=this.create_el({classes:"task-row",append_to:this.$task_column_content});if(f.style.top=p._index*w-1+"px",f.style.height=w+"px",this.options.task_column.content&&typeof this.options.task_column.content=="function"){const b=this.options.task_column.content(p);typeof b=="string"?f.innerHTML=b:b instanceof HTMLElement&&f.appendChild(b)}else f.textContent=p.name,f.title=p.name;f.setAttribute("data-task-id",p.id)}),this.$task_column.style.width=this.options.task_column.width+"px",this.$task_column_resize_handle=this.create_el({classes:"task-column-resize-handle",append_to:this.$task_column}),this.options.isRTL?(_=(d=this.$wrapper)==null?void 0:d.classList)==null||_.add("rtl"):(g=(l=this.$wrapper)==null?void 0:l.classList)==null||g.remove("rtl")}make_grid_ticks(){if(this.options.lines==="none")return;let t=0,e=this.config.header_height,i=this.grid_height-this.config.header_height,n=m("g",{class:"lines_layer",append_to:this.layers.grid}),s=this.config.header_height;const o=this.dates.length*this.config.column_width,a=this.options.bar_height+this.options.padding;if(this.options.lines!=="vertical")for(let h=this.config.header_height;h<this.grid_height;h+=a)m("line",{x1:0,y1:s+a,x2:o,y2:s+a,class:"row-line",append_to:n}),s+=a;if(this.options.lines!=="horizontal")for(let h of this.dates){let d="tick";this.config.view_mode.thick_line&&this.config.view_mode.thick_line(h)&&(d+=" thick"),m("path",{d:`M ${t} ${e} v ${i}`,class:d,append_to:this.layers.grid}),this.view_is("month")?t+=c.get_days_in_month(h)*this.config.column_width/30:this.view_is("year")?t+=c.get_days_in_year(h)*this.config.column_width/365:t+=this.config.column_width}}highlight_holidays(){let t={};if(this.options.holidays)for(let e in this.options.holidays){let i=this.options.holidays[e];i==="weekend"&&(i=this.options.is_weekend);let n;if(typeof i=="object"){let s=i.find(o=>typeof o=="function");if(s&&(n=s),this.options.holidays.name){let o=new Date(i.date+" ");i=a=>o.getTime()===a.getTime(),t[o]=i.name}else i=o=>this.options.holidays[e].filter(a=>typeof a!="function").map(a=>{if(a.name){let h=new Date(a.date+" ");return t[h]=a.name,h.getTime()}return new Date(a+" ").getTime()}).includes(o.getTime())}for(let s=new Date(this.gantt_start);s<=this.gantt_end;s.setDate(s.getDate()+1))if(!(this.config.ignored_dates.find(o=>o.getTime()==s.getTime())||this.config.ignored_function&&this.config.ignored_function(s))&&(i(s)||n&&n(s))){const o=c.diff(s,this.gantt_start,this.config.unit)/this.config.step*this.config.column_width,a=this.grid_height-this.config.header_height,h=c.format(s,"YYYY-MM-DD",this.options.language).replace(" ","_");if(t[s]){let d=this.create_el({classes:"holiday-label label_"+h,append_to:this.$extras});d.textContent=t[s]}m("rect",{x:Math.round(o),y:this.config.header_height,width:this.config.column_width/c.convert_scales(this.config.view_mode.step,"day"),height:a,class:"holiday-highlight "+h,style:`fill: ${e};`,append_to:this.layers.grid})}}}highlight_current(){const t=this.get_closest_date();if(!t)return;const[e,i]=t;i.classList.add("current-date-highlight");const s=c.diff(new Date,this.gantt_start,this.config.unit)/this.config.step*this.config.column_width;this.$current_highlight=this.create_el({top:this.config.header_height,left:s,height:this.grid_height-this.config.header_height,classes:"current-highlight",append_to:this.$container}),this.$current_ball_highlight=this.create_el({top:this.config.header_height-6,left:s-2.5,width:6,height:6,classes:"current-ball-highlight",append_to:this.$header})}make_grid_highlights(){this.highlight_holidays(),this.config.ignored_positions=[];const t=(this.options.bar_height+this.options.padding)*this.tasks.length;this.layers.grid.innerHTML+=`<pattern id="diagonalHatch" patternUnits="userSpaceOnUse" width="4" height="4">
49
+ `,this.hide(),this.title=this.parent.querySelector(".title"),this.subtitle=this.parent.querySelector(".subtitle"),this.details=this.parent.querySelector(".details"),this.actions=this.parent.querySelector(".actions")}show({x:t,y:e,task:i,target:s}){this.actions.innerHTML="";let n=this.popup_func({task:i,chart:this.gantt,get_title:()=>this.title,set_title:r=>this.title.innerHTML=r,get_subtitle:()=>this.subtitle,set_subtitle:r=>this.subtitle.innerHTML=r,get_details:()=>this.details,set_details:r=>this.details.innerHTML=r,add_action:(r,a)=>{let h=this.gantt.create_el({classes:"action-btn",type:"button",append_to:this.actions});typeof r=="function"&&(r=r(i)),h.innerHTML=r,h.onclick=d=>a(i,this.gantt,d)}});n!==!1&&(n&&(this.parent.innerHTML=n),this.actions.innerHTML===""?this.actions.remove():this.parent.appendChild(this.actions),this.parent.style.left=t+10+"px",this.parent.style.top=e-10+"px",this.parent.classList.remove("hide"))}hide(){this.parent.classList.add("hide")}}function z(o){const t=o.getFullYear();return t-t%10+""}function R(o,t,e){let i=g.add(o,6,"day"),s=i.getMonth()!==o.getMonth()?"D MMM":"D",n=!t||o.getMonth()!==t.getMonth()?"D MMM":"D";return`${g.format(o,n,e)} - ${g.format(i,s,e)}`}const x=[{name:"Hour",padding:"7d",step:"1h",date_format:"YYYY-MM-DD HH:",lower_text:"HH",upper_text:(o,t,e)=>!t||o.getDate()!==t.getDate()?g.format(o,"D MMMM",e):"",upper_text_frequency:24},{name:"Quarter Day",padding:"7d",step:"6h",date_format:"YYYY-MM-DD HH:",lower_text:"HH",upper_text:(o,t,e)=>!t||o.getDate()!==t.getDate()?g.format(o,"D MMM",e):"",upper_text_frequency:4},{name:"Half Day",padding:"14d",step:"12h",date_format:"YYYY-MM-DD HH:",lower_text:"HH",upper_text:(o,t,e)=>!t||o.getDate()!==t.getDate()?o.getMonth()!==o.getMonth()?g.format(o,"D MMM",e):g.format(o,"D",e):"",upper_text_frequency:2},{name:"Day",padding:"7d",date_format:"YYYY-MM-DD",step:"1d",lower_text:(o,t,e)=>!t||o.getDate()!==t.getDate()?g.format(o,"D",e):"",upper_text:(o,t,e)=>!t||o.getMonth()!==t.getMonth()?g.format(o,"MMMM",e):"",thick_line:o=>o.getDay()===1},{name:"Week",padding:"1m",step:"7d",date_format:"YYYY-MM-DD",column_width:140,lower_text:R,upper_text:(o,t,e)=>!t||o.getMonth()!==t.getMonth()?g.format(o,"MMMM",e):"",thick_line:o=>o.getDate()>=1&&o.getDate()<=7,upper_text_frequency:4},{name:"Month",padding:"2m",step:"1m",column_width:120,date_format:"YYYY-MM",lower_text:"MMMM",upper_text:(o,t,e)=>!t||o.getFullYear()!==t.getFullYear()?g.format(o,"YYYY",e):"",thick_line:o=>o.getMonth()%3===0,snap_at:"7d"},{name:"Year",padding:"2y",step:"1y",column_width:120,date_format:"YYYY",upper_text:(o,t,e)=>!t||z(o)!==z(t)?z(o):"",lower_text:"YYYY",snap_at:"30d"}],U={arrow_curve:5,auto_move_label:!1,bar_corner_radius:3,bar_height:30,container_height:"auto",column_width:null,critical_path:!1,date_format:"YYYY-MM-DD HH:mm",dependencies_type:"finish-to-start",dependency_shifting:"none",upper_header_height:45,lower_header_height:30,snap_at:null,infinite_padding:!0,holidays:{"var(--g-weekend-highlight-color)":"weekend"},ignore:[],isRTL:!1,language:"en",lines:"both",padding:18,popup:o=>{o.set_title(o.task.name),o.task.description?o.set_subtitle(o.task.description):o.set_subtitle("");const t=g.format(o.task._start,"MMM D",o.chart.options.language),e=g.format(g.add(o.task._end,-1,"second"),"MMM D",o.chart.options.language);o.set_details(`${t} - ${e} (${o.task.actual_duration} days${o.task.ignored_duration?" + "+o.task.ignored_duration+" excluded":""})<br/>Progress: ${Math.floor(o.task.progress*100)/100}%`)},popup_on:"click",readonly_progress:!1,readonly_dates:!1,readonly:!1,scroll_to:"today",show_expected_progress:!1,task_add_icon_position:null,today_button:!0,view_mode:"Day",view_mode_select:!1,view_modes:x,is_weekend:o=>o.getDay()===0||o.getDay()===6,task_column:{enabled:!1,width:200,header_text:"Task Name",content:null}};class P{constructor(t,e,i){this.setup_wrapper(t),this.setup_options(i),this.apply_rtl_direction(),this.setup_tasks(e),this.change_view_mode(),this.bind_events()}setup_wrapper(t){let e,i;if(typeof t=="string"){let s=document.querySelector(t);if(!s)throw new ReferenceError(`CSS selector "${t}" could not be found in DOM`);t=s}if(t instanceof HTMLElement)i=t,e=t.querySelector("svg");else if(t instanceof SVGElement)e=t;else throw new TypeError("Frappe Gantt only supports usage of a string CSS selector, HTML DOM element or SVG DOM element for the 'element' parameter");e?(this.$svg=e,this.$svg.classList.add("gantt")):this.$svg=w("svg",{append_to:i,class:"gantt"}),this.$wrapper=this.create_el({classes:"gantt-wrapper",append_to:this.$svg.parentElement}),this.$container=this.create_el({classes:"gantt-container",append_to:this.$wrapper}),this.$container.appendChild(this.$svg),this.$popup_wrapper=this.create_el({classes:"popup-wrapper",append_to:this.$container})}apply_rtl_direction(){this.options.isRTL&&(this.$container.style.direction="ltr")}setup_options(t){var i;this.original_options=t,t!=null&&t.view_modes&&(t.view_modes=t.view_modes.map(s=>{if(typeof s=="string"){const n=x.find(r=>r.name===s);return n||console.error(`The view mode "${s}" is not predefined in Frappe Gantt. Please define the view mode object instead.`),n}return s}),t.view_mode=t.view_modes[0]),this.options={...U,...t};const e={"grid-height":"container_height","bar-height":"bar_height","lower-header-height":"lower_header_height","upper-header-height":"upper_header_height"};for(let s in e){let n=this.options[e[s]];n!=="auto"&&(this.$wrapper.style.setProperty("--gv-"+s,n+"px"),this.$container.style.setProperty("--gv-"+s,n+"px"))}if((i=this.options.task_column)!=null&&i.enabled&&(this.$wrapper.style.setProperty("--gv-task-column-width",this.options.task_column.width+"px"),this.$container.style.setProperty("--gv-task-column-width",this.options.task_column.width+"px")),this.config={ignored_dates:[],ignored_positions:[],extend_by_units:10},typeof this.options.ignore!="function"){typeof this.options.ignore=="string"&&(this.options.ignore=[this.options.ignore]);for(let s of this.options.ignore){if(typeof s=="function"){this.config.ignored_function=s;continue}typeof s=="string"&&(s==="weekend"?this.config.ignored_function=n=>n.getDay()==6||n.getDay()==0:this.config.ignored_dates.push(new Date(s+" ")))}}else this.config.ignored_function=this.options.ignore}update_options(t){this.setup_options({...this.original_options,...t}),this.apply_rtl_direction(),this.change_view_mode(void 0,!0)}setup_tasks(t){this.tasks=t.map((e,i)=>{var s;if(!e.start||!e.end)if(!e.start&&!e.end){if(!((s=this.options.task_column)!=null&&s.enabled))return console.warn(`task "${e.id||e.name}" has no dates and will be hidden (task column is disabled)`),!1;e._has_no_dates=!0,e._start=new Date,e._end=new Date,e._index=i}else{if(!e.start)return console.error(`task "${e.id}" doesn't have a start date`),!1;if(!e.end&&!e.duration)return console.error(`task "${e.id}" doesn't have an end date`),!1}if(!e._has_no_dates){if(e._start=g.parse(e.start),e.end===void 0&&e.duration!==void 0&&(e.end=e._start,e.duration.split(" ").forEach(h=>{let{duration:d,scale:_}=g.parse_duration(h);e.end=g.add(e.end,d,_)})),e._end=g.parse(e.end),g.diff(e._end,e._start,"year")<0)return console.error(`start of task can't be after end of task: in task "${e.id}"`),!1;if(g.diff(e._end,e._start,"year")>10)return console.error(`the duration of task "${e.id}" is too long (above ten years)`),!1;e._index=i,g.get_date_values(e._end).slice(3).every(a=>a===0)&&(e._end=g.add(e._end,24,"hour"))}return(typeof e.dependencies=="string"||Array.isArray(e.dependencies)&&e.dependencies.some(n=>typeof n=="string"))&&console.warn(`[frappe-gantt] Task "${e.id}": dependencies must be an array of {id, type?} objects. String format is no longer supported.`),Array.isArray(e.dependencies)||(e.dependencies=[]),e.dependencies=e.dependencies.filter(n=>n&&typeof n.id=="string").map(n=>({...n,id:n.id.replaceAll(" ","_")})),e.id?typeof e.id=="string"?e.id=e.id.replaceAll(" ","_"):e.id=`${e.id}`:e.id=Q(e),e}).filter(e=>e).map((e,i)=>(e._index=i,e)),this.setup_dependencies()}setup_dependencies(){this.dependency_map={};for(let t of this.tasks)for(let e of t.dependencies)this.dependency_map[e.id]=this.dependency_map[e.id]||[],this.dependency_map[e.id].push(t.id)}refresh(t,e=!1){this.setup_tasks(t),this.change_view_mode(this.options.view_mode,e)}update_task(t,e){let i=this.tasks.find(r=>r.id===t),s=this.bars[i._index];const n=e.dependencies!==void 0;Object.assign(i,e),n&&(Array.isArray(i.dependencies)||(i.dependencies=[]),i.dependencies=i.dependencies.filter(r=>r&&typeof r.id=="string").map(r=>({...r,id:r.id.replaceAll(" ","_")})),this.setup_dependencies(),this.layers.arrow.innerHTML="",this.make_arrows(),this.map_arrows_on_bars()),s.refresh()}change_view_mode(t=this.options.view_mode,e=!1){typeof t=="string"&&(t=this.options.view_modes.find(n=>n.name===t));let i,s;e&&(i=this.$container.scrollLeft,s=this.options.scroll_to,this.options.scroll_to=null),this.options.view_mode=t.name,this.config.view_mode=t,this.update_view_scale(t),this.setup_dates(e),this.render(),e&&(this.$container.scrollLeft=i,this.options.scroll_to=s),this.trigger_event("view_change",[t])}update_view_scale(t){let{duration:e,scale:i}=g.parse_duration(t.step);this.config.step=e,this.config.unit=i,this.config.column_width=this.options.column_width||t.column_width||45,this.$container.style.setProperty("--gv-column-width",this.config.column_width+"px"),this.config.header_height=this.options.lower_header_height+this.options.upper_header_height+10}setup_dates(t=!1){this.setup_gantt_dates(t),this.setup_date_values()}setup_gantt_dates(t){let e,i;this.tasks.length||(e=new Date,i=new Date);for(let s of this.tasks)(!e||s._start<e)&&(e=s._start),(!i||s._end>i)&&(i=s._end);if(e=g.start_of(e,this.config.unit),i=g.start_of(i,this.config.unit),!t)if(this.options.infinite_padding)this.gantt_start=g.add(e,-this.config.extend_by_units*3,this.config.unit),this.gantt_end=g.add(i,this.config.extend_by_units*3,this.config.unit);else{typeof this.config.view_mode.padding=="string"&&(this.config.view_mode.padding=[this.config.view_mode.padding,this.config.view_mode.padding]);let[s,n]=this.config.view_mode.padding.map(g.parse_duration);this.gantt_start=g.add(e,-s.duration,s.scale),this.gantt_end=g.add(i,n.duration,n.scale)}this.config.date_format=this.config.view_mode.date_format||this.options.date_format,this.gantt_start.setHours(0,0,0,0)}setup_date_values(){let t=this.gantt_start;for(this.dates=[t];t<this.gantt_end;)t=g.add(t,this.config.step,this.config.unit),this.dates.push(t)}bind_events(){this.bind_grid_click(),this.bind_holiday_labels(),this.bind_bar_events(),this.bind_task_column_resize(),this.bind_task_column_scroll()}render(){this.clear(),this.setup_layers(),this.make_grid(),this.make_dates(),this.make_grid_extras(),this.make_bars(),this.make_arrows(),this.map_arrows_on_bars(),this.set_dimensions(),this.set_scroll_position(this.options.scroll_to)}setup_layers(){this.layers={};const t=["grid","arrow","progress","bar"];for(let e of t)this.layers[e]=w("g",{class:e,append_to:this.$svg});this.$extras=this.create_el({classes:"extras",append_to:this.$container}),this.$adjust=this.create_el({classes:"adjust hide",append_to:this.$extras,type:"button"}),this.$adjust.innerHTML="&larr;"}make_grid(){this.make_grid_background(),this.make_grid_rows(),this.make_grid_header(),this.make_side_header(),this.make_task_column()}make_grid_extras(){this.make_grid_highlights(),this.make_grid_ticks()}make_grid_background(){const t=this.dates.length*this.config.column_width,e=Math.max(this.config.header_height+this.options.padding+(this.options.bar_height+this.options.padding)*this.tasks.length-10,this.options.container_height!=="auto"?this.options.container_height:0);w("rect",{x:0,y:0,width:t,height:e,class:"grid-background",append_to:this.$svg}),m.attr(this.$svg,{height:e,width:"100%"}),this.grid_height=e,this.options.container_height==="auto"&&(this.$container.style.height=e+"px")}make_grid_rows(){const t=w("g",{append_to:this.layers.grid}),e=this.dates.length*this.config.column_width,i=this.options.bar_height+this.options.padding;this.config.header_height;for(let s=this.config.header_height;s<this.grid_height;s+=i)w("rect",{x:0,y:s,width:e,height:i,class:"grid-row",append_to:t})}make_grid_header(){this.$header=this.create_el({width:this.dates.length*this.config.column_width,classes:"grid-header",append_to:this.$container}),this.$upper_header=this.create_el({classes:"upper-header",append_to:this.$header}),this.$lower_header=this.create_el({classes:"lower-header",append_to:this.$header})}make_side_header(){if(this.$side_header=this.create_el({classes:"side-header"}),this.$upper_header.prepend(this.$side_header),this.options.view_mode_select){const t=document.createElement("select");t.classList.add("viewmode-select");const e=document.createElement("option");e.selected=!0,e.disabled=!0,e.textContent="Mode",t.appendChild(e);for(const i of this.options.view_modes){const s=document.createElement("option");s.value=i.name,s.textContent=i.name,i.name===this.config.view_mode.name&&(s.selected=!0),t.appendChild(s)}t.addEventListener("change",(function(){this.change_view_mode(t.value,!0)}).bind(this)),this.$side_header.appendChild(t)}if(this.options.today_button){let t=document.createElement("button");t.classList.add("today-button"),t.textContent="Today",t.onclick=this.scroll_current.bind(this),this.$side_header.prepend(t),this.$today_button=t}}make_task_column(){var i,s,n,r,a,h,d,_,c,p;if((i=this.$task_column)==null||i.remove(),!((s=this.options.task_column)!=null&&s.enabled)){(r=(n=this.$wrapper)==null?void 0:n.classList)==null||r.remove("has-task-column");return}(h=(a=this.$wrapper)==null?void 0:a.classList)==null||h.add("has-task-column"),this.$task_column=this.create_el({classes:"task-column",append_to:this.$wrapper}),this.$wrapper.insertBefore(this.$task_column,this.$container),this.$task_column_header=this.create_el({classes:"task-column-header",append_to:this.$task_column}),this.$task_column_header.textContent=this.options.task_column.header_text||"Task Name",this.$task_column_content=this.create_el({classes:"task-column-content",append_to:this.$task_column});const t=this.options.bar_height+this.options.padding,e=Math.max(this.tasks.length*t,this.grid_height-this.config.header_height);this.$task_column_content.style.minHeight=e+"px",this.$wrapper.style.setProperty("--gv-task-column-content-height",e+"px"),this.$container.style.setProperty("--gv-task-column-content-height",e+"px"),this.tasks.forEach(l=>{const f=this.options.bar_height+this.options.padding,u=this.create_el({classes:"task-row",append_to:this.$task_column_content});if(u.style.top=l._index*f-1+"px",u.style.height=f+"px",this.options.task_column.content&&typeof this.options.task_column.content=="function"){const b=this.options.task_column.content(l);typeof b=="string"?u.innerHTML=b:b instanceof HTMLElement&&u.appendChild(b)}else u.textContent=l.name,u.title=l.name;u.setAttribute("data-task-id",l.id)}),this.$task_column.style.width=this.options.task_column.width+"px",this.$task_column_resize_handle=this.create_el({classes:"task-column-resize-handle",append_to:this.$task_column}),this.options.isRTL?(_=(d=this.$wrapper)==null?void 0:d.classList)==null||_.add("rtl"):(p=(c=this.$wrapper)==null?void 0:c.classList)==null||p.remove("rtl")}make_grid_ticks(){if(this.options.lines==="none")return;let t=0,e=this.config.header_height,i=this.grid_height-this.config.header_height,s=w("g",{class:"lines_layer",append_to:this.layers.grid}),n=this.config.header_height;const r=this.dates.length*this.config.column_width,a=this.options.bar_height+this.options.padding;if(this.options.lines!=="vertical")for(let h=this.config.header_height;h<this.grid_height;h+=a)w("line",{x1:0,y1:n+a,x2:r,y2:n+a,class:"row-line",append_to:s}),n+=a;if(this.options.lines!=="horizontal")for(let h of this.dates){let d="tick";this.config.view_mode.thick_line&&this.config.view_mode.thick_line(h)&&(d+=" thick"),w("path",{d:`M ${t} ${e} v ${i}`,class:d,append_to:this.layers.grid}),this.view_is("month")?t+=g.get_days_in_month(h)*this.config.column_width/30:this.view_is("year")?t+=g.get_days_in_year(h)*this.config.column_width/365:t+=this.config.column_width}}highlight_holidays(){let t={};if(this.options.holidays)for(let e in this.options.holidays){let i=this.options.holidays[e];i==="weekend"&&(i=this.options.is_weekend);let s;if(typeof i=="object"){let n=i.find(r=>typeof r=="function");if(n&&(s=n),this.options.holidays.name){let r=new Date(i.date+" ");i=a=>r.getTime()===a.getTime(),t[r]=i.name}else i=r=>this.options.holidays[e].filter(a=>typeof a!="function").map(a=>{if(a.name){let h=new Date(a.date+" ");return t[h]=a.name,h.getTime()}return new Date(a+" ").getTime()}).includes(r.getTime())}for(let n=new Date(this.gantt_start);n<=this.gantt_end;n.setDate(n.getDate()+1))if(!(this.config.ignored_dates.find(r=>r.getTime()==n.getTime())||this.config.ignored_function&&this.config.ignored_function(n))&&(i(n)||s&&s(n))){const r=g.diff(n,this.gantt_start,this.config.unit)/this.config.step*this.config.column_width,a=this.grid_height-this.config.header_height,h=g.format(n,"YYYY-MM-DD",this.options.language).replace(" ","_");if(t[n]){let d=this.create_el({classes:"holiday-label label_"+h,append_to:this.$extras});d.textContent=t[n]}w("rect",{x:Math.round(r),y:this.config.header_height,width:this.config.column_width/g.convert_scales(this.config.view_mode.step,"day"),height:a,class:"holiday-highlight "+h,style:`fill: ${e};`,append_to:this.layers.grid})}}}highlight_current(){const t=this.get_closest_date();if(!t)return;const[e,i]=t;i.classList.add("current-date-highlight");const n=g.diff(new Date,this.gantt_start,this.config.unit)/this.config.step*this.config.column_width;this.$current_highlight=this.create_el({top:this.config.header_height,left:n,height:this.grid_height-this.config.header_height,classes:"current-highlight",append_to:this.$container}),this.$current_ball_highlight=this.create_el({top:this.config.header_height-6,left:n-2.5,width:6,height:6,classes:"current-ball-highlight",append_to:this.$header})}make_grid_highlights(){this.highlight_holidays(),this.config.ignored_positions=[];const t=(this.options.bar_height+this.options.padding)*this.tasks.length;this.layers.grid.innerHTML+=`<pattern id="diagonalHatch" patternUnits="userSpaceOnUse" width="4" height="4">
25
50
  <path d="M-1,1 l2,-2
26
51
  M0,4 l4,-4
27
52
  M3,5 l2,-2"
28
53
  style="stroke:grey; stroke-width:0.3" />
29
- </pattern>`;for(let i=new Date(this.gantt_start);i<=this.gantt_end;i.setDate(i.getDate()+1)){if(!this.config.ignored_dates.find(s=>s.getTime()==i.getTime())&&(!this.config.ignored_function||!this.config.ignored_function(i)))continue;let n=c.convert_scales(c.diff(i,this.gantt_start)+"d",this.config.unit)/this.config.step;this.config.ignored_positions.push(n*this.config.column_width),m("rect",{x:n*this.config.column_width,y:this.config.header_height,width:this.config.column_width,height:t,class:"ignored-bar",style:"fill: url(#diagonalHatch);",append_to:this.$svg})}this.highlight_current(this.config.view_mode)}create_el({left:t,top:e,width:i,height:n,id:s,classes:o,append_to:a,type:h}){let d=document.createElement(h||"div");for(let _ of o.split(" "))d.classList.add(_);return d.style.top=e+"px",d.style.left=t+"px",s&&(d.id=s),i&&(d.style.width=i+"px"),n&&(d.style.height=n+"px"),a&&a.appendChild(d),d}make_dates(){this.get_dates_to_draw().forEach((t,e)=>{if(t.lower_text){let i=this.create_el({left:t.x,top:t.lower_y,classes:"lower-text date_"+D(t.formatted_date),append_to:this.$lower_header});i.innerText=t.lower_text}if(t.upper_text){let i=this.create_el({left:t.x,top:t.upper_y,classes:"upper-text",append_to:this.$upper_header});i.innerText=t.upper_text}}),this.upperTexts=Array.from(this.$container.querySelectorAll(".upper-text"))}get_dates_to_draw(){let t=null;return this.dates.map((i,n)=>{const s=this.get_date_info(i,t,n);return t=s,s})}get_date_info(t,e){let i=e?e.date:null;this.config.column_width;const n=e?e.x+e.column_width:0;let s=this.config.view_mode.upper_text,o=this.config.view_mode.lower_text;return s?typeof s=="string"&&(this.config.view_mode.upper_text=a=>c.format(a,s,this.options.language)):this.config.view_mode.upper_text=()=>"",o?typeof o=="string"&&(this.config.view_mode.lower_text=a=>c.format(a,o,this.options.language)):this.config.view_mode.lower_text=()=>"",{date:t,formatted_date:D(c.format(t,this.config.date_format,this.options.language)),column_width:this.config.column_width,x:n,upper_text:this.config.view_mode.upper_text(t,i,this.options.language),lower_text:this.config.view_mode.lower_text(t,i,this.options.language),upper_y:17,lower_y:this.options.upper_header_height+5}}make_bars(){this.bars=this.tasks.map(t=>{if(t._has_no_dates)return null;const e=new q(this,t);return this.layers.bar.appendChild(e.group),e}).filter(t=>t!==null)}make_arrows(){this.arrows=[],this.options.critical_path&&this.calculate_critical_path();for(let t of this.tasks){let e=[];e=t.dependencies.map(i=>{const n=this.get_task(i);if(!n)return;const s=this.bars[n._index],o=this.bars[t._index];if(!s||!o)return;const a=new W(this,s,o);return this.layers.arrow.appendChild(a.element),a}).filter(Boolean),this.arrows=this.arrows.concat(e)}}calculate_critical_path(){this.tasks.forEach(s=>s._is_critical=!1);const t={};this.tasks.forEach(s=>{t[s.id]={es:0,ef:0,ls:0,lf:0}});const e=s=>{if(t[s.id].ef>0)return t[s.id];let o=0;s.dependencies&&s.dependencies.length>0&&s.dependencies.forEach(h=>{const d=this.get_task(h);if(d){const _=e(d);o=Math.max(o,_.ef)}}),t[s.id].es=o;const a=c.diff(s._end,s._start,"hour")/24;return t[s.id].ef=o+a,t[s.id]};this.tasks.forEach(s=>e(s));const i=Math.max(...Object.values(t).map(s=>s.ef)),n=s=>{if(t[s.id].ls>0||t[s.id].lf>0)return t[s.id];const o=this.tasks.filter(d=>d.dependencies&&d.dependencies.includes(s.id));let a=i;o.length>0&&o.forEach(d=>{const _=n(d);a=Math.min(a,_.ls)});const h=c.diff(s._end,s._start,"hour")/24;return t[s.id].lf=a,t[s.id].ls=a-h,t[s.id]};this.tasks.forEach(s=>n(s)),this.tasks.forEach(s=>{const o=t[s.id],a=o.ls-o.es;s._is_critical=Math.abs(a)<.01})}update_arrow_critical_path(){this.arrows.forEach(t=>{t.from_task.task._is_critical===!0&&t.to_task.task._is_critical===!0?t.element.classList.add("arrow-critical"):t.element.classList.remove("arrow-critical")})}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_dimensions(){const{width:t}=this.$svg.getBoundingClientRect(),e=this.$svg.querySelector(".grid .grid-row")?this.$svg.querySelector(".grid .grid-row").getAttribute("width"):0;t<e&&this.$svg.setAttribute("width",e)}set_scroll_position(t){if(this.options.infinite_padding&&(!t||t==="start")){let[o,...a]=this.get_start_end_positions();this.$container.scrollLeft=o;return}if(!t||t==="start")t=this.gantt_start;else if(t==="end")t=this.gantt_end;else{if(t==="today")return this.scroll_current();typeof t=="string"&&(t=c.parse(t))}const i=c.diff(t,this.gantt_start,this.config.unit)/this.config.step*this.config.column_width;this.$container.scrollTo({left:i-this.config.column_width/6,behavior:"smooth"}),this.$current&&this.$current.classList.remove("current-upper"),this.current_date=c.add(this.gantt_start,this.$container.scrollLeft/this.config.column_width,this.config.unit);let n=this.config.view_mode.upper_text(this.current_date,null,this.options.language),s=this.upperTexts.find(o=>o.textContent===n);this.current_date=c.add(this.gantt_start,(this.$container.scrollLeft+s.clientWidth)/this.config.column_width,this.config.unit),n=this.config.view_mode.upper_text(this.current_date,null,this.options.language),s=this.upperTexts.find(o=>o.textContent===n),s.classList.add("current-upper"),this.$current=s}scroll_current(){let t=this.get_closest_date();t&&this.set_scroll_position(t[0])}get_closest_date(){let t=new Date;if(t<this.gantt_start||t>this.gantt_end)return null;let e=new Date,i=this.$container.querySelector(".date_"+D(c.format(e,this.config.date_format,this.options.language))),n=0;for(;!i&&n<this.config.step;)e=c.add(e,-1,this.config.unit),i=this.$container.querySelector(".date_"+D(c.format(e,this.config.date_format,this.options.language))),n++;return[new Date(c.format(e,this.config.date_format,this.options.language)+" "),i]}bind_grid_click(){u.on(this.$container,"click",".grid-row, .grid-header, .ignored-bar, .holiday-highlight",(t,e)=>{if(e&&e.classList.contains("grid-row")){const i=this.$svg,n=i.createSVGPoint();n.x=t.clientX,n.y=t.clientY;const s=n.matrixTransform(i.getScreenCTM().inverse()),o=this.options.bar_height+this.options.padding,a=Math.floor((s.y-this.config.header_height)/o),h=this.tasks[a];if(h&&h._has_no_dates){const d=s.x/this.config.column_width,_=Math.floor(d*this.config.step),l=c.add(this.gantt_start,_,this.config.unit);h._start=l,h._end=c.add(l,1,"day"),h.start=l,h.end=h._end,delete h._has_no_dates,this.refresh(this.tasks,!0),this.trigger_event("date_change",[h,h._start,h._end]),this.trigger_event("after_date_change",[h,h._start,h._end]);return}}this.unselect_all(),this.hide_popup()})}bind_holiday_labels(){const t=this.$container.querySelectorAll(".holiday-highlight");for(let e of t){const i=this.$container.querySelector(".label_"+e.classList[1]);if(!i)continue;let n;e.onmouseenter=s=>{n=setTimeout(()=>{i.classList.add("show"),i.style.left=(s.offsetX||s.layerX)+"px",i.style.top=(s.offsetY||s.layerY)+"px"},300)},e.onmouseleave=s=>{clearTimeout(n),i.classList.remove("show")}}}get_start_end_positions(){if(!this.bars.length)return[0,0,0];let{x:t,width:e}=this.bars[0].group.getBBox(),i=t,n=t,s=t+e;return Array.prototype.forEach.call(this.bars,function({group:o},a){let{x:h,width:d}=o.getBBox();h<i&&(i=h),h>n&&(n=h),h+d>s&&(s=h+d)}),[i,n,s]}bind_bar_events(){let t=!1,e=0,i=0,n=!1,s=!1,o=null,a=[];this.bar_being_dragged=null;const h=()=>t||n||s;this.$svg.onclick=_=>{_.target.classList.contains("grid-row")&&this.unselect_all()};let d=0;if(u.on(this.$svg,"mousemove",".bar-wrapper, .handle",_=>{this.bar_being_dragged===!1&&Math.abs((_.offsetX||_.layerX)-d)>10&&(this.bar_being_dragged=!0)}),u.on(this.$svg,"mousedown",".bar-wrapper, .handle",(_,l)=>{const g=u.closest(".bar-wrapper",l);l.classList.contains("left")?(n=!0,l.classList.add("visible")):l.classList.contains("right")?(s=!0,l.classList.add("visible")):l.classList.contains("bar-wrapper")&&(t=!0),this.popup&&this.popup.hide(),e=_.offsetX||_.layerX,o=g.getAttribute("data-id");const w=this.get_bar(o).task.dependencies_type||this.options.dependencies_type;let f;this.options.move_dependencies&&w==="fixed"?f=[o,...this.get_all_dependent_tasks(o)]:f=[o],a=f.map(b=>this.get_bar(b)),this.bar_being_dragged=!1,d=e,a.forEach(b=>{const $=b.$bar;$.ox=$.getX(),$.oy=$.getY(),$.owidth=$.getWidth(),$.finaldx=0})}),this.options.infinite_padding){let _=!1;u.on(this.$container,"mousewheel",l=>{let g=this.$container.scrollWidth/2;if(!_&&l.currentTarget.scrollLeft<=g){let p=l.currentTarget.scrollLeft;_=!0,this.gantt_start=c.add(this.gantt_start,-this.config.extend_by_units,this.config.unit),this.setup_date_values(),this.render(),l.currentTarget.scrollLeft=p+this.config.column_width*this.config.extend_by_units,setTimeout(()=>_=!1,300)}if(!_&&l.currentTarget.scrollWidth-(l.currentTarget.scrollLeft+l.currentTarget.clientWidth)<=g){let p=l.currentTarget.scrollLeft;_=!0,this.gantt_end=c.add(this.gantt_end,this.config.extend_by_units,this.config.unit),this.setup_date_values(),this.render(),l.currentTarget.scrollLeft=p,setTimeout(()=>_=!1,300)}})}u.on(this.$container,"scroll",_=>{this.$task_column&&!this._syncing_scroll&&(this._syncing_scroll=!0,this.$task_column.scrollTop=_.currentTarget.scrollTop,requestAnimationFrame(()=>{this._syncing_scroll=!1}));let l=[];const g=this.bars.map(({group:k})=>k.getAttribute("data-id"));let p;i&&(p=_.currentTarget.scrollLeft-i),this.current_date=c.add(this.gantt_start,_.currentTarget.scrollLeft/this.config.column_width*this.config.step,this.config.unit);let w=this.config.view_mode.upper_text(this.current_date,null,this.options.language),f=this.upperTexts.find(k=>k.textContent===w);this.current_date=c.add(this.gantt_start,(_.currentTarget.scrollLeft+f.clientWidth)/this.config.column_width*this.config.step,this.config.unit),w=this.config.view_mode.upper_text(this.current_date,null,this.options.language),f=this.upperTexts.find(k=>k.textContent===w),f!==this.$current&&(this.$current&&this.$current.classList.remove("current-upper"),f.classList.add("current-upper"),this.$current=f),i=_.currentTarget.scrollLeft;let[b,$,N]=this.get_start_end_positions();i>N+100?(this.$adjust.innerHTML="&larr;",this.$adjust.classList.remove("hide"),this.$adjust.onclick=()=>{this.$container.scrollTo({left:$,behavior:"smooth"})}):i+_.currentTarget.offsetWidth<b-100?(this.$adjust.innerHTML="&rarr;",this.$adjust.classList.remove("hide"),this.$adjust.onclick=()=>{this.$container.scrollTo({left:b,behavior:"smooth"})}):this.$adjust.classList.add("hide"),p&&(l=g.map(k=>this.get_bar(k)),this.options.auto_move_label&&l.forEach(k=>{k.update_label_position_on_horizontal_scroll({x:p,sx:_.currentTarget.scrollLeft})}))}),u.on(this.$svg,"mousemove",_=>{if(!h())return;const l=(_.offsetX||_.layerX)-e;a.forEach(g=>{const p=g.$bar;p.finaldx=this.get_snap_position(l,p.ox),this.hide_popup(),n?o===g.task.id?g.update_bar_position({x:p.ox+p.finaldx,width:p.owidth-p.finaldx}):g.update_bar_position({x:p.ox+p.finaldx}):s?o===g.task.id&&g.update_bar_position({width:p.owidth+p.finaldx}):t&&!this.options.readonly&&!this.options.readonly_dates&&g.update_bar_position({x:p.ox+p.finaldx})})}),document.addEventListener("mouseup",()=>{var g,p,w;const _=this.bar_being_dragged===!0;this.bar_being_dragged=null;const l=[];a.forEach(f=>{if(!f.$bar.finaldx){_&&f.set_action_completed();return}f.date_changed(),f.compute_progress(),f.set_action_completed(),l.push({task:f.task,start:f.task._start,end:c.add(f.task._end,-1,"second")})}),this.options.critical_path&&a.some(f=>f.$bar.finaldx)&&(this.calculate_critical_path(),this.update_arrow_critical_path()),l.length>0&&l.forEach(({task:f,start:b,end:$})=>{this.trigger_event("after_date_change",[f,b,$])}),t=!1,n=!1,s=!1,(w=(p=(g=this.$container.querySelector(".visible"))==null?void 0:g.classList)==null?void 0:p.remove)==null||w.call(p,"visible")}),this.bind_bar_progress()}bind_task_column_resize(){if(!this.$task_column_resize_handle)return;let t=!1,e=0,i=0;const n=100,s=600;u.on(this.$task_column_resize_handle,"mousedown",o=>{t=!0,e=o.clientX,i=this.options.task_column.width,this.$task_column.classList.add("resizing"),o.preventDefault()}),u.on(document,"mousemove",o=>{if(!t)return;let a=o.clientX-e;this.options.isRTL&&(a=-a);let h=i+a;h=Math.max(n,Math.min(s,h)),this.options.task_column.width=h,this.$task_column.style.width=h+"px",this.$wrapper.style.setProperty("--gv-task-column-width",h+"px"),this.$container.style.setProperty("--gv-task-column-width",h+"px"),this.trigger_event("task_column_resize",[h])}),u.on(document,"mouseup",()=>{t&&(t=!1,this.$task_column.classList.remove("resizing"),this.trigger_event("task_after_column_resize",[this.options.task_column.width]))})}bind_task_column_scroll(){this.$task_column&&u.on(this.$task_column,"scroll",t=>{this._syncing_scroll||(this._syncing_scroll=!0,this.$container.scrollTop=t.currentTarget.scrollTop,requestAnimationFrame(()=>{this._syncing_scroll=!1}))})}bind_bar_progress(){let t=0,e=null,i=null,n=null,s=null;u.on(this.$svg,"mousedown",".handle.progress",(a,h)=>{e=!0,t=a.offsetX||a.layerX;const _=u.closest(".bar-wrapper",h).getAttribute("data-id");i=this.get_bar(_),n=i.$bar_progress,s=i.$bar,n.finaldx=0,n.owidth=n.getWidth(),n.min_dx=-n.owidth,n.max_dx=s.getWidth()-n.getWidth()});const o=this.config.ignored_positions.map(a=>[a,a+this.config.column_width]);u.on(this.$svg,"mousemove",a=>{if(!e)return;let h=a.offsetX||a.layerX;if(h>t){let l=o.find(([g,p])=>h>=g&&h<p);for(;l;)h=l[1],l=o.find(([g,p])=>h>=g&&h<p)}else{let l=o.find(([g,p])=>h>g&&h<=p);for(;l;)h=l[0],l=o.find(([g,p])=>h>g&&h<=p)}let _=h-t;console.log(n),_>n.max_dx&&(_=n.max_dx),_<n.min_dx&&(_=n.min_dx),n.setAttribute("width",n.owidth+_),u.attr(i.$handle_progress,"cx",n.getEndX()),n.finaldx=_}),u.on(this.$svg,"mouseup",()=>{e=!1,n&&n.finaldx&&(n.finaldx=0,i.progress_changed(),i.set_action_completed(),i=null,n=null,s=null)})}get_all_dependent_tasks(t){let e=[],i=[t];for(;i.length;){const n=i.reduce((s,o)=>(s=s.concat(this.dependency_map[o]),s),[]);e=e.concat(n),i=n.filter(s=>!i.includes(s))}return e.filter(Boolean)}update_dependent_tasks_by_type(t){const e=t.task.dependencies_type||this.options.dependencies_type,i=[];return e==="fixed"||(this.dependency_map[t.task.id]||[]).forEach(s=>{const o=this.get_bar(s);if(!o)return;const a=o.task,h=a.dependencies_type||this.options.dependencies_type;let d,_;const l=c.diff(a._end,a._start,"hour");let g=!1;switch(h){case"finish-to-start":t.task._end>a._start&&(d=new Date(t.task._end),_=c.add(d,l,"hour"),g=!0);break;case"start-to-start":t.task._start>a._start&&(d=new Date(t.task._start),_=c.add(d,l,"hour"),g=!0);break;case"finish-to-finish":t.task._end>a._end&&(_=new Date(t.task._end),d=c.add(_,-l,"hour"),g=!0);break;case"start-to-finish":t.task._start>a._end&&(_=new Date(t.task._start),d=c.add(_,-l,"hour"),g=!0);break;default:return}if(!g)return;a._start=d,a._end=_,o.compute_x(),o.compute_duration(),o.update_bar_position({x:o.x,width:o.width}),this.trigger_event("date_change",[a,d,c.add(_,-1,"second")]),i.push({task:a,start:d,end:c.add(_,-1,"second")});const p=this.update_dependent_tasks_by_type(o);i.push(...p)}),i}get_snap_position(t,e){let i=1;const n=this.options.snap_at||this.config.view_mode.snap_at||"1d";if(n!=="unit"){const{duration:_,scale:l}=c.parse_duration(n);i=c.convert_scales(this.config.view_mode.step,l)/_}const s=t%(this.config.column_width/i);let o=t-s+(s<this.config.column_width/i*2?0:this.config.column_width/i),a=e+o;const h=o>0?1:-1;let d=this.get_ignored_region(a,h);for(;d.length;)a+=this.config.column_width*h,d=this.get_ignored_region(a,h),d.length||(a-=this.config.column_width*h);return a-e}get_ignored_region(t,e=1){return e===1?this.config.ignored_positions.filter(i=>t>i&&t<=i+this.config.column_width):this.config.ignored_positions.filter(i=>t>=i&&t<i+this.config.column_width)}unselect_all(){this.popup&&this.popup.parent.classList.add("hide"),this.$container.querySelectorAll(".date-range-highlight").forEach(t=>t.classList.add("hide"))}view_is(t){return typeof t=="string"?this.config.view_mode.name===t:Array.isArray(t)?t.some(view_is):this.config.view_mode.name===t.name}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.options.popup!==!1&&(this.popup||(this.popup=new F(this.$popup_wrapper,this.options.popup,this)),this.popup.show(t))}hide_popup(){this.popup&&this.popup.hide()}trigger_event(t,e){this.options["on_"+t]&&this.options["on_"+t].apply(this,e)}get_oldest_starting_date(){return this.tasks.length?this.tasks.map(t=>t._start).reduce((t,e)=>e<=t?e:t):new Date}clear(){var t,e,i,n,s,o,a,h,d,_,l,g,p,w,f,b;this.$svg.innerHTML="",(e=(t=this.$header)==null?void 0:t.remove)==null||e.call(t),(n=(i=this.$side_header)==null?void 0:i.remove)==null||n.call(i),(o=(s=this.$task_column)==null?void 0:s.remove)==null||o.call(s),(h=(a=this.$current_highlight)==null?void 0:a.remove)==null||h.call(a),(_=(d=this.$extras)==null?void 0:d.remove)==null||_.call(d),(g=(l=this.popup)==null?void 0:l.hide)==null||g.call(l),(w=(p=this.$wrapper)==null?void 0:p.classList)==null||w.remove("has-task-column"),(b=(f=this.$wrapper)==null?void 0:f.classList)==null||b.remove("rtl")}}X.VIEW_MODE={HOUR:y[0],QUARTER_DAY:y[1],HALF_DAY:y[2],DAY:y[3],WEEK:y[4],MONTH:y[5],YEAR:y[6]};function I(r){return r.name+"_"+Math.random().toString(36).slice(2,12)}function D(r){return r.replaceAll(" ","_").replaceAll(":","_").replaceAll(".","_")}return X});
54
+ </pattern>`;for(let i=new Date(this.gantt_start);i<=this.gantt_end;i.setDate(i.getDate()+1)){if(!this.config.ignored_dates.find(n=>n.getTime()==i.getTime())&&(!this.config.ignored_function||!this.config.ignored_function(i)))continue;let s=g.convert_scales(g.diff(i,this.gantt_start)+"d",this.config.unit)/this.config.step;this.config.ignored_positions.push(s*this.config.column_width),w("rect",{x:s*this.config.column_width,y:this.config.header_height,width:this.config.column_width,height:t,class:"ignored-bar",style:"fill: url(#diagonalHatch);",append_to:this.$svg})}this.highlight_current(this.config.view_mode)}create_el({left:t,top:e,width:i,height:s,id:n,classes:r,append_to:a,type:h}){let d=document.createElement(h||"div");for(let _ of r.split(" "))d.classList.add(_);return d.style.top=e+"px",d.style.left=t+"px",n&&(d.id=n),i&&(d.style.width=i+"px"),s&&(d.style.height=s+"px"),a&&a.appendChild(d),d}make_dates(){this.get_dates_to_draw().forEach((t,e)=>{if(t.lower_text){let i=this.create_el({left:t.x,top:t.lower_y,classes:"lower-text date_"+D(t.formatted_date),append_to:this.$lower_header});i.innerText=t.lower_text}if(t.upper_text){let i=this.create_el({left:t.x,top:t.upper_y,classes:"upper-text",append_to:this.$upper_header});i.innerText=t.upper_text}}),this.upperTexts=Array.from(this.$container.querySelectorAll(".upper-text"))}get_dates_to_draw(){let t=null;return this.dates.map((i,s)=>{const n=this.get_date_info(i,t,s);return t=n,n})}get_date_info(t,e){let i=e?e.date:null;this.config.column_width;const s=e?e.x+e.column_width:0;let n=this.config.view_mode.upper_text,r=this.config.view_mode.lower_text;return n?typeof n=="string"&&(this.config.view_mode.upper_text=a=>g.format(a,n,this.options.language)):this.config.view_mode.upper_text=()=>"",r?typeof r=="string"&&(this.config.view_mode.lower_text=a=>g.format(a,r,this.options.language)):this.config.view_mode.lower_text=()=>"",{date:t,formatted_date:D(g.format(t,this.config.date_format,this.options.language)),column_width:this.config.column_width,x:s,upper_text:this.config.view_mode.upper_text(t,i,this.options.language),lower_text:this.config.view_mode.lower_text(t,i,this.options.language),upper_y:17,lower_y:this.options.upper_header_height+5}}make_bars(){this.bars=this.tasks.map(t=>{if(t._has_no_dates)return null;const e=new G(this,t);return this.layers.bar.appendChild(e.group),e}).filter(t=>t!==null)}make_arrows(){this.arrows=[],this.options.critical_path&&this.calculate_critical_path();for(let t of this.tasks){let e=[];e=t.dependencies.map(i=>{const s=this.get_task(i.id);if(!s)return;const n=this.bars[s._index],r=this.bars[t._index];if(!n||!r)return;const a=i.type||this.options.dependencies_type||"finish-to-start",h=new B(this,n,r,a);return this.layers.arrow.appendChild(h.element),this.layers.arrow.appendChild(h.hit_element),h}).filter(Boolean),this.arrows=this.arrows.concat(e)}}calculate_critical_path(){this.tasks.forEach(n=>n._is_critical=!1);const t={};this.tasks.forEach(n=>{t[n.id]={es:0,ef:0,ls:0,lf:0}});const e=n=>{if(t[n.id].ef>0)return t[n.id];let r=0;n.dependencies&&n.dependencies.length>0&&n.dependencies.forEach(h=>{const d=this.get_task(h.id);if(d){const _=e(d);r=Math.max(r,_.ef)}}),t[n.id].es=r;const a=g.diff(n._end,n._start,"hour")/24;return t[n.id].ef=r+a,t[n.id]};this.tasks.forEach(n=>e(n));const i=Math.max(...Object.values(t).map(n=>n.ef)),s=n=>{if(t[n.id].ls>0||t[n.id].lf>0)return t[n.id];const r=this.tasks.filter(d=>d.dependencies&&d.dependencies.some(_=>_.id===n.id));let a=i;r.length>0&&r.forEach(d=>{const _=s(d);a=Math.min(a,_.ls)});const h=g.diff(n._end,n._start,"hour")/24;return t[n.id].lf=a,t[n.id].ls=a-h,t[n.id]};this.tasks.forEach(n=>s(n)),this.tasks.forEach(n=>{const r=t[n.id],a=r.ls-r.es;n._is_critical=Math.abs(a)<.01})}update_arrow_critical_path(){this.arrows.forEach(t=>{t.from_task.task._is_critical===!0&&t.to_task.task._is_critical===!0?t.element.classList.add("arrow-critical"):t.element.classList.remove("arrow-critical")})}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_dimensions(){const{width:t}=this.$svg.getBoundingClientRect(),e=this.$svg.querySelector(".grid .grid-row")?this.$svg.querySelector(".grid .grid-row").getAttribute("width"):0;t<e&&this.$svg.setAttribute("width",e)}set_scroll_position(t){if(this.options.infinite_padding&&(!t||t==="start")){let[r,...a]=this.get_start_end_positions();this.$container.scrollLeft=r;return}if(!t||t==="start")t=this.gantt_start;else if(t==="end")t=this.gantt_end;else{if(t==="today")return this.scroll_current();typeof t=="string"&&(t=g.parse(t))}const i=g.diff(t,this.gantt_start,this.config.unit)/this.config.step*this.config.column_width;this.$container.scrollTo({left:i-this.config.column_width/6,behavior:"smooth"}),this.$current&&this.$current.classList.remove("current-upper"),this.current_date=g.add(this.gantt_start,this.$container.scrollLeft/this.config.column_width,this.config.unit);let s=this.config.view_mode.upper_text(this.current_date,null,this.options.language),n=this.upperTexts.find(r=>r.textContent===s);this.current_date=g.add(this.gantt_start,(this.$container.scrollLeft+n.clientWidth)/this.config.column_width,this.config.unit),s=this.config.view_mode.upper_text(this.current_date,null,this.options.language),n=this.upperTexts.find(r=>r.textContent===s),n.classList.add("current-upper"),this.$current=n}scroll_current(){let t=this.get_closest_date();t&&this.set_scroll_position(t[0])}get_closest_date(){let t=new Date;if(t<this.gantt_start||t>this.gantt_end)return null;let e=new Date,i=this.$container.querySelector(".date_"+D(g.format(e,this.config.date_format,this.options.language))),s=0;for(;!i&&s<this.config.step;)e=g.add(e,-1,this.config.unit),i=this.$container.querySelector(".date_"+D(g.format(e,this.config.date_format,this.options.language))),s++;return[new Date(g.format(e,this.config.date_format,this.options.language)+" "),i]}bind_grid_click(){m.on(this.$container,"click",".grid-row, .grid-header, .ignored-bar, .holiday-highlight",(t,e)=>{if(e&&e.classList.contains("grid-row")){const i=this.$svg,s=i.createSVGPoint();s.x=t.clientX,s.y=t.clientY;const n=s.matrixTransform(i.getScreenCTM().inverse()),r=this.options.bar_height+this.options.padding,a=Math.floor((n.y-this.config.header_height)/r),h=this.tasks[a];if(h&&h._has_no_dates){const d=n.x/this.config.column_width,_=Math.floor(d*this.config.step),c=g.add(this.gantt_start,_,this.config.unit);h._start=c,h._end=g.add(c,1,"day"),h.start=c,h.end=h._end,delete h._has_no_dates,this.refresh(this.tasks,!0),this.trigger_event("date_change",[h,h._start,h._end]),this.trigger_event("after_date_change",[h,h._start,h._end]);return}}this.unselect_all(),this.hide_popup()})}bind_holiday_labels(){const t=this.$container.querySelectorAll(".holiday-highlight");for(let e of t){const i=this.$container.querySelector(".label_"+e.classList[1]);if(!i)continue;let s;e.onmouseenter=n=>{s=setTimeout(()=>{i.classList.add("show"),i.style.left=(n.offsetX||n.layerX)+"px",i.style.top=(n.offsetY||n.layerY)+"px"},300)},e.onmouseleave=n=>{clearTimeout(s),i.classList.remove("show")}}}get_start_end_positions(){if(!this.bars.length)return[0,0,0];let{x:t,width:e}=this.bars[0].group.getBBox(),i=t,s=t,n=t+e;return Array.prototype.forEach.call(this.bars,function({group:r},a){let{x:h,width:d}=r.getBBox();h<i&&(i=h),h>s&&(s=h),h+d>n&&(n=h+d)}),[i,s,n]}bind_bar_events(){let t=!1,e=0,i=0,s=!1,n=!1,r=null,a=[];this.bar_being_dragged=null;const h=()=>t||s||n;this.$svg.onclick=_=>{_.target.classList.contains("grid-row")&&this.unselect_all()};let d=0;if(m.on(this.$svg,"mousemove",".bar-wrapper, .handle",_=>{this.bar_being_dragged===!1&&Math.abs((_.offsetX||_.layerX)-d)>10&&(this.bar_being_dragged=!0)}),m.on(this.$svg,"mousedown",".bar-wrapper, .handle",(_,c)=>{const p=m.closest(".bar-wrapper",c);c.classList.contains("left")?(s=!0,c.classList.add("visible")):c.classList.contains("right")?(n=!0,c.classList.add("visible")):c.classList.contains("bar-wrapper")&&(t=!0),this.popup&&this.popup.hide(),e=_.offsetX||_.layerX,r=p.getAttribute("data-id"),a=[this.get_bar(r)],this.bar_being_dragged=!1,d=e,a.forEach(l=>{const f=l.$bar;f.ox=f.getX(),f.oy=f.getY(),f.owidth=f.getWidth(),f.finaldx=0})}),this.options.infinite_padding){let _=!1;m.on(this.$container,"mousewheel",c=>{let p=this.$container.scrollWidth/2;if(!_&&c.currentTarget.scrollLeft<=p){let l=c.currentTarget.scrollLeft;_=!0,this.gantt_start=g.add(this.gantt_start,-this.config.extend_by_units,this.config.unit),this.setup_date_values(),this.render(),c.currentTarget.scrollLeft=l+this.config.column_width*this.config.extend_by_units,setTimeout(()=>_=!1,300)}if(!_&&c.currentTarget.scrollWidth-(c.currentTarget.scrollLeft+c.currentTarget.clientWidth)<=p){let l=c.currentTarget.scrollLeft;_=!0,this.gantt_end=g.add(this.gantt_end,this.config.extend_by_units,this.config.unit),this.setup_date_values(),this.render(),c.currentTarget.scrollLeft=l,setTimeout(()=>_=!1,300)}})}m.on(this.$container,"scroll",_=>{this.$task_column&&!this._syncing_scroll&&(this._syncing_scroll=!0,this.$task_column.scrollTop=_.currentTarget.scrollTop,requestAnimationFrame(()=>{this._syncing_scroll=!1}));let c=[];const p=this.bars.map(({group:$})=>$.getAttribute("data-id"));let l;i&&(l=_.currentTarget.scrollLeft-i),this.current_date=g.add(this.gantt_start,_.currentTarget.scrollLeft/this.config.column_width*this.config.step,this.config.unit);let f=this.config.view_mode.upper_text(this.current_date,null,this.options.language),u=this.upperTexts.find($=>$.textContent===f);this.current_date=g.add(this.gantt_start,(_.currentTarget.scrollLeft+u.clientWidth)/this.config.column_width*this.config.step,this.config.unit),f=this.config.view_mode.upper_text(this.current_date,null,this.options.language),u=this.upperTexts.find($=>$.textContent===f),u!==this.$current&&(this.$current&&this.$current.classList.remove("current-upper"),u.classList.add("current-upper"),this.$current=u),i=_.currentTarget.scrollLeft;let[b,y,k]=this.get_start_end_positions();i>k+100?(this.$adjust.innerHTML="&larr;",this.$adjust.classList.remove("hide"),this.$adjust.onclick=()=>{this.$container.scrollTo({left:y,behavior:"smooth"})}):i+_.currentTarget.offsetWidth<b-100?(this.$adjust.innerHTML="&rarr;",this.$adjust.classList.remove("hide"),this.$adjust.onclick=()=>{this.$container.scrollTo({left:b,behavior:"smooth"})}):this.$adjust.classList.add("hide"),l&&(c=p.map($=>this.get_bar($)),this.options.auto_move_label&&c.forEach($=>{$.update_label_position_on_horizontal_scroll({x:l,sx:_.currentTarget.scrollLeft})}))}),m.on(this.$svg,"mousemove",_=>{if(!h())return;const c=(_.offsetX||_.layerX)-e;a.forEach(p=>{const l=p.$bar;l.finaldx=this.get_snap_position(c,l.ox),this.hide_popup(),s?r===p.task.id?p.update_bar_position({x:l.ox+l.finaldx,width:l.owidth-l.finaldx}):p.update_bar_position({x:l.ox+l.finaldx}):n?r===p.task.id&&p.update_bar_position({width:l.owidth+l.finaldx}):t&&!this.options.readonly&&!this.options.readonly_dates&&p.update_bar_position({x:l.ox+l.finaldx})})}),document.addEventListener("mouseup",()=>{var p,l,f;const _=this.bar_being_dragged===!0;this.bar_being_dragged=null;const c=[];if(a.forEach(u=>{if(!u.$bar.finaldx){_&&u.set_action_completed();return}u.date_changed(),u.compute_progress(),u.set_action_completed(),c.push({task:u.task,start:u.task._start,end:g.add(u.task._end,-1,"second")})}),this.options.critical_path&&a.some(u=>u.$bar.finaldx)&&(this.calculate_critical_path(),this.update_arrow_critical_path()),c.length>0&&this.options.dependency_shifting!=="none"){const u=this.options.dependency_shifting;let b;s?b=u==="maintain_buffer_downstream"?"none":"upstream":n?b="downstream":b=u==="maintain_buffer_downstream"?"downstream":"both",c.forEach(({task:y})=>{if(b==="none")return;const k=a.find(C=>C.task.id===y.id);if(!k||!k.$bar.finaldx)return;const $=k.$bar.finaldx/this.config.column_width,K=this.config.unit==="hour"?36e5:this.config.unit==="day"?864e5:this.config.unit==="month"?30*864e5:this.config.unit==="year"?365*864e5:864e5,J=$*this.config.step*K;N(this.tasks,y.id,J,this.options.dependency_shifting,b).forEach((C,Z)=>{const T=this.get_bar(Z);if(!T)return;const A=T.task,tt=new Date(A._start.getTime()+C),et=g.diff(tt,this.gantt_start,this.config.unit)/this.config.step*this.config.column_width;T.update_bar_position({x:et}),T.update_arrow_position(),this.trigger_event("after_date_change",[A,A._start,g.add(A._end,-1,"second")])})})}c.length>0&&c.forEach(({task:u,start:b,end:y})=>{this.trigger_event("after_date_change",[u,b,y])}),a.forEach(u=>{u.$bar.finaldx=0}),t=!1,s=!1,n=!1,(f=(l=(p=this.$container.querySelector(".visible"))==null?void 0:p.classList)==null?void 0:l.remove)==null||f.call(l,"visible")}),this.bind_bar_progress()}bind_task_column_resize(){if(!this.$task_column_resize_handle)return;let t=!1,e=0,i=0;const s=100,n=600;m.on(this.$task_column_resize_handle,"mousedown",r=>{t=!0,e=r.clientX,i=this.options.task_column.width,this.$task_column.classList.add("resizing"),r.preventDefault()}),m.on(document,"mousemove",r=>{if(!t)return;let a=r.clientX-e;this.options.isRTL&&(a=-a);let h=i+a;h=Math.max(s,Math.min(n,h)),this.options.task_column.width=h,this.$task_column.style.width=h+"px",this.$wrapper.style.setProperty("--gv-task-column-width",h+"px"),this.$container.style.setProperty("--gv-task-column-width",h+"px"),this.trigger_event("task_column_resize",[h])}),m.on(document,"mouseup",()=>{t&&(t=!1,this.$task_column.classList.remove("resizing"),this.trigger_event("task_after_column_resize",[this.options.task_column.width]))})}bind_task_column_scroll(){this.$task_column&&m.on(this.$task_column,"scroll",t=>{this._syncing_scroll||(this._syncing_scroll=!0,this.$container.scrollTop=t.currentTarget.scrollTop,requestAnimationFrame(()=>{this._syncing_scroll=!1}))})}bind_bar_progress(){let t=0,e=null,i=null,s=null,n=null;m.on(this.$svg,"mousedown",".handle.progress",(a,h)=>{e=!0,t=a.offsetX||a.layerX;const _=m.closest(".bar-wrapper",h).getAttribute("data-id");i=this.get_bar(_),s=i.$bar_progress,n=i.$bar,s.finaldx=0,s.owidth=s.getWidth(),s.min_dx=-s.owidth,s.max_dx=n.getWidth()-s.getWidth()});const r=this.config.ignored_positions.map(a=>[a,a+this.config.column_width]);m.on(this.$svg,"mousemove",a=>{if(!e)return;let h=a.offsetX||a.layerX;if(h>t){let c=r.find(([p,l])=>h>=p&&h<l);for(;c;)h=c[1],c=r.find(([p,l])=>h>=p&&h<l)}else{let c=r.find(([p,l])=>h>p&&h<=l);for(;c;)h=c[0],c=r.find(([p,l])=>h>p&&h<=l)}let _=h-t;console.log(s),_>s.max_dx&&(_=s.max_dx),_<s.min_dx&&(_=s.min_dx),s.setAttribute("width",s.owidth+_),m.attr(i.$handle_progress,"cx",s.getEndX()),s.finaldx=_}),m.on(this.$svg,"mouseup",()=>{e=!1,s&&s.finaldx&&(s.finaldx=0,i.progress_changed(),i.set_action_completed(),i=null,s=null,n=null)})}get_all_dependent_tasks(t){let e=[],i=[t];for(;i.length;){const s=i.reduce((n,r)=>(n=n.concat(this.dependency_map[r]),n),[]);e=e.concat(s),i=s.filter(n=>!i.includes(n))}return e.filter(Boolean)}get_snap_position(t,e){let i=1;const s=this.options.snap_at||this.config.view_mode.snap_at||"1d";if(s!=="unit"){const{duration:_,scale:c}=g.parse_duration(s);i=g.convert_scales(this.config.view_mode.step,c)/_}const n=t%(this.config.column_width/i);let r=t-n+(n<this.config.column_width/i*2?0:this.config.column_width/i),a=e+r;const h=r>0?1:-1;let d=this.get_ignored_region(a,h);for(;d.length;)a+=this.config.column_width*h,d=this.get_ignored_region(a,h),d.length||(a-=this.config.column_width*h);return a-e}get_ignored_region(t,e=1){return e===1?this.config.ignored_positions.filter(i=>t>i&&t<=i+this.config.column_width):this.config.ignored_positions.filter(i=>t>=i&&t<i+this.config.column_width)}unselect_all(){this.popup&&this.popup.parent.classList.add("hide"),this.$container.querySelectorAll(".date-range-highlight").forEach(t=>t.classList.add("hide"))}view_is(t){return typeof t=="string"?this.config.view_mode.name===t:Array.isArray(t)?t.some(view_is):this.config.view_mode.name===t.name}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.options.popup!==!1&&(this.popup||(this.popup=new I(this.$popup_wrapper,this.options.popup,this)),this.popup.show(t))}hide_popup(){this.popup&&this.popup.hide()}trigger_event(t,e){this.options["on_"+t]&&this.options["on_"+t].apply(this,e)}get_oldest_starting_date(){return this.tasks.length?this.tasks.map(t=>t._start).reduce((t,e)=>e<=t?e:t):new Date}clear(){var t,e,i,s,n,r,a,h,d,_,c,p,l,f,u,b;this.$svg.innerHTML="",(e=(t=this.$header)==null?void 0:t.remove)==null||e.call(t),(s=(i=this.$side_header)==null?void 0:i.remove)==null||s.call(i),(r=(n=this.$task_column)==null?void 0:n.remove)==null||r.call(n),(h=(a=this.$current_highlight)==null?void 0:a.remove)==null||h.call(a),(_=(d=this.$extras)==null?void 0:d.remove)==null||_.call(d),(p=(c=this.popup)==null?void 0:c.hide)==null||p.call(c),(f=(l=this.$wrapper)==null?void 0:l.classList)==null||f.remove("has-task-column"),(b=(u=this.$wrapper)==null?void 0:u.classList)==null||b.remove("rtl")}}P.VIEW_MODE={HOUR:x[0],QUARTER_DAY:x[1],HALF_DAY:x[2],DAY:x[3],WEEK:x[4],MONTH:x[5],YEAR:x[6]};function Q(o){return o.name+"_"+Math.random().toString(36).slice(2,12)}function D(o){return o.replaceAll(" ","_").replaceAll(":","_").replaceAll(".","_")}return P});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@workiom/frappe-gantt",
3
- "version": "1.0.19",
3
+ "version": "1.0.21",
4
4
  "description": "A simple, modern, interactive gantt library for the web",
5
5
  "main": "src/index.js",
6
6
  "type": "module",