# @zumer/snapdom-plugins Official plugins for [SnapDOM](https://github.com/zumerlab/snapdom), a capture engine for web apps. Core exports images and canvases; this package adds HTML, structured context, element maps, PDF, ASCII, visual transforms and live GIF/video recording. Image, HTML and structured exports use captured state; GIF and video start a sequence of live captures when their export method is called. ## Install Install the plugins next to a matching core: ```bash npm install @zumer/snapdom@latest @zumer/snapdom-plugins@latest ``` Plugins 3.x require a 3.x core. See the [migration guide](https://github.com/zumerlab/snapdom#migrating-from-v2) when upgrading from v2. ## Usage Import plugins individually (recommended for tree-shaking): ```js import { snapdom } from '@zumer/snapdom'; import { filter } from '@zumer/snapdom-plugins/filter'; import { timestampOverlay } from '@zumer/snapdom-plugins/timestamp-overlay'; const result = await snapdom(element, { plugins: [filter({ preset: 'grayscale' }), timestampOverlay()] }); const png = await result.toPng(); ``` Or use the package entry point: ```js import { filter, timestampOverlay, replaceText } from '@zumer/snapdom-plugins'; ``` CDN (no install): ```js import { snapdom } from 'https://esm.sh/@zumer/snapdom@latest'; import { filter } from 'https://esm.sh/@zumer/snapdom-plugins@latest/filter'; ``` --- ## Plugins ### `filter` Applies CSS filter effects to the clone, overriding authored filters. `preset` takes precedence over `filter`; an unknown preset logs a warning and `filter` applies. ```js import { filter } from '@zumer/snapdom-plugins/filter'; snapdom(el, { plugins: [filter({ preset: 'grayscale' })] }); ``` | Option | Type | Default | Description | |--------|------|---------|-------------| | `preset` | `string` | — | `'grayscale'` \| `'sepia'` \| `'blur'` \| `'invert'` \| `'vintage'` \| `'dramatic'` | | `filter` | `string` | `''` | Raw CSS filter string, e.g. `'blur(2px) contrast(1.2)'` | --- ### `timestamp-overlay` Adds a timestamp label. The clock or custom formatter runs for every capture. ```js import { timestampOverlay } from '@zumer/snapdom-plugins/timestamp-overlay'; snapdom(el, { plugins: [timestampOverlay({ position: 'top-right', format: 'date' })] }); ``` | Option | Type | Default | Description | |--------|------|---------|-------------| | `format` | `string \| function` | `'datetime'` | `'datetime'` \| `'date'` \| `'time'` \| `'iso'` \| custom `(Date) => string` | | `position` | `string` | `'bottom-right'` | `'top-left'` \| `'top-right'` \| `'bottom-left'` \| `'bottom-right'` | | `background` | `string` | `'rgba(0,0,0,0.6)'` | Label background color | | `color` | `string` | `'#fff'` | Label text color | | `fontSize` | `number` | `11` | Font size in px | --- ### `replace-text` Replaces DOM text in the clone using strings or regular expressions. Stylesheet and script text are left unchanged. ```js import { replaceText } from '@zumer/snapdom-plugins/replace-text'; snapdom(el, { plugins: [replaceText({ replacements: [ { find: 'DRAFT', replace: 'APPROVED' }, { find: /\d{4}-\d{2}-\d{2}/, replace: '[REDACTED]' } ] })] }); ``` | Option | Type | Default | Description | |--------|------|---------|-------------| | `replacements` | `Array<{ find: string\|RegExp, replace: string }>` | `[]` | List of find/replace pairs | --- ### `redact-inputs` Masks input and textarea values, excludes selected blocks, and removes named attributes from captured outputs. Core already masks password fields to match their visible bullets; other field values remain visible unless you redact them. The live page stays unchanged. ```js import { redactInputs } from '@zumer/snapdom-plugins/redact-inputs'; // Defaults: email, tel, and the cc-* / current-password / new-password / one-time-code // autocomplete tokens. snapdom(el, { plugins: [redactInputs()] }); // Everything, including textareas: snapdom(el, { plugins: [redactInputs({ all: true })] }); // App-specific fields, blanked rather than bulleted: snapdom(el, { plugins: [redactInputs({ selector: '[data-private]', mask: () => '' })] }); // Exclude whole blocks and remove metadata attributes: const redaction = redactInputs({ blocks: ['.private-panel', '[data-private-block]'], attributes: [ { selector: '[data-token]', names: ['data-token'] }, { selector: '.customer', names: ['title', 'aria-label'] } ] }); snapdom(el, { plugins: [redaction] }); // Remove those blocks from the layout as well: snapdom(el, { excludeMode: 'remove', plugins: [redaction] }); ``` The default mask keeps the string's length. Glyph widths can differ, so wrapping and truncation may change. A `