astro-dgmo 0.7.0 → 0.8.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 +44 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -104,6 +104,50 @@ A -> B
|
|
|
104
104
|
|
|
105
105
|
See the [`remark-dgmo` README](https://github.com/diagrammo/remark-dgmo) for the full option matrix.
|
|
106
106
|
|
|
107
|
+
## Cloud references (opt-in)
|
|
108
|
+
|
|
109
|
+
A fence can name a published [Diagrammo Cloud](https://diagrammo.app) diagram
|
|
110
|
+
instead of carrying its own source, so the page stops going stale the day it is
|
|
111
|
+
written:
|
|
112
|
+
|
|
113
|
+
````md
|
|
114
|
+
```dgmo
|
|
115
|
+
cloud dgm_01HQ3RSTUV
|
|
116
|
+
```
|
|
117
|
+
````
|
|
118
|
+
|
|
119
|
+
```js
|
|
120
|
+
// astro.config.mjs
|
|
121
|
+
integrations: [dgmo({ references: { enabled: true } })];
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
The build resolves it, renders it exactly like any other block, and writes what
|
|
125
|
+
it fetched to `.dgmo/references/<id>.json` — **commit that directory.** It is
|
|
126
|
+
what makes your build reproducible, offline-capable, and independent of our
|
|
127
|
+
uptime: if we are unreachable, the site builds from the committed copy and warns.
|
|
128
|
+
|
|
129
|
+
⚠️ **If your site sets a Content-Security-Policy it must allow
|
|
130
|
+
`connect-src https://api.diagrammo.app`.** Without it the diagram still renders
|
|
131
|
+
(it was baked at build time) but never refreshes, and nothing can report that —
|
|
132
|
+
the report would be blocked too.
|
|
133
|
+
|
|
134
|
+
### When a diagram changes after you build
|
|
135
|
+
|
|
136
|
+
By default the page **notices** — a small link to the live diagram — rather than
|
|
137
|
+
re-rendering it. Re-rendering means shipping the dgmo renderer in your bundle,
|
|
138
|
+
and on this repo's own fixture that is the difference between **1 chunk / 8.9 KB
|
|
139
|
+
gzipped and 88 chunks / 634 KB**. Lazy for your readers; not free for your
|
|
140
|
+
`dist/`.
|
|
141
|
+
|
|
142
|
+
Opt in if your diagrams change far more often than your site rebuilds:
|
|
143
|
+
|
|
144
|
+
```js
|
|
145
|
+
integrations: [dgmo({ references: { enabled: true, refresh: 'render' } })];
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
The full behaviour, including what each kind of failure does to your build, is in
|
|
149
|
+
the [`remark-dgmo` README](https://github.com/diagrammo/remark-dgmo#cloud-references-opt-in).
|
|
150
|
+
|
|
107
151
|
## Working reference site
|
|
108
152
|
|
|
109
153
|
[`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.
|
package/dist/index.js
CHANGED
|
@@ -25,6 +25,12 @@ function dgmoIntegration(options = {}) {
|
|
|
25
25
|
import.meta.resolve("remark-dgmo/client.js")
|
|
26
26
|
);
|
|
27
27
|
injectScript("page", readFileSync(clientJsPath, "utf8"));
|
|
28
|
+
if (options.references?.refresh === "render") {
|
|
29
|
+
const renderJsPath = fileURLToPath(
|
|
30
|
+
import.meta.resolve("remark-dgmo/client-render.js")
|
|
31
|
+
);
|
|
32
|
+
injectScript("page", readFileSync(renderJsPath, "utf8"));
|
|
33
|
+
}
|
|
28
34
|
}
|
|
29
35
|
}
|
|
30
36
|
};
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { readFileSync } from 'node:fs';\nimport { fileURLToPath } from 'node:url';\nimport type { AstroIntegration } from 'astro';\nimport remarkDgmo from 'remark-dgmo';\nimport type { DgmoIntegrationOptions } from './options.js';\n\nexport type { DgmoIntegrationOptions, Mode, Theme } from './options.js';\nexport { default as remarkDgmo } from 'remark-dgmo';\n\n/**\n * Astro integration that renders DGMO fenced code blocks at build time.\n *\n * @example\n * ```js\n * // astro.config.mjs\n * import dgmo from 'astro-dgmo';\n *\n * export default defineConfig({\n * integrations: [dgmo()],\n * });\n * ```\n *\n * v0.3.0 changes the rendered HTML class-name prefix from `astro-dgmo-*` to\n * `dgmo-*`. Both are emitted for one minor cycle via the shared `remark-dgmo`\n * `legacyClassNames` option, so existing user CSS keeps working until v0.4.\n *\n * v0.3.0 also defaults to `colorMode: 'auto'` (dual-render, light+dark SVGs)\n * to fix the silent dark/light-mismatch bug on Starlight and any toggle-\n * enabled Astro site. Users on single-mode sites can opt back to single-render\n * by setting `colorMode: 'light'` or `colorMode: 'dark'` in the integration\n * options.\n *\n * **CSS:** Astro 6's IntegrationHook has no programmatic stylesheet\n * injection — only `injectScript`. You must import the color-mode stylesheet\n * yourself in a global layout (e.g. `src/layouts/Base.astro`):\n *\n * import 'remark-dgmo/client.css';\n */\nexport default function dgmoIntegration(\n options: DgmoIntegrationOptions = {}\n): AstroIntegration {\n // Emit BOTH new (`dgmo-*`) and legacy (`astro-dgmo-*`) class names so user\n // CSS targeting the v0.2 classes keeps working. Removed in v0.4.\n const optionsWithLegacy: DgmoIntegrationOptions = {\n ...options,\n legacyClassNames: [\n ...(options.legacyClassNames ?? []),\n 'astro-dgmo',\n 'astro-dgmo-card',\n ],\n };\n\n return {\n name: 'astro-dgmo',\n hooks: {\n 'astro:config:setup'({ updateConfig, injectScript }) {\n updateConfig({\n markdown: {\n remarkPlugins: [[remarkDgmo, optionsWithLegacy]],\n },\n });\n // Inline the shared remark-dgmo client script so showcase-mode copy\n // buttons + viewBox tightening light up without users wiring scripts\n // manually. Read at config-setup time so the absolute path resolves\n // through node_modules.\n const clientJsPath = fileURLToPath(\n import.meta.resolve('remark-dgmo/client.js')\n );\n injectScript('page', readFileSync(clientJsPath, 'utf8'));\n },\n },\n };\n}\n"],"mappings":";AAAA,SAAS,oBAAoB;AAC7B,SAAS,qBAAqB;AAE9B,OAAO,gBAAgB;AAIvB,SAAoB,WAAXA,gBAA6B;AA+BvB,SAAR,gBACL,UAAkC,CAAC,GACjB;AAGlB,QAAM,oBAA4C;AAAA,IAChD,GAAG;AAAA,IACH,kBAAkB;AAAA,MAChB,GAAI,QAAQ,oBAAoB,CAAC;AAAA,MACjC;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AAAA,IACL,MAAM;AAAA,IACN,OAAO;AAAA,MACL,qBAAqB,EAAE,cAAc,aAAa,GAAG;AACnD,qBAAa;AAAA,UACX,UAAU;AAAA,YACR,eAAe,CAAC,CAAC,YAAY,iBAAiB,CAAC;AAAA,UACjD;AAAA,QACF,CAAC;AAKD,cAAM,eAAe;AAAA,UACnB,YAAY,QAAQ,uBAAuB;AAAA,QAC7C;AACA,qBAAa,QAAQ,aAAa,cAAc,MAAM,CAAC;AAAA,
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { readFileSync } from 'node:fs';\nimport { fileURLToPath } from 'node:url';\nimport type { AstroIntegration } from 'astro';\nimport remarkDgmo from 'remark-dgmo';\nimport type { DgmoIntegrationOptions } from './options.js';\n\nexport type { DgmoIntegrationOptions, Mode, Theme } from './options.js';\nexport { default as remarkDgmo } from 'remark-dgmo';\n\n/**\n * Astro integration that renders DGMO fenced code blocks at build time.\n *\n * @example\n * ```js\n * // astro.config.mjs\n * import dgmo from 'astro-dgmo';\n *\n * export default defineConfig({\n * integrations: [dgmo()],\n * });\n * ```\n *\n * v0.3.0 changes the rendered HTML class-name prefix from `astro-dgmo-*` to\n * `dgmo-*`. Both are emitted for one minor cycle via the shared `remark-dgmo`\n * `legacyClassNames` option, so existing user CSS keeps working until v0.4.\n *\n * v0.3.0 also defaults to `colorMode: 'auto'` (dual-render, light+dark SVGs)\n * to fix the silent dark/light-mismatch bug on Starlight and any toggle-\n * enabled Astro site. Users on single-mode sites can opt back to single-render\n * by setting `colorMode: 'light'` or `colorMode: 'dark'` in the integration\n * options.\n *\n * **CSS:** Astro 6's IntegrationHook has no programmatic stylesheet\n * injection — only `injectScript`. You must import the color-mode stylesheet\n * yourself in a global layout (e.g. `src/layouts/Base.astro`):\n *\n * import 'remark-dgmo/client.css';\n */\nexport default function dgmoIntegration(\n options: DgmoIntegrationOptions = {}\n): AstroIntegration {\n // Emit BOTH new (`dgmo-*`) and legacy (`astro-dgmo-*`) class names so user\n // CSS targeting the v0.2 classes keeps working. Removed in v0.4.\n const optionsWithLegacy: DgmoIntegrationOptions = {\n ...options,\n legacyClassNames: [\n ...(options.legacyClassNames ?? []),\n 'astro-dgmo',\n 'astro-dgmo-card',\n ],\n };\n\n return {\n name: 'astro-dgmo',\n hooks: {\n 'astro:config:setup'({ updateConfig, injectScript }) {\n updateConfig({\n markdown: {\n remarkPlugins: [[remarkDgmo, optionsWithLegacy]],\n },\n });\n // Inline the shared remark-dgmo client script so showcase-mode copy\n // buttons + viewBox tightening light up without users wiring scripts\n // manually. Read at config-setup time so the absolute path resolves\n // through node_modules.\n const clientJsPath = fileURLToPath(\n import.meta.resolve('remark-dgmo/client.js')\n );\n injectScript('page', readFileSync(clientJsPath, 'utf8'));\n\n // Cloud references, `refresh: 'render'` only (story 10.4). The base\n // client NOTICES that a referenced diagram moved; this second module is\n // what re-renders it, and it is separate because its dynamic import is\n // static-analyzable — injecting it unconditionally took this repo's own\n // fixture from 1 chunk / 7,990 gzipped bytes to 90 chunks / 634,199.\n // Lazy for the reader, not free for the site, so it is opt-in.\n if (options.references?.refresh === 'render') {\n const renderJsPath = fileURLToPath(\n import.meta.resolve('remark-dgmo/client-render.js')\n );\n injectScript('page', readFileSync(renderJsPath, 'utf8'));\n }\n },\n },\n };\n}\n"],"mappings":";AAAA,SAAS,oBAAoB;AAC7B,SAAS,qBAAqB;AAE9B,OAAO,gBAAgB;AAIvB,SAAoB,WAAXA,gBAA6B;AA+BvB,SAAR,gBACL,UAAkC,CAAC,GACjB;AAGlB,QAAM,oBAA4C;AAAA,IAChD,GAAG;AAAA,IACH,kBAAkB;AAAA,MAChB,GAAI,QAAQ,oBAAoB,CAAC;AAAA,MACjC;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AAAA,IACL,MAAM;AAAA,IACN,OAAO;AAAA,MACL,qBAAqB,EAAE,cAAc,aAAa,GAAG;AACnD,qBAAa;AAAA,UACX,UAAU;AAAA,YACR,eAAe,CAAC,CAAC,YAAY,iBAAiB,CAAC;AAAA,UACjD;AAAA,QACF,CAAC;AAKD,cAAM,eAAe;AAAA,UACnB,YAAY,QAAQ,uBAAuB;AAAA,QAC7C;AACA,qBAAa,QAAQ,aAAa,cAAc,MAAM,CAAC;AAQvD,YAAI,QAAQ,YAAY,YAAY,UAAU;AAC5C,gBAAM,eAAe;AAAA,YACnB,YAAY,QAAQ,8BAA8B;AAAA,UACpD;AACA,uBAAa,QAAQ,aAAa,cAAc,MAAM,CAAC;AAAA,QACzD;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;","names":["default"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "astro-dgmo",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
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": {
|
|
@@ -65,14 +65,14 @@
|
|
|
65
65
|
"prepublishOnly": "pnpm build && pnpm test"
|
|
66
66
|
},
|
|
67
67
|
"peerDependencies": {
|
|
68
|
-
"@diagrammo/dgmo": ">=0.
|
|
68
|
+
"@diagrammo/dgmo": ">=0.57.0 <1",
|
|
69
69
|
"astro": "^4.0.0 || ^5.0.0 || ^6.0.0"
|
|
70
70
|
},
|
|
71
71
|
"dependencies": {
|
|
72
|
-
"remark-dgmo": "^0.
|
|
72
|
+
"remark-dgmo": "^0.11.0"
|
|
73
73
|
},
|
|
74
74
|
"devDependencies": {
|
|
75
|
-
"@diagrammo/dgmo": "^0.
|
|
75
|
+
"@diagrammo/dgmo": "^0.57.0",
|
|
76
76
|
"@eslint/js": "^10.0.1",
|
|
77
77
|
"@types/node": "^22.10.0",
|
|
78
78
|
"astro": "^6.1.10",
|