|
@@ -99,7 +99,7 @@ this.singlefile.lib.modules.fontsMinifier = this.singlefile.lib.modules.fontsMin
|
|
|
|
|
|
|
|
function getFontsInfo(cssRules, fontsInfo) {
|
|
function getFontsInfo(cssRules, fontsInfo) {
|
|
|
cssRules.forEach(ruleData => {
|
|
cssRules.forEach(ruleData => {
|
|
|
- if (ruleData.type == "Atrule" && ruleData.name == "media" && ruleData.block && ruleData.block.children) {
|
|
|
|
|
|
|
+ if (ruleData.type == "Atrule" && (ruleData.name == "media" || ruleData.name == "supports") && ruleData.block && ruleData.block.children) {
|
|
|
getFontsInfo(ruleData.block.children, fontsInfo);
|
|
getFontsInfo(ruleData.block.children, fontsInfo);
|
|
|
} else if (ruleData.type == "Rule") {
|
|
} else if (ruleData.type == "Rule") {
|
|
|
const fontFamilyNames = getFontFamilyNames(ruleData.block);
|
|
const fontFamilyNames = getFontFamilyNames(ruleData.block);
|
|
@@ -125,7 +125,7 @@ this.singlefile.lib.modules.fontsMinifier = this.singlefile.lib.modules.fontsMin
|
|
|
const removedRules = [];
|
|
const removedRules = [];
|
|
|
for (let cssRule = cssRules.head; cssRule; cssRule = cssRule.next) {
|
|
for (let cssRule = cssRules.head; cssRule; cssRule = cssRule.next) {
|
|
|
const ruleData = cssRule.data;
|
|
const ruleData = cssRule.data;
|
|
|
- if (ruleData.type == "Atrule" && ruleData.name == "media" && ruleData.block && ruleData.block.children) {
|
|
|
|
|
|
|
+ if (ruleData.type == "Atrule" && (ruleData.name == "media" || ruleData.name == "supports") && ruleData.block && ruleData.block.children) {
|
|
|
filterUnusedFonts(ruleData.block.children, declaredFonts, unusedFonts, filteredUsedFonts, docContent);
|
|
filterUnusedFonts(ruleData.block.children, declaredFonts, unusedFonts, filteredUsedFonts, docContent);
|
|
|
} else if (ruleData.type == "Atrule" && ruleData.name == "font-face") {
|
|
} else if (ruleData.type == "Atrule" && ruleData.name == "font-face") {
|
|
|
const fontFamily = singlefile.lib.helper.normalizeFontFamily(getDeclarationValue(ruleData.block.children, "font-family"));
|
|
const fontFamily = singlefile.lib.helper.normalizeFontFamily(getDeclarationValue(ruleData.block.children, "font-family"));
|
|
@@ -150,6 +150,7 @@ this.singlefile.lib.modules.fontsMinifier = this.singlefile.lib.modules.fontsMin
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function testUsedFont(ruleData, familyName, declaredFonts, filteredUsedFonts) {
|
|
function testUsedFont(ruleData, familyName, declaredFonts, filteredUsedFonts) {
|
|
|
|
|
+ debugger;
|
|
|
let test;
|
|
let test;
|
|
|
const optionalUsedFonts = filteredUsedFonts && filteredUsedFonts.get(familyName);
|
|
const optionalUsedFonts = filteredUsedFonts && filteredUsedFonts.get(familyName);
|
|
|
if (optionalUsedFonts && optionalUsedFonts.length) {
|
|
if (optionalUsedFonts && optionalUsedFonts.length) {
|
|
@@ -231,26 +232,30 @@ this.singlefile.lib.modules.fontsMinifier = this.singlefile.lib.modules.fontsMin
|
|
|
let foundWeight;
|
|
let foundWeight;
|
|
|
if (fontInfo[2] == fontStyle) {
|
|
if (fontInfo[2] == fontStyle) {
|
|
|
let fontWeight = Number(fontInfo[1]);
|
|
let fontWeight = Number(fontInfo[1]);
|
|
|
- if (fontWeight >= 400 && fontWeight <= 500) {
|
|
|
|
|
- foundWeight = fontWeights.find(weight => weight >= fontWeight && weight <= 500);
|
|
|
|
|
- if (!foundWeight) {
|
|
|
|
|
- foundWeight = findDescendingFontWeight(fontWeight, fontWeights);
|
|
|
|
|
- }
|
|
|
|
|
- if (!foundWeight) {
|
|
|
|
|
- foundWeight = findAscendingFontWeight(fontWeight, fontWeights);
|
|
|
|
|
|
|
+ if (fontWeights.length > 1) {
|
|
|
|
|
+ if (fontWeight >= 400 && fontWeight <= 500) {
|
|
|
|
|
+ foundWeight = fontWeights.find(weight => weight >= fontWeight && weight <= 500);
|
|
|
|
|
+ if (!foundWeight) {
|
|
|
|
|
+ foundWeight = findDescendingFontWeight(fontWeight, fontWeights);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!foundWeight) {
|
|
|
|
|
+ foundWeight = findAscendingFontWeight(fontWeight, fontWeights);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
- }
|
|
|
|
|
- if (fontWeight < 400) {
|
|
|
|
|
- foundWeight = fontWeights.slice().reverse().find(weight => weight <= fontWeight);
|
|
|
|
|
- if (!foundWeight) {
|
|
|
|
|
- foundWeight = findAscendingFontWeight(fontWeight, fontWeights);
|
|
|
|
|
|
|
+ if (fontWeight < 400) {
|
|
|
|
|
+ foundWeight = fontWeights.slice().reverse().find(weight => weight <= fontWeight);
|
|
|
|
|
+ if (!foundWeight) {
|
|
|
|
|
+ foundWeight = findAscendingFontWeight(fontWeight, fontWeights);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
- }
|
|
|
|
|
- if (fontWeight > 500) {
|
|
|
|
|
- foundWeight = fontWeights.find(weight => weight >= fontWeight);
|
|
|
|
|
- if (!foundWeight) {
|
|
|
|
|
- foundWeight = findDescendingFontWeight(fontWeight, fontWeights);
|
|
|
|
|
|
|
+ if (fontWeight > 500) {
|
|
|
|
|
+ foundWeight = fontWeights.find(weight => weight >= fontWeight);
|
|
|
|
|
+ if (!foundWeight) {
|
|
|
|
|
+ foundWeight = findDescendingFontWeight(fontWeight, fontWeights);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
+ } else {
|
|
|
|
|
+ foundWeight = fontWeights[0];
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
return foundWeight;
|
|
return foundWeight;
|
|
@@ -267,7 +272,7 @@ this.singlefile.lib.modules.fontsMinifier = this.singlefile.lib.modules.fontsMin
|
|
|
function getRulesTextContent(doc, cssRules, workStylesheet, content) {
|
|
function getRulesTextContent(doc, cssRules, workStylesheet, content) {
|
|
|
cssRules.forEach(ruleData => {
|
|
cssRules.forEach(ruleData => {
|
|
|
if (ruleData.block && ruleData.block.children && ruleData.prelude && ruleData.prelude.children) {
|
|
if (ruleData.block && ruleData.block.children && ruleData.prelude && ruleData.prelude.children) {
|
|
|
- if (ruleData.type == "Atrule" && ruleData.name == "media") {
|
|
|
|
|
|
|
+ if (ruleData.type == "Atrule" && (ruleData.name == "media" || ruleData.name == "supports")) {
|
|
|
content = getRulesTextContent(doc, ruleData.block.children, workStylesheet, content);
|
|
content = getRulesTextContent(doc, ruleData.block.children, workStylesheet, content);
|
|
|
} else if (ruleData.type == "Rule") {
|
|
} else if (ruleData.type == "Rule") {
|
|
|
content = getDeclarationsTextContent(ruleData.block.children, workStylesheet, content);
|
|
content = getDeclarationsTextContent(ruleData.block.children, workStylesheet, content);
|