@teamflojo/floimg-mermaid 0.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/LICENSE +21 -0
- package/README.md +426 -0
- package/dist/index.d.ts +68 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +118 -0
- package/dist/index.js.map +1 -0
- package/package.json +59 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Brett Cooke
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,426 @@
|
|
|
1
|
+
# imgflo-mermaid
|
|
2
|
+
|
|
3
|
+
Mermaid diagram generator for imgflo - create flowcharts, sequence diagrams, class diagrams, and more using Mermaid syntax.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install imgflo imgflo-mermaid
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
This will install Mermaid CLI (~50MB including dependencies).
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import createClient from 'imgflo';
|
|
17
|
+
import mermaid from 'imgflo-mermaid';
|
|
18
|
+
|
|
19
|
+
const imgflo = createClient({
|
|
20
|
+
store: {
|
|
21
|
+
default: 's3',
|
|
22
|
+
s3: { region: 'us-east-1', bucket: 'my-diagrams' }
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
// Register the Mermaid generator
|
|
27
|
+
imgflo.registerGenerator(mermaid());
|
|
28
|
+
|
|
29
|
+
// Generate a flowchart
|
|
30
|
+
const diagram = await imgflo.generate({
|
|
31
|
+
generator: 'mermaid',
|
|
32
|
+
params: {
|
|
33
|
+
code: `
|
|
34
|
+
graph TD
|
|
35
|
+
A[Start] --> B{Is it working?}
|
|
36
|
+
B -->|Yes| C[Great!]
|
|
37
|
+
B -->|No| D[Debug]
|
|
38
|
+
D --> B
|
|
39
|
+
`,
|
|
40
|
+
theme: 'dark'
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
// Upload to S3
|
|
45
|
+
const result = await imgflo.save(diagram, './output/flow.svg');
|
|
46
|
+
console.log(result.url);
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Diagram Types
|
|
50
|
+
|
|
51
|
+
Mermaid supports many diagram types - all available via pass-through syntax:
|
|
52
|
+
|
|
53
|
+
### Flowchart
|
|
54
|
+
|
|
55
|
+
```typescript
|
|
56
|
+
await imgflo.generate({
|
|
57
|
+
generator: 'mermaid',
|
|
58
|
+
params: {
|
|
59
|
+
code: `
|
|
60
|
+
graph LR
|
|
61
|
+
A[Square Rect] --> B(Rounded)
|
|
62
|
+
B --> C{Decision}
|
|
63
|
+
C -->|One| D[Result 1]
|
|
64
|
+
C -->|Two| E[Result 2]
|
|
65
|
+
`
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Sequence Diagram
|
|
71
|
+
|
|
72
|
+
```typescript
|
|
73
|
+
await imgflo.generate({
|
|
74
|
+
generator: 'mermaid',
|
|
75
|
+
params: {
|
|
76
|
+
code: `
|
|
77
|
+
sequenceDiagram
|
|
78
|
+
Alice->>John: Hello John, how are you?
|
|
79
|
+
John-->>Alice: Great!
|
|
80
|
+
Alice-)John: See you later!
|
|
81
|
+
`
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### Class Diagram
|
|
87
|
+
|
|
88
|
+
```typescript
|
|
89
|
+
await imgflo.generate({
|
|
90
|
+
generator: 'mermaid',
|
|
91
|
+
params: {
|
|
92
|
+
code: `
|
|
93
|
+
classDiagram
|
|
94
|
+
Animal <|-- Duck
|
|
95
|
+
Animal <|-- Fish
|
|
96
|
+
Animal : +int age
|
|
97
|
+
Animal : +String gender
|
|
98
|
+
Animal: +isMammal()
|
|
99
|
+
class Duck{
|
|
100
|
+
+String beakColor
|
|
101
|
+
+swim()
|
|
102
|
+
+quack()
|
|
103
|
+
}
|
|
104
|
+
`
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### State Diagram
|
|
110
|
+
|
|
111
|
+
```typescript
|
|
112
|
+
await imgflo.generate({
|
|
113
|
+
generator: 'mermaid',
|
|
114
|
+
params: {
|
|
115
|
+
code: `
|
|
116
|
+
stateDiagram-v2
|
|
117
|
+
[*] --> Still
|
|
118
|
+
Still --> [*]
|
|
119
|
+
Still --> Moving
|
|
120
|
+
Moving --> Still
|
|
121
|
+
Moving --> Crash
|
|
122
|
+
Crash --> [*]
|
|
123
|
+
`
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
### Entity Relationship Diagram
|
|
129
|
+
|
|
130
|
+
```typescript
|
|
131
|
+
await imgflo.generate({
|
|
132
|
+
generator: 'mermaid',
|
|
133
|
+
params: {
|
|
134
|
+
code: `
|
|
135
|
+
erDiagram
|
|
136
|
+
CUSTOMER ||--o{ ORDER : places
|
|
137
|
+
ORDER ||--|{ LINE-ITEM : contains
|
|
138
|
+
CUSTOMER }|..|{ DELIVERY-ADDRESS : uses
|
|
139
|
+
`
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### Gantt Chart
|
|
145
|
+
|
|
146
|
+
```typescript
|
|
147
|
+
await imgflo.generate({
|
|
148
|
+
generator: 'mermaid',
|
|
149
|
+
params: {
|
|
150
|
+
code: `
|
|
151
|
+
gantt
|
|
152
|
+
title A Gantt Diagram
|
|
153
|
+
dateFormat YYYY-MM-DD
|
|
154
|
+
section Section
|
|
155
|
+
A task :a1, 2024-01-01, 30d
|
|
156
|
+
Another task :after a1, 20d
|
|
157
|
+
`
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### Pie Chart
|
|
163
|
+
|
|
164
|
+
```typescript
|
|
165
|
+
await imgflo.generate({
|
|
166
|
+
generator: 'mermaid',
|
|
167
|
+
params: {
|
|
168
|
+
code: `
|
|
169
|
+
pie title Pets adopted by volunteers
|
|
170
|
+
"Dogs" : 386
|
|
171
|
+
"Cats" : 85
|
|
172
|
+
"Rats" : 15
|
|
173
|
+
`
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### Git Graph
|
|
179
|
+
|
|
180
|
+
```typescript
|
|
181
|
+
await imgflo.generate({
|
|
182
|
+
generator: 'mermaid',
|
|
183
|
+
params: {
|
|
184
|
+
code: `
|
|
185
|
+
gitGraph
|
|
186
|
+
commit
|
|
187
|
+
commit
|
|
188
|
+
branch develop
|
|
189
|
+
checkout develop
|
|
190
|
+
commit
|
|
191
|
+
commit
|
|
192
|
+
checkout main
|
|
193
|
+
merge develop
|
|
194
|
+
`
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
## Configuration
|
|
200
|
+
|
|
201
|
+
### Generator Options
|
|
202
|
+
|
|
203
|
+
```typescript
|
|
204
|
+
imgflo.registerGenerator(mermaid({
|
|
205
|
+
theme: 'dark', // Default theme
|
|
206
|
+
backgroundColor: '#1a1a1a', // Default background
|
|
207
|
+
format: 'svg', // 'svg' | 'png'
|
|
208
|
+
width: 800, // Default width (for PNG)
|
|
209
|
+
height: 600 // Default height (for PNG)
|
|
210
|
+
}));
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
### Per-Diagram Overrides
|
|
214
|
+
|
|
215
|
+
```typescript
|
|
216
|
+
await imgflo.generate({
|
|
217
|
+
generator: 'mermaid',
|
|
218
|
+
params: {
|
|
219
|
+
code: '...',
|
|
220
|
+
theme: 'forest', // Override theme
|
|
221
|
+
backgroundColor: 'transparent',
|
|
222
|
+
format: 'png', // Generate PNG instead
|
|
223
|
+
width: 1200,
|
|
224
|
+
height: 800
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
### Available Themes
|
|
230
|
+
|
|
231
|
+
- `default` - Default Mermaid theme
|
|
232
|
+
- `forest` - Green theme
|
|
233
|
+
- `dark` - Dark theme
|
|
234
|
+
- `neutral` - Neutral grey theme
|
|
235
|
+
|
|
236
|
+
### Advanced Configuration
|
|
237
|
+
|
|
238
|
+
Pass Mermaid config object directly:
|
|
239
|
+
|
|
240
|
+
```typescript
|
|
241
|
+
await imgflo.generate({
|
|
242
|
+
generator: 'mermaid',
|
|
243
|
+
params: {
|
|
244
|
+
code: '...',
|
|
245
|
+
mermaidConfig: {
|
|
246
|
+
theme: 'base',
|
|
247
|
+
themeVariables: {
|
|
248
|
+
primaryColor: '#BB2528',
|
|
249
|
+
primaryTextColor: '#fff',
|
|
250
|
+
primaryBorderColor: '#7C0000',
|
|
251
|
+
lineColor: '#F8B229',
|
|
252
|
+
secondaryColor: '#006100',
|
|
253
|
+
tertiaryColor: '#fff'
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
});
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
## Mermaid Documentation
|
|
261
|
+
|
|
262
|
+
Since this generator uses Mermaid syntax directly, refer to the official Mermaid docs:
|
|
263
|
+
|
|
264
|
+
- **Diagram Types**: https://mermaid.js.org/intro/syntax-reference.html
|
|
265
|
+
- **Flowcharts**: https://mermaid.js.org/syntax/flowchart.html
|
|
266
|
+
- **Sequence Diagrams**: https://mermaid.js.org/syntax/sequenceDiagram.html
|
|
267
|
+
- **Configuration**: https://mermaid.js.org/config/setup/modules/mermaidAPI.html
|
|
268
|
+
- **Themes**: https://mermaid.js.org/config/theming.html
|
|
269
|
+
|
|
270
|
+
## Examples
|
|
271
|
+
|
|
272
|
+
### System Architecture
|
|
273
|
+
|
|
274
|
+
```typescript
|
|
275
|
+
const architecture = await imgflo.generate({
|
|
276
|
+
generator: 'mermaid',
|
|
277
|
+
params: {
|
|
278
|
+
code: `
|
|
279
|
+
graph TB
|
|
280
|
+
subgraph "Frontend"
|
|
281
|
+
A[React App]
|
|
282
|
+
B[Next.js]
|
|
283
|
+
end
|
|
284
|
+
subgraph "Backend"
|
|
285
|
+
C[API Gateway]
|
|
286
|
+
D[Lambda Functions]
|
|
287
|
+
E[(Database)]
|
|
288
|
+
end
|
|
289
|
+
A --> C
|
|
290
|
+
B --> C
|
|
291
|
+
C --> D
|
|
292
|
+
D --> E
|
|
293
|
+
`,
|
|
294
|
+
theme: 'dark',
|
|
295
|
+
backgroundColor: 'transparent'
|
|
296
|
+
}
|
|
297
|
+
});
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
### User Journey
|
|
301
|
+
|
|
302
|
+
```typescript
|
|
303
|
+
const journey = await imgflo.generate({
|
|
304
|
+
generator: 'mermaid',
|
|
305
|
+
params: {
|
|
306
|
+
code: `
|
|
307
|
+
journey
|
|
308
|
+
title My working day
|
|
309
|
+
section Go to work
|
|
310
|
+
Make tea: 5: Me
|
|
311
|
+
Go upstairs: 3: Me
|
|
312
|
+
Do work: 1: Me, Cat
|
|
313
|
+
section Go home
|
|
314
|
+
Go downstairs: 5: Me
|
|
315
|
+
Sit down: 5: Me
|
|
316
|
+
`
|
|
317
|
+
}
|
|
318
|
+
});
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
### Mind Map
|
|
322
|
+
|
|
323
|
+
```typescript
|
|
324
|
+
const mindMap = await imgflo.generate({
|
|
325
|
+
generator: 'mermaid',
|
|
326
|
+
params: {
|
|
327
|
+
code: `
|
|
328
|
+
mindmap
|
|
329
|
+
root((imgflo))
|
|
330
|
+
Generators
|
|
331
|
+
Shapes
|
|
332
|
+
OpenAI
|
|
333
|
+
QuickChart
|
|
334
|
+
Mermaid
|
|
335
|
+
Transform
|
|
336
|
+
Convert
|
|
337
|
+
Resize
|
|
338
|
+
Upload
|
|
339
|
+
S3
|
|
340
|
+
Filesystem
|
|
341
|
+
`
|
|
342
|
+
}
|
|
343
|
+
});
|
|
344
|
+
```
|
|
345
|
+
|
|
346
|
+
## Output Formats
|
|
347
|
+
|
|
348
|
+
### SVG (Default)
|
|
349
|
+
|
|
350
|
+
```typescript
|
|
351
|
+
// Returns scalable vector graphic
|
|
352
|
+
const svg = await imgflo.generate({
|
|
353
|
+
generator: 'mermaid',
|
|
354
|
+
params: { code: '...', format: 'svg' }
|
|
355
|
+
});
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
### PNG
|
|
359
|
+
|
|
360
|
+
```typescript
|
|
361
|
+
// Returns raster image
|
|
362
|
+
const png = await imgflo.generate({
|
|
363
|
+
generator: 'mermaid',
|
|
364
|
+
params: {
|
|
365
|
+
code: '...',
|
|
366
|
+
format: 'png',
|
|
367
|
+
width: 1920,
|
|
368
|
+
height: 1080
|
|
369
|
+
}
|
|
370
|
+
});
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
## Performance
|
|
374
|
+
|
|
375
|
+
- **First render**: ~1-2 seconds (includes CLI startup)
|
|
376
|
+
- **Subsequent renders**: ~500ms-1s per diagram
|
|
377
|
+
- **Memory**: ~50-100MB per process
|
|
378
|
+
|
|
379
|
+
## Troubleshooting
|
|
380
|
+
|
|
381
|
+
### "Mermaid code parsing failed"
|
|
382
|
+
|
|
383
|
+
Check your Mermaid syntax:
|
|
384
|
+
```typescript
|
|
385
|
+
// ❌ Bad syntax
|
|
386
|
+
code: `graph TD A -> B`
|
|
387
|
+
|
|
388
|
+
// ✅ Correct syntax
|
|
389
|
+
code: `graph TD\n A --> B`
|
|
390
|
+
```
|
|
391
|
+
|
|
392
|
+
### Diagram not rendering
|
|
393
|
+
|
|
394
|
+
Ensure proper indentation and whitespace:
|
|
395
|
+
```typescript
|
|
396
|
+
code: `
|
|
397
|
+
graph TD
|
|
398
|
+
A[Start] --> B[End]
|
|
399
|
+
`
|
|
400
|
+
```
|
|
401
|
+
|
|
402
|
+
### Theme not applying
|
|
403
|
+
|
|
404
|
+
Make sure theme name is valid:
|
|
405
|
+
```typescript
|
|
406
|
+
theme: 'dark' // ✅ Valid
|
|
407
|
+
theme: 'blue' // ❌ Invalid
|
|
408
|
+
```
|
|
409
|
+
|
|
410
|
+
## Why Mermaid?
|
|
411
|
+
|
|
412
|
+
- **Text-based**: Easy to version control and generate programmatically
|
|
413
|
+
- **Wide support**: Many diagram types
|
|
414
|
+
- **Clean syntax**: Human-readable
|
|
415
|
+
- **AI-friendly**: Easy for LLMs to generate
|
|
416
|
+
- **No GUI needed**: Perfect for automation
|
|
417
|
+
|
|
418
|
+
## License
|
|
419
|
+
|
|
420
|
+
MIT
|
|
421
|
+
|
|
422
|
+
## See Also
|
|
423
|
+
|
|
424
|
+
- [imgflo](https://github.com/bcooke/imgflo) - Core library
|
|
425
|
+
- [Mermaid](https://mermaid.js.org) - Diagram library
|
|
426
|
+
- [Mermaid Live Editor](https://mermaid.live) - Test diagrams
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { ImageGenerator, GeneratorSchema } from "@teamflojo/floimg";
|
|
2
|
+
/**
|
|
3
|
+
* Schema for the Mermaid diagram generator
|
|
4
|
+
*/
|
|
5
|
+
export declare const mermaidSchema: GeneratorSchema;
|
|
6
|
+
/**
|
|
7
|
+
* Mermaid diagram generator - creates diagrams using Mermaid syntax
|
|
8
|
+
*
|
|
9
|
+
* This generator accepts Mermaid diagram syntax directly (pass-through pattern).
|
|
10
|
+
* No imgflo abstraction - you get full Mermaid capabilities.
|
|
11
|
+
*
|
|
12
|
+
* @see https://mermaid.js.org/intro/ - Mermaid documentation
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* import createClient from '@teamflojo/floimg';
|
|
17
|
+
* import mermaid from '@teamflojo/floimg-mermaid';
|
|
18
|
+
*
|
|
19
|
+
* const floimg = createClient();
|
|
20
|
+
* floimg.registerGenerator(mermaid());
|
|
21
|
+
*
|
|
22
|
+
* const diagram = await floimg.generate({
|
|
23
|
+
* generator: 'mermaid',
|
|
24
|
+
* params: {
|
|
25
|
+
* code: `
|
|
26
|
+
* graph TD
|
|
27
|
+
* A[Start] --> B[Process]
|
|
28
|
+
* B --> C[End]
|
|
29
|
+
* `,
|
|
30
|
+
* theme: 'dark'
|
|
31
|
+
* }
|
|
32
|
+
* });
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export interface MermaidConfig {
|
|
36
|
+
/** Default theme: 'default' | 'forest' | 'dark' | 'neutral' */
|
|
37
|
+
theme?: string;
|
|
38
|
+
/** Default background color */
|
|
39
|
+
backgroundColor?: string;
|
|
40
|
+
/** Output format: 'svg' | 'png' (default: 'svg') */
|
|
41
|
+
format?: 'svg' | 'png';
|
|
42
|
+
/** Image width (for PNG) */
|
|
43
|
+
width?: number;
|
|
44
|
+
/** Image height (for PNG) */
|
|
45
|
+
height?: number;
|
|
46
|
+
}
|
|
47
|
+
export interface MermaidParams extends Record<string, unknown> {
|
|
48
|
+
/** Mermaid diagram code (required) */
|
|
49
|
+
code?: string;
|
|
50
|
+
/** Theme override */
|
|
51
|
+
theme?: string;
|
|
52
|
+
/** Background color override */
|
|
53
|
+
backgroundColor?: string;
|
|
54
|
+
/** Format override */
|
|
55
|
+
format?: 'svg' | 'png';
|
|
56
|
+
/** Width override (for PNG) */
|
|
57
|
+
width?: number;
|
|
58
|
+
/** Height override (for PNG) */
|
|
59
|
+
height?: number;
|
|
60
|
+
/** Mermaid config object (advanced) */
|
|
61
|
+
mermaidConfig?: Record<string, unknown>;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Create a Mermaid generator instance
|
|
65
|
+
*/
|
|
66
|
+
export default function mermaid(config?: MermaidConfig): ImageGenerator;
|
|
67
|
+
export { mermaid };
|
|
68
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAa,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAMpF;;GAEG;AACH,eAAO,MAAM,aAAa,EAAE,eA8C3B,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,WAAW,aAAa;IAC5B,+DAA+D;IAC/D,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,+BAA+B;IAC/B,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,oDAAoD;IACpD,MAAM,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC;IACvB,4BAA4B;IAC5B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,6BAA6B;IAC7B,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,aAAc,SAAQ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAC5D,sCAAsC;IACtC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,qBAAqB;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,gCAAgC;IAChC,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,sBAAsB;IACtB,MAAM,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC;IACvB,+BAA+B;IAC/B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,gCAAgC;IAChC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,uCAAuC;IACvC,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACzC;AAED;;GAEG;AACH,MAAM,CAAC,OAAO,UAAU,OAAO,CAAC,MAAM,GAAE,aAAkB,GAAG,cAAc,CAkF1E;AAGD,OAAO,EAAE,OAAO,EAAE,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { run as runMermaid } from "@mermaid-js/mermaid-cli";
|
|
2
|
+
import { writeFile, unlink } from "fs/promises";
|
|
3
|
+
import { tmpdir } from "os";
|
|
4
|
+
import { join } from "path";
|
|
5
|
+
/**
|
|
6
|
+
* Schema for the Mermaid diagram generator
|
|
7
|
+
*/
|
|
8
|
+
export const mermaidSchema = {
|
|
9
|
+
name: "mermaid",
|
|
10
|
+
description: "Generate diagrams using Mermaid syntax (flowcharts, sequence diagrams, etc.)",
|
|
11
|
+
category: "Diagrams",
|
|
12
|
+
parameters: {
|
|
13
|
+
code: {
|
|
14
|
+
type: "string",
|
|
15
|
+
title: "Mermaid Code",
|
|
16
|
+
description: "Mermaid diagram syntax (e.g., 'graph TD; A-->B')",
|
|
17
|
+
},
|
|
18
|
+
theme: {
|
|
19
|
+
type: "string",
|
|
20
|
+
title: "Theme",
|
|
21
|
+
description: "Diagram color theme",
|
|
22
|
+
enum: ["default", "forest", "dark", "neutral"],
|
|
23
|
+
default: "default",
|
|
24
|
+
},
|
|
25
|
+
backgroundColor: {
|
|
26
|
+
type: "string",
|
|
27
|
+
title: "Background Color",
|
|
28
|
+
description: "Background color (hex or named color)",
|
|
29
|
+
default: "white",
|
|
30
|
+
},
|
|
31
|
+
format: {
|
|
32
|
+
type: "string",
|
|
33
|
+
title: "Output Format",
|
|
34
|
+
description: "Output image format",
|
|
35
|
+
enum: ["svg", "png"],
|
|
36
|
+
default: "svg",
|
|
37
|
+
},
|
|
38
|
+
width: {
|
|
39
|
+
type: "number",
|
|
40
|
+
title: "Width",
|
|
41
|
+
description: "Image width in pixels (for PNG)",
|
|
42
|
+
minimum: 100,
|
|
43
|
+
maximum: 4096,
|
|
44
|
+
},
|
|
45
|
+
height: {
|
|
46
|
+
type: "number",
|
|
47
|
+
title: "Height",
|
|
48
|
+
description: "Image height in pixels (for PNG)",
|
|
49
|
+
minimum: 100,
|
|
50
|
+
maximum: 4096,
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
requiredParameters: ["code"],
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Create a Mermaid generator instance
|
|
57
|
+
*/
|
|
58
|
+
export default function mermaid(config = {}) {
|
|
59
|
+
const { theme: defaultTheme = 'default', backgroundColor: defaultBgColor = 'white', format: defaultFormat = 'svg', width: defaultWidth, height: defaultHeight, } = config;
|
|
60
|
+
return {
|
|
61
|
+
name: "mermaid",
|
|
62
|
+
schema: mermaidSchema,
|
|
63
|
+
async generate(params) {
|
|
64
|
+
const { code, theme = defaultTheme, backgroundColor = defaultBgColor, format = defaultFormat, width = defaultWidth, height = defaultHeight, mermaidConfig = {}, } = params;
|
|
65
|
+
if (!code) {
|
|
66
|
+
throw new Error("Mermaid 'code' parameter is required");
|
|
67
|
+
}
|
|
68
|
+
// Create temp files
|
|
69
|
+
const tempId = Math.random().toString(36).substring(7);
|
|
70
|
+
const inputFile = join(tmpdir(), `mermaid-${tempId}.mmd`);
|
|
71
|
+
const outputFile = join(tmpdir(), `mermaid-${tempId}.${format}`);
|
|
72
|
+
try {
|
|
73
|
+
// Write Mermaid code to temp file
|
|
74
|
+
await writeFile(inputFile, code, 'utf-8');
|
|
75
|
+
// Build Mermaid CLI config
|
|
76
|
+
const cliConfig = {
|
|
77
|
+
theme,
|
|
78
|
+
backgroundColor,
|
|
79
|
+
...(width && { width }),
|
|
80
|
+
...(height && { height }),
|
|
81
|
+
...mermaidConfig,
|
|
82
|
+
};
|
|
83
|
+
// Run Mermaid CLI
|
|
84
|
+
await runMermaid(inputFile, outputFile, // CLI typing is too strict, we build valid paths
|
|
85
|
+
cliConfig);
|
|
86
|
+
// Read output
|
|
87
|
+
const { readFile } = await import('fs/promises');
|
|
88
|
+
const bytes = await readFile(outputFile);
|
|
89
|
+
// Determine MIME type
|
|
90
|
+
const mimeType = format === 'png' ? 'image/png' : 'image/svg+xml';
|
|
91
|
+
return {
|
|
92
|
+
bytes: Buffer.from(bytes),
|
|
93
|
+
mime: mimeType,
|
|
94
|
+
...(width && { width }),
|
|
95
|
+
...(height && { height }),
|
|
96
|
+
source: "mermaid",
|
|
97
|
+
metadata: {
|
|
98
|
+
theme,
|
|
99
|
+
format,
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
finally {
|
|
104
|
+
// Cleanup temp files
|
|
105
|
+
try {
|
|
106
|
+
await unlink(inputFile);
|
|
107
|
+
await unlink(outputFile);
|
|
108
|
+
}
|
|
109
|
+
catch (err) {
|
|
110
|
+
// Ignore cleanup errors
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
// Also export as named export for convenience
|
|
117
|
+
export { mermaid };
|
|
118
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":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
"description": "Mermaid diagram generator for floimg - create flowcharts, sequence diagrams, and more",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist",
|
|
16
|
+
"README.md",
|
|
17
|
+
"LICENSE"
|
|
18
|
+
],
|
|
19
|
+
"keywords": [
|
|
20
|
+
"floimg",
|
|
21
|
+
"mermaid",
|
|
22
|
+
"diagram",
|
|
23
|
+
"flowchart",
|
|
24
|
+
"sequence-diagram",
|
|
25
|
+
"visualization",
|
|
26
|
+
"image-generation"
|
|
27
|
+
],
|
|
28
|
+
"author": "Brett Cooke",
|
|
29
|
+
"license": "MIT",
|
|
30
|
+
"repository": {
|
|
31
|
+
"type": "git",
|
|
32
|
+
"url": "https://github.com/TeamFlojo/floimg.git",
|
|
33
|
+
"directory": "packages/floimg-mermaid"
|
|
34
|
+
},
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"@teamflojo/floimg": "^0.1.0"
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"@mermaid-js/mermaid-cli": "^11.4.1",
|
|
40
|
+
"puppeteer": "^23.11.1"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@types/node": "^22.10.2",
|
|
44
|
+
"typescript": "^5.7.2",
|
|
45
|
+
"vitest": "^2.1.8",
|
|
46
|
+
"@teamflojo/floimg": "0.1.0"
|
|
47
|
+
},
|
|
48
|
+
"engines": {
|
|
49
|
+
"node": ">=18.0.0"
|
|
50
|
+
},
|
|
51
|
+
"scripts": {
|
|
52
|
+
"build": "tsc",
|
|
53
|
+
"dev": "tsc --watch",
|
|
54
|
+
"test": "vitest",
|
|
55
|
+
"typecheck": "tsc --noEmit",
|
|
56
|
+
"clean": "rm -rf dist",
|
|
57
|
+
"postinstall": "puppeteer browsers install chrome"
|
|
58
|
+
}
|
|
59
|
+
}
|