@workiom/frappe-gantt 1.0.26 → 1.0.27

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,38 +1,38 @@
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",A="hour",H="minute",Y="second",F="millisecond",g={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,s;const n=r.split(" ");i=n[0].split(t).map(o=>parseInt(o,10)),s=n[1]&&n[1].split(e),i[1]=i[1]?i[1]-1:0;let a=i;return s&&s.length&&(s.length===4&&(s[3]="0."+s[3],s[3]=parseFloat(s[3])*1e3),a=a.concat(s)),new Date(...a)}},to_string(r,t=!1){if(!(r instanceof Date))throw new TypeError("Invalid argument type");const e=this.get_date_values(r).map((n,a)=>(a===1&&(n=n+1),a===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(r,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(r),a=n.charAt(0).toUpperCase()+n.slice(1),o=this.get_date_values(r).map(l=>L(l,2,0)),d={YYYY:o[0],MM:L(+o[1]+1,2,0),DD:o[2],HH:o[3],mm:o[4],ss:o[5],SSS:o[6],D:o[2],MMMM:a,MMM:s.format(r)};let h=t;const _=[];return Object.keys(d).sort((l,p)=>p.length-l.length).forEach(l=>{h.includes(l)&&(h=h.replaceAll(l,`$${_.length}`),_.push(d[l]))}),_.forEach((l,p)=>{h=h.replaceAll(`$${p}`,l)}),h},diff(r,t,e="day"){let i,s,n,a,o,d,h;i=r-t+(t.getTimezoneOffset()-r.getTimezoneOffset())*6e4,s=i/1e3,a=s/60,n=a/60,o=n/24;let _=r.getFullYear()-t.getFullYear(),l=r.getMonth()-t.getMonth();return l+=o%30/30,d=_*12+l,r.getDate()<t.getDate()&&d--,h=d/12,e.endsWith("s")||(e+="s"),Math.round({milliseconds:i,seconds:s,minutes:a,hours:n,days:o,months:d,years:h}[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===M?t:0),r.getDate()+(e===E?t:0),r.getHours()+(e===A?t:0),r.getMinutes()+(e===H?t:0),r.getSeconds()+(e===Y?t:0),r.getMilliseconds()+(e===F?t:0)];return new Date(...i)},start_of(r,t){const e={[v]:6,[M]:5,[E]:4,[A]:3,[H]:2,[Y]:1,[F]:0};function i(n){const a=e[t];return e[n]<=a}const s=[r.getFullYear(),i(v)?0:r.getMonth(),i(M)?1:r.getDate(),i(E)?0:r.getHours(),i(A)?0:r.getMinutes(),i(H)?0:r.getSeconds(),i(Y)?0:r.getMilliseconds()];return new Date(...s)},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:s}=this.parse_duration(r);return i*e[s]/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 L(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 w(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 X(r,t,e,i){const s=V(r,t,e,i);if(s===r){const n=document.createEvent("HTMLEvents");n.initEvent("click",!0,!0),n.eventName="click",s.dispatchEvent(n)}}function V(r,t,e,i,s="0.4s",n="0.1s"){const a=r.querySelector("animate");if(a)return u.attr(a,{attributeName:t,from:e,to:i,dur:s,begin:"click + "+n}),r;const o=w("animate",{attributeName:t,from:e,to:i,dur:s,begin:n,calcMode:"spline",values:e+";"+i,keyTimes:"0; 1",keySplines:N("ease-out")});return r.appendChild(o),r}function N(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(s){const n=s.target.closest(e);n&&(s.delegatedTarget=n,i.call(this,s,n))})},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)};function O(r,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,a=new Map,o=new Map;for(const d of r)d._has_no_dates||(n.set(d.id,d),a.set(d.id,[]),o.set(d.id,[]));for(const d of r)if(!d._has_no_dates)for(const h of d.dependencies||[]){if(!n.has(h.id))continue;const _=h.type||"finish-to-start";a.get(d.id).push({id:h.id,type:_}),o.get(h.id).push({id:d.id,type:_})}return i==="maintain_buffer_all"||i==="maintain_buffer_downstream"?q(t,e,a,o,s==="both",s==="upstream"):i==="consume_buffer"?j(t,e,n,a,o,s):new Map}function q(r,t,e,i,s,n){const a=new Map,o=new Set([r]),d=[],h=_=>{for(const{id:l}of _)o.has(l)||(o.add(l),d.push(l))};for(n&&!s?h(e.get(r)||[]):(h(i.get(r)||[]),s&&h(e.get(r)||[]));d.length>0;){const _=d.shift();a.set(_,t),n&&!s?h(e.get(_)||[]):(h(i.get(_)||[]),s&&h(e.get(_)||[]))}return a}function j(r,t,e,i,s,n){const a=new Map;for(const[c]of e)a.set(c,(i.get(c)||[]).length);const o=[],d=[];for(const[c,m]of a)m===0&&d.push(c);for(;d.length>0;){const c=d.shift();o.push(c);for(const{id:m}of s.get(c)||[]){const f=a.get(m)-1;a.set(m,f),f===0&&d.push(m)}}const h=new Map([[r,0]]),_=c=>e.get(c)._start.getTime()+(h.get(c)||0),l=c=>e.get(c)._end.getTime()+(h.get(c)||0);if(n==="downstream"||n==="both")for(const c of o){if(c===r)continue;let m=0;for(const{id:f,type:b}of i.get(c)||[]){const y=W(f,c,b,_,l);y>m&&(m=y)}m>0&&h.set(c,(h.get(c)||0)+m)}if(n==="upstream"||n==="both")for(let c=o.length-1;c>=0;c--){const m=o[c];if(m===r)continue;let f=0;for(const{id:b,type:y}of s.get(m)||[]){const k=W(m,b,y,_,l);if(k>0){const $=-k;$<f&&(f=$)}}f<0&&h.set(m,(h.get(m)||0)+f)}const p=new Map;for(const[c,m]of h)c!==r&&m!==0&&p.set(c,m);return p}function W(r,t,e,i,s){const n=i(r),a=s(r),o=i(t),d=s(t);switch(e){case"finish-to-start":return a>o?a-o:0;case"start-to-start":return n>o?n-o:0;case"finish-to-finish":return a>d?a-d:0;case"start-to-finish":return n>d?n-d:0;default:return a>o?a-o:0}}class R{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.is_active=!1,this.type_dropdown=null,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(),a=this.from_task.$bar.getX(),o=this.to_task.$bar.getX()+this.to_task.$bar.getWidth(),d=this.to_task.$bar.getX(),h=c=>e.header_height+t.bar_height/2+(t.padding+t.bar_height)*c.task._index+t.padding/2,_=h(this.from_task),l=h(this.to_task),p=(_+l)/2;switch(this.dependency_type){case"finish-to-start":this.path=this._path_finish_to_start(n,a,o,d,_,l,p,s,i),this.label_pos={x:d,y:l,side:"left"};break;case"start-to-start":this.path=this._path_start_to_start(a,d,_,l,s,i),this.label_pos={x:d,y:l,side:"left"};break;case"finish-to-finish":this.path=this._path_finish_to_finish(n,o,_,l,s,i),this.label_pos={x:o,y:l,side:"right"};break;case"start-to-finish":this.path=this._path_start_to_finish(a,o,_,l,p,s,i),this.label_pos={x:o,y:l,side:"right"};break;default:this.path=this._path_finish_to_start(n,a,o,d,_,l,p,s,i),this.label_pos={x:d,y:l,side:"left"}}}_path_finish_to_start(t,e,i,s,n,a,o,d,h){const _=t+d,l=a<n;if(_<s)return l?`
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",S="day",A="hour",H="minute",Y="second",F="millisecond",g={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,s;const n=r.split(" ");i=n[0].split(t).map(o=>parseInt(o,10)),s=n[1]&&n[1].split(e),i[1]=i[1]?i[1]-1:0;let a=i;return s&&s.length&&(s.length===4&&(s[3]="0."+s[3],s[3]=parseFloat(s[3])*1e3),a=a.concat(s)),new Date(...a)}},to_string(r,t=!1){if(!(r instanceof Date))throw new TypeError("Invalid argument type");const e=this.get_date_values(r).map((n,a)=>(a===1&&(n=n+1),a===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(r,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(r),a=n.charAt(0).toUpperCase()+n.slice(1),o=this.get_date_values(r).map(l=>L(l,2,0)),h={YYYY:o[0],MM:L(+o[1]+1,2,0),DD:o[2],HH:o[3],mm:o[4],ss:o[5],SSS:o[6],D:o[2],MMMM:a,MMM:s.format(r)};let d=t;const _=[];return Object.keys(h).sort((l,c)=>c.length-l.length).forEach(l=>{d.includes(l)&&(d=d.replaceAll(l,`$${_.length}`),_.push(h[l]))}),_.forEach((l,c)=>{d=d.replaceAll(`$${c}`,l)}),d},diff(r,t,e="day"){let i,s,n,a,o,h,d;i=r-t+(t.getTimezoneOffset()-r.getTimezoneOffset())*6e4,s=i/1e3,a=s/60,n=a/60,o=n/24;let _=r.getFullYear()-t.getFullYear(),l=r.getMonth()-t.getMonth();return l+=o%30/30,h=_*12+l,r.getDate()<t.getDate()&&h--,d=h/12,e.endsWith("s")||(e+="s"),Math.round({milliseconds:i,seconds:s,minutes:a,hours:n,days:o,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===M?t:0),r.getDate()+(e===S?t:0),r.getHours()+(e===A?t:0),r.getMinutes()+(e===H?t:0),r.getSeconds()+(e===Y?t:0),r.getMilliseconds()+(e===F?t:0)];return new Date(...i)},start_of(r,t){const e={[v]:6,[M]:5,[S]:4,[A]:3,[H]:2,[Y]:1,[F]:0};function i(n){const a=e[t];return e[n]<=a}const s=[r.getFullYear(),i(v)?0:r.getMonth(),i(M)?1:r.getDate(),i(S)?0:r.getHours(),i(A)?0:r.getMinutes(),i(H)?0:r.getSeconds(),i(Y)?0:r.getMilliseconds()];return new Date(...s)},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:s}=this.parse_duration(r);return i*e[s]/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 L(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 m(r,t){return typeof r=="string"?(t||document).querySelector(r):r||null}function w(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 X(r,t,e,i){const s=V(r,t,e,i);if(s===r){const n=document.createEvent("HTMLEvents");n.initEvent("click",!0,!0),n.eventName="click",s.dispatchEvent(n)}}function V(r,t,e,i,s="0.4s",n="0.1s"){const a=r.querySelector("animate");if(a)return m.attr(a,{attributeName:t,from:e,to:i,dur:s,begin:"click + "+n}),r;const o=w("animate",{attributeName:t,from:e,to:i,dur:s,begin:n,calcMode:"spline",values:e+";"+i,keyTimes:"0; 1",keySplines:N("ease-out")});return r.appendChild(o),r}function N(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]}m.on=(r,t,e,i)=>{i?m.delegate(r,t,e,i):(i=e,m.bind(r,t,i))},m.off=(r,t,e)=>{r.removeEventListener(t,e)},m.bind=(r,t,e)=>{t.split(/\s+/).forEach(function(i){r.addEventListener(i,e)})},m.delegate=(r,t,e,i)=>{r.addEventListener(t,function(s){const n=s.target.closest(e);n&&(s.delegatedTarget=n,i.call(this,s,n))})},m.closest=(r,t)=>t?t.matches(r)?t:m.closest(r,t.parentNode):null,m.attr=(r,t,e)=>{if(!e&&typeof t=="string")return r.getAttribute(t);if(typeof t=="object"){for(let i in t)m.attr(r,i,t[i]);return}r.setAttribute(t,e)};function O(r,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,a=new Map,o=new Map;for(const h of r)h._has_no_dates||(n.set(h.id,h),a.set(h.id,[]),o.set(h.id,[]));for(const h of r)if(!h._has_no_dates)for(const d of h.dependencies||[]){if(!n.has(d.id))continue;const _=d.type||"finish-to-start";a.get(h.id).push({id:d.id,type:_}),o.get(d.id).push({id:h.id,type:_})}return i==="maintain_buffer_all"||i==="maintain_buffer_downstream"?q(t,e,a,o,s==="both",s==="upstream"):i==="consume_buffer"?j(t,e,n,a,o,s):new Map}function q(r,t,e,i,s,n){const a=new Map,o=new Set([r]),h=[],d=_=>{for(const{id:l}of _)o.has(l)||(o.add(l),h.push(l))};for(n&&!s?d(e.get(r)||[]):(d(i.get(r)||[]),s&&d(e.get(r)||[]));h.length>0;){const _=h.shift();a.set(_,t),n&&!s?d(e.get(_)||[]):(d(i.get(_)||[]),s&&d(e.get(_)||[]))}return a}function j(r,t,e,i,s,n){const a=new Map;for(const[p]of e)a.set(p,(i.get(p)||[]).length);const o=[],h=[];for(const[p,f]of a)f===0&&h.push(p);for(;h.length>0;){const p=h.shift();o.push(p);for(const{id:f}of s.get(p)||[]){const u=a.get(f)-1;a.set(f,u),u===0&&h.push(f)}}const d=new Map([[r,0]]),_=p=>e.get(p)._start.getTime()+(d.get(p)||0),l=p=>e.get(p)._end.getTime()+(d.get(p)||0);if(n==="downstream"||n==="both")for(const p of o){if(p===r)continue;let f=0;for(const{id:u,type:b}of i.get(p)||[]){const $=W(u,p,b,_,l);$>f&&(f=$)}f>0&&d.set(p,(d.get(p)||0)+f)}if(n==="upstream"||n==="both")for(let p=o.length-1;p>=0;p--){const f=o[p];if(f===r)continue;let u=0;for(const{id:b,type:$}of s.get(f)||[]){const k=W(f,b,$,_,l);if(k>0){const y=-k;y<u&&(u=y)}}u<0&&d.set(f,(d.get(f)||0)+u)}const c=new Map;for(const[p,f]of d)p!==r&&f!==0&&c.set(p,f);return c}function W(r,t,e,i,s){const n=i(r),a=s(r),o=i(t),h=s(t);switch(e){case"finish-to-start":return a>o?a-o:0;case"start-to-start":return n>o?n-o:0;case"finish-to-finish":return a>h?a-h:0;case"start-to-finish":return n>h?n-h:0;default:return a>o?a-o:0}}class R{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.is_active=!1,this.type_dropdown=null,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(),a=this.from_task.$bar.getX(),o=this.to_task.$bar.getX()+this.to_task.$bar.getWidth(),h=this.to_task.$bar.getX(),d=p=>e.header_height+t.bar_height/2+(t.padding+t.bar_height)*p.task._index+t.padding/2,_=d(this.from_task),l=d(this.to_task),c=(_+l)/2;switch(this.dependency_type){case"finish-to-start":this.path=this._path_finish_to_start(n,a,o,h,_,l,c,s,i),this.label_pos={x:h,y:l,side:"left"};break;case"start-to-start":this.path=this._path_start_to_start(a,h,_,l,s,i),this.label_pos={x:h,y:l,side:"left"};break;case"finish-to-finish":this.path=this._path_finish_to_finish(n,o,_,l,s,i),this.label_pos={x:o,y:l,side:"right"};break;case"start-to-finish":this.path=this._path_start_to_finish(a,o,_,l,c,s,i),this.label_pos={x:o,y:l,side:"right"};break;default:this.path=this._path_finish_to_start(n,a,o,h,_,l,c,s,i),this.label_pos={x:h,y:l,side:"left"}}}_path_finish_to_start(t,e,i,s,n,a,o,h,d){const _=t+h,l=a<n;if(_<s)return l?`
2
2
  M ${t} ${n}
