ai-diagrams-mcp 1.0.1 → 1.1.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 +258 -12
- package/dist/sharing/index.d.ts +16 -0
- package/dist/sharing/index.d.ts.map +1 -0
- package/dist/sharing/index.js +28 -0
- package/dist/sharing/index.js.map +1 -0
- package/dist/tools/render-diagram.d.ts +7 -0
- package/dist/tools/render-diagram.d.ts.map +1 -1
- package/dist/tools/render-diagram.js +40 -5
- package/dist/tools/render-diagram.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -8,13 +8,38 @@ An MCP (Model Context Protocol) server that renders Mermaid diagrams to an inter
|
|
|
8
8
|
- **Multiple Diagrams** - Render multiple diagrams in a single view
|
|
9
9
|
- **Mermaid Themes** - Support for default, dark, forest, and neutral themes
|
|
10
10
|
- **Light/Dark Mode** - Automatic system preference detection with manual toggle
|
|
11
|
+
- **Shareable Links** - Upload diagrams and get public HTTPS links (no account required)
|
|
11
12
|
- **Cross-Platform** - Works on macOS, Linux, and Windows
|
|
12
13
|
|
|
13
|
-
##
|
|
14
|
+
## Quick Start
|
|
14
15
|
|
|
15
|
-
|
|
16
|
+
```bash
|
|
17
|
+
npx -y ai-diagrams-mcp
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Or install globally:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm install -g ai-diagrams-mcp
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Configuration by AI Tool
|
|
16
27
|
|
|
17
|
-
|
|
28
|
+
<table>
|
|
29
|
+
<tr>
|
|
30
|
+
<th>Tool</th>
|
|
31
|
+
<th>Config File</th>
|
|
32
|
+
<th>Configuration</th>
|
|
33
|
+
</tr>
|
|
34
|
+
|
|
35
|
+
<tr>
|
|
36
|
+
<td><strong>Claude Code</strong></td>
|
|
37
|
+
<td>
|
|
38
|
+
|
|
39
|
+
`~/.claude.json` or project `.mcp.json`
|
|
40
|
+
|
|
41
|
+
</td>
|
|
42
|
+
<td>
|
|
18
43
|
|
|
19
44
|
```json
|
|
20
45
|
{
|
|
@@ -27,27 +52,181 @@ No installation needed. Configure your MCP client to use:
|
|
|
27
52
|
}
|
|
28
53
|
```
|
|
29
54
|
|
|
30
|
-
|
|
55
|
+
Or via CLI: `claude mcp add ai-diagrams -- npx -y ai-diagrams-mcp`
|
|
31
56
|
|
|
32
|
-
|
|
33
|
-
|
|
57
|
+
</td>
|
|
58
|
+
</tr>
|
|
59
|
+
|
|
60
|
+
<tr>
|
|
61
|
+
<td><strong>Claude Desktop</strong></td>
|
|
62
|
+
<td>
|
|
63
|
+
|
|
64
|
+
macOS: `~/Library/Application Support/Claude/claude_desktop_config.json`
|
|
65
|
+
|
|
66
|
+
Windows: `%APPDATA%\Claude\claude_desktop_config.json`
|
|
67
|
+
|
|
68
|
+
</td>
|
|
69
|
+
<td>
|
|
70
|
+
|
|
71
|
+
```json
|
|
72
|
+
{
|
|
73
|
+
"mcpServers": {
|
|
74
|
+
"ai-diagrams": {
|
|
75
|
+
"command": "npx",
|
|
76
|
+
"args": ["-y", "ai-diagrams-mcp"]
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
</td>
|
|
83
|
+
</tr>
|
|
84
|
+
|
|
85
|
+
<tr>
|
|
86
|
+
<td><strong>Cursor</strong></td>
|
|
87
|
+
<td>
|
|
88
|
+
|
|
89
|
+
`~/.cursor/mcp.json` or Settings → Features → MCP
|
|
90
|
+
|
|
91
|
+
</td>
|
|
92
|
+
<td>
|
|
93
|
+
|
|
94
|
+
```json
|
|
95
|
+
{
|
|
96
|
+
"mcpServers": {
|
|
97
|
+
"ai-diagrams": {
|
|
98
|
+
"command": "npx",
|
|
99
|
+
"args": ["-y", "ai-diagrams-mcp"]
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
</td>
|
|
106
|
+
</tr>
|
|
107
|
+
|
|
108
|
+
<tr>
|
|
109
|
+
<td><strong>VS Code (Copilot)</strong></td>
|
|
110
|
+
<td>
|
|
111
|
+
|
|
112
|
+
`.vscode/mcp.json` in workspace or via Command Palette: `MCP: Add Server`
|
|
113
|
+
|
|
114
|
+
</td>
|
|
115
|
+
<td>
|
|
116
|
+
|
|
117
|
+
```json
|
|
118
|
+
{
|
|
119
|
+
"servers": {
|
|
120
|
+
"ai-diagrams": {
|
|
121
|
+
"command": "npx",
|
|
122
|
+
"args": ["-y", "ai-diagrams-mcp"]
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
</td>
|
|
129
|
+
</tr>
|
|
130
|
+
|
|
131
|
+
<tr>
|
|
132
|
+
<td><strong>Cline</strong></td>
|
|
133
|
+
<td>
|
|
134
|
+
|
|
135
|
+
Click MCP Servers icon → Configure → Edit MCP Settings
|
|
136
|
+
|
|
137
|
+
</td>
|
|
138
|
+
<td>
|
|
139
|
+
|
|
140
|
+
```json
|
|
141
|
+
{
|
|
142
|
+
"mcpServers": {
|
|
143
|
+
"ai-diagrams": {
|
|
144
|
+
"command": "npx",
|
|
145
|
+
"args": ["-y", "ai-diagrams-mcp"]
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
34
149
|
```
|
|
35
150
|
|
|
36
|
-
|
|
151
|
+
</td>
|
|
152
|
+
</tr>
|
|
153
|
+
|
|
154
|
+
<tr>
|
|
155
|
+
<td><strong>Windsurf</strong></td>
|
|
156
|
+
<td>
|
|
157
|
+
|
|
158
|
+
`~/.codeium/windsurf/mcp_config.json`
|
|
159
|
+
|
|
160
|
+
</td>
|
|
161
|
+
<td>
|
|
37
162
|
|
|
38
163
|
```json
|
|
39
164
|
{
|
|
40
165
|
"mcpServers": {
|
|
41
166
|
"ai-diagrams": {
|
|
42
|
-
"command": "
|
|
167
|
+
"command": "npx",
|
|
168
|
+
"args": ["-y", "ai-diagrams-mcp"]
|
|
43
169
|
}
|
|
44
170
|
}
|
|
45
171
|
}
|
|
46
172
|
```
|
|
47
173
|
|
|
48
|
-
|
|
174
|
+
</td>
|
|
175
|
+
</tr>
|
|
176
|
+
|
|
177
|
+
<tr>
|
|
178
|
+
<td><strong>Zed</strong></td>
|
|
179
|
+
<td>
|
|
49
180
|
|
|
50
|
-
|
|
181
|
+
Settings → Open Settings (JSON)
|
|
182
|
+
|
|
183
|
+
</td>
|
|
184
|
+
<td>
|
|
185
|
+
|
|
186
|
+
```json
|
|
187
|
+
{
|
|
188
|
+
"context_servers": {
|
|
189
|
+
"ai-diagrams": {
|
|
190
|
+
"command": {
|
|
191
|
+
"path": "npx",
|
|
192
|
+
"args": ["-y", "ai-diagrams-mcp"]
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
</td>
|
|
200
|
+
</tr>
|
|
201
|
+
|
|
202
|
+
<tr>
|
|
203
|
+
<td><strong>OpenAI Codex CLI</strong></td>
|
|
204
|
+
<td>
|
|
205
|
+
|
|
206
|
+
`~/.codex/config.toml`
|
|
207
|
+
|
|
208
|
+
</td>
|
|
209
|
+
<td>
|
|
210
|
+
|
|
211
|
+
```toml
|
|
212
|
+
[mcp_servers.ai-diagrams]
|
|
213
|
+
command = "npx"
|
|
214
|
+
args = ["-y", "ai-diagrams-mcp"]
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
Or via CLI: `codex mcp add ai-diagrams -- npx -y ai-diagrams-mcp`
|
|
218
|
+
|
|
219
|
+
</td>
|
|
220
|
+
</tr>
|
|
221
|
+
|
|
222
|
+
<tr>
|
|
223
|
+
<td><strong>JetBrains IDEs</strong></td>
|
|
224
|
+
<td>
|
|
225
|
+
|
|
226
|
+
Settings → Tools → MCP Server
|
|
227
|
+
|
|
228
|
+
</td>
|
|
229
|
+
<td>
|
|
51
230
|
|
|
52
231
|
```json
|
|
53
232
|
{
|
|
@@ -60,9 +239,14 @@ Add to your Claude Code MCP settings (`~/.claude/claude_desktop_config.json` or
|
|
|
60
239
|
}
|
|
61
240
|
```
|
|
62
241
|
|
|
242
|
+
</td>
|
|
243
|
+
</tr>
|
|
244
|
+
|
|
245
|
+
</table>
|
|
246
|
+
|
|
63
247
|
## Usage
|
|
64
248
|
|
|
65
|
-
Once configured,
|
|
249
|
+
Once configured, ask your AI assistant to render diagrams:
|
|
66
250
|
|
|
67
251
|
> "Create a flowchart showing the user authentication process"
|
|
68
252
|
|
|
@@ -74,11 +258,13 @@ The `render_diagram` tool accepts:
|
|
|
74
258
|
|
|
75
259
|
- **diagrams** - Array of `{ title?: string, code: string }` objects
|
|
76
260
|
- **theme** - Optional: `'default'` | `'dark'` | `'forest'` | `'neutral'`
|
|
261
|
+
- **share** - Optional: `true` to upload and get a public shareable link
|
|
262
|
+
- **shareExpiry** - Optional: `'1h'` | `'12h'` | `'24h'` | `'72h'` (default: `'1h'`)
|
|
77
263
|
|
|
78
264
|
## Example
|
|
79
265
|
|
|
80
266
|
```javascript
|
|
81
|
-
// Tool call
|
|
267
|
+
// Tool call - local only
|
|
82
268
|
{
|
|
83
269
|
"diagrams": [
|
|
84
270
|
{
|
|
@@ -88,8 +274,37 @@ The `render_diagram` tool accepts:
|
|
|
88
274
|
],
|
|
89
275
|
"theme": "dark"
|
|
90
276
|
}
|
|
277
|
+
|
|
278
|
+
// Tool call - with shareable link
|
|
279
|
+
{
|
|
280
|
+
"diagrams": [
|
|
281
|
+
{
|
|
282
|
+
"title": "Authentication Flow",
|
|
283
|
+
"code": "graph TD\n A[User] -->|Login| B[Auth Server]\n B -->|Token| A"
|
|
284
|
+
}
|
|
285
|
+
],
|
|
286
|
+
"share": true
|
|
287
|
+
}
|
|
91
288
|
```
|
|
92
289
|
|
|
290
|
+
## Supported Diagram Types
|
|
291
|
+
|
|
292
|
+
Mermaid supports many diagram types including:
|
|
293
|
+
|
|
294
|
+
- Flowcharts
|
|
295
|
+
- Sequence Diagrams
|
|
296
|
+
- Class Diagrams
|
|
297
|
+
- State Diagrams
|
|
298
|
+
- Entity Relationship Diagrams
|
|
299
|
+
- Gantt Charts
|
|
300
|
+
- Pie Charts
|
|
301
|
+
- Mind Maps
|
|
302
|
+
- Timeline
|
|
303
|
+
- Git Graphs
|
|
304
|
+
- Quadrant Charts
|
|
305
|
+
|
|
306
|
+
See [Mermaid documentation](https://mermaid.js.org/intro/) for full syntax reference.
|
|
307
|
+
|
|
93
308
|
## Viewer Features
|
|
94
309
|
|
|
95
310
|
- **Zoom Controls** - Use +/- buttons or pinch gesture on trackpad
|
|
@@ -97,6 +312,31 @@ The `render_diagram` tool accepts:
|
|
|
97
312
|
- **Reset** - Return to original view
|
|
98
313
|
- **Theme Toggle** - Switch between light, dark, and system modes
|
|
99
314
|
|
|
315
|
+
## Sharing
|
|
316
|
+
|
|
317
|
+
Generate temporary public links to share diagrams with colleagues:
|
|
318
|
+
|
|
319
|
+
```javascript
|
|
320
|
+
{
|
|
321
|
+
"diagrams": [...],
|
|
322
|
+
"share": true,
|
|
323
|
+
"shareExpiry": "24h" // Options: 1h, 12h, 24h, 72h
|
|
324
|
+
}
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
- No account required
|
|
328
|
+
- Full interactive viewer with zoom/pan
|
|
329
|
+
- Links expire automatically (default: 1h)
|
|
330
|
+
|
|
331
|
+
## Output Files
|
|
332
|
+
|
|
333
|
+
Each render creates two files in the temp directory:
|
|
334
|
+
|
|
335
|
+
- `mermaid-viewer-{uuid}.html` - Interactive viewer (opened in browser)
|
|
336
|
+
- `mermaid-source-{uuid}.json` - Diagram source for reference/iteration
|
|
337
|
+
|
|
338
|
+
The source file makes it easy to adjust and re-render diagrams.
|
|
339
|
+
|
|
100
340
|
## Development
|
|
101
341
|
|
|
102
342
|
```bash
|
|
@@ -122,6 +362,12 @@ npm start
|
|
|
122
362
|
- **Zoom/Pan**: @panzoom/panzoom
|
|
123
363
|
- **MCP SDK**: @modelcontextprotocol/sdk
|
|
124
364
|
|
|
365
|
+
## Resources
|
|
366
|
+
|
|
367
|
+
- [Model Context Protocol](https://modelcontextprotocol.io/) - MCP specification
|
|
368
|
+
- [Mermaid.js](https://mermaid.js.org/) - Diagram syntax documentation
|
|
369
|
+
- [MCP Servers Directory](https://github.com/modelcontextprotocol/servers) - Community MCP servers
|
|
370
|
+
|
|
125
371
|
## License
|
|
126
372
|
|
|
127
373
|
MIT
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export interface ShareResult {
|
|
2
|
+
url: string;
|
|
3
|
+
expiresIn: string;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Format expiry for display
|
|
7
|
+
*/
|
|
8
|
+
export declare function formatExpiry(expiresIn: string): string;
|
|
9
|
+
/**
|
|
10
|
+
* Upload HTML to litterbox.catbox.moe (anonymous, temporary file hosting)
|
|
11
|
+
* No restrictive CSP - JavaScript execution works fully
|
|
12
|
+
*
|
|
13
|
+
* Retention options: 1h, 12h, 24h, 72h
|
|
14
|
+
*/
|
|
15
|
+
export declare function uploadToLitterbox(html: string, filename: string, time?: '1h' | '12h' | '24h' | '72h'): Promise<ShareResult>;
|
|
16
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/sharing/index.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,WAAW;IAC1B,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAEtD;AAED;;;;;GAKG;AACH,wBAAsB,iBAAiB,CACrC,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,EAChB,IAAI,GAAE,IAAI,GAAG,KAAK,GAAG,KAAK,GAAG,KAAa,GACzC,OAAO,CAAC,WAAW,CAAC,CAkBtB"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Format expiry for display
|
|
3
|
+
*/
|
|
4
|
+
export function formatExpiry(expiresIn) {
|
|
5
|
+
return `in ${expiresIn}`;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Upload HTML to litterbox.catbox.moe (anonymous, temporary file hosting)
|
|
9
|
+
* No restrictive CSP - JavaScript execution works fully
|
|
10
|
+
*
|
|
11
|
+
* Retention options: 1h, 12h, 24h, 72h
|
|
12
|
+
*/
|
|
13
|
+
export async function uploadToLitterbox(html, filename, time = '72h') {
|
|
14
|
+
const formData = new FormData();
|
|
15
|
+
formData.append('reqtype', 'fileupload');
|
|
16
|
+
formData.append('time', time);
|
|
17
|
+
formData.append('fileToUpload', new Blob([html], { type: 'text/html' }), filename);
|
|
18
|
+
const response = await fetch('https://litterbox.catbox.moe/resources/internals/api.php', {
|
|
19
|
+
method: 'POST',
|
|
20
|
+
body: formData,
|
|
21
|
+
});
|
|
22
|
+
if (!response.ok) {
|
|
23
|
+
throw new Error(`Upload failed: ${response.status} ${response.statusText}`);
|
|
24
|
+
}
|
|
25
|
+
const url = await response.text();
|
|
26
|
+
return { url: url.trim(), expiresIn: time };
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/sharing/index.ts"],"names":[],"mappings":"AAKA;;GAEG;AACH,MAAM,UAAU,YAAY,CAAC,SAAiB;IAC5C,OAAO,MAAM,SAAS,EAAE,CAAC;AAC3B,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,IAAY,EACZ,QAAgB,EAChB,OAAqC,KAAK;IAE1C,MAAM,QAAQ,GAAG,IAAI,QAAQ,EAAE,CAAC;IAChC,QAAQ,CAAC,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC;IACzC,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAC9B,QAAQ,CAAC,MAAM,CAAC,cAAc,EAAE,IAAI,IAAI,CAAC,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC,EAAE,QAAQ,CAAC,CAAC;IAEnF,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,0DAA0D,EAAE;QACvF,MAAM,EAAE,MAAM;QACd,IAAI,EAAE,QAAQ;KACf,CAAC,CAAC;IAEH,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;QACjB,MAAM,IAAI,KAAK,CAAC,kBAAkB,QAAQ,CAAC,MAAM,IAAI,QAAQ,CAAC,UAAU,EAAE,CAAC,CAAC;IAC9E,CAAC;IAED,MAAM,GAAG,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;IAElC,OAAO,EAAE,GAAG,EAAE,GAAG,CAAC,IAAI,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;AAC9C,CAAC"}
|
|
@@ -10,6 +10,13 @@ export declare const renderDiagramSchema: z.ZodObject<{
|
|
|
10
10
|
forest: "forest";
|
|
11
11
|
neutral: "neutral";
|
|
12
12
|
}>>>;
|
|
13
|
+
share: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
14
|
+
shareExpiry: z.ZodDefault<z.ZodOptional<z.ZodEnum<{
|
|
15
|
+
"1h": "1h";
|
|
16
|
+
"12h": "12h";
|
|
17
|
+
"24h": "24h";
|
|
18
|
+
"72h": "72h";
|
|
19
|
+
}>>>;
|
|
13
20
|
}, z.core.$strip>;
|
|
14
21
|
export type RenderDiagramInput = z.infer<typeof renderDiagramSchema>;
|
|
15
22
|
export declare function renderDiagram(input: RenderDiagramInput): Promise<string>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render-diagram.d.ts","sourceRoot":"","sources":["../../src/tools/render-diagram.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"render-diagram.d.ts","sourceRoot":"","sources":["../../src/tools/render-diagram.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;iBAyB9B,CAAC;AAEH,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAErE,wBAAsB,aAAa,CAAC,KAAK,EAAE,kBAAkB,GAAG,OAAO,CAAC,MAAM,CAAC,CAmD9E"}
|
|
@@ -4,6 +4,7 @@ import { tmpdir } from 'node:os';
|
|
|
4
4
|
import { join } from 'node:path';
|
|
5
5
|
import open from 'open';
|
|
6
6
|
import { z } from 'zod';
|
|
7
|
+
import { uploadToLitterbox, formatExpiry } from '../sharing/index.js';
|
|
7
8
|
import { generateViewerHTML } from '../templates/viewer-bundle.js';
|
|
8
9
|
export const renderDiagramSchema = z.object({
|
|
9
10
|
diagrams: z
|
|
@@ -18,6 +19,16 @@ export const renderDiagramSchema = z.object({
|
|
|
18
19
|
.optional()
|
|
19
20
|
.default('default')
|
|
20
21
|
.describe('Mermaid theme to use'),
|
|
22
|
+
share: z
|
|
23
|
+
.boolean()
|
|
24
|
+
.optional()
|
|
25
|
+
.default(false)
|
|
26
|
+
.describe('Upload and return a public shareable link'),
|
|
27
|
+
shareExpiry: z
|
|
28
|
+
.enum(['1h', '12h', '24h', '72h'])
|
|
29
|
+
.optional()
|
|
30
|
+
.default('1h')
|
|
31
|
+
.describe('How long the shareable link should last (default: 1h)'),
|
|
21
32
|
});
|
|
22
33
|
export async function renderDiagram(input) {
|
|
23
34
|
// Validate input
|
|
@@ -28,15 +39,39 @@ export async function renderDiagram(input) {
|
|
|
28
39
|
theme: validated.theme,
|
|
29
40
|
});
|
|
30
41
|
// Create unique filename in temp directory
|
|
31
|
-
const
|
|
42
|
+
const uuid = randomUUID();
|
|
43
|
+
const filename = `mermaid-viewer-${uuid}.html`;
|
|
32
44
|
const filepath = join(tmpdir(), filename);
|
|
33
|
-
//
|
|
34
|
-
|
|
45
|
+
// Also save diagram source for easy reference/iteration
|
|
46
|
+
const sourceFilename = `mermaid-source-${uuid}.json`;
|
|
47
|
+
const sourceFilepath = join(tmpdir(), sourceFilename);
|
|
48
|
+
const sourceData = {
|
|
49
|
+
diagrams: validated.diagrams,
|
|
50
|
+
theme: validated.theme,
|
|
51
|
+
generatedAt: new Date().toISOString(),
|
|
52
|
+
};
|
|
53
|
+
// Write HTML file and source file
|
|
54
|
+
await Promise.all([
|
|
55
|
+
writeFile(filepath, html, 'utf-8'),
|
|
56
|
+
writeFile(sourceFilepath, JSON.stringify(sourceData, null, 2), 'utf-8'),
|
|
57
|
+
]);
|
|
35
58
|
// Open in default browser
|
|
36
59
|
await open(filepath);
|
|
37
|
-
//
|
|
60
|
+
// Build result message
|
|
38
61
|
const diagramCount = validated.diagrams.length;
|
|
39
62
|
const diagramWord = diagramCount === 1 ? 'diagram' : 'diagrams';
|
|
40
|
-
|
|
63
|
+
let result = `Successfully rendered ${diagramCount} ${diagramWord} and opened in browser.\nFile saved to: ${filepath}\nSource saved to: ${sourceFilepath}`;
|
|
64
|
+
// Upload to litterbox if sharing is enabled
|
|
65
|
+
if (validated.share) {
|
|
66
|
+
try {
|
|
67
|
+
const shareResult = await uploadToLitterbox(html, filename, validated.shareExpiry);
|
|
68
|
+
result += `\n\nShareable link: ${shareResult.url}\nExpires: ${formatExpiry(shareResult.expiresIn)}`;
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
72
|
+
result += `\n\nFailed to create shareable link: ${message}`;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return result;
|
|
41
76
|
}
|
|
42
77
|
//# sourceMappingURL=render-diagram.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render-diagram.js","sourceRoot":"","sources":["../../src/tools/render-diagram.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,kBAAkB,EAAqB,MAAM,+BAA+B,CAAC;AAEtF,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC1C,QAAQ,EAAE,CAAC;SACR,KAAK,CACJ,CAAC,CAAC,MAAM,CAAC;QACP,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,gCAAgC,CAAC;QACvE,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,sBAAsB,CAAC;KAClD,CAAC,CACH;SACA,GAAG,CAAC,CAAC,CAAC;SACN,QAAQ,CAAC,6BAA6B,CAAC;IAC1C,KAAK,EAAE,CAAC;SACL,IAAI,CAAC,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC;SAC9C,QAAQ,EAAE;SACV,OAAO,CAAC,SAAS,CAAC;SAClB,QAAQ,CAAC,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"render-diagram.js","sourceRoot":"","sources":["../../src/tools/render-diagram.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CA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