Turn any idea, plan, or codebase into a beautiful interactive diagram. An agent skill for Claude Code, Codex, and more.
HTML agent-skillsai-agentsarchitecture-diagramclaude-codeclaude-skillscodexcoding-agentsdeepseek-harnessdeveloper-toolsdiagramsdiagrams-as-codedsh-pluginflowchartllmmermaidopencodesequence-diagramsoftware-architecturesystem-designvisualization
Regenerate example renders; consolidate images into docs/assets
tt-a1i747f2a478d8a
diff --git a/docs/assets/archify-lifecycle.png b/docs/assets/archify-lifecycle.pngindex 0234a105..cb8300fa 100644Binary files a/docs/assets/archify-lifecycle.png and b/docs/assets/archify-lifecycle.png differdiff --git a/examples/images/archify-light.png b/docs/assets/archify-light.pngsimilarity index 100%rename from examples/images/archify-light.pngrename to docs/assets/archify-light.pngdiff --git a/examples/images/archify-menu.png b/docs/assets/archify-menu.pngsimilarity index 100%rename from examples/images/archify-menu.pngrename to docs/assets/archify-menu.pngdiff --git a/docs/assets/archify-workflow.png b/docs/assets/archify-workflow.pngnew file mode 100644index 00000000..5fd62c84Binary files /dev/null and b/docs/assets/archify-workflow.png differdiff --git a/examples/images/claude-skills-settings.png b/docs/assets/claude-skills-settings.pngsimilarity index 100%rename from examples/images/claude-skills-settings.pngrename to docs/assets/claude-skills-settings.pngdiff --git a/examples/dataflow-product-analytics.html b/examples/dataflow-product-analytics.htmlindex 8f9383a3..34f2599b 100644--- a/examples/dataflow-product-analytics.html+++ b/examples/dataflow-product-analytics.html@@ -3,8 +3,36 @@<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0">+ <meta name="generator" content="archify 2.6.0"><title>Product Analytics Data Flow Diagram</title>- <link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;600;700&display=swap" rel="stylesheet">+ <script>+ // Resolve the theme before first paint so light-preference users don't+ // see a dark flash. The toolbar script below re-applies with UI state.+ (function () {+ try {+ var theme = null;+ try {+ var param = new URLSearchParams(window.location.search).get('theme');+ if (param === 'light' || param === 'dark') theme = param;+ } catch (_) {}+ if (!theme) {+ try { theme = localStorage.getItem('archify-theme'); } catch (_) {}+ }+ if (theme !== 'light' && theme !== 'dark') {+ theme = window.matchMedia('(prefers-color-scheme: light)').matches ? 'light' : 'dark';+ }+ document.documentElement.setAttribute('data-theme', theme);+ } catch (_) {}+ })();+ </script>+ <!-- Async font load: a blackholed network must not block first paint.+ The body font stack falls back to system monospace until it lands. -->+ <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>+ <link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;600;700&display=swap"+ rel="stylesheet" media="print" onload="this.media='all'">+ <noscript>+ <link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;600;700&display=swap" rel="stylesheet">+ </noscript><style>/* ==========================================================THEME VARIABLES — switch by toggling [data-theme] on <html>@@ -16,6 +44,8 @@--text: #ffffff;--text-muted: #94a3b8;--text-dim: #475569;+ /* UI chrome (menu hints, footer) needs more contrast than SVG .t-dim accents */+ --text-faint: #7d8da1;--panel: rgba(15, 23, 42, 0.5);--panel-border: #1e293b;@@ -57,6 +87,7 @@--text: #0f172a;--text-muted: #64748b;--text-dim: #94a3b8;+ --text-faint: #64748b;--panel: #ffffff;--panel-border: #e2e8f0;@@ -93,7 +124,7 @@* { margin: 0; padding: 0; box-sizing: border-box; }body {- font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;+ font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, 'DejaVu Sans Mono', 'Liberation Mono', 'Noto Sans Mono CJK SC', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', monospace;background: var(--bg);min-height: 100vh;padding: 2rem;@@ -199,7 +230,7 @@.footer {text-align: center;margin-top: 1.5rem;- color: var(--text-dim);+ color: var(--text-faint);font-size: 0.75rem;}@@ -212,6 +243,9 @@@page { size: landscape; margin: 1.5cm; }@media print {+ /* Force the FULL light palette — including component fills/strokes and+ lane/arrow colors — so printing from dark theme doesn't put neon+ strokes and translucent dark fills on white paper. */:root, [data-theme="dark"], [data-theme="light"] {--bg: #ffffff;--grid: transparent;@@ -220,11 +254,30 @@--text: #0f172a;--text-muted: #475569;--text-dim: #94a3b8;+ --text-faint: #64748b;--mask: #ffffff;+ --lane-fill: rgba(248, 250, 252, 0.65);+ --lane-stroke: #cbd5e1;+ --arrow: #94a3b8;+ --arrow-emphasis: #059669;+ --frontend-fill: rgba(34, 211, 238, 0.15);+ --frontend-stroke: #0891b2;+ --backend-fill: rgba(52, 211, 153, 0.18);+ --backend-stroke: #059669;+ --database-fill: rgba(167, 139, 250, 0.2);+ --database-stroke: #7c3aed;+ --cloud-fill: rgba(251, 191, 36, 0.18);+ --cloud-stroke: #d97706;+ --security-fill: rgba(251, 113, 133, 0.15);+ --security-stroke: #e11d48;+ --messagebus-fill: rgba(251, 146, 60, 0.15);+ --messagebus-stroke:#ea580c;+ --external-fill: rgba(148, 163, 184, 0.18);+ --external-stroke: #64748b;}body { background: #ffffff !important; padding: 0; }.container { max-width: none; }- .toolbar, .archify-toast { display: none !important; }+ .toolbar, .archify-toast, .no-print { display: none !important; }.diagram-container, .card { box-shadow: none; border-color: #e2e8f0; }.cards { grid-template-columns: 1fr 1fr; }/* Ensure elements break sensibly across pages */@@ -295,7 +348,7 @@background: var(--toolbar-hover);}.toolbar .export-menu .hint {- color: var(--text-dim);+ color: var(--text-faint);font-size: 0.625rem;}.toolbar .export-menu hr {@@ -426,11 +479,11 @@</button><div class="export-menu" id="export-menu" role="menu" aria-label="Export"><button data-action="copy" type="button" role="menuitem" tabindex="-1">Copy to clipboard <span class="hint">PNG</span></button>- <hr role="separator" aria-hidden="true">+ <hr role="separator"><button data-format="png" type="button" role="menuitem" tabindex="-1">Download PNG</button><button data-format="jpeg" type="button" role="menuitem" tabindex="-1">Download JPEG</button><button data-format="webp" type="button" role="menuitem" tabindex="-1">Download WebP</button>- <hr role="separator" aria-hidden="true">+ <hr role="separator"><button data-format="svg" type="button" role="menuitem" tabindex="-1">Download SVG <span class="hint">vector</span></button></div></div>@@ -448,7 +501,7 @@<!-- Main Diagram --><div class="diagram-container">- <svg viewBox="0 0 1080 760">+ <svg viewBox="0 0 1080 760" role="img" aria-label="Product Analytics Data Flow — Events, consent, PII isolation, warehouse sync, and downstream analytics (data-flow diagram)"><!-- Definitions --><defs><marker id="arrowhead" markerWidth="10" markerHeight="7" refX="9" refY="3.5" orient="auto">@@ -646,7 +699,7 @@<!-- Footer --><p class="footer">- Data-flow diagram • Built with Archify • Press <kbd>T</kbd> for theme and <kbd>E</kbd> for export+ Data-flow diagram • Built with Archify<span class="no-print"> • Press <kbd>T</kbd> for theme and <kbd>E</kbd> for export</span></p></div>@@ -663,13 +716,27 @@var icon = document.getElementById('theme-icon');var label = document.getElementById('theme-label');- function resolveInitial() {+ // localStorage can throw (blocked cookies, sandboxed iframes); the whole+ // script element dies on an uncaught error, so guard every access.+ function readStored() {+ try { return localStorage.getItem(STORAGE_KEY); } catch (_) { return null; }+ }+ function writeStored(value) {+ try { localStorage.setItem(STORAGE_KEY, value); } catch (_) {}+ }+ function urlOverride() {// URL param wins (useful for deterministic screenshots / share links)try {var param = new URLSearchParams(window.location.search).get('theme');if (param === 'light' || param === 'dark') return param;} catch (_) {}- var saved = localStorage.getItem(STORAGE_KEY);+ return null;+ }++ function resolveInitial() {+ var fromUrl = urlOverride();+ if (fromUrl) return fromUrl;+ var saved = readStored();if (saved === 'light' || saved === 'dark') return saved;return window.matchMedia('(prefers-color-scheme: light)').matches ? 'light' : 'dark';}@@ -684,12 +751,24 @@function toggle() {var next = html.getAttribute('data-theme') === 'dark' ? 'light' : 'dark';apply(next);- localStorage.setItem(STORAGE_KEY, next);+ writeStored(next);}apply(resolveInitial());btn.addEventListener('click', toggle);+ // Follow live OS theme changes while the user has no explicit preference.+ try {+ var media = window.matchMedia('(prefers-color-scheme: light)');+ var onChange = function (e) {+ var saved = readStored();+ if (urlOverride() || saved === 'light' || saved === 'dark') return;+ apply(e.matches ? 'light' : 'dark');+ };+ if (media.addEventListener) media.addEventListener('change', onChange);+ else if (media.addListener) media.addListener(onChange);+ } catch (_) {}+return { toggle: toggle };})();@@ -709,7 +788,10 @@var RASTER_SCALE = 4;function diagramFilename() {- var title = (document.title || 'diagram').replace(/\s+Architecture(\s+Diagram)?$/i, '').trim();+ var title = (document.title || 'diagram')+ .replace(/\s+Architecture(\s+Diagram)?$/i, '')+ .replace(/\s+Diagram$/i, '')+ .trim();return title.replace(/[^a-z0-9_\-]+/gi, '-').toLowerCase().replace(/^-+|-+$/g, '') || 'diagram';@@ -752,21 +834,37 @@clone.setAttribute('height', vb.height * scale);clone.setAttribute('xmlns', 'http://www.w3.org/2000/svg');- var hostStyle = Array.prototype.map.call(document.querySelectorAll('style'), function (s) {- return s.textContent;- }).join('\n');-- var varNames = [- '--bg','--grid','--text','--text-muted','--text-dim',- '--arrow','--arrow-emphasis','--mask',- '--frontend-fill','--frontend-stroke',- '--backend-fill','--backend-stroke',- '--database-fill','--database-stroke',- '--cloud-fill','--cloud-stroke',- '--security-fill','--security-stroke',- '--messagebus-fill','--messagebus-stroke',- '--external-fill','--external-stroke'- ];+ // Only the SVG-relevant rules: semantic classes, markers, and the+ // theme variable blocks. Toolbar/cards/print CSS can never apply+ // inside a standalone SVG and would only bloat the export.+ var hostStyle = (function () {+ var out = [];+ Array.prototype.forEach.call(document.styleSheets, function (sheet) {+ var rules;+ try { rules = sheet.cssRules; } catch (_) { return; } // cross-origin+ if (!rules) return;+ Array.prototype.forEach.call(rules, function (rule) {+ if (rule.type !== 1) return; // plain style rules only+ var sel = rule.selectorText || '';+ if (/(^|,)\s*(svg|:root|\[data-theme|\.c-|\.t-|\.a-|\.m-)/.test(sel)) {+ out.push(rule.cssText);+ }+ });+ });+ return out.join('\n');+ })();++ // Derive the variable list from the stylesheet so newly added theme+ // variables can never be missed by the export pipeline again+ // (--lane-fill/--lane-stroke once were).+ var varNames = (function () {+ var seen = {};+ var names = [];+ (hostStyle.match(/--[a-zA-Z0-9-]+(?=\s*:)/g) || []).forEach(function (n) {+ if (!seen[n]) { seen[n] = true; names.push(n); }+ });+ return names;+ })();// Resolve the full variable set for a given data-theme via an// off-DOM probe, independent of what the viewer is currently set to.@@ -811,7 +909,7 @@style.textContent =fontFallback + "\n" +- "svg { font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace; }\n" ++ "svg { font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, 'DejaVu Sans Mono', 'Liberation Mono', 'Noto Sans Mono CJK SC', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', monospace; }\n" +hostStyle + "\n" +":root, svg { " + darkVars + " }\n" +"@media (prefers-color-scheme: light) { :root, svg { " + lightVars + " } }\n" +@@ -839,7 +937,7 @@// Keep this order.style.textContent =fontFallback + "\n" +- "svg { font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace; }\n" ++ "svg { font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, 'DejaVu Sans Mono', 'Liberation Mono', 'Noto Sans Mono CJK SC', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', monospace; }\n" +hostStyle + "\n" +":root, svg { " + vars + " }\n";@@ -964,23 +1062,30 @@});// ---- Toast ----------------------------------------------------------+ // A live region only announces CHANGES to an existing node, so the toast+ // element is created once up front and updated in place.+ var toastEl = document.createElement('div');+ toastEl.className = 'archify-toast';+ toastEl.setAttribute('role', 'status');+ document.body.appendChild(toastEl);+ var toastTimer = null;+function toast(msg) {- var t = document.createElement('div');- t.className = 'archify-toast';- t.textContent = msg;- document.body.appendChild(t);- requestAnimationFrame(function () { t.classList.add('show'); });- setTimeout(function () {- t.classList.remove('show');- setTimeout(function () { t.remove(); }, 300);- }, 1500);+ toastEl.textContent = '';+ requestAnimationFrame(function () {+ toastEl.textContent = msg;+ toastEl.classList.add('show');+ });+ clearTimeout(toastTimer);+ toastTimer = setTimeout(function () { toastEl.classList.remove('show'); }, 1500);}- function open() {+ function open(focusLast) {menu.classList.add('open');btn.setAttribute('aria-expanded', 'true');- var first = items().filter(function (i) { return !i.disabled; })[0];- if (first) first.focus();+ var available = items().filter(function (i) { return !i.disabled; });+ var target = focusLast ? available[available.length - 1] : available[0];+ if (target) target.focus();}function close(focusTrigger) {menu.classList.remove('open');@@ -994,6 +1099,13 @@if (isOpen()) close(false);else open();});+ // APG menu-button pattern: ArrowDown/ArrowUp on the trigger opens the menu.+ btn.addEventListener('keydown', function (e) {+ if (e.key === 'ArrowDown' || e.key === 'ArrowUp') {+ e.preventDefault();+ if (!isOpen()) open(e.key === 'ArrowUp');+ }+ });document.addEventListener('click', function (e) {if (!menu.contains(e.target) && e.target !== btn) close(false);});@@ -1029,7 +1141,7 @@function runExport(format) {var base = diagramFilename();- close(false);+ close(true);return (format === 'svg'? Promise.resolve(serializeSvg(1, { autoTheme: true })).then(function (d) {download(new Blob([d.svgString], { type: 'image/svg+xml;charset=utf-8' }), base + '.svg');@@ -1044,14 +1156,25 @@}function runCopy() {- close(false);+ close(true);if (!canCopyImage()) {alert('Clipboard image write not supported in this browser.');return;}- return rasterize('png').then(function (blob) {- return navigator.clipboard.write([new ClipboardItem({ 'image/png': blob })]);- }).then(function () {+ // WebKit requires ClipboardItem to be constructed synchronously inside+ // the user gesture — pass the pending Promise<Blob> as the item value.+ // Browsers that reject promise values throw synchronously; fall back+ // to awaiting the blob first (works in Chromium/Firefox).+ var blobPromise = rasterize('png');+ var writePromise;+ try {+ writePromise = navigator.clipboard.write([new ClipboardItem({ 'image/png': blobPromise })]);+ } catch (_) {+ writePromise = blobPromise.then(function (blob) {+ return navigator.clipboard.write([new ClipboardItem({ 'image/png': blob })]);+ });+ }+ return writePromise.then(function () {toast('Copied PNG to clipboard');}).catch(function (err) {console.error(err);diff --git a/examples/images/archify-dark.png b/examples/images/archify-dark.pngdeleted file mode 100644index 481b6751..00000000Binary files a/examples/images/archify-dark.png and /dev/null differdiff --git a/examples/images/archify-dataflow.png b/examples/images/archify-dataflow.pngdeleted file mode 100644index 471d5903..00000000Binary files a/examples/images/archify-dataflow.png and /dev/null differdiff --git a/examples/images/archify-lifecycle.png b/examples/images/archify-lifecycle.pngdeleted file mode 100644index 0234a105..00000000Binary files a/examples/images/archify-lifecycle.png and /dev/null differdiff --git a/examples/images/archify-print.png b/examples/images/archify-print.pngdeleted file mode 100644index 8c00c1e0..00000000Binary files a/examples/images/archify-print.png and /dev/null differdiff --git a/examples/images/archify-readme-hero.png b/examples/images/archify-readme-hero.pngdeleted file mode 100644index ae202d1f..00000000Binary files a/examples/images/archify-readme-hero.png and /dev/null differdiff --git a/examples/images/archify-sequence.png b/examples/images/archify-sequence.pngdeleted file mode 100644index f1d8ce69..00000000Binary files a/examples/images/archify-sequence.png and /dev/null differdiff --git a/examples/images/archify-social-preview.png b/examples/images/archify-social-preview.pngdeleted file mode 100644index a0967d7a..00000000Binary files a/examples/images/archify-social-preview.png and /dev/null differdiff --git a/examples/lifecycle-agent-run.html b/examples/lifecycle-agent-run.htmlindex 395cb31b..5c5301af 100644--- a/examples/lifecycle-agent-run.html+++ b/examples/lifecycle-agent-run.html@@ -3,8 +3,36 @@<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0">+ <meta name="generator" content="archify 2.6.0"><title>Agent Run Lifecycle Diagram</title>- <link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;600;700&display=swap" rel="stylesheet">+ <script>+ // Resolve the theme before first paint so light-preference users don't+ // see a dark flash. The toolbar script below re-applies with UI state.+ (function () {+ try {+ var theme = null;+ try {+ var param = new URLSearchParams(window.location.search).get('theme');+ if (param === 'light' || param === 'dark') theme = param;+ } catch (_) {}+ if (!theme) {+ try { theme = localStorage.getItem('archify-theme'); } catch (_) {}+ }+ if (theme !== 'light' && theme !== 'dark') {+ theme = window.matchMedia('(prefers-color-scheme: light)').matches ? 'light' : 'dark';+ }+ document.documentElement.setAttribute('data-theme', theme);+ } catch (_) {}+ })();+ </script>+ <!-- Async font load: a blackholed network must not block first paint.+ The body font stack falls back to system monospace until it lands. -->+ <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>+ <link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;600;700&display=swap"+ rel="stylesheet" media="print" onload="this.media='all'">+ <noscript>+ <link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;600;700&display=swap" rel="stylesheet">+ </noscript><style>/* ==========================================================THEME VARIABLES — switch by toggling [data-theme] on <html>@@ -16,6 +44,8 @@--text: #ffffff;--text-muted: #94a3b8;--text-dim: #475569;+ /* UI chrome (menu hints, footer) needs more contrast than SVG .t-dim accents */+ --text-faint: #7d8da1;--panel: rgba(15, 23, 42, 0.5);--panel-border: #1e293b;@@ -57,6 +87,7 @@--text: #0f172a;--text-muted: #64748b;--text-dim: #94a3b8;+ --text-faint: #64748b;--panel: #ffffff;--panel-border: #e2e8f0;@@ -93,7 +124,7 @@* { margin: 0; padding: 0; box-sizing: border-box; }body {- font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;+ font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, 'DejaVu Sans Mono', 'Liberation Mono', 'Noto Sans Mono CJK SC', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', monospace;background: var(--bg);min-height: 100vh;padding: 2rem;@@ -199,7 +230,7 @@.footer {text-align: center;margin-top: 1.5rem;- color: var(--text-dim);+ color: var(--text-faint);font-size: 0.75rem;}@@ -212,6 +243,9 @@@page { size: landscape; margin: 1.5cm; }@media print {+ /* Force the FULL light palette — including component fills/strokes and+ lane/arrow colors — so printing from dark theme doesn't put neon+ strokes and translucent dark fills on white paper. */:root, [data-theme="dark"], [data-theme="light"] {--bg: #ffffff;--grid: transparent;@@ -220,11 +254,30 @@--text: #0f172a;--text-muted: #475569;--text-dim: #94a3b8;+ --text-faint: #64748b;--mask: #ffffff;+ --lane-fill: rgba(248, 250, 252, 0.65);+ --lane-stroke: #cbd5e1;+ --arrow: #94a3b8;+ --arrow-emphasis: #059669;+ --frontend-fill: rgba(34, 211, 238, 0.15);+ --frontend-stroke: #0891b2;+ --backend-fill: rgba(52, 211, 153, 0.18);+ --backend-stroke: #059669;+ --database-fill: rgba(167, 139, 250, 0.2);+ --database-stroke: #7c3aed;+ --cloud-fill: rgba(251, 191, 36, 0.18);+ --cloud-stroke: #d97706;+ --security-fill: rgba(251, 113, 133, 0.15);+ --security-stroke: #e11d48;+ --messagebus-fill: rgba(251, 146, 60, 0.15);+ --messagebus-stroke:#ea580c;+ --external-fill: rgba(148, 163, 184, 0.18);+ --external-stroke: #64748b;}body { background: #ffffff !important; padding: 0; }.container { max-width: none; }- .toolbar, .archify-toast { display: none !important; }+ .toolbar, .archify-toast, .no-print { display: none !important; }.diagram-container, .card { box-shadow: none; border-color: #e2e8f0; }.cards { grid-template-columns: 1fr 1fr; }/* Ensure elements break sensibly across pages */@@ -295,7 +348,7 @@background: var(--toolbar-hover);}.toolbar .export-menu .hint {- color: var(--text-dim);+ color: var(--text-faint);font-size: 0.625rem;}.toolbar .export-menu hr {@@ -426,11 +479,11 @@</button><div class="export-menu" id="export-menu" role="menu" aria-label="Export"><button data-action="copy" type="button" role="menuitem" tabindex="-1">Copy to clipboard <span class="hint">PNG</span></button>- <hr role="separator" aria-hidden="true">+ <hr role="separator"><button data-format="png" type="button" role="menuitem" tabindex="-1">Download PNG</button><button data-format="jpeg" type="button" role="menuitem" tabindex="-1">Download JPEG</button><button data-format="webp" type="button" role="menuitem" tabindex="-1">Download WebP</button>- <hr role="separator" aria-hidden="true">+ <hr role="separator"><button data-format="svg" type="button" role="menuitem" tabindex="-1">Download SVG <span class="hint">vector</span></button></div></div>@@ -448,7 +501,7 @@<!-- Main Diagram --><div class="diagram-container">- <svg viewBox="0 0 980 660">+ <svg viewBox="0 0 980 660" role="img" aria-label="Agent Run Lifecycle — State machine for planning, tool execution, human approval, retries, and terminal outcomes (lifecycle diagram)"><!-- Definitions --><defs><marker id="arrowhead" markerWidth="10" markerHeight="7" refX="9" refY="3.5" orient="auto">@@ -475,9 +528,9 @@<path d="M 72 112 L 908 112" class="a-default" stroke-width="0.8" stroke-dasharray="3,8"/><text x="72" y="100" class="t-dim" font-size="10" font-weight="600">01 / Lifecycle phases</text><path d="M 72 264 L 908 264" class="a-default" stroke-width="0.8" stroke-dasharray="3,8"/>- <text x="72" y="252" class="t-dim" font-size="10" font-weight="600">02 / Interruptions + recovery</text>+ <text x="72" y="252" class="t-dim" font-size="10" font-weight="600">02 / Interruptions + Recovery loop</text><path d="M 72 436 L 908 436" class="a-default" stroke-width="0.8" stroke-dasharray="3,8"/>- <text x="72" y="424" class="t-dim" font-size="10" font-weight="600">03 / Outcomes</text>+ <text x="72" y="424" class="t-dim" font-size="10" font-weight="600">03 / Terminal exits</text><!-- Primary lifecycle rail --><path d="M 154 157 L 748 157" class="a-emphasis" stroke-width="2.2" marker-end="url(#arrowhead-emphasis)"/>@@ -616,7 +669,7 @@<!-- Footer --><p class="footer">- Lifecycle diagram • Built with Archify • Press <kbd>T</kbd> for theme and <kbd>E</kbd> for export+ Lifecycle diagram • Built with Archify<span class="no-print"> • Press <kbd>T</kbd> for theme and <kbd>E</kbd> for export</span></p></div>@@ -633,13 +686,27 @@var icon = document.getElementById('theme-icon');var label = document.getElementById('theme-label');- function resolveInitial() {+ // localStorage can throw (blocked cookies, sandboxed iframes); the whole+ // script element dies on an uncaught error, so guard every access.+ function readStored() {+ try { return localStorage.getItem(STORAGE_KEY); } catch (_) { return null; }+ }+ function writeStored(value) {+ try { localStorage.setItem(STORAGE_KEY, value); } catch (_) {}+ }+ function urlOverride() {// URL param wins (useful for deterministic screenshots / share links)try {var param = new URLSearchParams(window.location.search).get('theme');if (param === 'light' || param === 'dark') return param;} catch (_) {}- var saved = localStorage.getItem(STORAGE_KEY);+ return null;+ }++ function resolveInitial() {+ var fromUrl = urlOverride();+ if (fromUrl) return fromUrl;+ var saved = readStored();if (saved === 'light' || saved === 'dark') return saved;return window.matchMedia('(prefers-color-scheme: light)').matches ? 'light' : 'dark';}@@ -654,12 +721,24 @@function toggle() {var next = html.getAttribute('data-theme') === 'dark' ? 'light' : 'dark';apply(next);- localStorage.setItem(STORAGE_KEY, next);+ writeStored(next);}apply(resolveInitial());btn.addEventListener('click', toggle);+ // Follow live OS theme changes while the user has no explicit preference.+ try {+ var media = window.matchMedia('(prefers-color-scheme: light)');+ var onChange = function (e) {+ var saved = readStored();+ if (urlOverride() || saved === 'light' || saved === 'dark') return;+ apply(e.matches ? 'light' : 'dark');+ };+ if (media.addEventListener) media.addEventListener('change', onChange);+ else if (media.addListener) media.addListener(onChange);+ } catch (_) {}+return { toggle: toggle };})();@@ -679,7 +758,10 @@var RASTER_SCALE = 4;function diagramFilename() {- var title = (document.title || 'diagram').replace(/\s+Architecture(\s+Diagram)?$/i, '').trim();+ var title = (document.title || 'diagram')+ .replace(/\s+Architecture(\s+Diagram)?$/i, '')+ .replace(/\s+Diagram$/i, '')+ .trim();return title.replace(/[^a-z0-9_\-]+/gi, '-').toLowerCase().replace(/^-+|-+$/g, '') || 'diagram';@@ -722,21 +804,37 @@clone.setAttribute('height', vb.height * scale);clone.setAttribute('xmlns', 'http://www.w3.org/2000/svg');- var hostStyle = Array.prototype.map.call(document.querySelectorAll('style'), function (s) {- return s.textContent;- }).join('\n');-- var varNames = [- '--bg','--grid','--text','--text-muted','--text-dim',- '--arrow','--arrow-emphasis','--mask',- '--frontend-fill','--frontend-stroke',- '--backend-fill','--backend-stroke',- '--database-fill','--database-stroke',- '--cloud-fill','--cloud-stroke',- '--security-fill','--security-stroke',- '--messagebus-fill','--messagebus-stroke',- '--external-fill','--external-stroke'- ];+ // Only the SVG-relevant rules: semantic classes, markers, and the+ // theme variable blocks. Toolbar/cards/print CSS can never apply+ // inside a standalone SVG and would only bloat the export.+ var hostStyle = (function () {+ var out = [];+ Array.prototype.forEach.call(document.styleSheets, function (sheet) {+ var rules;+ try { rules = sheet.cssRules; } catch (_) { return; } // cross-origin+ if (!rules) return;+ Array.prototype.forEach.call(rules, function (rule) {+ if (rule.type !== 1) return; // plain style rules only+ var sel = rule.selectorText || '';+ if (/(^|,)\s*(svg|:root|\[data-theme|\.c-|\.t-|\.a-|\.m-)/.test(sel)) {+ out.push(rule.cssText);+ }+ });+ });+ return out.join('\n');+ })();++ // Derive the variable list from the stylesheet so newly added theme+ // variables can never be missed by the export pipeline again+ // (--lane-fill/--lane-stroke once were).+ var varNames = (function () {+ var seen = {};+ var names = [];+ (hostStyle.match(/--[a-zA-Z0-9-]+(?=\s*:)/g) || []).forEach(function (n) {+ if (!seen[n]) { seen[n] = true; names.push(n); }+ });+ return names;+ })();// Resolve the full variable set for a given data-theme via an// off-DOM probe, independent of what the viewer is currently set to.@@ -781,7 +879,7 @@style.textContent =fontFallback + "\n" +- "svg { font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace; }\n" ++ "svg { font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, 'DejaVu Sans Mono', 'Liberation Mono', 'Noto Sans Mono CJK SC', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', monospace; }\n" +hostStyle + "\n" +":root, svg { " + darkVars + " }\n" +"@media (prefers-color-scheme: light) { :root, svg { " + lightVars + " } }\n" +@@ -809,7 +907,7 @@// Keep this order.style.textContent =fontFallback + "\n" +- "svg { font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace; }\n" ++ "svg { font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, 'DejaVu Sans Mono', 'Liberation Mono', 'Noto Sans Mono CJK SC', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', monospace; }\n" +hostStyle + "\n" +":root, svg { " + vars + " }\n";@@ -934,23 +1032,30 @@});// ---- Toast ----------------------------------------------------------+ // A live region only announces CHANGES to an existing node, so the toast+ // element is created once up front and updated in place.+ var toastEl = document.createElement('div');+ toastEl.className = 'archify-toast';+ toastEl.setAttribute('role', 'status');+ document.body.appendChild(toastEl);+ var toastTimer = null;+function toast(msg) {- var t = document.createElement('div');- t.className = 'archify-toast';- t.textContent = msg;- document.body.appendChild(t);- requestAnimationFrame(function () { t.classList.add('show'); });- setTimeout(function () {- t.classList.remove('show');- setTimeout(function () { t.remove(); }, 300);- }, 1500);+ toastEl.textContent = '';+ requestAnimationFrame(function () {+ toastEl.textContent = msg;+ toastEl.classList.add('show');+ });+ clearTimeout(toastTimer);+ toastTimer = setTimeout(function () { toastEl.classList.remove('show'); }, 1500);}- function open() {+ function open(focusLast) {menu.classList.add('open');btn.setAttribute('aria-expanded', 'true');- var first = items().filter(function (i) { return !i.disabled; })[0];- if (first) first.focus();+ var available = items().filter(function (i) { return !i.disabled; });+ var target = focusLast ? available[available.length - 1] : available[0];+ if (target) target.focus();}function close(focusTrigger) {menu.classList.remove('open');@@ -964,6 +1069,13 @@if (isOpen()) close(false);else open();});+ // APG menu-button pattern: ArrowDown/ArrowUp on the trigger opens the menu.+ btn.addEventListener('keydown', function (e) {+ if (e.key === 'ArrowDown' || e.key === 'ArrowUp') {+ e.preventDefault();+ if (!isOpen()) open(e.key === 'ArrowUp');+ }+ });document.addEventListener('click', function (e) {if (!menu.contains(e.target) && e.target !== btn) close(false);});@@ -999,7 +1111,7 @@function runExport(format) {var base = diagramFilename();- close(false);+ close(true);return (format === 'svg'? Promise.resolve(serializeSvg(1, { autoTheme: true })).then(function (d) {download(new Blob([d.svgString], { type: 'image/svg+xml;charset=utf-8' }), base + '.svg');@@ -1014,14 +1126,25 @@}function runCopy() {- close(false);+ close(true);if (!canCopyImage()) {alert('Clipboard image write not supported in this browser.');return;}- return rasterize('png').then(function (blob) {- return navigator.clipboard.write([new ClipboardItem({ 'image/png': blob })]);- }).then(function () {+ // WebKit requires ClipboardItem to be constructed synchronously inside+ // the user gesture — pass the pending Promise<Blob> as the item value.+ // Browsers that reject promise values throw synchronously; fall back+ // to awaiting the blob first (works in Chromium/Firefox).+ var blobPromise = rasterize('png');+ var writePromise;+ try {+ writePromise = navigator.clipboard.write([new ClipboardItem({ 'image/png': blobPromise })]);+ } catch (_) {+ writePromise = blobPromise.then(function (blob) {+ return navigator.clipboard.write([new ClipboardItem({ 'image/png': blob })]);+ });+ }+ return writePromise.then(function () {toast('Copied PNG to clipboard');}).catch(function (err) {console.error(err);diff --git a/examples/sequence-cache-miss-request.html b/examples/sequence-cache-miss-request.htmlindex c7bf0376..48dbb926 100644--- a/examples/sequence-cache-miss-request.html+++ b/examples/sequence-cache-miss-request.html@@ -3,8 +3,36 @@<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0">+ <meta name="generator" content="archify 2.6.0"><title>Cache Miss Request Sequence Diagram</title>- <link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;600;700&display=swap" rel="stylesheet">+ <script>+ // Resolve the theme before first paint so light-preference users don't+ // see a dark flash. The toolbar script below re-applies with UI state.+ (function () {+ try {+ var theme = null;+ try {+ var param = new URLSearchParams(window.location.search).get('theme');+ if (param === 'light' || param === 'dark') theme = param;+ } catch (_) {}+ if (!theme) {+ try { theme = localStorage.getItem('archify-theme'); } catch (_) {}+ }+ if (theme !== 'light' && theme !== 'dark') {+ theme = window.matchMedia('(prefers-color-scheme: light)').matches ? 'light' : 'dark';+ }+ document.documentElement.setAttribute('data-theme', theme);+ } catch (_) {}+ })();+ </script>+ <!-- Async font load: a blackholed network must not block first paint.+ The body font stack falls back to system monospace until it lands. -->+ <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>+ <link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;600;700&display=swap"+ rel="stylesheet" media="print" onload="this.media='all'">+ <noscript>+ <link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;600;700&display=swap" rel="stylesheet">+ </noscript><style>/* ==========================================================THEME VARIABLES — switch by toggling [data-theme] on <html>@@ -16,6 +44,8 @@--text: #ffffff;--text-muted: #94a3b8;--text-dim: #475569;+ /* UI chrome (menu hints, footer) needs more contrast than SVG .t-dim accents */+ --text-faint: #7d8da1;--panel: rgba(15, 23, 42, 0.5);--panel-border: #1e293b;@@ -57,6 +87,7 @@--text: #0f172a;--text-muted: #64748b;--text-dim: #94a3b8;+ --text-faint: #64748b;--panel: #ffffff;--panel-border: #e2e8f0;@@ -93,7 +124,7 @@* { margin: 0; padding: 0; box-sizing: border-box; }body {- font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;+ font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, 'DejaVu Sans Mono', 'Liberation Mono', 'Noto Sans Mono CJK SC', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', monospace;background: var(--bg);min-height: 100vh;padding: 2rem;@@ -199,7 +230,7 @@.footer {text-align: center;margin-top: 1.5rem;- color: var(--text-dim);+ color: var(--text-faint);font-size: 0.75rem;}@@ -212,6 +243,9 @@@page { size: landscape; margin: 1.5cm; }@media print {+ /* Force the FULL light palette — including component fills/strokes and+ lane/arrow colors — so printing from dark theme doesn't put neon+ strokes and translucent dark fills on white paper. */:root, [data-theme="dark"], [data-theme="light"] {--bg: #ffffff;--grid: transparent;@@ -220,11 +254,30 @@--text: #0f172a;--text-muted: #475569;--text-dim: #94a3b8;+ --text-faint: #64748b;--mask: #ffffff;+ --lane-fill: rgba(248, 250, 252, 0.65);+ --lane-stroke: #cbd5e1;+ --arrow: #94a3b8;+ --arrow-emphasis: #059669;+ --frontend-fill: rgba(34, 211, 238, 0.15);+ --frontend-stroke: #0891b2;+ --backend-fill: rgba(52, 211, 153, 0.18);+ --backend-stroke: #059669;+ --database-fill: rgba(167, 139, 250, 0.2);+ --database-stroke: #7c3aed;+ --cloud-fill: rgba(251, 191, 36, 0.18);+ --cloud-stroke: #d97706;+ --security-fill: rgba(251, 113, 133, 0.15);+ --security-stroke: #e11d48;+ --messagebus-fill: rgba(251, 146, 60, 0.15);+ --messagebus-stroke:#ea580c;+ --external-fill: rgba(148, 163, 184, 0.18);+ --external-stroke: #64748b;}body { background: #ffffff !important; padding: 0; }.container { max-width: none; }- .toolbar, .archify-toast { display: none !important; }+ .toolbar, .archify-toast, .no-print { display: none !important; }.diagram-container, .card { box-shadow: none; border-color: #e2e8f0; }.cards { grid-template-columns: 1fr 1fr; }/* Ensure elements break sensibly across pages */@@ -295,7 +348,7 @@background: var(--toolbar-hover);}.toolbar .export-menu .hint {- color: var(--text-dim);+ color: var(--text-faint);font-size: 0.625rem;}.toolbar .export-menu hr {@@ -426,11 +479,11 @@</button><div class="export-menu" id="export-menu" role="menu" aria-label="Export"><button data-action="copy" type="button" role="menuitem" tabindex="-1">Copy to clipboard <span class="hint">PNG</span></button>- <hr role="separator" aria-hidden="true">+ <hr role="separator"><button data-format="png" type="button" role="menuitem" tabindex="-1">Download PNG</button><button data-format="jpeg" type="button" role="menuitem" tabindex="-1">Download JPEG</button><button data-format="webp" type="button" role="menuitem" tabindex="-1">Download WebP</button>- <hr role="separator" aria-hidden="true">+ <hr role="separator"><button data-format="svg" type="button" role="menuitem" tabindex="-1">Download SVG <span class="hint">vector</span></button></div></div>@@ -448,7 +501,7 @@<!-- Main Diagram --><div class="diagram-container">- <svg viewBox="0 0 820 760">+ <svg viewBox="0 0 820 760" role="img" aria-label="Cache Miss Request Sequence — Frontend request path with auth, cache fallback, persistence, and async trace (sequence diagram)"><!-- Definitions --><defs><marker id="arrowhead" markerWidth="10" markerHeight="7" refX="9" refY="3.5" orient="auto">@@ -643,7 +696,7 @@<!-- Footer --><p class="footer">- Sequence diagram • Built with Archify • Press <kbd>T</kbd> for theme and <kbd>E</kbd> for export+ Sequence diagram • Built with Archify<span class="no-print"> • Press <kbd>T</kbd> for theme and <kbd>E</kbd> for export</span></p></div>@@ -660,13 +713,27 @@var icon = document.getElementById('theme-icon');var label = document.getElementById('theme-label');- function resolveInitial() {+ // localStorage can throw (blocked cookies, sandboxed iframes); the whole+ // script element dies on an uncaught error, so guard every access.+ function readStored() {+ try { return localStorage.getItem(STORAGE_KEY); } catch (_) { return null; }+ }+ function writeStored(value) {+ try { localStorage.setItem(STORAGE_KEY, value); } catch (_) {}+ }+ function urlOverride() {// URL param wins (useful for deterministic screenshots / share links)try {var param = new URLSearchParams(window.location.search).get('theme');if (param === 'light' || param === 'dark') return param;} catch (_) {}- var saved = localStorage.getItem(STORAGE_KEY);+ return null;+ }++ function resolveInitial() {+ var fromUrl = urlOverride();+ if (fromUrl) return fromUrl;+ var saved = readStored();if (saved === 'light' || saved === 'dark') return saved;return window.matchMedia('(prefers-color-scheme: light)').matches ? 'light' : 'dark';}@@ -681,12 +748,24 @@function toggle() {var next = html.getAttribute('data-theme') === 'dark' ? 'light' : 'dark';apply(next);- localStorage.setItem(STORAGE_KEY, next);+ writeStored(next);}apply(resolveInitial());btn.addEventListener('click', toggle);+ // Follow live OS theme changes while the user has no explicit preference.+ try {+ var media = window.matchMedia('(prefers-color-scheme: light)');+ var onChange = function (e) {+ var saved = readStored();+ if (urlOverride() || saved === 'light' || saved === 'dark') return;+ apply(e.matches ? 'light' : 'dark');+ };+ if (media.addEventListener) media.addEventListener('change', onChange);+ else if (media.addListener) media.addListener(onChange);+ } catch (_) {}+return { toggle: toggle };})();@@ -706,7 +785,10 @@var RASTER_SCALE = 4;function diagramFilename() {- var title = (document.title || 'diagram').replace(/\s+Architecture(\s+Diagram)?$/i, '').trim();+ var title = (document.title || 'diagram')+ .replace(/\s+Architecture(\s+Diagram)?$/i, '')+ .replace(/\s+Diagram$/i, '')+ .trim();return title.replace(/[^a-z0-9_\-]+/gi, '-').toLowerCase().replace(/^-+|-+$/g, '') || 'diagram';@@ -749,21 +831,37 @@clone.setAttribute('height', vb.height * scale);clone.setAttribute('xmlns', 'http://www.w3.org/2000/svg');- var hostStyle = Array.prototype.map.call(document.querySelectorAll('style'), function (s) {- return s.textContent;- }).join('\n');-- var varNames = [- '--bg','--grid','--text','--text-muted','--text-dim',- '--arrow','--arrow-emphasis','--mask',- '--frontend-fill','--frontend-stroke',- '--backend-fill','--backend-stroke',- '--database-fill','--database-stroke',- '--cloud-fill','--cloud-stroke',- '--security-fill','--security-stroke',- '--messagebus-fill','--messagebus-stroke',- '--external-fill','--external-stroke'- ];+ // Only the SVG-relevant rules: semantic classes, markers, and the+ // theme variable blocks. Toolbar/cards/print CSS can never apply+ // inside a standalone SVG and would only bloat the export.+ var hostStyle = (function () {+ var out = [];+ Array.prototype.forEach.call(document.styleSheets, function (sheet) {+ var rules;+ try { rules = sheet.cssRules; } catch (_) { return; } // cross-origin+ if (!rules) return;+ Array.prototype.forEach.call(rules, function (rule) {+ if (rule.type !== 1) return; // plain style rules only+ var sel = rule.selectorText || '';+ if (/(^|,)\s*(svg|:root|\[data-theme|\.c-|\.t-|\.a-|\.m-)/.test(sel)) {+ out.push(rule.cssText);+ }+ });+ });+ return out.join('\n');+ })();++ // Derive the variable list from the stylesheet so newly added theme+ // variables can never be missed by the export pipeline again+ // (--lane-fill/--lane-stroke once were).+ var varNames = (function () {+ var seen = {};+ var names = [];+ (hostStyle.match(/--[a-zA-Z0-9-]+(?=\s*:)/g) || []).forEach(function (n) {+ if (!seen[n]) { seen[n] = true; names.push(n); }+ });+ return names;+ })();// Resolve the full variable set for a given data-theme via an// off-DOM probe, independent of what the viewer is currently set to.@@ -808,7 +906,7 @@style.textContent =fontFallback + "\n" +- "svg { font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace; }\n" ++ "svg { font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, 'DejaVu Sans Mono', 'Liberation Mono', 'Noto Sans Mono CJK SC', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', monospace; }\n" +hostStyle + "\n" +":root, svg { " + darkVars + " }\n" +"@media (prefers-color-scheme: light) { :root, svg { " + lightVars + " } }\n" +@@ -836,7 +934,7 @@// Keep this order.style.textContent =fontFallback + "\n" +- "svg { font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace; }\n" ++ "svg { font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, 'DejaVu Sans Mono', 'Liberation Mono', 'Noto Sans Mono CJK SC', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', monospace; }\n" +hostStyle + "\n" +":root, svg { " + vars + " }\n";@@ -961,23 +1059,30 @@});// ---- Toast ----------------------------------------------------------+ // A live region only announces CHANGES to an existing node, so the toast+ // element is created once up front and updated in place.+ var toastEl = document.createElement('div');+ toastEl.className = 'archify-toast';+ toastEl.setAttribute('role', 'status');+ document.body.appendChild(toastEl);+ var toastTimer = null;+function toast(msg) {- var t = document.createElement('div');- t.className = 'archify-toast';- t.textContent = msg;- document.body.appendChild(t);- requestAnimationFrame(function () { t.classList.add('show'); });- setTimeout(function () {- t.classList.remove('show');- setTimeout(function () { t.remove(); }, 300);- }, 1500);+ toastEl.textContent = '';+ requestAnimationFrame(function () {+ toastEl.textContent = msg;+ toastEl.classList.add('show');+ });+ clearTimeout(toastTimer);+ toastTimer = setTimeout(function () { toastEl.classList.remove('show'); }, 1500);}- function open() {+ function open(focusLast) {menu.classList.add('open');btn.setAttribute('aria-expanded', 'true');- var first = items().filter(function (i) { return !i.disabled; })[0];- if (first) first.focus();+ var available = items().filter(function (i) { return !i.disabled; });+ var target = focusLast ? available[available.length - 1] : available[0];+ if (target) target.focus();}function close(focusTrigger) {menu.classList.remove('open');@@ -991,6 +1096,13 @@if (isOpen()) close(false);else open();});+ // APG menu-button pattern: ArrowDown/ArrowUp on the trigger opens the menu.+ btn.addEventListener('keydown', function (e) {+ if (e.key === 'ArrowDown' || e.key === 'ArrowUp') {+ e.preventDefault();+ if (!isOpen()) open(e.key === 'ArrowUp');+ }+ });document.addEventListener('click', function (e) {if (!menu.contains(e.target) && e.target !== btn) close(false);});@@ -1026,7 +1138,7 @@function runExport(format) {var base = diagramFilename();- close(false);+ close(true);return (format === 'svg'? Promise.resolve(serializeSvg(1, { autoTheme: true })).then(function (d) {download(new Blob([d.svgString], { type: 'image/svg+xml;charset=utf-8' }), base + '.svg');@@ -1041,14 +1153,25 @@}function runCopy() {- close(false);+ close(true);if (!canCopyImage()) {alert('Clipboard image write not supported in this browser.');return;}- return rasterize('png').then(function (blob) {- return navigator.clipboard.write([new ClipboardItem({ 'image/png': blob })]);- }).then(function () {+ // WebKit requires ClipboardItem to be constructed synchronously inside+ // the user gesture — pass the pending Promise<Blob> as the item value.+ // Browsers that reject promise values throw synchronously; fall back+ // to awaiting the blob first (works in Chromium/Firefox).+ var blobPromise = rasterize('png');+ var writePromise;+ try {+ writePromise = navigator.clipboard.write([new ClipboardItem({ 'image/png': blobPromise })]);+ } catch (_) {+ writePromise = blobPromise.then(function (blob) {+ return navigator.clipboard.write([new ClipboardItem({ 'image/png': blob })]);+ });+ }+ return writePromise.then(function () {toast('Copied PNG to clipboard');}).catch(function (err) {console.error(err);diff --git a/examples/web-app-rendered.html b/examples/web-app-rendered.htmlnew file mode 100644index 00000000..d05bde69--- /dev/null+++ b/examples/web-app-rendered.html@@ -0,0 +1,1202 @@+<!DOCTYPE html>+<html lang="en" data-theme="dark">+<head>+ <meta charset="UTF-8">+ <meta name="viewport" content="width=device-width, initial-scale=1.0">+ <meta name="generator" content="archify 2.6.0">+ <title>Sample Web App Diagram</title>+ <script>+ // Resolve the theme before first paint so light-preference users don't+ // see a dark flash. The toolbar script below re-applies with UI state.+ (function () {+ try {+ var theme = null;+ try {+ var param = new URLSearchParams(window.location.search).get('theme');+ if (param === 'light' || param === 'dark') theme = param;+ } catch (_) {}+ if (!theme) {+ try { theme = localStorage.getItem('archify-theme'); } catch (_) {}+ }+ if (theme !== 'light' && theme !== 'dark') {+ theme = window.matchMedia('(prefers-color-scheme: light)').matches ? 'light' : 'dark';+ }+ document.documentElement.setAttribute('data-theme', theme);+ } catch (_) {}+ })();+ </script>+ <!-- Async font load: a blackholed network must not block first paint.+ The body font stack falls back to system monospace until it lands. -->+ <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>+ <link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;600;700&display=swap"+ rel="stylesheet" media="print" onload="this.media='all'">+ <noscript>+ <link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;600;700&display=swap" rel="stylesheet">+ </noscript>+ <style>+ /* ==========================================================+ THEME VARIABLES — switch by toggling [data-theme] on <html>+ ========================================================== */+ :root,+ [data-theme="dark"] {+ --bg: #020617;+ --grid: #1e293b;+ --text: #ffffff;+ --text-muted: #94a3b8;+ --text-dim: #475569;+ /* UI chrome (menu hints, footer) needs more contrast than SVG .t-dim accents */+ --text-faint: #7d8da1;++ --panel: rgba(15, 23, 42, 0.5);+ --panel-border: #1e293b;+ --lane-fill: rgba(15, 23, 42, 0.22);+ --lane-stroke: #334155;++ --arrow: #64748b;+ --arrow-emphasis: #34d399;++ /* Opaque mask color used behind semi-transparent component fills+ so the arrows drawn underneath are properly hidden. */+ --mask: #0f172a;++ --frontend-fill: rgba(8, 51, 68, 0.4);+ --frontend-stroke: #22d3ee;+ --backend-fill: rgba(6, 78, 59, 0.4);+ --backend-stroke: #34d399;+ --database-fill: rgba(76, 29, 149, 0.4);+ --database-stroke: #a78bfa;+ --cloud-fill: rgba(120, 53, 15, 0.3);+ --cloud-stroke: #fbbf24;+ --security-fill: rgba(136, 19, 55, 0.4);+ --security-stroke: #fb7185;+ --messagebus-fill: rgba(251, 146, 60, 0.3);+ --messagebus-stroke:#fb923c;+ --external-fill: rgba(30, 41, 59, 0.5);+ --external-stroke: #94a3b8;++ --toolbar-bg: rgba(15, 23, 42, 0.8);+ --toolbar-border: #334155;+ --toolbar-text: #e2e8f0;+ --toolbar-hover: rgba(15, 23, 42, 0.95);+ --toolbar-menu-bg: #0f172a;+ }++ [data-theme="light"] {+ --bg: #f8fafc;+ --grid: #e2e8f0;+ --text: #0f172a;+ --text-muted: #64748b;+ --text-dim: #94a3b8;+ --text-faint: #64748b;++ --panel: #ffffff;+ --panel-border: #e2e8f0;+ --lane-fill: rgba(248, 250, 252, 0.65);+ --lane-stroke: #cbd5e1;++ --arrow: #94a3b8;+ --arrow-emphasis: #059669;++ --mask: #ffffff;++ --frontend-fill: rgba(34, 211, 238, 0.15);+ --frontend-stroke: #0891b2;+ --backend-fill: rgba(52, 211, 153, 0.18);+ --backend-stroke: #059669;+ --database-fill: rgba(167, 139, 250, 0.2);+ --database-stroke: #7c3aed;+ --cloud-fill: rgba(251, 191, 36, 0.18);+ --cloud-stroke: #d97706;+ --security-fill: rgba(251, 113, 133, 0.15);+ --security-stroke: #e11d48;+ --messagebus-fill: rgba(251, 146, 60, 0.15);+ --messagebus-stroke:#ea580c;+ --external-fill: rgba(148, 163, 184, 0.18);+ --external-stroke: #64748b;++ --toolbar-bg: rgba(255, 255, 255, 0.92);+ --toolbar-border: #cbd5e1;+ --toolbar-text: #334155;+ --toolbar-hover: #ffffff;+ --toolbar-menu-bg: #ffffff;+ }++ * { margin: 0; padding: 0; box-sizing: border-box; }++ body {+ font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, 'DejaVu Sans Mono', 'Liberation Mono', 'Noto Sans Mono CJK SC', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', monospace;+ background: var(--bg);+ min-height: 100vh;+ padding: 2rem;+ color: var(--text);+ transition: background 0.2s ease, color 0.2s ease;+ }++ .container { max-width: 1200px; margin: 0 auto; }++ .header { margin-bottom: 2rem; }++ .header-row {+ display: flex;+ align-items: center;+ gap: 1rem;+ margin-bottom: 0.5rem;+ }++ .pulse-dot {+ width: 12px;+ height: 12px;+ background: var(--frontend-stroke);+ border-radius: 50%;+ animation: pulse 2s infinite;+ }++ @keyframes pulse {+ 0%, 100% { opacity: 1; }+ 50% { opacity: 0.5; }+ }++ h1 {+ font-size: 1.5rem;+ font-weight: 700;+ letter-spacing: -0.025em;+ }++ .subtitle {+ color: var(--text-muted);+ font-size: 0.875rem;+ margin-left: 1.75rem;+ }++ .diagram-container {+ background: var(--panel);+ border-radius: 1rem;+ border: 1px solid var(--panel-border);+ padding: 1.5rem;+ overflow-x: auto;+ }++ svg {+ width: 100%;+ min-width: min(900px, 100%);+ display: block;+ }++ .cards {+ display: grid;+ grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));+ gap: 1rem;+ margin-top: 2rem;+ }++ .card {+ background: var(--panel);+ border-radius: 0.75rem;+ border: 1px solid var(--panel-border);+ padding: 1.25rem;+ }++ .card-header {+ display: flex;+ align-items: center;+ gap: 0.5rem;+ margin-bottom: 0.75rem;+ }++ .card-dot {+ width: 8px;+ height: 8px;+ border-radius: 50%;+ }++ .card-dot.cyan { background: var(--frontend-stroke); }+ .card-dot.emerald { background: var(--backend-stroke); }+ .card-dot.violet { background: var(--database-stroke); }+ .card-dot.amber { background: var(--cloud-stroke); }+ .card-dot.rose { background: var(--security-stroke); }+ .card-dot.orange { background: var(--messagebus-stroke); }+ .card-dot.slate { background: var(--external-stroke); }++ .card h3 { font-size: 0.875rem; font-weight: 600; color: var(--text); }++ .card ul {+ list-style: none;+ color: var(--text-muted);+ font-size: 0.75rem;+ }++ .card li { margin-bottom: 0.375rem; }++ .footer {+ text-align: center;+ margin-top: 1.5rem;+ color: var(--text-faint);+ font-size: 0.75rem;+ }++ /* ==========================================================+ Print stylesheet — hide interactive controls, force light,+ drop the grid so the diagram doesn't waste ink, use landscape+ so wide diagrams fit, pack summary cards into 2 columns to+ avoid an orphan card on a trailing page.+ ========================================================== */+ @page { size: landscape; margin: 1.5cm; }++ @media print {+ /* Force the FULL light palette — including component fills/strokes and+ lane/arrow colors — so printing from dark theme doesn't put neon+ strokes and translucent dark fills on white paper. */+ :root, [data-theme="dark"], [data-theme="light"] {+ --bg: #ffffff;+ --grid: transparent;+ --panel: #ffffff;+ --panel-border: #e2e8f0;+ --text: #0f172a;+ --text-muted: #475569;+ --text-dim: #94a3b8;+ --text-faint: #64748b;+ --mask: #ffffff;+ --lane-fill: rgba(248, 250, 252, 0.65);+ --lane-stroke: #cbd5e1;+ --arrow: #94a3b8;+ --arrow-emphasis: #059669;+ --frontend-fill: rgba(34, 211, 238, 0.15);+ --frontend-stroke: #0891b2;+ --backend-fill: rgba(52, 211, 153, 0.18);+ --backend-stroke: #059669;+ --database-fill: rgba(167, 139, 250, 0.2);+ --database-stroke: #7c3aed;+ --cloud-fill: rgba(251, 191, 36, 0.18);+ --cloud-stroke: #d97706;+ --security-fill: rgba(251, 113, 133, 0.15);+ --security-stroke: #e11d48;+ --messagebus-fill: rgba(251, 146, 60, 0.15);+ --messagebus-stroke:#ea580c;+ --external-fill: rgba(148, 163, 184, 0.18);+ --external-stroke: #64748b;+ }+ body { background: #ffffff !important; padding: 0; }+ .container { max-width: none; }+ .toolbar, .archify-toast, .no-print { display: none !important; }+ .diagram-container, .card { box-shadow: none; border-color: #e2e8f0; }+ .cards { grid-template-columns: 1fr 1fr; }+ /* Ensure elements break sensibly across pages */+ .card { break-inside: avoid; page-break-inside: avoid; }+ .diagram-container { break-inside: avoid; page-break-inside: avoid; }+ h1, .subtitle { color: #0f172a; }+ }++ /* ==========================================================+ TOOLBAR (theme toggle + export menu)+ ========================================================== */+ .toolbar {+ position: fixed;+ top: 1rem;+ right: 1rem;+ display: flex;+ gap: 0.5rem;+ z-index: 100;+ }+ .toolbar button {+ background: var(--toolbar-bg);+ color: var(--toolbar-text);+ border: 1px solid var(--toolbar-border);+ padding: 0.5rem 0.875rem;+ border-radius: 0.5rem;+ font-family: inherit;+ font-size: 0.75rem;+ font-weight: 500;+ cursor: pointer;+ backdrop-filter: blur(8px);+ transition: background 0.15s, border-color 0.15s;+ display: inline-flex;+ align-items: center;+ gap: 0.375rem;+ }+ .toolbar button:hover {+ background: var(--toolbar-hover);+ border-color: var(--arrow);+ }+ .toolbar button:focus-visible {+ outline: 2px solid var(--frontend-stroke);+ outline-offset: 2px;+ }+ .toolbar .export-wrap { position: relative; }+ .toolbar .export-menu {+ position: absolute;+ top: calc(100% + 0.375rem);+ right: 0;+ background: var(--toolbar-menu-bg);+ border: 1px solid var(--toolbar-border);+ border-radius: 0.5rem;+ padding: 0.375rem;+ min-width: 160px;+ display: none;+ flex-direction: column;+ box-shadow: 0 4px 20px rgba(0,0,0,0.25);+ }+ .toolbar .export-menu.open { display: flex; }+ .toolbar .export-menu button {+ background: transparent;+ border: 0;+ justify-content: space-between;+ width: 100%;+ text-align: left;+ padding: 0.5rem 0.75rem;+ }+ .toolbar .export-menu button:hover {+ background: var(--toolbar-hover);+ }+ .toolbar .export-menu .hint {+ color: var(--text-faint);+ font-size: 0.625rem;+ }+ .toolbar .export-menu hr {+ border: 0;+ border-top: 1px solid var(--toolbar-border);+ margin: 0.25rem 0.375rem;+ opacity: 0.5;+ }++ /* Toast — brief feedback for actions like "copied" */+ .archify-toast {+ position: fixed;+ top: 1rem;+ left: 50%;+ transform: translateX(-50%) translateY(-8px);+ background: var(--toolbar-menu-bg);+ color: var(--text);+ border: 1px solid var(--toolbar-border);+ padding: 0.5rem 1rem;+ border-radius: 0.5rem;+ font-family: inherit;+ font-size: 0.75rem;+ opacity: 0;+ transition: opacity 0.2s, transform 0.2s;+ z-index: 200;+ pointer-events: none;+ box-shadow: 0 4px 20px rgba(0,0,0,0.25);+ }+ .archify-toast.show {+ opacity: 1;+ transform: translateX(-50%) translateY(0);+ }++ @media (max-width: 720px) {+ body { padding: 1rem; }+ .toolbar {+ position: static;+ justify-content: flex-end;+ margin-bottom: 1rem;+ }+ .header { margin-bottom: 1.25rem; }+ .header-row {+ gap: 0.75rem;+ align-items: flex-start;+ }+ h1 {+ font-size: 1.25rem;+ line-height: 1.25;+ }+ .subtitle {+ margin-left: 0;+ font-size: 0.8125rem;+ line-height: 1.55;+ }+ .diagram-container {+ padding: 0.75rem;+ border-radius: 0.75rem;+ }+ .cards {+ grid-template-columns: 1fr;+ margin-top: 1rem;+ }+ }++ /* ==========================================================+ SVG SEMANTIC CLASSES — use these instead of inline fill/stroke+ ========================================================== */+ .c-grid { stroke: var(--grid); fill: none; }+ .c-mask { fill: var(--mask); stroke: none; }++ .c-frontend { fill: var(--frontend-fill); stroke: var(--frontend-stroke); }+ .c-backend { fill: var(--backend-fill); stroke: var(--backend-stroke); }+ .c-database { fill: var(--database-fill); stroke: var(--database-stroke); }+ .c-cloud { fill: var(--cloud-fill); stroke: var(--cloud-stroke); }+ .c-security { fill: var(--security-fill); stroke: var(--security-stroke); }+ .c-messagebus { fill: var(--messagebus-fill); stroke: var(--messagebus-stroke); }+ .c-external { fill: var(--external-fill); stroke: var(--external-stroke); }++ /* Text helpers */+ .t-primary { fill: var(--text); }+ .t-muted { fill: var(--text-muted); }+ .t-dim { fill: var(--text-dim); }+ .t-frontend { fill: var(--frontend-stroke); }+ .t-backend { fill: var(--backend-stroke); }+ .t-database { fill: var(--database-stroke); }+ .t-cloud { fill: var(--cloud-stroke); }+ .t-security { fill: var(--security-stroke); }+ .t-messagebus { fill: var(--messagebus-stroke); }+ .t-external { fill: var(--external-stroke); }++ /* Arrows */+ .a-default { stroke: var(--arrow); fill: none; }+ .a-emphasis { stroke: var(--arrow-emphasis); fill: none; }+ .a-security { stroke: var(--security-stroke); fill: none; stroke-dasharray: 5,5; }+ .a-dashed { stroke: var(--database-stroke); fill: none; stroke-dasharray: 4,4; }++ /* Arrowhead markers reference these */+ .m-default { fill: var(--arrow); }+ .m-emphasis { fill: var(--arrow-emphasis); }+ .m-security { fill: var(--security-stroke); }+ .m-dashed { fill: var(--database-stroke); }++ /* Dashed boundary variants */+ .c-security-group { fill: transparent; stroke: var(--security-stroke); stroke-dasharray: 4,4; }+ .c-region { fill: rgba(251, 191, 36, 0.05); stroke: var(--cloud-stroke); stroke-dasharray: 8,4; }+ .c-lane { fill: var(--lane-fill); stroke: var(--lane-stroke); stroke-dasharray: 6,6; }+ </style>+</head>+<body>+ <!-- Toolbar: theme toggle + export menu (present on every generated diagram)+ Keyboard: T toggles theme, E opens export menu (when no input focused) -->+ <div class="toolbar" role="toolbar" aria-label="Diagram actions">+ <button id="btn-theme" type="button"+ title="Toggle theme (T)"+ aria-label="Toggle color theme"+ aria-pressed="false">+ <span id="theme-icon" aria-hidden="true">☾</span>+ <span id="theme-label">Dark</span>+ </button>+ <div class="export-wrap">+ <button id="btn-export" type="button"+ title="Export diagram (E)"+ aria-label="Export diagram"+ aria-haspopup="menu"+ aria-expanded="false"+ aria-controls="export-menu">+ Export <span aria-hidden="true">▾</span>+ </button>+ <div class="export-menu" id="export-menu" role="menu" aria-label="Export">+ <button data-action="copy" type="button" role="menuitem" tabindex="-1">Copy to clipboard <span class="hint">PNG</span></button>+ <hr role="separator">+ <button data-format="png" type="button" role="menuitem" tabindex="-1">Download PNG</button>+ <button data-format="jpeg" type="button" role="menuitem" tabindex="-1">Download JPEG</button>+ <button data-format="webp" type="button" role="menuitem" tabindex="-1">Download WebP</button>+ <hr role="separator">+ <button data-format="svg" type="button" role="menuitem" tabindex="-1">Download SVG <span class="hint">vector</span></button>+ </div>+ </div>+ </div>++ <div class="container">+ <!-- Header -->+ <div class="header">+ <div class="header-row">+ <div class="pulse-dot"></div>+ <h1>Sample Web App</h1>+ </div>+ <p class="subtitle">Classic 3-tier SaaS on AWS — rendered by Archify</p>+ </div>++ <!-- Main Diagram -->+ <div class="diagram-container">+ <svg viewBox="0 0 1080 588" role="img" aria-label="Sample Web App — Classic 3-tier SaaS on AWS — rendered by Archify (architecture diagram)">+ <!-- Definitions -->+ <defs>+ <marker id="arrowhead" markerWidth="10" markerHeight="7" refX="9" refY="3.5" orient="auto">+ <polygon points="0 0, 10 3.5, 0 7" class="m-default" />+ </marker>+ <marker id="arrowhead-emphasis" markerWidth="10" markerHeight="7" refX="9" refY="3.5" orient="auto">+ <polygon points="0 0, 10 3.5, 0 7" class="m-emphasis" />+ </marker>+ <marker id="arrowhead-security" markerWidth="10" markerHeight="7" refX="9" refY="3.5" orient="auto">+ <polygon points="0 0, 10 3.5, 0 7" class="m-security" />+ </marker>+ <marker id="arrowhead-dashed" markerWidth="10" markerHeight="7" refX="9" refY="3.5" orient="auto">+ <polygon points="0 0, 10 3.5, 0 7" class="m-dashed" />+ </marker>+ <pattern id="grid" width="40" height="40" patternUnits="userSpaceOnUse">+ <path d="M 40 0 L 0 0 0 40" class="c-grid" stroke-width="0.5"/>+ </pattern>+ </defs>++ <!-- Background Grid -->+ <rect width="100%" height="100%" fill="url(#grid)" />++ <!-- Boundaries (behind everything) -->+ <rect x="220" y="120" width="820" height="400" rx="12" class="c-region" stroke-width="1"/>+ <text x="228" y="138" class="t-cloud" font-size="9" font-weight="600">AWS Region: us-west-2</text>++ <rect x="430" y="270" width="400" height="110" rx="8" class="c-security-group" stroke-width="1"/>+ <text x="438" y="288" class="t-security" font-size="9" font-weight="600">sg-api :443/:8000</text>++ <!-- Connection paths (before components for correct z-order) -->+ <path d="M 160 330 L 250 330" class="a-emphasis" stroke-width="1.8" marker-end="url(#arrowhead-emphasis)"/>+ <path d="M 160 142 L 439.5 142 Q 447.5 142 447.5 150 L 447.5 292 Q 447.5 300 455.5 300 L 735 300" class="a-security" stroke-width="1.5" marker-end="url(#arrowhead-security)"/>+ <path d="M 380 330 L 460 330" class="a-default" stroke-width="1.5" marker-end="url(#arrowhead)"/>+ <path d="M 315 360 L 315 440" class="a-dashed" stroke-width="1.5" marker-end="url(#arrowhead-dashed)"/>+ <path d="M 590 330 L 670 330" class="a-default" stroke-width="1.5" marker-end="url(#arrowhead)"/>+ <path d="M 735 300 L 735 210" class="a-default" stroke-width="1.5" marker-end="url(#arrowhead)"/>+ <path d="M 800 330 L 880 330" class="a-default" stroke-width="1.5" marker-end="url(#arrowhead)"/>+ <path d="M 735 360 L 735 440" class="a-dashed" stroke-width="1.5" marker-end="url(#arrowhead-dashed)"/>+ <path d="M 800 470 L 880 470" class="a-default" stroke-width="1.5" marker-end="url(#arrowhead)"/>++ <!-- Components -->+ <rect x="40" y="300" width="120" height="60" rx="6" class="c-mask"/>+ <rect x="40" y="300" width="120" height="60" rx="6" class="c-external" stroke-width="1.5"/>+ <text x="100" y="328" class="t-primary" font-size="11" font-weight="600" text-anchor="middle">Users</text>+ <text x="100" y="344" class="t-muted" font-size="9" text-anchor="middle">Browser / Mobile</text>++ <rect x="40" y="110" width="120" height="64" rx="6" class="c-mask"/>+ <rect x="40" y="110" width="120" height="64" rx="6" class="c-security" stroke-width="1.5"/>+ <text x="100" y="140" class="t-primary" font-size="11" font-weight="600" text-anchor="middle">Auth Provider</text>+ <text x="100" y="156" class="t-muted" font-size="9" text-anchor="middle">OAuth 2.0</text>+ <text x="100" y="166" class="t-security" font-size="7" text-anchor="middle">JWT + PKCE</text>++ <rect x="250" y="300" width="130" height="60" rx="6" class="c-mask"/>+ <rect x="250" y="300" width="130" height="60" rx="6" class="c-cloud" stroke-width="1.5"/>+ <text x="315" y="328" class="t-primary" font-size="11" font-weight="600" text-anchor="middle">CloudFront</text>+ <text x="315" y="344" class="t-muted" font-size="9" text-anchor="middle">CDN</text>++ <rect x="460" y="300" width="130" height="60" rx="6" class="c-mask"/>+ <rect x="460" y="300" width="130" height="60" rx="6" class="c-cloud" stroke-width="1.5"/>+ <text x="525" y="328" class="t-primary" font-size="11" font-weight="600" text-anchor="middle">Load Balancer</text>+ <text x="525" y="344" class="t-muted" font-size="9" text-anchor="middle">HTTPS :443</text>++ <rect x="670" y="300" width="130" height="60" rx="6" class="c-mask"/>+ <rect x="670" y="300" width="130" height="60" rx="6" class="c-backend" stroke-width="1.5"/>+ <text x="735" y="328" class="t-primary" font-size="11" font-weight="600" text-anchor="middle">API Server</text>+ <text x="735" y="344" class="t-muted" font-size="9" text-anchor="middle">FastAPI :8000</text>++ <rect x="670" y="150" width="130" height="60" rx="6" class="c-mask"/>+ <rect x="670" y="150" width="130" height="60" rx="6" class="c-database" stroke-width="1.5"/>+ <text x="735" y="178" class="t-primary" font-size="11" font-weight="600" text-anchor="middle">Redis</text>+ <text x="735" y="194" class="t-muted" font-size="9" text-anchor="middle">cache :6379</text>++ <rect x="880" y="300" width="130" height="60" rx="6" class="c-mask"/>+ <rect x="880" y="300" width="130" height="60" rx="6" class="c-database" stroke-width="1.5"/>+ <text x="945" y="328" class="t-primary" font-size="11" font-weight="600" text-anchor="middle">PostgreSQL</text>+ <text x="945" y="344" class="t-muted" font-size="9" text-anchor="middle">primary :5432</text>++ <rect x="250" y="440" width="130" height="60" rx="6" class="c-mask"/>+ <rect x="250" y="440" width="130" height="60" rx="6" class="c-cloud" stroke-width="1.5"/>+ <text x="315" y="468" class="t-primary" font-size="11" font-weight="600" text-anchor="middle">S3</text>+ <text x="315" y="484" class="t-muted" font-size="9" text-anchor="middle">static assets</text>+ <text x="315" y="492" class="t-cloud" font-size="7" text-anchor="middle">OAI protected</text>++ <rect x="670" y="440" width="130" height="60" rx="6" class="c-mask"/>+ <rect x="670" y="440" width="130" height="60" rx="6" class="c-messagebus" stroke-width="1.5"/>+ <text x="735" y="468" class="t-primary" font-size="11" font-weight="600" text-anchor="middle">SQS</text>+ <text x="735" y="484" class="t-muted" font-size="9" text-anchor="middle">job queue</text>++ <rect x="880" y="440" width="130" height="60" rx="6" class="c-mask"/>+ <rect x="880" y="440" width="130" height="60" rx="6" class="c-backend" stroke-width="1.5"/>+ <text x="945" y="468" class="t-primary" font-size="11" font-weight="600" text-anchor="middle">Worker</text>+ <text x="945" y="484" class="t-muted" font-size="9" text-anchor="middle">async jobs</text>++ <!-- Connection labels -->+ <rect x="188" y="310" width="34" height="14" rx="3" class="c-mask"/>+ <text x="205" y="320" class="t-backend" font-size="8" text-anchor="middle">HTTPS</text>+ <rect x="418.5" y="201" width="58" height="14" rx="3" class="c-mask"/>+ <text x="447.5" y="211" class="t-security" font-size="8" text-anchor="middle">verify JWT</text>++ <rect x="295.6" y="398" width="38.8" height="14" rx="3" class="c-mask"/>+ <text x="315" y="408" class="t-messagebus" font-size="8" text-anchor="middle">static</text>++ <rect x="701.2" y="212" width="67.6" height="14" rx="3" class="c-mask"/>+ <text x="735" y="222" class="t-muted" font-size="8" text-anchor="middle">read-through</text>+ <rect x="825" y="310" width="30" height="14" rx="3" class="c-mask"/>+ <text x="840" y="320" class="t-muted" font-size="8" text-anchor="middle">SQL</text>+ <rect x="713.2" y="398" width="43.6" height="14" rx="3" class="c-mask"/>+ <text x="735" y="408" class="t-messagebus" font-size="8" text-anchor="middle">enqueue</text>+++ <!-- Legend -->+ <text x="40" y="559" class="t-primary" font-size="9" font-weight="600">Legend</text>+ <rect x="40" y="564" width="14" height="9" rx="2" class="c-external" stroke-width="1"/>+ <text x="60" y="572" class="t-muted" font-size="8">External</text>+ <rect x="138" y="564" width="14" height="9" rx="2" class="c-security" stroke-width="1"/>+ <text x="158" y="572" class="t-muted" font-size="8">Security</text>+ <rect x="236" y="564" width="14" height="9" rx="2" class="c-cloud" stroke-width="1"/>+ <text x="256" y="572" class="t-muted" font-size="8">Cloud</text>+ <rect x="319" y="564" width="14" height="9" rx="2" class="c-backend" stroke-width="1"/>+ <text x="339" y="572" class="t-muted" font-size="8">Backend</text>+ <rect x="412" y="564" width="14" height="9" rx="2" class="c-database" stroke-width="1"/>+ <text x="432" y="572" class="t-muted" font-size="8">Database</text>+ <rect x="510" y="564" width="14" height="9" rx="2" class="c-messagebus" stroke-width="1"/>+ <text x="530" y="572" class="t-muted" font-size="8">Message bus</text>+ </svg>+ </div>++ <!-- Info Cards -->+ <div class="cards">+ <div class="card">+ <div class="card-header">+ <div class="card-dot cyan"></div>+ <h3>Edge</h3>+ </div>+ <ul>+ <li>• CloudFront CDN fronts all traffic</li>+ <li>• S3 serves static assets via OAI</li>+ </ul>+ </div>++ <div class="card">+ <div class="card-header">+ <div class="card-dot emerald"></div>+ <h3>Application</h3>+ </div>+ <ul>+ <li>• FastAPI behind an HTTPS load balancer</li>+ <li>• Redis read-through cache</li>+ <li>• Async work drained from SQS by a worker</li>+ </ul>+ </div>++ <div class="card">+ <div class="card-header">+ <div class="card-dot rose"></div>+ <h3>Security</h3>+ </div>+ <ul>+ <li>• OAuth 2.0 with JWT + PKCE</li>+ <li>• API + LB isolated in a security group</li>+ </ul>+ </div>+ </div>++ <!-- Footer -->+ <p class="footer">+ Architecture diagram • Built with Archify<span class="no-print"> • Press <kbd>T</kbd> for theme and <kbd>E</kbd> for export</span>+ </p>+ </div>++ <script>+ /* ============================================================+ Theme toggle — persists to localStorage, respects system pref+ ============================================================ */+ var Archify = {};++ Archify.theme = (function () {+ var STORAGE_KEY = 'archify-theme';+ var html = document.documentElement;+ var btn = document.getElementById('btn-theme');+ var icon = document.getElementById('theme-icon');+ var label = document.getElementById('theme-label');++ // localStorage can throw (blocked cookies, sandboxed iframes); the whole+ // script element dies on an uncaught error, so guard every access.+ function readStored() {+ try { return localStorage.getItem(STORAGE_KEY); } catch (_) { return null; }+ }+ function writeStored(value) {+ try { localStorage.setItem(STORAGE_KEY, value); } catch (_) {}+ }+ function urlOverride() {+ // URL param wins (useful for deterministic screenshots / share links)+ try {+ var param = new URLSearchParams(window.location.search).get('theme');+ if (param === 'light' || param === 'dark') return param;+ } catch (_) {}+ return null;+ }++ function resolveInitial() {+ var fromUrl = urlOverride();+ if (fromUrl) return fromUrl;+ var saved = readStored();+ if (saved === 'light' || saved === 'dark') return saved;+ return window.matchMedia('(prefers-color-scheme: light)').matches ? 'light' : 'dark';+ }++ function apply(theme) {+ html.setAttribute('data-theme', theme);+ icon.textContent = theme === 'dark' ? '\u263E' : '\u263C';+ label.textContent = theme === 'dark' ? 'Dark' : 'Light';+ btn.setAttribute('aria-pressed', theme === 'light' ? 'true' : 'false');+ }++ function toggle() {+ var next = html.getAttribute('data-theme') === 'dark' ? 'light' : 'dark';+ apply(next);+ writeStored(next);+ }++ apply(resolveInitial());+ btn.addEventListener('click', toggle);++ // Follow live OS theme changes while the user has no explicit preference.+ try {+ var media = window.matchMedia('(prefers-color-scheme: light)');+ var onChange = function (e) {+ var saved = readStored();+ if (urlOverride() || saved === 'light' || saved === 'dark') return;+ apply(e.matches ? 'light' : 'dark');+ };+ if (media.addEventListener) media.addEventListener('change', onChange);+ else if (media.addListener) media.addListener(onChange);+ } catch (_) {}++ return { toggle: toggle };+ })();++ /* ============================================================+ Export — PNG / JPEG / WebP / SVG (download) and Copy PNG (clipboard)++ Raster exports are always rendered at 4x source resolution for+ maximum sharpness. The trick: we set the serialized SVG's+ `width`/`height` to viewBox * 4 so the browser rasterizes the+ vectors at that resolution natively. drawImage then draws at+ the image's natural size (no upscaling = no blur).++ JPEG/WebP paint the current theme's background explicitly since+ those formats have no alpha channel.+ ============================================================ */+ (function () {+ var RASTER_SCALE = 4;++ function diagramFilename() {+ var title = (document.title || 'diagram')+ .replace(/\s+Architecture(\s+Diagram)?$/i, '')+ .replace(/\s+Diagram$/i, '')+ .trim();+ return title.replace(/[^a-z0-9_\-]+/gi, '-')+ .toLowerCase()+ .replace(/^-+|-+$/g, '') || 'diagram';+ }++ function currentBg() {+ return getComputedStyle(document.body).backgroundColor || '#ffffff';+ }++ /**+ * Serialize the main SVG into a standalone document.+ *+ * Two modes:+ * - Default (opts.autoTheme=false) — locks the serialized SVG to the+ * viewer's current theme. Used by the raster pipeline+ * (PNG/JPEG/WebP/clipboard) because canvas rasterization needs+ * deterministic colors; a raster cannot react to+ * prefers-color-scheme after encoding.+ * - autoTheme=true — emits BOTH dark and light variable sets plus a+ * `@media (prefers-color-scheme)` rule so the resulting SVG+ * self-themes when embedded in GitHub READMEs or other hosts that+ * expose a color scheme. Used for "Download SVG".+ */+ function serializeSvg(scale, opts) {+ // scale: integer multiplier for intrinsic SVG pixel dimensions used by+ // the raster path. Defaults to 1 (natural size) for SVG download.+ scale = scale || 1;+ opts = opts || {};+ var autoTheme = opts.autoTheme === true;++ var svg = document.querySelector('.diagram-container svg');+ var clone = svg.cloneNode(true);++ var vb = svg.viewBox.baseVal;+ // Scale width/height so the browser rasterizes the vectors at target+ // resolution directly. viewBox stays unchanged so coordinates don't+ // shift. This is the key to sharp rasters — do NOT scale later via+ // canvas upscaling.+ clone.setAttribute('width', vb.width * scale);+ clone.setAttribute('height', vb.height * scale);+ clone.setAttribute('xmlns', 'http://www.w3.org/2000/svg');++ // Only the SVG-relevant rules: semantic classes, markers, and the+ // theme variable blocks. Toolbar/cards/print CSS can never apply+ // inside a standalone SVG and would only bloat the export.+ var hostStyle = (function () {+ var out = [];+ Array.prototype.forEach.call(document.styleSheets, function (sheet) {+ var rules;+ try { rules = sheet.cssRules; } catch (_) { return; } // cross-origin+ if (!rules) return;+ Array.prototype.forEach.call(rules, function (rule) {+ if (rule.type !== 1) return; // plain style rules only+ var sel = rule.selectorText || '';+ if (/(^|,)\s*(svg|:root|\[data-theme|\.c-|\.t-|\.a-|\.m-)/.test(sel)) {+ out.push(rule.cssText);+ }+ });+ });+ return out.join('\n');+ })();++ // Derive the variable list from the stylesheet so newly added theme+ // variables can never be missed by the export pipeline again+ // (--lane-fill/--lane-stroke once were).+ var varNames = (function () {+ var seen = {};+ var names = [];+ (hostStyle.match(/--[a-zA-Z0-9-]+(?=\s*:)/g) || []).forEach(function (n) {+ if (!seen[n]) { seen[n] = true; names.push(n); }+ });+ return names;+ })();++ // Resolve the full variable set for a given data-theme via an+ // off-DOM probe, independent of what the viewer is currently set to.+ function resolveVars(themeAttr) {+ var probe = document.createElement('div');+ probe.setAttribute('data-theme', themeAttr);+ probe.style.cssText = 'position:absolute;width:0;height:0;visibility:hidden;';+ document.body.appendChild(probe);+ try {+ var c = getComputedStyle(probe);+ return varNames.map(function (n) {+ return n + ': ' + c.getPropertyValue(n).trim() + ';';+ }).join(' ');+ } finally {+ document.body.removeChild(probe);+ }+ }++ // Prepend a local()-only @font-face block for each weight so that the+ // sandboxed image-rendering context used during PNG/JPEG/WebP export+ // can find JetBrains Mono if the user has it installed locally, and+ // falls through cleanly to the monospace stack otherwise. The usual+ // Google-Fonts <link> in the host document is unreachable from the+ // serialized SVG, so url()-sourced faces would just hang.+ var fontFallback = [400, 500, 600, 700].map(function (w) {+ return "@font-face { font-family: 'JetBrains Mono'; font-weight: " + w ++ "; src: local('JetBrains Mono'), local('JetBrainsMono-Regular'); }";+ }).join('\n');++ var style = document.createElementNS('http://www.w3.org/2000/svg', 'style');+ var bgRect = document.createElementNS('http://www.w3.org/2000/svg', 'rect');+ bgRect.setAttribute('width', '100%');+ bgRect.setAttribute('height', '100%');++ if (autoTheme) {+ // Dual-theme SVG. Dark is the default (so hosts without+ // prefers-color-scheme still render), light swaps in via media+ // query, and svg[data-theme="..."] still lets downstream+ // consumers force a specific theme.+ var darkVars = resolveVars('dark');+ var lightVars = resolveVars('light');++ style.textContent =+ fontFallback + "\n" ++ "svg { font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, 'DejaVu Sans Mono', 'Liberation Mono', 'Noto Sans Mono CJK SC', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', monospace; }\n" ++ hostStyle + "\n" ++ ":root, svg { " + darkVars + " }\n" ++ "@media (prefers-color-scheme: light) { :root, svg { " + lightVars + " } }\n" ++ "svg[data-theme=\"light\"] { " + lightVars + " }\n" ++ "svg[data-theme=\"dark\"] { " + darkVars + " }\n" ++ "rect.c-bg-rect { fill: var(--bg); }\n";++ // Don't lock the serialized SVG to the viewer's current theme.+ clone.removeAttribute('data-theme');+ // Background follows the CSS variable, not a fixed color, so it+ // swaps with the media query.+ bgRect.setAttribute('class', 'c-bg-rect');+ } else {+ // Raster path: lock to the viewer's current theme.+ var theme = document.documentElement.getAttribute('data-theme') || 'dark';+ var themeHost = document.querySelector('[data-theme="' + theme + '"]') || document.documentElement;+ var computed = getComputedStyle(themeHost);+ var vars = varNames.map(function (n) {+ return n + ': ' + computed.getPropertyValue(n).trim() + ';';+ }).join(' ');++ // IMPORTANT: inject the resolved variables AFTER hostStyle,+ // otherwise hostStyle's ":root, [data-theme=\"dark\"] { ... }" rule+ // overrides our chosen theme via later-in-cascade equal-specificity.+ // Keep this order.+ style.textContent =+ fontFallback + "\n" ++ "svg { font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, 'DejaVu Sans Mono', 'Liberation Mono', 'Noto Sans Mono CJK SC', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', monospace; }\n" ++ hostStyle + "\n" ++ ":root, svg { " + vars + " }\n";++ bgRect.setAttribute('fill', computed.getPropertyValue('--bg').trim() || '#ffffff');+ }++ clone.insertBefore(style, clone.firstChild);+ clone.insertBefore(bgRect, style.nextSibling);++ return {+ svgString: new XMLSerializer().serializeToString(clone),+ width: vb.width * scale,+ height: vb.height * scale+ };+ }++ function download(blob, filename) {+ var url = URL.createObjectURL(blob);+ var a = document.createElement('a');+ a.href = url;+ a.download = filename;+ document.body.appendChild(a);+ a.click();+ a.remove();+ setTimeout(function () { URL.revokeObjectURL(url); }, 1000);+ }++ // Conservative upper bound on total canvas pixels. Older Safari on iOS+ // silently produces a blank canvas above ~16 Mpx; Chrome / Firefox /+ // desktop Safari are far higher but start failing on memory-constrained+ // devices. We pick the largest integer scale in {4,3,2,1} whose target+ // pixel count fits under this cap.+ var MAX_CANVAS_PIXELS = 16 * 1024 * 1024;++ function pickSafeScale(vbW, vbH) {+ for (var s = RASTER_SCALE; s >= 1; s--) {+ if (vbW * s * vbH * s <= MAX_CANVAS_PIXELS) return s;+ }+ return 1;+ }++ function rasterize(format) {+ // Serialize at a safe scale (RASTER_SCALE=4 by default, reduced if the+ // resulting canvas would exceed MAX_CANVAS_PIXELS). The SVG itself is+ // rasterized at target resolution natively; drawImage draws at natural+ // size — no upsampling blur.+ var svg = document.querySelector('.diagram-container svg');+ var vb = svg.viewBox.baseVal;+ var scale = pickSafeScale(vb.width, vb.height);+ var data = serializeSvg(scale);+ var svgBlob = new Blob([data.svgString], { type: 'image/svg+xml;charset=utf-8' });+ var svgUrl = URL.createObjectURL(svgBlob);++ return new Promise(function (resolve, reject) {+ var img = new Image();+ img.onload = function () {+ var canvas = document.createElement('canvas');+ canvas.width = data.width;+ canvas.height = data.height;+ var ctx = canvas.getContext('2d');+ if (format === 'jpeg') {+ ctx.fillStyle = currentBg();+ ctx.fillRect(0, 0, canvas.width, canvas.height);+ }+ // Draw at natural size — SVG was already rasterized at target res.+ ctx.drawImage(img, 0, 0);+ URL.revokeObjectURL(svgUrl);+ var mime = format === 'jpeg' ? 'image/jpeg' :+ format === 'webp' ? 'image/webp' : 'image/png';+ var quality = format === 'png' ? undefined : 0.95;+ canvas.toBlob(function (blob) {+ if (!blob) reject(new Error('toBlob returned null for ' + format));+ else resolve(blob);+ }, mime, quality);+ };+ img.onerror = function (e) {+ URL.revokeObjectURL(svgUrl);+ reject(e);+ };+ img.src = svgUrl;+ });+ }++ var menu = document.getElementById('export-menu');+ var btn = document.getElementById('btn-export');+ var items = function () {+ return Array.prototype.slice.call(menu.querySelectorAll('button[role="menuitem"]'));+ };++ // ---- Clipboard support ----------------------------------------------+ function canCopyImage() {+ return typeof ClipboardItem !== 'undefined' &&+ navigator.clipboard &&+ typeof navigator.clipboard.write === 'function';+ }++ // ---- Raster format detection ----------------------------------------+ // canvas.toBlob('image/webp') silently returns a PNG on browsers without+ // WebP encoding (older Safari), so detect explicitly.+ function supports(format) {+ if (format === 'svg' || format === 'png') return true;+ var mime = format === 'jpeg' ? 'image/jpeg' : 'image/webp';+ try {+ var c = document.createElement('canvas');+ c.width = c.height = 2;+ return c.toDataURL(mime).indexOf('data:' + mime) === 0;+ } catch (_) { return false; }+ }++ // Gray out unsupported items.+ items().forEach(function (it) {+ if (it.dataset.format && !supports(it.dataset.format)) {+ it.disabled = true;+ it.title = 'Not supported by this browser';+ it.style.opacity = '0.5';+ }+ if (it.dataset.action === 'copy' && !canCopyImage()) {+ it.disabled = true;+ it.title = 'Clipboard image write not supported by this browser';+ it.style.opacity = '0.5';+ }+ });++ // ---- Toast ----------------------------------------------------------+ // A live region only announces CHANGES to an existing node, so the toast+ // element is created once up front and updated in place.+ var toastEl = document.createElement('div');+ toastEl.className = 'archify-toast';+ toastEl.setAttribute('role', 'status');+ document.body.appendChild(toastEl);+ var toastTimer = null;++ function toast(msg) {+ toastEl.textContent = '';+ requestAnimationFrame(function () {+ toastEl.textContent = msg;+ toastEl.classList.add('show');+ });+ clearTimeout(toastTimer);+ toastTimer = setTimeout(function () { toastEl.classList.remove('show'); }, 1500);+ }++ function open(focusLast) {+ menu.classList.add('open');+ btn.setAttribute('aria-expanded', 'true');+ var available = items().filter(function (i) { return !i.disabled; });+ var target = focusLast ? available[available.length - 1] : available[0];+ if (target) target.focus();+ }+ function close(focusTrigger) {+ menu.classList.remove('open');+ btn.setAttribute('aria-expanded', 'false');+ if (focusTrigger) btn.focus();+ }+ function isOpen() { return menu.classList.contains('open'); }++ btn.addEventListener('click', function (e) {+ e.stopPropagation();+ if (isOpen()) close(false);+ else open();+ });+ // APG menu-button pattern: ArrowDown/ArrowUp on the trigger opens the menu.+ btn.addEventListener('keydown', function (e) {+ if (e.key === 'ArrowDown' || e.key === 'ArrowUp') {+ e.preventDefault();+ if (!isOpen()) open(e.key === 'ArrowUp');+ }+ });+ document.addEventListener('click', function (e) {+ if (!menu.contains(e.target) && e.target !== btn) close(false);+ });++ // Keyboard navigation inside the menu.+ // Menu items: Up/Down, Home/End.+ // Esc closes + returns focus to trigger; Tab closes.+ menu.addEventListener('keydown', function (e) {+ if (e.key === 'Escape') { e.preventDefault(); close(true); return; }+ if (e.key === 'Tab') { close(false); return; }++ var available = items().filter(function (i) { return !i.disabled; });+ var current = available.indexOf(document.activeElement);+ switch (e.key) {+ case 'ArrowDown':+ e.preventDefault();+ if (available.length) available[(current + 1 + available.length) % available.length].focus();+ break;+ case 'ArrowUp':+ e.preventDefault();+ if (available.length) available[(current - 1 + available.length) % available.length].focus();+ break;+ case 'Home':+ e.preventDefault();+ if (available[0]) available[0].focus();+ break;+ case 'End':+ e.preventDefault();+ if (available.length) available[available.length - 1].focus();+ break;+ }+ });++ function runExport(format) {+ var base = diagramFilename();+ close(true);+ return (format === 'svg'+ ? Promise.resolve(serializeSvg(1, { autoTheme: true })).then(function (d) {+ download(new Blob([d.svgString], { type: 'image/svg+xml;charset=utf-8' }), base + '.svg');+ })+ : rasterize(format).then(function (blob) {+ download(blob, base + '.' + format);+ })+ ).catch(function (err) {+ console.error(err);+ alert('Export failed: ' + (err && err.message ? err.message : format));+ });+ }++ function runCopy() {+ close(true);+ if (!canCopyImage()) {+ alert('Clipboard image write not supported in this browser.');+ return;+ }+ // WebKit requires ClipboardItem to be constructed synchronously inside+ // the user gesture — pass the pending Promise<Blob> as the item value.+ // Browsers that reject promise values throw synchronously; fall back+ // to awaiting the blob first (works in Chromium/Firefox).+ var blobPromise = rasterize('png');+ var writePromise;+ try {+ writePromise = navigator.clipboard.write([new ClipboardItem({ 'image/png': blobPromise })]);+ } catch (_) {+ writePromise = blobPromise.then(function (blob) {+ return navigator.clipboard.write([new ClipboardItem({ 'image/png': blob })]);+ });+ }+ return writePromise.then(function () {+ toast('Copied PNG to clipboard');+ }).catch(function (err) {+ console.error(err);+ alert('Copy failed: ' + (err && err.message ? err.message : 'unknown'));+ });+ }++ menu.addEventListener('click', function (e) {+ var copyBtn = e.target.closest('button[data-action="copy"]');+ if (copyBtn && !copyBtn.disabled) { runCopy(); return; }++ var formatBtn = e.target.closest('button[data-format]');+ if (formatBtn && !formatBtn.disabled) { runExport(formatBtn.dataset.format); }+ });++ Archify.exportMenu = { open: open, close: close, isOpen: isOpen, run: runExport };++ // Auto-open on page load for demo/screenshot purposes: ?openExport=1+ // Wait for fonts (so the menu doesn't flash before typography lands)+ // and paint before opening. Fallback timeout for browsers without the+ // Font Loading API.+ try {+ if (new URLSearchParams(window.location.search).get('openExport') === '1') {+ var openWhenReady = function () {+ requestAnimationFrame(function () { requestAnimationFrame(open); });+ };+ if (document.fonts && document.fonts.ready) {+ document.fonts.ready.then(openWhenReady);+ } else {+ setTimeout(openWhenReady, 200);+ }+ }+ } catch (_) {}+ })();++ /* ============================================================+ Global keyboard shortcuts+ T -> toggle theme+ E -> open export menu+ Ignored when focus is inside an input/textarea/contenteditable.+ ============================================================ */+ document.addEventListener('keydown', function (e) {+ if (e.metaKey || e.ctrlKey || e.altKey) return;+ var t = e.target;+ if (t && (t.tagName === 'INPUT' || t.tagName === 'TEXTAREA' || t.isContentEditable)) return;+ if (e.key === 't' || e.key === 'T') {+ e.preventDefault();+ Archify.theme.toggle();+ } else if (e.key === 'e' || e.key === 'E') {+ e.preventDefault();+ if (!Archify.exportMenu.isOpen()) Archify.exportMenu.open();+ }+ });+ </script>+</body>+</html>diff --git a/examples/web-app.html b/examples/web-app.htmlindex de3ddfc8..338cf341 100644--- a/examples/web-app.html+++ b/examples/web-app.html@@ -3,8 +3,36 @@<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0">+ <meta name="generator" content="archify 2.6.0"><title>Sample Web App Architecture Diagram</title>- <link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;600;700&display=swap" rel="stylesheet">+ <script>+ // Resolve the theme before first paint so light-preference users don't+ // see a dark flash. The toolbar script below re-applies with UI state.+ (function () {+ try {+ var theme = null;+ try {+ var param = new URLSearchParams(window.location.search).get('theme');+ if (param === 'light' || param === 'dark') theme = param;+ } catch (_) {}+ if (!theme) {+ try { theme = localStorage.getItem('archify-theme'); } catch (_) {}+ }+ if (theme !== 'light' && theme !== 'dark') {+ theme = window.matchMedia('(prefers-color-scheme: light)').matches ? 'light' : 'dark';+ }+ document.documentElement.setAttribute('data-theme', theme);+ } catch (_) {}+ })();+ </script>+ <!-- Async font load: a blackholed network must not block first paint.+ The body font stack falls back to system monospace until it lands. -->+ <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>+ <link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;600;700&display=swap"+ rel="stylesheet" media="print" onload="this.media='all'">+ <noscript>+ <link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;600;700&display=swap" rel="stylesheet">+ </noscript><style>/* ==========================================================THEME VARIABLES — switch by toggling [data-theme] on <html>@@ -16,9 +44,13 @@--text: #ffffff;--text-muted: #94a3b8;--text-dim: #475569;+ /* UI chrome (menu hints, footer) needs more contrast than SVG .t-dim accents */+ --text-faint: #7d8da1;--panel: rgba(15, 23, 42, 0.5);--panel-border: #1e293b;+ --lane-fill: rgba(15, 23, 42, 0.22);+ --lane-stroke: #334155;--arrow: #64748b;--arrow-emphasis: #34d399;@@ -55,9 +87,12 @@--text: #0f172a;--text-muted: #64748b;--text-dim: #94a3b8;+ --text-faint: #64748b;--panel: #ffffff;--panel-border: #e2e8f0;+ --lane-fill: rgba(248, 250, 252, 0.65);+ --lane-stroke: #cbd5e1;--arrow: #94a3b8;--arrow-emphasis: #059669;@@ -89,7 +124,7 @@* { margin: 0; padding: 0; box-sizing: border-box; }body {- font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;+ font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, 'DejaVu Sans Mono', 'Liberation Mono', 'Noto Sans Mono CJK SC', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', monospace;background: var(--bg);min-height: 100vh;padding: 2rem;@@ -143,7 +178,7 @@svg {width: 100%;- min-width: 900px;+ min-width: min(900px, 100%);display: block;}@@ -195,7 +230,7 @@.footer {text-align: center;margin-top: 1.5rem;- color: var(--text-dim);+ color: var(--text-faint);font-size: 0.75rem;}@@ -208,6 +243,9 @@@page { size: landscape; margin: 1.5cm; }@media print {+ /* Force the FULL light palette — including component fills/strokes and+ lane/arrow colors — so printing from dark theme doesn't put neon+ strokes and translucent dark fills on white paper. */:root, [data-theme="dark"], [data-theme="light"] {--bg: #ffffff;--grid: transparent;@@ -216,11 +254,30 @@--text: #0f172a;--text-muted: #475569;--text-dim: #94a3b8;+ --text-faint: #64748b;--mask: #ffffff;+ --lane-fill: rgba(248, 250, 252, 0.65);+ --lane-stroke: #cbd5e1;+ --arrow: #94a3b8;+ --arrow-emphasis: #059669;+ --frontend-fill: rgba(34, 211, 238, 0.15);+ --frontend-stroke: #0891b2;+ --backend-fill: rgba(52, 211, 153, 0.18);+ --backend-stroke: #059669;+ --database-fill: rgba(167, 139, 250, 0.2);+ --database-stroke: #7c3aed;+ --cloud-fill: rgba(251, 191, 36, 0.18);+ --cloud-stroke: #d97706;+ --security-fill: rgba(251, 113, 133, 0.15);+ --security-stroke: #e11d48;+ --messagebus-fill: rgba(251, 146, 60, 0.15);+ --messagebus-stroke:#ea580c;+ --external-fill: rgba(148, 163, 184, 0.18);+ --external-stroke: #64748b;}body { background: #ffffff !important; padding: 0; }.container { max-width: none; }- .toolbar, .archify-toast { display: none !important; }+ .toolbar, .archify-toast, .no-print { display: none !important; }.diagram-container, .card { box-shadow: none; border-color: #e2e8f0; }.cards { grid-template-columns: 1fr 1fr; }/* Ensure elements break sensibly across pages */@@ -291,7 +348,7 @@background: var(--toolbar-hover);}.toolbar .export-menu .hint {- color: var(--text-dim);+ color: var(--text-faint);font-size: 0.625rem;}.toolbar .export-menu hr {@@ -325,6 +382,37 @@transform: translateX(-50%) translateY(0);}+ @media (max-width: 720px) {+ body { padding: 1rem; }+ .toolbar {+ position: static;+ justify-content: flex-end;+ margin-bottom: 1rem;+ }+ .header { margin-bottom: 1.25rem; }+ .header-row {+ gap: 0.75rem;+ align-items: flex-start;+ }+ h1 {+ font-size: 1.25rem;+ line-height: 1.25;+ }+ .subtitle {+ margin-left: 0;+ font-size: 0.8125rem;+ line-height: 1.55;+ }+ .diagram-container {+ padding: 0.75rem;+ border-radius: 0.75rem;+ }+ .cards {+ grid-template-columns: 1fr;+ margin-top: 1rem;+ }+ }+/* ==========================================================SVG SEMANTIC CLASSES — use these instead of inline fill/stroke========================================================== */@@ -366,6 +454,7 @@/* Dashed boundary variants */.c-security-group { fill: transparent; stroke: var(--security-stroke); stroke-dasharray: 4,4; }.c-region { fill: rgba(251, 191, 36, 0.05); stroke: var(--cloud-stroke); stroke-dasharray: 8,4; }+ .c-lane { fill: var(--lane-fill); stroke: var(--lane-stroke); stroke-dasharray: 6,6; }</style></head><body>@@ -390,11 +479,11 @@</button><div class="export-menu" id="export-menu" role="menu" aria-label="Export"><button data-action="copy" type="button" role="menuitem" tabindex="-1">Copy to clipboard <span class="hint">PNG</span></button>- <hr role="separator" aria-hidden="true">+ <hr role="separator"><button data-format="png" type="button" role="menuitem" tabindex="-1">Download PNG</button><button data-format="jpeg" type="button" role="menuitem" tabindex="-1">Download JPEG</button><button data-format="webp" type="button" role="menuitem" tabindex="-1">Download WebP</button>- <hr role="separator" aria-hidden="true">+ <hr role="separator"><button data-format="svg" type="button" role="menuitem" tabindex="-1">Download SVG <span class="hint">vector</span></button></div></div>@@ -407,12 +496,12 @@<div class="pulse-dot"></div><h1>Sample Web App Architecture</h1></div>- <p class="subtitle">Classic 3-tier SaaS on AWS — generated by the Archify Claude Skill</p>+ <p class="subtitle">Classic 3-tier SaaS on AWS — generated by the Archify Claude Skill</p></div><!-- Main Diagram --><div class="diagram-container">- <svg viewBox="0 0 1000 680">+ <svg viewBox="0 0 1000 680" role="img" aria-label="Sample Web App Architecture diagram"><!-- Definitions --><defs><marker id="arrowhead" markerWidth="10" markerHeight="7" refX="9" refY="3.5" orient="auto">@@ -560,7 +649,6 @@</svg></div>- <!-- Info Cards --><div class="cards"><div class="card"><div class="card-header">@@ -621,13 +709,27 @@var icon = document.getElementById('theme-icon');var label = document.getElementById('theme-label');- function resolveInitial() {+ // localStorage can throw (blocked cookies, sandboxed iframes); the whole+ // script element dies on an uncaught error, so guard every access.+ function readStored() {+ try { return localStorage.getItem(STORAGE_KEY); } catch (_) { return null; }+ }+ function writeStored(value) {+ try { localStorage.setItem(STORAGE_KEY, value); } catch (_) {}+ }+ function urlOverride() {// URL param wins (useful for deterministic screenshots / share links)try {var param = new URLSearchParams(window.location.search).get('theme');if (param === 'light' || param === 'dark') return param;} catch (_) {}- var saved = localStorage.getItem(STORAGE_KEY);+ return null;+ }++ function resolveInitial() {+ var fromUrl = urlOverride();+ if (fromUrl) return fromUrl;+ var saved = readStored();if (saved === 'light' || saved === 'dark') return saved;return window.matchMedia('(prefers-color-scheme: light)').matches ? 'light' : 'dark';}@@ -642,12 +744,24 @@function toggle() {var next = html.getAttribute('data-theme') === 'dark' ? 'light' : 'dark';apply(next);- localStorage.setItem(STORAGE_KEY, next);+ writeStored(next);}apply(resolveInitial());btn.addEventListener('click', toggle);+ // Follow live OS theme changes while the user has no explicit preference.+ try {+ var media = window.matchMedia('(prefers-color-scheme: light)');+ var onChange = function (e) {+ var saved = readStored();+ if (urlOverride() || saved === 'light' || saved === 'dark') return;+ apply(e.matches ? 'light' : 'dark');+ };+ if (media.addEventListener) media.addEventListener('change', onChange);+ else if (media.addListener) media.addListener(onChange);+ } catch (_) {}+return { toggle: toggle };})();@@ -667,7 +781,10 @@var RASTER_SCALE = 4;function diagramFilename() {- var title = (document.title || 'diagram').replace(/\s+Architecture(\s+Diagram)?$/i, '').trim();+ var title = (document.title || 'diagram')+ .replace(/\s+Architecture(\s+Diagram)?$/i, '')+ .replace(/\s+Diagram$/i, '')+ .trim();return title.replace(/[^a-z0-9_\-]+/gi, '-').toLowerCase().replace(/^-+|-+$/g, '') || 'diagram';@@ -710,21 +827,37 @@clone.setAttribute('height', vb.height * scale);clone.setAttribute('xmlns', 'http://www.w3.org/2000/svg');- var hostStyle = Array.prototype.map.call(document.querySelectorAll('style'), function (s) {- return s.textContent;- }).join('\n');-- var varNames = [- '--bg','--grid','--text','--text-muted','--text-dim',- '--arrow','--arrow-emphasis','--mask',- '--frontend-fill','--frontend-stroke',- '--backend-fill','--backend-stroke',- '--database-fill','--database-stroke',- '--cloud-fill','--cloud-stroke',- '--security-fill','--security-stroke',- '--messagebus-fill','--messagebus-stroke',- '--external-fill','--external-stroke'- ];+ // Only the SVG-relevant rules: semantic classes, markers, and the+ // theme variable blocks. Toolbar/cards/print CSS can never apply+ // inside a standalone SVG and would only bloat the export.+ var hostStyle = (function () {+ var out = [];+ Array.prototype.forEach.call(document.styleSheets, function (sheet) {+ var rules;+ try { rules = sheet.cssRules; } catch (_) { return; } // cross-origin+ if (!rules) return;+ Array.prototype.forEach.call(rules, function (rule) {+ if (rule.type !== 1) return; // plain style rules only+ var sel = rule.selectorText || '';+ if (/(^|,)\s*(svg|:root|\[data-theme|\.c-|\.t-|\.a-|\.m-)/.test(sel)) {+ out.push(rule.cssText);+ }+ });+ });+ return out.join('\n');+ })();++ // Derive the variable list from the stylesheet so newly added theme+ // variables can never be missed by the export pipeline again+ // (--lane-fill/--lane-stroke once were).+ var varNames = (function () {+ var seen = {};+ var names = [];+ (hostStyle.match(/--[a-zA-Z0-9-]+(?=\s*:)/g) || []).forEach(function (n) {+ if (!seen[n]) { seen[n] = true; names.push(n); }+ });+ return names;+ })();// Resolve the full variable set for a given data-theme via an// off-DOM probe, independent of what the viewer is currently set to.@@ -769,7 +902,7 @@style.textContent =fontFallback + "\n" +- "svg { font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace; }\n" ++ "svg { font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, 'DejaVu Sans Mono', 'Liberation Mono', 'Noto Sans Mono CJK SC', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', monospace; }\n" +hostStyle + "\n" +":root, svg { " + darkVars + " }\n" +"@media (prefers-color-scheme: light) { :root, svg { " + lightVars + " } }\n" +@@ -797,7 +930,7 @@// Keep this order.style.textContent =fontFallback + "\n" +- "svg { font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace; }\n" ++ "svg { font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, 'DejaVu Sans Mono', 'Liberation Mono', 'Noto Sans Mono CJK SC', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', monospace; }\n" +hostStyle + "\n" +":root, svg { " + vars + " }\n";@@ -922,23 +1055,30 @@});// ---- Toast ----------------------------------------------------------+ // A live region only announces CHANGES to an existing node, so the toast+ // element is created once up front and updated in place.+ var toastEl = document.createElement('div');+ toastEl.className = 'archify-toast';+ toastEl.setAttribute('role', 'status');+ document.body.appendChild(toastEl);+ var toastTimer = null;+function toast(msg) {- var t = document.createElement('div');- t.className = 'archify-toast';- t.textContent = msg;- document.body.appendChild(t);- requestAnimationFrame(function () { t.classList.add('show'); });- setTimeout(function () {- t.classList.remove('show');- setTimeout(function () { t.remove(); }, 300);- }, 1500);+ toastEl.textContent = '';+ requestAnimationFrame(function () {+ toastEl.textContent = msg;+ toastEl.classList.add('show');+ });+ clearTimeout(toastTimer);+ toastTimer = setTimeout(function () { toastEl.classList.remove('show'); }, 1500);}- function open() {+ function open(focusLast) {menu.classList.add('open');btn.setAttribute('aria-expanded', 'true');- var first = items().filter(function (i) { return !i.disabled; })[0];- if (first) first.focus();+ var available = items().filter(function (i) { return !i.disabled; });+ var target = focusLast ? available[available.length - 1] : available[0];+ if (target) target.focus();}function close(focusTrigger) {menu.classList.remove('open');@@ -952,6 +1092,13 @@if (isOpen()) close(false);else open();});+ // APG menu-button pattern: ArrowDown/ArrowUp on the trigger opens the menu.+ btn.addEventListener('keydown', function (e) {+ if (e.key === 'ArrowDown' || e.key === 'ArrowUp') {+ e.preventDefault();+ if (!isOpen()) open(e.key === 'ArrowUp');+ }+ });document.addEventListener('click', function (e) {if (!menu.contains(e.target) && e.target !== btn) close(false);});@@ -987,7 +1134,7 @@function runExport(format) {var base = diagramFilename();- close(false);+ close(true);return (format === 'svg'? Promise.resolve(serializeSvg(1, { autoTheme: true })).then(function (d) {download(new Blob([d.svgString], { type: 'image/svg+xml;charset=utf-8' }), base + '.svg');@@ -1002,14 +1149,25 @@}function runCopy() {- close(false);+ close(true);if (!canCopyImage()) {alert('Clipboard image write not supported in this browser.');return;}- return rasterize('png').then(function (blob) {- return navigator.clipboard.write([new ClipboardItem({ 'image/png': blob })]);- }).then(function () {+ // WebKit requires ClipboardItem to be constructed synchronously inside+ // the user gesture — pass the pending Promise<Blob> as the item value.+ // Browsers that reject promise values throw synchronously; fall back+ // to awaiting the blob first (works in Chromium/Firefox).+ var blobPromise = rasterize('png');+ var writePromise;+ try {+ writePromise = navigator.clipboard.write([new ClipboardItem({ 'image/png': blobPromise })]);+ } catch (_) {+ writePromise = blobPromise.then(function (blob) {+ return navigator.clipboard.write([new ClipboardItem({ 'image/png': blob })]);+ });+ }+ return writePromise.then(function () {toast('Copied PNG to clipboard');}).catch(function (err) {console.error(err);diff --git a/examples/workflow-agent-tool-call-rendered.html b/examples/workflow-agent-tool-call-rendered.htmlindex a4cb6f19..6bba3a24 100644--- a/examples/workflow-agent-tool-call-rendered.html+++ b/examples/workflow-agent-tool-call-rendered.html@@ -3,8 +3,36 @@<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0">+ <meta name="generator" content="archify 2.6.0"><title>Agent Tool Call Workflow Diagram</title>- <link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;600;700&display=swap" rel="stylesheet">+ <script>+ // Resolve the theme before first paint so light-preference users don't+ // see a dark flash. The toolbar script below re-applies with UI state.+ (function () {+ try {+ var theme = null;+ try {+ var param = new URLSearchParams(window.location.search).get('theme');+ if (param === 'light' || param === 'dark') theme = param;+ } catch (_) {}+ if (!theme) {+ try { theme = localStorage.getItem('archify-theme'); } catch (_) {}+ }+ if (theme !== 'light' && theme !== 'dark') {+ theme = window.matchMedia('(prefers-color-scheme: light)').matches ? 'light' : 'dark';+ }+ document.documentElement.setAttribute('data-theme', theme);+ } catch (_) {}+ })();+ </script>+ <!-- Async font load: a blackholed network must not block first paint.+ The body font stack falls back to system monospace until it lands. -->+ <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>+ <link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;600;700&display=swap"+ rel="stylesheet" media="print" onload="this.media='all'">+ <noscript>+ <link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;600;700&display=swap" rel="stylesheet">+ </noscript><style>/* ==========================================================THEME VARIABLES — switch by toggling [data-theme] on <html>@@ -16,6 +44,8 @@--text: #ffffff;--text-muted: #94a3b8;--text-dim: #475569;+ /* UI chrome (menu hints, footer) needs more contrast than SVG .t-dim accents */+ --text-faint: #7d8da1;--panel: rgba(15, 23, 42, 0.5);--panel-border: #1e293b;@@ -57,6 +87,7 @@--text: #0f172a;--text-muted: #64748b;--text-dim: #94a3b8;+ --text-faint: #64748b;--panel: #ffffff;--panel-border: #e2e8f0;@@ -93,7 +124,7 @@* { margin: 0; padding: 0; box-sizing: border-box; }body {- font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;+ font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, 'DejaVu Sans Mono', 'Liberation Mono', 'Noto Sans Mono CJK SC', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', monospace;background: var(--bg);min-height: 100vh;padding: 2rem;@@ -199,7 +230,7 @@.footer {text-align: center;margin-top: 1.5rem;- color: var(--text-dim);+ color: var(--text-faint);font-size: 0.75rem;}@@ -212,6 +243,9 @@@page { size: landscape; margin: 1.5cm; }@media print {+ /* Force the FULL light palette — including component fills/strokes and+ lane/arrow colors — so printing from dark theme doesn't put neon+ strokes and translucent dark fills on white paper. */:root, [data-theme="dark"], [data-theme="light"] {--bg: #ffffff;--grid: transparent;@@ -220,11 +254,30 @@--text: #0f172a;--text-muted: #475569;--text-dim: #94a3b8;+ --text-faint: #64748b;--mask: #ffffff;+ --lane-fill: rgba(248, 250, 252, 0.65);+ --lane-stroke: #cbd5e1;+ --arrow: #94a3b8;+ --arrow-emphasis: #059669;+ --frontend-fill: rgba(34, 211, 238, 0.15);+ --frontend-stroke: #0891b2;+ --backend-fill: rgba(52, 211, 153, 0.18);+ --backend-stroke: #059669;+ --database-fill: rgba(167, 139, 250, 0.2);+ --database-stroke: #7c3aed;+ --cloud-fill: rgba(251, 191, 36, 0.18);+ --cloud-stroke: #d97706;+ --security-fill: rgba(251, 113, 133, 0.15);+ --security-stroke: #e11d48;+ --messagebus-fill: rgba(251, 146, 60, 0.15);+ --messagebus-stroke:#ea580c;+ --external-fill: rgba(148, 163, 184, 0.18);+ --external-stroke: #64748b;}body { background: #ffffff !important; padding: 0; }.container { max-width: none; }- .toolbar, .archify-toast { display: none !important; }+ .toolbar, .archify-toast, .no-print { display: none !important; }.diagram-container, .card { box-shadow: none; border-color: #e2e8f0; }.cards { grid-template-columns: 1fr 1fr; }/* Ensure elements break sensibly across pages */@@ -295,7 +348,7 @@background: var(--toolbar-hover);}.toolbar .export-menu .hint {- color: var(--text-dim);+ color: var(--text-faint);font-size: 0.625rem;}.toolbar .export-menu hr {@@ -426,11 +479,11 @@</button><div class="export-menu" id="export-menu" role="menu" aria-label="Export"><button data-action="copy" type="button" role="menuitem" tabindex="-1">Copy to clipboard <span class="hint">PNG</span></button>- <hr role="separator" aria-hidden="true">+ <hr role="separator"><button data-format="png" type="button" role="menuitem" tabindex="-1">Download PNG</button><button data-format="jpeg" type="button" role="menuitem" tabindex="-1">Download JPEG</button><button data-format="webp" type="button" role="menuitem" tabindex="-1">Download WebP</button>- <hr role="separator" aria-hidden="true">+ <hr role="separator"><button data-format="svg" type="button" role="menuitem" tabindex="-1">Download SVG <span class="hint">vector</span></button></div></div>@@ -448,7 +501,7 @@<!-- Main Diagram --><div class="diagram-container">- <svg viewBox="0 0 720 780">+ <svg viewBox="0 0 720 780" role="img" aria-label="Agent Tool Call Workflow — Renderer-driven workflow prototype with lanes, anchored nodes, and orthogonal edges (workflow diagram)"><!-- Definitions --><defs><marker id="arrowhead" markerWidth="10" markerHeight="7" refX="9" refY="3.5" orient="auto">@@ -631,7 +684,7 @@<!-- Footer --><p class="footer">- Workflow diagram • Built with Archify • Press <kbd>T</kbd> for theme and <kbd>E</kbd> for export+ Workflow diagram • Built with Archify<span class="no-print"> • Press <kbd>T</kbd> for theme and <kbd>E</kbd> for export</span></p></div>@@ -648,13 +701,27 @@var icon = document.getElementById('theme-icon');var label = document.getElementById('theme-label');- function resolveInitial() {+ // localStorage can throw (blocked cookies, sandboxed iframes); the whole+ // script element dies on an uncaught error, so guard every access.+ function readStored() {+ try { return localStorage.getItem(STORAGE_KEY); } catch (_) { return null; }+ }+ function writeStored(value) {+ try { localStorage.setItem(STORAGE_KEY, value); } catch (_) {}+ }+ function urlOverride() {// URL param wins (useful for deterministic screenshots / share links)try {var param = new URLSearchParams(window.location.search).get('theme');if (param === 'light' || param === 'dark') return param;} catch (_) {}- var saved = localStorage.getItem(STORAGE_KEY);+ return null;+ }++ function resolveInitial() {+ var fromUrl = urlOverride();+ if (fromUrl) return fromUrl;+ var saved = readStored();if (saved === 'light' || saved === 'dark') return saved;return window.matchMedia('(prefers-color-scheme: light)').matches ? 'light' : 'dark';}@@ -669,12 +736,24 @@function toggle() {var next = html.getAttribute('data-theme') === 'dark' ? 'light' : 'dark';apply(next);- localStorage.setItem(STORAGE_KEY, next);+ writeStored(next);}apply(resolveInitial());btn.addEventListener('click', toggle);+ // Follow live OS theme changes while the user has no explicit preference.+ try {+ var media = window.matchMedia('(prefers-color-scheme: light)');+ var onChange = function (e) {+ var saved = readStored();+ if (urlOverride() || saved === 'light' || saved === 'dark') return;+ apply(e.matches ? 'light' : 'dark');+ };+ if (media.addEventListener) media.addEventListener('change', onChange);+ else if (media.addListener) media.addListener(onChange);+ } catch (_) {}+return { toggle: toggle };})();@@ -694,7 +773,10 @@var RASTER_SCALE = 4;function diagramFilename() {- var title = (document.title || 'diagram').replace(/\s+Architecture(\s+Diagram)?$/i, '').trim();+ var title = (document.title || 'diagram')+ .replace(/\s+Architecture(\s+Diagram)?$/i, '')+ .replace(/\s+Diagram$/i, '')+ .trim();return title.replace(/[^a-z0-9_\-]+/gi, '-').toLowerCase().replace(/^-+|-+$/g, '') || 'diagram';@@ -737,21 +819,37 @@clone.setAttribute('height', vb.height * scale);clone.setAttribute('xmlns', 'http://www.w3.org/2000/svg');- var hostStyle = Array.prototype.map.call(document.querySelectorAll('style'), function (s) {- return s.textContent;- }).join('\n');-- var varNames = [- '--bg','--grid','--text','--text-muted','--text-dim',- '--arrow','--arrow-emphasis','--mask',- '--frontend-fill','--frontend-stroke',- '--backend-fill','--backend-stroke',- '--database-fill','--database-stroke',- '--cloud-fill','--cloud-stroke',- '--security-fill','--security-stroke',- '--messagebus-fill','--messagebus-stroke',- '--external-fill','--external-stroke'- ];+ // Only the SVG-relevant rules: semantic classes, markers, and the+ // theme variable blocks. Toolbar/cards/print CSS can never apply+ // inside a standalone SVG and would only bloat the export.+ var hostStyle = (function () {+ var out = [];+ Array.prototype.forEach.call(document.styleSheets, function (sheet) {+ var rules;+ try { rules = sheet.cssRules; } catch (_) { return; } // cross-origin+ if (!rules) return;+ Array.prototype.forEach.call(rules, function (rule) {+ if (rule.type !== 1) return; // plain style rules only+ var sel = rule.selectorText || '';+ if (/(^|,)\s*(svg|:root|\[data-theme|\.c-|\.t-|\.a-|\.m-)/.test(sel)) {+ out.push(rule.cssText);+ }+ });+ });+ return out.join('\n');+ })();++ // Derive the variable list from the stylesheet so newly added theme+ // variables can never be missed by the export pipeline again+ // (--lane-fill/--lane-stroke once were).+ var varNames = (function () {+ var seen = {};+ var names = [];+ (hostStyle.match(/--[a-zA-Z0-9-]+(?=\s*:)/g) || []).forEach(function (n) {+ if (!seen[n]) { seen[n] = true; names.push(n); }+ });+ return names;+ })();// Resolve the full variable set for a given data-theme via an// off-DOM probe, independent of what the viewer is currently set to.@@ -796,7 +894,7 @@style.textContent =fontFallback + "\n" +- "svg { font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace; }\n" ++ "svg { font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, 'DejaVu Sans Mono', 'Liberation Mono', 'Noto Sans Mono CJK SC', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', monospace; }\n" +hostStyle + "\n" +":root, svg { " + darkVars + " }\n" +"@media (prefers-color-scheme: light) { :root, svg { " + lightVars + " } }\n" +@@ -824,7 +922,7 @@// Keep this order.style.textContent =fontFallback + "\n" +- "svg { font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace; }\n" ++ "svg { font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, 'DejaVu Sans Mono', 'Liberation Mono', 'Noto Sans Mono CJK SC', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', monospace; }\n" +hostStyle + "\n" +":root, svg { " + vars + " }\n";@@ -949,23 +1047,30 @@});// ---- Toast ----------------------------------------------------------+ // A live region only announces CHANGES to an existing node, so the toast+ // element is created once up front and updated in place.+ var toastEl = document.createElement('div');+ toastEl.className = 'archify-toast';+ toastEl.setAttribute('role', 'status');+ document.body.appendChild(toastEl);+ var toastTimer = null;+function toast(msg) {- var t = document.createElement('div');- t.className = 'archify-toast';- t.textContent = msg;- document.body.appendChild(t);- requestAnimationFrame(function () { t.classList.add('show'); });- setTimeout(function () {- t.classList.remove('show');- setTimeout(function () { t.remove(); }, 300);- }, 1500);+ toastEl.textContent = '';+ requestAnimationFrame(function () {+ toastEl.textContent = msg;+ toastEl.classList.add('show');+ });+ clearTimeout(toastTimer);+ toastTimer = setTimeout(function () { toastEl.classList.remove('show'); }, 1500);}- function open() {+ function open(focusLast) {menu.classList.add('open');btn.setAttribute('aria-expanded', 'true');- var first = items().filter(function (i) { return !i.disabled; })[0];- if (first) first.focus();+ var available = items().filter(function (i) { return !i.disabled; });+ var target = focusLast ? available[available.length - 1] : available[0];+ if (target) target.focus();}function close(focusTrigger) {menu.classList.remove('open');@@ -979,6 +1084,13 @@if (isOpen()) close(false);else open();});+ // APG menu-button pattern: ArrowDown/ArrowUp on the trigger opens the menu.+ btn.addEventListener('keydown', function (e) {+ if (e.key === 'ArrowDown' || e.key === 'ArrowUp') {+ e.preventDefault();+ if (!isOpen()) open(e.key === 'ArrowUp');+ }+ });document.addEventListener('click', function (e) {if (!menu.contains(e.target) && e.target !== btn) close(false);});@@ -1014,7 +1126,7 @@function runExport(format) {var base = diagramFilename();- close(false);+ close(true);return (format === 'svg'? Promise.resolve(serializeSvg(1, { autoTheme: true })).then(function (d) {download(new Blob([d.svgString], { type: 'image/svg+xml;charset=utf-8' }), base + '.svg');@@ -1029,14 +1141,25 @@}function runCopy() {- close(false);+ close(true);if (!canCopyImage()) {alert('Clipboard image write not supported in this browser.');return;}- return rasterize('png').then(function (blob) {- return navigator.clipboard.write([new ClipboardItem({ 'image/png': blob })]);- }).then(function () {+ // WebKit requires ClipboardItem to be constructed synchronously inside+ // the user gesture — pass the pending Promise<Blob> as the item value.+ // Browsers that reject promise values throw synchronously; fall back+ // to awaiting the blob first (works in Chromium/Firefox).+ var blobPromise = rasterize('png');+ var writePromise;+ try {+ writePromise = navigator.clipboard.write([new ClipboardItem({ 'image/png': blobPromise })]);+ } catch (_) {+ writePromise = blobPromise.then(function (blob) {+ return navigator.clipboard.write([new ClipboardItem({ 'image/png': blob })]);+ });+ }+ return writePromise.then(function () {toast('Copied PNG to clipboard');}).catch(function (err) {console.error(err);