Parcourir la source

reset box-sizing before computing image size

Gildas il y a 7 ans
Parent
commit
2d6b8a5f4e
1 fichiers modifiés avec 8 ajouts et 0 suppressions
  1. 8 0
      lib/single-file/doc-helper.js

+ 8 - 0
lib/single-file/doc-helper.js

@@ -266,6 +266,9 @@ this.docHelper = this.docHelper || (() => {
 	}
 
 	function getSize(imageElement) {
+		const boxSizing = imageElement.style.getPropertyValue("box-sizing");
+		const boxSizingImportant = imageElement.style.getPropertyPriority("box-sizing");
+		imageElement.style.setProperty("box-sizing", "border-box", "important");
 		const computedStyle = getComputedStyle(imageElement);
 		const paddingLeft = getWidth("padding-left", computedStyle);
 		const paddingRight = getWidth("padding-right", computedStyle);
@@ -273,6 +276,11 @@ this.docHelper = this.docHelper || (() => {
 		const paddingBottom = getWidth("padding-bottom", computedStyle);
 		const width = imageElement.clientWidth;
 		const height = imageElement.clientHeight;
+		if (boxSizing) {
+			imageElement.style.setProperty("box-sizing", boxSizing, boxSizingImportant);
+		} else {
+			imageElement.style.removeProperty("box-sizing");
+		}
 		if (width >= 0 && height >= 0 && paddingLeft >= 0 && paddingRight >= 0 && paddingTop >= 0 && paddingBottom >= 0) {
 			return {
 				width: (paddingLeft || paddingRight) && (width - paddingLeft - paddingRight) + "px",