|
|
@@ -35,6 +35,23 @@ const SingleFileCore = (() => {
|
|
|
};
|
|
|
}
|
|
|
|
|
|
+ // -------------
|
|
|
+ // ProgressEvent
|
|
|
+ // -------------
|
|
|
+ const PAGE_LOADING = "page-loading";
|
|
|
+ const PAGE_LOADED = "page-loaded";
|
|
|
+ const RESOURCES_INITIALIZING = "resource-initializing";
|
|
|
+ const RESOURCES_INITIALIZED = "resources-initialized";
|
|
|
+ const RESOURCE_LOADING = "resource-loading";
|
|
|
+ const RESOURCE_LOADED = "resource-loaded";
|
|
|
+ const PAGE_ENDED = "page-ended";
|
|
|
+
|
|
|
+ class ProgressEvent {
|
|
|
+ constructor(type, details) {
|
|
|
+ return { type, details, PAGE_LOADING, PAGE_LOADED, RESOURCES_INITIALIZING, RESOURCES_INITIALIZED, RESOURCE_LOADING, RESOURCE_LOADED, PAGE_ENDED };
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// -------------
|
|
|
// PageProcessor
|
|
|
// -------------
|
|
|
@@ -46,17 +63,17 @@ const SingleFileCore = (() => {
|
|
|
|
|
|
async loadPage(pageContent) {
|
|
|
if (this.onprogress) {
|
|
|
- this.onprogress({ type: "page-loading", details: { pageURL: this.options.url } });
|
|
|
+ this.onprogress(new ProgressEvent(PAGE_LOADING, { pageURL: this.options.url }));
|
|
|
}
|
|
|
await this.processor.loadPage(pageContent);
|
|
|
if (this.onprogress) {
|
|
|
- this.onprogress({ type: "page-loaded", details: { pageURL: this.options.url } });
|
|
|
+ this.onprogress(new ProgressEvent(PAGE_LOADED, { pageURL: this.options.url }));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
async initialize() {
|
|
|
if (this.onprogress) {
|
|
|
- this.onprogress({ type: "resources-initializing", details: { pageURL: this.options.url } });
|
|
|
+ this.onprogress(new ProgressEvent(RESOURCES_INITIALIZING, { pageURL: this.options.url }));
|
|
|
}
|
|
|
if (!this.options.jsEnabled) {
|
|
|
this.processor.insertNoscriptContents();
|
|
|
@@ -75,7 +92,7 @@ const SingleFileCore = (() => {
|
|
|
await Promise.all([this.processor.inlineStylesheets(true), this.processor.linkStylesheets()], this.processor.attributeStyles(true));
|
|
|
this.pendingPromises = Promise.all([this.processor.inlineStylesheets(), this.processor.attributeStyles(), this.processor.pageResources()]);
|
|
|
if (this.onprogress) {
|
|
|
- this.onprogress({ type: "resources-initialized", details: { pageURL: this.options.url, index: 0, max: batchRequest.getMaxResources() } });
|
|
|
+ this.onprogress(new ProgressEvent(RESOURCES_INITIALIZED, { pageURL: this.options.url, index: 0, max: batchRequest.getMaxResources() }));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -84,13 +101,13 @@ const SingleFileCore = (() => {
|
|
|
details => {
|
|
|
if (this.onprogress) {
|
|
|
details.pageURL = this.options.url;
|
|
|
- this.onprogress({ type: "resource-loading", details });
|
|
|
+ this.onprogress(new ProgressEvent(RESOURCE_LOADING, details));
|
|
|
}
|
|
|
},
|
|
|
details => {
|
|
|
if (this.onprogress) {
|
|
|
details.pageURL = this.options.url;
|
|
|
- this.onprogress({ type: "resource-loaded", details });
|
|
|
+ this.onprogress(new ProgressEvent(RESOURCE_LOADED, details));
|
|
|
}
|
|
|
});
|
|
|
await this.pendingPromises;
|
|
|
@@ -98,7 +115,7 @@ const SingleFileCore = (() => {
|
|
|
this.processor.removeUnusedCSSRules();
|
|
|
}
|
|
|
if (this.onprogress) {
|
|
|
- this.onprogress({ type: "page-ended", details: { pageURL: this.options.url } });
|
|
|
+ this.onprogress(new ProgressEvent(PAGE_ENDED, { pageURL: this.options.url }));
|
|
|
}
|
|
|
return this.processor.getContent();
|
|
|
}
|