فهرست منبع

filter duplicate used fonts

Former-commit-id: 43cc0c107eb2543560d1f575df0e2463fe97b80b
Gildas 6 سال پیش
والد
کامیت
375e99ea67
1فایلهای تغییر یافته به همراه4 افزوده شده و 3 حذف شده
  1. 4 3
      lib/single-file/single-file-helper.js

+ 4 - 3
lib/single-file/single-file-helper.js

@@ -102,14 +102,14 @@ this.singlefile.lib.helper = this.singlefile.lib.helper || (() => {
 			stylesheets: getStylesheetsData(doc),
 			images: elementsInfo.images,
 			posters: elementsInfo.posters,
-			usedFonts: Array.from(elementsInfo.usedFonts),
+			usedFonts: Array.from(elementsInfo.usedFonts.values()),
 			shadowRoots: elementsInfo.shadowRoots,
 			imports: elementsInfo.imports,
 			referrer: doc.referrer
 		};
 	}
 
-	function getElementsInfo(win, doc, element, options, data = { usedFonts: new Set(), canvases: [], images: [], posters: [], shadowRoots: [], imports: [] }, ascendantHidden) {
+	function getElementsInfo(win, doc, element, options, data = { usedFonts: new Map(), canvases: [], images: [], posters: [], shadowRoots: [], imports: [] }, ascendantHidden) {
 		const elements = Array.from(element.childNodes).filter(node => node instanceof win.HTMLElement);
 		elements.forEach(element => {
 			let elementHidden, computedStyle;
@@ -226,7 +226,8 @@ this.singlefile.lib.helper = this.singlefile.lib.helper || (() => {
 				if (!options.loadedFonts || options.loadedFonts.find(font => normalizeFontFamily(font.family) == fontFamilyName && font.style == fontStyle)) {
 					const fontWeight = getFontWeight(computedStyle.getPropertyValue("font-weight"));
 					const fontVariant = computedStyle.getPropertyValue("font-variant") || "normal";
-					usedFonts.add([fontFamilyName, fontWeight, fontStyle, fontVariant]);
+					const value = [fontFamilyName, fontWeight, fontStyle, fontVariant];
+					usedFonts.set(JSON.stringify(value), [fontFamilyName, fontWeight, fontStyle, fontVariant]);
 				}
 			});
 		}