@alexpeng/dsh-custom-plugin 0.9.0 → 0.9.2

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.
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Mermaid render + scratch-node cleanup, kept out of the React component so the
3
+ * failure path can be exercised in a real browser.
4
+ *
5
+ * Mermaid appends its error diagram to <body> before `render()` rejects; a
6
+ * caller that only catches the exception leaves `div#d<id>` (and sometimes the
7
+ * SVG) behind. Everything below exists to make that impossible: suppress the
8
+ * error UI, remove all three possible scratch nodes in a `finally`, and expose
9
+ * a sweep for diagrams left by older builds.
10
+ *
11
+ * This module must stay dependency-free: `scripts/smoke.mjs` transpiles it on
12
+ * its own and loads it as an ES module in the headless browser.
13
+ * @module @alexpeng/dsh-custom-plugin/client/mermaid-render
14
+ */
15
+ /** The slice of window.mermaid this module uses. */
16
+ export interface MermaidLike {
17
+ initialize(options: Record<string, unknown>): void;
18
+ render(id: string, code: string): Promise<string | {
19
+ svg: string;
20
+ }>;
21
+ }
22
+ export type MermaidRenderResult = {
23
+ ok: true;
24
+ svg: string;
25
+ } | {
26
+ ok: false;
27
+ error: string;
28
+ };
29
+ /** Remove the three nodes Mermaid may leave for one render id. */
30
+ export declare function removeMermaidScratch(doc: Document | null, id: string): void;
31
+ /** Remove error diagrams left in <body> by builds without error suppression. */
32
+ export declare function removeLegacyMermaidErrors(doc: Document | null): void;
33
+ export declare function renderMermaid(code: string, dark?: boolean, options?: {
34
+ win?: Window | null;
35
+ doc?: Document | null;
36
+ }): Promise<MermaidRenderResult>;
@@ -0,0 +1,21 @@
1
+ /**
2
+ * In-place Mermaid rendering over the GUI's code-block DOM, extracted from the
3
+ * React component so it can be benchmarked and tested without mounting the
4
+ * whole shell.
5
+ *
6
+ * Behaviour is deliberately unchanged: the GUI-owned `<pre>` node is never
7
+ * moved, the plugin-owned wrapper is inserted before the block and toggles the
8
+ * block's `display`, a failed render keeps the raw fence plus a retry marker,
9
+ * and a theme flip invalidates the rendered-SVG memo.
10
+ * @module @alexpeng/dsh-custom-plugin/client/mermaid-scan
11
+ */
12
+ import type { MermaidRenderResult } from './mermaid-render.ts';
13
+ export interface MermaidScanDeps {
14
+ ensureMermaid(): Promise<boolean>;
15
+ renderMermaid(code: string, dark: boolean): Promise<MermaidRenderResult>;
16
+ }
17
+ export interface MermaidScanner {
18
+ scan(dark: boolean): Promise<void>;
19
+ restore(): void;
20
+ }
21
+ export declare function createMermaidScanner(deps: MermaidScanDeps): MermaidScanner;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@alexpeng/dsh-custom-plugin",
3
3
  "description": "Custom convenience suite for the dsh web GUI: appearance, folders, prompts, session export/search, Mermaid, quote reply, usage analytics, local budget, key-free backups, and a Ctrl/Cmd+K command palette; dual-face plugin mounted without dsh source changes.",
4
- "version": "0.9.0",
4
+ "version": "0.9.2",
5
5
  "type": "module",
6
6
  "icon": "./icon.svg",
7
7
  "main": "lib/index.js",
@@ -58,6 +58,7 @@
58
58
  "check:readme": "node scripts/check-readme-i18n.mjs",
59
59
  "smoke": "node scripts/smoke.mjs",
60
60
  "canary": "node scripts/compat-canary.mjs",
61
+ "bench:mermaid": "node scripts/mermaid-scan-bench.mjs",
61
62
  "prepare": "npm run build",
62
63
  "prepublishOnly": "tsc --noEmit && vitest run"
63
64
  },