@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
@@ -1,5 +1,7 @@
1
1
  import { ELEMENT_SIZES, LABEL_CHAR_WIDTH, LABEL_HEIGHT, LABEL_MIN_WIDTH, LABEL_VERTICAL_OFFSET, } from "../types.js";
2
2
  import { boundarySide } from "./bands.js";
3
+ import { isDetour } from "./graph.js";
4
+ import { leafLanes } from "./lanes.js";
3
5
  /**
4
6
  * Geometry constants. Layout may add space beyond these; it never takes any back.
5
7
  * Hand-drawn diagrams keep about 50-60 px between neighbouring shapes; wider
@@ -7,6 +9,8 @@ import { boundarySide } from "./bands.js";
7
9
  */
8
10
  export const H_GAP = 60;
9
11
  export const V_GAP = 60;
12
+ /** Gap above a row of stacked detours (see `isDetour`): tasks on a 120 px pitch. */
13
+ const DETOUR_GAP = 40;
10
14
  /**
11
15
  * Gap beside a column holding an expanded container. The container's border,
12
16
  * its title and the notes on its children crowd that gap, so it keeps more air.
@@ -19,8 +23,15 @@ const EXTERNAL_LABEL_OFFSET = 4;
19
23
  const GRID_GAP_X = 40;
20
24
  const GRID_GAP_Y = 20;
21
25
  export const COMPONENT_GAP = 80;
26
+ const ROW_GRID = 10;
22
27
  export const LANE_PADDING = 40;
28
+ /** Vertical lane padding when lanes hand over in a shared column: 2 × 30 + 80 puts rows 140 apart, a 60 px flow. */
29
+ const HAND_OVER_PADDING = 30;
23
30
  export const BOUNDARY_SIZE = 36;
31
+ /** Air kept between two boundary events docked side by side, and before a host's corner. */
32
+ const BOUNDARY_CLEARANCE = 4;
33
+ /** Height of a lane band with nothing in it: room for one boundary-sized row. */
34
+ export const MIN_LANE_HEIGHT = 2 * LANE_PADDING + BOUNDARY_SIZE;
24
35
  const DEFAULT_SIZE = { width: 100, height: 80 };
