@diagc/cli 1.7.0 → 1.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. package/README.md +1 -1
  2. package/assets/guide/compose.md +84 -0
  3. package/assets/guide/git-graph.md +3 -0
  4. package/assets/guide/index.md +11 -3
  5. package/assets/skill/SKILL.md +2 -1
  6. package/assets/studio/assets/{index-DzVDK5uD.css → index-CAVbaTgv.css} +1 -1
  7. package/assets/studio/assets/index-Cgkqoymm.js +112 -0
  8. package/assets/studio/index.html +2 -2
  9. package/assets/viewer/index.html +23 -23
  10. package/assets/viewer/shared/caveat-cyrillic-500-normal.woff +0 -0
  11. package/assets/viewer/shared/caveat-cyrillic-500-normal.woff2 +0 -0
  12. package/assets/viewer/shared/caveat-cyrillic-700-normal.woff +0 -0
  13. package/assets/viewer/shared/caveat-cyrillic-700-normal.woff2 +0 -0
  14. package/assets/viewer/shared/caveat-cyrillic-ext-500-normal.woff +0 -0
  15. package/assets/viewer/shared/caveat-cyrillic-ext-500-normal.woff2 +0 -0
  16. package/assets/viewer/shared/caveat-cyrillic-ext-700-normal.woff +0 -0
  17. package/assets/viewer/shared/caveat-cyrillic-ext-700-normal.woff2 +0 -0
  18. package/assets/viewer/shared/caveat-latin-500-normal.woff +0 -0
  19. package/assets/viewer/shared/caveat-latin-500-normal.woff2 +0 -0
  20. package/assets/viewer/shared/caveat-latin-700-normal.woff +0 -0
  21. package/assets/viewer/shared/caveat-latin-700-normal.woff2 +0 -0
  22. package/assets/viewer/shared/caveat-latin-ext-500-normal.woff +0 -0
  23. package/assets/viewer/shared/caveat-latin-ext-500-normal.woff2 +0 -0
  24. package/assets/viewer/shared/caveat-latin-ext-700-normal.woff +0 -0
  25. package/assets/viewer/shared/caveat-latin-ext-700-normal.woff2 +0 -0
  26. package/assets/viewer/shared/chakra-petch-latin-500-normal.woff2 +0 -0
  27. package/assets/viewer/shared/chakra-petch-latin-600-normal.woff2 +0 -0
  28. package/assets/viewer/shared/inter-latin-400-normal.woff2 +0 -0
  29. package/assets/viewer/shared/inter-latin-600-normal.woff2 +0 -0
  30. package/assets/viewer/shared/jetbrains-mono-latin-400-normal.woff2 +0 -0
  31. package/assets/viewer/shared/jetbrains-mono-latin-600-normal.woff2 +0 -0
  32. package/assets/viewer/shared/kalam-devanagari-400-normal.woff +0 -0
  33. package/assets/viewer/shared/kalam-devanagari-400-normal.woff2 +0 -0
  34. package/assets/viewer/shared/kalam-devanagari-700-normal.woff +0 -0
  35. package/assets/viewer/shared/kalam-devanagari-700-normal.woff2 +0 -0
  36. package/assets/viewer/shared/kalam-latin-400-normal.woff +0 -0
  37. package/assets/viewer/shared/kalam-latin-400-normal.woff2 +0 -0
  38. package/assets/viewer/shared/kalam-latin-700-normal.woff +0 -0
  39. package/assets/viewer/shared/kalam-latin-700-normal.woff2 +0 -0
  40. package/assets/viewer/shared/kalam-latin-ext-400-normal.woff +0 -0
  41. package/assets/viewer/shared/kalam-latin-ext-400-normal.woff2 +0 -0
  42. package/assets/viewer/shared/kalam-latin-ext-700-normal.woff +0 -0
  43. package/assets/viewer/shared/kalam-latin-ext-700-normal.woff2 +0 -0
  44. package/assets/viewer/shared/viewer.css +2 -0
  45. package/assets/viewer/shared/viewer.js +46 -0
  46. package/dist/api/diagrams.d.ts +20 -0
  47. package/dist/api/diagrams.js +69 -3
  48. package/dist/api/handlers.d.ts +1 -1
  49. package/dist/api/handlers.js +1 -1
  50. package/dist/api/routes.js +13 -0
  51. package/dist/cli/parse.d.ts +9 -1
  52. package/dist/cli/parse.js +14 -1
  53. package/dist/cli/run.js +6 -2
  54. package/dist/cli.js +7 -1
  55. package/dist/commands/compile.d.ts +1 -1
  56. package/dist/commands/compile.js +5 -6
  57. package/dist/commands/lint.js +4 -5
  58. package/dist/commands/publish.d.ts +1 -1
  59. package/dist/commands/publish.js +15 -7
  60. package/dist/commands/shared.d.ts +9 -0
  61. package/dist/commands/shared.js +30 -1
  62. package/dist/commands/show.d.ts +1 -1
  63. package/dist/commands/show.js +12 -2
  64. package/dist/compile.d.ts +11 -1
  65. package/dist/compile.js +25 -6
  66. package/dist/guide.js +22 -10
  67. package/dist/home.d.ts +5 -1
  68. package/dist/home.js +2 -0
  69. package/dist/init.d.ts +1 -1
  70. package/dist/init.js +1 -1
  71. package/dist/lint.js +2 -1
  72. package/dist/loadHints.d.ts +8 -0
  73. package/dist/loadHints.js +36 -0
  74. package/dist/names.js +1 -1
  75. package/dist/publish/html.d.ts +13 -0
  76. package/dist/publish/html.js +54 -2
  77. package/dist/publish/publish.d.ts +10 -0
  78. package/dist/publish/publish.js +45 -23
  79. package/dist/publish/snapshot.d.ts +21 -2
  80. package/dist/publish/snapshot.js +95 -18
  81. package/dist/text/git.d.ts +52 -0
  82. package/dist/text/git.js +274 -0
  83. package/dist/text/layout.d.ts +29 -0
  84. package/dist/text/paint.js +95 -0
  85. package/dist/text/scene.d.ts +3 -0
  86. package/dist/text/scene.js +7 -3
  87. package/dist/tui/actions.js +14 -2
  88. package/dist/tui/screen.js +1 -0
  89. package/dist/tui/state.d.ts +2 -0
  90. package/dist/tui/state.js +1 -0
  91. package/dist/watch.js +23 -7
  92. package/package.json +2 -2
  93. package/assets/studio/assets/index-DRsUukzt.js +0 -112
