Skip to content

Turn any idea, plan, or codebase into a beautiful interactive diagram. An agent skill for Claude Code, Codex, and more.

v2.1: copy PNG to clipboard, 1x/2x/4x scale selector

tt-a1i4bb1dd7bce19
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a98e64cf..9f1d680d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,19 @@
All notable changes are documented here. Format loosely follows [Keep a Changelog](https://keepachangelog.com/).
+## [2.1.0] — 2026-04-15
+
+### Added
+- **Copy PNG to clipboard.** New menu action writes the diagram straight to the system clipboard via `ClipboardItem` / `navigator.clipboard.write` so it can be pasted into Slack, Notion, GitHub, Figma, Keynote, etc. Item is dimmed on browsers that don't support clipboard image writes.
+- **Export scale selector (1× / 2× / 4×)** at the top of the Export menu. Raster downloads and Copy use the selected scale. Selection persists in `localStorage`. Keyboard: <kbd>←</kbd> / <kbd>→</kbd> switch scale.
+- **Toast feedback** — brief "Copied PNG to clipboard (2×)" confirmation after successful copy.
+- **URL parameter `?openExport=1`** — auto-opens the Export menu on load. Primarily for deterministic screenshots and live demos.
+- Screenshot showing the Export menu open (`examples/images/archify-menu.png`) wired into the README preview section.
+
+### Changed
+- Export menu items renamed from `PNG / JPEG / WebP / SVG` to `Download PNG / JPEG / WebP / SVG` to disambiguate from the new `Copy PNG` action above.
+- `SCALE` constant replaced by `getScale()` reading from the radiogroup; scale flows through `rasterize()` and clipboard copy alike.
+
## [2.0.0] — 2026-04-15
First Archify release. Fork / rewrite of
diff --git a/README.md b/README.md
index 678f08de..9135b4e3 100644
--- a/README.md
+++ b/README.md
@@ -1,42 +1,50 @@
# Archify
-**Generate beautiful architecture diagrams in chat. Switch dark / light. Export PNG / JPEG / WebP / SVG.**
+**Generate beautiful architecture diagrams in chat. Switch dark / light. Copy to clipboard or export PNG / JPEG / WebP / SVG at 1× / 2× / 4×.**
-Archify is a [Claude Skill](https://support.claude.com/en/articles/12512180-using-skills-in-claude) that turns a plain-English description of your system into a polished, self-contained architecture diagram — a single HTML file you can open, toggle themes on, and export to any common image format.
+Archify is a [Claude Skill](https://support.claude.com/en/articles/12512180-using-skills-in-claude) that turns a plain-English description of your system into a polished, self-contained architecture diagram — a single HTML file you can open, toggle themes on, copy to the clipboard, and export to any common image format.
- **No design skills needed** — describe your architecture in English, get a diagram
- **Built-in theme toggle** — one click between dark and light, persists across sessions
-- **One-click image export** — PNG, JPEG, WebP (2x retina), or SVG (vector)
+- **Copy PNG to clipboard** — one click, paste straight into Slack / Notion / GitHub
+- **Export to image** — PNG, JPEG, WebP, or SVG at user-selected 1× / 2× / 4× scale
- **Self-contained HTML** — zero dependencies, share by sending the file
- **Iterate by chat** — "add Redis", "move auth to the left", "use emerald for the API"
![License](https://img.shields.io/badge/license-MIT-22c55e?style=flat-square)
![Claude](https://img.shields.io/badge/Claude-Skill-7C3AED?style=flat-square)
-![Version](https://img.shields.io/badge/version-2.0-0891b2?style=flat-square)
+![Version](https://img.shields.io/badge/version-2.1-0891b2?style=flat-square)
## Preview
-Same diagram, two themes, one click to switch — and the Export menu top-right:
+Same diagram, two themes, one click to switch:
| Dark | Light |
|---|---|
| ![Dark theme](examples/images/archify-dark.png) | ![Light theme](examples/images/archify-light.png) |
-Live example: [`examples/web-app.html`](examples/web-app.html) — open in a browser, press <kbd>T</kbd> to toggle, <kbd>E</kbd> to open Export.
+The Export menu with the 1× / 2× / 4× scale selector and Copy-to-clipboard:
-## What's new in 2.0
+![Export menu](examples/images/archify-menu.png)
-Archify is based on [Cocoon-AI/architecture-diagram-generator](https://github.com/Cocoon-AI/architecture-diagram-generator) v1.0 (dark-only, HTML output). 2.0 rewrites the template around a themeable CSS-variable system and adds a client-side export pipeline:
+Live example: [`examples/web-app.html`](examples/web-app.html) — open in a browser, press <kbd>T</kbd> to toggle theme, <kbd>E</kbd> to open Export. Append `?theme=light` or `?openExport=1` to the URL for deterministic screenshots.
-| Feature | v1.0 | Archify 2.0 |
-|---|---|---|
-| Dark theme | Yes | Yes |
-| Light theme | — | Yes, one-click toggle |
-| Theme persistence | — | `localStorage` + `prefers-color-scheme` |
-| PNG export | manual screenshot | Built-in, 2x retina |
-| JPEG / WebP export | — | Built-in, 2x retina |
-| SVG export | — | Built-in, vector, styles inlined |
-| Styling model | Inline `fill` / `stroke` | CSS custom properties + semantic classes |
+## What's new
+
+Archify is based on [Cocoon-AI/architecture-diagram-generator](https://github.com/Cocoon-AI/architecture-diagram-generator) v1.0 (dark-only, HTML output). 2.0 rewrote the template around a themeable CSS-variable system and added a client-side export pipeline; 2.1 extends that with copy-to-clipboard and selectable export scale:
+
+| Feature | v1.0 | Archify 2.0 | Archify 2.1 |
+|---|---|---|---|
+| Dark theme | Yes | Yes | Yes |
+| Light theme | — | Yes (toggle) | Yes (toggle) |
+| Theme persistence | — | `localStorage` + `prefers-color-scheme` | + URL param `?theme=` |
+| PNG download | manual screenshot | 2× retina | **1× / 2× / 4× user-selectable** |
+| JPEG / WebP download | — | 2× retina | **1× / 2× / 4×** |
+| SVG download | — | Vector, styles inlined | Same |
+| Copy PNG to clipboard | — | — | **Yes** (via `ClipboardItem`) |
+| Keyboard shortcuts | — | — | **<kbd>T</kbd> / <kbd>E</kbd> + full menu nav** |
+| Accessibility | — | — | **ARIA semantics + focus-visible** |
+| Styling model | Inline `fill` / `stroke` | CSS custom properties + semantic classes | Same |
## Quick start
@@ -98,20 +106,40 @@ That's it. Claude generates an HTML file you can open in any browser. Iterate by
## Using the output
-Open the generated HTML in any browser. Top-right you'll see:
+Open the generated HTML in any browser. Top-right you'll see two buttons:
+
+- **Theme button** (Dark / Light) — one click flip, persisted across sessions. Shortcut: <kbd>T</kbd>.
+- **Export menu** — opens a dropdown with a scale selector and five actions. Shortcut: <kbd>E</kbd>.
+
+### Export menu
+
+| Control | What it does |
+|---|---|
+| **1× / 2× / 4×** scale selector | Sets the raster output scale; remembered per-browser. 1× = compact, 2× = retina (default), 4× = print / slides. |
+| **Copy PNG** | Puts a PNG of the current diagram straight on your clipboard at the selected scale. Paste into Slack, Notion, GitHub, Figma. |
+| **Download PNG / JPEG / WebP** | Saves a raster image at the selected scale. JPEG/WebP are painted over the current theme's background (no alpha); PNG keeps transparency. |
+| **Download SVG** | Vector export with all styles inlined. Edit in Figma / Illustrator. Scale selector doesn't apply — SVG is resolution-independent. |
-- **Theme button** — toggles Dark / Light. Remembered across sessions. Shortcut: <kbd>T</kbd>.
-- **Export menu** — drops down with PNG / JPEG / WebP / SVG options. Shortcut: <kbd>E</kbd>.
+### Keyboard
-Inside the menu: <kbd>Arrow</kbd> keys navigate, <kbd>Enter</kbd> exports, <kbd>Esc</kbd> closes.
+- <kbd>T</kbd> anywhere — toggle theme
+- <kbd>E</kbd> anywhere — open the Export menu
+- <kbd>←</kbd> <kbd>→</kbd> on the scale selector — switch scale
+- <kbd>↑</kbd> <kbd>↓</kbd> inside the menu — navigate actions
+- <kbd>Home</kbd> / <kbd>End</kbd> — jump to first / last action
+- <kbd>Enter</kbd> / <kbd>Space</kbd> — activate
+- <kbd>Esc</kbd> — close menu
-The export respects the **current** theme — flip to light mode first if you want a light-mode PNG. PNG/JPEG/WebP are rendered at 2x retina; SVG is true vector with all styles inlined, so it scales cleanly and can be further edited in Figma or Illustrator.
+### URL parameters
-**URL parameter:** append `?theme=light` or `?theme=dark` to force a starting theme — handy for deterministic screenshots, share links, or embedding in docs pipelines.
+- `?theme=light` or `?theme=dark` — force a starting theme (deterministic screenshots, share links, embeds)
+- `?openExport=1` — auto-open the Export menu on load (demo / docs screenshots)
-**Format support:** WebP depends on your browser's canvas encoder. If WebP isn't supported (older Safari), the menu item is dimmed and disabled. PNG and JPEG are universal.
+### Notes
-**Font caveat:** exported raster images use the system's monospace fallback (`ui-monospace` / Menlo / Consolas) because the sandboxed image-rendering context can't fetch Google Fonts. Install JetBrains Mono locally for pixel-perfect exports.
+- **WebP support** depends on your browser's canvas encoder. If unavailable (older Safari), the menu item is dimmed and disabled. PNG and JPEG are universal.
+- **Clipboard support** for images requires `ClipboardItem` + `navigator.clipboard.write` (Chromium, Firefox 127+, Safari 16+). If unavailable, Copy PNG is dimmed.
+- **Fonts in exports**: raster images use the system monospace fallback (`ui-monospace` / Menlo / Consolas) because the sandboxed image-rendering context can't fetch Google Fonts. Install JetBrains Mono locally for pixel-perfect rendering.
## Example prompts
diff --git a/archify.zip b/archify.zip
index 8481f314..24327f08 100644
Binary files a/archify.zip and b/archify.zip differ
diff --git a/archify/assets/template.html b/archify/assets/template.html
index d45b5fa5..1c414909 100644
--- a/archify/assets/template.html
+++ b/archify/assets/template.html
@@ -264,6 +264,55 @@
color: var(--text-dim);
font-size: 0.625rem;
}
+ .toolbar .export-menu .export-scale {
+ display: flex;
+ gap: 0.25rem;
+ padding: 0.125rem;
+ }
+ .toolbar .export-menu .export-scale button {
+ flex: 1;
+ width: auto;
+ justify-content: center;
+ padding: 0.3125rem 0.375rem;
+ font-size: 0.7rem;
+ border: 1px solid transparent;
+ border-radius: 0.25rem;
+ }
+ .toolbar .export-menu .export-scale button[aria-checked="true"] {
+ background: var(--toolbar-hover);
+ border-color: var(--frontend-stroke);
+ color: var(--frontend-stroke);
+ }
+ .toolbar .export-menu .export-sep {
+ height: 1px;
+ background: var(--toolbar-border);
+ margin: 0.25rem 0.375rem;
+ opacity: 0.6;
+ }
+
+ /* 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);
+ }
/* ==========================================================
SVG SEMANTIC CLASSES — use these instead of inline fill/stroke
@@ -328,11 +377,18 @@
aria-controls="export-menu">
Export <span aria-hidden="true">&#9662;</span>
</button>
- <div class="export-menu" id="export-menu" role="menu" aria-label="Export format">
- <button data-format="png" type="button" role="menuitem" tabindex="-1">PNG <span class="hint">2&times;</span></button>
- <button data-format="jpeg" type="button" role="menuitem" tabindex="-1">JPEG <span class="hint">2&times;</span></button>
- <button data-format="webp" type="button" role="menuitem" tabindex="-1">WebP <span class="hint">2&times;</span></button>
- <button data-format="svg" type="button" role="menuitem" tabindex="-1">SVG <span class="hint">vector</span></button>
+ <div class="export-menu" id="export-menu" role="menu" aria-label="Export">
+ <div class="export-scale" role="radiogroup" aria-label="Raster scale">
+ <button data-scale="1" type="button" role="radio" aria-checked="false" title="1x (compact)">1&times;</button>
+ <button data-scale="2" type="button" role="radio" aria-checked="true" title="2x (retina, default)">2&times;</button>
+ <button data-scale="4" type="button" role="radio" aria-checked="false" title="4x (print / slides)">4&times;</button>
+ </div>
+ <div class="export-sep" aria-hidden="true"></div>
+ <button data-action="copy" type="button" role="menuitem" tabindex="-1">Copy PNG <span class="hint">clipboard</span></button>
+ <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>
+ <button data-format="svg" type="button" role="menuitem" tabindex="-1">Download SVG <span class="hint">vector</span></button>
</div>
</div>
</div>
@@ -587,12 +643,13 @@
})();
/* ============================================================
- Export — PNG / JPEG / WebP / SVG
- PNG/JPEG/WebP are rendered from the SVG onto a 2x canvas.
- JPEG/WebP use the current theme's background color.
+ Export — PNG / JPEG / WebP / SVG (download) and Copy PNG (clipboard)
+ Raster scale is user-selectable (1x / 2x / 4x) and persists in
+ localStorage. JPEG/WebP paint the current theme's background
+ explicitly since those formats have no alpha.
============================================================ */
(function () {
- var SCALE = 2;
+ var SCALE_KEY = 'archify-export-scale';
function diagramFilename() {
var title = (document.title || 'diagram').replace(/\s+Architecture(\s+Diagram)?$/i, '').trim();
@@ -681,13 +738,14 @@
var data = serializeSvg();
var svgBlob = new Blob([data.svgString], { type: 'image/svg+xml;charset=utf-8' });
var svgUrl = URL.createObjectURL(svgBlob);
+ var scale = getScale();
return new Promise(function (resolve, reject) {
var img = new Image();
img.onload = function () {
var canvas = document.createElement('canvas');
- canvas.width = data.width * SCALE;
- canvas.height = data.height * SCALE;
+ canvas.width = data.width * scale;
+ canvas.height = data.height * scale;
var ctx = canvas.getContext('2d');
if (format === 'jpeg') {
ctx.fillStyle = currentBg();
@@ -714,11 +772,39 @@
var menu = document.getElementById('export-menu');
var btn = document.getElementById('btn-export');
var items = function () {
- return Array.prototype.slice.call(menu.querySelectorAll('button[data-format]'));
+ return Array.prototype.slice.call(menu.querySelectorAll('button[role="menuitem"]'));
+ };
+ var scaleButtons = function () {
+ return Array.prototype.slice.call(menu.querySelectorAll('.export-scale button[data-scale]'));
};
- // Raster format support detection — canvas.toBlob('image/webp') silently
- // returns a PNG on browsers without WebP encoding (Safari < 16).
+ // ---- Raster scale (1x / 2x / 4x) -------------------------------------
+ function getScale() {
+ var checked = menu.querySelector('.export-scale button[aria-checked="true"]');
+ return checked ? parseInt(checked.dataset.scale, 10) : 2;
+ }
+ function setScale(scale) {
+ var s = String(scale);
+ scaleButtons().forEach(function (b) {
+ b.setAttribute('aria-checked', b.dataset.scale === s ? 'true' : 'false');
+ });
+ try { localStorage.setItem(SCALE_KEY, s); } catch (_) {}
+ }
+ (function restoreScale() {
+ var saved = parseInt(localStorage.getItem(SCALE_KEY), 10);
+ if (saved === 1 || saved === 2 || saved === 4) setScale(saved);
+ })();
+
+ // ---- 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';
@@ -729,15 +815,33 @@
} catch (_) { return false; }
}
- // Gray out unsupported menu items.
+ // Gray out unsupported items.
items().forEach(function (it) {
- if (!supports(it.dataset.format)) {
+ 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 ----------------------------------------------------------
+ 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);
+ }
+
function open() {
menu.classList.add('open');
btn.setAttribute('aria-expanded', 'true');
@@ -760,8 +864,29 @@
if (!menu.contains(e.target) && e.target !== btn) close(false);
});
- // Keyboard navigation inside the menu: ArrowUp/Down, Home/End, Esc, Tab.
+ // Keyboard navigation inside the menu.
+ // Scale radio group: Left/Right moves + selects (roving tabindex).
+ // 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 onScale = e.target.closest('.export-scale button');
+ if (onScale) {
+ var sb = scaleButtons();
+ var idx = sb.indexOf(onScale);
+ if (e.key === 'ArrowLeft' || e.key === 'ArrowRight') {
+ e.preventDefault();
+ var next = e.key === 'ArrowRight'
+ ? sb[(idx + 1) % sb.length]
+ : sb[(idx - 1 + sb.length) % sb.length];
+ setScale(next.dataset.scale);
+ next.focus();
+ }
+ return;
+ }
+
var available = items().filter(function (i) { return !i.disabled; });
var current = available.indexOf(document.activeElement);
switch (e.key) {
@@ -781,13 +906,6 @@
e.preventDefault();
if (available.length) available[available.length - 1].focus();
break;
- case 'Escape':
- e.preventDefault();
- close(true);
- break;
- case 'Tab':
- close(false);
- break;
}
});
@@ -807,13 +925,41 @@
});
}
+ function runCopy() {
+ close(false);
+ 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 () {
+ toast('Copied PNG to clipboard (' + getScale() + 'x)');
+ }).catch(function (err) {
+ console.error(err);
+ alert('Copy failed: ' + (err && err.message ? err.message : 'unknown'));
+ });
+ }
+
menu.addEventListener('click', function (e) {
- var target = e.target.closest('button[data-format]');
- if (!target || target.disabled) return;
- runExport(target.dataset.format);
+ var scaleBtn = e.target.closest('.export-scale button[data-scale]');
+ if (scaleBtn) { setScale(scaleBtn.dataset.scale); return; }
+
+ 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
+ try {
+ if (new URLSearchParams(window.location.search).get('openExport') === '1') {
+ setTimeout(open, 60);
+ }
+ } catch (_) {}
})();
/* ============================================================
diff --git a/examples/images/archify-dark.png b/examples/images/archify-dark.png
index f8f6c92b..d843a39c 100644
Binary files a/examples/images/archify-dark.png and b/examples/images/archify-dark.png differ
diff --git a/examples/images/archify-menu.png b/examples/images/archify-menu.png
new file mode 100644
index 00000000..801d1733
Binary files /dev/null and b/examples/images/archify-menu.png differ
diff --git a/examples/web-app.html b/examples/web-app.html
index f7da1dc2..dda1799a 100644
--- a/examples/web-app.html
+++ b/examples/web-app.html
@@ -264,6 +264,55 @@
color: var(--text-dim);
font-size: 0.625rem;
}
+ .toolbar .export-menu .export-scale {
+ display: flex;
+ gap: 0.25rem;
+ padding: 0.125rem;
+ }
+ .toolbar .export-menu .export-scale button {
+ flex: 1;
+ width: auto;
+ justify-content: center;
+ padding: 0.3125rem 0.375rem;
+ font-size: 0.7rem;
+ border: 1px solid transparent;
+ border-radius: 0.25rem;
+ }
+ .toolbar .export-menu .export-scale button[aria-checked="true"] {
+ background: var(--toolbar-hover);
+ border-color: var(--frontend-stroke);
+ color: var(--frontend-stroke);
+ }
+ .toolbar .export-menu .export-sep {
+ height: 1px;
+ background: var(--toolbar-border);
+ margin: 0.25rem 0.375rem;
+ opacity: 0.6;
+ }
+
+ /* 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);
+ }
/* ==========================================================
SVG SEMANTIC CLASSES — use these instead of inline fill/stroke
@@ -328,11 +377,18 @@
aria-controls="export-menu">
Export <span aria-hidden="true">&#9662;</span>
</button>
- <div class="export-menu" id="export-menu" role="menu" aria-label="Export format">
- <button data-format="png" type="button" role="menuitem" tabindex="-1">PNG <span class="hint">2&times;</span></button>
- <button data-format="jpeg" type="button" role="menuitem" tabindex="-1">JPEG <span class="hint">2&times;</span></button>
- <button data-format="webp" type="button" role="menuitem" tabindex="-1">WebP <span class="hint">2&times;</span></button>
- <button data-format="svg" type="button" role="menuitem" tabindex="-1">SVG <span class="hint">vector</span></button>
+ <div class="export-menu" id="export-menu" role="menu" aria-label="Export">
+ <div class="export-scale" role="radiogroup" aria-label="Raster scale">
+ <button data-scale="1" type="button" role="radio" aria-checked="false" title="1x (compact)">1&times;</button>
+ <button data-scale="2" type="button" role="radio" aria-checked="true" title="2x (retina, default)">2&times;</button>
+ <button data-scale="4" type="button" role="radio" aria-checked="false" title="4x (print / slides)">4&times;</button>
+ </div>
+ <div class="export-sep" aria-hidden="true"></div>
+ <button data-action="copy" type="button" role="menuitem" tabindex="-1">Copy PNG <span class="hint">clipboard</span></button>
+ <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>
+ <button data-format="svg" type="button" role="menuitem" tabindex="-1">Download SVG <span class="hint">vector</span></button>
</div>
</div>
</div>
@@ -539,7 +595,7 @@
<!-- Footer -->
<p class="footer">
- Try the <kbd>T</kbd> key to toggle theme &middot; Click <em>Export</em> for PNG / JPEG / WebP / SVG
+ Try <kbd>T</kbd> to toggle theme &middot; <kbd>E</kbd> for Export &middot; pick 1&times; / 2&times; / 4&times; scale &middot; PNG / JPEG / WebP / SVG or copy to clipboard
</p>
</div>
@@ -557,6 +613,7 @@
var label = document.getElementById('theme-label');
function resolveInitial() {
+ // 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;
@@ -586,12 +643,13 @@
})();
/* ============================================================
- Export — PNG / JPEG / WebP / SVG
- PNG/JPEG/WebP are rendered from the SVG onto a 2x canvas.
- JPEG/WebP use the current theme's background color.
+ Export — PNG / JPEG / WebP / SVG (download) and Copy PNG (clipboard)
+ Raster scale is user-selectable (1x / 2x / 4x) and persists in
+ localStorage. JPEG/WebP paint the current theme's background
+ explicitly since those formats have no alpha.
============================================================ */
(function () {
- var SCALE = 2;
+ var SCALE_KEY = 'archify-export-scale';
function diagramFilename() {
var title = (document.title || 'diagram').replace(/\s+Architecture(\s+Diagram)?$/i, '').trim();
@@ -680,13 +738,14 @@
var data = serializeSvg();
var svgBlob = new Blob([data.svgString], { type: 'image/svg+xml;charset=utf-8' });
var svgUrl = URL.createObjectURL(svgBlob);
+ var scale = getScale();
return new Promise(function (resolve, reject) {
var img = new Image();
img.onload = function () {
var canvas = document.createElement('canvas');
- canvas.width = data.width * SCALE;
- canvas.height = data.height * SCALE;
+ canvas.width = data.width * scale;
+ canvas.height = data.height * scale;
var ctx = canvas.getContext('2d');
if (format === 'jpeg') {
ctx.fillStyle = currentBg();
@@ -713,11 +772,39 @@
var menu = document.getElementById('export-menu');
var btn = document.getElementById('btn-export');
var items = function () {
- return Array.prototype.slice.call(menu.querySelectorAll('button[data-format]'));
+ return Array.prototype.slice.call(menu.querySelectorAll('button[role="menuitem"]'));
+ };
+ var scaleButtons = function () {
+ return Array.prototype.slice.call(menu.querySelectorAll('.export-scale button[data-scale]'));
};
- // Raster format support detection — canvas.toBlob('image/webp') silently
- // returns a PNG on browsers without WebP encoding (Safari < 16).
+ // ---- Raster scale (1x / 2x / 4x) -------------------------------------
+ function getScale() {
+ var checked = menu.querySelector('.export-scale button[aria-checked="true"]');
+ return checked ? parseInt(checked.dataset.scale, 10) : 2;
+ }
+ function setScale(scale) {
+ var s = String(scale);
+ scaleButtons().forEach(function (b) {
+ b.setAttribute('aria-checked', b.dataset.scale === s ? 'true' : 'false');
+ });
+ try { localStorage.setItem(SCALE_KEY, s); } catch (_) {}
+ }
+ (function restoreScale() {
+ var saved = parseInt(localStorage.getItem(SCALE_KEY), 10);
+ if (saved === 1 || saved === 2 || saved === 4) setScale(saved);
+ })();
+
+ // ---- 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';
@@ -728,15 +815,33 @@
} catch (_) { return false; }
}
- // Gray out unsupported menu items.
+ // Gray out unsupported items.
items().forEach(function (it) {
- if (!supports(it.dataset.format)) {
+ 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 ----------------------------------------------------------
+ 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);
+ }
+
function open() {
menu.classList.add('open');
btn.setAttribute('aria-expanded', 'true');
@@ -759,8 +864,29 @@
if (!menu.contains(e.target) && e.target !== btn) close(false);
});
- // Keyboard navigation inside the menu: ArrowUp/Down, Home/End, Esc, Tab.
+ // Keyboard navigation inside the menu.
+ // Scale radio group: Left/Right moves + selects (roving tabindex).
+ // 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 onScale = e.target.closest('.export-scale button');
+ if (onScale) {
+ var sb = scaleButtons();
+ var idx = sb.indexOf(onScale);
+ if (e.key === 'ArrowLeft' || e.key === 'ArrowRight') {
+ e.preventDefault();
+ var next = e.key === 'ArrowRight'
+ ? sb[(idx + 1) % sb.length]
+ : sb[(idx - 1 + sb.length) % sb.length];
+ setScale(next.dataset.scale);
+ next.focus();
+ }
+ return;
+ }
+
var available = items().filter(function (i) { return !i.disabled; });
var current = available.indexOf(document.activeElement);
switch (e.key) {
@@ -780,13 +906,6 @@
e.preventDefault();
if (available.length) available[available.length - 1].focus();
break;
- case 'Escape':
- e.preventDefault();
- close(true);
- break;
- case 'Tab':
- close(false);
- break;
}
});
@@ -806,13 +925,40 @@
});
}
+ function runCopy() {
+ close(false);
+ 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 () {
+ toast('Copied PNG to clipboard (' + getScale() + 'x)');
+ }).catch(function (err) {
+ console.error(err);
+ alert('Copy failed: ' + (err && err.message ? err.message : 'unknown'));
+ });
+ }
+
menu.addEventListener('click', function (e) {
- var target = e.target.closest('button[data-format]');
- if (!target || target.disabled) return;
- runExport(target.dataset.format);
+ var scaleBtn = e.target.closest('.export-scale button[data-scale]');
+ if (scaleBtn) { setScale(scaleBtn.dataset.scale); return; }
+
+ 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 };
+
+ try {
+ if (new URLSearchParams(window.location.search).get('openExport') === '1') {
+ setTimeout(open, 60);
+ }
+ } catch (_) {}
})();
/* ============================================================