@ai-gui/plugin-mermaid 0.4.2 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +10 -6
- package/dist/index.js +10 -6
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -32,20 +32,21 @@ function mermaid(opts = {}) {
|
|
|
32
32
|
const maxSourceBytes = opts.maxSourceBytes ?? 64 * 1024;
|
|
33
33
|
if (!Number.isSafeInteger(maxSourceBytes) || maxSourceBytes <= 0) throw new TypeError("maxSourceBytes must be a positive safe integer");
|
|
34
34
|
const outputs = new WeakMap();
|
|
35
|
-
const render = (node) => {
|
|
35
|
+
const render = (node, context) => {
|
|
36
|
+
const wanted = context?.theme ?? theme;
|
|
36
37
|
const cached = outputs.get(node);
|
|
37
|
-
if (cached) return cached;
|
|
38
|
+
if (cached && cached.theme === wanted) return cached.output;
|
|
38
39
|
const output = enqueue(async () => {
|
|
39
40
|
try {
|
|
40
41
|
if (new TextEncoder().encode(node.content ?? "").byteLength > maxSourceBytes) return errorHtml();
|
|
41
42
|
const m = await loadMermaid();
|
|
42
|
-
if (initializedTheme
|
|
43
|
+
if (initializedTheme !== wanted) {
|
|
43
44
|
m.initialize({
|
|
44
45
|
startOnLoad: false,
|
|
45
|
-
theme,
|
|
46
|
+
theme: wanted,
|
|
46
47
|
securityLevel: "strict"
|
|
47
48
|
});
|
|
48
|
-
initializedTheme =
|
|
49
|
+
initializedTheme = wanted;
|
|
49
50
|
}
|
|
50
51
|
const id = `aigui-mermaid-${nextId++}`;
|
|
51
52
|
const { svg } = await m.render(id, node.content ?? "");
|
|
@@ -57,7 +58,10 @@ function mermaid(opts = {}) {
|
|
|
57
58
|
return errorHtml();
|
|
58
59
|
}
|
|
59
60
|
});
|
|
60
|
-
outputs.set(node,
|
|
61
|
+
outputs.set(node, {
|
|
62
|
+
theme: wanted,
|
|
63
|
+
output
|
|
64
|
+
});
|
|
61
65
|
return output;
|
|
62
66
|
};
|
|
63
67
|
return {
|
package/dist/index.js
CHANGED
|
@@ -30,20 +30,21 @@ function mermaid(opts = {}) {
|
|
|
30
30
|
const maxSourceBytes = opts.maxSourceBytes ?? 64 * 1024;
|
|
31
31
|
if (!Number.isSafeInteger(maxSourceBytes) || maxSourceBytes <= 0) throw new TypeError("maxSourceBytes must be a positive safe integer");
|
|
32
32
|
const outputs = new WeakMap();
|
|
33
|
-
const render = (node) => {
|
|
33
|
+
const render = (node, context) => {
|
|
34
|
+
const wanted = context?.theme ?? theme;
|
|
34
35
|
const cached = outputs.get(node);
|
|
35
|
-
if (cached) return cached;
|
|
36
|
+
if (cached && cached.theme === wanted) return cached.output;
|
|
36
37
|
const output = enqueue(async () => {
|
|
37
38
|
try {
|
|
38
39
|
if (new TextEncoder().encode(node.content ?? "").byteLength > maxSourceBytes) return errorHtml();
|
|
39
40
|
const m = await loadMermaid();
|
|
40
|
-
if (initializedTheme
|
|
41
|
+
if (initializedTheme !== wanted) {
|
|
41
42
|
m.initialize({
|
|
42
43
|
startOnLoad: false,
|
|
43
|
-
theme,
|
|
44
|
+
theme: wanted,
|
|
44
45
|
securityLevel: "strict"
|
|
45
46
|
});
|
|
46
|
-
initializedTheme =
|
|
47
|
+
initializedTheme = wanted;
|
|
47
48
|
}
|
|
48
49
|
const id = `aigui-mermaid-${nextId++}`;
|
|
49
50
|
const { svg } = await m.render(id, node.content ?? "");
|
|
@@ -55,7 +56,10 @@ function mermaid(opts = {}) {
|
|
|
55
56
|
return errorHtml();
|
|
56
57
|
}
|
|
57
58
|
});
|
|
58
|
-
outputs.set(node,
|
|
59
|
+
outputs.set(node, {
|
|
60
|
+
theme: wanted,
|
|
61
|
+
output
|
|
62
|
+
});
|
|
59
63
|
return output;
|
|
60
64
|
};
|
|
61
65
|
return {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-gui/plugin-mermaid",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Mermaid diagram plugin for AIGUI.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"llm",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
54
|
"mermaid": "^11.4.0",
|
|
55
|
-
"@ai-gui/core": "0.
|
|
55
|
+
"@ai-gui/core": "0.5.0"
|
|
56
56
|
},
|
|
57
57
|
"scripts": {
|
|
58
58
|
"build": "tsdown",
|