25
36
  const EXTERNAL_LABEL_TYPES = new Set([
26
37
  "startEvent",
@@ -48,13 +59,6 @@ export function sizeOf(el, childExtent) {
48
59
  return { width: childExtent.width, height: childExtent.height };
49
60
  return ELEMENT_SIZES[el.type] ?? DEFAULT_SIZE;
50
61
  }
51
- /**
52
- * Turn ranks and bands into coordinates.
53
- *
54
- * Ranks become columns sized by their widest node, bands become rows sized by
55
- * their tallest. Nodes are centred in both, so any two nodes sharing a band
56
- * share a centre line and the spine routes as one straight segment.
57
- */
58
62
  export function place(graph, bandLayout, sizes, laneSet,
59
63
  /**
60
64
  * Pack nodes that have no sequence flow at all into a wrapped grid rather
@@ -76,7 +80,11 @@ grid,
76
80
  * container's top to its inner spine. The container is hung so that spine
77
81
  * continues the row's line, and the flow runs straight through it.
78
82
  */
79
- axes = new Map()) {
83
+ axes = new Map(),
84
+ /** Slot flow-less data references under the activity they are wired to. */
85
+ slotArtifacts = false,
86
+ /** Lane refinements; absent or all off lays lanes out the way they always were. */
87
+ laneOpts = {}) {
80
88
  const bounds = new Map();
81
89
  const componentOf = new Map();
82
90
  for (let i = 0; i < graph.components.length; i++) {
@@ -113,11 +121,15 @@ axes = new Map()) {
113
121
  // ── Rows: one line per band, laid out per component then stacked ──
114
122
  const loose = packLoose ? looseNodes(graph) : [];
115
123
  const looseSet = new Set(loose);
124
+ const artifactOwners = laneSet || packLoose || !slotArtifacts ? new Map() : artifactOwnersOf(graph);
116
125
  let cursorY = 0;
117
126
  for (let component = 0; component < graph.components.length; component++) {
118
127
  const members = (graph.components[component] ?? []).filter((id) => graph.byId.has(id));
119
128
  if (members.length === 0)
120
129
  continue;
130
+ // An artifact wired to one activity is slotted under it below, not stacked apart.
131
+ if (members.length === 1 && artifactOwners.has(members[0]))
132
+ continue;
121
133
  if (members.length === 1 && looseSet.has(members[0])) {
122
134
  // The whole grid takes the place of the first loose node; the rest are in it.
123
135
  if (members[0] === loose[0])
@@ -149,9 +161,10 @@ axes = new Map()) {
149
161
  }
150
162
  cursorY = bottom + dy + COMPONENT_GAP;
151
163
  }
152
- separateSameCell(graph, bandLayout, bounds);
153
- const lanes = laneSet ? applyLanes(graph, laneSet, bounds) : [];
164
+ separateSameCell(graph, bandLayout, bounds, laneSet && laneOpts.byLane ? leafLanes(laneSet).leafOf : undefined);
165
+ const lanes = laneSet ? applyLanes(graph, laneSet, bounds, laneOpts) : [];
154
166
  dockBoundaryEvents(graph, bounds, titled);
167
+ placeArtifacts(graph, artifactOwners, bounds);
155
168
  return { bounds, lanes, gutterX };
156
169
  }
157
170
  /**
@@ -159,7 +172,7 @@ axes = new Map()) {
159
172
  * label sits between two neighbouring columns, or where events' and gateways'
160
173
  * labels, centred below shapes narrower than themselves, would meet.
161
174
  */
162
- function columnGaps(graph, sizes, colWidth, ranks) {
175
+ export function columnGaps(graph, sizes, colWidth, ranks) {
163
176
  const rankOf = (id) => {
164
177
  const el = graph.byId.get(id);
165
178
  const host = el?.type === "boundaryEvent" ? el.attachedToRef : id;
@@ -309,10 +322,14 @@ function bandLines(graph, bandLayout, members, sizes, xOf, axes, titled) {
309
322
  let previous = 0;
310
323
  for (const band of list) {
311
324
  const wide = span(band);
325
+ const members = byBand.get(band) ?? [];
326
+ // A row of stacked detours only carries short vertical flows into the
327
+ // row beside it: a 120 px row pitch for tasks, as hand layouts use.
328
+ const gap = members.every((id) => isDetour(graph, id)) ? DETOUR_GAP : V_GAP;
312
329
  let y = previous + dir;
313
330
  for (const box of placed) {
314
331
  if (xOverlap(box, wide)) {
315
- y = dir === 1 ? Math.max(y, box.bottom + V_GAP) : Math.min(y, box.top - V_GAP);
332
+ y = dir === 1 ? Math.max(y, box.bottom + gap) : Math.min(y, box.top - gap);
316
333
  }
317
334
  for (const id of byBand.get(band) ?? []) {
318
335
  const b = xOf(id);
@@ -322,10 +339,14 @@ function bandLines(graph, bandLayout, members, sizes, xOf, axes, titled) {
322
339
  continue;
323
340
  y =
324
341
  dir === 1
325
- ? Math.max(y, box.bottom + V_GAP + e.above)
326
- : Math.min(y, box.top - V_GAP - e.below);
342
+ ? Math.max(y, box.bottom + gap + e.above)
343
+ : Math.min(y, box.top - gap - e.below);
327
344
  }
328
345
  }
346
+ // A row of nothing but exception handlers or stacked detours keeps the
347
+ // spine's 10 px phase, so its tasks share the main row's grid.
348
+ if (members.every((id) => graph.exceptionRow.has(id) || isDetour(graph, id)))
349
+ y = dir * Math.ceil(Math.abs(y) / ROW_GRID) * ROW_GRID;
329
350
  place(band, y);
330
351
  previous = y;
331
352
  }
@@ -391,7 +412,9 @@ function placeGrid(graph, ids, sizes, top, bounds, hint) {
391
412
  * branches were compacted onto one band, for instance. Push the later ones
392
413
  * down in declaration order until the cell is clear.
393
414
  */
394
- function separateSameCell(graph, bandLayout, bounds) {
415
+ function separateSameCell(graph, bandLayout, bounds,
416
+ /** Nodes in different lanes never share a row, so a hand-over column needs no push. */
417
+ leafOf) {
395
418
  const componentOf = new Map();
396
419
  for (let i = 0; i < graph.components.length; i++) {
397
420
  for (const id of graph.components[i] ?? [])
@@ -403,7 +426,7 @@ function separateSameCell(graph, bandLayout, bounds) {
403
426
  for (const node of graph.nodes) {
404
427
  const rank = graph.ranks.get(node.id) ?? 0;
405
428
  const band = bandLayout.bands.get(node.id) ?? 0;
406
- const key = `${componentOf.get(node.id) ?? 0}:${rank}:${band}`;
429
+ const key = `${componentOf.get(node.id) ?? 0}:${rank}:${band}:${leafOf?.get(node.id) ?? ""}`;
407
430
  const list = cells.get(key);
408
431
  if (list)
409
432
  list.push(node.id);
@@ -430,7 +453,7 @@ function separateSameCell(graph, bandLayout, bounds) {
430
453
  * Nested lane sets keep both levels: leaf lanes take a band each, and an
431
454
  * ancestor lane spans the bands of its descendants.
432
455
  */
433
- function applyLanes(graph, laneSet, bounds) {
456
+ function applyLanes(graph, laneSet, bounds, { order, compact, byLane } = {}) {
434
457
  const tree = laneTree(laneSet);
435
458
  if (tree.length === 0)
436
459
  return [];
@@ -444,6 +467,12 @@ function applyLanes(graph, laneSet, bounds) {
444
467
  }
445
468
  };
446
469
  collectLeaves(tree);
470
+ if (order && order.length === leaves.length) {
471
+ const byId = new Map(leaves.map((l) => [l.id, l]));
472
+ const sorted = order.map((id) => byId.get(id));
473
+ if (sorted.every((l) => l !== undefined))
474
+ leaves.splice(0, leaves.length, ...sorted);
475
+ }
447
476
  const laneOf = new Map();
448
477
  for (const leaf of leaves) {
449
478
  for (const ref of leaf.refs)
@@ -497,15 +526,19 @@ function applyLanes(graph, laneSet, bounds) {
497
526
  const left = minX - LANE_PADDING;
498
527
  const span = new Map();
499
528
  let top = 0;
529
+ // Tight lanes make a hand-over exactly as long as the gap between columns.
530
+ const pad = byLane ? HAND_OVER_PADDING : LANE_PADDING;
500
531
  for (const leaf of leaves) {
532
+ if (compact)
533
+ compactLane(graph, members.get(leaf.id) ?? [], bounds);
501
534
  const own = (members.get(leaf.id) ?? [])
502
535
  .map((n) => bounds.get(n))
503
536
  .filter((b) => b !== undefined);
504
- let height = 2 * LANE_PADDING + BOUNDARY_SIZE;
537
+ let height = MIN_LANE_HEIGHT;
505
538
  if (own.length > 0) {
506
539
  const lowest = Math.min(...own.map((b) => b.y));
507
- height = Math.max(...own.map((b) => b.y + b.height)) - lowest + 2 * LANE_PADDING;
508
- const shift = top + LANE_PADDING - lowest;
540
+ height = Math.max(...own.map((b) => b.y + b.height)) - lowest + 2 * pad;
541
+ const shift = top + pad - lowest;
509
542
  for (const b of own)
510
543
  b.y += shift;
511
544
  }
@@ -533,6 +566,7 @@ function applyLanes(graph, laneSet, bounds) {
533
566
  span.set(node.id, own);
534
567
  slots.push({
535
568
  id: node.id,
569
+ depth: node.depth,
536
570
  bounds: { x: left, y: own.top, width, height: own.bottom - own.top },
537
571
  });
538
572
  extent = extent
@@ -542,8 +576,12 @@ function applyLanes(graph, laneSet, bounds) {
542
576
  return extent;
543
577
  };
544
578
  emit(tree);
545
- // Outermost first, so a parent lane is drawn behind the lanes it contains.
546
- return slots.sort((a, b) => b.bounds.height - a.bounds.height || a.bounds.y - b.bounds.y);
579
+ // Outermost first, so a parent lane is drawn behind the lanes it contains. A
580
+ // parent with one child has the child's exact bounds, so depth decides; the
581
+ // height and y keys keep the order flat lane sets have always had.
582
+ return slots
583
+ .sort((a, b) => a.depth - b.depth || b.bounds.height - a.bounds.height || a.bounds.y - b.bounds.y)
584
+ .map(({ id, bounds }) => ({ id, bounds }));
547
585
  }
548
586
  /**
549
587
  * Puts each lane's data objects and stores in a row under the lane's flow nodes,
@@ -570,12 +608,84 @@ function placeDataUnderActivities(members, dataHome, bounds) {
570
608
  }
571
609
  }
572
610
  }
573
- function laneTree(laneSet) {
574
- return laneSet.lanes.map((lane) => ({
575
- id: lane.id,
576
- refs: lane.flowNodeRefs,
577
- children: lane.childLaneSet ? laneTree(lane.childLaneSet) : [],
578
- }));
611
+ /**
612
+ * Pull a lane's off-row nodes up onto an earlier row of the same lane when
613
+ * that row has room at their column and no flow between its own nodes runs
614
+ * through it, so a lane is as tall as its busiest row rather than as the
615
+ * bands it happened to inherit. Only nodes whose lane neighbours are all on
616
+ * the target row (or that have none) move: a node never leaves its chain.
617
+ */
618
+ function compactLane(graph, ids, bounds) {
619
+ const flowNodes = ids.filter((id) => graph.byId.has(id) && bounds.has(id));
620
+ if (flowNodes.length < 2 || flowNodes.some((id) => graph.byId.get(id)?.type.startsWith("data")))
621
+ return;
622
+ const inLane = new Set(flowNodes);
623
+ const centreY = (id) => {
624
+ const b = bounds.get(id);
625
+ return b.y + b.height / 2;
626
+ };
627
+ const rowOf = new Map(flowNodes.map((id) => [id, centreY(id)]));
628
+ const rows = [...new Set(rowOf.values())].sort((a, b) => a - b);
629
+ if (rows.length < 2)
630
+ return;
631
+ const neighbours = (id) => [
632
+ ...(graph.outgoing.get(id) ?? []).map((f) => f.targetRef),
633
+ ...(graph.incoming.get(id) ?? []).map((f) => graph.byId.get(f.sourceRef)?.id ?? f.sourceRef),
634
+ ].filter((n) => inLane.has(n) && n !== id);
635
+ const members = (row) => flowNodes.filter((id) => rowOf.get(id) === row);
636
+ const fits = (id, row) => {
637
+ const b = bounds.get(id);
638
+ const on = members(row);
639
+ for (const m of on) {
640
+ const o = bounds.get(m);
641
+ if (b.x - H_GAP < o.x + o.width && o.x - H_GAP < b.x + b.width)
642
+ return false;
643
+ }
644
+ for (const f of [...graph.outgoing.values()].flat()) {
645
+ if (!on.includes(f.sourceRef) || !on.includes(f.targetRef))
646
+ continue;
647
+ const from = bounds.get(f.sourceRef);
648
+ const to = bounds.get(f.targetRef);
649
+ const left = Math.min(from.x, to.x);
650
+ const right = Math.max(from.x + from.width, to.x + to.width);
651
+ if (b.x < right && b.x + b.width > left)
652
+ return false;
653
+ }
654
+ return true;
655
+ };
656
+ for (const row of rows.slice(1)) {
657
+ for (const id of members(row)) {
658
+ const near = neighbours(id);
659
+ for (const target of rows) {
660
+ if (target >= row)
661
+ break;
662
+ if (near.some((n) => rowOf.get(n) !== target) || !fits(id, target))
663
+ continue;
664
+ bounds.get(id).y += target - row;
665
+ rowOf.set(id, target);
666
+ break;
667
+ }
668
+ }
669
+ }
670
+ }
671
+ /**
672
+ * The lane set as a tree of ids and refs.
673
+ *
674
+ * @throws Error when one lane object occurs twice, as a lane set that contains
675
+ * itself does; walking it would never end.
676
+ */
677
+ function laneTree(laneSet, depth = 0, seen = new Set()) {
678
+ return laneSet.lanes.map((lane) => {
679
+ if (seen.has(lane))
680
+ throw new Error(`Lane ${lane.id} occurs twice in its lane set`);
681
+ seen.add(lane);
682
+ return {
683
+ id: lane.id,
684
+ depth,
685
+ refs: lane.flowNodeRefs,
686
+ children: lane.childLaneSet ? laneTree(lane.childLaneSet, depth + 1, seen) : [],
687
+ };
688
+ });
579
689
  }
580
690
  /**
581
691
  * Dock boundary events on their host's edge — escalation on top, everything
@@ -585,7 +695,7 @@ function laneTree(laneSet) {
585
695
  * The side comes from {@link boundarySide}, the rule that also placed the
586
696
  * handler's band, so a handler is never routed around its own host.
587
697
  */
588
- function dockBoundaryEvents(graph, bounds, titled) {
698
+ export function dockBoundaryEvents(graph, bounds, titled) {
589
699
  for (const [hostId, events] of graph.attachers) {
590
700
  const host = bounds.get(hostId);
591
701
  if (!host)
@@ -604,12 +714,28 @@ function dockBoundaryEvents(graph, bounds, titled) {
604
714
  handlerDepth(graph, bounds, hostId, host, side, a.id) ||
605
715
  handlerReach(graph, b.id) - handlerReach(graph, a.id));
606
716
  const n = ordered.length;
717
+ // A handler in the host's own column (see handlerSteps in graph.ts) is
718
+ // under the host's centre: its event docks there and the flow drops
719
+ // straight down. The others share the half toward their handlers, right.
720
+ const pitch = n > 1 ? (host.width / 2 - BOUNDARY_CLEARANCE) / (n - 1) : 0;
721
+ const column = n === 1 || pitch >= BOUNDARY_SIZE + BOUNDARY_CLEARANCE
722
+ ? ordered.find((e) => inHostColumn(graph, bounds, hostId, host, side, e.id))
723
+ : undefined;
724
+ const others = ordered.filter((e) => e !== column);
725
+ const slot = (i) => {
726
+ const event = ordered[i];
727
+ if (column === undefined)
728
+ return ((i + 1) * host.width) / (n + 1);
729
+ if (event === column)
730
+ return host.width / 2;
731
+ return host.width / 2 + (others.indexOf(event) + 1) * pitch;
732
+ };
607
733
  for (let i = 0; i < n; i++) {
608
734
  const event = ordered[i];
609
735
  if (!event)
610
736
  continue;
611
737
  bounds.set(event.id, {
612
- x: host.x + ((i + 1) * host.width) / (n + 1) - BOUNDARY_SIZE / 2,
738
+ x: host.x + slot(i) - BOUNDARY_SIZE / 2,
613
739
  y: (side === "top" ? host.y : host.y + host.height) - BOUNDARY_SIZE / 2,
614
740
  width: BOUNDARY_SIZE,
615
741
  height: BOUNDARY_SIZE,
@@ -641,6 +767,20 @@ function handlerDepth(graph, bounds, hostId, host, side, eventId) {
641
767
  }
642
768
  return Number.isFinite(depth) ? depth : 0;
643
769
  }
770
+ /** True when a handler of this event sits straight out from the host's centre, past the docked side. */
771
+ function inHostColumn(graph, bounds, hostId, host, side, eventId) {
772
+ const mid = host.x + host.width / 2;
773
+ for (const flow of graph.outgoing.get(hostId) ?? []) {
774
+ if (flow.sourceRef !== eventId)
775
+ continue;
776
+ const target = bounds.get(flow.targetRef);
777
+ if (!target || Math.abs(target.x + target.width / 2 - mid) >= 1)
778
+ continue;
779
+ if (side === "bottom" ? target.y > host.y + host.height : target.y + target.height < host.y)
780
+ return true;
781
+ }
782
+ return false;
783
+ }
644
784
  /** How far the handler of a boundary event runs, in ranks. */
645
785
  function handlerReach(graph, eventId) {
646
786
  let reach = 0;
@@ -653,4 +793,82 @@ function handlerReach(graph, eventId) {
653
793
  }
654
794
  return reach;
655
795
  }
796
+ const ARTIFACT_TYPES = new Set(["dataObjectReference", "dataStoreReference"]);
797
+ /** Gap between an activity and the artifact slotted beside it. */
798
+ const ARTIFACT_GAP = 40;
799
+ const ARTIFACT_CLEARANCE = 10;
800
+ const ARTIFACT_SPACING = 20;
801
+ /**
802
+ * Flow-less data references mapped to the activity they are wired to (the
803
+ * first one declared), so they can be slotted next to it.
804
+ */
805
+ export function artifactOwnersOf(graph) {
806
+ const owners = new Map();
807
+ const isArtifact = (id) => {
808
+ const el = graph.byId.get(id);
809
+ return (el !== undefined &&
810
+ ARTIFACT_TYPES.has(el.type) &&
811
+ (graph.outgoing.get(id) ?? []).length === 0 &&
812
+ (graph.incoming.get(id) ?? []).length === 0);
813
+ };
814
+ const claim = (ref, owner) => {
815
+ if (!owners.has(ref) &&
816
+ isArtifact(ref) &&
817
+ !ARTIFACT_TYPES.has(graph.byId.get(owner)?.type ?? "")) {
818
+ owners.set(ref, owner);
819
+ }
820
+ };
821
+ for (const node of graph.nodes) {
822
+ for (const a of node.dataInputAssociations ?? [])
823
+ for (const ref of a.sourceRefs)
824
+ claim(ref, node.id);
825
+ for (const a of node.dataOutputAssociations ?? []) {
826
+ if (a.targetRef !== undefined)
827
+ claim(a.targetRef, node.id);
828
+ }
829
+ }
830
+ return owners;
831
+ }
832
+ /**
833
+ * Put each artifact on its activity's centre line, below it first (the
834
+ * association is then one short vertical line), above it for a second one
835
+ * (and first when boundary events hang below). More go beside those, and a
836
+ * taken spot sends the artifact down until the area is clear.
837
+ */
838
+ export function placeArtifacts(graph, owners, bounds) {
839
+ const taken = [...bounds.values()];
840
+ const hits = (b) => taken.some((o) => b.x - ARTIFACT_CLEARANCE < o.x + o.width &&
841
+ o.x < b.x + b.width + ARTIFACT_CLEARANCE &&
842
+ b.y - ARTIFACT_CLEARANCE < o.y + o.height &&
843
+ o.y < b.y + b.height + ARTIFACT_CLEARANCE);
844
+ for (const [ref, owner] of owners) {
845
+ const host = bounds.get(owner);
846
+ if (!host)
847
+ continue;
848
+ const size = ELEMENT_SIZES[graph.byId.get(ref)?.type ?? ""] ?? DEFAULT_SIZE;
849
+ const centre = host.x + host.width / 2;
850
+ const below = host.y + host.height + ARTIFACT_GAP;
851
+ const above = host.y - ARTIFACT_GAP - size.height;
852
+ const at = (dx, y) => ({
853
+ x: centre + dx - size.width / 2,
854
+ y,
855
+ width: size.width,
856
+ height: size.height,
857
+ });
858
+ const hung = (graph.attachers.get(owner) ?? []).length > 0;
859
+ const candidates = hung ? [at(0, above), at(0, below)] : [at(0, below), at(0, above)];
860
+ const step = size.width + ARTIFACT_SPACING;
861
+ for (const k of [1, 2, 3]) {
862
+ candidates.push(at(k * step, below), at(-k * step, below));
863
+ }
864
+ let spot = candidates.find((b) => !hits(b));
865
+ if (!spot) {
866
+ spot = at(0, below);
867
+ while (hits(spot))
868
+ spot = { ...spot, y: spot.y + 10 };
869
+ }
870
+ bounds.set(ref, spot);
871
+ taken.push(spot);
872
+ }
873
+ }
656
874
  //# sourceMappingURL=place.js.map
@@ -82,6 +82,13 @@ export function routeFlows(graph, flows, bounds, bandLayout, gutterX) {
82
82
  };
83
83
  const routed = new Map();
84
84
  const pending = [];
85
+ // A boundary handler leaving a host has to get past the host's column; a
86
+ // join template from that column would close the row it passes through.
87
+ const handlerRanks = new Set();
88
+ for (const [host, events] of graph.attachers) {
89
+ if (events.length > 0)
90
+ handlerRanks.add(graph.ranks.get(host) ?? -1);
91
+ }
85
92
  for (const flow of flows) {
86
93
  const source = bounds.get(flow.sourceRef);
87
94
  const target = bounds.get(flow.targetRef);
@@ -95,7 +102,9 @@ export function routeFlows(graph, flows, bounds, bandLayout, gutterX) {
95
102
  ? []
96
103
  : fromBoundary
97
104
  ? fromBoundaryCandidates(ctx, source, bounds.get(hostOf(graph, flow.sourceRef)), target, targetRank)
98
- : forwardCandidates(ctx, source, target, sourceRank, targetRank);
105
+ : forwardCandidates(ctx, source, target, sourceRank, targetRank, isJoinGateway(graph, flow.targetRef) &&
106
+ !isSplitGateway(graph, flow.sourceRef) &&
107
+ !handlerRanks.has(sourceRank ?? -1));
99
108
  const clear = pick(direct, ctx, flow.sourceRef, flow.targetRef);
100
109
  if (clear && clear.crossings <= CROSSING_TOLERANCE) {
101
110
  commit(ctx, routed, flow, clear.waypoints);
@@ -195,6 +204,19 @@ function commit(ctx, routed, flow, waypoints) {
195
204
  }
196
205
  }
197
206
  }
207
+ const GATEWAYS = new Set([
208
+ "exclusiveGateway",
209
+ "parallelGateway",
210
+ "inclusiveGateway",
211
+ "eventBasedGateway",
212
+ "complexGateway",
213
+ ]);
214
+ function isJoinGateway(graph, id) {
215
+ return GATEWAYS.has(graph.byId.get(id)?.type ?? "") && (graph.incoming.get(id) ?? []).length > 1;
216
+ }
217
+ function isSplitGateway(graph, id) {
218
+ return GATEWAYS.has(graph.byId.get(id)?.type ?? "") && (graph.outgoing.get(id) ?? []).length > 1;
219
+ }
198
220
  function hostOf(graph, eventId) {
199
221
  for (const [hostId, events] of graph.attachers) {
200
222
  if (events.some((e) => e.id === eventId))
@@ -307,7 +329,9 @@ function blocked(ctx, waypoints, sourceId, targetId) {
307
329
  * Candidates for a normal forward flow, best first: a straight spine segment,
308
330
  * a branch leaving through the source's top or bottom, then the gutter turn.
309
331
  */
310
- function forwardCandidates(ctx, source, target, sourceRank, targetRank) {
332
+ function forwardCandidates(ctx, source, target, sourceRank, targetRank,
333
+ /** The target is a join gateway reached from something other than a split. */
334
+ intoJoin = false) {
311
335
  const from = centre(source);
312
336
  const to = centre(target);
313
337
  const rightOf = target.x >= source.x + source.width;
@@ -367,6 +391,15 @@ function forwardCandidates(ctx, source, target, sourceRank, targetRank) {
367
391
  { x: target.x, y: to.y },
368
392
  ],
369
393
  ];
394
+ // A join is reached the way its split was left, mirrored: along the
395
+ // branch's own row, then up or down into the gateway at its centre-x.
396
+ if (intoJoin) {
397
+ candidates.unshift([
398
+ { x: source.x + source.width, y: from.y },
399
+ { x: to.x, y: from.y },
400
+ { x: to.x, y: down ? target.y : target.y + target.height },
401
+ ]);
402
+ }
370
403
  // Turning in the gutter right behind the source instead reaches the target
371
404
  // band early; which of the two crosses less depends on what is already
372
405
  // routed, so both are offered.
@@ -63,14 +63,6 @@ export interface LayoutEdge {
63
63
  /** Label bounds for overlap checking. */
64
64
  labelBounds?: Bounds;
65
65
  }
66
- /** Result of laying out a sub-process's children, linked to its parent. */
67
- export interface SubProcessChildResult {
68
- parentId: string;
69
- result: LayoutResult;
70
- /** Subprocess position at the time children were translated to absolute coordinates. */
71
- parentX: number;
72
- parentY: number;
73
- }
74
66
  /** How the unconnected children of an ad-hoc sub-process are arranged in their grid. */
75
67
  export interface GridHint {
76
68
  /** Columns in the grid; defaults to `ceil(sqrt(n))`. */
@@ -41,7 +41,7 @@ export interface PreserveOptions {
41
41
  *
42
42
  * - `"remove"` (default) — take it out, because the update says so.
43
43
  * - `"keep"` — leave it. A serializer omits an attribute set to its schema
44
- * default, so `isExecutable="false"` disappears from a file that said it
44
+ * default, so `isSequential="false"` disappears from a file that said it
45
45
  * out loud. Keeping it is only safe when re-reading the result gives the
46
46
  * same model, which is a check the caller has to make; see
47
47
  * `exportPreserving` in the BPMN module.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bpmnkit/core",
3
- "version": "1.15.0",
3
+ "version": "1.17.0",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -37,7 +37,7 @@
37
37
  "node": ">=20"
38
38
  },
39
39
  "dependencies": {
40
- "@bpmnkit/feel": "^1.1.2"
40
+ "@bpmnkit/feel": "^1.1.3"
41
41
  },
42
42
  "description": "TypeScript-first BPMN 2.0 SDK — parse, build, layout, and optimize diagrams",
43
43
  "keywords": [