@bpmnkit/core 1.14.0 → 1.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -14,6 +14,8 @@ export { stripCamunda8 } from "./bpmn/strip-camunda8.js";
14
14
  export type { DroppedCamunda8Item, StripCamunda8Result } from "./bpmn/strip-camunda8.js";
15
15
  export { applyAutoLayout } from "./bpmn/auto-layout.js";
16
16
  export { placeNewShapes } from "./bpmn/place-new-shapes.js";
17
+ export { makeRoom } from "./bpmn/make-room.js";
18
+ export type { MakeRoomResult } from "./bpmn/make-room.js";
17
19
  export type { PlaceNewShapesOptions, PlaceNewShapesResult } from "./bpmn/place-new-shapes.js";
18
20
  export { diffSemantics, projectSemantics, semanticHash } from "./bpmn/semantic-hash.js";
19
21
  export type { JsonValue, SemanticDiff, SemanticProjection } from "./bpmn/semantic-hash.js";
@@ -60,6 +62,8 @@ export { Dmn, drgId, layoutDmn, benchmarkDmnLayout, compactifyDmn, expandDmn } f
60
62
  export type { DmnBenchmarkResult, DmnElementPosition, CompactDmn, CompactDmnDecision, CompactDmnInput, CompactDmnOutput, CompactDmnRule, } from "./dmn/index.js";
61
63
  export { Form, compactifyForm, expandForm } from "./form/index.js";
62
64
  export { lintForm } from "./form/lint.js";
65
+ export { attachUserTaskForms, parseFormFields } from "./form/user-task-forms.js";
66
+ export type { UserTaskFormsOptions, UserTaskFormsResult } from "./form/user-task-forms.js";
63
67
  export { lintDmn } from "./dmn/lint.js";
64
68
  export type { CheckFinding, CheckSeverity } from "./check-finding.js";
65
69
  export type { CompactForm, CompactFormField } from "./form/index.js";
package/dist/index.js CHANGED
@@ -11,6 +11,7 @@ export { Bpmn, SAMPLE_BPMN_XML } from "./bpmn/index.js";
11
11
  export { stripCamunda8 } from "./bpmn/strip-camunda8.js";
12
12
  export { applyAutoLayout } from "./bpmn/auto-layout.js";
13
13
  export { placeNewShapes } from "./bpmn/place-new-shapes.js";
14
+ export { makeRoom } from "./bpmn/make-room.js";
14
15
  export { diffSemantics, projectSemantics, semanticHash } from "./bpmn/semantic-hash.js";
15
16
  export { extractProcessContract, generateProcessTypes } from "./bpmn/process-types.js";
16
17
  export { isDeployable, validateDeployable, validateDeployableXml, } from "./bpmn/zeebe-validate/index.js";
