From 852a005b3219ce9cc4f8224ac5ebcc6ce1fcc6b1 Mon Sep 17 00:00:00 2001 From: sukumarp2022 <121007359+sukumarp2022@users.noreply.github.com> Date: Thu, 14 May 2026 08:37:28 +0530 Subject: [PATCH] feat(web): add export as image screenshot to share menu (#1569) Add an option to export the current preview viewport as a PNG image. - Add requestPreviewSnapshot() utility in exports.ts (reuses the existing srcdoc snapshot bridge via postMessage) - Add exportAsImage() and dataUrlToBlob() helpers for Blob download - Add Export as image menu item in the HTML viewer share menu, gated behind srcdoc mode (bridge only present in srcdoc, not URL-load mode) - Refactor PreviewDrawOverlay to delegate to the shared requestPreviewSnapshot() instead of duplicating the snapshot logic - Add fileViewer.exportImage i18n key across all 19 locale files - Add 7 unit tests covering snapshot request, timeout, error handling, and download filename sanitization Fixes #1500 --- apps/web/src/components/FileViewer.tsx | 29 +++ .../web/src/components/PreviewDrawOverlay.tsx | 23 +-- apps/web/src/i18n/locales/ar.ts | 2 + apps/web/src/i18n/locales/de.ts | 2 + apps/web/src/i18n/locales/en.ts | 2 + apps/web/src/i18n/locales/es-ES.ts | 2 + apps/web/src/i18n/locales/fa.ts | 2 + apps/web/src/i18n/locales/fr.ts | 2 + apps/web/src/i18n/locales/hu.ts | 2 + apps/web/src/i18n/locales/id.ts | 2 + apps/web/src/i18n/locales/ja.ts | 2 + apps/web/src/i18n/locales/ko.ts | 2 + apps/web/src/i18n/locales/pl.ts | 2 + apps/web/src/i18n/locales/pt-BR.ts | 2 + apps/web/src/i18n/locales/ru.ts | 2 + apps/web/src/i18n/locales/th.ts | 2 + apps/web/src/i18n/locales/tr.ts | 2 + apps/web/src/i18n/locales/uk.ts | 2 + apps/web/src/i18n/locales/zh-CN.ts | 2 + apps/web/src/i18n/locales/zh-TW.ts | 2 + apps/web/src/i18n/types.ts | 2 + apps/web/src/runtime/exports.ts | 76 ++++++++ apps/web/tests/runtime/exports.test.ts | 169 ++++++++++++++++++ 23 files changed, 316 insertions(+), 19 deletions(-) diff --git a/apps/web/src/components/FileViewer.tsx b/apps/web/src/components/FileViewer.tsx index 9aaf13e401..c1f2ad4b20 100644 --- a/apps/web/src/components/FileViewer.tsx +++ b/apps/web/src/components/FileViewer.tsx @@ -46,6 +46,7 @@ import { import type { ProjectFilePreview } from '../providers/registry'; import { exportAsHtml, + exportAsImage, exportAsJsx, exportAsMd, exportAsPdf, @@ -54,6 +55,7 @@ import { exportReactComponentAsHtml, exportReactComponentAsZip, openSandboxedPreviewInNewTab, + requestPreviewSnapshot, } from '../runtime/exports'; import { buildReactComponentSrcdoc } from '../runtime/react-component'; import { buildSrcdoc } from '../runtime/srcdoc'; @@ -5485,6 +5487,33 @@ function HtmlViewer({ {t('fileViewer.exportMd')} + {!useUrlLoadPreview ? ( + + ) : null}