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,249 @@
|
|
|
1
|
+
import { required } from './invariant.js';
|
|
2
|
+
import { createAnchorRegistry, placeSharedAnchors, } from './routing/anchors.js';
|
|
3
|
+
import { farSide, planBundles } from './routing/bundles.js';
|
|
4
|
+
import { createCongestion } from './routing/congestion.js';
|
|
5
|
+
import { clearances, leadLength, markerGap, searchMargin, trackGap } from './routing/constants.js';
|
|
6
|
+
import { bounds, centre, crosses, facing, oppositeSide, otherAxis, pointDistance, ports, sidePort, } from './routing/primitives.js';
|
|
7
|
+
import { routeBetween } from './routing/search.js';
|
|
8
|
+
import { loopCandidates, straightRoute } from './routing/shapes.js';
|
|
9
|
+
import { ancestorIds, boxOf, } from './routing/types.js';
|
|
10
|
+
export { bundleKind } from './routing/types.js';
|
|
11
|
+
function createRoutingState(nodes, edges, warn) {
|
|
12
|
+
const degrees = new Map();
|
|
13
|
+
for (const { source, target } of edges) {
|
|
14
|
+
for (const id of [source, target])
|
|
15
|
+
degrees.set(id, (degrees.get(id) ?? 0) + 1);
|
|
16
|
+
}
|
|
17
|
+
const usedPorts = new Map();
|
|
18
|
+
const pairKey = ({ source, target }) => JSON.stringify([source, target].sort());
|
|
19
|
+
const parallelCounts = new Map();
|
|
20
|
+
for (const edge of edges)
|
|
21
|
+
parallelCounts.set(pairKey(edge), (parallelCounts.get(pairKey(edge)) ?? 0) + 1);
|
|
22
|
+
return {
|
|
23
|
+
nodes,
|
|
24
|
+
warn,
|
|
25
|
+
congestion: createCongestion(),
|
|
26
|
+
anchors: createAnchorRegistry(),
|
|
27
|
+
routes: new Map(),
|
|
28
|
+
bundles: new Map(),
|
|
29
|
+
portFraction(id) {
|
|
30
|
+
const used = (usedPorts.get(id) ?? 0) + 1;
|
|
31
|
+
usedPorts.set(id, used);
|
|
32
|
+
return used / ((degrees.get(id) ?? 0) + 1);
|
|
33
|
+
},
|
|
34
|
+
parallelCount: (edge) => parallelCounts.get(pairKey(edge)) ?? 1,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
function prepare(state, edge) {
|
|
38
|
+
const { nodes, congestion, anchors, routes, warn } = state;
|
|
39
|
+
const source = nodes.get(edge.source);
|
|
40
|
+
const target = nodes.get(edge.target);
|
|
41
|
+
if (!source || !target)
|
|
42
|
+
throw new Error(`Missing endpoints for relationship "${edge.id}".`);
|
|
43
|
+
const sourceBox = source.box;
|
|
44
|
+
const targetBox = target.box;
|
|
45
|
+
const sourceMarker = edge.sourceMarker ?? false;
|
|
46
|
+
const targetMarker = edge.targetMarker ?? false;
|
|
47
|
+
const sourceAncestors = ancestorIds(edge.source, nodes);
|
|
48
|
+
const targetAncestors = ancestorIds(edge.target, nodes);
|
|
49
|
+
const open = new Set([...sourceAncestors, ...targetAncestors]);
|
|
50
|
+
const sourceInsideTarget = sourceAncestors.includes(edge.target);
|
|
51
|
+
const targetInsideSource = targetAncestors.includes(edge.source);
|
|
52
|
+
const container = sourceInsideTarget
|
|
53
|
+
? edge.target
|
|
54
|
+
: targetInsideSource
|
|
55
|
+
? edge.source
|
|
56
|
+
: sourceAncestors.find((id) => targetAncestors.includes(id));
|
|
57
|
+
const frame = container === undefined ? undefined : nodes.get(container)?.box;
|
|
58
|
+
// An edge can cross its container's frame wherever the title and icon leave room.
|
|
59
|
+
const obstaclesFor = (clearance) => [...nodes].flatMap(([id, node]) => (open.has(id) ? (node.decorations ?? []) : [node.box]).map((box) => ({ id, ...bounds(box, clearance) })));
|
|
60
|
+
function search(starts, ends, clearance, separate, owner) {
|
|
61
|
+
const obstacles = obstaclesFor(clearance);
|
|
62
|
+
const available = (port, id) => !crosses(port.anchor, port.lead, obstacles.filter((box) => box.id !== id || open.has(id)));
|
|
63
|
+
const usableStarts = starts.filter((port) => available(port, edge.source) &&
|
|
64
|
+
(!separate.start || anchors.clear(edge.source, sourceBox, port.anchor, sourceMarker)));
|
|
65
|
+
const usableEnds = ends.filter((port) => available(port, edge.target) &&
|
|
66
|
+
(!separate.end || anchors.clear(edge.target, targetBox, port.anchor, targetMarker)));
|
|
67
|
+
const cost = (axis, from, to) => congestion.cost(axis, from, to, owner);
|
|
68
|
+
const frameRegion = frame && bounds(frame, -clearance);
|
|
69
|
+
// Search near the endpoints first; on large diagrams the full grid is far bigger than any good route needs.
|
|
70
|
+
const nearSource = bounds(sourceBox, searchMargin);
|
|
71
|
+
const nearTarget = bounds(targetBox, searchMargin);
|
|
72
|
+
const outer = frameRegion ?? { left: -Infinity, right: Infinity, top: -Infinity, bottom: Infinity };
|
|
73
|
+
const nearby = {
|
|
74
|
+
left: Math.max(Math.min(nearSource.left, nearTarget.left), outer.left),
|
|
75
|
+
right: Math.min(Math.max(nearSource.right, nearTarget.right), outer.right),
|
|
76
|
+
top: Math.max(Math.min(nearSource.top, nearTarget.top), outer.top),
|
|
77
|
+
bottom: Math.min(Math.max(nearSource.bottom, nearTarget.bottom), outer.bottom),
|
|
78
|
+
};
|
|
79
|
+
const local = obstacles.filter((box) => box.left < nearby.right && box.right > nearby.left && box.top < nearby.bottom && box.bottom > nearby.top);
|
|
80
|
+
return ((local.length < obstacles.length ? routeBetween(usableStarts, usableEnds, local, cost, nearby) : undefined) ??
|
|
81
|
+
routeBetween(usableStarts, usableEnds, obstacles, cost, frameRegion));
|
|
82
|
+
}
|
|
83
|
+
// A diagram with one awkward connector is more useful than no diagram, so the last resort is a straight line.
|
|
84
|
+
function fallback(starts, ends) {
|
|
85
|
+
const [nearest] = starts
|
|
86
|
+
.flatMap((start) => ends.map((end) => [start.anchor, end.anchor]))
|
|
87
|
+
.sort(([a, b], [c, d]) => pointDistance(a, b) - pointDistance(c, d));
|
|
88
|
+
if (!nearest)
|
|
89
|
+
throw new Error(`Relationship "${edge.id}" has no ports to connect.`);
|
|
90
|
+
warn?.(`ArchiMate could not find an orthogonal route for relationship "${edge.id}" and drew a direct line.`);
|
|
91
|
+
return [...nearest];
|
|
92
|
+
}
|
|
93
|
+
function record(points, owner) {
|
|
94
|
+
const first = points[0];
|
|
95
|
+
const last = points.at(-1);
|
|
96
|
+
if (!first || !last || points.length < 2) {
|
|
97
|
+
throw new Error(`Route for relationship "${edge.id}" has fewer than two points.`);
|
|
98
|
+
}
|
|
99
|
+
anchors.reserve(edge.source, sourceBox, first, sourceMarker);
|
|
100
|
+
anchors.reserve(edge.target, targetBox, last, targetMarker);
|
|
101
|
+
routes.set(edge.id, [...points]);
|
|
102
|
+
for (let index = 1; index < points.length; index++) {
|
|
103
|
+
const start = points[index - 1];
|
|
104
|
+
const end = points[index];
|
|
105
|
+
if (!start || !end)
|
|
106
|
+
continue;
|
|
107
|
+
const axis = start.y === end.y ? 'x' : 'y';
|
|
108
|
+
const across = start[otherAxis(axis)];
|
|
109
|
+
congestion.add(axis, across, Math.min(start[axis], end[axis]), Math.max(start[axis], end[axis]), owner);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return {
|
|
113
|
+
sourceBox,
|
|
114
|
+
targetBox,
|
|
115
|
+
sourceMarker,
|
|
116
|
+
targetMarker,
|
|
117
|
+
sourceInsideTarget,
|
|
118
|
+
targetInsideSource,
|
|
119
|
+
frame,
|
|
120
|
+
obstaclesFor,
|
|
121
|
+
search,
|
|
122
|
+
fallback,
|
|
123
|
+
record,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
// Self-relationships and straight connections are recorded at once; the rest wait until the bundles are in place.
|
|
127
|
+
function routeSingles(state, edges) {
|
|
128
|
+
const { anchors, congestion, portFraction } = state;
|
|
129
|
+
const deferred = [];
|
|
130
|
+
const loops = new Map();
|
|
131
|
+
for (const edge of edges) {
|
|
132
|
+
const { sourceBox, targetBox, sourceMarker, targetMarker, sourceInsideTarget, targetInsideSource, frame, obstaclesFor, search, fallback, record, } = prepare(state, edge);
|
|
133
|
+
const nestedEdge = sourceInsideTarget || targetInsideSource;
|
|
134
|
+
const sourcePorts = ports(sourceBox, portFraction(edge.source), targetInsideSource);
|
|
135
|
+
const targetPorts = ports(targetBox, portFraction(edge.target), sourceInsideTarget);
|
|
136
|
+
const starts = nestedEdge ? sourcePorts : facing(sourcePorts, sourceBox, targetBox);
|
|
137
|
+
const ends = nestedEdge ? targetPorts : facing(targetPorts, targetBox, sourceBox);
|
|
138
|
+
if (edge.source === edge.target) {
|
|
139
|
+
const lane = loops.get(edge.source) ?? 0;
|
|
140
|
+
loops.set(edge.source, lane + 1);
|
|
141
|
+
const obstacles = obstaclesFor(clearances.comfortable).filter(({ id }) => id !== edge.source);
|
|
142
|
+
const region = frame && bounds(frame);
|
|
143
|
+
const inside = ({ x, y }) => !region || (x >= region.left && x <= region.right && y >= region.top && y <= region.bottom);
|
|
144
|
+
const loopsAvailable = loopCandidates(sourceBox, lane);
|
|
145
|
+
const clear = loopsAvailable.find((points) => {
|
|
146
|
+
const first = points[0];
|
|
147
|
+
const last = points.at(-1);
|
|
148
|
+
return (first !== undefined &&
|
|
149
|
+
last !== undefined &&
|
|
150
|
+
anchors.clear(edge.source, sourceBox, first, sourceMarker) &&
|
|
151
|
+
anchors.clear(edge.source, sourceBox, last, targetMarker) &&
|
|
152
|
+
points.every((point, index) => {
|
|
153
|
+
const previous = points[index - 1];
|
|
154
|
+
return inside(point) && (!previous || !crosses(previous, point, obstacles));
|
|
155
|
+
}));
|
|
156
|
+
});
|
|
157
|
+
if (!clear) {
|
|
158
|
+
state.warn?.(`ArchiMate could not keep the self-relationship "${edge.id}" clear of other shapes and anchors.`);
|
|
159
|
+
}
|
|
160
|
+
record(clear ?? required(loopsAvailable[lane % loopsAvailable.length], 'a self-relationship loop'));
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
const direct = !sourceInsideTarget && !targetInsideSource
|
|
164
|
+
? straightRoute(sourceBox, targetBox, obstaclesFor(clearances.comfortable).filter(({ id }) => id !== edge.source && id !== edge.target), congestion.cost, (from, to) => anchors.clear(edge.source, sourceBox, from, sourceMarker) &&
|
|
165
|
+
anchors.clear(edge.target, targetBox, to, targetMarker), { gap: sourceMarker || targetMarker ? markerGap : trackGap, parallel: state.parallelCount(edge) })
|
|
166
|
+
: undefined;
|
|
167
|
+
if (direct)
|
|
168
|
+
record(direct);
|
|
169
|
+
else {
|
|
170
|
+
const apart = { start: true, end: true };
|
|
171
|
+
const together = { start: false, end: false };
|
|
172
|
+
const { comfortable, tight } = clearances;
|
|
173
|
+
deferred.push(() => {
|
|
174
|
+
record(search(starts, ends, comfortable, apart) ??
|
|
175
|
+
search(starts, ends, comfortable, together) ??
|
|
176
|
+
search(starts, ends, tight, together) ??
|
|
177
|
+
fallback(starts, ends));
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
return deferred;
|
|
182
|
+
}
|
|
183
|
+
function routeBundles(state, { ports: sharedPorts, order: routingOrder }) {
|
|
184
|
+
const { nodes, bundles, portFraction } = state;
|
|
185
|
+
for (const group of routingOrder) {
|
|
186
|
+
const shared = sharedPorts.get(group.id);
|
|
187
|
+
if (!shared)
|
|
188
|
+
continue;
|
|
189
|
+
const sharedBox = boxOf(nodes, group.element);
|
|
190
|
+
// The farthest member lays the trunk; nearer members then branch off it.
|
|
191
|
+
const members = group.members.toSorted((a, b) => {
|
|
192
|
+
const far = (edge) => boxOf(nodes, group.sharedEnd === 'start' ? edge.target : edge.source);
|
|
193
|
+
return pointDistance(centre(far(b)), centre(sharedBox)) - pointDistance(centre(far(a)), centre(sharedBox));
|
|
194
|
+
});
|
|
195
|
+
for (const edge of members) {
|
|
196
|
+
const context = prepare(state, edge);
|
|
197
|
+
const farId = group.sharedEnd === 'start' ? edge.target : edge.source;
|
|
198
|
+
const farBox = boxOf(nodes, farId);
|
|
199
|
+
const fraction = portFraction(farId);
|
|
200
|
+
const facingSide = farSide(group.side, shared.anchor, farBox);
|
|
201
|
+
const insetX = Math.min(leadLength, farBox.width / 4);
|
|
202
|
+
const insetY = Math.min(leadLength, farBox.height / 4);
|
|
203
|
+
const across = facingSide === 'top' || facingSide === 'bottom' ? 'x' : 'y';
|
|
204
|
+
const low = across === 'x' ? farBox.x + insetX : farBox.y + insetY;
|
|
205
|
+
const high = across === 'x' ? farBox.x + farBox.width - insetX : farBox.y + farBox.height - insetY;
|
|
206
|
+
const straightAcross = facingSide === oppositeSide[group.side] && shared.anchor[across] >= low && shared.anchor[across] <= high;
|
|
207
|
+
const along = straightAcross ? shared.anchor[across] : low + fraction * (high - low);
|
|
208
|
+
// Other relationships may already hold the best spot, so offer the rest of the facing side as well.
|
|
209
|
+
// A branch that rises beside a nearer element can enter without a jog where it already runs.
|
|
210
|
+
const besideElements = [...nodes.values()]
|
|
211
|
+
.flatMap(({ box }) => across === 'x'
|
|
212
|
+
? [box.x - clearances.comfortable, box.x + box.width + clearances.comfortable]
|
|
213
|
+
: [box.y - clearances.comfortable, box.y + box.height + clearances.comfortable])
|
|
214
|
+
.filter((position) => position >= low && position <= high);
|
|
215
|
+
const preferred = [
|
|
216
|
+
along,
|
|
217
|
+
...besideElements,
|
|
218
|
+
...Array.from({ length: 5 }, (_, index) => low + ((index + 0.5) * (high - low)) / 5),
|
|
219
|
+
].map((position) => sidePort(farBox, facingSide, position));
|
|
220
|
+
const anyFar = facing(ports(farBox, fraction, false), farBox, sharedBox);
|
|
221
|
+
// The shared anchor is reserved for the whole bundle, so only the far end keeps clear of other anchors.
|
|
222
|
+
const attempt = (far, clearance, separate) => group.sharedEnd === 'start'
|
|
223
|
+
? context.search([shared], far, clearance, { start: false, end: separate }, group.id)
|
|
224
|
+
: context.search(far, [shared], clearance, { start: separate, end: false }, group.id);
|
|
225
|
+
const { comfortable, tight } = clearances;
|
|
226
|
+
const points = attempt(preferred, comfortable, true) ??
|
|
227
|
+
attempt(anyFar, comfortable, true) ??
|
|
228
|
+
attempt(anyFar, comfortable, false) ??
|
|
229
|
+
attempt(anyFar, tight, false) ??
|
|
230
|
+
(group.sharedEnd === 'start' ? context.fallback([shared], anyFar) : context.fallback(anyFar, [shared]));
|
|
231
|
+
context.record(points, group.members.length > 1 ? group.id : undefined);
|
|
232
|
+
if (group.members.length > 1)
|
|
233
|
+
bundles.set(edge.id, { id: group.id, sharedEnd: group.sharedEnd });
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
export function routeArchitecture(nodes, edges, { warn } = {}) {
|
|
238
|
+
const state = createRoutingState(nodes, edges, warn);
|
|
239
|
+
const groups = planBundles(nodes, edges);
|
|
240
|
+
const shared = placeSharedAnchors(nodes, groups, state.anchors);
|
|
241
|
+
const grouped = new Set([...groups.values()].flatMap(({ members }) => members.map(({ id }) => id)));
|
|
242
|
+
const detours = routeSingles(state, edges.filter(({ id }) => !grouped.has(id)));
|
|
243
|
+
// Reserve straight connectors first, then planned bundles, so detours route around both.
|
|
244
|
+
routeBundles(state, shared);
|
|
245
|
+
for (const detour of detours)
|
|
246
|
+
detour();
|
|
247
|
+
return { routes: state.routes, bundles: state.bundles };
|
|
248
|
+
}
|
|
249
|
+
//# sourceMappingURL=orthogonalRouter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"orthogonalRouter.js","sourceRoot":"","sources":["../../src/mermaid/orthogonalRouter.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EACL,oBAAoB,EACpB,kBAAkB,GAGnB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,EAAE,gBAAgB,EAAmC,MAAM,yBAAyB,CAAC;AAC5F,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AACnG,OAAO,EACL,MAAM,EACN,MAAM,EACN,OAAO,EACP,MAAM,EACN,YAAY,EACZ,SAAS,EACT,aAAa,EACb,KAAK,EACL,QAAQ,GAGT,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpE,OAAO,EACL,WAAW,EACX,KAAK,GAMN,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AA0ChD,SAAS,kBAAkB,CACzB,KAAuC,EACvC,KAA6B,EAC7B,IAA4B;IAE5B,MAAM,OAAO,GAAG,IAAI,GAAG,EAAkB,CAAC;IAC1C,KAAK,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,KAAK,EAAE,CAAC;QACvC,KAAK,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC;YAAE,OAAO,CAAC,G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AU,iBAAiB,CAC/B,KAAuC,EACvC,KAA6B,EAC7B,EAAE,IAAI,KAAqB,EAAE;IAE7B,MAAM,KAAK,GAAG,kBAAkB,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;IACrD,MAAM,MAAM,GAAG,WAAW,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IACzC,MAAM,MAAM,GAAG,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;IAChE,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IACpG,MAAM,OAAO,GAAG,YAAY,CAC1B,KAAK,EACL,KAAK,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAC3C,CAAC;IACF,yFAAyF;IACzF,YAAY,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IAC5B,KAAK,MAAM,MAAM,IAAI,OAAO;QAAE,MAAM,EAAE,CAAC;IACvC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC;AAC1D,CAAC","sourcesContent":["import type { Box, Point } from './architectureLayout.js';\nimport { required } from './invariant.js';\nimport {\n createAnchorRegistry,\n placeSharedAnchors,\n type AnchorRegistry,\n type SharedAnchors,\n} from './routing/anchors.js';\nimport { farSide, planBundles } from './routing/bundles.js';\nimport { createCongestion, type Congestion, type RouteCost } from './routing/congestion.js';\nimport { clearances, leadLength, markerGap, searchMargin, trackGap } from './routing/constants.js';\nimport {\n bounds,\n centre,\n crosses,\n facing,\n oppositeSide,\n otherAxis,\n pointDistance,\n ports,\n sidePort,\n type Bounds,\n type Port,\n} from './routing/primitives.js';\nimport { routeBetween } from './routing/search.js';\nimport { loopCandidates, straightRoute } from './routing/shapes.js';\nimport {\n ancestorIds,\n boxOf,\n type ArchitectureRoutes,\n type RouteBundle,\n type RoutingEdge,\n type RoutingNode,\n type RoutingOptions,\n} from './routing/types.js';\n\nexport { bundleKind } from './routing/types.js';\nexport type {\n ArchitectureRoutes,\n BundleKind,\n RouteBundle,\n RoutingEdge,\n RoutingNode,\n RoutingOptions,\n} from './routing/types.js';\n\ninterface RouteContext {\n readonly sourceBox: Box;\n readonly targetBox: Box;\n readonly sourceMarker: boolean;\n readonly targetMarker: boolean;\n readonly sourceInsideTarget: boolean;\n readonly targetInsideSource: boolean;\n readonly frame: Box | undefined;\n readonly obstaclesFor: (clearance: number) => (Bounds & { readonly id: string })[];\n readonly search: (\n starts: readonly Port[],\n ends: readonly Port[],\n clearance: number,\n separate: { readonly start: boolean; readonly end: boolean },\n owner?: string,\n ) => Point[] | undefined;\n readonly fallback: (starts: readonly Port[], ends: readonly Port[]) => Point[];\n readonly record: (points: readonly Point[], owner?: string) => void;\n}\n\ninterface RoutingState {\n readonly nodes: ReadonlyMap<string, RoutingNode>;\n readonly warn: ((message: string) => void) | undefined;\n readonly congestion: Congestion;\n readonly anchors: AnchorRegistry;\n readonly routes: Map<string, Point[]>;\n readonly bundles: Map<string, RouteBundle>;\n // Spreads each element's ports along its sides in the order relationships ask for them.\n readonly portFraction: (id: string) => number;\n readonly parallelCount: (edge: RoutingEdge) => number;\n}\n\nfunction createRoutingState(\n nodes: ReadonlyMap<string, RoutingNode>,\n edges: readonly RoutingEdge[],\n warn: RoutingOptions['warn'],\n): RoutingState {\n const degrees = new Map<string, number>();\n for (const { source, target } of edges) {\n for (const id of [source, target]) degrees.set(id, (degrees.get(id) ?? 0) + 1);\n }\n const usedPorts = new Map<string, number>();\n const pairKey = ({ source, target }: RoutingEdge) => JSON.stringify([source, target].sort());\n const parallelCounts = new Map<string, number>();\n for (const edge of edges) parallelCounts.set(pairKey(edge), (parallelCounts.get(pairKey(edge)) ?? 0) + 1);\n return {\n nodes,\n warn,\n congestion: createCongestion(),\n anchors: createAnchorRegistry(),\n routes: new Map(),\n bundles: new Map(),\n portFraction(id) {\n const used = (usedPorts.get(id) ?? 0) + 1;\n usedPorts.set(id, used);\n return used / ((degrees.get(id) ?? 0) + 1);\n },\n parallelCount: (edge) => parallelCounts.get(pairKey(edge)) ?? 1,\n };\n}\n\nfunction prepare(state: RoutingState, edge: RoutingEdge): RouteContext {\n const { nodes, congestion, anchors, routes, warn } = state;\n const source = nodes.get(edge.source);\n const target = nodes.get(edge.target);\n if (!source || !target) throw new Error(`Missing endpoints for relationship \"${edge.id}\".`);\n const sourceBox = source.box;\n const targetBox = target.box;\n const sourceMarker = edge.sourceMarker ?? false;\n const targetMarker = edge.targetMarker ?? false;\n const sourceAncestors = ancestorIds(edge.source, nodes);\n const targetAncestors = ancestorIds(edge.target, nodes);\n const open = new Set([...sourceAncestors, ...targetAncestors]);\n const sourceInsideTarget = sourceAncestors.includes(edge.target);\n const targetInsideSource = targetAncestors.includes(edge.source);\n const container = sourceInsideTarget\n ? edge.target\n : targetInsideSource\n ? edge.source\n : sourceAncestors.find((id) => targetAncestors.includes(id));\n const frame = container === undefined ? undefined : nodes.get(container)?.box;\n\n // An edge can cross its container's frame wherever the title and icon leave room.\n const obstaclesFor = (clearance: number) =>\n [...nodes].flatMap(([id, node]) =>\n (open.has(id) ? (node.decorations ?? []) : [node.box]).map((box) => ({ id, ...bounds(box, clearance) })),\n );\n function search(\n starts: readonly Port[],\n ends: readonly Port[],\n clearance: number,\n separate: { readonly start: boolean; readonly end: boolean },\n owner?: string,\n ): Point[] | undefined {\n const obstacles = obstaclesFor(clearance);\n const available = (port: Port, id: string): boolean =>\n !crosses(\n port.anchor,\n port.lead,\n obstacles.filter((box) => box.id !== id || open.has(id)),\n );\n const usableStarts = starts.filter(\n (port) =>\n available(port, edge.source) &&\n (!separate.start || anchors.clear(edge.source, sourceBox, port.anchor, sourceMarker)),\n );\n const usableEnds = ends.filter(\n (port) =>\n available(port, edge.target) &&\n (!separate.end || anchors.clear(edge.target, targetBox, port.anchor, targetMarker)),\n );\n const cost: RouteCost = (axis, from, to) => congestion.cost(axis, from, to, owner);\n const frameRegion = frame && bounds(frame, -clearance);\n // Search near the endpoints first; on large diagrams the full grid is far bigger than any good route needs.\n const nearSource = bounds(sourceBox, searchMargin);\n const nearTarget = bounds(targetBox, searchMargin);\n const outer = frameRegion ?? { left: -Infinity, right: Infinity, top: -Infinity, bottom: Infinity };\n const nearby: Bounds = {\n left: Math.max(Math.min(nearSource.left, nearTarget.left), outer.left),\n right: Math.min(Math.max(nearSource.right, nearTarget.right), outer.right),\n top: Math.max(Math.min(nearSource.top, nearTarget.top), outer.top),\n bottom: Math.min(Math.max(nearSource.bottom, nearTarget.bottom), outer.bottom),\n };\n const local = obstacles.filter(\n (box) => box.left < nearby.right && box.right > nearby.left && box.top < nearby.bottom && box.bottom > nearby.top,\n );\n return (\n (local.length < obstacles.length ? routeBetween(usableStarts, usableEnds, local, cost, nearby) : undefined) ??\n routeBetween(usableStarts, usableEnds, obstacles, cost, frameRegion)\n );\n }\n // A diagram with one awkward connector is more useful than no diagram, so the last resort is a straight line.\n function fallback(starts: readonly Port[], ends: readonly Port[]): Point[] {\n const [nearest] = starts\n .flatMap((start) => ends.map((end) => [start.anchor, end.anchor] as const))\n .sort(([a, b], [c, d]) => pointDistance(a, b) - pointDistance(c, d));\n if (!nearest) throw new Error(`Relationship \"${edge.id}\" has no ports to connect.`);\n warn?.(`ArchiMate could not find an orthogonal route for relationship \"${edge.id}\" and drew a direct line.`);\n return [...nearest];\n }\n function record(points: readonly Point[], owner?: string): void {\n const first = points[0];\n const last = points.at(-1);\n if (!first || !last || points.length < 2) {\n throw new Error(`Route for relationship \"${edge.id}\" has fewer than two points.`);\n }\n anchors.reserve(edge.source, sourceBox, first, sourceMarker);\n anchors.reserve(edge.target, targetBox, last, targetMarker);\n routes.set(edge.id, [...points]);\n for (let index = 1; index < points.length; index++) {\n const start = points[index - 1];\n const end = points[index];\n if (!start || !end) continue;\n const axis = start.y === end.y ? 'x' : 'y';\n const across = start[otherAxis(axis)];\n congestion.add(axis, across, Math.min(start[axis], end[axis]), Math.max(start[axis], end[axis]), owner);\n }\n }\n return {\n sourceBox,\n targetBox,\n sourceMarker,\n targetMarker,\n sourceInsideTarget,\n targetInsideSource,\n frame,\n obstaclesFor,\n search,\n fallback,\n record,\n };\n}\n\n// Self-relationships and straight connections are recorded at once; the rest wait until the bundles are in place.\nfunction routeSingles(state: RoutingState, edges: readonly RoutingEdge[]): (() => void)[] {\n const { anchors, congestion, portFraction } = state;\n const deferred: (() => void)[] = [];\n const loops = new Map<string, number>();\n for (const edge of edges) {\n const {\n sourceBox,\n targetBox,\n sourceMarker,\n targetMarker,\n sourceInsideTarget,\n targetInsideSource,\n frame,\n obstaclesFor,\n search,\n fallback,\n record,\n } = prepare(state, edge);\n const nestedEdge = sourceInsideTarget || targetInsideSource;\n const sourcePorts = ports(sourceBox, portFraction(edge.source), targetInsideSource);\n const targetPorts = ports(targetBox, portFraction(edge.target), sourceInsideTarget);\n const starts = nestedEdge ? sourcePorts : facing(sourcePorts, sourceBox, targetBox);\n const ends = nestedEdge ? targetPorts : facing(targetPorts, targetBox, sourceBox);\n if (edge.source === edge.target) {\n const lane = loops.get(edge.source) ?? 0;\n loops.set(edge.source, lane + 1);\n const obstacles = obstaclesFor(clearances.comfortable).filter(({ id }) => id !== edge.source);\n const region = frame && bounds(frame);\n const inside = ({ x, y }: Point) =>\n !region || (x >= region.left && x <= region.right && y >= region.top && y <= region.bottom);\n const loopsAvailable = loopCandidates(sourceBox, lane);\n const clear = loopsAvailable.find((points) => {\n const first = points[0];\n const last = points.at(-1);\n return (\n first !== undefined &&\n last !== undefined &&\n anchors.clear(edge.source, sourceBox, first, sourceMarker) &&\n anchors.clear(edge.source, sourceBox, last, targetMarker) &&\n points.every((point, index) => {\n const previous = points[index - 1];\n return inside(point) && (!previous || !crosses(previous, point, obstacles));\n })\n );\n });\n if (!clear) {\n state.warn?.(`ArchiMate could not keep the self-relationship \"${edge.id}\" clear of other shapes and anchors.`);\n }\n record(clear ?? required(loopsAvailable[lane % loopsAvailable.length], 'a self-relationship loop'));\n continue;\n }\n const direct =\n !sourceInsideTarget && !targetInsideSource\n ? straightRoute(\n sourceBox,\n targetBox,\n obstaclesFor(clearances.comfortable).filter(({ id }) => id !== edge.source && id !== edge.target),\n congestion.cost,\n (from, to) =>\n anchors.clear(edge.source, sourceBox, from, sourceMarker) &&\n anchors.clear(edge.target, targetBox, to, targetMarker),\n { gap: sourceMarker || targetMarker ? markerGap : trackGap, parallel: state.parallelCount(edge) },\n )\n : undefined;\n if (direct) record(direct);\n else {\n const apart = { start: true, end: true };\n const together = { start: false, end: false };\n const { comfortable, tight } = clearances;\n deferred.push(() => {\n record(\n search(starts, ends, comfortable, apart) ??\n search(starts, ends, comfortable, together) ??\n search(starts, ends, tight, together) ??\n fallback(starts, ends),\n );\n });\n }\n }\n return deferred;\n}\n\nfunction routeBundles(state: RoutingState, { ports: sharedPorts, order: routingOrder }: SharedAnchors): void {\n const { nodes, bundles, portFraction } = state;\n for (const group of routingOrder) {\n const shared = sharedPorts.get(group.id);\n if (!shared) continue;\n const sharedBox = boxOf(nodes, group.element);\n // The farthest member lays the trunk; nearer members then branch off it.\n const members = group.members.toSorted((a, b) => {\n const far = (edge: RoutingEdge) => boxOf(nodes, group.sharedEnd === 'start' ? edge.target : edge.source);\n return pointDistance(centre(far(b)), centre(sharedBox)) - pointDistance(centre(far(a)), centre(sharedBox));\n });\n for (const edge of members) {\n const context = prepare(state, edge);\n const farId = group.sharedEnd === 'start' ? edge.target : edge.source;\n const farBox = boxOf(nodes, farId);\n const fraction = portFraction(farId);\n const facingSide = farSide(group.side, shared.anchor, farBox);\n const insetX = Math.min(leadLength, farBox.width / 4);\n const insetY = Math.min(leadLength, farBox.height / 4);\n const across = facingSide === 'top' || facingSide === 'bottom' ? 'x' : 'y';\n const low = across === 'x' ? farBox.x + insetX : farBox.y + insetY;\n const high = across === 'x' ? farBox.x + farBox.width - insetX : farBox.y + farBox.height - insetY;\n const straightAcross =\n facingSide === oppositeSide[group.side] && shared.anchor[across] >= low && shared.anchor[across] <= high;\n const along = straightAcross ? shared.anchor[across] : low + fraction * (high - low);\n // Other relationships may already hold the best spot, so offer the rest of the facing side as well.\n // A branch that rises beside a nearer element can enter without a jog where it already runs.\n const besideElements = [...nodes.values()]\n .flatMap(({ box }) =>\n across === 'x'\n ? [box.x - clearances.comfortable, box.x + box.width + clearances.comfortable]\n : [box.y - clearances.comfortable, box.y + box.height + clearances.comfortable],\n )\n .filter((position) => position >= low && position <= high);\n const preferred = [\n along,\n ...besideElements,\n ...Array.from({ length: 5 }, (_, index) => low + ((index + 0.5) * (high - low)) / 5),\n ].map((position) => sidePort(farBox, facingSide, position));\n const anyFar = facing(ports(farBox, fraction, false), farBox, sharedBox);\n // The shared anchor is reserved for the whole bundle, so only the far end keeps clear of other anchors.\n const attempt = (far: readonly Port[], clearance: number, separate: boolean) =>\n group.sharedEnd === 'start'\n ? context.search([shared], far, clearance, { start: false, end: separate }, group.id)\n : context.search(far, [shared], clearance, { start: separate, end: false }, group.id);\n const { comfortable, tight } = clearances;\n const points =\n attempt(preferred, comfortable, true) ??\n attempt(anyFar, comfortable, true) ??\n attempt(anyFar, comfortable, false) ??\n attempt(anyFar, tight, false) ??\n (group.sharedEnd === 'start' ? context.fallback([shared], anyFar) : context.fallback(anyFar, [shared]));\n context.record(points, group.members.length > 1 ? group.id : undefined);\n if (group.members.length > 1) bundles.set(edge.id, { id: group.id, sharedEnd: group.sharedEnd });\n }\n }\n}\n\nexport function routeArchitecture(\n nodes: ReadonlyMap<string, RoutingNode>,\n edges: readonly RoutingEdge[],\n { warn }: RoutingOptions = {},\n): ArchitectureRoutes {\n const state = createRoutingState(nodes, edges, warn);\n const groups = planBundles(nodes, edges);\n const shared = placeSharedAnchors(nodes, groups, state.anchors);\n const grouped = new Set([...groups.values()].flatMap(({ members }) => members.map(({ id }) => id)));\n const detours = routeSingles(\n state,\n edges.filter(({ id }) => !grouped.has(id)),\n );\n // Reserve straight connectors first, then planned bundles, so detours route around both.\n routeBundles(state, shared);\n for (const detour of detours) detour();\n return { routes: state.routes, bundles: state.bundles };\n}\n"]}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { Arrangement, LayoutRelationship, PlacedNode, SizedNode } from './architectureLayout.js';
|
|
2
|
+
export declare function placeConnectedLayers(nodes: readonly SizedNode[], layers: readonly string[], relationships: readonly LayoutRelationship[], gap: number, layerGap: number, maxRowWidth: number): Arrangement;
|
|
3
|
+
export declare function sequence(nodes: readonly SizedNode[], flows: ReadonlyMap<string, readonly string[]>): PlacedNode[];
|