@bpmnkit/core 1.0.0 → 1.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 (64) hide show
  1. package/README.md +25 -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/full-operations.js +5 -2
  21. package/dist/bpmn/label-style.d.ts +51 -0
  22. package/dist/bpmn/label-style.js +116 -0
  23. package/dist/bpmn/lint.d.ts +23 -3
  24. package/dist/bpmn/lint.js +47 -10
  25. package/dist/bpmn/optimize/bpmnlint-rules.d.ts +31 -0
  26. package/dist/bpmn/optimize/bpmnlint-rules.js +916 -0
  27. package/dist/bpmn/optimize/deploy.d.ts +8 -2
  28. package/dist/bpmn/optimize/deploy.js +16 -3
  29. package/dist/bpmn/optimize/index.js +11 -2
  30. package/dist/bpmn/optimize/types.d.ts +14 -0
  31. package/dist/bpmn/optimize/variable-flow.js +4 -1
  32. package/dist/bpmn/process-types.d.ts +112 -0
  33. package/dist/bpmn/process-types.js +490 -0
  34. package/dist/bpmn/svg.js +51 -22
  35. package/dist/doc/docx.d.ts +20 -0
  36. package/dist/doc/docx.js +253 -0
  37. package/dist/doc/html.d.ts +21 -0
  38. package/dist/doc/html.js +303 -0
  39. package/dist/doc/index.d.ts +7 -0
  40. package/dist/doc/index.js +5 -0
  41. package/dist/doc/markdown.d.ts +11 -0
  42. package/dist/doc/markdown.js +160 -0
  43. package/dist/doc/model.d.ts +129 -0
  44. package/dist/doc/model.js +617 -0
  45. package/dist/doc/zip.d.ts +5 -0
  46. package/dist/doc/zip.js +75 -0
  47. package/dist/index.d.ts +16 -0
  48. package/dist/index.js +8 -0
  49. package/dist/layout/annotations.d.ts +4 -2
  50. package/dist/layout/annotations.js +31 -2
  51. package/dist/layout/collaboration/ordering.d.ts +8 -0
  52. package/dist/layout/collaboration/ordering.js +57 -18
  53. package/dist/layout/orthogonal.d.ts +32 -0
  54. package/dist/layout/orthogonal.js +367 -0
  55. package/dist/layout/repair.d.ts +31 -0
  56. package/dist/layout/repair.js +220 -0
  57. package/dist/layout/semantic/route.js +45 -3
  58. package/dist/node/bpmnlint.d.ts +109 -0
  59. package/dist/node/bpmnlint.js +198 -0
  60. package/dist/node/index.d.ts +2 -0
  61. package/dist/node/index.js +1 -0
  62. package/dist/xml/xml-patch.d.ts +21 -0
  63. package/dist/xml/xml-patch.js +27 -1
  64. package/package.json +2 -2
@@ -468,8 +468,11 @@ function operationsForCompact(definitions, compact) {
468
468
  replacedFlows.add(flow.id);
469
469
  continue;
470
470
  }
