astro-dgmo 0.3.2 → 0.3.4
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 +74 -132
- package/package.json +17 -3
package/README.md
CHANGED
|
@@ -2,33 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
Render [DGMO](https://diagrammo.app) diagrams from fenced code blocks in your Astro site at build time. Powered by [`@diagrammo/dgmo`](https://www.npmjs.com/package/@diagrammo/dgmo) and the framework-agnostic [`remark-dgmo`](https://www.npmjs.com/package/remark-dgmo) core. Zero client JavaScript by default.
|
|
4
4
|
|
|
5
|
-
## Upgrading from 0.2.x to 0.3.0
|
|
6
|
-
|
|
7
|
-
**Heads up: this release doubles your SVG bytes by default** to fix a silent rendering bug on dark/light-toggle sites (Starlight, custom-toggle Astro sites).
|
|
8
|
-
|
|
9
|
-
v0.2 baked one palette per diagram at build time. If your site supported a dark/light toggle, half your readers saw a mismatched diagram (light diagram on dark page, or vice versa). v0.3 fixes this by rendering each diagram twice (light + dark palettes) and using CSS to show the right one based on `[data-theme="dark"]` on `<html>`.
|
|
10
|
-
|
|
11
|
-
**Three migration paths:**
|
|
12
|
-
|
|
13
|
-
1. **Do nothing** — accept the ~2× SVG bytes per diagram in exchange for correct light/dark behavior. Recommended for Starlight and any site with a color-mode toggle.
|
|
14
|
-
2. **Opt out:** set `colorMode: 'light'` (or `'dark'`) in the integration options to keep the v0.2 single-render behavior. Recommended only if your site is single-mode.
|
|
15
|
-
3. **Use a different selector:** if your site signals dark mode via `.dark` class instead of `[data-theme="dark"]`, see "Custom color-mode selector" below.
|
|
16
|
-
|
|
17
|
-
**You must add a CSS import** to a global layout (Astro 6's IntegrationHook has no programmatic stylesheet injection):
|
|
18
|
-
|
|
19
|
-
```astro
|
|
20
|
-
---
|
|
21
|
-
// src/layouts/Base.astro
|
|
22
|
-
import 'remark-dgmo/client.css';
|
|
23
|
-
---
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
**Class names changed.** The rendered HTML class-name prefix changes from `astro-dgmo-*` to `dgmo-*` (e.g., `astro-dgmo-card` → `dgmo-card`). For one minor cycle (v0.3.x) we emit BOTH so existing CSS keeps working. v0.4 drops the legacy aliases. If you have CSS or DOM walkers targeting `astro-dgmo-*` classes, update them now to the `dgmo-*` equivalents.
|
|
27
|
-
|
|
28
|
-
No API changes. No breaking changes to fenced-block syntax or per-block options.
|
|
29
|
-
|
|
30
|
-
## Overview
|
|
31
|
-
|
|
32
5
|
```dgmo
|
|
33
6
|
sequence
|
|
34
7
|
Client -POST /login-> API
|
|
@@ -37,7 +10,7 @@ Auth -JWT-> API
|
|
|
37
10
|
API -200 OK-> Client
|
|
38
11
|
```
|
|
39
12
|
|
|
40
|
-
…in any `.md` or `.mdx` file becomes a beautifully rendered SVG, inlined into the page.
|
|
13
|
+
…in any `.md` or `.mdx` file becomes a beautifully rendered SVG, inlined into the page. Every diagram is rendered twice at build time (light + dark palettes) and follows the host's color-mode toggle via shipped CSS.
|
|
41
14
|
|
|
42
15
|
## Install
|
|
43
16
|
|
|
@@ -49,7 +22,7 @@ npm install astro-dgmo @diagrammo/dgmo
|
|
|
49
22
|
|
|
50
23
|
`@diagrammo/dgmo` is a peer dependency.
|
|
51
24
|
|
|
52
|
-
##
|
|
25
|
+
## Quick start
|
|
53
26
|
|
|
54
27
|
Add the integration to `astro.config.mjs`:
|
|
55
28
|
|
|
@@ -62,7 +35,16 @@ export default defineConfig({
|
|
|
62
35
|
});
|
|
63
36
|
```
|
|
64
37
|
|
|
65
|
-
|
|
38
|
+
Then import `remark-dgmo/client.css` in a global layout — Astro 6's IntegrationHook has no programmatic stylesheet injection, so this manual step is unavoidable:
|
|
39
|
+
|
|
40
|
+
```astro
|
|
41
|
+
---
|
|
42
|
+
// src/layouts/Base.astro
|
|
43
|
+
import 'remark-dgmo/client.css';
|
|
44
|
+
---
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
That's the whole integration. Anywhere in your Markdown or MDX content, write a fenced block with the language `dgmo`:
|
|
66
48
|
|
|
67
49
|
````markdown
|
|
68
50
|
```dgmo
|
|
@@ -73,40 +55,16 @@ Rust 25
|
|
|
73
55
|
```
|
|
74
56
|
````
|
|
75
57
|
|
|
76
|
-
At build time
|
|
58
|
+
At build time the block is replaced with an inline `<svg>` wrapped in a `<figure class="dgmo dgmo--diagram">`. No client JavaScript is shipped unless you opt into showcase mode.
|
|
77
59
|
|
|
78
|
-
|
|
60
|
+
Pass options to the integration to override defaults:
|
|
79
61
|
|
|
80
62
|
```js
|
|
81
|
-
dgmo({
|
|
82
|
-
// Output mode for `dgmo` blocks. 'diagram' (default) renders just the SVG.
|
|
83
|
-
// 'showcase' renders syntax-highlighted source + diagram + copy + open-in-editor.
|
|
84
|
-
mode: 'diagram',
|
|
85
|
-
|
|
86
|
-
// Color-mode strategy.
|
|
87
|
-
// 'auto' (default) — render twice (light + dark) and toggle via CSS.
|
|
88
|
-
// 'light' | 'dark' — single-render with the matching palette mode.
|
|
89
|
-
colorMode: 'auto',
|
|
90
|
-
|
|
91
|
-
// Defaults for the `render()` call from @diagrammo/dgmo. Under colorMode 'auto'
|
|
92
|
-
// (the default), `theme` is unreachable — both light and dark SVGs are emitted.
|
|
93
|
-
palette: 'nord', // any registered palette
|
|
94
|
-
theme: 'dark', // 'light' | 'dark' | 'transparent'
|
|
95
|
-
|
|
96
|
-
// Showcase chrome — enabled automatically in showcase mode.
|
|
97
|
-
showSource: undefined, // boolean; default = (mode === 'showcase')
|
|
98
|
-
showCopy: undefined, // boolean; default = (mode === 'showcase')
|
|
99
|
-
showOpenInEditor: undefined, // boolean; default = (mode === 'showcase')
|
|
100
|
-
|
|
101
|
-
// Where the "Open in editor" link points.
|
|
102
|
-
editorBaseUrl: 'https://online.diagrammo.app',
|
|
103
|
-
|
|
104
|
-
// Outer wrapper element + class hook.
|
|
105
|
-
wrapper: 'figure', // 'figure' | 'div'
|
|
106
|
-
className: 'astro-dgmo',
|
|
107
|
-
});
|
|
63
|
+
dgmo({ mode: 'showcase', palette: 'catppuccin', colorMode: 'auto' });
|
|
108
64
|
```
|
|
109
65
|
|
|
66
|
+
See [`remark-dgmo`](https://www.npmjs.com/package/remark-dgmo) for the full options matrix — `astro-dgmo` forwards everything through.
|
|
67
|
+
|
|
110
68
|
## Per-block overrides
|
|
111
69
|
|
|
112
70
|
Append options to the fence info string. Tokens are space-separated; values may be quoted.
|
|
@@ -118,102 +76,86 @@ A -> B
|
|
|
118
76
|
```
|
|
119
77
|
````
|
|
120
78
|
|
|
121
|
-
|
|
79
|
+
| Token | Effect |
|
|
80
|
+
| ------------------------------------------------------- | ----------------------------------- |
|
|
81
|
+
| `diagram` / `showcase` | Set `mode` for this block |
|
|
82
|
+
| `palette=<name>` | Override palette |
|
|
83
|
+
| `theme=light` / `theme=dark` / `theme=transparent` | Override theme (single-render only) |
|
|
84
|
+
| `colorMode=auto` / `colorMode=light` / `colorMode=dark` | Override color-mode strategy |
|
|
85
|
+
| `title="…"` | Add a caption (`<figcaption>`) |
|
|
86
|
+
| `source` / `noSource` | Force source listing on/off |
|
|
87
|
+
| `copy` / `noCopy` | Force copy button on/off |
|
|
88
|
+
| `openInEditor` / `noOpenInEditor` | Force editor link on/off |
|
|
122
89
|
|
|
123
|
-
|
|
124
|
-
|---|---|
|
|
125
|
-
| `diagram` / `showcase` | Set `mode` for this block |
|
|
126
|
-
| `palette=<name>` | Override palette |
|
|
127
|
-
| `theme=light` / `theme=dark` / `theme=transparent` | Override theme |
|
|
128
|
-
| `title="…"` | Add a caption (`<figcaption>`) |
|
|
129
|
-
| `source` / `noSource` | Force source listing on/off |
|
|
130
|
-
| `copy` / `noCopy` | Force copy button on/off |
|
|
131
|
-
| `openInEditor` / `noOpenInEditor` | Force editor link on/off |
|
|
90
|
+
See the [`remark-dgmo` README](https://github.com/diagrammo/remark-dgmo) for the full option matrix.
|
|
132
91
|
|
|
133
|
-
##
|
|
92
|
+
## Working reference site
|
|
134
93
|
|
|
135
|
-
|
|
94
|
+
[`tests/fixture/`](./tests/fixture/) is a complete minimal Astro 6 site running this integration. Copy [`tests/fixture/astro.config.mjs`](./tests/fixture/astro.config.mjs) + [`tests/fixture/src/layouts/Base.astro`](./tests/fixture/src/layouts/Base.astro) as a starting template.
|
|
136
95
|
|
|
137
|
-
```
|
|
138
|
-
|
|
96
|
+
```bash
|
|
97
|
+
git clone https://github.com/diagrammo/astro-dgmo
|
|
98
|
+
cd astro-dgmo
|
|
99
|
+
pnpm install && pnpm build
|
|
100
|
+
cd tests/fixture && pnpm install --no-frozen-lockfile && pnpm exec astro dev
|
|
139
101
|
```
|
|
140
102
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
````markdown
|
|
144
|
-
```dgmo showcase
|
|
145
|
-
kanban
|
|
146
|
-
[Backlog](blue)
|
|
147
|
-
Draft RFC
|
|
148
|
-
Plan migration
|
|
149
|
-
[Doing](yellow)
|
|
150
|
-
Wire auth flow
|
|
151
|
-
[Done](green)
|
|
152
|
-
Hello world
|
|
153
|
-
```
|
|
154
|
-
````
|
|
103
|
+
Opens at http://localhost:4321 with four example diagrams (plain auto, colored tag sequence, showcase mode, per-block override) and a `data-theme` toggle for verifying the dark/light swap. See [`tests/fixture/README.md`](./tests/fixture/README.md) for details.
|
|
155
104
|
|
|
156
|
-
##
|
|
105
|
+
## How CSS is delivered
|
|
157
106
|
|
|
158
|
-
The
|
|
107
|
+
The shipped `remark-dgmo/client.css` contains three rules that hide the wrong-mode SVG based on `[data-theme="dark"]` on `<html>`. Astro's Vite pipeline inlines the import — a `<style>` block ends up in `<head>`, no separate stylesheet file is emitted. The required `import 'remark-dgmo/client.css'` in a global layout is what triggers that inlining; without it, both light and dark wrappers render at the same time.
|
|
159
108
|
|
|
160
|
-
|
|
161
|
-
.dgmo { /* outer wrapper */ }
|
|
162
|
-
.dgmo--diagram { /* simple mode */ }
|
|
163
|
-
.dgmo--showcase { /* showcase mode */ }
|
|
164
|
-
.dgmo-light, .dgmo-dark { /* dual-render wrappers (colorMode auto) */ }
|
|
165
|
-
.dgmo-caption { /* title/caption */ }
|
|
166
|
-
.dgmo-svg { /* svg container (single-render only) */ }
|
|
167
|
-
.dgmo-card { /* showcase card */ }
|
|
168
|
-
.dgmo-source-wrap, .dgmo-source-inner { /* source block */ }
|
|
169
|
-
.dgmo-toolbar { /* "dgmo" label + action icons (single row) */ }
|
|
170
|
-
.dgmo-toolbar-label { /* "dgmo" tag */ }
|
|
171
|
-
.dgmo-toolbar-actions { /* container for the icon buttons */ }
|
|
172
|
-
.dgmo-toolbar-btn { /* shared style for both icon buttons */ }
|
|
173
|
-
.dgmo-open { /* "Open in online editor" external-link icon */ }
|
|
174
|
-
.dgmo-copy { /* copy-to-clipboard icon */ }
|
|
175
|
-
.dgmo-copy--success { /* copy button after a successful copy */ }
|
|
176
|
-
.dgmo-pre, .dgmo-code { /* highlighted source */ }
|
|
177
|
-
```
|
|
109
|
+
A small client script (~600 bytes) is injected via `injectScript('page', …)`. It tightens each diagram's `viewBox` to its content bounds and binds showcase-mode copy buttons. If your site forbids inline scripts via CSP, ignore this script — diagrams still render, but layout may have extra whitespace and copy buttons won't function.
|
|
178
110
|
|
|
179
|
-
|
|
111
|
+
## Custom color-mode selector
|
|
180
112
|
|
|
181
113
|
The shipped `remark-dgmo/client.css` keys on `[data-theme="dark"]`. For Tailwind-style sites that use a `.dark` class on `<html>`, don't import that stylesheet — inline these three rules in your own CSS instead:
|
|
182
114
|
|
|
183
115
|
```css
|
|
184
|
-
.dgmo-dark {
|
|
185
|
-
|
|
186
|
-
|
|
116
|
+
.dgmo-dark {
|
|
117
|
+
display: none;
|
|
118
|
+
}
|
|
119
|
+
html.dark .dgmo-light {
|
|
120
|
+
display: none;
|
|
121
|
+
}
|
|
122
|
+
html.dark .dgmo-dark {
|
|
123
|
+
display: block;
|
|
124
|
+
}
|
|
187
125
|
```
|
|
188
126
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
## Direct remark plugin
|
|
192
|
-
|
|
193
|
-
For fine-grained control (or to use outside Astro), import the remark plugin directly:
|
|
194
|
-
|
|
195
|
-
```js
|
|
196
|
-
import remarkDgmo from 'astro-dgmo/remark';
|
|
197
|
-
|
|
198
|
-
// e.g. in any remark/rehype pipeline:
|
|
199
|
-
unified()
|
|
200
|
-
.use(remarkParse)
|
|
201
|
-
.use(remarkDgmo, { mode: 'showcase', palette: 'dracula' })
|
|
202
|
-
.use(remarkRehype)
|
|
203
|
-
.use(rehypeStringify)
|
|
204
|
-
.process(source);
|
|
205
|
-
```
|
|
127
|
+
For other selectors (`data-color-scheme="dark"`, `:root[data-mode="dark"]`, etc.), same three rules with the selector swapped.
|
|
206
128
|
|
|
207
129
|
## How it works
|
|
208
130
|
|
|
209
|
-
1. The Astro integration registers a remark plugin via `astro:config:setup`.
|
|
131
|
+
1. The Astro integration registers a remark plugin via `astro:config:setup` and inline-injects the `remark-dgmo` client script via `injectScript('page', …)`.
|
|
210
132
|
2. The remark plugin walks `.md`/`.mdx` ASTs after parse, finding `code` nodes whose `lang === 'dgmo'`.
|
|
211
|
-
3. Each block is rendered to an SVG string by calling `render()` from `@diagrammo/dgmo
|
|
212
|
-
4. The original `code` node is replaced with an `html` node containing the rendered
|
|
213
|
-
5.
|
|
133
|
+
3. Each block is rendered to an SVG string by calling `render()` from `@diagrammo/dgmo` — once per theme under default `colorMode: 'auto'`, or once total under `'light'` / `'dark'`. Width/height are stripped and a `viewBox` is added so the diagram scales responsively.
|
|
134
|
+
4. The original `code` node is replaced with an `html` node containing the rendered wrapper(s).
|
|
135
|
+
5. The injected client script tightens viewBoxes after layout and binds copy-button click handlers.
|
|
214
136
|
|
|
215
137
|
All rendering happens at build time. No diagram source is shipped to the browser unless you enable showcase mode (which inlines a syntax-highlighted copy of the source for display).
|
|
216
138
|
|
|
139
|
+
## Migration
|
|
140
|
+
|
|
141
|
+
### Upgrading from 0.2.x to 0.3.0
|
|
142
|
+
|
|
143
|
+
**Heads up: this release doubles your SVG bytes by default** to fix a silent rendering bug on dark/light-toggle sites (Starlight, custom-toggle Astro sites).
|
|
144
|
+
|
|
145
|
+
v0.2 baked one palette per diagram at build time. If your site supported a dark/light toggle, half your readers saw a mismatched diagram. v0.3 fixes this by rendering each diagram twice (light + dark palettes) and using CSS to show the right one based on `[data-theme="dark"]` on `<html>`.
|
|
146
|
+
|
|
147
|
+
**Three paths:**
|
|
148
|
+
|
|
149
|
+
1. **Do nothing** — accept the ~2× SVG bytes per diagram in exchange for correct light/dark behavior. Recommended for Starlight and any site with a color-mode toggle.
|
|
150
|
+
2. **Opt out:** set `colorMode: 'light'` (or `'dark'`) in the integration options to keep the v0.2 single-render behavior. Recommended only if your site is single-mode.
|
|
151
|
+
3. **Use a different selector:** if your site signals dark mode via `.dark` class instead of `[data-theme="dark"]`, see "Custom color-mode selector" above.
|
|
152
|
+
|
|
153
|
+
**You must add a CSS import** to a global layout — see Quick start.
|
|
154
|
+
|
|
155
|
+
**Class names changed.** The rendered HTML class-name prefix changed from `astro-dgmo-*` to `dgmo-*` (e.g., `astro-dgmo-card` → `dgmo-card`). For one minor cycle (v0.3.x) we emit BOTH so existing CSS keeps working. v0.4 drops the legacy aliases. If you have CSS or DOM walkers targeting `astro-dgmo-*` classes, update them now to the `dgmo-*` equivalents.
|
|
156
|
+
|
|
157
|
+
No API changes. No breaking changes to fenced-block syntax or per-block options.
|
|
158
|
+
|
|
217
159
|
## License
|
|
218
160
|
|
|
219
161
|
MIT
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "astro-dgmo",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.4",
|
|
4
4
|
"description": "Astro integration to render DGMO diagrams from fenced code blocks at build time. Powered by @diagrammo/dgmo.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -25,6 +25,9 @@
|
|
|
25
25
|
"remark"
|
|
26
26
|
],
|
|
27
27
|
"type": "module",
|
|
28
|
+
"engines": {
|
|
29
|
+
"node": ">=20.6"
|
|
30
|
+
},
|
|
28
31
|
"main": "./dist/index.js",
|
|
29
32
|
"module": "./dist/index.js",
|
|
30
33
|
"types": "./dist/index.d.ts",
|
|
@@ -50,6 +53,12 @@
|
|
|
50
53
|
"typecheck": "tsc --noEmit",
|
|
51
54
|
"test": "vitest run",
|
|
52
55
|
"test:watch": "vitest",
|
|
56
|
+
"test:e2e": "pnpm build && cd tests/fixture && pnpm install --no-frozen-lockfile && pnpm exec astro build && node ../../scripts/assert-build-output.mjs",
|
|
57
|
+
"lint": "eslint .",
|
|
58
|
+
"lint:fix": "eslint . --fix",
|
|
59
|
+
"format": "prettier --write .",
|
|
60
|
+
"format:check": "prettier --check .",
|
|
61
|
+
"check:deadcode": "knip",
|
|
53
62
|
"prepublishOnly": "pnpm build && pnpm test"
|
|
54
63
|
},
|
|
55
64
|
"peerDependencies": {
|
|
@@ -57,14 +66,19 @@
|
|
|
57
66
|
"astro": "^4.0.0 || ^5.0.0 || ^6.0.0"
|
|
58
67
|
},
|
|
59
68
|
"dependencies": {
|
|
60
|
-
"remark-dgmo": "^0.
|
|
69
|
+
"remark-dgmo": "^0.2.2"
|
|
61
70
|
},
|
|
62
71
|
"devDependencies": {
|
|
63
72
|
"@diagrammo/dgmo": "^0.15.0",
|
|
73
|
+
"@eslint/js": "^10.0.1",
|
|
64
74
|
"@types/node": "^22.10.0",
|
|
65
|
-
"astro": "^6.1.
|
|
75
|
+
"astro": "^6.1.10",
|
|
76
|
+
"eslint": "^10.4.0",
|
|
77
|
+
"knip": "^6.14.1",
|
|
78
|
+
"prettier": "^3.8.3",
|
|
66
79
|
"tsup": "^8.5.1",
|
|
67
80
|
"typescript": "^6.0.2",
|
|
81
|
+
"typescript-eslint": "^8.59.3",
|
|
68
82
|
"vitest": "^4.1.4"
|
|
69
83
|
}
|
|
70
84
|
}
|