react-super-mermaid 0.1.0 → 0.3.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/README.md +338 -165
- package/dist/index.cjs +560 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +30 -2
- package/dist/index.d.ts +30 -2
- package/dist/index.js +560 -17
- package/dist/index.js.map +1 -1
- package/llms.txt +41 -0
- package/package.json +84 -83
package/llms.txt
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# react-super-mermaid
|
|
2
|
+
|
|
3
|
+
> Drop-in React Mermaid viewer. Renders any Mermaid diagram, then re-styles it after render with two signature themes — `colorful` (modern palette, soft shadows, slate edges, vibrant per-type colouring) and `sketch` (Excalidraw hand-drawn) — and layers on pan/zoom, in-diagram search, fullscreen, background toggle, and SVG/PNG/JPEG/WebP export. Mermaid, svg-pan-zoom and React are optional peer dependencies that are never bundled (inject an instance, dynamic-import the peer, or load from a CDN). TypeScript, SSR-safe, zero-config styling, ships a `'use client'` boundary for Next.js.
|
|
4
|
+
|
|
5
|
+
Key facts:
|
|
6
|
+
- Package: `react-super-mermaid` on npm. License MIT. Author markku636.
|
|
7
|
+
- Install: `npm i react-super-mermaid` then optionally `npm i mermaid svg-pan-zoom` (peers). For no-build pages, load mermaid from a CDN and install nothing.
|
|
8
|
+
- Entry component: `<MermaidViewer code={...} />`. Give it a sized parent — it fills `height: 100%`.
|
|
9
|
+
- Themes: `colorful` (default), `sketch`, `auto`, and Mermaid's native `default` / `dark` / `neutral` / `forest`.
|
|
10
|
+
- Post-render styling is pure DOM manipulation in the browser; each pass early-outs on zero matches, so a Mermaid DOM change can never break rendering.
|
|
11
|
+
|
|
12
|
+
## Components and hooks
|
|
13
|
+
|
|
14
|
+
- `MermaidViewer` — full viewer with toolbar (theme picker, search, zoom, export, fullscreen, background). Props: `code` (required string), `theme`, `dark`, `toolbar`, `panZoom`, `search`, `exportable`, `background`, `backgroundMode` (`transparent|solid|grid`), `fullscreen`, `onFullscreenChange`, `keyboard`, `seed`, `fontUrl`, `mermaid` (`{instance?,cdnUrl?}`), `svgPanZoom`, `mermaidConfig`, `injectStyles`, `className`, `style`, `onRender`, `onError`.
|
|
15
|
+
- `MermaidDiagram` — diagram only (equivalent to `<MermaidViewer toolbar={false} />`).
|
|
16
|
+
- `useMermaidViewer` — hook backing the components for custom UIs.
|
|
17
|
+
- Imperative ref handle (`MermaidViewerHandle`): `zoomIn / zoomOut / fit / reset / actualSize / getZoomPercent / search / next / prev / clearSearch / exportSvg / exportPng / downloadSvg / downloadPng / getSvg / enterFullscreen / exitFullscreen / toggleFullscreen / isFullscreen / setBackground / cycleBackground / getBackground`.
|
|
18
|
+
|
|
19
|
+
## Framework-agnostic core API
|
|
20
|
+
|
|
21
|
+
- `renderDiagram({ code, container, theme, dark, seed, fontUrl, mermaidConfig, mermaid, injectStyles })` — one-shot render + post-process into a container, returns `{ svg, svgString, id }`.
|
|
22
|
+
- `loadMermaid({ source })` — resolve external mermaid: injected instance → peer `import('mermaid')` → CDN; memoized.
|
|
23
|
+
- `colorizeDiagram(svgOrRoot, { dark })` — apply the `colorful` post-process (palette + shadows + per-type colouring for flowchart / sequence / class / state / ER / pie / gantt / mindmap / timeline / journey).
|
|
24
|
+
- `boostLegibility(svgOrRoot)` — bump label font-weight for crisp text in every theme (weight-only, never changes colours). Applied automatically by the viewer.
|
|
25
|
+
- `sketchifyDiagram(svgOrRoot, { dark, seed })` — apply the Excalidraw hand-drawn post-process (sequence diagrams especially).
|
|
26
|
+
- `resolveTheme(theme, dark)`, `ensureStyles()`, `loadSvgPanZoom()`, and export helpers (`serializeLiveSvg`, `prepareSvgString`, `prepareSvgElement`, `rasterizeToBlob`, `svgBlob`, `downloadBlob`).
|
|
27
|
+
|
|
28
|
+
## Styling
|
|
29
|
+
|
|
30
|
+
- Styles auto-inject once (`injectStyles` default true) — no CSS import. Override via CSS variables on `.rsm-root`, e.g. `--rsm-accent`, `--rsm-border`, `--rsm-radius`, `--rsm-surface`.
|
|
31
|
+
- `sketch` uses Excalidraw's Virgil font fetched at runtime from the package's jsDelivr asset; falls back to `KaiTi / Comic Sans MS / cursive` if it can't load. `colorful` needs no font.
|
|
32
|
+
|
|
33
|
+
## Keyboard shortcuts
|
|
34
|
+
|
|
35
|
+
Focus the viewer: `/` or `Ctrl/Cmd+F` search · `+`/`-` zoom · `0` fit · `1` actual size · `w` fit width · `f` fullscreen · `b` cycle background · `Esc` close search / exit fullscreen.
|
|
36
|
+
|
|
37
|
+
## Links
|
|
38
|
+
|
|
39
|
+
- Source and full docs: https://github.com/markku636/react-super-mermaid
|
|
40
|
+
- npm: https://www.npmjs.com/package/react-super-mermaid
|
|
41
|
+
- Runnable demo: the `example/` directory (Vite + React).
|
package/package.json
CHANGED
|
@@ -1,83 +1,84 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "react-super-mermaid",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Drop-in React Mermaid viewer: beautified colorful + Excalidraw sketch themes, pan/zoom, in-diagram search, and SVG/PNG export. Loads mermaid externally (injected, peer, or CDN). Zero-config styling, TypeScript.",
|
|
5
|
-
"type": "module",
|
|
6
|
-
"license": "MIT",
|
|
7
|
-
"author": "markku636",
|
|
8
|
-
"homepage": "https://github.com/markku636/react-super-mermaid#readme",
|
|
9
|
-
"repository": {
|
|
10
|
-
"type": "git",
|
|
11
|
-
"url": "git+https://github.com/markku636/react-super-mermaid.git"
|
|
12
|
-
},
|
|
13
|
-
"bugs": {
|
|
14
|
-
"url": "https://github.com/markku636/react-super-mermaid/issues"
|
|
15
|
-
},
|
|
16
|
-
"keywords": [
|
|
17
|
-
"react",
|
|
18
|
-
"mermaid",
|
|
19
|
-
"diagram",
|
|
20
|
-
"flowchart",
|
|
21
|
-
"sequence-diagram",
|
|
22
|
-
"svg",
|
|
23
|
-
"pan-zoom",
|
|
24
|
-
"excalidraw",
|
|
25
|
-
"sketch",
|
|
26
|
-
"png-export",
|
|
27
|
-
"typescript"
|
|
28
|
-
],
|
|
29
|
-
"sideEffects": false,
|
|
30
|
-
"main": "./dist/index.cjs",
|
|
31
|
-
"module": "./dist/index.js",
|
|
32
|
-
"types": "./dist/index.d.ts",
|
|
33
|
-
"exports": {
|
|
34
|
-
".": {
|
|
35
|
-
"types": "./dist/index.d.ts",
|
|
36
|
-
"import": "./dist/index.js",
|
|
37
|
-
"require": "./dist/index.cjs"
|
|
38
|
-
},
|
|
39
|
-
"./package.json": "./package.json"
|
|
40
|
-
},
|
|
41
|
-
"files": [
|
|
42
|
-
"dist",
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
"
|
|
58
|
-
"react
|
|
59
|
-
"
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
"@types/react
|
|
72
|
-
"@types/
|
|
73
|
-
"
|
|
74
|
-
"
|
|
75
|
-
"react
|
|
76
|
-
"
|
|
77
|
-
"
|
|
78
|
-
"
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "react-super-mermaid",
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "Drop-in React Mermaid viewer: beautified colorful + Excalidraw sketch themes, pan/zoom, in-diagram search, and SVG/PNG export. Loads mermaid externally (injected, peer, or CDN). Zero-config styling, TypeScript.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"author": "markku636",
|
|
8
|
+
"homepage": "https://github.com/markku636/react-super-mermaid#readme",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/markku636/react-super-mermaid.git"
|
|
12
|
+
},
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/markku636/react-super-mermaid/issues"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"react",
|
|
18
|
+
"mermaid",
|
|
19
|
+
"diagram",
|
|
20
|
+
"flowchart",
|
|
21
|
+
"sequence-diagram",
|
|
22
|
+
"svg",
|
|
23
|
+
"pan-zoom",
|
|
24
|
+
"excalidraw",
|
|
25
|
+
"sketch",
|
|
26
|
+
"png-export",
|
|
27
|
+
"typescript"
|
|
28
|
+
],
|
|
29
|
+
"sideEffects": false,
|
|
30
|
+
"main": "./dist/index.cjs",
|
|
31
|
+
"module": "./dist/index.js",
|
|
32
|
+
"types": "./dist/index.d.ts",
|
|
33
|
+
"exports": {
|
|
34
|
+
".": {
|
|
35
|
+
"types": "./dist/index.d.ts",
|
|
36
|
+
"import": "./dist/index.js",
|
|
37
|
+
"require": "./dist/index.cjs"
|
|
38
|
+
},
|
|
39
|
+
"./package.json": "./package.json"
|
|
40
|
+
},
|
|
41
|
+
"files": [
|
|
42
|
+
"dist",
|
|
43
|
+
"llms.txt",
|
|
44
|
+
"README.md",
|
|
45
|
+
"LICENSE"
|
|
46
|
+
],
|
|
47
|
+
"engines": {
|
|
48
|
+
"node": ">=18"
|
|
49
|
+
},
|
|
50
|
+
"scripts": {
|
|
51
|
+
"build": "tsup",
|
|
52
|
+
"dev": "tsup --watch",
|
|
53
|
+
"typecheck": "tsc --noEmit",
|
|
54
|
+
"prepublishOnly": "npm run typecheck && npm run build"
|
|
55
|
+
},
|
|
56
|
+
"peerDependencies": {
|
|
57
|
+
"mermaid": ">=10 <12",
|
|
58
|
+
"react": ">=17",
|
|
59
|
+
"react-dom": ">=17",
|
|
60
|
+
"svg-pan-zoom": "^3.6.0"
|
|
61
|
+
},
|
|
62
|
+
"peerDependenciesMeta": {
|
|
63
|
+
"mermaid": {
|
|
64
|
+
"optional": true
|
|
65
|
+
},
|
|
66
|
+
"svg-pan-zoom": {
|
|
67
|
+
"optional": true
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
"devDependencies": {
|
|
71
|
+
"@types/react": "^18.3.0",
|
|
72
|
+
"@types/react-dom": "^18.3.0",
|
|
73
|
+
"@types/svg-pan-zoom": "^3.3.4",
|
|
74
|
+
"mermaid": "^11.15.0",
|
|
75
|
+
"react": "^18.3.1",
|
|
76
|
+
"react-dom": "^18.3.1",
|
|
77
|
+
"svg-pan-zoom": "^3.6.2",
|
|
78
|
+
"tsup": "^8.3.5",
|
|
79
|
+
"typescript": "^5.6.3"
|
|
80
|
+
},
|
|
81
|
+
"publishConfig": {
|
|
82
|
+
"access": "public"
|
|
83
|
+
}
|
|
84
|
+
}
|