|
|
@@ -1405,12 +1405,13 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
|
|
|
removedRules.forEach(cssRule => stylesheet.children.remove(cssRule));
|
|
|
}
|
|
|
|
|
|
- static async resolveImportURLs(stylesheetContent, baseURI, options, workStylesheet) {
|
|
|
+ static async resolveImportURLs(stylesheetContent, baseURI, options, workStylesheet, importedStyleSheets = new Set()) {
|
|
|
stylesheetContent = ProcessorHelper.resolveStylesheetURLs(stylesheetContent, baseURI);
|
|
|
const imports = Util.getImportFunctions(stylesheetContent);
|
|
|
await Promise.all(imports.map(async cssImport => {
|
|
|
const match = Util.matchImport(cssImport);
|
|
|
if (match) {
|
|
|
+ const regExpCssImport = Util.getRegExp(cssImport);
|
|
|
let resourceURL = Util.normalizeURL(match.resourceURL);
|
|
|
if (!Util.testIgnoredPath(resourceURL) && Util.testValidPath(resourceURL)) {
|
|
|
try {
|
|
|
@@ -1418,7 +1419,8 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
|
|
|
} catch (error) {
|
|
|
// ignored
|
|
|
}
|
|
|
- if (Util.testValidURL(resourceURL)) {
|
|
|
+ if (Util.testValidURL(resourceURL) && !importedStyleSheets.has(resourceURL)) {
|
|
|
+ importedStyleSheets.add(resourceURL);
|
|
|
const content = await util.getContent(resourceURL, {
|
|
|
maxResourceSize: options.maxResourceSize,
|
|
|
maxResourceSizeEnabled: options.maxResourceSizeEnabled,
|
|
|
@@ -1433,15 +1435,20 @@ this.singlefile.lib.core = this.singlefile.lib.core || (() => {
|
|
|
}
|
|
|
importedStylesheetContent = Util.wrapMediaQuery(importedStylesheetContent, match.media);
|
|
|
if (stylesheetContent.includes(cssImport)) {
|
|
|
- importedStylesheetContent = await ProcessorHelper.resolveImportURLs(importedStylesheetContent, resourceURL, options, workStylesheet);
|
|
|
+ importedStylesheetContent = await ProcessorHelper.resolveImportURLs(importedStylesheetContent, resourceURL, options, workStylesheet, importedStyleSheets);
|
|
|
workStylesheet.textContent = importedStylesheetContent;
|
|
|
if (workStylesheet.sheet.cssRules.length) {
|
|
|
- stylesheetContent = stylesheetContent.replace(Util.getRegExp(cssImport), importedStylesheetContent);
|
|
|
+ stylesheetContent = stylesheetContent.replace(regExpCssImport, importedStylesheetContent);
|
|
|
} else {
|
|
|
- stylesheetContent = stylesheetContent.replace(Util.getRegExp(cssImport), "");
|
|
|
+ stylesheetContent = stylesheetContent.replace(regExpCssImport, "");
|
|
|
}
|
|
|
}
|
|
|
+ } else {
|
|
|
+ importedStyleSheets.add(resourceURL);
|
|
|
+ stylesheetContent = stylesheetContent.replace(regExpCssImport, "");
|
|
|
}
|
|
|
+ } else {
|
|
|
+ stylesheetContent = stylesheetContent.replace(regExpCssImport, "");
|
|
|
}
|
|
|
}
|
|
|
}));
|