|
@@ -81,7 +81,7 @@ this.docHelper = this.docHelper || (() => {
|
|
|
elementsInfo = new Map(Array.from(elementsInfo).filter(([element]) => element.getAttribute(markerRemovedContent) != ""));
|
|
elementsInfo = new Map(Array.from(elementsInfo).filter(([element]) => element.getAttribute(markerRemovedContent) != ""));
|
|
|
}
|
|
}
|
|
|
if (options.removeUnusedStyles) {
|
|
if (options.removeUnusedStyles) {
|
|
|
- usedFonts = getUsedFonts(elementsInfo);
|
|
|
|
|
|
|
+ usedFonts = getUsedFonts(elementsInfo, Array.from(doc.fonts));
|
|
|
}
|
|
}
|
|
|
if (options.compressHTML) {
|
|
if (options.compressHTML) {
|
|
|
elementsInfo.forEach((elementInfo, element) => {
|
|
elementsInfo.forEach((elementInfo, element) => {
|
|
@@ -116,19 +116,19 @@ this.docHelper = this.docHelper || (() => {
|
|
|
};
|
|
};
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- function getUsedFonts(styles) {
|
|
|
|
|
|
|
+ function getUsedFonts(styles, loadedFonts) {
|
|
|
const usedFonts = new Set();
|
|
const usedFonts = new Set();
|
|
|
styles.forEach(style => {
|
|
styles.forEach(style => {
|
|
|
const fontFamilyNames = style.fontFamily.split(",");
|
|
const fontFamilyNames = style.fontFamily.split(",");
|
|
|
fontFamilyNames.forEach(fontFamilyName => {
|
|
fontFamilyNames.forEach(fontFamilyName => {
|
|
|
- style.fontFamily = removeQuotes(fontFamilyName).toLowerCase().trim();
|
|
|
|
|
- usedFonts.add(getFontKey(style));
|
|
|
|
|
|
|
+ fontFamilyName = removeQuotes(fontFamilyName.trim()).toLowerCase();
|
|
|
|
|
+ if (loadedFonts.find(font => font.family.toLowerCase() == fontFamilyName && font.style == style.fontStyle && font.weight == style.fontWeight && font.weight == style.fontWeight && font.variant == style.fontVariant)) {
|
|
|
|
|
+ const { fontWeight, fontStyle, fontVariant } = style;
|
|
|
|
|
+ usedFonts.add([fontFamilyName, fontWeight, fontStyle, fontVariant]);
|
|
|
|
|
+ }
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
- return Array.from(usedFonts).map(key => {
|
|
|
|
|
- const [fontFamily, fontWeight, fontStyle, fontVariant] = JSON.parse(key);
|
|
|
|
|
- return { fontFamily, fontWeight, fontStyle, fontVariant };
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ return Array.from(usedFonts);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function getElementsInfo(win, element, elementsInfo = new Map()) {
|
|
function getElementsInfo(win, element, elementsInfo = new Map()) {
|