1
0
Эх сурвалжийг харах

removed removeUnusedCSSRules paramter in fonts-minifier.js

Gildas 7 жил өмнө
parent
commit
01bee11c73

+ 3 - 3
extension/ui/pages/help.html

@@ -196,9 +196,9 @@
 					</li>
 
 					<li>
-						<span class="option">remove alternative fonts to woff</span>
-						<p>Check this option to remove fonts that are alternatives to the Web Open Font Format. Checking this this option should
-							not alter the document for modern browsers and can considerably reduce the size of the file.</p>
+						<span class="option">remove alternative fonts to woff and unused font rules</span>
+						<p>Check this option to remove fonts that are alternatives to the Web Open Font Format and CSS font rules that are not
+							used. Checking this this option should not alter the document and can considerably reduce the size of the file.</p>
 						<p class="notice">It is recommended to
 							<u>check</u> this option</p>
 					</li>

+ 1 - 1
extension/ui/pages/options.html

@@ -81,7 +81,7 @@
 			<input type="checkbox" id="removeUnusedCSSRulesInput">
 		</div>
 		<div class="option">
-			<label for="removeAlternativeFontsInput">remove alternative fonts to woff</label>
+			<label for="removeAlternativeFontsInput">remove alternative fonts to woff and unused font rules</label>
 			<input type="checkbox" id="removeAlternativeFontsInput">
 		</div>
 		<div class="option">

+ 18 - 20
lib/single-file/fonts-minifier.js

@@ -27,7 +27,7 @@ this.fontsMinifier = this.fontsMinifier || (() => {
 	const REGEXP_URL_NO_QUOTES_FN = /url\s*\(\s*(.*?)\s*\)/i;
 
 	return {
-		process: (doc, removeUnusedCSSRules, secondPass) => {
+		process: (doc, secondPass) => {
 			const declaredFonts = new Set();
 			const usedFonts = new Set();
 			const stats = {
@@ -44,38 +44,36 @@ this.fontsMinifier = this.fontsMinifier || (() => {
 				if (style.sheet) {
 					const processedRules = style.sheet.cssRules.length;
 					stats.rules.processed += processedRules;
-					style.textContent = processRules(doc, style.sheet.cssRules, declaredFonts, usedFonts, removeUnusedCSSRules, stats, secondPass);
+					style.textContent = processRules(doc, style.sheet.cssRules, declaredFonts, usedFonts, stats, secondPass);
+					stats.rules.discarded += processedRules - style.sheet.cssRules.length;
+				}
+			});
+			doc.querySelectorAll("[style]").forEach(element => {
+				if (element.style.fontFamily) {
+					element.style.fontFamily.split(",").forEach(fontFamilyName => usedFonts.add(getFontFamilyName(fontFamilyName)));
+				}
+			});
+			const unusedFonts = Array.from(declaredFonts).filter(fontFamilyName => !usedFonts.has(fontFamilyName));
+			doc.querySelectorAll("style").forEach(style => {
+				if (style.sheet) {
+					const processedRules = style.sheet.cssRules.length;
+					style.textContent = deleteUnusedFonts(doc, style.sheet.cssRules, unusedFonts);
 					stats.rules.discarded += processedRules - style.sheet.cssRules.length;
 				}
 			});
-			if (removeUnusedCSSRules) {
-				doc.querySelectorAll("[style]").forEach(element => {
-					if (element.style.fontFamily) {
-						element.style.fontFamily.split(",").forEach(fontFamilyName => usedFonts.add(getFontFamilyName(fontFamilyName)));
-					}
-				});
-				const unusedFonts = Array.from(declaredFonts).filter(fontFamilyName => !usedFonts.has(fontFamilyName));
-				doc.querySelectorAll("style").forEach(style => {
-					if (style.sheet) {
-						const processedRules = style.sheet.cssRules.length;
-						style.textContent = deleteUnusedFonts(doc, style.sheet.cssRules, unusedFonts);
-						stats.rules.discarded += processedRules - style.sheet.cssRules.length;
-					}
-				});
-			}
 			return stats;
 		}
 	};
 
-	function processRules(doc, rules, declaredFonts, usedFonts, removeUnusedCSSRules, stats, secondPass) {
+	function processRules(doc, rules, declaredFonts, usedFonts, stats, secondPass) {
 		let stylesheetContent = "";
 		if (rules) {
 			Array.from(rules).forEach(rule => {
 				if (rule.type == CSSRule.MEDIA_RULE) {
 					stylesheetContent += "@media " + Array.prototype.join.call(rule.media, ",") + " {";
-					stylesheetContent += processRules(doc, rule.cssRules, declaredFonts, usedFonts, removeUnusedCSSRules, stats, secondPass);
+					stylesheetContent += processRules(doc, rule.cssRules, declaredFonts, usedFonts, stats, secondPass);
 					stylesheetContent += "}";
-				} else if (removeUnusedCSSRules && rule.type == CSSRule.STYLE_RULE) {
+				} else if (rule.type == CSSRule.STYLE_RULE) {
 					if (rule.style && rule.style.fontFamily) {
 						rule.style.fontFamily.split(",").forEach(fontFamilyName => usedFonts.add(getFontFamilyName(fontFamilyName)));
 					}

+ 2 - 2
lib/single-file/single-file-browser.js

@@ -129,8 +129,8 @@ this.SingleFile = this.SingleFile || (() => {
 			return rulesMinifier.process(doc);
 		}
 
-		static fontsMinifier(doc, removeUnusedCSSRules, secondPass) {
-			return fontsMinifier.process(doc, removeUnusedCSSRules, secondPass);
+		static fontsMinifier(doc, secondPass) {
+			return fontsMinifier.process(doc, secondPass);
 		}
 
 		static uglifycss(content, options) {

+ 1 - 1
lib/single-file/single-file-core.js

@@ -399,7 +399,7 @@ this.SingleFileCore = this.SingleFileCore || (() => {
 		}
 
 		removeAlternativeFonts(secondPass) {
-			DOM.fontsMinifier(this.doc, this.options.removeUnusedCSSRules, secondPass);
+			DOM.fontsMinifier(this.doc, secondPass);
 		}
 
 		removeHiddenElements(sessionId) {