@@ -0,0 +1,274 @@
1
+ import { gitGraph, isGitKind, latestCommit, mergedAway, placeColumns, } from '@diagc/core/internal';
2
+ import { cellWidth, printable } from './width.js';
3
+ // A git graph in cells, one of two ways. Down the screen, the default, as a terminal
4
+ // reads a history: each lane a column in declaration order, each commit a dot on its
5
+ // column's row with its tag beside it, and the lanes' names along the foot. Across the
6
+ // screen, as the page draws it (the renderer's git-layout.ts): each lane a row, each
7
+ // commit a dot at its column with its tag on the row above, and the lane's name at the
8
+ // right end, where the page has its label box. Across, columns come from core's
9
+ // placeColumns, as the page's do, so a tag clears its neighbours and a stage frame is
10
+ // wide enough for its title; down, the rows do, so a frame has room for its border.
11
+ // Stages frame their columns across every lane. Commits on no lane get a track of their
12
+ // own after the lanes, and the rest a row of boxes under the picture.
13
+ /** The graph's spacing across the screen, in cells. */
14
+ export const GIT = {
15
+ /** neighbouring columns' distance when nothing needs more: a dot and three cells of line */
16
+ PITCH: 4,
17
+ /** the least room between two tags on one lane: two cells, as one would read the
18
+ * two as one phrase */
19
+ TAG_GAP: 2,
20
+ /** rows from one lane's line to the next: the next lane's tags and a blank row between */
21
+ LANE: 3,
22
+ /** what a stage's frame needs besides its title: a corner and a cell of border
23
+ * before it, a space either side, a cell of border and a corner after */
24
+ FRAME_ROOM: 6,
25
+ /** from the last column's reach to the lanes' names: the tail's run and a space */
26
+ NAME_GAP: 2,
27
+ /** blank rows between the lanes and the boxes under them */
28
+ STRAY_ROW: 1,
29
+ /** between two boxes in that row */
30
+ STRAY_GAP: 4,
31
+ };
32
+ /** The graph's spacing down the screen, in cells. */
33
+ export const GIT_DOWN = {
34
+ /** rows from one column's dots to the next when nothing needs more: a dot and the row
35
+ * a branch turns off on, or a merge turns in */
36
+ PITCH: 2,
37
+ /** rows a stage's frame reaches past its first and last dots: the row a line turns
38
+ * on, then its border, so no line turns along a border */
39
+ FRAME: 2,
40
+ /** the least room between a lane's widest tag, or its name, and the next lane */
41
+ LANE_GAP: 2,
42
+ /** columns left of the first lane where stages are framed: the frame's side and a space */
43
+ MARGIN: 2,
44
+ /** what a stage's frame needs past the last lane besides its title: a cell of border
45
+ * before it, a space either side, a cell of border and a corner after */
46
+ TITLE_ROOM: 5,
47
+ /** rows from the last dot's reach to the lanes' names: the tail's run */
48
+ NAME_GAP: 2,
49
+ };
50
+ /** A name on one line, as a tag, a lane's name and a stage's title are drawn. */
51
+ const oneLine = (node) => printable(node.name.split(/\r?\n/).join(' '));
52
+ /** Every node the view shows, parents before children. */
53
+ function shownNodes(view) {
54
+ const out = [];
55
+ const walk = (vn) => {
56
+ out.push(vn);
57
+ vn.children.forEach(walk);
58
+ };
59
+ view.roots.forEach(walk);
60
+ return out;
61
+ }
62
+ /** The tracks: each lane the view shows, then the strays' when there are any. */
63
+ function tracksOf(graph, shown) {
64
+ const tracks = graph.lanes
65
+ .filter((lane) => shown.has(lane.id))
66
+ .map((lane) => ({ id: lane.id, commits: lane.commits.filter((c) => shown.has(c.id)) }));
67
+ const strays = graph.strays.filter((c) => shown.has(c.id));
68
+ return strays.length > 0 ? [...tracks, { id: '', commits: strays }] : tracks;
69
+ }
70
+ const columnOf = (parts, commit) => parts.graph.columns.get(commit.id) ?? 0;
71
+ /** The dot a lane's tail runs on from: its last commit's, unless that merged away. */
72
+ function tailFrom(parts, lane, dots) {
73
+ const last = latestCommit(parts.graph, lane);
74
+ return last === undefined || mergedAway(parts.model, last.id) ? undefined : dots.get(last.id);
75
+ }
76
+ /** A git link's path across the screen: down from where a branch leaves and along its
77
+ * lane, along and up half a pitch before where a merge lands (the page's gitRoute). */
78
+ function acrossRoute(s, t) {
79
+ if (t.y === s.y)
80
+ return [s, t];
81
+ if (t.y > s.y || t.x <= s.x)
82
+ return [s, { x: s.x, y: t.y }, t];
83
+ const x = t.x - GIT.PITCH / 2;
84
+ return [s, { x, y: s.y }, { x, y: t.y }, t];
85
+ }
86
+ /** A git link's path down the screen, which turns the way acrossRoute does, by the
87
+ * lanes' order: across on the row under where it leaves, as its tag is beside it, and
88
+ * down its lane, or down its lane and across on the row over where it lands. */
89
+ function downRoute(s, t) {
90
+ if (t.x === s.x)
91
+ return [s, t];
92
+ const y = t.x > s.x || t.y <= s.y ? s.y + 1 : t.y - 1;
93
+ return [s, { x: s.x, y }, { x: t.x, y }, t];
94
+ }
95
+ /** What is not on a track, boxed in a row from the left at `y`. */
96
+ function placeLoose(nodes, boxes, y, placed) {
97
+ let x = 0;
98
+ for (const vn of nodes) {
99
+ if (placed.has(vn.id))
100
+ continue;
101
+ const text = boxes.get(vn.id);
102
+ const [width, height] = [text?.width ?? 5, text?.height ?? 3];
103
+ placed.set(vn.id, { x, y, width, height });
104
+ x += width + GIT.STRAY_GAP;
105
+ }
106
+ }
107
+ /** The picture's size: every box and every route. */
108
+ function measure(boxes, routes) {
109
+ let [width, height] = [0, 0];
110
+ for (const b of boxes.values())
111
+ [width, height] = [Math.max(width, b.x + b.width), Math.max(height, b.y + b.height)];
112
+ for (const r of routes.values()) {
113
+ for (const p of r.points)
114
+ [width, height] = [Math.max(width, p.x + 1), Math.max(height, p.y + 1)];
115
+ }
116
+ return [width, height];
117
+ }
118
+ /** The layout, its links routed from dot to dot and what is on no track boxed. */
119
+ function finished(parts, { git, placed, route, looseY }) {
120
+ const routes = new Map();
121
+ for (const e of parts.view.edges) {
122
+ const [s, t] = [git.dots.get(e.from), git.dots.get(e.to)];
123
+ if (isGitKind(e.kind) && s !== undefined && t !== undefined)
124
+ routes.set(e.id, { points: route(s, t) });
125
+ }
126
+ placeLoose(parts.nodes, parts.boxes, looseY, placed);
127
+ const [width, height] = measure(placed, routes);
128
+ return { width, height, boxes: placed, routes, git };
129
+ }
130
+ /** The graph across the screen: a row a track, the names at the right end. */
131
+ function across(parts) {
132
+ const { graph, tracks, stages, maxCol } = parts;
133
+ const tags = [];
134
+ for (const track of tracks) {
135
+ for (const c of track.commits) {
136
+ const width = cellWidth(oneLine(c));
137
+ if (width > 0)
138
+ tags.push({ col: columnOf(parts, c), row: track.id, left: Math.floor(width / 2), right: Math.ceil(width / 2) });
139
+ }
140
+ }
141
+ // a frame's width rounded up to even, so that it grows by whole cells either side
142
+ const frames = stages.map((s) => {
143
+ const width = cellWidth(oneLine(s.node)) + GIT.FRAME_ROOM;
144
+ return { id: s.id, fromCol: s.fromCol, toCol: s.toCol, width: width + (width % 2) };
145
+ });
146
+ const half = GIT.PITCH / 2;
147
+ const cols = placeColumns({ maxCol, first: half, pitch: GIT.PITCH, gap: GIT.TAG_GAP, tags, frames });
148
+ const placed = new Map();
149
+ const git = {
150
+ down: false,
151
+ dots: new Map(),
152
+ tags: new Map(),
153
+ names: new Map(),
154
+ tails: [],
155
+ stages: new Map(),
156
+ };
157
+ const top = stages.length > 0 ? 1 : 0;
158
+ const lineOf = (i) => top + i * GIT.LANE + 1;
159
+ const end = maxCol < 0 ? 0 : cols.x[maxCol] + half + cols.growRight[maxCol];
160
+ const nameX = end + GIT.NAME_GAP;
161
+ tracks.forEach((track, i) => {
162
+ const y = lineOf(i);
163
+ for (const c of track.commits) {
164
+ const dot = { x: cols.x[columnOf(parts, c)], y };
165
+ git.dots.set(c.id, dot);
166
+ const text = oneLine(c);
167
+ const width = cellWidth(text);
168
+ if (width === 0) {
169
+ placed.set(c.id, { ...dot, width: 1, height: 1 });
170
+ continue;
171
+ }
172
+ const tag = { x: dot.x - Math.floor(width / 2), y: y - 1, text };
173
+ git.tags.set(c.id, tag);
174
+ const x = Math.min(tag.x, dot.x);
175
+ placed.set(c.id, { x, y: tag.y, width: Math.max(tag.x + width, dot.x + 1) - x, height: 2 });
176
+ }
177
+ const lane = graph.lanes.find((l) => l.id === track.id);
178
+ if (lane === undefined)
179
+ return;
180
+ const name = { x: nameX, y, text: oneLine(lane.node) };
181
+ git.names.set(lane.id, name);
182
+ placed.set(lane.id, { x: name.x, y, width: Math.max(1, cellWidth(name.text)), height: 1 });
183
+ const from = tailFrom(parts, lane.id, git.dots);
184
+ if (from !== undefined && from.x + 1 <= nameX - 2) {
185
+ git.tails.push({ lane: lane.id, from: { x: from.x + 1, y }, to: { x: nameX - 2, y } });
186
+ }
187
+ });
188
+ const bottom = tracks.length === 0 ? top : lineOf(tracks.length - 1) + 1;
189
+ for (const s of stages) {
190
+ const grow = cols.growth.get(s.id);
191
+ const x = cols.x[s.fromCol] - half - grow;
192
+ placed.set(s.id, { x, y: 0, width: cols.x[s.toCol] + half + grow - x, height: bottom + 1 });
193
+ git.stages.set(s.id, { x: x + 2, y: 0, text: oneLine(s.node) });
194
+ }
195
+ return finished(parts, { git, placed, route: acrossRoute, looseY: bottom + 1 + GIT.STRAY_ROW });
196
+ }
197
+ /** The graph down the screen: a column a track, each as wide as its widest tag or its
198
+ * name, the names along the foot. */
199
+ function down(parts) {
200
+ const { graph, tracks, stages, maxCol } = parts;
201
+ const { PITCH, FRAME, LANE_GAP, NAME_GAP } = GIT_DOWN;
202
+ // A tag is on its dot's row, so it takes no room between rows; a frame takes its reach.
203
+ const frames = stages.map((s) => ({ ...s, width: (s.toCol - s.fromCol + 1) * PITCH + 2 * FRAME }));
204
+ const rows = placeColumns({ maxCol, first: 0, pitch: PITCH, gap: 0, tags: [], frames });
205
+ const nameY = (maxCol < 0 ? 0 : rows.x[maxCol] + rows.growRight[maxCol]) + NAME_GAP;
206
+ const placed = new Map();
207
+ const git = {
208
+ down: true,
209
+ dots: new Map(),
210
+ tags: new Map(),
211
+ names: new Map(),
212
+ tails: [],
213
+ stages: new Map(),
214
+ };
215
+ let x = stages.length > 0 ? GIT_DOWN.MARGIN : 0;
216
+ let [last, reachEnd] = [x, x];
217
+ for (const track of tracks) {
218
+ let reach = 1;
219
+ for (const c of track.commits) {
220
+ const dot = { x, y: rows.x[columnOf(parts, c)] };
221
+ git.dots.set(c.id, dot);
222
+ const text = oneLine(c);
223
+ const width = cellWidth(text);
224
+ if (width > 0)
225
+ git.tags.set(c.id, { x: x + 2, y: dot.y, text });
226
+ placed.set(c.id, { ...dot, width: width > 0 ? 2 + width : 1, height: 1 });
227
+ reach = Math.max(reach, width > 0 ? 2 + width : 1);
228
+ }
229
+ const lane = graph.lanes.find((l) => l.id === track.id);
230
+ if (lane !== undefined) {
231
+ const name = { x, y: nameY, text: oneLine(lane.node) };
232
+ git.names.set(lane.id, name);
233
+ const width = Math.max(1, cellWidth(name.text));
234
+ placed.set(lane.id, { x, y: nameY, width, height: 1 });
235
+ reach = Math.max(reach, width);
236
+ const from = tailFrom(parts, lane.id, git.dots);
237
+ if (from !== undefined)
238
+ git.tails.push({ lane: lane.id, from: { x, y: from.y + 1 }, to: { x, y: nameY - 1 } });
239
+ }
240
+ [last, reachEnd] = [x, x + reach];
241
+ x += reach + LANE_GAP;
242
+ }
243
+ // Every frame is as wide as the picture, and as the widest title written past the
244
+ // last track, where no lane's line crosses its border.
245
+ let right = reachEnd + 1;
246
+ for (const s of stages)
247
+ right = Math.max(right, last + cellWidth(oneLine(s.node)) + GIT_DOWN.TITLE_ROOM);
248
+ for (const s of stages) {
249
+ const y = rows.x[s.fromCol] - FRAME;
250
+ placed.set(s.id, { x: 0, y, width: right + 1, height: rows.x[s.toCol] + FRAME - y + 1 });
251
+ git.stages.set(s.id, { x: last + 2, y, text: oneLine(s.node) });
252
+ }
253
+ return finished(parts, { git, placed, route: downRoute, looseY: nameY + 1 + GIT.STRAY_ROW });
254
+ }
255
+ /**
256
+ * The graph in cells, for a git-graph plane: every node the view shows gets a box — a
257
+ * commit its dot and tag, a lane its name, a stage its frame — and every drawn git
258
+ * link between two dots a route from one to the other.
259
+ */
260
+ export function gitCells(model, view, boxes, way) {
261
+ const nodes = shownNodes(view);
262
+ const shown = new Set(nodes.map((n) => n.id));
263
+ const graph = gitGraph(model, way.plane);
264
+ const tracks = tracksOf(graph, shown);
265
+ const stages = graph.stages.filter((s) => shown.has(s.id));
266
+ let maxCol = -1;
267
+ for (const track of tracks)
268
+ for (const c of track.commits)
269
+ maxCol = Math.max(maxCol, graph.columns.get(c.id) ?? 0);
270
+ for (const s of stages)
271
+ maxCol = Math.max(maxCol, s.toCol);
272
+ const parts = { model, graph, view, boxes, nodes, tracks, stages, maxCol };
273
+ return way.across === true ? across(parts) : down(parts);
274
+ }
@@ -32,12 +32,41 @@ export interface FishDrawing {
32
32
  /** the categories among `words`: their bones' labels */
33
33
  labels: Set<string>;
34
34
  }
