@zumer/snapdom 1.7.1 → 1.9.3-next-dev.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 +161 -35
- package/dist/snapdom.js +1089 -598
- package/dist/snapdom.min.js +13 -13
- package/dist/snapdom.min.mjs +13 -13
- package/dist/snapdom.mjs +559 -171
- package/package.json +3 -2
- package/types/snapdom.d.ts +7 -2
package/README.md
CHANGED
|
@@ -7,7 +7,25 @@
|
|
|
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/sponsors/tinchox5">
|
|
23
|
+
<img alt="Sponsor tinchox5" src="https://img.shields.io/github/sponsors/tinchox5?style=flat-square&label=Sponsor">
|
|
24
|
+
</a>
|
|
25
|
+
|
|
26
|
+
<a href="https://github.com/zumerlab/snapdom/blob/main/LICENSE">
|
|
27
|
+
<img alt="License" src="https://img.shields.io/github/license/zumerlab/snapdom?style=flat-square">
|
|
28
|
+
</a>
|
|
11
29
|
</p>
|
|
12
30
|
|
|
13
31
|
**snapDOM** is a fast and accurate DOM-to-image capture tool built for **Zumly**, a zoom-based view transition framework.
|
|
@@ -128,28 +146,63 @@ All capture methods accept an `options` object:
|
|
|
128
146
|
| `fast` | boolean | `true` | Skips idle delay for faster results |
|
|
129
147
|
| `embedFonts` | boolean | `false` | Inlines fonts (icon fonts always embedded) |
|
|
130
148
|
| `scale` | number | `1` | Output scale multiplier |
|
|
149
|
+
| `width` | number | - | Output specific width size |
|
|
150
|
+
| `height` | number | - | Output specific height size |
|
|
131
151
|
| `backgroundColor` | string | `"#fff"` | Fallback color for JPG/WebP |
|
|
132
152
|
| `quality` | number | `1` | Quality for JPG/WebP (0 to 1) |
|
|
133
|
-
| `
|
|
153
|
+
| `useProxy` | string | '' | Specify a proxy for handling CORS images as fallback|
|
|
154
|
+
| `type` | string | `svg` | Select `png`, `jpg`, `webp` Blob type|
|
|
155
|
+
| `exclude` | string[] | - | CSS selectors for elements to exclude |
|
|
156
|
+
| `filter` | function | - | Custom filter function ie `(el) => !el.classList.contains('hidden')` |
|
|
157
|
+
|
|
158
|
+
### Setting custom dimensions with width and height options
|
|
159
|
+
|
|
160
|
+
Use the `width` and `height` options to generate an image with specific dimensions.
|
|
161
|
+
|
|
162
|
+
**Examples:**
|
|
163
|
+
|
|
164
|
+
**1. Fixed width (proportional height)**
|
|
165
|
+
Sets a specific width while maintaining the aspect ratio. Height adjusts proportionally.
|
|
166
|
+
|
|
167
|
+
```js
|
|
168
|
+
const result = await snapdom(element, {
|
|
169
|
+
width: 400 // Outputs a 400px-wide image with auto-scaled height
|
|
170
|
+
});
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
**2. Fixed height (proportional width)**
|
|
174
|
+
Sets a specific height while maintaining the aspect ratio. Width adjusts proportionally.
|
|
175
|
+
|
|
176
|
+
```js
|
|
177
|
+
const result = await snapdom(element, {
|
|
178
|
+
height: 200 // Outputs a 200px-tall image with auto-scaled width
|
|
179
|
+
});
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
**3. Fixed width and height (may distort image)**
|
|
183
|
+
Forces exact dimensions, potentially distorting the image if the aspect ratio differs.
|
|
184
|
+
|
|
185
|
+
```js
|
|
186
|
+
const result = await snapdom(element, {
|
|
187
|
+
width: 800, // Outputs an 800px × 200px image (may stretch/squish content)
|
|
188
|
+
height: 200
|
|
189
|
+
});
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
**Note:** If `scale` is different from 1, it takes priority over width and height.
|
|
193
|
+
Example: `{ scale: 3, width: 500 }` ignores width and scales the image 3x instead.
|
|
194
|
+
|
|
134
195
|
|
|
135
196
|
### Cross-Origin Images
|
|
136
197
|
|
|
137
|
-
By default, snapDOM loads images with `crossOrigin="anonymous"`.
|
|
198
|
+
By default, snapDOM loads images with `crossOrigin="anonymous"` or `crossOrigin="use-credentials"`. In case fails to get the images, `useProxy` can be used to deal with CORS images:
|
|
138
199
|
|
|
139
200
|
```js
|
|
140
201
|
const result = await snapdom(element, {
|
|
141
|
-
|
|
142
|
-
// Use credentials for same-origin images
|
|
143
|
-
if (url.startsWith(window.location.origin)) {
|
|
144
|
-
return "use-credentials";
|
|
145
|
-
}
|
|
146
|
-
// Use anonymous for cross-origin images
|
|
147
|
-
return "anonymous";
|
|
148
|
-
}
|
|
202
|
+
useProxy: 'your/proxy/' //Example: 'https://corsproxy.io/?url=' or 'https://api.allorigins.win/raw?url='
|
|
149
203
|
});
|
|
150
204
|
```
|
|
151
205
|
|
|
152
|
-
This is useful when your images require authentication or when dealing with credentialed requests.
|
|
153
206
|
|
|
154
207
|
### Download options
|
|
155
208
|
|
|
@@ -184,13 +237,13 @@ import { snapdom, preCache } from './snapdom.mjs';
|
|
|
184
237
|
|
|
185
238
|
* `embedFonts` *(boolean, default: true)* — Inlines non-icon fonts during preload.
|
|
186
239
|
* `reset` *(boolean, default: false)* — Clears all existing internal caches.
|
|
187
|
-
* `
|
|
240
|
+
* `useProxy` *(string)* — Proxy for handling CORS images as fallback.
|
|
188
241
|
|
|
189
242
|
|
|
190
243
|
## Features
|
|
191
244
|
|
|
192
245
|
* Captures **shadow DOM** and Web Components
|
|
193
|
-
* Supports `::before` and `::
|
|
246
|
+
* Supports `::before`, `::after` and `::first-letter` pseudo-elements
|
|
194
247
|
* Inlines background images and fonts
|
|
195
248
|
* Handles **Font Awesome**, **Material Icons**, and more
|
|
196
249
|
* `data-capture="exclude"` to ignore an element
|
|
@@ -198,50 +251,123 @@ import { snapdom, preCache } from './snapdom.mjs';
|
|
|
198
251
|
|
|
199
252
|
## Limitations
|
|
200
253
|
|
|
201
|
-
* External images
|
|
254
|
+
* External images shloud be CORS-accessible (use `useProxy` option for handling CORS denied)
|
|
202
255
|
* Iframes are not supported
|
|
203
256
|
* When WebP format is used on Safari, it will fallback to PNG rendering.
|
|
204
257
|
* `@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)
|
|
205
258
|
|
|
206
|
-
## Benchmarks
|
|
207
259
|
|
|
208
|
-
|
|
260
|
+
Of course! Here's the updated **README section in English**, with `modern-screenshot` removed and replaced by `html-to-image`:
|
|
209
261
|
|
|
262
|
+
---
|
|
210
263
|
|
|
211
|
-
|
|
264
|
+
## ⚡ Performance Benchmarks
|
|
212
265
|
|
|
213
|
-
|
|
214
|
-
| -------------------------------- | :---------------------: | :---------------: |
|
|
215
|
-
| Small element (200×100) | 6.46× faster | 32.27× faster |
|
|
216
|
-
| Modal size (400×300) | 7.28× faster | 32.66× faster |
|
|
217
|
-
| Page view (1200×800) | 13.17× faster | 35.29× faster |
|
|
218
|
-
| Large scroll area (2000×1500) | 38.23× faster | 68.85× faster |
|
|
219
|
-
| Very large element (4000×2000) | 93.31× faster | 133.12× faster |
|
|
220
|
-
| Complex small element (200×100) | 3.97× faster | 15.23× faster |
|
|
221
|
-
| Complex modal (400×300) | 2.32× faster | 5.33× faster |
|
|
222
|
-
| Complex page (1200×800) | 1.62× faster | 1.65× faster |
|
|
223
|
-
| Complex large scroll (2000×1500) | 1.66× faster | 1.24× faster |
|
|
224
|
-
| Complex very large (4000×2000) | 1.52× faster | 1.28× faster |
|
|
266
|
+
Snapdom has received **significant performance improvements** since version `v1.8.0`. The following benchmarks compare:
|
|
225
267
|
|
|
268
|
+
* **Snapdom (current)**
|
|
269
|
+
* **Snapdom v1.8.0**
|
|
270
|
+
* `html2canvas`
|
|
271
|
+
* `html-to-image`
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
### Simple elements
|
|
275
|
+
|
|
276
|
+
| Scenario | Snapdom (current) | Snapdom v1.8.0 | html2canvas | html-to-image |
|
|
277
|
+
| ------------------------ | ----------------- | -------------- | ----------- | ------------- |
|
|
278
|
+
| Small (200×100) | **0.4 ms** | 1.2 ms | 70.3 ms | 3.6 ms |
|
|
279
|
+
| Modal (400×300) | **0.4 ms** | 1.1 ms | 68.8 ms | 3.6 ms |
|
|
280
|
+
| Page View (1200×800) | **0.4 ms** | 1.0 ms | 100.5 ms | 3.4 ms |
|
|
281
|
+
| Large Scroll (2000×1500) | **0.4 ms** | 1.0 ms | 153.1 ms | 3.4 ms |
|
|
282
|
+
| Very Large (4000×2000) | **0.4 ms** | 1.0 ms | 278.9 ms | 4.3 ms |
|
|
283
|
+
|
|
284
|
+
---
|
|
285
|
+
|
|
286
|
+
### Complex elements
|
|
287
|
+
|
|
288
|
+
| Scenario | Snapdom (current) | Snapdom v1.8.0 | html2canvas | html-to-image |
|
|
289
|
+
| ------------------------ | ----------------- | -------------- | ----------- | ------------- |
|
|
290
|
+
| Small (200×100) | **1.1 ms** | 3.2 ms | 76.0 ms | 15.3 ms |
|
|
291
|
+
| Modal (400×300) | **4.5 ms** | 14.0 ms | 133.2 ms | 55.4 ms |
|
|
292
|
+
| Page View (1200×800) | **32.9 ms** | 113.6 ms | 303.4 ms | 369.1 ms |
|
|
293
|
+
| Large Scroll (2000×1500) | **133.9 ms** | 387.4 ms | 594.4 ms | 1,163.0 ms |
|
|
294
|
+
| Very Large (4000×2000) | **364.0 ms** | 1,200.4 ms | 1,380.8 ms | 3,023.9 ms |
|
|
295
|
+
|
|
296
|
+
---
|
|
297
|
+
|
|
298
|
+
### Summary
|
|
299
|
+
|
|
300
|
+
* Snapdom (current) is **2×–6× faster** than `v1.8.0`
|
|
301
|
+
* Up to **150× faster** than `html2canvas`
|
|
302
|
+
* Up to **8× faster** than `html-to-image` in large scenarios
|
|
303
|
+
|
|
304
|
+
<sub>Benchmarks run in Chromium using Vitest.<br>
|
|
305
|
+
Hardware: MacBook Air 2018.<br>
|
|
306
|
+
⚠️ Performance may vary depending on device.</sub>
|
|
307
|
+
|
|
308
|
+
---
|
|
226
309
|
|
|
227
310
|
### Run the benchmarks
|
|
228
311
|
|
|
229
|
-
|
|
312
|
+
```sh
|
|
313
|
+
git clone https://github.com/zumerlab/snapdom.git
|
|
314
|
+
cd snapdom
|
|
315
|
+
npm install
|
|
316
|
+
npm run test:benchmark
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
## Development
|
|
320
|
+
|
|
321
|
+
To contribute or build snapDOM locally:
|
|
230
322
|
|
|
231
323
|
```sh
|
|
324
|
+
# Clone the repository
|
|
232
325
|
git clone https://github.com/zumerlab/snapdom.git
|
|
233
326
|
cd snapdom
|
|
327
|
+
|
|
328
|
+
# Switch to dev branch
|
|
329
|
+
git checkout dev
|
|
330
|
+
|
|
331
|
+
# Install dependencies
|
|
234
332
|
npm install
|
|
333
|
+
|
|
334
|
+
# Compile the library (ESM, CJS, and minified versions)
|
|
335
|
+
npm run compile
|
|
336
|
+
|
|
337
|
+
# Run tests
|
|
338
|
+
npm test
|
|
339
|
+
|
|
340
|
+
# Run Benchmarks
|
|
235
341
|
npm run test:benchmark
|
|
236
342
|
```
|
|
237
343
|
|
|
238
|
-
|
|
344
|
+
The main entry point is in `src/`, and output bundles are generated in the `dist/` folder.
|
|
345
|
+
|
|
346
|
+
For detailed contribution guidelines, please see [CONTRIBUTING](https://github.com/zumerlab/snapdom/blob/main/CONTRIBUTING.md).
|
|
347
|
+
|
|
239
348
|
|
|
240
349
|
## Contributors 🙌
|
|
241
350
|
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
351
|
+
<!-- CONTRIBUTORS:START -->
|
|
352
|
+
<p>
|
|
353
|
+
<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>
|
|
354
|
+
<a href="https://github.com/tarwin" title="tarwin"><img src="https://avatars.githubusercontent.com/u/646149?v=4&s=100" style="border-radius:10px; width:60px; height:60px; object-fit:cover; margin:5px;" alt="tarwin"/></a>
|
|
355
|
+
<a href="https://github.com/17biubiu" title="17biubiu"><img src="https://avatars.githubusercontent.com/u/13295895?v=4&s=100" style="border-radius:10px; width:60px; height:60px; object-fit:cover; margin:5px;" alt="17biubiu"/></a>
|
|
356
|
+
<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>
|
|
357
|
+
<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>
|
|
358
|
+
<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>
|
|
359
|
+
<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>
|
|
360
|
+
<a href="https://github.com/simon1uo" title="simon1uo"><img src="https://avatars.githubusercontent.com/u/60037549?v=4&s=100" style="border-radius:10px; width:60px; height:60px; object-fit:cover; margin:5px;" alt="simon1uo"/></a>
|
|
361
|
+
<a href="https://github.com/titoBouzout" title="titoBouzout"><img src="https://avatars.githubusercontent.com/u/64156?v=4&s=100" style="border-radius:10px; width:60px; height:60px; object-fit:cover; margin:5px;" alt="titoBouzout"/></a>
|
|
362
|
+
<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>
|
|
363
|
+
</p>
|
|
364
|
+
<!-- CONTRIBUTORS:END -->
|
|
365
|
+
|
|
366
|
+
## 💖 Sponsors
|
|
367
|
+
|
|
368
|
+
Special thanks to [@megaphonecolin](https://github.com/megaphonecolin) for supporting this project!
|
|
369
|
+
|
|
370
|
+
If you'd like to support this project too, you can [become a sponsor](https://github.com/sponsors/tinchox5).
|
|
245
371
|
|
|
246
372
|
## License
|
|
247
373
|
|