UNPKG

@xpyjs/gantt-core

Version:

A powerful and flexible Gantt chart component library for modern web applications with TypeScript support

18 lines 199 kB
(function(N,A){typeof exports=="object"&&typeof module<"u"?A(exports,require("dayjs"),require("lodash-es"),require("konva")):typeof define=="function"&&define.amd?define(["exports","dayjs","lodash-es","konva"],A):(N=typeof globalThis<"u"?globalThis:N||self,A(N.XGantt={},N.dayjs,N._,N.Konva))})(this,function(N,A,O,k){"use strict";var Ye=Object.defineProperty;var Ue=(N,A,O)=>A in N?Ye(N,A,{enumerable:!0,configurable:!0,writable:!0,value:O}):N[A]=O;var a=(N,A,O)=>Ue(N,typeof A!="symbol"?A+"":A,O);const ft="0.0.1-rc.2";function Ht(){const f="#eca710",t="#ffffff",e="#e7209e",i="#ffffff",s="#1c42e8";[" __ __ _____ _____ _____ _____ _____ ","| | || __|| _ || | ||_ _||_ _|","|- -|| | || || | | | | | | | ","|__|__||_____||__|__||_|___| |_| |_| "].forEach(o=>{console.log(`%c${o}`,`color: ${f}; font-weight: bold; font-family: monospace;`)}),console.log(`%c 🚀 欢迎使用 XGantt %c Version: ${ft} `,`background-color: ${e}; color: ${t}; padding: 2px 4px; border-radius: 6px 0 0 6px; font-weight: bold; margin: 4px 0;`,`background-color: ${s}; color: ${i}; padding: 2px 4px; border-radius: 0 6px 6px 0; font-weight: normal; margin: 4px 0;`)}const P=class P{static setOptions(t){P.options={...P.options,...t}}static getLevel(){return P.options.level}static debug(...t){P.logWithLevel(1,console.debug,...t)}static info(...t){P.logWithLevel(2,console.info,...t)}static warn(...t){P.logWithLevel(3,console.warn,...t)}static error(...t){P.logWithLevel(4,console.error,...t)}static assert(t,...e){if(!t&&P.options.level<=4){const i=P.formatArgs("Assertion failed:",...e);console.error(...i)}}static getMessage(...t){return P.formatArgs(...t).join("")}static exception(...t){return new Error(P.getMessage(...t))}static logWithLevel(t,e,...i){if(P.options.level<=t){const s=P.formatArgs(...i);e(...s)}}static formatArgs(...t){const e=[P.Prefix];return P.options.showTimestamp&&e.unshift(`[${A().format("YYYY-MM-DD HH:mm:ss.SSS")}]`),[e.join(""),...t]}};a(P,"Prefix","[XGantt]"),a(P,"options",{level:2,showTimestamp:!1});let D=P;const nt=()=>({data:[],links:{show:!1,key:"id",data:[],distance:20,dash:[0],width:1,gap:5,arrow:{width:6,height:8},radius:3,create:{enabled:!1,mode:"hover",radius:3,width:2,from:!0,to:!0},move:{enabled:!1},enableCycleDetection:!0},baselines:{data:[],taskKey:"taskId",show:!1,fields:{startTime:"startTime",endTime:"endTime",name:"name",id:"id",target:"target",highlight:"highlight"},mode:"line",position:"bottom",backgroundColor:"#999",opacity:.6,radius:2,label:{show:!1,forceDisplay:!1,color:"#666",fontSize:10,position:"right",fontFamily:"Arial"},compare:{enabled:!1,tolerance:.5,mode:"both",target:"end",delayed:{backgroundColor:"#ff4444",opacity:.8},ahead:{backgroundColor:"#44ff44",opacity:.8},indicator:{show:!0,position:"top",fontFamily:"Arial",fontSize:10,size:6,delayed:{show:!0,color:"#af1b1b",opacity:1},ahead:{show:!0,color:"#1baf1b",opacity:1},ontime:{show:!1,color:"#999",opacity:1}}}},milestone:{show:!1,shape:"diamond",border:{width:1},label:{show:!0,text:"",fontSize:10,fontFamily:"Arial",position:"top-right"}},summary:{show:!1,mode:"expand",move:{enabled:!1}},fields:{id:"id",startTime:"startTime",endTime:"endTime",name:"name",progress:"progress",children:"children",type:"type"},selection:{enabled:!1,includeSelf:!0},expand:{show:!0,enabled:!0},dateFormat:"YYYY-MM-DD HH:mm:ss",locale:"en",unit:"day",table:{width:100,ellipsis:!0,align:"center",headerAlign:"center",emptyText:"-"},chart:{autoCellWidth:!1,cellWidth:"normal"},primaryColor:"#eca710",border:{color:"#e5e5e5"},header:{height:80,color:"#000",fontSize:14,fontWeight:600,fontFamily:"Arial"},row:{height:30,indent:16,hover:{backgroundColor:"#000",opacity:.05},select:{backgroundColor:"#000",opacity:.1}},bar:{height:20,show:!0,move:{byUnit:!1,link:{child:"none",parent:"none"}}},today:{show:!0,type:"line",backgroundColor:"lightblue",opacity:1,width:1},weekend:{show:!0,backgroundColor:"#c9c9c9",opacity:.1},holiday:{opacity:.1}});class Gt{constructor(){a(this,"options",nt())}getOptions(){return this.options}setOptions(t,e={merge:!0}){var i;if(this.options=e.merge?O.merge(nt(),this.options,t):O.merge(nt(),t),(i=t.holiday)!=null&&i.holidays&&t.holiday.holidays.length>0){const s=[];t.holiday.holidays.forEach(n=>{if(O.isArray(n.date)){const o=n.date.map(r=>A(r)).sort((r,h)=>r.diff(h));for(let r=1;r<o.length;r++)if(o[r].diff(o[r-1],"day")>1){s.push({...n,date:o.slice(0,r).map(h=>h.valueOf())}),o.splice(0,r);break}o.length>0&&s.push({...n,date:o.map(r=>r.valueOf())})}else s.push(n)}),this.options.holiday.holidays=s}}update(t){this.setOptions(t)}getRowBackgroundColor(t){var s;let e="";const i=(s=this.options.row)==null?void 0:s.backgroundColor;return O.isString(i)?e=i:O.isArray(i)&&i.length>0?e=i[t.level]:O.isFunction(i)&&(e=i(t.getEmitData())),e}unpackFunc(t,e){return O.isFunction(t)?t(e.getEmitData()):t}}class Rt{constructor(){a(this,"events",new Map)}on(t,e){var i;this.events.has(t)||this.events.set(t,[]),(i=this.events.get(t))==null||i.push(e)}emit(t,...e){var i;this.events.has(t)&&((i=this.events.get(t))==null||i.forEach(s=>s(...e)))}off(t,e){var i;this.events.has(t)&&this.events.set(t,((i=this.events.get(t))==null?void 0:i.filter(s=>s!==e))||[])}offAll(){this.events.clear()}}var v=(f=>(f.LOADED="loaded",f.COLUMN_WIDTH_CHANGE="column-width-change",f.MOVE_GUIDELINE="move-guideline",f.SHOW_GUIDELINE="show-guideline",f.HIDE_GUIDELINE="hide-guideline",f.TOGGLE_COLLAPSE="toggle-collapse",f.SCROLL="scroll",f.CHART_OFFSET_CHANGE="chart_offset_change",f.DATA_UPDATE="data-update",f.VIEW_UPDATE="view-update",f.UPDATE_TABLE_HEADER="update_table_header",f.UPDATE_TABLE_BODY="update_table_body",f.UPDATE_CHART_HEADER="update_chart_header",f.UPDATE_TASK="update_task",f.UPDATE_LINK="update_link",f.CREATE_LINK="create_link",f.TASK_SELECTED="task_selected",f.TASK_UNSELECTED="task_unselected",f.SELECT_LINK="select_link",f.CHECK_TASK="check_task",f.CONTEXT_LINK="context_link",f.ROW_CLICK="row-click",f.ROW_DBL_CLICK="row-dbl-click",f.ROW_CONTEXTMENU="row-contextmenu",f.SLIDER_CLICK="slider-click",f.SLIDER_DBL_CLICK="slider-dbl-click",f.SLIDER_CONTEXTMENU="slider-contextmenu",f.SLIDER_DRAGGING="slider-dragging",f.SLIDER_ENTER="slider-enter",f.SLIDER_HOVER="slider-hover",f.SLIDER_LEAVE="slider-leave",f.SLIDER_BLINK="slider-blink",f.LINK_BLINK="link-blink",f.ROW_HIGHLIGHT="row-highlight",f.ROW_UNHIGHLIGHT="row-unhighlight",f.TASK_DRAG_START="task-drag-start",f.TASK_DRAG_MOVE="task-drag-move",f.TASK_DRAG_END="task-drag-end",f.BASELINE_CLICK="baseline-click",f.BASELINE_CONTEXTMENU="baseline-contextmenu",f.BASELINE_MOUSEENTER="baseline-mouseenter",f.BASELINE_MOUSEMOVE="baseline-mousemove",f.BASELINE_MOUSEOUT="baseline-mouseout",f.ERROR="error",f))(v||{}),X=(f=>(f.INVALID_TYPE="INVALID_TYPE",f.TASK_NOT_FOUND="TASK_NOT_FOUND",f.LINK_NOT_ALLOWED="LINK_NOT_ALLOWED",f.LINK_SAME="LINK_SAME",f.LINK_EXIST="LINK_EXIST",f.LINK_INVALID_ARG="LINK_INVALID_ARG",f.LINK_CYCLE="LINK_CYCLE",f))(X||{});function Q(){return Math.random().toString(36).substring(2,15)}function F(f,t,e){if(!Number.isFinite(f)||!Number.isFinite(t)||!Number.isFinite(e))return Number.isFinite(t)?t:0;const i=Math.min(t,e),s=Math.max(t,e);return Math.min(Math.max(i,f),s)}function tt(f,t){let e=f;return O.isString(e)&&(/%$/.test(e)?e=t*parseFloat(e)/100:e=parseFloat(e)),isNaN(e)?0:e}function ot(f,t){if(t===0)throw new Error("基准值不能为0");if(Math.abs(f)<=t/2)return 0;const e=Math.floor(f/t),i=Math.ceil(f/t),s=e*t,n=i*t,o=Math.abs(f-s),r=Math.abs(f-n);return o<=r?s:n}function et(f,t=4){return typeof f=="number"?[f,f,f,f]:Array.isArray(f)?[f[0]??t,f[1]??t,f[2]??t,f[3]??t]:[t,t,t,t]}function Wt(f,t=100){if(!Number.isFinite(f)||!Number.isFinite(t)||t===0||f<0)return 0;const e=f/Math.abs(t);return Math.min(e,1)}function rt(f,t=2,e=!1){const i=f.toFixed(t);return e?i:i.replace(/\.?0+$/,"")}const at=new Map;function pt(f,t=16,e=16){const i=at.get(f);if(i)return i;const s=new Promise((n,o)=>{let r=f;if(!/viewBox\s*=\s*["'][^"']*["']/.test(r)){const l=r.match(/width\s*=\s*["']([^"']*)["']/),m=r.match(/height\s*=\s*["']([^"']*)["']/),p=l?parseFloat(l[1]):t,u=m?parseFloat(m[1]):e;r=r.replace(/<svg([^>]*)>/,`<svg$1 viewBox="0 0 ${p} ${u}">`)}r=r.replace(/width\s*=\s*["'][^"']*["']/,`width="${t}"`),r=r.replace(/height\s*=\s*["'][^"']*["']/,`height="${e}"`),/width\s*=/.test(r)||(r=r.replace(/<svg/,`<svg width="${t}"`)),/height\s*=/.test(r)||(r=r.replace(/<svg/,`<svg height="${e}"`)),/preserveAspectRatio\s*=/.test(r)||(r=r.replace(/<svg([^>]*)>/,'<svg$1 preserveAspectRatio="xMidYMid meet">'));const c=new Image;c.onload=()=>{URL.revokeObjectURL(c.src),n(c)},c.onerror=l=>{URL.revokeObjectURL(c.src),at.delete(f),o(l)};const g=new Blob([r],{type:"image/svg+xml"}),d=URL.createObjectURL(g);c.src=d});return at.set(f,s),s}class ht{constructor(t,e,i,s,n){a(this,"__key__",Q());a(this,"id");a(this,"name");a(this,"startTime");a(this,"endTime");a(this,"progress");a(this,"type");a(this,"expanded");a(this,"children");a(this,"parent");a(this,"level");a(this,"flatIndex");a(this,"duration",0);a(this,"data");a(this,"fields");this.store=t,this.event=e,this.fields=this.store.getOptionManager().getOptions().fields,this.id=n||i[this.fields.id]||Q(),this.data=i,this.name=i[this.fields.name]||"",this.type=i[this.fields.type]||"task",this.updateMode(),this.progress=i[this.fields.progress],this.expanded=this.store.getOptionManager().getOptions().expand.show?this.store.getOptionManager().getOptions().expand.enabled:!0,this.children=[],this.level=s&&s.level!==void 0?s.level+1:0,this.parent=s,this.flatIndex=0,this.store.updateTime(this.startTime,this.endTime)}getField(t){if(!t||O.isString(t)&&t.trim()==="")return;if(!t.includes("."))return this.data[t];const e=t.split(".");let i=this.data;for(let s=0;s<e.length;s++){const n=e[s];if(i==null||typeof i!="object"||!(n in i))return;i=i[n]}return O.isObject(i)?O.cloneDeep(i):i}updateMode(){let t=!1;return this.data[this.fields.startTime]&&(!this.startTime||!this.startTime.isSame(A(this.data[this.fields.startTime])))&&(this.startTime=A(this.data[this.fields.startTime]),t=!0),this.data[this.fields.endTime]&&(!this.endTime||!this.endTime.isSame(A(this.data[this.fields.endTime])))&&(this.endTime=A(this.data[this.fields.endTime]),t=!0),this.startTime&&this.endTime&&this.duration===0&&(this.duration=this.endTime.diff(this.startTime)),this.isMilestone()&&(!this.endTime||!this.endTime.isSame(this.startTime))&&(this.endTime=this.startTime,t=!0),t}updateData(t){this.data=t;let e=!1;t[this.fields.name]&&this.name!==t[this.fields.name]&&(this.name=t[this.fields.name],e=!0),t[this.fields.type]&&this.type!==t[this.fields.type]&&(this.type=t[this.fields.type],e=!0),e=this.updateMode(),t[this.fields.progress]!==void 0&&(this.progress!==t[this.fields.progress]&&(e=!0),this.progress=F(t[this.fields.progress],0,100)),e&&this.event.emit(v.UPDATE_TASK,this)}updateTime(t,e){var s,n;this.startTime=t,this.endTime=this.isMilestone()?t:e;const i=(n=(s=this.store)==null?void 0:s.getOptionManager().getOptions())==null?void 0:n.dateFormat;this.data[this.fields.startTime||"startTime"]=this.startTime.format(i),this.isMilestone()?this.data[this.fields.endTime||"endTime"]=this.startTime.add(this.duration).format(i):this.data[this.fields.endTime||"endTime"]=this.endTime.format(i),this.event.emit(v.UPDATE_TASK,this)}clone(){return new ht(this.store,this.event,O.cloneDeep(this.data),this.parent,this.id)}getEmitData(){return{data:this.data,$index:this.flatIndex,level:this.level+1}}getAllChildren(){const t=[],e=i=>{i.forEach(s=>{t.push(s),O.isArray(s.children)&&s.children.length>0&&e(s.children)})};return e(this.children),t}isMilestone(){return this.store.getOptionManager().getOptions().milestone.show?this.type==="milestone":!1}isSummary(){return this.store.getOptionManager().getOptions().summary.show?this.type==="summary":!1}}class $t{constructor(t,e,i){a(this,"id");a(this,"taskId");a(this,"startTime");a(this,"endTime");a(this,"name");a(this,"data");a(this,"highlight",!0);a(this,"target",!1);this.store=t,this.event=e;const s=this.store.getOptionManager().getOptions().fields,n=this.store.getOptionManager().getOptions().baselines.fields;this.taskId=i[t.getOptionManager().getOptions().baselines.taskKey],this.id=i[s.id]||i[n.id]||Q(),this.name=i[s.name]||i[n.name]||"",this.highlight=i[n.highlight]!==!1,this.target=i[n.target]===!0;const o=i[s.startTime]||i[n.startTime];o&&(this.startTime=A(o));const r=i[s.endTime]||i[n.endTime];r&&(this.endTime=A(r)),this.data=i}getField(t){return this.data[t]}validate(){return!this.taskId||!this.startTime||!this.endTime?!1:this.startTime.isBefore(this.endTime)}getTimeDiff(){if(!this.validate())return null;const t=this.store.getDataManager().getTaskById(this.taskId);if(!t||!t.startTime||!t.endTime)return null;const e=this.store.getTimeAxis().getCellUnit(),i=this.startTime.diff(t.startTime,e,!0),s=this.endTime.diff(t.endTime,e,!0),n=this.store.getOptionManager().getOptions().baselines.compare.tolerance,o=i<-n?"delayed":i>n?"ahead":"ontime",r=s<-n?"delayed":s>n?"ahead":"ontime",h=this.endTime.diff(this.startTime,e,!0),c=t.endTime.diff(t.startTime,e,!0),g=h>0?(c-h)/h*100:0;return{startDiff:i,endDiff:s,startStatus:o,endStatus:r,progressDiff:g,unit:e}}}class Ft{constructor(t,e){a(this,"rawData",[]);a(this,"tasks",[]);a(this,"taskMap",new Map);a(this,"visibleTasksCache",[]);a(this,"isDirty",!0);a(this,"collapsedTaskIds",new Set);a(this,"selectedTaskId",null);a(this,"checkedList",[]);a(this,"baselines",[]);a(this,"baselineMap",new Map);a(this,"baselineTaskMap",new Map);a(this,"dataLevel",0);this.store=t,this.event=e}setData(t,e=!1){this.rawData=t,this.initTasks(e),this.invalidateCache(),this.event.emit(v.DATA_UPDATE)}initTasks(t=!1){t?(this.dataLevel=0,this.tasks=[],this.taskMap.clear(),this.collapsedTaskIds.clear(),this.rawData.forEach(e=>{this.tasks.push(this.createTask(e))})):this.rawData.length>0?this.updateTask(this.rawData,this.tasks):(this.tasks=[],this.taskMap.clear(),this.collapsedTaskIds.clear())}createTask(t,e){const i=this.store.getOptionManager().getOptions().fields,s=new ht(this.store,this.event,t,e);return Array.isArray(t[i.children])&&(s.children=t[i.children].map(n=>this.createTask(n,s))),this.taskMap.set(s.id,s),this.dataLevel=Math.max(this.dataLevel,s.level),s}updateTask(t,e,i){let s=0;for(;s<t.length;){const n=t[s],o=e[s];if(n&&!o){const r=this.createTask(n,i);e.push(r),this.taskMap.set(r.id,r),this.dataLevel=Math.max(this.dataLevel,r.level)}else!n&&o?(this.taskMap.delete(o.id),e.splice(s,1)):n&&o&&(n[this.store.getOptionManager().getOptions().fields.id]===o.id?(o.updateData(n),this.dataLevel=Math.max(this.dataLevel,o.level)):(this.taskMap.delete(o.id),e[s]=this.createTask(n,o.parent),this.taskMap.set(e[s].id,e[s]),this.dataLevel=Math.max(this.dataLevel,e[s].level)));if(n[this.store.getOptionManager().getOptions().fields.children]){const r=n[this.store.getOptionManager().getOptions().fields.children];if(o&&o.children)this.updateTask(r,o.children,o);else{const h=r.map(c=>this.createTask(c,e[s]));e[s].children=h}}else o&&o.children&&(o.children=[]);s++}e.length>=s&&e.splice(s).forEach(o=>{this.taskMap.delete(o.id)})}getData(){return this.rawData}getTasks(t=!0){return t?this.tasks:Array.from(this.taskMap.values())}getTaskById(t){return this.taskMap.get(t)}expandTask(t,e=!1){const i=this.getTaskById(t);return i?(i.expanded=!i.expanded,i.expanded?this.collapsedTaskIds.delete(i.id):this.collapsedTaskIds.add(i.id),e&&i.children&&i.children.length>0&&i.children.forEach(s=>{this.expandTask(s.id,e)}),this.invalidateCache(),this.event.emit(v.VIEW_UPDATE),!0):!1}getVisibleTasks(){if(!this.isDirty&&this.visibleTasksCache.length>0)return this.visibleTasksCache;const t=[];let e=0;const i=(s,n)=>{this.collapsedTaskIds.has(s.id)&&s.expanded&&(s.expanded=!1),s.flatIndex=e++,t.push(s),s.expanded&&s.children&&s.children.length>0&&s.children.forEach(o=>i(o))};return this.tasks.forEach(s=>i(s)),this.visibleTasksCache=t,this.isDirty=!1,t}isTaskVisible(t){let e=t.parent;for(;e;){if(this.collapsedTaskIds.has(e.id))return!1;e=e.parent}return!0}getVisibleSize(){return this.getVisibleTasks().length}clear(){this.rawData=[],this.tasks=[],this.taskMap.clear(),this.visibleTasksCache=[],this.isDirty=!0,this.collapsedTaskIds.clear(),this.event.emit(v.DATA_UPDATE)}invalidateCache(){this.isDirty=!0}selectTask(t){const e=this.getTaskById(t);return e?(this.selectedTaskId===t||(this.unselectTask(),this.selectedTaskId=t,this.event.emit(v.TASK_SELECTED,e)),!0):!1}unselectTask(){if(this.selectedTaskId){const t=this.selectedTaskId;this.selectedTaskId=null,this.event.emit(v.TASK_UNSELECTED,t)}}isTaskSelected(t){return this.selectedTaskId===t}getSelectedTask(){return this.selectedTaskId?this.getTaskById(this.selectedTaskId):void 0}getCheckedList(){return this.checkedList}updateCheckedList(t,e){const i=this.checkedList.findIndex(s=>s.id===e.id);t?i===-1?this.checkedList.push(e):this.checkedList.splice(i,1,e):i!==-1&&this.checkedList.splice(i,1)}toggleAllChecked(t){t?this.checkedList=this.getVisibleTasks().slice():this.checkedList=[]}isTaskChecked(t){return this.checkedList.findIndex(e=>e.id===t.id)!==-1}updateTaskTime(t,e,i,s,n=[]){let o=e,r=i;const h=this.store.getOptionManager().getOptions().bar.move.link.child,c=this.store.getOptionManager().getOptions().bar.move.link.parent,g=this.store.getTimeAxis().getCellUnit();let d=t.parent;for(;c!=="none"&&d;){if(c==="expand"){let m=d.startTime||o,p=d.endTime||r;(!d.startTime||o.isBefore(d.startTime))&&(m=o),(!d.endTime||r.isAfter(d.endTime))&&(p=r),(d.startTime===void 0||d.endTime===void 0||!m.isSame(d.startTime)||!p.isSame(d.endTime))&&(n.findIndex(u=>u.id===d.id)===-1&&n.push(d.clone()),d.updateTime(m,p))}else c==="strict"&&(d.startTime&&o.isBefore(d.startTime)&&(o=d.startTime,r.isSameOrBefore(o)&&(r=o.add(1,g))),d.endTime&&r.isAfter(d.endTime)&&(r=d.endTime,o.isAfter(r)&&(o=r.subtract(1,g))));d=d.parent}let l=t.children||[];for(;h!=="none"&&l.length>0;){const m=[];l.forEach(p=>{let u=p.startTime||o,y=p.endTime||r,x=o.diff(t.startTime),T=r.diff(t.endTime);h==="scale"?s==="both"?(n.findIndex(b=>b.id===p.id)===-1&&n.push(p.clone()),p.updateTime(u.add(x),y.add(T))):s==="left"?(u=u.add(x),u.isSameOrAfter(y.subtract(1,g))&&(y.isBefore(t.endTime)?y=u.add(1,g):u=y.subtract(1,g),u.isSameOrBefore(o)&&(o=u)),n.findIndex(b=>b.id===p.id)===-1&&n.push(p.clone()),p.updateTime(u,y)):s==="right"&&(y=y.add(T),y.isSameOrBefore(u.add(1,g))&&(u.isAfter(t.startTime)?u=y.subtract(1,g):y=u.add(1,g)),y.isSameOrAfter(r)&&(r=y),n.findIndex(b=>b.id===p.id)===-1&&n.push(p.clone()),p.updateTime(u,y)):h==="fixed"&&(s==="both"?(n.findIndex(b=>b.id===p.id)===-1&&n.push(p.clone()),p.updateTime(u.add(x),y.add(T))):s==="left"?u.isSameOrBefore(o)&&(u=o,u.isSameOrAfter(y.subtract(1,g))&&(y.isBefore(t.endTime)?y=u.add(1,g):u=y.subtract(1,g),u.isSameOrBefore(o)&&(o=u)),n.findIndex(b=>b.id===p.id)===-1&&n.push(p.clone()),p.updateTime(u,y)):s==="right"&&y.isSameOrAfter(r)&&(y=r,y.isSameOrBefore(u.add(1,g))&&(u.isAfter(t.startTime)?u=y.subtract(1,g):y=u.add(1,g)),y.isSameOrAfter(r)&&(r=y),n.findIndex(b=>b.id===p.id)===-1&&n.push(p.clone()),p.updateTime(u,y))),p.children&&p.children.length>0&&m.push(...p.children)}),l=m}n.findIndex(m=>m.id===t.id)===-1&&n.push(t.clone()),t.updateTime(o,r)}setBaselines(t){this.baselines=[],this.baselineMap.clear(),this.baselineTaskMap.clear(),t.forEach(e=>{var s,n;const i=new $t(this.store,this.event,e);this.baselines.push(i),this.baselineMap.set(i.id,i),this.baselineTaskMap.has(i.taskId)||this.baselineTaskMap.set(i.taskId,[]),i.target?(s=this.baselineTaskMap.get(i.taskId))==null||s.unshift(i):(n=this.baselineTaskMap.get(i.taskId))==null||n.push(i)})}getBaselines(){return this.baselines}getBaselineById(t){return this.baselineMap.get(t)}getBaselinesByTaskId(t){return this.baselineTaskMap.get(t)||[]}}function Bt(f){var s;if(typeof f=="object"&&f!==null)return{r:F(f.r??0,0,255),g:F(f.g??0,0,255),b:F(f.b??0,0,255),a:F(f.a??1,0,1)};if(typeof f!="string")return D.warn(`Invalid color value type: ${typeof f}`),null;let t=f.trim();const e=(s=document==null?void 0:document.createElement("canvas"))==null?void 0:s.getContext("2d");if(e&&(e.fillStyle=t,t=e.fillStyle),t.startsWith("#")){const n=t.slice(1);let o,r,h,c,g=1;try{o=parseInt(n,16)}catch{return D.warn(`Invalid hex color: ${f}`),null}if(n.length===3)r=(o>>8&15)*17,h=(o>>4&15)*17,c=(o&15)*17;else if(n.length===6)r=o>>16&255,h=o>>8&255,c=o&255;else if(n.length===8)r=o>>24&255,h=o>>16&255,c=o>>8&255,g=(o&255)/255;else return D.warn(`Invalid hex color length: ${f}`),null;return{r,g:h,b:c,a:g}}let i=t.match(/rgba?\(\s*(\d+%?)\s*,\s*(\d+%?)\s*,\s*(\d+%?)\s*(?:,\s*([\d.]+)\s*)?\)/i);if(i){const n=o=>o.endsWith("%")?F(parseFloat(o)/100*255,0,255):F(parseInt(o,10),0,255);return{r:n(i[1]),g:n(i[2]),b:n(i[3]),a:i[4]!==void 0?F(parseFloat(i[4]),0,1):1}}return D.warn(`Could not parse color: ${f}`),null}function zt(f,t,e,i,s=!1,n=!1){const o=l=>{const m=Math.round(F(l,0,255)).toString(16);return m.length===1?"0"+m:m},r=o(f),h=o(t),c=o(e),g=o(i*255);if(s&&r[0]===r[1]&&h[0]===h[1]&&c[0]===c[1]&&i===1&&!n)return`#${r[0]}${h[0]}${c[0]}`;const d=`#${r}${h}${c}`;return n||i<1?`${d}${g}`:d}class Z{constructor(t){a(this,"_r");a(this,"_g");a(this,"_b");a(this,"_a");const e=Bt(t);e===null?(D.error(`Failed to parse color: ${t}. Using default black.`),this._r=0,this._g=0,this._b=0,this._a=1):(this._r=Math.round(e.r),this._g=Math.round(e.g),this._b=Math.round(e.b),this._a=e.a)}get R(){return this._r}get G(){return this._g}get B(){return this._b}get A(){return this._a}red(t){return t===void 0?this._r:(this._r=Math.round(F(t,0,255)),this)}green(t){return t===void 0?this._g:(this._g=Math.round(F(t,0,255)),this)}blue(t){return t===void 0?this._b:(this._b=Math.round(F(t,0,255)),this)}alpha(t){return t===void 0?this._a:(this._a=F(t,0,1),this)}toHex(t=!1,e=!1){return zt(this._r,this._g,this._b,this._a,t,e)}toRgb(){const t=Math.round(this._r),e=Math.round(this._g),i=Math.round(this._b);if(this._a===1)return`rgb(${t}, ${e}, ${i})`;{const s=parseFloat(this._a.toFixed(2));return`rgba(${t}, ${e}, ${i}, ${s})`}}toObject(){return{r:this._r,g:this._g,b:this._b,a:this._a}}toString(){return this.toRgb()}brighten(t=10){if(t<0)return this.darken(-t);const e=F(t,0,100)/100;return this._r=Math.round(F(this._r+(255-this._r)*e,0,255)),this._g=Math.round(F(this._g+(255-this._g)*e,0,255)),this._b=Math.round(F(this._b+(255-this._b)*e,0,255)),this}darken(t=10){if(t<0)return this.brighten(-t);const e=F(t,0,100)/100;return this._r=Math.round(F(this._r*(1-e),0,255)),this._g=Math.round(F(this._g*(1-e),0,255)),this._b=Math.round(F(this._b*(1-e),0,255)),this}isLight(){return(this._r*299+this._g*587+this._b*114)/1e3>128}isDark(){return!this.isLight()}mix(t,e=50){const i=F(e,0,100)/100,s=z(t);return this._r=Math.round(F(this._r*(1-i)+s.R*i,0,255)),this._g=Math.round(F(this._g*(1-i)+s.G*i,0,255)),this._b=Math.round(F(this._b*(1-i)+s.B*i,0,255)),this._a=F(this._a*(1-i)+s.A*i,0,1),this}clone(){return new Z({r:this._r,g:this._g,b:this._b,a:this._a})}static extend(t,e){typeof t=="function"?t(e,Z,z):D.warn("Invalid plugin provided to Colorjs.extend. Expected a function.")}}const z=f=>f instanceof Z?f:new Z(f);class mt{constructor(t,e,i){a(this,"element");a(this,"iconElement");a(this,"_state",0);a(this,"options");var o;this.context=t,this.container=e,this.task=i;const n=(this.task?this.context.store.getDataManager().isTaskChecked(this.task):!1)?1:0;this.options={initialState:n,size:14},this.element=document.createElement("div"),this.iconElement=document.createElement("div"),this._state=this.options.initialState,this.createElement(),this.updateIcon(),this.bindEvents(),this.registerEvents(),(o=this.container)==null||o.appendChild(this.element)}createElement(){this.element.className="x-gantt-checkbox",this.element.style.width=`${this.options.size}px`,this.element.style.height=`${this.options.size}px`,this.element.style.setProperty("border",`1px solid ${this.context.store.getOptionManager().getOptions().border.color}`,"important"),this.iconElement.className="x-gantt-checkbox__icon",this.iconElement.style.cssText=` display: flex; align-items: center; justify-content: center; width: 100%; height: 100%; color: #ffffff; font-size: ${Math.floor(this.options.size*.75)}px; line-height: 1; `,this.element.appendChild(this.iconElement),this.element.addEventListener("mouseenter",()=>{this._state===0&&this.element.classList.add("hover")}),this.element.addEventListener("mouseleave",()=>{this._state===0&&this.element.classList.remove("hover")})}updateIcon(){const t=this.context.store.getOptionManager().getOptions().primaryColor;this.iconElement.innerHTML="";let e="#ffffff",i=z(t).alpha(.5).toHex();switch(this._state){case 0:e="#ffffff",i=i;break;case 1:e=t,i=t,this.iconElement.innerHTML=` <svg width="12" height="9" viewBox="0 0 12 9" fill="none"> <path d="M10.5 1.5L4.5 7.5L1.5 4.5" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/> </svg> `;break;case 2:e=t,i=t,this.iconElement.innerHTML=` <svg width="8" height="2" viewBox="0 0 8 2" fill="none"> <rect width="8" height="2" fill="currentColor" rx="1"/> </svg> `;break}this.iconElement.style.setProperty("background-color",e,"important"),this.iconElement.style.setProperty("border-color",i,"important")}bindEvents(){this.element.addEventListener("click",t=>{if(t.preventDefault(),t.stopPropagation(),this.task){const e=this.context.store.getDataManager().isTaskChecked(this.task);e?(this.context.store.getDataManager().updateCheckedList(!1,this.task),this.setState(0)):(this.context.store.getDataManager().updateCheckedList(!0,this.task),this.setState(1)),this.context.event.emit(v.CHECK_TASK,[this.task],!e)}else{const e=this.context.store.getDataManager().getCheckedList().length===this.context.store.getDataManager().getVisibleSize();this.setState(e?1:0),this.context.store.getDataManager().toggleAllChecked(!e),this.context.event.emit(v.CHECK_TASK,this.context.store.getDataManager().getVisibleTasks(),!e)}}),this.element.addEventListener("contextmenu",t=>{if(t.preventDefault(),t.stopPropagation(),this.task){const e=this.task.getAllChildren();if(e.length===0)return;this.context.store.getOptionManager().getOptions().selection.includeSelf&&e.unshift(this.task);const i=e.every(s=>this.context.store.getDataManager().isTaskChecked(s));i?(e.forEach(s=>{this.context.store.getDataManager().updateCheckedList(!1,s)}),this.setState(0)):(e.forEach(s=>{this.context.store.getDataManager().updateCheckedList(!0,s)}),this.setState(1)),this.context.event.emit(v.CHECK_TASK,e,!i)}else{const e=this.context.store.getDataManager().getCheckedList().length===this.context.store.getDataManager().getVisibleSize();this.setState(e?1:0),this.context.store.getDataManager().toggleAllChecked(!e),this.context.event.emit(v.CHECK_TASK,this.context.store.getDataManager().getVisibleTasks(),!e)}})}registerEvents(){this.context.event.on(v.CHECK_TASK,this.updateState.bind(this))}getElement(){return this.element}setState(t){this._state!==t&&(this._state=t,this.updateIcon())}updateState(){if(this.task){const t=this.context.store.getDataManager().isTaskChecked(this.task);this.setState(t?1:0)}else{const t=this.context.store.getDataManager().getCheckedList().length===this.context.store.getDataManager().getVisibleSize();this.setState(t?1:0)}}destroy(){this.element&&this.element.parentNode&&this.element.parentNode.removeChild(this.element)}}const xt="handler_column";class Nt{constructor(t){a(this,"sourceColumns",[]);a(this,"columns",[]);a(this,"leafColumns",[]);a(this,"temporaryLeafColumns",[]);a(this,"mergeInfo",new Map);a(this,"collapseTable",!1);this.context=t}init(t){t!=null&&t.length&&(this.sourceColumns=t),this.columns=[],this.leafColumns=[],this.processColumns(this.sourceColumns,this.columns)}processColumns(t,e=[],i,s=1){t.forEach((n,o)=>{var p;const r="children"in n&&Array.isArray(n.children)&&n.children.length>0,h=!r;let c="";r?c=`group-${o}`:c=`field-${n.field}`;const g=[...(i==null?void 0:i.path)||[],c];c="column-"+o+"-"+g.join("-");const d=n.label||(h?n.field:""),l=h?((p=this.temporaryLeafColumns.find(u=>u.key===c))==null?void 0:p.width)||n.width||100:"auto",m={label:d,level:s,maxLevel:s,column:n,children:[],path:g,key:c,isLeaf:h,width:l};if(e.push(m),h)this.leafColumns.push(m);else if(r){const u=n.children;this.processColumns(u,m.children,m,s+1),m.maxLevel=Math.max(m.maxLevel,m.children.reduce((y,x)=>Math.max(y,x.maxLevel),0))}}),this.temporaryLeafColumns=O.cloneDeep(this.leafColumns)}findColumnByKey(t){return this.columns.find(e=>e.key===t)}update(t){this.init(t),this.clearMergeInfo()}getColumns(){return this.columns}getColumn(t){return this.leafColumns.find(e=>e.key===t)}getLeafColumns(){return this.leafColumns}getTotalWidth(){return this.isCollapsed()?0:this.leafColumns.reduce((t,e)=>t+e.width,this.getHandlerColumn().width)}getColumnWidth(t){if(t===xt)return this.getHandlerColumn().width;const e=this.leafColumns.find(i=>i.key===t);return typeof(e==null?void 0:e.width)=="number"?e.width:0}setColumnWidth(t,e){const i=this.leafColumns.find(s=>s.key===t);i&&(i.width=e),this.context.event.emit(v.COLUMN_WIDTH_CHANGE,t,e)}isLastColumn(t){return this.leafColumns.findIndex(i=>i.key===t)===this.leafColumns.length-1}addMergeInfo(t,e,i){this.mergeInfo.has(t)||this.mergeInfo.set(t,new Map),this.mergeInfo.get(t).set(e,i)}getMergeInfo(t,e){var i;return(i=this.mergeInfo.get(t))==null?void 0:i.get(e)}clearMergeInfo(){this.mergeInfo.clear()}getHandlerColumn(){let t=0;return this.context.store.getOptionManager().getOptions().selection.enabled&&(t+=40),this.context.store.getDataManager().dataLevel>0&&this.context.store.getOptionManager().getOptions().expand.show&&(t+=40),{label:"",level:1,maxLevel:1,column:{field:"",resizable:!1,align:"left",headerAlign:"left",customStyle:{paddingLeft:this.context.store.getOptionManager().getOptions().expand.show?"8px":0},headerRender:()=>this.context.store.getOptionManager().getOptions().selection.enabled?new mt(this.context).getElement():null,ellipsis:!1},children:[],path:[],key:xt,isLeaf:!0,width:t}}isMultiHeader(){return this.columns.some(t=>t.maxLevel>1)}collapse(){this.collapseTable=!this.collapseTable,this.context.event.emit(v.TOGGLE_COLLAPSE)}isCollapsed(){return this.collapseTable}}const K=class K{constructor(t,e){a(this,"links",[]);a(this,"fromLinksMap",new Map);a(this,"toLinksMap",new Map);a(this,"topoOrder",null);a(this,"topoIndex",new Map);a(this,"lastCycleReport",null);a(this,"directConnectionCache",new Map);a(this,"forwardMemo",new Map);a(this,"backwardMemo",new Map);a(this,"cacheDependencies",new Map);a(this,"cacheAccessStats",new Map);a(this,"MAX_CACHE_SIZE",1e3);a(this,"CACHE_TTL",5*60*1e3);a(this,"enableCycleDetection",!0);this.store=t,this.event=e}setCycleDetection(t){this.enableCycleDetection=!!t}getLinks(){return this.links}getLinksByTaskId(t){return this.links.filter(e=>e.from===t||e.to===t)}setLinks(t,e=!1){const i=new Set,s=new Set;this.links.forEach(r=>{i.add(r.from),i.add(r.to)}),t.forEach(r=>{s.add(r.from),s.add(r.to)});const n=Array.from(new Set([...i,...s]));let o="BATCH";this.links.length===0?o="ADD":t.length===0?o="REMOVE":Math.abs(t.length-this.links.length)===1&&(o=t.length>this.links.length?"ADD":"REMOVE"),this.links=t||[],this.rebuildAdjacency(),this.invalidateSmartCaches(n,o),e&&this.enableCycleDetection?this.detectAllCycles():this.lastCycleReport=null}update(){this.setLinks(this.links,!0)}isLinkExist(t,e,i){return this.links.some(s=>s.from===t&&s.to===e&&(s.type||"FS")===(i||"FS"))}validateLinkType(t){return Object.keys(K.LINK_TYPE_MAP).includes(t)}convertPointsToLinkType(t,e){return`${t}${e}`}validateLink(t){return!t||t.from==null||t.to==null?{ok:!1,reason:X.LINK_INVALID_ARG,message:D.getMessage("Missing endpoint")}:t.from===t.to?{ok:!1,reason:X.LINK_SAME,message:D.getMessage("Cannot link task to itself")}:!this.getTask(t.from)||!this.getTask(t.to)?{ok:!1,reason:X.TASK_NOT_FOUND,message:D.getMessage("Task not found")}:t.type&&!this.validateLinkType(t.type)?{ok:!1,reason:X.INVALID_TYPE,message:D.getMessage(`Invalid link type: ${t.type}. It must be one of: ${Object.keys(K.LINK_TYPE_MAP).join(", ")}`)}:this.isLinkExist(t.from,t.to,t.type)?{ok:!1,reason:X.LINK_EXIST,message:D.getMessage("Link already exists")}:{ok:!0}}validateChain(t,e,i){const s={from:t,to:e,type:i},n=this.validateLink(s);if(!n.ok)return n;if(this.enableCycleDetection){const o=this.willCreateCycle(t,e);if(o)return{ok:!1,reason:X.LINK_CYCLE,message:D.getMessage("Adding this link would create a cycle"),cycleInfo:o}}return{ok:!0}}validateLinks(t){const e=[],i=[];for(const s of t){const n=this.validateLink(s);n.ok?i.push(s):e.push({link:s,reason:n.reason,message:n.message||""})}return{invalid:e,valid:i,totalCount:t.length}}getTaskLinks(t){const e=this.toLinksMap.get(t)||[],i=this.fromLinksMap.get(t)||[],s=[...e,...i];return{incoming:e,outgoing:i,all:s}}getTaskPredecessors(t){const e=this.toLinksMap.get(t)||[];return{tasks:e.map(s=>this.getTask(s.from)).filter(s=>!!s),links:e}}getTaskSuccessors(t){const e=this.fromLinksMap.get(t)||[];return{tasks:e.map(s=>this.getTask(s.to)).filter(s=>!!s),links:e}}getDirectlyConnectedTasks(t){const e=this.getTaskPredecessors(t).tasks,i=this.getTaskSuccessors(t).tasks,s=new Map;return[...e,...i].forEach(n=>{s.set(n.id,n)}),Array.from(s.values())}hasConnectionPath(t,e){if(t===e)return!0;const i=new Set,s=[t];for(;s.length;){const n=s.pop();if(n===e)return!0;if(i.has(n))continue;i.add(n);const o=this.getTaskSuccessors(n).tasks;for(const r of o)i.has(r.id)||s.push(r.id)}return!1}getDataChain(t){const e=this.getTask(t);if(!e)return{prev:{chain:[],nodes:[],links:[]},next:{chain:[],nodes:[],links:[]},allNodes:[],allLinks:[],current:void 0};const i=this.forwardMemo.get(t),s=this.backwardMemo.get(t);this.recordCacheAccess(t,!!(i&&s));const n=x=>(this.fromLinksMap.get(x)||[]).map(b=>this.getTask(b.to)).filter(b=>!!b),o=x=>(this.toLinksMap.get(x)||[]).map(b=>this.getTask(b.from)).filter(b=>!!b),r=(x,T,b=new Set)=>{const w=x.id;if(this.forwardMemo.has(w))return this.recordCacheAccess(w,!0),this.forwardMemo.get(w);if(T.has(x.id)||b.has(x.id))return[];T.add(x.id),b.add(x.id);const L=n(x.id);let M=[];if(L.length===0)M=[[x]];else{for(const C of L){const S=r(C,T,b);for(const E of S)M.push([x,...E])}M.length===0&&(M=[[x]])}return T.delete(x.id),M.length<100&&(this.forwardMemo.set(w,M),this.recordCacheAccess(w,!1)),M},h=(x,T,b=new Set)=>{const w=x.id;if(this.backwardMemo.has(w))return this.recordCacheAccess(w,!0),this.backwardMemo.get(w);if(T.has(x.id)||b.has(x.id))return[];T.add(x.id),b.add(x.id);const L=o(x.id);let M=[];if(L.length===0)M=[[x]];else{for(const C of L){const S=h(C,T,b);for(const E of S)M.push([...E,x])}M.length===0&&(M=[[x]])}return T.delete(x.id),M.length<100&&(this.backwardMemo.set(w,M),this.recordCacheAccess(w,!1)),M},c=h(e,new Set),g=r(e,new Set);this.getDirectlyConnectedTasks(t).forEach(x=>{this.establishCacheDependency(t,x.id),this.establishCacheDependency(x.id,t)});const l=new Map,m=new Map,p=(x,T)=>{const b=[];for(const w of x){w.forEach(L=>l.set(L.id,L));for(let L=0;L<w.length-1;L++){const M=w[L].id,C=w[L+1].id,S=this.findLinkFast(M,C);if(S){const E=`${S.from}-${S.to}-${S.type||"default"}`;m.has(E)||(b.push(S),m.set(E,S))}}}return b},u=p(c),y=p(g);return{prev:{chain:c.map(x=>x.map(T=>T.getEmitData().data)),nodes:c.flat().filter((x,T,b)=>b.findIndex(w=>w.id===x.id)===T).map(x=>x.getEmitData().data),links:u},next:{chain:g.map(x=>x.map(T=>T.getEmitData().data)),nodes:g.flat().filter((x,T,b)=>b.findIndex(w=>w.id===x.id)===T).map(x=>x.getEmitData().data),links:y},allNodes:Array.from(l.values()).map(x=>x.getEmitData().data),allLinks:Array.from(m.values()),current:e.getEmitData().data}}hasCycle(){return this.lastCycleReport?this.lastCycleReport.hasCycle:this.detectAllCycles(!1).hasCycle}detectAllCycles(t=!0){const e=new Map,i=new Map,s=new Set,n=[];let o=0;const r=[],h=l=>{e.set(l,o),i.set(l,o),o++,n.push(l),s.add(l);const m=this.fromLinksMap.get(l)||[];for(const p of m)e.has(p.to)?s.has(p.to)&&i.set(l,Math.min(i.get(l),e.get(p.to))):(h(p.to),i.set(l,Math.min(i.get(l),i.get(p.to))));if(i.get(l)===e.get(l)){const p=[];for(;;){const u=n.pop();if(s.delete(u),p.push(u),u===l)break}r.push(p)}};this.store.getDataManager().getTasks(!1).forEach(l=>{e.has(l.id)||h(l.id)});const c=r.filter(l=>l.length>1||this.hasSelfLoop(l[0])),g=c.map(l=>l.slice()),d={hasCycle:c.length>0,sccs:c,cycles:g,nodes:Array.from(new Set(c.flat()))};return this.lastCycleReport=d,t&&d.hasCycle&&D.warn("Cycle detected in task dependencies",d),d}getCycleReport(){return this.lastCycleReport}detectLinkConflicts(t,e){const i=this.links.filter(d=>d.from===t&&d.to===e),s=this.links.filter(d=>d.from===e&&d.to===t),n=[...i,...s],o=[],r=[],h=new Map;n.forEach(d=>{d.type&&h.set(d.type,(h.get(d.type)||0)+1)});const c=h.has("FS"),g=h.has("SF");return c&&g&&(o.push(...n.filter(d=>d.type==="FS"||d.type==="SF")),r.push("FS-SF conflict")),{hasConflict:o.length>0,conflicts:o,conflictTypes:r}}hasConflictingLinks(t,e){return this.detectLinkConflicts(t,e).hasConflict}computeTopo(){if(this.topoOrder)return this.topoOrder;const t=new Map;this.store.getDataManager().getTasks(!1).forEach(s=>t.set(s.id,0));for(const s of this.links)t.has(s.to)&&t.set(s.to,(t.get(s.to)||0)+1);const e=[];t.forEach((s,n)=>{s===0&&e.push(n)});const i=[];for(;e.length;){const s=e.shift();i.push(s);const n=this.fromLinksMap.get(s)||[];for(const o of n){const r=(t.get(o.to)||0)-1;t.set(o.to,r),r===0&&e.push(o.to)}}return i.length!==this.store.getDataManager().getTasks(!1).length?null:(i.forEach((s,n)=>this.topoIndex.set(s,n)),this.topoOrder=i,i)}willCreateCycle(t,e){if(this.computeTopo()){const r=this.topoIndex.get(t),h=this.topoIndex.get(e);if(r!=null&&h!=null&&r<h)return null}const s=[e],n=new Set,o=new Map;for(;s.length;){const r=s.pop();if(n.has(r))continue;n.add(r);const h=this.fromLinksMap.get(r)||[];for(const c of h){const g=c.to;if(!n.has(g)&&!o.has(g)&&o.set(g,r),g===t){o.has(g)||o.set(g,r);const d=[];let l=t;for(;l!==void 0;)d.push(l),l=o.get(l);const m=d.slice().reverse(),p=[t,...m];return{cycles:[p],nodes:Array.from(new Set(p)),sccs:[]}}s.push(g)}}return null}rebuildAdjacency(){this.fromLinksMap.clear(),this.toLinksMap.clear();for(const t of this.links)this.fromLinksMap.has(t.from)||this.fromLinksMap.set(t.from,[]),this.toLinksMap.has(t.to)||this.toLinksMap.set(t.to,[]),this.fromLinksMap.get(t.from).push(t),this.toLinksMap.get(t.to).push(t)}invalidateAllCaches(){this.topoOrder=null,this.topoIndex.clear(),this.directConnectionCache.clear(),this.forwardMemo.clear(),this.backwardMemo.clear(),this.cacheDependencies.clear(),this.cacheAccessStats.clear()}invalidateConnectionCache(t){t?t.forEach(e=>this.directConnectionCache.delete(e)):this.directConnectionCache.clear()}findLinkFast(t,e){const i=this.fromLinksMap.get(t);if(i)return i.find(s=>s.to===e)}getTask(t){return this.store.getDataManager().getTaskById(t)}hasSelfLoop(t){return(this.fromLinksMap.get(t)||[]).some(e=>e.to===t)}buildSimpleCycleInfo(t,e){const i=[t,e];return{cycles:[i],nodes:Array.from(new Set(i)),sccs:[]}}invalidateSmartCaches(t,e="UPDATE"){if(!t||t.length===0){this.invalidateAllCaches();return}switch(e){case"ADD":this.handleAddLinkInvalidation(t);break;case"REMOVE":this.handleRemoveLinkInvalidation(t);break;case"UPDATE":this.handleUpdateLinkInvalidation(t);break;case"BATCH":this.handleBatchOperationInvalidation(t);break}this.cleanupExpiredCaches(),this.limitCacheSize()}handleAddLinkInvalidation(t){const e=new Set;for(const i of t)e.add(i),this.getUpstreamTasksRecursive(i,3).forEach(o=>e.add(o)),this.getDownstreamTasksRecursive(i,3).forEach(o=>e.add(o));this.invalidateSpecificCaches(Array.from(e))}handleRemoveLinkInvalidation(t){const e=new Set;for(const i of t)e.add(i),this.getConnectedComponent(i).forEach(n=>e.add(n));this.invalidateSpecificCaches(Array.from(e))}handleUpdateLinkInvalidation(t){const e=new Set;for(const i of t){e.add(i),this.getDirectlyConnectedTasks(i).forEach(o=>e.add(o.id));const n=this.cacheDependencies.get(i);n&&n.forEach(o=>e.add(o))}this.invalidateSpecificCaches(Array.from(e))}handleBatchOperationInvalidation(t){if(t.length>50){this.invalidateAllCaches();return}const e=new Set(t);for(const i of t)this.getDirectlyConnectedTasks(i).forEach(n=>e.add(n.id));this.invalidateSpecificCaches(Array.from(e))}invalidateSpecificCaches(t){for(const e of t)this.forwardMemo.delete(e),this.backwardMemo.delete(e),this.directConnectionCache.delete(e),this.cacheAccessStats.delete(e),this.cacheDependencies.delete(e),this.cacheDependencies.forEach((i,s)=>{i.delete(e)});t.length>5&&(this.topoOrder=null,this.topoIndex.clear())}getUpstreamTasksRecursive(t,e){const i=new Set,s=new Set,n=(o,r)=>{if(r>=e||s.has(o))return;s.add(o);const h=this.getTaskPredecessors(o).tasks;for(const c of h)i.add(c.id),n(c.id,r+1)};return n(t,0),Array.from(i)}getDownstreamTasksRecursive(t,e){const i=new Set,s=new Set,n=(o,r)=>{if(r>=e||s.has(o))return;s.add(o);const h=this.getTaskSuccessors(o).tasks;for(const c of h)i.add(c.id),n(c.id,r+1)};return n(t,0),Array.from(i)}getConnectedComponent(t){const e=new Set,i=new Set,s=[t];for(;s.length>0;){const n=s.pop();if(i.has(n))continue;i.add(n),e.add(n);const o=this.getDirectlyConnectedTasks(n);for(const r of o)i.has(r.id)||s.push(r.id)}return Array.from(e)}cleanupExpiredCaches(){const t=Date.now(),e=[];this.cacheAccessStats.forEach((i,s)=>{t-i.lastAccess>this.CACHE_TTL&&e.push(s)}),this.invalidateSpecificCaches(e)}limitCacheSize(){const t=this.forwardMemo.size+this.backwardMemo.size;if(t>this.MAX_CACHE_SIZE){const e=Array.from(this.cacheAccessStats.entries()).sort((n,o)=>n[1].lastAccess-o[1].lastAccess),i=Math.ceil(t*.2),s=e.slice(0,i).map(([n])=>n);this.invalidateSpecificCaches(s)}}recordCacheAccess(t,e){const i=this.cacheAccessStats.get(t)||{hits:0,lastAccess:0};e&&(i.hits+=1),i.lastAccess=Date.now(),this.cacheAccessStats.set(t,i)}establishCacheDependency(t,e){this.cacheDependencies.has(t)||this.cacheDependencies.set(t,new Set),this.cacheDependencies.get(t).add(e)}getDebugInfo(){const t=this.store.getDataManager().getTasks(!1),e=t.filter(i=>{const s=this.toLinksMap.has(i.id)&&this.toLinksMap.get(i.id).length>0,n=this.fromLinksMap.has(i.id)&&this.fromLinksMap.get(i.id).length>0;return!s&&!n}).map(i=>i.id);return{totalLinks:this.links.length,totalTasks:t.length,connectionComponents:this.countConnectionComponents(),hasCycle:this.hasCycle(),topologicalOrder:this.computeTopo(),isolatedTasks:e}}countConnectionComponents(){const t=this.store.getDataManager().getTasks(!1),e=new Set;let i=0;const s=n=>{if(e.has(n))return;e.add(n);const o=this.getDirectlyConnectedTasks(n);for(const r of o)e.has(r.id)||s(r.id)};for(const n of t)e.has(n.id)||(s(n.id),i++);return i}getCachePerformanceStats(){const t=Array.from(this.cacheAccessStats.values()).reduce((n,o)=>n+o.hits,0),e=this.cacheAccessStats.size,i=Date.now(),s=Array.from(this.cacheAccessStats.values()).filter(n=>i-n.lastAccess>this.CACHE_TTL).length;return{totalCacheSize:this.forwardMemo.size+this.backwardMemo.size,hitRate:e>0?t/e*100:0,memoryUsage:this.estimateMemoryUsage(),expiredEntries:s,dependencyCount:this.cacheDependencies.size}}estimateMemoryUsage(){const t=this.links.length*100,e=this.forwardMemo.size*300,i=this.backwardMemo.size*300,s=this.cacheDependencies.size*50,n=this.cacheAccessStats.size*50,o=t+e+i+s+n;return o>1024*1024?`${(o/1024/1024).toFixed(2)} MB`:o>1024?`${(o/1024).toFixed(2)} KB`:`${o} B`}};a(K,"LINK_TYPE_MAP",{FS:{from:"F",to:"S",description:"结束到开始"},SF:{from:"S",to:"F",description:"开始到结束"},FF:{from:"F",to:"F",description:"结束到结束"},SS:{from:"S",to:"S",description:"开始到开始"}});let lt=K;var U=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function V(f){return f&&f.__esModule&&Object.prototype.hasOwnProperty.call(f,"default")?f.default:f}var yt={exports:{}};(function(f,t){(function(e,i){f.exports=i()})(U,function(){var e,i,s=1e3,n=6e4,o=36e5,r=864e5,h=/\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,c=31536e6,g=2628e6,d=/^(-|\+)?P(?:([-+]?[0-9,.]*)Y)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)W)?(?:([-+]?[0-9,.]*)D)?(?:T(?:([-+]?[0-9,.]*)H)?(?:([-+]?[0-9,.]*)M)?(?:([-+]?[0-9,.]*)S)?)?$/,l={years:c,months:g,days:r,hours:o,minutes:n,seconds:s,milliseconds:1,weeks:6048e5},m=function(M){return M instanceof w},p=function(M,C,S){return new w(M,S,C.$l)},u=function(M){return i.p(M)+"s"},y=function(M){return M<0},x=function(M){return y(M)?Math.ceil(M):Math.floor(M)},T=function(M){return Math.abs(M)},b=function(M,C){return M?y(M)?{negative:!0,format:""+T(M)+C}:{negative:!1,format:""+M+C}:{negative:!1,format:""}},w=function(){function M(S,E,H){var I=this;if(this.$d={},this.$l=H,S===void 0&&(this.$ms=0,this.parseFromMilliseconds()),E)return p(S*l[u(E)],this);if(typeof S=="number")return this.$ms=S,this.parseFromMilliseconds(),this;if(typeof S=="object")return Object.keys(S).forEach(function($){I.$d[u($)]=S[$]}),this.calMilliseconds(),this;if(typeof S=="string"){var _=S.match(d);if(_){var R=_.slice(2).map(function($){return $!=null?Number($):0});return this.$d.years=R[0],this.$d.months=R[1],this.$d.weeks=R[2],this.$d.days=R[3],this.$d.hours=R[4],this.$d.minutes=R[5],this.$d.seconds=R[6],this.calMilliseconds(),this}}return this}var C=M.prototype;return C.calMilliseconds=function(){var S=this;this.$ms=Object.keys(this.$d).reduce(function(E,H){return E+(S.$d[H]||0)*l[H]},0)},C.parseFromMilliseconds=function(){var S=this.$ms;this.$d.years=x(S/c),S%=c,this.$d.months=x(S/g),S%=g,this.$d.days=x(S/r),S%=r,this.$d.hours=x(S/o),S%=o,this.$d.minutes=x(S/n),S%=n,this.$d.seconds=x(S/s),S%=s,this.$d.milliseconds=S},C.toISOString=function(){var S=b(this.$d.years,"Y"),E=b(this.$d.months,"M"),H=+this.$d.days||0;this.$d.weeks&&(H+=7*this.$d.weeks);var I=b(H,"D"),_=b(this.$d.hours,"H"),R=b(this.$d.minutes,"M"),$=this.$d.seconds||0;this.$d.milliseconds&&($+=this.$d.milliseconds/1e3,$=Math.round(1e3*$)/1e3);var G=b($,"S"),W=S.negative||E.negative||I.negative||_.negative||R.negative||G.negative,B=_.format||R.format||G.format?"T":"",Y=(W?"-":"")+"P"+S.format+E.format+I.format+B+_.format+R.format+G.format;return Y==="P"||Y==="-P"?"P0D":Y},C.toJSON=function(){return this.toISOString()},C.format=function(S){var E=S||"YYYY-MM-DDTHH:mm:ss",H={Y:this.$d.years,YY:i.s(this.$d.years,2,"0"),YYYY:i.s(this.$d.years,4,"0"),M:this.$d.months,MM:i.s(this.$d.months,2,"0"),D:this.$d.days,DD:i.s(this.$d.days,2,"0"),H:this.$d.hours,HH:i.s(this.$d.hours,2,"0"),m:this.$d.minutes,mm:i.s(this.$d.minutes,2,"0"),s:this.$d.seconds,ss:i.s(this.$d.seconds,2,"0"),SSS:i.s(this.$d.milliseconds,3,"0")};return E.replace(h,function(I,_){return _||String(H[I])})},C.as=function(S){return this.$ms/l[u(S)]},C.get=function(S){var E=this.$ms,H=u(S);return H==="milliseconds"?E%=1e3:E=H==="weeks"?x(E/l[H]):this.$d[H],E||0},C.add=function(S,E,H){var I;return I=E?S*l[u(E)]:m(S)?S.$ms:p(S,this).$ms,p(this.$ms+I*(H?-1:1),this)},C.subtract=function(S,E){return this.add(S,E,!0)},C.locale=function(S){var E=this.clone();return E.$l=S,E},C.clone=function(){return p(this.$ms,this)},C.humanize=function(S){return e().add(this.$ms,"ms").locale(this.$l).fromNow(!S)},C.valueOf=function(){return this.asMilliseconds()},C.milliseconds=function(){return this.get("milliseconds")},C.asMilliseconds=function(){return this.as("milliseconds")},C.seconds=function(){return this.get("seconds")},C.asSeconds=function(){return this.as("seconds")},C.minutes=function(){return this.get("minutes")},C.asMinutes=function(){return this.as("minutes")},C.hours=function(){return this.get("hours")},C.asHours=function(){return this.as("hours")},C.days=function(){return this.get("days")},C.asDays=function(){return this.as("days")},C.weeks=function(){return this.get("weeks")},C.asWeeks=function(){return this.as("weeks")},C.months=function(){return this.get("months")},C.asMonths=function(){return this.as("months")},C.years=function(){return this.get("years")},C.asYears=function(){return this.as("years")},M}(),L=function(M,C,S){return M.add(C.years()*S,"y").add(C.months()*S,"M").add(C.days()*S,"d").add(C.hours()*S,"h").add(C.minutes()*S,"m").add(C.seconds()*S,"s").add(C.milliseconds()*S,"ms")};return function(M,C,S){e=S,i=S().$utils(),S.duration=function(I,_){var R=S.locale();return p(I,{$l:R},_)},S.isDuration=m;var E=C.prototype.add,H=C.prototype.subtract;C.prototype.add=function(I,_){return m(I)?L(this,I,1):E.bind(this)(I,_)},C.prototype.subtract=function(I,_){return m(I)?L(this,I,-1):H.bind(this)(I,_)}}})})(yt);var Pt=yt.exports;const Yt=V(Pt);var wt={exports:{}};(function(f,t){(function(e,i){f.exports=i()})(U,function(){return function(e,i,s){i.prototype.isBetween=function(n,o,r,h){var c=s(n),g=s(o),d=(h=h||"()")[0]==="(",l=h[1]===")";return(d?this.isAfter(c,r):!this.isBefore(c,r))&&(l?this.isBefore(g,r):!this.isAfter(g,r))||(d?this.isBefore(c,r):!this.isAfter(c,r))&&(l?this.isAfter(g,r):!this.isBefore(g,r))}}})})(wt);var Ut=wt.exports;const Xt=V(Ut);var bt={exports:{}};(function(f,t){(function(e,i){f.exports=i()})(U,function(){return function(e,i){i.prototype.isSameOrBefore=function(s,n){return this.isSame(s,n)||this.isBefore(s,n)}}})})(bt);var Vt=bt.exports;const qt=V(Vt);var Tt={exports:{}};(function(f,t){(function(e,i){f.exports=i()})(U,function(){return function(e,i){i.prototype.isSameOrAfter=function(s,n){return this.isSame(s,n)||this.isAfter(s,n)}}})})(Tt);var Qt=Tt.exports;const jt=V(Qt);var St={exports:{}};(function(f,t){(function(e,i){f.exports=i()})(U,function(){return function(e,i,s){var n=i.prototype,o=function(d){return d&&(d.indexOf?d:d.s)},r=function(d,l,m,p,u){var y=d.name?d:d.$locale(),x=o(y[l]),T=o(y[m]),b=x||T.map(function(L){return L.slice(0,p)});if(!u)return b;var w=y.weekStart;return b.map(function(L,M){return b[(M+(w||0))%7]})},h=function(){return s.Ls[s.locale()]},c=function(d,l){return d.formats[l]||function(m){return m.replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g,function(p,u,y){return u||y.slice(1)})}(d.formats[l.toUp