Przeglądaj źródła

fixed possible naming conflict

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

+ 7 - 6
lib/single-file/single-file-core.js

@@ -613,7 +613,7 @@ this.SingleFileCore = this.SingleFileCore || (() => {
 		}
 
 		async inlineStylesheets(initialization) {
-			await Promise.all(Array.from(this.doc.querySelectorAll("style")).map(async styleElement => {
+			await Promise.all(Array.from(this.doc.querySelectorAll("style")).map(async (styleElement, indexStyle) => {
 				if (!initialization) {
 					this.stats.add("processed", "styleSheets", 1);
 				}
@@ -621,7 +621,7 @@ this.SingleFileCore = this.SingleFileCore || (() => {
 				if (initialization) {
 					stylesheetContent = await DomProcessorHelper.resolveImportURLs(styleElement.textContent, this.baseURI, { maxResourceSize: this.options.maxResourceSize, maxResourceSizeEnabled: this.options.maxResourceSizeEnabled });
 				} else {
-					stylesheetContent = await DomProcessorHelper.processStylesheet(styleElement.textContent, this.baseURI, this.options, false, this.batchRequest);
+					stylesheetContent = await DomProcessorHelper.processStylesheet(styleElement.textContent, this.baseURI, this.options, false, indexStyle, this.batchRequest);
 				}
 				styleElement.textContent = stylesheetContent;
 			}));
@@ -729,7 +729,7 @@ this.SingleFileCore = this.SingleFileCore || (() => {
 				if (initialization) {
 					stylesheetContent = DomProcessorHelper.resolveStylesheetURLs(stylesheetContent, this.baseURI);
 				} else {
-					stylesheetContent = await DomProcessorHelper.processStylesheet(element.getAttribute("style"), this.baseURI, this.options, true, this.batchRequest);
+					stylesheetContent = await DomProcessorHelper.processStylesheet(element.getAttribute("style"), this.baseURI, this.options, true, 0, this.batchRequest);
 				}
 				element.setAttribute("style", stylesheetContent);
 			}));
@@ -849,7 +849,7 @@ this.SingleFileCore = this.SingleFileCore || (() => {
 			}
 		}
 
-		static async processStylesheet(stylesheetContent, baseURI, options, inline, batchRequest) {
+		static async processStylesheet(stylesheetContent, baseURI, options, inline, indexStyle, batchRequest) {
 			stylesheetContent = DomProcessorHelper.resolveStylesheetURLs(stylesheetContent, baseURI);
 			const urlFunctions = DomUtil.getUrlFunctions(stylesheetContent);
 			let indexVariable = 0;
@@ -860,8 +860,9 @@ this.SingleFileCore = this.SingleFileCore || (() => {
 					const dataURI = await batchRequest.addURL(resourceURL);
 					const functions = stylesheetContent.match(DomUtil.getRegExp(urlFunction));
 					if (!inline && options.compressCSS && functions.length > 1) {
-						stylesheetContent = "--single-file-" + indexVariable + ":url(\"" + dataURI + "\")" + (indexVariable ? ";" : "}") + stylesheetContent;
-						stylesheetContent = stylesheetContent.replace(DomUtil.getRegExp(urlFunction), "var(--single-file-" + indexVariable + ")");
+						const variableName = "--single-file-" + indexStyle + "-" + indexVariable;
+						stylesheetContent = variableName + ":url(\"" + dataURI + "\")" + (indexVariable ? ";" : "}") + stylesheetContent;
+						stylesheetContent = stylesheetContent.replace(DomUtil.getRegExp(urlFunction), "var(" + variableName + ")");
 						indexVariable++;
 					} else {
 						stylesheetContent = stylesheetContent.replace(DomUtil.getRegExp(urlFunction), urlFunction.replace(originalResourceURL, dataURI));