@the-docs/plugin-bpmn 0.0.1-alpha.4
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/build/index.d.ts +3 -0
- package/dist/build/index.d.ts.map +1 -0
- package/dist/build/index.js +3 -0
- package/dist/build/index.js.map +1 -0
- package/dist/build/rehype.d.ts +9 -0
- package/dist/build/rehype.d.ts.map +1 -0
- package/dist/build/rehype.js +139 -0
- package/dist/build/rehype.js.map +1 -0
- package/dist/build/render.d.ts +12 -0
- package/dist/build/render.d.ts.map +1 -0
- package/dist/build/render.js +295 -0
- package/dist/build/render.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +49 -0
- package/dist/index.js.map +1 -0
- package/dist/runtime/bpmn-image.d.ts +8 -0
- package/dist/runtime/bpmn-image.d.ts.map +1 -0
- package/dist/runtime/bpmn-image.js +5 -0
- package/dist/runtime/bpmn-image.js.map +1 -0
- package/dist/types.d.ts +17 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +10 -0
- package/dist/types.js.map +1 -0
- package/package.json +41 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/build/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/build/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Root } from "hast";
|
|
2
|
+
import type { BpmnPluginOptions } from "../types.js";
|
|
3
|
+
interface VFileLike {
|
|
4
|
+
path?: string;
|
|
5
|
+
}
|
|
6
|
+
/** Replaces Markdown images that reference .bpmn files with generated SVGs. */
|
|
7
|
+
export declare function bpmnRehypePlugin(options?: BpmnPluginOptions): () => (tree: Root, file: VFileLike) => Promise<void>;
|
|
8
|
+
export {};
|
|
9
|
+
//# sourceMappingURL=rehype.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rehype.d.ts","sourceRoot":"","sources":["../../src/build/rehype.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAW,IAAI,EAAE,MAAM,MAAM,CAAA;AAGzC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAkBpD,UAAU,SAAS;IACjB,IAAI,CAAC,EAAE,MAAM,CAAA;CACd;AAoGD,+EAA+E;AAC/E,wBAAgB,gBAAgB,CAAC,OAAO,GAAE,iBAAsB,UAI5B,MAAM,IAAI,EAAE,MAAM,SAAS,mBAiD9D"}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import { dirname, extname, resolve } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import { bpmnPlugin } from "../index.js";
|
|
5
|
+
const runtimeModuleId = fileURLToPath(new URL("../runtime/bpmn-image.js", import.meta.url));
|
|
6
|
+
const runtimeImport = `import BpmnImage from ${JSON.stringify(runtimeModuleId)}`;
|
|
7
|
+
function importNode() {
|
|
8
|
+
return {
|
|
9
|
+
type: "mdxjsEsm",
|
|
10
|
+
value: runtimeImport,
|
|
11
|
+
data: {
|
|
12
|
+
estree: {
|
|
13
|
+
type: "Program",
|
|
14
|
+
sourceType: "module",
|
|
15
|
+
body: [
|
|
16
|
+
{
|
|
17
|
+
type: "ImportDeclaration",
|
|
18
|
+
specifiers: [
|
|
19
|
+
{
|
|
20
|
+
type: "ImportDefaultSpecifier",
|
|
21
|
+
local: { type: "Identifier", name: "BpmnImage" },
|
|
22
|
+
},
|
|
23
|
+
],
|
|
24
|
+
source: {
|
|
25
|
+
type: "Literal",
|
|
26
|
+
value: runtimeModuleId,
|
|
27
|
+
raw: JSON.stringify(runtimeModuleId),
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
],
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
function modelExpression(model) {
|
|
36
|
+
const serialized = JSON.stringify(model);
|
|
37
|
+
const source = `JSON.parse(${JSON.stringify(serialized)})`;
|
|
38
|
+
return {
|
|
39
|
+
type: "mdxJsxAttributeValueExpression",
|
|
40
|
+
value: source,
|
|
41
|
+
data: {
|
|
42
|
+
estree: {
|
|
43
|
+
type: "Program",
|
|
44
|
+
sourceType: "module",
|
|
45
|
+
body: [
|
|
46
|
+
{
|
|
47
|
+
type: "ExpressionStatement",
|
|
48
|
+
expression: {
|
|
49
|
+
type: "CallExpression",
|
|
50
|
+
optional: false,
|
|
51
|
+
callee: {
|
|
52
|
+
type: "MemberExpression",
|
|
53
|
+
computed: false,
|
|
54
|
+
optional: false,
|
|
55
|
+
object: { type: "Identifier", name: "JSON" },
|
|
56
|
+
property: { type: "Identifier", name: "parse" },
|
|
57
|
+
},
|
|
58
|
+
arguments: [
|
|
59
|
+
{
|
|
60
|
+
type: "Literal",
|
|
61
|
+
value: serialized,
|
|
62
|
+
raw: JSON.stringify(serialized),
|
|
63
|
+
},
|
|
64
|
+
],
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
],
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
function componentNode(model, alt) {
|
|
73
|
+
return {
|
|
74
|
+
type: "mdxJsxFlowElement",
|
|
75
|
+
name: "BpmnImage",
|
|
76
|
+
attributes: [
|
|
77
|
+
{
|
|
78
|
+
type: "mdxJsxAttribute",
|
|
79
|
+
name: "model",
|
|
80
|
+
value: modelExpression(model),
|
|
81
|
+
},
|
|
82
|
+
{ type: "mdxJsxAttribute", name: "alt", value: alt },
|
|
83
|
+
],
|
|
84
|
+
children: [],
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
function bpmnUrl(node) {
|
|
88
|
+
if (node.tagName !== "img" || typeof node.properties.src !== "string") {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
const url = node.properties.src;
|
|
92
|
+
if (/^(?:[a-z]+:|\/\/|\/)/i.test(url))
|
|
93
|
+
return;
|
|
94
|
+
const cleanUrl = decodeURIComponent(url.split(/[?#]/, 1)[0] ?? "");
|
|
95
|
+
if (extname(cleanUrl).toLowerCase() !== ".bpmn")
|
|
96
|
+
return;
|
|
97
|
+
return { cleanUrl, url };
|
|
98
|
+
}
|
|
99
|
+
/** Replaces Markdown images that reference .bpmn files with generated SVGs. */
|
|
100
|
+
export function bpmnRehypePlugin(options = {}) {
|
|
101
|
+
const plugin = bpmnPlugin(options);
|
|
102
|
+
return function attacher() {
|
|
103
|
+
return async function transform(tree, file) {
|
|
104
|
+
if (!file.path) {
|
|
105
|
+
throw new Error("BPMN assets require an MDX file path");
|
|
106
|
+
}
|
|
107
|
+
const matches = [];
|
|
108
|
+
const visit = (parent) => {
|
|
109
|
+
parent.children.forEach((child, index) => {
|
|
110
|
+
if (child.type !== "element")
|
|
111
|
+
return;
|
|
112
|
+
const node = child;
|
|
113
|
+
const asset = bpmnUrl(node);
|
|
114
|
+
if (asset)
|
|
115
|
+
matches.push({ parent, index, node, ...asset });
|
|
116
|
+
visit(node);
|
|
117
|
+
});
|
|
118
|
+
};
|
|
119
|
+
visit(tree);
|
|
120
|
+
if (!matches.length)
|
|
121
|
+
return;
|
|
122
|
+
await Promise.all(matches.map(async ({ parent, index, node, cleanUrl, url }) => {
|
|
123
|
+
const assetPath = resolve(dirname(file.path), cleanUrl);
|
|
124
|
+
const content = await readFile(assetPath);
|
|
125
|
+
const model = await plugin.parse({
|
|
126
|
+
kind: "asset",
|
|
127
|
+
url,
|
|
128
|
+
extension: ".bpmn",
|
|
129
|
+
content,
|
|
130
|
+
documentPath: file.path,
|
|
131
|
+
}, {});
|
|
132
|
+
const alt = typeof node.properties.alt === "string" ? node.properties.alt : "";
|
|
133
|
+
parent.children[index] = componentNode(model, alt);
|
|
134
|
+
}));
|
|
135
|
+
tree.children.unshift(importNode());
|
|
136
|
+
};
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
//# sourceMappingURL=rehype.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rehype.js","sourceRoot":"","sources":["../../src/build/rehype.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAC3C,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAIxC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAGxC,MAAM,eAAe,GAAG,aAAa,CACnC,IAAI,GAAG,CAAC,0BAA0B,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CACrD,CAAA;AACD,MAAM,aAAa,GAAG,yBAAyB,IAAI,CAAC,SAAS,CAAC,eAAe,CAAC,EAAE,CAAA;AAiBhF,SAAS,UAAU;IACjB,OAAO;QACL,IAAI,EAAE,UAAU;QAChB,KAAK,EAAE,aAAa;QACpB,IAAI,EAAE;YACJ,MAAM,EAAE;gBACN,IAAI,EAAE,SAAS;gBACf,UAAU,EAAE,QAAQ;gBACpB,IAAI,EAAE;oBACJ;wBACE,IAAI,EAAE,mBAAmB;wBACzB,UAAU,EAAE;4BACV;gCACE,IAAI,EAAE,wBAAwB;gCAC9B,KAAK,EAAE,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,WAAW,EAAE;6BACjD;yBACF;wBACD,MAAM,EAAE;4BACN,IAAI,EAAE,SAAS;4BACf,KAAK,EAAE,eAAe;4BACtB,GA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CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface RenderBpmnOptions {
|
|
2
|
+
padding?: number;
|
|
3
|
+
signal?: AbortSignal;
|
|
4
|
+
}
|
|
5
|
+
export interface RenderedBpmnSvg {
|
|
6
|
+
svg: string;
|
|
7
|
+
width: number;
|
|
8
|
+
height: number;
|
|
9
|
+
}
|
|
10
|
+
/** Render a BPMN 2.0 XML diagram to a self-contained SVG at build time. */
|
|
11
|
+
export declare function renderBpmnToSvg(content: Uint8Array, { padding, signal }?: RenderBpmnOptions): Promise<RenderedBpmnSvg>;
|
|
12
|
+
//# sourceMappingURL=render.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../../src/build/render.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,iBAAiB;IAChC,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,MAAM,CAAC,EAAE,WAAW,CAAA;CACrB;AAED,MAAM,WAAW,eAAe;IAC9B,GAAG,EAAE,MAAM,CAAA;IACX,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;CACf;AAyMD,2EAA2E;AAC3E,wBAAsB,eAAe,CACnC,OAAO,EAAE,UAAU,EACnB,EAAE,OAAY,EAAE,MAAM,EAAE,GAAE,iBAAsB,GAC/C,OAAO,CAAC,eAAe,CAAC,CA2G1B"}
|
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import { JSDOM, VirtualConsole } from "jsdom";
|
|
3
|
+
let bpmnViewerSource;
|
|
4
|
+
function loadBpmnViewerSource() {
|
|
5
|
+
bpmnViewerSource ??= readFile(new URL(import.meta.resolve("bpmn-js/dist/bpmn-viewer.production.min.js")), "utf8");
|
|
6
|
+
return bpmnViewerSource;
|
|
7
|
+
}
|
|
8
|
+
/*
|
|
9
|
+
* diagram-js relies on the browser SVG geometry API while importing BPMN.
|
|
10
|
+
* JSDOM does not implement that API, so provide the matrix, transform, point,
|
|
11
|
+
* and bounding-box operations needed by the read-only BPMN viewer.
|
|
12
|
+
*/
|
|
13
|
+
const svgGeometryPolyfill = String.raw `
|
|
14
|
+
class BpmnSvgMatrix {
|
|
15
|
+
constructor(a = 1, b = 0, c = 0, d = 1, e = 0, f = 0) {
|
|
16
|
+
Object.assign(this, { a, b, c, d, e, f })
|
|
17
|
+
}
|
|
18
|
+
multiply(other) {
|
|
19
|
+
return new BpmnSvgMatrix(
|
|
20
|
+
this.a * other.a + this.c * other.b,
|
|
21
|
+
this.b * other.a + this.d * other.b,
|
|
22
|
+
this.a * other.c + this.c * other.d,
|
|
23
|
+
this.b * other.c + this.d * other.d,
|
|
24
|
+
this.a * other.e + this.c * other.f + this.e,
|
|
25
|
+
this.b * other.e + this.d * other.f + this.f,
|
|
26
|
+
)
|
|
27
|
+
}
|
|
28
|
+
translate(x, y = 0) {
|
|
29
|
+
return this.multiply(new BpmnSvgMatrix(1, 0, 0, 1, x, y))
|
|
30
|
+
}
|
|
31
|
+
scale(value) {
|
|
32
|
+
return this.multiply(new BpmnSvgMatrix(value, 0, 0, value, 0, 0))
|
|
33
|
+
}
|
|
34
|
+
inverse() {
|
|
35
|
+
const determinant = this.a * this.d - this.b * this.c
|
|
36
|
+
if (!determinant) return new BpmnSvgMatrix()
|
|
37
|
+
return new BpmnSvgMatrix(
|
|
38
|
+
this.d / determinant,
|
|
39
|
+
-this.b / determinant,
|
|
40
|
+
-this.c / determinant,
|
|
41
|
+
this.a / determinant,
|
|
42
|
+
(this.c * this.f - this.d * this.e) / determinant,
|
|
43
|
+
(this.b * this.e - this.a * this.f) / determinant,
|
|
44
|
+
)
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
class BpmnSvgTransform {
|
|
48
|
+
constructor(matrix = new BpmnSvgMatrix()) { this.matrix = matrix }
|
|
49
|
+
setMatrix(matrix) { this.matrix = matrix }
|
|
50
|
+
setTranslate(x, y) { this.matrix = new BpmnSvgMatrix(1, 0, 0, 1, x, y) }
|
|
51
|
+
setScale(x, y) { this.matrix = new BpmnSvgMatrix(x, 0, 0, y, 0, 0) }
|
|
52
|
+
setRotate(angle, x, y) {
|
|
53
|
+
const radians = angle * Math.PI / 180
|
|
54
|
+
const rotation = new BpmnSvgMatrix(
|
|
55
|
+
Math.cos(radians), Math.sin(radians),
|
|
56
|
+
-Math.sin(radians), Math.cos(radians), 0, 0,
|
|
57
|
+
)
|
|
58
|
+
this.matrix = new BpmnSvgMatrix().translate(x, y)
|
|
59
|
+
.multiply(rotation).translate(-x, -y)
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
window.SVGMatrix = BpmnSvgMatrix
|
|
63
|
+
window.SVGTransform = BpmnSvgTransform
|
|
64
|
+
|
|
65
|
+
const bpmnTransformLists = new WeakMap()
|
|
66
|
+
function bpmnMatrixText(matrix) {
|
|
67
|
+
return "matrix(" + [matrix.a, matrix.b, matrix.c, matrix.d, matrix.e, matrix.f].join(" ") + ")"
|
|
68
|
+
}
|
|
69
|
+
function bpmnTransformList(element) {
|
|
70
|
+
let transforms = bpmnTransformLists.get(element)
|
|
71
|
+
if (transforms) return transforms
|
|
72
|
+
const items = []
|
|
73
|
+
transforms = {
|
|
74
|
+
clear() { items.length = 0; element.removeAttribute("transform") },
|
|
75
|
+
appendItem(item) {
|
|
76
|
+
items.push(item)
|
|
77
|
+
element.setAttribute("transform", bpmnMatrixText(this.consolidate().matrix))
|
|
78
|
+
return item
|
|
79
|
+
},
|
|
80
|
+
createSVGTransformFromMatrix(matrix) { return new BpmnSvgTransform(matrix) },
|
|
81
|
+
consolidate() {
|
|
82
|
+
if (!items.length) return null
|
|
83
|
+
return new BpmnSvgTransform(
|
|
84
|
+
items.reduce((matrix, item) => matrix.multiply(item.matrix), new BpmnSvgMatrix())
|
|
85
|
+
)
|
|
86
|
+
},
|
|
87
|
+
}
|
|
88
|
+
bpmnTransformLists.set(element, transforms)
|
|
89
|
+
return transforms
|
|
90
|
+
}
|
|
91
|
+
Object.defineProperty(SVGElement.prototype, "transform", {
|
|
92
|
+
configurable: true,
|
|
93
|
+
get() { return { baseVal: bpmnTransformList(this) } },
|
|
94
|
+
})
|
|
95
|
+
SVGSVGElement.prototype.createSVGMatrix = () => new BpmnSvgMatrix()
|
|
96
|
+
SVGSVGElement.prototype.createSVGTransform = () => new BpmnSvgTransform()
|
|
97
|
+
SVGSVGElement.prototype.createSVGPoint = () => ({
|
|
98
|
+
x: 0,
|
|
99
|
+
y: 0,
|
|
100
|
+
matrixTransform(matrix) {
|
|
101
|
+
return {
|
|
102
|
+
x: matrix.a * this.x + matrix.c * this.y + matrix.e,
|
|
103
|
+
y: matrix.b * this.x + matrix.d * this.y + matrix.f,
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
function bpmnNumbers(value) {
|
|
109
|
+
return (value || "").match(/-?\d*\.?\d+(?:e[-+]?\d+)?/gi)?.map(Number) || []
|
|
110
|
+
}
|
|
111
|
+
function bpmnBox(x = 0, y = 0, width = 0, height = 0) {
|
|
112
|
+
return { x, y, width, height }
|
|
113
|
+
}
|
|
114
|
+
function bpmnUnion(boxes) {
|
|
115
|
+
const valid = boxes.filter((box) => box && Number.isFinite(box.x) && Number.isFinite(box.y))
|
|
116
|
+
if (!valid.length) return bpmnBox()
|
|
117
|
+
const x = Math.min(...valid.map((box) => box.x))
|
|
118
|
+
const y = Math.min(...valid.map((box) => box.y))
|
|
119
|
+
const right = Math.max(...valid.map((box) => box.x + box.width))
|
|
120
|
+
const bottom = Math.max(...valid.map((box) => box.y + box.height))
|
|
121
|
+
return bpmnBox(x, y, right - x, bottom - y)
|
|
122
|
+
}
|
|
123
|
+
function bpmnAttributeMatrix(value) {
|
|
124
|
+
let matrix = new BpmnSvgMatrix()
|
|
125
|
+
for (const part of (value || "").matchAll(/(matrix|translate|scale|rotate)\s*\(([^)]*)\)/g)) {
|
|
126
|
+
const values = bpmnNumbers(part[2])
|
|
127
|
+
let next = new BpmnSvgMatrix()
|
|
128
|
+
if (part[1] === "matrix") next = new BpmnSvgMatrix(...values.slice(0, 6))
|
|
129
|
+
if (part[1] === "translate") next = next.translate(values[0] || 0, values[1] || 0)
|
|
130
|
+
if (part[1] === "scale") {
|
|
131
|
+
const x = values[0] ?? 1
|
|
132
|
+
const y = values[1] ?? x
|
|
133
|
+
next = new BpmnSvgMatrix(x, 0, 0, y, 0, 0)
|
|
134
|
+
}
|
|
135
|
+
if (part[1] === "rotate") {
|
|
136
|
+
const transform = new BpmnSvgTransform()
|
|
137
|
+
transform.setRotate(values[0] || 0, values[1] || 0, values[2] || 0)
|
|
138
|
+
next = transform.matrix
|
|
139
|
+
}
|
|
140
|
+
matrix = matrix.multiply(next)
|
|
141
|
+
}
|
|
142
|
+
return matrix
|
|
143
|
+
}
|
|
144
|
+
function bpmnTransformBox(box, matrix) {
|
|
145
|
+
const points = [
|
|
146
|
+
[box.x, box.y],
|
|
147
|
+
[box.x + box.width, box.y],
|
|
148
|
+
[box.x, box.y + box.height],
|
|
149
|
+
[box.x + box.width, box.y + box.height],
|
|
150
|
+
].map(([x, y]) => [matrix.a * x + matrix.c * y + matrix.e, matrix.b * x + matrix.d * y + matrix.f])
|
|
151
|
+
const xs = points.map(([x]) => x)
|
|
152
|
+
const ys = points.map(([, y]) => y)
|
|
153
|
+
return bpmnBox(Math.min(...xs), Math.min(...ys), Math.max(...xs) - Math.min(...xs), Math.max(...ys) - Math.min(...ys))
|
|
154
|
+
}
|
|
155
|
+
SVGElement.prototype.getBBox = function () {
|
|
156
|
+
const number = (name) => Number(this.getAttribute(name)) || 0
|
|
157
|
+
const tag = this.tagName.toLowerCase()
|
|
158
|
+
let own
|
|
159
|
+
if (tag === "rect" || tag === "image" || tag === "foreignobject") {
|
|
160
|
+
own = bpmnBox(number("x"), number("y"), number("width"), number("height"))
|
|
161
|
+
} else if (tag === "circle") {
|
|
162
|
+
own = bpmnBox(number("cx") - number("r"), number("cy") - number("r"), number("r") * 2, number("r") * 2)
|
|
163
|
+
} else if (tag === "ellipse") {
|
|
164
|
+
own = bpmnBox(number("cx") - number("rx"), number("cy") - number("ry"), number("rx") * 2, number("ry") * 2)
|
|
165
|
+
} else if (tag === "line") {
|
|
166
|
+
own = bpmnUnion([bpmnBox(number("x1"), number("y1")), bpmnBox(number("x2"), number("y2"))])
|
|
167
|
+
} else if (tag === "text" || tag === "tspan") {
|
|
168
|
+
const fontSize = Number.parseFloat(getComputedStyle(this).fontSize) || 12
|
|
169
|
+
own = bpmnBox(number("x"), number("y") - fontSize, Math.max(1, (this.textContent || "").length * fontSize * 0.6), fontSize * 1.2)
|
|
170
|
+
} else if (tag === "path" || tag === "polygon" || tag === "polyline") {
|
|
171
|
+
const values = bpmnNumbers(this.getAttribute(tag === "path" ? "d" : "points"))
|
|
172
|
+
const points = []
|
|
173
|
+
for (let index = 0; index + 1 < values.length; index += 2) {
|
|
174
|
+
points.push(bpmnBox(values[index], values[index + 1]))
|
|
175
|
+
}
|
|
176
|
+
own = bpmnUnion(points)
|
|
177
|
+
}
|
|
178
|
+
const childBoxes = Array.from(this.children)
|
|
179
|
+
.filter((child) => !["defs", "style", "title", "desc"].includes(child.tagName.toLowerCase()))
|
|
180
|
+
.map((child) => bpmnTransformBox(child.getBBox(), bpmnAttributeMatrix(child.getAttribute("transform"))))
|
|
181
|
+
.filter((box) => box.width || box.height)
|
|
182
|
+
const children = childBoxes.length ? bpmnUnion(childBoxes) : undefined
|
|
183
|
+
return bpmnUnion([own, children].filter(Boolean))
|
|
184
|
+
}
|
|
185
|
+
SVGElement.prototype.getCTM = function () { return bpmnAttributeMatrix(this.getAttribute("transform")) }
|
|
186
|
+
SVGElement.prototype.getScreenCTM = SVGElement.prototype.getCTM
|
|
187
|
+
`;
|
|
188
|
+
function encodedScriptValue(value) {
|
|
189
|
+
return Buffer.from(JSON.stringify(value)).toString("base64");
|
|
190
|
+
}
|
|
191
|
+
function dimension(value) {
|
|
192
|
+
return Number.isFinite(value) && value > 0 ? Math.ceil(value) : 1;
|
|
193
|
+
}
|
|
194
|
+
/** Render a BPMN 2.0 XML diagram to a self-contained SVG at build time. */
|
|
195
|
+
export async function renderBpmnToSvg(content, { padding = 24, signal } = {}) {
|
|
196
|
+
signal?.throwIfAborted();
|
|
197
|
+
let source;
|
|
198
|
+
try {
|
|
199
|
+
source = new TextDecoder("utf-8", { fatal: true }).decode(content);
|
|
200
|
+
}
|
|
201
|
+
catch (error) {
|
|
202
|
+
throw new TypeError("The BPMN asset is not valid UTF-8", { cause: error });
|
|
203
|
+
}
|
|
204
|
+
const viewerSource = await loadBpmnViewerSource();
|
|
205
|
+
const encodedSource = encodedScriptValue(source);
|
|
206
|
+
const safePadding = Number.isFinite(padding) ? Math.max(0, padding) : 24;
|
|
207
|
+
const document = `<!doctype html><body><div id="bpmn-host" style="width:1200px;height:800px"></div><script>
|
|
208
|
+
${svgGeometryPolyfill}
|
|
209
|
+
${viewerSource}
|
|
210
|
+
const source = JSON.parse(decodeURIComponent(escape(atob(${JSON.stringify(encodedSource)}))))
|
|
211
|
+
const viewer = new BpmnJS({ container: "#bpmn-host" })
|
|
212
|
+
viewer.importXML(source)
|
|
213
|
+
.then(() => viewer.saveSVG())
|
|
214
|
+
.then(({ svg }) => {
|
|
215
|
+
const parsed = new DOMParser().parseFromString(svg, "image/svg+xml")
|
|
216
|
+
const root = parsed.documentElement
|
|
217
|
+
const viewBox = (root.getAttribute("viewBox") || "0 0 1 1").trim().split(/\\s+/).map(Number)
|
|
218
|
+
const extra = ${safePadding} - 5
|
|
219
|
+
const x = viewBox[0] - extra
|
|
220
|
+
const y = viewBox[1] - extra
|
|
221
|
+
const width = Math.max(1, viewBox[2] + extra * 2)
|
|
222
|
+
const height = Math.max(1, viewBox[3] + extra * 2)
|
|
223
|
+
root.setAttribute("viewBox", [x, y, width, height].join(" "))
|
|
224
|
+
root.setAttribute("width", String(Math.ceil(width)))
|
|
225
|
+
root.setAttribute("height", String(Math.ceil(height)))
|
|
226
|
+
document.body.dataset.bpmnSvg = btoa(unescape(encodeURIComponent(new XMLSerializer().serializeToString(root))))
|
|
227
|
+
document.body.dataset.bpmnWidth = String(width)
|
|
228
|
+
document.body.dataset.bpmnHeight = String(height)
|
|
229
|
+
viewer.destroy()
|
|
230
|
+
})
|
|
231
|
+
.catch((error) => {
|
|
232
|
+
document.body.dataset.bpmnError = String(error?.stack || error)
|
|
233
|
+
viewer.destroy()
|
|
234
|
+
})
|
|
235
|
+
</script></body>`;
|
|
236
|
+
const virtualConsole = new VirtualConsole();
|
|
237
|
+
const dom = new JSDOM(document, {
|
|
238
|
+
runScripts: "dangerously",
|
|
239
|
+
virtualConsole,
|
|
240
|
+
beforeParse(window) {
|
|
241
|
+
Object.defineProperty(window, "structuredClone", {
|
|
242
|
+
value: structuredClone,
|
|
243
|
+
});
|
|
244
|
+
Object.defineProperties(window.HTMLElement.prototype, {
|
|
245
|
+
offsetHeight: { configurable: true, get: () => 800 },
|
|
246
|
+
offsetWidth: { configurable: true, get: () => 1_200 },
|
|
247
|
+
});
|
|
248
|
+
},
|
|
249
|
+
});
|
|
250
|
+
try {
|
|
251
|
+
const rendered = await new Promise((resolve, reject) => {
|
|
252
|
+
let finished = false;
|
|
253
|
+
const timeout = setTimeout(() => {
|
|
254
|
+
finished = true;
|
|
255
|
+
reject(new Error("Timed out while rendering the BPMN diagram"));
|
|
256
|
+
}, 10_000);
|
|
257
|
+
const poll = () => {
|
|
258
|
+
if (finished)
|
|
259
|
+
return;
|
|
260
|
+
if (signal?.aborted) {
|
|
261
|
+
finished = true;
|
|
262
|
+
clearTimeout(timeout);
|
|
263
|
+
reject(signal.reason);
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
const renderError = dom.window.document.body.dataset.bpmnError;
|
|
267
|
+
if (renderError) {
|
|
268
|
+
finished = true;
|
|
269
|
+
clearTimeout(timeout);
|
|
270
|
+
reject(new Error(`Unable to render the BPMN diagram: ${renderError}`));
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
const encodedSvg = dom.window.document.body.dataset.bpmnSvg;
|
|
274
|
+
if (encodedSvg) {
|
|
275
|
+
finished = true;
|
|
276
|
+
clearTimeout(timeout);
|
|
277
|
+
resolve({
|
|
278
|
+
svg: Buffer.from(encodedSvg, "base64").toString("utf8"),
|
|
279
|
+
width: dimension(Number(dom.window.document.body.dataset.bpmnWidth)),
|
|
280
|
+
height: dimension(Number(dom.window.document.body.dataset.bpmnHeight)),
|
|
281
|
+
});
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
setTimeout(poll, 10);
|
|
285
|
+
};
|
|
286
|
+
poll();
|
|
287
|
+
});
|
|
288
|
+
signal?.throwIfAborted();
|
|
289
|
+
return rendered;
|
|
290
|
+
}
|
|
291
|
+
finally {
|
|
292
|
+
dom.window.close();
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
//# sourceMappingURL=render.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render.js","sourceRoot":"","sources":["../../src/build/render.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAE3C,OAAO,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,OAAO,CAAA;AAa7C,IAAI,gBAA6C,CAAA;AAEjD,SAAS,oBAAoB;IAC3B,gBAAgB,KAAK,QAAQ,CAC3B,IAAI,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,4CAA4C,CAAC,CAAC,EAC1E,MAAM,CACP,CAAA;IACD,OAAO,gBAAgB,CAAA;AACzB,CAAC;AAED;;;;GAIG;AACH,MAAM,mBAAmB,GAAG,MAAM,CAAC,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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luginOptions } from "./types.js";
|
|
2
|
+
export type { BpmnModel, BpmnPluginOptions } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Turns BPMN 2.0 XML assets into SVG-backed images while MDX is compiled. The
|
|
5
|
+
* BPMN renderer and source XML remain outside the browser bundle.
|
|
6
|
+
*/
|
|
7
|
+
export declare function bpmnPlugin(options?: BpmnPluginOptions): import("@the-docs/plugin-contract").MdxPlugin<BpmnModel>;
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAG9D,YAAY,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAE9D;;;GAGG;AACH,wBAAgB,UAAU,CAAC,OAAO,GAAE,iBAAsB,4DA6CzD"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { basename } from "node:path";
|
|
2
|
+
import { defineMdxPlugin } from "@the-docs/plugin-contract";
|
|
3
|
+
import { resolveBpmnPluginOptions } from "./types.js";
|
|
4
|
+
/**
|
|
5
|
+
* Turns BPMN 2.0 XML assets into SVG-backed images while MDX is compiled. The
|
|
6
|
+
* BPMN renderer and source XML remain outside the browser bundle.
|
|
7
|
+
*/
|
|
8
|
+
export function bpmnPlugin(options = {}) {
|
|
9
|
+
const resolvedOptions = resolveBpmnPluginOptions(options);
|
|
10
|
+
return defineMdxPlugin({
|
|
11
|
+
id: "bpmn",
|
|
12
|
+
version: "1.0.0",
|
|
13
|
+
targets: [{ kind: "asset", extensions: [".bpmn"] }],
|
|
14
|
+
async parse(input, context) {
|
|
15
|
+
if (input.kind !== "asset" || input.extension.toLowerCase() !== ".bpmn") {
|
|
16
|
+
throw new TypeError("The BPMN plugin only accepts .bpmn assets");
|
|
17
|
+
}
|
|
18
|
+
context.signal?.throwIfAborted();
|
|
19
|
+
const { renderBpmnToSvg } = await import("./build/render.js");
|
|
20
|
+
const image = await renderBpmnToSvg(input.content, {
|
|
21
|
+
padding: resolvedOptions.padding,
|
|
22
|
+
signal: context.signal,
|
|
23
|
+
});
|
|
24
|
+
return {
|
|
25
|
+
dataUrl: `data:image/svg+xml;base64,${Buffer.from(image.svg).toString("base64")}`,
|
|
26
|
+
width: image.width,
|
|
27
|
+
height: image.height,
|
|
28
|
+
title: basename(input.url, input.extension),
|
|
29
|
+
};
|
|
30
|
+
},
|
|
31
|
+
component: {
|
|
32
|
+
load: () => import("./runtime/bpmn-image.js"),
|
|
33
|
+
},
|
|
34
|
+
build: {
|
|
35
|
+
async renderToImage(model, renderOptions) {
|
|
36
|
+
if (renderOptions.format !== "svg") {
|
|
37
|
+
throw new TypeError("BPMN currently renders build images as SVG");
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
content: Buffer.from(model.dataUrl.split(",", 2)[1] ?? "", "base64"),
|
|
41
|
+
mediaType: "image/svg+xml",
|
|
42
|
+
width: model.width,
|
|
43
|
+
height: model.height,
|
|
44
|
+
};
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AAEpC,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAA;AAG3D,OAAO,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAA;AAIrD;;;GAGG;AACH,MAAM,UAAU,UAAU,CAAC,UAA6B,EAAE;IACxD,MAAM,eAAe,GAAG,wBAAwB,CAAC,OAAO,CAAC,CAAA;IAEzD,OAAO,eAAe,CAAY;QAChC,EAAE,EAAE,MAAM;QACV,OAAO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I,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,EAAE,QAAQ,CAAC;oBACpE,SAAS,EAAE,eAAe;oBAC1B,KAAK,EAAE,KAAK,CAAC,KAAK;oBAClB,MAAM,EAAE,KAAK,CAAC,MAAM;iBACrB,CAAA;YACH,CAAC;SACF;KACF,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { PluginComponentProps } from "@the-docs/plugin-contract";
|
|
2
|
+
import type { BpmnModel } from "../types.js";
|
|
3
|
+
interface BpmnImageProps extends PluginComponentProps<BpmnModel> {
|
|
4
|
+
alt?: string;
|
|
5
|
+
}
|
|
6
|
+
export default function BpmnImage({ model, alt, }: BpmnImageProps): import("react/jsx-runtime").JSX.Element;
|
|
7
|
+
export {};
|
|
8
|
+
//# sourceMappingURL=bpmn-image.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bpmn-image.d.ts","sourceRoot":"","sources":["../../src/runtime/bpmn-image.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAA;AAErE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAE5C,UAAU,cAAe,SAAQ,oBAAoB,CAAC,SAAS,CAAC;IAC9D,GAAG,CAAC,EAAE,MAAM,CAAA;CACb;AAED,MAAM,CAAC,OAAO,UAAU,SAAS,CAAC,EAChC,KAAK,EACL,GAAiB,GAClB,EAAE,cAAc,2CAYhB"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
export default function BpmnImage({ model, alt = model.title, }) {
|
|
3
|
+
return (_jsx("img", { className: "bpmn-image", src: model.dataUrl, alt: alt, width: model.width, height: model.height, loading: "lazy", decoding: "async" }));
|
|
4
|
+
}
|
|
5
|
+
//# sourceMappingURL=bpmn-image.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bpmn-image.js","sourceRoot":"","sources":["../../src/runtime/bpmn-image.tsx"],"names":[],"mappings":";AAQA,MAAM,CAAC,OAAO,UAAU,SAAS,CAAC,EAChC,KAAK,EACL,GAAG,GAAG,KAAK,CAAC,KAAK,GACF;IACf,OAAO,CACL,cACE,SAAS,EAAC,YAAY,EACtB,GAAG,EAAE,KAAK,CAAC,OAAO,EAClB,GAAG,EAAE,GAAG,EACR,KAAK,EAAE,KAAK,CAAC,KAAK,EAClB,MAAM,EAAE,KAAK,CAAC,MAAM,EACpB,OAAO,EAAC,MAAM,EACd,QAAQ,EAAC,OAAO,GAChB,CACH,CAAA;AACH,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export type BpmnModel = {
|
|
2
|
+
dataUrl: string;
|
|
3
|
+
width: number;
|
|
4
|
+
height: number;
|
|
5
|
+
title: string;
|
|
6
|
+
};
|
|
7
|
+
export interface BpmnPluginOptions {
|
|
8
|
+
/** Empty space, in pixels, around the rendered process diagram. */
|
|
9
|
+
padding?: number;
|
|
10
|
+
}
|
|
11
|
+
export declare const defaultBpmnPluginOptions: {
|
|
12
|
+
readonly padding: 24;
|
|
13
|
+
};
|
|
14
|
+
export declare function resolveBpmnPluginOptions(options?: BpmnPluginOptions): {
|
|
15
|
+
padding: number;
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GAAG;IACtB,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;IACd,KAAK,EAAE,MAAM,CAAA;CACd,CAAA;AAED,MAAM,WAAW,iBAAiB;IAChC,mEAAmE;IACnE,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAED,eAAO,MAAM,wBAAwB;;CAE3B,CAAA;AAEV,wBAAgB,wBAAwB,CAAC,OAAO,GAAE,iBAAsB;;EAMvE"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export const defaultBpmnPluginOptions = {
|
|
2
|
+
padding: 24,
|
|
3
|
+
};
|
|
4
|
+
export function resolveBpmnPluginOptions(options = {}) {
|
|
5
|
+
const padding = Number.isFinite(options.padding)
|
|
6
|
+
? Math.max(0, options.padding ?? defaultBpmnPluginOptions.padding)
|
|
7
|
+
: defaultBpmnPluginOptions.padding;
|
|
8
|
+
return { padding };
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAYA,MAAM,CAAC,MAAM,wBAAwB,GAAG;IACtC,OAAO,EAAE,EAAE;CACH,CAAA;AAEV,MAAM,UAAU,wBAAwB,CAAC,UAA6B,EAAE;IACtE,MAAM,OAAO,GAAG,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC;QAC9C,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,CAAC,OAAO,IAAI,wBAAwB,CAAC,OAAO,CAAC;QAClE,CAAC,CAAC,wBAAwB,CAAC,OAAO,CAAA;IAEpC,OAAO,EAAE,OAAO,EAAE,CAAA;AACpB,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@the-docs/plugin-bpmn",
|
|
3
|
+
"version": "0.0.1-alpha.4",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"dependencies": {
|
|
6
|
+
"bpmn-js": "^18.23.0",
|
|
7
|
+
"jsdom": "^24.1.3",
|
|
8
|
+
"react": "^19.2.6",
|
|
9
|
+
"@the-docs/plugin-contract": "^0.0.1-alpha.4"
|
|
10
|
+
},
|
|
11
|
+
"devDependencies": {
|
|
12
|
+
"@types/hast": "^3.0.4",
|
|
13
|
+
"@types/jsdom": "^21.1.7",
|
|
14
|
+
"@types/node": "^24",
|
|
15
|
+
"@types/react": "^19",
|
|
16
|
+
"typescript": "^6"
|
|
17
|
+
},
|
|
18
|
+
"exports": {
|
|
19
|
+
".": "./dist/index.js",
|
|
20
|
+
"./build": "./dist/build/index.js",
|
|
21
|
+
"./runtime": "./dist/runtime/bpmn-image.js"
|
|
22
|
+
},
|
|
23
|
+
"description": "The Docs plugin bpmn",
|
|
24
|
+
"license": "MIT",
|
|
25
|
+
"repository": {
|
|
26
|
+
"type": "git",
|
|
27
|
+
"url": "git+https://github.com/thspacecode/the-docs.git",
|
|
28
|
+
"directory": "packages/plugin-bpmn"
|
|
29
|
+
},
|
|
30
|
+
"publishConfig": {
|
|
31
|
+
"access": "public"
|
|
32
|
+
},
|
|
33
|
+
"files": [
|
|
34
|
+
"dist"
|
|
35
|
+
],
|
|
36
|
+
"scripts": {
|
|
37
|
+
"build": "rm -rf dist && tsc -p tsconfig.json --noEmit false --declaration --declarationMap --sourceMap --outDir dist --rootDir src --allowImportingTsExtensions false && node ../../scripts/copy-package-assets.mjs",
|
|
38
|
+
"format": "prettier --write \"**/*.{ts,tsx}\"",
|
|
39
|
+
"typecheck": "tsc --noEmit"
|
|
40
|
+
}
|
|
41
|
+
}
|