nextra-dgmo 0.2.7 → 0.2.8
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 +28 -8
- package/dist/nextra-client.js +27 -1
- package/dist/nextra-client.js.map +1 -1
- package/package.json +3 -3
package/dist/client.css
CHANGED
|
@@ -34,21 +34,25 @@ html.dark .dgmo-dark {
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
/* === Toolbar ===
|
|
37
|
-
* The diagram is the star: the toolbar is
|
|
38
|
-
* (
|
|
39
|
-
*
|
|
40
|
-
* the
|
|
37
|
+
* The diagram is the star: the toolbar is an overlay pinned to the diagram's
|
|
38
|
+
* top-right corner (position:absolute — it reserves no layout space, so the
|
|
39
|
+
* block is exactly as tall as the chart). It stays fully transparent until
|
|
40
|
+
* the block is hovered or focused, or the source panel is open. It is the
|
|
41
|
+
* <summary> of the source <details>, so toggling works without any JS.
|
|
41
42
|
* No text labels, no disclosure triangle — three wordless icon buttons. */
|
|
42
43
|
.dgmo-source-wrap {
|
|
43
44
|
margin: 0;
|
|
44
45
|
}
|
|
45
46
|
.dgmo-toolbar {
|
|
47
|
+
position: absolute;
|
|
48
|
+
top: 0.4em;
|
|
49
|
+
right: 0.4em;
|
|
50
|
+
z-index: 2;
|
|
46
51
|
display: flex;
|
|
47
52
|
align-items: center;
|
|
48
53
|
justify-content: flex-end;
|
|
49
54
|
gap: 0.25em;
|
|
50
|
-
|
|
51
|
-
padding: 0.15em 0;
|
|
55
|
+
padding: 0.15em;
|
|
52
56
|
opacity: 0;
|
|
53
57
|
transition: opacity 0.15s ease;
|
|
54
58
|
cursor: pointer;
|
|
@@ -151,6 +155,14 @@ html.dark .dgmo-dark {
|
|
|
151
155
|
overflow: auto;
|
|
152
156
|
border-radius: 0.5em;
|
|
153
157
|
box-shadow: 0 12px 48px rgba(0, 0, 0, 0.45);
|
|
158
|
+
/* Opaque surface behind the enlarged diagram so a transparent embed doesn't
|
|
159
|
+
* show the page through it. The client overrides this inline with the block's
|
|
160
|
+
* own palette bg (data-dgmo-bg); this is the fallback for blocks that predate
|
|
161
|
+
* that attribute. */
|
|
162
|
+
background: #fff;
|
|
163
|
+
}
|
|
164
|
+
html.dark .dgmo-lightbox-svg {
|
|
165
|
+
background: #1e1e1e;
|
|
154
166
|
}
|
|
155
167
|
.dgmo-lightbox-svg > svg {
|
|
156
168
|
display: block;
|
|
@@ -185,9 +197,10 @@ html.dark .dgmo-dark {
|
|
|
185
197
|
* border so the code visibly belongs to the chart above it. The frame box
|
|
186
198
|
* (border + padding) is RESERVED at all times — with the border transparent
|
|
187
199
|
* while closed — so opening the panel only paints the border in. It never
|
|
188
|
-
* reflows the diagram
|
|
189
|
-
*
|
|
200
|
+
* reflows the diagram. position:relative anchors the overlay toolbar to
|
|
201
|
+
* this box. */
|
|
190
202
|
.dgmo:has(> .dgmo-source-wrap) {
|
|
203
|
+
position: relative;
|
|
191
204
|
border: 1px solid transparent;
|
|
192
205
|
border-radius: 0.6em;
|
|
193
206
|
padding: 0.75em 0.75em 0.5em;
|
|
@@ -230,6 +243,13 @@ html.dark .dgmo-dark {
|
|
|
230
243
|
font-size: 0.85em;
|
|
231
244
|
margin: 0.5em 0 0;
|
|
232
245
|
}
|
|
246
|
+
.dgmo-error-docs {
|
|
247
|
+
display: inline-block;
|
|
248
|
+
margin-top: 0.6em;
|
|
249
|
+
font-size: 0.9em;
|
|
250
|
+
font-weight: 600;
|
|
251
|
+
color: inherit;
|
|
252
|
+
}
|
|
233
253
|
|
|
234
254
|
/* === Source highlight roles ===
|
|
235
255
|
* Light values mirror LIGHT_ROLE_STYLES; dark overrides mirror
|
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.9.0_@diagrammo+dgmo@0.51.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
|
import { startCountdowns } from "@diagrammo/dgmo/countdown";
|
|
10
10
|
import { startClocks } from "@diagrammo/dgmo/clock";
|
|
11
11
|
var clickHandlerBound = false;
|
|
@@ -23,6 +23,16 @@ function bindDgmo() {
|
|
|
23
23
|
},
|
|
24
24
|
true
|
|
25
25
|
);
|
|
26
|
+
document.addEventListener(
|
|
27
|
+
"mouseout",
|
|
28
|
+
(e) => collapseIdleSourcePanels(e.relatedTarget),
|
|
29
|
+
true
|
|
30
|
+
);
|
|
31
|
+
document.addEventListener(
|
|
32
|
+
"focusout",
|
|
33
|
+
(e) => collapseIdleSourcePanels(e.relatedTarget),
|
|
34
|
+
true
|
|
35
|
+
);
|
|
26
36
|
clickHandlerBound = true;
|
|
27
37
|
}
|
|
28
38
|
tightenViewBoxes();
|
|
@@ -42,6 +52,19 @@ function bindDgmo() {
|
|
|
42
52
|
themeObserverBound = true;
|
|
43
53
|
}
|
|
44
54
|
}
|
|
55
|
+
function collapseIdleSourcePanels(movedTo) {
|
|
56
|
+
const open = document.querySelectorAll(
|
|
57
|
+
"details.dgmo-source-wrap[open]"
|
|
58
|
+
);
|
|
59
|
+
open.forEach((d) => {
|
|
60
|
+
const block = d.closest(".dgmo");
|
|
61
|
+
if (!block) return;
|
|
62
|
+
if (movedTo && block.contains(movedTo)) return;
|
|
63
|
+
if (block.contains(document.activeElement)) return;
|
|
64
|
+
if (block.matches(":hover")) return;
|
|
65
|
+
d.open = false;
|
|
66
|
+
});
|
|
67
|
+
}
|
|
45
68
|
async function handleToolbarBtnClick(e) {
|
|
46
69
|
const target = e.target;
|
|
47
70
|
if (!target || typeof target.closest !== "function") return;
|
|
@@ -131,11 +154,13 @@ function openDgmoLightbox(fromButton) {
|
|
|
131
154
|
if (!block) return;
|
|
132
155
|
const wrappers = block.querySelectorAll(".dgmo-light, .dgmo-dark, .dgmo-svg");
|
|
133
156
|
let svg = null;
|
|
157
|
+
let bg = null;
|
|
134
158
|
for (const w of Array.from(wrappers)) {
|
|
135
159
|
if (window.getComputedStyle(w).display === "none") continue;
|
|
136
160
|
const found = w.querySelector("svg");
|
|
137
161
|
if (found) {
|
|
138
162
|
svg = found;
|
|
163
|
+
bg = w.getAttribute("data-dgmo-bg");
|
|
139
164
|
break;
|
|
140
165
|
}
|
|
141
166
|
}
|
|
@@ -153,6 +178,7 @@ function openDgmoLightbox(fromButton) {
|
|
|
153
178
|
closeBtn.innerHTML = LIGHTBOX_CLOSE_ICON;
|
|
154
179
|
const host = document.createElement("div");
|
|
155
180
|
host.className = "dgmo-lightbox-svg";
|
|
181
|
+
if (bg) host.style.background = bg;
|
|
156
182
|
host.appendChild(clone);
|
|
157
183
|
dialog.appendChild(closeBtn);
|
|
158
184
|
dialog.appendChild(host);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/nextra-client.tsx","../node_modules/.pnpm/remark-dgmo@0.8.0_@diagrammo+dgmo@0.50.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\n// Lean, zero-import ~1 KB ticker for the `countdown` chart type — the only\n// dynamic dgmo chart. Its own subpath so this client bundle never pulls the\n// render pipeline. Lights up all five remark host wrappers (Astro, Docusaurus,\n// Fumadocs, Nextra, VitePress) — they all call bindDgmo().\nimport { startCountdowns } from '@diagrammo/dgmo/countdown';\n// Same deal for the `clock` chart type — a sibling ~1 KB 1s ticker on its own\n// subpath. Updates the baked `data-dgmo-clock` analog/digital world-clock rows.\nimport { startClocks } from '@diagrammo/dgmo/clock';\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 // Capture phase, not bubble: the handler must run BEFORE any\n // framework-level click handling. Docusaurus (markdown.format 'md')\n // maps the raw <details> onto its theme Details component, whose React\n // onClick — delegated at the app root — toggles the panel for ANY click\n // inside the <summary>, including our copy/open buttons. Capturing at\n // document and stopping propagation for in-summary buttons keeps those\n // clicks ours; plain summary clicks pass through untouched so the\n // toggle (native or framework-managed) still works.\n document.addEventListener(\n 'click',\n (e) => {\n void handleToolbarBtnClick(e);\n },\n true\n );\n clickHandlerBound = true;\n }\n tightenViewBoxes();\n\n // Seed the dynamic chart types (countdown, clock) and register their 1s\n // tickers (idempotent; no-op when none are on the page). Both call\n // `window.setInterval`, so gate on it: a partial DOM can clear the\n // interactive-browser guard above yet still lack timers (some SSG runtimes).\n if (typeof window.setInterval === 'function') {\n startCountdowns();\n startClocks();\n }\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) {\n e.preventDefault();\n // Keep the click from reaching framework toggle handlers (Docusaurus's\n // Details component collapses the panel on any in-summary click).\n e.stopPropagation();\n }\n\n if (btn.matches('button.dgmo-expand')) {\n openDgmoLightbox(btn);\n return;\n }\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\n// ============================================================\n// Full-screen lightbox (expand toolbar button)\n// ============================================================\n//\n// MIRROR of the canonical helper in @diagrammo/dgmo's `auto/shared.ts`\n// (`openDgmoLightbox`), kept near-verbatim here for the same reason copy/open\n// handling is mirrored per surface. The `.dgmo-lightbox*` CSS is single-sourced\n// in dgmo's BLOCK_CSS (this package's client.css is a generated byte-copy).\n\nconst LIGHTBOX_XLINK_NS = 'http://www.w3.org/1999/xlink';\nconst LIGHTBOX_REF_ATTRS = [\n 'clip-path',\n 'mask',\n 'filter',\n 'fill',\n 'stroke',\n 'marker-start',\n 'marker-mid',\n 'marker-end',\n];\nlet lightboxIdSeq = 0;\n\nconst LIGHTBOX_CLOSE_ICON =\n '<svg width=\"20\" height=\"20\" viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.6\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\"><path d=\"m4 4 8 8\"/><path d=\"m12 4-8 8\"/></svg>';\n\n/**\n * Namespace a cloned SVG's ids + internal `url(#id)`/`href=\"#id\"` refs so the\n * clone can't clash with the still-mounted inline copy (WebKit resolves\n * duplicate ids to the first match, corrupting gradients/clips/masks).\n */\nfunction namespaceLightboxSvgIds(root: SVGElement, prefix: string): void {\n const map = new Map<string, string>();\n root.querySelectorAll('[id]').forEach((el) => {\n const oldId = el.getAttribute('id');\n if (!oldId) return;\n const newId = prefix + oldId;\n map.set(oldId, newId);\n el.setAttribute('id', newId);\n });\n if (map.size === 0) return;\n const remap = (value: string): string =>\n value.replace(/url\\(#([^)]+)\\)/g, (m, id: string) => {\n const next = map.get(id);\n return next ? `url(#${next})` : m;\n });\n root.querySelectorAll('*').forEach((el) => {\n for (const attr of LIGHTBOX_REF_ATTRS) {\n const v = el.getAttribute(attr);\n if (v && v.includes('url(#')) el.setAttribute(attr, remap(v));\n }\n const style = el.getAttribute('style');\n if (style && style.includes('url(#'))\n el.setAttribute('style', remap(style));\n const href = el.getAttribute('href');\n if (href && href.startsWith('#') && map.has(href.slice(1)))\n el.setAttribute('href', '#' + map.get(href.slice(1)));\n const xhref = el.getAttributeNS(LIGHTBOX_XLINK_NS, 'href');\n if (xhref && xhref.startsWith('#') && map.has(xhref.slice(1)))\n el.setAttributeNS(\n LIGHTBOX_XLINK_NS,\n 'href',\n '#' + map.get(xhref.slice(1))\n );\n });\n}\n\n/**\n * Open the diagram belonging to `fromButton`'s block in a full-viewport\n * `<dialog>` lightbox: clone the currently-visible color-mode SVG, namespace\n * its ids, then `showModal()`. Escape / backdrop-click / close button dismiss.\n */\nfunction openDgmoLightbox(fromButton: Element): void {\n if (typeof document === 'undefined') return;\n const block = fromButton.closest('.dgmo');\n if (!block) return;\n\n const wrappers = block.querySelectorAll('.dgmo-light, .dgmo-dark, .dgmo-svg');\n let svg: SVGSVGElement | null = null;\n for (const w of Array.from(wrappers)) {\n if (window.getComputedStyle(w).display === 'none') continue;\n const found = w.querySelector('svg');\n if (found) {\n svg = found as SVGSVGElement;\n break;\n }\n }\n if (!svg) svg = block.querySelector('svg');\n if (!svg) return;\n\n const clone = svg.cloneNode(true) as SVGSVGElement;\n namespaceLightboxSvgIds(clone, `dgmo-lb-${++lightboxIdSeq}-`);\n\n const dialog = document.createElement('dialog');\n dialog.className = 'dgmo-lightbox';\n dialog.setAttribute('aria-label', 'Diagram, full screen');\n\n const closeBtn = document.createElement('button');\n closeBtn.type = 'button';\n closeBtn.className = 'dgmo-lightbox-close';\n closeBtn.setAttribute('aria-label', 'Close full screen');\n closeBtn.innerHTML = LIGHTBOX_CLOSE_ICON;\n\n const host = document.createElement('div');\n host.className = 'dgmo-lightbox-svg';\n host.appendChild(clone);\n\n dialog.appendChild(closeBtn);\n dialog.appendChild(host);\n document.body.appendChild(dialog);\n\n const close = (): void => {\n if (dialog.open) dialog.close();\n };\n closeBtn.addEventListener('click', close);\n dialog.addEventListener('click', (e) => {\n if (e.target === dialog) close();\n });\n dialog.addEventListener('close', () => dialog.remove());\n dialog.showModal();\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;;;ACS5B,SAAS,uBAAuB;AAGhC,SAAS,mBAAmB;AAE5B,IAAI,oBAAoB;AACxB,IAAI,qBAAqB;AAEzB,SAAS,uBAAgC;AACvC,SACE,OAAO,WAAW,eAClB,OAAO,aAAa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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\n// Lean, zero-import ~1 KB ticker for the `countdown` chart type — the only\n// dynamic dgmo chart. Its own subpath so this client bundle never pulls the\n// render pipeline. Lights up all five remark host wrappers (Astro, Docusaurus,\n// Fumadocs, Nextra, VitePress) — they all call bindDgmo().\nimport { startCountdowns } from '@diagrammo/dgmo/countdown';\n// Same deal for the `clock` chart type — a sibling ~1 KB 1s ticker on its own\n// subpath. Updates the baked `data-dgmo-clock` analog/digital world-clock rows.\nimport { startClocks } from '@diagrammo/dgmo/clock';\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 // Capture phase, not bubble: the handler must run BEFORE any\n // framework-level click handling. Docusaurus (markdown.format 'md')\n // maps the raw <details> onto its theme Details component, whose React\n // onClick — delegated at the app root — toggles the panel for ANY click\n // inside the <summary>, including our copy/open buttons. Capturing at\n // document and stopping propagation for in-summary buttons keeps those\n // clicks ours; plain summary clicks pass through untouched so the\n // toggle (native or framework-managed) still works.\n document.addEventListener(\n 'click',\n (e) => {\n void handleToolbarBtnClick(e);\n },\n true\n );\n // Auto-collapse an open source panel once the pointer AND focus have both\n // left the block — the expanded code shouldn't linger after you move on.\n // Delegated (the click handler is document-level too); `relatedTarget` is\n // where the pointer/focus went, so a move to a child of the same block\n // keeps it open.\n document.addEventListener(\n 'mouseout',\n (e) =>\n collapseIdleSourcePanels((e as MouseEvent).relatedTarget as Node | null),\n true\n );\n document.addEventListener(\n 'focusout',\n (e) =>\n collapseIdleSourcePanels((e as FocusEvent).relatedTarget as Node | null),\n true\n );\n clickHandlerBound = true;\n }\n tightenViewBoxes();\n\n // Seed the dynamic chart types (countdown, clock) and register their 1s\n // tickers (idempotent; no-op when none are on the page). Both call\n // `window.setInterval`, so gate on it: a partial DOM can clear the\n // interactive-browser guard above yet still lack timers (some SSG runtimes).\n if (typeof window.setInterval === 'function') {\n startCountdowns();\n startClocks();\n }\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\n/**\n * Close any open `<details.dgmo-source-wrap>` whose block is no longer under\n * the pointer and holds no focus. `movedTo` is the event's relatedTarget (the\n * element the pointer/focus moved to); staying within the same block is a\n * no-op. Belt-and-suspenders with `:hover` + `activeElement` so a mouse-out\n * that still leaves focus inside (or vice-versa) keeps the panel open.\n */\nfunction collapseIdleSourcePanels(movedTo: Node | null): void {\n const open = document.querySelectorAll<HTMLDetailsElement>(\n 'details.dgmo-source-wrap[open]'\n );\n open.forEach((d) => {\n const block = d.closest('.dgmo');\n if (!block) return;\n if (movedTo && block.contains(movedTo)) return;\n if (block.contains(document.activeElement)) return;\n if (block.matches(':hover')) return;\n d.open = false;\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) {\n e.preventDefault();\n // Keep the click from reaching framework toggle handlers (Docusaurus's\n // Details component collapses the panel on any in-summary click).\n e.stopPropagation();\n }\n\n if (btn.matches('button.dgmo-expand')) {\n openDgmoLightbox(btn);\n return;\n }\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\n// ============================================================\n// Full-screen lightbox (expand toolbar button)\n// ============================================================\n//\n// MIRROR of the canonical helper in @diagrammo/dgmo's `auto/shared.ts`\n// (`openDgmoLightbox`), kept near-verbatim here for the same reason copy/open\n// handling is mirrored per surface. The `.dgmo-lightbox*` CSS is single-sourced\n// in dgmo's BLOCK_CSS (this package's client.css is a generated byte-copy).\n\nconst LIGHTBOX_XLINK_NS = 'http://www.w3.org/1999/xlink';\nconst LIGHTBOX_REF_ATTRS = [\n 'clip-path',\n 'mask',\n 'filter',\n 'fill',\n 'stroke',\n 'marker-start',\n 'marker-mid',\n 'marker-end',\n];\nlet lightboxIdSeq = 0;\n\nconst LIGHTBOX_CLOSE_ICON =\n '<svg width=\"20\" height=\"20\" viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.6\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\"><path d=\"m4 4 8 8\"/><path d=\"m12 4-8 8\"/></svg>';\n\n/**\n * Namespace a cloned SVG's ids + internal `url(#id)`/`href=\"#id\"` refs so the\n * clone can't clash with the still-mounted inline copy (WebKit resolves\n * duplicate ids to the first match, corrupting gradients/clips/masks).\n */\nfunction namespaceLightboxSvgIds(root: SVGElement, prefix: string): void {\n const map = new Map<string, string>();\n root.querySelectorAll('[id]').forEach((el) => {\n const oldId = el.getAttribute('id');\n if (!oldId) return;\n const newId = prefix + oldId;\n map.set(oldId, newId);\n el.setAttribute('id', newId);\n });\n if (map.size === 0) return;\n const remap = (value: string): string =>\n value.replace(/url\\(#([^)]+)\\)/g, (m, id: string) => {\n const next = map.get(id);\n return next ? `url(#${next})` : m;\n });\n root.querySelectorAll('*').forEach((el) => {\n for (const attr of LIGHTBOX_REF_ATTRS) {\n const v = el.getAttribute(attr);\n if (v && v.includes('url(#')) el.setAttribute(attr, remap(v));\n }\n const style = el.getAttribute('style');\n if (style && style.includes('url(#'))\n el.setAttribute('style', remap(style));\n const href = el.getAttribute('href');\n if (href && href.startsWith('#') && map.has(href.slice(1)))\n el.setAttribute('href', '#' + map.get(href.slice(1)));\n const xhref = el.getAttributeNS(LIGHTBOX_XLINK_NS, 'href');\n if (xhref && xhref.startsWith('#') && map.has(xhref.slice(1)))\n el.setAttributeNS(\n LIGHTBOX_XLINK_NS,\n 'href',\n '#' + map.get(xhref.slice(1))\n );\n });\n}\n\n/**\n * Open the diagram belonging to `fromButton`'s block in a full-viewport\n * `<dialog>` lightbox: clone the currently-visible color-mode SVG, namespace\n * its ids, then `showModal()`. Escape / backdrop-click / close button dismiss.\n */\nfunction openDgmoLightbox(fromButton: Element): void {\n if (typeof document === 'undefined') return;\n const block = fromButton.closest('.dgmo');\n if (!block) return;\n\n const wrappers = block.querySelectorAll('.dgmo-light, .dgmo-dark, .dgmo-svg');\n let svg: SVGSVGElement | null = null;\n let bg: string | null = null;\n for (const w of Array.from(wrappers)) {\n if (window.getComputedStyle(w).display === 'none') continue;\n const found = w.querySelector('svg');\n if (found) {\n svg = found as SVGSVGElement;\n bg = w.getAttribute('data-dgmo-bg');\n break;\n }\n }\n if (!svg) svg = block.querySelector('svg');\n if (!svg) return;\n\n const clone = svg.cloneNode(true) as SVGSVGElement;\n namespaceLightboxSvgIds(clone, `dgmo-lb-${++lightboxIdSeq}-`);\n\n const dialog = document.createElement('dialog');\n dialog.className = 'dgmo-lightbox';\n dialog.setAttribute('aria-label', 'Diagram, full screen');\n\n const closeBtn = document.createElement('button');\n closeBtn.type = 'button';\n closeBtn.className = 'dgmo-lightbox-close';\n closeBtn.setAttribute('aria-label', 'Close full screen');\n closeBtn.innerHTML = LIGHTBOX_CLOSE_ICON;\n\n const host = document.createElement('div');\n host.className = 'dgmo-lightbox-svg';\n // Always paint an opaque surface behind the enlarged diagram — transparent\n // embeds strip the chart bg from the SVG, so without this the page shows\n // through the expanded view. Use the block's own palette bg when stashed.\n if (bg) host.style.background = bg;\n host.appendChild(clone);\n\n dialog.appendChild(closeBtn);\n dialog.appendChild(host);\n document.body.appendChild(dialog);\n\n const close = (): void => {\n if (dialog.open) dialog.close();\n };\n closeBtn.addEventListener('click', close);\n dialog.addEventListener('click', (e) => {\n if (e.target === dialog) close();\n });\n dialog.addEventListener('close', () => dialog.remove());\n dialog.showModal();\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,iBA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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;;;ADpWO,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.2.
|
|
3
|
+
"version": "0.2.8",
|
|
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": {
|
|
@@ -95,10 +95,10 @@
|
|
|
95
95
|
}
|
|
96
96
|
},
|
|
97
97
|
"dependencies": {
|
|
98
|
-
"remark-dgmo": "^0.
|
|
98
|
+
"remark-dgmo": "^0.9.0"
|
|
99
99
|
},
|
|
100
100
|
"devDependencies": {
|
|
101
|
-
"@diagrammo/dgmo": "
|
|
101
|
+
"@diagrammo/dgmo": "^0.51.0",
|
|
102
102
|
"@eslint/js": "^10.0.1",
|
|
103
103
|
"@types/node": "^22.10.0",
|
|
104
104
|
"@types/react": "^19.0.0",
|