@taskctrl/canvas-timeline 0.1.1 → 0.2.0
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/canvas/GridLayer.d.ts +2 -2
- package/dist/canvas/ItemsLayer.d.ts +1 -1
- package/dist/canvas-timeline.cjs.js +1 -1
- package/dist/canvas-timeline.cjs.js.map +1 -1
- package/dist/canvas-timeline.es.js +816 -734
- package/dist/canvas-timeline.es.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/interaction/snapUtils.d.ts +15 -0
- package/dist/types.d.ts +8 -0
- package/package.json +7 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Group, TimelineTheme, DayStyle, RowStyle } from '../types';
|
|
1
|
+
import type { Group, TimelineTheme, DayStyle, RowStyle, TimeRangeHighlight } from '../types';
|
|
2
2
|
import type { ViewState } from '../core/ViewState';
|
|
3
3
|
export declare class GridLayer {
|
|
4
|
-
draw(ctx: CanvasRenderingContext2D, view: ViewState, groups: Group[], theme: TimelineTheme, dayStyle?: (date: Date) => DayStyle | null, rowStyle?: (group: Group) => RowStyle | null): void;
|
|
4
|
+
draw(ctx: CanvasRenderingContext2D, view: ViewState, groups: Group[], theme: TimelineTheme, dayStyle?: (date: Date) => DayStyle | null, rowStyle?: (group: Group) => RowStyle | null, highlights?: TimeRangeHighlight[]): void;
|
|
5
5
|
}
|
|
@@ -3,6 +3,6 @@ import type { ViewState } from '../core/ViewState';
|
|
|
3
3
|
import type { IntervalTree } from '../core/IntervalTree';
|
|
4
4
|
import type { LayoutEngine } from '../core/LayoutEngine';
|
|
5
5
|
export declare class ItemsLayer {
|
|
6
|
-
draw(ctx: CanvasRenderingContext2D, view: ViewState, groups: Group[],
|
|
6
|
+
draw(ctx: CanvasRenderingContext2D, view: ViewState, groups: Group[], items: Item[], tree: IntervalTree<Item>, layout: LayoutEngine, itemRenderer: CanvasItemRenderer, groupRenderer: CanvasGroupItemRenderer | undefined, theme: TimelineTheme, selected: number[], hoveredItemId: number | undefined, dependencies?: Dependency[]): void;
|
|
7
7
|
private drawDependencies;
|
|
8
8
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const X=require("react/jsx-runtime"),u=require("react"),er=require("react-dom"),ee=require("dayjs"),ae={primary:"#269bf7",trainColors:{},status:{red:"#EF5350",yellow:"#FBBF24",green:"#31c48d"},grid:{line:"#E5E5E5",rowAlt:"#F7F7F7",weekend:"rgba(0,0,0,0.03)"},item:{radius:3,text:"#374151",selectedRing:"#a3a3a3"},marker:{today:"#FD7171",milestone:"#3B82F6",cursor:"#269bf7"},sidebar:{bg:"#F9FAFB",border:"#E5E7EB",text:"#6c737f"},header:{bg:"#F9FAFB",border:"#E5E7EB",text:"#6c737f"}};class Ue{constructor(e){Object.defineProperty(this,"visibleTimeStart",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"visibleTimeEnd",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"canvasWidth",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"canvasHeight",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"sidebarWidth",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"lineHeight",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"groupCount",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"buffer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"scrollTop",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"visibleDuration",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"pixelsPerMs",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.visibleTimeStart=e.visibleTimeStart,this.visibleTimeEnd=e.visibleTimeEnd,this.canvasWidth=e.canvasWidth,this.canvasHeight=e.canvasHeight,this.sidebarWidth=e.sidebarWidth,this.lineHeight=e.lineHeight,this.groupCount=e.groupCount,this.buffer=e.buffer,this.scrollTop=e.scrollTop,this.visibleDuration=this.visibleTimeEnd-this.visibleTimeStart,this.pixelsPerMs=this.canvasWidth/this.visibleDuration}update(e){e.visibleTimeStart!==void 0&&(this.visibleTimeStart=e.visibleTimeStart),e.visibleTimeEnd!==void 0&&(this.visibleTimeEnd=e.visibleTimeEnd),e.canvasWidth!==void 0&&(this.canvasWidth=e.canvasWidth),e.canvasHeight!==void 0&&(this.canvasHeight=e.canvasHeight),e.sidebarWidth!==void 0&&(this.sidebarWidth=e.sidebarWidth),e.lineHeight!==void 0&&(this.lineHeight=e.lineHeight),e.groupCount!==void 0&&(this.groupCount=e.groupCount),e.buffer!==void 0&&(this.buffer=e.buffer),e.scrollTop!==void 0&&(this.scrollTop=e.scrollTop),this.visibleDuration=this.visibleTimeEnd-this.visibleTimeStart,this.pixelsPerMs=this.canvasWidth/this.visibleDuration}timeToX(e){return(e-this.visibleTimeStart)*this.pixelsPerMs}xToTime(e){return this.visibleTimeStart+e/this.pixelsPerMs}yToGroupIndex(e){const r=Math.floor((e+this.scrollTop)/this.lineHeight);return Math.max(0,Math.min(r,this.groupCount-1))}groupIndexToY(e){return e*this.lineHeight-this.scrollTop}getBufferBounds(){const e=this.visibleDuration*1.5;return{bufferStart:this.visibleTimeStart-e,bufferEnd:this.visibleTimeEnd+e}}getVisibleGroupRange(){const e=Math.max(0,Math.floor(this.scrollTop/this.lineHeight)),r=Math.ceil(this.canvasHeight/this.lineHeight),o=Math.min(this.groupCount-1,e+r);return{firstVisible:e,lastVisible:o}}isScrollInBuffer(e){const r=this.visibleDuration*1.5*this.pixelsPerMs;return Math.abs(e)<r}getTotalHeight(){return this.groupCount*this.lineHeight}}class tr{constructor(){Object.defineProperty(this,"root",{enumerable:!0,configurable:!0,writable:!0,value:null})}buildFromItems(e,r,o){const l=e.map(c=>({item:c,start:r(c),end:o(c)}));this.root=this.buildNode(l)}buildNode(e){if(e.length===0)return null;let r=1/0,o=-1/0;for(const f of e)f.start<r&&(r=f.start),f.end>o&&(o=f.end);const l=(r+o)/2,c=[],a=[],b=[];for(const f of e)f.end<l?c.push(f):f.start>l?a.push(f):b.push(f);return{center:l,left:this.buildNode(c),right:this.buildNode(a),overlapping:b}}query(e,r){const o=[];return this.queryNode(this.root,e,r,o),o}queryNode(e,r,o,l){if(e!==null){for(const c of e.overlapping)c.start<=o&&c.end>=r&&l.push(c.item);r<=e.center&&e.left!==null&&this.queryNode(e.left,r,o,l),o>=e.center&&e.right!==null&&this.queryNode(e.right,r,o,l)}}}class rr{constructor(e,r){Object.defineProperty(this,"lineHeight",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"itemHeightRatio",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"layoutCache",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"groupMaxStack",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),this.lineHeight=e,this.itemHeightRatio=r}computeLayout(e,r){if(this.layoutCache=new Map,this.groupMaxStack=new Map,!r){const c=this.lineHeight*this.itemHeightRatio;for(const a of e)this.layoutCache.set(a.id,{stackLevel:0,itemHeight:c}),this.groupMaxStack.set(a.group,0);return this.layoutCache}const o=new Map;for(const c of e){let a=o.get(c.group);a||(a=[],o.set(c.group,a)),a.push(c)}const l=this.lineHeight*this.itemHeightRatio;for(const[c,a]of o){a.sort((v,T)=>{const y=v.start_time-T.start_time;return y!==0?y:T.end_time-T.start_time-(v.end_time-v.start_time)});const b=[];let f=0;for(const v of a){let T=-1;for(let y=0;y<b.length;y++)if(b[y]<=v.start_time){T=y;break}T===-1?(T=b.length,b.push(v.end_time)):b[T]=v.end_time,T>f&&(f=T),this.layoutCache.set(v.id,{stackLevel:T,itemHeight:l})}this.groupMaxStack.set(c,f)}return this.layoutCache}getLayout(e){return this.layoutCache.get(e)}getGroupHeight(e){return((this.groupMaxStack.get(e)??0)+1)*this.lineHeight}}function De(t,e,r,o,l,c){const a=r.xToTime(t),b=new Map;for(let y=0;y<c.length;y++)b.set(c[y].id,y);const f=o.query(a,a);let v=null,T=-1/0;for(const y of f){const H=b.get(y.group);if(H===void 0)continue;const k=l.getLayout(y.id);if(!k)continue;const M=r.timeToX(y.start_time),I=r.timeToX(y.end_time)-M;if(t<M||t>M+I)continue;const S=r.groupIndexToY(H)+k.stackLevel*r.lineHeight+(r.lineHeight-k.itemHeight)/2,O=k.itemHeight;e<S||e>S+O||S>T&&(T=S,v=y)}return v}function Ke(t,e,r){const o=e.yToGroupIndex(t);return r[o]??null}function yt(t,e,r,o=6){const l=r.timeToX(e.start_time),c=r.timeToX(e.end_time);return t-l<=o?"left":c-t<=o?"right":"body"}function Je(t,e,r){const o=window.devicePixelRatio||1,l=Math.round(e*o),c=Math.round(r*o);(t.width!==l||t.height!==c)&&(t.width=l,t.height=c,t.style.width=`${e}px`,t.style.height=`${r}px`);const a=t.getContext("2d");return a.setTransform(o,0,0,o,0,0),a}function Qe(t,e){const r=window.devicePixelRatio||1;t.clearRect(0,0,e.width/r,e.height/r)}class ir{constructor(e){Object.defineProperty(this,"dirty",{enumerable:!0,configurable:!0,writable:!0,value:{grid:!1,items:!1,overlay:!1}}),Object.defineProperty(this,"rafId",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"drawCallback",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.drawCallback=e}markDirty(e){this.dirty[e]=!0,this.schedule()}markAllDirty(){this.dirty.grid=!0,this.dirty.items=!0,this.dirty.overlay=!0,this.schedule()}dispose(){this.rafId!==null&&(cancelAnimationFrame(this.rafId),this.rafId=null)}schedule(){this.rafId===null&&(this.rafId=requestAnimationFrame(()=>{this.rafId=null;const e={...this.dirty};this.dirty.grid=!1,this.dirty.items=!1,this.dirty.overlay=!1,this.drawCallback(e)}))}}class nr{draw(e,r,o,l,c,a){const{firstVisible:b,lastVisible:f}=r.getVisibleGroupRange();for(let S=b;S<=f;S++){const O=r.groupIndexToY(S),j=o[S];if(!j)continue;let N;const z=a==null?void 0:a(j);z!=null&&z.backgroundColor?N=z.backgroundColor:N=S%2===0?"#FFFFFF":l.grid.rowAlt,e.fillStyle=N,e.fillRect(0,O,r.canvasWidth,r.lineHeight),e.strokeStyle=(z==null?void 0:z.borderBottomColor)??l.grid.line,e.lineWidth=.5,e.beginPath(),e.moveTo(0,O+r.lineHeight),e.lineTo(r.canvasWidth,O+r.lineHeight),e.stroke()}const v=r.visibleTimeStart,T=r.visibleTimeEnd,k=864e5/(T-v)*r.canvasWidth;let M="day";k<2?M="month":k<8&&(M="week");{let S=ee(v).startOf("day");const O=ee(T).endOf("day");let j=null,N=1,z=0;const x=[],ie=V=>{j!==null&&(e.fillStyle=j,N!==1&&(e.globalAlpha=N),e.fillRect(z,0,V-z,r.canvasHeight),N!==1&&(e.globalAlpha=1),j=null,N=1)};for(;S.isBefore(O);){const V=r.timeToX(S.valueOf()),Ce=S.toDate(),Z=c==null?void 0:c(Ce);let te=null,ne=1;if(Z!=null&&Z.backgroundColor)te=Z.backgroundColor,ne=Z.opacity??1;else{const me=S.day();(me===0||me===6)&&(te=l.grid.weekend)}Z!=null&&Z.borderColor&&x.push({x:V,color:Z.borderColor}),te===j&&ne===N||(ie(V),te!==null&&(j=te,N=ne,z=V)),S=S.add(1,"day")}j!==null&&ie(r.timeToX(S.valueOf()));for(const V of x)e.strokeStyle=V.color,e.lineWidth=.5,e.beginPath(),e.moveTo(V.x,0),e.lineTo(V.x,r.canvasHeight),e.stroke()}let I=ee(v).startOf(M);const W=ee(T).add(1,M);for(e.strokeStyle=l.grid.line,e.lineWidth=.5,e.beginPath();I.isBefore(W);){const S=r.timeToX(I.valueOf());e.moveTo(S,0),e.lineTo(S,r.canvasHeight),I=I.add(1,M)}e.stroke()}}const Tt='500 12px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif';function Ht(t,e){return{roundRect(r,o,l,c,a=3){t.beginPath(),t.roundRect(r,o,l,c,a),t.fill()},fillText(r,o,l,c){if(t.font=Tt,c!==void 0&&t.measureText(r).width>c){let a=0,b=r.length;for(;a<b;){const f=Math.ceil((a+b)/2),v=r.slice(0,f)+"...";t.measureText(v).width<=c?a=f:b=f-1}t.fillText(r.slice(0,a)+"...",o,l)}else t.fillText(r,o,l)},gradient(r,o,l,c){const a=t.createLinearGradient(r,0,r+o,0);return a.addColorStop(0,l),a.addColorStop(.5,l),a.addColorStop(.5,c),a.addColorStop(1,c),a},leftBar(r,o=3){e&&(t.save(),t.fillStyle=r,t.fillRect(e.x,e.y,o,e.height),t.restore())},icon(r,o,l,c=14){t.save();const a=c/2;if(r==="check"){t.fillStyle="#31c48d",t.beginPath(),t.arc(o+a,l+a,a,0,Math.PI*2),t.fill(),t.strokeStyle="#ffffff",t.lineWidth=c*.12,t.beginPath();const b=o+a,f=l+a;t.moveTo(b-a*.45,f),t.lineTo(b-a*.1,f+a*.42),t.lineTo(b+a*.45,f-a*.35),t.stroke()}else if(r==="danger-red"||r==="danger-yellow"){const b=r==="danger-red"?"#EF5350":"#FBBF24";t.fillStyle=b,t.beginPath(),t.moveTo(o+a,l),t.lineTo(o+c,l+c),t.lineTo(o,l+c),t.closePath(),t.fill(),t.fillStyle="#ffffff";const f=c*.12,v=o+a-f/2;t.fillRect(v,l+c*.35,f,c*.35),t.beginPath(),t.arc(o+a,l+c*.82,f*.7,0,Math.PI*2),t.fill()}t.restore()},badge(r,o,l,c){t.save(),t.font=Tt;const b=t.measureText(r).width,f=8,T=12+3*2,y=b+f*2,H=T/2;t.fillStyle=c,t.beginPath(),t.roundRect(o,l,y,T,H),t.fill(),t.fillStyle="#ffffff",t.textAlign="center",t.textBaseline="middle",t.fillText(r,o+y/2,l+T/2),t.restore()}}}class sr{draw(e,r,o,l,c,a,b,f,v,T,y,H){const k=(r.visibleTimeEnd-r.visibleTimeStart)*.1,M=r.visibleTimeStart-k,I=r.visibleTimeEnd+k,W=c.query(M,I),S=new Map;for(let x=0;x<o.length;x++)S.set(o[x].id,x);const O=new Set(T),j=new Map,N=-r.lineHeight,z=r.canvasHeight+r.lineHeight;for(const x of W){const ie=S.get(x.group);if(ie===void 0)continue;const V=a.getLayout(x.id);if(!V)continue;const Z=r.groupIndexToY(ie)+V.stackLevel*r.lineHeight+(r.lineHeight-V.itemHeight)/2,te=V.itemHeight;if(Z+te<N||Z>z)continue;const ne=r.timeToX(x.start_time),me=r.timeToX(x.end_time)-ne,be={x:ne,y:Z,width:me,height:te};j.set(x.id,be);const Pe={selected:O.has(x.id),hovered:y===x.id,dragging:!1,filtered:x.filtered!==!1};e.save();const Ie=Ht(e,be);(f&&(x.type==="control_area_group"||x.type==="construction_train")?f:b)(e,x,be,Pe,Ie),e.restore()}H&&H.length>0&&this.drawDependencies(e,H,j,y,v)}drawDependencies(e,r,o,l,c){for(const a of r){const b=o.get(a.fromItemId),f=o.get(a.toItemId);if(!b||!f)continue;const v=l===a.fromItemId||l===a.toItemId;e.strokeStyle=v?c.primary:a.color??"#94A3B8",e.lineWidth=v?2:1.5,e.setLineDash([]);const T=b.x+b.width,y=b.y+b.height/2,H=f.x,k=f.y+f.height/2,M=Math.abs(H-T),I=Math.max(M*.4,30);e.beginPath(),e.moveTo(T,y),e.bezierCurveTo(T+I,y,H-I,k,H,k),e.stroke();const W=6;e.fillStyle=e.strokeStyle,e.beginPath(),e.moveTo(H,k),e.lineTo(H-W,k-W/2),e.lineTo(H-W,k+W/2),e.closePath(),e.fill()}}}class or{draw(e,r,o,l){const{cursorX:c,snapX:a,markers:b,interaction:f}=l;if(b)for(const v of b){const T=r.timeToX(v.date);if(e.fillStyle=v.color,e.fillRect(T-v.width/2,0,v.width,r.canvasHeight),v.label){e.save(),e.font='500 10px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif';const y=e.measureText(v.label).width,H=8,k=200,M=Math.min(y+H*2,k),I=20,W=T-M/2,S=4;e.fillStyle=v.color,e.beginPath(),e.roundRect(W,S,M,I,3),e.fill(),e.fillStyle="#FFFFFF",e.textBaseline="middle";const O=k-H*2,j=y>O?v.label.slice(0,Math.floor(v.label.length*O/y))+"…":v.label;e.fillText(j,W+H,S+I/2),e.restore()}}if(c!=null&&(e.strokeStyle=o.marker.cursor,e.lineWidth=1,e.beginPath(),e.moveTo(c,0),e.lineTo(c,r.canvasHeight),e.stroke()),a!=null&&(e.strokeStyle=o.primary,e.lineWidth=1,e.setLineDash([4,4]),e.beginPath(),e.moveTo(a,0),e.lineTo(a,r.canvasHeight),e.stroke(),e.setLineDash([])),f){f.groupChanged&&f.targetGroupY!==void 0&&(e.fillStyle="rgba(59, 130, 246, 0.08)",e.fillRect(0,f.targetGroupY,r.canvasWidth,r.lineHeight)),e.save(),e.globalAlpha=.5;const v=Ht(e,f.bounds);f.renderer(e,f.item,f.bounds,{selected:!1,hovered:!1,dragging:!0,filtered:!0},v),e.restore()}}}const kt=120;function lr(t){let e=t.deltaY||t.deltaX;return t.deltaMode===1?e*=15:t.deltaMode===2&&(e*=800),Math.max(-kt,Math.min(kt,e))}class ar{constructor(e,r,o,l,c){Object.defineProperty(this,"onZoom",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"visibleTimeStart",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"visibleTimeEnd",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"minZoom",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"maxZoom",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.onZoom=e,this.visibleTimeStart=r,this.visibleTimeEnd=o,this.minZoom=l,this.maxZoom=c}updateBounds(e,r){this.visibleTimeStart=e,this.visibleTimeEnd=r}handleWheelZoom(e,r){const o=lr(e),l=e.ctrlKey?10:e.metaKey?3:1,c=o>0?1+l*o/500:1/(1+l*-o/500),a=this.visibleTimeEnd-this.visibleTimeStart;let b=Math.round(a*c);b=Math.max(this.minZoom,Math.min(this.maxZoom,b));const f=Math.round(this.visibleTimeStart+(a-b)*r),v=f+b;this.onZoom(f,v)}}const ur=4;class cr{constructor(e){Object.defineProperty(this,"state",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"dragSnap",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"activated",{enumerable:!0,configurable:!0,writable:!0,value:!1}),this.dragSnap=e}startInteraction(e,r,o,l){this.state={item:e,mode:r,startX:o,startY:l,currentX:o,currentY:l,deltaX:0,originalGroup:e.group,currentGroup:e.group},this.activated=!1}update(e,r){this.state&&(this.state.currentX=e,this.state.currentY=r,this.state.deltaX=e-this.state.startX,!this.activated&&Math.abs(this.state.deltaX)>=ur&&(this.activated=!0))}setCurrentGroup(e){this.state&&(this.state.currentGroup=e)}endMove(e){if(!this.state)return null;const r=this.state.deltaX/e,o=this.state.item.start_time+r,l=Math.round(o/this.dragSnap)*this.dragSnap,c=this.state.currentGroup;return this.state=null,this.activated=!1,{newStartTime:l,newGroupId:c}}endResize(e){if(!this.state)return null;const r=this.state.deltaX/e,o=this.state.mode==="resize-left"?"left":"right",c=(o==="left"?this.state.item.start_time:this.state.item.end_time)+r,a=Math.round(c/this.dragSnap)*this.dragSnap;return this.state=null,this.activated=!1,{newTime:a,edge:o}}cancel(){this.state=null,this.activated=!1}getState(){return this.state}getMode(){var e;return((e=this.state)==null?void 0:e.mode)??null}isActive(){return this.state!==null&&this.activated}isPending(){return this.state!==null}}var Rt=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Dt(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var Pt={exports:{}};(function(t,e){(function(r,o){t.exports=o()})(Rt,function(){var r="day";return function(o,l,c){var a=function(v){return v.add(4-v.isoWeekday(),r)},b=l.prototype;b.isoWeekYear=function(){return a(this).year()},b.isoWeek=function(v){if(!this.$utils().u(v))return this.add(7*(v-this.isoWeek()),r);var T,y,H,k,M=a(this),I=(T=this.isoWeekYear(),y=this.$u,H=(y?c.utc:c)().year(T).startOf("year"),k=4-H.isoWeekday(),H.isoWeekday()>4&&(k+=7),H.add(k,r));return M.diff(I,"week")+1},b.isoWeekday=function(v){return this.$utils().u(v)?this.day()||7:this.day(this.day()%7?v:v-7)};var f=b.startOf;b.startOf=function(v,T){var y=this.$utils(),H=!!y.u(T)||T;return y.p(v)==="isoweek"?H?this.date(this.date()-(this.isoWeekday()-1)).startOf("day"):this.date(this.date()-1-(this.isoWeekday()-1)+7).endOf("day"):f.bind(this)(v,T)}}})})(Pt);var dr=Pt.exports;const fr=Dt(dr),wt=5;function Ct({groups:t,width:e,lineHeight:r,scrollTop:o,canvasHeight:l,theme:c,groupRenderer:a,onScroll:b}){var W;const f=u.useRef(null),v=u.useRef(!1),T=t.length*r,y=l,H=Math.max(0,Math.floor(o/r)-wt),k=Math.min(t.length-1,Math.ceil((o+l)/r)+wt),M=u.useCallback(S=>{v.current||b(S.currentTarget.scrollTop)},[b]);u.useEffect(()=>{f.current&&(v.current=!0,f.current.scrollTop=o,requestAnimationFrame(()=>{v.current=!1}))},[o]);const I=[];for(let S=H;S<=k;S++){const O=t[S];O&&I.push(X.jsx("div",{style:{position:"absolute",top:S*r,height:r,width:"100%",overflow:"hidden",display:"flex",alignItems:"stretch",borderBottom:`1px solid ${((W=c.grid)==null?void 0:W.line)??"#E5E5E5"}`,boxSizing:"border-box"},children:a(O)},O.id))}return X.jsx("div",{ref:f,onScroll:M,style:{width:e,height:y,overflowY:T>l?"auto":"hidden",overflowX:"hidden",position:"relative",borderRight:`1px solid ${c.sidebar.border}`,backgroundColor:c.sidebar.bg},children:X.jsx("div",{style:{height:T,position:"relative"},children:I})})}function It(t){return null}It.displayName="TodayMarker";function Et(t){return{date:Math.floor(Date.now()/6e4)*6e4,color:t.color??"#FD7171",width:t.width??6,label:t.label}}function hr(t){return t.interval??1e4}function Ot(t){return null}Ot.displayName="CustomMarker";function St(t){return{date:t.date,color:t.color??"#3B82F6",width:t.width??4,label:t.label}}ee.extend(fr);function mr(t){return t?{...ae,...t,status:{...ae.status,...t.status},grid:{...ae.grid,...t.grid},item:{...ae.item,...t.item},marker:{...ae.marker,...t.marker},sidebar:{...ae.sidebar,...t.sidebar},header:{...ae.header,...t.header}}:ae}const Mt=32,gr=u.memo(u.forwardRef(function(e,r){const{groups:o,items:l,defaultTimeStart:c,defaultTimeEnd:a,sidebarWidth:b,lineHeight:f,itemHeightRatio:v,stackItems:T,canMove:y,canChangeGroup:H,canResize:k,dragSnap:M,minZoom:I,maxZoom:W,theme:S,dayStyle:O,rowStyle:j,showCursorLine:N,itemRenderer:z,groupRenderer:x,sidebarGroupRenderer:ie,dependencies:V,onItemClick:Ce,onItemDoubleClick:Z,onItemContextMenu:te,onItemMove:ne,onItemResize:me,moveResizeValidator:be,onItemHover:Pe,onCanvasDoubleClick:Ie,onCanvasContextMenu:je,onTimeChange:et,onZoom:tt,selected:rt=[],rightSidebarWidth:Xe,rightSidebarGroupRenderer:it,onReady:Oe,children:ue}=e,ge=u.useMemo(()=>mr(S),[S]),nt=u.useCallback((s,i)=>{for(let d=0;d<i.length;d++)if(i[d].id===s)return d;return 0},[]),Xt=rt.join(","),Le=u.useMemo(()=>rt,[Xt]),st=u.useRef(null),ot=u.useRef(null),lt=u.useRef(null),Ee=u.useRef(null),at=u.useRef(null),Lt=u.useRef(null),[ut,_t]=u.useState({width:800,height:600});u.useEffect(()=>{const s=at.current;if(!s)return;const i=new ResizeObserver(d=>{const m=d[0];m&&_t({width:m.contentRect.width,height:m.contentRect.height})});return i.observe(s),()=>i.disconnect()},[]);const ce=Math.max(0,ut.width-b-(Xe??0)),de=o.length*f||ut.height,D=u.useRef(new Ue({visibleTimeStart:e.visibleTimeStart??c,visibleTimeEnd:e.visibleTimeEnd??a,canvasWidth:ce,canvasHeight:de,sidebarWidth:b,lineHeight:f,groupCount:o.length,buffer:e.buffer??3,scrollTop:0})),_e=u.useRef(null),Se=u.useRef(void 0),[ct,At]=u.useState(e.visibleTimeStart??c),[dt,Yt]=u.useState(e.visibleTimeEnd??a),[ft,Fe]=u.useState(0),Me=u.useRef(null),pe=u.useCallback(()=>{const s=D.current;At(s.visibleTimeStart),Yt(s.visibleTimeEnd),Fe(s.scrollTop),Me.current=null},[]),Ae=u.useCallback(()=>{Me.current===null&&(Me.current=setTimeout(pe,Mt))},[pe]);u.useEffect(()=>()=>{Me.current!==null&&clearTimeout(Me.current)},[]);const Ye=u.useMemo(()=>{const s=new tr;return s.buildFromItems(l,i=>i.start_time,i=>i.end_time),s},[l]),Ne=u.useMemo(()=>{const s=new rr(f,v);return s.computeLayout(l,T),s},[l,f,v,T]),ye=u.useMemo(()=>new nr,[]),Te=u.useMemo(()=>new sr,[]),ke=u.useMemo(()=>new or,[]),G=u.useMemo(()=>new cr(M),[M]),Be=u.useMemo(()=>{const s=[];return u.Children.forEach(ue,i=>{var m;if(!u.isValidElement(i))return;const d=(m=i.type)==null?void 0:m.displayName;d==="TodayMarker"?s.push(Et(i.props)):d==="CustomMarker"&&s.push(St(i.props))}),s},[ue]),We=u.useMemo(()=>Be.map(s=>`${s.date}|${s.color}|${s.width}|${s.label??""}`).join(";"),[Be]),He=u.useRef(Be);He.current=Be;const Ge=u.useMemo(()=>{let s=0;return u.Children.forEach(ue,i=>{var m;if(!u.isValidElement(i))return;((m=i.type)==null?void 0:m.displayName)==="TodayMarker"&&(s=hr(i.props))}),s},[ue]),F=u.useRef({groups:o,items:l,intervalTree:Ye,layoutEngine:Ne,itemRenderer:z,groupRenderer:x,theme:ge,selected:Le,dependencies:V,dayStyle:O,rowStyle:j,showCursorLine:N,canvasWidth:ce,canvasHeight:de,lineHeight:f,itemHeightRatio:v,onTimeChange:et,onZoom:tt,onItemHover:Pe,onItemClick:Ce,onItemDoubleClick:Z,onItemContextMenu:te,onItemMove:ne,onItemResize:me,onCanvasDoubleClick:Ie,onCanvasContextMenu:je,canMove:y,canResize:k,canChangeGroup:H,dragSnap:M,sidebarWidth:b,moveResizeValidator:be});F.current={groups:o,items:l,intervalTree:Ye,layoutEngine:Ne,itemRenderer:z,groupRenderer:x,theme:ge,selected:Le,dependencies:V,dayStyle:O,rowStyle:j,showCursorLine:N,canvasWidth:ce,canvasHeight:de,lineHeight:f,itemHeightRatio:v,onTimeChange:et,onZoom:tt,onItemHover:Pe,onItemClick:Ce,onItemDoubleClick:Z,onItemContextMenu:te,onItemMove:ne,onItemResize:me,onCanvasDoubleClick:Ie,onCanvasContextMenu:je,canMove:y,canResize:k,canChangeGroup:H,dragSnap:M,sidebarWidth:b,moveResizeValidator:be};const Nt=u.useCallback(()=>{const s=st.current;if(!s)return;const i=F.current,d=Je(s,i.canvasWidth,i.canvasHeight);Qe(d,s),ye.draw(d,D.current,i.groups,i.theme,i.dayStyle,i.rowStyle)},[ye]),Gt=u.useCallback(()=>{const s=ot.current;if(!s)return;const i=F.current,d=Je(s,i.canvasWidth,i.canvasHeight);Qe(d,s),Te.draw(d,D.current,i.groups,i.items,i.intervalTree,i.layoutEngine,i.itemRenderer,i.groupRenderer,i.theme,i.selected,Se.current,i.dependencies)},[Te]),ht=u.useCallback((s,i)=>{const d=D.current,m=F.current,n=m.canvasWidth/(d.visibleTimeEnd-d.visibleTimeStart),h=i/n,p=s.start_time+h,w=Math.round(p/m.dragSnap)*m.dragSnap;return d.timeToX(w)},[]),zt=u.useCallback(()=>{const s=lt.current;if(!s)return;const i=F.current,d=Je(s,i.canvasWidth,i.canvasHeight);Qe(d,s);const m=D.current,n=G.getState();let h=null;if(n){const p=m.timeToX(n.item.start_time),w=m.timeToX(n.item.end_time)-p;let R,P;n.mode==="resize-left"?(R=p+n.deltaX,P=w-n.deltaX):n.mode==="resize-right"?(R=p,P=w+n.deltaX):(R=p+n.deltaX,P=w);const _=nt(n.currentGroup,i.groups),$=m.groupIndexToY(_),A=n.currentGroup!==n.originalGroup;h={item:n.item,mode:n.mode,bounds:{x:R,y:$+(i.lineHeight-i.lineHeight*i.itemHeightRatio)/2,width:P,height:i.lineHeight*i.itemHeightRatio},renderer:i.itemRenderer,targetGroupY:$,groupChanged:A}}ke.draw(d,m,i.theme,{cursorX:i.showCursorLine?_e.current:null,snapX:n?ht(n.item,n.deltaX):null,markers:He.current,interaction:h})},[ke,G,ht,nt]),ze=u.useRef(null);ze.current||(ze.current=new ir(s=>{s.grid&&Nt(),s.items&&Gt(),s.overlay&&zt()}));const E=ze.current;u.useEffect(()=>()=>E.dispose(),[E]),u.useEffect(()=>{if(!Ge)return;const s=setInterval(()=>{const i=[];u.Children.forEach(ue,d=>{var n;if(!u.isValidElement(d))return;const m=(n=d.type)==null?void 0:n.displayName;m==="TodayMarker"?i.push(Et(d.props)):m==="CustomMarker"&&i.push(St(d.props))}),He.current=i,E.markDirty("overlay")},Ge);return()=>clearInterval(s)},[Ge,ue,E]),u.useEffect(()=>{D.current.update({canvasWidth:ce,canvasHeight:de,sidebarWidth:b,lineHeight:f,groupCount:o.length}),E.markAllDirty()},[ce,de,b,f,o.length,E]),u.useEffect(()=>{E.markDirty("grid"),E.markDirty("items")},[l,o,Le,ge,O,j,Ye,Ne,E]);const mt=u.useRef(We);u.useEffect(()=>{We!==mt.current&&(mt.current=We,E.markDirty("overlay"))},[We,E]);const gt=u.useRef(e.visibleTimeStart),vt=u.useRef(e.visibleTimeEnd);e.visibleTimeStart!==void 0&&e.visibleTimeStart!==gt.current&&(gt.current=e.visibleTimeStart,D.current.update({visibleTimeStart:e.visibleTimeStart}),E.markAllDirty()),e.visibleTimeEnd!==void 0&&e.visibleTimeEnd!==vt.current&&(vt.current=e.visibleTimeEnd,D.current.update({visibleTimeEnd:e.visibleTimeEnd}),E.markAllDirty());const Re=u.useRef(null),$e=u.useCallback(s=>{Re.current===null&&(Re.current=setTimeout(()=>{var m,n;Re.current=null;const i=D.current,d=F.current;s==="zoom"?(m=d.onZoom)==null||m.call(d,i.visibleTimeStart,i.visibleTimeEnd):(n=d.onTimeChange)==null||n.call(d,i.visibleTimeStart,i.visibleTimeEnd)},Mt))},[]);u.useEffect(()=>()=>{Re.current!==null&&clearTimeout(Re.current)},[]);const xe=u.useRef(null),Ve=u.useMemo(()=>new ar((s,i)=>{var d;D.current.update({visibleTimeStart:s,visibleTimeEnd:i}),(d=xe.current)==null||d.updateBounds(s,i),E.markAllDirty(),Ae(),$e("zoom")},c,a,I,W),[]);xe.current=Ve;const bt=u.useCallback(s=>{const i=D.current,d=i.groupCount*i.lineHeight,m=Math.max(0,d-i.canvasHeight),n=Math.max(0,Math.min(m,i.scrollTop+s));n!==i.scrollTop&&(i.update({scrollTop:n}),E.markDirty("grid"),E.markDirty("items"),E.markDirty("overlay"),Fe(n))},[E]),Ze=u.useCallback(s=>{var p,w,R;const i=D.current,d=i.canvasWidth/(i.visibleTimeEnd-i.visibleTimeStart),m=s/d,n=i.visibleTimeStart+m,h=i.visibleTimeEnd+m;i.update({visibleTimeStart:n,visibleTimeEnd:h}),(p=xe.current)==null||p.updateBounds(n,h),E.markAllDirty(),er.flushSync(()=>pe()),(R=(w=F.current).onTimeChange)==null||R.call(w,n,h)},[E,pe]);u.useEffect(()=>{const s=Ee.current;if(!s)return;const i=d=>{if(d.ctrlKey||d.metaKey||d.altKey){d.preventDefault();const m=s.getBoundingClientRect(),n=(d.clientX-m.left)/m.width;Ve.handleWheelZoom(d,n)}else if(d.shiftKey)d.preventDefault(),Ze(d.deltaY);else{const m=d.deltaX;m!==0&&Math.abs(m)>Math.abs(d.deltaY)?(d.preventDefault(),Ze(m)):d.deltaY!==0&&bt(d.deltaY)}};return s.addEventListener("wheel",i,{passive:!1}),()=>s.removeEventListener("wheel",i)},[Ve,bt,Ze]);const fe=u.useRef({lastDistance:null,lastCenter:null});u.useEffect(()=>{const s=Ee.current;if(!s)return;const i=(p,w)=>Math.abs(p.clientX-w.clientX),d=(p,w,R)=>(p.clientX+w.clientX)/2-R.left,m=p=>{p.touches.length===2&&(p.preventDefault(),fe.current.lastDistance=i(p.touches[0],p.touches[1]),fe.current.lastCenter=null)},n=p=>{var w;if(p.touches.length===2&&fe.current.lastDistance!==null){p.preventDefault();const R=i(p.touches[0],p.touches[1]),P=s.getBoundingClientRect(),$=d(p.touches[0],p.touches[1],P)/P.width;if(R!==0&&fe.current.lastDistance!==0){const A=fe.current.lastDistance/R,J=D.current,q=J.visibleTimeEnd-J.visibleTimeStart;let C=q*A;C=Math.max(I,Math.min(W,C));const g=J.visibleTimeStart+q*$,Q=g-C*$,L=g+C*(1-$);J.update({visibleTimeStart:Q,visibleTimeEnd:L}),(w=xe.current)==null||w.updateBounds(Q,L),E.markAllDirty(),Ae(),$e("zoom")}fe.current.lastDistance=R}},h=()=>{fe.current.lastDistance=null,fe.current.lastCenter=null};return s.addEventListener("touchstart",m,{passive:!1}),s.addEventListener("touchmove",n,{passive:!1}),s.addEventListener("touchend",h),()=>{s.removeEventListener("touchstart",m),s.removeEventListener("touchmove",n),s.removeEventListener("touchend",h)}},[E,Ae,$e]);const $t=u.useCallback(s=>{var R;const i=s.currentTarget,d=i.getBoundingClientRect(),m=s.clientX-d.left,n=s.clientY-d.top;if(_e.current=m,G.isPending()){if(G.update(m,n),G.isActive()){const P=G.getState();if(P&&P.mode==="move"&&F.current.canChangeGroup){const _=Ke(n,D.current,F.current.groups);_&&G.setCurrentGroup(_.id)}E.markDirty("overlay")}return}F.current.showCursorLine&&E.markDirty("overlay");const h=F.current,p=De(m,n,D.current,h.intervalTree,h.layoutEngine,h.groups),w=p==null?void 0:p.id;if(w!==Se.current&&(Se.current=w,E.markDirty("items"),(R=h.onItemHover)==null||R.call(h,w??null,s.nativeEvent)),p){const P=yt(m,p,D.current),_=h.canResize;P==="left"&&(_==="left"||_==="both")||P==="right"&&(_==="right"||_==="both")?i.style.cursor="col-resize":h.canMove?i.style.cursor="grab":i.style.cursor="default"}else i.style.cursor="default"},[G,E]),Vt=u.useCallback(s=>{const i=F.current,d=s.currentTarget.getBoundingClientRect(),m=s.clientX-d.left,n=s.clientY-d.top,h=De(m,n,D.current,i.intervalTree,i.layoutEngine,i.groups);if(!h)return;const p=yt(m,h,D.current),w=i.canResize;p==="left"&&(w==="left"||w==="both")?G.startInteraction(h,"resize-left",m,n):p==="right"&&(w==="right"||w==="both")?G.startInteraction(h,"resize-right",m,n):i.canMove&&G.startInteraction(h,"move",m,n)},[G]),Zt=u.useCallback(s=>{var p,w,R,P,_,$;const i=s.currentTarget;if(G.isActive()){const A=G.getState(),J=D.current,q=J.canvasWidth/(J.visibleTimeEnd-J.visibleTimeStart);if(A){const C=F.current.moveResizeValidator;if(A.mode==="move"){const g=G.endMove(q);if(g){const Q=C?C("move",A.item.id,g.newStartTime):g.newStartTime;(w=(p=F.current).onItemMove)==null||w.call(p,A.item.id,Q,g.newGroupId)}}else{const g=G.endResize(q);if(g){const Q=C?C("resize",A.item.id,g.newTime,g.edge):g.newTime;(P=(R=F.current).onItemResize)==null||P.call(R,A.item.id,Q,g.edge)}}}i.style.cursor="default",E.markDirty("overlay");return}G.isPending()&&G.cancel();const d=i.getBoundingClientRect(),m=s.clientX-d.left,n=s.clientY-d.top,h=De(m,n,D.current,F.current.intervalTree,F.current.layoutEngine,F.current.groups);h&&(($=(_=F.current).onItemClick)==null||$.call(_,h.id,s.nativeEvent))},[G,E]),qt=u.useCallback(s=>{var p,w;const i=s.currentTarget.getBoundingClientRect(),d=s.clientX-i.left,m=s.clientY-i.top,n=F.current,h=De(d,m,D.current,n.intervalTree,n.layoutEngine,n.groups);if(h)(p=n.onItemDoubleClick)==null||p.call(n,h.id,s.nativeEvent);else{const R=Ke(m,D.current,n.groups),P=D.current.xToTime(d);R&&((w=n.onCanvasDoubleClick)==null||w.call(n,R.id,P))}},[]),Ut=u.useCallback(s=>{var p,w;s.preventDefault();const i=s.currentTarget.getBoundingClientRect(),d=s.clientX-i.left,m=s.clientY-i.top,n=F.current,h=De(d,m,D.current,n.intervalTree,n.layoutEngine,n.groups);if(h)(p=n.onItemContextMenu)==null||p.call(n,h.id,s.nativeEvent);else{const R=Ke(m,D.current,n.groups),P=D.current.xToTime(d);R&&((w=n.onCanvasContextMenu)==null||w.call(n,R.id,P,s.nativeEvent))}},[]),Kt=u.useCallback(()=>{var s,i;_e.current=null,Ee.current&&(Ee.current.style.cursor="default"),Se.current!==void 0&&(Se.current=void 0,E.markDirty("items"),(i=(s=F.current).onItemHover)==null||i.call(s,null,new PointerEvent("pointerleave"))),F.current.showCursorLine&&E.markDirty("overlay")},[E]),Jt=u.useMemo(()=>{const s=[];return u.Children.forEach(ue,i=>{var m;if(!u.isValidElement(i))return;if(((m=i.type)==null?void 0:m.displayName)==="TimelineHeaders"){const n=i.props;s.push(u.cloneElement(i,{visibleTimeStart:n.visibleTimeStart??ct,visibleTimeEnd:n.visibleTimeEnd??dt,canvasWidth:n.canvasWidth??ce,sidebarWidth:n.sidebarWidth??b,theme:n.theme??ge,onZoomToInterval:n.onZoomToInterval??((h,p)=>{var w,R,P,_;D.current.update({visibleTimeStart:h,visibleTimeEnd:p}),E.markAllDirty(),pe(),(R=(w=F.current).onTimeChange)==null||R.call(w,h,p),(_=(P=F.current).onZoom)==null||_.call(P,h,p)})}))}}),s},[ue,ct,dt,ce,b,ge,E,pe]),pt=u.useRef(!1);u.useEffect(()=>{pt.current||(pt.current=!0,E.markAllDirty())},[E]),u.useImperativeHandle(r,()=>({captureToCanvas({timeStart:s,timeEnd:i,scale:d,sidebarWidth:m}){const n=F.current,h=28,p=h*3,w=n.groups.length*n.lineHeight,R=D.current,P=n.canvasWidth/(R.visibleTimeEnd-R.visibleTimeStart),_=i-s,$=Math.max(n.canvasWidth,Math.round(_*P)),A=(m+$)*d,J=(p+w)*d,q=document.createElement("canvas");q.width=A,q.height=J;const C=q.getContext("2d");C.scale(d,d);for(let L=0;L<n.groups.length;L++){const se=n.groups[L],oe=p+L*n.lineHeight;if(n.rowStyle){const Y=n.rowStyle(se);Y!=null&&Y.backgroundColor&&(C.fillStyle=Y.backgroundColor,C.fillRect(0,oe,m,n.lineHeight))}const B=se.type;let U="400",K=8;B==="project"?U="700":B==="CAG"?U="600":B==="CA"&&(U="400",K=24),C.fillStyle="#111",C.font=`${U} 12px sans-serif`,C.textBaseline="middle",C.fillText(se.title,K,oe+n.lineHeight/2,m-K-4)}const g=(L,se,oe)=>{var K,Y;C.fillStyle=((K=n.theme.header)==null?void 0:K.bg)??"#f5f5f5",C.fillRect(m,L,$,h),C.strokeStyle=((Y=n.theme.grid)==null?void 0:Y.line)??"#e0e0e0",C.lineWidth=1,C.strokeRect(m,L,$,h);let B=ee(s).startOf(oe);B.valueOf()<s&&(B=B.add(1,oe));const U=$/(i-s);for(;B.valueOf()<i;){const he=B.add(1,oe),re=m+(B.valueOf()-s)*U,le=m+(Math.min(he.valueOf(),i)-s)*U-re;C.beginPath(),C.moveTo(re,L),C.lineTo(re,L+h),C.stroke(),C.fillStyle="#333",C.font="600 11px sans-serif",C.textBaseline="middle",C.textAlign="center",C.fillText(se(B),re+le/2,L+h/2,le-4),B=he}C.textAlign="start"};g(0,L=>L.format("YYYY"),"year"),g(h,L=>L.format("MM"),"month"),g(h*2,L=>String(L.isoWeek()),"week");const Q=new Ue({visibleTimeStart:s,visibleTimeEnd:i,canvasWidth:$,canvasHeight:w,sidebarWidth:0,lineHeight:n.lineHeight,groupCount:n.groups.length,buffer:1,scrollTop:0});return C.save(),C.translate(m,p),C.beginPath(),C.rect(0,0,$,w),C.clip(),ye.draw(C,Q,n.groups,n.theme,n.dayStyle,n.rowStyle),Te.draw(C,Q,n.groups,n.items,n.intervalTree,n.layoutEngine,n.itemRenderer,n.groupRenderer,n.theme,n.selected,void 0,n.dependencies),ke.draw(C,Q,n.theme,{cursorX:null,snapX:null,markers:He.current,interaction:null}),C.restore(),q}}),[ye,Te,ke]),u.useEffect(()=>{const s={captureToCanvas({timeStart:i,timeEnd:d,scale:m,sidebarWidth:n}){var oe;const h=F.current,p=28,w=p*3,R=h.groups.length*h.lineHeight,P=D.current,_=h.canvasWidth/(P.visibleTimeEnd-P.visibleTimeStart),$=d-i,A=Math.max(h.canvasWidth,Math.round($*_)),J=n+A,q=w+R,C=document.createElement("canvas");C.width=J*m,C.height=q*m;const g=C.getContext("2d");g.scale(m,m),g.fillStyle="#FFFFFF",g.fillRect(0,0,J,q),g.save(),g.beginPath(),g.rect(0,0,n,q),g.clip(),g.fillStyle="#F9FAFB",g.fillRect(0,0,n,w),g.strokeStyle="#E5E7EB",g.lineWidth=1,g.strokeRect(0,0,n,w);for(let B=0;B<h.groups.length;B++){const U=h.groups[B],K=w+B*h.lineHeight,Y=(oe=h.rowStyle)==null?void 0:oe.call(h,U);g.fillStyle=(Y==null?void 0:Y.backgroundColor)??(B%2===0?"#FFFFFF":"#F7F7F7"),g.fillRect(0,K,n,h.lineHeight),g.strokeStyle="#E5E5E5",g.lineWidth=.5,g.beginPath(),g.moveTo(0,K+h.lineHeight),g.lineTo(n,K+h.lineHeight),g.stroke();const he=U.type??"";let re=8,ve="400",le=11;he==="project"?(ve="700",le=12):he==="control_area_group"?ve="600":he==="control_area"&&(re=24),g.fillStyle="#374151",g.font=`${ve} ${le}px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif`,g.textBaseline="middle";const we=typeof U.title=="string"?U.title:String(U.title);g.fillText(we,re,K+h.lineHeight/2,n-re-8)}g.strokeStyle="#E5E7EB",g.lineWidth=1,g.beginPath(),g.moveTo(n,0),g.lineTo(n,q),g.stroke(),g.restore(),g.save(),g.beginPath(),g.rect(n,0,A,w),g.clip();const Q=d-i,L=[{unit:"year",row:0},{unit:"month",row:1},{unit:"week",row:2}];for(const{unit:B,row:U}of L){const K=U*p;g.fillStyle="#F9FAFB",g.fillRect(n,K,A,p);let Y=ee(i).startOf(B);const he=ee(d).add(1,B);for(;Y.isBefore(he);){const re=Y.add(1,B),ve=n+(Y.valueOf()-i)/Q*A,le=(re.valueOf()-Y.valueOf())/Q*A;g.strokeStyle="#E5E7EB",g.lineWidth=.5,g.strokeRect(ve,K,le,p);let we;B==="year"?we=Y.format("YYYY"):B==="month"?we=Y.format("MM"):we=`${Y.week()}`,g.fillStyle="#6c737f",g.font=B==="year"?'600 11px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif':'400 11px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',g.textBaseline="middle",g.textAlign="center",le>20&&g.fillText(we,ve+le/2,K+p/2),Y=re}}g.textAlign="start",g.restore(),g.save(),g.beginPath(),g.rect(n,w,A,R),g.clip(),g.translate(n,w);const se=new Ue({visibleTimeStart:i,visibleTimeEnd:d,canvasWidth:A,canvasHeight:R,sidebarWidth:0,lineHeight:h.lineHeight,groupCount:h.groups.length,buffer:1,scrollTop:0});return ye.draw(g,se,h.groups,h.theme,h.dayStyle,h.rowStyle),Te.draw(g,se,h.groups,h.items,h.intervalTree,h.layoutEngine,h.itemRenderer,h.groupRenderer,h.theme,h.selected,void 0,h.dependencies),ke.draw(g,se,h.theme,{cursorX:null,markers:He.current}),g.restore(),C}};Oe==null||Oe(s)},[Oe,ye,Te,ke]);const Qt={position:"relative",width:ce,height:de,overflow:"hidden",cursor:"default"},qe={position:"absolute",top:0,left:0};return X.jsxs("div",{ref:at,style:{display:"flex",flexDirection:"column",width:"100%"},children:[Jt,X.jsxs("div",{ref:Lt,style:{display:"flex",overflow:"hidden"},children:[X.jsx(Ct,{groups:o,width:b,lineHeight:f,scrollTop:ft,canvasHeight:de,theme:ge,groupRenderer:ie,onScroll:s=>{D.current.update({scrollTop:s}),E.markDirty("grid"),E.markDirty("items"),E.markDirty("overlay"),Fe(s)}}),X.jsxs("div",{ref:Ee,style:Qt,onPointerMove:$t,onPointerDown:Vt,onPointerUp:Zt,onDoubleClick:qt,onContextMenu:Ut,onPointerLeave:Kt,children:[X.jsx("canvas",{ref:st,style:{...qe,zIndex:0}}),X.jsx("canvas",{ref:ot,style:{...qe,zIndex:1}}),X.jsx("canvas",{ref:lt,style:{...qe,zIndex:2}})]}),Xe&&it?X.jsx(Ct,{groups:o,width:Xe,lineHeight:f,scrollTop:ft,canvasHeight:de,theme:ge,groupRenderer:it,onScroll:s=>{D.current.update({scrollTop:s}),E.markDirty("grid"),E.markDirty("items"),E.markDirty("overlay"),Fe(s)}}):null]})]})}));function Ft({children:t,theme:e,className:r,classNames:o,style:l,visibleTimeStart:c,visibleTimeEnd:a,canvasWidth:b,sidebarWidth:f=0,onZoomToInterval:v}){const T=u.Children.map(t,y=>{var k;if(!u.isValidElement(y))return y;if(((k=y.type)==null?void 0:k.displayName)==="DateHeader"){const M=y.props,I=u.cloneElement(y,{visibleTimeStart:M.visibleTimeStart??c,visibleTimeEnd:M.visibleTimeEnd??a,canvasWidth:M.canvasWidth??b,theme:M.theme??e,onZoomToInterval:M.onIntervalClick??M.onZoomToInterval??v});return X.jsxs("div",{style:{display:"flex"},children:[X.jsx("div",{style:{width:f,flexShrink:0}}),X.jsx("div",{style:{flex:1,overflow:"hidden"},children:I})]})}return y});return X.jsx("div",{className:r,style:{position:"sticky",top:0,zIndex:20,display:"flex",flexDirection:"column",backgroundColor:(e==null?void 0:e.header.bg)??"#F9FAFB",borderTop:`1px solid ${(e==null?void 0:e.header.border)??"#E5E7EB"}`,borderBottom:`1px solid ${(e==null?void 0:e.header.border)??"#E5E7EB"}`,...l},children:T})}Ft.displayName="TimelineHeaders";var Bt={exports:{}};(function(t,e){(function(r,o){t.exports=o()})(Rt,function(){var r="week",o="year";return function(l,c,a){var b=c.prototype;b.week=function(f){if(f===void 0&&(f=null),f!==null)return this.add(7*(f-this.week()),"day");var v=this.$locale().yearStart||1;if(this.month()===11&&this.date()>25){var T=a(this).startOf(o).add(1,o).date(v),y=a(this).endOf(r);if(T.isBefore(y))return 1}var H=a(this).startOf(o).date(v).startOf(r).subtract(1,"millisecond"),k=this.diff(H,r,!0);return k<0?a(this).startOf("week").week():Math.ceil(k)},b.weeks=function(f){return f===void 0&&(f=null),this.week(f)}}})})(Bt);var vr=Bt.exports;const br=Dt(vr);ee.extend(br);const pr={year:30,month:30,week:20,day:15,hour:30};function Wt({unit:t,visibleTimeStart:e=0,visibleTimeEnd:r=0,canvasWidth:o=0,theme:l,height:c=28,className:a,labelFormat:b,onIntervalClick:f,minCellWidth:v,onZoomToInterval:T}){const y=u.useMemo(()=>{if(!e||!r||!o)return[];const k=r-e,M=v??pr[t];if(M>0){const O=ee(e).startOf(t);if((O.add(1,t).valueOf()-O.valueOf())/k*o<M)return[]}const I=[];let W=ee(e).startOf(t).subtract(1,t);const S=ee(r).add(2,t).valueOf();for(;W.valueOf()<S;){const O=W.add(1,t),j=W.valueOf(),N=O.valueOf(),z=(j-e)/k*o,x=(N-j)/k*o,ie=yr(W,O,t,b);I.push({start:j,end:N,label:ie,left:z,width:x}),W=O}return I},[e,r,o,t,b,v]),H=u.useCallback((k,M)=>{f?f(k,M):T&&T(k,M)},[f,T]);return y.length===0?null:X.jsx("div",{style:{display:"flex",position:"relative",height:c,overflow:"hidden"},children:y.map(k=>X.jsx("div",{className:a,onClick:()=>H(k.start,k.end),style:{position:"absolute",left:k.left,width:k.width,height:"100%",display:"flex",alignItems:"center",justifyContent:"center",borderRight:`1px solid ${(l==null?void 0:l.header.border)??"#E5E7EB"}`,borderBottom:`1px solid ${(l==null?void 0:l.header.border)??"#E5E7EB"}`,fontSize:12,color:(l==null?void 0:l.header.text)??"#6c737f",backgroundColor:(l==null?void 0:l.header.bg)??"#F9FAFB",overflow:"hidden",whiteSpace:"nowrap",cursor:"pointer",userSelect:"none",padding:"0 4px",boxSizing:"border-box"},children:X.jsx("span",{children:k.label})},k.start))})}Wt.displayName="DateHeader";function yr(t,e,r,o,l){return typeof o=="function"?o(t.toDate(),e.toDate(),r):typeof o=="string"?t.format(o):Tr(t,r)}function Tr(t,e){switch(e){case"year":return t.format("YYYY");case"month":return t.format("MM");case"week":return`${t.week()}`;case"day":return t.format("D");case"hour":return t.format("HH:mm")}}function xt({width:t,children:e,style:r}){const o=()=>({style:{width:t,...r}});return e?X.jsx(X.Fragment,{children:e({getRootProps:o})}):X.jsx("div",{style:{width:t}})}xt.displayName="SidebarHeader";function jt({children:t}){return X.jsx(X.Fragment,{children:t})}jt.displayName="CustomHeader";exports.CanvasTimeline=gr;exports.CustomHeader=jt;exports.CustomMarker=Ot;exports.DEFAULT_THEME=ae;exports.DateHeader=Wt;exports.SidebarHeader=xt;exports.TimelineHeaders=Ft;exports.TodayMarker=It;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const V=require("react/jsx-runtime"),c=require("react"),si=require("react-dom"),ce=require("dayjs"),he={primary:"#269bf7",trainColors:{},status:{red:"#EF5350",yellow:"#FBBF24",green:"#31c48d"},grid:{line:"#E5E5E5",rowAlt:"#F7F7F7",weekend:"rgba(0,0,0,0.03)"},item:{radius:3,text:"#374151",selectedRing:"#a3a3a3"},marker:{today:"#FD7171",milestone:"#3B82F6",cursor:"#269bf7"},sidebar:{bg:"#F9FAFB",border:"#E5E7EB",text:"#6c737f"},header:{bg:"#F9FAFB",border:"#E5E7EB",text:"#6c737f"}};class Je{constructor(e){Object.defineProperty(this,"visibleTimeStart",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"visibleTimeEnd",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"canvasWidth",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"canvasHeight",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"sidebarWidth",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"lineHeight",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"groupCount",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"buffer",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"scrollTop",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"visibleDuration",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"pixelsPerMs",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.visibleTimeStart=e.visibleTimeStart,this.visibleTimeEnd=e.visibleTimeEnd,this.canvasWidth=e.canvasWidth,this.canvasHeight=e.canvasHeight,this.sidebarWidth=e.sidebarWidth,this.lineHeight=e.lineHeight,this.groupCount=e.groupCount,this.buffer=e.buffer,this.scrollTop=e.scrollTop,this.visibleDuration=this.visibleTimeEnd-this.visibleTimeStart,this.pixelsPerMs=this.canvasWidth/this.visibleDuration}update(e){e.visibleTimeStart!==void 0&&(this.visibleTimeStart=e.visibleTimeStart),e.visibleTimeEnd!==void 0&&(this.visibleTimeEnd=e.visibleTimeEnd),e.canvasWidth!==void 0&&(this.canvasWidth=e.canvasWidth),e.canvasHeight!==void 0&&(this.canvasHeight=e.canvasHeight),e.sidebarWidth!==void 0&&(this.sidebarWidth=e.sidebarWidth),e.lineHeight!==void 0&&(this.lineHeight=e.lineHeight),e.groupCount!==void 0&&(this.groupCount=e.groupCount),e.buffer!==void 0&&(this.buffer=e.buffer),e.scrollTop!==void 0&&(this.scrollTop=e.scrollTop),this.visibleDuration=this.visibleTimeEnd-this.visibleTimeStart,this.pixelsPerMs=this.canvasWidth/this.visibleDuration}timeToX(e){return(e-this.visibleTimeStart)*this.pixelsPerMs}xToTime(e){return this.visibleTimeStart+e/this.pixelsPerMs}yToGroupIndex(e){const t=Math.floor((e+this.scrollTop)/this.lineHeight);return Math.max(0,Math.min(t,this.groupCount-1))}groupIndexToY(e){return e*this.lineHeight-this.scrollTop}getBufferBounds(){const e=this.visibleDuration*1.5;return{bufferStart:this.visibleTimeStart-e,bufferEnd:this.visibleTimeEnd+e}}getVisibleGroupRange(){const e=Math.max(0,Math.floor(this.scrollTop/this.lineHeight)),t=Math.ceil(this.canvasHeight/this.lineHeight),o=Math.min(this.groupCount-1,e+t);return{firstVisible:e,lastVisible:o}}isScrollInBuffer(e){const t=this.visibleDuration*1.5*this.pixelsPerMs;return Math.abs(e)<t}getTotalHeight(){return this.groupCount*this.lineHeight}}class oi{constructor(){Object.defineProperty(this,"root",{enumerable:!0,configurable:!0,writable:!0,value:null})}buildFromItems(e,t,o){const l=e.map(u=>({item:u,start:t(u),end:o(u)}));this.root=this.buildNode(l)}buildNode(e){if(e.length===0)return null;let t=1/0,o=-1/0;for(const d of e)d.start<t&&(t=d.start),d.end>o&&(o=d.end);const l=(t+o)/2,u=[],a=[],g=[];for(const d of e)d.end<l?u.push(d):d.start>l?a.push(d):g.push(d);return{center:l,left:this.buildNode(u),right:this.buildNode(a),overlapping:g}}query(e,t){const o=[];return this.queryNode(this.root,e,t,o),o}queryNode(e,t,o,l){if(e!==null){for(const u of e.overlapping)u.start<=o&&u.end>=t&&l.push(u.item);t<=e.center&&e.left!==null&&this.queryNode(e.left,t,o,l),o>=e.center&&e.right!==null&&this.queryNode(e.right,t,o,l)}}}class li{constructor(e,t){Object.defineProperty(this,"lineHeight",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"itemHeightRatio",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"layoutCache",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"groupMaxStack",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),this.lineHeight=e,this.itemHeightRatio=t}computeLayout(e,t){if(this.layoutCache=new Map,this.groupMaxStack=new Map,!t){const u=this.lineHeight*this.itemHeightRatio;for(const a of e)this.layoutCache.set(a.id,{stackLevel:0,itemHeight:u}),this.groupMaxStack.set(a.group,0);return this.layoutCache}const o=new Map;for(const u of e){let a=o.get(u.group);a||(a=[],o.set(u.group,a)),a.push(u)}const l=this.lineHeight*this.itemHeightRatio;for(const[u,a]of o){a.sort((v,k)=>{const y=v.start_time-k.start_time;return y!==0?y:k.end_time-k.start_time-(v.end_time-v.start_time)});const g=[];let d=0;for(const v of a){let k=-1;for(let y=0;y<g.length;y++)if(g[y]<=v.start_time){k=y;break}k===-1?(k=g.length,g.push(v.end_time)):g[k]=v.end_time,k>d&&(d=k),this.layoutCache.set(v.id,{stackLevel:k,itemHeight:l})}this.groupMaxStack.set(u,d)}return this.layoutCache}getLayout(e){return this.layoutCache.get(e)}getGroupHeight(e){return((this.groupMaxStack.get(e)??0)+1)*this.lineHeight}}function De(i,e,t,o,l,u){const a=t.xToTime(i),g=new Map;for(let y=0;y<u.length;y++)g.set(u[y].id,y);const d=o.query(a,a);let v=null,k=-1/0;for(const y of d){const H=g.get(y.group);if(H===void 0)continue;const E=l.getLayout(y.id);if(!E)continue;const I=t.timeToX(y.start_time),B=t.timeToX(y.end_time)-I;if(i<I||i>I+B)continue;const Y=t.groupIndexToY(H)+E.stackLevel*t.lineHeight+(t.lineHeight-E.itemHeight)/2,T=E.itemHeight;e<Y||e>Y+T||Y>k&&(k=Y,v=y)}return v}function Qe(i,e,t){const o=e.yToGroupIndex(i);return t[o]??null}function Et(i,e,t,o=6){const l=t.timeToX(e.start_time),u=t.timeToX(e.end_time);return i-l<=o?"left":u-i<=o?"right":"body"}function et(i,e,t){const o=window.devicePixelRatio||1,l=Math.round(e*o),u=Math.round(t*o);(i.width!==l||i.height!==u)&&(i.width=l,i.height=u,i.style.width=`${e}px`,i.style.height=`${t}px`);const a=i.getContext("2d");return a.setTransform(o,0,0,o,0,0),a}function tt(i,e){const t=window.devicePixelRatio||1;i.clearRect(0,0,e.width/t,e.height/t)}class ai{constructor(e){Object.defineProperty(this,"dirty",{enumerable:!0,configurable:!0,writable:!0,value:{grid:!1,items:!1,overlay:!1}}),Object.defineProperty(this,"rafId",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"drawCallback",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.drawCallback=e}markDirty(e){this.dirty[e]=!0,this.schedule()}markAllDirty(){this.dirty.grid=!0,this.dirty.items=!0,this.dirty.overlay=!0,this.schedule()}dispose(){this.rafId!==null&&(cancelAnimationFrame(this.rafId),this.rafId=null)}schedule(){this.rafId===null&&(this.rafId=requestAnimationFrame(()=>{this.rafId=null;const e={...this.dirty};this.dirty.grid=!1,this.dirty.items=!1,this.dirty.overlay=!1,this.drawCallback(e)}))}}class ui{draw(e,t,o,l,u,a,g){const{firstVisible:d,lastVisible:v}=t.getVisibleGroupRange();for(let T=d;T<=v;T++){const P=t.groupIndexToY(T),_=o[T];if(!_)continue;let N;const w=a==null?void 0:a(_);w!=null&&w.backgroundColor?N=w.backgroundColor:N=T%2===0?"#FFFFFF":l.grid.rowAlt,e.fillStyle=N,e.fillRect(0,P,t.canvasWidth,t.lineHeight),e.strokeStyle=(w==null?void 0:w.borderBottomColor)??l.grid.line,e.lineWidth=.5,e.beginPath(),e.moveTo(0,P+t.lineHeight),e.lineTo(t.canvasWidth,P+t.lineHeight),e.stroke()}if(g&&g.length>0)for(const T of g){const P=t.timeToX(T.start),_=t.timeToX(T.end);if(_<0||P>t.canvasWidth)continue;const N=Math.max(0,P),w=Math.min(t.canvasWidth,_)-N,A=T.opacity??.12,Z=parseInt(T.color.slice(1,3),16),q=parseInt(T.color.slice(3,5),16),re=parseInt(T.color.slice(5,7),16);e.fillStyle=`rgb(${Math.round(Z*A+255*(1-A))},${Math.round(q*A+255*(1-A))},${Math.round(re*A+255*(1-A))})`,e.fillRect(N,0,w,t.canvasHeight)}const k=t.visibleTimeStart,y=t.visibleTimeEnd,I=864e5/(y-k)*t.canvasWidth;let B="day";I<2?B="month":I<8&&(B="week");{let T=ce(k).startOf("day");const P=ce(y).endOf("day");let _=null,N=1,w=0;const A=[],Z=q=>{_!==null&&(e.fillStyle=_,N!==1&&(e.globalAlpha=N),e.fillRect(w,0,q-w,t.canvasHeight),N!==1&&(e.globalAlpha=1),_=null,N=1)};for(;T.isBefore(P);){const q=t.timeToX(T.valueOf()),re=T.toDate(),G=u==null?void 0:u(re);let oe=null,fe=1;if(G!=null&&G.backgroundColor)oe=G.backgroundColor,fe=G.opacity??1;else{const ue=T.day();(ue===0||ue===6)&&(oe=l.grid.weekend)}G!=null&&G.borderColor&&A.push({x:q,color:G.borderColor}),oe===_&&fe===N||(Z(q),oe!==null&&(_=oe,N=fe,w=q)),T=T.add(1,"day")}_!==null&&Z(t.timeToX(T.valueOf()));for(const q of A)e.strokeStyle=q.color,e.lineWidth=.5,e.beginPath(),e.moveTo(q.x,0),e.lineTo(q.x,t.canvasHeight),e.stroke()}let x=ce(k).startOf(B);const Y=ce(y).add(1,B);for(e.strokeStyle=l.grid.line,e.lineWidth=.5,e.beginPath();x.isBefore(Y);){const T=t.timeToX(x.valueOf());e.moveTo(T,0),e.lineTo(T,t.canvasHeight),x=x.add(1,B)}if(e.stroke(),g&&g.length>0)for(const T of g){const P=t.timeToX(T.start),_=t.timeToX(T.end);if(!(_<0||P>t.canvasWidth)&&(e.strokeStyle=T.color,e.globalAlpha=.4,e.lineWidth=1,e.beginPath(),P>=0&&P<=t.canvasWidth&&(e.moveTo(P,0),e.lineTo(P,t.canvasHeight)),_>=0&&_<=t.canvasWidth&&(e.moveTo(_,0),e.lineTo(_,t.canvasHeight)),e.stroke(),e.globalAlpha=1,T.label)){const N=Math.max(0,P),w=Math.min(t.canvasWidth,_)-N;e.save(),e.font='600 10px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif';const A=e.measureText(T.label).width,Z=6,q=A+Z*2,re=18,G=N+(w-q)/2,oe=4;e.fillStyle=T.color,e.globalAlpha=.9,e.beginPath(),e.roundRect(G,oe,q,re,3),e.fill(),e.globalAlpha=1,e.fillStyle="#FFFFFF",e.textBaseline="middle",e.fillText(T.label,G+Z,oe+re/2),e.restore()}}}}const Mt='500 12px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif';function Pt(i,e){return{roundRect(t,o,l,u,a=3){i.beginPath(),i.roundRect(t,o,l,u,a),i.fill()},fillText(t,o,l,u){if(i.font=Mt,u!==void 0&&i.measureText(t).width>u){let a=0,g=t.length;for(;a<g;){const d=Math.ceil((a+g)/2),v=t.slice(0,d)+"...";i.measureText(v).width<=u?a=d:g=d-1}i.fillText(t.slice(0,a)+"...",o,l)}else i.fillText(t,o,l)},gradient(t,o,l,u){const a=i.createLinearGradient(t,0,t+o,0);return a.addColorStop(0,l),a.addColorStop(.5,l),a.addColorStop(.5,u),a.addColorStop(1,u),a},leftBar(t,o=3){e&&(i.save(),i.fillStyle=t,i.fillRect(e.x,e.y,o,e.height),i.restore())},icon(t,o,l,u=14){i.save();const a=u/2;if(t==="check"){i.fillStyle="#31c48d",i.beginPath(),i.arc(o+a,l+a,a,0,Math.PI*2),i.fill(),i.strokeStyle="#ffffff",i.lineWidth=u*.12,i.beginPath();const g=o+a,d=l+a;i.moveTo(g-a*.45,d),i.lineTo(g-a*.1,d+a*.42),i.lineTo(g+a*.45,d-a*.35),i.stroke()}else if(t==="danger-red"||t==="danger-yellow"){const g=t==="danger-red"?"#EF5350":"#FBBF24";i.fillStyle=g,i.beginPath(),i.moveTo(o+a,l),i.lineTo(o+u,l+u),i.lineTo(o,l+u),i.closePath(),i.fill(),i.fillStyle="#ffffff";const d=u*.12,v=o+a-d/2;i.fillRect(v,l+u*.35,d,u*.35),i.beginPath(),i.arc(o+a,l+u*.82,d*.7,0,Math.PI*2),i.fill()}i.restore()},badge(t,o,l,u){i.save(),i.font=Mt;const g=i.measureText(t).width,d=8,k=12+3*2,y=g+d*2,H=k/2;i.fillStyle=u,i.beginPath(),i.roundRect(o,l,y,k,H),i.fill(),i.fillStyle="#ffffff",i.textAlign="center",i.textBaseline="middle",i.fillText(t,o+y/2,l+k/2),i.restore()}}}class ci{draw(e,t,o,l,u,a,g,d,v,k,y,H){const E=(t.visibleTimeEnd-t.visibleTimeStart)*.1,I=t.visibleTimeStart-E,B=t.visibleTimeEnd+E,x=u.query(I,B),Y=new Map;for(let w=0;w<o.length;w++)Y.set(o[w].id,w);const T=new Set(k),P=new Map,_=-t.lineHeight,N=t.canvasHeight+t.lineHeight;for(const w of x){const A=Y.get(w.group);if(A===void 0)continue;const Z=a.getLayout(w.id);if(!Z)continue;const re=t.groupIndexToY(A)+Z.stackLevel*t.lineHeight+(t.lineHeight-Z.itemHeight)/2,G=Z.itemHeight;if(re+G<_||re>N)continue;const oe=t.timeToX(w.start_time),fe=t.timeToX(w.end_time)-oe,ue={x:oe,y:re,width:fe,height:G};P.set(w.id,ue);const Te={selected:T.has(w.id),hovered:y===w.id,dragging:!1,filtered:w.filtered!==!1};e.save();const Pe=Pt(e,ue);(d&&(w.type==="control_area_group"||w.type==="construction_train")?d:g)(e,w,ue,Te,Pe),e.restore()}if(H&&H.length>0){const w=new Set;for(const A of H)P.has(A.fromItemId)||w.add(A.fromItemId),P.has(A.toItemId)||w.add(A.toItemId);if(w.size>0){const A=new Map;for(const Z of l)w.has(Z.id)&&A.set(Z.id,Z);for(const[Z,q]of A){const re=Y.get(q.group);if(re===void 0)continue;const G=a.getLayout(Z);if(!G)continue;const fe=t.groupIndexToY(re)+G.stackLevel*t.lineHeight+(t.lineHeight-G.itemHeight)/2,ue=t.timeToX(q.start_time),Te=t.timeToX(q.end_time)-ue;P.set(Z,{x:ue,y:fe,width:Te,height:G.itemHeight})}}this.drawDependencies(e,H,P,y,v)}}drawDependencies(e,t,o,l,u){for(const a of t){const g=o.get(a.fromItemId),d=o.get(a.toItemId);if(!g||!d)continue;const v=l===a.fromItemId||l===a.toItemId;e.strokeStyle=v?u.primary:a.color??"#94A3B8",e.lineWidth=v?2:1.5,e.setLineDash([]);const k=g.x+g.width,y=g.y+g.height/2,H=d.x,E=d.y+d.height/2,I=Math.abs(H-k),B=Math.max(I*.4,30);e.beginPath(),e.moveTo(k,y),e.bezierCurveTo(k+B,y,H-B,E,H,E),e.stroke();const x=6;e.fillStyle=e.strokeStyle,e.beginPath(),e.moveTo(H,E),e.lineTo(H-x,E-x/2),e.lineTo(H-x,E+x/2),e.closePath(),e.fill()}}}class di{draw(e,t,o,l){const{cursorX:u,snapX:a,markers:g,interaction:d}=l;if(g)for(const v of g){const k=t.timeToX(v.date);if(e.fillStyle=v.color,e.fillRect(k-v.width/2,0,v.width,t.canvasHeight),v.label){e.save(),e.font='500 10px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif';const y=e.measureText(v.label).width,H=8,E=200,I=Math.min(y+H*2,E),B=20,x=k-I/2,Y=4;e.fillStyle=v.color,e.beginPath(),e.roundRect(x,Y,I,B,3),e.fill(),e.fillStyle="#FFFFFF",e.textBaseline="middle";const T=E-H*2,P=y>T?v.label.slice(0,Math.floor(v.label.length*T/y))+"…":v.label;e.fillText(P,x+H,Y+B/2),e.restore()}}if(u!=null&&(e.strokeStyle=o.marker.cursor,e.lineWidth=1,e.beginPath(),e.moveTo(u,0),e.lineTo(u,t.canvasHeight),e.stroke()),a!=null&&(e.strokeStyle=o.primary,e.lineWidth=1,e.setLineDash([4,4]),e.beginPath(),e.moveTo(a,0),e.lineTo(a,t.canvasHeight),e.stroke(),e.setLineDash([])),d){d.groupChanged&&d.targetGroupY!==void 0&&(e.fillStyle="rgba(59, 130, 246, 0.08)",e.fillRect(0,d.targetGroupY,t.canvasWidth,t.lineHeight)),e.save(),e.globalAlpha=.5;const v=Pt(e,d.bounds);d.renderer(e,d.item,d.bounds,{selected:!1,hovered:!1,dragging:!0,filtered:!0},v),e.restore()}}}const Ct=120;function fi(i){let e=i.deltaY||i.deltaX;return i.deltaMode===1?e*=15:i.deltaMode===2&&(e*=800),Math.max(-Ct,Math.min(Ct,e))}class hi{constructor(e,t,o,l,u){Object.defineProperty(this,"onZoom",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"visibleTimeStart",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"visibleTimeEnd",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"minZoom",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"maxZoom",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.onZoom=e,this.visibleTimeStart=t,this.visibleTimeEnd=o,this.minZoom=l,this.maxZoom=u}updateBounds(e,t){this.visibleTimeStart=e,this.visibleTimeEnd=t}handleWheelZoom(e,t){const o=fi(e),l=e.ctrlKey?10:e.metaKey?3:1,u=o>0?1+l*o/500:1/(1+l*-o/500),a=this.visibleTimeEnd-this.visibleTimeStart;let g=Math.round(a*u);g=Math.max(this.minZoom,Math.min(this.maxZoom,g));const d=Math.round(this.visibleTimeStart+(a-g)*t),v=d+g;this.onZoom(d,v)}}const mi=4;class gi{constructor(e){Object.defineProperty(this,"state",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"dragSnap",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"activated",{enumerable:!0,configurable:!0,writable:!0,value:!1}),this.dragSnap=e}startInteraction(e,t,o,l){this.state={item:e,mode:t,startX:o,startY:l,currentX:o,currentY:l,deltaX:0,originalGroup:e.group,currentGroup:e.group},this.activated=!1}update(e,t){this.state&&(this.state.currentX=e,this.state.currentY=t,this.state.deltaX=e-this.state.startX,!this.activated&&Math.abs(this.state.deltaX)>=mi&&(this.activated=!0))}setCurrentGroup(e){this.state&&(this.state.currentGroup=e)}endMove(e){if(!this.state)return null;const t=this.state.deltaX/e,o=this.state.item.start_time+t,l=Math.round(o/this.dragSnap)*this.dragSnap,u=this.state.currentGroup;return this.state=null,this.activated=!1,{newStartTime:l,newGroupId:u}}endResize(e){if(!this.state)return null;const t=this.state.deltaX/e,o=this.state.mode==="resize-left"?"left":"right",u=(o==="left"?this.state.item.start_time:this.state.item.end_time)+t,a=Math.round(u/this.dragSnap)*this.dragSnap;return this.state=null,this.activated=!1,{newTime:a,edge:o}}cancel(){this.state=null,this.activated=!1}getState(){return this.state}getMode(){var e;return((e=this.state)==null?void 0:e.mode)??null}isActive(){return this.state!==null&&this.activated}isPending(){return this.state!==null}}function it(i,e,t){const o=[];for(const l of i)l.id!==e&&(o.push(t(l.start_time)),o.push(t(l.end_time)));return o}function je(i,e,t,o,l){if(e.length===0)return null;let u=e[0],a=Math.abs(i-u);for(let g=1;g<e.length;g++){const d=Math.abs(i-e[g]);d<a&&(a=d,u=e[g])}return a<=t?u:null}var Xt=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Ft(i){return i&&i.__esModule&&Object.prototype.hasOwnProperty.call(i,"default")?i.default:i}var Ot={exports:{}};(function(i,e){(function(t,o){i.exports=o()})(Xt,function(){var t="day";return function(o,l,u){var a=function(v){return v.add(4-v.isoWeekday(),t)},g=l.prototype;g.isoWeekYear=function(){return a(this).year()},g.isoWeek=function(v){if(!this.$utils().u(v))return this.add(7*(v-this.isoWeek()),t);var k,y,H,E,I=a(this),B=(k=this.isoWeekYear(),y=this.$u,H=(y?u.utc:u)().year(k).startOf("year"),E=4-H.isoWeekday(),H.isoWeekday()>4&&(E+=7),H.add(E,t));return I.diff(B,"week")+1},g.isoWeekday=function(v){return this.$utils().u(v)?this.day()||7:this.day(this.day()%7?v:v-7)};var d=g.startOf;g.startOf=function(v,k){var y=this.$utils(),H=!!y.u(k)||k;return y.p(v)==="isoweek"?H?this.date(this.date()-(this.isoWeekday()-1)).startOf("day"):this.date(this.date()-1-(this.isoWeekday()-1)+7).endOf("day"):d.bind(this)(v,k)}}})})(Ot);var bi=Ot.exports;const vi=Ft(bi),wt=5;function Ht({groups:i,width:e,lineHeight:t,scrollTop:o,canvasHeight:l,theme:u,groupRenderer:a,onScroll:g}){var x;const d=c.useRef(null),v=c.useRef(!1),k=i.length*t,y=l,H=Math.max(0,Math.floor(o/t)-wt),E=Math.min(i.length-1,Math.ceil((o+l)/t)+wt),I=c.useCallback(Y=>{v.current||g(Y.currentTarget.scrollTop)},[g]);c.useEffect(()=>{d.current&&(v.current=!0,d.current.scrollTop=o,requestAnimationFrame(()=>{v.current=!1}))},[o]);const B=[];for(let Y=H;Y<=E;Y++){const T=i[Y];T&&B.push(V.jsx("div",{style:{position:"absolute",top:Y*t,height:t,width:"100%",overflow:"hidden",display:"flex",alignItems:"stretch",borderBottom:`1px solid ${((x=u.grid)==null?void 0:x.line)??"#E5E5E5"}`,boxSizing:"border-box"},children:a(T)},T.id))}return V.jsx("div",{ref:d,onScroll:I,style:{width:e,height:y,overflowY:k>l?"auto":"hidden",overflowX:"hidden",position:"relative",borderRight:`1px solid ${u.sidebar.border}`,backgroundColor:u.sidebar.bg},children:V.jsx("div",{style:{height:k,position:"relative"},children:B})})}function Wt(i){return null}Wt.displayName="TodayMarker";function Rt(i){return{date:Math.floor(Date.now()/6e4)*6e4,color:i.color??"#FD7171",width:i.width??6,label:i.label}}function pi(i){return i.interval??1e4}function Bt(i){return null}Bt.displayName="CustomMarker";function It(i){return{date:i.date,color:i.color??"#3B82F6",width:i.width??4,label:i.label}}ce.extend(vi);function yi(i){return i?{...he,...i,status:{...he.status,...i.status},grid:{...he.grid,...i.grid},item:{...he.item,...i.item},marker:{...he.marker,...i.marker},sidebar:{...he.sidebar,...i.sidebar},header:{...he.header,...i.header}}:he}const Dt=32,Ti=c.memo(c.forwardRef(function(e,t){const{groups:o,items:l,defaultTimeStart:u,defaultTimeEnd:a,sidebarWidth:g,lineHeight:d,itemHeightRatio:v,stackItems:k,canMove:y,canChangeGroup:H,canResize:E,dragSnap:I,minZoom:B,maxZoom:x,theme:Y,dayStyle:T,rowStyle:P,showCursorLine:_,itemRenderer:N,groupRenderer:w,sidebarGroupRenderer:A,dependencies:Z,highlights:q,onItemClick:re,onItemDoubleClick:G,onItemContextMenu:oe,onItemMove:fe,onItemResize:ue,moveResizeValidator:Te,onItemHover:Pe,onCanvasDoubleClick:xe,onCanvasContextMenu:rt,onTimeChange:nt,onZoom:st,selected:ot=[],rightSidebarWidth:Le,rightSidebarGroupRenderer:lt,onReady:Xe,children:me}=e,ye=c.useMemo(()=>yi(Y),[Y]),at=c.useCallback((s,r)=>{for(let f=0;f<r.length;f++)if(r[f].id===s)return f;return 0},[]),Yt=ot.join(","),Ae=c.useMemo(()=>ot,[Yt]),ut=c.useRef(null),ct=c.useRef(null),dt=c.useRef(null),Ce=c.useRef(null),ft=c.useRef(null),$t=c.useRef(null),[Nt,Gt]=c.useState(800);c.useEffect(()=>{const s=ft.current;if(!s)return;const r=new ResizeObserver(f=>{const h=f[0];h&&Gt(h.contentRect.width)});return r.observe(s),()=>r.disconnect()},[]);const ge=Math.max(0,Nt-g-(Le??0)),be=o.length*d,D=c.useRef(new Je({visibleTimeStart:e.visibleTimeStart??u,visibleTimeEnd:e.visibleTimeEnd??a,canvasWidth:ge,canvasHeight:be,sidebarWidth:g,lineHeight:d,groupCount:o.length,buffer:e.buffer??3,scrollTop:0})),Ye=c.useRef(null),we=c.useRef(void 0),[ht,zt]=c.useState(e.visibleTimeStart??u),[mt,Vt]=c.useState(e.visibleTimeEnd??a),[gt,Fe]=c.useState(0),He=c.useRef(null),ke=c.useCallback(()=>{const s=D.current;zt(s.visibleTimeStart),Vt(s.visibleTimeEnd),Fe(s.scrollTop),He.current=null},[]),$e=c.useCallback(()=>{He.current===null&&(He.current=setTimeout(ke,Dt))},[ke]);c.useEffect(()=>()=>{He.current!==null&&clearTimeout(He.current)},[]);const Ne=c.useMemo(()=>{const s=new oi;return s.buildFromItems(l,r=>r.start_time,r=>r.end_time),s},[l]),Ge=c.useMemo(()=>{const s=new li(d,v);return s.computeLayout(l,k),s},[l,d,v,k]),Se=c.useMemo(()=>new ui,[]),Ee=c.useMemo(()=>new ci,[]),Me=c.useMemo(()=>new di,[]),Q=c.useMemo(()=>new gi(I),[I]),Oe=c.useMemo(()=>{const s=[];return c.Children.forEach(me,r=>{var h;if(!c.isValidElement(r))return;const f=(h=r.type)==null?void 0:h.displayName;f==="TodayMarker"?s.push(Rt(r.props)):f==="CustomMarker"&&s.push(It(r.props))}),s},[me]),We=c.useMemo(()=>Oe.map(s=>`${s.date}|${s.color}|${s.width}|${s.label??""}`).join(";"),[Oe]),Re=c.useRef(Oe);Re.current=Oe;const ze=c.useMemo(()=>{let s=0;return c.Children.forEach(me,r=>{var h;if(!c.isValidElement(r))return;((h=r.type)==null?void 0:h.displayName)==="TodayMarker"&&(s=pi(r.props))}),s},[me]),O=c.useRef({groups:o,items:l,intervalTree:Ne,layoutEngine:Ge,itemRenderer:N,groupRenderer:w,theme:ye,selected:Ae,dependencies:Z,highlights:q,dayStyle:T,rowStyle:P,showCursorLine:_,canvasWidth:ge,canvasHeight:be,lineHeight:d,itemHeightRatio:v,onTimeChange:nt,onZoom:st,onItemHover:Pe,onItemClick:re,onItemDoubleClick:G,onItemContextMenu:oe,onItemMove:fe,onItemResize:ue,onCanvasDoubleClick:xe,onCanvasContextMenu:rt,canMove:y,canResize:E,canChangeGroup:H,dragSnap:I,sidebarWidth:g,moveResizeValidator:Te});O.current={groups:o,items:l,intervalTree:Ne,layoutEngine:Ge,itemRenderer:N,groupRenderer:w,theme:ye,selected:Ae,dependencies:Z,highlights:q,dayStyle:T,rowStyle:P,showCursorLine:_,canvasWidth:ge,canvasHeight:be,lineHeight:d,itemHeightRatio:v,onTimeChange:nt,onZoom:st,onItemHover:Pe,onItemClick:re,onItemDoubleClick:G,onItemContextMenu:oe,onItemMove:fe,onItemResize:ue,onCanvasDoubleClick:xe,onCanvasContextMenu:rt,canMove:y,canResize:E,canChangeGroup:H,dragSnap:I,sidebarWidth:g,moveResizeValidator:Te};const Zt=c.useCallback(()=>{const s=ut.current;if(!s)return;const r=O.current,f=et(s,r.canvasWidth,r.canvasHeight);tt(f,s),Se.draw(f,D.current,r.groups,r.theme,r.dayStyle,r.rowStyle,r.highlights)},[Se]),qt=c.useCallback(()=>{const s=ct.current;if(!s)return;const r=O.current,f=et(s,r.canvasWidth,r.canvasHeight);tt(f,s),Ee.draw(f,D.current,r.groups,r.items,r.intervalTree,r.layoutEngine,r.itemRenderer,r.groupRenderer,r.theme,r.selected,we.current,r.dependencies)},[Ee]),bt=c.useCallback((s,r,f)=>{const h=D.current,n=O.current,m=n.canvasWidth/(h.visibleTimeEnd-h.visibleTimeStart),p=r/m,S=[];f==="move"?(S.push(h.timeToX(s.start_time+p)),S.push(h.timeToX(s.end_time+p))):f==="resize-left"?S.push(h.timeToX(s.start_time+p)):S.push(h.timeToX(s.end_time+p));const R=(h.visibleTimeEnd-h.visibleTimeStart)*.1,F=n.intervalTree.query(h.visibleTimeStart-R,h.visibleTimeEnd+R),U=it(F,s.id,te=>h.timeToX(te));for(const te of S){const z=je(te,U,8,m,n.dragSnap);if(z!==null)return z}const J=s.start_time+p,X=Math.round(J/n.dragSnap)*n.dragSnap;return h.timeToX(X)},[]),Ut=c.useCallback(()=>{const s=dt.current;if(!s)return;const r=O.current,f=et(s,r.canvasWidth,r.canvasHeight);tt(f,s);const h=D.current,n=Q.getState();let m=null;if(n){const p=h.timeToX(n.item.start_time),S=h.timeToX(n.item.end_time)-p;let R,F;n.mode==="resize-left"?(R=p+n.deltaX,F=S-n.deltaX):n.mode==="resize-right"?(R=p,F=S+n.deltaX):(R=p+n.deltaX,F=S);const U=at(n.currentGroup,r.groups),J=h.groupIndexToY(U),X=n.currentGroup!==n.originalGroup;m={item:n.item,mode:n.mode,bounds:{x:R,y:J+(r.lineHeight-r.lineHeight*r.itemHeightRatio)/2,width:F,height:r.lineHeight*r.itemHeightRatio},renderer:r.itemRenderer,targetGroupY:J,groupChanged:X}}Me.draw(f,h,r.theme,{cursorX:r.showCursorLine?Ye.current:null,snapX:n?bt(n.item,n.deltaX,n.mode):null,markers:Re.current,interaction:m})},[Me,Q,bt,at]),Ve=c.useRef(null);Ve.current||(Ve.current=new ai(s=>{s.grid&&Zt(),s.items&&qt(),s.overlay&&Ut()}));const C=Ve.current;c.useEffect(()=>()=>C.dispose(),[C]),c.useEffect(()=>{if(!ze)return;const s=setInterval(()=>{const r=[];c.Children.forEach(me,f=>{var n;if(!c.isValidElement(f))return;const h=(n=f.type)==null?void 0:n.displayName;h==="TodayMarker"?r.push(Rt(f.props)):h==="CustomMarker"&&r.push(It(f.props))}),Re.current=r,C.markDirty("overlay")},ze);return()=>clearInterval(s)},[ze,me,C]),c.useEffect(()=>{D.current.update({canvasWidth:ge,canvasHeight:be,sidebarWidth:g,lineHeight:d,groupCount:o.length}),C.markAllDirty()},[ge,be,g,d,o.length,C]),c.useEffect(()=>{C.markDirty("grid"),C.markDirty("items")},[l,o,Ae,ye,T,P,Ne,Ge,C]);const Be=c.useMemo(()=>{var s;return((s=e.highlights)==null?void 0:s.map(r=>`${r.start}|${r.end}|${r.color}|${r.label??""}|${r.opacity??""}`).join(";"))??""},[e.highlights]),vt=c.useRef(Be);c.useEffect(()=>{Be!==vt.current&&(vt.current=Be,C.markDirty("grid"))},[Be,C]);const pt=c.useRef(We);c.useEffect(()=>{We!==pt.current&&(pt.current=We,C.markDirty("overlay"))},[We,C]);const yt=c.useRef(e.visibleTimeStart),Tt=c.useRef(e.visibleTimeEnd);e.visibleTimeStart!==void 0&&e.visibleTimeStart!==yt.current&&(yt.current=e.visibleTimeStart,D.current.update({visibleTimeStart:e.visibleTimeStart}),C.markAllDirty()),e.visibleTimeEnd!==void 0&&e.visibleTimeEnd!==Tt.current&&(Tt.current=e.visibleTimeEnd,D.current.update({visibleTimeEnd:e.visibleTimeEnd}),C.markAllDirty());const Ie=c.useRef(null),Ze=c.useCallback(s=>{Ie.current===null&&(Ie.current=setTimeout(()=>{var h,n;Ie.current=null;const r=D.current,f=O.current;s==="zoom"?(h=f.onZoom)==null||h.call(f,r.visibleTimeStart,r.visibleTimeEnd):(n=f.onTimeChange)==null||n.call(f,r.visibleTimeStart,r.visibleTimeEnd)},Dt))},[]);c.useEffect(()=>()=>{Ie.current!==null&&clearTimeout(Ie.current)},[]);const _e=c.useRef(null),qe=c.useMemo(()=>new hi((s,r)=>{var f;D.current.update({visibleTimeStart:s,visibleTimeEnd:r}),(f=_e.current)==null||f.updateBounds(s,r),C.markAllDirty(),$e(),Ze("zoom")},u,a,B,x),[]);_e.current=qe;const kt=c.useCallback(s=>{const r=D.current,f=r.groupCount*r.lineHeight,h=Math.max(0,f-r.canvasHeight),n=Math.max(0,Math.min(h,r.scrollTop+s));n!==r.scrollTop&&(r.update({scrollTop:n}),C.markDirty("grid"),C.markDirty("items"),C.markDirty("overlay"),Fe(n))},[C]),Ue=c.useCallback(s=>{var p,S,R;const r=D.current,f=r.canvasWidth/(r.visibleTimeEnd-r.visibleTimeStart),h=s/f,n=r.visibleTimeStart+h,m=r.visibleTimeEnd+h;r.update({visibleTimeStart:n,visibleTimeEnd:m}),(p=_e.current)==null||p.updateBounds(n,m),C.markAllDirty(),si.flushSync(()=>ke()),(R=(S=O.current).onTimeChange)==null||R.call(S,n,m)},[C,ke]);c.useEffect(()=>{const s=Ce.current;if(!s)return;const r=f=>{if(f.ctrlKey||f.metaKey||f.altKey){f.preventDefault();const h=s.getBoundingClientRect(),n=(f.clientX-h.left)/h.width;qe.handleWheelZoom(f,n)}else if(f.shiftKey)f.preventDefault(),Ue(f.deltaY);else{const h=f.deltaX;h!==0&&Math.abs(h)>Math.abs(f.deltaY)?(f.preventDefault(),Ue(h)):f.deltaY!==0&&kt(f.deltaY)}};return s.addEventListener("wheel",r,{passive:!1}),()=>s.removeEventListener("wheel",r)},[qe,kt,Ue]);const ve=c.useRef({lastDistance:null,lastCenter:null});c.useEffect(()=>{const s=Ce.current;if(!s)return;const r=(p,S)=>Math.abs(p.clientX-S.clientX),f=(p,S,R)=>(p.clientX+S.clientX)/2-R.left,h=p=>{p.touches.length===2&&(p.preventDefault(),ve.current.lastDistance=r(p.touches[0],p.touches[1]),ve.current.lastCenter=null)},n=p=>{var S;if(p.touches.length===2&&ve.current.lastDistance!==null){p.preventDefault();const R=r(p.touches[0],p.touches[1]),F=s.getBoundingClientRect(),J=f(p.touches[0],p.touches[1],F)/F.width;if(R!==0&&ve.current.lastDistance!==0){const X=ve.current.lastDistance/R,te=D.current,z=te.visibleTimeEnd-te.visibleTimeStart;let M=z*X;M=Math.max(B,Math.min(x,M));const b=te.visibleTimeStart+z*J,L=b-M*J,j=b+M*(1-J);te.update({visibleTimeStart:L,visibleTimeEnd:j}),(S=_e.current)==null||S.updateBounds(L,j),C.markAllDirty(),$e(),Ze("zoom")}ve.current.lastDistance=R}},m=()=>{ve.current.lastDistance=null,ve.current.lastCenter=null};return s.addEventListener("touchstart",h,{passive:!1}),s.addEventListener("touchmove",n,{passive:!1}),s.addEventListener("touchend",m),()=>{s.removeEventListener("touchstart",h),s.removeEventListener("touchmove",n),s.removeEventListener("touchend",m)}},[C,$e,Ze]);const Kt=c.useCallback(s=>{var R;const r=s.currentTarget,f=r.getBoundingClientRect(),h=s.clientX-f.left,n=s.clientY-f.top;if(Ye.current=h,Q.isPending()){if(Q.update(h,n),Q.isActive()){const F=Q.getState();if(F&&F.mode==="move"&&O.current.canChangeGroup){const U=Qe(n,D.current,O.current.groups);U&&Q.setCurrentGroup(U.id)}C.markDirty("overlay")}return}O.current.showCursorLine&&C.markDirty("overlay");const m=O.current,p=De(h,n,D.current,m.intervalTree,m.layoutEngine,m.groups),S=p==null?void 0:p.id;if(S!==we.current&&(we.current=S,C.markDirty("items"),(R=m.onItemHover)==null||R.call(m,S??null,s.nativeEvent)),p){const F=Et(h,p,D.current),U=m.canResize;F==="left"&&(U==="left"||U==="both")||F==="right"&&(U==="right"||U==="both")?r.style.cursor="col-resize":m.canMove?r.style.cursor="grab":r.style.cursor="default"}else r.style.cursor="default"},[Q,C]),Jt=c.useCallback(s=>{const r=O.current,f=s.currentTarget.getBoundingClientRect(),h=s.clientX-f.left,n=s.clientY-f.top,m=De(h,n,D.current,r.intervalTree,r.layoutEngine,r.groups);if(!m)return;const p=Et(h,m,D.current),S=r.canResize;p==="left"&&(S==="left"||S==="both")?Q.startInteraction(m,"resize-left",h,n):p==="right"&&(S==="right"||S==="both")?Q.startInteraction(m,"resize-right",h,n):r.canMove&&Q.startInteraction(m,"move",h,n)},[Q]),Qt=c.useCallback(s=>{var p,S,R,F,U,J;const r=s.currentTarget;if(Q.isActive()){const X=Q.getState(),te=D.current,z=te.canvasWidth/(te.visibleTimeEnd-te.visibleTimeStart);if(X){const M=O.current.moveResizeValidator;if(X.mode==="move"){const b=Q.endMove(z);if(b){const L=D.current,j=O.current,le=X.deltaX/z,ae=L.timeToX(X.item.start_time+le),W=L.timeToX(X.item.end_time+le),K=(L.visibleTimeEnd-L.visibleTimeStart)*.1,ee=j.intervalTree.query(L.visibleTimeStart-K,L.visibleTimeEnd+K),$=it(ee,X.item.id,se=>L.timeToX(se));let ne=b.newStartTime;const ie=je(ae,$,8,z,j.dragSnap);if(ie!==null)ne=L.xToTime(ie);else{const se=je(W,$,8,z,j.dragSnap);if(se!==null){const pe=X.item.end_time-X.item.start_time;ne=L.xToTime(se)-pe}}const de=M?M("move",X.item.id,ne):ne;(S=(p=O.current).onItemMove)==null||S.call(p,X.item.id,de,b.newGroupId)}}else{const b=Q.endResize(z);if(b){const L=D.current,j=O.current,le=X.deltaX/z,ae=b.edge==="left"?X.item.start_time+le:X.item.end_time+le,W=L.timeToX(ae),K=(L.visibleTimeEnd-L.visibleTimeStart)*.1,ee=j.intervalTree.query(L.visibleTimeStart-K,L.visibleTimeEnd+K),$=it(ee,X.item.id,se=>L.timeToX(se)),ne=je(W,$,8,z,j.dragSnap),ie=ne!==null?L.xToTime(ne):b.newTime,de=M?M("resize",X.item.id,ie,b.edge):ie;(F=(R=O.current).onItemResize)==null||F.call(R,X.item.id,de,b.edge)}}}r.style.cursor="default",C.markDirty("overlay");return}Q.isPending()&&Q.cancel();const f=r.getBoundingClientRect(),h=s.clientX-f.left,n=s.clientY-f.top,m=De(h,n,D.current,O.current.intervalTree,O.current.layoutEngine,O.current.groups);m&&((J=(U=O.current).onItemClick)==null||J.call(U,m.id,s.nativeEvent))},[Q,C]),ei=c.useCallback(s=>{var p,S;const r=s.currentTarget.getBoundingClientRect(),f=s.clientX-r.left,h=s.clientY-r.top,n=O.current,m=De(f,h,D.current,n.intervalTree,n.layoutEngine,n.groups);if(m)(p=n.onItemDoubleClick)==null||p.call(n,m.id,s.nativeEvent);else{const R=Qe(h,D.current,n.groups),F=D.current.xToTime(f);R&&((S=n.onCanvasDoubleClick)==null||S.call(n,R.id,F))}},[]),ti=c.useCallback(s=>{var p,S;s.preventDefault();const r=s.currentTarget.getBoundingClientRect(),f=s.clientX-r.left,h=s.clientY-r.top,n=O.current,m=De(f,h,D.current,n.intervalTree,n.layoutEngine,n.groups);if(m)(p=n.onItemContextMenu)==null||p.call(n,m.id,s.nativeEvent);else{const R=Qe(h,D.current,n.groups),F=D.current.xToTime(f);R&&((S=n.onCanvasContextMenu)==null||S.call(n,R.id,F,s.nativeEvent))}},[]),ii=c.useCallback(()=>{var s,r;Ye.current=null,Ce.current&&(Ce.current.style.cursor="default"),we.current!==void 0&&(we.current=void 0,C.markDirty("items"),(r=(s=O.current).onItemHover)==null||r.call(s,null,new PointerEvent("pointerleave"))),O.current.showCursorLine&&C.markDirty("overlay")},[C]),ri=c.useMemo(()=>{const s=[];return c.Children.forEach(me,r=>{var h;if(!c.isValidElement(r))return;if(((h=r.type)==null?void 0:h.displayName)==="TimelineHeaders"){const n=r.props;s.push(c.cloneElement(r,{visibleTimeStart:n.visibleTimeStart??ht,visibleTimeEnd:n.visibleTimeEnd??mt,canvasWidth:n.canvasWidth??ge,sidebarWidth:n.sidebarWidth??g,theme:n.theme??ye,onZoomToInterval:n.onZoomToInterval??((m,p)=>{var S,R,F,U;D.current.update({visibleTimeStart:m,visibleTimeEnd:p}),C.markAllDirty(),ke(),(R=(S=O.current).onTimeChange)==null||R.call(S,m,p),(U=(F=O.current).onZoom)==null||U.call(F,m,p)})}))}}),s},[me,ht,mt,ge,g,ye,C,ke]),St=c.useRef(!1);c.useEffect(()=>{St.current||(St.current=!0,C.markAllDirty())},[C]),c.useImperativeHandle(t,()=>({captureToCanvas({timeStart:s,timeEnd:r,scale:f,sidebarWidth:h}){const n=O.current,m=28,p=m*3,S=n.groups.length*n.lineHeight,R=D.current,F=n.canvasWidth/(R.visibleTimeEnd-R.visibleTimeStart),U=r-s,J=Math.max(n.canvasWidth,Math.round(U*F)),X=(h+J)*f,te=(p+S)*f,z=document.createElement("canvas");z.width=X,z.height=te;const M=z.getContext("2d");M.scale(f,f);for(let j=0;j<n.groups.length;j++){const le=n.groups[j],ae=p+j*n.lineHeight;if(n.rowStyle){const $=n.rowStyle(le);$!=null&&$.backgroundColor&&(M.fillStyle=$.backgroundColor,M.fillRect(0,ae,h,n.lineHeight))}const W=le.type;let K="400",ee=8;W==="project"?K="700":W==="CAG"?K="600":W==="CA"&&(K="400",ee=24),M.fillStyle="#111",M.font=`${K} 12px sans-serif`,M.textBaseline="middle",M.fillText(le.title,ee,ae+n.lineHeight/2,h-ee-4)}const b=(j,le,ae)=>{var ee,$;M.fillStyle=((ee=n.theme.header)==null?void 0:ee.bg)??"#f5f5f5",M.fillRect(h,j,J,m),M.strokeStyle=(($=n.theme.grid)==null?void 0:$.line)??"#e0e0e0",M.lineWidth=1,M.strokeRect(h,j,J,m);let W=ce(s).startOf(ae);W.valueOf()<s&&(W=W.add(1,ae));const K=J/(r-s);for(;W.valueOf()<r;){const ne=W.add(1,ae),ie=h+(W.valueOf()-s)*K,se=h+(Math.min(ne.valueOf(),r)-s)*K-ie;M.beginPath(),M.moveTo(ie,j),M.lineTo(ie,j+m),M.stroke(),M.fillStyle="#333",M.font="600 11px sans-serif",M.textBaseline="middle",M.textAlign="center",M.fillText(le(W),ie+se/2,j+m/2,se-4),W=ne}M.textAlign="start"};b(0,j=>j.format("YYYY"),"year"),b(m,j=>j.format("MM"),"month"),b(m*2,j=>String(j.isoWeek()),"week");const L=new Je({visibleTimeStart:s,visibleTimeEnd:r,canvasWidth:J,canvasHeight:S,sidebarWidth:0,lineHeight:n.lineHeight,groupCount:n.groups.length,buffer:1,scrollTop:0});return M.save(),M.translate(h,p),M.beginPath(),M.rect(0,0,J,S),M.clip(),Se.draw(M,L,n.groups,n.theme,n.dayStyle,n.rowStyle,n.highlights),Ee.draw(M,L,n.groups,n.items,n.intervalTree,n.layoutEngine,n.itemRenderer,n.groupRenderer,n.theme,n.selected,void 0,n.dependencies),Me.draw(M,L,n.theme,{cursorX:null,snapX:null,markers:Re.current,interaction:null}),M.restore(),z}}),[Se,Ee,Me]),c.useEffect(()=>{const s={captureToCanvas({timeStart:r,timeEnd:f,scale:h,sidebarWidth:n}){var ae;const m=O.current,p=28,S=p*3,R=m.groups.length*m.lineHeight,F=D.current,U=m.canvasWidth/(F.visibleTimeEnd-F.visibleTimeStart),J=f-r,X=Math.max(m.canvasWidth,Math.round(J*U)),te=n+X,z=S+R,M=document.createElement("canvas");M.width=te*h,M.height=z*h;const b=M.getContext("2d");b.scale(h,h),b.fillStyle="#FFFFFF",b.fillRect(0,0,te,z),b.save(),b.beginPath(),b.rect(0,0,n,z),b.clip(),b.fillStyle="#F9FAFB",b.fillRect(0,0,n,S),b.strokeStyle="#E5E7EB",b.lineWidth=1,b.strokeRect(0,0,n,S);for(let W=0;W<m.groups.length;W++){const K=m.groups[W],ee=S+W*m.lineHeight,$=(ae=m.rowStyle)==null?void 0:ae.call(m,K);b.fillStyle=($==null?void 0:$.backgroundColor)??(W%2===0?"#FFFFFF":"#F7F7F7"),b.fillRect(0,ee,n,m.lineHeight),b.strokeStyle="#E5E5E5",b.lineWidth=.5,b.beginPath(),b.moveTo(0,ee+m.lineHeight),b.lineTo(n,ee+m.lineHeight),b.stroke();const ne=K.type??"";let ie=8,de="400",se=11;ne==="project"?(de="700",se=12):ne==="control_area_group"?de="600":ne==="control_area"&&(ie=24),b.fillStyle="#374151",b.font=`${de} ${se}px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif`,b.textBaseline="middle";const pe=typeof K.title=="string"?K.title:String(K.title);b.fillText(pe,ie,ee+m.lineHeight/2,n-ie-8)}b.strokeStyle="#E5E7EB",b.lineWidth=1,b.beginPath(),b.moveTo(n,0),b.lineTo(n,z),b.stroke(),b.restore(),b.save(),b.beginPath(),b.rect(n,0,X,S),b.clip();const L=f-r,j=[{unit:"year",row:0},{unit:"month",row:1},{unit:"week",row:2}];for(const{unit:W,row:K}of j){const ee=K*p;b.fillStyle="#F9FAFB",b.fillRect(n,ee,X,p);let $=ce(r).startOf(W);const ne=ce(f).add(1,W);for(;$.isBefore(ne);){const ie=$.add(1,W),de=n+($.valueOf()-r)/L*X,se=(ie.valueOf()-$.valueOf())/L*X;b.strokeStyle="#E5E7EB",b.lineWidth=.5,b.strokeRect(de,ee,se,p);let pe;W==="year"?pe=$.format("YYYY"):W==="month"?pe=$.format("MM"):pe=`${$.week()}`,b.fillStyle="#6c737f",b.font=W==="year"?'600 11px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif':'400 11px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',b.textBaseline="middle",b.textAlign="center",se>20&&b.fillText(pe,de+se/2,ee+p/2),$=ie}}b.textAlign="start",b.restore(),b.save(),b.beginPath(),b.rect(n,S,X,R),b.clip(),b.translate(n,S);const le=new Je({visibleTimeStart:r,visibleTimeEnd:f,canvasWidth:X,canvasHeight:R,sidebarWidth:0,lineHeight:m.lineHeight,groupCount:m.groups.length,buffer:1,scrollTop:0});return Se.draw(b,le,m.groups,m.theme,m.dayStyle,m.rowStyle,m.highlights),Ee.draw(b,le,m.groups,m.items,m.intervalTree,m.layoutEngine,m.itemRenderer,m.groupRenderer,m.theme,m.selected,void 0,m.dependencies),Me.draw(b,le,m.theme,{cursorX:null,markers:Re.current}),b.restore(),M}};Xe==null||Xe(s)},[Xe,Se,Ee,Me]);const ni={position:"relative",width:ge,height:be,overflow:"hidden",cursor:"default"},Ke={position:"absolute",top:0,left:0};return V.jsxs("div",{ref:ft,style:{display:"flex",flexDirection:"column",width:"100%"},children:[ri,V.jsxs("div",{ref:$t,style:{display:"flex",overflow:"hidden"},children:[V.jsx(Ht,{groups:o,width:g,lineHeight:d,scrollTop:gt,canvasHeight:be,theme:ye,groupRenderer:A,onScroll:s=>{D.current.update({scrollTop:s}),C.markDirty("grid"),C.markDirty("items"),C.markDirty("overlay"),Fe(s)}}),V.jsxs("div",{ref:Ce,style:ni,onPointerMove:Kt,onPointerDown:Jt,onPointerUp:Qt,onDoubleClick:ei,onContextMenu:ti,onPointerLeave:ii,children:[V.jsx("canvas",{ref:ut,style:{...Ke,zIndex:0}}),V.jsx("canvas",{ref:ct,style:{...Ke,zIndex:1}}),V.jsx("canvas",{ref:dt,style:{...Ke,zIndex:2}})]}),Le&<?V.jsx(Ht,{groups:o,width:Le,lineHeight:d,scrollTop:gt,canvasHeight:be,theme:ye,groupRenderer:lt,onScroll:s=>{D.current.update({scrollTop:s}),C.markDirty("grid"),C.markDirty("items"),C.markDirty("overlay"),Fe(s)}}):null]})]})}));function _t({children:i,theme:e,className:t,classNames:o,style:l,visibleTimeStart:u,visibleTimeEnd:a,canvasWidth:g,sidebarWidth:d=0,onZoomToInterval:v}){const k=c.Children.map(i,y=>{var E;if(!c.isValidElement(y))return y;if(((E=y.type)==null?void 0:E.displayName)==="DateHeader"){const I=y.props,B=c.cloneElement(y,{visibleTimeStart:I.visibleTimeStart??u,visibleTimeEnd:I.visibleTimeEnd??a,canvasWidth:I.canvasWidth??g,theme:I.theme??e,onZoomToInterval:I.onIntervalClick??I.onZoomToInterval??v});return V.jsxs("div",{style:{display:"flex"},children:[V.jsx("div",{style:{width:d,flexShrink:0}}),V.jsx("div",{style:{flex:1,overflow:"hidden"},children:B})]})}return y});return V.jsx("div",{className:t,style:{position:"sticky",top:0,zIndex:20,display:"flex",flexDirection:"column",backgroundColor:(e==null?void 0:e.header.bg)??"#F9FAFB",borderTop:`1px solid ${(e==null?void 0:e.header.border)??"#E5E7EB"}`,borderBottom:`1px solid ${(e==null?void 0:e.header.border)??"#E5E7EB"}`,...l},children:k})}_t.displayName="TimelineHeaders";var jt={exports:{}};(function(i,e){(function(t,o){i.exports=o()})(Xt,function(){var t="week",o="year";return function(l,u,a){var g=u.prototype;g.week=function(d){if(d===void 0&&(d=null),d!==null)return this.add(7*(d-this.week()),"day");var v=this.$locale().yearStart||1;if(this.month()===11&&this.date()>25){var k=a(this).startOf(o).add(1,o).date(v),y=a(this).endOf(t);if(k.isBefore(y))return 1}var H=a(this).startOf(o).date(v).startOf(t).subtract(1,"millisecond"),E=this.diff(H,t,!0);return E<0?a(this).startOf("week").week():Math.ceil(E)},g.weeks=function(d){return d===void 0&&(d=null),this.week(d)}}})})(jt);var ki=jt.exports;const Si=Ft(ki);ce.extend(Si);const Ei={year:30,month:30,week:20,day:15,hour:30};function xt({unit:i,visibleTimeStart:e=0,visibleTimeEnd:t=0,canvasWidth:o=0,theme:l,height:u=28,className:a,labelFormat:g,onIntervalClick:d,minCellWidth:v,onZoomToInterval:k}){const y=c.useMemo(()=>{if(!e||!t||!o)return[];const E=t-e,I=v??Ei[i];if(I>0){const T=ce(e).startOf(i);if((T.add(1,i).valueOf()-T.valueOf())/E*o<I)return[]}const B=[];let x=ce(e).startOf(i).subtract(1,i);const Y=ce(t).add(2,i).valueOf();for(;x.valueOf()<Y;){const T=x.add(1,i),P=x.valueOf(),_=T.valueOf(),N=(P-e)/E*o,w=(_-P)/E*o,A=Mi(x,T,i,g);B.push({start:P,end:_,label:A,left:N,width:w}),x=T}return B},[e,t,o,i,g,v]),H=c.useCallback((E,I)=>{d?d(E,I):k&&k(E,I)},[d,k]);return y.length===0?null:V.jsx("div",{style:{display:"flex",position:"relative",height:u,overflow:"hidden"},children:y.map(E=>V.jsx("div",{className:a,onClick:()=>H(E.start,E.end),style:{position:"absolute",left:E.left,width:E.width,height:"100%",display:"flex",alignItems:"center",justifyContent:"center",borderRight:`1px solid ${(l==null?void 0:l.header.border)??"#E5E7EB"}`,borderBottom:`1px solid ${(l==null?void 0:l.header.border)??"#E5E7EB"}`,fontSize:12,color:(l==null?void 0:l.header.text)??"#6c737f",backgroundColor:(l==null?void 0:l.header.bg)??"#F9FAFB",overflow:"hidden",whiteSpace:"nowrap",cursor:"pointer",userSelect:"none",padding:"0 4px",boxSizing:"border-box"},children:V.jsx("span",{children:E.label})},E.start))})}xt.displayName="DateHeader";function Mi(i,e,t,o,l){return typeof o=="function"?o(i.toDate(),e.toDate(),t):typeof o=="string"?i.format(o):Ci(i,t)}function Ci(i,e){switch(e){case"year":return i.format("YYYY");case"month":return i.format("MM");case"week":return`${i.week()}`;case"day":return i.format("D");case"hour":return i.format("HH:mm")}}function Lt({width:i,children:e,style:t}){const o=()=>({style:{width:i,...t}});return e?V.jsx(V.Fragment,{children:e({getRootProps:o})}):V.jsx("div",{style:{width:i}})}Lt.displayName="SidebarHeader";function At({children:i}){return V.jsx(V.Fragment,{children:i})}At.displayName="CustomHeader";exports.CanvasTimeline=Ti;exports.CustomHeader=At;exports.CustomMarker=Bt;exports.DEFAULT_THEME=he;exports.DateHeader=xt;exports.SidebarHeader=Lt;exports.TimelineHeaders=_t;exports.TodayMarker=Wt;
|
|
2
2
|
//# sourceMappingURL=canvas-timeline.cjs.js.map
|