Explorar el Código

re-use computed styles when available

Gildas hace 6 años
padre
commit
f6f405147e
Se han modificado 1 ficheros con 4 adiciones y 4 borrados
  1. 4 4
      lib/single-file/single-file-helper.js

+ 4 - 4
lib/single-file/single-file-helper.js

@@ -149,7 +149,7 @@ this.singlefile.lib.helper = this.singlefile.lib.helper || (() => {
 	function getResourcesInfo(win, doc, element, options, data, elementHidden, computedStyle) {
 		if (element.tagName == "CANVAS") {
 			try {
-				const size = getSize(win, element);
+				const size = getSize(win, element, computedStyle);
 				data.canvasData.push({ dataURI: element.toDataURL("image/png", ""), width: size.width, height: size.height });
 				element.setAttribute(CANVAS_ATTRIBUTE_NAME, data.canvasData.length - 1);
 			} catch (error) {
@@ -166,7 +166,7 @@ this.singlefile.lib.helper = this.singlefile.lib.helper || (() => {
 			element.removeAttribute(LAZY_SRC_ATTRIBUTE_NAME);
 			computedStyle = computedStyle || win.getComputedStyle(element);
 			if (computedStyle) {
-				imageData.size = getSize(win, element);
+				imageData.size = getSize(win, element, computedStyle);
 				const boxShadow = computedStyle.getPropertyValue("box-shadow");
 				const backgroundImage = computedStyle.getPropertyValue("background-image");
 				if ((!boxShadow || boxShadow == "none") &&
@@ -282,11 +282,11 @@ this.singlefile.lib.helper = this.singlefile.lib.helper || (() => {
 		}
 	}
 
-	function getSize(win, imageElement) {
+	function getSize(win, imageElement, computedStyle) {
 		let pxWidth = imageElement.naturalWidth;
 		let pxHeight = imageElement.naturalHeight;
 		if (!pxWidth && !pxHeight) {
-			const computedStyle = win.getComputedStyle(imageElement);
+			computedStyle = computedStyle || win.getComputedStyle(imageElement);
 			let removeBorderWidth = false;
 			if (computedStyle.getPropertyValue("box-sizing") == "content-box") {
 				const boxSizingValue = imageElement.style.getPropertyValue("box-sizing");