@bpmnkit/core 1.15.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 (60) hide show
  1. package/builder-reference.md +2 -1
  2. package/dist/bpmn/auto-layout.d.ts +0 -8
  3. package/dist/bpmn/auto-layout.js +605 -98
  4. package/dist/bpmn/bpmn-builder.d.ts +120 -14
  5. package/dist/bpmn/bpmn-builder.js +411 -152
  6. package/dist/bpmn/bpmn-model.d.ts +15 -0
  7. package/dist/bpmn/bpmn-parser.js +32 -6
  8. package/dist/bpmn/bpmn-serializer.js +9 -2
  9. package/dist/bpmn/compact-stream.d.ts +7 -0
  10. package/dist/bpmn/compact-stream.js +7 -0
  11. package/dist/bpmn/compact.d.ts +124 -9
  12. package/dist/bpmn/compact.js +295 -27
  13. package/dist/bpmn/full-operations.d.ts +19 -0
  14. package/dist/bpmn/full-operations.js +191 -7
  15. package/dist/bpmn/make-room.js +114 -0
  16. package/dist/bpmn/place-new-shapes.js +4 -2
  17. package/dist/bpmn/preserving-writer.d.ts +1 -1
  18. package/dist/bpmn/preserving-writer.js +1 -1
  19. package/dist/bpmn/process-delta.d.ts +32 -1
  20. package/dist/bpmn/process-delta.js +62 -1
  21. package/dist/bpmn/process-text-writer.d.ts +18 -7
  22. package/dist/bpmn/process-text-writer.js +105 -22
  23. package/dist/bpmn/process-text.d.ts +27 -1
  24. package/dist/bpmn/process-text.js +350 -2
  25. package/dist/bpmn/swimlanes.d.ts +178 -0
  26. package/dist/bpmn/swimlanes.js +774 -0
  27. package/dist/index.d.ts +5 -4
  28. package/dist/index.js +3 -2
  29. package/dist/layout/collaboration/crossings.d.ts +13 -0
  30. package/dist/layout/collaboration/crossings.js +37 -0
  31. package/dist/layout/collaboration/docked-labels.d.ts +21 -0
  32. package/dist/layout/collaboration/docked-labels.js +65 -0
  33. package/dist/layout/collaboration/message-tracks.d.ts +20 -0
  34. package/dist/layout/collaboration/message-tracks.js +78 -0
  35. package/dist/layout/collaboration/stack-crossings.d.ts +38 -0
  36. package/dist/layout/collaboration/stack-crossings.js +155 -0
  37. package/dist/layout/grid/edge-labels.js +21 -10
  38. package/dist/layout/layered/coords.d.ts +13 -0
  39. package/dist/layout/layered/coords.js +211 -0
  40. package/dist/layout/layered/index.d.ts +21 -0
  41. package/dist/layout/layered/index.js +288 -0
  42. package/dist/layout/layered/layers.d.ts +60 -0
  43. package/dist/layout/layered/layers.js +374 -0
  44. package/dist/layout/layered/route.d.ts +66 -0
  45. package/dist/layout/layered/route.js +369 -0
  46. package/dist/layout/layout-engine.d.ts +6 -2
  47. package/dist/layout/layout-engine.js +4 -2
  48. package/dist/layout/semantic/bands.js +8 -2
  49. package/dist/layout/semantic/graph.d.ts +33 -1
  50. package/dist/layout/semantic/graph.js +200 -4
  51. package/dist/layout/semantic/index.d.ts +8 -2
  52. package/dist/layout/semantic/index.js +114 -14
  53. package/dist/layout/semantic/lanes.d.ts +40 -0
  54. package/dist/layout/semantic/lanes.js +198 -0
  55. package/dist/layout/semantic/place.d.ts +46 -2
  56. package/dist/layout/semantic/place.js +248 -30
  57. package/dist/layout/semantic/route.js +35 -2
  58. package/dist/layout/types.d.ts +0 -8
  59. package/dist/xml/xml-patch.d.ts +1 -1
  60. package/package.json +2 -2
