|
|
@@ -63,14 +63,16 @@ this.fontsAltMinifier = this.fontsAltMinifier || (() => {
|
|
|
let sheetIndex = 0;
|
|
|
stylesheets.forEach(stylesheetInfo => {
|
|
|
const cssRules = stylesheetInfo.stylesheet.children;
|
|
|
- stats.rules.processed += cssRules.getSize();
|
|
|
- stats.rules.discarded += cssRules.getSize();
|
|
|
- if (stylesheetInfo.mediaText && stylesheetInfo.mediaText != MEDIA_ALL) {
|
|
|
- const mediaFontsDetails = createFontsDetailsInfo();
|
|
|
- fontsDetails.medias.set("media-" + sheetIndex + "-" + stylesheetInfo.mediaText, mediaFontsDetails);
|
|
|
- getFontsDetails(doc, cssRules, sheetIndex, mediaFontsDetails);
|
|
|
- } else {
|
|
|
- getFontsDetails(doc, cssRules, sheetIndex, fontsDetails);
|
|
|
+ if (cssRules) {
|
|
|
+ stats.rules.processed += cssRules.getSize();
|
|
|
+ stats.rules.discarded += cssRules.getSize();
|
|
|
+ if (stylesheetInfo.mediaText && stylesheetInfo.mediaText != MEDIA_ALL) {
|
|
|
+ const mediaFontsDetails = createFontsDetailsInfo();
|
|
|
+ fontsDetails.medias.set("media-" + sheetIndex + "-" + stylesheetInfo.mediaText, mediaFontsDetails);
|
|
|
+ getFontsDetails(doc, cssRules, sheetIndex, mediaFontsDetails);
|
|
|
+ } else {
|
|
|
+ getFontsDetails(doc, cssRules, sheetIndex, fontsDetails);
|
|
|
+ }
|
|
|
}
|
|
|
sheetIndex++;
|
|
|
});
|
|
|
@@ -78,12 +80,15 @@ this.fontsAltMinifier = this.fontsAltMinifier || (() => {
|
|
|
sheetIndex = 0;
|
|
|
stylesheets.forEach(stylesheetInfo => {
|
|
|
const cssRules = stylesheetInfo.stylesheet.children;
|
|
|
- if (stylesheetInfo.mediaText && stylesheetInfo.mediaText != MEDIA_ALL) {
|
|
|
- processFontFaceRules(cssRules, sheetIndex, fontsDetails.medias.get("media-" + sheetIndex + "-" + stylesheetInfo.mediaText), stats);
|
|
|
- } else {
|
|
|
- processFontFaceRules(cssRules, sheetIndex, fontsDetails, stats);
|
|
|
+ const media = stylesheetInfo.mediaText;
|
|
|
+ if (cssRules) {
|
|
|
+ if (media && media != MEDIA_ALL) {
|
|
|
+ processFontFaceRules(cssRules, sheetIndex, fontsDetails.medias.get("media-" + sheetIndex + "-" + media), stats);
|
|
|
+ } else {
|
|
|
+ processFontFaceRules(cssRules, sheetIndex, fontsDetails, stats);
|
|
|
+ }
|
|
|
+ stats.rules.discarded -= cssRules.getSize();
|
|
|
}
|
|
|
- stats.rules.discarded -= cssRules.getSize();
|
|
|
sheetIndex++;
|
|
|
});
|
|
|
return stats;
|
|
|
@@ -99,26 +104,24 @@ this.fontsAltMinifier = this.fontsAltMinifier || (() => {
|
|
|
mediaFontsDetails.medias.set("media-" + sheetIndex + "-" + mediaIndex + "-" + mediaText, fontsDetails);
|
|
|
mediaIndex++;
|
|
|
getFontsDetails(doc, cssRule.block.children, sheetIndex, fontsDetails);
|
|
|
- } if (cssRule.type == "Atrule" && cssRule.name == "supports" && cssRule.block && cssRule.block.children && cssRule.prelude) {
|
|
|
+ } else if (cssRule.type == "Atrule" && cssRule.name == "supports" && cssRule.block && cssRule.block.children && cssRule.prelude) {
|
|
|
const supportsText = cssTree.generate(cssRule.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") {
|
|
|
- const fontKey = getFontKey(cssRule);
|
|
|
- let fontInfo = mediaFontsDetails.fonts.get(fontKey);
|
|
|
- if (!fontInfo) {
|
|
|
- fontInfo = [];
|
|
|
- mediaFontsDetails.fonts.set(fontKey, fontInfo);
|
|
|
- }
|
|
|
- const src = getPropertyValue(cssRule, "src");
|
|
|
- if (src) {
|
|
|
- const fontSources = src.match(REGEXP_URL_FUNCTION);
|
|
|
- if (fontSources) {
|
|
|
- fontSources.forEach(source => fontInfo.unshift(source));
|
|
|
- }
|
|
|
+ } else if (cssRule.type == "Atrule" && cssRule.name == "font-face" && cssRule.block && cssRule.block.children) {
|
|
|
+ const fontKey = getFontKey(cssRule);
|
|
|
+ let fontInfo = mediaFontsDetails.fonts.get(fontKey);
|
|
|
+ if (!fontInfo) {
|
|
|
+ fontInfo = [];
|
|
|
+ mediaFontsDetails.fonts.set(fontKey, fontInfo);
|
|
|
+ }
|
|
|
+ const src = getPropertyValue(cssRule, "src");
|
|
|
+ if (src) {
|
|
|
+ const fontSources = src.match(REGEXP_URL_FUNCTION);
|
|
|
+ if (fontSources) {
|
|
|
+ fontSources.forEach(source => fontInfo.unshift(source));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -222,7 +225,10 @@ this.fontsAltMinifier = this.fontsAltMinifier || (() => {
|
|
|
}
|
|
|
|
|
|
function getPropertyValue(cssRule, propertyName) {
|
|
|
- const property = cssRule.block.children.filter(node => node.property == propertyName).tail;
|
|
|
+ let property;
|
|
|
+ if (cssRule.block.children) {
|
|
|
+ property = cssRule.block.children.filter(node => node.property == propertyName).tail;
|
|
|
+ }
|
|
|
if (property) {
|
|
|
try {
|
|
|
return cssTree.generate(property.data.value);
|