|
|
@@ -193,7 +193,7 @@ const SingleFileCore = (() => {
|
|
|
beforeListener({ index: indexResource, max: resourceURLs.length, url: resourceURL, error });
|
|
|
indexResource = indexResource + 1;
|
|
|
try {
|
|
|
- const dataURI = await Download.getContent(resourceURL, { asDataURI: true, maxSize: options.maxResourceSize });
|
|
|
+ const dataURI = await Download.getContent(resourceURL, { asDataURI: true, maxResourceSize: options.maxResourceSize, maxResourceSizeEnabled: options.maxResourceSizeEnabled });
|
|
|
resourceRequests.map(resourceRequest => resourceRequest.resolve(dataURI));
|
|
|
} catch (responseError) {
|
|
|
error = responseError;
|
|
|
@@ -222,7 +222,7 @@ const SingleFileCore = (() => {
|
|
|
|
|
|
async loadPage(pageContent) {
|
|
|
if (!pageContent || this.options.saveRawPage) {
|
|
|
- pageContent = await Download.getContent(this.baseURI, { asDataURI: false, maxSize: this.options.maxResourceSize });
|
|
|
+ pageContent = await Download.getContent(this.baseURI, { asDataURI: false, maxResourceSize: this.options.maxResourceSize, maxResourceSizeEnabled: this.options.maxResourceSizeEnabled });
|
|
|
}
|
|
|
this.dom = DOM.create(pageContent, this.baseURI);
|
|
|
this.DOMParser = this.dom.DOMParser;
|
|
|
@@ -471,7 +471,7 @@ const SingleFileCore = (() => {
|
|
|
|
|
|
async inlineStylesheets(initialization) {
|
|
|
await Promise.all(Array.from(this.doc.querySelectorAll("style")).map(async styleElement => {
|
|
|
- const stylesheetContent = initialization ? await DomProcessorHelper.resolveImportURLs(styleElement.textContent, this.baseURI, this.options.maxResourceSize) : await DomProcessorHelper.processStylesheet(styleElement.textContent, this.baseURI);
|
|
|
+ const stylesheetContent = initialization ? await DomProcessorHelper.resolveImportURLs(styleElement.textContent, this.baseURI, { maxResourceSize: this.options.maxResourceSize, maxResourceSizeEnabled: this.options.maxResourceSizeEnabled }) : await DomProcessorHelper.processStylesheet(styleElement.textContent, this.baseURI);
|
|
|
styleElement.textContent = this.options.compressCSS ? this.dom.uglifycss(stylesheetContent) : stylesheetContent;
|
|
|
}));
|
|
|
}
|
|
|
@@ -479,7 +479,7 @@ const SingleFileCore = (() => {
|
|
|
async scripts() {
|
|
|
await Promise.all(Array.from(this.doc.querySelectorAll("script[src]")).map(async scriptElement => {
|
|
|
if (scriptElement.src) {
|
|
|
- const scriptContent = await Download.getContent(scriptElement.src, { asDataURI: false, maxSize: this.options.maxResourceSize });
|
|
|
+ const scriptContent = await Download.getContent(scriptElement.src, { asDataURI: false, maxResourceSize: this.options.maxResourceSize, maxResourceSizeEnabled: this.options.maxResourceSizeEnabled });
|
|
|
scriptElement.textContent = scriptContent.replace(/<\/script>/gi, "<\\/script>");
|
|
|
}
|
|
|
scriptElement.removeAttribute("src");
|
|
|
@@ -508,7 +508,8 @@ const SingleFileCore = (() => {
|
|
|
compressCSS: this.options.compressCSS,
|
|
|
lazyLoadImages: this.options.lazyLoadImages,
|
|
|
framesData: this.options.framesData,
|
|
|
- maxResourceSize: this.options.maxResourceSize
|
|
|
+ maxResourceSize: this.options.maxResourceSize,
|
|
|
+ maxResourceSizeEnabled: this.options.maxResourceSizeEnabled
|
|
|
};
|
|
|
if (frameData.content) {
|
|
|
frameData.processor = new PageProcessor(options);
|
|
|
@@ -575,14 +576,14 @@ const SingleFileCore = (() => {
|
|
|
|
|
|
async attributeStyles(initialization) {
|
|
|
await Promise.all(Array.from(this.doc.querySelectorAll("[style]")).map(async element => {
|
|
|
- const stylesheetContent = initialization ? await DomProcessorHelper.resolveImportURLs(element.getAttribute("style"), this.baseURI, this.options.maxResourceSize) : await DomProcessorHelper.processStylesheet(element.getAttribute("style"), this.baseURI);
|
|
|
+ const stylesheetContent = initialization ? await DomProcessorHelper.resolveImportURLs(element.getAttribute("style"), this.baseURI, { maxResourceSize: this.options.maxResourceSize, maxResourceSizeEnabled: this.options.maxResourceSizeEnabled }) : await DomProcessorHelper.processStylesheet(element.getAttribute("style"), this.baseURI);
|
|
|
element.setAttribute("style", stylesheetContent);
|
|
|
}));
|
|
|
}
|
|
|
|
|
|
async linkStylesheets() {
|
|
|
await Promise.all(Array.from(this.doc.querySelectorAll("link[rel*=stylesheet]")).map(async linkElement => {
|
|
|
- const stylesheetContent = await DomProcessorHelper.resolveLinkStylesheetURLs(linkElement.href, this.baseURI, linkElement.media, this.options.maxResourceSize);
|
|
|
+ const stylesheetContent = await DomProcessorHelper.resolveLinkStylesheetURLs(linkElement.href, this.baseURI, linkElement.media, { maxResourceSize: this.options.maxResourceSize, maxResourceSizeEnabled: this.options.maxResourceSizeEnabled });
|
|
|
const styleElement = this.doc.createElement("style");
|
|
|
styleElement.textContent = this.options.compressCSS ? this.dom.uglifycss(stylesheetContent) : stylesheetContent;
|
|
|
linkElement.parentElement.replaceChild(styleElement, linkElement);
|
|
|
@@ -611,7 +612,7 @@ const SingleFileCore = (() => {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- static async resolveImportURLs(stylesheetContent, baseURI, maxResourceSize) {
|
|
|
+ static async resolveImportURLs(stylesheetContent, baseURI, options) {
|
|
|
stylesheetContent = DomUtil.removeCssComments(stylesheetContent);
|
|
|
const imports = DomUtil.getImportFunctions(stylesheetContent);
|
|
|
await Promise.all(imports.map(async cssImport => {
|
|
|
@@ -619,7 +620,7 @@ const SingleFileCore = (() => {
|
|
|
if (match) {
|
|
|
const resourceURL = DomUtil.normalizeURL(match.resourceURL);
|
|
|
if (resourceURL != baseURI && resourceURL != ABOUT_BLANK_URI) {
|
|
|
- let importedStylesheetContent = await Download.getContent(new URL(match.resourceURL, baseURI).href, { asDataURI: false, maxSize: maxResourceSize });
|
|
|
+ let importedStylesheetContent = await Download.getContent(new URL(match.resourceURL, baseURI).href, { asDataURI: false, maxResourceSize: options.maxResourceSize, maxResourceSizeEnabled: options.maxResourceSizeEnabled });
|
|
|
importedStylesheetContent = DomUtil.wrapMediaQuery(importedStylesheetContent, match.media);
|
|
|
if (stylesheetContent.indexOf(cssImport) != -1) {
|
|
|
stylesheetContent = stylesheetContent.replace(cssImport, importedStylesheetContent);
|
|
|
@@ -629,7 +630,7 @@ const SingleFileCore = (() => {
|
|
|
}));
|
|
|
stylesheetContent = DomProcessorHelper.resolveStylesheetURLs(stylesheetContent, baseURI);
|
|
|
if (imports.length) {
|
|
|
- return await DomProcessorHelper.resolveImportURLs(stylesheetContent, baseURI, maxResourceSize);
|
|
|
+ return await DomProcessorHelper.resolveImportURLs(stylesheetContent, baseURI, options);
|
|
|
} else {
|
|
|
return stylesheetContent;
|
|
|
}
|
|
|
@@ -647,11 +648,11 @@ const SingleFileCore = (() => {
|
|
|
return stylesheetContent;
|
|
|
}
|
|
|
|
|
|
- static async resolveLinkStylesheetURLs(resourceURL, baseURI, media, maxResourceSize) {
|
|
|
+ static async resolveLinkStylesheetURLs(resourceURL, baseURI, media, options) {
|
|
|
resourceURL = DomUtil.normalizeURL(resourceURL);
|
|
|
if (resourceURL && resourceURL != baseURI && resourceURL != ABOUT_BLANK_URI) {
|
|
|
- let stylesheetContent = await Download.getContent(resourceURL, { asDataURI: false, maxSize: maxResourceSize });
|
|
|
- stylesheetContent = await DomProcessorHelper.resolveImportURLs(stylesheetContent, resourceURL, maxResourceSize);
|
|
|
+ let stylesheetContent = await Download.getContent(resourceURL, { asDataURI: false, maxResourceSize: options.maxResourceSize, maxResourceSizeEnabled: options.maxResourceSizeEnabled });
|
|
|
+ stylesheetContent = await DomProcessorHelper.resolveImportURLs(stylesheetContent, resourceURL, options);
|
|
|
stylesheetContent = DomUtil.wrapMediaQuery(stylesheetContent, media);
|
|
|
return stylesheetContent;
|
|
|
}
|