Skip to content

Commit

Permalink
fix(export-element): preserve node sizing
Browse files Browse the repository at this point in the history
  • Loading branch information
iamogbz committed Dec 22, 2024
1 parent afa2442 commit a94fed5
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions scripts/export-element/index.user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down

0 comments on commit a94fed5

Please sign in to comment.