@bpmnkit/core 1.0.0 → 1.2.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 (73) hide show
  1. package/README.md +30 -3
  2. package/dist/bpmn/agentic.js +3 -1
  3. package/dist/bpmn/auto-layout.js +184 -15
  4. package/dist/bpmn/bpmn-builder.js +69 -7
  5. package/dist/bpmn/bpmn-model.d.ts +78 -0
  6. package/dist/bpmn/bpmn-parser.js +195 -37
  7. package/dist/bpmn/bpmn-serializer.js +121 -72
  8. package/dist/bpmn/bpmnlint.d.ts +153 -0
  9. package/dist/bpmn/bpmnlint.js +364 -0
  10. package/dist/bpmn/camunda-compat-data.d.ts +165 -0
  11. package/dist/bpmn/camunda-compat-data.js +423 -0
  12. package/dist/bpmn/camunda-compat-feel.d.ts +68 -0
  13. package/dist/bpmn/camunda-compat-feel.js +338 -0
  14. package/dist/bpmn/camunda-compat.d.ts +120 -0
  15. package/dist/bpmn/camunda-compat.js +1677 -0
  16. package/dist/bpmn/camunda7/juel.d.ts +41 -0
  17. package/dist/bpmn/camunda7/juel.js +333 -0
  18. package/dist/bpmn/camunda7/migrate.d.ts +72 -0
  19. package/dist/bpmn/camunda7/migrate.js +1152 -0
  20. package/dist/bpmn/compact.d.ts +4 -0
  21. package/dist/bpmn/compact.js +80 -0
  22. package/dist/bpmn/full-operations.js +5 -2
  23. package/dist/bpmn/label-style.d.ts +51 -0
  24. package/dist/bpmn/label-style.js +116 -0
  25. package/dist/bpmn/lint.d.ts +23 -3
  26. package/dist/bpmn/lint.js +47 -10
  27. package/dist/bpmn/optimize/bpmnlint-rules.d.ts +31 -0
  28. package/dist/bpmn/optimize/bpmnlint-rules.js +916 -0
  29. package/dist/bpmn/optimize/deploy.d.ts +8 -2
  30. package/dist/bpmn/optimize/deploy.js +16 -3
  31. package/dist/bpmn/optimize/index.js +11 -2
  32. package/dist/bpmn/optimize/patterns.js +3 -0
  33. package/dist/bpmn/optimize/types.d.ts +14 -0
  34. package/dist/bpmn/optimize/variable-flow.js +4 -1
  35. package/dist/bpmn/process-delta.d.ts +88 -0
  36. package/dist/bpmn/process-delta.js +236 -0
  37. package/dist/bpmn/process-text-writer.d.ts +53 -0
  38. package/dist/bpmn/process-text-writer.js +193 -0
  39. package/dist/bpmn/process-text.d.ts +175 -0
  40. package/dist/bpmn/process-text.js +1255 -0
  41. package/dist/bpmn/process-types.d.ts +112 -0
  42. package/dist/bpmn/process-types.js +490 -0
  43. package/dist/bpmn/svg.js +51 -22
  44. package/dist/doc/docx.d.ts +20 -0
  45. package/dist/doc/docx.js +253 -0
  46. package/dist/doc/html.d.ts +21 -0
  47. package/dist/doc/html.js +303 -0
  48. package/dist/doc/index.d.ts +7 -0
  49. package/dist/doc/index.js +5 -0
  50. package/dist/doc/markdown.d.ts +11 -0
  51. package/dist/doc/markdown.js +160 -0
  52. package/dist/doc/model.d.ts +129 -0
  53. package/dist/doc/model.js +617 -0
  54. package/dist/doc/zip.d.ts +5 -0
  55. package/dist/doc/zip.js +75 -0
  56. package/dist/index.d.ts +22 -0
  57. package/dist/index.js +11 -0
  58. package/dist/layout/annotations.d.ts +4 -2
  59. package/dist/layout/annotations.js +31 -2
  60. package/dist/layout/collaboration/ordering.d.ts +8 -0
  61. package/dist/layout/collaboration/ordering.js +57 -18
  62. package/dist/layout/orthogonal.d.ts +32 -0
  63. package/dist/layout/orthogonal.js +367 -0
  64. package/dist/layout/repair.d.ts +31 -0
  65. package/dist/layout/repair.js +220 -0
  66. package/dist/layout/semantic/route.js +45 -3
  67. package/dist/node/bpmnlint.d.ts +109 -0
  68. package/dist/node/bpmnlint.js +198 -0
  69. package/dist/node/index.d.ts +2 -0
  70. package/dist/node/index.js +1 -0
  71. package/dist/xml/xml-patch.d.ts +21 -0
  72. package/dist/xml/xml-patch.js +27 -1
  73. package/package.json +2 -2
@@ -2,24 +2,47 @@ import { serializeXml } from "../xml/xml-parser.js";
2
2
  // ---------------------------------------------------------------------------
3
3
  // Namespace prefix resolution
4
4
  // ---------------------------------------------------------------------------
5
+ /**
6
+ * The prefix a document binds `uri` to: `""` when it is the document's default
7
+ * namespace, otherwise the first named prefix, otherwise `undefined`.
8
+ *
9
+ * The default wins when a document binds both. Models from other tools often put
10
+ * BPMN in the default namespace and add a named binding they never use, and
11
+ * writing their elements the way they spelled them keeps the file recognisable.
12
+ */
5
13
  function nsPrefix(namespaces, uri) {
14
+ if (namespaces[""] === uri)
15
+ return "";
6
16
  for (const [prefix, u] of Object.entries(namespaces)) {
7
17
  if (u === uri)
8
18
  return prefix;
9
19
  }
10
20
  return undefined;
11
21
  }
