Jelajahi Sumber

fixed issue when font-weight conatins multiple values

Former-commit-id: 1b5bf160440eec8e37a813bd215f91b6ce66d3b5
Gildas 5 tahun lalu
induk
melakukan
79e85e957a
1 mengubah file dengan 9 tambahan dan 4 penghapusan
  1. 9 4
      lib/single-file/modules/css-fonts-minifier.js

+ 9 - 4
lib/single-file/modules/css-fonts-minifier.js

@@ -110,10 +110,11 @@ this.singlefile.lib.modules.fontsMinifier = this.singlefile.lib.modules.fontsMin
 				if (ruleData.type == "Atrule" && ruleData.name == "font-face") {
 					const fontFamily = singlefile.lib.helper.getFontFamily(getDeclarationValue(ruleData.block.children, "font-family"));
 					if (fontFamily) {
-						const fontWeight = singlefile.lib.helper.getFontWeight(getDeclarationValue(ruleData.block.children, "font-weight") || "400");
+						const fontWeight = getDeclarationValue(ruleData.block.children, "font-weight") || "400";
 						const fontStyle = getDeclarationValue(ruleData.block.children, "font-style") || "normal";
 						const fontVariant = getDeclarationValue(ruleData.block.children, "font-variant") || "normal";
-						fontsInfo.declared.push({ fontFamily, fontWeight, fontStyle, fontVariant });
+						fontWeight.split(",").forEach(weightValue =>
+							fontsInfo.declared.push({ fontFamily, fontWeight: singlefile.lib.helper.getFontWeight(singlefile.lib.helper.removeQuotes(weightValue)), fontStyle, fontVariant }));
 					}
 				}
 			}
@@ -159,20 +160,24 @@ this.singlefile.lib.modules.fontsMinifier = this.singlefile.lib.modules.fontsMin
 				.map(fontInfo => fontInfo.fontWeight)
 				.sort((weight1, weight2) => weight1 - weight2);
 			let usedFontWeights = optionalUsedFonts.map(fontInfo => getUsedFontWeight(fontInfo, fontStyle, declaredFontsWeights));
-			test = usedFontWeights.includes(fontWeight);
+			test = testFontweight(fontWeight, usedFontWeights);
 			if (!test) {
 				usedFontWeights = optionalUsedFonts.map(fontInfo => {
 					fontInfo[2] = "normal";
 					return getUsedFontWeight(fontInfo, fontStyle, declaredFontsWeights);
 				});
 			}
-			test = usedFontWeights.includes(fontWeight);
+			test = testFontweight(fontWeight, usedFontWeights);
 		} else {
 			test = true;
 		}
 		return test;
 	}
 
+	function testFontweight(fontWeight, usedFontWeights) {
+		return fontWeight.split(",").find(weightValue => usedFontWeights.includes(singlefile.lib.helper.getFontWeight(singlefile.lib.helper.removeQuotes(weightValue))));
+	}
+
 	function getDeclarationValue(declarations, propertyName) {
 		let property;
 		if (declarations) {