astro-dgmo 0.3.1 → 0.3.3
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 +58 -122
- package/package.json +4 -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,65 +76,39 @@ A -> B
|
|
|
118
76
|
```
|
|
119
77
|
````
|
|
120
78
|
|
|
121
|
-
Recognized tokens:
|
|
122
|
-
|
|
123
79
|
| Token | Effect |
|
|
124
80
|
|---|---|
|
|
125
81
|
| `diagram` / `showcase` | Set `mode` for this block |
|
|
126
82
|
| `palette=<name>` | Override palette |
|
|
127
|
-
| `theme=light` / `theme=dark` / `theme=transparent` | Override theme |
|
|
83
|
+
| `theme=light` / `theme=dark` / `theme=transparent` | Override theme (single-render only) |
|
|
84
|
+
| `colorMode=auto` / `colorMode=light` / `colorMode=dark` | Override color-mode strategy |
|
|
128
85
|
| `title="…"` | Add a caption (`<figcaption>`) |
|
|
129
86
|
| `source` / `noSource` | Force source listing on/off |
|
|
130
87
|
| `copy` / `noCopy` | Force copy button on/off |
|
|
131
88
|
| `openInEditor` / `noOpenInEditor` | Force editor link on/off |
|
|
132
89
|
|
|
133
|
-
|
|
90
|
+
See the [`remark-dgmo` README](https://github.com/diagrammo/remark-dgmo) for the full option matrix.
|
|
134
91
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
```js
|
|
138
|
-
dgmo({ mode: 'showcase' });
|
|
139
|
-
```
|
|
92
|
+
## Working reference site
|
|
140
93
|
|
|
141
|
-
|
|
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.
|
|
142
95
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
Plan migration
|
|
149
|
-
[Doing](yellow)
|
|
150
|
-
Wire auth flow
|
|
151
|
-
[Done](green)
|
|
152
|
-
Hello world
|
|
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
|
|
153
101
|
```
|
|
154
|
-
````
|
|
155
102
|
|
|
156
|
-
|
|
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.
|
|
157
104
|
|
|
158
|
-
|
|
105
|
+
## How CSS is delivered
|
|
159
106
|
|
|
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
|
-
```
|
|
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.
|
|
178
108
|
|
|
179
|
-
|
|
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.
|
|
110
|
+
|
|
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
|
|
|
@@ -186,34 +118,38 @@ html.dark .dgmo-light { display: none; }
|
|
|
186
118
|
html.dark .dgmo-dark { display: block; }
|
|
187
119
|
```
|
|
188
120
|
|
|
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
|
-
```
|
|
121
|
+
For other selectors (`data-color-scheme="dark"`, `:root[data-mode="dark"]`, etc.), same three rules with the selector swapped.
|
|
206
122
|
|
|
207
123
|
## How it works
|
|
208
124
|
|
|
209
|
-
1. The Astro integration registers a remark plugin via `astro:config:setup`.
|
|
125
|
+
1. The Astro integration registers a remark plugin via `astro:config:setup` and inline-injects the `remark-dgmo` client script via `injectScript('page', …)`.
|
|
210
126
|
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.
|
|
127
|
+
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.
|
|
128
|
+
4. The original `code` node is replaced with an `html` node containing the rendered wrapper(s).
|
|
129
|
+
5. The injected client script tightens viewBoxes after layout and binds copy-button click handlers.
|
|
214
130
|
|
|
215
131
|
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
132
|
|
|
133
|
+
## Migration
|
|
134
|
+
|
|
135
|
+
### Upgrading from 0.2.x to 0.3.0
|
|
136
|
+
|
|
137
|
+
**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).
|
|
138
|
+
|
|
139
|
+
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>`.
|
|
140
|
+
|
|
141
|
+
**Three paths:**
|
|
142
|
+
|
|
143
|
+
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.
|
|
144
|
+
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.
|
|
145
|
+
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.
|
|
146
|
+
|
|
147
|
+
**You must add a CSS import** to a global layout — see Quick start.
|
|
148
|
+
|
|
149
|
+
**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.
|
|
150
|
+
|
|
151
|
+
No API changes. No breaking changes to fenced-block syntax or per-block options.
|
|
152
|
+
|
|
217
153
|
## License
|
|
218
154
|
|
|
219
155
|
MIT
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "astro-dgmo",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.3",
|
|
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": {
|
|
@@ -50,6 +50,7 @@
|
|
|
50
50
|
"typecheck": "tsc --noEmit",
|
|
51
51
|
"test": "vitest run",
|
|
52
52
|
"test:watch": "vitest",
|
|
53
|
+
"test:e2e": "pnpm build && cd tests/fixture && pnpm install --no-frozen-lockfile && pnpm exec astro build && node ../../scripts/assert-build-output.mjs",
|
|
53
54
|
"prepublishOnly": "pnpm build && pnpm test"
|
|
54
55
|
},
|
|
55
56
|
"peerDependencies": {
|
|
@@ -57,12 +58,12 @@
|
|
|
57
58
|
"astro": "^4.0.0 || ^5.0.0 || ^6.0.0"
|
|
58
59
|
},
|
|
59
60
|
"dependencies": {
|
|
60
|
-
"remark-dgmo": "^0.
|
|
61
|
+
"remark-dgmo": "^0.2.2"
|
|
61
62
|
},
|
|
62
63
|
"devDependencies": {
|
|
63
64
|
"@diagrammo/dgmo": "^0.15.0",
|
|
64
65
|
"@types/node": "^22.10.0",
|
|
65
|
-
"astro": "^6.1.
|
|
66
|
+
"astro": "^6.1.10",
|
|
66
67
|
"tsup": "^8.5.1",
|
|
67
68
|
"typescript": "^6.0.2",
|
|
68
69
|
"vitest": "^4.1.4"
|