|
|
@@ -29,7 +29,7 @@ this.fontsMinifier = this.fontsMinifier || (() => {
|
|
|
return {
|
|
|
process: (doc, secondPass) => {
|
|
|
const declaredFonts = new Set();
|
|
|
- const usedFonts = new Set();
|
|
|
+ const usedFonts = [];
|
|
|
const stats = {
|
|
|
rules: {
|
|
|
processed: 0,
|
|
|
@@ -50,10 +50,12 @@ this.fontsMinifier = this.fontsMinifier || (() => {
|
|
|
});
|
|
|
doc.querySelectorAll("[style]").forEach(element => {
|
|
|
if (element.style.fontFamily) {
|
|
|
- element.style.fontFamily.split(",").forEach(fontFamilyName => usedFonts.add(getFontFamilyName(fontFamilyName)));
|
|
|
+ const fontFamilyNames = element.style.fontFamily.split(",").map(fontFamilyName => getFontFamilyName(fontFamilyName));
|
|
|
+ usedFonts.push(fontFamilyNames);
|
|
|
}
|
|
|
});
|
|
|
- const unusedFonts = Array.from(declaredFonts).filter(fontFamilyName => !usedFonts.has(fontFamilyName));
|
|
|
+ const filteredUsedFonts = new Set(usedFonts.map(fontNames => fontNames.find(fontName => declaredFonts.has(fontName))).filter(fontName => fontName));
|
|
|
+ const unusedFonts = Array.from(declaredFonts).filter(fontFamilyName => !filteredUsedFonts.has(fontFamilyName));
|
|
|
doc.querySelectorAll("style").forEach(style => {
|
|
|
if (style.sheet) {
|
|
|
const processedRules = style.sheet.cssRules.length;
|
|
|
@@ -75,7 +77,8 @@ this.fontsMinifier = this.fontsMinifier || (() => {
|
|
|
stylesheetContent += "}";
|
|
|
} else if (rule.type == CSSRule.STYLE_RULE) {
|
|
|
if (rule.style && rule.style.fontFamily) {
|
|
|
- rule.style.fontFamily.split(",").forEach(fontFamilyName => usedFonts.add(getFontFamilyName(fontFamilyName)));
|
|
|
+ const fontFamilyNames = rule.style.fontFamily.split(",").map(fontFamilyName => getFontFamilyName(fontFamilyName));
|
|
|
+ usedFonts.push(fontFamilyNames);
|
|
|
}
|
|
|
stylesheetContent += rule.cssText;
|
|
|
} else {
|