@zumer/snapdom 1.8.0 → 1.9.3

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 CHANGED
@@ -19,6 +19,10 @@
19
19
  <a href="https://github.com/zumerlab/snapdom/network/members">
20
20
  <img alt="GitHub forks" src="https://img.shields.io/github/forks/zumerlab/snapdom?style=flat-square&label=Forks">
21
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
+
22
26
  <a href="https://github.com/zumerlab/snapdom/blob/main/LICENSE">
23
27
  <img alt="License" src="https://img.shields.io/github/license/zumerlab/snapdom?style=flat-square">
24
28
  </a>
@@ -146,7 +150,7 @@ All capture methods accept an `options` object:
146
150
  | `height` | number | - | Output specific height size |
147
151
  | `backgroundColor` | string | `"#fff"` | Fallback color for JPG/WebP |
148
152
  | `quality` | number | `1` | Quality for JPG/WebP (0 to 1) |
149
- | `crossOrigin` | function | - | Function to determine CORS mode per image URL |
153
+ | `useProxy` | string | '' | Specify a proxy for handling CORS images as fallback|
150
154
 
151
155
  ### Setting custom dimensions with width and height options
152
156
 
@@ -154,7 +158,7 @@ Use the `width` and `height` options to generate an image with specific dimensio
154
158
 
155
159
  **Examples:**
156
160
 
157
- **1. Fixed width (proportional Hhight)**
161
+ **1. Fixed width (proportional height)**
158
162
  Sets a specific width while maintaining the aspect ratio. Height adjusts proportionally.
159
163
 
160
164
  ```js
@@ -188,22 +192,14 @@ Example: `{ scale: 3, width: 500 }` ignores width and scales the image 3x instea
188
192
 
189
193
  ### Cross-Origin Images
190
194
 
191
- By default, snapDOM loads images with `crossOrigin="anonymous"`. You can customize this behavior using the `crossOrigin` option:
195
+ 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:
192
196
 
193
197
  ```js
194
198
  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
- }
199
+ useProxy: 'your/proxy/' //Example: 'https://corsproxy.io/?url=' or 'https://api.allorigins.win/raw?url='
203
200
  });
204
201
  ```
205
202
 
206
- This is useful when your images require authentication or when dealing with credentialed requests.
207
203
 
208
204
  ### Download options
209
205
 
@@ -238,13 +234,13 @@ import { snapdom, preCache } from './snapdom.mjs';
238
234
 
239
235
  * `embedFonts` *(boolean, default: true)* — Inlines non-icon fonts during preload.
240
236
  * `reset` *(boolean, default: false)* — Clears all existing internal caches.
241
- * `crossOrigin` *(function)* — Function to determine CORS mode per image URL during preload.
237
+ * `useProxy` *(string)* — Proxy for handling CORS images as fallback.
242
238
 
243
239
 
244
240
  ## Features
245
241
 
246
242
  * Captures **shadow DOM** and Web Components
247
- * Supports `::before` and `::after` pseudo-elements
243
+ * Supports `::before`, `::after` and `::first-letter` pseudo-elements
248
244
  * Inlines background images and fonts
249
245
  * Handles **Font Awesome**, **Material Icons**, and more
250
246
  * `data-capture="exclude"` to ignore an element
@@ -252,29 +248,58 @@ import { snapdom, preCache } from './snapdom.mjs';
252
248
 
253
249
  ## Limitations
254
250
 
255
- * External images must be CORS-accessible (use `crossOrigin` option for credentialed requests)
251
+ * External images shloud be CORS-accessible (use `useProxy` option for handling CORS denied)
256
252
  * Iframes are not supported
257
253
  * When WebP format is used on Safari, it will fallback to PNG rendering.
258
254
  * `@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)
259
255
 
260
- ## Benchmarks
261
256
 
