@ai-gui/plugin-mermaid 0.5.0 → 0.6.1

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 CHANGED
@@ -1,6 +1,21 @@
1
1
  "use strict";
2
2
 
3
3
  //#region src/index.ts
4
+ /** The themes Mermaid ships with. Anything else it is handed is not a theme it can find. */
5
+ const MERMAID_THEMES = new Set([
6
+ "default",
7
+ "base",
8
+ "dark",
9
+ "forest",
10
+ "neutral",
11
+ "neo",
12
+ "neo-dark",
13
+ "redux",
14
+ "redux-dark",
15
+ "redux-color",
16
+ "redux-dark-color",
17
+ "null"
18
+ ]);
4
19
  let nextId = 0;
5
20
  let mermaidPromise = null;
6
21
  let initializedTheme;
@@ -33,7 +48,8 @@ function mermaid(opts = {}) {
33
48
  if (!Number.isSafeInteger(maxSourceBytes) || maxSourceBytes <= 0) throw new TypeError("maxSourceBytes must be a positive safe integer");
34
49
  const outputs = new WeakMap();
35
50
  const render = (node, context) => {
36
- const wanted = context?.theme ?? theme;
51
+ const scheme = context?.theme;
52
+ const wanted = scheme === "dark" ? "dark" : scheme && MERMAID_THEMES.has(scheme) ? scheme : theme;
37
53
  const cached = outputs.get(node);
38
54
  if (cached && cached.theme === wanted) return cached.output;
39
55
  const output = enqueue(async () => {
@@ -52,7 +68,8 @@ function mermaid(opts = {}) {
52
68
  const { svg } = await m.render(id, node.content ?? "");
53
69
  return {
54
70
  kind: "html",
55
- html: svg
71
+ html: svg,
72
+ trusted: true
56
73
  };
57
74
  } catch {
58
75
  return errorHtml();
package/dist/index.js CHANGED
@@ -1,4 +1,19 @@
1
1
  //#region src/index.ts
2
+ /** The themes Mermaid ships with. Anything else it is handed is not a theme it can find. */
3
+ const MERMAID_THEMES = new Set([
4
+ "default",
5
+ "base",
6
+ "dark",
7
+ "forest",
8
+ "neutral",
9
+ "neo",
10
+ "neo-dark",
11
+ "redux",
12
+ "redux-dark",
13
+ "redux-color",
14
+ "redux-dark-color",
15
+ "null"
16
+ ]);
2
17
  let nextId = 0;
3
18
  let mermaidPromise = null;
4
19
  let initializedTheme;
@@ -31,7 +46,8 @@ function mermaid(opts = {}) {
31
46
  if (!Number.isSafeInteger(maxSourceBytes) || maxSourceBytes <= 0) throw new TypeError("maxSourceBytes must be a positive safe integer");
32
47
  const outputs = new WeakMap();
33
48
  const render = (node, context) => {
34
- const wanted = context?.theme ?? theme;
49
+ const scheme = context?.theme;
50
+ const wanted = scheme === "dark" ? "dark" : scheme && MERMAID_THEMES.has(scheme) ? scheme : theme;
35
51
  const cached = outputs.get(node);
36
52
  if (cached && cached.theme === wanted) return cached.output;
37
53
  const output = enqueue(async () => {
@@ -50,7 +66,8 @@ function mermaid(opts = {}) {
50
66
  const { svg } = await m.render(id, node.content ?? "");
51
67
  return {
52
68
  kind: "html",
53
- html: svg
69
+ html: svg,
70
+ trusted: true
54
71
  };
55
72
  } catch {
56
73
  return errorHtml();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-gui/plugin-mermaid",
3
- "version": "0.5.0",
3
+ "version": "0.6.1",
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.5.0"
55
+ "@ai-gui/core": "0.6.1"
56
56
  },
57
57
  "scripts": {
58
58
  "build": "tsdown",