@bpmnkit/core 1.0.0 → 1.2.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 (73) hide show
  1. package/README.md +30 -3
  2. package/dist/bpmn/agentic.js +3 -1
  3. package/dist/bpmn/auto-layout.js +184 -15
  4. package/dist/bpmn/bpmn-builder.js +69 -7
  5. package/dist/bpmn/bpmn-model.d.ts +78 -0
  6. package/dist/bpmn/bpmn-parser.js +195 -37
  7. package/dist/bpmn/bpmn-serializer.js +121 -72
  8. package/dist/bpmn/bpmnlint.d.ts +153 -0
  9. package/dist/bpmn/bpmnlint.js +364 -0
  10. package/dist/bpmn/camunda-compat-data.d.ts +165 -0
  11. package/dist/bpmn/camunda-compat-data.js +423 -0
  12. package/dist/bpmn/camunda-compat-feel.d.ts +68 -0
  13. package/dist/bpmn/camunda-compat-feel.js +338 -0
  14. package/dist/bpmn/camunda-compat.d.ts +120 -0
  15. package/dist/bpmn/camunda-compat.js +1677 -0
  16. package/dist/bpmn/camunda7/juel.d.ts +41 -0
  17. package/dist/bpmn/camunda7/juel.js +333 -0
  18. package/dist/bpmn/camunda7/migrate.d.ts +72 -0
  19. package/dist/bpmn/camunda7/migrate.js +1152 -0
  20. package/dist/bpmn/compact.d.ts +4 -0
  21. package/dist/bpmn/compact.js +80 -0
  22. package/dist/bpmn/full-operations.js +5 -2
  23. package/dist/bpmn/label-style.d.ts +51 -0
  24. package/dist/bpmn/label-style.js +116 -0
  25. package/dist/bpmn/lint.d.ts +23 -3
  26. package/dist/bpmn/lint.js +47 -10
  27. package/dist/bpmn/optimize/bpmnlint-rules.d.ts +31 -0
  28. package/dist/bpmn/optimize/bpmnlint-rules.js +916 -0
  29. package/dist/bpmn/optimize/deploy.d.ts +8 -2
  30. package/dist/bpmn/optimize/deploy.js +16 -3
  31. package/dist/bpmn/optimize/index.js +11 -2
  32. package/dist/bpmn/optimize/patterns.js +3 -0
  33. package/dist/bpmn/optimize/types.d.ts +14 -0
  34. package/dist/bpmn/optimize/variable-flow.js +4 -1
  35. package/dist/bpmn/process-delta.d.ts +88 -0
  36. package/dist/bpmn/process-delta.js +236 -0
  37. package/dist/bpmn/process-text-writer.d.ts +53 -0
  38. package/dist/bpmn/process-text-writer.js +193 -0
  39. package/dist/bpmn/process-text.d.ts +175 -0
  40. package/dist/bpmn/process-text.js +1255 -0
  41. package/dist/bpmn/process-types.d.ts +112 -0
  42. package/dist/bpmn/process-types.js +490 -0
  43. package/dist/bpmn/svg.js +51 -22
  44. package/dist/doc/docx.d.ts +20 -0
  45. package/dist/doc/docx.js +253 -0
  46. package/dist/doc/html.d.ts +21 -0
  47. package/dist/doc/html.js +303 -0
  48. package/dist/doc/index.d.ts +7 -0
  49. package/dist/doc/index.js +5 -0
  50. package/dist/doc/markdown.d.ts +11 -0
  51. package/dist/doc/markdown.js +160 -0
  52. package/dist/doc/model.d.ts +129 -0
  53. package/dist/doc/model.js +617 -0
  54. package/dist/doc/zip.d.ts +5 -0
  55. package/dist/doc/zip.js +75 -0
  56. package/dist/index.d.ts +22 -0
  57. package/dist/index.js +11 -0
  58. package/dist/layout/annotations.d.ts +4 -2
  59. package/dist/layout/annotations.js +31 -2
  60. package/dist/layout/collaboration/ordering.d.ts +8 -0
  61. package/dist/layout/collaboration/ordering.js +57 -18
  62. package/dist/layout/orthogonal.d.ts +32 -0
  63. package/dist/layout/orthogonal.js +367 -0
  64. package/dist/layout/repair.d.ts +31 -0
  65. package/dist/layout/repair.js +220 -0
  66. package/dist/layout/semantic/route.js +45 -3
  67. package/dist/node/bpmnlint.d.ts +109 -0
  68. package/dist/node/bpmnlint.js +198 -0
  69. package/dist/node/index.d.ts +2 -0
  70. package/dist/node/index.js +1 -0
  71. package/dist/xml/xml-patch.d.ts +21 -0
  72. package/dist/xml/xml-patch.js +27 -1
  73. package/package.json +2 -2
