@aranzatech/diagrams-bpmn 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/dist/chunk-23B2IGK5.js +24 -0
  2. package/dist/chunk-23B2IGK5.js.map +1 -0
  3. package/dist/chunk-3AFZDIMQ.js +286 -0
  4. package/dist/chunk-3AFZDIMQ.js.map +1 -0
  5. package/dist/chunk-4OAEWYYU.js +579 -0
  6. package/dist/chunk-4OAEWYYU.js.map +1 -0
  7. package/dist/chunk-57LA2WSJ.js +476 -0
  8. package/dist/chunk-57LA2WSJ.js.map +1 -0
  9. package/dist/chunk-6TUC5QX5.js +491 -0
  10. package/dist/chunk-6TUC5QX5.js.map +1 -0
  11. package/dist/chunk-MLUJKUTG.js +86 -0
  12. package/dist/chunk-MLUJKUTG.js.map +1 -0
  13. package/dist/chunk-NXMUX67A.js +1443 -0
  14. package/dist/chunk-NXMUX67A.js.map +1 -0
  15. package/dist/edges/index.cjs +300 -0
  16. package/dist/edges/index.cjs.map +1 -0
  17. package/dist/edges/index.d.cts +17 -0
  18. package/dist/edges/index.d.ts +17 -0
  19. package/dist/edges/index.js +4 -0
  20. package/dist/edges/index.js.map +1 -0
  21. package/dist/elements/index.cjs +587 -0
  22. package/dist/elements/index.cjs.map +1 -0
  23. package/dist/elements/index.d.cts +20 -0
  24. package/dist/elements/index.d.ts +20 -0
  25. package/dist/elements/index.js +4 -0
  26. package/dist/elements/index.js.map +1 -0
  27. package/dist/index.cjs +3442 -0
  28. package/dist/index.cjs.map +1 -0
  29. package/dist/index.d.cts +67 -0
  30. package/dist/index.d.ts +67 -0
  31. package/dist/index.js +45 -0
  32. package/dist/index.js.map +1 -0
  33. package/dist/nodes/index.cjs +1487 -0
  34. package/dist/nodes/index.cjs.map +1 -0
  35. package/dist/nodes/index.d.cts +45 -0
  36. package/dist/nodes/index.d.ts +45 -0
  37. package/dist/nodes/index.js +4 -0
  38. package/dist/nodes/index.js.map +1 -0
  39. package/dist/simulation/index.cjs +483 -0
  40. package/dist/simulation/index.cjs.map +1 -0
  41. package/dist/simulation/index.d.cts +62 -0
  42. package/dist/simulation/index.d.ts +62 -0
  43. package/dist/simulation/index.js +3 -0
  44. package/dist/simulation/index.js.map +1 -0
  45. package/dist/types-CxzazgBX.d.cts +111 -0
  46. package/dist/types-CxzazgBX.d.ts +111 -0
  47. package/dist/xml/index.cjs +1068 -0
  48. package/dist/xml/index.cjs.map +1 -0
  49. package/dist/xml/index.d.cts +24 -0
  50. package/dist/xml/index.d.ts +24 -0
  51. package/dist/xml/index.js +4 -0
  52. package/dist/xml/index.js.map +1 -0
  53. package/package.json +84 -0
