Răsfoiți Sursa

refactored testHiddenElement

Gildas 6 ani în urmă
părinte
comite
b99ceb9055
1 a modificat fișierele cu 8 adăugiri și 8 ștergeri
  1. 8 8
      lib/single-file/util/doc-helper.js

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

@@ -107,9 +107,6 @@ this.docHelper = this.docHelper || (() => {
 			if (options.removeHiddenElements || options.removeUnusedFonts || options.compressHTML) {
 				const computedStyle = win.getComputedStyle(element);
 				if (options.removeHiddenElements) {
-					const display = computedStyle.getPropertyValue("display");
-					const opacity = computedStyle.getPropertyValue("opacity");
-					const visibility = computedStyle.getPropertyValue("visibility");
 					if (ascendantHidden) {
 						Array.from(element.childNodes).filter(node => node instanceof win.HTMLElement).forEach(element => {
 							if (!options.ignoredTags.includes(element.tagName)) {
@@ -117,7 +114,7 @@ this.docHelper = this.docHelper || (() => {
 							}
 						});
 					}
-					elementHidden = ascendantHidden || testHiddenElement(element, { display, opacity, visibility });
+					elementHidden = ascendantHidden || testHiddenElement(element, computedStyle);
 				}
 				if (options.compressHTML) {
 					const whiteSpace = computedStyle.getPropertyValue("white-space");
@@ -219,11 +216,14 @@ this.docHelper = this.docHelper || (() => {
 		return removeQuotes(fontFamilyName.trim()).toLowerCase();
 	}
 
-	function testHiddenElement(element, style) {
+	function testHiddenElement(element, computedStyle) {
 		let hidden = false;
-		if (style) {
-			hidden = style.display == "none";
-			if (!hidden && (style.opacity == "0" || style.visibility == "hidden") && element.getBoundingClientRect) {
+		if (computedStyle) {
+			const display = computedStyle.getPropertyValue("display");
+			const opacity = computedStyle.getPropertyValue("opacity");
+			const visibility = computedStyle.getPropertyValue("visibility");
+			hidden = display == "none";
+			if (!hidden && (opacity == "0" || visibility == "hidden") && element.getBoundingClientRect) {
 				const boundingRect = element.getBoundingClientRect();
 				hidden = !boundingRect.width && !boundingRect.height;
 			}