@transitrix/diagrams 1.0.1 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (115) hide show
  1. package/dist/activities/cpm.js +11 -2
  2. package/dist/activities/gantt.js +6 -3
  3. package/dist/activities/types.d.ts +1 -0
  4. package/dist/activities/validate.js +3 -3
  5. package/dist/activity-card/__tests__/resolver.test.js +22 -1
  6. package/dist/activity-card/resolver.js +11 -5
  7. package/dist/compliance/__tests__/impact.test.js +198 -0
  8. package/dist/compliance/html.js +1 -7
  9. package/dist/compliance/impact.d.ts +24 -1
  10. package/dist/compliance/impact.js +97 -21
  11. package/dist/factor/__tests__/validate.test.js +3 -3
  12. package/dist/factor/types.d.ts +1 -1
  13. package/dist/factor/validate.js +2 -2
  14. package/dist/fgca/__tests__/chain-table.test.js +2 -2
  15. package/dist/fgca/__tests__/layout.test.js +11 -11
  16. package/dist/fgca/__tests__/preview-layout.test.js +7 -7
  17. package/dist/fgca/__tests__/resolver.test.js +2 -2
  18. package/dist/fgca/chain-table.d.ts +1 -1
  19. package/dist/fgca/chain-table.js +4 -4
  20. package/dist/fgca/index.d.ts +2 -2
  21. package/dist/fgca/index.js +1 -1
  22. package/dist/fgca/layout.d.ts +2 -2
  23. package/dist/fgca/layout.js +9 -9
  24. package/dist/fgca/nodeTypes.d.ts +1 -1
  25. package/dist/fgca/nodeTypes.js +2 -2
  26. package/dist/fgca/nodes/FGCAFactorNode.d.ts +3 -3
  27. package/dist/fgca/nodes/FGCAFactorNode.js +5 -5
  28. package/dist/fgca/parse-canonical.js +15 -10
  29. package/dist/fgca/preview-layout.d.ts +1 -1
  30. package/dist/fgca/preview-layout.js +4 -4
  31. package/dist/fgca/resolver.js +3 -1
  32. package/dist/fgca/types.d.ts +11 -11
  33. package/dist/fgca/types.js +2 -2
  34. package/dist/fgca/validate.d.ts +2 -2
  35. package/dist/fgca/validate.js +17 -14
  36. package/dist/process-blueprint/index.d.ts +1 -1
  37. package/dist/process-blueprint/layout.js +64 -37
  38. package/dist/process-blueprint/types.d.ts +14 -0
  39. package/dist/scenarios/index.d.ts +1 -1
  40. package/dist/scenarios/types.d.ts +4 -4
  41. package/dist/theme/themes.js +2 -0
  42. package/dist/theme/tokens.d.ts +7 -1
  43. package/dist/theme/tokens.js +3 -1
  44. package/dist/webview/__tests__/entry-notations.test.js +2 -0
  45. package/dist/webview/__tests__/render-process.test.d.ts +1 -0
  46. package/dist/webview/__tests__/render-process.test.js +463 -0
  47. package/dist/webview/__tests__/render-util.test.d.ts +1 -0
  48. package/dist/webview/__tests__/render-util.test.js +54 -0
  49. package/dist/webview/entry.d.ts +1 -1
  50. package/dist/webview/entry.js +9 -5
  51. package/dist/webview/render-activities.d.ts +21 -1
  52. package/dist/webview/render-activities.js +91 -56
  53. package/dist/webview/render-activity-card.d.ts +11 -1
  54. package/dist/webview/render-activity-card.js +11 -2
  55. package/dist/webview/render-blocks.d.ts +24 -1
  56. package/dist/webview/render-blocks.js +58 -24
  57. package/dist/webview/render-fgca.d.ts +27 -0
  58. package/dist/webview/render-fgca.js +29 -15
  59. package/dist/webview/render-goals.d.ts +26 -1
  60. package/dist/webview/render-goals.js +30 -20
  61. package/dist/webview/render-process-blueprint.d.ts +11 -1
  62. package/dist/webview/render-process-blueprint.js +118 -53
  63. package/dist/webview/render-process.d.ts +95 -0
  64. package/dist/webview/render-process.js +392 -0
  65. package/dist/webview/render-scenarios.js +2 -2
  66. package/dist/webview/render-util.d.ts +19 -6
  67. package/dist/webview/render-util.js +23 -15
  68. package/package.json +15 -1
  69. package/src/activities/cpm.ts +14 -2
  70. package/src/activities/gantt.ts +6 -5
  71. package/src/activities/types.ts +1 -0
  72. package/src/activities/validate.ts +3 -3
  73. package/src/activity-card/__tests__/resolver.test.ts +24 -1
  74. package/src/activity-card/resolver.ts +12 -5
  75. package/src/compliance/__tests__/impact.test.ts +219 -0
  76. package/src/compliance/html.ts +1 -8
  77. package/src/compliance/impact.ts +141 -23
  78. package/src/factor/__tests__/validate.test.ts +3 -3
  79. package/src/factor/types.ts +1 -1
  80. package/src/factor/validate.ts +2 -2
  81. package/src/fgca/__tests__/chain-table.test.ts +2 -2
  82. package/src/fgca/__tests__/layout.test.ts +13 -13
  83. package/src/fgca/__tests__/preview-layout.test.ts +7 -7
  84. package/src/fgca/__tests__/resolver.test.ts +2 -2
  85. package/src/fgca/chain-table.ts +5 -5
  86. package/src/fgca/index.ts +3 -3
  87. package/src/fgca/layout.ts +11 -11
  88. package/src/fgca/nodeTypes.ts +3 -3
  89. package/src/fgca/nodes/FGCAFactorNode.tsx +6 -6
  90. package/src/fgca/parse-canonical.ts +17 -12
  91. package/src/fgca/preview-layout.ts +5 -5
  92. package/src/fgca/resolver.ts +3 -1
  93. package/src/fgca/types.ts +13 -13
  94. package/src/fgca/validate.ts +17 -14
  95. package/src/process-blueprint/index.ts +1 -0
  96. package/src/process-blueprint/layout.ts +71 -42
  97. package/src/process-blueprint/types.ts +15 -0
  98. package/src/scenarios/index.ts +2 -2
  99. package/src/scenarios/types.ts +4 -4
  100. package/src/scenarios/validate.ts +3 -3
  101. package/src/theme/themes.ts +2 -0
  102. package/src/theme/tokens.ts +3 -1
  103. package/src/webview/__tests__/entry-notations.test.ts +2 -0
  104. package/src/webview/__tests__/render-process.test.ts +538 -0
  105. package/src/webview/__tests__/render-util.test.ts +66 -0
  106. package/src/webview/entry.ts +11 -5
  107. package/src/webview/render-activities.ts +107 -67
  108. package/src/webview/render-activity-card.ts +11 -2
  109. package/src/webview/render-blocks.ts +78 -28
  110. package/src/webview/render-fgca.ts +52 -28
  111. package/src/webview/render-goals.ts +45 -23
  112. package/src/webview/render-process-blueprint.ts +156 -82
  113. package/src/webview/render-process.ts +507 -0
  114. package/src/webview/render-scenarios.ts +3 -3
  115. package/src/webview/render-util.ts +27 -14
