@bpmnkit/core 0.0.8

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 (104) hide show
  1. package/README.md +185 -0
  2. package/dist/bpmn/auto-layout.d.ts +10 -0
  3. package/dist/bpmn/auto-layout.js +203 -0
  4. package/dist/bpmn/bpmn-builder.d.ts +381 -0
  5. package/dist/bpmn/bpmn-builder.js +1223 -0
  6. package/dist/bpmn/bpmn-model.d.ts +403 -0
  7. package/dist/bpmn/bpmn-model.js +2 -0
  8. package/dist/bpmn/bpmn-parser.d.ts +4 -0
  9. package/dist/bpmn/bpmn-parser.js +642 -0
  10. package/dist/bpmn/bpmn-serializer.d.ts +4 -0
  11. package/dist/bpmn/bpmn-serializer.js +515 -0
  12. package/dist/bpmn/compact.d.ts +91 -0
  13. package/dist/bpmn/compact.js +349 -0
  14. package/dist/bpmn/di-color.d.ts +9 -0
  15. package/dist/bpmn/di-color.js +32 -0
  16. package/dist/bpmn/index.d.ts +105 -0
  17. package/dist/bpmn/index.js +176 -0
  18. package/dist/bpmn/optimize/feel.d.ts +4 -0
  19. package/dist/bpmn/optimize/feel.js +186 -0
  20. package/dist/bpmn/optimize/flow.d.ts +4 -0
  21. package/dist/bpmn/optimize/flow.js +323 -0
  22. package/dist/bpmn/optimize/index.d.ts +5 -0
  23. package/dist/bpmn/optimize/index.js +51 -0
  24. package/dist/bpmn/optimize/naming.d.ts +8 -0
  25. package/dist/bpmn/optimize/naming.js +145 -0
  26. package/dist/bpmn/optimize/tasks.d.ts +4 -0
  27. package/dist/bpmn/optimize/tasks.js +273 -0
  28. package/dist/bpmn/optimize/types.d.ts +44 -0
  29. package/dist/bpmn/optimize/types.js +2 -0
  30. package/dist/bpmn/optimize/utils.d.ts +23 -0
  31. package/dist/bpmn/optimize/utils.js +129 -0
  32. package/dist/bpmn/rest-connector.d.ts +48 -0
  33. package/dist/bpmn/rest-connector.js +69 -0
  34. package/dist/bpmn/svg.d.ts +35 -0
  35. package/dist/bpmn/svg.js +557 -0
  36. package/dist/bpmn/type-guards.d.ts +136 -0
  37. package/dist/bpmn/type-guards.js +211 -0
  38. package/dist/bpmn/utils.d.ts +88 -0
  39. package/dist/bpmn/utils.js +207 -0
  40. package/dist/bpmn/zeebe-extensions.d.ts +72 -0
  41. package/dist/bpmn/zeebe-extensions.js +96 -0
  42. package/dist/dmn/compact.d.ts +44 -0
  43. package/dist/dmn/compact.js +125 -0
  44. package/dist/dmn/dmn-builder.d.ts +59 -0
  45. package/dist/dmn/dmn-builder.js +144 -0
  46. package/dist/dmn/dmn-layout.d.ts +57 -0
  47. package/dist/dmn/dmn-layout.js +256 -0
  48. package/dist/dmn/dmn-model.d.ts +158 -0
  49. package/dist/dmn/dmn-model.js +2 -0
  50. package/dist/dmn/dmn-parser.d.ts +4 -0
  51. package/dist/dmn/dmn-parser.js +275 -0
  52. package/dist/dmn/dmn-serializer.d.ts +4 -0
  53. package/dist/dmn/dmn-serializer.js +296 -0
  54. package/dist/dmn/index.d.ts +28 -0
  55. package/dist/dmn/index.js +51 -0
  56. package/dist/errors.d.ts +77 -0
  57. package/dist/errors.js +66 -0
  58. package/dist/form/compact.d.ts +20 -0
  59. package/dist/form/compact.js +146 -0
  60. package/dist/form/form-builder.d.ts +111 -0
  61. package/dist/form/form-builder.js +347 -0
  62. package/dist/form/form-model.d.ts +221 -0
  63. package/dist/form/form-model.js +2 -0
  64. package/dist/form/form-parser.d.ts +4 -0
  65. package/dist/form/form-parser.js +514 -0
  66. package/dist/form/form-serializer.d.ts +4 -0
  67. package/dist/form/form-serializer.js +240 -0
  68. package/dist/form/index.d.ts +27 -0
  69. package/dist/form/index.js +43 -0
  70. package/dist/index.d.ts +37 -0
  71. package/dist/index.js +19 -0
  72. package/dist/layout/bench.d.ts +86 -0
  73. package/dist/layout/bench.js +225 -0
  74. package/dist/layout/coordinates.d.ts +62 -0
  75. package/dist/layout/coordinates.js +868 -0
  76. package/dist/layout/crossing.d.ts +8 -0
  77. package/dist/layout/crossing.js +60 -0
  78. package/dist/layout/graph.d.ts +28 -0
  79. package/dist/layout/graph.js +126 -0
  80. package/dist/layout/index.d.ts +7 -0
  81. package/dist/layout/index.js +5 -0
  82. package/dist/layout/layers.d.ts +13 -0
  83. package/dist/layout/layers.js +49 -0
  84. package/dist/layout/layout-engine.d.ts +21 -0
  85. package/dist/layout/layout-engine.js +191 -0
  86. package/dist/layout/overlap.d.ts +10 -0
  87. package/dist/layout/overlap.js +70 -0
  88. package/dist/layout/routing.d.ts +26 -0
  89. package/dist/layout/routing.js +439 -0
  90. package/dist/layout/subprocess.d.ts +14 -0
  91. package/dist/layout/subprocess.js +77 -0
  92. package/dist/layout/types.d.ts +72 -0
  93. package/dist/layout/types.js +37 -0
  94. package/dist/types/id-generator.d.ts +8 -0
  95. package/dist/types/id-generator.js +31 -0
  96. package/dist/types/index.d.ts +3 -0
  97. package/dist/types/index.js +2 -0
  98. package/dist/types/xml-element.d.ts +12 -0
  99. package/dist/types/xml-element.js +2 -0
  100. package/dist/xml/index.d.ts +2 -0
  101. package/dist/xml/index.js +2 -0
  102. package/dist/xml/xml-parser.d.ts +13 -0
  103. package/dist/xml/xml-parser.js +271 -0
  104. package/package.json +38 -0
