|
|
@@ -97,27 +97,27 @@ this.fontsAltMinifier = this.fontsAltMinifier || (() => {
|
|
|
|
|
|
function getFontsDetails(doc, cssRules, sheetIndex, mediaFontsDetails) {
|
|
|
let mediaIndex = 0, supportsIndex = 0;
|
|
|
- cssRules.forEach(cssRule => {
|
|
|
- if (cssRule.type == "Atrule" && cssRule.name == "media" && cssRule.block && cssRule.block.children && cssRule.prelude) {
|
|
|
- const mediaText = cssTree.generate(cssRule.prelude);
|
|
|
+ cssRules.forEach(ruleData => {
|
|
|
+ if (ruleData.type == "Atrule" && ruleData.name == "media" && ruleData.block && ruleData.block.children && ruleData.prelude) {
|
|
|
+ const mediaText = cssTree.generate(ruleData.prelude);
|
|
|
const fontsDetails = createFontsDetailsInfo();
|
|
|
mediaFontsDetails.medias.set("media-" + sheetIndex + "-" + mediaIndex + "-" + mediaText, fontsDetails);
|
|
|
mediaIndex++;
|
|
|
- getFontsDetails(doc, cssRule.block.children, sheetIndex, fontsDetails);
|
|
|
- } else if (cssRule.type == "Atrule" && cssRule.name == "supports" && cssRule.block && cssRule.block.children && cssRule.prelude) {
|
|
|
- const supportsText = cssTree.generate(cssRule.prelude);
|
|
|
+ getFontsDetails(doc, ruleData.block.children, sheetIndex, fontsDetails);
|
|
|
+ } else if (ruleData.type == "Atrule" && ruleData.name == "supports" && ruleData.block && ruleData.block.children && ruleData.prelude) {
|
|
|
+ const supportsText = cssTree.generate(ruleData.prelude);
|
|
|
const fontsDetails = createFontsDetailsInfo();
|
|
|
mediaFontsDetails.supports.set("supports-" + sheetIndex + "-" + supportsIndex + "-" + supportsText, fontsDetails);
|
|
|
supportsIndex++;
|
|
|
- getFontsDetails(doc, cssRule.block.children, sheetIndex, fontsDetails);
|
|
|
- } else if (cssRule.type == "Atrule" && cssRule.name == "font-face" && cssRule.block && cssRule.block.children) {
|
|
|
- const fontKey = getFontKey(cssRule);
|
|
|
+ getFontsDetails(doc, ruleData.block.children, sheetIndex, fontsDetails);
|
|
|
+ } else if (ruleData.type == "Atrule" && ruleData.name == "font-face" && ruleData.block && ruleData.block.children) {
|
|
|
+ const fontKey = getFontKey(ruleData);
|
|
|
let fontInfo = mediaFontsDetails.fonts.get(fontKey);
|
|
|
if (!fontInfo) {
|
|
|
fontInfo = [];
|
|
|
mediaFontsDetails.fonts.set(fontKey, fontInfo);
|
|
|
}
|
|
|
- const src = getPropertyValue(cssRule, "src");
|
|
|
+ const src = getPropertyValue(ruleData, "src");
|
|
|
if (src) {
|
|
|
const fontSources = src.match(REGEXP_URL_FUNCTION);
|
|
|
if (fontSources) {
|
|
|
@@ -189,7 +189,7 @@ this.fontsAltMinifier = this.fontsAltMinifier || (() => {
|
|
|
removedRules.forEach(cssRule => cssRules.remove(cssRule));
|
|
|
}
|
|
|
|
|
|
- function processFontFaceRule(cssRule, fontInfo, stats) {
|
|
|
+ function processFontFaceRule(ruleData, fontInfo, stats) {
|
|
|
const findSource = fontFormat => fontInfo.find(source => !source.src.match(EMPTY_URL_SOURCE) && source.format == fontFormat);
|
|
|
const filterSource = fontSource => fontInfo.filter(source => source == fontSource || source.src.startsWith(LOCAL_SOURCE));
|
|
|
stats.fonts.processed += fontInfo.length;
|
|
|
@@ -210,24 +210,24 @@ this.fontsAltMinifier = this.fontsAltMinifier || (() => {
|
|
|
}
|
|
|
stats.fonts.discarded -= fontInfo.length;
|
|
|
const removedNodes = [];
|
|
|
- for (let node = cssRule.block.children.head; node; node = node.next) {
|
|
|
+ for (let node = ruleData.block.children.head; node; node = node.next) {
|
|
|
if (node.data.property == "src") {
|
|
|
removedNodes.push(node);
|
|
|
}
|
|
|
}
|
|
|
removedNodes.pop();
|
|
|
- removedNodes.forEach(node => cssRule.block.children.remove(node));
|
|
|
- const srcDeclaration = cssRule.block.children.filter(node => node.property == "src").tail;
|
|
|
+ removedNodes.forEach(node => ruleData.block.children.remove(node));
|
|
|
+ const srcDeclaration = ruleData.block.children.filter(node => node.property == "src").tail;
|
|
|
if (srcDeclaration) {
|
|
|
fontInfo.reverse();
|
|
|
srcDeclaration.data.value = cssTree.parse(fontInfo.map(fontSource => fontSource.src).join(","), { context: "value" });
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- function getPropertyValue(cssRule, propertyName) {
|
|
|
+ function getPropertyValue(ruleData, propertyName) {
|
|
|
let property;
|
|
|
- if (cssRule.block.children) {
|
|
|
- property = cssRule.block.children.filter(node => node.property == propertyName).tail;
|
|
|
+ if (ruleData.block.children) {
|
|
|
+ property = ruleData.block.children.filter(node => node.property == propertyName).tail;
|
|
|
}
|
|
|
if (property) {
|
|
|
try {
|
|
|
@@ -238,16 +238,16 @@ this.fontsAltMinifier = this.fontsAltMinifier || (() => {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- function getFontKey(cssRule) {
|
|
|
+ function getFontKey(ruleData) {
|
|
|
return JSON.stringify([
|
|
|
- getFontFamily(getPropertyValue(cssRule, "font-family")),
|
|
|
- getFontWeight(getPropertyValue(cssRule, "font-weight") || "400"),
|
|
|
- getPropertyValue(cssRule, "font-style") || "normal",
|
|
|
- getPropertyValue(cssRule, "unicode-range"),
|
|
|
- getFontStretch(getPropertyValue(cssRule, "font-stretch")),
|
|
|
- getPropertyValue(cssRule, "font-variant") || "normal",
|
|
|
- getPropertyValue(cssRule, "font-feature-settings"),
|
|
|
- getPropertyValue(cssRule, "font-variation-settings")
|
|
|
+ getFontFamily(getPropertyValue(ruleData, "font-family")),
|
|
|
+ getFontWeight(getPropertyValue(ruleData, "font-weight") || "400"),
|
|
|
+ getPropertyValue(ruleData, "font-style") || "normal",
|
|
|
+ getPropertyValue(ruleData, "unicode-range"),
|
|
|
+ getFontStretch(getPropertyValue(ruleData, "font-stretch")),
|
|
|
+ getPropertyValue(ruleData, "font-variant") || "normal",
|
|
|
+ getPropertyValue(ruleData, "font-feature-settings"),
|
|
|
+ getPropertyValue(ruleData, "font-variation-settings")
|
|
|
]);
|
|
|
}
|
|
|
|