@@ -0,0 +1,392 @@
1
+ /**
2
+ * Host-neutral SVG emitter for the BPMN process notation.
3
+ *
4
+ * Part of the custom process renderer programme (ADR 2026-06-22).
5
+ * P1: skeleton emitter — current DSL element subset: tasks, user/service tasks,
6
+ * XOR/AND gateways, start/end events, data objects, sequence flows (with
7
+ * default-flow markers), and association edges.
8
+ *
9
+ * Single-emitter unification (review C): `renderProcessBody` is the canonical
10
+ * body shared by every host. Callers wrap it with a host-specific title block
11
+ * or a standalone SVG shell.
12
+ *
13
+ * No VS Code APIs. No Node.js built-ins. Browser-safe.
14
+ */
15
+ import { generateSvgEmbedCss } from '../theme/index.js';
16
+ import { escXml } from './render-util.js';
17
+ // ---------------------------------------------------------------------------
18
+ // Constants — match DEFAULT_LAYOUT_DIAGRAM_OPTIONS in src/layout-options.ts
19
+ // ---------------------------------------------------------------------------
20
+ /** Width of the lane-name column (px). Matches the laneLabelWidth default. */
21
+ const LANE_LABEL_BAND = 44;
22
+ /** End margin (px) along the header height axis for rotated pool/lane captions. */
23
+ const HEADER_LABEL_AXIS_PAD = 32;
24
+ /** Estimated horizontal advance (px) per character at the header label font size. */
25
+ const HEADER_LABEL_CHAR_W = 6.5;
26
+ /** Maximum characters per wrapped line inside a task box. */
27
+ const TASK_CHARS = 14;
28
+ /** Line height for wrapped task-name text (px). */
29
+ const TASK_LINE_H = 14;
30
+ /** Maximum characters per line for below-element labels (events, gateways). */
31
+ const LABEL_CHARS = 18;
32
+ /** Line height for multi-line below-element labels (px). */
33
+ const LABEL_LINE_H = 13;
34
+ // ---------------------------------------------------------------------------
35
+ // BPMN-specific CSS — no font-style:italic per CLAUDE.md design rule
36
+ // ---------------------------------------------------------------------------
37
+ export const BPMN_PROCESS_CSS = `
38
+ .bpmn-pool { fill: var(--ts-bg-surface,#f8fafc); stroke: var(--ts-node-stroke,#94a3b8); stroke-width: 1.5; }
39
+ .bpmn-pool-name { fill: var(--ts-bg-elevated,#f1f5f9); stroke: var(--ts-node-stroke,#94a3b8); stroke-width: 0.75; }
40
+ .bpmn-lane { fill: var(--ts-bg,#ffffff); stroke: var(--ts-node-stroke,#94a3b8); stroke-width: 0.75; }
41
+ .bpmn-lane-header { fill: var(--ts-bg-elevated,#f1f5f9); stroke: var(--ts-node-stroke,#94a3b8); stroke-width: 0.75; }
42
+ .bpmn-pool-label { fill: var(--ts-text-primary,#1e293b); font-size: 11px; font-weight: 700; }
43
+ .bpmn-lane-label { fill: var(--ts-text-primary,#1e293b); font-size: 11px; font-weight: 600; }
44
+ .bpmn-task { fill: var(--ts-bg,#ffffff); stroke: var(--ts-node-stroke,#94a3b8); stroke-width: 1.5; }
45
+ .bpmn-task-name { fill: var(--ts-text-primary,#1e293b); font-size: 11px; text-anchor: middle; }
46
+ .bpmn-event { fill: var(--ts-bg,#ffffff); stroke: var(--ts-node-stroke,#94a3b8); }
47
+ .bpmn-event-start { stroke-width: 1.5; }
48
+ .bpmn-event-end { stroke-width: 4; }
49
+ .bpmn-event-label { fill: var(--ts-text-secondary,#64748b); font-size: 10px; text-anchor: middle; }
50
+ .bpmn-gateway { fill: var(--ts-bg,#ffffff); stroke: var(--ts-node-stroke,#94a3b8); stroke-width: 1.5; }
51
+ .bpmn-gateway-marker { stroke: var(--ts-node-stroke,#94a3b8); stroke-width: 2.5; stroke-linecap: round; fill: none; }
52
+ .bpmn-gateway-label { fill: var(--ts-text-secondary,#64748b); font-size: 10px; text-anchor: middle; }
53
+ .bpmn-seq-flow { fill: none; stroke: var(--ts-edge-stroke,#64748b); stroke-width: 1.5; }
54
+ .bpmn-default-mark { stroke: var(--ts-edge-stroke,#64748b); stroke-width: 1.5; stroke-linecap: round; }
55
+ .bpmn-assoc { fill: none; stroke: var(--ts-edge-stroke,#64748b); stroke-width: 1; stroke-dasharray: 4 2; }
56
+ .bpmn-data-obj { fill: var(--ts-bg,#ffffff); stroke: var(--ts-node-stroke,#94a3b8); stroke-width: 1; }
57
+ .bpmn-data-obj-label { fill: var(--ts-text-secondary,#64748b); font-size: 10px; text-anchor: middle; }
58
+ .bpmn-event-intermediate { fill: none; stroke: var(--ts-node-stroke,#94a3b8); stroke-width: 1; }
59
+ .bpmn-event-icon { fill: none; stroke: var(--ts-node-stroke,#94a3b8); stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
60
+ `;
61
+ // ---------------------------------------------------------------------------
62
+ // Internal helpers
63
+ // ---------------------------------------------------------------------------
64
+ function r(n) {
65
+ return Math.round(n);
66
+ }
67
+ /** Truncate at a word boundary so rotated header labels never break mid-word. */
68
+ function wordTruncate(text, maxChars) {
69
+ if (text.length <= maxChars)
70
+ return text;
71
+ const cut = text.slice(0, maxChars - 1);
72
+ const lastSpace = cut.lastIndexOf(' ');
73
+ return (lastSpace > maxChars / 2 ? cut.slice(0, lastSpace) : cut) + '…';
74
+ }
75
+ function fitRotatedHeaderText(name, spanPx) {
76
+ const maxChars = Math.max(4, Math.floor(spanPx / HEADER_LABEL_CHAR_W));
77
+ return wordTruncate(name, maxChars);
78
+ }
79
+ function wrapTaskName(name) {
80
+ if (!name)
81
+ return [];
82
+ const words = name.split(/\s+/);
83
+ const lines = [];
84
+ let cur = '';
85
+ for (const w of words) {
86
+ const token = w.length > TASK_CHARS ? w.slice(0, TASK_CHARS - 1) + '…' : w;
87
+ if (!cur) {
88
+ cur = token;
89
+ }
90
+ else if (cur.length + 1 + token.length <= TASK_CHARS) {
91
+ cur += ' ' + token;
92
+ }
93
+ else {
94
+ lines.push(cur);
95
+ if (lines.length === 3) {
96
+ if (lines[2].length > TASK_CHARS - 1)
97
+ lines[2] = lines[2].slice(0, TASK_CHARS - 1) + '…';
98
+ return lines;
99
+ }
100
+ cur = token;
101
+ }
102
+ }
103
+ if (cur && lines.length < 3)
104
+ lines.push(cur);
105
+ if (lines.length === 0)
106
+ lines.push(name.slice(0, TASK_CHARS));
107
+ return lines;
108
+ }
109
+ function taskNameSvg(name, cx, cy) {
110
+ if (!name)
111
+ return '';
112
+ const lines = wrapTaskName(name);
113
+ const totalH = lines.length * TASK_LINE_H;
114
+ const startY = cy - totalH / 2 + TASK_LINE_H * 0.8;
115
+ const tspans = lines
116
+ .map((ln, i) => `<tspan x="${r(cx)}" y="${r(startY + i * TASK_LINE_H)}">${escXml(ln)}</tspan>`)
117
+ .join('');
118
+ return `<text class="bpmn-task-name">${tspans}</text>`;
119
+ }
120
+ function wrapBelowLabel(name) {
121
+ const words = name.split(/\s+/).filter(Boolean);
122
+ const allLines = [];
123
+ let cur = '';
124
+ for (const word of words) {
125
+ const tok = word.length > LABEL_CHARS ? word.slice(0, LABEL_CHARS - 1) + '…' : word;
126
+ const test = cur ? `${cur} ${tok}` : tok;
127
+ if (test.length <= LABEL_CHARS) {
128
+ cur = test;
129
+ }
130
+ else {
131
+ if (cur)
132
+ allLines.push(cur);
133
+ cur = tok;
134
+ }
135
+ }
136
+ if (cur)
137
+ allLines.push(cur);
138
+ if (allLines.length === 0)
139
+ return [name.slice(0, LABEL_CHARS)];
140
+ if (allLines.length <= 3)
141
+ return allLines;
142
+ const lines = allLines.slice(0, 3);
143
+ const last = lines[2];
144
+ lines[2] = last.length + 1 <= LABEL_CHARS ? last + '…' : last.slice(0, LABEL_CHARS - 1) + '…';
145
+ return lines;
146
+ }
147
+ function belowLabelSvg(name, cls, cx, belowY, minX = 0) {
148
+ if (!name)
149
+ return '';
150
+ const lines = wrapBelowLabel(name);
151
+ const halfW = Math.max(...lines.map((l) => l.length)) * 3;
152
+ const textX = minX > 0 ? Math.max(cx, minX + halfW + 2) : cx;
153
+ const startY = r(belowY + 12);
154
+ if (lines.length === 1) {
155
+ return `<text class="${cls}" x="${r(textX)}" y="${startY}">${escXml(lines[0])}</text>`;
156
+ }
157
+ const tspans = lines
158
+ .map((ln, i) => `<tspan x="${r(textX)}" dy="${i === 0 ? 0 : LABEL_LINE_H}">${escXml(ln)}</tspan>`)
159
+ .join('');
160
+ return `<text class="${cls}" x="${r(textX)}" y="${startY}">${tspans}</text>`;
161
+ }
162
+ // ---------------------------------------------------------------------------
163
+ // Element renderer
164
+ // ---------------------------------------------------------------------------
165
+ function renderElement(el, b, ox, oy, minLabelX = 0) {
166
+ const ex = b.x + ox;
167
+ const ey = b.y + oy;
168
+ const cx = ex + b.width / 2;
169
+ const cy = ey + b.height / 2;
170
+ const halfR = Math.min(b.width, b.height) / 2;
171
+ switch (el.type) {
172
+ case 'startEvent':
173
+ return [
174
+ `<circle class="bpmn-event bpmn-event-start" cx="${r(cx)}" cy="${r(cy)}" r="${r(halfR)}"/>`,
175
+ belowLabelSvg(el.name, 'bpmn-event-label', cx, ey + b.height, minLabelX),
176
+ ].join('\n');
177
+ case 'endEvent':
178
+ return [
179
+ `<circle class="bpmn-event bpmn-event-end" cx="${r(cx)}" cy="${r(cy)}" r="${r(halfR - 2)}"/>`,
180
+ belowLabelSvg(el.name, 'bpmn-event-label', cx, ey + b.height, minLabelX),
181
+ ].join('\n');
182
+ case 'task':
183
+ case 'userTask':
184
+ case 'serviceTask':
185
+ return [
186
+ `<rect class="diagram-node bpmn-task" x="${r(ex)}" y="${r(ey)}" width="${r(b.width)}" height="${r(b.height)}" rx="4" ry="4"/>`,
187
+ taskNameSvg(el.name, cx, cy),
188
+ ].join('\n');
189
+ case 'exclusiveGateway':
190
+ return [
191
+ `<path class="bpmn-gateway" d="M ${r(cx)},${r(ey)} L ${r(ex + b.width)},${r(cy)} L ${r(cx)},${r(ey + b.height)} L ${r(ex)},${r(cy)} Z"/>`,
192
+ `<path class="bpmn-gateway-marker" d="M ${r(cx - 10)},${r(cy - 10)} L ${r(cx + 10)},${r(cy + 10)} M ${r(cx + 10)},${r(cy - 10)} L ${r(cx - 10)},${r(cy + 10)}"/>`,
193
+ belowLabelSvg(el.name, 'bpmn-gateway-label', cx, ey + b.height, minLabelX),
194
+ ].join('\n');
195
+ case 'parallelGateway':
196
+ return [
197
+ `<path class="bpmn-gateway" d="M ${r(cx)},${r(ey)} L ${r(ex + b.width)},${r(cy)} L ${r(cx)},${r(ey + b.height)} L ${r(ex)},${r(cy)} Z"/>`,
198
+ `<path class="bpmn-gateway-marker" d="M ${r(cx)},${r(cy - 12)} L ${r(cx)},${r(cy + 12)} M ${r(cx - 12)},${r(cy)} L ${r(cx + 12)},${r(cy)}"/>`,
199
+ belowLabelSvg(el.name, 'bpmn-gateway-label', cx, ey + b.height, minLabelX),
200
+ ].join('\n');
201
+ case 'inclusiveGateway':
202
+ return [
203
+ `<path class="bpmn-gateway" d="M ${r(cx)},${r(ey)} L ${r(ex + b.width)},${r(cy)} L ${r(cx)},${r(ey + b.height)} L ${r(ex)},${r(cy)} Z"/>`,
204
+ `<circle class="bpmn-gateway-marker" cx="${r(cx)}" cy="${r(cy)}" r="${r(halfR * 0.4)}"/>`,
205
+ belowLabelSvg(el.name, 'bpmn-gateway-label', cx, ey + b.height, minLabelX),
206
+ ].join('\n');
207
+ case 'intermediateMessageEvent': {
208
+ const innerR = r(halfR - 4);
209
+ const eHW = r(halfR * 0.45);
210
+ const eHH = r(halfR * 0.3);
211
+ return [
212
+ `<circle class="bpmn-event bpmn-event-start" cx="${r(cx)}" cy="${r(cy)}" r="${r(halfR)}"/>`,
213
+ `<circle class="bpmn-event-intermediate" cx="${r(cx)}" cy="${r(cy)}" r="${innerR}"/>`,
214
+ `<rect class="bpmn-event-icon" x="${r(cx - eHW)}" y="${r(cy - eHH)}" width="${r(eHW * 2)}" height="${r(eHH * 2)}"/>`,
215
+ `<path class="bpmn-event-icon" d="M ${r(cx - eHW)},${r(cy - eHH)} L ${r(cx)},${r(cy)} L ${r(cx + eHW)},${r(cy - eHH)}"/>`,
216
+ belowLabelSvg(el.name, 'bpmn-event-label', cx, ey + b.height, minLabelX),
217
+ ].join('\n');
218
+ }
219
+ case 'intermediateTimerEvent': {
220
+ const innerR = r(halfR - 4);
221
+ const clockR = r(halfR * 0.5);
222
+ const handLen = r(halfR * 0.38);
223
+ return [
224
+ `<circle class="bpmn-event bpmn-event-start" cx="${r(cx)}" cy="${r(cy)}" r="${r(halfR)}"/>`,
225
+ `<circle class="bpmn-event-intermediate" cx="${r(cx)}" cy="${r(cy)}" r="${innerR}"/>`,
226
+ `<circle class="bpmn-event-icon" cx="${r(cx)}" cy="${r(cy)}" r="${clockR}"/>`,
227
+ `<line class="bpmn-event-icon" x1="${r(cx)}" y1="${r(cy)}" x2="${r(cx)}" y2="${r(cy - handLen)}"/>`,
228
+ `<line class="bpmn-event-icon" x1="${r(cx)}" y1="${r(cy)}" x2="${r(cx + r(handLen * 0.7))}" y2="${r(cy)}"/>`,
229
+ belowLabelSvg(el.name, 'bpmn-event-label', cx, ey + b.height, minLabelX),
230
+ ].join('\n');
231
+ }
232
+ case 'dataObject': {
233
+ const fold = Math.min(8, b.width / 3, b.height / 3);
234
+ return [
235
+ `<path class="bpmn-data-obj" d="M ${r(ex)},${r(ey)} L ${r(ex + b.width - fold)},${r(ey)} L ${r(ex + b.width)},${r(ey + fold)} L ${r(ex + b.width)},${r(ey + b.height)} L ${r(ex)},${r(ey + b.height)} Z"/>`,
236
+ `<path class="bpmn-data-obj" fill="none" d="M ${r(ex + b.width - fold)},${r(ey)} L ${r(ex + b.width - fold)},${r(ey + fold)} L ${r(ex + b.width)},${r(ey + fold)}"/>`,
237
+ belowLabelSvg(el.name, 'bpmn-data-obj-label', cx, ey + b.height, minLabelX),
238
+ ].join('\n');
239
+ }
240
+ default:
241
+ return [
242
+ `<rect class="diagram-node" x="${r(ex)}" y="${r(ey)}" width="${r(b.width)}" height="${r(b.height)}"/>`,
243
+ el.name
244
+ ? `<text class="text-primary" x="${r(cx)}" y="${r(cy)}" text-anchor="middle" dominant-baseline="central">${escXml(el.name)}</text>`
245
+ : '',
246
+ ].join('\n');
247
+ }
248
+ }
249
+ // ---------------------------------------------------------------------------
250
+ // Pool / lane structure
251
+ // ---------------------------------------------------------------------------
252
+ function renderPoolLanes(layout, ox, oy) {
253
+ const { process, laneBounds, poolBounds: pb } = layout;
254
+ const parts = [];
255
+ const px = r(pb.x + ox);
256
+ const py = r(pb.y + oy);
257
+ const pw = r(pb.width);
258
+ const ph = r(pb.height);
259
+ // Pool name band width: distance from pool left edge to first lane left edge
260
+ const firstLb = laneBounds.size > 0 ? [...laneBounds.values()][0] : undefined;
261
+ const poolNameW = firstLb ? r(firstLb.x - pb.x) : 48;
262
+ parts.push(`<rect class="bpmn-pool" x="${px}" y="${py}" width="${pw}" height="${ph}"/>`);
263
+ parts.push(`<rect class="bpmn-pool-name" x="${px}" y="${py}" width="${poolNameW}" height="${ph}"/>`);
264
+ const pLX = r(px + poolNameW / 2);
265
+ const poolLabelSpan = Math.max(ph - 2 * HEADER_LABEL_AXIS_PAD, 0);
266
+ const pLY = r(py + HEADER_LABEL_AXIS_PAD + poolLabelSpan / 2);
267
+ parts.push(`<text class="bpmn-pool-label" text-anchor="middle" dominant-baseline="central"` +
268
+ ` transform="rotate(-90,${pLX},${pLY})" x="${pLX}" y="${pLY}">${escXml(fitRotatedHeaderText(process.poolName, poolLabelSpan))}</text>`);
269
+ for (const lane of process.lanes) {
270
+ const lb = laneBounds.get(lane.id);
271
+ if (!lb)
272
+ continue;
273
+ const lx = r(lb.x + ox);
274
+ const ly = r(lb.y + oy);
275
+ const lw = r(lb.width);
276
+ const lh = r(lb.height);
277
+ parts.push(`<rect class="bpmn-lane" x="${lx}" y="${ly}" width="${lw}" height="${lh}"/>`);
278
+ parts.push(`<rect class="bpmn-lane-header" x="${lx}" y="${ly}" width="${LANE_LABEL_BAND}" height="${lh}"/>`);
279
+ const lLX = r(lx + LANE_LABEL_BAND / 2);
280
+ const laneLabelSpan = Math.max(lh - 2 * HEADER_LABEL_AXIS_PAD, 0);
281
+ const lLY = r(ly + HEADER_LABEL_AXIS_PAD + laneLabelSpan / 2);
282
+ parts.push(`<text class="bpmn-lane-label" text-anchor="middle" dominant-baseline="central"` +
283
+ ` transform="rotate(-90,${lLX},${lLY})" x="${lLX}" y="${lLY}">${escXml(fitRotatedHeaderText(lane.name, laneLabelSpan))}</text>`);
284
+ }
285
+ return parts.join('\n');
286
+ }
287
+ // ---------------------------------------------------------------------------
288
+ // Public API
289
+ // ---------------------------------------------------------------------------
290
+ /**
291
+ * Canonical body emitter, shared by every host (VS Code, JCEF, static export).
292
+ *
293
+ * Renders: pool + lane structure, all flow elements, sequence flows (with
294
+ * default-flow markers), and association edges. The `<defs>` block
295
+ * containing the arrowhead marker is included so the body is self-contained.
296
+ *
297
+ * @param layout - Positioned process layout (output of `layoutProcess`).
298
+ * @param ox - Horizontal canvas offset (px) applied to all coordinates.
299
+ * @param oy - Vertical canvas offset (px) applied to all coordinates.
300
+ */
301
+ export function renderProcessBody(layout, ox, oy) {
302
+ const parts = [];
303
+ // Build clip-path rects for every lane so element labels can't bleed into the
304
+ // lane-name header strip on the left.
305
+ const laneClipDefs = layout.process.lanes.map((lane) => {
306
+ const lb = layout.laneBounds.get(lane.id);
307
+ if (!lb)
308
+ return '';
309
+ const clipId = `bpmn-lc-${escXml(lane.id)}`;
310
+ const cx2 = r(lb.x + ox + LANE_LABEL_BAND);
311
+ const cy2 = r(lb.y + oy);
312
+ const cw = r(lb.width - LANE_LABEL_BAND);
313
+ const ch = r(lb.height);
314
+ return ` <clipPath id="${clipId}"><rect x="${cx2}" y="${cy2}" width="${cw}" height="${ch}"/></clipPath>`;
315
+ }).filter(Boolean).join('\n');
316
+ parts.push(`<defs>\n` +
317
+ ` <marker id="bpmn-arrow" viewBox="0 0 10 10" refX="9" refY="5"` +
318
+ ` markerWidth="8" markerHeight="8" orient="auto">\n` +
319
+ ` <path d="M 0 0 L 10 5 L 0 10 z" class="arrow-fill"/>\n` +
320
+ ` </marker>\n` +
321
+ (laneClipDefs ? laneClipDefs + '\n' : '') +
322
+ `</defs>`);
323
+ parts.push(renderPoolLanes(layout, ox, oy));
324
+ for (const lane of layout.process.lanes) {
325
+ const lb = layout.laneBounds.get(lane.id);
326
+ const clipId = lb ? `bpmn-lc-${escXml(lane.id)}` : undefined;
327
+ const laneContentX = lb ? lb.x + ox + LANE_LABEL_BAND : 0;
328
+ if (clipId)
329
+ parts.push(`<g clip-path="url(#${clipId})">`);
330
+ for (const el of lane.elements) {
331
+ const b = layout.elements.get(el.id);
332
+ if (!b)
333
+ continue;
334
+ parts.push(renderElement(el, b, ox, oy, laneContentX));
335
+ }
336
+ if (clipId)
337
+ parts.push('</g>');
338
+ }
339
+ for (const flow of layout.flows) {
340
+ if (flow.waypoints.length < 2)
341
+ continue;
342
+ const pts = flow.waypoints.map((p) => `${r(p.x + ox)},${r(p.y + oy)}`).join(' ');
343
+ parts.push(`<polyline class="bpmn-seq-flow" points="${pts}" marker-end="url(#bpmn-arrow)"/>`);
344
+ if (flow.default) {
345
+ const p0 = flow.waypoints[0];
346
+ const p1 = flow.waypoints[1];
347
+ const dx = p1.x - p0.x;
348
+ const dy = p1.y - p0.y;
349
+ const len = Math.sqrt(dx * dx + dy * dy);
350
+ if (len >= 1) {
351
+ const nx = dx / len;
352
+ const ny = dy / len;
353
+ const HALF = 5;
354
+ const OFFSET = 8;
355
+ const cx = p0.x + ox + nx * OFFSET;
356
+ const cy = p0.y + oy + ny * OFFSET;
357
+ // Perpendicular slash: marks the default outflow per BPMN 2.0 §10.3.3
358
+ parts.push(`<line class="bpmn-default-mark" x1="${r(cx - ny * HALF)}" y1="${r(cy + nx * HALF)}" x2="${r(cx + ny * HALF)}" y2="${r(cy - nx * HALF)}"/>`);
359
+ }
360
+ }
361
+ }
362
+ for (const assoc of layout.associations) {
363
+ if (assoc.waypoints.length < 2)
364
+ continue;
365
+ const pts = assoc.waypoints.map((p) => `${r(p.x + ox)},${r(p.y + oy)}`).join(' ');
366
+ parts.push(`<polyline class="bpmn-assoc" points="${pts}"/>`);
367
+ }
368
+ return parts.join('\n');
369
+ }
370
+ /**
371
+ * Self-contained SVG for the BPMN process notation.
372
+ *
373
+ * Embeds the shared Transitrix theme CSS plus BPMN-specific rules so the
374
+ * output can be dropped into a static webview panel or saved as an `.svg`
375
+ * file. VS Code's dynamic preview (which supplies CSS separately via a
376
+ * webview stylesheet) should call `renderProcessBody` directly and wrap it
377
+ * with its own HTML shell.
378
+ */
379
+ export function renderProcessLayoutSvg(layout, options = {}) {
380
+ const { title = '', topInset = title ? 32 : 0 } = options;
381
+ const pb = layout.poolBounds;
382
+ const PAD = 16;
383
+ const svgW = r(pb.x + pb.width + PAD);
384
+ const svgH = r(pb.y + pb.height + PAD + topInset);
385
+ const embedCss = generateSvgEmbedCss('transitrix') + BPMN_PROCESS_CSS;
386
+ const body = renderProcessBody(layout, 0, topInset);
387
+ return (`<svg xmlns="http://www.w3.org/2000/svg" width="${svgW}" height="${svgH}" viewBox="0 0 ${svgW} ${svgH}">\n` +
388
+ `<style>${embedCss}</style>\n` +
389
+ (title ? `${title}\n` : '') +
390
+ `${body}\n` +
391
+ `</svg>`);
392
+ }
@@ -9,7 +9,7 @@ const RELEVANCE_BADGE = {
9
9
  Medium: 'badge-medium',
10
10
  Low: 'badge-low',
11
11
  };
