@diagc/cli 1.4.0 → 1.6.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/assets/guide/index.md +1 -1
- package/assets/skill/SKILL.md +1 -1
- package/assets/studio/assets/{index-B4EbTBLO.js → index-DRsUukzt.js} +48 -46
- package/assets/studio/index.html +1 -1
- package/dist/api/diagrams.d.ts +5 -0
- package/dist/api/diagrams.js +37 -24
- package/dist/api/dispatch.d.ts +3 -0
- package/dist/api/handlers.d.ts +1 -0
- package/dist/api/handlers.js +1 -0
- package/dist/api/pages.d.ts +21 -0
- package/dist/api/pages.js +50 -0
- package/dist/api/routes.d.ts +2 -0
- package/dist/api/routes.js +6 -0
- 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 +23 -1
- 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 +36 -0
- package/dist/init.d.ts +1 -1
- package/dist/init.js +1 -1
- package/dist/publish/publish.d.ts +15 -1
- package/dist/publish/publish.js +22 -15
- package/dist/serve.d.ts +3 -0
- package/dist/serve.js +2 -2
- package/dist/studio.js +1 -0
- 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 +111 -0
- package/dist/text/braille.d.ts +28 -0
- package/dist/text/braille.js +58 -0
- package/dist/text/canvas.d.ts +65 -0
- package/dist/text/canvas.js +155 -0
- package/dist/text/content.d.ts +32 -0
- package/dist/text/content.js +90 -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 +31 -0
- package/dist/text/glyphs.js +84 -0
- package/dist/text/layout.d.ts +61 -0
- package/dist/text/layout.js +334 -0
- package/dist/text/legend.d.ts +44 -0
- package/dist/text/legend.js +252 -0
- package/dist/text/paint.d.ts +25 -0
- package/dist/text/paint.js +208 -0
- package/dist/text/render.d.ts +11 -0
- package/dist/text/render.js +28 -0
- package/dist/text/scene.d.ts +40 -0
- package/dist/text/scene.js +50 -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 +10 -0
- package/dist/tui/actions.js +297 -0
- package/dist/tui/app.d.ts +31 -0
- package/dist/tui/app.js +389 -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 +25 -0
- package/dist/tui/nav.js +79 -0
- package/dist/tui/overview.d.ts +46 -0
- package/dist/tui/overview.js +115 -0
- package/dist/tui/pixels.d.ts +28 -0
- package/dist/tui/pixels.js +80 -0
- package/dist/tui/screen.d.ts +44 -0
- package/dist/tui/screen.js +335 -0
- package/dist/tui/state.d.ts +100 -0
- package/dist/tui/state.js +72 -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,90 @@
|
|
|
1
|
+
import { ACTIVITY_END_TYPE, FB_EFFECT_TYPE, } from '@diagc/core/internal';
|
|
2
|
+
import { subtitleOf, typeLook } from './vocabulary.js';
|
|
3
|
+
import { cellWidth, fitCells, printable, wrapCells } from './width.js';
|
|
4
|
+
/** The cells a name or subtitle wraps at: about what a browser box shows on a line. */
|
|
5
|
+
export const NAME_WRAP = 28;
|
|
6
|
+
/** The cells an edge label is cut to: the renderer's edge chip ellipsises near here,
|
|
7
|
+
* and a terminal has less room than a canvas, not more. */
|
|
8
|
+
export const LABEL_MAX = 32;
|
|
9
|
+
/** An open container's title is one line in its top border; past this it is cut. */
|
|
10
|
+
const TITLE_MAX = 60;
|
|
11
|
+
/** The mark a glyph type's name follows, which is what a legend keys it by. */
|
|
12
|
+
export function typeMark(type, shape, glyphs) {
|
|
13
|
+
if (shape === 'diamond')
|
|
14
|
+
return glyphs.decision;
|
|
15
|
+
if (type === ACTIVITY_END_TYPE)
|
|
16
|
+
return glyphs.end;
|
|
17
|
+
// an activity's start, a git commit: the dot is the element, the name a caption
|
|
18
|
+
if (shape === 'dot')
|
|
19
|
+
return glyphs.start;
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
const markOf = (vn, shape, glyphs) => vn.external !== undefined ? glyphs.external : typeMark(vn.node.type, shape, glyphs);
|
|
23
|
+
/** A table's rows: a key column when any row is a key, names padded so the types
|
|
24
|
+
* line up in one column. */
|
|
25
|
+
function columnRows(columns) {
|
|
26
|
+
const keyed = columns.some((c) => c.pk === true || c.fk === true);
|
|
27
|
+
const nameWidth = Math.max(0, ...columns.map((c) => cellWidth(printable(c.name))));
|
|
28
|
+
return columns.map((c) => {
|
|
29
|
+
const key = !keyed ? '' : c.pk === true ? 'PK ' : c.fk === true ? 'FK ' : ' ';
|
|
30
|
+
const own = printable(c.name);
|
|
31
|
+
const name = c.type === undefined ? own : `${own}${' '.repeat(nameWidth - cellWidth(own))} ${printable(c.type)}`;
|
|
32
|
+
return { text: `${key}${name}`, role: 'row' };
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
/** The cells a box's lines need with its border and a cell of padding each side. */
|
|
36
|
+
const widthOf = (lines) => Math.max(...lines.map((l) => cellWidth(l.text))) + 4;
|
|
37
|
+
export function boxText(vn, ctx) {
|
|
38
|
+
const look = typeLook(vn.node.type, ctx.notation);
|
|
39
|
+
const dashed = look.dashed === true || vn.external !== undefined;
|
|
40
|
+
// A table's header is its name alone, as the renderer draws it: the rows say what it is.
|
|
41
|
+
const subtitle = printable(look.shape === 'table' ? '' : subtitleOf(vn.node, ctx.notation));
|
|
42
|
+
if (vn.state === 'expanded') {
|
|
43
|
+
// one line in the border: a name's own line breaks become spaces there
|
|
44
|
+
const own = printable(vn.node.name);
|
|
45
|
+
const title = fitCells(subtitle === '' ? own : `${own} ${subtitle}`, TITLE_MAX, ctx.glyphs.ellipsis);
|
|
46
|
+
return {
|
|
47
|
+
lines: [{ text: title, role: 'title' }],
|
|
48
|
+
width: cellWidth(title) + 6,
|
|
49
|
+
height: 3,
|
|
50
|
+
shape: look.shape,
|
|
51
|
+
dashed,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
const mark = markOf(vn, look.shape, ctx.glyphs);
|
|
55
|
+
const name = mark === undefined ? vn.node.name : vn.node.name === '' ? mark : `${mark} ${vn.node.name}`;
|
|
56
|
+
// A name keeps its own line breaks (the studio's name field takes them), each line
|
|
57
|
+
// wrapped on its own. A fishbone's head is one line, as on the page: it names the
|
|
58
|
+
// whole fish, where wrapping would leave a word on a line of its own.
|
|
59
|
+
const lines = vn.node.type === FB_EFFECT_TYPE
|
|
60
|
+
? [{ text: fitCells(printable(name), TITLE_MAX, ctx.glyphs.ellipsis), role: 'title' }]
|
|
61
|
+
: name
|
|
62
|
+
.split(/\r?\n/)
|
|
63
|
+
.flatMap((line) => wrapCells(printable(line), NAME_WRAP))
|
|
64
|
+
.map((text) => ({ text, role: 'title' }));
|
|
65
|
+
for (const text of subtitle === '' ? [] : wrapCells(subtitle, NAME_WRAP))
|
|
66
|
+
lines.push({ text, role: 'subtitle' });
|
|
67
|
+
const columns = look.shape === 'table' ? (vn.columns ?? vn.node.columns ?? []) : [];
|
|
68
|
+
lines.push(...columnRows(columns));
|
|
69
|
+
if (vn.state === 'collapsed')
|
|
70
|
+
lines.push({ text: `${ctx.glyphs.folded} ${ctx.inside} inside`, role: 'note' });
|
|
71
|
+
// a cylinder's lid and a table's rule under its title each take a row
|
|
72
|
+
const extra = look.shape === 'cylinder' || columns.length > 0 ? 1 : 0;
|
|
73
|
+
return { lines, width: widthOf(lines), height: lines.length + 2 + extra, shape: look.shape, dashed };
|
|
74
|
+
}
|
|
75
|
+
/** What an edge says beside its line: the relation's labels, or an aggregate's own
|
|
76
|
+
* label, then a causal link's polarity and delay. Cut to `LABEL_MAX`. */
|
|
77
|
+
export function edgeText(edge, glyphs) {
|
|
78
|
+
const said = edge.constituents.length === 1
|
|
79
|
+
? (edge.labels ?? [])
|
|
80
|
+
.map((l) => printable(l.text).trim())
|
|
81
|
+
.filter((t) => t !== '')
|
|
82
|
+
.join(' / ')
|
|
83
|
+
: printable(edge.label ?? '');
|
|
84
|
+
const parts = [said];
|
|
85
|
+
if (edge.polarity !== undefined)
|
|
86
|
+
parts.push(`(${edge.polarity})`);
|
|
87
|
+
if (edge.delay === true)
|
|
88
|
+
parts.push(glyphs.delay);
|
|
89
|
+
return fitCells(parts.filter((p) => p !== '').join(' '), LABEL_MAX, glyphs.ellipsis);
|
|
90
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type CompiledView, type DiagramModel } from '@diagc/core/internal';
|
|
2
|
+
import type { BoxText } from './content.js';
|
|
3
|
+
import type { TextLayout } from './layout.js';
|
|
4
|
+
/** The fish's spacing, in cells. */
|
|
5
|
+
export declare const FISH: {
|
|
6
|
+
/** the shortest bone, in rows */
|
|
7
|
+
readonly BONE_MIN: 2;
|
|
8
|
+
/** the shortest line from a cause's words to its bone */
|
|
9
|
+
readonly LINE_MIN: 2;
|
|
10
|
+
/** from where a cause's line meets its bone to where its first sub-cause's tick
|
|
11
|
+
* does: far enough that the tick does not read as a second bone */
|
|
12
|
+
readonly SUB_INSET: 4;
|
|
13
|
+
/** between a sub-cause's words and the tick of the next one along */
|
|
14
|
+
readonly SUB_GAP: 2;
|
|
15
|
+
/** between a column's bones and the next column's words, and before the head */
|
|
16
|
+
readonly COLUMN_GAP: 3;
|
|
17
|
+
/** between the fish and the row under it of what is not on it */
|
|
18
|
+
readonly STRAY_ROW: 2;
|
|
19
|
+
/** between two boxes in that row */
|
|
20
|
+
readonly STRAY_GAP: 4;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* The fish in cells, for a fishbone plane: every node the view shows gets a box, the
|
|
24
|
+
* words' cells for one on the fish, and every drawn relation on the fish a route. A
|
|
25
|
+
* view without its effect has no fish, only the row of boxes.
|
|
26
|
+
*/
|
|
27
|
+
export declare function fishCells(model: DiagramModel, view: CompiledView, boxes: ReadonlyMap<string, BoxText>): TextLayout;
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import { fishboneTree, } from '@diagc/core/internal';
|
|
2
|
+
import { cellWidth, printable } from './width.js';
|
|
3
|
+
// A fishbone in cells, as the page draws it (the renderer's fishbone-layout.ts): the
|
|
4
|
+
// spine across with the head boxed at its right end, the categories alternately above
|
|
5
|
+
// and below it in relation order, two to a column from left to right, each on a bone
|
|
6
|
+
// slanting in to the spine. A slant is one cell a row, and a cell is about twice as
|
|
7
|
+
// tall as it is wide, so it comes out near the page's sixty degrees. A bone's causes
|
|
8
|
+
// hang on lines that end at it, the first nearest its label, and their sub-causes sit
|
|
9
|
+
// past those lines on ticks. What is not on the fish goes in a row of boxes under it.
|
|
10
|
+
/** The fish's spacing, in cells. */
|
|
11
|
+
export const FISH = {
|
|
12
|
+
/** the shortest bone, in rows */
|
|
13
|
+
BONE_MIN: 2,
|
|
14
|
+
/** the shortest line from a cause's words to its bone */
|
|
15
|
+
LINE_MIN: 2,
|
|
16
|
+
/** from where a cause's line meets its bone to where its first sub-cause's tick
|
|
17
|
+
* does: far enough that the tick does not read as a second bone */
|
|
18
|
+
SUB_INSET: 4,
|
|
19
|
+
/** between a sub-cause's words and the tick of the next one along */
|
|
20
|
+
SUB_GAP: 2,
|
|
21
|
+
/** between a column's bones and the next column's words, and before the head */
|
|
22
|
+
COLUMN_GAP: 3,
|
|
23
|
+
/** between the fish and the row under it of what is not on it */
|
|
24
|
+
STRAY_ROW: 2,
|
|
25
|
+
/** between two boxes in that row */
|
|
26
|
+
STRAY_GAP: 4,
|
|
27
|
+
};
|
|
28
|
+
/** A name on one line: what a category's label and a sub-cause's words are. */
|
|
29
|
+
const oneLine = (fish, id) => printable(fish.model.nodes
|
|
30
|
+
.find((n) => n.id === id)
|
|
31
|
+
.name.split(/\r?\n/)
|
|
32
|
+
.join(' '));
|
|
33
|
+
/** A cause's words, wrapped as its box would wrap them. */
|
|
34
|
+
const linesOf = (fish, id) => fish.boxes.get(id)?.lines.map((l) => l.text) ?? [oneLine(fish, id)];
|
|
35
|
+
/**
|
|
36
|
+
* One category's side of the spine: the causes from the spine outwards, the last one
|
|
37
|
+
* nearest it, a blank row between, then the bone up past the outermost words and its
|
|
38
|
+
* label. A cause's words end a space before its line, right-aligned when they wrap,
|
|
39
|
+
* and hang from the line towards the spine. Its sub-causes go leftwards along the row
|
|
40
|
+
* past the line, from near the bone, each on a tick that meets the line.
|
|
41
|
+
*/
|
|
42
|
+
function sideOf(fish, category, above) {
|
|
43
|
+
const words = new Map();
|
|
44
|
+
const links = [];
|
|
45
|
+
const causes = category.causes.filter((c) => fish.shown.has(c.id));
|
|
46
|
+
let start = FISH.BONE_MIN;
|
|
47
|
+
let top = 0;
|
|
48
|
+
for (const cause of [...causes].reverse()) {
|
|
49
|
+
// Hung towards the spine, the words leave the row past the line to the sub-causes,
|
|
50
|
+
// each on a tick of one cell, crossing nothing. There they may reach out over the
|
|
51
|
+
// cause's words, which keeps the line short: it need only reach the ticks.
|
|
52
|
+
const lines = linesOf(fish, cause.id);
|
|
53
|
+
const h = start + lines.length - 1;
|
|
54
|
+
const bone = -h;
|
|
55
|
+
let land = bone - FISH.SUB_INSET;
|
|
56
|
+
let line = bone - FISH.LINE_MIN;
|
|
57
|
+
const subs = cause.subs.filter((s) => fish.shown.has(s));
|
|
58
|
+
for (const sub of subs) {
|
|
59
|
+
const text = oneLine(fish, sub);
|
|
60
|
+
const tick = land - 1;
|
|
61
|
+
const begin = tick - 1 - cellWidth(text);
|
|
62
|
+
words.set(sub, [{ x: begin, h: h + 1, text }]);
|
|
63
|
+
links.push({
|
|
64
|
+
from: sub,
|
|
65
|
+
to: cause.id,
|
|
66
|
+
points: [
|
|
67
|
+
{ x: tick, h: h + 1 },
|
|
68
|
+
{ x: land, h },
|
|
69
|
+
],
|
|
70
|
+
});
|
|
71
|
+
line = Math.min(line, land);
|
|
72
|
+
land = begin - FISH.SUB_GAP;
|
|
73
|
+
}
|
|
74
|
+
links.push({
|
|
75
|
+
from: cause.id,
|
|
76
|
+
to: category.id,
|
|
77
|
+
points: [
|
|
78
|
+
{ x: line, h },
|
|
79
|
+
{ x: bone - 1, h },
|
|
80
|
+
],
|
|
81
|
+
});
|
|
82
|
+
const k = lines.length;
|
|
83
|
+
words.set(cause.id, lines.map((text, i) => ({ x: line - 1 - cellWidth(text), h: above ? h - i : h - (k - 1 - i), text })));
|
|
84
|
+
top = h + (subs.length > 0 ? 1 : 0);
|
|
85
|
+
start = top + 2;
|
|
86
|
+
}
|
|
87
|
+
const height = Math.max(FISH.BONE_MIN, top);
|
|
88
|
+
const label = oneLine(fish, category.id);
|
|
89
|
+
const labelX = -(height + 1) - Math.floor(cellWidth(label) / 2);
|
|
90
|
+
words.set(category.id, [{ x: labelX, h: height + 1, text: label }]);
|
|
91
|
+
const starts = [...words.values()].flat().map((w) => w.x);
|
|
92
|
+
return {
|
|
93
|
+
category: category.id,
|
|
94
|
+
above,
|
|
95
|
+
height,
|
|
96
|
+
words,
|
|
97
|
+
links,
|
|
98
|
+
left: -Math.min(...starts),
|
|
99
|
+
right: Math.max(0, labelX + cellWidth(label) - 1),
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
const extent = (lines) => {
|
|
103
|
+
const x = Math.min(...lines.map((l) => l.x));
|
|
104
|
+
const y = Math.min(...lines.map((l) => l.y));
|
|
105
|
+
return {
|
|
106
|
+
x,
|
|
107
|
+
y,
|
|
108
|
+
width: Math.max(...lines.map((l) => l.x + cellWidth(l.text))) - x,
|
|
109
|
+
height: Math.max(...lines.map((l) => l.y)) - y + 1,
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
/** Every node the view shows, parents before children. */
|
|
113
|
+
function shownNodes(view) {
|
|
114
|
+
const out = [];
|
|
115
|
+
const walk = (vn) => {
|
|
116
|
+
out.push(vn);
|
|
117
|
+
vn.children.forEach(walk);
|
|
118
|
+
};
|
|
119
|
+
view.roots.forEach(walk);
|
|
120
|
+
return out;
|
|
121
|
+
}
|
|
122
|
+
/** What is not on the fish, boxed in a row from the left at `y`. */
|
|
123
|
+
function placeStrays(nodes, fish, y, boxes) {
|
|
124
|
+
let x = 0;
|
|
125
|
+
for (const vn of nodes) {
|
|
126
|
+
if (boxes.has(vn.id))
|
|
127
|
+
continue;
|
|
128
|
+
const text = fish.boxes.get(vn.id);
|
|
129
|
+
const [width, height] = [text?.width ?? 5, text?.height ?? 3];
|
|
130
|
+
boxes.set(vn.id, { x, y, width, height });
|
|
131
|
+
x += width + FISH.STRAY_GAP;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
/** The picture's size: every box and every route; the spine runs inside them. */
|
|
135
|
+
function measure(boxes, routes) {
|
|
136
|
+
let [width, height] = [0, 0];
|
|
137
|
+
for (const b of boxes.values())
|
|
138
|
+
[width, height] = [Math.max(width, b.x + b.width), Math.max(height, b.y + b.height)];
|
|
139
|
+
for (const r of routes.values()) {
|
|
140
|
+
for (const p of r.points)
|
|
141
|
+
[width, height] = [Math.max(width, p.x + 1), Math.max(height, p.y + 1)];
|
|
142
|
+
}
|
|
143
|
+
return [width, height];
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* The fish in cells, for a fishbone plane: every node the view shows gets a box, the
|
|
147
|
+
* words' cells for one on the fish, and every drawn relation on the fish a route. A
|
|
148
|
+
* view without its effect has no fish, only the row of boxes.
|
|
149
|
+
*/
|
|
150
|
+
export function fishCells(model, view, boxes) {
|
|
151
|
+
const nodes = shownNodes(view);
|
|
152
|
+
const fish = { model, boxes, shown: new Set(nodes.map((n) => n.id)) };
|
|
153
|
+
const tree = fishboneTree(model);
|
|
154
|
+
const effect = tree.effect !== undefined && fish.shown.has(tree.effect) ? tree.effect : undefined;
|
|
155
|
+
const placed = new Map();
|
|
156
|
+
const routes = new Map();
|
|
157
|
+
if (effect === undefined) {
|
|
158
|
+
placeStrays(nodes, fish, 0, placed);
|
|
159
|
+
const [width, height] = measure(placed, routes);
|
|
160
|
+
return { width, height, boxes: placed, routes };
|
|
161
|
+
}
|
|
162
|
+
const sides = tree.categories.filter((c) => fish.shown.has(c.id)).map((c, i) => sideOf(fish, c, i % 2 === 0));
|
|
163
|
+
const head = boxes.get(effect);
|
|
164
|
+
const reach = (above) => Math.max(0, ...sides.filter((s) => s.above === above).map((s) => s.height + 1));
|
|
165
|
+
const spine = Math.max(reach(true), Math.floor(head.height / 2));
|
|
166
|
+
const bottom = spine + Math.max(reach(false), head.height - 1 - Math.floor(head.height / 2));
|
|
167
|
+
const edgeOf = new Map(view.edges.map((e) => [`${e.from} ${e.to}`, e.id]));
|
|
168
|
+
const words = new Map();
|
|
169
|
+
let left = 0;
|
|
170
|
+
for (let c = 0; c < sides.length; c += 2) {
|
|
171
|
+
const column = sides.slice(c, c + 2);
|
|
172
|
+
const join = left + Math.max(...column.map((s) => s.left));
|
|
173
|
+
for (const side of column) {
|
|
174
|
+
const at = (p) => ({ x: join + p.x, y: side.above ? spine - p.h : spine + p.h });
|
|
175
|
+
for (const [id, lines] of side.words) {
|
|
176
|
+
const placedLines = lines.map((l) => ({ ...at(l), text: l.text }));
|
|
177
|
+
words.set(id, placedLines);
|
|
178
|
+
placed.set(id, extent(placedLines));
|
|
179
|
+
}
|
|
180
|
+
const bone = {
|
|
181
|
+
from: side.category,
|
|
182
|
+
to: effect,
|
|
183
|
+
points: [
|
|
184
|
+
{ x: -side.height, h: side.height },
|
|
185
|
+
{ x: 0, h: 0 },
|
|
186
|
+
],
|
|
187
|
+
};
|
|
188
|
+
for (const link of [...side.links, bone]) {
|
|
189
|
+
const id = edgeOf.get(`${link.from} ${link.to}`);
|
|
190
|
+
if (id !== undefined)
|
|
191
|
+
routes.set(id, { points: link.points.map(at) });
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
left = join + Math.max(...column.map((s) => s.right)) + 1 + FISH.COLUMN_GAP;
|
|
195
|
+
}
|
|
196
|
+
// with no bones yet the head still ends a spine, a stub of one
|
|
197
|
+
const headX = sides.length === 0 ? FISH.COLUMN_GAP + 1 : left;
|
|
198
|
+
placed.set(effect, { x: headX, y: spine - Math.floor(head.height / 2), width: head.width, height: head.height });
|
|
199
|
+
placeStrays(nodes, fish, bottom + 1 + FISH.STRAY_ROW, placed);
|
|
200
|
+
const [width, height] = measure(placed, routes);
|
|
201
|
+
const labels = new Set(sides.map((s) => s.category));
|
|
202
|
+
return {
|
|
203
|
+
width,
|
|
204
|
+
height,
|
|
205
|
+
boxes: placed,
|
|
206
|
+
routes,
|
|
207
|
+
fish: { spine: { y: spine, from: 0, to: headX }, head: effect, words, labels },
|
|
208
|
+
};
|
|
209
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type DiagramModel, type LayoutOverlay, type NotationId } from '@diagc/core/internal';
|
|
2
|
+
export type Pins = Record<string, 'expanded' | 'collapsed'>;
|
|
3
|
+
/** The PNG export's folds: every container open, except those the layout keeps
|
|
4
|
+
* folded for the export (`layout.export.collapsed`). The viewer's `exportFolds`. */
|
|
5
|
+
export declare function exportPins(model: DiagramModel, overlay: LayoutOverlay | undefined): Pins;
|
|
6
|
+
/** Only the top `depth` levels open: a container whose shallowest way down from a root
|
|
7
|
+
* on the plane is fewer than `depth` steps is open, every other one folded. */
|
|
8
|
+
export declare function depthPins(model: DiagramModel, plane: string | undefined, depth: number): Pins;
|
|
9
|
+
/** The published page's opening folds: what the layout saved as unfolded for the plane. */
|
|
10
|
+
export declare function readerPins(model: DiagramModel, overlay: LayoutOverlay | undefined, plane: string | undefined): Pins;
|
|
11
|
+
/** `pins` with the containers that never fold — an activity lane, a trust boundary, a
|
|
12
|
+
* git branch — pinned open over them, as the renderer pins them. Unchanged (the same
|
|
13
|
+
* object) when there are none. */
|
|
14
|
+
export declare function withNeverFolds(model: DiagramModel, pins: Pins, notation: NotationId | undefined): Pins;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { buildHierarchy, openingPins, } from '@diagc/core/internal';
|
|
2
|
+
import { neverFolds } from './vocabulary.js';
|
|
3
|
+
const containers = (model) => [...new Set(model.containment.map((c) => c.parent))];
|
|
4
|
+
/** The PNG export's folds: every container open, except those the layout keeps
|
|
5
|
+
* folded for the export (`layout.export.collapsed`). The viewer's `exportFolds`. */
|
|
6
|
+
export function exportPins(model, overlay) {
|
|
7
|
+
const folded = new Set(overlay?.export?.collapsed ?? []);
|
|
8
|
+
return Object.fromEntries(containers(model).map((id) => [id, folded.has(id) ? 'collapsed' : 'expanded']));
|
|
9
|
+
}
|
|
10
|
+
/** Only the top `depth` levels open: a container whose shallowest way down from a root
|
|
11
|
+
* on the plane is fewer than `depth` steps is open, every other one folded. */
|
|
12
|
+
export function depthPins(model, plane, depth) {
|
|
13
|
+
const hierarchy = buildHierarchy(model, plane);
|
|
14
|
+
const depthOf = new Map(hierarchy.roots.map((id) => [id, 0]));
|
|
15
|
+
const queue = [...hierarchy.roots];
|
|
16
|
+
for (let i = 0; i < queue.length; i++) {
|
|
17
|
+
const id = queue[i];
|
|
18
|
+
for (const child of hierarchy.childrenOf.get(id) ?? []) {
|
|
19
|
+
if (depthOf.has(child))
|
|
20
|
+
continue;
|
|
21
|
+
depthOf.set(child, depthOf.get(id) + 1);
|
|
22
|
+
queue.push(child);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
const pins = {};
|
|
26
|
+
for (const [id, kids] of hierarchy.childrenOf) {
|
|
27
|
+
if (kids.length > 0)
|
|
28
|
+
pins[id] = (depthOf.get(id) ?? 0) < depth ? 'expanded' : 'collapsed';
|
|
29
|
+
}
|
|
30
|
+
return pins;
|
|
31
|
+
}
|
|
32
|
+
/** The published page's opening folds: what the layout saved as unfolded for the plane. */
|
|
33
|
+
export function readerPins(model, overlay, plane) {
|
|
34
|
+
return openingPins(overlay, model, plane);
|
|
35
|
+
}
|
|
36
|
+
/** `pins` with the containers that never fold — an activity lane, a trust boundary, a
|
|
37
|
+
* git branch — pinned open over them, as the renderer pins them. Unchanged (the same
|
|
38
|
+
* object) when there are none. */
|
|
39
|
+
export function withNeverFolds(model, pins, notation) {
|
|
40
|
+
const parents = new Set(containers(model));
|
|
41
|
+
const open = model.nodes.filter((n) => parents.has(n.id) && neverFolds(n, notation));
|
|
42
|
+
if (open.length === 0)
|
|
43
|
+
return pins;
|
|
44
|
+
return { ...pins, ...Object.fromEntries(open.map((n) => [n.id, 'expanded'])) };
|
|
45
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { EndMark } from './vocabulary.js';
|
|
2
|
+
export declare const UP = 1;
|
|
3
|
+
export declare const DOWN = 2;
|
|
4
|
+
export declare const LEFT = 4;
|
|
5
|
+
export declare const RIGHT = 8;
|
|
6
|
+
export type Weight = 'light' | 'heavy' | 'dashed';
|
|
7
|
+
export type Corner = 'round' | 'chamfer';
|
|
8
|
+
export type ArrowDirection = 'up' | 'down' | 'left' | 'right';
|
|
9
|
+
export interface Glyphs {
|
|
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;
|
|
13
|
+
arrow(direction: ArrowDirection): string;
|
|
14
|
+
/** a line one cell a row, a fishbone's bone or tick: falling to the right, or rising */
|
|
15
|
+
slant(falling: boolean): string;
|
|
16
|
+
mark(mark: Exclude<EndMark, 'arrow' | 'none'>): string;
|
|
17
|
+
/** one cell, for text cut short */
|
|
18
|
+
ellipsis: string;
|
|
19
|
+
/** what a folded container's note starts with */
|
|
20
|
+
folded: string;
|
|
21
|
+
/** what a drill view's stand-in for an outside node starts with */
|
|
22
|
+
external: string;
|
|
23
|
+
/** the marks a glyph type's box starts with: an activity's start and end, a decision */
|
|
24
|
+
start: string;
|
|
25
|
+
end: string;
|
|
26
|
+
decision: string;
|
|
27
|
+
/** a causal link's delay, after its label */
|
|
28
|
+
delay: string;
|
|
29
|
+
}
|
|
30
|
+
export declare const UNICODE: Glyphs;
|
|
31
|
+
export declare const ASCII: Glyphs;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// The characters a picture is drawn with. A line is recorded on the canvas as the
|
|
2
|
+
// directions it leaves a cell in (a mask of the four below) and only turned into a
|
|
3
|
+
// character at the end, so wherever two lines meet the junction comes out right
|
|
4
|
+
// without the code that drew either knowing about the other.
|
|
5
|
+
export const UP = 1;
|
|
6
|
+
export const DOWN = 2;
|
|
7
|
+
export const LEFT = 4;
|
|
8
|
+
export const RIGHT = 8;
|
|
9
|
+
/** Index a 16-entry table by mask; a lone direction draws as the whole line. */
|
|
10
|
+
function table(chars) {
|
|
11
|
+
const list = [...chars];
|
|
12
|
+
return (mask) => list[mask];
|
|
13
|
+
}
|
|
14
|
+
// By mask: 0 U D UD L UL DL UDL R UR DR UDR LR ULR DLR all
|
|
15
|
+
const LIGHT = table(' │││─┘┐┤─└┌├─┴┬┼');
|
|
16
|
+
const HEAVY = table(' ┃┃┃━┛┓┫━┗┏┣━┻┳╋');
|
|
17
|
+
const CORNERS = new Set([DOWN | RIGHT, DOWN | LEFT, UP | RIGHT, UP | LEFT]);
|
|
18
|
+
const ROUND = { [DOWN | RIGHT]: '╭', [DOWN | LEFT]: '╮', [UP | RIGHT]: '╰', [UP | LEFT]: '╯' };
|
|
19
|
+
const CHAMFER = {
|
|
20
|
+
[DOWN | RIGHT]: '╱',
|
|
21
|
+
[DOWN | LEFT]: '╲',
|
|
22
|
+
[UP | RIGHT]: '╲',
|
|
23
|
+
[UP | LEFT]: '╱',
|
|
24
|
+
};
|
|
25
|
+
export const UNICODE = {
|
|
26
|
+
line(mask, weight, corner) {
|
|
27
|
+
if (corner !== undefined && CORNERS.has(mask))
|
|
28
|
+
return (corner === 'round' ? ROUND : CHAMFER)[mask];
|
|
29
|
+
if (weight === 'heavy')
|
|
30
|
+
return HEAVY(mask);
|
|
31
|
+
// The dashed set has no junctions: where a dashed line meets anything, the
|
|
32
|
+
// meeting reads better solid than broken.
|
|
33
|
+
if (weight === 'dashed' && (mask & (LEFT | RIGHT)) === 0)
|
|
34
|
+
return '╎';
|
|
35
|
+
if (weight === 'dashed' && (mask & (UP | DOWN)) === 0)
|
|
36
|
+
return '╌';
|
|
37
|
+
return LIGHT(mask);
|
|
38
|
+
},
|
|
39
|
+
arrow: (direction) => ({ up: '▲', down: '▼', left: '◀', right: '▶' })[direction],
|
|
40
|
+
slant: (falling) => (falling ? '╲' : '╱'),
|
|
41
|
+
mark: (mark) => ({ dot: '●', square: '■', diamond: '◆', many: '*', one: '1' })[mark],
|
|
42
|
+
ellipsis: '…',
|
|
43
|
+
folded: '+',
|
|
44
|
+
external: '↗',
|
|
45
|
+
start: '●',
|
|
46
|
+
end: '◉',
|
|
47
|
+
decision: '◇',
|
|
48
|
+
delay: '‖',
|
|
49
|
+
};
|
|
50
|
+
const ASCII_ROUND = {
|
|
51
|
+
[DOWN | RIGHT]: '.',
|
|
52
|
+
[DOWN | LEFT]: '.',
|
|
53
|
+
[UP | RIGHT]: "'",
|
|
54
|
+
[UP | LEFT]: "'",
|
|
55
|
+
};
|
|
56
|
+
const ASCII_CHAMFER = {
|
|
57
|
+
[DOWN | RIGHT]: '/',
|
|
58
|
+
[DOWN | LEFT]: '\\',
|
|
59
|
+
[UP | RIGHT]: '\\',
|
|
60
|
+
[UP | LEFT]: '/',
|
|
61
|
+
};
|
|
62
|
+
export const ASCII = {
|
|
63
|
+
line(mask, weight, corner) {
|
|
64
|
+
if (corner !== undefined && CORNERS.has(mask))
|
|
65
|
+
return (corner === 'round' ? ASCII_ROUND : ASCII_CHAMFER)[mask];
|
|
66
|
+
const vertical = (mask & (LEFT | RIGHT)) === 0;
|
|
67
|
+
const horizontal = (mask & (UP | DOWN)) === 0;
|
|
68
|
+
if (vertical)
|
|
69
|
+
return weight === 'dashed' ? ':' : '|';
|
|
70
|
+
if (horizontal)
|
|
71
|
+
return weight === 'dashed' ? '.' : weight === 'heavy' ? '=' : '-';
|
|
72
|
+
return '+';
|
|
73
|
+
},
|
|
74
|
+
arrow: (direction) => ({ up: '^', down: 'v', left: '<', right: '>' })[direction],
|
|
75
|
+
slant: (falling) => (falling ? '\\' : '/'),
|
|
76
|
+
mark: (mark) => ({ dot: 'o', square: '#', diamond: '@', many: '*', one: '1' })[mark],
|
|
77
|
+
ellipsis: '~',
|
|
78
|
+
folded: '+',
|
|
79
|
+
external: '->',
|
|
80
|
+
start: '*',
|
|
81
|
+
end: '@',
|
|
82
|
+
decision: '<>',
|
|
83
|
+
delay: '||',
|
|
84
|
+
};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { CompiledView } from '@diagc/core/internal';
|
|
2
|
+
import type { CellPoint, CellRect } from './canvas.js';
|
|
3
|
+
import type { BoxText } from './content.js';
|
|
4
|
+
/** Where a box is, in whole cells from the picture's top-left corner. */
|
|
5
|
+
export type BoxGeometry = CellRect;
|
|
6
|
+
/** An edge's path. `points[0]` is the cell just outside the source box and the last
|
|
7
|
+
* point the cell just outside the target box, where the arrowhead goes; consecutive
|
|
8
|
+
* points differ on one axis only. On a fish (`FishDrawing`) a bone and a tick are
|
|
9
|
+
* slanted instead, one cell a row, and end on the line they meet. */
|
|
10
|
+
export interface Route {
|
|
11
|
+
points: CellPoint[];
|
|
12
|
+
label?: CellPoint & {
|
|
13
|
+
text: string;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
/** What a fishbone is drawn with besides boxes and routes, where it is drawn as the
|
|
17
|
+
* fish (fish.ts). */
|
|
18
|
+
export interface FishDrawing {
|
|
19
|
+
/** the spine, along row `y` from its tail to the head's border */
|
|
20
|
+
spine: {
|
|
21
|
+
y: number;
|
|
22
|
+
from: number;
|
|
23
|
+
to: number;
|
|
24
|
+
};
|
|
25
|
+
/** the effect, boxed at the spine's right end */
|
|
26
|
+
head: string;
|
|
27
|
+
/** the categories and causes, drawn as their words rather than boxed: each line
|
|
28
|
+
* where it starts. A node's box in `boxes` is the cells its words take. */
|
|
29
|
+
words: Map<string, (CellPoint & {
|
|
30
|
+
text: string;
|
|
31
|
+
})[]>;
|
|
32
|
+
/** the categories among `words`: their bones' labels */
|
|
33
|
+
labels: Set<string>;
|
|
34
|
+
}
|
|
35
|
+
export interface TextLayout {
|
|
36
|
+
width: number;
|
|
37
|
+
height: number;
|
|
38
|
+
boxes: Map<string, BoxGeometry>;
|
|
39
|
+
routes: Map<string, Route>;
|
|
40
|
+
fish?: FishDrawing;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* elk `layered`, in character cells: a node is as big as its text, and the gaps
|
|
44
|
+
* are a few cells. elk's options do not inherit into nested graphs, and every one it
|
|
45
|
+
* is not told falls back to its pixel-sized default (10, 12, 20 …), which in cells
|
|
46
|
+
* opens tens of rows between the levels of a container — so this set goes on the
|
|
47
|
+
* root and on every container alike.
|
|
48
|
+
*/
|
|
49
|
+
export declare const CELL_OPTIONS: Readonly<Record<string, string>>;
|
|
50
|
+
/** Where a box is from an end of a route that stops beside it: the direction (a
|
|
51
|
+
* glyph mask bit) to step from the end to reach its border; undefined when the end is
|
|
52
|
+
* not beside it. */
|
|
53
|
+
export declare function towardBox(end: CellPoint, g: BoxGeometry): number | undefined;
|
|
54
|
+
/** One cell's step in each direction. */
|
|
55
|
+
export declare const STEP: Readonly<Record<number, CellPoint>>;
|
|
56
|
+
/**
|
|
57
|
+
* Lays the view out in cells. Every one of `layoutEdges` takes part, drawn or not,
|
|
58
|
+
* so that turning a layer on or off never moves a box (the renderer's rule); the
|
|
59
|
+
* routes of the edges actually drawn are picked from the result by id.
|
|
60
|
+
*/
|
|
61
|
+
export declare function layoutCells(view: CompiledView, boxes: ReadonlyMap<string, BoxText>, direction: string, labels: ReadonlyMap<string, string>): Promise<TextLayout>;
|