@zumer/snapdom-plugins 1.0.0 → 1.0.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.
Files changed (2) hide show
  1. package/README.md +231 -0
  2. package/package.json +18 -4
package/README.md ADDED
@@ -0,0 +1,231 @@
1
+ # @zumer/snapdom-plugins
2
+
3
+ Official plugins for [SnapDOM](https://github.com/zumerlab/snapdom) — extend and transform DOM captures with zero core changes.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @zumer/snapdom-plugins
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ Import plugins individually (recommended for tree-shaking):
14
+
15
+ ```js
16
+ import { snapdom } from '@zumer/snapdom';
17
+ import { filter } from '@zumer/snapdom-plugins/filter';
18
+ import { timestampOverlay } from '@zumer/snapdom-plugins/timestamp-overlay';
19
+
20
+ const result = await snapdom(element, {
21
+ plugins: [filter({ preset: 'grayscale' }), timestampOverlay()]
22
+ });
23
+ const png = await result.toPng();
24
+ ```
25
+
26
+ Or import everything at once:
27
+
28
+ ```js
29
+ import { filter, timestampOverlay, replaceText } from '@zumer/snapdom-plugins';
30
+ ```
31
+
32
+ CDN (no install):
33
+
34
+ ```js
35
+ import { snapdom } from 'https://esm.sh/@zumer/snapdom';
36
+ import { filter } from 'https://esm.sh/@zumer/snapdom-plugins/filter';
37
+ ```
38
+
39
+ ---
40
+
41
+ ## Plugins
42
+
43
+ ### `filter`
44
+
45
+ Applies CSS filter effects to the captured clone.
46
+
47
+ ```js
48
+ import { filter } from '@zumer/snapdom-plugins/filter';
49
+
50
+ snapdom(el, { plugins: [filter({ preset: 'grayscale' })] });
51
+ ```
52
+
53
+ | Option | Type | Default | Description |
54
+ |--------|------|---------|-------------|
55
+ | `preset` | `string` | — | `'grayscale'` \| `'sepia'` \| `'blur'` \| `'invert'` \| `'vintage'` \| `'dramatic'` |
56
+ | `filter` | `string` | `''` | Raw CSS filter string, e.g. `'blur(2px) contrast(1.2)'` |
57
+
58
+ ---
59
+
60
+ ### `timestamp-overlay`
61
+
62
+ Adds a translucent timestamp label to the captured clone.
63
+
64
+ ```js
65
+ import { timestampOverlay } from '@zumer/snapdom-plugins/timestamp-overlay';
66
+
67
+ snapdom(el, { plugins: [timestampOverlay({ position: 'top-right', format: 'date' })] });
68
+ ```
69
+
70
+ | Option | Type | Default | Description |
71
+ |--------|------|---------|-------------|
72
+ | `format` | `string \| function` | `'datetime'` | `'datetime'` \| `'date'` \| `'time'` \| `'iso'` \| custom `(Date) => string` |
73
+ | `position` | `string` | `'bottom-right'` | `'top-left'` \| `'top-right'` \| `'bottom-left'` \| `'bottom-right'` |
74
+ | `background` | `string` | `'rgba(0,0,0,0.6)'` | Label background color |
75
+ | `color` | `string` | `'#fff'` | Label text color |
76
+ | `fontSize` | `number` | `11` | Font size in px |
77
+
78
+ ---
79
+
80
+ ### `replace-text`
81
+
82
+ Find-and-replace text in the captured clone. Supports strings and regex.
83
+
84
+ ```js
85
+ import { replaceText } from '@zumer/snapdom-plugins/replace-text';
86
+
87
+ snapdom(el, {
88
+ plugins: [replaceText({
89
+ replacements: [
90
+ { find: 'DRAFT', replace: 'APPROVED' },
91
+ { find: /\d{4}-\d{2}-\d{2}/, replace: '[REDACTED]' }
92
+ ]
93
+ })]
94
+ });
95
+ ```
96
+
97
+ | Option | Type | Default | Description |
98
+ |--------|------|---------|-------------|
99
+ | `replacements` | `Array<{ find: string\|RegExp, replace: string }>` | `[]` | List of find/replace pairs |
100
+
101
+ ---
102
+
103
+ ### `color-tint`
104
+
105
+ Tints the entire capture to a specified color using a `mix-blend-mode` overlay.
106
+
107
+ ```js
108
+ import { colorTint } from '@zumer/snapdom-plugins/color-tint';
109
+
110
+ snapdom(el, { plugins: [colorTint({ color: 'royalblue', opacity: 0.4 })] });
111
+ ```
112
+
113
+ | Option | Type | Default | Description |
114
+ |--------|------|---------|-------------|
115
+ | `color` | `string` | `'red'` | Any CSS color value |
116
+ | `opacity` | `number` | `1` | Overlay opacity (0–1) |
117
+
118
+ ---
119
+
120
+ ### `picture-resolver`
121
+
122
+ Resolves lazy-loaded `<picture>` placeholders and `data-src` patterns before capture.
123
+ Detects base64/blob stubs, fetches the real image, and restores the DOM after cloning (zero side effects).
124
+
125
+ ```js
126
+ import { pictureResolver } from '@zumer/snapdom-plugins/picture-resolver';
127
+
128
+ snapdom(el, { plugins: [pictureResolver({ timeout: 3000 })] });
129
+ ```
130
+
131
+ | Option | Type | Default | Description |
132
+ |--------|------|---------|-------------|
133
+ | `timeout` | `number` | `5000` | Max ms per image fetch |
134
+ | `concurrency` | `number` | `4` | Max parallel fetches |
135
+ | `resolveLazySrc` | `boolean` | `true` | Also resolve `data-src` / `data-srcset` patterns |
136
+ | `useProxy` | `string` | `''` | CORS proxy URL for cross-origin images |
137
+ | `silent` | `boolean` | `false` | Suppress console warnings |
138
+
139
+ ---
140
+
141
+ ### `ascii-export`
142
+
143
+ Adds a `toAscii()` export method that converts captures to ASCII art.
144
+
145
+ ```js
146
+ import { asciiExport } from '@zumer/snapdom-plugins/ascii-export';
147
+
148
+ const result = await snapdom(el, { plugins: [asciiExport({ width: 100 })] });
149
+ const art = await result.toAscii();
150
+ console.log(art);
151
+ ```
152
+
153
+ | Option | Type | Default | Description |
154
+ |--------|------|---------|-------------|
155
+ | `width` | `number` | `80` | Character width of output |
156
+ | `charset` | `string` | `' .:-=+*#%@'` | Characters from lightest to darkest |
157
+ | `invert` | `boolean` | `false` | Invert luminance mapping |
158
+
159
+ ---
160
+
161
+ ### `pdf-image`
162
+
163
+ Exports the capture as a PNG embedded in a downloadable PDF (A4). Adds a `toPdfImage()` method.
164
+
165
+ ```js
166
+ import { pdfImage } from '@zumer/snapdom-plugins/pdf-image';
167
+
168
+ const result = await snapdom(el, { plugins: [pdfImage({ orientation: 'landscape' })] });
169
+ await result.toPdfImage(); // triggers download
170
+ ```
171
+
172
+ | Option | Type | Default | Description |
173
+ |--------|------|---------|-------------|
174
+ | `orientation` | `string` | `'portrait'` | `'portrait'` \| `'landscape'` |
175
+ | `quality` | `number` | `0.92` | JPEG quality (0–1) |
176
+ | `filename` | `string` | `'capture.pdf'` | Download filename |
177
+
178
+ ---
179
+
180
+ ### `html-in-canvas`
181
+
182
+ Uses the experimental [WICG `drawElementImage`](https://github.com/WICG/canvas-place-element) API for direct DOM-to-canvas rendering where supported. Falls back gracefully.
183
+
184
+ ```js
185
+ import { htmlInCanvas } from '@zumer/snapdom-plugins/html-in-canvas';
186
+
187
+ snapdom(el, { plugins: [htmlInCanvas()] });
188
+ ```
189
+
190
+ > This plugin uses an experimental browser API and may not work in all environments.
191
+
192
+ ---
193
+
194
+ ## Plugin registration
195
+
196
+ **Global** (applies to all captures):
197
+
198
+ ```js
199
+ import { snapdom } from '@zumer/snapdom';
200
+ import { filter } from '@zumer/snapdom-plugins/filter';
201
+
202
+ snapdom.plugins(filter({ preset: 'sepia' }));
203
+ ```
204
+
205
+ **Per-capture** (overrides global for that call):
206
+
207
+ ```js
208
+ const result = await snapdom(element, {
209
+ plugins: [filter({ preset: 'dramatic' })]
210
+ });
211
+ ```
212
+
213
+ Per-capture plugins run before global ones. Duplicate plugin names are skipped automatically.
214
+
215
+ ---
216
+
217
+ ## Build your own plugin
218
+
219
+ Use the template to scaffold a new plugin in seconds:
220
+
221
+ ```bash
222
+ npx degit zumerlab/snapdom/packages/plugin-template my-plugin
223
+ ```
224
+
225
+ See [PLUGIN_SPEC.md](../../PLUGIN_SPEC.md) for the full hook specification and [CONTRIBUTING_PLUGINS.md](../../CONTRIBUTING_PLUGINS.md) to get your plugin listed on the community page.
226
+
227
+ ---
228
+
229
+ ## License
230
+
231
+ MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zumer/snapdom-plugins",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Official plugins for SnapDOM",
5
5
  "type": "module",
6
6
  "exports": {
@@ -14,14 +14,28 @@
14
14
  "./html-in-canvas": "./html-in-canvas.js",
15
15
  "./pdf-image": "./pdf-image.js"
16
16
  },
17
+ "files": [
18
+ "*.js",
19
+ "README.md"
20
+ ],
17
21
  "keywords": [
18
22
  "snapdom",
19
23
  "snapdom-plugin",
20
24
  "dom-capture",
21
25
  "plugins"
22
26
  ],
23
- "peerDependencies": {
24
- "@zumer/snapdom": ">=0.9.0"
27
+ "author": "Juan Martin Muda",
28
+ "license": "MIT",
29
+ "repository": {
30
+ "type": "git",
31
+ "url": "git+https://github.com/zumerlab/snapdom.git",
32
+ "directory": "packages/plugins"
25
33
  },
26
- "license": "MIT"
34
+ "bugs": {
35
+ "url": "https://github.com/zumerlab/snapdom/issues"
36
+ },
37
+ "homepage": "https://zumerlab.github.io/snapdom/",
38
+ "peerDependencies": {
39
+ "@zumer/snapdom": ">=2.7.0"
40
+ }
27
41
  }