@sinm/kai 1.8.5

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 (61) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +219 -0
  3. package/bin/kai-cli.js +21 -0
  4. package/dist-cli/kai-cli.js +218494 -0
  5. package/dist-electron/renderer/assets/_baseUniq-C3qTPmDE.js +660 -0
  6. package/dist-electron/renderer/assets/arc-BNCDL4e8.js +131 -0
  7. package/dist-electron/renderer/assets/architectureDiagram-Q4EWVU46-BdbGbDeJ.js +8718 -0
  8. package/dist-electron/renderer/assets/blockDiagram-DXYQGD6D-QiXI7ilT.js +3637 -0
  9. package/dist-electron/renderer/assets/c4Diagram-AHTNJAMY-BddxtMgY.js +2482 -0
  10. package/dist-electron/renderer/assets/channel-C_JLiB8I.js +7 -0
  11. package/dist-electron/renderer/assets/chunk-4BX2VUAB-s-dHrXuO.js +16 -0
  12. package/dist-electron/renderer/assets/chunk-4TB4RGXK-vzGbJGfp.js +1920 -0
  13. package/dist-electron/renderer/assets/chunk-55IACEB6-DS6S48ws.js +13 -0
  14. package/dist-electron/renderer/assets/chunk-EDXVE4YY-CkjF90gW.js +24 -0
  15. package/dist-electron/renderer/assets/chunk-FMBD7UC4-BXvIgVUY.js +19 -0
  16. package/dist-electron/renderer/assets/chunk-OYMX7WX6-YZbrtKSv.js +1939 -0
  17. package/dist-electron/renderer/assets/chunk-QZHKN3VN-BbLYRfB3.js +19 -0
  18. package/dist-electron/renderer/assets/chunk-YZCP3GAM-JVGt9SK_.js +116 -0
  19. package/dist-electron/renderer/assets/classDiagram-6PBFFD2Q-BwZMRjub.js +23 -0
  20. package/dist-electron/renderer/assets/classDiagram-v2-HSJHXN6E-BwZMRjub.js +23 -0
  21. package/dist-electron/renderer/assets/clone-BC-6Iyrf.js +8 -0
  22. package/dist-electron/renderer/assets/cose-bilkent-S5V4N54A-C3CGX8BH.js +4942 -0
  23. package/dist-electron/renderer/assets/cytoscape.esm-D6E6cAed.js +30246 -0
  24. package/dist-electron/renderer/assets/dagre-KV5264BT-DXOCL1ZZ.js +694 -0
  25. package/dist-electron/renderer/assets/defaultLocale-B2RvLBDe.js +206 -0
  26. package/dist-electron/renderer/assets/diagram-5BDNPKRD-B9dghm7-.js +171 -0
  27. package/dist-electron/renderer/assets/diagram-G4DWMVQ6-DDupyCeT.js +853 -0
  28. package/dist-electron/renderer/assets/diagram-MMDJMWI5-Bagr5R3p.js +303 -0
  29. package/dist-electron/renderer/assets/diagram-TYMM5635-YL5sCgeo.js +214 -0
  30. package/dist-electron/renderer/assets/erDiagram-SMLLAGMA-CHytCe4p.js +1227 -0
  31. package/dist-electron/renderer/assets/flowDiagram-DWJPFMVM-BJgPbbzi.js +2332 -0
  32. package/dist-electron/renderer/assets/ganttDiagram-T4ZO3ILL-BN-Vq0iy.js +3714 -0
  33. package/dist-electron/renderer/assets/gitGraphDiagram-UUTBAWPF-CbUpEcLb.js +1375 -0
  34. package/dist-electron/renderer/assets/graph-Di49T8Ee.js +953 -0
  35. package/dist-electron/renderer/assets/index-C55TZN9T.css +14105 -0
  36. package/dist-electron/renderer/assets/index-D-H_6heO.js +91405 -0
  37. package/dist-electron/renderer/assets/infoDiagram-42DDH7IO-BPl-rsFx.js +33 -0
  38. package/dist-electron/renderer/assets/init-ZxktEp_H.js +16 -0
  39. package/dist-electron/renderer/assets/ishikawaDiagram-UXIWVN3A-C8ly-VN_.js +967 -0
  40. package/dist-electron/renderer/assets/journeyDiagram-VCZTEJTY-nUjo5Mzy.js +1255 -0
  41. package/dist-electron/renderer/assets/kanban-definition-6JOO6SKY-DWVGGGQB.js +1052 -0
  42. package/dist-electron/renderer/assets/katex-CYis69t2.js +14301 -0
  43. package/dist-electron/renderer/assets/layout-BO15dWax.js +2217 -0
  44. package/dist-electron/renderer/assets/linear-bwcJeNAk.js +340 -0
  45. package/dist-electron/renderer/assets/min-CSnTolL5.js +41 -0
  46. package/dist-electron/renderer/assets/mindmap-definition-QFDTVHPH-WJVpu9VT.js +1186 -0
  47. package/dist-electron/renderer/assets/ordinal-CxptdPJm.js +76 -0
  48. package/dist-electron/renderer/assets/pieDiagram-DEJITSTG-DF_DZ5Q4.js +248 -0
  49. package/dist-electron/renderer/assets/quadrantDiagram-34T5L4WZ-UhXGuJcr.js +1342 -0
  50. package/dist-electron/renderer/assets/requirementDiagram-MS252O5E-BtD6ux77.js +1204 -0
  51. package/dist-electron/renderer/assets/sankeyDiagram-XADWPNL6-CC4IbM1T.js +1205 -0
  52. package/dist-electron/renderer/assets/sequenceDiagram-FGHM5R23-Da4bQBSu.js +4502 -0
  53. package/dist-electron/renderer/assets/stateDiagram-FHFEXIEX-zEkMqOXM.js +452 -0
  54. package/dist-electron/renderer/assets/stateDiagram-v2-QKLJ7IA2-DpXHvwUL.js +21 -0
  55. package/dist-electron/renderer/assets/timeline-definition-GMOUNBTQ-DJnjzEUR.js +1596 -0
  56. package/dist-electron/renderer/assets/vennDiagram-DHZGUBPP-f6WAsZFS.js +2486 -0
  57. package/dist-electron/renderer/assets/wardley-RL74JXVD-pTLEMWKj.js +24199 -0
  58. package/dist-electron/renderer/assets/wardleyDiagram-NUSXRM2D-GRV6kOg2.js +901 -0
  59. package/dist-electron/renderer/assets/xychartDiagram-5P7HB3ND-BAcUBgxf.js +1932 -0
  60. package/dist-electron/renderer/index.html +13 -0
  61. package/package.json +52 -0
