π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
fix(paste):update-styling
Aswin Asok3dce72ec2109
diff --git a/web/apps/paste/src/features/paste/components/PasteCreatePanel.tsx b/web/apps/paste/src/features/paste/components/PasteCreatePanel.tsxindex 95db060e94..9efcd647e9 100644--- a/web/apps/paste/src/features/paste/components/PasteCreatePanel.tsx+++ b/web/apps/paste/src/features/paste/components/PasteCreatePanel.tsx@@ -24,6 +24,7 @@ import type { FormEvent } from "react";import { useState } from "react";import { MAX_PASTE_CHARS } from "../constants";import { PasteLinkCard } from "./PasteLinkCard";+import { downloadPasteQrCode } from "./PasteQrCode";import { pasteTextFieldSx } from "./textFieldSx";interface PasteCreatePanelProps {@@ -203,6 +204,17 @@ export const PasteCreatePanel = ({void onCreate(submittedPassword);};+ const handleDownloadQrClick = () => {+ if (!createdLink) return;++ void downloadPasteQrCode({+ value: createdLink,+ tokens,+ paperBg: tokens.qr.paperBg,+ showCenterLock: createdLinkPasswordProtected,+ }).catch(() => undefined);+ };+return (<Box sx={{ width: "100%", maxWidth: "100%", minWidth: 0 }}><Box@@ -498,23 +510,50 @@ export const PasteCreatePanel = ({link={createdLink}onCopy={onCopyLink}onShare={onShareLink}+ passwordProtected={createdLinkPasswordProtected}/>- {createdLinkPasswordProtected && (+ <Box+ sx={{+ mt: 0.85,+ display: "flex",+ justifyContent: "flex-start",+ }}+ ><Typography+ component="button"+ type="button"variant="mini"+ onClick={handleDownloadQrClick}sx={{- mt: 0.85,+ appearance: "none",+ border: 0,+ p: 0,+ m: 0,+ bgcolor: "transparent",color: tokens.text.muted,+ cursor: "pointer",fontSize: { xs: "0.68rem", sm: "0.72rem" },- fontWeight: 500,+ fontWeight: 600,lineHeight: 1.3,letterSpacing: 0,- opacity: 0.58,+ opacity: 0.6,+ textDecoration: "underline",+ textUnderlineOffset: "3px",+ "&:hover": {+ color: tokens.text.muted,+ opacity: 0.72,+ textDecoration: "underline",+ },+ "&:focus-visible": {+ outline: `2px solid ${tokens.button.primaryBg}`,+ outlineOffset: 3,+ borderRadius: "4px",+ },}}>- This paste is password protected+ Download QR</Typography>- )}+ </Box></Box>)}diff --git a/web/apps/paste/src/features/paste/components/PasteLinkCard.tsx b/web/apps/paste/src/features/paste/components/PasteLinkCard.tsxindex 7d79eba4b2..6df715dbea 100644--- a/web/apps/paste/src/features/paste/components/PasteLinkCard.tsx+++ b/web/apps/paste/src/features/paste/components/PasteLinkCard.tsx@@ -24,6 +24,7 @@ interface PasteLinkCardProps {link: string;onCopy: (value: string) => Promise<void>;onShare: (url: string) => Promise<void>;+ passwordProtected?: boolean;}interface MeasuredPath {@@ -36,6 +37,7 @@ export const PasteLinkCard = ({link,onCopy,onShare,+ passwordProtected = false,}: PasteLinkCardProps) => {const { resolvedMode } = usePasteColorMode();const tokens = getPasteThemeTokens(resolvedMode);@@ -241,10 +243,10 @@ export const PasteLinkCard = ({sm: '"qr details" "qr actions"',},alignItems: "center",- rowGap: { xs: 1.45, sm: 1.35 },+ rowGap: { xs: 1.3, sm: 1 },columnGap: { xs: 1.4, sm: 1.8 },px: { xs: 1.45, sm: 1.8 },- py: { xs: 2.1, sm: 1.35 },+ py: { xs: 1.6, sm: 1.95 },mx: "auto",position: "relative",zIndex: 1,@@ -279,6 +281,7 @@ export const PasteLinkCard = ({size={previewQrSize}paperBg={tokens.qr.paperBg}borderRadius="10px"+ showCenterLock={passwordProtected}/></Box>@@ -292,7 +295,7 @@ export const PasteLinkCard = ({alignSelf: "stretch",justifyContent: "center",pr: { xs: 0, sm: 0.55 },- transform: { xs: "none", sm: "translateY(14px)" },+ transform: { xs: "none", sm: "translateY(8px)" },}}><Typography@@ -395,7 +398,7 @@ export const PasteLinkCard = ({sx={{gridArea: "actions",position: "relative",- minHeight: { xs: previewQrSize, sm: 82 },+ minHeight: { xs: previewQrSize, sm: 64 },mt: { xs: 0, sm: 0.65 },width: "100%",maxWidth: "100%",@@ -403,7 +406,7 @@ export const PasteLinkCard = ({alignItems: { xs: "center", sm: "stretch" },justifyContent: { xs: "center", sm: "flex-start" },overflow: "visible",- transform: { xs: "none", sm: "translateY(14px)" },+ transform: { xs: "none", sm: "translateY(8px)" },}}><Stackdiff --git a/web/apps/paste/src/features/paste/components/PasteQrCode.tsx b/web/apps/paste/src/features/paste/components/PasteQrCode.tsxindex 87831627ed..07e2c00dc5 100644--- a/web/apps/paste/src/features/paste/components/PasteQrCode.tsx+++ b/web/apps/paste/src/features/paste/components/PasteQrCode.tsx@@ -13,6 +13,7 @@ interface PasteQrCodeProps {size?: number;paperBg?: string;borderRadius?: string;+ showCenterLock?: boolean;/** When set, shows a floating close control (e.g. to dismiss the QR panel). */onClose?: () => void;/** Color mode for close button hover; pass when `onClose` is used. */@@ -22,6 +23,9 @@ interface PasteQrCodeProps {interface QRCodeStylingInstance {append(container: HTMLElement): void;update(options: Record<string, unknown>): void;+ download(+ options?: { name?: string; extension?: string } | string,+ ): Promise<void>;_qr?: { getModuleCount(): number };}@@ -36,9 +40,16 @@ interface QRCodeStylingModule {type QrErrorCorrectionLevel = "L" | "M" | "Q" | "H";const QR_ERROR_CORRECTION_LEVEL: QrErrorCorrectionLevel = "M";+const QR_LOGO_ERROR_CORRECTION_LEVEL: QrErrorCorrectionLevel = "H";const QUIET_ZONE_MODULES = 4;const QR_LOAD_ERROR_LABEL = "QR unavailable. Refresh to try again.";+const qrCenterLockDataUrl = (paperBg: string, lockColor: string) => {+ const svg = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32"><rect width="32" height="32" rx="5" fill="${paperBg}"/><path fill="${lockColor}" d="M10 14v-2.5C10 8.5 12.5 6 16 6s6 2.5 6 5.5V14h1c1.1 0 2 .9 2 2v8c0 1.1-.9 2-2 2H9c-1.1 0-2-.9-2-2v-8c0-1.1.9-2 2-2h1Zm3 0h6v-2.5C19 10.1 17.9 9 16 9s-3 1.1-3 2.5V14Z"/></svg>`;++ return `data:image/svg+xml,${encodeURIComponent(svg)}`;+};+const isQRCodeStylingModule = (value: unknown,): value is QRCodeStylingModule => {@@ -67,12 +78,85 @@ const getQrRenderMetrics = (qrSize: number, moduleCount: number) => {};};+const getPasteQrCodeOptions = ({+ value,+ qrSize,+ qrPaperBg,+ tokens,+ showCenterLock,+}: {+ value: string;+ qrSize: number;+ qrPaperBg: string;+ tokens: PasteThemeTokens;+ showCenterLock: boolean;+}) => ({+ width: qrSize,+ height: qrSize,+ type: "svg",+ data: value,+ qrOptions: {+ errorCorrectionLevel: showCenterLock+ ? QR_LOGO_ERROR_CORRECTION_LEVEL+ : QR_ERROR_CORRECTION_LEVEL,+ },+ backgroundOptions: { color: qrPaperBg },+ dotsOptions: { color: tokens.qr.module, type: "rounded" },+ cornersSquareOptions: { color: tokens.qr.finder, type: "extra-rounded" },+ cornersDotOptions: { color: tokens.qr.finder, type: "dot" },+ ...(showCenterLock && {+ image: qrCenterLockDataUrl(qrPaperBg, tokens.qr.finder),+ imageOptions: { hideBackgroundDots: true, imageSize: 0.2, margin: 1 },+ }),+});++export const downloadPasteQrCode = async ({+ value,+ tokens,+ paperBg,+ showCenterLock,+}: {+ value: string;+ tokens: PasteThemeTokens;+ paperBg?: string;+ showCenterLock: boolean;+}) => {+ const qrSize = 512;+ const qrPaperBg = paperBg ?? tokens.qr.paperBg;+ const qrCodeStylingModule = (await import("qr-code-styling")) as unknown;++ if (!isQRCodeStylingModule(qrCodeStylingModule)) {+ throw new Error("Failed to load qr-code-styling");+ }++ const { default: QRCodeStyling } = qrCodeStylingModule;+ const qrOptions = getPasteQrCodeOptions({+ value,+ qrSize,+ qrPaperBg,+ tokens,+ showCenterLock,+ });+ const qrCode = new QRCodeStyling(qrOptions);+ const moduleCount = getQrModuleCount(qrCode);++ if (moduleCount !== undefined) {+ qrCode.update({+ ...qrOptions,+ ...getQrRenderMetrics(qrSize, moduleCount),+ });+ }++ await qrCode.download({ name: "ente-paste-qr", extension: "png" });+};+export const PasteQrCode = ({value,tokens,size,paperBg,borderRadius,+ showCenterLock = false,onClose,resolvedMode,}: PasteQrCodeProps) => {@@ -85,21 +169,22 @@ export const PasteQrCode = ({const qrPaperBg = paperBg ?? tokens.qr.paperBg;const qrOptions = useMemo(- () => ({- width: qrSize,- height: qrSize,- type: "svg",- data: value,- qrOptions: { errorCorrectionLevel: QR_ERROR_CORRECTION_LEVEL },- backgroundOptions: { color: qrPaperBg },- dotsOptions: { color: tokens.qr.module, type: "rounded" },- cornersSquareOptions: {- color: tokens.qr.finder,- type: "extra-rounded",- },- cornersDotOptions: { color: tokens.qr.finder, type: "dot" },- }),- [qrSize, tokens.qr.finder, tokens.qr.module, qrPaperBg, value],+ () =>+ getPasteQrCodeOptions({+ value,+ qrSize,+ qrPaperBg,+ tokens,+ showCenterLock,+ }),+ [+ qrSize,+ showCenterLock,+ tokens.qr.finder,+ tokens.qr.module,+ qrPaperBg,+ value,+ ],);useEffect(() => {diff --git a/web/apps/paste/src/types/qr-code-styling.d.ts b/web/apps/paste/src/types/qr-code-styling.d.tsindex e77a393fe2..f618dc82de 100644--- a/web/apps/paste/src/types/qr-code-styling.d.ts+++ b/web/apps/paste/src/types/qr-code-styling.d.ts@@ -5,5 +5,8 @@ declare module "qr-code-styling" {constructor(options?: QRCodeStylingOptions);append(container: HTMLElement): void;update(options?: QRCodeStylingOptions): void;+ download(+ options?: { name?: string; extension?: string } | string,+ ): Promise<void>;}}