@diagc/cli 1.6.0 → 1.8.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 (45) hide show
  1. package/README.md +8 -3
  2. package/assets/guide/git-graph.md +3 -0
  3. package/assets/guide/index.md +3 -3
  4. package/assets/skill/SKILL.md +1 -1
  5. package/assets/studio/assets/index-CB6jjAka.js +112 -0
  6. package/assets/studio/index.html +1 -1
  7. package/assets/viewer/index.html +23 -23
  8. package/dist/cli/parse.d.ts +8 -1
  9. package/dist/cli/parse.js +13 -1
  10. package/dist/cli/run.js +6 -2
  11. package/dist/cli.js +6 -2
  12. package/dist/commands/show.d.ts +1 -1
  13. package/dist/commands/show.js +12 -2
  14. package/dist/commands/tui.d.ts +1 -1
  15. package/dist/commands/tui.js +10 -2
  16. package/dist/text/ansi.js +11 -5
  17. package/dist/text/canvas.d.ts +9 -2
  18. package/dist/text/canvas.js +25 -7
  19. package/dist/text/dos.d.ts +69 -0
  20. package/dist/text/dos.js +93 -0
  21. package/dist/text/git.d.ts +52 -0
  22. package/dist/text/git.js +274 -0
  23. package/dist/text/glyphs.d.ts +4 -3
  24. package/dist/text/glyphs.js +18 -2
  25. package/dist/text/layout.d.ts +39 -1
  26. package/dist/text/layout.js +10 -7
  27. package/dist/text/legend.js +17 -13
  28. package/dist/text/paint.d.ts +6 -4
  29. package/dist/text/paint.js +164 -17
  30. package/dist/text/scene.d.ts +7 -0
  31. package/dist/text/scene.js +16 -4
  32. package/dist/tui/actions.d.ts +5 -0
  33. package/dist/tui/actions.js +17 -2
  34. package/dist/tui/app.d.ts +3 -0
  35. package/dist/tui/app.js +18 -5
  36. package/dist/tui/nav.d.ts +16 -10
  37. package/dist/tui/nav.js +26 -4
  38. package/dist/tui/overview.d.ts +4 -2
  39. package/dist/tui/overview.js +38 -8
  40. package/dist/tui/screen.d.ts +10 -0
  41. package/dist/tui/screen.js +105 -23
  42. package/dist/tui/state.d.ts +14 -10
  43. package/dist/tui/state.js +13 -4
  44. package/package.json +2 -2
  45. 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
+ }
@@ -3,13 +3,14 @@ export declare const UP = 1;
3
3
  export declare const DOWN = 2;
4
4
  export declare const LEFT = 4;
5
5
  export declare const RIGHT = 8;
6
- export type Weight = 'light' | 'heavy' | 'dashed';
6
+ export type Weight = 'light' | 'heavy' | 'dashed' | 'double';
7
7
  export type Corner = 'round' | 'chamfer';
8
8
  export type ArrowDirection = 'up' | 'down' | 'left' | 'right';
