@bpmnkit/core 1.16.0 → 1.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/dist/bpmn/auto-layout.d.ts +0 -8
  2. package/dist/bpmn/auto-layout.js +432 -59
  3. package/dist/bpmn/make-room.js +114 -0
  4. package/dist/bpmn/place-new-shapes.js +4 -2
  5. package/dist/layout/collaboration/crossings.d.ts +13 -0
  6. package/dist/layout/collaboration/crossings.js +37 -0
  7. package/dist/layout/collaboration/docked-labels.d.ts +21 -0
  8. package/dist/layout/collaboration/docked-labels.js +65 -0
  9. package/dist/layout/collaboration/message-tracks.d.ts +20 -0
  10. package/dist/layout/collaboration/message-tracks.js +78 -0
  11. package/dist/layout/collaboration/stack-crossings.d.ts +38 -0
  12. package/dist/layout/collaboration/stack-crossings.js +155 -0
  13. package/dist/layout/grid/edge-labels.js +21 -10
  14. package/dist/layout/layered/coords.d.ts +13 -0
  15. package/dist/layout/layered/coords.js +211 -0
  16. package/dist/layout/layered/index.d.ts +21 -0
  17. package/dist/layout/layered/index.js +288 -0
  18. package/dist/layout/layered/layers.d.ts +60 -0
  19. package/dist/layout/layered/layers.js +374 -0
  20. package/dist/layout/layered/route.d.ts +66 -0
  21. package/dist/layout/layered/route.js +369 -0
  22. package/dist/layout/layout-engine.d.ts +6 -2
  23. package/dist/layout/layout-engine.js +4 -2
  24. package/dist/layout/semantic/bands.js +8 -2
  25. package/dist/layout/semantic/graph.d.ts +33 -1
  26. package/dist/layout/semantic/graph.js +200 -4
  27. package/dist/layout/semantic/index.d.ts +8 -2
  28. package/dist/layout/semantic/index.js +114 -14
  29. package/dist/layout/semantic/lanes.d.ts +40 -0
  30. package/dist/layout/semantic/lanes.js +198 -0
  31. package/dist/layout/semantic/place.d.ts +44 -2
  32. package/dist/layout/semantic/place.js +220 -21
  33. package/dist/layout/semantic/route.js +35 -2
  34. package/dist/layout/types.d.ts +0 -8
  35. package/package.json +1 -1
