nextra-dgmo 0.4.1 → 0.4.2
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 +30 -0
- package/dist/{chunk-4W254UGY.js → chunk-XNULWB4X.js} +16 -2
- package/dist/chunk-XNULWB4X.js.map +1 -0
- package/dist/client-render-HT3VPJJS.js +11 -0
- package/dist/client-render-HT3VPJJS.js.map +1 -0
- package/dist/config.d.ts +3 -1
- package/dist/config.js +3 -1
- package/dist/index.js +1 -1
- package/dist/nextra-client.d.ts +19 -0
- package/dist/nextra-render-client.d.ts +3 -0
- package/dist/nextra-render-client.js +17 -0
- package/dist/nextra-render-client.js.map +1 -0
- package/package.json +7 -2
- package/dist/chunk-4W254UGY.js.map +0 -1
package/README.md
CHANGED
|
@@ -161,6 +161,36 @@ A -> B
|
|
|
161
161
|
|
|
162
162
|
See the [`remark-dgmo` README](https://github.com/diagrammo/remark-dgmo) for the full option matrix.
|
|
163
163
|
|
|
164
|
+
## Live links: when a diagram changes after you build
|
|
165
|
+
|
|
166
|
+
A fence can name a published [Diagrammo Cloud](https://diagrammo.app) diagram instead of carrying its own source:
|
|
167
|
+
|
|
168
|
+
````markdown
|
|
169
|
+
```dgmo
|
|
170
|
+
live-link dgm_01HQ3RSTUV
|
|
171
|
+
```
|
|
172
|
+
````
|
|
173
|
+
|
|
174
|
+
The build fetches it, renders it like any other block, and writes what it fetched to `.dgmo/references/<id>.json` — **commit that directory.** It is what keeps your build reproducible and independent of our uptime.
|
|
175
|
+
|
|
176
|
+
If the diagram changes after your last build, the page **notices** by default: readers get a small link to the live version. Re-drawing it in the browser instead means shipping the renderer, so it takes two steps that are really one decision.
|
|
177
|
+
|
|
178
|
+
```js
|
|
179
|
+
// next.config.mjs
|
|
180
|
+
const withNextra = nextra(
|
|
181
|
+
withDgmo({}, { dgmo: { liveLink: { refresh: 'render' } } })
|
|
182
|
+
);
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
```tsx
|
|
186
|
+
// app/layout.tsx — beside <DgmoClient />
|
|
187
|
+
import { DgmoRenderClient } from 'nextra-dgmo/client-render';
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
Set the option without mounting the component and your build says so, once, naming both. Next emits the renderer as its own chunk, fetched only when a diagram has actually changed.
|
|
191
|
+
|
|
192
|
+
⚠️ If your site sets a Content-Security-Policy it must allow `connect-src https://api.diagrammo.app`, or the baked diagram renders and simply never updates.
|
|
193
|
+
|
|
164
194
|
## How CSS is delivered
|
|
165
195
|
|
|
166
196
|
`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.
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import remarkDgmo from "remark-dgmo";
|
|
3
3
|
function withDgmo(nextraConfig = {}, options = {}) {
|
|
4
4
|
const dgmoOptions = { mdx: true, ...options.dgmo };
|
|
5
|
+
noticeRenderClientRequired(dgmoOptions);
|
|
5
6
|
const remarkInstance = [remarkDgmo, dgmoOptions];
|
|
6
7
|
const mdxOptions = nextraConfig["mdxOptions"] ?? {};
|
|
7
8
|
const existing = mdxOptions["remarkPlugins"];
|
|
@@ -27,6 +28,18 @@ function withDgmo(nextraConfig = {}, options = {}) {
|
|
|
27
28
|
mdxOptions: { ...mdxOptions, remarkPlugins }
|
|
28
29
|
};
|
|
29
30
|
}
|
|
31
|
+
var noticed = false;
|
|
32
|
+
function noticeRenderClientRequired(dgmoOptions) {
|
|
33
|
+
if (noticed) return;
|
|
34
|
+
if (dgmoOptions.liveLink?.refresh !== "render") return;
|
|
35
|
+
noticed = true;
|
|
36
|
+
console.info(
|
|
37
|
+
"[nextra-dgmo] Live links are set to re-render in the browser. Mount `<DgmoRenderClient />` from `nextra-dgmo/client-render` in app/layout.tsx, beside `<DgmoClient />` \u2014 without it a diagram that has moved is linked to, not redrawn. Your Content-Security-Policy must also allow `connect-src https://api.diagrammo.app`."
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
function resetRenderClientNotice() {
|
|
41
|
+
noticed = false;
|
|
42
|
+
}
|
|
30
43
|
function isDgmoEntry(entry) {
|
|
31
44
|
if (entry === remarkDgmo) return true;
|
|
32
45
|
if (Array.isArray(entry) && entry[0] === remarkDgmo) return true;
|
|
@@ -34,6 +47,7 @@ function isDgmoEntry(entry) {
|
|
|
34
47
|
}
|
|
35
48
|
|
|
36
49
|
export {
|
|
37
|
-
withDgmo
|
|
50
|
+
withDgmo,
|
|
51
|
+
resetRenderClientNotice
|
|
38
52
|
};
|
|
39
|
-
//# sourceMappingURL=chunk-
|
|
53
|
+
//# sourceMappingURL=chunk-XNULWB4X.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 noticeRenderClientRequired(dgmoOptions);\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\nlet noticed = false;\n\n/**\n * Say the second half out loud, once per build.\n *\n * `liveLink: { refresh: 'render' }` is a decision about what runs in a reader's\n * browser, and this function only touches the MDX pipeline — Nextra mounts its\n * own client tree, so nothing here can put a component in it. Until\n * `<DgmoRenderClient />` is mounted the setting has no effect whatsoever, and\n * the page falls back to the \"This diagram has been updated\" link.\n *\n * That silence is the whole defect this exists to close: through 0.4.1 the\n * option was accepted and dropped, so a site believed it had turned re-rendering\n * on. A build is the one moment somebody is demonstrably paying attention.\n *\n * Test seam: `resetRenderClientNotice()`.\n */\nfunction noticeRenderClientRequired(dgmoOptions: DgmoOptions): void {\n if (noticed) return;\n if (dgmoOptions.liveLink?.refresh !== 'render') return;\n noticed = true;\n console.info(\n '[nextra-dgmo] Live links are set to re-render in the browser. Mount `<DgmoRenderClient />` from `nextra-dgmo/client-render` in app/layout.tsx, beside `<DgmoClient />` — without it a diagram that has moved is linked to, not redrawn. Your Content-Security-Policy must also allow `connect-src https://api.diagrammo.app`.'\n );\n}\n\n/** Test seam: reset the once-per-process notice. */\nexport function resetRenderClientNotice(): void {\n noticed = false;\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,6BAA2B,WAAW;AACtC,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,IAAI,UAAU;AAiBd,SAAS,2BAA2B,aAAgC;AAClE,MAAI,QAAS;AACb,MAAI,YAAY,UAAU,YAAY,SAAU;AAChD,YAAU;AACV,UAAQ;AAAA,IACN;AAAA,EACF;AACF;AAGO,SAAS,0BAAgC;AAC9C,YAAU;AACZ;AAEA,SAAS,YAAY,OAAyB;AAC5C,MAAI,UAAU,WAAY,QAAO;AACjC,MAAI,MAAM,QAAQ,KAAK,KAAK,MAAM,CAAC,MAAM,WAAY,QAAO;AAC5D,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
// node_modules/.pnpm/remark-dgmo@0.14.0_@diagrammo+dgmo@0.60.0_@lezer+common@1.5.2_@lezer+highlight@1.2.3_@lezer+lr@1.4.10_/node_modules/remark-dgmo/dist/client-render.js
|
|
4
|
+
(() => {
|
|
5
|
+
const g = globalThis;
|
|
6
|
+
g.__dgmoReferenceRenderer = () => import("@diagrammo/dgmo/block");
|
|
7
|
+
if (typeof Event === "function" && typeof g.dispatchEvent === "function") {
|
|
8
|
+
g.dispatchEvent(new Event("dgmo:renderer-ready"));
|
|
9
|
+
}
|
|
10
|
+
})();
|
|
11
|
+
//# sourceMappingURL=client-render-HT3VPJJS.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../node_modules/.pnpm/remark-dgmo@0.14.0_@diagrammo+dgmo@0.60.0_@lezer+common@1.5.2_@lezer+highlight@1.2.3_@lezer+lr@1.4.10_/node_modules/remark-dgmo/src/client-render.ts"],"sourcesContent":["/**\n * Cloud references — the OPT-IN renderer (Diagrammo Cloud story 10.4).\n *\n * Load this alongside `remark-dgmo/client.js` if you want a referenced diagram\n * that has changed since your last build to be **re-rendered in the reader's\n * browser** rather than merely flagged as updated.\n *\n * ```js\n * import 'remark-dgmo/client.js';\n * import 'remark-dgmo/client-render.js'; // opt in to the swap\n * ```\n *\n * ## Why it is a separate file\n *\n * Because the cost is real and it lands on the adopter. Measured on\n * `astro-dgmo`'s fixture (2026-07-30): with this one dynamic import living in\n * the base client, the built site went from **1 chunk / 7,990 gzipped bytes to\n * 90 chunks / 634,199**. Bundlers resolve a static-analyzable dynamic import at\n * BUILD time — \"lazy\" says when the reader downloads it, not whether the site\n * ships it. Keeping the renderer in a module nobody imports by default is the\n * only way a bundler can decline to follow it.\n *\n * ## Why it imports nothing, not even from this package\n *\n * Hosts INLINE both files into one script scope (Astro's `injectScript`\n * concatenates them), so anything this module pulled in would be declared twice\n * and the build would fail with `Identifier … has already been declared`. The\n * handshake is therefore a global plus an event, both deliberately named, and\n * the whole file is wrapped so it declares nothing at the top level.\n */\n\n(() => {\n const g = globalThis as {\n __dgmoReferenceRenderer?: () => Promise<unknown>;\n dispatchEvent?: (event: Event) => boolean;\n };\n\n g.__dgmoReferenceRenderer = () => import('@diagrammo/dgmo/block');\n\n // The base client has almost certainly already made its pass and found no\n // renderer. Tell it to look again, so a diagram that moved is swapped on this\n // load rather than the next one.\n if (typeof Event === 'function' && typeof g.dispatchEvent === 'function') {\n g.dispatchEvent(new Event('dgmo:renderer-ready'));\n }\n})();\n"],"mappings":";;;CA+BC,MAAM;AACL,QAAM,IAAI;AAKV,IAAE,0BAA0B,MAAM,OAAO,uBAAuB;AAKhE,MAAI,OAAO,UAAU,cAAc,OAAO,EAAE,kBAAkB,YAAY;AACxE,MAAE,cAAc,IAAI,MAAM,qBAAqB,CAAC;EAClD;AACF,GAAG;","names":[]}
|
package/dist/config.d.ts
CHANGED
|
@@ -49,5 +49,7 @@ interface WithDgmoOptions {
|
|
|
49
49
|
* prepends `remarkDgmo` to the function's eventual output.
|
|
50
50
|
*/
|
|
51
51
|
declare function withDgmo(nextraConfig?: NextraConfig, options?: WithDgmoOptions): NextraConfig;
|
|
52
|
+
/** Test seam: reset the once-per-process notice. */
|
|
53
|
+
declare function resetRenderClientNotice(): void;
|
|
52
54
|
|
|
53
|
-
export { type NextraConfig, type RemarkPlugin, type RemarkPluginsArray, type RemarkPluginsField, type RemarkPluginsFn, type WithDgmoOptions, withDgmo };
|
|
55
|
+
export { type NextraConfig, type RemarkPlugin, type RemarkPluginsArray, type RemarkPluginsField, type RemarkPluginsFn, type WithDgmoOptions, resetRenderClientNotice, withDgmo };
|
package/dist/config.js
CHANGED
package/dist/index.js
CHANGED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Nextra-shaped client wrapper for `remark-dgmo`'s framework-neutral
|
|
3
|
+
* `bindDgmo()` function. Drop this once inside your `app/layout.tsx`
|
|
4
|
+
* (typically alongside Nextra's layout) and it will:
|
|
5
|
+
*
|
|
6
|
+
* - run `bindDgmo()` on initial mount, tightening every diagram's
|
|
7
|
+
* viewBox to content bounds and wiring showcase-mode copy buttons;
|
|
8
|
+
* - re-run `bindDgmo()` on every client-side route change (Next's
|
|
9
|
+
* app router does not refire `DOMContentLoaded` semantics on soft
|
|
10
|
+
* navigation).
|
|
11
|
+
*
|
|
12
|
+
* Lives in this package — not in `remark-dgmo` — so that Next's `'use
|
|
13
|
+
* client'` directive and `next/navigation` import stay out of the
|
|
14
|
+
* framework-agnostic core.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
declare function DgmoClient(): null;
|
|
18
|
+
|
|
19
|
+
export { DgmoClient, DgmoClient as default };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
"use client";
|
|
3
|
+
|
|
4
|
+
// src/nextra-render-client.tsx
|
|
5
|
+
import { useEffect } from "react";
|
|
6
|
+
function DgmoRenderClient() {
|
|
7
|
+
useEffect(() => {
|
|
8
|
+
void import("./client-render-HT3VPJJS.js");
|
|
9
|
+
}, []);
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
var nextra_render_client_default = DgmoRenderClient;
|
|
13
|
+
export {
|
|
14
|
+
DgmoRenderClient,
|
|
15
|
+
nextra_render_client_default as default
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=nextra-render-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/nextra-render-client.tsx"],"sourcesContent":["/**\n * The opt-in half of live links: re-draw a diagram that has moved since your\n * last build, in the reader's browser, instead of only linking to the new\n * version.\n *\n * Mount it once, next to `<DgmoClient />`, and only if you also set\n * `liveLink: { refresh: 'render' }` in `next.config.mjs` — the two halves are\n * one decision:\n *\n * ```tsx\n * import { DgmoClient } from 'nextra-dgmo/client';\n * import { DgmoRenderClient } from 'nextra-dgmo/client-render';\n *\n * <body>\n * <DgmoClient />\n * <DgmoRenderClient />\n * {children}\n * </body>\n * ```\n *\n * ## Why it is a second component rather than a prop on the first\n *\n * Because the cost lands on your build whether or not the prop is ever set. A\n * bundler resolves a static-analyzable dynamic `import()` at BUILD time —\n * \"lazy\" says when the reader downloads the renderer, never whether your site\n * ships it. Naming the renderer from a module every consumer already imports\n * would pull its graph into every consumer's build. Kept in a module nobody\n * imports by default, a bundler can decline to follow it.\n *\n * ## Why the import is inside the component\n *\n * `remark-dgmo/client-render.js` exports nothing — it registers a renderer by\n * running — so `import 'remark-dgmo/client-render.js'` is a side-effect import,\n * which any bundler honouring that package's `sideEffects` field may delete\n * outright. Measured with esbuild against remark-dgmo 0.14.0 on 2026-08-06: 75\n * bytes of output, zero registrations, no error. A dynamic import is a call that\n * produces a value, so it survives, and Next emits the renderer as its own chunk\n * fetched only when a diagram has actually changed.\n */\n'use client';\n\nimport { useEffect } from 'react';\n\nexport function DgmoRenderClient(): null {\n useEffect(() => {\n // Registering twice is harmless — the module sets one global and announces\n // itself — but there is no reason to re-run it on every navigation, so this\n // effect deliberately has no dependencies.\n void import('remark-dgmo/client-render.js');\n }, []);\n\n return null;\n}\n\nexport default DgmoRenderClient;\n"],"mappings":";;;;AAyCA,SAAS,iBAAiB;AAEnB,SAAS,mBAAyB;AACvC,YAAU,MAAM;AAId,SAAK,OAAO,6BAA8B;AAAA,EAC5C,GAAG,CAAC,CAAC;AAEL,SAAO;AACT;AAEA,IAAO,+BAAQ;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nextra-dgmo",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.2",
|
|
4
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
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -48,6 +48,11 @@
|
|
|
48
48
|
"import": "./dist/nextra-client.js",
|
|
49
49
|
"default": "./dist/nextra-client.js"
|
|
50
50
|
},
|
|
51
|
+
"./client-render": {
|
|
52
|
+
"types": "./dist/nextra-render-client.d.ts",
|
|
53
|
+
"import": "./dist/nextra-render-client.js",
|
|
54
|
+
"default": "./dist/nextra-render-client.js"
|
|
55
|
+
},
|
|
51
56
|
"./client.css": "./dist/client.css"
|
|
52
57
|
},
|
|
53
58
|
"files": [
|
|
@@ -61,7 +66,7 @@
|
|
|
61
66
|
},
|
|
62
67
|
"scripts": {
|
|
63
68
|
"build": "tsup && node scripts/build-css.mjs",
|
|
64
|
-
"postbuild": "test -f dist/client.css && test -f dist/nextra-client.js",
|
|
69
|
+
"postbuild": "test -f dist/client.css && test -f dist/nextra-client.js && test -f dist/nextra-render-client.js",
|
|
65
70
|
"dev": "tsup --watch",
|
|
66
71
|
"typecheck": "tsc --noEmit",
|
|
67
72
|
"pretest": "pnpm build",
|
|
@@ -1 +0,0 @@
|
|
|
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":[]}
|