single-file-core 1.3.32 → 1.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/core/index.js +2 -8
- package/modules/template-formatter.js +9 -2
- package/package.json +1 -1
- package/single-file.js +4 -2
package/core/index.js
CHANGED
|
@@ -86,12 +86,10 @@ const RESOURCE_LOADED = "resource-loaded";
|
|
|
86
86
|
const PAGE_ENDED = "page-ended";
|
|
87
87
|
const STAGE_STARTED = "stage-started";
|
|
88
88
|
const STAGE_ENDED = "stage-ended";
|
|
89
|
-
const STAGE_TASK_STARTED = "stage-task-started";
|
|
90
|
-
const STAGE_TASK_ENDED = "stage-task-ended";
|
|
91
89
|
|
|
92
90
|
class ProgressEvent {
|
|
93
91
|
constructor(type, detail) {
|
|
94
|
-
return { type, detail, PAGE_LOADING, PAGE_LOADED, RESOURCES_INITIALIZING, RESOURCES_INITIALIZED, RESOURCE_LOADED, PAGE_ENDED, STAGE_STARTED, STAGE_ENDED
|
|
92
|
+
return { type, detail, PAGE_LOADING, PAGE_LOADED, RESOURCES_INITIALIZING, RESOURCES_INITIALIZED, RESOURCE_LOADED, PAGE_ENDED, STAGE_STARTED, STAGE_ENDED };
|
|
95
93
|
}
|
|
96
94
|
}
|
|
97
95
|
|
|
@@ -268,7 +266,7 @@ class Runner {
|
|
|
268
266
|
|
|
269
267
|
async getPageData() {
|
|
270
268
|
if (this.root) {
|
|
271
|
-
await this.onprogress(new ProgressEvent(PAGE_ENDED, { pageURL: this.options.url, options: this.options
|
|
269
|
+
await this.onprogress(new ProgressEvent(PAGE_ENDED, { pageURL: this.options.url, options: this.options }));
|
|
272
270
|
}
|
|
273
271
|
return this.processor.getPageData();
|
|
274
272
|
}
|
|
@@ -285,11 +283,9 @@ class Runner {
|
|
|
285
283
|
startTime = Date.now();
|
|
286
284
|
log(" -- STARTED task =", task.action);
|
|
287
285
|
}
|
|
288
|
-
await this.onprogress(new ProgressEvent(STAGE_TASK_STARTED, { pageURL: this.options.url, step, task: task.action, frame, options: this.options }));
|
|
289
286
|
if (!this.cancelled) {
|
|
290
287
|
this.executeTask(task);
|
|
291
288
|
}
|
|
292
|
-
await this.onprogress(new ProgressEvent(STAGE_TASK_ENDED, { pageURL: this.options.url, step, task: task.action, frame, options: this.options }));
|
|
293
289
|
if (DEBUG) {
|
|
294
290
|
log(" -- ENDED task =", task.action, "delay =", Date.now() - startTime);
|
|
295
291
|
}
|
|
@@ -302,11 +298,9 @@ class Runner {
|
|
|
302
298
|
startTime = Date.now();
|
|
303
299
|
log(" // STARTED task =", task.action);
|
|
304
300
|
}
|
|
305
|
-
await this.onprogress(new ProgressEvent(STAGE_TASK_STARTED, { pageURL: this.options.url, step, task: task.action, frame, options: this.options }));
|
|
306
301
|
if (!this.cancelled) {
|
|
307
302
|
await this.executeTask(task);
|
|
308
303
|
}
|
|
309
|
-
await this.onprogress(new ProgressEvent(STAGE_TASK_ENDED, { pageURL: this.options.url, step, task: task.action, frame, options: this.options }));
|
|
310
304
|
if (DEBUG) {
|
|
311
305
|
log(" // ENDED task =", task.action, "delay =", Date.now() - startTime);
|
|
312
306
|
}
|
|
@@ -17014,8 +17014,14 @@ async function evalTemplate(template = "", options, content, doc, dontReplaceSla
|
|
|
17014
17014
|
"encode-uri": value => { try { return encodeURI(value); } catch (error) { return value; } },
|
|
17015
17015
|
"decode-uri": value => { try { return decodeURI(value); } catch (error) { return value; } },
|
|
17016
17016
|
"encode-uri-component": value => { try { return encodeURIComponent(value); } catch (error) { return value; } },
|
|
17017
|
-
"decode-uri-component": value => { try { return decodeURIComponent(value); } catch (error) { return value; } }
|
|
17017
|
+
"decode-uri-component": value => { try { return decodeURIComponent(value); } catch (error) { return value; } },
|
|
17018
|
+
"date-locale": locales => new Date().toLocaleDateString(locales),
|
|
17019
|
+
"time-locale": locales => new Date().toLocaleTimeString(locales),
|
|
17020
|
+
"datetime-locale": locales => new Date().toLocaleString(locales)
|
|
17018
17021
|
};
|
|
17022
|
+
functions["date-locale"].dontReplaceSlash = false;
|
|
17023
|
+
functions["time-locale"].dontReplaceSlash = false;
|
|
17024
|
+
functions["datetime-locale"].dontReplaceSlash = false;
|
|
17019
17025
|
if (doc) {
|
|
17020
17026
|
functions["page-element-text"] = (selector) => {
|
|
17021
17027
|
const element = doc.querySelector(selector);
|
|
@@ -17043,7 +17049,8 @@ async function evalTemplate(template = "", options, content, doc, dontReplaceSla
|
|
|
17043
17049
|
.filter(argument => argument != undefined && argument != null && argument != "");
|
|
17044
17050
|
if ((argument != undefined && argument != null && argument != "") || optionalArguments.length > 0) {
|
|
17045
17051
|
try {
|
|
17046
|
-
|
|
17052
|
+
const dontReplaceSlash = fn.dontReplaceSlash === undefined ? true : fn.dontReplaceSlash;
|
|
17053
|
+
return await getValue(() => fn(argument, ...optionalArguments), dontReplaceSlash, options.filenameReplacementCharacter, lengthData);
|
|
17047
17054
|
} catch (error) {
|
|
17048
17055
|
return "";
|
|
17049
17056
|
}
|
package/package.json
CHANGED
package/single-file.js
CHANGED
|
@@ -90,12 +90,14 @@ async function getPageData(options = {}, initOptions, doc = globalThis.document,
|
|
|
90
90
|
options.insertCanonicalLink = true;
|
|
91
91
|
|
|
92
92
|
const externalOnProgress = options.onprogress;
|
|
93
|
-
options.onprogress = event => {
|
|
93
|
+
options.onprogress = async event => {
|
|
94
94
|
if (event.type === event.RESOURCES_INITIALIZED && doc && win && options.loadDeferredImages) {
|
|
95
95
|
processors.lazy.resetZoomLevel(options);
|
|
96
96
|
}
|
|
97
97
|
|
|
98
|
-
if (externalOnProgress)
|
|
98
|
+
if (externalOnProgress) {
|
|
99
|
+
await externalOnProgress(event);
|
|
100
|
+
}
|
|
99
101
|
};
|
|
100
102
|
|
|
101
103
|
const processor = new SingleFile(options);
|