feat(snapdom): update screenshot generation options for SVG and PNG exports

This commit is contained in:
lzinga 2025-12-04 12:52:01 -08:00
parent 4b8c8888ee
commit 2666c1e196
2 changed files with 12 additions and 8 deletions

View File

@ -684,7 +684,10 @@ async function downloadAsSvg(nameWithoutExtension: string, svgSource: string | S
const { element, cleanup } = prepareElementForSnapdom(svgSource);
try {
const result = await snapdom(element);
const result = await snapdom(element, {
backgroundColor: "transparent",
scale: 2
});
await triggerDownload(`${nameWithoutExtension}.svg`, result.url);
} finally {
cleanup();
@ -719,7 +722,10 @@ async function downloadAsPng(nameWithoutExtension: string, svgSource: string | S
const { element, cleanup } = prepareElementForSnapdom(svgSource);
try {
const result = await snapdom(element);
const result = await snapdom(element, {
backgroundColor: "transparent",
scale: 2
});
const pngImg = await result.toPng();
await triggerDownload(`${nameWithoutExtension}.png`, pngImg.src);
} finally {

View File

@ -47,11 +47,6 @@ export default function MindMap({ note, ntxId, noteContext }: TypeWidgetProps) {
const containerRef = useRef<HTMLDivElement>(null);
const [ isReadOnly ] = useNoteLabelBoolean(note, "readOnly");
// Shared options for snapdom screenshot generation used in both attachment saving and exports
const imageOptions : SnapdomOptions = {
backgroundColor: "transparent",
scale: 2
};
const spacedUpdate = useEditorSpacedUpdate({
note,
@ -59,7 +54,10 @@ export default function MindMap({ note, ntxId, noteContext }: TypeWidgetProps) {
getData: async () => {
if (!apiRef.current) return;
const result = await snapdom(apiRef.current.nodes, imageOptions);
const result = await snapdom(apiRef.current.nodes, {
backgroundColor: "transparent",
scale: 2
});
// a data URL in the format: "data:image/svg+xml;charset=utf-8,<url-encoded-svg>"
// We need to extract the content after the comma and decode the URL encoding (%3C to <, %20 to space, etc.)