@zumer/snapdom 1.9.11 → 1.9.12-dev.1

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
@@ -37,6 +37,9 @@ It captures any HTML element as a scalable SVG image, preserving styles, fonts,
37
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
+ * Support same-origin `ìframe`
41
+ * Support CSS counter() and counters()
42
+ * Support `...` line-clamp
40
43
 
41
44
  ## Demo
42
45
 
@@ -46,11 +49,10 @@ It captures any HTML element as a scalable SVG image, preserving styles, fonts,
46
49
  ## Table of Contents
47
50
 
48
51
  - [Installation](#installation)
49
- - [NPM / Yarn](#npm--yarn)
50
- - [CDN](#cdn)
51
- - [Script tag (local)](#script-tag-local)
52
- - [ES Module](#es-module)
53
- - [Module via CDN](#module-via-cdn)
52
+ - [NPM / Yarn (stable)](#npm--yarn-stable)
53
+ - [NPM / Yarn (dev builds)](#npm--yarn-dev-builds)
54
+ - [CDN (stable)](#cdn-stable)
55
+ - [CDN (dev builds)](#cdn-dev-builds)
54
56
  - [Basic usage](#basic-usage)
55
57
  - [Reusable capture](#reusable-capture)
56
58
  - [One-step shortcuts](#one-step-shortcuts)
@@ -82,50 +84,53 @@ It captures any HTML element as a scalable SVG image, preserving styles, fonts,
82
84
  - [License](#license)
83
85
 
84
86
 
87
+
85
88
  ## Installation
86
89
 
87
- ### NPM / Yarn
90
+ ### NPM / Yarn (stable)
88
91
 
89
- ```sh
92
+ ```bash
90
93
  npm i @zumer/snapdom
91
- ```
92
-
93
- ```sh
94
94
  yarn add @zumer/snapdom
95
95
  ```
96
96
 
97
- Then import it in your code:
97
+ ### NPM / Yarn (dev builds)
98
98
 
99
- ```js
100
- import { snapdom } from '@zumer/snapdom';
99
+ For early access to new features and fixes:
100
+
101
+ ```bash
102
+ npm i @zumer/snapdom@dev
103
+ yarn add @zumer/snapdom@dev
101
104
  ```
102
105
 
103
- ### CDN
106
+ ⚠️ The `@dev` tag usually includes improvements before they reach production, but may be less stable.
104
107
 
105
- ```html
106
- <script src="https://cdn.jsdelivr.net/npm/@zumer/snapdom/dist/snapdom.min.js"></script>
107
- ```
108
108
 
109
- ### Script tag (local)
109
+ ### CDN (stable)
110
110
 
111
111
  ```html
112
- <script src="snapdom.js"></script>
113
- ```
112
+ <!-- Minified UMD build -->
113
+ <script src="https://unpkg.com/@zumer/snapdom/dist/snapdom.min.js"></script>
114
114
 
115
- ### ES Module
116
-
117
- ```js
118
- import { snapdom } from './snapdom.mjs';
115
+ <!-- ES Module build -->
116
+ <script type="module">
117
+ import { snapdom } from "https://unpkg.com/@zumer/snapdom/dist/snapdom.mjs";
118
+ </script>
119
119
  ```
120
120
 
121
- ### Module via CDN
121
+ ### CDN (dev builds)
122
122
 
123
123
  ```html
124
+ <!-- Minified UMD build (dev) -->
125
+ <script src="https://unpkg.com/@zumer/snapdom@dev/dist/snapdom.min.js"></script>
126
+
127
+ <!-- ES Module build (dev) -->
124
128
  <script type="module">
125
- import { snapdom } from 'https://cdn.jsdelivr.net/npm/@zumer/snapdom/dist/snapdom.mjs';
129
+ import { snapdom } from "https://unpkg.com/@zumer/snapdom@dev/dist/snapdom.mjs";
126
130
  </script>
127
131
  ```
128
132
 
133
+
129
134
  ## Basic usage
130
135
 
131
136
  ### Reusable capture
@@ -202,9 +207,12 @@ All capture methods accept an `options` object:
202
207
  | `useProxy` | string | `''` | Proxy base for CORS fallbacks |
203
208
  | `type` | string | `svg` | Default Blob type (`svg`\|`png`\|`jpg`\|`webp`) |
204
209
  | `exclude` | string[] | - | CSS selectors to exclude |
210
+ | `excludeMode` | string | 'hide' | Controls how `exclude` works with nodes |
205
211
  | `filter` | function | - | Custom predicate `(el) => boolean` |
212
+ | `filterMode` | string | 'hide' | Controls how `filter` works with nodes |
206
213
  | `cache` | string | `"soft"` | Control internal caches: `disabled`, `soft`, `auto`, `full` |
207
- | `defaultImageUrl` | string \| function | - | Fallback image when an `<img>` fails. If a function is provided, it receives `{ width?, height?, src?, element }` and must return a URL (string or Promise<string>). Useful for placeholder services (e.g. `https://placehold.co/{width}x{height}`) |
214
+ | `placeholders` | boolean | `true` | Show placeholders for images and cross-origin iframes |
215
+ | `fallbackURL` | string \| function | - | Fallback image when an `<img>` fails. If a function is provided, it receives `{ width?, height?, src?, element }` and must return a URL (string or Promise<string>). Useful for placeholder services (e.g. `https://placehold.co/{width}x{height}`) |
208
216
 
209
217
  ### Fallback image on `<img>` load failure
210
218
 
@@ -213,20 +221,20 @@ Provide a default image for failed `<img>` loads. You can pass a fixed URL or a
213
221
  ```js
214
222
  // 1) Fixed URL fallback
215
223
  await snapdom.toImg(element, {
216
- defaultImageUrl: '/images/fallback.png'
224
+ fallbackURL: '/images/fallback.png'
217
225
  });
218
226
 
219
227
  // 2) Dynamic placeholder via callback
220
228
  await snapdom.toImg(element, {
221
- defaultImageUrl: ({ width = 300, height = 150 }) =>
222
- `https://placehold.co/${Math.round(width)}x${Math.round(height)}`
229
+ fallbackURL: ({ width: 300, height: 150 }) =>
230
+ `https://placehold.co/${width}x${height}`
223
231
  });
224
232
 
225
233
  // 3) With proxy (if your fallback host has no CORS)
226
234
  await snapdom.toImg(element, {
227
- defaultImageUrl: ({ width = 300, height = 150 }) =>
228
- `https://dummyimage.com/${Math.round(width)}x${Math.round(height)}/cccccc/666.png&text=img`,
229
- useProxy: 'https://corsproxy.io/?url='
235
+ fallbackURL: ({ width = 300, height = 150 }) =>
236
+ `https://dummyimage.com/${width}x${height}/cccccc/666.png&text=img`,
237
+ useProxy: 'https://proxy.corsfix.com/?'
230
238
  });
231
239
  ```
232
240
 
@@ -247,13 +255,11 @@ By default snapDOM tries `crossOrigin="anonymous"` (or `use-credentials` for sam
247
255
 
248
256
  ```js
249
257
  await snapdom.toPng(el, {
250
- useProxy: 'your-proxy' // Example 'https://api.allorigins.win/raw?url='
258
+ useProxy: 'https://proxy.corsfix.com/?' // Note: Any cors proxy could be used 'https://proxy.corsfix.com/?'
251
259
  });
252
260
  ```
253
261
 
254
- **Tips**
255
262
 
256
- * Keep the proxy **fast** and **cache-friendly** (adds big wins on repeated captures).
257
263
  * The proxy is only used as a **fallback**; same-origin and CORS-enabled assets skip it.
258
264
 
259
265
  ### Fonts
@@ -304,7 +310,9 @@ await snapdom.toPng(el, {
304
310
  ### Filtering nodes: `exclude` vs `filter`
305
311
 
306
312
  * `exclude`: remove by **selector**.
313
+ * `excludeMode`: `hide` applies `visibility:hidden` CSS rule on excluded nodes and the layout remains as the original. `remove` do not clone excluded nodes at all.
307
314
  * `filter`: advanced predicate per element (return `false` to drop).
315
+ * `filterMode`: `hide` applies `visibility:hidden` CSS rule on filtered nodes and the layout remains as the original. `remove` do not clone filtered nodes at all.
308
316
 
309
317
  **Example: filter out elements with `display:none`:**
310
318
  ```js
@@ -339,13 +347,13 @@ await preCache({
339
347
  root: document.body,
340
348
  embedFonts: true,
341
349
  localFonts: [{ family: 'Inter', src: '/fonts/Inter.woff2', weight: 400 }],
342
- useProxy: 'your-proxy'
350
+ useProxy: 'https://proxy.corsfix.com/?'
343
351
  });
344
352
  ```
345
353
 
346
354
  ### Cache control
347
355
 
348
- SnapDOM maintains internal caches for images, backgrounds, resources, styles, and fonts.
356
+ SnapDOM maintains internal caches for images, backgrounds, resources, styles, and fonts.
349
357
  You can control how they are cleared between captures using the `cache` option:
350
358
 
351
359
  | Mode | Description |
@@ -382,7 +390,7 @@ Values are **average capture time (ms)** → lower is better.
382
390
 
383
391
  ### Simple elements
384
392
 
385
- | Scenario | SnapDOM v1.9.10 | SnapDOM v1.9.9 | html2canvas | html-to-image |
393
+ | Scenario | SnapDOM current | SnapDOM v1.9.9 | html2canvas | html-to-image |
386
394
  | ------------------------ | --------------- | -------------- | ----------- | ------------- |
387
395
  | Small (200×100) | **0.5 ms** | 0.8 ms | 67.7 ms | 3.1 ms |
388
396
  | Modal (400×300) | **0.5 ms** | 0.8 ms | 75.5 ms | 3.6 ms |
@@ -394,7 +402,7 @@ Values are **average capture time (ms)** → lower is better.
394
402
 
395
403
  ### Complex elements
396
404
 
397
- | Scenario | SnapDOM v1.9.10 | SnapDOM v1.9.9 | html2canvas | html-to-image |
405
+ | Scenario | SnapDOM current | SnapDOM v1.9.9 | html2canvas | html-to-image |
398
406
  | ------------------------ | --------------- | -------------- | ----------- | ------------- |
399
407
  | Small (200×100) | **1.6 ms** | 3.3 ms | 68.0 ms | 14.3 ms |
400
408
  | Modal (400×300) | **2.9 ms** | 6.8 ms | 87.5 ms | 34.8 ms |