image-exporter 0.0.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/.gitattributes +2 -0
- package/.prettierrc +5 -0
- package/LICENSE.md +201 -0
- package/README.md +3 -0
- package/dist/image-exporter.es.js +3807 -0
- package/dist/image-exporter.umd.js +3813 -0
- package/example/example.css +122 -0
- package/example/example.html +152 -0
- package/example/github.jpg +0 -0
- package/example/poll-h.svg +1 -0
- package/package.json +50 -0
- package/src/capture-images.ts +129 -0
- package/src/clean-up.ts +50 -0
- package/src/cors-proxy/index.ts +22 -0
- package/src/cors-proxy/proxy-css.ts +52 -0
- package/src/cors-proxy/proxy-images.ts +90 -0
- package/src/default-options.ts +58 -0
- package/src/download-images.ts +52 -0
- package/src/get-capture-element.test.html +21 -0
- package/src/get-capture-element.test.ts +36 -0
- package/src/get-capture-element.ts +175 -0
- package/src/get-options/get-input-options.test.html +217 -0
- package/src/get-options/get-input-options.test.ts +109 -0
- package/src/get-options/get-input-options.ts +40 -0
- package/src/get-options/get-item-options.ts +46 -0
- package/src/get-options/get-wrapper-options.test.html +33 -0
- package/src/get-options/get-wrapper-options.test.ts +109 -0
- package/src/get-options/get-wrapper-options.ts +84 -0
- package/src/get-options/index.ts +28 -0
- package/src/image-exporter.ts +108 -0
- package/src/index.ts +8 -0
- package/src/types/image.ts +2 -0
- package/src/types/index.ts +2 -0
- package/src/types/options.ts +69 -0
- package/src/utils/convert-to-slug.ts +15 -0
- package/src/utils/get-attribute-values.ts +68 -0
- package/src/utils/get-date-MMDDYY.ts +11 -0
- package/src/utils/ignore-items.ts +11 -0
- package/src/utils/index.ts +18 -0
- package/src/utils/is-valid-url.ts +20 -0
- package/src/utils/is-visible.ts +12 -0
- package/src/utils/parse-labels.ts +55 -0
- package/src/utils/push-to-window.ts +3 -0
- package/tests/index.html +88 -0
- package/tests/input-tests.html +169 -0
- package/vite.config.js +39 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Determines if a given element is currently visible on the page.
|
|
3
|
+
*
|
|
4
|
+
* @param element - The DOM element to check for visibility.
|
|
5
|
+
* @returns True if the element is visible, false otherwise.
|
|
6
|
+
*/
|
|
7
|
+
export function isVisible(element: Element): boolean {
|
|
8
|
+
if (!(element instanceof HTMLElement)) return false;
|
|
9
|
+
if (element.offsetParent === null) return false;
|
|
10
|
+
const rect = element.getBoundingClientRect();
|
|
11
|
+
return rect.width > 0 && rect.height > 0;
|
|
12
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import * as types from "../types";
|
|
2
|
+
import { convertToSlug } from "./convert-to-slug";
|
|
3
|
+
import { getDateMMDDYY } from "./get-date-MMDDYY";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Generates a zip file label based on user settings.
|
|
7
|
+
*
|
|
8
|
+
* This function creates a label for a zip file using various parameters from the user settings.
|
|
9
|
+
* It includes optional elements such as a date stamp and scale factor in the filename, depending on the user's preferences.
|
|
10
|
+
*
|
|
11
|
+
* @param {Object} options - The settings provided by the user.
|
|
12
|
+
* It is expected to have the following properties:
|
|
13
|
+
* - includeScaleZip: {boolean} - Determines if scale factor should be included in the label.
|
|
14
|
+
* - fileScale: {number} - The scale factor to be used if includeScaleZip is true.
|
|
15
|
+
* - includeDateZip: {boolean} - Determines if the current date should be included in the label.
|
|
16
|
+
* - zipName: {string} - The base name of the zip file.
|
|
17
|
+
* @returns {string|null} The formatted zip file label, or null if userSettings is not provided.
|
|
18
|
+
*
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
export function parseZipLabel(options: types.Options): string {
|
|
22
|
+
const date = getDateMMDDYY();
|
|
23
|
+
const zipScale = convertStringToBoolean(options.zip.scaleInLabel.value)
|
|
24
|
+
? `_@${options.image.scale.value}x`
|
|
25
|
+
: "";
|
|
26
|
+
const zipDate = convertStringToBoolean(options.zip.dateInLabel.value) ? `_${date}` : "";
|
|
27
|
+
const zipNameSlug = convertToSlug(options.zip.label.value);
|
|
28
|
+
const zipLabel = `${zipNameSlug}${zipDate}${zipScale}.zip`;
|
|
29
|
+
|
|
30
|
+
return zipLabel;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function parseImageLabel(itemOptions: types.ItemOptions): string {
|
|
34
|
+
const date = getDateMMDDYY();
|
|
35
|
+
const imgScale = itemOptions.image.scaleInLabel.value
|
|
36
|
+
? `_@${itemOptions.image.scale.value}x`
|
|
37
|
+
: "";
|
|
38
|
+
const imgDate = itemOptions.image.dateInLabel.value ? `_${date}` : "";
|
|
39
|
+
const imgNameSlug = convertToSlug(itemOptions.userSlug) || `img-${itemOptions.id}`;
|
|
40
|
+
const imgLabel = `${imgNameSlug}${imgDate}${imgScale}`;
|
|
41
|
+
|
|
42
|
+
return imgLabel;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function convertStringToBoolean(str: boolean | string): boolean | string {
|
|
46
|
+
// Convert "true" or "false" to boolean
|
|
47
|
+
if (str === "true") {
|
|
48
|
+
return true;
|
|
49
|
+
} else if (str === "false") {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Return the original string if no conversion is possible
|
|
54
|
+
return str;
|
|
55
|
+
}
|
package/tests/index.html
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
+
<title>Tests</title>
|
|
7
|
+
<link
|
|
8
|
+
rel="stylesheet"
|
|
9
|
+
href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.classless.min.css"
|
|
10
|
+
/>
|
|
11
|
+
<script src="/dist/image-exporter.umd.js"></script>
|
|
12
|
+
|
|
13
|
+
<style>
|
|
14
|
+
slug {
|
|
15
|
+
display: none;
|
|
16
|
+
}
|
|
17
|
+
artboard {
|
|
18
|
+
border: 1px solid #2d3138;
|
|
19
|
+
}
|
|
20
|
+
section {
|
|
21
|
+
justify-content: flex-start;
|
|
22
|
+
align-items: flex-start;
|
|
23
|
+
flex-direction: column;
|
|
24
|
+
padding: 1rem 0;
|
|
25
|
+
}
|
|
26
|
+
.test-1 {
|
|
27
|
+
padding: 1rem;
|
|
28
|
+
background-color: #f0f0f0;
|
|
29
|
+
color: #333;
|
|
30
|
+
width: 300px;
|
|
31
|
+
height: 300px;
|
|
32
|
+
font-weight: 800;
|
|
33
|
+
display: flex;
|
|
34
|
+
justify-content: center;
|
|
35
|
+
align-items: center;
|
|
36
|
+
background: linear-gradient(45deg, #01aaff, #0172ad);
|
|
37
|
+
color: white;
|
|
38
|
+
margin: 0rem;
|
|
39
|
+
}
|
|
40
|
+
</style>
|
|
41
|
+
</head>
|
|
42
|
+
<body>
|
|
43
|
+
<header>
|
|
44
|
+
<h1>Tests</h1>
|
|
45
|
+
<p>Exports a series of artboards simulating common scenarios.</p>
|
|
46
|
+
<p>Check each export on build.</p>
|
|
47
|
+
<button gf="trigger">Run</button>
|
|
48
|
+
<label for="format" class="input-label">File Format</label>
|
|
49
|
+
<select title="format" ie-format-input class="example-input">
|
|
50
|
+
<option value="png">PNG</option>
|
|
51
|
+
<option value="jpg">JPG</option>
|
|
52
|
+
</select>
|
|
53
|
+
|
|
54
|
+
<label for="scale" class="input-label">Scale</label>
|
|
55
|
+
<select title="scale" ie-scale-input class="example-input">
|
|
56
|
+
<option value="1">@1x</option>
|
|
57
|
+
<option value="2">@2x</option>
|
|
58
|
+
<option value="3">@3x</option>
|
|
59
|
+
<option value="4">@4x</option>
|
|
60
|
+
</select>
|
|
61
|
+
</header>
|
|
62
|
+
<main ie="wrapper" ie-scale="4">
|
|
63
|
+
<section>
|
|
64
|
+
<h2 gf="test-trigger">Test 1</h2>
|
|
65
|
+
<artboard ie="capture" class="test-1">
|
|
66
|
+
<slug ie="slug">ping</slug>
|
|
67
|
+
<div>This is the headline</div>
|
|
68
|
+
</artboard>
|
|
69
|
+
<artboard ie="capture" class="test-1" ie-scale="1,2,3,4" test="test">
|
|
70
|
+
<slug ie="slug">pong</slug>
|
|
71
|
+
<div>This is the headline</div>
|
|
72
|
+
</artboard>
|
|
73
|
+
</section>
|
|
74
|
+
</main>
|
|
75
|
+
<script>
|
|
76
|
+
let options = {
|
|
77
|
+
corsProxyBaseUrl: "http://localhost:8010/",
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
let imageExporter = new ImageExporter({ options });
|
|
81
|
+
imageExporter.addTrigger(document.querySelector("[gf=trigger]"));
|
|
82
|
+
imageExporter.addTrigger(
|
|
83
|
+
document.querySelector("[gf=test-trigger]"),
|
|
84
|
+
document.querySelector("[test=test]")
|
|
85
|
+
);
|
|
86
|
+
</script>
|
|
87
|
+
</body>
|
|
88
|
+
</html>
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
+
<title>Tests</title>
|
|
7
|
+
<link
|
|
8
|
+
rel="stylesheet"
|
|
9
|
+
href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.classless.min.css"
|
|
10
|
+
/>
|
|
11
|
+
<script src="/dist/image-exporter.umd.js"></script>
|
|
12
|
+
|
|
13
|
+
<style>
|
|
14
|
+
slug {
|
|
15
|
+
display: none;
|
|
16
|
+
}
|
|
17
|
+
artboard {
|
|
18
|
+
border: 1px solid #2d3138;
|
|
19
|
+
}
|
|
20
|
+
section {
|
|
21
|
+
justify-content: flex-start;
|
|
22
|
+
align-items: flex-start;
|
|
23
|
+
flex-direction: column;
|
|
24
|
+
padding: 1rem 0;
|
|
25
|
+
}
|
|
26
|
+
.artboard-1 {
|
|
27
|
+
padding: 1rem;
|
|
28
|
+
background-color: #f0f0f0;
|
|
29
|
+
color: #333;
|
|
30
|
+
width: 300px;
|
|
31
|
+
height: 300px;
|
|
32
|
+
font-weight: 800;
|
|
33
|
+
display: flex;
|
|
34
|
+
justify-content: center;
|
|
35
|
+
align-items: center;
|
|
36
|
+
background: linear-gradient(45deg, #01aaff, #0172ad);
|
|
37
|
+
color: white;
|
|
38
|
+
margin: 0rem;
|
|
39
|
+
}
|
|
40
|
+
</style>
|
|
41
|
+
</head>
|
|
42
|
+
<body>
|
|
43
|
+
<header>
|
|
44
|
+
<h1>Input Tests</h1>
|
|
45
|
+
<hr />
|
|
46
|
+
|
|
47
|
+
<h2>Inputs</h2>
|
|
48
|
+
<div>
|
|
49
|
+
<!-- Scale -->
|
|
50
|
+
<label for="scale"><strong>Scale</strong></label>
|
|
51
|
+
<select title="scale" ie-scale-input>
|
|
52
|
+
<option value="1">@1x</option>
|
|
53
|
+
<option value="2">@2x</option>
|
|
54
|
+
<option value="3">@3x</option>
|
|
55
|
+
<option value="4">@4x</option>
|
|
56
|
+
</select>
|
|
57
|
+
</div>
|
|
58
|
+
<div>
|
|
59
|
+
<!-- Quality -->
|
|
60
|
+
<label for="quality"><strong>Quality</strong></label>
|
|
61
|
+
<input
|
|
62
|
+
type="range"
|
|
63
|
+
id="quality"
|
|
64
|
+
name="quality"
|
|
65
|
+
min="0.00"
|
|
66
|
+
max="1.00"
|
|
67
|
+
value="1"
|
|
68
|
+
step="0.01"
|
|
69
|
+
ie-quality-input
|
|
70
|
+
/>
|
|
71
|
+
</div>
|
|
72
|
+
<div>
|
|
73
|
+
<!-- Format -->
|
|
74
|
+
<label for="format"><strong>Format</strong></label>
|
|
75
|
+
<select title="format" ie-format-input>
|
|
76
|
+
<option value="png">PNG</option>
|
|
77
|
+
<option value="jpg">JPG</option>
|
|
78
|
+
</select>
|
|
79
|
+
</div>
|
|
80
|
+
<div>
|
|
81
|
+
<fieldset>
|
|
82
|
+
<legend><strong>Image label</strong></legend>
|
|
83
|
+
<!-- dateInLabel -->
|
|
84
|
+
<label for="dateInLabel">
|
|
85
|
+
<input
|
|
86
|
+
type="checkbox"
|
|
87
|
+
id="dateInLabel"
|
|
88
|
+
name="dateInLabel"
|
|
89
|
+
name="dateInLabel"
|
|
90
|
+
role="switch"
|
|
91
|
+
checked=""
|
|
92
|
+
ie-img-label-date-input
|
|
93
|
+
/>
|
|
94
|
+
Date in label
|
|
95
|
+
</label>
|
|
96
|
+
<!--scaleInLabel-->
|
|
97
|
+
<label for="scaleInLabel">
|
|
98
|
+
<input
|
|
99
|
+
type="checkbox"
|
|
100
|
+
id="scaleInLabel"
|
|
101
|
+
name="scaleInLabel"
|
|
102
|
+
name="scaleInLabel"
|
|
103
|
+
role="switch"
|
|
104
|
+
checked=""
|
|
105
|
+
ie-img-label-scale-input
|
|
106
|
+
/>
|
|
107
|
+
Scale in label
|
|
108
|
+
</label>
|
|
109
|
+
</fieldset>
|
|
110
|
+
</div>
|
|
111
|
+
<fieldset>
|
|
112
|
+
<legend><strong>Zip label</strong></legend>
|
|
113
|
+
<!-- zipLabel -->
|
|
114
|
+
<label for="zipLabel">Label</label>
|
|
115
|
+
<input type="text" id="zipLabel" name="zipLabel" ie-zip-label-input />
|
|
116
|
+
<!-- zipDateInLabel -->
|
|
117
|
+
<label for="zipDateInLabel">
|
|
118
|
+
<input
|
|
119
|
+
type="checkbox"
|
|
120
|
+
id="zipDateInLabel"
|
|
121
|
+
name="zipDateInLabel"
|
|
122
|
+
name="zipDateInLabel"
|
|
123
|
+
role="switch"
|
|
124
|
+
checked=""
|
|
125
|
+
ie-zip-label-date-input
|
|
126
|
+
/>
|
|
127
|
+
Date in label
|
|
128
|
+
</label>
|
|
129
|
+
<!--zipScaleInLabel-->
|
|
130
|
+
<label for="zipScaleInLabel">
|
|
131
|
+
<input
|
|
132
|
+
type="checkbox"
|
|
133
|
+
id="zipScaleInLabel"
|
|
134
|
+
name="zipScaleInLabel"
|
|
135
|
+
name="zipScaleInLabel"
|
|
136
|
+
role="switch"
|
|
137
|
+
checked=""
|
|
138
|
+
ie-zip-label-scale-input
|
|
139
|
+
/>
|
|
140
|
+
Scale in label
|
|
141
|
+
</label>
|
|
142
|
+
</fieldset>
|
|
143
|
+
|
|
144
|
+
<button ie-trigger>Run</button>
|
|
145
|
+
</header>
|
|
146
|
+
<hr />
|
|
147
|
+
<main ie="wrapper">
|
|
148
|
+
<section>
|
|
149
|
+
<h2>Artboards</h2>
|
|
150
|
+
<artboard ie="capture" class="artboard-1">
|
|
151
|
+
<slug ie="slug">ping</slug>
|
|
152
|
+
<div>This is the headline</div>
|
|
153
|
+
</artboard>
|
|
154
|
+
<artboard ie="capture" class="artboard-1">
|
|
155
|
+
<slug ie="slug">pong</slug>
|
|
156
|
+
<div>This is the headline</div>
|
|
157
|
+
</artboard>
|
|
158
|
+
</section>
|
|
159
|
+
</main>
|
|
160
|
+
<script>
|
|
161
|
+
const testOptions = {
|
|
162
|
+
corsProxyBaseUrl: "http://localhost:8010/",
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
let imageExporter = new ImageExporter({ testOptions });
|
|
166
|
+
imageExporter.addTrigger("[ie-trigger]");
|
|
167
|
+
</script>
|
|
168
|
+
</body>
|
|
169
|
+
</html>
|
package/vite.config.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { defineConfig } from "vite";
|
|
2
|
+
import strip from "@rollup/plugin-strip";
|
|
3
|
+
|
|
4
|
+
export default defineConfig({
|
|
5
|
+
build: {
|
|
6
|
+
outDir: "dist",
|
|
7
|
+
emptyOutDir: true,
|
|
8
|
+
minify: false,
|
|
9
|
+
lib: {
|
|
10
|
+
entry: "src/index.ts",
|
|
11
|
+
name: "image-exporter",
|
|
12
|
+
fileName: (format) => `image-exporter.${format}.js`,
|
|
13
|
+
},
|
|
14
|
+
rollupOptions: {
|
|
15
|
+
input: "src/index.ts",
|
|
16
|
+
plugins: [
|
|
17
|
+
{
|
|
18
|
+
name: "wrap-in-iife",
|
|
19
|
+
generateBundle(outputOptions, bundle) {
|
|
20
|
+
if (outputOptions.format === "umd") {
|
|
21
|
+
Object.keys(bundle).forEach((fileName) => {
|
|
22
|
+
const file = bundle[fileName];
|
|
23
|
+
if (fileName.slice(-3) === ".js" && "code" in file) {
|
|
24
|
+
file.code = `(() => {\n${file.code}})()`;
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
strip({
|
|
31
|
+
include: "**/*.(js|ts)",
|
|
32
|
+
functions: ["console.log"],
|
|
33
|
+
// Only apply this plugin during build, not during watch
|
|
34
|
+
exclude: process.env.NODE_ENV === "development" ? "**/*" : "",
|
|
35
|
+
}),
|
|
36
|
+
],
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
});
|