fix(NodeContainer) : fix issue with responsive SVG for image generation.

This commit is contained in:
hocine BENKHADRA 2021-03-27 08:35:07 +01:00
parent 0f01810005
commit 8350c1df85

View File

@ -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))}`