remark-dgmo 0.1.3 → 0.1.4

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.
@@ -134,12 +134,114 @@ function normalizeSvg(input) {
134
134
  svg = svg.replace(/<svg/, `<svg viewBox="0 0 ${wh[1]} ${wh[2]}"`);
135
135
  }
136
136
  }
137
+ const tight = computeBBox(svg);
138
+ if (tight && tight.width > 0 && tight.height > 0) {
139
+ const pad = 16;
140
+ const vb = `${tight.x - pad} ${tight.y - pad} ${tight.width + pad * 2} ${tight.height + pad * 2}`;
141
+ svg = svg.replace(/(<svg[^>]*?)viewBox="[^"]*"/, `$1viewBox="${vb}"`);
142
+ }
137
143
  svg = svg.replace(/(<svg[^>]*?) width="[^"]*"/g, "$1");
138
144
  svg = svg.replace(/(<svg[^>]*?) height="[^"]*"/g, "$1");
139
145
  svg = svg.replace(/(<svg[^>]*?style="[^"]*?)background:[^;"]*;?\s*/g, "$1");
140
146
  svg = svg.replace(/<svg\s{2,}/g, "<svg ");
141
147
  return svg;
142
148
  }
149
+ function computeBBox(svg) {
150
+ const xs = [];
151
+ const ys = [];
152
+ function push(x, y) {
153
+ if (Number.isFinite(x) && Number.isFinite(y)) {
154
+ xs.push(x);
155
+ ys.push(y);
156
+ }
157
+ }
158
+ function attr(tag, name) {
159
+ const m = tag.match(new RegExp(`\\b${name}="([^"]*)"`));
160
+ if (!m) return null;
161
+ const n = parseFloat(m[1]);
162
+ return Number.isFinite(n) ? n : null;
163
+ }
164
+ for (const m of svg.matchAll(/<rect\b[^>]*?\/?>/g)) {
165
+ const tag = m[0];
166
+ const x = attr(tag, "x");
167
+ const y = attr(tag, "y");
168
+ const w = attr(tag, "width");
169
+ const h = attr(tag, "height");
170
+ if (x !== null && y !== null && w !== null && h !== null) {
171
+ push(x, y);
172
+ push(x + w, y + h);
173
+ }
174
+ }
175
+ for (const m of svg.matchAll(/<line\b[^>]*?\/?>/g)) {
176
+ const tag = m[0];
177
+ const x1 = attr(tag, "x1");
178
+ const y1 = attr(tag, "y1");
179
+ const x2 = attr(tag, "x2");
180
+ const y2 = attr(tag, "y2");
181
+ if (x1 !== null && y1 !== null && x2 !== null && y2 !== null) {
182
+ push(x1, y1);
183
+ push(x2, y2);
184
+ }
185
+ }
186
+ for (const m of svg.matchAll(/<circle\b[^>]*?\/?>/g)) {
187
+ const tag = m[0];
188
+ const cx = attr(tag, "cx");
189
+ const cy = attr(tag, "cy");
190
+ const r = attr(tag, "r");
191
+ if (cx !== null && cy !== null && r !== null) {
192
+ push(cx - r, cy - r);
193
+ push(cx + r, cy + r);
194
+ }
195
+ }
196
+ for (const m of svg.matchAll(/<ellipse\b[^>]*?\/?>/g)) {
197
+ const tag = m[0];
198
+ const cx = attr(tag, "cx");
199
+ const cy = attr(tag, "cy");
200
+ const rx = attr(tag, "rx");
201
+ const ry = attr(tag, "ry");
202
+ if (cx !== null && cy !== null && rx !== null && ry !== null) {
203
+ push(cx - rx, cy - ry);
204
+ push(cx + rx, cy + ry);
205
+ }
206
+ }
207
+ for (const m of svg.matchAll(/<text\b([^>]*?)>([\s\S]*?)<\/text>/g)) {
208
+ const tag = `<text${m[1]}>`;
209
+ const text = m[2].replace(/<[^>]+>/g, "");
210
+ const x = attr(tag, "x");
211
+ const y = attr(tag, "y");
212
+ if (x !== null && y !== null) {
213
+ const w = text.length * 7;
214
+ push(x - w / 2, y - 14);
215
+ push(x + w / 2, y + 4);
216
+ }
217
+ }
218
+ for (const m of svg.matchAll(/<path\b[^>]*?\bd="([^"]+)"/g)) {
219
+ const d = m[1];
220
+ const nums = d.match(/-?\d+(?:\.\d+)?/g);
221
+ if (!nums) continue;
222
+ for (let i = 0; i + 1 < nums.length; i += 2) {
223
+ push(parseFloat(nums[i]), parseFloat(nums[i + 1]));
224
+ }
225
+ }
226
+ for (const m of svg.matchAll(/<(?:polygon|polyline)\b[^>]*?\bpoints="([^"]+)"/g)) {
227
+ const nums = m[1].match(/-?\d+(?:\.\d+)?/g);
228
+ if (!nums) continue;
229
+ for (let i = 0; i + 1 < nums.length; i += 2) {
230
+ push(parseFloat(nums[i]), parseFloat(nums[i + 1]));
231
+ }
232
+ }
233
+ if (xs.length === 0 || ys.length === 0) return null;
234
+ const minX = Math.min(...xs);
235
+ const maxX = Math.max(...xs);
236
+ const minY = Math.min(...ys);
237
+ const maxY = Math.max(...ys);
238
+ return {
239
+ x: minX,
240
+ y: minY,
241
+ width: maxX - minX,
242
+ height: maxY - minY
243
+ };
244
+ }
143
245
 
144
246
  // src/escape.ts
