Skip to content

AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.

feat(sharing): download the share QR code as PNG or SVG (#716)

Dariusz Korytof6253513b342
diff --git a/apps/web/src/components/dialogs/ShareQrCode.test.mjs b/apps/web/src/components/dialogs/ShareQrCode.test.mjs
index 5a9a92ef..6be93745 100644
--- a/apps/web/src/components/dialogs/ShareQrCode.test.mjs
+++ b/apps/web/src/components/dialogs/ShareQrCode.test.mjs
@@ -3,6 +3,7 @@ import { readFileSync } from "node:fs";
import { createElement } from "react";
import { renderToStaticMarkup } from "react-dom/server";
import { QRCodeSVG } from "qrcode.react";
+import { shareQrCodeFileName } from "./ShareQrCode.tsx";
const source = (name) => readFileSync(new URL(`./${name}`, import.meta.url), "utf8");
@@ -37,4 +38,28 @@ describe("share link QR code", () => {
expect(markup).not.toContain("<title");
expect(markup).toContain("<path");
});
+
+ test("offers PNG and SVG downloads of a print-size code with a quiet zone", () => {
+ const component = source("ShareQrCode.tsx");
+ expect(component).toContain('t("sharing.qrCodeDownloadPng")');
+ expect(component).toContain('t("sharing.qrCodeDownloadSvg")');
+ expect(component).toContain("marginSize={QR_DOWNLOAD_MARGIN}");
+
+ const markup = renderToStaticMarkup(createElement(QRCodeSVG, {
+ value: "https://notes.example/share/abc",
+ size: 1024,
+ level: "M",
+ marginSize: 4,
+ xmlns: "http://www.w3.org/2000/svg",
+ }));
+ expect(markup).toContain('xmlns="http://www.w3.org/2000/svg"');
+ expect(markup).toContain('width="1024"');
+ });
+
+ test("names the downloaded file after the share address", () => {
+ expect(shareQrCodeFileName("https://notes.example/share/meeting-notes", "png")).toBe("edgeever-share-qr-meeting-notes.png");
+ expect(shareQrCodeFileName("https://notes.example/share/notebook/abc_DEF-1", "svg")).toBe("edgeever-share-qr-abc_DEF-1.svg");
+ expect(shareQrCodeFileName("https://notes.example/s/%3Cx%3E", "png")).toBe("edgeever-share-qr-3Cx3E.png");
+ expect(shareQrCodeFileName("not a url", "png")).toBe("edgeever-share-qr.png");
+ });
});
diff --git a/apps/web/src/components/dialogs/ShareQrCode.tsx b/apps/web/src/components/dialogs/ShareQrCode.tsx
index 66a19ffa..41aafb2e 100644
--- a/apps/web/src/components/dialogs/ShareQrCode.tsx
+++ b/apps/web/src/components/dialogs/ShareQrCode.tsx
@@ -1,8 +1,26 @@
-import { ChevronDown, QrCode } from "lucide-react";
-import { QRCodeSVG } from "qrcode.react";
+import { ChevronDown, Download, QrCode } from "lucide-react";
+import { QRCodeCanvas, QRCodeSVG } from "qrcode.react";
+import { useRef } from "react";
import { useTranslation } from "react-i18next";
import { Button } from "@/components/ui/button";
import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "@/components/ui/collapsible";
+import { canvasToPngBlob, downloadBlob } from "@/lib/infographic-image-export";
+
+// Large enough for print, with the standard four-module quiet zone around it.
+const QR_DOWNLOAD_SIZE = 1024;
+const QR_DOWNLOAD_MARGIN = 4;
+
+/** File name from the last path segment of the link: the custom address or the token. */
+export const shareQrCodeFileName = (url: string, extension: "png" | "svg") => {
+ let segment = "";
+ try {
+ segment = new URL(url).pathname.split("/").filter(Boolean).at(-1) ?? "";
+ } catch {
+ // Keep the generic name for a value that is not a URL.
+ }
+ const safe = segment.replace(/[^A-Za-z0-9_-]/g, "").slice(0, 48);
+ return `edgeever-share-qr${safe ? `-${safe}` : ""}.${extension}`;
+};
/**
* Scannable share link for opening a share on another device. Callers render it
@@ -10,6 +28,19 @@ import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "@/component
*/
export const ShareQrCode = ({ url, hint }: { url: string; hint: string }) => {
const { t } = useTranslation();
+ const canvasRef = useRef<HTMLCanvasElement>(null);
+ const svgRef = useRef<SVGSVGElement>(null);
+
+ const downloadPng = async () => {
+ if (!canvasRef.current) return;
+ downloadBlob(await canvasToPngBlob(canvasRef.current), shareQrCodeFileName(url, "png"));
+ };
+
+ const downloadSvg = () => {
+ if (!svgRef.current) return;
+ const markup = new XMLSerializer().serializeToString(svgRef.current);
+ downloadBlob(new Blob([markup], { type: "image/svg+xml;charset=utf-8" }), shareQrCodeFileName(url, "svg"));
+ };
return (
<Collapsible>
@@ -36,6 +67,38 @@ export const ShareQrCode = ({ url, hint }: { url: string; hint: string }) => {
/>
</div>
<figcaption className="text-center text-xs leading-5 text-muted-foreground">{hint}</figcaption>
+ <div className="flex flex-wrap justify-center gap-2">
+ <Button variant="outline" size="sm" onClick={() => void downloadPng()}>
+ <Download className="h-3.5 w-3.5" aria-hidden="true" />
+ {t("sharing.qrCodeDownloadPng")}
+ </Button>
+ <Button variant="outline" size="sm" onClick={downloadSvg}>
+ <Download className="h-3.5 w-3.5" aria-hidden="true" />
+ {t("sharing.qrCodeDownloadSvg")}
+ </Button>
+ </div>
+ {/* Download sources: the same code at print size with a quiet zone. */}
+ <div hidden aria-hidden="true">
+ <QRCodeCanvas
+ ref={canvasRef}
+ value={url}
+ size={QR_DOWNLOAD_SIZE}
+ level="M"
+ marginSize={QR_DOWNLOAD_MARGIN}
+ bgColor="#ffffff"
+ fgColor="#000000"
+ />
+ <QRCodeSVG
+ ref={svgRef}
+ value={url}
+ size={QR_DOWNLOAD_SIZE}
+ level="M"
+ marginSize={QR_DOWNLOAD_MARGIN}
+ bgColor="#ffffff"
+ fgColor="#000000"
+ xmlns="http://www.w3.org/2000/svg"
+ />
+ </div>
</figure>
</CollapsibleContent>
</Collapsible>
diff --git a/packages/shared/src/i18n/en-US.ts b/packages/shared/src/i18n/en-US.ts
index 7717f393..6a5acb42 100644
--- a/packages/shared/src/i18n/en-US.ts
+++ b/packages/shared/src/i18n/en-US.ts
@@ -2876,6 +2876,8 @@ export const enUS = {
qrCodeLabel: "QR code for the share link",
qrCodeHint: "Scan with a phone camera to open this note.",
qrCodeNotebookHint: "Scan with a phone camera to open this notebook.",
+ qrCodeDownloadPng: "Download PNG",
+ qrCodeDownloadSvg: "Download SVG",
contentLabel: "Shared note content",
siteHideContents: "Hide contents",
siteShowContents: "Show contents",
diff --git a/packages/shared/src/i18n/ja.ts b/packages/shared/src/i18n/ja.ts
index 602ae26e..d8fc535a 100644
--- a/packages/shared/src/i18n/ja.ts
+++ b/packages/shared/src/i18n/ja.ts
@@ -2865,6 +2865,8 @@ export const ja = {
qrCodeLabel: "共有リンクの QR コード",
qrCodeHint: "スマートフォンのカメラで読み取ると、このノートを開けます。",
qrCodeNotebookHint: "スマートフォンのカメラで読み取ると、このノートブックを開けます。",
+ qrCodeDownloadPng: "PNG をダウンロード",
+ qrCodeDownloadSvg: "SVG をダウンロード",
contentLabel: "共有されたノートの内容",
siteHideContents: "目次を隠す",
siteShowContents: "目次を表示",
diff --git a/packages/shared/src/i18n/pl.ts b/packages/shared/src/i18n/pl.ts
index cfc8d17d..7b5a27b9 100644
--- a/packages/shared/src/i18n/pl.ts
+++ b/packages/shared/src/i18n/pl.ts
@@ -2865,6 +2865,8 @@ export const pl = {
qrCodeLabel: "Kod QR linku udostępniania",
qrCodeHint: "Zeskanuj aparatem telefonu, aby otworzyć tę notatkę.",
qrCodeNotebookHint: "Zeskanuj aparatem telefonu, aby otworzyć ten notes.",
+ qrCodeDownloadPng: "Pobierz PNG",
+ qrCodeDownloadSvg: "Pobierz SVG",
contentLabel: "Treść udostępnionej notatki",
siteHideContents: "Ukryj spis treści",
siteShowContents: "Pokaż spis treści",
diff --git a/packages/shared/src/i18n/ru.ts b/packages/shared/src/i18n/ru.ts
index 958e204a..f7f1b909 100644
--- a/packages/shared/src/i18n/ru.ts
+++ b/packages/shared/src/i18n/ru.ts
@@ -2876,6 +2876,8 @@ export const ru = {
qrCodeLabel: "QR-код ссылки доступа",
qrCodeHint: "Наведите камеру телефона, чтобы открыть эту заметку.",
qrCodeNotebookHint: "Наведите камеру телефона, чтобы открыть этот блокнот.",
+ qrCodeDownloadPng: "Скачать PNG",
+ qrCodeDownloadSvg: "Скачать SVG",
contentLabel: "Содержимое общей заметки",
siteHideContents: "Скрыть оглавление",
siteShowContents: "Показать оглавление",
diff --git a/packages/shared/src/i18n/zh-CN.ts b/packages/shared/src/i18n/zh-CN.ts
index df553138..6f544cea 100644
--- a/packages/shared/src/i18n/zh-CN.ts
+++ b/packages/shared/src/i18n/zh-CN.ts
@@ -2874,6 +2874,8 @@ export const zhCN = {
qrCodeLabel: "分享链接二维码",
qrCodeHint: "用手机相机扫码即可打开这篇笔记。",
qrCodeNotebookHint: "用手机相机扫码即可打开这个笔记本。",
+ qrCodeDownloadPng: "下载 PNG",
+ qrCodeDownloadSvg: "下载 SVG",
contentLabel: "分享的笔记内容",
siteHideContents: "收起目录",
siteShowContents: "展开目录",