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@latestUsage
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
| Option | Type | Default | Description |
|---|---|---|---|
fps | number | 10 | Frames per second |
duration | number | 2000 | Total duration in ms (ignored if frames is set) |
frames | number | none | Explicit frame count (overrides duration) |
maxColors | number | 256 | Palette size per frame (2–256) |
background | string | '#ffffff' | Color composited under transparent pixels |
scale | number | capture's scale | Capture scale |
repeat | number | 0 | Loop count (0 = forever, -1 = play once) |
filename | string | '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.