262
- `snapDOM` is not only highly accurate — it’s **extremely fast**.
257
+ ## ⚡ Performance Benchmarks
258
+
259
+ Snapdom has received **major performance improvements** since version `v1.8.0`. Below are benchmark results comparing:
260
+
261
+ * 🔷 **Snapdom (current)**
262
+ * 🔸 **Snapdom v1.8.0**
263
+ * 🟥 `html2canvas`
264
+ * 🟨 `modern-screenshot`
265
+
266
+ Each benchmark shows the **fastest observed time** (lower is better), measured in **milliseconds (ms)**.
267
+
268
+ ---
269
+
270
+ ### Simple elements
271
+
272
+ | Scenario | Snapdom (current) | Snapdom v1.8.0 | html2canvas | modern-screenshot |
273
+ | ------------------------ | ----------------- | -------------- | ----------- | ----------------- |
274
+ | Small (200×100) | **0.4 ms** | 1.2 ms | 70.3 ms | 11.9 ms |
275
+ | Modal (400×300) | **0.4 ms** | 1.1 ms | 68.8 ms | 14.1 ms |
276
+ | Page View (1200×800) | **0.4 ms** | 1.0 ms | 100.5 ms | 34.2 ms |
277
+ | Large Scroll (2000×1500) | **0.4 ms** | 1.0 ms | 153.1 ms | 77.8 ms |
278
+ | Very Large (4000×2000) | **0.4 ms** | 1.0 ms | 278.9 ms | 194.7 ms |
263
279
 
264
- Latest benchmarks show significant performance improvements against other libraries:
280
+ ---
265
281
 
266
- | Scenario | vs. `modern-screenshot` | vs. `html2canvas` |
267
- | -------------------------------- | :---------------------: | :---------------: |
268
- | Small element (200×100) | 6.46× faster | 32.27× faster |
269
- | Modal size (400×300) | 7.28× faster | 32.66× faster |
270
- | Page view (1200×800) | 13.17× faster | 35.29× faster |
271
- | Large scroll area (2000×1500) | 38.23× faster | 68.85× faster |
272
- | Very large element (4000×2000) | 93.31× faster | 133.12× faster |
273
- | Complex small element (200×100) | 3.97× faster | 15.23× faster |
274
- | Complex modal (400×300) | 2.32× faster | 5.33× faster |
275
- | Complex page (1200×800) | 1.62× faster | 1.65× faster |
276
- | Complex large scroll (2000×1500) | 1.66× faster | 1.24× faster |
277
- | Complex very large (4000×2000) | 1.52× faster | 1.28× faster |
282
+ ### Complex elements
283
+
284
+ | Scenario | Snapdom (current) | Snapdom v1.8.0 | html2canvas | modern-screenshot |
285
+ | ------------------------ | ----------------- | -------------- | ----------- | ----------------- |
286
+ | Small (200×100) | **1.1 ms** | 3.2 ms | 72.5 ms | 16.1 ms |
287
+ | Modal (400×300) | **4.5 ms** | 14.0 ms | 90.1 ms | 34.6 ms |
288
+ | Page View (1200×800) | **32.9 ms** | 113.6 ms | 196.1 ms | 181.1 ms |
289
+ | Large Scroll (2000×1500) | **133.9 ms** | 387.4 ms | 446.6 ms | 635.9 ms |
290
+ | Very Large (4000×2000) | **364.0 ms** | 1,200.4 ms | 1,275.4 ms | 1,685.6 ms |
291
+
292
+ ---
293
+
294
+ ### Summary
295
+
296
+ * Snapdom (current) is consistently **2×–4× faster** than `v1.8.0`
297
+ * Up to **500× faster** than `html2canvas`
298
+ * Also significantly faster than `modern-screenshot`, especially for large DOMs
299
+
300
+ <sub>All benchmarks were run in Chromium using Vitest.<br>
301
+ Tests were performed on a 2018 MacBook Air.<br>
302
+ ⚠️ Performance can be even better on more modern hardware.</sub>
278
303
 
279
304
 
280
305
  ### Run the benchmarks
@@ -322,14 +347,22 @@ For detailed contribution guidelines, please see [CONTRIBUTING](https://github.c
322
347
  <!-- CONTRIBUTORS:START -->
323
348
  <p>
324
349
  <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>
350
+ <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>
325
351
  <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
352
  <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
353
  <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
354
  <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>
355
+ <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>
329
356
  <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
357
  </p>
331
358
  <!-- CONTRIBUTORS:END -->
332
359
 
360
+ ## 💖 Sponsors
361
+
362
+ Special thanks to [@megaphonecolin](https://github.com/megaphonecolin) for supporting this project!
363
+
364
+ If you'd like to support this project too, you can [become a sponsor](https://github.com/sponsors/tinchox5).
365
+
333
366
  ## License
334
367
 
335
368
  MIT © Zumerlab