Virtual whiteboard for sketching hand-drawn like diagrams
feat: transparent link background, scale link icon when zooming to below 100% (#9520)
zsviczianf7dcc893ea0f
diff --git a/packages/element/src/renderElement.ts b/packages/element/src/renderElement.tsindex c8091e8edb..e749bd90c3 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(`<svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="image" class="svg-inline--fa fa-image fa-w-16" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path fill="#888" d="M464 448H48c-26.51 0-48-21.49-48-48V112c0-26.51 21.49-48 48-48h416c26.51 0 48 21.49 48 48v288c0 26.51-21.49 48-48 48zM112 120c-30.928 0-56 25.072-56 56s25.072 56 56 56 56-25.072 56-56-25.072-56-56-56zM64 384h384V272l-87.515-87.515c-4.686-4.686-12.284-4.686-16.971 0L208 320l-55.515-55.515c-4.686-4.686-12.284-4.686-16.971 0L64 336v48z"></path></svg>`,diff --git a/packages/excalidraw/components/hyperlink/helpers.ts b/packages/excalidraw/components/hyperlink/helpers.tsindex bdabbfc440..7d39b7ff74 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(- `<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="#1971c2" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-external-link"><path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"></path><polyline points="15 3 21 3 21 9"></polyline><line x1="10" y1="14" x2="21" y2="3"></line></svg>`,+ `<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="#1971c2" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round" class="feather feather-external-link"><path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"></path><polyline points="15 3 21 3 21 9"></polyline><line x1="10" y1="14" x2="21" y2="3"></line></svg>`,)}`;export const ELEMENT_LINK_IMG = document.createElement("img");@@ -32,13 +32,14 @@ export const getLinkHandleFromCoords = (appState: Pick<UIAppState, "zoom">,): 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 handleconst x = x2 + dashedLineMargin - centeringOffset;diff --git a/packages/excalidraw/renderer/staticScene.ts b/packages/excalidraw/renderer/staticScene.tsindex d63779464a..18cf0092d0 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") {