( svg: SVGSVGElement, padding: ParsedPadding, )
| 68 | } |
| 69 | |
| 70 | export function getBoundViewBox( |
| 71 | svg: SVGSVGElement, |
| 72 | padding: ParsedPadding, |
| 73 | ): string { |
| 74 | const bbox = svg.getBBox(); |
| 75 | const clientRect = svg.getBoundingClientRect(); |
| 76 | const scaleX = clientRect.width > 0 ? bbox.width / clientRect.width : 1; |
| 77 | const scaleY = clientRect.height > 0 ? bbox.height / clientRect.height : 1; |
| 78 | |
| 79 | const [topPx, rightPx, bottomPx, leftPx] = padding; |
| 80 | const topSvg = topPx * scaleY; |
| 81 | const rightSvg = rightPx * scaleX; |
| 82 | const bottomSvg = bottomPx * scaleY; |
| 83 | const leftSvg = leftPx * scaleX; |
| 84 | |
| 85 | const newX = bbox.x - leftSvg; |
| 86 | const newY = bbox.y - topSvg; |
| 87 | const newWidth = bbox.width + leftSvg + rightSvg; |
| 88 | const newHeight = bbox.height + topSvg + bottomSvg; |
| 89 | |
| 90 | return `${newX} ${newY} ${newWidth} ${newHeight}`; |
| 91 | } |
| 92 | |
| 93 | function setSVGPaddingInBrowser(svg: SVGSVGElement, padding: ParsedPadding) { |
| 94 | const viewBox = getBoundViewBox(svg, padding); |
no outgoing calls
no test coverage detected