3
- H ${_-h}
4
- a ${h} ${h} 0 0 0 ${h} ${-h}
5
- V ${a+h}
6
- a ${h} ${h} 0 0 1 ${h} ${-h}
3
+ H ${_-d}
4
+ a ${d} ${d} 0 0 0 ${d} ${-d}
5
+ V ${a+d}
6
+ a ${d} ${d} 0 0 1 ${d} ${-d}
7
7
  H ${s}
8
8
  m -5 -5 l 5 5 l -5 5`:`
9
9
  M ${t} ${n}
10
- H ${_-h}
11
- a ${h} ${h} 0 0 1 ${h} ${h}
12
- V ${a-h}
13
- a ${h} ${h} 0 0 0 ${h} ${h}
10
+ H ${_-d}
11
+ a ${d} ${d} 0 0 1 ${d} ${d}
12
+ V ${a-d}
13
+ a ${d} ${d} 0 0 0 ${d} ${d}
14
14
  H ${s}
15
- m -5 -5 l 5 5 l -5 5`;const p=s-d;return l?`
15
+ m -5 -5 l 5 5 l -5 5`;const c=s-h;return l?`
16
16
  M ${t} ${n}
17
- H ${_-h}
18
- a ${h} ${h} 0 0 0 ${h} ${-h}
19
- V ${o+h}
20
- a ${h} ${h} 0 0 0 ${-h} ${-h}
21
- H ${p+h}
22
- a ${h} ${h} 0 0 1 ${-h} ${-h}
23
- V ${a+h}
24
- a ${h} ${h} 0 0 1 ${h} ${-h}
17
+ H ${_-d}
18
+ a ${d} ${d} 0 0 0 ${d} ${-d}
19
+ V ${o+d}
20
+ a ${d} ${d} 0 0 0 ${-d} ${-d}
21
+ H ${c+d}
22
+ a ${d} ${d} 0 0 1 ${-d} ${-d}
23
+ V ${a+d}
24
+ a ${d} ${d} 0 0 1 ${d} ${-d}
25
25
  H ${s}
26
26
  m -5 -5 l 5 5 l -5 5`:`
27
27
  M ${t} ${n}
28
- H ${_-h}
29
- a ${h} ${h} 0 0 1 ${h} ${h}
30
- V ${o-h}
31
- a ${h} ${h} 0 0 1 ${-h} ${h}
32
- H ${p+h}
33
- a ${h} ${h} 0 0 0 ${-h} ${h}
34
- V ${a-h}
35
- a ${h} ${h} 0 0 0 ${h} ${h}
28
+ H ${_-d}
29
+ a ${d} ${d} 0 0 1 ${d} ${d}
30
+ V ${o-d}
31
+ a ${d} ${d} 0 0 1 ${-d} ${d}
32
+ H ${c+d}
33
+ a ${d} ${d} 0 0 0 ${-d} ${d}
34
+ V ${a-d}
35
+ a ${d} ${d} 0 0 0 ${d} ${d}
36
36
  H ${s}
37
37
  m -5 -5 l 5 5 l -5 5`}_path_start_to_start(t,e,i,s,n,a){const o=Math.min(t,e)-n;return s<i?`
38
38
  M ${t} ${i}
@@ -62,50 +62,50 @@
62
62
  V ${s-a}
63
63
  a ${a} ${a} 0 0 1 ${-a} ${a}
64
64
  H ${e}
65
- m 5 -5 l -5 5 l 5 5`}_path_start_to_finish(t,e,i,s,n,a,o){const d=t-a,h=e+a,_=s<i;return h<d+2*o?_?`
65
+ m 5 -5 l -5 5 l 5 5`}_path_start_to_finish(t,e,i,s,n,a,o){const h=t-a,d=e+a,_=s<i;return d<h+2*o?_?`
66
66
  M ${t} ${i}
67
- H ${d+o}
67
+ H ${h+o}
68
68
  a ${o} ${o} 0 0 1 ${-o} ${-o}
69
69
  V ${s+o}
70
70
  a ${o} ${o} 0 0 0 ${-o} ${-o}
71
71
  H ${e}
72
72
  m 5 -5 l -5 5 l 5 5`:`
73
73
  M ${t} ${i}
74
- H ${d+o}
74
+ H ${h+o}
75
75
  a ${o} ${o} 0 0 0 ${-o} ${o}
76
76
  V ${s-o}
77
77
  a ${o} ${o} 0 0 1 ${-o} ${o}
78
78
  H ${e}
79
79
  m 5 -5 l -5 5 l 5 5`:_?`
80
80
  M ${t} ${i}