145
247
  var HTML_ENTITIES = {
@@ -379,4 +481,4 @@ export {
379
481
  renderDgmoBlock,
380
482
  remarkDgmo
381
483
  };
382
- //# sourceMappingURL=chunk-7VVNWBXS.js.map
484
+ //# sourceMappingURL=chunk-E5QL6KCZ.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/remark-plugin.ts","../src/render-block.ts","../src/options.ts","../src/fence-meta.ts","../src/svg-normalize.ts","../src/escape.ts"],"sourcesContent":["import { visit } from 'unist-util-visit';\nimport type { Root, Code, Html, Parent } from 'mdast';\nimport { renderDgmoBlock, type BlockLocation } from './render-block.js';\nimport type { DgmoOptions } from './options.js';\n\nexport type RemarkDgmoOptions = DgmoOptions;\n\ninterface FencePayload {\n source: string;\n meta: string | null;\n location: BlockLocation;\n}\n\ninterface Target {\n parent: Parent;\n index: number;\n payload: FencePayload;\n}\n\n/**\n * Remark plugin that finds ```dgmo fenced code blocks and replaces them with\n * an HTML node containing the rendered SVG (and optional showcase chrome).\n *\n * The `lang` field on the code node is the fence language (the word after the\n * backticks). The `meta` field is everything that follows on the same line,\n * which we use to allow per-block options like ```dgmo showcase palette=catppuccin.\n *\n * Replaces the code node entirely (parent.children[index] = newNode) rather\n * than mutating it in place — otherwise downstream rehype/Shiki plugins still\n * see the lingering `lang: 'dgmo'` and `value: '...source...'` properties and\n * may re-process the block as a plaintext code listing, clobbering our\n * syntax-highlighted output.\n *\n * Async-safe: replacement is collected first, applied after parsing finishes.\n */\nexport default function remarkDgmo(options: RemarkDgmoOptions = {}) {\n return async function transformer(\n tree: Root,\n file?: { path?: string }\n ): Promise<void> {\n const targets: Target[] = [];\n visit(tree, 'code', (node: Code, index, parent) => {\n if (node.lang !== 'dgmo') return;\n if (!parent || index === undefined) return;\n const loc: BlockLocation = {};\n if (file?.path) loc.path = file.path;\n const line = node.position?.start.line;\n if (typeof line === 'number') loc.line = line;\n targets.push({\n parent: parent as Parent,\n index,\n payload: { source: node.value, meta: node.meta ?? null, location: loc },\n });\n });\n if (targets.length === 0) return;\n\n const rendered = await Promise.all(\n targets.map(t =>\n renderDgmoBlock(\n t.payload.source,\n t.payload.meta,\n options,\n t.payload.location\n ).catch(err => ({\n html: errorHtml(err, t.payload.source, options),\n diagnostics: [],\n }))\n )\n );\n\n // Replace in reverse index order per parent so earlier replacements don't\n // shift indices of later targets in the same parent. (Visit walks in tree\n // order, so within a single parent's children targets are also ordered;\n // reversing is sufficient.)\n for (let i = targets.length - 1; i >= 0; i--) {\n const t = targets[i];\n const html: Html = { type: 'html', value: rendered[i].html };\n t.parent.children[t.index] = html;\n }\n };\n}\n\nfunction errorHtml(\n err: unknown,\n source: string,\n options: RemarkDgmoOptions\n): string {\n const msg =\n err instanceof Error ? err.message : 'Failed to render dgmo block.';\n const safeMsg = msg.replace(/[<>&]/g, ch =>\n ch === '<' ? '&lt;' : ch === '>' ? '&gt;' : '&amp;'\n );\n const safeSrc = source.replace(/[<>&]/g, ch =>\n ch === '<' ? '&lt;' : ch === '>' ? '&gt;' : '&amp;'\n );\n const baseClass = options.className ?? 'dgmo';\n const legacy = (options.legacyClassNames ?? []).join(' ');\n const cls = legacy\n ? `${baseClass} ${legacy} ${baseClass}--error`\n : `${baseClass} ${baseClass}--error`;\n return (\n `<div class=\"${cls}\" role=\"alert\">` +\n `<strong>dgmo render error:</strong> ${safeMsg}` +\n `<pre>${safeSrc}</pre></div>`\n );\n}\n","import {\n render,\n encodeDiagramUrl,\n palettes,\n type PaletteConfig,\n} from '@diagrammo/dgmo';\nimport { highlightDgmo, NORD_ROLE_STYLES } from '@diagrammo/dgmo/highlight';\nimport {\n resolveOptions,\n type DgmoOptions,\n type ResolvedOptions,\n type Theme,\n} from './options.js';\nimport { parseFenceMeta } from './fence-meta.js';\nimport { normalizeSvg } from './svg-normalize.js';\nimport { escapeHtml, escapeAttr } from './escape.js';\n\nexport interface RenderBlockResult {\n html: string;\n diagnostics: Array<{ message: string; line?: number; severity?: string }>;\n}\n\n/**\n * Optional source-location hint, passed through from the remark transformer so\n * palette-fallback warnings can point at the offending block.\n */\nexport interface BlockLocation {\n path?: string;\n line?: number;\n}\n\n/**\n * Render a single ```dgmo block to inline HTML. Pure function: takes source +\n * options and returns the HTML string and any diagnostics from the parser.\n *\n * The remark plugin calls this for every matched code node.\n */\nexport async function renderDgmoBlock(\n source: string,\n meta: string | null | undefined,\n integrationOptions: DgmoOptions = {},\n location?: BlockLocation\n): Promise<RenderBlockResult> {\n const block = parseFenceMeta(meta);\n const base = resolveOptions(integrationOptions);\n const effectiveMode = block.mode ?? base.mode;\n const showcase = effectiveMode === 'showcase';\n const opts: ResolvedOptions = {\n ...base,\n mode: effectiveMode,\n palette: block.palette ?? base.palette,\n theme: block.theme ?? base.theme,\n colorMode: block.colorMode ?? base.colorMode,\n showSource:\n block.showSource ?? (block.mode ? showcase : base.showSource),\n showCopy: block.showCopy ?? (block.mode ? showcase : base.showCopy),\n showOpenInEditor:\n block.showOpenInEditor ?? (block.mode ? showcase : base.showOpenInEditor),\n };\n\n const trimmed = source.trim();\n const palette = resolvePaletteWithWarning(opts.palette, location);\n\n // collect diagnostics from however many render passes we end up doing\n const allDiagnostics: RenderBlockResult['diagnostics'] = [];\n\n if (opts.colorMode === 'auto') {\n const [lightSvgRaw, darkSvgRaw] = await Promise.all([\n renderForTheme(trimmed, palette, 'light', opts.palette, location),\n renderForTheme(trimmed, palette, 'dark', opts.palette, location),\n ]);\n allDiagnostics.push(...lightSvgRaw.diagnostics, ...darkSvgRaw.diagnostics);\n\n const lightSvg = normalizeSvg(lightSvgRaw.svg);\n const darkSvg = normalizeSvg(darkSvgRaw.svg);\n\n let editorUrl: string | undefined;\n if (opts.showOpenInEditor) {\n const url = encodeDiagramUrl(trimmed, { baseUrl: opts.editorBaseUrl });\n editorUrl = url ?? opts.editorBaseUrl;\n }\n\n const html =\n opts.mode === 'showcase'\n ? renderShowcaseDual(trimmed, lightSvg, darkSvg, editorUrl, opts, block.title)\n : renderSimpleDual(lightSvg, darkSvg, opts, block.title);\n\n return { html, diagnostics: allDiagnostics };\n }\n\n // Single-render path. colorMode is narrowed to 'light' | 'dark' here since\n // 'auto' is handled above. The dgmo render() also accepts 'transparent', but\n // we don't surface that via colorMode — it's reachable via `theme`.\n const themeForRender: Theme = opts.colorMode === 'light' ? 'light' : 'dark';\n const { svg: rawSvg, diagnostics } = await render(trimmed, {\n palette,\n theme: themeForRender,\n });\n allDiagnostics.push(...diagnostics);\n const svg = normalizeSvg(rawSvg);\n\n let editorUrl: string | undefined;\n if (opts.showOpenInEditor) {\n const url = encodeDiagramUrl(trimmed, { baseUrl: opts.editorBaseUrl });\n editorUrl = url ?? opts.editorBaseUrl;\n }\n\n const html =\n opts.mode === 'showcase'\n ? renderShowcase(trimmed, svg, editorUrl, opts, block.title)\n : renderSimple(svg, opts, block.title);\n\n return { html, diagnostics: allDiagnostics };\n}\n\nfunction locationSuffix(location: BlockLocation | undefined): string {\n if (!location) return '';\n if (location.path && location.line) return ` at ${location.path}:${location.line}`;\n if (location.line) return ` at line ${location.line}`;\n return '';\n}\n\nfunction resolvePaletteWithWarning(\n name: string,\n location: BlockLocation | undefined\n): PaletteConfig {\n const found = Object.values(palettes).find(p => p.id === name);\n if (!found) {\n // eslint-disable-next-line no-console\n console.warn(\n `[remark-dgmo] palette \"${name}\" not registered, falling back to \"nord\"${locationSuffix(location)}`\n );\n return palettes.nord;\n }\n return found;\n}\n\n/**\n * Render one theme. If `colorMode: 'auto'` is requested but the palette is\n * missing the requested mode, fall back to nord's mode and emit a warning.\n *\n * Today this is defensive: dgmo's palette registry validates both modes at\n * registration time, so every registered palette has both pairs by\n * construction. User-supplied palettes via `registerPalette()` that slip past\n * validation would hit this path; tests exercise it via mocking.\n */\nasync function renderForTheme(\n source: string,\n palette: PaletteConfig,\n theme: 'light' | 'dark',\n requestedName: string,\n location: BlockLocation | undefined\n): Promise<{ svg: string; diagnostics: RenderBlockResult['diagnostics'] }> {\n if (!palette[theme]) {\n // eslint-disable-next-line no-console\n console.warn(\n `[remark-dgmo] palette \"${requestedName}\" has no ${theme} mode; using nord ${theme} for the missing pair${locationSuffix(location)}`\n );\n // Build a synthetic palette where the missing mode is borrowed from nord.\n const filled: PaletteConfig = {\n ...palette,\n [theme]: palettes.nord[theme],\n } as PaletteConfig;\n return render(source, { palette: filled, theme });\n }\n return render(source, { palette, theme });\n}\n\nfunction buildWrapperClasses(\n resolved: Pick<ResolvedOptions, 'className' | 'legacyClassNames'>,\n variant: 'diagram' | 'showcase' | 'error'\n): string {\n const base = `${resolved.className} ${resolved.className}--${variant}`;\n const legacy = resolved.legacyClassNames.join(' ');\n return legacy ? `${base} ${legacy}` : base;\n}\n\nfunction buildInnerClasses(\n resolved: Pick<ResolvedOptions, 'legacyClassNames'>,\n primary: string\n): string {\n const legacy = resolved.legacyClassNames.join(' ');\n return legacy ? `${primary} ${legacy}` : primary;\n}\n\nfunction renderSimple(\n svg: string,\n opts: ResolvedOptions,\n title?: string\n): string {\n const Wrapper = opts.wrapper;\n const wrapperClass = buildWrapperClasses(opts, 'diagram');\n const captionHtml = title\n ? `<figcaption class=\"dgmo-caption\">${escapeHtml(title)}</figcaption>`\n : '';\n const captionFallback =\n title && Wrapper !== 'figure'\n ? `<div class=\"dgmo-caption\">${escapeHtml(title)}</div>`\n : '';\n return (\n `<${Wrapper} class=\"${escapeAttr(wrapperClass)}\">` +\n (Wrapper === 'figure' ? captionHtml : captionFallback) +\n `<div class=\"${escapeAttr(buildInnerClasses(opts, 'dgmo-svg'))}\">${svg}</div>` +\n `</${Wrapper}>`\n );\n}\n\nfunction renderSimpleDual(\n lightSvg: string,\n darkSvg: string,\n opts: ResolvedOptions,\n title?: string\n): string {\n const Wrapper = opts.wrapper;\n const wrapperClass = buildWrapperClasses(opts, 'diagram');\n const captionHtml = title\n ? `<figcaption class=\"dgmo-caption\">${escapeHtml(title)}</figcaption>`\n : '';\n const captionFallback =\n title && Wrapper !== 'figure'\n ? `<div class=\"dgmo-caption\">${escapeHtml(title)}</div>`\n : '';\n return (\n `<${Wrapper} class=\"${escapeAttr(wrapperClass)}\">` +\n (Wrapper === 'figure' ? captionHtml : captionFallback) +\n `<div class=\"${escapeAttr(buildInnerClasses(opts, 'dgmo-light'))}\">${lightSvg}</div>` +\n `<div class=\"${escapeAttr(buildInnerClasses(opts, 'dgmo-dark'))}\">${darkSvg}</div>` +\n `</${Wrapper}>`\n );\n}\n\nfunction renderShowcase(\n source: string,\n svg: string,\n editorUrl: string | undefined,\n opts: ResolvedOptions,\n title?: string\n): string {\n const Wrapper = opts.wrapper;\n const wrapperClass = buildWrapperClasses(opts, 'showcase');\n const cardClass = buildInnerClasses(opts, 'dgmo-card');\n\n const captionHtml = title\n ? Wrapper === 'figure'\n ? `<figcaption class=\"dgmo-caption\">${escapeHtml(title)}</figcaption>`\n : `<div class=\"dgmo-caption\">${escapeHtml(title)}</div>`\n : '';\n\n const sourceHtml = opts.showSource ? renderSource(source) : '';\n\n const openButton =\n opts.showOpenInEditor && editorUrl\n ? `<a href=\"${escapeAttr(editorUrl)}\" target=\"_blank\" rel=\"noopener noreferrer\" class=\"dgmo-toolbar-btn dgmo-open\" aria-label=\"Open in online editor\" title=\"Open in online editor\">\n <svg width=\"16\" height=\"16\" viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.5\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\">\n <path d=\"M9.5 2.5h4v4\"/>\n <path d=\"M13.5 2.5 7 9\"/>\n <path d=\"M12.5 9.5v3a1 1 0 0 1-1 1h-8a1 1 0 0 1-1-1v-8a1 1 0 0 1 1-1h3\"/>\n </svg>\n </a>`\n : '';\n\n const copyButton = opts.showCopy\n ? `<button type=\"button\" class=\"dgmo-toolbar-btn dgmo-copy\" aria-label=\"Copy to clipboard\" title=\"Copy to clipboard\" data-dgmo-source=\"${escapeAttr(source)}\">\n <svg width=\"16\" height=\"16\" viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.5\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\">\n <rect x=\"5.5\" y=\"5.5\" width=\"8\" height=\"8\" rx=\"1.5\"/>\n <path d=\"M10.5 5.5V3a1.5 1.5 0 0 0-1.5-1.5H3A1.5 1.5 0 0 0 1.5 3v6A1.5 1.5 0 0 0 3 10.5h2.5\"/>\n </svg>\n </button>`\n : '';\n\n const toolbarActions =\n openButton || copyButton\n ? `<div class=\"dgmo-toolbar-actions\">${openButton}${copyButton}</div>`\n : '';\n\n const toolbar = opts.showSource\n ? `<div class=\"dgmo-toolbar\"><span class=\"dgmo-toolbar-label\">dgmo</span>${toolbarActions}</div>`\n : '';\n\n return (\n `<${Wrapper} class=\"${escapeAttr(wrapperClass)}\">` +\n captionHtml +\n `<div class=\"${escapeAttr(cardClass)}\">` +\n (opts.showSource\n ? `<div class=\"dgmo-source-wrap\">${toolbar}<div class=\"dgmo-source-inner\">${sourceHtml}</div></div>`\n : '') +\n `<div class=\"${escapeAttr(buildInnerClasses(opts, 'dgmo-svg'))}\">${svg}</div>` +\n `</div>` +\n `</${Wrapper}>`\n );\n}\n\nfunction renderShowcaseDual(\n source: string,\n lightSvg: string,\n darkSvg: string,\n editorUrl: string | undefined,\n opts: ResolvedOptions,\n title?: string\n): string {\n const Wrapper = opts.wrapper;\n const wrapperClass = buildWrapperClasses(opts, 'showcase');\n const cardClass = buildInnerClasses(opts, 'dgmo-card');\n\n const captionHtml = title\n ? Wrapper === 'figure'\n ? `<figcaption class=\"dgmo-caption\">${escapeHtml(title)}</figcaption>`\n : `<div class=\"dgmo-caption\">${escapeHtml(title)}</div>`\n : '';\n\n const sourceHtml = opts.showSource ? renderSource(source) : '';\n\n const openButton =\n opts.showOpenInEditor && editorUrl\n ? `<a href=\"${escapeAttr(editorUrl)}\" target=\"_blank\" rel=\"noopener noreferrer\" class=\"dgmo-toolbar-btn dgmo-open\" aria-label=\"Open in online editor\" title=\"Open in online editor\">\n <svg width=\"16\" height=\"16\" viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.5\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\">\n <path d=\"M9.5 2.5h4v4\"/>\n <path d=\"M13.5 2.5 7 9\"/>\n <path d=\"M12.5 9.5v3a1 1 0 0 1-1 1h-8a1 1 0 0 1-1-1v-8a1 1 0 0 1 1-1h3\"/>\n </svg>\n </a>`\n : '';\n\n const copyButton = opts.showCopy\n ? `<button type=\"button\" class=\"dgmo-toolbar-btn dgmo-copy\" aria-label=\"Copy to clipboard\" title=\"Copy to clipboard\" data-dgmo-source=\"${escapeAttr(source)}\">\n <svg width=\"16\" height=\"16\" viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.5\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\">\n <rect x=\"5.5\" y=\"5.5\" width=\"8\" height=\"8\" rx=\"1.5\"/>\n <path d=\"M10.5 5.5V3a1.5 1.5 0 0 0-1.5-1.5H3A1.5 1.5 0 0 0 1.5 3v6A1.5 1.5 0 0 0 3 10.5h2.5\"/>\n </svg>\n </button>`\n : '';\n\n const toolbarActions =\n openButton || copyButton\n ? `<div class=\"dgmo-toolbar-actions\">${openButton}${copyButton}</div>`\n : '';\n\n const toolbar = opts.showSource\n ? `<div class=\"dgmo-toolbar\"><span class=\"dgmo-toolbar-label\">dgmo</span>${toolbarActions}</div>`\n : '';\n\n return (\n `<${Wrapper} class=\"${escapeAttr(wrapperClass)}\">` +\n captionHtml +\n `<div class=\"${escapeAttr(cardClass)}\">` +\n (opts.showSource\n ? `<div class=\"dgmo-source-wrap\">${toolbar}<div class=\"dgmo-source-inner\">${sourceHtml}</div></div>`\n : '') +\n `<div class=\"${escapeAttr(buildInnerClasses(opts, 'dgmo-light'))}\">${lightSvg}</div>` +\n `<div class=\"${escapeAttr(buildInnerClasses(opts, 'dgmo-dark'))}\">${darkSvg}</div>` +\n `</div>` +\n `</${Wrapper}>`\n );\n}\n\nfunction renderSource(source: string): string {\n const tokens = highlightDgmo(source);\n const inner = tokens\n .map(t => {\n const styles = NORD_ROLE_STYLES[t.role];\n const text = escapeHtml(t.text);\n if (!styles || Object.keys(styles).length === 0) return text;\n const styleStr = Object.entries(styles)\n .map(\n ([k, v]) => `${k.replace(/[A-Z]/g, m => '-' + m.toLowerCase())}:${v}`\n )\n .join(';');\n return `<span style=\"${escapeAttr(styleStr)}\">${text}</span>`;\n })\n .join('');\n // NOTE: We deliberately use <pre><span> rather than <pre><code> here. Astro's\n // Shiki rehype plugin (and Docusaurus's MDX pipeline) walk the hast and\n // post-process any <pre><code> pair (even ones we emit from a remark plugin\n // via raw HTML), which clobbers our pre-rendered highlight spans with a\n // plaintext listing. Using a <span> as the inner element bypasses the\n // matcher while preserving preformatted-text semantics on the outer <pre>.\n return `<pre class=\"dgmo-pre\"><span class=\"dgmo-code\">${inner}</span></pre>`;\n}\n","export type Mode = 'diagram' | 'showcase';\n\nexport type Theme = 'light' | 'dark' | 'transparent';\n\n/**\n * Framework-agnostic options for `remarkDgmo` / `renderDgmoBlock`.\n *\n * Wrapper packages (`astro-dgmo`, `docusaurus-plugin-dgmo`) re-export this\n * shape under their own conventional names (`DgmoIntegrationOptions`,\n * `DocusaurusDgmoOptions`).\n */\nexport interface DgmoOptions {\n /**\n * Output mode for `dgmo` fenced blocks.\n * - `diagram` (default): render the SVG only, in a `<figure>`.\n * - `showcase`: render syntax-highlighted source + SVG + copy + open-in-editor.\n *\n * Override per-block via the fence info string: ```dgmo showcase\n */\n mode?: Mode;\n\n /** Default palette name. Default: `nord`. */\n palette?: string;\n\n /**\n * Default theme (`light` | `dark` | `transparent`). Default: `dark`.\n *\n * NOTE: under the default `colorMode: 'auto'`, this option is unreachable —\n * dual-render emits both light and dark SVGs regardless. `theme` is consulted\n * only when `colorMode` is explicitly set to `'light'` or `'dark'`.\n */\n theme?: Theme;\n\n /**\n * Color-mode strategy for emitted SVG(s). Default: `auto`.\n *\n * - `auto` — render every block twice (light + dark palettes) and wrap each\n * SVG in a `<div class=\"dgmo-light\">` / `<div class=\"dgmo-dark\">` so the\n * shipped CSS can flip visibility based on the host site's color-mode\n * signal (`[data-theme=\"dark\"]` by default).\n * - `light` / `dark` — single-render with the matching theme. Halves the\n * emitted SVG bytes; recommended only for single-mode sites.\n */\n colorMode?: 'auto' | 'light' | 'dark';\n\n /**\n * Show source code above the diagram. Defaults to `true` in showcase mode,\n * `false` in diagram mode.\n */\n showSource?: boolean;\n\n /**\n * Show a copy-to-clipboard button. Defaults to `true` in showcase mode,\n * `false` in diagram mode.\n */\n showCopy?: boolean;\n\n /**\n * Show an \"Open in online editor\" link. Defaults to `true` in showcase mode,\n * `false` in diagram mode.\n */\n showOpenInEditor?: boolean;\n\n /**\n * Base URL for the \"Open in editor\" link. Default: `https://online.diagrammo.app`.\n * The plugin appends `?dgmo=...` (compressed source) to the base.\n */\n editorBaseUrl?: string;\n\n /**\n * Wrapper element. Default: `figure`.\n */\n wrapper?: 'figure' | 'div';\n\n /**\n * Class added to the outer wrapper. Defaults to `dgmo`.\n * Useful as a styling hook.\n */\n className?: string;\n\n /**\n * Additional class names appended to every emitted wrapper's `class`\n * attribute. Used by `astro-dgmo` v0.3.0 to emit both the new `dgmo-*` class\n * names and the legacy `astro-dgmo-*` ones for one minor cycle of backward\n * compatibility. Default: `[]`.\n */\n legacyClassNames?: string[];\n}\n\nexport type ResolvedOptions = Required<\n Omit<DgmoOptions, 'showSource' | 'showCopy' | 'showOpenInEditor'>\n> & {\n showSource: boolean;\n showCopy: boolean;\n showOpenInEditor: boolean;\n};\n\n/**\n * Apply defaults, including mode-dependent defaults for showSource/showCopy/showOpenInEditor.\n */\nexport function resolveOptions(opts: DgmoOptions = {}): ResolvedOptions {\n const mode: Mode = opts.mode ?? 'diagram';\n const showcase = mode === 'showcase';\n return {\n mode,\n palette: opts.palette ?? 'nord',\n theme: opts.theme ?? 'dark',\n colorMode: opts.colorMode ?? 'auto',\n showSource: opts.showSource ?? showcase,\n showCopy: opts.showCopy ?? showcase,\n showOpenInEditor: opts.showOpenInEditor ?? showcase,\n editorBaseUrl: opts.editorBaseUrl ?? 'https://online.diagrammo.app',\n wrapper: opts.wrapper ?? 'figure',\n className: opts.className ?? 'dgmo',\n legacyClassNames: opts.legacyClassNames ?? [],\n };\n}\n","import type { Mode, Theme } from './options.js';\n\n/**\n * Per-block options that can be set via the fence info string, e.g.\n *\n * ```dgmo showcase palette=catppuccin theme=light title=\"Login flow\"\n *\n * Tokens are space-separated. Boolean tokens are bare words (`showcase`,\n * `diagram`, `noSource`). Key=value pairs use `=`; values may be quoted with\n * double quotes to include spaces.\n */\nexport interface BlockOptions {\n mode?: Mode;\n palette?: string;\n theme?: Theme;\n colorMode?: 'auto' | 'light' | 'dark';\n showSource?: boolean;\n showCopy?: boolean;\n showOpenInEditor?: boolean;\n title?: string;\n}\n\nconst BARE_FLAGS: Record<string, Partial<BlockOptions>> = {\n diagram: { mode: 'diagram' },\n showcase: { mode: 'showcase' },\n noSource: { showSource: false },\n source: { showSource: true },\n noCopy: { showCopy: false },\n copy: { showCopy: true },\n noOpenInEditor: { showOpenInEditor: false },\n openInEditor: { showOpenInEditor: true },\n};\n\nconst VALID_THEMES = new Set<Theme>(['light', 'dark', 'transparent']);\nconst VALID_COLOR_MODES = new Set<'auto' | 'light' | 'dark'>([\n 'auto',\n 'light',\n 'dark',\n]);\n\n/**\n * Parse the meta string that follows ```dgmo on the fence line.\n * Robust to: empty, missing, malformed input.\n */\nexport function parseFenceMeta(meta: string | null | undefined): BlockOptions {\n if (!meta) return {};\n const out: BlockOptions = {};\n const tokens = tokenize(meta);\n for (const tok of tokens) {\n if (BARE_FLAGS[tok]) {\n Object.assign(out, BARE_FLAGS[tok]);\n continue;\n }\n const eq = tok.indexOf('=');\n if (eq < 0) continue;\n const key = tok.slice(0, eq).trim();\n const rawVal = tok.slice(eq + 1).trim();\n const val = unquote(rawVal);\n switch (key) {\n case 'palette':\n if (val) out.palette = val;\n break;\n case 'theme':\n if (VALID_THEMES.has(val as Theme)) out.theme = val as Theme;\n break;\n case 'colorMode':\n if (VALID_COLOR_MODES.has(val as 'auto' | 'light' | 'dark')) {\n out.colorMode = val as 'auto' | 'light' | 'dark';\n }\n break;\n case 'mode':\n if (val === 'diagram' || val === 'showcase') out.mode = val;\n break;\n case 'showSource':\n out.showSource = parseBool(val);\n break;\n case 'showCopy':\n out.showCopy = parseBool(val);\n break;\n case 'showOpenInEditor':\n out.showOpenInEditor = parseBool(val);\n break;\n case 'title':\n if (val) out.title = val;\n break;\n }\n }\n return out;\n}\n\nfunction parseBool(s: string): boolean {\n return s === 'true' || s === '1' || s === 'yes';\n}\n\nfunction unquote(s: string): string {\n if (s.length >= 2 && s.startsWith('\"') && s.endsWith('\"')) {\n return s.slice(1, -1);\n }\n return s;\n}\n\n/**\n * Split on whitespace, respecting double-quoted segments so a value like\n * `title=\"Login flow\"` survives intact.\n */\nfunction tokenize(input: string): string[] {\n const out: string[] = [];\n let buf = '';\n let inQuotes = false;\n for (let i = 0; i < input.length; i++) {\n const ch = input[i];\n if (ch === '\"') {\n inQuotes = !inQuotes;\n buf += ch;\n continue;\n }\n if (!inQuotes && /\\s/.test(ch)) {\n if (buf) {\n out.push(buf);\n buf = '';\n }\n continue;\n }\n buf += ch;\n }\n if (buf) out.push(buf);\n return out;\n}\n","/**\n * Normalize an SVG produced by `@diagrammo/dgmo` for inline embedding:\n *\n * - Ensure the root `<svg>` has a `viewBox` so it scales responsively.\n * - Strip fixed `width=\"N\"` / `height=\"N\"` so CSS controls sizing.\n * - Remove any inline `background:` from the root style so the page background\n * shows through.\n */\nexport function normalizeSvg(input: string): string {\n let svg = input;\n const rootMatch = svg.match(/<svg[^>]*>/);\n const rootTag = rootMatch?.[0] ?? '';\n if (rootTag && !rootTag.includes('viewBox')) {\n const wh = rootTag.match(/width=\"(\\d+)\"[^>]*height=\"(\\d+)\"/);\n if (wh) {\n svg = svg.replace(/<svg/, `<svg viewBox=\"0 0 ${wh[1]} ${wh[2]}\"`);\n }\n }\n svg = svg.replace(/(<svg[^>]*?) width=\"[^\"]*\"/g, '$1');\n svg = svg.replace(/(<svg[^>]*?) height=\"[^\"]*\"/g, '$1');\n svg = svg.replace(/(<svg[^>]*?style=\"[^\"]*?)background:[^;\"]*;?\\s*/g, '$1');\n svg = svg.replace(/<svg\\s{2,}/g, '<svg ');\n return svg;\n}\n","const HTML_ENTITIES: Record<string, string> = {\n '&': '&amp;',\n '<': '&lt;',\n '>': '&gt;',\n '\"': '&quot;',\n \"'\": '&#39;',\n};\n\nexport function escapeHtml(s: string): string {\n return s.replace(/[&<>\"']/g, ch => HTML_ENTITIES[ch]);\n}\n\nexport function escapeAttr(s: string): string {\n return s.replace(/[&<>\"']/g, ch => HTML_ENTITIES[ch]);\n}\n"],"mappings":";AAAA,SAAS,aAAa;;;ACAtB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP,SAAS,eAAe,wBAAwB;;;AC8FzC,SAAS,eAAe,OAAoB,CAAC,GAAoB;AACtE,QAAM,OAAa,KAAK,QAAQ;AAChC,QAAM,WAAW,SAAS;AAC1B,SAAO;AAAA,IACL;AAAA,IACA,SAAS,KAAK,WAAW;AAAA,IACzB,OAAO,KAAK,SAAS;AAAA,IACrB,WAAW,KAAK,aAAa;AAAA,IAC7B,YAAY,KAAK,cAAc;AAAA,IAC/B,UAAU,KAAK,YAAY;AAAA,IAC3B,kBAAkB,KAAK,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AQ;AAAA,UACV,EAAE,QAAQ;AAAA,UACV;AAAA,UACA,EAAE,QAAQ;AAAA,QACZ,EAAE,MAAM,UAAQ;AAAA,UACd,MAAM,UAAU,KAAK,EAAE,QAAQ,QAAQ,OAAO;AAAA,UAC9C,aAAa,CAAC;AAAA,QAChB,EAAE;AAAA,MACJ;AAAA,IACF;AAMA,aAAS,IAAI,QAAQ,SAAS,GAAG,KAAK,GAAG,KAAK;AAC5C,YAAM,IAAI,QAAQ,CAAC;AACnB,YAAM,OAAa,EAAE,MAAM,QAAQ,OAAO,SAAS,CAAC,EAAE,KAAK;AAC3D,QAAE,OAAO,SAAS,EAAE,KAAK,IAAI;AAAA,IAC/B;AAAA,EACF;AACF;AAEA,SAAS,UACP,KACA,QACA,SACQ;AACR,QAAM,MACJ,eAAe,QAAQ,IAAI,UAAU;AACvC,QAAM,UAAU,IAAI;AAAA,IAAQ;AAAA,IAAU,QACpC,OAAO,MAAM,SAAS,OAAO,MAAM,SAAS;AAAA,EAC9C;AACA,QAAM,UAAU,OAAO;AAAA,IAAQ;AAAA,IAAU,QACvC,OAAO,MAAM,SAAS,OAAO,MAAM,SAAS;AAAA,EAC9C;AACA,QAAM,YAAY,QAAQ,aAAa;AACvC,QAAM,UAAU,QAAQ,oBAAoB,CAAC,GAAG,KAAK,GAAG;AACxD,QAAM,MAAM,SACR,GAAG,SAAS,IAAI,MAAM,IAAI,SAAS,YACnC,GAAG,SAAS,IAAI,SAAS;AAC7B,SACE,eAAe,GAAG,sDACqB,OAAO,QACtC,OAAO;AAEnB;","names":["editorUrl","html"]}
1
+ {"version":3,"sources":["../src/remark-plugin.ts","../src/render-block.ts","../src/options.ts","../src/fence-meta.ts","../src/svg-normalize.ts","../src/escape.ts"],"sourcesContent":["import { visit } from 'unist-util-visit';\nimport type { Root, Code, Html, Parent } from 'mdast';\nimport { renderDgmoBlock, type BlockLocation } from './render-block.js';\nimport type { DgmoOptions } from './options.js';\n\nexport type RemarkDgmoOptions = DgmoOptions;\n\ninterface FencePayload {\n source: string;\n meta: string | null;\n location: BlockLocation;\n}\n\ninterface Target {\n parent: Parent;\n index: number;\n payload: FencePayload;\n}\n\n/**\n * Remark plugin that finds ```dgmo fenced code blocks and replaces them with\n * an HTML node containing the rendered SVG (and optional showcase chrome).\n *\n * The `lang` field on the code node is the fence language (the word after the\n * backticks). The `meta` field is everything that follows on the same line,\n * which we use to allow per-block options like ```dgmo showcase palette=catppuccin.\n *\n * Replaces the code node entirely (parent.children[index] = newNode) rather\n * than mutating it in place — otherwise downstream rehype/Shiki plugins still\n * see the lingering `lang: 'dgmo'` and `value: '...source...'` properties and\n * may re-process the block as a plaintext code listing, clobbering our\n * syntax-highlighted output.\n *\n * Async-safe: replacement is collected first, applied after parsing finishes.\n */\nexport default function remarkDgmo(options: RemarkDgmoOptions = {}) {\n return async function transformer(\n tree: Root,\n file?: { path?: string }\n ): Promise<void> {\n const targets: Target[] = [];\n visit(tree, 'code', (node: Code, index, parent) => {\n if (node.lang !== 'dgmo') return;\n if (!parent || index === undefined) return;\n const loc: BlockLocation = {};\n if (file?.path) loc.path = file.path;\n const line = node.position?.start.line;\n if (typeof line === 'number') loc.line = line;\n targets.push({\n parent: parent as Parent,\n index,\n payload: { source: node.value, meta: node.meta ?? null, location: loc },\n });\n });\n if (targets.length === 0) return;\n\n const rendered = await Promise.all(\n targets.map(t =>\n renderDgmoBlock(\n t.payload.source,\n t.payload.meta,\n options,\n t.payload.location\n ).catch(err => ({\n html: errorHtml(err, t.payload.source, options),\n diagnostics: [],\n }))\n )\n );\n\n // Replace in reverse index order per parent so earlier replacements don't\n // shift indices of later targets in the same parent. (Visit walks in tree\n // order, so within a single parent's children targets are also ordered;\n // reversing is sufficient.)\n for (let i = targets.length - 1; i >= 0; i--) {\n const t = targets[i];\n const html: Html = { type: 'html', value: rendered[i].html };\n t.parent.children[t.index] = html;\n }\n };\n}\n\nfunction errorHtml(\n err: unknown,\n source: string,\n options: RemarkDgmoOptions\n): string {\n const msg =\n err instanceof Error ? err.message : 'Failed to render dgmo block.';\n const safeMsg = msg.replace(/[<>&]/g, ch =>\n ch === '<' ? '&lt;' : ch === '>' ? '&gt;' : '&amp;'\n );\n const safeSrc = source.replace(/[<>&]/g, ch =>\n ch === '<' ? '&lt;' : ch === '>' ? '&gt;' : '&amp;'\n );\n const baseClass = options.className ?? 'dgmo';\n const legacy = (options.legacyClassNames ?? []).join(' ');\n const cls = legacy\n ? `${baseClass} ${legacy} ${baseClass}--error`\n : `${baseClass} ${baseClass}--error`;\n return (\n `<div class=\"${cls}\" role=\"alert\">` +\n `<strong>dgmo render error:</strong> ${safeMsg}` +\n `<pre>${safeSrc}</pre></div>`\n );\n}\n","import {\n render,\n encodeDiagramUrl,\n palettes,\n type PaletteConfig,\n} from '@diagrammo/dgmo';\nimport { highlightDgmo, NORD_ROLE_STYLES } from '@diagrammo/dgmo/highlight';\nimport {\n resolveOptions,\n type DgmoOptions,\n type ResolvedOptions,\n type Theme,\n} from './options.js';\nimport { parseFenceMeta } from './fence-meta.js';\nimport { normalizeSvg } from './svg-normalize.js';\nimport { escapeHtml, escapeAttr } from './escape.js';\n\nexport interface RenderBlockResult {\n html: string;\n diagnostics: Array<{ message: string; line?: number; severity?: string }>;\n}\n\n/**\n * Optional source-location hint, passed through from the remark transformer so\n * palette-fallback warnings can point at the offending block.\n */\nexport interface BlockLocation {\n path?: string;\n line?: number;\n}\n\n/**\n * Render a single ```dgmo block to inline HTML. Pure function: takes source +\n * options and returns the HTML string and any diagnostics from the parser.\n *\n * The remark plugin calls this for every matched code node.\n */\nexport async function renderDgmoBlock(\n source: string,\n meta: string | null | undefined,\n integrationOptions: DgmoOptions = {},\n location?: BlockLocation\n): Promise<RenderBlockResult> {\n const block = parseFenceMeta(meta);\n const base = resolveOptions(integrationOptions);\n const effectiveMode = block.mode ?? base.mode;\n const showcase = effectiveMode === 'showcase';\n const opts: ResolvedOptions = {\n ...base,\n mode: effectiveMode,\n palette: block.palette ?? base.palette,\n theme: block.theme ?? base.theme,\n colorMode: block.colorMode ?? base.colorMode,\n showSource:\n block.showSource ?? (block.mode ? showcase : base.showSource),\n showCopy: block.showCopy ?? (block.mode ? showcase : base.showCopy),\n showOpenInEditor:\n block.showOpenInEditor ?? (block.mode ? showcase : base.showOpenInEditor),\n };\n\n const trimmed = source.trim();\n const palette = resolvePaletteWithWarning(opts.palette, location);\n\n // collect diagnostics from however many render passes we end up doing\n const allDiagnostics: RenderBlockResult['diagnostics'] = [];\n\n if (opts.colorMode === 'auto') {\n const [lightSvgRaw, darkSvgRaw] = await Promise.all([\n renderForTheme(trimmed, palette, 'light', opts.palette, location),\n renderForTheme(trimmed, palette, 'dark', opts.palette, location),\n ]);\n allDiagnostics.push(...lightSvgRaw.diagnostics, ...darkSvgRaw.diagnostics);\n\n const lightSvg = normalizeSvg(lightSvgRaw.svg);\n const darkSvg = normalizeSvg(darkSvgRaw.svg);\n\n let editorUrl: string | undefined;\n if (opts.showOpenInEditor) {\n const url = encodeDiagramUrl(trimmed, { baseUrl: opts.editorBaseUrl });\n editorUrl = url ?? opts.editorBaseUrl;\n }\n\n const html =\n opts.mode === 'showcase'\n ? renderShowcaseDual(trimmed, lightSvg, darkSvg, editorUrl, opts, block.title)\n : renderSimpleDual(lightSvg, darkSvg, opts, block.title);\n\n return { html, diagnostics: allDiagnostics };\n }\n\n // Single-render path. colorMode is narrowed to 'light' | 'dark' here since\n // 'auto' is handled above. The dgmo render() also accepts 'transparent', but\n // we don't surface that via colorMode — it's reachable via `theme`.\n const themeForRender: Theme = opts.colorMode === 'light' ? 'light' : 'dark';\n const { svg: rawSvg, diagnostics } = await render(trimmed, {\n palette,\n theme: themeForRender,\n });\n allDiagnostics.push(...diagnostics);\n const svg = normalizeSvg(rawSvg);\n\n let editorUrl: string | undefined;\n if (opts.showOpenInEditor) {\n const url = encodeDiagramUrl(trimmed, { baseUrl: opts.editorBaseUrl });\n editorUrl = url ?? opts.editorBaseUrl;\n }\n\n const html =\n opts.mode === 'showcase'\n ? renderShowcase(trimmed, svg, editorUrl, opts, block.title)\n : renderSimple(svg, opts, block.title);\n\n return { html, diagnostics: allDiagnostics };\n}\n\nfunction locationSuffix(location: BlockLocation | undefined): string {\n if (!location) return '';\n if (location.path && location.line) return ` at ${location.path}:${location.line}`;\n if (location.line) return ` at line ${location.line}`;\n return '';\n}\n\nfunction resolvePaletteWithWarning(\n name: string,\n location: BlockLocation | undefined\n): PaletteConfig {\n const found = Object.values(palettes).find(p => p.id === name);\n if (!found) {\n // eslint-disable-next-line no-console\n console.warn(\n `[remark-dgmo] palette \"${name}\" not registered, falling back to \"nord\"${locationSuffix(location)}`\n );\n return palettes.nord;\n }\n return found;\n}\n\n/**\n * Render one theme. If `colorMode: 'auto'` is requested but the palette is\n * missing the requested mode, fall back to nord's mode and emit a warning.\n *\n * Today this is defensive: dgmo's palette registry validates both modes at\n * registration time, so every registered palette has both pairs by\n * construction. User-supplied palettes via `registerPalette()` that slip past\n * validation would hit this path; tests exercise it via mocking.\n */\nasync function renderForTheme(\n source: string,\n palette: PaletteConfig,\n theme: 'light' | 'dark',\n requestedName: string,\n location: BlockLocation | undefined\n): Promise<{ svg: string; diagnostics: RenderBlockResult['diagnostics'] }> {\n if (!palette[theme]) {\n // eslint-disable-next-line no-console\n console.warn(\n `[remark-dgmo] palette \"${requestedName}\" has no ${theme} mode; using nord ${theme} for the missing pair${locationSuffix(location)}`\n );\n // Build a synthetic palette where the missing mode is borrowed from nord.\n const filled: PaletteConfig = {\n ...palette,\n [theme]: palettes.nord[theme],\n } as PaletteConfig;\n return render(source, { palette: filled, theme });\n }\n return render(source, { palette, theme });\n}\n\nfunction buildWrapperClasses(\n resolved: Pick<ResolvedOptions, 'className' | 'legacyClassNames'>,\n variant: 'diagram' | 'showcase' | 'error'\n): string {\n const base = `${resolved.className} ${resolved.className}--${variant}`;\n const legacy = resolved.legacyClassNames.join(' ');\n return legacy ? `${base} ${legacy}` : base;\n}\n\nfunction buildInnerClasses(\n resolved: Pick<ResolvedOptions, 'legacyClassNames'>,\n primary: string\n): string {\n const legacy = resolved.legacyClassNames.join(' ');\n return legacy ? `${primary} ${legacy}` : primary;\n}\n\nfunction renderSimple(\n svg: string,\n opts: ResolvedOptions,\n title?: string\n): string {\n const Wrapper = opts.wrapper;\n const wrapperClass = buildWrapperClasses(opts, 'diagram');\n const captionHtml = title\n ? `<figcaption class=\"dgmo-caption\">${escapeHtml(title)}</figcaption>`\n : '';\n const captionFallback =\n title && Wrapper !== 'figure'\n ? `<div class=\"dgmo-caption\">${escapeHtml(title)}</div>`\n : '';\n return (\n `<${Wrapper} class=\"${escapeAttr(wrapperClass)}\">` +\n (Wrapper === 'figure' ? captionHtml : captionFallback) +\n `<div class=\"${escapeAttr(buildInnerClasses(opts, 'dgmo-svg'))}\">${svg}</div>` +\n `</${Wrapper}>`\n );\n}\n\nfunction renderSimpleDual(\n lightSvg: string,\n darkSvg: string,\n opts: ResolvedOptions,\n title?: string\n): string {\n const Wrapper = opts.wrapper;\n const wrapperClass = buildWrapperClasses(opts, 'diagram');\n const captionHtml = title\n ? `<figcaption class=\"dgmo-caption\">${escapeHtml(title)}</figcaption>`\n : '';\n const captionFallback =\n title && Wrapper !== 'figure'\n ? `<div class=\"dgmo-caption\">${escapeHtml(title)}</div>`\n : '';\n return (\n `<${Wrapper} class=\"${escapeAttr(wrapperClass)}\">` +\n (Wrapper === 'figure' ? captionHtml : captionFallback) +\n `<div class=\"${escapeAttr(buildInnerClasses(opts, 'dgmo-light'))}\">${lightSvg}</div>` +\n `<div class=\"${escapeAttr(buildInnerClasses(opts, 'dgmo-dark'))}\">${darkSvg}</div>` +\n `</${Wrapper}>`\n );\n}\n\nfunction renderShowcase(\n source: string,\n svg: string,\n editorUrl: string | undefined,\n opts: ResolvedOptions,\n title?: string\n): string {\n const Wrapper = opts.wrapper;\n const wrapperClass = buildWrapperClasses(opts, 'showcase');\n const cardClass = buildInnerClasses(opts, 'dgmo-card');\n\n const captionHtml = title\n ? Wrapper === 'figure'\n ? `<figcaption class=\"dgmo-caption\">${escapeHtml(title)}</figcaption>`\n : `<div class=\"dgmo-caption\">${escapeHtml(title)}</div>`\n : '';\n\n const sourceHtml = opts.showSource ? renderSource(source) : '';\n\n const openButton =\n opts.showOpenInEditor && editorUrl\n ? `<a href=\"${escapeAttr(editorUrl)}\" target=\"_blank\" rel=\"noopener noreferrer\" class=\"dgmo-toolbar-btn dgmo-open\" aria-label=\"Open in online editor\" title=\"Open in online editor\">\n <svg width=\"16\" height=\"16\" viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.5\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\">\n <path d=\"M9.5 2.5h4v4\"/>\n <path d=\"M13.5 2.5 7 9\"/>\n <path d=\"M12.5 9.5v3a1 1 0 0 1-1 1h-8a1 1 0 0 1-1-1v-8a1 1 0 0 1 1-1h3\"/>\n </svg>\n </a>`\n : '';\n\n const copyButton = opts.showCopy\n ? `<button type=\"button\" class=\"dgmo-toolbar-btn dgmo-copy\" aria-label=\"Copy to clipboard\" title=\"Copy to clipboard\" data-dgmo-source=\"${escapeAttr(source)}\">\n <svg width=\"16\" height=\"16\" viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.5\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\">\n <rect x=\"5.5\" y=\"5.5\" width=\"8\" height=\"8\" rx=\"1.5\"/>\n <path d=\"M10.5 5.5V3a1.5 1.5 0 0 0-1.5-1.5H3A1.5 1.5 0 0 0 1.5 3v6A1.5 1.5 0 0 0 3 10.5h2.5\"/>\n </svg>\n </button>`\n : '';\n\n const toolbarActions =\n openButton || copyButton\n ? `<div class=\"dgmo-toolbar-actions\">${openButton}${copyButton}</div>`\n : '';\n\n const toolbar = opts.showSource\n ? `<div class=\"dgmo-toolbar\"><span class=\"dgmo-toolbar-label\">dgmo</span>${toolbarActions}</div>`\n : '';\n\n return (\n `<${Wrapper} class=\"${escapeAttr(wrapperClass)}\">` +\n captionHtml +\n `<div class=\"${escapeAttr(cardClass)}\">` +\n (opts.showSource\n ? `<div class=\"dgmo-source-wrap\">${toolbar}<div class=\"dgmo-source-inner\">${sourceHtml}</div></div>`\n : '') +\n `<div class=\"${escapeAttr(buildInnerClasses(opts, 'dgmo-svg'))}\">${svg}</div>` +\n `</div>` +\n `</${Wrapper}>`\n );\n}\n\nfunction renderShowcaseDual(\n source: string,\n lightSvg: string,\n darkSvg: string,\n editorUrl: string | undefined,\n opts: ResolvedOptions,\n title?: string\n): string {\n const Wrapper = opts.wrapper;\n const wrapperClass = buildWrapperClasses(opts, 'showcase');\n const cardClass = buildInnerClasses(opts, 'dgmo-card');\n\n const captionHtml = title\n ? Wrapper === 'figure'\n ? `<figcaption class=\"dgmo-caption\">${escapeHtml(title)}</figcaption>`\n : `<div class=\"dgmo-caption\">${escapeHtml(title)}</div>`\n : '';\n\n const sourceHtml = opts.showSource ? renderSource(source) : '';\n\n const openButton =\n opts.showOpenInEditor && editorUrl\n ? `<a href=\"${escapeAttr(editorUrl)}\" target=\"_blank\" rel=\"noopener noreferrer\" class=\"dgmo-toolbar-btn dgmo-open\" aria-label=\"Open in online editor\" title=\"Open in online editor\">\n <svg width=\"16\" height=\"16\" viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.5\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\">\n <path d=\"M9.5 2.5h4v4\"/>\n <path d=\"M13.5 2.5 7 9\"/>\n <path d=\"M12.5 9.5v3a1 1 0 0 1-1 1h-8a1 1 0 0 1-1-1v-8a1 1 0 0 1 1-1h3\"/>\n </svg>\n </a>`\n : '';\n\n const copyButton = opts.showCopy\n ? `<button type=\"button\" class=\"dgmo-toolbar-btn dgmo-copy\" aria-label=\"Copy to clipboard\" title=\"Copy to clipboard\" data-dgmo-source=\"${escapeAttr(source)}\">\n <svg width=\"16\" height=\"16\" viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.5\" stroke-linecap=\"round\" stroke-linejoin=\"round\" aria-hidden=\"true\">\n <rect x=\"5.5\" y=\"5.5\" width=\"8\" height=\"8\" rx=\"1.5\"/>\n <path d=\"M10.5 5.5V3a1.5 1.5 0 0 0-1.5-1.5H3A1.5 1.5 0 0 0 1.5 3v6A1.5 1.5 0 0 0 3 10.5h2.5\"/>\n </svg>\n </button>`\n : '';\n\n const toolbarActions =\n openButton || copyButton\n ? `<div class=\"dgmo-toolbar-actions\">${openButton}${copyButton}</div>`\n : '';\n\n const toolbar = opts.showSource\n ? `<div class=\"dgmo-toolbar\"><span class=\"dgmo-toolbar-label\">dgmo</span>${toolbarActions}</div>`\n : '';\n\n return (\n `<${Wrapper} class=\"${escapeAttr(wrapperClass)}\">` +\n captionHtml +\n `<div class=\"${escapeAttr(cardClass)}\">` +\n (opts.showSource\n ? `<div class=\"dgmo-source-wrap\">${toolbar}<div class=\"dgmo-source-inner\">${sourceHtml}</div></div>`\n : '') +\n `<div class=\"${escapeAttr(buildInnerClasses(opts, 'dgmo-light'))}\">${lightSvg}</div>` +\n `<div class=\"${escapeAttr(buildInnerClasses(opts, 'dgmo-dark'))}\">${darkSvg}</div>` +\n `</div>` +\n `</${Wrapper}>`\n );\n}\n\nfunction renderSource(source: string): string {\n const tokens = highlightDgmo(source);\n const inner = tokens\n .map(t => {\n const styles = NORD_ROLE_STYLES[t.role];\n const text = escapeHtml(t.text);\n if (!styles || Object.keys(styles).length === 0) return text;\n const styleStr = Object.entries(styles)\n .map(\n ([k, v]) => `${k.replace(/[A-Z]/g, m => '-' + m.toLowerCase())}:${v}`\n )\n .join(';');\n return `<span style=\"${escapeAttr(styleStr)}\">${text}</span>`;\n })\n .join('');\n // NOTE: We deliberately use <pre><span> rather than <pre><code> here. Astro's\n // Shiki rehype plugin (and Docusaurus's MDX pipeline) walk the hast and\n // post-process any <pre><code> pair (even ones we emit from a remark plugin\n // via raw HTML), which clobbers our pre-rendered highlight spans with a\n // plaintext listing. Using a <span> as the inner element bypasses the\n // matcher while preserving preformatted-text semantics on the outer <pre>.\n return `<pre class=\"dgmo-pre\"><span class=\"dgmo-code\">${inner}</span></pre>`;\n}\n","export type Mode = 'diagram' | 'showcase';\n\nexport type Theme = 'light' | 'dark' | 'transparent';\n\n/**\n * Framework-agnostic options for `remarkDgmo` / `renderDgmoBlock`.\n *\n * Wrapper packages (`astro-dgmo`, `docusaurus-plugin-dgmo`) re-export this\n * shape under their own conventional names (`DgmoIntegrationOptions`,\n * `DocusaurusDgmoOptions`).\n */\nexport interface DgmoOptions {\n /**\n * Output mode for `dgmo` fenced blocks.\n * - `diagram` (default): render the SVG only, in a `<figure>`.\n * - `showcase`: render syntax-highlighted source + SVG + copy + open-in-editor.\n *\n * Override per-block via the fence info string: ```dgmo showcase\n */\n mode?: Mode;\n\n /** Default palette name. Default: `nord`. */\n palette?: string;\n\n /**\n * Default theme (`light` | `dark` | `transparent`). Default: `dark`.\n *\n * NOTE: under the default `colorMode: 'auto'`, this option is unreachable —\n * dual-render emits both light and dark SVGs regardless. `theme` is consulted\n * only when `colorMode` is explicitly set to `'light'` or `'dark'`.\n */\n theme?: Theme;\n\n /**\n * Color-mode strategy for emitted SVG(s). Default: `auto`.\n *\n * - `auto` — render every block twice (light + dark palettes) and wrap each\n * SVG in a `<div class=\"dgmo-light\">` / `<div class=\"dgmo-dark\">` so the\n * shipped CSS can flip visibility based on the host site's color-mode\n * signal (`[data-theme=\"dark\"]` by default).\n * - `light` / `dark` — single-render with the matching theme. Halves the\n * emitted SVG bytes; recommended only for single-mode sites.\n */\n colorMode?: 'auto' | 'light' | 'dark';\n\n /**\n * Show source code above the diagram. Defaults to `true` in showcase mode,\n * `false` in diagram mode.\n */\n showSource?: boolean;\n\n /**\n * Show a copy-to-clipboard button. Defaults to `true` in showcase mode,\n * `false` in diagram mode.\n */\n showCopy?: boolean;\n\n /**\n * Show an \"Open in online editor\" link. Defaults to `true` in showcase mode,\n * `false` in diagram mode.\n */\n showOpenInEditor?: boolean;\n\n /**\n * Base URL for the \"Open in editor\" link. Default: `https://online.diagrammo.app`.\n * The plugin appends `?dgmo=...` (compressed source) to the base.\n */\n editorBaseUrl?: string;\n\n /**\n * Wrapper element. Default: `figure`.\n */\n wrapper?: 'figure' | 'div';\n\n /**\n * Class added to the outer wrapper. Defaults to `dgmo`.\n * Useful as a styling hook.\n */\n className?: string;\n\n /**\n * Additional class names appended to every emitted wrapper's `class`\n * attribute. Used by `astro-dgmo` v0.3.0 to emit both the new `dgmo-*` class\n * names and the legacy `astro-dgmo-*` ones for one minor cycle of backward\n * compatibility. Default: `[]`.\n */\n legacyClassNames?: string[];\n}\n\nexport type ResolvedOptions = Required<\n Omit<DgmoOptions, 'showSource' | 'showCopy' | 'showOpenInEditor'>\n> & {\n showSource: boolean;\n showCopy: boolean;\n showOpenInEditor: boolean;\n};\n\n/**\n * Apply defaults, including mode-dependent defaults for showSource/showCopy/showOpenInEditor.\n */\nexport function resolveOptions(opts: DgmoOptions = {}): ResolvedOptions {\n const mode: Mode = opts.mode ?? 'diagram';\n const showcase = mode === 'showcase';\n return {\n mode,\n palette: opts.palette ?? 'nord',\n theme: opts.theme ?? 'dark',\n colorMode: opts.colorMode ?? 'auto',\n showSource: opts.showSource ?? showcase,\n showCopy: opts.showCopy ?? showcase,\n showOpenInEditor: opts.showOpenInEditor ?? showcase,\n editorBaseUrl: opts.editorBaseUrl ?? 'https://online.diagrammo.app',\n wrapper: opts.wrapper ?? 'figure',\n className: opts.className ?? 'dgmo',\n legacyClassNames: opts.legacyClassNames ?? [],\n };\n}\n","import type { Mode, Theme } from './options.js';\n\n/**\n * Per-block options that can be set via the fence info string, e.g.\n *\n * ```dgmo showcase palette=catppuccin theme=light title=\"Login flow\"\n *\n * Tokens are space-separated. Boolean tokens are bare words (`showcase`,\n * `diagram`, `noSource`). Key=value pairs use `=`; values may be quoted with\n * double quotes to include spaces.\n */\nexport interface BlockOptions {\n mode?: Mode;\n palette?: string;\n theme?: Theme;\n colorMode?: 'auto' | 'light' | 'dark';\n showSource?: boolean;\n showCopy?: boolean;\n showOpenInEditor?: boolean;\n title?: string;\n}\n\nconst BARE_FLAGS: Record<string, Partial<BlockOptions>> = {\n diagram: { mode: 'diagram' },\n showcase: { mode: 'showcase' },\n noSource: { showSource: false },\n source: { showSource: true },\n noCopy: { showCopy: false },\n copy: { showCopy: true },\n noOpenInEditor: { showOpenInEditor: false },\n openInEditor: { showOpenInEditor: true },\n};\n\nconst VALID_THEMES = new Set<Theme>(['light', 'dark', 'transparent']);\nconst VALID_COLOR_MODES = new Set<'auto' | 'light' | 'dark'>([\n 'auto',\n 'light',\n 'dark',\n]);\n\n/**\n * Parse the meta string that follows ```dgmo on the fence line.\n * Robust to: empty, missing, malformed input.\n */\nexport function parseFenceMeta(meta: string | null | undefined): BlockOptions {\n if (!meta) return {};\n const out: BlockOptions = {};\n const tokens = tokenize(meta);\n for (const tok of tokens) {\n if (BARE_FLAGS[tok]) {\n Object.assign(out, BARE_FLAGS[tok]);\n continue;\n }\n const eq = tok.indexOf('=');\n if (eq < 0) continue;\n const key = tok.slice(0, eq).trim();\n const rawVal = tok.slice(eq + 1).trim();\n const val = unquote(rawVal);\n switch (key) {\n case 'palette':\n if (val) out.palette = val;\n break;\n case 'theme':\n if (VALID_THEMES.has(val as Theme)) out.theme = val as Theme;\n break;\n case 'colorMode':\n if (VALID_COLOR_MODES.has(val as 'auto' | 'light' | 'dark')) {\n out.colorMode = val as 'auto' | 'light' | 'dark';\n }\n break;\n case 'mode':\n if (val === 'diagram' || val === 'showcase') out.mode = val;\n break;\n case 'showSource':\n out.showSource = parseBool(val);\n break;\n case 'showCopy':\n out.showCopy = parseBool(val);\n break;\n case 'showOpenInEditor':\n out.showOpenInEditor = parseBool(val);\n break;\n case 'title':\n if (val) out.title = val;\n break;\n }\n }\n return out;\n}\n\nfunction parseBool(s: string): boolean {\n return s === 'true' || s === '1' || s === 'yes';\n}\n\nfunction unquote(s: string): string {\n if (s.length >= 2 && s.startsWith('\"') && s.endsWith('\"')) {\n return s.slice(1, -1);\n }\n return s;\n}\n\n/**\n * Split on whitespace, respecting double-quoted segments so a value like\n * `title=\"Login flow\"` survives intact.\n */\nfunction tokenize(input: string): string[] {\n const out: string[] = [];\n let buf = '';\n let inQuotes = false;\n for (let i = 0; i < input.length; i++) {\n const ch = input[i];\n if (ch === '\"') {\n inQuotes = !inQuotes;\n buf += ch;\n continue;\n }\n if (!inQuotes && /\\s/.test(ch)) {\n if (buf) {\n out.push(buf);\n buf = '';\n }\n continue;\n }\n buf += ch;\n }\n if (buf) out.push(buf);\n return out;\n}\n","/**\n * Normalize an SVG produced by `@diagrammo/dgmo` for inline embedding:\n *\n * - Compute a tight content bounding box from element coordinates and\n * set the root `viewBox` to bbox+padding. Replaces the JS-side\n * `getBBox()` step that can't measure dual-rendered SVGs hidden by\n * color-mode CSS.\n * - Ensure the root `<svg>` has a `viewBox` so it scales responsively.\n * - Strip fixed `width=\"N\"` / `height=\"N\"` so CSS controls sizing.\n * - Remove any inline `background:` from the root style so the page\n * background shows through.\n */\nexport function normalizeSvg(input: string): string {\n let svg = input;\n const rootMatch = svg.match(/<svg[^>]*>/);\n const rootTag = rootMatch?.[0] ?? '';\n if (rootTag && !rootTag.includes('viewBox')) {\n const wh = rootTag.match(/width=\"(\\d+)\"[^>]*height=\"(\\d+)\"/);\n if (wh) {\n svg = svg.replace(/<svg/, `<svg viewBox=\"0 0 ${wh[1]} ${wh[2]}\"`);\n }\n }\n\n // Tighten viewBox to the content bbox. dgmo emits diagrams within a\n // fixed-size canvas (e.g. viewBox=\"0 0 1200 250\"), with content often\n // occupying only a fraction of that canvas. Tightening here means\n // dual-rendered SVGs render at the same scale whether visible or not.\n const tight = computeBBox(svg);\n if (tight && tight.width > 0 && tight.height > 0) {\n const pad = 16;\n const vb = `${tight.x - pad} ${tight.y - pad} ${tight.width + pad * 2} ${tight.height + pad * 2}`;\n svg = svg.replace(/(<svg[^>]*?)viewBox=\"[^\"]*\"/, `$1viewBox=\"${vb}\"`);\n }\n\n svg = svg.replace(/(<svg[^>]*?) width=\"[^\"]*\"/g, '$1');\n svg = svg.replace(/(<svg[^>]*?) height=\"[^\"]*\"/g, '$1');\n svg = svg.replace(/(<svg[^>]*?style=\"[^\"]*?)background:[^;\"]*;?\\s*/g, '$1');\n svg = svg.replace(/<svg\\s{2,}/g, '<svg ');\n return svg;\n}\n\n/**\n * Compute an approximate content bounding box from raw element coordinates.\n *\n * This is a regex walk, not a real SVG layout — it ignores `transform`\n * attributes and uses a heuristic for text widths. dgmo's renderer mostly\n * uses absolute coordinates within its viewBox, so the approximation is\n * close enough that the rendered output reliably fills the visible area.\n */\nfunction computeBBox(\n svg: string\n): { x: number; y: number; width: number; height: number } | null {\n const xs: number[] = [];\n const ys: number[] = [];\n\n function push(x: number, y: number): void {\n if (Number.isFinite(x) && Number.isFinite(y)) {\n xs.push(x);\n ys.push(y);\n }\n }\n\n function attr(tag: string, name: string): number | null {\n const m = tag.match(new RegExp(`\\\\b${name}=\"([^\"]*)\"`));\n if (!m) return null;\n const n = parseFloat(m[1]);\n return Number.isFinite(n) ? n : null;\n }\n\n // <rect x y width height>\n for (const m of svg.matchAll(/<rect\\b[^>]*?\\/?>/g)) {\n const tag = m[0];\n const x = attr(tag, 'x');\n const y = attr(tag, 'y');\n const w = attr(tag, 'width');\n const h = attr(tag, 'height');\n if (x !== null && y !== null && w !== null && h !== null) {\n push(x, y);\n push(x + w, y + h);\n }\n }\n\n // <line x1 y1 x2 y2>\n for (const m of svg.matchAll(/<line\\b[^>]*?\\/?>/g)) {\n const tag = m[0];\n const x1 = attr(tag, 'x1');\n const y1 = attr(tag, 'y1');\n const x2 = attr(tag, 'x2');\n const y2 = attr(tag, 'y2');\n if (x1 !== null && y1 !== null && x2 !== null && y2 !== null) {\n push(x1, y1);\n push(x2, y2);\n }\n }\n\n // <circle cx cy r>\n for (const m of svg.matchAll(/<circle\\b[^>]*?\\/?>/g)) {\n const tag = m[0];\n const cx = attr(tag, 'cx');\n const cy = attr(tag, 'cy');\n const r = attr(tag, 'r');\n if (cx !== null && cy !== null && r !== null) {\n push(cx - r, cy - r);\n push(cx + r, cy + r);\n }\n }\n\n // <ellipse cx cy rx ry>\n for (const m of svg.matchAll(/<ellipse\\b[^>]*?\\/?>/g)) {\n const tag = m[0];\n const cx = attr(tag, 'cx');\n const cy = attr(tag, 'cy');\n const rx = attr(tag, 'rx');\n const ry = attr(tag, 'ry');\n if (cx !== null && cy !== null && rx !== null && ry !== null) {\n push(cx - rx, cy - ry);\n push(cx + rx, cy + ry);\n }\n }\n\n // <text x y>some content</text>\n // Approximate width: text content length × an empirical font width factor.\n // dgmo uses Inter ~14px by default; ~7-8px per character is a usable\n // rough estimate that won't drastically under- or over-count.\n for (const m of svg.matchAll(/<text\\b([^>]*?)>([\\s\\S]*?)<\\/text>/g)) {\n const tag = `<text${m[1]}>`;\n const text = m[2].replace(/<[^>]+>/g, ''); // strip inner tags (tspan, etc.)\n const x = attr(tag, 'x');\n const y = attr(tag, 'y');\n if (x !== null && y !== null) {\n const w = text.length * 7;\n // text-anchor may be start/middle/end; assume worst case (middle) for span\n push(x - w / 2, y - 14);\n push(x + w / 2, y + 4);\n }\n }\n\n // <path d=\"...\"> — pull every coordinate pair out of the d attribute.\n for (const m of svg.matchAll(/<path\\b[^>]*?\\bd=\"([^\"]+)\"/g)) {\n const d = m[1];\n const nums = d.match(/-?\\d+(?:\\.\\d+)?/g);\n if (!nums) continue;\n for (let i = 0; i + 1 < nums.length; i += 2) {\n push(parseFloat(nums[i]), parseFloat(nums[i + 1]));\n }\n }\n\n // <polygon points=\"x,y x,y ...\"> and <polyline>\n for (const m of svg.matchAll(/<(?:polygon|polyline)\\b[^>]*?\\bpoints=\"([^\"]+)\"/g)) {\n const nums = m[1].match(/-?\\d+(?:\\.\\d+)?/g);\n if (!nums) continue;\n for (let i = 0; i + 1 < nums.length; i += 2) {\n push(parseFloat(nums[i]), parseFloat(nums[i + 1]));\n }\n }\n\n if (xs.length === 0 || ys.length === 0) return null;\n\n const minX = Math.min(...xs);\n const maxX = Math.max(...xs);\n const minY = Math.min(...ys);\n const maxY = Math.max(...ys);\n\n return {\n x: minX,\n y: minY,\n width: maxX - minX,\n height: maxY - minY,\n };\n}\n","const HTML_ENTITIES: Record<string, string> = {\n '&': '&amp;',\n '<': '&lt;',\n '>': '&gt;',\n '\"': '&quot;',\n \"'\": '&#39;',\n};\n\nexport function escapeHtml(s: string): string {\n return s.replace(/[&<>\"']/g, ch => HTML_ENTITIES[ch]);\n}\n\nexport function escapeAttr(s: string): string {\n return s.replace(/[&<>\"']/g, ch => HTML_ENTITIES[ch]);\n}\n"],"mappings":";AAAA,SAAS,aAAa;;;ACAtB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP,SAAS,eAAe,wBAAwB;;;AC8FzC,SAAS,eAAe,OAAoB,CAAC,GAAoB;AACtE,QAAM,OAAa,KAAK,QAAQ;AAChC,QAAM,WAAW,SAAS;AAC1B,SAAO;AAAA,IACL;AAAA,IACA,SAAS,KAAK,WAAW;AAAA,IACzB,OAAO,KAAK,SAAS;AAAA,IACrB,WAAW,KAAK,aAAa;AAAA,IAC7B,YAAY,KAAK,cAAc;AAAA,IAC/B,UAAU,KAAK,YAAY;AAAA,IAC3B,kBAAkB,KAAK,oBAAoB;AAAA,IAC3C,eAAe,KAAK,iBAAiB;AAAA,IACrC,SAAS,KAAK,WAAW;AAAA,IACzB,WAAW,KAAK,aAAa;AAAA,IAC7B,kBAAkB,KAAK,oBAAoB,CAAC;AAAA,EAC9C;AACF;;;AC9FA,IAAM,aAAoD;AAAA,EACxD,SAAS,EAAE,MAAM,UAAU;AAAA,EAC3B,UAAU,EAAE,MAAM,WAAW;AAAA,EAC7B,UAAU,EAAE,YAAY,MAAM;AAAA,EAC9B,QAAQ,EAAE,YAAY,KAAK;AAAA,EAC3B,QAAQ,EAAE,UAAU,MAAM;AAAA,EAC1B,MAAM,EAAE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M,SAAS;AAAA,EAC9C;AACA,QAAM,UAAU,OAAO;AAAA,IAAQ;AAAA,IAAU,QACvC,OAAO,MAAM,SAAS,OAAO,MAAM,SAAS;AAAA,EAC9C;AACA,QAAM,YAAY,QAAQ,aAAa;AACvC,QAAM,UAAU,QAAQ,oBAAoB,CAAC,GAAG,KAAK,GAAG;AACxD,QAAM,MAAM,SACR,GAAG,SAAS,IAAI,MAAM,IAAI,SAAS,YACnC,GAAG,SAAS,IAAI,SAAS;AAC7B,SACE,eAAe,GAAG,sDACqB,OAAO,QACtC,OAAO;AAEnB;","names":["editorUrl","html"]}
package/dist/client.css CHANGED
@@ -11,7 +11,10 @@
11
11
  * SVGs are emitted with viewBox only (no fixed width/height). Force them
12
12
  * to fill their wrapper so light and dark variants render at identical
13
13
  * sizes — without this, browsers fall back to the 300x150 UA default and
14
- * the two themes can disagree depending on host CSS. */
14
+ * the two themes can disagree depending on host CSS.
15
+ *
16
+ * Targets the SVG, NOT its wrapper div — the wrappers' display is what
17
+ * the color-mode toggle rules above flip, so we mustn't override it. */
15
18
  .dgmo-light > svg,
16
19
  .dgmo-dark > svg,
17
20
  .dgmo-svg > svg {
package/dist/client.js CHANGED
@@ -1,5 +1,6 @@
1
1
  // src/client.ts
2
2
  var clickHandlerBound = false;
3
+ var themeObserverBound = false;
3
4
  function bindDgmo() {
4
5
  if (typeof window === "undefined" || typeof document === "undefined") return;
5
6
  if (!clickHandlerBound) {
@@ -7,6 +8,17 @@ function bindDgmo() {
7
8
  clickHandlerBound = true;
8
9
  }
9
10
  tightenViewBoxes();
11
+ if (!themeObserverBound) {
12
+ const html = document.documentElement;
13
+ const reTighten = () => {
14
+ requestAnimationFrame(() => requestAnimationFrame(tightenViewBoxes));
15
+ };
16
+ new MutationObserver(reTighten).observe(html, {
17
+ attributes: true,
18
+ attributeFilter: ["data-theme", "class"]
19
+ });
20
+ themeObserverBound = true;
21
+ }
10
22
  }
11
23
  async function handleCopyClick(e) {
12
24
  const target = e.target;
@@ -23,9 +35,18 @@ async function handleCopyClick(e) {
23
35
  setTimeout(() => btn.classList.remove("dgmo-copy--success"), 1500);
24
36
  }
25
37
  function tightenViewBoxes() {
26
- const SVG_SELECTORS = ".dgmo-svg svg, .dgmo-light svg, .dgmo-dark svg";
27
- document.querySelectorAll(SVG_SELECTORS).forEach((node) => {
28
- const svg = node;
38
+ const WRAPPER_SELECTORS = ".dgmo-light, .dgmo-dark, .dgmo-svg";
39
+ document.querySelectorAll(WRAPPER_SELECTORS).forEach((node) => {
40
+ const wrapper = node;
41
+ const svg = wrapper.querySelector("svg");
42
+ if (!svg) return;
43
+ const computed = window.getComputedStyle(wrapper);
44
+ const wasHidden = computed.display === "none";
45
+ const savedInlineDisplay = wrapper.style.display;
46
+ if (wasHidden) {
47
+ wrapper.style.display = "block";
48
+ void wrapper.offsetHeight;
49
+ }
29
50
  try {
30
51
  const bbox = svg.getBBox();
31
52
  if (bbox.width > 0 && bbox.height > 0) {
@@ -37,6 +58,7 @@ function tightenViewBoxes() {
37
58
  }
38
59
  } catch {
39
60
  }
61
+ if (wasHidden) wrapper.style.display = savedInlineDisplay;
40
62
  });
41
63
  }
42
64
  if (typeof window !== "undefined" && typeof document !== "undefined") {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/client.ts"],"sourcesContent":["/**\n * Framework-neutral client-side enhancement for diagrams emitted by\n * `remark-dgmo`:\n *\n * - Bind a delegated click handler for `button.dgmo-copy` to copy the\n * source string in `data-dgmo-source` to the clipboard.\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 (Node SSR), `bindDgmo()` is a no-op.\n */\n\nlet clickHandlerBound = false;\n\nexport function bindDgmo(): void {\n if (typeof window === 'undefined' || typeof document === 'undefined') return;\n\n if (!clickHandlerBound) {\n document.addEventListener('click', handleCopyClick);\n clickHandlerBound = true;\n }\n tightenViewBoxes();\n}\n\nasync function handleCopyClick(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('button.dgmo-copy') as HTMLElement | null;\n if (!btn) return;\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}\n\nfunction tightenViewBoxes(): void {\n const SVG_SELECTORS = '.dgmo-svg svg, .dgmo-light svg, .dgmo-dark svg';\n document.querySelectorAll(SVG_SELECTORS).forEach(node => {\n const svg = node as SVGSVGElement;\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}\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 (typeof window !== 'undefined' && typeof document !== 'undefined') {\n if (document.readyState === 'loading') {\n document.addEventListener('DOMContentLoaded', bindDgmo);\n } else {\n bindDgmo();\n }\n}\n"],"mappings":";AAkBA,IAAI,oBAAoB;AAEjB,SAAS,WAAiB;AAC/B,MAAI,OAAO,WAAW,eAAe,OAAO,aAAa,YAAa;AAEtE,MAAI,CAAC,mBAAmB;AACtB,aAAS,iBAAiB,SAAS,eAAe;AAClD,wBAAoB;AAAA,EACtB;AACA,mBAAiB;AACnB;AAEA,eAAe,gBAAgB,GAAyB;AACtD,QAAM,SAAS,EAAE;AACjB,MAAI,CAAC,UAAU,OAAO,OAAO,YAAY,WAAY;AACrD,QAAM,MAAM,OAAO,QAAQ,kBAAkB;AAC7C,MAAI,CAAC,IAAK;AACV,QAAM,MAAM,IAAI,QAAQ,cAAc;AACtC,MAAI;AACF,UAAM,UAAU,UAAU,UAAU,GAAG;AAAA,EACzC,QAAQ;AACN;AAAA,EACF;AACA,MAAI,UAAU,IAAI,oBAAoB;AACtC,aAAW,MAAM,IAAI,UAAU,OAAO,oBAAoB,GAAG,IAAI;AACnE;AAEA,SAAS,mBAAyB;AAChC,QAAM,gBAAgB;AACtB,WAAS,iBAAiB,aAAa,EAAE,QAAQ,UAAQ;AACvD,UAAM,MAAM;AACZ,QAAI;AACF,YAAM,OAAQ,IAAsC,QAAQ;AAC5D,UAAI,KAAK,QAAQ,KAAK,KAAK,SAAS,GAAG;AACrC,cAAM,MAAM;AACZ,YAAI;AAAA,UACF;AAAA,UACA,GAAG,KAAK,IAAI,GAAG,IAAI,KAAK,IAAI,GAAG,IAAI,KAAK,QAAQ,MAAM,CAAC,IACrD,KAAK,SAAS,MAAM,CACtB;AAAA,QACF;AAAA,MACF;AAAA,IACF,QAAQ;AAAA,IAER;AAAA,EACF,CAAC;AACH;AAKA,IAAI,OAAO,WAAW,eAAe,OAAO,aAAa,aAAa;AACpE,MAAI,SAAS,eAAe,WAAW;AACrC,aAAS,iBAAiB,oBAAoB,QAAQ;AAAA,EACxD,OAAO;AACL,aAAS;AAAA,EACX;AACF;","names":[]}
1
+ {"version":3,"sources":["../src/client.ts"],"sourcesContent":["/**\n * Framework-neutral client-side enhancement for diagrams emitted by\n * `remark-dgmo`:\n *\n * - Bind a delegated click handler for `button.dgmo-copy` to copy the\n * source string in `data-dgmo-source` to the clipboard.\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 (Node SSR), `bindDgmo()` is a no-op.\n */\n\nlet clickHandlerBound = false;\nlet themeObserverBound = false;\n\nexport function bindDgmo(): void {\n if (typeof window === 'undefined' || typeof document === 'undefined') return;\n\n if (!clickHandlerBound) {\n document.addEventListener('click', handleCopyClick);\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 handleCopyClick(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('button.dgmo-copy') as HTMLElement | null;\n if (!btn) return;\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}\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) wrapper.style.display = savedInlineDisplay;\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 (typeof window !== 'undefined' && typeof document !== 'undefined') {\n if (document.readyState === 'loading') {\n document.addEventListener('DOMContentLoaded', bindDgmo);\n } else {\n bindDgmo();\n }\n}\n"],"mappings":";AAkBA,IAAI,oBAAoB;AACxB,IAAI,qBAAqB;AAElB,SAAS,WAAiB;AAC/B,MAAI,OAAO,WAAW,eAAe,OAAO,aAAa,YAAa;AAEtE,MAAI,CAAC,mBAAmB;AACtB,aAAS,iBAAiB,SAAS,eAAe;AAClD,wBAAoB;AAAA,EACtB;AACA,mBAAiB;AAYjB,MAAI,CAAC,oBAAoB;AACvB,UAAM,OAAO,SAAS;AACtB,UAAM,YAAY,MAAM;AACtB,4BAAsB,MAAM,sBAAsB,gBAAgB,CAAC;AAAA,IACrE;AACA,QAAI,iBAAiB,SAAS,EAAE,QAAQ,MAAM;AAAA,MAC5C,YAAY;AAAA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,SAAS,eAAe,WAAW;AACrC,aAAS,iBAAiB,oBAAoB,QAAQ;AAAA,EACxD,OAAO;AACL,aAAS;AAAA,EACX;AACF;","names":[]}
package/dist/index.d.ts CHANGED
@@ -54,10 +54,14 @@ declare function parseFenceMeta(meta: string | null | undefined): BlockOptions;
54
54
  /**
55
55
  * Normalize an SVG produced by `@diagrammo/dgmo` for inline embedding:
56
56
  *
57
+ * - Compute a tight content bounding box from element coordinates and
58
+ * set the root `viewBox` to bbox+padding. Replaces the JS-side
59
+ * `getBBox()` step that can't measure dual-rendered SVGs hidden by
60
+ * color-mode CSS.
57
61
  * - Ensure the root `<svg>` has a `viewBox` so it scales responsively.
58
62
  * - Strip fixed `width="N"` / `height="N"` so CSS controls sizing.
59
- * - Remove any inline `background:` from the root style so the page background
60
- * shows through.
63
+ * - Remove any inline `background:` from the root style so the page
64
+ * background shows through.
61
65
  */
62
66
  declare function normalizeSvg(input: string): string;
63
67
 
package/dist/index.js CHANGED
@@ -4,7 +4,7 @@ import {
4
4
  remarkDgmo,
5
5
  renderDgmoBlock,
6
6
  resolveOptions
7
- } from "./chunk-7VVNWBXS.js";
7
+ } from "./chunk-E5QL6KCZ.js";
8
8
  export {
9
9
  remarkDgmo as default,
10
10
  normalizeSvg,
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  remarkDgmo
3
- } from "./chunk-7VVNWBXS.js";
3
+ } from "./chunk-E5QL6KCZ.js";
4
4
  export {
5
5
  remarkDgmo as default
6
6
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "remark-dgmo",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "Remark plugin to render DGMO diagrams from fenced code blocks at build time. Framework-agnostic core shared by astro-dgmo, docusaurus-plugin-dgmo, and any unified pipeline.",
5
5
  "license": "MIT",
6
6
  "repository": {