Skip to content
SnapDOMGitHub★ 8K
@zumer/snapdom-plugins · MIT

Record the element as a GIF.

Adds toGif(), which records the live element and returns an image/gif Blob. Its built-in GIF89a encoder uses median-cut quantization and LZW, with no encoding dependency.

npm install @zumer/snapdom@latest @zumer/snapdom-plugins@latest

Usage

import { snapdom } from '@zumer/snapdom';
import { gifExport } from '@zumer/snapdom-plugins/gif-export';

const el = document.querySelector('#target');
const result = await snapdom(el, { plugins: [gifExport({ fps: 12, duration: 3000 })] });
const blob = await result.toGif();

// Or download directly:
await result.toGif({ download: 'animation.gif' });

Options

OptionTypeDefaultDescription
fpsnumber10Frames per second
durationnumber2000Total duration in ms (ignored if frames is set)
framesnumbernoneExplicit frame count (overrides duration)
maxColorsnumber256Palette size per frame (2–256)
backgroundstring'#ffffff'Color composited under transparent pixels
scalenumbercapture's scaleCapture scale
repeatnumber0Loop count (0 = forever, -1 = play once)
filenamestring'capture.gif'Download filename

Per-call opts override constructor options and accept download (boolean | string). Recording starts when toGif() runs, including its first frame. It preserves the original capture policy, including exclusions and plugins. Frame capture speed limits the sampling rate.

Try it here

Live element

Component preview
Capture an editable component
1,284+12% vs last week

Editable text and an open shadow root can be captured together.

Result

Nothing captured yet

Edit the title, then run. This uses the real library from unpkg.