@diagrammo/dgmo 0.0.1
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 +335 -0
- package/dist/index.cjs +6698 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +685 -0
- package/dist/index.d.ts +685 -0
- package/dist/index.js +6611 -0
- package/dist/index.js.map +1 -0
- package/package.json +51 -0
- package/src/chartjs.ts +784 -0
- package/src/colors.ts +75 -0
- package/src/d3.ts +5021 -0
- package/src/dgmo-mermaid.ts +247 -0
- package/src/dgmo-router.ts +77 -0
- package/src/echarts.ts +1207 -0
- package/src/index.ts +126 -0
- package/src/palettes/bold.ts +59 -0
- package/src/palettes/catppuccin.ts +76 -0
- package/src/palettes/color-utils.ts +191 -0
- package/src/palettes/gruvbox.ts +77 -0
- package/src/palettes/index.ts +35 -0
- package/src/palettes/mermaid-bridge.ts +220 -0
- package/src/palettes/nord.ts +59 -0
- package/src/palettes/one-dark.ts +62 -0
- package/src/palettes/registry.ts +92 -0
- package/src/palettes/rose-pine.ts +76 -0
- package/src/palettes/solarized.ts +69 -0
- package/src/palettes/tokyo-night.ts +78 -0
- package/src/palettes/types.ts +67 -0
- package/src/sequence/parser.ts +531 -0
- package/src/sequence/participant-inference.ts +178 -0
- package/src/sequence/renderer.ts +1487 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Diagrammo
|
|
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,335 @@
|
|
|
1
|
+
# @diagrammo/dgmo
|
|
2
|
+
|
|
3
|
+
A unified diagram markup language — parser, config builder, renderer, and color system.
|
|
4
|
+
|
|
5
|
+
Write simple, readable `.dgmo` text files and render them as charts, diagrams, and visualizations using Chart.js, ECharts, D3, or Mermaid.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @diagrammo/dgmo
|
|
11
|
+
# or
|
|
12
|
+
pnpm add @diagrammo/dgmo
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## How it works
|
|
16
|
+
|
|
17
|
+
Every `.dgmo` file is plain text with a `chart: <type>` header followed by metadata and data. The library routes each chart type to the right framework and gives you either:
|
|
18
|
+
|
|
19
|
+
- A **framework config object** you render yourself (Chart.js, ECharts, Mermaid)
|
|
20
|
+
- A **rendered SVG** via D3 or the built-in sequence renderer
|
|
21
|
+
|
|
22
|
+
```
|
|
23
|
+
parse → build config → render
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
All parsers are pure functions with no DOM dependency. Renderers that produce SVG accept a container element.
|
|
27
|
+
|
|
28
|
+
## Supported chart types
|
|
29
|
+
|
|
30
|
+
| Type | Framework | Description |
|
|
31
|
+
|------|-----------|-------------|
|
|
32
|
+
| `bar` | Chart.js | Vertical/horizontal bar charts |
|
|
33
|
+
| `bar-stacked` | Chart.js | Stacked bar charts |
|
|
34
|
+
| `line` | Chart.js | Line charts with crosshair |
|
|
35
|
+
| `area` | Chart.js | Filled area charts |
|
|
36
|
+
| `pie` | Chart.js | Pie charts with connector labels |
|
|
37
|
+
| `doughnut` | Chart.js | Doughnut charts |
|
|
38
|
+
| `radar` | Chart.js | Radar/spider charts |
|
|
39
|
+
| `polar-area` | Chart.js | Polar area charts |
|
|
40
|
+
| `scatter` | ECharts | XY scatter with categories and sizing |
|
|
41
|
+
| `sankey` | ECharts | Flow diagrams |
|
|
42
|
+
| `chord` | ECharts | Circular relationship diagrams |
|
|
43
|
+
| `function` | ECharts | Mathematical function plots |
|
|
44
|
+
| `heatmap` | ECharts | Matrix heatmaps |
|
|
45
|
+
| `funnel` | ECharts | Conversion funnels |
|
|
46
|
+
| `slope` | D3 | Before/after comparison |
|
|
47
|
+
| `wordcloud` | D3 | Weighted text clouds |
|
|
48
|
+
| `arc` | D3 | Arc/network diagrams |
|
|
49
|
+
| `timeline` | D3 | Timelines with eras and markers |
|
|
50
|
+
| `venn` | D3 | Set intersection diagrams |
|
|
51
|
+
| `quadrant` | D3/Mermaid | 2D quadrant scatter |
|
|
52
|
+
| `sequence` | D3 | Sequence diagrams with type inference |
|
|
53
|
+
|
|
54
|
+
## Usage
|
|
55
|
+
|
|
56
|
+
### Chart.js (bar, line, pie, radar, etc.)
|
|
57
|
+
|
|
58
|
+
```typescript
|
|
59
|
+
import { parseChartJs, buildChartJsConfig } from '@diagrammo/dgmo';
|
|
60
|
+
import { Chart } from 'chart.js/auto';
|
|
61
|
+
|
|
62
|
+
const content = `
|
|
63
|
+
chart: bar
|
|
64
|
+
title: Revenue by Quarter
|
|
65
|
+
xlabel: Quarter
|
|
66
|
+
ylabel: Revenue ($M)
|
|
67
|
+
|
|
68
|
+
Q1: 12
|
|
69
|
+
Q2: 19
|
|
70
|
+
Q3: 15
|
|
71
|
+
Q4: 22
|
|
72
|
+
`;
|
|
73
|
+
|
|
74
|
+
const parsed = parseChartJs(content, palette.light);
|
|
75
|
+
const config = buildChartJsConfig(parsed, palette.light, false);
|
|
76
|
+
new Chart(canvas, config);
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### ECharts (scatter, sankey, heatmap, etc.)
|
|
80
|
+
|
|
81
|
+
```typescript
|
|
82
|
+
import { parseEChart, buildEChartsOption } from '@diagrammo/dgmo';
|
|
83
|
+
import * as echarts from 'echarts';
|
|
84
|
+
|
|
85
|
+
const content = `
|
|
86
|
+
chart: sankey
|
|
87
|
+
title: Energy Flow
|
|
88
|
+
|
|
89
|
+
Coal -> Electricity: 50
|
|
90
|
+
Gas -> Electricity: 30
|
|
91
|
+
Electricity -> Industry: 45
|
|
92
|
+
Electricity -> Homes: 35
|
|
93
|
+
`;
|
|
94
|
+
|
|
95
|
+
const parsed = parseEChart(content);
|
|
96
|
+
const option = buildEChartsOption(parsed, palette.light, false);
|
|
97
|
+
echarts.init(container).setOption(option);
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### D3 (slope, timeline, wordcloud, etc.)
|
|
101
|
+
|
|
102
|
+
```typescript
|
|
103
|
+
import { parseD3, renderTimeline } from '@diagrammo/dgmo';
|
|
104
|
+
|
|
105
|
+
const content = `
|
|
106
|
+
chart: timeline
|
|
107
|
+
title: Project Milestones
|
|
108
|
+
|
|
109
|
+
2024-01: Kickoff
|
|
110
|
+
2024-03 -> 2024-06: Development
|
|
111
|
+
2024-07: Launch
|
|
112
|
+
`;
|
|
113
|
+
|
|
114
|
+
const parsed = parseD3(content, palette.light);
|
|
115
|
+
renderTimeline(container, parsed, palette.light, false);
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### Sequence diagrams
|
|
119
|
+
|
|
120
|
+
Sequence diagrams use a minimal DSL. Participants are inferred from messages — no declaration blocks needed. Types (service, database, actor, queue, etc.) are inferred from naming conventions.
|
|
121
|
+
|
|
122
|
+
```typescript
|
|
123
|
+
import { parseSequenceDgmo, renderSequenceDiagram } from '@diagrammo/dgmo';
|
|
124
|
+
|
|
125
|
+
const content = `
|
|
126
|
+
title: Login Flow
|
|
127
|
+
|
|
128
|
+
User -> AuthService: login(email, pass)
|
|
129
|
+
AuthService -> UserDB: findByEmail(email)
|
|
130
|
+
UserDB -> AuthService: <- user
|
|
131
|
+
AuthService -> User: <- token
|
|
132
|
+
`;
|
|
133
|
+
|
|
134
|
+
const parsed = parseSequenceDgmo(content);
|
|
135
|
+
renderSequenceDiagram(container, parsed, palette.light, false, (lineNum) => {
|
|
136
|
+
// clicked a message — jump to that line in the editor
|
|
137
|
+
});
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
**Sequence syntax highlights:**
|
|
141
|
+
|
|
142
|
+
- `A -> B: message` — synchronous call
|
|
143
|
+
- `A ~> B: message` — async/fire-and-forget
|
|
144
|
+
- `A -> B: method(): returnValue` — call with return
|
|
145
|
+
- `if` / `else` / `end` — conditional blocks
|
|
146
|
+
- `loop` / `end` — loop blocks
|
|
147
|
+
- `parallel` / `else` / `end` — concurrent branches
|
|
148
|
+
- `== Section ==` — horizontal dividers
|
|
149
|
+
- `## GroupName(color)` — participant grouping
|
|
150
|
+
- `Name is a database` — explicit type declaration
|
|
151
|
+
- `Name position 0` — explicit ordering
|
|
152
|
+
|
|
153
|
+
**Participant type inference** — 162 rules map names to shapes automatically:
|
|
154
|
+
|
|
155
|
+
| Pattern | Inferred type | Shape |
|
|
156
|
+
|---------|--------------|-------|
|
|
157
|
+
| User, Admin, Alice, Bob | actor | stick figure |
|
|
158
|
+
| DB, Postgres, Mongo, Redis (store) | database | cylinder |
|
|
159
|
+
| Redis, Memcache (cache) | cache | dashed cylinder |
|
|
160
|
+
| Queue, Kafka, SQS, EventBus | queue | horizontal cylinder |
|
|
161
|
+
| Gateway, Proxy, LB, CDN | networking | shield |
|
|
162
|
+
| App, Browser, Dashboard, CLI | frontend | rounded rect |
|
|
163
|
+
| Service, API, Lambda, Fn | service | pill shape |
|
|
164
|
+
| External, ThirdParty, Vendor | external | dashed square |
|
|
165
|
+
|
|
166
|
+
### Routing
|
|
167
|
+
|
|
168
|
+
If you don't know the chart type ahead of time, use the router:
|
|
169
|
+
|
|
170
|
+
```typescript
|
|
171
|
+
import { parseDgmoChartType, getDgmoFramework } from '@diagrammo/dgmo';
|
|
172
|
+
|
|
173
|
+
const chartType = parseDgmoChartType(content); // e.g. 'bar'
|
|
174
|
+
const framework = getDgmoFramework(chartType); // e.g. 'chartjs'
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
Content with `->` arrows and no `chart:` header is automatically detected as a sequence diagram.
|
|
178
|
+
|
|
179
|
+
## .dgmo file format
|
|
180
|
+
|
|
181
|
+
Plain text. Lines starting with `#` or `//` are comments. Empty lines are ignored.
|
|
182
|
+
|
|
183
|
+
```
|
|
184
|
+
chart: <type>
|
|
185
|
+
title: Optional Title
|
|
186
|
+
xlabel: X Axis
|
|
187
|
+
ylabel: Y Axis
|
|
188
|
+
series: Series1, Series2
|
|
189
|
+
orientation: horizontal
|
|
190
|
+
|
|
191
|
+
# Data section
|
|
192
|
+
Label: value
|
|
193
|
+
Label (color): value
|
|
194
|
+
Label: value1, value2
|
|
195
|
+
|
|
196
|
+
# Connections (sankey, chord, arc)
|
|
197
|
+
Source -> Target: weight
|
|
198
|
+
|
|
199
|
+
# Groups
|
|
200
|
+
## Category Name
|
|
201
|
+
Item1: value
|
|
202
|
+
Item2: value
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
Colors can be specified inline as named colors (`red`, `blue`, `teal`, etc.) or hex values (`#ff6b6b`). They resolve against the active palette.
|
|
206
|
+
|
|
207
|
+
## Palettes
|
|
208
|
+
|
|
209
|
+
Eight built-in palettes, each with light and dark variants:
|
|
210
|
+
|
|
211
|
+
- `nordPalette` — cool, muted Scandinavian tones (default)
|
|
212
|
+
- `solarizedPalette` — warm/cool Solarized
|
|
213
|
+
- `catppuccinPalette` — modern pastels
|
|
214
|
+
- `rosePinePalette` — soft mauve and rose
|
|
215
|
+
- `gruvboxPalette` — retro groove
|
|
216
|
+
- `tokyoNightPalette` — Tokyo night
|
|
217
|
+
- `oneDarkPalette` — Atom One Dark inspired
|
|
218
|
+
- `boldPalette` — high-contrast
|
|
219
|
+
|
|
220
|
+
```typescript
|
|
221
|
+
import { getPalette, getAvailablePalettes, registerPalette } from '@diagrammo/dgmo';
|
|
222
|
+
|
|
223
|
+
// Use a built-in palette
|
|
224
|
+
const palette = getPalette('nord');
|
|
225
|
+
const colors = palette.light; // or palette.dark
|
|
226
|
+
|
|
227
|
+
// List available palettes
|
|
228
|
+
const all = getAvailablePalettes(); // [{ id, name }, ...]
|
|
229
|
+
|
|
230
|
+
// Register a custom palette
|
|
231
|
+
registerPalette({
|
|
232
|
+
id: 'custom',
|
|
233
|
+
name: 'My Theme',
|
|
234
|
+
light: { bg: '#fff', surface: '#f5f5f5', /* ... 17 more fields */ },
|
|
235
|
+
dark: { bg: '#1a1a1a', surface: '#2a2a2a', /* ... */ },
|
|
236
|
+
});
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
### Color utilities
|
|
240
|
+
|
|
241
|
+
```typescript
|
|
242
|
+
import { hexToHSL, hslToHex, mute, tint, shade, contrastText } from '@diagrammo/dgmo';
|
|
243
|
+
|
|
244
|
+
hexToHSL('#5e81ac') // { h: 213, s: 32, l: 52 }
|
|
245
|
+
mute('#5e81ac') // desaturated + darkened hex
|
|
246
|
+
tint('#5e81ac', 0.3) // blended toward white
|
|
247
|
+
contrastText('#2e3440', '#eceff4', '#2e3440') // WCAG-compliant pick
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
### Mermaid theming
|
|
251
|
+
|
|
252
|
+
Generate Mermaid-compatible CSS variables from any palette:
|
|
253
|
+
|
|
254
|
+
```typescript
|
|
255
|
+
import { buildMermaidThemeVars, buildThemeCSS } from '@diagrammo/dgmo';
|
|
256
|
+
|
|
257
|
+
const vars = buildMermaidThemeVars(palette.light); // ~121 CSS custom properties
|
|
258
|
+
const css = buildThemeCSS(palette.light); // complete CSS string
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
## SVG export
|
|
262
|
+
|
|
263
|
+
Render any D3-based chart to an SVG string (no visible DOM needed):
|
|
264
|
+
|
|
265
|
+
```typescript
|
|
266
|
+
import { renderD3ForExport } from '@diagrammo/dgmo';
|
|
267
|
+
|
|
268
|
+
const svgString = await renderD3ForExport(content, 'light');
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
## API overview
|
|
272
|
+
|
|
273
|
+
### Router
|
|
274
|
+
|
|
275
|
+
| Export | Description |
|
|
276
|
+
|--------|-------------|
|
|
277
|
+
| `parseDgmoChartType(content)` | Extract chart type from content |
|
|
278
|
+
| `getDgmoFramework(type)` | Map chart type to framework |
|
|
279
|
+
| `DGMO_CHART_TYPE_MAP` | Full type-to-framework registry |
|
|
280
|
+
|
|
281
|
+
### Parsers
|
|
282
|
+
|
|
283
|
+
| Export | Description |
|
|
284
|
+
|--------|-------------|
|
|
285
|
+
| `parseChartJs(content, colors)` | Parse Chart.js chart types |
|
|
286
|
+
| `parseEChart(content)` | Parse ECharts chart types |
|
|
287
|
+
| `parseD3(content, colors)` | Parse D3 chart types |
|
|
288
|
+
| `parseSequenceDgmo(content)` | Parse sequence diagrams |
|
|
289
|
+
| `parseQuadrant(content)` | Parse quadrant charts |
|
|
290
|
+
|
|
291
|
+
### Config builders
|
|
292
|
+
|
|
293
|
+
| Export | Description |
|
|
294
|
+
|--------|-------------|
|
|
295
|
+
| `buildChartJsConfig(parsed, colors, dark)` | Chart.js configuration object |
|
|
296
|
+
| `buildEChartsOption(parsed, colors, dark)` | ECharts option object |
|
|
297
|
+
| `buildMermaidQuadrant(parsed, colors)` | Mermaid quadrant syntax string |
|
|
298
|
+
|
|
299
|
+
### D3 renderers
|
|
300
|
+
|
|
301
|
+
| Export | Description |
|
|
302
|
+
|--------|-------------|
|
|
303
|
+
| `renderSlopeChart(el, parsed, colors, dark)` | Slope chart SVG |
|
|
304
|
+
| `renderArcDiagram(el, parsed, colors, dark)` | Arc diagram SVG |
|
|
305
|
+
| `renderTimeline(el, parsed, colors, dark)` | Timeline SVG |
|
|
306
|
+
| `renderWordCloud(el, parsed, colors, dark)` | Word cloud SVG |
|
|
307
|
+
| `renderVenn(el, parsed, colors, dark)` | Venn diagram SVG |
|
|
308
|
+
| `renderQuadrant(el, parsed, colors, dark)` | Quadrant chart SVG |
|
|
309
|
+
| `renderD3ForExport(content, theme)` | Any D3 chart as SVG string |
|
|
310
|
+
|
|
311
|
+
### Sequence renderer
|
|
312
|
+
|
|
313
|
+
| Export | Description |
|
|
314
|
+
|--------|-------------|
|
|
315
|
+
| `renderSequenceDiagram(el, parsed, colors, dark, onClick)` | Sequence diagram SVG |
|
|
316
|
+
| `buildRenderSequence(parsed)` | Ordered render steps |
|
|
317
|
+
| `computeActivations(steps, participants)` | Activation bar positions |
|
|
318
|
+
|
|
319
|
+
### Palette & color
|
|
320
|
+
|
|
321
|
+
| Export | Description |
|
|
322
|
+
|--------|-------------|
|
|
323
|
+
| `getPalette(id)` | Get palette by ID (falls back to Nord) |
|
|
324
|
+
| `getAvailablePalettes()` | List registered palettes |
|
|
325
|
+
| `registerPalette(config)` | Register a custom palette |
|
|
326
|
+
| `resolveColor(name, colors)` | Resolve color name or hex |
|
|
327
|
+
| `hexToHSL(hex)` / `hslToHex(h,s,l)` | Color conversion |
|
|
328
|
+
| `mute(hex)` / `tint(hex, amount)` / `shade(hex, base, amount)` | Color manipulation |
|
|
329
|
+
| `contrastText(bg, light, dark)` | WCAG contrast text picker |
|
|
330
|
+
| `buildMermaidThemeVars(colors)` | Mermaid CSS variables |
|
|
331
|
+
| `buildThemeCSS(colors)` | Mermaid theme CSS string |
|
|
332
|
+
|
|
333
|
+
## License
|
|
334
|
+
|
|
335
|
+
MIT
|