35
+ /** What a git graph is drawn with besides boxes and routes (git.ts). A commit's box
36
+ * is the cells of its dot and tag, a lane's its name's, a stage's its frame; a route
37
+ * runs from dot to dot, both included. */
38
+ export interface GitDrawing {
39
+ /** time runs down the screen and each lane is a column; false, across and a row */
40
+ down: boolean;
41
+ /** commit id → its dot */
42
+ dots: Map<string, CellPoint>;
43
+ /** commit id → its tag, where it starts; an untagged commit has none */
44
+ tags: Map<string, CellPoint & {
45
+ text: string;
46
+ }>;
47
+ /** lane id → its name, where it starts, at its line's end */
48
+ names: Map<string, CellPoint & {
49
+ text: string;
50
+ }>;
51
+ /** each lane's line from its last commit on to its name, dashed; none where that
52
+ * commit merged away */
53
+ tails: {
54
+ lane: string;
55
+ from: CellPoint;
56
+ to: CellPoint;
57
+ }[];
58
+ /** stage id → its title, where it starts in its frame's top border */
59
+ stages: Map<string, CellPoint & {
60
+ text: string;
61
+ }>;
62
+ }
35
63
  export interface TextLayout {
36
64
  width: number;
37
65
  height: number;
38
66
  boxes: Map<string, BoxGeometry>;
39
67
  routes: Map<string, Route>;
40
68
  fish?: FishDrawing;
69
+ git?: GitDrawing;
41
70
  }
