astro-archify 0.3.4

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 (30) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +169 -0
  3. package/astro-archify-integration.d.ts +100 -0
  4. package/astro-archify-integration.js +0 -0
  5. package/package.json +64 -0
  6. package/vendor/archify/LICENSE +22 -0
  7. package/vendor/archify/NOTICE.md +48 -0
  8. package/vendor/archify/assets/template.html +14787 -0
  9. package/vendor/archify/renderers/architecture/grid.mjs +62 -0
  10. package/vendor/archify/renderers/architecture/render-architecture.mjs +1089 -0
  11. package/vendor/archify/renderers/dataflow/render-dataflow.mjs +482 -0
  12. package/vendor/archify/renderers/lifecycle/render-lifecycle.mjs +570 -0
  13. package/vendor/archify/renderers/sequence/render-sequence.mjs +468 -0
  14. package/vendor/archify/renderers/shared/brand-marks.mjs +563 -0
  15. package/vendor/archify/renderers/shared/cli.mjs +220 -0
  16. package/vendor/archify/renderers/shared/desktop-readability.mjs +26 -0
  17. package/vendor/archify/renderers/shared/diagnostics.mjs +116 -0
  18. package/vendor/archify/renderers/shared/engineering-profiles.mjs +157 -0
  19. package/vendor/archify/renderers/shared/generated-brand-marks.mjs +2003 -0
  20. package/vendor/archify/renderers/shared/generated-validators.mjs +13 -0
  21. package/vendor/archify/renderers/shared/geometry.mjs +1334 -0
  22. package/vendor/archify/renderers/shared/i18n.mjs +594 -0
  23. package/vendor/archify/renderers/shared/layout-report.mjs +40 -0
  24. package/vendor/archify/renderers/shared/legend.mjs +217 -0
  25. package/vendor/archify/renderers/shared/output-path.mjs +321 -0
  26. package/vendor/archify/renderers/shared/repository-evidence.mjs +235 -0
  27. package/vendor/archify/renderers/shared/text-fit.mjs +49 -0
  28. package/vendor/archify/renderers/shared/utils.mjs +232 -0
  29. package/vendor/archify/renderers/shared/validator.mjs +86 -0
  30. package/vendor/archify/renderers/workflow/render-workflow.mjs +749 -0
