@mogura/moguchart-core 0.8.0 → 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -21,6 +21,8 @@ export declare class GanttBarElement extends LitElement {
21
21
  private getX;
22
22
  private setupDragEvents;
23
23
  private onResizeStart;
24
+ /** ドラッグ開始と判定するための移動閾値(px) */
25
+ private static readonly DRAG_THRESHOLD;
24
26
  private onMoveStart;
25
27
  protected updated(changedProperties: PropertyValues): void;
26
28
  disconnectedCallback(): void;
@@ -413,8 +413,10 @@ export interface BarHoverEventDetail {
413
413
  task: GanttTask;
414
414
  /** マウスのX座標 */
415
415
  x: number;
416
- /** マウスのY座標 */
416
+ /** マウスのY座標(バー上辺) */
417
417
  y: number;
418
+ /** バー下辺のY座標 */
419
+ barBottom: number;
418
420
  }
419
421
  /**
420
422
  * タスククリックイベントの詳細
@@ -286,7 +286,10 @@ function B(e, t, n, r) {
286
286
  }
287
287
  //#endregion
288
288
  //#region src/components/gantt-bar.ts
289
- var V = class extends e {
289
+ var V, H = class extends e {
290
+ static {
291
+ V = this;
292
+ }
290
293
  constructor(...e) {
291
294
  super(...e), this.lane = 0, this.selected = !1, this.focused = !1, this.multiDragDx = 0, this.multiDragDy = 0, this.multiDragActive = !1, this.multiDragSameRow = !1, this.connectorDropTarget = !1, this.isExporting = !1, this.isCriticalPath = !1, this._currentDragCursor = null, this._dragAnimationFrame = null, this._wasDragging = !1, this._connectorEdgeThreshold = 30, this.handleKeyDown = (e) => {
292
295
  (e.key === "Control" || e.key === "Alt") && this.updateCursor(!0);
@@ -557,6 +560,9 @@ var V = class extends e {
557
560
  });
558
561
  });
559
562
  }
563
+ static {
564
+ this.DRAG_THRESHOLD = 3;
565
+ }
560
566
  onMoveStart(e) {
561
567
  if (e.button === 2) return;
562
568
  e.stopPropagation();
@@ -564,31 +570,37 @@ var V = class extends e {
564
570
  if (!t || !n) return;
565
571
  let r = this.task.movable ?? "both";
566
572
  if (r === "none") return;
567
- let i = e.ctrlKey || e.altKey ? "copy" : "grabbing";
568
- this._currentDragCursor = i, t.style.cursor = i, t.setPointerCapture(e.pointerId), n.classList.add("dragging");
569
- let a = e.clientX, o = e.clientY, s = new Date(this.task.start), c = new Date(this.task.end), l = this.option.snapDuration ?? 1440;
573
+ t.setPointerCapture(e.pointerId);
574
+ let i = e.clientX, a = e.clientY, o = new Date(this.task.start), s = new Date(this.task.end), c = this.option.snapDuration ?? 1440, l = !1;
570
575
  this.setupDragEvents(t, e.pointerId, (e) => {
571
- let i = e.ctrlKey || e.altKey ? "copy" : "grabbing";
572
- this._currentDragCursor = i, t.style.cursor = i;
573
- let u = e.clientX - a, d = e.clientY - o;
574
- r === "y" && (u = 0), r === "x" && (d = 0), this.multiDragActive && !this.multiDragSameRow && (d = 0);
575
- let f = u;
576
+ let u = e.clientX - i, d = e.clientY - a;
577
+ if (!l) {
578
+ if (Math.abs(u) < V.DRAG_THRESHOLD && Math.abs(d) < V.DRAG_THRESHOLD) return;
579
+ l = !0;
580
+ let r = e.ctrlKey || e.altKey ? "copy" : "grabbing";
581
+ this._currentDragCursor = r, t.style.cursor = r, n.classList.add("dragging");
582
+ }
583
+ let f = e.ctrlKey || e.altKey ? "copy" : "grabbing";
584
+ this._currentDragCursor = f, t.style.cursor = f;
585
+ let p = u, m = d;
586
+ r === "y" && (p = 0), r === "x" && (m = 0), this.multiDragActive && !this.multiDragSameRow && (m = 0);
587
+ let h = p;
576
588
  if (this.option.calendar.pxPerMonth) {
577
- let e = N(this.getX(s) + u, this.option.calendar.start, 50, this.option.calendar.pxPerMonth), t = (e.getFullYear() - s.getFullYear()) * 12 + (e.getMonth() - s.getMonth()) + (e.getDate() > 15 ? 1 : 0), n = new Date(s);
578
- n.setMonth(n.getMonth() + t), f = this.getX(n) - this.getX(s);
589
+ let e = N(this.getX(o) + p, this.option.calendar.start, 50, this.option.calendar.pxPerMonth), t = (e.getFullYear() - o.getFullYear()) * 12 + (e.getMonth() - o.getMonth()) + (e.getDate() > 15 ? 1 : 0), n = new Date(o);
590
+ n.setMonth(n.getMonth() + t), h = this.getX(n) - this.getX(o);
579
591
  } else {
580
- let e = this.option.calendar.pxPerDay / 1440 * l;
581
- f = Math.round(u / e) * e;
592
+ let e = this.option.calendar.pxPerDay / 1440 * c;
593
+ h = Math.round(p / e) * e;
582
594
  }
583
- n.style.transform = `translate(${f}px, ${d}px)`, this._dragAnimationFrame && cancelAnimationFrame(this._dragAnimationFrame), this._dragAnimationFrame = requestAnimationFrame(() => {
595
+ n.style.transform = `translate(${h}px, ${m}px)`, this._dragAnimationFrame && cancelAnimationFrame(this._dragAnimationFrame), this._dragAnimationFrame = requestAnimationFrame(() => {
584
596
  let t = e.ctrlKey || e.altKey;
585
597
  this.dispatchEvent(new CustomEvent("task-update", {
586
598
  detail: {
587
599
  ...this.task,
588
- start: s,
589
- end: c,
590
- dx: f,
591
- dy: d,
600
+ start: o,
601
+ end: s,
602
+ dx: h,
603
+ dy: m,
592
604
  isDragging: !0,
593
605
  x: e.clientX,
594
606
  y: e.clientY,
@@ -598,12 +610,24 @@ var V = class extends e {
598
610
  composed: !0
599
611
  }));
600
612
  });
601
- }, (e, i) => {
602
- if (this._currentDragCursor = null, n.classList.remove("dragging"), n.style.transform = "", t.style.cursor = "", this._dragAnimationFrame &&= (cancelAnimationFrame(this._dragAnimationFrame), null), e) this.requestUpdate(), this.dispatchEvent(new CustomEvent("task-update", {
613
+ }, (e, u) => {
614
+ if (this._currentDragCursor = null, n.classList.remove("dragging"), n.style.transform = "", t.style.cursor = "", this._dragAnimationFrame &&= (cancelAnimationFrame(this._dragAnimationFrame), null), !l) {
615
+ u && (this.dispatchEvent(new CustomEvent("bar-click", {
616
+ detail: {
617
+ task: this.task,
618
+ event: u,
619
+ isMultiSelect: u.metaKey || u.ctrlKey
620
+ },
621
+ bubbles: !0,
622
+ composed: !0
623
+ })), this._wasDragging = !0);
624
+ return;
625
+ }
626
+ if (e) this.requestUpdate(), this.dispatchEvent(new CustomEvent("task-update", {
603
627
  detail: {
604
628
  ...this.task,
605
- start: s,
606
- end: c,
629
+ start: o,
630
+ end: s,
607
631
  dx: 0,
608
632
  dy: 0,
609
633
  isDragging: !1
@@ -611,33 +635,33 @@ var V = class extends e {
611
635
  bubbles: !0,
612
636
  composed: !0
613
637
  }));
614
- else if (i) {
615
- let e = i.clientX - a, t = e;
638
+ else if (u) {
639
+ let e = u.clientX - i, t = e;
616
640
  if (this.option.calendar.pxPerMonth) {
617
- let n = N(this.getX(s) + e, this.option.calendar.start, 50, this.option.calendar.pxPerMonth), r = (n.getFullYear() - s.getFullYear()) * 12 + (n.getMonth() - s.getMonth()) + (n.getDate() > 15 ? 1 : 0), i = new Date(s);
618
- i.setMonth(i.getMonth() + r), t = this.getX(i) - this.getX(s);
641
+ let n = N(this.getX(o) + e, this.option.calendar.start, 50, this.option.calendar.pxPerMonth), r = (n.getFullYear() - o.getFullYear()) * 12 + (n.getMonth() - o.getMonth()) + (n.getDate() > 15 ? 1 : 0), i = new Date(o);
642
+ i.setMonth(i.getMonth() + r), t = this.getX(i) - this.getX(o);
619
643
  } else {
620
- let n = this.option.calendar.pxPerDay / 1440 * l;
644
+ let n = this.option.calendar.pxPerDay / 1440 * c;
621
645
  t = Math.round(e / n) * n;
622
646
  }
623
- let n = i.clientY - o;
647
+ let n = u.clientY - a;
624
648
  if (r === "y" && (t = 0), r === "x" && (n = 0), this.multiDragActive && !this.multiDragSameRow && (n = 0), t === 0 && Math.abs(n) < 5) {
625
649
  this.dispatchEvent(new CustomEvent("bar-click", {
626
650
  detail: {
627
651
  task: this.task,
628
- event: i,
629
- isMultiSelect: i.metaKey || i.ctrlKey
652
+ event: u,
653
+ isMultiSelect: u.metaKey || u.ctrlKey
630
654
  },
631
655
  bubbles: !0,
632
656
  composed: !0
633
657
  })), this._wasDragging = !0;
634
658
  return;
635
659
  }
636
- let u = i.ctrlKey || i.altKey;
660
+ let l = u.ctrlKey || u.altKey;
637
661
  this._wasDragging = !0, this.multiDragActive || this.dispatchEvent(new CustomEvent("bar-click", {
638
662
  detail: {
639
663
  task: this.task,
640
- event: i,
664
+ event: u,
641
665
  isMultiSelect: !1
642
666
  },
643
667
  bubbles: !0,
@@ -645,12 +669,12 @@ var V = class extends e {
645
669
  })), this.dispatchEvent(new CustomEvent("task-update", {
646
670
  detail: {
647
671
  ...this.task,
648
- start: s,
649
- end: c,
672
+ start: o,
673
+ end: s,
650
674
  dx: t,
651
675
  dy: n,
652
676
  isDragging: !1,
653
- mode: u ? "copy" : "move"
677
+ mode: l ? "copy" : "move"
654
678
  },
655
679
  bubbles: !0,
656
680
  composed: !0
@@ -689,7 +713,8 @@ var V = class extends e {
689
713
  detail: {
690
714
  task: this.task,
691
715
  x: n.left + n.width / 2,
692
- y: n.top
716
+ y: n.top,
717
+ barBottom: n.bottom
693
718
  },
694
719
  bubbles: !0,
695
720
  composed: !0
@@ -831,27 +856,27 @@ var V = class extends e {
831
856
  `;
832
857
  }
833
858
  };
834
- B([s({ type: Object })], V.prototype, "task", void 0), B([s({ type: Object })], V.prototype, "option", void 0), B([s({ type: Number })], V.prototype, "lane", void 0), B([s({
859
+ B([s({ type: Object })], H.prototype, "task", void 0), B([s({ type: Object })], H.prototype, "option", void 0), B([s({ type: Number })], H.prototype, "lane", void 0), B([s({
835
860
  type: Boolean,
836
861
  reflect: !0
837
- })], V.prototype, "selected", void 0), B([s({
862
+ })], H.prototype, "selected", void 0), B([s({
838
863
  type: Boolean,
839
864
  reflect: !0
840
- })], V.prototype, "focused", void 0), B([s({ type: Number })], V.prototype, "multiDragDx", void 0), B([s({ type: Number })], V.prototype, "multiDragDy", void 0), B([s({ type: Boolean })], V.prototype, "multiDragActive", void 0), B([s({ type: Boolean })], V.prototype, "multiDragSameRow", void 0), B([s({
865
+ })], H.prototype, "focused", void 0), B([s({ type: Number })], H.prototype, "multiDragDx", void 0), B([s({ type: Number })], H.prototype, "multiDragDy", void 0), B([s({ type: Boolean })], H.prototype, "multiDragActive", void 0), B([s({ type: Boolean })], H.prototype, "multiDragSameRow", void 0), B([s({
841
866
  type: Boolean,
842
867
  reflect: !0,
843
868
  attribute: "connector-drop-target"
844
- })], V.prototype, "connectorDropTarget", void 0), B([s({
869
+ })], H.prototype, "connectorDropTarget", void 0), B([s({
845
870
  type: Boolean,
846
871
  reflect: !0
847
- })], V.prototype, "isExporting", void 0), B([s({
872
+ })], H.prototype, "isExporting", void 0), B([s({
848
873
  type: Boolean,
849
874
  reflect: !0,
850
875
  attribute: "critical-path"
851
- })], V.prototype, "isCriticalPath", void 0), V = B([o("gantt-bar")], V);
876
+ })], H.prototype, "isCriticalPath", void 0), H = V = B([o("gantt-bar")], H);
852
877
  //#endregion
853
878
  //#region src/components/gantt-calendar.ts
854
- var H = class extends e {
879
+ var U = class extends e {
855
880
  constructor(...e) {
856
881
  super(...e), this.theme = "light", this.currentTime = /* @__PURE__ */ new Date(), this.isExporting = !1, this.hoveredMilestoneId = null, this._cachedDays = null, this._cachedMonths = null, this._cachedYears = null, this._cachedWeeks = null, this._cachedStartTime = 0, this._cachedEndTime = 0, this._cachedPxPerDay = 0, this._cachedPxPerMonth = void 0, this._cachedWeekStartDay = -1;
857
882
  }
@@ -1354,10 +1379,10 @@ var H = class extends e {
1354
1379
  `;
1355
1380
  }
1356
1381
  };
1357
- B([s({ type: Object })], H.prototype, "option", void 0), B([s({ type: String })], H.prototype, "theme", void 0), B([s({ type: Object })], H.prototype, "currentTime", void 0), B([s({ type: Boolean })], H.prototype, "isExporting", void 0), B([s({ type: String })], H.prototype, "hoveredMilestoneId", void 0), B([s({ attribute: !1 })], H.prototype, "cornerContent", void 0), B([s({ attribute: !1 })], H.prototype, "calendarMonthContent", void 0), B([s({ attribute: !1 })], H.prototype, "calendarDayContent", void 0), B([s({ attribute: !1 })], H.prototype, "calendarWeekContent", void 0), B([s({ attribute: !1 })], H.prototype, "calendarHourContent", void 0), H = B([o("gantt-calendar")], H);
1382
+ B([s({ type: Object })], U.prototype, "option", void 0), B([s({ type: String })], U.prototype, "theme", void 0), B([s({ type: Object })], U.prototype, "currentTime", void 0), B([s({ type: Boolean })], U.prototype, "isExporting", void 0), B([s({ type: String })], U.prototype, "hoveredMilestoneId", void 0), B([s({ attribute: !1 })], U.prototype, "cornerContent", void 0), B([s({ attribute: !1 })], U.prototype, "calendarMonthContent", void 0), B([s({ attribute: !1 })], U.prototype, "calendarDayContent", void 0), B([s({ attribute: !1 })], U.prototype, "calendarWeekContent", void 0), B([s({ attribute: !1 })], U.prototype, "calendarHourContent", void 0), U = B([o("gantt-calendar")], U);
1358
1383
  //#endregion
1359
1384
  //#region src/components/gantt-row-background.ts
1360
- var U = class extends e {
1385
+ var W = class extends e {
1361
1386
  constructor(...e) {
1362
1387
  super(...e), this.theme = "light", this.rowId = "", this._cachedCells = null, this._cachedCellsStartTime = 0, this._cachedCellsEndTime = 0, this._cachedCellsPxPerDay = 0, this._cachedCellsPxPerMonth = void 0, this._cachedCellsTheme = "";
1363
1388
  }
@@ -1428,10 +1453,10 @@ var U = class extends e {
1428
1453
  `;
1429
1454
  }
1430
1455
  };
1431
- B([s({ type: Object })], U.prototype, "option", void 0), B([s({ type: String })], U.prototype, "theme", void 0), B([s({ type: String })], U.prototype, "rowId", void 0), U = B([o("gantt-row-background")], U);
1456
+ B([s({ type: Object })], W.prototype, "option", void 0), B([s({ type: String })], W.prototype, "theme", void 0), B([s({ type: String })], W.prototype, "rowId", void 0), W = B([o("gantt-row-background")], W);
1432
1457
  //#endregion
1433
1458
  //#region src/components/gantt-row.ts