12
- function buildFactorsTable(factors) {
12
+ function buildDriversTable(factors) {
13
13
  if (!factors || factors.length === 0)
14
14
  return '';
15
15
  const rows = factors
@@ -49,7 +49,7 @@ export function renderScenarioHtml(scn) {
49
49
  <p class="scn-vision-text">${escHtml(scn.vision)}</p>
50
50
  </section>`);
51
51
  }
52
- blocks.push(buildFactorsTable(scn.factors_view));
52
+ blocks.push(buildDriversTable(scn.factors_view));
53
53
  blocks.push(buildRefSection('Goals', extractIds(scn.goals, 'goal_id')));
54
54
  blocks.push(buildRefSection('Capabilities', extractIds(scn.capabilities, 'capability_id')));
55
55
  blocks.push(buildRefSection('Activities', extractIds(scn.activities, 'activity_id')));
@@ -7,10 +7,23 @@
7
7
  export declare function escXml(s: string): string;
8
8
  /** Same encoding as `escXml`; aliased so HTML-table renderers read clearly. */
9
9
  export declare const escHtml: typeof escXml;
10
- /** Pull common frontmatter for the optional preview heading. */
11
- export declare function readDocHeader(doc: unknown): {
12
- title?: string;
13
- subtitle?: string;
14
- version?: string;
15
- date?: string;
10
+ /**
11
+ * Extracts standard diagram-level metadata from a raw parsed YAML document.
12
+ *
13
+ * Per CONTRACT §1.1, every notation stores its canonical metadata at the root level:
14
+ * name: "Human-readable diagram title" # required
15
+ * generated_at: "YYYY-MM-DD" # optional
16
+ *
17
+ * Backward-compat reads: `title` (legacy alias for `name`), `date` (legacy alias
18
+ * for `generated_at`), and `description`/`version` which are not in the standard
19
+ * but widely present in existing files.
20
+ *
21
+ * Host-neutral so both the VS Code preview chrome and the webview bundle share a
22
+ * single metadata reader (review E). Accepts `unknown` and guards internally.
23
+ */
24
+ export declare function extractDiagramMeta(doc: unknown): {
25
+ title: string | undefined;
26
+ subtitle: string | undefined;
27
+ date: string | undefined;
28
+ version: string | undefined;
16
29
  };
@@ -13,19 +13,27 @@ export function escXml(s) {
13
13
  }
14
14
  /** Same encoding as `escXml`; aliased so HTML-table renderers read clearly. */
15
15
  export const escHtml = escXml;
16
- /** Pull common frontmatter for the optional preview heading. */
17
- export function readDocHeader(doc) {
18
- if (!doc || typeof doc !== 'object')
19
- return {};
20
- const raw = doc;
21
- const out = {};
22
- if (typeof raw['title'] === 'string')
23
- out.title = raw['title'];
24
- if (typeof raw['description'] === 'string')
25
- out.subtitle = raw['description'];
26
- if (raw['version'] !== undefined)
27
- out.version = String(raw['version']);
28
- if (typeof raw['date'] === 'string')
29
- out.date = raw['date'];
30
- return out;
16
+ /**
17
+ * Extracts standard diagram-level metadata from a raw parsed YAML document.
18
+ *
19
+ * Per CONTRACT §1.1, every notation stores its canonical metadata at the root level:
20
+ * name: "Human-readable diagram title" # required
21
+ * generated_at: "YYYY-MM-DD" # optional
22
+ *
23
+ * Backward-compat reads: `title` (legacy alias for `name`), `date` (legacy alias
24
+ * for `generated_at`), and `description`/`version` which are not in the standard
25
+ * but widely present in existing files.
26
+ *
27
+ * Host-neutral so both the VS Code preview chrome and the webview bundle share a
28
+ * single metadata reader (review E). Accepts `unknown` and guards internally.
29
+ */
30
+ export function extractDiagramMeta(doc) {
31
+ const raw = (doc && typeof doc === 'object' ? doc : {});
32
+ const name = typeof raw['name'] === 'string' ? raw['name'] : undefined;
33
+ const title = name ?? (typeof raw['title'] === 'string' ? raw['title'] : undefined);
34
+ const subtitle = typeof raw['description'] === 'string' ? raw['description'] : undefined;
35
+ const genAt = typeof raw['generated_at'] === 'string' ? raw['generated_at'] : undefined;
36
+ const date = genAt ?? (typeof raw['date'] === 'string' ? raw['date'] : undefined);
37
+ const version = raw['version'] !== undefined ? String(raw['version']) : undefined;
38
+ return { title, subtitle, date, version };
31
39
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@transitrix/diagrams",
3
- "version": "1.0.1",
3
+ "version": "1.1.0",
4
4
  "type": "module",
5
5
  "description": "Shared rendering, validation, and pure mutations for Transitrix custom diagram formats.",
6
6
  "license": "MIT",
@@ -15,6 +15,20 @@
15
15
  },
16
16
  "main": "dist/index.js",
17
17
  "types": "dist/index.d.ts",
18
+ "exports": {
19
+ ".": {
20
+ "types": "./dist/index.d.ts",
21
+ "import": "./dist/index.js"
22
+ },
23
+ "./*.js": {
24
+ "types": "./dist/*.d.ts",
25
+ "import": "./dist/*.js"
26
+ },
27
+ "./*": {
28
+ "types": "./dist/*/index.d.ts",
29
+ "import": "./dist/*/index.js"
30
+ }
31
+ },
18
32
  "files": [
19
33
  "dist",
20
34
  "src"
@@ -5,6 +5,18 @@ export function computeCpm(activities: Activity[]): CpmResult {
5
5
 
6
6
  if (activities.length === 0) return result;
7
7
 
8
+ // When no activity carries any duration data, critical path is indeterminate —
9
+ // return all non-critical so the diagram renders in default grey.
10
+ const hasDuration = activities.some(
11
+ (a) => (a.duration !== undefined && a.duration !== null) || (a.duration_days !== undefined && a.duration_days !== null),
12
+ );
13
+ if (!hasDuration) {
14
+ for (const a of activities) {
15
+ result.set(a.id, { es: 0, ef: 0, ls: 0, lf: 0, slack: 0, isCritical: false });
16
+ }
17
+ return result;
18
+ }
19
+
8
20
  // Build successor map and in-degree for topological sort
9
21
  const successors = new Map<string, string[]>();
10
22
  const predecessors = new Map<string, string[]>();
@@ -45,7 +57,7 @@ export function computeCpm(activities: Activity[]): CpmResult {
45
57
  const ef = new Map<string, number>();
46
58
  for (const id of topoOrder) {
47
59
  const a = actById.get(id)!;
48
- const dur = a.duration ?? 0;
60
+ const dur = a.duration ?? a.duration_days ?? 0;
49
61
  const maxPredEf = Math.max(0, ...(predecessors.get(id) ?? []).map(p => ef.get(p) ?? 0));
50
62
  es.set(id, maxPredEf);
51
63
  ef.set(id, maxPredEf + dur);
@@ -59,7 +71,7 @@ export function computeCpm(activities: Activity[]): CpmResult {
59
71
  const lf = new Map<string, number>();
60
72
  for (const id of [...topoOrder].reverse()) {
61
73
  const a = actById.get(id)!;
62
- const dur = a.duration ?? 0;
74
+ const dur = a.duration ?? a.duration_days ?? 0;
63
75
  const succs = successors.get(id) ?? [];
64
76
  const minSuccLs = succs.length === 0 ? projectFinish : Math.min(...succs.map(s => ls.get(s) ?? projectFinish));
65
77
  lf.set(id, minSuccLs);
@@ -113,9 +113,10 @@ function detectMode(doc: ActivityDoc, leaves: Activity[]): 'computed' | 'pinned'
113
113
  if (allPinned) return 'pinned';
114
114
  const hasProjectStart =
115
115
  typeof doc.project?.start_date === 'string' && doc.project.start_date.length > 0;
116
- const allHaveDuration = leaves.every(
117
- (a) => typeof a.duration === 'number' && Number.isFinite(a.duration) && a.duration >= 0,
118
- );
116
+ const allHaveDuration = leaves.every((a) => {
117
+ const d = a.duration ?? a.duration_days;
118
+ return typeof d === 'number' && Number.isFinite(d) && d >= 0;
119
+ });
119
120
  if (hasProjectStart && allHaveDuration) return 'computed';
120
121
  return null;
121
122
  }
@@ -144,7 +145,7 @@ export function computeGanttLayout(doc: ActivityDoc): GanttResult {
144
145
  for (const a of leaves) {
145
146
  const startDate = a.start_date as string;
146
147
  const endDate = a.end_date as string;
147
- const isMilestone = a.duration === 0 || startDate === endDate;
148
+ const isMilestone = (a.duration ?? a.duration_days) === 0 || startDate === endDate;
148
149
  const bar: GanttBar = {
149
150
  id: a.id,
150
151
  name: a.name,
@@ -166,7 +167,7 @@ export function computeGanttLayout(doc: ActivityDoc): GanttResult {
166
167
  for (const a of leaves) {
167
168
  const c = cpm.get(a.id);
168
169
  const es = c?.es ?? 0;
169
- const dur = a.duration ?? 0;
170
+ const dur = a.duration ?? a.duration_days ?? 0;
170
171
  const startDate = nthWorkingDay(projectStart, es, calendar);
171
172
  const endDate = dur === 0
172
173
  ? startDate
@@ -15,6 +15,7 @@ export interface Activity {
15
15
  id: string;
16
16
  name: string;
17
17
  duration?: number;
18
+ duration_days?: number;
18
19
  activity_type?: string;
19
20
  goals?: string[];
20
21
  scenario?: string;
@@ -130,7 +130,7 @@ export function validateActivities(input: unknown): ActivityValidationResult {
130
130
  }
131
131
 
132
132
  // ACT-009: non-negative numeric fields
133
- const numericFields = ['duration', 'labor_cost', 'resources_cost', 'effort', 'score', 'sort'] as const;
133
+ const numericFields = ['duration', 'duration_days', 'labor_cost', 'resources_cost', 'effort', 'score', 'sort'] as const;
134
134
  for (const field of numericFields) {
135
135
  const val = act[field];
136
136
  if (val !== undefined && val !== null) {
@@ -140,8 +140,8 @@ export function validateActivities(input: unknown): ActivityValidationResult {
140
140
  }
141
141
  }
142
142
 
143
- // ACT-011: warn if no duration
144
- if (act.duration === undefined || act.duration === null) {
143
+ // ACT-011: warn if no duration (duration_days is accepted as an alias)
144
+ if ((act.duration === undefined || act.duration === null) && (act.duration_days === undefined || act.duration_days === null)) {
145
145
  warnings.push({ code: 'ACT-011', message: `Activity "${id}" has no duration — cannot participate in CPM analysis`, path });
146
146
  }
147
147
  }
@@ -41,7 +41,7 @@ const UNRELATED = {
41
41
  name: 'Other',
42
42
  parent: 'ACTIVITY-SOMETHING-ELSE-1',
43
43
  };
44
- const FACTOR = { notation: 'factor', id: 'FACTOR-EU-MDR-1', name: 'EU MDR regulation' };
44
+ const FACTOR = { notation: 'driver', id: 'FACTOR-EU-MDR-1', name: 'EU MDR regulation' };
45
45
  const GOAL = { notation: 'goal', id: 'GOAL-EU-MARKET-1', name: 'Access EU market', factors: ['FACTOR-EU-MDR-1'] };
46
46
  const CHANGE = {
47
47
  notation: 'change',
@@ -233,6 +233,29 @@ describe('resolveActivityCard', () => {
233
233
  expect(r.errors.some((e) => e.code === 'PC-001')).toBe(true);
234
234
  });
235
235
 
236
+ it('PC-001 diagnostic discloses paths searched and actionable hint (#344)', () => {
237
+ const r = resolveActivityCard(CARD, { elements: [FACTOR, GOAL, CHANGE], relations });
238
+ const pc001 = r.errors.find((e) => e.code === 'PC-001');
239
+ expect(pc001).toBeDefined();
240
+ // Must disclose both searched paths (§7 PC-001)
241
+ expect(pc001!.message).toContain('canon/elements/**');
242
+ expect(pc001!.message).toContain('canon/views/activities/**');
243
+ // Must include actionable hint with expected file pattern (§7 PC-001)
244
+ expect(pc001!.message).toContain('notation: activity');
245
+ expect(pc001!.message).toContain(`id: "${CARD.activity_card.project}"`);
246
+ });
247
+
248
+ it('resolves without PC-001 when project activity lives in a deep canon/elements subfolder (#344)', () => {
249
+ // Regression: the resolver must accept elements regardless of which subfolder
250
+ // they were loaded from (e.g. canon/elements/05_implementation/activities/).
251
+ // The resolver is filesystem-free, so we simulate the deep-path scenario by
252
+ // including the PROJECT element in the elements pool — just as loadCanon does
253
+ // after walking canon/elements/** recursively.
254
+ const r = resolveActivityCard(CARD, sources);
255
+ expect(r.valid, JSON.stringify(r.errors)).toBe(true);
256
+ expect(r.errors.some((e) => e.code === 'PC-001')).toBe(false);
257
+ });
258
+
236
259
  it('resolves activity_type and status from the Activity element', () => {
237
260
  const r = resolveActivityCard(CARD, {
238
261
  elements: [{ ...PROJECT, activity_type: 'programme', status: 'on_track' }, CHILD, FACTOR, GOAL, CHANGE],