@@ -0,0 +1,901 @@
1
+ import { s as setAccDescription, g as getAccDescription, q as getDiagramTitle, p as setDiagramTitle, a as getAccTitle, b as setAccTitle, _ as __name, l as log, I as selectSvgElement, e as configureSvgSize, z as clear, c as getConfig2$1, i as sanitizeText } from "./index-D-H_6heO.js";
2
+ import { p as populateCommonDb } from "./chunk-4BX2VUAB-s-dHrXuO.js";
3
+ import { p as parse } from "./wardley-RL74JXVD-pTLEMWKj.js";
4
+ import "./min-CSnTolL5.js";
5
+ import "./_baseUniq-C3qTPmDE.js";
6
+ var toPercent = /* @__PURE__ */ __name((value, context) => {
7
+ const normalized = value <= 1 ? value * 100 : value;
8
+ if (normalized < 0 || normalized > 100) {
9
+ throw new Error(
10
+ `${context} must be between 0-1 (decimal) or 0-100 (percentage). Received: ${value}`
11
+ );
12
+ }
13
+ return normalized;
14
+ }, "toPercent");
15
+ var toCoordinates = /* @__PURE__ */ __name((visibility, evolution, context) => {
16
+ return {
17
+ x: toPercent(evolution, `${context} evolution`),
18
+ y: toPercent(visibility, `${context} visibility`)
19
+ };
20
+ }, "toCoordinates");
21
+ var getFlowFromPort = /* @__PURE__ */ __name((port) => {
22
+ if (!port) {
23
+ return void 0;
24
+ }
25
+ if (port === "+<>") {
26
+ return "bidirectional";
27
+ }
28
+ if (port === "+<") {
29
+ return "backward";
30
+ }
31
+ if (port === "+>") {
32
+ return "forward";
33
+ }
34
+ return void 0;
35
+ }, "getFlowFromPort");
36
+ var extractFlowFromArrow = /* @__PURE__ */ __name((arrow) => {
37
+ if (!arrow?.startsWith("+")) {
38
+ return {};
39
+ }
40
+ const labelMatch = /^\+'([^']*)'/.exec(arrow);
41
+ const flowLabel = labelMatch?.[1];
42
+ if (arrow.includes("<>")) {
43
+ return { flow: "bidirectional", label: flowLabel };
44
+ }
45
+ if (arrow.includes("<")) {
46
+ return { flow: "backward", label: flowLabel };
47
+ }
48
+ if (arrow.includes(">")) {
49
+ return { flow: "forward", label: flowLabel };
50
+ }
51
+ return { label: flowLabel };
52
+ }, "extractFlowFromArrow");
53
+ var populateDb = /* @__PURE__ */ __name((ast, db) => {
54
+ populateCommonDb(ast, db);
55
+ if (ast.size) {
56
+ db.setSize(ast.size.width, ast.size.height);
57
+ }
58
+ if (ast.evolution) {
59
+ const stages = ast.evolution.stages.map((stage) => {
60
+ if (stage.secondName) {
61
+ return `${stage.name.trim()} / ${stage.secondName.trim()}`;
62
+ }
63
+ return stage.name.trim();
64
+ });
65
+ const stageBoundaries = ast.evolution.stages.filter((stage) => stage.boundary !== void 0).map((stage) => stage.boundary);
66
+ db.updateAxes({ stages, stageBoundaries });
67
+ }
68
+ ast.anchors.forEach((anchor) => {
69
+ const coords = toCoordinates(anchor.visibility, anchor.evolution, `Anchor "${anchor.name}"`);
70
+ db.addNode(anchor.name, anchor.name, coords.x, coords.y, "anchor");
71
+ });
72
+ ast.components.forEach((component) => {
73
+ const coords = toCoordinates(
74
+ component.visibility,
75
+ component.evolution,
76
+ `Component "${component.name}"`
77
+ );
78
+ const labelOffsetX = component.label ? (component.label.negX ? -1 : 1) * component.label.offsetX : void 0;
79
+ const labelOffsetY = component.label ? (component.label.negY ? -1 : 1) * component.label.offsetY : void 0;
80
+ const sourceStrategy = component.decorator?.strategy;
81
+ db.addNode(
82
+ component.name,
83
+ component.name,
84
+ coords.x,
85
+ coords.y,
86
+ "component",
87
+ labelOffsetX,
88
+ labelOffsetY,
89
+ component.inertia,
90
+ sourceStrategy
91
+ );
92
+ });
93
+ ast.notes.forEach((note) => {
94
+ const coords = toCoordinates(note.visibility, note.evolution, `Note "${note.text}"`);
95
+ db.addNote(note.text, coords.x, coords.y);
96
+ });
97
+ ast.pipelines.forEach((pipeline) => {
98
+ const parentNode = db.getNode(pipeline.parent);
99
+ if (!parentNode || typeof parentNode.y !== "number") {
100
+ throw new Error(
101
+ `Pipeline "${pipeline.parent}" must reference an existing component with coordinates.`
102
+ );
103
+ }
104
+ const parentY = parentNode.y;
105
+ db.startPipeline(pipeline.parent);
106
+ pipeline.components.forEach((component) => {
107
+ const componentId = `${pipeline.parent}_${component.name}`;
108
+ const labelOffsetX = component.label ? (component.label.negX ? -1 : 1) * component.label.offsetX : void 0;
109
+ const labelOffsetY = component.label ? (component.label.negY ? -1 : 1) * component.label.offsetY : void 0;
110
+ const x = toPercent(component.evolution, `Pipeline component "${component.name}" evolution`);
111
+ db.addNode(
112
+ componentId,
113
+ component.name,
114
+ x,
115
+ parentY,
116
+ "pipeline-component",
117
+ labelOffsetX,
118
+ labelOffsetY
119
+ );
120
+ db.addPipelineComponent(pipeline.parent, componentId);
121
+ });
122
+ });
123
+ ast.links.forEach((link) => {
124
+ const isDashed = !!link.arrow && (link.arrow.includes("-.->") || link.arrow.includes(".-."));
125
+ let flow = getFlowFromPort(link.fromPort) ?? getFlowFromPort(link.toPort);
126
+ const { flow: arrowFlow, label: flowLabel } = extractFlowFromArrow(link.arrow);
127
+ if (!flow && arrowFlow) {
128
+ flow = arrowFlow;
129
+ }
130
+ const annotation = link.linkLabel;
131
+ const label = flowLabel ?? annotation;
132
+ db.addLink(link.from, link.to, isDashed, label, flow);
133
+ });
134
+ ast.evolves.forEach((evolve) => {
135
+ const node = db.getNode(evolve.component);
136
+ if (node?.y !== void 0) {
137
+ const target = toPercent(evolve.target, `Evolve target for "${evolve.component}"`);
138
+ db.addTrend(evolve.component, target, node.y);
139
+ }
140
+ });
141
+ if (ast.annotations.length > 0) {
142
+ const annotationsBox = ast.annotations[0];
143
+ const coords = toCoordinates(annotationsBox.x, annotationsBox.y, "Annotations box");
144
+ db.setAnnotationsBox(coords.x, coords.y);
145
+ }
146
+ ast.annotation.forEach((annotation) => {
147
+ const coords = toCoordinates(annotation.x, annotation.y, `Annotation ${annotation.number}`);
148
+ db.addAnnotation(annotation.number, [{ x: coords.x, y: coords.y }], annotation.text);
149
+ });
150
+ ast.accelerators.forEach((accelerator) => {
151
+ const coords = toCoordinates(accelerator.x, accelerator.y, `Accelerator "${accelerator.name}"`);
152
+ db.addAccelerator(accelerator.name, coords.x, coords.y);
153
+ });
154
+ ast.deaccelerators.forEach((deaccelerator) => {
155
+ const coords = toCoordinates(
156
+ deaccelerator.x,
157
+ deaccelerator.y,
158
+ `Deaccelerator "${deaccelerator.name}"`
159
+ );
160
+ db.addDeaccelerator(deaccelerator.name, coords.x, coords.y);
161
+ });
162
+ }, "populateDb");
163
+ var parser = {
164
+ parser: {
165
+ // @ts-expect-error - WardleyDB is not assignable to DiagramDB
166
+ yy: void 0
167
+ },
168
+ parse: /* @__PURE__ */ __name(async (input) => {
169
+ const ast = await parse("wardley", input);
170
+ log.debug(ast);
171
+ const db = parser.parser?.yy;
172
+ if (!db || typeof db.addNode !== "function") {
173
+ throw new Error(
174
+ "parser.parser?.yy was not a WardleyDB. This is due to a bug within Mermaid, please report this issue at https://github.com/mermaid-js/mermaid/issues."
175
+ );
176
+ }
177
+ populateDb(ast, db);
178
+ }, "parse")
179
+ };
180
+ var WardleyBuilder = class {
181
+ constructor() {
182
+ this.nodes = /* @__PURE__ */ new Map();
183
+ this.links = [];
184
+ this.trends = /* @__PURE__ */ new Map();
185
+ this.pipelines = /* @__PURE__ */ new Map();
186
+ this.annotations = [];
187
+ this.notes = [];
188
+ this.accelerators = [];
189
+ this.deaccelerators = [];
190
+ this.axes = {};
191
+ }
192
+ static {
193
+ __name(this, "WardleyBuilder");
194
+ }
195
+ addNode(node) {
196
+ const existing = this.nodes.get(node.id) ?? { id: node.id, label: node.label };
197
+ const merged = {
198
+ ...existing,
199
+ ...node,
200
+ className: node.className ?? existing.className,
201
+ labelOffsetX: node.labelOffsetX ?? existing.labelOffsetX,
202
+ labelOffsetY: node.labelOffsetY ?? existing.labelOffsetY
203
+ };
204
+ this.nodes.set(node.id, merged);
205
+ }
206
+ addLink(link) {
207
+ this.links.push(link);
208
+ }
209
+ addTrend(trend) {
210
+ this.trends.set(trend.nodeId, trend);
211
+ }
212
+ startPipeline(nodeId) {
213
+ this.pipelines.set(nodeId, { nodeId, componentIds: [] });
214
+ const node = this.nodes.get(nodeId);
215
+ if (node) {
216
+ node.isPipelineParent = true;
217
+ }
218
+ }
219
+ addPipelineComponent(pipelineNodeId, componentId) {
220
+ const pipeline = this.pipelines.get(pipelineNodeId);
221
+ if (pipeline) {
222
+ pipeline.componentIds.push(componentId);
223
+ }
224
+ const node = this.nodes.get(componentId);
225
+ if (node) {
226
+ node.inPipeline = true;
227
+ }
228
+ }
229
+ addAnnotation(annotation) {
230
+ this.annotations.push(annotation);
231
+ }
232
+ addNote(note) {
233
+ this.notes.push(note);
234
+ }
235
+ addAccelerator(accelerator) {
236
+ this.accelerators.push(accelerator);
237
+ }
238
+ addDeaccelerator(deaccelerator) {
239
+ this.deaccelerators.push(deaccelerator);
240
+ }
241
+ setAnnotationsBox(x, y) {
242
+ this.annotationsBox = { x, y };
243
+ }
244
+ setAxes(partial) {
245
+ this.axes = {
246
+ ...this.axes,
247
+ ...partial
248
+ };
249
+ }
250
+ setSize(width, height) {
251
+ this.size = { width, height };
252
+ }
253
+ getNode(id) {
254
+ return this.nodes.get(id);
255
+ }
256
+ build() {
257
+ const nodes = [];
258
+ for (const node of this.nodes.values()) {
259
+ if (typeof node.x !== "number" || typeof node.y !== "number") {
260
+ throw new Error(`Node "${node.label}" is missing coordinates`);
261
+ }
262
+ nodes.push(node);
263
+ }
264
+ return {
265
+ nodes,
266
+ links: [...this.links],
267
+ trends: [...this.trends.values()],
268
+ pipelines: [...this.pipelines.values()],
269
+ annotations: [...this.annotations],
270
+ notes: [...this.notes],
271
+ accelerators: [...this.accelerators],
272
+ deaccelerators: [...this.deaccelerators],
273
+ annotationsBox: this.annotationsBox,
274
+ axes: { ...this.axes },
275
+ size: this.size
276
+ };
277
+ }
278
+ clear() {
279
+ this.nodes.clear();
280
+ this.links = [];
281
+ this.trends.clear();
282
+ this.pipelines.clear();
283
+ this.annotations = [];
284
+ this.notes = [];
285
+ this.accelerators = [];
286
+ this.deaccelerators = [];
287
+ this.annotationsBox = void 0;
288
+ this.axes = {};
289
+ this.size = void 0;
290
+ }
291
+ };
292
+ var builder = new WardleyBuilder();
293
+ function textSanitizer(text) {
294
+ const config = getConfig2$1();
295
+ return sanitizeText(text.trim(), config);
296
+ }
297
+ __name(textSanitizer, "textSanitizer");
298
+ function getConfig2() {
299
+ return getConfig2$1()["wardley-beta"];
300
+ }
301
+ __name(getConfig2, "getConfig");
302
+ function addNode(id, label, x, y, className, labelOffsetX, labelOffsetY, inertia, sourceStrategy) {
303
+ builder.addNode({
304
+ id,
305
+ label: textSanitizer(label),
306
+ x,
307
+ y,
308
+ className,
309
+ labelOffsetX,
310
+ labelOffsetY,
311
+ inertia,
312
+ sourceStrategy
313
+ });
314
+ }
315
+ __name(addNode, "addNode");
316
+ function addLink(sourceId, targetId, dashed = false, label, flow) {
317
+ builder.addLink({ source: sourceId, target: targetId, dashed, label, flow });
318
+ }
319
+ __name(addLink, "addLink");
320
+ function addTrend(nodeId, targetX, targetY) {
321
+ builder.addTrend({ nodeId, targetX, targetY });
322
+ }
323
+ __name(addTrend, "addTrend");
324
+ function addAnnotation(number, coordinates, text) {
325
+ builder.addAnnotation({
326
+ number,
327
+ coordinates,
328
+ text: text ? textSanitizer(text) : void 0
329
+ });
330
+ }
331
+ __name(addAnnotation, "addAnnotation");
332
+ function addNote(text, x, y) {
333
+ builder.addNote({
334
+ text: textSanitizer(text),
335
+ x,
336
+ y
337
+ });
338
+ }
339
+ __name(addNote, "addNote");
340
+ function addAccelerator(name, x, y) {
341
+ builder.addAccelerator({
342
+ name: textSanitizer(name),
343
+ x,
344
+ y
345
+ });
346
+ }
347
+ __name(addAccelerator, "addAccelerator");
348
+ function addDeaccelerator(name, x, y) {
349
+ builder.addDeaccelerator({
350
+ name: textSanitizer(name),
351
+ x,
352
+ y
353
+ });
354
+ }
355
+ __name(addDeaccelerator, "addDeaccelerator");
356
+ function setAnnotationsBox(x, y) {
357
+ builder.setAnnotationsBox(x, y);
358
+ }
359
+ __name(setAnnotationsBox, "setAnnotationsBox");
360
+ function setSize(width, height) {
361
+ builder.setSize(width, height);
362
+ }
363
+ __name(setSize, "setSize");
364
+ function startPipeline(nodeId) {
365
+ builder.startPipeline(nodeId);
366
+ }
367
+ __name(startPipeline, "startPipeline");
368
+ function addPipelineComponent(pipelineNodeId, componentId) {
369
+ builder.addPipelineComponent(pipelineNodeId, componentId);
370
+ }
371
+ __name(addPipelineComponent, "addPipelineComponent");
372
+ function updateAxes(partial) {
373
+ const sanitized = {};
374
+ if (partial.xLabel) {
375
+ sanitized.xLabel = textSanitizer(partial.xLabel);
376
+ }
377
+ if (partial.yLabel) {
378
+ sanitized.yLabel = textSanitizer(partial.yLabel);
379
+ }
380
+ if (partial.stages) {
381
+ sanitized.stages = partial.stages.map((stage) => textSanitizer(stage));
382
+ }
383
+ if (partial.stageBoundaries) {
384
+ sanitized.stageBoundaries = partial.stageBoundaries;
385
+ }
386
+ builder.setAxes(sanitized);
387
+ }
388
+ __name(updateAxes, "updateAxes");
389
+ function getNode(id) {
390
+ return builder.getNode(id);
391
+ }
392
+ __name(getNode, "getNode");
393
+ function getWardleyData() {
394
+ return builder.build();
395
+ }
396
+ __name(getWardleyData, "getWardleyData");
397
+ function clear2() {
398
+ builder.clear();
399
+ clear();
400
+ }
401
+ __name(clear2, "clear");
402
+ var wardleyDb_default = {
403
+ getConfig: getConfig2,
404
+ addNode,
405
+ addLink,
406
+ addTrend,
407
+ addAnnotation,
408
+ addNote,
409
+ addAccelerator,
410
+ addDeaccelerator,
411
+ setAnnotationsBox,
412
+ setSize,
413
+ startPipeline,
414
+ addPipelineComponent,
415
+ updateAxes,
416
+ getNode,
417
+ getWardleyData,
418
+ clear: clear2,
419
+ setAccTitle,
420
+ getAccTitle,
421
+ setDiagramTitle,
422
+ getDiagramTitle,
423
+ getAccDescription,
424
+ setAccDescription
425
+ };
426
+ var DEFAULT_STAGES = ["Genesis", "Custom Built", "Product", "Commodity"];
427
+ var getTheme = /* @__PURE__ */ __name(() => {
428
+ const { themeVariables } = getConfig2$1();
429
+ return {
430
+ backgroundColor: themeVariables.wardley?.backgroundColor ?? themeVariables.background ?? "#fff",
431
+ axisColor: themeVariables.wardley?.axisColor ?? "#000",
432
+ axisTextColor: themeVariables.wardley?.axisTextColor ?? themeVariables.primaryTextColor ?? "#222",
433
+ gridColor: themeVariables.wardley?.gridColor ?? "rgba(100, 100, 100, 0.2)",
434
+ componentFill: themeVariables.wardley?.componentFill ?? "#fff",
435
+ componentStroke: themeVariables.wardley?.componentStroke ?? "#000",
436
+ componentLabelColor: themeVariables.wardley?.componentLabelColor ?? themeVariables.primaryTextColor ?? "#222",
437
+ linkStroke: themeVariables.wardley?.linkStroke ?? "#000",
438
+ evolutionStroke: themeVariables.wardley?.evolutionStroke ?? "#dc3545",
439
+ annotationStroke: themeVariables.wardley?.annotationStroke ?? "#000",
440
+ annotationTextColor: themeVariables.wardley?.annotationTextColor ?? themeVariables.primaryTextColor ?? "#222",
441
+ annotationFill: themeVariables.wardley?.annotationFill ?? themeVariables.background ?? "#fff"
442
+ };
443
+ }, "getTheme");
444
+ var getConfigValues = /* @__PURE__ */ __name(() => {
445
+ const wardleyConfig = getConfig2$1()["wardley-beta"];
446
+ return {
447
+ width: wardleyConfig?.width ?? 900,
448
+ height: wardleyConfig?.height ?? 600,
449
+ padding: wardleyConfig?.padding ?? 48,
450
+ nodeRadius: wardleyConfig?.nodeRadius ?? 6,
451
+ nodeLabelOffset: wardleyConfig?.nodeLabelOffset ?? 8,
452
+ axisFontSize: wardleyConfig?.axisFontSize ?? 12,
453
+ labelFontSize: wardleyConfig?.labelFontSize ?? 10,
454
+ showGrid: wardleyConfig?.showGrid ?? false,
455
+ useMaxWidth: wardleyConfig?.useMaxWidth ?? true
456
+ };
457
+ }, "getConfigValues");
458
+ var draw = /* @__PURE__ */ __name((text, id, _version, diagObj) => {
459
+ log.debug("Rendering Wardley map\n" + text);
460
+ const configValues = getConfigValues();
461
+ const theme = getTheme();
462
+ const squareSize = configValues.nodeRadius * 1.6;
463
+ const db = diagObj.db;
464
+ const data = db.getWardleyData();
465
+ const title = db.getDiagramTitle();
466
+ const width = data.size?.width ?? configValues.width;
467
+ const height = data.size?.height ?? configValues.height;
468
+ const svg = selectSvgElement(id);
469
+ svg.selectAll("*").remove();
470
+ configureSvgSize(svg, height, width, configValues.useMaxWidth);
471
+ svg.attr("viewBox", `0 0 ${width} ${height}`);
472
+ const root = svg.append("g").attr("class", "wardley-map");
473
+ const defs = svg.append("defs");
474
+ defs.append("marker").attr("id", `arrow-${id}`).attr("viewBox", "0 0 10 10").attr("refX", 9).attr("refY", 5).attr("markerWidth", 6).attr("markerHeight", 6).attr("orient", "auto-start-reverse").append("path").attr("d", "M 0 0 L 10 5 L 0 10 z").attr("fill", theme.evolutionStroke).attr("stroke", "none");
475
+ defs.append("marker").attr("id", `link-arrow-end-${id}`).attr("viewBox", "0 0 10 10").attr("refX", 9).attr("refY", 5).attr("markerWidth", 5).attr("markerHeight", 5).attr("orient", "auto").append("path").attr("d", "M 0 0 L 10 5 L 0 10 z").attr("fill", theme.linkStroke).attr("stroke", "none");
476
+ defs.append("marker").attr("id", `link-arrow-start-${id}`).attr("viewBox", "0 0 10 10").attr("refX", 1).attr("refY", 5).attr("markerWidth", 5).attr("markerHeight", 5).attr("orient", "auto").append("path").attr("d", "M 10 0 L 0 5 L 10 10 z").attr("fill", theme.linkStroke).attr("stroke", "none");
477
+ root.append("rect").attr("class", "wardley-background").attr("width", width).attr("height", height).attr("fill", theme.backgroundColor);
478
+ const chartWidth = width - configValues.padding * 2;
479
+ const chartHeight = height - configValues.padding * 2;
480
+ if (title) {
481
+ root.append("text").attr("class", "wardley-title").attr("x", width / 2).attr("y", configValues.padding / 2).attr("fill", theme.axisTextColor).attr("font-size", configValues.axisFontSize * 1.05).attr("font-weight", "bold").attr("text-anchor", "middle").attr("dominant-baseline", "middle").text(title);
482
+ }
483
+ const projectX = /* @__PURE__ */ __name((value) => configValues.padding + value / 100 * chartWidth, "projectX");
484
+ const projectY = /* @__PURE__ */ __name((value) => height - configValues.padding - value / 100 * chartHeight, "projectY");
485
+ const axisGroup = root.append("g").attr("class", "wardley-axes");
486
+ axisGroup.append("line").attr("x1", configValues.padding).attr("x2", width - configValues.padding).attr("y1", height - configValues.padding).attr("y2", height - configValues.padding).attr("stroke", theme.axisColor).attr("stroke-width", 1);
487
+ axisGroup.append("line").attr("x1", configValues.padding).attr("x2", configValues.padding).attr("y1", configValues.padding).attr("y2", height - configValues.padding).attr("stroke", theme.axisColor).attr("stroke-width", 1);
488
+ const xLabel = data.axes.xLabel ?? "Evolution";
489
+ const yLabel = data.axes.yLabel ?? "Visibility";
490
+ axisGroup.append("text").attr("class", "wardley-axis-label wardley-axis-label-x").attr("x", configValues.padding + chartWidth / 2).attr("y", height - configValues.padding / 4).attr("fill", theme.axisTextColor).attr("font-size", configValues.axisFontSize).attr("font-weight", "bold").attr("text-anchor", "middle").text(xLabel);
491
+ axisGroup.append("text").attr("class", "wardley-axis-label wardley-axis-label-y").attr("x", configValues.padding / 3).attr("y", configValues.padding + chartHeight / 2).attr("fill", theme.axisTextColor).attr("font-size", configValues.axisFontSize).attr("font-weight", "bold").attr("text-anchor", "middle").attr(
492
+ "transform",
493
+ `rotate(-90 ${configValues.padding / 3} ${configValues.padding + chartHeight / 2})`
494
+ ).text(yLabel);
495
+ const stages = data.axes.stages && data.axes.stages.length > 0 ? data.axes.stages : DEFAULT_STAGES;
496
+ if (stages.length > 0) {
497
+ const stageGroup = root.append("g").attr("class", "wardley-stages");
498
+ const boundaries = data.axes.stageBoundaries;
499
+ const stagePositions = [];
500
+ if (boundaries && boundaries.length === stages.length) {
501
+ let prevBoundary = 0;
502
+ boundaries.forEach((boundary) => {
503
+ stagePositions.push({ start: prevBoundary, end: boundary });
504
+ prevBoundary = boundary;
505
+ });
506
+ } else {
507
+ const stageWidth = 1 / stages.length;
508
+ stages.forEach((_, index) => {
509
+ stagePositions.push({
510
+ start: index * stageWidth,
511
+ end: (index + 1) * stageWidth
512
+ });
513
+ });
514
+ }
515
+ stages.forEach((stage, index) => {
516
+ const pos = stagePositions[index];
517
+ const startX = configValues.padding + pos.start * chartWidth;
518
+ const endX = configValues.padding + pos.end * chartWidth;
519
+ const centerX = (startX + endX) / 2;
520
+ if (index > 0) {
521
+ stageGroup.append("line").attr("x1", startX).attr("x2", startX).attr("y1", configValues.padding).attr("y2", height - configValues.padding).attr("stroke", "#000").attr("stroke-width", 1).attr("stroke-dasharray", "5 5").attr("opacity", 0.8);
522
+ }
523
+ stageGroup.append("text").attr("class", "wardley-stage-label").attr("x", centerX).attr("y", height - configValues.padding / 1.5).attr("fill", theme.axisTextColor).attr("font-size", configValues.axisFontSize - 2).attr("text-anchor", "middle").text(stage);
524
+ });
525
+ }
526
+ if (configValues.showGrid) {
527
+ const gridGroup = root.append("g").attr("class", "wardley-grid");
528
+ for (let i = 1; i < 4; i++) {
529
+ const ratio = i / 4;
530
+ const x = configValues.padding + chartWidth * ratio;
531
+ gridGroup.append("line").attr("x1", x).attr("x2", x).attr("y1", configValues.padding).attr("y2", height - configValues.padding).attr("stroke", theme.gridColor).attr("stroke-dasharray", "2 6");
532
+ gridGroup.append("line").attr("x1", configValues.padding).attr("x2", width - configValues.padding).attr("y1", height - configValues.padding - chartHeight * ratio).attr("y2", height - configValues.padding - chartHeight * ratio).attr("stroke", theme.gridColor).attr("stroke-dasharray", "2 6");
533
+ }
534
+ }
535
+ const positions = /* @__PURE__ */ new Map();
536
+ data.nodes.forEach((node) => {
537
+ positions.set(node.id, {
538
+ x: projectX(node.x),
539
+ y: projectY(node.y),
540
+ node
541
+ });
542
+ });
543
+ if (data.pipelines.length > 0) {
544
+ const pipelineGroup = root.append("g").attr("class", "wardley-pipelines");
545
+ const pipelineLinksGroup = root.append("g").attr("class", "wardley-pipeline-links");
546
+ data.pipelines.forEach((pipeline) => {
547
+ if (pipeline.componentIds.length === 0) {
548
+ return;
549
+ }
550
+ const sortedComponents = pipeline.componentIds.map((id2) => ({ id: id2, pos: positions.get(id2), node: data.nodes.find((n) => n.id === id2) })).filter((c) => c.pos && c.node).sort((a, b) => a.node.x - b.node.x);
551
+ for (let i = 0; i < sortedComponents.length - 1; i++) {
552
+ const current = sortedComponents[i];
553
+ const next = sortedComponents[i + 1];
554
+ pipelineLinksGroup.append("line").attr("class", "wardley-pipeline-evolution-link").attr("x1", current.pos.x).attr("y1", current.pos.y).attr("x2", next.pos.x).attr("y2", next.pos.y).attr("stroke", theme.linkStroke).attr("stroke-width", 1).attr("stroke-dasharray", "4 4");
555
+ }
556
+ let minX = Infinity;
557
+ let maxX = -Infinity;
558
+ let y = 0;
559
+ pipeline.componentIds.forEach((componentId) => {
560
+ const pos = positions.get(componentId);
561
+ if (pos) {
562
+ minX = Math.min(minX, pos.x);
563
+ maxX = Math.max(maxX, pos.x);
564
+ y = pos.y;
565
+ }
566
+ });
567
+ if (minX !== Infinity && maxX !== -Infinity) {
568
+ const padding = 15;
569
+ const height2 = configValues.nodeRadius * 4;
570
+ const boxTop = y - height2 / 2;
571
+ const parentPos = positions.get(pipeline.nodeId);
572
+ if (parentPos) {
573
+ const centerX = (minX + maxX) / 2;
574
+ parentPos.x = centerX;
575
+ parentPos.y = boxTop - squareSize / 6;
576
+ }
577
+ pipelineGroup.append("rect").attr("class", "wardley-pipeline-box").attr("x", minX - padding).attr("y", boxTop).attr("width", maxX - minX + padding * 2).attr("height", height2).attr("fill", "none").attr("stroke", theme.axisColor).attr("stroke-width", 1.5).attr("rx", 4).attr("ry", 4);
578
+ }
579
+ });
580
+ }
581
+ const linksGroup = root.append("g").attr("class", "wardley-links");
582
+ const pipelineMap = /* @__PURE__ */ new Map();
583
+ data.pipelines.forEach((pipeline) => {
584
+ pipelineMap.set(pipeline.nodeId, new Set(pipeline.componentIds));
585
+ });
586
+ const validLinks = data.links.filter((link) => {
587
+ if (!positions.has(link.source) || !positions.has(link.target)) {
588
+ return false;
589
+ }
590
+ const pipelineComponents = pipelineMap.get(link.target);
591
+ if (pipelineComponents?.has(link.source)) {
592
+ return false;
593
+ }
594
+ return true;
595
+ });
596
+ linksGroup.selectAll("line").data(validLinks).enter().append("line").attr("class", (link) => `wardley-link${link.dashed ? " wardley-link--dashed" : ""}`).attr("x1", (link) => {
597
+ const sourcePos = positions.get(link.source);
598
+ const targetPos = positions.get(link.target);
599
+ const sourceNode = data.nodes.find((n) => n.id === link.source);
600
+ const radius = sourceNode.isPipelineParent ? squareSize / Math.sqrt(2) : configValues.nodeRadius;
601
+ const dx = targetPos.x - sourcePos.x;
602
+ const dy = targetPos.y - sourcePos.y;
603
+ const distance = Math.sqrt(dx * dx + dy * dy);
604
+ return sourcePos.x + dx / distance * radius;
605
+ }).attr("y1", (link) => {
606
+ const sourcePos = positions.get(link.source);
607
+ const targetPos = positions.get(link.target);
608
+ const sourceNode = data.nodes.find((n) => n.id === link.source);
609
+ const radius = sourceNode.isPipelineParent ? squareSize / Math.sqrt(2) : configValues.nodeRadius;
610
+ const dx = targetPos.x - sourcePos.x;
611
+ const dy = targetPos.y - sourcePos.y;
612
+ const distance = Math.sqrt(dx * dx + dy * dy);
613
+ return sourcePos.y + dy / distance * radius;
614
+ }).attr("x2", (link) => {
615
+ const sourcePos = positions.get(link.source);
616
+ const targetPos = positions.get(link.target);
617
+ const targetNode = data.nodes.find((n) => n.id === link.target);
618
+ const radius = targetNode.isPipelineParent ? squareSize / Math.sqrt(2) : configValues.nodeRadius;
619
+ const dx = sourcePos.x - targetPos.x;
620
+ const dy = sourcePos.y - targetPos.y;
621
+ const distance = Math.sqrt(dx * dx + dy * dy);
622
+ return targetPos.x + dx / distance * radius;
623
+ }).attr("y2", (link) => {
624
+ const sourcePos = positions.get(link.source);
625
+ const targetPos = positions.get(link.target);
626
+ const targetNode = data.nodes.find((n) => n.id === link.target);
627
+ const radius = targetNode.isPipelineParent ? squareSize / Math.sqrt(2) : configValues.nodeRadius;
628
+ const dx = sourcePos.x - targetPos.x;
629
+ const dy = sourcePos.y - targetPos.y;
630
+ const distance = Math.sqrt(dx * dx + dy * dy);
631
+ return targetPos.y + dy / distance * radius;
632
+ }).attr("stroke", theme.linkStroke).attr("stroke-width", 1).attr("stroke-dasharray", (link) => link.dashed ? "6 6" : null).attr("marker-end", (link) => {
633
+ if (link.flow === "forward" || link.flow === "bidirectional") {
634
+ return `url(#link-arrow-end-${id})`;
635
+ }
636
+ return null;
637
+ }).attr("marker-start", (link) => {
638
+ if (link.flow === "backward" || link.flow === "bidirectional") {
639
+ return `url(#link-arrow-start-${id})`;
640
+ }
641
+ return null;
642
+ });
643
+ linksGroup.selectAll("text").data(validLinks.filter((link) => link.label)).enter().append("text").attr("class", "wardley-link-label").attr("x", (link) => {
644
+ const sourcePos = positions.get(link.source);
645
+ const targetPos = positions.get(link.target);
646
+ const midX = (sourcePos.x + targetPos.x) / 2;
647
+ const dy = targetPos.y - sourcePos.y;
648
+ const dx = targetPos.x - sourcePos.x;
649
+ const distance = Math.sqrt(dx * dx + dy * dy);
650
+ const offset = 8;
651
+ const perpX = dy / distance;
652
+ return midX + perpX * offset;
653
+ }).attr("y", (link) => {
654
+ const sourcePos = positions.get(link.source);
655
+ const targetPos = positions.get(link.target);
656
+ const midY = (sourcePos.y + targetPos.y) / 2;
657
+ const dx = targetPos.x - sourcePos.x;
658
+ const dy = targetPos.y - sourcePos.y;
659
+ const distance = Math.sqrt(dx * dx + dy * dy);
660
+ const offset = 8;
661
+ const perpY = -dx / distance;
662
+ return midY + perpY * offset;
663
+ }).attr("fill", theme.axisTextColor).attr("font-size", configValues.labelFontSize).attr("text-anchor", "middle").attr("dominant-baseline", "middle").attr("transform", (link) => {
664
+ const sourcePos = positions.get(link.source);
665
+ const targetPos = positions.get(link.target);
666
+ const midX = (sourcePos.x + targetPos.x) / 2;
667
+ const midY = (sourcePos.y + targetPos.y) / 2;
668
+ const dx = targetPos.x - sourcePos.x;
669
+ const dy = targetPos.y - sourcePos.y;
670
+ const distance = Math.sqrt(dx * dx + dy * dy);
671
+ const offset = 8;
672
+ const perpX = dy / distance;
673
+ const perpY = -dx / distance;
674
+ const labelX = midX + perpX * offset;
675
+ const labelY = midY + perpY * offset;
676
+ let angle = Math.atan2(dy, dx) * 180 / Math.PI;
677
+ if (angle > 90 || angle < -90) {
678
+ angle += 180;
679
+ }
680
+ return `rotate(${angle} ${labelX} ${labelY})`;
681
+ }).text((link) => link.label);
682
+ const trendGroup = root.append("g").attr("class", "wardley-trends");
683
+ const trendsWithPositions = data.trends.map((trend) => {
684
+ const origin = positions.get(trend.nodeId);
685
+ if (!origin) {
686
+ return null;
687
+ }
688
+ const targetX = projectX(trend.targetX);
689
+ const targetY = projectY(trend.targetY);
690
+ const dx = targetX - origin.x;
691
+ const dy = targetY - origin.y;
692
+ const distance = Math.sqrt(dx * dx + dy * dy);
693
+ const shortenBy = configValues.nodeRadius + 2;
694
+ const adjustedX2 = distance > shortenBy ? targetX - dx / distance * shortenBy : targetX;
695
+ const adjustedY2 = distance > shortenBy ? targetY - dy / distance * shortenBy : targetY;
696
+ return {
697
+ origin,
698
+ targetX,
699
+ targetY,
700
+ adjustedX2,
701
+ adjustedY2
702
+ };
703
+ }).filter((trend) => trend !== null);
704
+ trendGroup.selectAll("line").data(trendsWithPositions).enter().append("line").attr("class", "wardley-trend").attr("x1", (trend) => trend.origin.x).attr("y1", (trend) => trend.origin.y).attr("x2", (trend) => trend.adjustedX2).attr("y2", (trend) => trend.adjustedY2).attr("stroke", theme.evolutionStroke).attr("stroke-width", 1).attr("stroke-dasharray", "4 4").attr("marker-end", `url(#arrow-${id})`);
705
+ const nodesGroup = root.append("g").attr("class", "wardley-nodes");
706
+ const nodeEnter = nodesGroup.selectAll("g").data(data.nodes).enter().append("g").attr(
707
+ "class",
708
+ (node) => ["wardley-node", node.className ? `wardley-node--${node.className}` : ""].filter(Boolean).join(" ")
709
+ );
710
+ nodeEnter.filter((node) => node.sourceStrategy === "outsource").append("circle").attr("class", "wardley-outsource-overlay").attr("cx", (node) => positions.get(node.id).x).attr("cy", (node) => positions.get(node.id).y).attr("r", configValues.nodeRadius * 2).attr("fill", "#666").attr("stroke", theme.componentStroke).attr("stroke-width", 1);
711
+ nodeEnter.filter((node) => node.sourceStrategy === "buy").append("circle").attr("class", "wardley-buy-overlay").attr("cx", (node) => positions.get(node.id).x).attr("cy", (node) => positions.get(node.id).y).attr("r", configValues.nodeRadius * 2).attr("fill", "#ccc").attr("stroke", theme.componentStroke).attr("stroke-width", 1);
712
+ nodeEnter.filter((node) => node.sourceStrategy === "build").append("circle").attr("class", "wardley-build-overlay").attr("cx", (node) => positions.get(node.id).x).attr("cy", (node) => positions.get(node.id).y).attr("r", configValues.nodeRadius * 2).attr("fill", "#eee").attr("stroke", "#000").attr("stroke-width", 1);
713
+ const marketNodes = nodeEnter.filter((node) => node.sourceStrategy === "market");
714
+ marketNodes.append("circle").attr("class", "wardley-market-overlay").attr("cx", (node) => positions.get(node.id).x).attr("cy", (node) => positions.get(node.id).y).attr("r", configValues.nodeRadius * 2).attr("fill", "white").attr("stroke", theme.componentStroke).attr("stroke-width", 1);
715
+ nodeEnter.filter(
716
+ (node) => !node.isPipelineParent && node.sourceStrategy !== "market" && node.className !== "anchor"
717
+ ).append("circle").attr("cx", (node) => positions.get(node.id).x).attr("cy", (node) => positions.get(node.id).y).attr("r", configValues.nodeRadius).attr("fill", theme.componentFill).attr("stroke", theme.componentStroke).attr("stroke-width", 1);
718
+ const smallCircleRadius = configValues.nodeRadius * 0.7;
719
+ const triangleRadius = configValues.nodeRadius * 1.2;
720
+ marketNodes.append("line").attr("class", "wardley-market-line").attr("x1", (node) => positions.get(node.id).x).attr("y1", (node) => positions.get(node.id).y - triangleRadius).attr("x2", (node) => positions.get(node.id).x - triangleRadius * Math.cos(Math.PI / 6)).attr("y2", (node) => positions.get(node.id).y + triangleRadius * Math.sin(Math.PI / 6)).attr("stroke", theme.componentStroke).attr("stroke-width", 1);
721
+ marketNodes.append("line").attr("class", "wardley-market-line").attr("x1", (node) => positions.get(node.id).x - triangleRadius * Math.cos(Math.PI / 6)).attr("y1", (node) => positions.get(node.id).y + triangleRadius * Math.sin(Math.PI / 6)).attr("x2", (node) => positions.get(node.id).x + triangleRadius * Math.cos(Math.PI / 6)).attr("y2", (node) => positions.get(node.id).y + triangleRadius * Math.sin(Math.PI / 6)).attr("stroke", theme.componentStroke).attr("stroke-width", 1);
722
+ marketNodes.append("line").attr("class", "wardley-market-line").attr("x1", (node) => positions.get(node.id).x + triangleRadius * Math.cos(Math.PI / 6)).attr("y1", (node) => positions.get(node.id).y + triangleRadius * Math.sin(Math.PI / 6)).attr("x2", (node) => positions.get(node.id).x).attr("y2", (node) => positions.get(node.id).y - triangleRadius).attr("stroke", theme.componentStroke).attr("stroke-width", 1);
723
+ marketNodes.append("circle").attr("class", "wardley-market-dot").attr("cx", (node) => positions.get(node.id).x).attr("cy", (node) => positions.get(node.id).y - triangleRadius).attr("r", smallCircleRadius).attr("fill", "white").attr("stroke", theme.componentStroke).attr("stroke-width", 2);
724
+ marketNodes.append("circle").attr("class", "wardley-market-dot").attr("cx", (node) => positions.get(node.id).x - triangleRadius * Math.cos(Math.PI / 6)).attr("cy", (node) => positions.get(node.id).y + triangleRadius * Math.sin(Math.PI / 6)).attr("r", smallCircleRadius).attr("fill", "white").attr("stroke", theme.componentStroke).attr("stroke-width", 2);
725
+ marketNodes.append("circle").attr("class", "wardley-market-dot").attr("cx", (node) => positions.get(node.id).x + triangleRadius * Math.cos(Math.PI / 6)).attr("cy", (node) => positions.get(node.id).y + triangleRadius * Math.sin(Math.PI / 6)).attr("r", smallCircleRadius).attr("fill", "white").attr("stroke", theme.componentStroke).attr("stroke-width", 2);
726
+ nodeEnter.filter((node) => node.isPipelineParent === true).append("rect").attr("x", (node) => positions.get(node.id).x - squareSize / 2).attr("y", (node) => positions.get(node.id).y - squareSize / 2).attr("width", squareSize).attr("height", squareSize).attr("fill", theme.componentFill).attr("stroke", theme.componentStroke).attr("stroke-width", 1);
727
+ nodeEnter.filter((node) => node.inertia === true).append("line").attr("class", "wardley-inertia").attr("x1", (node) => {
728
+ const pos = positions.get(node.id);
729
+ let offset = node.isPipelineParent ? squareSize / 2 + 15 : configValues.nodeRadius + 15;
730
+ if (node.sourceStrategy) {
731
+ offset += configValues.nodeRadius + 10;
732
+ }
733
+ return pos.x + offset;
734
+ }).attr("y1", (node) => {
735
+ const pos = positions.get(node.id);
736
+ const lineHeight = node.isPipelineParent ? squareSize : configValues.nodeRadius * 2;
737
+ return pos.y - lineHeight / 2;
738
+ }).attr("x2", (node) => {
739
+ const pos = positions.get(node.id);
740
+ let offset = node.isPipelineParent ? squareSize / 2 + 15 : configValues.nodeRadius + 15;
741
+ if (node.sourceStrategy) {
742
+ offset += configValues.nodeRadius + 10;
743
+ }
744
+ return pos.x + offset;
745
+ }).attr("y2", (node) => {
746
+ const pos = positions.get(node.id);
747
+ const lineHeight = node.isPipelineParent ? squareSize : configValues.nodeRadius * 2;
748
+ return pos.y + lineHeight / 2;
749
+ }).attr("stroke", theme.componentStroke).attr("stroke-width", 6);
750
+ nodeEnter.append("text").attr("x", (node) => {
751
+ const pos = positions.get(node.id);
752
+ if (node.className === "anchor") {
753
+ return node.labelOffsetX !== void 0 ? pos.x + node.labelOffsetX : pos.x;
754
+ }
755
+ let defaultOffset = configValues.nodeLabelOffset;
756
+ if (node.sourceStrategy && node.labelOffsetX === void 0) {
757
+ defaultOffset += 10;
758
+ }
759
+ const customOffset = node.labelOffsetX ?? defaultOffset;
760
+ return pos.x + customOffset;
761
+ }).attr("y", (node) => {
762
+ const pos = positions.get(node.id);
763
+ if (node.className === "anchor") {
764
+ return node.labelOffsetY !== void 0 ? pos.y + node.labelOffsetY : pos.y - 3;
765
+ }
766
+ let defaultOffset = -configValues.nodeLabelOffset;
767
+ if (node.sourceStrategy && node.labelOffsetY === void 0) {
768
+ defaultOffset -= 10;
769
+ }
770
+ const customOffset = node.labelOffsetY ?? defaultOffset;
771
+ return pos.y + customOffset;
772
+ }).attr("class", "wardley-node-label").attr("fill", (node) => {
773
+ if (node.className === "evolved") {
774
+ return theme.evolutionStroke;
775
+ }
776
+ if (node.className === "anchor") {
777
+ return "#000";
778
+ }
779
+ return theme.componentLabelColor;
780
+ }).attr("font-size", configValues.labelFontSize).attr("font-weight", (node) => node.className === "anchor" ? "bold" : "normal").attr("text-anchor", (node) => node.className === "anchor" ? "middle" : "start").attr("dominant-baseline", (node) => node.className === "anchor" ? "middle" : "auto").text((node) => node.label);
781
+ if (data.annotations.length > 0) {
782
+ const annotationsGroup = root.append("g").attr("class", "wardley-annotations");
783
+ data.annotations.forEach((annotation) => {
784
+ const projectedCoords = annotation.coordinates.map((coord) => ({
785
+ x: projectX(coord.x),
786
+ y: projectY(coord.y)
787
+ }));
788
+ if (projectedCoords.length > 1) {
789
+ for (let i = 0; i < projectedCoords.length - 1; i++) {
790
+ annotationsGroup.append("line").attr("class", "wardley-annotation-line").attr("x1", projectedCoords[i].x).attr("y1", projectedCoords[i].y).attr("x2", projectedCoords[i + 1].x).attr("y2", projectedCoords[i + 1].y).attr("stroke", theme.axisColor).attr("stroke-width", 1.5).attr("stroke-dasharray", "4 4");
791
+ }
792
+ }
793
+ projectedCoords.forEach((coord) => {
794
+ const annotationNode = annotationsGroup.append("g").attr("class", "wardley-annotation");
795
+ annotationNode.append("circle").attr("cx", coord.x).attr("cy", coord.y).attr("r", 10).attr("fill", "white").attr("stroke", theme.axisColor).attr("stroke-width", 1.5);
796
+ annotationNode.append("text").attr("x", coord.x).attr("y", coord.y).attr("text-anchor", "middle").attr("dominant-baseline", "central").attr("font-size", 10).attr("fill", theme.axisTextColor).attr("font-weight", "bold").text(annotation.number);
797
+ });
798
+ });
799
+ if (data.annotationsBox) {
800
+ let boxX = projectX(data.annotationsBox.x);
801
+ let boxY = projectY(data.annotationsBox.y);
802
+ const padding = 10;
803
+ const lineHeight = 16;
804
+ const fontSize = 11;
805
+ const textBoxGroup = annotationsGroup.append("g").attr("class", "wardley-annotations-box");
806
+ const sortedAnnotations = [...data.annotations].filter((a) => a.text).sort((a, b) => a.number - b.number);
807
+ const textElements = [];
808
+ sortedAnnotations.forEach((annotation, idx) => {
809
+ const text2 = textBoxGroup.append("text").attr("x", boxX + padding).attr("y", boxY + padding + (idx + 1) * lineHeight).attr("font-size", fontSize).attr("fill", theme.axisTextColor).attr("text-anchor", "start").attr("dominant-baseline", "middle").text(`${annotation.number}. ${annotation.text}`);
810
+ textElements.push(text2);
811
+ });
812
+ if (textElements.length > 0) {
813
+ let maxWidth = 0;
814
+ let maxHeight = 0;
815
+ textElements.forEach((text2) => {
816
+ const textNode = text2.node();
817
+ const textWidth = textNode.getComputedTextLength();
818
+ maxWidth = Math.max(maxWidth, textWidth);
819
+ const bbox = textNode.getBBox();
820
+ maxHeight = Math.max(maxHeight, bbox.height);
821
+ });
822
+ const boxWidth = maxWidth + padding * 2 + 105;
823
+ const boxHeight = sortedAnnotations.length * lineHeight + padding * 2 + maxHeight / 2;
824
+ const minX = configValues.padding;
825
+ const maxX = width - configValues.padding - boxWidth;
826
+ const minY = configValues.padding;
827
+ const maxY = height - configValues.padding - boxHeight;
828
+ boxX = Math.max(minX, Math.min(boxX, maxX));
829
+ boxY = Math.max(minY, Math.min(boxY, maxY));
830
+ textElements.forEach((text2, idx) => {
831
+ text2.attr("x", boxX + padding).attr("y", boxY + padding + (idx + 1) * lineHeight);
832
+ });
833
+ textBoxGroup.insert("rect", "text").attr("x", boxX).attr("y", boxY).attr("width", boxWidth).attr("height", boxHeight).attr("fill", "white").attr("stroke", theme.axisColor).attr("stroke-width", 1.5).attr("rx", 4).attr("ry", 4);
834
+ }
835
+ }
836
+ }
837
+ if (data.notes.length > 0) {
838
+ const notesGroup = root.append("g").attr("class", "wardley-notes");
839
+ data.notes.forEach((note) => {
840
+ const noteX = projectX(note.x);
841
+ const noteY = projectY(note.y);
842
+ notesGroup.append("text").attr("x", noteX).attr("y", noteY).attr("text-anchor", "start").attr("font-size", 11).attr("fill", theme.axisTextColor).attr("font-weight", "bold").text(note.text);
843
+ });
844
+ }
845
+ if (data.accelerators.length > 0) {
846
+ const acceleratorsGroup = root.append("g").attr("class", "wardley-accelerators");
847
+ data.accelerators.forEach((accelerator) => {
848
+ const accX = projectX(accelerator.x);
849
+ const accY = projectY(accelerator.y);
850
+ const arrowWidth = 60;
851
+ const arrowHeight = 30;
852
+ const arrowHeadWidth = 20;
853
+ const arrowPath = `
854
+ M ${accX} ${accY - arrowHeight / 2}
855
+ L ${accX + arrowWidth - arrowHeadWidth} ${accY - arrowHeight / 2}
856
+ L ${accX + arrowWidth - arrowHeadWidth} ${accY - arrowHeight / 2 - 8}
857
+ L ${accX + arrowWidth} ${accY}
858
+ L ${accX + arrowWidth - arrowHeadWidth} ${accY + arrowHeight / 2 + 8}
859
+ L ${accX + arrowWidth - arrowHeadWidth} ${accY + arrowHeight / 2}
860
+ L ${accX} ${accY + arrowHeight / 2}
861
+ Z
862
+ `;
863
+ acceleratorsGroup.append("path").attr("d", arrowPath).attr("fill", "white").attr("stroke", theme.componentStroke).attr("stroke-width", 1);
864
+ acceleratorsGroup.append("text").attr("x", accX + arrowWidth / 2).attr("y", accY + arrowHeight / 2 + 15).attr("text-anchor", "middle").attr("font-size", 10).attr("fill", theme.axisTextColor).attr("font-weight", "bold").text(accelerator.name);
865
+ });
866
+ }
867
+ if (data.deaccelerators.length > 0) {
868
+ const deacceleratorsGroup = root.append("g").attr("class", "wardley-deaccelerators");
869
+ data.deaccelerators.forEach((deaccelerator) => {
870
+ const decX = projectX(deaccelerator.x);
871
+ const decY = projectY(deaccelerator.y);
872
+ const arrowWidth = 60;
873
+ const arrowHeight = 30;
874
+ const arrowHeadWidth = 20;
875
+ const arrowPath = `
876
+ M ${decX + arrowWidth} ${decY - arrowHeight / 2}
877
+ L ${decX + arrowHeadWidth} ${decY - arrowHeight / 2}
878
+ L ${decX + arrowHeadWidth} ${decY - arrowHeight / 2 - 8}
879
+ L ${decX} ${decY}
880
+ L ${decX + arrowHeadWidth} ${decY + arrowHeight / 2 + 8}
881
+ L ${decX + arrowHeadWidth} ${decY + arrowHeight / 2}
882
+ L ${decX + arrowWidth} ${decY + arrowHeight / 2}
883
+ Z
884
+ `;
885
+ deacceleratorsGroup.append("path").attr("d", arrowPath).attr("fill", "white").attr("stroke", theme.componentStroke).attr("stroke-width", 1);
886
+ deacceleratorsGroup.append("text").attr("x", decX + arrowWidth / 2).attr("y", decY + arrowHeight / 2 + 15).attr("text-anchor", "middle").attr("font-size", 10).attr("fill", theme.axisTextColor).attr("font-weight", "bold").text(deaccelerator.name);
887
+ });
888
+ }
889
+ }, "draw");
890
+ var wardleyRenderer_default = {
891
+ draw
892
+ };
893
+ var diagram = {
894
+ parser,
895
+ db: wardleyDb_default,
896
+ renderer: wardleyRenderer_default,
897
+ styles: /* @__PURE__ */ __name(() => "", "styles")
898
+ };
899
+ export {
900
+ diagram
901
+ };