nextra-dgmo 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 +190 -0
- package/dist/chunk-4W254UGY.js +39 -0
- package/dist/chunk-4W254UGY.js.map +1 -0
- package/dist/client.css +121 -0
- package/dist/config.d.ts +53 -0
- package/dist/config.js +7 -0
- package/dist/config.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/nextra-client.js +117 -0
- package/dist/nextra-client.js.map +1 -0
- package/dist/remark.d.ts +2 -0
- package/dist/remark.js +7 -0
- package/dist/remark.js.map +1 -0
- package/package.json +119 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Demian Neidetcher
|
|
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,190 @@
|
|
|
1
|
+
# nextra-dgmo
|
|
2
|
+
|
|
3
|
+
Render [DGMO](https://diagrammo.app) diagrams from ` ```dgmo ` fenced code blocks in your [Nextra](https://nextra.site) 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 (one tiny re-binder fires on route change).
|
|
4
|
+
|
|
5
|
+
📖 **Setup guide:** [diagrammo.app/embed#nextra](https://diagrammo.app/embed#nextra)
|
|
6
|
+
|
|
7
|
+
Every diagram is rendered twice at build time (light + dark palettes) and follows Nextra's color-mode toggle through a shipped, `.dark`-rewritten stylesheet.
|
|
8
|
+
|
|
9
|
+
<p align="center">
|
|
10
|
+
<a href="https://diagrammo.app"><img src="https://diagrammo.app/readme/sequence.gif" alt="A DGMO diagram authored as plain text" width="100%"></a>
|
|
11
|
+
<br>
|
|
12
|
+
<em>Write a fenced <code>dgmo</code> block — it renders to SVG at build time.</em>
|
|
13
|
+
</p>
|
|
14
|
+
|
|
15
|
+
## Chart types & visual authoring
|
|
16
|
+
|
|
17
|
+
One small plain-text language, **45 chart types** — flowcharts, sequence, state, class, ER, C4, org charts, gantt, maps, mind maps, and the full bar/line/pie/area/sankey family. Browse every type with live examples in the **[language reference](https://diagrammo.app/reference)**.
|
|
18
|
+
|
|
19
|
+
Prefer to author visually? Draft diagrams in the **[Diagrammo desktop app](https://diagrammo.app/app)** or the **[online editor](https://online.diagrammo.app)** — live preview, autocomplete, optional vim keybindings, 7 themeable palettes, and one-click PNG/SVG export — then paste the `dgmo` block into your docs. More at **[diagrammo.app](https://diagrammo.app)**.
|
|
20
|
+
|
|
21
|
+
## Install
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
pnpm add nextra-dgmo @diagrammo/dgmo
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
`@diagrammo/dgmo`, `nextra`, `next`, and `react` are peer dependencies. Node 20.6+.
|
|
28
|
+
|
|
29
|
+
## ⚠️ Turbopack caveat (read first)
|
|
30
|
+
|
|
31
|
+
Nextra wires DGMO in through `next.config.mjs`, and `withDgmo` injects the `remark-dgmo` plugin as a **function-valued** MDX option. Turbopack cannot serialize function-valued remark plugins, so:
|
|
32
|
+
|
|
33
|
+
- **Production builds:** use Webpack — `next build` (Nextra 4's default). Do **not** pass `--turbopack` to `next build`.
|
|
34
|
+
- **Dev:** run `next dev` **without** `--turbopack`.
|
|
35
|
+
|
|
36
|
+
The build/SSG path that actually emits the inline SVG is unaffected — this is purely about how the plugin is passed to the compiler, and Webpack handles it fine. If your `package.json` scripts were scaffolded with `--turbopack`, drop that flag.
|
|
37
|
+
|
|
38
|
+
## Quick start
|
|
39
|
+
|
|
40
|
+
Two small edits to your Nextra site.
|
|
41
|
+
|
|
42
|
+
### 1. `next.config.mjs` — wire the remark plugin
|
|
43
|
+
|
|
44
|
+
```js
|
|
45
|
+
import nextra from 'nextra';
|
|
46
|
+
import { withDgmo } from 'nextra-dgmo/config';
|
|
47
|
+
|
|
48
|
+
const withNextra = nextra(
|
|
49
|
+
withDgmo(
|
|
50
|
+
{/* your existing nextra options, if any */},
|
|
51
|
+
{ dgmo: { palette: 'slate' } }
|
|
52
|
+
)
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
export default withNextra({/* your next config */});
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
`withDgmo()` augments your Nextra config's `mdxOptions.remarkPlugins` with `remark-dgmo` and defaults `mdx: true` on it so blocks render as MDX-safe `mdxJsxFlowElement` nodes. Idempotent. Unlike Fumadocs, Nextra nests the remark pipeline under `mdxOptions`, so `withDgmo` injects one level deeper — you don't have to know that; just pass your Nextra options object through it. If you already have your own remark plugins:
|
|
59
|
+
|
|
60
|
+
```js
|
|
61
|
+
const withNextra = nextra(
|
|
62
|
+
withDgmo({ mdxOptions: { remarkPlugins: [myOtherPlugin] } })
|
|
63
|
+
);
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
`remark-dgmo` is prepended so it runs before any downstream remark plugin.
|
|
67
|
+
|
|
68
|
+
### 2. `app/layout.tsx` — mount the client component
|
|
69
|
+
|
|
70
|
+
```tsx
|
|
71
|
+
import './global.css';
|
|
72
|
+
import { DgmoClient } from 'nextra-dgmo/client';
|
|
73
|
+
import type { ReactNode } from 'react';
|
|
74
|
+
|
|
75
|
+
export default function RootLayout({ children }: { children: ReactNode }) {
|
|
76
|
+
return (
|
|
77
|
+
<html lang="en" suppressHydrationWarning>
|
|
78
|
+
<body>
|
|
79
|
+
{children}
|
|
80
|
+
<DgmoClient />
|
|
81
|
+
</body>
|
|
82
|
+
</html>
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
`<DgmoClient />` is a no-render Client Component that does two things:
|
|
88
|
+
|
|
89
|
+
1. Runs `bindDgmo()` on initial mount and on every soft route change — Next's app router doesn't refire `DOMContentLoaded` semantics on client-side navigation, so without this you'd lose viewBox tightening and showcase-mode copy buttons after the first SPA transition.
|
|
90
|
+
2. Side-effect-imports the shipped `nextra-dgmo/client.css` so Next's CSS pipeline picks it up automatically. The stylesheet is generated from `remark-dgmo/client.css` at build time with `[data-theme="dark"]` rewritten to `html.dark` — the attribute Nextra's `next-themes` default uses. No manual `@import` required.
|
|
91
|
+
|
|
92
|
+
That's the whole integration.
|
|
93
|
+
|
|
94
|
+
### Passing remark-dgmo options
|
|
95
|
+
|
|
96
|
+
```js
|
|
97
|
+
const withNextra = nextra(
|
|
98
|
+
withDgmo({}, { dgmo: { palette: 'catppuccin', colorMode: 'auto' } })
|
|
99
|
+
);
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
The second argument forwards anything in `remark-dgmo`'s option surface (palette, theme, colorMode, mode, className, etc.).
|
|
103
|
+
|
|
104
|
+
## Options
|
|
105
|
+
|
|
106
|
+
The second argument to `withDgmo` is `{ dgmo: DgmoOptions }`. Common keys:
|
|
107
|
+
|
|
108
|
+
| Option | Type | Default | Effect |
|
|
109
|
+
| ----------- | ------------------------------- | -------- | ----------------------------------------------------------------------------- |
|
|
110
|
+
| `palette` | palette name | `slate` | Which of the 7 built-in palettes to render with. |
|
|
111
|
+
| `theme` | theme name | — | Named theme preset (overrides individual palette/colorMode where it applies). |
|
|
112
|
+
| `colorMode` | `'auto' \| 'light' \| 'dark'` | `'auto'` | `auto` dual-renders light + dark and toggles via the host's `.dark` class. |
|
|
113
|
+
| `mode` | render mode | — | Passthrough to `@diagrammo/dgmo`'s render mode. |
|
|
114
|
+
| `showcase` | boolean (per-block info string) | `false` | Renders the source alongside the diagram with a copy-to-clipboard button. |
|
|
115
|
+
|
|
116
|
+
Per-block overrides live on the fence info string (see below); the `withDgmo` `dgmo` option sets the site-wide defaults.
|
|
117
|
+
|
|
118
|
+
## Configure (manual)
|
|
119
|
+
|
|
120
|
+
If `withDgmo` doesn't fit (dynamic remark plugin loading, you need to inspect the wiring), do it by hand — remember Nextra's remark slot lives under `mdxOptions`:
|
|
121
|
+
|
|
122
|
+
```js
|
|
123
|
+
import nextra from 'nextra';
|
|
124
|
+
import remarkDgmo from 'nextra-dgmo/remark';
|
|
125
|
+
|
|
126
|
+
const withNextra = nextra({
|
|
127
|
+
mdxOptions: {
|
|
128
|
+
remarkPlugins: [[remarkDgmo, { mdx: true }]],
|
|
129
|
+
},
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
export default withNextra({});
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
The `mdx: true` option is required — Nextra always routes content through `@mdx-js/mdx`, which rejects the raw `html` mdast nodes `remark-dgmo` emits by default.
|
|
136
|
+
|
|
137
|
+
## Use
|
|
138
|
+
|
|
139
|
+
Drop a fenced block with the language `dgmo` into any `.md`/`.mdx` file in your Nextra content tree.
|
|
140
|
+
|
|
141
|
+
````markdown
|
|
142
|
+
```dgmo
|
|
143
|
+
sequence
|
|
144
|
+
Client -POST /login-> API
|
|
145
|
+
API -validate-> Auth
|
|
146
|
+
Auth -JWT-> API
|
|
147
|
+
API -200 OK-> Client
|
|
148
|
+
```
|
|
149
|
+
````
|
|
150
|
+
|
|
151
|
+
## Per-block overrides
|
|
152
|
+
|
|
153
|
+
Append options to the fence info string. Tokens are space-separated; values may be quoted.
|
|
154
|
+
|
|
155
|
+
````markdown
|
|
156
|
+
```dgmo showcase title="Login flow" palette=catppuccin colorMode=light
|
|
157
|
+
sequence
|
|
158
|
+
A -> B
|
|
159
|
+
```
|
|
160
|
+
````
|
|
161
|
+
|
|
162
|
+
See the [`remark-dgmo` README](https://github.com/diagrammo/remark-dgmo) for the full option matrix.
|
|
163
|
+
|
|
164
|
+
## How CSS is delivered
|
|
165
|
+
|
|
166
|
+
`nextra-dgmo/client.css` is the shipped stylesheet. It's the same three visibility rules + sizing + showcase chrome as upstream `remark-dgmo/client.css`, but the dark-mode selector is rewritten from `[data-theme="dark"]` to `html.dark` — the attribute Nextra's `next-themes` integration uses by default.
|
|
167
|
+
|
|
168
|
+
It's auto-imported by `<DgmoClient />` via a side-effect `import 'nextra-dgmo/client.css'`. Next's CSS pipeline picks the import up from the Client Component module and extracts it into the page bundle. If you prefer to manage the import yourself, drop in the manual config path above and `@import 'nextra-dgmo/client.css'` from your `app/global.css` instead.
|
|
169
|
+
|
|
170
|
+
## Custom color-mode selector
|
|
171
|
+
|
|
172
|
+
If you've configured `next-themes` with a non-default attribute (e.g. `attribute="data-theme"`), the shipped CSS won't match. Two options:
|
|
173
|
+
|
|
174
|
+
1. Switch back to the default (Nextra's preset expects `html.dark`).
|
|
175
|
+
2. Skip `<DgmoClient />`'s auto-import and instead `@import 'remark-dgmo/client.css'` directly in `app/global.css` (keys on `[data-theme="dark"]`), then override your theme's dark-mode rules to match.
|
|
176
|
+
|
|
177
|
+
See the "Custom color-mode selector" section in the [`remark-dgmo` README](https://github.com/diagrammo/remark-dgmo) for the underlying selectors.
|
|
178
|
+
|
|
179
|
+
## How it works
|
|
180
|
+
|
|
181
|
+
1. `withDgmo` prepends `remark-dgmo` (with `mdx: true`) to your Nextra config's `mdxOptions.remarkPlugins`. Nextra's MDX build pipeline runs the plugin during compilation.
|
|
182
|
+
2. For each fenced `dgmo` block, `remark-dgmo` calls `render()` from `@diagrammo/dgmo` once per theme (under default `colorMode: 'auto'`) and replaces the block with an `mdxJsxFlowElement` carrying the rendered SVG wrappers via `dangerouslySetInnerHTML`.
|
|
183
|
+
3. The shipped CSS, side-effect-imported by `<DgmoClient />`, gates the wrappers' visibility on `html.dark`. Toggling Nextra's theme switcher flips the class, which flips visibility.
|
|
184
|
+
4. The `<DgmoClient />` Client Component subscribes to `usePathname()` and re-runs `bindDgmo()` on every soft navigation. The function tightens each diagram's `viewBox` to content bounds and wires showcase-mode copy buttons.
|
|
185
|
+
|
|
186
|
+
All rendering happens at build time. The browser ships only inline SVG + the small CSS rules + a ~1.5 KB `bindDgmo` payload. This wrapper reuses the `remark-dgmo` core shared with the Astro, Docusaurus, and Fumadocs integrations.
|
|
187
|
+
|
|
188
|
+
## License
|
|
189
|
+
|
|
190
|
+
MIT
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// src/config.ts
|
|
2
|
+
import remarkDgmo from "remark-dgmo";
|
|
3
|
+
function withDgmo(nextraConfig = {}, options = {}) {
|
|
4
|
+
const dgmoOptions = { mdx: true, ...options.dgmo };
|
|
5
|
+
const remarkInstance = [remarkDgmo, dgmoOptions];
|
|
6
|
+
const mdxOptions = nextraConfig["mdxOptions"] ?? {};
|
|
7
|
+
const existing = mdxOptions["remarkPlugins"];
|
|
8
|
+
if (Array.isArray(existing) && existing.some(isDgmoEntry)) {
|
|
9
|
+
return nextraConfig;
|
|
10
|
+
}
|
|
11
|
+
let remarkPlugins;
|
|
12
|
+
if (typeof existing === "function") {
|
|
13
|
+
const userFn = existing;
|
|
14
|
+
remarkPlugins = (defaults) => {
|
|
15
|
+
const next = userFn(defaults);
|
|
16
|
+
const arr = Array.isArray(next) ? [...next] : [];
|
|
17
|
+
if (!arr.some(isDgmoEntry)) arr.unshift(remarkInstance);
|
|
18
|
+
return arr;
|
|
19
|
+
};
|
|
20
|
+
} else {
|
|
21
|
+
const arr = Array.isArray(existing) ? [...existing] : [];
|
|
22
|
+
arr.unshift(remarkInstance);
|
|
23
|
+
remarkPlugins = arr;
|
|
24
|
+
}
|
|
25
|
+
return {
|
|
26
|
+
...nextraConfig,
|
|
27
|
+
mdxOptions: { ...mdxOptions, remarkPlugins }
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function isDgmoEntry(entry) {
|
|
31
|
+
if (entry === remarkDgmo) return true;
|
|
32
|
+
if (Array.isArray(entry) && entry[0] === remarkDgmo) return true;
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export {
|
|
37
|
+
withDgmo
|
|
38
|
+
};
|
|
39
|
+
//# sourceMappingURL=chunk-4W254UGY.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/config.ts"],"sourcesContent":["import remarkDgmo from 'remark-dgmo';\nimport type { DgmoOptions } from 'remark-dgmo';\n\n/**\n * Shape of the `remarkPlugins` slot inside a Nextra config's `mdxOptions`.\n * We only need that one slot — everything else on the config is forwarded\n * untouched — so we type it loosely instead of importing Nextra's internal\n * types (which churn between minor versions).\n *\n * `remarkPlugins` accepts the same shapes Nextra accepts: either a plain\n * array, or a function that receives the framework's defaults and returns\n * the array to use. We preserve whichever form the user passed.\n */\nexport type RemarkPlugin = unknown;\nexport type RemarkPluginsArray = RemarkPlugin[];\nexport type RemarkPluginsFn = (\n defaults: RemarkPluginsArray\n) => RemarkPluginsArray;\nexport type RemarkPluginsField = RemarkPluginsArray | RemarkPluginsFn;\n\n// Loosely-typed mirror of Nextra's config object. We accept and return\n// `any` for the field shape so this composes cleanly with\n// `nextra(withDgmo(...))` — Nextra's own types are invariant in surprising\n// ways across minors. We type-check just enough to preserve compile-time\n// safety on `mdxOptions.remarkPlugins`, the only field we touch.\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type NextraConfig = Record<string, any>;\n\nexport interface WithDgmoOptions {\n /** Options forwarded to `remark-dgmo` (palette, theme, colorMode, etc.). */\n dgmo?: DgmoOptions;\n}\n\n/**\n * Augment a Nextra config object so the `remark-dgmo` plugin runs as part\n * of the MDX pipeline. Unlike Fumadocs — which exposes `remarkPlugins` at\n * the top level of its `mdxOptions` object — Nextra nests the remark\n * pipeline one level deeper, under `nextraConfig.mdxOptions.remarkPlugins`.\n * Designed to compose with Nextra's own `nextra()` factory:\n *\n * ```js\n * // next.config.mjs\n * import nextra from 'nextra'\n * import { withDgmo } from 'nextra-dgmo/config'\n *\n * const withNextra = nextra(\n * withDgmo({ /* nextra options *\\/ }, { dgmo: { palette: 'slate' } })\n * )\n *\n * export default withNextra({ /* next config *\\/ })\n * ```\n *\n * Idempotent — running it on an already-wired config returns the same\n * config without double-injecting. The remark plugin is prepended to the\n * plugin list so it sees fenced `dgmo` blocks before any downstream remark\n * plugin (notably Nextra's own MDX file resolver) gets a chance to\n * transform them.\n *\n * If `mdxOptions.remarkPlugins` is the function form Nextra supports\n * (`(defaults) => [...]`), the returned config keeps the function form and\n * prepends `remarkDgmo` to the function's eventual output.\n */\nexport function withDgmo(\n nextraConfig: NextraConfig = {},\n options: WithDgmoOptions = {}\n): NextraConfig {\n // Nextra always routes content through @mdx-js/mdx, which rejects raw\n // `html` mdast nodes with `Cannot handle unknown node \"raw\"`. Default\n // remark-dgmo's `mdx` flag to `true` so blocks emit an\n // mdxJsxFlowElement (`<div dangerouslySetInnerHTML={…}/>`) that MDX\n // accepts. The user can still override via `options.dgmo.mdx = false`.\n const dgmoOptions: DgmoOptions = { mdx: true, ...options.dgmo };\n const remarkInstance: RemarkPlugin = [remarkDgmo, dgmoOptions];\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const mdxOptions = (nextraConfig['mdxOptions'] ?? {}) as Record<string, any>;\n const existing = mdxOptions['remarkPlugins'];\n\n // Already wired — bail early. Identity match doesn't survive across\n // calls (we construct a new tuple each time), so we check by reference\n // to the `remarkDgmo` function itself.\n if (Array.isArray(existing) && existing.some(isDgmoEntry)) {\n return nextraConfig;\n }\n\n let remarkPlugins: RemarkPluginsField;\n if (typeof existing === 'function') {\n const userFn = existing as RemarkPluginsFn;\n remarkPlugins = (defaults: RemarkPluginsArray) => {\n const next = userFn(defaults);\n const arr: RemarkPluginsArray = Array.isArray(next) ? [...next] : [];\n if (!arr.some(isDgmoEntry)) arr.unshift(remarkInstance);\n return arr;\n };\n } else {\n const arr = Array.isArray(existing) ? [...existing] : [];\n arr.unshift(remarkInstance);\n remarkPlugins = arr;\n }\n\n return {\n ...nextraConfig,\n mdxOptions: { ...mdxOptions, remarkPlugins },\n };\n}\n\nfunction isDgmoEntry(entry: unknown): boolean {\n if (entry === remarkDgmo) return true;\n if (Array.isArray(entry) && entry[0] === remarkDgmo) return true;\n return false;\n}\n"],"mappings":";AAAA,OAAO,gBAAgB;AA8DhB,SAAS,SACd,eAA6B,CAAC,GAC9B,UAA2B,CAAC,GACd;AAMd,QAAM,cAA2B,EAAE,KAAK,MAAM,GAAG,QAAQ,KAAK;AAC9D,QAAM,iBAA+B,CAAC,YAAY,WAAW;AAG7D,QAAM,aAAc,aAAa,YAAY,KAAK,CAAC;AACnD,QAAM,WAAW,WAAW,eAAe;AAK3C,MAAI,MAAM,QAAQ,QAAQ,KAAK,SAAS,KAAK,WAAW,GAAG;AACzD,WAAO;AAAA,EACT;AAEA,MAAI;AACJ,MAAI,OAAO,aAAa,YAAY;AAClC,UAAM,SAAS;AACf,oBAAgB,CAAC,aAAiC;AAChD,YAAM,OAAO,OAAO,QAAQ;AAC5B,YAAM,MAA0B,MAAM,QAAQ,IAAI,IAAI,CAAC,GAAG,IAAI,IAAI,CAAC;AACnE,UAAI,CAAC,IAAI,KAAK,WAAW,EAAG,KAAI,QAAQ,cAAc;AACtD,aAAO;AAAA,IACT;AAAA,EACF,OAAO;AACL,UAAM,MAAM,MAAM,QAAQ,QAAQ,IAAI,CAAC,GAAG,QAAQ,IAAI,CAAC;AACvD,QAAI,QAAQ,cAAc;AAC1B,oBAAgB;AAAA,EAClB;AAEA,SAAO;AAAA,IACL,GAAG;AAAA,IACH,YAAY,EAAE,GAAG,YAAY,cAAc;AAAA,EAC7C;AACF;AAEA,SAAS,YAAY,OAAyB;AAC5C,MAAI,UAAU,WAAY,QAAO;AACjC,MAAI,MAAM,QAAQ,KAAK,KAAK,MAAM,CAAC,MAAM,WAAY,QAAO;AAC5D,SAAO;AACT;","names":[]}
|
package/dist/client.css
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/* nextra-dgmo/client.css
|
|
2
|
+
*
|
|
3
|
+
* Generated from remark-dgmo/client.css at build time. Selectors of the
|
|
4
|
+
* form `[data-theme="dark"]` are rewritten to `html.dark` for Nextra's
|
|
5
|
+
* next-themes default (attribute="class"). Do not edit manually —
|
|
6
|
+
* change scripts/build-css.mjs instead.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/* remark-dgmo — visibility, sizing, and showcase chrome.
|
|
10
|
+
* Override the `html.dark` selector if your site uses
|
|
11
|
+
* `.dark` or another convention. */
|
|
12
|
+
|
|
13
|
+
/* === Color-mode visibility === */
|
|
14
|
+
.dgmo-dark {
|
|
15
|
+
display: none;
|
|
16
|
+
}
|
|
17
|
+
html.dark .dgmo-light {
|
|
18
|
+
display: none;
|
|
19
|
+
}
|
|
20
|
+
html.dark .dgmo-dark {
|
|
21
|
+
display: block;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/* === Diagram sizing ===
|
|
25
|
+
* SVGs are emitted with viewBox only (no fixed width/height). Force them
|
|
26
|
+
* to fill their wrapper so light and dark variants render at identical
|
|
27
|
+
* sizes — without this, browsers fall back to the 300x150 UA default and
|
|
28
|
+
* the two themes can disagree depending on host CSS.
|
|
29
|
+
*
|
|
30
|
+
* Targets the SVG, NOT its wrapper div — the wrappers' display is what
|
|
31
|
+
* the color-mode toggle rules above flip, so we mustn't override it. */
|
|
32
|
+
.dgmo-light > svg,
|
|
33
|
+
.dgmo-dark > svg,
|
|
34
|
+
.dgmo-svg > svg {
|
|
35
|
+
display: block;
|
|
36
|
+
width: 100%;
|
|
37
|
+
height: auto;
|
|
38
|
+
max-width: 100%;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/* === Showcase mode: source block ===
|
|
42
|
+
* <pre> is browser-default `white-space: pre`, but Docusaurus and several
|
|
43
|
+
* other docs frameworks reset that. Force preservation here so the source
|
|
44
|
+
* keeps its newlines and renders as code. */
|
|
45
|
+
.dgmo-pre {
|
|
46
|
+
white-space: pre;
|
|
47
|
+
overflow-x: auto;
|
|
48
|
+
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
|
|
49
|
+
font-size: 0.85em;
|
|
50
|
+
line-height: 1.5;
|
|
51
|
+
margin: 0;
|
|
52
|
+
padding: 1em;
|
|
53
|
+
}
|
|
54
|
+
.dgmo-code {
|
|
55
|
+
display: block;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/* === Showcase mode: card + toolbar ===
|
|
59
|
+
* Showcase order is diagram-then-source. The source is wrapped in a
|
|
60
|
+
* <details> disclosure that's collapsed by default — the <summary>
|
|
61
|
+
* doubles as the toolbar row at the bottom of the card. */
|
|
62
|
+
.dgmo-card {
|
|
63
|
+
border: 1px solid rgba(127, 127, 127, 0.2);
|
|
64
|
+
border-radius: 0.5em;
|
|
65
|
+
overflow: hidden;
|
|
66
|
+
}
|
|
67
|
+
.dgmo-source-wrap {
|
|
68
|
+
border-top: 1px solid rgba(127, 127, 127, 0.2);
|
|
69
|
+
}
|
|
70
|
+
/* Summary is the clickable toolbar. Hide the native disclosure marker
|
|
71
|
+
* (both spec and webkit pseudo) so our own chevron is the only indicator. */
|
|
72
|
+
.dgmo-toolbar {
|
|
73
|
+
display: flex;
|
|
74
|
+
align-items: center;
|
|
75
|
+
justify-content: space-between;
|
|
76
|
+
padding: 0.4em 0.75em;
|
|
77
|
+
background: rgba(127, 127, 127, 0.07);
|
|
78
|
+
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
|
|
79
|
+
font-size: 0.75em;
|
|
80
|
+
color: rgba(127, 127, 127, 0.95);
|
|
81
|
+
cursor: pointer;
|
|
82
|
+
list-style: none;
|
|
83
|
+
user-select: none;
|
|
84
|
+
}
|
|
85
|
+
.dgmo-toolbar::-webkit-details-marker {
|
|
86
|
+
display: none;
|
|
87
|
+
}
|
|
88
|
+
.dgmo-toolbar-label {
|
|
89
|
+
display: inline-flex;
|
|
90
|
+
align-items: center;
|
|
91
|
+
gap: 0.4em;
|
|
92
|
+
}
|
|
93
|
+
.dgmo-chevron {
|
|
94
|
+
transition: transform 0.15s ease;
|
|
95
|
+
flex-shrink: 0;
|
|
96
|
+
}
|
|
97
|
+
details[open] > .dgmo-toolbar .dgmo-chevron {
|
|
98
|
+
transform: rotate(90deg);
|
|
99
|
+
}
|
|
100
|
+
.dgmo-toolbar-actions {
|
|
101
|
+
display: flex;
|
|
102
|
+
gap: 0.4em;
|
|
103
|
+
}
|
|
104
|
+
.dgmo-toolbar-btn {
|
|
105
|
+
background: none;
|
|
106
|
+
border: 0;
|
|
107
|
+
padding: 0.25em;
|
|
108
|
+
color: inherit;
|
|
109
|
+
cursor: pointer;
|
|
110
|
+
display: inline-flex;
|
|
111
|
+
align-items: center;
|
|
112
|
+
opacity: 0.7;
|
|
113
|
+
transition: opacity 0.15s ease;
|
|
114
|
+
}
|
|
115
|
+
.dgmo-toolbar-btn:hover {
|
|
116
|
+
opacity: 1;
|
|
117
|
+
}
|
|
118
|
+
.dgmo-copy--success {
|
|
119
|
+
color: #5cba7a;
|
|
120
|
+
opacity: 1;
|
|
121
|
+
}
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { DgmoOptions } from 'remark-dgmo';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Shape of the `remarkPlugins` slot inside a Nextra config's `mdxOptions`.
|
|
5
|
+
* We only need that one slot — everything else on the config is forwarded
|
|
6
|
+
* untouched — so we type it loosely instead of importing Nextra's internal
|
|
7
|
+
* types (which churn between minor versions).
|
|
8
|
+
*
|
|
9
|
+
* `remarkPlugins` accepts the same shapes Nextra accepts: either a plain
|
|
10
|
+
* array, or a function that receives the framework's defaults and returns
|
|
11
|
+
* the array to use. We preserve whichever form the user passed.
|
|
12
|
+
*/
|
|
13
|
+
type RemarkPlugin = unknown;
|
|
14
|
+
type RemarkPluginsArray = RemarkPlugin[];
|
|
15
|
+
type RemarkPluginsFn = (defaults: RemarkPluginsArray) => RemarkPluginsArray;
|
|
16
|
+
type RemarkPluginsField = RemarkPluginsArray | RemarkPluginsFn;
|
|
17
|
+
type NextraConfig = Record<string, any>;
|
|
18
|
+
interface WithDgmoOptions {
|
|
19
|
+
/** Options forwarded to `remark-dgmo` (palette, theme, colorMode, etc.). */
|
|
20
|
+
dgmo?: DgmoOptions;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Augment a Nextra config object so the `remark-dgmo` plugin runs as part
|
|
24
|
+
* of the MDX pipeline. Unlike Fumadocs — which exposes `remarkPlugins` at
|
|
25
|
+
* the top level of its `mdxOptions` object — Nextra nests the remark
|
|
26
|
+
* pipeline one level deeper, under `nextraConfig.mdxOptions.remarkPlugins`.
|
|
27
|
+
* Designed to compose with Nextra's own `nextra()` factory:
|
|
28
|
+
*
|
|
29
|
+
* ```js
|
|
30
|
+
* // next.config.mjs
|
|
31
|
+
* import nextra from 'nextra'
|
|
32
|
+
* import { withDgmo } from 'nextra-dgmo/config'
|
|
33
|
+
*
|
|
34
|
+
* const withNextra = nextra(
|
|
35
|
+
* withDgmo({ /* nextra options *\/ }, { dgmo: { palette: 'slate' } })
|
|
36
|
+
* )
|
|
37
|
+
*
|
|
38
|
+
* export default withNextra({ /* next config *\/ })
|
|
39
|
+
* ```
|
|
40
|
+
*
|
|
41
|
+
* Idempotent — running it on an already-wired config returns the same
|
|
42
|
+
* config without double-injecting. The remark plugin is prepended to the
|
|
43
|
+
* plugin list so it sees fenced `dgmo` blocks before any downstream remark
|
|
44
|
+
* plugin (notably Nextra's own MDX file resolver) gets a chance to
|
|
45
|
+
* transform them.
|
|
46
|
+
*
|
|
47
|
+
* If `mdxOptions.remarkPlugins` is the function form Nextra supports
|
|
48
|
+
* (`(defaults) => [...]`), the returned config keeps the function form and
|
|
49
|
+
* prepends `remarkDgmo` to the function's eventual output.
|
|
50
|
+
*/
|
|
51
|
+
declare function withDgmo(nextraConfig?: NextraConfig, options?: WithDgmoOptions): NextraConfig;
|
|
52
|
+
|
|
53
|
+
export { type NextraConfig, type RemarkPlugin, type RemarkPluginsArray, type RemarkPluginsField, type RemarkPluginsFn, type WithDgmoOptions, withDgmo };
|
package/dist/config.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["// ============================================================\n// nextra-dgmo — Public API\n// ============================================================\n//\n// Nextra (Next.js docs) wrapper for the framework-agnostic\n// `remark-dgmo` plugin. Three things land here:\n//\n// 1. `withDgmo` — augments a Nextra config object so the remark plugin\n// runs as part of the MDX pipeline. The main ergonomic helper.\n// 2. Re-exported types from `remark-dgmo` (DgmoOptions et al).\n// 3. The remark plugin itself, for users who want to wire it manually.\n//\n// The host-specific bits — the `<DgmoClient />` React component and the\n// adapted `client.css` — live behind their own subpath exports\n// (`nextra-dgmo/client`, `nextra-dgmo/client.css`) so they don't pull\n// React/JSX into the server-only config code path.\n\nexport { withDgmo } from './config.js';\nexport type {\n WithDgmoOptions,\n NextraConfig,\n RemarkPlugin,\n RemarkPluginsArray,\n RemarkPluginsFn,\n RemarkPluginsField,\n} from './config.js';\n\nexport { default as remarkDgmo } from 'remark-dgmo';\nexport type { DgmoOptions, Mode, Theme, ResolvedOptions } from 'remark-dgmo';\n"],"mappings":";;;;;AA2BA,SAAoB,WAAXA,gBAA6B;","names":["default"]}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
// src/nextra-client.tsx
|
|
4
|
+
import "nextra-dgmo/client.css";
|
|
5
|
+
import { useEffect } from "react";
|
|
6
|
+
import { usePathname } from "next/navigation";
|
|
7
|
+
|
|
8
|
+
// node_modules/.pnpm/remark-dgmo@0.4.0_@diagrammo+dgmo@0.39.0_@lezer+common@1.5.2_@lezer+highlight@1.2.3_@lezer+lr@1.4.10_/node_modules/remark-dgmo/dist/client.js
|
|
9
|
+
var clickHandlerBound = false;
|
|
10
|
+
var themeObserverBound = false;
|
|
11
|
+
function isInteractiveBrowser() {
|
|
12
|
+
return typeof window !== "undefined" && typeof document !== "undefined" && typeof MutationObserver !== "undefined" && typeof requestAnimationFrame !== "undefined";
|
|
13
|
+
}
|
|
14
|
+
function bindDgmo() {
|
|
15
|
+
if (!isInteractiveBrowser()) return;
|
|
16
|
+
if (!clickHandlerBound) {
|
|
17
|
+
document.addEventListener("click", (e) => {
|
|
18
|
+
void handleToolbarBtnClick(e);
|
|
19
|
+
});
|
|
20
|
+
clickHandlerBound = true;
|
|
21
|
+
}
|
|
22
|
+
tightenViewBoxes();
|
|
23
|
+
if (!themeObserverBound) {
|
|
24
|
+
const html = document.documentElement;
|
|
25
|
+
const reTighten = () => {
|
|
26
|
+
requestAnimationFrame(() => requestAnimationFrame(tightenViewBoxes));
|
|
27
|
+
};
|
|
28
|
+
new MutationObserver(reTighten).observe(html, {
|
|
29
|
+
attributes: true,
|
|
30
|
+
attributeFilter: ["data-theme", "class"]
|
|
31
|
+
});
|
|
32
|
+
themeObserverBound = true;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
async function handleToolbarBtnClick(e) {
|
|
36
|
+
const target = e.target;
|
|
37
|
+
if (!target || typeof target.closest !== "function") return;
|
|
38
|
+
const btn = target.closest(".dgmo-toolbar-btn");
|
|
39
|
+
if (!btn) return;
|
|
40
|
+
const insideSummary = !!btn.closest("summary");
|
|
41
|
+
if (insideSummary) e.preventDefault();
|
|
42
|
+
if (btn.matches("button.dgmo-copy")) {
|
|
43
|
+
const src = btn.dataset["dgmoSource"] ?? "";
|
|
44
|
+
try {
|
|
45
|
+
await navigator.clipboard.writeText(src);
|
|
46
|
+
} catch {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
btn.classList.add("dgmo-copy--success");
|
|
50
|
+
setTimeout(() => btn.classList.remove("dgmo-copy--success"), 1500);
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
if (insideSummary && btn.matches("a.dgmo-open")) {
|
|
54
|
+
const anchor = btn;
|
|
55
|
+
if (anchor.href) {
|
|
56
|
+
window.open(
|
|
57
|
+
anchor.href,
|
|
58
|
+
anchor.target || "_blank",
|
|
59
|
+
"noopener,noreferrer"
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
function tightenViewBoxes() {
|
|
65
|
+
const WRAPPER_SELECTORS = ".dgmo-light, .dgmo-dark, .dgmo-svg";
|
|
66
|
+
document.querySelectorAll(WRAPPER_SELECTORS).forEach((node) => {
|
|
67
|
+
const wrapper = node;
|
|
68
|
+
const svg = wrapper.querySelector("svg");
|
|
69
|
+
if (!svg) return;
|
|
70
|
+
const computed = window.getComputedStyle(wrapper);
|
|
71
|
+
const wasHidden = computed.display === "none";
|
|
72
|
+
const savedInlineDisplay = wrapper.style.display;
|
|
73
|
+
if (wasHidden) {
|
|
74
|
+
wrapper.style.display = "block";
|
|
75
|
+
void wrapper.offsetHeight;
|
|
76
|
+
}
|
|
77
|
+
try {
|
|
78
|
+
const bbox = svg.getBBox();
|
|
79
|
+
if (bbox.width > 0 && bbox.height > 0) {
|
|
80
|
+
const pad = 16;
|
|
81
|
+
svg.setAttribute(
|
|
82
|
+
"viewBox",
|
|
83
|
+
`${bbox.x - pad} ${bbox.y - pad} ${bbox.width + pad * 2} ${bbox.height + pad * 2}`
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
} catch {
|
|
87
|
+
}
|
|
88
|
+
if (wasHidden) {
|
|
89
|
+
wrapper.style.display = savedInlineDisplay;
|
|
90
|
+
if (savedInlineDisplay === "" && wrapper.getAttribute("style") === "") {
|
|
91
|
+
wrapper.removeAttribute("style");
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
if (isInteractiveBrowser()) {
|
|
97
|
+
if (document.readyState === "loading") {
|
|
98
|
+
document.addEventListener("DOMContentLoaded", bindDgmo);
|
|
99
|
+
} else {
|
|
100
|
+
bindDgmo();
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// src/nextra-client.tsx
|
|
105
|
+
function DgmoClient() {
|
|
106
|
+
const pathname = usePathname();
|
|
107
|
+
useEffect(() => {
|
|
108
|
+
bindDgmo();
|
|
109
|
+
}, [pathname]);
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
var nextra_client_default = DgmoClient;
|
|
113
|
+
export {
|
|
114
|
+
DgmoClient,
|
|
115
|
+
nextra_client_default as default
|
|
116
|
+
};
|
|
117
|
+
//# sourceMappingURL=nextra-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/nextra-client.tsx","../node_modules/.pnpm/remark-dgmo@0.4.0_@diagrammo+dgmo@0.39.0_@lezer+common@1.5.2_@lezer+highlight@1.2.3_@lezer+lr@1.4.10_/node_modules/remark-dgmo/src/client.ts"],"sourcesContent":["/**\n * Nextra-shaped client wrapper for `remark-dgmo`'s framework-neutral\n * `bindDgmo()` function. Drop this once inside your `app/layout.tsx`\n * (typically alongside Nextra's layout) and it will:\n *\n * - run `bindDgmo()` on initial mount, tightening every diagram's\n * viewBox to content bounds and wiring showcase-mode copy buttons;\n * - re-run `bindDgmo()` on every client-side route change (Next's\n * app router does not refire `DOMContentLoaded` semantics on soft\n * navigation).\n *\n * Lives in this package — not in `remark-dgmo` — so that Next's `'use\n * client'` directive and `next/navigation` import stay out of the\n * framework-agnostic core.\n */\n// Side-effect CSS import: Next's app-router CSS pipeline picks this up\n// because the component is a Client Component imported from a layout.\n// Self-references the package via its exports map so it works at both\n// build time (tsup marks it external) and consumer time (Next resolves\n// it through node_modules/nextra-dgmo/dist/client.css). Mounting\n// `<DgmoClient />` is now the only thing a consumer has to do for both\n// runtime rebinding AND theme-aware styling.\nimport 'nextra-dgmo/client.css';\nimport { useEffect } from 'react';\nimport { usePathname } from 'next/navigation';\nimport { bindDgmo } from 'remark-dgmo/client.js';\n\nexport function DgmoClient(): null {\n const pathname = usePathname();\n\n useEffect(() => {\n // bindDgmo is idempotent — it scans for already-bound buttons and\n // skips them — so calling it on every pathname change is safe and\n // covers both initial paint and subsequent SPA navigations.\n bindDgmo();\n }, [pathname]);\n\n return null;\n}\n\nexport default DgmoClient;\n","/**\n * Framework-neutral client-side enhancement for diagrams emitted by\n * `remark-dgmo`:\n *\n * - Bind a delegated click handler for the showcase toolbar buttons:\n * `.dgmo-copy` copies the source string in `data-dgmo-source` to the\n * clipboard. `.dgmo-open` is an `<a href>` whose default-action\n * navigation is preserved — except when it lives inside a `<summary>`\n * (the collapsible toolbar case), where we have to manually navigate\n * because the same click's `preventDefault()` cancels both the\n * summary's toggle AND the anchor's nav.\n * - Tighten each diagram's `viewBox` to its actual content bounds via\n * `SVGGraphicsElement.getBBox()`, since SVG-export from the renderer\n * embeds a generous bounding box.\n *\n * `bindDgmo()` is safe to call multiple times: the click handler is bound\n * once-and-only-once (idempotent), and viewBox tightening is run every\n * invocation so SPA-style frameworks (Docusaurus) can re-run it after\n * route changes.\n *\n * In a non-browser environment, `bindDgmo()` is a no-op. We can't just check\n * for `window`/`document`: some SSG renderers (Docusaurus's static export among\n * them) evaluate client modules against a PARTIAL DOM that defines `window` and\n * `document` but NOT the browser-only APIs this function relies on\n * (`MutationObserver`, `requestAnimationFrame`, `SVGGraphicsElement.getBBox`).\n * So we feature-detect those too and bail unless we're in a real browser —\n * otherwise the module-level auto-init below throws during server render.\n */\n\nlet clickHandlerBound = false;\nlet themeObserverBound = false;\n\nfunction isInteractiveBrowser(): boolean {\n return (\n typeof window !== 'undefined' &&\n typeof document !== 'undefined' &&\n typeof MutationObserver !== 'undefined' &&\n typeof requestAnimationFrame !== 'undefined'\n );\n}\n\nexport function bindDgmo(): void {\n if (!isInteractiveBrowser()) return;\n\n if (!clickHandlerBound) {\n document.addEventListener('click', (e) => {\n void handleToolbarBtnClick(e);\n });\n clickHandlerBound = true;\n }\n tightenViewBoxes();\n\n // Color-mode toggles flip which dual-render wrapper is `display: none`.\n // The wrapper that was hidden at load couldn't be measured (getBBox\n // returns 0 on display:none subtrees), so its SVG keeps the full\n // un-tightened viewBox and looks tiny when it becomes visible. Watch\n // for the host's color-mode signal flipping and re-tighten then.\n //\n // Double-rAF defers the measurement until AFTER the browser has\n // finished the layout pass that the display-change triggered. Without\n // it, MutationObserver fires synchronously before layout and getBBox\n // still returns 0 on the freshly-visible element.\n if (!themeObserverBound) {\n const html = document.documentElement;\n const reTighten = () => {\n requestAnimationFrame(() => requestAnimationFrame(tightenViewBoxes));\n };\n new MutationObserver(reTighten).observe(html, {\n attributes: true,\n attributeFilter: ['data-theme', 'class'],\n });\n themeObserverBound = true;\n }\n}\n\nasync function handleToolbarBtnClick(e: Event): Promise<void> {\n const target = e.target as Element | null;\n if (!target || typeof target.closest !== 'function') return;\n const btn = target.closest('.dgmo-toolbar-btn') as HTMLElement | null;\n if (!btn) return;\n\n // The showcase toolbar IS the <summary> of a <details> disclosure, so a\n // click on any descendant would also toggle the disclosure unless we\n // cancel the default action. preventDefault here cancels the summary's\n // toggle — but it also cancels an anchor's navigation, so we have to\n // manually re-open the link below when the open-in-editor button is\n // nested inside a summary.\n const insideSummary = !!btn.closest('summary');\n if (insideSummary) e.preventDefault();\n\n if (btn.matches('button.dgmo-copy')) {\n const src = btn.dataset['dgmoSource'] ?? '';\n try {\n await navigator.clipboard.writeText(src);\n } catch {\n return;\n }\n btn.classList.add('dgmo-copy--success');\n setTimeout(() => btn.classList.remove('dgmo-copy--success'), 1500);\n return;\n }\n\n if (insideSummary && btn.matches('a.dgmo-open')) {\n const anchor = btn as HTMLAnchorElement;\n if (anchor.href) {\n window.open(\n anchor.href,\n anchor.target || '_blank',\n 'noopener,noreferrer'\n );\n }\n }\n}\n\nfunction tightenViewBoxes(): void {\n const WRAPPER_SELECTORS = '.dgmo-light, .dgmo-dark, .dgmo-svg';\n document.querySelectorAll(WRAPPER_SELECTORS).forEach((node) => {\n const wrapper = node as HTMLElement;\n const svg = wrapper.querySelector('svg') as SVGSVGElement | null;\n if (!svg) return;\n\n // `getBBox()` returns 0,0,0,0 on elements whose ancestor is `display: none`.\n // Under dual-render the inactive color-mode wrapper IS display:none at load,\n // so its SVG would stay un-tightened — and then look small after the user\n // toggles into it. Set the wrapper to inline-style `display: block`\n // synchronously, read getBBox, then restore. Modern browsers don't paint\n // between these synchronous DOM writes, so there's no visible flicker.\n const computed = window.getComputedStyle(wrapper);\n const wasHidden = computed.display === 'none';\n const savedInlineDisplay = wrapper.style.display;\n if (wasHidden) {\n wrapper.style.display = 'block';\n // Force a synchronous layout pass before getBBox so the freshly-\n // shown element actually has bounds. Without this, some browsers\n // still report 0,0,0,0 because they batch the display change for\n // the next frame.\n void wrapper.offsetHeight;\n }\n\n try {\n const bbox = (svg as unknown as SVGGraphicsElement).getBBox();\n if (bbox.width > 0 && bbox.height > 0) {\n const pad = 16;\n svg.setAttribute(\n 'viewBox',\n `${bbox.x - pad} ${bbox.y - pad} ${bbox.width + pad * 2} ${\n bbox.height + pad * 2\n }`\n );\n }\n } catch {\n // ignore: SVG not yet in the DOM, or getBBox unsupported\n }\n\n if (wasHidden) {\n wrapper.style.display = savedInlineDisplay;\n // Clearing the only inline property leaves `style=\"\"` on the\n // element in Chrome/Safari. React 19's post-hydration check reads\n // that empty attribute as a server-vs-client mismatch on the\n // wrapper div (the wrapper is React-owned; only its `innerHTML`\n // is dangerouslySetInnerHTML). Drop the empty attribute so the\n // wrapper round-trips back to its SSR shape.\n if (savedInlineDisplay === '' && wrapper.getAttribute('style') === '') {\n wrapper.removeAttribute('style');\n }\n }\n });\n}\n\n// Auto-init on initial load. Docusaurus-style SPA wrappers also re-call\n// bindDgmo on route changes; that's safe (the click handler is bound once,\n// viewBox tightening runs every time).\nif (isInteractiveBrowser()) {\n if (document.readyState === 'loading') {\n document.addEventListener('DOMContentLoaded', bindDgmo);\n } else {\n bindDgmo();\n }\n}\n"],"mappings":"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","names":[]}
|
package/dist/remark.d.ts
ADDED
package/dist/remark.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/remark.ts"],"sourcesContent":["/**\n * Re-export `remark-dgmo` so users have a single dependency to install\n * (`nextra-dgmo`) and a single import path for the remark plugin:\n *\n * import remarkDgmo from 'nextra-dgmo/remark';\n *\n * Equivalent to importing `remark-dgmo` directly — the package is one of\n * our runtime dependencies.\n */\nexport { default } from 'remark-dgmo';\nexport * from 'remark-dgmo';\n"],"mappings":";AASA,SAAS,WAAAA,gBAAe;AACxB,cAAc;","names":["default"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "nextra-dgmo",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Nextra integration to render DGMO diagrams from fenced code blocks at build time. Two-step install: `withDgmo()` in next.config.mjs plus `<DgmoClient />` in app/layout.tsx — the client component handles route-change rebinding and auto-imports the theme-aware stylesheet.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/diagrammo/nextra-dgmo.git"
|
|
9
|
+
},
|
|
10
|
+
"homepage": "https://github.com/diagrammo/nextra-dgmo#readme",
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/diagrammo/nextra-dgmo/issues"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [
|
|
15
|
+
"nextra",
|
|
16
|
+
"next",
|
|
17
|
+
"nextjs",
|
|
18
|
+
"dgmo",
|
|
19
|
+
"diagrammo",
|
|
20
|
+
"diagram",
|
|
21
|
+
"diagrams",
|
|
22
|
+
"mdx",
|
|
23
|
+
"markdown",
|
|
24
|
+
"remark"
|
|
25
|
+
],
|
|
26
|
+
"type": "module",
|
|
27
|
+
"main": "./dist/index.js",
|
|
28
|
+
"module": "./dist/index.js",
|
|
29
|
+
"types": "./dist/index.d.ts",
|
|
30
|
+
"exports": {
|
|
31
|
+
".": {
|
|
32
|
+
"types": "./dist/index.d.ts",
|
|
33
|
+
"import": "./dist/index.js",
|
|
34
|
+
"default": "./dist/index.js"
|
|
35
|
+
},
|
|
36
|
+
"./config": {
|
|
37
|
+
"types": "./dist/config.d.ts",
|
|
38
|
+
"import": "./dist/config.js",
|
|
39
|
+
"default": "./dist/config.js"
|
|
40
|
+
},
|
|
41
|
+
"./remark": {
|
|
42
|
+
"types": "./dist/remark.d.ts",
|
|
43
|
+
"import": "./dist/remark.js",
|
|
44
|
+
"default": "./dist/remark.js"
|
|
45
|
+
},
|
|
46
|
+
"./client": {
|
|
47
|
+
"types": "./dist/nextra-client.d.ts",
|
|
48
|
+
"import": "./dist/nextra-client.js",
|
|
49
|
+
"default": "./dist/nextra-client.js"
|
|
50
|
+
},
|
|
51
|
+
"./client.css": "./dist/client.css"
|
|
52
|
+
},
|
|
53
|
+
"files": [
|
|
54
|
+
"dist",
|
|
55
|
+
"README.md",
|
|
56
|
+
"LICENSE"
|
|
57
|
+
],
|
|
58
|
+
"sideEffects": false,
|
|
59
|
+
"engines": {
|
|
60
|
+
"node": ">=20.6"
|
|
61
|
+
},
|
|
62
|
+
"scripts": {
|
|
63
|
+
"build": "tsup && node scripts/build-css.mjs",
|
|
64
|
+
"postbuild": "test -f dist/client.css && test -f dist/nextra-client.js",
|
|
65
|
+
"dev": "tsup --watch",
|
|
66
|
+
"typecheck": "tsc --noEmit",
|
|
67
|
+
"pretest": "pnpm build",
|
|
68
|
+
"test": "vitest run --coverage",
|
|
69
|
+
"test:watch": "vitest",
|
|
70
|
+
"lint": "eslint .",
|
|
71
|
+
"lint:fix": "eslint . --fix",
|
|
72
|
+
"format": "prettier --write .",
|
|
73
|
+
"format:check": "prettier --check .",
|
|
74
|
+
"check:deadcode": "knip",
|
|
75
|
+
"check:duplication": "jscpd ./src",
|
|
76
|
+
"check:deps": "depcheck --ignores='nextra-dgmo'",
|
|
77
|
+
"check:all": "pnpm check:deadcode && pnpm check:duplication && pnpm check:deps",
|
|
78
|
+
"prepublishOnly": "pnpm build && pnpm test"
|
|
79
|
+
},
|
|
80
|
+
"peerDependencies": {
|
|
81
|
+
"@diagrammo/dgmo": "^0.39.0",
|
|
82
|
+
"next": "^15.0.0 || ^16.0.0",
|
|
83
|
+
"nextra": "^4.0.0",
|
|
84
|
+
"react": "^19.0.0"
|
|
85
|
+
},
|
|
86
|
+
"peerDependenciesMeta": {
|
|
87
|
+
"next": {
|
|
88
|
+
"optional": false
|
|
89
|
+
},
|
|
90
|
+
"nextra": {
|
|
91
|
+
"optional": false
|
|
92
|
+
},
|
|
93
|
+
"react": {
|
|
94
|
+
"optional": false
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
"dependencies": {
|
|
98
|
+
"remark-dgmo": "^0.4.0"
|
|
99
|
+
},
|
|
100
|
+
"devDependencies": {
|
|
101
|
+
"@diagrammo/dgmo": "^0.39.0",
|
|
102
|
+
"@eslint/js": "^10.0.1",
|
|
103
|
+
"@types/node": "^22.10.0",
|
|
104
|
+
"@types/react": "^19.0.0",
|
|
105
|
+
"@vitest/coverage-v8": "^4.1.6",
|
|
106
|
+
"depcheck": "^1.4.7",
|
|
107
|
+
"eslint": "^10.4.0",
|
|
108
|
+
"next": "^16.0.0",
|
|
109
|
+
"nextra": "^4.0.0",
|
|
110
|
+
"jscpd": "^4.0.9",
|
|
111
|
+
"knip": "^6.14.1",
|
|
112
|
+
"prettier": "^3.8.3",
|
|
113
|
+
"react": "^19.0.0",
|
|
114
|
+
"tsup": "^8.5.1",
|
|
115
|
+
"typescript": "^6.0.2",
|
|
116
|
+
"typescript-eslint": "^8.59.3",
|
|
117
|
+
"vitest": "^4.1.4"
|
|
118
|
+
}
|
|
119
|
+
}
|