Răsfoiți Sursa

fixed removing of unused styles

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

+ 5 - 5
lib/single-file/doc-helper.js

@@ -67,7 +67,7 @@ this.docHelper = this.docHelper || (() => {
 			canvasData = getCanvasData(doc, win);
 			imageData = getImageData(doc, win, options);
 			if (options.removeHiddenElements || options.removeAlternativeFonts || options.compressHTML) {
-				const styles = getStyles(win, doc.body);
+				let styles = getStyles(win, doc.body);
 				if (options.removeHiddenElements) {
 					const markerRemovedContent = removedContentAttributeName(options.sessionId);
 					let ignoredTags = JSON.parse(JSON.stringify(IGNORED_REMOVED_TAG_NAMES));
@@ -75,7 +75,7 @@ this.docHelper = this.docHelper || (() => {
 						ignoredTags = ignoredTags.concat("SCRIPT");
 					}
 					markHiddenCandidates(win, doc.body, styles, false, markerRemovedContent, new Set(), ignoredTags);
-					markHiddenElements(win, doc.body, styles, markerRemovedContent);
+					markHiddenElements(win, doc.body, markerRemovedContent);
 					markBackdropBackground(doc, win, markerRemovedContent);
 					doc.querySelectorAll("iframe").forEach(element => {
 						const boundingRect = element.getBoundingClientRect();
@@ -83,6 +83,7 @@ this.docHelper = this.docHelper || (() => {
 							element.setAttribute(markerRemovedContent, "");
 						}
 					});
+					styles = new Map(Array.from(styles).filter(([element, style]) => element.getAttribute(markerRemovedContent) != ""));
 				}
 				if (options.removeAlternativeFonts) {
 					usedFonts = getUsedFonts(styles);
@@ -176,13 +177,12 @@ this.docHelper = this.docHelper || (() => {
 		}
 	}
 
-	function markHiddenElements(win, element, styles, markerRemovedContent) {
+	function markHiddenElements(win, element, markerRemovedContent) {
 		const elements = Array.from(element.childNodes).filter(node => node.nodeType == win.Node.ELEMENT_NODE);
 		if (element.getAttribute(markerRemovedContent) == "") {
 			element.removeAttribute(markerRemovedContent);
 		} else {
-			styles.delete(element);
-			elements.forEach(element => markHiddenElements(win, element, styles, markerRemovedContent));
+			elements.forEach(element => markHiddenElements(win, element, markerRemovedContent));
 		}
 	}