From 6f23c620c1e508d49a695210ab57dda2c550a809 Mon Sep 17 00:00:00 2001 From: Aleksey Shakhmatov Date: Fri, 22 May 2026 21:12:54 +0300 Subject: [PATCH] feat(toolbar): copy diagram to clipboard as PNG MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add a "⧉ Copy" button that places the current diagram on the system clipboard as a PNG via the async Clipboard API (ClipboardItem). The write is invoked synchronously with the PNG handed over as a promise, so it stays inside the click gesture WebKit requires. PNG export and clipboard copy now re-render through renderRaster(), which forces htmlLabels off via an injected init directive. Flowcharts otherwise emit HTML labels that taint the canvas and make toBlob()/clipboard writes fail — this also fixes pre-existing flowchart PNG export. The live preview and SVG export keep the richer foreignObject labels. Verified end-to-end: renderRaster yields a foreignObject-free SVG, it rasterizes without tainting, and clipboard.write resolves on a real click. --- README.md | 4 +++- src/lib/components/Toolbar.svelte | 38 ++++++++++++++++++++++++++++--- src/lib/export.ts | 27 +++++++++++++++++++--- src/lib/mermaid.ts | 15 ++++++++++++ 4 files changed, 77 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 084b323..d9127ed 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,9 @@ TypeScript** frontend using **CodeMirror 6** and **Mermaid 11**. **focus mode** spotlights any node and its neighbours so you can read a dense graph without changing it. Every rewrite lands in the editor and is reversible with ⌘Z. -- **Export** the current diagram to **SVG** or **PNG** (2× scale). +- **Export** the current diagram to **SVG** or **PNG** (2× scale), or **copy a + PNG straight to the clipboard**. (PNG/clipboard re-render flowcharts with + text labels so the bitmap rasterizes cleanly across platforms.) - **Project registry** — recently opened projects are remembered in a local SQLite database so you can jump back in from the start screen. - **Themes** — switch the Mermaid theme (default / neutral / dark / forest / diff --git a/src/lib/components/Toolbar.svelte b/src/lib/components/Toolbar.svelte index 3050762..beb375d 100644 --- a/src/lib/components/Toolbar.svelte +++ b/src/lib/components/Toolbar.svelte @@ -1,8 +1,18 @@
@@ -63,6 +88,13 @@
+