svg-exportJS icon indicating copy to clipboard operation
svg-exportJS copied to clipboard

bug: read viewbox correctly when it is defined with commas

Open serman opened this issue 1 year ago • 0 comments

Hello! Thanks for your module.

According to the view box definition https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/viewBox , the numbers could be separated with commas or spaces.

I was importing a d3 generated svg with viewBox="0,0,468,200" and the exported output was viewBox="0,0,468,200 undefined 354 200"

Because the split function is only taking into account using spaces as dividers

 _options.originalMinXViewBox = svgElement.getAttribute("viewBox") ? svgElement.getAttribute("viewBox").split(/\s/)[0] : 0;
        _options.originalMinYViewBox = svgElement.getAttribute("viewBox") ? svgElement.getAttribute("viewBox").split(/\s/)[1] : 0;

With this change, it works for me with commas, spaces or both.

serman avatar Feb 10 '25 16:02 serman