22
+ const BPMN_NS = "http://www.omg.org/spec/BPMN/20100524/MODEL";
23
+ const BPMNDI_NS = "http://www.omg.org/spec/BPMN/20100524/DI";
24
+ const DC_NS = "http://www.omg.org/spec/DD/20100524/DC";
25
+ const DI_NS = "http://www.omg.org/spec/DD/20100524/DI";
26
+ /**
27
+ * What goes in front of a local name: `"bpmn:"`, or `""` when the namespace is the
28
+ * document's default — models from other tools often put BPMN there, and writing
29
+ * `<process>` back keeps their spelling (and keeps the XML valid).
30
+ */
31
+ function qualifier(ns, uri, fallback) {
32
+ const prefix = nsPrefix(ns, uri) ?? fallback;
33
+ return prefix === "" ? "" : `${prefix}:`;
34
+ }
12
35
  function bpmnPrefix(ns) {
13
- return nsPrefix(ns, "http://www.omg.org/spec/BPMN/20100524/MODEL") ?? "bpmn";
36
+ return qualifier(ns, BPMN_NS, "bpmn");
14
37
  }
15
38
  function bpmndiPrefix(ns) {
16
- return nsPrefix(ns, "http://www.omg.org/spec/BPMN/20100524/DI") ?? "bpmndi";
39
+ return qualifier(ns, BPMNDI_NS, "bpmndi");
17
40
  }
18
41
  function dcPrefix(ns) {
19
- return nsPrefix(ns, "http://www.omg.org/spec/DD/20100524/DC") ?? "dc";
42
+ return qualifier(ns, DC_NS, "dc");
20
43
  }
21
44
  function diPrefix(ns) {
22
- return nsPrefix(ns, "http://www.omg.org/spec/DD/20100524/DI") ?? "di";
45
+ return qualifier(ns, DI_NS, "di");
23
46
  }
24
47
  // ---------------------------------------------------------------------------
25
48
  // Helpers
