@zumer/snapdom 3.1.1 → 3.1.2-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 +37 -1
- package/dist/snapdom.js +9 -9
- package/dist/snapdom.mjs +9 -9
- package/package.json +1 -1
- package/types/snapdom.d.ts +5 -2
package/README.md
CHANGED
|
@@ -175,6 +175,42 @@ const result = await snapdom(card, {
|
|
|
175
175
|
|
|
176
176
|
[All options](https://snapdom.dev/docs/options/) include shadows, transforms, fonts, CORS, fallbacks and layout reconciliation.
|
|
177
177
|
|
|
178
|
+
### Export a long page
|
|
179
|
+
|
|
180
|
+
With the default SVG engine, PNG file exports automatically handle captures beyond the browser's canvas limits. Capture once, then download one full-resolution file or get its Blob:
|
|
181
|
+
|
|
182
|
+
```js
|
|
183
|
+
const capture = await snapdom(article);
|
|
184
|
+
await capture.download({ format: 'png', scale: 2 });
|
|
185
|
+
// Or upload/store the file yourself:
|
|
186
|
+
const blob = await capture.toBlob({ format: 'png', scale: 2, dpr: 1 });
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
SnapDOM renders the frozen capture in windows and encodes them into one PNG. It preserves the requested dimensions, including shadows and padding, without allocating a canvas for the whole image. `download()` always uses DPR 1; `toBlob()` uses the capture's DPR unless you override it. Ordinary-sized exports use the native encoder.
|
|
190
|
+
|
|
191
|
+
This requires `CompressionStream`; older browsers keep the existing downscale and warning. Very large files still take time and memory to encode, and the application opening them has its own image limits.
|
|
192
|
+
|
|
193
|
+
### Export a long page in pieces
|
|
194
|
+
|
|
195
|
+
`toCanvas()`, `toPng()` and JPEG/WebP exports still use a single canvas and scale down past SnapDOM's size guards (16,384px per side in Safari, 32,767px in Chrome/Firefox, plus an area limit). When you need separate canvases, use `crop`:
|
|
196
|
+
|
|
197
|
+
```js
|
|
198
|
+
const capture = await snapdom(article);
|
|
199
|
+
const { contentX, contentY, w0, h0 } = capture.meta;
|
|
200
|
+
const pieceHeight = 4000; // CSS px
|
|
201
|
+
|
|
202
|
+
for (let y = 0; y < h0; y += pieceHeight) {
|
|
203
|
+
const canvas = await capture.toCanvas({
|
|
204
|
+
scale: 2,
|
|
205
|
+
dpr: 1,
|
|
206
|
+
crop: { x: contentX, y: contentY + y, width: w0, height: Math.min(pieceHeight, h0 - y) }
|
|
207
|
+
});
|
|
208
|
+
// save or upload this piece, then move on
|
|
209
|
+
}
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
`crop` is a rectangle, not a switch. It is in the coordinates of `capture.meta`, and each call returns one canvas. The capture runs once; only the rasterization repeats. Keep `pieceHeight × scale × dpr` under the limit, and set `dpr` yourself, since it defaults to the device pixel ratio. [How tiling works](https://snapdom.dev/blog/huge-page-mosaic/).
|
|
213
|
+
|
|
178
214
|
### Export HTML or structured context
|
|
179
215
|
|
|
180
216
|
Official plugins are published separately as `@zumer/snapdom-plugins` and must match the core major version; they declare a peer dependency on a v3 core. Their sources live in `packages/plugins/` in this checkout.
|
|
@@ -297,7 +333,7 @@ Capture-affecting plugins suspend memoization unless they declare `pure: true`.
|
|
|
297
333
|
- SnapDOM needs a browser DOM. A server-side Node.js process needs a browser environment to run it.
|
|
298
334
|
- Cross-origin images, fonts and stylesheets need readable resources or an appropriate proxy. `crossorigin` does not grant access unless the server also allows it. Cross-origin iframes use placeholders.
|
|
299
335
|
- SVG output includes HTML inside `<foreignObject>`. It is suitable for browsers; support varies in other SVG viewers and document tools.
|
|
300
|
-
- Output depends on browser rendering and
|
|
336
|
+
- Output depends on browser rendering and image limits; for tall PNG files see [Export a long page](#export-a-long-page). Safari may fall back to PNG when WebP encoding is unavailable.
|
|
301
337
|
- Canvas, video and other changing surfaces are captured fresh. JavaScript CSSOM edits are not observable automatically; use `invalidate: true` after them.
|
|
302
338
|
- Core captures visible input values. Semantic plugins redact sensitive field values in their text/map output, but their attached image needs `redactInputs` or `exclude` if you want those pixels hidden too.
|
|
303
339
|
|