@koyori-app/arc-vue 0.1.0-alpha.3 → 0.1.0-alpha.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,5 @@
1
- import { GanttTask, GanttDep } from './types.ts';
1
+ import { GanttTask, GanttDep, GanttRow } from './types.ts';
2
+ import { PaletteOverrides, ProgressLineMode, ViewRange } from './options';
2
3
  type __VLS_Props = {
3
4
  tasks: GanttTask[];
4
5
  deps?: GanttDep[];
@@ -19,12 +20,69 @@ type __VLS_Props = {
19
20
  * legend of every existing caller.
20
21
  */
21
22
  legend?: 'shown' | 'hidden';
23
+ /**
24
+ * `'hidden'` leaves the title column out: the days start half a bar
25
+ * (`HIDDEN_LABELS_LEFT_PX`, or half of `barHeight` when it is set) in from
26
+ * the left edge, and a click hits only the bars and the milestones' diamonds.
27
+ * For a caller that lays the chart beside a list of its own. A string for the
28
+ * same reason as `legend`.
29
+ */
30
+ rowLabels?: 'shown' | 'hidden';
31
+ /** `'hidden'` leaves out the `NN%` on every bar and milestone. */
32
+ percentLabels?: 'shown' | 'hidden';
33
+ /**
34
+ * The chart's rows, top to bottom, for a caller that lays them out itself
35
+ * beside a list of its own: task rows and group rows (a band, no bar). A
36
+ * task left out is not drawn. Left out, one row per task as the crate lays
37
+ * them out. See `docs/design/external-rows.md`.
38
+ */
39
+ rows?: GanttRow[];
40
+ /** Height of a row in pixels. Left out, the crate's own. */
41
+ rowHeight?: number;
42
+ /** Height of the date header in pixels. Left out, the crate's own. */
43
+ headerHeight?: number;
44
+ /** Height of a bar in pixels. Left out, the crate's own. */
45
+ barHeight?: number;
46
+ /** `'bottom'` sets a bar low in a tall row, leaving the room above it. */
47
+ barAlign?: 'middle' | 'bottom';
48
+ /**
49
+ * Colours that replace the chart's own, by colour name, such as
50
+ * `{ HeaderBg: 'var(--koyori-color-surface)' }`. The SVG path writes
51
+ * `var(--…)` as it is, and the browser follows a token whenever it changes.
52
+ * The canvas path reads it off the canvas's computed style when it paints,
53
+ * and paints again when the colour scheme or an ancestor's `class`, `style`
54
+ * or `data-*` changes. A token changed any other way (a stylesheet swapped
55
+ * in, say) needs `repaint()`, or the palette passed again as a new object.
56
+ */
57
+ palette?: PaletteOverrides;
58
+ /** Width of a day in pixels. Left out, the crate's own. */
59
+ pxPerDay?: number;
60
+ /**
61
+ * What the date header marks: `'week'` (the default), `'day'` (every day's
62
+ * number and weekday, and the month above the first day of each), or
63
+ * `'month'`. With `'day'` and no `headerHeight`, the header is 48 px, room
64
+ * for its three tiers. A `headerHeight` below 48 leaves the months out rather
65
+ * than draw them over the days.
66
+ */
67
+ scale?: 'week' | 'day' | 'month';
68
+ /** Weekday numbers drawn as weekend bands, 0 for Monday to 6 for Sunday. */
69
+ weekendDays?: number[];
70
+ /** Seven labels, Monday first, for the `'day'` scale, such as `['月', …, '日']`. */
71
+ weekdayLabels?: string[];
72
+ /** The days the chart shows, both included; left out, every task's days. */
73
+ view?: ViewRange;
74
+ /** How the progress line is drawn; left out, the line as before. */
75
+ progressLine?: ProgressLineMode;
22
76
  /** Render backend — default `svg` preserves existing DOM projection. */
23
77
  backend?: 'svg' | 'canvas';
24
78
  /** Override auto-detected device tier (VRT / Storybook should pin this). */
25
79
  deviceTier?: 'low' | 'high';
26
80
  };
27
- declare const __VLS_export: import('vue').DefineComponent<__VLS_Props, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {
81
+ /** Paints the canvas again, once per frame however often it is asked. */
82
+ declare function repaint(): void;
83
+ declare const __VLS_export: import('vue').DefineComponent<__VLS_Props, {
84
+ repaint: typeof repaint;
85
+ }, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {
28
86
  taskClick: (task: GanttTask) => any;
29
87
  }, string, import('vue').PublicProps, Readonly<__VLS_Props> & Readonly<{
30
88
  onTaskClick?: ((task: GanttTask) => any) | undefined;
package/dist/arc-vue.css CHANGED
@@ -1,2 +1,2 @@
1
- .koyori-gantt-scroll[data-v-73e8a554]{width:100%;overflow:auto}.koyori-gantt-scroll--virtual[data-v-73e8a554]{max-height:min(70vh,600px)}.koyori-gantt-inner[data-v-73e8a554]{width:100%;position:relative}.koyori-gantt-error[data-v-73e8a554]{color:#991b1b;padding:12px}.koyori-gantt-svg[data-v-73e8a554]{width:100%;position:absolute;top:0;left:0}.koyori-gantt-canvas[data-v-73e8a554]{display:block;position:absolute;top:0;left:0}.koyori-gantt-svg[data-v-73e8a554] svg{display:block}.koyori-gantt-skeleton[data-v-73e8a554]{--koyori-skeleton-gap:4px;--koyori-skeleton-bar-min-w:8px}.koyori-gantt-skeleton-row[data-v-73e8a554]{height:var(--v229b63f3);align-items:center;gap:var(--koyori-skeleton-gap);display:flex}.koyori-gantt-skeleton-label[data-v-73e8a554]{width:var(--v43727630);background:#e5e7eb;border-radius:4px;flex-shrink:0;height:12px}.koyori-gantt-skeleton-bar[data-v-73e8a554]{height:var(--v2293e8da);min-width:var(--koyori-skeleton-bar-min-w);max-width:calc(100% - var(--v43727630) - var(--koyori-skeleton-gap) - var(--koyori-skeleton-bar-min-w));background:#d1d5db;border-radius:4px;animation:1.4s ease-in-out infinite koyori-gantt-shimmer-73e8a554}@keyframes koyori-gantt-shimmer-73e8a554{0%,to{opacity:.6}50%{opacity:1}}
1
+ .koyori-gantt-scroll[data-v-05f0ec3c]{width:100%;overflow:auto}.koyori-gantt-scroll--virtual[data-v-05f0ec3c]{max-height:min(70vh,600px)}.koyori-gantt-inner[data-v-05f0ec3c]{width:100%;position:relative}.koyori-gantt-error[data-v-05f0ec3c]{color:#991b1b;padding:12px}.koyori-gantt-svg[data-v-05f0ec3c]{width:100%;position:absolute;top:0;left:0}.koyori-gantt-canvas[data-v-05f0ec3c]{display:block;position:absolute;top:0;left:0}.koyori-gantt-svg[data-v-05f0ec3c] svg{display:block}.koyori-gantt-skeleton[data-v-05f0ec3c]{--koyori-skeleton-gap:4px;--koyori-skeleton-bar-min-w:8px}.koyori-gantt-skeleton-row[data-v-05f0ec3c]{height:var(--v59cd6a8e);align-items:center;gap:var(--koyori-skeleton-gap);display:flex}.koyori-gantt-skeleton-label[data-v-05f0ec3c]{width:var(--koyori-skeleton-label-w);background:#e5e7eb;border-radius:4px;flex-shrink:0;height:12px}.koyori-gantt-skeleton-bar[data-v-05f0ec3c]{height:var(--v59c5ef75);min-width:var(--koyori-skeleton-bar-min-w);max-width:calc(100% - var(--koyori-skeleton-label-w) - var(--koyori-skeleton-gap) - var(--koyori-skeleton-bar-min-w));background:#d1d5db;border-radius:4px;animation:1.4s ease-in-out infinite koyori-gantt-shimmer-05f0ec3c}@keyframes koyori-gantt-shimmer-05f0ec3c{0%,to{opacity:.6}50%{opacity:1}}
2
2
  /*$vite$:1*/
package/dist/arc-vue.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { Fragment as e, computed as t, createElementBlock as n, createElementVNode as r, defineComponent as i, nextTick as a, normalizeClass as o, normalizeStyle as s, onBeforeUnmount as c, onMounted as l, openBlock as u, ref as d, renderList as ee, toDisplayString as te, useCssVars as ne, watch as f } from "vue";
2
- import p, { empty_svg_markup as re, legend_spec_json as m, render_canvas_commands as ie, render_svg as h, render_svg_error as ae } from "@koyori-app/arc";
2
+ import p, { empty_svg_markup as re, legend_spec_json as ie, render_canvas_commands as ae, render_svg as oe, render_svg_error as se } from "@koyori-app/arc";
3
3
  //#region src/replayCommands.ts
4
- var g = [
4
+ var ce = [
5
5
  "BarBg",
6
6
  "TierLow",
7
7
  "TierMid",
@@ -14,14 +14,47 @@ var g = [
14
14
  "HeaderBg",
15
15
  "GridLabel",
16
16
  "ProgressTextOnFg",
17
- "ProgressTextOnBg"
18
- ];
19
- function _(e, t) {
17
+ "ProgressTextOnBg",
18
+ "GroupRow",
19
+ "Weekend",
20
+ "BarStroke",
21
+ "DoneBg",
22
+ "DoneStroke",
23
+ "WarnBg",
24
+ "WarnStroke",
25
+ "HardDeadline",
26
+ "Note",
27
+ "NoteBg",
28
+ "ProgressLine"
29
+ ], le = {
30
+ GroupRow: "HeaderBg",
31
+ Weekend: "HeaderBg",
32
+ BarStroke: "GridLabel",
33
+ DoneBg: "BarBg",
34
+ DoneStroke: "GridLabel",
35
+ WarnBg: "BarBg",
36
+ WarnStroke: "Progress",
37
+ HardDeadline: "Progress",
38
+ Note: "GridLabel",
39
+ NoteBg: "HeaderBg",
40
+ ProgressLine: "Progress"
41
+ };
42
+ function m(e, t) {
43
+ let n = e.palette.colors.find(([e]) => e === t);
44
+ if (n) return n[1];
45
+ let r = le[t];
46
+ return r ? m(e, r) : void 0;
47
+ }
48
+ function h(e, t) {
49
+ let n = /^var\((--[A-Za-z0-9_-]+)\)$/.exec(e);
50
+ return n ? !t || typeof getComputedStyle > "u" ? "#000000" : getComputedStyle(t).getPropertyValue(n[1]).trim() || "#000000" : e;
51
+ }
52
+ function g(e, t, n) {
20
53
  if (t === 255) return "#374151";
21
- let n = g[t];
22
- return n ? e.palette.colors.find(([e]) => e === n)?.[1] ?? "#000000" : "#000000";
54
+ let r = ce[t];
55
+ return r ? h(m(e, r) ?? "#000000", n) : "#000000";
23
56
  }
24
- function v(e, t, n, r, i) {
57
+ function _(e, t, n, r, i) {
25
58
  if (r <= 0 || i <= 0) return e;
26
59
  let a = t + r, o = n + i;
27
60
  if (e.w === 0 && e.h === 0) return {
@@ -38,20 +71,20 @@ function v(e, t, n, r, i) {
38
71
  h: u - c
39
72
  };
40
73
  }
41
- function y(e, t, n, r, i, a) {
74
+ function v(e, t, n, r, i, a) {
42
75
  if (a > 0 && typeof e.roundRect == "function") {
43
76
  e.beginPath(), e.roundRect(t, n, r, i, a), e.fill();
44
77
  return;
45
78
  }
46
79
  e.fillRect(t, n, r, i);
47
80
  }
48
- function b(e, t, n, r, i) {
49
- if (e.strokeStyle = _(t, n), e.lineWidth = r, i) {
81
+ function y(e, t, n, r, i) {
82
+ if (e.strokeStyle = g(t, n, e.canvas), e.lineWidth = r, i) {
50
83
  let t = i.split(",").map((e) => Number.parseFloat(e.trim()));
51
84
  e.setLineDash(t.every(Number.isFinite) ? t : []);
52
85
  } else e.setLineDash([]);
53
86
  }
54
- function x(e, t) {
87
+ function b(e, t) {
55
88
  let n = [], r = null, i = {
56
89
  x: 0,
57
90
  y: 0,
@@ -86,23 +119,23 @@ function x(e, t) {
86
119
  }
87
120
  if ("FillRect" in a) {
88
121
  let { x: n, y: o, w: s, h: c, color_id: l, radius: u } = a.FillRect;
89
- e.fillStyle = _(t, l), y(e, n, o, s, c, u), r && (i = v(i, n, o, s, c));
122
+ e.fillStyle = g(t, l, e.canvas), v(e, n, o, s, c, u), r && (i = _(i, n, o, s, c));
90
123
  continue;
91
124
  }
92
125
  if ("FillPolygon" in a) {
93
126
  let { points: n, color_id: o } = a.FillPolygon;
94
127
  if (n.length === 0) continue;
95
- e.fillStyle = _(t, o), e.beginPath(), e.moveTo(n[0][0], n[0][1]);
128
+ e.fillStyle = g(t, o, e.canvas), e.beginPath(), e.moveTo(n[0][0], n[0][1]);
96
129
  for (let t = 1; t < n.length; t++) e.lineTo(n[t][0], n[t][1]);
97
130
  if (e.closePath(), e.fill(), r && n.length > 0) {
98
131
  let e = n.map((e) => e[0]), t = n.map((e) => e[1]), r = Math.min(...e), a = Math.min(...t);
99
- i = v(i, r, a, Math.max(...e) - r, Math.max(...t) - a);
132
+ i = _(i, r, a, Math.max(...e) - r, Math.max(...t) - a);
100
133
  }
101
134
  continue;
102
135
  }
103
136
  if ("StrokePath" in a) {
104
137
  let { d: n, color_id: r, width: i } = a.StrokePath;
105
- b(e, t, r, i, null);
138
+ y(e, t, r, i, null);
106
139
  let o = new Path2D(n);
107
140
  e.stroke(o);
108
141
  continue;
@@ -110,19 +143,19 @@ function x(e, t) {
110
143
  if ("StrokePolyline" in a) {
111
144
  let { points: n, color_id: r, width: i, dash: o } = a.StrokePolyline;
112
145
  if (n.length < 2) continue;
113
- b(e, t, r, i, o), e.beginPath(), e.moveTo(n[0][0], n[0][1]);
146
+ y(e, t, r, i, o), e.beginPath(), e.moveTo(n[0][0], n[0][1]);
114
147
  for (let t = 1; t < n.length; t++) e.lineTo(n[t][0], n[t][1]);
115
148
  e.stroke();
116
149
  continue;
117
150
  }
118
151
  if ("DrawText" in a) {
119
152
  let { x: n, y: r, text: i, color_id: o, anchor: s, size: c, weight: l } = a.DrawText;
120
- e.fillStyle = _(t, o), e.font = `${l} ${c}px sans-serif`, e.textBaseline = "alphabetic", s === 1 ? e.textAlign = "center" : s === 2 ? e.textAlign = "end" : e.textAlign = "start", e.fillText(i, n, r), e.textAlign = "start";
153
+ e.fillStyle = g(t, o, e.canvas), e.font = `${l} ${c}px sans-serif`, e.textBaseline = "alphabetic", s === 1 ? e.textAlign = "center" : s === 2 ? e.textAlign = "end" : e.textAlign = "start", e.fillText(i, n, r), e.textAlign = "start";
121
154
  }
122
155
  }
123
156
  return { hitRegions: n };
124
157
  }
125
- function oe(e) {
158
+ function ue(e) {
126
159
  try {
127
160
  return JSON.parse(e);
128
161
  } catch {
@@ -135,7 +168,7 @@ function oe(e) {
135
168
  };
136
169
  }
137
170
  }
138
- function S(e, t, n) {
171
+ function de(e, t, n) {
139
172
  for (let r = e.length - 1; r >= 0; r--) {
140
173
  let i = e[r];
141
174
  if (t >= i.x && t <= i.x + i.w && n >= i.y && n <= i.y + i.h) return i.taskId;
@@ -144,34 +177,39 @@ function S(e, t, n) {
144
177
  }
145
178
  //#endregion
146
179
  //#region src/canvasLifecycle.ts
147
- function se(e) {
180
+ function fe(e) {
148
181
  if (!e) return;
149
182
  let t = e.getContext("2d");
150
183
  t && t.clearRect(0, 0, e.width, e.height), e.width = 0, e.height = 0, e.style.width = "0px", e.style.height = "0px";
151
184
  }
152
185
  //#endregion
153
186
  //#region src/options.ts
154
- function C(e) {
187
+ function pe(e) {
155
188
  let t = {};
156
- return e.today != null && (t.today = e.today), e.scrollViewport != null && (t.scroll_viewport = e.scrollViewport), e.tzOffsetMinutes != null && (t.tz_offset_minutes = Number.isFinite(e.tzOffsetMinutes) ? e.tzOffsetMinutes : String(e.tzOffsetMinutes)), e.legend != null && (t.legend = e.legend), Object.keys(t).length === 0 ? void 0 : JSON.stringify(t);
189
+ return e.today != null && (t.today = e.today), e.scrollViewport != null && (t.scroll_viewport = e.scrollViewport), e.tzOffsetMinutes != null && (t.tz_offset_minutes = Number.isFinite(e.tzOffsetMinutes) ? e.tzOffsetMinutes : String(e.tzOffsetMinutes)), e.legend != null && (t.legend = e.legend), e.rowLabels != null && (t.row_labels = e.rowLabels), e.percentLabels != null && (t.percent_labels = e.percentLabels), e.rowHeightPx != null && (t.row_height_px = e.rowHeightPx), e.headerHeightPx != null && (t.header_height_px = e.headerHeightPx), e.barHeightPx != null && (t.bar_height_px = e.barHeightPx), e.barAlign != null && (t.bar_align = e.barAlign), e.palette != null && (t.palette = e.palette), e.pxPerDay != null && (t.px_per_day = e.pxPerDay), e.scale != null && (t.scale = e.scale), e.weekendDays != null && (t.weekend_days = e.weekendDays), e.weekdayLabels != null && (t.weekday_labels = e.weekdayLabels), e.view != null && (t.view = {
190
+ from: e.view.from,
191
+ to: e.view.to
192
+ }), e.progressLine != null && (t.progress_line = e.progressLine), Object.keys(t).length === 0 ? void 0 : JSON.stringify(t);
157
193
  }
158
- var w = {
194
+ var x = {
159
195
  CODE_CANVAS_CAPACITY: "canvas_capacity",
160
196
  CODE_INPUT_LIMIT: "input_limit",
161
197
  CODE_PARSE_ERROR: "parse_error",
162
198
  CODE_SERIALIZE_ERROR: "serialize_error"
163
- }.CODE_CANVAS_CAPACITY, ce = "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"0\" height=\"0\" viewBox=\"0 0 0 0\" role=\"img\" aria-label=\"Empty Gantt chart\" font-family=\"sans-serif\" font-size=\"12\"><title>Empty Gantt chart</title><desc>No tasks to display</desc></svg>", T = {
199
+ }.CODE_CANVAS_CAPACITY, me = "<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"0\" height=\"0\" viewBox=\"0 0 0 0\" role=\"img\" aria-label=\"Empty Gantt chart\" font-family=\"sans-serif\" font-size=\"12\"><title>Empty Gantt chart</title><desc>No tasks to display</desc></svg>", S = {
164
200
  ROW_H: 40,
165
201
  HEADER_H: 30,
202
+ DAY_SCALE_HEADER_H: 48,
166
203
  LEGEND_H: 40,
167
204
  CHART_BOTTOM_PADDING_PX: 10,
168
205
  LABEL_W: 120,
169
- BAR_H: 20
170
- }, E = {
206
+ BAR_H: 20,
207
+ HIDDEN_LABELS_LEFT_PX: 10
208
+ }, C = {
171
209
  MAX_CANVAS_SIDE_PX: 16384,
172
210
  MAX_CANVAS_AREA_PX: 32 * 1024 * 1024
173
211
  };
174
- function le(e) {
212
+ function he(e) {
175
213
  try {
176
214
  let t = JSON.parse(e);
177
215
  return {
@@ -184,19 +222,19 @@ function le(e) {
184
222
  }
185
223
  //#endregion
186
224
  //#region src/canvasScale.ts
187
- function D(e, t, n) {
225
+ function w(e, t, n) {
188
226
  if (!(e > 0) || !(t > 0) || !(n > 0) || !Number.isFinite(n)) return 1;
189
- let { MAX_CANVAS_SIDE_PX: r, MAX_CANVAS_AREA_PX: i } = E, a = Math.min(r / e, r / t, Math.sqrt(i / (e * t)));
227
+ let { MAX_CANVAS_SIDE_PX: r, MAX_CANVAS_AREA_PX: i } = C, a = Math.min(r / e, r / t, Math.sqrt(i / (e * t)));
190
228
  return Math.min(n, a);
191
229
  }
192
- function ue(e, t, n) {
193
- let r = D(e, t, n);
230
+ function ge(e, t, n) {
231
+ let r = w(e, t, n);
194
232
  return {
195
233
  width: Math.floor(e * r),
196
234
  height: Math.floor(t * r)
197
235
  };
198
236
  }
199
- function de(e, t, n, r, i) {
237
+ function _e(e, t, n, r, i) {
200
238
  return !(n.width > 0) || !(n.height > 0) ? null : {
201
239
  x: (e - n.left) * (r / n.width),
202
240
  y: (t - n.top) * (i / n.height)
@@ -204,17 +242,22 @@ function de(e, t, n, r, i) {
204
242
  }
205
243
  //#endregion
206
244
  //#region src/canvasFallback.ts
207
- function fe(e, t = "shown") {
208
- return e === 0 ? 0 : e * T.ROW_H + T.HEADER_H + (t === "hidden" ? 0 : T.LEGEND_H) + T.CHART_BOTTOM_PADDING_PX;
245
+ function T(e = {}) {
246
+ return e.headerHeight == null ? e.scale === "day" ? S.DAY_SCALE_HEADER_H : S.HEADER_H : e.headerHeight;
209
247
  }
210
- function O(e) {
211
- return e.code === w;
248
+ function ve(e, t, n = "shown", r = {}) {
249
+ if (t === 0) return 0;
250
+ let i = r.rowHeight ?? S.ROW_H;
251
+ return (e ? e.reduce((e, t) => e + (t.height ?? i), 0) : t * i) + T(r) + (n === "hidden" ? 0 : S.LEGEND_H) + S.CHART_BOTTOM_PADDING_PX;
212
252
  }
213
- function k(e, t) {
253
+ function ye(e) {
254
+ return e.code === x;
255
+ }
256
+ function E(e, t) {
214
257
  return e.startsWith("<svg ") && e !== t;
215
258
  }
216
- function pe(e, t, n) {
217
- return O(e) && k(t, n) ? {
259
+ function be(e, t, n) {
260
+ return ye(e) && E(t, n) ? {
218
261
  mode: "svg",
219
262
  svg: t
220
263
  } : {
@@ -222,17 +265,17 @@ function pe(e, t, n) {
222
265
  message: e.message
223
266
  };
224
267
  }
268
+ function xe(e, t) {
269
+ let n = (t ?? S.BAR_H) / 2;
270
+ return e === "hidden" ? n : Math.max(S.LABEL_W, n);
271
+ }
225
272
  //#endregion
226
273
  //#region src/GanttChart.vue?vue&type=script&setup=true&lang.ts
227
- var me = {
228
- key: 0,
229
- class: "koyori-gantt-skeleton",
230
- "aria-hidden": "true"
231
- }, he = {
274
+ var Se = {
232
275
  key: 0,
233
276
  class: "koyori-gantt-error",
234
277
  role: "alert"
235
- }, ge = ["innerHTML"], A = /*#__PURE__*/ ((e, t) => {
278
+ }, Ce = ["innerHTML"], D = /*#__PURE__*/ ((e, t) => {
236
279
  let n = e.__vccOpts || e;
237
280
  for (let [e, r] of t) n[e] = r;
238
281
  return n;
@@ -244,191 +287,254 @@ var me = {
244
287
  today: {},
245
288
  tzOffsetMinutes: {},
246
289
  legend: {},
290
+ rowLabels: {},
291
+ percentLabels: {},
292
+ rows: {},
293
+ rowHeight: {},
294
+ headerHeight: {},
295
+ barHeight: {},
296
+ barAlign: {},
297
+ palette: {},
298
+ pxPerDay: {},
299
+ scale: {},
300
+ weekendDays: {},
301
+ weekdayLabels: {},
302
+ view: {},
303
+ progressLine: {},
247
304
  backend: {},
248
305
  deviceTier: {}
249
306
  },
250
307
  emits: ["taskClick"],
251
- setup(i, { emit: m }) {
308
+ setup(i, { expose: ie, emit: ce }) {
252
309
  ne((e) => ({
253
- v229b63f3: g,
254
- v43727630: _,
255
- v2293e8da: v
310
+ v59cd6a8e: le.value,
311
+ v59c5ef75: h
256
312
  }));
257
- let g = `${T.ROW_H}px`, _ = `${T.LABEL_W}px`, v = `${T.BAR_H}px`, y = i, b = m, w = d(!1), E = d(""), D = d(0), k = d(600), A = d(null), j = d(null), M = d([]), N = d(""), P = d(""), F = d(null), I = {
313
+ let le = t(() => `${g.rowHeight ?? S.ROW_H}px`), m = t(() => `${xe(g.rowLabels, g.barHeight)}px`), h = `${S.BAR_H}px`, g = i, _ = ce, v = d(!1), y = d(""), x = d(0), C = d(600), w = d(null), T = d(null), E = d([]), D = d(""), O = d(""), k = d(null), A = {
258
314
  width: 0,
259
315
  height: 0
260
- }, L = d(ce), R = t(() => y.backend === "canvas");
261
- function z(e) {
262
- let t = e ?? A.value;
263
- t && (D.value = t.scrollTop, k.value = t.clientHeight);
316
+ }, j = d(me), M = t(() => g.backend === "canvas");
317
+ function N(e) {
318
+ let t = e ?? w.value;
319
+ t && (x.value = t.scrollTop, C.value = t.clientHeight);
264
320
  }
265
321
  l(async () => {
266
- await p(), L.value = re(), w.value = !0, await a(), z(), B.value && (V.value = !0);
322
+ await p(), j.value = re(), v.value = !0, await a(), N(), P.value && (F.value = !0);
267
323
  });
268
- function _e() {
269
- if (y.deviceTier) return y.deviceTier;
324
+ function we() {
325
+ if (g.deviceTier) return g.deviceTier;
270
326
  if (typeof navigator > "u") return "low";
271
327
  let e = navigator;
272
328
  return e.deviceMemory === void 0 || e.deviceMemory <= 4 || navigator.hardwareConcurrency <= 4 ? "low" : "high";
273
329
  }
274
- let ve = t(() => _e()), B = t(() => ve.value === "low"), V = d(!1);
275
- f(B, async (e) => {
330
+ let Te = t(() => we()), P = t(() => Te.value === "low"), F = d(!1);
331
+ f(P, async (e) => {
276
332
  if (!e) {
277
- V.value = !1;
333
+ F.value = !1;
278
334
  return;
279
335
  }
280
- V.value = !1, await a(), z(), V.value = !0;
336
+ F.value = !1, await a(), N(), F.value = !0;
281
337
  }, { flush: "post" });
282
- let ye = t(() => K.value ? 0 : fe(y.tasks.length, y.legend)), be = t(() => {
283
- if (!(!B.value || !V.value)) return {
284
- scroll_y: D.value,
285
- client_height: k.value
338
+ let Ee = t(() => z.value ? 0 : ve(g.rows, g.tasks.length, g.legend, {
339
+ rowHeight: g.rowHeight,
340
+ headerHeight: g.headerHeight,
341
+ scale: g.scale
342
+ })), De = t(() => {
343
+ if (!(!P.value || !F.value)) return {
344
+ scroll_y: x.value,
345
+ client_height: C.value
286
346
  };
287
- }), H = t(() => C({
288
- today: y.today,
289
- scrollViewport: be.value,
290
- tzOffsetMinutes: y.tzOffsetMinutes,
291
- legend: y.legend
292
- })), U = t(() => B.value && !V.value), W = t(() => !w.value || y.tasks.length === 0 || R.value ? "" : U.value ? null : h(JSON.stringify(y.tasks), JSON.stringify(y.deps ?? []), H.value)), G = t(() => !w.value || y.tasks.length === 0 || !R.value || U.value ? "" : ie(JSON.stringify(y.tasks), JSON.stringify(y.deps ?? []), H.value));
293
- f(W, (e) => {
294
- e !== null && (E.value = e);
347
+ });
348
+ function Oe(e) {
349
+ return pe({
350
+ today: g.today,
351
+ scrollViewport: e,
352
+ tzOffsetMinutes: g.tzOffsetMinutes,
353
+ legend: g.legend,
354
+ rowLabels: g.rowLabels,
355
+ percentLabels: g.percentLabels,
356
+ rowHeightPx: g.rowHeight,
357
+ headerHeightPx: g.headerHeight,
358
+ barHeightPx: g.barHeight,
359
+ barAlign: g.barAlign,
360
+ palette: g.palette,
361
+ pxPerDay: g.pxPerDay,
362
+ scale: g.scale,
363
+ weekendDays: g.weekendDays,
364
+ weekdayLabels: g.weekdayLabels,
365
+ view: g.view,
366
+ progressLine: g.progressLine
367
+ });
368
+ }
369
+ let I = t(() => Oe(De.value)), L = t(() => g.rows ? [JSON.stringify(g.rows)] : []), ke = t(() => P.value && !F.value), Ae = t(() => !v.value || g.tasks.length === 0 || M.value ? "" : ke.value ? null : oe(JSON.stringify(g.tasks), JSON.stringify(g.deps ?? []), I.value, ...L.value)), R = t(() => !v.value || g.tasks.length === 0 || !M.value || ke.value ? "" : ae(JSON.stringify(g.tasks), JSON.stringify(g.deps ?? []), I.value, ...L.value));
370
+ f(Ae, (e) => {
371
+ e !== null && (y.value = e);
295
372
  }, { immediate: !0 });
296
- let xe = t(() => {
297
- if (!w.value || y.tasks.length === 0 || R.value || W.value !== L.value) return null;
298
- let e = ae(JSON.stringify(y.tasks), JSON.stringify(y.deps ?? []), H.value);
299
- return e ? le(e) : null;
300
- }), K = t(() => P.value || xe.value?.message || "");
301
- function q(e) {
302
- M.value = [], se(e);
373
+ let je = t(() => {
374
+ if (!v.value || g.tasks.length === 0 || M.value || Ae.value !== j.value) return null;
375
+ let e = se(JSON.stringify(g.tasks), JSON.stringify(g.deps ?? []), I.value, ...L.value);
376
+ return e ? he(e) : null;
377
+ }), z = t(() => O.value || je.value?.message || "");
378
+ function B(e) {
379
+ E.value = [], fe(e);
303
380
  }
304
- function J() {
305
- N.value = "", P.value = "", F.value = null;
381
+ function V() {
382
+ D.value = "", O.value = "", k.value = null;
306
383
  }
307
- function Y(e) {
308
- F.value = e;
384
+ function Me(e) {
385
+ k.value = e;
309
386
  let t = "";
310
- if (O(e)) try {
311
- t = h(JSON.stringify(y.tasks), JSON.stringify(y.deps ?? []), C({
312
- today: y.today,
313
- scrollViewport: {
314
- scroll_y: D.value,
315
- client_height: Math.min(k.value, 600)
316
- },
317
- tzOffsetMinutes: y.tzOffsetMinutes,
318
- legend: y.legend
319
- }));
387
+ if (ye(e)) try {
388
+ t = oe(JSON.stringify(g.tasks), JSON.stringify(g.deps ?? []), Oe({
389
+ scroll_y: x.value,
390
+ client_height: Math.min(C.value, 600)
391
+ }), ...L.value);
320
392
  } catch {}
321
- let n = pe(e, t, L.value);
322
- n.mode === "svg" ? (N.value = n.svg, P.value = "") : (N.value = "", P.value = n.message);
393
+ let n = be(e, t, j.value);
394
+ n.mode === "svg" ? (D.value = n.svg, O.value = "") : (D.value = "", O.value = n.message);
323
395
  }
324
- f([D, k], () => {
325
- N.value && F.value && Y(F.value);
396
+ f([x, C], () => {
397
+ D.value && k.value && Me(k.value);
326
398
  });
327
- async function Se() {
328
- let e = G.value;
399
+ async function H() {
400
+ let e = R.value;
329
401
  if (!e) {
330
- q(j.value), J();
402
+ B(T.value), V();
331
403
  return;
332
404
  }
333
- let t = j.value;
334
- if (!t && (J(), await a(), t = j.value, !t)) return;
335
- let n = oe(e);
405
+ let t = T.value;
406
+ if (!t && (V(), await a(), t = T.value, !t)) return;
407
+ let n = ue(e);
336
408
  if (n.error) {
337
- q(t), Y({
409
+ B(t), Me({
338
410
  message: n.error,
339
411
  code: n.code
340
412
  });
341
413
  return;
342
414
  }
343
- J();
344
- let r = n.viewport_width, i = n.viewport_height, o = ue(r, i, X.value);
345
- t.width = o.width, t.height = o.height, t.style.width = `${r}px`, t.style.height = `${i}px`, I = {
415
+ V();
416
+ let r = n.viewport_width, i = n.viewport_height, o = ge(r, i, U.value);
417
+ t.width = o.width, t.height = o.height, t.style.width = `${r}px`, t.style.height = `${i}px`, A = {
346
418
  width: r,
347
419
  height: i
348
420
  };
349
421
  let s = t.getContext("2d");
350
422
  if (!s) {
351
- q(t);
423
+ B(t);
352
424
  return;
353
425
  }
354
- r > 0 && i > 0 && s.setTransform(o.width / r, 0, 0, o.height / i, 0, 0), M.value = x(s, n).hitRegions;
426
+ r > 0 && i > 0 && s.setTransform(o.width / r, 0, 0, o.height / i, 0, 0), E.value = b(s, n).hitRegions;
355
427
  }
356
- f(G, () => {
357
- a().then(Se);
428
+ f(R, () => {
429
+ a().then(H);
358
430
  }, { immediate: !0 });
359
- let X = d(Q()), Z = null;
360
- function Q() {
431
+ let U = d(G()), W = null;
432
+ function G() {
361
433
  return typeof window > "u" ? 1 : window.devicePixelRatio || 1;
362
434
  }
363
- function Ce() {
364
- Z?.removeEventListener("change", $), Z = null;
435
+ function Ne() {
436
+ W?.removeEventListener("change", Fe), W = null;
365
437
  }
366
- function we() {
367
- Ce(), !(typeof window > "u" || typeof window.matchMedia != "function") && (Z = window.matchMedia(`(resolution: ${Q()}dppx)`), Z.addEventListener("change", $));
438
+ function Pe() {
439
+ Ne(), !(typeof window > "u" || typeof window.matchMedia != "function") && (W = window.matchMedia(`(resolution: ${G()}dppx)`), W.addEventListener("change", Fe));
368
440
  }
369
- function $() {
370
- X.value = Q(), we();
441
+ function Fe() {
442
+ U.value = G(), Pe();
371
443
  }
372
- l(we), c(Ce), f(X, () => {
373
- j.value && G.value && Se();
444
+ l(Pe), c(Ne), f(U, () => {
445
+ T.value && R.value && H();
374
446
  });
375
- function Te(e) {
376
- z(e.target);
447
+ let K = d(null), Ie = t(() => Object.values(g.palette ?? {}).some((e) => typeof e == "string" && e.includes("var("))), q = t(() => M.value && !D.value && Ie.value), J = null, Y = null, X = 0;
448
+ function Z() {
449
+ if (X) return;
450
+ let e = () => {
451
+ X = 0, T.value && R.value && H();
452
+ };
453
+ typeof requestAnimationFrame == "function" ? X = requestAnimationFrame(e) : e();
454
+ }
455
+ function Le(e) {
456
+ return e === "class" || e === "style" || (e?.startsWith("data-") ?? !1);
377
457
  }
378
- function Ee(e) {
458
+ function Q() {
459
+ J?.removeEventListener("change", Z), J = null, Y?.disconnect(), Y = null;
460
+ }
461
+ function $() {
462
+ if (Q(), !(typeof window > "u" || !q.value) && (typeof window.matchMedia == "function" && (J = window.matchMedia("(prefers-color-scheme: dark)"), J.addEventListener("change", Z)), typeof MutationObserver < "u" && K.value)) {
463
+ Y = new MutationObserver((e) => {
464
+ e.some((e) => Le(e.attributeName)) && Z();
465
+ });
466
+ for (let e = K.value.parentElement; e; e = e.parentElement) Y.observe(e, { attributes: !0 });
467
+ }
468
+ }
469
+ l($), f(q, $), f(() => g.palette, () => {
470
+ $(), M.value && Z();
471
+ }), c(() => {
472
+ Q(), X && typeof cancelAnimationFrame == "function" && cancelAnimationFrame(X), X = 0;
473
+ }), ie({ repaint: Z });
474
+ function Re(e) {
475
+ N(e.target);
476
+ }
477
+ function ze(e) {
379
478
  let t = e.target.closest("[data-task-id]");
380
479
  if (!t) return;
381
- let n = t.getAttribute("data-task-id"), r = y.tasks.find((e) => e.id === n);
382
- r && b("taskClick", r);
480
+ let n = t.getAttribute("data-task-id"), r = g.tasks.find((e) => e.id === n);
481
+ r && _("taskClick", r);
383
482
  }
384
- function De(e) {
385
- let t = j.value;
483
+ function Be(e) {
484
+ let t = T.value;
386
485
  if (!t) return;
387
- let n = de(e.clientX, e.clientY, t.getBoundingClientRect(), I.width, I.height);
486
+ let n = _e(e.clientX, e.clientY, t.getBoundingClientRect(), A.width, A.height);
388
487
  if (!n) return;
389
- let r = S(M.value, n.x, n.y);
488
+ let r = de(E.value, n.x, n.y);
390
489
  if (!r) return;
391
- let i = y.tasks.find((e) => e.id === r);
392
- i && b("taskClick", i);
490
+ let i = g.tasks.find((e) => e.id === r);
491
+ i && _("taskClick", i);
393
492
  }
394
493
  return (t, i) => (u(), n("div", {
494
+ ref_key: "rootRef",
495
+ ref: K,
395
496
  class: "koyori-gantt",
396
- onClick: i[0] ||= (e) => (!R.value || N.value) && Ee(e)
397
- }, [w.value ? (u(), n("div", {
497
+ onClick: i[0] ||= (e) => (!M.value || D.value) && ze(e)
498
+ }, [v.value ? (u(), n("div", {
398
499
  key: 1,
399
500
  ref_key: "scrollRef",
400
- ref: A,
401
- class: o(["koyori-gantt-scroll", { "koyori-gantt-scroll--virtual": B.value || F.value }]),
402
- onScroll: Te
403
- }, [K.value ? (u(), n("div", he, " Unable to render Gantt chart: " + te(K.value), 1)) : (u(), n("div", {
501
+ ref: w,
502
+ class: o(["koyori-gantt-scroll", { "koyori-gantt-scroll--virtual": P.value || k.value }]),
503
+ onScroll: Re
504
+ }, [z.value ? (u(), n("div", Se, " Unable to render Gantt chart: " + te(z.value), 1)) : (u(), n("div", {
404
505
  key: 1,
405
506
  class: "koyori-gantt-inner",
406
- style: s({ height: `${ye.value}px` })
407
- }, [R.value && !N.value ? (u(), n("canvas", {
507
+ style: s({ height: `${Ee.value}px` })
508
+ }, [M.value && !D.value ? (u(), n("canvas", {
408
509
  key: 0,
409
510
  ref_key: "canvasRef",
410
- ref: j,
511
+ ref: T,
411
512
  class: "koyori-gantt-canvas",
412
513
  role: "img",
413
514
  "aria-label": "Gantt chart",
414
- onClick: De
515
+ onClick: Be
415
516
  }, null, 512)) : (u(), n("div", {
416
517
  key: 1,
417
518
  class: "koyori-gantt-svg",
418
- innerHTML: N.value || E.value
419
- }, null, 8, ge))], 4))], 34)) : (u(), n("div", me, [(u(!0), n(e, null, ee(y.tasks, (e) => (u(), n("div", {
519
+ innerHTML: D.value || y.value
520
+ }, null, 8, Ce))], 4))], 34)) : (u(), n("div", {
521
+ key: 0,
522
+ class: "koyori-gantt-skeleton",
523
+ style: s({ "--koyori-skeleton-label-w": m.value }),
524
+ "aria-hidden": "true"
525
+ }, [(u(!0), n(e, null, ee(g.tasks, (e) => (u(), n("div", {
420
526
  key: e.id,
421
527
  class: "koyori-gantt-skeleton-row"
422
528
  }, [i[1] ||= r("div", { class: "koyori-gantt-skeleton-label" }, null, -1), r("div", {
423
529
  class: "koyori-gantt-skeleton-bar",
424
530
  style: s({ width: `${e.progress_pct}%` })
425
- }, null, 4)]))), 128))]))]));
531
+ }, null, 4)]))), 128))], 4))], 512));
426
532
  }
427
- }), [["__scopeId", "data-v-73e8a554"]]);
533
+ }), [["__scopeId", "data-v-05f0ec3c"]]);
428
534
  //#endregion
429
535
  //#region src/legend.ts
430
- async function j() {
431
- return await p(), JSON.parse(m());
536
+ async function O() {
537
+ return await p(), JSON.parse(ie());
432
538
  }
433
539
  //#endregion
434
- export { A as GanttChart, S as findTaskAtPoint, j as loadLegendSpec, oe as parseCommandBuffer, x as replayCommands };
540
+ export { D as GanttChart, de as findTaskAtPoint, O as loadLegendSpec, ue as parseCommandBuffer, b as replayCommands };
@@ -1 +1 @@
1
- (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("vue"),require("@koyori-app/arc")):typeof define==`function`&&define.amd?define([`exports`,`vue`,`@koyori-app/arc`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.ArcVue={},e.Vue,e.KoyoriArc))})(this,function(e,t,n){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var r=Object.create,i=Object.defineProperty,a=Object.getOwnPropertyDescriptor,o=Object.getOwnPropertyNames,s=Object.getPrototypeOf,c=Object.prototype.hasOwnProperty,l=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var s=o(t),l=0,u=s.length,d;l<u;l++)d=s[l],!c.call(e,d)&&d!==n&&i(e,d,{get:(e=>t[e]).bind(null,d),enumerable:!(r=a(t,d))||r.enumerable});return e};n=((e,t,n)=>(n=e==null?{}:r(s(e)),l(t||!e||!e.__esModule?i(n,`default`,{value:e,enumerable:!0}):n,e)))(n,1);var u=[`BarBg`,`TierLow`,`TierMid`,`TierHigh`,`TierDone`,`Dep`,`Progress`,`Grid`,`Today`,`HeaderBg`,`GridLabel`,`ProgressTextOnFg`,`ProgressTextOnBg`];function d(e,t){if(t===255)return`#374151`;let n=u[t];return n?e.palette.colors.find(([e])=>e===n)?.[1]??`#000000`:`#000000`}function f(e,t,n,r,i){if(r<=0||i<=0)return e;let a=t+r,o=n+i;if(e.w===0&&e.h===0)return{x:t,y:n,w:r,h:i};let s=Math.min(e.x,t),c=Math.min(e.y,n),l=Math.max(e.x+e.w,a),u=Math.max(e.y+e.h,o);return{x:s,y:c,w:l-s,h:u-c}}function p(e,t,n,r,i,a){if(a>0&&typeof e.roundRect==`function`){e.beginPath(),e.roundRect(t,n,r,i,a),e.fill();return}e.fillRect(t,n,r,i)}function m(e,t,n,r,i){if(e.strokeStyle=d(t,n),e.lineWidth=r,i){let t=i.split(`,`).map(e=>Number.parseFloat(e.trim()));e.setLineDash(t.every(Number.isFinite)?t:[])}else e.setLineDash([])}function h(e,t){let n=[],r=null,i={x:0,y:0,w:0,h:0};e.clearRect(0,0,t.viewport_width,t.viewport_height);for(let a of t.ops){if(a===`GroupEnd`){r&&i.w>0&&i.h>0&&n.push({taskId:r,x:i.x,y:i.y,w:i.w,h:i.h}),r=null,i={x:0,y:0,w:0,h:0};continue}if(`GroupStart`in a){r=a.GroupStart.task_id,i={x:0,y:0,w:0,h:0};continue}if(`FillRect`in a){let{x:n,y:o,w:s,h:c,color_id:l,radius:u}=a.FillRect;e.fillStyle=d(t,l),p(e,n,o,s,c,u),r&&(i=f(i,n,o,s,c));continue}if(`FillPolygon`in a){let{points:n,color_id:o}=a.FillPolygon;if(n.length===0)continue;e.fillStyle=d(t,o),e.beginPath(),e.moveTo(n[0][0],n[0][1]);for(let t=1;t<n.length;t++)e.lineTo(n[t][0],n[t][1]);if(e.closePath(),e.fill(),r&&n.length>0){let e=n.map(e=>e[0]),t=n.map(e=>e[1]),r=Math.min(...e),a=Math.min(...t);i=f(i,r,a,Math.max(...e)-r,Math.max(...t)-a)}continue}if(`StrokePath`in a){let{d:n,color_id:r,width:i}=a.StrokePath;m(e,t,r,i,null);let o=new Path2D(n);e.stroke(o);continue}if(`StrokePolyline`in a){let{points:n,color_id:r,width:i,dash:o}=a.StrokePolyline;if(n.length<2)continue;m(e,t,r,i,o),e.beginPath(),e.moveTo(n[0][0],n[0][1]);for(let t=1;t<n.length;t++)e.lineTo(n[t][0],n[t][1]);e.stroke();continue}if(`DrawText`in a){let{x:n,y:r,text:i,color_id:o,anchor:s,size:c,weight:l}=a.DrawText;e.fillStyle=d(t,o),e.font=`${l} ${c}px sans-serif`,e.textBaseline=`alphabetic`,s===1?e.textAlign=`center`:s===2?e.textAlign=`end`:e.textAlign=`start`,e.fillText(i,n,r),e.textAlign=`start`}}return{hitRegions:n}}function g(e){try{return JSON.parse(e)}catch{return{viewport_width:0,viewport_height:0,ops:[],palette:{colors:[]},error:`invalid json`}}}function _(e,t,n){for(let r=e.length-1;r>=0;r--){let i=e[r];if(t>=i.x&&t<=i.x+i.w&&n>=i.y&&n<=i.y+i.h)return i.taskId}return null}function v(e){if(!e)return;let t=e.getContext(`2d`);t&&t.clearRect(0,0,e.width,e.height),e.width=0,e.height=0,e.style.width=`0px`,e.style.height=`0px`}function y(e){let t={};return e.today!=null&&(t.today=e.today),e.scrollViewport!=null&&(t.scroll_viewport=e.scrollViewport),e.tzOffsetMinutes!=null&&(t.tz_offset_minutes=Number.isFinite(e.tzOffsetMinutes)?e.tzOffsetMinutes:String(e.tzOffsetMinutes)),e.legend!=null&&(t.legend=e.legend),Object.keys(t).length===0?void 0:JSON.stringify(t)}var b={CODE_CANVAS_CAPACITY:`canvas_capacity`,CODE_INPUT_LIMIT:`input_limit`,CODE_PARSE_ERROR:`parse_error`,CODE_SERIALIZE_ERROR:`serialize_error`}.CODE_CANVAS_CAPACITY,x=`<svg xmlns="http://www.w3.org/2000/svg" width="0" height="0" viewBox="0 0 0 0" role="img" aria-label="Empty Gantt chart" font-family="sans-serif" font-size="12"><title>Empty Gantt chart</title><desc>No tasks to display</desc></svg>`,S={ROW_H:40,HEADER_H:30,LEGEND_H:40,CHART_BOTTOM_PADDING_PX:10,LABEL_W:120,BAR_H:20},C={MAX_CANVAS_SIDE_PX:16384,MAX_CANVAS_AREA_PX:32*1024*1024};function w(e){try{let t=JSON.parse(e);return{message:typeof t.error==`string`?t.error:e,code:typeof t.code==`string`?t.code:void 0}}catch{return{message:e}}}function T(e,t,n){if(!(e>0)||!(t>0)||!(n>0)||!Number.isFinite(n))return 1;let{MAX_CANVAS_SIDE_PX:r,MAX_CANVAS_AREA_PX:i}=C,a=Math.min(r/e,r/t,Math.sqrt(i/(e*t)));return Math.min(n,a)}function E(e,t,n){let r=T(e,t,n);return{width:Math.floor(e*r),height:Math.floor(t*r)}}function ee(e,t,n,r,i){return!(n.width>0)||!(n.height>0)?null:{x:(e-n.left)*(r/n.width),y:(t-n.top)*(i/n.height)}}function te(e,t=`shown`){return e===0?0:e*S.ROW_H+S.HEADER_H+(t===`hidden`?0:S.LEGEND_H)+S.CHART_BOTTOM_PADDING_PX}function D(e){return e.code===b}function O(e,t){return e.startsWith(`<svg `)&&e!==t}function ne(e,t,n){return D(e)&&O(t,n)?{mode:`svg`,svg:t}:{mode:`error`,message:e.message}}var re={key:0,class:`koyori-gantt-skeleton`,"aria-hidden":`true`},ie={key:0,class:`koyori-gantt-error`,role:`alert`},ae=[`innerHTML`],k=((e,t)=>{let n=e.__vccOpts||e;for(let[e,r]of t)n[e]=r;return n})((0,t.defineComponent)({__name:`GanttChart`,props:{tasks:{},deps:{},today:{},tzOffsetMinutes:{},legend:{},backend:{},deviceTier:{}},emits:[`taskClick`],setup(e,{emit:r}){(0,t.useCssVars)(e=>({v229b63f3:i,v43727630:a,v2293e8da:o}));let i=`${S.ROW_H}px`,a=`${S.LABEL_W}px`,o=`${S.BAR_H}px`,s=e,c=r,l=(0,t.ref)(!1),u=(0,t.ref)(``),d=(0,t.ref)(0),f=(0,t.ref)(600),p=(0,t.ref)(null),m=(0,t.ref)(null),b=(0,t.ref)([]),C=(0,t.ref)(``),T=(0,t.ref)(``),O=(0,t.ref)(null),k={width:0,height:0},A=(0,t.ref)(x),j=(0,t.computed)(()=>s.backend===`canvas`);function M(e){let t=e??p.value;t&&(d.value=t.scrollTop,f.value=t.clientHeight)}(0,t.onMounted)(async()=>{await(0,n.default)(),A.value=(0,n.empty_svg_markup)(),l.value=!0,await(0,t.nextTick)(),M(),F.value&&(I.value=!0)});function N(){if(s.deviceTier)return s.deviceTier;if(typeof navigator>`u`)return`low`;let e=navigator;return e.deviceMemory===void 0||e.deviceMemory<=4||navigator.hardwareConcurrency<=4?`low`:`high`}let P=(0,t.computed)(()=>N()),F=(0,t.computed)(()=>P.value===`low`),I=(0,t.ref)(!1);(0,t.watch)(F,async e=>{if(!e){I.value=!1;return}I.value=!1,await(0,t.nextTick)(),M(),I.value=!0},{flush:`post`});let L=(0,t.computed)(()=>U.value?0:te(s.tasks.length,s.legend)),R=(0,t.computed)(()=>{if(!(!F.value||!I.value))return{scroll_y:d.value,client_height:f.value}}),z=(0,t.computed)(()=>y({today:s.today,scrollViewport:R.value,tzOffsetMinutes:s.tzOffsetMinutes,legend:s.legend})),B=(0,t.computed)(()=>F.value&&!I.value),V=(0,t.computed)(()=>!l.value||s.tasks.length===0||j.value?``:B.value?null:(0,n.render_svg)(JSON.stringify(s.tasks),JSON.stringify(s.deps??[]),z.value)),H=(0,t.computed)(()=>!l.value||s.tasks.length===0||!j.value||B.value?``:(0,n.render_canvas_commands)(JSON.stringify(s.tasks),JSON.stringify(s.deps??[]),z.value));(0,t.watch)(V,e=>{e!==null&&(u.value=e)},{immediate:!0});let oe=(0,t.computed)(()=>{if(!l.value||s.tasks.length===0||j.value||V.value!==A.value)return null;let e=(0,n.render_svg_error)(JSON.stringify(s.tasks),JSON.stringify(s.deps??[]),z.value);return e?w(e):null}),U=(0,t.computed)(()=>T.value||oe.value?.message||``);function W(e){b.value=[],v(e)}function G(){C.value=``,T.value=``,O.value=null}function K(e){O.value=e;let t=``;if(D(e))try{t=(0,n.render_svg)(JSON.stringify(s.tasks),JSON.stringify(s.deps??[]),y({today:s.today,scrollViewport:{scroll_y:d.value,client_height:Math.min(f.value,600)},tzOffsetMinutes:s.tzOffsetMinutes,legend:s.legend}))}catch{}let r=ne(e,t,A.value);r.mode===`svg`?(C.value=r.svg,T.value=``):(C.value=``,T.value=r.message)}(0,t.watch)([d,f],()=>{C.value&&O.value&&K(O.value)});async function q(){let e=H.value;if(!e){W(m.value),G();return}let n=m.value;if(!n&&(G(),await(0,t.nextTick)(),n=m.value,!n))return;let r=g(e);if(r.error){W(n),K({message:r.error,code:r.code});return}G();let i=r.viewport_width,a=r.viewport_height,o=E(i,a,J.value);n.width=o.width,n.height=o.height,n.style.width=`${i}px`,n.style.height=`${a}px`,k={width:i,height:a};let s=n.getContext(`2d`);if(!s){W(n);return}i>0&&a>0&&s.setTransform(o.width/i,0,0,o.height/a,0,0),b.value=h(s,r).hitRegions}(0,t.watch)(H,()=>{(0,t.nextTick)().then(q)},{immediate:!0});let J=(0,t.ref)(X()),Y=null;function X(){return typeof window>`u`?1:window.devicePixelRatio||1}function Z(){Y?.removeEventListener(`change`,$),Y=null}function Q(){Z(),!(typeof window>`u`||typeof window.matchMedia!=`function`)&&(Y=window.matchMedia(`(resolution: ${X()}dppx)`),Y.addEventListener(`change`,$))}function $(){J.value=X(),Q()}(0,t.onMounted)(Q),(0,t.onBeforeUnmount)(Z),(0,t.watch)(J,()=>{m.value&&H.value&&q()});function se(e){M(e.target)}function ce(e){let t=e.target.closest(`[data-task-id]`);if(!t)return;let n=t.getAttribute(`data-task-id`),r=s.tasks.find(e=>e.id===n);r&&c(`taskClick`,r)}function le(e){let t=m.value;if(!t)return;let n=ee(e.clientX,e.clientY,t.getBoundingClientRect(),k.width,k.height);if(!n)return;let r=_(b.value,n.x,n.y);if(!r)return;let i=s.tasks.find(e=>e.id===r);i&&c(`taskClick`,i)}return(e,n)=>((0,t.openBlock)(),(0,t.createElementBlock)(`div`,{class:`koyori-gantt`,onClick:n[0]||=e=>(!j.value||C.value)&&ce(e)},[l.value?((0,t.openBlock)(),(0,t.createElementBlock)(`div`,{key:1,ref_key:`scrollRef`,ref:p,class:(0,t.normalizeClass)([`koyori-gantt-scroll`,{"koyori-gantt-scroll--virtual":F.value||O.value}]),onScroll:se},[U.value?((0,t.openBlock)(),(0,t.createElementBlock)(`div`,ie,` Unable to render Gantt chart: `+(0,t.toDisplayString)(U.value),1)):((0,t.openBlock)(),(0,t.createElementBlock)(`div`,{key:1,class:`koyori-gantt-inner`,style:(0,t.normalizeStyle)({height:`${L.value}px`})},[j.value&&!C.value?((0,t.openBlock)(),(0,t.createElementBlock)(`canvas`,{key:0,ref_key:`canvasRef`,ref:m,class:`koyori-gantt-canvas`,role:`img`,"aria-label":`Gantt chart`,onClick:le},null,512)):((0,t.openBlock)(),(0,t.createElementBlock)(`div`,{key:1,class:`koyori-gantt-svg`,innerHTML:C.value||u.value},null,8,ae))],4))],34)):((0,t.openBlock)(),(0,t.createElementBlock)(`div`,re,[((0,t.openBlock)(!0),(0,t.createElementBlock)(t.Fragment,null,(0,t.renderList)(s.tasks,e=>((0,t.openBlock)(),(0,t.createElementBlock)(`div`,{key:e.id,class:`koyori-gantt-skeleton-row`},[n[1]||=(0,t.createElementVNode)(`div`,{class:`koyori-gantt-skeleton-label`},null,-1),(0,t.createElementVNode)(`div`,{class:`koyori-gantt-skeleton-bar`,style:(0,t.normalizeStyle)({width:`${e.progress_pct}%`})},null,4)]))),128))]))]))}}),[[`__scopeId`,`data-v-73e8a554`]]);async function A(){return await(0,n.default)(),JSON.parse((0,n.legend_spec_json)())}e.GanttChart=k,e.findTaskAtPoint=_,e.loadLegendSpec=A,e.parseCommandBuffer=g,e.replayCommands=h});
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("vue"),require("@koyori-app/arc")):typeof define==`function`&&define.amd?define([`exports`,`vue`,`@koyori-app/arc`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.ArcVue={},e.Vue,e.KoyoriArc))})(this,function(e,t,n){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var r=Object.create,i=Object.defineProperty,a=Object.getOwnPropertyDescriptor,o=Object.getOwnPropertyNames,s=Object.getPrototypeOf,c=Object.prototype.hasOwnProperty,l=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var s=o(t),l=0,u=s.length,d;l<u;l++)d=s[l],!c.call(e,d)&&d!==n&&i(e,d,{get:(e=>t[e]).bind(null,d),enumerable:!(r=a(t,d))||r.enumerable});return e};n=((e,t,n)=>(n=e==null?{}:r(s(e)),l(t||!e||!e.__esModule?i(n,`default`,{value:e,enumerable:!0}):n,e)))(n,1);var u=[`BarBg`,`TierLow`,`TierMid`,`TierHigh`,`TierDone`,`Dep`,`Progress`,`Grid`,`Today`,`HeaderBg`,`GridLabel`,`ProgressTextOnFg`,`ProgressTextOnBg`,`GroupRow`,`Weekend`,`BarStroke`,`DoneBg`,`DoneStroke`,`WarnBg`,`WarnStroke`,`HardDeadline`,`Note`,`NoteBg`,`ProgressLine`],d={GroupRow:`HeaderBg`,Weekend:`HeaderBg`,BarStroke:`GridLabel`,DoneBg:`BarBg`,DoneStroke:`GridLabel`,WarnBg:`BarBg`,WarnStroke:`Progress`,HardDeadline:`Progress`,Note:`GridLabel`,NoteBg:`HeaderBg`,ProgressLine:`Progress`};function f(e,t){let n=e.palette.colors.find(([e])=>e===t);if(n)return n[1];let r=d[t];return r?f(e,r):void 0}function p(e,t){let n=/^var\((--[A-Za-z0-9_-]+)\)$/.exec(e);return n?!t||typeof getComputedStyle>`u`?`#000000`:getComputedStyle(t).getPropertyValue(n[1]).trim()||`#000000`:e}function m(e,t,n){if(t===255)return`#374151`;let r=u[t];return r?p(f(e,r)??`#000000`,n):`#000000`}function h(e,t,n,r,i){if(r<=0||i<=0)return e;let a=t+r,o=n+i;if(e.w===0&&e.h===0)return{x:t,y:n,w:r,h:i};let s=Math.min(e.x,t),c=Math.min(e.y,n),l=Math.max(e.x+e.w,a),u=Math.max(e.y+e.h,o);return{x:s,y:c,w:l-s,h:u-c}}function g(e,t,n,r,i,a){if(a>0&&typeof e.roundRect==`function`){e.beginPath(),e.roundRect(t,n,r,i,a),e.fill();return}e.fillRect(t,n,r,i)}function _(e,t,n,r,i){if(e.strokeStyle=m(t,n,e.canvas),e.lineWidth=r,i){let t=i.split(`,`).map(e=>Number.parseFloat(e.trim()));e.setLineDash(t.every(Number.isFinite)?t:[])}else e.setLineDash([])}function ee(e,t){let n=[],r=null,i={x:0,y:0,w:0,h:0};e.clearRect(0,0,t.viewport_width,t.viewport_height);for(let a of t.ops){if(a===`GroupEnd`){r&&i.w>0&&i.h>0&&n.push({taskId:r,x:i.x,y:i.y,w:i.w,h:i.h}),r=null,i={x:0,y:0,w:0,h:0};continue}if(`GroupStart`in a){r=a.GroupStart.task_id,i={x:0,y:0,w:0,h:0};continue}if(`FillRect`in a){let{x:n,y:o,w:s,h:c,color_id:l,radius:u}=a.FillRect;e.fillStyle=m(t,l,e.canvas),g(e,n,o,s,c,u),r&&(i=h(i,n,o,s,c));continue}if(`FillPolygon`in a){let{points:n,color_id:o}=a.FillPolygon;if(n.length===0)continue;e.fillStyle=m(t,o,e.canvas),e.beginPath(),e.moveTo(n[0][0],n[0][1]);for(let t=1;t<n.length;t++)e.lineTo(n[t][0],n[t][1]);if(e.closePath(),e.fill(),r&&n.length>0){let e=n.map(e=>e[0]),t=n.map(e=>e[1]),r=Math.min(...e),a=Math.min(...t);i=h(i,r,a,Math.max(...e)-r,Math.max(...t)-a)}continue}if(`StrokePath`in a){let{d:n,color_id:r,width:i}=a.StrokePath;_(e,t,r,i,null);let o=new Path2D(n);e.stroke(o);continue}if(`StrokePolyline`in a){let{points:n,color_id:r,width:i,dash:o}=a.StrokePolyline;if(n.length<2)continue;_(e,t,r,i,o),e.beginPath(),e.moveTo(n[0][0],n[0][1]);for(let t=1;t<n.length;t++)e.lineTo(n[t][0],n[t][1]);e.stroke();continue}if(`DrawText`in a){let{x:n,y:r,text:i,color_id:o,anchor:s,size:c,weight:l}=a.DrawText;e.fillStyle=m(t,o,e.canvas),e.font=`${l} ${c}px sans-serif`,e.textBaseline=`alphabetic`,s===1?e.textAlign=`center`:s===2?e.textAlign=`end`:e.textAlign=`start`,e.fillText(i,n,r),e.textAlign=`start`}}return{hitRegions:n}}function v(e){try{return JSON.parse(e)}catch{return{viewport_width:0,viewport_height:0,ops:[],palette:{colors:[]},error:`invalid json`}}}function y(e,t,n){for(let r=e.length-1;r>=0;r--){let i=e[r];if(t>=i.x&&t<=i.x+i.w&&n>=i.y&&n<=i.y+i.h)return i.taskId}return null}function te(e){if(!e)return;let t=e.getContext(`2d`);t&&t.clearRect(0,0,e.width,e.height),e.width=0,e.height=0,e.style.width=`0px`,e.style.height=`0px`}function ne(e){let t={};return e.today!=null&&(t.today=e.today),e.scrollViewport!=null&&(t.scroll_viewport=e.scrollViewport),e.tzOffsetMinutes!=null&&(t.tz_offset_minutes=Number.isFinite(e.tzOffsetMinutes)?e.tzOffsetMinutes:String(e.tzOffsetMinutes)),e.legend!=null&&(t.legend=e.legend),e.rowLabels!=null&&(t.row_labels=e.rowLabels),e.percentLabels!=null&&(t.percent_labels=e.percentLabels),e.rowHeightPx!=null&&(t.row_height_px=e.rowHeightPx),e.headerHeightPx!=null&&(t.header_height_px=e.headerHeightPx),e.barHeightPx!=null&&(t.bar_height_px=e.barHeightPx),e.barAlign!=null&&(t.bar_align=e.barAlign),e.palette!=null&&(t.palette=e.palette),e.pxPerDay!=null&&(t.px_per_day=e.pxPerDay),e.scale!=null&&(t.scale=e.scale),e.weekendDays!=null&&(t.weekend_days=e.weekendDays),e.weekdayLabels!=null&&(t.weekday_labels=e.weekdayLabels),e.view!=null&&(t.view={from:e.view.from,to:e.view.to}),e.progressLine!=null&&(t.progress_line=e.progressLine),Object.keys(t).length===0?void 0:JSON.stringify(t)}var b={CODE_CANVAS_CAPACITY:`canvas_capacity`,CODE_INPUT_LIMIT:`input_limit`,CODE_PARSE_ERROR:`parse_error`,CODE_SERIALIZE_ERROR:`serialize_error`}.CODE_CANVAS_CAPACITY,re=`<svg xmlns="http://www.w3.org/2000/svg" width="0" height="0" viewBox="0 0 0 0" role="img" aria-label="Empty Gantt chart" font-family="sans-serif" font-size="12"><title>Empty Gantt chart</title><desc>No tasks to display</desc></svg>`,x={ROW_H:40,HEADER_H:30,DAY_SCALE_HEADER_H:48,LEGEND_H:40,CHART_BOTTOM_PADDING_PX:10,LABEL_W:120,BAR_H:20,HIDDEN_LABELS_LEFT_PX:10},S={MAX_CANVAS_SIDE_PX:16384,MAX_CANVAS_AREA_PX:32*1024*1024};function ie(e){try{let t=JSON.parse(e);return{message:typeof t.error==`string`?t.error:e,code:typeof t.code==`string`?t.code:void 0}}catch{return{message:e}}}function C(e,t,n){if(!(e>0)||!(t>0)||!(n>0)||!Number.isFinite(n))return 1;let{MAX_CANVAS_SIDE_PX:r,MAX_CANVAS_AREA_PX:i}=S,a=Math.min(r/e,r/t,Math.sqrt(i/(e*t)));return Math.min(n,a)}function ae(e,t,n){let r=C(e,t,n);return{width:Math.floor(e*r),height:Math.floor(t*r)}}function oe(e,t,n,r,i){return!(n.width>0)||!(n.height>0)?null:{x:(e-n.left)*(r/n.width),y:(t-n.top)*(i/n.height)}}function w(e={}){return e.headerHeight==null?e.scale===`day`?x.DAY_SCALE_HEADER_H:x.HEADER_H:e.headerHeight}function se(e,t,n=`shown`,r={}){if(t===0)return 0;let i=r.rowHeight??x.ROW_H;return(e?e.reduce((e,t)=>e+(t.height??i),0):t*i)+w(r)+(n===`hidden`?0:x.LEGEND_H)+x.CHART_BOTTOM_PADDING_PX}function T(e){return e.code===b}function E(e,t){return e.startsWith(`<svg `)&&e!==t}function ce(e,t,n){return T(e)&&E(t,n)?{mode:`svg`,svg:t}:{mode:`error`,message:e.message}}function le(e,t){let n=(t??x.BAR_H)/2;return e===`hidden`?n:Math.max(x.LABEL_W,n)}var ue={key:0,class:`koyori-gantt-error`,role:`alert`},de=[`innerHTML`],D=((e,t)=>{let n=e.__vccOpts||e;for(let[e,r]of t)n[e]=r;return n})((0,t.defineComponent)({__name:`GanttChart`,props:{tasks:{},deps:{},today:{},tzOffsetMinutes:{},legend:{},rowLabels:{},percentLabels:{},rows:{},rowHeight:{},headerHeight:{},barHeight:{},barAlign:{},palette:{},pxPerDay:{},scale:{},weekendDays:{},weekdayLabels:{},view:{},progressLine:{},backend:{},deviceTier:{}},emits:[`taskClick`],setup(e,{expose:r,emit:i}){(0,t.useCssVars)(e=>({v59cd6a8e:a.value,v59c5ef75:s}));let a=(0,t.computed)(()=>`${c.rowHeight??x.ROW_H}px`),o=(0,t.computed)(()=>`${le(c.rowLabels,c.barHeight)}px`),s=`${x.BAR_H}px`,c=e,l=i,u=(0,t.ref)(!1),d=(0,t.ref)(``),f=(0,t.ref)(0),p=(0,t.ref)(600),m=(0,t.ref)(null),h=(0,t.ref)(null),g=(0,t.ref)([]),_=(0,t.ref)(``),b=(0,t.ref)(``),S=(0,t.ref)(null),C={width:0,height:0},w=(0,t.ref)(re),E=(0,t.computed)(()=>c.backend===`canvas`);function D(e){let t=e??m.value;t&&(f.value=t.scrollTop,p.value=t.clientHeight)}(0,t.onMounted)(async()=>{await(0,n.default)(),w.value=(0,n.empty_svg_markup)(),u.value=!0,await(0,t.nextTick)(),D(),O.value&&(k.value=!0)});function fe(){if(c.deviceTier)return c.deviceTier;if(typeof navigator>`u`)return`low`;let e=navigator;return e.deviceMemory===void 0||e.deviceMemory<=4||navigator.hardwareConcurrency<=4?`low`:`high`}let pe=(0,t.computed)(()=>fe()),O=(0,t.computed)(()=>pe.value===`low`),k=(0,t.ref)(!1);(0,t.watch)(O,async e=>{if(!e){k.value=!1;return}k.value=!1,await(0,t.nextTick)(),D(),k.value=!0},{flush:`post`});let me=(0,t.computed)(()=>I.value?0:se(c.rows,c.tasks.length,c.legend,{rowHeight:c.rowHeight,headerHeight:c.headerHeight,scale:c.scale})),he=(0,t.computed)(()=>{if(!(!O.value||!k.value))return{scroll_y:f.value,client_height:p.value}});function A(e){return ne({today:c.today,scrollViewport:e,tzOffsetMinutes:c.tzOffsetMinutes,legend:c.legend,rowLabels:c.rowLabels,percentLabels:c.percentLabels,rowHeightPx:c.rowHeight,headerHeightPx:c.headerHeight,barHeightPx:c.barHeight,barAlign:c.barAlign,palette:c.palette,pxPerDay:c.pxPerDay,scale:c.scale,weekendDays:c.weekendDays,weekdayLabels:c.weekdayLabels,view:c.view,progressLine:c.progressLine})}let j=(0,t.computed)(()=>A(he.value)),M=(0,t.computed)(()=>c.rows?[JSON.stringify(c.rows)]:[]),N=(0,t.computed)(()=>O.value&&!k.value),P=(0,t.computed)(()=>!u.value||c.tasks.length===0||E.value?``:N.value?null:(0,n.render_svg)(JSON.stringify(c.tasks),JSON.stringify(c.deps??[]),j.value,...M.value)),F=(0,t.computed)(()=>!u.value||c.tasks.length===0||!E.value||N.value?``:(0,n.render_canvas_commands)(JSON.stringify(c.tasks),JSON.stringify(c.deps??[]),j.value,...M.value));(0,t.watch)(P,e=>{e!==null&&(d.value=e)},{immediate:!0});let ge=(0,t.computed)(()=>{if(!u.value||c.tasks.length===0||E.value||P.value!==w.value)return null;let e=(0,n.render_svg_error)(JSON.stringify(c.tasks),JSON.stringify(c.deps??[]),j.value,...M.value);return e?ie(e):null}),I=(0,t.computed)(()=>b.value||ge.value?.message||``);function L(e){g.value=[],te(e)}function R(){_.value=``,b.value=``,S.value=null}function z(e){S.value=e;let t=``;if(T(e))try{t=(0,n.render_svg)(JSON.stringify(c.tasks),JSON.stringify(c.deps??[]),A({scroll_y:f.value,client_height:Math.min(p.value,600)}),...M.value)}catch{}let r=ce(e,t,w.value);r.mode===`svg`?(_.value=r.svg,b.value=``):(_.value=``,b.value=r.message)}(0,t.watch)([f,p],()=>{_.value&&S.value&&z(S.value)});async function B(){let e=F.value;if(!e){L(h.value),R();return}let n=h.value;if(!n&&(R(),await(0,t.nextTick)(),n=h.value,!n))return;let r=v(e);if(r.error){L(n),z({message:r.error,code:r.code});return}R();let i=r.viewport_width,a=r.viewport_height,o=ae(i,a,V.value);n.width=o.width,n.height=o.height,n.style.width=`${i}px`,n.style.height=`${a}px`,C={width:i,height:a};let s=n.getContext(`2d`);if(!s){L(n);return}i>0&&a>0&&s.setTransform(o.width/i,0,0,o.height/a,0,0),g.value=ee(s,r).hitRegions}(0,t.watch)(F,()=>{(0,t.nextTick)().then(B)},{immediate:!0});let V=(0,t.ref)(U()),H=null;function U(){return typeof window>`u`?1:window.devicePixelRatio||1}function W(){H?.removeEventListener(`change`,K),H=null}function G(){W(),!(typeof window>`u`||typeof window.matchMedia!=`function`)&&(H=window.matchMedia(`(resolution: ${U()}dppx)`),H.addEventListener(`change`,K))}function K(){V.value=U(),G()}(0,t.onMounted)(G),(0,t.onBeforeUnmount)(W),(0,t.watch)(V,()=>{h.value&&F.value&&B()});let q=(0,t.ref)(null),_e=(0,t.computed)(()=>Object.values(c.palette??{}).some(e=>typeof e==`string`&&e.includes(`var(`))),ve=(0,t.computed)(()=>E.value&&!_.value&&_e.value),J=null,Y=null,X=0;function Z(){if(X)return;let e=()=>{X=0,h.value&&F.value&&B()};typeof requestAnimationFrame==`function`?X=requestAnimationFrame(e):e()}function ye(e){return e===`class`||e===`style`||(e?.startsWith(`data-`)??!1)}function Q(){J?.removeEventListener(`change`,Z),J=null,Y?.disconnect(),Y=null}function $(){if(Q(),!(typeof window>`u`||!ve.value)&&(typeof window.matchMedia==`function`&&(J=window.matchMedia(`(prefers-color-scheme: dark)`),J.addEventListener(`change`,Z)),typeof MutationObserver<`u`&&q.value)){Y=new MutationObserver(e=>{e.some(e=>ye(e.attributeName))&&Z()});for(let e=q.value.parentElement;e;e=e.parentElement)Y.observe(e,{attributes:!0})}}(0,t.onMounted)($),(0,t.watch)(ve,$),(0,t.watch)(()=>c.palette,()=>{$(),E.value&&Z()}),(0,t.onBeforeUnmount)(()=>{Q(),X&&typeof cancelAnimationFrame==`function`&&cancelAnimationFrame(X),X=0}),r({repaint:Z});function be(e){D(e.target)}function xe(e){let t=e.target.closest(`[data-task-id]`);if(!t)return;let n=t.getAttribute(`data-task-id`),r=c.tasks.find(e=>e.id===n);r&&l(`taskClick`,r)}function Se(e){let t=h.value;if(!t)return;let n=oe(e.clientX,e.clientY,t.getBoundingClientRect(),C.width,C.height);if(!n)return;let r=y(g.value,n.x,n.y);if(!r)return;let i=c.tasks.find(e=>e.id===r);i&&l(`taskClick`,i)}return(e,n)=>((0,t.openBlock)(),(0,t.createElementBlock)(`div`,{ref_key:`rootRef`,ref:q,class:`koyori-gantt`,onClick:n[0]||=e=>(!E.value||_.value)&&xe(e)},[u.value?((0,t.openBlock)(),(0,t.createElementBlock)(`div`,{key:1,ref_key:`scrollRef`,ref:m,class:(0,t.normalizeClass)([`koyori-gantt-scroll`,{"koyori-gantt-scroll--virtual":O.value||S.value}]),onScroll:be},[I.value?((0,t.openBlock)(),(0,t.createElementBlock)(`div`,ue,` Unable to render Gantt chart: `+(0,t.toDisplayString)(I.value),1)):((0,t.openBlock)(),(0,t.createElementBlock)(`div`,{key:1,class:`koyori-gantt-inner`,style:(0,t.normalizeStyle)({height:`${me.value}px`})},[E.value&&!_.value?((0,t.openBlock)(),(0,t.createElementBlock)(`canvas`,{key:0,ref_key:`canvasRef`,ref:h,class:`koyori-gantt-canvas`,role:`img`,"aria-label":`Gantt chart`,onClick:Se},null,512)):((0,t.openBlock)(),(0,t.createElementBlock)(`div`,{key:1,class:`koyori-gantt-svg`,innerHTML:_.value||d.value},null,8,de))],4))],34)):((0,t.openBlock)(),(0,t.createElementBlock)(`div`,{key:0,class:`koyori-gantt-skeleton`,style:(0,t.normalizeStyle)({"--koyori-skeleton-label-w":o.value}),"aria-hidden":`true`},[((0,t.openBlock)(!0),(0,t.createElementBlock)(t.Fragment,null,(0,t.renderList)(c.tasks,e=>((0,t.openBlock)(),(0,t.createElementBlock)(`div`,{key:e.id,class:`koyori-gantt-skeleton-row`},[n[1]||=(0,t.createElementVNode)(`div`,{class:`koyori-gantt-skeleton-label`},null,-1),(0,t.createElementVNode)(`div`,{class:`koyori-gantt-skeleton-bar`,style:(0,t.normalizeStyle)({width:`${e.progress_pct}%`})},null,4)]))),128))],4))],512))}}),[[`__scopeId`,`data-v-05f0ec3c`]]);async function fe(){return await(0,n.default)(),JSON.parse((0,n.legend_spec_json)())}e.GanttChart=D,e.findTaskAtPoint=y,e.loadLegendSpec=fe,e.parseCommandBuffer=v,e.replayCommands=ee});
@@ -1,4 +1,5 @@
1
1
  import { LegendMode } from './options';
2
+ import { GanttRow } from './types.ts';
2
3
  import { RenderFailure } from './wasmContract';
3
4
  export type CanvasFailureResolution = {
4
5
  mode: 'svg';
@@ -12,6 +13,26 @@ export type CanvasFailureResolution = {
12
13
  * A hidden legend takes no height, so the band it would occupy is left out.
13
14
  */
14
15
  export declare function chartHeightForTaskCount(taskCount: number, legend?: LegendMode): number;
16
+ /** The sizes a caller may set, in pixels; each left out is the crate's own. */
17
+ export interface RowSizes {
18
+ rowHeight?: number;
19
+ headerHeight?: number;
20
+ /** The date header's scale, which decides the header's height when none is set. */
21
+ scale?: 'week' | 'day' | 'month';
22
+ }
23
+ /**
24
+ * The header's height as the crate draws it: `headerHeight` when set, and
25
+ * otherwise `DAY_SCALE_HEADER_H` for the `'day'` scale, whose month, day and
26
+ * weekday do not fit `HEADER_H`, and `HEADER_H` for the others.
27
+ */
28
+ export declare function headerHeightPx(sizes?: RowSizes): number;
29
+ /**
30
+ * `chartHeightForTaskCount` for a chart that may lay out its own rows: the
31
+ * header, every row at its own height (or `rowHeight`), and below them the
32
+ * legend when shown and the bottom padding. Without `rows` it is one row per
33
+ * task, as the crate lays them out.
34
+ */
35
+ export declare function chartHeightForRows(rows: GanttRow[] | undefined, taskCount: number, legend?: LegendMode, sizes?: RowSizes): number;
15
36
  /**
16
37
  * Canvas capacity errors can use the independently bounded SVG renderer.
17
38
  * Decided by `code` alone — the message beside it is display text and is free
@@ -27,3 +48,13 @@ export declare function isCanvasCapacityError(failure: RenderFailure): boolean;
27
48
  */
28
49
  export declare function isRenderedSvg(svg: string, emptySvgMarkup: string): boolean;
29
50
  export declare function resolveCanvasFailure(failure: RenderFailure, fallbackSvg: string, emptySvgMarkup: string): CanvasFailureResolution;
51
+ /**
52
+ * The width of the loading skeleton's label column, which stands in for the
53
+ * chart's left margin, so the skeleton's bars start where the drawn chart's
54
+ * do. It reads the bar the chart draws (`barHeight`, or `BAR_H`) the way the
55
+ * crate's `label_width` does: with the titles shown, the title column
56
+ * `LABEL_W` unless half the bar is wider; with them hidden, half the bar
57
+ * (`HIDDEN_LABELS_LEFT_PX` for the default bar). Half the bar is the room a
58
+ * first-day milestone's diamond needs.
59
+ */
60
+ export declare function skeletonLabelWidthPx(rowLabels?: 'shown' | 'hidden', barHeight?: number): number;
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export { default as GanttChart } from './GanttChart.vue';
2
- export type { GanttTask, GanttDep } from './types.ts';
2
+ export type { GanttTask, GanttDep, GanttRow, BarState, BarShape } from './types.ts';
3
3
  export { replayCommands, parseCommandBuffer, findTaskAtPoint, } from './replayCommands';
4
- export type { CommandBuffer, DrawOp, ReplayResult, TaskHitRegion } from './replayCommands';
4
+ export type { ColorIdName, CommandBuffer, DrawOp, ReplayResult, TaskHitRegion, } from './replayCommands';
5
5
  export { loadLegendSpec } from './legend';
6
6
  export type { LegendSpec, LegendTier, LegendProgressLine } from './legend';
7
- export type { ChartOptions, LegendMode } from './options';
7
+ export type { BarAlign, ChartOptions, LabelMode, LegendMode, PaletteOverrides, ProgressLineMode, Scale, ViewRange, } from './options';
package/dist/options.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { ColorIdName } from './replayCommands';
1
2
  /**
2
3
  * The `options_json` string the Wasm entry points take.
3
4
  *
@@ -13,11 +14,60 @@ export interface ScrollViewportOption {
13
14
  }
14
15
  /** Whether the chart draws its own legend. Left out, the legend is drawn. */
15
16
  export type LegendMode = 'shown' | 'hidden';
17
+ /**
18
+ * Whether the chart draws one kind of its own text: `rowLabels` the task titles
19
+ * left of the days, `percentLabels` the `NN%` on each bar. Left out, it is drawn.
20
+ */
21
+ export type LabelMode = 'shown' | 'hidden';
22
+ /**
23
+ * Colours that replace the chart's own, by colour name. A value is a CSS
24
+ * colour: `#hex`, `rgb()`/`hsl()`/`oklch()`, or `var(--name)` to draw with the
25
+ * caller's design tokens. The crate refuses anything else.
26
+ */
27
+ export type PaletteOverrides = Partial<Record<ColorIdName, string>>;
28
+ /** Where a bar sits in its row. Left out, it is centred. */
29
+ export type BarAlign = 'middle' | 'bottom';
30
+ /**
31
+ * What the date header marks: `'week'` a line and `M/D` at each Monday (the
32
+ * default), `'day'` every day's number and weekday under the month, `'month'`
33
+ * a line and `YYYY/M` at the first of each month.
34
+ */
35
+ export type Scale = 'week' | 'day' | 'month';
36
+ /**
37
+ * The days a chart shows, `from` through `to` (YYYY-MM-DD, both included). A
38
+ * bar running past either end is cut there and marked `← M/D` or `→ M/D`; a
39
+ * task wholly outside is drawn as its mark alone.
40
+ */
41
+ /**
42
+ * How the chart draws the progress line: `'shown'` (the default) is the line as
43
+ * before, `'hidden'` draws none, and `'by_row'` bends out from the today line to
44
+ * each row that is late or ahead and back at its bottom edge.
45
+ */
46
+ export type ProgressLineMode = 'shown' | 'hidden' | 'by_row';
47
+ export interface ViewRange {
48
+ from: string;
49
+ to: string;
50
+ }
16
51
  export interface ChartOptionsInput {
17
52
  today?: string | null;
18
53
  scrollViewport?: ScrollViewportOption | null;
19
54
  tzOffsetMinutes?: number | null;
20
55
  legend?: LegendMode | null;
56
+ rowLabels?: LabelMode | null;
57
+ percentLabels?: LabelMode | null;
58
+ rowHeightPx?: number | null;
59
+ headerHeightPx?: number | null;
60
+ barHeightPx?: number | null;
61
+ barAlign?: BarAlign | null;
62
+ palette?: PaletteOverrides | null;
63
+ pxPerDay?: number | null;
64
+ scale?: Scale | null;
65
+ /** Weekday numbers drawn as weekend bands, 0 for Monday to 6 for Sunday. */
66
+ weekendDays?: number[] | null;
67
+ /** Seven labels, Monday first, for the `'day'` scale. */
68
+ weekdayLabels?: string[] | null;
69
+ view?: ViewRange | null;
70
+ progressLine?: ProgressLineMode | null;
21
71
  }
22
72
  /**
23
73
  * The object `options_json` carries. Every key is optional, and a chart drawn
@@ -28,5 +78,18 @@ export interface ChartOptions {
28
78
  scroll_viewport?: ScrollViewportOption;
29
79
  tz_offset_minutes?: number | string;
30
80
  legend?: LegendMode;
81
+ row_labels?: LabelMode;
82
+ percent_labels?: LabelMode;
83
+ row_height_px?: number;
84
+ header_height_px?: number;
85
+ bar_height_px?: number;
86
+ bar_align?: BarAlign;
87
+ palette?: PaletteOverrides;
88
+ px_per_day?: number;
89
+ scale?: Scale;
90
+ weekend_days?: number[];
91
+ weekday_labels?: string[];
92
+ view?: ViewRange;
93
+ progress_line?: ProgressLineMode;
31
94
  }
32
95
  export declare function buildOptionsJson(input: ChartOptionsInput): string | undefined;
@@ -1,5 +1,5 @@
1
1
  /** Mirrors koyori-arc-core `CommandBuffer` JSON (serde externally-tagged `DrawOp`). */
2
- export type ColorIdName = 'BarBg' | 'TierLow' | 'TierMid' | 'TierHigh' | 'TierDone' | 'Dep' | 'Progress' | 'Grid' | 'Today' | 'HeaderBg' | 'GridLabel' | 'ProgressTextOnFg' | 'ProgressTextOnBg';
2
+ export type ColorIdName = 'BarBg' | 'TierLow' | 'TierMid' | 'TierHigh' | 'TierDone' | 'Dep' | 'Progress' | 'Grid' | 'Today' | 'HeaderBg' | 'GridLabel' | 'ProgressTextOnFg' | 'ProgressTextOnBg' | 'GroupRow' | 'Weekend' | 'BarStroke' | 'DoneBg' | 'DoneStroke' | 'WarnBg' | 'WarnStroke' | 'HardDeadline' | 'Note' | 'NoteBg' | 'ProgressLine';
3
3
  export interface CommandBuffer {
4
4
  viewport_width: number;
5
5
  viewport_height: number;
@@ -63,6 +63,12 @@ export interface TaskHitRegion {
63
63
  export interface ReplayResult {
64
64
  hitRegions: TaskHitRegion[];
65
65
  }
66
+ /**
67
+ * A canvas cannot draw `var(--name)`, which the SVG path writes as it is. It is
68
+ * read off the canvas element's computed style, where the caller's tokens are
69
+ * in scope; a name with no value there draws black, as a missing colour does.
70
+ */
71
+ export declare function resolveCssColor(color: string, el: Element | undefined): string;
66
72
  /**
67
73
  * Replay a wasm-produced `CommandBuffer` onto a Canvas2D context.
68
74
  * Single JS loop — no per-op wasm round-trips.
package/dist/types.d.ts CHANGED
@@ -20,6 +20,35 @@ export interface GanttTask {
20
20
  */
21
21
  end?: string;
22
22
  }
23
+ /**
24
+ * One row of a chart whose rows the caller lays out (`rows` on `GanttChart`).
25
+ * A task row draws that task's bar; a group row draws a band across the days
26
+ * and no bar. `height` is in pixels; left out, the row is `rowHeight` tall.
27
+ *
28
+ * A task row may also carry marks; a row without them draws the bar as a chart
29
+ * without `rows` does.
30
+ * - `hard_deadline` (YYYY-MM-DD): a diamond in the middle of that day.
31
+ * - `state`: fills and outlines the bar (`normal`, `done`, `warn`).
32
+ * - `note`: a line of text past the bar and the diamond (at most 200 characters).
33
+ * - `shape`: `point` draws a dot on the span's last day instead of a bar, with a
34
+ * line to the diamond when the deadline is later.
35
+ */
36
+ export type GanttRow = {
37
+ kind: 'task';
38
+ task_id: string;
39
+ height?: number;
40
+ hard_deadline?: string | null;
41
+ state?: BarState | null;
42
+ note?: string | null;
43
+ shape?: BarShape;
44
+ } | {
45
+ kind: 'group';
46
+ height?: number;
47
+ };
48
+ /** How a task row's bar is filled and outlined. */
49
+ export type BarState = 'normal' | 'done' | 'warn';
50
+ /** A task row drawn as a bar (the default) or as a dot on its last day. */
51
+ export type BarShape = 'bar' | 'point';
23
52
  /** Mirrors `task_relations` entity. */
24
53
  export interface GanttDep {
25
54
  /** `task_relations.blocker_task_id` */
@@ -38,16 +38,22 @@ export declare const EMPTY_SVG_MARKUP: string;
38
38
  * Reproduced where:
39
39
  * - `ROW_H`, `HEADER_H`, `LEGEND_H`, `CHART_BOTTOM_PADDING_PX` — the chart
40
40
  * height `chartHeightForTaskCount()` reserves before Wasm answers.
41
+ * - `DAY_SCALE_HEADER_H` — the header `chartHeightForRows()` reserves for the
42
+ * `'day'` scale when no height is set, the one the crate draws it with.
41
43
  * - `ROW_H`, `LABEL_W`, `BAR_H` — the loading skeleton's row metrics, which
42
44
  * stand in for real rows and must line up with them.
45
+ * - `HIDDEN_LABELS_LEFT_PX` — the skeleton's left margin with the title column
46
+ * hidden: the chart keeps half a bar there for a first-day milestone.
43
47
  */
44
48
  export declare const RUST_LAYOUT: {
45
49
  readonly ROW_H: 40;
46
50
  readonly HEADER_H: 30;
51
+ readonly DAY_SCALE_HEADER_H: 48;
47
52
  readonly LEGEND_H: 40;
48
53
  readonly CHART_BOTTOM_PADDING_PX: 10;
49
54
  readonly LABEL_W: 120;
50
55
  readonly BAR_H: 20;
56
+ readonly HIDDEN_LABELS_LEFT_PX: 10;
51
57
  };
52
58
  /**
53
59
  * Keys are the Rust constant names in `crates/koyori-arc-core/src/render.rs`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@koyori-app/arc-vue",
3
- "version": "0.1.0-alpha.3",
3
+ "version": "0.1.0-alpha.5",
4
4
  "type": "module",
5
5
  "license": "MPL-2.0 OR GPL-2.0-or-later",
6
6
  "repository": {
@@ -43,7 +43,7 @@
43
43
  "vitest": "^4.1.10",
44
44
  "vue": "^3.5.39",
45
45
  "vue-tsc": "^3.3.7",
46
- "@koyori-app/arc": "0.1.0-alpha.3"
46
+ "@koyori-app/arc": "0.1.0-alpha.5"
47
47
  },
48
48
  "scripts": {
49
49
  "build": "vite build",