@zumer/snapdom 1.3.0 → 1.8.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 +125 -11
- package/dist/snapdom.js +834 -476
- package/dist/snapdom.min.js +15 -3
- package/dist/snapdom.min.mjs +15 -3
- package/dist/snapdom.mjs +352 -95
- package/package.json +3 -2
- package/types/snapdom.d.ts +2 -0
package/README.md
CHANGED
|
@@ -7,7 +7,21 @@
|
|
|
7
7
|
</p>
|
|
8
8
|
|
|
9
9
|
<p align="center">
|
|
10
|
-
|
|
10
|
+
<a href="https://www.npmjs.com/package/@zumer/snapdom">
|
|
11
|
+
<img alt="NPM version" src="https://img.shields.io/npm/v/@zumer/snapdom?style=flat-square&label=Version">
|
|
12
|
+
</a>
|
|
13
|
+
<a href="https://github.com/zumerlab/snapdom/graphs/contributors">
|
|
14
|
+
<img alt="GitHub contributors" src="https://img.shields.io/github/contributors/zumerlab/snapdom?style=flat-square&label=Contributors">
|
|
15
|
+
</a>
|
|
16
|
+
<a href="https://github.com/zumerlab/snapdom/stargazers">
|
|
17
|
+
<img alt="GitHub stars" src="https://img.shields.io/github/stars/zumerlab/snapdom?style=flat-square&label=Stars">
|
|
18
|
+
</a>
|
|
19
|
+
<a href="https://github.com/zumerlab/snapdom/network/members">
|
|
20
|
+
<img alt="GitHub forks" src="https://img.shields.io/github/forks/zumerlab/snapdom?style=flat-square&label=Forks">
|
|
21
|
+
</a>
|
|
22
|
+
<a href="https://github.com/zumerlab/snapdom/blob/main/LICENSE">
|
|
23
|
+
<img alt="License" src="https://img.shields.io/github/license/zumerlab/snapdom?style=flat-square">
|
|
24
|
+
</a>
|
|
11
25
|
</p>
|
|
12
26
|
|
|
13
27
|
**snapDOM** is a fast and accurate DOM-to-image capture tool built for **Zumly**, a zoom-based view transition framework.
|
|
@@ -122,14 +136,74 @@ Returns an object with reusable export methods:
|
|
|
122
136
|
|
|
123
137
|
All capture methods accept an `options` object:
|
|
124
138
|
|
|
125
|
-
| Option | Type
|
|
126
|
-
| ----------------- |
|
|
127
|
-
| `compress` | boolean
|
|
128
|
-
| `fast` | boolean
|
|
129
|
-
| `embedFonts` | boolean
|
|
130
|
-
| `scale` | number
|
|
131
|
-
| `
|
|
132
|
-
| `
|
|
139
|
+
| Option | Type | Default | Description |
|
|
140
|
+
| ----------------- | -------- | -------- | ------------------------------------------ |
|
|
141
|
+
| `compress` | boolean | `true` | Removes redundant styles |
|
|
142
|
+
| `fast` | boolean | `true` | Skips idle delay for faster results |
|
|
143
|
+
| `embedFonts` | boolean | `false` | Inlines fonts (icon fonts always embedded) |
|
|
144
|
+
| `scale` | number | `1` | Output scale multiplier |
|
|
145
|
+
| `width` | number | - | Output specific width size |
|
|
146
|
+
| `height` | number | - | Output specific height size |
|
|
147
|
+
| `backgroundColor` | string | `"#fff"` | Fallback color for JPG/WebP |
|
|
148
|
+
| `quality` | number | `1` | Quality for JPG/WebP (0 to 1) |
|
|
149
|
+
| `crossOrigin` | function | - | Function to determine CORS mode per image URL |
|
|
150
|
+
|
|
151
|
+
### Setting custom dimensions with width and height options
|
|
152
|
+
|
|
153
|
+
Use the `width` and `height` options to generate an image with specific dimensions.
|
|
154
|
+
|
|
155
|
+
**Examples:**
|
|
156
|
+
|
|
157
|
+
**1. Fixed width (proportional Hhight)**
|
|
158
|
+
Sets a specific width while maintaining the aspect ratio. Height adjusts proportionally.
|
|
159
|
+
|
|
160
|
+
```js
|
|
161
|
+
const result = await snapdom(element, {
|
|
162
|
+
width: 400 // Outputs a 400px-wide image with auto-scaled height
|
|
163
|
+
});
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
**2. Fixed height (proportional width)**
|
|
167
|
+
Sets a specific height while maintaining the aspect ratio. Width adjusts proportionally.
|
|
168
|
+
|
|
169
|
+
```js
|
|
170
|
+
const result = await snapdom(element, {
|
|
171
|
+
height: 200 // Outputs a 200px-tall image with auto-scaled width
|
|
172
|
+
});
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
**3. Fixed width and height (may distort image)**
|
|
176
|
+
Forces exact dimensions, potentially distorting the image if the aspect ratio differs.
|
|
177
|
+
|
|
178
|
+
```js
|
|
179
|
+
const result = await snapdom(element, {
|
|
180
|
+
width: 800, // Outputs an 800px × 200px image (may stretch/squish content)
|
|
181
|
+
height: 200
|
|
182
|
+
});
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
**Note:** If `scale` is different from 1, it takes priority over width and height.
|
|
186
|
+
Example: `{ scale: 3, width: 500 }` ignores width and scales the image 3x instead.
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
### Cross-Origin Images
|
|
190
|
+
|
|
191
|
+
By default, snapDOM loads images with `crossOrigin="anonymous"`. You can customize this behavior using the `crossOrigin` option:
|
|
192
|
+
|
|
193
|
+
```js
|
|
194
|
+
const result = await snapdom(element, {
|
|
195
|
+
crossOrigin: (url) => {
|
|
196
|
+
// Use credentials for same-origin images
|
|
197
|
+
if (url.startsWith(window.location.origin)) {
|
|
198
|
+
return "use-credentials";
|
|
199
|
+
}
|
|
200
|
+
// Use anonymous for cross-origin images
|
|
201
|
+
return "anonymous";
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
This is useful when your images require authentication or when dealing with credentialed requests.
|
|
133
207
|
|
|
134
208
|
### Download options
|
|
135
209
|
|
|
@@ -164,6 +238,7 @@ import { snapdom, preCache } from './snapdom.mjs';
|
|
|
164
238
|
|
|
165
239
|
* `embedFonts` *(boolean, default: true)* — Inlines non-icon fonts during preload.
|
|
166
240
|
* `reset` *(boolean, default: false)* — Clears all existing internal caches.
|
|
241
|
+
* `crossOrigin` *(function)* — Function to determine CORS mode per image URL during preload.
|
|
167
242
|
|
|
168
243
|
|
|
169
244
|
## Features
|
|
@@ -177,15 +252,15 @@ import { snapdom, preCache } from './snapdom.mjs';
|
|
|
177
252
|
|
|
178
253
|
## Limitations
|
|
179
254
|
|
|
180
|
-
* External images must be CORS-accessible
|
|
255
|
+
* External images must be CORS-accessible (use `crossOrigin` option for credentialed requests)
|
|
181
256
|
* Iframes are not supported
|
|
182
257
|
* When WebP format is used on Safari, it will fallback to PNG rendering.
|
|
258
|
+
* `@font-face` CSS rule is well supported, but if need to use JS `FontFace()`, see this workaround [`#43`](https://github.com/zumerlab/snapdom/issues/43)
|
|
183
259
|
|
|
184
260
|
## Benchmarks
|
|
185
261
|
|
|
186
262
|
`snapDOM` is not only highly accurate — it’s **extremely fast**.
|
|
187
263
|
|
|
188
|
-
|
|
189
264
|
Latest benchmarks show significant performance improvements against other libraries:
|
|
190
265
|
|
|
191
266
|
| Scenario | vs. `modern-screenshot` | vs. `html2canvas` |
|
|
@@ -215,6 +290,45 @@ npm run test:benchmark
|
|
|
215
290
|
|
|
216
291
|
They execute in **headless Chromium** using real DOM nodes.
|
|
217
292
|
|
|
293
|
+
## Development
|
|
294
|
+
|
|
295
|
+
To contribute or build snapDOM locally:
|
|
296
|
+
|
|
297
|
+
```sh
|
|
298
|
+
# Clone the repository
|
|
299
|
+
git clone https://github.com/zumerlab/snapdom.git
|
|
300
|
+
cd snapdom
|
|
301
|
+
|
|
302
|
+
# Install dependencies
|
|
303
|
+
npm install
|
|
304
|
+
|
|
305
|
+
# Compile the library (ESM, CJS, and minified versions)
|
|
306
|
+
npm run compile
|
|
307
|
+
|
|
308
|
+
# Run tests
|
|
309
|
+
npm test
|
|
310
|
+
|
|
311
|
+
# Run Benchmarks
|
|
312
|
+
npm run test:benchmark
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
The main entry point is in `src/`, and output bundles are generated in the `dist/` folder.
|
|
316
|
+
|
|
317
|
+
For detailed contribution guidelines, please see [CONTRIBUTING](https://github.com/zumerlab/snapdom/blob/main/CONTRIBUTING.md).
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+
## Contributors 🙌
|
|
321
|
+
|
|
322
|
+
<!-- CONTRIBUTORS:START -->
|
|
323
|
+
<p>
|
|
324
|
+
<a href="https://github.com/tinchox5" title="tinchox5"><img src="https://avatars.githubusercontent.com/u/11557901?v=4&s=100" style="border-radius:10px; width:60px; height:60px; object-fit:cover; margin:5px;" alt="tinchox5"/></a>
|
|
325
|
+
<a href="https://github.com/pedrocateexte" title="pedrocateexte"><img src="https://avatars.githubusercontent.com/u/207524750?v=4&s=100" style="border-radius:10px; width:60px; height:60px; object-fit:cover; margin:5px;" alt="pedrocateexte"/></a>
|
|
326
|
+
<a href="https://github.com/domialex" title="domialex"><img src="https://avatars.githubusercontent.com/u/4694217?v=4&s=100" style="border-radius:10px; width:60px; height:60px; object-fit:cover; margin:5px;" alt="domialex"/></a>
|
|
327
|
+
<a href="https://github.com/elliots" title="elliots"><img src="https://avatars.githubusercontent.com/u/622455?v=4&s=100" style="border-radius:10px; width:60px; height:60px; object-fit:cover; margin:5px;" alt="elliots"/></a>
|
|
328
|
+
<a href="https://github.com/jswhisperer" title="jswhisperer"><img src="https://avatars.githubusercontent.com/u/1177690?v=4&s=100" style="border-radius:10px; width:60px; height:60px; object-fit:cover; margin:5px;" alt="jswhisperer"/></a>
|
|
329
|
+
<a href="https://github.com/jhbae200" title="jhbae200"><img src="https://avatars.githubusercontent.com/u/20170610?v=4&s=100" style="border-radius:10px; width:60px; height:60px; object-fit:cover; margin:5px;" alt="jhbae200"/></a>
|
|
330
|
+
</p>
|
|
331
|
+
<!-- CONTRIBUTORS:END -->
|
|
218
332
|
|
|
219
333
|
## License
|
|
220
334
|
|