@zumer/snapdom 1.9.12-dev.0 → 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 +45 -41
- package/dist/snapdom.js +326 -58
- package/dist/snapdom.min.js +5 -5
- package/dist/snapdom.min.mjs +4 -4
- package/dist/snapdom.mjs +313 -50
- package/package.json +1 -1
- package/types/snapdom.d.ts +5 -5
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
|
-
- [
|
|
51
|
-
- [
|
|
52
|
-
- [
|
|
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
|
-
```
|
|
92
|
+
```bash
|
|
90
93
|
npm i @zumer/snapdom
|
|
91
|
-
```
|
|
92
|
-
|
|
93
|
-
```sh
|
|
94
94
|
yarn add @zumer/snapdom
|
|
95
95
|
```
|
|
96
96
|
|
|
97
|
-
|
|
97
|
+
### NPM / Yarn (dev builds)
|
|
98
98
|
|
|
99
|
-
|
|
100
|
-
|
|
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
|
-
|
|
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
|
-
###
|
|
109
|
+
### CDN (stable)
|
|
110
110
|
|
|
111
111
|
```html
|
|
112
|
-
|
|
113
|
-
|
|
112
|
+
<!-- Minified UMD build -->
|
|
113
|
+
<script src="https://unpkg.com/@zumer/snapdom/dist/snapdom.min.js"></script>
|
|
114
114
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
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
|
-
###
|
|
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
|
|
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,11 +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 |
|
|
205
|
-
| `excludeMode` | string | '
|
|
210
|
+
| `excludeMode` | string | 'hide' | Controls how `exclude` works with nodes |
|
|
206
211
|
| `filter` | function | - | Custom predicate `(el) => boolean` |
|
|
207
|
-
| `filterMode` | string | '
|
|
212
|
+
| `filterMode` | string | 'hide' | Controls how `filter` works with nodes |
|
|
208
213
|
| `cache` | string | `"soft"` | Control internal caches: `disabled`, `soft`, `auto`, `full` |
|
|
209
|
-
| `
|
|
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}`) |
|
|
210
216
|
|
|
211
217
|
### Fallback image on `<img>` load failure
|
|
212
218
|
|
|
@@ -215,20 +221,20 @@ Provide a default image for failed `<img>` loads. You can pass a fixed URL or a
|
|
|
215
221
|
```js
|
|
216
222
|
// 1) Fixed URL fallback
|
|
217
223
|
await snapdom.toImg(element, {
|
|
218
|
-
|
|
224
|
+
fallbackURL: '/images/fallback.png'
|
|
219
225
|
});
|
|
220
226
|
|
|
221
227
|
// 2) Dynamic placeholder via callback
|
|
222
228
|
await snapdom.toImg(element, {
|
|
223
|
-
|
|
224
|
-
`https://placehold.co/${
|
|
229
|
+
fallbackURL: ({ width: 300, height: 150 }) =>
|
|
230
|
+
`https://placehold.co/${width}x${height}`
|
|
225
231
|
});
|
|
226
232
|
|
|
227
233
|
// 3) With proxy (if your fallback host has no CORS)
|
|
228
234
|
await snapdom.toImg(element, {
|
|
229
|
-
|
|
230
|
-
`https://dummyimage.com/${
|
|
231
|
-
useProxy: 'https://
|
|
235
|
+
fallbackURL: ({ width = 300, height = 150 }) =>
|
|
236
|
+
`https://dummyimage.com/${width}x${height}/cccccc/666.png&text=img`,
|
|
237
|
+
useProxy: 'https://proxy.corsfix.com/?'
|
|
232
238
|
});
|
|
233
239
|
```
|
|
234
240
|
|
|
@@ -249,13 +255,11 @@ By default snapDOM tries `crossOrigin="anonymous"` (or `use-credentials` for sam
|
|
|
249
255
|
|
|
250
256
|
```js
|
|
251
257
|
await snapdom.toPng(el, {
|
|
252
|
-
useProxy: '
|
|
258
|
+
useProxy: 'https://proxy.corsfix.com/?' // Note: Any cors proxy could be used 'https://proxy.corsfix.com/?'
|
|
253
259
|
});
|
|
254
260
|
```
|
|
255
261
|
|
|
256
|
-
**Tips**
|
|
257
262
|
|
|
258
|
-
* Keep the proxy **fast** and **cache-friendly** (adds big wins on repeated captures).
|
|
259
263
|
* The proxy is only used as a **fallback**; same-origin and CORS-enabled assets skip it.
|
|
260
264
|
|
|
261
265
|
### Fonts
|
|
@@ -306,9 +310,9 @@ await snapdom.toPng(el, {
|
|
|
306
310
|
### Filtering nodes: `exclude` vs `filter`
|
|
307
311
|
|
|
308
312
|
* `exclude`: remove by **selector**.
|
|
309
|
-
* `excludeMode`: `
|
|
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.
|
|
310
314
|
* `filter`: advanced predicate per element (return `false` to drop).
|
|
311
|
-
* `filterMode`: `
|
|
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.
|
|
312
316
|
|
|
313
317
|
**Example: filter out elements with `display:none`:**
|
|
314
318
|
```js
|
|
@@ -343,7 +347,7 @@ await preCache({
|
|
|
343
347
|
root: document.body,
|
|
344
348
|
embedFonts: true,
|
|
345
349
|
localFonts: [{ family: 'Inter', src: '/fonts/Inter.woff2', weight: 400 }],
|
|
346
|
-
useProxy: '
|
|
350
|
+
useProxy: 'https://proxy.corsfix.com/?'
|
|
347
351
|
});
|
|
348
352
|
```
|
|
349
353
|
|