Skip to content
SnapDOMTry SnapStudioGitHub★ 8K
Documentation

SnapDOM Documentation

Capture a DOM element as an image. Plugins add PDF, editable vector and recordings. This reference covers SnapDOM 3.

Installation

npm i @zumer/snapdom@latest

Or use yarn add @zumer/snapdom@latest.

Quick start

Capture an element as a PNG image:

import { snapdom } from '@zumer/snapdom';

const img = await snapdom.toPng(document.querySelector('#card'));
document.body.appendChild(img);

Use snapdom(el) when you need several exports from the same captured state:

const result = await snapdom(document.querySelector('#card'));
await result.toPng();      // → HTMLImageElement
await result.toSvg();      // → SVG as Image
await result.download({ format: 'jpg', filename: 'card.jpg' });

Documentation sections

Browser and module builds

CDN

Choose the script tag for a global snapdom, or the module import:

<!-- Minified build -->
<script src="https://unpkg.com/@zumer/snapdom@latest/dist/snapdom.js"></script>
<!-- Minified ES Module build -->
<script type="module">
  import { snapdom } from "https://unpkg.com/@zumer/snapdom@latest/dist/snapdom.mjs";
</script>

Build outputs

VariantFileUse case
ESM (tree-shakeable)dist/snapdom.mjsBundlers (Vite, webpack), import
IIFE (global)dist/snapdom.jsBrowser script tag; exposes window.snapdom. No CommonJS build.

Plugin registry import. The subpath shares the core runtime and registry:

import { registerPlugins } from '@zumer/snapdom/plugins';

Capture flow

A capture freezes the subtree; exports read that state. With the default SVG engine:

StageWhat happens
CloneDeep clone with styles, open Shadow DOM and same-origin iframes. Leave nodes out with exclude.
Styles & PseudoInline ::before/::after as elements, resolve counter()/counters().
Images & BackgroundsFetch and inline external images/backgrounds as data URLs.
FontsEmbed the webfonts the capture uses by default. Render icon-font glyphs through the icon path.
SVGWrap clone in <foreignObject>, serialize to data:image/svg+xml.
ExportReturn the SVG, rasterize to PNG/JPG/WebP/canvas, create a blob, or run a plugin export.

Plugins can use the clone without rendering by declaring needs: 'clone'. Image exports require 'render', the default. Hooks and custom outputs: see the plugins guide.

Choose a recipe for your output

For a PNG preview, a downloaded file or a Blob to upload, use the HTML to PNG recipe. For a shareable report with several charts, use the dashboard export recipe.

For framework state updates, the Angular guide waits for the next render, the Svelte guide waits for tick(), and the Lit guide selects a card inside its shadow root after updateComplete.

Start capturing

Run a capture in the browser demo.

Open the demo Install from npm