Przeglądaj źródła

minor refactoring

Gildas 7 lat temu
rodzic
commit
4756d8c877
1 zmienionych plików z 11 dodań i 11 usunięć
  1. 11 11
      lib/single-file/single-file-core.js

+ 11 - 11
lib/single-file/single-file-core.js

@@ -1073,18 +1073,18 @@ this.SingleFileCore = this.SingleFileCore || (() => {
 
 		static async processStylesheet(doc, stylesheetContent, cssRules, baseURI, options, batchRequest) {
 			const urlFunctions = getURLFunctions(cssRules);
-			const styleResources = Promise.all(urlFunctions.style.map(urlFunction => processURLFunction(urlFunction)));
-			const otherResources = Promise.all(urlFunctions.other.map(urlFunction => processURLFunction(urlFunction, true)));
-			await Promise.all([styleResources, otherResources]);
+			await Promise.all([
+				Promise.all(urlFunctions.style.map(urlFunction => processURLFunction(urlFunction))),
+				Promise.all(urlFunctions.font.map(urlFunction => processURLFunction(urlFunction, true)))]);
 			return stylesheetContent;
 
-			async function processURLFunction(urlFunction, processFont) {
+			async function processURLFunction(urlFunction, isFont) {
 				const originalResourceURL = DomUtil.matchURL(urlFunction);
 				const resourceURL = DomUtil.normalizeURL(originalResourceURL);
 				if (!DomUtil.testIgnoredPath(resourceURL)) {
 					if (DomUtil.testValidURL(resourceURL, baseURI, options.url)) {
 						let { content, indexResource, duplicate } = await batchRequest.addURL(resourceURL);
-						const validResource = !processFont || content == EMPTY_DATA_URI || content.startsWith(PREFIX_DATA_URI_VND) || content.startsWith(PREFIX_DATA_URI_IMAGE_SVG) || await DOM.validFont(urlFunction);
+						const validResource = !isFont || content == EMPTY_DATA_URI || content.startsWith(PREFIX_DATA_URI_VND) || content.startsWith(PREFIX_DATA_URI_IMAGE_SVG) || await DOM.validFont(urlFunction);
 						if (!validResource) {
 							content = EMPTY_DATA_URI;
 						}
@@ -1098,7 +1098,7 @@ this.SingleFileCore = this.SingleFileCore || (() => {
 							regExpUrlFunction = DomUtil.getRegExp(urlFunction);
 						}
 						if (stylesheetContent.match(regExpUrlFunction)) {
-							if (duplicate && options.groupDuplicateImages && !processFont) {
+							if (duplicate && options.groupDuplicateImages && !isFont) {
 								stylesheetContent = stylesheetContent.replace(regExpUrlFunction, "var(" + SINGLE_FILE_VARIABLE_NAME_PREFIX + indexResource + ")");
 								DomUtil.insertVariable(doc, indexResource, content, options);
 							} else {
@@ -1109,17 +1109,17 @@ this.SingleFileCore = this.SingleFileCore || (() => {
 				}
 			}
 
-			function getURLFunctions(cssRules, urlFunctions = { style: [], other: [] }) {
+			function getURLFunctions(cssRules, urlFunctions = { style: [], font: [] }) {
 				Array.from(cssRules).forEach(cssRule => {
 					if (cssRule.type == CSSRule.MEDIA_RULE) {
 						getURLFunctions(cssRule.cssRules, urlFunctions);
-					} else if (cssRule.type == CSSRule.STYLE_RULE) {
-						getURLFunctionsRule(cssRule.cssText, urlFunctions.style);
+					} else if (cssRule.type == CSSRule.FONT_FACE_RULE) {
+						getURLFunctionsRule(cssRule.cssText, urlFunctions.font);
 					} else {
-						getURLFunctionsRule(cssRule.cssText, urlFunctions.other);
+						getURLFunctionsRule(cssRule.cssText, urlFunctions.style);
 					}
 				});
-				return { style: Array.from(urlFunctions.style), other: Array.from(urlFunctions.other) };
+				return { style: Array.from(urlFunctions.style), font: Array.from(urlFunctions.font) };
 			}
 
 			function getURLFunctionsRule(cssText, urlFunctions) {