package/README.md CHANGED
@@ -7,11 +7,13 @@
7
7
  [![license](https://img.shields.io/npm/l/@bpmnkit/core?style=flat-square)](https://github.com/bpmnkit/monorepo/blob/main/LICENSE)
8
8
  [![typescript](https://img.shields.io/badge/TypeScript-strict-6244d7?style=flat-square&logo=typescript&logoColor=white)](https://github.com/bpmnkit/monorepo)
9
9
  [![ai-assisted](https://img.shields.io/badge/AI--assisted-claude-8b5cf6?style=flat-square)](https://github.com/bpmnkit/monorepo)
10
- [![stable](https://img.shields.io/badge/status-stable-16a34a?style=flat-square)](https://bpmnkit.com/docs/getting-started/stability)
10
+ [![tier: core](https://img.shields.io/badge/tier-core-16a34a?style=flat-square)](https://bpmnkit.com/docs/getting-started/stability#product-tiers)
11
11
 
12
12
  [Website](https://bpmnkit.com) · [Documentation](https://bpmnkit.com/docs) · [GitHub](https://github.com/bpmnkit/monorepo) · [Changelog](https://github.com/bpmnkit/monorepo/blob/main/packages/core/CHANGELOG.md)
13
13
  </div>
14
14
 
15
+ > **Core tier.** Semver at 1.0: nothing breaks without a major release. See [product tiers](https://bpmnkit.com/docs/getting-started/stability#product-tiers).
16
+
15
17
  ---
16
18
 
17
19
  ## Overview
@@ -278,6 +280,13 @@ Event definitions are options on the element: `timerDuration`, `timerDate`,
278
280
  | `projectSemantics(defs)` | The canonical, presentation-free projection the hash covers |
279
281
  | `diffSemantics(a, b)` | What changed between two models, keyed by element id |
280
282
 
283
+ ### Typed code generation
284
+
285
+ | Export | Description |
286
+ |--------|-------------|
287
+ | `generateProcessTypes(defs \| defs[], options?)` | TypeScript source typing job types (variables, output, headers, errors), process ids, messages, signals, error and escalation codes. Deterministic |
288
+ | `extractProcessContract(defs \| defs[])` | The same contract as data — what `casen gen types` renders and `--check-workers` compares |
289
+
281
290
  ### Editing
282
291
 
283
292
  | Export | Description |
@@ -322,11 +331,27 @@ const { semanticHash, changes } = await writeBpmn(defs, { output: "flow.bpmn" })
322
331
  |--------|-------------|
323
332
  | `layoutProcess(process)` | Auto-layout all elements; returns `LayoutResult` |
324
333
  | `optimize(defs)` | Run all optimization rules; returns `OptimizeReport` |
334
+ | `analyzeCamundaCompat(defs, version?)` | What the targeted Camunda 8 version cannot run or requires, as `compat/*` findings — Camunda Modeler's `@camunda/linting` rules |
325
335
  | `compactify(defs)` | Convert to compact `CompactDiagram` |
326
336
  | `expand(compact)` | Restore full `BpmnDefinitions` |
327
337
  | `createCompactStream(opts?)` | Read a diagram out of a model's token stream, frame by frame |
338
+ | `parseProcessText(text)` | Read a process a model wrote in the line format (`PROCESS_TEXT_GUIDE`); never throws |
339
+ | `createProcessTextStream()` | Read the line format while it streams, one finished line at a time |
340
+ | `writeProcessText(defs)` | Write an existing diagram in the line format, for a model to read; returns the text and an alias → element id map |
341
+ | `parseProcessDelta(text)` | Read a change script (`PROCESS_DELTA_GUIDE`): only what changes, by id; never throws |
328
342
  | `generateId(prefix)` | Generate a unique short ID |
329
343
 
344
+ ### Process documentation
345
+
346
+ | Export | Description |
347
+ |--------|-------------|
348
+ | `renderDocumentationHtml(defs, options?)` | Self-contained, print-ready HTML: diagram, contents, every element in flow order, linked DMN tables and forms. Print → Save as PDF |
349
+ | `renderDocumentationMarkdown(defs, options?)` | The same content as Markdown, for wikis and Confluence |
350
+ | `renderDocumentationDocx(defs, options?)` | The same content as a Word `.docx` (bytes), diagram as SVG |
351
+ | `buildProcessDocumentation(defs, options?)` | The structured content, for a renderer of your own |
352
+
353
+ `options` takes `decisions` (`DmnDefinitions[]`), `forms` (`FormDefinition[]`), `title`, `subtitle` and `diagram`. Output is deterministic and all model text is escaped.
354
+
330
355
  ---
331
356
 
332
357
  ## Related Packages
@@ -335,11 +360,12 @@ const { semanticHash, changes } = await writeBpmn(defs, { output: "flow.bpmn" })
335
360
  |---------|-------------|
336
361
  | [`@bpmnkit/canvas`](https://www.npmjs.com/package/@bpmnkit/canvas) | Zero-dependency SVG BPMN viewer |
337
362
  | [`@bpmnkit/editor`](https://www.npmjs.com/package/@bpmnkit/editor) | Full-featured interactive BPMN editor |
338
- | [`@bpmnkit/engine`](https://www.npmjs.com/package/@bpmnkit/engine) | Lightweight BPMN process execution engine |
363
+ | [`@bpmnkit/engine`](https://www.npmjs.com/package/@bpmnkit/engine) | Lightweight BPMN process simulator for tests and demos |
339
364
  | [`@bpmnkit/feel`](https://www.npmjs.com/package/@bpmnkit/feel) | FEEL expression language parser & evaluator |
340
- | [`@bpmnkit/plugins`](https://www.npmjs.com/package/@bpmnkit/plugins) | 22 composable canvas plugins |
365
+ | [`@bpmnkit/plugins`](https://www.npmjs.com/package/@bpmnkit/plugins) | 34 composable canvas plugins |
341
366
  | [`@bpmnkit/api`](https://www.npmjs.com/package/@bpmnkit/api) | Camunda 8 REST API TypeScript client |
342
367
  | [`@bpmnkit/ascii`](https://www.npmjs.com/package/@bpmnkit/ascii) | Render BPMN diagrams as Unicode ASCII art |
368
+ | [`@bpmnkit/markdown`](https://www.npmjs.com/package/@bpmnkit/markdown) | BPMN diagrams in Markdown — remark, markdown-it and README pre-rendering |
343
369
  | [`@bpmnkit/docspack`](https://www.npmjs.com/package/@bpmnkit/docspack) | BPMN Kit docs as an offline docspack package for AI agents |
344
370
  | [`@bpmnkit/camunda-docspack`](https://www.npmjs.com/package/@bpmnkit/camunda-docspack) | Camunda 8 docs as an offline docspack package for AI agents |
345
371
  | [`@bpmnkit/ui`](https://www.npmjs.com/package/@bpmnkit/ui) | Shared design tokens and UI components |
@@ -352,6 +378,7 @@ const { semanticHash, changes } = await writeBpmn(defs, { output: "flow.bpmn" })
352
378
  | [`@bpmnkit/patterns`](https://www.npmjs.com/package/@bpmnkit/patterns) | Domain process patterns for BPMNKit AIKit |
353
379
  | [`@bpmnkit/reebe-wasm`](https://www.npmjs.com/package/@bpmnkit/reebe-wasm) | WebAssembly BPMN engine for browser simulation |
354
380
  | [`@bpmnkit/worker-client`](https://www.npmjs.com/package/@bpmnkit/worker-client) | Thin Zeebe REST client for standalone workers |
381
+ | [`@bpmnkit/flow`](https://www.npmjs.com/package/@bpmnkit/flow) | Code-first durable flows that derive BPMN, job types and workers |
355
382
  | [`@bpmnkit/user-tasks`](https://www.npmjs.com/package/@bpmnkit/user-tasks) | Embeddable user task widget for Camunda 8 |
356
383
  | [`@bpmnkit/cli-sdk`](https://www.npmjs.com/package/@bpmnkit/cli-sdk) | Plugin authoring SDK for the casen CLI |
357
384
  | [`@bpmnkit/create-casen-plugin`](https://www.npmjs.com/package/@bpmnkit/create-casen-plugin) | Scaffold a new casen CLI plugin in seconds |
@@ -11,8 +11,10 @@ function fromAiExpression(param) {
11
11
  if (param.schema !== undefined)
12
12
  args.push(JSON.stringify(param.schema));
13
13
  if (param.required === false) {
14
+ // Zeebe rejects the deployment of a `null` schema (its tagged-parameter extractor
15
+ // accepts only a context), and leaves an empty one out of the tool's parameters.
14
16
  if (param.schema === undefined)
15
- args.push("null");
17
+ args.push("{}");
16
18
  args.push("{ required: false }");
17
19
  }
18
20
  return `=fromAi(${args.join(", ")})`;
@@ -3,6 +3,7 @@ import { alignPools } from "../layout/collaboration/alignment.js";
3
3
  import { orderPools } from "../layout/collaboration/ordering.js";
4
4
  import { collapseCollinear } from "../layout/grid/grid-router.js";
5
5
  import { layoutProcess } from "../layout/layout-engine.js";
6
+ import { repairRoutes } from "../layout/repair.js";
6
7
  const POOL_HEADER = 30;
7
8
  const LANE_HEADER = 30;
8
9
  const PADDING = 20;
@@ -482,22 +483,43 @@ function poolOwners(defs, collab) {
482
483
  }
483
484
  return owners;
484
485
  }
485
- /** Message flows collapsed into weighted pool-to-pool relationships. */
486
- function poolLinks(collab, owners) {
487
- const weights = new Map();
486
+ /**
487
+ * Message flows as pool-to-pool relationships, one per flow, each carrying how
488
+ * deep inside its pool the message leaves and arrives.
489
+ */
490
+ function poolLinks(collab, owners, depth) {
491
+ const links = [];
488
492
  for (const flow of collab.messageFlows) {
489
493
  const from = owners.get(flow.sourceRef);
490
494
  const to = owners.get(flow.targetRef);
491
495
  if (from === undefined || to === undefined || from === to)
492
496
  continue;
493
- const key = from < to ? `${from}:${to}` : `${to}:${from}`;
494
- const existing = weights.get(key);
495
- if (existing)
496
- existing.weight++;
497
- else
498
- weights.set(key, { from, to, weight: 1 });
497
+ const link = { from, to, weight: 1 };
498
+ const fromDepth = depth(flow.sourceRef);
499
+ const toDepth = depth(flow.targetRef);
500
+ if (fromDepth !== undefined)
501
+ link.fromDepth = fromDepth;
502
+ if (toDepth !== undefined)
503
+ link.toDepth = toDepth;
504
+ links.push(link);
499
505
  }
500
- return [...weights.values()];
506
+ return links;
507
+ }
508
+ /** Each laid-out element's vertical position within its own process, 0 top to 1 bottom. */
509
+ function depthIndex(layouts) {
510
+ const depths = new Map();
511
+ for (const layout of layouts) {
512
+ if (layout.nodes.length === 0)
513
+ continue;
514
+ const { minY, maxY } = contentBbox(layout.nodes);
515
+ const height = maxY - minY;
516
+ if (height <= 0)
517
+ continue;
518
+ for (const node of layout.nodes) {
519
+ depths.set(node.id, (node.bounds.y + node.bounds.height / 2 - minY) / height);
520
+ }
521
+ }
522
+ return depths;
501
523
  }
502
524
  /** Width of a laid-out process, ignoring where in space it happens to sit. */
503
525
  function contentWidth(layout) {
@@ -590,6 +612,8 @@ export function applyAutoLayout(defs, engine = "semantic") {
590
612
  // place in the stack; processes no participant references follow.
591
613
  const processById = new Map(defs.processes.map((p) => [p.id, p]));
592
614
  const pools = [];
615
+ /** Layouts computed early, for ordering; reused rather than run twice. */
616
+ const layoutOf = new Map();
593
617
  if (collab) {
594
618
  const participantPools = collab.participants.map((participant) => ({
595
619
  participantId: participant.id,
@@ -597,7 +621,13 @@ export function applyAutoLayout(defs, engine = "semantic") {
597
621
  }));
598
622
  // Pools that exchange messages read better next to each other, so the
599
623
  // stack follows the message flows rather than the declaration order.
600
- const order = orderPools(participantPools.length, poolLinks(collab, poolOwners(defs, collab)));
624
+ for (const pool of participantPools) {
625
+ if (pool.process && !layoutOf.has(pool.process)) {
626
+ layoutOf.set(pool.process, layoutProcess(pool.process, engine, collapsed));
627
+ }
628
+ }
629
+ const depths = depthIndex(layoutOf.values());
630
+ const order = orderPools(participantPools.length, poolLinks(collab, poolOwners(defs, collab), (id) => depths.get(id)));
601
631
  for (const index of order) {
602
632
  const pool = participantPools[index];
603
633
  if (pool)
@@ -614,7 +644,9 @@ export function applyAutoLayout(defs, engine = "semantic") {
614
644
  }
615
645
  // Lay every pool out first: alignment needs to see all of them before any
616
646
  // geometry is committed.
617
- const layouts = pools.map((pool) => pool.process ? layoutProcess(pool.process, engine, collapsed) : { nodes: [], edges: [] });
647
+ const layouts = pools.map((pool) => pool.process
648
+ ? (layoutOf.get(pool.process) ?? layoutProcess(pool.process, engine, collapsed))
649
+ : { nodes: [], edges: [] });
618
650
  const alignment = alignPools(pools.length, layouts.map((layout) => contentWidth(layout)), messageLinks(collab, pools, layouts));
619
651
  /** Pools with nothing to draw; widened to match the others once all are placed. */
620
652
  const blackBoxPools = [];
@@ -660,7 +692,9 @@ export function applyAutoLayout(defs, engine = "semantic") {
660
692
  // they replace the proportional tiling below.
661
693
  const engineLanes = result.lanes;
662
694
  // Pre-compute annotation positions in layout space so they're included in the bbox
663
- const annBounds = process ? packAnnotations(process, result.nodes) : new Map();
695
+ const annBounds = process
696
+ ? packAnnotations(process, result.nodes, result.edges)
697
+ : new Map();
664
698
  const { minX, minY, maxX, maxY } = contentBbox(result.nodes, annBounds.values());
665
699
  const contentW = maxX - minX;
666
700
  const contentH = maxY - minY;
@@ -668,8 +702,12 @@ export function applyAutoLayout(defs, engine = "semantic") {
668
702
  // aligns to the band space rather than to the content bounding box —
669
703
  // otherwise the shapes drift out of the lanes drawn around them.
670
704
  const laneBands = participantId && hasLanes ? engineLanes : undefined;
671
- const bandTop = laneBands?.[0]?.bounds.y ?? 0;
672
- const bandHeight = laneBands ? laneBands.reduce((sum, lane) => sum + lane.bounds.height, 0) : 0;
705
+ // Bands arrive outermost first and nested lanes overlap their parent, so the
706
+ // pool spans their extent rather than the first band or the sum of heights.
707
+ const bandTop = laneBands ? Math.min(...laneBands.map((lane) => lane.bounds.y)) : 0;
708
+ const bandHeight = laneBands
709
+ ? Math.max(...laneBands.map((lane) => lane.bounds.y + lane.bounds.height)) - bandTop
710
+ : 0;
673
711
  let dx;
674
712
  let dy;
675
713
  if (participantId) {
@@ -827,6 +865,10 @@ export function applyAutoLayout(defs, engine = "semantic") {
827
865
  allEdges.push({ id: `${run.id}_di`, bpmnElement: run.id, waypoints, unknownAttributes: {} });
828
866
  }
829
867
  }
868
+ const repair = routeRepair(defs);
869
+ repair(allShapes, allEdges);
870
+ for (const plane of rootPlanes)
871
+ repair(plane.shapes, plane.edges);
830
872
  const planeBpmnElement = collab?.id ?? defs.processes[0]?.id ?? "plane";
831
873
  const existingDiagram = defs.diagrams[0];
832
874
  return {
@@ -857,4 +899,131 @@ export function applyAutoLayout(defs, engine = "semantic") {
857
899
  ],
858
900
  };
859
901
  }
902
+ /**
903
+ * The final pass over a finished plane: any connection still running through a
904
+ * shape it is unrelated to gets an obstacle-aware route. Relatedness is what a
905
+ * route may touch — its endpoints, the scopes and pools holding them, and a
906
+ * boundary event's host (or a host's boundary events).
907
+ */
908
+ function routeRepair(defs) {
909
+ const parent = new Map();
910
+ const attachedTo = new Map();
911
+ const attachers = new Map();
912
+ const connections = new Map();
913
+ const containers = new Set();
914
+ const participantOf = new Map();
915
+ for (const collab of defs.collaborations) {
916
+ for (const participant of collab.participants) {
917
+ containers.add(participant.id);
918
+ if (participant.processRef)
919
+ participantOf.set(participant.processRef, participant.id);
920
+ }
921
+ for (const flow of collab.messageFlows) {
922
+ connections.set(flow.id, { kind: "message", source: flow.sourceRef, target: flow.targetRef });
923
+ }
924
+ for (const a of collab.associations ?? []) {
925
+ connections.set(a.id, { kind: "association", source: a.sourceRef, target: a.targetRef });
926
+ }
927
+ for (const group of collab.groups ?? [])
928
+ containers.add(group.id);
929
+ }
930
+ const walk = (elements, owner) => {
931
+ for (const element of elements) {
932
+ if (owner)
933
+ parent.set(element.id, owner);
934
+ if (element.type === "boundaryEvent") {
935
+ attachedTo.set(element.id, element.attachedToRef);
936
+ const list = attachers.get(element.attachedToRef);
937
+ if (list)
938
+ list.push(element.id);
939
+ else
940
+ attachers.set(element.attachedToRef, [element.id]);
941
+ }
942
+ const scope = element;
943
+ for (const flow of scope.sequenceFlows ?? []) {
944
+ connections.set(flow.id, {
945
+ kind: "sequence",
946
+ source: flow.sourceRef,
947
+ target: flow.targetRef,
948
+ });
949
+ }
950
+ if (scope.flowElements)
951
+ walk(scope.flowElements, element.id);
952
+ }
953
+ };
954
+ for (const process of defs.processes) {
955
+ const owner = participantOf.get(process.id);
956
+ walk(process.flowElements, owner);
957
+ for (const flow of process.sequenceFlows ?? []) {
958
+ connections.set(flow.id, { kind: "sequence", source: flow.sourceRef, target: flow.targetRef });
959
+ }
960
+ for (const a of process.associations ?? []) {
961
+ connections.set(a.id, { kind: "association", source: a.sourceRef, target: a.targetRef });
962
+ }
963
+ for (const group of process.groups ?? [])
964
+ containers.add(group.id);
965
+ const lanes = (set) => {
966
+ for (const lane of set?.lanes ?? []) {
967
+ containers.add(lane.id);
968
+ lanes(lane.childLaneSet);
969
+ }
970
+ };
971
+ lanes(process.laneSet);
972
+ }
973
+ const related = (id) => {
974
+ const out = [...(attachers.get(id) ?? [])];
975
+ const host = attachedTo.get(id);
976
+ if (host)
977
+ out.push(host);
978
+ for (let p = parent.get(id); p !== undefined; p = parent.get(p))
979
+ out.push(p);
980
+ return out;
981
+ };
982
+ return (shapes, edges) => {
983
+ if (edges.length === 0)
984
+ return;
985
+ const onPlane = new Map(shapes.map((s) => [s.bpmnElement, s.bounds]));
986
+ const visible = (id) => {
987
+ let current = id;
988
+ while (current !== undefined && !onPlane.has(current))
989
+ current = parent.get(current);
990
+ return current ?? id;
991
+ };
992
+ const planeShapes = shapes.map((s) => ({
993
+ id: s.bpmnElement,
994
+ bounds: s.bounds,
995
+ container: containers.has(s.bpmnElement),
996
+ }));
997
+ const planeEdges = [];
998
+ for (const di of edges) {
999
+ const connection = connections.get(di.bpmnElement);
1000
+ if (!connection)
1001
+ continue;
1002
+ planeEdges.push({
1003
+ kind: connection.kind,
1004
+ sourceRef: visible(connection.source),
1005
+ targetRef: visible(connection.target),
1006
+ waypoints: di.waypoints,
1007
+ di,
1008
+ });
1009
+ }
1010
+ const boundarySide = (id) => {
1011
+ const host = attachedTo.get(id);
1012
+ const own = onPlane.get(id);
1013
+ const hostBounds = host ? onPlane.get(host) : undefined;
1014
+ if (!own || !hostBounds)
1015
+ return undefined;
1016
+ return own.y + own.height / 2 <= hostBounds.y + 1 ? "top" : "bottom";
1017
+ };
1018
+ repairRoutes(planeShapes, planeEdges, related, boundarySide);
1019
+ for (const edge of planeEdges) {
1020
+ if (edge.waypoints !== edge.di.waypoints) {
1021
+ edge.di.waypoints = edge.waypoints.map((wp) => ({
1022
+ x: Math.round(wp.x),
1023
+ y: Math.round(wp.y),
1024
+ }));
1025
+ }
1026
+ }
1027
+ };
1028
+ }
860
1029
  //# sourceMappingURL=auto-layout.js.map
@@ -43,6 +43,59 @@ function resolveMessage(messageName, rootMessages) {
43
43
  return existing.id;
44
44
  }
45
45
  /** Builds the `zeebe:subscription` extension element for a correlated message catch. */
46
+ /**
47
+ * Moves each element's `zeebe:subscription` onto the `bpmn:message` it refers to.
48
+ *
49
+ * Zeebe reads a message's correlation key from the message, and its schema
50
+ * allows `zeebe:subscription` only there; Camunda's linter rejects it anywhere
51
+ * else. The builders take the key on the catching element, so this runs once
52
+ * the model is complete. A message shared by elements that name different keys
53
+ * cannot hold both, so those stay on their elements, where lint reports them,
54
+ * rather than one silently winning.
55
+ */
56
+ function hoistMessageSubscriptions(defs) {
57
+ const isSubscription = (el) => el.name === "zeebe:subscription";
58
+ const owners = new Map();
59
+ const visit = (elements) => {
60
+ for (const el of elements) {
61
+ const sub = el.extensionElements.find(isSubscription);
62
+ if (sub) {
63
+ const ref = "messageRef" in el && typeof el.messageRef === "string"
64
+ ? el.messageRef
65
+ : "eventDefinitions" in el
66
+ ? el.eventDefinitions.find((d) => d.type === "message")?.messageRef
67
+ : undefined;
68
+ if (ref !== undefined) {
69
+ const list = owners.get(ref) ?? [];
70
+ list.push({ host: el, sub });
71
+ owners.set(ref, list);
72
+ }
73
+ }
74
+ if ("flowElements" in el && Array.isArray(el.flowElements))
75
+ visit(el.flowElements);
76
+ }
77
+ };
78
+ for (const process of defs.processes)
79
+ visit(process.flowElements);
80
+ for (const [ref, list] of owners) {
81
+ const message = defs.messages.find((m) => m.id === ref);
82
+ const first = list[0];
83
+ if (!message || !first)
84
+ continue;
85
+ const existing = message.extensionElements?.find(isSubscription);
86
+ const keys = new Set(list.map(({ sub }) => sub.attributes.correlationKey));
87
+ if (existing)
88
+ keys.add(existing.attributes.correlationKey);
89
+ if (keys.size > 1)
90
+ continue;
91
+ if (!existing)
92
+ message.extensionElements = [...(message.extensionElements ?? []), first.sub];
93
+ for (const { host, sub } of list) {
94
+ host.extensionElements = host.extensionElements.filter((x) => x !== sub);
95
+ }
96
+ }
97
+ return defs;
98
+ }
46
99
  function buildMessageSubscriptionExt(correlationKey) {
47
100
  if (!correlationKey)
48
101
  return [];
@@ -763,7 +816,10 @@ export class BranchBuilder {
763
816
  return this.addElement(el);
764
817
  }
765
818
  receiveTask(id, options) {
766
- const el = makeFlowElement(id, "receiveTask", options);
819
+ const el = makeFlowElement(id, "receiveTask", {
820
+ ...options,
821
+ extensionElements: buildMessageSubscriptionExt(options?.correlationKey),
822
+ });
767
823
  if (options?.isForCompensation)
768
824
  el.isForCompensation = true;
769
825
  if (options?.messageName)
@@ -1158,7 +1214,10 @@ export class SubProcessContentBuilder {
1158
1214
  return this.addElement(el);
1159
1215
  }
1160
1216
  receiveTask(id, options) {
1161
- const el = makeFlowElement(id, "receiveTask", options);
1217
+ const el = makeFlowElement(id, "receiveTask", {
1218
+ ...options,
1219
+ extensionElements: buildMessageSubscriptionExt(options?.correlationKey),
1220
+ });
1162
1221
  if (options?.isForCompensation)
1163
1222
  el.isForCompensation = true;
1164
1223
  if (options?.messageName)
@@ -1882,7 +1941,10 @@ export class ProcessBuilder {
1882
1941
  }
1883
1942
  /** Add a receive task (aspirational). */
1884
1943
  receiveTask(id, options) {
1885
- const el = makeFlowElement(id, "receiveTask", options);
1944
+ const el = makeFlowElement(id, "receiveTask", {
1945
+ ...options,
1946
+ extensionElements: buildMessageSubscriptionExt(options?.correlationKey),
1947
+ });
1886
1948
  if (options?.isForCompensation)
1887
1949
  el.isForCompensation = true;
1888
1950
  if (options?.messageName)
@@ -2248,7 +2310,7 @@ export class ProcessBuilder {
2248
2310
  ]
2249
2311
  : [],
2250
2312
  };
2251
- return this._autoLayout ? applyAutoLayout(defs) : defs;
2313
+ return hoistMessageSubscriptions(this._autoLayout ? applyAutoLayout(defs) : defs);
2252
2314
  }
2253
2315
  /**
2254
2316
  * Writes this process's contents back into the document it came from.
@@ -2284,7 +2346,7 @@ export class ProcessBuilder {
2284
2346
  definitions.messages = this.rootMessages;
2285
2347
  definitions.signals = this.rootSignals;
2286
2348
  definitions.escalations = this.rootEscalations;
2287
- return this._autoLayout ? applyAutoLayout(definitions) : definitions;
2349
+ return hoistMessageSubscriptions(this._autoLayout ? applyAutoLayout(definitions) : definitions);
2288
2350
  }
2289
2351
  /**
2290
2352
  * Refuses to rewire a flow that was already in the document.
@@ -2580,7 +2642,7 @@ export class DiagramBuilder {
2580
2642
  return index;
2581
2643
  }
2582
2644
  build() {
2583
- return {
2645
+ return hoistMessageSubscriptions({
2584
2646
  id: this._id,
2585
2647
  targetNamespace: "http://bpmn.io/schema/bpmn",
2586
2648
  exporter: "@bpmnkit/core",
@@ -2605,7 +2667,7 @@ export class DiagramBuilder {
2605
2667
  collaborations: this.buildCollaborations(),
2606
2668
  processes: this._processes,
2607
2669
  diagrams: [],
2608
- };
2670
+ });
2609
2671
  }
2610
2672
  /**
2611
2673
  * A document with no participants has no collaboration — an empty