@@ -0,0 +1,579 @@
1
+ import { BPMN_ELEMENT_CATALOG } from './chunk-6TUC5QX5.js';
2
+ import { BpmnModdle } from 'bpmn-moddle';
3
+
4
+ // src/xml/mapper.ts
5
+ var MODDLE_TO_ELEMENT_TYPE = {
6
+ "bpmn:StartEvent": "StartEvent",
7
+ "bpmn:EndEvent": "EndEvent",
8
+ "bpmn:IntermediateCatchEvent": "IntermediateCatchEvent",
9
+ "bpmn:IntermediateThrowEvent": "IntermediateThrowEvent",
10
+ "bpmn:BoundaryEvent": "BoundaryEvent",
11
+ "bpmn:Task": "Task",
12
+ "bpmn:UserTask": "UserTask",
13
+ "bpmn:ServiceTask": "ServiceTask",
14
+ "bpmn:ScriptTask": "ScriptTask",
15
+ "bpmn:ManualTask": "ManualTask",
16
+ "bpmn:BusinessRuleTask": "BusinessRuleTask",
17
+ "bpmn:ReceiveTask": "ReceiveTask",
18
+ "bpmn:SendTask": "SendTask",
19
+ "bpmn:CallActivity": "CallActivity",
20
+ "bpmn:ExclusiveGateway": "ExclusiveGateway",
21
+ "bpmn:InclusiveGateway": "InclusiveGateway",
22
+ "bpmn:ParallelGateway": "ParallelGateway",
23
+ "bpmn:EventBasedGateway": "EventBasedGateway",
24
+ "bpmn:ComplexGateway": "ComplexGateway",
25
+ "bpmn:SubProcess": "SubProcess",
26
+ "bpmn:AdHocSubProcess": "SubProcess",
27
+ "bpmn:Transaction": "SubProcess",
28
+ "bpmn:TextAnnotation": "Annotation",
29
+ "bpmn:Group": "Group",
30
+ "bpmn:DataObject": "DataObject",
31
+ "bpmn:DataObjectReference": "DataObjectReference",
32
+ "bpmn:DataInput": "DataInput",
33
+ "bpmn:DataOutput": "DataOutput",
34
+ "bpmn:DataStore": "DataStore",
35
+ "bpmn:DataStoreReference": "DataStoreReference",
36
+ "bpmn:Conversation": "Conversation",
37
+ "bpmn:SubConversation": "SubConversation",
38
+ "bpmn:CallConversation": "CallConversation",
39
+ "bpmn:ChoreographyTask": "ChoreographyTask",
40
+ "bpmn:SubChoreography": "SubChoreography",
41
+ "bpmn:CallChoreography": "CallChoreography",
42
+ "bpmn:Lane": "Lane"
43
+ };
44
+ var ELEMENT_TYPE_TO_MODDLE = {
45
+ StartEvent: "bpmn:StartEvent",
46
+ EndEvent: "bpmn:EndEvent",
47
+ IntermediateCatchEvent: "bpmn:IntermediateCatchEvent",
48
+ IntermediateThrowEvent: "bpmn:IntermediateThrowEvent",
49
+ BoundaryEvent: "bpmn:BoundaryEvent",
50
+ Task: "bpmn:Task",
51
+ UserTask: "bpmn:UserTask",
52
+ ServiceTask: "bpmn:ServiceTask",
53
+ ScriptTask: "bpmn:ScriptTask",
54
+ ManualTask: "bpmn:ManualTask",
55
+ BusinessRuleTask: "bpmn:BusinessRuleTask",
56
+ ReceiveTask: "bpmn:ReceiveTask",
57
+ SendTask: "bpmn:SendTask",
58
+ CallActivity: "bpmn:CallActivity",
59
+ ExclusiveGateway: "bpmn:ExclusiveGateway",
60
+ InclusiveGateway: "bpmn:InclusiveGateway",
61
+ ParallelGateway: "bpmn:ParallelGateway",
62
+ EventBasedGateway: "bpmn:EventBasedGateway",
63
+ ComplexGateway: "bpmn:ComplexGateway",
64
+ SubProcess: "bpmn:SubProcess",
65
+ Pool: "bpmn:Participant",
66
+ Lane: "bpmn:Lane",
67
+ Annotation: "bpmn:TextAnnotation",
68
+ Group: "bpmn:Group",
69
+ DataObject: "bpmn:DataObject",
70
+ DataObjectReference: "bpmn:DataObjectReference",
71
+ DataInput: "bpmn:DataInput",
72
+ DataOutput: "bpmn:DataOutput",
73
+ DataStore: "bpmn:DataStore",
74
+ DataStoreReference: "bpmn:DataStoreReference",
75
+ Conversation: "bpmn:Conversation",
76
+ SubConversation: "bpmn:SubConversation",
77
+ CallConversation: "bpmn:CallConversation",
78
+ ChoreographyTask: "bpmn:ChoreographyTask",
79
+ SubChoreography: "bpmn:SubChoreography",
80
+ CallChoreography: "bpmn:CallChoreography"
81
+ };
82
+ var MODDLE_TO_EDGE_TYPE = {
83
+ "bpmn:SequenceFlow": "sequenceFlow",
84
+ "bpmn:MessageFlow": "messageFlow",
85
+ "bpmn:Association": "association",
86
+ "bpmn:DataInputAssociation": "dataAssociation",
87
+ "bpmn:DataOutputAssociation": "dataAssociation",
88
+ "bpmn:ConversationLink": "conversationLink"
89
+ };
90
+ var EDGE_TYPE_TO_MODDLE = {
91
+ sequenceFlow: "bpmn:SequenceFlow",
92
+ messageFlow: "bpmn:MessageFlow",
93
+ association: "bpmn:Association",
94
+ dataAssociation: "bpmn:DataInputAssociation",
95
+ conversationLink: "bpmn:ConversationLink"
96
+ };
97
+ var EVENT_DEF_TO_TRIGGER = {
98
+ "bpmn:MessageEventDefinition": "message",
99
+ "bpmn:TimerEventDefinition": "timer",
100
+ "bpmn:EscalationEventDefinition": "escalation",
101
+ "bpmn:ConditionalEventDefinition": "conditional",
102
+ "bpmn:ErrorEventDefinition": "error",
103
+ "bpmn:CancelEventDefinition": "cancel",
104
+ "bpmn:CompensateEventDefinition": "compensation",
105
+ "bpmn:SignalEventDefinition": "signal",
106
+ "bpmn:LinkEventDefinition": "link",
107
+ "bpmn:TerminateEventDefinition": "terminate"
108
+ };
109
+ var TRIGGER_TO_EVENT_DEF = {
110
+ message: "bpmn:MessageEventDefinition",
111
+ timer: "bpmn:TimerEventDefinition",
112
+ escalation: "bpmn:EscalationEventDefinition",
113
+ conditional: "bpmn:ConditionalEventDefinition",
114
+ error: "bpmn:ErrorEventDefinition",
115
+ cancel: "bpmn:CancelEventDefinition",
116
+ compensation: "bpmn:CompensateEventDefinition",
117
+ signal: "bpmn:SignalEventDefinition",
118
+ link: "bpmn:LinkEventDefinition",
119
+ terminate: "bpmn:TerminateEventDefinition"
120
+ };
121
+
122
+ // src/xml/importer.ts
123
+ function asElements(v) {
124
+ return Array.isArray(v) ? v : [];
125
+ }
126
+ function asString(v) {
127
+ return typeof v === "string" && v.trim() ? v.trim() : void 0;
128
+ }
129
+ function extractDiagramInfo(definitions) {
130
+ const shapes = /* @__PURE__ */ new Map();
131
+ const waypoints = /* @__PURE__ */ new Map();
132
+ for (const diagram of asElements(definitions.diagrams)) {
133
+ const plane = diagram.plane;
134
+ if (!plane) continue;
135
+ for (const el of asElements(plane.planeElement)) {
136
+ const bpmnEl = el.bpmnElement;
137
+ if (!bpmnEl?.id) continue;
138
+ const id = bpmnEl.id;
139
+ if (el.$type === "bpmndi:BPMNShape") {
140
+ const b = el.bounds;
141
+ if (b) {
142
+ shapes.set(id, {
143
+ x: b.x,
144
+ y: b.y,
145
+ width: b.width,
146
+ height: b.height,
147
+ ...typeof el.isExpanded === "boolean" ? { isExpanded: el.isExpanded } : {}
148
+ });
149
+ }
150
+ } else if (el.$type === "bpmndi:BPMNEdge") {
151
+ const pts = el.waypoint ?? [];
152
+ if (pts.length) waypoints.set(id, pts);
153
+ }
154
+ }
155
+ }
156
+ return { shapes, waypoints };
157
+ }
158
+ function extractLaneMembership(process) {
159
+ const map = /* @__PURE__ */ new Map();
160
+ function walkLaneSet(laneSet2) {
161
+ for (const lane of asElements(laneSet2.lanes)) {
162
+ const laneId = lane.id;
163
+ if (!laneId) continue;
164
+ for (const ref of asElements(lane.flowNodeRef)) {
165
+ if (ref.id) map.set(ref.id, laneId);
166
+ }
167
+ const child = lane.childLaneSet;
168
+ if (child) walkLaneSet(child);
169
+ }
170
+ }
171
+ const laneSet = process.laneSet;
172
+ if (laneSet) walkLaneSet(laneSet);
173
+ return map;
174
+ }
175
+ function extractTrigger(el) {
176
+ const defs = asElements(el.eventDefinitions);
177
+ if (defs.length === 0) return void 0;
178
+ if (defs.length > 1) return el.$type.includes("Parallel") ? "parallelMultiple" : "multiple";
179
+ return EVENT_DEF_TO_TRIGGER[defs[0].$type];
180
+ }
181
+ function extractSubProcessVariant(el) {
182
+ if (el.$type === "bpmn:Transaction") return "transaction";
183
+ if (el.$type === "bpmn:AdHocSubProcess") return "adhoc";
184
+ if (el.triggeredByEvent === true) return "event";
185
+ return "embedded";
186
+ }
187
+ function walkFlowElements(elements, parentId, ctx, nodes, edges) {
188
+ for (const el of elements) {
189
+ const { $type, id } = el;
190
+ if (!id) continue;
191
+ const edgeType = MODDLE_TO_EDGE_TYPE[$type];
192
+ if (edgeType !== void 0) {
193
+ buildEdge(el, edgeType, ctx, edges);
194
+ continue;
195
+ }
196
+ if ($type === "bpmn:LaneSet") continue;
197
+ const elementType = MODDLE_TO_ELEMENT_TYPE[$type];
198
+ if (!elementType) {
199
+ ctx.warnings.push(`Unknown element type "${$type}" (id=${id}) \u2014 skipped.`);
200
+ continue;
201
+ }
202
+ buildNode(el, elementType, parentId, ctx, nodes);
203
+ if ($type === "bpmn:SubProcess" || $type === "bpmn:Transaction" || $type === "bpmn:AdHocSubProcess") {
204
+ const children = asElements(el.flowElements);
205
+ const laneMembership = extractLaneMembership(el);
206
+ walkFlowElements(children, id, { ...ctx, laneMembership }, nodes, edges);
207
+ }
208
+ }
209
+ }
210
+ function buildNode(el, elementType, parentId, ctx, nodes) {
211
+ const id = el.id;
212
+ const meta = BPMN_ELEMENT_CATALOG[elementType];
213
+ const shape = ctx.shapes.get(id);
214
+ const x = shape?.x ?? ctx.autoX.value;
215
+ const y = shape?.y ?? 100;
216
+ if (!shape) ctx.autoX.value += (meta?.defaultWidth ?? 120) + 20;
217
+ const label = asString(el.name);
218
+ const trigger = extractTrigger(el);
219
+ const isNonInterrupting = el.cancelActivity === false;
220
+ const data = {
221
+ elementType,
222
+ ...label ? { label } : {},
223
+ ...trigger ? { trigger } : {},
224
+ ...isNonInterrupting ? { isNonInterrupting: true } : {}
225
+ };
226
+ if (elementType === "SubProcess") {
227
+ const variant = extractSubProcessVariant(el);
228
+ if (variant) data.subProcessVariant = variant;
229
+ const isExpanded = shape?.isExpanded ?? true;
230
+ data.isExpanded = isExpanded;
231
+ }
232
+ const laneId = ctx.laneMembership.get(id);
233
+ const effectiveParentId = laneId ?? parentId;
234
+ const node = {
235
+ id,
236
+ type: elementType,
237
+ position: { x, y },
238
+ data,
239
+ width: shape?.width ?? meta?.defaultWidth,
240
+ height: shape?.height ?? meta?.defaultHeight,
241
+ ...effectiveParentId ? { parentId: effectiveParentId } : {}
242
+ };
243
+ nodes.push(node);
244
+ }
245
+ function buildEdge(el, edgeType, ctx, edges) {
246
+ const id = el.id;
247
+ const source = el.sourceRef?.id;
248
+ const target = el.targetRef?.id;
249
+ if (!source || !target) {
250
+ ctx.warnings.push(`Edge "${id}" missing source or target \u2014 skipped.`);
251
+ return;
252
+ }
253
+ const label = asString(el.name);
254
+ const condExpr = el.conditionExpression;
255
+ const data = {
256
+ edgeType,
257
+ ...label ? { label } : {},
258
+ ...condExpr?.body ? { conditionExpression: condExpr.body } : {}
259
+ };
260
+ const waypoints = ctx.waypoints.get(id);
261
+ if (waypoints?.length) data.routingPoints = waypoints;
262
+ edges.push({ id, type: edgeType, source, target, data });
263
+ }
264
+ function handleCollaboration(collaboration, ctx, nodes, edges) {
265
+ for (const participant of asElements(collaboration.participants)) {
266
+ const id = participant.id;
267
+ if (!id) continue;
268
+ const label = asString(participant.name);
269
+ const shape = ctx.shapes.get(id);
270
+ const poolNode = {
271
+ id,
272
+ type: "Pool",
273
+ position: { x: shape?.x ?? 0, y: shape?.y ?? 0 },
274
+ data: { elementType: "Pool", ...label ? { label } : {} },
275
+ width: shape?.width ?? 600,
276
+ height: shape?.height ?? 200
277
+ };
278
+ nodes.push(poolNode);
279
+ const processRef = participant.processRef;
280
+ if (processRef) {
281
+ const laneMembership = extractLaneMembership(processRef);
282
+ walkFlowElements(
283
+ asElements(processRef.flowElements),
284
+ id,
285
+ { ...ctx, laneMembership },
286
+ nodes,
287
+ edges
288
+ );
289
+ const laneSet = processRef.laneSet;
290
+ if (laneSet) {
291
+ addLaneNodes(laneSet, id, ctx, nodes);
292
+ }
293
+ }
294
+ }
295
+ for (const mf of asElements(collaboration.messageFlows)) {
296
+ buildEdge(mf, "messageFlow", ctx, edges);
297
+ }
298
+ for (const cl of asElements(collaboration.conversationLinks)) {
299
+ buildEdge(cl, "conversationLink", ctx, edges);
300
+ }
301
+ }
302
+ function addLaneNodes(laneSet, poolId, ctx, nodes) {
303
+ for (const lane of asElements(laneSet.lanes)) {
304
+ const id = lane.id;
305
+ if (!id) continue;
306
+ const label = asString(lane.name);
307
+ const shape = ctx.shapes.get(id);
308
+ nodes.push({
309
+ id,
310
+ type: "Lane",
311
+ position: { x: shape?.x ?? 30, y: shape?.y ?? 0 },
312
+ data: { elementType: "Lane", ...label ? { label } : {} },
313
+ width: shape?.width ?? 570,
314
+ height: shape?.height ?? 120,
315
+ parentId: poolId
316
+ });
317
+ const child = lane.childLaneSet;
318
+ if (child) addLaneNodes(child, poolId, ctx, nodes);
319
+ }
320
+ }
321
+ async function parseBpmnXml(xml) {
322
+ const moddle = new BpmnModdle();
323
+ const warnings = [];
324
+ let rootElement;
325
+ try {
326
+ const result = await moddle.fromXML(xml);
327
+ rootElement = result.rootElement;
328
+ for (const w of result.warnings) warnings.push(w.message);
329
+ } catch (err) {
330
+ throw new Error(`Failed to parse BPMN XML: ${String(err)}`);
331
+ }
332
+ const nodes = [];
333
+ const edges = [];
334
+ const { shapes, waypoints } = extractDiagramInfo(rootElement);
335
+ const ctx = {
336
+ shapes,
337
+ waypoints,
338
+ laneMembership: /* @__PURE__ */ new Map(),
339
+ warnings,
340
+ autoX: { value: 50 }
341
+ };
342
+ for (const rootEl of asElements(rootElement.rootElements)) {
343
+ if (rootEl.$type === "bpmn:Collaboration") {
344
+ handleCollaboration(rootEl, ctx, nodes, edges);
345
+ } else if (rootEl.$type === "bpmn:Process") {
346
+ const laneMembership = extractLaneMembership(rootEl);
347
+ const laneSet = rootEl.laneSet;
348
+ if (laneSet) addLaneNodes(laneSet, "", ctx, nodes);
349
+ walkFlowElements(
350
+ asElements(rootEl.flowElements),
351
+ void 0,
352
+ { ...ctx, laneMembership },
353
+ nodes,
354
+ edges
355
+ );
356
+ }
357
+ }
358
+ return { nodes, edges, warnings };
359
+ }
360
+ function uid(prefix, id) {
361
+ return `${prefix}_${id}`;
362
+ }
363
+ function asNodes(nodes, types) {
364
+ return nodes.filter((n) => types.includes(n.data.elementType));
365
+ }
366
+ function buildFlowableAttrs(data) {
367
+ const attrs = {};
368
+ if (data.flowableAssignee) attrs["flowable:assignee"] = data.flowableAssignee;
369
+ if (data.flowableCandidateGroups) attrs["flowable:candidateGroups"] = data.flowableCandidateGroups;
370
+ if (data.flowableCandidateUsers) attrs["flowable:candidateUsers"] = data.flowableCandidateUsers;
371
+ if (data.flowableFormKey) attrs["flowable:formKey"] = data.flowableFormKey;
372
+ if (data.flowableDueDate) attrs["flowable:dueDate"] = data.flowableDueDate;
373
+ if (data.flowableType) attrs["flowable:type"] = data.flowableType;
374
+ if (data.flowableExpression) attrs["flowable:expression"] = data.flowableExpression;
375
+ if (data.flowableClass) attrs["flowable:class"] = data.flowableClass;
376
+ if (data.flowableDelegateExpression) attrs["flowable:delegateExpression"] = data.flowableDelegateExpression;
377
+ return attrs;
378
+ }
379
+ function buildSemanticModel(moddle, nodes, edges, opts) {
380
+ const defId = opts.id ?? "Definitions_1";
381
+ const defName = opts.name;
382
+ const poolNodes = asNodes(nodes, ["Pool"]);
383
+ const laneNodes = asNodes(nodes, ["Lane"]);
384
+ const isCollaboration = poolNodes.length > 0;
385
+ const definitions = moddle.create("bpmn:Definitions", {
386
+ id: defId,
387
+ targetNamespace: "http://bpmn.io/schema/bpmn",
388
+ ...defName ? { name: defName } : {}
389
+ });
390
+ const rootElements = [];
391
+ if (isCollaboration) {
392
+ const participants = [];
393
+ const processes = [];
394
+ for (const pool of poolNodes) {
395
+ const processId = `Process_${pool.id}`;
396
+ const process = buildProcess(moddle, nodes, edges, pool.id, laneNodes, processId);
397
+ processes.push(process);
398
+ const participant = moddle.create("bpmn:Participant", {
399
+ id: pool.id,
400
+ name: pool.data.label ?? "",
401
+ processRef: process
402
+ });
403
+ participants.push(participant);
404
+ }
405
+ const messageFlowEdges = edges.filter((e) => e.data?.edgeType === "messageFlow");
406
+ const conversationLinkEdges = edges.filter((e) => e.data?.edgeType === "conversationLink");
407
+ const messageFlows = messageFlowEdges.map(
408
+ (e) => moddle.create("bpmn:MessageFlow", {
409
+ id: e.id,
410
+ name: e.data?.label ?? "",
411
+ sourceRef: { id: e.source },
412
+ targetRef: { id: e.target }
413
+ })
414
+ );
415
+ const conversationLinks = conversationLinkEdges.map(
416
+ (e) => moddle.create("bpmn:ConversationLink", {
417
+ id: e.id,
418
+ sourceRef: { id: e.source },
419
+ targetRef: { id: e.target }
420
+ })
421
+ );
422
+ const collaboration = moddle.create("bpmn:Collaboration", {
423
+ id: `Collaboration_${defId}`,
424
+ participants,
425
+ messageFlows,
426
+ conversationLinks
427
+ });
428
+ rootElements.push(collaboration, ...processes);
429
+ } else {
430
+ const process = buildProcess(moddle, nodes, edges, void 0, laneNodes, "Process_1");
431
+ rootElements.push(process);
432
+ }
433
+ definitions.rootElements = rootElements;
434
+ return definitions;
435
+ }
436
+ function buildProcess(moddle, allNodes, allEdges, poolId, laneNodes, processId) {
437
+ const myNodes = poolId ? allNodes.filter(
438
+ (n) => n.parentId === poolId || laneNodes.some((l) => l.id === n.parentId && l.parentId === poolId)
439
+ ) : allNodes.filter((n) => n.data.elementType !== "Pool" && n.data.elementType !== "Lane");
440
+ const myLanes = laneNodes.filter((l) => poolId ? l.parentId === poolId : true);
441
+ const flowElements = [];
442
+ for (const node of myNodes) {
443
+ const el = buildFlowElement(moddle, node);
444
+ if (el) flowElements.push(el);
445
+ }
446
+ const myNodeIds = new Set(myNodes.map((n) => n.id));
447
+ const myEdges = allEdges.filter(
448
+ (e) => (e.data?.edgeType === "sequenceFlow" || e.data?.edgeType === "association" || e.data?.edgeType === "dataAssociation") && myNodeIds.has(e.source) && myNodeIds.has(e.target)
449
+ );
450
+ for (const edge of myEdges) {
451
+ const edgeMeta = buildEdgeElement(moddle, edge);
452
+ if (edgeMeta) flowElements.push(edgeMeta);
453
+ }
454
+ const process = moddle.create("bpmn:Process", {
455
+ id: processId,
456
+ isExecutable: true,
457
+ flowElements
458
+ });
459
+ if (myLanes.length > 0) {
460
+ const laneElements = myLanes.map(
461
+ (l) => moddle.create("bpmn:Lane", {
462
+ id: l.id,
463
+ name: l.data.label ?? "",
464
+ flowNodeRef: myNodes.filter((n) => n.parentId === l.id).map((n) => ({ id: n.id }))
465
+ })
466
+ );
467
+ process.laneSet = moddle.create("bpmn:LaneSet", {
468
+ id: `LaneSet_${processId}`,
469
+ lanes: laneElements
470
+ });
471
+ }
472
+ return process;
473
+ }
474
+ function buildFlowElement(moddle, node, _allNodes, _allEdges) {
475
+ const { elementType, label, trigger } = node.data;
476
+ if (elementType === "Pool" || elementType === "Lane") return null;
477
+ const moddleType = ELEMENT_TYPE_TO_MODDLE[elementType];
478
+ if (!moddleType) return null;
479
+ const attrs = {
480
+ id: node.id,
481
+ name: label ?? ""
482
+ };
483
+ if (trigger && trigger !== "none") {
484
+ const defType = TRIGGER_TO_EVENT_DEF[trigger];
485
+ if (defType) {
486
+ attrs.eventDefinitions = [moddle.create(defType, { id: uid("EventDef", node.id) })];
487
+ }
488
+ }
489
+ if (elementType === "SubProcess" && node.data.subProcessVariant === "transaction") {
490
+ return moddle.create("bpmn:Transaction", attrs);
491
+ }
492
+ if (elementType === "SubProcess" && node.data.subProcessVariant === "adhoc") {
493
+ return moddle.create("bpmn:AdHocSubProcess", attrs);
494
+ }
495
+ const element = moddle.create(moddleType, attrs);
496
+ const flowableAttrs = buildFlowableAttrs(node.data);
497
+ if (Object.keys(flowableAttrs).length > 0) {
498
+ element.$attrs = flowableAttrs;
499
+ }
500
+ return element;
501
+ }
502
+ function buildEdgeElement(moddle, edge) {
503
+ if (!edge.data) return null;
504
+ const moddleType = EDGE_TYPE_TO_MODDLE[edge.data.edgeType];
505
+ if (!moddleType) return null;
506
+ const attrs = {
507
+ id: edge.id,
508
+ name: edge.data.label ?? "",
509
+ sourceRef: { id: edge.source },
510
+ targetRef: { id: edge.target }
511
+ };
512
+ if (edge.data.conditionExpression) {
513
+ attrs.conditionExpression = moddle.create("bpmn:FormalExpression", {
514
+ body: edge.data.conditionExpression
515
+ });
516
+ }
517
+ return moddle.create(moddleType, attrs);
518
+ }
519
+ function buildBpmnDI(moddle, definitions, nodes, edges) {
520
+ const shapes = [];
521
+ const edgeShapes = [];
522
+ for (const node of nodes) {
523
+ const meta = BPMN_ELEMENT_CATALOG[node.data.elementType];
524
+ const w = node.width ?? meta?.defaultWidth ?? 120;
525
+ const h = node.height ?? meta?.defaultHeight ?? 60;
526
+ const bounds = moddle.create("dc:Bounds", {
527
+ x: node.position.x,
528
+ y: node.position.y,
529
+ width: w,
530
+ height: h
531
+ });
532
+ const shape = moddle.create("bpmndi:BPMNShape", {
533
+ id: uid("BPMNShape", node.id),
534
+ bpmnElement: { id: node.id },
535
+ bounds
536
+ });
537
+ if (node.data.isExpanded !== void 0) {
538
+ shape.isExpanded = node.data.isExpanded;
539
+ }
540
+ shapes.push(shape);
541
+ }
542
+ for (const edge of edges) {
543
+ const waypoints = edge.data?.routingPoints?.map(
544
+ (p) => moddle.create("dc:Point", { x: p.x, y: p.y })
545
+ ) ?? [];
546
+ edgeShapes.push(
547
+ moddle.create("bpmndi:BPMNEdge", {
548
+ id: uid("BPMNEdge", edge.id),
549
+ bpmnElement: { id: edge.id },
550
+ waypoint: waypoints
551
+ })
552
+ );
553
+ }
554
+ const rootEls = definitions.rootElements;
555
+ const planeElement = rootEls?.[0];
556
+ const plane = moddle.create("bpmndi:BPMNPlane", {
557
+ id: "BPMNPlane_1",
558
+ bpmnElement: planeElement ?? { id: "unknown" },
559
+ planeElement: [...shapes, ...edgeShapes]
560
+ });
561
+ const diagram = moddle.create("bpmndi:BPMNDiagram", {
562
+ id: "BPMNDiagram_1",
563
+ plane
564
+ });
565
+ definitions.diagrams = [diagram];
566
+ }
567
+ async function serializeBpmnXml(nodes, edges, opts = {}) {
568
+ const moddle = new BpmnModdle();
569
+ const definitions = buildSemanticModel(moddle, nodes, edges, opts);
570
+ buildBpmnDI(moddle, definitions, nodes, edges);
571
+ const { xml } = await moddle.toXML(definitions, {
572
+ format: opts.format ?? true
573
+ });
574
+ return xml;
575
+ }
576
+
577
+ export { parseBpmnXml, serializeBpmnXml };
578
+ //# sourceMappingURL=chunk-4OAEWYYU.js.map
579
+ //# sourceMappingURL=chunk-4OAEWYYU.js.map