nextra-dgmo 0.1.0 → 0.2.1
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/dist/client.css +242 -65
- package/dist/nextra-client.js +1 -1
- package/dist/nextra-client.js.map +1 -1
- package/package.json +6 -6
package/dist/client.css
CHANGED
|
@@ -6,11 +6,11 @@
|
|
|
6
6
|
* change scripts/build-css.mjs instead.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
/*
|
|
10
|
-
* Override the
|
|
11
|
-
*
|
|
9
|
+
/* @diagrammo/dgmo block — standard embed chrome.
|
|
10
|
+
* Override the html.dark selectors if your site uses .dark or
|
|
11
|
+
* another color-mode convention. */
|
|
12
12
|
|
|
13
|
-
/* === Color-mode visibility === */
|
|
13
|
+
/* === Color-mode visibility (dual-render) === */
|
|
14
14
|
.dgmo-dark {
|
|
15
15
|
display: none;
|
|
16
16
|
}
|
|
@@ -22,13 +22,8 @@ html.dark .dgmo-dark {
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
/* === Diagram sizing ===
|
|
25
|
-
* SVGs are emitted with viewBox only (no fixed width/height). Force them
|
|
26
|
-
*
|
|
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. */
|
|
25
|
+
* SVGs are emitted with viewBox only (no fixed width/height). Force them to
|
|
26
|
+
* fill their wrapper so light and dark variants render at identical sizes. */
|
|
32
27
|
.dgmo-light > svg,
|
|
33
28
|
.dgmo-dark > svg,
|
|
34
29
|
.dgmo-svg > svg {
|
|
@@ -38,84 +33,266 @@ html.dark .dgmo-dark {
|
|
|
38
33
|
max-width: 100%;
|
|
39
34
|
}
|
|
40
35
|
|
|
41
|
-
/* ===
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
.
|
|
46
|
-
|
|
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
|
-
}
|
|
36
|
+
/* === Toolbar ===
|
|
37
|
+
* The diagram is the star: the toolbar is a slim reserved row below the SVG
|
|
38
|
+
* (height always in flow — no layout shift) that stays fully transparent
|
|
39
|
+
* until the block is hovered or focused, or the source panel is open. It is
|
|
40
|
+
* the <summary> of the source <details>, so toggling works without any JS.
|
|
41
|
+
* No text labels, no disclosure triangle — three wordless icon buttons. */
|
|
67
42
|
.dgmo-source-wrap {
|
|
68
|
-
|
|
43
|
+
margin: 0;
|
|
69
44
|
}
|
|
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
45
|
.dgmo-toolbar {
|
|
73
46
|
display: flex;
|
|
74
47
|
align-items: center;
|
|
75
|
-
justify-content:
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
48
|
+
justify-content: flex-end;
|
|
49
|
+
gap: 0.25em;
|
|
50
|
+
min-height: 1.9em;
|
|
51
|
+
padding: 0.15em 0;
|
|
52
|
+
opacity: 0;
|
|
53
|
+
transition: opacity 0.15s ease;
|
|
81
54
|
cursor: pointer;
|
|
82
55
|
list-style: none;
|
|
83
56
|
user-select: none;
|
|
57
|
+
color: rgba(127, 127, 127, 0.9);
|
|
84
58
|
}
|
|
85
59
|
.dgmo-toolbar::-webkit-details-marker {
|
|
86
60
|
display: none;
|
|
87
61
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
.dgmo-
|
|
94
|
-
|
|
95
|
-
|
|
62
|
+
/* Reveal is keyed to the diagram IMAGE (the svg wrappers), not the whole
|
|
63
|
+
* figure — hovering the open code panel keeps the page quiet. The toolbar's
|
|
64
|
+
* own :hover keeps it alive while the pointer travels down from the image
|
|
65
|
+
* (they're adjacent, so there's no dead gap). focus-within covers keyboard
|
|
66
|
+
* and touch-tap. */
|
|
67
|
+
.dgmo-light:hover ~ .dgmo-source-wrap > .dgmo-toolbar,
|
|
68
|
+
.dgmo-dark:hover ~ .dgmo-source-wrap > .dgmo-toolbar,
|
|
69
|
+
.dgmo-svg:hover ~ .dgmo-source-wrap > .dgmo-toolbar,
|
|
70
|
+
.dgmo-toolbar:hover,
|
|
71
|
+
.dgmo:focus-within .dgmo-toolbar {
|
|
72
|
+
opacity: 1;
|
|
96
73
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
.dgmo-toolbar
|
|
101
|
-
|
|
102
|
-
|
|
74
|
+
/* Touch devices have no hover: keep the icons faintly visible so the
|
|
75
|
+
* affordance is discoverable at all. */
|
|
76
|
+
@media (hover: none) {
|
|
77
|
+
.dgmo-toolbar {
|
|
78
|
+
opacity: 0.5;
|
|
79
|
+
}
|
|
103
80
|
}
|
|
81
|
+
|
|
82
|
+
.dgmo-toggle,
|
|
104
83
|
.dgmo-toolbar-btn {
|
|
84
|
+
display: inline-flex;
|
|
85
|
+
align-items: center;
|
|
86
|
+
justify-content: center;
|
|
87
|
+
width: 1.9em;
|
|
88
|
+
height: 1.9em;
|
|
89
|
+
border-radius: 0.35em;
|
|
105
90
|
background: none;
|
|
106
91
|
border: 0;
|
|
107
|
-
padding: 0
|
|
92
|
+
padding: 0;
|
|
108
93
|
color: inherit;
|
|
109
94
|
cursor: pointer;
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
95
|
+
opacity: 0.75;
|
|
96
|
+
transition:
|
|
97
|
+
opacity 0.15s ease,
|
|
98
|
+
background-color 0.15s ease;
|
|
114
99
|
}
|
|
100
|
+
.dgmo-toggle:hover,
|
|
115
101
|
.dgmo-toolbar-btn:hover {
|
|
116
102
|
opacity: 1;
|
|
103
|
+
background: rgba(127, 127, 127, 0.12);
|
|
104
|
+
}
|
|
105
|
+
.dgmo-toggle svg,
|
|
106
|
+
.dgmo-toolbar-btn svg {
|
|
107
|
+
width: 1em;
|
|
108
|
+
height: 1em;
|
|
109
|
+
}
|
|
110
|
+
/* Active state while the source panel is open. */
|
|
111
|
+
.dgmo-source-wrap[open] > .dgmo-toolbar .dgmo-toggle {
|
|
112
|
+
opacity: 1;
|
|
113
|
+
background: rgba(127, 127, 127, 0.15);
|
|
117
114
|
}
|
|
118
115
|
.dgmo-copy--success {
|
|
119
116
|
color: #5cba7a;
|
|
120
117
|
opacity: 1;
|
|
121
118
|
}
|
|
119
|
+
|
|
120
|
+
/* === Open state: frame the whole block ===
|
|
121
|
+
* When the source panel is open, diagram + toolbar + code get one shared
|
|
122
|
+
* border so the code visibly belongs to the chart above it, not to the
|
|
123
|
+
* surrounding prose. Closed blocks stay frameless. */
|
|
124
|
+
.dgmo:has(> .dgmo-source-wrap[open]) {
|
|
125
|
+
border: 1px solid rgba(127, 127, 127, 0.3);
|
|
126
|
+
border-radius: 0.6em;
|
|
127
|
+
padding: 0.75em 0.75em 0.5em;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/* === Source panel (hidden until toggled) === */
|
|
131
|
+
.dgmo-source-inner {
|
|
132
|
+
border-top: 1px solid rgba(127, 127, 127, 0.25);
|
|
133
|
+
background: rgba(127, 127, 127, 0.06);
|
|
134
|
+
overflow: hidden;
|
|
135
|
+
margin: 0 -0.75em -0.5em;
|
|
136
|
+
border-radius: 0 0 0.6em 0.6em;
|
|
137
|
+
}
|
|
138
|
+
.dgmo-pre {
|
|
139
|
+
white-space: pre;
|
|
140
|
+
overflow-x: auto;
|
|
141
|
+
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
|
|
142
|
+
font-size: 0.85em;
|
|
143
|
+
line-height: 1.5;
|
|
144
|
+
margin: 0;
|
|
145
|
+
padding: 1em;
|
|
146
|
+
}
|
|
147
|
+
.dgmo-code {
|
|
148
|
+
display: block;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/* === Error card === */
|
|
152
|
+
.dgmo--error {
|
|
153
|
+
border: 1px solid rgba(220, 80, 80, 0.5);
|
|
154
|
+
border-radius: 0.5em;
|
|
155
|
+
padding: 0.75em 1em;
|
|
156
|
+
}
|
|
157
|
+
.dgmo--error pre {
|
|
158
|
+
white-space: pre;
|
|
159
|
+
overflow-x: auto;
|
|
160
|
+
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
|
|
161
|
+
font-size: 0.85em;
|
|
162
|
+
margin: 0.5em 0 0;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/* === Source highlight roles ===
|
|
166
|
+
* Light values mirror LIGHT_ROLE_STYLES; dark overrides mirror
|
|
167
|
+
* NORD_ROLE_STYLES. Guarded by the parity test in tests/block.test.ts. */
|
|
168
|
+
.dgmo-tok-keyword {
|
|
169
|
+
color: #3b6ea5;
|
|
170
|
+
font-weight: bold;
|
|
171
|
+
}
|
|
172
|
+
.dgmo-tok-controlKeyword {
|
|
173
|
+
color: #7d5ba6;
|
|
174
|
+
font-weight: bold;
|
|
175
|
+
}
|
|
176
|
+
.dgmo-tok-definitionKeyword {
|
|
177
|
+
color: #2f5a86;
|
|
178
|
+
font-weight: bold;
|
|
179
|
+
}
|
|
180
|
+
.dgmo-tok-modifier {
|
|
181
|
+
color: #7d5ba6;
|
|
182
|
+
}
|
|
183
|
+
.dgmo-tok-chartType {
|
|
184
|
+
color: #b8691f;
|
|
185
|
+
font-weight: bold;
|
|
186
|
+
}
|
|
187
|
+
.dgmo-tok-operator {
|
|
188
|
+
color: #c0504d;
|
|
189
|
+
font-weight: bold;
|
|
190
|
+
}
|
|
191
|
+
.dgmo-tok-number {
|
|
192
|
+
color: #7d5ba6;
|
|
193
|
+
}
|
|
194
|
+
.dgmo-tok-comment {
|
|
195
|
+
color: #677483;
|
|
196
|
+
font-style: italic;
|
|
197
|
+
}
|
|
198
|
+
.dgmo-tok-heading {
|
|
199
|
+
color: #b8691f;
|
|
200
|
+
font-weight: bold;
|
|
201
|
+
}
|
|
202
|
+
.dgmo-tok-bracket {
|
|
203
|
+
color: #5b6672;
|
|
204
|
+
}
|
|
205
|
+
.dgmo-tok-separator {
|
|
206
|
+
color: #2d7268;
|
|
207
|
+
}
|
|
208
|
+
.dgmo-tok-deprecatedSyntax {
|
|
209
|
+
color: #c0504d;
|
|
210
|
+
text-decoration: line-through;
|
|
211
|
+
}
|
|
212
|
+
.dgmo-tok-url {
|
|
213
|
+
color: #3b6ea5;
|
|
214
|
+
text-decoration: underline;
|
|
215
|
+
}
|
|
216
|
+
.dgmo-tok-colorAnnotation {
|
|
217
|
+
color: #b8691f;
|
|
218
|
+
font-style: italic;
|
|
219
|
+
}
|
|
220
|
+
.dgmo-tok-punctuation {
|
|
221
|
+
color: #677483;
|
|
222
|
+
}
|
|
223
|
+
.dgmo-tok-propertyName {
|
|
224
|
+
color: #2d7268;
|
|
225
|
+
}
|
|
226
|
+
.dgmo-tok-string {
|
|
227
|
+
color: #3f7a3b;
|
|
228
|
+
}
|
|
229
|
+
.dgmo-tok-noteContent {
|
|
230
|
+
color: #677483;
|
|
231
|
+
font-style: italic;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
html.dark .dgmo-tok-keyword {
|
|
235
|
+
color: #81a1c1;
|
|
236
|
+
font-weight: bold;
|
|
237
|
+
}
|
|
238
|
+
html.dark .dgmo-tok-controlKeyword {
|
|
239
|
+
color: #b48ead;
|
|
240
|
+
font-weight: bold;
|
|
241
|
+
}
|
|
242
|
+
html.dark .dgmo-tok-definitionKeyword {
|
|
243
|
+
color: #5e81ac;
|
|
244
|
+
font-weight: bold;
|
|
245
|
+
}
|
|
246
|
+
html.dark .dgmo-tok-modifier {
|
|
247
|
+
color: #b48ead;
|
|
248
|
+
}
|
|
249
|
+
html.dark .dgmo-tok-chartType {
|
|
250
|
+
color: #d08770;
|
|
251
|
+
font-weight: bold;
|
|
252
|
+
}
|
|
253
|
+
html.dark .dgmo-tok-operator {
|
|
254
|
+
color: #bf616a;
|
|
255
|
+
font-weight: bold;
|
|
256
|
+
}
|
|
257
|
+
html.dark .dgmo-tok-number {
|
|
258
|
+
color: #b48ead;
|
|
259
|
+
}
|
|
260
|
+
html.dark .dgmo-tok-comment {
|
|
261
|
+
color: #616e88;
|
|
262
|
+
font-style: italic;
|
|
263
|
+
}
|
|
264
|
+
html.dark .dgmo-tok-heading {
|
|
265
|
+
color: #d08770;
|
|
266
|
+
font-weight: bold;
|
|
267
|
+
}
|
|
268
|
+
html.dark .dgmo-tok-bracket {
|
|
269
|
+
color: #5e81ac;
|
|
270
|
+
}
|
|
271
|
+
html.dark .dgmo-tok-separator {
|
|
272
|
+
color: #88c0d0;
|
|
273
|
+
}
|
|
274
|
+
html.dark .dgmo-tok-deprecatedSyntax {
|
|
275
|
+
color: #bf616a;
|
|
276
|
+
text-decoration: line-through;
|
|
277
|
+
}
|
|
278
|
+
html.dark .dgmo-tok-url {
|
|
279
|
+
color: #88c0d0;
|
|
280
|
+
text-decoration: underline;
|
|
281
|
+
}
|
|
282
|
+
html.dark .dgmo-tok-colorAnnotation {
|
|
283
|
+
color: #d08770;
|
|
284
|
+
font-style: italic;
|
|
285
|
+
}
|
|
286
|
+
html.dark .dgmo-tok-punctuation {
|
|
287
|
+
color: #616e88;
|
|
288
|
+
}
|
|
289
|
+
html.dark .dgmo-tok-propertyName {
|
|
290
|
+
color: #88c0d0;
|
|
291
|
+
}
|
|
292
|
+
html.dark .dgmo-tok-string {
|
|
293
|
+
color: #a3be8c;
|
|
294
|
+
}
|
|
295
|
+
html.dark .dgmo-tok-noteContent {
|
|
296
|
+
color: #616e88;
|
|
297
|
+
font-style: italic;
|
|
298
|
+
}
|
package/dist/nextra-client.js
CHANGED
|
@@ -5,7 +5,7 @@ import "nextra-dgmo/client.css";
|
|
|
5
5
|
import { useEffect } from "react";
|
|
6
6
|
import { usePathname } from "next/navigation";
|
|
7
7
|
|
|
8
|
-
// node_modules/.pnpm/remark-dgmo@0.
|
|
8
|
+
// node_modules/.pnpm/remark-dgmo@0.5.1_@diagrammo+dgmo@0.47.0_@lezer+common@1.5.2_@lezer+highlight@1.2.3_@lezer+lr@1.4.10_/node_modules/remark-dgmo/dist/client.js
|
|
9
9
|
var clickHandlerBound = false;
|
|
10
10
|
var themeObserverBound = false;
|
|
11
11
|
function isInteractiveBrowser() {
|
|
@@ -1 +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":";;;AAsBA,OAAO;AACP,SAAS,iBAAiB;AAC1B,SAAS,mBAAmB;;;ACK5B,IAAI,oBAAoB;AACxB,IAAI,qBAAqB;AAEzB,SAAS,uBAAgC;AACvC,SACE,OAAO,WAAW,eAClB,OAAO,aAAa,eACpB,OAAO,qBAAqB,eAC5B,OAAO,0BAA0B;AAErC;AAEO,SAAS,WAAiB;AAC/B,MAAI,CAAC,qBAAqB,EAAG;AAE7B,MAAI,CAAC,mBAAmB;AACtB,aAAS,iBAAiB,SAAS,CAAC,MAAM;AACxC,WAAK,sBAAsB,CAAC;IAC9B,CAAC;AACD,wBAAoB;EACtB;AACA,mBAAiB;AAYjB,MAAI,CAAC,oBAAoB;AACvB,UAAM,OAAO,SAAS;AACtB,UAAM,YAAY,MAAM;AACtB,4BAAsB,MAAM,sBAAsB,gBAAgB,CAAC;IACrE;AACA,QAAI,iBAAiB,SAAS,EAAE,QAAQ,MAAM;MAC5C,YAAY;MACZ,iBAAiB,CAAC,cAAc,OAAO;IACzC,CAAC;AACD,yBAAqB;EACvB;AACF;AAEA,eAAe,sBAAsB,GAAyB;AAC5D,QAAM,SAAS,EAAE;AACjB,MAAI,CAAC,UAAU,OAAO,OAAO,YAAY,WAAY;AACrD,QAAM,MAAM,OAAO,QAAQ,mBAAmB;AAC9C,MAAI,CAAC,IAAK;AAQV,QAAM,gBAAgB,CAAC,CAAC,IAAI,QAAQ,SAAS;AAC7C,MAAI,cAAe,GAAE,eAAe;AAEpC,MAAI,IAAI,QAAQ,kBAAkB,GAAG;AACnC,UAAM,MAA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aAAS;EACX;AACF;;;ADvJO,SAAS,aAAmB;AACjC,QAAM,WAAW,YAAY;AAE7B,YAAU,MAAM;AAId,aAAS;AAAA,EACX,GAAG,CAAC,QAAQ,CAAC;AAEb,SAAO;AACT;AAEA,IAAO,wBAAQ;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/nextra-client.tsx","../node_modules/.pnpm/remark-dgmo@0.5.1_@diagrammo+dgmo@0.47.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":";;;AAsBA,OAAO;AACP,SAAS,iBAAiB;AAC1B,SAAS,mBAAmB;;;ACK5B,IAAI,oBAAoB;AACxB,IAAI,qBAAqB;AAEzB,SAAS,uBAAgC;AACvC,SACE,OAAO,WAAW,eAClB,OAAO,aAAa,eACpB,OAAO,qBAAqB,eAC5B,OAAO,0BAA0B;AAErC;AAEO,SAAS,WAAiB;AAC/B,MAAI,CAAC,qBAAqB,EAAG;AA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AW,OAAO,iBAAiB,OAAO;AAChD,UAAM,YAAY,SAAS,YAAY;AACvC,UAAM,qBAAqB,QAAQ,MAAM;AACzC,QAAI,WAAW;AACb,cAAQ,MAAM,UAAU;AAKxB,WAAK,QAAQ;IACf;AAEA,QAAI;AACF,YAAM,OAAQ,IAAsC,QAAQ;AAC5D,UAAI,KAAK,QAAQ,KAAK,KAAK,SAAS,GAAG;AACrC,cAAM,MAAM;AACZ,YAAI;UACF;UACA,GAAG,KAAK,IAAI,GAAG,IAAI,KAAK,IAAI,GAAG,IAAI,KAAK,QAAQ,MAAM,CAAC,IACrD,KAAK,SAAS,MAAM,CACtB;QACF;MACF;IACF,QAAQ;IAER;AAEA,QAAI,WAAW;AACb,cAAQ,MAAM,UAAU;AAOxB,UAAI,uBAAuB,MAAM,QAAQ,aAAa,OAAO,MAAM,IAAI;AACrE,gBAAQ,gBAAgB,OAAO;MACjC;IACF;EACF,CAAC;AACH;AAKA,IAAI,qBAAqB,GAAG;AAC1B,MAAI,SAAS,eAAe,WAAW;AACrC,aAAS,iBAAiB,oBAAoB,QAAQ;EACxD,OAAO;AACL,aAAS;EACX;AACF;;;ADvJO,SAAS,aAAmB;AACjC,QAAM,WAAW,YAAY;AAE7B,YAAU,MAAM;AAId,aAAS;AAAA,EACX,GAAG,CAAC,QAAQ,CAAC;AAEb,SAAO;AACT;AAEA,IAAO,wBAAQ;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nextra-dgmo",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
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": {
|
|
@@ -78,7 +78,7 @@
|
|
|
78
78
|
"prepublishOnly": "pnpm build && pnpm test"
|
|
79
79
|
},
|
|
80
80
|
"peerDependencies": {
|
|
81
|
-
"@diagrammo/dgmo": "
|
|
81
|
+
"@diagrammo/dgmo": ">=0.45.0 <1",
|
|
82
82
|
"next": "^15.0.0 || ^16.0.0",
|
|
83
83
|
"nextra": "^4.0.0",
|
|
84
84
|
"react": "^19.0.0"
|
|
@@ -95,20 +95,20 @@
|
|
|
95
95
|
}
|
|
96
96
|
},
|
|
97
97
|
"dependencies": {
|
|
98
|
-
"remark-dgmo": "^0.
|
|
98
|
+
"remark-dgmo": "^0.5.1"
|
|
99
99
|
},
|
|
100
100
|
"devDependencies": {
|
|
101
|
-
"@diagrammo/dgmo": "^0.
|
|
101
|
+
"@diagrammo/dgmo": "^0.47.0",
|
|
102
102
|
"@eslint/js": "^10.0.1",
|
|
103
103
|
"@types/node": "^22.10.0",
|
|
104
104
|
"@types/react": "^19.0.0",
|
|
105
105
|
"@vitest/coverage-v8": "^4.1.6",
|
|
106
106
|
"depcheck": "^1.4.7",
|
|
107
107
|
"eslint": "^10.4.0",
|
|
108
|
-
"next": "^16.0.0",
|
|
109
|
-
"nextra": "^4.0.0",
|
|
110
108
|
"jscpd": "^4.0.9",
|
|
111
109
|
"knip": "^6.14.1",
|
|
110
|
+
"next": "^16.0.0",
|
|
111
|
+
"nextra": "^4.0.0",
|
|
112
112
|
"prettier": "^3.8.3",
|
|
113
113
|
"react": "^19.0.0",
|
|
114
114
|
"tsup": "^8.5.1",
|