@bpmnkit/core 1.11.0 → 1.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/bpmn/svg.js CHANGED
@@ -1,3 +1,5 @@
1
+ import { applyAutoLayout } from "./auto-layout.js";
2
+ import { readDiColor } from "./di-color.js";
1
3
  import { collectLabelStyles, labelFontCss, resolveLabelFont, } from "./label-style.js";
2
4
  const LIGHT = {
3
5
  bg: "#f8f9fa",
@@ -22,7 +24,7 @@ const DARK = {
22
24
  *
23
25
  * The definitions must already contain diagram interchange (DI) position data —
24
26
  * i.e. they were produced by `.withAutoLayout().build()` or parsed from BPMN
25
- * XML that includes `<bpmndi:BPMNDiagram>` elements.
27
+ * XML that includes `<bpmndi:BPMNDiagram>` elements (or pass `autoLayout: true`).
26
28
  *
27
29
  * Works in every environment (Node.js, browsers, Deno, Bun, edge runtimes) with
28
30
  * zero external dependencies. Returns a standalone SVG string that can be written
@@ -44,17 +46,33 @@ const DARK = {
44
46
  * ```
45
47
  */
46
48
  export function exportSvg(defs, options) {
47
- const t = options?.theme === "dark" ? DARK : LIGHT;
49
+ return exportSvgDetailed(defs, options).svg;
50
+ }
51
+ /** Like {@link exportSvg}, plus the drawn size, viewBox, element geometry and warnings. */
52
+ export function exportSvgDetailed(input, options) {
53
+ const t = resolveCtx(options);
48
54
  const padding = options?.padding ?? 20;
49
- const plane = defs.diagrams[0]?.plane;
55
+ const useDiColors = options?.colors === "di";
56
+ const withIds = options?.elementIds === true;
57
+ const withBg = options?.background !== false;
58
+ const warnings = [];
59
+ const elements = [];
60
+ const idAttr = (id) => (withIds ? ` data-element-id="${esc(id)}"` : "");
61
+ let defs = input;
62
+ let plane = selectPlane(defs, options?.plane);
63
+ if (options?.autoLayout === true && options.plane === undefined && !plane?.shapes.length) {
64
+ defs = applyAutoLayout(defs, "semantic");
65
+ warnings.push({ type: "autoLayoutApplied" });
66
+ plane = selectPlane(defs, undefined);
67
+ }
50
68
  if (!plane)
51
- return emptySvg(t);
69
+ return emptyResult(t, withBg, warnings);
52
70
  // Build model index for name/type lookups
53
71
  const idx = buildIndex(defs);
54
72
  const labelStyles = collectLabelStyles(defs);
55
73
  const fontOf = (label) => {
56
74
  const font = resolveLabelFont(label, labelStyles);
57
- return font ? labelFontCss(font, DEFAULT_FAMILY, DEFAULT_SIZE) : undefined;
75
+ return font ? labelFontCss(font, t.fontFamily, t.fontSize) : undefined;
58
76
  };
59
77
  // ── Bounding box ──────────────────────────────────────────────────────────
60
78
  let minX = Number.POSITIVE_INFINITY;
@@ -77,11 +95,12 @@ export function exportSvg(defs, options) {
77
95
  }
78
96
  }
79
97
  if (!Number.isFinite(minX))
80
- return emptySvg(t);
98
+ return emptyResult(t, withBg, warnings);
81
99
  const ox = minX - padding;
82
100
  const oy = minY - padding;
83
101
  const vw = maxX - minX + padding * 2;
84
102
  const vh = maxY - minY + padding * 2;
103
+ const { width, height } = fitSize(vw, vh, options);
85
104
  // ── Edges ─────────────────────────────────────────────────────────────────
86
105
  const edgeParts = [];
87
106
  for (const edge of plane.edges) {
@@ -91,14 +110,21 @@ export function exportSvg(defs, options) {
91
110
  const isMsg = idx.messageFlowIds.has(edge.bpmnElement);
92
111
  const isAssoc = !flow && !isMsg;
93
112
  const d = waypointsToPath(edge.waypoints);
94
- const strokeColor = t.flowStroke;
113
+ const strokeColor = useDiColors
114
+ ? (readDiColor(edge.unknownAttributes).stroke ?? t.flowStroke)
115
+ : t.flowStroke;
95
116
  const sw = 1.5;
117
+ elements.push({
118
+ id: edge.bpmnElement,
119
+ kind: isMsg ? "messageFlow" : isAssoc ? "association" : "sequenceFlow",
120
+ geometry: { kind: "edge", waypoints: edge.waypoints.map((w) => [w.x, w.y]) },
121
+ });
96
122
  if (isAssoc) {
97
- edgeParts.push(`<path d="${d}" fill="none" stroke="${strokeColor}" stroke-width="${sw}" stroke-dasharray="5 3"/>`);
123
+ edgeParts.push(`<path d="${d}"${idAttr(edge.bpmnElement)} fill="none" stroke="${strokeColor}" stroke-width="${sw}" stroke-dasharray="5 3"/>`);
98
124
  continue;
99
125
  }
100
126
  const dashArray = isMsg ? ' stroke-dasharray="6 3"' : "";
101
- edgeParts.push(`<path d="${d}" fill="none" stroke="${strokeColor}" stroke-width="${sw}"${dashArray} marker-end="url(#arr)"/>`);
127
+ edgeParts.push(`<path d="${d}"${idAttr(edge.bpmnElement)} fill="none" stroke="${strokeColor}" stroke-width="${sw}"${dashArray} marker-end="url(#arr)"/>`);
102
128
  // Default-flow slash
103
129
  if (flow && idx.defaultFlowIds.has(edge.bpmnElement)) {
104
130
  const wp0 = edge.waypoints[0];
@@ -130,31 +156,53 @@ export function exportSvg(defs, options) {
130
156
  const containerParts = [];
131
157
  const shapeParts = [];
132
158
  const labelParts = [];
159
+ const drawn = new Set();
133
160
  for (const shape of plane.shapes) {
134
161
  const { x, y, width, height } = shape.bounds;
135
162
  const el = idx.elements.get(shape.bpmnElement);
136
163
  const type = el?.type ?? "";
137
164
  const font = fontOf(shape.label);
165
+ // Per-shape palette: DI colours replace fill/stroke for body and markers.
166
+ const c = useDiColors ? readDiColor(shape.unknownAttributes) : undefined;
167
+ const ts = c
168
+ ? { ...t, shapeFill: c.fill ?? t.shapeFill, shapeStroke: c.stroke ?? t.shapeStroke }
169
+ : t;
138
170
  let inner;
139
171
  let isContainer = false;
172
+ let kind = el?.type;
140
173
  if (isEvent(type)) {
141
- inner = renderEvent(el, width, height, t);
174
+ inner = renderEvent(el, width, height, ts);
142
175
  }
143
176
  else if (isGateway(type)) {
144
- inner = renderGateway(el, width, height, t);
177
+ inner = renderGateway(el, width, height, ts);
178
+ }
179
+ else if (type === "dataObjectReference") {
180
+ inner = renderDataObject(el, width, height, ts);
181
+ }
182
+ else if (type === "dataStoreReference") {
183
+ inner = renderDataStore(width, height, ts);
145
184
  }
146
185
  else if (type === "" && !el) {
147
- // Pool, lane, or annotation
186
+ // Pool, lane, annotation or group
148
187
  const annotation = idx.annotations.get(shape.bpmnElement);
188
+ const group = idx.groups.get(shape.bpmnElement);
149
189
  if (annotation !== undefined) {
150
- inner = renderAnnotation(annotation.text, width, height, t, font);
190
+ inner = renderAnnotation(annotation.text, width, height, ts, font);
191
+ kind = "textAnnotation";
192
+ }
193
+ else if (group !== undefined) {
194
+ inner = renderGroup(idx.groupLabel(group), width, height, ts, font);
195
+ kind = "group";
196
+ isContainer = true;
151
197
  }
152
198
  else if (idx.participants.has(shape.bpmnElement)) {
153
- inner = renderPool(idx.participants.get(shape.bpmnElement), width, height, t, font);
199
+ inner = renderPool(idx.participants.get(shape.bpmnElement), width, height, ts, font);
200
+ kind = "participant";
154
201
  isContainer = true;
155
202
  }
156
203
  else if (idx.lanes.has(shape.bpmnElement)) {
157
- inner = renderLane(idx.lanes.get(shape.bpmnElement), width, height, t, font);
204
+ inner = renderLane(idx.lanes.get(shape.bpmnElement), width, height, ts, font);
205
+ kind = "lane";
158
206
  isContainer = true;
159
207
  }
160
208
  else {
@@ -171,21 +219,32 @@ export function exportSvg(defs, options) {
171
219
  type === "eventSubProcess" ||
172
220
  type === "transaction") &&
173
221
  shape.isExpanded === true;
174
- inner = renderTask(el, width, height, t, { expanded: isExpandedContainer, font });
222
+ inner = renderTask(el, width, height, ts, { expanded: isExpandedContainer, font });
175
223
  if (isExpandedContainer)
176
224
  isContainer = true;
177
225
  }
178
226
  if (inner) {
179
- const g = `<g transform="translate(${x} ${y})">${inner}</g>`;
227
+ const g = `<g transform="translate(${x} ${y})"${idAttr(shape.bpmnElement)}>${inner}</g>`;
180
228
  if (isContainer) {
181
229
  containerParts.push(g);
182
230
  }
183
231
  else {
184
232
  shapeParts.push(g);
185
233
  }
234
+ if (kind) {
235
+ elements.push({
236
+ id: shape.bpmnElement,
237
+ kind,
238
+ geometry: { kind: "shape", bounds: shape.bounds },
239
+ });
240
+ drawn.add(shape.bpmnElement);
241
+ }
186
242
  }
187
- // External labels for events and gateways
188
- const isExtLabel = isEvent(type) || isGateway(type);
243
+ // External labels for events, gateways and data elements
244
+ const isExtLabel = isEvent(type) ||
245
+ isGateway(type) ||
246
+ type === "dataObjectReference" ||
247
+ type === "dataStoreReference";
189
248
  if (el?.name && isExtLabel) {
190
249
  const lb = shape.label?.bounds ?? {
191
250
  x: shape.bounds.x + shape.bounds.width / 2 - 40,
@@ -196,12 +255,15 @@ export function exportSvg(defs, options) {
196
255
  labelParts.push(labelSvg(el.name, lb.x + lb.width / 2, lb.y + lb.height / 2, lb.width, t, true, font));
197
256
  }
198
257
  }
258
+ for (const id of idx.elements.keys()) {
259
+ if (!drawn.has(id))
260
+ warnings.push({ type: "elementWithoutDi", id });
261
+ }
199
262
  // ── Assemble SVG ──────────────────────────────────────────────────────────
200
- const bgStyle = `fill="${t.bg}"`;
201
263
  const arrowFill = t.flowStroke;
202
- return [
203
- `<svg xmlns="http://www.w3.org/2000/svg" viewBox="${ox} ${oy} ${vw} ${vh}" width="${vw}" height="${vh}">`,
204
- `<rect x="${ox}" y="${oy}" width="${vw}" height="${vh}" ${bgStyle}/>`,
264
+ const svg = [
265
+ `<svg xmlns="http://www.w3.org/2000/svg" viewBox="${ox} ${oy} ${vw} ${vh}" width="${width}" height="${height}">`,
266
+ ...(withBg ? [`<rect x="${ox}" y="${oy}" width="${vw}" height="${vh}" fill="${t.bg}"/>`] : []),
205
267
  "<defs>",
206
268
  ` <marker id="arr" markerWidth="8" markerHeight="6" refX="7" refY="3" orient="auto" markerUnits="strokeWidth">`,
207
269
  ` <path d="M0,0 L8,3 L0,6 Z" fill="${arrowFill}"/>`,
@@ -213,10 +275,53 @@ export function exportSvg(defs, options) {
213
275
  ...labelParts,
214
276
  "</svg>",
215
277
  ].join("\n");
278
+ return { svg, viewBox: { x: ox, y: oy, w: vw, h: vh }, width, height, elements, warnings };
216
279
  }
217
280
  // ── Helpers ───────────────────────────────────────────────────────────────────
218
- function emptySvg(t) {
219
- return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1 1" width="1" height="1"><rect width="1" height="1" fill="${t.bg}"/></svg>`;
281
+ /** @internal Theme colours and font settings from the shared export options. */
282
+ export function resolveCtx(options) {
283
+ const theme = options?.theme;
284
+ const base = theme === "dark" ? DARK : typeof theme === "object" ? theme : LIGHT;
285
+ return {
286
+ ...base,
287
+ fontFamily: options?.font?.family ?? DEFAULT_FAMILY,
288
+ fontSize: options?.font?.size ?? DEFAULT_SIZE,
289
+ lineH: options?.font?.lineHeight ?? DEFAULT_LINE_H,
290
+ };
291
+ }
292
+ /** @internal `width`/`height` after `scale` and `maxSize` (the viewBox never changes). */
293
+ export function fitSize(vw, vh, options) {
294
+ let width = vw * (options?.scale ?? 1);
295
+ let height = vh * (options?.scale ?? 1);
296
+ if (options?.maxSize) {
297
+ const [mw, mh] = options.maxSize;
298
+ const f = Math.min(1, mw / width, mh / height);
299
+ width = width * f;
300
+ height = height * f;
301
+ }
302
+ return { width, height };
303
+ }
304
+ function emptyResult(t, withBg, warnings) {
305
+ const rect = withBg ? `<rect width="1" height="1" fill="${t.bg}"/>` : "";
306
+ return {
307
+ svg: `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1 1" width="1" height="1">${rect}</svg>`,
308
+ viewBox: { x: 0, y: 0, w: 1, h: 1 },
309
+ width: 1,
310
+ height: 1,
311
+ elements: [],
312
+ warnings,
313
+ };
314
+ }
315
+ /** Picks the plane to draw; undefined when the model has none. */
316
+ function selectPlane(defs, sel) {
317
+ if (!sel)
318
+ return defs.diagrams[0]?.plane;
319
+ const hit = "id" in sel
320
+ ? defs.diagrams.find((d) => d.id === sel.id || d.plane.id === sel.id)
321
+ : defs.diagrams.find((d) => d.plane.bpmnElement === sel.process);
322
+ if (!hit)
323
+ throw new Error(`Plane not found: ${"id" in sel ? sel.id : sel.process}`);
324
+ return hit.plane;
220
325
  }
221
326
  function isEvent(type) {
222
327
  return (type === "startEvent" ||
@@ -238,12 +343,14 @@ const DEFAULT_FAMILY = "system-ui,-apple-system,sans-serif";
238
343
  const DEFAULT_SIZE = 11;
239
344
  const DEFAULT_LINE_H = 14;
240
345
  /** Estimated glyph width for a label font — scaled from the 11px default. */
241
- function charPx(font) {
346
+ /** @internal */
347
+ export function charPx(font, t) {
242
348
  if (!font)
243
- return AVG_CHAR_PX;
349
+ return AVG_CHAR_PX * (t.fontSize / DEFAULT_SIZE);
244
350
  return AVG_CHAR_PX * (font.fontSize / DEFAULT_SIZE) * (font.fontWeight === "bold" ? 1.1 : 1);
245
351
  }
246
- function wrapText(text, maxPx, charW = AVG_CHAR_PX) {
352
+ /** @internal */
353
+ export function wrapText(text, maxPx, charW = AVG_CHAR_PX) {
247
354
  if (!text.trim())
248
355
  return [];
249
356
  const words = text.split(/\s+/);
@@ -266,16 +373,18 @@ function wrapText(text, maxPx, charW = AVG_CHAR_PX) {
266
373
  lines.push(line);
267
374
  return lines.length > 0 ? lines : [text];
268
375
  }
269
- function esc(s) {
376
+ /** @internal */
377
+ export function esc(s) {
270
378
  return s
271
379
  .replace(/&/g, "&amp;")
272
380
  .replace(/</g, "&lt;")
273
381
  .replace(/>/g, "&gt;")
274
382
  .replace(/"/g, "&quot;");
275
383
  }
276
- function fontStyle(font) {
384
+ /** @internal */
385
+ export function fontStyle(font, t) {
277
386
  if (!font)
278
- return `font-family:${DEFAULT_FAMILY};font-size:${DEFAULT_SIZE}px`;
387
+ return `font-family:${t.fontFamily};font-size:${t.fontSize}px`;
279
388
  let out = `font-family:${font.fontFamily};font-size:${font.fontSize}px`;
280
389
  if (font.fontWeight !== "normal")
281
390
  out += `;font-weight:${font.fontWeight}`;
@@ -287,16 +396,17 @@ function fontStyle(font) {
287
396
  }
288
397
  /** A label's inline style, XML-escaped for a double-quoted attribute. */
289
398
  function textStyle(t, font) {
290
- return esc(`fill:${t.text};${fontStyle(font)};text-anchor:middle;dominant-baseline:central;paint-order:stroke;stroke:${t.textHalo};stroke-width:4px;stroke-linejoin:round`);
399
+ return esc(`fill:${t.text};${fontStyle(font, t)};text-anchor:middle;dominant-baseline:central;paint-order:stroke;stroke:${t.textHalo};stroke-width:4px;stroke-linejoin:round`);
291
400
  }
292
401
  /**
293
402
  * Generates SVG text element(s) for a label centred at (cx, cy).
294
403
  * topAlign=true makes multi-line text flow downward from cy rather than
295
404
  * being centred around it — prevents long labels from overlapping the shape above.
296
405
  */
297
- function labelSvg(text, cx, cy, maxWidth, t, topAlign = false, font) {
298
- const lines = wrapText(text, maxWidth, charPx(font));
299
- const lineH = font ? (font.fontSize * DEFAULT_LINE_H) / DEFAULT_SIZE : DEFAULT_LINE_H;
406
+ /** @internal */
407
+ export function labelSvg(text, cx, cy, maxWidth, t, topAlign = false, font) {
408
+ const lines = wrapText(text, maxWidth, charPx(font, t));
409
+ const lineH = font ? (font.fontSize * t.lineH) / t.fontSize : t.lineH;
300
410
  const style = textStyle(t, font);
301
411
  if (lines.length === 1) {
302
412
  return `<text style="${style}" x="${cx}" y="${cy}">${esc(lines[0] ?? text)}</text>`;
@@ -415,18 +525,44 @@ function gatewayMarker(type) {
415
525
  return "";
416
526
  }
417
527
  }
418
- // ── Sub-process marker ────────────────────────────────────────────────────────
419
- function subProcessMarker(type) {
420
- if (type === "adHocSubProcess") {
421
- return `<path d="M-7 0Q-4 -4 0 0Q4 4 7 0" class="bi"/>`;
528
+ // ── Activity marker row ───────────────────────────────────────────────────────
529
+ const MARKER_STEP = 16;
530
+ /**
531
+ * Bottom-centre marker row: multi-instance, compensation, ad-hoc tilde and the
532
+ * collapsed `+` box (call activities always, sub-process variants when collapsed).
533
+ */
534
+ function activityMarkers(el, expanded) {
535
+ const glyphs = [];
536
+ const lc = "loopCharacteristics" in el ? el.loopCharacteristics : undefined;
537
+ if (lc) {
538
+ glyphs.push(lc.isSequential
539
+ ? `<path d="M-5 -4h10M-5 0h10M-5 4h10" class="bi"/>`
540
+ : `<path d="M-4 -5v10M0 -5v10M4 -5v10" class="bi"/>`);
541
+ }
542
+ if ("isForCompensation" in el && el.isForCompensation) {
543
+ glyphs.push(`<path d="M1 -3.5l-5 3.5 5 3.5zM6 -3.5l-5 3.5 5 3.5z" class="bi"/>`);
544
+ }
545
+ if (el.type === "adHocSubProcess")
546
+ glyphs.push(`<path d="M-7 0Q-4 -4 0 0Q4 4 7 0" class="bi"/>`);
547
+ const subProcess = el.type === "subProcess" ||
548
+ el.type === "adHocSubProcess" ||
549
+ el.type === "eventSubProcess" ||
550
+ el.type === "transaction";
551
+ if (el.type === "callActivity" || (subProcess && !expanded)) {
552
+ glyphs.push(`<rect x="-7" y="-7" width="14" height="14" rx="1" class="bi"/><path d="M0 -4v8M-4 0h8" class="bi"/>`);
422
553
  }
423
- return `<rect x="-7" y="-7" width="14" height="14" rx="1" class="bi"/><path d="M0 -4v8M-4 0h8" class="bi"/>`;
554
+ const start = -((glyphs.length - 1) * MARKER_STEP) / 2;
555
+ return glyphs
556
+ .map((g, i) => `<g transform="translate(${start + i * MARKER_STEP} 0)">${g}</g>`)
557
+ .join("");
424
558
  }
425
559
  // ── Shape renderers ────────────────────────────────────────────────────────────
426
- function shapeStyle(t, sw = 1.5, dash) {
560
+ /** @internal */
561
+ export function shapeStyle(t, sw = 1.5, dash) {
427
562
  return `fill:${t.shapeFill};stroke:${t.shapeStroke};stroke-width:${sw}${dash ? `;stroke-dasharray:${dash}` : ""}`;
428
563
  }
429
- function iconStyle(t) {
564
+ /** @internal */
565
+ export function iconStyle(t) {
430
566
  return `fill:none;stroke:${t.shapeStroke};stroke-width:1.5;stroke-linecap:round;stroke-linejoin:round`;
431
567
  }
432
568
  function iconSolidStyle(t) {
@@ -444,7 +580,8 @@ function gwMarkerFillStyle(t) {
444
580
  * CSS classes cannot be used in standalone SVGs, so we map them to inline styles
445
581
  * via a local `<style>` element scoped to the enclosing `<g>`.
446
582
  */
447
- function iconGroup(content, x, y, t) {
583
+ /** @internal */
584
+ export function iconGroup(content, x, y, t) {
448
585
  const bi = iconStyle(t);
449
586
  const bis = iconSolidStyle(t);
450
587
  const gm = gwMarkerFillStyle(t);
@@ -512,10 +649,9 @@ function renderTask(el, width, height, t, options) {
512
649
  }
513
650
  }
514
651
  // The "+" marker means "contents elsewhere"; an expanded body shows them.
515
- const container = type === "subProcess" || type === "eventSubProcess" || type === "transaction";
516
- if ((container && !options?.expanded) || type === "adHocSubProcess") {
517
- out += iconGroup(subProcessMarker(type), width / 2, height - 10, t);
518
- }
652
+ const markers = el ? activityMarkers(el, options?.expanded === true) : "";
653
+ if (markers)
654
+ out += iconGroup(markers, width / 2, height - 10, t);
519
655
  return out;
520
656
  }
521
657
  function renderGateway(el, width, height, t) {
@@ -530,6 +666,29 @@ function renderGateway(el, width, height, t) {
530
666
  }
531
667
  return out;
532
668
  }
669
+ function renderDataObject(el, width, height, t) {
670
+ const fold = Math.min(14, width / 3);
671
+ let out = `<path d="M0 0 H${width - fold} L${width} ${fold} V${height} H0 Z" style="${shapeStyle(t)}"/>` +
672
+ `<path d="M${width - fold} 0 V${fold} H${width}" style="${iconStyle(t)}"/>`;
673
+ if (el?.type === "dataObjectReference" && el.isCollection) {
674
+ out += iconGroup(`<path d="M-3 -5v9M0 -5v9M3 -5v9" class="bi"/>`, width / 2, height - 6, t);
675
+ }
676
+ return out;
677
+ }
678
+ function renderDataStore(width, height, t) {
679
+ const ry = Math.min(8, height / 6);
680
+ const rx = width / 2;
681
+ return (`<path d="M0 ${ry} A ${rx} ${ry} 0 0 0 ${width} ${ry} V ${height - ry} A ${rx} ${ry} 0 0 1 0 ${height - ry} Z" style="${shapeStyle(t)}"/>` +
682
+ `<ellipse cx="${rx}" cy="${ry}" rx="${rx}" ry="${ry}" style="${shapeStyle(t)}"/>` +
683
+ `<path d="M0 ${ry * 2} A ${rx} ${ry} 0 0 0 ${width} ${ry * 2} M0 ${ry * 3.4} A ${rx} ${ry} 0 0 0 ${width} ${ry * 3.4}" style="${iconStyle(t)}"/>`);
684
+ }
685
+ function renderGroup(name, width, height, t, font) {
686
+ const style = `fill:none;stroke:${t.shapeStroke};stroke-width:1.5;stroke-dasharray:6 3`;
687
+ let out = `<rect x="0" y="0" width="${width}" height="${height}" rx="8" style="${style}"/>`;
688
+ if (name)
689
+ out += labelSvg(name, width / 2, 14, width - 16, t, true, font);
690
+ return out;
691
+ }
533
692
  function renderPool(participant, width, height, t, font) {
534
693
  const bodyStyle = `fill:${t.shapeFill};stroke:${t.shapeStroke};stroke-width:1.5`;
535
694
  const headerStyle = `fill:${t.poolHeader};stroke:${t.shapeStroke};stroke-width:1.5`;
@@ -564,6 +723,7 @@ function buildIndex(defs) {
564
723
  const annotations = new Map();
565
724
  const participants = new Map();
566
725
  const lanes = new Map();
726
+ const groups = new Map();
567
727
  const messageFlowIds = new Set();
568
728
  const defaultFlowIds = new Set();
569
729
  function indexElements(flowElements, seqFlows) {
@@ -598,6 +758,8 @@ function buildIndex(defs) {
598
758
  for (const ta of proc.textAnnotations) {
599
759
  annotations.set(ta.id, ta);
600
760
  }
761
+ for (const g of proc.groups ?? [])
762
+ groups.set(g.id, g);
601
763
  if (proc.laneSet)
602
764
  indexLaneSet(proc.laneSet);
603
765
  }
@@ -608,10 +770,28 @@ function buildIndex(defs) {
608
770
  for (const ta of collab.textAnnotations) {
609
771
  annotations.set(ta.id, ta);
610
772
  }
773
+ for (const g of collab.groups ?? [])
774
+ groups.set(g.id, g);
611
775
  for (const mf of collab.messageFlows) {
612
776
  messageFlowIds.add(mf.id);
613
777
  }
614
778
  }
615
- return { elements, flows, annotations, participants, lanes, messageFlowIds, defaultFlowIds };
779
+ const categoryValues = new Map();
780
+ for (const cat of defs.categories ?? []) {
781
+ for (const v of cat.categoryValues)
782
+ categoryValues.set(v.id, v.value);
783
+ }
784
+ const groupLabel = (g) => g.categoryValueRef ? categoryValues.get(g.categoryValueRef) : undefined;
785
+ return {
786
+ elements,
787
+ flows,
788
+ annotations,
789
+ participants,
790
+ lanes,
791
+ groups,
792
+ groupLabel,
793
+ messageFlowIds,
794
+ defaultFlowIds,
795
+ };
616
796
  }
617
797
  //# sourceMappingURL=svg.js.map
@@ -0,0 +1,25 @@
1
+ import { type SvgExportOptions } from "../bpmn/svg.js";
2
+ import type { DmnDecisionTable, DmnDefinitions } from "./dmn-model.js";
3
+ /** Options shared with `exportSvg`; plane, colour and layout options do not apply to DMN. */
4
+ export type DmnSvgOptions = Pick<SvgExportOptions, "theme" | "padding" | "scale" | "maxSize" | "font" | "elementIds" | "background">;
5
+ export interface DecisionTableSvgOptions extends DmnSvgOptions {
6
+ /** Decision name shown in a title bar above the table. */
7
+ name?: string;
8
+ }
9
+ /**
10
+ * Generates a self-contained SVG of a DMN requirements diagram (DRD): decisions
11
+ * (rectangles), input data (stadiums), knowledge sources (wavy bottom), business
12
+ * knowledge models (clipped corners), and information (solid arrow), knowledge
13
+ * (dashed arrow) and authority (dotted, circle end) requirements.
14
+ *
15
+ * Definitions without diagram interchange are laid out with `layoutDmn` first.
16
+ */
17
+ export declare function exportDrdSvg(input: DmnDefinitions, options?: DmnSvgOptions): string;
18
+ /**
19
+ * Generates a self-contained SVG of a decision table: hit-policy letter and rule
20
+ * numbers in the first column, then input and output columns, then an annotation
21
+ * column when any rule has a description. Column widths follow the longest text
22
+ * (6.5 px per character) clamped to 60–280 px; longer text wraps.
23
+ */
24
+ export declare function exportDecisionTableSvg(table: DmnDecisionTable, options?: DecisionTableSvgOptions): string;
25
+ //# sourceMappingURL=svg.d.ts.map