archimaid 0.0.0-stage → 0.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.
- package/CHANGELOG.md +32 -0
- package/FOUNDATION.md +108 -0
- package/LICENSE +21 -0
- package/README.md +271 -2
- package/dist/archimate/catalogue.d.ts +106 -0
- package/dist/archimate/catalogue.js +219 -0
- package/dist/archimate/catalogue.js.map +1 -0
- package/dist/archimate/diagnostics.d.ts +48 -0
- package/dist/archimate/diagnostics.js +64 -0
- package/dist/archimate/diagnostics.js.map +1 -0
- package/dist/archimate/frontmatter.d.ts +13 -0
- package/dist/archimate/frontmatter.js +62 -0
- package/dist/archimate/frontmatter.js.map +1 -0
- package/dist/archimate/grammar.d.ts +60 -0
- package/dist/archimate/grammar.js +273 -0
- package/dist/archimate/grammar.js.map +1 -0
- package/dist/archimate/lexer.d.ts +91 -0
- package/dist/archimate/lexer.js +215 -0
- package/dist/archimate/lexer.js.map +1 -0
- package/dist/archimate/model.d.ts +46 -0
- package/dist/archimate/model.js +2 -0
- package/dist/archimate/model.js.map +1 -0
- package/dist/archimate/nesting.d.ts +14 -0
- package/dist/archimate/nesting.js +84 -0
- package/dist/archimate/nesting.js.map +1 -0
- package/dist/archimate/parser.d.ts +14 -0
- package/dist/archimate/parser.js +53 -0
- package/dist/archimate/parser.js.map +1 -0
- package/dist/archimate/suggestions.d.ts +1 -0
- package/dist/archimate/suggestions.js +44 -0
- package/dist/archimate/suggestions.js.map +1 -0
- package/dist/archimate/validate.d.ts +4 -0
- package/dist/archimate/validate.js +402 -0
- package/dist/archimate/validate.js.map +1 -0
- package/dist/bundle/archimaid.esm.min.mjs +1 -0
- package/dist/bundle/chunks/archimateDiagram-WUCF6KHR.mjs +132 -0
- package/dist/bundle/chunks/chunk-QBMRZFD3.mjs +1 -0
- package/dist/bundle/chunks/elk.bundled-2VSLVJGB.mjs +26 -0
- package/dist/cli/render.d.ts +10 -0
- package/dist/cli/render.js +102 -0
- package/dist/cli/render.js.map +1 -0
- package/dist/cli/report.d.ts +20 -0
- package/dist/cli/report.js +39 -0
- package/dist/cli/report.js.map +1 -0
- package/dist/cli/sources.d.ts +19 -0
- package/dist/cli/sources.js +86 -0
- package/dist/cli/sources.js.map +1 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +137 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/language.d.ts +5 -0
- package/dist/language.js +3 -0
- package/dist/language.js.map +1 -0
- package/dist/mermaid/archimateDetector.d.ts +12 -0
- package/dist/mermaid/archimateDetector.js +29 -0
- package/dist/mermaid/archimateDetector.js.map +1 -0
- package/dist/mermaid/archimateDiagram.d.ts +9 -0
- package/dist/mermaid/archimateDiagram.js +75 -0
- package/dist/mermaid/archimateDiagram.js.map +1 -0
- package/dist/mermaid/archimateRenderer.d.ts +6 -0
- package/dist/mermaid/archimateRenderer.js +40 -0
- package/dist/mermaid/archimateRenderer.js.map +1 -0
- package/dist/mermaid/architectureLayout.d.ts +50 -0
- package/dist/mermaid/architectureLayout.js +144 -0
- package/dist/mermaid/architectureLayout.js.map +1 -0
- package/dist/mermaid/geometry.d.ts +3 -0
- package/dist/mermaid/geometry.js +20 -0
- package/dist/mermaid/geometry.js.map +1 -0
- package/dist/mermaid/hierarchy.d.ts +1 -0
- package/dist/mermaid/hierarchy.js +8 -0
- package/dist/mermaid/hierarchy.js.map +1 -0
- package/dist/mermaid/invariant.d.ts +1 -0
- package/dist/mermaid/invariant.js +7 -0
- package/dist/mermaid/invariant.js.map +1 -0
- package/dist/mermaid/orthogonalRouter.d.ts +4 -0
- package/dist/mermaid/orthogonalRouter.js +249 -0
- package/dist/mermaid/orthogonalRouter.js.map +1 -0
- package/dist/mermaid/relationshipPlacement.d.ts +3 -0
- package/dist/mermaid/relationshipPlacement.js +350 -0
- package/dist/mermaid/relationshipPlacement.js.map +1 -0
- package/dist/mermaid/render/draw.d.ts +17 -0
- package/dist/mermaid/render/draw.js +275 -0
- package/dist/mermaid/render/draw.js.map +1 -0
- package/dist/mermaid/render/elkRoutes.d.ts +6 -0
- package/dist/mermaid/render/elkRoutes.js +216 -0
- package/dist/mermaid/render/elkRoutes.js.map +1 -0
- package/dist/mermaid/render/graph.d.ts +17 -0
- package/dist/mermaid/render/graph.js +200 -0
- package/dist/mermaid/render/graph.js.map +1 -0
- package/dist/mermaid/render/labels.d.ts +12 -0
- package/dist/mermaid/render/labels.js +148 -0
- package/dist/mermaid/render/labels.js.map +1 -0
- package/dist/mermaid/render/layout.d.ts +12 -0
- package/dist/mermaid/render/layout.js +60 -0
- package/dist/mermaid/render/layout.js.map +1 -0
- package/dist/mermaid/render/measure.d.ts +16 -0
- package/dist/mermaid/render/measure.js +96 -0
- package/dist/mermaid/render/measure.js.map +1 -0
- package/dist/mermaid/render/place.d.ts +20 -0
- package/dist/mermaid/render/place.js +63 -0
- package/dist/mermaid/render/place.js.map +1 -0
- package/dist/mermaid/render/route.d.ts +29 -0
- package/dist/mermaid/render/route.js +113 -0
- package/dist/mermaid/render/route.js.map +1 -0
- package/dist/mermaid/render/shared.d.ts +83 -0
- package/dist/mermaid/render/shared.js +52 -0
- package/dist/mermaid/render/shared.js.map +1 -0
- package/dist/mermaid/render/svg.d.ts +6 -0
- package/dist/mermaid/render/svg.js +33 -0
- package/dist/mermaid/render/svg.js.map +1 -0
- package/dist/mermaid/render/viewport.d.ts +14 -0
- package/dist/mermaid/render/viewport.js +58 -0
- package/dist/mermaid/render/viewport.js.map +1 -0
- package/dist/mermaid/routing/anchors.d.ts +14 -0
- package/dist/mermaid/routing/anchors.js +134 -0
- package/dist/mermaid/routing/anchors.js.map +1 -0
- package/dist/mermaid/routing/bundles.d.ts +14 -0
- package/dist/mermaid/routing/bundles.js +94 -0
- package/dist/mermaid/routing/bundles.js.map +1 -0
- package/dist/mermaid/routing/congestion.d.ts +8 -0
- package/dist/mermaid/routing/congestion.js +70 -0
- package/dist/mermaid/routing/congestion.js.map +1 -0
- package/dist/mermaid/routing/constants.d.ts +13 -0
- package/dist/mermaid/routing/constants.js +17 -0
- package/dist/mermaid/routing/constants.js.map +1 -0
- package/dist/mermaid/routing/primitives.d.ts +33 -0
- package/dist/mermaid/routing/primitives.js +110 -0
- package/dist/mermaid/routing/primitives.js.map +1 -0
- package/dist/mermaid/routing/search.d.ts +4 -0
- package/dist/mermaid/routing/search.js +171 -0
- package/dist/mermaid/routing/search.js.map +1 -0
- package/dist/mermaid/routing/shapes.d.ts +8 -0
- package/dist/mermaid/routing/shapes.js +82 -0
- package/dist/mermaid/routing/shapes.js.map +1 -0
- package/dist/mermaid/routing/types.d.ts +37 -0
- package/dist/mermaid/routing/types.js +14 -0
- package/dist/mermaid/routing/types.js.map +1 -0
- package/dist/mermaid/styles.d.ts +89 -0
- package/dist/mermaid/styles.js +166 -0
- package/dist/mermaid/styles.js.map +1 -0
- package/docs/reference.md +86 -0
- package/examples/cross-layer-relationships.mmd +79 -0
- package/examples/cross-layer-relationships.svg +33 -0
- package/examples/element-preview.svg +1 -0
- package/examples/nested-components.mmd +21 -0
- package/examples/nested-components.svg +4 -0
- package/examples/order-fulfilment.mmd +10 -0
- package/examples/order-management.mmd +15 -0
- package/examples/order-management.svg +2 -0
- package/package.json +91 -4
- package/skills/archimaid/SKILL.md +123 -0
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { bendCost, leadLength } from './constants.js';
|
|
2
|
+
export function otherAxis(axis) {
|
|
3
|
+
return axis === 'x' ? 'y' : 'x';
|
|
4
|
+
}
|
|
5
|
+
export function bounds(box, padding = 0) {
|
|
6
|
+
return {
|
|
7
|
+
left: box.x - padding,
|
|
8
|
+
right: box.x + box.width + padding,
|
|
9
|
+
top: box.y - padding,
|
|
10
|
+
bottom: box.y + box.height + padding,
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
// Strict comparisons treat a segment on an obstacle's boundary as clear; the renderer's entersBox() differs.
|
|
14
|
+
export function crosses(start, end, obstacles) {
|
|
15
|
+
if (start.y === end.y) {
|
|
16
|
+
const left = Math.min(start.x, end.x);
|
|
17
|
+
const right = Math.max(start.x, end.x);
|
|
18
|
+
return obstacles.some((box) => box.top < start.y && start.y < box.bottom && left < box.right && right > box.left);
|
|
19
|
+
}
|
|
20
|
+
const top = Math.min(start.y, end.y);
|
|
21
|
+
const bottom = Math.max(start.y, end.y);
|
|
22
|
+
return obstacles.some((box) => box.left < start.x && start.x < box.right && top < box.bottom && bottom > box.top);
|
|
23
|
+
}
|
|
24
|
+
export function ports(box, fraction, inside) {
|
|
25
|
+
const insetX = Math.min(leadLength, box.width / 4);
|
|
26
|
+
const insetY = Math.min(leadLength, box.height / 4);
|
|
27
|
+
const x = box.x + insetX + fraction * (box.width - 2 * insetX);
|
|
28
|
+
const y = box.y + insetY + fraction * (box.height - 2 * insetY);
|
|
29
|
+
const right = box.x + box.width;
|
|
30
|
+
const bottom = box.y + box.height;
|
|
31
|
+
const lead = inside ? -leadLength : leadLength;
|
|
32
|
+
const choices = [
|
|
33
|
+
{ anchor: { x, y: bottom }, lead: { x, y: bottom + lead }, axis: 'y', cost: 0 },
|
|
34
|
+
{ anchor: { x: box.x, y }, lead: { x: box.x - lead, y }, axis: 'x', cost: 0 },
|
|
35
|
+
{ anchor: { x: right, y }, lead: { x: right + lead, y }, axis: 'x', cost: 0 },
|
|
36
|
+
];
|
|
37
|
+
if (!inside)
|
|
38
|
+
choices.push({ anchor: { x, y: box.y }, lead: { x, y: box.y - lead }, axis: 'y', cost: 0 });
|
|
39
|
+
return choices;
|
|
40
|
+
}
|
|
41
|
+
export function firstAtLeast(sorted, value, strictlyAbove = false) {
|
|
42
|
+
let low = 0;
|
|
43
|
+
let high = sorted.length;
|
|
44
|
+
while (low < high) {
|
|
45
|
+
const middle = (low + high) >>> 1;
|
|
46
|
+
const candidate = sorted[middle] ?? Infinity;
|
|
47
|
+
if (candidate < value || (strictlyAbove && candidate === value))
|
|
48
|
+
low = middle + 1;
|
|
49
|
+
else
|
|
50
|
+
high = middle;
|
|
51
|
+
}
|
|
52
|
+
return low;
|
|
53
|
+
}
|
|
54
|
+
export function axisSize(box, axis) {
|
|
55
|
+
return axis === 'x' ? box.width : box.height;
|
|
56
|
+
}
|
|
57
|
+
export function pointDistance(a, b) {
|
|
58
|
+
return Math.hypot(a.x - b.x, a.y - b.y);
|
|
59
|
+
}
|
|
60
|
+
export const oppositeSide = { top: 'bottom', bottom: 'top', left: 'right', right: 'left' };
|
|
61
|
+
export function beyondSides(box, other) {
|
|
62
|
+
return {
|
|
63
|
+
top: other.y + other.height <= box.y,
|
|
64
|
+
bottom: other.y >= box.y + box.height,
|
|
65
|
+
left: other.x + other.width <= box.x,
|
|
66
|
+
right: other.x >= box.x + box.width,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
// Ports that face away from the other endpoint force a detour around their own element.
|
|
70
|
+
export function facing(candidates, box, other) {
|
|
71
|
+
const beyond = beyondSides(box, other);
|
|
72
|
+
const vertical = beyond.top || beyond.bottom;
|
|
73
|
+
return candidates.map((port) => {
|
|
74
|
+
const side = portSide(box, port.anchor);
|
|
75
|
+
// Layers stack vertically, so a horizontal exit toward another rank would claim the channel between ranks.
|
|
76
|
+
const cost = beyond[side]
|
|
77
|
+
? port.axis === 'x' && vertical
|
|
78
|
+
? bendCost
|
|
79
|
+
: 0
|
|
80
|
+
: beyond[oppositeSide[side]]
|
|
81
|
+
? 3 * bendCost
|
|
82
|
+
: bendCost;
|
|
83
|
+
return { ...port, cost };
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
export function portSide(box, point) {
|
|
87
|
+
if (point.x === box.x)
|
|
88
|
+
return 'left';
|
|
89
|
+
if (point.x === box.x + box.width)
|
|
90
|
+
return 'right';
|
|
91
|
+
return point.y === box.y ? 'top' : 'bottom';
|
|
92
|
+
}
|
|
93
|
+
export function centre(box) {
|
|
94
|
+
return { x: box.x + box.width / 2, y: box.y + box.height / 2 };
|
|
95
|
+
}
|
|
96
|
+
export function sidePort(box, side, position) {
|
|
97
|
+
const right = box.x + box.width;
|
|
98
|
+
const bottom = box.y + box.height;
|
|
99
|
+
switch (side) {
|
|
100
|
+
case 'top':
|
|
101
|
+
return { anchor: { x: position, y: box.y }, lead: { x: position, y: box.y - leadLength }, axis: 'y', cost: 0 };
|
|
102
|
+
case 'bottom':
|
|
103
|
+
return { anchor: { x: position, y: bottom }, lead: { x: position, y: bottom + leadLength }, axis: 'y', cost: 0 };
|
|
104
|
+
case 'left':
|
|
105
|
+
return { anchor: { x: box.x, y: position }, lead: { x: box.x - leadLength, y: position }, axis: 'x', cost: 0 };
|
|
106
|
+
case 'right':
|
|
107
|
+
return { anchor: { x: right, y: position }, lead: { x: right + leadLength, y: position }, axis: 'x', cost: 0 };
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
//# sourceMappingURL=primitives.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"primitives.js","sourceRoot":"","sources":["../../../src/mermaid/routing/primitives.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAiBtD,MAAM,UAAU,SAAS,CAAC,IAAU;IAClC,OAAO,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC;AAClC,CAAC;AAED,MAAM,UAAU,MAAM,CAAC,GAAQ,EAAE,OAAO,GAAG,CAAC;IAC1C,OAAO;QACL,IAAI,EAAE,GAAG,CAAC,CAAC,GAAG,OAAO;QACrB,KAAK,EAAE,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,KAAK,GAAG,OAAO;QAClC,GAAG,EAAE,GAAG,CAAC,CAAC,GAAG,OAAO;QACpB,MAAM,EAAE,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC,MAAM,GAAG,OAAO;KACrC,CAAC;AACJ,CAAC;AAED,6GAA6G;AAC7G,MAAM,UAAU,OAA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AAE,EAAE,IAAI,EAAE,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,MAAM,GAAG,UAAU,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC;QACnH,KAAK,MAAM;YACT,OAAO,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,QAAQ,EAAE,EAAE,IAAI,EAAE,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC,GAAG,UAAU,EAAE,CAAC,EAAE,QAAQ,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC;QACjH,KAAK,OAAO;YACV,OAAO,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,EAAE,IAAI,EAAE,EAAE,CAAC,EAAE,KAAK,GAAG,UAAU,EAAE,CAAC,EAAE,QAAQ,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC;IACnH,CAAC;AACH,CAAC","sourcesContent":["import type { Box, Point } from '../architectureLayout.js';\nimport { bendCost, leadLength } from './constants.js';\n\nexport type Axis = 'x' | 'y';\nexport interface Port {\n anchor: Point;\n lead: Point;\n axis: Axis;\n cost: number;\n}\n\nexport interface Bounds {\n left: number;\n right: number;\n top: number;\n bottom: number;\n}\n\nexport function otherAxis(axis: Axis): Axis {\n return axis === 'x' ? 'y' : 'x';\n}\n\nexport function bounds(box: Box, padding = 0): Bounds {\n return {\n left: box.x - padding,\n right: box.x + box.width + padding,\n top: box.y - padding,\n bottom: box.y + box.height + padding,\n };\n}\n\n// Strict comparisons treat a segment on an obstacle's boundary as clear; the renderer's entersBox() differs.\nexport function crosses(start: Point, end: Point, obstacles: readonly Bounds[]): boolean {\n if (start.y === end.y) {\n const left = Math.min(start.x, end.x);\n const right = Math.max(start.x, end.x);\n return obstacles.some((box) => box.top < start.y && start.y < box.bottom && left < box.right && right > box.left);\n }\n const top = Math.min(start.y, end.y);\n const bottom = Math.max(start.y, end.y);\n return obstacles.some((box) => box.left < start.x && start.x < box.right && top < box.bottom && bottom > box.top);\n}\n\nexport function ports(box: Box, fraction: number, inside: boolean): Port[] {\n const insetX = Math.min(leadLength, box.width / 4);\n const insetY = Math.min(leadLength, box.height / 4);\n const x = box.x + insetX + fraction * (box.width - 2 * insetX);\n const y = box.y + insetY + fraction * (box.height - 2 * insetY);\n const right = box.x + box.width;\n const bottom = box.y + box.height;\n const lead = inside ? -leadLength : leadLength;\n const choices: Port[] = [\n { anchor: { x, y: bottom }, lead: { x, y: bottom + lead }, axis: 'y', cost: 0 },\n { anchor: { x: box.x, y }, lead: { x: box.x - lead, y }, axis: 'x', cost: 0 },\n { anchor: { x: right, y }, lead: { x: right + lead, y }, axis: 'x', cost: 0 },\n ];\n if (!inside) choices.push({ anchor: { x, y: box.y }, lead: { x, y: box.y - lead }, axis: 'y', cost: 0 });\n return choices;\n}\n\nexport function firstAtLeast(sorted: ArrayLike<number>, value: number, strictlyAbove = false): number {\n let low = 0;\n let high = sorted.length;\n while (low < high) {\n const middle = (low + high) >>> 1;\n const candidate = sorted[middle] ?? Infinity;\n if (candidate < value || (strictlyAbove && candidate === value)) low = middle + 1;\n else high = middle;\n }\n return low;\n}\n\nexport function axisSize(box: Box, axis: Axis): number {\n return axis === 'x' ? box.width : box.height;\n}\n\nexport function pointDistance(a: Point, b: Point): number {\n return Math.hypot(a.x - b.x, a.y - b.y);\n}\n\nexport type Side = 'top' | 'bottom' | 'left' | 'right';\nexport const oppositeSide = { top: 'bottom', bottom: 'top', left: 'right', right: 'left' } satisfies Record<Side, Side>;\n\nexport function beyondSides(box: Box, other: Box): Record<Side, boolean> {\n return {\n top: other.y + other.height <= box.y,\n bottom: other.y >= box.y + box.height,\n left: other.x + other.width <= box.x,\n right: other.x >= box.x + box.width,\n };\n}\n\n// Ports that face away from the other endpoint force a detour around their own element.\nexport function facing(candidates: readonly Port[], box: Box, other: Box): Port[] {\n const beyond = beyondSides(box, other);\n const vertical = beyond.top || beyond.bottom;\n return candidates.map((port) => {\n const side = portSide(box, port.anchor);\n // Layers stack vertically, so a horizontal exit toward another rank would claim the channel between ranks.\n const cost = beyond[side]\n ? port.axis === 'x' && vertical\n ? bendCost\n : 0\n : beyond[oppositeSide[side]]\n ? 3 * bendCost\n : bendCost;\n return { ...port, cost };\n });\n}\n\nexport function portSide(box: Box, point: Point): Side {\n if (point.x === box.x) return 'left';\n if (point.x === box.x + box.width) return 'right';\n return point.y === box.y ? 'top' : 'bottom';\n}\n\nexport function centre(box: Box): Point {\n return { x: box.x + box.width / 2, y: box.y + box.height / 2 };\n}\n\nexport function sidePort(box: Box, side: Side, position: number): Port {\n const right = box.x + box.width;\n const bottom = box.y + box.height;\n switch (side) {\n case 'top':\n return { anchor: { x: position, y: box.y }, lead: { x: position, y: box.y - leadLength }, axis: 'y', cost: 0 };\n case 'bottom':\n return { anchor: { x: position, y: bottom }, lead: { x: position, y: bottom + leadLength }, axis: 'y', cost: 0 };\n case 'left':\n return { anchor: { x: box.x, y: position }, lead: { x: box.x - leadLength, y: position }, axis: 'x', cost: 0 };\n case 'right':\n return { anchor: { x: right, y: position }, lead: { x: right + leadLength, y: position }, axis: 'x', cost: 0 };\n }\n}\n"]}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Point } from '../architectureLayout.js';
|
|
2
|
+
import type { RouteCost } from './congestion.js';
|
|
3
|
+
import { type Bounds, type Port } from './primitives.js';
|
|
4
|
+
export declare function routeBetween(starts: readonly Port[], ends: readonly Port[], obstacles: readonly Bounds[], routeCost: RouteCost, region: Bounds | undefined): Point[] | undefined;
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { simplify } from '../geometry.js';
|
|
2
|
+
import { bendCost, heuristicWeight, leadLength } from './constants.js';
|
|
3
|
+
import { firstAtLeast } from './primitives.js';
|
|
4
|
+
function push(queue, state) {
|
|
5
|
+
let index = queue.length;
|
|
6
|
+
queue.push(state);
|
|
7
|
+
while (index > 0) {
|
|
8
|
+
const parent = Math.floor((index - 1) / 2);
|
|
9
|
+
const higher = queue[parent];
|
|
10
|
+
if (!higher || higher.priority <= state.priority)
|
|
11
|
+
break;
|
|
12
|
+
queue[index] = higher;
|
|
13
|
+
index = parent;
|
|
14
|
+
}
|
|
15
|
+
queue[index] = state;
|
|
16
|
+
}
|
|
17
|
+
function pop(queue) {
|
|
18
|
+
const first = queue[0];
|
|
19
|
+
const tail = queue.pop();
|
|
20
|
+
if (!tail || queue.length === 0)
|
|
21
|
+
return first;
|
|
22
|
+
let index = 0;
|
|
23
|
+
while (true) {
|
|
24
|
+
const left = index * 2 + 1;
|
|
25
|
+
const right = left + 1;
|
|
26
|
+
const leftState = queue[left];
|
|
27
|
+
const rightState = queue[right];
|
|
28
|
+
if (!leftState)
|
|
29
|
+
break;
|
|
30
|
+
const best = rightState && rightState.priority < leftState.priority ? right : left;
|
|
31
|
+
const next = queue[best];
|
|
32
|
+
if (!next || tail.priority <= next.priority)
|
|
33
|
+
break;
|
|
34
|
+
queue[index] = next;
|
|
35
|
+
index = best;
|
|
36
|
+
}
|
|
37
|
+
queue[index] = tail;
|
|
38
|
+
return first;
|
|
39
|
+
}
|
|
40
|
+
// Search only at ports and obstacle boundaries, where an orthogonal turn can clear a shape.
|
|
41
|
+
function buildGrid(leads, obstacles, region) {
|
|
42
|
+
function coordinates(axis, low, high) {
|
|
43
|
+
const values = leads.map((point) => point[axis]);
|
|
44
|
+
for (const box of obstacles)
|
|
45
|
+
values.push(box[low], box[high]);
|
|
46
|
+
const ordered = [...new Set(values)].sort((a, b) => a - b);
|
|
47
|
+
const first = ordered[0] ?? 0;
|
|
48
|
+
const last = ordered.at(-1) ?? 0;
|
|
49
|
+
const minimum = region?.[low] ?? first - leadLength;
|
|
50
|
+
const maximum = region?.[high] ?? last + leadLength;
|
|
51
|
+
return [...new Set([minimum, ...ordered, maximum])]
|
|
52
|
+
.filter((value) => value >= minimum && value <= maximum)
|
|
53
|
+
.sort((a, b) => a - b);
|
|
54
|
+
}
|
|
55
|
+
const xs = coordinates('x', 'left', 'right');
|
|
56
|
+
const ys = coordinates('y', 'top', 'bottom');
|
|
57
|
+
const blockers = { x: new Map(), y: new Map() };
|
|
58
|
+
return {
|
|
59
|
+
xs,
|
|
60
|
+
ys,
|
|
61
|
+
columns: new Map(xs.map((x, index) => [x, index])),
|
|
62
|
+
rows: new Map(ys.map((y, index) => [y, index])),
|
|
63
|
+
// Steps join neighbouring grid coordinates, so mark once per grid line which steps enter an obstacle.
|
|
64
|
+
blockedSteps(axis, across) {
|
|
65
|
+
const cached = blockers[axis].get(across);
|
|
66
|
+
if (cached)
|
|
67
|
+
return cached;
|
|
68
|
+
const values = axis === 'x' ? xs : ys;
|
|
69
|
+
const steps = new Uint8Array(Math.max(0, values.length - 1));
|
|
70
|
+
for (const box of obstacles) {
|
|
71
|
+
const [low, high, start, end] = axis === 'x' ? [box.left, box.right, box.top, box.bottom] : [box.top, box.bottom, box.left, box.right];
|
|
72
|
+
if (!(start < across && across < end))
|
|
73
|
+
continue;
|
|
74
|
+
steps.fill(1, Math.max(0, firstAtLeast(values, low, true) - 1), firstAtLeast(values, high));
|
|
75
|
+
}
|
|
76
|
+
blockers[axis].set(across, steps);
|
|
77
|
+
return steps;
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
export function routeBetween(starts, ends, obstacles, routeCost, region) {
|
|
82
|
+
if (!starts.length || !ends.length)
|
|
83
|
+
return undefined;
|
|
84
|
+
const { xs, ys, columns, rows, blockedSteps } = buildGrid([...starts, ...ends].map(({ lead }) => lead), obstacles, region);
|
|
85
|
+
const queue = [];
|
|
86
|
+
const distances = new Map();
|
|
87
|
+
const key = (column, row, axis) => (row * xs.length + column) * 2 + Number(axis === 'y');
|
|
88
|
+
function enqueue(column, row, axis, distance, previous, port) {
|
|
89
|
+
const x = xs[column];
|
|
90
|
+
const y = ys[row];
|
|
91
|
+
if (x === undefined || y === undefined)
|
|
92
|
+
return;
|
|
93
|
+
const id = key(column, row, axis);
|
|
94
|
+
if ((distances.get(id) ?? Infinity) <= distance)
|
|
95
|
+
return;
|
|
96
|
+
distances.set(id, distance);
|
|
97
|
+
let remaining = Infinity;
|
|
98
|
+
for (const { lead } of ends)
|
|
99
|
+
remaining = Math.min(remaining, Math.abs(x - lead.x) + Math.abs(y - lead.y));
|
|
100
|
+
push(queue, {
|
|
101
|
+
column,
|
|
102
|
+
row,
|
|
103
|
+
axis,
|
|
104
|
+
distance,
|
|
105
|
+
priority: distance + heuristicWeight * remaining,
|
|
106
|
+
...(previous && { previous }),
|
|
107
|
+
...(port && { port }),
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
for (const port of starts) {
|
|
111
|
+
const column = columns.get(port.lead.x);
|
|
112
|
+
const row = rows.get(port.lead.y);
|
|
113
|
+
if (column !== undefined && row !== undefined)
|
|
114
|
+
enqueue(column, row, port.axis, port.cost, undefined, port);
|
|
115
|
+
}
|
|
116
|
+
let best;
|
|
117
|
+
let state;
|
|
118
|
+
while ((state = pop(queue))) {
|
|
119
|
+
if (best && state.priority >= best.cost)
|
|
120
|
+
break;
|
|
121
|
+
if (state.distance !== distances.get(key(state.column, state.row, state.axis)))
|
|
122
|
+
continue;
|
|
123
|
+
const x = xs[state.column];
|
|
124
|
+
const y = ys[state.row];
|
|
125
|
+
if (x === undefined || y === undefined)
|
|
126
|
+
continue;
|
|
127
|
+
const point = { x, y };
|
|
128
|
+
for (const port of ends) {
|
|
129
|
+
if (port.lead.x !== x || port.lead.y !== y)
|
|
130
|
+
continue;
|
|
131
|
+
const cost = state.distance + port.cost + (port.axis === state.axis ? 0 : bendCost);
|
|
132
|
+
if (!best || cost < best.cost)
|
|
133
|
+
best = { state, port, cost };
|
|
134
|
+
}
|
|
135
|
+
const neighbors = [
|
|
136
|
+
[state.column - 1, state.row, 'x'],
|
|
137
|
+
[state.column + 1, state.row, 'x'],
|
|
138
|
+
[state.column, state.row - 1, 'y'],
|
|
139
|
+
[state.column, state.row + 1, 'y'],
|
|
140
|
+
];
|
|
141
|
+
for (const [column, row, axis] of neighbors) {
|
|
142
|
+
const nextX = xs[column];
|
|
143
|
+
const nextY = ys[row];
|
|
144
|
+
if (nextX === undefined || nextY === undefined)
|
|
145
|
+
continue;
|
|
146
|
+
const next = { x: nextX, y: nextY };
|
|
147
|
+
const step = axis === 'x' ? Math.min(column, state.column) : Math.min(row, state.row);
|
|
148
|
+
if (blockedSteps(axis, axis === 'x' ? y : x)[step])
|
|
149
|
+
continue;
|
|
150
|
+
const distance = state.distance +
|
|
151
|
+
Math.abs(point[axis] - next[axis]) +
|
|
152
|
+
(axis === state.axis ? 0 : bendCost) +
|
|
153
|
+
routeCost(axis, point, next);
|
|
154
|
+
enqueue(column, row, axis, distance, state);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
if (!best)
|
|
158
|
+
return undefined;
|
|
159
|
+
const points = [best.port.anchor];
|
|
160
|
+
for (let current = best.state; current; current = current.previous) {
|
|
161
|
+
const x = xs[current.column];
|
|
162
|
+
const y = ys[current.row];
|
|
163
|
+
if (x === undefined || y === undefined)
|
|
164
|
+
throw new Error('Invalid orthogonal routing point.');
|
|
165
|
+
points.push({ x, y });
|
|
166
|
+
if (current.port)
|
|
167
|
+
points.push(current.port.anchor);
|
|
168
|
+
}
|
|
169
|
+
return simplify(points.reverse());
|
|
170
|
+
}
|
|
171
|
+
//# sourceMappingURL=search.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search.js","sourceRoot":"","sources":["../../../src/mermaid/routing/search.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAEvE,OAAO,EAAE,YAAY,EAAqC,MAAM,iBAAiB,CAAC;A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ACtB,IAAI,OAAO,CAAC,IAAI;YAAE,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACrD,CAAC;IACD,OAAO,QAAQ,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC;AACpC,CAAC","sourcesContent":["import type { Point } from '../architectureLayout.js';\nimport { simplify } from '../geometry.js';\nimport { bendCost, heuristicWeight, leadLength } from './constants.js';\nimport type { RouteCost } from './congestion.js';\nimport { firstAtLeast, type Axis, type Bounds, type Port } from './primitives.js';\n\ninterface State {\n column: number;\n row: number;\n axis: Axis;\n distance: number;\n priority: number;\n previous?: State;\n port?: Port;\n}\n\nfunction push(queue: State[], state: State): void {\n let index = queue.length;\n queue.push(state);\n while (index > 0) {\n const parent = Math.floor((index - 1) / 2);\n const higher = queue[parent];\n if (!higher || higher.priority <= state.priority) break;\n queue[index] = higher;\n index = parent;\n }\n queue[index] = state;\n}\n\nfunction pop(queue: State[]): State | undefined {\n const first = queue[0];\n const tail = queue.pop();\n if (!tail || queue.length === 0) return first;\n let index = 0;\n while (true) {\n const left = index * 2 + 1;\n const right = left + 1;\n const leftState = queue[left];\n const rightState = queue[right];\n if (!leftState) break;\n const best = rightState && rightState.priority < leftState.priority ? right : left;\n const next = queue[best];\n if (!next || tail.priority <= next.priority) break;\n queue[index] = next;\n index = best;\n }\n queue[index] = tail;\n return first;\n}\n\ninterface Grid {\n readonly xs: readonly number[];\n readonly ys: readonly number[];\n readonly columns: ReadonlyMap<number, number>;\n readonly rows: ReadonlyMap<number, number>;\n readonly blockedSteps: (axis: Axis, across: number) => Uint8Array;\n}\n\n// Search only at ports and obstacle boundaries, where an orthogonal turn can clear a shape.\nfunction buildGrid(leads: readonly Point[], obstacles: readonly Bounds[], region: Bounds | undefined): Grid {\n function coordinates(axis: Axis, low: 'left' | 'top', high: 'right' | 'bottom'): number[] {\n const values = leads.map((point) => point[axis]);\n for (const box of obstacles) values.push(box[low], box[high]);\n const ordered = [...new Set(values)].sort((a, b) => a - b);\n const first = ordered[0] ?? 0;\n const last = ordered.at(-1) ?? 0;\n const minimum = region?.[low] ?? first - leadLength;\n const maximum = region?.[high] ?? last + leadLength;\n return [...new Set([minimum, ...ordered, maximum])]\n .filter((value) => value >= minimum && value <= maximum)\n .sort((a, b) => a - b);\n }\n const xs = coordinates('x', 'left', 'right');\n const ys = coordinates('y', 'top', 'bottom');\n const blockers: Record<Axis, Map<number, Uint8Array>> = { x: new Map(), y: new Map() };\n return {\n xs,\n ys,\n columns: new Map(xs.map((x, index) => [x, index])),\n rows: new Map(ys.map((y, index) => [y, index])),\n // Steps join neighbouring grid coordinates, so mark once per grid line which steps enter an obstacle.\n blockedSteps(axis, across) {\n const cached = blockers[axis].get(across);\n if (cached) return cached;\n const values = axis === 'x' ? xs : ys;\n const steps = new Uint8Array(Math.max(0, values.length - 1));\n for (const box of obstacles) {\n const [low, high, start, end] =\n axis === 'x' ? [box.left, box.right, box.top, box.bottom] : [box.top, box.bottom, box.left, box.right];\n if (!(start < across && across < end)) continue;\n steps.fill(1, Math.max(0, firstAtLeast(values, low, true) - 1), firstAtLeast(values, high));\n }\n blockers[axis].set(across, steps);\n return steps;\n },\n };\n}\n\nexport function routeBetween(\n starts: readonly Port[],\n ends: readonly Port[],\n obstacles: readonly Bounds[],\n routeCost: RouteCost,\n region: Bounds | undefined,\n): Point[] | undefined {\n if (!starts.length || !ends.length) return undefined;\n const { xs, ys, columns, rows, blockedSteps } = buildGrid(\n [...starts, ...ends].map(({ lead }) => lead),\n obstacles,\n region,\n );\n const queue: State[] = [];\n const distances = new Map<number, number>();\n const key = (column: number, row: number, axis: Axis) => (row * xs.length + column) * 2 + Number(axis === 'y');\n\n function enqueue(column: number, row: number, axis: Axis, distance: number, previous?: State, port?: Port): void {\n const x = xs[column];\n const y = ys[row];\n if (x === undefined || y === undefined) return;\n const id = key(column, row, axis);\n if ((distances.get(id) ?? Infinity) <= distance) return;\n distances.set(id, distance);\n let remaining = Infinity;\n for (const { lead } of ends) remaining = Math.min(remaining, Math.abs(x - lead.x) + Math.abs(y - lead.y));\n push(queue, {\n column,\n row,\n axis,\n distance,\n priority: distance + heuristicWeight * remaining,\n ...(previous && { previous }),\n ...(port && { port }),\n });\n }\n\n for (const port of starts) {\n const column = columns.get(port.lead.x);\n const row = rows.get(port.lead.y);\n if (column !== undefined && row !== undefined) enqueue(column, row, port.axis, port.cost, undefined, port);\n }\n let best: { state: State; port: Port; cost: number } | undefined;\n let state: State | undefined;\n while ((state = pop(queue))) {\n if (best && state.priority >= best.cost) break;\n if (state.distance !== distances.get(key(state.column, state.row, state.axis))) continue;\n const x = xs[state.column];\n const y = ys[state.row];\n if (x === undefined || y === undefined) continue;\n const point = { x, y };\n for (const port of ends) {\n if (port.lead.x !== x || port.lead.y !== y) continue;\n const cost = state.distance + port.cost + (port.axis === state.axis ? 0 : bendCost);\n if (!best || cost < best.cost) best = { state, port, cost };\n }\n const neighbors = [\n [state.column - 1, state.row, 'x'],\n [state.column + 1, state.row, 'x'],\n [state.column, state.row - 1, 'y'],\n [state.column, state.row + 1, 'y'],\n ] as const;\n for (const [column, row, axis] of neighbors) {\n const nextX = xs[column];\n const nextY = ys[row];\n if (nextX === undefined || nextY === undefined) continue;\n const next = { x: nextX, y: nextY };\n const step = axis === 'x' ? Math.min(column, state.column) : Math.min(row, state.row);\n if (blockedSteps(axis, axis === 'x' ? y : x)[step]) continue;\n const distance =\n state.distance +\n Math.abs(point[axis] - next[axis]) +\n (axis === state.axis ? 0 : bendCost) +\n routeCost(axis, point, next);\n enqueue(column, row, axis, distance, state);\n }\n }\n\n if (!best) return undefined;\n const points = [best.port.anchor];\n for (let current: State | undefined = best.state; current; current = current.previous) {\n const x = xs[current.column];\n const y = ys[current.row];\n if (x === undefined || y === undefined) throw new Error('Invalid orthogonal routing point.');\n points.push({ x, y });\n if (current.port) points.push(current.port.anchor);\n }\n return simplify(points.reverse());\n}\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Box, Point } from '../architectureLayout.js';
|
|
2
|
+
import type { RouteCost } from './congestion.js';
|
|
3
|
+
import { type Bounds } from './primitives.js';
|
|
4
|
+
export declare function straightRoute(source: Box, target: Box, obstacles: readonly Bounds[], routeCost: RouteCost, available: (from: Point, to: Point) => boolean, { gap, parallel }: {
|
|
5
|
+
gap: number;
|
|
6
|
+
parallel: number;
|
|
7
|
+
}): Point[] | undefined;
|
|
8
|
+
export declare function loopCandidates(box: Box, lane: number): Point[][];
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { leadLength, loopReach, trackGap } from './constants.js';
|
|
2
|
+
import { axisSize, crosses, otherAxis } from './primitives.js';
|
|
3
|
+
export function straightRoute(source, target, obstacles, routeCost, available, { gap, parallel }) {
|
|
4
|
+
for (const axis of ['x', 'y']) {
|
|
5
|
+
const across = otherAxis(axis);
|
|
6
|
+
const sourceSize = axisSize(source, across);
|
|
7
|
+
const targetSize = axisSize(target, across);
|
|
8
|
+
const sourceInset = Math.min(leadLength, sourceSize / 4);
|
|
9
|
+
const targetInset = Math.min(leadLength, targetSize / 4);
|
|
10
|
+
const low = Math.max(source[across] + sourceInset, target[across] + targetInset);
|
|
11
|
+
const high = Math.min(source[across] + sourceSize - sourceInset, target[across] + targetSize - targetInset);
|
|
12
|
+
if (high < low)
|
|
13
|
+
continue;
|
|
14
|
+
const forward = source[axis] < target[axis];
|
|
15
|
+
const start = forward ? source[axis] + axisSize(source, axis) : source[axis];
|
|
16
|
+
const end = forward ? target[axis] : target[axis] + axisSize(target, axis);
|
|
17
|
+
if ((forward ? end - start : start - end) < leadLength)
|
|
18
|
+
continue;
|
|
19
|
+
const middle = (low + high) / 2;
|
|
20
|
+
// Relationships between the same pair share the overlap evenly, outward from its middle.
|
|
21
|
+
const spacing = Math.max(gap, (high - low) / (parallel + 1));
|
|
22
|
+
const spread = parallel > 1
|
|
23
|
+
? Array.from({ length: parallel }, (_, index) => index + 1).flatMap((step) => [
|
|
24
|
+
middle - step * spacing,
|
|
25
|
+
middle + step * spacing,
|
|
26
|
+
])
|
|
27
|
+
: [];
|
|
28
|
+
const candidates = [
|
|
29
|
+
middle,
|
|
30
|
+
source[across] + sourceSize / 2,
|
|
31
|
+
target[across] + targetSize / 2,
|
|
32
|
+
...spread,
|
|
33
|
+
middle - gap,
|
|
34
|
+
middle + gap,
|
|
35
|
+
low,
|
|
36
|
+
high,
|
|
37
|
+
];
|
|
38
|
+
for (const coordinate of candidates) {
|
|
39
|
+
if (coordinate < low || coordinate > high)
|
|
40
|
+
continue;
|
|
41
|
+
const from = axis === 'x' ? { x: start, y: coordinate } : { x: coordinate, y: start };
|
|
42
|
+
const to = axis === 'x' ? { x: end, y: coordinate } : { x: coordinate, y: end };
|
|
43
|
+
if (available(from, to) && !crosses(from, to, obstacles) && routeCost(axis, from, to) === 0) {
|
|
44
|
+
return [from, to];
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
export function loopCandidates(box, lane) {
|
|
51
|
+
const reach = loopReach + lane * trackGap;
|
|
52
|
+
const exit = Math.min(leadLength, box.height / 4);
|
|
53
|
+
const entry = Math.min(loopReach, box.width / 2);
|
|
54
|
+
const left = box.x;
|
|
55
|
+
const right = box.x + box.width;
|
|
56
|
+
const top = box.y;
|
|
57
|
+
const bottom = box.y + box.height;
|
|
58
|
+
return [
|
|
59
|
+
[right, 1],
|
|
60
|
+
[left, -1],
|
|
61
|
+
].flatMap(([side, outward]) => {
|
|
62
|
+
const channel = side + outward * reach;
|
|
63
|
+
const x = side - outward * entry;
|
|
64
|
+
return [
|
|
65
|
+
[
|
|
66
|
+
{ x: side, y: top + exit },
|
|
67
|
+
{ x: channel, y: top + exit },
|
|
68
|
+
{ x: channel, y: top - reach },
|
|
69
|
+
{ x, y: top - reach },
|
|
70
|
+
{ x, y: top },
|
|
71
|
+
],
|
|
72
|
+
[
|
|
73
|
+
{ x: side, y: bottom - exit },
|
|
74
|
+
{ x: channel, y: bottom - exit },
|
|
75
|
+
{ x: channel, y: bottom + reach },
|
|
76
|
+
{ x, y: bottom + reach },
|
|
77
|
+
{ x, y: bottom },
|
|
78
|
+
],
|
|
79
|
+
];
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=shapes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shapes.js","sourceRoot":"","sources":["../../../src/mermaid/routing/shapes.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAEjE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,SAAS,EAAe,MAAM,iBAAiB,CAAC;AAE5E,MAAM,UAAU,aAAa,CAC3B,MAAW,EACX,MAAW,EACX,SAA4B,EAC5B,SAAoB,EACpB,SAA8C,EAC9C,EAAE,GAAG,EAAE,QAAQ,EAAqC;IAEpD,KAAK,MAAM,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,CAAU,EAAE,CAAC;QACvC,MAAM,MAAM,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC;QAC/B,MAAM,UAAU,GAAG,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAC5C,MAAM,UAAU,GAAG,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAC5C,MAAM,WAAW,GAAG,IAAI,CAAC,GAAG,CAAC,UAAU,EAAE,UAAU,GAAG,CAAC,CAAC,CAAC;QACzD,MAAM,WAAW,GAAG,IAAI,CAAC,GAAG,CAAC,UAAU,EAAE,UAAU,GAAG,CAAC,CAAC,CAAC;QACzD,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,WAAW,EAAE,MAAM,CAAC,MAAM,CAAC,GAAG,WAAW,CAAC,CAAC;QACjF,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM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O,EAAE,CAAC,EAAE,MAAM,GAAG,KAAK,EAAE;gBACjC,EAAE,CAAC,EAAE,CAAC,EAAE,MAAM,GAAG,KAAK,EAAE;gBACxB,EAAE,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE;aACjB;SACF,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type { Box, Point } from '../architectureLayout.js';\nimport { leadLength, loopReach, trackGap } from './constants.js';\nimport type { RouteCost } from './congestion.js';\nimport { axisSize, crosses, otherAxis, type Bounds } from './primitives.js';\n\nexport function straightRoute(\n source: Box,\n target: Box,\n obstacles: readonly Bounds[],\n routeCost: RouteCost,\n available: (from: Point, to: Point) => boolean,\n { gap, parallel }: { gap: number; parallel: number },\n): Point[] | undefined {\n for (const axis of ['x', 'y'] as const) {\n const across = otherAxis(axis);\n const sourceSize = axisSize(source, across);\n const targetSize = axisSize(target, across);\n const sourceInset = Math.min(leadLength, sourceSize / 4);\n const targetInset = Math.min(leadLength, targetSize / 4);\n const low = Math.max(source[across] + sourceInset, target[across] + targetInset);\n const high = Math.min(source[across] + sourceSize - sourceInset, target[across] + targetSize - targetInset);\n if (high < low) continue;\n\n const forward = source[axis] < target[axis];\n const start = forward ? source[axis] + axisSize(source, axis) : source[axis];\n const end = forward ? target[axis] : target[axis] + axisSize(target, axis);\n if ((forward ? end - start : start - end) < leadLength) continue;\n\n const middle = (low + high) / 2;\n // Relationships between the same pair share the overlap evenly, outward from its middle.\n const spacing = Math.max(gap, (high - low) / (parallel + 1));\n const spread =\n parallel > 1\n ? Array.from({ length: parallel }, (_, index) => index + 1).flatMap((step) => [\n middle - step * spacing,\n middle + step * spacing,\n ])\n : [];\n const candidates = [\n middle,\n source[across] + sourceSize / 2,\n target[across] + targetSize / 2,\n ...spread,\n middle - gap,\n middle + gap,\n low,\n high,\n ];\n for (const coordinate of candidates) {\n if (coordinate < low || coordinate > high) continue;\n const from = axis === 'x' ? { x: start, y: coordinate } : { x: coordinate, y: start };\n const to = axis === 'x' ? { x: end, y: coordinate } : { x: coordinate, y: end };\n if (available(from, to) && !crosses(from, to, obstacles) && routeCost(axis, from, to) === 0) {\n return [from, to];\n }\n }\n }\n return undefined;\n}\n\nexport function loopCandidates(box: Box, lane: number): Point[][] {\n const reach = loopReach + lane * trackGap;\n const exit = Math.min(leadLength, box.height / 4);\n const entry = Math.min(loopReach, box.width / 2);\n const left = box.x;\n const right = box.x + box.width;\n const top = box.y;\n const bottom = box.y + box.height;\n return (\n [\n [right, 1],\n [left, -1],\n ] as const\n ).flatMap(([side, outward]) => {\n const channel = side + outward * reach;\n const x = side - outward * entry;\n return [\n [\n { x: side, y: top + exit },\n { x: channel, y: top + exit },\n { x: channel, y: top - reach },\n { x, y: top - reach },\n { x, y: top },\n ],\n [\n { x: side, y: bottom - exit },\n { x: channel, y: bottom - exit },\n { x: channel, y: bottom + reach },\n { x, y: bottom + reach },\n { x, y: bottom },\n ],\n ];\n });\n}\n"]}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { Box, Point } from '../architectureLayout.js';
|
|
2
|
+
export interface RoutingNode {
|
|
3
|
+
readonly box: Box;
|
|
4
|
+
readonly parent?: string;
|
|
5
|
+
readonly decorations?: readonly Box[];
|
|
6
|
+
}
|
|
7
|
+
export interface RoutingEdge {
|
|
8
|
+
readonly id: string;
|
|
9
|
+
readonly source: string;
|
|
10
|
+
readonly target: string;
|
|
11
|
+
readonly sourceMarker?: boolean;
|
|
12
|
+
readonly targetMarker?: boolean;
|
|
13
|
+
readonly bundling?: BundleKind;
|
|
14
|
+
}
|
|
15
|
+
export interface BundleKind {
|
|
16
|
+
readonly type: string;
|
|
17
|
+
readonly access: string;
|
|
18
|
+
readonly directed: boolean;
|
|
19
|
+
}
|
|
20
|
+
export declare function bundleKind({ type, access, directed, }: {
|
|
21
|
+
readonly type: string;
|
|
22
|
+
readonly access?: string | undefined;
|
|
23
|
+
readonly directed?: boolean | undefined;
|
|
24
|
+
}): BundleKind;
|
|
25
|
+
export interface RoutingOptions {
|
|
26
|
+
readonly warn?: (message: string) => void;
|
|
27
|
+
}
|
|
28
|
+
export interface RouteBundle {
|
|
29
|
+
readonly id: string;
|
|
30
|
+
readonly sharedEnd: 'start' | 'end';
|
|
31
|
+
}
|
|
32
|
+
export interface ArchitectureRoutes {
|
|
33
|
+
readonly routes: ReadonlyMap<string, readonly Point[]>;
|
|
34
|
+
readonly bundles: ReadonlyMap<string, RouteBundle>;
|
|
35
|
+
}
|
|
36
|
+
export declare function ancestorIds(id: string, nodes: ReadonlyMap<string, RoutingNode>): string[];
|
|
37
|
+
export declare function boxOf(nodes: ReadonlyMap<string, RoutingNode>, id: string): Box;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ancestors } from '../hierarchy.js';
|
|
2
|
+
export function bundleKind({ type, access, directed, }) {
|
|
3
|
+
return { type, access: access ?? 'unspecified', directed: directed ?? false };
|
|
4
|
+
}
|
|
5
|
+
export function ancestorIds(id, nodes) {
|
|
6
|
+
return ancestors(id, { get: (child) => nodes.get(child)?.parent });
|
|
7
|
+
}
|
|
8
|
+
export function boxOf(nodes, id) {
|
|
9
|
+
const node = nodes.get(id);
|
|
10
|
+
if (!node)
|
|
11
|
+
throw new Error(`Missing endpoint "${id}" for an ArchiMate relationship.`);
|
|
12
|
+
return node.box;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/mermaid/routing/types.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAyB5C,MAAM,UAAU,UAAU,CAAC,EACzB,IAAI,EACJ,MAAM,EACN,QAAQ,GAKT;IACC,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,IAAI,aAAa,EAAE,QAAQ,EAAE,QAAQ,IAAI,KAAK,EAAE,CAAC;AAChF,CAAC;AAiBD,MAAM,UAAU,WAAW,CAAC,EAAU,EAAE,KAAuC;IAC7E,OAAO,SAAS,CAAC,EAAE,EAAE,EAAE,GAAG,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;AACrE,CAAC;AAED,MAAM,UAAU,KAAK,CAAC,KAAuC,EAAE,EAAU;IACvE,MAAM,IAAI,GAAG,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAC3B,IAAI,CAAC,IAAI;QAAE,MAAM,IAAI,KAAK,CAAC,qBAAqB,EAAE,kCAAkC,CAAC,CAAC;IACtF,OAAO,IAAI,CAAC,GAAG,CAAC;AAClB,CAAC","sourcesContent":["import type { Box, Point } from '../architectureLayout.js';\nimport { ancestors } from '../hierarchy.js';\n\nexport interface RoutingNode {\n readonly box: Box;\n readonly parent?: string;\n readonly decorations?: readonly Box[];\n}\n\nexport interface RoutingEdge {\n readonly id: string;\n readonly source: string;\n readonly target: string;\n readonly sourceMarker?: boolean;\n readonly targetMarker?: boolean;\n // Absent means the relationship is never bundled, as for relationships of notes.\n readonly bundling?: BundleKind;\n}\n\n// Relationships drawn alike may share a line, so a bundle needs the same type, access mode and direction.\nexport interface BundleKind {\n readonly type: string;\n readonly access: string;\n readonly directed: boolean;\n}\n\nexport function bundleKind({\n type,\n access,\n directed,\n}: {\n readonly type: string;\n readonly access?: string | undefined;\n readonly directed?: boolean | undefined;\n}): BundleKind {\n return { type, access: access ?? 'unspecified', directed: directed ?? false };\n}\n\nexport interface RoutingOptions {\n readonly warn?: (message: string) => void;\n}\n\nexport interface RouteBundle {\n readonly id: string;\n // Members of a bundle coincide from the end they share: their start, or their end.\n readonly sharedEnd: 'start' | 'end';\n}\n\nexport interface ArchitectureRoutes {\n readonly routes: ReadonlyMap<string, readonly Point[]>;\n readonly bundles: ReadonlyMap<string, RouteBundle>;\n}\n\nexport function ancestorIds(id: string, nodes: ReadonlyMap<string, RoutingNode>): string[] {\n return ancestors(id, { get: (child) => nodes.get(child)?.parent });\n}\n\nexport function boxOf(nodes: ReadonlyMap<string, RoutingNode>, id: string): Box {\n const node = nodes.get(id);\n if (!node) throw new Error(`Missing endpoint \"${id}\" for an ArchiMate relationship.`);\n return node.box;\n}\n"]}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import type { MermaidConfig } from 'mermaid';
|
|
2
|
+
import { type ElementCategory } from '../archimate/catalogue.js';
|
|
3
|
+
interface ElementColours {
|
|
4
|
+
readonly fill: string;
|
|
5
|
+
readonly stroke: string;
|
|
6
|
+
readonly text: string;
|
|
7
|
+
}
|
|
8
|
+
export interface PaletteColours {
|
|
9
|
+
readonly elements: Readonly<Record<ElementCategory, ElementColours>>;
|
|
10
|
+
readonly location: ElementColours;
|
|
11
|
+
readonly note: ElementColours & {
|
|
12
|
+
readonly fold: string;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
export declare const archimatePalettes: {
|
|
16
|
+
modern: {
|
|
17
|
+
elements: {
|
|
18
|
+
motivation: {
|
|
19
|
+
fill: string;
|
|
20
|
+
stroke: string;
|
|
21
|
+
text: string;
|
|
22
|
+
};
|
|
23
|
+
strategy: {
|
|
24
|
+
fill: string;
|
|
25
|
+
stroke: string;
|
|
26
|
+
text: string;
|
|
27
|
+
};
|
|
28
|
+
business: {
|
|
29
|
+
fill: string;
|
|
30
|
+
stroke: string;
|
|
31
|
+
text: string;
|
|
32
|
+
};
|
|
33
|
+
application: {
|
|
34
|
+
fill: string;
|
|
35
|
+
stroke: string;
|
|
36
|
+
text: string;
|
|
37
|
+
};
|
|
38
|
+
technology: {
|
|
39
|
+
fill: string;
|
|
40
|
+
stroke: string;
|
|
41
|
+
text: string;
|
|
42
|
+
};
|
|
43
|
+
physical: {
|
|
44
|
+
fill: string;
|
|
45
|
+
stroke: string;
|
|
46
|
+
text: string;
|
|
47
|
+
};
|
|
48
|
+
implementationAndMigration: {
|
|
49
|
+
fill: string;
|
|
50
|
+
stroke: string;
|
|
51
|
+
text: string;
|
|
52
|
+
};
|
|
53
|
+
composite: {
|
|
54
|
+
fill: string;
|
|
55
|
+
stroke: string;
|
|
56
|
+
text: string;
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
location: {
|
|
60
|
+
fill: string;
|
|
61
|
+
stroke: string;
|
|
62
|
+
text: string;
|
|
63
|
+
};
|
|
64
|
+
note: {
|
|
65
|
+
fill: string;
|
|
66
|
+
fold: string;
|
|
67
|
+
stroke: string;
|
|
68
|
+
text: string;
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
export type ArchiMatePalette = keyof typeof archimatePalettes;
|
|
73
|
+
export interface DiagramColours {
|
|
74
|
+
readonly canvas: string;
|
|
75
|
+
readonly text: string;
|
|
76
|
+
readonly relationship: string;
|
|
77
|
+
readonly relationshipOutline?: string;
|
|
78
|
+
}
|
|
79
|
+
export interface DiagramTypography {
|
|
80
|
+
readonly fontFamily: string;
|
|
81
|
+
readonly labelSize: number;
|
|
82
|
+
readonly titleSize: number;
|
|
83
|
+
readonly edgeLabelSize: number;
|
|
84
|
+
}
|
|
85
|
+
export type ColourResolver = (colour: string) => string | undefined;
|
|
86
|
+
export declare function resolveDiagramColours(config?: MermaidConfig, resolve?: ColourResolver, warn?: (message: string) => void): DiagramColours;
|
|
87
|
+
export declare function resolveTypography(theme: unknown, variables: unknown): DiagramTypography;
|
|
88
|
+
export declare const archimateStyles: (options?: unknown) => string;
|
|
89
|
+
export {};
|