@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.
- package/builder-reference.md +2 -1
- package/dist/bpmn/auto-layout.d.ts +0 -8
- package/dist/bpmn/auto-layout.js +605 -98
- package/dist/bpmn/bpmn-builder.d.ts +120 -14
- package/dist/bpmn/bpmn-builder.js +411 -152
- package/dist/bpmn/bpmn-model.d.ts +15 -0
- package/dist/bpmn/bpmn-parser.js +32 -6
- package/dist/bpmn/bpmn-serializer.js +9 -2
- package/dist/bpmn/compact-stream.d.ts +7 -0
- package/dist/bpmn/compact-stream.js +7 -0
- package/dist/bpmn/compact.d.ts +124 -9
- package/dist/bpmn/compact.js +295 -27
- package/dist/bpmn/full-operations.d.ts +19 -0
- package/dist/bpmn/full-operations.js +191 -7
- package/dist/bpmn/make-room.js +114 -0
- package/dist/bpmn/place-new-shapes.js +4 -2
- package/dist/bpmn/preserving-writer.d.ts +1 -1
- package/dist/bpmn/preserving-writer.js +1 -1
- package/dist/bpmn/process-delta.d.ts +32 -1
- package/dist/bpmn/process-delta.js +62 -1
- package/dist/bpmn/process-text-writer.d.ts +18 -7
- package/dist/bpmn/process-text-writer.js +105 -22
- package/dist/bpmn/process-text.d.ts +27 -1
- package/dist/bpmn/process-text.js +350 -2
- package/dist/bpmn/swimlanes.d.ts +178 -0
- package/dist/bpmn/swimlanes.js +774 -0
- package/dist/index.d.ts +5 -4
- package/dist/index.js +3 -2
- package/dist/layout/collaboration/crossings.d.ts +13 -0
- package/dist/layout/collaboration/crossings.js +37 -0
- package/dist/layout/collaboration/docked-labels.d.ts +21 -0
- package/dist/layout/collaboration/docked-labels.js +65 -0
- package/dist/layout/collaboration/message-tracks.d.ts +20 -0
- package/dist/layout/collaboration/message-tracks.js +78 -0
- package/dist/layout/collaboration/stack-crossings.d.ts +38 -0
- package/dist/layout/collaboration/stack-crossings.js +155 -0
- package/dist/layout/grid/edge-labels.js +21 -10
- package/dist/layout/layered/coords.d.ts +13 -0
- package/dist/layout/layered/coords.js +211 -0
- package/dist/layout/layered/index.d.ts +21 -0
- package/dist/layout/layered/index.js +288 -0
- package/dist/layout/layered/layers.d.ts +60 -0
- package/dist/layout/layered/layers.js +374 -0
- package/dist/layout/layered/route.d.ts +66 -0
- package/dist/layout/layered/route.js +369 -0
- package/dist/layout/layout-engine.d.ts +6 -2
- package/dist/layout/layout-engine.js +4 -2
- package/dist/layout/semantic/bands.js +8 -2
- package/dist/layout/semantic/graph.d.ts +33 -1
- package/dist/layout/semantic/graph.js +200 -4
- package/dist/layout/semantic/index.d.ts +8 -2
- package/dist/layout/semantic/index.js +114 -14
- package/dist/layout/semantic/lanes.d.ts +40 -0
- package/dist/layout/semantic/lanes.js +198 -0
- package/dist/layout/semantic/place.d.ts +46 -2
- package/dist/layout/semantic/place.js +248 -30
- package/dist/layout/semantic/route.js +35 -2
- package/dist/layout/types.d.ts +0 -8
- package/dist/xml/xml-patch.d.ts +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { pathCrossings } from "../collaboration/crossings.js";
|
|
2
|
+
/** Most lanes whose order is searched exhaustively (n! candidates). */
|
|
3
|
+
const MAX_ORDERED_LANES = 6;
|
|
4
|
+
/** Leaf lane id per flow-node ref, in declaration order; `flat` when no lane nests another. */
|
|
5
|
+
export function leafLanes(laneSet) {
|
|
6
|
+
const leaves = [];
|
|
7
|
+
const leafOf = new Map();
|
|
8
|
+
let flat = true;
|
|
9
|
+
const seen = new Set();
|
|
10
|
+
const walk = (lanes) => {
|
|
11
|
+
for (const lane of lanes) {
|
|
12
|
+
// Same guard as the placement's lane tree: a lane set containing itself must throw there, not loop here.
|
|
13
|
+
if (seen.has(lane))
|
|
14
|
+
return;
|
|
15
|
+
seen.add(lane);
|
|
16
|
+
if (lane.childLaneSet && lane.childLaneSet.lanes.length > 0) {
|
|
17
|
+
flat = false;
|
|
18
|
+
walk(lane.childLaneSet.lanes);
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
leaves.push(lane.id);
|
|
22
|
+
for (const ref of lane.flowNodeRefs)
|
|
23
|
+
if (!leafOf.has(ref))
|
|
24
|
+
leafOf.set(ref, lane.id);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
walk(laneSet.lanes);
|
|
28
|
+
return { leaves, leafOf, flat };
|
|
29
|
+
}
|
|
30
|
+
/** Lane distance summed over every flow that leaves a lane, for a given top-to-bottom order. */
|
|
31
|
+
function crossLaneCost(pairs, pos) {
|
|
32
|
+
let cost = 0;
|
|
33
|
+
for (const [a, b] of pairs)
|
|
34
|
+
cost += Math.abs((pos.get(a) ?? 0) - (pos.get(b) ?? 0));
|
|
35
|
+
return cost;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Top-to-bottom lane order that keeps the flows between lanes short: the
|
|
39
|
+
* declared order unless another order is strictly cheaper (ties keep what the
|
|
40
|
+
* author wrote). Nested lane sets and sets beyond six lanes keep their order.
|
|
41
|
+
*/
|
|
42
|
+
export function laneOrder(graph, leaves, leafOf, flat) {
|
|
43
|
+
if (!flat || leaves.length < 3 || leaves.length > MAX_ORDERED_LANES)
|
|
44
|
+
return leaves;
|
|
45
|
+
const pairs = [];
|
|
46
|
+
for (const flows of graph.outgoing.values()) {
|
|
47
|
+
for (const f of flows) {
|
|
48
|
+
// A loop or a lane's own end event should not pull the lanes apart.
|
|
49
|
+
if (graph.backEdges.has(f.id) || graph.byId.get(f.targetRef)?.type === "endEvent")
|
|
50
|
+
continue;
|
|
51
|
+
const from = graph.byId.has(f.sourceRef) ? leafOf.get(f.sourceRef) : undefined;
|
|
52
|
+
const to = leafOf.get(f.targetRef);
|
|
53
|
+
if (from && to && from !== to)
|
|
54
|
+
pairs.push([from, to]);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
let best = leaves;
|
|
58
|
+
let bestCost = crossLaneCost(pairs, new Map(leaves.map((id, i) => [id, i])));
|
|
59
|
+
const rest = (items) => items.length <= 1
|
|
60
|
+
? [items]
|
|
61
|
+
: items.flatMap((x, i) => rest([...items.slice(0, i), ...items.slice(i + 1)]).map((r) => [x, ...r]));
|
|
62
|
+
for (const order of rest(leaves)) {
|
|
63
|
+
const cost = crossLaneCost(pairs, new Map(order.map((id, i) => [id, i])));
|
|
64
|
+
if (cost < bestCost) {
|
|
65
|
+
best = order;
|
|
66
|
+
bestCost = cost;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return best;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Flows into the lane directly above or below that share their source's
|
|
73
|
+
* column, so the hand-over is a straight vertical run. One per source and
|
|
74
|
+
* direction; the target takes only that flow in, and neither end carries a
|
|
75
|
+
* boundary event (its handler would need the column).
|
|
76
|
+
*/
|
|
77
|
+
export function laneHandoffs(graph, leafOf, order,
|
|
78
|
+
/** Only sources with a single way on: plain hand-overs, no splits. */
|
|
79
|
+
plainOnly = false) {
|
|
80
|
+
const pos = new Map(order.map((id, i) => [id, i]));
|
|
81
|
+
const out = new Set();
|
|
82
|
+
const forwardIn = (id) => (graph.incoming.get(id) ?? []).filter((f) => !graph.backEdges.has(f.id)).length;
|
|
83
|
+
for (const node of graph.nodes) {
|
|
84
|
+
const from = leafOf.get(node.id);
|
|
85
|
+
if (from === undefined || graph.attachers.has(node.id))
|
|
86
|
+
continue;
|
|
87
|
+
const taken = new Set();
|
|
88
|
+
if (plainOnly && (graph.outgoing.get(node.id) ?? []).length !== 1)
|
|
89
|
+
continue;
|
|
90
|
+
for (const flow of graph.outgoing.get(node.id) ?? []) {
|
|
91
|
+
if (graph.backEdges.has(flow.id))
|
|
92
|
+
continue;
|
|
93
|
+
const to = leafOf.get(flow.targetRef);
|
|
94
|
+
if (to === undefined || graph.attachers.has(flow.targetRef))
|
|
95
|
+
continue;
|
|
96
|
+
const step = (pos.get(to) ?? 0) - (pos.get(from) ?? 0);
|
|
97
|
+
if (Math.abs(step) !== 1 || taken.has(step) || forwardIn(flow.targetRef) !== 1)
|
|
98
|
+
continue;
|
|
99
|
+
taken.add(step);
|
|
100
|
+
out.add(flow.id);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return out;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Cost of a laned layout, lower is better, compared term by term (a refinement must not lose in any): flows
|
|
107
|
+
* through a shape that is not theirs, crossings between flows, bends, how far
|
|
108
|
+
* the happy path strays from its mean row, area.
|
|
109
|
+
*/
|
|
110
|
+
export function laneCost(result) {
|
|
111
|
+
const nodes = new Map(result.nodes.map((n) => [n.id, n.bounds]));
|
|
112
|
+
let through = 0;
|
|
113
|
+
let bends = 0;
|
|
114
|
+
for (const e of result.edges) {
|
|
115
|
+
bends += Math.max(0, e.waypoints.length - 2);
|
|
116
|
+
for (let i = 1; i < e.waypoints.length; i++) {
|
|
117
|
+
const p = e.waypoints[i - 1];
|
|
118
|
+
const q = e.waypoints[i];
|
|
119
|
+
for (const [id, b] of nodes) {
|
|
120
|
+
if (id === e.sourceRef || id === e.targetRef)
|
|
121
|
+
continue;
|
|
122
|
+
if (Math.max(p.x, q.x) > b.x + 1 &&
|
|
123
|
+
Math.min(p.x, q.x) < b.x + b.width - 1 &&
|
|
124
|
+
Math.max(p.y, q.y) > b.y + 1 &&
|
|
125
|
+
Math.min(p.y, q.y) < b.y + b.height - 1)
|
|
126
|
+
through++;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
let crossings = 0;
|
|
131
|
+
for (let i = 0; i < result.edges.length; i++)
|
|
132
|
+
for (let j = i + 1; j < result.edges.length; j++)
|
|
133
|
+
crossings += pathCrossings(result.edges[i].waypoints, result.edges[j].waypoints);
|
|
134
|
+
let right = 0;
|
|
135
|
+
let bottom = 0;
|
|
136
|
+
for (const b of nodes.values()) {
|
|
137
|
+
right = Math.max(right, b.x + b.width);
|
|
138
|
+
bottom = Math.max(bottom, b.y + b.height);
|
|
139
|
+
}
|
|
140
|
+
return [through, crossings, bends, happyAxisDev(result), lengthCV(result), right * bottom];
|
|
141
|
+
}
|
|
142
|
+
/** True when `a` is no worse than `b` in any term and better in at least one. */
|
|
143
|
+
export function cheaper(a, b) {
|
|
144
|
+
let better = false;
|
|
145
|
+
for (let i = 0; i < a.length; i++) {
|
|
146
|
+
if (a[i] > b[i])
|
|
147
|
+
return false;
|
|
148
|
+
if (a[i] < b[i])
|
|
149
|
+
better = true;
|
|
150
|
+
}
|
|
151
|
+
return better;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Spread of the rows the first-declared forward path from each start event
|
|
155
|
+
* visits, the way `pnpm layout:score` measures it: lanes in an order that
|
|
156
|
+
* puts the happy path's lanes together score lower.
|
|
157
|
+
*/
|
|
158
|
+
function happyAxisDev(result) {
|
|
159
|
+
const centreY = new Map(result.nodes.map((n) => [n.id, n.bounds.y + n.bounds.height / 2]));
|
|
160
|
+
const devs = [];
|
|
161
|
+
for (const start of result.nodes.filter((n) => n.type === "startEvent")) {
|
|
162
|
+
const seen = new Set([start.id]);
|
|
163
|
+
let cur = start.id;
|
|
164
|
+
for (;;) {
|
|
165
|
+
const next = result.edges.find((e) => e.sourceRef === cur && !seen.has(e.targetRef));
|
|
166
|
+
if (!next)
|
|
167
|
+
break;
|
|
168
|
+
seen.add(next.targetRef);
|
|
169
|
+
cur = next.targetRef;
|
|
170
|
+
}
|
|
171
|
+
const ys = [...seen].map((id) => centreY.get(id)).filter((y) => y !== undefined);
|
|
172
|
+
const mean = ys.reduce((a, b) => a + b, 0) / Math.max(1, ys.length);
|
|
173
|
+
devs.push(Math.sqrt(ys.reduce((a, y) => a + (y - mean) ** 2, 0) / Math.max(1, ys.length)));
|
|
174
|
+
}
|
|
175
|
+
return Math.round(devs.reduce((a, b) => a + b, 0) / Math.max(1, devs.length));
|
|
176
|
+
}
|
|
177
|
+
/** Lane membership, declared order and the cheaper top-to-bottom order, when there is one. */
|
|
178
|
+
export function lanePlan(graph, laneSet) {
|
|
179
|
+
const { leaves, leafOf, flat } = leafLanes(laneSet);
|
|
180
|
+
const order = laneOrder(graph, leaves, leafOf, flat);
|
|
181
|
+
return { leafOf, order: flat && order !== leaves ? order : undefined, declared: leaves, flat };
|
|
182
|
+
}
|
|
183
|
+
/** Coefficient of variation of the flows' path lengths, to two decimals. */
|
|
184
|
+
function lengthCV(result) {
|
|
185
|
+
const lengths = result.edges.map((e) => {
|
|
186
|
+
let sum = 0;
|
|
187
|
+
for (let i = 1; i < e.waypoints.length; i++) {
|
|
188
|
+
const p = e.waypoints[i - 1];
|
|
189
|
+
const q = e.waypoints[i];
|
|
190
|
+
sum += Math.abs(p.x - q.x) + Math.abs(p.y - q.y);
|
|
191
|
+
}
|
|
192
|
+
return sum;
|
|
193
|
+
});
|
|
194
|
+
const mean = lengths.reduce((a, b) => a + b, 0) / Math.max(1, lengths.length);
|
|
195
|
+
const sd = Math.sqrt(lengths.reduce((a, l) => a + (l - mean) ** 2, 0) / Math.max(1, lengths.length));
|
|
196
|
+
return Math.round((100 * sd) / Math.max(1, mean)) / 100;
|
|
197
|
+
}
|
|
198
|
+
//# sourceMappingURL=lanes.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { BpmnFlowElement, BpmnLaneSet } from "../../bpmn/bpmn-model.js";
|
|
2
2
|
import type { Bounds, GridHint } from "../types.js";
|
|
3
3
|
import { type BandLayout } from "./bands.js";
|
|
4
|
-
import type
|
|
4
|
+
import { type SemanticGraph } from "./graph.js";
|
|
5
5
|
/**
|
|
6
6
|
* Geometry constants. Layout may add space beyond these; it never takes any back.
|
|
7
7
|
* Hand-drawn diagrams keep about 50-60 px between neighbouring shapes; wider
|
|
@@ -17,6 +17,8 @@ export declare const CONTAINER_GAP = 100;
|
|
|
17
17
|
export declare const COMPONENT_GAP = 80;
|
|
18
18
|
export declare const LANE_PADDING = 40;
|
|
19
19
|
export declare const BOUNDARY_SIZE = 36;
|
|
20
|
+
/** Height of a lane band with nothing in it: room for one boundary-sized row. */
|
|
21
|
+
export declare const MIN_LANE_HEIGHT: number;
|
|
20
22
|
/**
|
|
21
23
|
* Width of the label an event or gateway carries centred below its shape;
|
|
22
24
|
* undefined for types whose name sits inside the shape.
|
|
@@ -47,6 +49,14 @@ export declare function sizeOf(el: BpmnFlowElement, childExtent?: Bounds): {
|
|
|
47
49
|
* their tallest. Nodes are centred in both, so any two nodes sharing a band
|
|
48
50
|
* share a centre line and the spine routes as one straight segment.
|
|
49
51
|
*/
|
|
52
|
+
export interface LaneOptions {
|
|
53
|
+
/** Leaf lane ids top to bottom (default: declared order). */
|
|
54
|
+
order?: readonly string[];
|
|
55
|
+
/** Pull off-row nodes up onto earlier rows of their lane. */
|
|
56
|
+
compact?: boolean;
|
|
57
|
+
/** Nodes of different lanes never push each other down a row. */
|
|
58
|
+
byLane?: boolean;
|
|
59
|
+
}
|
|
50
60
|
export declare function place(graph: SemanticGraph, bandLayout: BandLayout, sizes: Map<string, {
|
|
51
61
|
width: number;
|
|
52
62
|
height: number;
|
|
@@ -71,5 +81,39 @@ grid?: GridHint,
|
|
|
71
81
|
* container's top to its inner spine. The container is hung so that spine
|
|
72
82
|
* continues the row's line, and the flow runs straight through it.
|
|
73
83
|
*/
|
|
74
|
-
axes?: ReadonlyMap<string, number
|
|
84
|
+
axes?: ReadonlyMap<string, number>,
|
|
85
|
+
/** Slot flow-less data references under the activity they are wired to. */
|
|
86
|
+
slotArtifacts?: boolean,
|
|
87
|
+
/** Lane refinements; absent or all off lays lanes out the way they always were. */
|
|
88
|
+
laneOpts?: LaneOptions): Placement;
|
|
89
|
+
/**
|
|
90
|
+
* The gap in front of each rank. At least {@link H_GAP}; wider where a flow
|
|
91
|
+
* label sits between two neighbouring columns, or where events' and gateways'
|
|
92
|
+
* labels, centred below shapes narrower than themselves, would meet.
|
|
93
|
+
*/
|
|
94
|
+
export declare function columnGaps(graph: SemanticGraph, sizes: Map<string, {
|
|
95
|
+
width: number;
|
|
96
|
+
height: number;
|
|
97
|
+
}>, colWidth: Map<number, number>, ranks: number[]): Map<number, number>;
|
|
98
|
+
/**
|
|
99
|
+
* Dock boundary events on their host's edge — escalation on top, everything
|
|
100
|
+
* else on the bottom — spread along it. Events sharing a side are ordered by
|
|
101
|
+
* how far out from that border their handler ended up, then how far it runs —
|
|
102
|
+
* farthest first, so outer slots serve outer paths and the routes nest.
|
|
103
|
+
* The side comes from {@link boundarySide}, the rule that also placed the
|
|
104
|
+
* handler's band, so a handler is never routed around its own host.
|
|
105
|
+
*/
|
|
106
|
+
export declare function dockBoundaryEvents(graph: SemanticGraph, bounds: Map<string, Bounds>, titled: ReadonlySet<string>): void;
|
|
107
|
+
/**
|
|
108
|
+
* Flow-less data references mapped to the activity they are wired to (the
|
|
109
|
+
* first one declared), so they can be slotted next to it.
|
|
110
|
+
*/
|
|
111
|
+
export declare function artifactOwnersOf(graph: SemanticGraph): Map<string, string>;
|
|
112
|
+
/**
|
|
113
|
+
* Put each artifact on its activity's centre line, below it first (the
|
|
114
|
+
* association is then one short vertical line), above it for a second one
|
|
115
|
+
* (and first when boundary events hang below). More go beside those, and a
|
|
116
|
+
* taken spot sends the artifact down until the area is clear.
|
|
117
|
+
*/
|
|
118
|
+
export declare function placeArtifacts(graph: SemanticGraph, owners: ReadonlyMap<string, string>, bounds: Map<string, Bounds>): void;
|
|
75
119
|
//# sourceMappingURL=place.d.ts.map
|