@@ -0,0 +1,211 @@
1
+ /** Clear space between two nodes of one column, and around a dummy. */
2
+ const NODE_GAP = 40;
3
+ const DUMMY_GAP = 20;
4
+ const key = (a, b) => (a < b ? `${a}\u0001${b}` : `${b}\u0001${a}`);
5
+ /**
6
+ * Type-1 conflicts (Brandes–Köpf): a non-inner segment crossing an inner one
7
+ * (dummy to dummy) loses its claim to be straight, so long flows stay
8
+ * straight. Boundary segments are never aligned either.
9
+ */
10
+ function conflicts(lg) {
11
+ const out = new Set();
12
+ const pos = new Map();
13
+ for (const layer of lg.layers)
14
+ layer.forEach((id, i) => pos.set(id, i));
15
+ for (const segs of lg.pred.values()) {
16
+ for (const s of segs)
17
+ if (s.bias !== 0)
18
+ out.add(key(s.from, s.to));
19
+ }
20
+ for (let r = 1; r < lg.layers.length; r++) {
21
+ const prev = lg.layers[r - 1] ?? [];
22
+ const layer = lg.layers[r] ?? [];
23
+ let k0 = 0;
24
+ let scan = 0;
25
+ const last = layer[layer.length - 1];
26
+ layer.forEach((v, i) => {
27
+ const inner = lg.dummies.has(v)
28
+ ? (lg.pred.get(v) ?? []).find((s) => lg.dummies.has(s.from))?.from
29
+ : undefined;
30
+ const k1 = inner !== undefined ? (pos.get(inner) ?? 0) : prev.length;
31
+ if (inner === undefined && v !== last)
32
+ return;
33
+ for (const w of layer.slice(scan, i + 1)) {
34
+ for (const s of lg.pred.get(w) ?? []) {
35
+ const p = pos.get(s.from) ?? 0;
36
+ if ((p < k0 || k1 < p) && !(lg.dummies.has(s.from) && lg.dummies.has(w))) {
37
+ out.add(key(s.from, w));
38
+ }
39
+ }
40
+ }
41
+ scan = i + 1;
42
+ k0 = k1;
43
+ });
44
+ }
45
+ return out;
46
+ }
47
+ /** Block roots and alignment chains for one of the four directions. */
48
+ function align(layers, neighbours, blocked) {
49
+ const root = new Map();
50
+ const next = new Map();
51
+ const pos = new Map();
52
+ for (const layer of layers) {
53
+ layer.forEach((id, i) => {
54
+ root.set(id, id);
55
+ next.set(id, id);
56
+ pos.set(id, i);
57
+ });
58
+ }
59
+ for (const layer of layers) {
60
+ let prevIdx = -1;
61
+ for (const v of layer) {
62
+ const ws = neighbours(v).sort((a, b) => (pos.get(a) ?? 0) - (pos.get(b) ?? 0));
63
+ if (ws.length === 0)
64
+ continue;
65
+ const mp = (ws.length - 1) / 2;
66
+ for (let i = Math.floor(mp); i <= Math.ceil(mp); i++) {
67
+ const w = ws[i];
68
+ const pw = pos.get(w) ?? 0;
69
+ if (next.get(v) === v && prevIdx < pw && !blocked.has(key(v, w))) {
70
+ next.set(w, v);
71
+ const r = root.get(w);
72
+ root.set(v, r);
73
+ next.set(v, r);
74
+ prevIdx = pw;
75
+ }
76
+ }
77
+ }
78
+ }
79
+ return { root, next };
80
+ }
81
+ /** Pack blocks as tightly as separations allow: longest path over the block graph, then pull back. */
82
+ function compact(layers, root, sep) {
83
+ const edges = new Map();
84
+ const inEdges = new Map();
85
+ const roots = [];
86
+ const known = new Set();
87
+ for (const layer of layers) {
88
+ for (const id of layer) {
89
+ const r = root.get(id);
90
+ if (!known.has(r)) {
91
+ known.add(r);
92
+ roots.push(r);
93
+ edges.set(r, new Map());
94
+ inEdges.set(r, new Map());
95
+ }
96
+ }
97
+ }
98
+ for (const layer of layers) {
99
+ for (let i = 1; i < layer.length; i++) {
100
+ const u = layer[i - 1];
101
+ const v = layer[i];
102
+ const ru = root.get(u);
103
+ const rv = root.get(v);
104
+ const w = Math.max(edges.get(ru)?.get(rv) ?? 0, sep(u, v));
105
+ edges.get(ru)?.set(rv, w);
106
+ inEdges.get(rv)?.set(ru, w);
107
+ }
108
+ }
109
+ const indeg = new Map();
110
+ for (const r of roots)
111
+ indeg.set(r, inEdges.get(r)?.size ?? 0);
112
+ const order = roots.filter((r) => indeg.get(r) === 0);
113
+ for (let i = 0; i < order.length; i++) {
114
+ for (const s of (edges.get(order[i]) ?? new Map()).keys()) {
115
+ const left = (indeg.get(s) ?? 0) - 1;
116
+ indeg.set(s, left);
117
+ if (left === 0)
118
+ order.push(s);
119
+ }
120
+ }
121
+ const xs = new Map();
122
+ for (const r of order) {
123
+ let x = 0;
124
+ for (const [p, w] of inEdges.get(r) ?? [])
125
+ x = Math.max(x, (xs.get(p) ?? 0) + w);
126
+ xs.set(r, x);
127
+ }
128
+ for (let i = order.length - 1; i >= 0; i--) {
129
+ const r = order[i];
130
+ let min = Number.POSITIVE_INFINITY;
131
+ for (const [s, w] of edges.get(r) ?? [])
132
+ min = Math.min(min, (xs.get(s) ?? 0) - w);
133
+ if (min !== Number.POSITIVE_INFINITY)
134
+ xs.set(r, Math.max(xs.get(r) ?? 0, min));
135
+ }
136
+ const out = new Map();
137
+ for (const layer of layers)
138
+ for (const id of layer)
139
+ out.set(id, xs.get(root.get(id)) ?? 0);
140
+ return out;
141
+ }
142
+ /**
143
+ * Brandes–Köpf centre lines (the cross-column axis here is y): the balanced
144
+ * mean, then the four aligned variants, each kept only while it holds every
145
+ * column's spacing. The caller picks one by how the flows would route.
146
+ */
147
+ export function yCandidates(lg, extent) {
148
+ const blocked = conflicts(lg);
149
+ const gap = (a, b) => lg.dummies.has(a) || lg.dummies.has(b) ? DUMMY_GAP : NODE_GAP;
150
+ const runs = [];
151
+ for (const up of [true, false]) {
152
+ const vertical = up ? lg.layers : [...lg.layers].reverse();
153
+ for (const leftFirst of [true, false]) {
154
+ const layers = leftFirst ? vertical.map((l) => [...l]) : vertical.map((l) => [...l].reverse());
155
+ const neighbours = (id) => up ? (lg.pred.get(id) ?? []).map((s) => s.from) : (lg.succ.get(id) ?? []).map((s) => s.to);
156
+ const { root } = align(layers, neighbours, blocked);
157
+ const sep = (u, v) => (leftFirst ? extent(u).below + extent(v).above : extent(u).above + extent(v).below) +
158
+ gap(u, v);
159
+ const ys = compact(layers, root, sep);
160
+ if (!leftFirst)
161
+ for (const [id, y] of ys)
162
+ ys.set(id, -y);
163
+ runs.push(ys);
164
+ }
165
+ }
166
+ const span = (ys) => {
167
+ let lo = Number.POSITIVE_INFINITY;
168
+ let hi = Number.NEGATIVE_INFINITY;
169
+ for (const [id, y] of ys) {
170
+ lo = Math.min(lo, y - extent(id).above);
171
+ hi = Math.max(hi, y + extent(id).below);
172
+ }
173
+ return [lo, hi];
174
+ };
175
+ let smallest = 0;
176
+ let width = Number.POSITIVE_INFINITY;
177
+ runs.forEach((ys, i) => {
178
+ const [lo, hi] = span(ys);
179
+ if (hi - lo < width) {
180
+ width = hi - lo;
181
+ smallest = i;
182
+ }
183
+ });
184
+ const [minS, maxS] = span(runs[smallest]);
185
+ runs.forEach((ys, i) => {
186
+ const [lo, hi] = span(ys);
187
+ const delta = i % 2 === 0 ? minS - lo : maxS - hi;
188
+ for (const [id, y] of ys)
189
+ ys.set(id, y + delta);
190
+ });
191
+ const balanced = new Map();
192
+ for (const id of runs[0].keys()) {
193
+ const v = runs.map((ys) => ys.get(id) ?? 0).sort((a, b) => a - b);
194
+ balanced.set(id, Math.round((v[1] + v[2]) / 2));
195
+ }
196
+ return [balanced, ...runs].filter((ys) => separated(lg, ys, extent, gap));
197
+ }
198
+ /** True when every column keeps its order and spacing (the balanced mean can break it). */
199
+ function separated(lg, ys, extent, gap) {
200
+ for (const layer of lg.layers) {
201
+ for (let i = 1; i < layer.length; i++) {
202
+ const u = layer[i - 1];
203
+ const v = layer[i];
204
+ const need = extent(u).below + extent(v).above + gap(u, v);
205
+ if ((ys.get(v) ?? 0) - (ys.get(u) ?? 0) < need - 0.5)
206
+ return false;
207
+ }
208
+ }
209
+ return true;
210
+ }
211
+ //# sourceMappingURL=coords.js.map
@@ -0,0 +1,21 @@
1
+ import type { BpmnSequenceFlow } from "../../bpmn/bpmn-model.js";
2
+ import type { SemanticGraph } from "../semantic/graph.js";
3
+ import type { Bounds, LayoutEdge } from "../types.js";
4
+ export interface LayeredPlacement {
5
+ bounds: Map<string, Bounds>;
6
+ edges: LayoutEdge[];
7
+ /** 0 for nodes on their component start's line, 1 elsewhere. */
8
+ row: Map<string, number>;
9
+ }
10
+ /**
11
+ * Sugiyama layout of one lane-free scope: columns by longest path with a
12
+ * network-simplex pull, dummy nodes for long flows, median/transpose ordering,
13
+ * Brandes–Köpf centre lines and orthogonal routing with one track per jog in
14
+ * each gutter. Boundary events dock as in the semantic engine; loops run in
15
+ * corridors past both ends.
16
+ */
17
+ export declare function layeredPlace(graph: SemanticGraph, flows: BpmnSequenceFlow[], sizes: Map<string, {
18
+ width: number;
19
+ height: number;
20
+ }>, titled: ReadonlySet<string>, slotArtifacts: boolean): LayeredPlacement;
21
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,288 @@
1
+ import { boundarySide } from "../semantic/bands.js";
2
+ import { COMPONENT_GAP, artifactOwnersOf, columnGaps, dockBoundaryEvents, externalLabelWidth, placeArtifacts, } from "../semantic/place.js";
3
+ import { LABEL_HEIGHT } from "../types.js";
4
+ import { yCandidates } from "./coords.js";
5
+ import { assignLayers, buildLayering, orderLayers, stackedFlows } from "./layers.js";
6
+ import { Router, drawPlan, edgeOf, jogsOf, orderTracks, planFlow, } from "./route.js";
7
+ /** Gap between an event or gateway and its label below; see `semantic/index.ts`. */
8
+ const LABEL_OFFSET = 4;
9
+ /** How far a docked boundary event hangs past its host's border. */
10
+ const BOUNDARY_HANG = 18;
11
+ /** Spacing between parallel tracks in one gutter. */
12
+ const TRACK = 12;
13
+ /** Gap between loose nodes in their row under the diagram. */
14
+ const LOOSE_GAP = 40;
15
+ const DEFAULT_SIZE = { width: 100, height: 80 };
16
+ /** Nominal column pitch, to weigh a flow's horizontal run against its vertical travel. */
17
+ const PITCH = 160;
18
+ /**
19
+ * The candidate whose flows route with the fewest bends; ties go to the more
20
+ * even flow lengths (smallest sum of squares), then the lower one.
21
+ */
22
+ function pickY(graph, lg, candidates, extent, size, sideOf) {
23
+ const columns = new Map();
24
+ for (const [id, r] of lg.rank) {
25
+ if (lg.dummies.has(id))
26
+ continue;
27
+ const list = columns.get(r);
28
+ if (list)
29
+ list.push(id);
30
+ else
31
+ columns.set(r, [id]);
32
+ }
33
+ const flows = new Map();
34
+ for (const list of graph.outgoing.values())
35
+ for (const f of list)
36
+ flows.set(f.id, f);
37
+ let best = candidates[0];
38
+ let bestKey = [
39
+ Number.POSITIVE_INFINITY,
40
+ Number.POSITIVE_INFINITY,
41
+ Number.POSITIVE_INFINITY,
42
+ ];
43
+ for (const y of candidates) {
44
+ const input = {
45
+ graph,
46
+ y,
47
+ rank: lg.rank,
48
+ columns,
49
+ height: (id) => size(id).height,
50
+ sideOf,
51
+ };
52
+ let bends = 0;
53
+ let squares = 0;
54
+ for (const [id, chain] of lg.chains) {
55
+ const plan = planFlow(input, flows.get(id), chain);
56
+ const n = chain.length;
57
+ if (plan.exit === "stack") {
58
+ const d = Math.abs(plan.ys[1] - plan.ys[0]);
59
+ squares += d * d;
60
+ continue;
61
+ }
62
+ let travel = 0;
63
+ for (let i = 0; i + 1 < n; i++) {
64
+ const d = Math.abs(plan.ys[i + 1] - plan.ys[i]);
65
+ travel += d;
66
+ if (d > 0)
67
+ bends += 2;
68
+ }
69
+ if (plan.exit !== "right") {
70
+ bends += 1;
71
+ travel += Math.abs(plan.ys[0] - (y.get(chain[0]) ?? 0));
72
+ }
73
+ if (plan.entry === "side") {
74
+ bends += 1;
75
+ travel += Math.abs(plan.ys[n - 1] - (y.get(chain[n - 1]) ?? 0));
76
+ }
77
+ const length = (n - 1) * PITCH + travel;
78
+ squares += length * length;
79
+ }
80
+ let lo = Number.POSITIVE_INFINITY;
81
+ let hi = Number.NEGATIVE_INFINITY;
82
+ for (const [id, v] of y) {
83
+ lo = Math.min(lo, v - extent(id).above);
84
+ hi = Math.max(hi, v + extent(id).below);
85
+ }
86
+ const key = [bends, squares, hi - lo];
87
+ if (key[0] < bestKey[0] ||
88
+ (key[0] === bestKey[0] &&
89
+ (key[1] < bestKey[1] || (key[1] === bestKey[1] && key[2] < bestKey[2])))) {
90
+ best = y;
91
+ bestKey = key;
92
+ }
93
+ }
94
+ return best;
95
+ }
96
+ /**
97
+ * Sugiyama layout of one lane-free scope: columns by longest path with a
98
+ * network-simplex pull, dummy nodes for long flows, median/transpose ordering,
99
+ * Brandes–Köpf centre lines and orthogonal routing with one track per jog in
100
+ * each gutter. Boundary events dock as in the semantic engine; loops run in
101
+ * corridors past both ends.
102
+ */
103
+ export function layeredPlace(graph, flows, sizes, titled, slotArtifacts) {
104
+ const size = (id) => sizes.get(id) ?? DEFAULT_SIZE;
105
+ const sideOf = (eventId) => {
106
+ const event = graph.byId.get(eventId);
107
+ return boundarySide(event, titled.has(event.attachedToRef));
108
+ };
109
+ const extents = new Map();
110
+ for (const node of graph.nodes) {
111
+ const h = size(node.id).height;
112
+ const label = node.name ? externalLabelWidth(node.type, node.name) : undefined;
113
+ extents.set(node.id, {
114
+ above: h / 2,
115
+ below: h / 2 + (label !== undefined ? LABEL_OFFSET + LABEL_HEIGHT : 0),
116
+ });
117
+ }
118
+ for (const [host, events] of graph.attachers) {
119
+ const ext = extents.get(host);
120
+ if (!ext)
121
+ continue;
122
+ const h = size(host).height;
123
+ for (const event of events) {
124
+ const reach = h / 2 + BOUNDARY_HANG + (event.name ? LABEL_OFFSET + LABEL_HEIGHT : 0);
125
+ if (sideOf(event.id) > 0)
126
+ ext.below = Math.max(ext.below, reach);
127
+ else
128
+ ext.above = Math.max(ext.above, reach);
129
+ }
130
+ }
131
+ const extent = (id) => extents.get(id) ?? { above: 0, below: 0 };
132
+ const biasOf = (flow) => graph.byId.get(flow.sourceRef)?.type === "boundaryEvent" ? sideOf(flow.sourceRef) * 0.5 : 0;
133
+ const hasFlow = (id) => (graph.outgoing.get(id) ?? []).length > 0 || (graph.incoming.get(id) ?? []).length > 0;
134
+ // ── Columns, order and centre lines, per component, stacked top to bottom ──
135
+ const owners = slotArtifacts ? artifactOwnersOf(graph) : new Map();
136
+ const loose = [];
137
+ const parts = [];
138
+ const y = new Map();
139
+ const row = new Map();
140
+ graph.ranks.clear();
141
+ let cursor = 0;
142
+ graph.components.forEach((all, c) => {
143
+ const members = all.filter((id) => graph.byId.has(id));
144
+ if (members.length === 0)
145
+ return;
146
+ if (members.length === 1 && !hasFlow(members[0])) {
147
+ if (!owners.has(members[0]))
148
+ loose.push(members[0]);
149
+ return;
150
+ }
151
+ const start = graph.starts[c] ?? members[0];
152
+ const stacks = stackedFlows(graph, members, sideOf);
153
+ const rank = assignLayers(graph, members, stacks);
154
+ const lg = buildLayering(graph, members, start, rank, biasOf);
155
+ orderLayers(lg, stacks);
156
+ const ys = pickY(graph, lg, yCandidates(lg, extent), extent, size, sideOf);
157
+ let top = Number.POSITIVE_INFINITY;
158
+ let bottom = Number.NEGATIVE_INFINITY;
159
+ for (const [id, v] of ys) {
160
+ top = Math.min(top, v - extent(id).above);
161
+ bottom = Math.max(bottom, v + extent(id).below);
162
+ }
163
+ const dy = cursor - top;
164
+ for (const [id, v] of ys)
165
+ y.set(id, Math.round(v + dy));
166
+ for (const [id, r] of lg.rank)
167
+ if (!lg.dummies.has(id))
168
+ graph.ranks.set(id, r);
169
+ const spine = y.get(start);
170
+ for (const id of members)
171
+ row.set(id, y.get(id) === spine ? 0 : 1);
172
+ cursor = Math.round(bottom + dy) + COMPONENT_GAP;
173
+ parts.push(lg);
174
+ });
175
+ // ── Routes on centre lines: which flows jog in which gutter ──
176
+ const columns = new Map();
177
+ for (const node of graph.nodes) {
178
+ const r = graph.ranks.get(node.id);
179
+ if (r === undefined)
180
+ continue;
181
+ const list = columns.get(r);
182
+ if (list)
183
+ list.push(node.id);
184
+ else
185
+ columns.set(r, [node.id]);
186
+ }
187
+ const rankOf = new Map();
188
+ for (const lg of parts)
189
+ for (const [id, r] of lg.rank)
190
+ rankOf.set(id, r);
191
+ const plans = [];
192
+ const chainOf = new Map();
193
+ for (const lg of parts)
194
+ for (const [flow, chain] of lg.chains)
195
+ chainOf.set(flow, chain);
196
+ const input = { graph, y, rank: rankOf, columns, height: (id) => size(id).height, sideOf };
197
+ for (const flow of flows) {
198
+ const chain = chainOf.get(flow.id);
199
+ if (chain)
200
+ plans.push(planFlow(input, flow, chain));
201
+ }
202
+ const gutters = new Map();
203
+ for (const plan of plans) {
204
+ for (const jog of jogsOf(plan)) {
205
+ const list = gutters.get(jog.gutter);
206
+ if (list)
207
+ list.push(jog);
208
+ else
209
+ gutters.set(jog.gutter, [jog]);
210
+ }
211
+ }
212
+ // ── Column x: widest node, gaps wide enough for labels and tracks ──
213
+ const colWidth = new Map();
214
+ for (const [r, ids] of columns) {
215
+ for (const id of ids)
216
+ colWidth.set(r, Math.max(colWidth.get(r) ?? 0, size(id).width));
217
+ }
218
+ const ranks = [...colWidth.keys()].sort((a, b) => a - b);
219
+ const gaps = columnGaps(graph, sizes, colWidth, ranks);
220
+ const colX = new Map();
221
+ let x = 0;
222
+ for (const [i, r] of ranks.entries()) {
223
+ if (i > 0) {
224
+ const tracks = (gutters.get(r) ?? []).length;
225
+ x += Math.max(gaps.get(r) ?? 0, (tracks + 1) * TRACK);
226
+ }
227
+ colX.set(r, x);
228
+ x += colWidth.get(r) ?? 0;
229
+ }
230
+ const bounds = new Map();
231
+ for (const [r, ids] of columns) {
232
+ for (const id of ids) {
233
+ const s = size(id);
234
+ bounds.set(id, {
235
+ x: (colX.get(r) ?? 0) + ((colWidth.get(r) ?? 0) - s.width) / 2,
236
+ y: (y.get(id) ?? 0) - s.height / 2,
237
+ width: s.width,
238
+ height: s.height,
239
+ });
240
+ }
241
+ }
242
+ const track = new Map();
243
+ for (const [g, jogs] of gutters) {
244
+ const i = ranks.indexOf(g);
245
+ const prev = ranks[i - 1];
246
+ if (prev === undefined)
247
+ continue;
248
+ const left = (colX.get(prev) ?? 0) + (colWidth.get(prev) ?? 0);
249
+ const width = (colX.get(g) ?? 0) - left;
250
+ orderTracks(jogs).forEach((jog, k, all) => {
251
+ track.set(`${jog.flow}\u0001${g}`, Math.round(left + (width * (k + 1)) / (all.length + 1)));
252
+ });
253
+ }
254
+ // ── Docked events, loose nodes and slotted artifacts ──
255
+ dockBoundaryEvents(graph, bounds, titled);
256
+ let lx = 0;
257
+ for (const id of loose) {
258
+ const s = size(id);
259
+ bounds.set(id, { x: lx, y: cursor, width: s.width, height: s.height });
260
+ lx += s.width + LOOSE_GAP;
261
+ }
262
+ placeArtifacts(graph, owners, bounds);
263
+ // ── Draw: forward flows on their tracks, then loops around them ──
264
+ const router = new Router(graph, bounds);
265
+ const routes = new Map();
266
+ for (const plan of plans) {
267
+ const points = router.settle(plan.flow, drawPlan(plan, bounds, (flow, g) => track.get(`${flow}\u0001${g}`) ?? 0));
268
+ router.commit(points);
269
+ routes.set(plan.flow.id, points);
270
+ }
271
+ for (const flow of flows) {
272
+ if (routes.has(flow.id) || !bounds.has(flow.sourceRef) || !bounds.has(flow.targetRef))
273
+ continue;
274
+ const points = router.loop(flow);
275
+ if (!points)
276
+ continue;
277
+ router.commit(points);
278
+ routes.set(flow.id, points);
279
+ }
280
+ const edges = [];
281
+ for (const flow of flows) {
282
+ const points = routes.get(flow.id);
283
+ if (points)
284
+ edges.push(edgeOf(flow, points));
285
+ }
286
+ return { bounds, edges, row };
287
+ }
288
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,60 @@
1
+ import type { BpmnSequenceFlow } from "../../bpmn/bpmn-model.js";
2
+ import type { SemanticGraph } from "../semantic/graph.js";
3
+ /** One edge between neighbouring columns: a whole flow, or one piece of a long one. */
4
+ export interface Segment {
5
+ from: string;
6
+ to: string;
7
+ flow: string;
8
+ /**
9
+ * Pull toward the side a boundary event docks on (+0.5 below, -0.5 above),
10
+ * so its handler orders past the host's own successor. Non-zero segments are
11
+ * never aligned straight: the flow leaves the event, not the host's centre.
12
+ */
13
+ bias: number;
14
+ }
15
+ /**
16
+ * A flow drawn as one vertical drop inside a column: `mover` sits right under
17
+ * (`side` 1) or over (-1) `anchor`, in the same column.
18
+ */
19
+ export interface Stack {
20
+ flow: string;
21
+ mover: string;
22
+ anchor: string;
23
+ side: number;
24
+ }
25
+ /** A component cut into columns, long flows carried by dummy nodes. */
26
+ export interface Layering {
27
+ /** Columns left to right, each top to bottom: node ids and dummy ids. */
28
+ layers: string[][];
29
+ rank: Map<string, number>;
30
+ /** Dummy id → the flow it carries. */
31
+ dummies: Map<string, string>;
32
+ succ: Map<string, Segment[]>;
33
+ pred: Map<string, Segment[]>;
34
+ /** Forward flow id → its chain of ids, source (the host for a boundary event) to target. */
35
+ chains: Map<string, string[]>;
36
+ }
37
+ /**
38
+ * Flows that stay inside one column (the P2 rules, as layering constraints):
39
+ * - a one-node detour of a split that feeds the split's other target stacks
40
+ * under that target and flows up into it;
41
+ * - the first boundary event of a host whose handler has no other way in drops
42
+ * its handler straight under (or over) the host.
43
+ */
44
+ export declare function stackedFlows(graph: SemanticGraph, members: string[], sideOf: (eventId: string) => number): Map<string, Stack>;
45
+ /**
46
+ * Longest-path columns, then a local network-simplex move: a node with more
47
+ * flows out than in slides right up to its nearest successor (a second start
48
+ * event, a split feeding a far join), one with more in than out slides left.
49
+ * Total flow length only shrinks, which keeps long dummy chains rare.
50
+ */
51
+ export declare function assignLayers(graph: SemanticGraph, members: string[], stacks: ReadonlyMap<string, Stack>): Map<string, number>;
52
+ /**
53
+ * Build the columns with dummy nodes, seeded in depth-first discovery order
54
+ * from the component's start so the first branch starts on top.
55
+ */
56
+ export declare function buildLayering(graph: SemanticGraph, members: string[], start: string, rank: Map<string, number>, biasOf: (flow: BpmnSequenceFlow) => number): Layering;
57
+ export declare function totalCrossings(lg: Layering): number;
58
+ /** Median sweeps with transpose; keeps the order with the fewest crossings seen. */
59
+ export declare function orderLayers(lg: Layering, stacks: ReadonlyMap<string, Stack>): void;
60
+ //# sourceMappingURL=layers.d.ts.map