42
71
  /**
43
72
  * elk `layered`, in character cells: a node is as big as its text, and the gaps
@@ -208,6 +208,97 @@ function paintFish(p, fish, edges) {
208
208
  for (const [id, g] of boxes)
209
209
  drawBox(p, id, g);
210
210
  }
211
+ /** Text or a line in a node's own colour (`ownCss`), where it has one. */
212
+ const ownInk = (p, id) => {
213
+ const fg = rgb(ownCss(p, id));
214
+ return fg !== undefined ? { fg } : {};
215
+ };
216
+ /** Every cell a link or a lane's tail runs through, as `x,y`. */
217
+ function linedCells(p, git, edges) {
218
+ const lined = new Set();
219
+ const run = (a, b) => {
220
+ const [dx, dy] = [Math.sign(b.x - a.x), Math.sign(b.y - a.y)];
221
+ for (let i = 0; i <= Math.abs(b.x - a.x) + Math.abs(b.y - a.y); i++)
222
+ lined.add(`${a.x + i * dx},${a.y + i * dy}`);
223
+ };
224
+ for (const edge of edges) {
225
+ const { points } = p.scene.layout.routes.get(edge.id);
226
+ for (let i = 1; i < points.length; i++)
227
+ run(points[i - 1], points[i]);
228
+ }
229
+ for (const tail of git.tails)
230
+ run(tail.from, tail.to);
231
+ return lined;
232
+ }
233
+ /** A stage's frame, dim and dashed, or heavy when it is selected. It is stroked cell by
234
+ * cell and gives way where a line runs through it, so a lane's line runs in front of
235
+ * the frame rather than meeting it in a junction. */
236
+ function drawStageFrame(p, id, lined) {
237
+ const g = p.scene.layout.boxes.get(id);
238
+ const [weight, ink] = id === p.selected ? ['heavy', ownInk(p, id)] : ['dashed', { ...ownInk(p, id), dim: true }];
239
+ const [right, bottom] = [g.x + g.width - 1, g.y + g.height - 1];
240
+ const stroke = (x, y, mask) => {
241
+ if (!lined.has(`${x},${y}`))
242
+ p.canvas.stroke({ x, y }, mask, weight, ink);
243
+ };
244
+ for (let x = g.x; x <= right; x++) {
245
+ const mask = (x > g.x ? LEFT : 0) | (x < right ? RIGHT : 0);
246
+ for (const y of [g.y, bottom])
247
+ stroke(x, y, mask);
248
+ }
249
+ for (let y = g.y; y <= bottom; y++) {
250
+ const mask = (y > g.y ? UP : 0) | (y < bottom ? DOWN : 0);
251
+ for (const x of [g.x, right])
252
+ stroke(x, y, mask);
253
+ }
254
+ }
255
+ /** A lane's tail, cell by cell down the screen, where a one-cell segment would read as
256
+ * one across it. */
257
+ function drawTail(p, git, tail) {
258
+ const ink = ownInk(p, tail.lane);
259
+ if (!git.down)
260
+ return p.canvas.segment(tail.from, tail.to, 'dashed', ink);
261
+ for (let y = tail.from.y; y <= tail.to.y; y++)
262
+ p.canvas.stroke({ x: tail.from.x, y }, UP | DOWN, 'dashed', ink);
263
+ }
264
+ /**
265
+ * A git graph as its lanes (git.ts): the stages' frames first, then the links
266
+ * and the lanes' tails, then each commit's dot over the lines that meet it, its tag
267
+ * bold beside it, the lanes' names, the stages' titles in their frames' top borders,
268
+ * and last the boxes of what is on no lane. A dot, tag, name or title is selected in
269
+ * reverse, a stage's frame heavy.
270
+ */
271
+ function paintGit(p, git, edges) {
272
+ const { layout } = p.scene;
273
+ const own = (id) => ownInk(p, id);
274
+ const chosen = (id, style) => (id === p.selected ? { ...style, inverse: true } : style);
275
+ const boxes = [...layout.boxes].filter(([id]) => !git.dots.has(id) && !git.names.has(id) && !git.stages.has(id));
276
+ if (p.dos !== undefined)
277
+ castShadows(p.canvas, boxes.map(([, g]) => g));
278
+ const lined = linedCells(p, git, edges);
279
+ for (const id of git.stages.keys())
280
+ drawStageFrame(p, id, lined);
281
+ for (const edge of edges) {
282
+ const { points } = layout.routes.get(edge.id);
283
+ const ink = edgeInk(p, edge);
284
+ for (let i = 1; i < points.length; i++)
285
+ p.canvas.segment(points[i - 1], points[i], ink.weight, ink.style);
286
+ }
287
+ for (const tail of git.tails)
288
+ drawTail(p, git, tail);
289
+ for (const [id, dot] of git.dots)
290
+ p.canvas.put(dot, p.glyphs.start, chosen(id, own(id)));
291
+ for (const [id, tag] of git.tags)
292
+ p.canvas.text(tag, tag.text, chosen(id, { ...own(id), bold: true }));
293
+ for (const [id, name] of git.names)
294
+ p.canvas.text(name, name.text, chosen(id, { ...own(id), bold: true }));
295
+ for (const [id, title] of git.stages) {
296
+ const g = layout.boxes.get(id);
297
+ p.canvas.text(title, ` ${title.text} `, chosen(id, { ...own(id), bold: true }), g.x + g.width - 2);
298
+ }
299
+ for (const [id, g] of boxes)
300
+ drawBox(p, id, g);
301
+ }
211
302
  /** An edge's label: in its line's ink, or in DOS yellow. */
