@venizia/vulcan 0.4.8 → 0.4.9-1
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/base/extensions/vulcan-guards.ts +48 -41
- package/base/hooks/antigravity-guards.ts +4 -3
- package/base/hooks/codex-guards.ts +17 -6
- package/base/hooks/guard-git.ts +8 -8
- package/base/hooks/guard-manifest.ts +5 -5
- package/base/hooks/guard-outside.ts +8 -8
- package/base/hooks/guard-package.ts +6 -6
- package/base/hooks/guard-remote-hosts.ts +14 -9
- package/base/hooks/guard-scripting.ts +6 -6
- package/base/hooks/guard-writes.ts +20 -11
- package/base/hooks/post-tool.ts +4 -3
- package/base/hooks/prompt-submit.ts +4 -3
- package/base/hooks/session-start.ts +5 -3
- package/base/hooks/stop.ts +4 -3
- package/base/hooks/subagent-start.ts +2 -2
- package/base/make/vulcan.mk +1 -4
- package/base/skills/build-a-feature/SKILL.md +1 -1
- package/base/skills/docs-update/SKILL.md +11 -5
- package/base/skills/docs-update/evals/evals.json +1 -1
- package/base/skills/docs-writing/SKILL.md +1 -1
- package/base/skills/plan-a-change/references/spec-card.md +1 -1
- package/base/skills/ship/SKILL.md +1 -1
- package/base/skills/visualize-work/SKILL.md +29 -6
- package/base/skills/visualize-work/references/spec.md +16 -5
- package/package.json +5 -6
- package/src/agents/atlas-block.ts +43 -43
- package/src/agents/codex-hooks.ts +55 -52
- package/src/agents/common/types.ts +1 -1
- package/src/agents/detect.ts +19 -16
- package/src/agents/exclude.ts +97 -98
- package/src/agents/hooks-json.ts +41 -43
- package/src/agents/local.ts +46 -43
- package/src/agents/prompt.ts +45 -42
- package/src/agents/render.ts +203 -201
- package/src/agents/resolve.ts +133 -134
- package/src/agents/table.ts +12 -8
- package/src/cli.ts +3 -1
- package/src/commands/add.command.ts +2 -2
- package/src/commands/agents.command.ts +11 -17
- package/src/commands/clean.command.ts +6 -6
- package/src/commands/doctor.command.ts +6 -4
- package/src/commands/help.command.ts +11 -9
- package/src/commands/init.command.ts +14 -8
- package/src/commands/preset.command.ts +2 -2
- package/src/commands/profile.command.ts +43 -50
- package/src/commands/sync.command.ts +109 -111
- package/src/commands/upgrade.command.ts +85 -78
- package/src/commands/visualize.command.ts +20 -5
- package/src/commands/x.command.ts +55 -50
- package/src/common/format.ts +23 -21
- package/src/common/index.ts +2 -0
- package/src/common/json.ts +8 -5
- package/src/common/layout-folder.ts +96 -111
- package/src/common/paths.ts +14 -12
- package/src/common/record.ts +7 -0
- package/src/common/text.ts +7 -0
- package/src/config/common/constants.ts +13 -1
- package/src/config/common/types.ts +8 -1
- package/src/config/loader.ts +53 -48
- package/src/config/packages.ts +17 -11
- package/src/config/schema.ts +54 -7
- package/src/create/add-app.ts +604 -493
- package/src/create/add-lib.ts +249 -242
- package/src/create/bunfig.ts +26 -23
- package/src/create/checks.ts +36 -34
- package/src/create/common/constants.ts +1 -0
- package/src/create/common/failure.ts +10 -0
- package/src/create/common/index.ts +2 -0
- package/src/create/common/preset-path.ts +11 -0
- package/src/create/common/types.ts +7 -2
- package/src/create/diff.ts +21 -23
- package/src/create/dockerignore.ts +26 -24
- package/src/create/files.ts +7 -5
- package/src/create/init-monorepo.ts +78 -80
- package/src/create/lib-preset.ts +62 -61
- package/src/create/manifest-json.ts +10 -4
- package/src/create/names.ts +217 -210
- package/src/create/next.ts +27 -24
- package/src/create/plan.ts +15 -12
- package/src/create/preset-diff.ts +415 -240
- package/src/create/preset-menu.ts +40 -34
- package/src/create/preset.ts +207 -194
- package/src/create/process.ts +80 -71
- package/src/create/scratch.ts +49 -48
- package/src/create/workspace.ts +423 -398
- package/src/doctor/checks.ts +1069 -998
- package/src/doctor/makefile.ts +17 -13
- package/src/doctor/runner.ts +88 -116
- package/src/doctor/skills.ts +97 -95
- package/src/doctor/tags.ts +44 -41
- package/src/hooks/codex-patch.ts +27 -24
- package/src/hooks/command-view.ts +44 -39
- package/src/hooks/common/constants.ts +0 -3
- package/src/hooks/common/types.ts +15 -1
- package/src/hooks/decision.ts +38 -42
- package/src/hooks/guard-git.ts +52 -50
- package/src/hooks/guard-manifest.ts +58 -55
- package/src/hooks/guard-outside.ts +109 -88
- package/src/hooks/guard-package.ts +86 -77
- package/src/hooks/guard-scripting.ts +20 -15
- package/src/hooks/guard-writes.ts +169 -111
- package/src/hooks/owner-reply.ts +128 -128
- package/src/hooks/post-tool.ts +94 -93
- package/src/hooks/project-guards.ts +93 -55
- package/src/hooks/project-tmp.ts +27 -24
- package/src/hooks/remote-hosts.ts +157 -149
- package/src/hooks/session-digest.ts +99 -95
- package/src/hooks/shell.ts +519 -500
- package/src/hooks/subagent-card.ts +11 -7
- package/src/hooks/trusted-scripts.ts +158 -80
- package/src/init/common/types.ts +1 -1
- package/src/init/scaffold.ts +137 -134
- package/src/local/clean.ts +39 -37
- package/src/local/format.ts +21 -17
- package/src/local/scan.ts +146 -140
- package/src/manifest/render.ts +127 -112
- package/src/owner/card.ts +51 -46
- package/src/owner/profile.ts +100 -96
- package/src/owner/reply-switch.ts +9 -6
- package/src/owner/shape.ts +72 -70
- package/src/owner/survey.ts +175 -164
- package/src/owner/view.ts +62 -59
- package/src/owner/violations.ts +119 -123
- package/src/router.ts +4 -1
- package/src/rules/base.ts +15 -11
- package/src/rules/common/types.ts +1 -1
- package/src/rules/parser.ts +39 -32
- package/src/rules/slots.ts +8 -6
- package/src/signals/claims.ts +30 -28
- package/src/signals/classify.ts +36 -33
- package/src/signals/loop.ts +39 -37
- package/src/signals/state.ts +80 -85
- package/src/skills/frontmatter.ts +28 -28
- package/src/sync/agent-files.ts +217 -199
- package/src/sync/agent-removal.ts +62 -68
- package/src/sync/atlas-block.ts +45 -43
- package/src/sync/base-rules.ts +32 -30
- package/src/sync/claude-launch.ts +74 -37
- package/src/sync/common/constants.ts +4 -0
- package/src/sync/common/index.ts +1 -0
- package/src/sync/common/symlink.ts +9 -0
- package/src/sync/common/types.ts +2 -2
- package/src/sync/exclude.ts +77 -69
- package/src/sync/local-choice.ts +50 -47
- package/src/sync/planner.ts +64 -68
- package/src/sync/prune.ts +52 -48
- package/src/sync/settings.ts +167 -168
- package/src/ui/capability.ts +12 -7
- package/src/ui/keyboard.ts +35 -33
- package/src/ui/prompt.ts +81 -77
- package/src/visualize/assets.ts +379 -195
- package/src/visualize/charts.ts +188 -176
- package/src/visualize/compare-css.ts +31 -0
- package/src/visualize/compare-render.ts +196 -0
- package/src/visualize/compare-schema.ts +81 -0
- package/src/visualize/compare-validate.ts +126 -0
- package/src/visualize/constants.ts +29 -3
- package/src/visualize/diagrams.ts +189 -174
- package/src/visualize/gate.ts +136 -0
- package/src/visualize/grid-span.ts +34 -0
- package/src/visualize/icons.ts +9 -4
- package/src/visualize/index.ts +2 -0
- package/src/visualize/kinds-css.ts +54 -0
- package/src/visualize/kinds-render.ts +698 -0
- package/src/visualize/kinds-schema.ts +148 -0
- package/src/visualize/kinds-validate.ts +186 -0
- package/src/visualize/labels-vi.ts +109 -0
- package/src/visualize/labels.ts +53 -0
- package/src/visualize/layout.ts +112 -92
- package/src/visualize/page.ts +140 -114
- package/src/visualize/render.ts +158 -114
- package/src/visualize/schema.ts +21 -1
- package/src/visualize/sections.ts +401 -309
- package/src/visualize/sources.ts +270 -0
- package/src/visualize/theme.ts +474 -0
- package/src/visualize/validate.ts +15 -5
- package/src/wiki/anchors.ts +39 -37
- package/src/wiki/command.ts +4 -4
- package/src/wiki/source-links.ts +49 -49
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { NodeKinds, NodeStates, VisualizeLimits } from './constants.ts';
|
|
3
|
+
import { SOURCE_SCHEMA } from './sources.ts';
|
|
4
|
+
|
|
5
|
+
/** Which of the two versions an edge belongs to: both, only the first (a), or only the second (b). */
|
|
6
|
+
export class EdgeSides {
|
|
7
|
+
static readonly BOTH = 'both';
|
|
8
|
+
static readonly A = 'a';
|
|
9
|
+
static readonly B = 'b';
|
|
10
|
+
static readonly SCHEME_SET = new Set<string>([this.BOTH, this.A, this.B]);
|
|
11
|
+
|
|
12
|
+
static isValid(value: string): boolean {
|
|
13
|
+
return this.SCHEME_SET.has(value);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** The limits of the compare view; the shared ones come from `VisualizeLimits`. */
|
|
18
|
+
export class CompareLimits {
|
|
19
|
+
/** The name of a side is read in a sentence with `only here`, so it is short. */
|
|
20
|
+
static readonly MAX_SIDE = 24;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** One line of plain text: no markup is interpreted anywhere, it is all escaped. */
|
|
24
|
+
const text = (max: number) =>
|
|
25
|
+
z
|
|
26
|
+
.string()
|
|
27
|
+
.max(max)
|
|
28
|
+
.regex(/^(?=.*\S)[^\p{Cc}--]+$/u, 'one line of text, not blank');
|
|
29
|
+
/** A closed set as a pattern, so the printed JSON Schema says the same as the renderer. */
|
|
30
|
+
const choice = (opts: { set: Set<string> }) =>
|
|
31
|
+
z
|
|
32
|
+
.string()
|
|
33
|
+
.regex(new RegExp(`^(${[...opts.set].join('|')})$`), `one of: ${[...opts.set].join(', ')}`);
|
|
34
|
+
const ID = z
|
|
35
|
+
.string()
|
|
36
|
+
.regex(/^[a-z][a-z0-9-]{0,31}$/, 'lowercase letters, digits and -, at most 32');
|
|
37
|
+
const GRID = z
|
|
38
|
+
.number()
|
|
39
|
+
.int()
|
|
40
|
+
.min(0)
|
|
41
|
+
.max(VisualizeLimits.MAX_GRID - 1);
|
|
42
|
+
|
|
43
|
+
/** Two versions of one mechanism as one figure: the boxes they share, and the arrows each has or lacks. */
|
|
44
|
+
export const COMPARE_SCHEMA = z.strictObject({
|
|
45
|
+
/** The name of the first version. */
|
|
46
|
+
a: text(CompareLimits.MAX_SIDE),
|
|
47
|
+
/** The name of the second version. */
|
|
48
|
+
b: text(CompareLimits.MAX_SIDE),
|
|
49
|
+
nodes: z
|
|
50
|
+
.array(
|
|
51
|
+
z.strictObject({
|
|
52
|
+
id: ID,
|
|
53
|
+
label: text(VisualizeLimits.MAX_LABEL),
|
|
54
|
+
sublabel: text(VisualizeLimits.MAX_LABEL).optional(),
|
|
55
|
+
row: GRID,
|
|
56
|
+
col: GRID,
|
|
57
|
+
kind: choice({ set: NodeKinds.SCHEME_SET }).optional(),
|
|
58
|
+
state: choice({ set: NodeStates.SCHEME_SET }).optional(),
|
|
59
|
+
source: SOURCE_SCHEMA.optional(),
|
|
60
|
+
}),
|
|
61
|
+
)
|
|
62
|
+
.min(2)
|
|
63
|
+
.max(VisualizeLimits.MAX_NODES),
|
|
64
|
+
edges: z
|
|
65
|
+
.array(
|
|
66
|
+
z.strictObject({
|
|
67
|
+
from: ID,
|
|
68
|
+
to: ID,
|
|
69
|
+
/** Every arrow says what it does: a verb. */
|
|
70
|
+
label: text(VisualizeLimits.MAX_EDGE_LABEL),
|
|
71
|
+
/** Absent, the arrow is in both versions. */
|
|
72
|
+
in: choice({ set: EdgeSides.SCHEME_SET }).optional(),
|
|
73
|
+
}),
|
|
74
|
+
)
|
|
75
|
+
.min(1)
|
|
76
|
+
.max(VisualizeLimits.MAX_EDGES),
|
|
77
|
+
/** The sentence under the figure; absent, the page counts the changed arrows itself. */
|
|
78
|
+
caption: text(VisualizeLimits.MAX_SENTENCE).optional(),
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
export type TCompare = z.output<typeof COMPARE_SCHEMA>;
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { EdgeSides } from './compare-schema.ts';
|
|
2
|
+
import type { TCompare } from './compare-schema.ts';
|
|
3
|
+
|
|
4
|
+
/** The part of a page spec the compare view lives in. */
|
|
5
|
+
export interface ICompareSpec {
|
|
6
|
+
compare?: TCompare | undefined;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
interface ICell {
|
|
10
|
+
row: number;
|
|
11
|
+
col: number;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** What a schema cannot say about the compare view: ids, ends of arrows, the grid, and that something differs. */
|
|
15
|
+
export class CompareChecks {
|
|
16
|
+
/** The boxes an arrow would cross: along the source's row to the target's column, then along that column. */
|
|
17
|
+
private static blockersOf(opts: {
|
|
18
|
+
from: ICell;
|
|
19
|
+
to: ICell;
|
|
20
|
+
cells: Map<string, string>;
|
|
21
|
+
}): string[] {
|
|
22
|
+
const { from, to, cells } = opts;
|
|
23
|
+
const crossed: ICell[] = [];
|
|
24
|
+
const between = (start: number, end: number): number[] => {
|
|
25
|
+
const sign = end > start ? 1 : -1;
|
|
26
|
+
const found: number[] = [];
|
|
27
|
+
|
|
28
|
+
for (let at = start + sign; start !== end && at !== end; at += sign) {
|
|
29
|
+
found.push(at);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return found;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
for (const col of between(from.col, to.col)) {
|
|
36
|
+
crossed.push({ row: from.row, col });
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (from.row !== to.row && from.col !== to.col) {
|
|
40
|
+
crossed.push({ row: from.row, col: to.col });
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
for (const row of between(from.row, to.row)) {
|
|
44
|
+
crossed.push({ row, col: to.col });
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return crossed.flatMap((cell) => cells.get(`${cell.row},${cell.col}`) ?? []);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
static check(opts: { spec: ICompareSpec }): string[] {
|
|
51
|
+
const { compare } = opts.spec;
|
|
52
|
+
|
|
53
|
+
if (compare === undefined) {
|
|
54
|
+
return [];
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const problems: string[] = [];
|
|
58
|
+
const ids = new Set<string>();
|
|
59
|
+
const cells = new Map<string, string>();
|
|
60
|
+
const positions = new Map<string, ICell>();
|
|
61
|
+
|
|
62
|
+
for (const node of compare.nodes) {
|
|
63
|
+
if (ids.has(node.id)) {
|
|
64
|
+
problems.push(`compare.nodes: id '${node.id}' is used twice`);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
ids.add(node.id);
|
|
68
|
+
|
|
69
|
+
const owner = cells.get(`${node.row},${node.col}`);
|
|
70
|
+
|
|
71
|
+
if (owner !== undefined) {
|
|
72
|
+
problems.push(
|
|
73
|
+
`compare.nodes: '${node.id}' and '${owner}' are both in row ${node.row}, col ${node.col}`,
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
cells.set(`${node.row},${node.col}`, node.id);
|
|
78
|
+
positions.set(node.id, { row: node.row, col: node.col });
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const names = new Set<string>();
|
|
82
|
+
|
|
83
|
+
for (const edge of compare.edges) {
|
|
84
|
+
const name = `${edge.from}>${edge.to}`;
|
|
85
|
+
|
|
86
|
+
for (const end of [edge.from, edge.to]) {
|
|
87
|
+
if (!ids.has(end)) {
|
|
88
|
+
problems.push(`compare.edges: '${name}' names '${end}', which is not a node`);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (edge.from === edge.to) {
|
|
93
|
+
problems.push(`compare.edges: '${name}' loops to itself`);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (names.has(name)) {
|
|
97
|
+
problems.push(`compare.edges: '${name}' is drawn twice`);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (names.has(`${edge.to}>${edge.from}`)) {
|
|
101
|
+
problems.push(
|
|
102
|
+
`compare.edges: '${name}' and '${edge.to}>${edge.from}' run on the same line - draw one arrow, or put the boxes in another place`,
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
names.add(name);
|
|
107
|
+
|
|
108
|
+
const from = positions.get(edge.from);
|
|
109
|
+
const to = positions.get(edge.to);
|
|
110
|
+
|
|
111
|
+
if (from !== undefined && to !== undefined && edge.from !== edge.to) {
|
|
112
|
+
for (const blocker of CompareChecks.blockersOf({ from, to, cells })) {
|
|
113
|
+
problems.push(
|
|
114
|
+
`compare.edges: '${name}' would be drawn through box '${blocker}' - move a box`,
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (!compare.edges.some((edge) => (edge.in ?? EdgeSides.BOTH) !== EdgeSides.BOTH)) {
|
|
121
|
+
problems.push("compare: no edge differs between 'a' and 'b'");
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return problems;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
@@ -156,9 +156,9 @@ export class VisualizeLimits {
|
|
|
156
156
|
static readonly MAX_SERIES = 3;
|
|
157
157
|
static readonly MAX_PARTS = 5;
|
|
158
158
|
static readonly MAX_LIST = 6;
|
|
159
|
-
/** Typical pages are
|
|
160
|
-
static readonly WARN_BYTES =
|
|
161
|
-
static readonly FAIL_BYTES =
|
|
159
|
+
/** Typical pages are 30-60 KB; a page past `FAIL_BYTES` is refused: two pages, not one dense one. */
|
|
160
|
+
static readonly WARN_BYTES = 80 * 1024;
|
|
161
|
+
static readonly FAIL_BYTES = 150 * 1024;
|
|
162
162
|
static readonly OUTPUT_DIRECTORY = 'prototypes';
|
|
163
163
|
}
|
|
164
164
|
|
|
@@ -243,5 +243,31 @@ export const DEFAULT_CHROME = {
|
|
|
243
243
|
tableView: 'Table view',
|
|
244
244
|
value: 'Value',
|
|
245
245
|
uses: 'Uses',
|
|
246
|
+
/** The theme switch says what a click does. */
|
|
247
|
+
themeToLight: 'Switch to the light theme',
|
|
248
|
+
themeToDark: 'Switch to the dark theme',
|
|
249
|
+
/** The label of the in-page links in the top bar. */
|
|
250
|
+
navLabel: 'On this page',
|
|
251
|
+
sequence: 'Sequence',
|
|
252
|
+
lifecycle: 'Lifecycle',
|
|
253
|
+
tree: 'Structure',
|
|
254
|
+
compareView: 'What differs',
|
|
255
|
+
inBoth: 'in both',
|
|
256
|
+
sources: 'Sources',
|
|
257
|
+
terms: 'Words in this page',
|
|
258
|
+
/** The words that tell an added arrow from a removed one: never colour alone. */
|
|
259
|
+
onlyHere: 'only here',
|
|
260
|
+
addedEdge: 'added',
|
|
261
|
+
removedEdge: 'removed',
|
|
262
|
+
/** The words of the sequence, lifecycle and tree figures: a message kind, a state kind, and the counts in their captions. */
|
|
263
|
+
kindCall: 'call',
|
|
264
|
+
kindReply: 'reply',
|
|
265
|
+
kindAsync: 'async',
|
|
266
|
+
stateStart: 'start',
|
|
267
|
+
stateEnd: 'end',
|
|
268
|
+
countMessages: 'messages',
|
|
269
|
+
countStates: 'states',
|
|
270
|
+
countTransitions: 'transitions',
|
|
271
|
+
countItems: 'items',
|
|
246
272
|
};
|
|
247
273
|
export type TChrome = typeof DEFAULT_CHROME;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { NodeStates } from './constants.ts';
|
|
2
2
|
import type { TChrome } from './constants.ts';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
3
|
+
import { SpecCharts } from './charts.ts';
|
|
4
|
+
import { GridSpans } from './grid-span.ts';
|
|
5
|
+
import { IconSet } from './icons.ts';
|
|
6
|
+
import { FigureLayout } from './layout.ts';
|
|
6
7
|
import type { TVisualizeSpec } from './schema.ts';
|
|
7
8
|
|
|
8
9
|
type TDiagram = NonNullable<NonNullable<TVisualizeSpec['explainer']>['steps'][number]['diagram']>;
|
|
@@ -15,7 +16,7 @@ export interface IDrawing {
|
|
|
15
16
|
fallback: string;
|
|
16
17
|
}
|
|
17
18
|
|
|
18
|
-
const escaped = (value: string): string => escapeText({ value });
|
|
19
|
+
const escaped = (value: string): string => FigureLayout.escapeText({ value });
|
|
19
20
|
|
|
20
21
|
const box = (opts: {
|
|
21
22
|
x: number;
|
|
@@ -36,189 +37,203 @@ const box = (opts: {
|
|
|
36
37
|
const arrowHead = (opts: { x: number; y: number }): string =>
|
|
37
38
|
`<path d="M${opts.x - 7} ${opts.y - 5}L${opts.x} ${opts.y}L${opts.x - 7} ${opts.y + 5}" fill="none" class="dline"/>`;
|
|
38
39
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
export class SpecDiagrams {
|
|
41
|
+
/** An explainer step's diagram: a row of boxes joined by labelled arrows, or stacked layers. */
|
|
42
|
+
static render(opts: { diagram: TDiagram }): IDrawing {
|
|
43
|
+
const { diagram } = opts;
|
|
44
|
+
|
|
45
|
+
if (diagram.type === 'row') {
|
|
46
|
+
const longest = Math.max(
|
|
47
|
+
...diagram.nodes.flatMap((node) => [
|
|
48
|
+
node.label.length * 8.2,
|
|
49
|
+
(node.sub?.length ?? 0) * 7.6,
|
|
50
|
+
]),
|
|
51
|
+
);
|
|
52
|
+
const bw = Math.max(124, Math.ceil(longest) + 24);
|
|
53
|
+
const gap = 78;
|
|
54
|
+
const width = diagram.nodes.length * bw + (diagram.nodes.length - 1) * gap + 16;
|
|
55
|
+
const parts = diagram.nodes
|
|
56
|
+
.map((node, index) => {
|
|
57
|
+
const x = 8 + index * (bw + gap);
|
|
58
|
+
const label = diagram.arrows?.[index];
|
|
59
|
+
const arrow =
|
|
60
|
+
index < diagram.nodes.length - 1
|
|
61
|
+
? `<path d="M${x + bw + 4} 40H${x + bw + gap - 4}" class="dline"/>${arrowHead({ x: x + bw + gap - 4, y: 40 })}${label === undefined ? '' : `<text class="dl" x="${x + bw + gap / 2}" y="30" text-anchor="middle">${escaped(label)}</text>`}`
|
|
62
|
+
: '';
|
|
63
|
+
|
|
64
|
+
return `${box({ x, y: 12, width: bw, height: 56, label: node.label, sub: node.sub })}${arrow}`;
|
|
65
|
+
})
|
|
66
|
+
.join('');
|
|
67
|
+
|
|
68
|
+
return {
|
|
69
|
+
svg: `<svg width="${width}" viewBox="0 0 ${width} 80" role="group" aria-label="diagram">${parts}</svg>`,
|
|
70
|
+
width,
|
|
71
|
+
fallback: `<ol class="path">${diagram.nodes
|
|
72
|
+
.map(
|
|
73
|
+
(node, index) =>
|
|
74
|
+
`<li><b>${escaped(node.label)}</b>${node.sub === undefined ? '' : ` <span class="mut">${escaped(node.sub)}</span>`}${index < diagram.nodes.length - 1 && diagram.arrows?.[index] !== undefined ? `<span class="verb">${escaped(diagram.arrows[index] ?? '')}</span>` : ''}</li>`,
|
|
75
|
+
)
|
|
76
|
+
.join('')}</ol>`,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
42
79
|
|
|
43
|
-
|
|
44
|
-
const
|
|
45
|
-
|
|
80
|
+
const most = Math.max(...diagram.layers.map((layer) => layer.items.length));
|
|
81
|
+
const label = Math.max(
|
|
82
|
+
112,
|
|
83
|
+
Math.ceil(Math.max(...diagram.layers.map((layer) => layer.label.length)) * 8.8) + 30,
|
|
84
|
+
);
|
|
85
|
+
const iw = Math.max(
|
|
86
|
+
112,
|
|
87
|
+
Math.ceil(
|
|
88
|
+
Math.max(...diagram.layers.flatMap((layer) => layer.items.map((item) => item.length))) * 8,
|
|
89
|
+
) + 24,
|
|
46
90
|
);
|
|
47
|
-
const
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
const label = diagram.arrows?.[index];
|
|
54
|
-
const arrow =
|
|
55
|
-
index < diagram.nodes.length - 1
|
|
56
|
-
? `<path d="M${x + bw + 4} 40H${x + bw + gap - 4}" class="dline"/>${arrowHead({ x: x + bw + gap - 4, y: 40 })}${label === undefined ? '' : `<text class="dl" x="${x + bw + gap / 2}" y="30" text-anchor="middle">${escaped(label)}</text>`}`
|
|
57
|
-
: '';
|
|
58
|
-
|
|
59
|
-
return `${box({ x, y: 12, width: bw, height: 56, label: node.label, sub: node.sub })}${arrow}`;
|
|
91
|
+
const width = label + most * (iw + 10) + 14;
|
|
92
|
+
const parts = diagram.layers
|
|
93
|
+
.map((layer, row) => {
|
|
94
|
+
const y = 8 + row * 62;
|
|
95
|
+
|
|
96
|
+
return `<g><rect x="4" y="${y}" width="${width - 8}" height="54" rx="4" class="dband"/><text class="dlab" x="14" y="${y + 31}">${escaped(layer.label)}</text>${layer.items.map((item, col) => box({ x: label + col * (iw + 10), y: y + 8, width: iw, height: 38, label: item })).join('')}</g>`;
|
|
60
97
|
})
|
|
61
98
|
.join('');
|
|
62
99
|
|
|
63
100
|
return {
|
|
64
|
-
svg: `<svg width="${width}" viewBox="0 0 ${width}
|
|
101
|
+
svg: `<svg width="${width}" viewBox="0 0 ${width} ${diagram.layers.length * 62 + 12}" role="group" aria-label="layers">${parts}</svg>`,
|
|
65
102
|
width,
|
|
66
|
-
fallback: `<
|
|
67
|
-
.map(
|
|
68
|
-
(node, index) =>
|
|
69
|
-
`<li><b>${escaped(node.label)}</b>${node.sub === undefined ? '' : ` <span class="mut">${escaped(node.sub)}</span>`}${index < diagram.nodes.length - 1 && diagram.arrows?.[index] !== undefined ? `<span class="verb">${escaped(diagram.arrows[index] ?? '')}</span>` : ''}</li>`,
|
|
70
|
-
)
|
|
71
|
-
.join('')}</ol>`,
|
|
103
|
+
fallback: `<ul class="path">${diagram.layers.map((layer) => `<li><b>${escaped(layer.label)}</b>: ${layer.items.map(escaped).join(', ')}</li>`).join('')}</ul>`,
|
|
72
104
|
};
|
|
73
105
|
}
|
|
74
106
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
Math.
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
) +
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
.
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
const bw = 176;
|
|
111
|
-
const bh = 68;
|
|
112
|
-
const gap = 64;
|
|
113
|
-
const rowHeight = 190;
|
|
114
|
-
const width = label + most * (bw + gap) + 4;
|
|
115
|
-
const height = architecture.layers.length * rowHeight + 8;
|
|
116
|
-
const positions = new Map<string, { x: number; y: number; row: number }>();
|
|
117
|
-
|
|
118
|
-
architecture.layers.forEach((layer, row) => {
|
|
119
|
-
const total = layer.boxes.length * (bw + gap) - gap;
|
|
120
|
-
const start = label + (most * (bw + gap) - gap - total) / 2;
|
|
121
|
-
|
|
122
|
-
layer.boxes.forEach((boxSpec, col) =>
|
|
123
|
-
positions.set(boxSpec.id, { x: start + col * (bw + gap), y: 4 + row * rowHeight + 34, row }),
|
|
124
|
-
);
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
const bands = architecture.layers
|
|
128
|
-
.map(
|
|
129
|
-
(layer, row) =>
|
|
130
|
-
`<rect x="2" y="${4 + row * rowHeight}" width="${width - 4}" height="${rowHeight - 14}" rx="4" class="dband"/><text class="dlab" x="14" y="${4 + row * rowHeight + 24}">${escaped(layer.label)}</text>`,
|
|
131
|
-
)
|
|
132
|
-
.join('');
|
|
133
|
-
// Links that cross the same gap between two layers get their own horizontal run, so no two lines share one.
|
|
134
|
-
const lanes = new Map<number, number>();
|
|
135
|
-
const across = new Map<number, number>();
|
|
136
|
-
|
|
137
|
-
for (const link of architecture.links) {
|
|
138
|
-
const from = positions.get(link.from);
|
|
139
|
-
const to = positions.get(link.to);
|
|
140
|
-
|
|
141
|
-
if (from !== undefined && to !== undefined && from.row !== to.row) {
|
|
142
|
-
across.set(Math.min(from.row, to.row), (across.get(Math.min(from.row, to.row)) ?? 0) + 1);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
const links = architecture.links
|
|
147
|
-
.map((link) => {
|
|
148
|
-
const a = positions.get(link.from);
|
|
149
|
-
const b = positions.get(link.to);
|
|
150
|
-
|
|
151
|
-
if (a === undefined || b === undefined) {
|
|
152
|
-
return '';
|
|
153
|
-
}
|
|
107
|
+
/** The layered view: bands from top to bottom, boxes in each, and an elbow line for every link. */
|
|
108
|
+
static renderArchitecture(opts: { architecture: TArchitecture; chrome: TChrome }): IDrawing {
|
|
109
|
+
const { architecture } = opts;
|
|
110
|
+
const most = Math.max(...architecture.layers.map((layer) => layer.boxes.length));
|
|
111
|
+
const label = 120;
|
|
112
|
+
const bw = 176;
|
|
113
|
+
const bh = 68;
|
|
114
|
+
const gap = 64;
|
|
115
|
+
const rowHeight = 190;
|
|
116
|
+
const width = label + most * (bw + gap) + 4;
|
|
117
|
+
const height = architecture.layers.length * rowHeight + 8;
|
|
118
|
+
const positions = new Map<string, { x: number; y: number; row: number }>();
|
|
119
|
+
|
|
120
|
+
architecture.layers.forEach((layer, row) => {
|
|
121
|
+
const total = layer.boxes.length * (bw + gap) - gap;
|
|
122
|
+
const start = label + (most * (bw + gap) - gap - total) / 2;
|
|
123
|
+
|
|
124
|
+
layer.boxes.forEach((boxSpec, col) =>
|
|
125
|
+
positions.set(boxSpec.id, {
|
|
126
|
+
x: start + col * (bw + gap),
|
|
127
|
+
y: 4 + row * rowHeight + 34,
|
|
128
|
+
row,
|
|
129
|
+
}),
|
|
130
|
+
);
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
const bands = architecture.layers
|
|
134
|
+
.map(
|
|
135
|
+
(layer, row) =>
|
|
136
|
+
`<rect x="2" y="${4 + row * rowHeight}" width="${width - 4}" height="${rowHeight - 14}" rx="4" class="dband"/><text class="dlab" x="14" y="${4 + row * rowHeight + 24}">${escaped(layer.label)}</text>`,
|
|
137
|
+
)
|
|
138
|
+
.join('');
|
|
139
|
+
// Links that cross the same gap between two layers get their own horizontal run, so no two lines share one.
|
|
140
|
+
const lanes = new Map<number, number>();
|
|
141
|
+
const across = new Map<number, number>();
|
|
154
142
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
const x2 = sign === 1 ? b.x : b.x + bw;
|
|
159
|
-
const y = a.y + bh / 2;
|
|
143
|
+
for (const link of architecture.links) {
|
|
144
|
+
const from = positions.get(link.from);
|
|
145
|
+
const to = positions.get(link.to);
|
|
160
146
|
|
|
161
|
-
|
|
147
|
+
if (from !== undefined && to !== undefined && from.row !== to.row) {
|
|
148
|
+
across.set(Math.min(from.row, to.row), (across.get(Math.min(from.row, to.row)) ?? 0) + 1);
|
|
162
149
|
}
|
|
150
|
+
}
|
|
163
151
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
152
|
+
const links = architecture.links
|
|
153
|
+
.map((link) => {
|
|
154
|
+
const a = positions.get(link.from);
|
|
155
|
+
const b = positions.get(link.to);
|
|
156
|
+
|
|
157
|
+
if (a === undefined || b === undefined) {
|
|
158
|
+
return '';
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
if (a.row === b.row) {
|
|
162
|
+
const sign = a.x < b.x ? 1 : -1;
|
|
163
|
+
const x1 = sign === 1 ? a.x + bw : a.x;
|
|
164
|
+
const x2 = sign === 1 ? b.x : b.x + bw;
|
|
165
|
+
const y = a.y + bh / 2;
|
|
166
|
+
|
|
167
|
+
return `<g class="dlink"><path d="M${x1} ${y}H${x2}" class="dline"/><path d="M${x2 - sign * 7} ${y - 5}L${x2} ${y}L${x2 - sign * 7} ${y + 5}" fill="none" class="dline"/>${link.label === undefined ? '' : `<text class="dl" x="${(x1 + x2) / 2}" y="${y - 8}" text-anchor="middle">${escaped(link.label)}</text>`}</g>`;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const down = a.row < b.row;
|
|
171
|
+
const gapIndex = Math.min(a.row, b.row);
|
|
172
|
+
const lane = lanes.get(gapIndex) ?? 0;
|
|
173
|
+
|
|
174
|
+
lanes.set(gapIndex, lane + 1);
|
|
175
|
+
|
|
176
|
+
const top = 4 + gapIndex * rowHeight + 34 + bh;
|
|
177
|
+
const bottom = 4 + (gapIndex + 1) * rowHeight + 34;
|
|
178
|
+
const ym =
|
|
179
|
+
top + 14 + ((bottom - top - 28) * (lane + 1)) / ((across.get(gapIndex) ?? 1) + 1);
|
|
180
|
+
const shift = lane % 3 === 1 ? 10 : lane % 3 === 2 ? -10 : 0;
|
|
181
|
+
const x1 = a.x + bw / 2 + shift;
|
|
182
|
+
const x2 = b.x + bw / 2 + shift;
|
|
183
|
+
const y1 = down ? a.y + bh : a.y;
|
|
184
|
+
const y2 = down ? b.y : b.y + bh;
|
|
185
|
+
const tip = down ? -7 : 7;
|
|
186
|
+
|
|
187
|
+
return `<g class="dlink"><path d="M${x1} ${y1}V${ym}H${x2}V${y2}" class="dline"/><path d="M${x2 - 5} ${y2 + tip}L${x2} ${y2}L${x2 + 5} ${y2 + tip}" fill="none" class="dline"/>${link.label === undefined ? '' : `<text class="dl" x="${(x1 + x2) / 2}" y="${ym - 5}" text-anchor="middle">${escaped(link.label)}</text>`}</g>`;
|
|
188
|
+
})
|
|
189
|
+
.join('');
|
|
190
|
+
const boxes = architecture.layers
|
|
191
|
+
.flatMap((layer) => layer.boxes)
|
|
192
|
+
.map((spec) => {
|
|
193
|
+
const p = positions.get(spec.id);
|
|
194
|
+
|
|
195
|
+
return p === undefined
|
|
196
|
+
? ''
|
|
197
|
+
: box({
|
|
198
|
+
x: p.x,
|
|
199
|
+
y: p.y,
|
|
200
|
+
width: bw,
|
|
201
|
+
height: bh,
|
|
202
|
+
label: spec.label,
|
|
203
|
+
sub: spec.sub,
|
|
204
|
+
tone: spec.state === undefined ? undefined : NodeStates.toneOf(spec.state),
|
|
205
|
+
icon:
|
|
206
|
+
spec.state === undefined
|
|
207
|
+
? undefined
|
|
208
|
+
: SpecCharts.stateIcon({ state: spec.state, size: 20 }),
|
|
209
|
+
});
|
|
210
|
+
})
|
|
211
|
+
.join('');
|
|
212
|
+
const names = new Map(
|
|
213
|
+
architecture.layers.flatMap((layer) =>
|
|
214
|
+
layer.boxes.map((spec) => [spec.id, spec.label] as const),
|
|
215
|
+
),
|
|
216
|
+
);
|
|
214
217
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
const right = map.branches.filter((_, index) => index % 2 === 1);
|
|
218
|
+
return {
|
|
219
|
+
svg: `<svg width="${width}" viewBox="0 0 ${width} ${height}" role="group" aria-label="${escaped(opts.chrome.architecture)}">${bands}${links}${boxes}</svg>`,
|
|
220
|
+
width,
|
|
221
|
+
fallback: `<ul class="path">${architecture.layers.map((layer) => `<li><b>${escaped(layer.label)}</b>: ${layer.boxes.map((spec) => `${spec.state === undefined ? '' : `<span class="c-${NodeStates.toneOf(spec.state)} inl">${SpecCharts.stateIcon({ state: spec.state, size: 16 })}</span>`}${escaped(spec.label)}`).join(', ')}</li>`).join('')}${architecture.links.map((link) => `<li>${escaped(names.get(link.from) ?? link.from)} <span class="verb">${escaped(link.label ?? opts.chrome.uses)}</span> ${escaped(names.get(link.to) ?? link.to)}</li>`).join('')}</ul>`,
|
|
222
|
+
};
|
|
223
|
+
}
|
|
222
224
|
|
|
223
|
-
|
|
224
|
-
|
|
225
|
+
/** The idea map: the centre between two columns of branches, each branch a cluster of ideas. */
|
|
226
|
+
static renderIdeaMap(opts: {
|
|
227
|
+
map: NonNullable<TVisualizeSpec['ideaMap']>;
|
|
228
|
+
spans: Set<number>;
|
|
229
|
+
}): string {
|
|
230
|
+
const { map, spans } = opts;
|
|
231
|
+
// Branches alternate left and right, a pair to a row; each takes three rows of the grid (title, chips, note) from it,
|
|
232
|
+
// so the title and the chips of two branches in one row sit at the same height, and the centre spans every row.
|
|
233
|
+
const rows = Math.ceil(map.branches.length / 2) * 3;
|
|
234
|
+
const cluster = (branch: (typeof map.branches)[number], index: number): string =>
|
|
235
|
+
`<li class="branch" data-s="${(index % 5) + 1}"><h3><i class="sw" data-s="${(index % 5) + 1}"></i>${escaped(branch.label)}</h3><ul class="chips">${branch.items.map((item) => `<li>${escaped(item)}</li>`).join('')}</ul>${branch.note === undefined ? '' : `<p class="mut">${escaped(branch.note)}</p>`}</li>`;
|
|
236
|
+
|
|
237
|
+
return `<div class="idea"><div class="centre win ${GridSpans.classOf({ count: rows, spans })}">${IconSet.iconSvg({ name: 'star', size: 22 })}<b>${escaped(map.center)}</b></div><ul class="bs" role="list">${map.branches.map((branch, index) => cluster(branch, index)).join('')}</ul></div>`;
|
|
238
|
+
}
|
|
239
|
+
}
|