mirror of
https://github.com/niklasvh/html2canvas.git
synced 2023-08-10 21:13:10 +03:00
fix(NodeContainer) : fix issue with responsive SVG for image generation.
This commit is contained in:
parent
0f01810005
commit
8350c1df85
@ -273,6 +273,23 @@ const getImage = (node: HTMLElement | SVGSVGElement, resourceLoader: ResourceLoa
|
||||
node instanceof node.ownerDocument.defaultView.SVGSVGElement ||
|
||||
node instanceof SVGSVGElement
|
||||
) {
|
||||
const percentValueTest: RegExp = /^[0-9]{1,3}\%$/i;
|
||||
if (
|
||||
percentValueTest.test(node.getAttribute('width')) ||
|
||||
percentValueTest.test(node.getAttribute('height')) ||
|
||||
percentValueTest.test(node.style.width) ||
|
||||
percentValueTest.test(node.style.height)
|
||||
) {
|
||||
if (!node.clientWidth && !node.clientHeight && node.parentNode) {
|
||||
const parentStyle = window.getComputedStyle(node.parentNode);
|
||||
node.setAttribute('width', parentStyle.width);
|
||||
node.setAttribute('height', parentStyle.height);
|
||||
} else {
|
||||
node.setAttribute('width', node.clientWidth);
|
||||
node.setAttribute('height', node.clientHeight);
|
||||
}
|
||||
}
|
||||
|
||||
const s = new XMLSerializer();
|
||||
return resourceLoader.loadImage(
|
||||
`data:image/svg+xml,${encodeURIComponent(s.serializeToString(node))}`
|
||||
|
Loading…
x
Reference in New Issue
Block a user