@leitwerk-dev/workflow-graph 0.0.0-stage → 0.4.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/README.md +33 -2
- package/dist/LICENSE +13 -0
- package/dist/WorkflowGraph.svelte +366 -0
- package/dist/WorkflowIcon.svelte +30 -0
- package/dist/WorkflowRoute.svelte +89 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +374 -0
- package/dist/index.js.map +1 -0
- package/dist/layout.d.ts +67 -0
- package/dist/layout.d.ts.map +1 -0
- package/package.json +52 -5
- package/src/WorkflowGraph.svelte +366 -0
- package/src/WorkflowIcon.svelte +30 -0
- package/src/WorkflowRoute.svelte +89 -0
- package/src/index.ts +9 -0
- package/src/layout.ts +531 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,374 @@
|
|
|
1
|
+
// src/layout.ts
|
|
2
|
+
import { shortestSuccessfulTurnPath } from "@leitwerk-dev/domain";
|
|
3
|
+
var turnId = (id) => `turn:${id}`;
|
|
4
|
+
var endId = (status) => `end:${status}`;
|
|
5
|
+
function shortestSuccessfulPath(flow) {
|
|
6
|
+
const ids = new Set(flow.nodes.map((node) => node.turnId));
|
|
7
|
+
const entry = flow.entryTurnIds.find((id) => ids.has(id)) ?? flow.nodes[0]?.turnId;
|
|
8
|
+
if (!entry) return [];
|
|
9
|
+
return shortestSuccessfulTurnPath(
|
|
10
|
+
entry,
|
|
11
|
+
(id) => flow.edges.filter((edge) => edge.from === id).flatMap(
|
|
12
|
+
(edge) => edge.lifecycleStatus === "completed" ? [null] : edge.to !== null && ids.has(edge.to) ? [edge.to] : []
|
|
13
|
+
)
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
function turnKindLabel(kind) {
|
|
17
|
+
switch (kind) {
|
|
18
|
+
case "llm":
|
|
19
|
+
return "LLM turn";
|
|
20
|
+
case "automatic":
|
|
21
|
+
return "Automation";
|
|
22
|
+
case "human":
|
|
23
|
+
return "Operator decision";
|
|
24
|
+
case "external":
|
|
25
|
+
return "External wait";
|
|
26
|
+
case "completed":
|
|
27
|
+
return "Completed";
|
|
28
|
+
case "aborted":
|
|
29
|
+
return "Aborted";
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function makeNode(definition) {
|
|
33
|
+
const repeated = definition.repetition === "sequential";
|
|
34
|
+
const width = repeated ? 380 : definition.description.length > 50 ? 260 : 225;
|
|
35
|
+
const lines = Math.min(
|
|
36
|
+
3,
|
|
37
|
+
Math.max(1, Math.ceil(definition.description.length / (repeated ? 23 : 24)))
|
|
38
|
+
);
|
|
39
|
+
const activityHeight = 85 + (lines - 1) * 21;
|
|
40
|
+
const height = repeated ? activityHeight + 115 : Math.max(112, 90 + lines * 21);
|
|
41
|
+
return {
|
|
42
|
+
id: turnId(definition.turnId),
|
|
43
|
+
turnId: definition.turnId,
|
|
44
|
+
title: definition.description,
|
|
45
|
+
kind: definition.turnType,
|
|
46
|
+
definition,
|
|
47
|
+
synthetic: false,
|
|
48
|
+
column: 0,
|
|
49
|
+
lane: 0,
|
|
50
|
+
x: 0,
|
|
51
|
+
y: 0,
|
|
52
|
+
width,
|
|
53
|
+
height,
|
|
54
|
+
repeat: repeated ? {
|
|
55
|
+
activity: { x: 18, y: 57.5, width: 235, height: activityHeight },
|
|
56
|
+
collector: { x: 326, y: height / 2 },
|
|
57
|
+
axis: height / 2,
|
|
58
|
+
loopY: height - 22
|
|
59
|
+
} : null
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
function layoutWorkflow(flow) {
|
|
63
|
+
const nodes = flow.nodes.map(makeNode);
|
|
64
|
+
const statuses = new Map(flow.endStates.map((state) => [state.lifecycleStatus, state.synthetic]));
|
|
65
|
+
for (const edge of flow.edges)
|
|
66
|
+
if (edge.lifecycleStatus) statuses.set(edge.lifecycleStatus, false);
|
|
67
|
+
for (const [status, synthetic] of statuses)
|
|
68
|
+
nodes.push({
|
|
69
|
+
id: endId(status),
|
|
70
|
+
turnId: null,
|
|
71
|
+
title: turnKindLabel(status),
|
|
72
|
+
kind: status,
|
|
73
|
+
definition: null,
|
|
74
|
+
synthetic,
|
|
75
|
+
column: 0,
|
|
76
|
+
lane: 0,
|
|
77
|
+
x: 0,
|
|
78
|
+
y: 0,
|
|
79
|
+
width: 190,
|
|
80
|
+
height: 70,
|
|
81
|
+
repeat: null
|
|
82
|
+
});
|
|
83
|
+
const byId = new Map(nodes.map((node) => [node.id, node]));
|
|
84
|
+
const spine = shortestSuccessfulPath(flow);
|
|
85
|
+
const mainPath = spine.map(turnId);
|
|
86
|
+
if (flow.edges.some((edge) => edge.from === spine.at(-1) && edge.lifecycleStatus === "completed"))
|
|
87
|
+
mainPath.push(endId("completed"));
|
|
88
|
+
const edges = flow.edges.flatMap((edge, index) => {
|
|
89
|
+
const from = turnId(edge.from);
|
|
90
|
+
const to = edge.to !== null ? turnId(edge.to) : edge.lifecycleStatus ? endId(edge.lifecycleStatus) : null;
|
|
91
|
+
return to && byId.has(from) && byId.has(to) ? [
|
|
92
|
+
{
|
|
93
|
+
id: `route-${index}`,
|
|
94
|
+
from,
|
|
95
|
+
to,
|
|
96
|
+
label: edge.label,
|
|
97
|
+
...edge.condition ? { condition: edge.condition } : {},
|
|
98
|
+
kind: edge.kind,
|
|
99
|
+
points: [],
|
|
100
|
+
labelPosition: { x: 0, y: 0 },
|
|
101
|
+
sourceSide: "right",
|
|
102
|
+
targetSide: "left"
|
|
103
|
+
}
|
|
104
|
+
] : [];
|
|
105
|
+
});
|
|
106
|
+
const placed = /* @__PURE__ */ new Set();
|
|
107
|
+
const occupied = /* @__PURE__ */ new Set();
|
|
108
|
+
const place = (id, column, lane) => {
|
|
109
|
+
const node = byId.get(id);
|
|
110
|
+
if (!node || placed.has(id)) return;
|
|
111
|
+
while (occupied.has(`${column}:${lane}`)) lane += lane < 0 ? -1 : 1;
|
|
112
|
+
node.column = column;
|
|
113
|
+
node.lane = lane;
|
|
114
|
+
placed.add(id);
|
|
115
|
+
occupied.add(`${column}:${lane}`);
|
|
116
|
+
};
|
|
117
|
+
for (const [column, id] of mainPath.entries()) place(id, column, 0);
|
|
118
|
+
for (const id of placed) {
|
|
119
|
+
const parent = byId.get(id);
|
|
120
|
+
if (!parent) continue;
|
|
121
|
+
for (const edge of edges.filter((edge2) => edge2.from === id)) {
|
|
122
|
+
const next = byId.get(edge.to);
|
|
123
|
+
if (!next || placed.has(next.id)) continue;
|
|
124
|
+
place(
|
|
125
|
+
next.id,
|
|
126
|
+
parent.column + 1,
|
|
127
|
+
parent.lane || (next.kind === "human" || next.kind === "aborted" ? -1 : 1)
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
for (const node of nodes)
|
|
132
|
+
if (!placed.has(node.id))
|
|
133
|
+
place(node.id, node.synthetic ? Math.max(0, mainPath.length - 1) : 0, 1);
|
|
134
|
+
for (const edge of edges) {
|
|
135
|
+
const from = byId.get(edge.from);
|
|
136
|
+
const to = byId.get(edge.to);
|
|
137
|
+
if (to.column <= from.column && canReach(edge.to, edge.from, edges)) edge.kind = "loopback";
|
|
138
|
+
}
|
|
139
|
+
const columnCount = Math.max(0, ...nodes.map((node) => node.column)) + 1;
|
|
140
|
+
const widths = Array.from(
|
|
141
|
+
{ length: columnCount },
|
|
142
|
+
(_, column) => Math.max(225, ...nodes.filter((node) => node.column === column).map((node) => node.width))
|
|
143
|
+
);
|
|
144
|
+
const columns = [];
|
|
145
|
+
let x = 50;
|
|
146
|
+
for (const width of widths) {
|
|
147
|
+
columns.push(x);
|
|
148
|
+
x += width + 115;
|
|
149
|
+
}
|
|
150
|
+
const lanes = [...new Set(nodes.map((node) => node.lane))].sort((a, b) => a - b);
|
|
151
|
+
const laneCenters = /* @__PURE__ */ new Map();
|
|
152
|
+
let y = 90 + edges.filter((edge) => edge.kind === "loopback").length * 22;
|
|
153
|
+
for (const lane of lanes) {
|
|
154
|
+
const height = Math.max(
|
|
155
|
+
130,
|
|
156
|
+
...nodes.filter((node) => node.lane === lane).map((node) => node.height)
|
|
157
|
+
);
|
|
158
|
+
laneCenters.set(lane, y + height / 2);
|
|
159
|
+
y += height + 85;
|
|
160
|
+
}
|
|
161
|
+
for (const node of nodes) {
|
|
162
|
+
node.x = columns[node.column] + (widths[node.column] - node.width) / 2;
|
|
163
|
+
node.y = (laneCenters.get(node.lane) ?? 0) - node.height / 2;
|
|
164
|
+
}
|
|
165
|
+
for (const edge of edges) {
|
|
166
|
+
const from = byId.get(edge.from);
|
|
167
|
+
const to = byId.get(edge.to);
|
|
168
|
+
if (edge.kind === "loopback") {
|
|
169
|
+
edge.sourceSide = "top";
|
|
170
|
+
edge.targetSide = "top";
|
|
171
|
+
} else if (from.column === to.column) {
|
|
172
|
+
edge.sourceSide = from.y < to.y ? "bottom" : "top";
|
|
173
|
+
edge.targetSide = from.y < to.y ? "top" : "bottom";
|
|
174
|
+
} else if (from.lane === to.lane) {
|
|
175
|
+
edge.sourceSide = "right";
|
|
176
|
+
edge.targetSide = "left";
|
|
177
|
+
} else if (to.lane !== 0 && from.lane === 0) {
|
|
178
|
+
edge.sourceSide = to.lane < from.lane ? "top" : "bottom";
|
|
179
|
+
edge.targetSide = "left";
|
|
180
|
+
} else if (from.lane !== 0 && to.lane === 0) {
|
|
181
|
+
edge.sourceSide = to.lane < from.lane ? "top" : "bottom";
|
|
182
|
+
edge.targetSide = to.lane < from.lane ? "bottom" : "top";
|
|
183
|
+
} else {
|
|
184
|
+
edge.sourceSide = to.column < from.column ? "left" : "right";
|
|
185
|
+
edge.targetSide = to.column < from.column ? "right" : "left";
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
const isMain = (edge) => mainPath.indexOf(edge.from) >= 0 && mainPath[mainPath.indexOf(edge.from) + 1] === edge.to;
|
|
189
|
+
const port = (edge, source) => {
|
|
190
|
+
const node = byId.get(source ? edge.from : edge.to);
|
|
191
|
+
const side = source ? edge.sourceSide : edge.targetSide;
|
|
192
|
+
const horizontal = side === "left" || side === "right";
|
|
193
|
+
const peers = edges.flatMap((other) => [
|
|
194
|
+
...other.from === node.id && other.sourceSide === side && (!node.repeat || source) ? [{ edge: other, source: true, opposite: byId.get(other.to) }] : [],
|
|
195
|
+
...other.to === node.id && other.targetSide === side && (!node.repeat || !source) ? [{ edge: other, source: false, opposite: byId.get(other.from) }] : []
|
|
196
|
+
]).sort((a, b) => {
|
|
197
|
+
const first = a.opposite;
|
|
198
|
+
const second = b.opposite;
|
|
199
|
+
const distance = horizontal ? first.y + first.height / 2 - (second.y + second.height / 2) : first.x + first.width / 2 - (second.x + second.width / 2);
|
|
200
|
+
return distance || Number(a.source) - Number(b.source);
|
|
201
|
+
});
|
|
202
|
+
const primary = peers.find(({ edge: other }) => isMain(other));
|
|
203
|
+
const center = primary ? peers.indexOf(primary) : (peers.length - 1) / 2;
|
|
204
|
+
const available = horizontal ? (node.repeat?.activity.height ?? node.height) / 2 - 16 : node.repeat ? source ? 28 : 10 : node.width / 2 - 52;
|
|
205
|
+
const spacing = Math.min(32, available / Math.max(1, center, peers.length - 1 - center));
|
|
206
|
+
const index = peers.findIndex((peer) => peer.edge === edge && peer.source === source);
|
|
207
|
+
const spread = (index - center) * spacing;
|
|
208
|
+
const cx = node.x + (node.repeat ? source ? 326 : 240 : node.width / 2 + (edge.from === edge.to ? source ? 36 : -36 : 0));
|
|
209
|
+
const cy = node.y + node.height / 2;
|
|
210
|
+
if (side === "left") return { x: node.x, y: cy + spread };
|
|
211
|
+
if (side === "right") return { x: node.x + node.width, y: cy + spread };
|
|
212
|
+
return { x: cx + spread, y: side === "top" ? node.y : node.y + node.height };
|
|
213
|
+
};
|
|
214
|
+
let loopIndex = 0;
|
|
215
|
+
const routed = [];
|
|
216
|
+
for (const edge of [...edges].sort((a, b) => Number(isMain(b)) - Number(isMain(a)))) {
|
|
217
|
+
const start = port(edge, true), end = port(edge, false);
|
|
218
|
+
const from = escapePort(start, edge.sourceSide), to = escapePort(end, edge.targetSide);
|
|
219
|
+
const rejoinsMainPath = byId.get(edge.from)?.lane !== 0 && byId.get(edge.to)?.lane === 0;
|
|
220
|
+
const preferredY = edge.kind === "loopback" ? 28 + loopIndex++ * 22 : rejoinsMainPath && (edge.sourceSide === "top" || edge.sourceSide === "bottom") && (edge.targetSide === "top" || edge.targetSide === "bottom") ? (start.y + end.y) / 2 : void 0;
|
|
221
|
+
const middle = route(from, to, nodes, routed, preferredY);
|
|
222
|
+
edge.points = simplify([start, ...middle, end]);
|
|
223
|
+
routed.push(edge.points);
|
|
224
|
+
edge.labelPosition = routeLabel(edge.points);
|
|
225
|
+
}
|
|
226
|
+
return { width: x - 65, height: y - 35, nodes, edges, mainPath };
|
|
227
|
+
}
|
|
228
|
+
function canReach(start, target, edges) {
|
|
229
|
+
const visited = /* @__PURE__ */ new Set([start]);
|
|
230
|
+
for (const id of visited) {
|
|
231
|
+
if (id === target) return true;
|
|
232
|
+
for (const edge of edges) if (edge.from === id) visited.add(edge.to);
|
|
233
|
+
}
|
|
234
|
+
return false;
|
|
235
|
+
}
|
|
236
|
+
function escapePort(point, side) {
|
|
237
|
+
return {
|
|
238
|
+
x: point.x + (side === "right" ? 20 : side === "left" ? -20 : 0),
|
|
239
|
+
y: point.y + (side === "bottom" ? 20 : side === "top" ? -20 : 0)
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
function simplify(points) {
|
|
243
|
+
const result = [];
|
|
244
|
+
for (const point of points) {
|
|
245
|
+
const last = result.at(-1), before = result.at(-2);
|
|
246
|
+
if (last && last.x === point.x && last.y === point.y) continue;
|
|
247
|
+
if (before && last && (before.x === last.x && last.x === point.x || before.y === last.y && last.y === point.y))
|
|
248
|
+
result.pop();
|
|
249
|
+
result.push(point);
|
|
250
|
+
}
|
|
251
|
+
return result;
|
|
252
|
+
}
|
|
253
|
+
function strictBoundsOverlap(a, b, c, d) {
|
|
254
|
+
return Math.max(a.x, b.x) > Math.min(c.x, d.x) && Math.min(a.x, b.x) < Math.max(c.x, d.x) && Math.max(a.y, b.y) > Math.min(c.y, d.y) && Math.min(a.y, b.y) < Math.max(c.y, d.y);
|
|
255
|
+
}
|
|
256
|
+
function clearSegment(a, b, nodes) {
|
|
257
|
+
return !nodes.some(
|
|
258
|
+
(node) => strictBoundsOverlap(
|
|
259
|
+
a,
|
|
260
|
+
b,
|
|
261
|
+
{ x: node.x - 10, y: node.y - 10 },
|
|
262
|
+
{ x: node.x + node.width + 10, y: node.y + node.height + 10 }
|
|
263
|
+
)
|
|
264
|
+
);
|
|
265
|
+
}
|
|
266
|
+
function route(start, end, nodes, previous, preferredY) {
|
|
267
|
+
const xs = [
|
|
268
|
+
.../* @__PURE__ */ new Set([
|
|
269
|
+
start.x,
|
|
270
|
+
end.x,
|
|
271
|
+
...nodes.flatMap((node) => [node.x - 25, node.x + node.width + 25])
|
|
272
|
+
])
|
|
273
|
+
];
|
|
274
|
+
const ys = [
|
|
275
|
+
.../* @__PURE__ */ new Set([
|
|
276
|
+
start.y,
|
|
277
|
+
end.y,
|
|
278
|
+
preferredY ?? 28,
|
|
279
|
+
...nodes.flatMap((node) => [node.y - 25, node.y + node.height + 25])
|
|
280
|
+
])
|
|
281
|
+
];
|
|
282
|
+
const candidates = preferredY !== void 0 ? [[start, { x: start.x, y: preferredY }, { x: end.x, y: preferredY }, end]] : [
|
|
283
|
+
...start.x === end.x || start.y === end.y ? [[start, end]] : [],
|
|
284
|
+
[start, { x: start.x, y: end.y }, end],
|
|
285
|
+
[start, { x: end.x, y: start.y }, end],
|
|
286
|
+
...xs.map((x) => [start, { x, y: start.y }, { x, y: end.y }, end]),
|
|
287
|
+
...ys.map((y) => [start, { x: start.x, y }, { x: end.x, y }, end])
|
|
288
|
+
];
|
|
289
|
+
const legal = candidates.map(simplify).filter(
|
|
290
|
+
(points) => points.slice(1).every((point, index) => clearSegment(points[index], point, nodes))
|
|
291
|
+
);
|
|
292
|
+
const score = (points) => points.slice(1).reduce((sum, point, index) => {
|
|
293
|
+
const before = points[index];
|
|
294
|
+
const crossings = previous.reduce(
|
|
295
|
+
(count, route2) => count + route2.slice(1).filter((b, i) => strictBoundsOverlap(before, point, route2[i], b)).length,
|
|
296
|
+
0
|
|
297
|
+
);
|
|
298
|
+
return sum + Math.abs(before.x - point.x) + Math.abs(before.y - point.y) + crossings * 80;
|
|
299
|
+
}, points.length * 12);
|
|
300
|
+
legal.sort((a, b) => score(a) - score(b));
|
|
301
|
+
return legal[0] ?? gridRoute(start, end, xs, ys, nodes);
|
|
302
|
+
}
|
|
303
|
+
function gridRoute(start, end, xs, ys, nodes) {
|
|
304
|
+
xs.sort((a, b) => a - b);
|
|
305
|
+
ys.sort((a, b) => a - b);
|
|
306
|
+
const indexOf = (p) => ys.indexOf(p.y) * xs.length + xs.indexOf(p.x);
|
|
307
|
+
const pointAt = (index) => ({
|
|
308
|
+
x: xs[index % xs.length],
|
|
309
|
+
y: ys[Math.floor(index / xs.length)]
|
|
310
|
+
});
|
|
311
|
+
const first = indexOf(start), last = indexOf(end);
|
|
312
|
+
const open = /* @__PURE__ */ new Set([first]);
|
|
313
|
+
const costs = /* @__PURE__ */ new Map([[first, 0]]), parents = /* @__PURE__ */ new Map();
|
|
314
|
+
while (open.size) {
|
|
315
|
+
let current = first, best = Number.POSITIVE_INFINITY;
|
|
316
|
+
for (const index of open) {
|
|
317
|
+
const point2 = pointAt(index);
|
|
318
|
+
const cost = (costs.get(index) ?? 0) + Math.abs(point2.x - end.x) + Math.abs(point2.y - end.y);
|
|
319
|
+
if (cost < best) {
|
|
320
|
+
current = index;
|
|
321
|
+
best = cost;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
if (current === last) {
|
|
325
|
+
const points = [end];
|
|
326
|
+
while (parents.has(current)) {
|
|
327
|
+
current = parents.get(current);
|
|
328
|
+
points.push(pointAt(current));
|
|
329
|
+
}
|
|
330
|
+
return simplify(points.reverse());
|
|
331
|
+
}
|
|
332
|
+
open.delete(current);
|
|
333
|
+
const point = pointAt(current), xi = current % xs.length, yi = Math.floor(current / xs.length);
|
|
334
|
+
for (const [nx, ny] of [
|
|
335
|
+
[xi - 1, yi],
|
|
336
|
+
[xi + 1, yi],
|
|
337
|
+
[xi, yi - 1],
|
|
338
|
+
[xi, yi + 1]
|
|
339
|
+
]) {
|
|
340
|
+
if (nx < 0 || ny < 0 || nx >= xs.length || ny >= ys.length) continue;
|
|
341
|
+
const next = ny * xs.length + nx, target = pointAt(next);
|
|
342
|
+
if (!clearSegment(point, target, nodes)) continue;
|
|
343
|
+
const cost = (costs.get(current) ?? 0) + Math.abs(point.x - target.x) + Math.abs(point.y - target.y);
|
|
344
|
+
if (cost >= (costs.get(next) ?? Number.POSITIVE_INFINITY)) continue;
|
|
345
|
+
parents.set(next, current);
|
|
346
|
+
costs.set(next, cost);
|
|
347
|
+
open.add(next);
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
throw new Error("Workflow route has no clear corridor");
|
|
351
|
+
}
|
|
352
|
+
function routeLabel(points) {
|
|
353
|
+
let longest = -1, position = points[0] ?? { x: 0, y: 0 };
|
|
354
|
+
for (let index = 1; index < points.length; index++) {
|
|
355
|
+
const a = points[index - 1], b = points[index], length = Math.abs(a.x - b.x) + Math.abs(a.y - b.y);
|
|
356
|
+
if (length <= longest) continue;
|
|
357
|
+
longest = length;
|
|
358
|
+
position = {
|
|
359
|
+
x: (a.x + b.x) / 2 + (a.x === b.x ? 44 : 0),
|
|
360
|
+
y: (a.y + b.y) / 2 - (a.y === b.y ? 16 : 0)
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
return position;
|
|
364
|
+
}
|
|
365
|
+
function edgePath(points) {
|
|
366
|
+
return points.map((point, index) => `${index === 0 ? "M" : "L"}${point.x} ${point.y}`).join("");
|
|
367
|
+
}
|
|
368
|
+
export {
|
|
369
|
+
edgePath,
|
|
370
|
+
layoutWorkflow,
|
|
371
|
+
shortestSuccessfulPath,
|
|
372
|
+
turnKindLabel
|
|
373
|
+
};
|
|
374
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/layout.ts"],"sourcesContent":["import type {\n\tProcessFlowEdge,\n\tProcessFlowNode,\n\tProcessFlowView,\n\tProcessTurnType,\n} from \"@leitwerk-dev/domain\";\nimport { shortestSuccessfulTurnPath } from \"@leitwerk-dev/domain\";\n\n/** @internal */\nexport interface Point {\n\t/** @internal */ x: number;\n\t/** @internal */ y: number;\n}\n/** @internal */\nexport interface RepeatGeometry {\n\t/** @internal */ activity: {\n\t\t/** @internal */ x: number;\n\t\t/** @internal */ y: number;\n\t\t/** @internal */ width: number;\n\t\t/** @internal */ height: number;\n\t};\n\t/** @internal */ collector: Point;\n\t/** @internal */ axis: number;\n\t/** @internal */ loopY: number;\n}\n/** @internal */\nexport interface WorkflowNode {\n\t/** @internal */ id: string;\n\t/** @internal */ turnId: string | null;\n\t/** @internal */ title: string;\n\t/** @internal */ kind: ProcessTurnType | \"completed\" | \"aborted\";\n\t/** @internal */ definition: ProcessFlowNode | null;\n\t/** @internal */ synthetic: boolean;\n\t/** @internal */ column: number;\n\t/** @internal */ lane: number;\n\t/** @internal */ x: number;\n\t/** @internal */ y: number;\n\t/** @internal */ width: number;\n\t/** @internal */ height: number;\n\t/** @internal */ repeat: RepeatGeometry | null;\n}\n/** @internal */\ntype Side = \"left\" | \"right\" | \"top\" | \"bottom\";\n/** @internal */\nexport interface WorkflowEdge {\n\t/** @internal */ id: string;\n\t/** @internal */ from: string;\n\t/** @internal */ to: string;\n\t/** @internal */ label: string | null;\n\t/** @internal */ condition?: ProcessFlowEdge[\"condition\"];\n\t/** @internal */ kind: ProcessFlowEdge[\"kind\"];\n\t/** @internal */ points: Point[];\n\t/** @internal */ labelPosition: Point;\n\t/** @internal */ sourceSide: Side;\n\t/** @internal */ targetSide: Side;\n}\n/** @internal */\nexport interface WorkflowLayout {\n\t/** @internal */ width: number;\n\t/** @internal */ height: number;\n\t/** @internal */ nodes: WorkflowNode[];\n\t/** @internal */ edges: WorkflowEdge[];\n\t/** Layout node identities, including the completed terminal. @internal */ mainPath: string[];\n}\n\nconst turnId = (id: string) => `turn:${id}`;\nconst endId = (status: string) => `end:${status}`;\n\n/** Stable breadth-first search; abort and declared happy-path hints cannot shorten success. @internal */\nexport function shortestSuccessfulPath(flow: ProcessFlowView): string[] {\n\tconst ids = new Set(flow.nodes.map((node) => node.turnId));\n\tconst entry = flow.entryTurnIds.find((id) => ids.has(id)) ?? flow.nodes[0]?.turnId;\n\tif (!entry) return [];\n\treturn shortestSuccessfulTurnPath(entry, (id) =>\n\t\tflow.edges\n\t\t\t.filter((edge) => edge.from === id)\n\t\t\t.flatMap((edge) =>\n\t\t\t\tedge.lifecycleStatus === \"completed\"\n\t\t\t\t\t? [null]\n\t\t\t\t\t: edge.to !== null && ids.has(edge.to)\n\t\t\t\t\t\t? [edge.to]\n\t\t\t\t\t\t: [],\n\t\t\t),\n\t);\n}\n\n/** Labels match the Chronicle's turn-kind vocabulary. @internal */\nexport function turnKindLabel(kind: WorkflowNode[\"kind\"]): string {\n\tswitch (kind) {\n\t\tcase \"llm\":\n\t\t\treturn \"LLM turn\";\n\t\tcase \"automatic\":\n\t\t\treturn \"Automation\";\n\t\tcase \"human\":\n\t\t\treturn \"Operator decision\";\n\t\tcase \"external\":\n\t\t\treturn \"External wait\";\n\t\tcase \"completed\":\n\t\t\treturn \"Completed\";\n\t\tcase \"aborted\":\n\t\t\treturn \"Aborted\";\n\t}\n}\n\nfunction makeNode(definition: ProcessFlowNode): WorkflowNode {\n\tconst repeated = definition.repetition === \"sequential\";\n\tconst width = repeated ? 380 : definition.description.length > 50 ? 260 : 225;\n\tconst lines = Math.min(\n\t\t3,\n\t\tMath.max(1, Math.ceil(definition.description.length / (repeated ? 23 : 24))),\n\t);\n\tconst activityHeight = 85 + (lines - 1) * 21;\n\tconst height = repeated ? activityHeight + 115 : Math.max(112, 90 + lines * 21);\n\treturn {\n\t\tid: turnId(definition.turnId),\n\t\tturnId: definition.turnId,\n\t\ttitle: definition.description,\n\t\tkind: definition.turnType,\n\t\tdefinition,\n\t\tsynthetic: false,\n\t\tcolumn: 0,\n\t\tlane: 0,\n\t\tx: 0,\n\t\ty: 0,\n\t\twidth,\n\t\theight,\n\t\trepeat: repeated\n\t\t\t? {\n\t\t\t\t\tactivity: { x: 18, y: 57.5, width: 235, height: activityHeight },\n\t\t\t\t\tcollector: { x: 326, y: height / 2 },\n\t\t\t\t\taxis: height / 2,\n\t\t\t\t\tloopY: height - 22,\n\t\t\t\t}\n\t\t\t: null,\n\t};\n}\n\n/** Places the shortest successful path on one line and routes every declared transition. @internal */\nexport function layoutWorkflow(flow: ProcessFlowView): WorkflowLayout {\n\tconst nodes = flow.nodes.map(makeNode);\n\tconst statuses = new Map(flow.endStates.map((state) => [state.lifecycleStatus, state.synthetic]));\n\tfor (const edge of flow.edges)\n\t\tif (edge.lifecycleStatus) statuses.set(edge.lifecycleStatus, false);\n\tfor (const [status, synthetic] of statuses)\n\t\tnodes.push({\n\t\t\tid: endId(status),\n\t\t\tturnId: null,\n\t\t\ttitle: turnKindLabel(status),\n\t\t\tkind: status,\n\t\t\tdefinition: null,\n\t\t\tsynthetic,\n\t\t\tcolumn: 0,\n\t\t\tlane: 0,\n\t\t\tx: 0,\n\t\t\ty: 0,\n\t\t\twidth: 190,\n\t\t\theight: 70,\n\t\t\trepeat: null,\n\t\t});\n\tconst byId = new Map(nodes.map((node) => [node.id, node]));\n\tconst spine = shortestSuccessfulPath(flow);\n\tconst mainPath = spine.map(turnId);\n\tif (flow.edges.some((edge) => edge.from === spine.at(-1) && edge.lifecycleStatus === \"completed\"))\n\t\tmainPath.push(endId(\"completed\"));\n\tconst edges: WorkflowEdge[] = flow.edges.flatMap((edge, index) => {\n\t\tconst from = turnId(edge.from);\n\t\tconst to =\n\t\t\tedge.to !== null\n\t\t\t\t? turnId(edge.to)\n\t\t\t\t: edge.lifecycleStatus\n\t\t\t\t\t? endId(edge.lifecycleStatus)\n\t\t\t\t\t: null;\n\t\treturn to && byId.has(from) && byId.has(to)\n\t\t\t? [\n\t\t\t\t\t{\n\t\t\t\t\t\tid: `route-${index}`,\n\t\t\t\t\t\tfrom,\n\t\t\t\t\t\tto,\n\t\t\t\t\t\tlabel: edge.label,\n\t\t\t\t\t\t...(edge.condition ? { condition: edge.condition } : {}),\n\t\t\t\t\t\tkind: edge.kind,\n\t\t\t\t\t\tpoints: [],\n\t\t\t\t\t\tlabelPosition: { x: 0, y: 0 },\n\t\t\t\t\t\tsourceSide: \"right\" as const,\n\t\t\t\t\t\ttargetSide: \"left\" as const,\n\t\t\t\t\t},\n\t\t\t\t]\n\t\t\t: [];\n\t});\n\tconst placed = new Set<string>();\n\tconst occupied = new Set<string>();\n\tconst place = (id: string, column: number, lane: number) => {\n\t\tconst node = byId.get(id);\n\t\tif (!node || placed.has(id)) return;\n\t\twhile (occupied.has(`${column}:${lane}`)) lane += lane < 0 ? -1 : 1;\n\t\tnode.column = column;\n\t\tnode.lane = lane;\n\t\tplaced.add(id);\n\t\toccupied.add(`${column}:${lane}`);\n\t};\n\tfor (const [column, id] of mainPath.entries()) place(id, column, 0);\n\tfor (const id of placed) {\n\t\tconst parent = byId.get(id);\n\t\tif (!parent) continue;\n\t\tfor (const edge of edges.filter((edge) => edge.from === id)) {\n\t\t\tconst next = byId.get(edge.to);\n\t\t\tif (!next || placed.has(next.id)) continue;\n\t\t\tplace(\n\t\t\t\tnext.id,\n\t\t\t\tparent.column + 1,\n\t\t\t\tparent.lane || (next.kind === \"human\" || next.kind === \"aborted\" ? -1 : 1),\n\t\t\t);\n\t\t}\n\t}\n\t// Unreachable declarations and implicit abort remain visible without fabricated edges.\n\tfor (const node of nodes)\n\t\tif (!placed.has(node.id))\n\t\t\tplace(node.id, node.synthetic ? Math.max(0, mainPath.length - 1) : 0, 1);\n\tfor (const edge of edges) {\n\t\tconst from = byId.get(edge.from) as WorkflowNode;\n\t\tconst to = byId.get(edge.to) as WorkflowNode;\n\t\t// A side path may rejoin to its left without repeating any work.\n\t\tif (to.column <= from.column && canReach(edge.to, edge.from, edges)) edge.kind = \"loopback\";\n\t}\n\tconst columnCount = Math.max(0, ...nodes.map((node) => node.column)) + 1;\n\tconst widths = Array.from({ length: columnCount }, (_, column) =>\n\t\tMath.max(225, ...nodes.filter((node) => node.column === column).map((node) => node.width)),\n\t);\n\tconst columns: number[] = [];\n\tlet x = 50;\n\tfor (const width of widths) {\n\t\tcolumns.push(x);\n\t\tx += width + 115;\n\t}\n\tconst lanes = [...new Set(nodes.map((node) => node.lane))].sort((a, b) => a - b);\n\tconst laneCenters = new Map<number, number>();\n\tlet y = 90 + edges.filter((edge) => edge.kind === \"loopback\").length * 22;\n\tfor (const lane of lanes) {\n\t\tconst height = Math.max(\n\t\t\t130,\n\t\t\t...nodes.filter((node) => node.lane === lane).map((node) => node.height),\n\t\t);\n\t\tlaneCenters.set(lane, y + height / 2);\n\t\ty += height + 85;\n\t}\n\tfor (const node of nodes) {\n\t\tnode.x = columns[node.column] + (widths[node.column] - node.width) / 2;\n\t\tnode.y = (laneCenters.get(node.lane) ?? 0) - node.height / 2;\n\t}\n\tfor (const edge of edges) {\n\t\tconst from = byId.get(edge.from) as WorkflowNode;\n\t\tconst to = byId.get(edge.to) as WorkflowNode;\n\t\tif (edge.kind === \"loopback\") {\n\t\t\tedge.sourceSide = \"top\";\n\t\t\tedge.targetSide = \"top\";\n\t\t} else if (from.column === to.column) {\n\t\t\tedge.sourceSide = from.y < to.y ? \"bottom\" : \"top\";\n\t\t\tedge.targetSide = from.y < to.y ? \"top\" : \"bottom\";\n\t\t} else if (from.lane === to.lane) {\n\t\t\tedge.sourceSide = \"right\";\n\t\t\tedge.targetSide = \"left\";\n\t\t} else if (to.lane !== 0 && from.lane === 0) {\n\t\t\tedge.sourceSide = to.lane < from.lane ? \"top\" : \"bottom\";\n\t\t\tedge.targetSide = \"left\";\n\t\t} else if (from.lane !== 0 && to.lane === 0) {\n\t\t\tedge.sourceSide = to.lane < from.lane ? \"top\" : \"bottom\";\n\t\t\tedge.targetSide = to.lane < from.lane ? \"bottom\" : \"top\";\n\t\t} else {\n\t\t\tedge.sourceSide = to.column < from.column ? \"left\" : \"right\";\n\t\t\tedge.targetSide = to.column < from.column ? \"right\" : \"left\";\n\t\t}\n\t}\n\tconst isMain = (edge: WorkflowEdge) =>\n\t\tmainPath.indexOf(edge.from) >= 0 && mainPath[mainPath.indexOf(edge.from) + 1] === edge.to;\n\tconst port = (edge: WorkflowEdge, source: boolean): Point => {\n\t\tconst node = byId.get(source ? edge.from : edge.to) as WorkflowNode;\n\t\tconst side = source ? edge.sourceSide : edge.targetSide;\n\t\tconst horizontal = side === \"left\" || side === \"right\";\n\t\t// Incoming and outgoing connections share one port allocation per side.\n\t\t// Repeats already separate incoming activity ports from outgoing collection ports.\n\t\tconst peers = edges\n\t\t\t.flatMap((other) => [\n\t\t\t\t...(other.from === node.id && other.sourceSide === side && (!node.repeat || source)\n\t\t\t\t\t? [{ edge: other, source: true, opposite: byId.get(other.to) as WorkflowNode }]\n\t\t\t\t\t: []),\n\t\t\t\t...(other.to === node.id && other.targetSide === side && (!node.repeat || !source)\n\t\t\t\t\t? [{ edge: other, source: false, opposite: byId.get(other.from) as WorkflowNode }]\n\t\t\t\t\t: []),\n\t\t\t])\n\t\t\t.sort((a, b) => {\n\t\t\t\tconst first = a.opposite;\n\t\t\t\tconst second = b.opposite;\n\t\t\t\tconst distance = horizontal\n\t\t\t\t\t? first.y + first.height / 2 - (second.y + second.height / 2)\n\t\t\t\t\t: first.x + first.width / 2 - (second.x + second.width / 2);\n\t\t\t\treturn distance || Number(a.source) - Number(b.source);\n\t\t\t});\n\t\tconst primary = peers.find(({ edge: other }) => isMain(other));\n\t\tconst center = primary ? peers.indexOf(primary) : (peers.length - 1) / 2;\n\t\tconst available = horizontal\n\t\t\t? (node.repeat?.activity.height ?? node.height) / 2 - 16\n\t\t\t: node.repeat\n\t\t\t\t? source\n\t\t\t\t\t? 28\n\t\t\t\t\t: 10\n\t\t\t\t: node.width / 2 - 52;\n\t\tconst spacing = Math.min(32, available / Math.max(1, center, peers.length - 1 - center));\n\t\tconst index = peers.findIndex((peer) => peer.edge === edge && peer.source === source);\n\t\tconst spread = (index - center) * spacing;\n\t\tconst cx =\n\t\t\tnode.x +\n\t\t\t(node.repeat\n\t\t\t\t? source\n\t\t\t\t\t? 326\n\t\t\t\t\t: 240\n\t\t\t\t: node.width / 2 + (edge.from === edge.to ? (source ? 36 : -36) : 0));\n\t\tconst cy = node.y + node.height / 2;\n\t\tif (side === \"left\") return { x: node.x, y: cy + spread };\n\t\tif (side === \"right\") return { x: node.x + node.width, y: cy + spread };\n\t\treturn { x: cx + spread, y: side === \"top\" ? node.y : node.y + node.height };\n\t};\n\tlet loopIndex = 0;\n\tconst routed: Point[][] = [];\n\t// Main-line edges get the unobstructed central ports before side routes.\n\tfor (const edge of [...edges].sort((a, b) => Number(isMain(b)) - Number(isMain(a)))) {\n\t\tconst start = port(edge, true),\n\t\t\tend = port(edge, false);\n\t\tconst from = escapePort(start, edge.sourceSide),\n\t\t\tto = escapePort(end, edge.targetSide);\n\t\tconst rejoinsMainPath = byId.get(edge.from)?.lane !== 0 && byId.get(edge.to)?.lane === 0;\n\t\tconst preferredY =\n\t\t\tedge.kind === \"loopback\"\n\t\t\t\t? 28 + loopIndex++ * 22\n\t\t\t\t: rejoinsMainPath &&\n\t\t\t\t\t\t(edge.sourceSide === \"top\" || edge.sourceSide === \"bottom\") &&\n\t\t\t\t\t\t(edge.targetSide === \"top\" || edge.targetSide === \"bottom\")\n\t\t\t\t\t? (start.y + end.y) / 2\n\t\t\t\t\t: undefined;\n\t\tconst middle = route(from, to, nodes, routed, preferredY);\n\t\tedge.points = simplify([start, ...middle, end]);\n\t\trouted.push(edge.points);\n\t\tedge.labelPosition = routeLabel(edge.points);\n\t}\n\treturn { width: x - 65, height: y - 35, nodes, edges, mainPath };\n}\n\nfunction canReach(start: string, target: string, edges: WorkflowEdge[]): boolean {\n\tconst visited = new Set([start]);\n\tfor (const id of visited) {\n\t\tif (id === target) return true;\n\t\tfor (const edge of edges) if (edge.from === id) visited.add(edge.to);\n\t}\n\treturn false;\n}\n\nfunction escapePort(point: Point, side: Side): Point {\n\treturn {\n\t\tx: point.x + (side === \"right\" ? 20 : side === \"left\" ? -20 : 0),\n\t\ty: point.y + (side === \"bottom\" ? 20 : side === \"top\" ? -20 : 0),\n\t};\n}\nfunction simplify(points: Point[]): Point[] {\n\tconst result: Point[] = [];\n\tfor (const point of points) {\n\t\tconst last = result.at(-1),\n\t\t\tbefore = result.at(-2);\n\t\tif (last && last.x === point.x && last.y === point.y) continue;\n\t\tif (\n\t\t\tbefore &&\n\t\t\tlast &&\n\t\t\t((before.x === last.x && last.x === point.x) || (before.y === last.y && last.y === point.y))\n\t\t)\n\t\t\tresult.pop();\n\t\tresult.push(point);\n\t}\n\treturn result;\n}\nfunction strictBoundsOverlap(a: Point, b: Point, c: Point, d: Point): boolean {\n\treturn (\n\t\tMath.max(a.x, b.x) > Math.min(c.x, d.x) &&\n\t\tMath.min(a.x, b.x) < Math.max(c.x, d.x) &&\n\t\tMath.max(a.y, b.y) > Math.min(c.y, d.y) &&\n\t\tMath.min(a.y, b.y) < Math.max(c.y, d.y)\n\t);\n}\nfunction clearSegment(a: Point, b: Point, nodes: WorkflowNode[]): boolean {\n\treturn !nodes.some((node) =>\n\t\tstrictBoundsOverlap(\n\t\t\ta,\n\t\t\tb,\n\t\t\t{ x: node.x - 10, y: node.y - 10 },\n\t\t\t{ x: node.x + node.width + 10, y: node.y + node.height + 10 },\n\t\t),\n\t);\n}\nfunction route(\n\tstart: Point,\n\tend: Point,\n\tnodes: WorkflowNode[],\n\tprevious: Point[][],\n\tpreferredY?: number,\n): Point[] {\n\tconst xs = [\n\t\t...new Set([\n\t\t\tstart.x,\n\t\t\tend.x,\n\t\t\t...nodes.flatMap((node) => [node.x - 25, node.x + node.width + 25]),\n\t\t]),\n\t];\n\tconst ys = [\n\t\t...new Set([\n\t\t\tstart.y,\n\t\t\tend.y,\n\t\t\tpreferredY ?? 28,\n\t\t\t...nodes.flatMap((node) => [node.y - 25, node.y + node.height + 25]),\n\t\t]),\n\t];\n\tconst candidates =\n\t\tpreferredY !== undefined\n\t\t\t? [[start, { x: start.x, y: preferredY }, { x: end.x, y: preferredY }, end]]\n\t\t\t: [\n\t\t\t\t\t...(start.x === end.x || start.y === end.y ? [[start, end]] : []),\n\t\t\t\t\t[start, { x: start.x, y: end.y }, end],\n\t\t\t\t\t[start, { x: end.x, y: start.y }, end],\n\t\t\t\t\t...xs.map((x) => [start, { x, y: start.y }, { x, y: end.y }, end]),\n\t\t\t\t\t...ys.map((y) => [start, { x: start.x, y }, { x: end.x, y }, end]),\n\t\t\t\t];\n\tconst legal = candidates\n\t\t.map(simplify)\n\t\t.filter((points) =>\n\t\t\tpoints.slice(1).every((point, index) => clearSegment(points[index], point, nodes)),\n\t\t);\n\tconst score = (points: Point[]) =>\n\t\tpoints.slice(1).reduce((sum, point, index) => {\n\t\t\tconst before = points[index];\n\t\t\tconst crossings = previous.reduce(\n\t\t\t\t(count, route) =>\n\t\t\t\t\tcount +\n\t\t\t\t\troute.slice(1).filter((b, i) => strictBoundsOverlap(before, point, route[i], b)).length,\n\t\t\t\t0,\n\t\t\t);\n\t\t\treturn sum + Math.abs(before.x - point.x) + Math.abs(before.y - point.y) + crossings * 80;\n\t\t}, points.length * 12);\n\tlegal.sort((a, b) => score(a) - score(b));\n\treturn legal[0] ?? gridRoute(start, end, xs, ys, nodes);\n}\n\n// Unusual cross-links can require more bends than the simple candidates above.\nfunction gridRoute(\n\tstart: Point,\n\tend: Point,\n\txs: number[],\n\tys: number[],\n\tnodes: WorkflowNode[],\n): Point[] {\n\txs.sort((a, b) => a - b);\n\tys.sort((a, b) => a - b);\n\tconst indexOf = (p: Point) => ys.indexOf(p.y) * xs.length + xs.indexOf(p.x);\n\tconst pointAt = (index: number) => ({\n\t\tx: xs[index % xs.length],\n\t\ty: ys[Math.floor(index / xs.length)],\n\t});\n\tconst first = indexOf(start),\n\t\tlast = indexOf(end);\n\tconst open = new Set([first]);\n\tconst costs = new Map([[first, 0]]),\n\t\tparents = new Map<number, number>();\n\twhile (open.size) {\n\t\tlet current = first,\n\t\t\tbest = Number.POSITIVE_INFINITY;\n\t\tfor (const index of open) {\n\t\t\tconst point = pointAt(index);\n\t\t\tconst cost = (costs.get(index) ?? 0) + Math.abs(point.x - end.x) + Math.abs(point.y - end.y);\n\t\t\tif (cost < best) {\n\t\t\t\tcurrent = index;\n\t\t\t\tbest = cost;\n\t\t\t}\n\t\t}\n\t\tif (current === last) {\n\t\t\tconst points = [end];\n\t\t\twhile (parents.has(current)) {\n\t\t\t\tcurrent = parents.get(current) as number;\n\t\t\t\tpoints.push(pointAt(current));\n\t\t\t}\n\t\t\treturn simplify(points.reverse());\n\t\t}\n\t\topen.delete(current);\n\t\tconst point = pointAt(current),\n\t\t\txi = current % xs.length,\n\t\t\tyi = Math.floor(current / xs.length);\n\t\tfor (const [nx, ny] of [\n\t\t\t[xi - 1, yi],\n\t\t\t[xi + 1, yi],\n\t\t\t[xi, yi - 1],\n\t\t\t[xi, yi + 1],\n\t\t]) {\n\t\t\tif (nx < 0 || ny < 0 || nx >= xs.length || ny >= ys.length) continue;\n\t\t\tconst next = ny * xs.length + nx,\n\t\t\t\ttarget = pointAt(next);\n\t\t\tif (!clearSegment(point, target, nodes)) continue;\n\t\t\tconst cost =\n\t\t\t\t(costs.get(current) ?? 0) + Math.abs(point.x - target.x) + Math.abs(point.y - target.y);\n\t\t\tif (cost >= (costs.get(next) ?? Number.POSITIVE_INFINITY)) continue;\n\t\t\tparents.set(next, current);\n\t\t\tcosts.set(next, cost);\n\t\t\topen.add(next);\n\t\t}\n\t}\n\t// Every node has separated lanes and columns, so outer corridors remain open.\n\tthrow new Error(\"Workflow route has no clear corridor\");\n}\nfunction routeLabel(points: Point[]): Point {\n\tlet longest = -1,\n\t\tposition = points[0] ?? { x: 0, y: 0 };\n\tfor (let index = 1; index < points.length; index++) {\n\t\tconst a = points[index - 1],\n\t\t\tb = points[index],\n\t\t\tlength = Math.abs(a.x - b.x) + Math.abs(a.y - b.y);\n\t\tif (length <= longest) continue;\n\t\tlongest = length;\n\t\tposition = {\n\t\t\tx: (a.x + b.x) / 2 + (a.x === b.x ? 44 : 0),\n\t\t\ty: (a.y + b.y) / 2 - (a.y === b.y ? 16 : 0),\n\t\t};\n\t}\n\treturn position;\n}\n/** SVG polyline with no smoothing that can displace aligned ports. @internal */\nexport function edgePath(points: readonly Point[]): string {\n\treturn points.map((point, index) => `${index === 0 ? \"M\" : \"L\"}${point.x} ${point.y}`).join(\"\");\n}\n"],"mappings":";AAMA,SAAS,kCAAkC;AA2D3C,IAAM,SAAS,CAAC,OAAe,QAAQ,EAAE;AACzC,IAAM,QAAQ,CAAC,WAAmB,OAAO,MAAM;AAGxC,SAAS,uBAAuB,MAAiC;AACvE,QAAM,MAAM,IAAI,IAAI,KAAK,MAAM,IAAI,CAAC,SAAS,KAAK,MAAM,CAAC;AACzD,QAAM,QAAQ,KAAK,aAAa,KAAK,CAAC,OAAO,IAAI,IAAI,EAAE,CAAC,KAAK,KAAK,MAAM,CAAC,GAAG;AAC5E,MAAI,CAAC,MAAO,QAAO,CAAC;AACpB,SAAO;AAAA,IAA2B;AAAA,IAAO,CAAC,OACzC,KAAK,MACH,OAAO,CAAC,SAAS,KAAK,SAAS,EAAE,EACjC;AAAA,MAAQ,CAAC,SACT,KAAK,oBAAoB,cACtB,CAAC,IAAI,IACL,KAAK,OAAO,QAAQ,IAAI,IAAI,KAAK,EAAE,IAClC,CAAC,KAAK,EAAE,IACR,CAAC;AAAA,IACN;AAAA,EACF;AACD;AAGO,SAAS,cAAc,MAAoC;AACjE,UAAQ,MAAM;AAAA,IACb,KAAK;AACJ,aAAO;AAAA,IACR,KAAK;AACJ,aAAO;AAAA,IACR,KAAK;AACJ,aAAO;AAAA,IACR,KAAK;AACJ,aAAO;AAAA,IACR,KAAK;AACJ,aAAO;AAAA,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,IAAI,MAAM,OAAO;AACzB,YAAM,IAAI,MAAM,IAAI;AACpB,WAAK,IAAI,IAAI;AAAA,IACd;AAAA,EACD;AAEA,QAAM,IAAI,MAAM,sCAAsC;AACvD;AACA,SAAS,WAAW,QAAwB;AAC3C,MAAI,UAAU,IACb,WAAW,OAAO,CAAC,KAAK,EAAE,GAAG,GAAG,GAAG,EAAE;AACtC,WAAS,QAAQ,GAAG,QAAQ,OAAO,QAAQ,SAAS;AACnD,UAAM,IAAI,OAAO,QAAQ,CAAC,GACzB,IAAI,OAAO,KAAK,GAChB,SAAS,KAAK,IAAI,EAAE,IAAI,EAAE,CAAC,IAAI,KAAK,IAAI,EAAE,IAAI,EAAE,CAAC;AAClD,QAAI,UAAU,QAAS;AACvB,cAAU;AACV,eAAW;AAAA,MACV,IAAI,EAAE,IAAI,EAAE,KAAK,KAAK,EAAE,MAAM,EAAE,IAAI,KAAK;AAAA,MACzC,IAAI,EAAE,IAAI,EAAE,KAAK,KAAK,EAAE,MAAM,EAAE,IAAI,KAAK;AAAA,IAC1C;AAAA,EACD;AACA,SAAO;AACR;AAEO,SAAS,SAAS,QAAkC;AAC1D,SAAO,OAAO,IAAI,CAAC,OAAO,UAAU,GAAG,UAAU,IAAI,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,MAAM,CAAC,EAAE,EAAE,KAAK,EAAE;AAC/F;","names":["edge","route","point"]}
|
package/dist/layout.d.ts
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { ProcessFlowEdge, ProcessFlowNode, ProcessFlowView, ProcessTurnType } from "@leitwerk-dev/domain";
|
|
2
|
+
/** @internal */
|
|
3
|
+
export interface Point {
|
|
4
|
+
/** @internal */ x: number;
|
|
5
|
+
/** @internal */ y: number;
|
|
6
|
+
}
|
|
7
|
+
/** @internal */
|
|
8
|
+
export interface RepeatGeometry {
|
|
9
|
+
/** @internal */ activity: {
|
|
10
|
+
/** @internal */ x: number;
|
|
11
|
+
/** @internal */ y: number;
|
|
12
|
+
/** @internal */ width: number;
|
|
13
|
+
/** @internal */ height: number;
|
|
14
|
+
};
|
|
15
|
+
/** @internal */ collector: Point;
|
|
16
|
+
/** @internal */ axis: number;
|
|
17
|
+
/** @internal */ loopY: number;
|
|
18
|
+
}
|
|
19
|
+
/** @internal */
|
|
20
|
+
export interface WorkflowNode {
|
|
21
|
+
/** @internal */ id: string;
|
|
22
|
+
/** @internal */ turnId: string | null;
|
|
23
|
+
/** @internal */ title: string;
|
|
24
|
+
/** @internal */ kind: ProcessTurnType | "completed" | "aborted";
|
|
25
|
+
/** @internal */ definition: ProcessFlowNode | null;
|
|
26
|
+
/** @internal */ synthetic: boolean;
|
|
27
|
+
/** @internal */ column: number;
|
|
28
|
+
/** @internal */ lane: number;
|
|
29
|
+
/** @internal */ x: number;
|
|
30
|
+
/** @internal */ y: number;
|
|
31
|
+
/** @internal */ width: number;
|
|
32
|
+
/** @internal */ height: number;
|
|
33
|
+
/** @internal */ repeat: RepeatGeometry | null;
|
|
34
|
+
}
|
|
35
|
+
/** @internal */
|
|
36
|
+
type Side = "left" | "right" | "top" | "bottom";
|
|
37
|
+
/** @internal */
|
|
38
|
+
export interface WorkflowEdge {
|
|
39
|
+
/** @internal */ id: string;
|
|
40
|
+
/** @internal */ from: string;
|
|
41
|
+
/** @internal */ to: string;
|
|
42
|
+
/** @internal */ label: string | null;
|
|
43
|
+
/** @internal */ condition?: ProcessFlowEdge["condition"];
|
|
44
|
+
/** @internal */ kind: ProcessFlowEdge["kind"];
|
|
45
|
+
/** @internal */ points: Point[];
|
|
46
|
+
/** @internal */ labelPosition: Point;
|
|
47
|
+
/** @internal */ sourceSide: Side;
|
|
48
|
+
/** @internal */ targetSide: Side;
|
|
49
|
+
}
|
|
50
|
+
/** @internal */
|
|
51
|
+
export interface WorkflowLayout {
|
|
52
|
+
/** @internal */ width: number;
|
|
53
|
+
/** @internal */ height: number;
|
|
54
|
+
/** @internal */ nodes: WorkflowNode[];
|
|
55
|
+
/** @internal */ edges: WorkflowEdge[];
|
|
56
|
+
/** Layout node identities, including the completed terminal. @internal */ mainPath: string[];
|
|
57
|
+
}
|
|
58
|
+
/** Stable breadth-first search; abort and declared happy-path hints cannot shorten success. @internal */
|
|
59
|
+
export declare function shortestSuccessfulPath(flow: ProcessFlowView): string[];
|
|
60
|
+
/** Labels match the Chronicle's turn-kind vocabulary. @internal */
|
|
61
|
+
export declare function turnKindLabel(kind: WorkflowNode["kind"]): string;
|
|
62
|
+
/** Places the shortest successful path on one line and routes every declared transition. @internal */
|
|
63
|
+
export declare function layoutWorkflow(flow: ProcessFlowView): WorkflowLayout;
|
|
64
|
+
/** SVG polyline with no smoothing that can displace aligned ports. @internal */
|
|
65
|
+
export declare function edgePath(points: readonly Point[]): string;
|
|
66
|
+
export {};
|
|
67
|
+
//# sourceMappingURL=layout.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"layout.d.ts","sourceRoot":"","sources":["../src/layout.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,eAAe,EACf,eAAe,EACf,eAAe,EACf,eAAe,EACf,MAAM,sBAAsB,CAAC;AAG9B,gBAAgB;AAChB,MAAM,WAAW,KAAK;IACrB,gBAAgB,CAAC,CAAC,EAAE,MAAM,CAAC;IAC3B,gBAAgB,CAAC,CAAC,EAAE,MAAM,CAAC;CAC3B;AACD,gBAAgB;AAChB,MAAM,WAAW,cAAc;IAC9B,gBAAgB,CAAC,QAAQ,EAAE;QAC1B,gBAAgB,CAAC,CAAC,EAAE,MAAM,CAAC;QAC3B,gBAAgB,CAAC,CAAC,EAAE,MAAM,CAAC;QAC3B,gBAAgB,CAAC,KAAK,EAAE,MAAM,CAAC;QAC/B,gBAAgB,CAAC,MAAM,EAAE,MAAM,CAAC;KAChC,CAAC;IACF,gBAAgB,CAAC,SAAS,EAAE,KAAK,CAAC;IAClC,gBAAgB,CAAC,IAAI,EAAE,MAAM,CAAC;IAC9B,gBAAgB,CAAC,KAAK,EAAE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AAC,aAAa,EAAE,KAAK,CAAC;IACtC,gBAAgB,CAAC,UAAU,EAAE,IAAI,CAAC;IAClC,gBAAgB,CAAC,UAAU,EAAE,IAAI,CAAC;CAClC;AACD,gBAAgB;AAChB,MAAM,WAAW,cAAc;IAC9B,gBAAgB,CAAC,KAAK,EAAE,MAAM,CAAC;IAC/B,gBAAgB,CAAC,MAAM,EAAE,MAAM,CAAC;IAChC,gBAAgB,CAAC,KAAK,EAAE,YAAY,EAAE,CAAC;IACvC,gBAAgB,CAAC,KAAK,EAAE,YAAY,EAAE,CAAC;IACvC,0EAA0E,CAAC,QAAQ,EAAE,MAAM,EAAE,CAAC;CAC9F;AAKD,yGAAyG;AACzG,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,eAAe,GAAG,MAAM,EAAE,CAetE;AAED,mEAAmE;AACnE,wBAAgB,aAAa,CAAC,IAAI,EAAE,YAAY,CAAC,MAAM,CAAC,GAAG,MAAM,CAehE;AAmCD,sGAAsG;AACtG,wBAAgB,cAAc,CAAC,IAAI,EAAE,eAAe,GAAG,cAAc,CA8MpE;AAuLD,gFAAgF;AAChF,wBAAgB,QAAQ,CAAC,MAAM,EAAE,SAAS,KAAK,EAAE,GAAG,MAAM,CAEzD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,53 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
"name": "@leitwerk-dev/workflow-graph",
|
|
3
|
+
"version": "0.4.0",
|
|
4
|
+
"repository": {
|
|
5
|
+
"type": "git",
|
|
6
|
+
"url": "git+https://github.com/leitwerk-dev/leitwerk.git",
|
|
7
|
+
"directory": "packages/workflow-graph"
|
|
8
|
+
},
|
|
9
|
+
"type": "module",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"source": "./src/index.ts",
|
|
13
|
+
"import": "./dist/index.js",
|
|
14
|
+
"types": "./dist/index.d.ts"
|
|
15
|
+
},
|
|
16
|
+
"./WorkflowGraph.svelte": {
|
|
17
|
+
"source": "./src/WorkflowGraph.svelte",
|
|
18
|
+
"svelte": "./dist/WorkflowGraph.svelte",
|
|
19
|
+
"default": "./dist/WorkflowGraph.svelte"
|
|
20
|
+
},
|
|
21
|
+
"./internal/WorkflowIcon.svelte": {
|
|
22
|
+
"source": "./src/WorkflowIcon.svelte",
|
|
23
|
+
"svelte": "./dist/WorkflowIcon.svelte",
|
|
24
|
+
"default": "./dist/WorkflowIcon.svelte"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build": "tsup --silent"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"@leitwerk-dev/domain": "0.4.0"
|
|
32
|
+
},
|
|
33
|
+
"peerDependencies": {
|
|
34
|
+
"svelte": "^5.55.0"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"svelte": "^5.55.0",
|
|
38
|
+
"tsup": "^8.5.1"
|
|
39
|
+
},
|
|
40
|
+
"license": "Apache-2.0",
|
|
41
|
+
"publishConfig": {
|
|
42
|
+
"access": "public"
|
|
43
|
+
},
|
|
44
|
+
"engines": {
|
|
45
|
+
"node": ">=26 <27"
|
|
46
|
+
},
|
|
47
|
+
"files": [
|
|
48
|
+
"dist/**",
|
|
49
|
+
"src/**",
|
|
50
|
+
"!dist/**/*.test.*",
|
|
51
|
+
"!src/**/*.test.ts"
|
|
52
|
+
]
|
|
53
|
+
}
|