Skip to content

feat: export canvas as PNG or SVG image#40

Merged
trmquang93 merged 1 commit intomainfrom
feat/export-canvas-image
Apr 26, 2026
Merged

feat: export canvas as PNG or SVG image#40
trmquang93 merged 1 commit intomainfrom
feat/export-canvas-image

Conversation

@trmquang93
Copy link
Copy Markdown
Collaborator

Summary

  • Adds Export as PNG and Export as SVG items to the File menu, exporting the canvas (entire flow, current scope, or rubber-band selection) for embedding in design docs, tickets, and chats.
  • Selection-priority chain: multi-select ▸ scope root ▸ entire canvas.
  • PNG renders at 2x pixel ratio (Retina) with a 16384px safety cap so large flows downscale gracefully instead of blanking out.
  • SVG is self-contained (screen images embedded as data URLs) so it renders standalone in Figma/Illustrator/Notion.

Implementation

  • New src/utils/exportCanvasImage.js — pure utility module with no React/JSX deps.
  • Reuses the existing screenContentToHref pattern (handles imageData, svgContent, and wireframe content types via wireframeToSvg).
  • Renders screens, bezier connections (color-coded by connectionPath), connection labels, sticky notes, and screen-group rectangles — matching the editor visuals while excluding editor chrome.
  • Hotspots drawn as subtle dashed overlays so reviewers can see tap targets.
  • No new runtime dependencies — uses native <canvas> and <svg> only.

Test plan

  • Unit tests added: 19 new tests in exportCanvasImage.test.js covering selection filtering, bounding-box math, SVG output, color paths, XML escaping, and screen-content encoding.
  • Full suite: 667/667 passed (npm test).
  • Lint: clean (npm run lint).
  • Build: clean, no new warnings (npm run build).
  • Manual: try Export as PNG with no selection — expect entire canvas as PNG.
  • Manual: rubber-band 2 screens, Export as SVG — expect only those screens + their direct connection.
  • Manual: set a scope root, Export as PNG — expect only the scoped sub-flow.
  • Manual: open the SVG in Figma — expect screen images visible, labels editable.

User guide

Updated src/pages/docs/userGuide.md with a new "Exporting Canvas Images (PNG / SVG)" section explaining scope rules, PNG-vs-SVG trade-offs, and what's included/excluded.

Closes backlog item 5.8.

Adds File-menu actions to export the canvas (entire flow, current
scope, or rubber-band selection) as a high-resolution PNG or
self-contained SVG for embedding in design docs, tickets, and chats.

The renderer reuses the existing screenToImage primitive to handle
all three screen content types (raw image, SVG, wireframe) and draws
connection bezier curves, sticky notes, and screen-group rectangles
without pulling in a DOM-capture dependency.

Selection priority: multi-select > scope root > entire canvas.
PNG renders at 2x pixel ratio with a 16384px safety cap.
@trmquang93 trmquang93 merged commit 6b762a8 into main Apr 26, 2026
1 check passed
@trmquang93 trmquang93 deleted the feat/export-canvas-image branch April 26, 2026 23:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant