single-file-core 1.1.78 → 1.1.79
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.
- package/modules/css-fonts-minifier.js +41 -18
- package/package.json +1 -1
|
@@ -218,27 +218,13 @@ function getFontFamilyNames(declarations) {
|
|
|
218
218
|
let fontFamilyName = declarations.children.filter(node => node.property == "font-family").tail;
|
|
219
219
|
let fontFamilyNames = [];
|
|
220
220
|
if (fontFamilyName) {
|
|
221
|
-
let familyName = "";
|
|
222
221
|
if (fontFamilyName.data.value.children) {
|
|
223
|
-
|
|
224
|
-
fontFamilyName.data.value.children.forEach(node => {
|
|
225
|
-
if (node.type == "Operator" && node.value == "," && familyName) {
|
|
226
|
-
fontFamilyNames.push(helper.normalizeFontFamily(familyName));
|
|
227
|
-
familyName = "";
|
|
228
|
-
previousType = null;
|
|
229
|
-
} else {
|
|
230
|
-
if (previousType == "Identifier" && node.type == "Identifier") {
|
|
231
|
-
familyName += " ";
|
|
232
|
-
}
|
|
233
|
-
familyName += cssTree.generate(node);
|
|
234
|
-
}
|
|
235
|
-
previousType = node.type;
|
|
236
|
-
});
|
|
222
|
+
parseFamilyNames(fontFamilyName.data.value, fontFamilyNames);
|
|
237
223
|
} else {
|
|
238
224
|
fontFamilyName = cssTree.generate(fontFamilyName.data.value);
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
225
|
+
if (fontFamilyName) {
|
|
226
|
+
fontFamilyNames.push(helper.normalizeFontFamily(fontFamilyName));
|
|
227
|
+
}
|
|
242
228
|
}
|
|
243
229
|
}
|
|
244
230
|
const font = declarations.children.filter(node => node.property == "font").tail;
|
|
@@ -253,6 +239,43 @@ function getFontFamilyNames(declarations) {
|
|
|
253
239
|
return fontFamilyNames;
|
|
254
240
|
}
|
|
255
241
|
|
|
242
|
+
function parseFamilyNames(fontFamilyNameTokenData, fontFamilyNames) {
|
|
243
|
+
let nextToken = fontFamilyNameTokenData.children.head;
|
|
244
|
+
while (nextToken) {
|
|
245
|
+
if (nextToken.data.type == "Identifier") {
|
|
246
|
+
let familyName = nextToken.data.name;
|
|
247
|
+
let nextIdentifierToken = nextToken.next;
|
|
248
|
+
while (nextIdentifierToken && nextIdentifierToken.data.type != "Operator" && nextIdentifierToken.data.value != ",") {
|
|
249
|
+
familyName += " " + nextIdentifierToken.data.name;
|
|
250
|
+
nextIdentifierToken = nextIdentifierToken.next;
|
|
251
|
+
}
|
|
252
|
+
fontFamilyNames.push(helper.normalizeFontFamily(familyName));
|
|
253
|
+
nextToken = nextToken.next;
|
|
254
|
+
} else if (nextToken.data.type == "Function" && nextToken.data.name == "var" && nextToken.data.children) {
|
|
255
|
+
const varName = nextToken.data.children.head.data.name;
|
|
256
|
+
fontFamilyNames.push(helper.normalizeFontFamily("var(" + varName + ")"));
|
|
257
|
+
let nextValueToken = nextToken.data.children.head.next;
|
|
258
|
+
while (nextValueToken && nextValueToken.data.type == "Operator" && nextValueToken.data.value == ",") {
|
|
259
|
+
nextValueToken = nextValueToken.next;
|
|
260
|
+
}
|
|
261
|
+
const fallbackToken = nextValueToken;
|
|
262
|
+
if (fallbackToken) {
|
|
263
|
+
if (fallbackToken.data.children) {
|
|
264
|
+
parseFamilyNames(fallbackToken.data, fontFamilyNames);
|
|
265
|
+
} else {
|
|
266
|
+
fontFamilyNames.push(helper.normalizeFontFamily(fallbackToken.data.value));
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
nextToken = nextToken.next;
|
|
270
|
+
} else if (nextToken.data.type == "String") {
|
|
271
|
+
fontFamilyNames.push(helper.normalizeFontFamily(nextToken.data.value));
|
|
272
|
+
nextToken = nextToken.next;
|
|
273
|
+
} else if (nextToken.data.type == "Operator" && nextToken.data.value == ",") {
|
|
274
|
+
nextToken = nextToken.next;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
256
279
|
function getUsedFontWeight(fontInfo, fontStyle, fontWeights) {
|
|
257
280
|
let foundWeight;
|
|
258
281
|
fontWeights = fontWeights.map(weight => String(Number.parseInt(weight, 10)));
|