@diagc/cli 1.5.0 → 1.7.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.
- package/README.md +8 -3
- package/assets/guide/index.md +1 -1
- package/assets/skill/SKILL.md +1 -1
- package/dist/cli/io.d.ts +5 -0
- package/dist/cli/io.js +4 -0
- package/dist/cli/parse.d.ts +7 -0
- package/dist/cli/parse.js +25 -0
- package/dist/cli/run.js +4 -0
- package/dist/cli.js +24 -2
- package/dist/commands/shared.d.ts +4 -0
- package/dist/commands/shared.js +13 -0
- package/dist/commands/show.d.ts +5 -0
- package/dist/commands/show.js +115 -0
- package/dist/commands/tui.d.ts +3 -0
- package/dist/commands/tui.js +44 -0
- package/dist/init.d.ts +1 -1
- package/dist/init.js +1 -1
- package/dist/text/accents.d.ts +9 -0
- package/dist/text/accents.js +83 -0
- package/dist/text/ansi.d.ts +28 -0
- package/dist/text/ansi.js +117 -0
- package/dist/text/braille.d.ts +28 -0
- package/dist/text/braille.js +58 -0
- package/dist/text/canvas.d.ts +72 -0
- package/dist/text/canvas.js +173 -0
- package/dist/text/content.d.ts +32 -0
- package/dist/text/content.js +90 -0
- package/dist/text/dos.d.ts +69 -0
- package/dist/text/dos.js +93 -0
- package/dist/text/fish.d.ts +27 -0
- package/dist/text/fish.js +209 -0
- package/dist/text/folds.d.ts +14 -0
- package/dist/text/folds.js +45 -0
- package/dist/text/glyphs.d.ts +32 -0
- package/dist/text/glyphs.js +100 -0
- package/dist/text/layout.d.ts +70 -0
- package/dist/text/layout.js +337 -0
- package/dist/text/legend.d.ts +44 -0
- package/dist/text/legend.js +256 -0
- package/dist/text/paint.d.ts +27 -0
- package/dist/text/paint.js +260 -0
- package/dist/text/render.d.ts +11 -0
- package/dist/text/render.js +28 -0
- package/dist/text/scene.d.ts +44 -0
- package/dist/text/scene.js +58 -0
- package/dist/text/vocabulary.d.ts +37 -0
- package/dist/text/vocabulary.js +211 -0
- package/dist/text/width.d.ts +15 -0
- package/dist/text/width.js +181 -0
- package/dist/tui/actions.d.ts +15 -0
- package/dist/tui/actions.js +300 -0
- package/dist/tui/app.d.ts +34 -0
- package/dist/tui/app.js +402 -0
- package/dist/tui/details.d.ts +3 -0
- package/dist/tui/details.js +54 -0
- package/dist/tui/keys.d.ts +33 -0
- package/dist/tui/keys.js +113 -0
- package/dist/tui/kitty.d.ts +36 -0
- package/dist/tui/kitty.js +65 -0
- package/dist/tui/legend.d.ts +14 -0
- package/dist/tui/legend.js +18 -0
- package/dist/tui/nav.d.ts +31 -0
- package/dist/tui/nav.js +101 -0
- package/dist/tui/overview.d.ts +48 -0
- package/dist/tui/overview.js +145 -0
- package/dist/tui/pixels.d.ts +28 -0
- package/dist/tui/pixels.js +80 -0
- package/dist/tui/screen.d.ts +54 -0
- package/dist/tui/screen.js +416 -0
- package/dist/tui/state.d.ts +102 -0
- package/dist/tui/state.js +80 -0
- package/dist/tui/terminal.d.ts +21 -0
- package/dist/tui/terminal.js +53 -0
- package/dist/watch.d.ts +2 -0
- package/dist/watch.js +1 -0
- package/package.json +3 -2
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
import { parseColor } from './ansi.js';
|
|
2
|
+
import { Canvas } from './canvas.js';
|
|
3
|
+
import { BLACK, castShadows, CYAN, DESKTOP, dosFill, dosSlots, inkOn, mixed, WHITE, YELLOW } from './dos.js';
|
|
4
|
+
import { DOWN, LEFT, RIGHT, UP } from './glyphs.js';
|
|
5
|
+
import { STEP, towardBox } from './layout.js';
|
|
6
|
+
import { kindLook, typeLook } from './vocabulary.js';
|
|
7
|
+
import { cellWidth } from './width.js';
|
|
8
|
+
export const WEIGHT = { solid: 'light', dashed: 'dashed', heavy: 'heavy' };
|
|
9
|
+
export const CORNER = {
|
|
10
|
+
rounded: 'round',
|
|
11
|
+
cylinder: 'round',
|
|
12
|
+
dot: 'round',
|
|
13
|
+
hexagon: 'chamfer',
|
|
14
|
+
diamond: 'chamfer',
|
|
15
|
+
};
|
|
16
|
+
const LINE_STYLE = {
|
|
17
|
+
title: { bold: true },
|
|
18
|
+
subtitle: { dim: true },
|
|
19
|
+
note: { dim: true },
|
|
20
|
+
row: {},
|
|
21
|
+
};
|
|
22
|
+
export const rgb = (css) => {
|
|
23
|
+
const parsed = css === undefined ? undefined : parseColor(css);
|
|
24
|
+
return parsed === undefined ? undefined : { rgb: parsed };
|
|
25
|
+
};
|
|
26
|
+
/** A node's own colour, as the renderer resolves it: its own, the one its notation
|
|
27
|
+
* gives it (a lane's, a bone's), the model's for its type (or for every type). */
|
|
28
|
+
export function colorCss(model, node, accents) {
|
|
29
|
+
const typeColor = node.type !== undefined ? model.typeColors?.[node.type] : undefined;
|
|
30
|
+
return node.color ?? accents.nodes.get(node.id) ?? typeColor ?? model.typeColors?.['*'];
|
|
31
|
+
}
|
|
32
|
+
/** A node's accent: its own colour, then the notation's for the type. */
|
|
33
|
+
export function accentCss(model, node, notation, accents) {
|
|
34
|
+
return colorCss(model, node, accents) ?? typeLook(node.type, notation).accent;
|
|
35
|
+
}
|
|
36
|
+
/** A node's own colour (`colorCss`), as the CSS a terminal has to read. */
|
|
37
|
+
const ownCss = (p, id) => colorCss(p.scene.input.model, p.scene.nodes.get(id).node, p.scene.accents);
|
|
38
|
+
/** How a box's border is drawn: heavy when selected (and for a fork bar), dashed
|
|
39
|
+
* for a boundary, in the node's accent. In DOS a frame is double: a box's white on its
|
|
40
|
+
* fill, an open group's in its own colour, never the palette's, and the selection's
|
|
41
|
+
* yellow. */
|
|
42
|
+
function borderInk(p, id) {
|
|
43
|
+
const box = p.scene.boxes.get(id);
|
|
44
|
+
if (p.dos !== undefined) {
|
|
45
|
+
const weight = box.shape === 'bar' ? 'heavy' : box.dashed ? 'dashed' : 'double';
|
|
46
|
+
const fg = id === p.selected ? YELLOW : isFrame(p.scene, id) ? (rgb(ownCss(p, id)) ?? WHITE) : WHITE;
|
|
47
|
+
return { weight, style: { fg } };
|
|
48
|
+
}
|
|
49
|
+
const fg = rgb(accentCss(p.scene.input.model, p.scene.nodes.get(id).node, p.scene.notation, p.scene.accents));
|
|
50
|
+
const weight = id === p.selected || box.shape === 'bar' ? 'heavy' : box.dashed ? 'dashed' : 'light';
|
|
51
|
+
return { weight, style: fg !== undefined ? { fg } : {} };
|
|
52
|
+
}
|
|
53
|
+
/** The corner a box's shape gives its frame; DOS has square ones only. */
|
|
54
|
+
const cornerOf = (p, id) => p.dos === undefined ? CORNER[p.scene.boxes.get(id).shape] : undefined;
|
|
55
|
+
/** An open container's frame. Its title is written later (`drawTitle`). */
|
|
56
|
+
function drawFrame(p, id, g) {
|
|
57
|
+
const ink = borderInk(p, id);
|
|
58
|
+
p.canvas.rect(g, ink.weight, ink.style, cornerOf(p, id));
|
|
59
|
+
}
|
|
60
|
+
/** A box's fill in the DOS style (`dosFill`) and its ink; the small print is the ink 70%
|
|
61
|
+
* over the fill. */
|
|
62
|
+
function cardOf(p, slots, id) {
|
|
63
|
+
const fill = dosFill(p.scene.boxes.get(id).shape, ownCss(p, id), p.scene.nodes.get(id).node.type, slots);
|
|
64
|
+
const ink = inkOn(fill.rgb);
|
|
65
|
+
const small = { fg: mixed(ink.rgb, fill.rgb, 0.7) };
|
|
66
|
+
return { fill, ink, lines: { title: { bold: true }, subtitle: small, note: small, row: {} } };
|
|
67
|
+
}
|
|
68
|
+
/** A DOS box's ground: its fill under the whole box, a table's head cyan. */
|
|
69
|
+
function groundCard(p, box, g, card) {
|
|
70
|
+
p.canvas.ground(g, { bg: card.fill, fg: card.ink });
|
|
71
|
+
if (box.shape !== 'table')
|
|
72
|
+
return;
|
|
73
|
+
const head = box.lines.findIndex((line) => line.role === 'row');
|
|
74
|
+
const height = head < 0 ? box.lines.length : head;
|
|
75
|
+
p.canvas.ground({ x: g.x + 1, y: g.y + 1, width: g.width - 2, height }, { bg: CYAN, fg: BLACK });
|
|
76
|
+
}
|
|
77
|
+
/** An open container's title, in its top border. Written after the edges: a line that
|
|
78
|
+
* crosses the border there loses a cell, where the other way round the title would
|
|
79
|
+
* lose a letter. */
|
|
80
|
+
function drawTitle(p, id, g) {
|
|
81
|
+
const title = p.scene.boxes.get(id).lines[0]?.text ?? '';
|
|
82
|
+
const style = { bold: true, inverse: id === p.selected };
|
|
83
|
+
if (title !== '')
|
|
84
|
+
p.canvas.text({ x: g.x + 2, y: g.y }, ` ${title} `, style, g.x + g.width - 2);
|
|
85
|
+
}
|
|
86
|
+
/** A leaf or folded box: border, shape details, and its lines (centred, but a table's
|
|
87
|
+
* rows left-aligned so their columns line up). `weight` overrides the border's. */
|
|
88
|
+
function drawBox(p, id, g, weight) {
|
|
89
|
+
const box = p.scene.boxes.get(id);
|
|
90
|
+
const ink = { ...borderInk(p, id), ...(weight !== undefined ? { weight } : {}) };
|
|
91
|
+
const rule = (y) => p.canvas.segment({ x: g.x, y }, { x: g.x + g.width - 1, y }, ink.weight, ink.style);
|
|
92
|
+
p.canvas.clear({ x: g.x + 1, y: g.y + 1, width: g.width - 2, height: g.height - 2 });
|
|
93
|
+
const card = p.dos === undefined ? undefined : cardOf(p, p.dos, id);
|
|
94
|
+
if (card !== undefined)
|
|
95
|
+
groundCard(p, box, g, card);
|
|
96
|
+
p.canvas.rect(g, ink.weight, ink.style, cornerOf(p, id));
|
|
97
|
+
let y = g.y + 1;
|
|
98
|
+
if (box.shape === 'cylinder')
|
|
99
|
+
rule(y++);
|
|
100
|
+
let ruled = false;
|
|
101
|
+
for (const line of box.lines) {
|
|
102
|
+
if (line.role === 'row' && !ruled) {
|
|
103
|
+
rule(y++);
|
|
104
|
+
ruled = true;
|
|
105
|
+
}
|
|
106
|
+
const x = line.role === 'row' ? g.x + 2 : g.x + Math.floor((g.width - cellWidth(line.text)) / 2);
|
|
107
|
+
const style = line.role === 'title' && id === p.selected
|
|
108
|
+
? { bold: true, inverse: true }
|
|
109
|
+
: (card?.lines ?? LINE_STYLE)[line.role];
|
|
110
|
+
p.canvas.text({ x, y: y++ }, line.text, style, g.x + g.width - 1);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
function edgeInk(p, edge) {
|
|
114
|
+
const weight = WEIGHT[kindLook(edge, p.scene.notation).line];
|
|
115
|
+
const fg = rgb(edge.style?.color ?? edge.tint ?? p.scene.accents.edges.get(edge.id));
|
|
116
|
+
const base = fg !== undefined ? { fg } : {};
|
|
117
|
+
if (p.selected === undefined)
|
|
118
|
+
return { weight, style: base };
|
|
119
|
+
const mine = edge.from === p.selected || edge.to === p.selected;
|
|
120
|
+
return { weight, style: { ...base, ...(mine ? { bold: true } : { dim: true }) } };
|
|
121
|
+
}
|
|
122
|
+
const OPPOSITE = { [UP]: DOWN, [DOWN]: UP, [LEFT]: RIGHT, [RIGHT]: LEFT };
|
|
123
|
+
const ARROW = { [UP]: 'up', [DOWN]: 'down', [LEFT]: 'left', [RIGHT]: 'right' };
|
|
124
|
+
/** Runs the line from an end into the border beside it, so the border shows a
|
|
125
|
+
* junction (`┬`, `├`, …) where the line leaves or meets the box. */
|
|
126
|
+
function join(p, end, g, ink) {
|
|
127
|
+
const dir = g === undefined ? undefined : towardBox(end, g);
|
|
128
|
+
if (dir === undefined)
|
|
129
|
+
return;
|
|
130
|
+
p.canvas.stroke(end, dir, ink.weight, ink.style);
|
|
131
|
+
const step = STEP[dir];
|
|
132
|
+
p.canvas.stroke({ x: end.x + step.x, y: end.y + step.y }, OPPOSITE[dir], 'light');
|
|
133
|
+
}
|
|
134
|
+
/** Which way a mark at an end points: at the box beside it. Not along the last
|
|
135
|
+
* segment, which can run alongside the box — elk's last stub into a box is often under
|
|
136
|
+
* a cell, and gone once the end is moved off the border. */
|
|
137
|
+
function arrowOf(end, prev, box) {
|
|
138
|
+
const toward = box === undefined ? undefined : towardBox(end, box);
|
|
139
|
+
if (toward !== undefined)
|
|
140
|
+
return ARROW[toward];
|
|
141
|
+
if (end.y !== prev.y)
|
|
142
|
+
return end.y > prev.y ? 'down' : 'up';
|
|
143
|
+
return end.x > prev.x ? 'right' : 'left';
|
|
144
|
+
}
|
|
145
|
+
/** One end of an edge: its mark, or with none the line run into the border. */
|
|
146
|
+
function drawEnd(p, edge, end) {
|
|
147
|
+
const points = p.scene.layout.routes.get(edge.id).points;
|
|
148
|
+
if (points.length < 2)
|
|
149
|
+
return;
|
|
150
|
+
const look = kindLook(edge, p.scene.notation);
|
|
151
|
+
const [at, prev] = end === 'start' ? [points[0], points[1]] : [points.at(-1), points.at(-2)];
|
|
152
|
+
const box = p.scene.layout.boxes.get(end === 'start' ? edge.from : edge.to);
|
|
153
|
+
const mark = end === 'start' ? (look.start ?? 'none') : look.end;
|
|
154
|
+
const ink = edgeInk(p, edge);
|
|
155
|
+
// in DOS a mark is white of its own, not the ground's, to stay bright in a shadow
|
|
156
|
+
const style = p.dos === undefined ? ink.style : { fg: WHITE, ...ink.style };
|
|
157
|
+
if (mark === 'none')
|
|
158
|
+
join(p, at, box, ink);
|
|
159
|
+
else if (mark === 'arrow')
|
|
160
|
+
p.canvas.put(at, p.glyphs.arrow(arrowOf(at, prev, box)), style);
|
|
161
|
+
else
|
|
162
|
+
p.canvas.put(at, p.glyphs.mark(mark), style);
|
|
163
|
+
}
|
|
164
|
+
const isFrame = (scene, id) => {
|
|
165
|
+
const vn = scene.nodes.get(id);
|
|
166
|
+
return vn.state === 'expanded' && vn.children.length > 0;
|
|
167
|
+
};
|
|
168
|
+
/** A route of a fish: its straight runs as lines, its slants one character a cell, up
|
|
169
|
+
* to the cell it ends on, which is the line it meets. */
|
|
170
|
+
function drawFishRoute(p, points, ink) {
|
|
171
|
+
for (let i = 1; i < points.length; i++) {
|
|
172
|
+
const [a, b] = [points[i - 1], points[i]];
|
|
173
|
+
if (a.x === b.x || a.y === b.y) {
|
|
174
|
+
p.canvas.segment(a, b, ink.weight, ink.style);
|
|
175
|
+
continue;
|
|
176
|
+
}
|
|
177
|
+
const [dx, dy] = [Math.sign(b.x - a.x), Math.sign(b.y - a.y)];
|
|
178
|
+
const slant = p.glyphs.slant(dx === dy);
|
|
179
|
+
for (let x = a.x, y = a.y; x !== b.x; x += dx, y += dy)
|
|
180
|
+
p.canvas.put({ x, y }, slant, ink.style);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* A fishbone as the fish (fish.ts): the lines first, then the head's box, heavy, and
|
|
185
|
+
* the spine run into its border, then the words, a bone's label bold in the bone's
|
|
186
|
+
* colour, and last the boxes of what is not on the fish. A word is selected as a title
|
|
187
|
+
* is, in reverse.
|
|
188
|
+
*/
|
|
189
|
+
function paintFish(p, fish, edges) {
|
|
190
|
+
const { layout } = p.scene;
|
|
191
|
+
const boxes = [...layout.boxes].filter(([id]) => id !== fish.head && !fish.words.has(id));
|
|
192
|
+
if (p.dos !== undefined)
|
|
193
|
+
castShadows(p.canvas, [layout.boxes.get(fish.head), ...boxes.map(([, g]) => g)]);
|
|
194
|
+
for (const edge of edges)
|
|
195
|
+
drawFishRoute(p, layout.routes.get(edge.id).points, edgeInk(p, edge));
|
|
196
|
+
drawBox(p, fish.head, layout.boxes.get(fish.head), 'heavy');
|
|
197
|
+
const { y, from, to } = fish.spine;
|
|
198
|
+
p.canvas.segment({ x: from, y }, { x: to, y }, 'heavy', borderInk(p, fish.head).style);
|
|
199
|
+
for (const [id, lines] of fish.words) {
|
|
200
|
+
const label = fish.labels.has(id);
|
|
201
|
+
const style = {
|
|
202
|
+
...(label ? { ...borderInk(p, id).style, bold: true } : {}),
|
|
203
|
+
...(id === p.selected ? { bold: true, inverse: true } : {}),
|
|
204
|
+
};
|
|
205
|
+
for (const line of lines)
|
|
206
|
+
p.canvas.text(line, line.text, style);
|
|
207
|
+
}
|
|
208
|
+
for (const [id, g] of boxes)
|
|
209
|
+
drawBox(p, id, g);
|
|
210
|
+
}
|
|
211
|
+
/** An edge's label: in its line's ink, or in DOS yellow. */
|
|
212
|
+
const labelStyle = (p, edge) => {
|
|
213
|
+
const { style } = edgeInk(p, edge);
|
|
214
|
+
return p.dos === undefined ? style : { ...style, fg: YELLOW };
|
|
215
|
+
};
|
|
216
|
+
/**
|
|
217
|
+
* The scene as a canvas, in layers: open containers' frames from the outside in,
|
|
218
|
+
* then the edges' lines, then the boxes over them (a box clears what is under it)
|
|
219
|
+
* and the frames' titles, then edge labels and the ends of the edges, last so
|
|
220
|
+
* nothing covers an arrowhead. In the DOS style (the scene's `style`) it all lies on
|
|
221
|
+
* the desktop, the boxes' shadows laid on it first.
|
|
222
|
+
*/
|
|
223
|
+
export function paint(scene, options) {
|
|
224
|
+
const { layout } = scene;
|
|
225
|
+
const p = { canvas: new Canvas(layout.width, layout.height), scene, ...options };
|
|
226
|
+
if (scene.input.style === 'dos') {
|
|
227
|
+
p.dos = dosSlots(scene.input.model, scene.notation);
|
|
228
|
+
p.canvas.ground({ x: 0, y: 0, width: layout.width, height: layout.height }, DESKTOP);
|
|
229
|
+
}
|
|
230
|
+
const drawn = [...scene.nodes.keys()].flatMap((id) => {
|
|
231
|
+
const g = layout.boxes.get(id);
|
|
232
|
+
return g === undefined ? [] : [{ id, g, frame: isFrame(scene, id) }];
|
|
233
|
+
});
|
|
234
|
+
const edges = scene.view.edges.filter((e) => layout.routes.has(e.id));
|
|
235
|
+
if (layout.fish !== undefined) {
|
|
236
|
+
paintFish(p, layout.fish, edges);
|
|
237
|
+
return p.canvas;
|
|
238
|
+
}
|
|
239
|
+
if (p.dos !== undefined)
|
|
240
|
+
castShadows(p.canvas, drawn.filter((d) => !d.frame).map((d) => d.g));
|
|
241
|
+
for (const { id, g, frame } of drawn)
|
|
242
|
+
if (frame)
|
|
243
|
+
drawFrame(p, id, g);
|
|
244
|
+
for (const edge of edges) {
|
|
245
|
+
const { points } = layout.routes.get(edge.id);
|
|
246
|
+
const ink = edgeInk(p, edge);
|
|
247
|
+
for (let i = 1; i < points.length; i++)
|
|
248
|
+
p.canvas.segment(points[i - 1], points[i], ink.weight, ink.style);
|
|
249
|
+
}
|
|
250
|
+
for (const { id, g, frame } of drawn)
|
|
251
|
+
(frame ? drawTitle : drawBox)(p, id, g);
|
|
252
|
+
for (const edge of edges) {
|
|
253
|
+
const label = layout.routes.get(edge.id).label;
|
|
254
|
+
if (label !== undefined)
|
|
255
|
+
p.canvas.text(label, label.text, labelStyle(p, edge));
|
|
256
|
+
drawEnd(p, edge, 'start');
|
|
257
|
+
drawEnd(p, edge, 'end');
|
|
258
|
+
}
|
|
259
|
+
return p.canvas;
|
|
260
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type ColorMode } from './ansi.js';
|
|
2
|
+
import { type SceneInput } from './scene.js';
|
|
3
|
+
export interface TextOptions {
|
|
4
|
+
/** plain ASCII in place of box-drawing characters */
|
|
5
|
+
ascii: boolean;
|
|
6
|
+
color: ColorMode;
|
|
7
|
+
}
|
|
8
|
+
/** A diagram's view as lines of text, with the legend it declares; none when the view
|
|
9
|
+
* has nothing in it. A legend only offered (for shapes that say nothing of themselves)
|
|
10
|
+
* is left out, as the published picture leaves it out. */
|
|
11
|
+
export declare function renderToLines(input: SceneInput, options: TextOptions): Promise<string[]>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { serialize } from './ansi.js';
|
|
2
|
+
import { ASCII, UNICODE } from './glyphs.js';
|
|
3
|
+
import { legendCells } from './legend.js';
|
|
4
|
+
import { paint } from './paint.js';
|
|
5
|
+
import { buildScene } from './scene.js';
|
|
6
|
+
/** The picture with its legend beside it, as the corner it names would have it: over
|
|
7
|
+
* or under the picture with a blank row between, against its left or right edge. Not
|
|
8
|
+
* over the picture, as on a canvas, where a printed picture would lose what it covers.
|
|
9
|
+
* A legend wider than the picture starts at the left edge either way: set against the
|
|
10
|
+
* right one, it would push the picture along for the sake of its key. */
|
|
11
|
+
function withLegend(picture, legend, position) {
|
|
12
|
+
const indent = position.endsWith('right') ? Math.max(0, (picture[0]?.length ?? 0) - (legend[0]?.length ?? 0)) : 0;
|
|
13
|
+
const placed = legend.map((row) => [...Array.from({ length: indent }, () => ({ ch: ' ', style: {} })), ...row]);
|
|
14
|
+
return position.startsWith('top') ? [...placed, [], ...picture] : [...picture, [], ...placed];
|
|
15
|
+
}
|
|
16
|
+
/** A diagram's view as lines of text, with the legend it declares; none when the view
|
|
17
|
+
* has nothing in it. A legend only offered (for shapes that say nothing of themselves)
|
|
18
|
+
* is left out, as the published picture leaves it out. */
|
|
19
|
+
export async function renderToLines(input, options) {
|
|
20
|
+
const glyphs = options.ascii ? ASCII : UNICODE;
|
|
21
|
+
const scene = await buildScene(input, glyphs);
|
|
22
|
+
if (scene.layout.boxes.size === 0)
|
|
23
|
+
return [];
|
|
24
|
+
const picture = paint(scene, { glyphs }).cells(glyphs);
|
|
25
|
+
const legend = scene.legend?.declared === true ? scene.legend : undefined;
|
|
26
|
+
const cells = legend === undefined ? picture : withLegend(picture, legendCells(legend, glyphs), legend.position);
|
|
27
|
+
return serialize(cells, options.color);
|
|
28
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { type CompiledView, type DiagramModel, type HierarchyIndex, type LayoutOverlay, type NotationId, type ViewNode } from '@diagc/core/internal';
|
|
2
|
+
import { type Accents } from './accents.js';
|
|
3
|
+
import { type BoxText } from './content.js';
|
|
4
|
+
import { type TextStyle } from './dos.js';
|
|
5
|
+
import { type Pins } from './folds.js';
|
|
6
|
+
import type { Glyphs } from './glyphs.js';
|
|
7
|
+
import { type TextLayout } from './layout.js';
|
|
8
|
+
import { type TextLegend } from './legend.js';
|
|
9
|
+
/** What a text picture is a picture of. */
|
|
10
|
+
export interface SceneInput {
|
|
11
|
+
model: DiagramModel;
|
|
12
|
+
overlay?: LayoutOverlay;
|
|
13
|
+
/** absent = the model's first plane */
|
|
14
|
+
plane?: string;
|
|
15
|
+
/** the layers drawn; absent = the plane's presets (compileView's own rule) */
|
|
16
|
+
layers?: string[];
|
|
17
|
+
pins: Pins;
|
|
18
|
+
/** draw this container's interior only (the drill view) */
|
|
19
|
+
root?: string;
|
|
20
|
+
/** the style it is drawn in; absent = the terminal's own. DOS's boxes cast shadows,
|
|
21
|
+
* which the picture leaves room for at its right and its foot. */
|
|
22
|
+
style?: TextStyle;
|
|
23
|
+
}
|
|
24
|
+
/** A laid-out view: everything painting and the TUI's navigation read. */
|
|
25
|
+
export interface Scene {
|
|
26
|
+
input: SceneInput;
|
|
27
|
+
/** the compiled view, its `edges` cut to the ones the notation draws */
|
|
28
|
+
view: CompiledView;
|
|
29
|
+
layout: TextLayout;
|
|
30
|
+
boxes: Map<string, BoxText>;
|
|
31
|
+
/** every drawn node by id, in drawing order (parents before children) */
|
|
32
|
+
nodes: Map<string, ViewNode>;
|
|
33
|
+
/** the box each drawn node is drawn inside; undefined at the top level */
|
|
34
|
+
parentOf: Map<string, string | undefined>;
|
|
35
|
+
/** the plane's containment, over the nodes the active layers show */
|
|
36
|
+
hierarchy: HierarchyIndex;
|
|
37
|
+
notation?: NotationId;
|
|
38
|
+
/** the colours the notation gives boxes and lines that set none */
|
|
39
|
+
accents: Accents;
|
|
40
|
+
/** the key to what is drawn: declared by the diagram, or offered for what its
|
|
41
|
+
* shapes cannot say; absent when there is nothing to key */
|
|
42
|
+
legend?: TextLegend;
|
|
43
|
+
}
|
|
44
|
+
export declare function buildScene(input: SceneInput, glyphs: Glyphs): Promise<Scene>;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { activeNotation, buildHierarchy, compileView, defined, defaultLayoutDirection, FISHBONE_NOTATION, layoutPlaneKey, presetLayers, } from '@diagc/core/internal';
|
|
2
|
+
import { notationAccents } from './accents.js';
|
|
3
|
+
import { boxText, edgeText } from './content.js';
|
|
4
|
+
import { SHADOW_REACH } from './dos.js';
|
|
5
|
+
import { fishCells } from './fish.js';
|
|
6
|
+
import { withNeverFolds } from './folds.js';
|
|
7
|
+
import { layoutCells } from './layout.js';
|
|
8
|
+
import { legendOf } from './legend.js';
|
|
9
|
+
import { hidesKind } from './vocabulary.js';
|
|
10
|
+
const DIRECTIONS = new Set(['DOWN', 'UP', 'LEFT', 'RIGHT']);
|
|
11
|
+
/** The way the plane flows: its saved layout setting, else the model's default. */
|
|
12
|
+
function directionOf(input) {
|
|
13
|
+
const saved = input.overlay?.settings?.[layoutPlaneKey(input.model, input.plane)]?.direction;
|
|
14
|
+
return saved !== undefined && DIRECTIONS.has(saved) ? saved : defaultLayoutDirection(input.model);
|
|
15
|
+
}
|
|
16
|
+
/** How the scene is laid out: its plane's flow, and room for DOS's shadows. */
|
|
17
|
+
const flowOf = (input) => ({
|
|
18
|
+
direction: directionOf(input),
|
|
19
|
+
...(input.style === 'dos' ? { shadow: SHADOW_REACH } : {}),
|
|
20
|
+
});
|
|
21
|
+
export async function buildScene(input, glyphs) {
|
|
22
|
+
const { model, plane } = input;
|
|
23
|
+
const notation = activeNotation(model.planes, plane, model.notation);
|
|
24
|
+
const compiled = compileView(model, {
|
|
25
|
+
pins: withNeverFolds(model, input.pins, notation),
|
|
26
|
+
...(plane !== undefined ? { plane } : {}),
|
|
27
|
+
...(input.layers !== undefined ? { activeLayers: input.layers } : {}),
|
|
28
|
+
...(input.root !== undefined ? { root: input.root } : {}),
|
|
29
|
+
});
|
|
30
|
+
// Only the drawn set loses a notation's hidden kinds: layoutEdges keep them, the
|
|
31
|
+
// rule that keeps a layer toggle from moving a box (the renderer does the same).
|
|
32
|
+
const view = { ...compiled, edges: compiled.edges.filter((e) => !hidesKind(e.kind, notation)) };
|
|
33
|
+
const hierarchy = buildHierarchy(model, plane, new Set(input.layers ?? presetLayers(model.planes, plane)));
|
|
34
|
+
const nodes = new Map();
|
|
35
|
+
const parentOf = new Map();
|
|
36
|
+
const boxes = new Map();
|
|
37
|
+
const walk = (vn, parent) => {
|
|
38
|
+
nodes.set(vn.id, vn);
|
|
39
|
+
parentOf.set(vn.id, parent);
|
|
40
|
+
const inside = hierarchy.childrenOf.get(vn.id)?.length ?? 0;
|
|
41
|
+
boxes.set(vn.id, boxText(vn, { inside, glyphs, ...(notation !== undefined ? { notation } : {}) }));
|
|
42
|
+
for (const child of vn.children)
|
|
43
|
+
walk(child, vn.id);
|
|
44
|
+
};
|
|
45
|
+
for (const root of view.roots)
|
|
46
|
+
walk(root, undefined);
|
|
47
|
+
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
|
+
const laid = notation === FISHBONE_NOTATION
|
|
50
|
+
? fishCells(model, view, boxes)
|
|
51
|
+
: await layoutCells(view, boxes, flowOf(input), labels);
|
|
52
|
+
const room = input.style === 'dos' && laid.boxes.size > 0;
|
|
53
|
+
const layout = room ? { ...laid, width: laid.width + SHADOW_REACH.x, height: laid.height + SHADOW_REACH.y } : laid;
|
|
54
|
+
const accents = notationAccents(model, plane, notation, view.edges);
|
|
55
|
+
const scene = { input, view, layout, boxes, nodes, parentOf, hierarchy, accents, ...defined({ notation }) };
|
|
56
|
+
const legend = legendOf(scene, glyphs);
|
|
57
|
+
return legend === undefined ? scene : { ...scene, legend };
|
|
58
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { type DiagramNode, type NotationId, type ViewEdge } from '@diagc/core/internal';
|
|
2
|
+
/** The shapes a terminal can tell apart. */
|
|
3
|
+
export type TextShape = 'box' | 'rounded' | 'cylinder' | 'hexagon' | 'diamond' | 'dot' | 'bar' | 'note' | 'table';
|
|
4
|
+
export interface TypeLook {
|
|
5
|
+
shape: TextShape;
|
|
6
|
+
/** the subtitle in place of the raw type id; `''` prints none (the renderer's `label`) */
|
|
7
|
+
label?: string;
|
|
8
|
+
dashed?: boolean;
|
|
9
|
+
/** a container of this type is always drawn open (the renderer's `alwaysExpanded`) */
|
|
10
|
+
neverFolds?: boolean;
|
|
11
|
+
/** the border colour a notation gives the type (C4's blues) */
|
|
12
|
+
accent?: string;
|
|
13
|
+
/** what a legend calls the type (the renderer's `legendLabel`): set only on a shape
|
|
14
|
+
* that says nothing about itself, which a legend keys without being asked */
|
|
15
|
+
legend?: string;
|
|
16
|
+
}
|
|
17
|
+
export type LineStyle = 'solid' | 'dashed' | 'heavy';
|
|
18
|
+
export type EndMark = 'arrow' | 'none' | 'dot' | 'square' | 'diamond' | 'many' | 'one';
|
|
19
|
+
export interface KindLook {
|
|
20
|
+
line: LineStyle;
|
|
21
|
+
end: EndMark;
|
|
22
|
+
start?: EndMark;
|
|
23
|
+
/** what a legend calls the kind, as `TypeLook.legend` */
|
|
24
|
+
legend?: string;
|
|
25
|
+
}
|
|
26
|
+
/** One entry per type the renderer styles, in its order. */
|
|
27
|
+
export declare const TYPE_LOOKS: Readonly<Record<string, TypeLook>>;
|
|
28
|
+
/** One entry per kind the renderer styles, in its order. */
|
|
29
|
+
export declare const KIND_LOOKS: Readonly<Record<string, KindLook>>;
|
|
30
|
+
export declare function typeLook(type: string | undefined, notation: NotationId | undefined): TypeLook;
|
|
31
|
+
export declare function kindLook(edge: Pick<ViewEdge, 'kind' | 'style'>, notation: NotationId | undefined): KindLook;
|
|
32
|
+
/** Kinds a notation never draws as lines: a plan's roles become chips on the zone. */
|
|
33
|
+
export declare function hidesKind(kind: string, notation: NotationId | undefined): boolean;
|
|
34
|
+
/** The subtitle a box prints under its name, as the renderer prints it: the type's
|
|
35
|
+
* label, or the raw type id for a type without one; `''` for none. */
|
|
36
|
+
export declare function subtitleOf(node: DiagramNode, notation: NotationId | undefined): string;
|
|
37
|
+
export declare function neverFolds(node: DiagramNode, notation: NotationId | undefined): boolean;
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import { GIT_NOTATION, GIT_STAGE_TYPE, isActivityChrome, isPlanRole, } from '@diagc/core/internal';
|
|
2
|
+
const box = (label, extra = {}) => ({
|
|
3
|
+
shape: 'box',
|
|
4
|
+
...(label !== undefined ? { label } : {}),
|
|
5
|
+
...extra,
|
|
6
|
+
});
|
|
7
|
+
const shaped = (shape, label, extra = {}) => ({
|
|
8
|
+
shape,
|
|
9
|
+
...(label !== undefined ? { label } : {}),
|
|
10
|
+
...extra,
|
|
11
|
+
});
|
|
12
|
+
const dashed = { dashed: true };
|
|
13
|
+
const open = { neverFolds: true };
|
|
14
|
+
/** One entry per type the renderer styles, in its order. */
|
|
15
|
+
export const TYPE_LOOKS = {
|
|
16
|
+
system: box(undefined, dashed),
|
|
17
|
+
platform: box(undefined, dashed),
|
|
18
|
+
service: box(),
|
|
19
|
+
database: shaped('cylinder'),
|
|
20
|
+
'aws-rds': shaped('cylinder'),
|
|
21
|
+
table: shaped('cylinder'),
|
|
22
|
+
'db-table': shaped('table'),
|
|
23
|
+
queue: shaped('rounded'),
|
|
24
|
+
infra: shaped('hexagon'),
|
|
25
|
+
person: shaped('rounded'),
|
|
26
|
+
team: shaped('rounded'),
|
|
27
|
+
comment: shaped('rounded'),
|
|
28
|
+
'c4-person': box('[Person]'),
|
|
29
|
+
'c4-person-external': box('[Person]'),
|
|
30
|
+
'c4-system': box('[Software System]'),
|
|
31
|
+
'c4-system-external': box('[Software System]'),
|
|
32
|
+
'c4-enterprise-boundary': box('[Enterprise]', dashed),
|
|
33
|
+
'c4-system-boundary': box('[System]', dashed),
|
|
34
|
+
'c4-group': box('[Group]', dashed),
|
|
35
|
+
'c4-container': box('[Container]'),
|
|
36
|
+
'c4-container-external': box('[Container]'),
|
|
37
|
+
'c4-container-web': box('[Container]'),
|
|
38
|
+
'c4-container-spa': box('[Container]'),
|
|
39
|
+
'c4-container-mobile': box('[Container]'),
|
|
40
|
+
'c4-container-desktop': box('[Container]'),
|
|
41
|
+
'c4-container-api': box('[Container]'),
|
|
42
|
+
'c4-container-function': box('[Container]'),
|
|
43
|
+
'c4-container-cli': box('[Container]'),
|
|
44
|
+
'c4-container-db': shaped('cylinder', '[Container]'),
|
|
45
|
+
'c4-container-blob': shaped('cylinder', '[Container]'),
|
|
46
|
+
'c4-container-search': shaped('cylinder', '[Container]'),
|
|
47
|
+
'c4-container-queue': shaped('rounded', '[Container]'),
|
|
48
|
+
'c4-container-boundary': box('[Container]', dashed),
|
|
49
|
+
'c4-component': box('[Component]'),
|
|
50
|
+
'c4-component-external': box('[Component]'),
|
|
51
|
+
'c4-component-db': shaped('cylinder', '[Component]'),
|
|
52
|
+
'c4-component-queue': shaped('rounded', '[Component]'),
|
|
53
|
+
'c4-deployment-node': box('[Deployment Node]', dashed),
|
|
54
|
+
'c4-infrastructure-node': shaped('hexagon', '[Infrastructure Node]'),
|
|
55
|
+
'c4-container-instance': box('[Container Instance]'),
|
|
56
|
+
'c4-class': box('[Class]'),
|
|
57
|
+
'c4-interface': box('[Interface]', dashed),
|
|
58
|
+
'c4-enum': box('[Enumeration]'),
|
|
59
|
+
'aws-group': box(''),
|
|
60
|
+
'aws-account': box(''),
|
|
61
|
+
'aws-cloud': box(''),
|
|
62
|
+
'aws-vpc': box(''),
|
|
63
|
+
'aws-region': box('', dashed),
|
|
64
|
+
'aws-auto-scaling-group': box('', dashed),
|
|
65
|
+
'aws-az': box('', dashed),
|
|
66
|
+
'aws-subnet-public': box(''),
|
|
67
|
+
'aws-subnet-private': box(''),
|
|
68
|
+
'activity-frame': box(undefined, open),
|
|
69
|
+
'activity-lane': box(undefined, open),
|
|
70
|
+
'activity-region': box(undefined, { ...dashed, ...open, legend: 'Interruptible region' }),
|
|
71
|
+
'activity-action': shaped('rounded', '', { legend: 'Action' }),
|
|
72
|
+
'activity-decision': shaped('diamond', '', { legend: 'Decision / merge' }),
|
|
73
|
+
'activity-bar': shaped('bar', '', { legend: 'Fork / join' }),
|
|
74
|
+
'activity-start': shaped('dot', '', { legend: 'Start' }),
|
|
75
|
+
'activity-end': shaped('dot', '', { legend: 'End' }),
|
|
76
|
+
'activity-send': box('', { legend: 'Send signal' }),
|
|
77
|
+
'activity-receive': box('', { legend: 'Receive signal' }),
|
|
78
|
+
'activity-object': box('', { legend: 'Object' }),
|
|
79
|
+
'activity-note': shaped('note', ''),
|
|
80
|
+
'so-decision': shaped('rounded', ''),
|
|
81
|
+
'so-consequence-positive': shaped('rounded', ''),
|
|
82
|
+
'so-consequence-negative': shaped('rounded', ''),
|
|
83
|
+
'so-consequence-neutral': shaped('rounded', ''),
|
|
84
|
+
'fb-effect': box(''),
|
|
85
|
+
'fb-category': box(''),
|
|
86
|
+
'fb-cause': box(''),
|
|
87
|
+
'deploy-environment': box('[Environment]', { legend: 'Environment' }),
|
|
88
|
+
'deploy-region': box('[Region]', { legend: 'Region' }),
|
|
89
|
+
'deploy-zone': box('[Availability zone]', { ...dashed, legend: 'Availability zone' }),
|
|
90
|
+
'deploy-network': box('[Network]', { legend: 'Network' }),
|
|
91
|
+
'deploy-subnet-public': box('[Public subnet]', { legend: 'Public subnet' }),
|
|
92
|
+
'deploy-subnet-private': box('[Private subnet]', { legend: 'Private subnet' }),
|
|
93
|
+
'deploy-cluster': box('[Cluster]', { ...dashed, legend: 'Cluster' }),
|
|
94
|
+
'deploy-host': box('[Host]'),
|
|
95
|
+
'deploy-service': shaped('rounded', '[Service]'),
|
|
96
|
+
'deploy-database': shaped('cylinder', '[Database]'),
|
|
97
|
+
'deploy-queue': shaped('rounded', '[Queue]'),
|
|
98
|
+
'deploy-storage': shaped('cylinder', '[Storage]'),
|
|
99
|
+
'deploy-load-balancer': shaped('hexagon', '[Load balancer]'),
|
|
100
|
+
'deploy-gateway': shaped('hexagon', '[Gateway]'),
|
|
101
|
+
'deploy-firewall': box('[Firewall]'),
|
|
102
|
+
'deploy-internet': shaped('rounded', '[External network]', dashed),
|
|
103
|
+
'tm-entity': box('', { legend: 'External entity' }),
|
|
104
|
+
'tm-process': shaped('rounded', '', { legend: 'Process' }),
|
|
105
|
+
'tm-store': shaped('cylinder', '', { legend: 'Data store' }),
|
|
106
|
+
'tm-boundary': box('', { ...dashed, ...open, legend: 'Trust boundary' }),
|
|
107
|
+
'plan-zone': shaped('rounded', '', { legend: 'Zone' }),
|
|
108
|
+
'plan-event': shaped('diamond', '', { legend: 'Event' }),
|
|
109
|
+
};
|
|
110
|
+
const solid = { line: 'solid', end: 'arrow' };
|
|
111
|
+
/** One entry per kind the renderer styles, in its order. */
|
|
112
|
+
export const KIND_LOOKS = {
|
|
113
|
+
sync: solid,
|
|
114
|
+
async: { line: 'dashed', end: 'arrow' },
|
|
115
|
+
reads: solid,
|
|
116
|
+
writes: { line: 'heavy', end: 'arrow' },
|
|
117
|
+
'hosted-on': { line: 'dashed', end: 'arrow' },
|
|
118
|
+
flow: solid,
|
|
119
|
+
mixed: { line: 'heavy', end: 'arrow' },
|
|
120
|
+
fk: { line: 'solid', end: 'one', start: 'many', legend: 'Foreign key: many to one' },
|
|
121
|
+
control: { ...solid, legend: 'Control flow' },
|
|
122
|
+
'object-flow': { line: 'dashed', end: 'arrow', legend: 'Object flow' },
|
|
123
|
+
interrupt: { ...solid, legend: 'Interrupt' },
|
|
124
|
+
'note-link': { line: 'dashed', end: 'none', legend: 'Note link' },
|
|
125
|
+
influence: solid,
|
|
126
|
+
network: solid,
|
|
127
|
+
'leads-to': solid,
|
|
128
|
+
'cause-of': solid,
|
|
129
|
+
'data-flow': { ...solid, legend: 'Data flow' },
|
|
130
|
+
owns: { ...solid, legend: 'Owns' },
|
|
131
|
+
executes: { ...solid, legend: 'Executes' },
|
|
132
|
+
checks: { ...solid, legend: 'Checks' },
|
|
133
|
+
};
|
|
134
|
+
// What a notation's profile changes (packages/renderer/src/notations.ts). Not pinned
|
|
135
|
+
// by the test: the profiles are code, not tables, and these are the few looks a
|
|
136
|
+
// terminal can show — C4's person shape and colours, deployment's solid node, git's
|
|
137
|
+
// round commits and headless dashed links.
|
|
138
|
+
const C4_COLOURS = {
|
|
139
|
+
'c4-person': '#08427b',
|
|
140
|
+
'c4-person-external': '#999999',
|
|
141
|
+
'c4-system': '#1168bd',
|
|
142
|
+
'c4-system-external': '#999999',
|
|
143
|
+
'c4-container-external': '#999999',
|
|
144
|
+
'c4-component': '#85bbf0',
|
|
145
|
+
'c4-component-db': '#85bbf0',
|
|
146
|
+
'c4-component-queue': '#85bbf0',
|
|
147
|
+
'c4-component-external': '#999999',
|
|
148
|
+
...Object.fromEntries(['', '-web', '-spa', '-mobile', '-desktop', '-api', '-function', '-cli', '-db', '-blob', '-search', '-queue'].map((suffix) => [`c4-container${suffix}`, '#438dd5'])),
|
|
149
|
+
};
|
|
150
|
+
const NOTATION_TYPES = {
|
|
151
|
+
c4: Object.fromEntries(Object.entries(C4_COLOURS).map(([type, accent]) => [
|
|
152
|
+
type,
|
|
153
|
+
{ ...TYPE_LOOKS[type], accent, ...(type.startsWith('c4-person') ? { shape: 'rounded' } : {}) },
|
|
154
|
+
])),
|
|
155
|
+
deployment: { 'c4-deployment-node': box('[Deployment Node]') },
|
|
156
|
+
// a commit is a dot and a branch a lane in the browser: neither prints its type
|
|
157
|
+
[GIT_NOTATION]: { commit: shaped('dot', ''), branch: box('', open), [GIT_STAGE_TYPE]: box('') },
|
|
158
|
+
plan: { 'plan-zone': { ...TYPE_LOOKS['plan-zone'], ...open } },
|
|
159
|
+
};
|
|
160
|
+
const NOTATION_KINDS = {
|
|
161
|
+
[GIT_NOTATION]: {
|
|
162
|
+
commit: { line: 'dashed', end: 'none' },
|
|
163
|
+
branch: { line: 'dashed', end: 'none' },
|
|
164
|
+
merge: { line: 'dashed', end: 'none' },
|
|
165
|
+
},
|
|
166
|
+
};
|
|
167
|
+
export function typeLook(type, notation) {
|
|
168
|
+
if (type === undefined)
|
|
169
|
+
return { shape: 'box' };
|
|
170
|
+
const own = notation !== undefined ? NOTATION_TYPES[notation]?.[type] : undefined;
|
|
171
|
+
return own ?? TYPE_LOOKS[type] ?? { shape: 'box' };
|
|
172
|
+
}
|
|
173
|
+
export function kindLook(edge, notation) {
|
|
174
|
+
const own = notation !== undefined ? NOTATION_KINDS[notation]?.[edge.kind] : undefined;
|
|
175
|
+
const base = own ?? KIND_LOOKS[edge.kind] ?? solid;
|
|
176
|
+
const style = edge.style;
|
|
177
|
+
if (style === undefined)
|
|
178
|
+
return base;
|
|
179
|
+
const line = style.line === 'dashed' || style.line === 'dotted'
|
|
180
|
+
? 'dashed'
|
|
181
|
+
: (style.width ?? 0) >= 2.5
|
|
182
|
+
? 'heavy'
|
|
183
|
+
: style.line === 'solid'
|
|
184
|
+
? 'solid'
|
|
185
|
+
: base.line;
|
|
186
|
+
return { ...base, line, ...(style.end !== undefined ? { end: style.end } : {}) };
|
|
187
|
+
}
|
|
188
|
+
/** Kinds a notation never draws as lines: a plan's roles become chips on the zone. */
|
|
189
|
+
export function hidesKind(kind, notation) {
|
|
190
|
+
return notation === 'plan' && isPlanRole(kind);
|
|
191
|
+
}
|
|
192
|
+
/** The renderer's `typeSubtitle`: `[Container]` + `Java` → `[Container: Java]`. An
|
|
193
|
+
* empty label stays empty, so a glyph type's technology cannot resurrect it. */
|
|
194
|
+
function typeSubtitle(label, technology) {
|
|
195
|
+
if (technology === undefined || label === '')
|
|
196
|
+
return label;
|
|
197
|
+
return label.endsWith(']') ? `${label.slice(0, -1)}: ${technology}]` : `${label}: ${technology}`;
|
|
198
|
+
}
|
|
199
|
+
/** The subtitle a box prints under its name, as the renderer prints it: the type's
|
|
200
|
+
* label, or the raw type id for a type without one; `''` for none. */
|
|
201
|
+
export function subtitleOf(node, notation) {
|
|
202
|
+
// The activity frame, lanes and regions are drawn as bodies of their own, which
|
|
203
|
+
// print the name alone; their registry entries carry no label only because they
|
|
204
|
+
// are never drawn as a plain box.
|
|
205
|
+
if (node.type === undefined || isActivityChrome(node.type))
|
|
206
|
+
return '';
|
|
207
|
+
return typeSubtitle(typeLook(node.type, notation).label ?? node.type, node.technology);
|
|
208
|
+
}
|
|
209
|
+
export function neverFolds(node, notation) {
|
|
210
|
+
return typeLook(node.type, notation).neverFolds === true;
|
|
211
|
+
}
|