Ver código fonte

fixed fonts filtering issue

Gildas 7 anos atrás
pai
commit
d05a1dc303
1 arquivos alterados com 10 adições e 6 exclusões
  1. 10 6
      lib/single-file/css-fonts-minifier.js

+ 10 - 6
lib/single-file/css-fonts-minifier.js

@@ -62,6 +62,10 @@ this.fontsMinifier = this.fontsMinifier || (() => {
 					stats.rules.processed += style.sheet.cssRules.length;
 					stats.rules.discarded += style.sheet.cssRules.length;
 					processRules(doc, style.sheet.cssRules, fontsDetails, declaredFonts, usedFonts, secondPass);
+				}
+			});
+			doc.querySelectorAll("style").forEach(style => {
+				if (style.sheet) {
 					style.textContent = processFontFaceRules(style.sheet.cssRules, fontsDetails, "all", stats);
 				}
 			});
@@ -111,14 +115,14 @@ this.fontsMinifier = this.fontsMinifier || (() => {
 							const fontKey = getFontKey(rule.style);
 							let fontInfo = fontsDetails.get(fontKey);
 							if (!fontInfo) {
-								fontInfo = new Set();
+								fontInfo = [];
 								fontsDetails.set(fontKey, fontInfo);
 							}
 							const src = rule.style.getPropertyValue("src");
 							if (src) {
 								const fontSources = src.match(REGEXP_URL_FUNCTION);
 								if (fontSources) {
-									fontSources.forEach(source => fontInfo.add(source));
+									fontSources.forEach(source => fontInfo.unshift(source));
 								}
 							}
 						}
@@ -149,7 +153,7 @@ this.fontsMinifier = this.fontsMinifier || (() => {
 	}
 
 	function processFontFaceRule(rule, fontInfo, stats) {
-		let fontSources = Array.from(fontInfo).map(fontSource => {
+		let fontSources = fontInfo.map(fontSource => {
 			const fontFormatMatch = fontSource.match(REGEXP_FONT_FORMAT_VALUE);
 			let fontFormat;
 			if (fontFormatMatch && fontFormatMatch[1]) {
@@ -191,21 +195,21 @@ this.fontsMinifier = this.fontsMinifier || (() => {
 		stats.fonts.processed += fontSources.length;
 		stats.fonts.discarded += fontSources.length;
 		if (woffFontFound) {
-			fontSources = fontSources.filter(fontSource => fontTest(fontSource, woffFontFound.format));
+			fontSources = [woffFontFound];
 		} else {
 			let ttfFontFound = fontSources.find(fontSource => fontTest(fontSource, "truetype-variations"));
 			if (!ttfFontFound) {
 				ttfFontFound = fontSources.find(fontSource => fontTest(fontSource, "truetype"));
 			}
 			if (ttfFontFound) {
-				fontSources = fontSources.filter(fontSource => fontTest(fontSource, ttfFontFound.format));
+				fontSources = [ttfFontFound];
 			} else {
 				let otfFontFound = fontSources.find(fontSource => fontTest(fontSource, "opentype"));
 				if (!otfFontFound) {
 					otfFontFound = fontSources.find(fontSource => fontTest(fontSource, "embedded-opentype"));
 				}
 				if (otfFontFound) {
-					fontSources = fontSources.filter(fontSource => fontTest(fontSource, otfFontFound.format));
+					fontSources = [otfFontFound];
 				}
 			}
 		}