From f7dcc893ea0f2d1061db614d3c2c7b43e256e7bc Mon Sep 17 00:00:00 2001 From: zsviczian Date: Wed, 14 May 2025 13:38:18 +0200 Subject: [PATCH] feat: transparent link background, scale link icon when zooming to below 100% (#9520) * Do not set link background color, dynamically scale down link icon size with zoom. * removed unnecessary change * use canvas bg color & reduce size and stroke width --------- Co-authored-by: dwelle <5153846+dwelle@users.noreply.github.com> --- packages/element/src/renderElement.ts | 2 -- .../excalidraw/components/hyperlink/helpers.ts | 17 +++++++++-------- packages/excalidraw/renderer/staticScene.ts | 2 +- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/packages/element/src/renderElement.ts b/packages/element/src/renderElement.ts index c8091e8ed..e749bd90c 100644 --- a/packages/element/src/renderElement.ts +++ b/packages/element/src/renderElement.ts @@ -349,8 +349,6 @@ const generateElementCanvas = ( }; }; -export const DEFAULT_LINK_SIZE = 14; - const IMAGE_PLACEHOLDER_IMG = document.createElement("img"); IMAGE_PLACEHOLDER_IMG.src = `data:${MIME_TYPES.svg},${encodeURIComponent( ``, diff --git a/packages/excalidraw/components/hyperlink/helpers.ts b/packages/excalidraw/components/hyperlink/helpers.ts index bdabbfc44..7d39b7ff7 100644 --- a/packages/excalidraw/components/hyperlink/helpers.ts +++ b/packages/excalidraw/components/hyperlink/helpers.ts @@ -4,8 +4,6 @@ import { MIME_TYPES } from "@excalidraw/common"; import { getElementAbsoluteCoords } from "@excalidraw/element"; import { hitElementBoundingBox } from "@excalidraw/element"; -import { DEFAULT_LINK_SIZE } from "@excalidraw/element"; - import type { GlobalPoint, Radians } from "@excalidraw/math"; import type { Bounds } from "@excalidraw/element"; @@ -16,9 +14,11 @@ import type { import type { AppState, UIAppState } from "../../types"; +export const DEFAULT_LINK_SIZE = 12; + export const EXTERNAL_LINK_IMG = document.createElement("img"); EXTERNAL_LINK_IMG.src = `data:${MIME_TYPES.svg}, ${encodeURIComponent( - ``, + ``, )}`; export const ELEMENT_LINK_IMG = document.createElement("img"); @@ -32,13 +32,14 @@ export const getLinkHandleFromCoords = ( appState: Pick, ): Bounds => { const size = DEFAULT_LINK_SIZE; - const linkWidth = size / appState.zoom.value; - const linkHeight = size / appState.zoom.value; - const linkMarginY = size / appState.zoom.value; + const zoom = appState.zoom.value > 1 ? appState.zoom.value : 1; + const linkWidth = size / zoom; + const linkHeight = size / zoom; + const linkMarginY = size / zoom; const centerX = (x1 + x2) / 2; const centerY = (y1 + y2) / 2; - const centeringOffset = (size - 8) / (2 * appState.zoom.value); - const dashedLineMargin = 4 / appState.zoom.value; + const centeringOffset = (size - 8) / (2 * zoom); + const dashedLineMargin = 4 / zoom; // Same as `ne` resize handle const x = x2 + dashedLineMargin - centeringOffset; diff --git a/packages/excalidraw/renderer/staticScene.ts b/packages/excalidraw/renderer/staticScene.ts index d63779464..18cf0092d 100644 --- a/packages/excalidraw/renderer/staticScene.ts +++ b/packages/excalidraw/renderer/staticScene.ts @@ -188,7 +188,7 @@ const renderLinkIcon = ( window.devicePixelRatio * appState.zoom.value, window.devicePixelRatio * appState.zoom.value, ); - linkCanvasCacheContext.fillStyle = "#fff"; + linkCanvasCacheContext.fillStyle = appState.viewBackgroundColor || "#fff"; linkCanvasCacheContext.fillRect(0, 0, width, height); if (canvasKey === "elementLink") {