@venizia/vulcan 0.4.9-0 → 0.4.9-2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (141) hide show
  1. package/base/extensions/vulcan-guards.ts +48 -41
  2. package/base/hooks/antigravity-guards.ts +2 -2
  3. package/base/hooks/codex-guards.ts +15 -5
  4. package/base/hooks/guard-git.ts +8 -8
  5. package/base/hooks/guard-manifest.ts +4 -5
  6. package/base/hooks/guard-outside.ts +8 -8
  7. package/base/hooks/guard-package.ts +5 -6
  8. package/base/hooks/guard-remote-hosts.ts +6 -7
  9. package/base/hooks/guard-scripting.ts +5 -6
  10. package/base/hooks/guard-writes.ts +8 -9
  11. package/base/hooks/post-tool.ts +2 -2
  12. package/base/hooks/prompt-submit.ts +2 -2
  13. package/base/hooks/session-start.ts +3 -3
  14. package/base/hooks/stop.ts +2 -2
  15. package/base/hooks/subagent-start.ts +2 -2
  16. package/base/skills/docs-update/SKILL.md +4 -2
  17. package/base/skills/visualize-work/SKILL.md +9 -0
  18. package/package.json +3 -3
  19. package/src/agents/atlas-block.ts +43 -43
  20. package/src/agents/codex-hooks.ts +45 -43
  21. package/src/agents/detect.ts +19 -16
  22. package/src/agents/exclude.ts +96 -97
  23. package/src/agents/hooks-json.ts +38 -36
  24. package/src/agents/local.ts +46 -43
  25. package/src/agents/prompt.ts +45 -42
  26. package/src/agents/render.ts +201 -195
  27. package/src/agents/resolve.ts +133 -134
  28. package/src/agents/table.ts +12 -8
  29. package/src/commands/add.command.ts +2 -2
  30. package/src/commands/agents.command.ts +11 -17
  31. package/src/commands/clean.command.ts +6 -6
  32. package/src/commands/doctor.command.ts +4 -4
  33. package/src/commands/init.command.ts +12 -8
  34. package/src/commands/preset.command.ts +2 -2
  35. package/src/commands/profile.command.ts +42 -49
  36. package/src/commands/sync.command.ts +109 -111
  37. package/src/commands/upgrade.command.ts +80 -75
  38. package/src/commands/visualize.command.ts +7 -13
  39. package/src/commands/x.command.ts +55 -50
  40. package/src/common/format.ts +23 -21
  41. package/src/common/json.ts +8 -5
  42. package/src/common/layout-folder.ts +94 -91
  43. package/src/common/paths.ts +14 -12
  44. package/src/config/loader.ts +52 -49
  45. package/src/config/packages.ts +14 -11
  46. package/src/config/schema.ts +3 -3
  47. package/src/create/add-app.ts +519 -509
  48. package/src/create/add-lib.ts +237 -240
  49. package/src/create/bunfig.ts +26 -23
  50. package/src/create/checks.ts +36 -34
  51. package/src/create/diff.ts +21 -23
  52. package/src/create/dockerignore.ts +26 -24
  53. package/src/create/files.ts +7 -5
  54. package/src/create/init-monorepo.ts +75 -80
  55. package/src/create/lib-preset.ts +59 -63
  56. package/src/create/manifest-json.ts +10 -4
  57. package/src/create/names.ts +217 -210
  58. package/src/create/next.ts +26 -23
  59. package/src/create/plan.ts +15 -12
  60. package/src/create/preset-diff.ts +301 -303
  61. package/src/create/preset-menu.ts +38 -32
  62. package/src/create/preset.ts +202 -197
  63. package/src/create/process.ts +79 -72
  64. package/src/create/scratch.ts +48 -49
  65. package/src/create/workspace.ts +404 -396
  66. package/src/doctor/checks.ts +1027 -1014
  67. package/src/doctor/makefile.ts +17 -13
  68. package/src/doctor/runner.ts +88 -118
  69. package/src/doctor/skills.ts +97 -95
  70. package/src/doctor/tags.ts +42 -37
  71. package/src/hooks/codex-patch.ts +25 -22
  72. package/src/hooks/command-view.ts +44 -39
  73. package/src/hooks/decision.ts +37 -37
  74. package/src/hooks/guard-git.ts +51 -49
  75. package/src/hooks/guard-manifest.ts +58 -55
  76. package/src/hooks/guard-outside.ts +93 -91
  77. package/src/hooks/guard-package.ts +82 -79
  78. package/src/hooks/guard-scripting.ts +19 -14
  79. package/src/hooks/guard-writes.ts +154 -149
  80. package/src/hooks/owner-reply.ts +127 -127
  81. package/src/hooks/post-tool.ts +94 -93
  82. package/src/hooks/project-guards.ts +65 -62
  83. package/src/hooks/project-tmp.ts +27 -24
  84. package/src/hooks/remote-hosts.ts +153 -130
  85. package/src/hooks/session-digest.ts +98 -101
  86. package/src/hooks/shell.ts +509 -499
  87. package/src/hooks/subagent-card.ts +11 -7
  88. package/src/hooks/trusted-scripts.ts +106 -104
  89. package/src/init/scaffold.ts +135 -132
  90. package/src/local/clean.ts +38 -36
  91. package/src/local/format.ts +21 -17
  92. package/src/local/scan.ts +144 -138
  93. package/src/manifest/render.ts +110 -104
  94. package/src/owner/card.ts +51 -46
  95. package/src/owner/profile.ts +99 -93
  96. package/src/owner/reply-switch.ts +9 -6
  97. package/src/owner/shape.ts +71 -69
  98. package/src/owner/survey.ts +173 -171
  99. package/src/owner/view.ts +62 -59
  100. package/src/owner/violations.ts +119 -123
  101. package/src/rules/base.ts +15 -11
  102. package/src/rules/parser.ts +39 -32
  103. package/src/rules/slots.ts +8 -6
  104. package/src/signals/claims.ts +30 -28
  105. package/src/signals/classify.ts +38 -33
  106. package/src/signals/loop.ts +39 -37
  107. package/src/signals/state.ts +79 -81
  108. package/src/skills/frontmatter.ts +28 -28
  109. package/src/sync/agent-files.ts +217 -199
  110. package/src/sync/agent-removal.ts +56 -59
  111. package/src/sync/atlas-block.ts +45 -43
  112. package/src/sync/base-rules.ts +32 -30
  113. package/src/sync/claude-launch.ts +36 -34
  114. package/src/sync/exclude.ts +77 -69
  115. package/src/sync/local-choice.ts +50 -47
  116. package/src/sync/planner.ts +59 -61
  117. package/src/sync/prune.ts +52 -48
  118. package/src/sync/settings.ts +166 -167
  119. package/src/ui/capability.ts +12 -7
  120. package/src/ui/keyboard.ts +38 -38
  121. package/src/ui/prompt.ts +79 -77
  122. package/src/visualize/assets.ts +33 -24
  123. package/src/visualize/charts.ts +179 -176
  124. package/src/visualize/compare-css.ts +3 -2
  125. package/src/visualize/compare-render.ts +9 -7
  126. package/src/visualize/diagrams.ts +189 -174
  127. package/src/visualize/grid-span.ts +34 -0
  128. package/src/visualize/icons.ts +7 -5
  129. package/src/visualize/kinds-render.ts +50 -45
  130. package/src/visualize/kinds-validate.ts +12 -10
  131. package/src/visualize/labels.ts +21 -17
  132. package/src/visualize/layout.ts +112 -97
  133. package/src/visualize/page.ts +92 -104
  134. package/src/visualize/render.ts +143 -140
  135. package/src/visualize/sections.ts +395 -384
  136. package/src/visualize/sources.ts +2 -2
  137. package/src/visualize/theme.ts +12 -10
  138. package/src/visualize/validate.ts +13 -9
  139. package/src/wiki/anchors.ts +38 -36
  140. package/src/wiki/command.ts +4 -4
  141. package/src/wiki/source-links.ts +46 -44
