image-exporter 0.0.1 → 1.0.0
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 +137 -2
- package/bun.lockb +0 -0
- package/dist/image-exporter.es.js +499 -612
- package/dist/image-exporter.umd.js +506 -619
- package/package.json +18 -15
- package/src/capture/capture-element.ts +58 -0
- package/src/capture/determine-total-elements.ts +40 -0
- package/src/capture/download-images.ts +69 -0
- package/src/capture/get-image-options.ts +196 -0
- package/src/capture/handle-filenames.ts +52 -0
- package/src/capture/index.ts +99 -0
- package/src/capture/remove-hidden-elements.ts +19 -0
- package/src/config.ts +19 -0
- package/src/cors-proxy/cleanup.ts +43 -0
- package/src/cors-proxy/index.ts +6 -21
- package/src/{utils → cors-proxy}/is-valid-url.ts +5 -3
- package/src/cors-proxy/proxy-css.ts +51 -44
- package/src/cors-proxy/proxy-images.ts +21 -77
- package/src/cors-proxy/run.ts +26 -0
- package/src/index.ts +10 -4
- package/src/logger.ts +61 -0
- package/src/types.d.ts +51 -0
- package/vite.config.js +3 -7
- package/example/example.css +0 -122
- package/example/example.html +0 -152
- package/example/github.jpg +0 -0
- package/example/poll-h.svg +0 -1
- package/src/capture-images.ts +0 -129
- package/src/clean-up.ts +0 -50
- package/src/default-options.ts +0 -58
- package/src/download-images.ts +0 -52
- package/src/get-capture-element.test.html +0 -21
- package/src/get-capture-element.test.ts +0 -36
- package/src/get-capture-element.ts +0 -175
- package/src/get-options/get-input-options.test.html +0 -217
- package/src/get-options/get-input-options.test.ts +0 -109
- package/src/get-options/get-input-options.ts +0 -40
- package/src/get-options/get-item-options.ts +0 -46
- package/src/get-options/get-wrapper-options.test.html +0 -33
- package/src/get-options/get-wrapper-options.test.ts +0 -109
- package/src/get-options/get-wrapper-options.ts +0 -84
- package/src/get-options/index.ts +0 -28
- package/src/image-exporter.ts +0 -108
- package/src/types/image.ts +0 -2
- package/src/types/index.ts +0 -2
- package/src/types/options.ts +0 -69
- package/src/utils/convert-to-slug.ts +0 -15
- package/src/utils/get-attribute-values.ts +0 -68
- package/src/utils/get-date-MMDDYY.ts +0 -11
- package/src/utils/ignore-items.ts +0 -11
- package/src/utils/index.ts +0 -18
- package/src/utils/is-visible.ts +0 -12
- package/src/utils/parse-labels.ts +0 -55
- package/src/utils/push-to-window.ts +0 -3
- package/tests/index.html +0 -88
- package/tests/input-tests.html +0 -169
package/README.md
CHANGED
|
@@ -1,3 +1,138 @@
|
|
|
1
|
-
# image-exporter
|
|
1
|
+
# image-exporter [v1.0.0]
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
image-exporter is a client-side javascript tool that downloads DOM elements as images. It can be imported using your favorite package manager or used directly the window.
|
|
4
|
+
|
|
5
|
+
## Examples:
|
|
6
|
+
|
|
7
|
+
### Package
|
|
8
|
+
|
|
9
|
+
```Typescript
|
|
10
|
+
import { capture } from "image-exporter";
|
|
11
|
+
|
|
12
|
+
const artboards = document.querySelectorAll(".artboard");
|
|
13
|
+
|
|
14
|
+
// Returned as [dataUrl, filename] rather than downloaded
|
|
15
|
+
const images = capture(artboards, {
|
|
16
|
+
format: 'png',
|
|
17
|
+
downloadImages: false
|
|
18
|
+
})
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
### Browser
|
|
22
|
+
|
|
23
|
+
```HTML
|
|
24
|
+
<script src="your-path/image-exporter.umd.js" type="text/javascript"></script>
|
|
25
|
+
|
|
26
|
+
<div class="artboard">I will be downloaded.</div>
|
|
27
|
+
|
|
28
|
+
<script>
|
|
29
|
+
const capture = window.imageExporter;
|
|
30
|
+
const artboards = document.querySelectorAll(".artboard");
|
|
31
|
+
capture(artboards)
|
|
32
|
+
</script>
|
|
33
|
+
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Installation
|
|
37
|
+
|
|
38
|
+
`npm i image-exporter` or whatever package manager you're using.
|
|
39
|
+
|
|
40
|
+
```Typescript
|
|
41
|
+
import { capture } from "image-exporter";
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Config
|
|
45
|
+
|
|
46
|
+
```Typescript
|
|
47
|
+
{
|
|
48
|
+
/** Download images as files upon capture. */
|
|
49
|
+
downloadImages: boolean;
|
|
50
|
+
/** Default label for images. Does not include file extension or scale. */
|
|
51
|
+
defaultImageLabel: string;
|
|
52
|
+
/** Label for zip file. Does not include file extension or scale. */
|
|
53
|
+
zipLabel: Label;
|
|
54
|
+
/** Base URL for CORS proxy used when fetching external images. */
|
|
55
|
+
corsProxyBaseUrl: string;
|
|
56
|
+
/** Enable window logging for use by external scripts */
|
|
57
|
+
enableWindowLogging: boolean;
|
|
58
|
+
/** Enable verbose logging for debugging. */
|
|
59
|
+
loggingLevel: "none" | "info" | "error" | "verbose";
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### CORS proxy
|
|
64
|
+
|
|
65
|
+
If your capture elements have externally hosted images or CSS inside them, you will likely hit a [CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS) error.
|
|
66
|
+
|
|
67
|
+
To bypass this, you can provide a CORS proxy base URL. URLs will be encoded and appended without a `?` to your base URL. Include your own trailing slash.
|
|
68
|
+
|
|
69
|
+
I recommend [cors-proxy-worker](https://github.com/briantuckerdesign/cors-proxy-worker) for production and [local-cors-proxy-encoded](https://github.com/briantuckerdesign/local-cors-proxy-encoded) for development.
|
|
70
|
+
|
|
71
|
+
Example: `https://example-cors-proxy.com/` -> `https://example-cors-proxy.com/https%3A%2F%2FmyEncodedUrl.com`
|
|
72
|
+
|
|
73
|
+
## Image options
|
|
74
|
+
|
|
75
|
+
Image options can also be set at the `config` level and will serve as the default if no values are provided for that specific capture element.
|
|
76
|
+
|
|
77
|
+
```Typescript
|
|
78
|
+
{
|
|
79
|
+
/** Label for image. Does not include file extension or scale. */
|
|
80
|
+
label: string;
|
|
81
|
+
/** File format, jpg, png, or svg. */
|
|
82
|
+
format: "jpg" | "png" | "svg";
|
|
83
|
+
/** Scale of image. Can be a number or a comma-separated list of numbers. */
|
|
84
|
+
scale: number | number[];
|
|
85
|
+
/** Quality of image. 0.0 to 1.0, only applies to jpg.*/
|
|
86
|
+
quality: number;
|
|
87
|
+
/** Include scale in label. True or false. Automatically true if scale is an array. */
|
|
88
|
+
includeScaleInLabel: boolean;
|
|
89
|
+
}
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### Setting image options
|
|
93
|
+
|
|
94
|
+
Image options are set on the element itself using data attributes.
|
|
95
|
+
|
|
96
|
+
The attributes are:
|
|
97
|
+
|
|
98
|
+
```
|
|
99
|
+
data-label
|
|
100
|
+
data-format
|
|
101
|
+
data-scale
|
|
102
|
+
data-quality
|
|
103
|
+
data-include-scale-in-label
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
#### Example
|
|
107
|
+
|
|
108
|
+
```HTML
|
|
109
|
+
<div
|
|
110
|
+
data-label="My custom label"
|
|
111
|
+
data-format="jpg"
|
|
112
|
+
data-scale="1,2"
|
|
113
|
+
data-quality="0.8"
|
|
114
|
+
data-include-scale-in-label="true">
|
|
115
|
+
I will be downloaded at @1x and @2x with a custom label, quality of 0.8, a JPG, and include scale in label.
|
|
116
|
+
</div>
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### Setting config options
|
|
120
|
+
|
|
121
|
+
Config options are set in the `config` object passed to the `capture` function.
|
|
122
|
+
|
|
123
|
+
#### Example
|
|
124
|
+
|
|
125
|
+
```HTML
|
|
126
|
+
<div class="artboard" data-scale="1,2">I will be downloaded at @1x and @2x.</div>
|
|
127
|
+
<div class="artboard" data-format="jpg" data-quality="0.8">I will be a compressed JPG.</div>
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
## Built using
|
|
131
|
+
|
|
132
|
+
- [`html-to-image`](https://github.com/bubkoo/html-to-image)
|
|
133
|
+
|
|
134
|
+
- [`jszip`](https://github.com/Stuk/jszip)
|
|
135
|
+
|
|
136
|
+
- [`downloadjs`](https://github.com/rndme/download)
|
|
137
|
+
|
|
138
|
+
Bundled in Vite and written in Typescript.
|
package/bun.lockb
ADDED
|
Binary file
|