@@ -0,0 +1,349 @@
1
+ import { layoutProcess } from "../layout/index.js";
2
+ // ── Compactify ───────────────────────────────────────────────────────────────
3
+ function findAttr(ext, name, attr) {
4
+ return ext.find((e) => e.name === name)?.attributes[attr];
5
+ }
6
+ function compactifyElement(el) {
7
+ const ext = el.extensionElements;
8
+ const result = { id: el.id, type: el.type };
9
+ if (el.name)
10
+ result.name = el.name;
11
+ const jobType = findAttr(ext, "zeebe:taskDefinition", "type");
12
+ if (jobType)
13
+ result.jobType = jobType;
14
+ // Extract task headers (key→value map from zeebe:taskHeaders children)
15
+ const taskHeadersEl = ext.find((e) => e.name === "zeebe:taskHeaders");
16
+ if (taskHeadersEl && taskHeadersEl.children.length > 0) {
17
+ const headers = {};
18
+ for (const child of taskHeadersEl.children) {
19
+ const key = child.attributes.key;
20
+ const value = child.attributes.value;
21
+ if (key !== undefined && value !== undefined)
22
+ headers[key] = value;
23
+ }
24
+ if (Object.keys(headers).length > 0)
25
+ result.taskHeaders = headers;
26
+ }
27
+ const calledProcess = findAttr(ext, "zeebe:calledElement", "processId");
28
+ if (calledProcess)
29
+ result.calledProcess = calledProcess;
30
+ const formId = findAttr(ext, "zeebe:formDefinition", "formId");
31
+ if (formId)
32
+ result.formId = formId;
33
+ const decisionId = findAttr(ext, "zeebe:calledDecision", "decisionId");
34
+ if (decisionId) {
35
+ result.decisionId = decisionId;
36
+ const rv = findAttr(ext, "zeebe:calledDecision", "resultVariable");
37
+ if (rv)
38
+ result.resultVariable = rv;
39
+ }
40
+ else {
41
+ // For service tasks: extract the primary output variable from ioMapping
42
+ const ioMappingEl = ext.find((e) => e.name === "zeebe:ioMapping");
43
+ if (ioMappingEl) {
44
+ const outputs = ioMappingEl.children.filter((c) => c.name === "zeebe:output");
45
+ if (outputs.length === 1) {
46
+ const target = outputs[0]?.attributes.target;
47
+ if (target)
48
+ result.resultVariable = target;
49
+ }
50
+ }
51
+ }
52
+ if ("eventDefinitions" in el && el.eventDefinitions.length > 0) {
53
+ result.eventType = el.eventDefinitions[0]?.type;
54
+ }
55
+ if (el.type === "boundaryEvent") {
56
+ result.attachedTo = el.attachedToRef;
57
+ if (el.cancelActivity === false)
58
+ result.interrupting = false;
59
+ }
60
+ return result;
61
+ }
62
+ /**
63
+ * Converts a {@link BpmnDefinitions} model into a token-efficient
64
+ * {@link CompactDiagram} representation suitable for AI contexts (LLM prompts,
65
+ * MCP tool calls, etc.). The compact format is typically 5–15× smaller than
66
+ * raw BPMN XML.
67
+ *
68
+ * Use {@link expand} to restore a compact diagram back to a full model with
69
+ * auto-generated layout.
70
+ *
71
+ * @example
72
+ * ```typescript
73
+ * import { Bpmn, compactify, expand } from "@bpmnkit/core"
74
+ *
75
+ * const defs = Bpmn.parse(xml)
76
+ * const compact = compactify(defs) // send to AI
77
+ * const restored = expand(compact) // get back BpmnDefinitions
78
+ * const xml2 = Bpmn.export(restored)
79
+ * ```
80
+ */
81
+ export function compactify(defs) {
82
+ return {
83
+ id: defs.id,
84
+ processes: defs.processes.map((process) => ({
85
+ id: process.id,
86
+ name: process.name,
87
+ elements: process.flowElements.map(compactifyElement),
88
+ flows: process.sequenceFlows.map((sf) => {
89
+ const f = { id: sf.id, from: sf.sourceRef, to: sf.targetRef };
90
+ if (sf.name)
91
+ f.name = sf.name;
92
+ if (sf.conditionExpression)
93
+ f.condition = sf.conditionExpression.text;
94
+ return f;
95
+ }),
96
+ })),
97
+ };
98
+ }
99
+ // ── Expand ───────────────────────────────────────────────────────────────────
100
+ function makeEventDef(eventType) {
101
+ switch (eventType) {
102
+ case "timer":
103
+ return { type: "timer" };
104
+ case "error":
105
+ return { type: "error" };
106
+ case "message":
107
+ return { type: "message" };
108
+ case "signal":
109
+ return { type: "signal" };
110
+ case "escalation":
111
+ return { type: "escalation" };
112
+ case "cancel":
113
+ return { type: "cancel" };
114
+ case "terminate":
115
+ return { type: "terminate" };
116
+ case "conditional":
117
+ return { type: "conditional" };
118
+ case "link":
119
+ return { type: "link" };
120
+ case "compensate":
121
+ return { type: "compensate" };
122
+ default:
123
+ return undefined;
124
+ }
125
+ }
126
+ function makeExtensions(el) {
127
+ const ext = [];
128
+ if (el.jobType) {
129
+ ext.push({ name: "zeebe:taskDefinition", attributes: { type: el.jobType }, children: [] });
130
+ }
131
+ if (el.taskHeaders && Object.keys(el.taskHeaders).length > 0) {
132
+ ext.push({
133
+ name: "zeebe:taskHeaders",
134
+ attributes: {},
135
+ children: Object.entries(el.taskHeaders).map(([key, value]) => ({
136
+ name: "zeebe:header",
137
+ attributes: { key, value },
138
+ children: [],
139
+ })),
140
+ });
141
+ }
142
+ if (el.calledProcess) {
143
+ ext.push({
144
+ name: "zeebe:calledElement",
145
+ attributes: { processId: el.calledProcess },
146
+ children: [],
147
+ });
148
+ }
149
+ if (el.formId) {
150
+ ext.push({ name: "zeebe:formDefinition", attributes: { formId: el.formId }, children: [] });
151
+ }
152
+ if (el.decisionId) {
153
+ ext.push({
154
+ name: "zeebe:calledDecision",
155
+ attributes: {
156
+ decisionId: el.decisionId,
157
+ resultVariable: el.resultVariable ?? "result",
158
+ },
159
+ children: [],
160
+ });
161
+ }
162
+ else if (el.resultVariable && el.jobType) {
163
+ // Service task with a result variable: map the connector response to the variable
164
+ ext.push({
165
+ name: "zeebe:ioMapping",
166
+ attributes: {},
167
+ children: [
168
+ {
169
+ name: "zeebe:output",
170
+ attributes: { source: "= response", target: el.resultVariable },
171
+ children: [],
172
+ },
173
+ ],
174
+ });
175
+ }
176
+ return ext;
177
+ }
178
+ function buildFlowElement(el, incoming, outgoing) {
179
+ const base = {
180
+ id: el.id,
181
+ name: el.name,
182
+ incoming,
183
+ outgoing,
184
+ extensionElements: makeExtensions(el),
185
+ unknownAttributes: {},
186
+ };
187
+ const eventDef = el.eventType ? makeEventDef(el.eventType) : undefined;
188
+ const eventDefs = eventDef ? [eventDef] : [];
189
+ const subContent = {
190
+ flowElements: [],
191
+ sequenceFlows: [],
192
+ textAnnotations: [],
193
+ associations: [],
194
+ };
195
+ switch (el.type) {
196
+ case "startEvent":
197
+ return { ...base, type: "startEvent", eventDefinitions: eventDefs };
198
+ case "endEvent":
199
+ return { ...base, type: "endEvent", eventDefinitions: eventDefs };
200
+ case "intermediateCatchEvent":
201
+ return { ...base, type: "intermediateCatchEvent", eventDefinitions: eventDefs };
202
+ case "intermediateThrowEvent":
203
+ return { ...base, type: "intermediateThrowEvent", eventDefinitions: eventDefs };
204
+ case "boundaryEvent":
205
+ return {
206
+ ...base,
207
+ type: "boundaryEvent",
208
+ attachedToRef: el.attachedTo ?? "",
209
+ cancelActivity: el.interrupting !== false,
210
+ eventDefinitions: eventDefs,
211
+ };
212
+ case "serviceTask":
213
+ return { ...base, type: "serviceTask" };
214
+ case "scriptTask":
215
+ return { ...base, type: "scriptTask" };
216
+ case "userTask":
217
+ return { ...base, type: "userTask" };
218
+ case "businessRuleTask":
219
+ return { ...base, type: "businessRuleTask" };
220
+ case "callActivity":
221
+ return { ...base, type: "callActivity" };
222
+ case "sendTask":
223
+ return { ...base, type: "sendTask" };
224
+ case "receiveTask":
225
+ return { ...base, type: "receiveTask" };
226
+ case "manualTask":
227
+ return { ...base, type: "manualTask" };
228
+ case "task":
229
+ return { ...base, type: "task" };
230
+ case "subProcess":
231
+ return { ...base, type: "subProcess", ...subContent };
232
+ case "adHocSubProcess":
233
+ return { ...base, type: "adHocSubProcess", ...subContent };
234
+ case "eventSubProcess":
235
+ return { ...base, type: "eventSubProcess", ...subContent };
236
+ case "transaction":
237
+ return { ...base, type: "transaction", ...subContent };
238
+ case "exclusiveGateway":
239
+ return { ...base, type: "exclusiveGateway" };
240
+ case "parallelGateway":
241
+ return { ...base, type: "parallelGateway" };
242
+ case "inclusiveGateway":
243
+ return { ...base, type: "inclusiveGateway" };
244
+ case "eventBasedGateway":
245
+ return { ...base, type: "eventBasedGateway" };
246
+ case "complexGateway":
247
+ return { ...base, type: "complexGateway" };
248
+ }
249
+ }
250
+ function buildDiagram(processId, process) {
251
+ const layout = layoutProcess(process);
252
+ const shapes = layout.nodes.map((n) => ({
253
+ id: `${n.id}_di`,
254
+ bpmnElement: n.id,
255
+ isExpanded: n.isExpanded,
256
+ bounds: n.bounds,
257
+ label: n.labelBounds ? { bounds: n.labelBounds } : undefined,
258
+ unknownAttributes: {},
259
+ }));
260
+ const edges = layout.edges.map((e) => ({
261
+ id: `${e.id}_di`,
262
+ bpmnElement: e.id,
263
+ waypoints: e.waypoints,
264
+ unknownAttributes: {},
265
+ }));
266
+ return {
267
+ id: `BPMNDiagram_${processId}`,
268
+ plane: {
269
+ id: `BPMNPlane_${processId}`,
270
+ bpmnElement: processId,
271
+ shapes,
272
+ edges,
273
+ },
274
+ };
275
+ }
276
+ function expandProcess(compact) {
277
+ const incoming = new Map();
278
+ const outgoing = new Map();
279
+ for (const f of compact.flows) {
280
+ const out = outgoing.get(f.from) ?? [];
281
+ out.push(f.id);
282
+ outgoing.set(f.from, out);
283
+ const inc = incoming.get(f.to) ?? [];
284
+ inc.push(f.id);
285
+ incoming.set(f.to, inc);
286
+ }
287
+ const flowElements = compact.elements.map((el) => buildFlowElement(el, incoming.get(el.id) ?? [], outgoing.get(el.id) ?? []));
288
+ const sequenceFlows = compact.flows.map((f) => ({
289
+ id: f.id,
290
+ name: f.name,
291
+ sourceRef: f.from,
292
+ targetRef: f.to,
293
+ conditionExpression: f.condition ? { text: f.condition, attributes: {} } : undefined,
294
+ extensionElements: [],
295
+ unknownAttributes: {},
296
+ }));
297
+ const process = {
298
+ id: compact.id,
299
+ name: compact.name,
300
+ isExecutable: true,
301
+ extensionElements: [],
302
+ flowElements,
303
+ sequenceFlows,
304
+ textAnnotations: [],
305
+ associations: [],
306
+ unknownAttributes: {},
307
+ };
308
+ return { process, diagram: buildDiagram(compact.id, process) };
309
+ }
310
+ /**
311
+ * Restores a {@link CompactDiagram} (produced by {@link compactify} or an AI
312
+ * model) back to a full {@link BpmnDefinitions} with auto-generated layout.
313
+ *
314
+ * @example
315
+ * ```typescript
316
+ * const compact = await askAI(prompt) // AI returns CompactDiagram JSON
317
+ * const defs = expand(compact)
318
+ * const xml = Bpmn.export(defs)
319
+ * editor.loadXml(xml)
320
+ * ```
321
+ */
322
+ export function expand(compact) {
323
+ const processes = [];
324
+ const diagrams = [];
325
+ for (const cp of compact.processes) {
326
+ const { process, diagram } = expandProcess(cp);
327
+ processes.push(process);
328
+ diagrams.push(diagram);
329
+ }
330
+ return {
331
+ id: compact.id,
332
+ targetNamespace: "http://bpmn.io/schema/bpmn",
333
+ namespaces: {
334
+ bpmn: "http://www.omg.org/spec/BPMN/20100524/MODEL",
335
+ bpmndi: "http://www.omg.org/spec/BPMN/20100524/DI",
336
+ dc: "http://www.omg.org/spec/DD/20100524/DC",
337
+ di: "http://www.omg.org/spec/DD/20100524/DI",
338
+ zeebe: "http://camunda.org/schema/zeebe/1.0",
339
+ },
340
+ unknownAttributes: {},
341
+ errors: [],
342
+ escalations: [],
343
+ messages: [],
344
+ collaborations: [],
345
+ processes,
346
+ diagrams,
347
+ };
348
+ }
349
+ //# sourceMappingURL=compact.js.map
@@ -0,0 +1,9 @@
1
+ export declare const BIOC_NS = "http://bpmn.io/schema/bpmn/biocolor/1.0";
2
+ export declare const COLOR_NS = "http://www.omg.org/spec/BPMN/non-normative/color/1.0";
3
+ export interface DiColor {
4
+ fill?: string;
5
+ stroke?: string;
6
+ }
7
+ export declare function readDiColor(attrs: Record<string, string>): DiColor;
8
+ export declare function writeDiColor(attrs: Record<string, string>, color: DiColor): Record<string, string>;
9
+ //# sourceMappingURL=di-color.d.ts.map
@@ -0,0 +1,32 @@
1
+ export const BIOC_NS = "http://bpmn.io/schema/bpmn/biocolor/1.0";
2
+ export const COLOR_NS = "http://www.omg.org/spec/BPMN/non-normative/color/1.0";
3
+ export function readDiColor(attrs) {
4
+ return {
5
+ fill: attrs["bioc:fill"] ?? attrs["color:background-color"] ?? undefined,
6
+ stroke: attrs["bioc:stroke"] ?? attrs["color:border-color"] ?? undefined,
7
+ };
8
+ }
9
+ export function writeDiColor(attrs, color) {
10
+ // Build a new object, omitting existing color keys, then add new ones if set
11
+ const r = {};
12
+ const colorKeys = new Set([
13
+ "bioc:fill",
14
+ "color:background-color",
15
+ "bioc:stroke",
16
+ "color:border-color",
17
+ ]);
18
+ for (const [k, v] of Object.entries(attrs)) {
19
+ if (!colorKeys.has(k))
20
+ r[k] = v;
21
+ }
22
+ if (color.fill) {
23
+ r["bioc:fill"] = color.fill;
24
+ r["color:background-color"] = color.fill;
25
+ }
26
+ if (color.stroke) {
27
+ r["bioc:stroke"] = color.stroke;
28
+ r["color:border-color"] = color.stroke;
29
+ }
30
+ return r;
31
+ }
32
+ //# sourceMappingURL=di-color.js.map
@@ -0,0 +1,105 @@
1
+ import { ProcessBuilder } from "./bpmn-builder.js";
2
+ import type { BpmnDefinitions } from "./bpmn-model.js";
3
+ /** A minimal 3-element BPMN diagram useful for first-launch or "New Diagram" defaults. */
4
+ export declare const SAMPLE_BPMN_XML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<bpmn:definitions xmlns:bpmn=\"http://www.omg.org/spec/BPMN/20100524/MODEL\"\n xmlns:bpmndi=\"http://www.omg.org/spec/BPMN/20100524/DI\"\n xmlns:dc=\"http://www.omg.org/spec/DD/20100524/DC\"\n xmlns:di=\"http://www.omg.org/spec/DD/20100524/DI\"\n id=\"Definitions_1\" targetNamespace=\"http://bpmn.io/schema/bpmn\">\n <bpmn:process id=\"proc\" isExecutable=\"true\">\n <bpmn:startEvent id=\"start\" name=\"Start\">\n <bpmn:outgoing>flow1</bpmn:outgoing>\n </bpmn:startEvent>\n <bpmn:serviceTask id=\"task1\" name=\"Process Order\">\n <bpmn:incoming>flow1</bpmn:incoming>\n <bpmn:outgoing>flow2</bpmn:outgoing>\n </bpmn:serviceTask>\n <bpmn:endEvent id=\"end\" name=\"End\">\n <bpmn:incoming>flow2</bpmn:incoming>\n </bpmn:endEvent>\n <bpmn:sequenceFlow id=\"flow1\" sourceRef=\"start\" targetRef=\"task1\"/>\n <bpmn:sequenceFlow id=\"flow2\" sourceRef=\"task1\" targetRef=\"end\"/>\n </bpmn:process>\n <bpmndi:BPMNDiagram id=\"diagram1\">\n <bpmndi:BPMNPlane id=\"plane1\" bpmnElement=\"proc\">\n <bpmndi:BPMNShape id=\"start_di\" bpmnElement=\"start\">\n <dc:Bounds x=\"152\" y=\"202\" width=\"36\" height=\"36\"/>\n </bpmndi:BPMNShape>\n <bpmndi:BPMNShape id=\"task1_di\" bpmnElement=\"task1\">\n <dc:Bounds x=\"260\" y=\"180\" width=\"100\" height=\"80\"/>\n </bpmndi:BPMNShape>\n <bpmndi:BPMNShape id=\"end_di\" bpmnElement=\"end\">\n <dc:Bounds x=\"432\" y=\"202\" width=\"36\" height=\"36\"/>\n </bpmndi:BPMNShape>\n <bpmndi:BPMNEdge id=\"flow1_di\" bpmnElement=\"flow1\">\n <di:waypoint x=\"188\" y=\"220\"/>\n <di:waypoint x=\"260\" y=\"220\"/>\n </bpmndi:BPMNEdge>\n <bpmndi:BPMNEdge id=\"flow2_di\" bpmnElement=\"flow2\">\n <di:waypoint x=\"360\" y=\"220\"/>\n <di:waypoint x=\"432\" y=\"220\"/>\n </bpmndi:BPMNEdge>\n </bpmndi:BPMNPlane>\n </bpmndi:BPMNDiagram>\n</bpmn:definitions>";
5
+ /**
6
+ * Entry point for all BPMN operations — parsing, building, exporting, and
7
+ * creating empty diagrams.
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * import { Bpmn } from "@bpmnkit/core"
12
+ *
13
+ * // Parse existing XML
14
+ * const defs = Bpmn.parse(xml)
15
+ *
16
+ * // Build a new process
17
+ * const defs2 = Bpmn.createProcess("order")
18
+ * .startEvent("start")
19
+ * .serviceTask("task", { name: "Process", taskType: "process" })
20
+ * .endEvent("end")
21
+ * .withAutoLayout()
22
+ * .build()
23
+ *
24
+ * const xml2 = Bpmn.export(defs2)
25
+ * ```
26
+ */
27
+ export declare const Bpmn: {
28
+ /**
29
+ * Create a new BPMN process using the fluent builder API.
30
+ *
31
+ * @param processId - Unique identifier for the process (used as the XML `id` attribute).
32
+ *
33
+ * @example
34
+ * ```typescript
35
+ * const defs = Bpmn.createProcess("order-process")
36
+ * .startEvent("start", { name: "Order received" })
37
+ * .serviceTask("validate", { name: "Validate", taskType: "validate-order" })
38
+ * .endEvent("end")
39
+ * .withAutoLayout()
40
+ * .build()
41
+ * ```
42
+ */
43
+ readonly createProcess: (processId: string) => ProcessBuilder;
44
+ /**
45
+ * Parse a BPMN 2.0 XML string into a typed {@link BpmnDefinitions} model.
46
+ *
47
+ * @param xml - BPMN 2.0 XML string (must contain a `<bpmn:definitions>` root).
48
+ * @returns Typed definitions object.
49
+ * @throws {ParseError} If the XML is malformed or a required attribute is missing.
50
+ *
51
+ * @example
52
+ * ```typescript
53
+ * import { Bpmn, ParseError } from "@bpmnkit/core"
54
+ *
55
+ * try {
56
+ * const defs = Bpmn.parse(xmlString)
57
+ * console.log(defs.processes[0].id)
58
+ * } catch (err) {
59
+ * if (err instanceof ParseError) console.error(err.message)
60
+ * }
61
+ * ```
62
+ */
63
+ readonly parse: (xml: string) => BpmnDefinitions;
64
+ /**
65
+ * Serialise a {@link BpmnDefinitions} model back to BPMN 2.0 XML.
66
+ *
67
+ * @param definitions - The typed BPMN model to export.
68
+ * @returns A BPMN 2.0 XML string.
69
+ *
70
+ * @example
71
+ * ```typescript
72
+ * const xml = Bpmn.export(defs)
73
+ * fs.writeFileSync("diagram.bpmn", xml, "utf-8")
74
+ * ```
75
+ */
76
+ readonly export: (definitions: BpmnDefinitions) => string;
77
+ /**
78
+ * Returns a minimal valid BPMN XML string containing one process with a
79
+ * single start event. Useful for "New Diagram" / empty-canvas actions.
80
+ *
81
+ * @param processId - Process id (defaults to a random string).
82
+ * @param processName - Human-readable process name (defaults to `"New Process"`).
83
+ *
84
+ * @example
85
+ * ```typescript
86
+ * const xml = Bpmn.makeEmpty("order-process", "Order Process")
87
+ * editor.loadXml(xml)
88
+ * ```
89
+ */
90
+ readonly makeEmpty: (processId?: string, processName?: string) => string;
91
+ /** A minimal 3-element sample diagram. Re-exported for convenience. */
92
+ readonly SAMPLE_XML: "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<bpmn:definitions xmlns:bpmn=\"http://www.omg.org/spec/BPMN/20100524/MODEL\"\n xmlns:bpmndi=\"http://www.omg.org/spec/BPMN/20100524/DI\"\n xmlns:dc=\"http://www.omg.org/spec/DD/20100524/DC\"\n xmlns:di=\"http://www.omg.org/spec/DD/20100524/DI\"\n id=\"Definitions_1\" targetNamespace=\"http://bpmn.io/schema/bpmn\">\n <bpmn:process id=\"proc\" isExecutable=\"true\">\n <bpmn:startEvent id=\"start\" name=\"Start\">\n <bpmn:outgoing>flow1</bpmn:outgoing>\n </bpmn:startEvent>\n <bpmn:serviceTask id=\"task1\" name=\"Process Order\">\n <bpmn:incoming>flow1</bpmn:incoming>\n <bpmn:outgoing>flow2</bpmn:outgoing>\n </bpmn:serviceTask>\n <bpmn:endEvent id=\"end\" name=\"End\">\n <bpmn:incoming>flow2</bpmn:incoming>\n </bpmn:endEvent>\n <bpmn:sequenceFlow id=\"flow1\" sourceRef=\"start\" targetRef=\"task1\"/>\n <bpmn:sequenceFlow id=\"flow2\" sourceRef=\"task1\" targetRef=\"end\"/>\n </bpmn:process>\n <bpmndi:BPMNDiagram id=\"diagram1\">\n <bpmndi:BPMNPlane id=\"plane1\" bpmnElement=\"proc\">\n <bpmndi:BPMNShape id=\"start_di\" bpmnElement=\"start\">\n <dc:Bounds x=\"152\" y=\"202\" width=\"36\" height=\"36\"/>\n </bpmndi:BPMNShape>\n <bpmndi:BPMNShape id=\"task1_di\" bpmnElement=\"task1\">\n <dc:Bounds x=\"260\" y=\"180\" width=\"100\" height=\"80\"/>\n </bpmndi:BPMNShape>\n <bpmndi:BPMNShape id=\"end_di\" bpmnElement=\"end\">\n <dc:Bounds x=\"432\" y=\"202\" width=\"36\" height=\"36\"/>\n </bpmndi:BPMNShape>\n <bpmndi:BPMNEdge id=\"flow1_di\" bpmnElement=\"flow1\">\n <di:waypoint x=\"188\" y=\"220\"/>\n <di:waypoint x=\"260\" y=\"220\"/>\n </bpmndi:BPMNEdge>\n <bpmndi:BPMNEdge id=\"flow2_di\" bpmnElement=\"flow2\">\n <di:waypoint x=\"360\" y=\"220\"/>\n <di:waypoint x=\"432\" y=\"220\"/>\n </bpmndi:BPMNEdge>\n </bpmndi:BPMNPlane>\n </bpmndi:BPMNDiagram>\n</bpmn:definitions>";
93
+ /**
94
+ * Apply auto-layout to a BPMN XML string.
95
+ *
96
+ * Parses the XML, runs the Sugiyama layered layout algorithm on every process,
97
+ * replaces all BPMNDi positions with the computed layout, and returns the
98
+ * updated XML. Works for plain processes and collaborations with pools/lanes.
99
+ *
100
+ * @param xml - BPMN 2.0 XML string
101
+ * @returns BPMN 2.0 XML string with updated diagram interchange
102
+ */
103
+ readonly autoLayout: (xml: string) => string;
104
+ };
105
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,176 @@
1
+ import { applyAutoLayout } from "./auto-layout.js";
2
+ import { ProcessBuilder } from "./bpmn-builder.js";
3
+ import { parseBpmn } from "./bpmn-parser.js";
4
+ import { serializeBpmn } from "./bpmn-serializer.js";
5
+ /** A minimal 3-element BPMN diagram useful for first-launch or "New Diagram" defaults. */
6
+ export const SAMPLE_BPMN_XML = `<?xml version="1.0" encoding="UTF-8"?>
7
+ <bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL"
8
+ xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI"
9
+ xmlns:dc="http://www.omg.org/spec/DD/20100524/DC"
10
+ xmlns:di="http://www.omg.org/spec/DD/20100524/DI"
11
+ id="Definitions_1" targetNamespace="http://bpmn.io/schema/bpmn">
12
+ <bpmn:process id="proc" isExecutable="true">
13
+ <bpmn:startEvent id="start" name="Start">
14
+ <bpmn:outgoing>flow1</bpmn:outgoing>
15
+ </bpmn:startEvent>
16
+ <bpmn:serviceTask id="task1" name="Process Order">
17
+ <bpmn:incoming>flow1</bpmn:incoming>
18
+ <bpmn:outgoing>flow2</bpmn:outgoing>
19
+ </bpmn:serviceTask>
20
+ <bpmn:endEvent id="end" name="End">
21
+ <bpmn:incoming>flow2</bpmn:incoming>
22
+ </bpmn:endEvent>
23
+ <bpmn:sequenceFlow id="flow1" sourceRef="start" targetRef="task1"/>
24
+ <bpmn:sequenceFlow id="flow2" sourceRef="task1" targetRef="end"/>
25
+ </bpmn:process>
26
+ <bpmndi:BPMNDiagram id="diagram1">
27
+ <bpmndi:BPMNPlane id="plane1" bpmnElement="proc">
28
+ <bpmndi:BPMNShape id="start_di" bpmnElement="start">
29
+ <dc:Bounds x="152" y="202" width="36" height="36"/>
30
+ </bpmndi:BPMNShape>
31
+ <bpmndi:BPMNShape id="task1_di" bpmnElement="task1">
32
+ <dc:Bounds x="260" y="180" width="100" height="80"/>
33
+ </bpmndi:BPMNShape>
34
+ <bpmndi:BPMNShape id="end_di" bpmnElement="end">
35
+ <dc:Bounds x="432" y="202" width="36" height="36"/>
36
+ </bpmndi:BPMNShape>
37
+ <bpmndi:BPMNEdge id="flow1_di" bpmnElement="flow1">
38
+ <di:waypoint x="188" y="220"/>
39
+ <di:waypoint x="260" y="220"/>
40
+ </bpmndi:BPMNEdge>
41
+ <bpmndi:BPMNEdge id="flow2_di" bpmnElement="flow2">
42
+ <di:waypoint x="360" y="220"/>
43
+ <di:waypoint x="432" y="220"/>
44
+ </bpmndi:BPMNEdge>
45
+ </bpmndi:BPMNPlane>
46
+ </bpmndi:BPMNDiagram>
47
+ </bpmn:definitions>`;
48
+ /**
49
+ * Entry point for all BPMN operations — parsing, building, exporting, and
50
+ * creating empty diagrams.
51
+ *
52
+ * @example
53
+ * ```typescript
54
+ * import { Bpmn } from "@bpmnkit/core"
55
+ *
56
+ * // Parse existing XML
57
+ * const defs = Bpmn.parse(xml)
58
+ *
59
+ * // Build a new process
60
+ * const defs2 = Bpmn.createProcess("order")
61
+ * .startEvent("start")
62
+ * .serviceTask("task", { name: "Process", taskType: "process" })
63
+ * .endEvent("end")
64
+ * .withAutoLayout()
65
+ * .build()
66
+ *
67
+ * const xml2 = Bpmn.export(defs2)
68
+ * ```
69
+ */
70
+ export const Bpmn = {
71
+ /**
72
+ * Create a new BPMN process using the fluent builder API.
73
+ *
74
+ * @param processId - Unique identifier for the process (used as the XML `id` attribute).
75
+ *
76
+ * @example
77
+ * ```typescript
78
+ * const defs = Bpmn.createProcess("order-process")
79
+ * .startEvent("start", { name: "Order received" })
80
+ * .serviceTask("validate", { name: "Validate", taskType: "validate-order" })
81
+ * .endEvent("end")
82
+ * .withAutoLayout()
83
+ * .build()
84
+ * ```
85
+ */
86
+ createProcess(processId) {
87
+ return new ProcessBuilder(processId);
88
+ },
89
+ /**
90
+ * Parse a BPMN 2.0 XML string into a typed {@link BpmnDefinitions} model.
91
+ *
92
+ * @param xml - BPMN 2.0 XML string (must contain a `<bpmn:definitions>` root).
93
+ * @returns Typed definitions object.
94
+ * @throws {ParseError} If the XML is malformed or a required attribute is missing.
95
+ *
96
+ * @example
97
+ * ```typescript
98
+ * import { Bpmn, ParseError } from "@bpmnkit/core"
99
+ *
100
+ * try {
101
+ * const defs = Bpmn.parse(xmlString)
102
+ * console.log(defs.processes[0].id)
103
+ * } catch (err) {
104
+ * if (err instanceof ParseError) console.error(err.message)
105
+ * }
106
+ * ```
107
+ */
108
+ parse(xml) {
109
+ return parseBpmn(xml);
110
+ },
111
+ /**
112
+ * Serialise a {@link BpmnDefinitions} model back to BPMN 2.0 XML.
113
+ *
114
+ * @param definitions - The typed BPMN model to export.
115
+ * @returns A BPMN 2.0 XML string.
116
+ *
117
+ * @example
118
+ * ```typescript
119
+ * const xml = Bpmn.export(defs)
120
+ * fs.writeFileSync("diagram.bpmn", xml, "utf-8")
121
+ * ```
122
+ */
123
+ export(definitions) {
124
+ return serializeBpmn(definitions);
125
+ },
126
+ /**
127
+ * Returns a minimal valid BPMN XML string containing one process with a
128
+ * single start event. Useful for "New Diagram" / empty-canvas actions.
129
+ *
130
+ * @param processId - Process id (defaults to a random string).
131
+ * @param processName - Human-readable process name (defaults to `"New Process"`).
132
+ *
133
+ * @example
134
+ * ```typescript
135
+ * const xml = Bpmn.makeEmpty("order-process", "Order Process")
136
+ * editor.loadXml(xml)
137
+ * ```
138
+ */
139
+ makeEmpty(processId = `Process_${Math.random().toString(36).slice(2, 9)}`, processName = "New Process") {
140
+ const startId = `StartEvent_${processId}`;
141
+ return `<?xml version="1.0" encoding="UTF-8"?>
142
+ <bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL"
143
+ xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI"
144
+ xmlns:dc="http://www.omg.org/spec/DD/20100524/DC"
145
+ id="Definitions_${processId}" targetNamespace="http://bpmn.io/schema/bpmn">
146
+ <bpmn:process id="${processId}" name="${processName}" isExecutable="true">
147
+ <bpmn:startEvent id="${startId}"/>
148
+ </bpmn:process>
149
+ <bpmndi:BPMNDiagram id="BPMNDiagram_${processId}">
150
+ <bpmndi:BPMNPlane id="BPMNPlane_${processId}" bpmnElement="${processId}">
151
+ <bpmndi:BPMNShape id="${startId}_di" bpmnElement="${startId}">
152
+ <dc:Bounds x="152" y="82" width="36" height="36"/>
153
+ </bpmndi:BPMNShape>
154
+ </bpmndi:BPMNPlane>
155
+ </bpmndi:BPMNDiagram>
156
+ </bpmn:definitions>`;
157
+ },
158
+ /** A minimal 3-element sample diagram. Re-exported for convenience. */
159
+ SAMPLE_XML: SAMPLE_BPMN_XML,
160
+ /**
161
+ * Apply auto-layout to a BPMN XML string.
162
+ *
163
+ * Parses the XML, runs the Sugiyama layered layout algorithm on every process,
164
+ * replaces all BPMNDi positions with the computed layout, and returns the
165
+ * updated XML. Works for plain processes and collaborations with pools/lanes.
166
+ *
167
+ * @param xml - BPMN 2.0 XML string
168
+ * @returns BPMN 2.0 XML string with updated diagram interchange
169
+ */
170
+ autoLayout(xml) {
171
+ const defs = parseBpmn(xml);
172
+ const laid = applyAutoLayout(defs);
173
+ return serializeBpmn(laid);
174
+ },
175
+ };
176
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,4 @@
1
+ import type { BpmnProcess } from "../bpmn-model.js";
2
+ import type { OptimizationFinding, ResolvedOptions } from "./types.js";
3
+ export declare function analyzeFeel(p: BpmnProcess, opts: ResolvedOptions): OptimizationFinding[];
4
+ //# sourceMappingURL=feel.d.ts.map