212
303
  const labelStyle = (p, edge) => {
213
304
  const { style } = edgeInk(p, edge);
@@ -236,6 +327,10 @@ export function paint(scene, options) {
236
327
  paintFish(p, layout.fish, edges);
237
328
  return p.canvas;
238
329
  }
330
+ if (layout.git !== undefined) {
331
+ paintGit(p, layout.git, edges);
332
+ return p.canvas;
333
+ }
239
334
  if (p.dos !== undefined)
240
335
  castShadows(p.canvas, drawn.filter((d) => !d.frame).map((d) => d.g));
241
336
  for (const { id, g, frame } of drawn)
@@ -20,6 +20,9 @@ export interface SceneInput {
20
20
  /** the style it is drawn in; absent = the terminal's own. DOS's boxes cast shadows,
21
21
  * which the picture leaves room for at its right and its foot. */
22
22
  style?: TextStyle;
23
+ /** a git graph across the screen, its lanes rows, as the page draws it; absent = down
24
+ * the screen, its lanes columns, as a terminal reads a history */
25
+ horizontal?: boolean;
23
26
  }
24
27
  /** A laid-out view: everything painting and the TUI's navigation read. */
25
28
  export interface Scene {
@@ -1,9 +1,10 @@
1
- import { activeNotation, buildHierarchy, compileView, defined, defaultLayoutDirection, FISHBONE_NOTATION, layoutPlaneKey, presetLayers, } from '@diagc/core/internal';
1
+ import { activeNotation, buildHierarchy, compileView, defined, defaultLayoutDirection, FISHBONE_NOTATION, GIT_NOTATION, layoutPlaneKey, presetLayers, } from '@diagc/core/internal';
2
2
  import { notationAccents } from './accents.js';
3
3
  import { boxText, edgeText } from './content.js';
4
4
  import { SHADOW_REACH } from './dos.js';
5
5
  import { fishCells } from './fish.js';
6
6
  import { withNeverFolds } from './folds.js';
7
+ import { gitCells } from './git.js';
7
8
  import { layoutCells } from './layout.js';
8
9
  import { legendOf } from './legend.js';
9
10
  import { hidesKind } from './vocabulary.js';
@@ -45,10 +46,13 @@ export async function buildScene(input, glyphs) {
45
46
  for (const root of view.roots)
46
47
  walk(root, undefined);
47
48
  const labels = new Map(view.layoutEdges.map((e) => [e.id, edgeText(e, glyphs)]));
48
- // A fishbone is the fish, as on the page, whatever way the plane's settings say to flow.
49
+ // A fishbone is the fish and a git graph its lanes, whatever way the plane's
50
+ // settings say to flow.
49
51
  const laid = notation === FISHBONE_NOTATION
50
52
  ? fishCells(model, view, boxes)
51
- : await layoutCells(view, boxes, flowOf(input), labels);
53
+ : notation === GIT_NOTATION
54
+ ? gitCells(model, view, boxes, defined({ plane, across: input.horizontal }))
55
+ : await layoutCells(view, boxes, flowOf(input), labels);
52
56
  const room = input.style === 'dos' && laid.boxes.size > 0;
53
57
  const layout = room ? { ...laid, width: laid.width + SHADOW_REACH.x, height: laid.height + SHADOW_REACH.y } : laid;
54
58
  const accents = notationAccents(model, plane, notation, view.edges);
@@ -1,3 +1,4 @@
1
+ import { GIT_NOTATION } from '@diagc/core/internal';
1
2
  import { neverFolds } from '../text/vocabulary.js';
2
3
  import { onLegend } from './legend.js';
3
4
  import { clampScroll, follow, hitTest, nearest, readingOrder } from './nav.js';
@@ -89,8 +90,18 @@ function switchPlane(d, ctx, step) {
89
90
  const at = Math.max(0, planes.findIndex((p) => p.id === (d.plane ?? planes[0].id)));
90
91
  const plane = planes[(at + step + planes.length) % planes.length];
91
92
  // what the reader has open or shut stays as it was; the view is the new plane's
92
- const { panel, overview, legend } = d;
93
- return relayout({ ...openDiagram(d.name, ctx.model, ctx.overlay, plane.id), panel, overview, legend });
93
+ const { panel, overview, legend, horizontal } = d;
94
+ const kept = { panel, overview, legend, ...(horizontal === true ? { horizontal } : {}) };
95
+ return relayout({ ...openDiagram(d.name, ctx.model, ctx.overlay, plane.id), ...kept });
96
+ }
97
+ /** A git graph turned across the screen, or back down it, the selection kept in view;
98
+ * anything else says it does not turn, or the key would seem to do nothing. */
99
+ function turnGit(d, ctx) {
100
+ if (ctx.scene?.notation !== GIT_NOTATION)
101
+ return say(d, 'only a git graph turns across the screen');
102
+ const { horizontal, ...rest } = d;
103
+ const turned = horizontal === true ? rest : { ...rest, horizontal: true };
104
+ return relayout({ ...turned, scroll: { x: 0, y: 0 }, ...(d.selected !== undefined ? { follow: true } : {}) });
94
105
  }
95
106
  function toggleLayer(d, ctx, n) {
96
107
  const layer = ctx.model?.layers[n - 1];
@@ -218,6 +229,7 @@ const KEYS = {
218
229
  i: (d) => stay({ ...d, panel: !d.panel }),
219
230
  o: (d, ctx) => toggleOverview(d, ctx),
220
231
  L: (d, ctx) => toggleLegend(d, ctx),
232
+ H: (d, ctx) => turnGit(d, ctx),
221
233
  '?': (d) => stay({ ...d, help: !d.help }),
222
234
  s: (d, ctx) => ({ diagram: d, effects: [{ kind: 'relayout' }], style: otherStyle(ctx.style) }),
223
235
  r: (d) => ({ diagram: d, effects: [{ kind: 'reload' }] }),
@@ -29,6 +29,7 @@ const HELP = [
29
29
  ['i', 'details of the box'],
30
30
  ['o', 'overview on / off'],
31
31
  ['L', 'legend on / off'],
32
+ ['H', 'a git graph across / down'],
32
33
  ['s', 'DOS style on / off'],
33
34
  ['Shift-arrows, PgUp, PgDn', 'scroll'],
34
35
  ['Home, End, mouse wheel', 'scroll'],
@@ -47,6 +47,8 @@ export interface DiagramState {
47
47
  };
48
48
  /** scroll the selection into view once the layout it waits for arrives (`settle`) */
49
49
  follow?: boolean;
50
+ /** a git graph turned across the screen (`H`); absent = down it */
51
+ horizontal?: true;
50
52
  }
51
53
  export interface TuiState {
52
54
  screen: 'list' | 'diagram';
package/dist/tui/state.js CHANGED
@@ -29,6 +29,7 @@ export function sceneInput(state, model, overlay, style) {
29
29
  ...(state.plane !== undefined ? { plane: state.plane } : {}),
30
30
  ...(root !== undefined ? { root } : {}),
31
31
  ...(style !== undefined ? { style } : {}),
32
+ ...(state.horizontal === true ? { horizontal: true } : {}),
32
33
  };
33
34
  }
34
35
  /** `state` fitted to a new picture: a selection the picture no longer draws is gone,
package/dist/watch.js CHANGED
@@ -1,6 +1,8 @@
1
+ import { existsSync } from 'node:fs';
2
+ import { rm } from 'node:fs/promises';
1
3
  import { watch as chokidarWatch } from 'chokidar';
2
4
  import { errMessage } from '@diagc/core/internal';
3
- import { compileFile } from './compile.js';
5
+ import { artifactPathFor, compileFile } from './compile.js';
4
6
  /** Human-readable rendering of a compile event, shared by the one-shot
5
7
  * `compile` command, the `watch` command's live log, and the `studio` watcher
6
8
  * so all three surface success/failure identically. `ok:false` events are
@@ -65,12 +67,25 @@ export function startWatch(dir, outDir, opts = {}) {
65
67
  opts.onEvent?.({ file, ok: false, error: errMessage(e) });
66
68
  }
67
69
  };
68
- // Serialize compiles per file path: each event chains onto the previous
69
- // in-flight compile for the same path, so events for one file are processed
70
- // sequentially in trigger order (a slow earlier compile can no longer report
71
- // or write a stale result after a newer one). Different files still compile
72
- // concurrently.
73
- const runner = createSerialRunner(compile);
70
+ // A source that is gone takes its artifact with it: left behind, the studio
71
+ // would list the diagram again, read-only, from the stale copy. Reported as
72
+ // nothing — there is no result to print.
73
+ const remove = async (file) => {
74
+ try {
75
+ await rm(artifactPathFor(file, outDir, dir), { force: true });
76
+ }
77
+ catch {
78
+ /* a directory already gone, or unreadable: nothing left to remove */
79
+ }
80
+ };
81
+ // Serialize work per file path: each event chains onto the previous in-flight
82
+ // task for the same path, so events for one file are processed sequentially in
83
+ // trigger order (a slow earlier compile can no longer report or write a stale
84
+ // result after a newer one). Different files still compile concurrently. What
85
+ // a task does is decided when it runs, from the disk: a file that is there is
86
+ // compiled, one that is not has its artifact removed — so an add followed by an
87
+ // unlink, or the reverse, lands on whatever the disk says last.
88
+ const runner = createSerialRunner((file) => (existsSync(file) ? compile(file) : remove(file)));
74
89
  const onFsEvent = (file) => {
75
90
  if (!file.endsWith('.diagram.ts') && !file.endsWith('.diagram.json'))
76
91
  return;
@@ -78,6 +93,7 @@ export function startWatch(dir, outDir, opts = {}) {
78
93
  };
79
94
  watcher.on('add', onFsEvent);
80
95
  watcher.on('change', onFsEvent);
96
+ watcher.on('unlink', onFsEvent);
81
97
  return {
82
98
  async close() {
83
99
  await watcher.close();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@diagc/cli",
3
- "version": "1.7.0",
3
+ "version": "1.9.0",
4
4
  "description": "Author software-architecture diagrams as code, compile them to a validated model, edit them in a local studio, and publish pages and images.",
5
5
  "license": "AGPL-3.0-only",
6
6
  "author": "Bogdan Frankovskyi",
@@ -45,7 +45,7 @@
45
45
  "fast-glob": "^3.3.0",
46
46
  "jiti": "^2.0.0",
47
47
  "playwright-core": "^1.62.0",
48
- "@diagc/core": "1.7.0"
48
+ "@diagc/core": "1.9.0"
49
49
  },
50
50
  "publishConfig": {
51
51
  "access": "public"