@svar-ui/gantt-store 2.4.0 → 2.4.1

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.
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- var Kt=new Date().valueOf(),cn=()=>Kt++;function bt(){return"temp://"+Kt++}function un(e,t){if(Object.keys(e).length!==Object.keys(t).length)return!1;for(const n in t){const s=e[n],a=t[n];if(!wt(s,a))return!1}return!0}function wt(e,t){if(typeof e=="number"||typeof e=="string"||typeof e=="boolean"||e===null)return e===t;if(typeof e!=typeof t||(e===null||t===null)&&e!==t||e instanceof Date&&t instanceof Date&&e.getTime()!==t.getTime())return!1;if(typeof e=="object")if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return!1;for(let n=e.length-1;n>=0;n--)if(!wt(e[n],t[n]))return!1;return!0}else return un(e,t);return e===t}function P(e){if(typeof e!="object"||e===null)return e;if(e instanceof Date)return new Date(e);if(e instanceof Array)return e.map(P);const t={};for(const n in e)t[n]=P(e[n]);return t}var Zt=class{constructor(e){this._data=e,this._pool=new Map;for(let t=0;t<e.length;t++){const n=e[t];this._pool.set(n.id,n)}}add(e){e={id:cn(),...e},this._data.push(e),this._pool.set(e.id,e)}update(e,t){const n=this._data.findIndex(a=>a.id==e),s={...this._data[n],...t};this._data[n]=s,this._pool.set(s.id,s)}remove(e){this._data=this._data.filter(t=>t.id!=e),this._pool.delete(e)}filter(e){this._data=this._data.filter(t=>{const n=e(t);return n||this._pool.delete(t.id),n})}byId(e){return this._pool.get(e)}map(e){return this._data.map(e)}forEach(e){this._data.forEach(e)}},ln=class{constructor(e){const t={id:0,$level:0,data:[],parent:null},n=new Map;n.set(0,t),this._pool=n,e&&e.length&&this.parse(e,0)}parse(e,t){const n=this._pool;for(let a=0;a<e.length;a++){const r=e[a];r.parent=r.parent||t,r.data=null,n.set(r.id,r)}for(let a=0;a<e.length;a++){const r=e[a],i=n.get(r.parent);i&&(i.data||(i.data=[]),i.data.push(r))}const s=n.get(t);this.setLevel(s,s.$level+1,!1)}add(e,t){const n=this._pool.get(e.parent||0);e.$level=n.$level+1,this._pool.set(e.id,e),n.data?t===-1?n.data=[...n.data,e]:ee(n,t,e):n.data=[e]}addAfter(e,t){if(!t)return this.add(e,-1);const n=this.byId(t),s=this.byId(n.parent),a=rt(s,n.id)+1;e.parent=s.id,e.$level=s.$level+1,this.add(e,a)}remove(e){const t=this._pool.get(e);this._remove(t);const n=this._pool.get(t.parent);n.data=n.data.filter(s=>s.id!=e),this._clearBranch(n)}_remove(e){e.data&&e.data.forEach(t=>this._remove(t)),this._pool.delete(e.id)}update(e,t){let n=this._pool.get(e);const s=this._pool.get(n.parent),a=rt(s,n.id);n={...n,...t},s&&a>=0&&(s.data[a]=n,s.data=[...s.data]),this._pool.set(n.id,n)}move(e,t,n){const s=this._pool.get(e),a=t==="child",r=this._pool.get(n),i=r.$level+(a?1:0);if(!s||!r)return;const o=this._pool.get(s.parent),d=a?r:this._pool.get(r.parent);d.data||(d.data=[]);const c=rt(o,s.id);hn(o,c);const u=a?d.data.length:rt(d,r.id)+(t==="after"?1:0);if(ee(d,u,s),o.id===d.id&&c===u)return null;s.parent=d.id,s.$level!==i&&(s.$level=i,this.setLevel(s,i+1,!0)),this.update(s.id,s),this._clearBranch(o)}_clearBranch(e){e.data&&!e.data.length&&(e.open&&delete e.open,this.update(e.id,{data:null}))}toArray(){const e=[],t=this._pool.get(0).data;return t&&te(t,e),e}byId(e){return this._pool.get(e)}getBranch(e){return this._pool.get(e).data}forEach(e){this._pool.forEach((t,n)=>{n!==0&&e(t)})}eachChild(e,t){const n=this.byId(t);!n||!n.data||n.data.forEach((s,a)=>{e(this.byId(s.id),a),this.eachChild(e,s.id)})}setLevel(e,t,n){e.data&&(e.data=e.data.map(s=>(n&&(s={...s},this._pool.set(s.id,s)),s.$level=t,s.data&&this.setLevel(s,t+1,n),s)))}};function te(e,t){e.forEach(n=>{t.push(n),n.open===!0&&te(n.data,t)})}function hn(e,t){const n=[...e.data];n.splice(t,1),e.data=n}function ee(e,t,n){const s=[...e.data];s.splice(t,0,n),e.data=s}function rt(e,t){return e?.data.findIndex(n=>n.id===t)}var ne=2,fn=class{constructor(e){e&&(this._writable=e.writable,this._async=e.async),this._values={},this._state={}}setState(e,t=0){const n={};return this._wrapProperties(e,this._state,this._values,"",n,t),n}getState(){return this._values}getReactive(){return this._state}_wrapProperties(e,t,n,s,a,r){for(const i in e){const o=t[i],d=n[i],c=e[i];if(o&&(d===c&&typeof c!="object"||c instanceof Date&&d instanceof Date&&d.getTime()===c.getTime()))continue;const u=s+(s?".":"")+i;o?(o.__parse(c,u,a,r)&&(n[i]=c),r&ne?a[u]=o.__trigger:o.__trigger()):(c&&c.__reactive?t[i]=this._wrapNested(c,c,u,a):t[i]=this._wrapWritable(c),n[i]=c),a[u]=a[u]||null}}_wrapNested(e,t,n,s){const a=this._wrapWritable(e);return this._wrapProperties(e,a,t,n,s,0),a.__parse=(r,i,o,d)=>(this._wrapProperties(r,a,t,i,o,d),!1),a}_wrapWritable(e){const t=[],n=function(){for(let s=0;s<t.length;s++)t[s](e)};return{subscribe:s=>(t.push(s),this._async?setTimeout(s,1,e):s(e),()=>{const a=t.indexOf(s);a>=0&&t.splice(a,1)}),__trigger:()=>{t.length&&(this._async?setTimeout(n,1):n())},__parse:function(s){return e=s,!0}}}},gn=class{constructor(e,t,n,s){typeof e=="function"?this._setter=e:this._setter=e.setState.bind(e),this._routes=t,this._parsers=n,this._prev={},this._triggers=new Map,this._sources=new Map,this._routes.forEach(a=>{a.in.forEach(r=>{const i=this._triggers.get(r)||[];i.push(a),this._triggers.set(r,i)}),a.out.forEach(r=>{const i=this._sources.get(r)||{};a.in.forEach(o=>i[o]=!0),this._sources.set(r,i)})}),this._routes.forEach(a=>{a.length=Math.max(...a.in.map(r=>se(r,this._sources,1)))}),this._bus=s}init(e){const t={};for(const n in e)if(this._prev[n]!==e[n]){const s=this._parsers[n];t[n]=s?s(e[n]):e[n]}this._prev=this._prev?{...this._prev,...e}:{...e},this.setState(t),this._bus&&this._bus.exec("init-state",t)}setStateAsync(e){const t=this._setter(e,ne);return this._async?Object.assign(this._async.signals,t):this._async={signals:t,timer:setTimeout(this._applyState.bind(this),1)},t}_applyState(){const e=this._async;if(e){this._async=null,this._triggerUpdates(e.signals,[]);for(const t in e.signals){const n=e.signals[t];n&&n()}}}setState(e,t=[]){const n=this._setter(e);return this._triggerUpdates(n,t),n}_triggerUpdates(e,t){const n=Object.keys(e),s=!t.length;t=t||[];for(let a=0;a<n.length;a++){const r=n[a],i=this._triggers.get(r);i&&i.forEach(o=>{t.indexOf(o)==-1&&t.push(o)})}s&&this._execNext(t)}_execNext(e){for(;e.length;){e.sort((n,s)=>n.length<s.length?1:-1);const t=e[e.length-1];e.splice(e.length-1),t.exec(e)}}};function se(e,t,n){const s=t.get(e);if(!s)return n;const a=Object.keys(s).map(r=>se(r,t,n+1));return Math.max(...a)}var pn=class{constructor(){this._nextHandler=null,this._handlers={},this._tag=new WeakMap,this.exec=this.exec.bind(this)}on(e,t,n){let s=this._handlers[e];s?n&&n.intercept?s.unshift(t):s.push(t):s=this._handlers[e]=[t],n&&n.tag&&this._tag.set(t,n.tag)}intercept(e,t,n){this.on(e,t,{...n,intercept:!0})}detach(e){for(const t in this._handlers){const n=this._handlers[t];for(let s=n.length-1;s>=0;s--)this._tag.get(n[s])===e&&n.splice(s,1)}}async exec(e,t){const n=this._handlers[e];if(n)for(let s=0;s<n.length;s++){const a=n[s](t);if(a===!1||a&&a.then&&await a===!1)return}return this._nextHandler&&await this._nextHandler.exec(e,t),t}setNext(e){return this._nextHandler=e}};function mn(e,t){return typeof e=="string"?e.localeCompare(t,void 0,{numeric:!0}):typeof e=="object"?e.getTime()-t.getTime():(e??0)-(t??0)}function kn(e,t){return typeof e=="string"?-e.localeCompare(t,void 0,{numeric:!0}):typeof t=="object"?t.getTime()-e.getTime():(t??0)-(e??0)}function yn({key:e,order:t}){const n=t==="asc"?mn:kn;return(s,a)=>n(s[e],a[e])}function bn(e){if(!e||!e.length)return;const t=e.map(n=>yn(n));return e.length===1?t[0]:function(n,s){for(let a=0;a<t.length;a++){const r=t[a](n,s);if(r!==0)return r}return 0}}function wn(e,t){return e.sort(bn(t))}class xn extends ln{_sort;constructor(t){super(),this.parse(t,0)}parse(t,n){if(!t||!t.length)return;const s=t.map(a=>this.normalizeTask(a,t));super.parse(s,n),this._sort&&this.sortBranch(this._sort,n)}getBranch(t){const n=this._pool.get(t);return this._pool.get(n.parent||0).data}contains(t,n){const s=this._pool.get(t).data;let a=!1;if(s)for(let r=0;r<s.length;r++){if(s[r].id===n){a=!0;break}if(s[r].data&&(a=this.contains(s[r].id,n),a))break}return a}getIndexById(t){return this.getBranch(t).findIndex(n=>n.id===t)}add(t,n){const s=this.normalizeTask(t);return super.add(s,n),s}copy(t,n,s){const a=this.add({...t,id:null,data:null,parent:n},s);let r=[[t.id,a.id]];return t.data?.forEach((i,o)=>{const d=this.copy(i,a.id,o);r=r.concat(d)}),r}normalizeTask(t){const n=t.id||bt(),s=t.parent||0,a=t.text||"",r=t.type||"task",i=t.progress||0,o=t.details||"",d={...t,id:n,text:a,parent:s,progress:i,type:r,details:o};return t.segments&&(d.segments=t.segments.map(c=>({...c}))),t.segments&&(d.segments=t.segments.map(c=>({...c}))),d}getSummaryId(t,n=!1){const s=this._pool.get(t);if(!s.parent)return null;const a=this._pool.get(s.parent);if(n){let r=t,i=this.getSummaryId(r);const o=[];for(;i;)r=i,o.push(i),i=this.getSummaryId(r);return o}return a.type==="summary"?a.id:this.getSummaryId(a.id)}sort(t){this._sort=t,t&&this.sortBranch(t,0)}sortBranch(t,n){const s=this._pool.get(n||0).data;s&&(wn(s,t),s.forEach(a=>{this.sortBranch(t,a.id)}))}serialize(){const t=[],n=this._pool.get(0).data;return n&&ae(n,t),t}}function ae(e,t){e.forEach(n=>{t.push(n),n.data&&ae(n.data,t)})}function w(e){const t=Object.prototype.toString.call(e);return e instanceof Date||typeof e=="object"&&t==="[object Date]"?new e.constructor(+e):typeof e=="number"||t==="[object Number]"||typeof e=="string"||t==="[object String]"?new Date(e):new Date(NaN)}function $(e,t){return e instanceof Date?new e.constructor(t):new Date(t)}function it(e,t){const n=w(e);return isNaN(t)?$(e,NaN):(t&&n.setDate(n.getDate()+t),n)}function xt(e,t){const n=w(e);if(isNaN(t))return $(e,NaN);if(!t)return n;const s=n.getDate(),a=$(e,n.getTime());a.setMonth(n.getMonth()+t+1,0);const r=a.getDate();return s>=r?a:(n.setFullYear(a.getFullYear(),a.getMonth(),s),n)}function re(e,t){const n=+w(e);return $(e,n+t)}const ot=6048e5,Sn=864e5,ie=6e4,oe=36e5;function vn(e,t){return re(e,t*oe)}let _n={};function G(){return _n}function C(e,t){const n=G(),s=t?.weekStartsOn??t?.locale?.options?.weekStartsOn??n.weekStartsOn??n.locale?.options?.weekStartsOn??0,a=w(e),r=a.getDay(),i=(r<s?7:0)+r-s;return a.setDate(a.getDate()-i),a.setHours(0,0,0,0),a}function j(e){return C(e,{weekStartsOn:1})}function de(e){const t=w(e),n=t.getFullYear(),s=$(e,0);s.setFullYear(n+1,0,4),s.setHours(0,0,0,0);const a=j(s),r=$(e,0);r.setFullYear(n,0,4),r.setHours(0,0,0,0);const i=j(r);return t.getTime()>=a.getTime()?n+1:t.getTime()>=i.getTime()?n:n-1}function U(e){const t=w(e);return t.setHours(0,0,0,0),t}function dt(e){const t=w(e),n=new Date(Date.UTC(t.getFullYear(),t.getMonth(),t.getDate(),t.getHours(),t.getMinutes(),t.getSeconds(),t.getMilliseconds()));return n.setUTCFullYear(t.getFullYear()),+e-+n}function St(e,t){const n=U(e),s=U(t),a=+n-dt(n),r=+s-dt(s);return Math.round((a-r)/Sn)}function vt(e){const t=de(e),n=$(e,0);return n.setFullYear(t,0,4),n.setHours(0,0,0,0),j(n)}function Dn(e,t){return re(e,t*ie)}function Tn(e,t){const n=t*3;return xt(e,n)}function ce(e,t){const n=t*7;return it(e,n)}function Mn(e,t){return xt(e,t*12)}function R(e,t){const n=w(e),s=w(t),a=n.getTime()-s.getTime();return a<0?-1:a>0?1:a}function $n(e,t){const n=U(e),s=U(t);return+n==+s}function Hn(e){return e instanceof Date||typeof e=="object"&&Object.prototype.toString.call(e)==="[object Date]"}function Wn(e){if(!Hn(e)&&typeof e!="number")return!1;const t=w(e);return!isNaN(Number(t))}function _t(e,t){const n=j(e),s=j(t),a=+n-dt(n),r=+s-dt(s);return Math.round((a-r)/ot)}function In(e,t){const n=w(e),s=w(t),a=n.getFullYear()-s.getFullYear(),r=n.getMonth()-s.getMonth();return a*12+r}function En(e,t){const n=w(e),s=w(t);return n.getFullYear()-s.getFullYear()}function Dt(e){return t=>{const n=(e?Math[e]:Math.trunc)(t);return n===0?0:n}}function ue(e,t){return+w(e)-+w(t)}function Pn(e,t,n){const s=ue(e,t)/oe;return Dt(n?.roundingMethod)(s)}function Cn(e,t,n){const s=ue(e,t)/ie;return Dt(n?.roundingMethod)(s)}function le(e){const t=w(e);return t.setHours(23,59,59,999),t}function Tt(e){const t=w(e),n=t.getMonth();return t.setFullYear(t.getFullYear(),n+1,0),t.setHours(23,59,59,999),t}function On(e){const t=w(e);return+le(t)==+Tt(t)}function he(e,t){const n=w(e),s=w(t),a=R(n,s),r=Math.abs(In(n,s));let i;if(r<1)i=0;else{n.getMonth()===1&&n.getDate()>27&&n.setDate(30),n.setMonth(n.getMonth()-a*r);let o=R(n,s)===-a;On(w(e))&&r===1&&R(e,s)===1&&(o=!1),i=a*(r-Number(o))}return i===0?0:i}function Nn(e,t,n){const s=he(e,t)/3;return Dt(n?.roundingMethod)(s)}function zn(e,t){const n=w(e),s=w(t),a=R(n,s),r=Math.abs(En(n,s));n.setFullYear(1584),s.setFullYear(1584);const i=R(n,s)===-a,o=a*(r-+i);return o===0?0:o}function J(e){const t=w(e),n=t.getMonth(),s=n-n%3;return t.setMonth(s,1),t.setHours(0,0,0,0),t}function fe(e){const t=w(e);return t.setDate(1),t.setHours(0,0,0,0),t}function An(e){const t=w(e),n=t.getFullYear();return t.setFullYear(n+1,0,0),t.setHours(23,59,59,999),t}function ge(e){const t=w(e),n=$(e,0);return n.setFullYear(t.getFullYear(),0,1),n.setHours(0,0,0,0),n}function Un(e){const t=w(e);return t.setMinutes(59,59,999),t}function Yn(e,t){const n=G(),s=t?.weekStartsOn??t?.locale?.options?.weekStartsOn??n.weekStartsOn??n.locale?.options?.weekStartsOn??0,a=w(e),r=a.getDay(),i=(r<s?-7:0)+6-(r-s);return a.setDate(a.getDate()+i),a.setHours(23,59,59,999),a}function Mt(e){const t=w(e),n=t.getMonth(),s=n-n%3+3;return t.setMonth(s,0),t.setHours(23,59,59,999),t}const Bn={lessThanXSeconds:{one:"less than a second",other:"less than {{count}} seconds"},xSeconds:{one:"1 second",other:"{{count}} seconds"},halfAMinute:"half a minute",lessThanXMinutes:{one:"less than a minute",other:"less than {{count}} minutes"},xMinutes:{one:"1 minute",other:"{{count}} minutes"},aboutXHours:{one:"about 1 hour",other:"about {{count}} hours"},xHours:{one:"1 hour",other:"{{count}} hours"},xDays:{one:"1 day",other:"{{count}} days"},aboutXWeeks:{one:"about 1 week",other:"about {{count}} weeks"},xWeeks:{one:"1 week",other:"{{count}} weeks"},aboutXMonths:{one:"about 1 month",other:"about {{count}} months"},xMonths:{one:"1 month",other:"{{count}} months"},aboutXYears:{one:"about 1 year",other:"about {{count}} years"},xYears:{one:"1 year",other:"{{count}} years"},overXYears:{one:"over 1 year",other:"over {{count}} years"},almostXYears:{one:"almost 1 year",other:"almost {{count}} years"}},Fn=(e,t,n)=>{let s;const a=Bn[e];return typeof a=="string"?s=a:t===1?s=a.one:s=a.other.replace("{{count}}",t.toString()),n?.addSuffix?n.comparison&&n.comparison>0?"in "+s:s+" ago":s};function $t(e){return(t={})=>{const n=t.width?String(t.width):e.defaultWidth;return e.formats[n]||e.formats[e.defaultWidth]}}const jn={full:"EEEE, MMMM do, y",long:"MMMM do, y",medium:"MMM d, y",short:"MM/dd/yyyy"},qn={full:"h:mm:ss a zzzz",long:"h:mm:ss a z",medium:"h:mm:ss a",short:"h:mm a"},Ln={full:"{{date}} 'at' {{time}}",long:"{{date}} 'at' {{time}}",medium:"{{date}}, {{time}}",short:"{{date}}, {{time}}"},Xn={date:$t({formats:jn,defaultWidth:"full"}),time:$t({formats:qn,defaultWidth:"full"}),dateTime:$t({formats:Ln,defaultWidth:"full"})},Qn={lastWeek:"'last' eeee 'at' p",yesterday:"'yesterday at' p",today:"'today at' p",tomorrow:"'tomorrow at' p",nextWeek:"eeee 'at' p",other:"P"},Gn=(e,t,n,s)=>Qn[e];function V(e){return(t,n)=>{const s=n?.context?String(n.context):"standalone";let a;if(s==="formatting"&&e.formattingValues){const i=e.defaultFormattingWidth||e.defaultWidth,o=n?.width?String(n.width):i;a=e.formattingValues[o]||e.formattingValues[i]}else{const i=e.defaultWidth,o=n?.width?String(n.width):e.defaultWidth;a=e.values[o]||e.values[i]}const r=e.argumentCallback?e.argumentCallback(t):t;return a[r]}}const Rn={narrow:["B","A"],abbreviated:["BC","AD"],wide:["Before Christ","Anno Domini"]},Jn={narrow:["1","2","3","4"],abbreviated:["Q1","Q2","Q3","Q4"],wide:["1st quarter","2nd quarter","3rd quarter","4th quarter"]},Vn={narrow:["J","F","M","A","M","J","J","A","S","O","N","D"],abbreviated:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],wide:["January","February","March","April","May","June","July","August","September","October","November","December"]},Kn={narrow:["S","M","T","W","T","F","S"],short:["Su","Mo","Tu","We","Th","Fr","Sa"],abbreviated:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],wide:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]},Zn={narrow:{am:"a",pm:"p",midnight:"mi",noon:"n",morning:"morning",afternoon:"afternoon",evening:"evening",night:"night"},abbreviated:{am:"AM",pm:"PM",midnight:"midnight",noon:"noon",morning:"morning",afternoon:"afternoon",evening:"evening",night:"night"},wide:{am:"a.m.",pm:"p.m.",midnight:"midnight",noon:"noon",morning:"morning",afternoon:"afternoon",evening:"evening",night:"night"}},ts={narrow:{am:"a",pm:"p",midnight:"mi",noon:"n",morning:"in the morning",afternoon:"in the afternoon",evening:"in the evening",night:"at night"},abbreviated:{am:"AM",pm:"PM",midnight:"midnight",noon:"noon",morning:"in the morning",afternoon:"in the afternoon",evening:"in the evening",night:"at night"},wide:{am:"a.m.",pm:"p.m.",midnight:"midnight",noon:"noon",morning:"in the morning",afternoon:"in the afternoon",evening:"in the evening",night:"at night"}},es=(e,t)=>{const n=Number(e),s=n%100;if(s>20||s<10)switch(s%10){case 1:return n+"st";case 2:return n+"nd";case 3:return n+"rd"}return n+"th"},ns={ordinalNumber:es,era:V({values:Rn,defaultWidth:"wide"}),quarter:V({values:Jn,defaultWidth:"wide",argumentCallback:e=>e-1}),month:V({values:Vn,defaultWidth:"wide"}),day:V({values:Kn,defaultWidth:"wide"}),dayPeriod:V({values:Zn,defaultWidth:"wide",formattingValues:ts,defaultFormattingWidth:"wide"})};function K(e){return(t,n={})=>{const s=n.width,a=s&&e.matchPatterns[s]||e.matchPatterns[e.defaultMatchWidth],r=t.match(a);if(!r)return null;const i=r[0],o=s&&e.parsePatterns[s]||e.parsePatterns[e.defaultParseWidth],d=Array.isArray(o)?as(o,l=>l.test(i)):ss(o,l=>l.test(i));let c;c=e.valueCallback?e.valueCallback(d):d,c=n.valueCallback?n.valueCallback(c):c;const u=t.slice(i.length);return{value:c,rest:u}}}function ss(e,t){for(const n in e)if(Object.prototype.hasOwnProperty.call(e,n)&&t(e[n]))return n}function as(e,t){for(let n=0;n<e.length;n++)if(t(e[n]))return n}function rs(e){return(t,n={})=>{const s=t.match(e.matchPattern);if(!s)return null;const a=s[0],r=t.match(e.parsePattern);if(!r)return null;let i=e.valueCallback?e.valueCallback(r[0]):r[0];i=n.valueCallback?n.valueCallback(i):i;const o=t.slice(a.length);return{value:i,rest:o}}}const is=/^(\d+)(th|st|nd|rd)?/i,os=/\d+/i,ds={narrow:/^(b|a)/i,abbreviated:/^(b\.?\s?c\.?|b\.?\s?c\.?\s?e\.?|a\.?\s?d\.?|c\.?\s?e\.?)/i,wide:/^(before christ|before common era|anno domini|common era)/i},cs={any:[/^b/i,/^(a|c)/i]},us={narrow:/^[1234]/i,abbreviated:/^q[1234]/i,wide:/^[1234](th|st|nd|rd)? quarter/i},ls={any:[/1/i,/2/i,/3/i,/4/i]},hs={narrow:/^[jfmasond]/i,abbreviated:/^(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)/i,wide:/^(january|february|march|april|may|june|july|august|september|october|november|december)/i},fs={narrow:[/^j/i,/^f/i,/^m/i,/^a/i,/^m/i,/^j/i,/^j/i,/^a/i,/^s/i,/^o/i,/^n/i,/^d/i],any:[/^ja/i,/^f/i,/^mar/i,/^ap/i,/^may/i,/^jun/i,/^jul/i,/^au/i,/^s/i,/^o/i,/^n/i,/^d/i]},gs={narrow:/^[smtwf]/i,short:/^(su|mo|tu|we|th|fr|sa)/i,abbreviated:/^(sun|mon|tue|wed|thu|fri|sat)/i,wide:/^(sunday|monday|tuesday|wednesday|thursday|friday|saturday)/i},ps={narrow:[/^s/i,/^m/i,/^t/i,/^w/i,/^t/i,/^f/i,/^s/i],any:[/^su/i,/^m/i,/^tu/i,/^w/i,/^th/i,/^f/i,/^sa/i]},ms={narrow:/^(a|p|mi|n|(in the|at) (morning|afternoon|evening|night))/i,any:/^([ap]\.?\s?m\.?|midnight|noon|(in the|at) (morning|afternoon|evening|night))/i},ks={any:{am:/^a/i,pm:/^p/i,midnight:/^mi/i,noon:/^no/i,morning:/morning/i,afternoon:/afternoon/i,evening:/evening/i,night:/night/i}},ys={ordinalNumber:rs({matchPattern:is,parsePattern:os,valueCallback:e=>parseInt(e,10)}),era:K({matchPatterns:ds,defaultMatchWidth:"wide",parsePatterns:cs,defaultParseWidth:"any"}),quarter:K({matchPatterns:us,defaultMatchWidth:"wide",parsePatterns:ls,defaultParseWidth:"any",valueCallback:e=>e+1}),month:K({matchPatterns:hs,defaultMatchWidth:"wide",parsePatterns:fs,defaultParseWidth:"any"}),day:K({matchPatterns:gs,defaultMatchWidth:"wide",parsePatterns:ps,defaultParseWidth:"any"}),dayPeriod:K({matchPatterns:ms,defaultMatchWidth:"any",parsePatterns:ks,defaultParseWidth:"any"})},bs={code:"en-US",formatDistance:Fn,formatLong:Xn,formatRelative:Gn,localize:ns,match:ys,options:{weekStartsOn:0,firstWeekContainsDate:1}};function ws(e){const t=w(e);return St(t,ge(t))+1}function xs(e){const t=w(e),n=+j(t)-+vt(t);return Math.round(n/ot)+1}function pe(e,t){const n=w(e),s=n.getFullYear(),a=G(),r=t?.firstWeekContainsDate??t?.locale?.options?.firstWeekContainsDate??a.firstWeekContainsDate??a.locale?.options?.firstWeekContainsDate??1,i=$(e,0);i.setFullYear(s+1,0,r),i.setHours(0,0,0,0);const o=C(i,t),d=$(e,0);d.setFullYear(s,0,r),d.setHours(0,0,0,0);const c=C(d,t);return n.getTime()>=o.getTime()?s+1:n.getTime()>=c.getTime()?s:s-1}function Ss(e,t){const n=G(),s=t?.firstWeekContainsDate??t?.locale?.options?.firstWeekContainsDate??n.firstWeekContainsDate??n.locale?.options?.firstWeekContainsDate??1,a=pe(e,t),r=$(e,0);return r.setFullYear(a,0,s),r.setHours(0,0,0,0),C(r,t)}function vs(e,t){const n=w(e),s=+C(n,t)-+Ss(n,t);return Math.round(s/ot)+1}function D(e,t){const n=e<0?"-":"",s=Math.abs(e).toString().padStart(t,"0");return n+s}const O={y(e,t){const n=e.getFullYear(),s=n>0?n:1-n;return D(t==="yy"?s%100:s,t.length)},M(e,t){const n=e.getMonth();return t==="M"?String(n+1):D(n+1,2)},d(e,t){return D(e.getDate(),t.length)},a(e,t){const n=e.getHours()/12>=1?"pm":"am";switch(t){case"a":case"aa":return n.toUpperCase();case"aaa":return n;case"aaaaa":return n[0];case"aaaa":default:return n==="am"?"a.m.":"p.m."}},h(e,t){return D(e.getHours()%12||12,t.length)},H(e,t){return D(e.getHours(),t.length)},m(e,t){return D(e.getMinutes(),t.length)},s(e,t){return D(e.getSeconds(),t.length)},S(e,t){const n=t.length,s=e.getMilliseconds(),a=Math.trunc(s*Math.pow(10,n-3));return D(a,t.length)}},q={midnight:"midnight",noon:"noon",morning:"morning",afternoon:"afternoon",evening:"evening",night:"night"},me={G:function(e,t,n){const s=e.getFullYear()>0?1:0;switch(t){case"G":case"GG":case"GGG":return n.era(s,{width:"abbreviated"});case"GGGGG":return n.era(s,{width:"narrow"});case"GGGG":default:return n.era(s,{width:"wide"})}},y:function(e,t,n){if(t==="yo"){const s=e.getFullYear(),a=s>0?s:1-s;return n.ordinalNumber(a,{unit:"year"})}return O.y(e,t)},Y:function(e,t,n,s){const a=pe(e,s),r=a>0?a:1-a;if(t==="YY"){const i=r%100;return D(i,2)}return t==="Yo"?n.ordinalNumber(r,{unit:"year"}):D(r,t.length)},R:function(e,t){const n=de(e);return D(n,t.length)},u:function(e,t){const n=e.getFullYear();return D(n,t.length)},Q:function(e,t,n){const s=Math.ceil((e.getMonth()+1)/3);switch(t){case"Q":return String(s);case"QQ":return D(s,2);case"Qo":return n.ordinalNumber(s,{unit:"quarter"});case"QQQ":return n.quarter(s,{width:"abbreviated",context:"formatting"});case"QQQQQ":return n.quarter(s,{width:"narrow",context:"formatting"});case"QQQQ":default:return n.quarter(s,{width:"wide",context:"formatting"})}},q:function(e,t,n){const s=Math.ceil((e.getMonth()+1)/3);switch(t){case"q":return String(s);case"qq":return D(s,2);case"qo":return n.ordinalNumber(s,{unit:"quarter"});case"qqq":return n.quarter(s,{width:"abbreviated",context:"standalone"});case"qqqqq":return n.quarter(s,{width:"narrow",context:"standalone"});case"qqqq":default:return n.quarter(s,{width:"wide",context:"standalone"})}},M:function(e,t,n){const s=e.getMonth();switch(t){case"M":case"MM":return O.M(e,t);case"Mo":return n.ordinalNumber(s+1,{unit:"month"});case"MMM":return n.month(s,{width:"abbreviated",context:"formatting"});case"MMMMM":return n.month(s,{width:"narrow",context:"formatting"});case"MMMM":default:return n.month(s,{width:"wide",context:"formatting"})}},L:function(e,t,n){const s=e.getMonth();switch(t){case"L":return String(s+1);case"LL":return D(s+1,2);case"Lo":return n.ordinalNumber(s+1,{unit:"month"});case"LLL":return n.month(s,{width:"abbreviated",context:"standalone"});case"LLLLL":return n.month(s,{width:"narrow",context:"standalone"});case"LLLL":default:return n.month(s,{width:"wide",context:"standalone"})}},w:function(e,t,n,s){const a=vs(e,s);return t==="wo"?n.ordinalNumber(a,{unit:"week"}):D(a,t.length)},I:function(e,t,n){const s=xs(e);return t==="Io"?n.ordinalNumber(s,{unit:"week"}):D(s,t.length)},d:function(e,t,n){return t==="do"?n.ordinalNumber(e.getDate(),{unit:"date"}):O.d(e,t)},D:function(e,t,n){const s=ws(e);return t==="Do"?n.ordinalNumber(s,{unit:"dayOfYear"}):D(s,t.length)},E:function(e,t,n){const s=e.getDay();switch(t){case"E":case"EE":case"EEE":return n.day(s,{width:"abbreviated",context:"formatting"});case"EEEEE":return n.day(s,{width:"narrow",context:"formatting"});case"EEEEEE":return n.day(s,{width:"short",context:"formatting"});case"EEEE":default:return n.day(s,{width:"wide",context:"formatting"})}},e:function(e,t,n,s){const a=e.getDay(),r=(a-s.weekStartsOn+8)%7||7;switch(t){case"e":return String(r);case"ee":return D(r,2);case"eo":return n.ordinalNumber(r,{unit:"day"});case"eee":return n.day(a,{width:"abbreviated",context:"formatting"});case"eeeee":return n.day(a,{width:"narrow",context:"formatting"});case"eeeeee":return n.day(a,{width:"short",context:"formatting"});case"eeee":default:return n.day(a,{width:"wide",context:"formatting"})}},c:function(e,t,n,s){const a=e.getDay(),r=(a-s.weekStartsOn+8)%7||7;switch(t){case"c":return String(r);case"cc":return D(r,t.length);case"co":return n.ordinalNumber(r,{unit:"day"});case"ccc":return n.day(a,{width:"abbreviated",context:"standalone"});case"ccccc":return n.day(a,{width:"narrow",context:"standalone"});case"cccccc":return n.day(a,{width:"short",context:"standalone"});case"cccc":default:return n.day(a,{width:"wide",context:"standalone"})}},i:function(e,t,n){const s=e.getDay(),a=s===0?7:s;switch(t){case"i":return String(a);case"ii":return D(a,t.length);case"io":return n.ordinalNumber(a,{unit:"day"});case"iii":return n.day(s,{width:"abbreviated",context:"formatting"});case"iiiii":return n.day(s,{width:"narrow",context:"formatting"});case"iiiiii":return n.day(s,{width:"short",context:"formatting"});case"iiii":default:return n.day(s,{width:"wide",context:"formatting"})}},a:function(e,t,n){const s=e.getHours()/12>=1?"pm":"am";switch(t){case"a":case"aa":return n.dayPeriod(s,{width:"abbreviated",context:"formatting"});case"aaa":return n.dayPeriod(s,{width:"abbreviated",context:"formatting"}).toLowerCase();case"aaaaa":return n.dayPeriod(s,{width:"narrow",context:"formatting"});case"aaaa":default:return n.dayPeriod(s,{width:"wide",context:"formatting"})}},b:function(e,t,n){const s=e.getHours();let a;switch(s===12?a=q.noon:s===0?a=q.midnight:a=s/12>=1?"pm":"am",t){case"b":case"bb":return n.dayPeriod(a,{width:"abbreviated",context:"formatting"});case"bbb":return n.dayPeriod(a,{width:"abbreviated",context:"formatting"}).toLowerCase();case"bbbbb":return n.dayPeriod(a,{width:"narrow",context:"formatting"});case"bbbb":default:return n.dayPeriod(a,{width:"wide",context:"formatting"})}},B:function(e,t,n){const s=e.getHours();let a;switch(s>=17?a=q.evening:s>=12?a=q.afternoon:s>=4?a=q.morning:a=q.night,t){case"B":case"BB":case"BBB":return n.dayPeriod(a,{width:"abbreviated",context:"formatting"});case"BBBBB":return n.dayPeriod(a,{width:"narrow",context:"formatting"});case"BBBB":default:return n.dayPeriod(a,{width:"wide",context:"formatting"})}},h:function(e,t,n){if(t==="ho"){let s=e.getHours()%12;return s===0&&(s=12),n.ordinalNumber(s,{unit:"hour"})}return O.h(e,t)},H:function(e,t,n){return t==="Ho"?n.ordinalNumber(e.getHours(),{unit:"hour"}):O.H(e,t)},K:function(e,t,n){const s=e.getHours()%12;return t==="Ko"?n.ordinalNumber(s,{unit:"hour"}):D(s,t.length)},k:function(e,t,n){let s=e.getHours();return s===0&&(s=24),t==="ko"?n.ordinalNumber(s,{unit:"hour"}):D(s,t.length)},m:function(e,t,n){return t==="mo"?n.ordinalNumber(e.getMinutes(),{unit:"minute"}):O.m(e,t)},s:function(e,t,n){return t==="so"?n.ordinalNumber(e.getSeconds(),{unit:"second"}):O.s(e,t)},S:function(e,t){return O.S(e,t)},X:function(e,t,n){const s=e.getTimezoneOffset();if(s===0)return"Z";switch(t){case"X":return ye(s);case"XXXX":case"XX":return Y(s);case"XXXXX":case"XXX":default:return Y(s,":")}},x:function(e,t,n){const s=e.getTimezoneOffset();switch(t){case"x":return ye(s);case"xxxx":case"xx":return Y(s);case"xxxxx":case"xxx":default:return Y(s,":")}},O:function(e,t,n){const s=e.getTimezoneOffset();switch(t){case"O":case"OO":case"OOO":return"GMT"+ke(s,":");case"OOOO":default:return"GMT"+Y(s,":")}},z:function(e,t,n){const s=e.getTimezoneOffset();switch(t){case"z":case"zz":case"zzz":return"GMT"+ke(s,":");case"zzzz":default:return"GMT"+Y(s,":")}},t:function(e,t,n){const s=Math.trunc(e.getTime()/1e3);return D(s,t.length)},T:function(e,t,n){const s=e.getTime();return D(s,t.length)}};function ke(e,t=""){const n=e>0?"-":"+",s=Math.abs(e),a=Math.trunc(s/60),r=s%60;return r===0?n+String(a):n+String(a)+t+D(r,2)}function ye(e,t){return e%60===0?(e>0?"-":"+")+D(Math.abs(e)/60,2):Y(e,t)}function Y(e,t=""){const n=e>0?"-":"+",s=Math.abs(e),a=D(Math.trunc(s/60),2),r=D(s%60,2);return n+a+t+r}const be=(e,t)=>{switch(e){case"P":return t.date({width:"short"});case"PP":return t.date({width:"medium"});case"PPP":return t.date({width:"long"});case"PPPP":default:return t.date({width:"full"})}},we=(e,t)=>{switch(e){case"p":return t.time({width:"short"});case"pp":return t.time({width:"medium"});case"ppp":return t.time({width:"long"});case"pppp":default:return t.time({width:"full"})}},_s=(e,t)=>{const n=e.match(/(P+)(p+)?/)||[],s=n[1],a=n[2];if(!a)return be(e,t);let r;switch(s){case"P":r=t.dateTime({width:"short"});break;case"PP":r=t.dateTime({width:"medium"});break;case"PPP":r=t.dateTime({width:"long"});break;case"PPPP":default:r=t.dateTime({width:"full"});break}return r.replace("{{date}}",be(s,t)).replace("{{time}}",we(a,t))},Ds={p:we,P:_s},Ts=/^D+$/,Ms=/^Y+$/,$s=["D","DD","YY","YYYY"];function Hs(e){return Ts.test(e)}function Ws(e){return Ms.test(e)}function Is(e,t,n){const s=Es(e,t,n);if(console.warn(s),$s.includes(e))throw new RangeError(s)}function Es(e,t,n){const s=e[0]==="Y"?"years":"days of the month";return`Use \`${e.toLowerCase()}\` instead of \`${e}\` (in \`${t}\`) for formatting ${s} to the input \`${n}\`; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md`}const Ps=/[yYQqMLwIdDecihHKkms]o|(\w)\1*|''|'(''|[^'])+('|$)|./g,Cs=/P+p+|P+|p+|''|'(''|[^'])+('|$)|./g,Os=/^'([^]*?)'?$/,Ns=/''/g,zs=/[a-zA-Z]/;function As(e,t,n){const s=G(),a=n?.locale??s.locale??bs,r=n?.firstWeekContainsDate??n?.locale?.options?.firstWeekContainsDate??s.firstWeekContainsDate??s.locale?.options?.firstWeekContainsDate??1,i=n?.weekStartsOn??n?.locale?.options?.weekStartsOn??s.weekStartsOn??s.locale?.options?.weekStartsOn??0,o=w(e);if(!Wn(o))throw new RangeError("Invalid time value");let d=t.match(Cs).map(u=>{const l=u[0];if(l==="p"||l==="P"){const h=Ds[l];return h(u,a.formatLong)}return u}).join("").match(Ps).map(u=>{if(u==="''")return{isToken:!1,value:"'"};const l=u[0];if(l==="'")return{isToken:!1,value:Us(u)};if(me[l])return{isToken:!0,value:u};if(l.match(zs))throw new RangeError("Format string contains an unescaped latin alphabet character `"+l+"`");return{isToken:!1,value:u}});a.localize.preprocessor&&(d=a.localize.preprocessor(o,d));const c={firstWeekContainsDate:r,weekStartsOn:i,locale:a};return d.map(u=>{if(!u.isToken)return u.value;const l=u.value;(!n?.useAdditionalWeekYearTokens&&Ws(l)||!n?.useAdditionalDayOfYearTokens&&Hs(l))&&Is(l,t,String(e));const h=me[l[0]];return h(o,l,a.localize,c)}).join("")}function Us(e){const t=e.match(Os);return t?t[1].replace(Ns,"'"):e}function xe(e){const t=w(e),n=t.getFullYear(),s=t.getMonth(),a=$(e,0);return a.setFullYear(n,s+1,0),a.setHours(0,0,0,0),a.getDate()}function Ys(e){const t=w(e).getFullYear();return t%400===0||t%4===0&&t%100!==0}function Se(e){const t=w(e);return String(new Date(t))==="Invalid Date"?NaN:Ys(t)?366:365}function Bs(e){const t=vt(e),n=+vt(ce(t,60))-+t;return Math.round(n/ot)}function H(e,t){const n=w(e),s=w(t);return+n==+s}function Fs(e){const t=w(e);return t.setMinutes(0,0,0),t}function js(e,t,n){const s=C(e,n),a=C(t,n);return+s==+a}function qs(e,t){const n=w(e),s=w(t);return n.getFullYear()===s.getFullYear()&&n.getMonth()===s.getMonth()}function Ls(e,t){const n=J(e),s=J(t);return+n==+s}function Xs(e,t){const n=w(e),s=w(t);return n.getFullYear()===s.getFullYear()}const Ht={year:zn,quarter:Nn,month:he,week:_t,day:St,hour:Pn,minute:Cn},N={year:{quarter:4,month:12,week:Bs,day:Qs,hour:Gs},quarter:{month:3,week:Rs,day:ve,hour:Js},month:{week:Vs,day:Ks,hour:Zs},week:{day:7,hour:24*7},day:{hour:24},hour:{minute:60}};function Qs(e){return e?Se(e):365}function Gs(e){return Se(e)*24}function Rs(e){const t=J(e),n=it(U(Mt(e)),1);return _t(n,t)}function ve(e){if(e){const t=J(e),n=Mt(e);return St(n,t)+1}return 91}function Js(e){return ve(e)*24}function Vs(e){if(e){const t=fe(e),n=it(U(Tt(e)),1);return _t(n,t)}return 5}function Ks(e){return e?xe(e):30}function Zs(e){return xe(e)*24}function ct(e,t,n){const s=N[e][t];return s?typeof s=="number"?s:s(n):1}function ta(e,t){return e===t||!!(N[e]&&N[e][t])}const ut={year:Mn,quarter:Tn,month:xt,week:ce,day:it,hour:vn,minute:Dn};function E(e,t,n){if(t){if(e==="day")return(s,a)=>t.getWorkingDays(a,s,!0);if(e==="hour")return(s,a)=>t.getWorkingHours(a,s,!0)}return(s,a,r,i)=>!N[e][r]||typeof N[e][r]=="number"||Te(e,s,a,n)?Z(e,s,a,r,i,n):ea(s,a,e,r,i,n)}function Z(e,t,n,s,a,r){const i=s||e;let o=n,d=t;if(a&&(o=I(i,n,r),d=I(i,t,r),d<t&&(d=T(i)(d,1))),e!==i){const c=Ht[i](d,o),u=ct(e,i,n);return c/u}else return Ht[i](d,o)}function ea(e,t,n,s,a,r){let i=0;const o=I(n,t,r);if(t>o){const c=ut[n](o,1);i=Z(n,c,t,s,void 0,r),t=c}let d=0;return Te(n,t,e,r)||(d=Z(n,I(n,e,r),t,void 0,void 0,r),t=ut[n](t,d)),d+=i+Z(n,e,t,s,void 0,r),!d&&a&&(d=Z(n,e,t,s,a,r)),d}function T(e,t){if(t){if(e==="day")return(n,s)=>t.addWorkingDays(n,s,!0);if(e==="hour")return(n,s)=>t.addWorkingHours(n,s)}return ut[e]}const _e={year:ge,quarter:J,month:fe,week:(e,t)=>C(e,{weekStartsOn:t}),day:U,hour:Fs};function I(e,t,n){const s=_e[e];return s?s(t,n):new Date(t)}const na={year:An,quarter:Mt,month:Tt,week:(e,t)=>Yn(e,{weekStartsOn:t}),day:le,hour:Un},De={year:Xs,quarter:Ls,month:qs,week:(e,t,n)=>js(e,t,{weekStartsOn:n}),day:$n};function Te(e,t,n,s){const a=De[e];return a?a(t,n,s):!1}const sa={start:_e,end:na,add:ut,isSame:De,diff:Ht,smallerCount:N},Me=e=>typeof e=="function"?e(new Date):e;function aa(e,t){for(const n in t){if(n==="smallerCount"){const s=Object.keys(t[n]).sort((o,d)=>W.indexOf(o)-W.indexOf(d)).shift();let a=W.indexOf(s);const r=t[n][s],i=Me(r);for(let o=a-1;o>=0;o--){const d=W[o],c=Me(N[d][s]);if(i<=c)break;a=o}W.splice(a,0,e)}if(n==="biggerCount")for(const s in t[n])N[s][e]=t[n][s];else sa[n][e]=t[n]}}function Wt(e,t=1,n){return n.isWorkingDay(e)||(e=t>0?n.getNextWorkingDay(e):n.getPreviousWorkingDay(e)),e}function lt(e){return(t,n)=>{if(n>0)for(let s=0;s<n;s++)t=e.getNextWorkingDay(t);if(n<0)for(let s=0;s>n;s--)t=e.getPreviousWorkingDay(t);return t}}function L(e){const t=new Date;return e.map(n=>({item:n,len:T(n.unit)(t,1)})).sort((n,s)=>n.len<s.len?-1:1)[0].item}const W=["year","quarter","month","week","day","hour"],It=50,Et=300;function ra(e,t,n,s,a){let r=e,i=t,o=!1,d=!1;a&&a.forEach(u=>{(!e||n)&&(!r||u.start<=r)&&(r=u.start,o=!0);const l=u.type==="milestone"?u.start:u.end;(!t||n)&&(!i||l>=i)&&(i=l,d=!0)});const c=T(s||"day");return r?o&&(r=c(r,-1)):i?r=c(i,-30):r=new Date,i?d&&(i=c(i,1)):i=c(r,30),{_start:r,_end:i}}function ia(e,t,n,s,a,r,i){const o=L(i).unit,d=E(o,void 0,r),c=d(t,e,"",!0),u=I(o,t,r);e=I(o,e,r),t=u<t?T(o)(u,1):u;const l=c*s,h=a*i.length,f=i.map(g=>{const m=[],k=T(g.unit);let y=I(g.unit,e,r);for(;y<t;){const b=k(y,g.step),_=y<e?e:y,x=b>t?t:b,S=d(x,_,"",!0)*s,v=typeof g.format=="function"?g.format(y,b):g.format;let M="";g.css&&(M+=typeof g.css=="function"?g.css(y):g.css),m.push({width:S,value:v,date:_,css:M,unit:g.unit}),y=b}return{cells:m,add:k,height:a}});let p=s;return o!==n&&(p=Math.round(p/ct(o,n))||1),{rows:f,width:l,height:h,diff:d,start:e,end:t,lengthUnit:n,minUnit:o,lengthUnitWidth:p}}function oa(e,t,n,s){const a=typeof e=="boolean"?{}:e,r=W.indexOf(L(n).unit);if(typeof a.level>"u"&&(a.level=r),a.levels)a.levels.forEach(d=>{d.minCellWidth||(d.minCellWidth=ht(a.minCellWidth,It)),d.maxCellWidth||(d.maxCellWidth=ht(a.maxCellWidth,Et))});else{const d=[],c=n.length||1,u=ht(a.minCellWidth,It),l=ht(a.maxCellWidth,Et);n.forEach(h=>{h.format&&!t[h.unit]&&(t[h.unit]=h.format)}),W.forEach((h,f)=>{if(f===r)d.push({minCellWidth:u,maxCellWidth:l,scales:n});else{const p=[];if(f)for(let g=c-1;g>0;g--){const m=W[f-g];m&&p.push({unit:m,step:1,format:t[m]})}p.push({unit:h,step:1,format:t[h]}),d.push({minCellWidth:u,maxCellWidth:l,scales:p})}}),a.levels=d}a.levels[a.level]||(a.level=0);const i=a.levels[a.level],o=Math.min(Math.max(s,i.minCellWidth),i.maxCellWidth);return{zoom:a,scales:i.scales,cellWidth:o}}function da(e,t,n,s,a,r,i){e.level=n;let o;const d=s.scales||s,c=L(d).unit,u=ca(c,a);if(t===-1){const f=ct(c,a);o=i*f}else{const f=ct(L(r).unit,c);o=Math.round(i/f)}const l=s.minCellWidth??It,h=s.maxCellWidth??Et;return{scales:d,cellWidth:Math.min(h,Math.max(l,o)),lengthUnit:u,zoom:e}}function ca(e,t){const n=W.indexOf(e),s=W.indexOf(t);return s>=n?e==="hour"?"hour":"day":W[s]}function ht(e,t){return e??t}function Pt(){let e=!0;return e=!1,e}const Ct=8,$e=4,ua=3,He=7,la=Ct+$e;function We(e,t,n,s){(e.open||e.type!="summary")&&e.data?.forEach(a=>{typeof a.$x>"u"&&Ee(a,n,s),a.$x+=t,We(a,t,n,s)})}function Ot(e,t,n,s){const a=e.getSummaryId(t.id);if(a){const r=e.byId(a),i={xMin:1/0,xMax:0};Ie(r,i,n,s),r.$x=i.xMin,r.$w=i.xMax-i.xMin,Ot(e,r,n,s)}}function Ie(e,t,n,s){e.data?.forEach(a=>{if(!a.unscheduled){typeof a.$x>"u"&&Ee(a,n,s);const r=a.type==="milestone"&&a.$h?a.$h/2:0;t.xMin>a.$x&&(t.xMin=a.$x+r);const i=a.$x+a.$w-r;t.xMax<i&&(t.xMax=i)}a.type!=="summary"&&Ie(a,t,n,s)})}function Ee(e,t,n){e.$x=Math.round(t.diff(e.start,t.start,t.lengthUnit)*n),e.$w=Math.round(t.diff(e.end,e.start,t.lengthUnit,!0)*n)}function Nt(e,t){let n;t&&(n=t.filter(a=>a.parent==e.id));const s={data:n,...e};if(s.data?.length)s.data.forEach(a=>{if(a.unscheduled&&!a.data)return;(t||a.type!="summary"&&a.data)&&(a.unscheduled&&(a={...a,start:void 0,end:void 0}),a=Nt(a,t)),a.start&&(!s.start||s.start>a.start)&&(s.start=new Date(a.start));const r=a.end||a.start;r&&(!s.end||s.end<r)&&(s.end=new Date(r))});else if(e.type==="summary")throw Error("Summary tasks must have start and end dates if they have no subtasks");return s}function Pe(e,t,n){return Ce(e,t,n,!1),n.splitTasks&&e.segments?.forEach(s=>{Pe(s,t,{...n,baselines:!1}),s.$x-=e.$x}),n.baselines&&Ce(e,t,n,!0),e}function Ce(e,t,n,s){const{cellWidth:a,cellHeight:r,_scales:i,baselines:o}=n,{start:d,end:c,lengthUnit:u,diff:l}=i,h=(s?"base_":"")+"start",f=(s?"base_":"")+"end",p="$x"+(s?"_base":""),g="$y"+(s?"_base":""),m="$w"+(s?"_base":""),k="$h"+(s?"_base":""),y="$skip"+(s?"_baseline":"");let b=e[h],_=e[f];if(s&&!b){e[y]=!0;return}e[h]<d&&(e[f]<d||H(e[f],d))?b=_=d:e[h]>c&&(b=_=c),e[p]=Math.round(l(b,d,u)*a),e[g]=s?e.$y+e.$h+$e:r*t+ua,e[m]=Math.round(l(_,b,u,!0)*a),e[k]=s?Ct:o?r-He-la:r-He,e.type==="milestone"&&(e[p]=e[p]-e.$h/2,e[m]=e.$h,s&&(e[g]=e.$y+Ct,e[m]=e[k]=e.$h)),n.unscheduledTasks&&e.unscheduled&&!s?e.$skip=!0:e[y]=H(b,_)}function ha(e,t){if(Pt())return!1;const{mode:n,l:s,w:a,dx:r,index:i}=t,{segments:o}=e;if(i||n==="end"){if(r>0&&i<o.length-1){if(s+a+r>o[i+1].$x+e.$x)return!1}else if(r<0&&i){const d=n==="end"?a:0;if(s+r+d<o[i-1].$x+e.$x+o[i-1].$w)return!1}}return!0}function fa(e,t){if(Pt())return;const{segments:n}=e,{segmentIndex:s,mode:a}=t,r=n[s];(s||a!=="move")&&(t.index=s,t.l=r.$x+e.$x,t.w=r.$w,t.segment=!0)}const zt=20,ga=function(e,t,n,s,a){const r=Math.round(s/2)-3;if(!t||!n||!t.$y||!n.$y||t.$skip||n.$skip)return e.$p="",e.$pl=0,e;let i=!1,o=!1;switch(e.type){case"e2s":o=!0;break;case"s2s":i=!0,o=!0;break;case"s2e":i=!0;break}const d=i?t.$x:t.$x+t.$w,c=a?t.$y-7:t.$y,u=o?n.$x:n.$x+n.$w,l=a?n.$y-7:n.$y;if(d!==u||c!==l){const h=ma(d,c+r,u,l+r,i,o,s/2,a),f=ka(u,l+r,o);e.$p=`${h},${f}`,e.$pl=pa(e.$p)}return e};function pa(e){const t=e.split(",").map(Number),n=[];for(let a=0;a<t.length;a+=2)a+1<t.length&&n.push([t[a],t[a+1]]);let s=0;for(let a=0;a<n.length-1;a++){const[r,i]=n[a],[o,d]=n[a+1];s+=Math.hypot(o-r,d-i)}return s}function ma(e,t,n,s,a,r,i,o){const d=zt*(a?-1:1),c=zt*(r?-1:1),u=e+d,l=n+c,h=[e,t,u,t,0,0,0,0,l,s,n,s],f=l-u;let p=s-t;const g=r===a;return g||(l<=e+zt-2&&r||l>e&&!r)&&(p=o?p-i+6:p-i),g&&r&&u>l||g&&!r&&u<l?(h[4]=h[2]+f,h[5]=h[3],h[6]=h[4],h[7]=h[5]+p):(h[4]=h[2],h[5]=h[3]+p,h[6]=h[4]+f,h[7]=h[5]),h.join(",")}function ka(e,t,n){return n?`${e-5},${t-3},${e-5},${t+3},${e},${t}`:`${e+5},${t+3},${e+5},${t-3},${e},${t}`}function ya(e,t,n){if(t&&n){const s=n.x-t.x,a=n.y-t.y,r=(s>0?t.x:n.x)-e.left,i=(a>0?t.y:n.y)-e.top,o=`${s>0?0:-s},${a>0?0:-a},${s>0?s:0},${a>0?a:0}`;return{width:Math.abs(s),height:Math.abs(a),left:r,top:i,p:o}}else return null}function Oe(e){return e.map(t=>{const n=t.id||bt();return{...t,id:n}})}const Ne=["start","end","duration"];function ba(e,t){const{type:n,unscheduled:s}=e;return s||n==="summary"?!Ne.includes(t):n==="milestone"?!["end","duration"].includes(t):!0}function wa(e,t){return typeof t=="function"?t:Ne.includes(e)?(typeof t=="string"&&(t={type:t,config:{}}),t.config||(t.config={}),t.type==="datepicker"&&(t.config.buttons=["today"]),(n,s)=>ba(n,s.id)?t:null):t}function xa(e){return!e||!e.length?[]:e.map(t=>{const n=t.align||"left",s=t.id==="add-task",a=!s&&t.flexgrow?t.flexgrow:null,r=a?1:t.width||(s?50:120),i=t.editor&&wa(t.id,t.editor);return{width:r,align:n,header:t.header,id:t.id,template:t.template,_template:t._template,...a&&{flexgrow:a},cell:t.cell,resize:t.resize??!0,sort:t.sort??!s,...i&&{editor:i},...t.options&&{options:t.options}}})}const Sa=[{id:"text",header:"Task name",flexgrow:1,sort:!0},{id:"start",header:"Start date",align:"center",sort:!0},{id:"duration",header:"Duration",width:100,align:"center",sort:!0},{id:"add-task",header:"Add task",width:50,align:"center",sort:!1,resize:!1}];function tt(e,t,n,s){const{selected:a,tasks:r}=e.getState(),i=a.length,o=["edit-task","paste-task","edit-task:task","edit-task:segment"],d=["copy-task","cut-task"],c=["copy-task","cut-task","delete-task","indent-task:remove","move-task:down"],u=["add-task","undo","redo"],l=["indent-task:add","move-task:down","move-task:up"],h={"indent-task:remove":2},f=!i&&u.includes(t),p={parent:l.includes(t),level:h[t]};if(n=n||(i?a[a.length-1]:null),!(!n&&!f)){if(t!=="paste-task"&&(e._temp=null),o.includes(t)||f||a.length===1)ze(e,t,n,s);else if(i){const g=d.includes(t)?a:va(a,r,p);c.includes(t)&&g.reverse();const m=e.getHistory();m&&m.startBatch(),g.forEach((k,y)=>ze(e,t,k,s,y)),m&&m.endBatch()}}}function va(e,t,n){let s=e.map(a=>{const r=t.byId(a);return{id:a,level:r.$level,parent:r.parent,index:t.getIndexById(a)}});return(n.parent||n.level)&&(s=s.filter(a=>n.level&&a.level<=n.level||!e.includes(a.parent))),s.sort((a,r)=>a.level-r.level||a.index-r.index),s.map(a=>a.id)}function ze(e,t,n,s,a){const r=e.exec?e.exec:e.in.exec;let i=t.split(":")[0],o=t.split(":")[1];const d=n?.id||n;let c={id:d},u={},l=!1;if(i=="copy-task"||i=="cut-task"){e._temp||(e._temp=[]),e._temp.push({id:d,cut:i=="cut-task"});return}else if(i=="paste-task"){if(e._temp&&e._temp.length){const h=e.getHistory();h&&h.startBatch();const f=new Map;if(e._temp.forEach(p=>{const g={id:p.id,target:d,mode:"after"};r(p.cut?"move-task":"copy-task",g),f.set(p.id,g.id)}),!e._temp[0].cut){const{links:p}=e.getState(),g=e._temp.map(k=>k.id),m=[];p.forEach(k=>{g.includes(k.source)&&g.includes(k.target)&&m.push(k)}),m.forEach(k=>{r("add-link",{link:{source:f.get(k.source),target:f.get(k.target),type:k.type}})}),e._temp.forEach((k,y)=>{r("select-task",{id:f.get(k.id),toggle:!!y})})}h&&h.endBatch(),e._temp=null}return}else i==="add-task"?(u={task:{type:"task",text:s("New Task")},target:d,show:!0,select:!1},c={},l=!0):i==="edit-task"?(i="show-editor",o==="segment"&&typeof n=="object"&&(u=n)):i==="convert-task"?(i="update-task",u={task:{type:o}},o=void 0):i==="indent-task"&&(o=o==="add");if(i==="split-task"&&typeof n=="object")u=n;else if(i==="delete-task"&&o==="segment"&&typeof n=="object"){const h=e.getTask(d),{segmentIndex:f}=n,p=h.segments.filter((g,m)=>m!==f);r("update-task",{id:d,task:{segments:p}});return}typeof o<"u"&&(u={mode:o,...u}),c={...c,...u},r(i,c),l&&r("select-task",{id:c.id,toggle:!!a})}function Ae(e,t){return e.some(n=>n.data?Ae(n.data,t):n.id===t)}const Ue=(e,t)=>T(e,t),_a=(e,t)=>E(e,t);function Ye(e,t){Array.isArray(e)&&(e.forEach(n=>z(n,t)),e.forEach(n=>{if(n.type==="summary"&&!(n.start&&n.end)){const{start:s,end:a}=Nt(n,e);n.start=s,n.end=a,z(n,t)}}))}function z(e,t){e.unscheduled||At(e,t,!1),e.base_start&&At(e,t,!0)}function At(e,t,n){const{calendar:s,durationUnit:a}=t,r=a||"day",[i,o,d]=Be(n);if(e.type==="milestone")e[d]=0,e[o]=void 0;else if(e[i]){if(!n&&t.splitTasks&&e.segments)return Ta(e,t);e[d]?e[o]=Ue(r,s)(e[i],e[d]):e[o]?e[d]=_a(r,s)(e[o],e[i]):(e[o]=Ue(r,s)(e[i],1),e[d]=1)}}function Be(e){return e?["base_start","base_end","base_duration"]:["start","end","duration"]}function Fe(e,t,n){const[s,a,r]=Be(n);(t===r||t===s)&&(e[a]=null),t===a&&(e[r]=0,e[s]&&e[s]>=e[a]&&(e[a]=null,e[r]=1))}function Da(e,t,n){Fe(e,n,!1),e.base_start&&Fe(e,n,!0),z(e,t)}function Ta(e,t){if(!e.segments.length||e.type==="summary"||e.duration===0)return;const{segments:n}=e,s=e.start&&e.end===null&&e.duration,{_scales:a,calendar:r}=t,i=s&&T(a.lengthUnit,r);let o=0;for(let d=0;d<n.length&&(!s||o!==s);d++){const c=n[d];At(c,t),s&&(s<=o+c.duration||d===n.length-1)?(e.end=i(c.start,s-o),o=s):o+=c.duration}e.duration=o,s||(e.end=n[n.length-1].end)}function Ma(e,t){const{left:n,width:s,segmentIndex:a}=t,r=typeof n<"u",i=typeof s<"u",{segments:o}=e;if(!o?.length||!r&&!i)return;const d=o[a];if(r){const l=n-e.$x;if(a)d.$x=l;else for(let h=1;h<o.length;h++)o[h].$x+=-l}i&&(d.$w=s);const c=o.length;let u=!1;if(!a&&i||a===o.length-1){const l=o[c-1];t.width=l.$x-o[0].$x+l.$w,u=!0}else delete t.width;return!a&&r?u=!0:delete t.left,u}function je(e,t){return e.map(n=>(delete n.duration,z(n,t),n))}function qe(e,t,n,s,a){let r=t.segments||e.segments;const i=r?.length;if(!i||Ut(t)||t.segments===null)return{...t,segments:null};let o=e;const d=s||s===0;d&&(o=e.segments[s]);const{_scales:c,calendar:u}=n,{lengthUnit:l}=c,h=t.start&&!H(o.start,t.start),f=t.end&&!H(o.end,t.end),p=E(l,u),g=E(l),m=T(l,u),k=T(l),y=u?lt(u):m;r=r.map(S=>({...S}));const b=h?g(t.start,o.start):0,_=f?g(t.end,o.end):0;if(u){if(b&&!u.isWorkingDay(t.start)&&(t.start=y(t.start,b>0||!a?1:-1)),_)if(h)t.end=y(t.start,t.duration||o.duration);else{const S=k(t.end,-1);u.isWorkingDay(S)||(t.end=y(t.end,_>0||!a?1:-1),_<0&&a&&(t.end=k(t.end,1)))}b&&H(t.end,t.start)&&(t.end=m(t.end,1))}let x;if(d&&(x={...t},t={}),h||f){if(d){let S,v;i>1&&(S=s>0?r[s-1]:null,v=s<i-1?r[s+1]:null,h&&(S&&(x.start<S.end||H(x.start,S.start))?x.start=S.end:v&&x.start.valueOf()>=v.start.valueOf()&&(x.start=m(v.start,-1))),f&&(v&&x.end>v.start?x.end=v.start:S&&x.end<S.end&&(x.end=m(S.end,1))));const M=r[s];if(h&&S&&!p(x.start,S.end)){if(x.start=S.start,u){const F=p(x.end||M.end,S.end)||1;x.duration=S.duration+F,x.end=m(x.start,x.duration)}r.splice(s-1,1),s--}else if(f&&v&&!p(v.start,x.end)){if(x.end=v.end,u){const F=p(v.start,x.start||M.start)||1;x.duration=v.duration+F,x.start=y(x.end,-x.duration)}r.splice(s+1,1)}r[s]={...M,...x}}else if(h){const S=Le(l,u);let v=0;b>0?v=p(t.start,r[0].start):v=-p(e.start,t.start),v&&(r=r.map(M=>(M.start=y(M.start,v),M.end=S(M.start,M.duration),M))),u&&Xe(r,c.lengthUnit,0,u,v),t.end=r[r.length-1].end}else if(f)if(_>0)r[i-1].end=t.end;else for(let S=i-1;S>=0;S--){const v=r[S];v.start.valueOf()>=t.end.valueOf()?r.splice(S,1):S===r.length-1&&(v.end=t.end)}t.segments=je(r,n)}else d&&(r[s]={...r[s],...x},t.segments=r);return(d||t.segments)&&(r=t.segments||r,t.start=r[0].start,t.end=r[r.length-1].end),r.length<2&&(t.segments=null),t}function $a(e,t,n){const{_scales:s,calendar:a}=n;let r,{segments:i}=e;const o=i?.length;o&&(typeof t>"u"&&(t=o-1),r=i[t]);const d=r||e;i=i?.map(_=>({..._}));const{lengthUnit:c}=s,u=d.duration;if(u<=1)return null;const l={},h=T(c,a),f=Le(c,a),p=E(c,a),g=a?lt(a):h,m=u-Math.round(u/2),k=u-m,y=f(d.start,k);r||(i=l.segments=[],i.push({start:d.start,end:y})),t=t||0,i[t].end=y;let b=g(y,1);return a&&!p(b,y)&&(b=g(b,1)),i.splice(t+1,0,{start:b,end:g(b,m)}),Xe(i,c,t+1,a),l.end=i[i.length-1].end,l.segments=je(i,n),l}function Ut(e){return e.type==="summary"||e.type==="milestone"}function Ha(e,t,n){if(Ut(e))return!0;const{_scales:s,calendar:a}=t,{lengthUnit:r}=s;let i=e;const{segments:o}=e;return o?.length&&(typeof n>"u"&&(n=o.length-1),i=e.segments[n]),E(r,a)(i.end,i.start)<2}function Le(e,t){const n=T(e);if(!t)return n;const s=T(e,t);return(a,r)=>{const i=s(a,r-1);return t.isWorkingDay(i)?n(i,1):s(i,1)}}function Xe(e,t,n,s,a){const r=T(t,s),i=E(t),o=s?lt(s):null;for(let d=n+1;d<e.length;d++){const c=e[d],u=e[d-1].end,l=i(c.start,u);l<1?(c.start=r(u,1),c.end=r(c.start,c.duration)):s&&!s.isWorkingDay(c.start)&&(c.start=o(c.start,a<0&&l>1?-1:1),c.end=r(c.start,c.duration))}}class Yt{in;getState;setState;getHistory;_timer;_tags=new Set;constructor(t,n,s,a){this.in=t,this.getState=n,this.setState=s,this.getHistory=a}debounce(t,n=10){clearTimeout(this._timer),this._timer=setTimeout(t,n)}shouldTrack(t,n={}){return!(t.inProgress||n[t.eventSource])}registerHandler(t,n,s,a){const r=a||`${this.getDefaultTag()}-${t}`;this.in[t](n,s,{tag:r}),this._tags.add(r)}on(t,n,s){this.registerHandler("on",t,n,s)}intercept(t,n,s){this.registerHandler("intercept",t,n,s)}detachHandlers(){this._tags.forEach(t=>this.in.detach(t))}}class Wa extends Yt{undo=[];redo=[];progress={};_dataSnapshot={};_batch=[];_isBatching=!1;init(){this.setHandlers(),this.resetStateHistory()}destroy(){this.setState({history:null})}getDefaultTag(){return"historyManager"}getHandlers(){return{"add-task":{handler:t=>{let{task:n}=t;return n=P(n),n.data&&delete n.data,n.open&&delete n.open,{action:"delete-task",data:{id:t.id},source:{action:"add-task",data:{...t,task:n,select:!1}}}}},"delete-task":{getSnapshot:t=>this.getOrder(t.id,!0),handler:t=>{const{id:n}=t,{task:s,mode:a,target:r,kids:i,links:o}=this.getPrevData(),d=[{id:n,task:s,mode:a,target:r,select:!1}];return i.forEach(c=>{d.push({id:c.id,task:c,mode:"child",select:!1})}),o.forEach(c=>{d.push({action:"add-link",link:c})}),{action:"add-task",data:d,source:{action:"delete-task",data:t}}}},"update-task":{getSnapshot:t=>{const{id:n}=t,{tasks:s}=this.getState(),a=s.byId(n);return{task:P(a)}},handler:t=>{const{id:n}=t,{task:s}=this.getPrevData(),a=P(t.task);if(a.segments&&!s.segments&&(s.segments=null),!wt(s,a))return{action:"update-task",data:{id:n,task:s},source:{action:"update-task",data:{...t,task:a,diff:void 0,segmentIndex:void 0}}}},progress:!0},"copy-task":{handler:t=>{const{id:n}=t,{task:s,mode:a,target:r,kids:i,links:o}=this.getOrder(t.id,!0),d=[{id:n,task:s,mode:a,target:r,select:!1}];return i.forEach(c=>{d.push({id:c.id,task:c,select:!1})}),o.forEach(c=>{d.push({action:"add-link",link:c})}),{action:"delete-task",data:{id:t.id},source:{action:"add-task",data:d}}}},"move-task":{getSnapshot:t=>this.getOrder(t.id),handler:t=>{const{id:n}=t,{target:s,mode:a}=this.getPrevData();return{action:"move-task",data:{id:n,target:s,mode:a},source:{action:"move-task",data:{id:n,target:t.target,mode:t.mode}}}},progress:!0},"add-link":{handler:t=>({action:"delete-link",data:{id:t.id},source:{action:"add-link",data:t}})},"delete-link":{getSnapshot:t=>{const{id:n}=t,{links:s}=this.getState(),a=s.byId(n);return{link:P(a)}},handler:t=>{const{link:n}=this.getPrevData();return{action:"add-link",data:{id:t.id,link:n},source:{action:"delete-link",data:t}}}},"update-link":{getSnapshot:t=>{const{id:n}=t,{links:s}=this.getState(),a=s.byId(n);return{link:P(a)}},handler:t=>{const{link:n}=this.getPrevData();return{action:"update-link",data:{id:t.id,link:n},source:{action:"update-link",data:t}}}}}}resetHistory(){this.undo=[],this.redo=[],this.progress={},this.resetStateHistory()}setHandlers(){const t=this.getHandlers();for(const n in t){const{getSnapshot:s,handler:a,progress:r}=t[n];this.in.intercept(n,i=>{if(!(i.eventSource==="undo"||i.eventSource==="redo"||i.skipUndo||!s)){if(r){(i.inProgress&&!this.progress[n]||typeof i.inProgress!="boolean")&&this.setPrevData(s(i)),this.progress[n]=i.inProgress;return}this.setPrevData(s(i))}}),this.in.on(n,i=>{if(i.eventSource==="undo"||i.eventSource==="redo"||i.skipUndo||i.inProgress)return;const o=a(i);o&&this.addToHistory(o)})}}setPrevData(t){this._dataSnapshot=t}getPrevData(){return this._dataSnapshot}addToHistory(t){this._isBatching?this._batch.push(t):(this.undo.push(t),this.redo=[],this.setStateHistory())}startBatch(){this._isBatching=!0,this._batch=[]}endBatch(){if(this._isBatching=!1,this._batch.length===0)return;const t={action:"batch",data:this._batch,source:{action:"batch",data:this._batch.map(n=>n.source)}};this.undo.push(t),this._batch=[],this.redo=[],this.setStateHistory()}handleUndo(){if(!this.undo.length)return;const t=this.undo.pop();this.redo.push({...t.source,source:t}),t.action==="batch"?[...t.data].reverse().forEach(n=>{this.executeHistoryEntry(n,"undo")}):this.executeHistoryEntry(t,"undo"),this.setStateHistory()}handleRedo(){if(!this.redo.length)return;const t=this.redo.pop();this.undo.push({...t.source,source:t}),t.action==="batch"?t.data.forEach(n=>{this.executeHistoryEntry(n,"redo")}):this.executeHistoryEntry(t,"redo"),this.setStateHistory()}executeHistoryEntry(t,n){Array.isArray(t.data)?t.data.forEach(({action:s,...a})=>{const r=s||t.action,i={...a,eventSource:n};i.task&&delete i.task.data,this.in.exec(r,i)}):(t.data.task&&delete t.data.task.data,this.in.exec(t.action,{...t.data,eventSource:n}))}resetStateHistory(){this.setState({history:{undo:0,redo:0}})}setStateHistory(){this.setState({history:{undo:this.undo.length,redo:this.redo.length}})}getOrder(t,n){const{tasks:s,links:a}=this.getState();let r={};const i=[],o=s.byId(t),d=o.parent||0,c=s.byId(d).data,u=c.findIndex(h=>h.id===t),l=c[u+1];if(l?r={mode:"before",target:l.id}:c.length?r={mode:"after",target:c[u-1]?.id}:r={mode:"child",target:d},a.forEach(h=>{(h.source===t||h.target===t)&&i.push(h)}),r.task=P(o),n){const h=[];s.eachChild(f=>{h.push(f)},t),r.kids=h.map(f=>({...f})),h.forEach(f=>{a.forEach(p=>{(p.source===f.id||p.target===f.id)&&!i.some(({id:g})=>p.id==g)&&i.push(p)})})}return r.links=i,r}}const Qe=Symbol.for("constructDateFrom");function ft(e,t){return typeof e=="function"?e(t):e&&typeof e=="object"&&Qe in e?e[Qe](t):e instanceof Date?new e.constructor(t):new Date(t)}function Bt(e,t){return ft(e,e)}function et(e,t,n){const s=Bt(e);return isNaN(t)?ft(e,NaN):(t&&s.setDate(s.getDate()+t),s)}function Ia(e,...t){const n=ft.bind(null,t.find(s=>typeof s=="object"));return t.map(n)}function Ea(e,t){const n=Bt(e);return n.setHours(0,0,0,0),n}function Pa(e,t){const[n,s]=Ia(e,t.start,t.end);return{start:n,end:s}}function Ft(e,t){const{start:n,end:s}=Pa(t?.in,e);let a=+n>+s;const r=a?+n:+s,i=a?s:n;i.setHours(0,0,0,0);let o=1;const d=[];for(;+i<=r;)d.push(ft(n,i)),i.setDate(i.getDate()+o),i.setHours(0,0,0,0);return a?d.reverse():d}function Ca(e,t){return Bt(e).getDay()}function jt(e){return Math.round(e.getTime()/864e5)-19e3}function Ge(e,t){return jt(e)}function Re(e,t){return t.inclusiveEnd?jt(e)+1:jt(e)}function Je(e){const t=new Date((e+19e3)*864e5);return new Date(t.getFullYear(),t.getMonth(),t.getDate())}var Ve=class{constructor(e,t,n){e&&this.parse(e,t,n)}parse(e,t=[],n={}){this._originalData=[...e],this._originalLinks=[...t],this._originalConfig={...n},this._nodes=new Map;const{start:s,end:a}=Oa(e,n),r=this._data=new Array(e.length+2);if(r[0]={id:0,in:[],out:[],counter:0,start:Ge(s)},r[1]={id:1,in:[],out:[],counter:0,start:Re(a,n)},!e.length){const h={left:r[0],right:r[1],lag:void 0};r[0].out.push(h),r[1].in.push(h);return}for(let h=0;h<e.length;h++){const f=e[h],p=2*h+2,g={};r[p]={id:p,in:[],out:[g],counter:0,start:Ge(f.start)},r[p+1]={id:p+1,in:[g],out:[],counter:0,start:Re(f.end||f.start,n)},g.left=r[p],g.right=r[p+1],g.lag=f.duration||g.right.start-g.left.start,this._nodes.set(f.id,p)}for(const h of t){const f=r[this._nodes.get(h.source)+1],p=r[this._nodes.get(h.target)];if(!f||!p){console.warn(`Link ${h.source} -> ${h.target} not found`);continue}const g={left:f,right:p,lag:h.lag!==void 0?h.lag:void 0};f.out.push(g),p.in.push(g)}const i=[],o=[];let d=r[2],c=r[2];for(let h=2;h<r.length;h++){const f=r[h];f.in.length===0&&i.push(f),f.out.length===0&&o.push(f),f.start<d.start&&(d=f),f.start>c.start&&(c=f)}i.length||i.push(d),o.length||o.push(c);const u=r[0],l=r[1];for(const h of i){const f={left:u,right:h,lag:void 0};u.out.push(f),h.in.push(f)}for(const h of o){const f={left:h,right:l,lag:void 0};h.out.push(f),l.in.push(f)}}byOrder(e){return this._data[e]}byId(e){return this._data[this._nodes.get(e)]}toTaskIds(e,t=!1){if(!t)return e.map(a=>this.getTaskId(a));const n=[];let s=null;for(const a of e){const r=this.getTaskId(a);r===0||s===r||(s=r,n.push(r))}return n}toTasks(e){return e.map(t=>this.getCurrentTask(t))}forward(e){this._resetCounters();const t=[this._data[0]];let n=0;for(;n<t.length;){const s=t[n];e(s);for(const a of s.out){const r=a.right;r&&(r.counter++,r.counter===r.in.length&&t.push(a.right))}n++}return t}backward(e){this._resetCounters();const t=[this._data[1]];let n=0;for(;n<t.length;){const s=t[n];e(s);for(const a of s.in){const r=a.left;r&&(r.counter++,r.counter===r.out.length&&t.push(a.left))}n++}return t}_resetCounters(){for(const e of this._data)e.counter=0}resetToOriginal(){this.parse(this._originalData,this._originalLinks,this._originalConfig)}getCurrentTask(e){const t=this.getTaskId(e),n=this.getOriginalTask(t)||{id:"__new"},s=e-e%2,a=this._data[s].start,r=this._data[s+1].start,i=this._data[s].out[0].lag;return{...n,start:Je(a),end:Je(r),duration:i}}getOriginalTask(e){return this._originalData.find(t=>t.id===e)}getTaskId(e){if(e<=1)return 0;const t=Math.floor((e-2)/2);return this._originalData[t].id}getStartNodeId(e){return this._nodes.get(e)||0}getEndNodeId(e){const t=this._nodes.get(e);return t!==void 0?t+1:0}};function Oa(e,t){if(t.start&&t.end)return{start:t.start,end:t.end};let n=t.start||new Date(2970,1,1),s=t.end||new Date(1970,1,1);for(const a of e)a.start<n&&(n=a.start),a.end>s&&(s=a.end);return{start:n,end:s}}var Ke=1,Ze=2;function Na(e,t,n){const s=za(e,t,n);return e.toTaskIds(s,!0)}function za(e,t,n){const s=Ua(e,n),a=[],r=e.byOrder(0),i=e.byOrder(1);if(t===Ke){let o=i;const d=0;for(;o!==r;){o!==i&&a.push(o.id);let c=null,u=1/0,l=-1;for(const h of o.in){const f=s.get(h.left.id);(f.totalSlack<u||f.totalSlack===u&&f.count>l)&&(l=f.count,c=h.left,u=f.totalSlack)}if(u>d||!c)break;o=c}return a.reverse()}else if(t===Ze){let o=r;for(;o!==i;){o!==r&&a.push(o.id);let d=0,c=1/0;for(let u=0;u<o.out.length;u++){const l=o.out[u].right,h=s.get(l.id),f=o.out[u].lag??0,p=h.earliest-(o.start+f),g=h.pathSlack+p;g<c&&(c=g,d=u)}o=o.out[d].right}}return a}function Aa(e){return Math.round(e.getTime()/864e5)-19e3}function gt(e){const t=new Date((e+19e3)*864e5);return new Date(t.getFullYear(),t.getMonth(),t.getDate())}function qt(e,t,n){if(!n)return e+t;const s=gt(e),a=n.addWorkingDays(s,t);return a?Aa(a):e+t}function Ua(e,t){const n=new Map,s=t?.calendar,a=e.byOrder(0).start;e.forward(i=>{let o=a;for(const d of i.in){const c=n.get(d.left.id);if(c){const u=qt(c.earliest,d.lag??0,s);u>o&&(o=u)}}n.set(i.id,{earliest:o,latest:0,freeSlack:0,totalSlack:0,pathSlack:0,count:0})});const r=e.byOrder(1).start;return e.backward(i=>{const o=n.get(i.id);let d=r,c=r,u=0,l=r;for(const h of i.out){const f=n.get(h.right.id),p=h.lag??0,g=qt(f.latest,-p,s);g<d&&(d=g),(f.pathSlack<c||f.pathSlack===c&&f.count>u)&&(u=f.count,c=f.pathSlack);const m=qt(f.earliest,-p,s);m<l&&(l=m)}if(o.latest=d,s){const h=gt(o.earliest),f=gt(o.latest),p=gt(l);o.totalSlack=s.getWorkingDays(h,f,!0),o.freeSlack=s.getWorkingDays(h,p,!0)}else o.totalSlack=o.latest-o.earliest,o.freeSlack=l-o.earliest;o.pathSlack=c+o.totalSlack,o.count=u+1}),n}var Ya=class A{static{this.globalConfig={defaultHoursPerDay:8,maxIterations:365}}constructor(t){this.name=t?.name,this.weekHours=[0,8,8,8,8,8,0];const n=t?.weekHours;n&&(this.weekHours=[n.sunday??0,n.monday??8,n.tuesday??8,n.wednesday??8,n.thursday??8,n.friday??8,n.saturday??0]),this.exceptions=new Map,this.rules=[]}static setGlobalConfig(t){A.globalConfig={...A.globalConfig,...t}}setDayHours(t,n){const s=this.normalizeDate(t);this.exceptions.set(s.getTime(),n)}setRangeHours(t,n,s){const a=this.normalizeDate(t),r=this.normalizeDate(n),i=Ft({start:a,end:r});for(const o of i)this.exceptions.set(o.getTime(),s)}isWorkingDay(t){return this.getWorkingHours(t)>0}getWorkingHours(t,n,s){if(n===void 0)return this.getDayHours(t);const a=this.normalizeDate(t),r=this.normalizeDate(n,s);if(a>r)return 0;let i=0;const o=Ft({start:a,end:r});for(const d of o)i+=this.getDayHours(d);return i}getWorkingDays(t,n,s){const a=this.normalizeDate(t),r=this.normalizeDate(n,s);if(a>r)return 0;let i=0;const o=Ft({start:a,end:r});for(const d of o)this.getDayHours(d)>0&&i++;return i}getNextWorkingDay(t){const n=A.globalConfig.maxIterations||365;let s=this.normalizeDate(t),a=0;for(;a<n;){if(s=et(s,1),this.getDayHours(s)>0)return s;a++}return null}getPreviousWorkingDay(t){const n=A.globalConfig.maxIterations||365;let s=this.normalizeDate(t),a=0;for(;a<n;){if(s=et(s,-1),this.getDayHours(s)>0)return s;a++}return null}addWorkingDays(t,n,s){if(n===0)return this.normalizeDate(t);const a=A.globalConfig.maxIterations||365;let r=this.normalizeDate(t);const i=n>0?1:-1;if(this.getDayHours(r)===0){const c=i>0?this.getNextWorkingDay(r):this.getPreviousWorkingDay(r);if(!c)return null;r=c}let o=s?Math.abs(n)-1:Math.abs(n),d=0;for(;o>0&&d<a;)r=et(r,i),this.getDayHours(r)>0&&o--,d++;return o>0?null:(s&&(r=et(r,i)),r)}addWorkingHours(t,n){if(n===0)return this.normalizeDate(t);const s=A.globalConfig.maxIterations||365;let a=this.normalizeDate(t),r=Math.abs(n);const i=n>0?1:-1;let o=0;for(;r>0&&o<s;){o>0&&(a=et(a,i));const d=this.getDayHours(a);d>0&&(r-=d),o++}return r>0?null:a}addRule(t){this.rules.push(t)}clone(t){const n={sunday:this.weekHours[0],monday:this.weekHours[1],tuesday:this.weekHours[2],wednesday:this.weekHours[3],thursday:this.weekHours[4],friday:this.weekHours[5],saturday:this.weekHours[6]},s=new A({name:t?.name||this.name,weekHours:t?.weekHours||n});for(const r of this.rules)s.rules.push(r);const a=r=>{const i=this.normalizeDate(r).getTime();return this.exceptions.get(i)};return s.rules.push(a),s}getDayHours(t){const n=this.normalizeDate(t),s=n.getTime(),a=this.exceptions.get(s);if(a!==void 0)return a;for(let i=this.rules.length-1;i>=0;i--){const o=this.rules[i](n);if(o!==void 0)return o}const r=Ca(n);return this.weekHours[r]??0}normalizeDate(t,n=!1){const s=Ea(t);return new Date(s.getFullYear(),s.getMonth(),s.getDate()-(n?1:0))}};function Ba(e){return e.setDate(e.getDate()-1),e}var Lt=0,tn=1,en=2,Fa=1,nn=864e5;function B(e){return Math.round(e.getTime()/nn)-19e3}function X(e){return new Date((e+19e3)*nn)}function sn(e,t,n){return t.isWorkingDay(e)?e:n===tn?t.getPreviousWorkingDay(e)??e:t.getNextWorkingDay(e)??e}function pt(e,t,n){const s=X(e),a=n.addWorkingDays(s,t);return a?B(a):e+t}var ja=-1e12,Xt=1e12;function an(e,t,n,s,a,r,i){const o=t.start>=n&&t.start<=s&&r!==Lt;if(o&&!i)return;const d=t.id%2===0,c=e.byOrder(t.id+(d?1:-1));if(o)a.debug.push(`[${t.id}] cascade: already valid, checking links only`);else{const u=d?t.out[0].lag:t.in[0].lag;let l=r!==en?s:n;if(a.calendar){const h=X(l),f=sn(h,a.calendar,r);l=B(f)}if(a.debug.push(`[${t.id}] update ${t.start} => ${l}`),t.start=l,a.modified.add(t.id),a.calendar&&d){const h=X(t.start),f=a.calendar.addWorkingDays(h,u,!0);f?l=B(f):l=t.start+u}else if(a.calendar&&!d){const h=Ba(X(t.start)),f=a.calendar.addWorkingDays(h,-u,!1);l=f?B(f):t.start-u}else l=t.start+(d?1:-1)*u;a.debug.push(`[${c.id}] update ${c.start} => ${l}`),c.start=l,a.modified.add(c.id)}nt(e,d?t.in:t.out,t,d,a,i),nt(e,d?c.out:c.in,c,d,a,i)}function nt(e,t,n,s,a,r){for(let i=0;i<t.length;i++){const o=t[i],d=o.left.id===n.id?o.right:o.left;if(d.id<2)continue;const c=o.left===d;if(c&&!a.backward||!c&&!a.forward)continue;const u=o.lag!==void 0;let l;if(u)if(a.calendar){const m=X(n.start),k=c?-o.lag:o.lag,y=a.calendar.addWorkingDays(m,k);l=y?B(y):n.start+k}else l=c?n.start-o.lag:n.start+o.lag;else if(a.calendar&&!c){const m=X(n.start),k=a.calendar.addWorkingDays(m,0);l=k?B(k):n.start}else l=n.start;let h=u?l:c?ja:l,f=u||c?l:Xt,p=d;if(d.id%2===(s?1:0)){p=e.byOrder(d.id+(s?-1:1));const m=s?d.in[0].lag:d.out[0].lag;if(a.calendar)s?(h=pt(h,-m,a.calendar),f!==Xt&&(f=pt(f,-m,a.calendar))):(h=pt(h,m,a.calendar),f!==Xt&&(f=pt(f,m,a.calendar)));else{const k=s?-m:m;h+=k,f+=k}}const g=p.start>=h&&p.start<=f;g&&!r||(g||a.debug.push(`[${n.id}] link to ${d.id} violation: [${p.id}] ${p.start} not in [${h}, ${f}]`),qa(n,p,h,f,c?tn:en,a))}}function rn(e,t,n){n.debug.push(`[${e.id}] link to ${t.id} violation: target node can't be rescheduled`),n.conflicts.push({type:Fa,source:e.id,target:t.id})}function qa(e,t,n,s,a,r){if(r.modified.has(t.id))return t.start<n||t.start>s?(rn(e,t,r),!1):!0;const i=r.signals.get(t.id);if(!i)return r.signals.set(t.id,{sourceNode:e,targetNode:t,min:n,max:s,mode:a}),r.queue.push(t.id),!0;const o=Math.max(i.min,n),d=Math.min(i.max,s);return o>d?(rn(e,t,r),!1):(i.min=o,i.max=d,!0)}function La(e,t,n,s,a){const r=Xa(e,t,n,s,a),i=new Set;for(const c of r.updates){if(c<=1)continue;const u=c-c%2;i.add(u)}const o=e.toTasks(Array.from(i)),d=r.conflicts.map(c=>({type:c.type,source:e.getTaskId(c.source),target:e.getTaskId(c.target)}));return{updates:o,conflicts:d,debug:r.debug}}function Xa(e,t,n,s,a){const r=a?.cascade??!1,i=a?.calendar,o=a?.forward??!0,d=a?.backward??!0,c=e.getStartNodeId(t),u=c<=1,l={queue:[],modified:new Set,signals:new Map,conflicts:[],debug:[],calendar:i,forward:o,backward:d};if(u){const f=e.byOrder(c);l.debug.push(`[${c}] virtual node, force=true, checking links`),nt(e,f.out,f,!0,l,r)}else{const f=e.getOriginalTask(t),p=s!==void 0&&s!==f.duration,g=p||n!==void 0&&n.getTime()!==f.start.getTime();n=n||f.start,i&&n&&(n=sn(n,i,Lt));const m=e.byOrder(c);p&&(f.duration=s,m.out[0].lag=s,e.byOrder(c+1).in[0].lag=s);const k=B(n);if(g)an(e,m,k,k,l,Lt,r);else{const y=e.byOrder(m.id+1);l.debug.push(`[${m.id}] force=true, checking links without modifying`),nt(e,m.in,m,!0,l,r),nt(e,y.out,y,!0,l,r)}}let h=0;for(;h<l.queue.length;){const f=l.signals.get(l.queue[h]);an(e,f.targetNode,f.min,f.max,l,f.mode,r),h++}return{updates:l.modified,conflicts:l.conflicts,debug:l.debug}}class mt{prevState=new Map;track(t,n,s){const a={};s.forEach(r=>{n[r]!==void 0&&(a[r]=n[r])}),this.prevState.set(t,a)}hasChanged(t,n,s){const a=this.prevState.get(t);if(!a)return!1;const r=s.some(i=>{const o=a[i],d=n[i];return o instanceof Date&&d instanceof Date?!H(o,d):o!==d});return this.prevState.delete(t),r}clear(t){t!==void 0?this.prevState.delete(t):this.prevState.clear()}getSnapshot(t){return this.prevState.get(t)}}function Qa(e){const t={},n=new Map;for(const d of e){const{source:c,target:u}=d;(t[c]??=[]).push(u),n.set(`${c}->${u}`,d)}const s=new Set,a=[],r=new Set,i=new Set,o=d=>{s.add(d),r.add(d),a.push(d);for(const c of t[d]||[])if(!s.has(c))o(c);else if(r.has(c)){const u=a.indexOf(c),l=a.slice(u).concat(c);for(let h=0;h<l.length-1;h++){const f=`${l[h]}->${l[h+1]}`;n.has(f)&&i.add(n.get(f).id)}}a.pop(),r.delete(d)};for(const d of Object.keys(t).map(Number))s.has(d)||o(d);return i}const st={"schedule-tasks":1,"move-task":1,"copy-task":1,"add-task":1};class Ga extends Yt{taskTracker=new mt;linkTracker=new mt;init(){this.setupScheduleHandler(),this.setupTaskHandlers(),this.setupLinkHandlers()}destroy(){this.taskTracker.clear(),this.linkTracker.clear(),this.detachHandlers()}schedule(t=0,n){n&&this.deleteInvalidLinks(),this.in.exec("schedule-tasks",{id:t})}getDefaultTag(){return"scheduler"}setupScheduleHandler(){this.on("schedule-tasks",({id:t,task:n})=>{const{links:s,tasks:a,projectStart:r,projectEnd:i,calendar:o,unscheduledTasks:d}=this.getState(),c={calendar:o};t===0?(n={},c.cascade=!0):n||(n=a.byId(t));const u=new Ve,l=[],h=[];s.forEach(g=>{if(g.type==="e2s"){let m=!0;if(d){const k=a.byId(g.source),y=a.byId(g.target);m=!k.unscheduled&&!y.unscheduled}m&&l.push(g)}}),a.serialize().forEach(g=>{(!d||!g.unscheduled)&&h.push({...g})}),u.parse(h,l,{start:r,end:i});const f=La(u,t,n.start,n.duration,c),p=this.getHistory();p&&p.startBatch(),f.updates.forEach(g=>{if(g.id===t)return;const m={start:g.start,duration:g.duration};g.type!=="milestone"&&(m.end=g.end),this.in.exec("update-task",{id:g.id,task:m,eventSource:"schedule-tasks"})}),p&&p.endBatch()})}setupTaskHandlers(){this.intercept("update-task",t=>{if(t.eventSource=="undo"||t.eventSource=="redo"||t.skipUndo||!this.shouldTrack(t,st))return;const n=this.getState().tasks.byId(t.id);n&&this.taskTracker.track(t.id,n,["start","end","duration","type"])}),this.on("update-task",t=>{if(t.eventSource=="undo"||t.eventSource=="redo"||t.skipUndo||!this.shouldTrack(t,st))return;const{id:n,task:s}=t;this.taskTracker.hasChanged(n,s,["start","end","duration"])&&this.debounce(()=>this.schedule())}),this.in.on("move-task",({inProgress:t})=>{t!==!0&&this.schedule(0,!0)}),this.on("copy-task",t=>{this.shouldTrack(t,st)&&this.schedule()}),this.on("add-task",t=>{this.shouldTrack(t,st)&&this.getState().tasks.getSummaryId(t.id)&&this.schedule()}),this.on("provide-data",()=>{this.schedule(0,!0)})}setupLinkHandlers(){this.intercept("update-link",t=>{const{links:n}=this.getState(),s=n.byId(t.id);s&&this.linkTracker.track(t.id,s,["type","source","target","lag"])}),this.on("update-link",t=>{if(this.linkTracker.hasChanged(t.id,t.link,["type","source","target","lag"])){const n=this.linkTracker.getSnapshot(t.id);(t.link.type==="e2s"||n?.type==="e2s")&&this.schedule()}}),this.intercept("delete-link",t=>{const{links:n}=this.getState(),s=n.byId(t.id);s&&this.linkTracker.track(t.id,s,["type"])}),this.on("delete-link",t=>{this.linkTracker.getSnapshot(t.id)?.type==="e2s"&&t.eventSource!=="schedule-tasks"&&this.schedule(),this.linkTracker.clear(t.id)}),this.in.intercept("add-link",t=>{const{links:n}=this.getState();if(this.getInvalidLinks([...n.map(s=>s),t.link]).size)return!1}),this.on("add-link",t=>{this.shouldTrack(t,st)&&t.link.type==="e2s"&&this.schedule()})}deleteInvalidLinks(){const{links:t}=this.getState(),n=this.getInvalidLinks(t.map(s=>s));for(const s of n)this.in.exec("delete-link",{id:s,eventSource:"schedule-tasks"})}getInvalidLinks(t){const{tasks:n}=this.getState(),s=new Set;return t.forEach(a=>{const r=n.getSummaryId(a.source,!0),i=n.getSummaryId(a.target,!0);(r?.includes(a.target)||i?.includes(a.source))&&s.add(a.id)}),new Set([...s,...Qa(t)])}}const Ra={strict:Ke,flexible:Ze},on={"schedule-tasks":1,"update-task":1,"move-task":1};class Ja extends Yt{taskTracker=new mt;linkTracker=new mt;init(){this.setupTaskHandlers(),this.setupLinkHandlers()}destroy(){this.taskTracker.clear(),this.linkTracker.clear(),this.detachHandlers();const{links:t,tasks:n}=this.getState();t.forEach(s=>{delete s.$critical}),n.forEach(s=>{delete s.$critical}),this.setState({tasks:n,links:t})}calculate(){const{tasks:t,links:n,criticalPath:s,projectStart:a,projectEnd:r,calendar:i,unscheduledTasks:o}=this.getState(),d=[],c=[],u=[];n.forEach(g=>{if(g.type==="e2s"){let m=!0;[g.source,g.target].forEach(k=>{if(m){const{type:y,unscheduled:b}=t.byId(k);m=y!=="summary"&&(!o||!b)}}),m&&d.push({...g})}}),t.serialize().forEach(g=>{g.type!=="summary"&&(!o||!g.unscheduled)?c.push({...g}):u.push(g.id)});const l=new Ve(c,d,{start:a,end:r}),h={calendar:i},f=Na(l,Ra[s.type],h),p={};f.forEach(g=>p[g]=!0),u.reverse().forEach(g=>{const m=t.byId(g)?.data||[];m.length&&m.some(k=>p[k.id])&&(p[g]=!0)}),n.forEach(g=>{const m=p[g.source],k=p[g.target];m&&k?g.$critical=!0:delete g.$critical}),t.forEach(g=>{p[g.id]?g.$critical=!0:delete g.$critical}),this.setState({tasks:t,links:n})}getDefaultTag(){return"path"}setupTaskHandlers(){this.intercept("update-task",t=>{if(!this.shouldTrack(t,on))return;const n=this.getState().tasks.byId(t.id);n&&this.taskTracker.track(t.id,n,["start","end","duration","type","unscheduled"])}),this.on("update-task",t=>{this.shouldTrack(t,on)&&this.taskTracker.hasChanged(t.id,t.task,["start","end","duration","type","unscheduled"])&&this.debounce(()=>this.calculate())}),this.on("add-task",t=>{t.task.unscheduled||this.debounce(()=>this.calculate())}),this.on("delete-task",()=>{this.debounce(()=>this.calculate())}),this.on("move-task",t=>{t.inProgress!==!0&&this.debounce(()=>this.calculate())})}setupLinkHandlers(){this.on("add-link",t=>{t.link.type==="e2s"&&this.calculate()}),this.intercept("update-link",t=>{const{links:n}=this.getState(),s=n.byId(t.id);s&&this.linkTracker.track(t.id,s,["type","source","target","lag"])}),this.on("update-link",t=>{if(this.linkTracker.hasChanged(t.id,t.link,["type","source","target","lag"])){const n=this.linkTracker.getSnapshot(t.id);(t.link.type==="e2s"||n?.type==="e2s")&&this.calculate()}}),this.intercept("delete-link",t=>{const{links:n}=this.getState(),s=n.byId(t.id);s&&this.linkTracker.track(t.id,s,["type"])}),this.on("delete-link",t=>{this.linkTracker.getSnapshot(t.id)?.type==="e2s"&&this.calculate(),this.linkTracker.clear(t.id)})}}class Va extends fn{in;_router;_modules=new Map;constructor(t){super({writable:t,async:!1}),this._router=new gn(super.setState.bind(this),[{in:["tasks","start","end","scales","autoScale"],out:["_start","_end"],exec:a=>{const{_end:r,_start:i,start:o,end:d,tasks:c,scales:u,autoScale:l}=this.getState();if(!o||!d||l){const h=L(u).unit,f=ra(o,d,l,h,c);(f._end!=r||f._start!=i)&&this.setState(f,a)}else this.setState({_start:o,_end:d},a)}},{in:["_start","_end","cellWidth","scaleHeight","scales","lengthUnit","_weekStart"],out:["_scales"],exec:a=>{const r=this.getState();let{lengthUnit:i}=r;const{_start:o,_end:d,cellWidth:c,scaleHeight:u,scales:l,_weekStart:h}=r,f=L(l).unit;ta(f,i)||(i=f);const p=ia(o,d,i,c,u,h,l);this.setState({_scales:p},a)}},{in:["_scales","tasks","cellHeight","baselines","unscheduledTasks"],out:["_tasks"],exec:a=>{const{cellWidth:r,cellHeight:i,tasks:o,_scales:d,baselines:c,splitTasks:u,unscheduledTasks:l}=this.getState(),h=o.toArray().map((f,p)=>Pe(f,p,{cellWidth:r,cellHeight:i,_scales:d,baselines:c,splitTasks:u,unscheduledTasks:l}));this.setState({_tasks:h},a)}},{in:["_tasks","links","cellHeight"],out:["_links"],exec:a=>{const{tasks:r,links:i,cellHeight:o,baselines:d,criticalPath:c}=this.getState(),u=i.map(l=>{const h=r.byId(l.source),f=r.byId(l.target);return ga(l,h,f,o,d)}).toSorted((l,h)=>c?!!l.$critical==!!h.$critical?h.$pl-l.$pl:l.$critical?1:-1:h.$pl-l.$pl).filter(l=>l!==null);this.setState({_links:u},a)}},{in:["tasks","activeTask"],out:["_activeTask"],exec:a=>{const r=this.getState();let{activeTask:i}=r;i&&typeof i=="object"&&(i=i.id);const o=r.tasks.byId(i);this.setState({_activeTask:o||null},a)}},{in:["tasks","selected"],out:["_selected"],exec:a=>{const{tasks:r,selected:i}=this.getState(),o=i.map(d=>r.byId(d)).filter(d=>!!d);this.setState({_selected:o},a)}},{in:["start","end"],out:["cellWidth"],exec:a=>{const{_cellWidth:r,cellWidth:i}=this.getState();r!=i&&this.setState({cellWidth:r},a)}},{in:["markers","_scales","cellWidth"],out:["_markers"],exec:a=>{const{markers:r,_scales:i,cellWidth:o}=this.getState(),{start:d,diff:c}=i,u=r.map(l=>(l.left=c(l.start,d)*o,l));this.setState({_markers:u},a)}},{in:["unscheduledTasks"],out:["columns"],exec:a=>{const{columns:r,unscheduledTasks:i}=this.getState(),o=r.map(d=>(d._template&&(d.id=="start"||d.id=="end"||d.id=="duration")&&(d={...d,template:(c,u,l)=>u.unscheduled&&i?"-":l._template(c,u,l)}),d));this.setState({columns:o},a)}}],{tasks:a=>new xn(a),links:a=>new Zt(a),columns:a=>xa(a)});const n=this.in=new pn;n.on("show-editor",a=>{const{splitTasks:r}=this.getState();if(r){const{id:i,segmentIndex:o}=a;if(i&&(o||o===0)){this.setStateAsync({activeTask:{id:i,segmentIndex:o}});return}}this.setStateAsync({activeTask:a.id})}),n.on("select-task",({id:a,toggle:r,range:i,show:o,segmentIndex:d})=>{const{selected:c,_tasks:u,activeTask:l,splitTasks:h}=this.getState();let f=!1,p;if(c.length&&(r||i)){const m=[...c];if(i){const k=m[m.length-1],y=u.findIndex(v=>v.id==k),b=u.findIndex(v=>v.id==a),_=Math.min(y,b),x=Math.max(y,b)+1,S=u.slice(_,x).map(v=>v.id);y>b&&S.reverse(),S.forEach(v=>{m.includes(v)||m.push(v)})}else if(r){const k=m.findIndex(y=>y==a);k===-1?m.push(a):(f=!0,m.splice(k,1))}p=m}else p=[a];const g={selected:p};o&&p.length&&(g._scrollTask={id:p[0],mode:o}),this.setStateAsync(g),!f&&l&&(l!==a||h)&&n.exec("show-editor",{id:a,...h&&{segmentIndex:d}})}),n.on("delete-link",({id:a})=>{const{links:r}=this.getState();r.remove(a),this.setStateAsync({links:r})}),n.on("update-link",a=>{const{links:r}=this.getState(),i=a.id;let o=a.link;r.update(i,o),o=r.byId(i),!o.lag&&o.lag!==0&&delete o.lag,this.setStateAsync({links:r}),a.link=o}),n.on("add-link",a=>{const{link:r}=a,{links:i}=this.getState();!r.source||!r.target||(r.type||(r.type="e2s"),r.id=r.id||bt(),i.add(r),this.setStateAsync({links:i}),a.id=r.id,a.link=i.byId(r.id))});let s=null;n.on("move-task",a=>{const{tasks:r}=this.getState();let{mode:i,target:o}=a;const{id:d,inProgress:c}=a,u=r.byId(d);if(typeof c>"u"?a.source=u.parent:a.source=s=s??u.parent,c===!1){r.update(u.id,{$reorder:!1}),this.setState({tasks:r}),s=null;return}if(o===d||r.contains(d,o)){a.skipProvider=!0;return}if(i==="up"||i==="down"){const l=r.getBranch(d);let h=r.getIndexById(d);if(i==="up"){const f=u.parent===0;if(h===0&&f){a.skipProvider=!0;return}h-=1,i="before"}else if(i==="down"){const f=h===l.length-1,p=u.parent===0;if(f&&p){a.skipProvider=!0;return}h+=1,i="after"}if(o=l[h]&&l[h].id||u.parent,o){const f=r.getBranch(o);let p=r.getIndexById(o),g=f[p];if(g.data){if(i==="before"){if(g.parent===u.parent){for(;g.data;)g.open||n.exec("open-task",{id:g.id,mode:!0}),g=g.data[g.data.length-1];o=g.id}}else if(i==="after"){let y;g.parent===u.parent?(y=g,g=g.data[0],o=g.id,i="before"):f.length-1!==p&&(y=g,p+=1,g=f[p],u.$level>g.$level&&g.data?(y=g,g=g.data[0],o=g.id,i="before"):o=g.id),y&&!y.open&&n.exec("open-task",{id:y.id,mode:!0})}}const m=r.getSummaryId(u.id);r.move(d,i,o);const k=r.getSummaryId(d);m!=k&&(m&&this.resetSummaryDates(m,"move-task"),k&&this.resetSummaryDates(k,"move-task"))}}else{const l=r.byId(o);let h=l,f=!1;for(;h.$level>u.$level;)h=r.byId(h.parent),h.id===d&&(f=!0);if(f)return;const p=r.getSummaryId(u.id);if(r.move(d,i,o),i=="child"){let m=l;for(;m.id!==0&&!m.open;)n.exec("open-task",{id:m.id,mode:!0}),m=r.byId(m.parent)}const g=r.getSummaryId(d);p!=g&&(p&&this.resetSummaryDates(p,"move-task"),g&&this.resetSummaryDates(g,"move-task"))}c?this.setState({tasks:r}):this.setStateAsync({tasks:r}),a.target=o,a.mode=i}),n.on("drag-task",a=>{const r=this.getState(),{tasks:i,_tasks:o,_selected:d,_scales:c,cellWidth:u}=r,l=i.byId(a.id);if(a.segmentIndex>=0&&r.splitTasks&&Ma(l,a)===!1){this.setState({_tasks:o});return}const{left:h,top:f,width:p,inProgress:g}=a,m={_tasks:o,_selected:d};if(typeof p<"u"&&(l.$w=p,Ot(i,l,c,u)),typeof h<"u"){if(l.type==="summary"){const k=h-l.$x;We(l,k,c,u)}l.$x=h,Ot(i,l,c,u)}typeof f<"u"&&(l.$y=f+4,l.$reorder=g),typeof p<"u"&&(l.$w=p),typeof h<"u"&&(l.$x=h),typeof f<"u"&&(l.$y=f+4,l.$reorder=g),this.setState(m)}),n.on("update-task",a=>{const{id:r,segmentIndex:i,diff:o,eventSource:d}=a;let{task:c}=a;const{tasks:u,_scales:l,durationUnit:h,splitTasks:f,calendar:p}=this.getState(),g=u.byId(r),m={_scales:l,durationUnit:h,calendar:p,splitTasks:f};if(d==="add-task"||d==="copy-task"||d==="move-task"||d==="update-task"||d==="delete-task"||d==="provide-data"){f&&g.segments&&(c=qe(g,c,m)),z(c,m),u.update(r,c);return}const k=l.lengthUnit;let y=T(k);const b=E(k,p);if(o&&(c.start&&(c.start=y(c.start,o)),!i&&i!==0&&(c.start&&c.end?c.duration=g.duration:(c.start?c.end=g.end:(c.end=y(c.end,o),c.start=g.start,c.duration=b(c.end,c.start)),b(c.end,c.start)||(c.duration=1)))),f&&g.segments&&(o&&i>=0&&c.end&&(c.end=y(c.end,o)),c=qe(g,c,m,i,o)),c.type=c.type??g.type,p&&c.start&&(c.start=Wt(c.start,o,p)),c.start&&c.end&&(!H(c.start,g.start)||!H(c.end,g.end))&&c.type==="summary"&&g.data?.length){let x=o||b(c.start,g.start);p&&(x=c.start>g.start?b(c.start,g.start):-b(g.start,c.start),y=lt(p)),this.moveSummaryKids(g,S=>(S=y(S,x),p?Wt(S,o,p):S),"update-task")}c.start||(c.start=g.start),!c.end&&!c.duration&&(c.duration=g.duration),z(c,m),u.update(r,c),(p&&c.type==="summary"||c.type==="summary"&&g.type!=="summary")&&this.resetSummaryDates(r,"update-task",!0);const _=u.getSummaryId(r);_&&this.resetSummaryDates(_,"update-task"),this.setStateAsync({tasks:u}),a.task=u.byId(r)}),n.on("add-task",a=>{const{tasks:r,_scales:i,unscheduledTasks:o,durationUnit:d,splitTasks:c,calendar:u}=this.getState(),{target:l,mode:h,task:f,show:p,select:g=!0}=a;!a.eventSource&&o&&(f.unscheduled=!0);let m=-1,k,y;if(l?(y=r.byId(l),h=="child"?(k=y,f.parent=k.id):(y.parent!==null&&(k=r.byId(y.parent),f.parent=k.id),m=r.getIndexById(l),h=="after"&&(m+=1))):f.parent&&(k=r.byId(f.parent)),!f.start){if(k?.start)f.start=new Date(k.start.valueOf());else if(y)f.start=new Date(y.start.valueOf());else{const S=r.getBranch(0);let v;if(S?.length){const M=S[S.length-1];if(!M.$skip){const F=new Date(M.start.valueOf());i.start<=F&&(v=F)}}f.start=v||T(d,u)(i.start,1)}f.duration=1}u&&(f.start=Wt(f.start,1,u)),this.getState().baselines&&(f.base_start=f.start,f.base_duration=f.duration),z(f,{durationUnit:d,splitTasks:c,calendar:u});const b=r.add(f,m),_={tasks:r};if(k&&p){for(;k&&k.id;)n.exec("open-task",{id:k.id,mode:!0}),k=r.byId(k.parent);_._scrollTask={id:b.id,mode:p}}a.id=b.id;const x=r.getSummaryId(b.id);x&&this.resetSummaryDates(x,"add-task"),this.setStateAsync(_),a.id=b.id,a.task=b,g&&n.exec("select-task",{id:b.id})}),n.on("delete-task",a=>{const{id:r}=a,{tasks:i,links:o,selected:d}=this.getState();a.source=i.byId(r).parent;const c=i.getSummaryId(r),u=[r];i.eachChild(h=>u.push(h.id),r),o.filter(h=>!(u.includes(h.source)||u.includes(h.target)));const l={tasks:i,links:o};d.includes(r)&&(l.selected=d.filter(h=>h!==r)),i.remove(r),c&&this.resetSummaryDates(c,"delete-task"),this.setStateAsync(l)}),n.on("indent-task",({id:a,mode:r})=>{const{tasks:i}=this.getState();if(r){const o=i.getBranch(a)[i.getIndexById(a)-1];o&&n.exec("move-task",{id:a,mode:"child",target:o.id})}else{const o=i.byId(a),d=i.byId(o.parent);d&&d.parent!==null&&n.exec("move-task",{id:a,mode:"after",target:o.parent})}}),n.on("copy-task",a=>{const{id:r,target:i,mode:o,eventSource:d}=a;if(d==="copy-task")return;const{tasks:c,links:u}=this.getState();if(c.contains(r,i)){a.skipProvider=!0;return}const l=c.getSummaryId(r),h=c.getSummaryId(i);let f=c.getIndexById(i);o=="before"&&(f-=1);const p=c.byId(r),g=c.copy(p,c.byId(i).parent,f+1);a.source=a.id,a.id=g[0][1],p.lazy&&(a.lazy=!0),l!=h&&h&&this.resetSummaryDates(h,"copy-task");let m=[];for(let k=1;k<g.length;k++){const[y,b]=g[k];u.forEach(_=>{if(_.source===y){const x={..._};delete x.target,m.push({...x,source:b})}else if(_.target===y){const x={..._};delete x.source,m.push({...x,target:b})}})}m=m.reduce((k,y)=>{const b=k.findIndex(_=>_.id===y.id);return b>-1?k[b]={...k[b],...y}:k.push(y),k},[]);for(let k=1;k<g.length;k++){const[y,b]=g[k],_=c.byId(b);n.exec("copy-task",{source:y,id:b,lazy:!!_.lazy,eventSource:"copy-task",target:_.parent,mode:"child",skipUndo:!0})}m.forEach(k=>{n.exec("add-link",{link:{source:k.source,target:k.target,type:k.type},eventSource:"copy-task",skipUndo:!0})}),this.setStateAsync({tasks:c})}),n.on("open-task",({id:a,mode:r})=>{const{tasks:i}=this.getState(),o=i.byId(a);o.lazy?n.exec("request-data",{id:o.id}):(i.toArray().forEach(d=>d.$y=0),i.update(a,{open:r}),this.setState({tasks:i}))}),n.on("scroll-chart",({left:a,top:r})=>{if(!isNaN(a)){const i=this.calcScaleDate(a);this.setState({scrollLeft:a,_scaleDate:i})}isNaN(r)||this.setState({scrollTop:r})}),n.on("render-data",a=>{this.setState({area:a})}),n.on("provide-data",a=>{const{tasks:r,links:i,durationUnit:o,calendar:d,splitTasks:c}=this.getState(),u=r.byId(a.id);u.lazy?(u.lazy=!1,u.open=!0):u.data=[],Ye(a.data.tasks,{durationUnit:o,splitTasks:c,calendar:d}),r.parse(a.data.tasks,a.id),u.type=="summary"&&this.resetSummaryDates(u.id,"provide-data"),this.setStateAsync({tasks:r,links:new Zt(i.map(l=>l).concat(Oe(a.data.links)))})}),n.on("zoom-scale",({dir:a,offset:r})=>{const{zoom:i,cellWidth:o,_cellWidth:d,scrollLeft:c}=this.getState(),u=r+c,l=this.calcScaleDate(u);let h=o;a<0&&(h=d||o);const f=h+a*50,p=i.levels[i.level],g=a<0&&o>p.maxCellWidth;if(f<p.minCellWidth||f>p.maxCellWidth||g){if(!this.changeScale(i,a))return}else this.setState({cellWidth:f,_cellWidth:f});const{_scales:m,_start:k,cellWidth:y,_weekStart:b}=this.getState(),_=I(m.minUnit,k,b),x=m.diff(l,_,"hour");typeof r>"u"&&(r=y);let S=Math.round(x*y)-r;S<0&&(S=0),this.setState({scrollLeft:S,_scaleDate:l,_zoomOffset:r})}),n.on("expand-scale",({minWidth:a})=>{const{_start:r,_scales:i,start:o,end:d,_end:c,cellWidth:u,_scaleDate:l,_zoomOffset:h}=this.getState(),f=T(i.minUnit);let p=i.width;if(o&&d){if(p<a&&p){const b=a/p;this.setState({cellWidth:u*b})}return!0}let g=0;for(;p<a;)p+=u,g++;const m=g?d?-g:-1:0,k=o||f(r,m);let y=0;if(l){const b=i.diff(l,k,"hour");y=Math.max(0,Math.round(b*u)-(h||0))}this.setState({_start:k,_end:d||f(c,g),scrollLeft:y})}),n.on("sort-tasks",({key:a,order:r,add:i})=>{const o=this.getState(),{tasks:d}=o;let c=o._sort;const u={key:a,order:r};let l=c?.length||0;l&&i?(c.forEach((h,f)=>{h.key===a&&(l=f)}),c[l]=u):c=[u],d.sort(c),this.setState({_sort:c,tasks:d})}),n.on("hotkey",({key:a,event:r,eventSource:i})=>{switch(a){case"arrowup":case"arrowdown":{const{selected:o,_tasks:d}=this.getState();r.preventDefault();const c=o.length;let u;if(a==="arrowup"?u=c?this.getPrevRow(o[c-1])?.id:d[d.length-1]?.id:u=c?this.getNextRow(o[c-1])?.id:d[0]?.id,u){const l=i==="chart"?"xy":!0;this.in.exec("select-task",{id:u,show:l})}break}case"ctrl+c":{tt(this,"copy-task",null,null);break}case"ctrl+x":{tt(this,"cut-task",null,null);break}case"ctrl+v":{tt(this,"paste-task",null,null);break}case"ctrl+d":case"backspace":{r.preventDefault(),tt(this,"delete-task",null,null);break}case"ctrl+z":{this.in.exec("undo",{});break}case"ctrl+y":{this.in.exec("redo",{});break}}}),n.on("undo",()=>{this.getHistory()?.handleUndo()}),n.on("redo",()=>{this.getHistory()?.handleRedo()}),n.on("split-task",({id:a,segmentIndex:r})=>{const i=this.getState(),{tasks:o,_scales:d,durationUnit:c,splitTasks:u,calendar:l}=i;if(!u)return;const h=o.byId(a);if(Ut(h))return;const f=$a(h,r,{_scales:d,durationUnit:c,calendar:l,splitTasks:u});f&&n.exec("update-task",{id:a,task:f,eventSource:"split-task"})})}init(t){const n=this.getState().area?{}:{scrollLeft:0,scrollTop:0,area:{from:0,start:0,end:0}};t.cellWidth&&(t._cellWidth=t.cellWidth),t._sort=null,Pt()&&(t.unscheduledTasks=!1,t.baselines=!1,t.markers=[],t.undo=!1,t.schedule={},t.criticalPath=null,t.splitTasks=!1),Array.isArray(t.tasks)&&this.getHistory()?.resetHistory(),this._router.init({_scrollTask:null,selected:[],markers:[],autoScale:!0,durationUnit:"day",...n,...t}),t.schedule?.auto?this.enableModule("autoScheduler",Ga).schedule(0,!0):this.disableModule("autoScheduler"),t.criticalPath?this.enableModule("criticalPath",Ja).calculate():this.disableModule("criticalPath"),t.undo?this.enableModule("historyManager",Wa):this.disableModule("historyManager")}enableModule(t,n){if(!this._modules.has(t)){const s=new n(this.in,this.getState.bind(this),this.setState.bind(this),this.getHistory.bind(this));return s.init(),this._modules.set(t,s),s}return this._modules.get(t)}disableModule(t){const n=this._modules.get(t);n&&(n.destroy(),this._modules.delete(t))}setState(t,n){return this._router.setState(t,n)}setStateAsync(t){this._router.setStateAsync(t)}getTask(t){const{tasks:n}=this.getState();return n.byId(t)}getHistory(){return this.getState().undo?this._modules.get("historyManager"):null}serialize(){const{tasks:t}=this.getState();return t.serialize()}changeScale(t,n){const s=t.level+n,a=t.levels[s];if(a){const{cellWidth:r,scales:i,_scales:o}=this.getState(),d=da(t,n,s,a,o.lengthUnit,i,r);return d._cellWidth=d.cellWidth,this.setState(d),!0}return!1}isScheduled(t){return this.getState().unscheduledTasks?t.some(n=>!n.unscheduled||n.data&&this.isScheduled(n.data)):!0}resetSummaryDates(t,n,s){const{tasks:a,durationUnit:r,splitTasks:i,calendar:o}=this.getState(),d=a.byId(t),c=d.data;if(c?.length&&this.isScheduled(c)){const u=Nt({...d,start:void 0,end:void 0,duration:void 0});if(!H(d.start,u.start)||!H(d.end,u.end)){s?(z(u,{durationUnit:r,splitTasks:i,calendar:o}),a.update(t,u)):this.in.exec("update-task",{id:t,task:u,eventSource:n,skipUndo:!0});const l=a.getSummaryId(t);l&&this.resetSummaryDates(l,n)}}}moveSummaryKids(t,n,s){const{tasks:a}=this.getState();t.data.forEach(r=>{const i={...a.byId(r.id),start:n(r.start)};delete i.end,delete i.id,this.in.exec("update-task",{id:r.id,task:i,eventSource:s,skipUndo:!0}),r.data?.length&&this.moveSummaryKids(r,n,s)})}calcScaleDate(t){const{_scales:n,_start:s,_weekStart:a}=this.getState(),r=n.lengthUnit==="day"?n.lengthUnitWidth/24:n.lengthUnitWidth;return T("hour")(I(n.minUnit,s,a),Math.floor(t/r))}getNextRow(t){const n=this.getState()._tasks,s=n.findIndex(a=>a.id==t);return n[s+1]}getPrevRow(t){const n=this.getState()._tasks,s=n.findIndex(a=>a.id==t);return n[s-1]}}function Ka(e,t,n,s){if(typeof document>"u")return"";const a=document.createElement("canvas");{const r=Za(a,e,t,1,n);tr(r,s,0,e,0,t)}return a.toDataURL()}function Za(e,t,n,s,a){e.setAttribute("width",(t*s).toString()),e.setAttribute("height",(n*s).toString());const r=e.getContext("2d");return r.translate(-.5,-.5),r.strokeStyle=a,r}function tr(e,t,n,s,a,r){e.beginPath(),e.moveTo(s,a),e.lineTo(s,r),t==="full"&&e.lineTo(n,r),e.stroke()}function er(e){let t=[...Gt];return e?.splitTasks&&(t.splice(4,0,{id:"split-task",text:"Split",icon:"wxi-arrow-split"}),t.splice(4,0,{id:"edit",text:"Edit",icon:"wxi-edit",data:[{id:"edit-task:task",text:"Task",isHidden:(n,s,a)=>!Q(a)},{id:"edit-task:segment",text:"Segment",isHidden:(n,s,a)=>!Q(a)}]}),t.push({id:"delete",icon:"wxi-delete",text:"Delete",data:[{id:"delete-task:task",text:"Task",isHidden:(n,s,a)=>!Qt(s)||!Q(a)},{id:"delete-task:segment",text:"Segment",isHidden:(n,s,a)=>!Qt(s)||!Q(a)}]})),t.length>Gt.length&&(t=at(t)),t}function at(e){return e.map(t=>{switch(t.data&&at(t.data),t.id){case"add-task:before":case"move-task:up":t.isDisabled=(n,s)=>sr(n,s);break;case"move-task:down":t.isDisabled=(n,s)=>ar(n,s);break;case"indent-task:add":t.isDisabled=(n,s)=>rr(n,s)===n.parent;break;case"indent-task:remove":t.isDisabled=n=>nr(n);break;case"undo":t.isDisabled=n=>!n.undo;break;case"redo":t.isDisabled=n=>!n.redo;break;case"split-task":t.isDisabled=(n,s,a)=>{let r;return typeof a=="object"&&(r=a.segmentIndex),Ha(n,s,r)};break}return t})}function nr(e){return e.parent===0}function sr(e,t){const{_tasks:n}=t;return n[0]?.id===e.id}function ar(e,t){const{_tasks:n}=t;return n[n.length-1]?.id===e.id}function rr(e,t){const{_tasks:n}=t,s=n.findIndex(a=>a.id===e.id);return n[s-1]?.id??e.parent}function Q(e){return e&&typeof e=="object"}function Qt(e){return!e.selected||e.selected.length<2}const ir=e=>t=>t.type===e,Gt=at([{id:"add-task",text:"Add",icon:"wxi-plus",data:[{id:"add-task:child",text:"Child task"},{id:"add-task:before",text:"Task above"},{id:"add-task:after",text:"Task below"}]},{type:"separator"},{id:"convert-task",text:"Convert to",icon:"wxi-swap-horizontal",dataFactory:e=>({id:`convert-task:${e.id}`,text:`${e.label}`,isDisabled:ir(e.id)})},{id:"edit-task",text:"Edit",icon:"wxi-edit",isHidden:(e,t,n)=>Q(n)},{type:"separator"},{id:"cut-task",text:"Cut",icon:"wxi-content-cut",subtext:"Ctrl+X"},{id:"copy-task",text:"Copy",icon:"wxi-content-copy",subtext:"Ctrl+C"},{id:"paste-task",text:"Paste",icon:"wxi-content-paste",subtext:"Ctrl+V"},{id:"move-task",text:"Move",icon:"wxi-swap-vertical",data:[{id:"move-task:up",text:"Up"},{id:"move-task:down",text:"Down"}]},{type:"separator"},{id:"indent-task:add",text:"Indent",icon:"wxi-indent"},{id:"indent-task:remove",text:"Outdent",icon:"wxi-unindent"},{type:"separator"},{id:"delete-task",icon:"wxi-delete",text:"Delete",subtext:"Ctrl+D / BS",isHidden:(e,t,n)=>Qt(t)&&Q(n)}]);function or(e){let t=[...Rt];return e?.undo&&(t=t.concat([{comp:"separator"},{id:"undo",comp:"icon",icon:"wxi-undo",menuText:"Undo"},{id:"redo",comp:"icon",icon:"wxi-redo",menuText:"Redo"}])),e?.splitTasks&&t.splice(2,0,{id:"split-task",comp:"icon",icon:"wxi-arrow-split",menuText:"Split"}),t.length>Rt.length&&(t=at(t)),t}const Rt=at([{id:"add-task",comp:"button",icon:"wxi-plus",text:"New task",type:"primary"},{id:"edit-task",comp:"icon",icon:"wxi-edit",menuText:"Edit",text:"Ctrl+E"},{id:"delete-task",comp:"icon",icon:"wxi-delete",menuText:"Delete",text:"Ctrl+D, Backspace"},{comp:"separator"},{id:"move-task:up",comp:"icon",icon:"wxi-angle-up",menuText:"Move up"},{id:"move-task:down",comp:"icon",icon:"wxi-angle-down",menuText:"Move down"},{comp:"separator"},{id:"copy-task",comp:"icon",icon:"wxi-content-copy",menuText:"Copy",text:"Ctrl+V"},{id:"cut-task",comp:"icon",icon:"wxi-content-cut",menuText:"Cut",text:"Ctrl+X"},{id:"paste-task",comp:"icon",icon:"wxi-content-paste",menuText:"Paste",text:"Ctrl+V"},{comp:"separator"},{id:"indent-task:add",comp:"icon",icon:"wxi-indent",menuText:"Indent"},{id:"indent-task:remove",comp:"icon",icon:"wxi-unindent",menuText:"Outdent"}]);function kt(e){return e.type==="summary"}function Jt(e){return e.type==="milestone"}function yt(e){return typeof e.parent>"u"}function Vt(e,t){return t.unscheduledTasks&&e.unscheduled}function dr(e){const t=[...dn];return e?.unscheduledTasks&&t.splice(6,0,{key:"unscheduled",comp:"twostate",label:"",config:{value:!0,text:"Unschedule",textActive:"Schedule"},isHidden:n=>kt(n)||yt(n)}),t}const dn=[{key:"text",comp:"text",label:"Name",config:{placeholder:"Add task name"}},{key:"details",comp:"textarea",label:"Description",config:{placeholder:"Add description"}},{key:"type",comp:"select",label:"Type",isHidden:e=>yt(e)},{key:"start",comp:"date",label:"Start date",isHidden:e=>kt(e),isDisabled:Vt},{key:"end",comp:"date",label:"End date",isHidden:e=>kt(e)||Jt(e),isDisabled:Vt},{key:"duration",comp:"counter",label:"Duration",config:{min:1},isHidden:e=>kt(e)||Jt(e),isDisabled:Vt},{key:"progress",comp:"slider",label:"Progress",config:{min:1,max:100},isHidden:e=>Jt(e)||yt(e)},{key:"links",comp:"links",label:"",isHidden:e=>yt(e)}],cr=[{id:"task",label:"Task"},{id:"summary",label:"Summary task"},{id:"milestone",label:"Milestone"}],ur=Ya;export{ur as Calendar,Va as DataStore,Sa as defaultColumns,dn as defaultEditorItems,Gt as defaultMenuOptions,cr as defaultTaskTypes,Rt as defaultToolbarButtons,fa as extendDragOptions,As as format,T as getAdder,E as getDiffer,dr as getEditorItems,er as getMenuOptions,or as getToolbarButtons,I as getUnitStart,Ka as grid,tt as handleAction,Ae as isHandledAction,ha as isSegmentMoveAllowed,Oe as normalizeLinks,oa as normalizeZoom,Ye as parseTaskDates,ya as placeLink,Da as prepareEditTask,aa as registerScaleUnit};
1
+ var Kt=new Date().valueOf(),cn=()=>Kt++;function bt(){return"temp://"+Kt++}function un(e,t){if(Object.keys(e).length!==Object.keys(t).length)return!1;for(const n in t){const s=e[n],a=t[n];if(!wt(s,a))return!1}return!0}function wt(e,t){if(typeof e=="number"||typeof e=="string"||typeof e=="boolean"||e===null)return e===t;if(typeof e!=typeof t||(e===null||t===null)&&e!==t||e instanceof Date&&t instanceof Date&&e.getTime()!==t.getTime())return!1;if(typeof e=="object")if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return!1;for(let n=e.length-1;n>=0;n--)if(!wt(e[n],t[n]))return!1;return!0}else return un(e,t);return e===t}function P(e){if(typeof e!="object"||e===null)return e;if(e instanceof Date)return new Date(e);if(e instanceof Array)return e.map(P);const t={};for(const n in e)t[n]=P(e[n]);return t}var Zt=class{constructor(e){this._data=e,this._pool=new Map;for(let t=0;t<e.length;t++){const n=e[t];this._pool.set(n.id,n)}}add(e){e={id:cn(),...e},this._data.push(e),this._pool.set(e.id,e)}update(e,t){const n=this._data.findIndex(a=>a.id==e),s={...this._data[n],...t};this._data[n]=s,this._pool.set(s.id,s)}remove(e){this._data=this._data.filter(t=>t.id!=e),this._pool.delete(e)}filter(e){this._data=this._data.filter(t=>{const n=e(t);return n||this._pool.delete(t.id),n})}byId(e){return this._pool.get(e)}map(e){return this._data.map(e)}forEach(e){this._data.forEach(e)}},ln=class{constructor(e){const t={id:0,$level:0,data:[],parent:null},n=new Map;n.set(0,t),this._pool=n,e&&e.length&&this.parse(e,0)}parse(e,t){const n=this._pool;for(let a=0;a<e.length;a++){const r=e[a];r.parent=r.parent||t,r.data=null,n.set(r.id,r)}for(let a=0;a<e.length;a++){const r=e[a],i=n.get(r.parent);i&&(i.data||(i.data=[]),i.data.push(r))}const s=n.get(t);this.setLevel(s,s.$level+1,!1)}add(e,t){const n=this._pool.get(e.parent||0);e.$level=n.$level+1,this._pool.set(e.id,e),n.data?t===-1?n.data=[...n.data,e]:ee(n,t,e):n.data=[e]}addAfter(e,t){if(!t)return this.add(e,-1);const n=this.byId(t),s=this.byId(n.parent),a=rt(s,n.id)+1;e.parent=s.id,e.$level=s.$level+1,this.add(e,a)}remove(e){const t=this._pool.get(e);this._remove(t);const n=this._pool.get(t.parent);n.data=n.data.filter(s=>s.id!=e),this._clearBranch(n)}_remove(e){e.data&&e.data.forEach(t=>this._remove(t)),this._pool.delete(e.id)}update(e,t){let n=this._pool.get(e);const s=this._pool.get(n.parent),a=rt(s,n.id);n={...n,...t},s&&a>=0&&(s.data[a]=n,s.data=[...s.data]),this._pool.set(n.id,n)}move(e,t,n){const s=this._pool.get(e),a=t==="child",r=this._pool.get(n),i=r.$level+(a?1:0);if(!s||!r)return;const o=this._pool.get(s.parent),d=a?r:this._pool.get(r.parent);d.data||(d.data=[]);const c=rt(o,s.id);hn(o,c);const u=a?d.data.length:rt(d,r.id)+(t==="after"?1:0);if(ee(d,u,s),o.id===d.id&&c===u)return null;s.parent=d.id,s.$level!==i&&(s.$level=i,this.setLevel(s,i+1,!0)),this.update(s.id,s),this._clearBranch(o)}_clearBranch(e){e.data&&!e.data.length&&(e.open&&delete e.open,this.update(e.id,{data:null}))}toArray(){const e=[],t=this._pool.get(0).data;return t&&te(t,e),e}byId(e){return this._pool.get(e)}getBranch(e){return this._pool.get(e).data}forEach(e){this._pool.forEach((t,n)=>{n!==0&&e(t)})}eachChild(e,t){const n=this.byId(t);!n||!n.data||n.data.forEach((s,a)=>{e(this.byId(s.id),a),this.eachChild(e,s.id)})}setLevel(e,t,n){e.data&&(e.data=e.data.map(s=>(n&&(s={...s},this._pool.set(s.id,s)),s.$level=t,s.data&&this.setLevel(s,t+1,n),s)))}};function te(e,t){e.forEach(n=>{t.push(n),n.open===!0&&te(n.data,t)})}function hn(e,t){const n=[...e.data];n.splice(t,1),e.data=n}function ee(e,t,n){const s=[...e.data];s.splice(t,0,n),e.data=s}function rt(e,t){return e?.data.findIndex(n=>n.id===t)}var ne=2,fn=class{constructor(e){e&&(this._writable=e.writable,this._async=e.async),this._values={},this._state={}}setState(e,t=0){const n={};return this._wrapProperties(e,this._state,this._values,"",n,t),n}getState(){return this._values}getReactive(){return this._state}_wrapProperties(e,t,n,s,a,r){for(const i in e){const o=t[i],d=n[i],c=e[i];if(o&&(d===c&&typeof c!="object"||c instanceof Date&&d instanceof Date&&d.getTime()===c.getTime()))continue;const u=s+(s?".":"")+i;o?(o.__parse(c,u,a,r)&&(n[i]=c),r&ne?a[u]=o.__trigger:o.__trigger()):(c&&c.__reactive?t[i]=this._wrapNested(c,c,u,a):t[i]=this._wrapWritable(c),n[i]=c),a[u]=a[u]||null}}_wrapNested(e,t,n,s){const a=this._wrapWritable(e);return this._wrapProperties(e,a,t,n,s,0),a.__parse=(r,i,o,d)=>(this._wrapProperties(r,a,t,i,o,d),!1),a}_wrapWritable(e){const t=[],n=function(){for(let s=0;s<t.length;s++)t[s](e)};return{subscribe:s=>(t.push(s),this._async?setTimeout(s,1,e):s(e),()=>{const a=t.indexOf(s);a>=0&&t.splice(a,1)}),__trigger:()=>{t.length&&(this._async?setTimeout(n,1):n())},__parse:function(s){return e=s,!0}}}},gn=class{constructor(e,t,n,s){typeof e=="function"?this._setter=e:this._setter=e.setState.bind(e),this._routes=t,this._parsers=n,this._prev={},this._triggers=new Map,this._sources=new Map,this._routes.forEach(a=>{a.in.forEach(r=>{const i=this._triggers.get(r)||[];i.push(a),this._triggers.set(r,i)}),a.out.forEach(r=>{const i=this._sources.get(r)||{};a.in.forEach(o=>i[o]=!0),this._sources.set(r,i)})}),this._routes.forEach(a=>{a.length=Math.max(...a.in.map(r=>se(r,this._sources,1)))}),this._bus=s}init(e){const t={};for(const n in e)if(this._prev[n]!==e[n]){const s=this._parsers[n];t[n]=s?s(e[n]):e[n]}this._prev=this._prev?{...this._prev,...e}:{...e},this.setState(t),this._bus&&this._bus.exec("init-state",t)}setStateAsync(e){const t=this._setter(e,ne);return this._async?Object.assign(this._async.signals,t):this._async={signals:t,timer:setTimeout(this._applyState.bind(this),1)},t}_applyState(){const e=this._async;if(e){this._async=null,this._triggerUpdates(e.signals,[]);for(const t in e.signals){const n=e.signals[t];n&&n()}}}setState(e,t=[]){const n=this._setter(e);return this._triggerUpdates(n,t),n}_triggerUpdates(e,t){const n=Object.keys(e),s=!t.length;t=t||[];for(let a=0;a<n.length;a++){const r=n[a],i=this._triggers.get(r);i&&i.forEach(o=>{t.indexOf(o)==-1&&t.push(o)})}s&&this._execNext(t)}_execNext(e){for(;e.length;){e.sort((n,s)=>n.length<s.length?1:-1);const t=e[e.length-1];e.splice(e.length-1),t.exec(e)}}};function se(e,t,n){const s=t.get(e);if(!s)return n;const a=Object.keys(s).map(r=>se(r,t,n+1));return Math.max(...a)}var pn=class{constructor(){this._nextHandler=null,this._handlers={},this._tag=new WeakMap,this.exec=this.exec.bind(this)}on(e,t,n){let s=this._handlers[e];s?n&&n.intercept?s.unshift(t):s.push(t):s=this._handlers[e]=[t],n&&n.tag&&this._tag.set(t,n.tag)}intercept(e,t,n){this.on(e,t,{...n,intercept:!0})}detach(e){for(const t in this._handlers){const n=this._handlers[t];for(let s=n.length-1;s>=0;s--)this._tag.get(n[s])===e&&n.splice(s,1)}}async exec(e,t){const n=this._handlers[e];if(n)for(let s=0;s<n.length;s++){const a=n[s](t);if(a===!1||a&&a.then&&await a===!1)return}return this._nextHandler&&await this._nextHandler.exec(e,t),t}setNext(e){return this._nextHandler=e}};function mn(e,t){return typeof e=="string"?e.localeCompare(t,void 0,{numeric:!0}):typeof e=="object"?e.getTime()-t.getTime():(e??0)-(t??0)}function kn(e,t){return typeof e=="string"?-e.localeCompare(t,void 0,{numeric:!0}):typeof t=="object"?t.getTime()-e.getTime():(t??0)-(e??0)}function yn({key:e,order:t}){const n=t==="asc"?mn:kn;return(s,a)=>n(s[e],a[e])}function bn(e){if(!e||!e.length)return;const t=e.map(n=>yn(n));return e.length===1?t[0]:function(n,s){for(let a=0;a<t.length;a++){const r=t[a](n,s);if(r!==0)return r}return 0}}function wn(e,t){return e.sort(bn(t))}class xn extends ln{_sort;constructor(t){super(),this.parse(t,0)}parse(t,n){if(!t||!t.length)return;const s=t.map(a=>this.normalizeTask(a,t));super.parse(s,n),this._sort&&this.sortBranch(this._sort,n)}getBranch(t){const n=this._pool.get(t);return this._pool.get(n.parent||0).data}contains(t,n){const s=this._pool.get(t).data;let a=!1;if(s)for(let r=0;r<s.length;r++){if(s[r].id===n){a=!0;break}if(s[r].data&&(a=this.contains(s[r].id,n),a))break}return a}getIndexById(t){return this.getBranch(t).findIndex(n=>n.id===t)}add(t,n){const s=this.normalizeTask(t);return super.add(s,n),s}copy(t,n,s){const a=this.add({...t,id:null,data:null,parent:n},s);let r=[[t.id,a.id]];return t.data?.forEach((i,o)=>{const d=this.copy(i,a.id,o);r=r.concat(d)}),r}normalizeTask(t){const n=t.id||bt(),s=t.parent||0,a=t.text||"",r=t.type||"task",i=t.progress||0,o=t.details||"",d={...t,id:n,text:a,parent:s,progress:i,type:r,details:o};return t.segments&&(d.segments=t.segments.map(c=>({...c}))),t.segments&&(d.segments=t.segments.map(c=>({...c}))),d}getSummaryId(t,n=!1){const s=this._pool.get(t);if(!s.parent)return null;const a=this._pool.get(s.parent);if(n){let r=t,i=this.getSummaryId(r);const o=[];for(;i;)r=i,o.push(i),i=this.getSummaryId(r);return o}return a.type==="summary"?a.id:this.getSummaryId(a.id)}sort(t){this._sort=t,t&&this.sortBranch(t,0)}sortBranch(t,n){const s=this._pool.get(n||0).data;s&&(wn(s,t),s.forEach(a=>{this.sortBranch(t,a.id)}))}serialize(){const t=[],n=this._pool.get(0).data;return n&&ae(n,t),t}}function ae(e,t){e.forEach(n=>{t.push(n),n.data&&ae(n.data,t)})}function w(e){const t=Object.prototype.toString.call(e);return e instanceof Date||typeof e=="object"&&t==="[object Date]"?new e.constructor(+e):typeof e=="number"||t==="[object Number]"||typeof e=="string"||t==="[object String]"?new Date(e):new Date(NaN)}function $(e,t){return e instanceof Date?new e.constructor(t):new Date(t)}function it(e,t){const n=w(e);return isNaN(t)?$(e,NaN):(t&&n.setDate(n.getDate()+t),n)}function xt(e,t){const n=w(e);if(isNaN(t))return $(e,NaN);if(!t)return n;const s=n.getDate(),a=$(e,n.getTime());a.setMonth(n.getMonth()+t+1,0);const r=a.getDate();return s>=r?a:(n.setFullYear(a.getFullYear(),a.getMonth(),s),n)}function re(e,t){const n=+w(e);return $(e,n+t)}const ot=6048e5,Sn=864e5,ie=6e4,oe=36e5;function vn(e,t){return re(e,t*oe)}let _n={};function G(){return _n}function C(e,t){const n=G(),s=t?.weekStartsOn??t?.locale?.options?.weekStartsOn??n.weekStartsOn??n.locale?.options?.weekStartsOn??0,a=w(e),r=a.getDay(),i=(r<s?7:0)+r-s;return a.setDate(a.getDate()-i),a.setHours(0,0,0,0),a}function j(e){return C(e,{weekStartsOn:1})}function de(e){const t=w(e),n=t.getFullYear(),s=$(e,0);s.setFullYear(n+1,0,4),s.setHours(0,0,0,0);const a=j(s),r=$(e,0);r.setFullYear(n,0,4),r.setHours(0,0,0,0);const i=j(r);return t.getTime()>=a.getTime()?n+1:t.getTime()>=i.getTime()?n:n-1}function U(e){const t=w(e);return t.setHours(0,0,0,0),t}function dt(e){const t=w(e),n=new Date(Date.UTC(t.getFullYear(),t.getMonth(),t.getDate(),t.getHours(),t.getMinutes(),t.getSeconds(),t.getMilliseconds()));return n.setUTCFullYear(t.getFullYear()),+e-+n}function St(e,t){const n=U(e),s=U(t),a=+n-dt(n),r=+s-dt(s);return Math.round((a-r)/Sn)}function vt(e){const t=de(e),n=$(e,0);return n.setFullYear(t,0,4),n.setHours(0,0,0,0),j(n)}function Dn(e,t){return re(e,t*ie)}function Tn(e,t){const n=t*3;return xt(e,n)}function ce(e,t){const n=t*7;return it(e,n)}function Mn(e,t){return xt(e,t*12)}function R(e,t){const n=w(e),s=w(t),a=n.getTime()-s.getTime();return a<0?-1:a>0?1:a}function $n(e,t){const n=U(e),s=U(t);return+n==+s}function Hn(e){return e instanceof Date||typeof e=="object"&&Object.prototype.toString.call(e)==="[object Date]"}function Wn(e){if(!Hn(e)&&typeof e!="number")return!1;const t=w(e);return!isNaN(Number(t))}function _t(e,t){const n=j(e),s=j(t),a=+n-dt(n),r=+s-dt(s);return Math.round((a-r)/ot)}function In(e,t){const n=w(e),s=w(t),a=n.getFullYear()-s.getFullYear(),r=n.getMonth()-s.getMonth();return a*12+r}function En(e,t){const n=w(e),s=w(t);return n.getFullYear()-s.getFullYear()}function Dt(e){return t=>{const n=(e?Math[e]:Math.trunc)(t);return n===0?0:n}}function ue(e,t){return+w(e)-+w(t)}function Pn(e,t,n){const s=ue(e,t)/oe;return Dt(n?.roundingMethod)(s)}function Cn(e,t,n){const s=ue(e,t)/ie;return Dt(n?.roundingMethod)(s)}function le(e){const t=w(e);return t.setHours(23,59,59,999),t}function Tt(e){const t=w(e),n=t.getMonth();return t.setFullYear(t.getFullYear(),n+1,0),t.setHours(23,59,59,999),t}function On(e){const t=w(e);return+le(t)==+Tt(t)}function he(e,t){const n=w(e),s=w(t),a=R(n,s),r=Math.abs(In(n,s));let i;if(r<1)i=0;else{n.getMonth()===1&&n.getDate()>27&&n.setDate(30),n.setMonth(n.getMonth()-a*r);let o=R(n,s)===-a;On(w(e))&&r===1&&R(e,s)===1&&(o=!1),i=a*(r-Number(o))}return i===0?0:i}function Nn(e,t,n){const s=he(e,t)/3;return Dt(n?.roundingMethod)(s)}function zn(e,t){const n=w(e),s=w(t),a=R(n,s),r=Math.abs(En(n,s));n.setFullYear(1584),s.setFullYear(1584);const i=R(n,s)===-a,o=a*(r-+i);return o===0?0:o}function J(e){const t=w(e),n=t.getMonth(),s=n-n%3;return t.setMonth(s,1),t.setHours(0,0,0,0),t}function fe(e){const t=w(e);return t.setDate(1),t.setHours(0,0,0,0),t}function An(e){const t=w(e),n=t.getFullYear();return t.setFullYear(n+1,0,0),t.setHours(23,59,59,999),t}function ge(e){const t=w(e),n=$(e,0);return n.setFullYear(t.getFullYear(),0,1),n.setHours(0,0,0,0),n}function Un(e){const t=w(e);return t.setMinutes(59,59,999),t}function Yn(e,t){const n=G(),s=t?.weekStartsOn??t?.locale?.options?.weekStartsOn??n.weekStartsOn??n.locale?.options?.weekStartsOn??0,a=w(e),r=a.getDay(),i=(r<s?-7:0)+6-(r-s);return a.setDate(a.getDate()+i),a.setHours(23,59,59,999),a}function Mt(e){const t=w(e),n=t.getMonth(),s=n-n%3+3;return t.setMonth(s,0),t.setHours(23,59,59,999),t}const Bn={lessThanXSeconds:{one:"less than a second",other:"less than {{count}} seconds"},xSeconds:{one:"1 second",other:"{{count}} seconds"},halfAMinute:"half a minute",lessThanXMinutes:{one:"less than a minute",other:"less than {{count}} minutes"},xMinutes:{one:"1 minute",other:"{{count}} minutes"},aboutXHours:{one:"about 1 hour",other:"about {{count}} hours"},xHours:{one:"1 hour",other:"{{count}} hours"},xDays:{one:"1 day",other:"{{count}} days"},aboutXWeeks:{one:"about 1 week",other:"about {{count}} weeks"},xWeeks:{one:"1 week",other:"{{count}} weeks"},aboutXMonths:{one:"about 1 month",other:"about {{count}} months"},xMonths:{one:"1 month",other:"{{count}} months"},aboutXYears:{one:"about 1 year",other:"about {{count}} years"},xYears:{one:"1 year",other:"{{count}} years"},overXYears:{one:"over 1 year",other:"over {{count}} years"},almostXYears:{one:"almost 1 year",other:"almost {{count}} years"}},Fn=(e,t,n)=>{let s;const a=Bn[e];return typeof a=="string"?s=a:t===1?s=a.one:s=a.other.replace("{{count}}",t.toString()),n?.addSuffix?n.comparison&&n.comparison>0?"in "+s:s+" ago":s};function $t(e){return(t={})=>{const n=t.width?String(t.width):e.defaultWidth;return e.formats[n]||e.formats[e.defaultWidth]}}const jn={full:"EEEE, MMMM do, y",long:"MMMM do, y",medium:"MMM d, y",short:"MM/dd/yyyy"},qn={full:"h:mm:ss a zzzz",long:"h:mm:ss a z",medium:"h:mm:ss a",short:"h:mm a"},Ln={full:"{{date}} 'at' {{time}}",long:"{{date}} 'at' {{time}}",medium:"{{date}}, {{time}}",short:"{{date}}, {{time}}"},Xn={date:$t({formats:jn,defaultWidth:"full"}),time:$t({formats:qn,defaultWidth:"full"}),dateTime:$t({formats:Ln,defaultWidth:"full"})},Qn={lastWeek:"'last' eeee 'at' p",yesterday:"'yesterday at' p",today:"'today at' p",tomorrow:"'tomorrow at' p",nextWeek:"eeee 'at' p",other:"P"},Gn=(e,t,n,s)=>Qn[e];function V(e){return(t,n)=>{const s=n?.context?String(n.context):"standalone";let a;if(s==="formatting"&&e.formattingValues){const i=e.defaultFormattingWidth||e.defaultWidth,o=n?.width?String(n.width):i;a=e.formattingValues[o]||e.formattingValues[i]}else{const i=e.defaultWidth,o=n?.width?String(n.width):e.defaultWidth;a=e.values[o]||e.values[i]}const r=e.argumentCallback?e.argumentCallback(t):t;return a[r]}}const Rn={narrow:["B","A"],abbreviated:["BC","AD"],wide:["Before Christ","Anno Domini"]},Jn={narrow:["1","2","3","4"],abbreviated:["Q1","Q2","Q3","Q4"],wide:["1st quarter","2nd quarter","3rd quarter","4th quarter"]},Vn={narrow:["J","F","M","A","M","J","J","A","S","O","N","D"],abbreviated:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],wide:["January","February","March","April","May","June","July","August","September","October","November","December"]},Kn={narrow:["S","M","T","W","T","F","S"],short:["Su","Mo","Tu","We","Th","Fr","Sa"],abbreviated:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],wide:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]},Zn={narrow:{am:"a",pm:"p",midnight:"mi",noon:"n",morning:"morning",afternoon:"afternoon",evening:"evening",night:"night"},abbreviated:{am:"AM",pm:"PM",midnight:"midnight",noon:"noon",morning:"morning",afternoon:"afternoon",evening:"evening",night:"night"},wide:{am:"a.m.",pm:"p.m.",midnight:"midnight",noon:"noon",morning:"morning",afternoon:"afternoon",evening:"evening",night:"night"}},ts={narrow:{am:"a",pm:"p",midnight:"mi",noon:"n",morning:"in the morning",afternoon:"in the afternoon",evening:"in the evening",night:"at night"},abbreviated:{am:"AM",pm:"PM",midnight:"midnight",noon:"noon",morning:"in the morning",afternoon:"in the afternoon",evening:"in the evening",night:"at night"},wide:{am:"a.m.",pm:"p.m.",midnight:"midnight",noon:"noon",morning:"in the morning",afternoon:"in the afternoon",evening:"in the evening",night:"at night"}},es=(e,t)=>{const n=Number(e),s=n%100;if(s>20||s<10)switch(s%10){case 1:return n+"st";case 2:return n+"nd";case 3:return n+"rd"}return n+"th"},ns={ordinalNumber:es,era:V({values:Rn,defaultWidth:"wide"}),quarter:V({values:Jn,defaultWidth:"wide",argumentCallback:e=>e-1}),month:V({values:Vn,defaultWidth:"wide"}),day:V({values:Kn,defaultWidth:"wide"}),dayPeriod:V({values:Zn,defaultWidth:"wide",formattingValues:ts,defaultFormattingWidth:"wide"})};function K(e){return(t,n={})=>{const s=n.width,a=s&&e.matchPatterns[s]||e.matchPatterns[e.defaultMatchWidth],r=t.match(a);if(!r)return null;const i=r[0],o=s&&e.parsePatterns[s]||e.parsePatterns[e.defaultParseWidth],d=Array.isArray(o)?as(o,l=>l.test(i)):ss(o,l=>l.test(i));let c;c=e.valueCallback?e.valueCallback(d):d,c=n.valueCallback?n.valueCallback(c):c;const u=t.slice(i.length);return{value:c,rest:u}}}function ss(e,t){for(const n in e)if(Object.prototype.hasOwnProperty.call(e,n)&&t(e[n]))return n}function as(e,t){for(let n=0;n<e.length;n++)if(t(e[n]))return n}function rs(e){return(t,n={})=>{const s=t.match(e.matchPattern);if(!s)return null;const a=s[0],r=t.match(e.parsePattern);if(!r)return null;let i=e.valueCallback?e.valueCallback(r[0]):r[0];i=n.valueCallback?n.valueCallback(i):i;const o=t.slice(a.length);return{value:i,rest:o}}}const is=/^(\d+)(th|st|nd|rd)?/i,os=/\d+/i,ds={narrow:/^(b|a)/i,abbreviated:/^(b\.?\s?c\.?|b\.?\s?c\.?\s?e\.?|a\.?\s?d\.?|c\.?\s?e\.?)/i,wide:/^(before christ|before common era|anno domini|common era)/i},cs={any:[/^b/i,/^(a|c)/i]},us={narrow:/^[1234]/i,abbreviated:/^q[1234]/i,wide:/^[1234](th|st|nd|rd)? quarter/i},ls={any:[/1/i,/2/i,/3/i,/4/i]},hs={narrow:/^[jfmasond]/i,abbreviated:/^(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)/i,wide:/^(january|february|march|april|may|june|july|august|september|october|november|december)/i},fs={narrow:[/^j/i,/^f/i,/^m/i,/^a/i,/^m/i,/^j/i,/^j/i,/^a/i,/^s/i,/^o/i,/^n/i,/^d/i],any:[/^ja/i,/^f/i,/^mar/i,/^ap/i,/^may/i,/^jun/i,/^jul/i,/^au/i,/^s/i,/^o/i,/^n/i,/^d/i]},gs={narrow:/^[smtwf]/i,short:/^(su|mo|tu|we|th|fr|sa)/i,abbreviated:/^(sun|mon|tue|wed|thu|fri|sat)/i,wide:/^(sunday|monday|tuesday|wednesday|thursday|friday|saturday)/i},ps={narrow:[/^s/i,/^m/i,/^t/i,/^w/i,/^t/i,/^f/i,/^s/i],any:[/^su/i,/^m/i,/^tu/i,/^w/i,/^th/i,/^f/i,/^sa/i]},ms={narrow:/^(a|p|mi|n|(in the|at) (morning|afternoon|evening|night))/i,any:/^([ap]\.?\s?m\.?|midnight|noon|(in the|at) (morning|afternoon|evening|night))/i},ks={any:{am:/^a/i,pm:/^p/i,midnight:/^mi/i,noon:/^no/i,morning:/morning/i,afternoon:/afternoon/i,evening:/evening/i,night:/night/i}},ys={ordinalNumber:rs({matchPattern:is,parsePattern:os,valueCallback:e=>parseInt(e,10)}),era:K({matchPatterns:ds,defaultMatchWidth:"wide",parsePatterns:cs,defaultParseWidth:"any"}),quarter:K({matchPatterns:us,defaultMatchWidth:"wide",parsePatterns:ls,defaultParseWidth:"any",valueCallback:e=>e+1}),month:K({matchPatterns:hs,defaultMatchWidth:"wide",parsePatterns:fs,defaultParseWidth:"any"}),day:K({matchPatterns:gs,defaultMatchWidth:"wide",parsePatterns:ps,defaultParseWidth:"any"}),dayPeriod:K({matchPatterns:ms,defaultMatchWidth:"any",parsePatterns:ks,defaultParseWidth:"any"})},bs={code:"en-US",formatDistance:Fn,formatLong:Xn,formatRelative:Gn,localize:ns,match:ys,options:{weekStartsOn:0,firstWeekContainsDate:1}};function ws(e){const t=w(e);return St(t,ge(t))+1}function xs(e){const t=w(e),n=+j(t)-+vt(t);return Math.round(n/ot)+1}function pe(e,t){const n=w(e),s=n.getFullYear(),a=G(),r=t?.firstWeekContainsDate??t?.locale?.options?.firstWeekContainsDate??a.firstWeekContainsDate??a.locale?.options?.firstWeekContainsDate??1,i=$(e,0);i.setFullYear(s+1,0,r),i.setHours(0,0,0,0);const o=C(i,t),d=$(e,0);d.setFullYear(s,0,r),d.setHours(0,0,0,0);const c=C(d,t);return n.getTime()>=o.getTime()?s+1:n.getTime()>=c.getTime()?s:s-1}function Ss(e,t){const n=G(),s=t?.firstWeekContainsDate??t?.locale?.options?.firstWeekContainsDate??n.firstWeekContainsDate??n.locale?.options?.firstWeekContainsDate??1,a=pe(e,t),r=$(e,0);return r.setFullYear(a,0,s),r.setHours(0,0,0,0),C(r,t)}function vs(e,t){const n=w(e),s=+C(n,t)-+Ss(n,t);return Math.round(s/ot)+1}function D(e,t){const n=e<0?"-":"",s=Math.abs(e).toString().padStart(t,"0");return n+s}const O={y(e,t){const n=e.getFullYear(),s=n>0?n:1-n;return D(t==="yy"?s%100:s,t.length)},M(e,t){const n=e.getMonth();return t==="M"?String(n+1):D(n+1,2)},d(e,t){return D(e.getDate(),t.length)},a(e,t){const n=e.getHours()/12>=1?"pm":"am";switch(t){case"a":case"aa":return n.toUpperCase();case"aaa":return n;case"aaaaa":return n[0];case"aaaa":default:return n==="am"?"a.m.":"p.m."}},h(e,t){return D(e.getHours()%12||12,t.length)},H(e,t){return D(e.getHours(),t.length)},m(e,t){return D(e.getMinutes(),t.length)},s(e,t){return D(e.getSeconds(),t.length)},S(e,t){const n=t.length,s=e.getMilliseconds(),a=Math.trunc(s*Math.pow(10,n-3));return D(a,t.length)}},q={midnight:"midnight",noon:"noon",morning:"morning",afternoon:"afternoon",evening:"evening",night:"night"},me={G:function(e,t,n){const s=e.getFullYear()>0?1:0;switch(t){case"G":case"GG":case"GGG":return n.era(s,{width:"abbreviated"});case"GGGGG":return n.era(s,{width:"narrow"});case"GGGG":default:return n.era(s,{width:"wide"})}},y:function(e,t,n){if(t==="yo"){const s=e.getFullYear(),a=s>0?s:1-s;return n.ordinalNumber(a,{unit:"year"})}return O.y(e,t)},Y:function(e,t,n,s){const a=pe(e,s),r=a>0?a:1-a;if(t==="YY"){const i=r%100;return D(i,2)}return t==="Yo"?n.ordinalNumber(r,{unit:"year"}):D(r,t.length)},R:function(e,t){const n=de(e);return D(n,t.length)},u:function(e,t){const n=e.getFullYear();return D(n,t.length)},Q:function(e,t,n){const s=Math.ceil((e.getMonth()+1)/3);switch(t){case"Q":return String(s);case"QQ":return D(s,2);case"Qo":return n.ordinalNumber(s,{unit:"quarter"});case"QQQ":return n.quarter(s,{width:"abbreviated",context:"formatting"});case"QQQQQ":return n.quarter(s,{width:"narrow",context:"formatting"});case"QQQQ":default:return n.quarter(s,{width:"wide",context:"formatting"})}},q:function(e,t,n){const s=Math.ceil((e.getMonth()+1)/3);switch(t){case"q":return String(s);case"qq":return D(s,2);case"qo":return n.ordinalNumber(s,{unit:"quarter"});case"qqq":return n.quarter(s,{width:"abbreviated",context:"standalone"});case"qqqqq":return n.quarter(s,{width:"narrow",context:"standalone"});case"qqqq":default:return n.quarter(s,{width:"wide",context:"standalone"})}},M:function(e,t,n){const s=e.getMonth();switch(t){case"M":case"MM":return O.M(e,t);case"Mo":return n.ordinalNumber(s+1,{unit:"month"});case"MMM":return n.month(s,{width:"abbreviated",context:"formatting"});case"MMMMM":return n.month(s,{width:"narrow",context:"formatting"});case"MMMM":default:return n.month(s,{width:"wide",context:"formatting"})}},L:function(e,t,n){const s=e.getMonth();switch(t){case"L":return String(s+1);case"LL":return D(s+1,2);case"Lo":return n.ordinalNumber(s+1,{unit:"month"});case"LLL":return n.month(s,{width:"abbreviated",context:"standalone"});case"LLLLL":return n.month(s,{width:"narrow",context:"standalone"});case"LLLL":default:return n.month(s,{width:"wide",context:"standalone"})}},w:function(e,t,n,s){const a=vs(e,s);return t==="wo"?n.ordinalNumber(a,{unit:"week"}):D(a,t.length)},I:function(e,t,n){const s=xs(e);return t==="Io"?n.ordinalNumber(s,{unit:"week"}):D(s,t.length)},d:function(e,t,n){return t==="do"?n.ordinalNumber(e.getDate(),{unit:"date"}):O.d(e,t)},D:function(e,t,n){const s=ws(e);return t==="Do"?n.ordinalNumber(s,{unit:"dayOfYear"}):D(s,t.length)},E:function(e,t,n){const s=e.getDay();switch(t){case"E":case"EE":case"EEE":return n.day(s,{width:"abbreviated",context:"formatting"});case"EEEEE":return n.day(s,{width:"narrow",context:"formatting"});case"EEEEEE":return n.day(s,{width:"short",context:"formatting"});case"EEEE":default:return n.day(s,{width:"wide",context:"formatting"})}},e:function(e,t,n,s){const a=e.getDay(),r=(a-s.weekStartsOn+8)%7||7;switch(t){case"e":return String(r);case"ee":return D(r,2);case"eo":return n.ordinalNumber(r,{unit:"day"});case"eee":return n.day(a,{width:"abbreviated",context:"formatting"});case"eeeee":return n.day(a,{width:"narrow",context:"formatting"});case"eeeeee":return n.day(a,{width:"short",context:"formatting"});case"eeee":default:return n.day(a,{width:"wide",context:"formatting"})}},c:function(e,t,n,s){const a=e.getDay(),r=(a-s.weekStartsOn+8)%7||7;switch(t){case"c":return String(r);case"cc":return D(r,t.length);case"co":return n.ordinalNumber(r,{unit:"day"});case"ccc":return n.day(a,{width:"abbreviated",context:"standalone"});case"ccccc":return n.day(a,{width:"narrow",context:"standalone"});case"cccccc":return n.day(a,{width:"short",context:"standalone"});case"cccc":default:return n.day(a,{width:"wide",context:"standalone"})}},i:function(e,t,n){const s=e.getDay(),a=s===0?7:s;switch(t){case"i":return String(a);case"ii":return D(a,t.length);case"io":return n.ordinalNumber(a,{unit:"day"});case"iii":return n.day(s,{width:"abbreviated",context:"formatting"});case"iiiii":return n.day(s,{width:"narrow",context:"formatting"});case"iiiiii":return n.day(s,{width:"short",context:"formatting"});case"iiii":default:return n.day(s,{width:"wide",context:"formatting"})}},a:function(e,t,n){const s=e.getHours()/12>=1?"pm":"am";switch(t){case"a":case"aa":return n.dayPeriod(s,{width:"abbreviated",context:"formatting"});case"aaa":return n.dayPeriod(s,{width:"abbreviated",context:"formatting"}).toLowerCase();case"aaaaa":return n.dayPeriod(s,{width:"narrow",context:"formatting"});case"aaaa":default:return n.dayPeriod(s,{width:"wide",context:"formatting"})}},b:function(e,t,n){const s=e.getHours();let a;switch(s===12?a=q.noon:s===0?a=q.midnight:a=s/12>=1?"pm":"am",t){case"b":case"bb":return n.dayPeriod(a,{width:"abbreviated",context:"formatting"});case"bbb":return n.dayPeriod(a,{width:"abbreviated",context:"formatting"}).toLowerCase();case"bbbbb":return n.dayPeriod(a,{width:"narrow",context:"formatting"});case"bbbb":default:return n.dayPeriod(a,{width:"wide",context:"formatting"})}},B:function(e,t,n){const s=e.getHours();let a;switch(s>=17?a=q.evening:s>=12?a=q.afternoon:s>=4?a=q.morning:a=q.night,t){case"B":case"BB":case"BBB":return n.dayPeriod(a,{width:"abbreviated",context:"formatting"});case"BBBBB":return n.dayPeriod(a,{width:"narrow",context:"formatting"});case"BBBB":default:return n.dayPeriod(a,{width:"wide",context:"formatting"})}},h:function(e,t,n){if(t==="ho"){let s=e.getHours()%12;return s===0&&(s=12),n.ordinalNumber(s,{unit:"hour"})}return O.h(e,t)},H:function(e,t,n){return t==="Ho"?n.ordinalNumber(e.getHours(),{unit:"hour"}):O.H(e,t)},K:function(e,t,n){const s=e.getHours()%12;return t==="Ko"?n.ordinalNumber(s,{unit:"hour"}):D(s,t.length)},k:function(e,t,n){let s=e.getHours();return s===0&&(s=24),t==="ko"?n.ordinalNumber(s,{unit:"hour"}):D(s,t.length)},m:function(e,t,n){return t==="mo"?n.ordinalNumber(e.getMinutes(),{unit:"minute"}):O.m(e,t)},s:function(e,t,n){return t==="so"?n.ordinalNumber(e.getSeconds(),{unit:"second"}):O.s(e,t)},S:function(e,t){return O.S(e,t)},X:function(e,t,n){const s=e.getTimezoneOffset();if(s===0)return"Z";switch(t){case"X":return ye(s);case"XXXX":case"XX":return Y(s);case"XXXXX":case"XXX":default:return Y(s,":")}},x:function(e,t,n){const s=e.getTimezoneOffset();switch(t){case"x":return ye(s);case"xxxx":case"xx":return Y(s);case"xxxxx":case"xxx":default:return Y(s,":")}},O:function(e,t,n){const s=e.getTimezoneOffset();switch(t){case"O":case"OO":case"OOO":return"GMT"+ke(s,":");case"OOOO":default:return"GMT"+Y(s,":")}},z:function(e,t,n){const s=e.getTimezoneOffset();switch(t){case"z":case"zz":case"zzz":return"GMT"+ke(s,":");case"zzzz":default:return"GMT"+Y(s,":")}},t:function(e,t,n){const s=Math.trunc(e.getTime()/1e3);return D(s,t.length)},T:function(e,t,n){const s=e.getTime();return D(s,t.length)}};function ke(e,t=""){const n=e>0?"-":"+",s=Math.abs(e),a=Math.trunc(s/60),r=s%60;return r===0?n+String(a):n+String(a)+t+D(r,2)}function ye(e,t){return e%60===0?(e>0?"-":"+")+D(Math.abs(e)/60,2):Y(e,t)}function Y(e,t=""){const n=e>0?"-":"+",s=Math.abs(e),a=D(Math.trunc(s/60),2),r=D(s%60,2);return n+a+t+r}const be=(e,t)=>{switch(e){case"P":return t.date({width:"short"});case"PP":return t.date({width:"medium"});case"PPP":return t.date({width:"long"});case"PPPP":default:return t.date({width:"full"})}},we=(e,t)=>{switch(e){case"p":return t.time({width:"short"});case"pp":return t.time({width:"medium"});case"ppp":return t.time({width:"long"});case"pppp":default:return t.time({width:"full"})}},_s=(e,t)=>{const n=e.match(/(P+)(p+)?/)||[],s=n[1],a=n[2];if(!a)return be(e,t);let r;switch(s){case"P":r=t.dateTime({width:"short"});break;case"PP":r=t.dateTime({width:"medium"});break;case"PPP":r=t.dateTime({width:"long"});break;case"PPPP":default:r=t.dateTime({width:"full"});break}return r.replace("{{date}}",be(s,t)).replace("{{time}}",we(a,t))},Ds={p:we,P:_s},Ts=/^D+$/,Ms=/^Y+$/,$s=["D","DD","YY","YYYY"];function Hs(e){return Ts.test(e)}function Ws(e){return Ms.test(e)}function Is(e,t,n){const s=Es(e,t,n);if(console.warn(s),$s.includes(e))throw new RangeError(s)}function Es(e,t,n){const s=e[0]==="Y"?"years":"days of the month";return`Use \`${e.toLowerCase()}\` instead of \`${e}\` (in \`${t}\`) for formatting ${s} to the input \`${n}\`; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md`}const Ps=/[yYQqMLwIdDecihHKkms]o|(\w)\1*|''|'(''|[^'])+('|$)|./g,Cs=/P+p+|P+|p+|''|'(''|[^'])+('|$)|./g,Os=/^'([^]*?)'?$/,Ns=/''/g,zs=/[a-zA-Z]/;function As(e,t,n){const s=G(),a=n?.locale??s.locale??bs,r=n?.firstWeekContainsDate??n?.locale?.options?.firstWeekContainsDate??s.firstWeekContainsDate??s.locale?.options?.firstWeekContainsDate??1,i=n?.weekStartsOn??n?.locale?.options?.weekStartsOn??s.weekStartsOn??s.locale?.options?.weekStartsOn??0,o=w(e);if(!Wn(o))throw new RangeError("Invalid time value");let d=t.match(Cs).map(u=>{const l=u[0];if(l==="p"||l==="P"){const h=Ds[l];return h(u,a.formatLong)}return u}).join("").match(Ps).map(u=>{if(u==="''")return{isToken:!1,value:"'"};const l=u[0];if(l==="'")return{isToken:!1,value:Us(u)};if(me[l])return{isToken:!0,value:u};if(l.match(zs))throw new RangeError("Format string contains an unescaped latin alphabet character `"+l+"`");return{isToken:!1,value:u}});a.localize.preprocessor&&(d=a.localize.preprocessor(o,d));const c={firstWeekContainsDate:r,weekStartsOn:i,locale:a};return d.map(u=>{if(!u.isToken)return u.value;const l=u.value;(!n?.useAdditionalWeekYearTokens&&Ws(l)||!n?.useAdditionalDayOfYearTokens&&Hs(l))&&Is(l,t,String(e));const h=me[l[0]];return h(o,l,a.localize,c)}).join("")}function Us(e){const t=e.match(Os);return t?t[1].replace(Ns,"'"):e}function xe(e){const t=w(e),n=t.getFullYear(),s=t.getMonth(),a=$(e,0);return a.setFullYear(n,s+1,0),a.setHours(0,0,0,0),a.getDate()}function Ys(e){const t=w(e).getFullYear();return t%400===0||t%4===0&&t%100!==0}function Se(e){const t=w(e);return String(new Date(t))==="Invalid Date"?NaN:Ys(t)?366:365}function Bs(e){const t=vt(e),n=+vt(ce(t,60))-+t;return Math.round(n/ot)}function H(e,t){const n=w(e),s=w(t);return+n==+s}function Fs(e){const t=w(e);return t.setMinutes(0,0,0),t}function js(e,t,n){const s=C(e,n),a=C(t,n);return+s==+a}function qs(e,t){const n=w(e),s=w(t);return n.getFullYear()===s.getFullYear()&&n.getMonth()===s.getMonth()}function Ls(e,t){const n=J(e),s=J(t);return+n==+s}function Xs(e,t){const n=w(e),s=w(t);return n.getFullYear()===s.getFullYear()}const Ht={year:zn,quarter:Nn,month:he,week:_t,day:St,hour:Pn,minute:Cn},N={year:{quarter:4,month:12,week:Bs,day:Qs,hour:Gs},quarter:{month:3,week:Rs,day:ve,hour:Js},month:{week:Vs,day:Ks,hour:Zs},week:{day:7,hour:24*7},day:{hour:24},hour:{minute:60}};function Qs(e){return e?Se(e):365}function Gs(e){return Se(e)*24}function Rs(e){const t=J(e),n=it(U(Mt(e)),1);return _t(n,t)}function ve(e){if(e){const t=J(e),n=Mt(e);return St(n,t)+1}return 91}function Js(e){return ve(e)*24}function Vs(e){if(e){const t=fe(e),n=it(U(Tt(e)),1);return _t(n,t)}return 5}function Ks(e){return e?xe(e):30}function Zs(e){return xe(e)*24}function ct(e,t,n){const s=N[e][t];return s?typeof s=="number"?s:s(n):1}function ta(e,t){return e===t||!!(N[e]&&N[e][t])}const ut={year:Mn,quarter:Tn,month:xt,week:ce,day:it,hour:vn,minute:Dn};function E(e,t,n){if(t){if(e==="day")return(s,a)=>t.getWorkingDays(a,s,!0);if(e==="hour")return(s,a)=>t.getWorkingHours(a,s,!0)}return(s,a,r,i)=>!N[e][r]||typeof N[e][r]=="number"||Te(e,s,a,n)?Z(e,s,a,r,i,n):ea(s,a,e,r,i,n)}function Z(e,t,n,s,a,r){const i=s||e;let o=n,d=t;if(a&&(o=I(i,n,r),d=I(i,t,r),d<t&&(d=T(i)(d,1))),e!==i){const c=Ht[i](d,o),u=ct(e,i,n);return c/u}else return Ht[i](d,o)}function ea(e,t,n,s,a,r){let i=0;const o=I(n,t,r);if(t>o){const c=ut[n](o,1);i=Z(n,c,t,s,void 0,r),t=c}let d=0;return Te(n,t,e,r)||(d=Z(n,I(n,e,r),t,void 0,void 0,r),t=ut[n](t,d)),d+=i+Z(n,e,t,s,void 0,r),!d&&a&&(d=Z(n,e,t,s,a,r)),d}function T(e,t){if(t){if(e==="day")return(n,s)=>t.addWorkingDays(n,s,!0);if(e==="hour")return(n,s)=>t.addWorkingHours(n,s)}return ut[e]}const _e={year:ge,quarter:J,month:fe,week:(e,t)=>C(e,{weekStartsOn:t}),day:U,hour:Fs};function I(e,t,n){const s=_e[e];return s?s(t,n):new Date(t)}const na={year:An,quarter:Mt,month:Tt,week:(e,t)=>Yn(e,{weekStartsOn:t}),day:le,hour:Un},De={year:Xs,quarter:Ls,month:qs,week:(e,t,n)=>js(e,t,{weekStartsOn:n}),day:$n};function Te(e,t,n,s){const a=De[e];return a?a(t,n,s):!1}const sa={start:_e,end:na,add:ut,isSame:De,diff:Ht,smallerCount:N},Me=e=>typeof e=="function"?e(new Date):e;function aa(e,t){for(const n in t){if(n==="smallerCount"){const s=Object.keys(t[n]).sort((o,d)=>W.indexOf(o)-W.indexOf(d)).shift();let a=W.indexOf(s);const r=t[n][s],i=Me(r);for(let o=a-1;o>=0;o--){const d=W[o],c=Me(N[d][s]);if(i<=c)break;a=o}W.splice(a,0,e)}if(n==="biggerCount")for(const s in t[n])N[s][e]=t[n][s];else sa[n][e]=t[n]}}function Wt(e,t=1,n){return n.isWorkingDay(e)||(e=t>0?n.getNextWorkingDay(e):n.getPreviousWorkingDay(e)),e}function lt(e){return(t,n)=>{if(n>0)for(let s=0;s<n;s++)t=e.getNextWorkingDay(t);if(n<0)for(let s=0;s>n;s--)t=e.getPreviousWorkingDay(t);return t}}function L(e){const t=new Date;return e.map(n=>({item:n,len:T(n.unit)(t,1)})).sort((n,s)=>n.len<s.len?-1:1)[0].item}const W=["year","quarter","month","week","day","hour"],It=50,Et=300;function ra(e,t,n,s,a){let r=e,i=t,o=!1,d=!1;a&&a.forEach(u=>{(!e||n)&&(!r||u.start<=r)&&(r=u.start,o=!0);const l=u.type==="milestone"?u.start:u.end;(!t||n)&&(!i||l>=i)&&(i=l,d=!0)});const c=T(s||"day");return r?o&&(r=c(r,-1)):i?r=c(i,-30):r=new Date,i?d&&(i=c(i,1)):i=c(r,30),{_start:r,_end:i}}function ia(e,t,n,s,a,r,i){const o=L(i).unit,d=E(o,void 0,r),c=d(t,e,"",!0),u=I(o,t,r);e=I(o,e,r),t=u<t?T(o)(u,1):u;const l=c*s,h=a*i.length,f=i.map(g=>{const m=[],k=T(g.unit);let y=I(g.unit,e,r);for(;y<t;){const b=k(y,g.step),_=y<e?e:y,x=b>t?t:b,S=d(x,_,"",!0)*s,v=typeof g.format=="function"?g.format(y,b):g.format;let M="";g.css&&(M+=typeof g.css=="function"?g.css(y):g.css),m.push({width:S,value:v,date:_,css:M,unit:g.unit}),y=b}return{cells:m,add:k,height:a}});let p=s;return o!==n&&(p=Math.round(p/ct(o,n))||1),{rows:f,width:l,height:h,diff:d,start:e,end:t,lengthUnit:n,minUnit:o,lengthUnitWidth:p}}function oa(e,t,n,s){const a=typeof e=="boolean"?{}:e,r=W.indexOf(L(n).unit);if(typeof a.level>"u"&&(a.level=r),a.levels)a.levels.forEach(d=>{d.minCellWidth||(d.minCellWidth=ht(a.minCellWidth,It)),d.maxCellWidth||(d.maxCellWidth=ht(a.maxCellWidth,Et))});else{const d=[],c=n.length||1,u=ht(a.minCellWidth,It),l=ht(a.maxCellWidth,Et);n.forEach(h=>{h.format&&!t[h.unit]&&(t[h.unit]=h.format)}),W.forEach((h,f)=>{if(f===r)d.push({minCellWidth:u,maxCellWidth:l,scales:n});else{const p=[];if(f)for(let g=c-1;g>0;g--){const m=W[f-g];m&&p.push({unit:m,step:1,format:t[m]})}p.push({unit:h,step:1,format:t[h]}),d.push({minCellWidth:u,maxCellWidth:l,scales:p})}}),a.levels=d}a.levels[a.level]||(a.level=0);const i=a.levels[a.level],o=Math.min(Math.max(s,i.minCellWidth),i.maxCellWidth);return{zoom:a,scales:i.scales,cellWidth:o}}function da(e,t,n,s,a,r,i){e.level=n;let o;const d=s.scales||s,c=L(d).unit,u=ca(c,a);if(t===-1){const f=ct(c,a);o=i*f}else{const f=ct(L(r).unit,c);o=Math.round(i/f)}const l=s.minCellWidth??It,h=s.maxCellWidth??Et;return{scales:d,cellWidth:Math.min(h,Math.max(l,o)),lengthUnit:u,zoom:e}}function ca(e,t){const n=W.indexOf(e),s=W.indexOf(t);return s>=n?e==="hour"?"hour":"day":W[s]}function ht(e,t){return e??t}function Pt(){let e=!0;return e=!1,e}const Ct=8,$e=4,ua=3,He=7,la=Ct+$e;function We(e,t,n,s){(e.open||e.type!="summary")&&e.data?.forEach(a=>{typeof a.$x>"u"&&Ee(a,n,s),a.$x+=t,We(a,t,n,s)})}function Ot(e,t,n,s){const a=e.getSummaryId(t.id);if(a){const r=e.byId(a),i={xMin:1/0,xMax:0};Ie(r,i,n,s),r.$x=i.xMin,r.$w=i.xMax-i.xMin,Ot(e,r,n,s)}}function Ie(e,t,n,s){e.data?.forEach(a=>{if(!a.unscheduled){typeof a.$x>"u"&&Ee(a,n,s);const r=a.type==="milestone"&&a.$h?a.$h/2:0;t.xMin>a.$x&&(t.xMin=a.$x+r);const i=a.$x+a.$w-r;t.xMax<i&&(t.xMax=i)}a.type!=="summary"&&Ie(a,t,n,s)})}function Ee(e,t,n){e.$x=Math.round(t.diff(e.start,t.start,t.lengthUnit)*n),e.$w=Math.round(t.diff(e.end,e.start,t.lengthUnit,!0)*n)}function Nt(e,t){let n;t&&(n=t.filter(a=>a.parent==e.id));const s={data:n,...e};if(s.data?.length)s.data.forEach(a=>{if(a.unscheduled&&!a.data)return;(t||a.type!="summary"&&a.data)&&(a.unscheduled&&(a={...a,start:void 0,end:void 0}),a=Nt(a,t)),a.start&&(!s.start||s.start>a.start)&&(s.start=new Date(a.start));const r=a.end||a.start;r&&(!s.end||s.end<r)&&(s.end=new Date(r))});else if(e.type==="summary")throw Error("Summary tasks must have start and end dates if they have no subtasks");return s}function Pe(e,t,n){return Ce(e,t,n,!1),n.splitTasks&&e.segments?.forEach(s=>{Pe(s,t,{...n,baselines:!1}),s.$x-=e.$x}),n.baselines&&Ce(e,t,n,!0),e}function Ce(e,t,n,s){const{cellWidth:a,cellHeight:r,_scales:i,baselines:o}=n,{start:d,end:c,lengthUnit:u,diff:l}=i,h=(s?"base_":"")+"start",f=(s?"base_":"")+"end",p="$x"+(s?"_base":""),g="$y"+(s?"_base":""),m="$w"+(s?"_base":""),k="$h"+(s?"_base":""),y="$skip"+(s?"_baseline":"");let b=e[h],_=e[f];if(s&&!b){e[y]=!0;return}e[h]<d&&(e[f]<d||H(e[f],d))?b=_=d:e[h]>c&&(b=_=c),e[p]=Math.round(l(b,d,u)*a),e[g]=s?e.$y+e.$h+$e:r*t+ua,e[m]=Math.round(l(_,b,u,!0)*a),e[k]=s?Ct:o?r-He-la:r-He,e.type==="milestone"&&(e[p]=e[p]-e.$h/2,e[m]=e.$h,s&&(e[g]=e.$y+Ct,e[m]=e[k]=e.$h)),n.unscheduledTasks&&e.unscheduled&&!s?e.$skip=!0:e[y]=H(b,_)}function ha(e,t){if(Pt())return!1;const{mode:n,l:s,w:a,dx:r,index:i}=t,{segments:o}=e;if(i||n==="end"){if(r>0&&i<o.length-1){if(s+a+r>o[i+1].$x+e.$x)return!1}else if(r<0&&i){const d=n==="end"?a:0;if(s+r+d<o[i-1].$x+e.$x+o[i-1].$w)return!1}}return!0}function fa(e,t){if(Pt())return;const{segments:n}=e,{segmentIndex:s,mode:a}=t,r=n[s];(s||a!=="move")&&(t.index=s,t.l=r.$x+e.$x,t.w=r.$w,t.segment=!0)}const zt=20,ga=function(e,t,n,s,a){const r=Math.round(s/2)-3;if(!t||!n||!t.$y||!n.$y||t.$skip||n.$skip)return e.$p="",e.$pl=0,e;let i=!1,o=!1;switch(e.type){case"e2s":o=!0;break;case"s2s":i=!0,o=!0;break;case"s2e":i=!0;break}const d=i?t.$x:t.$x+t.$w,c=a?t.$y-7:t.$y,u=o?n.$x:n.$x+n.$w,l=a?n.$y-7:n.$y;if(d!==u||c!==l){const h=ma(d,c+r,u,l+r,i,o,s/2,a),f=ka(u,l+r,o);e.$p=`${h},${f}`,e.$pl=pa(e.$p)}return e};function pa(e){const t=e.split(",").map(Number),n=[];for(let a=0;a<t.length;a+=2)a+1<t.length&&n.push([t[a],t[a+1]]);let s=0;for(let a=0;a<n.length-1;a++){const[r,i]=n[a],[o,d]=n[a+1];s+=Math.hypot(o-r,d-i)}return s}function ma(e,t,n,s,a,r,i,o){const d=zt*(a?-1:1),c=zt*(r?-1:1),u=e+d,l=n+c,h=[e,t,u,t,0,0,0,0,l,s,n,s],f=l-u;let p=s-t;const g=r===a;return g||(l<=e+zt-2&&r||l>e&&!r)&&(p=o?p-i+6:p-i),g&&r&&u>l||g&&!r&&u<l?(h[4]=h[2]+f,h[5]=h[3],h[6]=h[4],h[7]=h[5]+p):(h[4]=h[2],h[5]=h[3]+p,h[6]=h[4]+f,h[7]=h[5]),h.join(",")}function ka(e,t,n){return n?`${e-5},${t-3},${e-5},${t+3},${e},${t}`:`${e+5},${t+3},${e+5},${t-3},${e},${t}`}function ya(e,t,n){if(t&&n){const s=n.x-t.x,a=n.y-t.y,r=(s>0?t.x:n.x)-e.left,i=(a>0?t.y:n.y)-e.top,o=`${s>0?0:-s},${a>0?0:-a},${s>0?s:0},${a>0?a:0}`;return{width:Math.abs(s),height:Math.abs(a),left:r,top:i,p:o}}else return null}function Oe(e){return e.map(t=>{const n=t.id||bt();return{...t,id:n}})}const Ne=["start","end","duration"];function ba(e,t){const{type:n,unscheduled:s}=e;return s||n==="summary"?!Ne.includes(t):n==="milestone"?!["end","duration"].includes(t):!0}function wa(e,t){return typeof t=="function"?t:Ne.includes(e)?(typeof t=="string"&&(t={type:t,config:{}}),t.config||(t.config={}),t.type==="datepicker"&&(t.config.buttons=["today"]),(n,s)=>ba(n,s.id)?t:null):t}function xa(e){return!e||!e.length?[]:e.map(t=>{const n=t.align||"left",s=t.id==="add-task",a=!s&&t.flexgrow?t.flexgrow:null,r=a?1:t.width||(s?50:120),i=t.editor&&wa(t.id,t.editor);return{width:r,align:n,header:t.header,id:t.id,template:t.template,_template:t._template,...a&&{flexgrow:a},cell:t.cell,resize:t.resize??!0,sort:t.sort??!s,...i&&{editor:i},...t.options&&{options:t.options}}})}const Sa=[{id:"text",header:"Task name",flexgrow:1,sort:!0},{id:"start",header:"Start date",align:"center",sort:!0},{id:"duration",header:"Duration",width:100,align:"center",sort:!0},{id:"add-task",header:"Add task",width:50,align:"center",sort:!1,resize:!1}];function tt(e,t,n,s){const{selected:a,tasks:r}=e.getState(),i=a.length,o=["edit-task","paste-task","edit-task:task","edit-task:segment"],d=["copy-task","cut-task"],c=["copy-task","cut-task","delete-task","indent-task:remove","move-task:down"],u=["add-task","undo","redo"],l=["indent-task:add","move-task:down","move-task:up"],h={"indent-task:remove":2},f=!i&&u.includes(t),p={parent:l.includes(t),level:h[t]};if(n=n||(i?a[a.length-1]:null),!(!n&&!f)){if(t!=="paste-task"&&(e._temp=null),o.includes(t)||f||a.length===1)ze(e,t,n,s);else if(i){const g=d.includes(t)?a:va(a,r,p);c.includes(t)&&g.reverse();const m=e.getHistory();m&&m.startBatch(),g.forEach((k,y)=>ze(e,t,k,s,y)),m&&m.endBatch()}}}function va(e,t,n){let s=e.map(a=>{const r=t.byId(a);return{id:a,level:r.$level,parent:r.parent,index:t.getIndexById(a)}});return(n.parent||n.level)&&(s=s.filter(a=>n.level&&a.level<=n.level||!e.includes(a.parent))),s.sort((a,r)=>a.level-r.level||a.index-r.index),s.map(a=>a.id)}function ze(e,t,n,s,a){const r=e.exec?e.exec:e.in.exec;let i=t.split(":")[0],o=t.split(":")[1];const d=n?.id||n;let c={id:d},u={},l=!1;if(i=="copy-task"||i=="cut-task"){e._temp||(e._temp=[]),e._temp.push({id:d,cut:i=="cut-task"});return}else if(i=="paste-task"){if(e._temp&&e._temp.length){const h=e.getHistory();h&&h.startBatch();const f=new Map;if(e._temp.forEach(p=>{const g={id:p.id,target:d,mode:"after"};r(p.cut?"move-task":"copy-task",g),f.set(p.id,g.id)}),!e._temp[0].cut){const{links:p}=e.getState(),g=e._temp.map(k=>k.id),m=[];p.forEach(k=>{g.includes(k.source)&&g.includes(k.target)&&m.push(k)}),m.forEach(k=>{r("add-link",{link:{source:f.get(k.source),target:f.get(k.target),type:k.type}})}),e._temp.forEach((k,y)=>{r("select-task",{id:f.get(k.id),toggle:!!y})})}h&&h.endBatch(),e._temp=null}return}else i==="add-task"?(u={task:{type:"task",text:s("New Task")},target:d,show:!0,select:!1},c={},l=!0):i==="edit-task"?(i="show-editor",o==="segment"&&typeof n=="object"&&(u=n)):i==="convert-task"?(i="update-task",u={task:{type:o}},o=void 0):i==="indent-task"&&(o=o==="add");if(i==="split-task"&&typeof n=="object")u=n;else if(i==="delete-task"&&o==="segment"&&typeof n=="object"){const h=e.getTask(d),{segmentIndex:f}=n,p=h.segments.filter((g,m)=>m!==f);r("update-task",{id:d,task:{segments:p}});return}typeof o<"u"&&(u={mode:o,...u}),c={...c,...u},r(i,c),l&&r("select-task",{id:c.id,toggle:!!a})}function Ae(e,t){return e.some(n=>n.data?Ae(n.data,t):n.id===t)}const Ue=(e,t)=>T(e,t),_a=(e,t)=>E(e,t);function Ye(e,t){Array.isArray(e)&&(e.forEach(n=>z(n,t)),e.forEach(n=>{if(n.type==="summary"&&!(n.start&&n.end)){const{start:s,end:a}=Nt(n,e);n.start=s,n.end=a,z(n,t)}}))}function z(e,t){e.unscheduled||At(e,t,!1),e.base_start&&At(e,t,!0)}function At(e,t,n){const{calendar:s,durationUnit:a}=t,r=a||"day",[i,o,d]=Be(n);if(e.type==="milestone")e[d]=0,e[o]=void 0;else if(e[i]){if(!n&&t.splitTasks&&e.segments)return Ta(e,t);e[d]?e[o]=Ue(r,s)(e[i],e[d]):e[o]?e[d]=_a(r,s)(e[o],e[i]):(e[o]=Ue(r,s)(e[i],1),e[d]=1)}}function Be(e){return e?["base_start","base_end","base_duration"]:["start","end","duration"]}function Fe(e,t,n){const[s,a,r]=Be(n);(t===r||t===s)&&(e[a]=null),t===a&&(e[r]=0,e[s]&&e[s]>=e[a]&&(e[a]=null,e[r]=1))}function Da(e,t,n){Fe(e,n,!1),e.base_start&&Fe(e,n,!0),z(e,t)}function Ta(e,t){if(!e.segments.length||e.type==="summary"||e.duration===0)return;const{segments:n}=e,s=e.start&&e.end===null&&e.duration,{_scales:a,calendar:r}=t,i=s&&T(a.lengthUnit,r);let o=0;for(let d=0;d<n.length&&(!s||o!==s);d++){const c=n[d];At(c,t),s&&(s<=o+c.duration||d===n.length-1)?(e.end=i(c.start,s-o),o=s):o+=c.duration}e.duration=o,s||(e.end=n[n.length-1].end)}function Ma(e,t){const{left:n,width:s,segmentIndex:a}=t,r=typeof n<"u",i=typeof s<"u",{segments:o}=e;if(!o?.length||!r&&!i)return;const d=o[a];if(r){const l=n-e.$x;if(a)d.$x=l;else for(let h=1;h<o.length;h++)o[h].$x+=-l}i&&(d.$w=s);const c=o.length;let u=!1;if(!a&&i||a===o.length-1){const l=o[c-1];t.width=l.$x-o[0].$x+l.$w,u=!0}else delete t.width;return!a&&r?u=!0:delete t.left,u}function je(e,t){return e.map(n=>(delete n.duration,z(n,t),n))}function qe(e,t,n,s,a){let r=t.segments||e.segments;const i=r?.length;if(!i||Ut(t)||t.segments===null)return{...t,segments:null};let o=e;const d=s||s===0;d&&(o=e.segments[s]);const{_scales:c,calendar:u}=n,{lengthUnit:l}=c,h=t.start&&!H(o.start,t.start),f=t.end&&!H(o.end,t.end),p=E(l,u),g=E(l),m=T(l,u),k=T(l),y=u?lt(u):m;r=r.map(S=>({...S}));const b=h?g(t.start,o.start):0,_=f?g(t.end,o.end):0;if(u){if(b&&!u.isWorkingDay(t.start)&&(t.start=y(t.start,b>0||!a?1:-1)),_)if(h)t.end=y(t.start,t.duration||o.duration);else{const S=k(t.end,-1);u.isWorkingDay(S)||(t.end=y(t.end,_>0||!a?1:-1),_<0&&a&&(t.end=k(t.end,1)))}b&&H(t.end,t.start)&&(t.end=m(t.end,1))}let x;if(d&&(x={...t},t={}),h||f){if(d){let S,v;i>1&&(S=s>0?r[s-1]:null,v=s<i-1?r[s+1]:null,h&&(S&&(x.start<S.end||H(x.start,S.start))?x.start=S.end:v&&x.start.valueOf()>=v.start.valueOf()&&(x.start=m(v.start,-1))),f&&(v&&x.end>v.start?x.end=v.start:S&&x.end<S.end&&(x.end=m(S.end,1))));const M=r[s];if(h&&S&&!p(x.start,S.end)){if(x.start=S.start,u){const F=p(x.end||M.end,S.end)||1;x.duration=S.duration+F,x.end=m(x.start,x.duration)}r.splice(s-1,1),s--}else if(f&&v&&!p(v.start,x.end)){if(x.end=v.end,u){const F=p(v.start,x.start||M.start)||1;x.duration=v.duration+F,x.start=y(x.end,-x.duration)}r.splice(s+1,1)}r[s]={...M,...x}}else if(h){const S=Le(l,u);let v=0;b>0?v=p(t.start,r[0].start):v=-p(e.start,t.start),v&&(r=r.map(M=>(M.start=y(M.start,v),M.end=S(M.start,M.duration),M))),u&&Xe(r,c.lengthUnit,0,u,v),t.end=r[r.length-1].end}else if(f)if(_>0)r[i-1].end=t.end;else for(let S=i-1;S>=0;S--){const v=r[S];v.start.valueOf()>=t.end.valueOf()?r.splice(S,1):S===r.length-1&&(v.end=t.end)}t.segments=je(r,n)}else d&&(r[s]={...r[s],...x},t.segments=r);return(d||t.segments)&&(r=t.segments||r,t.start=r[0].start,t.end=r[r.length-1].end),r.length<2&&(t.segments=null),t}function $a(e,t,n){const{_scales:s,calendar:a}=n;let r,{segments:i}=e;const o=i?.length;o&&(typeof t>"u"&&(t=o-1),r=i[t]);const d=r||e;i=i?.map(_=>({..._}));const{lengthUnit:c}=s,u=d.duration;if(u<=1)return null;const l={},h=T(c,a),f=Le(c,a),p=E(c,a),g=a?lt(a):h,m=u-Math.round(u/2),k=u-m,y=f(d.start,k);r||(i=l.segments=[],i.push({start:d.start,end:y})),t=t||0,i[t].end=y;let b=g(y,1);return a&&!p(b,y)&&(b=g(b,1)),i.splice(t+1,0,{start:b,end:g(b,m)}),Xe(i,c,t+1,a),l.end=i[i.length-1].end,l.segments=je(i,n),l}function Ut(e){return e.type==="summary"||e.type==="milestone"}function Ha(e,t,n){if(Ut(e))return!0;const{_scales:s,calendar:a}=t,{lengthUnit:r}=s;let i=e;const{segments:o}=e;return o?.length&&(typeof n>"u"&&(n=o.length-1),i=e.segments[n]),E(r,a)(i.end,i.start)<2}function Le(e,t){const n=T(e);if(!t)return n;const s=T(e,t);return(a,r)=>{const i=s(a,r-1);return t.isWorkingDay(i)?n(i,1):s(i,1)}}function Xe(e,t,n,s,a){const r=T(t,s),i=E(t),o=s?lt(s):null;for(let d=n+1;d<e.length;d++){const c=e[d],u=e[d-1].end,l=i(c.start,u);l<1?(c.start=r(u,1),c.end=r(c.start,c.duration)):s&&!s.isWorkingDay(c.start)&&(c.start=o(c.start,a<0&&l>1?-1:1),c.end=r(c.start,c.duration))}}class Yt{in;getState;setState;getHistory;_timer;_tags=new Set;constructor(t,n,s,a){this.in=t,this.getState=n,this.setState=s,this.getHistory=a}debounce(t,n=10){clearTimeout(this._timer),this._timer=setTimeout(t,n)}shouldTrack(t,n={}){return!(t.inProgress||n[t.eventSource])}registerHandler(t,n,s,a){const r=a||`${this.getDefaultTag()}-${t}`;this.in[t](n,s,{tag:r}),this._tags.add(r)}on(t,n,s){this.registerHandler("on",t,n,s)}intercept(t,n,s){this.registerHandler("intercept",t,n,s)}detachHandlers(){this._tags.forEach(t=>this.in.detach(t))}}class Wa extends Yt{undo=[];redo=[];progress={};_dataSnapshot={};_batch=[];_isBatching=!1;init(){this.setHandlers(),this.resetStateHistory()}destroy(){this.setState({history:null})}getDefaultTag(){return"historyManager"}getHandlers(){return{"add-task":{handler:t=>{let{task:n}=t;return n=P(n),n.data&&delete n.data,n.open&&delete n.open,{action:"delete-task",data:{id:t.id},source:{action:"add-task",data:{...t,task:n,select:!1}}}}},"delete-task":{getSnapshot:t=>this.getOrder(t.id,!0),handler:t=>{const{id:n}=t,{task:s,mode:a,target:r,kids:i,links:o}=this.getPrevData(),d=[{id:n,task:s,mode:a,target:r,select:!1}];return i.forEach(c=>{d.push({id:c.id,task:c,mode:"child",select:!1})}),o.forEach(c=>{d.push({action:"add-link",link:c})}),{action:"add-task",data:d,source:{action:"delete-task",data:t}}}},"update-task":{getSnapshot:t=>{const{id:n}=t,{tasks:s}=this.getState(),a=s.byId(n);return{task:P(a)}},handler:t=>{const{id:n}=t,{task:s}=this.getPrevData(),a=P(t.task);if(a.segments&&!s.segments&&(s.segments=null),!wt(s,a))return{action:"update-task",data:{id:n,task:s},source:{action:"update-task",data:{...t,task:a,diff:void 0,segmentIndex:void 0}}}},progress:!0},"copy-task":{handler:t=>{const{id:n}=t,{task:s,mode:a,target:r,kids:i,links:o}=this.getOrder(t.id,!0),d=[{id:n,task:s,mode:a,target:r,select:!1}];return i.forEach(c=>{d.push({id:c.id,task:c,select:!1})}),o.forEach(c=>{d.push({action:"add-link",link:c})}),{action:"delete-task",data:{id:t.id},source:{action:"add-task",data:d}}}},"move-task":{getSnapshot:t=>this.getOrder(t.id),handler:t=>{const{id:n}=t,{target:s,mode:a}=this.getPrevData();return{action:"move-task",data:{id:n,target:s,mode:a},source:{action:"move-task",data:{id:n,target:t.target,mode:t.mode}}}},progress:!0},"add-link":{handler:t=>({action:"delete-link",data:{id:t.id},source:{action:"add-link",data:t}})},"delete-link":{getSnapshot:t=>{const{id:n}=t,{links:s}=this.getState(),a=s.byId(n);return{link:P(a)}},handler:t=>{const{link:n}=this.getPrevData();return{action:"add-link",data:{id:t.id,link:n},source:{action:"delete-link",data:t}}}},"update-link":{getSnapshot:t=>{const{id:n}=t,{links:s}=this.getState(),a=s.byId(n);return{link:P(a)}},handler:t=>{const{link:n}=this.getPrevData();return{action:"update-link",data:{id:t.id,link:n},source:{action:"update-link",data:t}}}}}}resetHistory(){this.undo=[],this.redo=[],this.progress={},this.resetStateHistory()}setHandlers(){const t=this.getHandlers();for(const n in t){const{getSnapshot:s,handler:a,progress:r}=t[n];this.in.intercept(n,i=>{if(!(i.eventSource==="undo"||i.eventSource==="redo"||i.skipUndo||!s)){if(r){(i.inProgress&&!this.progress[n]||typeof i.inProgress!="boolean")&&this.setPrevData(s(i)),this.progress[n]=i.inProgress;return}this.setPrevData(s(i))}}),this.in.on(n,i=>{if(i.eventSource==="undo"||i.eventSource==="redo"||i.skipUndo||i.inProgress)return;const o=a(i);o&&this.addToHistory(o)})}}setPrevData(t){this._dataSnapshot=t}getPrevData(){return this._dataSnapshot}addToHistory(t){this._isBatching?this._batch.push(t):(this.undo.push(t),this.redo=[],this.setStateHistory())}startBatch(){this._isBatching=!0,this._batch=[]}endBatch(){if(this._isBatching=!1,this._batch.length===0)return;const t={action:"batch",data:this._batch,source:{action:"batch",data:this._batch.map(n=>n.source)}};this.undo.push(t),this._batch=[],this.redo=[],this.setStateHistory()}handleUndo(){if(!this.undo.length)return;const t=this.undo.pop();this.redo.push({...t.source,source:t}),t.action==="batch"?[...t.data].reverse().forEach(n=>{this.executeHistoryEntry(n,"undo")}):this.executeHistoryEntry(t,"undo"),this.setStateHistory()}handleRedo(){if(!this.redo.length)return;const t=this.redo.pop();this.undo.push({...t.source,source:t}),t.action==="batch"?t.data.forEach(n=>{this.executeHistoryEntry(n,"redo")}):this.executeHistoryEntry(t,"redo"),this.setStateHistory()}executeHistoryEntry(t,n){Array.isArray(t.data)?t.data.forEach(({action:s,...a})=>{const r=s||t.action,i={...a,eventSource:n};i.task&&delete i.task.data,this.in.exec(r,i)}):(t.data.task&&delete t.data.task.data,this.in.exec(t.action,{...t.data,eventSource:n}))}resetStateHistory(){this.setState({history:{undo:0,redo:0}})}setStateHistory(){this.setState({history:{undo:this.undo.length,redo:this.redo.length}})}getOrder(t,n){const{tasks:s,links:a}=this.getState();let r={};const i=[],o=s.byId(t),d=o.parent||0,c=s.byId(d).data,u=c.findIndex(h=>h.id===t),l=c[u+1];if(l?r={mode:"before",target:l.id}:c.length?r={mode:"after",target:c[u-1]?.id}:r={mode:"child",target:d},a.forEach(h=>{(h.source===t||h.target===t)&&i.push(h)}),r.task=P(o),n){const h=[];s.eachChild(f=>{h.push(f)},t),r.kids=h.map(f=>({...f})),h.forEach(f=>{a.forEach(p=>{(p.source===f.id||p.target===f.id)&&!i.some(({id:g})=>p.id==g)&&i.push(p)})})}return r.links=i,r}}const Qe=Symbol.for("constructDateFrom");function ft(e,t){return typeof e=="function"?e(t):e&&typeof e=="object"&&Qe in e?e[Qe](t):e instanceof Date?new e.constructor(t):new Date(t)}function Bt(e,t){return ft(e,e)}function et(e,t,n){const s=Bt(e);return isNaN(t)?ft(e,NaN):(t&&s.setDate(s.getDate()+t),s)}function Ia(e,...t){const n=ft.bind(null,t.find(s=>typeof s=="object"));return t.map(n)}function Ea(e,t){const n=Bt(e);return n.setHours(0,0,0,0),n}function Pa(e,t){const[n,s]=Ia(e,t.start,t.end);return{start:n,end:s}}function Ft(e,t){const{start:n,end:s}=Pa(t?.in,e);let a=+n>+s;const r=a?+n:+s,i=a?s:n;i.setHours(0,0,0,0);let o=1;const d=[];for(;+i<=r;)d.push(ft(n,i)),i.setDate(i.getDate()+o),i.setHours(0,0,0,0);return a?d.reverse():d}function Ca(e,t){return Bt(e).getDay()}function jt(e){return Math.round(e.getTime()/864e5)-19e3}function Ge(e,t){return jt(e)}function Re(e,t){return t.inclusiveEnd?jt(e)+1:jt(e)}function Je(e){const t=new Date((e+19e3)*864e5);return new Date(t.getFullYear(),t.getMonth(),t.getDate())}var Ve=class{constructor(e,t,n){e&&this.parse(e,t,n)}parse(e,t=[],n={}){this._originalData=[...e],this._originalLinks=[...t],this._originalConfig={...n},this._nodes=new Map;const{start:s,end:a}=Oa(e,n),r=this._data=new Array(e.length+2);if(r[0]={id:0,in:[],out:[],counter:0,start:Ge(s)},r[1]={id:1,in:[],out:[],counter:0,start:Re(a,n)},!e.length){const h={left:r[0],right:r[1],lag:void 0};r[0].out.push(h),r[1].in.push(h);return}for(let h=0;h<e.length;h++){const f=e[h],p=2*h+2,g={};r[p]={id:p,in:[],out:[g],counter:0,start:Ge(f.start)},r[p+1]={id:p+1,in:[g],out:[],counter:0,start:Re(f.end||f.start,n)},g.left=r[p],g.right=r[p+1],g.lag=f.duration||g.right.start-g.left.start,this._nodes.set(f.id,p)}for(const h of t){const f=r[this._nodes.get(h.source)+1],p=r[this._nodes.get(h.target)];if(!f||!p){console.warn(`Link ${h.source} -> ${h.target} not found`);continue}const g={left:f,right:p,lag:h.lag!==void 0?h.lag:void 0};f.out.push(g),p.in.push(g)}const i=[],o=[];let d=r[2],c=r[2];for(let h=2;h<r.length;h++){const f=r[h];f.in.length===0&&i.push(f),f.out.length===0&&o.push(f),f.start<d.start&&(d=f),f.start>c.start&&(c=f)}i.length||i.push(d),o.length||o.push(c);const u=r[0],l=r[1];for(const h of i){const f={left:u,right:h,lag:void 0};u.out.push(f),h.in.push(f)}for(const h of o){const f={left:h,right:l,lag:void 0};h.out.push(f),l.in.push(f)}}byOrder(e){return this._data[e]}byId(e){return this._data[this._nodes.get(e)]}toTaskIds(e,t=!1){if(!t)return e.map(a=>this.getTaskId(a));const n=[];let s=null;for(const a of e){const r=this.getTaskId(a);r===0||s===r||(s=r,n.push(r))}return n}toTasks(e){return e.map(t=>this.getCurrentTask(t))}forward(e){this._resetCounters();const t=[this._data[0]];let n=0;for(;n<t.length;){const s=t[n];e(s);for(const a of s.out){const r=a.right;r&&(r.counter++,r.counter===r.in.length&&t.push(a.right))}n++}return t}backward(e){this._resetCounters();const t=[this._data[1]];let n=0;for(;n<t.length;){const s=t[n];e(s);for(const a of s.in){const r=a.left;r&&(r.counter++,r.counter===r.out.length&&t.push(a.left))}n++}return t}_resetCounters(){for(const e of this._data)e.counter=0}resetToOriginal(){this.parse(this._originalData,this._originalLinks,this._originalConfig)}getCurrentTask(e){const t=this.getTaskId(e),n=this.getOriginalTask(t)||{id:"__new"},s=e-e%2,a=this._data[s].start,r=this._data[s+1].start,i=this._data[s].out[0].lag;return{...n,start:Je(a),end:Je(r),duration:i}}getOriginalTask(e){return this._originalData.find(t=>t.id===e)}getTaskId(e){if(e<=1)return 0;const t=Math.floor((e-2)/2);return this._originalData[t].id}getStartNodeId(e){return this._nodes.get(e)||0}getEndNodeId(e){const t=this._nodes.get(e);return t!==void 0?t+1:0}};function Oa(e,t){if(t.start&&t.end)return{start:t.start,end:t.end};let n=t.start||new Date(2970,1,1),s=t.end||new Date(1970,1,1);for(const a of e)a.start<n&&(n=a.start),a.end>s&&(s=a.end);return{start:n,end:s}}var Ke=1,Ze=2;function Na(e,t,n){const s=za(e,t,n);return e.toTaskIds(s,!0)}function za(e,t,n){const s=Ua(e,n),a=[],r=e.byOrder(0),i=e.byOrder(1);if(t===Ke){let o=i;const d=0;for(;o!==r;){o!==i&&a.push(o.id);let c=null,u=1/0,l=-1;for(const h of o.in){const f=s.get(h.left.id);(f.totalSlack<u||f.totalSlack===u&&f.count>l)&&(l=f.count,c=h.left,u=f.totalSlack)}if(u>d||!c)break;o=c}return a.reverse()}else if(t===Ze){let o=r;for(;o!==i;){o!==r&&a.push(o.id);let d=0,c=1/0;for(let u=0;u<o.out.length;u++){const l=o.out[u].right,h=s.get(l.id),f=o.out[u].lag??0,p=h.earliest-(o.start+f),g=h.pathSlack+p;g<c&&(c=g,d=u)}o=o.out[d].right}}return a}function Aa(e){return Math.round(e.getTime()/864e5)-19e3}function gt(e){const t=new Date((e+19e3)*864e5);return new Date(t.getFullYear(),t.getMonth(),t.getDate())}function qt(e,t,n){if(!n)return e+t;const s=gt(e),a=n.addWorkingDays(s,t);return a?Aa(a):e+t}function Ua(e,t){const n=new Map,s=t?.calendar,a=e.byOrder(0).start;e.forward(i=>{let o=a;for(const d of i.in){const c=n.get(d.left.id);if(c){const u=qt(c.earliest,d.lag??0,s);u>o&&(o=u)}}n.set(i.id,{earliest:o,latest:0,freeSlack:0,totalSlack:0,pathSlack:0,count:0})});const r=e.byOrder(1).start;return e.backward(i=>{const o=n.get(i.id);let d=r,c=r,u=0,l=r;for(const h of i.out){const f=n.get(h.right.id),p=h.lag??0,g=qt(f.latest,-p,s);g<d&&(d=g),(f.pathSlack<c||f.pathSlack===c&&f.count>u)&&(u=f.count,c=f.pathSlack);const m=qt(f.earliest,-p,s);m<l&&(l=m)}if(o.latest=d,s){const h=gt(o.earliest),f=gt(o.latest),p=gt(l);o.totalSlack=s.getWorkingDays(h,f,!0),o.freeSlack=s.getWorkingDays(h,p,!0)}else o.totalSlack=o.latest-o.earliest,o.freeSlack=l-o.earliest;o.pathSlack=c+o.totalSlack,o.count=u+1}),n}var Ya=class A{static{this.globalConfig={defaultHoursPerDay:8,maxIterations:365}}constructor(t){this.name=t?.name,this.weekHours=[0,8,8,8,8,8,0];const n=t?.weekHours;n&&(this.weekHours=[n.sunday??0,n.monday??8,n.tuesday??8,n.wednesday??8,n.thursday??8,n.friday??8,n.saturday??0]),this.exceptions=new Map,this.rules=[]}static setGlobalConfig(t){A.globalConfig={...A.globalConfig,...t}}setDayHours(t,n){const s=this.normalizeDate(t);this.exceptions.set(s.getTime(),n)}setRangeHours(t,n,s){const a=this.normalizeDate(t),r=this.normalizeDate(n),i=Ft({start:a,end:r});for(const o of i)this.exceptions.set(o.getTime(),s)}isWorkingDay(t){return this.getWorkingHours(t)>0}getWorkingHours(t,n,s){if(n===void 0)return this.getDayHours(t);const a=this.normalizeDate(t),r=this.normalizeDate(n,s);if(a>r)return 0;let i=0;const o=Ft({start:a,end:r});for(const d of o)i+=this.getDayHours(d);return i}getWorkingDays(t,n,s){const a=this.normalizeDate(t),r=this.normalizeDate(n,s);if(a>r)return 0;let i=0;const o=Ft({start:a,end:r});for(const d of o)this.getDayHours(d)>0&&i++;return i}getNextWorkingDay(t){const n=A.globalConfig.maxIterations||365;let s=this.normalizeDate(t),a=0;for(;a<n;){if(s=et(s,1),this.getDayHours(s)>0)return s;a++}return null}getPreviousWorkingDay(t){const n=A.globalConfig.maxIterations||365;let s=this.normalizeDate(t),a=0;for(;a<n;){if(s=et(s,-1),this.getDayHours(s)>0)return s;a++}return null}addWorkingDays(t,n,s){if(n===0)return this.normalizeDate(t);const a=A.globalConfig.maxIterations||365;let r=this.normalizeDate(t);const i=n>0?1:-1;if(this.getDayHours(r)===0){const c=i>0?this.getNextWorkingDay(r):this.getPreviousWorkingDay(r);if(!c)return null;r=c}let o=s?Math.abs(n)-1:Math.abs(n),d=0;for(;o>0&&d<a;)r=et(r,i),this.getDayHours(r)>0&&o--,d++;return o>0?null:(s&&(r=et(r,i)),r)}addWorkingHours(t,n){if(n===0)return this.normalizeDate(t);const s=A.globalConfig.maxIterations||365;let a=this.normalizeDate(t),r=Math.abs(n);const i=n>0?1:-1;let o=0;for(;r>0&&o<s;){o>0&&(a=et(a,i));const d=this.getDayHours(a);d>0&&(r-=d),o++}return r>0?null:a}addRule(t){this.rules.push(t)}clone(t){const n={sunday:this.weekHours[0],monday:this.weekHours[1],tuesday:this.weekHours[2],wednesday:this.weekHours[3],thursday:this.weekHours[4],friday:this.weekHours[5],saturday:this.weekHours[6]},s=new A({name:t?.name||this.name,weekHours:t?.weekHours||n});for(const r of this.rules)s.rules.push(r);const a=r=>{const i=this.normalizeDate(r).getTime();return this.exceptions.get(i)};return s.rules.push(a),s}getDayHours(t){const n=this.normalizeDate(t),s=n.getTime(),a=this.exceptions.get(s);if(a!==void 0)return a;for(let i=this.rules.length-1;i>=0;i--){const o=this.rules[i](n);if(o!==void 0)return o}const r=Ca(n);return this.weekHours[r]??0}normalizeDate(t,n=!1){const s=Ea(t);return new Date(s.getFullYear(),s.getMonth(),s.getDate()-(n?1:0))}};function Ba(e){return e.setDate(e.getDate()-1),e}var Lt=0,tn=1,en=2,Fa=1,nn=864e5;function B(e){return Math.round(e.getTime()/nn)-19e3}function X(e){return new Date((e+19e3)*nn)}function sn(e,t,n){return t.isWorkingDay(e)?e:n===tn?t.getPreviousWorkingDay(e)??e:t.getNextWorkingDay(e)??e}function pt(e,t,n){const s=X(e),a=n.addWorkingDays(s,t);return a?B(a):e+t}var ja=-1e12,Xt=1e12;function an(e,t,n,s,a,r,i){const o=t.start>=n&&t.start<=s&&r!==Lt;if(o&&!i)return;const d=t.id%2===0,c=e.byOrder(t.id+(d?1:-1));if(o)a.debug.push(`[${t.id}] cascade: already valid, checking links only`);else{const u=d?t.out[0].lag:t.in[0].lag;let l=r!==en?s:n;if(a.calendar){const h=X(l),f=sn(h,a.calendar,r);l=B(f)}if(a.debug.push(`[${t.id}] update ${t.start} => ${l}`),t.start=l,a.modified.add(t.id),a.calendar&&d){const h=X(t.start),f=a.calendar.addWorkingDays(h,u,!0);f?l=B(f):l=t.start+u}else if(a.calendar&&!d){const h=Ba(X(t.start)),f=a.calendar.addWorkingDays(h,-u,!1);l=f?B(f):t.start-u}else l=t.start+(d?1:-1)*u;a.debug.push(`[${c.id}] update ${c.start} => ${l}`),c.start=l,a.modified.add(c.id)}nt(e,d?t.in:t.out,t,d,a,i),nt(e,d?c.out:c.in,c,d,a,i)}function nt(e,t,n,s,a,r){for(let i=0;i<t.length;i++){const o=t[i],d=o.left.id===n.id?o.right:o.left;if(d.id<2)continue;const c=o.left===d;if(c&&!a.backward||!c&&!a.forward)continue;const u=o.lag!==void 0;let l;if(u)if(a.calendar){const m=X(n.start),k=c?-o.lag:o.lag,y=a.calendar.addWorkingDays(m,k);l=y?B(y):n.start+k}else l=c?n.start-o.lag:n.start+o.lag;else if(a.calendar&&!c){const m=X(n.start),k=a.calendar.addWorkingDays(m,0);l=k?B(k):n.start}else l=n.start;let h=u?l:c?ja:l,f=u||c?l:Xt,p=d;if(d.id%2===(s?1:0)){p=e.byOrder(d.id+(s?-1:1));const m=s?d.in[0].lag:d.out[0].lag;if(a.calendar)s?(h=pt(h,-m,a.calendar),f!==Xt&&(f=pt(f,-m,a.calendar))):(h=pt(h,m,a.calendar),f!==Xt&&(f=pt(f,m,a.calendar)));else{const k=s?-m:m;h+=k,f+=k}}const g=p.start>=h&&p.start<=f;g&&!r||(g||a.debug.push(`[${n.id}] link to ${d.id} violation: [${p.id}] ${p.start} not in [${h}, ${f}]`),qa(n,p,h,f,c?tn:en,a))}}function rn(e,t,n){n.debug.push(`[${e.id}] link to ${t.id} violation: target node can't be rescheduled`),n.conflicts.push({type:Fa,source:e.id,target:t.id})}function qa(e,t,n,s,a,r){if(r.modified.has(t.id))return t.start<n||t.start>s?(rn(e,t,r),!1):!0;const i=r.signals.get(t.id);if(!i)return r.signals.set(t.id,{sourceNode:e,targetNode:t,min:n,max:s,mode:a}),r.queue.push(t.id),!0;const o=Math.max(i.min,n),d=Math.min(i.max,s);return o>d?(rn(e,t,r),!1):(i.min=o,i.max=d,!0)}function La(e,t,n,s,a){const r=Xa(e,t,n,s,a),i=new Set;for(const c of r.updates){if(c<=1)continue;const u=c-c%2;i.add(u)}const o=e.toTasks(Array.from(i)),d=r.conflicts.map(c=>({type:c.type,source:e.getTaskId(c.source),target:e.getTaskId(c.target)}));return{updates:o,conflicts:d,debug:r.debug}}function Xa(e,t,n,s,a){const r=a?.cascade??!1,i=a?.calendar,o=a?.forward??!0,d=a?.backward??!0,c=e.getStartNodeId(t),u=c<=1,l={queue:[],modified:new Set,signals:new Map,conflicts:[],debug:[],calendar:i,forward:o,backward:d};if(u){const f=e.byOrder(c);l.debug.push(`[${c}] virtual node, force=true, checking links`),nt(e,f.out,f,!0,l,r)}else{const f=e.getOriginalTask(t),p=s!==void 0&&s!==f.duration,g=p||n!==void 0&&n.getTime()!==f.start.getTime();n=n||f.start,i&&n&&(n=sn(n,i,Lt));const m=e.byOrder(c);p&&(f.duration=s,m.out[0].lag=s,e.byOrder(c+1).in[0].lag=s);const k=B(n);if(g)an(e,m,k,k,l,Lt,r);else{const y=e.byOrder(m.id+1);l.debug.push(`[${m.id}] force=true, checking links without modifying`),nt(e,m.in,m,!0,l,r),nt(e,y.out,y,!0,l,r)}}let h=0;for(;h<l.queue.length;){const f=l.signals.get(l.queue[h]);an(e,f.targetNode,f.min,f.max,l,f.mode,r),h++}return{updates:l.modified,conflicts:l.conflicts,debug:l.debug}}class mt{prevState=new Map;track(t,n,s){const a={};s.forEach(r=>{n[r]!==void 0&&(a[r]=n[r])}),this.prevState.set(t,a)}hasChanged(t,n,s){const a=this.prevState.get(t);if(!a)return!1;const r=s.some(i=>{const o=a[i],d=n[i];return o instanceof Date&&d instanceof Date?!H(o,d):o!==d});return this.prevState.delete(t),r}clear(t){t!==void 0?this.prevState.delete(t):this.prevState.clear()}getSnapshot(t){return this.prevState.get(t)}}function Qa(e){const t={},n=new Map;for(const d of e){const{source:c,target:u}=d;(t[c]??=[]).push(u),n.set(`${c}->${u}`,d)}const s=new Set,a=[],r=new Set,i=new Set,o=d=>{s.add(d),r.add(d),a.push(d);for(const c of t[d]||[])if(!s.has(c))o(c);else if(r.has(c)){const u=a.indexOf(c),l=a.slice(u).concat(c);for(let h=0;h<l.length-1;h++){const f=`${l[h]}->${l[h+1]}`;n.has(f)&&i.add(n.get(f).id)}}a.pop(),r.delete(d)};for(const d of Object.keys(t).map(Number))s.has(d)||o(d);return i}const st={"schedule-tasks":1,"move-task":1,"copy-task":1,"add-task":1};class Ga extends Yt{taskTracker=new mt;linkTracker=new mt;init(){this.setupScheduleHandler(),this.setupTaskHandlers(),this.setupLinkHandlers()}destroy(){this.taskTracker.clear(),this.linkTracker.clear(),this.detachHandlers()}schedule(t=0,n){n&&this.deleteInvalidLinks(),this.in.exec("schedule-tasks",{id:t})}getDefaultTag(){return"scheduler"}setupScheduleHandler(){this.on("schedule-tasks",({id:t,task:n})=>{const{links:s,tasks:a,projectStart:r,projectEnd:i,calendar:o,unscheduledTasks:d}=this.getState(),c={calendar:o};t===0?(n={},c.cascade=!0):n||(n=a.byId(t));const u=new Ve,l=[],h=[];s.forEach(g=>{if(g.type==="e2s"){let m=!0;if(d){const k=a.byId(g.source),y=a.byId(g.target);m=!k.unscheduled&&!y.unscheduled}m&&l.push(g)}}),a.serialize().forEach(g=>{(!d||!g.unscheduled)&&h.push({...g})}),u.parse(h,l,{start:r,end:i});const f=La(u,t,n.start,n.duration,c),p=this.getHistory();p&&p.startBatch(),f.updates.forEach(g=>{if(g.id===t)return;const m={start:g.start,duration:g.duration};g.type!=="milestone"&&(m.end=g.end),this.in.exec("update-task",{id:g.id,task:m,eventSource:"schedule-tasks"})}),p&&p.endBatch()})}setupTaskHandlers(){this.intercept("update-task",t=>{if(t.eventSource=="undo"||t.eventSource=="redo"||t.skipUndo||!this.shouldTrack(t,st))return;const n=this.getState().tasks.byId(t.id);n&&this.taskTracker.track(t.id,n,["start","end","duration","type"])}),this.on("update-task",t=>{if(t.eventSource=="undo"||t.eventSource=="redo"||t.skipUndo||!this.shouldTrack(t,st))return;const{id:n,task:s}=t;this.taskTracker.hasChanged(n,s,["start","end","duration"])&&this.debounce(()=>this.schedule())}),this.in.on("move-task",({inProgress:t})=>{t!==!0&&this.schedule(0,!0)}),this.on("copy-task",t=>{this.shouldTrack(t,st)&&this.schedule()}),this.on("add-task",t=>{this.shouldTrack(t,st)&&this.getState().tasks.getSummaryId(t.id)&&this.schedule()}),this.on("provide-data",()=>{this.schedule(0,!0)})}setupLinkHandlers(){this.intercept("update-link",t=>{const{links:n}=this.getState(),s=n.byId(t.id);s&&this.linkTracker.track(t.id,s,["type","source","target","lag"])}),this.on("update-link",t=>{if(this.linkTracker.hasChanged(t.id,t.link,["type","source","target","lag"])){const n=this.linkTracker.getSnapshot(t.id);(t.link.type==="e2s"||n?.type==="e2s")&&this.schedule()}}),this.intercept("delete-link",t=>{const{links:n}=this.getState(),s=n.byId(t.id);s&&this.linkTracker.track(t.id,s,["type"])}),this.on("delete-link",t=>{this.linkTracker.getSnapshot(t.id)?.type==="e2s"&&t.eventSource!=="schedule-tasks"&&this.schedule(),this.linkTracker.clear(t.id)}),this.in.intercept("add-link",t=>{const{links:n}=this.getState();if(this.getInvalidLinks([...n.map(s=>s),t.link]).size)return!1}),this.on("add-link",t=>{this.shouldTrack(t,st)&&t.link.type==="e2s"&&this.schedule()})}deleteInvalidLinks(){const{links:t}=this.getState(),n=this.getInvalidLinks(t.map(s=>s));for(const s of n)this.in.exec("delete-link",{id:s,eventSource:"schedule-tasks"})}getInvalidLinks(t){const{tasks:n}=this.getState(),s=new Set;return t.forEach(a=>{const r=n.getSummaryId(a.source,!0),i=n.getSummaryId(a.target,!0);(r?.includes(a.target)||i?.includes(a.source))&&s.add(a.id)}),new Set([...s,...Qa(t)])}}const Ra={strict:Ke,flexible:Ze},on={"schedule-tasks":1,"update-task":1,"move-task":1};class Ja extends Yt{taskTracker=new mt;linkTracker=new mt;init(){this.setupTaskHandlers(),this.setupLinkHandlers()}destroy(){this.taskTracker.clear(),this.linkTracker.clear(),this.detachHandlers();const{links:t,tasks:n}=this.getState();t.forEach(s=>{delete s.$critical}),n.forEach(s=>{delete s.$critical}),this.setState({tasks:n,links:t})}calculate(){const{tasks:t,links:n,criticalPath:s,projectStart:a,projectEnd:r,calendar:i,unscheduledTasks:o}=this.getState(),d=[],c=[],u=[];n.forEach(g=>{if(g.type==="e2s"){let m=!0;[g.source,g.target].forEach(k=>{if(m){const{type:y,unscheduled:b}=t.byId(k);m=y!=="summary"&&(!o||!b)}}),m&&d.push({...g})}}),t.serialize().forEach(g=>{g.type!=="summary"&&(!o||!g.unscheduled)?c.push({...g}):u.push(g.id)});const l=new Ve(c,d,{start:a,end:r}),h={calendar:i},f=Na(l,Ra[s.type],h),p={};f.forEach(g=>p[g]=!0),u.reverse().forEach(g=>{const m=t.byId(g)?.data||[];m.length&&m.some(k=>p[k.id])&&(p[g]=!0)}),n.forEach(g=>{const m=p[g.source],k=p[g.target];m&&k?g.$critical=!0:delete g.$critical}),t.forEach(g=>{p[g.id]?g.$critical=!0:delete g.$critical}),this.setState({tasks:t,links:n})}getDefaultTag(){return"path"}setupTaskHandlers(){this.intercept("update-task",t=>{if(!this.shouldTrack(t,on))return;const n=this.getState().tasks.byId(t.id);n&&this.taskTracker.track(t.id,n,["start","end","duration","type","unscheduled"])}),this.on("update-task",t=>{this.shouldTrack(t,on)&&this.taskTracker.hasChanged(t.id,t.task,["start","end","duration","type","unscheduled"])&&this.debounce(()=>this.calculate())}),this.on("add-task",t=>{t.task.unscheduled||this.debounce(()=>this.calculate())}),this.on("delete-task",()=>{this.debounce(()=>this.calculate())}),this.on("move-task",t=>{t.inProgress!==!0&&this.debounce(()=>this.calculate())})}setupLinkHandlers(){this.on("add-link",t=>{t.link.type==="e2s"&&this.calculate()}),this.intercept("update-link",t=>{const{links:n}=this.getState(),s=n.byId(t.id);s&&this.linkTracker.track(t.id,s,["type","source","target","lag"])}),this.on("update-link",t=>{if(this.linkTracker.hasChanged(t.id,t.link,["type","source","target","lag"])){const n=this.linkTracker.getSnapshot(t.id);(t.link.type==="e2s"||n?.type==="e2s")&&this.calculate()}}),this.intercept("delete-link",t=>{const{links:n}=this.getState(),s=n.byId(t.id);s&&this.linkTracker.track(t.id,s,["type"])}),this.on("delete-link",t=>{this.linkTracker.getSnapshot(t.id)?.type==="e2s"&&this.calculate(),this.linkTracker.clear(t.id)})}}class Va extends fn{in;_router;_modules=new Map;constructor(t){super({writable:t,async:!1}),this._router=new gn(super.setState.bind(this),[{in:["tasks","start","end","scales","autoScale"],out:["_start","_end"],exec:a=>{const{_end:r,_start:i,start:o,end:d,tasks:c,scales:u,autoScale:l}=this.getState();if(!o||!d||l){const h=L(u).unit,f=ra(o,d,l,h,c);(f._end!=r||f._start!=i)&&this.setState(f,a)}else this.setState({_start:o,_end:d},a)}},{in:["_start","_end","cellWidth","scaleHeight","scales","lengthUnit","_weekStart"],out:["_scales"],exec:a=>{const r=this.getState();let{lengthUnit:i}=r;const{_start:o,_end:d,cellWidth:c,scaleHeight:u,scales:l,_weekStart:h}=r,f=L(l).unit;ta(f,i)||(i=f);const p=ia(o,d,i,c,u,h,l);this.setState({_scales:p},a)}},{in:["_scales","tasks","cellHeight","baselines","unscheduledTasks"],out:["_tasks"],exec:a=>{const{cellWidth:r,cellHeight:i,tasks:o,_scales:d,baselines:c,splitTasks:u,unscheduledTasks:l}=this.getState(),h=o.toArray().map((f,p)=>Pe(f,p,{cellWidth:r,cellHeight:i,_scales:d,baselines:c,splitTasks:u,unscheduledTasks:l}));this.setState({_tasks:h},a)}},{in:["_tasks","links","cellHeight"],out:["_links"],exec:a=>{const{tasks:r,links:i,cellHeight:o,baselines:d,criticalPath:c}=this.getState(),u=i.map(l=>{const h=r.byId(l.source),f=r.byId(l.target);return ga(l,h,f,o,d)}).toSorted((l,h)=>c?!!l.$critical==!!h.$critical?h.$pl-l.$pl:l.$critical?1:-1:h.$pl-l.$pl).filter(l=>l!==null);this.setState({_links:u},a)}},{in:["tasks","activeTask"],out:["_activeTask"],exec:a=>{const r=this.getState();let{activeTask:i}=r;i&&typeof i=="object"&&(i=i.id);const o=r.tasks.byId(i);this.setState({_activeTask:o||null},a)}},{in:["tasks","selected"],out:["_selected"],exec:a=>{const{tasks:r,selected:i}=this.getState(),o=i.map(d=>r.byId(d)).filter(d=>!!d);this.setState({_selected:o},a)}},{in:["start","end"],out:["cellWidth"],exec:a=>{const{_cellWidth:r,cellWidth:i}=this.getState();r!=i&&this.setState({cellWidth:r},a)}},{in:["markers","_scales","cellWidth"],out:["_markers"],exec:a=>{const{markers:r,_scales:i,cellWidth:o}=this.getState(),{start:d,diff:c}=i,u=r.map(l=>(l.left=c(l.start,d)*o,l));this.setState({_markers:u},a)}},{in:["unscheduledTasks"],out:["columns"],exec:a=>{const{columns:r,unscheduledTasks:i}=this.getState(),o=r.map(d=>(d._template&&(d.id=="start"||d.id=="end"||d.id=="duration")&&(d={...d,template:(c,u,l)=>u.unscheduled&&i?"-":l._template(c,u,l)}),d));this.setState({columns:o},a)}}],{tasks:a=>new xn(a),links:a=>new Zt(a),columns:a=>xa(a)});const n=this.in=new pn;n.on("show-editor",a=>{const{splitTasks:r}=this.getState();if(r){const{id:i,segmentIndex:o}=a;if(i&&(o||o===0)){this.setStateAsync({activeTask:{id:i,segmentIndex:o}});return}}this.setStateAsync({activeTask:a.id})}),n.on("select-task",({id:a,toggle:r,range:i,show:o,segmentIndex:d})=>{const{selected:c,_tasks:u,activeTask:l,splitTasks:h}=this.getState();let f=!1,p;if(c.length&&(r||i)){const m=[...c];if(i){const k=m[m.length-1],y=u.findIndex(v=>v.id==k),b=u.findIndex(v=>v.id==a),_=Math.min(y,b),x=Math.max(y,b)+1,S=u.slice(_,x).map(v=>v.id);y>b&&S.reverse(),S.forEach(v=>{m.includes(v)||m.push(v)})}else if(r){const k=m.findIndex(y=>y==a);k===-1?m.push(a):(f=!0,m.splice(k,1))}p=m}else p=[a];const g={selected:p};o&&p.length&&(g._scrollTask={id:p[0],mode:o}),this.setStateAsync(g),!f&&l&&(l!==a||h)&&n.exec("show-editor",{id:a,...h&&{segmentIndex:d}})}),n.on("delete-link",({id:a})=>{const{links:r}=this.getState();r.remove(a),this.setStateAsync({links:r})}),n.on("update-link",a=>{const{links:r}=this.getState(),i=a.id;let o=a.link;r.update(i,o),o=r.byId(i),!o.lag&&o.lag!==0&&delete o.lag,this.setStateAsync({links:r}),a.link=o}),n.on("add-link",a=>{const{link:r}=a,{links:i}=this.getState();!r.source||!r.target||(r.type||(r.type="e2s"),r.id=r.id||bt(),i.add(r),this.setStateAsync({links:i}),a.id=r.id,a.link=i.byId(r.id))});let s=null;n.on("move-task",a=>{const{tasks:r}=this.getState();let{mode:i,target:o}=a;const{id:d,inProgress:c}=a,u=r.byId(d);if(typeof c>"u"?a.source=u.parent:a.source=s=s??u.parent,c===!1){r.update(u.id,{$reorder:!1}),this.setState({tasks:r}),s=null;return}if(o===d||r.contains(d,o)){a.skipProvider=!0;return}if(i==="up"||i==="down"){const l=r.getBranch(d);let h=r.getIndexById(d);if(i==="up"){const f=u.parent===0;if(h===0&&f){a.skipProvider=!0;return}h-=1,i="before"}else if(i==="down"){const f=h===l.length-1,p=u.parent===0;if(f&&p){a.skipProvider=!0;return}h+=1,i="after"}if(o=l[h]&&l[h].id||u.parent,o){const f=r.getBranch(o);let p=r.getIndexById(o),g=f[p];if(g.data){if(i==="before"){if(g.parent===u.parent){for(;g.data;)g.open||n.exec("open-task",{id:g.id,mode:!0}),g=g.data[g.data.length-1];o=g.id}}else if(i==="after"){let y;g.parent===u.parent?(y=g,g=g.data[0],o=g.id,i="before"):f.length-1!==p&&(y=g,p+=1,g=f[p],u.$level>g.$level&&g.data?(y=g,g=g.data[0],o=g.id,i="before"):o=g.id),y&&!y.open&&n.exec("open-task",{id:y.id,mode:!0})}}const m=r.getSummaryId(u.id);r.move(d,i,o);const k=r.getSummaryId(d);m!=k&&(m&&this.resetSummaryDates(m,"move-task"),k&&this.resetSummaryDates(k,"move-task"))}}else{const l=r.byId(o);let h=l,f=!1;for(;h.$level>u.$level;)h=r.byId(h.parent),h.id===d&&(f=!0);if(f)return;const p=r.getSummaryId(u.id);if(r.move(d,i,o),i=="child"){let m=l;for(;m.id!==0&&!m.open;)n.exec("open-task",{id:m.id,mode:!0}),m=r.byId(m.parent)}const g=r.getSummaryId(d);p!=g&&(p&&this.resetSummaryDates(p,"move-task"),g&&this.resetSummaryDates(g,"move-task"))}c?this.setState({tasks:r}):this.setStateAsync({tasks:r}),a.target=o,a.mode=i}),n.on("drag-task",a=>{const r=this.getState(),{tasks:i,_tasks:o,_selected:d,_scales:c,cellWidth:u}=r,l=i.byId(a.id);if(a.segmentIndex>=0&&r.splitTasks&&Ma(l,a)===!1){this.setState({_tasks:o});return}const{left:h,top:f,width:p,inProgress:g}=a,m={_tasks:o,_selected:d};if(typeof p<"u"&&(l.$w=p,Ot(i,l,c,u)),typeof h<"u"){if(l.type==="summary"){const k=h-l.$x;We(l,k,c,u)}l.$x=h,Ot(i,l,c,u)}typeof f<"u"&&(l.$y=f+4,l.$reorder=g),typeof p<"u"&&(l.$w=p),typeof h<"u"&&(l.$x=h),typeof f<"u"&&(l.$y=f+4,l.$reorder=g),this.setState(m)}),n.on("update-task",a=>{const{id:r,segmentIndex:i,diff:o,eventSource:d}=a;let{task:c}=a;const{tasks:u,_scales:l,durationUnit:h,splitTasks:f,calendar:p}=this.getState(),g=u.byId(r),m={_scales:l,durationUnit:h,calendar:p,splitTasks:f};if(d==="add-task"||d==="copy-task"||d==="move-task"||d==="update-task"||d==="delete-task"||d==="provide-data"){f&&g.segments&&(c=qe(g,c,m)),z(c,m),u.update(r,c);return}const k=l.lengthUnit;let y=T(k);const b=E(k,p);if(o&&(c.start&&(c.start=y(c.start,o)),!i&&i!==0&&(c.start&&c.end?c.duration=g.duration:(c.start?c.end=g.end:(c.end=y(c.end,o),c.start=g.start,c.duration=b(c.end,c.start)),b(c.end,c.start)||(c.duration=1)))),f&&g.segments&&(o&&i>=0&&c.end&&(c.end=y(c.end,o)),c=qe(g,c,m,i,o)),c.type=c.type??g.type,p&&c.start&&(c.start=Wt(c.start,o,p)),c.start&&c.end&&(!H(c.start,g.start)||!H(c.end,g.end))&&c.type==="summary"&&g.data?.length){let x=o||b(c.start,g.start);p&&(x=c.start>g.start?b(c.start,g.start):-b(g.start,c.start),y=lt(p)),this.moveSummaryKids(g,S=>(S=y(S,x),p?Wt(S,o,p):S),"update-task")}c.start||(c.start=g.start),!c.end&&!c.duration&&(c.duration=g.duration),z(c,m),u.update(r,c),(p&&c.type==="summary"||c.type==="summary"&&g.type!=="summary")&&this.resetSummaryDates(r,"update-task",!0);const _=u.getSummaryId(r);_&&this.resetSummaryDates(_,"update-task"),this.setStateAsync({tasks:u}),a.task=u.byId(r)}),n.on("add-task",a=>{const{tasks:r,_scales:i,unscheduledTasks:o,durationUnit:d,splitTasks:c,calendar:u}=this.getState(),{target:l,mode:h,task:f,show:p,select:g=!0}=a;!a.eventSource&&o&&(f.unscheduled=!0);let m=-1,k,y;if(l?(y=r.byId(l),h=="child"?(k=y,f.parent=k.id):(y.parent!==null&&(k=r.byId(y.parent),f.parent=k.id),m=r.getIndexById(l),h=="after"&&(m+=1))):f.parent&&(k=r.byId(f.parent)),!f.start){if(k?.start)f.start=new Date(k.start.valueOf());else if(y)f.start=new Date(y.start.valueOf());else{const S=r.getBranch(0);let v;if(S?.length){const M=S[S.length-1];if(!M.$skip){const F=new Date(M.start.valueOf());i.start<=F&&(v=F)}}f.start=v||T(d,u)(i.start,1)}f.duration=1}u&&(f.start=Wt(f.start,1,u)),this.getState().baselines&&(f.base_start=f.start,f.base_duration=f.duration),z(f,{durationUnit:d,splitTasks:c,calendar:u});const b=r.add(f,m),_={tasks:r};if(k&&p){for(;k&&k.id;)n.exec("open-task",{id:k.id,mode:!0}),k=r.byId(k.parent);_._scrollTask={id:b.id,mode:p}}a.id=b.id;const x=r.getSummaryId(b.id);x&&this.resetSummaryDates(x,"add-task"),this.setStateAsync(_),a.id=b.id,a.task=b,g&&n.exec("select-task",{id:b.id})}),n.on("delete-task",a=>{const{id:r}=a,{tasks:i,links:o,selected:d}=this.getState();a.source=i.byId(r).parent;const c=i.getSummaryId(r),u=[r];i.eachChild(h=>u.push(h.id),r),o.filter(h=>!(u.includes(h.source)||u.includes(h.target)));const l={tasks:i,links:o};d.includes(r)&&(l.selected=d.filter(h=>h!==r)),i.remove(r),c&&this.resetSummaryDates(c,"delete-task"),this.setStateAsync(l)}),n.on("indent-task",({id:a,mode:r})=>{const{tasks:i}=this.getState();if(r){const o=i.getBranch(a)[i.getIndexById(a)-1];o&&n.exec("move-task",{id:a,mode:"child",target:o.id})}else{const o=i.byId(a),d=i.byId(o.parent);d&&d.parent!==null&&n.exec("move-task",{id:a,mode:"after",target:o.parent})}}),n.on("copy-task",a=>{const{id:r,target:i,mode:o,eventSource:d}=a;if(d==="copy-task")return;const{tasks:c,links:u}=this.getState();if(c.contains(r,i)){a.skipProvider=!0;return}const l=c.getSummaryId(r),h=c.getSummaryId(i);let f=c.getIndexById(i);o=="before"&&(f-=1);const p=c.byId(r),g=c.copy(p,c.byId(i).parent,f+1);a.source=a.id,a.id=g[0][1],p.lazy&&(a.lazy=!0),l!=h&&h&&this.resetSummaryDates(h,"copy-task");let m=[];for(let k=1;k<g.length;k++){const[y,b]=g[k];u.forEach(_=>{if(_.source===y){const x={..._};delete x.target,m.push({...x,source:b})}else if(_.target===y){const x={..._};delete x.source,m.push({...x,target:b})}})}m=m.reduce((k,y)=>{const b=k.findIndex(_=>_.id===y.id);return b>-1?k[b]={...k[b],...y}:k.push(y),k},[]);for(let k=1;k<g.length;k++){const[y,b]=g[k],_=c.byId(b);n.exec("copy-task",{source:y,id:b,lazy:!!_.lazy,eventSource:"copy-task",target:_.parent,mode:"child",skipUndo:!0})}m.forEach(k=>{n.exec("add-link",{link:{source:k.source,target:k.target,type:k.type},eventSource:"copy-task",skipUndo:!0})}),this.setStateAsync({tasks:c})}),n.on("open-task",({id:a,mode:r})=>{const{tasks:i}=this.getState(),o=i.byId(a);o.lazy?n.exec("request-data",{id:o.id}):(i.toArray().forEach(d=>d.$y=0),i.update(a,{open:r}),this.setState({tasks:i}))}),n.on("scroll-chart",({left:a,top:r})=>{if(!isNaN(a)){const i=this.calcScaleDate(a);this.setState({scrollLeft:a,_scaleDate:i})}isNaN(r)||this.setState({scrollTop:r})}),n.on("render-data",a=>{this.setState({area:a})}),n.on("provide-data",a=>{const{tasks:r,links:i,durationUnit:o,calendar:d,splitTasks:c}=this.getState(),u=r.byId(a.id);u.lazy?(u.lazy=!1,u.open=!0):u.data=[],Ye(a.data.tasks,{durationUnit:o,splitTasks:c,calendar:d}),r.parse(a.data.tasks,a.id),u.type=="summary"&&this.resetSummaryDates(u.id,"provide-data"),this.setStateAsync({tasks:r,links:new Zt(i.map(l=>l).concat(Oe(a.data.links)))})}),n.on("zoom-scale",({dir:a,offset:r})=>{const{zoom:i,cellWidth:o,_cellWidth:d,scrollLeft:c}=this.getState(),u=r+c,l=this.calcScaleDate(u);let h=o;a<0&&(h=d||o);const f=h+a*50,p=i.levels[i.level],g=a<0&&o>p.maxCellWidth;if(f<p.minCellWidth||f>p.maxCellWidth||g){if(!this.changeScale(i,a))return}else this.setState({cellWidth:f,_cellWidth:f});const{_scales:m,_start:k,cellWidth:y,_weekStart:b}=this.getState(),_=I(m.minUnit,k,b),x=m.diff(l,_,"hour");typeof r>"u"&&(r=y);let S=Math.round(x*y)-r;S<0&&(S=0),this.setState({scrollLeft:S,_scaleDate:l,_zoomOffset:r})}),n.on("expand-scale",({minWidth:a})=>{const{_start:r,_scales:i,start:o,end:d,_end:c,cellWidth:u,_scaleDate:l,_zoomOffset:h}=this.getState(),f=T(i.minUnit);let p=i.width;if(o&&d){if(p<a&&p){const b=a/p;this.setState({cellWidth:u*b})}return!0}let g=0;for(;p<a;)p+=u,g++;const m=g?d?-g:-1:0,k=o||f(r,m);let y=0;if(l){const b=i.diff(l,k,"hour");y=Math.max(0,Math.round(b*u)-(h||0))}this.setState({_start:k,_end:d||f(c,g),scrollLeft:y})}),n.on("sort-tasks",({key:a,order:r,add:i})=>{const o=this.getState(),{tasks:d}=o;let c=o._sort;const u={key:a,order:r};let l=c?.length||0;l&&i?(c.forEach((h,f)=>{h.key===a&&(l=f)}),c[l]=u):c=[u],d.sort(c),this.setState({_sort:c,tasks:d})}),n.on("hotkey",({key:a,event:r,eventSource:i})=>{switch(a){case"arrowup":case"arrowdown":{const{selected:o,_tasks:d}=this.getState();r.preventDefault();const c=o.length;let u;if(a==="arrowup"?u=c?this.getPrevRow(o[c-1])?.id:d[d.length-1]?.id:u=c?this.getNextRow(o[c-1])?.id:d[0]?.id,u){const l=i==="chart"?"xy":!0;this.in.exec("select-task",{id:u,show:l})}break}case"ctrl+c":{tt(this,"copy-task",null,null);break}case"ctrl+x":{tt(this,"cut-task",null,null);break}case"ctrl+v":{tt(this,"paste-task",null,null);break}case"ctrl+d":case"backspace":{r.preventDefault(),tt(this,"delete-task",null,null);break}case"ctrl+z":{this.in.exec("undo",{});break}case"ctrl+y":{this.in.exec("redo",{});break}}}),n.on("undo",()=>{this.getHistory()?.handleUndo()}),n.on("redo",()=>{this.getHistory()?.handleRedo()}),n.on("split-task",({id:a,segmentIndex:r})=>{const i=this.getState(),{tasks:o,_scales:d,durationUnit:c,splitTasks:u,calendar:l}=i;if(!u)return;const h=o.byId(a);if(Ut(h))return;const f=$a(h,r,{_scales:d,durationUnit:c,calendar:l,splitTasks:u});f&&n.exec("update-task",{id:a,task:f,eventSource:"split-task"})})}init(t){const n=this.getState().area?{}:{scrollLeft:0,scrollTop:0,area:{from:0,start:0,end:0}};t.cellWidth&&(t._cellWidth=t.cellWidth),t._sort=null,Pt()&&(t.unscheduledTasks=!1,t.baselines=!1,t.markers=[],t.undo=!1,t.schedule={},t.criticalPath=null,t.splitTasks=!1),Array.isArray(t.tasks)&&this.getHistory()?.resetHistory(),this._router.init({_scrollTask:null,selected:[],markers:[],autoScale:!0,durationUnit:"day",...n,...t}),t.schedule?.auto?this.enableModule("autoScheduler",Ga).schedule(0,!0):this.disableModule("autoScheduler"),t.criticalPath?this.enableModule("criticalPath",Ja).calculate():this.disableModule("criticalPath"),t.undo?this.enableModule("historyManager",Wa):this.disableModule("historyManager")}enableModule(t,n){if(!this._modules.has(t)){const s=new n(this.in,this.getState.bind(this),this.setState.bind(this),this.getHistory.bind(this));return s.init(),this._modules.set(t,s),s}return this._modules.get(t)}disableModule(t){const n=this._modules.get(t);n&&(n.destroy(),this._modules.delete(t))}setState(t,n){return this._router.setState(t,n)}setStateAsync(t){this._router.setStateAsync(t)}getTask(t){const{tasks:n}=this.getState();return n.byId(t)}getHistory(){return this.getState().undo?this._modules.get("historyManager"):null}serialize(){const{tasks:t}=this.getState();return t.serialize()}changeScale(t,n){const s=t.level+n,a=t.levels[s];if(a){const{cellWidth:r,scales:i,_scales:o}=this.getState(),d=da(t,n,s,a,o.lengthUnit,i,r);return d._cellWidth=d.cellWidth,this.setState(d),!0}return!1}isScheduled(t){return this.getState().unscheduledTasks?t.some(n=>!n.unscheduled||n.data&&this.isScheduled(n.data)):!0}resetSummaryDates(t,n,s){const{tasks:a,durationUnit:r,splitTasks:i,calendar:o}=this.getState(),d=a.byId(t),c=d.data;if(c?.length&&this.isScheduled(c)){const u=Nt({...d,start:void 0,end:void 0,duration:void 0});if(!H(d.start,u.start)||!H(d.end,u.end)){s?(z(u,{durationUnit:r,splitTasks:i,calendar:o}),a.update(t,u)):this.in.exec("update-task",{id:t,task:u,eventSource:n,skipUndo:!0});const l=a.getSummaryId(t);l&&this.resetSummaryDates(l,n)}}}moveSummaryKids(t,n,s){const{tasks:a}=this.getState();t.data.forEach(r=>{const i={...a.byId(r.id),start:n(r.start)};delete i.end,delete i.id,this.in.exec("update-task",{id:r.id,task:i,eventSource:s,skipUndo:!0}),r.data?.length&&this.moveSummaryKids(r,n,s)})}calcScaleDate(t){const{_scales:n,_start:s,_weekStart:a}=this.getState(),r=n.lengthUnit==="day"?n.lengthUnitWidth/24:n.lengthUnitWidth;return T("hour")(I(n.minUnit,s,a),Math.floor(t/r))}getNextRow(t){const n=this.getState()._tasks,s=n.findIndex(a=>a.id==t);return n[s+1]}getPrevRow(t){const n=this.getState()._tasks,s=n.findIndex(a=>a.id==t);return n[s-1]}}function Ka(e,t,n,s){if(typeof document>"u")return"";const a=document.createElement("canvas");{const r=Za(a,e,t,1,n);tr(r,s,0,e,0,t)}return a.toDataURL()}function Za(e,t,n,s,a){e.setAttribute("width",(t*s).toString()),e.setAttribute("height",(n*s).toString());const r=e.getContext("2d");return r.translate(-.5,-.5),r.strokeStyle=a,r}function tr(e,t,n,s,a,r){e.beginPath(),e.moveTo(s,a),e.lineTo(s,r),t==="full"&&e.lineTo(n,r),e.stroke()}function er(e){let t=[...Gt];return e?.splitTasks&&(t.splice(4,0,{id:"split-task",text:"Split",icon:"wxi-arrow-split"}),t.splice(4,0,{id:"edit",text:"Edit",icon:"wxi-edit",data:[{id:"edit-task:task",text:"Task",isHidden:(n,s,a)=>!Q(a)},{id:"edit-task:segment",text:"Segment",isHidden:(n,s,a)=>!Q(a)}]}),t.push({id:"delete",icon:"wxi-delete",text:"Delete",data:[{id:"delete-task:task",text:"Task",isHidden:(n,s,a)=>!Qt(s)||!Q(a)},{id:"delete-task:segment",text:"Segment",isHidden:(n,s,a)=>!Qt(s)||!Q(a)}]})),t.length>Gt.length&&(t=at(t)),t}function at(e){return e.map(t=>{switch(t.data&&at(t.data),t.id){case"add-task:before":case"move-task:up":t.isDisabled=(n,s)=>sr(n,s);break;case"move-task:down":t.isDisabled=(n,s)=>ar(n,s);break;case"indent-task:add":t.isDisabled=(n,s)=>rr(n,s)===n.parent;break;case"indent-task:remove":t.isDisabled=n=>nr(n);break;case"undo":t.isDisabled=n=>!n.undo;break;case"redo":t.isDisabled=n=>!n.redo;break;case"split-task":t.isDisabled=(n,s,a)=>{let r;return typeof a=="object"&&(r=a.segmentIndex),Ha(n,s,r)};break}return t})}function nr(e){return e.parent===0}function sr(e,t){const{_tasks:n}=t;return n[0]?.id===e.id}function ar(e,t){const{_tasks:n}=t;return n[n.length-1]?.id===e.id}function rr(e,t){const{_tasks:n}=t,s=n.findIndex(a=>a.id===e.id);return n[s-1]?.id??e.parent}function Q(e){return e&&typeof e=="object"}function Qt(e){return!e.selected||e.selected.length<2}const ir=e=>t=>t.type===e,Gt=at([{id:"add-task",text:"Add",icon:"wxi-plus",data:[{id:"add-task:child",text:"Child task"},{id:"add-task:before",text:"Task above"},{id:"add-task:after",text:"Task below"}]},{type:"separator"},{id:"convert-task",text:"Convert to",icon:"wxi-swap-horizontal",dataFactory:e=>({id:`convert-task:${e.id}`,text:`${e.label}`,isDisabled:ir(e.id)})},{id:"edit-task",text:"Edit",icon:"wxi-edit",isHidden:(e,t,n)=>Q(n)},{type:"separator"},{id:"cut-task",text:"Cut",icon:"wxi-content-cut",subtext:"Ctrl+X"},{id:"copy-task",text:"Copy",icon:"wxi-content-copy",subtext:"Ctrl+C"},{id:"paste-task",text:"Paste",icon:"wxi-content-paste",subtext:"Ctrl+V"},{id:"move-task",text:"Move",icon:"wxi-swap-vertical",data:[{id:"move-task:up",text:"Up"},{id:"move-task:down",text:"Down"}]},{type:"separator"},{id:"indent-task:add",text:"Indent",icon:"wxi-indent"},{id:"indent-task:remove",text:"Outdent",icon:"wxi-unindent"},{type:"separator"},{id:"delete-task",icon:"wxi-delete",text:"Delete",subtext:"Ctrl+D / BS",isHidden:(e,t,n)=>Qt(t)&&Q(n)}]);function or(e){let t=[...Rt];return e?.undo&&(t=t.concat([{comp:"separator"},{id:"undo",comp:"icon",icon:"wxi-undo",menuText:"Undo"},{id:"redo",comp:"icon",icon:"wxi-redo",menuText:"Redo"}])),e?.splitTasks&&t.splice(2,0,{id:"split-task",comp:"icon",icon:"wxi-arrow-split",menuText:"Split"}),t.length>Rt.length&&(t=at(t)),t}const Rt=at([{id:"add-task",comp:"button",icon:"wxi-plus",text:"New task",type:"primary"},{id:"edit-task",comp:"icon",icon:"wxi-edit",menuText:"Edit",text:"Ctrl+E"},{id:"delete-task",comp:"icon",icon:"wxi-delete",menuText:"Delete",text:"Ctrl+D, Backspace"},{comp:"separator"},{id:"move-task:up",comp:"icon",icon:"wxi-angle-up",menuText:"Move up"},{id:"move-task:down",comp:"icon",icon:"wxi-angle-down",menuText:"Move down"},{comp:"separator"},{id:"copy-task",comp:"icon",icon:"wxi-content-copy",menuText:"Copy",text:"Ctrl+V"},{id:"cut-task",comp:"icon",icon:"wxi-content-cut",menuText:"Cut",text:"Ctrl+X"},{id:"paste-task",comp:"icon",icon:"wxi-content-paste",menuText:"Paste",text:"Ctrl+V"},{comp:"separator"},{id:"indent-task:add",comp:"icon",icon:"wxi-indent",menuText:"Indent"},{id:"indent-task:remove",comp:"icon",icon:"wxi-unindent",menuText:"Outdent"}]);function kt(e){return e.type==="summary"}function Jt(e){return e.type==="milestone"}function yt(e){return typeof e.parent>"u"}function Vt(e,t){return t.unscheduledTasks&&e.unscheduled}function dr(e){const t=[...dn];return e?.unscheduledTasks&&t.splice(6,0,{key:"unscheduled",comp:"twostate",label:"",config:{value:!0,text:"Unschedule",textActive:"Schedule"},isHidden:n=>kt(n)||yt(n)}),t}const dn=[{key:"text",comp:"text",label:"Name",config:{placeholder:"Add task name"}},{key:"details",comp:"textarea",label:"Description",config:{placeholder:"Add description"}},{key:"type",comp:"select",label:"Type",isHidden:e=>yt(e)},{key:"start",comp:"date",label:"Start date",isHidden:e=>kt(e),isDisabled:Vt},{key:"end",comp:"date",label:"End date",isHidden:e=>kt(e)||Jt(e),isDisabled:Vt},{key:"duration",comp:"counter",label:"Duration",config:{min:1},isHidden:e=>kt(e)||Jt(e),isDisabled:Vt},{key:"progress",comp:"slider",label:"Progress",config:{min:1,max:100},isHidden:e=>Jt(e)||yt(e)},{key:"links",comp:"links",label:"",isHidden:e=>yt(e)}],cr=[{id:"task",label:"Task"},{id:"summary",label:"Summary task"},{id:"milestone",label:"Milestone"}];export{Ya as Calendar,Va as DataStore,Sa as defaultColumns,dn as defaultEditorItems,Gt as defaultMenuOptions,cr as defaultTaskTypes,Rt as defaultToolbarButtons,fa as extendDragOptions,As as format,T as getAdder,E as getDiffer,dr as getEditorItems,er as getMenuOptions,or as getToolbarButtons,I as getUnitStart,Ka as grid,tt as handleAction,Ae as isHandledAction,ha as isSegmentMoveAllowed,Oe as normalizeLinks,oa as normalizeZoom,Ye as parseTaskDates,ya as placeLink,Da as prepareEditTask,aa as registerScaleUnit};