image-exporter 1.0.2 → 1.0.3
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/README.md +1 -1
- package/dist/image-exporter.es.js +20 -7
- package/dist/image-exporter.umd.js +20 -7
- package/package.json +1 -1
- package/src/capture/capture-element.ts +0 -2
- package/src/capture/index.ts +9 -6
- package/src/logger.ts +11 -1
package/README.md
CHANGED
|
@@ -50,7 +50,7 @@ import { capture } from "image-exporter";
|
|
|
50
50
|
/** Default label for images. Does not include file extension or scale. */
|
|
51
51
|
defaultImageLabel: string;
|
|
52
52
|
/** Label for zip file. Does not include file extension or scale. */
|
|
53
|
-
zipLabel:
|
|
53
|
+
zipLabel: string;
|
|
54
54
|
/** Base URL for CORS proxy used when fetching external images. */
|
|
55
55
|
corsProxyBaseUrl: string;
|
|
56
56
|
/** Enable window logging for use by external scripts */
|
|
@@ -3338,7 +3338,11 @@ const log = {
|
|
|
3338
3338
|
info: (...messages) => logAction(messages, "info"),
|
|
3339
3339
|
error: (...messages) => logAction(messages, "error"),
|
|
3340
3340
|
verbose: (...messages) => logAction(messages, "verbose"),
|
|
3341
|
-
progress: (progress, total) => logProgress(progress, total)
|
|
3341
|
+
progress: (progress, total) => logProgress(progress, total),
|
|
3342
|
+
group: {
|
|
3343
|
+
open: (...messages) => logAction(messages, "group"),
|
|
3344
|
+
close: (...messages) => logAction(messages, "groupEnd")
|
|
3345
|
+
}
|
|
3342
3346
|
};
|
|
3343
3347
|
async function logAction(messages, type = "info") {
|
|
3344
3348
|
const combinedMessage = messages.map((msg) => typeof msg === "object" ? JSON.stringify(msg) : msg).join(" ");
|
|
@@ -3358,6 +3362,12 @@ async function logAction(messages, type = "info") {
|
|
|
3358
3362
|
console.log(...messages);
|
|
3359
3363
|
}
|
|
3360
3364
|
break;
|
|
3365
|
+
case "group":
|
|
3366
|
+
console.group(...messages);
|
|
3367
|
+
break;
|
|
3368
|
+
case "groupEnd":
|
|
3369
|
+
console.groupEnd();
|
|
3370
|
+
break;
|
|
3361
3371
|
}
|
|
3362
3372
|
if (windowLogging) window.imageExporterLogs.push({ message: combinedMessage, type });
|
|
3363
3373
|
}
|
|
@@ -3638,6 +3648,7 @@ async function determineTotalElements(elements) {
|
|
|
3638
3648
|
let windowLogging = true;
|
|
3639
3649
|
let loggingLevel = "none";
|
|
3640
3650
|
async function capture(elements, userConfig = defaultConfig) {
|
|
3651
|
+
log.group.open("image-exporter");
|
|
3641
3652
|
try {
|
|
3642
3653
|
const config = { ...defaultConfig, ...userConfig };
|
|
3643
3654
|
windowLogging = config.enableWindowLogging;
|
|
@@ -3649,19 +3660,19 @@ async function capture(elements, userConfig = defaultConfig) {
|
|
|
3649
3660
|
const totalElements = await determineTotalElements(elements);
|
|
3650
3661
|
if (originalLength !== elements.length)
|
|
3651
3662
|
log.verbose(
|
|
3652
|
-
"
|
|
3663
|
+
"Skipping capture of hidden elements: ",
|
|
3653
3664
|
originalLength - elements.length
|
|
3654
3665
|
);
|
|
3655
|
-
log.verbose("
|
|
3666
|
+
log.verbose("Element to capture", elements.length);
|
|
3656
3667
|
if (userConfig.corsProxyBaseUrl) await corsProxy.run(config, elements);
|
|
3657
3668
|
let images = [];
|
|
3658
3669
|
let filenames = [];
|
|
3659
3670
|
let imageNumber = 1;
|
|
3660
3671
|
for (const element of elements) {
|
|
3661
3672
|
const imageOptions = await getImageOptions(element, config);
|
|
3662
|
-
log.verbose("
|
|
3673
|
+
log.verbose("Image options", imageOptions);
|
|
3663
3674
|
if (imageOptions.scale instanceof Array) {
|
|
3664
|
-
log.verbose("
|
|
3675
|
+
log.verbose("Multi-scale capture");
|
|
3665
3676
|
imageOptions.includeScaleInLabel = true;
|
|
3666
3677
|
for (const scale of imageOptions.scale) {
|
|
3667
3678
|
log.progress(imageNumber++, totalElements);
|
|
@@ -3674,7 +3685,7 @@ async function capture(elements, userConfig = defaultConfig) {
|
|
|
3674
3685
|
}
|
|
3675
3686
|
} else if (typeof imageOptions.scale === "number") {
|
|
3676
3687
|
log.progress(imageNumber++, totalElements);
|
|
3677
|
-
log.verbose("
|
|
3688
|
+
log.verbose("Single-scale capture");
|
|
3678
3689
|
const image = await captureElement(
|
|
3679
3690
|
element,
|
|
3680
3691
|
imageOptions,
|
|
@@ -3683,12 +3694,14 @@ async function capture(elements, userConfig = defaultConfig) {
|
|
|
3683
3694
|
images.push(image);
|
|
3684
3695
|
}
|
|
3685
3696
|
}
|
|
3686
|
-
if (userConfig.downloadImages) downloadImages(images, config);
|
|
3697
|
+
if (userConfig.downloadImages) await downloadImages(images, config);
|
|
3687
3698
|
if (userConfig.corsProxyBaseUrl) await corsProxy.cleanUp();
|
|
3688
3699
|
return images;
|
|
3689
3700
|
} catch (error) {
|
|
3690
3701
|
log.error(error);
|
|
3691
3702
|
return null;
|
|
3703
|
+
} finally {
|
|
3704
|
+
log.group.close();
|
|
3692
3705
|
}
|
|
3693
3706
|
}
|
|
3694
3707
|
if (typeof window !== "undefined") {
|
|
@@ -3343,7 +3343,11 @@
|
|
|
3343
3343
|
info: (...messages) => logAction(messages, "info"),
|
|
3344
3344
|
error: (...messages) => logAction(messages, "error"),
|
|
3345
3345
|
verbose: (...messages) => logAction(messages, "verbose"),
|
|
3346
|
-
progress: (progress, total) => logProgress(progress, total)
|
|
3346
|
+
progress: (progress, total) => logProgress(progress, total),
|
|
3347
|
+
group: {
|
|
3348
|
+
open: (...messages) => logAction(messages, "group"),
|
|
3349
|
+
close: (...messages) => logAction(messages, "groupEnd")
|
|
3350
|
+
}
|
|
3347
3351
|
};
|
|
3348
3352
|
async function logAction(messages, type = "info") {
|
|
3349
3353
|
const combinedMessage = messages.map((msg) => typeof msg === "object" ? JSON.stringify(msg) : msg).join(" ");
|
|
@@ -3363,6 +3367,12 @@
|
|
|
3363
3367
|
console.log(...messages);
|
|
3364
3368
|
}
|
|
3365
3369
|
break;
|
|
3370
|
+
case "group":
|
|
3371
|
+
console.group(...messages);
|
|
3372
|
+
break;
|
|
3373
|
+
case "groupEnd":
|
|
3374
|
+
console.groupEnd();
|
|
3375
|
+
break;
|
|
3366
3376
|
}
|
|
3367
3377
|
if (windowLogging) window.imageExporterLogs.push({ message: combinedMessage, type });
|
|
3368
3378
|
}
|
|
@@ -3643,6 +3653,7 @@
|
|
|
3643
3653
|
let windowLogging = true;
|
|
3644
3654
|
let loggingLevel = "none";
|
|
3645
3655
|
async function capture(elements, userConfig = defaultConfig) {
|
|
3656
|
+
log.group.open("image-exporter");
|
|
3646
3657
|
try {
|
|
3647
3658
|
const config = { ...defaultConfig, ...userConfig };
|
|
3648
3659
|
windowLogging = config.enableWindowLogging;
|
|
@@ -3654,19 +3665,19 @@
|
|
|
3654
3665
|
const totalElements = await determineTotalElements(elements);
|
|
3655
3666
|
if (originalLength !== elements.length)
|
|
3656
3667
|
log.verbose(
|
|
3657
|
-
"
|
|
3668
|
+
"Skipping capture of hidden elements: ",
|
|
3658
3669
|
originalLength - elements.length
|
|
3659
3670
|
);
|
|
3660
|
-
log.verbose("
|
|
3671
|
+
log.verbose("Element to capture", elements.length);
|
|
3661
3672
|
if (userConfig.corsProxyBaseUrl) await corsProxy.run(config, elements);
|
|
3662
3673
|
let images = [];
|
|
3663
3674
|
let filenames = [];
|
|
3664
3675
|
let imageNumber = 1;
|
|
3665
3676
|
for (const element of elements) {
|
|
3666
3677
|
const imageOptions = await getImageOptions(element, config);
|
|
3667
|
-
log.verbose("
|
|
3678
|
+
log.verbose("Image options", imageOptions);
|
|
3668
3679
|
if (imageOptions.scale instanceof Array) {
|
|
3669
|
-
log.verbose("
|
|
3680
|
+
log.verbose("Multi-scale capture");
|
|
3670
3681
|
imageOptions.includeScaleInLabel = true;
|
|
3671
3682
|
for (const scale of imageOptions.scale) {
|
|
3672
3683
|
log.progress(imageNumber++, totalElements);
|
|
@@ -3679,7 +3690,7 @@
|
|
|
3679
3690
|
}
|
|
3680
3691
|
} else if (typeof imageOptions.scale === "number") {
|
|
3681
3692
|
log.progress(imageNumber++, totalElements);
|
|
3682
|
-
log.verbose("
|
|
3693
|
+
log.verbose("Single-scale capture");
|
|
3683
3694
|
const image = await captureElement(
|
|
3684
3695
|
element,
|
|
3685
3696
|
imageOptions,
|
|
@@ -3688,12 +3699,14 @@
|
|
|
3688
3699
|
images.push(image);
|
|
3689
3700
|
}
|
|
3690
3701
|
}
|
|
3691
|
-
if (userConfig.downloadImages) downloadImages(images, config);
|
|
3702
|
+
if (userConfig.downloadImages) await downloadImages(images, config);
|
|
3692
3703
|
if (userConfig.corsProxyBaseUrl) await corsProxy.cleanUp();
|
|
3693
3704
|
return images;
|
|
3694
3705
|
} catch (error) {
|
|
3695
3706
|
log.error(error);
|
|
3696
3707
|
return null;
|
|
3708
|
+
} finally {
|
|
3709
|
+
log.group.close();
|
|
3697
3710
|
}
|
|
3698
3711
|
}
|
|
3699
3712
|
if (typeof window !== "undefined") {
|
package/package.json
CHANGED
|
@@ -2,8 +2,6 @@ import * as htmlToImage from "html-to-image";
|
|
|
2
2
|
import { Image, ParsedImageOptions } from "../types";
|
|
3
3
|
import { handleFileNames } from "./handle-filenames";
|
|
4
4
|
import { Options } from "html-to-image/lib/types";
|
|
5
|
-
import { get } from "http";
|
|
6
|
-
|
|
7
5
|
/**
|
|
8
6
|
* captureElement
|
|
9
7
|
*
|
package/src/capture/index.ts
CHANGED
|
@@ -20,6 +20,7 @@ export async function capture(
|
|
|
20
20
|
elements: HTMLElement[] | NodeListOf<HTMLElement> | HTMLElement,
|
|
21
21
|
userConfig: Partial<Config> = defaultConfig
|
|
22
22
|
): Promise<Image[] | null> {
|
|
23
|
+
log.group.open("image-exporter");
|
|
23
24
|
try {
|
|
24
25
|
/* --------------------------------- Config --------------------------------- */
|
|
25
26
|
const config = { ...defaultConfig, ...userConfig };
|
|
@@ -36,10 +37,10 @@ export async function capture(
|
|
|
36
37
|
|
|
37
38
|
if (originalLength !== elements.length)
|
|
38
39
|
log.verbose(
|
|
39
|
-
"
|
|
40
|
+
"Skipping capture of hidden elements: ",
|
|
40
41
|
originalLength - elements.length
|
|
41
42
|
);
|
|
42
|
-
log.verbose("
|
|
43
|
+
log.verbose("Element to capture", elements.length);
|
|
43
44
|
|
|
44
45
|
/* ------------------------------- CORS proxy ------------------------------- */
|
|
45
46
|
if (userConfig.corsProxyBaseUrl) await corsProxy.run(config, elements);
|
|
@@ -51,11 +52,11 @@ export async function capture(
|
|
|
51
52
|
|
|
52
53
|
for (const element of elements) {
|
|
53
54
|
const imageOptions = await getImageOptions(element, config);
|
|
54
|
-
log.verbose("
|
|
55
|
+
log.verbose("Image options", imageOptions);
|
|
55
56
|
|
|
56
57
|
if (imageOptions.scale instanceof Array) {
|
|
57
58
|
/* --------------------------- Multi-scale capture -------------------------- */
|
|
58
|
-
log.verbose("
|
|
59
|
+
log.verbose("Multi-scale capture");
|
|
59
60
|
|
|
60
61
|
imageOptions.includeScaleInLabel = true;
|
|
61
62
|
|
|
@@ -72,7 +73,7 @@ export async function capture(
|
|
|
72
73
|
} else if (typeof imageOptions.scale === "number") {
|
|
73
74
|
log.progress(imageNumber++, totalElements);
|
|
74
75
|
/* -------------------------- Single scale capture -------------------------- */
|
|
75
|
-
log.verbose("
|
|
76
|
+
log.verbose("Single-scale capture");
|
|
76
77
|
|
|
77
78
|
const image = await captureElement(
|
|
78
79
|
element,
|
|
@@ -85,7 +86,7 @@ export async function capture(
|
|
|
85
86
|
}
|
|
86
87
|
|
|
87
88
|
/* -------------------------------- Download -------------------------------- */
|
|
88
|
-
if (userConfig.downloadImages) downloadImages(images, config);
|
|
89
|
+
if (userConfig.downloadImages) await downloadImages(images, config);
|
|
89
90
|
|
|
90
91
|
/* --------------------------- Clean up CORS proxy -------------------------- */
|
|
91
92
|
if (userConfig.corsProxyBaseUrl) await corsProxy.cleanUp();
|
|
@@ -95,5 +96,7 @@ export async function capture(
|
|
|
95
96
|
} catch (error) {
|
|
96
97
|
log.error(error);
|
|
97
98
|
return null;
|
|
99
|
+
} finally {
|
|
100
|
+
log.group.close();
|
|
98
101
|
}
|
|
99
102
|
}
|
package/src/logger.ts
CHANGED
|
@@ -5,6 +5,10 @@ export const log = {
|
|
|
5
5
|
error: (...messages: any[]) => logAction(messages, "error"),
|
|
6
6
|
verbose: (...messages: any[]) => logAction(messages, "verbose"),
|
|
7
7
|
progress: (progress: number, total: number) => logProgress(progress, total),
|
|
8
|
+
group: {
|
|
9
|
+
open: (...messages: any[]) => logAction(messages, "group"),
|
|
10
|
+
close: (...messages: any[]) => logAction(messages, "groupEnd"),
|
|
11
|
+
},
|
|
8
12
|
};
|
|
9
13
|
|
|
10
14
|
async function logAction(messages: any[], type: LogType = "info") {
|
|
@@ -28,6 +32,12 @@ async function logAction(messages: any[], type: LogType = "info") {
|
|
|
28
32
|
console.log(...messages);
|
|
29
33
|
}
|
|
30
34
|
break;
|
|
35
|
+
case "group":
|
|
36
|
+
console.group(...messages);
|
|
37
|
+
break;
|
|
38
|
+
case "groupEnd":
|
|
39
|
+
console.groupEnd();
|
|
40
|
+
break;
|
|
31
41
|
}
|
|
32
42
|
|
|
33
43
|
if (windowLogging) window.imageExporterLogs.push({ message: combinedMessage, type });
|
|
@@ -39,7 +49,7 @@ async function logProgress(progress: number, total: number) {
|
|
|
39
49
|
}
|
|
40
50
|
}
|
|
41
51
|
|
|
42
|
-
type LogType = "info" | "error" | "verbose" | "progress";
|
|
52
|
+
type LogType = "info" | "error" | "verbose" | "progress" | "group" | "groupEnd";
|
|
43
53
|
|
|
44
54
|
type Log = {
|
|
45
55
|
message: string;
|