@@ -30,21 +53,25 @@ function el(name, attributes, children, text) {
30
53
  // ---------------------------------------------------------------------------
31
54
  // Event definitions
32
55
  // ---------------------------------------------------------------------------
56
+ /** Modelled attributes followed by the ones the parser kept verbatim. */
57
+ function withUnknown(attrs, owner) {
58
+ return owner.unknownAttributes ? { ...attrs, ...owner.unknownAttributes } : attrs;
59
+ }
33
60
  function serializeEventDefinitions(defs, bp) {
34
61
  return defs.map((d) => {
35
62
  switch (d.type) {
36
63
  case "timer": {
37
64
  const children = [];
38
65
  if (d.timeDuration !== undefined) {
39
- children.push(el(`${bp}:timeDuration`, d.timeDurationAttributes ?? {}, [], d.timeDuration));
66
+ children.push(el(`${bp}timeDuration`, d.timeDurationAttributes ?? {}, [], d.timeDuration));
40
67
  }
41
68
  if (d.timeDate !== undefined) {
42
- children.push(el(`${bp}:timeDate`, d.timeDateAttributes ?? {}, [], d.timeDate));
69
+ children.push(el(`${bp}timeDate`, d.timeDateAttributes ?? {}, [], d.timeDate));
43
70
  }
44
71
  if (d.timeCycle !== undefined) {
45
- children.push(el(`${bp}:timeCycle`, d.timeCycleAttributes ?? {}, [], d.timeCycle));
72
+ children.push(el(`${bp}timeCycle`, d.timeCycleAttributes ?? {}, [], d.timeCycle));
46
73
  }
47
- return el(`${bp}:timerEventDefinition`, d.id ? { id: d.id } : {}, children);
74
+ return el(`${bp}timerEventDefinition`, withUnknown(d.id ? { id: d.id } : {}, d), children);
48
75
  }
49
76
  case "error": {
50
77
  const attrs = {};
@@ -52,7 +79,7 @@ function serializeEventDefinitions(defs, bp) {
52
79
  attrs.id = d.id;
53
80
  if (d.errorRef)
54
81
  attrs.errorRef = d.errorRef;
55
- return el(`${bp}:errorEventDefinition`, attrs, []);
82
+ return el(`${bp}errorEventDefinition`, withUnknown(attrs, d), []);
56
83
  }
57
84
  case "escalation": {
58
85
  const attrs = {};
@@ -60,7 +87,7 @@ function serializeEventDefinitions(defs, bp) {
60
87
  attrs.id = d.id;
61
88
  if (d.escalationRef)
62
89
  attrs.escalationRef = d.escalationRef;
63
- return el(`${bp}:escalationEventDefinition`, attrs, []);
90
+ return el(`${bp}escalationEventDefinition`, withUnknown(attrs, d), []);
64
91
  }
65
92
  case "message": {
66
93
  const attrs = {};
@@ -68,7 +95,7 @@ function serializeEventDefinitions(defs, bp) {
68
95
  attrs.id = d.id;
69
96
  if (d.messageRef)
70
97
  attrs.messageRef = d.messageRef;
71
- return el(`${bp}:messageEventDefinition`, attrs, []);
98
+ return el(`${bp}messageEventDefinition`, withUnknown(attrs, d), []);
72
99
  }
73
100
  case "signal": {
74
101
  const attrs = {};
@@ -76,7 +103,7 @@ function serializeEventDefinitions(defs, bp) {
76
103
  attrs.id = d.id;
77
104
  if (d.signalRef)
78
105
  attrs.signalRef = d.signalRef;
79
- return el(`${bp}:signalEventDefinition`, attrs, []);
106
+ return el(`${bp}signalEventDefinition`, withUnknown(attrs, d), []);
80
107
  }
81
108
  case "conditional": {
82
109
  const attrs = {};
@@ -84,9 +111,9 @@ function serializeEventDefinitions(defs, bp) {
84
111
  attrs.id = d.id;
85
112
  const condChildren = [];
86
113
  if (d.condition !== undefined) {
87
- condChildren.push(el(`${bp}:condition`, {}, [], d.condition));
114
+ condChildren.push(el(`${bp}condition`, d.conditionAttributes ?? {}, [], d.condition));
88
115
  }
89
- return el(`${bp}:conditionalEventDefinition`, attrs, condChildren);
116
+ return el(`${bp}conditionalEventDefinition`, withUnknown(attrs, d), condChildren);
90
117
  }
91
118
  case "link": {
92
119
  const attrs = {};
@@ -94,19 +121,19 @@ function serializeEventDefinitions(defs, bp) {
94
121
  attrs.id = d.id;
95
122
  if (d.name)
96
123
  attrs.name = d.name;
97
- return el(`${bp}:linkEventDefinition`, attrs, []);
124
+ return el(`${bp}linkEventDefinition`, withUnknown(attrs, d), []);
98
125
  }
99
126
  case "cancel": {
100
127
  const attrs = {};
101
128
  if (d.id)
102
129
  attrs.id = d.id;
103
- return el(`${bp}:cancelEventDefinition`, attrs, []);
130
+ return el(`${bp}cancelEventDefinition`, withUnknown(attrs, d), []);
104
131
  }
105
132
  case "terminate": {
106
133
  const attrs = {};
107
134
  if (d.id)
108
135
  attrs.id = d.id;
109
- return el(`${bp}:terminateEventDefinition`, attrs, []);
136
+ return el(`${bp}terminateEventDefinition`, withUnknown(attrs, d), []);
110
137
  }
111
138
  case "compensate": {
112
139
  const attrs = {};
@@ -114,7 +141,7 @@ function serializeEventDefinitions(defs, bp) {
114
141
  attrs.id = d.id;
115
142
  if (d.activityRef)
116
143
  attrs.activityRef = d.activityRef;
117
- return el(`${bp}:compensateEventDefinition`, attrs, []);
144
+ return el(`${bp}compensateEventDefinition`, withUnknown(attrs, d), []);
118
145
  }
119
146
  default: {
120
147
  const _exhaustive = d;
@@ -129,7 +156,7 @@ function serializeEventDefinitions(defs, bp) {
129
156
  function serializeExtensionElements(extensions, bp) {
130
157
  if (extensions.length === 0)
131
158
  return [];
132
- return [el(`${bp}:extensionElements`, {}, extensions)];
159
+ return [el(`${bp}extensionElements`, {}, extensions)];
133
160
  }
134
161
  /**
135
162
  * The `documentation` and `extensionElements` children shared by every BPMN
@@ -138,7 +165,7 @@ function serializeExtensionElements(extensions, bp) {
138
165
  function serializeBaseChildren(owner, bp) {
139
166
  const children = [];
140
167
  if (owner.documentation !== undefined) {
141
- children.push(el(`${bp}:documentation`, {}, [], owner.documentation));
168
+ children.push(el(`${bp}documentation`, owner.documentationAttributes ?? {}, [], owner.documentation));
142
169
  }
143
170
  children.push(...serializeExtensionElements(owner.extensionElements ?? [], bp));
144
171
  return children;
@@ -154,18 +181,21 @@ function serializeProperty(property, bp) {
154
181
  attrs.name = property.name;
155
182
  if (property.itemSubjectRef !== undefined)
156
183
  attrs.itemSubjectRef = property.itemSubjectRef;
157
- return el(`${bp}:property`, attrs, []);
184
+ return el(`${bp}property`, attrs, []);
158
185
  }
159
186
  function serializeDataAssociation(association, tag, bp) {
160
187
  const attrs = { ...association.unknownAttributes };
161
188
  if (association.id !== undefined)
162
189
  attrs.id = association.id;
163
- const children = association.sourceRefs.map((ref) => el(`${bp}:sourceRef`, {}, [], ref));
190
+ const children = [
191
+ ...serializeBaseChildren(association, bp),
192
+ ...association.sourceRefs.map((ref) => el(`${bp}sourceRef`, {}, [], ref)),
193
+ ];
164
194
  if (association.targetRef !== undefined) {
165
- children.push(el(`${bp}:targetRef`, {}, [], association.targetRef));
195
+ children.push(el(`${bp}targetRef`, {}, [], association.targetRef));
166
196
  }
167
197
  children.push(...(association.unknownChildren ?? []));
168
- return el(`${bp}:${tag}`, attrs, children);
198
+ return el(`${bp}${tag}`, attrs, children);
169
199
  }
170
200
  // ---------------------------------------------------------------------------
171
201
  // Multi-instance loop
@@ -174,23 +204,25 @@ function serializeLoopCharacteristics(lc, bp) {
174
204
  if (!lc)
175
205
  return [];
176
206
  const attrs = {};
207
+ if (lc.id !== undefined)
208
+ attrs.id = lc.id;
177
209
  if (lc.isSequential)
178
210
  attrs.isSequential = "true";
179
211
  const children = [...serializeExtensionElements(lc.extensionElements, bp)];
180
212
  if (lc.loopCardinality) {
181
- children.push(el(`${bp}:loopCardinality`, lc.loopCardinality.attributes, [], lc.loopCardinality.text));
213
+ children.push(el(`${bp}loopCardinality`, lc.loopCardinality.attributes, [], lc.loopCardinality.text));
182
214
  }
183
215
  if (lc.completionCondition) {
184
- children.push(el(`${bp}:completionCondition`, lc.completionCondition.attributes, [], lc.completionCondition.text));
216
+ children.push(el(`${bp}completionCondition`, lc.completionCondition.attributes, [], lc.completionCondition.text));
185
217
  }
186
218
  children.push(...(lc.unknownChildren ?? []));
187
- return [el(`${bp}:multiInstanceLoopCharacteristics`, attrs, children)];
219
+ return [el(`${bp}multiInstanceLoopCharacteristics`, withUnknown(attrs, lc), children)];
188
220
  }
189
221
  // ---------------------------------------------------------------------------
190
222
  // Flow elements
191
223
  // ---------------------------------------------------------------------------
192
224
  function flowRefs(refs, tag, bp) {
193
- return refs.map((r) => el(`${bp}:${tag}`, {}, [], r));
225
+ return refs.map((r) => el(`${bp}${tag}`, {}, [], r));
194
226
  }
195
227
  function serializeFlowElement(fe, ns) {
196
228
  const bp = bpmnPrefix(ns);
@@ -202,7 +234,7 @@ function serializeFlowElement(fe, ns) {
202
234
  const children = [];
203
235
  // Documentation
204
236
  if (fe.documentation !== undefined) {
205
- children.push(el(`${bp}:documentation`, {}, [], fe.documentation));
237
+ children.push(el(`${bp}documentation`, fe.documentationAttributes ?? {}, [], fe.documentation));
206
238
  }
207
239
  // Extension elements
208
240
  children.push(...serializeExtensionElements(fe.extensionElements, bp));
@@ -259,7 +291,7 @@ function serializeFlowElement(fe, ns) {
259
291
  children.push(...serializeLoopCharacteristics(fe.loopCharacteristics, bp));
260
292
  children.push(...serializeProcessContents(fe, ns));
261
293
  if (fe.completionCondition) {
262
- children.push(el(`${bp}:completionCondition`, fe.completionCondition.attributes, [], fe.completionCondition.text));
294
+ children.push(el(`${bp}completionCondition`, fe.completionCondition.attributes, [], fe.completionCondition.text));
263
295
  }
264
296
  break;
265
297
  case "subProcess":
@@ -305,7 +337,7 @@ function serializeFlowElement(fe, ns) {
305
337
  attrs.dataStoreRef = fe.dataStoreRef;
306
338
  break;
307
339
  }
308
- return el(`${bp}:${fe.type}`, attrs, children);
340
+ return el(`${bp}${fe.type}`, attrs, children);
309
341
  }
310
342
  // ---------------------------------------------------------------------------
311
343
  // Sequence flows
@@ -319,12 +351,12 @@ function serializeSequenceFlow(sf, bp) {
319
351
  };
320
352
  if (sf.name !== undefined)
321
353
  attrs.name = sf.name;
322
- const children = [];
323
- children.push(...serializeExtensionElements(sf.extensionElements, bp));
354
+ const children = serializeBaseChildren(sf, bp);
324
355
  if (sf.conditionExpression) {
325
- children.push(el(`${bp}:conditionExpression`, sf.conditionExpression.attributes, [], sf.conditionExpression.text));
356
+ children.push(el(`${bp}conditionExpression`, sf.conditionExpression.attributes, [], sf.conditionExpression.text));
326
357
  }
327
- return el(`${bp}:sequenceFlow`, attrs, children);
358
+ children.push(...(sf.unknownChildren ?? []));
359
+ return el(`${bp}sequenceFlow`, attrs, children);
328
360
  }
329
361
  // ---------------------------------------------------------------------------
330
362
  // Annotations
@@ -339,16 +371,16 @@ function serializeCategory(category, bp) {
339
371
  const valueAttrs = { id: value.id, ...value.unknownAttributes };
340
372
  if (value.value !== undefined)
341
373
  valueAttrs.value = value.value;
342
- return el(`${bp}:categoryValue`, valueAttrs, []);
374
+ return el(`${bp}categoryValue`, valueAttrs, []);
343
375
  });
344
- return el(`${bp}:category`, attrs, children);
376
+ return el(`${bp}category`, attrs, children);
345
377
  }
346
378
  function serializeTextAnnotation(ta, bp) {
347
379
  const children = serializeBaseChildren(ta, bp);
348
380
  if (ta.text !== undefined) {
349
- children.push(el(`${bp}:text`, {}, [], ta.text));
381
+ children.push(el(`${bp}text`, {}, [], ta.text));
350
382
  }
351
- return el(`${bp}:textAnnotation`, { id: ta.id, ...ta.unknownAttributes }, children);
383
+ return el(`${bp}textAnnotation`, { id: ta.id, ...ta.unknownAttributes }, children);
352
384
  }
353
385
  function serializeAssociation(a, bp) {
354
386
  const attrs = {
@@ -359,13 +391,13 @@ function serializeAssociation(a, bp) {
359
391
  };
360
392
  if (a.associationDirection !== undefined)
361
393
  attrs.associationDirection = a.associationDirection;
362
- return el(`${bp}:association`, attrs, serializeBaseChildren(a, bp));
394
+ return el(`${bp}association`, attrs, serializeBaseChildren(a, bp));
363
395
  }
364
396
  function serializeGroup(g, bp) {
365
397
  const attrs = { id: g.id, ...g.unknownAttributes };
366
398
  if (g.categoryValueRef !== undefined)
367
399
  attrs.categoryValueRef = g.categoryValueRef;
368
- return el(`${bp}:group`, attrs, serializeBaseChildren(g, bp));
400
+ return el(`${bp}group`, attrs, serializeBaseChildren(g, bp));
369
401
  }
370
402
  // ---------------------------------------------------------------------------
371
403
  // Process contents
@@ -399,11 +431,11 @@ function serializeLane(lane, bp) {
399
431
  if (lane.name !== undefined)
400
432
  attrs.name = lane.name;
401
433
  const children = serializeBaseChildren(lane, bp);
402
- children.push(...lane.flowNodeRefs.map((ref) => el(`${bp}:flowNodeRef`, {}, [], ref)));
434
+ children.push(...lane.flowNodeRefs.map((ref) => el(`${bp}flowNodeRef`, {}, [], ref)));
403
435
  if (lane.childLaneSet) {
404
436
  children.push(serializeLaneSet(lane.childLaneSet, bp));
405
437
  }
406
- return el(`${bp}:lane`, attrs, children);
438
+ return el(`${bp}lane`, attrs, children);
407
439
  }
408
440
  function serializeLaneSet(laneSet, bp) {
409
441
  const attrs = { ...laneSet.unknownAttributes };
@@ -411,7 +443,7 @@ function serializeLaneSet(laneSet, bp) {
411
443
  attrs.id = laneSet.id;
412
444
  if (laneSet.name !== undefined)
413
445
  attrs.name = laneSet.name;
414
- return el(`${bp}:laneSet`, attrs, laneSet.lanes.map((l) => serializeLane(l, bp)));
446
+ return el(`${bp}laneSet`, attrs, laneSet.lanes.map((l) => serializeLane(l, bp)));
415
447
  }
416
448
  // ---------------------------------------------------------------------------
417
449
  // Process
@@ -423,13 +455,17 @@ function serializeProcess(process, ns) {
423
455
  attrs.name = process.name;
424
456
  if (process.isExecutable)
425
457
  attrs.isExecutable = "true";
426
- const children = serializeBaseChildren({ documentation: process.documentation, extensionElements: process.extensionElements }, bp);
458
+ const children = serializeBaseChildren({
459
+ documentation: process.documentation,
460
+ documentationAttributes: process.documentationAttributes,
461
+ extensionElements: process.extensionElements,
462
+ }, bp);
427
463
  if (process.laneSet) {
428
464
  children.push(serializeLaneSet(process.laneSet, bp));
429
465
  }
430
466
  children.push(...serializeProcessContents(process, ns));
431
467
  children.push(...(process.unknownChildren ?? []));
432
- return el(`${bp}:process`, attrs, children);
468
+ return el(`${bp}process`, attrs, children);
433
469
  }
434
470
  // ---------------------------------------------------------------------------
435
471
  // Collaboration
@@ -440,7 +476,7 @@ function serializeParticipant(p, bp) {
440
476
  attrs.name = p.name;
441
477
  if (p.processRef !== undefined)
442
478
  attrs.processRef = p.processRef;
443
- return el(`${bp}:participant`, attrs, serializeBaseChildren(p, bp));
479
+ return el(`${bp}participant`, attrs, serializeBaseChildren(p, bp));
444
480
  }
445
481
  function serializeMessageFlow(mf, bp) {
446
482
  const attrs = {
@@ -453,7 +489,7 @@ function serializeMessageFlow(mf, bp) {
453
489
  attrs.name = mf.name;
454
490
  if (mf.messageRef !== undefined)
455
491
  attrs.messageRef = mf.messageRef;
456
- return el(`${bp}:messageFlow`, attrs, serializeBaseChildren(mf, bp));
492
+ return el(`${bp}messageFlow`, attrs, serializeBaseChildren(mf, bp));
457
493
  }
458
494
  function serializeCollaboration(c, ns) {
459
495
  const bp = bpmnPrefix(ns);
@@ -474,7 +510,10 @@ function serializeCollaboration(c, ns) {
474
510
  children.push(serializeGroup(g, bp));
475
511
  }
476
512
  children.push(...(c.unknownChildren ?? []));
477
- return el(`${bp}:collaboration`, { id: c.id, ...c.unknownAttributes }, children);
513
+ const attrs = { id: c.id, ...c.unknownAttributes };
514
+ if (c.name !== undefined)
515
+ attrs.name = c.name;
516
+ return el(`${bp}collaboration`, attrs, children);
478
517
  }
479
518
  // ---------------------------------------------------------------------------
480
519
  // Root elements
@@ -485,7 +524,7 @@ function serializeError(e, bp) {
485
524
  attrs.name = e.name;
486
525
  if (e.errorCode !== undefined)
487
526
  attrs.errorCode = e.errorCode;
488
- return el(`${bp}:error`, { ...e.unknownAttributes, ...attrs }, serializeBaseChildren(e, bp));
527
+ return el(`${bp}error`, { ...e.unknownAttributes, ...attrs }, serializeBaseChildren(e, bp));
489
528
  }
490
529
  function serializeEscalation(e, bp) {
491
530
  const attrs = { id: e.id };
@@ -493,27 +532,26 @@ function serializeEscalation(e, bp) {
493
532
  attrs.name = e.name;
494
533
  if (e.escalationCode !== undefined)
495
534
  attrs.escalationCode = e.escalationCode;
496
- return el(`${bp}:escalation`, { ...e.unknownAttributes, ...attrs }, serializeBaseChildren(e, bp));
535
+ return el(`${bp}escalation`, { ...e.unknownAttributes, ...attrs }, serializeBaseChildren(e, bp));
497
536
  }
498
537
  function serializeMessage(m, bp) {
499
538
  const attrs = { id: m.id, ...m.unknownAttributes };
500
539
  if (m.name !== undefined)
501
540
  attrs.name = m.name;
502
- return el(`${bp}:message`, attrs, serializeBaseChildren(m, bp));
541
+ return el(`${bp}message`, attrs, serializeBaseChildren(m, bp));
503
542
  }
504
543
  function serializeSignal(s, bp) {
505
544
  const attrs = { id: s.id };
506
545
  if (s.name !== undefined)
507
546
  attrs.name = s.name;
508
- return el(`${bp}:signal`, { ...s.unknownAttributes, ...attrs }, serializeBaseChildren(s, bp));
547
+ return el(`${bp}signal`, { ...s.unknownAttributes, ...attrs }, serializeBaseChildren(s, bp));
509
548
  }
510
549
  // ---------------------------------------------------------------------------
511
550
  // Diagram interchange
512
551
  // ---------------------------------------------------------------------------
513
552
  function serializeDiShape(shape, bdi, dc) {
514
553
  const attrs = {
515
- id: shape.id,
516
- bpmnElement: shape.bpmnElement,
554
+ ...diRefs(shape.id, shape.bpmnElement),
517
555
  ...shape.unknownAttributes,
518
556
  };
519
557
  if (shape.isMarkerVisible !== undefined)
@@ -523,7 +561,7 @@ function serializeDiShape(shape, bdi, dc) {
523
561
  if (shape.isHorizontal !== undefined)
524
562
  attrs.isHorizontal = String(shape.isHorizontal);
525
563
  const children = [
526
- el(`${dc}:Bounds`, {
564
+ el(`${dc}Bounds`, {
527
565
  x: String(shape.bounds.x),
528
566
  y: String(shape.bounds.y),
529
567
  width: String(shape.bounds.width),
@@ -533,37 +571,48 @@ function serializeDiShape(shape, bdi, dc) {
533
571
  if (shape.label) {
534
572
  const labelChildren = [];
535
573
  if (shape.label.bounds) {
536
- labelChildren.push(el(`${dc}:Bounds`, {
574
+ labelChildren.push(el(`${dc}Bounds`, {
537
575
  x: String(shape.label.bounds.x),
538
576
  y: String(shape.label.bounds.y),
539
577
  width: String(shape.label.bounds.width),
540
578
  height: String(shape.label.bounds.height),
541
579
  }, []));
542
580
  }
543
- children.push(el(`${bdi}:BPMNLabel`, {}, labelChildren));
581
+ children.push(el(`${bdi}BPMNLabel`, shape.label.unknownAttributes ?? {}, labelChildren));
544
582
  }
545
- return el(`${bdi}:BPMNShape`, attrs, children);
583
+ return el(`${bdi}BPMNShape`, attrs, children);
546
584
  }
547
585
  function serializeDiEdge(edge, bdi, dc, dip) {
548
586
  const attrs = {
549
- id: edge.id,
550
- bpmnElement: edge.bpmnElement,
587
+ ...diRefs(edge.id, edge.bpmnElement),
551
588
  ...edge.unknownAttributes,
552
589
  };
553
- const children = edge.waypoints.map((w) => el(`${dip}:waypoint`, { x: String(w.x), y: String(w.y) }, []));
590
+ const children = edge.waypoints.map((w) => el(`${dip}waypoint`, { ...w.unknownAttributes, x: String(w.x), y: String(w.y) }, []));
554
591
  if (edge.label) {
555
592
  const labelChildren = [];
556
593
  if (edge.label.bounds) {
557
- labelChildren.push(el(`${dc}:Bounds`, {
594
+ labelChildren.push(el(`${dc}Bounds`, {
558
595
  x: String(edge.label.bounds.x),
559
596
  y: String(edge.label.bounds.y),
560
597
  width: String(edge.label.bounds.width),
561
598
  height: String(edge.label.bounds.height),
562
599
  }, []));
563
600
  }
564
- children.push(el(`${bdi}:BPMNLabel`, {}, labelChildren));
601
+ children.push(el(`${bdi}BPMNLabel`, edge.label.unknownAttributes ?? {}, labelChildren));
565
602
  }
566
- return el(`${bdi}:BPMNEdge`, attrs, children);
603
+ return el(`${bdi}BPMNEdge`, attrs, children);
604
+ }
605
+ /**
606
+ * The `id` / `bpmnElement` pair of a DI element, leaving out the ones the model holds
607
+ * as `""` — BPMN DI makes both optional, and the parser reads an absent one as empty.
608
+ */
609
+ function diRefs(id, bpmnElement) {
610
+ const refs = {};
611
+ if (id !== "")
612
+ refs.id = id;
613
+ if (bpmnElement !== "")
614
+ refs.bpmnElement = bpmnElement;
615
+ return refs;
567
616
  }
568
617
  function serializeDiagram(diagram, ns) {
569
618
  const bdi = bpmndiPrefix(ns);
@@ -576,11 +625,11 @@ function serializeDiagram(diagram, ns) {
576
625
  for (const e of diagram.plane.edges) {
577
626
  planeChildren.push(serializeDiEdge(e, bdi, dc, dip));
578
627
  }
579
- const plane = el(`${bdi}:BPMNPlane`, {
580
- id: diagram.plane.id,
581
- bpmnElement: diagram.plane.bpmnElement,
582
- }, planeChildren);
583
- return el(`${bdi}:BPMNDiagram`, { id: diagram.id }, [plane]);
628
+ const plane = el(`${bdi}BPMNPlane`, { ...diRefs(diagram.plane.id, diagram.plane.bpmnElement), ...diagram.plane.unknownAttributes }, planeChildren);
629
+ return el(`${bdi}BPMNDiagram`, { ...diRefs(diagram.id, ""), ...diagram.unknownAttributes }, [
630
+ plane,
631
+ ...(diagram.unknownChildren ?? []),
632
+ ]);
584
633
  }
585
634
  // ---------------------------------------------------------------------------
586
635
  // Public API
@@ -611,7 +660,7 @@ export function serializeBpmn(definitions) {
611
660
  }
612
661
  const children = [];
613
662
  if (definitions.documentation !== undefined) {
614
- children.push(el(`${bp}:documentation`, {}, [], definitions.documentation));
663
+ children.push(el(`${bp}documentation`, definitions.documentationAttributes ?? {}, [], definitions.documentation));
615
664
  }
616
665
  // Categories supply the labels groups reference
617
666
  for (const category of definitions.categories ?? []) {
@@ -646,7 +695,7 @@ export function serializeBpmn(definitions) {
646
695
  for (const d of definitions.diagrams) {
647
696
  children.push(serializeDiagram(d, ns));
648
697
  }
649
- const root = el(`${bp}:definitions`, attrs, children);
698
+ const root = el(`${bp}definitions`, attrs, children);
650
699
  declareUsedNamespaces(root, attrs);
651
700
  return serializeXml(root);
652
701
  }
@@ -0,0 +1,153 @@
1
+ /**
2
+ * `.bpmnlintrc` compatibility — reading a bpmnlint configuration and applying
3
+ * it to BPMN Kit's own findings.
4
+ *
5
+ * Teams coming from bpmn.io keep their lint configuration in a `.bpmnlintrc`.
6
+ * This module reads that file's JSON, expands bpmnlint's built-in presets, and
7
+ * maps each bpmnlint rule onto the BPMN Kit findings that report the same
8
+ * problem, so the file's `off`/`warn`/`error`/`info` settings govern those
9
+ * findings. Rules BPMN Kit had no finding for, and the parts of rules its
10
+ * findings do not cover exactly, are implemented natively in
11
+ * `optimize/bpmnlint-rules.ts` and only run when the config enables them.
12
+ *
13
+ * Pure and dependency-free: nothing here touches the filesystem or loads
14
+ * bpmnlint itself. Finding the file and running real bpmnlint (for
15
+ * third-party `bpmnlint-plugin-*` rules) is `@bpmnkit/core/node`'s job.
16
+ *
17
+ * @packageDocumentation
18
+ */
19
+ import type { BpmnDefinitions } from "./bpmn-model.js";
20
+ import type { OptimizationCategory, OptimizationFinding } from "./optimize/types.js";
21
+ /** A rule's reporting level. bpmnlint also accepts `0`–`3` for these, in this order. */
22
+ export type BpmnlintSeverity = "off" | "warn" | "error" | "info";
23
+ /** A rule's setting as written in `.bpmnlintrc`: a level, or `[level, options]`. */
24
+ export type BpmnlintRuleValue = BpmnlintSeverity | 0 | 1 | 2 | 3 | readonly [BpmnlintSeverity | 0 | 1 | 2 | 3, unknown?];
25
+ /** The contents of a `.bpmnlintrc` file. */
26
+ export interface BpmnlintConfig {
27
+ extends?: string | string[];
28
+ rules?: Record<string, BpmnlintRuleValue>;
29
+ /** Moddle extension descriptors, by prefix. Only real bpmnlint uses these. */
30
+ moddleExtensions?: Record<string, string>;
31
+ }
32
+ /** One rule's effective setting after presets and overrides are merged. */
33
+ export interface BpmnlintRuleSetting {
34
+ severity: BpmnlintSeverity;
35
+ /** The second element of an `[level, options]` setting, when there was one. */
36
+ options?: unknown;
37
+ }
38
+ /** A `.bpmnlintrc` with its presets expanded and its rule names normalised. */
39
+ export interface ResolvedBpmnlintConfig {
40
+ /** Rule name (`label-required`, `camunda-compat/timer`, …) → effective setting. */
41
+ rules: Record<string, BpmnlintRuleSetting>;
42
+ /**
43
+ * `extends` entries this module could not expand — plugin configs
44
+ * (`plugin:<name>/<config>`) live in npm packages, which only real bpmnlint
45
+ * can load. Their rules are therefore unknown here.
46
+ */
47
+ unresolvedExtends: string[];
48
+ }
49
+ /**
50
+ * Parses the text of a `.bpmnlintrc` file.
51
+ *
52
+ * @param text - The file's contents (JSON).
53
+ * @throws When the text is not JSON or does not have the shape bpmnlint expects.
54
+ */
55
+ export declare function parseBpmnlintConfig(text: string): BpmnlintConfig;
56
+ /**
57
+ * Normalises a rule name the way bpmnlint does, so the same rule written two
58
+ * ways is one rule: `bpmnlint/label-required` → `label-required`,
59
+ * `bpmnlint-plugin-foo/bar` → `foo/bar`, `@scope/bpmnlint-plugin-foo/bar` →
60
+ * `@scope/foo/bar`.
61
+ *
62
+ * @param name - The rule name as written in the config.
63
+ */
64
+ export declare function normalizeBpmnlintRuleName(name: string): string;
65
+ /**
66
+ * Expands a config's `extends` and merges its rules into one effective setting
67
+ * per rule. Later entries win, and the file's own `rules` win over everything
68
+ * it extends — the order bpmnlint applies.
69
+ *
70
+ * `bpmnlint:recommended`, `bpmnlint:all` and `bpmnlint:correctness` expand to
71
+ * bpmnlint 11.14's presets. Plugin configs cannot be expanded without loading
72
+ * the plugin and are listed in `unresolvedExtends` instead.
73
+ *
74
+ * @param config - A parsed `.bpmnlintrc`.
75
+ */
76
+ export declare function resolveBpmnlintConfig(config: BpmnlintConfig): ResolvedBpmnlintConfig;
77
+ /** How faithfully BPMN Kit reproduces a bpmnlint rule. */
78
+ export type BpmnlintMatch = "exact" | "approximate";
79
+ export interface BpmnlintRuleMapping {
80
+ /** The BPMN Kit finding ids that report this rule's problem. */
81
+ findings: readonly string[];
82
+ match: BpmnlintMatch;
83
+ /** Where the two differ, for `approximate`. */
84
+ note?: string;
85
+ /**
86
+ * BPMN Kit's own findings for the same concern whose semantics differ from
87
+ * the rule's. While a config sets the rule, at any level, they are dropped
88
+ * and the native finding in `findings` reports the rule instead. Without a
89
+ * config they are reported as usual.
90
+ */
91
+ replaces?: readonly string[];
92
+ }
93
+ /**
94
+ * Every bpmnlint built-in rule and the BPMN Kit findings standing in for it.
95
+ *
96
+ * The documentation table (`guides/bpmnlint`) is written from this — keep them
97
+ * in step.
98
+ */
99
+ export declare const BPMNLINT_RULE_MAP: Readonly<Record<string, BpmnlintRuleMapping>>;
100
+ /**
101
+ * The bpmnlint rule a BPMN Kit finding stands in for, if any.
102
+ *
103
+ * @param findingId - A finding id such as `flow/mixed-gateway`.
104
+ */
105
+ export declare function bpmnlintRuleForFinding(findingId: string): string | undefined;
106
+ /** A configured rule, or `extends` entry, BPMN Kit could not honour. */
107
+ export interface UnsupportedBpmnlintRule {
108
+ /** The rule name, or the `extends` entry. */
109
+ name: string;
110
+ reason: "plugin-rule" | "unknown-rule" | "unresolved-extends";
111
+ /** The configured severity, for a rule. */
112
+ severity?: BpmnlintSeverity;
113
+ }
114
+ export interface ApplyBpmnlintOptions {
115
+ /**
116
+ * Real bpmnlint ran the configured rules itself, so BPMN Kit must not report
117
+ * them a second time: findings mapped to a configured rule are dropped and
118
+ * no native equivalents run. Rules the config leaves out are untouched.
119
+ */
120
+ delegated?: boolean;
121
+ /** Restrict native equivalents to these categories (mirrors `--categories`). */
122
+ categories?: readonly OptimizationCategory[];
123
+ }
124
+ export interface BpmnlintApplication {
125
+ /** The findings with the config applied: re-levelled, dropped or added. */
126
+ findings: OptimizationFinding[];
127
+ /** What the config asked for that BPMN Kit could not do. Empty when delegated. */
128
+ unsupported: UnsupportedBpmnlintRule[];
129
+ }
130
+ /**
131
+ * Applies a `.bpmnlintrc` to a set of BPMN Kit findings.
132
+ *
133
+ * - A finding that stands in for a configured rule takes that rule's
134
+ * severity, or is dropped when the rule is `off`, and carries the rule name
135
+ * in `bpmnlintRule`.
136
+ * - A finding a configured rule `replaces` is dropped: the rule's native
137
+ * finding reports the concern with bpmnlint's semantics instead.
138
+ * - Enabled rules BPMN Kit implements natively are run and their findings
139
+ * added.
140
+ * - Findings with no bpmnlint counterpart, and findings whose rule the config
141
+ * does not mention, keep BPMN Kit's defaults: the config overrides BPMN
142
+ * Kit's opinion where it has one, it does not switch BPMN Kit's other rules
143
+ * off.
144
+ * - Configured rules with no equivalent are returned in `unsupported`, never
145
+ * silently ignored.
146
+ *
147
+ * @param definitions - The model the findings were produced from.
148
+ * @param findings - Output of `optimize()` (or a filtered subset of it).
149
+ * @param config - A resolved `.bpmnlintrc`.
150
+ * @param options - See {@link ApplyBpmnlintOptions}.
151
+ */
152
+ export declare function applyBpmnlintConfig(definitions: BpmnDefinitions, findings: readonly OptimizationFinding[], config: ResolvedBpmnlintConfig, options?: ApplyBpmnlintOptions): BpmnlintApplication;
153
+ //# sourceMappingURL=bpmnlint.d.ts.map