single-file-core 1.2.33 → 1.2.34
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -60,12 +60,12 @@ function process(doc, stylesheets, styles, options) {
|
|
|
60
60
|
if (cssRules) {
|
|
61
61
|
stats.processed += cssRules.size;
|
|
62
62
|
stats.discarded += cssRules.size;
|
|
63
|
-
getFontsInfo(cssRules, fontsInfo);
|
|
63
|
+
getFontsInfo(cssRules, fontsInfo, options);
|
|
64
64
|
docContent = getRulesTextContent(doc, cssRules, workStyleElement, docContent);
|
|
65
65
|
}
|
|
66
66
|
});
|
|
67
67
|
styles.forEach(declarations => {
|
|
68
|
-
const fontFamilyNames = getFontFamilyNames(declarations);
|
|
68
|
+
const fontFamilyNames = getFontFamilyNames(declarations, options);
|
|
69
69
|
if (fontFamilyNames.length) {
|
|
70
70
|
fontsInfo.used.push(fontFamilyNames);
|
|
71
71
|
}
|
|
@@ -110,12 +110,12 @@ function process(doc, stylesheets, styles, options) {
|
|
|
110
110
|
return stats;
|
|
111
111
|
}
|
|
112
112
|
|
|
113
|
-
function getFontsInfo(cssRules, fontsInfo) {
|
|
113
|
+
function getFontsInfo(cssRules, fontsInfo, options) {
|
|
114
114
|
cssRules.forEach(ruleData => {
|
|
115
115
|
if (ruleData.type == "Atrule" && (ruleData.name == "media" || ruleData.name == "supports" || ruleData.name == "layer") && ruleData.block && ruleData.block.children) {
|
|
116
|
-
getFontsInfo(ruleData.block.children, fontsInfo);
|
|
116
|
+
getFontsInfo(ruleData.block.children, fontsInfo, options);
|
|
117
117
|
} else if (ruleData.type == "Rule") {
|
|
118
|
-
const fontFamilyNames = getFontFamilyNames(ruleData.block);
|
|
118
|
+
const fontFamilyNames = getFontFamilyNames(ruleData.block, options);
|
|
119
119
|
if (fontFamilyNames.length) {
|
|
120
120
|
fontsInfo.used.push(fontFamilyNames);
|
|
121
121
|
}
|
|
@@ -222,7 +222,7 @@ function getDeclarationValue(declarations, propertyName) {
|
|
|
222
222
|
}
|
|
223
223
|
}
|
|
224
224
|
|
|
225
|
-
function getFontFamilyNames(declarations) {
|
|
225
|
+
function getFontFamilyNames(declarations, options) {
|
|
226
226
|
let fontFamilyName = declarations.children.filter(node => node.property == "font-family").tail;
|
|
227
227
|
let fontFamilyNames = [];
|
|
228
228
|
if (fontFamilyName) {
|
|
@@ -238,7 +238,13 @@ function getFontFamilyNames(declarations) {
|
|
|
238
238
|
const font = declarations.children.filter(node => node.property == "font").tail;
|
|
239
239
|
if (font && font.data && font.data.value) {
|
|
240
240
|
try {
|
|
241
|
-
|
|
241
|
+
let value = font.data.value;
|
|
242
|
+
let fontFamilyName = cssTree.generate(value);
|
|
243
|
+
const matchedVar = fontFamilyName.match(/^var\((--.*)\)$/);
|
|
244
|
+
if (matchedVar && matchedVar[1]) {
|
|
245
|
+
value = cssTree.parse(globalThis.getComputedStyle(options.doc.body).getPropertyValue(matchedVar[1]), { context: "value" });
|
|
246
|
+
}
|
|
247
|
+
const parsedFont = fontPropertyParser.parse(value);
|
|
242
248
|
parsedFont.family.forEach(familyName => fontFamilyNames.push(helper.normalizeFontFamily(familyName)));
|
|
243
249
|
} catch (error) {
|
|
244
250
|
// ignored
|