Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
feat(snapdom): update screenshot generation options for SVG and PNG exports
lzinga2666c1e196c2
diff --git a/apps/client/src/services/utils.ts b/apps/client/src/services/utils.tsindex 3a75b90d69..7e064d25f7 100644--- a/apps/client/src/services/utils.ts+++ b/apps/client/src/services/utils.ts@@ -684,7 +684,10 @@ async function downloadAsSvg(nameWithoutExtension: string, svgSource: string | Sconst { 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 | Sconst { 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 {diff --git a/apps/client/src/widgets/type_widgets/MindMap.tsx b/apps/client/src/widgets/type_widgets/MindMap.tsxindex 3741d8fbf6..db46da0257 100644--- a/apps/client/src/widgets/type_widgets/MindMap.tsx+++ b/apps/client/src/widgets/type_widgets/MindMap.tsx@@ -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.)