@zumer/snapdom 1.9.6 → 1.9.8
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 +57 -9
- package/dist/snapdom.js +240 -139
- package/dist/snapdom.min.js +3 -3
- package/dist/snapdom.min.mjs +3 -3
- package/dist/snapdom.mjs +230 -137
- package/package.json +1 -1
- package/types/snapdom.d.ts +1 -0
package/README.md
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
# snapDOM
|
|
2
|
-
|
|
3
1
|
<p align="center">
|
|
4
2
|
<a href="http://zumerlab.github.io/snapdom">
|
|
5
|
-
<img src="https://raw.githubusercontent.com/zumerlab/snapdom/main/docs/assets/
|
|
3
|
+
<img src="https://raw.githubusercontent.com/zumerlab/snapdom/main/docs/assets/newhero.png" width="70%">
|
|
6
4
|
</a>
|
|
7
5
|
</p>
|
|
8
6
|
|
|
@@ -28,13 +26,15 @@
|
|
|
28
26
|
</a>
|
|
29
27
|
</p>
|
|
30
28
|
|
|
29
|
+
# snapDOM
|
|
30
|
+
|
|
31
31
|
**snapDOM** is a fast and accurate DOM-to-image capture tool built for **Zumly**, a zoom-based view transition framework.
|
|
32
32
|
|
|
33
33
|
It captures any HTML element as a scalable SVG image, preserving styles, fonts, background images, pseudo-elements, and even shadow DOM. It also supports export to raster image formats and canvas.
|
|
34
34
|
|
|
35
35
|
* 📸 Full DOM capture
|
|
36
36
|
* 🎨 Embedded styles, pseudo-elements, and fonts
|
|
37
|
-
* 🖼️ Export to SVG, PNG, JPG, WebP, or
|
|
37
|
+
* 🖼️ Export to SVG, PNG, JPG, WebP, `canvas`, or Blob
|
|
38
38
|
* ⚡ Ultra fast, no dependencies
|
|
39
39
|
* 📦 100% based on standard Web APIs
|
|
40
40
|
|
|
@@ -54,6 +54,12 @@ npm i @zumer/snapdom
|
|
|
54
54
|
yarn add @zumer/snapdom
|
|
55
55
|
```
|
|
56
56
|
|
|
57
|
+
Then import it in your code:
|
|
58
|
+
|
|
59
|
+
```js
|
|
60
|
+
import { snapdom } from '@zumer/snapdom';
|
|
61
|
+
```
|
|
62
|
+
|
|
57
63
|
### CDN
|
|
58
64
|
|
|
59
65
|
```html
|
|
@@ -116,8 +122,8 @@ Returns an object with reusable export methods:
|
|
|
116
122
|
toRaw(): string;
|
|
117
123
|
toImg(): Promise<HTMLImageElement>;
|
|
118
124
|
toCanvas(): Promise<HTMLCanvasElement>;
|
|
119
|
-
toBlob(): Promise<Blob>;
|
|
120
|
-
toPng(): Promise<HTMLImageElement>;
|
|
125
|
+
toBlob(options?): Promise<Blob>;
|
|
126
|
+
toPng(options?): Promise<HTMLImageElement>;
|
|
121
127
|
toJpg(options?): Promise<HTMLImageElement>;
|
|
122
128
|
toWebp(options?): Promise<HTMLImageElement>;
|
|
123
129
|
download(options?): Promise<void>;
|
|
@@ -146,6 +152,7 @@ All capture methods accept an `options` object:
|
|
|
146
152
|
| `fast` | boolean | `true` | Skips idle delay for faster results |
|
|
147
153
|
| `embedFonts` | boolean | `false` | Inlines fonts (icon fonts always embedded) |
|
|
148
154
|
| `scale` | number | `1` | Output scale multiplier |
|
|
155
|
+
| `dpr` | number | `devicePixelRatio` | Device pixel ratio |
|
|
149
156
|
| `width` | number | - | Output specific width size |
|
|
150
157
|
| `height` | number | - | Output specific height size |
|
|
151
158
|
| `backgroundColor` | string | `"#fff"` | Fallback color for JPG/WebP |
|
|
@@ -217,7 +224,7 @@ const result = await snapdom(element, {
|
|
|
217
224
|
|
|
218
225
|
### `preCache()` – Optional helper
|
|
219
226
|
|
|
220
|
-
The `preCache()` function can be used to load external resources (like images and fonts) in advance. It is specially useful when the element to
|
|
227
|
+
The `preCache()` function can be used to load external resources (like images and fonts) in advance. It is specially useful when the element to capture is big and complex.
|
|
221
228
|
|
|
222
229
|
```js
|
|
223
230
|
import { preCache } from '@zumer/snapdom';
|
|
@@ -236,7 +243,6 @@ import { snapdom, preCache } from './snapdom.mjs';
|
|
|
236
243
|
**Options for `preCache()`:**
|
|
237
244
|
|
|
238
245
|
* `embedFonts` *(boolean, default: true)* — Inlines non-icon fonts during preload.
|
|
239
|
-
* `reset` *(boolean, default: false)* — Clears all existing internal caches.
|
|
240
246
|
* `useProxy` *(string)* — Proxy for handling CORS images as fallback.
|
|
241
247
|
|
|
242
248
|
|
|
@@ -251,7 +257,7 @@ import { snapdom, preCache } from './snapdom.mjs';
|
|
|
251
257
|
|
|
252
258
|
## Limitations
|
|
253
259
|
|
|
254
|
-
* External images
|
|
260
|
+
* External images should be CORS-accessible (use `useProxy` option for handling CORS denied)
|
|
255
261
|
* Iframes are not supported
|
|
256
262
|
* When WebP format is used on Safari, it will fallback to PNG rendering.
|
|
257
263
|
* `@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)
|
|
@@ -312,6 +318,36 @@ npm install
|
|
|
312
318
|
npm run test:benchmark
|
|
313
319
|
```
|
|
314
320
|
|
|
321
|
+
|
|
322
|
+
## Roadmap
|
|
323
|
+
|
|
324
|
+
Planned improvements for future versions of SnapDOM:
|
|
325
|
+
|
|
326
|
+
* [ ] **Implement plugin system**
|
|
327
|
+
SnapDOM will support external plugins to extend or override internal behavior (e.g. custom node transformers, exporters, or filters).
|
|
328
|
+
|
|
329
|
+
* [ ] **Refactor to modular architecture**
|
|
330
|
+
Internal logic will be split into smaller, focused modules to improve maintainability and code reuse.
|
|
331
|
+
|
|
332
|
+
* [X] **Decouple internal logic from global options**
|
|
333
|
+
Functions will be redesigned to avoid relying directly on `options`. A centralized capture context will improve clarity, autonomy, and testability. See [`next` branch](https://github.com/zumerlab/snapdom/tree/main)
|
|
334
|
+
|
|
335
|
+
* [ ] **Expose cache control**
|
|
336
|
+
Users will be able to manually clear image and font caches or configure their own caching strategies.
|
|
337
|
+
|
|
338
|
+
* [ ] **Auto font preloading**
|
|
339
|
+
Required fonts will be automatically detected and preloaded before capture, reducing the need for manual `preCache()` calls.
|
|
340
|
+
|
|
341
|
+
* [ ] **Document plugin development**
|
|
342
|
+
A full guide will be provided for creating and registering custom SnapDOM plugins.
|
|
343
|
+
|
|
344
|
+
* [ ] **Make export utilities tree-shakeable**
|
|
345
|
+
Export functions like `toPng`, `toJpg`, `toBlob`, etc. will be restructured into independent modules to support tree shaking and minimal builds.
|
|
346
|
+
|
|
347
|
+
Have ideas or feature requests?
|
|
348
|
+
Feel free to share suggestions or feedback in [GitHub Discussions](https://github.com/zumerlab/snapdom/discussions).
|
|
349
|
+
|
|
350
|
+
|
|
315
351
|
## Development
|
|
316
352
|
|
|
317
353
|
To contribute or build snapDOM locally:
|
|
@@ -352,13 +388,21 @@ For detailed contribution guidelines, please see [CONTRIBUTING](https://github.c
|
|
|
352
388
|
<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>
|
|
353
389
|
<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>
|
|
354
390
|
<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>
|
|
391
|
+
<a href="https://github.com/av01d" title="av01d"><img src="https://avatars.githubusercontent.com/u/6247646?v=4&s=100" style="border-radius:10px; width:60px; height:60px; object-fit:cover; margin:5px;" alt="av01d"/></a>
|
|
392
|
+
<a href="https://github.com/CHOYSEN" title="CHOYSEN"><img src="https://avatars.githubusercontent.com/u/25995358?v=4&s=100" style="border-radius:10px; width:60px; height:60px; object-fit:cover; margin:5px;" alt="CHOYSEN"/></a>
|
|
355
393
|
<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>
|
|
356
394
|
<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>
|
|
357
395
|
<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>
|
|
358
396
|
<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>
|
|
397
|
+
<a href="https://github.com/sharuzzaman" title="sharuzzaman"><img src="https://avatars.githubusercontent.com/u/7421941?v=4&s=100" style="border-radius:10px; width:60px; height:60px; object-fit:cover; margin:5px;" alt="sharuzzaman"/></a>
|
|
359
398
|
<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>
|
|
360
399
|
<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>
|
|
361
400
|
<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>
|
|
401
|
+
<a href="https://github.com/miusuncle" title="miusuncle"><img src="https://avatars.githubusercontent.com/u/7549857?v=4&s=100" style="border-radius:10px; width:60px; height:60px; object-fit:cover; margin:5px;" alt="miusuncle"/></a>
|
|
402
|
+
<a href="https://github.com/rbbydotdev" title="rbbydotdev"><img src="https://avatars.githubusercontent.com/u/101137670?v=4&s=100" style="border-radius:10px; width:60px; height:60px; object-fit:cover; margin:5px;" alt="rbbydotdev"/></a>
|
|
403
|
+
<a href="https://github.com/zhanghaotian2018" title="zhanghaotian2018"><img src="https://avatars.githubusercontent.com/u/169218899?v=4&s=100" style="border-radius:10px; width:60px; height:60px; object-fit:cover; margin:5px;" alt="zhanghaotian2018"/></a>
|
|
404
|
+
<a href="https://github.com/kohaiy" title="kohaiy"><img src="https://avatars.githubusercontent.com/u/15622127?v=4&s=100" style="border-radius:10px; width:60px; height:60px; object-fit:cover; margin:5px;" alt="kohaiy"/></a>
|
|
405
|
+
<a href="https://github.com/fu050409" title="fu050409"><img src="https://avatars.githubusercontent.com/u/46275354?v=4&s=100" style="border-radius:10px; width:60px; height:60px; object-fit:cover; margin:5px;" alt="fu050409"/></a>
|
|
362
406
|
</p>
|
|
363
407
|
<!-- CONTRIBUTORS:END -->
|
|
364
408
|
|
|
@@ -368,6 +412,10 @@ Special thanks to [@megaphonecolin](https://github.com/megaphonecolin) for suppo
|
|
|
368
412
|
|
|
369
413
|
If you'd like to support this project too, you can [become a sponsor](https://github.com/sponsors/tinchox5).
|
|
370
414
|
|
|
415
|
+
## Star History
|
|
416
|
+
|
|
417
|
+
[](https://www.star-history.com/#zumerlab/snapdom&Date)
|
|
418
|
+
|
|
371
419
|
## License
|
|
372
420
|
|
|
373
421
|
MIT © Zumerlab
|