Преглед изворни кода

Add suport of URLs in CSS custom properties

Gildas пре 5 година
родитељ
комит
271938b87f
1 измењених фајлова са 10 додато и 2 уклоњено
  1. 10 2
      lib/single-file/single-file-core.js

+ 10 - 2
lib/single-file/single-file-core.js

@@ -1708,7 +1708,15 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
 
 		static async processStyle(declarations, baseURI, options, cssVariables, batchRequest) {
 			await Promise.all(declarations.map(async declaration => {
-				if (declaration.type == "Declaration" && declaration.value.children) {
+				let children = declaration.value.children;
+				if (!children && declaration.value && declaration.value.type == "Raw") {
+					try {
+						children = cssTree.parse(declaration.value.value, { context: "value" }).children;
+					} catch (error) {
+						// ignored
+					}
+				}
+				if (declaration.type == "Declaration" && children) {
 					const urlFunctions = getUrlFunctions(getCSSValue(declaration.value));
 					await Promise.all(urlFunctions.map(async urlFunction => {
 						const originalResourceURL = matchURL(urlFunction);
@@ -1718,7 +1726,7 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
 								let { content, indexResource, duplicate } = await batchRequest.addURL(resourceURL, true, "image", true);
 								let variableDefined;
 								const tokens = [];
-								findURLToken(originalResourceURL, declaration.value.children, (token, parent, rootFunction) => {
+								findURLToken(originalResourceURL, children, (token, parent, rootFunction) => {
 									if (!originalResourceURL.startsWith("#")) {
 										if (duplicate && options.groupDuplicateImages && rootFunction && util.getContentSize(content) < SINGLE_FILE_VARIABLE_MAX_SIZE) {
 											const value = cssTree.parse("var(" + SINGLE_FILE_VARIABLE_NAME_PREFIX + indexResource + ")", { context: "value" }).children.head;