astro-dgmo 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,7 +2,11 @@
2
2
  import { visit } from "unist-util-visit";
3
3
 
4
4
  // src/render-block.ts
5
- import { render, encodeDiagramUrl } from "@diagrammo/dgmo";
5
+ import {
6
+ render,
7
+ encodeDiagramUrl,
8
+ palettes
9
+ } from "@diagrammo/dgmo";
6
10
  import { highlightDgmo, NORD_ROLE_STYLES } from "@diagrammo/dgmo/highlight";
7
11
 
8
12
  // src/options.ts
@@ -141,6 +145,9 @@ function escapeAttr(s) {
141
145
  }
142
146
 
143
147
  // src/render-block.ts
148
+ function resolvePalette(name) {
149
+ return Object.values(palettes).find((p) => p.id === name) ?? palettes.nord;
150
+ }
144
151
  async function renderDgmoBlock(source, meta, integrationOptions = {}) {
145
152
  const block = parseFenceMeta(meta);
146
153
  const base = resolveOptions(integrationOptions);
@@ -156,15 +163,16 @@ async function renderDgmoBlock(source, meta, integrationOptions = {}) {
156
163
  showOpenInEditor: block.showOpenInEditor ?? (block.mode ? showcase : base.showOpenInEditor)
157
164
  };
158
165
  const trimmed = source.trim();
166
+ const palette = resolvePalette(opts.palette);
159
167
  const { svg: rawSvg, diagnostics } = await render(trimmed, {
160
- palette: opts.palette,
168
+ palette,
161
169
  theme: opts.theme === "transparent" ? "transparent" : opts.theme
162
170
  });
163
171
  const svg = normalizeSvg(rawSvg);
164
172
  let editorUrl;
165
173
  if (opts.showOpenInEditor) {
166
- const encoded = encodeDiagramUrl(trimmed, { baseUrl: opts.editorBaseUrl });
167
- editorUrl = encoded.url ?? opts.editorBaseUrl;
174
+ const url = encodeDiagramUrl(trimmed, { baseUrl: opts.editorBaseUrl });
175
+ editorUrl = url ?? opts.editorBaseUrl;
168
176
  }
169
177
  const html = opts.mode === "showcase" ? renderShowcase(trimmed, svg, editorUrl, opts, block.title) : renderSimple(svg, opts, block.title);
170
178
  return { html, diagnostics };
@@ -257,4 +265,4 @@ function errorHtml(err, source) {
257
265
  export {
258
266
  remarkDgmo
259
267
  };
260
- //# sourceMappingURL=chunk-L3GVL5NB.js.map
268
+ //# sourceMappingURL=chunk-ILMP3TIX.js.map
@@ -0,0 +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 } from './render-block.js';\nimport type { DgmoIntegrationOptions } from './options.js';\n\nexport type RemarkDgmoOptions = DgmoIntegrationOptions;\n\ninterface FencePayload {\n source: string;\n meta: string | null;\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(tree: Root): 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 targets.push({\n parent: parent as Parent,\n index,\n payload: { source: node.value, meta: node.meta ?? null },\n });\n });\n if (targets.length === 0) return;\n\n const rendered = await Promise.all(\n targets.map(t =>\n renderDgmoBlock(t.payload.source, t.payload.meta, options).catch(\n err => ({\n html: errorHtml(err, t.payload.source),\n diagnostics: [],\n })\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(err: unknown, source: string): 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 return (\n `<div class=\"astro-dgmo astro-dgmo--error\" 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 { resolveOptions, type DgmoIntegrationOptions } from './options.js';\n\nfunction resolvePalette(name: string): PaletteConfig {\n return Object.values(palettes).find((p) => p.id === name) ?? palettes.nord;\n}\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 * 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: DgmoIntegrationOptions = {}\n): Promise<RenderBlockResult> {\n const block = parseFenceMeta(meta);\n const base = resolveOptions(integrationOptions);\n // Apply per-block overrides on top of integration defaults. If the block\n // changes mode, we re-resolve mode-dependent defaults from that mode unless\n // the block explicitly overrode them too.\n const effectiveMode = block.mode ?? base.mode;\n const showcase = effectiveMode === 'showcase';\n const opts = {\n ...base,\n mode: effectiveMode,\n palette: block.palette ?? base.palette,\n theme: block.theme ?? base.theme,\n showSource:\n block.showSource ??\n (block.mode ? showcase : base.showSource),\n showCopy:\n block.showCopy ??\n (block.mode ? showcase : base.showCopy),\n showOpenInEditor:\n block.showOpenInEditor ??\n (block.mode ? showcase : base.showOpenInEditor),\n };\n\n const trimmed = source.trim();\n const palette = resolvePalette(opts.palette);\n const { svg: rawSvg, diagnostics } = await render(trimmed, {\n palette,\n theme: opts.theme === 'transparent' ? 'transparent' : opts.theme,\n });\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 = opts.mode === 'showcase'\n ? renderShowcase(trimmed, svg, editorUrl, opts, block.title)\n : renderSimple(svg, opts, block.title);\n\n return { html, diagnostics };\n}\n\nfunction renderSimple(\n svg: string,\n opts: { wrapper: 'figure' | 'div'; className: string },\n title?: string\n): string {\n const Wrapper = opts.wrapper;\n const captionHtml = title\n ? `<figcaption class=\"astro-dgmo-caption\">${escapeHtml(title)}</figcaption>`\n : '';\n // For non-figure wrappers we still emit a caption div if a title was given.\n const captionFallback = title && Wrapper !== 'figure'\n ? `<div class=\"astro-dgmo-caption\">${escapeHtml(title)}</div>`\n : '';\n return (\n `<${Wrapper} class=\"${escapeAttr(opts.className)} astro-dgmo--diagram\">` +\n (Wrapper === 'figure' ? captionHtml : captionFallback) +\n `<div class=\"astro-dgmo-svg\">${svg}</div>` +\n `</${Wrapper}>`\n );\n}\n\nfunction renderShowcase(\n source: string,\n svg: string,\n editorUrl: string | undefined,\n opts: {\n wrapper: 'figure' | 'div';\n className: string;\n showSource: boolean;\n showCopy: boolean;\n showOpenInEditor: boolean;\n },\n title?: string\n): string {\n const Wrapper = opts.wrapper;\n const captionHtml = title\n ? Wrapper === 'figure'\n ? `<figcaption class=\"astro-dgmo-caption\">${escapeHtml(title)}</figcaption>`\n : `<div class=\"astro-dgmo-caption\">${escapeHtml(title)}</div>`\n : '';\n\n const sourceHtml = opts.showSource ? renderSource(source) : '';\n\n // Toolbar: \"DGMO\" label on the left; icon-only action buttons on the right.\n // Open-in-editor uses an external-link (box+arrow) icon; copy uses a\n // clipboard icon. Both live inline with the label so the showcase header\n // stays a single row.\n const openButton = opts.showOpenInEditor && editorUrl\n ? `<a href=\"${escapeAttr(editorUrl)}\" target=\"_blank\" rel=\"noopener noreferrer\" class=\"astro-dgmo-toolbar-btn astro-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=\"astro-dgmo-toolbar-btn astro-dgmo-copy\" aria-label=\"Copy to clipboard\" title=\"Copy to clipboard\" data-astro-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 = openButton || copyButton\n ? `<div class=\"astro-dgmo-toolbar-actions\">${openButton}${copyButton}</div>`\n : '';\n\n const toolbar = opts.showSource\n ? `<div class=\"astro-dgmo-toolbar\"><span class=\"astro-dgmo-toolbar-label\">dgmo</span>${toolbarActions}</div>`\n : '';\n\n return (\n `<${Wrapper} class=\"${escapeAttr(opts.className)} astro-dgmo--showcase\">` +\n captionHtml +\n `<div class=\"astro-dgmo-card\">` +\n (opts.showSource\n ? `<div class=\"astro-dgmo-source-wrap\">${toolbar}<div class=\"astro-dgmo-source-inner\">${sourceHtml}</div></div>`\n : '') +\n `<div class=\"astro-dgmo-svg\">${svg}</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]) =>\n `${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.\n // Astro's Shiki rehype plugin walks the hast and post-processes any\n // <pre><code> pair (even ones we emit from a remark plugin via raw HTML),\n // which clobbers our pre-rendered highlight spans with a plaintext\n // listing. Using a <span> as the inner element bypasses Shiki's matcher\n // while preserving preformatted-text semantics on the outer <pre>.\n return `<pre class=\"astro-dgmo-pre\"><span class=\"astro-dgmo-code\">${inner}</span></pre>`;\n}\n","export type Mode = 'diagram' | 'showcase';\n\nexport type Theme = 'light' | 'dark' | 'transparent';\n\nexport interface DgmoIntegrationOptions {\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 /** Default theme. Default: `dark`. */\n theme?: Theme;\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 `astro-dgmo`.\n * Useful as a styling hook.\n */\n className?: string;\n}\n\nexport type ResolvedOptions = Required<\n Omit<DgmoIntegrationOptions, '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(\n opts: DgmoIntegrationOptions = {}\n): 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 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 ?? 'astro-dgmo',\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 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']);\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 '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 *\n * Mirrors the post-processing previously inlined in `Diagram.astro` on the\n * marketing site.\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 => HT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+1,6 @@
1
1
  import {
2
2
  remarkDgmo
3
- } from "./chunk-L3GVL5NB.js";
3
+ } from "./chunk-ILMP3TIX.js";
4
4
  export {
5
5
  remarkDgmo as default
6
6
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astro-dgmo",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Astro integration to render DGMO diagrams from fenced code blocks at build time. Powered by @diagrammo/dgmo.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -53,7 +53,7 @@
53
53
  "prepublishOnly": "pnpm build && pnpm test"
54
54
  },
55
55
  "peerDependencies": {
56
- "@diagrammo/dgmo": ">=0.8.25",
56
+ "@diagrammo/dgmo": ">=0.15.0",
57
57
  "astro": ">=4.0.0"
58
58
  },
59
59
  "dependencies": {
@@ -63,7 +63,7 @@
63
63
  "unist-util-visit": "^5.0.0"
64
64
  },
65
65
  "devDependencies": {
66
- "@diagrammo/dgmo": "^0.8.26",
66
+ "@diagrammo/dgmo": "^0.15.0",
67
67
  "@types/mdast": "^4.0.4",
68
68
  "@types/node": "^22.10.0",
69
69
  "astro": "^6.1.5",
@@ -1 +0,0 @@
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 } from './render-block.js';\nimport type { DgmoIntegrationOptions } from './options.js';\n\nexport type RemarkDgmoOptions = DgmoIntegrationOptions;\n\ninterface FencePayload {\n source: string;\n meta: string | null;\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(tree: Root): 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 targets.push({\n parent: parent as Parent,\n index,\n payload: { source: node.value, meta: node.meta ?? null },\n });\n });\n if (targets.length === 0) return;\n\n const rendered = await Promise.all(\n targets.map(t =>\n renderDgmoBlock(t.payload.source, t.payload.meta, options).catch(\n err => ({\n html: errorHtml(err, t.payload.source),\n diagnostics: [],\n })\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(err: unknown, source: string): 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 return (\n `<div class=\"astro-dgmo astro-dgmo--error\" role=\"alert\">` +\n `<strong>dgmo render error:</strong> ${safeMsg}` +\n `<pre>${safeSrc}</pre></div>`\n );\n}\n","import { render, encodeDiagramUrl } from '@diagrammo/dgmo';\nimport { highlightDgmo, NORD_ROLE_STYLES } from '@diagrammo/dgmo/highlight';\nimport { resolveOptions, type DgmoIntegrationOptions } 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 * 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: DgmoIntegrationOptions = {}\n): Promise<RenderBlockResult> {\n const block = parseFenceMeta(meta);\n const base = resolveOptions(integrationOptions);\n // Apply per-block overrides on top of integration defaults. If the block\n // changes mode, we re-resolve mode-dependent defaults from that mode unless\n // the block explicitly overrode them too.\n const effectiveMode = block.mode ?? base.mode;\n const showcase = effectiveMode === 'showcase';\n const opts = {\n ...base,\n mode: effectiveMode,\n palette: block.palette ?? base.palette,\n theme: block.theme ?? base.theme,\n showSource:\n block.showSource ??\n (block.mode ? showcase : base.showSource),\n showCopy:\n block.showCopy ??\n (block.mode ? showcase : base.showCopy),\n showOpenInEditor:\n block.showOpenInEditor ??\n (block.mode ? showcase : base.showOpenInEditor),\n };\n\n const trimmed = source.trim();\n const { svg: rawSvg, diagnostics } = await render(trimmed, {\n palette: opts.palette,\n theme: opts.theme === 'transparent' ? 'transparent' : opts.theme,\n });\n const svg = normalizeSvg(rawSvg);\n\n let editorUrl: string | undefined;\n if (opts.showOpenInEditor) {\n const encoded = encodeDiagramUrl(trimmed, { baseUrl: opts.editorBaseUrl });\n editorUrl = encoded.url ?? opts.editorBaseUrl;\n }\n\n const html = opts.mode === 'showcase'\n ? renderShowcase(trimmed, svg, editorUrl, opts, block.title)\n : renderSimple(svg, opts, block.title);\n\n return { html, diagnostics };\n}\n\nfunction renderSimple(\n svg: string,\n opts: { wrapper: 'figure' | 'div'; className: string },\n title?: string\n): string {\n const Wrapper = opts.wrapper;\n const captionHtml = title\n ? `<figcaption class=\"astro-dgmo-caption\">${escapeHtml(title)}</figcaption>`\n : '';\n // For non-figure wrappers we still emit a caption div if a title was given.\n const captionFallback = title && Wrapper !== 'figure'\n ? `<div class=\"astro-dgmo-caption\">${escapeHtml(title)}</div>`\n : '';\n return (\n `<${Wrapper} class=\"${escapeAttr(opts.className)} astro-dgmo--diagram\">` +\n (Wrapper === 'figure' ? captionHtml : captionFallback) +\n `<div class=\"astro-dgmo-svg\">${svg}</div>` +\n `</${Wrapper}>`\n );\n}\n\nfunction renderShowcase(\n source: string,\n svg: string,\n editorUrl: string | undefined,\n opts: {\n wrapper: 'figure' | 'div';\n className: string;\n showSource: boolean;\n showCopy: boolean;\n showOpenInEditor: boolean;\n },\n title?: string\n): string {\n const Wrapper = opts.wrapper;\n const captionHtml = title\n ? Wrapper === 'figure'\n ? `<figcaption class=\"astro-dgmo-caption\">${escapeHtml(title)}</figcaption>`\n : `<div class=\"astro-dgmo-caption\">${escapeHtml(title)}</div>`\n : '';\n\n const sourceHtml = opts.showSource ? renderSource(source) : '';\n\n // Toolbar: \"DGMO\" label on the left; icon-only action buttons on the right.\n // Open-in-editor uses an external-link (box+arrow) icon; copy uses a\n // clipboard icon. Both live inline with the label so the showcase header\n // stays a single row.\n const openButton = opts.showOpenInEditor && editorUrl\n ? `<a href=\"${escapeAttr(editorUrl)}\" target=\"_blank\" rel=\"noopener noreferrer\" class=\"astro-dgmo-toolbar-btn astro-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=\"astro-dgmo-toolbar-btn astro-dgmo-copy\" aria-label=\"Copy to clipboard\" title=\"Copy to clipboard\" data-astro-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 = openButton || copyButton\n ? `<div class=\"astro-dgmo-toolbar-actions\">${openButton}${copyButton}</div>`\n : '';\n\n const toolbar = opts.showSource\n ? `<div class=\"astro-dgmo-toolbar\"><span class=\"astro-dgmo-toolbar-label\">dgmo</span>${toolbarActions}</div>`\n : '';\n\n return (\n `<${Wrapper} class=\"${escapeAttr(opts.className)} astro-dgmo--showcase\">` +\n captionHtml +\n `<div class=\"astro-dgmo-card\">` +\n (opts.showSource\n ? `<div class=\"astro-dgmo-source-wrap\">${toolbar}<div class=\"astro-dgmo-source-inner\">${sourceHtml}</div></div>`\n : '') +\n `<div class=\"astro-dgmo-svg\">${svg}</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]) =>\n `${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.\n // Astro's Shiki rehype plugin walks the hast and post-processes any\n // <pre><code> pair (even ones we emit from a remark plugin via raw HTML),\n // which clobbers our pre-rendered highlight spans with a plaintext\n // listing. Using a <span> as the inner element bypasses Shiki's matcher\n // while preserving preformatted-text semantics on the outer <pre>.\n return `<pre class=\"astro-dgmo-pre\"><span class=\"astro-dgmo-code\">${inner}</span></pre>`;\n}\n","export type Mode = 'diagram' | 'showcase';\n\nexport type Theme = 'light' | 'dark' | 'transparent';\n\nexport interface DgmoIntegrationOptions {\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 /** Default theme. Default: `dark`. */\n theme?: Theme;\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 `astro-dgmo`.\n * Useful as a styling hook.\n */\n className?: string;\n}\n\nexport type ResolvedOptions = Required<\n Omit<DgmoIntegrationOptions, '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(\n opts: DgmoIntegrationOptions = {}\n): 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 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 ?? 'astro-dgmo',\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 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']);\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 '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 *\n * Mirrors the post-processing previously inlined in `Diagram.astro` on the\n * marketing site.\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,SAAS,QAAQ,wBAAwB;AACzC,SAAS,eAAe,wBAAwB;;;ACkEzC,SAAS,eACd,OAA+B,CAAC,GACf;AACjB,QAAM,OAAa,KAAK,QAAQ;AAChC,QAAM,WAAW,SAAS;AAC1B,SAAO;AAAA,IACL;AAAA,IACA,SAAS,KAAK,WAAW;AAAA,IACzB,OAAO,KAAK,SAAS;AAAA,IACrB,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,EAC/B;AACF;;;AC9DA,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,UAAU,KAAK;AAAA,EACvB,gBAAgB,EAAE,kBAAkB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