From a94fed5ce75a327f6d707d95fb79db7de0909270 Mon Sep 17 00:00:00 2001 From: Emmanuel Ogbizi-Ugbe Date: Sun, 22 Dec 2024 15:11:21 -0500 Subject: [PATCH] fix(export-element): preserve node sizing --- scripts/export-element/index.user.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/scripts/export-element/index.user.ts b/scripts/export-element/index.user.ts index a4187cfd..e6a18336 100644 --- a/scripts/export-element/index.user.ts +++ b/scripts/export-element/index.user.ts @@ -213,18 +213,27 @@ import { html2canvas } from "libraries/html2canvas"; async function cloneAndDownloadImage(node: Node) { const clone = cloneNodeWithStyles(window, node); const backgroundColor = findBackgroundColor(node); + const nodeSize = ( + findLastNodeWithPredicate( + node, + (element) => element instanceof Element, + ) as Element + )?.getBoundingClientRect() ?? { + height: "fit-content", + width: "fit-content", + }; const modalContent = document.createElement("a"); modalContent.style.backgroundColor = backgroundColor; modalContent.style.cursor = "pointer"; modalContent.style.display = "block"; - modalContent.style.height = "fit-content"; + modalContent.style.height = nodeSize.height.toString(); modalContent.style.padding = "min(1vh, 1vw)"; modalContent.style.position = "relative"; modalContent.style.textDecoration = "none"; modalContent.style.top = "1vh"; modalContent.style.userSelect = "none"; - modalContent.style.width = "fit-content"; + modalContent.style.width = nodeSize.width.toString(); const modalWrapper = document.createElement("div"); modalWrapper.style.alignItems = "start";