@ai-gui/plugin-mermaid 0.6.1 → 0.7.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 CHANGED
@@ -29,6 +29,18 @@ function enqueue(work) {
29
29
  function escapeHtml(s) {
30
30
  return s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
31
31
  }
32
+ /**
33
+ * Remove the container Mermaid rendered into.
34
+ *
35
+ * Mermaid appends a host element id'd `d<id>` to the document and removes it itself on success. A
36
+ * parse error aborts before that, leaving its own error graphic in the page — outside the renderer,
37
+ * so nothing that owns the answer can clean it up.
38
+ */
39
+ function discardMermaidHost(id) {
40
+ if (typeof document === "undefined") return;
41
+ document.getElementById(`d${id}`)?.remove();
42
+ document.getElementById(id)?.remove();
43
+ }
32
44
  function errorHtml() {
33
45
  return {
34
46
  kind: "html",
@@ -65,12 +77,16 @@ function mermaid(opts = {}) {
65
77
  initializedTheme = wanted;
66
78
  }
67
79
  const id = `aigui-mermaid-${nextId++}`;
68
- const { svg } = await m.render(id, node.content ?? "");
69
- return {
70
- kind: "html",
71
- html: svg,
72
- trusted: true
73
- };
80
+ try {
81
+ const { svg } = await m.render(id, node.content ?? "");
82
+ return {
83
+ kind: "html",
84
+ html: svg,
85
+ trusted: true
86
+ };
87
+ } finally {
88
+ discardMermaidHost(id);
89
+ }
74
90
  } catch {
75
91
  return errorHtml();
76
92
  }
package/dist/index.js CHANGED
@@ -27,6 +27,18 @@ function enqueue(work) {
27
27
  function escapeHtml(s) {
28
28
  return s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
29
29
  }
30
+ /**
31
+ * Remove the container Mermaid rendered into.
32
+ *
33
+ * Mermaid appends a host element id'd `d<id>` to the document and removes it itself on success. A
34
+ * parse error aborts before that, leaving its own error graphic in the page — outside the renderer,
35
+ * so nothing that owns the answer can clean it up.
36
+ */
37
+ function discardMermaidHost(id) {
38
+ if (typeof document === "undefined") return;
39
+ document.getElementById(`d${id}`)?.remove();
40
+ document.getElementById(id)?.remove();
41
+ }
30
42
  function errorHtml() {
31
43
  return {
32
44
  kind: "html",
@@ -63,12 +75,16 @@ function mermaid(opts = {}) {
63
75
  initializedTheme = wanted;
64
76
  }
65
77
  const id = `aigui-mermaid-${nextId++}`;
66
- const { svg } = await m.render(id, node.content ?? "");
67
- return {
68
- kind: "html",
69
- html: svg,
70
- trusted: true
71
- };
78
+ try {
79
+ const { svg } = await m.render(id, node.content ?? "");
80
+ return {
81
+ kind: "html",
82
+ html: svg,
83
+ trusted: true
84
+ };
85
+ } finally {
86
+ discardMermaidHost(id);
87
+ }
72
88
  } catch {
73
89
  return errorHtml();
74
90
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-gui/plugin-mermaid",
3
- "version": "0.6.1",
3
+ "version": "0.7.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.6.1"
55
+ "@ai-gui/core": "0.7.0"
56
56
  },
57
57
  "scripts": {
58
58
  "build": "tsdown",