@the-docs/plugin-mermaid 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 +13 -0
- package/dist/build/render.d.ts.map +1 -0
- package/dist/build/render.js +239 -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 +52 -0
- package/dist/index.js.map +1 -0
- package/dist/runtime/mermaid-image.d.ts +8 -0
- package/dist/runtime/mermaid-image.d.ts.map +1 -0
- package/dist/runtime/mermaid-image.js +5 -0
- package/dist/runtime/mermaid-image.js.map +1 -0
- package/dist/types.d.ts +18 -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,mBAAmB,EAAE,MAAM,aAAa,CAAA;AACjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/build/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;AACjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Root } from "hast";
|
|
2
|
+
import type { MermaidPluginOptions } from "../types.js";
|
|
3
|
+
interface VFileLike {
|
|
4
|
+
path?: string;
|
|
5
|
+
}
|
|
6
|
+
/** Replaces `mermaid` code fences with SVG-backed image components. */
|
|
7
|
+
export declare function mermaidRehypePlugin(options?: MermaidPluginOptions): () => (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":"AAEA,OAAO,KAAK,EAAW,IAAI,EAAQ,MAAM,MAAM,CAAA;AAG/C,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAkBvD,UAAU,SAAS;IACjB,IAAI,CAAC,EAAE,MAAM,CAAA;CACd;AA+GD,uEAAuE;AACvE,wBAAgB,mBAAmB,CAAC,OAAO,GAAE,oBAAyB,UAIlC,MAAM,IAAI,EAAE,MAAM,SAAS,mBAyC9D"}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { fileURLToPath } from "node:url";
|
|
2
|
+
import { mermaidPlugin } from "../index.js";
|
|
3
|
+
const runtimeModuleId = fileURLToPath(new URL("../runtime/mermaid-image.js", import.meta.url));
|
|
4
|
+
const runtimeImport = `import MermaidImage from ${JSON.stringify(runtimeModuleId)}`;
|
|
5
|
+
function importNode() {
|
|
6
|
+
return {
|
|
7
|
+
type: "mdxjsEsm",
|
|
8
|
+
value: runtimeImport,
|
|
9
|
+
data: {
|
|
10
|
+
estree: {
|
|
11
|
+
type: "Program",
|
|
12
|
+
sourceType: "module",
|
|
13
|
+
body: [
|
|
14
|
+
{
|
|
15
|
+
type: "ImportDeclaration",
|
|
16
|
+
specifiers: [
|
|
17
|
+
{
|
|
18
|
+
type: "ImportDefaultSpecifier",
|
|
19
|
+
local: { type: "Identifier", name: "MermaidImage" },
|
|
20
|
+
},
|
|
21
|
+
],
|
|
22
|
+
source: {
|
|
23
|
+
type: "Literal",
|
|
24
|
+
value: runtimeModuleId,
|
|
25
|
+
raw: JSON.stringify(runtimeModuleId),
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
function modelExpression(model) {
|
|
34
|
+
const serialized = JSON.stringify(model);
|
|
35
|
+
const source = `JSON.parse(${JSON.stringify(serialized)})`;
|
|
36
|
+
return {
|
|
37
|
+
type: "mdxJsxAttributeValueExpression",
|
|
38
|
+
value: source,
|
|
39
|
+
data: {
|
|
40
|
+
estree: {
|
|
41
|
+
type: "Program",
|
|
42
|
+
sourceType: "module",
|
|
43
|
+
body: [
|
|
44
|
+
{
|
|
45
|
+
type: "ExpressionStatement",
|
|
46
|
+
expression: {
|
|
47
|
+
type: "CallExpression",
|
|
48
|
+
optional: false,
|
|
49
|
+
callee: {
|
|
50
|
+
type: "MemberExpression",
|
|
51
|
+
computed: false,
|
|
52
|
+
optional: false,
|
|
53
|
+
object: { type: "Identifier", name: "JSON" },
|
|
54
|
+
property: { type: "Identifier", name: "parse" },
|
|
55
|
+
},
|
|
56
|
+
arguments: [
|
|
57
|
+
{
|
|
58
|
+
type: "Literal",
|
|
59
|
+
value: serialized,
|
|
60
|
+
raw: JSON.stringify(serialized),
|
|
61
|
+
},
|
|
62
|
+
],
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
],
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
function componentNode(model) {
|
|
71
|
+
return {
|
|
72
|
+
type: "mdxJsxFlowElement",
|
|
73
|
+
name: "MermaidImage",
|
|
74
|
+
attributes: [
|
|
75
|
+
{
|
|
76
|
+
type: "mdxJsxAttribute",
|
|
77
|
+
name: "model",
|
|
78
|
+
value: modelExpression(model),
|
|
79
|
+
},
|
|
80
|
+
],
|
|
81
|
+
children: [],
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
function hasMermaidLanguage(node) {
|
|
85
|
+
const className = node.properties.className;
|
|
86
|
+
const classes = (Array.isArray(className) ? className : [className])
|
|
87
|
+
.flatMap((value) => String(value ?? "").split(/\s+/))
|
|
88
|
+
.filter(Boolean);
|
|
89
|
+
return classes.includes("language-mermaid");
|
|
90
|
+
}
|
|
91
|
+
function mermaidCode(node) {
|
|
92
|
+
if (node.tagName !== "pre")
|
|
93
|
+
return;
|
|
94
|
+
const code = node.children.find((child) => child.type === "element" &&
|
|
95
|
+
child.tagName === "code" &&
|
|
96
|
+
hasMermaidLanguage(child));
|
|
97
|
+
if (!code)
|
|
98
|
+
return;
|
|
99
|
+
return code.children
|
|
100
|
+
.filter((child) => child.type === "text")
|
|
101
|
+
.map((child) => child.value)
|
|
102
|
+
.join("");
|
|
103
|
+
}
|
|
104
|
+
/** Replaces `mermaid` code fences with SVG-backed image components. */
|
|
105
|
+
export function mermaidRehypePlugin(options = {}) {
|
|
106
|
+
const plugin = mermaidPlugin(options);
|
|
107
|
+
return function attacher() {
|
|
108
|
+
return async function transform(tree, file) {
|
|
109
|
+
const matches = [];
|
|
110
|
+
const visit = (parent) => {
|
|
111
|
+
parent.children.forEach((child, index) => {
|
|
112
|
+
if (child.type !== "element")
|
|
113
|
+
return;
|
|
114
|
+
const node = child;
|
|
115
|
+
const source = mermaidCode(node);
|
|
116
|
+
if (source !== undefined) {
|
|
117
|
+
matches.push({ parent, index, source });
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
visit(node);
|
|
121
|
+
});
|
|
122
|
+
};
|
|
123
|
+
visit(tree);
|
|
124
|
+
if (!matches.length)
|
|
125
|
+
return;
|
|
126
|
+
await Promise.all(matches.map(async ({ parent, index, source }) => {
|
|
127
|
+
const model = await plugin.parse({
|
|
128
|
+
kind: "code-fence",
|
|
129
|
+
language: "mermaid",
|
|
130
|
+
content: source,
|
|
131
|
+
documentPath: file.path ?? "",
|
|
132
|
+
}, {});
|
|
133
|
+
parent.children[index] = componentNode(model);
|
|
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,aAAa,EAAE,MAAM,UAAU,CAAA;AAIxC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAG3C,MAAM,eAAe,GAAG,aAAa,CACnC,IAAI,GAAG,CAAC,6BAA6B,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CACxD,CAAA;AACD,MAAM,aAAa,GAAG,4BAA4B,IAAI,CAAC,SAAS,CAAC,eAAe,CAAC,EAAE,CAAA;AAiBnF,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,cAAc,EAAE;6BACpD;yBACF;wBACD,MAAM,EAAE;4BACN,IAAI,EAAE,SAAS;4BACf,KAAK,EAAE,eAAe;4BACtB,GAAG,EAAE,IAAI,CAAC,SAAS,CAAC,eAAe,CAAC;yBACrC;qBACF;iBACF;aACF;SACF;KACF,CAAA;AACH,CAAC;AAED,SAAS,eAAe,CAAC,KAAc;IACrC,MAAM,UAAU,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAA;IACxC,MAAM,MAAM,GAAG,cAAc,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,GAAG,CAAA;IAE1D,OAAO;QAC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,CAAC,IAAI,CAAC,CAAA;oBAChC,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;wBACzB,OAAO,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAA;wBACvC,OAAM;oBACR,CAAC;oBACD,KAAK,CAAC,IAAI,CAAC,CAAA;gBACb,CAAC,CAAC,CAAA;YACJ,CAAC,CAAA;YACD,KAAK,CAAC,IAAI,CAAC,CAAA;YAEX,IAAI,CAAC,OAAO,CAAC,MAAM;gBAAE,OAAM;YAE3B,MAAM,OAAO,CAAC,GAAG,CACf,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE;gBAC9C,MAAM,KAAK,GAAG,MAAM,MAAM,CAAC,KAAK,CAC9B;oBACE,IAAI,EAAE,YAAY;oBAClB,QAAQ,EAAE,SAAS;oBACnB,OAAO,EAAE,MAAM;oBACf,YAAY,EAAE,IAAI,CAAC,IAAI,IAAI,EAAE;iBAC9B,EACD,EAAE,CACH,CAAA;gBACD,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,aAAa,CAAC,KAAK,CAAU,CAAA;YACxD,CAAC,CAAC,CACH,CAAA;YAED,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,UAAU,EAAW,CAAC,CAAA;QAC9C,CAAC,CAAA;IACH,CAAC,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { MermaidTheme } from "../types.js";
|
|
2
|
+
export interface RenderMermaidOptions {
|
|
3
|
+
theme?: MermaidTheme;
|
|
4
|
+
signal?: AbortSignal;
|
|
5
|
+
}
|
|
6
|
+
export interface RenderedMermaidSvg {
|
|
7
|
+
svg: string;
|
|
8
|
+
width: number;
|
|
9
|
+
height: number;
|
|
10
|
+
}
|
|
11
|
+
/** Render Mermaid source to a self-contained SVG in an isolated build-only DOM. */
|
|
12
|
+
export declare function renderMermaidToSvg(source: string, { theme, signal }?: RenderMermaidOptions): Promise<RenderedMermaidSvg>;
|
|
13
|
+
//# sourceMappingURL=render.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../../src/build/render.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE/C,MAAM,WAAW,oBAAoB;IACnC,KAAK,CAAC,EAAE,YAAY,CAAA;IACpB,MAAM,CAAC,EAAE,WAAW,CAAA;CACrB;AAED,MAAM,WAAW,kBAAkB;IACjC,GAAG,EAAE,MAAM,CAAA;IACX,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;CACf;AAqJD,mFAAmF;AACnF,wBAAsB,kBAAkB,CACtC,MAAM,EAAE,MAAM,EACd,EAAE,KAAiB,EAAE,MAAM,EAAE,GAAE,oBAAyB,GACvD,OAAO,CAAC,kBAAkB,CAAC,CAqG7B"}
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import { TextDecoder, TextEncoder } from "node:util";
|
|
3
|
+
import { JSDOM, VirtualConsole } from "jsdom";
|
|
4
|
+
let mermaidBrowserSource;
|
|
5
|
+
function loadMermaidBrowserSource() {
|
|
6
|
+
mermaidBrowserSource ??= readFile(new URL(import.meta.resolve("mermaid/dist/mermaid.min.js")), "utf8");
|
|
7
|
+
return mermaidBrowserSource;
|
|
8
|
+
}
|
|
9
|
+
/*
|
|
10
|
+
* Mermaid measures SVG labels and groups while laying out a diagram. JSDOM
|
|
11
|
+
* deliberately does not implement SVG geometry, so provide the small geometry
|
|
12
|
+
* surface Mermaid needs. Group bounds are derived from their rendered children,
|
|
13
|
+
* which also gives Mermaid an accurate final viewBox.
|
|
14
|
+
*/
|
|
15
|
+
const svgGeometryPolyfill = String.raw `
|
|
16
|
+
function mermaidBox(x = 0, y = 0, width = 0, height = 0) {
|
|
17
|
+
return { x, y, width, height }
|
|
18
|
+
}
|
|
19
|
+
function mermaidNumbers(value) {
|
|
20
|
+
return (value || "").match(/-?\d*\.?\d+(?:e[-+]?\d+)?/gi)?.map(Number) || []
|
|
21
|
+
}
|
|
22
|
+
function mermaidUnion(boxes) {
|
|
23
|
+
const valid = boxes.filter((box) =>
|
|
24
|
+
box && Number.isFinite(box.x) && Number.isFinite(box.y) &&
|
|
25
|
+
(box.width || box.height)
|
|
26
|
+
)
|
|
27
|
+
if (!valid.length) return mermaidBox()
|
|
28
|
+
const x = Math.min(...valid.map((box) => box.x))
|
|
29
|
+
const y = Math.min(...valid.map((box) => box.y))
|
|
30
|
+
const right = Math.max(...valid.map((box) => box.x + box.width))
|
|
31
|
+
const bottom = Math.max(...valid.map((box) => box.y + box.height))
|
|
32
|
+
return mermaidBox(x, y, right - x, bottom - y)
|
|
33
|
+
}
|
|
34
|
+
function mermaidTransformBox(value, box) {
|
|
35
|
+
let a = 1, b = 0, c = 0, d = 1, e = 0, f = 0
|
|
36
|
+
for (const part of (value || "").matchAll(/(matrix|translate|scale|rotate)\s*\(([^)]*)\)/g)) {
|
|
37
|
+
const values = mermaidNumbers(part[2])
|
|
38
|
+
let matrix = [1, 0, 0, 1, 0, 0]
|
|
39
|
+
if (part[1] === "matrix") matrix = values.slice(0, 6)
|
|
40
|
+
if (part[1] === "translate") matrix = [1, 0, 0, 1, values[0] || 0, values[1] || 0]
|
|
41
|
+
if (part[1] === "scale") matrix = [values[0] ?? 1, 0, 0, values[1] ?? values[0] ?? 1, 0, 0]
|
|
42
|
+
if (part[1] === "rotate") {
|
|
43
|
+
const radians = (values[0] || 0) * Math.PI / 180
|
|
44
|
+
const cosine = Math.cos(radians)
|
|
45
|
+
const sine = Math.sin(radians)
|
|
46
|
+
const x = values[1] || 0
|
|
47
|
+
const y = values[2] || 0
|
|
48
|
+
matrix = [
|
|
49
|
+
cosine, sine, -sine, cosine,
|
|
50
|
+
x - x * cosine + y * sine,
|
|
51
|
+
y - x * sine - y * cosine,
|
|
52
|
+
]
|
|
53
|
+
}
|
|
54
|
+
const [ma, mb, mc, md, me, mf] = matrix
|
|
55
|
+
;[a, b, c, d, e, f] = [
|
|
56
|
+
ma * a + mc * b,
|
|
57
|
+
mb * a + md * b,
|
|
58
|
+
ma * c + mc * d,
|
|
59
|
+
mb * c + md * d,
|
|
60
|
+
ma * e + mc * f + me,
|
|
61
|
+
mb * e + md * f + mf,
|
|
62
|
+
]
|
|
63
|
+
}
|
|
64
|
+
const points = [
|
|
65
|
+
[box.x, box.y],
|
|
66
|
+
[box.x + box.width, box.y],
|
|
67
|
+
[box.x, box.y + box.height],
|
|
68
|
+
[box.x + box.width, box.y + box.height],
|
|
69
|
+
].map(([x, y]) => [a * x + c * y + e, b * x + d * y + f])
|
|
70
|
+
const xs = points.map(([x]) => x)
|
|
71
|
+
const ys = points.map(([, y]) => y)
|
|
72
|
+
return mermaidBox(
|
|
73
|
+
Math.min(...xs),
|
|
74
|
+
Math.min(...ys),
|
|
75
|
+
Math.max(...xs) - Math.min(...xs),
|
|
76
|
+
Math.max(...ys) - Math.min(...ys),
|
|
77
|
+
)
|
|
78
|
+
}
|
|
79
|
+
SVGElement.prototype.getBBox = function () {
|
|
80
|
+
const tag = this.tagName.toLowerCase()
|
|
81
|
+
const number = (name) => Number(this.getAttribute(name)) || 0
|
|
82
|
+
if (tag === "text" || tag === "tspan") {
|
|
83
|
+
const size = Number.parseFloat(getComputedStyle(this).fontSize) || 16
|
|
84
|
+
return mermaidBox(
|
|
85
|
+
number("x"),
|
|
86
|
+
number("y") - size * 0.8,
|
|
87
|
+
Math.max(1, (this.textContent || "").length * size * 0.6),
|
|
88
|
+
size,
|
|
89
|
+
)
|
|
90
|
+
}
|
|
91
|
+
if (tag === "rect" || tag === "image" || tag === "foreignobject") {
|
|
92
|
+
return mermaidBox(number("x"), number("y"), number("width"), number("height"))
|
|
93
|
+
}
|
|
94
|
+
if (tag === "circle") {
|
|
95
|
+
const radius = number("r")
|
|
96
|
+
return mermaidBox(number("cx") - radius, number("cy") - radius, radius * 2, radius * 2)
|
|
97
|
+
}
|
|
98
|
+
if (tag === "ellipse") {
|
|
99
|
+
return mermaidBox(
|
|
100
|
+
number("cx") - number("rx"),
|
|
101
|
+
number("cy") - number("ry"),
|
|
102
|
+
number("rx") * 2,
|
|
103
|
+
number("ry") * 2,
|
|
104
|
+
)
|
|
105
|
+
}
|
|
106
|
+
if (tag === "line") {
|
|
107
|
+
return mermaidUnion([
|
|
108
|
+
mermaidBox(number("x1"), number("y1"), 1, 1),
|
|
109
|
+
mermaidBox(number("x2"), number("y2"), 1, 1),
|
|
110
|
+
])
|
|
111
|
+
}
|
|
112
|
+
if (tag === "polygon" || tag === "polyline" || tag === "path") {
|
|
113
|
+
const values = mermaidNumbers(
|
|
114
|
+
this.getAttribute(tag === "path" ? "d" : "points"),
|
|
115
|
+
)
|
|
116
|
+
const points = []
|
|
117
|
+
for (let index = 0; index < values.length; index += 2) {
|
|
118
|
+
points.push(mermaidBox(values[index], values[index + 1], 1, 1))
|
|
119
|
+
}
|
|
120
|
+
return mermaidUnion(points)
|
|
121
|
+
}
|
|
122
|
+
const children = mermaidUnion(
|
|
123
|
+
Array.from(this.children)
|
|
124
|
+
.filter((child) => !["defs", "style", "title", "desc"].includes(child.tagName.toLowerCase()))
|
|
125
|
+
.map((child) => mermaidTransformBox(child.getAttribute("transform"), child.getBBox())),
|
|
126
|
+
)
|
|
127
|
+
return children.width || children.height
|
|
128
|
+
? children
|
|
129
|
+
: mermaidBox(0, 0, 100, 20)
|
|
130
|
+
}
|
|
131
|
+
SVGElement.prototype.getComputedTextLength = function () {
|
|
132
|
+
return this.getBBox().width
|
|
133
|
+
}
|
|
134
|
+
`;
|
|
135
|
+
function encodedScriptValue(value) {
|
|
136
|
+
return Buffer.from(JSON.stringify(value)).toString("base64");
|
|
137
|
+
}
|
|
138
|
+
function dimension(value) {
|
|
139
|
+
return typeof value === "number" && Number.isFinite(value) && value > 0
|
|
140
|
+
? Math.ceil(value)
|
|
141
|
+
: 1;
|
|
142
|
+
}
|
|
143
|
+
/** Render Mermaid source to a self-contained SVG in an isolated build-only DOM. */
|
|
144
|
+
export async function renderMermaidToSvg(source, { theme = "neutral", signal } = {}) {
|
|
145
|
+
signal?.throwIfAborted();
|
|
146
|
+
const mermaidSource = await loadMermaidBrowserSource();
|
|
147
|
+
const encodedSource = encodedScriptValue(source);
|
|
148
|
+
const encodedConfig = encodedScriptValue({
|
|
149
|
+
startOnLoad: false,
|
|
150
|
+
securityLevel: "strict",
|
|
151
|
+
theme,
|
|
152
|
+
// Dagre renders entirely through SVG and works in the isolated build DOM.
|
|
153
|
+
layout: "dagre",
|
|
154
|
+
// SVG text works in generated images; JSDOM cannot measure foreignObject labels.
|
|
155
|
+
htmlLabels: false,
|
|
156
|
+
});
|
|
157
|
+
const document = `<!doctype html><body><div id="mermaid-host"></div><script>
|
|
158
|
+
${svgGeometryPolyfill}
|
|
159
|
+
${mermaidSource}
|
|
160
|
+
const source = JSON.parse(atob(${JSON.stringify(encodedSource)}))
|
|
161
|
+
const config = JSON.parse(atob(${JSON.stringify(encodedConfig)}))
|
|
162
|
+
mermaid.initialize(config)
|
|
163
|
+
mermaid.render("mermaid-diagram", source)
|
|
164
|
+
.then(({ svg }) => {
|
|
165
|
+
document.getElementById("mermaid-host").innerHTML = svg
|
|
166
|
+
document.body.dataset.mermaidComplete = "true"
|
|
167
|
+
})
|
|
168
|
+
.catch((error) => {
|
|
169
|
+
document.body.dataset.mermaidError = String(error?.stack || error)
|
|
170
|
+
})
|
|
171
|
+
</script></body>`;
|
|
172
|
+
const virtualConsole = new VirtualConsole();
|
|
173
|
+
const dom = new JSDOM(document, {
|
|
174
|
+
runScripts: "dangerously",
|
|
175
|
+
virtualConsole,
|
|
176
|
+
beforeParse(window) {
|
|
177
|
+
Object.defineProperties(window, {
|
|
178
|
+
structuredClone: { value: structuredClone },
|
|
179
|
+
TextDecoder: { value: TextDecoder },
|
|
180
|
+
TextEncoder: { value: TextEncoder },
|
|
181
|
+
});
|
|
182
|
+
Object.defineProperties(window.HTMLElement.prototype, {
|
|
183
|
+
offsetHeight: { configurable: true, get: () => 800 },
|
|
184
|
+
offsetWidth: { configurable: true, get: () => 1_200 },
|
|
185
|
+
});
|
|
186
|
+
},
|
|
187
|
+
});
|
|
188
|
+
try {
|
|
189
|
+
const svg = await new Promise((resolve, reject) => {
|
|
190
|
+
let finished = false;
|
|
191
|
+
const timeout = setTimeout(() => {
|
|
192
|
+
finished = true;
|
|
193
|
+
reject(new Error("Timed out while rendering the Mermaid diagram"));
|
|
194
|
+
}, 10_000);
|
|
195
|
+
const poll = () => {
|
|
196
|
+
if (finished)
|
|
197
|
+
return;
|
|
198
|
+
if (signal?.aborted) {
|
|
199
|
+
finished = true;
|
|
200
|
+
clearTimeout(timeout);
|
|
201
|
+
reject(signal.reason);
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
const renderError = dom.window.document.body.dataset.mermaidError;
|
|
205
|
+
if (renderError) {
|
|
206
|
+
finished = true;
|
|
207
|
+
clearTimeout(timeout);
|
|
208
|
+
reject(new Error(`Unable to render the Mermaid diagram: ${renderError}`));
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
const rendered = dom.window.document.querySelector("#mermaid-host svg");
|
|
212
|
+
if (rendered) {
|
|
213
|
+
finished = true;
|
|
214
|
+
clearTimeout(timeout);
|
|
215
|
+
resolve(rendered);
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
setTimeout(poll, 10);
|
|
219
|
+
};
|
|
220
|
+
poll();
|
|
221
|
+
});
|
|
222
|
+
const viewBox = svg.getAttribute("viewBox")?.trim().split(/\s+/).map(Number);
|
|
223
|
+
const width = dimension(viewBox?.length === 4 ? viewBox[2] : undefined);
|
|
224
|
+
const height = dimension(viewBox?.length === 4 ? viewBox[3] : undefined);
|
|
225
|
+
signal?.throwIfAborted();
|
|
226
|
+
svg.setAttribute("width", String(width));
|
|
227
|
+
svg.setAttribute("height", String(height));
|
|
228
|
+
svg.style.removeProperty("max-width");
|
|
229
|
+
return {
|
|
230
|
+
svg: svg.outerHTML,
|
|
231
|
+
width,
|
|
232
|
+
height,
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
finally {
|
|
236
|
+
dom.window.close();
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
//# 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;AAC3C,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,WAAW,CAAA;AAEpD,OAAO,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,OAAO,CAAA;AAe7C,IAAI,oBAAiD,CAAA;AAErD,SAAS,wBAAwB;IAC/B,oBAAoB,KAAK,QAAQ,CAC/B,IAAI,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,6BAA6B,CAAC,CAAC,EAC3D,MAAM,CACP,CAAA;IACD,OAAO,oBAAoB,CAAA;AAC7B,CAAC;AAED;;;;;GAKG;AACH,MAAM,mBAAmB,GAAG,MAAM,CAAC,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAuHrC,CAAA;AAED,SAAS,kBAAkB,CAAC,KAAc;IACxC,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAA;AAC9D,CAAC;AAED,SAAS,SAAS,CAAC,KAAyB;IAC1C,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,Q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AA;oBACf,YAAY,CAAC,OAAO,CAAC,CAAA;oBACrB,OAAO,CAAC,QAAoC,CAAC,CAAA;oBAC7C,OAAM;gBACR,CAAC;gBAED,UAAU,CAAC,IAAI,EAAE,EAAE,CAAC,CAAA;YACtB,CAAC,CAAA;YACD,IAAI,EAAE,CAAA;QACR,CAAC,CAAC,CAAA;QACF,MAAM,OAAO,GAAG,GAAG,CAAC,YAAY,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;QAC5E,MAAM,KAAK,GAAG,SAAS,CAAC,OAAO,EAAE,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAA;QACvE,MAAM,MAAM,GAAG,SAAS,CAAC,OAAO,EAAE,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAA;QAExE,MAAM,EAAE,cAAc,EAAE,CAAA;QACxB,GAAG,CAAC,YAAY,CAAC,OAAO,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,CAAA;QACxC,GAAG,CAAC,YAAY,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,CAAA;QAC1C,GAAG,CAAC,KAAK,CAAC,cAAc,CAAC,WAAW,CAAC,CAAA;QAErC,OAAO;YACL,GAAG,EAAE,GAAG,CAAC,SAAS;YAClB,KAAK;YACL,MAAM;SACP,CAAA;IACH,CAAC;YAAS,CAAC;QACT,GAAG,CAAC,MAAM,CAAC,KAAK,EAAE,CAAA;IACpB,CAAC;AACH,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { MermaidModel, MermaidPluginOptions } from "./types.js";
|
|
2
|
+
export type { MermaidModel, MermaidPluginOptions, MermaidTheme, } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Turns Mermaid code fences into SVG-backed images while MDX is compiled.
|
|
5
|
+
* Mermaid and its DOM environment remain outside the browser bundle.
|
|
6
|
+
*/
|
|
7
|
+
export declare function mermaidPlugin(options?: MermaidPluginOptions): import("@the-docs/plugin-contract").MdxPlugin<MermaidModel>;
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAA;AAGpE,YAAY,EACV,YAAY,EACZ,oBAAoB,EACpB,YAAY,GACb,MAAM,YAAY,CAAA;AAQnB;;;GAGG;AACH,wBAAgB,aAAa,CAAC,OAAO,GAAE,oBAAyB,+DAkD/D"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { defineMdxPlugin } from "@the-docs/plugin-contract";
|
|
2
|
+
import { resolveMermaidPluginOptions } from "./types.js";
|
|
3
|
+
function diagramAlt(source) {
|
|
4
|
+
return (source.match(/^\s*accTitle\s*:\s*(.+?)\s*$/im)?.[1] ?? "Mermaid diagram");
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Turns Mermaid code fences into SVG-backed images while MDX is compiled.
|
|
8
|
+
* Mermaid and its DOM environment remain outside the browser bundle.
|
|
9
|
+
*/
|
|
10
|
+
export function mermaidPlugin(options = {}) {
|
|
11
|
+
const resolvedOptions = resolveMermaidPluginOptions(options);
|
|
12
|
+
return defineMdxPlugin({
|
|
13
|
+
id: "mermaid",
|
|
14
|
+
version: "1.0.0",
|
|
15
|
+
targets: [{ kind: "code-fence", language: "mermaid" }],
|
|
16
|
+
async parse(input, context) {
|
|
17
|
+
if (input.kind !== "code-fence" ||
|
|
18
|
+
input.language.trim().toLowerCase() !== "mermaid") {
|
|
19
|
+
throw new TypeError("The Mermaid plugin only accepts mermaid code fences");
|
|
20
|
+
}
|
|
21
|
+
context.signal?.throwIfAborted();
|
|
22
|
+
const { renderMermaidToSvg } = await import("./build/render.js");
|
|
23
|
+
const image = await renderMermaidToSvg(input.content, {
|
|
24
|
+
theme: resolvedOptions.theme,
|
|
25
|
+
signal: context.signal,
|
|
26
|
+
});
|
|
27
|
+
return {
|
|
28
|
+
dataUrl: `data:image/svg+xml;base64,${Buffer.from(image.svg).toString("base64")}`,
|
|
29
|
+
width: image.width,
|
|
30
|
+
height: image.height,
|
|
31
|
+
alt: diagramAlt(input.content),
|
|
32
|
+
};
|
|
33
|
+
},
|
|
34
|
+
component: {
|
|
35
|
+
load: () => import("./runtime/mermaid-image.js"),
|
|
36
|
+
},
|
|
37
|
+
build: {
|
|
38
|
+
async renderToImage(model, renderOptions) {
|
|
39
|
+
if (renderOptions.format !== "svg") {
|
|
40
|
+
throw new TypeError("Mermaid currently renders build images as SVG");
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
content: Buffer.from(model.dataUrl.split(",", 2)[1] ?? "", "base64"),
|
|
44
|
+
mediaType: "image/svg+xml",
|
|
45
|
+
width: model.width,
|
|
46
|
+
height: model.height,
|
|
47
|
+
};
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAA;AAG3D,OAAO,EAAE,2BAA2B,EAAE,MAAM,YAAY,CAAA;AAQxD,SAAS,UAAU,CAAC,MAAc;IAChC,OAAO,CACL,MAAM,CAAC,KAAK,CAAC,gCAAgC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,iBAAiB,CACzE,CAAA;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,aAA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,EAAE,CAAC;oBACnC,MAAM,IAAI,SAAS,CAAC,+CAA+C,CAAC,CAAA;gBACtE,CAAC;gBAED,OAAO;oBACL,OAAO,EAAE,MAAM,CAAC,IAAI,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 { MermaidModel } from "../types.js";
|
|
3
|
+
interface MermaidImageProps extends PluginComponentProps<MermaidModel> {
|
|
4
|
+
alt?: string;
|
|
5
|
+
}
|
|
6
|
+
export default function MermaidImage({ model, alt, }: MermaidImageProps): import("react/jsx-runtime").JSX.Element;
|
|
7
|
+
export {};
|
|
8
|
+
//# sourceMappingURL=mermaid-image.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mermaid-image.d.ts","sourceRoot":"","sources":["../../src/runtime/mermaid-image.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAA;AAErE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE/C,UAAU,iBAAkB,SAAQ,oBAAoB,CAAC,YAAY,CAAC;IACpE,GAAG,CAAC,EAAE,MAAM,CAAA;CACb;AAED,MAAM,CAAC,OAAO,UAAU,YAAY,CAAC,EACnC,KAAK,EACL,GAAe,GAChB,EAAE,iBAAiB,2CAYnB"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
export default function MermaidImage({ model, alt = model.alt, }) {
|
|
3
|
+
return (_jsx("img", { className: "mermaid-image", src: model.dataUrl, alt: alt, width: model.width, height: model.height, loading: "lazy", decoding: "async" }));
|
|
4
|
+
}
|
|
5
|
+
//# sourceMappingURL=mermaid-image.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mermaid-image.js","sourceRoot":"","sources":["../../src/runtime/mermaid-image.tsx"],"names":[],"mappings":";AAQA,MAAM,CAAC,OAAO,UAAU,YAAY,CAAC,EACnC,KAAK,EACL,GAAG,GAAG,KAAK,CAAC,GAAG,GACG;IAClB,OAAO,CACL,cACE,SAAS,EAAC,eAAe,EACzB,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,18 @@
|
|
|
1
|
+
export type MermaidTheme = "default" | "base" | "dark" | "forest" | "neutral";
|
|
2
|
+
export type MermaidModel = {
|
|
3
|
+
dataUrl: string;
|
|
4
|
+
width: number;
|
|
5
|
+
height: number;
|
|
6
|
+
alt: string;
|
|
7
|
+
};
|
|
8
|
+
export interface MermaidPluginOptions {
|
|
9
|
+
/** Mermaid's built-in theme used for generated diagrams. */
|
|
10
|
+
theme?: MermaidTheme;
|
|
11
|
+
}
|
|
12
|
+
export declare const defaultMermaidPluginOptions: {
|
|
13
|
+
readonly theme: "neutral";
|
|
14
|
+
};
|
|
15
|
+
export declare function resolveMermaidPluginOptions(options?: MermaidPluginOptions): {
|
|
16
|
+
theme: MermaidTheme;
|
|
17
|
+
};
|
|
18
|
+
//# 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,YAAY,GAAG,SAAS,GAAG,MAAM,GAAG,MAAM,GAAG,QAAQ,GAAG,SAAS,CAAA;AAE7E,MAAM,MAAM,YAAY,GAAG;IACzB,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;IACd,GAAG,EAAE,MAAM,CAAA;CACZ,CAAA;AAED,MAAM,WAAW,oBAAoB;IACnC,4DAA4D;IAC5D,KAAK,CAAC,EAAE,YAAY,CAAA;CACrB;AAED,eAAO,MAAM,2BAA2B;;CAE9B,CAAA;AAEV,wBAAgB,2BAA2B,CACzC,OAAO,GAAE,oBAAyB;WAR1B,YAAY;EAcrB"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAcA,MAAM,CAAC,MAAM,2BAA2B,GAAG;IACzC,KAAK,EAAE,SAAS;CACR,CAAA;AAEV,MAAM,UAAU,2BAA2B,CACzC,UAAgC,EAAE;IAElC,OAAO;QACL,GAAG,2BAA2B;QAC9B,GAAG,OAAO;KACX,CAAA;AACH,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@the-docs/plugin-mermaid",
|
|
3
|
+
"version": "0.0.1-alpha.4",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"dependencies": {
|
|
6
|
+
"jsdom": "^24.1.3",
|
|
7
|
+
"mermaid": "^11.16.1",
|
|
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/mermaid-image.js"
|
|
22
|
+
},
|
|
23
|
+
"description": "The Docs plugin mermaid",
|
|
24
|
+
"license": "MIT",
|
|
25
|
+
"repository": {
|
|
26
|
+
"type": "git",
|
|
27
|
+
"url": "git+https://github.com/thspacecode/the-docs.git",
|
|
28
|
+
"directory": "packages/plugin-mermaid"
|
|
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
|
+
}
|