@lightblues/jig 0.1.4 → 0.1.5

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.
@@ -53,11 +53,18 @@ function scrub(root) {
53
53
  export async function drawMermaid(el, source, mermaid, o = {}) {
54
54
  const id = `jig-mmd-${++seq}`;
55
55
  const doc = el.ownerDocument;
56
+ // mermaid's temporary nodes (the drawing root `id` and its wrapper `d<id>`). Removed before the SVG, which keeps the
57
+ // same id, goes into `el`: removing them afterwards took the drawn SVG out of an attached `el` (0.1.4, assay-020).
58
+ const cleanup = () => {
59
+ doc.getElementById(id)?.remove();
60
+ doc.getElementById(`d${id}`)?.remove();
61
+ };
56
62
  try {
57
63
  const mod = typeof mermaid === 'function' ? await mermaid() : mermaid;
58
64
  const m = 'default' in mod && mod.default ? mod.default : mod;
59
65
  m.initialize({ ...o.config, ...MERMAID_CONFIG, secure: [...MERMAID_CONFIG.secure] });
60
66
  const { svg } = await m.render(id, source);
67
+ cleanup();
61
68
  const tpl = doc.createElement('template');
62
69
  tpl.innerHTML = svg; // inert: nothing in a template loads or runs
63
70
  scrub(tpl.content);
@@ -68,6 +75,7 @@ export async function drawMermaid(el, source, mermaid, o = {}) {
68
75
  return true;
69
76
  }
70
77
  catch {
78
+ cleanup();
71
79
  const pre = doc.createElement('pre');
72
80
  pre.className = 'jig-mermaid-error';
73
81
  const code = doc.createElement('code');
@@ -77,8 +85,4 @@ export async function drawMermaid(el, source, mermaid, o = {}) {
77
85
  el.replaceChildren(pre);
78
86
  return false;
79
87
  }
80
- finally {
81
- doc.getElementById(id)?.remove();
82
- doc.getElementById(`d${id}`)?.remove();
83
- }
84
88
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lightblues/jig",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "Reusable parts for my apps: agent runtimes (Paseo, pi) that speak AG-UI, a thin thread-following client, one markdown renderer, and more as they prove reusable.",
5
5
  "type": "module",
6
6
  "license": "MIT",