|
|
@@ -33,9 +33,6 @@ this.singlefile.lib.modules.fontsMinifier = this.singlefile.lib.modules.fontsMin
|
|
|
const REGEXP_DASH = /-/;
|
|
|
const REGEXP_QUESTION_MARK = /\?/g;
|
|
|
const REGEXP_STARTS_U_PLUS = /^U\+/i;
|
|
|
- const REGEXP_SIMPLE_QUOTES_STRING = /^'(.*?)'$/;
|
|
|
- const REGEXP_DOUBLE_QUOTES_STRING = /^"(.*?)"$/;
|
|
|
-
|
|
|
|
|
|
return {
|
|
|
process: (doc, stylesheets, styles, options) => {
|
|
|
@@ -67,7 +64,7 @@ this.singlefile.lib.modules.fontsMinifier = this.singlefile.lib.modules.fontsMin
|
|
|
const matchedVar = familyName.match(/^var\((--.*)\)$/);
|
|
|
if (matchedVar && matchedVar[1]) {
|
|
|
const computedFamilyName = getComputedStyle.call(window, options.doc.body).getPropertyValue(matchedVar[1]);
|
|
|
- return (computedFamilyName && computedFamilyName.split(",").map(name => getFontFamily(name))) || familyName;
|
|
|
+ return (computedFamilyName && computedFamilyName.split(",").map(name => singlefile.lib.helper.getFontFamily(name))) || familyName;
|
|
|
}
|
|
|
return familyName;
|
|
|
}));
|
|
|
@@ -111,7 +108,7 @@ this.singlefile.lib.modules.fontsMinifier = this.singlefile.lib.modules.fontsMin
|
|
|
}
|
|
|
} else {
|
|
|
if (ruleData.type == "Atrule" && ruleData.name == "font-face") {
|
|
|
- const fontFamily = getFontFamily(getDeclarationValue(ruleData.block.children, "font-family"));
|
|
|
+ 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 fontStyle = getDeclarationValue(ruleData.block.children, "font-style") || "normal";
|
|
|
@@ -130,7 +127,7 @@ this.singlefile.lib.modules.fontsMinifier = this.singlefile.lib.modules.fontsMin
|
|
|
if (ruleData.type == "Atrule" && ruleData.name == "media" && ruleData.block && ruleData.block.children) {
|
|
|
filterUnusedFonts(ruleData.block.children, declaredFonts, unusedFonts, filteredUsedFonts, docContent);
|
|
|
} else if (ruleData.type == "Atrule" && ruleData.name == "font-face") {
|
|
|
- const fontFamily = getFontFamily(getDeclarationValue(ruleData.block.children, "font-family"));
|
|
|
+ const fontFamily = singlefile.lib.helper.getFontFamily(getDeclarationValue(ruleData.block.children, "font-family"));
|
|
|
if (fontFamily) {
|
|
|
const unicodeRange = getDeclarationValue(ruleData.block.children, "unicode-range");
|
|
|
if (unusedFonts.find(fontInfo => fontInfo.fontFamily == fontFamily) || !testUnicodeRange(docContent, unicodeRange) || !testUsedFont(ruleData, fontFamily, declaredFonts, filteredUsedFonts)) {
|
|
|
@@ -192,7 +189,7 @@ this.singlefile.lib.modules.fontsMinifier = this.singlefile.lib.modules.fontsMin
|
|
|
if (fontFamilyName.data.value.children) {
|
|
|
fontFamilyName.data.value.children.forEach(node => {
|
|
|
if (node.type == "Operator" && node.value == "," && familyName) {
|
|
|
- fontFamilyNames.push(getFontFamily(familyName));
|
|
|
+ fontFamilyNames.push(singlefile.lib.helper.getFontFamily(familyName));
|
|
|
familyName = "";
|
|
|
} else {
|
|
|
familyName += cssTree.generate(node);
|
|
|
@@ -202,14 +199,14 @@ this.singlefile.lib.modules.fontsMinifier = this.singlefile.lib.modules.fontsMin
|
|
|
fontFamilyName = cssTree.generate(fontFamilyName.data.value);
|
|
|
}
|
|
|
if (familyName) {
|
|
|
- fontFamilyNames.push(getFontFamily(familyName));
|
|
|
+ fontFamilyNames.push(singlefile.lib.helper.getFontFamily(familyName));
|
|
|
}
|
|
|
}
|
|
|
const font = declarations.children.filter(node => node.property == "font").tail;
|
|
|
if (font && font.data && font.data.value) {
|
|
|
try {
|
|
|
const parsedFont = singlefile.lib.vendor.fontPropertyParser.parse(cssTree.generate(font.data.value));
|
|
|
- parsedFont.family.forEach(familyName => fontFamilyNames.push(getFontFamily(familyName)));
|
|
|
+ parsedFont.family.forEach(familyName => fontFamilyNames.push(singlefile.lib.helper.getFontFamily(familyName)));
|
|
|
} catch (error) {
|
|
|
// ignored
|
|
|
}
|
|
|
@@ -335,14 +332,4 @@ this.singlefile.lib.modules.fontsMinifier = this.singlefile.lib.modules.fontsMin
|
|
|
return "\\u{" + range + "}";
|
|
|
}
|
|
|
|
|
|
- function getFontFamily(string = "") {
|
|
|
- string = string.toLowerCase().trim();
|
|
|
- if (string.match(REGEXP_SIMPLE_QUOTES_STRING)) {
|
|
|
- string = string.replace(REGEXP_SIMPLE_QUOTES_STRING, "$1");
|
|
|
- } else {
|
|
|
- string = string.replace(REGEXP_DOUBLE_QUOTES_STRING, "$1");
|
|
|
- }
|
|
|
- return string.trim().replace(/\\+ +/gi, " ");
|
|
|
- }
|
|
|
-
|
|
|
})();
|