@@ -36,6 +37,7 @@ export { buildAiAgentSubProcess, AI_AGENT_JOB_WORKER_TASK_TYPE, AI_AGENT_DEFAULT
36
37
  export { Dmn, drgId, layoutDmn, benchmarkDmnLayout, compactifyDmn, expandDmn } from "./dmn/index.js";
37
38
  export { Form, compactifyForm, expandForm } from "./form/index.js";
38
39
  export { lintForm } from "./form/lint.js";
40
+ export { attachUserTaskForms, parseFormFields } from "./form/user-task-forms.js";
39
41
  export { lintDmn } from "./dmn/lint.js";
40
42
  export { FormBuilder, GroupBuilder } from "./form/form-builder.js";
41
43
  export { generateId, resetIdCounter } from "./types/id-generator.js";
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Labels around message flows, placed after the flows are routed.
3
+ *
4
+ * A message flow's name is what the pools say to each other, so it belongs on
5
+ * the flow where nothing else is: the empty band between two pools. And a flow
6
+ * docking under an event runs straight through the name the event carries
7
+ * below itself, so that name moves above the event (or beside it).
8
+ */
9
+ import type { BpmnDiEdge, BpmnDiShape } from "../../bpmn/bpmn-model.js";
10
+ export interface MessageLabelInput {
11
+ shapes: BpmnDiShape[];
12
+ edges: BpmnDiEdge[];
13
+ /** Named message flows by id. */
14
+ names: ReadonlyMap<string, string>;
15
+ /** Pools, lanes and expanded sub-processes: drawn around content, not obstacles. */
16
+ containers: ReadonlySet<string>;
17
+ /** Pools, top to bottom, for the bands between them. */
18
+ pools: ReadonlySet<string>;
19
+ }
20
+ /**
21
+ * Moves an event's name off the message flow docking on it, then gives each
22
+ * named message flow a label in the band between pools when one is free.
23
+ */
24
+ export declare function placeMessageFlowLabels(input: MessageLabelInput): void;
25
+ //# sourceMappingURL=message-labels.d.ts.map
@@ -0,0 +1,108 @@
1
+ import { LABEL_CHAR_WIDTH, LABEL_HEIGHT, LABEL_MIN_WIDTH } from "../types.js";
2
+ /** Space between a flow and the label beside it. */
3
+ const LABEL_GAP = 4;
4
+ /** How far a label slides along its segment per try. */
5
+ const SLIDE_STEP = 10;
6
+ function overlaps(a, b) {
7
+ return a.x < b.x + b.width && b.x < a.x + a.width && a.y < b.y + b.height && b.y < a.y + a.height;
8
+ }
9
+ function crosses(p, q, b) {
10
+ return (Math.max(p.x, q.x) > b.x &&
11
+ Math.min(p.x, q.x) < b.x + b.width &&
12
+ Math.max(p.y, q.y) > b.y &&
13
+ Math.min(p.y, q.y) < b.y + b.height);
14
+ }
15
+ function edgeThrough(edge, b) {
16
+ return edge.waypoints.slice(1).some((q, i) => {
17
+ const p = edge.waypoints[i];
18
+ return p !== undefined && crosses(p, q, b);
19
+ });
20
+ }
21
+ /**
22
+ * Moves an event's name off the message flow docking on it, then gives each
23
+ * named message flow a label in the band between pools when one is free.
24
+ */
25
+ export function placeMessageFlowLabels(input) {
26
+ const { shapes, edges, names, containers, pools } = input;
27
+ const messageEdges = edges.filter((e) => names.has(e.bpmnElement));
28
+ if (messageEdges.length === 0)
29
+ return;
30
+ const solids = shapes.filter((s) => !containers.has(s.bpmnElement)).map((s) => s.bounds);
31
+ const labels = () => [
32
+ ...shapes.flatMap((s) => (s.label?.bounds ? [s.label.bounds] : [])),
33
+ ...edges.flatMap((e) => (e.label?.bounds ? [e.label.bounds] : [])),
34
+ ];
35
+ const free = (b, own) => !solids.some((s) => overlaps(s, b)) &&
36
+ !labels().some((l) => l !== own && overlaps(l, b)) &&
37
+ !edges.some((e) => edgeThrough(e, b));
38
+ for (const shape of shapes) {
39
+ const label = shape.label?.bounds;
40
+ if (label === undefined || !messageEdges.some((e) => edgeThrough(e, label)))
41
+ continue;
42
+ const s = shape.bounds;
43
+ const cx = s.x + s.width / 2;
44
+ const spot = [
45
+ { x: cx - label.width / 2, y: s.y - LABEL_GAP - label.height },
46
+ { x: s.x + s.width + LABEL_GAP, y: s.y + s.height },
47
+ { x: s.x - LABEL_GAP - label.width, y: s.y + s.height },
48
+ { x: s.x + s.width + LABEL_GAP, y: s.y - label.height },
49
+ ]
50
+ .map((p) => ({
51
+ x: Math.round(p.x),
52
+ y: Math.round(p.y),
53
+ width: label.width,
54
+ height: label.height,
55
+ }))
56
+ .find((b) => free(b, label));
57
+ if (spot && shape.label)
58
+ shape.label.bounds = spot;
59
+ }
60
+ const poolBounds = shapes
61
+ .filter((s) => pools.has(s.bpmnElement))
62
+ .map((s) => s.bounds)
63
+ .sort((a, b) => a.y - b.y);
64
+ const bands = [];
65
+ for (let i = 0; i + 1 < poolBounds.length; i++) {
66
+ const above = poolBounds[i];
67
+ const below = poolBounds[i + 1];
68
+ if (above && below && below.y > above.y + above.height)
69
+ bands.push({ top: above.y + above.height, bottom: below.y });
70
+ }
71
+ for (const edge of messageEdges) {
72
+ const name = names.get(edge.bpmnElement) ?? "";
73
+ const width = Math.max(name.length * LABEL_CHAR_WIDTH, LABEL_MIN_WIDTH);
74
+ const height = LABEL_HEIGHT;
75
+ const beside = (x, y) => [
76
+ { x: Math.round(x + LABEL_GAP), y: Math.round(y - height / 2), width, height },
77
+ { x: Math.round(x - LABEL_GAP - width), y: Math.round(y - height / 2), width, height },
78
+ ];
79
+ const candidates = [];
80
+ const vertical = [];
81
+ for (let i = 0; i + 1 < edge.waypoints.length; i++) {
82
+ const p = edge.waypoints[i];
83
+ const q = edge.waypoints[i + 1];
84
+ if (!p || !q || p.x !== q.x)
85
+ continue;
86
+ vertical.push({ x: p.x, top: Math.min(p.y, q.y), bottom: Math.max(p.y, q.y) });
87
+ }
88
+ // In a band first: nothing else is drawn there.
89
+ for (const v of vertical)
90
+ for (const band of bands)
91
+ if (v.top <= band.top && band.bottom <= v.bottom)
92
+ candidates.push(...beside(v.x, (band.top + band.bottom) / 2));
93
+ // Then along the longest run, from its middle outwards.
94
+ vertical.sort((a, b) => b.bottom - b.top - (a.bottom - a.top));
95
+ for (const v of vertical) {
96
+ const mid = (v.top + v.bottom) / 2;
97
+ for (let d = 0; d <= (v.bottom - v.top) / 2; d += SLIDE_STEP)
98
+ candidates.push(...beside(v.x, mid + d), ...beside(v.x, mid - d));
99
+ }
100
+ const spot = candidates.find((b) => !solids.some((s) => overlaps(s, b)) &&
101
+ !labels().some((l) => overlaps(l, b)) &&
102
+ !edges.some((e) => e !== edge && edgeThrough(e, b)));
103
+ const chosen = spot ?? candidates[0];
104
+ if (chosen)
105
+ edge.label = { bounds: chosen };
106
+ }
107
+ }
108
+ //# sourceMappingURL=message-labels.js.map
@@ -24,6 +24,10 @@ export interface PoolLink {
24
24
  /**
25
25
  * Order pools by their message-flow relationships. Returns indices into the
26
26
  * input order; an input with no message flows comes back unchanged.
27
+ *
28
+ * `edges` are pools that read better at the top or bottom of the stack: black
29
+ * boxes, partners on the rim of the conversation. Preferred there when it costs
30
+ * the messages no more than one pool step.
27
31
  */
28
- export declare function orderPools(count: number, links: readonly PoolLink[]): number[];
32
+ export declare function orderPools(count: number, links: readonly PoolLink[], edges?: ReadonlySet<number>): number[];
29
33
  //# sourceMappingURL=ordering.d.ts.map
@@ -52,7 +52,13 @@ function pairCosts(links) {
52
52
  * term is a tie-break: with nothing to gain from moving, the pools stay where
53
53
  * the author put them.
54
54
  */
55
- function cost(order, pairs) {
55
+ /**
56
+ * What an edge pool costs for sitting between two others: one message's pool
57
+ * step. It settles near-ties toward the rim but never stretches the messages
58
+ * further, which reads worse than a black box in the middle.
59
+ */
60
+ const EDGE_PENALTY = 1;
61
+ function cost(order, pairs, edges = new Set()) {
56
62
  const position = [];
57
63
  for (let i = 0; i < order.length; i++) {
58
64
  const id = order[i];
@@ -67,6 +73,9 @@ function cost(order, pairs) {
67
73
  continue;
68
74
  total += pair.weight * Math.abs(a - b) + (a < b ? pair.aAbove : pair.aBelow);
69
75
  }
76
+ for (let i = 1; i + 1 < order.length; i++)
77
+ if (edges.has(order[i] ?? -1))
78
+ total += EDGE_PENALTY;
70
79
  let drift = 0;
71
80
  for (let i = 0; i < order.length; i++)
72
81
  drift += Math.abs((order[i] ?? i) - i);
@@ -75,21 +84,27 @@ function cost(order, pairs) {
75
84
  /**
76
85
  * Order pools by their message-flow relationships. Returns indices into the
77
86
  * input order; an input with no message flows comes back unchanged.
87
+ *
88
+ * `edges` are pools that read better at the top or bottom of the stack: black
89
+ * boxes, partners on the rim of the conversation. Preferred there when it costs
90
+ * the messages no more than one pool step.
78
91
  */
79
- export function orderPools(count, links) {
92
+ export function orderPools(count, links, edges = new Set()) {
80
93
  const identity = Array.from({ length: count }, (_, i) => i);
81
94
  if (count < 3 || links.length === 0)
82
95
  return identity;
83
96
  const pairs = pairCosts(links);
84
- return count <= EXHAUSTIVE_LIMIT ? exhaustive(identity, pairs) : refine(identity, pairs);
97
+ return count <= EXHAUSTIVE_LIMIT
98
+ ? exhaustive(identity, pairs, edges)
99
+ : refine(identity, pairs, edges);
85
100
  }
86
101
  /** Every order, best first-found wins — so declaration order survives a tie. */
87
- function exhaustive(identity, pairs) {
102
+ function exhaustive(identity, pairs, edges) {
88
103
  let best = identity;
89
- let bestCost = cost(identity, pairs);
104
+ let bestCost = cost(identity, pairs, edges);
90
105
  const permute = (prefix, rest) => {
91
106
  if (rest.length === 0) {
92
- const candidate = cost(prefix, pairs);
107
+ const candidate = cost(prefix, pairs, edges);
93
108
  if (candidate < bestCost) {
94
109
  best = [...prefix];
95
110
  bestCost = candidate;
@@ -110,9 +125,9 @@ function exhaustive(identity, pairs) {
110
125
  * Take each pool out and put it back wherever it fits best, repeating until a
111
126
  * full sweep changes nothing.
112
127
  */
113
- function refine(identity, pairs) {
128
+ function refine(identity, pairs, edges) {
114
129
  let order = [...identity];
115
- let current = cost(order, pairs);
130
+ let current = cost(order, pairs, edges);
116
131
  for (let sweep = 0; sweep < order.length; sweep++) {
117
132
  let improved = false;
118
133
  for (let from = 0; from < order.length; from++) {
@@ -124,7 +139,7 @@ function refine(identity, pairs) {
124
139
  if (to === from)
125
140
  continue;
126
141
  const candidate = [...without.slice(0, to), pool, ...without.slice(to)];
127
- const candidateCost = cost(candidate, pairs);
142
+ const candidateCost = cost(candidate, pairs, edges);
128
143
  if (candidateCost < current) {
129
144
  order = candidate;
130
145
  current = candidateCost;
@@ -17,6 +17,9 @@ export function buildSemanticGraph(flowElements, sequenceFlows) {
17
17
  const nodes = [];
18
18
  const attachers = new Map();
19
19
  for (const el of flowElements) {
20
+ // A data object has no shape: its references are what a diagram draws.
21
+ if (el.type === "dataObject")
22
+ continue;
20
23
  if (el.type === "boundaryEvent") {
21
24
  const be = el;
22
25
  const list = attachers.get(be.attachedToRef);
@@ -449,6 +449,29 @@ function applyLanes(graph, laneSet, bounds) {
449
449
  for (const ref of leaf.refs)
450
450
  laneOf.set(ref, leaf);
451
451
  }
452
+ // A data object or store is never a lane member (BPMN lanes hold flow nodes), so it
453
+ // follows the first laned activity wired to it; otherwise it lands below the
454
+ // lanes, outside the pool.
455
+ const dataHome = new Map();
456
+ const follow = (ref, lane, activity) => {
457
+ if (laneOf.has(ref))
458
+ return;
459
+ laneOf.set(ref, lane);
460
+ dataHome.set(ref, activity);
461
+ };
462
+ for (const node of graph.nodes) {
463
+ const lane = laneOf.get(node.id);
464
+ if (!lane)
465
+ continue;
466
+ for (const a of node.dataInputAssociations ?? []) {
467
+ for (const ref of a.sourceRefs)
468
+ follow(ref, lane, node.id);
469
+ }
470
+ for (const a of node.dataOutputAssociations ?? []) {
471
+ if (a.targetRef !== undefined)
472
+ follow(a.targetRef, lane, node.id);
473
+ }
474
+ }
452
475
  const members = new Map();
453
476
  for (const leaf of leaves)
454
477
  members.set(leaf.id, []);
@@ -461,6 +484,7 @@ function applyLanes(graph, laneSet, bounds) {
461
484
  else
462
485
  orphans.push(node.id);
463
486
  }
487
+ placeDataUnderActivities(members, dataHome, bounds);
464
488
  let minX = Number.POSITIVE_INFINITY;
465
489
  let maxX = Number.NEGATIVE_INFINITY;
466
490
  for (const b of bounds.values()) {
@@ -521,6 +545,31 @@ function applyLanes(graph, laneSet, bounds) {
521
545
  // Outermost first, so a parent lane is drawn behind the lanes it contains.
522
546
  return slots.sort((a, b) => b.bounds.height - a.bounds.height || a.bounds.y - b.bounds.y);
523
547
  }
548
+ /**
549
+ * Puts each lane's data objects and stores in a row under the lane's flow nodes,
550
+ * each centred below the activity it is wired to, so the lane grows by one row
551
+ * instead of stretching to wherever the data was ranked.
552
+ */
553
+ function placeDataUnderActivities(members, dataHome, bounds) {
554
+ for (const ids of members.values()) {
555
+ const flow = ids.filter((id) => !dataHome.has(id)).map((id) => bounds.get(id));
556
+ const homeX = (id) => bounds.get(dataHome.get(id) ?? "")?.x ?? 0;
557
+ const data = ids.filter((id) => dataHome.has(id)).sort((a, b) => homeX(a) - homeX(b));
558
+ if (data.length === 0 || flow.length === 0)
559
+ continue;
560
+ const bottom = Math.max(...flow.map((b) => (b ? b.y + b.height : 0)));
561
+ let right = Number.NEGATIVE_INFINITY;
562
+ for (const id of data) {
563
+ const b = bounds.get(id);
564
+ const home = bounds.get(dataHome.get(id) ?? "");
565
+ if (!b || !home)
566
+ continue;
567
+ b.x = Math.max(home.x + home.width / 2 - b.width / 2, right + H_GAP / 2);
568
+ b.y = bottom + V_GAP / 2;
569
+ right = b.x + b.width;
570
+ }
571
+ }
572
+ }
524
573
  function laneTree(laneSet) {
525
574
  return laneSet.lanes.map((lane) => ({
526
575
  id: lane.id,
package/llms.txt CHANGED
@@ -3,7 +3,7 @@
3
3
  > BPMN 2.0, DMN and Camunda Form SDK for TypeScript. Agents: read the card for your type, not the README.
4
4
 
5
5
  - [AGENTS.md](AGENTS.md): what to read and the rules for all types
6
- - [BPMN card](agent-cards/bpmn.md): process build script and traps
6
+ - [BPMN card](agent-cards/bpmn.md): one `casen build` command; templates for one pool, pools/lanes/message flows/data, and layout-preserving edits; traps
7
7
  - [DMN card](agent-cards/dmn.md): decision table and DRD script and traps
8
8
  - [Form card](agent-cards/form.md): form script and traps
9
9
  - [Builder reference](builder-reference.md): every builder option
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bpmnkit/core",
3
- "version": "1.14.0",
3
+ "version": "1.15.0",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",