@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.
- package/README.md +30 -3
- package/dist/bpmn/agentic.js +3 -1
- package/dist/bpmn/auto-layout.js +184 -15
- package/dist/bpmn/bpmn-builder.js +69 -7
- package/dist/bpmn/bpmn-model.d.ts +78 -0
- package/dist/bpmn/bpmn-parser.js +195 -37
- package/dist/bpmn/bpmn-serializer.js +121 -72
- package/dist/bpmn/bpmnlint.d.ts +153 -0
- package/dist/bpmn/bpmnlint.js +364 -0
- package/dist/bpmn/camunda-compat-data.d.ts +165 -0
- package/dist/bpmn/camunda-compat-data.js +423 -0
- package/dist/bpmn/camunda-compat-feel.d.ts +68 -0
- package/dist/bpmn/camunda-compat-feel.js +338 -0
- package/dist/bpmn/camunda-compat.d.ts +120 -0
- package/dist/bpmn/camunda-compat.js +1677 -0
- package/dist/bpmn/camunda7/juel.d.ts +41 -0
- package/dist/bpmn/camunda7/juel.js +333 -0
- package/dist/bpmn/camunda7/migrate.d.ts +72 -0
- package/dist/bpmn/camunda7/migrate.js +1152 -0
- package/dist/bpmn/compact.d.ts +4 -0
- package/dist/bpmn/compact.js +80 -0
- package/dist/bpmn/full-operations.js +5 -2
- package/dist/bpmn/label-style.d.ts +51 -0
- package/dist/bpmn/label-style.js +116 -0
- package/dist/bpmn/lint.d.ts +23 -3
- package/dist/bpmn/lint.js +47 -10
- package/dist/bpmn/optimize/bpmnlint-rules.d.ts +31 -0
- package/dist/bpmn/optimize/bpmnlint-rules.js +916 -0
- package/dist/bpmn/optimize/deploy.d.ts +8 -2
- package/dist/bpmn/optimize/deploy.js +16 -3
- package/dist/bpmn/optimize/index.js +11 -2
- package/dist/bpmn/optimize/patterns.js +3 -0
- package/dist/bpmn/optimize/types.d.ts +14 -0
- package/dist/bpmn/optimize/variable-flow.js +4 -1
- package/dist/bpmn/process-delta.d.ts +88 -0
- package/dist/bpmn/process-delta.js +236 -0
- package/dist/bpmn/process-text-writer.d.ts +53 -0
- package/dist/bpmn/process-text-writer.js +193 -0
- package/dist/bpmn/process-text.d.ts +175 -0
- package/dist/bpmn/process-text.js +1255 -0
- package/dist/bpmn/process-types.d.ts +112 -0
- package/dist/bpmn/process-types.js +490 -0
- package/dist/bpmn/svg.js +51 -22
- package/dist/doc/docx.d.ts +20 -0
- package/dist/doc/docx.js +253 -0
- package/dist/doc/html.d.ts +21 -0
- package/dist/doc/html.js +303 -0
- package/dist/doc/index.d.ts +7 -0
- package/dist/doc/index.js +5 -0
- package/dist/doc/markdown.d.ts +11 -0
- package/dist/doc/markdown.js +160 -0
- package/dist/doc/model.d.ts +129 -0
- package/dist/doc/model.js +617 -0
- package/dist/doc/zip.d.ts +5 -0
- package/dist/doc/zip.js +75 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +11 -0
- package/dist/layout/annotations.d.ts +4 -2
- package/dist/layout/annotations.js +31 -2
- package/dist/layout/collaboration/ordering.d.ts +8 -0
- package/dist/layout/collaboration/ordering.js +57 -18
- package/dist/layout/orthogonal.d.ts +32 -0
- package/dist/layout/orthogonal.js +367 -0
- package/dist/layout/repair.d.ts +31 -0
- package/dist/layout/repair.js +220 -0
- package/dist/layout/semantic/route.js +45 -3
- package/dist/node/bpmnlint.d.ts +109 -0
- package/dist/node/bpmnlint.js +198 -0
- package/dist/node/index.d.ts +2 -0
- package/dist/node/index.js +1 -0
- package/dist/xml/xml-patch.d.ts +21 -0
- package/dist/xml/xml-patch.js +27 -1
- package/package.json +2 -2
package/dist/bpmn/svg.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { collectLabelStyles, labelFontCss, resolveLabelFont, } from "./label-style.js";
|
|
1
2
|
const LIGHT = {
|
|
2
3
|
bg: "#f8f9fa",
|
|
3
4
|
shapeFill: "#ffffff",
|
|
@@ -50,6 +51,11 @@ export function exportSvg(defs, options) {
|
|
|
50
51
|
return emptySvg(t);
|
|
51
52
|
// Build model index for name/type lookups
|
|
52
53
|
const idx = buildIndex(defs);
|
|
54
|
+
const labelStyles = collectLabelStyles(defs);
|
|
55
|
+
const fontOf = (label) => {
|
|
56
|
+
const font = resolveLabelFont(label, labelStyles);
|
|
57
|
+
return font ? labelFontCss(font, DEFAULT_FAMILY, DEFAULT_SIZE) : undefined;
|
|
58
|
+
};
|
|
53
59
|
// ── Bounding box ──────────────────────────────────────────────────────────
|
|
54
60
|
let minX = Number.POSITIVE_INFINITY;
|
|
55
61
|
let minY = Number.POSITIVE_INFINITY;
|
|
@@ -115,7 +121,7 @@ export function exportSvg(defs, options) {
|
|
|
115
121
|
// Edge label
|
|
116
122
|
if (flow?.name && edge.label?.bounds) {
|
|
117
123
|
const { x, y, width, height } = edge.label.bounds;
|
|
118
|
-
edgeParts.push(labelSvg(flow.name, x + width / 2, y + height / 2, width - 4, t));
|
|
124
|
+
edgeParts.push(labelSvg(flow.name, x + width / 2, y + height / 2, width - 4, t, false, fontOf(edge.label)));
|
|
119
125
|
}
|
|
120
126
|
}
|
|
121
127
|
// ── Shapes ────────────────────────────────────────────────────────────────
|
|
@@ -128,6 +134,7 @@ export function exportSvg(defs, options) {
|
|
|
128
134
|
const { x, y, width, height } = shape.bounds;
|
|
129
135
|
const el = idx.elements.get(shape.bpmnElement);
|
|
130
136
|
const type = el?.type ?? "";
|
|
137
|
+
const font = fontOf(shape.label);
|
|
131
138
|
let inner;
|
|
132
139
|
let isContainer = false;
|
|
133
140
|
if (isEvent(type)) {
|
|
@@ -140,14 +147,14 @@ export function exportSvg(defs, options) {
|
|
|
140
147
|
// Pool, lane, or annotation
|
|
141
148
|
const annotation = idx.annotations.get(shape.bpmnElement);
|
|
142
149
|
if (annotation !== undefined) {
|
|
143
|
-
inner = renderAnnotation(annotation.text, width, height, t);
|
|
150
|
+
inner = renderAnnotation(annotation.text, width, height, t, font);
|
|
144
151
|
}
|
|
145
152
|
else if (idx.participants.has(shape.bpmnElement)) {
|
|
146
|
-
inner = renderPool(idx.participants.get(shape.bpmnElement), width, height, t);
|
|
153
|
+
inner = renderPool(idx.participants.get(shape.bpmnElement), width, height, t, font);
|
|
147
154
|
isContainer = true;
|
|
148
155
|
}
|
|
149
156
|
else if (idx.lanes.has(shape.bpmnElement)) {
|
|
150
|
-
inner = renderLane(idx.lanes.get(shape.bpmnElement), width, height, t);
|
|
157
|
+
inner = renderLane(idx.lanes.get(shape.bpmnElement), width, height, t, font);
|
|
151
158
|
isContainer = true;
|
|
152
159
|
}
|
|
153
160
|
else {
|
|
@@ -164,7 +171,7 @@ export function exportSvg(defs, options) {
|
|
|
164
171
|
type === "eventSubProcess" ||
|
|
165
172
|
type === "transaction") &&
|
|
166
173
|
shape.isExpanded === true;
|
|
167
|
-
inner = renderTask(el, width, height, t, { expanded: isExpandedContainer });
|
|
174
|
+
inner = renderTask(el, width, height, t, { expanded: isExpandedContainer, font });
|
|
168
175
|
if (isExpandedContainer)
|
|
169
176
|
isContainer = true;
|
|
170
177
|
}
|
|
@@ -186,7 +193,7 @@ export function exportSvg(defs, options) {
|
|
|
186
193
|
width: 80,
|
|
187
194
|
height: 20,
|
|
188
195
|
};
|
|
189
|
-
labelParts.push(labelSvg(el.name, lb.x + lb.width / 2, lb.y + lb.height / 2, lb.width - 4, t, true));
|
|
196
|
+
labelParts.push(labelSvg(el.name, lb.x + lb.width / 2, lb.y + lb.height / 2, lb.width - 4, t, true, font));
|
|
190
197
|
}
|
|
191
198
|
}
|
|
192
199
|
// ── Assemble SVG ──────────────────────────────────────────────────────────
|
|
@@ -227,7 +234,16 @@ function isGateway(type) {
|
|
|
227
234
|
}
|
|
228
235
|
// ── Text ──────────────────────────────────────────────────────────────────────
|
|
229
236
|
const AVG_CHAR_PX = 6.5;
|
|
230
|
-
|
|
237
|
+
const DEFAULT_FAMILY = "system-ui,-apple-system,sans-serif";
|
|
238
|
+
const DEFAULT_SIZE = 11;
|
|
239
|
+
const DEFAULT_LINE_H = 14;
|
|
240
|
+
/** Estimated glyph width for a label font — scaled from the 11px default. */
|
|
241
|
+
function charPx(font) {
|
|
242
|
+
if (!font)
|
|
243
|
+
return AVG_CHAR_PX;
|
|
244
|
+
return AVG_CHAR_PX * (font.fontSize / DEFAULT_SIZE) * (font.fontWeight === "bold" ? 1.1 : 1);
|
|
245
|
+
}
|
|
246
|
+
function wrapText(text, maxPx, charW = AVG_CHAR_PX) {
|
|
231
247
|
if (!text.trim())
|
|
232
248
|
return [];
|
|
233
249
|
const words = text.split(/\s+/);
|
|
@@ -235,7 +251,7 @@ function wrapText(text, maxPx) {
|
|
|
235
251
|
let line = "";
|
|
236
252
|
for (const word of words) {
|
|
237
253
|
const candidate = line ? `${line} ${word}` : word;
|
|
238
|
-
if (candidate.length *
|
|
254
|
+
if (candidate.length * charW <= maxPx) {
|
|
239
255
|
line = candidate;
|
|
240
256
|
}
|
|
241
257
|
else if (line) {
|
|
@@ -257,18 +273,31 @@ function esc(s) {
|
|
|
257
273
|
.replace(/>/g, ">")
|
|
258
274
|
.replace(/"/g, """);
|
|
259
275
|
}
|
|
260
|
-
function
|
|
261
|
-
|
|
276
|
+
function fontStyle(font) {
|
|
277
|
+
if (!font)
|
|
278
|
+
return `font-family:${DEFAULT_FAMILY};font-size:${DEFAULT_SIZE}px`;
|
|
279
|
+
let out = `font-family:${font.fontFamily};font-size:${font.fontSize}px`;
|
|
280
|
+
if (font.fontWeight !== "normal")
|
|
281
|
+
out += `;font-weight:${font.fontWeight}`;
|
|
282
|
+
if (font.fontStyle !== "normal")
|
|
283
|
+
out += `;font-style:${font.fontStyle}`;
|
|
284
|
+
if (font.textDecoration !== "none")
|
|
285
|
+
out += `;text-decoration:${font.textDecoration}`;
|
|
286
|
+
return out;
|
|
287
|
+
}
|
|
288
|
+
/** A label's inline style, XML-escaped for a double-quoted attribute. */
|
|
289
|
+
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`);
|
|
262
291
|
}
|
|
263
292
|
/**
|
|
264
293
|
* Generates SVG text element(s) for a label centred at (cx, cy).
|
|
265
294
|
* topAlign=true makes multi-line text flow downward from cy rather than
|
|
266
295
|
* being centred around it — prevents long labels from overlapping the shape above.
|
|
267
296
|
*/
|
|
268
|
-
function labelSvg(text, cx, cy, maxWidth, t, topAlign = false) {
|
|
269
|
-
const lines = wrapText(text, maxWidth);
|
|
270
|
-
const lineH =
|
|
271
|
-
const style = textStyle(t);
|
|
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;
|
|
300
|
+
const style = textStyle(t, font);
|
|
272
301
|
if (lines.length === 1) {
|
|
273
302
|
return `<text style="${style}" x="${cx}" y="${cy}">${esc(lines[0] ?? text)}</text>`;
|
|
274
303
|
}
|
|
@@ -476,10 +505,10 @@ function renderTask(el, width, height, t, options) {
|
|
|
476
505
|
// subprocess header, so it doesn't collide with the child shapes drawn
|
|
477
506
|
// inside it (a centered label would land right where children are placed).
|
|
478
507
|
if (options?.expanded) {
|
|
479
|
-
out += labelSvg(el.name, width / 2, 14, width - 16, t, true);
|
|
508
|
+
out += labelSvg(el.name, width / 2, 14, width - 16, t, true, options.font);
|
|
480
509
|
}
|
|
481
510
|
else {
|
|
482
|
-
out += labelSvg(el.name, width / 2, height / 2, width - 16, t);
|
|
511
|
+
out += labelSvg(el.name, width / 2, height / 2, width - 16, t, false, options?.font);
|
|
483
512
|
}
|
|
484
513
|
}
|
|
485
514
|
if (type === "subProcess" ||
|
|
@@ -502,31 +531,31 @@ function renderGateway(el, width, height, t) {
|
|
|
502
531
|
}
|
|
503
532
|
return out;
|
|
504
533
|
}
|
|
505
|
-
function renderPool(participant, width, height, t) {
|
|
534
|
+
function renderPool(participant, width, height, t, font) {
|
|
506
535
|
const bodyStyle = `fill:${t.shapeFill};stroke:${t.shapeStroke};stroke-width:1.5`;
|
|
507
536
|
const headerStyle = `fill:${t.poolHeader};stroke:${t.shapeStroke};stroke-width:1.5`;
|
|
508
537
|
let out = `<rect x="0" y="0" width="${width}" height="${height}" style="${bodyStyle}"/>` +
|
|
509
538
|
`<rect x="0" y="0" width="30" height="${height}" style="${headerStyle}"/>`;
|
|
510
539
|
if (participant?.name) {
|
|
511
|
-
out += `<text style="${textStyle(t)}" transform="translate(15 ${height / 2}) rotate(-90)">${esc(participant.name)}</text>`;
|
|
540
|
+
out += `<text style="${textStyle(t, font)}" transform="translate(15 ${height / 2}) rotate(-90)">${esc(participant.name)}</text>`;
|
|
512
541
|
}
|
|
513
542
|
return out;
|
|
514
543
|
}
|
|
515
|
-
function renderLane(lane, width, height, t) {
|
|
544
|
+
function renderLane(lane, width, height, t, font) {
|
|
516
545
|
const bodyStyle = `fill:${t.shapeFill};stroke:${t.shapeStroke};stroke-width:1.5`;
|
|
517
546
|
const headerStyle = `fill:${t.poolHeader};stroke:${t.shapeStroke};stroke-width:1.5`;
|
|
518
547
|
let out = `<rect x="0" y="0" width="${width}" height="${height}" style="${bodyStyle}"/>` +
|
|
519
548
|
`<rect x="0" y="0" width="30" height="${height}" style="${headerStyle}"/>`;
|
|
520
549
|
if (lane?.name) {
|
|
521
|
-
out += `<text style="${textStyle(t)}" transform="translate(15 ${height / 2}) rotate(-90)">${esc(lane.name)}</text>`;
|
|
550
|
+
out += `<text style="${textStyle(t, font)}" transform="translate(15 ${height / 2}) rotate(-90)">${esc(lane.name)}</text>`;
|
|
522
551
|
}
|
|
523
552
|
return out;
|
|
524
553
|
}
|
|
525
|
-
function renderAnnotation(text, width, height, t) {
|
|
554
|
+
function renderAnnotation(text, width, height, t, font) {
|
|
526
555
|
const pathStyle = `fill:none;stroke:${t.shapeStroke};stroke-width:1.5`;
|
|
527
556
|
let out = `<path d="M${width} 0 L0 0 L0 ${height} L${width} ${height}" style="${pathStyle}"/>`;
|
|
528
557
|
if (text) {
|
|
529
|
-
out += labelSvg(text, width / 2, height / 2, width - 8, t);
|
|
558
|
+
out += labelSvg(text, width / 2, height / 2, width - 8, t, false, font);
|
|
530
559
|
}
|
|
531
560
|
return out;
|
|
532
561
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { BpmnDefinitions } from "../bpmn/bpmn-model.js";
|
|
2
|
+
import { type DocumentationOptions, type ProcessDocumentation } from "./model.js";
|
|
3
|
+
/** Options for {@link renderDocumentationDocx}. */
|
|
4
|
+
export interface DocxDocumentationOptions extends DocumentationOptions {
|
|
5
|
+
/** Page size. Default `"a4"`. */
|
|
6
|
+
paper?: "a4" | "letter";
|
|
7
|
+
}
|
|
8
|
+
/** Renders already-built documentation as the bytes of a Word (.docx) file. */
|
|
9
|
+
export declare function documentationToDocx(doc: ProcessDocumentation, paper?: "a4" | "letter"): Uint8Array;
|
|
10
|
+
/**
|
|
11
|
+
* Renders a BPMN model as a Word document (.docx) with the same sections as
|
|
12
|
+
* {@link renderDocumentationHtml}. Headings use Word's built-in heading styles,
|
|
13
|
+
* so the navigation pane and an inserted table of contents pick them up. The
|
|
14
|
+
* diagram is embedded as SVG on a landscape page, with no bitmap fallback:
|
|
15
|
+
* readers without SVG support (Word before 2019) show no image.
|
|
16
|
+
*
|
|
17
|
+
* Returns the file's bytes: write them to disk or wrap them in a `Blob`.
|
|
18
|
+
*/
|
|
19
|
+
export declare function renderDocumentationDocx(defs: BpmnDefinitions, options?: DocxDocumentationOptions): Uint8Array;
|
|
20
|
+
//# sourceMappingURL=docx.d.ts.map
|
package/dist/doc/docx.js
ADDED
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
import { buildProcessDocumentation, } from "./model.js";
|
|
2
|
+
import { zipStore } from "./zip.js";
|
|
3
|
+
// Page sizes in twentieths of a point (twips).
|
|
4
|
+
const PAPER = {
|
|
5
|
+
a4: { w: 11906, h: 16838 },
|
|
6
|
+
letter: { w: 12240, h: 15840 },
|
|
7
|
+
};
|
|
8
|
+
const MARGIN = 1134; // 20 mm
|
|
9
|
+
const EMU_PER_TWIP = 635;
|
|
10
|
+
const W_NS = 'xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" xmlns:pic="http://schemas.openxmlformats.org/drawingml/2006/picture"';
|
|
11
|
+
// biome-ignore lint/suspicious/noControlCharactersInRegex: matching them is the point — Word rejects a file that contains them.
|
|
12
|
+
const XML_FORBIDDEN = /[\u0000-\u0008\u000b\u000c\u000e-\u001f]/g;
|
|
13
|
+
/** XML-escapes text and drops the control characters XML 1.0 cannot carry. */
|
|
14
|
+
function x(s) {
|
|
15
|
+
return s
|
|
16
|
+
.replace(XML_FORBIDDEN, "")
|
|
17
|
+
.replace(/&/g, "&")
|
|
18
|
+
.replace(/</g, "<")
|
|
19
|
+
.replace(/>/g, ">")
|
|
20
|
+
.replace(/"/g, """);
|
|
21
|
+
}
|
|
22
|
+
function run(text, style = {}) {
|
|
23
|
+
const props = [];
|
|
24
|
+
if (style.bold)
|
|
25
|
+
props.push("<w:b/>");
|
|
26
|
+
if (style.italic)
|
|
27
|
+
props.push("<w:i/>");
|
|
28
|
+
if (style.mono)
|
|
29
|
+
props.push('<w:rFonts w:ascii="Consolas" w:hAnsi="Consolas" w:cs="Consolas"/>');
|
|
30
|
+
if (style.muted)
|
|
31
|
+
props.push('<w:color w:val="4A5058"/>');
|
|
32
|
+
const rPr = props.length > 0 ? `<w:rPr>${props.join("")}</w:rPr>` : "";
|
|
33
|
+
const lines = text.split(/\r?\n/);
|
|
34
|
+
const body = lines
|
|
35
|
+
.map((l, i) => `${i > 0 ? "<w:br/>" : ""}<w:t xml:space="preserve">${x(l)}</w:t>`)
|
|
36
|
+
.join("");
|
|
37
|
+
return `<w:r>${rPr}${body}</w:r>`;
|
|
38
|
+
}
|
|
39
|
+
function para(content, style, keepNext = false) {
|
|
40
|
+
const pPr = [];
|
|
41
|
+
if (style)
|
|
42
|
+
pPr.push(`<w:pStyle w:val="${style}"/>`);
|
|
43
|
+
if (keepNext)
|
|
44
|
+
pPr.push("<w:keepNext/>");
|
|
45
|
+
return `<w:p>${pPr.length > 0 ? `<w:pPr>${pPr.join("")}</w:pPr>` : ""}${content}</w:p>`;
|
|
46
|
+
}
|
|
47
|
+
function text(s, style, runStyle) {
|
|
48
|
+
return para(run(s, runStyle), style);
|
|
49
|
+
}
|
|
50
|
+
function tableXml(head, rows, widths) {
|
|
51
|
+
const borders = ["top", "left", "bottom", "right", "insideH", "insideV"]
|
|
52
|
+
.map((b) => `<w:${b} w:val="single" w:sz="4" w:space="0" w:color="D9DBDF"/>`)
|
|
53
|
+
.join("");
|
|
54
|
+
const grid = widths
|
|
55
|
+
? `<w:tblGrid>${widths.map((w) => `<w:gridCol w:w="${w}"/>`).join("")}</w:tblGrid>`
|
|
56
|
+
: "";
|
|
57
|
+
const cellXml = (content, header, i) => {
|
|
58
|
+
const width = widths?.[i] ? `<w:tcW w:w="${widths[i]}" w:type="dxa"/>` : "";
|
|
59
|
+
const shade = header ? '<w:shd w:val="clear" w:color="auto" w:fill="ECEEF1"/>' : "";
|
|
60
|
+
// Several values in one cell become one paragraph each.
|
|
61
|
+
const lines = Array.isArray(content) ? content : [content];
|
|
62
|
+
const paras = lines.map((l) => para(run(l, header ? { bold: true } : {}), "TableText")).join("");
|
|
63
|
+
return `<w:tc><w:tcPr>${width}${shade}</w:tcPr>${paras}</w:tc>`;
|
|
64
|
+
};
|
|
65
|
+
const headRow = `<w:tr><w:trPr><w:tblHeader/><w:cantSplit/></w:trPr>${head.map((h, i) => cellXml(h, true, i)).join("")}</w:tr>`;
|
|
66
|
+
const bodyRows = rows
|
|
67
|
+
.map((r) => `<w:tr><w:trPr><w:cantSplit/></w:trPr>${r.map((c, i) => cellXml(c, false, i)).join("")}</w:tr>`)
|
|
68
|
+
.join("");
|
|
69
|
+
return `<w:tbl><w:tblPr><w:tblW w:w="5000" w:type="pct"/><w:tblBorders>${borders}</w:tblBorders><w:tblCellMar><w:left w:w="80" w:type="dxa"/><w:right w:w="80" w:type="dxa"/></w:tblCellMar></w:tblPr>${grid}${headRow}${bodyRows}</w:tbl>${para("")}`;
|
|
70
|
+
}
|
|
71
|
+
function sectPr(paper, landscape) {
|
|
72
|
+
const size = landscape
|
|
73
|
+
? `<w:pgSz w:w="${paper.h}" w:h="${paper.w}" w:orient="landscape"/>`
|
|
74
|
+
: `<w:pgSz w:w="${paper.w}" w:h="${paper.h}"/>`;
|
|
75
|
+
return `<w:sectPr>${size}<w:pgMar w:top="${MARGIN}" w:right="${MARGIN}" w:bottom="${MARGIN}" w:left="${MARGIN}" w:header="708" w:footer="708" w:gutter="0"/></w:sectPr>`;
|
|
76
|
+
}
|
|
77
|
+
function diagramXml(svg, paper) {
|
|
78
|
+
const w = Number(/\bwidth="([\d.]+)"/.exec(svg)?.[1] ?? 0);
|
|
79
|
+
const h = Number(/\bheight="([\d.]+)"/.exec(svg)?.[1] ?? 0);
|
|
80
|
+
if (!(w > 0 && h > 0))
|
|
81
|
+
return "";
|
|
82
|
+
// Landscape page, less margins and room for the heading.
|
|
83
|
+
const maxW = (paper.h - 2 * MARGIN) * EMU_PER_TWIP;
|
|
84
|
+
const maxH = (paper.w - 2 * MARGIN - 1200) * EMU_PER_TWIP;
|
|
85
|
+
const px = 9525; // EMU per CSS pixel
|
|
86
|
+
const scale = Math.min(1, maxW / (w * px), maxH / (h * px));
|
|
87
|
+
const cx = Math.round(w * px * scale);
|
|
88
|
+
const cy = Math.round(h * px * scale);
|
|
89
|
+
// The SVG is referenced from both the plain blip and the Office SVG
|
|
90
|
+
// extension (the one Word writes itself). The spec wants a bitmap in the
|
|
91
|
+
// plain blip as a fallback for readers without SVG support; rasterising
|
|
92
|
+
// needs a canvas this package does not have, so those readers get no image.
|
|
93
|
+
const blip = `<a:blip r:embed="rIdDiagram"><a:extLst><a:ext uri="{96DAC541-7B7A-43D3-8B79-37D633B846F1}"><asvg:svgBlip xmlns:asvg="http://schemas.microsoft.com/office/drawing/2016/SVG/main" r:embed="rIdDiagram"/></a:ext></a:extLst></a:blip>`;
|
|
94
|
+
return para(`<w:r><w:drawing><wp:inline distT="0" distB="0" distL="0" distR="0"><wp:extent cx="${cx}" cy="${cy}"/><wp:docPr id="1" name="Diagram"/><a:graphic><a:graphicData uri="http://schemas.openxmlformats.org/drawingml/2006/picture"><pic:pic><pic:nvPicPr><pic:cNvPr id="1" name="diagram.svg"/><pic:cNvPicPr/></pic:nvPicPr><pic:blipFill>${blip}<a:stretch><a:fillRect/></a:stretch></pic:blipFill><pic:spPr><a:xfrm><a:off x="0" y="0"/><a:ext cx="${cx}" cy="${cy}"/></a:xfrm><a:prstGeom prst="rect"><a:avLst/></a:prstGeom></pic:spPr></pic:pic></a:graphicData></a:graphic></wp:inline></w:drawing></w:r>`);
|
|
95
|
+
}
|
|
96
|
+
function processXml(p) {
|
|
97
|
+
const out = [text(p.title, "Heading1")];
|
|
98
|
+
const meta = [`Process ID ${p.id}`];
|
|
99
|
+
if (p.participant)
|
|
100
|
+
meta.push("drawn as a pool");
|
|
101
|
+
meta.push(p.executable ? "executable" : "not executable");
|
|
102
|
+
out.push(text(meta.join(" · "), undefined, { muted: true }));
|
|
103
|
+
if (p.documentation)
|
|
104
|
+
out.push(text(p.documentation));
|
|
105
|
+
if (p.lanes.length > 0) {
|
|
106
|
+
out.push(text("Lanes and performers", "Heading2"));
|
|
107
|
+
out.push(tableXml(["Lane", "Responsible for"], p.lanes.map((l) => [[...l.path, l.name].join(" / "), l.elements.join(", ") || "—"])));
|
|
108
|
+
}
|
|
109
|
+
if (p.elements.length === 0) {
|
|
110
|
+
out.push(text("This process has no elements.", undefined, { italic: true }));
|
|
111
|
+
return out;
|
|
112
|
+
}
|
|
113
|
+
const laneCol = p.lanes.length > 0;
|
|
114
|
+
out.push(text("Steps at a glance", "Heading2"));
|
|
115
|
+
out.push(tableXml(["#", "Name", "Type", ...(laneCol ? ["Lane"] : [])], p.elements.map((el) => [
|
|
116
|
+
el.number,
|
|
117
|
+
el.name ?? el.id,
|
|
118
|
+
el.typeLabel,
|
|
119
|
+
...(laneCol ? [el.lane ?? ""] : []),
|
|
120
|
+
]), laneCol ? [900, 3600, 2700, 2400] : [900, 4800, 3900]));
|
|
121
|
+
out.push(text("Step details", "Heading2"));
|
|
122
|
+
for (const el of p.elements) {
|
|
123
|
+
out.push(text(`${el.number} ${el.name ?? el.id}`, "Heading3"));
|
|
124
|
+
out.push(para(run(el.typeLabel, { italic: true, muted: true }), undefined, true));
|
|
125
|
+
if (el.documentation)
|
|
126
|
+
out.push(para(run(el.documentation), undefined, true));
|
|
127
|
+
const rows = [];
|
|
128
|
+
if (el.lane)
|
|
129
|
+
rows.push(["Lane", el.lane]);
|
|
130
|
+
for (const prop of el.properties)
|
|
131
|
+
rows.push([prop.label, prop.value]);
|
|
132
|
+
rows.push(["ID", el.id]);
|
|
133
|
+
out.push(tableXml(["Property", "Value"], rows, [2600, 7000]));
|
|
134
|
+
}
|
|
135
|
+
return out;
|
|
136
|
+
}
|
|
137
|
+
function documentXml(doc, paper) {
|
|
138
|
+
const body = [
|
|
139
|
+
text("PROCESS DOCUMENTATION", undefined, { muted: true }),
|
|
140
|
+
text(doc.title, "Title"),
|
|
141
|
+
];
|
|
142
|
+
if (doc.subtitle)
|
|
143
|
+
body.push(text(doc.subtitle, undefined, { muted: true }));
|
|
144
|
+
if (doc.documentation)
|
|
145
|
+
body.push(text(doc.documentation));
|
|
146
|
+
const diagram = doc.diagramSvg ? diagramXml(doc.diagramSvg, paper) : "";
|
|
147
|
+
if (diagram) {
|
|
148
|
+
// The diagram gets a landscape section of its own; everything else is portrait.
|
|
149
|
+
body.push(`<w:p><w:pPr>${sectPr(paper, false)}</w:pPr></w:p>`);
|
|
150
|
+
body.push(text("Diagram", "Heading1"), diagram);
|
|
151
|
+
body.push(`<w:p><w:pPr>${sectPr(paper, true)}</w:pPr></w:p>`);
|
|
152
|
+
}
|
|
153
|
+
doc.processes.forEach((p, i) => {
|
|
154
|
+
if (i > 0 || !diagram)
|
|
155
|
+
body.push(para('<w:r><w:br w:type="page"/></w:r>'));
|
|
156
|
+
body.push(...processXml(p));
|
|
157
|
+
});
|
|
158
|
+
if (doc.messageFlows.length > 0) {
|
|
159
|
+
body.push(text("Message flows", "Heading1"));
|
|
160
|
+
body.push(tableXml(["From", "To", "Message"], doc.messageFlows.map((m) => [m.from, m.to, m.name ?? m.message ?? ""])));
|
|
161
|
+
}
|
|
162
|
+
if (doc.decisions.length > 0) {
|
|
163
|
+
body.push(text("Decisions", "Heading1"));
|
|
164
|
+
for (const d of doc.decisions) {
|
|
165
|
+
body.push(text(d.name, "Heading2"));
|
|
166
|
+
const meta = [`Decision ID ${d.id}`, `hit policy ${d.hitPolicy}`];
|
|
167
|
+
if (d.calledBy.length > 0)
|
|
168
|
+
meta.push(`called by ${d.calledBy.join(", ")}`);
|
|
169
|
+
body.push(text(meta.join(" · "), undefined, { muted: true }));
|
|
170
|
+
body.push(tableXml([
|
|
171
|
+
"#",
|
|
172
|
+
...d.inputs.map((i) => `When: ${i}`),
|
|
173
|
+
...d.outputs.map((o) => `Then: ${o}`),
|
|
174
|
+
"Note",
|
|
175
|
+
], d.rules.map((r, i) => [String(i + 1), ...r])));
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
if (doc.forms.length > 0) {
|
|
179
|
+
body.push(text("Forms", "Heading1"));
|
|
180
|
+
for (const f of doc.forms) {
|
|
181
|
+
body.push(text(f.id, "Heading2"));
|
|
182
|
+
if (f.usedBy.length > 0)
|
|
183
|
+
body.push(text(`Shown by ${f.usedBy.join(", ")}`, undefined, { muted: true }));
|
|
184
|
+
if (f.fields.length === 0) {
|
|
185
|
+
body.push(text("This form has no input fields.", undefined, { italic: true }));
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
188
|
+
body.push(tableXml(["Field", "Variable", "Type", "Required", "Options"], f.fields.map((field) => [
|
|
189
|
+
field.label,
|
|
190
|
+
field.key,
|
|
191
|
+
field.type,
|
|
192
|
+
field.required ? "Yes" : "No",
|
|
193
|
+
field.options,
|
|
194
|
+
])));
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
return `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n<w:document ${W_NS}><w:body>${body.join("")}${sectPr(paper, false)}</w:body></w:document>`;
|
|
198
|
+
}
|
|
199
|
+
const STYLES = `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
200
|
+
<w:styles xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
|
|
201
|
+
<w:docDefaults><w:rPrDefault><w:rPr><w:rFonts w:ascii="Calibri" w:hAnsi="Calibri" w:eastAsia="Calibri" w:cs="Calibri"/><w:sz w:val="21"/><w:szCs w:val="21"/><w:color w:val="14161A"/><w:lang w:val="en-US"/></w:rPr></w:rPrDefault><w:pPrDefault><w:pPr><w:spacing w:after="120" w:line="264" w:lineRule="auto"/></w:pPr></w:pPrDefault></w:docDefaults>
|
|
202
|
+
<w:style w:type="paragraph" w:default="1" w:styleId="Normal"><w:name w:val="Normal"/><w:qFormat/></w:style>
|
|
203
|
+
<w:style w:type="paragraph" w:styleId="Title"><w:name w:val="Title"/><w:basedOn w:val="Normal"/><w:next w:val="Normal"/><w:qFormat/><w:pPr><w:spacing w:after="240"/></w:pPr><w:rPr><w:b/><w:sz w:val="56"/><w:szCs w:val="56"/></w:rPr></w:style>
|
|
204
|
+
<w:style w:type="paragraph" w:styleId="Heading1"><w:name w:val="heading 1"/><w:basedOn w:val="Normal"/><w:next w:val="Normal"/><w:qFormat/><w:pPr><w:keepNext/><w:spacing w:before="240" w:after="160"/><w:pBdr><w:bottom w:val="single" w:sz="4" w:space="4" w:color="D9DBDF"/></w:pBdr><w:outlineLvl w:val="0"/></w:pPr><w:rPr><w:b/><w:sz w:val="36"/><w:szCs w:val="36"/></w:rPr></w:style>
|
|
205
|
+
<w:style w:type="paragraph" w:styleId="Heading2"><w:name w:val="heading 2"/><w:basedOn w:val="Normal"/><w:next w:val="Normal"/><w:qFormat/><w:pPr><w:keepNext/><w:spacing w:before="240" w:after="100"/><w:outlineLvl w:val="1"/></w:pPr><w:rPr><w:b/><w:sz w:val="28"/><w:szCs w:val="28"/></w:rPr></w:style>
|
|
206
|
+
<w:style w:type="paragraph" w:styleId="Heading3"><w:name w:val="heading 3"/><w:basedOn w:val="Normal"/><w:next w:val="Normal"/><w:qFormat/><w:pPr><w:keepNext/><w:spacing w:before="200" w:after="40"/><w:outlineLvl w:val="2"/></w:pPr><w:rPr><w:b/><w:color w:val="A8503A"/><w:sz w:val="23"/><w:szCs w:val="23"/></w:rPr></w:style>
|
|
207
|
+
<w:style w:type="paragraph" w:styleId="TableText"><w:name w:val="Table Text"/><w:basedOn w:val="Normal"/><w:pPr><w:spacing w:before="20" w:after="20"/></w:pPr><w:rPr><w:sz w:val="19"/><w:szCs w:val="19"/></w:rPr></w:style>
|
|
208
|
+
</w:styles>`;
|
|
209
|
+
const CONTENT_TYPES = `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
210
|
+
<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types"><Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/><Default Extension="xml" ContentType="application/xml"/><Default Extension="svg" ContentType="image/svg+xml"/><Override PartName="/word/document.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml"/><Override PartName="/word/styles.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml"/></Types>`;
|
|
211
|
+
const ROOT_RELS = `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
212
|
+
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="word/document.xml"/></Relationships>`;
|
|
213
|
+
function documentRels(withDiagram) {
|
|
214
|
+
const image = withDiagram
|
|
215
|
+
? '<Relationship Id="rIdDiagram" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/image" Target="media/diagram.svg"/>'
|
|
216
|
+
: "";
|
|
217
|
+
return `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
218
|
+
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rIdStyles" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles" Target="styles.xml"/>${image}</Relationships>`;
|
|
219
|
+
}
|
|
220
|
+
/** Renders already-built documentation as the bytes of a Word (.docx) file. */
|
|
221
|
+
export function documentationToDocx(doc, paper = "a4") {
|
|
222
|
+
const size = PAPER[paper];
|
|
223
|
+
const enc = new TextEncoder();
|
|
224
|
+
const document = documentXml(doc, size);
|
|
225
|
+
const withDiagram = document.includes('r:embed="rIdDiagram"');
|
|
226
|
+
const files = [
|
|
227
|
+
{ name: "[Content_Types].xml", data: enc.encode(CONTENT_TYPES) },
|
|
228
|
+
{ name: "_rels/.rels", data: enc.encode(ROOT_RELS) },
|
|
229
|
+
{ name: "word/document.xml", data: enc.encode(document) },
|
|
230
|
+
{ name: "word/styles.xml", data: enc.encode(STYLES) },
|
|
231
|
+
{ name: "word/_rels/document.xml.rels", data: enc.encode(documentRels(withDiagram)) },
|
|
232
|
+
];
|
|
233
|
+
if (withDiagram && doc.diagramSvg) {
|
|
234
|
+
// Label halos rely on `paint-order`, which Word and LibreOffice ignore:
|
|
235
|
+
// the halo would be painted over the text and hide it.
|
|
236
|
+
const svg = doc.diagramSvg.replace(/;paint-order:stroke;stroke:[^;"]+;stroke-width:[^;"]+/g, "");
|
|
237
|
+
files.push({ name: "word/media/diagram.svg", data: enc.encode(svg) });
|
|
238
|
+
}
|
|
239
|
+
return zipStore(files);
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Renders a BPMN model as a Word document (.docx) with the same sections as
|
|
243
|
+
* {@link renderDocumentationHtml}. Headings use Word's built-in heading styles,
|
|
244
|
+
* so the navigation pane and an inserted table of contents pick them up. The
|
|
245
|
+
* diagram is embedded as SVG on a landscape page, with no bitmap fallback:
|
|
246
|
+
* readers without SVG support (Word before 2019) show no image.
|
|
247
|
+
*
|
|
248
|
+
* Returns the file's bytes: write them to disk or wrap them in a `Blob`.
|
|
249
|
+
*/
|
|
250
|
+
export function renderDocumentationDocx(defs, options = {}) {
|
|
251
|
+
return documentationToDocx(buildProcessDocumentation(defs, options), options.paper);
|
|
252
|
+
}
|
|
253
|
+
//# sourceMappingURL=docx.js.map
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { BpmnDefinitions } from "../bpmn/bpmn-model.js";
|
|
2
|
+
import { type DocumentationOptions, type ProcessDocumentation } from "./model.js";
|
|
3
|
+
export declare function escapeHtml(s: string): string;
|
|
4
|
+
/** Renders already-built documentation as a standalone HTML document. */
|
|
5
|
+
export declare function documentationToHtml(doc: ProcessDocumentation): string;
|
|
6
|
+
/**
|
|
7
|
+
* Renders a BPMN model as a self-contained, print-ready HTML document: the
|
|
8
|
+
* diagram as inline SVG, a table of contents, one section per process or pool
|
|
9
|
+
* with its lanes and every element in flow order, then any message flows,
|
|
10
|
+
* decision tables and forms. No scripts, no network requests. The browser's
|
|
11
|
+
* Print → Save as PDF gives a paginated PDF on A4 or Letter.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* import { Bpmn, renderDocumentationHtml } from "@bpmnkit/core"
|
|
16
|
+
*
|
|
17
|
+
* const html = renderDocumentationHtml(Bpmn.parse(xml), { title: "Order to Cash" })
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare function renderDocumentationHtml(defs: BpmnDefinitions, options?: DocumentationOptions): string;
|
|
21
|
+
//# sourceMappingURL=html.d.ts.map
|