@zumer/snapdom 1.8.0 → 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 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,10 @@ 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|
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')` |
150
157
 
151
158
  ### Setting custom dimensions with width and height options
152
159
 
@@ -154,7 +161,7 @@ Use the `width` and `height` options to generate an image with specific dimensio
154
161
 
155
162
  **Examples:**
156
163
 
157
- **1. Fixed width (proportional Hhight)**
164
+ **1. Fixed width (proportional height)**
158
165
  Sets a specific width while maintaining the aspect ratio. Height adjusts proportionally.
159
166
 
160
167
  ```js
@@ -188,22 +195,14 @@ Example: `{ scale: 3, width: 500 }` ignores width and scales the image 3x instea
188
195
 
189
196
  ### Cross-Origin Images
190
197
 
191
- By default, snapDOM loads images with `crossOrigin="anonymous"`. You can customize this behavior using the `crossOrigin` option:
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:
192
199
 
193
200
  ```js
194
201
  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
- }
202
+ useProxy: 'your/proxy/' //Example: 'https://corsproxy.io/?url=' or 'https://api.allorigins.win/raw?url='
203
203
  });
204
204
  ```
205
205
 
206
- This is useful when your images require authentication or when dealing with credentialed requests.
207
206
 
208
207
  ### Download options
209
208
 
@@ -238,13 +237,13 @@ import { snapdom, preCache } from './snapdom.mjs';
238
237
 
239
238
  * `embedFonts` *(boolean, default: true)* — Inlines non-icon fonts during preload.
240
239
  * `reset` *(boolean, default: false)* — Clears all existing internal caches.
241
- * `crossOrigin` *(function)* — Function to determine CORS mode per image URL during preload.
240
+ * `useProxy` *(string)* — Proxy for handling CORS images as fallback.
242
241
 
243
242
 
244
243
  ## Features
245
244
 
246
245
  * Captures **shadow DOM** and Web Components
247
- * Supports `::before` and `::after` pseudo-elements
246
+ * Supports `::before`, `::after` and `::first-letter` pseudo-elements
248
247
  * Inlines background images and fonts
249
248
  * Handles **Font Awesome**, **Material Icons**, and more
250
249
  * `data-capture="exclude"` to ignore an element
@@ -252,34 +251,63 @@ import { snapdom, preCache } from './snapdom.mjs';
252
251
 
253
252
  ## Limitations
254
253
 
255
- * External images must be CORS-accessible (use `crossOrigin` option for credentialed requests)
254
+ * External images shloud be CORS-accessible (use `useProxy` option for handling CORS denied)
256
255
  * Iframes are not supported
257
256
  * When WebP format is used on Safari, it will fallback to PNG rendering.
258
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)
259
258
 
260
- ## Benchmarks
261
259
 
262
- `snapDOM` is not only highly accurate — it’s **extremely fast**.
260
+ Of course! Here's the updated **README section in English**, with `modern-screenshot` removed and replaced by `html-to-image`:
263
261
 
264
- Latest benchmarks show significant performance improvements against other libraries:
262
+ ---
265
263
 
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 |
264
+ ## ⚡ Performance Benchmarks
278
265
 
266
+ Snapdom has received **significant performance improvements** since version `v1.8.0`. The following benchmarks compare:
279
267
 
280
- ### Run the benchmarks
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
+ ---
281
297
 
282
- To run these benchmarks yourself:
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
+ ---
309
+
310
+ ### Run the benchmarks
283
311
 
284
312
  ```sh
285
313
  git clone https://github.com/zumerlab/snapdom.git
@@ -288,8 +316,6 @@ npm install
288
316
  npm run test:benchmark
289
317
  ```
290
318
 
291
- They execute in **headless Chromium** using real DOM nodes.
292
-
293
319
  ## Development
294
320
 
295
321
  To contribute or build snapDOM locally:
@@ -299,6 +325,9 @@ To contribute or build snapDOM locally:
299
325
  git clone https://github.com/zumerlab/snapdom.git
300
326
  cd snapdom
301
327
 
328
+ # Switch to dev branch
329
+ git checkout dev
330
+
302
331
  # Install dependencies
303
332
  npm install
304
333
 
@@ -322,14 +351,24 @@ For detailed contribution guidelines, please see [CONTRIBUTING](https://github.c
322
351
  <!-- CONTRIBUTORS:START -->
323
352
  <p>
324
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>
325
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>
326
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>
327
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>
328
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>
329
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>
330
363
  </p>
331
364
  <!-- CONTRIBUTORS:END -->
332
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).
371
+
333
372
  ## License
334
373
 
335
374
  MIT © Zumerlab