From 27d95c8203deb1bfa6a99ab2cf712d7cc2a3c8bd Mon Sep 17 00:00:00 2001 From: Robert Rosman Date: Fri, 31 May 2024 21:47:30 +0200 Subject: [PATCH] fix: add width and height from viewBox if missing --- src/utils/export/exportSvg.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/utils/export/exportSvg.ts b/src/utils/export/exportSvg.ts index 46b5664..4f272b8 100644 --- a/src/utils/export/exportSvg.ts +++ b/src/utils/export/exportSvg.ts @@ -6,6 +6,11 @@ export function exportSvg({ svg, history, tools }: ExportParameters) { // get svg data const clone = unref(svg).cloneNode(true) as SVGElement tools.forEach((tool) => tool.beforeExport?.({ svg: clone, history, tools })) + if ((!clone.hasAttribute('width') || !clone.hasAttribute('height')) && clone.hasAttribute('viewBox')) { + const viewBox = clone.getAttribute('viewBox')!.split(' ') + clone.setAttribute('width', viewBox[2]) + clone.setAttribute('height', viewBox[3]) + } const xml = new XMLSerializer().serializeToString(clone) // make it base64