471
- const sameLabel = (want.name ?? undefined) === (flow.name ?? undefined);
472
- const sameCondition = (want.condition ?? undefined) === (flow.conditionExpression?.text ?? undefined);
471
+ // An empty label or condition is the same as none: the compact view omits
472
+ // both, and treating "" as a change would delete and re-add the flow,
473
+ // taking its extensions and condition attributes with it.
474
+ const sameLabel = (want.name || undefined) === (flow.name || undefined);
475
+ const sameCondition = (want.condition || undefined) === (flow.conditionExpression?.text || undefined);
473
476
  if (!sameLabel || !sameCondition) {
474
477
  operations.push({ op: "delete_flow", id: flow.id });
475
478
  replacedFlows.add(flow.id);
@@ -0,0 +1,51 @@
1
+ import type { BpmnDefinitions, BpmnDiLabel } from "./bpmn-model.js";
2
+ /**
3
+ * The `dc:Font` of a `bpmndi:BPMNLabelStyle`. Every field is optional: an
4
+ * attribute the file omits (or carries an unusable value for) is left unset,
5
+ * and the renderer's default applies to it.
6
+ */
7
+ export interface BpmnLabelFont {
8
+ /** Font family (`name`), as written — may be a comma-separated list. */
9
+ name?: string;
10
+ /** Font size (`size`), drawn as CSS pixels — DI coordinates are pixels. */
11
+ size?: number;
12
+ isBold?: boolean;
13
+ isItalic?: boolean;
14
+ isUnderline?: boolean;
15
+ isStrikeThrough?: boolean;
16
+ }
17
+ /** CSS values for a resolved label font, ready for inline styles or `ctx.font`. */
18
+ export interface LabelFontCss {
19
+ fontFamily: string;
20
+ /** In px. */
21
+ fontSize: number;
22
+ fontWeight: "normal" | "bold";
23
+ fontStyle: "normal" | "italic";
24
+ /** `"none"`, or `underline` / `line-through` / both. */
25
+ textDecoration: string;
26
+ }
27
+ /**
28
+ * Indexes every `bpmndi:BPMNLabelStyle` in the document by id.
29
+ *
30
+ * Styles are owned by a `BPMNDiagram`, but a label's `labelStyle` is an id
31
+ * reference, and ids are document-unique — so all diagrams are indexed and a
32
+ * label may use a style defined under another diagram.
33
+ */
34
+ export declare function collectLabelStyles(defs: BpmnDefinitions): Map<string, BpmnLabelFont>;
35
+ /**
36
+ * The font a DI label is drawn in: the style its `labelStyle` attribute
37
+ * references, or `undefined` for the renderer default.
38
+ *
39
+ * BPMN DI has no default label style on the diagram or plane and no
40
+ * inheritance between labels, so a label without a (resolvable) `labelStyle`
41
+ * gets the default. `labelStyle` is typed `xsd:QName`, so a prefixed value
42
+ * (`di:LS1`) falls back to its local part.
43
+ */
44
+ export declare function resolveLabelFont(label: BpmnDiLabel | undefined, styles: ReadonlyMap<string, BpmnLabelFont>): BpmnLabelFont | undefined;
45
+ /**
46
+ * Converts a label font into CSS values. Missing fields take the defaults
47
+ * given; the file's family (each entry of a comma-separated `name`, quoted)
48
+ * goes in front of `defaultFamily`, which stays as the fallback stack.
49
+ */
50
+ export declare function labelFontCss(font: BpmnLabelFont | undefined, defaultFamily: string, defaultSize: number): LabelFontCss;
51
+ //# sourceMappingURL=label-style.d.ts.map
@@ -0,0 +1,116 @@
1
+ const localName = (name) => name.slice(name.indexOf(":") + 1);
2
+ function parseBool(v) {
3
+ if (v === "true" || v === "1")
4
+ return true;
5
+ if (v === "false" || v === "0")
6
+ return false;
7
+ return undefined;
8
+ }
9
+ function parseFont(style) {
10
+ const font = style.children.find((c) => localName(c.name) === "Font");
11
+ if (!font)
12
+ return {};
13
+ const a = font.attributes;
14
+ const out = {};
15
+ const name = a.name?.trim();
16
+ if (name)
17
+ out.name = name;
18
+ const size = a.size === undefined ? Number.NaN : Number(a.size);
19
+ if (Number.isFinite(size) && size > 0)
20
+ out.size = size;
21
+ const bold = parseBool(a.isBold);
22
+ if (bold !== undefined)
23
+ out.isBold = bold;
24
+ const italic = parseBool(a.isItalic);
25
+ if (italic !== undefined)
26
+ out.isItalic = italic;
27
+ const underline = parseBool(a.isUnderline);
28
+ if (underline !== undefined)
29
+ out.isUnderline = underline;
30
+ const strike = parseBool(a.isStrikeThrough);
31
+ if (strike !== undefined)
32
+ out.isStrikeThrough = strike;
33
+ return out;
34
+ }
35
+ /**
36
+ * Indexes every `bpmndi:BPMNLabelStyle` in the document by id.
37
+ *
38
+ * Styles are owned by a `BPMNDiagram`, but a label's `labelStyle` is an id
39
+ * reference, and ids are document-unique — so all diagrams are indexed and a
40
+ * label may use a style defined under another diagram.
41
+ */
42
+ export function collectLabelStyles(defs) {
43
+ const styles = new Map();
44
+ for (const diagram of defs.diagrams) {
45
+ for (const child of diagram.unknownChildren ?? []) {
46
+ if (localName(child.name) !== "BPMNLabelStyle")
47
+ continue;
48
+ const id = child.attributes.id;
49
+ if (id)
50
+ styles.set(id, parseFont(child));
51
+ }
52
+ }
53
+ return styles;
54
+ }
55
+ /**
56
+ * The font a DI label is drawn in: the style its `labelStyle` attribute
57
+ * references, or `undefined` for the renderer default.
58
+ *
59
+ * BPMN DI has no default label style on the diagram or plane and no
60
+ * inheritance between labels, so a label without a (resolvable) `labelStyle`
61
+ * gets the default. `labelStyle` is typed `xsd:QName`, so a prefixed value
62
+ * (`di:LS1`) falls back to its local part.
63
+ */
64
+ export function resolveLabelFont(label, styles) {
65
+ const ref = label?.unknownAttributes?.labelStyle?.trim();
66
+ if (!ref)
67
+ return undefined;
68
+ return styles.get(ref) ?? styles.get(localName(ref));
69
+ }
70
+ const GENERIC_FAMILIES = new Set([
71
+ "serif",
72
+ "sans-serif",
73
+ "monospace",
74
+ "cursive",
75
+ "fantasy",
76
+ "system-ui",
77
+ "ui-serif",
78
+ "ui-sans-serif",
79
+ "ui-monospace",
80
+ "ui-rounded",
81
+ "math",
82
+ "emoji",
83
+ "fangsong",
84
+ ]);
85
+ /** Quotes one family name as a CSS string; generic keywords stay bare. */
86
+ function cssFamily(family) {
87
+ if (GENERIC_FAMILIES.has(family.toLowerCase()))
88
+ return family.toLowerCase();
89
+ const escaped = family.replace(/[\\"]/g, "\\$&").replace(/[\n\r\f]/g, " ");
90
+ return `"${escaped}"`;
91
+ }
92
+ /**
93
+ * Converts a label font into CSS values. Missing fields take the defaults
94
+ * given; the file's family (each entry of a comma-separated `name`, quoted)
95
+ * goes in front of `defaultFamily`, which stays as the fallback stack.
96
+ */
97
+ export function labelFontCss(font, defaultFamily, defaultSize) {
98
+ const families = (font?.name ?? "")
99
+ .split(",")
100
+ .map((f) => f.trim().replace(/^(["'])(.*)\1$/, "$2"))
101
+ .filter((f) => f.length > 0)
102
+ .map(cssFamily);
103
+ const decorations = [];
104
+ if (font?.isUnderline)
105
+ decorations.push("underline");
106
+ if (font?.isStrikeThrough)
107
+ decorations.push("line-through");
108
+ return {
109
+ fontFamily: [...families, defaultFamily].join(", "),
110
+ fontSize: font?.size ?? defaultSize,
111
+ fontWeight: font?.isBold ? "bold" : "normal",
112
+ fontStyle: font?.isItalic ? "italic" : "normal",
113
+ textDecoration: decorations.length > 0 ? decorations.join(" ") : "none",
114
+ };
115
+ }
116
+ //# sourceMappingURL=label-style.js.map
@@ -1,4 +1,5 @@
1
1
  import type { BpmnDefinitions } from "./bpmn-model.js";
2
+ import { type ResolvedBpmnlintConfig, type UnsupportedBpmnlintRule } from "./bpmnlint.js";
2
3
  import type { OptimizationCategory, OptimizationSeverity, OptimizeOptions } from "./optimize/types.js";
3
4
  /**
4
5
  * The engine a model says it targets, read from `modeler:executionPlatform`.
@@ -31,6 +32,8 @@ export interface LintDiagnostic {
31
32
  plane?: string;
32
33
  /** Whether the live report carries an automatic fix for this finding. */
33
34
  fixable: boolean;
35
+ /** The bpmnlint rule it was reported under, when a `.bpmnlintrc` governs it. */
36
+ bpmnlintRule?: string;
34
37
  }
35
38
  export interface LintReport {
36
39
  diagnostics: LintDiagnostic[];
@@ -40,6 +43,11 @@ export interface LintReport {
40
43
  categories: OptimizationCategory[];
41
44
  counts: Record<OptimizationSeverity, number>;
42
45
  total: number;
46
+ /**
47
+ * Present when a `.bpmnlintrc` was applied: the configured rules (or
48
+ * `extends` entries) BPMN Kit has no equivalent for.
49
+ */
50
+ bpmnlintUnsupported?: UnsupportedBpmnlintRule[];
43
51
  }
44
52
  export interface LintOptions extends OptimizeOptions {
45
53
  /**
@@ -47,6 +55,17 @@ export interface LintOptions extends OptimizeOptions {
47
55
  * an engine-neutral diagram should not be told it is undeployable.
48
56
  */
49
57
  forceEngineRules?: boolean;
58
+ /**
59
+ * A resolved `.bpmnlintrc` to apply — see `applyBpmnlintConfig`. Its
60
+ * severities govern the findings that stand in for bpmnlint rules, and the
61
+ * native equivalents of the rules it enables are run.
62
+ */
63
+ bpmnlint?: ResolvedBpmnlintConfig;
64
+ /**
65
+ * Real bpmnlint already reported the configured rules; drop BPMN Kit's
66
+ * equivalents instead of re-levelling them. Only meaningful with `bpmnlint`.
67
+ */
68
+ bpmnlintDelegated?: boolean;
50
69
  }
51
70
  /**
52
71
  * Reads the execution platform a model declares.
@@ -90,8 +109,9 @@ export declare function lintDiagram(definitions: BpmnDefinitions, options?: Lint
90
109
  * that `LintDiagnostic` deliberately drops. Both ask here which rules apply.
91
110
  *
92
111
  * @param definitions - The model whose execution platform decides.
93
- * @param options - `categories` to narrow to, and `forceEngineRules` to keep
94
- * the engine layer on a model that names no platform.
112
+ * @param options - `categories` to narrow to, `forceEngineRules` to keep the
113
+ * engine layer on a model that names no platform, and `camundaVersion` — a
114
+ * version a `.bpmnlintrc` pins — to keep `compat` on such a model.
95
115
  */
96
- export declare function lintCategories(definitions: BpmnDefinitions, options?: Pick<LintOptions, "categories" | "forceEngineRules">): OptimizationCategory[];
116
+ export declare function lintCategories(definitions: BpmnDefinitions, options?: Pick<LintOptions, "categories" | "forceEngineRules" | "camundaVersion">): OptimizationCategory[];
97
117
  //# sourceMappingURL=lint.d.ts.map
package/dist/bpmn/lint.js CHANGED
@@ -1,3 +1,5 @@
1
+ import { applyBpmnlintConfig, } from "./bpmnlint.js";
2
+ import { applyCamundaCompatConfig, dedupeCamundaCompat, isCamundaCompatFinding, splitCamundaCompatConfig, } from "./camunda-compat.js";
1
3
  import { optimize } from "./optimize/index.js";
2
4
  /**
3
5
  * Categories whose findings only mean something against a Camunda 8 engine.
@@ -6,8 +8,8 @@ import { optimize } from "./optimize/index.js";
6
8
  * Zeebe extensions, every other category either stays quiet or reports
7
9
  * something structural that holds regardless, while `deploy` reports
8
10
  * "serviceTask has no zeebe:taskDefinition type" as an **error** — a demand the
9
- * author never signed up for. `connector` and `agentic` are the same kind of
10
- * claim about the same engine.
11
+ * author never signed up for. `connector` and `agentic` (and the `compat/…` findings `deploy` carries) are the same
12
+ * kind of claim about the same engine.
11
13
  */
12
14
  const ENGINE_CATEGORIES = ["deploy", "connector", "agentic"];
13
15
  /**
@@ -69,12 +71,35 @@ function planeIndex(definitions) {
69
71
  export function lintDiagram(definitions, options = {}) {
70
72
  const platform = detectExecutionPlatform(definitions);
71
73
  const engineRules = options.forceEngineRules === true || platform.id !== "none";
72
- const { forceEngineRules: _ignored, ...optimizeOptions } = options;
73
- const report = optimize(definitions, optimizeOptions);
74
+ const { forceEngineRules: _ignored, bpmnlint, bpmnlintDelegated, ...optimizeOptions } = options;
75
+ // A `.bpmnlintrc` extending `plugin:camunda-compat/camunda-cloud-X-Y`, or an
76
+ // explicit `camundaVersion`, pins the version the `compat/…` findings check —
77
+ // even on a model that names no platform.
78
+ const split = bpmnlint === undefined ? undefined : splitCamundaCompatConfig(bpmnlint);
79
+ const pinned = split?.compat?.version ?? optimizeOptions.camundaVersion;
80
+ const report = optimize(definitions, {
81
+ ...optimizeOptions,
82
+ ...(pinned !== undefined ? { camundaVersion: pinned } : {}),
83
+ });
74
84
  const requested = optimizeOptions.categories;
75
- const findings = engineRules
85
+ const engineFiltered = engineRules
76
86
  ? report.findings
77
- : report.findings.filter((f) => !ENGINE_CATEGORIES.includes(f.category));
87
+ : report.findings.filter((f) => !ENGINE_CATEGORIES.includes(f.category) ||
88
+ (isCamundaCompatFinding(f) && pinned !== undefined));
89
+ const compat = split?.compat === undefined
90
+ ? undefined
91
+ : applyCamundaCompatConfig(engineFiltered, split.compat, {
92
+ delegated: bpmnlintDelegated === true,
93
+ });
94
+ const applied = split === undefined
95
+ ? undefined
96
+ : applyBpmnlintConfig(definitions, compat?.findings ?? engineFiltered, split.rest, {
97
+ delegated: bpmnlintDelegated === true,
98
+ ...(requested !== undefined ? { categories: requested } : {}),
99
+ });
100
+ // bpmnlint's own rules run last, so a compatibility finding one of them now
101
+ // reports on the same element (`link-event`) is dropped here.
102
+ const findings = applied === undefined ? engineFiltered : dedupeCamundaCompat(applied.findings);
78
103
  const planes = planeIndex(definitions);
79
104
  const diagnostics = findings.map((finding) => {
80
105
  const plane = finding.elementIds.map((id) => planes.get(id)).find((p) => p !== undefined);
@@ -87,6 +112,7 @@ export function lintDiagram(definitions, options = {}) {
87
112
  processId: finding.processId,
88
113
  elementIds: finding.elementIds,
89
114
  fixable: finding.applyFix !== undefined,
115
+ ...(finding.bpmnlintRule !== undefined ? { bpmnlintRule: finding.bpmnlintRule } : {}),
90
116
  };
91
117
  return plane === undefined ? base : { ...base, plane };
92
118
  });
@@ -96,9 +122,15 @@ export function lintDiagram(definitions, options = {}) {
96
122
  return {
97
123
  diagnostics,
98
124
  platform,
99
- categories: lintCategories(definitions, options),
125
+ categories: lintCategories(definitions, {
126
+ ...options,
127
+ ...(pinned !== undefined ? { camundaVersion: pinned } : {}),
128
+ }),
100
129
  counts,
101
130
  total: diagnostics.length,
131
+ ...(applied !== undefined
132
+ ? { bpmnlintUnsupported: [...applied.unsupported, ...(compat?.unsupported ?? [])] }
133
+ : {}),
102
134
  };
103
135
  }
104
136
  /** Every category the optimizer knows, in the order it runs them. */
@@ -124,12 +156,17 @@ const ALL_CATEGORIES = [
124
156
  * that `LintDiagnostic` deliberately drops. Both ask here which rules apply.
125
157
  *
126
158
  * @param definitions - The model whose execution platform decides.
127
- * @param options - `categories` to narrow to, and `forceEngineRules` to keep
128
- * the engine layer on a model that names no platform.
159
+ * @param options - `categories` to narrow to, `forceEngineRules` to keep the
160
+ * engine layer on a model that names no platform, and `camundaVersion` — a
161
+ * version a `.bpmnlintrc` pins — to keep `compat` on such a model.
129
162
  */
130
163
  export function lintCategories(definitions, options = {}) {
131
164
  const base = options.categories ?? ALL_CATEGORIES;
132
165
  const engineRules = options.forceEngineRules === true || detectExecutionPlatform(definitions).id !== "none";
133
- return engineRules ? [...base] : base.filter((c) => !ENGINE_CATEGORIES.includes(c));
166
+ if (engineRules)
167
+ return [...base];
168
+ // A pinned `camundaVersion` still runs the compatibility check: `optimize`
169
+ // runs it whenever a version is given, and `lintDiagram` keeps its findings.
170
+ return base.filter((c) => !ENGINE_CATEGORIES.includes(c));
134
171
  }
135
172
  //# sourceMappingURL=lint.js.map
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Native equivalents of bpmnlint rules BPMN Kit had no finding for, or whose
3
+ * finding checks only the top-level process or a different set of elements.
4
+ *
5
+ * These are opt-in: nothing here runs unless a `.bpmnlintrc` enables the
6
+ * bpmnlint rule it stands in for (see `../bpmnlint.ts`). The default
7
+ * `casen lint` report is unchanged by their existence — several of them
8
+ * (`no-inclusive-gateway`, `standard-size`, …) are house style rather than
9
+ * correctness, and a team that never asked for them should not see them.
10
+ *
11
+ * Every rule walks every scope — processes and the sub-processes nested in
12
+ * them — because bpmnlint does. Connectivity is read from the sequence flows
13
+ * of each scope rather than from the `<incoming>`/`<outgoing>` children, which
14
+ * hand-written and generated XML routinely omits.
15
+ */
16
+ import type { BpmnDefinitions } from "../bpmn-model.js";
17
+ import type { OptimizationCategory, OptimizationFinding } from "./types.js";
18
+ /** The bpmnlint rules this module implements natively. */
19
+ export declare const NATIVE_BPMNLINT_RULES: readonly string[];
20
+ /**
21
+ * Runs the native equivalents of the given bpmnlint rules.
22
+ *
23
+ * Findings come back at `warning` severity; the caller applies the severity
24
+ * the `.bpmnlintrc` asked for.
25
+ *
26
+ * @param defs - The model to check.
27
+ * @param rules - bpmnlint rule name → that rule's options from the config.
28
+ * @param categories - When given, rules outside these categories are skipped.
29
+ */
30
+ export declare function analyzeBpmnlintRules(defs: BpmnDefinitions, rules: ReadonlyMap<string, unknown>, categories?: readonly OptimizationCategory[]): OptimizationFinding[];
31
+ //# sourceMappingURL=bpmnlint-rules.d.ts.map