@@ -1,8 +1,9 @@
1
1
  import { NodeStates } from './constants.ts';
2
2
  import type { TChrome } from './constants.ts';
3
- import { stateIcon } from './charts.ts';
4
- import { iconSvg } from './icons.ts';
5
- import { escapeText } from './layout.ts';
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
- /** An explainer step's diagram: a row of boxes joined by labelled arrows, or stacked layers. */
40
- export const renderDiagram = (opts: { diagram: TDiagram }): IDrawing => {
41
- const { diagram } = opts;
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
- if (diagram.type === 'row') {
44
- const longest = Math.max(
45
- ...diagram.nodes.flatMap((node) => [node.label.length * 8.2, (node.sub?.length ?? 0) * 7.6]),
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 bw = Math.max(124, Math.ceil(longest) + 24);
48
- const gap = 78;
49
- const width = diagram.nodes.length * bw + (diagram.nodes.length - 1) * gap + 16;
50
- const parts = diagram.nodes
51
- .map((node, index) => {
52
- const x = 8 + index * (bw + gap);
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} 80" role="group" aria-label="diagram">${parts}</svg>`,
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: `<ol class="path">${diagram.nodes
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
- const most = Math.max(...diagram.layers.map((layer) => layer.items.length));
76
- const label = Math.max(
77
- 112,
78
- Math.ceil(Math.max(...diagram.layers.map((layer) => layer.label.length)) * 8.8) + 30,
79
- );
80
- const iw = Math.max(
81
- 112,
82
- Math.ceil(
83
- Math.max(...diagram.layers.flatMap((layer) => layer.items.map((item) => item.length))) * 8,
84
- ) + 24,
85
- );
86
- const width = label + most * (iw + 10) + 14;
87
- const parts = diagram.layers
88
- .map((layer, row) => {
89
- const y = 8 + row * 62;
90
-
91
- 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>`;
92
- })
93
- .join('');
94
-
95
- return {
96
- svg: `<svg width="${width}" viewBox="0 0 ${width} ${diagram.layers.length * 62 + 12}" role="group" aria-label="layers">${parts}</svg>`,
97
- width,
98
- fallback: `<ul class="path">${diagram.layers.map((layer) => `<li><b>${escaped(layer.label)}</b>: ${layer.items.map(escaped).join(', ')}</li>`).join('')}</ul>`,
99
- };
100
- };
101
-
102
- /** The layered view: bands from top to bottom, boxes in each, and an elbow line for every link. */
103
- export const renderArchitecture = (opts: {
104
- architecture: TArchitecture;
105
- chrome: TChrome;
106
- }): IDrawing => {
107
- const { architecture } = opts;
108
- const most = Math.max(...architecture.layers.map((layer) => layer.boxes.length));
109
- const label = 120;
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
- if (a.row === b.row) {
156
- const sign = a.x < b.x ? 1 : -1;
157
- const x1 = sign === 1 ? a.x + bw : a.x;
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
- 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>`;
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
- const down = a.row < b.row;
165
- const gapIndex = Math.min(a.row, b.row);
166
- const lane = lanes.get(gapIndex) ?? 0;
167
-
168
- lanes.set(gapIndex, lane + 1);
169
-
170
- const top = 4 + gapIndex * rowHeight + 34 + bh;
171
- const bottom = 4 + (gapIndex + 1) * rowHeight + 34;
172
- const ym = top + 14 + ((bottom - top - 28) * (lane + 1)) / ((across.get(gapIndex) ?? 1) + 1);
173
- const shift = lane % 3 === 1 ? 10 : lane % 3 === 2 ? -10 : 0;
174
- const x1 = a.x + bw / 2 + shift;
175
- const x2 = b.x + bw / 2 + shift;
176
- const y1 = down ? a.y + bh : a.y;
177
- const y2 = down ? b.y : b.y + bh;
178
- const tip = down ? -7 : 7;
179
-
180
- 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>`;
181
- })
182
- .join('');
183
- const boxes = architecture.layers
184
- .flatMap((layer) => layer.boxes)
185
- .map((spec) => {
186
- const p = positions.get(spec.id);
187
-
188
- return p === undefined
189
- ? ''
190
- : box({
191
- x: p.x,
192
- y: p.y,
193
- width: bw,
194
- height: bh,
195
- label: spec.label,
196
- sub: spec.sub,
197
- tone: spec.state === undefined ? undefined : NodeStates.toneOf(spec.state),
198
- icon: spec.state === undefined ? undefined : stateIcon({ state: spec.state, size: 20 }),
199
- });
200
- })
201
- .join('');
202
- const names = new Map(
203
- architecture.layers.flatMap((layer) =>
204
- layer.boxes.map((spec) => [spec.id, spec.label] as const),
205
- ),
206
- );
207
-
208
- return {
209
- svg: `<svg width="${width}" viewBox="0 0 ${width} ${height}" role="group" aria-label="${escaped(opts.chrome.architecture)}">${bands}${links}${boxes}</svg>`,
210
- width,
211
- 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">${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>`,
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
- /** The idea map: the centre between two columns of branches, each branch a cluster of ideas. */
216
- export const renderIdeaMap = (opts: { map: NonNullable<TVisualizeSpec['ideaMap']> }): string => {
217
- const { map } = opts;
218
- const cluster = (branch: (typeof map.branches)[number], index: number): string =>
219
- `<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>`;
220
- const left = map.branches.filter((_, index) => index % 2 === 0);
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
- return `<div class="idea"><ul class="side l">${left.map((branch, i) => cluster(branch, i * 2)).join('')}</ul><div class="centre win">${iconSvg({ name: 'star', size: 22 })}<b>${escaped(map.center)}</b></div><ul class="side r">${right.map((branch, i) => cluster(branch, i * 2 + 1)).join('')}</ul></div>`;
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
+ }
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Cards in a row share their rows: each card spans as many rows of its grid as it has parts, and takes those rows over
3
+ * from the grid (`grid-template-rows: subgrid`), so the score, the title, each criterion and each pro of one card sit
4
+ * at the same height as the same part of its neighbours, whatever wraps. The number of rows is only known when the page
5
+ * is made, and an inline `style` is blocked by the page's policy, so a class names the span (`sp4`) and the page carries
6
+ * the rules for exactly the spans it uses.
7
+ */
8
+ export class GridSpans {
9
+ /** The most rows a card can span: a tag, a total, a title, a line, 8 criteria, 6 pros and 6 cons, and room to spare. */
10
+ static readonly MAX = 40;
11
+
12
+ /** The class that makes an element span `count` rows; remembers the span so the page carries its rule. */
13
+ static classOf(opts: { count: number; spans: Set<number> }): string {
14
+ const count = Math.max(1, Math.min(GridSpans.MAX, Math.round(opts.count)));
15
+
16
+ opts.spans.add(count);
17
+
18
+ return `sp${count}`;
19
+ }
20
+
21
+ /** The rules of the spans a page uses; with no subgrid in the browser, or in one column (a phone), a card is a plain block. */
22
+ static css(opts: { spans: Set<number> }): string {
23
+ if (opts.spans.size === 0) {
24
+ return '';
25
+ }
26
+
27
+ const rules = [...opts.spans]
28
+ .sort((a, b) => a - b)
29
+ .map((count) => `.sp${count}{grid-row-end:span ${count}}`)
30
+ .join('');
31
+
32
+ return `@media (min-width:621px){@supports (grid-template-rows:subgrid){${rules}}}`;
33
+ }
34
+ }
@@ -23,9 +23,11 @@ const PATHS: Record<string, string> = {
23
23
  moon: '<path d="M20.2 14.6A8.4 8.4 0 0 1 9.4 3.8 8.4 8.4 0 1 0 20.2 14.6Z"/>',
24
24
  };
25
25
 
26
- /** An icon; `className` is added after `ic` for a page rule that targets one icon (the theme switch's sun and moon). */
27
- export const iconSvg = (opts: { name: string; size?: number; className?: string }): string => {
28
- const size = opts.size ?? 20;
26
+ export class IconSet {
27
+ /** An icon; `className` is added after `ic` for a page rule that targets one icon (the theme switch's sun and moon). */
28
+ static iconSvg(opts: { name: string; size?: number; className?: string }): string {
29
+ const size = opts.size ?? 20;
29
30
 
30
- return `<svg class="ic${opts.className === undefined ? '' : ` ${opts.className}`}" viewBox="0 0 24 24" width="${size}" height="${size}" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">${PATHS[opts.name] ?? ''}</svg>`;
31
- };
31
+ return `<svg class="ic${opts.className === undefined ? '' : ` ${opts.className}`}" viewBox="0 0 24 24" width="${size}" height="${size}" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">${PATHS[opts.name] ?? ''}</svg>`;
32
+ }
33
+ }
@@ -1,10 +1,10 @@
1
- import { stateIcon } from './charts.ts';
1
+ import { SpecCharts } from './charts.ts';
2
2
  import type { TChrome } from './constants.ts';
3
- import { escapeText } from './layout.ts';
3
+ import { FigureLayout } from './layout.ts';
4
4
  import { LifecycleKinds, MessageKinds } from './kinds-schema.ts';
5
5
  import type { ITreeNode, TLifecycle, TSequence, TTree } from './kinds-schema.ts';
6
6
  import type { INewKindsSpec } from './kinds-validate.ts';
7
- import { chip, section, stateWord } from './sections.ts';
7
+ import { SpecSections } from './sections.ts';
8
8
 
9
9
  /** What a section of the new kinds needs: its slice of the spec, the page's words, and the figure widths to register. */
10
10
  export interface INewKindsContext {
@@ -35,7 +35,7 @@ const KIND_WORDS = {
35
35
  countItems: 'items',
36
36
  } as const;
37
37
 
38
- const escaped = (value: string): string => escapeText({ value });
38
+ const escaped = (value: string): string => FigureLayout.escapeText({ value });
39
39
 
40
40
  const wordOf = (opts: { chrome: TChrome; key: keyof typeof KIND_WORDS }): string => {
41
41
  const given: Record<string, unknown> = opts.chrome;
@@ -568,7 +568,9 @@ const renderTree = (opts: { tree: TTree; chrome: TChrome }): IKindDrawing => {
568
568
 
569
569
  const sized = rows.map((row) => {
570
570
  const word =
571
- row.node.state === undefined ? undefined : stateWord({ chrome, state: row.node.state });
571
+ row.node.state === undefined
572
+ ? undefined
573
+ : SpecSections.stateWord({ chrome, state: row.node.state });
572
574
  const hasSub = row.node.sublabel !== undefined;
573
575
  const icon = row.node.state === undefined ? 0 : 26;
574
576
  const wordWidth = word === undefined ? 0 : Math.ceil(word.length * 7.4) + 20;
@@ -613,11 +615,12 @@ const renderTree = (opts: { tree: TTree; chrome: TChrome }): IKindDrawing => {
613
615
  const textX = row.x + 14 + row.icon;
614
616
  const state = row.node.state;
615
617
 
616
- return `<g class="knode${state === undefined ? '' : ` kn-${state.replaceAll(' ', '-')}`}"><rect class="kbox" x="${row.x}" y="${row.y}" width="${row.boxWidth}" height="${row.boxHeight}" rx="4"/>${state === undefined ? '' : `<g class="kic" transform="translate(${row.x + 12} ${centre - 8})">${stateIcon({ state, size: 16 }).replace('<svg', '<svg x="0" y="0"')}</g>`}<text class="kt" x="${textX}" y="${row.hasSub ? row.y + 21 : centre + 5}">${escaped(row.node.label)}</text>${row.word === undefined ? '' : `<text class="kw" x="${row.x + row.boxWidth - 12}" y="${row.hasSub ? row.y + 21 : centre + 4}" text-anchor="end">${escaped(row.word)}</text>`}${row.node.sublabel === undefined ? '' : `<text class="ks" x="${textX}" y="${row.y + 39}">${escaped(row.node.sublabel)}</text>`}</g>`;
618
+ return `<g class="knode${state === undefined ? '' : ` kn-${state.replaceAll(' ', '-')}`}"><rect class="kbox" x="${row.x}" y="${row.y}" width="${row.boxWidth}" height="${row.boxHeight}" rx="4"/>${state === undefined ? '' : `<g class="kic" transform="translate(${row.x + 12} ${centre - 8})">${SpecCharts.stateIcon({ state, size: 16 }).replace('<svg', '<svg x="0" y="0"')}</g>`}<text class="kt" x="${textX}" y="${row.hasSub ? row.y + 21 : centre + 5}">${escaped(row.node.label)}</text>${row.word === undefined ? '' : `<text class="kw" x="${row.x + row.boxWidth - 12}" y="${row.hasSub ? row.y + 21 : centre + 4}" text-anchor="end">${escaped(row.word)}</text>`}${row.node.sublabel === undefined ? '' : `<text class="ks" x="${textX}" y="${row.y + 39}">${escaped(row.node.sublabel)}</text>`}</g>`;
617
619
  })
618
620
  .join('');
619
621
  const outline = (node: ITreeNode): string => {
620
- const state = node.state === undefined ? '' : ` ${chip({ chrome, state: node.state })}`;
622
+ const state =
623
+ node.state === undefined ? '' : ` ${SpecSections.chip({ chrome, state: node.state })}`;
621
624
  const inner =
622
625
  node.children === undefined || node.children.length === 0
623
626
  ? ''
@@ -650,44 +653,46 @@ const frame = (opts: { ctx: INewKindsContext; drawing: IKindDrawing }): string =
650
653
  return `<figure class="kfig"><div class="fig f${width}">${opts.drawing.svg}</div>${opts.drawing.list}<figcaption>${escaped(opts.drawing.caption)}</figcaption></figure>`;
651
654
  };
652
655
 
653
- export const sequenceSection = (opts: { ctx: INewKindsContext }): string => {
654
- const { sequence } = opts.ctx.spec;
655
-
656
- return sequence === undefined
657
- ? ''
658
- : section({
659
- id: 'sequence',
660
- title: opts.ctx.chrome.sequence,
661
- body: frame({
662
- ctx: opts.ctx,
663
- drawing: renderSequence({ sequence, chrome: opts.ctx.chrome }),
664
- }),
665
- });
666
- };
656
+ export class KindsRender {
657
+ static sequenceSection(opts: { ctx: INewKindsContext }): string {
658
+ const { sequence } = opts.ctx.spec;
659
+
660
+ return sequence === undefined
661
+ ? ''
662
+ : SpecSections.section({
663
+ id: 'sequence',
664
+ title: opts.ctx.chrome.sequence,
665
+ body: frame({
666
+ ctx: opts.ctx,
667
+ drawing: renderSequence({ sequence, chrome: opts.ctx.chrome }),
668
+ }),
669
+ });
670
+ }
667
671
 
668
- export const lifecycleSection = (opts: { ctx: INewKindsContext }): string => {
669
- const { lifecycle } = opts.ctx.spec;
670
-
671
- return lifecycle === undefined
672
- ? ''
673
- : section({
674
- id: 'lifecycle',
675
- title: opts.ctx.chrome.lifecycle,
676
- body: frame({
677
- ctx: opts.ctx,
678
- drawing: renderLifecycle({ lifecycle, chrome: opts.ctx.chrome }),
679
- }),
680
- });
681
- };
672
+ static lifecycleSection(opts: { ctx: INewKindsContext }): string {
673
+ const { lifecycle } = opts.ctx.spec;
674
+
675
+ return lifecycle === undefined
676
+ ? ''
677
+ : SpecSections.section({
678
+ id: 'lifecycle',
679
+ title: opts.ctx.chrome.lifecycle,
680
+ body: frame({
681
+ ctx: opts.ctx,
682
+ drawing: renderLifecycle({ lifecycle, chrome: opts.ctx.chrome }),
683
+ }),
684
+ });
685
+ }
682
686
 
683
- export const treeSection = (opts: { ctx: INewKindsContext }): string => {
684
- const { tree } = opts.ctx.spec;
687
+ static treeSection(opts: { ctx: INewKindsContext }): string {
688
+ const { tree } = opts.ctx.spec;
685
689
 
686
- return tree === undefined
687
- ? ''
688
- : section({
689
- id: 'tree',
690
- title: opts.ctx.chrome.tree,
691
- body: frame({ ctx: opts.ctx, drawing: renderTree({ tree, chrome: opts.ctx.chrome }) }),
692
- });
693
- };
690
+ return tree === undefined
691
+ ? ''
692
+ : SpecSections.section({
693
+ id: 'tree',
694
+ title: opts.ctx.chrome.tree,
695
+ body: frame({ ctx: opts.ctx, drawing: renderTree({ tree, chrome: opts.ctx.chrome }) }),
696
+ });
697
+ }
698
+ }
@@ -172,13 +172,15 @@ const checkTree = (opts: { tree: TTree }): string[] => {
172
172
  return problems;
173
173
  };
174
174
 
175
- /** What a schema cannot say about the sequence, the lifecycle and the tree: ids, ends of arrows, reach, limits. */
176
- export const checkNewKinds = (opts: { spec: INewKindsSpec }): string[] => {
177
- const { sequence, lifecycle, tree } = opts.spec;
178
-
179
- return [
180
- ...(sequence === undefined ? [] : checkSequence({ sequence })),
181
- ...(lifecycle === undefined ? [] : checkLifecycle({ lifecycle })),
182
- ...(tree === undefined ? [] : checkTree({ tree })),
183
- ];
184
- };
175
+ export class KindsValidate {
176
+ /** What a schema cannot say about the sequence, the lifecycle and the tree: ids, ends of arrows, reach, limits. */
177
+ static checkNew(opts: { spec: INewKindsSpec }): string[] {
178
+ const { sequence, lifecycle, tree } = opts.spec;
179
+
180
+ return [
181
+ ...(sequence === undefined ? [] : checkSequence({ sequence })),
182
+ ...(lifecycle === undefined ? [] : checkLifecycle({ lifecycle })),
183
+ ...(tree === undefined ? [] : checkTree({ tree })),
184
+ ];
185
+ }
186
+ }