|
|
@@ -171,10 +171,10 @@ this.fontsMinifier = this.fontsMinifier || (() => {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- function filterUnusedFonts(rules, declaredFonts, unusedFonts, filteredUsedFonts, docContent) {
|
|
|
+ function filterUnusedFonts(cssRules, declaredFonts, unusedFonts, filteredUsedFonts, docContent) {
|
|
|
const removedRules = [];
|
|
|
- for (let rule = rules.head; rule; rule = rule.next) {
|
|
|
- const ruleData = rule.data;
|
|
|
+ for (let cssRule = cssRules.head; cssRule; cssRule = cssRule.next) {
|
|
|
+ const ruleData = cssRule.data;
|
|
|
if (ruleData.type == "Atrule" && ruleData.name == "media") {
|
|
|
filterUnusedFonts(ruleData.block.children, declaredFonts, unusedFonts, filteredUsedFonts, docContent);
|
|
|
} else if (ruleData.type == "Atrule" && ruleData.name == "font-face") {
|
|
|
@@ -182,21 +182,21 @@ this.fontsMinifier = this.fontsMinifier || (() => {
|
|
|
if (fontFamily) {
|
|
|
const unicodeRange = getPropertyValue(ruleData, "unicode-range");
|
|
|
if (unusedFonts.find(fontInfo => fontInfo.fontFamily == fontFamily) || !testUnicodeRange(docContent, unicodeRange) || !testUsedFont(ruleData, fontFamily, declaredFonts, filteredUsedFonts)) {
|
|
|
- removedRules.push(rule);
|
|
|
+ removedRules.push(cssRule);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- removedRules.forEach(rule => rules.remove(rule));
|
|
|
+ removedRules.forEach(cssRule => cssRules.remove(cssRule));
|
|
|
}
|
|
|
|
|
|
- function testUsedFont(rule, familyName, declaredFonts, filteredUsedFonts) {
|
|
|
+ function testUsedFont(cssRule, familyName, declaredFonts, filteredUsedFonts) {
|
|
|
let test;
|
|
|
const optionalUsedFonts = filteredUsedFonts && filteredUsedFonts.get(familyName);
|
|
|
if (optionalUsedFonts && optionalUsedFonts.length) {
|
|
|
- const fontStyle = getPropertyValue(rule, "font-style") || "normal";
|
|
|
- const fontWeight = getFontWeight(getPropertyValue(rule, "font-weight") || "400");
|
|
|
- const fontVariant = getPropertyValue(rule, "font-variant") || "normal";
|
|
|
+ const fontStyle = getPropertyValue(cssRule, "font-style") || "normal";
|
|
|
+ const fontWeight = getFontWeight(getPropertyValue(cssRule, "font-weight") || "400");
|
|
|
+ const fontVariant = getPropertyValue(cssRule, "font-variant") || "normal";
|
|
|
const declaredFontsWeights = declaredFonts
|
|
|
.filter(fontInfo => fontInfo.fontFamily == familyName && fontInfo.fontStyle == fontStyle && testFontVariant(fontInfo, fontVariant))
|
|
|
.map(fontInfo => fontInfo.fontWeight)
|