@@ -10,7 +10,9 @@ function effectiveSource(flow, byId) {
10
10
  return source.attachedToRef;
11
11
  return flow.sourceRef;
12
12
  }
13
- export function buildSemanticGraph(flowElements, sequenceFlows) {
13
+ export function buildSemanticGraph(flowElements, sequenceFlows,
14
+ /** Stack one-node detours under their sibling target; see {@link feedsSibling}. */
15
+ stackDetours = false) {
14
16
  const byId = new Map();
15
17
  for (const el of flowElements)
16
18
  byId.set(el.id, el);
@@ -59,6 +61,9 @@ export function buildSemanticGraph(flowElements, sequenceFlows) {
59
61
  components: [],
60
62
  starts: [],
61
63
  ranks: new Map(),
64
+ exceptionRow: new Set(),
65
+ stackDetours,
66
+ handoffs: new Set(),
62
67
  };
63
68
  findComponents(graph);
64
69
  markBackEdges(graph);
@@ -154,11 +159,90 @@ function sharesRank(graph, flow) {
154
159
  return false;
155
160
  return isJoin(graph, source.id) && isJoin(graph, target.id);
156
161
  }
162
+ /**
163
+ * A one-node detour of a split that leads straight into the split's other
164
+ * target (order pigment, then mix paint) shares that target's column: it is
165
+ * stacked under (or over) it and flows in vertically, instead of pushing the
166
+ * target and everything after it one column right. True for the detour's
167
+ * flow into that target.
168
+ */
169
+ function feedsSibling(graph, flow) {
170
+ if (!graph.stackDetours)
171
+ return false;
172
+ const into = graph.incoming.get(flow.sourceRef) ?? [];
173
+ const out = graph.outgoing.get(flow.sourceRef) ?? [];
174
+ if (into.length !== 1 || out.length !== 1)
175
+ return false;
176
+ const split = into[0];
177
+ if (graph.byId.get(split.sourceRef)?.type === "boundaryEvent")
178
+ return false;
179
+ if (graph.backEdges.has(split.id) || graph.backEdges.has(flow.id))
180
+ return false;
181
+ return (graph.outgoing.get(split.sourceRef) ?? []).some((f) => f.targetRef === flow.targetRef && f !== split && !graph.backEdges.has(f.id));
182
+ }
183
+ /** True when `id` is a detour stacked under its sibling target (see {@link feedsSibling}). */
184
+ export function isDetour(graph, id) {
185
+ const out = graph.outgoing.get(id) ?? [];
186
+ return out.length === 1 && feedsSibling(graph, out[0]);
187
+ }
188
+ /** True when `flow` enters a detour that {@link feedsSibling}: the spine takes the sibling instead. */
189
+ export function entersDetour(graph, flow) {
190
+ return isDetour(graph, flow.targetRef);
191
+ }
192
+ /**
193
+ * The entry flows of each boundary event's handler, in host then event order.
194
+ * Only a handler entered by that flow alone is listed: a shared target belongs
195
+ * to whatever else reaches it.
196
+ */
197
+ function handlerEntries(graph, sideOf) {
198
+ const entries = [];
199
+ for (const [host, events] of graph.attachers) {
200
+ for (const event of events) {
201
+ const flows = (graph.outgoing.get(host) ?? []).filter((f) => f.sourceRef === event.id &&
202
+ !graph.backEdges.has(f.id) &&
203
+ (graph.incoming.get(f.targetRef) ?? []).length === 1);
204
+ if (flows.length === 0)
205
+ continue;
206
+ // A rework loop (handler leads back to an earlier merge) is no exception
207
+ // path: its back edge routes below the diagram anyway, so a row of its
208
+ // own would only push the other branches down.
209
+ if (flows.some((f) => loopsBack(graph, f.targetRef)))
210
+ continue;
211
+ entries.push({ host, side: sideOf(event, host), flows });
212
+ }
213
+ }
214
+ return entries;
215
+ }
216
+ /** True when the handler chain starting at `entry` leaves through a back edge. */
217
+ function loopsBack(graph, entry) {
218
+ for (const id of chainOf(graph, entry))
219
+ if ((graph.outgoing.get(id) ?? []).some((f) => graph.backEdges.has(f.id)))
220
+ return true;
221
+ return false;
222
+ }
223
+ /** The nodes only `entry` leads to: it, and successors reached from nowhere else. */
224
+ function chainOf(graph, entry) {
225
+ const chain = new Set([entry]);
226
+ const stack = [entry];
227
+ while (stack.length > 0) {
228
+ const id = stack.pop();
229
+ for (const f of graph.outgoing.get(id) ?? []) {
230
+ if (graph.backEdges.has(f.id) || chain.has(f.targetRef))
231
+ continue;
232
+ if ((graph.incoming.get(f.targetRef) ?? []).length !== 1)
233
+ continue;
234
+ chain.add(f.targetRef);
235
+ stack.push(f.targetRef);
236
+ }
237
+ }
238
+ return chain;
239
+ }
157
240
  /**
158
241
  * Longest-path ranks over the acyclic remainder, then a bounded fixed point so
159
- * a boundary handler never precedes the activity it is attached to.
242
+ * a boundary handler never precedes the activity it is attached to. `steps`
243
+ * overrides the one-rank step of individual flows.
160
244
  */
161
- function assignRanks(graph) {
245
+ export function assignRanks(graph, steps = new Map()) {
162
246
  const { ranks } = graph;
163
247
  for (const node of graph.nodes)
164
248
  ranks.set(node.id, 0);
@@ -170,7 +254,9 @@ function assignRanks(graph) {
170
254
  for (const node of graph.nodes) {
171
255
  const rank = ranks.get(node.id) ?? 0;
172
256
  for (const flow of forward(node.id)) {
173
- const step = sharesRank(graph, flow) ? 0 : 1;
257
+ const step = sharesRank(graph, flow) || feedsSibling(graph, flow) || graph.handoffs.has(flow.id)
258
+ ? 0
259
+ : (steps.get(flow.id) ?? 1);
174
260
  const target = ranks.get(flow.targetRef) ?? 0;
175
261
  if (target < rank + step) {
176
262
  ranks.set(flow.targetRef, rank + step);
@@ -195,6 +281,116 @@ function assignRanks(graph) {
195
281
  ranks.set(id, (ranks.get(id) ?? 0) - min);
196
282
  }
197
283
  }
284
+ /**
285
+ * Exception row: re-rank so a boundary handler starts in its host's own column
286
+ * and its flow drops straight down (or up) from the event, onto a row the
287
+ * handlers of the spine share. A second event on one host fans out one column
288
+ * right. A handler whose column is taken (a sibling branch on that side, or an
289
+ * earlier handler's tail) keeps its step to the right, as before.
290
+ *
291
+ * Needs the hosts' bands, so it runs after a first band assignment; returns
292
+ * true when ranks changed and bands must be assigned again.
293
+ */
294
+ export function placeExceptionRow(graph, bands, sideOf) {
295
+ const entries = handlerEntries(graph, sideOf);
296
+ if (entries.length === 0)
297
+ return false;
298
+ const componentOf = new Map();
299
+ graph.components.forEach((members, i) => {
300
+ for (const id of members)
301
+ componentOf.set(id, i);
302
+ });
303
+ const chains = new Map();
304
+ const handlerNodes = new Set();
305
+ for (const entry of entries) {
306
+ for (const flow of entry.flows) {
307
+ const chain = chainOf(graph, flow.targetRef);
308
+ chains.set(flow.targetRef, chain);
309
+ for (const id of chain)
310
+ handlerNodes.add(id);
311
+ }
312
+ }
313
+ const band = (id) => bands.get(id) ?? 0;
314
+ const busy = new Set();
315
+ const blocked = new Set();
316
+ const rowKey = (entry) => `${componentOf.get(entry.host) ?? 0}:${band(entry.host)}:${entry.side}`;
317
+ for (const entry of entries) {
318
+ const hostRank = graph.ranks.get(entry.host);
319
+ const sibling = graph.nodes.some((n) => n.id !== entry.host &&
320
+ !handlerNodes.has(n.id) &&
321
+ graph.ranks.get(n.id) === hostRank &&
322
+ componentOf.get(n.id) === componentOf.get(entry.host) &&
323
+ (band(n.id) - band(entry.host)) * entry.side > 0);
324
+ if (sibling || band(entry.host) !== 0)
325
+ busy.add(entry);
326
+ if (sibling)
327
+ blocked.add(rowKey(entry));
328
+ }
329
+ // One row per scope, band and side: when a sibling branch blocks one handler's
330
+ // column, the row would be split between the handlers (a long drop for one, a
331
+ // step for the other), so all of them keep the step.
332
+ for (const entry of entries)
333
+ if (blocked.has(rowKey(entry)))
334
+ busy.add(entry);
335
+ const steps = new Map();
336
+ for (const entry of entries)
337
+ for (const flow of entry.flows)
338
+ steps.set(flow.id, busy.has(entry) ? 1 : 0);
339
+ if (busy.size === entries.length)
340
+ return false;
341
+ const lastRank = (chain) => Math.max(...[...chain].map((id) => graph.ranks.get(id) ?? 0));
342
+ /** Entries that keep their old step because they would collide on the row. */
343
+ const demoted = new Set();
344
+ const demote = (entry) => {
345
+ demoted.add(entry);
346
+ for (const flow of entry.flows)
347
+ steps.set(flow.id, 1);
348
+ };
349
+ for (let round = 0; round <= entries.length; round++) {
350
+ assignRanks(graph, steps);
351
+ const { ranks } = graph;
352
+ const order = [...entries].sort((a, b) => (ranks.get(a.host) ?? 0) - (ranks.get(b.host) ?? 0));
353
+ /** Per row and side: the first rank no earlier handler occupies. */
354
+ const free = new Map();
355
+ const last = new Map();
356
+ let changed = false;
357
+ for (const entry of order) {
358
+ if (busy.has(entry))
359
+ continue;
360
+ const key = `${componentOf.get(entry.host) ?? 0}:${band(entry.host)}:${entry.side}`;
361
+ const from = free.get(key) ?? Number.NEGATIVE_INFINITY;
362
+ if (!demoted.has(entry) && from > (ranks.get(entry.host) ?? 0)) {
363
+ // An earlier handler on the row holds this host's column. A second
364
+ // event of the same host steps right as before; for another host the
365
+ // earlier handler's tail would sit in the way of its event, so both do.
366
+ demote(entry);
367
+ const before = last.get(key);
368
+ if (before && before.host !== entry.host && !demoted.has(before))
369
+ demote(before);
370
+ changed = true;
371
+ break;
372
+ }
373
+ last.set(key, entry);
374
+ let end = Number.NEGATIVE_INFINITY;
375
+ for (const flow of entry.flows)
376
+ end = Math.max(end, lastRank(chains.get(flow.targetRef) ?? new Set()));
377
+ free.set(key, Math.max(from, end + 1));
378
+ }
379
+ if (!changed)
380
+ break;
381
+ }
382
+ if (!entries.some((e) => !busy.has(e) && !demoted.has(e)))
383
+ return false;
384
+ // Demoted handlers still sit on the row, one column right of their host.
385
+ for (const entry of entries) {
386
+ if (busy.has(entry))
387
+ continue;
388
+ for (const flow of entry.flows)
389
+ for (const id of chains.get(flow.targetRef) ?? [])
390
+ graph.exceptionRow.add(id);
391
+ }
392
+ return true;
393
+ }
198
394
  /**
199
395
  * True when an end event is reachable from `id` without traversing a back edge.
200
396
  * A node other than `id` itself that has no outgoing flow also ends the path.
@@ -5,7 +5,9 @@ import type { GridHint, LayoutHints, LayoutResult } from "../types.js";
5
5
  * semantic bands carry branch meaning up and down, and lane membership wins over
6
6
  * both.
7
7
  */
8
- export declare function semanticLayoutProcess(process: BpmnProcess, collapsed?: ReadonlySet<string>, grids?: LayoutHints["grids"]): LayoutResult;
8
+ export declare function semanticLayoutProcess(process: BpmnProcess, collapsed?: ReadonlySet<string>, grids?: LayoutHints["grids"], inPool?: boolean,
9
+ /** Run the layered (Sugiyama) placement and routing on every lane-free scope. */
10
+ layered?: boolean): LayoutResult;
9
11
  export declare function semanticLayout(flowElements: BpmnFlowElement[], sequenceFlows: BpmnSequenceFlow[], laneSet?: BpmnLaneSet,
10
12
  /** Sub-processes drawn collapsed: their contents go on a plane of their own. */
11
13
  collapsed?: ReadonlySet<string>,
@@ -14,6 +16,10 @@ inContainer?: boolean,
14
16
  /** Tool-grid hints, by container id; applied to the containers in this scope and below. */
15
17
  grids?: LayoutHints["grids"],
16
18
  /** The hint for this scope's own grid, when it is a hinted container's interior. */
17
- grid?: GridHint): LayoutResult;
19
+ grid?: GridHint,
20
+ /** Slot data references under the activity they are wired to. */
21
+ slotArtifacts?: boolean,
22
+ /** See {@link semanticLayoutProcess}. */
23
+ layered?: boolean): LayoutResult;
18
24
  export type { Placement } from "./place.js";
19
25
  //# sourceMappingURL=index.d.ts.map
@@ -1,7 +1,9 @@
1
1
  import { placeEdgeLabels } from "../grid/edge-labels.js";
2
+ import { layeredPlace } from "../layered/index.js";
2
3
  import { LABEL_CHAR_WIDTH, LABEL_HEIGHT, LABEL_MIN_WIDTH, SUBPROCESS_PADDING } from "../types.js";
3
- import { assignBands } from "./bands.js";
4
- import { buildSemanticGraph } from "./graph.js";
4
+ import { assignBands, boundarySide } from "./bands.js";
5
+ import { assignRanks, buildSemanticGraph, placeExceptionRow } from "./graph.js";
6
+ import { cheaper, laneCost, laneHandoffs, lanePlan } from "./lanes.js";
5
7
  import { externalLabelWidth, place, sizeOf } from "./place.js";
6
8
  import { routeFlows } from "./route.js";
7
9
  /** Padding between an expanded sub-process border and its children. */
@@ -10,14 +12,19 @@ const SUB_PADDING = SUBPROCESS_PADDING;
10
12
  const TITLE_BAND = 28;
11
13
  /** Gap between an event or gateway and its external label. */
12
14
  const LABEL_OFFSET = 4;
15
+ /** Step and limit when a blocked external label slides along a stem. */
16
+ const LABEL_SLIDE = 10;
17
+ const MAX_LABEL_SLIDE = 60;
13
18
  const CONTAINER_TYPES = new Set(["subProcess", "adHocSubProcess", "eventSubProcess", "transaction"]);
14
19
  /**
15
20
  * Lay out a process the way the BPMN reads: ranks carry the flow left to right,
16
21
  * semantic bands carry branch meaning up and down, and lane membership wins over
17
22
  * both.
18
23
  */
19
- export function semanticLayoutProcess(process, collapsed, grids) {
20
- return semanticLayout(process.flowElements, process.sequenceFlows, process.laneSet, collapsed, false, grids);
24
+ export function semanticLayoutProcess(process, collapsed, grids, inPool = false,
25
+ /** Run the layered (Sugiyama) placement and routing on every lane-free scope. */
26
+ layered = false) {
27
+ return semanticLayout(process.flowElements, process.sequenceFlows, process.laneSet, collapsed, false, grids, undefined, !inPool, layered);
21
28
  }
22
29
  export function semanticLayout(flowElements, sequenceFlows, laneSet,
23
30
  /** Sub-processes drawn collapsed: their contents go on a plane of their own. */
@@ -27,10 +34,14 @@ inContainer = false,
27
34
  /** Tool-grid hints, by container id; applied to the containers in this scope and below. */
28
35
  grids,
29
36
  /** The hint for this scope's own grid, when it is a hinted container's interior. */
30
- grid) {
37
+ grid,
38
+ /** Slot data references under the activity they are wired to. */
39
+ slotArtifacts = false,
40
+ /** See {@link semanticLayoutProcess}. */
41
+ layered = false) {
31
42
  if (flowElements.length === 0)
32
43
  return { nodes: [], edges: [] };
33
- const graph = buildSemanticGraph(flowElements, sequenceFlows);
44
+ const graph = buildSemanticGraph(flowElements, sequenceFlows, slotArtifacts);
34
45
  // Children first: an expanded sub-process is sized by what it contains, while
35
46
  // a collapsed one stays activity-sized and its contents move to their own plane.
36
47
  const childResults = new Map();
@@ -38,7 +49,7 @@ grid) {
38
49
  const sizes = new Map();
39
50
  const axes = new Map();
40
51
  for (const el of graph.nodes) {
41
- const child = childLayoutOf(el, collapsed, grids);
52
+ const child = childLayoutOf(el, collapsed, grids, layered);
42
53
  if (!child) {
43
54
  sizes.set(el.id, sizeOf(el));
44
55
  continue;
@@ -58,8 +69,86 @@ grid) {
58
69
  }
59
70
  // A named expanded sub-process draws its title along its top border.
60
71
  const titled = new Set([...childResults.keys()].filter((id) => graph.byId.get(id)?.name !== undefined));
61
- const bandLayout = assignBands(graph, titled);
62
- const { bounds, lanes, gutterX } = place(graph, bandLayout, sizes, laneSet, inContainer, titled, grid, axes);
72
+ if (layered && useLayered(graph, laneSet, inContainer, grid)) {
73
+ const placed = layeredPlace(graph, sequenceFlows, sizes, titled, slotArtifacts);
74
+ return finish(graph, flowElements, placed.bounds, placed.edges, (id) => placed.row.get(id) ?? 0, [], childResults, planes, collapsed);
75
+ }
76
+ const laneInfo = laneSet ? lanePlan(graph, laneSet) : undefined;
77
+ const run = (handoffs, laneOpts = {}) => {
78
+ graph.handoffs = handoffs;
79
+ assignRanks(graph);
80
+ // finish() moves the children, and a laned scope is laid out twice
81
+ const children = laneSet ? structuredClone(childResults) : childResults;
82
+ let bandLayout = assignBands(graph, titled);
83
+ // Lanes decide a handler's row themselves, so the exception row is for lane-free scopes.
84
+ if (!laneSet &&
85
+ placeExceptionRow(graph, bandLayout.bands, (event, host) => boundarySide(event, titled.has(host)))) {
86
+ bandLayout = assignBands(graph, titled);
87
+ }
88
+ const { bounds, lanes, gutterX } = place(graph, bandLayout, sizes, laneSet, inContainer, titled, grid, axes, slotArtifacts, laneOpts);
89
+ const edges = routeFlows(graph, sequenceFlows, bounds, bandLayout, gutterX);
90
+ return finish(graph, flowElements, bounds, edges, (id) => bandLayout.bands.get(id) ?? 0, lanes, children, planes, collapsed);
91
+ };
92
+ // Nested lane sets keep the placement they always had.
93
+ if (!laneSet || !laneInfo || !laneInfo.flat)
94
+ return run(graph.handoffs);
95
+ // The layout as it always was comes first and wins ties: a refinement is kept
96
+ // only when it is strictly cheaper (see `laneCost`).
97
+ const orders = [undefined];
98
+ if (laneInfo.order)
99
+ orders.push(laneInfo.order);
100
+ const legacy = run(new Set());
101
+ const legacyCost = laneCost(legacy);
102
+ let best = legacy;
103
+ let bestCost = legacyCost;
104
+ const none = new Set();
105
+ for (const order of orders) {
106
+ const lanes = order ?? laneInfo.declared;
107
+ const variants = [
108
+ [none, { order, compact: true }],
109
+ [none, { order, compact: true, byLane: true }],
110
+ [laneHandoffs(graph, laneInfo.leafOf, lanes, true), { order, compact: true, byLane: true }],
111
+ [laneHandoffs(graph, laneInfo.leafOf, lanes), { order, compact: true, byLane: true }],
112
+ ];
113
+ if (order)
114
+ variants.unshift([none, { order }]);
115
+ for (const [h, opts] of variants) {
116
+ if (h !== none && h.size === 0)
117
+ continue;
118
+ const result = run(h, opts);
119
+ const cost = laneCost(result);
120
+ // Must not lose to the old layout anywhere; among those that do not, the cheapest in order.
121
+ if (cheaper(cost, legacyCost) && lexicographicallyLess(cost, bestCost)) {
122
+ best = result;
123
+ bestCost = cost;
124
+ }
125
+ }
126
+ }
127
+ return best;
128
+ }
129
+ function lexicographicallyLess(a, b) {
130
+ for (let i = 0; i < a.length; i++) {
131
+ if (a[i] !== b[i])
132
+ return a[i] < b[i];
133
+ }
134
+ return false;
135
+ }
136
+ /**
137
+ * The layered engine covers scopes without lanes and without a packed tool
138
+ * grid; lanes stay with the semantic placement until lane-aware ordering lands.
139
+ */
140
+ function useLayered(graph, laneSet, inContainer, grid) {
141
+ if (laneSet || grid)
142
+ return false;
143
+ const flowless = graph.components.filter((c) => c.length === 1 &&
144
+ (graph.outgoing.get(c[0]) ?? []).length === 0 &&
145
+ (graph.incoming.get(c[0]) ?? []).length === 0).length;
146
+ if (inContainer && flowless >= 2)
147
+ return false;
148
+ return graph.components.length > flowless;
149
+ }
150
+ /** Nodes, labels and children of a placed and routed scope. */
151
+ function finish(graph, flowElements, bounds, edges, rowOf, lanes, childResults, planes, collapsed) {
63
152
  const besideStem = boundaryLabels(graph, bounds);
64
153
  const nodes = [];
65
154
  for (const el of flowElements) {
@@ -71,8 +160,8 @@ grid) {
71
160
  type: el.type,
72
161
  bounds: b,
73
162
  layer: graph.ranks.get(el.id) ?? 0,
74
- position: bandLayout.bands.get(el.id) ?? 0,
75
- gridRow: bandLayout.bands.get(el.id) ?? 0,
163
+ position: rowOf(el.id),
164
+ gridRow: rowOf(el.id),
76
165
  };
77
166
  if (el.name) {
78
167
  node.label = el.name;
@@ -86,7 +175,6 @@ grid) {
86
175
  node.isExpanded = false;
87
176
  nodes.push(node);
88
177
  }
89
- const edges = routeFlows(graph, sequenceFlows, bounds, bandLayout, gutterX);
90
178
  // Drop the children in, translated into their parent's interior.
91
179
  for (const [parentId, child] of childResults) {
92
180
  const parent = bounds.get(parentId);
@@ -124,7 +212,7 @@ grid) {
124
212
  return result;
125
213
  }
126
214
  /** Lay out a container's children and report the size its border needs. */
127
- function childLayoutOf(el, collapsed, grids) {
215
+ function childLayoutOf(el, collapsed, grids, layered) {
128
216
  if (!CONTAINER_TYPES.has(el.type))
129
217
  return null;
130
218
  const container = el;
@@ -133,7 +221,7 @@ function childLayoutOf(el, collapsed, grids) {
133
221
  const result = semanticLayout(container.flowElements, container.sequenceFlows ?? [], container.laneSet, collapsed,
134
222
  // A collapsed container's contents go on a plane of their own, laid out
135
223
  // like any top-level scope.
136
- !collapsed.has(el.id), grids, grids?.get(el.id));
224
+ !collapsed.has(el.id), grids, grids?.get(el.id), false, layered);
137
225
  const extent = extentOf(result);
138
226
  if (!extent)
139
227
  return null;
@@ -314,6 +402,18 @@ function clearExternalLabels(nodes, edges) {
314
402
  { ...label, x: cx + beside, y: above },
315
403
  { ...label, x: cx - beside - label.width, y: above },
316
404
  ];
405
+ // Still blocked, usually by a task beside the gateway: slide the label
406
+ // along the stem until it is past that neighbour.
407
+ for (let slide = LABEL_SLIDE; slide <= MAX_LABEL_SLIDE; slide += LABEL_SLIDE) {
408
+ for (const [dx, y] of [
409
+ [cx + beside, below + slide],
410
+ [cx - beside - label.width, below + slide],
411
+ [cx + beside, above - slide],
412
+ [cx - beside - label.width, above - slide],
413
+ ]) {
414
+ candidates.push({ ...label, x: dx, y });
415
+ }
416
+ }
317
417
  const spot = candidates.find(clear);
318
418
  if (spot) {
319
419
  label.x = spot.x;
@@ -0,0 +1,40 @@
1
+ import type { BpmnLaneSet } from "../../bpmn/bpmn-model.js";
2
+ import type { LayoutResult } from "../types.js";
3
+ import type { SemanticGraph } from "./graph.js";
4
+ /** Leaf lane id per flow-node ref, in declaration order; `flat` when no lane nests another. */
5
+ export declare function leafLanes(laneSet: BpmnLaneSet): {
6
+ leaves: string[];
7
+ leafOf: Map<string, string>;
8
+ flat: boolean;
9
+ };
10
+ /**
11
+ * Top-to-bottom lane order that keeps the flows between lanes short: the
12
+ * declared order unless another order is strictly cheaper (ties keep what the
13
+ * author wrote). Nested lane sets and sets beyond six lanes keep their order.
14
+ */
15
+ export declare function laneOrder(graph: SemanticGraph, leaves: string[], leafOf: ReadonlyMap<string, string>, flat: boolean): string[];
16
+ /**
17
+ * Flows into the lane directly above or below that share their source's
18
+ * column, so the hand-over is a straight vertical run. One per source and
19
+ * direction; the target takes only that flow in, and neither end carries a
20
+ * boundary event (its handler would need the column).
21
+ */
22
+ export declare function laneHandoffs(graph: SemanticGraph, leafOf: ReadonlyMap<string, string>, order: readonly string[],
23
+ /** Only sources with a single way on: plain hand-overs, no splits. */
24
+ plainOnly?: boolean): Set<string>;
25
+ /**
26
+ * Cost of a laned layout, lower is better, compared term by term (a refinement must not lose in any): flows
27
+ * through a shape that is not theirs, crossings between flows, bends, how far
28
+ * the happy path strays from its mean row, area.
29
+ */
30
+ export declare function laneCost(result: LayoutResult): [number, number, number, number, number, number];
31
+ /** True when `a` is no worse than `b` in any term and better in at least one. */
32
+ export declare function cheaper(a: readonly number[], b: readonly number[]): boolean;
33
+ /** Lane membership, declared order and the cheaper top-to-bottom order, when there is one. */
34
+ export declare function lanePlan(graph: SemanticGraph, laneSet: BpmnLaneSet): {
35
+ leafOf: Map<string, string>;
36
+ order: string[] | undefined;
37
+ declared: string[];
38
+ flat: boolean;
39
+ };
40
+ //# sourceMappingURL=lanes.d.ts.map