Sfoglia il codice sorgente

check if changing box-sizing value has any effect

Gildas 7 anni fa
parent
commit
68160c3c61
1 ha cambiato i file con 16 aggiunte e 1 eliminazioni
  1. 16 1
      lib/single-file/util/doc-helper.js

+ 16 - 1
lib/single-file/util/doc-helper.js

@@ -305,12 +305,27 @@ this.docHelper = this.docHelper || (() => {
 
 
 	function getSize(win, imageElement) {
 	function getSize(win, imageElement) {
 		const computedStyle = win.getComputedStyle(imageElement);
 		const computedStyle = win.getComputedStyle(imageElement);
+		let boxSizingEffective = false;
+		const boxSizingValue = imageElement.style.getPropertyValue("box-sizing");
+		const boxSizingPriority = imageElement.style.getPropertyPriority("box-sizing");
+		const clientWidth = imageElement.clientWidth;
+		if (computedStyle.getPropertyValue("box-sizing") == "content-box") {
+			imageElement.style.setProperty("box-sizing", "border-box", "important");
+		} else {
+			imageElement.style.setProperty("box-sizing", "content-box", "important");
+		}
+		boxSizingEffective = imageElement.clientWidth != clientWidth;
+		if (boxSizingValue) {
+			imageElement.style.setProperty("box-sizing", boxSizingValue, boxSizingPriority);
+		} else {
+			imageElement.style.removeProperty("box-sizing");
+		}
 		let paddingLeft, paddingRight, paddingTop, paddingBottom, borderLeft, borderRight, borderTop, borderBottom;
 		let paddingLeft, paddingRight, paddingTop, paddingBottom, borderLeft, borderRight, borderTop, borderBottom;
 		paddingLeft = getWidth("padding-left", computedStyle);
 		paddingLeft = getWidth("padding-left", computedStyle);
 		paddingRight = getWidth("padding-right", computedStyle);
 		paddingRight = getWidth("padding-right", computedStyle);
 		paddingTop = getWidth("padding-top", computedStyle);
 		paddingTop = getWidth("padding-top", computedStyle);
 		paddingBottom = getWidth("padding-bottom", computedStyle);
 		paddingBottom = getWidth("padding-bottom", computedStyle);
-		if (computedStyle.getPropertyValue("box-sizing") == "content-box") {
+		if (boxSizingEffective && computedStyle.getPropertyValue("box-sizing") == "content-box") {
 			borderLeft = getWidth("border-left-width", computedStyle);
 			borderLeft = getWidth("border-left-width", computedStyle);
 			borderRight = getWidth("border-right-width", computedStyle);
 			borderRight = getWidth("border-right-width", computedStyle);
 			borderTop = getWidth("border-top-width", computedStyle);
 			borderTop = getWidth("border-top-width", computedStyle);