@zumer/snapdom 1.9.10-dev.0 → 1.9.10-dev.2

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
@@ -1,6 +1,6 @@
1
1
  <p align="center">
2
2
  <a href="http://zumerlab.github.io/snapdom">
3
- <img src="https://raw.githubusercontent.com/zumerlab/snapdom/main/docs/assets/newhero.png" width="70%">
3
+ <img src="https://raw.githubusercontent.com/zumerlab/snapdom/main/docs/assets/newhero.png" width="80%">
4
4
  </a>
5
5
  </p>
6
6
 
@@ -164,6 +164,36 @@ All capture methods accept an `options` object:
164
164
  | `exclude` | string[] | - | CSS selectors to exclude |
165
165
  | `filter` | function | - | Custom predicate `(el) => boolean` |
166
166
  | `cache` | string | `"soft"` | Control internal caches: `disabled`, `soft`, `auto`, `full` |
167
+ | `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}`) |
168
+
169
+ ### Fallback image on `<img>` load failure
170
+
171
+ Provide a default image for failed `<img>` loads. You can pass a fixed URL or a callback that receives measured dimensions and returns a URL (handy to generate dynamic placeholders).
172
+
173
+ ```js
174
+ // 1) Fixed URL fallback
175
+ await snapdom.toImg(element, {
176
+ defaultImageUrl: '/images/fallback.png'
177
+ });
178
+
179
+ // 2) Dynamic placeholder via callback
180
+ await snapdom.toImg(element, {
181
+ defaultImageUrl: ({ width = 300, height = 150 }) =>
182
+ `https://placehold.co/${Math.round(width)}x${Math.round(height)}`
183
+ });
184
+
185
+ // 3) With proxy (if your fallback host has no CORS)
186
+ await snapdom.toImg(element, {
187
+ defaultImageUrl: ({ width = 300, height = 150 }) =>
188
+ `https://dummyimage.com/${Math.round(width)}x${Math.round(height)}/cccccc/666.png&text=img`,
189
+ useProxy: 'https://corsproxy.io/?url='
190
+ });
191
+ ```
192
+
193
+ Notes:
194
+ - If the fallback image also fails to load, snapDOM replaces the `<img>` with a placeholder block preserving width/height.
195
+ - Width/height used by the callback are gathered from the original element (dataset, style/attrs, etc.) when available.
196
+
167
197
 
168
198
  ### Dimensions (`scale`, `width`, `height`)
169
199
 
@@ -280,7 +310,7 @@ You can control how they are cleared between captures using the `cache` option:
280
310
 
281
311
  | Mode | Description |
282
312
  | ----------- | --------------------------------------------------------------------------- |
283
- | `"disabled"`| No cache: clears absolutely everything on every capture |
313
+ | `"disabled"`| No cache |
284
314
  | `"soft"` | Clears session caches (`styleMap`, `nodeMap`, `styleCache`) _(default)_ |
285
315
  | `"auto"` | Minimal cleanup: only clears transient maps |
286
316
  | `"full"` | Keeps all caches (nothing is cleared, maximum performance) |
@@ -301,7 +331,6 @@ await snapdom.toPng(el, { cache: 'disabled' });
301
331
  ## Limitations
302
332
 
303
333
  * External images should be CORS-accessible (use `useProxy` option for handling CORS denied)
304
- * Iframes are not supported
305
334
  * When WebP format is used on Safari, it will fallback to PNG rendering.
306
335
  * `@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)
307
336