@taskctrl/canvas-timeline 0.4.0 → 0.4.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const z=require("react/jsx-runtime"),f=require("react"),ci=require("react-dom"),fe=require("dayjs"),pe={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 tt{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),n=Math.min(this.groupCount-1,e+t);return{firstVisible:e,lastVisible:n}}isScrollInBuffer(e){const t=this.visibleDuration*1.5*this.pixelsPerMs;return Math.abs(e)<t}getTotalHeight(){return this.groupCount*this.lineHeight}}class di{constructor(){Object.defineProperty(this,"root",{enumerable:!0,configurable:!0,writable:!0,value:null})}buildFromItems(e,t,n){const r=e.map(d=>({item:d,start:t(d),end:n(d)}));this.root=this.buildNode(r)}buildNode(e){if(e.length===0)return null;let t=1/0,n=-1/0;for(const u of e)u.start<t&&(t=u.start),u.end>n&&(n=u.end);const r=(t+n)/2,d=[],a=[],c=[];for(const u of e)u.end<r?d.push(u):u.start>r?a.push(u):c.push(u);return{center:r,left:this.buildNode(d),right:this.buildNode(a),overlapping:c}}query(e,t){const n=[];return this.queryNode(this.root,e,t,n),n}queryNode(e,t,n,r){if(e!==null){for(const d of e.overlapping)d.start<=n&&d.end>=t&&r.push(d.item);t<=e.center&&e.left!==null&&this.queryNode(e.left,t,n,r),n>=e.center&&e.right!==null&&this.queryNode(e.right,t,n,r)}}}class fi{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,n){this.layoutCache=new Map,this.groupMaxStack=new Map;const r=this.lineHeight*this.itemHeightRatio,d=r*.6;if(!t){for(const c of e){const u=(n==null?void 0:n.isParent(c.id))??!1;this.layoutCache.set(c.id,{stackLevel:0,itemHeight:u?d:r}),this.groupMaxStack.set(c.group,0)}return this.layoutCache}const a=new Map;for(const c of e){let u=a.get(c.group);u||(u=[],a.set(c.group,u)),u.push(c)}for(const[c,u]of a)n?this.computeHierarchyLayout(u,n,r,d,c):this.computeFlatLayout(u,r,c);return this.layoutCache}computeFlatLayout(e,t,n){e.sort((a,c)=>{const u=a.start_time-c.start_time;return u!==0?u:c.end_time-c.start_time-(a.end_time-a.start_time)});const r=[];let d=0;for(const a of e){let c=-1;for(let u=0;u<r.length;u++)if(r[u]<=a.start_time){c=u;break}c===-1?(c=r.length,r.push(a.end_time)):r[c]=a.end_time,c>d&&(d=c),this.layoutCache.set(a.id,{stackLevel:c,itemHeight:t})}this.groupMaxStack.set(n,d)}computeHierarchyLayout(e,t,n,r,d){const a=[],c=[];for(const p of e)t.isParent(p.id)?c.push(p):a.push(p);a.sort((p,y)=>{const k=p.start_time-y.start_time;return k!==0?k:y.end_time-y.start_time-(p.end_time-p.start_time)});const u=[];let b=0;for(const p of a){let y=-1;for(let k=0;k<u.length;k++)if(u[k]<=p.start_time){y=k;break}y===-1?(y=u.length,u.push(p.end_time)):u[y]=p.end_time,y>b&&(b=y),this.layoutCache.set(p.id,{stackLevel:y,itemHeight:n})}c.sort((p,y)=>t.getNestingDepth(y.id)-t.getNestingDepth(p.id));let E=a.length>0?b+1:0;for(const p of c)this.layoutCache.set(p.id,{stackLevel:E,itemHeight:r}),E>b&&(b=E),E++;this.groupMaxStack.set(d,b)}getLayout(e){return this.layoutCache.get(e)}getGroupHeight(e){return((this.groupMaxStack.get(e)??0)+1)*this.lineHeight}}class _t{constructor(){Object.defineProperty(this,"parentToChildren",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"childToParent",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"itemMap",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"depthCache",{enumerable:!0,configurable:!0,writable:!0,value:new Map})}rebuild(e){this.parentToChildren=new Map,this.childToParent=new Map,this.itemMap=new Map,this.depthCache=new Map;for(const t of e)this.itemMap.set(t.id,t);for(const t of e)if(t.parentId!==void 0&&this.itemMap.has(t.parentId)){this.childToParent.set(t.id,t.parentId);let n=this.parentToChildren.get(t.parentId);n||(n=[],this.parentToChildren.set(t.parentId,n)),n.push(t.id)}for(const t of this.childToParent.keys()){const n=new Set;let r=t;for(;r!==void 0;){if(n.has(r)){const d=this.childToParent.get(t);this.childToParent.delete(t);const a=this.parentToChildren.get(d);if(a){const c=a.indexOf(t);c!==-1&&a.splice(c,1),a.length===0&&this.parentToChildren.delete(d)}break}n.add(r),r=this.childToParent.get(r)}}}isParent(e){const t=this.parentToChildren.get(e);return t!==void 0&&t.length>0}getParent(e){return this.childToParent.get(e)}getChildren(e){return this.parentToChildren.get(e)??[]}getDescendants(e){const t=[],n=[...this.getChildren(e)];for(;n.length>0;){const r=n.pop();t.push(r);const d=this.parentToChildren.get(r);d&&n.push(...d)}return t}getEffectiveSpan(e){const t=this.itemMap.get(e);if(!t)return{start:0,end:0};let n=t.start_time,r=t.end_time;const d=this.getDescendants(e);for(const a of d){const c=this.itemMap.get(a);c&&(c.start_time<n&&(n=c.start_time),c.end_time>r&&(r=c.end_time))}return{start:n,end:r}}getNestingDepth(e){const t=this.depthCache.get(e);if(t!==void 0)return t;let n=0,r=this.childToParent.get(e);for(;r!==void 0;)n++,r=this.childToParent.get(r);return this.depthCache.set(e,n),n}getMoveDelta(e,t){const n=this.itemMap.get(e);if(!n)return[];const r=t-n.start_time;return this.getDescendants(e).map(a=>{const c=this.itemMap.get(a);return{itemId:a,newStart:c.start_time+r}})}getResizeConstraint(e,t){const n=this.getDescendants(e);if(n.length===0)return t==="left"?{min:-1/0,max:1/0}:{min:-1/0,max:1/0};if(t==="left"){let r=1/0;for(const d of n){const a=this.itemMap.get(d);a&&a.start_time<r&&(r=a.start_time)}return{min:-1/0,max:r}}else{let r=-1/0;for(const d of n){const a=this.itemMap.get(d);a&&a.end_time>r&&(r=a.end_time)}return{min:r,max:1/0}}}}function hi(i,e,t,n,r,d){const{x:a,y:c,width:u,height:b}=t,E=d.primary;i.globalAlpha=.15,i.fillStyle=E,i.fillRect(a,c,u,b),i.globalAlpha=1,i.strokeStyle=E,i.lineWidth=1.5,i.strokeRect(a,c,u,b);const p=Math.min(b*.5,6),y=c+b/2;i.fillStyle=E,i.beginPath(),i.moveTo(a,y),i.lineTo(a+p,y-p),i.lineTo(a+p*2,y),i.lineTo(a+p,y+p),i.closePath(),i.fill(),i.beginPath(),i.moveTo(a+u,y),i.lineTo(a+u-p,y-p),i.lineTo(a+u-p*2,y),i.lineTo(a+u-p,y+p),i.closePath(),i.fill();const k=e.title;if(k&&u>30){i.fillStyle=d.item.text,i.font='500 11px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',i.textBaseline="middle";const H=i.measureText(k).width,I=u-p*4-4;if(I>20){const X=H>I?k.slice(0,Math.floor(k.length*I/H))+"...":k;i.fillText(X,a+u/2-Math.min(H,I)/2,y)}}n.selected&&(i.strokeStyle=d.item.selectedRing,i.lineWidth=2,i.strokeRect(a-1,c-1,u+2,b+2))}function Oe(i,e,t,n,r,d){const a=t.xToTime(i),c=new Map;for(let p=0;p<d.length;p++)c.set(d[p].id,p);const u=n.query(a,a);let b=null,E=-1/0;for(const p of u){const y=c.get(p.group);if(y===void 0)continue;const k=r.getLayout(p.id);if(!k)continue;const H=t.timeToX(p.start_time),I=t.timeToX(p.end_time)-H;if(i<H||i>H+I)continue;const $=t.groupIndexToY(y)+k.stackLevel*t.lineHeight+(t.lineHeight-k.itemHeight)/2,M=k.itemHeight;e<$||e>$+M||$>E&&(E=$,b=p)}return b}function it(i,e,t){const n=e.yToGroupIndex(i);return t[n]??null}function Ct(i,e,t,n=6){const r=t.timeToX(e.start_time),d=t.timeToX(e.end_time);return i-r<=n?"left":d-i<=n?"right":"body"}function nt(i,e,t){const n=window.devicePixelRatio||1,r=Math.round(e*n),d=Math.round(t*n);(i.width!==r||i.height!==d)&&(i.width=r,i.height=d,i.style.width=`${e}px`,i.style.height=`${t}px`);const a=i.getContext("2d");return a.setTransform(n,0,0,n,0,0),a}function rt(i,e){const t=window.devicePixelRatio||1;i.clearRect(0,0,e.width/t,e.height/t)}class mi{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 gi{draw(e,t,n,r,d,a,c){const{firstVisible:u,lastVisible:b}=t.getVisibleGroupRange();for(let M=u;M<=b;M++){const O=t.groupIndexToY(M),j=n[M];if(!j)continue;let A;const V=a==null?void 0:a(j);V!=null&&V.backgroundColor?A=V.backgroundColor:A=M%2===0?"#FFFFFF":r.grid.rowAlt,e.fillStyle=A,e.fillRect(0,O,t.canvasWidth,t.lineHeight),e.strokeStyle=(V==null?void 0:V.borderBottomColor)??r.grid.line,e.lineWidth=.5,e.beginPath(),e.moveTo(0,O+t.lineHeight),e.lineTo(t.canvasWidth,O+t.lineHeight),e.stroke()}if(c&&c.length>0)for(const M of c){const O=t.timeToX(M.start),j=t.timeToX(M.end);if(j<0||O>t.canvasWidth)continue;const A=Math.max(0,O),V=Math.min(t.canvasWidth,j)-A,ne=M.opacity??.12,D=parseInt(M.color.slice(1,3),16),L=parseInt(M.color.slice(3,5),16),q=parseInt(M.color.slice(5,7),16);e.fillStyle=`rgb(${Math.round(D*ne+255*(1-ne))},${Math.round(L*ne+255*(1-ne))},${Math.round(q*ne+255*(1-ne))})`,e.fillRect(A,0,V,t.canvasHeight)}const E=t.visibleTimeStart,p=t.visibleTimeEnd,H=864e5/(p-E)*t.canvasWidth;let I="day";H<2?I="month":H<8&&(I="week");{let M=fe(E).startOf("day");const O=fe(p).endOf("day");let j=null,A=1,V=0;const ne=[],D=L=>{j!==null&&(e.fillStyle=j,A!==1&&(e.globalAlpha=A),e.fillRect(V,0,L-V,t.canvasHeight),A!==1&&(e.globalAlpha=1),j=null,A=1)};for(;M.isBefore(O);){const L=t.timeToX(M.valueOf()),q=M.toDate(),J=d==null?void 0:d(q);let ie=null,ae=1;if(J!=null&&J.backgroundColor)ie=J.backgroundColor,ae=J.opacity??1;else{const he=M.day();(he===0||he===6)&&(ie=r.grid.weekend)}J!=null&&J.borderColor&&ne.push({x:L,color:J.borderColor}),ie===j&&ae===A||(D(L),ie!==null&&(j=ie,A=ae,V=L)),M=M.add(1,"day")}j!==null&&D(t.timeToX(M.valueOf()));for(const L of ne)e.strokeStyle=L.color,e.lineWidth=.5,e.beginPath(),e.moveTo(L.x,0),e.lineTo(L.x,t.canvasHeight),e.stroke()}let X=fe(E).startOf(I);const $=fe(p).add(1,I);for(e.strokeStyle=r.grid.line,e.lineWidth=.5,e.beginPath();X.isBefore($);){const M=t.timeToX(X.valueOf());e.moveTo(M,0),e.lineTo(M,t.canvasHeight),X=X.add(1,I)}if(e.stroke(),c&&c.length>0)for(const M of c){const O=t.timeToX(M.start),j=t.timeToX(M.end);if(!(j<0||O>t.canvasWidth)&&(e.strokeStyle=M.color,e.globalAlpha=.4,e.lineWidth=1,e.beginPath(),O>=0&&O<=t.canvasWidth&&(e.moveTo(O,0),e.lineTo(O,t.canvasHeight)),j>=0&&j<=t.canvasWidth&&(e.moveTo(j,0),e.lineTo(j,t.canvasHeight)),e.stroke(),e.globalAlpha=1,M.label)){const A=Math.max(0,O),V=Math.min(t.canvasWidth,j)-A;e.save(),e.font='600 10px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif';const ne=e.measureText(M.label).width,D=6,L=ne+D*2,q=18,J=A+(V-L)/2,ie=4;e.fillStyle=M.color,e.globalAlpha=.9,e.beginPath(),e.roundRect(J,ie,L,q,3),e.fill(),e.globalAlpha=1,e.fillStyle="#FFFFFF",e.textBaseline="middle",e.fillText(M.label,J+D,ie+q/2),e.restore()}}}}const wt='500 12px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif';function Ot(i,e){return{roundRect(t,n,r,d,a=3){i.beginPath(),i.roundRect(t,n,r,d,a),i.fill()},fillText(t,n,r,d){if(i.font=wt,d!==void 0&&i.measureText(t).width>d){let a=0,c=t.length;for(;a<c;){const u=Math.ceil((a+c)/2),b=t.slice(0,u)+"...";i.measureText(b).width<=d?a=u:c=u-1}i.fillText(t.slice(0,a)+"...",n,r)}else i.fillText(t,n,r)},gradient(t,n,r,d){const a=i.createLinearGradient(t,0,t+n,0);return a.addColorStop(0,r),a.addColorStop(.5,r),a.addColorStop(.5,d),a.addColorStop(1,d),a},leftBar(t,n=3){e&&(i.save(),i.fillStyle=t,i.fillRect(e.x,e.y,n,e.height),i.restore())},icon(t,n,r,d=14){i.save();const a=d/2;if(t==="check"){i.fillStyle="#31c48d",i.beginPath(),i.arc(n+a,r+a,a,0,Math.PI*2),i.fill(),i.strokeStyle="#ffffff",i.lineWidth=d*.12,i.beginPath();const c=n+a,u=r+a;i.moveTo(c-a*.45,u),i.lineTo(c-a*.1,u+a*.42),i.lineTo(c+a*.45,u-a*.35),i.stroke()}else if(t==="danger-red"||t==="danger-yellow"){const c=t==="danger-red"?"#EF5350":"#FBBF24";i.fillStyle=c,i.beginPath(),i.moveTo(n+a,r),i.lineTo(n+d,r+d),i.lineTo(n,r+d),i.closePath(),i.fill(),i.fillStyle="#ffffff";const u=d*.12,b=n+a-u/2;i.fillRect(b,r+d*.35,u,d*.35),i.beginPath(),i.arc(n+a,r+d*.82,u*.7,0,Math.PI*2),i.fill()}i.restore()},badge(t,n,r,d){i.save(),i.font=wt;const c=i.measureText(t).width,u=8,E=12+3*2,p=c+u*2,y=E/2;i.fillStyle=d,i.beginPath(),i.roundRect(n,r,p,E,y),i.fill(),i.fillStyle="#ffffff",i.textAlign="center",i.textBaseline="middle",i.fillText(t,n+p/2,r+E/2),i.restore()}}}class pi{draw(e,t,n,r,d,a,c,u,b,E,p,y,k,H){const I=(t.visibleTimeEnd-t.visibleTimeStart)*.1,X=t.visibleTimeStart-I,$=t.visibleTimeEnd+I,M=d.query(X,$),O=new Map;for(let D=0;D<n.length;D++)O.set(n[D].id,D);const j=new Set(E),A=new Map,V=-t.lineHeight,ne=t.canvasHeight+t.lineHeight;for(const D of M){const L=O.get(D.group);if(L===void 0)continue;const q=a.getLayout(D.id);if(!q)continue;const ie=t.groupIndexToY(L)+q.stackLevel*t.lineHeight+(t.lineHeight-q.itemHeight)/2,ae=q.itemHeight;if(ie+ae<V||ie>ne)continue;const he=t.timeToX(D.start_time),Se=t.timeToX(D.end_time)-he,me={x:he,y:ie,width:Se,height:ae};A.set(D.id,me);const Ee={selected:j.has(D.id),hovered:p===D.id,dragging:!1,filtered:D.filtered!==!1};e.save();const We=Ot(e,me);let ke;k&&(H!=null&&H.isParent(D.id))?ke=k:u&&(D.type==="control_area_group"||D.type==="construction_train")?ke=u:ke=c,ke(e,D,me,Ee,We),e.restore()}if(y&&y.length>0){const D=new Set;for(const L of y)A.has(L.fromItemId)||D.add(L.fromItemId),A.has(L.toItemId)||D.add(L.toItemId);if(D.size>0){const L=new Map;for(const q of r)D.has(q.id)&&L.set(q.id,q);for(const[q,J]of L){const ie=O.get(J.group);if(ie===void 0)continue;const ae=a.getLayout(q);if(!ae)continue;const Se=t.groupIndexToY(ie)+ae.stackLevel*t.lineHeight+(t.lineHeight-ae.itemHeight)/2,me=t.timeToX(J.start_time),Ee=t.timeToX(J.end_time)-me;A.set(q,{x:me,y:Se,width:Ee,height:ae.itemHeight})}}this.drawDependencies(e,y,A,p,b)}}drawDependencies(e,t,n,r,d){for(const a of t){const c=n.get(a.fromItemId),u=n.get(a.toItemId);if(!c||!u)continue;const b=r===a.fromItemId||r===a.toItemId;e.strokeStyle=b?d.primary:a.color??"#94A3B8",e.lineWidth=b?2:1.5,e.setLineDash([]);const E=c.x+c.width,p=c.y+c.height/2,y=u.x,k=u.y+u.height/2,H=Math.abs(y-E),I=Math.max(H*.4,30);e.beginPath(),e.moveTo(E,p),e.bezierCurveTo(E+I,p,y-I,k,y,k),e.stroke();const X=6;e.fillStyle=e.strokeStyle,e.beginPath(),e.moveTo(y,k),e.lineTo(y-X,k-X/2),e.lineTo(y-X,k+X/2),e.closePath(),e.fill()}}}class vi{draw(e,t,n,r){const{cursorX:d,snapX:a,markers:c,interaction:u}=r;if(c)for(const b of c){const E=t.timeToX(b.date);if(e.fillStyle=b.color,e.fillRect(E-b.width/2,0,b.width,t.canvasHeight),b.label){e.save(),e.font='500 10px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif';const p=e.measureText(b.label).width,y=8,k=200,H=Math.min(p+y*2,k),I=20,X=E-H/2,$=4;e.fillStyle=b.color,e.beginPath(),e.roundRect(X,$,H,I,3),e.fill(),e.fillStyle="#FFFFFF",e.textBaseline="middle";const M=k-y*2,O=p>M?b.label.slice(0,Math.floor(b.label.length*M/p))+"…":b.label;e.fillText(O,X+y,$+I/2),e.restore()}}if(d!=null&&(e.strokeStyle=n.marker.cursor,e.lineWidth=1,e.beginPath(),e.moveTo(d,0),e.lineTo(d,t.canvasHeight),e.stroke()),a!=null&&(e.strokeStyle=n.primary,e.lineWidth=1,e.setLineDash([4,4]),e.beginPath(),e.moveTo(a,0),e.lineTo(a,t.canvasHeight),e.stroke(),e.setLineDash([])),u){u.groupChanged&&u.targetGroupY!==void 0&&(e.fillStyle="rgba(59, 130, 246, 0.08)",e.fillRect(0,u.targetGroupY,t.canvasWidth,t.lineHeight)),e.save(),e.globalAlpha=.5;const b=Ot(e,u.bounds);u.renderer(e,u.item,u.bounds,{selected:!1,hovered:!1,dragging:!0,filtered:!0},b),e.restore()}}}const Ht=120;function bi(i){let e=i.deltaY||i.deltaX;return i.deltaMode===1?e*=15:i.deltaMode===2&&(e*=800),Math.max(-Ht,Math.min(Ht,e))}class yi{constructor(e,t,n,r,d){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=n,this.minZoom=r,this.maxZoom=d}updateBounds(e,t){this.visibleTimeStart=e,this.visibleTimeEnd=t}handleWheelZoom(e,t){const n=bi(e),r=e.ctrlKey?10:e.metaKey?3:1,d=n>0?1+r*n/500:1/(1+r*-n/500),a=this.visibleTimeEnd-this.visibleTimeStart;let c=Math.round(a*d);c=Math.max(this.minZoom,Math.min(this.maxZoom,c));const u=Math.round(this.visibleTimeStart+(a-c)*t),b=u+c;this.onZoom(u,b)}}const Ti=4;class ki{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,n,r){this.state={item:e,mode:t,startX:n,startY:r,currentX:n,currentY:r,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)>=Ti&&(this.activated=!0))}setCurrentGroup(e){this.state&&(this.state.currentGroup=e)}endMove(e){if(!this.state)return null;const t=this.state.deltaX/e,n=this.state.item.start_time+t,r=Math.round(n/this.dragSnap)*this.dragSnap,d=this.state.currentGroup;return this.state=null,this.activated=!1,{newStartTime:r,newGroupId:d}}endResize(e){if(!this.state)return null;const t=this.state.deltaX/e,n=this.state.mode==="resize-left"?"left":"right",d=(n==="left"?this.state.item.start_time:this.state.item.end_time)+t,a=Math.round(d/this.dragSnap)*this.dragSnap;return this.state=null,this.activated=!1,{newTime:a,edge:n}}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 st(i,e,t){const n=[];for(const r of i)r.id!==e&&(n.push(t(r.start_time)),n.push(t(r.end_time)));return n}function Ye(i,e,t,n,r){if(e.length===0)return null;let d=e[0],a=Math.abs(i-d);for(let c=1;c<e.length;c++){const u=Math.abs(i-e[c]);u<a&&(a=u,d=e[c])}return a<=t?d:null}var Wt=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Xt(i){return i&&i.__esModule&&Object.prototype.hasOwnProperty.call(i,"default")?i.default:i}var Bt={exports:{}};(function(i,e){(function(t,n){i.exports=n()})(Wt,function(){var t="day";return function(n,r,d){var a=function(b){return b.add(4-b.isoWeekday(),t)},c=r.prototype;c.isoWeekYear=function(){return a(this).year()},c.isoWeek=function(b){if(!this.$utils().u(b))return this.add(7*(b-this.isoWeek()),t);var E,p,y,k,H=a(this),I=(E=this.isoWeekYear(),p=this.$u,y=(p?d.utc:d)().year(E).startOf("year"),k=4-y.isoWeekday(),y.isoWeekday()>4&&(k+=7),y.add(k,t));return H.diff(I,"week")+1},c.isoWeekday=function(b){return this.$utils().u(b)?this.day()||7:this.day(this.day()%7?b:b-7)};var u=c.startOf;c.startOf=function(b,E){var p=this.$utils(),y=!!p.u(E)||E;return p.p(b)==="isoweek"?y?this.date(this.date()-(this.isoWeekday()-1)).startOf("day"):this.date(this.date()-1-(this.isoWeekday()-1)+7).endOf("day"):u.bind(this)(b,E)}}})})(Bt);var Mi=Bt.exports;const Si=Xt(Mi),Rt=5;function It({groups:i,width:e,lineHeight:t,scrollTop:n,canvasHeight:r,theme:d,groupRenderer:a,onScroll:c}){var X;const u=f.useRef(null),b=f.useRef(!1),E=i.length*t,p=r,y=Math.max(0,Math.floor(n/t)-Rt),k=Math.min(i.length-1,Math.ceil((n+r)/t)+Rt),H=f.useCallback($=>{b.current||c($.currentTarget.scrollTop)},[c]);f.useEffect(()=>{u.current&&(b.current=!0,u.current.scrollTop=n,requestAnimationFrame(()=>{b.current=!1}))},[n]);const I=[];for(let $=y;$<=k;$++){const M=i[$];M&&I.push(z.jsx("div",{style:{position:"absolute",top:$*t,height:t,width:"100%",overflow:"hidden",display:"flex",alignItems:"stretch",borderBottom:`1px solid ${((X=d.grid)==null?void 0:X.line)??"#E5E5E5"}`,boxSizing:"border-box"},children:a(M)},M.id))}return z.jsx("div",{ref:u,onScroll:H,style:{width:e,height:p,overflowY:E>r?"auto":"hidden",overflowX:"hidden",position:"relative",borderRight:`1px solid ${d.sidebar.border}`,backgroundColor:d.sidebar.bg},children:z.jsx("div",{style:{height:E,position:"relative"},children:I})})}function jt(i){return null}jt.displayName="TodayMarker";function Pt(i){return{date:Math.floor(Date.now()/6e4)*6e4,color:i.color??"#FD7171",width:i.width??6,label:i.label}}function Ei(i){return i.interval??1e4}function Lt(i){return null}Lt.displayName="CustomMarker";function Dt(i){return{date:i.date,color:i.color??"#3B82F6",width:i.width??4,label:i.label}}fe.extend(Si);function Ci(i){return i?{...pe,...i,status:{...pe.status,...i.status},grid:{...pe.grid,...i.grid},item:{...pe.item,...i.item},marker:{...pe.marker,...i.marker},sidebar:{...pe.sidebar,...i.sidebar},header:{...pe.header,...i.header}}:pe}const Ft=32,wi=f.memo(f.forwardRef(function(e,t){const{groups:n,items:r,defaultTimeStart:d,defaultTimeEnd:a,sidebarWidth:c,lineHeight:u,itemHeightRatio:b,stackItems:E,canMove:p,canChangeGroup:y,canResize:k,dragSnap:H,minZoom:I,maxZoom:X,theme:$,dayStyle:M,rowStyle:O,showCursorLine:j,itemRenderer:A,groupRenderer:V,sidebarGroupRenderer:ne,dependencies:D,highlights:L,onItemClick:q,onItemDoubleClick:J,onItemContextMenu:ie,onItemMove:ae,onItemResize:he,moveResizeValidator:Se,onItemHover:me,onCanvasDoubleClick:Ee,onCanvasContextMenu:We,onTimeChange:ke,onZoom:ot,selected:lt=[],rightSidebarWidth:Ne,rightSidebarGroupRenderer:at,onReady:Xe,devBadge:$t,children:ve}=e,ge=f.useMemo(()=>Ci($),[$]),ut=f.useCallback((l,s)=>{for(let h=0;h<s.length;h++)if(s[h].id===l)return h;return 0},[]),Gt=lt.join(","),ze=f.useMemo(()=>lt,[Gt]),ct=f.useRef(null),dt=f.useRef(null),ft=f.useRef(null),Ie=f.useRef(null),ht=f.useRef(null),Vt=f.useRef(null),[Zt,qt]=f.useState(800);f.useEffect(()=>{const l=ht.current;if(!l)return;const s=new ResizeObserver(h=>{const m=h[0];m&&qt(m.contentRect.width)});return s.observe(l),()=>s.disconnect()},[]);const be=Math.max(0,Zt-c-(Ne??0)),ye=n.length*u,F=f.useRef(new tt({visibleTimeStart:e.visibleTimeStart??d,visibleTimeEnd:e.visibleTimeEnd??a,canvasWidth:be,canvasHeight:ye,sidebarWidth:c,lineHeight:u,groupCount:n.length,buffer:e.buffer??3,scrollTop:0})),$e=f.useRef(null),Pe=f.useRef(void 0),[mt,Ut]=f.useState(e.visibleTimeStart??d),[gt,Kt]=f.useState(e.visibleTimeEnd??a),[pt,Be]=f.useState(0),De=f.useRef(null),Ce=f.useCallback(()=>{const l=F.current;Ut(l.visibleTimeStart),Kt(l.visibleTimeEnd),Be(l.scrollTop),De.current=null},[]),Ge=f.useCallback(()=>{De.current===null&&(De.current=setTimeout(Ce,Ft))},[Ce]);f.useEffect(()=>()=>{De.current!==null&&clearTimeout(De.current)},[]);const Me=f.useMemo(()=>{const l=new _t;return l.rebuild(r),l},[r]),Ve=f.useMemo(()=>{const l=new di;return l.buildFromItems(r,s=>Me.getEffectiveSpan(s.id).start,s=>Me.getEffectiveSpan(s.id).end),l},[r,Me]),Ze=f.useMemo(()=>{const l=new fi(u,b);return l.computeLayout(r,E,Me),l},[r,u,b,E,Me]),vt=f.useMemo(()=>e.summaryRenderer?e.summaryRenderer:(l,s,h,m,o)=>{hi(l,s,h,m,o,ge)},[e.summaryRenderer,ge]),we=f.useMemo(()=>new gi,[]),He=f.useMemo(()=>new pi,[]),Re=f.useMemo(()=>new vi,[]),ee=f.useMemo(()=>new ki(H),[H]),je=f.useMemo(()=>{const l=[];return f.Children.forEach(ve,s=>{var m;if(!f.isValidElement(s))return;const h=(m=s.type)==null?void 0:m.displayName;h==="TodayMarker"?l.push(Pt(s.props)):h==="CustomMarker"&&l.push(Dt(s.props))}),l},[ve]),Le=f.useMemo(()=>je.map(l=>`${l.date}|${l.color}|${l.width}|${l.label??""}`).join(";"),[je]),Fe=f.useRef(je);Fe.current=je;const qe=f.useMemo(()=>{let l=0;return f.Children.forEach(ve,s=>{var m;if(!f.isValidElement(s))return;((m=s.type)==null?void 0:m.displayName)==="TodayMarker"&&(l=Ei(s.props))}),l},[ve]),_=f.useRef({groups:n,items:r,intervalTree:Ve,layoutEngine:Ze,itemRenderer:A,groupRenderer:V,theme:ge,selected:ze,dependencies:D,highlights:L,dayStyle:M,rowStyle:O,showCursorLine:j,canvasWidth:be,canvasHeight:ye,lineHeight:u,itemHeightRatio:b,onTimeChange:ke,onZoom:ot,onItemHover:me,onItemClick:q,onItemDoubleClick:J,onItemContextMenu:ie,onItemMove:ae,onItemResize:he,onCanvasDoubleClick:Ee,onCanvasContextMenu:We,canMove:p,canResize:k,canChangeGroup:y,dragSnap:H,sidebarWidth:c,moveResizeValidator:Se,summaryRenderer:vt,hierarchyEngine:Me});_.current={groups:n,items:r,intervalTree:Ve,layoutEngine:Ze,itemRenderer:A,groupRenderer:V,theme:ge,selected:ze,dependencies:D,highlights:L,dayStyle:M,rowStyle:O,showCursorLine:j,canvasWidth:be,canvasHeight:ye,lineHeight:u,itemHeightRatio:b,onTimeChange:ke,onZoom:ot,onItemHover:me,onItemClick:q,onItemDoubleClick:J,onItemContextMenu:ie,onItemMove:ae,onItemResize:he,onCanvasDoubleClick:Ee,onCanvasContextMenu:We,canMove:p,canResize:k,canChangeGroup:y,dragSnap:H,sidebarWidth:c,moveResizeValidator:Se,summaryRenderer:vt,hierarchyEngine:Me};const Jt=f.useCallback(()=>{const l=ct.current;if(!l)return;const s=_.current,h=nt(l,s.canvasWidth,s.canvasHeight);rt(h,l),we.draw(h,F.current,s.groups,s.theme,s.dayStyle,s.rowStyle,s.highlights)},[we]),Qt=f.useCallback(()=>{const l=dt.current;if(!l)return;const s=_.current,h=nt(l,s.canvasWidth,s.canvasHeight);rt(h,l),He.draw(h,F.current,s.groups,s.items,s.intervalTree,s.layoutEngine,s.itemRenderer,s.groupRenderer,s.theme,s.selected,Pe.current,s.dependencies,s.summaryRenderer,s.hierarchyEngine)},[He]),bt=f.useCallback((l,s,h)=>{const m=F.current,o=_.current,g=o.canvasWidth/(m.visibleTimeEnd-m.visibleTimeStart),T=s/g,S=[];h==="move"?(S.push(m.timeToX(l.start_time+T)),S.push(m.timeToX(l.end_time+T))):h==="resize-left"?S.push(m.timeToX(l.start_time+T)):S.push(m.timeToX(l.end_time+T));const R=(m.visibleTimeEnd-m.visibleTimeStart)*.1,W=o.intervalTree.query(m.visibleTimeStart-R,m.visibleTimeEnd+R),Z=st(W,l.id,re=>m.timeToX(re));for(const re of S){const G=Ye(re,Z,8,g,o.dragSnap);if(G!==null)return G}const Q=h==="resize-right"?l.end_time+T:l.start_time+T,P=Math.round(Q/o.dragSnap)*o.dragSnap;return m.timeToX(P)},[]),ei=f.useCallback(()=>{const l=ft.current;if(!l)return;const s=_.current,h=nt(l,s.canvasWidth,s.canvasHeight);rt(h,l);const m=F.current,o=ee.getState();let g=null;if(o){const T=m.timeToX(o.item.start_time),S=m.timeToX(o.item.end_time)-T;let R,W;o.mode==="resize-left"?(R=T+o.deltaX,W=S-o.deltaX):o.mode==="resize-right"?(R=T,W=S+o.deltaX):(R=T+o.deltaX,W=S);const Z=ut(o.currentGroup,s.groups),Q=m.groupIndexToY(Z),P=o.currentGroup!==o.originalGroup;g={item:o.item,mode:o.mode,bounds:{x:R,y:Q+(s.lineHeight-s.lineHeight*s.itemHeightRatio)/2,width:W,height:s.lineHeight*s.itemHeightRatio},renderer:s.itemRenderer,targetGroupY:Q,groupChanged:P}}Re.draw(h,m,s.theme,{cursorX:s.showCursorLine?$e.current:null,snapX:o?bt(o.item,o.deltaX,o.mode):null,markers:Fe.current,interaction:g})},[Re,ee,bt,ut]),Ue=f.useRef(null);Ue.current||(Ue.current=new mi(l=>{l.grid&&Jt(),l.items&&Qt(),l.overlay&&ei()}));const w=Ue.current;f.useEffect(()=>()=>w.dispose(),[w]),f.useEffect(()=>{if(!qe)return;const l=setInterval(()=>{const s=[];f.Children.forEach(ve,h=>{var o;if(!f.isValidElement(h))return;const m=(o=h.type)==null?void 0:o.displayName;m==="TodayMarker"?s.push(Pt(h.props)):m==="CustomMarker"&&s.push(Dt(h.props))}),Fe.current=s,w.markDirty("overlay")},qe);return()=>clearInterval(l)},[qe,ve,w]),f.useEffect(()=>{F.current.update({canvasWidth:be,canvasHeight:ye,sidebarWidth:c,lineHeight:u,groupCount:n.length}),w.markAllDirty()},[be,ye,c,u,n.length,w]),f.useEffect(()=>{w.markDirty("grid"),w.markDirty("items")},[r,n,ze,ge,M,O,Ve,Ze,w]);const xe=f.useMemo(()=>{var l;return((l=e.highlights)==null?void 0:l.map(s=>`${s.start}|${s.end}|${s.color}|${s.label??""}|${s.opacity??""}`).join(";"))??""},[e.highlights]),yt=f.useRef(xe);f.useEffect(()=>{xe!==yt.current&&(yt.current=xe,w.markDirty("grid"))},[xe,w]);const Tt=f.useRef(Le);f.useEffect(()=>{Le!==Tt.current&&(Tt.current=Le,w.markDirty("overlay"))},[Le,w]);const kt=f.useRef(e.visibleTimeStart),Mt=f.useRef(e.visibleTimeEnd);e.visibleTimeStart!==void 0&&e.visibleTimeStart!==kt.current&&(kt.current=e.visibleTimeStart,F.current.update({visibleTimeStart:e.visibleTimeStart}),w.markAllDirty()),e.visibleTimeEnd!==void 0&&e.visibleTimeEnd!==Mt.current&&(Mt.current=e.visibleTimeEnd,F.current.update({visibleTimeEnd:e.visibleTimeEnd}),w.markAllDirty());const _e=f.useRef(null),Ke=f.useCallback(l=>{_e.current===null&&(_e.current=setTimeout(()=>{var m,o;_e.current=null;const s=F.current,h=_.current;l==="zoom"?(m=h.onZoom)==null||m.call(h,s.visibleTimeStart,s.visibleTimeEnd):(o=h.onTimeChange)==null||o.call(h,s.visibleTimeStart,s.visibleTimeEnd)},Ft))},[]);f.useEffect(()=>()=>{_e.current!==null&&clearTimeout(_e.current)},[]);const Ae=f.useRef(null),Je=f.useMemo(()=>new yi((l,s)=>{var h;F.current.update({visibleTimeStart:l,visibleTimeEnd:s}),(h=Ae.current)==null||h.updateBounds(l,s),w.markAllDirty(),Ge(),Ke("zoom")},d,a,I,X),[]);Ae.current=Je;const St=f.useCallback(l=>{const s=F.current,h=s.groupCount*s.lineHeight,m=Math.max(0,h-s.canvasHeight),o=Math.max(0,Math.min(m,s.scrollTop+l));o!==s.scrollTop&&(s.update({scrollTop:o}),w.markDirty("grid"),w.markDirty("items"),w.markDirty("overlay"),Be(o))},[w]),Qe=f.useCallback(l=>{var T,S,R;const s=F.current,h=s.canvasWidth/(s.visibleTimeEnd-s.visibleTimeStart),m=l/h,o=s.visibleTimeStart+m,g=s.visibleTimeEnd+m;s.update({visibleTimeStart:o,visibleTimeEnd:g}),(T=Ae.current)==null||T.updateBounds(o,g),w.markAllDirty(),ci.flushSync(()=>Ce()),(R=(S=_.current).onTimeChange)==null||R.call(S,o,g)},[w,Ce]);f.useEffect(()=>{const l=Ie.current;if(!l)return;const s=h=>{if(h.ctrlKey||h.metaKey||h.altKey){h.preventDefault();const m=l.getBoundingClientRect(),o=(h.clientX-m.left)/m.width;Je.handleWheelZoom(h,o)}else if(h.shiftKey)h.preventDefault(),Qe(h.deltaY);else{const m=h.deltaX;m!==0&&Math.abs(m)>Math.abs(h.deltaY)?(h.preventDefault(),Qe(m)):h.deltaY!==0&&St(h.deltaY)}};return l.addEventListener("wheel",s,{passive:!1}),()=>l.removeEventListener("wheel",s)},[Je,St,Qe]);const Te=f.useRef({lastDistance:null,lastCenter:null});f.useEffect(()=>{const l=Ie.current;if(!l)return;const s=(T,S)=>Math.abs(T.clientX-S.clientX),h=(T,S,R)=>(T.clientX+S.clientX)/2-R.left,m=T=>{T.touches.length===2&&(T.preventDefault(),Te.current.lastDistance=s(T.touches[0],T.touches[1]),Te.current.lastCenter=null)},o=T=>{var S;if(T.touches.length===2&&Te.current.lastDistance!==null){T.preventDefault();const R=s(T.touches[0],T.touches[1]),W=l.getBoundingClientRect(),Q=h(T.touches[0],T.touches[1],W)/W.width;if(R!==0&&Te.current.lastDistance!==0){const P=Te.current.lastDistance/R,re=F.current,G=re.visibleTimeEnd-re.visibleTimeStart;let C=G*P;C=Math.max(I,Math.min(X,C));const v=re.visibleTimeStart+G*Q,Y=v-C*Q,x=v+C*(1-Q);re.update({visibleTimeStart:Y,visibleTimeEnd:x}),(S=Ae.current)==null||S.updateBounds(Y,x),w.markAllDirty(),Ge(),Ke("zoom")}Te.current.lastDistance=R}},g=()=>{Te.current.lastDistance=null,Te.current.lastCenter=null};return l.addEventListener("touchstart",m,{passive:!1}),l.addEventListener("touchmove",o,{passive:!1}),l.addEventListener("touchend",g),()=>{l.removeEventListener("touchstart",m),l.removeEventListener("touchmove",o),l.removeEventListener("touchend",g)}},[w,Ge,Ke]);const ti=f.useCallback(l=>{var R;const s=l.currentTarget,h=s.getBoundingClientRect(),m=l.clientX-h.left,o=l.clientY-h.top;if($e.current=m,ee.isPending()){if(ee.update(m,o),ee.isActive()){const W=ee.getState();if(W&&W.mode==="move"&&_.current.canChangeGroup){const Z=it(o,F.current,_.current.groups);Z&&ee.setCurrentGroup(Z.id)}w.markDirty("overlay")}return}_.current.showCursorLine&&w.markDirty("overlay");const g=_.current,T=Oe(m,o,F.current,g.intervalTree,g.layoutEngine,g.groups),S=T==null?void 0:T.id;if(S!==Pe.current&&(Pe.current=S,w.markDirty("items"),(R=g.onItemHover)==null||R.call(g,S??null,l.nativeEvent)),T){const W=Ct(m,T,F.current),Z=g.canResize;W==="left"&&(Z==="left"||Z==="both")||W==="right"&&(Z==="right"||Z==="both")?s.style.cursor="col-resize":g.canMove?s.style.cursor="grab":s.style.cursor="default"}else s.style.cursor="default"},[ee,w]),ii=f.useCallback(l=>{const s=_.current,h=l.currentTarget.getBoundingClientRect(),m=l.clientX-h.left,o=l.clientY-h.top,g=Oe(m,o,F.current,s.intervalTree,s.layoutEngine,s.groups);if(!g)return;const T=Ct(m,g,F.current),S=s.canResize;T==="left"&&(S==="left"||S==="both")?ee.startInteraction(g,"resize-left",m,o):T==="right"&&(S==="right"||S==="both")?ee.startInteraction(g,"resize-right",m,o):s.canMove&&ee.startInteraction(g,"move",m,o)},[ee]),ni=f.useCallback(l=>{var T,S,R,W,Z,Q;const s=l.currentTarget;if(ee.isActive()){const P=ee.getState(),re=F.current,G=re.canvasWidth/(re.visibleTimeEnd-re.visibleTimeStart);if(P){const C=_.current.moveResizeValidator;if(P.mode==="move"){const v=ee.endMove(G);if(v){const Y=F.current,x=_.current,oe=P.deltaX/G,ce=Y.timeToX(P.item.start_time+oe),B=Y.timeToX(P.item.end_time+oe),U=(Y.visibleTimeEnd-Y.visibleTimeStart)*.1,te=x.intervalTree.query(Y.visibleTimeStart-U,Y.visibleTimeEnd+U),N=st(te,P.item.id,de=>Y.timeToX(de));let se=v.newStartTime;const K=Ye(ce,N,8,G,x.dragSnap);if(K!==null)se=Y.xToTime(K);else{const de=Ye(B,N,8,G,x.dragSnap);if(de!==null){const ui=P.item.end_time-P.item.start_time;se=Y.xToTime(de)-ui}}const le=C?C("move",P.item.id,se):se,ue=_.current.hierarchyEngine.getMoveDelta(P.item.id,le);(S=(T=_.current).onItemMove)==null||S.call(T,P.item.id,le,v.newGroupId,ue.length>0?ue:void 0)}}else{const v=ee.endResize(G);if(v){const Y=F.current,x=_.current,oe=P.deltaX/G,ce=v.edge==="left"?P.item.start_time+oe:P.item.end_time+oe,B=Y.timeToX(ce),U=(Y.visibleTimeEnd-Y.visibleTimeStart)*.1,te=x.intervalTree.query(Y.visibleTimeStart-U,Y.visibleTimeEnd+U),N=st(te,P.item.id,de=>Y.timeToX(de)),se=Ye(B,N,8,G,x.dragSnap);let K=se!==null?Y.xToTime(se):v.newTime;const le=_.current.hierarchyEngine.getResizeConstraint(P.item.id,v.edge);v.edge==="left"&&K>le.max?K=le.max:v.edge==="right"&&K<le.min&&(K=le.min);const ue=C?C("resize",P.item.id,K,v.edge):K;(W=(R=_.current).onItemResize)==null||W.call(R,P.item.id,ue,v.edge)}}}s.style.cursor="default",w.markDirty("overlay");return}ee.isPending()&&ee.cancel();const h=s.getBoundingClientRect(),m=l.clientX-h.left,o=l.clientY-h.top,g=Oe(m,o,F.current,_.current.intervalTree,_.current.layoutEngine,_.current.groups);g&&((Q=(Z=_.current).onItemClick)==null||Q.call(Z,g.id,l.nativeEvent))},[ee,w]),ri=f.useCallback(l=>{var T,S;const s=l.currentTarget.getBoundingClientRect(),h=l.clientX-s.left,m=l.clientY-s.top,o=_.current,g=Oe(h,m,F.current,o.intervalTree,o.layoutEngine,o.groups);if(g)(T=o.onItemDoubleClick)==null||T.call(o,g.id,l.nativeEvent);else{const R=it(m,F.current,o.groups),W=F.current.xToTime(h);R&&((S=o.onCanvasDoubleClick)==null||S.call(o,R.id,W))}},[]),si=f.useCallback(l=>{var T,S;l.preventDefault();const s=l.currentTarget.getBoundingClientRect(),h=l.clientX-s.left,m=l.clientY-s.top,o=_.current,g=Oe(h,m,F.current,o.intervalTree,o.layoutEngine,o.groups);if(g)(T=o.onItemContextMenu)==null||T.call(o,g.id,l.nativeEvent);else{const R=it(m,F.current,o.groups),W=F.current.xToTime(h);R&&((S=o.onCanvasContextMenu)==null||S.call(o,R.id,W,l.nativeEvent))}},[]),oi=f.useCallback(()=>{var l,s;$e.current=null,Ie.current&&(Ie.current.style.cursor="default"),Pe.current!==void 0&&(Pe.current=void 0,w.markDirty("items"),(s=(l=_.current).onItemHover)==null||s.call(l,null,new PointerEvent("pointerleave"))),_.current.showCursorLine&&w.markDirty("overlay")},[w]),li=f.useMemo(()=>{const l=[];return f.Children.forEach(ve,s=>{var m;if(!f.isValidElement(s))return;if(((m=s.type)==null?void 0:m.displayName)==="TimelineHeaders"){const o=s.props;l.push(f.cloneElement(s,{visibleTimeStart:o.visibleTimeStart??mt,visibleTimeEnd:o.visibleTimeEnd??gt,canvasWidth:o.canvasWidth??be,sidebarWidth:o.sidebarWidth??c,theme:o.theme??ge,onZoomToInterval:o.onZoomToInterval??((g,T)=>{var S,R,W,Z;F.current.update({visibleTimeStart:g,visibleTimeEnd:T}),w.markAllDirty(),Ce(),(R=(S=_.current).onTimeChange)==null||R.call(S,g,T),(Z=(W=_.current).onZoom)==null||Z.call(W,g,T)})}))}}),l},[ve,mt,gt,be,c,ge,w,Ce]),Et=f.useRef(!1);f.useEffect(()=>{Et.current||(Et.current=!0,w.markAllDirty())},[w]),f.useImperativeHandle(t,()=>({captureToCanvas({timeStart:l,timeEnd:s,scale:h,sidebarWidth:m}){const o=_.current,g=28,T=g*3,S=o.groups.length*o.lineHeight,R=F.current,W=o.canvasWidth/(R.visibleTimeEnd-R.visibleTimeStart),Z=s-l,Q=Math.max(o.canvasWidth,Math.round(Z*W)),P=(m+Q)*h,re=(T+S)*h,G=document.createElement("canvas");G.width=P,G.height=re;const C=G.getContext("2d");C.scale(h,h);for(let x=0;x<o.groups.length;x++){const oe=o.groups[x],ce=T+x*o.lineHeight;if(o.rowStyle){const N=o.rowStyle(oe);N!=null&&N.backgroundColor&&(C.fillStyle=N.backgroundColor,C.fillRect(0,ce,m,o.lineHeight))}const B=oe.type;let U="400",te=8;B==="project"?U="700":B==="CAG"?U="600":B==="CA"&&(U="400",te=24),C.fillStyle="#111",C.font=`${U} 12px sans-serif`,C.textBaseline="middle",C.fillText(oe.title,te,ce+o.lineHeight/2,m-te-4)}const v=(x,oe,ce)=>{var te,N;C.fillStyle=((te=o.theme.header)==null?void 0:te.bg)??"#f5f5f5",C.fillRect(m,x,Q,g),C.strokeStyle=((N=o.theme.grid)==null?void 0:N.line)??"#e0e0e0",C.lineWidth=1,C.strokeRect(m,x,Q,g);let B=fe(l).startOf(ce);B.valueOf()<l&&(B=B.add(1,ce));const U=Q/(s-l);for(;B.valueOf()<s;){const se=B.add(1,ce),K=m+(B.valueOf()-l)*U,ue=m+(Math.min(se.valueOf(),s)-l)*U-K;C.beginPath(),C.moveTo(K,x),C.lineTo(K,x+g),C.stroke(),C.fillStyle="#333",C.font="600 11px sans-serif",C.textBaseline="middle",C.textAlign="center",C.fillText(oe(B),K+ue/2,x+g/2,ue-4),B=se}C.textAlign="start"};v(0,x=>x.format("YYYY"),"year"),v(g,x=>x.format("MM"),"month"),v(g*2,x=>String(x.isoWeek()),"week");const Y=new tt({visibleTimeStart:l,visibleTimeEnd:s,canvasWidth:Q,canvasHeight:S,sidebarWidth:0,lineHeight:o.lineHeight,groupCount:o.groups.length,buffer:1,scrollTop:0});return C.save(),C.translate(m,T),C.beginPath(),C.rect(0,0,Q,S),C.clip(),we.draw(C,Y,o.groups,o.theme,o.dayStyle,o.rowStyle,o.highlights),He.draw(C,Y,o.groups,o.items,o.intervalTree,o.layoutEngine,o.itemRenderer,o.groupRenderer,o.theme,o.selected,void 0,o.dependencies,o.summaryRenderer,o.hierarchyEngine),Re.draw(C,Y,o.theme,{cursorX:null,snapX:null,markers:Fe.current,interaction:null}),C.restore(),G}}),[we,He,Re]),f.useEffect(()=>{const l={captureToCanvas({timeStart:s,timeEnd:h,scale:m,sidebarWidth:o}){var ce;const g=_.current,T=28,S=T*3,R=g.groups.length*g.lineHeight,W=F.current,Z=g.canvasWidth/(W.visibleTimeEnd-W.visibleTimeStart),Q=h-s,P=Math.max(g.canvasWidth,Math.round(Q*Z)),re=o+P,G=S+R,C=document.createElement("canvas");C.width=re*m,C.height=G*m;const v=C.getContext("2d");v.scale(m,m),v.fillStyle="#FFFFFF",v.fillRect(0,0,re,G),v.save(),v.beginPath(),v.rect(0,0,o,G),v.clip(),v.fillStyle="#F9FAFB",v.fillRect(0,0,o,S),v.strokeStyle="#E5E7EB",v.lineWidth=1,v.strokeRect(0,0,o,S);for(let B=0;B<g.groups.length;B++){const U=g.groups[B],te=S+B*g.lineHeight,N=(ce=g.rowStyle)==null?void 0:ce.call(g,U);v.fillStyle=(N==null?void 0:N.backgroundColor)??(B%2===0?"#FFFFFF":"#F7F7F7"),v.fillRect(0,te,o,g.lineHeight),v.strokeStyle="#E5E5E5",v.lineWidth=.5,v.beginPath(),v.moveTo(0,te+g.lineHeight),v.lineTo(o,te+g.lineHeight),v.stroke();const se=U.type??"";let K=8,le="400",ue=11;se==="project"?(le="700",ue=12):se==="control_area_group"?le="600":se==="control_area"&&(K=24),v.fillStyle="#374151",v.font=`${le} ${ue}px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif`,v.textBaseline="middle";const de=typeof U.title=="string"?U.title:String(U.title);v.fillText(de,K,te+g.lineHeight/2,o-K-8)}v.strokeStyle="#E5E7EB",v.lineWidth=1,v.beginPath(),v.moveTo(o,0),v.lineTo(o,G),v.stroke(),v.restore(),v.save(),v.beginPath(),v.rect(o,0,P,S),v.clip();const Y=h-s,x=[{unit:"year",row:0},{unit:"month",row:1},{unit:"week",row:2}];for(const{unit:B,row:U}of x){const te=U*T;v.fillStyle="#F9FAFB",v.fillRect(o,te,P,T);let N=fe(s).startOf(B);const se=fe(h).add(1,B);for(;N.isBefore(se);){const K=N.add(1,B),le=o+(N.valueOf()-s)/Y*P,ue=(K.valueOf()-N.valueOf())/Y*P;v.strokeStyle="#E5E7EB",v.lineWidth=.5,v.strokeRect(le,te,ue,T);let de;B==="year"?de=N.format("YYYY"):B==="month"?de=N.format("MM"):de=`${N.week()}`,v.fillStyle="#6c737f",v.font=B==="year"?'600 11px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif':'400 11px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',v.textBaseline="middle",v.textAlign="center",ue>20&&v.fillText(de,le+ue/2,te+T/2),N=K}}v.textAlign="start",v.restore(),v.save(),v.beginPath(),v.rect(o,S,P,R),v.clip(),v.translate(o,S);const oe=new tt({visibleTimeStart:s,visibleTimeEnd:h,canvasWidth:P,canvasHeight:R,sidebarWidth:0,lineHeight:g.lineHeight,groupCount:g.groups.length,buffer:1,scrollTop:0});return we.draw(v,oe,g.groups,g.theme,g.dayStyle,g.rowStyle,g.highlights),He.draw(v,oe,g.groups,g.items,g.intervalTree,g.layoutEngine,g.itemRenderer,g.groupRenderer,g.theme,g.selected,void 0,g.dependencies,g.summaryRenderer,g.hierarchyEngine),Re.draw(v,oe,g.theme,{cursorX:null,markers:Fe.current}),v.restore(),C}};Xe==null||Xe(l)},[Xe,we,He,Re]);const ai={position:"relative",width:be,height:ye,overflow:"hidden",cursor:"default"},et={position:"absolute",top:0,left:0};return z.jsxs("div",{ref:ht,style:{display:"flex",flexDirection:"column",width:"100%",position:"relative"},children:[$t?z.jsxs("div",{style:{position:"absolute",top:0,left:0,zIndex:9999,padding:"2px 6px",fontSize:10,fontFamily:"ui-monospace, SFMono-Regular, Menlo, monospace",lineHeight:1.4,color:"#fff",background:"rgba(17, 24, 39, 0.78)",borderBottomRightRadius:4,pointerEvents:"none",userSelect:"none"},children:["v","0.4.0"," · ","11:57:07"]}):null,li,z.jsxs("div",{ref:Vt,style:{display:"flex",overflow:"hidden"},children:[z.jsx(It,{groups:n,width:c,lineHeight:u,scrollTop:pt,canvasHeight:ye,theme:ge,groupRenderer:ne,onScroll:l=>{F.current.update({scrollTop:l}),w.markDirty("grid"),w.markDirty("items"),w.markDirty("overlay"),Be(l)}}),z.jsxs("div",{ref:Ie,style:ai,onPointerMove:ti,onPointerDown:ii,onPointerUp:ni,onDoubleClick:ri,onContextMenu:si,onPointerLeave:oi,children:[z.jsx("canvas",{ref:ct,style:{...et,zIndex:0}}),z.jsx("canvas",{ref:dt,style:{...et,zIndex:1}}),z.jsx("canvas",{ref:ft,style:{...et,zIndex:2}})]}),Ne&&at?z.jsx(It,{groups:n,width:Ne,lineHeight:u,scrollTop:pt,canvasHeight:ye,theme:ge,groupRenderer:at,onScroll:l=>{F.current.update({scrollTop:l}),w.markDirty("grid"),w.markDirty("items"),w.markDirty("overlay"),Be(l)}}):null]})]})}));function xt({children:i,theme:e,className:t,classNames:n,style:r,visibleTimeStart:d,visibleTimeEnd:a,canvasWidth:c,sidebarWidth:u=0,onZoomToInterval:b}){const E=f.Children.map(i,p=>{var k;if(!f.isValidElement(p))return p;if(((k=p.type)==null?void 0:k.displayName)==="DateHeader"){const H=p.props,I=f.cloneElement(p,{visibleTimeStart:H.visibleTimeStart??d,visibleTimeEnd:H.visibleTimeEnd??a,canvasWidth:H.canvasWidth??c,theme:H.theme??e,onZoomToInterval:H.onIntervalClick??H.onZoomToInterval??b});return z.jsxs("div",{style:{display:"flex"},children:[z.jsx("div",{style:{width:u,flexShrink:0}}),z.jsx("div",{style:{flex:1,overflow:"hidden"},children:I})]})}return p});return z.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"}`,...r},children:E})}xt.displayName="TimelineHeaders";var At={exports:{}};(function(i,e){(function(t,n){i.exports=n()})(Wt,function(){var t="week",n="year";return function(r,d,a){var c=d.prototype;c.week=function(u){if(u===void 0&&(u=null),u!==null)return this.add(7*(u-this.week()),"day");var b=this.$locale().yearStart||1;if(this.month()===11&&this.date()>25){var E=a(this).startOf(n).add(1,n).date(b),p=a(this).endOf(t);if(E.isBefore(p))return 1}var y=a(this).startOf(n).date(b).startOf(t).subtract(1,"millisecond"),k=this.diff(y,t,!0);return k<0?a(this).startOf("week").week():Math.ceil(k)},c.weeks=function(u){return u===void 0&&(u=null),this.week(u)}}})})(At);var Hi=At.exports;const Ri=Xt(Hi);fe.extend(Ri);const Ii={year:30,month:30,week:20,day:15,hour:30};function Yt({unit:i,visibleTimeStart:e=0,visibleTimeEnd:t=0,canvasWidth:n=0,theme:r,height:d=28,className:a,labelFormat:c,onIntervalClick:u,minCellWidth:b,onZoomToInterval:E}){const p=f.useMemo(()=>{if(!e||!t||!n)return[];const k=t-e,H=b??Ii[i];if(H>0){const M=fe(e).startOf(i);if((M.add(1,i).valueOf()-M.valueOf())/k*n<H)return[]}const I=[];let X=fe(e).startOf(i).subtract(1,i);const $=fe(t).add(2,i).valueOf();for(;X.valueOf()<$;){const M=X.add(1,i),O=X.valueOf(),j=M.valueOf(),A=(O-e)/k*n,V=(j-O)/k*n,ne=Pi(X,M,i,c);I.push({start:O,end:j,label:ne,left:A,width:V}),X=M}return I},[e,t,n,i,c,b]),y=f.useCallback((k,H)=>{u?u(k,H):E&&E(k,H)},[u,E]);return p.length===0?null:z.jsx("div",{style:{display:"flex",position:"relative",height:d,overflow:"hidden"},children:p.map(k=>z.jsx("div",{className:a,onClick:()=>y(k.start,k.end),style:{position:"absolute",left:k.left,width:k.width,height:"100%",display:"flex",alignItems:"center",justifyContent:"center",borderRight:`1px solid ${(r==null?void 0:r.header.border)??"#E5E7EB"}`,borderBottom:`1px solid ${(r==null?void 0:r.header.border)??"#E5E7EB"}`,fontSize:12,color:(r==null?void 0:r.header.text)??"#6c737f",backgroundColor:(r==null?void 0:r.header.bg)??"#F9FAFB",overflow:"hidden",whiteSpace:"nowrap",cursor:"pointer",userSelect:"none",padding:"0 4px",boxSizing:"border-box"},children:z.jsx("span",{children:k.label})},k.start))})}Yt.displayName="DateHeader";function Pi(i,e,t,n,r){return typeof n=="function"?n(i.toDate(),e.toDate(),t):typeof n=="string"?i.format(n):Di(i,t)}function Di(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 Nt({width:i,children:e,style:t}){const n=()=>({style:{width:i,...t}});return e?z.jsx(z.Fragment,{children:e({getRootProps:n})}):z.jsx("div",{style:{width:i}})}Nt.displayName="SidebarHeader";function zt({children:i}){return z.jsx(z.Fragment,{children:i})}zt.displayName="CustomHeader";exports.CanvasTimeline=wi;exports.CustomHeader=zt;exports.CustomMarker=Lt;exports.DEFAULT_THEME=pe;exports.DateHeader=Yt;exports.HierarchyEngine=_t;exports.SidebarHeader=Nt;exports.TimelineHeaders=xt;exports.TodayMarker=jt;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const $=require("react/jsx-runtime"),f=require("react"),hi=require("react-dom"),fe=require("dayjs"),be={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 rt{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),n=Math.min(this.groupCount-1,e+t);return{firstVisible:e,lastVisible:n}}isScrollInBuffer(e){const t=this.visibleDuration*1.5*this.pixelsPerMs;return Math.abs(e)<t}getTotalHeight(){return this.groupCount*this.lineHeight}}class mi{constructor(){Object.defineProperty(this,"root",{enumerable:!0,configurable:!0,writable:!0,value:null})}buildFromItems(e,t,n){const o=e.map(d=>({item:d,start:t(d),end:n(d)}));this.root=this.buildNode(o)}buildNode(e){if(e.length===0)return null;let t=1/0,n=-1/0;for(const u of e)u.start<t&&(t=u.start),u.end>n&&(n=u.end);const o=(t+n)/2,d=[],a=[],c=[];for(const u of e)u.end<o?d.push(u):u.start>o?a.push(u):c.push(u);return{center:o,left:this.buildNode(d),right:this.buildNode(a),overlapping:c}}query(e,t){const n=[];return this.queryNode(this.root,e,t,n),n}queryNode(e,t,n,o){if(e!==null){for(const d of e.overlapping)d.start<=n&&d.end>=t&&o.push(d.item);t<=e.center&&e.left!==null&&this.queryNode(e.left,t,n,o),n>=e.center&&e.right!==null&&this.queryNode(e.right,t,n,o)}}}class gi{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,n){this.layoutCache=new Map,this.groupMaxStack=new Map;const o=this.lineHeight*this.itemHeightRatio,d=o*.6;if(!t){for(const c of e){const u=(n==null?void 0:n.isParent(c.id))??!1;this.layoutCache.set(c.id,{stackLevel:0,itemHeight:u?d:o}),this.groupMaxStack.set(c.group,0)}return this.layoutCache}const a=new Map;for(const c of e){let u=a.get(c.group);u||(u=[],a.set(c.group,u)),u.push(c)}for(const[c,u]of a)n?this.computeHierarchyLayout(u,n,o,d,c):this.computeFlatLayout(u,o,c);return this.layoutCache}computeFlatLayout(e,t,n){e.sort((a,c)=>{const u=a.start_time-c.start_time;return u!==0?u:c.end_time-c.start_time-(a.end_time-a.start_time)});const o=[];let d=0;for(const a of e){let c=-1;for(let u=0;u<o.length;u++)if(o[u]<=a.start_time){c=u;break}c===-1?(c=o.length,o.push(a.end_time)):o[c]=a.end_time,c>d&&(d=c),this.layoutCache.set(a.id,{stackLevel:c,itemHeight:t})}this.groupMaxStack.set(n,d)}computeHierarchyLayout(e,t,n,o,d){const a=[],c=[];for(const p of e)t.isParent(p.id)?c.push(p):a.push(p);a.sort((p,y)=>{const M=p.start_time-y.start_time;return M!==0?M:y.end_time-y.start_time-(p.end_time-p.start_time)});const u=[];let v=0;for(const p of a){let y=-1;for(let M=0;M<u.length;M++)if(u[M]<=p.start_time){y=M;break}y===-1?(y=u.length,u.push(p.end_time)):u[y]=p.end_time,y>v&&(v=y),this.layoutCache.set(p.id,{stackLevel:y,itemHeight:n})}c.sort((p,y)=>t.getNestingDepth(y.id)-t.getNestingDepth(p.id));let E=a.length>0?v+1:0;for(const p of c)this.layoutCache.set(p.id,{stackLevel:E,itemHeight:o}),E>v&&(v=E),E++;this.groupMaxStack.set(d,v)}getLayout(e){return this.layoutCache.get(e)}getGroupHeight(e){return((this.groupMaxStack.get(e)??0)+1)*this.lineHeight}}class Wt{constructor(){Object.defineProperty(this,"parentToChildren",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"childToParent",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"itemMap",{enumerable:!0,configurable:!0,writable:!0,value:new Map}),Object.defineProperty(this,"depthCache",{enumerable:!0,configurable:!0,writable:!0,value:new Map})}rebuild(e){this.parentToChildren=new Map,this.childToParent=new Map,this.itemMap=new Map,this.depthCache=new Map;for(const t of e)this.itemMap.set(t.id,t);for(const t of e)if(t.parentId!==void 0&&this.itemMap.has(t.parentId)){this.childToParent.set(t.id,t.parentId);let n=this.parentToChildren.get(t.parentId);n||(n=[],this.parentToChildren.set(t.parentId,n)),n.push(t.id)}for(const t of this.childToParent.keys()){const n=new Set;let o=t;for(;o!==void 0;){if(n.has(o)){const d=this.childToParent.get(t);this.childToParent.delete(t);const a=this.parentToChildren.get(d);if(a){const c=a.indexOf(t);c!==-1&&a.splice(c,1),a.length===0&&this.parentToChildren.delete(d)}break}n.add(o),o=this.childToParent.get(o)}}}isParent(e){const t=this.parentToChildren.get(e);return t!==void 0&&t.length>0}getParent(e){return this.childToParent.get(e)}getChildren(e){return this.parentToChildren.get(e)??[]}getDescendants(e){const t=[],n=[...this.getChildren(e)];for(;n.length>0;){const o=n.pop();t.push(o);const d=this.parentToChildren.get(o);d&&n.push(...d)}return t}getEffectiveSpan(e){const t=this.itemMap.get(e);if(!t)return{start:0,end:0};let n=t.start_time,o=t.end_time;const d=this.getDescendants(e);for(const a of d){const c=this.itemMap.get(a);c&&(c.start_time<n&&(n=c.start_time),c.end_time>o&&(o=c.end_time))}return{start:n,end:o}}getNestingDepth(e){const t=this.depthCache.get(e);if(t!==void 0)return t;let n=0,o=this.childToParent.get(e);for(;o!==void 0;)n++,o=this.childToParent.get(o);return this.depthCache.set(e,n),n}getMoveDelta(e,t){const n=this.itemMap.get(e);if(!n)return[];const o=t-n.start_time;return this.getDescendants(e).map(a=>{const c=this.itemMap.get(a);return{itemId:a,newStart:c.start_time+o}})}getResizeConstraint(e,t){const n=this.getDescendants(e);if(n.length===0)return t==="left"?{min:-1/0,max:1/0}:{min:-1/0,max:1/0};if(t==="left"){let o=1/0;for(const d of n){const a=this.itemMap.get(d);a&&a.start_time<o&&(o=a.start_time)}return{min:-1/0,max:o}}else{let o=-1/0;for(const d of n){const a=this.itemMap.get(d);a&&a.end_time>o&&(o=a.end_time)}return{min:o,max:1/0}}}}function pi(i,e,t,n,o,d){const{x:a,y:c,width:u,height:v}=t,E=d.primary;i.globalAlpha=.15,i.fillStyle=E,i.fillRect(a,c,u,v),i.globalAlpha=1,i.strokeStyle=E,i.lineWidth=1.5,i.strokeRect(a,c,u,v);const p=Math.min(v*.5,6),y=c+v/2;i.fillStyle=E,i.beginPath(),i.moveTo(a,y),i.lineTo(a+p,y-p),i.lineTo(a+p*2,y),i.lineTo(a+p,y+p),i.closePath(),i.fill(),i.beginPath(),i.moveTo(a+u,y),i.lineTo(a+u-p,y-p),i.lineTo(a+u-p*2,y),i.lineTo(a+u-p,y+p),i.closePath(),i.fill();const M=e.title;if(M&&u>30){i.fillStyle=d.item.text,i.font='500 11px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif',i.textBaseline="middle";const H=i.measureText(M).width,P=u-p*4-4;if(P>20){const W=H>P?M.slice(0,Math.floor(M.length*P/H))+"...":M;i.fillText(W,a+u/2-Math.min(H,P)/2,y)}}n.selected&&(i.strokeStyle=d.item.selectedRing,i.lineWidth=2,i.strokeRect(a-1,c-1,u+2,v+2))}function Be(i,e,t,n,o,d){const a=t.xToTime(i),c=new Map;for(let p=0;p<d.length;p++)c.set(d[p].id,p);const u=n.query(a,a);let v=null,E=-1/0;for(const p of u){const y=c.get(p.group);if(y===void 0)continue;const M=o.getLayout(p.id);if(!M)continue;const H=t.timeToX(p.start_time),P=t.timeToX(p.end_time)-H;if(i<H||i>H+P)continue;const G=t.groupIndexToY(y)+M.stackLevel*t.lineHeight+(t.lineHeight-M.itemHeight)/2,k=M.itemHeight;e<G||e>G+k||G>E&&(E=G,v=p)}return v}function st(i,e,t){const n=e.yToGroupIndex(i);return t[n]??null}function Rt(i,e,t,n=6){const o=t.timeToX(e.start_time),d=t.timeToX(e.end_time);return i-o<=n?"left":d-i<=n?"right":"body"}function ot(i,e,t){const n=window.devicePixelRatio||1,o=Math.round(e*n),d=Math.round(t*n);(i.width!==o||i.height!==d)&&(i.width=o,i.height=d,i.style.width=`${e}px`,i.style.height=`${t}px`);const a=i.getContext("2d");return a.setTransform(n,0,0,n,0,0),a}function lt(i,e){const t=window.devicePixelRatio||1;i.clearRect(0,0,e.width/t,e.height/t)}class bi{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 vi{draw(e,t,n,o,d,a,c){const{firstVisible:u,lastVisible:v}=t.getVisibleGroupRange();for(let k=u;k<=v;k++){const O=t.groupIndexToY(k),j=n[k];if(!j)continue;let x;const q=a==null?void 0:a(j);q!=null&&q.backgroundColor?x=q.backgroundColor:x=k%2===0?"#FFFFFF":o.grid.rowAlt,e.fillStyle=x,e.fillRect(0,O,t.canvasWidth,t.lineHeight),e.strokeStyle=(q==null?void 0:q.borderBottomColor)??o.grid.line,e.lineWidth=.5,e.beginPath(),e.moveTo(0,O+t.lineHeight),e.lineTo(t.canvasWidth,O+t.lineHeight),e.stroke()}if(c&&c.length>0)for(const k of c){const O=t.timeToX(k.start),j=t.timeToX(k.end);if(j<0||O>t.canvasWidth)continue;const x=Math.max(0,O),q=Math.min(t.canvasWidth,j)-x,ne=k.opacity??.12,D=parseInt(k.color.slice(1,3),16),L=parseInt(k.color.slice(3,5),16),U=parseInt(k.color.slice(5,7),16);e.fillStyle=`rgb(${Math.round(D*ne+255*(1-ne))},${Math.round(L*ne+255*(1-ne))},${Math.round(U*ne+255*(1-ne))})`,e.fillRect(x,0,q,t.canvasHeight)}const E=t.visibleTimeStart,p=t.visibleTimeEnd,H=864e5/(p-E)*t.canvasWidth;let P="day";H<2?P="month":H<8&&(P="week");{let k=fe(E).startOf("day");const O=fe(p).endOf("day");let j=null,x=1,q=0;const ne=[],D=L=>{j!==null&&(e.fillStyle=j,x!==1&&(e.globalAlpha=x),e.fillRect(q,0,L-q,t.canvasHeight),x!==1&&(e.globalAlpha=1),j=null,x=1)};for(;k.isBefore(O);){const L=t.timeToX(k.valueOf()),U=k.toDate(),Q=d==null?void 0:d(U);let ie=null,ae=1;if(Q!=null&&Q.backgroundColor)ie=Q.backgroundColor,ae=Q.opacity??1;else{const me=k.day();(me===0||me===6)&&(ie=o.grid.weekend)}Q!=null&&Q.borderColor&&ne.push({x:L,color:Q.borderColor}),ie===j&&ae===x||(D(L),ie!==null&&(j=ie,x=ae,q=L)),k=k.add(1,"day")}j!==null&&D(t.timeToX(k.valueOf()));for(const L of ne)e.strokeStyle=L.color,e.lineWidth=.5,e.beginPath(),e.moveTo(L.x,0),e.lineTo(L.x,t.canvasHeight),e.stroke()}let W=fe(E).startOf(P);const G=fe(p).add(1,P);for(e.strokeStyle=o.grid.line,e.lineWidth=.5,e.beginPath();W.isBefore(G);){const k=t.timeToX(W.valueOf());e.moveTo(k,0),e.lineTo(k,t.canvasHeight),W=W.add(1,P)}if(e.stroke(),c&&c.length>0)for(const k of c){const O=t.timeToX(k.start),j=t.timeToX(k.end);if(!(j<0||O>t.canvasWidth)&&(e.strokeStyle=k.color,e.globalAlpha=.4,e.lineWidth=1,e.beginPath(),O>=0&&O<=t.canvasWidth&&(e.moveTo(O,0),e.lineTo(O,t.canvasHeight)),j>=0&&j<=t.canvasWidth&&(e.moveTo(j,0),e.lineTo(j,t.canvasHeight)),e.stroke(),e.globalAlpha=1,k.label)){const x=Math.max(0,O),q=Math.min(t.canvasWidth,j)-x;e.save(),e.font='600 10px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif';const ne=e.measureText(k.label).width,D=6,L=ne+D*2,U=18,Q=x+(q-L)/2,ie=4;e.fillStyle=k.color,e.globalAlpha=.9,e.beginPath(),e.roundRect(Q,ie,L,U,3),e.fill(),e.globalAlpha=1,e.fillStyle="#FFFFFF",e.textBaseline="middle",e.fillText(k.label,Q+D,ie+U/2),e.restore()}}}}const It='500 12px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif';function Bt(i,e){return{roundRect(t,n,o,d,a=3){i.beginPath(),i.roundRect(t,n,o,d,a),i.fill()},fillText(t,n,o,d){if(i.font=It,d!==void 0&&i.measureText(t).width>d){let a=0,c=t.length;for(;a<c;){const u=Math.ceil((a+c)/2),v=t.slice(0,u)+"...";i.measureText(v).width<=d?a=u:c=u-1}i.fillText(t.slice(0,a)+"...",n,o)}else i.fillText(t,n,o)},gradient(t,n,o,d){const a=i.createLinearGradient(t,0,t+n,0);return a.addColorStop(0,o),a.addColorStop(.5,o),a.addColorStop(.5,d),a.addColorStop(1,d),a},leftBar(t,n=3){e&&(i.save(),i.fillStyle=t,i.fillRect(e.x,e.y,n,e.height),i.restore())},icon(t,n,o,d=14){i.save();const a=d/2;if(t==="check"){i.fillStyle="#31c48d",i.beginPath(),i.arc(n+a,o+a,a,0,Math.PI*2),i.fill(),i.strokeStyle="#ffffff",i.lineWidth=d*.12,i.beginPath();const c=n+a,u=o+a;i.moveTo(c-a*.45,u),i.lineTo(c-a*.1,u+a*.42),i.lineTo(c+a*.45,u-a*.35),i.stroke()}else if(t==="danger-red"||t==="danger-yellow"){const c=t==="danger-red"?"#EF5350":"#FBBF24";i.fillStyle=c,i.beginPath(),i.moveTo(n+a,o),i.lineTo(n+d,o+d),i.lineTo(n,o+d),i.closePath(),i.fill(),i.fillStyle="#ffffff";const u=d*.12,v=n+a-u/2;i.fillRect(v,o+d*.35,u,d*.35),i.beginPath(),i.arc(n+a,o+d*.82,u*.7,0,Math.PI*2),i.fill()}i.restore()},badge(t,n,o,d){i.save(),i.font=It;const c=i.measureText(t).width,u=8,E=12+3*2,p=c+u*2,y=E/2;i.fillStyle=d,i.beginPath(),i.roundRect(n,o,p,E,y),i.fill(),i.fillStyle="#ffffff",i.textAlign="center",i.textBaseline="middle",i.fillText(t,n+p/2,o+E/2),i.restore()}}}class yi{draw(e,t,n,o,d,a,c,u,v,E,p,y,M,H){const P=(t.visibleTimeEnd-t.visibleTimeStart)*.1,W=t.visibleTimeStart-P,G=t.visibleTimeEnd+P,k=d.query(W,G),O=new Map;for(let D=0;D<n.length;D++)O.set(n[D].id,D);const j=new Set(E),x=new Map,q=-t.lineHeight,ne=t.canvasHeight+t.lineHeight;for(const D of k){const L=O.get(D.group);if(L===void 0)continue;const U=a.getLayout(D.id);if(!U)continue;const ie=t.groupIndexToY(L)+U.stackLevel*t.lineHeight+(t.lineHeight-U.itemHeight)/2,ae=U.itemHeight;if(ie+ae<q||ie>ne)continue;const me=t.timeToX(D.start_time),Ce=t.timeToX(D.end_time)-me,ge={x:me,y:ie,width:Ce,height:ae};x.set(D.id,ge);const we={selected:j.has(D.id),hovered:p===D.id,dragging:!1,filtered:D.filtered!==!1};e.save();const je=Bt(e,ge);let ke;M&&(H!=null&&H.isParent(D.id))?ke=M:u&&(D.type==="control_area_group"||D.type==="construction_train")?ke=u:ke=c,ke(e,D,ge,we,je),e.restore()}if(y&&y.length>0){const D=new Set;for(const L of y)x.has(L.fromItemId)||D.add(L.fromItemId),x.has(L.toItemId)||D.add(L.toItemId);if(D.size>0){const L=new Map;for(const U of o)D.has(U.id)&&L.set(U.id,U);for(const[U,Q]of L){const ie=O.get(Q.group);if(ie===void 0)continue;const ae=a.getLayout(U);if(!ae)continue;const Ce=t.groupIndexToY(ie)+ae.stackLevel*t.lineHeight+(t.lineHeight-ae.itemHeight)/2,ge=t.timeToX(Q.start_time),we=t.timeToX(Q.end_time)-ge;x.set(U,{x:ge,y:Ce,width:we,height:ae.itemHeight})}}this.drawDependencies(e,y,x,p,v)}}drawDependencies(e,t,n,o,d){for(const a of t){const c=n.get(a.fromItemId),u=n.get(a.toItemId);if(!c||!u)continue;const v=o===a.fromItemId||o===a.toItemId;e.strokeStyle=v?d.primary:a.color??"#94A3B8",e.lineWidth=v?2:1.5,e.setLineDash([]);const E=c.x+c.width,p=c.y+c.height/2,y=u.x,M=u.y+u.height/2,H=Math.abs(y-E),P=Math.max(H*.4,30);e.beginPath(),e.moveTo(E,p),e.bezierCurveTo(E+P,p,y-P,M,y,M),e.stroke();const W=6;e.fillStyle=e.strokeStyle,e.beginPath(),e.moveTo(y,M),e.lineTo(y-W,M-W/2),e.lineTo(y-W,M+W/2),e.closePath(),e.fill()}}}class Ti{draw(e,t,n,o){const{cursorX:d,snapX:a,markers:c,interaction:u}=o;if(c)for(const v of c){const E=t.timeToX(v.date);if(e.fillStyle=v.color,e.fillRect(E-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 p=e.measureText(v.label).width,y=8,M=200,H=Math.min(p+y*2,M),P=20,W=E-H/2,G=4;e.fillStyle=v.color,e.beginPath(),e.roundRect(W,G,H,P,3),e.fill(),e.fillStyle="#FFFFFF",e.textBaseline="middle";const k=M-y*2,O=p>k?v.label.slice(0,Math.floor(v.label.length*k/p))+"…":v.label;e.fillText(O,W+y,G+P/2),e.restore()}}if(d!=null&&(e.strokeStyle=n.marker.cursor,e.lineWidth=1,e.beginPath(),e.moveTo(d,0),e.lineTo(d,t.canvasHeight),e.stroke()),a!=null&&(e.strokeStyle=n.primary,e.lineWidth=1,e.setLineDash([4,4]),e.beginPath(),e.moveTo(a,0),e.lineTo(a,t.canvasHeight),e.stroke(),e.setLineDash([])),u){u.groupChanged&&u.targetGroupY!==void 0&&(e.fillStyle="rgba(59, 130, 246, 0.08)",e.fillRect(0,u.targetGroupY,t.canvasWidth,t.lineHeight)),e.save(),e.globalAlpha=.5;const v=Bt(e,u.bounds);u.renderer(e,u.item,u.bounds,{selected:!1,hovered:!1,dragging:!0,filtered:!0},v),e.restore()}}}const Pt=120;function Mi(i){let e=i.deltaY||i.deltaX;return i.deltaMode===1?e*=15:i.deltaMode===2&&(e*=800),Math.max(-Pt,Math.min(Pt,e))}class ki{constructor(e,t,n,o,d){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=n,this.minZoom=o,this.maxZoom=d}updateBounds(e,t){this.visibleTimeStart=e,this.visibleTimeEnd=t}handleWheelZoom(e,t){const n=Mi(e),o=e.ctrlKey?10:e.metaKey?3:1,d=n>0?1+o*n/500:1/(1+o*-n/500),a=this.visibleTimeEnd-this.visibleTimeStart;let c=Math.round(a*d);c=Math.max(this.minZoom,Math.min(this.maxZoom,c));const u=Math.round(this.visibleTimeStart+(a-c)*t),v=u+c;this.onZoom(u,v)}}const Si=4;class Ei{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,n,o){this.state={item:e,mode:t,startX:n,startY:o,currentX:n,currentY:o,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)>=Si&&(this.activated=!0))}setCurrentGroup(e){this.state&&(this.state.currentGroup=e)}endMove(e){if(!this.state)return null;const t=this.state.deltaX/e,n=this.state.item.start_time+t,o=Math.round(n/this.dragSnap)*this.dragSnap,d=this.state.currentGroup;return this.state=null,this.activated=!1,{newStartTime:o,newGroupId:d}}endResize(e){if(!this.state)return null;const t=this.state.deltaX/e,n=this.state.mode==="resize-left"?"left":"right",d=(n==="left"?this.state.item.start_time:this.state.item.end_time)+t,a=Math.round(d/this.dragSnap)*this.dragSnap;return this.state=null,this.activated=!1,{newTime:a,edge:n}}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 at(i,e,t){const n=[];for(const o of i)o.id!==e&&(n.push(t(o.start_time)),n.push(t(o.end_time)));return n}function Ge(i,e,t,n,o){if(e.length===0)return null;let d=e[0],a=Math.abs(i-d);for(let c=1;c<e.length;c++){const u=Math.abs(i-e[c]);u<a&&(a=u,d=e[c])}return a<=t?d:null}var jt=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Lt(i){return i&&i.__esModule&&Object.prototype.hasOwnProperty.call(i,"default")?i.default:i}var Yt={exports:{}};(function(i,e){(function(t,n){i.exports=n()})(jt,function(){var t="day";return function(n,o,d){var a=function(v){return v.add(4-v.isoWeekday(),t)},c=o.prototype;c.isoWeekYear=function(){return a(this).year()},c.isoWeek=function(v){if(!this.$utils().u(v))return this.add(7*(v-this.isoWeek()),t);var E,p,y,M,H=a(this),P=(E=this.isoWeekYear(),p=this.$u,y=(p?d.utc:d)().year(E).startOf("year"),M=4-y.isoWeekday(),y.isoWeekday()>4&&(M+=7),y.add(M,t));return H.diff(P,"week")+1},c.isoWeekday=function(v){return this.$utils().u(v)?this.day()||7:this.day(this.day()%7?v:v-7)};var u=c.startOf;c.startOf=function(v,E){var p=this.$utils(),y=!!p.u(E)||E;return p.p(v)==="isoweek"?y?this.date(this.date()-(this.isoWeekday()-1)).startOf("day"):this.date(this.date()-1-(this.isoWeekday()-1)+7).endOf("day"):u.bind(this)(v,E)}}})})(Yt);var Ci=Yt.exports;const wi=Lt(Ci),Dt=5;function Xt({groups:i,width:e,lineHeight:t,scrollTop:n,canvasHeight:o,theme:d,groupRenderer:a,onScroll:c}){var W;const u=f.useRef(null),v=f.useRef(!1),E=i.length*t,p=o,y=Math.max(0,Math.floor(n/t)-Dt),M=Math.min(i.length-1,Math.ceil((n+o)/t)+Dt),H=f.useCallback(G=>{v.current||c(G.currentTarget.scrollTop)},[c]);f.useEffect(()=>{u.current&&(v.current=!0,u.current.scrollTop=n,requestAnimationFrame(()=>{v.current=!1}))},[n]);const P=[];for(let G=y;G<=M;G++){const k=i[G];k&&P.push($.jsx("div",{style:{position:"absolute",top:G*t,height:t,width:"100%",overflow:"hidden",display:"flex",alignItems:"stretch",borderBottom:`1px solid ${((W=d.grid)==null?void 0:W.line)??"#E5E5E5"}`,boxSizing:"border-box"},children:a(k)},k.id))}return $.jsx("div",{ref:u,onScroll:H,style:{width:e,height:p,overflowY:E>o?"auto":"hidden",overflowX:"hidden",position:"relative",borderRight:`1px solid ${d.sidebar.border}`,backgroundColor:d.sidebar.bg},children:$.jsx("div",{style:{height:E,position:"relative"},children:P})})}function xt(i){return null}xt.displayName="TodayMarker";function Ft(i){return{date:Math.floor(Date.now()/6e4)*6e4,color:i.color??"#FD7171",width:i.width??6,label:i.label}}function Hi(i){return i.interval??1e4}function At(i){return null}At.displayName="CustomMarker";function _t(i){return{date:i.date,color:i.color??"#3B82F6",width:i.width??4,label:i.label}}fe.extend(wi);function Ri(i){return i?{...be,...i,status:{...be.status,...i.status},grid:{...be.grid,...i.grid},item:{...be.item,...i.item},marker:{...be.marker,...i.marker},sidebar:{...be.sidebar,...i.sidebar},header:{...be.header,...i.header}}:be}const Ot=32,Ii=f.memo(f.forwardRef(function(e,t){const{groups:n,items:o,defaultTimeStart:d,defaultTimeEnd:a,sidebarWidth:c,lineHeight:u,itemHeightRatio:v,stackItems:E,canMove:p,canChangeGroup:y,canResize:M,dragSnap:H,minZoom:P,maxZoom:W,theme:G,dayStyle:k,rowStyle:O,showCursorLine:j,itemRenderer:x,groupRenderer:q,sidebarGroupRenderer:ne,dependencies:D,highlights:L,onItemClick:U,onItemDoubleClick:Q,onItemContextMenu:ie,onItemMove:ae,onItemResize:me,moveResizeValidator:Ce,onItemHover:ge,onCanvasDoubleClick:we,onCanvasContextMenu:je,onTimeChange:ke,onZoom:ut,selected:ct=[],rightSidebarWidth:Ve,rightSidebarGroupRenderer:dt,onReady:Le,devBadge:Zt,children:ve}=e,pe=f.useMemo(()=>Ri(G),[G]),ft=f.useCallback((r,s)=>{for(let h=0;h<s.length;h++)if(s[h].id===r)return h;return 0},[]),qt=ct.join(","),Ze=f.useMemo(()=>ct,[qt]),ht=f.useRef(null),mt=f.useRef(null),gt=f.useRef(null),De=f.useRef(null),pt=f.useRef(null),Ut=f.useRef(null),[Kt,Jt]=f.useState(800);f.useEffect(()=>{const r=pt.current;if(!r)return;const s=new ResizeObserver(h=>{const m=h[0];m&&Jt(m.contentRect.width)});return s.observe(r),()=>s.disconnect()},[]);const ye=Math.max(0,Kt-c-(Ve??0)),Te=n.length*u,X=f.useRef(new rt({visibleTimeStart:e.visibleTimeStart??d,visibleTimeEnd:e.visibleTimeEnd??a,canvasWidth:ye,canvasHeight:Te,sidebarWidth:c,lineHeight:u,groupCount:n.length,buffer:e.buffer??3,scrollTop:0})),qe=f.useRef(null),Xe=f.useRef(void 0),he=f.useRef(null),Se=f.useRef(!1),bt=4,[vt,Qt]=f.useState(e.visibleTimeStart??d),[yt,ei]=f.useState(e.visibleTimeEnd??a),[Tt,Ye]=f.useState(0),Fe=f.useRef(null),He=f.useCallback(()=>{const r=X.current;Qt(r.visibleTimeStart),ei(r.visibleTimeEnd),Ye(r.scrollTop),Fe.current=null},[]),Ue=f.useCallback(()=>{Fe.current===null&&(Fe.current=setTimeout(He,Ot))},[He]);f.useEffect(()=>()=>{Fe.current!==null&&clearTimeout(Fe.current)},[]);const Ee=f.useMemo(()=>{const r=new Wt;return r.rebuild(o),r},[o]),Ke=f.useMemo(()=>{const r=new mi;return r.buildFromItems(o,s=>Ee.getEffectiveSpan(s.id).start,s=>Ee.getEffectiveSpan(s.id).end),r},[o,Ee]),Je=f.useMemo(()=>{const r=new gi(u,v);return r.computeLayout(o,E,Ee),r},[o,u,v,E,Ee]),Mt=f.useMemo(()=>e.summaryRenderer?e.summaryRenderer:(r,s,h,m,l)=>{pi(r,s,h,m,l,pe)},[e.summaryRenderer,pe]),Re=f.useMemo(()=>new vi,[]),Ie=f.useMemo(()=>new yi,[]),Pe=f.useMemo(()=>new Ti,[]),ee=f.useMemo(()=>new Ei(H),[H]),xe=f.useMemo(()=>{const r=[];return f.Children.forEach(ve,s=>{var m;if(!f.isValidElement(s))return;const h=(m=s.type)==null?void 0:m.displayName;h==="TodayMarker"?r.push(Ft(s.props)):h==="CustomMarker"&&r.push(_t(s.props))}),r},[ve]),Ae=f.useMemo(()=>xe.map(r=>`${r.date}|${r.color}|${r.width}|${r.label??""}`).join(";"),[xe]),_e=f.useRef(xe);_e.current=xe;const Qe=f.useMemo(()=>{let r=0;return f.Children.forEach(ve,s=>{var m;if(!f.isValidElement(s))return;((m=s.type)==null?void 0:m.displayName)==="TodayMarker"&&(r=Hi(s.props))}),r},[ve]),_=f.useRef({groups:n,items:o,intervalTree:Ke,layoutEngine:Je,itemRenderer:x,groupRenderer:q,theme:pe,selected:Ze,dependencies:D,highlights:L,dayStyle:k,rowStyle:O,showCursorLine:j,canvasWidth:ye,canvasHeight:Te,lineHeight:u,itemHeightRatio:v,onTimeChange:ke,onZoom:ut,onItemHover:ge,onItemClick:U,onItemDoubleClick:Q,onItemContextMenu:ie,onItemMove:ae,onItemResize:me,onCanvasDoubleClick:we,onCanvasContextMenu:je,canMove:p,canResize:M,canChangeGroup:y,dragSnap:H,sidebarWidth:c,moveResizeValidator:Ce,summaryRenderer:Mt,hierarchyEngine:Ee});_.current={groups:n,items:o,intervalTree:Ke,layoutEngine:Je,itemRenderer:x,groupRenderer:q,theme:pe,selected:Ze,dependencies:D,highlights:L,dayStyle:k,rowStyle:O,showCursorLine:j,canvasWidth:ye,canvasHeight:Te,lineHeight:u,itemHeightRatio:v,onTimeChange:ke,onZoom:ut,onItemHover:ge,onItemClick:U,onItemDoubleClick:Q,onItemContextMenu:ie,onItemMove:ae,onItemResize:me,onCanvasDoubleClick:we,onCanvasContextMenu:je,canMove:p,canResize:M,canChangeGroup:y,dragSnap:H,sidebarWidth:c,moveResizeValidator:Ce,summaryRenderer:Mt,hierarchyEngine:Ee};const ti=f.useCallback(()=>{const r=ht.current;if(!r)return;const s=_.current,h=ot(r,s.canvasWidth,s.canvasHeight);lt(h,r),Re.draw(h,X.current,s.groups,s.theme,s.dayStyle,s.rowStyle,s.highlights)},[Re]),ii=f.useCallback(()=>{const r=mt.current;if(!r)return;const s=_.current,h=ot(r,s.canvasWidth,s.canvasHeight);lt(h,r),Ie.draw(h,X.current,s.groups,s.items,s.intervalTree,s.layoutEngine,s.itemRenderer,s.groupRenderer,s.theme,s.selected,Xe.current,s.dependencies,s.summaryRenderer,s.hierarchyEngine)},[Ie]),kt=f.useCallback((r,s,h)=>{const m=X.current,l=_.current,g=l.canvasWidth/(m.visibleTimeEnd-m.visibleTimeStart),T=s/g,S=[];h==="move"?(S.push(m.timeToX(r.start_time+T)),S.push(m.timeToX(r.end_time+T))):h==="resize-left"?S.push(m.timeToX(r.start_time+T)):S.push(m.timeToX(r.end_time+T));const I=(m.visibleTimeEnd-m.visibleTimeStart)*.1,F=l.intervalTree.query(m.visibleTimeStart-I,m.visibleTimeEnd+I),z=at(F,r.id,re=>m.timeToX(re));for(const re of S){const Z=Ge(re,z,8,g,l.dragSnap);if(Z!==null)return Z}const V=h==="resize-right"?r.end_time+T:r.start_time+T,R=Math.round(V/l.dragSnap)*l.dragSnap;return m.timeToX(R)},[]),ni=f.useCallback(()=>{const r=gt.current;if(!r)return;const s=_.current,h=ot(r,s.canvasWidth,s.canvasHeight);lt(h,r);const m=X.current,l=ee.getState();let g=null;if(l){const T=m.timeToX(l.item.start_time),S=m.timeToX(l.item.end_time)-T;let I,F;l.mode==="resize-left"?(I=T+l.deltaX,F=S-l.deltaX):l.mode==="resize-right"?(I=T,F=S+l.deltaX):(I=T+l.deltaX,F=S);const z=ft(l.currentGroup,s.groups),V=m.groupIndexToY(z),R=l.currentGroup!==l.originalGroup;g={item:l.item,mode:l.mode,bounds:{x:I,y:V+(s.lineHeight-s.lineHeight*s.itemHeightRatio)/2,width:F,height:s.lineHeight*s.itemHeightRatio},renderer:s.itemRenderer,targetGroupY:V,groupChanged:R}}Pe.draw(h,m,s.theme,{cursorX:s.showCursorLine?qe.current:null,snapX:l?kt(l.item,l.deltaX,l.mode):null,markers:_e.current,interaction:g})},[Pe,ee,kt,ft]),et=f.useRef(null);et.current||(et.current=new bi(r=>{r.grid&&ti(),r.items&&ii(),r.overlay&&ni()}));const w=et.current;f.useEffect(()=>()=>w.dispose(),[w]),f.useEffect(()=>{if(!Qe)return;const r=setInterval(()=>{const s=[];f.Children.forEach(ve,h=>{var l;if(!f.isValidElement(h))return;const m=(l=h.type)==null?void 0:l.displayName;m==="TodayMarker"?s.push(Ft(h.props)):m==="CustomMarker"&&s.push(_t(h.props))}),_e.current=s,w.markDirty("overlay")},Qe);return()=>clearInterval(r)},[Qe,ve,w]),f.useEffect(()=>{X.current.update({canvasWidth:ye,canvasHeight:Te,sidebarWidth:c,lineHeight:u,groupCount:n.length}),w.markAllDirty()},[ye,Te,c,u,n.length,w]),f.useEffect(()=>{w.markDirty("grid"),w.markDirty("items")},[o,n,Ze,pe,k,O,Ke,Je,w]);const Ne=f.useMemo(()=>{var r;return((r=e.highlights)==null?void 0:r.map(s=>`${s.start}|${s.end}|${s.color}|${s.label??""}|${s.opacity??""}`).join(";"))??""},[e.highlights]),St=f.useRef(Ne);f.useEffect(()=>{Ne!==St.current&&(St.current=Ne,w.markDirty("grid"))},[Ne,w]);const Et=f.useRef(Ae);f.useEffect(()=>{Ae!==Et.current&&(Et.current=Ae,w.markDirty("overlay"))},[Ae,w]);const Ct=f.useRef(e.visibleTimeStart),wt=f.useRef(e.visibleTimeEnd);e.visibleTimeStart!==void 0&&e.visibleTimeStart!==Ct.current&&(Ct.current=e.visibleTimeStart,X.current.update({visibleTimeStart:e.visibleTimeStart}),w.markAllDirty()),e.visibleTimeEnd!==void 0&&e.visibleTimeEnd!==wt.current&&(wt.current=e.visibleTimeEnd,X.current.update({visibleTimeEnd:e.visibleTimeEnd}),w.markAllDirty());const Oe=f.useRef(null),tt=f.useCallback(r=>{Oe.current===null&&(Oe.current=setTimeout(()=>{var m,l;Oe.current=null;const s=X.current,h=_.current;r==="zoom"?(m=h.onZoom)==null||m.call(h,s.visibleTimeStart,s.visibleTimeEnd):(l=h.onTimeChange)==null||l.call(h,s.visibleTimeStart,s.visibleTimeEnd)},Ot))},[]);f.useEffect(()=>()=>{Oe.current!==null&&clearTimeout(Oe.current)},[]);const ze=f.useRef(null),it=f.useMemo(()=>new ki((r,s)=>{var h;X.current.update({visibleTimeStart:r,visibleTimeEnd:s}),(h=ze.current)==null||h.updateBounds(r,s),w.markAllDirty(),Ue(),tt("zoom")},d,a,P,W),[]);ze.current=it;const $e=f.useCallback(r=>{const s=X.current,h=s.groupCount*s.lineHeight,m=Math.max(0,h-s.canvasHeight),l=Math.max(0,Math.min(m,s.scrollTop+r));l!==s.scrollTop&&(s.update({scrollTop:l}),w.markDirty("grid"),w.markDirty("items"),w.markDirty("overlay"),Ye(l))},[w]),We=f.useCallback(r=>{var T,S,I;const s=X.current,h=s.canvasWidth/(s.visibleTimeEnd-s.visibleTimeStart),m=r/h,l=s.visibleTimeStart+m,g=s.visibleTimeEnd+m;s.update({visibleTimeStart:l,visibleTimeEnd:g}),(T=ze.current)==null||T.updateBounds(l,g),w.markAllDirty(),hi.flushSync(()=>He()),(I=(S=_.current).onTimeChange)==null||I.call(S,l,g)},[w,He]);f.useEffect(()=>{const r=De.current;if(!r)return;const s=h=>{if(h.ctrlKey||h.metaKey||h.altKey){h.preventDefault();const m=r.getBoundingClientRect(),l=(h.clientX-m.left)/m.width;it.handleWheelZoom(h,l)}else if(h.shiftKey)h.preventDefault(),We(h.deltaY);else{const m=h.deltaX;m!==0&&Math.abs(m)>Math.abs(h.deltaY)?(h.preventDefault(),We(m)):h.deltaY!==0&&$e(h.deltaY)}};return r.addEventListener("wheel",s,{passive:!1}),()=>r.removeEventListener("wheel",s)},[it,$e,We]);const Me=f.useRef({lastDistance:null,lastCenter:null});f.useEffect(()=>{const r=De.current;if(!r)return;const s=(T,S)=>Math.abs(T.clientX-S.clientX),h=(T,S,I)=>(T.clientX+S.clientX)/2-I.left,m=T=>{T.touches.length===2&&(T.preventDefault(),Me.current.lastDistance=s(T.touches[0],T.touches[1]),Me.current.lastCenter=null)},l=T=>{var S;if(T.touches.length===2&&Me.current.lastDistance!==null){T.preventDefault();const I=s(T.touches[0],T.touches[1]),F=r.getBoundingClientRect(),V=h(T.touches[0],T.touches[1],F)/F.width;if(I!==0&&Me.current.lastDistance!==0){const R=Me.current.lastDistance/I,re=X.current,Z=re.visibleTimeEnd-re.visibleTimeStart;let C=Z*R;C=Math.max(P,Math.min(W,C));const b=re.visibleTimeStart+Z*V,A=b-C*V,Y=b+C*(1-V);re.update({visibleTimeStart:A,visibleTimeEnd:Y}),(S=ze.current)==null||S.updateBounds(A,Y),w.markAllDirty(),Ue(),tt("zoom")}Me.current.lastDistance=I}},g=()=>{Me.current.lastDistance=null,Me.current.lastCenter=null};return r.addEventListener("touchstart",m,{passive:!1}),r.addEventListener("touchmove",l,{passive:!1}),r.addEventListener("touchend",g),()=>{r.removeEventListener("touchstart",m),r.removeEventListener("touchmove",l),r.removeEventListener("touchend",g)}},[w,Ue,tt]);const ri=f.useCallback(r=>{var I;const s=r.currentTarget,h=s.getBoundingClientRect(),m=r.clientX-h.left,l=r.clientY-h.top;if(qe.current=m,he.current){const F=r.clientX-he.current.startX,z=r.clientY-he.current.startY;if(!Se.current&&(Math.abs(F)>=bt||Math.abs(z)>=bt)&&(Se.current=!0,s.style.cursor="grabbing",s.setPointerCapture(r.pointerId)),Se.current){const V=r.clientX-he.current.lastX,R=r.clientY-he.current.lastY;he.current.lastX=r.clientX,he.current.lastY=r.clientY,Math.abs(V)>0&&We(-V),Math.abs(R)>0&&$e(-R)}return}if(ee.isPending()){if(ee.update(m,l),ee.isActive()){const F=ee.getState();if(F&&F.mode==="move"&&_.current.canChangeGroup){const z=st(l,X.current,_.current.groups);z&&ee.setCurrentGroup(z.id)}w.markDirty("overlay")}return}_.current.showCursorLine&&w.markDirty("overlay");const g=_.current,T=Be(m,l,X.current,g.intervalTree,g.layoutEngine,g.groups),S=T==null?void 0:T.id;if(S!==Xe.current&&(Xe.current=S,w.markDirty("items"),(I=g.onItemHover)==null||I.call(g,S??null,r.nativeEvent)),T){const F=Rt(m,T,X.current),z=g.canResize;F==="left"&&(z==="left"||z==="both")||F==="right"&&(z==="right"||z==="both")?s.style.cursor="col-resize":g.canMove?s.style.cursor="grab":s.style.cursor="default"}else s.style.cursor="default"},[ee,w,We,$e]),si=f.useCallback(r=>{const s=_.current,h=r.currentTarget.getBoundingClientRect(),m=r.clientX-h.left,l=r.clientY-h.top,g=Be(m,l,X.current,s.intervalTree,s.layoutEngine,s.groups);if(!g){he.current={startX:r.clientX,startY:r.clientY,lastX:r.clientX,lastY:r.clientY},Se.current=!1;return}const T=Rt(m,g,X.current),S=s.canResize;T==="left"&&(S==="left"||S==="both")?ee.startInteraction(g,"resize-left",m,l):T==="right"&&(S==="right"||S==="both")?ee.startInteraction(g,"resize-right",m,l):s.canMove&&ee.startInteraction(g,"move",m,l)},[ee]),oi=f.useCallback(r=>{var T,S,I,F,z,V;const s=r.currentTarget;if(he.current){const R=Se.current;if(he.current=null,Se.current=!1,s.style.cursor="default",R)return}if(ee.isActive()){const R=ee.getState(),re=X.current,Z=re.canvasWidth/(re.visibleTimeEnd-re.visibleTimeStart);if(R){const C=_.current.moveResizeValidator;if(R.mode==="move"){const b=ee.endMove(Z);if(b){const A=X.current,Y=_.current,oe=R.deltaX/Z,ce=A.timeToX(R.item.start_time+oe),B=A.timeToX(R.item.end_time+oe),K=(A.visibleTimeEnd-A.visibleTimeStart)*.1,te=Y.intervalTree.query(A.visibleTimeStart-K,A.visibleTimeEnd+K),N=at(te,R.item.id,de=>A.timeToX(de));let se=b.newStartTime;const J=Ge(ce,N,8,Z,Y.dragSnap);if(J!==null)se=A.xToTime(J);else{const de=Ge(B,N,8,Z,Y.dragSnap);if(de!==null){const fi=R.item.end_time-R.item.start_time;se=A.xToTime(de)-fi}}const le=C?C("move",R.item.id,se):se,ue=_.current.hierarchyEngine.getMoveDelta(R.item.id,le);(S=(T=_.current).onItemMove)==null||S.call(T,R.item.id,le,b.newGroupId,ue.length>0?ue:void 0)}}else{const b=ee.endResize(Z);if(b){const A=X.current,Y=_.current,oe=R.deltaX/Z,ce=b.edge==="left"?R.item.start_time+oe:R.item.end_time+oe,B=A.timeToX(ce),K=(A.visibleTimeEnd-A.visibleTimeStart)*.1,te=Y.intervalTree.query(A.visibleTimeStart-K,A.visibleTimeEnd+K),N=at(te,R.item.id,de=>A.timeToX(de)),se=Ge(B,N,8,Z,Y.dragSnap);let J=se!==null?A.xToTime(se):b.newTime;const le=_.current.hierarchyEngine.getResizeConstraint(R.item.id,b.edge);b.edge==="left"&&J>le.max?J=le.max:b.edge==="right"&&J<le.min&&(J=le.min);const ue=C?C("resize",R.item.id,J,b.edge):J;(F=(I=_.current).onItemResize)==null||F.call(I,R.item.id,ue,b.edge)}}}s.style.cursor="default",w.markDirty("overlay");return}ee.isPending()&&ee.cancel();const h=s.getBoundingClientRect(),m=r.clientX-h.left,l=r.clientY-h.top,g=Be(m,l,X.current,_.current.intervalTree,_.current.layoutEngine,_.current.groups);g&&((V=(z=_.current).onItemClick)==null||V.call(z,g.id,r.nativeEvent))},[ee,w]),li=f.useCallback(r=>{var T,S;const s=r.currentTarget.getBoundingClientRect(),h=r.clientX-s.left,m=r.clientY-s.top,l=_.current,g=Be(h,m,X.current,l.intervalTree,l.layoutEngine,l.groups);if(g)(T=l.onItemDoubleClick)==null||T.call(l,g.id,r.nativeEvent);else{const I=st(m,X.current,l.groups),F=X.current.xToTime(h);I&&((S=l.onCanvasDoubleClick)==null||S.call(l,I.id,F))}},[]),ai=f.useCallback(r=>{var T,S;r.preventDefault();const s=r.currentTarget.getBoundingClientRect(),h=r.clientX-s.left,m=r.clientY-s.top,l=_.current,g=Be(h,m,X.current,l.intervalTree,l.layoutEngine,l.groups);if(g)(T=l.onItemContextMenu)==null||T.call(l,g.id,r.nativeEvent);else{const I=st(m,X.current,l.groups),F=X.current.xToTime(h);I&&((S=l.onCanvasContextMenu)==null||S.call(l,I.id,F,r.nativeEvent))}},[]),ui=f.useCallback(()=>{var r,s;he.current=null,Se.current=!1,qe.current=null,De.current&&(De.current.style.cursor="default"),Xe.current!==void 0&&(Xe.current=void 0,w.markDirty("items"),(s=(r=_.current).onItemHover)==null||s.call(r,null,new PointerEvent("pointerleave"))),_.current.showCursorLine&&w.markDirty("overlay")},[w]),ci=f.useMemo(()=>{const r=[];return f.Children.forEach(ve,s=>{var m;if(!f.isValidElement(s))return;if(((m=s.type)==null?void 0:m.displayName)==="TimelineHeaders"){const l=s.props;r.push(f.cloneElement(s,{visibleTimeStart:l.visibleTimeStart??vt,visibleTimeEnd:l.visibleTimeEnd??yt,canvasWidth:l.canvasWidth??ye,sidebarWidth:l.sidebarWidth??c,theme:l.theme??pe,onZoomToInterval:l.onZoomToInterval??((g,T)=>{var S,I,F,z;X.current.update({visibleTimeStart:g,visibleTimeEnd:T}),w.markAllDirty(),He(),(I=(S=_.current).onTimeChange)==null||I.call(S,g,T),(z=(F=_.current).onZoom)==null||z.call(F,g,T)})}))}}),r},[ve,vt,yt,ye,c,pe,w,He]),Ht=f.useRef(!1);f.useEffect(()=>{Ht.current||(Ht.current=!0,w.markAllDirty())},[w]),f.useImperativeHandle(t,()=>({captureToCanvas({timeStart:r,timeEnd:s,scale:h,sidebarWidth:m}){const l=_.current,g=28,T=g*3,S=l.groups.length*l.lineHeight,I=X.current,F=l.canvasWidth/(I.visibleTimeEnd-I.visibleTimeStart),z=s-r,V=Math.max(l.canvasWidth,Math.round(z*F)),R=(m+V)*h,re=(T+S)*h,Z=document.createElement("canvas");Z.width=R,Z.height=re;const C=Z.getContext("2d");C.scale(h,h);for(let Y=0;Y<l.groups.length;Y++){const oe=l.groups[Y],ce=T+Y*l.lineHeight;if(l.rowStyle){const N=l.rowStyle(oe);N!=null&&N.backgroundColor&&(C.fillStyle=N.backgroundColor,C.fillRect(0,ce,m,l.lineHeight))}const B=oe.type;let K="400",te=8;B==="project"?K="700":B==="CAG"?K="600":B==="CA"&&(K="400",te=24),C.fillStyle="#111",C.font=`${K} 12px sans-serif`,C.textBaseline="middle",C.fillText(oe.title,te,ce+l.lineHeight/2,m-te-4)}const b=(Y,oe,ce)=>{var te,N;C.fillStyle=((te=l.theme.header)==null?void 0:te.bg)??"#f5f5f5",C.fillRect(m,Y,V,g),C.strokeStyle=((N=l.theme.grid)==null?void 0:N.line)??"#e0e0e0",C.lineWidth=1,C.strokeRect(m,Y,V,g);let B=fe(r).startOf(ce);B.valueOf()<r&&(B=B.add(1,ce));const K=V/(s-r);for(;B.valueOf()<s;){const se=B.add(1,ce),J=m+(B.valueOf()-r)*K,ue=m+(Math.min(se.valueOf(),s)-r)*K-J;C.beginPath(),C.moveTo(J,Y),C.lineTo(J,Y+g),C.stroke(),C.fillStyle="#333",C.font="600 11px sans-serif",C.textBaseline="middle",C.textAlign="center",C.fillText(oe(B),J+ue/2,Y+g/2,ue-4),B=se}C.textAlign="start"};b(0,Y=>Y.format("YYYY"),"year"),b(g,Y=>Y.format("MM"),"month"),b(g*2,Y=>String(Y.isoWeek()),"week");const A=new rt({visibleTimeStart:r,visibleTimeEnd:s,canvasWidth:V,canvasHeight:S,sidebarWidth:0,lineHeight:l.lineHeight,groupCount:l.groups.length,buffer:1,scrollTop:0});return C.save(),C.translate(m,T),C.beginPath(),C.rect(0,0,V,S),C.clip(),Re.draw(C,A,l.groups,l.theme,l.dayStyle,l.rowStyle,l.highlights),Ie.draw(C,A,l.groups,l.items,l.intervalTree,l.layoutEngine,l.itemRenderer,l.groupRenderer,l.theme,l.selected,void 0,l.dependencies,l.summaryRenderer,l.hierarchyEngine),Pe.draw(C,A,l.theme,{cursorX:null,snapX:null,markers:_e.current,interaction:null}),C.restore(),Z}}),[Re,Ie,Pe]),f.useEffect(()=>{const r={captureToCanvas({timeStart:s,timeEnd:h,scale:m,sidebarWidth:l}){var ce;const g=_.current,T=28,S=T*3,I=g.groups.length*g.lineHeight,F=X.current,z=g.canvasWidth/(F.visibleTimeEnd-F.visibleTimeStart),V=h-s,R=Math.max(g.canvasWidth,Math.round(V*z)),re=l+R,Z=S+I,C=document.createElement("canvas");C.width=re*m,C.height=Z*m;const b=C.getContext("2d");b.scale(m,m),b.fillStyle="#FFFFFF",b.fillRect(0,0,re,Z),b.save(),b.beginPath(),b.rect(0,0,l,Z),b.clip(),b.fillStyle="#F9FAFB",b.fillRect(0,0,l,S),b.strokeStyle="#E5E7EB",b.lineWidth=1,b.strokeRect(0,0,l,S);for(let B=0;B<g.groups.length;B++){const K=g.groups[B],te=S+B*g.lineHeight,N=(ce=g.rowStyle)==null?void 0:ce.call(g,K);b.fillStyle=(N==null?void 0:N.backgroundColor)??(B%2===0?"#FFFFFF":"#F7F7F7"),b.fillRect(0,te,l,g.lineHeight),b.strokeStyle="#E5E5E5",b.lineWidth=.5,b.beginPath(),b.moveTo(0,te+g.lineHeight),b.lineTo(l,te+g.lineHeight),b.stroke();const se=K.type??"";let J=8,le="400",ue=11;se==="project"?(le="700",ue=12):se==="control_area_group"?le="600":se==="control_area"&&(J=24),b.fillStyle="#374151",b.font=`${le} ${ue}px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif`,b.textBaseline="middle";const de=typeof K.title=="string"?K.title:String(K.title);b.fillText(de,J,te+g.lineHeight/2,l-J-8)}b.strokeStyle="#E5E7EB",b.lineWidth=1,b.beginPath(),b.moveTo(l,0),b.lineTo(l,Z),b.stroke(),b.restore(),b.save(),b.beginPath(),b.rect(l,0,R,S),b.clip();const A=h-s,Y=[{unit:"year",row:0},{unit:"month",row:1},{unit:"week",row:2}];for(const{unit:B,row:K}of Y){const te=K*T;b.fillStyle="#F9FAFB",b.fillRect(l,te,R,T);let N=fe(s).startOf(B);const se=fe(h).add(1,B);for(;N.isBefore(se);){const J=N.add(1,B),le=l+(N.valueOf()-s)/A*R,ue=(J.valueOf()-N.valueOf())/A*R;b.strokeStyle="#E5E7EB",b.lineWidth=.5,b.strokeRect(le,te,ue,T);let de;B==="year"?de=N.format("YYYY"):B==="month"?de=N.format("MM"):de=`${N.week()}`,b.fillStyle="#6c737f",b.font=B==="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",ue>20&&b.fillText(de,le+ue/2,te+T/2),N=J}}b.textAlign="start",b.restore(),b.save(),b.beginPath(),b.rect(l,S,R,I),b.clip(),b.translate(l,S);const oe=new rt({visibleTimeStart:s,visibleTimeEnd:h,canvasWidth:R,canvasHeight:I,sidebarWidth:0,lineHeight:g.lineHeight,groupCount:g.groups.length,buffer:1,scrollTop:0});return Re.draw(b,oe,g.groups,g.theme,g.dayStyle,g.rowStyle,g.highlights),Ie.draw(b,oe,g.groups,g.items,g.intervalTree,g.layoutEngine,g.itemRenderer,g.groupRenderer,g.theme,g.selected,void 0,g.dependencies,g.summaryRenderer,g.hierarchyEngine),Pe.draw(b,oe,g.theme,{cursorX:null,markers:_e.current}),b.restore(),C}};Le==null||Le(r)},[Le,Re,Ie,Pe]);const di={position:"relative",width:ye,height:Te,overflow:"hidden",cursor:"default"},nt={position:"absolute",top:0,left:0};return $.jsxs("div",{ref:pt,style:{display:"flex",flexDirection:"column",width:"100%",position:"relative"},children:[Zt?$.jsxs("div",{style:{position:"absolute",top:0,left:0,zIndex:9999,padding:"2px 6px",fontSize:10,fontFamily:"ui-monospace, SFMono-Regular, Menlo, monospace",lineHeight:1.4,color:"#fff",background:"rgba(17, 24, 39, 0.78)",borderBottomRightRadius:4,pointerEvents:"none",userSelect:"none"},children:["v","0.4.5"," · ","09:22:40"]}):null,ci,$.jsxs("div",{ref:Ut,style:{display:"flex",overflow:"hidden"},children:[$.jsx(Xt,{groups:n,width:c,lineHeight:u,scrollTop:Tt,canvasHeight:Te,theme:pe,groupRenderer:ne,onScroll:r=>{X.current.update({scrollTop:r}),w.markDirty("grid"),w.markDirty("items"),w.markDirty("overlay"),Ye(r)}}),$.jsxs("div",{ref:De,style:di,onPointerMove:ri,onPointerDown:si,onPointerUp:oi,onDoubleClick:li,onContextMenu:ai,onPointerLeave:ui,children:[$.jsx("canvas",{ref:ht,style:{...nt,zIndex:0}}),$.jsx("canvas",{ref:mt,style:{...nt,zIndex:1}}),$.jsx("canvas",{ref:gt,style:{...nt,zIndex:2}})]}),Ve&&dt?$.jsx(Xt,{groups:n,width:Ve,lineHeight:u,scrollTop:Tt,canvasHeight:Te,theme:pe,groupRenderer:dt,onScroll:r=>{X.current.update({scrollTop:r}),w.markDirty("grid"),w.markDirty("items"),w.markDirty("overlay"),Ye(r)}}):null]})]})}));function Nt({children:i,theme:e,className:t,classNames:n,style:o,visibleTimeStart:d,visibleTimeEnd:a,canvasWidth:c,sidebarWidth:u=0,onZoomToInterval:v}){const E=f.Children.map(i,p=>{var M;if(!f.isValidElement(p))return p;if(((M=p.type)==null?void 0:M.displayName)==="DateHeader"){const H=p.props,P=f.cloneElement(p,{visibleTimeStart:H.visibleTimeStart??d,visibleTimeEnd:H.visibleTimeEnd??a,canvasWidth:H.canvasWidth??c,theme:H.theme??e,onZoomToInterval:H.onIntervalClick??H.onZoomToInterval??v});return $.jsxs("div",{style:{display:"flex"},children:[$.jsx("div",{style:{width:u,flexShrink:0}}),$.jsx("div",{style:{flex:1,overflow:"hidden"},children:P})]})}return p});return $.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"}`,...o},children:E})}Nt.displayName="TimelineHeaders";var zt={exports:{}};(function(i,e){(function(t,n){i.exports=n()})(jt,function(){var t="week",n="year";return function(o,d,a){var c=d.prototype;c.week=function(u){if(u===void 0&&(u=null),u!==null)return this.add(7*(u-this.week()),"day");var v=this.$locale().yearStart||1;if(this.month()===11&&this.date()>25){var E=a(this).startOf(n).add(1,n).date(v),p=a(this).endOf(t);if(E.isBefore(p))return 1}var y=a(this).startOf(n).date(v).startOf(t).subtract(1,"millisecond"),M=this.diff(y,t,!0);return M<0?a(this).startOf("week").week():Math.ceil(M)},c.weeks=function(u){return u===void 0&&(u=null),this.week(u)}}})})(zt);var Pi=zt.exports;const Di=Lt(Pi);fe.extend(Di);const Xi={year:30,month:30,week:20,day:15,hour:30};function $t({unit:i,visibleTimeStart:e=0,visibleTimeEnd:t=0,canvasWidth:n=0,theme:o,height:d=28,className:a,labelFormat:c,onIntervalClick:u,minCellWidth:v,onZoomToInterval:E}){const p=f.useMemo(()=>{if(!e||!t||!n)return[];const M=t-e,H=v??Xi[i];if(H>0){const k=fe(e).startOf(i);if((k.add(1,i).valueOf()-k.valueOf())/M*n<H)return[]}const P=[];let W=fe(e).startOf(i).subtract(1,i);const G=fe(t).add(2,i).valueOf();for(;W.valueOf()<G;){const k=W.add(1,i),O=W.valueOf(),j=k.valueOf(),x=(O-e)/M*n,q=(j-O)/M*n,ne=Fi(W,k,i,c);P.push({start:O,end:j,label:ne,left:x,width:q}),W=k}return P},[e,t,n,i,c,v]),y=f.useCallback((M,H)=>{u?u(M,H):E&&E(M,H)},[u,E]);return p.length===0?null:$.jsx("div",{style:{display:"flex",position:"relative",height:d,overflow:"hidden"},children:p.map(M=>$.jsx("div",{className:a,onClick:()=>y(M.start,M.end),style:{position:"absolute",left:M.left,width:M.width,height:"100%",display:"flex",alignItems:"center",justifyContent:"center",borderRight:`1px solid ${(o==null?void 0:o.header.border)??"#E5E7EB"}`,borderBottom:`1px solid ${(o==null?void 0:o.header.border)??"#E5E7EB"}`,fontSize:12,color:(o==null?void 0:o.header.text)??"#6c737f",backgroundColor:(o==null?void 0:o.header.bg)??"#F9FAFB",overflow:"hidden",whiteSpace:"nowrap",cursor:"pointer",userSelect:"none",padding:"0 4px",boxSizing:"border-box"},children:$.jsx("span",{children:M.label})},M.start))})}$t.displayName="DateHeader";function Fi(i,e,t,n,o){return typeof n=="function"?n(i.toDate(),e.toDate(),t):typeof n=="string"?i.format(n):_i(i,t)}function _i(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 Gt({width:i,children:e,style:t}){const n=()=>({style:{width:i,...t}});return e?$.jsx($.Fragment,{children:e({getRootProps:n})}):$.jsx("div",{style:{width:i}})}Gt.displayName="SidebarHeader";function Vt({children:i}){return $.jsx($.Fragment,{children:i})}Vt.displayName="CustomHeader";exports.CanvasTimeline=Ii;exports.CustomHeader=Vt;exports.CustomMarker=At;exports.DEFAULT_THEME=be;exports.DateHeader=$t;exports.HierarchyEngine=Wt;exports.SidebarHeader=Gt;exports.TimelineHeaders=Nt;exports.TodayMarker=xt;
|
|
2
2
|
//# sourceMappingURL=canvas-timeline.cjs.js.map
|