|
|
@@ -1301,26 +1301,31 @@ this.SingleFileCore = this.SingleFileCore || (() => {
|
|
|
let { content, indexResource, duplicate } = await batchRequest.addURL(resourceURL);
|
|
|
if (duplicate && options.groupDuplicateImages) {
|
|
|
const tokens = [];
|
|
|
- for (let token = declaration.value.children.head; token; token = token.next) {
|
|
|
- if (token.data.type == "Url" && DOM.removeQuotes(DomUtil.getCSSValue(token.data.value)) == originalResourceURL) {
|
|
|
- const value = cssTree.parse("var(" + SINGLE_FILE_VARIABLE_NAME_PREFIX + indexResource + ")", { context: "value" }).children.head;
|
|
|
- tokens.push({ token, value });
|
|
|
- }
|
|
|
- }
|
|
|
- tokens.forEach(({ token, value }) => declaration.value.children.replace(token, value));
|
|
|
+ findURLToken(originalResourceURL, declaration.value.children, (token, parent) => {
|
|
|
+ const value = cssTree.parse("var(" + SINGLE_FILE_VARIABLE_NAME_PREFIX + indexResource + ")", { context: "value" }).children.head;
|
|
|
+ tokens.push({ parent, token, value });
|
|
|
+ });
|
|
|
cssVariables.set(indexResource, content);
|
|
|
+ tokens.forEach(({ parent, token, value }) => parent.replace(token, value));
|
|
|
} else {
|
|
|
- declaration.value.children.forEach(token => {
|
|
|
- if (token.type == "Url" && DOM.removeQuotes(DomUtil.getCSSValue(token.value)) == originalResourceURL) {
|
|
|
- token.value.value = content;
|
|
|
- }
|
|
|
- });
|
|
|
+ findURLToken(originalResourceURL, declaration.value.children, token => token.data.value.value = content);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}));
|
|
|
}
|
|
|
}));
|
|
|
+
|
|
|
+ function findURLToken(url, children, callback) {
|
|
|
+ for (let token = children.head; token; token = token.next) {
|
|
|
+ if (token.data.children) {
|
|
|
+ findURLToken(url, token.data.children, callback);
|
|
|
+ }
|
|
|
+ if (token.data.type == "Url" && DOM.removeQuotes(DomUtil.getCSSValue(token.data.value)) == url) {
|
|
|
+ callback(token, children);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
static async processAttribute(doc, resourceElements, attributeName, prefixDataURI, baseURI, options, cssVariables, styles, batchRequest, processDuplicates, removeElementIfMissing) {
|