Procházet zdrojové kódy

insert the style element used for variables before the first one found

Gildas před 7 roky
rodič
revize
f74163199c
1 změnil soubory, kde provedl 8 přidání a 3 odebrání
  1. 8 3
      lib/single-file/single-file-core.js

+ 8 - 3
lib/single-file/single-file-core.js

@@ -806,10 +806,15 @@ this.SingleFileCore = this.SingleFileCore || (() => {
 		insertVariables() {
 			if (this.cssVariables.size) {
 				const styleElement = this.doc.createElement("style");
-				if (this.doc.head.firstChild) {
-					this.doc.head.insertBefore(styleElement, this.doc.head.firstChild);
+				const firstStyleElement = this.doc.head.querySelector("style");
+				if (firstStyleElement) {
+					this.doc.head.insertBefore(styleElement, firstStyleElement);
 				} else {
-					this.doc.head.appendChild(styleElement);
+					if (this.doc.head.firstChild) {
+						this.doc.head.insertBefore(styleElement, this.doc.head.firstChild);
+					} else {
+						this.doc.head.appendChild(styleElement);
+					}
 				}
 				let stylesheetContent = "";
 				this.cssVariables.forEach((content, indexResource) => {