@@ -0,0 +1,482 @@
1
+ import path from 'node:path';
2
+ import { fileURLToPath } from 'node:url';
3
+ import { esc, renderDefinitions, renderSemanticSigil, textUnits } from '../shared/utils.mjs';
4
+ import { animateAttr, focusEdgeAttrs, focusNodeAttrs, focusNodeTitle, loadDiagramWithBrandMarks, writeDiagram, svgAccessibleText, svgRootAttrs } from '../shared/cli.mjs';
5
+ import { throwDiagnosticProblems } from '../shared/diagnostics.mjs';
6
+ import { resolveLegend, renderLegend as renderResolvedLegend } from '../shared/legend.mjs';
7
+ import { availableNodeTextWidth, fittedNodeFontSize, minimumNodeTextWidth } from '../shared/text-fit.mjs';
8
+ import { brandLabelFitWidth, brandMetadataFor, brandTopRailProblem, renderBrandMark } from '../shared/brand-marks.mjs';
9
+ import { translateMessage as i18nText } from '../shared/i18n.mjs';
10
+ import {
11
+ asArray,
12
+ isFinitePoint,
13
+ rectsOverlap,
14
+ cleanEndpointSideProblems,
15
+ cleanFlowProblems,
16
+ cleanCrossingProblems,
17
+ cleanAmbiguousCorridorProblems,
18
+ cleanBorderRunProblems,
19
+ cleanRouteRhythmProblems,
20
+ cleanLabelRouteClearanceProblems,
21
+ suggestLabelObstacleFix,
22
+ suggestLabelPairFix,
23
+ anchor,
24
+ automaticPortSpread,
25
+ defaultFromSide,
26
+ defaultToSide,
27
+ chosenSide,
28
+ polylinePath,
29
+ routePointsValue,
30
+ labelPoint,
31
+ componentFill,
32
+ componentText,
33
+ arrowClassMap,
34
+ variantAccent
35
+ } from '../shared/geometry.mjs';
36
+
37
+ const nodeTextFit = {
38
+ sublabelPreferred: 7,
39
+ sublabelMinimum: 6,
40
+ tagPreferred: 7,
41
+ tagMinimum: 6,
42
+ };
43
+
44
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
45
+ const { diagram: dataflow, template, outPath } = await loadDiagramWithBrandMarks({
46
+ rendererDir: __dirname,
47
+ diagramType: 'dataflow',
48
+ defaultExample: 'product-analytics.dataflow.json'
49
+ });
50
+
51
+ const viewBox = dataflow.meta?.viewBox || [940, 720];
52
+ const layout = {
53
+ stageY: 46,
54
+ stageH: 36,
55
+ stageBottomPad: 74,
56
+ leftX: 100,
57
+ colGap: 215,
58
+ stageW: 168,
59
+ nodeW: 112,
60
+ nodeH: 58,
61
+ rowYs: [128, 242, 356, 470, 584],
62
+ labelH: 16
63
+ };
64
+
65
+ function flowLabelSize(flow) {
66
+ const longestLine = Math.max(textUnits(flow.label), textUnits(flow.classification || ''));
67
+ return {
68
+ width: Math.round(Math.max(34, longestLine * 4.9 + 12) * 10) / 10,
69
+ height: flow.classification ? 27 : layout.labelH,
70
+ };
71
+ }
72
+
73
+ function stageX(index) {
74
+ return layout.leftX + index * layout.colGap;
75
+ }
76
+
77
+ function stageFrame(stage, index) {
78
+ return {
79
+ id: index,
80
+ label: stage.label,
81
+ kind: 'stage',
82
+ x: stageX(index) - layout.stageW / 2,
83
+ y: layout.stageY,
84
+ width: layout.stageW,
85
+ height: viewBox[1] - layout.stageY - layout.stageBottomPad,
86
+ radius: 10,
87
+ };
88
+ }
89
+
90
+ const compositionFrames = asArray(dataflow.stages).map(stageFrame);
91
+
92
+ function measureNode(node) {
93
+ const width = node.width || layout.nodeW;
94
+ const height = node.height || layout.nodeH;
95
+ const cx = stageX(node.stage);
96
+ const y = layout.rowYs[node.row] + (node.yOffset || 0);
97
+ return {
98
+ ...node,
99
+ width,
100
+ height,
101
+ cx,
102
+ cy: y + height / 2,
103
+ x: cx - width / 2,
104
+ y
105
+ };
106
+ }
107
+
108
+ const nodes = new Map(asArray(dataflow.nodes).map((node) => [node.id, measureNode(node)]));
109
+ const nodeSteps = new Map();
110
+ for (const [index, flow] of asArray(dataflow.flows).entries()) {
111
+ if (!nodeSteps.has(flow.from)) nodeSteps.set(flow.from, index);
112
+ if (!nodeSteps.has(flow.to)) nodeSteps.set(flow.to, index + 1);
113
+ }
114
+ for (const [index, node] of asArray(dataflow.nodes).entries()) {
115
+ if (!nodeSteps.has(node.id)) nodeSteps.set(node.id, index);
116
+ }
117
+
118
+ function validateDataflow() {
119
+ const problems = [];
120
+ if (dataflow.schema_version !== 1) problems.push('Data-flow files must set "schema_version": 1.');
121
+ if (dataflow.diagram_type !== 'dataflow') problems.push('Data-flow files must set "diagram_type": "dataflow".');
122
+ if (!dataflow.meta?.title) problems.push('Data-flow files must include meta.title.');
123
+ if (!Array.isArray(dataflow.stages) || dataflow.stages.length < 2) {
124
+ problems.push('Data-flow diagrams need at least two stages.');
125
+ }
126
+ if (!Array.isArray(dataflow.nodes) || dataflow.nodes.length < 2) {
127
+ problems.push('Data-flow diagrams need at least two nodes.');
128
+ }
129
+ if (!Array.isArray(dataflow.flows)) problems.push('Data-flow diagrams must include a flows array.');
130
+ if (dataflow.cards !== undefined && !Array.isArray(dataflow.cards)) problems.push('Data-flow "cards" must be an array.');
131
+ if (nodes.size !== asArray(dataflow.nodes).length) problems.push('Node ids must be unique.');
132
+
133
+ const stageCount = asArray(dataflow.stages).length;
134
+ for (const node of nodes.values()) {
135
+ if (typeof node.stage !== 'number' || node.stage < 0 || node.stage >= stageCount) {
136
+ problems.push(`Node "${node.id}" uses invalid stage ${node.stage} — valid stages are 0..${stageCount - 1}.`);
137
+ }
138
+ if (typeof node.row !== 'number' || node.row < 0 || node.row >= layout.rowYs.length) {
139
+ problems.push(`Node "${node.id}" uses invalid row ${node.row} — valid rows are 0..${layout.rowYs.length - 1}.`);
140
+ }
141
+ if (!isFinitePoint(node.x, node.y, node.cx, node.cy)) {
142
+ problems.push(`Node "${node.id}" produced non-finite coordinates — check stage, row, width, height, and yOffset are numbers.`);
143
+ continue;
144
+ }
145
+ if (node.x < 24 || node.x + node.width > viewBox[0] - 24) {
146
+ problems.push(`Node "${node.id}" exceeds the horizontal bounds of the viewBox — reduce node.width or increase meta.viewBox[0].`);
147
+ }
148
+ if (node.y < layout.stageY + layout.stageH + 22 || node.y + node.height > viewBox[1] - layout.stageBottomPad) {
149
+ problems.push(`Node "${node.id}" exceeds the readable diagram area — keep y between ${layout.stageY + layout.stageH + 22} and ${viewBox[1] - layout.stageBottomPad} (adjust row/yOffset or increase meta.viewBox[1]).`);
150
+ }
151
+ const estLabelW = textUnits(node.label) * 6.2;
152
+ if (estLabelW > node.width + 6) {
153
+ problems.push(`Label "${node.label}" (~${Math.round(estLabelW)}px) is wider than node "${node.id}" (${node.width}px) — shorten the label or increase node.width.`);
154
+ }
155
+ const brandRailProblem = brandTopRailProblem(node, node.width, 8);
156
+ if (brandRailProblem) problems.push(brandRailProblem);
157
+ // sublabel and tag render as single unwrapped <text> elements; shrink-to-fit
158
+ // handles the ordinary case, this rejects what it cannot rescue.
159
+ const availableTextW = availableNodeTextWidth(node.width);
160
+ for (const [field, value, minimum] of [
161
+ ['Sublabel', node.sublabel, nodeTextFit.sublabelMinimum],
162
+ ['Tag', node.tag, nodeTextFit.tagMinimum],
163
+ ]) {
164
+ if (!value) continue;
165
+ const minimumW = minimumNodeTextWidth(value, minimum);
166
+ if (minimumW > availableTextW) {
167
+ problems.push(`${field} "${value}" needs ~${Math.ceil(minimumW)}px at the ${minimum}px legible minimum, but node "${node.id}" provides ${availableTextW}px — shorten the ${field.toLowerCase()} or increase node.width.`);
168
+ }
169
+ }
170
+ }
171
+
172
+ const nodeList = asArray(dataflow.nodes);
173
+ for (let i = 0; i < nodeList.length; i += 1) {
174
+ for (let j = i + 1; j < nodeList.length; j += 1) {
175
+ const a = nodes.get(nodeList[i].id);
176
+ const b = nodes.get(nodeList[j].id);
177
+ if (rectsOverlap(a, b, 10)) {
178
+ problems.push(`Nodes "${a.id}" and "${b.id}" are less than 10px apart — move one to another stage/row or adjust yOffset.`);
179
+ }
180
+ }
181
+ }
182
+
183
+ for (const flow of asArray(dataflow.flows)) {
184
+ if (!nodes.has(flow.from)) problems.push(`Flow "${flow.label || flow.from}" references unknown source "${flow.from}".`);
185
+ if (!nodes.has(flow.to)) problems.push(`Flow "${flow.label || flow.to}" references unknown target "${flow.to}".`);
186
+ if (!flow.label) problems.push(`Flow "${flow.from}" -> "${flow.to}" must include a short data label.`);
187
+ if (nodes.has(flow.from) && nodes.has(flow.to)) {
188
+ const routed = pathFor(flow);
189
+ const [start, end] = [routed.points[0], routed.points[routed.points.length - 1]];
190
+ const distance = Math.hypot(end[0] - start[0], end[1] - start[1]);
191
+ if (distance < 34) problems.push(`Flow "${flow.label}" is too short (${Math.round(distance)}px; minimum 34px) — route it through a channel or spread its nodes.`);
192
+ if (Array.isArray(flow.via)) {
193
+ for (let segmentIndex = 0; segmentIndex < routed.points.length - 1; segmentIndex += 1) {
194
+ const segmentStart = routed.points[segmentIndex];
195
+ const segmentEnd = routed.points[segmentIndex + 1];
196
+ const isDiagonal = Math.abs(segmentStart[0] - segmentEnd[0]) > 0.01
197
+ && Math.abs(segmentStart[1] - segmentEnd[1]) > 0.01;
198
+ if (!isDiagonal) continue;
199
+ const viaIndex = Math.min(segmentIndex, flow.via.length - 1);
200
+ problems.push(`Flow "${flow.label}" has a diagonal segment from (${segmentStart.join(', ')}) to (${segmentEnd.join(', ')}) — align via[${viaIndex}] with its adjacent point by sharing the same x or y coordinate.`);
201
+ }
202
+ }
203
+ }
204
+ }
205
+
206
+ problems.push(...cleanEndpointSideProblems({
207
+ relations: dataflow.flows,
208
+ endpointIds: new Set(nodes.keys()),
209
+ pathFor,
210
+ diagramType: 'dataflow',
211
+ relationCollection: 'flows',
212
+ fromSideFor: (flow) => flowSides(flow).fromSide,
213
+ toSideFor: (flow) => flowSides(flow).toSide,
214
+ routeHint: 'keep automatic routing, or choose fromSide/toSide and via points whose first and final segments cross node borders perpendicularly',
215
+ }));
216
+ problems.push(...cleanFlowProblems({
217
+ relations: dataflow.flows,
218
+ endpointIds: new Set(nodes.keys()),
219
+ obstacles: nodes.values(),
220
+ pathFor,
221
+ diagramType: 'dataflow',
222
+ relationCollection: 'flows',
223
+ obstacleKind: 'node',
224
+ profile: dataflow.meta?.quality_profile,
225
+ routeHint: 'adjust fromSide/toSide, set route/via or channelX/channelY, or move the node to another stage/row'
226
+ }));
227
+ problems.push(...cleanCrossingProblems({
228
+ relations: dataflow.flows,
229
+ endpointIds: new Set(nodes.keys()),
230
+ pathFor,
231
+ diagramType: 'dataflow',
232
+ relationCollection: 'flows',
233
+ profile: dataflow.meta?.quality_profile,
234
+ routeHint: 'adjust route/via or channelX/channelY so the flows use separate stage corridors'
235
+ }));
236
+ problems.push(...cleanAmbiguousCorridorProblems({
237
+ relations: dataflow.flows,
238
+ endpointIds: new Set(nodes.keys()),
239
+ pathFor,
240
+ diagramType: 'dataflow',
241
+ relationCollection: 'flows',
242
+ profile: dataflow.meta?.quality_profile,
243
+ routeHint: 'adjust route/via or channelX/channelY so unrelated flows do not visually merge'
244
+ }));
245
+ problems.push(...cleanBorderRunProblems({
246
+ relations: dataflow.flows,
247
+ endpointIds: new Set(nodes.keys()),
248
+ frames: compositionFrames,
249
+ pathFor,
250
+ diagramType: 'dataflow',
251
+ relationCollection: 'flows',
252
+ profile: dataflow.meta?.quality_profile,
253
+ routeHint: 'adjust route/via or channelX/channelY so the flow crosses the stage perpendicularly instead of following its border'
254
+ }));
255
+ problems.push(...cleanRouteRhythmProblems({
256
+ relations: dataflow.flows,
257
+ endpointIds: new Set(nodes.keys()),
258
+ pathFor,
259
+ diagramType: 'dataflow',
260
+ relationCollection: 'flows',
261
+ profile: dataflow.meta?.quality_profile,
262
+ routeHint: 'adjust route/via or channelX/channelY so each turn uses a clear inter-stage corridor'
263
+ }));
264
+
265
+ const labelRects = [];
266
+ for (const [flowIndex, flow] of asArray(dataflow.flows).entries()) {
267
+ if (!flow.label || !nodes.has(flow.from) || !nodes.has(flow.to)) continue;
268
+ const [lx, ly] = labelPoint(flow, pathFor(flow).points);
269
+ const { width, height } = flowLabelSize(flow);
270
+ labelRects.push({ relation: flow, relationIndex: flowIndex, label: flow.label, x: lx - width / 2, y: ly - 11, width, height, lx, ly });
271
+ }
272
+ for (const rect of labelRects) {
273
+ for (const node of nodes.values()) {
274
+ if (rectsOverlap(rect, node, -2)) {
275
+ problems.push(`Label "${rect.label}" overlaps node "${node.id}" — adjust labelDx/labelDy/labelSegment or set labelAt.\n${suggestLabelObstacleFix(rect, rect.lx, rect.ly, node, 'node')}`);
276
+ }
277
+ }
278
+ }
279
+ for (let i = 0; i < labelRects.length; i += 1) {
280
+ for (let j = i + 1; j < labelRects.length; j += 1) {
281
+ if (rectsOverlap(labelRects[i], labelRects[j], -2)) {
282
+ problems.push(`Labels "${labelRects[i].label}" and "${labelRects[j].label}" overlap — adjust labelDx/labelDy.\n${suggestLabelPairFix(labelRects[i], labelRects[j])}`);
283
+ }
284
+ }
285
+ }
286
+ problems.push(...cleanLabelRouteClearanceProblems({
287
+ relations: dataflow.flows,
288
+ labels: labelRects,
289
+ endpointIds: new Set(nodes.keys()),
290
+ pathFor,
291
+ diagramType: 'dataflow',
292
+ relationCollection: 'flows',
293
+ profile: dataflow.meta?.quality_profile,
294
+ routeHint: 'adjust labelAt, labelDx, labelDy, or labelSegment; otherwise adjust the other flow route/via/channelX/channelY'
295
+ }));
296
+
297
+ const lastStageX = stageX(asArray(dataflow.stages).length - 1);
298
+ if (lastStageX + layout.stageW / 2 > viewBox[0] - 24) {
299
+ problems.push(`Stages exceed viewBox width — set meta.viewBox[0] to at least ${Math.ceil(lastStageX + layout.stageW / 2 + 24)}.`);
300
+ }
301
+
302
+ if (problems.length) {
303
+ throwDiagnosticProblems('Data-flow layout validation failed', problems, {
304
+ subject: { diagramType: 'dataflow' },
305
+ });
306
+ }
307
+ }
308
+
309
+ function routeVia(flow, from, to, start, end) {
310
+ if (flow.via) return flow.via;
311
+ switch (flow.route || 'auto') {
312
+ case 'straight':
313
+ return [];
314
+ case 'vertical-channel': {
315
+ const x = flow.channelX ?? start[0] + (end[0] > start[0] ? 44 : -44);
316
+ return [[x, start[1]], [x, end[1]]];
317
+ }
318
+ case 'bottom-channel': {
319
+ const y = flow.channelY ?? Math.max(from.y + from.height, to.y + to.height) + 26;
320
+ return [[start[0], y], [end[0], y]];
321
+ }
322
+ case 'top-channel': {
323
+ const y = flow.channelY ?? Math.min(from.y, to.y) - 24;
324
+ return [[start[0], y], [end[0], y]];
325
+ }
326
+ case 'auto':
327
+ default: {
328
+ if (Math.abs(start[1] - end[1]) < 4) return [];
329
+ const midX = start[0] + (end[0] - start[0]) / 2;
330
+ return [[midX, start[1]], [midX, end[1]]];
331
+ }
332
+ }
333
+ }
334
+
335
+ const pathCache = new Map();
336
+
337
+ function flowSides(flow) {
338
+ const from = nodes.get(flow.from);
339
+ const to = nodes.get(flow.to);
340
+ return {
341
+ fromSide: chosenSide(flow.fromSide, defaultFromSide(from, to)),
342
+ toSide: chosenSide(flow.toSide, defaultToSide(from, to)),
343
+ };
344
+ }
345
+
346
+ const automaticPorts = automaticPortSpread(dataflow.flows, nodes, {
347
+ sideFor: (flow, endpoint) => flowSides(flow)[endpoint === 'source' ? 'fromSide' : 'toSide'],
348
+ });
349
+
350
+ function pathFor(flow) {
351
+ if (pathCache.has(flow)) return pathCache.get(flow);
352
+ const from = nodes.get(flow.from);
353
+ const to = nodes.get(flow.to);
354
+ const ports = automaticPorts.get(flow);
355
+ const { fromSide, toSide } = flowSides(flow);
356
+ const start = ports?.from || anchor(from, fromSide);
357
+ const end = ports?.to || anchor(to, toSide);
358
+ const points = [start, ...routeVia(flow, from, to, start, end), end];
359
+ const routed = { d: polylinePath(points), points };
360
+ pathCache.set(flow, routed);
361
+ return routed;
362
+ }
363
+
364
+ function renderStage(stage, index) {
365
+ const frame = compositionFrames[index];
366
+ const cx = stageX(index);
367
+ return ` <rect data-graph-role="structural-frame" data-composition-frame-kind="stage" data-composition-frame-id="${index}" x="${frame.x}" y="${frame.y}" width="${frame.width}" height="${frame.height}" rx="${frame.radius}" class="c-lane" stroke-width="1"/>
368
+ <text x="${cx}" y="${layout.stageY + 22}" class="t-dim" font-size="9" font-weight="600" text-anchor="middle">${String(index + 1).padStart(2, '0')} / ${esc(stage.label)}</text>`;
369
+ }
370
+
371
+ function renderNode(node) {
372
+ const fill = componentFill[node.type] || 'c-external';
373
+ const accent = componentText[node.type] || 't-muted';
374
+ const hasSub = node.sublabel != null && node.sublabel !== '';
375
+ const sub = hasSub
376
+ ? `\n <text data-detail="context" x="${node.cx}" y="${node.y + 37}" class="t-muted" font-size="${fittedNodeFontSize(node.sublabel, node.width, nodeTextFit.sublabelPreferred, nodeTextFit.sublabelMinimum)}" text-anchor="middle">${esc(node.sublabel)}</text>`
377
+ : '';
378
+ const tag = node.tag
379
+ ? `\n <text data-detail="fine" x="${node.cx}" y="${node.y + node.height - 11}" class="${accent}" font-size="${fittedNodeFontSize(node.tag, node.width, nodeTextFit.tagPreferred, nodeTextFit.tagMinimum)}" text-anchor="middle">${esc(node.tag)}</text>`
380
+ : '';
381
+ const stage = asArray(dataflow.stages)[node.stage];
382
+ const context = stage
383
+ ? `${String(node.stage + 1).padStart(2, '0')} / ${stage.label}`
384
+ : i18nText(dataflow.meta.locale, 'node.context.dataflow');
385
+ const brand = renderBrandMark(node, { x: node.x + node.width - 22, y: node.y + 6 });
386
+ const labelFontSize = fittedNodeFontSize(node.label, brandLabelFitWidth(node, node.width), 10, 8);
387
+ const passport = { kind: node.type, sublabel: node.sublabel, tag: node.tag, context, ...brandMetadataFor(node) };
388
+ return ` <g ${focusNodeAttrs(node.id, node.label, passport, dataflow.meta.locale)}>
389
+ ${focusNodeTitle(node.label, passport)}
390
+ <rect x="${node.x}" y="${node.y}" width="${node.width}" height="${node.height}" rx="6" class="c-mask"/>
391
+ <rect x="${node.x}" y="${node.y}" width="${node.width}" height="${node.height}" rx="6" class="${fill}"${animateAttr(dataflow.meta, 'node', nodeSteps.get(node.id))} stroke-width="1.5"/>
392
+ ${renderSemanticSigil(node.type, { x: node.x + 6, y: node.y + 6 })}${brand ? `\n ${brand}` : ''}
393
+ <text data-node-label=""${hasSub ? ' data-detail-anchor=""' : ''} x="${node.cx}" y="${node.y + 21}" class="t-primary" font-size="${labelFontSize}" font-weight="600" text-anchor="middle">${esc(node.label)}</text>${sub}${tag}
394
+ </g>`;
395
+ }
396
+
397
+ function renderFlowPath(flow, index) {
398
+ const [cls, marker] = arrowClassMap[flow.variant || 'default'] || arrowClassMap.default;
399
+ const routed = pathFor(flow);
400
+ const strokeWidth = flow.width || (flow.variant === 'emphasis' ? 1.8 : 1.4);
401
+ return ` <path ${focusEdgeAttrs(flow.from, flow.to, flow.label, index, flow.id)} data-composition-points="${routePointsValue(routed.points)}" d="${routed.d}" class="${cls}"${animateAttr(dataflow.meta, 'edge', index)} stroke-width="${strokeWidth}" marker-end="url(#${marker})"/>`;
402
+ }
403
+
404
+ function renderFlowLabel(flow, index) {
405
+ const routed = pathFor(flow);
406
+ const [lx, ly] = labelPoint(flow, routed.points);
407
+ const { width: labelW, height: labelH } = flowLabelSize(flow);
408
+ const classification = flow.classification
409
+ ? `\n <text data-detail="fine" x="${lx}" y="${ly + 11}" class="t-dim" font-size="7" text-anchor="middle">${esc(flow.classification)}</text>`
410
+ : '';
411
+ return ` <g data-detail="context" ${focusEdgeAttrs(flow.from, flow.to, flow.label, index, flow.id)}>
412
+ <rect x="${lx - labelW / 2}" y="${ly - 11}" width="${labelW}" height="${labelH}" rx="4" class="c-mask"/>
413
+ <text x="${lx}" y="${ly}" class="${variantAccent(flow.variant)}" font-size="8" text-anchor="middle">${esc(flow.label)}</text>${classification}
414
+ </g>`;
415
+ }
416
+
417
+ const LEGEND_CATALOG = [
418
+ { kind: 'emphasis', className: 'a-emphasis', marker: 'arrowhead-emphasis', strokeWidth: 1.8, swatchWidth: 34, swatchGap: 9, interactive: false },
419
+ { kind: 'security', className: 'a-security', marker: 'arrowhead-security', swatchWidth: 34, swatchGap: 9, interactive: false },
420
+ { kind: 'dashed', className: 'a-dashed', marker: 'arrowhead-dashed', swatchWidth: 34, swatchGap: 9, interactive: false },
421
+ { kind: 'database' },
422
+ { kind: 'default', className: 'a-default', marker: 'arrowhead', swatchWidth: 34, swatchGap: 9, interactive: false },
423
+ ].map((entry) => ({
424
+ ...entry,
425
+ label: i18nText(dataflow.meta.locale, `legend.dataflow.${entry.kind}`),
426
+ }));
427
+
428
+ function renderLegend() {
429
+ const presentKinds = new Set(asArray(dataflow.flows).map((flow) => flow.variant || 'default'));
430
+ if ([...nodes.values()].some((node) => node.type === 'database')) presentKinds.add('database');
431
+ const entries = resolveLegend(dataflow.meta?.legend, LEGEND_CATALOG, presentKinds);
432
+ return renderResolvedLegend({
433
+ entries,
434
+ locale: dataflow.meta.locale,
435
+ layout: {
436
+ x: 40,
437
+ baselineY: viewBox[1] - 36,
438
+ width: viewBox[0] - 80,
439
+ minTitleY: viewBox[1] - 66,
440
+ unfit: dataflow.meta?.legend === undefined ? 'hide' : 'error',
441
+ diagramType: 'dataflow',
442
+ },
443
+ renderSwatch: (entry) => entry.kind === 'database'
444
+ ? `<rect x="${entry.x}" y="${entry.baseline - 8}" width="14" height="9" rx="2" class="c-database" stroke-width="1"/>`
445
+ : `<path d="M ${entry.x} ${entry.baseline - 3} L ${entry.x + 34} ${entry.baseline - 3}" class="${entry.className}" stroke-width="${entry.strokeWidth || 1.4}" marker-end="url(#${entry.marker})"/>`,
446
+ });
447
+ }
448
+
449
+ function renderSvg() {
450
+ return ` <svg viewBox="0 0 ${viewBox[0]} ${viewBox[1]}" ${svgRootAttrs(dataflow.meta, 'data-flow diagram')}>
451
+ ${svgAccessibleText(dataflow.meta, 'dataflow')}
452
+ ${renderDefinitions()}
453
+
454
+ <!-- Background Grid -->
455
+ <rect width="100%" height="100%" fill="url(#grid)" />
456
+
457
+ <!-- Data Stages -->
458
+ ${dataflow.stages.map(renderStage).join('\n\n')}
459
+
460
+ <!-- Flow paths -->
461
+ ${asArray(dataflow.flows).map(renderFlowPath).join('\n')}
462
+
463
+ <!-- Nodes -->
464
+ ${[...nodes.values()].map(renderNode).join('\n\n')}
465
+
466
+ <!-- Flow labels -->
467
+ ${asArray(dataflow.flows).map(renderFlowLabel).join('\n')}
468
+
469
+ <!-- Legend -->
470
+ ${renderLegend()}
471
+ </svg>`;
472
+ }
473
+
474
+ validateDataflow();
475
+ writeDiagram({
476
+ outPath,
477
+ template,
478
+ diagramType: 'dataflow',
479
+ meta: dataflow.meta,
480
+ svg: renderSvg(),
481
+ cards: dataflow.cards,
482
+ });