@@ -10,37 +10,57 @@ It converts any HTML element into a scalable SVG image, preserving styles, fonts
1010- ⚡ Lightweight, no dependencies
1111- 📦 100% based on standard Web APIs
1212
13+ ---
14+ ¡Obvio, Martín! 🔥
15+ Acá te integro la parte de ** Installation** agregando también la opción ** CDN** , de manera prolija y siguiendo tu estilo:
16+
1317---
1418
1519## Installation
1620
17- You can use ** snapDOM** either by including it as a script or importing it as a module.
21+ You can use ** snapDOM** by including it via ** CDN ** , ** script tag ** , or by ** importing it as a module** .
1822
19- ### Script tag
23+ ### CDN
24+
25+ ``` html
26+ <script src =" https://unpkg.com/@zumer/snapdom@latest/snapdom.min.js" ></script >
27+ ```
28+
29+ ---
30+
31+ ### Script tag (local)
2032
2133``` html
2234<script src =" snapdom.js" ></script >
2335```
2436
25- The global object ` captureAs ` will be available.
37+ The global object ` snapdom ` will be available.
2638
2739---
2840
2941### ES Module
3042
3143``` javascript
32- import { captureAs } from ' ./snapdom.esm.js' ;
44+ import { snapdom } from ' ./snapdom.mjs' ;
45+ ```
46+
47+ ### Script Tag (Type Module)
48+
49+ ```
50+ <script type="module">
51+ import { snapdom } from 'https://unpkg.com/@zumer/snapdom@latest/snapdom.mjs';
52+ </script>
3353```
3454
35- Now you can call ` captureAs.dataURL( )` , ` captureAs.png( )` , etc., directly in your JavaScript.
55+ Now you can call ` snapdom(el )` , ` snapdom.toPng(el )` , etc., directly in your JavaScript.
3656
3757---
3858
3959## Basic usage
4060
4161``` javascript
4262// Capture an element as SVG Data URL
43- const svgDataUrl = await captureAs . dataURL (document .querySelector (" #myElement" ));
63+ const svgDataUrl = await snapdom (document .querySelector (" #myElement" ));
4464
4565// Insert the captured image into the page
4666const img = new Image ();
@@ -52,17 +72,17 @@ document.body.appendChild(img);
5272
5373## API
5474
55- The main API is exposed as ` captureAs ` and offers multiple capture methods:
75+ The main API is exposed as ` snapdom ` and offers multiple capture methods:
5676
5777| Method | Description | Returns |
5878| :-------| :------------| :--------|
59- | ` captureAs.dataURL (el, scale?)` | Captures as SVG Data URL | ` Promise<string> ` |
60- | ` captureAs.img (el, scale?)` | Captures as ` HTMLImageElement ` (SVG) | ` Promise<HTMLImageElement> ` |
61- | ` captureAs.canvas (el, scale?)` | Captures as ` HTMLCanvasElement ` | ` Promise<HTMLCanvasElement> ` |
62- | ` captureAs.png (el, scale?)` | Captures as PNG image (` Image ` ) | ` Promise<HTMLImageElement> ` |
63- | ` captureAs.jpg (el, scale?, quality?)` | Captures as JPG image (` Image ` ) | ` Promise<HTMLImageElement> ` |
64- | ` captureAs.webp (el, scale?, quality?)` | Captures as WebP image (` Image ` ) | ` Promise<HTMLImageElement> ` |
65- | ` captureAs.blob (el, scale?)` | Captures as SVG ` Blob ` | ` Promise<Blob> ` |
79+ | ` snapdom (el, scale?)` | Captures as SVG Data URL | ` Promise<string> ` |
80+ | ` snapdom.toImg (el, scale?)` | Captures as ` HTMLImageElement ` (SVG) | ` Promise<HTMLImageElement> ` |
81+ | ` snapdom.toCanvas (el, scale?)` | Captures as ` HTMLCanvasElement ` | ` Promise<HTMLCanvasElement> ` |
82+ | ` snapdom.toPng (el, scale?)` | Captures as PNG image (` Image ` ) | ` Promise<HTMLImageElement> ` |
83+ | ` snapdom.toJpg (el, scale?, quality?)` | Captures as JPG image (` Image ` ) | ` Promise<HTMLImageElement> ` |
84+ | ` snapdom.toWebp (el, scale?, quality?)` | Captures as WebP image (` Image ` ) | ` Promise<HTMLImageElement> ` |
85+ | ` snapdom.toBlob (el, scale?)` | Captures as SVG ` Blob ` | ` Promise<Blob> ` |
6686
6787** Parameters:**
6888- ` el ` : DOM element to capture.
@@ -92,12 +112,12 @@ The main API is exposed as `captureAs` and offers multiple capture methods:
92112</div >
93113
94114<script type =" module" >
95- import { captureAs } from ' ./snapdom.esm.js' ;
115+ import { snapdom } from ' ./snapdom.esm.js' ;
96116
97117 const button = document .createElement (' button' );
98118 button .textContent = " Capture" ;
99119 button .onclick = async () => {
100- const img = await captureAs . png (document .getElementById (' captureMe' ), 2 );
120+ const img = await snapdom . toPng (document .getElementById (' captureMe' ), 2 );
101121 document .body .appendChild (img);
102122 };
103123 document .body .appendChild (button);
@@ -110,7 +130,31 @@ The main API is exposed as `captureAs` and offers multiple capture methods:
110130
111131- External images must be CORS-accessible.
112132- Fonts must be fully loaded before capturing (` document.fonts.ready ` is automatically awaited).
113- - Very dynamic or complex layouts might require manual style adjustments.
133+ - Iframes are not captured.
134+
135+ ---
136+
137+ ## Benchmark
138+
139+ ` snapDOM ` is not only highly accurate — it's also ** extremely fast** at capturing large or complex DOM structures.
140+
141+ In benchmark tests against popular libraries:
142+
143+ | Element Size | Winner | Compared to ` modern-screenshot ` | Compared to ` html2canvas ` |
144+ | :------------:| :------:| :-------------------------------:| :-------------------------:|
145+ | 200×100 (Small) | ` modern-screenshot ` | 1.18× faster | 4.46× faster |
146+ | 400×300 (Modal) | ` snapDOM ` | 1.04× faster | 4.07× faster |
147+ | 1200×800 (Page view) | ` snapDOM ` | 2.43× faster | 5.74× faster |
148+ | 2000×1500 (Large scroll area) | ` snapDOM ` | 5.02× faster | 9.35× faster |
149+ | 4000×2000 (Very large) | ` snapDOM ` | 11.35× faster | 15.98× faster |
150+
151+ ✅ ** Key insight** :
152+ While ` modern-screenshot ` is yet slightly faster for very small elements, ** snapDOM dramatically outperforms all others as the DOM size grows** .
153+
154+ ✅ ** Perfect for:**
155+ - Capturing full-page views
156+ - Capturing modal windows
157+ - Complex layouts with custom fonts, backgrounds, or shadow DOM
114158
115159---
116160
0 commit comments