|
|
@ -105,20 +105,40 @@ export const normalizeSVG = (SVGString: string) => {
|
|
|
|
svg.setAttribute("xmlns", SVG_NS);
|
|
|
|
svg.setAttribute("xmlns", SVG_NS);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!svg.hasAttribute("width") || !svg.hasAttribute("height")) {
|
|
|
|
let width = svg.getAttribute("width");
|
|
|
|
|
|
|
|
let height = svg.getAttribute("height");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Do not use % or auto values for width/height
|
|
|
|
|
|
|
|
// to avoid scaling issues when rendering at different sizes/zoom levels
|
|
|
|
|
|
|
|
if (width?.includes("%") || width === "auto") {
|
|
|
|
|
|
|
|
width = null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (height?.includes("%") || height === "auto") {
|
|
|
|
|
|
|
|
height = null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const viewBox = svg.getAttribute("viewBox");
|
|
|
|
const viewBox = svg.getAttribute("viewBox");
|
|
|
|
let width = svg.getAttribute("width") || "50";
|
|
|
|
|
|
|
|
let height = svg.getAttribute("height") || "50";
|
|
|
|
if (!width || !height) {
|
|
|
|
|
|
|
|
width = width || "50";
|
|
|
|
|
|
|
|
height = height || "50";
|
|
|
|
|
|
|
|
|
|
|
|
if (viewBox) {
|
|
|
|
if (viewBox) {
|
|
|
|
const match = viewBox.match(/\d+ +\d+ +(\d+) +(\d+)/);
|
|
|
|
const match = viewBox.match(/\d+ +\d+ +(\d+) +(\d+)/);
|
|
|
|
if (match) {
|
|
|
|
if (match) {
|
|
|
|
[, width, height] = match;
|
|
|
|
[, width, height] = match;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
svg.setAttribute("width", width);
|
|
|
|
svg.setAttribute("width", width);
|
|
|
|
svg.setAttribute("height", height);
|
|
|
|
svg.setAttribute("height", height);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Make sure viewBox is set
|
|
|
|
|
|
|
|
if (!viewBox) {
|
|
|
|
|
|
|
|
svg.setAttribute("viewBox", `0 0 ${width} ${height}`);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return svg.outerHTML;
|
|
|
|
return svg.outerHTML;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|