9
9
  export interface Glyphs {
10
10
  /** the character for a cell whose lines leave it in `mask`'s directions; `corner`
11
- * applies only while the mask is a plain corner */
12
- line(mask: number, weight: Weight, corner?: Corner): string;
11
+ * applies only while the mask is a plain corner, and `minor` names the directions
12
+ * drawn lighter than `weight`, which only a double line has characters to show */
13
+ line(mask: number, weight: Weight, corner?: Corner, minor?: number): string;
13
14
  arrow(direction: ArrowDirection): string;
14
15
  /** a line one cell a row, a fishbone's bone or tick: falling to the right, or rising */
15
16
  slant(falling: boolean): string;
@@ -15,6 +15,20 @@ function table(chars) {
15
15
  const LIGHT = table(' │││─┘┐┤─└┌├─┴┬┼');
16
16
  const HEAVY = table(' ┃┃┃━┛┓┫━┗┏┣━┻┳╋');
17
17
  const CORNERS = new Set([DOWN | RIGHT, DOWN | LEFT, UP | RIGHT, UP | LEFT]);
18
+ const DOUBLE = table(' ║║║═╝╗╣═╚╔╠═╩╦╬');
19
+ // The mixed junctions: double one way and single the other. Unicode has them only
20
+ // whole, so a line is double along an axis when any of its directions there is.
21
+ const DOUBLE_ACROSS = table(' │││═╛╕╡═╘╒╞═╧╤╪');
22
+ const DOUBLE_DOWN = table(' ║║║─╜╖╢─╙╓╟─╨╥╫');
23
+ /** A double line, with what joins it single where `minor` says. */
24
+ function double(mask, minor) {
25
+ const strong = mask & ~minor;
26
+ const across = (strong & (LEFT | RIGHT)) !== 0;
27
+ const down = (strong & (UP | DOWN)) !== 0;
28
+ if (across === down)
29
+ return across ? DOUBLE(mask) : LIGHT(mask);
30
+ return across ? DOUBLE_ACROSS(mask) : DOUBLE_DOWN(mask);
31
+ }
18
32
  const ROUND = { [DOWN | RIGHT]: '╭', [DOWN | LEFT]: '╮', [UP | RIGHT]: '╰', [UP | LEFT]: '╯' };
19
33
  const CHAMFER = {
20
34
  [DOWN | RIGHT]: '╱',
@@ -23,7 +37,9 @@ const CHAMFER = {
23
37
  [UP | LEFT]: '╱',
24
38
  };
25
39
  export const UNICODE = {
26
- line(mask, weight, corner) {
40
+ line(mask, weight, corner, minor = 0) {
41
+ if (weight === 'double')
42
+ return double(mask, minor);
27
43
  if (corner !== undefined && CORNERS.has(mask))
28
44
  return (corner === 'round' ? ROUND : CHAMFER)[mask];
29
45
  if (weight === 'heavy')
@@ -68,7 +84,7 @@ export const ASCII = {
68
84
  if (vertical)
69
85
  return weight === 'dashed' ? ':' : '|';
70
86
  if (horizontal)
71
- return weight === 'dashed' ? '.' : weight === 'heavy' ? '=' : '-';
87
+ return weight === 'dashed' ? '.' : weight === 'heavy' || weight === 'double' ? '=' : '-';
72
88
  return '+';
73
89
  },
74
90
  arrow: (direction) => ({ up: '^', down: 'v', left: '<', right: '>' })[direction],
@@ -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
@@ -47,6 +76,15 @@ export interface TextLayout {
47
76
  * root and on every container alike.
48
77
  */
49
78
  export declare const CELL_OPTIONS: Readonly<Record<string, string>>;
79
+ /** How the cells are laid out: the way the plane flows, and how far right and down a
80
+ * box's shadow falls where the style casts one (DOS), which keeps it off a frame. */
81
+ export interface Flow {
82
+ direction: string;
83
+ shadow?: {
84
+ x: number;
85
+ y: number;
86
+ };
87
+ }
50
88
  /** Where a box is from an end of a route that stops beside it: the direction (a
51
89
  * glyph mask bit) to step from the end to reach its border; undefined when the end is
52
90
  * not beside it. */
@@ -58,4 +96,4 @@ export declare const STEP: Readonly<Record<number, CellPoint>>;
58
96
  * so that turning a layer on or off never moves a box (the renderer's rule); the
59
97
  * routes of the edges actually drawn are picked from the result by id.
60
98
  */
61
- export declare function layoutCells(view: CompiledView, boxes: ReadonlyMap<string, BoxText>, direction: string, labels: ReadonlyMap<string, string>): Promise<TextLayout>;
99
+ export declare function layoutCells(view: CompiledView, boxes: ReadonlyMap<string, BoxText>, flow: Flow, labels: ReadonlyMap<string, string>): Promise<TextLayout>;
@@ -25,8 +25,9 @@ export const CELL_OPTIONS = {
25
25
  'elk.separateConnectedComponents': 'true',
26
26
  };
27
27
  /** Inside a container's frame: the title row and a blank one above the children, a
28
- * row below, two columns either side. */
29
- const CONTAINER_PADDING = '[top=2,left=2,bottom=1,right=2]';
28
+ * row below, two columns either side, and the reach of a child's shadow beyond that,
29
+ * as the page's padding holds it. */
30
+ const containerPadding = ({ x, y } = { x: 0, y: 0 }) => `[top=2,left=2,bottom=${1 + y},right=${2 + x}]`;
30
31
  /** The gaps for a flow. A cell is about twice as tall as it is wide, so a sideways
31
32
  * flow's gap between neighbours, counted in rows, is half a downward one's, counted in
32
33
  * columns, and its gap between levels twice: turned, the boxes keep their spacing. Only
@@ -38,7 +39,8 @@ function cellOptions(direction) {
38
39
  return { ...CELL_OPTIONS, 'elk.spacing.nodeNode': '2', 'elk.layered.spacing.nodeNodeBetweenLayers': '4' };
39
40
  }
40
41
  const elk = new ELK();
41
- function elkNode(vn, boxes, direction) {
42
+ function elkNode(vn, boxes, flow) {
43
+ const { direction } = flow;
42
44
  const box = boxes.get(vn.id);
43
45
  const width = box?.width ?? 5;
44
46
  const height = box?.height ?? 3;
@@ -54,11 +56,11 @@ function elkNode(vn, boxes, direction) {
54
56
  layoutOptions: {
55
57
  ...cellOptions(direction),
56
58
  'elk.direction': direction,
57
- 'elk.padding': CONTAINER_PADDING,
59
+ 'elk.padding': containerPadding(flow.shadow),
58
60
  'elk.nodeSize.constraints': 'MINIMUM_SIZE',
59
61
  'elk.nodeSize.minimum': vertical ? `(${height}, ${width})` : `(${width}, ${height})`,
60
62
  },
61
- children: vn.children.map((c) => elkNode(c, boxes, direction)),
63
+ children: vn.children.map((c) => elkNode(c, boxes, flow)),
62
64
  };
63
65
  }
64
66
  function elkEdges(view, labels) {
@@ -309,7 +311,8 @@ function normalize(boxes, routes) {
309
311
  * so that turning a layer on or off never moves a box (the renderer's rule); the
310
312
  * routes of the edges actually drawn are picked from the result by id.
311
313
  */
312
- export async function layoutCells(view, boxes, direction, labels) {
314
+ export async function layoutCells(view, boxes, flow, labels) {
315
+ const { direction } = flow;
313
316
  if (view.roots.length === 0)
314
317
  return { width: 0, height: 0, boxes: new Map(), routes: new Map() };
315
318
  const graph = {
@@ -320,7 +323,7 @@ export async function layoutCells(view, boxes, direction, labels) {
320
323
  'elk.padding': '[top=0,left=0,bottom=0,right=0]',
321
324
  'elk.hierarchyHandling': 'INCLUDE_CHILDREN',
322
325
  },
323
- children: view.roots.map((vn) => elkNode(vn, boxes, direction)),
326
+ children: view.roots.map((vn) => elkNode(vn, boxes, flow)),
324
327
  edges: elkEdges(view, labels),
325
328
  };
326
329
  const laid = collect(await elk.layout(graph));
@@ -1,8 +1,9 @@
1
1
  import { buildHierarchy, presetLayers, relationLayer, relationOnPlane, scopeToRoot, } from '@diagc/core/internal';
2
2
  import { Canvas } from './canvas.js';
3
3
  import { typeMark } from './content.js';
4
+ import { dosFill, dosSlots } from './dos.js';
4
5
  import { DOWN, LEFT, RIGHT } from './glyphs.js';
5
- import { accentCss, CORNER, rgb, WEIGHT } from './paint.js';
6
+ import { accentCss, colorCss, CORNER, rgb, WEIGHT } from './paint.js';
6
7
  import { KIND_LOOKS, kindLook, TYPE_LOOKS, typeLook } from './vocabulary.js';
7
8
  import { cellWidth, fitCells, printable } from './width.js';
8
9
  /** A swatch's cells: three, the width of a line with a mark at each end. */
@@ -53,13 +54,14 @@ function lineSwatch(look, glyphs) {
53
54
  return `${end(look.start, 'left')}${line}${end(look.end, 'right')}`;
54
55
  }
55
56
  /** A box of the type as the picture draws it: the mark its name follows where it has
56
- * one, else the top of its border, which carries its corners and its dashes. */
57
- function shapeSwatch(type, look, glyphs) {
57
+ * one, else the top of its border, which carries its corners and its dashes (in `dos`,
58
+ * square and double). */
59
+ function shapeSwatch(type, look, glyphs, dos) {
58
60
  const mark = typeMark(type, look.shape, glyphs);
59
61
  if (mark !== undefined)
60
62
  return centre(mark);
61
- const weight = look.shape === 'bar' ? 'heavy' : look.dashed === true ? 'dashed' : 'light';
62
- const corner = CORNER[look.shape];
63
+ const weight = look.shape === 'bar' ? 'heavy' : look.dashed === true ? 'dashed' : dos ? 'double' : 'light';
64
+ const corner = dos ? undefined : CORNER[look.shape];
63
65
  return `${glyphs.line(DOWN | RIGHT, weight, corner)}${glyphs.line(LEFT | RIGHT, weight)}${glyphs.line(DOWN | LEFT, weight, corner)}`;
64
66
  }
65
67
  const vocabulary = (caption) => caption !== undefined ? { vocabulary: true } : {};
@@ -121,17 +123,18 @@ function kindRows(scene, glyphs) {
121
123
  }
122
124
  function typeRows(scene, glyphs) {
123
125
  const { model } = scene.input;
124
- const accents = agreed([...scene.nodes.values()].flatMap((vn) => vn.node.type === undefined
125
- ? []
126
- : [[vn.node.type, accentCss(model, vn.node, scene.notation, scene.accents)]]));
126
+ const slots = scene.input.style === 'dos' ? dosSlots(model, scene.notation) : undefined;
127
+ // a DOS box is filled in its own colour or its type's slot, never the notation's accent
128
+ const css = (node) => slots === undefined ? accentCss(model, node, scene.notation, scene.accents) : colorCss(model, node, scene.accents);
129
+ const accents = agreed([...scene.nodes.values()].flatMap((vn) => vn.node.type === undefined ? [] : [[vn.node.type, css(vn.node)]]));
127
130
  return ordered(accents.keys(), Object.keys(TYPE_LOOKS)).map((type) => {
128
131
  const look = typeLook(type, scene.notation);
129
132
  // `label: ''` keeps a glyph type's box free of a subtitle; it is not a caption
130
133
  const label = look.legend ?? (look.label === undefined || look.label === '' ? printable(type) : look.label);
131
134
  return {
132
135
  id: `types:${type}`,
133
- swatch: shapeSwatch(type, look, glyphs),
134
- style: colour(accents.get(type)),
136
+ swatch: shapeSwatch(type, look, glyphs, slots !== undefined),
137
+ style: slots === undefined ? colour(accents.get(type)) : { fg: dosFill(look.shape, accents.get(type), type, slots) },
135
138
  label,
136
139
  ...vocabulary(look.legend),
137
140
  };
@@ -156,7 +159,8 @@ function markRows(scene) {
156
159
  }
157
160
  /** The hand-written rows. One naming a kind or a type already keyed recaptions that row
158
161
  * in place, keeping its swatch; the rest are rows of their own. */
159
- function itemRows(items, derived, notation, glyphs) {
162
+ function itemRows(items, derived, scene, glyphs) {
163
+ const { notation } = scene;
160
164
  return items.flatMap((item, i) => {
161
165
  const label = printable(item.label);
162
166
  const target = item.kind !== undefined ? `kinds:${item.kind}` : item.type !== undefined ? `types:${item.type}` : '';
@@ -170,7 +174,7 @@ function itemRows(items, derived, notation, glyphs) {
170
174
  const swatch = item.kind !== undefined
171
175
  ? lineSwatch(kindLook({ kind: item.kind }, notation), glyphs)
172
176
  : item.type !== undefined
173
- ? shapeSwatch(item.type, typeLook(item.type, notation), glyphs)
177
+ ? shapeSwatch(item.type, typeLook(item.type, notation), glyphs, scene.input.style === 'dos')
174
178
  : item.color !== undefined
175
179
  ? centre(glyphs.mark('square'))
176
180
  : centre('');
@@ -195,7 +199,7 @@ export function legendOf(scene, glyphs) {
195
199
  types,
196
200
  marks: shown.includes('marks') ? markRows(scene) : [],
197
201
  };
198
- const items = itemRows(config.items ?? [], [...derived.kinds, ...derived.types], scene.notation, glyphs);
202
+ const items = itemRows(config.items ?? [], [...derived.kinds, ...derived.types], scene, glyphs);
199
203
  const sections = ['layers', 'kinds', 'types', 'marks', 'items']
200
204
  .map((s) => ({ title: TITLES[s], rows: s === 'items' ? items : derived[s] }))
201
205
  .filter((s) => s.rows.length > 0);
@@ -12,14 +12,16 @@ export interface PaintOptions {
12
12
  export declare const WEIGHT: Record<LineStyle, Weight>;
13
13
  export declare const CORNER: Partial<Record<TextShape, Corner>>;
14
14
  export declare const rgb: (css: string | undefined) => Color | undefined;
15
- /** A node's accent, as the renderer resolves it: its own colour, the one its notation
16
- * gives it (a lane's, a bone's), the model's colour for its type (or for every type),
17
- * then the notation's for the type. */
15
+ /** A node's own colour, as the renderer resolves it: its own, the one its notation
16
+ * gives it (a lane's, a bone's), the model's for its type (or for every type). */
17
+ export declare function colorCss(model: DiagramModel, node: DiagramNode, accents: Accents): string | undefined;
18
+ /** A node's accent: its own colour, then the notation's for the type. */
18
19
  export declare function accentCss(model: DiagramModel, node: DiagramNode, notation: NotationId | undefined, accents: Accents): string | undefined;
19
20
  /**
20
21
  * The scene as a canvas, in layers: open containers' frames from the outside in,
21
22
  * then the edges' lines, then the boxes over them (a box clears what is under it)
22
23
  * and the frames' titles, then edge labels and the ends of the edges, last so
23
- * nothing covers an arrowhead.
24
+ * nothing covers an arrowhead. In the DOS style (the scene's `style`) it all lies on
25
+ * the desktop, the boxes' shadows laid on it first.
24
26
  */
25
27
  export declare function paint(scene: Scene, options: PaintOptions): Canvas;