81
- H ${d+o}
81
+ H ${h+o}
82
82
  a ${o} ${o} 0 0 1 ${-o} ${-o}
83
83
  V ${n+o}
84
84
  a ${o} ${o} 0 0 1 ${o} ${-o}
85
- H ${h-o}
85
+ H ${d-o}
86
86
  a ${o} ${o} 0 0 0 ${o} ${-o}
87
87
  V ${s+o}
88
88
  a ${o} ${o} 0 0 0 ${-o} ${-o}
89
89
  H ${e}
90
90
  m 5 -5 l -5 5 l 5 5`:`
91
91
  M ${t} ${i}
92
- H ${d+o}
92
+ H ${h+o}
93
93
  a ${o} ${o} 0 0 0 ${-o} ${o}
94
94
  V ${n-o}
95
95
  a ${o} ${o} 0 0 0 ${o} ${o}
96
- H ${h-o}
96
+ H ${d-o}
97
97
  a ${o} ${o} 0 0 1 ${o} ${o}
98
98
  V ${s-o}
99
99
  a ${o} ${o} 0 0 1 ${-o} ${o}
100
100
  H ${e}
101
- 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._show_label()}),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"),this.is_active||i.classList.remove("bar-arrow-critical","bar-arrow-invalid"))}),!this.is_active&&!this.is_hovered&&this._hide_label()}),this.hit_element.addEventListener("click",e=>{e.stopPropagation(),this.is_active?this.gantt.set_active_arrow(null):this.gantt.set_active_arrow(this)})}_get_type_abbr(){return{"finish-to-start":"FS","start-to-start":"SS","finish-to-finish":"FF","start-to-finish":"SF"}[this.dependency_type]||"FS"}_show_label(){if(this.label_element)return;const t=this._get_type_abbr(),e=21,i=20,{x:s,y:n,side:a}=this.label_pos,o=a==="left"?s-10-e/2:s+10+e/2,d=n;this.label_element=w("g",{class:"arrow-type-label"});const h=w("rect",{x:o-e/2,y:d-i/2,width:e,height:i,rx:3}),_=w("text",{x:o,y:d,"dominant-baseline":"middle","text-anchor":"middle"});_.textContent=t,this.label_element.appendChild(h),this.label_element.appendChild(_),this.label_element.addEventListener("mouseenter",()=>{this.hit_element.dispatchEvent(new MouseEvent("mouseenter",{bubbles:!1}))}),this.label_element.addEventListener("mouseleave",()=>{this.hit_element.dispatchEvent(new MouseEvent("mouseleave",{bubbles:!1}))}),this.label_element.addEventListener("click",l=>{l.stopPropagation(),this._toggle_type_dropdown()}),this.gantt.layers.arrow.appendChild(this.label_element)}_hide_label(){this.label_element&&(this.label_element.remove(),this.label_element=null)}_show_type_dropdown(){if(this.gantt.options.readonly||this.type_dropdown||(this.is_active||this.gantt.set_active_arrow(this),!this.label_element))return;const t=[{abbr:"FS",label:"Finish to Start",value:"finish-to-start"},{abbr:"SS",label:"Start to Start",value:"start-to-start"},{abbr:"FF",label:"Finish to Finish",value:"finish-to-finish"},{abbr:"SF",label:"Start to Finish",value:"start-to-finish"}];this.type_dropdown=document.createElement("div"),this.type_dropdown.className="arrow-type-dropdown",this.type_dropdown.addEventListener("click",a=>a.stopPropagation()),t.forEach(({abbr:a,label:o,value:d})=>{const h=document.createElement("div");h.className="arrow-type-option"+(d===this.dependency_type?" active":"");const _=document.createElement("strong");_.textContent=a;const l=document.createElement("span");l.textContent=o,h.appendChild(_),h.appendChild(l),h.addEventListener("click",p=>{p.stopPropagation(),this.gantt.change_dependency_type(this,d)}),this.type_dropdown.appendChild(h)}),this.gantt.$container.appendChild(this.type_dropdown);const e=this.label_element.getBoundingClientRect(),i=this.gantt.$container.getBoundingClientRect();this.type_dropdown.style.top=e.bottom-i.top+this.gantt.$container.scrollTop+"px",this.type_dropdown.style.left=e.left-i.left+this.gantt.$container.scrollLeft+"px";const s=this.label_element.querySelector("text"),n=this.label_element.querySelector("rect");if(s&&(s.textContent=this._get_type_abbr()+" ▾"),n){const o=parseFloat(n.getAttribute("width")),d=parseFloat(n.getAttribute("x"))+o/2;n.setAttribute("x",String(d-34/2)),n.setAttribute("width",String(34))}}_hide_type_dropdown(){var i,s;this.type_dropdown&&(this.type_dropdown.remove(),this.type_dropdown=null);const t=(i=this.label_element)==null?void 0:i.querySelector("text"),e=(s=this.label_element)==null?void 0:s.querySelector("rect");if(t&&(t.textContent=this._get_type_abbr()),e){const a=parseFloat(e.getAttribute("x"))+parseFloat(e.getAttribute("width"))/2;e.setAttribute("x",String(a-21/2)),e.setAttribute("width",String(21))}}_toggle_type_dropdown(){this.type_dropdown?this._hide_type_dropdown():this._show_type_dropdown()}activate(){this.is_active=!0,this.element.classList.add("arrow-active"),this._show_label();const t=this.is_invalid?"bar-arrow-invalid":this.is_critical?"bar-arrow-critical":"bar-arrow-active";this._get_connected_bars().forEach(e=>{const i=e.querySelector(".bar");i&&i.classList.add(t)})}deactivate(){this._hide_type_dropdown(),this.is_active=!1,this.element.classList.remove("arrow-active"),this._hide_label(),this._get_connected_bars().forEach(t=>{const e=t.querySelector(".bar");e&&e.classList.remove("bar-arrow-active","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.is_active&&(t+=" arrow-active"),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(),this.draw_connector_circles()}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((d,h)=>d+(h>=this.x&&h<e),0)*this.gantt.config.column_width;let s=(t-i)*this.task.progress/100;const n=this.x+s,a=this.gantt.config.ignored_positions.reduce((d,h)=>d+(h>=this.x&&h<n),0)*this.gantt.config.column_width;s+=a;let o=this.gantt.get_ignored_region(this.x+s);for(;o.length;)s+=this.gantt.config.column_width,o=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.show_bar_label?this.task.bar_label??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}),u.on(this.$add_icon_group,"mousedown",n=>{n.stopPropagation()}),u.on(this.$add_icon_group,"mouseup",n=>{n.stopPropagation()}),u.on(this.$add_icon_group,"click",n=>{n.stopPropagation(),this.gantt.trigger_event("task_add",[this.task])}),u.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()}),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(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)u.on(i,"mouseenter",()=>i.classList.add("active")),u.on(i,"mouseleave",()=>i.classList.remove("active"))}draw_connector_circles(){if(this.$connector_start=null,this.$connector_end=null,!this.gantt.options.allow_dependency_creation||this.gantt.options.readonly)return;const t=this.gantt.options.isRTL,e=this.y+this.height/2,i=t?this.x+this.width:this.x,s=t?this.x:this.x+this.width;this.$connector_start=w("circle",{class:"connector-circle connector-start","data-endpoint":"start",cx:i,cy:e,r:4,append_to:this.handle_group}),this.$connector_end=w("circle",{class:"connector-circle connector-end","data-endpoint":"end",cx:s,cy:e,r:4,append_to:this.handle_group})}update_connector_circles(){if(!this.$connector_start)return;const t=this.gantt.options.isRTL,e=this.$bar.getX(),i=this.$bar.getWidth(),s=this.y+this.height/2,n=t?e+i:e,a=t?e:e+i;this.$connector_start.setAttribute("cx",n),this.$connector_start.setAttribute("cy",s),this.$connector_end.setAttribute("cx",a),this.$connector_end.setAttribute("cy",s)}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=p=>{this.gantt.trigger_event("hover",[this.task,p.screenX,p.screenY,p])};if(u.on(this.group,"mouseover",e),this.event_listeners.push({event:"mouseover",handler:e}),this.gantt.options.popup_on==="click"){const p=c=>{const m=c.offsetX||c.layerX;if(this.$handle_progress){const f=+this.$handle_progress.getAttribute("cx");if(f>m-1&&f<m+1||this.gantt.bar_being_dragged)return}this.gantt.show_popup({x:c.offsetX||c.layerX,y:c.offsetY||c.layerY,task:this.task,target:this.$bar})};u.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 c=this.gantt.$container.querySelector(`.highlight-${CSS.escape(t)}`);c&&c.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",s),this.event_listeners.push({event:"mouseenter",handler:s});const n=()=>{var c,m;clearTimeout(i),this.gantt.options.popup_on==="hover"&&((m=(c=this.gantt.popup)==null?void 0:c.hide)==null||m.call(c));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))};u.on(this.group,"mouseleave",n),this.event_listeners.push({event:"mouseleave",handler:n});const a=()=>{this.is_dragging=!0,this.hide_add_icon()};u.on(this.group,"mousedown",a),this.event_listeners.push({event:"mousedown",handler:a});const o=()=>{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",o),this.event_listeners.push({event:"mouseup",handler:o});const d=()=>{this.action_completed||this.gantt.bar_being_dragged||this.gantt.trigger_event("click",[this.task])};u.on(this.group,"click",d),this.event_listeners.push({event:"click",handler:d});const h=()=>{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",h),this.event_listeners.push({event:"dblclick",handler:h});let _=!1;const l=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]))};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(),this.update_connector_circles()}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")||"",a=this.bar_group.querySelector(".img_mask")||"";let o=this.$bar.getX()+this.$bar.getWidth(),d=s.getX()+t,h=n&&n.getX()+t||0,_=n&&n.getBBox().width+7||7,l=d+s.getBBox().width+7,p=e+i.clientWidth/2;s.classList.contains("big")||(l<o&&t>0&&l<p||d-_>this.$bar.getX()&&t<0&&l>p)&&(s.setAttribute("x",d),n&&(n.setAttribute("x",h),a.setAttribute("x",h)))}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,a=this.image_size+10;const o=i.getBBox().width,d=e.getWidth();o>d?(i.classList.add("big"),s?(s.setAttribute("x",e.getEndX()+n),t.setAttribute("x",e.getEndX()+n),i.setAttribute("x",e.getEndX()+a)):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()+d/2+a)):i.setAttribute("x",e.getX()+d/2-o/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=`
101
+ 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._show_label()}),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"),this.is_active||i.classList.remove("bar-arrow-critical","bar-arrow-invalid"))}),!this.is_active&&!this.is_hovered&&this._hide_label()}),this.hit_element.addEventListener("click",e=>{e.stopPropagation(),this.is_active?this.gantt.set_active_arrow(null):this.gantt.set_active_arrow(this)})}_get_type_abbr(){return{"finish-to-start":"FS","start-to-start":"SS","finish-to-finish":"FF","start-to-finish":"SF"}[this.dependency_type]||"FS"}_show_label(){if(this.label_element)return;const t=this._get_type_abbr(),e=21,i=20,{x:s,y:n,side:a}=this.label_pos,o=a==="left"?s-10-e/2:s+10+e/2,h=n;this.label_element=w("g",{class:"arrow-type-label"});const d=w("rect",{x:o-e/2,y:h-i/2,width:e,height:i,rx:3}),_=w("text",{x:o,y:h,"dominant-baseline":"middle","text-anchor":"middle"});_.textContent=t,this.label_element.appendChild(d),this.label_element.appendChild(_),this.label_element.addEventListener("mouseenter",()=>{this.hit_element.dispatchEvent(new MouseEvent("mouseenter",{bubbles:!1}))}),this.label_element.addEventListener("mouseleave",()=>{this.hit_element.dispatchEvent(new MouseEvent("mouseleave",{bubbles:!1}))}),this.label_element.addEventListener("click",l=>{l.stopPropagation(),this._toggle_type_dropdown()}),this.gantt.layers.arrow.appendChild(this.label_element)}_hide_label(){this.label_element&&(this.label_element.remove(),this.label_element=null)}_show_type_dropdown(){if(this.gantt.options.readonly||this.type_dropdown||(this.is_active||this.gantt.set_active_arrow(this),!this.label_element))return;const t=[{abbr:"FS",label:"Finish to Start",value:"finish-to-start"},{abbr:"SS",label:"Start to Start",value:"start-to-start"},{abbr:"FF",label:"Finish to Finish",value:"finish-to-finish"},{abbr:"SF",label:"Start to Finish",value:"start-to-finish"}];this.type_dropdown=document.createElement("div"),this.type_dropdown.className="arrow-type-dropdown",this.type_dropdown.addEventListener("click",a=>a.stopPropagation()),t.forEach(({abbr:a,label:o,value:h})=>{const d=document.createElement("div");d.className="arrow-type-option"+(h===this.dependency_type?" active":"");const _=document.createElement("strong");_.textContent=a;const l=document.createElement("span");l.textContent=o,d.appendChild(_),d.appendChild(l),d.addEventListener("click",c=>{c.stopPropagation(),this.gantt.change_dependency_type(this,h)}),this.type_dropdown.appendChild(d)}),this.gantt.$container.appendChild(this.type_dropdown);const e=this.label_element.getBoundingClientRect(),i=this.gantt.$container.getBoundingClientRect();this.type_dropdown.style.top=e.bottom-i.top+this.gantt.$container.scrollTop+"px",this.type_dropdown.style.left=e.left-i.left+this.gantt.$container.scrollLeft+"px";const s=this.label_element.querySelector("text"),n=this.label_element.querySelector("rect");if(s&&(s.textContent=this._get_type_abbr()+" ▾"),n){const o=parseFloat(n.getAttribute("width")),h=parseFloat(n.getAttribute("x"))+o/2;n.setAttribute("x",String(h-34/2)),n.setAttribute("width",String(34))}}_hide_type_dropdown(){var i,s;this.type_dropdown&&(this.type_dropdown.remove(),this.type_dropdown=null);const t=(i=this.label_element)==null?void 0:i.querySelector("text"),e=(s=this.label_element)==null?void 0:s.querySelector("rect");if(t&&(t.textContent=this._get_type_abbr()),e){const a=parseFloat(e.getAttribute("x"))+parseFloat(e.getAttribute("width"))/2;e.setAttribute("x",String(a-21/2)),e.setAttribute("width",String(21))}}_toggle_type_dropdown(){this.type_dropdown?this._hide_type_dropdown():this._show_type_dropdown()}activate(){this.is_active=!0,this.element.classList.add("arrow-active"),this._show_label();const t=this.is_invalid?"bar-arrow-invalid":this.is_critical?"bar-arrow-critical":"bar-arrow-active";this._get_connected_bars().forEach(e=>{const i=e.querySelector(".bar");i&&i.classList.add(t)})}deactivate(){this._hide_type_dropdown(),this.is_active=!1,this.element.classList.remove("arrow-active"),this._hide_label(),this._get_connected_bars().forEach(t=>{const e=t.querySelector(".bar");e&&e.classList.remove("bar-arrow-active","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.is_active&&(t+=" arrow-active"),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(),this.draw_connector_circles()}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,a=this.gantt.config.ignored_positions.reduce((h,d)=>h+(d>=this.x&&d<n),0)*this.gantt.config.column_width;s+=a;let o=this.gantt.get_ignored_region(this.x+s);for(;o.length;)s+=this.gantt.config.column_width,o=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.show_bar_label?this.task.bar_label??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"))}draw_connector_circles(){if(this.$connector_start=null,this.$connector_end=null,!this.gantt.options.allow_dependency_creation||this.gantt.options.readonly)return;const t=this.gantt.options.isRTL,e=this.y+this.height/2,i=t?this.x+this.width:this.x,s=t?this.x:this.x+this.width;this.$connector_start=w("circle",{class:"connector-circle connector-start","data-endpoint":"start",cx:i,cy:e,r:4,append_to:this.handle_group}),this.$connector_end=w("circle",{class:"connector-circle connector-end","data-endpoint":"end",cx:s,cy:e,r:4,append_to:this.handle_group})}update_connector_circles(){if(!this.$connector_start)return;const t=this.gantt.options.isRTL,e=this.$bar.getX(),i=this.$bar.getWidth(),s=this.y+this.height/2,n=t?e+i:e,a=t?e:e+i;this.$connector_start.setAttribute("cx",n),this.$connector_start.setAttribute("cy",s),this.$connector_end.setAttribute("cx",a),this.$connector_end.setAttribute("cy",s)}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=c=>{this.gantt.trigger_event("hover",[this.task,c.screenX,c.screenY,c])};if(m.on(this.group,"mouseover",e),this.event_listeners.push({event:"mouseover",handler:e}),this.gantt.options.popup_on==="click"){const c=p=>{const f=p.offsetX||p.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:p.offsetX||p.layerX,y:p.offsetY||p.layerY,task:this.task,target:this.$bar})};m.on(this.group,"click",c),this.event_listeners.push({event:"click",handler:c})}let i;const s=c=>{i=setTimeout(()=>{this.gantt.options.popup_on==="hover"&&this.gantt.show_popup({x:c.offsetX||c.layerX,y:c.offsetY||c.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"))};m.on(this.group,"mouseenter",s),this.event_listeners.push({event:"mouseenter",handler:s});const n=()=>{var p,f;clearTimeout(i),this.gantt.options.popup_on==="hover"&&((f=(p=this.gantt.popup)==null?void 0:p.hide)==null||f.call(p));const c=this.gantt.$container.querySelector(`.highlight-${CSS.escape(t)}`);c&&c.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 a=()=>{this.is_dragging=!0,this.hide_add_icon()};m.on(this.group,"mousedown",a),this.event_listeners.push({event:"mousedown",handler:a});const o=()=>{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",o),this.event_listeners.push({event:"mouseup",handler:o});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 l=c=>{if(!_)return _=!0,setTimeout(function(){_=!1},300),!1;c.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",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(),this.update_connector_circles()}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")||"",a=this.bar_group.querySelector(".img_mask")||"";let o=this.$bar.getX()+this.$bar.getWidth(),h=s.getX()+t,d=n&&n.getX()+t||0,_=n&&n.getBBox().width+7||7,l=h+s.getBBox().width+7,c=e+i.clientWidth/2;s.classList.contains("big")||(l<o&&t>0&&l<c||h-_>this.$bar.getX()&&t<0&&l>c)&&(s.setAttribute("x",h),n&&(n.setAttribute("x",d),a.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,a=this.image_size+10;const o=i.getBBox().width,h=e.getWidth();o>h?(i.classList.add("big"),s?(s.setAttribute("x",e.getEndX()+n),t.setAttribute("x",e.getEndX()+n),i.setAttribute("x",e.getEndX()+a)):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+a)):i.setAttribute("x",e.getX()+h/2-o/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=`
102
102
  <div class="title"></div>
103
103
  <div class="subtitle"></div>
104
104
  <div class="details"></div>
105
105
  <div class="actions"></div>
106
- `,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:a=>this.title.innerHTML=a,get_subtitle:()=>this.subtitle,set_subtitle:a=>this.subtitle.innerHTML=a,get_details:()=>this.details,set_details:a=>this.details.innerHTML=a,add_action:(a,o)=>{let d=this.gantt.create_el({classes:"action-btn",type:"button",append_to:this.actions});typeof a=="function"&&(a=a(i)),d.innerHTML=a,d.onclick=h=>o(i,this.gantt,h)}});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 C(r){const t=r.getFullYear();return t-t%10+""}function U(r,t,e){let i=g.add(r,6,"day"),s=i.getMonth()!==r.getMonth()?"D MMM":"D",n=!t||r.getMonth()!==t.getMonth()?"D MMM":"D";return`${g.format(r,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:(r,t,e)=>!t||r.getDate()!==t.getDate()?g.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()?g.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()?g.format(r,"D MMM",e):g.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()?g.format(r,"D",e):"",upper_text:(r,t,e)=>!t||r.getMonth()!==t.getMonth()?g.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:U,upper_text:(r,t,e)=>!t||r.getMonth()!==t.getMonth()?g.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()?g.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||C(r)!==C(t)?C(r):"",lower_text:"YYYY",snap_at:"30d"}],Q={allow_dependency_creation:!0,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:r=>{r.set_title(r.task.name),r.task.description?r.set_subtitle(r.task.description):r.set_subtitle("");const t=g.format(r.task._start,"MMM D",r.chart.options.language),e=g.format(g.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_bar_label:!0,show_expected_progress:!1,task_add_icon_position:null,today_button:!0,view_mode:"Day",view_mode_select:!1,view_modes:x,is_weekend:r=>r.getDay()===0||r.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(a=>a.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={...Q,...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(d=>{let{duration:h,scale:_}=g.parse_duration(d);e.end=g.add(e.end,h,_)})),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(o=>o===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=B(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(a=>a.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(a=>a&&typeof a.id=="string").map(a=>({...a,id:a.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(),this.options.allow_dependency_creation&&this.bind_dependency_linking()}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.options.allow_dependency_creation&&(this.layers.linking=w("g",{class:"linking",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}),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=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,a,o,d,h,_,l,p;if((i=this.$task_column)==null||i.remove(),!((s=this.options.task_column)!=null&&s.enabled)){(a=(n=this.$wrapper)==null?void 0:n.classList)==null||a.remove("has-task-column");return}(d=(o=this.$wrapper)==null?void 0:o.classList)==null||d.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(c=>{const m=this.options.bar_height+this.options.padding,f=this.create_el({classes:"task-row",append_to:this.$task_column_content});if(f.style.top=c._index*m-1+"px",f.style.height=m+"px",this.options.task_column.content&&typeof this.options.task_column.content=="function"){const b=this.options.task_column.content(c);typeof b=="string"?f.innerHTML=b:b instanceof HTMLElement&&f.appendChild(b)}else f.textContent=c.name,f.title=c.name;f.setAttribute("data-task-id",c.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?(_=(h=this.$wrapper)==null?void 0:h.classList)==null||_.add("rtl"):(p=(l=this.$wrapper)==null?void 0:l.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 a=this.dates.length*this.config.column_width,o=this.options.bar_height+this.options.padding;if(this.options.lines!=="vertical")for(let d=this.config.header_height;d<this.grid_height;d+=o)w("line",{x1:0,y1:n+o,x2:a,y2:n+o,class:"row-line",append_to:s}),n+=o;if(this.options.lines!=="horizontal")for(let d of this.dates){let h="tick";this.config.view_mode.thick_line&&this.config.view_mode.thick_line(d)&&(h+=" thick"),w("path",{d:`M ${t} ${e} v ${i}`,class:h,append_to:this.layers.grid}),this.view_is("month")?t+=g.get_days_in_month(d)*this.config.column_width/30:this.view_is("year")?t+=g.get_days_in_year(d)*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(a=>typeof a=="function");if(n&&(s=n),this.options.holidays.name){let a=new Date(i.date+" ");i=o=>a.getTime()===o.getTime(),t[a]=i.name}else i=a=>this.options.holidays[e].filter(o=>typeof o!="function").map(o=>{if(o.name){let d=new Date(o.date+" ");return t[d]=o.name,d.getTime()}return new Date(o+" ").getTime()}).includes(a.getTime())}for(let n=new Date(this.gantt_start);n<=this.gantt_end;n.setDate(n.getDate()+1))if(!(this.config.ignored_dates.find(a=>a.getTime()==n.getTime())||this.config.ignored_function&&this.config.ignored_function(n))&&(i(n)||s&&s(n))){const a=g.diff(n,this.gantt_start,this.config.unit)/this.config.step*this.config.column_width,o=this.grid_height-this.config.header_height,d=g.format(n,"YYYY-MM-DD",this.options.language).replace(" ","_");if(t[n]){let h=this.create_el({classes:"holiday-label label_"+d,append_to:this.$extras});h.textContent=t[n]}w("rect",{x:Math.round(a),y:this.config.header_height,width:this.config.column_width/g.convert_scales(this.config.view_mode.step,"day"),height:o,class:"holiday-highlight "+d,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">
106
+ `,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:a=>this.title.innerHTML=a,get_subtitle:()=>this.subtitle,set_subtitle:a=>this.subtitle.innerHTML=a,get_details:()=>this.details,set_details:a=>this.details.innerHTML=a,add_action:(a,o)=>{let h=this.gantt.create_el({classes:"action-btn",type:"button",append_to:this.actions});typeof a=="function"&&(a=a(i)),h.innerHTML=a,h.onclick=d=>o(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 C(r){const t=r.getFullYear();return t-t%10+""}function U(r,t,e){let i=g.add(r,6,"day"),s=i.getMonth()!==r.getMonth()?"D MMM":"D",n=!t||r.getMonth()!==t.getMonth()?"D MMM":"D";return`${g.format(r,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:(r,t,e)=>!t||r.getDate()!==t.getDate()?g.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()?g.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()?g.format(r,"D MMM",e):g.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()?g.format(r,"D",e):"",upper_text:(r,t,e)=>!t||r.getMonth()!==t.getMonth()?g.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:U,upper_text:(r,t,e)=>!t||r.getMonth()!==t.getMonth()?g.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()?g.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||C(r)!==C(t)?C(r):"",lower_text:"YYYY",snap_at:"30d"}],Q={allow_dependency_creation:!0,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:r=>{r.set_title(r.task.name),r.task.description?r.set_subtitle(r.task.description):r.set_subtitle("");const t=g.format(r.task._start,"MMM D",r.chart.options.language),e=g.format(g.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_bar_label:!0,show_expected_progress:!1,task_add_icon_position:null,today_button:!0,view_mode:"Day",view_mode_select:!1,view_modes:x,is_weekend:r=>r.getDay()===0||r.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(a=>a.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={...Q,...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(o=>o===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=B(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(a=>a.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(a=>a&&typeof a.id=="string").map(a=>({...a,id:a.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(),this.options.allow_dependency_creation&&this.bind_dependency_linking()}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.options.allow_dependency_creation&&(this.layers.linking=w("g",{class:"linking",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,a,o,h,d,_,l,c;if((i=this.$task_column)==null||i.remove(),!((s=this.options.task_column)!=null&&s.enabled)){(a=(n=this.$wrapper)==null?void 0:n.classList)==null||a.remove("has-task-column");return}(h=(o=this.$wrapper)==null?void 0:o.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 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=p._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(p);typeof b=="string"?u.innerHTML=b:b instanceof HTMLElement&&u.appendChild(b)}else u.textContent=p.name,u.title=p.name;u.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"):(c=(l=this.$wrapper)==null?void 0:l.classList)==null||c.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 a=this.dates.length*this.config.column_width,o=this.options.bar_height+this.options.padding;if(this.options.lines!=="vertical")for(let h=this.config.header_height;h<this.grid_height;h+=o)w("line",{x1:0,y1:n+o,x2:a,y2:n+o,class:"row-line",append_to:s}),n+=o;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(a=>typeof a=="function");if(n&&(s=n),this.options.holidays.name){let a=new Date(i.date+" ");i=o=>a.getTime()===o.getTime(),t[a]=i.name}else i=a=>this.options.holidays[e].filter(o=>typeof o!="function").map(o=>{if(o.name){let h=new Date(o.date+" ");return t[h]=o.name,h.getTime()}return new Date(o+" ").getTime()}).includes(a.getTime())}for(let n=new Date(this.gantt_start);n<=this.gantt_end;n.setDate(n.getDate()+1))if(!(this.config.ignored_dates.find(a=>a.getTime()==n.getTime())||this.config.ignored_function&&this.config.ignored_function(n))&&(i(n)||s&&s(n))){const a=g.diff(n,this.gantt_start,this.config.unit)/this.config.step*this.config.column_width,o=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(a),y:this.config.header_height,width:this.config.column_width/g.convert_scales(this.config.view_mode.step,"day"),height:o,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">
107
107
  <path d="M-1,1 l2,-2
108
108
  M0,4 l4,-4
109
109
  M3,5 l2,-2"
110
110
  style="stroke:grey; stroke-width:0.3" />
111
- </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:a,append_to:o,type:d}){let h=document.createElement(d||"div");for(let _ of a.split(" "))h.classList.add(_);return h.style.top=e+"px",h.style.left=t+"px",n&&(h.id=n),i&&(h.style.width=i+"px"),s&&(h.style.height=s+"px"),o&&o.appendChild(h),h}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,a=this.config.view_mode.lower_text;return n?typeof n=="string"&&(this.config.view_mode.upper_text=o=>g.format(o,n,this.options.language)):this.config.view_mode.upper_text=()=>"",a?typeof a=="string"&&(this.config.view_mode.lower_text=o=>g.format(o,a,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.active_arrow=null,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],a=this.bars[t._index];if(!n||!a)return;const o=i.type||this.options.dependencies_type||"finish-to-start",d=new R(this,n,a,o);return this.layers.arrow.appendChild(d.element),this.layers.arrow.appendChild(d.hit_element),d}).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 a=0;n.dependencies&&n.dependencies.length>0&&n.dependencies.forEach(d=>{const h=this.get_task(d.id);if(h){const _=e(h);a=Math.max(a,_.ef)}}),t[n.id].es=a;const o=g.diff(n._end,n._start,"hour")/24;return t[n.id].ef=a+o,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 a=this.tasks.filter(h=>h.dependencies&&h.dependencies.some(_=>_.id===n.id));let o=i;a.length>0&&a.forEach(h=>{const _=s(h);o=Math.min(o,_.ls)});const d=g.diff(n._end,n._start,"hour")/24;return t[n.id].lf=o,t[n.id].ls=o-d,t[n.id]};this.tasks.forEach(n=>s(n)),this.tasks.forEach(n=>{const a=t[n.id],o=a.ls-a.es;n._is_critical=Math.abs(o)<.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[a,...o]=this.get_start_end_positions();this.$container.scrollLeft=a;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(a=>a.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(a=>a.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(){u.on(this.$container,"click",".grid-row, .grid-header, .ignored-bar, .holiday-highlight",(t,e)=>{if(e&&(e.classList.contains("grid-row")||e.classList.contains("ignored-bar")||e.classList.contains("holiday-highlight"))){const i=this.$svg,s=i.createSVGPoint();s.x=t.clientX,s.y=t.clientY;const n=s.matrixTransform(i.getScreenCTM().inverse()),a=this.options.bar_height+this.options.padding,o=Math.floor((n.y-this.config.header_height)/a),d=this.tasks[o];if(d&&d._has_no_dates){const h=n.x/this.config.column_width,_=Math.floor(h*this.config.step),l=g.add(this.gantt_start,_,this.config.unit);if(this.config.ignored_function)for(;this.config.ignored_function(l);)l=g.add(l,1,"day");d._start=l,d._end=g.add(l,1,"day"),d.start=l,d.end=d._end,delete d._has_no_dates,this.refresh(this.tasks,!0),this.trigger_event("date_change",[d,d._start,d._end]),this.trigger_event("after_date_change",[d,d._start,d._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:a},o){let{x:d,width:h}=a.getBBox();d<i&&(i=d),d>s&&(s=d),d+h>n&&(n=d+h)}),[i,s,n]}bind_bar_events(){let t=!1,e=0,i=0,s=!1,n=!1,a=null,o=[];this.bar_being_dragged=null,this.active_arrow=null;const d=()=>t||s||n;this.$svg.onclick=_=>{_.target.classList.contains("grid-row")&&this.unselect_all()},this._document_click_handler||(this._document_click_handler=()=>this.set_active_arrow(null),document.addEventListener("click",this._document_click_handler));let h=0;if(u.on(this.$svg,"mousemove",".bar-wrapper, .handle",_=>{this.bar_being_dragged===!1&&Math.abs((_.offsetX||_.layerX)-h)>10&&(this.bar_being_dragged=!0)}),u.on(this.$svg,"mousedown",".bar-wrapper, .handle",(_,l)=>{if(_.target.classList.contains("connector-circle"))return;const p=u.closest(".bar-wrapper",l);l.classList.contains("left")?(s=!0,l.classList.add("visible")):l.classList.contains("right")?(n=!0,l.classList.add("visible")):l.classList.contains("bar-wrapper")&&(t=!0),this.popup&&this.popup.hide(),e=_.offsetX||_.layerX,a=p.getAttribute("data-id"),o=[this.get_bar(a)],this.bar_being_dragged=!1,h=e,o.forEach(c=>{const m=c.$bar;m.ox=m.getX(),m.oy=m.getY(),m.owidth=m.getWidth(),m.finaldx=0})}),this.options.infinite_padding){let _=!1;u.on(this.$container,"mousewheel",l=>{let p=this.$container.scrollWidth/2;if(!_&&l.currentTarget.scrollLeft<=p){let c=l.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(),l.currentTarget.scrollLeft=c+this.config.column_width*this.config.extend_by_units,setTimeout(()=>_=!1,300)}if(!_&&l.currentTarget.scrollWidth-(l.currentTarget.scrollLeft+l.currentTarget.clientWidth)<=p){let c=l.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(),l.currentTarget.scrollLeft=c,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 p=this.bars.map(({group:$})=>$.getAttribute("data-id"));let c;i&&(c=_.currentTarget.scrollLeft-i),this.current_date=g.add(this.gantt_start,_.currentTarget.scrollLeft/this.config.column_width*this.config.step,this.config.unit);let m=this.config.view_mode.upper_text(this.current_date,null,this.options.language),f=this.upperTexts.find($=>$.textContent===m);this.current_date=g.add(this.gantt_start,(_.currentTarget.scrollLeft+f.clientWidth)/this.config.column_width*this.config.step,this.config.unit),m=this.config.view_mode.upper_text(this.current_date,null,this.options.language),f=this.upperTexts.find($=>$.textContent===m),f!==this.$current&&(this.$current&&this.$current.classList.remove("current-upper"),f.classList.add("current-upper"),this.$current=f),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"),c&&(l=p.map($=>this.get_bar($)),this.options.auto_move_label&&l.forEach($=>{$.update_label_position_on_horizontal_scroll({x:c,sx:_.currentTarget.scrollLeft})}))}),u.on(this.$svg,"mousemove",_=>{if(!d())return;const l=(_.offsetX||_.layerX)-e;o.forEach(p=>{const c=p.$bar;c.finaldx=this.get_snap_position(l,c.ox),this.hide_popup(),s?a===p.task.id?p.update_bar_position({x:c.ox+c.finaldx,width:c.owidth-c.finaldx}):p.update_bar_position({x:c.ox+c.finaldx}):n?a===p.task.id&&p.update_bar_position({width:c.owidth+c.finaldx}):t&&!this.options.readonly&&!this.options.readonly_dates&&p.update_bar_position({x:c.ox+c.finaldx})})}),document.addEventListener("mouseup",()=>{var p,c,m;const _=this.bar_being_dragged===!0;this.bar_being_dragged=null;const l=[];if(o.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:g.add(f.task._end,-1,"second")})}),this.options.critical_path&&o.some(f=>f.$bar.finaldx)&&(this.calculate_critical_path(),this.update_arrow_critical_path()),l.length>0&&this.options.dependency_shifting!=="none"){const f=this.options.dependency_shifting;let b;s?b=f==="maintain_buffer_downstream"?"none":"upstream":n?b="downstream":b=f==="maintain_buffer_downstream"?"downstream":"both",l.forEach(({task:y})=>{if(b==="none")return;const k=o.find(z=>z.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;O(this.tasks,y.id,J,this.options.dependency_shifting,b).forEach((z,Z)=>{const T=this.get_bar(Z);if(!T)return;const S=T.task,tt=new Date(S._start.getTime()+z),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",[S,S._start,g.add(S._end,-1,"second")])})})}l.length>0&&l.forEach(({task:f,start:b,end:y})=>{this.trigger_event("after_date_change",[f,b,y])}),o.forEach(f=>{f.$bar.finaldx=0}),t=!1,s=!1,n=!1,(m=(c=(p=this.$container.querySelector(".visible"))==null?void 0:p.classList)==null?void 0:c.remove)==null||m.call(c,"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;u.on(this.$task_column_resize_handle,"mousedown",a=>{t=!0,e=a.clientX,i=this.options.task_column.width,this.$task_column.classList.add("resizing"),a.preventDefault()}),u.on(document,"mousemove",a=>{if(!t)return;let o=a.clientX-e;this.options.isRTL&&(o=-o);let d=i+o;d=Math.max(s,Math.min(n,d)),this.options.task_column.width=d,this.$task_column.style.width=d+"px",this.$wrapper.style.setProperty("--gv-task-column-width",d+"px"),this.$container.style.setProperty("--gv-task-column-width",d+"px"),this.trigger_event("task_column_resize",[d])}),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,s=null,n=null;u.on(this.$svg,"mousedown",".handle.progress",(o,d)=>{e=!0,t=o.offsetX||o.layerX;const _=u.closest(".bar-wrapper",d).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 a=this.config.ignored_positions.map(o=>[o,o+this.config.column_width]);u.on(this.$svg,"mousemove",o=>{if(!e)return;let d=o.offsetX||o.layerX;if(d>t){let l=a.find(([p,c])=>d>=p&&d<c);for(;l;)d=l[1],l=a.find(([p,c])=>d>=p&&d<c)}else{let l=a.find(([p,c])=>d>p&&d<=c);for(;l;)d=l[0],l=a.find(([p,c])=>d>p&&d<=c)}let _=d-t;_>s.max_dx&&(_=s.max_dx),_<s.min_dx&&(_=s.min_dx),s.setAttribute("width",s.owidth+_),u.attr(i.$handle_progress,"cx",s.getEndX()),s.finaldx=_}),u.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)})}bind_dependency_linking(){this.is_linking=!1,this.linking_source_bar=null,this.linking_source_endpoint=null,this.linking_temp_line=null,this.linking_snap_badge=null,u.on(this.$svg,"mousedown",".connector-circle",(t,e)=>{const i=u.closest(".bar-wrapper",e);if(!i)return;const s=i.getAttribute("data-id"),n=this.get_bar(s);if(!n)return;this.is_linking=!0,this.linking_source_bar=n,this.linking_source_endpoint=e.getAttribute("data-endpoint");const a=parseFloat(e.getAttribute("cx")),o=parseFloat(e.getAttribute("cy"));this.linking_temp_line=w("line",{x1:a,y1:o,x2:a,y2:o,class:"linking-temp-line",append_to:this.layers.linking})}),u.on(this.$svg,"mousemove",t=>{if(!this.is_linking||!this.linking_temp_line)return;const e=this.$svg.createSVGPoint();e.x=t.clientX,e.y=t.clientY;const i=e.matrixTransform(this.$svg.getScreenCTM().inverse());this.linking_temp_line.setAttribute("x2",i.x),this.linking_temp_line.setAttribute("y2",i.y)}),u.on(this.$svg,"mouseover",".connector-circle",(t,e)=>{if(!this.is_linking)return;const i=u.closest(".bar-wrapper",e);if(!(!i||i.getAttribute("data-id")===this.linking_source_bar.task.id)&&(e.setAttribute("r","9"),this.linking_temp_line&&this.linking_temp_line.classList.add("snap"),!this.linking_snap_badge)){const n=e.getAttribute("data-endpoint"),a=this._resolve_dependency_type(this.linking_source_endpoint,n),o={"finish-to-start":"FS","start-to-start":"SS","finish-to-finish":"FF","start-to-finish":"SF"}[a]||"FS",d=parseFloat(e.getAttribute("cx")),h=parseFloat(e.getAttribute("cy"));this.linking_snap_badge=w("text",{x:d+12,y:h-10,class:"linking-snap-badge",append_to:this.layers.linking}),this.linking_snap_badge.textContent=o}}),u.on(this.$svg,"mouseout",".connector-circle",(t,e)=>{this.is_linking&&(e.setAttribute("r","4"),this.linking_temp_line&&this.linking_temp_line.classList.remove("snap"),this.linking_snap_badge&&(this.linking_snap_badge.remove(),this.linking_snap_badge=null))}),u.on(this.$svg,"mouseup",".connector-circle",(t,e)=>{if(!this.is_linking)return;const i=u.closest(".bar-wrapper",e);if(!i)return;const s=i.getAttribute("data-id");if(s!==this.linking_source_bar.task.id){const n=this.get_bar(s),a=e.getAttribute("data-endpoint");n&&this._commit_dependency(n,a)}}),document.addEventListener("mouseup",()=>{this.is_linking&&this._cancel_linking()}),document.addEventListener("keydown",t=>{if((t.key==="Delete"||t.key==="Backspace")&&this.active_arrow){const e=t.target.tagName;if(e==="INPUT"||e==="TEXTAREA"||t.target.isContentEditable)return;t.preventDefault(),this.delete_dependency(this.active_arrow)}})}_resolve_dependency_type(t,e){return t==="end"&&e==="start"?"finish-to-start":t==="start"&&e==="start"?"start-to-start":t==="end"&&e==="end"?"finish-to-finish":t==="start"&&e==="end"?"start-to-finish":"finish-to-start"}_commit_dependency(t,e){var l;const i=this.linking_source_bar.task,s=t.task,n=this._resolve_dependency_type(this.linking_source_endpoint,e),a=s.dependencies.find(p=>p.id===i.id),o=a?a.type||this.options.dependencies_type||"finish-to-start":null,d=s.dependencies.filter(p=>p.id!==i.id);if(o===n){this.update_task(s.id,{dependencies:d}),this.options.on_dependency_delete&&this.options.on_dependency_delete(i,s,n);return}const h=(l=i.dependencies)==null?void 0:l.find(p=>p.id===s.id);if(h){const p=h.type||this.options.dependencies_type||"finish-to-start";this.update_task(i.id,{dependencies:i.dependencies.filter(c=>c.id!==s.id)}),this.options.on_dependency_delete&&this.options.on_dependency_delete(s,i,p)}const _=[...d,{id:i.id,type:n}];this.update_task(s.id,{dependencies:_}),a?this.options.on_dependency_changed&&this.options.on_dependency_changed(i,s,o,n):this.options.on_dependency_create&&this.options.on_dependency_create(i,s,n)}_cancel_linking(){this.linking_temp_line&&(this.linking_temp_line.remove(),this.linking_temp_line=null),this.linking_snap_badge&&(this.linking_snap_badge.remove(),this.linking_snap_badge=null),this.$svg.querySelectorAll('.connector-circle[r="9"]').forEach(t=>t.setAttribute("r","4")),this.is_linking=!1,this.linking_source_bar=null,this.linking_source_endpoint=null}delete_dependency(t){const e=t.from_task.task,i=t.to_task.task,s=t.dependency_type,n=i.dependencies.filter(a=>{const o=a.type||this.options.dependencies_type||"finish-to-start";return!(a.id===e.id&&o===s)});this.set_active_arrow(null),this.update_task(i.id,{dependencies:n}),this.options.on_dependency_delete&&this.options.on_dependency_delete(e,i,s)}change_dependency_type(t,e){const i=t.from_task.task,s=t.to_task.task,n=t.dependency_type;if(t._hide_type_dropdown(),e===n||!s.dependencies.find(d=>d.id===i.id))return;const o=s.dependencies.map(d=>d.id===i.id?{...d,type:e}:d);this.set_active_arrow(null),this.update_task(s.id,{dependencies:o}),this.options.on_dependency_changed&&this.options.on_dependency_changed(i,s,n,e)}get_all_dependent_tasks(t){let e=[],i=[t];for(;i.length;){const s=i.reduce((n,a)=>(n=n.concat(this.dependency_map[a]),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:l}=g.parse_duration(s);i=g.convert_scales(this.config.view_mode.step,l)/_}const n=t%(this.config.column_width/i);let a=t-n+(n<this.config.column_width/i*2?0:this.config.column_width/i),o=e+a;const d=a>0?1:-1;let h=this.get_ignored_region(o,d);for(;h.length;)o+=this.config.column_width*d,h=this.get_ignored_region(o,d),h.length||(o-=this.config.column_width*d);return o-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)}set_active_arrow(t){this.active_arrow!==t&&(this.active_arrow&&this.active_arrow.deactivate(),this.active_arrow=t,t&&(t.activate(),this.options.on_arrow_click&&this.options.on_arrow_click(t.from_task.task,t.to_task.task)))}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,a,o,d,h,_,l,p,c,m,f,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),(a=(n=this.$task_column)==null?void 0:n.remove)==null||a.call(n),(d=(o=this.$current_highlight)==null?void 0:o.remove)==null||d.call(o),(_=(h=this.$extras)==null?void 0:h.remove)==null||_.call(h),(p=(l=this.popup)==null?void 0:l.hide)==null||p.call(l),(m=(c=this.$wrapper)==null?void 0:c.classList)==null||m.remove("has-task-column"),(b=(f=this.$wrapper)==null?void 0:f.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 B(r){return r.name+"_"+Math.random().toString(36).slice(2,12)}function D(r){return r.replaceAll(" ","_").replaceAll(":","_").replaceAll(".","_")}return P});
111
+ </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:a,append_to:o,type:h}){let d=document.createElement(h||"div");for(let _ of a.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"),o&&o.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,a=this.config.view_mode.lower_text;return n?typeof n=="string"&&(this.config.view_mode.upper_text=o=>g.format(o,n,this.options.language)):this.config.view_mode.upper_text=()=>"",a?typeof a=="string"&&(this.config.view_mode.lower_text=o=>g.format(o,a,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.active_arrow=null,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],a=this.bars[t._index];if(!n||!a)return;const o=i.type||this.options.dependencies_type||"finish-to-start",h=new R(this,n,a,o);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(){if(this.tasks.forEach(_=>_._is_critical=!1),this.tasks.length===0)return;const t=_=>g.diff(_._end,_._start,"hour")/24;let e=this.tasks[0]._start;this.tasks.forEach(_=>{_._start<e&&(e=_._start)});const i=_=>g.diff(_._start,e,"hour")/24,s=_=>_.type||this.options.dependencies_type||"finish-to-start",n={};this.tasks.forEach(_=>{n[_.id]={d:t(_),s:i(_),es:0,ef:0,ls:0,lf:0,f_done:!1,b_done:!1}});const a={};this.tasks.forEach(_=>a[_.id]=[]),this.tasks.forEach(_=>{(_.dependencies||[]).forEach(l=>{n[l.id]&&a[l.id].push({id:_.id,type:s(l)})})});const o=(_,l)=>{const c=n[_.id];if(c.f_done||l.has(_.id))return c;l.add(_.id);let p=c.s,f=!1;return(_.dependencies||[]).forEach(u=>{const b=this.get_task(u.id);if(!b||!n[u.id])return;const $=o(b,l),k=s(u);let y;k==="start-to-start"?y=$.es:k==="finish-to-finish"?y=$.ef-c.d:k==="start-to-finish"?y=$.es-c.d:y=$.ef,p=f?Math.max(p,y):y,f=!0}),c.es=p,c.ef=p+c.d,c.f_done=!0,l.delete(_.id),c};this.tasks.forEach(_=>o(_,new Set));const h=Math.max(...this.tasks.map(_=>n[_.id].ef)),d=(_,l)=>{const c=n[_.id];if(c.b_done||l.has(_.id))return c;l.add(_.id);const p=a[_.id];let f;if(p.length===0)f=h;else{let u=!1;p.forEach(b=>{const $=d(this.get_task(b.id),l);let k;b.type==="start-to-start"?k=$.ls+c.d:b.type==="finish-to-finish"?k=$.lf:b.type==="start-to-finish"?k=$.lf+c.d:k=$.ls,f=u?Math.min(f,k):k,u=!0})}return c.lf=f,c.ls=f-c.d,c.b_done=!0,l.delete(_.id),c};this.tasks.forEach(_=>d(_,new Set)),this.tasks.forEach(_=>{const l=n[_.id];_._is_critical=Math.abs(l.ls-l.es)<.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[a,...o]=this.get_start_end_positions();this.$container.scrollLeft=a;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(a=>a.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(a=>a.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")||e.classList.contains("ignored-bar")||e.classList.contains("holiday-highlight"))){const i=this.$svg,s=i.createSVGPoint();s.x=t.clientX,s.y=t.clientY;const n=s.matrixTransform(i.getScreenCTM().inverse()),a=this.options.bar_height+this.options.padding,o=Math.floor((n.y-this.config.header_height)/a),h=this.tasks[o];if(h&&h._has_no_dates){const d=n.x/this.config.column_width,_=Math.floor(d*this.config.step),l=g.add(this.gantt_start,_,this.config.unit);if(this.config.ignored_function)for(;this.config.ignored_function(l);)l=g.add(l,1,"day");h._start=l,h._end=g.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 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:a},o){let{x:h,width:d}=a.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,a=null,o=[];this.bar_being_dragged=null,this.active_arrow=null;const h=()=>t||s||n;this.$svg.onclick=_=>{_.target.classList.contains("grid-row")&&this.unselect_all()},this._document_click_handler||(this._document_click_handler=()=>this.set_active_arrow(null),document.addEventListener("click",this._document_click_handler));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",(_,l)=>{if(_.target.classList.contains("connector-circle"))return;const c=m.closest(".bar-wrapper",l);l.classList.contains("left")?(s=!0,l.classList.add("visible")):l.classList.contains("right")?(n=!0,l.classList.add("visible")):l.classList.contains("bar-wrapper")&&(t=!0),this.popup&&this.popup.hide(),e=_.offsetX||_.layerX,a=c.getAttribute("data-id"),o=[this.get_bar(a)],this.bar_being_dragged=!1,d=e,o.forEach(p=>{const f=p.$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",l=>{let c=this.$container.scrollWidth/2;if(!_&&l.currentTarget.scrollLeft<=c){let p=l.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(),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)<=c){let p=l.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(),l.currentTarget.scrollLeft=p,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 l=[];const c=this.bars.map(({group:y})=>y.getAttribute("data-id"));let p;i&&(p=_.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(y=>y.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(y=>y.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,$,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:$,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=c.map(y=>this.get_bar(y)),this.options.auto_move_label&&l.forEach(y=>{y.update_label_position_on_horizontal_scroll({x:p,sx:_.currentTarget.scrollLeft})}))}),m.on(this.$svg,"mousemove",_=>{if(!h())return;const l=(_.offsetX||_.layerX)-e;o.forEach(c=>{const p=c.$bar;p.finaldx=this.get_snap_position(l,p.ox),this.hide_popup(),s?a===c.task.id?c.update_bar_position({x:p.ox+p.finaldx,width:p.owidth-p.finaldx}):c.update_bar_position({x:p.ox+p.finaldx}):n?a===c.task.id&&c.update_bar_position({width:p.owidth+p.finaldx}):t&&!this.options.readonly&&!this.options.readonly_dates&&c.update_bar_position({x:p.ox+p.finaldx})})}),document.addEventListener("mouseup",()=>{var c,p,f;const _=this.bar_being_dragged===!0;this.bar_being_dragged=null;const l=[];if(o.forEach(u=>{if(!u.$bar.finaldx){_&&u.set_action_completed();return}u.date_changed(),u.compute_progress(),u.set_action_completed(),l.push({task:u.task,start:u.task._start,end:g.add(u.task._end,-1,"second")})}),this.options.critical_path&&o.some(u=>u.$bar.finaldx)&&(this.calculate_critical_path(),this.update_arrow_critical_path()),l.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",l.forEach(({task:$})=>{if(b==="none")return;const k=o.find(z=>z.task.id===$.id);if(!k||!k.$bar.finaldx)return;const y=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=y*this.config.step*K;O(this.tasks,$.id,J,this.options.dependency_shifting,b).forEach((z,Z)=>{const T=this.get_bar(Z);if(!T)return;const E=T.task,tt=new Date(E._start.getTime()+z),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",[E,E._start,g.add(E._end,-1,"second")])})})}l.length>0&&l.forEach(({task:u,start:b,end:$})=>{this.trigger_event("after_date_change",[u,b,$])}),o.forEach(u=>{u.$bar.finaldx=0}),t=!1,s=!1,n=!1,(f=(p=(c=this.$container.querySelector(".visible"))==null?void 0:c.classList)==null?void 0:p.remove)==null||f.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 s=100,n=600;m.on(this.$task_column_resize_handle,"mousedown",a=>{t=!0,e=a.clientX,i=this.options.task_column.width,this.$task_column.classList.add("resizing"),a.preventDefault()}),m.on(document,"mousemove",a=>{if(!t)return;let o=a.clientX-e;this.options.isRTL&&(o=-o);let h=i+o;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",(o,h)=>{e=!0,t=o.offsetX||o.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 a=this.config.ignored_positions.map(o=>[o,o+this.config.column_width]);m.on(this.$svg,"mousemove",o=>{if(!e)return;let h=o.offsetX||o.layerX;if(h>t){let l=a.find(([c,p])=>h>=c&&h<p);for(;l;)h=l[1],l=a.find(([c,p])=>h>=c&&h<p)}else{let l=a.find(([c,p])=>h>c&&h<=p);for(;l;)h=l[0],l=a.find(([c,p])=>h>c&&h<=p)}let _=h-t;_>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)})}bind_dependency_linking(){this.is_linking=!1,this.linking_source_bar=null,this.linking_source_endpoint=null,this.linking_temp_line=null,this.linking_snap_badge=null,m.on(this.$svg,"mousedown",".connector-circle",(t,e)=>{const i=m.closest(".bar-wrapper",e);if(!i)return;const s=i.getAttribute("data-id"),n=this.get_bar(s);if(!n)return;this.is_linking=!0,this.linking_source_bar=n,this.linking_source_endpoint=e.getAttribute("data-endpoint");const a=parseFloat(e.getAttribute("cx")),o=parseFloat(e.getAttribute("cy"));this.linking_temp_line=w("line",{x1:a,y1:o,x2:a,y2:o,class:"linking-temp-line",append_to:this.layers.linking})}),m.on(this.$svg,"mousemove",t=>{if(!this.is_linking||!this.linking_temp_line)return;const e=this.$svg.createSVGPoint();e.x=t.clientX,e.y=t.clientY;const i=e.matrixTransform(this.$svg.getScreenCTM().inverse());this.linking_temp_line.setAttribute("x2",i.x),this.linking_temp_line.setAttribute("y2",i.y)}),m.on(this.$svg,"mouseover",".connector-circle",(t,e)=>{if(!this.is_linking)return;const i=m.closest(".bar-wrapper",e);if(!(!i||i.getAttribute("data-id")===this.linking_source_bar.task.id)&&(e.setAttribute("r","9"),this.linking_temp_line&&this.linking_temp_line.classList.add("snap"),!this.linking_snap_badge)){const n=e.getAttribute("data-endpoint"),a=this._resolve_dependency_type(this.linking_source_endpoint,n),o={"finish-to-start":"FS","start-to-start":"SS","finish-to-finish":"FF","start-to-finish":"SF"}[a]||"FS",h=parseFloat(e.getAttribute("cx")),d=parseFloat(e.getAttribute("cy"));this.linking_snap_badge=w("text",{x:h+12,y:d-10,class:"linking-snap-badge",append_to:this.layers.linking}),this.linking_snap_badge.textContent=o}}),m.on(this.$svg,"mouseout",".connector-circle",(t,e)=>{this.is_linking&&(e.setAttribute("r","4"),this.linking_temp_line&&this.linking_temp_line.classList.remove("snap"),this.linking_snap_badge&&(this.linking_snap_badge.remove(),this.linking_snap_badge=null))}),m.on(this.$svg,"mouseup",".connector-circle",(t,e)=>{if(!this.is_linking)return;const i=m.closest(".bar-wrapper",e);if(!i)return;const s=i.getAttribute("data-id");if(s!==this.linking_source_bar.task.id){const n=this.get_bar(s),a=e.getAttribute("data-endpoint");n&&this._commit_dependency(n,a)}}),document.addEventListener("mouseup",()=>{this.is_linking&&this._cancel_linking()}),document.addEventListener("keydown",t=>{if((t.key==="Delete"||t.key==="Backspace")&&this.active_arrow){const e=t.target.tagName;if(e==="INPUT"||e==="TEXTAREA"||t.target.isContentEditable)return;t.preventDefault(),this.delete_dependency(this.active_arrow)}})}_resolve_dependency_type(t,e){return t==="end"&&e==="start"?"finish-to-start":t==="start"&&e==="start"?"start-to-start":t==="end"&&e==="end"?"finish-to-finish":t==="start"&&e==="end"?"start-to-finish":"finish-to-start"}_commit_dependency(t,e){var l;const i=this.linking_source_bar.task,s=t.task,n=this._resolve_dependency_type(this.linking_source_endpoint,e),a=s.dependencies.find(c=>c.id===i.id),o=a?a.type||this.options.dependencies_type||"finish-to-start":null,h=s.dependencies.filter(c=>c.id!==i.id);if(o===n){this.update_task(s.id,{dependencies:h}),this.options.on_dependency_delete&&this.options.on_dependency_delete(i,s,n);return}const d=(l=i.dependencies)==null?void 0:l.find(c=>c.id===s.id);if(d){const c=d.type||this.options.dependencies_type||"finish-to-start";this.update_task(i.id,{dependencies:i.dependencies.filter(p=>p.id!==s.id)}),this.options.on_dependency_delete&&this.options.on_dependency_delete(s,i,c)}const _=[...h,{id:i.id,type:n}];this.update_task(s.id,{dependencies:_}),a?this.options.on_dependency_changed&&this.options.on_dependency_changed(i,s,o,n):this.options.on_dependency_create&&this.options.on_dependency_create(i,s,n)}_cancel_linking(){this.linking_temp_line&&(this.linking_temp_line.remove(),this.linking_temp_line=null),this.linking_snap_badge&&(this.linking_snap_badge.remove(),this.linking_snap_badge=null),this.$svg.querySelectorAll('.connector-circle[r="9"]').forEach(t=>t.setAttribute("r","4")),this.is_linking=!1,this.linking_source_bar=null,this.linking_source_endpoint=null}delete_dependency(t){const e=t.from_task.task,i=t.to_task.task,s=t.dependency_type,n=i.dependencies.filter(a=>{const o=a.type||this.options.dependencies_type||"finish-to-start";return!(a.id===e.id&&o===s)});this.set_active_arrow(null),this.update_task(i.id,{dependencies:n}),this.options.on_dependency_delete&&this.options.on_dependency_delete(e,i,s)}change_dependency_type(t,e){const i=t.from_task.task,s=t.to_task.task,n=t.dependency_type;if(t._hide_type_dropdown(),e===n||!s.dependencies.find(h=>h.id===i.id))return;const o=s.dependencies.map(h=>h.id===i.id?{...h,type:e}:h);this.set_active_arrow(null),this.update_task(s.id,{dependencies:o}),this.options.on_dependency_changed&&this.options.on_dependency_changed(i,s,n,e)}get_all_dependent_tasks(t){let e=[],i=[t];for(;i.length;){const s=i.reduce((n,a)=>(n=n.concat(this.dependency_map[a]),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:l}=g.parse_duration(s);i=g.convert_scales(this.config.view_mode.step,l)/_}const n=t%(this.config.column_width/i);let a=t-n+(n<this.config.column_width/i*2?0:this.config.column_width/i),o=e+a;const h=a>0?1:-1;let d=this.get_ignored_region(o,h);for(;d.length;)o+=this.config.column_width*h,d=this.get_ignored_region(o,h),d.length||(o-=this.config.column_width*h);return o-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)}set_active_arrow(t){this.active_arrow!==t&&(this.active_arrow&&this.active_arrow.deactivate(),this.active_arrow=t,t&&(t.activate(),this.options.on_arrow_click&&this.options.on_arrow_click(t.from_task.task,t.to_task.task)))}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,a,o,h,d,_,l,c,p,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),(a=(n=this.$task_column)==null?void 0:n.remove)==null||a.call(n),(h=(o=this.$current_highlight)==null?void 0:o.remove)==null||h.call(o),(_=(d=this.$extras)==null?void 0:d.remove)==null||_.call(d),(c=(l=this.popup)==null?void 0:l.hide)==null||c.call(l),(f=(p=this.$wrapper)==null?void 0:p.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 B(r){return r.name+"_"+Math.random().toString(36).slice(2,12)}function D(r){return r.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.26",
3
+ "version": "1.0.27",
4
4
  "description": "A simple, modern, interactive gantt library for the web",
5
5
  "main": "src/index.js",
6
6
  "type": "module",