1434
- var W = class extends e {
1459
+ var G = class extends e {
1435
1460
  constructor(...e) {
1436
1461
  super(...e), this.isDragTarget = !1, this.draggingTask = null, this.draggingTaskIds = [], this.multiDragDx = 0, this.multiDragDy = 0, this.multiDragSameRow = !1, this.externalDragTask = null, this.theme = "light", this.isSelected = !1, this.dropPosition = null, this.selectedTaskIds = [], this.focusedTaskId = null, this.isExporting = !1, this.criticalPathTaskIds = [], this._cachedMonthGridLines = null, this._cachedMonthGridStartTime = 0, this._cachedMonthGridEndTime = 0, this._cachedMonthGridPxPerDay = 0, this._cachedMonthGridPxPerMonth = 0, this._rowHeaderTooltipEl = null;
1437
1462
  }
@@ -1929,16 +1954,16 @@ var W = class extends e {
1929
1954
  `;
1930
1955
  }
1931
1956
  };
1932
- B([s({ type: Object })], W.prototype, "row", void 0), B([s({ type: Object })], W.prototype, "option", void 0), B([s({ type: Boolean })], W.prototype, "isDragTarget", void 0), B([s({ type: Object })], W.prototype, "draggingTask", void 0), B([s({ type: Array })], W.prototype, "draggingTaskIds", void 0), B([s({ type: Number })], W.prototype, "multiDragDx", void 0), B([s({ type: Number })], W.prototype, "multiDragDy", void 0), B([s({ type: Boolean })], W.prototype, "multiDragSameRow", void 0), B([s({ type: Object })], W.prototype, "externalDragTask", void 0), B([s({ type: String })], W.prototype, "theme", void 0), B([s({
1957
+ B([s({ type: Object })], G.prototype, "row", void 0), B([s({ type: Object })], G.prototype, "option", void 0), B([s({ type: Boolean })], G.prototype, "isDragTarget", void 0), B([s({ type: Object })], G.prototype, "draggingTask", void 0), B([s({ type: Array })], G.prototype, "draggingTaskIds", void 0), B([s({ type: Number })], G.prototype, "multiDragDx", void 0), B([s({ type: Number })], G.prototype, "multiDragDy", void 0), B([s({ type: Boolean })], G.prototype, "multiDragSameRow", void 0), B([s({ type: Object })], G.prototype, "externalDragTask", void 0), B([s({ type: String })], G.prototype, "theme", void 0), B([s({
1933
1958
  type: Boolean,
1934
1959
  reflect: !0
1935
- })], W.prototype, "isSelected", void 0), B([s({ type: String })], W.prototype, "dropPosition", void 0), B([s({ type: Array })], W.prototype, "selectedTaskIds", void 0), B([s({ type: String })], W.prototype, "focusedTaskId", void 0), B([s({
1960
+ })], G.prototype, "isSelected", void 0), B([s({ type: String })], G.prototype, "dropPosition", void 0), B([s({ type: Array })], G.prototype, "selectedTaskIds", void 0), B([s({ type: String })], G.prototype, "focusedTaskId", void 0), B([s({
1936
1961
  type: Boolean,
1937
1962
  reflect: !0
1938
- })], W.prototype, "isExporting", void 0), B([s({ type: Array })], W.prototype, "criticalPathTaskIds", void 0), W = B([o("gantt-row")], W);
1963
+ })], G.prototype, "isExporting", void 0), B([s({ type: Array })], G.prototype, "criticalPathTaskIds", void 0), G = B([o("gantt-row")], G);
1939
1964
  //#endregion
1940
1965
  //#region src/components/gantt-chart-dependency-path.ts
1941
- function G(e, t, n, r, i, a, o, s) {
1966
+ function K(e, t, n, r, i, a, o, s) {
1942
1967
  let c = (n) => {
1943
1968
  if (Math.abs(t - r) < 1) return `M ${e} ${t} L ${n} ${r}`;
1944
1969
  if (e < n) {
@@ -1974,7 +1999,7 @@ function G(e, t, n, r, i, a, o, s) {
1974
1999
  }
1975
2000
  //#endregion
1976
2001
  //#region src/components/gantt-chart-styles.ts
1977
- var K = t`
2002
+ var q = t`
1978
2003
  :host {
1979
2004
  display: block;
1980
2005
  width: 100%;
@@ -2009,7 +2034,7 @@ var K = t`
2009
2034
  font-size: 11px;
2010
2035
  white-space: nowrap;
2011
2036
  pointer-events: none;
2012
- z-index: 1000;
2037
+ z-index: 2000;
2013
2038
  margin-top: -6px;
2014
2039
  text-align: left;
2015
2040
  line-height: 1.4;
@@ -2031,6 +2056,14 @@ var K = t`
2031
2056
  border-width: 4px;
2032
2057
  border-style: solid;
2033
2058
  }
2059
+ .tooltip.below {
2060
+ transform: translate(-50%, 0);
2061
+ margin-top: 6px;
2062
+ }
2063
+ .tooltip.below::after {
2064
+ top: auto;
2065
+ bottom: 100%;
2066
+ }
2034
2067
  .drag-info-overlay {
2035
2068
  position: fixed;
2036
2069
  top: 0;
@@ -2117,7 +2150,7 @@ var K = t`
2117
2150
  z-index: 58;
2118
2151
  }
2119
2152
  `;
2120
- function q(e, t) {
2153
+ function J(e, t) {
2121
2154
  let n = F(e, t);
2122
2155
  return `
2123
2156
  :host {
@@ -2134,6 +2167,9 @@ function q(e, t) {
2134
2167
  .tooltip::after {
2135
2168
  border-color: ${n.tooltipBg} transparent transparent transparent;
2136
2169
  }
2170
+ .tooltip.below::after {
2171
+ border-color: transparent transparent ${n.tooltipBg} transparent;
2172
+ }
2137
2173
  .drag-info-overlay {
2138
2174
  background: ${n.dragOverlayBg};
2139
2175
  color: ${n.dragOverlayText};
@@ -2169,11 +2205,11 @@ function q(e, t) {
2169
2205
  }
2170
2206
  //#endregion
2171
2207
  //#region src/components/gantt-chart-export.ts
2172
- function J(e, t) {
2208
+ function Y(e, t) {
2173
2209
  let n = document.createElement("a");
2174
2210
  n.href = e, n.download = t, n.click();
2175
2211
  }
2176
- async function Y(e, t = "png", n = {}) {
2212
+ async function X(e, t = "png", n = {}) {
2177
2213
  let { filename: r = "gantt-chart", download: i = !1, scale: a = 2, splitHeight: o } = n, s = e.shadowRoot?.querySelector(".scroll-container"), c = s ? s.scrollWidth : e.scrollWidth, l = s ? s.scrollHeight : e.scrollHeight, u = await f(e, {
2178
2214
  backgroundColor: "#ffffff",
2179
2215
  scale: a,
@@ -2244,12 +2280,12 @@ async function Y(e, t = "png", n = {}) {
2244
2280
  return t.addImage(e, "JPEG", 0, 0, c, l, void 0, "FAST"), i && t.save(`${r}.pdf`), t.output("blob");
2245
2281
  } else {
2246
2282
  let e = u.toDataURL("image/png");
2247
- return i && J(e, `${r}.png`), e;
2283
+ return i && Y(e, `${r}.png`), e;
2248
2284
  }
2249
2285
  }
2250
2286
  //#endregion
2251
2287
  //#region src/core/critical-path.ts
2252
- function X(e) {
2288
+ function Z(e) {
2253
2289
  let t = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map();
2254
2290
  for (let n of e) for (let e of n.tasks) {
2255
2291
  let n = e.dependencies ?? [], i = e.start instanceof Date ? e.start.getTime() : new Date(e.start).getTime(), a = e.end instanceof Date ? e.end.getTime() : new Date(e.end).getTime();
@@ -2317,7 +2353,7 @@ function X(e) {
2317
2353
  }
2318
2354
  //#endregion
2319
2355
  //#region src/components/gantt-chart.ts
2320
- var Z = class extends e {
2356
+ var Q = class extends e {
2321
2357
  constructor(...e) {
2322
2358
  super(...e), this.rows = [], this.theme = "light", this.selectedRowIds = [], this.selectedTaskIds = [], this.externalDraggingTask = null, this.selectedRows = /* @__PURE__ */ new Set(), this.selectedTasks = /* @__PURE__ */ new Set(), this.lastClickedRowId = null, this.virtualScrollTop = 0, this.dragTargetRowIndex = null, this.draggingTask = null, this.draggingTaskIds = [], this.multiDragDx = 0, this.multiDragDy = 0, this.multiDragSameRow = !1, this.viewportHeight = 400, this.dragOverlayInfo = null, this.calendarHeight = 0, this.tooltip = null, this.dragOverRowId = null, this.dragOverPosition = null, this.currentTime = /* @__PURE__ */ new Date(), this.dragPreview = null, this.currentRowHeaderWidth = 150, this.isResizingHeader = !1, this.hoveredMilestoneId = null, this.cursorLineX = null, this.connectorDrag = null, this._systemThemeMediaQuery = null, this.isExporting = !1, this.focusedTaskId = null, this.focusedRowId = null, this.zoomPxPerDay = null, this.zoomPxPerMonth = null, this._layoutCache = null, this.resizeObserver = null, this._cachedSelectedTaskIds = [], this._cachedSelectedTasksSize = -1, this._cachedCurrentOption = null, this._lastOptionRef = null, this._lastLabelWidth = -1, this._lastZoomPxPerDay = null, this._lastZoomPxPerMonth = null, this._scrollContainer = null, this.handleSystemThemeChange = (e) => {
2323
2359
  (this.option?.theme === "system" || this.option?.theme !== "light" && this.option?.theme !== "dark") && (this.theme = e.matches ? "dark" : "light");
@@ -2418,7 +2454,7 @@ var Z = class extends e {
2418
2454
  return this.zoomPxPerMonth ?? this.option.calendar.pxPerMonth;
2419
2455
  }
2420
2456
  static {
2421
- this.styles = K;
2457
+ this.styles = q;
2422
2458
  }
2423
2459
  firstUpdated() {
2424
2460
  this.setupCurrentTimeTimer();
@@ -2469,8 +2505,16 @@ var Z = class extends e {
2469
2505
  <div class="tooltip-row">${t.tooltip.duration(a)}</div>
2470
2506
  `, e);
2471
2507
  }
2472
- let i = e.getBoundingClientRect(), a = this.tooltip.x, o = this.tooltip.y;
2473
- i.right > window.innerWidth - 6 && (a = window.innerWidth - 6 - i.width / 2), i.left < 6 && (a = 6 + i.width / 2), i.top < 6 && (e.style.transform = "translate(-50%, 0)", e.style.marginTop = "6px"), (a !== this.tooltip.x || o !== this.tooltip.y) && (e.style.left = `${a}px`, e.style.top = `${o}px`);
2508
+ let i = e.getBoundingClientRect();
2509
+ if (!this.tooltip.below && i.top < 6) {
2510
+ this.tooltip = {
2511
+ ...this.tooltip,
2512
+ below: !0
2513
+ };
2514
+ return;
2515
+ }
2516
+ let a = this.tooltip.x;
2517
+ i.right > window.innerWidth - 6 && (a = window.innerWidth - 6 - i.width / 2), i.left < 6 && (a = 6 + i.width / 2), a !== this.tooltip.x && (e.style.left = `${a}px`);
2474
2518
  }
2475
2519
  }
2476
2520
  }
@@ -2773,11 +2817,13 @@ var Z = class extends e {
2773
2817
  t > 0 ? this.hoverTimer = window.setTimeout(() => {
2774
2818
  this.tooltip = {
2775
2819
  ...e.detail,
2776
- visible: !0
2820
+ visible: !0,
2821
+ below: !1
2777
2822
  };
2778
2823
  }, t) : this.tooltip = {
2779
2824
  ...e.detail,
2780
- visible: !0
2825
+ visible: !0,
2826
+ below: !1
2781
2827
  };
2782
2828
  }
2783
2829
  handleBarMouseLeave() {
@@ -3006,7 +3052,7 @@ var Z = class extends e {
3006
3052
  async exportImage(e = "png", t = {}) {
3007
3053
  this.isExporting = !0, await this.updateComplete, await new Promise((e) => requestAnimationFrame(e));
3008
3054
  try {
3009
- return await Y(this, e, t);
3055
+ return await X(this, e, t);
3010
3056
  } finally {
3011
3057
  this.isExporting = !1, await this.updateComplete;
3012
3058
  }
@@ -3333,14 +3379,14 @@ var Z = class extends e {
3333
3379
  break;
3334
3380
  }
3335
3381
  }
3336
- let d = this.displayRows.slice(c, l + 1), f = this.isExporting ? 0 : t[c] ? t[c].top : 0, p = t[l], m = p ? p.top + p.height : 0, h = Math.max(0, a - m), g = a > this.viewportHeight, _ = [], v = this.option.readOnly === !0, y = this.option.dependency?.showArrows !== !1, b = this.option.dependency?.arrowSize ?? 8, x = this.option.dependency?.lineStyle ?? "orthogonal", S = this.option.dependency?.cornerRadius ?? 8, C = this.option.dependency?.showCriticalPath === !0, w = C ? X(this.displayRows) : /* @__PURE__ */ new Set();
3382
+ let d = this.displayRows.slice(c, l + 1), f = this.isExporting ? 0 : t[c] ? t[c].top : 0, p = t[l], m = p ? p.top + p.height : 0, h = Math.max(0, a - m), g = a > this.viewportHeight, _ = [], v = this.option.readOnly === !0, y = this.option.dependency?.showArrows !== !1, b = this.option.dependency?.arrowSize ?? 8, x = this.option.dependency?.lineStyle ?? "orthogonal", S = this.option.dependency?.cornerRadius ?? 8, C = this.option.dependency?.showCriticalPath === !0, w = C ? Z(this.displayRows) : /* @__PURE__ */ new Set();
3337
3383
  for (let [e, t] of r) if (t.dependencies) for (let n of t.dependencies) {
3338
3384
  let a = r.get(n);
3339
3385
  if (a) {
3340
3386
  let r = a.x + a.width, o = a.y + a.height / 2, s = t.x, c = t.y + t.height / 2, l = r < s, u = y ? s - b : s, d = l ? Math.max(r, u) : u, f, p, m, h = this.option.bar?.height ?? 28, g = this.option.bar?.margin ?? 4;
3341
3387
  if (Math.abs(o - c) < 1 && l) f = d > r ? `M ${r} ${o} L ${d} ${c}` : "", p = s > r ? `M ${r} ${o} L ${s} ${c}` : "";
3342
3388
  else if (x === "orthogonal") {
3343
- let e = G(r, o, s, c, d, h, g, S);
3389
+ let e = K(r, o, s, c, d, h, g, S);
3344
3390
  f = e.pathD, p = e.hitPathD;
3345
3391
  } else if (l) {
3346
3392
  let e = (r + d) / 2;
@@ -3372,7 +3418,7 @@ var Z = class extends e {
3372
3418
  }
3373
3419
  }
3374
3420
  return n`
3375
- <style>${q(this.theme, this.option.customTheme)}
3421
+ <style>${J(this.theme, this.option.customTheme)}
3376
3422
  :host {
3377
3423
  --critical-path-color: ${e.criticalPath ?? "rgba(220, 38, 38, 0.85)"};
3378
3424
  }
@@ -3547,16 +3593,16 @@ var Z = class extends e {
3547
3593
  ${this.option.showDragInfoOverlay === !1 ? "" : n` <div class="drag-info-overlay"></div> `}
3548
3594
  ${this.tooltip ? n`
3549
3595
  <div
3550
- class="tooltip ${this.tooltip.visible ? "visible" : ""}"
3551
- style="top: ${this.tooltip.y}px; left: ${this.tooltip.x}px;"
3596
+ class="tooltip ${this.tooltip.visible ? "visible" : ""} ${this.tooltip.below ? "below" : ""}"
3597
+ style="top: ${this.tooltip.below ? this.tooltip.barBottom : this.tooltip.y}px; left: ${this.tooltip.x}px;"
3552
3598
  />
3553
3599
  ` : ""}
3554
3600
  `;
3555
3601
  }
3556
3602
  };
3557
- B([s({ type: Array })], Z.prototype, "rows", void 0), B([s({ type: Object })], Z.prototype, "option", void 0), B([s({
3603
+ B([s({ type: Array })], Q.prototype, "rows", void 0), B([s({ type: Object })], Q.prototype, "option", void 0), B([s({
3558
3604
  type: String,
3559
3605
  reflect: !0
3560
- })], Z.prototype, "theme", void 0), B([s({ type: Array })], Z.prototype, "selectedRowIds", void 0), B([s({ type: Array })], Z.prototype, "selectedTaskIds", void 0), B([s({ attribute: !1 })], Z.prototype, "externalDraggingTask", void 0), B([c()], Z.prototype, "selectedRows", void 0), B([c()], Z.prototype, "selectedTasks", void 0), B([c()], Z.prototype, "lastClickedRowId", void 0), B([c()], Z.prototype, "virtualScrollTop", void 0), B([c()], Z.prototype, "dragTargetRowIndex", void 0), B([c()], Z.prototype, "draggingTask", void 0), B([c()], Z.prototype, "draggingTaskIds", void 0), B([c()], Z.prototype, "multiDragDx", void 0), B([c()], Z.prototype, "multiDragDy", void 0), B([c()], Z.prototype, "multiDragSameRow", void 0), B([c()], Z.prototype, "viewportHeight", void 0), B([c()], Z.prototype, "calendarHeight", void 0), B([c()], Z.prototype, "tooltip", void 0), B([c()], Z.prototype, "dragOverRowId", void 0), B([c()], Z.prototype, "dragOverPosition", void 0), B([c()], Z.prototype, "currentTime", void 0), B([c()], Z.prototype, "dragPreview", void 0), B([c()], Z.prototype, "currentRowHeaderWidth", void 0), B([c()], Z.prototype, "isResizingHeader", void 0), B([c()], Z.prototype, "hoveredMilestoneId", void 0), B([c()], Z.prototype, "cursorLineX", void 0), B([c()], Z.prototype, "connectorDrag", void 0), B([c()], Z.prototype, "isExporting", void 0), B([c()], Z.prototype, "focusedTaskId", void 0), B([c()], Z.prototype, "focusedRowId", void 0), B([c()], Z.prototype, "zoomPxPerDay", void 0), B([c()], Z.prototype, "zoomPxPerMonth", void 0), Z = B([o("gantt-chart")], Z);
3606
+ })], Q.prototype, "theme", void 0), B([s({ type: Array })], Q.prototype, "selectedRowIds", void 0), B([s({ type: Array })], Q.prototype, "selectedTaskIds", void 0), B([s({ attribute: !1 })], Q.prototype, "externalDraggingTask", void 0), B([c()], Q.prototype, "selectedRows", void 0), B([c()], Q.prototype, "selectedTasks", void 0), B([c()], Q.prototype, "lastClickedRowId", void 0), B([c()], Q.prototype, "virtualScrollTop", void 0), B([c()], Q.prototype, "dragTargetRowIndex", void 0), B([c()], Q.prototype, "draggingTask", void 0), B([c()], Q.prototype, "draggingTaskIds", void 0), B([c()], Q.prototype, "multiDragDx", void 0), B([c()], Q.prototype, "multiDragDy", void 0), B([c()], Q.prototype, "multiDragSameRow", void 0), B([c()], Q.prototype, "viewportHeight", void 0), B([c()], Q.prototype, "calendarHeight", void 0), B([c()], Q.prototype, "tooltip", void 0), B([c()], Q.prototype, "dragOverRowId", void 0), B([c()], Q.prototype, "dragOverPosition", void 0), B([c()], Q.prototype, "currentTime", void 0), B([c()], Q.prototype, "dragPreview", void 0), B([c()], Q.prototype, "currentRowHeaderWidth", void 0), B([c()], Q.prototype, "isResizingHeader", void 0), B([c()], Q.prototype, "hoveredMilestoneId", void 0), B([c()], Q.prototype, "cursorLineX", void 0), B([c()], Q.prototype, "connectorDrag", void 0), B([c()], Q.prototype, "isExporting", void 0), B([c()], Q.prototype, "focusedTaskId", void 0), B([c()], Q.prototype, "focusedRowId", void 0), B([c()], Q.prototype, "zoomPxPerDay", void 0), B([c()], Q.prototype, "zoomPxPerMonth", void 0), Q = B([o("gantt-chart")], Q);
3561
3607
  //#endregion
3562
- export { m as ALL_BAR_PATTERNS, V as GanttBarElement, H as GanttCalendarElement, Z as GanttChartElement, W as GanttRowElement, y as PATTERN_CHECKERBOARD, S as PATTERN_CIRCLE, w as PATTERN_DIAGONAL_GRID, h as PATTERN_DIAGONAL_STRIPE, g as PATTERN_DIAGONAL_STRIPE_REVERSE, b as PATTERN_DOTS, D as PATTERN_DOTS_DENSE, C as PATTERN_GRID, v as PATTERN_HORIZONTAL_STRIPE, E as PATTERN_STRIPE_THICK, T as PATTERN_STRIPE_THIN, x as PATTERN_TRIANGLE, _ as PATTERN_VERTICAL_STRIPE, X as computeCriticalPath, A as enLocale, O as getPatternStyle, k as jaLocale };
3608
+ export { m as ALL_BAR_PATTERNS, H as GanttBarElement, U as GanttCalendarElement, Q as GanttChartElement, G as GanttRowElement, y as PATTERN_CHECKERBOARD, S as PATTERN_CIRCLE, w as PATTERN_DIAGONAL_GRID, h as PATTERN_DIAGONAL_STRIPE, g as PATTERN_DIAGONAL_STRIPE_REVERSE, b as PATTERN_DOTS, D as PATTERN_DOTS_DENSE, C as PATTERN_GRID, v as PATTERN_HORIZONTAL_STRIPE, E as PATTERN_STRIPE_THICK, T as PATTERN_STRIPE_THIN, x as PATTERN_TRIANGLE, _ as PATTERN_VERTICAL_STRIPE, Z as computeCriticalPath, A as enLocale, O as getPatternStyle, k as jaLocale };
@@ -51,7 +51,7 @@
51
51
  background-image: linear-gradient(${t} 1px, transparent 1px), linear-gradient(90deg, ${t} 1px, transparent 1px);
52
52
  background-size: ${n} ${n};
53
53
  background-repeat: repeat;
54
- `;default:return``}}var j={monthFormat:`YYYY年M月`,monthRowFormat:`M月`,dateFormat:e=>`${e.getFullYear()}/${e.getMonth()+1}/${e.getDate()}`,timeUnitDateFormat:e=>`${e.getFullYear()}年${e.getMonth()+1}月${e.getDate()}日`,dateTimeFormat:e=>{let t=`${e.getFullYear()}/${e.getMonth()+1}/${e.getDate()}`,n=e.getHours(),r=e.getMinutes();return n===0&&r===0?t:`${t} ${n.toString().padStart(2,`0`)}:${r.toString().padStart(2,`0`)}`},yearMonthFormat:e=>`${e.getFullYear()}/${e.getMonth()+1}`,duration:{days:e=>`${e}日`,hours:e=>`${e}時間`,minutes:e=>`${e}分`,zero:`0分`},tooltip:{duration:e=>`所要日数: ${e}日`},dragOverlay:{noTitle:`タイトルなし`,moveTo:e=>`移動先: ${e}`,movingTasks:e=>`${e}件のタスクを移動中`}},M={monthFormat:`MMM YYYY`,monthRowFormat:`MMM`,dateFormat:e=>`${e.getMonth()+1}/${e.getDate()}/${e.getFullYear()}`,timeUnitDateFormat:e=>`${[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`][e.getMonth()]} ${e.getDate()}, ${e.getFullYear()}`,dateTimeFormat:e=>{let t=`${e.getMonth()+1}/${e.getDate()}/${e.getFullYear()}`,n=e.getHours(),r=e.getMinutes();return n===0&&r===0?t:`${t} ${n.toString().padStart(2,`0`)}:${r.toString().padStart(2,`0`)}`},yearMonthFormat:e=>`${e.getFullYear()}/${e.getMonth()+1}`,duration:{days:e=>`${e} day${e===1?``:`s`}`,hours:e=>`${e} hour${e===1?``:`s`}`,minutes:e=>`${e} minute${e===1?``:`s`}`,zero:`0 minutes`},tooltip:{duration:e=>`Duration: ${e} day${e===1?``:`s`}`},dragOverlay:{noTitle:`No Title`,moveTo:e=>`Move to: ${e}`,movingTasks:e=>`Moving ${e} task${e===1?``:`s`}`}},N={light:{bg:`#f1f5f9`,text:`#0f172a`,border:`#cbd5e1`,gridLine:`#cbd5e1`,subGridLine:`#e2e8f0`,monthGridLine:`#94a3b8`,yearGridLine:`#64748b`,dragTarget:`#e0f2fe`,tooltipBg:`rgba(0, 0, 0, 0.8)`,tooltipText:`white`,dragOverlayBg:`rgba(0, 0, 0, 0.85)`,dragOverlayText:`white`,dragOverlaySubText:`#cbd5e1`,dragOverlayDivider:`#666`,dependencyLine:`#94a3b8`,calendarBg:`#e2e8f0`,saturday:`#dbeafe`,sunday:`#fee2e2`,holiday:`#fee2e2`,rowHeaderBg:`#e2e8f0`,rowSelected:`#bfdbfe`,rowSelectedHeader:`#dbeafe`,rowHiddenBg:`repeating-linear-gradient(45deg, #f3f4f6, #f3f4f6 10px, #e5e7eb 10px, #e5e7eb 20px)`,currentTimeLine:`rgba(239, 68, 68, 0.5)`,currentTimeLineText:`#ffffff`,criticalPath:`rgba(220, 38, 38, 0.85)`},dark:{bg:`#1e293b`,text:`#f8fafc`,border:`#263040`,gridLine:`#334155`,subGridLine:`#263040`,monthGridLine:`#475569`,yearGridLine:`#64748b`,dragTarget:`rgba(51, 65, 85, 0.5)`,tooltipBg:`rgba(255, 255, 255, 0.9)`,tooltipText:`#0f172a`,dragOverlayBg:`rgba(255, 255, 255, 0.9)`,dragOverlayText:`#0f172a`,dragOverlaySubText:`#64748b`,dragOverlayDivider:`#cbd5e1`,dependencyLine:`#475569`,calendarBg:`#0f172a`,saturday:`rgba(59, 130, 246, 0.15)`,sunday:`rgba(239, 68, 68, 0.15)`,holiday:`rgba(239, 68, 68, 0.15)`,rowHeaderBg:`#0f172a`,rowSelected:`#283548`,rowSelectedHeader:`#1c2738`,rowHiddenBg:`repeating-linear-gradient(45deg, #0f172a, #0f172a 10px, #1e293b 10px, #1e293b 20px)`,currentTimeLine:`rgba(239, 68, 68, 0.5)`,currentTimeLineText:`#ffffff`,criticalPath:`rgba(248, 113, 113, 0.85)`}},P=(e,t,n,r)=>{if(r!==void 0){let n=t.getFullYear(),i=t.getMonth(),a=e.getFullYear(),o=e.getMonth(),s=(a-n)*12+(o-i),c=new Date(n,i+1,0).getDate(),l=(t.getDate()-1+t.getHours()/24+t.getMinutes()/1440)/c,u=new Date(a,o+1,0).getDate();return(s+(e.getDate()-1+e.getHours()/24+e.getMinutes()/1440)/u-l)*r}return(e.getTime()-t.getTime())/(1e3*60*60*24)*n},F=(e,t,n,r)=>{if(r!==void 0){let n=t.getFullYear(),i=t.getMonth(),a=new Date(n,i+1,0).getDate(),o=(t.getDate()-1+t.getHours()/24+t.getMinutes()/1440)/a,s=e/r+o,c=i+Math.floor(s),l=n+Math.floor(c/12);c%=12,c<0&&(c+=12,--l);let u=(s-Math.floor(s))*new Date(l,c+1,0).getDate(),d=1+Math.floor(u),f=(u-Math.floor(u))*24,p=Math.floor(f),m=Math.round((f-p)*60);return new Date(l,c,d,p,m)}let i=e/n;return new Date(t.getTime()+i*24*60*60*1e3)};function I(e){if(!e.length)return{tasksWithLanes:[],laneCount:1};let t=[...e].sort((e,t)=>e.start.getTime()-t.start.getTime()),n=[],r=new Map;for(let e of t){let t=-1;for(let r=0;r<n.length;r++)if(e.start>=n[r]){n[r]=e.end,t=r;break}t===-1&&(n.push(e.end),t=n.length-1),r.set(e.id,t)}return{tasksWithLanes:e.map(e=>({...e,lane:r.get(e.id)??0})),laneCount:n.length||1}}var L=(e,t)=>({...N[e]||N.light,...t}),R=(e,t,n)=>{let r=e.getDay();return n&&n(e)?t.holiday:[t.sunday,t.monday??``,t.tuesday??``,t.wednesday??``,t.thursday??``,t.friday??``,t.saturday][r]};function z(e,t){return(t.getTime()-e.getTime())/(1e3*60*60*24)}var B=(e,t,n)=>{let r=n??j,i=t.getTime()-e.getTime(),a=Math.floor(i/(1e3*60*60*24)),o=i%(1e3*60*60*24),s=Math.floor(o/(1e3*60*60)),c=o%(1e3*60*60),l=Math.floor(c/(1e3*60)),u=``;return a>0&&(u+=r.duration.days(a)),s>0&&(u+=r.duration.hours(s)),l>0&&(u+=r.duration.minutes(l)),u||r.duration.zero},V={BAR:`#3b82f6`,LABEL_BACKGROUND:`#fafafa`,SATURDAY:`#dbeafe`,SUNDAY:`#fee2e2`,HOLIDAY:`#fee2e2`,BORDER:`#e2e8f0`}.BAR;function H(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}var U=class extends t.LitElement{constructor(...e){super(...e),this.lane=0,this.selected=!1,this.focused=!1,this.multiDragDx=0,this.multiDragDy=0,this.multiDragActive=!1,this.multiDragSameRow=!1,this.connectorDropTarget=!1,this.isExporting=!1,this.isCriticalPath=!1,this._currentDragCursor=null,this._dragAnimationFrame=null,this._wasDragging=!1,this._connectorEdgeThreshold=30,this.handleKeyDown=e=>{(e.key===`Control`||e.key===`Alt`)&&this.updateCursor(!0)},this.handleKeyUp=e=>{(e.key===`Control`||e.key===`Alt`)&&this.updateCursor(!1)},this.onMouseMoveOnBar=e=>{let t=this.shadowRoot?.querySelector(`.task-group`);if(!t||this.option.readOnly||this.option.dependency?.showConnectors===!1)return;let n=t.getBoundingClientRect(),r=e.clientX-n.left,i=r<=this._connectorEdgeThreshold,a=r>=n.width-this._connectorEdgeThreshold,o=this.shadowRoot?.querySelector(`.connector-left`),s=this.shadowRoot?.querySelector(`.connector-right`);o&&o.classList.toggle(`show-connector`,i),s&&s.classList.toggle(`show-connector`,a)}}static{this.styles=t.css`
54
+ `;default:return``}}var j={monthFormat:`YYYY年M月`,monthRowFormat:`M月`,dateFormat:e=>`${e.getFullYear()}/${e.getMonth()+1}/${e.getDate()}`,timeUnitDateFormat:e=>`${e.getFullYear()}年${e.getMonth()+1}月${e.getDate()}日`,dateTimeFormat:e=>{let t=`${e.getFullYear()}/${e.getMonth()+1}/${e.getDate()}`,n=e.getHours(),r=e.getMinutes();return n===0&&r===0?t:`${t} ${n.toString().padStart(2,`0`)}:${r.toString().padStart(2,`0`)}`},yearMonthFormat:e=>`${e.getFullYear()}/${e.getMonth()+1}`,duration:{days:e=>`${e}日`,hours:e=>`${e}時間`,minutes:e=>`${e}分`,zero:`0分`},tooltip:{duration:e=>`所要日数: ${e}日`},dragOverlay:{noTitle:`タイトルなし`,moveTo:e=>`移動先: ${e}`,movingTasks:e=>`${e}件のタスクを移動中`}},M={monthFormat:`MMM YYYY`,monthRowFormat:`MMM`,dateFormat:e=>`${e.getMonth()+1}/${e.getDate()}/${e.getFullYear()}`,timeUnitDateFormat:e=>`${[`Jan`,`Feb`,`Mar`,`Apr`,`May`,`Jun`,`Jul`,`Aug`,`Sep`,`Oct`,`Nov`,`Dec`][e.getMonth()]} ${e.getDate()}, ${e.getFullYear()}`,dateTimeFormat:e=>{let t=`${e.getMonth()+1}/${e.getDate()}/${e.getFullYear()}`,n=e.getHours(),r=e.getMinutes();return n===0&&r===0?t:`${t} ${n.toString().padStart(2,`0`)}:${r.toString().padStart(2,`0`)}`},yearMonthFormat:e=>`${e.getFullYear()}/${e.getMonth()+1}`,duration:{days:e=>`${e} day${e===1?``:`s`}`,hours:e=>`${e} hour${e===1?``:`s`}`,minutes:e=>`${e} minute${e===1?``:`s`}`,zero:`0 minutes`},tooltip:{duration:e=>`Duration: ${e} day${e===1?``:`s`}`},dragOverlay:{noTitle:`No Title`,moveTo:e=>`Move to: ${e}`,movingTasks:e=>`Moving ${e} task${e===1?``:`s`}`}},N={light:{bg:`#f1f5f9`,text:`#0f172a`,border:`#cbd5e1`,gridLine:`#cbd5e1`,subGridLine:`#e2e8f0`,monthGridLine:`#94a3b8`,yearGridLine:`#64748b`,dragTarget:`#e0f2fe`,tooltipBg:`rgba(0, 0, 0, 0.8)`,tooltipText:`white`,dragOverlayBg:`rgba(0, 0, 0, 0.85)`,dragOverlayText:`white`,dragOverlaySubText:`#cbd5e1`,dragOverlayDivider:`#666`,dependencyLine:`#94a3b8`,calendarBg:`#e2e8f0`,saturday:`#dbeafe`,sunday:`#fee2e2`,holiday:`#fee2e2`,rowHeaderBg:`#e2e8f0`,rowSelected:`#bfdbfe`,rowSelectedHeader:`#dbeafe`,rowHiddenBg:`repeating-linear-gradient(45deg, #f3f4f6, #f3f4f6 10px, #e5e7eb 10px, #e5e7eb 20px)`,currentTimeLine:`rgba(239, 68, 68, 0.5)`,currentTimeLineText:`#ffffff`,criticalPath:`rgba(220, 38, 38, 0.85)`},dark:{bg:`#1e293b`,text:`#f8fafc`,border:`#263040`,gridLine:`#334155`,subGridLine:`#263040`,monthGridLine:`#475569`,yearGridLine:`#64748b`,dragTarget:`rgba(51, 65, 85, 0.5)`,tooltipBg:`rgba(255, 255, 255, 0.9)`,tooltipText:`#0f172a`,dragOverlayBg:`rgba(255, 255, 255, 0.9)`,dragOverlayText:`#0f172a`,dragOverlaySubText:`#64748b`,dragOverlayDivider:`#cbd5e1`,dependencyLine:`#475569`,calendarBg:`#0f172a`,saturday:`rgba(59, 130, 246, 0.15)`,sunday:`rgba(239, 68, 68, 0.15)`,holiday:`rgba(239, 68, 68, 0.15)`,rowHeaderBg:`#0f172a`,rowSelected:`#283548`,rowSelectedHeader:`#1c2738`,rowHiddenBg:`repeating-linear-gradient(45deg, #0f172a, #0f172a 10px, #1e293b 10px, #1e293b 20px)`,currentTimeLine:`rgba(239, 68, 68, 0.5)`,currentTimeLineText:`#ffffff`,criticalPath:`rgba(248, 113, 113, 0.85)`}},P=(e,t,n,r)=>{if(r!==void 0){let n=t.getFullYear(),i=t.getMonth(),a=e.getFullYear(),o=e.getMonth(),s=(a-n)*12+(o-i),c=new Date(n,i+1,0).getDate(),l=(t.getDate()-1+t.getHours()/24+t.getMinutes()/1440)/c,u=new Date(a,o+1,0).getDate();return(s+(e.getDate()-1+e.getHours()/24+e.getMinutes()/1440)/u-l)*r}return(e.getTime()-t.getTime())/(1e3*60*60*24)*n},F=(e,t,n,r)=>{if(r!==void 0){let n=t.getFullYear(),i=t.getMonth(),a=new Date(n,i+1,0).getDate(),o=(t.getDate()-1+t.getHours()/24+t.getMinutes()/1440)/a,s=e/r+o,c=i+Math.floor(s),l=n+Math.floor(c/12);c%=12,c<0&&(c+=12,--l);let u=(s-Math.floor(s))*new Date(l,c+1,0).getDate(),d=1+Math.floor(u),f=(u-Math.floor(u))*24,p=Math.floor(f),m=Math.round((f-p)*60);return new Date(l,c,d,p,m)}let i=e/n;return new Date(t.getTime()+i*24*60*60*1e3)};function I(e){if(!e.length)return{tasksWithLanes:[],laneCount:1};let t=[...e].sort((e,t)=>e.start.getTime()-t.start.getTime()),n=[],r=new Map;for(let e of t){let t=-1;for(let r=0;r<n.length;r++)if(e.start>=n[r]){n[r]=e.end,t=r;break}t===-1&&(n.push(e.end),t=n.length-1),r.set(e.id,t)}return{tasksWithLanes:e.map(e=>({...e,lane:r.get(e.id)??0})),laneCount:n.length||1}}var L=(e,t)=>({...N[e]||N.light,...t}),R=(e,t,n)=>{let r=e.getDay();return n&&n(e)?t.holiday:[t.sunday,t.monday??``,t.tuesday??``,t.wednesday??``,t.thursday??``,t.friday??``,t.saturday][r]};function z(e,t){return(t.getTime()-e.getTime())/(1e3*60*60*24)}var B=(e,t,n)=>{let r=n??j,i=t.getTime()-e.getTime(),a=Math.floor(i/(1e3*60*60*24)),o=i%(1e3*60*60*24),s=Math.floor(o/(1e3*60*60)),c=o%(1e3*60*60),l=Math.floor(c/(1e3*60)),u=``;return a>0&&(u+=r.duration.days(a)),s>0&&(u+=r.duration.hours(s)),l>0&&(u+=r.duration.minutes(l)),u||r.duration.zero},V={BAR:`#3b82f6`,LABEL_BACKGROUND:`#fafafa`,SATURDAY:`#dbeafe`,SUNDAY:`#fee2e2`,HOLIDAY:`#fee2e2`,BORDER:`#e2e8f0`}.BAR;function H(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}var U,W=class extends t.LitElement{static{U=this}constructor(...e){super(...e),this.lane=0,this.selected=!1,this.focused=!1,this.multiDragDx=0,this.multiDragDy=0,this.multiDragActive=!1,this.multiDragSameRow=!1,this.connectorDropTarget=!1,this.isExporting=!1,this.isCriticalPath=!1,this._currentDragCursor=null,this._dragAnimationFrame=null,this._wasDragging=!1,this._connectorEdgeThreshold=30,this.handleKeyDown=e=>{(e.key===`Control`||e.key===`Alt`)&&this.updateCursor(!0)},this.handleKeyUp=e=>{(e.key===`Control`||e.key===`Alt`)&&this.updateCursor(!1)},this.onMouseMoveOnBar=e=>{let t=this.shadowRoot?.querySelector(`.task-group`);if(!t||this.option.readOnly||this.option.dependency?.showConnectors===!1)return;let n=t.getBoundingClientRect(),r=e.clientX-n.left,i=r<=this._connectorEdgeThreshold,a=r>=n.width-this._connectorEdgeThreshold,o=this.shadowRoot?.querySelector(`.connector-left`),s=this.shadowRoot?.querySelector(`.connector-right`);o&&o.classList.toggle(`show-connector`,i),s&&s.classList.toggle(`show-connector`,a)}}static{this.styles=t.css`
55
55
  :host {
56
56
  display: block;
57
57
  position: absolute;
@@ -215,7 +215,7 @@
215
215
  filter: brightness(1.08);
216
216
  }
217
217
  }
218
- `}getX(e){return P(e,this.option.calendar.start,this.option.calendar.pxPerDay??50,this.option.calendar.pxPerMonth)}setupDragEvents(e,t,n,r){let i=()=>{e.releasePointerCapture(t),window.removeEventListener(`pointermove`,a),window.removeEventListener(`pointerup`,o),window.removeEventListener(`keydown`,s)},a=e=>{n(e)},o=e=>{i(),r(!1,e)},s=e=>{e.key===`Escape`&&(i(),r(!0))};window.addEventListener(`pointermove`,a),window.addEventListener(`pointerup`,o),window.addEventListener(`keydown`,s)}onResizeStart(e,t){e.stopPropagation();let n=e.target,r=this.task.movable??`both`,i=this.task.resizable,a=!this.option.readOnly;if(a&&=i===void 0?!(r===`y`||r===`none`):i,!a)return;let o=this.shadowRoot?.querySelector(`.bar`);if(!o)return;o.style.pointerEvents=`none`;let s=this.shadowRoot?.querySelector(`.task-group`);s?.classList.add(`dragging`),n.setPointerCapture(e.pointerId);let c=e.clientX,l=new Date(this.task.start),u=new Date(this.task.end),d=new Date(l),f=new Date(u);this.setupDragEvents(n,e.pointerId,e=>{let n=e.clientX-c,r=new Date(l),i=new Date(u),a=this.option.calendar.pxPerDay??50,o=this.option.calendar.pxPerMonth,p=Math.max(this.option.snapDuration??1440,1);if(o){let e=this.getX(l),s=this.getX(u);if(t===`left`){let t=F(e+n,this.option.calendar.start,a,o);t.getDate()>15&&t.setMonth(t.getMonth()+1),t.setDate(1),t.setHours(0,0,0,0),r=t,r>=i&&(r=new Date(i),r.setMonth(r.getMonth()-1))}else{let e=F(s+n,this.option.calendar.start,a,o);e.getDate()>15&&e.setMonth(e.getMonth()+1),e.setDate(1),e.setHours(0,0,0,0),i=e,i<=r&&(i=new Date(r),i.setMonth(i.getMonth()+1))}}else{let e=a/1440,o=e*p,s=Math.round(n/o)*o,c=Math.round(s/e);t===`left`?(r=new Date(l.getTime()+c*60*1e3),r>=i&&(r=new Date(i.getTime()-p*60*1e3))):(i=new Date(u.getTime()+c*60*1e3),i<=r&&(i=new Date(r.getTime()+p*60*1e3)))}if(d=r,f=i,s){let e=this.getX(r),t=this.getX(i)-e;s.style.left=`${e}px`,s.style.width=`${t}px`}this._dragAnimationFrame&&cancelAnimationFrame(this._dragAnimationFrame),this._dragAnimationFrame=requestAnimationFrame(()=>{this.dispatchEvent(new CustomEvent(`task-update`,{detail:{...this.task,start:r,end:i,dy:0,isDragging:!0,x:e.clientX,y:e.clientY},bubbles:!0,composed:!0}))})},e=>{if(s?.classList.remove(`dragging`),o.style.pointerEvents=``,this._dragAnimationFrame&&=(cancelAnimationFrame(this._dragAnimationFrame),null),e){if(s){let e=this.getX(l),t=this.getX(u)-e;s.style.left=`${e}px`,s.style.width=`${t}px`}this.requestUpdate(),this.dispatchEvent(new CustomEvent(`task-update`,{detail:{...this.task,start:l,end:u,dy:0,isDragging:!1},bubbles:!0,composed:!0}))}else requestAnimationFrame(()=>{this.dispatchEvent(new CustomEvent(`task-update`,{detail:{...this.task,start:d,end:f,dy:0,isDragging:!1},bubbles:!0,composed:!0}))})})}onMoveStart(e){if(e.button===2)return;e.stopPropagation();let t=e.target,n=this.shadowRoot?.querySelector(`.task-group`);if(!t||!n)return;let r=this.task.movable??`both`;if(r===`none`)return;let i=e.ctrlKey||e.altKey?`copy`:`grabbing`;this._currentDragCursor=i,t.style.cursor=i,t.setPointerCapture(e.pointerId),n.classList.add(`dragging`);let a=e.clientX,o=e.clientY,s=new Date(this.task.start),c=new Date(this.task.end),l=this.option.snapDuration??1440;this.setupDragEvents(t,e.pointerId,e=>{let i=e.ctrlKey||e.altKey?`copy`:`grabbing`;this._currentDragCursor=i,t.style.cursor=i;let u=e.clientX-a,d=e.clientY-o;r===`y`&&(u=0),r===`x`&&(d=0),this.multiDragActive&&!this.multiDragSameRow&&(d=0);let f=u;if(this.option.calendar.pxPerMonth){let e=F(this.getX(s)+u,this.option.calendar.start,50,this.option.calendar.pxPerMonth),t=(e.getFullYear()-s.getFullYear())*12+(e.getMonth()-s.getMonth())+(e.getDate()>15?1:0),n=new Date(s);n.setMonth(n.getMonth()+t),f=this.getX(n)-this.getX(s)}else{let e=this.option.calendar.pxPerDay/1440*l;f=Math.round(u/e)*e}n.style.transform=`translate(${f}px, ${d}px)`,this._dragAnimationFrame&&cancelAnimationFrame(this._dragAnimationFrame),this._dragAnimationFrame=requestAnimationFrame(()=>{let t=e.ctrlKey||e.altKey;this.dispatchEvent(new CustomEvent(`task-update`,{detail:{...this.task,start:s,end:c,dx:f,dy:d,isDragging:!0,x:e.clientX,y:e.clientY,mode:t?`copy`:`move`},bubbles:!0,composed:!0}))})},(e,i)=>{if(this._currentDragCursor=null,n.classList.remove(`dragging`),n.style.transform=``,t.style.cursor=``,this._dragAnimationFrame&&=(cancelAnimationFrame(this._dragAnimationFrame),null),e)this.requestUpdate(),this.dispatchEvent(new CustomEvent(`task-update`,{detail:{...this.task,start:s,end:c,dx:0,dy:0,isDragging:!1},bubbles:!0,composed:!0}));else if(i){let e=i.clientX-a,t=e;if(this.option.calendar.pxPerMonth){let n=F(this.getX(s)+e,this.option.calendar.start,50,this.option.calendar.pxPerMonth),r=(n.getFullYear()-s.getFullYear())*12+(n.getMonth()-s.getMonth())+(n.getDate()>15?1:0),i=new Date(s);i.setMonth(i.getMonth()+r),t=this.getX(i)-this.getX(s)}else{let n=this.option.calendar.pxPerDay/1440*l;t=Math.round(e/n)*n}let n=i.clientY-o;if(r===`y`&&(t=0),r===`x`&&(n=0),this.multiDragActive&&!this.multiDragSameRow&&(n=0),t===0&&Math.abs(n)<5){this.dispatchEvent(new CustomEvent(`bar-click`,{detail:{task:this.task,event:i,isMultiSelect:i.metaKey||i.ctrlKey},bubbles:!0,composed:!0})),this._wasDragging=!0;return}let u=i.ctrlKey||i.altKey;this._wasDragging=!0,this.multiDragActive||this.dispatchEvent(new CustomEvent(`bar-click`,{detail:{task:this.task,event:i,isMultiSelect:!1},bubbles:!0,composed:!0})),this.dispatchEvent(new CustomEvent(`task-update`,{detail:{...this.task,start:s,end:c,dx:t,dy:n,isDragging:!1,mode:u?`copy`:`move`},bubbles:!0,composed:!0}))}})}updated(e){super.updated(e);let t=this.shadowRoot?.querySelector(`.bar`);if(t&&(this.option.customRendering?.barContent,this.dispatchEvent(new CustomEvent(`render-bar-content`,{detail:{container:t,task:this.task},bubbles:!0,composed:!0})),this._currentDragCursor?t.style.cursor=this._currentDragCursor:this.option.readOnly||(t.style.cursor=``)),e.has(`multiDragDx`)||e.has(`multiDragDy`)){let e=this.shadowRoot?.querySelector(`.task-group`);e&&(this.multiDragDx!==0||this.multiDragDy!==0?(e.style.transform=`translate(${this.multiDragDx}px, ${this.multiDragDy}px)`,e.style.opacity=`0.6`,e.style.pointerEvents=`none`):(e.style.transform=``,e.style.opacity=``,e.style.pointerEvents=``))}}disconnectedCallback(){super.disconnectedCallback(),window.removeEventListener(`keydown`,this.handleKeyDown),window.removeEventListener(`keyup`,this.handleKeyUp)}updateCursor(e){let t=this.shadowRoot?.querySelector(`.bar`);t&&!this._currentDragCursor&&(t.style.cursor=e?`copy`:``)}onMouseEnter(e){let t=e.currentTarget;if(t.classList.contains(`dragging`))return;this.option.readOnly||(window.addEventListener(`keydown`,this.handleKeyDown),window.addEventListener(`keyup`,this.handleKeyUp),(e.ctrlKey||e.altKey)&&this.updateCursor(!0),t.addEventListener(`mousemove`,this.onMouseMoveOnBar));let n=t.getBoundingClientRect();this.dispatchEvent(new CustomEvent(`bar-mouseenter`,{detail:{task:this.task,x:n.left+n.width/2,y:n.top},bubbles:!0,composed:!0}))}onMouseLeave(){let e=this.shadowRoot?.querySelector(`.task-group`);if(!this.option.readOnly){window.removeEventListener(`keydown`,this.handleKeyDown),window.removeEventListener(`keyup`,this.handleKeyUp),this.updateCursor(!1),e&&e.removeEventListener(`mousemove`,this.onMouseMoveOnBar);let t=this.shadowRoot?.querySelector(`.connector-left`),n=this.shadowRoot?.querySelector(`.connector-right`);t&&t.classList.remove(`show-connector`),n&&n.classList.remove(`show-connector`)}this.dispatchEvent(new CustomEvent(`bar-mouseleave`,{bubbles:!0,composed:!0}))}onDblClick(e){this.dispatchEvent(new CustomEvent(`task-dblclick`,{detail:{task:this.task,event:e},bubbles:!0,composed:!0}))}onClick(e){if(e.stopPropagation(),this._wasDragging){this._wasDragging=!1;return}this.dispatchEvent(new CustomEvent(`bar-click`,{detail:{task:this.task,event:e,isMultiSelect:e.metaKey||e.ctrlKey},bubbles:!0,composed:!0}))}onConnectorDragStart(e,t){e.stopPropagation(),e.preventDefault();let n=e.target;if(n.setPointerCapture(e.pointerId),!this.shadowRoot?.querySelector(`.task-group`))return;let r=this.option.bar?.height??28,i=this.option.bar?.margin??4,a=this.getX(this.task.start),o=this.getX(this.task.end)-a,s=this.lane*(r+i)+i,c=t===`start`?a:a+o,l=s+r/2;this.dispatchEvent(new CustomEvent(`connector-drag-start`,{detail:{taskId:this.task.id,endpoint:t,startX:c,startY:l,clientX:e.clientX,clientY:e.clientY},bubbles:!0,composed:!0})),this.setupDragEvents(n,e.pointerId,e=>{this.dispatchEvent(new CustomEvent(`connector-drag-move`,{detail:{taskId:this.task.id,endpoint:t,startX:c,startY:l,clientX:e.clientX,clientY:e.clientY},bubbles:!0,composed:!0}))},e=>{this.dispatchEvent(new CustomEvent(`connector-drag-end`,{detail:{taskId:this.task.id,endpoint:t,cancelled:e},bubbles:!0,composed:!0}))})}onContextMenu(e){if(e.ctrlKey){e.preventDefault(),e.stopPropagation();return}e.preventDefault(),e.stopPropagation(),this.dispatchEvent(new CustomEvent(`task-contextmenu`,{detail:{task:this.task,event:e},bubbles:!0,composed:!0}))}render(){if(!this.task||!this.option)return t.html``;let e=this.getX(this.task.start),n=this.getX(this.task.end)-e,r=this.option.bar?.height??28,i=this.option.bar?.margin??4,a=this.option.bar?.cornerRadius??4,o=this.lane*(r+i)+i,s=this.option.readOnly,c=this.task.movable??`both`,l=this.task.resizable,u=!s&&c!==`none`,d=!s;return d&&=l===void 0?!(c===`y`||c===`none`):l,t.html`
218
+ `}getX(e){return P(e,this.option.calendar.start,this.option.calendar.pxPerDay??50,this.option.calendar.pxPerMonth)}setupDragEvents(e,t,n,r){let i=()=>{e.releasePointerCapture(t),window.removeEventListener(`pointermove`,a),window.removeEventListener(`pointerup`,o),window.removeEventListener(`keydown`,s)},a=e=>{n(e)},o=e=>{i(),r(!1,e)},s=e=>{e.key===`Escape`&&(i(),r(!0))};window.addEventListener(`pointermove`,a),window.addEventListener(`pointerup`,o),window.addEventListener(`keydown`,s)}onResizeStart(e,t){e.stopPropagation();let n=e.target,r=this.task.movable??`both`,i=this.task.resizable,a=!this.option.readOnly;if(a&&=i===void 0?!(r===`y`||r===`none`):i,!a)return;let o=this.shadowRoot?.querySelector(`.bar`);if(!o)return;o.style.pointerEvents=`none`;let s=this.shadowRoot?.querySelector(`.task-group`);s?.classList.add(`dragging`),n.setPointerCapture(e.pointerId);let c=e.clientX,l=new Date(this.task.start),u=new Date(this.task.end),d=new Date(l),f=new Date(u);this.setupDragEvents(n,e.pointerId,e=>{let n=e.clientX-c,r=new Date(l),i=new Date(u),a=this.option.calendar.pxPerDay??50,o=this.option.calendar.pxPerMonth,p=Math.max(this.option.snapDuration??1440,1);if(o){let e=this.getX(l),s=this.getX(u);if(t===`left`){let t=F(e+n,this.option.calendar.start,a,o);t.getDate()>15&&t.setMonth(t.getMonth()+1),t.setDate(1),t.setHours(0,0,0,0),r=t,r>=i&&(r=new Date(i),r.setMonth(r.getMonth()-1))}else{let e=F(s+n,this.option.calendar.start,a,o);e.getDate()>15&&e.setMonth(e.getMonth()+1),e.setDate(1),e.setHours(0,0,0,0),i=e,i<=r&&(i=new Date(r),i.setMonth(i.getMonth()+1))}}else{let e=a/1440,o=e*p,s=Math.round(n/o)*o,c=Math.round(s/e);t===`left`?(r=new Date(l.getTime()+c*60*1e3),r>=i&&(r=new Date(i.getTime()-p*60*1e3))):(i=new Date(u.getTime()+c*60*1e3),i<=r&&(i=new Date(r.getTime()+p*60*1e3)))}if(d=r,f=i,s){let e=this.getX(r),t=this.getX(i)-e;s.style.left=`${e}px`,s.style.width=`${t}px`}this._dragAnimationFrame&&cancelAnimationFrame(this._dragAnimationFrame),this._dragAnimationFrame=requestAnimationFrame(()=>{this.dispatchEvent(new CustomEvent(`task-update`,{detail:{...this.task,start:r,end:i,dy:0,isDragging:!0,x:e.clientX,y:e.clientY},bubbles:!0,composed:!0}))})},e=>{if(s?.classList.remove(`dragging`),o.style.pointerEvents=``,this._dragAnimationFrame&&=(cancelAnimationFrame(this._dragAnimationFrame),null),e){if(s){let e=this.getX(l),t=this.getX(u)-e;s.style.left=`${e}px`,s.style.width=`${t}px`}this.requestUpdate(),this.dispatchEvent(new CustomEvent(`task-update`,{detail:{...this.task,start:l,end:u,dy:0,isDragging:!1},bubbles:!0,composed:!0}))}else requestAnimationFrame(()=>{this.dispatchEvent(new CustomEvent(`task-update`,{detail:{...this.task,start:d,end:f,dy:0,isDragging:!1},bubbles:!0,composed:!0}))})})}static{this.DRAG_THRESHOLD=3}onMoveStart(e){if(e.button===2)return;e.stopPropagation();let t=e.target,n=this.shadowRoot?.querySelector(`.task-group`);if(!t||!n)return;let r=this.task.movable??`both`;if(r===`none`)return;t.setPointerCapture(e.pointerId);let i=e.clientX,a=e.clientY,o=new Date(this.task.start),s=new Date(this.task.end),c=this.option.snapDuration??1440,l=!1;this.setupDragEvents(t,e.pointerId,e=>{let u=e.clientX-i,d=e.clientY-a;if(!l){if(Math.abs(u)<U.DRAG_THRESHOLD&&Math.abs(d)<U.DRAG_THRESHOLD)return;l=!0;let r=e.ctrlKey||e.altKey?`copy`:`grabbing`;this._currentDragCursor=r,t.style.cursor=r,n.classList.add(`dragging`)}let f=e.ctrlKey||e.altKey?`copy`:`grabbing`;this._currentDragCursor=f,t.style.cursor=f;let p=u,m=d;r===`y`&&(p=0),r===`x`&&(m=0),this.multiDragActive&&!this.multiDragSameRow&&(m=0);let h=p;if(this.option.calendar.pxPerMonth){let e=F(this.getX(o)+p,this.option.calendar.start,50,this.option.calendar.pxPerMonth),t=(e.getFullYear()-o.getFullYear())*12+(e.getMonth()-o.getMonth())+(e.getDate()>15?1:0),n=new Date(o);n.setMonth(n.getMonth()+t),h=this.getX(n)-this.getX(o)}else{let e=this.option.calendar.pxPerDay/1440*c;h=Math.round(p/e)*e}n.style.transform=`translate(${h}px, ${m}px)`,this._dragAnimationFrame&&cancelAnimationFrame(this._dragAnimationFrame),this._dragAnimationFrame=requestAnimationFrame(()=>{let t=e.ctrlKey||e.altKey;this.dispatchEvent(new CustomEvent(`task-update`,{detail:{...this.task,start:o,end:s,dx:h,dy:m,isDragging:!0,x:e.clientX,y:e.clientY,mode:t?`copy`:`move`},bubbles:!0,composed:!0}))})},(e,u)=>{if(this._currentDragCursor=null,n.classList.remove(`dragging`),n.style.transform=``,t.style.cursor=``,this._dragAnimationFrame&&=(cancelAnimationFrame(this._dragAnimationFrame),null),!l){u&&(this.dispatchEvent(new CustomEvent(`bar-click`,{detail:{task:this.task,event:u,isMultiSelect:u.metaKey||u.ctrlKey},bubbles:!0,composed:!0})),this._wasDragging=!0);return}if(e)this.requestUpdate(),this.dispatchEvent(new CustomEvent(`task-update`,{detail:{...this.task,start:o,end:s,dx:0,dy:0,isDragging:!1},bubbles:!0,composed:!0}));else if(u){let e=u.clientX-i,t=e;if(this.option.calendar.pxPerMonth){let n=F(this.getX(o)+e,this.option.calendar.start,50,this.option.calendar.pxPerMonth),r=(n.getFullYear()-o.getFullYear())*12+(n.getMonth()-o.getMonth())+(n.getDate()>15?1:0),i=new Date(o);i.setMonth(i.getMonth()+r),t=this.getX(i)-this.getX(o)}else{let n=this.option.calendar.pxPerDay/1440*c;t=Math.round(e/n)*n}let n=u.clientY-a;if(r===`y`&&(t=0),r===`x`&&(n=0),this.multiDragActive&&!this.multiDragSameRow&&(n=0),t===0&&Math.abs(n)<5){this.dispatchEvent(new CustomEvent(`bar-click`,{detail:{task:this.task,event:u,isMultiSelect:u.metaKey||u.ctrlKey},bubbles:!0,composed:!0})),this._wasDragging=!0;return}let l=u.ctrlKey||u.altKey;this._wasDragging=!0,this.multiDragActive||this.dispatchEvent(new CustomEvent(`bar-click`,{detail:{task:this.task,event:u,isMultiSelect:!1},bubbles:!0,composed:!0})),this.dispatchEvent(new CustomEvent(`task-update`,{detail:{...this.task,start:o,end:s,dx:t,dy:n,isDragging:!1,mode:l?`copy`:`move`},bubbles:!0,composed:!0}))}})}updated(e){super.updated(e);let t=this.shadowRoot?.querySelector(`.bar`);if(t&&(this.option.customRendering?.barContent,this.dispatchEvent(new CustomEvent(`render-bar-content`,{detail:{container:t,task:this.task},bubbles:!0,composed:!0})),this._currentDragCursor?t.style.cursor=this._currentDragCursor:this.option.readOnly||(t.style.cursor=``)),e.has(`multiDragDx`)||e.has(`multiDragDy`)){let e=this.shadowRoot?.querySelector(`.task-group`);e&&(this.multiDragDx!==0||this.multiDragDy!==0?(e.style.transform=`translate(${this.multiDragDx}px, ${this.multiDragDy}px)`,e.style.opacity=`0.6`,e.style.pointerEvents=`none`):(e.style.transform=``,e.style.opacity=``,e.style.pointerEvents=``))}}disconnectedCallback(){super.disconnectedCallback(),window.removeEventListener(`keydown`,this.handleKeyDown),window.removeEventListener(`keyup`,this.handleKeyUp)}updateCursor(e){let t=this.shadowRoot?.querySelector(`.bar`);t&&!this._currentDragCursor&&(t.style.cursor=e?`copy`:``)}onMouseEnter(e){let t=e.currentTarget;if(t.classList.contains(`dragging`))return;this.option.readOnly||(window.addEventListener(`keydown`,this.handleKeyDown),window.addEventListener(`keyup`,this.handleKeyUp),(e.ctrlKey||e.altKey)&&this.updateCursor(!0),t.addEventListener(`mousemove`,this.onMouseMoveOnBar));let n=t.getBoundingClientRect();this.dispatchEvent(new CustomEvent(`bar-mouseenter`,{detail:{task:this.task,x:n.left+n.width/2,y:n.top,barBottom:n.bottom},bubbles:!0,composed:!0}))}onMouseLeave(){let e=this.shadowRoot?.querySelector(`.task-group`);if(!this.option.readOnly){window.removeEventListener(`keydown`,this.handleKeyDown),window.removeEventListener(`keyup`,this.handleKeyUp),this.updateCursor(!1),e&&e.removeEventListener(`mousemove`,this.onMouseMoveOnBar);let t=this.shadowRoot?.querySelector(`.connector-left`),n=this.shadowRoot?.querySelector(`.connector-right`);t&&t.classList.remove(`show-connector`),n&&n.classList.remove(`show-connector`)}this.dispatchEvent(new CustomEvent(`bar-mouseleave`,{bubbles:!0,composed:!0}))}onDblClick(e){this.dispatchEvent(new CustomEvent(`task-dblclick`,{detail:{task:this.task,event:e},bubbles:!0,composed:!0}))}onClick(e){if(e.stopPropagation(),this._wasDragging){this._wasDragging=!1;return}this.dispatchEvent(new CustomEvent(`bar-click`,{detail:{task:this.task,event:e,isMultiSelect:e.metaKey||e.ctrlKey},bubbles:!0,composed:!0}))}onConnectorDragStart(e,t){e.stopPropagation(),e.preventDefault();let n=e.target;if(n.setPointerCapture(e.pointerId),!this.shadowRoot?.querySelector(`.task-group`))return;let r=this.option.bar?.height??28,i=this.option.bar?.margin??4,a=this.getX(this.task.start),o=this.getX(this.task.end)-a,s=this.lane*(r+i)+i,c=t===`start`?a:a+o,l=s+r/2;this.dispatchEvent(new CustomEvent(`connector-drag-start`,{detail:{taskId:this.task.id,endpoint:t,startX:c,startY:l,clientX:e.clientX,clientY:e.clientY},bubbles:!0,composed:!0})),this.setupDragEvents(n,e.pointerId,e=>{this.dispatchEvent(new CustomEvent(`connector-drag-move`,{detail:{taskId:this.task.id,endpoint:t,startX:c,startY:l,clientX:e.clientX,clientY:e.clientY},bubbles:!0,composed:!0}))},e=>{this.dispatchEvent(new CustomEvent(`connector-drag-end`,{detail:{taskId:this.task.id,endpoint:t,cancelled:e},bubbles:!0,composed:!0}))})}onContextMenu(e){if(e.ctrlKey){e.preventDefault(),e.stopPropagation();return}e.preventDefault(),e.stopPropagation(),this.dispatchEvent(new CustomEvent(`task-contextmenu`,{detail:{task:this.task,event:e},bubbles:!0,composed:!0}))}render(){if(!this.task||!this.option)return t.html``;let e=this.getX(this.task.start),n=this.getX(this.task.end)-e,r=this.option.bar?.height??28,i=this.option.bar?.margin??4,a=this.option.bar?.cornerRadius??4,o=this.lane*(r+i)+i,s=this.option.readOnly,c=this.task.movable??`both`,l=this.task.resizable,u=!s&&c!==`none`,d=!s;return d&&=l===void 0?!(c===`y`||c===`none`):l,t.html`
219
219
  <div
220
220
  class="task-group"
221
221
  style="
@@ -253,7 +253,7 @@
253
253
  ></div>
254
254
  `:``}
255
255
  </div>
256
- `}};H([(0,n.property)({type:Object})],U.prototype,`task`,void 0),H([(0,n.property)({type:Object})],U.prototype,`option`,void 0),H([(0,n.property)({type:Number})],U.prototype,`lane`,void 0),H([(0,n.property)({type:Boolean,reflect:!0})],U.prototype,`selected`,void 0),H([(0,n.property)({type:Boolean,reflect:!0})],U.prototype,`focused`,void 0),H([(0,n.property)({type:Number})],U.prototype,`multiDragDx`,void 0),H([(0,n.property)({type:Number})],U.prototype,`multiDragDy`,void 0),H([(0,n.property)({type:Boolean})],U.prototype,`multiDragActive`,void 0),H([(0,n.property)({type:Boolean})],U.prototype,`multiDragSameRow`,void 0),H([(0,n.property)({type:Boolean,reflect:!0,attribute:`connector-drop-target`})],U.prototype,`connectorDropTarget`,void 0),H([(0,n.property)({type:Boolean,reflect:!0})],U.prototype,`isExporting`,void 0),H([(0,n.property)({type:Boolean,reflect:!0,attribute:`critical-path`})],U.prototype,`isCriticalPath`,void 0),U=H([(0,n.customElement)(`gantt-bar`)],U);var W=class extends t.LitElement{constructor(...e){super(...e),this.theme=`light`,this.currentTime=new Date,this.isExporting=!1,this.hoveredMilestoneId=null,this._cachedDays=null,this._cachedMonths=null,this._cachedYears=null,this._cachedWeeks=null,this._cachedStartTime=0,this._cachedEndTime=0,this._cachedPxPerDay=0,this._cachedPxPerMonth=void 0,this._cachedWeekStartDay=-1}injectCustomContent(e,t,n){let r=e.querySelector(`.${n}`);if(r&&r.remove(),t instanceof HTMLElement)t.classList.add(n),e.appendChild(t);else if(typeof t==`string`){let r=document.createElement(`span`);r.classList.add(n),r.textContent=t,e.appendChild(r)}}updated(){let e=this.shadowRoot?.querySelector(`.label-placeholder`);if(!e)return;let t=e.querySelector(`.corner-content-root`);if(t&&t.remove(),this.cornerContent){let t=this.cornerContent();t instanceof HTMLElement&&(t.classList.add(`corner-content-root`),e.appendChild(t))}this.injectCalendarCustomContent()}injectCalendarCustomContent(){this.calendarMonthContent&&(this.shadowRoot?.querySelectorAll(`[data-calendar-month]`))?.forEach(e=>{let t=e,n={year:parseInt(t.dataset.calendarMonthYear??`0`,10),month:parseInt(t.dataset.calendarMonth??`0`,10),width:parseFloat(t.dataset.calendarMonthWidth??`0`),defaultLabel:t.dataset.calendarMonthLabel??``},r=this.calendarMonthContent(n);this.injectCustomContent(t,r,`custom-month-content`)}),this.calendarDayContent&&(this.shadowRoot?.querySelectorAll(`[data-calendar-day]`))?.forEach(e=>{let t=e,n=t.dataset.calendarDay??``,r={date:new Date(n),width:parseFloat(t.dataset.calendarDayWidth??`0`),isSaturday:t.dataset.calendarDaySaturday===`true`,isSunday:t.dataset.calendarDaySunday===`true`,isHoliday:t.dataset.calendarDayHoliday===`true`,defaultLabel:t.dataset.calendarDayLabel??``},i=this.calendarDayContent(r);this.injectCustomContent(t,i,`custom-day-content`)}),this.calendarWeekContent&&(this.shadowRoot?.querySelectorAll(`[data-calendar-week]`))?.forEach(e=>{let t=e,n=parseInt(t.dataset.calendarWeek??`0`,10),r=t.dataset.calendarWeekStart??``,i={weekNumber:n,startDate:new Date(r),width:parseFloat(t.dataset.calendarWeekWidth??`0`),defaultLabel:t.dataset.calendarWeekLabel??``},a=this.calendarWeekContent(i);this.injectCustomContent(t,a,`custom-week-content`)}),this.calendarHourContent&&(this.shadowRoot?.querySelectorAll(`[data-calendar-hour]`))?.forEach(e=>{let t=e,n=parseInt(t.dataset.calendarHour??`0`,10),r=parseFloat(t.dataset.calendarHourWidth??`0`),i=t.dataset.calendarHourDate??``,a={hour:n,width:r,date:new Date(i)},o=this.calendarHourContent(a);this.injectCustomContent(t,o,`custom-hour-content`)})}get totalDays(){return z(this.option.calendar.start,this.option.calendar.end)}static{this.styles=t.css`
256
+ `}};H([(0,n.property)({type:Object})],W.prototype,`task`,void 0),H([(0,n.property)({type:Object})],W.prototype,`option`,void 0),H([(0,n.property)({type:Number})],W.prototype,`lane`,void 0),H([(0,n.property)({type:Boolean,reflect:!0})],W.prototype,`selected`,void 0),H([(0,n.property)({type:Boolean,reflect:!0})],W.prototype,`focused`,void 0),H([(0,n.property)({type:Number})],W.prototype,`multiDragDx`,void 0),H([(0,n.property)({type:Number})],W.prototype,`multiDragDy`,void 0),H([(0,n.property)({type:Boolean})],W.prototype,`multiDragActive`,void 0),H([(0,n.property)({type:Boolean})],W.prototype,`multiDragSameRow`,void 0),H([(0,n.property)({type:Boolean,reflect:!0,attribute:`connector-drop-target`})],W.prototype,`connectorDropTarget`,void 0),H([(0,n.property)({type:Boolean,reflect:!0})],W.prototype,`isExporting`,void 0),H([(0,n.property)({type:Boolean,reflect:!0,attribute:`critical-path`})],W.prototype,`isCriticalPath`,void 0),W=U=H([(0,n.customElement)(`gantt-bar`)],W);var G=class extends t.LitElement{constructor(...e){super(...e),this.theme=`light`,this.currentTime=new Date,this.isExporting=!1,this.hoveredMilestoneId=null,this._cachedDays=null,this._cachedMonths=null,this._cachedYears=null,this._cachedWeeks=null,this._cachedStartTime=0,this._cachedEndTime=0,this._cachedPxPerDay=0,this._cachedPxPerMonth=void 0,this._cachedWeekStartDay=-1}injectCustomContent(e,t,n){let r=e.querySelector(`.${n}`);if(r&&r.remove(),t instanceof HTMLElement)t.classList.add(n),e.appendChild(t);else if(typeof t==`string`){let r=document.createElement(`span`);r.classList.add(n),r.textContent=t,e.appendChild(r)}}updated(){let e=this.shadowRoot?.querySelector(`.label-placeholder`);if(!e)return;let t=e.querySelector(`.corner-content-root`);if(t&&t.remove(),this.cornerContent){let t=this.cornerContent();t instanceof HTMLElement&&(t.classList.add(`corner-content-root`),e.appendChild(t))}this.injectCalendarCustomContent()}injectCalendarCustomContent(){this.calendarMonthContent&&(this.shadowRoot?.querySelectorAll(`[data-calendar-month]`))?.forEach(e=>{let t=e,n={year:parseInt(t.dataset.calendarMonthYear??`0`,10),month:parseInt(t.dataset.calendarMonth??`0`,10),width:parseFloat(t.dataset.calendarMonthWidth??`0`),defaultLabel:t.dataset.calendarMonthLabel??``},r=this.calendarMonthContent(n);this.injectCustomContent(t,r,`custom-month-content`)}),this.calendarDayContent&&(this.shadowRoot?.querySelectorAll(`[data-calendar-day]`))?.forEach(e=>{let t=e,n=t.dataset.calendarDay??``,r={date:new Date(n),width:parseFloat(t.dataset.calendarDayWidth??`0`),isSaturday:t.dataset.calendarDaySaturday===`true`,isSunday:t.dataset.calendarDaySunday===`true`,isHoliday:t.dataset.calendarDayHoliday===`true`,defaultLabel:t.dataset.calendarDayLabel??``},i=this.calendarDayContent(r);this.injectCustomContent(t,i,`custom-day-content`)}),this.calendarWeekContent&&(this.shadowRoot?.querySelectorAll(`[data-calendar-week]`))?.forEach(e=>{let t=e,n=parseInt(t.dataset.calendarWeek??`0`,10),r=t.dataset.calendarWeekStart??``,i={weekNumber:n,startDate:new Date(r),width:parseFloat(t.dataset.calendarWeekWidth??`0`),defaultLabel:t.dataset.calendarWeekLabel??``},a=this.calendarWeekContent(i);this.injectCustomContent(t,a,`custom-week-content`)}),this.calendarHourContent&&(this.shadowRoot?.querySelectorAll(`[data-calendar-hour]`))?.forEach(e=>{let t=e,n=parseInt(t.dataset.calendarHour??`0`,10),r=parseFloat(t.dataset.calendarHourWidth??`0`),i=t.dataset.calendarHourDate??``,a={hour:n,width:r,date:new Date(i)},o=this.calendarHourContent(a);this.injectCustomContent(t,o,`custom-hour-content`)})}get totalDays(){return z(this.option.calendar.start,this.option.calendar.end)}static{this.styles=t.css`
257
257
  :host {
258
258
  display: flex;
259
259
  width: fit-content;
@@ -538,7 +538,7 @@
538
538
  </div>
539
539
  `)}
540
540
  </div>
541
- `}};H([(0,n.property)({type:Object})],W.prototype,`option`,void 0),H([(0,n.property)({type:String})],W.prototype,`theme`,void 0),H([(0,n.property)({type:Object})],W.prototype,`currentTime`,void 0),H([(0,n.property)({type:Boolean})],W.prototype,`isExporting`,void 0),H([(0,n.property)({type:String})],W.prototype,`hoveredMilestoneId`,void 0),H([(0,n.property)({attribute:!1})],W.prototype,`cornerContent`,void 0),H([(0,n.property)({attribute:!1})],W.prototype,`calendarMonthContent`,void 0),H([(0,n.property)({attribute:!1})],W.prototype,`calendarDayContent`,void 0),H([(0,n.property)({attribute:!1})],W.prototype,`calendarWeekContent`,void 0),H([(0,n.property)({attribute:!1})],W.prototype,`calendarHourContent`,void 0),W=H([(0,n.customElement)(`gantt-calendar`)],W);var G=class extends t.LitElement{constructor(...e){super(...e),this.theme=`light`,this.rowId=``,this._cachedCells=null,this._cachedCellsStartTime=0,this._cachedCellsEndTime=0,this._cachedCellsPxPerDay=0,this._cachedCellsPxPerMonth=void 0,this._cachedCellsTheme=``}get totalDays(){return z(this.option.calendar.start,this.option.calendar.end)}static{this.styles=t.css`
541
+ `}};H([(0,n.property)({type:Object})],G.prototype,`option`,void 0),H([(0,n.property)({type:String})],G.prototype,`theme`,void 0),H([(0,n.property)({type:Object})],G.prototype,`currentTime`,void 0),H([(0,n.property)({type:Boolean})],G.prototype,`isExporting`,void 0),H([(0,n.property)({type:String})],G.prototype,`hoveredMilestoneId`,void 0),H([(0,n.property)({attribute:!1})],G.prototype,`cornerContent`,void 0),H([(0,n.property)({attribute:!1})],G.prototype,`calendarMonthContent`,void 0),H([(0,n.property)({attribute:!1})],G.prototype,`calendarDayContent`,void 0),H([(0,n.property)({attribute:!1})],G.prototype,`calendarWeekContent`,void 0),H([(0,n.property)({attribute:!1})],G.prototype,`calendarHourContent`,void 0),G=H([(0,n.customElement)(`gantt-calendar`)],G);var K=class extends t.LitElement{constructor(...e){super(...e),this.theme=`light`,this.rowId=``,this._cachedCells=null,this._cachedCellsStartTime=0,this._cachedCellsEndTime=0,this._cachedCellsPxPerDay=0,this._cachedCellsPxPerMonth=void 0,this._cachedCellsTheme=``}get totalDays(){return z(this.option.calendar.start,this.option.calendar.end)}static{this.styles=t.css`
542
542
  :host {
543
543
  position: absolute;
544
544
  top: 0;
@@ -567,7 +567,7 @@
567
567
  ${this._cachedCells.map(({width:e,color:n})=>t.html`<div
568
568
  style="width: ${e}px; background-color: ${n}; flex-shrink: 0;"
569
569
  ></div>`)}
570
- `}};H([(0,n.property)({type:Object})],G.prototype,`option`,void 0),H([(0,n.property)({type:String})],G.prototype,`theme`,void 0),H([(0,n.property)({type:String})],G.prototype,`rowId`,void 0),G=H([(0,n.customElement)(`gantt-row-background`)],G);var K=class extends t.LitElement{constructor(...e){super(...e),this.isDragTarget=!1,this.draggingTask=null,this.draggingTaskIds=[],this.multiDragDx=0,this.multiDragDy=0,this.multiDragSameRow=!1,this.externalDragTask=null,this.theme=`light`,this.isSelected=!1,this.dropPosition=null,this.selectedTaskIds=[],this.focusedTaskId=null,this.isExporting=!1,this.criticalPathTaskIds=[],this._cachedMonthGridLines=null,this._cachedMonthGridStartTime=0,this._cachedMonthGridEndTime=0,this._cachedMonthGridPxPerDay=0,this._cachedMonthGridPxPerMonth=0,this._rowHeaderTooltipEl=null}getDateX(e){return P(e,this.option.calendar.start,this.option.calendar.pxPerDay,this.option.calendar.pxPerMonth)}getMarkerPath(e,t){let n=t/2;switch(e){case`triangle-up`:return`M 0 ${t} L ${n} 0 L ${t} ${t} Z`;case`triangle-down`:return`M 0 0 L ${t} 0 L ${n} ${t} Z`;case`triangle-left`:return`M ${t} 0 L 0 ${n} L ${t} ${t} Z`;case`triangle-right`:return`M 0 0 L ${t} ${n} L 0 ${t} Z`;case`diamond`:return`M ${n} 0 L ${t} ${n} L ${n} ${t} L 0 ${n} Z`;case`square`:return`M 0 0 L ${t} 0 L ${t} ${t} L 0 ${t} Z`;default:return`M 0 ${t} L ${n} 0 L ${t} ${t} Z`}}resolveMarkerFontSize(e){switch(e){case`xs`:return 8;case`sm`:return 10;case`md`:return 12;case`lg`:return 14;case`xl`:return 18;default:return 10}}estimateMarkerWidth(e,t){let n=this.resolveMarkerFontSize(e.fontSize)*.7,r=e.name?e.name.length*n+4:0;return e.anchor===`center`?t:t+r}getMarkerXRange(e,t){let n=this.getDateX(e.date),r=this.estimateMarkerWidth(e,t),i=e.anchor===`center`,a;return a=e.anchor===`start`?n:e.anchor===`end`?n-r:n-t/2,i?{left:a,right:a+t}:{left:a,right:a+r}}calculateMarkerLanes(e,t){if(!e.length)return[];let n=e.map(e=>({marker:e,range:this.getMarkerXRange(e,t)})).sort((e,t)=>e.range.left-t.range.left),r=[],i=[];for(let e of n){let t=-1;for(let n=0;n<r.length;n++)if(e.range.left>=r[n]+2){r[n]=e.range.right,t=n;break}t===-1&&(r.push(e.range.right),t=r.length-1),i.push({marker:e.marker,lane:t})}return i}static{this.styles=t.css`
570
+ `}};H([(0,n.property)({type:Object})],K.prototype,`option`,void 0),H([(0,n.property)({type:String})],K.prototype,`theme`,void 0),H([(0,n.property)({type:String})],K.prototype,`rowId`,void 0),K=H([(0,n.customElement)(`gantt-row-background`)],K);var q=class extends t.LitElement{constructor(...e){super(...e),this.isDragTarget=!1,this.draggingTask=null,this.draggingTaskIds=[],this.multiDragDx=0,this.multiDragDy=0,this.multiDragSameRow=!1,this.externalDragTask=null,this.theme=`light`,this.isSelected=!1,this.dropPosition=null,this.selectedTaskIds=[],this.focusedTaskId=null,this.isExporting=!1,this.criticalPathTaskIds=[],this._cachedMonthGridLines=null,this._cachedMonthGridStartTime=0,this._cachedMonthGridEndTime=0,this._cachedMonthGridPxPerDay=0,this._cachedMonthGridPxPerMonth=0,this._rowHeaderTooltipEl=null}getDateX(e){return P(e,this.option.calendar.start,this.option.calendar.pxPerDay,this.option.calendar.pxPerMonth)}getMarkerPath(e,t){let n=t/2;switch(e){case`triangle-up`:return`M 0 ${t} L ${n} 0 L ${t} ${t} Z`;case`triangle-down`:return`M 0 0 L ${t} 0 L ${n} ${t} Z`;case`triangle-left`:return`M ${t} 0 L 0 ${n} L ${t} ${t} Z`;case`triangle-right`:return`M 0 0 L ${t} ${n} L 0 ${t} Z`;case`diamond`:return`M ${n} 0 L ${t} ${n} L ${n} ${t} L 0 ${n} Z`;case`square`:return`M 0 0 L ${t} 0 L ${t} ${t} L 0 ${t} Z`;default:return`M 0 ${t} L ${n} 0 L ${t} ${t} Z`}}resolveMarkerFontSize(e){switch(e){case`xs`:return 8;case`sm`:return 10;case`md`:return 12;case`lg`:return 14;case`xl`:return 18;default:return 10}}estimateMarkerWidth(e,t){let n=this.resolveMarkerFontSize(e.fontSize)*.7,r=e.name?e.name.length*n+4:0;return e.anchor===`center`?t:t+r}getMarkerXRange(e,t){let n=this.getDateX(e.date),r=this.estimateMarkerWidth(e,t),i=e.anchor===`center`,a;return a=e.anchor===`start`?n:e.anchor===`end`?n-r:n-t/2,i?{left:a,right:a+t}:{left:a,right:a+r}}calculateMarkerLanes(e,t){if(!e.length)return[];let n=e.map(e=>({marker:e,range:this.getMarkerXRange(e,t)})).sort((e,t)=>e.range.left-t.range.left),r=[],i=[];for(let e of n){let t=-1;for(let n=0;n<r.length;n++)if(e.range.left>=r[n]+2){r[n]=e.range.right,t=n;break}t===-1&&(r.push(e.range.right),t=r.length-1),i.push({marker:e.marker,lane:t})}return i}static{this.styles=t.css`
571
571
  :host {
572
572
  display: block;
573
573
  width: fit-content;
@@ -794,7 +794,7 @@
794
794
  `})}
795
795
  </div>
796
796
  </div>
797
- `}};H([(0,n.property)({type:Object})],K.prototype,`row`,void 0),H([(0,n.property)({type:Object})],K.prototype,`option`,void 0),H([(0,n.property)({type:Boolean})],K.prototype,`isDragTarget`,void 0),H([(0,n.property)({type:Object})],K.prototype,`draggingTask`,void 0),H([(0,n.property)({type:Array})],K.prototype,`draggingTaskIds`,void 0),H([(0,n.property)({type:Number})],K.prototype,`multiDragDx`,void 0),H([(0,n.property)({type:Number})],K.prototype,`multiDragDy`,void 0),H([(0,n.property)({type:Boolean})],K.prototype,`multiDragSameRow`,void 0),H([(0,n.property)({type:Object})],K.prototype,`externalDragTask`,void 0),H([(0,n.property)({type:String})],K.prototype,`theme`,void 0),H([(0,n.property)({type:Boolean,reflect:!0})],K.prototype,`isSelected`,void 0),H([(0,n.property)({type:String})],K.prototype,`dropPosition`,void 0),H([(0,n.property)({type:Array})],K.prototype,`selectedTaskIds`,void 0),H([(0,n.property)({type:String})],K.prototype,`focusedTaskId`,void 0),H([(0,n.property)({type:Boolean,reflect:!0})],K.prototype,`isExporting`,void 0),H([(0,n.property)({type:Array})],K.prototype,`criticalPathTaskIds`,void 0),K=H([(0,n.customElement)(`gantt-row`)],K);function q(e,t,n,r,i,a,o,s){let c=n=>{if(Math.abs(t-r)<1)return`M ${e} ${t} L ${n} ${r}`;if(e<n){let i=(e+n)/2,a=r>t?1:-1,o=Math.min(s,i-e,n-i,Math.abs(r-t)/2);return[`M ${e} ${t}`,`L ${i-o} ${t}`,`Q ${i} ${t} ${i} ${t+a*o}`,`L ${i} ${r-a*o}`,`Q ${i} ${r} ${i+o} ${r}`,`L ${n} ${r}`].join(` `)}else{let i=Math.max(12,s+4),c=e+i,l=n-i,u=(t+r)/2,d=Math.abs(t-r)<a?u+a+o:u,f=d-t,p=r-d,m=f>=0?1:-1,h=p>=0?1:-1,g=l-c,_=g>=0?1:-1,v=Math.min(s,i,Math.abs(f)/2),y=Math.min(s,Math.abs(f)/2,Math.abs(g)/2),b=Math.min(s,Math.abs(g)/2,Math.abs(p)/2),x=Math.min(s,Math.abs(p)/2,i);return[`M ${e} ${t}`,`L ${c-v} ${t}`,`Q ${c} ${t} ${c} ${t+m*v}`,`L ${c} ${d-m*y}`,`Q ${c} ${d} ${c+_*y} ${d}`,`L ${l-_*b} ${d}`,`Q ${l} ${d} ${l} ${d+h*b}`,`L ${l} ${r-h*x}`,`Q ${l} ${r} ${l+x} ${r}`,`L ${n} ${r}`].join(` `)}};return{pathD:c(i),hitPathD:c(n)}}var J=t.css`
797
+ `}};H([(0,n.property)({type:Object})],q.prototype,`row`,void 0),H([(0,n.property)({type:Object})],q.prototype,`option`,void 0),H([(0,n.property)({type:Boolean})],q.prototype,`isDragTarget`,void 0),H([(0,n.property)({type:Object})],q.prototype,`draggingTask`,void 0),H([(0,n.property)({type:Array})],q.prototype,`draggingTaskIds`,void 0),H([(0,n.property)({type:Number})],q.prototype,`multiDragDx`,void 0),H([(0,n.property)({type:Number})],q.prototype,`multiDragDy`,void 0),H([(0,n.property)({type:Boolean})],q.prototype,`multiDragSameRow`,void 0),H([(0,n.property)({type:Object})],q.prototype,`externalDragTask`,void 0),H([(0,n.property)({type:String})],q.prototype,`theme`,void 0),H([(0,n.property)({type:Boolean,reflect:!0})],q.prototype,`isSelected`,void 0),H([(0,n.property)({type:String})],q.prototype,`dropPosition`,void 0),H([(0,n.property)({type:Array})],q.prototype,`selectedTaskIds`,void 0),H([(0,n.property)({type:String})],q.prototype,`focusedTaskId`,void 0),H([(0,n.property)({type:Boolean,reflect:!0})],q.prototype,`isExporting`,void 0),H([(0,n.property)({type:Array})],q.prototype,`criticalPathTaskIds`,void 0),q=H([(0,n.customElement)(`gantt-row`)],q);function J(e,t,n,r,i,a,o,s){let c=n=>{if(Math.abs(t-r)<1)return`M ${e} ${t} L ${n} ${r}`;if(e<n){let i=(e+n)/2,a=r>t?1:-1,o=Math.min(s,i-e,n-i,Math.abs(r-t)/2);return[`M ${e} ${t}`,`L ${i-o} ${t}`,`Q ${i} ${t} ${i} ${t+a*o}`,`L ${i} ${r-a*o}`,`Q ${i} ${r} ${i+o} ${r}`,`L ${n} ${r}`].join(` `)}else{let i=Math.max(12,s+4),c=e+i,l=n-i,u=(t+r)/2,d=Math.abs(t-r)<a?u+a+o:u,f=d-t,p=r-d,m=f>=0?1:-1,h=p>=0?1:-1,g=l-c,_=g>=0?1:-1,v=Math.min(s,i,Math.abs(f)/2),y=Math.min(s,Math.abs(f)/2,Math.abs(g)/2),b=Math.min(s,Math.abs(g)/2,Math.abs(p)/2),x=Math.min(s,Math.abs(p)/2,i);return[`M ${e} ${t}`,`L ${c-v} ${t}`,`Q ${c} ${t} ${c} ${t+m*v}`,`L ${c} ${d-m*y}`,`Q ${c} ${d} ${c+_*y} ${d}`,`L ${l-_*b} ${d}`,`Q ${l} ${d} ${l} ${d+h*b}`,`L ${l} ${r-h*x}`,`Q ${l} ${r} ${l+x} ${r}`,`L ${n} ${r}`].join(` `)}};return{pathD:c(i),hitPathD:c(n)}}var Y=t.css`
798
798
  :host {
799
799
  display: block;
800
800
  width: 100%;
@@ -829,7 +829,7 @@
829
829
  font-size: 11px;
830
830
  white-space: nowrap;
831
831
  pointer-events: none;
832
- z-index: 1000;
832
+ z-index: 2000;
833
833
  margin-top: -6px;
834
834
  text-align: left;
835
835
  line-height: 1.4;
@@ -851,6 +851,14 @@
851
851
  border-width: 4px;
852
852
  border-style: solid;
853
853
  }
854
+ .tooltip.below {
855
+ transform: translate(-50%, 0);
856
+ margin-top: 6px;
857
+ }
858
+ .tooltip.below::after {
859
+ top: auto;
860
+ bottom: 100%;
861
+ }
854
862
  .drag-info-overlay {
855
863
  position: fixed;
856
864
  top: 0;
@@ -936,7 +944,7 @@
936
944
  pointer-events: none;
937
945
  z-index: 58;
938
946
  }
939
- `;function Y(e,t){let n=L(e,t);return`
947
+ `;function X(e,t){let n=L(e,t);return`
940
948
  :host {
941
949
  background: ${n.bg};
942
950
  border: 1px solid ${n.border};
@@ -951,6 +959,9 @@
951
959
  .tooltip::after {
952
960
  border-color: ${n.tooltipBg} transparent transparent transparent;
953
961
  }
962
+ .tooltip.below::after {
963
+ border-color: transparent transparent ${n.tooltipBg} transparent;
964
+ }
954
965
  .drag-info-overlay {
955
966
  background: ${n.dragOverlayBg};
956
967
  color: ${n.dragOverlayText};
@@ -982,7 +993,7 @@
982
993
  .header-resizer.resizing {
983
994
  background-color: ${n.border};
984
995
  }
985
- `}function X(e,t){let n=document.createElement(`a`);n.href=e,n.download=t,n.click()}async function Z(e,t=`png`,n={}){let{filename:r=`gantt-chart`,download:i=!1,scale:a=2,splitHeight:c}=n,l=e.shadowRoot?.querySelector(`.scroll-container`),u=l?l.scrollWidth:e.scrollWidth,d=l?l.scrollHeight:e.scrollHeight,f=await(0,o.default)(e,{backgroundColor:`#ffffff`,scale:a,width:u,height:d,windowWidth:u,windowHeight:d});if(c&&d>c){let t=50,n=e.shadowRoot?.querySelector(`gantt-calendar`);n&&n.offsetHeight>0?t=n.offsetHeight:e.calendarHeight&&(t=e.calendarHeight);let r=f.height/d,i=d-t,a=c-t,o=[];typeof e.getRowPositions==`function`&&(o=e.getRowPositions().map(e=>e.bottom));let s=[0],l=0;if(a>0)for(;l<i;){let e=l+a;if(e>=i){s.push(i);break}let t=-1;for(let n=0;n<o.length;n++){let r=o[n];r>l&&r<=e&&(t=Math.max(t,r))}if(t===-1)for(let e=0;e<o.length;e++){let n=o[e];if(n>l){t=n;break}}(t===-1||t===l)&&(t=e),s.push(t),l=t}else s.push(i);let u=s.length-1;if(u>0){let e=Math.floor(t*r),n=f.width,i=0,a=[];for(let n=0;n<u;n++){let o=s[n],c=s[n+1],l=Math.round((t+o)*r),u=Math.round((t+c)*r),d=u-l;a.push({srcStart:l,srcEnd:u,destHeight:d}),i+=e+d}let o=document.createElement(`canvas`);o.width=n,o.height=i;let c=o.getContext(`2d`);if(c){let t=0;for(let r=0;r<u;r++){c.drawImage(f,0,0,n,e,0,t,n,e),t+=e;let i=a[r];c.drawImage(f,0,i.srcStart,n,i.destHeight,0,t,n,i.destHeight),t+=i.destHeight}f=o,d=i/r}else console.warn(`[export] Failed to get 2D context for new canvas. It might be too large.`)}}if(t===`pdf`){let e=f.toDataURL(`image/jpeg`,.9),t=new s.jsPDF({orientation:u>d?`l`:`p`,unit:`px`,format:[u,d],compress:!0});return t.addImage(e,`JPEG`,0,0,u,d,void 0,`FAST`),i&&t.save(`${r}.pdf`),t.output(`blob`)}else{let e=f.toDataURL(`image/png`);return i&&X(e,`${r}.png`),e}}function Q(e){let t=new Map,n=new Map,r=new Map;for(let n of e)for(let e of n.tasks){let n=e.dependencies??[],i=e.start instanceof Date?e.start.getTime():new Date(e.start).getTime(),a=e.end instanceof Date?e.end.getTime():new Date(e.end).getTime();isNaN(i)||isNaN(a)||(t.set(e.id,{start:i,end:a,duration:a-i,dependencies:n}),r.set(e.id,0))}let i=new Set;for(let[e,a]of t){let o=0;for(let r of a.dependencies)if(t.has(r)){o++;let t=n.get(r)??[];t.push(e),n.set(r,t),i.add(e),i.add(r)}r.set(e,o)}if(i.size<2)return new Set;let a=[];for(let e of i)(r.get(e)??0)===0&&a.push(e);let o=[];for(;a.length>0;){let e=a.shift();o.push(e);for(let t of n.get(e)??[]){if(!i.has(t))continue;let e=(r.get(t)??0)-1;r.set(t,e),e===0&&a.push(t)}}if(o.length<i.size){let e=new Set(o);for(let t of i)e.has(t)||i.delete(t);if(i.size<2)return new Set}let s=new Map,c=new Map;for(let e of o){let n=t.get(e);if(!n)continue;let r=n.dependencies.filter(e=>s.has(e));if(r.length===0)s.set(e,n.end),c.set(e,null);else{let t=-1/0,i=null;for(let e of r){let r=s.get(e)+n.duration;r>t&&(t=r,i=e)}n.end>t&&(t=n.end),s.set(e,t),c.set(e,i)}}let l=[];for(let e of o)(n.get(e)??[]).filter(e=>i.has(e)).length===0&&l.push(e);if(l.length===0)return new Set;let u=l[0],d=s.get(l[0])??0;for(let e=1;e<l.length;e++){let t=s.get(l[e])??0;t>d&&(d=t,u=l[e])}let f=new Set,p=u;for(;p!==null;)f.add(p),p=c.get(p)??null;return f.size<=1?new Set:f}var $=class extends t.LitElement{constructor(...e){super(...e),this.rows=[],this.theme=`light`,this.selectedRowIds=[],this.selectedTaskIds=[],this.externalDraggingTask=null,this.selectedRows=new Set,this.selectedTasks=new Set,this.lastClickedRowId=null,this.virtualScrollTop=0,this.dragTargetRowIndex=null,this.draggingTask=null,this.draggingTaskIds=[],this.multiDragDx=0,this.multiDragDy=0,this.multiDragSameRow=!1,this.viewportHeight=400,this.dragOverlayInfo=null,this.calendarHeight=0,this.tooltip=null,this.dragOverRowId=null,this.dragOverPosition=null,this.currentTime=new Date,this.dragPreview=null,this.currentRowHeaderWidth=150,this.isResizingHeader=!1,this.hoveredMilestoneId=null,this.cursorLineX=null,this.connectorDrag=null,this._systemThemeMediaQuery=null,this.isExporting=!1,this.focusedTaskId=null,this.focusedRowId=null,this.zoomPxPerDay=null,this.zoomPxPerMonth=null,this._layoutCache=null,this.resizeObserver=null,this._cachedSelectedTaskIds=[],this._cachedSelectedTasksSize=-1,this._cachedCurrentOption=null,this._lastOptionRef=null,this._lastLabelWidth=-1,this._lastZoomPxPerDay=null,this._lastZoomPxPerMonth=null,this._scrollContainer=null,this.handleSystemThemeChange=e=>{(this.option?.theme===`system`||this.option?.theme!==`light`&&this.option?.theme!==`dark`)&&(this.theme=e.matches?`dark`:`light`)},this.handleScroll=e=>{let t=e.target;this.updateScrollTop(t.scrollTop),this.hoverTimer!==void 0&&window.clearTimeout(this.hoverTimer),this.tooltip&&={...this.tooltip,visible:!1}},this.updateScrollTop=(0,a.throttle)(e=>{this.virtualScrollTop=e},100),this.handleContainerMouseMove=e=>{if(!this.option.calendar.showCursorLine)return;let t=this.shadowRoot?.querySelector(`.scroll-container`);if(!t)return;let n=t.getBoundingClientRect(),r=e.clientX-n.left+t.scrollLeft;if(r<this.currentRowHeaderWidth){this.cursorLineX=null;return}this.cursorLineX=r},this.handleContainerMouseLeave=()=>{this.cursorLineX=null},this.handleWheel=e=>{if(!e.ctrlKey&&!e.metaKey||this.option.zoom?.enabled!==!0)return;e.preventDefault();let t=this._scrollContainer;if(!t)return;let n=t.getBoundingClientRect(),r=this.currentRowHeaderWidth,i=e.clientX-n.left+t.scrollLeft-r,a=this.effectivePxPerMonth!==void 0,o=a?this.effectivePxPerMonth:this.effectivePxPerDay,s=this.option.zoom?.step??1.2,c=a?20:2,l=a?600:200,u=this.option.zoom?.min??c,d=this.option.zoom?.max??l,f=e.deltaY>0?1/s:s,p=Math.max(u,Math.min(d,o*f));if(p===o)return;a?this.zoomPxPerMonth=p:this.zoomPxPerDay=p;let m=p/o;this.updateComplete.then(()=>{let e=i*m-i;t.scrollLeft+=e}),this.dispatchEvent(new CustomEvent(`zoom-change`,{detail:{pxPerDay:a?this.effectivePxPerDay:p,pxPerMonth:a?p:void 0},bubbles:!0,composed:!0}))},this.handleKeyDown=e=>{if(this.option.keyboard?.enabled===!1)return;let t=e.composedPath()[0];if(!(t!==this&&t?.tagName&&[`INPUT`,`TEXTAREA`,`SELECT`].includes(t.tagName)))switch(e.key){case`ArrowRight`:e.shiftKey&&!this.option.readOnly?this.moveSelectedTasksByKeyboard(1):this.moveFocusHorizontal(1),e.preventDefault();break;case`ArrowLeft`:e.shiftKey&&!this.option.readOnly?this.moveSelectedTasksByKeyboard(-1):this.moveFocusHorizontal(-1),e.preventDefault();break;case`ArrowDown`:this.moveFocusVertical(1),e.preventDefault();break;case`ArrowUp`:this.moveFocusVertical(-1),e.preventDefault();break;case`Enter`:case` `:this.focusedTaskId&&(e.ctrlKey||e.metaKey?this.toggleTaskSelection(this.focusedTaskId):this.selectSingleTask(this.focusedTaskId)),e.preventDefault();break;case`Escape`:this.clearSelection(),this.focusedTaskId=null,this.focusedRowId=null;break;case`Delete`:case`Backspace`:!this.option.readOnly&&this.selectedTasks.size>0&&this.dispatchEvent(new CustomEvent(`task-delete`,{detail:{taskIds:[...this.selectedTasks],event:e},bubbles:!0,composed:!0})),e.preventDefault();break;case`Home`:this.focusFirstOrLastTaskInRow(`first`),e.preventDefault();break;case`End`:this.focusFirstOrLastTaskInRow(`last`),e.preventDefault();break}}}get displayRows(){return this.option.showHiddenRows?this.rows:this.rows.filter(e=>e.visible!==!1)}get effectivePxPerDay(){return this.zoomPxPerDay??this.option.calendar.pxPerDay??50}get effectivePxPerMonth(){return this.zoomPxPerMonth??this.option.calendar.pxPerMonth}static{this.styles=J}firstUpdated(){this.setupCurrentTimeTimer();let e=this.shadowRoot?.getElementById(`calendar`);this.resizeObserver=new ResizeObserver(t=>{for(let n of t)n.target===this?this.viewportHeight=n.contentRect.height:n.target===e&&(this.calendarHeight=n.target.offsetHeight)}),this.resizeObserver.observe(this),e&&this.resizeObserver.observe(e),this._scrollContainer=this.shadowRoot?.querySelector(`.scroll-container`),this._scrollContainer?.addEventListener(`wheel`,this.handleWheel,{passive:!1})}connectedCallback(){super.connectedCallback(),this._systemThemeMediaQuery=window.matchMedia?window.matchMedia(`(prefers-color-scheme: dark)`):null,this._systemThemeMediaQuery?.addEventListener(`change`,this.handleSystemThemeChange),this.hasAttribute(`tabindex`)||this.setAttribute(`tabindex`,`0`),this.setAttribute(`role`,`grid`),this.setAttribute(`aria-label`,`Gantt Chart`),this.addEventListener(`keydown`,this.handleKeyDown),this.option?.theme===`system`||this.option?.theme!==`light`&&this.option?.theme!==`dark`?this.theme=this._systemThemeMediaQuery?.matches?`dark`:`light`:this.theme=this.option.theme}disconnectedCallback(){super.disconnectedCallback(),this.resizeObserver?.disconnect(),this.stopCurrentTimeTimer(),this._systemThemeMediaQuery?.removeEventListener(`change`,this.handleSystemThemeChange),this.removeEventListener(`keydown`,this.handleKeyDown),this._scrollContainer?.removeEventListener(`wheel`,this.handleWheel),this._scrollContainer=null}willUpdate(e){if(e.has(`option`)&&(this.option?.theme===`light`||this.option?.theme===`dark`?this.theme=this.option.theme:this._systemThemeMediaQuery&&(this.theme=this._systemThemeMediaQuery.matches?`dark`:`light`)),e.has(`option`)&&(this.setupCurrentTimeTimer(),this.isResizingHeader||(this.currentRowHeaderWidth=this.option.rowHeader?.width??150),this.zoomPxPerDay=null,this.zoomPxPerMonth=null),(e.has(`rows`)||e.has(`option`)||e.has(`currentRowHeaderWidth`)||e.has(`zoomPxPerDay`)||e.has(`zoomPxPerMonth`))&&(this._layoutCache=null),e.has(`selectedRowIds`)){let e=new Set(this.selectedRowIds);(e.size!==this.selectedRows.size||![...e].every(e=>this.selectedRows.has(e)))&&(this.selectedRows=e)}if(e.has(`selectedTaskIds`)){let e=new Set(this.selectedTaskIds);(e.size!==this.selectedTasks.size||![...e].every(e=>this.selectedTasks.has(e)))&&(this.selectedTasks=e)}(e.has(`selectedTasks`)||this._cachedSelectedTasksSize!==this.selectedTasks.size)&&(this._cachedSelectedTaskIds=[...this.selectedTasks],this._cachedSelectedTasksSize=this.selectedTasks.size)}updated(e){if(super.updated(e),this.tooltip){let e=this.shadowRoot?.querySelector(`.tooltip`);if(e){let n=this.option.customRendering?.tooltip?this.option.customRendering.tooltip(this.tooltip.task):void 0;if(n)typeof n==`string`?e.textContent=n:(0,t.render)(n,e);else{let n=this.option.locale??j,r=!!this.option.calendar.pxPerMonth,i=Math.round((this.tooltip.task.end.getTime()-this.tooltip.task.start.getTime())/(1e3*60*60*24));if(r){let r=new Date(this.tooltip.task.end);r.setMonth(r.getMonth()-1),(0,t.render)(t.html`
996
+ `}function Z(e,t){let n=document.createElement(`a`);n.href=e,n.download=t,n.click()}async function ee(e,t=`png`,n={}){let{filename:r=`gantt-chart`,download:i=!1,scale:a=2,splitHeight:c}=n,l=e.shadowRoot?.querySelector(`.scroll-container`),u=l?l.scrollWidth:e.scrollWidth,d=l?l.scrollHeight:e.scrollHeight,f=await(0,o.default)(e,{backgroundColor:`#ffffff`,scale:a,width:u,height:d,windowWidth:u,windowHeight:d});if(c&&d>c){let t=50,n=e.shadowRoot?.querySelector(`gantt-calendar`);n&&n.offsetHeight>0?t=n.offsetHeight:e.calendarHeight&&(t=e.calendarHeight);let r=f.height/d,i=d-t,a=c-t,o=[];typeof e.getRowPositions==`function`&&(o=e.getRowPositions().map(e=>e.bottom));let s=[0],l=0;if(a>0)for(;l<i;){let e=l+a;if(e>=i){s.push(i);break}let t=-1;for(let n=0;n<o.length;n++){let r=o[n];r>l&&r<=e&&(t=Math.max(t,r))}if(t===-1)for(let e=0;e<o.length;e++){let n=o[e];if(n>l){t=n;break}}(t===-1||t===l)&&(t=e),s.push(t),l=t}else s.push(i);let u=s.length-1;if(u>0){let e=Math.floor(t*r),n=f.width,i=0,a=[];for(let n=0;n<u;n++){let o=s[n],c=s[n+1],l=Math.round((t+o)*r),u=Math.round((t+c)*r),d=u-l;a.push({srcStart:l,srcEnd:u,destHeight:d}),i+=e+d}let o=document.createElement(`canvas`);o.width=n,o.height=i;let c=o.getContext(`2d`);if(c){let t=0;for(let r=0;r<u;r++){c.drawImage(f,0,0,n,e,0,t,n,e),t+=e;let i=a[r];c.drawImage(f,0,i.srcStart,n,i.destHeight,0,t,n,i.destHeight),t+=i.destHeight}f=o,d=i/r}else console.warn(`[export] Failed to get 2D context for new canvas. It might be too large.`)}}if(t===`pdf`){let e=f.toDataURL(`image/jpeg`,.9),t=new s.jsPDF({orientation:u>d?`l`:`p`,unit:`px`,format:[u,d],compress:!0});return t.addImage(e,`JPEG`,0,0,u,d,void 0,`FAST`),i&&t.save(`${r}.pdf`),t.output(`blob`)}else{let e=f.toDataURL(`image/png`);return i&&Z(e,`${r}.png`),e}}function Q(e){let t=new Map,n=new Map,r=new Map;for(let n of e)for(let e of n.tasks){let n=e.dependencies??[],i=e.start instanceof Date?e.start.getTime():new Date(e.start).getTime(),a=e.end instanceof Date?e.end.getTime():new Date(e.end).getTime();isNaN(i)||isNaN(a)||(t.set(e.id,{start:i,end:a,duration:a-i,dependencies:n}),r.set(e.id,0))}let i=new Set;for(let[e,a]of t){let o=0;for(let r of a.dependencies)if(t.has(r)){o++;let t=n.get(r)??[];t.push(e),n.set(r,t),i.add(e),i.add(r)}r.set(e,o)}if(i.size<2)return new Set;let a=[];for(let e of i)(r.get(e)??0)===0&&a.push(e);let o=[];for(;a.length>0;){let e=a.shift();o.push(e);for(let t of n.get(e)??[]){if(!i.has(t))continue;let e=(r.get(t)??0)-1;r.set(t,e),e===0&&a.push(t)}}if(o.length<i.size){let e=new Set(o);for(let t of i)e.has(t)||i.delete(t);if(i.size<2)return new Set}let s=new Map,c=new Map;for(let e of o){let n=t.get(e);if(!n)continue;let r=n.dependencies.filter(e=>s.has(e));if(r.length===0)s.set(e,n.end),c.set(e,null);else{let t=-1/0,i=null;for(let e of r){let r=s.get(e)+n.duration;r>t&&(t=r,i=e)}n.end>t&&(t=n.end),s.set(e,t),c.set(e,i)}}let l=[];for(let e of o)(n.get(e)??[]).filter(e=>i.has(e)).length===0&&l.push(e);if(l.length===0)return new Set;let u=l[0],d=s.get(l[0])??0;for(let e=1;e<l.length;e++){let t=s.get(l[e])??0;t>d&&(d=t,u=l[e])}let f=new Set,p=u;for(;p!==null;)f.add(p),p=c.get(p)??null;return f.size<=1?new Set:f}var $=class extends t.LitElement{constructor(...e){super(...e),this.rows=[],this.theme=`light`,this.selectedRowIds=[],this.selectedTaskIds=[],this.externalDraggingTask=null,this.selectedRows=new Set,this.selectedTasks=new Set,this.lastClickedRowId=null,this.virtualScrollTop=0,this.dragTargetRowIndex=null,this.draggingTask=null,this.draggingTaskIds=[],this.multiDragDx=0,this.multiDragDy=0,this.multiDragSameRow=!1,this.viewportHeight=400,this.dragOverlayInfo=null,this.calendarHeight=0,this.tooltip=null,this.dragOverRowId=null,this.dragOverPosition=null,this.currentTime=new Date,this.dragPreview=null,this.currentRowHeaderWidth=150,this.isResizingHeader=!1,this.hoveredMilestoneId=null,this.cursorLineX=null,this.connectorDrag=null,this._systemThemeMediaQuery=null,this.isExporting=!1,this.focusedTaskId=null,this.focusedRowId=null,this.zoomPxPerDay=null,this.zoomPxPerMonth=null,this._layoutCache=null,this.resizeObserver=null,this._cachedSelectedTaskIds=[],this._cachedSelectedTasksSize=-1,this._cachedCurrentOption=null,this._lastOptionRef=null,this._lastLabelWidth=-1,this._lastZoomPxPerDay=null,this._lastZoomPxPerMonth=null,this._scrollContainer=null,this.handleSystemThemeChange=e=>{(this.option?.theme===`system`||this.option?.theme!==`light`&&this.option?.theme!==`dark`)&&(this.theme=e.matches?`dark`:`light`)},this.handleScroll=e=>{let t=e.target;this.updateScrollTop(t.scrollTop),this.hoverTimer!==void 0&&window.clearTimeout(this.hoverTimer),this.tooltip&&={...this.tooltip,visible:!1}},this.updateScrollTop=(0,a.throttle)(e=>{this.virtualScrollTop=e},100),this.handleContainerMouseMove=e=>{if(!this.option.calendar.showCursorLine)return;let t=this.shadowRoot?.querySelector(`.scroll-container`);if(!t)return;let n=t.getBoundingClientRect(),r=e.clientX-n.left+t.scrollLeft;if(r<this.currentRowHeaderWidth){this.cursorLineX=null;return}this.cursorLineX=r},this.handleContainerMouseLeave=()=>{this.cursorLineX=null},this.handleWheel=e=>{if(!e.ctrlKey&&!e.metaKey||this.option.zoom?.enabled!==!0)return;e.preventDefault();let t=this._scrollContainer;if(!t)return;let n=t.getBoundingClientRect(),r=this.currentRowHeaderWidth,i=e.clientX-n.left+t.scrollLeft-r,a=this.effectivePxPerMonth!==void 0,o=a?this.effectivePxPerMonth:this.effectivePxPerDay,s=this.option.zoom?.step??1.2,c=a?20:2,l=a?600:200,u=this.option.zoom?.min??c,d=this.option.zoom?.max??l,f=e.deltaY>0?1/s:s,p=Math.max(u,Math.min(d,o*f));if(p===o)return;a?this.zoomPxPerMonth=p:this.zoomPxPerDay=p;let m=p/o;this.updateComplete.then(()=>{let e=i*m-i;t.scrollLeft+=e}),this.dispatchEvent(new CustomEvent(`zoom-change`,{detail:{pxPerDay:a?this.effectivePxPerDay:p,pxPerMonth:a?p:void 0},bubbles:!0,composed:!0}))},this.handleKeyDown=e=>{if(this.option.keyboard?.enabled===!1)return;let t=e.composedPath()[0];if(!(t!==this&&t?.tagName&&[`INPUT`,`TEXTAREA`,`SELECT`].includes(t.tagName)))switch(e.key){case`ArrowRight`:e.shiftKey&&!this.option.readOnly?this.moveSelectedTasksByKeyboard(1):this.moveFocusHorizontal(1),e.preventDefault();break;case`ArrowLeft`:e.shiftKey&&!this.option.readOnly?this.moveSelectedTasksByKeyboard(-1):this.moveFocusHorizontal(-1),e.preventDefault();break;case`ArrowDown`:this.moveFocusVertical(1),e.preventDefault();break;case`ArrowUp`:this.moveFocusVertical(-1),e.preventDefault();break;case`Enter`:case` `:this.focusedTaskId&&(e.ctrlKey||e.metaKey?this.toggleTaskSelection(this.focusedTaskId):this.selectSingleTask(this.focusedTaskId)),e.preventDefault();break;case`Escape`:this.clearSelection(),this.focusedTaskId=null,this.focusedRowId=null;break;case`Delete`:case`Backspace`:!this.option.readOnly&&this.selectedTasks.size>0&&this.dispatchEvent(new CustomEvent(`task-delete`,{detail:{taskIds:[...this.selectedTasks],event:e},bubbles:!0,composed:!0})),e.preventDefault();break;case`Home`:this.focusFirstOrLastTaskInRow(`first`),e.preventDefault();break;case`End`:this.focusFirstOrLastTaskInRow(`last`),e.preventDefault();break}}}get displayRows(){return this.option.showHiddenRows?this.rows:this.rows.filter(e=>e.visible!==!1)}get effectivePxPerDay(){return this.zoomPxPerDay??this.option.calendar.pxPerDay??50}get effectivePxPerMonth(){return this.zoomPxPerMonth??this.option.calendar.pxPerMonth}static{this.styles=Y}firstUpdated(){this.setupCurrentTimeTimer();let e=this.shadowRoot?.getElementById(`calendar`);this.resizeObserver=new ResizeObserver(t=>{for(let n of t)n.target===this?this.viewportHeight=n.contentRect.height:n.target===e&&(this.calendarHeight=n.target.offsetHeight)}),this.resizeObserver.observe(this),e&&this.resizeObserver.observe(e),this._scrollContainer=this.shadowRoot?.querySelector(`.scroll-container`),this._scrollContainer?.addEventListener(`wheel`,this.handleWheel,{passive:!1})}connectedCallback(){super.connectedCallback(),this._systemThemeMediaQuery=window.matchMedia?window.matchMedia(`(prefers-color-scheme: dark)`):null,this._systemThemeMediaQuery?.addEventListener(`change`,this.handleSystemThemeChange),this.hasAttribute(`tabindex`)||this.setAttribute(`tabindex`,`0`),this.setAttribute(`role`,`grid`),this.setAttribute(`aria-label`,`Gantt Chart`),this.addEventListener(`keydown`,this.handleKeyDown),this.option?.theme===`system`||this.option?.theme!==`light`&&this.option?.theme!==`dark`?this.theme=this._systemThemeMediaQuery?.matches?`dark`:`light`:this.theme=this.option.theme}disconnectedCallback(){super.disconnectedCallback(),this.resizeObserver?.disconnect(),this.stopCurrentTimeTimer(),this._systemThemeMediaQuery?.removeEventListener(`change`,this.handleSystemThemeChange),this.removeEventListener(`keydown`,this.handleKeyDown),this._scrollContainer?.removeEventListener(`wheel`,this.handleWheel),this._scrollContainer=null}willUpdate(e){if(e.has(`option`)&&(this.option?.theme===`light`||this.option?.theme===`dark`?this.theme=this.option.theme:this._systemThemeMediaQuery&&(this.theme=this._systemThemeMediaQuery.matches?`dark`:`light`)),e.has(`option`)&&(this.setupCurrentTimeTimer(),this.isResizingHeader||(this.currentRowHeaderWidth=this.option.rowHeader?.width??150),this.zoomPxPerDay=null,this.zoomPxPerMonth=null),(e.has(`rows`)||e.has(`option`)||e.has(`currentRowHeaderWidth`)||e.has(`zoomPxPerDay`)||e.has(`zoomPxPerMonth`))&&(this._layoutCache=null),e.has(`selectedRowIds`)){let e=new Set(this.selectedRowIds);(e.size!==this.selectedRows.size||![...e].every(e=>this.selectedRows.has(e)))&&(this.selectedRows=e)}if(e.has(`selectedTaskIds`)){let e=new Set(this.selectedTaskIds);(e.size!==this.selectedTasks.size||![...e].every(e=>this.selectedTasks.has(e)))&&(this.selectedTasks=e)}(e.has(`selectedTasks`)||this._cachedSelectedTasksSize!==this.selectedTasks.size)&&(this._cachedSelectedTaskIds=[...this.selectedTasks],this._cachedSelectedTasksSize=this.selectedTasks.size)}updated(e){if(super.updated(e),this.tooltip){let e=this.shadowRoot?.querySelector(`.tooltip`);if(e){let n=this.option.customRendering?.tooltip?this.option.customRendering.tooltip(this.tooltip.task):void 0;if(n)typeof n==`string`?e.textContent=n:(0,t.render)(n,e);else{let n=this.option.locale??j,r=!!this.option.calendar.pxPerMonth,i=Math.round((this.tooltip.task.end.getTime()-this.tooltip.task.start.getTime())/(1e3*60*60*24));if(r){let r=new Date(this.tooltip.task.end);r.setMonth(r.getMonth()-1),(0,t.render)(t.html`
986
997
  <div style="font-weight: bold;">${this.tooltip.task.name}</div>
987
998
  <div class="tooltip-row">
988
999
  ${n.yearMonthFormat(this.tooltip.task.start)} - ${n.yearMonthFormat(r)}
@@ -994,7 +1005,7 @@
994
1005
  ${n.dateFormat(this.tooltip.task.start)} - ${n.dateFormat(this.tooltip.task.end)}
995
1006
  </div>
996
1007
  <div class="tooltip-row">${n.tooltip.duration(i)}</div>
997
- `,e)}let r=e.getBoundingClientRect(),i=this.tooltip.x,a=this.tooltip.y;r.right>window.innerWidth-6&&(i=window.innerWidth-6-r.width/2),r.left<6&&(i=6+r.width/2),r.top<6&&(e.style.transform=`translate(-50%, 0)`,e.style.marginTop=`6px`),(i!==this.tooltip.x||a!==this.tooltip.y)&&(e.style.left=`${i}px`,e.style.top=`${a}px`)}}}updateDragOverlay(){if(!this.dragOverlayInfo||this.option.showDragInfoOverlay===!1)return;let e=L(this.theme,this.option.customTheme),n=this.shadowRoot?.querySelector(`.drag-info-overlay`);if(!n)return;n.classList.toggle(`visible`,this.dragOverlayInfo.visible);let{targetRow:r}=this.dragOverlayInfo,i=this.option.customRendering?.dragInfo?this.option.customRendering.dragInfo({id:this.dragOverlayInfo.id,name:this.dragOverlayInfo.name,start:this.dragOverlayInfo.start,end:this.dragOverlayInfo.end},this.dragOverlayInfo.currentStart,this.dragOverlayInfo.currentEnd,r):void 0;if(i)(0,t.render)(i,n);else{let i=this.option.locale??j,a=!!this.option.calendar.pxPerMonth,o,s;if(a){let e=new Date(this.dragOverlayInfo.currentEnd);e.setMonth(e.getMonth()-1),o=i.yearMonthFormat(this.dragOverlayInfo.currentStart),s=i.yearMonthFormat(e)}else o=i.dateTimeFormat(this.dragOverlayInfo.currentStart),s=i.dateTimeFormat(this.dragOverlayInfo.currentEnd);(0,t.render)(t.html`
1008
+ `,e)}let r=e.getBoundingClientRect();if(!this.tooltip.below&&r.top<6){this.tooltip={...this.tooltip,below:!0};return}let i=this.tooltip.x;r.right>window.innerWidth-6&&(i=window.innerWidth-6-r.width/2),r.left<6&&(i=6+r.width/2),i!==this.tooltip.x&&(e.style.left=`${i}px`)}}}updateDragOverlay(){if(!this.dragOverlayInfo||this.option.showDragInfoOverlay===!1)return;let e=L(this.theme,this.option.customTheme),n=this.shadowRoot?.querySelector(`.drag-info-overlay`);if(!n)return;n.classList.toggle(`visible`,this.dragOverlayInfo.visible);let{targetRow:r}=this.dragOverlayInfo,i=this.option.customRendering?.dragInfo?this.option.customRendering.dragInfo({id:this.dragOverlayInfo.id,name:this.dragOverlayInfo.name,start:this.dragOverlayInfo.start,end:this.dragOverlayInfo.end},this.dragOverlayInfo.currentStart,this.dragOverlayInfo.currentEnd,r):void 0;if(i)(0,t.render)(i,n);else{let i=this.option.locale??j,a=!!this.option.calendar.pxPerMonth,o,s;if(a){let e=new Date(this.dragOverlayInfo.currentEnd);e.setMonth(e.getMonth()-1),o=i.yearMonthFormat(this.dragOverlayInfo.currentStart),s=i.yearMonthFormat(e)}else o=i.dateTimeFormat(this.dragOverlayInfo.currentStart),s=i.dateTimeFormat(this.dragOverlayInfo.currentEnd);(0,t.render)(t.html`
998
1009
  <div style="font-weight: bold;">
999
1010
  ${this.dragOverlayInfo.name||i.dragOverlay.noTitle}
1000
1011
  </div>
@@ -1004,12 +1015,12 @@
1004
1015
  (${B(this.dragOverlayInfo.currentStart,this.dragOverlayInfo.currentEnd,this.option.locale)})
1005
1016
  </div>
1006
1017
  ${r?t.html`<div class="drag-info-sub" style="margin-top: 4px; border-top: 1px solid ${e.dragOverlayDivider}; padding-top: 4px; width: 100%;">${(this.option.locale??j).dragOverlay.moveTo(r.name)}</div>`:``}
1007
- `,n)}if(this.dragOverlayInfo.clientY!==void 0){let e=this.dragOverlayInfo.clientX??0,t=this.dragOverlayInfo.clientY,r=this.getBoundingClientRect();if(e<r.left||e>r.right||t<r.top||t>r.bottom){n.classList.remove(`visible`);return}let i=n.offsetWidth||200,a=n.offsetHeight||60,o=window.innerWidth,s=window.innerHeight,c=e-i/2;c=Math.max(8,Math.min(c,o-i-8));let l=t-a-40;l<8&&(l=t+40),l+a>s-8&&(l=s-a-8),n.style.left=`${c}px`,n.style.transform=`none`,n.style.top=`${l}px`,n.style.bottom=`auto`}}hideDragOverlay(){let e=this.shadowRoot?.querySelector(`.drag-info-overlay`);e&&e.classList.remove(`visible`)}setupCurrentTimeTimer(){this.stopCurrentTimeTimer();let e=this.option.calendar.currentTimeUpdateInterval;e&&e>0&&(this.currentTimeTimer=window.setInterval(()=>{this.currentTime=new Date},e))}stopCurrentTimeTimer(){this.currentTimeTimer!==void 0&&(window.clearInterval(this.currentTimeTimer),this.currentTimeTimer=void 0)}handleHeaderResizeStart(e){e.preventDefault(),e.stopPropagation(),this.isResizingHeader=!0;let t=e.clientX,n=this.currentRowHeaderWidth,r=e.target;r.setPointerCapture(e.pointerId);let i=this.option.rowHeader?.minWidth??50,a=this.option.rowHeader?.maxWidth??2**53-1,o=e=>{let r=n+(e.clientX-t);this.currentRowHeaderWidth=Math.max(i,Math.min(a,r))},s=()=>{this.isResizingHeader=!1,r.releasePointerCapture(e.pointerId),r.removeEventListener(`pointermove`,o),r.removeEventListener(`pointerup`,s);let t=Math.round(this.currentRowHeaderWidth);this.currentRowHeaderWidth=t,this.dispatchEvent(new CustomEvent(`row-header-resize`,{detail:{width:t},bubbles:!0,composed:!0}))};r.addEventListener(`pointermove`,o),r.addEventListener(`pointerup`,s)}getDateX(e){return P(e,this.option.calendar.start,this.effectivePxPerDay,this.effectivePxPerMonth)}calculateLayout(){if(this._layoutCache)return this._layoutCache;let e=0,t=this.currentRowHeaderWidth,n=new Map,r={layouts:this.displayRows.map(r=>{let{tasksWithLanes:i,laneCount:a}=I(r.tasks),o=this.option.bar?.height??28,s=this.option.bar?.margin??4;i.forEach(r=>{let i=this.getDateX(r.start)+t,a=this.getDateX(r.end)+t-i,c=e+r.lane*(o+s)+s;n.set(r.id,{x:i,y:c,width:a,height:o,dependencies:r.dependencies})});let c=a*(o+s)+s,l={top:e,height:c};return e+=c,l}),taskCoords:n,totalHeight:e};return this._layoutCache=r,r}isMultiDrag(e){return this.selectedTasks.size>=2&&this.selectedTasks.has(e)}isMultiDragSameRow(){if(this.selectedTasks.size<2)return!1;let e=null;for(let t of this.rows)for(let n of t.tasks)if(this.selectedTasks.has(n.id)){if(e===null)e=t.id;else if(e!==t.id)return!1}return e!==null}handleTaskUpdate(e){e.stopPropagation();let{id:t,start:n,end:r,dx:i,isDragging:a,mode:o}=e.detail,{dy:s}=e.detail,c=this.isMultiDrag(t),l=c&&this.isMultiDragSameRow();c&&!l&&(s=0);let u=n,d=r;if(i!==void 0){let e=this.effectivePxPerDay,t=this.effectivePxPerMonth,a=this.getDateX(n),o=this.getDateX(r);u=F(a+i,this.option.calendar.start,e,t),d=F(o+i,this.option.calendar.start,e,t)}(this.option.calendar.pxPerMonth||this.option.snapDuration&&this.option.snapDuration>=43200)&&(u.getDate()>15&&u.setMonth(u.getMonth()+1),u.setDate(1),u.setHours(0,0,0,0),d.getDate()>15&&d.setMonth(d.getMonth()+1),d.setDate(1),d.setHours(0,0,0,0));let f=-1,p,m=-1;if(this.rows.find((e,n)=>{let r=e.tasks.findIndex(e=>e.id===t);return r===-1?!1:(f=n,p=e.tasks[r],m=r,!0)}),f===-1||!p)return;let{layouts:h}=this.calculateLayout(),g=this.displayRows.findIndex(e=>e.id===this.rows[f].id);if(g===-1)return;let _=h[g].top,{tasksWithLanes:v}=I(this.rows[f].tasks),y=v.find(e=>e.id===t),b=y?y.lane:0,x=this.option.bar?.height??28,S=this.option.bar?.margin??4,C=_+(b*(x+S)+S)+s+x/2,w=-1;for(let e=0;e<h.length;e++){let t=h[e];if(C>=t.top&&C<t.top+t.height){w=e;break}}let T=w===-1?void 0:this.displayRows[w].id,E=c?[...this.selectedTasks]:void 0;if(this.dispatchEvent(new CustomEvent(`task-update`,{detail:{...e.detail,dy:s,start:u,end:d,targetRowId:T,selectedTaskIds:E},bubbles:!0,composed:!0})),a){if(this.hoverTimer!==void 0&&window.clearTimeout(this.hoverTimer),this.tooltip&&=null,(!this.draggingTask||this.draggingTask.id!==t)&&(this.draggingTask={id:t,name:e.detail.name,start:n,end:r,currentStart:u,currentEnd:d,mode:o},c?this.draggingTaskIds=[...this.selectedTasks]:this.draggingTaskIds=[]),c?(this.multiDragDx=i??0,this.multiDragSameRow=l,l?this.multiDragDy=s:this.multiDragDy=0):(this.multiDragDx!==0||this.multiDragDy!==0)&&(this.multiDragDx=0,this.multiDragDy=0),!c||l){let e=w>=0?w:null;this.dragTargetRowIndex!==e&&(this.dragTargetRowIndex=e)}c?this.dragOverlayInfo={id:t,name:(this.option.locale??j).dragOverlay.movingTasks(this.selectedTasks.size),start:n,end:r,currentStart:u,currentEnd:d,visible:!0,clientX:e.detail.x,clientY:e.detail.y}:this.dragOverlayInfo={id:t,name:e.detail.name,start:n,end:r,currentStart:u,currentEnd:d,targetRow:w>=0?this.displayRows[w]:void 0,visible:!0,clientX:e.detail.x,clientY:e.detail.y},this.updateDragOverlay();return}let D=this.draggingTaskIds.length>=2,O=this.multiDragSameRow;this.draggingTask=null,this.draggingTaskIds=[],this.multiDragDx=0,this.multiDragDy=0,this.multiDragSameRow=!1,this.dragTargetRowIndex=null,this.dragOverlayInfo&&(this.dragOverlayInfo={...this.dragOverlayInfo,visible:!1},this.hideDragOverlay()),this.tooltip&&={...this.tooltip,visible:!1};let k=-1;if(w!==-1){let e=this.displayRows[w];k=this.rows.findIndex(t=>t.id===e.id)}if(D&&i!==void 0){let e=this.effectivePxPerDay,t=this.effectivePxPerMonth;if(O&&k!==-1&&f!==k){let n=[...this.rows],r={...n[f]},a={...n[k]};r.tasks=[...r.tasks],a.tasks=[...a.tasks];let o=[];r.tasks=r.tasks.filter(n=>{if(this.selectedTasks.has(n.id)){let r=this.getDateX(n.start),a=this.getDateX(n.end),s=F(r+i,this.option.calendar.start,e,t),c=F(a+i,this.option.calendar.start,e,t);return(this.option.calendar.pxPerMonth||this.option.snapDuration&&this.option.snapDuration>=43200)&&(s.getDate()>15&&s.setMonth(s.getMonth()+1),s.setDate(1),s.setHours(0,0,0,0),c.getDate()>15&&c.setMonth(c.getMonth()+1),c.setDate(1),c.setHours(0,0,0,0)),o.push({...n,start:s,end:c}),!1}return!0}),a.tasks.push(...o),n[f]=r,n[k]=a,requestAnimationFrame(()=>{this.rows=n,this.dispatchEvent(new CustomEvent(`rows-change`,{detail:this.rows,bubbles:!0,composed:!0}))})}else{let n=this.rows.map(n=>n.tasks.some(e=>this.selectedTasks.has(e.id))?{...n,tasks:n.tasks.map(n=>{if(!this.selectedTasks.has(n.id))return n;let r=this.getDateX(n.start),a=this.getDateX(n.end),o=F(r+i,this.option.calendar.start,e,t),s=F(a+i,this.option.calendar.start,e,t);return(this.option.calendar.pxPerMonth||this.option.snapDuration&&this.option.snapDuration>=43200)&&(o.getDate()>15&&o.setMonth(o.getMonth()+1),o.setDate(1),o.setHours(0,0,0,0),s.getDate()>15&&s.setMonth(s.getMonth()+1),s.setDate(1),s.setHours(0,0,0,0)),{...n,start:o,end:s}})}:n);requestAnimationFrame(()=>{this.rows=n,this.dispatchEvent(new CustomEvent(`rows-change`,{detail:this.rows,bubbles:!0,composed:!0}))})}return}if(o===`copy`){if(k!==-1){let e=[...this.rows],t={...e[k]};t.tasks=[...t.tasks];let n=`task-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,r={...p,id:n,start:u,end:d,dependencies:[]};t.tasks.push(r),e[k]=t,requestAnimationFrame(()=>{this.rows=e,this.dispatchEvent(new CustomEvent(`rows-change`,{detail:this.rows,bubbles:!0,composed:!0}))})}}else{let e=[...this.rows],t={...e[f]};if(t.tasks=[...t.tasks],e[f]=t,k!==-1&&f!==k){let n={...e[k]};n.tasks=[...n.tasks],e[k]=n;let[r]=t.tasks.splice(m,1);n.tasks.push({...r,start:u,end:d})}else t.tasks[m]={...p,start:u,end:d};requestAnimationFrame(()=>{this.rows=e,this.dispatchEvent(new CustomEvent(`rows-change`,{detail:this.rows,bubbles:!0,composed:!0}))})}}handleBarMouseEnter(e){if(this.draggingTask||this.option.showTooltip===!1)return;this.hoverTimer!==void 0&&window.clearTimeout(this.hoverTimer);let t=this.option.tooltipDelay??500;t>0?this.hoverTimer=window.setTimeout(()=>{this.tooltip={...e.detail,visible:!0}},t):this.tooltip={...e.detail,visible:!0}}handleBarMouseLeave(){this.hoverTimer!==void 0&&window.clearTimeout(this.hoverTimer),this.tooltip&&={...this.tooltip,visible:!1}}async reorderRows(e,t,n){let r=Array.isArray(e)?e:[e],i=Array.from(this.shadowRoot?.querySelectorAll(`gantt-row`)??[]),a=new Map;i.forEach(e=>{e.row&&a.set(e.row.id,e.getBoundingClientRect().top)});let o=[...this.rows],s=[];if(o.findIndex(e=>e.id===t)===-1)return;r.forEach(e=>{let t=o.findIndex(t=>t.id===e);t!==-1&&s.push(o[t])});let c=o.filter(e=>!r.includes(e.id));if(r.includes(t))return;let l=c.findIndex(e=>e.id===t);n===`bottom`&&l++,c.splice(l,0,...s),this.rows=c,await this.updateComplete,Array.from(this.shadowRoot?.querySelectorAll(`gantt-row`)??[]).forEach(e=>{if(e.row){let t=a.get(e.row.id);if(t!==void 0){let n=t-e.getBoundingClientRect().top;n!==0&&e.animate([{transform:`translateY(${n}px)`,zIndex:`1`},{transform:`translateY(0)`,zIndex:`1`}],{duration:300,easing:`ease-out`})}}}),this.dispatchEvent(new CustomEvent(`row-reordered`,{detail:{sourceId:r[0],sourceIds:r,targetId:t,position:n,rows:this.rows},bubbles:!0,composed:!0})),this.dispatchEvent(new CustomEvent(`rows-change`,{detail:this.rows,bubbles:!0,composed:!0}))}handleContainerDragOver(e){e.preventDefault();let t=e.dataTransfer&&e.dataTransfer.types.includes(`application/json`);if(t&&(e.dataTransfer.dropEffect=`copy`),!this.option.enableRowReordering&&!t)return;let n=this.shadowRoot?.querySelector(`.scroll-container`);if(!n)return;let r=n.getBoundingClientRect(),i=e.clientY-r.top+n.scrollTop-this.calendarHeight,{layouts:a}=this.calculateLayout(),o=-1;for(let e=0;e<a.length;e++){let t=a[e];if(i>=t.top&&i<t.top+t.height){o=e;break}}if(o!==-1){let s=this.displayRows[o];if(t){if((this.dragOverRowId!==s.id||this.dragOverPosition!==null)&&(this.dragOverRowId=s.id,this.dragOverPosition=null),this.externalDraggingTask){let t=this.currentRowHeaderWidth,i=n.scrollLeft,a=e.clientX-r.left+i-t,o=this.effectivePxPerDay,c=this.effectivePxPerMonth,l=this.option.snapDuration??1440,u=o/1440*l,d=F(Math.round(a/u)*u,this.option.calendar.start,o,c),f=this.externalDraggingTask.end.getTime()-this.externalDraggingTask.start.getTime(),p=new Date(d.getTime()+f);(!this.dragPreview||this.dragPreview.rowId!==s.id||this.dragPreview.currentStart.getTime()!==d.getTime())&&(this.dragPreview={task:this.externalDraggingTask,currentStart:d,currentEnd:p,rowId:s.id})}}else{let e=a[o],t=i-e.top<e.height/2?`top`:`bottom`;(this.dragOverRowId!==s.id||this.dragOverPosition!==t)&&(this.dragOverRowId=s.id,this.dragOverPosition=t)}}else this.dragOverRowId=null,this.dragOverPosition=null,this.dragPreview=null}handleContainerDragLeave(e){let t=this.shadowRoot?.querySelector(`.scroll-container`),n=e.relatedTarget;t&&t.contains(n)||(this.dragOverRowId=null,this.dragOverPosition=null,this.dragPreview=null)}handleContainerDrop(e){e.preventDefault();let t=e.dataTransfer?.getData(`application/json`);if(t){this.handleExternalTaskDrop(e,t),this.dragOverRowId=null,this.dragOverPosition=null,this.dragPreview=null;return}if(!this.option.enableRowReordering)return;let n=e.dataTransfer?.getData(`text/plain`),r=this.dragOverRowId,i=this.dragOverPosition;if(this.dragOverRowId=null,this.dragOverPosition=null,this.dragPreview=null,n&&r&&n!==r&&i)if(this.selectedRows.has(n)&&this.selectedRows.size>1){let e=Array.from(this.selectedRows);this.reorderRows(e,r,i)}else this.reorderRows(n,r,i)}handleExternalTaskDrop(e,t){try{let n=JSON.parse(t);if(!n||typeof n!=`object`||typeof n.id!=`string`||typeof n.name!=`string`||!n.start||!n.end){console.warn(`Invalid dropped task data: missing required fields (id, name, start, end)`);return}let r=new Date(n.start),i=new Date(n.end);if(isNaN(r.getTime())||isNaN(i.getTime())){console.warn(`Invalid dropped task data: start or end is not a valid date`);return}let a={...n,start:r,end:i},o=this.shadowRoot?.querySelector(`.scroll-container`);if(!o)return;let s=o.getBoundingClientRect(),c=o.scrollLeft,l=o.scrollTop,u=this.currentRowHeaderWidth,d=e.clientX-s.left+c-u,f=this.effectivePxPerDay,p=this.effectivePxPerMonth,m=F(d,this.option.calendar.start,f,p),h=e.clientY-s.top+l-this.calendarHeight,{layouts:g}=this.calculateLayout(),_;for(let e=0;e<g.length;e++){let t=g[e];if(h>=t.top&&h<t.top+t.height){_=this.displayRows[e].id;break}}_&&this.dispatchEvent(new CustomEvent(`task-drop`,{detail:{task:a,dropDate:m,targetRowId:_},bubbles:!0,composed:!0}))}catch(e){console.warn(`Failed to parse dropped task data`,e)}}handleRowClicked(e){let{rowId:t,event:n}=e.detail,{shiftKey:r,ctrlKey:i,metaKey:a}=n,o=new Set(this.selectedRows);if(r&&this.lastClickedRowId){let e=this.rows.findIndex(e=>e.id===this.lastClickedRowId),n=this.rows.findIndex(e=>e.id===t);if(e!==-1&&n!==-1){let t=Math.min(e,n),r=Math.max(e,n);for(let e=t;e<=r;e++)o.add(this.rows[e].id)}}else if(i||a)o.has(t)?o.delete(t):o.add(t),this.lastClickedRowId=t;else{if(o.has(t)){this.lastClickedRowId=t;return}o.clear(),o.add(t),this.lastClickedRowId=t}this.selectedRows=o,this.dispatchEvent(new CustomEvent(`row-selection-change`,{detail:{selectedIds:Array.from(this.selectedRows)},bubbles:!0,composed:!0}))}handleRowContextMenu(e){this.selectedRows.has(e.detail.rowId)||this.handleRowClicked(e)}handleContainerClick(e){e.defaultPrevented||this.clearSelection()}handleContainerContextMenu(e){if(e.defaultPrevented)return;e.preventDefault();let t=this.shadowRoot?.querySelector(`.scroll-container`);if(!t)return;let n=t.getBoundingClientRect(),r=t.scrollLeft,i=t.scrollTop,a=this.currentRowHeaderWidth,o=e.clientY-n.top+i-this.calendarHeight,{layouts:s}=this.calculateLayout(),c;for(let e=0;e<s.length;e++){let t=s[e];if(o>=t.top&&o<t.top+t.height){c=this.displayRows[e].id;break}}if(c){let t=e.clientX-n.left+r-a,i=this.effectivePxPerDay,o=this.effectivePxPerMonth,s=F(t,this.option.calendar.start,i,o);this.dispatchEvent(new CustomEvent(`chart-contextmenu`,{detail:{event:e,date:s,rowId:c},bubbles:!0,composed:!0}))}this.clearSelection()}hitTest(e,t){let n=this.shadowRoot?.querySelector(`.scroll-container`);if(!n)return null;let r=n.getBoundingClientRect(),i=n.scrollLeft,a=n.scrollTop,o=this.currentRowHeaderWidth,s=t-r.top+a-this.calendarHeight,{layouts:c}=this.calculateLayout(),l;for(let e=0;e<c.length;e++){let t=c[e];if(s>=t.top&&s<t.top+t.height){l=this.displayRows[e].id;break}}if(!l)return null;let u=e-r.left+i-o,d=this.effectivePxPerDay,f=this.effectivePxPerMonth,p=F(u,this.option.calendar.start,d,f);return{rowId:l,date:p}}getRowPositions(){let{layouts:e}=this.calculateLayout();return e.map(e=>({top:e.top,height:e.height,bottom:e.top+e.height}))}async exportImage(e=`png`,t={}){this.isExporting=!0,await this.updateComplete,await new Promise(e=>requestAnimationFrame(e));try{return await Z(this,e,t)}finally{this.isExporting=!1,await this.updateComplete}}zoomTo(e){let t=this.effectivePxPerMonth!==void 0,n=t?20:2,r=t?600:200,i=this.option.zoom?.min??n,a=this.option.zoom?.max??r,o=Math.max(i,Math.min(a,e));t?this.zoomPxPerMonth=o:this.zoomPxPerDay=o,this.dispatchEvent(new CustomEvent(`zoom-change`,{detail:{pxPerDay:t?this.effectivePxPerDay:o,pxPerMonth:t?o:void 0},bubbles:!0,composed:!0}))}zoomToFit(){let e=this.shadowRoot?.querySelector(`.scroll-container`);if(!e)return;let t=null,n=null;for(let e of this.displayRows)for(let r of e.tasks)(!t||r.start<t)&&(t=r.start),(!n||r.end>n)&&(n=r.end);if(!t||!n)return;let r=this.currentRowHeaderWidth,i=e.clientWidth-r;if(!(i<=0)){if(this.effectivePxPerMonth!==void 0){let e=(n.getFullYear()-t.getFullYear())*12+(n.getMonth()-t.getMonth()),r=i/Math.max(1,e);this.zoomTo(r)}else{let e=n.getTime()-t.getTime(),r=i/Math.max(1,e/(1e3*60*60*24));this.zoomTo(r)}requestAnimationFrame(()=>{let n=this.getDateX(t)+r;e.scrollLeft=Math.max(0,n-10)})}}resetZoom(){let e=this.zoomPxPerDay!==null||this.zoomPxPerMonth!==null;if(this.zoomPxPerDay=null,this.zoomPxPerMonth=null,e){let e=this.option.calendar.pxPerMonth!==void 0;this.dispatchEvent(new CustomEvent(`zoom-change`,{detail:{pxPerDay:this.option.calendar.pxPerDay??50,pxPerMonth:e?this.option.calendar.pxPerMonth:void 0},bubbles:!0,composed:!0}))}}clearSelection(){this.selectedRows.size===0&&this.selectedTasks.size===0||(this.selectedRows.size>0&&(this.selectedRows=new Set,this.dispatchEvent(new CustomEvent(`row-selection-change`,{detail:{selectedIds:[]},bubbles:!0,composed:!0}))),this.selectedTasks.size>0&&(this.selectedTasks=new Set,this.dispatchEvent(new CustomEvent(`bar-selection-change`,{detail:{selectedIds:[]},bubbles:!0,composed:!0}))))}moveFocusHorizontal(e){let t=this.displayRows;if(t.length===0)return;if(!this.focusedTaskId||!this.focusedRowId){this.focusFirstAvailableTask();return}let n=t.findIndex(e=>e.id===this.focusedRowId);if(n===-1){this.focusFirstAvailableTask();return}let r=t[n],i=[...r.tasks].sort((e,t)=>e.start.getTime()-t.start.getTime()),a=i.findIndex(e=>e.id===this.focusedTaskId);if(a===-1){i.length>0&&this.setFocus(i[0].id,r.id);return}let o=a+e;o>=0&&o<i.length?this.setFocus(i[o].id,r.id):this.moveFocusVertical(e)}moveFocusVertical(e){let t=this.displayRows;if(t.length===0)return;if(!this.focusedTaskId||!this.focusedRowId){this.focusFirstAvailableTask();return}let n=t.findIndex(e=>e.id===this.focusedRowId);if(n===-1){this.focusFirstAvailableTask();return}for(let r=n+e;r>=0&&r<t.length;r+=e){let n=t[r];if(n.tasks.length>0){let t=[...n.tasks].sort((e,t)=>e.start.getTime()-t.start.getTime()),r=e>0?t[0]:t[t.length-1];this.setFocus(r.id,n.id);return}}}focusFirstAvailableTask(){for(let e of this.displayRows)if(e.tasks.length>0){let t=[...e.tasks].sort((e,t)=>e.start.getTime()-t.start.getTime());this.setFocus(t[0].id,e.id);return}}focusFirstOrLastTaskInRow(e){if(!this.focusedRowId){this.focusFirstAvailableTask();return}let t=this.displayRows.find(e=>e.id===this.focusedRowId);if(!t||t.tasks.length===0)return;let n=[...t.tasks].sort((e,t)=>e.start.getTime()-t.start.getTime()),r=e===`first`?n[0]:n[n.length-1];this.setFocus(r.id,t.id)}setFocus(e,t){this.focusedTaskId=e,this.focusedRowId=t,this.scrollToTask(e)}toggleTaskSelection(e){let t=new Set(this.selectedTasks);t.has(e)?t.delete(e):t.add(e),this.selectedTasks=t,this.dispatchEvent(new CustomEvent(`bar-selection-change`,{detail:{selectedIds:[...t]},bubbles:!0,composed:!0}))}selectSingleTask(e){this.selectedTasks=new Set([e]),this.dispatchEvent(new CustomEvent(`bar-selection-change`,{detail:{selectedIds:[e]},bubbles:!0,composed:!0}))}moveSelectedTasksByKeyboard(e){if(this.selectedTasks.size===0)return;let t=(this.option.keyboard?.moveStep??this.option.snapDuration??1440)*60*1e3*e,n=this.rows.map(e=>e.tasks.some(e=>this.selectedTasks.has(e.id))?{...e,tasks:e.tasks.map(e=>this.selectedTasks.has(e.id)?{...e,start:new Date(e.start.getTime()+t),end:new Date(e.end.getTime()+t)}:e)}:e);for(let e of this.rows)for(let n of e.tasks){if(!this.selectedTasks.has(n.id))continue;let r=new Date(n.start.getTime()+t),i=new Date(n.end.getTime()+t);this.dispatchEvent(new CustomEvent(`task-update`,{detail:{id:n.id,name:n.name,start:r,end:i,dx:0,dy:0,isDragging:!1,mode:`move`,targetRowId:e.id},bubbles:!0,composed:!0}))}this.rows=n,this.dispatchEvent(new CustomEvent(`rows-change`,{detail:this.rows,bubbles:!0,composed:!0}))}handleBarClick(e){e.stopPropagation();let{task:t,isMultiSelect:n}=e.detail;this.draggingTask=null,this.dragTargetRowIndex=null,this.dragOverlayInfo&&(this.dragOverlayInfo={...this.dragOverlayInfo,visible:!1},this.hideDragOverlay());let r;n?(r=new Set(this.selectedTasks),r.has(t.id)?r.delete(t.id):r.add(t.id)):r=new Set([t.id]),this.selectedTasks=r,this.dispatchEvent(new CustomEvent(`bar-selection-change`,{detail:{selectedIds:[...r]},bubbles:!0,composed:!0}))}handleBarContextMenu(e){let{task:t}=e.detail;this.selectedTasks.has(t.id)||(this.selectedTasks=new Set([t.id]),this.dispatchEvent(new CustomEvent(`bar-selection-change`,{detail:{selectedIds:[t.id]},bubbles:!0,composed:!0})))}handleConnectorDragStart(e){let{taskId:t,endpoint:n,clientX:r,clientY:i}=e.detail;e.stopPropagation();let{taskCoords:a}=this.calculateLayout(),o=a.get(t),s=this.currentRowHeaderWidth,c=e.detail.startX+s,l=e.detail.startY;o&&(c=n===`start`?o.x:o.x+o.width,l=o.y+o.height/2),this.connectorDrag={sourceTaskId:t,sourceEndpoint:n,startX:c,startY:l,currentClientX:r,currentClientY:i,targetTaskId:null,targetEndpoint:null},this.tooltip&&=null}handleConnectorDragMove(e){if(!this.connectorDrag)return;e.stopPropagation();let{clientX:t,clientY:n}=e.detail,r=this.shadowRoot?.querySelector(`.scroll-container`);if(!r)return;let i=r.getBoundingClientRect(),a=t-i.left+r.scrollLeft,o=n-i.top+r.scrollTop-this.calendarHeight,{taskCoords:s}=this.calculateLayout(),c=null,l=null,u=30;for(let[e,t]of s){if(e===this.connectorDrag.sourceTaskId)continue;let n=t.y+t.height/2,r=t.x,i=t.x+t.width,s=Math.sqrt((a-r)**2+(o-n)**2),d=Math.sqrt((a-i)**2+(o-n)**2);s<u&&(u=s,c=e,l=`start`),d<u&&(u=d,c=e,l=`end`)}let d=this.connectorDrag.targetTaskId;d!==c&&(d&&this._setConnectorDropTarget(d,!1),c&&this._setConnectorDropTarget(c,!0)),this.connectorDrag={...this.connectorDrag,currentClientX:t,currentClientY:n,targetTaskId:c,targetEndpoint:l}}handleConnectorDragEnd(e){if(!this.connectorDrag)return;e.stopPropagation();let{cancelled:t}=e.detail,{sourceTaskId:n,sourceEndpoint:r,targetTaskId:i,targetEndpoint:a}=this.connectorDrag;i&&this._setConnectorDropTarget(i,!1),!t&&i&&a&&this.dispatchEvent(new CustomEvent(`dependency-create`,{detail:{sourceTaskId:n,sourceEndpoint:r,targetTaskId:i,targetEndpoint:a},bubbles:!0,composed:!0})),this.connectorDrag=null}_setConnectorDropTarget(e,t){let n=this.shadowRoot?.querySelectorAll(`gantt-row`);if(n)for(let r of n){let n=r.shadowRoot?.querySelectorAll(`gantt-bar`);if(n){for(let r of n)if(r.task?.id===e){r.connectorDropTarget=t;return}}}}handleDependencyLineClick(e,t,n){this.dispatchEvent(new CustomEvent(`dependency-click`,{detail:{event:e,sourceTaskId:n,targetTaskId:t},bubbles:!0,composed:!0}))}selectTask(e){let t=!1;for(let n of this.displayRows)if(n.tasks.some(t=>t.id===e)){t=!0;break}return t?(this.selectedTasks=new Set([e]),this.dispatchEvent(new CustomEvent(`bar-selection-change`,{detail:{selectedIds:[e]},bubbles:!0,composed:!0})),this.scrollToTask(e),!0):!1}scrollToTask(e){let{taskCoords:t}=this.calculateLayout(),n=t.get(e);if(!n)return;let r=this.shadowRoot?.querySelector(`.scroll-container`);if(!r)return;let i=this.currentRowHeaderWidth,a=n.y+this.calendarHeight,o=a+n.height,s=r.scrollTop,c=r.scrollTop+r.clientHeight;if(a<s||o>c){let e=a-r.clientHeight/2+n.height/2;r.scrollTo({top:Math.max(0,e),behavior:`smooth`})}let l=n.x,u=n.x+n.width,d=r.scrollLeft+i,f=r.scrollLeft+r.clientWidth;if(l<d||u>f){let e=l-i-20;r.scrollTo({left:Math.max(0,e),behavior:`smooth`})}}render(){let e=L(this.theme,this.option.customTheme),{layouts:n,taskCoords:r,totalHeight:a}=this.calculateLayout(),o=this.currentRowHeaderWidth;(this._lastOptionRef!==this.option||this._lastLabelWidth!==o||this._lastZoomPxPerDay!==this.zoomPxPerDay||this._lastZoomPxPerMonth!==this.zoomPxPerMonth)&&(this._cachedCurrentOption={...this.option,rowHeader:{...this.option.rowHeader,width:o},calendar:{...this.option.calendar,pxPerDay:this.effectivePxPerDay,pxPerMonth:this.effectivePxPerMonth}},this._lastOptionRef=this.option,this._lastLabelWidth=o,this._lastZoomPxPerDay=this.zoomPxPerDay,this._lastZoomPxPerMonth=this.zoomPxPerMonth);let s=this._cachedCurrentOption,c=0,l=this.displayRows.length-1;if(!this.isExporting){for(let e=0;e<n.length;e++)if(n[e].top+n[e].height>this.virtualScrollTop){c=Math.max(0,e-5);break}for(let e=c;e<n.length;e++)if(n[e].top>this.virtualScrollTop+this.viewportHeight){l=Math.min(this.displayRows.length-1,e+5);break}}let u=this.displayRows.slice(c,l+1),d=this.isExporting?0:n[c]?n[c].top:0,f=n[l],p=f?f.top+f.height:0,m=Math.max(0,a-p),h=a>this.viewportHeight,g=[],_=this.option.readOnly===!0,v=this.option.dependency?.showArrows!==!1,y=this.option.dependency?.arrowSize??8,b=this.option.dependency?.lineStyle??`orthogonal`,x=this.option.dependency?.cornerRadius??8,S=this.option.dependency?.showCriticalPath===!0,C=S?Q(this.displayRows):new Set;for(let[e,n]of r)if(n.dependencies)for(let i of n.dependencies){let a=r.get(i);if(a){let r=a.x+a.width,o=a.y+a.height/2,s=n.x,c=n.y+n.height/2,l=r<s,u=v?s-y:s,d=l?Math.max(r,u):u,f,p,m,h=this.option.bar?.height??28,w=this.option.bar?.margin??4;if(Math.abs(o-c)<1&&l)f=d>r?`M ${r} ${o} L ${d} ${c}`:``,p=s>r?`M ${r} ${o} L ${s} ${c}`:``;else if(b===`orthogonal`){let e=q(r,o,s,c,d,h,w,x);f=e.pathD,p=e.hitPathD}else if(l){let e=(r+d)/2;f=`M ${r} ${o} C ${e} ${o} ${e} ${c} ${d} ${c}`,p=`M ${r} ${o} C ${(r+s)/2} ${o} ${(r+s)/2} ${c} ${s} ${c}`}else{let e=Math.max(12,(r-s)*.15),t=(o+c)/2,n=Math.abs(o-c)<h?t+h+w:t;f=`M ${r} ${o} C ${r+e} ${o}, ${r+e} ${n}, ${(r+d)/2} ${n} S ${d-e} ${c}, ${d} ${c}`,p=`M ${r} ${o} C ${r+e} ${o}, ${r+e} ${n}, ${(r+s)/2} ${n} S ${s-e} ${c}, ${s} ${c}`}m=v?`M ${d} ${c} L ${s} ${c}`:``,g.push(t.svg`<g class="dependency-group">
1018
+ `,n)}if(this.dragOverlayInfo.clientY!==void 0){let e=this.dragOverlayInfo.clientX??0,t=this.dragOverlayInfo.clientY,r=this.getBoundingClientRect();if(e<r.left||e>r.right||t<r.top||t>r.bottom){n.classList.remove(`visible`);return}let i=n.offsetWidth||200,a=n.offsetHeight||60,o=window.innerWidth,s=window.innerHeight,c=e-i/2;c=Math.max(8,Math.min(c,o-i-8));let l=t-a-40;l<8&&(l=t+40),l+a>s-8&&(l=s-a-8),n.style.left=`${c}px`,n.style.transform=`none`,n.style.top=`${l}px`,n.style.bottom=`auto`}}hideDragOverlay(){let e=this.shadowRoot?.querySelector(`.drag-info-overlay`);e&&e.classList.remove(`visible`)}setupCurrentTimeTimer(){this.stopCurrentTimeTimer();let e=this.option.calendar.currentTimeUpdateInterval;e&&e>0&&(this.currentTimeTimer=window.setInterval(()=>{this.currentTime=new Date},e))}stopCurrentTimeTimer(){this.currentTimeTimer!==void 0&&(window.clearInterval(this.currentTimeTimer),this.currentTimeTimer=void 0)}handleHeaderResizeStart(e){e.preventDefault(),e.stopPropagation(),this.isResizingHeader=!0;let t=e.clientX,n=this.currentRowHeaderWidth,r=e.target;r.setPointerCapture(e.pointerId);let i=this.option.rowHeader?.minWidth??50,a=this.option.rowHeader?.maxWidth??2**53-1,o=e=>{let r=n+(e.clientX-t);this.currentRowHeaderWidth=Math.max(i,Math.min(a,r))},s=()=>{this.isResizingHeader=!1,r.releasePointerCapture(e.pointerId),r.removeEventListener(`pointermove`,o),r.removeEventListener(`pointerup`,s);let t=Math.round(this.currentRowHeaderWidth);this.currentRowHeaderWidth=t,this.dispatchEvent(new CustomEvent(`row-header-resize`,{detail:{width:t},bubbles:!0,composed:!0}))};r.addEventListener(`pointermove`,o),r.addEventListener(`pointerup`,s)}getDateX(e){return P(e,this.option.calendar.start,this.effectivePxPerDay,this.effectivePxPerMonth)}calculateLayout(){if(this._layoutCache)return this._layoutCache;let e=0,t=this.currentRowHeaderWidth,n=new Map,r={layouts:this.displayRows.map(r=>{let{tasksWithLanes:i,laneCount:a}=I(r.tasks),o=this.option.bar?.height??28,s=this.option.bar?.margin??4;i.forEach(r=>{let i=this.getDateX(r.start)+t,a=this.getDateX(r.end)+t-i,c=e+r.lane*(o+s)+s;n.set(r.id,{x:i,y:c,width:a,height:o,dependencies:r.dependencies})});let c=a*(o+s)+s,l={top:e,height:c};return e+=c,l}),taskCoords:n,totalHeight:e};return this._layoutCache=r,r}isMultiDrag(e){return this.selectedTasks.size>=2&&this.selectedTasks.has(e)}isMultiDragSameRow(){if(this.selectedTasks.size<2)return!1;let e=null;for(let t of this.rows)for(let n of t.tasks)if(this.selectedTasks.has(n.id)){if(e===null)e=t.id;else if(e!==t.id)return!1}return e!==null}handleTaskUpdate(e){e.stopPropagation();let{id:t,start:n,end:r,dx:i,isDragging:a,mode:o}=e.detail,{dy:s}=e.detail,c=this.isMultiDrag(t),l=c&&this.isMultiDragSameRow();c&&!l&&(s=0);let u=n,d=r;if(i!==void 0){let e=this.effectivePxPerDay,t=this.effectivePxPerMonth,a=this.getDateX(n),o=this.getDateX(r);u=F(a+i,this.option.calendar.start,e,t),d=F(o+i,this.option.calendar.start,e,t)}(this.option.calendar.pxPerMonth||this.option.snapDuration&&this.option.snapDuration>=43200)&&(u.getDate()>15&&u.setMonth(u.getMonth()+1),u.setDate(1),u.setHours(0,0,0,0),d.getDate()>15&&d.setMonth(d.getMonth()+1),d.setDate(1),d.setHours(0,0,0,0));let f=-1,p,m=-1;if(this.rows.find((e,n)=>{let r=e.tasks.findIndex(e=>e.id===t);return r===-1?!1:(f=n,p=e.tasks[r],m=r,!0)}),f===-1||!p)return;let{layouts:h}=this.calculateLayout(),g=this.displayRows.findIndex(e=>e.id===this.rows[f].id);if(g===-1)return;let _=h[g].top,{tasksWithLanes:v}=I(this.rows[f].tasks),y=v.find(e=>e.id===t),b=y?y.lane:0,x=this.option.bar?.height??28,S=this.option.bar?.margin??4,C=_+(b*(x+S)+S)+s+x/2,w=-1;for(let e=0;e<h.length;e++){let t=h[e];if(C>=t.top&&C<t.top+t.height){w=e;break}}let T=w===-1?void 0:this.displayRows[w].id,E=c?[...this.selectedTasks]:void 0;if(this.dispatchEvent(new CustomEvent(`task-update`,{detail:{...e.detail,dy:s,start:u,end:d,targetRowId:T,selectedTaskIds:E},bubbles:!0,composed:!0})),a){if(this.hoverTimer!==void 0&&window.clearTimeout(this.hoverTimer),this.tooltip&&=null,(!this.draggingTask||this.draggingTask.id!==t)&&(this.draggingTask={id:t,name:e.detail.name,start:n,end:r,currentStart:u,currentEnd:d,mode:o},c?this.draggingTaskIds=[...this.selectedTasks]:this.draggingTaskIds=[]),c?(this.multiDragDx=i??0,this.multiDragSameRow=l,l?this.multiDragDy=s:this.multiDragDy=0):(this.multiDragDx!==0||this.multiDragDy!==0)&&(this.multiDragDx=0,this.multiDragDy=0),!c||l){let e=w>=0?w:null;this.dragTargetRowIndex!==e&&(this.dragTargetRowIndex=e)}c?this.dragOverlayInfo={id:t,name:(this.option.locale??j).dragOverlay.movingTasks(this.selectedTasks.size),start:n,end:r,currentStart:u,currentEnd:d,visible:!0,clientX:e.detail.x,clientY:e.detail.y}:this.dragOverlayInfo={id:t,name:e.detail.name,start:n,end:r,currentStart:u,currentEnd:d,targetRow:w>=0?this.displayRows[w]:void 0,visible:!0,clientX:e.detail.x,clientY:e.detail.y},this.updateDragOverlay();return}let D=this.draggingTaskIds.length>=2,O=this.multiDragSameRow;this.draggingTask=null,this.draggingTaskIds=[],this.multiDragDx=0,this.multiDragDy=0,this.multiDragSameRow=!1,this.dragTargetRowIndex=null,this.dragOverlayInfo&&(this.dragOverlayInfo={...this.dragOverlayInfo,visible:!1},this.hideDragOverlay()),this.tooltip&&={...this.tooltip,visible:!1};let k=-1;if(w!==-1){let e=this.displayRows[w];k=this.rows.findIndex(t=>t.id===e.id)}if(D&&i!==void 0){let e=this.effectivePxPerDay,t=this.effectivePxPerMonth;if(O&&k!==-1&&f!==k){let n=[...this.rows],r={...n[f]},a={...n[k]};r.tasks=[...r.tasks],a.tasks=[...a.tasks];let o=[];r.tasks=r.tasks.filter(n=>{if(this.selectedTasks.has(n.id)){let r=this.getDateX(n.start),a=this.getDateX(n.end),s=F(r+i,this.option.calendar.start,e,t),c=F(a+i,this.option.calendar.start,e,t);return(this.option.calendar.pxPerMonth||this.option.snapDuration&&this.option.snapDuration>=43200)&&(s.getDate()>15&&s.setMonth(s.getMonth()+1),s.setDate(1),s.setHours(0,0,0,0),c.getDate()>15&&c.setMonth(c.getMonth()+1),c.setDate(1),c.setHours(0,0,0,0)),o.push({...n,start:s,end:c}),!1}return!0}),a.tasks.push(...o),n[f]=r,n[k]=a,requestAnimationFrame(()=>{this.rows=n,this.dispatchEvent(new CustomEvent(`rows-change`,{detail:this.rows,bubbles:!0,composed:!0}))})}else{let n=this.rows.map(n=>n.tasks.some(e=>this.selectedTasks.has(e.id))?{...n,tasks:n.tasks.map(n=>{if(!this.selectedTasks.has(n.id))return n;let r=this.getDateX(n.start),a=this.getDateX(n.end),o=F(r+i,this.option.calendar.start,e,t),s=F(a+i,this.option.calendar.start,e,t);return(this.option.calendar.pxPerMonth||this.option.snapDuration&&this.option.snapDuration>=43200)&&(o.getDate()>15&&o.setMonth(o.getMonth()+1),o.setDate(1),o.setHours(0,0,0,0),s.getDate()>15&&s.setMonth(s.getMonth()+1),s.setDate(1),s.setHours(0,0,0,0)),{...n,start:o,end:s}})}:n);requestAnimationFrame(()=>{this.rows=n,this.dispatchEvent(new CustomEvent(`rows-change`,{detail:this.rows,bubbles:!0,composed:!0}))})}return}if(o===`copy`){if(k!==-1){let e=[...this.rows],t={...e[k]};t.tasks=[...t.tasks];let n=`task-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,r={...p,id:n,start:u,end:d,dependencies:[]};t.tasks.push(r),e[k]=t,requestAnimationFrame(()=>{this.rows=e,this.dispatchEvent(new CustomEvent(`rows-change`,{detail:this.rows,bubbles:!0,composed:!0}))})}}else{let e=[...this.rows],t={...e[f]};if(t.tasks=[...t.tasks],e[f]=t,k!==-1&&f!==k){let n={...e[k]};n.tasks=[...n.tasks],e[k]=n;let[r]=t.tasks.splice(m,1);n.tasks.push({...r,start:u,end:d})}else t.tasks[m]={...p,start:u,end:d};requestAnimationFrame(()=>{this.rows=e,this.dispatchEvent(new CustomEvent(`rows-change`,{detail:this.rows,bubbles:!0,composed:!0}))})}}handleBarMouseEnter(e){if(this.draggingTask||this.option.showTooltip===!1)return;this.hoverTimer!==void 0&&window.clearTimeout(this.hoverTimer);let t=this.option.tooltipDelay??500;t>0?this.hoverTimer=window.setTimeout(()=>{this.tooltip={...e.detail,visible:!0,below:!1}},t):this.tooltip={...e.detail,visible:!0,below:!1}}handleBarMouseLeave(){this.hoverTimer!==void 0&&window.clearTimeout(this.hoverTimer),this.tooltip&&={...this.tooltip,visible:!1}}async reorderRows(e,t,n){let r=Array.isArray(e)?e:[e],i=Array.from(this.shadowRoot?.querySelectorAll(`gantt-row`)??[]),a=new Map;i.forEach(e=>{e.row&&a.set(e.row.id,e.getBoundingClientRect().top)});let o=[...this.rows],s=[];if(o.findIndex(e=>e.id===t)===-1)return;r.forEach(e=>{let t=o.findIndex(t=>t.id===e);t!==-1&&s.push(o[t])});let c=o.filter(e=>!r.includes(e.id));if(r.includes(t))return;let l=c.findIndex(e=>e.id===t);n===`bottom`&&l++,c.splice(l,0,...s),this.rows=c,await this.updateComplete,Array.from(this.shadowRoot?.querySelectorAll(`gantt-row`)??[]).forEach(e=>{if(e.row){let t=a.get(e.row.id);if(t!==void 0){let n=t-e.getBoundingClientRect().top;n!==0&&e.animate([{transform:`translateY(${n}px)`,zIndex:`1`},{transform:`translateY(0)`,zIndex:`1`}],{duration:300,easing:`ease-out`})}}}),this.dispatchEvent(new CustomEvent(`row-reordered`,{detail:{sourceId:r[0],sourceIds:r,targetId:t,position:n,rows:this.rows},bubbles:!0,composed:!0})),this.dispatchEvent(new CustomEvent(`rows-change`,{detail:this.rows,bubbles:!0,composed:!0}))}handleContainerDragOver(e){e.preventDefault();let t=e.dataTransfer&&e.dataTransfer.types.includes(`application/json`);if(t&&(e.dataTransfer.dropEffect=`copy`),!this.option.enableRowReordering&&!t)return;let n=this.shadowRoot?.querySelector(`.scroll-container`);if(!n)return;let r=n.getBoundingClientRect(),i=e.clientY-r.top+n.scrollTop-this.calendarHeight,{layouts:a}=this.calculateLayout(),o=-1;for(let e=0;e<a.length;e++){let t=a[e];if(i>=t.top&&i<t.top+t.height){o=e;break}}if(o!==-1){let s=this.displayRows[o];if(t){if((this.dragOverRowId!==s.id||this.dragOverPosition!==null)&&(this.dragOverRowId=s.id,this.dragOverPosition=null),this.externalDraggingTask){let t=this.currentRowHeaderWidth,i=n.scrollLeft,a=e.clientX-r.left+i-t,o=this.effectivePxPerDay,c=this.effectivePxPerMonth,l=this.option.snapDuration??1440,u=o/1440*l,d=F(Math.round(a/u)*u,this.option.calendar.start,o,c),f=this.externalDraggingTask.end.getTime()-this.externalDraggingTask.start.getTime(),p=new Date(d.getTime()+f);(!this.dragPreview||this.dragPreview.rowId!==s.id||this.dragPreview.currentStart.getTime()!==d.getTime())&&(this.dragPreview={task:this.externalDraggingTask,currentStart:d,currentEnd:p,rowId:s.id})}}else{let e=a[o],t=i-e.top<e.height/2?`top`:`bottom`;(this.dragOverRowId!==s.id||this.dragOverPosition!==t)&&(this.dragOverRowId=s.id,this.dragOverPosition=t)}}else this.dragOverRowId=null,this.dragOverPosition=null,this.dragPreview=null}handleContainerDragLeave(e){let t=this.shadowRoot?.querySelector(`.scroll-container`),n=e.relatedTarget;t&&t.contains(n)||(this.dragOverRowId=null,this.dragOverPosition=null,this.dragPreview=null)}handleContainerDrop(e){e.preventDefault();let t=e.dataTransfer?.getData(`application/json`);if(t){this.handleExternalTaskDrop(e,t),this.dragOverRowId=null,this.dragOverPosition=null,this.dragPreview=null;return}if(!this.option.enableRowReordering)return;let n=e.dataTransfer?.getData(`text/plain`),r=this.dragOverRowId,i=this.dragOverPosition;if(this.dragOverRowId=null,this.dragOverPosition=null,this.dragPreview=null,n&&r&&n!==r&&i)if(this.selectedRows.has(n)&&this.selectedRows.size>1){let e=Array.from(this.selectedRows);this.reorderRows(e,r,i)}else this.reorderRows(n,r,i)}handleExternalTaskDrop(e,t){try{let n=JSON.parse(t);if(!n||typeof n!=`object`||typeof n.id!=`string`||typeof n.name!=`string`||!n.start||!n.end){console.warn(`Invalid dropped task data: missing required fields (id, name, start, end)`);return}let r=new Date(n.start),i=new Date(n.end);if(isNaN(r.getTime())||isNaN(i.getTime())){console.warn(`Invalid dropped task data: start or end is not a valid date`);return}let a={...n,start:r,end:i},o=this.shadowRoot?.querySelector(`.scroll-container`);if(!o)return;let s=o.getBoundingClientRect(),c=o.scrollLeft,l=o.scrollTop,u=this.currentRowHeaderWidth,d=e.clientX-s.left+c-u,f=this.effectivePxPerDay,p=this.effectivePxPerMonth,m=F(d,this.option.calendar.start,f,p),h=e.clientY-s.top+l-this.calendarHeight,{layouts:g}=this.calculateLayout(),_;for(let e=0;e<g.length;e++){let t=g[e];if(h>=t.top&&h<t.top+t.height){_=this.displayRows[e].id;break}}_&&this.dispatchEvent(new CustomEvent(`task-drop`,{detail:{task:a,dropDate:m,targetRowId:_},bubbles:!0,composed:!0}))}catch(e){console.warn(`Failed to parse dropped task data`,e)}}handleRowClicked(e){let{rowId:t,event:n}=e.detail,{shiftKey:r,ctrlKey:i,metaKey:a}=n,o=new Set(this.selectedRows);if(r&&this.lastClickedRowId){let e=this.rows.findIndex(e=>e.id===this.lastClickedRowId),n=this.rows.findIndex(e=>e.id===t);if(e!==-1&&n!==-1){let t=Math.min(e,n),r=Math.max(e,n);for(let e=t;e<=r;e++)o.add(this.rows[e].id)}}else if(i||a)o.has(t)?o.delete(t):o.add(t),this.lastClickedRowId=t;else{if(o.has(t)){this.lastClickedRowId=t;return}o.clear(),o.add(t),this.lastClickedRowId=t}this.selectedRows=o,this.dispatchEvent(new CustomEvent(`row-selection-change`,{detail:{selectedIds:Array.from(this.selectedRows)},bubbles:!0,composed:!0}))}handleRowContextMenu(e){this.selectedRows.has(e.detail.rowId)||this.handleRowClicked(e)}handleContainerClick(e){e.defaultPrevented||this.clearSelection()}handleContainerContextMenu(e){if(e.defaultPrevented)return;e.preventDefault();let t=this.shadowRoot?.querySelector(`.scroll-container`);if(!t)return;let n=t.getBoundingClientRect(),r=t.scrollLeft,i=t.scrollTop,a=this.currentRowHeaderWidth,o=e.clientY-n.top+i-this.calendarHeight,{layouts:s}=this.calculateLayout(),c;for(let e=0;e<s.length;e++){let t=s[e];if(o>=t.top&&o<t.top+t.height){c=this.displayRows[e].id;break}}if(c){let t=e.clientX-n.left+r-a,i=this.effectivePxPerDay,o=this.effectivePxPerMonth,s=F(t,this.option.calendar.start,i,o);this.dispatchEvent(new CustomEvent(`chart-contextmenu`,{detail:{event:e,date:s,rowId:c},bubbles:!0,composed:!0}))}this.clearSelection()}hitTest(e,t){let n=this.shadowRoot?.querySelector(`.scroll-container`);if(!n)return null;let r=n.getBoundingClientRect(),i=n.scrollLeft,a=n.scrollTop,o=this.currentRowHeaderWidth,s=t-r.top+a-this.calendarHeight,{layouts:c}=this.calculateLayout(),l;for(let e=0;e<c.length;e++){let t=c[e];if(s>=t.top&&s<t.top+t.height){l=this.displayRows[e].id;break}}if(!l)return null;let u=e-r.left+i-o,d=this.effectivePxPerDay,f=this.effectivePxPerMonth,p=F(u,this.option.calendar.start,d,f);return{rowId:l,date:p}}getRowPositions(){let{layouts:e}=this.calculateLayout();return e.map(e=>({top:e.top,height:e.height,bottom:e.top+e.height}))}async exportImage(e=`png`,t={}){this.isExporting=!0,await this.updateComplete,await new Promise(e=>requestAnimationFrame(e));try{return await ee(this,e,t)}finally{this.isExporting=!1,await this.updateComplete}}zoomTo(e){let t=this.effectivePxPerMonth!==void 0,n=t?20:2,r=t?600:200,i=this.option.zoom?.min??n,a=this.option.zoom?.max??r,o=Math.max(i,Math.min(a,e));t?this.zoomPxPerMonth=o:this.zoomPxPerDay=o,this.dispatchEvent(new CustomEvent(`zoom-change`,{detail:{pxPerDay:t?this.effectivePxPerDay:o,pxPerMonth:t?o:void 0},bubbles:!0,composed:!0}))}zoomToFit(){let e=this.shadowRoot?.querySelector(`.scroll-container`);if(!e)return;let t=null,n=null;for(let e of this.displayRows)for(let r of e.tasks)(!t||r.start<t)&&(t=r.start),(!n||r.end>n)&&(n=r.end);if(!t||!n)return;let r=this.currentRowHeaderWidth,i=e.clientWidth-r;if(!(i<=0)){if(this.effectivePxPerMonth!==void 0){let e=(n.getFullYear()-t.getFullYear())*12+(n.getMonth()-t.getMonth()),r=i/Math.max(1,e);this.zoomTo(r)}else{let e=n.getTime()-t.getTime(),r=i/Math.max(1,e/(1e3*60*60*24));this.zoomTo(r)}requestAnimationFrame(()=>{let n=this.getDateX(t)+r;e.scrollLeft=Math.max(0,n-10)})}}resetZoom(){let e=this.zoomPxPerDay!==null||this.zoomPxPerMonth!==null;if(this.zoomPxPerDay=null,this.zoomPxPerMonth=null,e){let e=this.option.calendar.pxPerMonth!==void 0;this.dispatchEvent(new CustomEvent(`zoom-change`,{detail:{pxPerDay:this.option.calendar.pxPerDay??50,pxPerMonth:e?this.option.calendar.pxPerMonth:void 0},bubbles:!0,composed:!0}))}}clearSelection(){this.selectedRows.size===0&&this.selectedTasks.size===0||(this.selectedRows.size>0&&(this.selectedRows=new Set,this.dispatchEvent(new CustomEvent(`row-selection-change`,{detail:{selectedIds:[]},bubbles:!0,composed:!0}))),this.selectedTasks.size>0&&(this.selectedTasks=new Set,this.dispatchEvent(new CustomEvent(`bar-selection-change`,{detail:{selectedIds:[]},bubbles:!0,composed:!0}))))}moveFocusHorizontal(e){let t=this.displayRows;if(t.length===0)return;if(!this.focusedTaskId||!this.focusedRowId){this.focusFirstAvailableTask();return}let n=t.findIndex(e=>e.id===this.focusedRowId);if(n===-1){this.focusFirstAvailableTask();return}let r=t[n],i=[...r.tasks].sort((e,t)=>e.start.getTime()-t.start.getTime()),a=i.findIndex(e=>e.id===this.focusedTaskId);if(a===-1){i.length>0&&this.setFocus(i[0].id,r.id);return}let o=a+e;o>=0&&o<i.length?this.setFocus(i[o].id,r.id):this.moveFocusVertical(e)}moveFocusVertical(e){let t=this.displayRows;if(t.length===0)return;if(!this.focusedTaskId||!this.focusedRowId){this.focusFirstAvailableTask();return}let n=t.findIndex(e=>e.id===this.focusedRowId);if(n===-1){this.focusFirstAvailableTask();return}for(let r=n+e;r>=0&&r<t.length;r+=e){let n=t[r];if(n.tasks.length>0){let t=[...n.tasks].sort((e,t)=>e.start.getTime()-t.start.getTime()),r=e>0?t[0]:t[t.length-1];this.setFocus(r.id,n.id);return}}}focusFirstAvailableTask(){for(let e of this.displayRows)if(e.tasks.length>0){let t=[...e.tasks].sort((e,t)=>e.start.getTime()-t.start.getTime());this.setFocus(t[0].id,e.id);return}}focusFirstOrLastTaskInRow(e){if(!this.focusedRowId){this.focusFirstAvailableTask();return}let t=this.displayRows.find(e=>e.id===this.focusedRowId);if(!t||t.tasks.length===0)return;let n=[...t.tasks].sort((e,t)=>e.start.getTime()-t.start.getTime()),r=e===`first`?n[0]:n[n.length-1];this.setFocus(r.id,t.id)}setFocus(e,t){this.focusedTaskId=e,this.focusedRowId=t,this.scrollToTask(e)}toggleTaskSelection(e){let t=new Set(this.selectedTasks);t.has(e)?t.delete(e):t.add(e),this.selectedTasks=t,this.dispatchEvent(new CustomEvent(`bar-selection-change`,{detail:{selectedIds:[...t]},bubbles:!0,composed:!0}))}selectSingleTask(e){this.selectedTasks=new Set([e]),this.dispatchEvent(new CustomEvent(`bar-selection-change`,{detail:{selectedIds:[e]},bubbles:!0,composed:!0}))}moveSelectedTasksByKeyboard(e){if(this.selectedTasks.size===0)return;let t=(this.option.keyboard?.moveStep??this.option.snapDuration??1440)*60*1e3*e,n=this.rows.map(e=>e.tasks.some(e=>this.selectedTasks.has(e.id))?{...e,tasks:e.tasks.map(e=>this.selectedTasks.has(e.id)?{...e,start:new Date(e.start.getTime()+t),end:new Date(e.end.getTime()+t)}:e)}:e);for(let e of this.rows)for(let n of e.tasks){if(!this.selectedTasks.has(n.id))continue;let r=new Date(n.start.getTime()+t),i=new Date(n.end.getTime()+t);this.dispatchEvent(new CustomEvent(`task-update`,{detail:{id:n.id,name:n.name,start:r,end:i,dx:0,dy:0,isDragging:!1,mode:`move`,targetRowId:e.id},bubbles:!0,composed:!0}))}this.rows=n,this.dispatchEvent(new CustomEvent(`rows-change`,{detail:this.rows,bubbles:!0,composed:!0}))}handleBarClick(e){e.stopPropagation();let{task:t,isMultiSelect:n}=e.detail;this.draggingTask=null,this.dragTargetRowIndex=null,this.dragOverlayInfo&&(this.dragOverlayInfo={...this.dragOverlayInfo,visible:!1},this.hideDragOverlay());let r;n?(r=new Set(this.selectedTasks),r.has(t.id)?r.delete(t.id):r.add(t.id)):r=new Set([t.id]),this.selectedTasks=r,this.dispatchEvent(new CustomEvent(`bar-selection-change`,{detail:{selectedIds:[...r]},bubbles:!0,composed:!0}))}handleBarContextMenu(e){let{task:t}=e.detail;this.selectedTasks.has(t.id)||(this.selectedTasks=new Set([t.id]),this.dispatchEvent(new CustomEvent(`bar-selection-change`,{detail:{selectedIds:[t.id]},bubbles:!0,composed:!0})))}handleConnectorDragStart(e){let{taskId:t,endpoint:n,clientX:r,clientY:i}=e.detail;e.stopPropagation();let{taskCoords:a}=this.calculateLayout(),o=a.get(t),s=this.currentRowHeaderWidth,c=e.detail.startX+s,l=e.detail.startY;o&&(c=n===`start`?o.x:o.x+o.width,l=o.y+o.height/2),this.connectorDrag={sourceTaskId:t,sourceEndpoint:n,startX:c,startY:l,currentClientX:r,currentClientY:i,targetTaskId:null,targetEndpoint:null},this.tooltip&&=null}handleConnectorDragMove(e){if(!this.connectorDrag)return;e.stopPropagation();let{clientX:t,clientY:n}=e.detail,r=this.shadowRoot?.querySelector(`.scroll-container`);if(!r)return;let i=r.getBoundingClientRect(),a=t-i.left+r.scrollLeft,o=n-i.top+r.scrollTop-this.calendarHeight,{taskCoords:s}=this.calculateLayout(),c=null,l=null,u=30;for(let[e,t]of s){if(e===this.connectorDrag.sourceTaskId)continue;let n=t.y+t.height/2,r=t.x,i=t.x+t.width,s=Math.sqrt((a-r)**2+(o-n)**2),d=Math.sqrt((a-i)**2+(o-n)**2);s<u&&(u=s,c=e,l=`start`),d<u&&(u=d,c=e,l=`end`)}let d=this.connectorDrag.targetTaskId;d!==c&&(d&&this._setConnectorDropTarget(d,!1),c&&this._setConnectorDropTarget(c,!0)),this.connectorDrag={...this.connectorDrag,currentClientX:t,currentClientY:n,targetTaskId:c,targetEndpoint:l}}handleConnectorDragEnd(e){if(!this.connectorDrag)return;e.stopPropagation();let{cancelled:t}=e.detail,{sourceTaskId:n,sourceEndpoint:r,targetTaskId:i,targetEndpoint:a}=this.connectorDrag;i&&this._setConnectorDropTarget(i,!1),!t&&i&&a&&this.dispatchEvent(new CustomEvent(`dependency-create`,{detail:{sourceTaskId:n,sourceEndpoint:r,targetTaskId:i,targetEndpoint:a},bubbles:!0,composed:!0})),this.connectorDrag=null}_setConnectorDropTarget(e,t){let n=this.shadowRoot?.querySelectorAll(`gantt-row`);if(n)for(let r of n){let n=r.shadowRoot?.querySelectorAll(`gantt-bar`);if(n){for(let r of n)if(r.task?.id===e){r.connectorDropTarget=t;return}}}}handleDependencyLineClick(e,t,n){this.dispatchEvent(new CustomEvent(`dependency-click`,{detail:{event:e,sourceTaskId:n,targetTaskId:t},bubbles:!0,composed:!0}))}selectTask(e){let t=!1;for(let n of this.displayRows)if(n.tasks.some(t=>t.id===e)){t=!0;break}return t?(this.selectedTasks=new Set([e]),this.dispatchEvent(new CustomEvent(`bar-selection-change`,{detail:{selectedIds:[e]},bubbles:!0,composed:!0})),this.scrollToTask(e),!0):!1}scrollToTask(e){let{taskCoords:t}=this.calculateLayout(),n=t.get(e);if(!n)return;let r=this.shadowRoot?.querySelector(`.scroll-container`);if(!r)return;let i=this.currentRowHeaderWidth,a=n.y+this.calendarHeight,o=a+n.height,s=r.scrollTop,c=r.scrollTop+r.clientHeight;if(a<s||o>c){let e=a-r.clientHeight/2+n.height/2;r.scrollTo({top:Math.max(0,e),behavior:`smooth`})}let l=n.x,u=n.x+n.width,d=r.scrollLeft+i,f=r.scrollLeft+r.clientWidth;if(l<d||u>f){let e=l-i-20;r.scrollTo({left:Math.max(0,e),behavior:`smooth`})}}render(){let e=L(this.theme,this.option.customTheme),{layouts:n,taskCoords:r,totalHeight:a}=this.calculateLayout(),o=this.currentRowHeaderWidth;(this._lastOptionRef!==this.option||this._lastLabelWidth!==o||this._lastZoomPxPerDay!==this.zoomPxPerDay||this._lastZoomPxPerMonth!==this.zoomPxPerMonth)&&(this._cachedCurrentOption={...this.option,rowHeader:{...this.option.rowHeader,width:o},calendar:{...this.option.calendar,pxPerDay:this.effectivePxPerDay,pxPerMonth:this.effectivePxPerMonth}},this._lastOptionRef=this.option,this._lastLabelWidth=o,this._lastZoomPxPerDay=this.zoomPxPerDay,this._lastZoomPxPerMonth=this.zoomPxPerMonth);let s=this._cachedCurrentOption,c=0,l=this.displayRows.length-1;if(!this.isExporting){for(let e=0;e<n.length;e++)if(n[e].top+n[e].height>this.virtualScrollTop){c=Math.max(0,e-5);break}for(let e=c;e<n.length;e++)if(n[e].top>this.virtualScrollTop+this.viewportHeight){l=Math.min(this.displayRows.length-1,e+5);break}}let u=this.displayRows.slice(c,l+1),d=this.isExporting?0:n[c]?n[c].top:0,f=n[l],p=f?f.top+f.height:0,m=Math.max(0,a-p),h=a>this.viewportHeight,g=[],_=this.option.readOnly===!0,v=this.option.dependency?.showArrows!==!1,y=this.option.dependency?.arrowSize??8,b=this.option.dependency?.lineStyle??`orthogonal`,x=this.option.dependency?.cornerRadius??8,S=this.option.dependency?.showCriticalPath===!0,C=S?Q(this.displayRows):new Set;for(let[e,n]of r)if(n.dependencies)for(let i of n.dependencies){let a=r.get(i);if(a){let r=a.x+a.width,o=a.y+a.height/2,s=n.x,c=n.y+n.height/2,l=r<s,u=v?s-y:s,d=l?Math.max(r,u):u,f,p,m,h=this.option.bar?.height??28,w=this.option.bar?.margin??4;if(Math.abs(o-c)<1&&l)f=d>r?`M ${r} ${o} L ${d} ${c}`:``,p=s>r?`M ${r} ${o} L ${s} ${c}`:``;else if(b===`orthogonal`){let e=J(r,o,s,c,d,h,w,x);f=e.pathD,p=e.hitPathD}else if(l){let e=(r+d)/2;f=`M ${r} ${o} C ${e} ${o} ${e} ${c} ${d} ${c}`,p=`M ${r} ${o} C ${(r+s)/2} ${o} ${(r+s)/2} ${c} ${s} ${c}`}else{let e=Math.max(12,(r-s)*.15),t=(o+c)/2,n=Math.abs(o-c)<h?t+h+w:t;f=`M ${r} ${o} C ${r+e} ${o}, ${r+e} ${n}, ${(r+d)/2} ${n} S ${d-e} ${c}, ${d} ${c}`,p=`M ${r} ${o} C ${r+e} ${o}, ${r+e} ${n}, ${(r+s)/2} ${n} S ${s-e} ${c}, ${s} ${c}`}m=v?`M ${d} ${c} L ${s} ${c}`:``,g.push(t.svg`<g class="dependency-group">
1008
1019
  ${_?``:t.svg`<path class="dependency-hit-area" d="${p}" @click="${t=>{t.stopPropagation(),this.handleDependencyLineClick(t,e,i)}}" />`}
1009
1020
  <path class="dependency-line ${S&&C.has(e)&&C.has(i)?`critical-path`:``}" d="${f}" />
1010
1021
  ${v?t.svg`<path class="dependency-line dependency-arrow-line ${S&&C.has(e)&&C.has(i)?`critical-path`:``}" d="${m}" marker-end="url(#dependency-arrowhead)" />`:``}
1011
1022
  </g>`)}}let w=null;if(this.connectorDrag){let e=this.shadowRoot?.querySelector(`.scroll-container`);if(e){let n=e.getBoundingClientRect(),i=this.connectorDrag.startX,a=this.connectorDrag.startY,o,s;if(this.connectorDrag.targetTaskId&&this.connectorDrag.targetEndpoint){let t=r.get(this.connectorDrag.targetTaskId);t?(o=this.connectorDrag.targetEndpoint===`start`?t.x:t.x+t.width,s=t.y+t.height/2):(o=this.connectorDrag.currentClientX-n.left+e.scrollLeft,s=this.connectorDrag.currentClientY-n.top+e.scrollTop-this.calendarHeight)}else o=this.connectorDrag.currentClientX-n.left+e.scrollLeft,s=this.connectorDrag.currentClientY-n.top+e.scrollTop-this.calendarHeight;let c=(i+o)/2;w=t.svg`<path class="connector-preview-line" d="M ${i} ${a} C ${c} ${a} ${c} ${s} ${o} ${s}" />`}}return t.html`
1012
- <style>${Y(this.theme,this.option.customTheme)}
1023
+ <style>${X(this.theme,this.option.customTheme)}
1013
1024
  :host {
1014
1025
  --critical-path-color: ${e.criticalPath??`rgba(220, 38, 38, 0.85)`};
1015
1026
  }
@@ -1175,8 +1186,8 @@
1175
1186
  ${this.option.showDragInfoOverlay===!1?``:t.html` <div class="drag-info-overlay"></div> `}
1176
1187
  ${this.tooltip?t.html`
1177
1188
  <div
1178
- class="tooltip ${this.tooltip.visible?`visible`:``}"
1179
- style="top: ${this.tooltip.y}px; left: ${this.tooltip.x}px;"
1189
+ class="tooltip ${this.tooltip.visible?`visible`:``} ${this.tooltip.below?`below`:``}"
1190
+ style="top: ${this.tooltip.below?this.tooltip.barBottom:this.tooltip.y}px; left: ${this.tooltip.x}px;"
1180
1191
  />
1181
1192
  `:``}
1182
- `}};H([(0,n.property)({type:Array})],$.prototype,`rows`,void 0),H([(0,n.property)({type:Object})],$.prototype,`option`,void 0),H([(0,n.property)({type:String,reflect:!0})],$.prototype,`theme`,void 0),H([(0,n.property)({type:Array})],$.prototype,`selectedRowIds`,void 0),H([(0,n.property)({type:Array})],$.prototype,`selectedTaskIds`,void 0),H([(0,n.property)({attribute:!1})],$.prototype,`externalDraggingTask`,void 0),H([(0,n.state)()],$.prototype,`selectedRows`,void 0),H([(0,n.state)()],$.prototype,`selectedTasks`,void 0),H([(0,n.state)()],$.prototype,`lastClickedRowId`,void 0),H([(0,n.state)()],$.prototype,`virtualScrollTop`,void 0),H([(0,n.state)()],$.prototype,`dragTargetRowIndex`,void 0),H([(0,n.state)()],$.prototype,`draggingTask`,void 0),H([(0,n.state)()],$.prototype,`draggingTaskIds`,void 0),H([(0,n.state)()],$.prototype,`multiDragDx`,void 0),H([(0,n.state)()],$.prototype,`multiDragDy`,void 0),H([(0,n.state)()],$.prototype,`multiDragSameRow`,void 0),H([(0,n.state)()],$.prototype,`viewportHeight`,void 0),H([(0,n.state)()],$.prototype,`calendarHeight`,void 0),H([(0,n.state)()],$.prototype,`tooltip`,void 0),H([(0,n.state)()],$.prototype,`dragOverRowId`,void 0),H([(0,n.state)()],$.prototype,`dragOverPosition`,void 0),H([(0,n.state)()],$.prototype,`currentTime`,void 0),H([(0,n.state)()],$.prototype,`dragPreview`,void 0),H([(0,n.state)()],$.prototype,`currentRowHeaderWidth`,void 0),H([(0,n.state)()],$.prototype,`isResizingHeader`,void 0),H([(0,n.state)()],$.prototype,`hoveredMilestoneId`,void 0),H([(0,n.state)()],$.prototype,`cursorLineX`,void 0),H([(0,n.state)()],$.prototype,`connectorDrag`,void 0),H([(0,n.state)()],$.prototype,`isExporting`,void 0),H([(0,n.state)()],$.prototype,`focusedTaskId`,void 0),H([(0,n.state)()],$.prototype,`focusedRowId`,void 0),H([(0,n.state)()],$.prototype,`zoomPxPerDay`,void 0),H([(0,n.state)()],$.prototype,`zoomPxPerMonth`,void 0),$=H([(0,n.customElement)(`gantt-chart`)],$),e.ALL_BAR_PATTERNS=g,Object.defineProperty(e,`GanttBarElement`,{enumerable:!0,get:function(){return U}}),Object.defineProperty(e,`GanttCalendarElement`,{enumerable:!0,get:function(){return W}}),Object.defineProperty(e,`GanttChartElement`,{enumerable:!0,get:function(){return $}}),Object.defineProperty(e,`GanttRowElement`,{enumerable:!0,get:function(){return K}}),e.PATTERN_CHECKERBOARD=x,e.PATTERN_CIRCLE=w,e.PATTERN_DIAGONAL_GRID=E,e.PATTERN_DIAGONAL_STRIPE=_,e.PATTERN_DIAGONAL_STRIPE_REVERSE=v,e.PATTERN_DOTS=S,e.PATTERN_DOTS_DENSE=k,e.PATTERN_GRID=T,e.PATTERN_HORIZONTAL_STRIPE=b,e.PATTERN_STRIPE_THICK=O,e.PATTERN_STRIPE_THIN=D,e.PATTERN_TRIANGLE=C,e.PATTERN_VERTICAL_STRIPE=y,e.computeCriticalPath=Q,e.enLocale=M,e.getPatternStyle=A,e.jaLocale=j});
1193
+ `}};H([(0,n.property)({type:Array})],$.prototype,`rows`,void 0),H([(0,n.property)({type:Object})],$.prototype,`option`,void 0),H([(0,n.property)({type:String,reflect:!0})],$.prototype,`theme`,void 0),H([(0,n.property)({type:Array})],$.prototype,`selectedRowIds`,void 0),H([(0,n.property)({type:Array})],$.prototype,`selectedTaskIds`,void 0),H([(0,n.property)({attribute:!1})],$.prototype,`externalDraggingTask`,void 0),H([(0,n.state)()],$.prototype,`selectedRows`,void 0),H([(0,n.state)()],$.prototype,`selectedTasks`,void 0),H([(0,n.state)()],$.prototype,`lastClickedRowId`,void 0),H([(0,n.state)()],$.prototype,`virtualScrollTop`,void 0),H([(0,n.state)()],$.prototype,`dragTargetRowIndex`,void 0),H([(0,n.state)()],$.prototype,`draggingTask`,void 0),H([(0,n.state)()],$.prototype,`draggingTaskIds`,void 0),H([(0,n.state)()],$.prototype,`multiDragDx`,void 0),H([(0,n.state)()],$.prototype,`multiDragDy`,void 0),H([(0,n.state)()],$.prototype,`multiDragSameRow`,void 0),H([(0,n.state)()],$.prototype,`viewportHeight`,void 0),H([(0,n.state)()],$.prototype,`calendarHeight`,void 0),H([(0,n.state)()],$.prototype,`tooltip`,void 0),H([(0,n.state)()],$.prototype,`dragOverRowId`,void 0),H([(0,n.state)()],$.prototype,`dragOverPosition`,void 0),H([(0,n.state)()],$.prototype,`currentTime`,void 0),H([(0,n.state)()],$.prototype,`dragPreview`,void 0),H([(0,n.state)()],$.prototype,`currentRowHeaderWidth`,void 0),H([(0,n.state)()],$.prototype,`isResizingHeader`,void 0),H([(0,n.state)()],$.prototype,`hoveredMilestoneId`,void 0),H([(0,n.state)()],$.prototype,`cursorLineX`,void 0),H([(0,n.state)()],$.prototype,`connectorDrag`,void 0),H([(0,n.state)()],$.prototype,`isExporting`,void 0),H([(0,n.state)()],$.prototype,`focusedTaskId`,void 0),H([(0,n.state)()],$.prototype,`focusedRowId`,void 0),H([(0,n.state)()],$.prototype,`zoomPxPerDay`,void 0),H([(0,n.state)()],$.prototype,`zoomPxPerMonth`,void 0),$=H([(0,n.customElement)(`gantt-chart`)],$),e.ALL_BAR_PATTERNS=g,Object.defineProperty(e,`GanttBarElement`,{enumerable:!0,get:function(){return W}}),Object.defineProperty(e,`GanttCalendarElement`,{enumerable:!0,get:function(){return G}}),Object.defineProperty(e,`GanttChartElement`,{enumerable:!0,get:function(){return $}}),Object.defineProperty(e,`GanttRowElement`,{enumerable:!0,get:function(){return q}}),e.PATTERN_CHECKERBOARD=x,e.PATTERN_CIRCLE=w,e.PATTERN_DIAGONAL_GRID=E,e.PATTERN_DIAGONAL_STRIPE=_,e.PATTERN_DIAGONAL_STRIPE_REVERSE=v,e.PATTERN_DOTS=S,e.PATTERN_DOTS_DENSE=k,e.PATTERN_GRID=T,e.PATTERN_HORIZONTAL_STRIPE=b,e.PATTERN_STRIPE_THICK=O,e.PATTERN_STRIPE_THIN=D,e.PATTERN_TRIANGLE=C,e.PATTERN_VERTICAL_STRIPE=y,e.computeCriticalPath=Q,e.enLocale=M,e.getPatternStyle=A,e.jaLocale=j});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mogura/moguchart-core",
3
- "version": "0.8.0",
3
+ "version": "0.8.1",
4
4
  "description": "A lightweight, framework-agnostic Gantt chart Web Component built with Lit. Works with Vue, React, Angular, Svelte, and more.",
5
5
  "license": "MIT",
6
6
  "author": "Murakami Hiroyuki",
@@ -41,6 +41,18 @@
41
41
  "require": "./dist/moguchart-core.umd.js"
42
42
  }
43
43
  },
44
+ "scripts": {
45
+ "dev": "vite",
46
+ "build": "vite build && pnpm exec tsc -p tsconfig.build.json",
47
+ "build:demo": "BUILD_MODE=demo vite build && pnpm exec tsc",
48
+ "preview": "vite preview",
49
+ "prepublishOnly": "pnpm run build",
50
+ "test": "vitest",
51
+ "test:run": "vitest run",
52
+ "test:ui": "vitest --ui",
53
+ "test:coverage": "vitest run --coverage",
54
+ "refresh:packages": "rm -rf node_modules pnpm-lock.yaml && pnpm i"
55
+ },
44
56
  "devDependencies": {
45
57
  "@holiday-jp/holiday_jp": "^2.5.1",
46
58
  "@types/lodash-es": "^4.17.12",
@@ -60,16 +72,5 @@
60
72
  "html2canvas-pro": "^2.0.2",
61
73
  "jspdf": "^4.2.1",
62
74
  "lodash-es": "^4.17.21"
63
- },
64
- "scripts": {
65
- "dev": "vite",
66
- "build": "vite build && pnpm exec tsc -p tsconfig.build.json",
67
- "build:demo": "BUILD_MODE=demo vite build && pnpm exec tsc",
68
- "preview": "vite preview",
69
- "test": "vitest",
70
- "test:run": "vitest run",
71
- "test:ui": "vitest --ui",
72
- "test:coverage": "vitest run --coverage",
73
- "refresh:packages": "rm -rf node_modules pnpm-lock.yaml && pnpm i"
74
75
  }
75
76
  }