1
0
Эх сурвалжийг харах

compute custom properties used as font names

Former-commit-id: 01568cd56324095409b92daa12a669e6e9184ec2
Gildas 6 жил өмнө
parent
commit
bb10e17007

+ 14 - 0
lib/single-file/modules/css-fonts-minifier.js

@@ -21,10 +21,14 @@
  *   Source.
  */
 
+/* global window */
+
 this.singlefile.lib.modules.fontsMinifier = this.singlefile.lib.modules.fontsMinifier || (() => {
 
 	const singlefile = this.singlefile;
 
+	const getComputedStyle = window.getComputedStyle;
+
 	const REGEXP_COMMA = /\s*,\s*/;
 	const REGEXP_DASH = /-/;
 	const REGEXP_QUESTION_MARK = /\?/g;
@@ -63,6 +67,16 @@ this.singlefile.lib.modules.fontsMinifier = this.singlefile.lib.modules.fontsMin
 			});
 			workStyleElement.remove();
 			docContent += doc.body.innerText;
+			if (getComputedStyle) {
+				fontsInfo.used = fontsInfo.used.map(fontNames => fontNames.map(fontName => {
+					const matchedVar = fontName.match(/^var\((--.*)\)$/);
+					if (matchedVar && matchedVar[1]) {
+						const computedFontName = getComputedStyle.call(window, options.doc.body).getPropertyValue(matchedVar[1]);
+						return computedFontName || fontName;
+					}
+					return fontName;
+				}));
+			}
 			const variableFound = fontsInfo.used.find(fontNames => fontNames.find(fontName => fontName.startsWith("var(--")));
 			let unusedFonts, filteredUsedFonts;
 			if (variableFound) {