@mkhuda/dom-screenshot 0.0.1 → 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 (51) hide show
  1. package/.gitattributes +1 -0
  2. package/EXAMPLES_QUICKSTART.md +240 -0
  3. package/README.md +542 -25
  4. package/TESTING.md +269 -0
  5. package/TESTING_STATUS.md +215 -0
  6. package/TEST_SETUP_SUMMARY.md +335 -0
  7. package/dist/dom-screenshot.d.ts +44 -272
  8. package/dist/dom-screenshot.d.ts.map +1 -0
  9. package/dist/dom-screenshot.esm.js +753 -0
  10. package/dist/dom-screenshot.esm.js.map +1 -0
  11. package/dist/dom-screenshot.min.js +2 -1
  12. package/dist/dom-screenshot.min.js.map +1 -0
  13. package/examples/README.md +211 -0
  14. package/examples/react-app/README.md +161 -0
  15. package/examples/react-app/index.html +12 -0
  16. package/examples/react-app/node_modules/.vite/deps/_metadata.json +46 -0
  17. package/examples/react-app/node_modules/.vite/deps/chunk-FK77NBP6.js +1895 -0
  18. package/examples/react-app/node_modules/.vite/deps/chunk-FK77NBP6.js.map +7 -0
  19. package/examples/react-app/node_modules/.vite/deps/chunk-VSODSHUF.js +21647 -0
  20. package/examples/react-app/node_modules/.vite/deps/chunk-VSODSHUF.js.map +7 -0
  21. package/examples/react-app/node_modules/.vite/deps/package.json +3 -0
  22. package/examples/react-app/node_modules/.vite/deps/react-dom.js +5 -0
  23. package/examples/react-app/node_modules/.vite/deps/react-dom.js.map +7 -0
  24. package/examples/react-app/node_modules/.vite/deps/react-dom_client.js +38 -0
  25. package/examples/react-app/node_modules/.vite/deps/react-dom_client.js.map +7 -0
  26. package/examples/react-app/node_modules/.vite/deps/react.js +4 -0
  27. package/examples/react-app/node_modules/.vite/deps/react.js.map +7 -0
  28. package/examples/react-app/node_modules/.vite/deps/react_jsx-dev-runtime.js +898 -0
  29. package/examples/react-app/node_modules/.vite/deps/react_jsx-dev-runtime.js.map +7 -0
  30. package/examples/react-app/node_modules/.vite/deps/react_jsx-runtime.js +910 -0
  31. package/examples/react-app/node_modules/.vite/deps/react_jsx-runtime.js.map +7 -0
  32. package/examples/react-app/package.json +21 -0
  33. package/examples/react-app/tsconfig.json +25 -0
  34. package/examples/react-app/tsconfig.node.json +10 -0
  35. package/examples/react-app/vite.config.ts +10 -0
  36. package/package.json +75 -44
  37. package/rollup.config.mjs +35 -0
  38. package/tests/README.md +394 -0
  39. package/tests/fixtures/html.ts +192 -0
  40. package/tests/fixtures/images.ts +86 -0
  41. package/tests/fixtures/styles.ts +288 -0
  42. package/tests/helpers/dom-helpers.ts +242 -0
  43. package/tests/mocks/canvas-mock.ts +94 -0
  44. package/tests/mocks/image-mock.ts +147 -0
  45. package/tests/mocks/xhr-mock.ts +202 -0
  46. package/tests/setup.ts +103 -0
  47. package/tests/unit/basic.test.ts +263 -0
  48. package/tests/unit/simple.test.ts +172 -0
  49. package/tsconfig.json +44 -20
  50. package/vitest.config.mts +35 -0
  51. package/rollup.config.js +0 -20
@@ -0,0 +1,335 @@
1
+ # Complete Test Setup Summary
2
+
3
+ ## ✅ What Was Created
4
+
5
+ ### 🎯 Configuration Files
6
+ 1. **vitest.config.ts** - Complete Vitest configuration with jsdom environment
7
+ 2. **tests/setup.ts** - Global test setup with:
8
+ - Chai with Promise support
9
+ - Sinon sandbox management
10
+ - Custom matchers (toBeValidDataUrl, toBeValidSvgDataUrl, toBeValidPngDataUrl)
11
+ - DOM cleanup
12
+
13
+ ### 📦 Dependencies Installed
14
+ ```
15
+ - vitest@^4.0.8 (Fast unit test framework)
16
+ - jsdom@^27.1.0 (DOM simulation)
17
+ - chai@^6.2.0 (Assertions)
18
+ - chai-as-promised@^8.0.2 (Promise assertions)
19
+ - sinon@^21.0.0 (Spies, stubs, mocks)
20
+ - nock@^14.0.10 (HTTP mocking)
21
+ - @testing-library/dom@^10.4.1 (DOM utilities)
22
+ - @vitest/coverage-v8@^4.0.8 (Coverage reporting)
23
+ - @vitest/ui@^4.0.8 (Visual test UI)
24
+ ```
25
+
26
+ ### 🛠️ Helper Utilities Created
27
+
28
+ #### 1. **tests/helpers/dom-helpers.ts**
29
+ - `createSimpleDiv()` - Simple div with text
30
+ - `createStyledDiv()` - Div with custom CSS
31
+ - `createColoredDiv()` - Colored text and background
32
+ - `createImageElement()` - Image element
33
+ - `createCanvasElement()` - Canvas with drawing
34
+ - `createVideoElement()` - Video element
35
+ - `createTextarea()` - Textarea with value
36
+ - `createInput()` - Input with value
37
+ - `createComplexDOM()` - Multi-element tree
38
+ - `createDOMWithStyles()` - Advanced styling
39
+ - `createDOMWithPseudoElements()` - With ::before/::after
40
+ - `createSVGElement()` - SVG element
41
+ - `wait()` - Promise delay
42
+ - `parseDataUrl()` - Parse data URLs
43
+ - `isValidDataUrl()` - Validate data URL
44
+ - `isImageDataUrl()` - Validate image data URL
45
+
46
+ #### 2. **tests/mocks/canvas-mock.ts**
47
+ - `mockCanvasToDataUrl()` - Mock canvas.toDataURL()
48
+ - `mockCanvasToBlob()` - Mock canvas.toBlob()
49
+ - `mockCanvasContext()` - Mock canvas context
50
+ - `createValidPngDataUrl()` - Generate valid PNG data URL
51
+ - `createValidJpegDataUrl()` - Generate valid JPEG data URL
52
+ - `createValidSvgDataUrl()` - Generate valid SVG data URL
53
+ - `mockCanvasDataUrls()` - Create multiple format URLs
54
+
55
+ #### 3. **tests/mocks/image-mock.ts**
56
+ - `mockImageSuccess()` - Mock successful image load
57
+ - `mockImageError()` - Mock image load error
58
+ - `mockImageCustom()` - Custom image behavior
59
+ - `createImageDataUrl()` - Create image data URL
60
+ - `stubImageXhr()` - Mock XHR for images
61
+ - `mockFileReaderDataUrl()` - Mock FileReader
62
+
63
+ #### 4. **tests/mocks/xhr-mock.ts**
64
+ - `mockXhrSuccess()` - Mock successful XHR
65
+ - `mockXhrError()` - Mock XHR error (404, etc)
66
+ - `mockXhrTimeout()` - Mock XHR timeout
67
+ - `stubUrlPattern()` - Mock specific URL patterns
68
+ - `createBase64ImageData()` - Create image data
69
+
70
+ ### 📦 Test Fixtures Created
71
+
72
+ #### 1. **tests/fixtures/html.ts** (12 HTML fixtures)
73
+ - `SIMPLE_HTML` - Basic div
74
+ - `STYLED_HTML` - With gradient, shadow, etc
75
+ - `COMPLEX_HTML` - Multiple elements
76
+ - `NESTED_HTML` - Nested divs
77
+ - `TEXT_HTML` - Text formatting
78
+ - `FORM_HTML` - Form elements
79
+ - `COLOR_HTML` - Color blocks
80
+ - `BORDER_SHADOW_HTML` - Borders & shadows
81
+ - `TRANSFORM_HTML` - CSS transforms
82
+ - `MULTI_IMAGE_HTML` - Multiple images
83
+ - `TABLE_HTML` - HTML table
84
+ - `SVG_HTML` - SVG elements
85
+ - `EMPTY_HTML` - Empty div
86
+ - `generateLargeHTML()` - Dynamic large HTML
87
+
88
+ #### 2. **tests/fixtures/images.ts** (7 image fixtures)
89
+ - `PNG_1X1_TRANSPARENT` - 1x1 PNG
90
+ - `JPEG_1X1_RED` - 1x1 JPEG
91
+ - `GIF_1X1_BLUE` - 1x1 GIF
92
+ - `SVG_CIRCLE` - SVG circle
93
+ - `INVALID_IMAGE_URL` - Broken image
94
+ - `REMOTE_IMAGE_URL` - HTTP URL
95
+ - `CORS_IMAGE_URL` - CORS URL
96
+ - `TEST_IMAGES` - Collection object
97
+ - `createTestImageElement()` - Create img element
98
+ - `createTestImageElements()` - Create multiple imgs
99
+
100
+ #### 3. **tests/fixtures/styles.ts** (12 CSS fixtures)
101
+ - `CSS_FIXTURES` - Pre-built CSS examples:
102
+ - coloredDiv
103
+ - gradientDiv
104
+ - borderShadowDiv
105
+ - borderRadiusDiv
106
+ - transformDiv
107
+ - opacityDiv
108
+ - fontStyledDiv
109
+ - flexboxDiv
110
+ - gridDiv
111
+ - spacingDiv
112
+ - textAlignDiv
113
+ - overflowDiv
114
+ - listDiv
115
+ - tableDiv
116
+ - `createStyleElement()` - Create style tag
117
+ - `createPseudoElementCSS()` - Pseudo-element CSS
118
+ - `createDivWithPseudoElements()` - Div with ::before/::after
119
+
120
+ ### 🧪 Sample Tests
121
+
122
+ #### **tests/unit/basic.test.ts** (Complete working example)
123
+ Tests for:
124
+ - ✅ toSvg() - SVG conversion
125
+ - ✅ toPng() - PNG conversion
126
+ - ✅ toJpeg() - JPEG conversion
127
+ - ✅ toBlob() - Blob conversion
128
+ - ✅ toPixelData() - Pixel data extraction
129
+ - ✅ Options (bgcolor, width, height, style, filter, quality)
130
+ - ✅ Error handling
131
+ - ✅ HTML integration
132
+ - ✅ Complex DOM handling
133
+
134
+ ### 📚 Documentation
135
+
136
+ 1. **tests/README.md** - Comprehensive testing guide
137
+ - Directory structure
138
+ - Quick start commands
139
+ - Writing tests
140
+ - Helper usage
141
+ - Mock usage
142
+ - Fixture usage
143
+ - Custom matchers
144
+ - Coverage reporting
145
+ - Debugging tips
146
+ - CI/CD examples
147
+ - Best practices
148
+
149
+ 2. **TESTING.md** - Quick reference guide
150
+ - Quick commands
151
+ - Structure overview
152
+ - First test example
153
+ - Mocking examples
154
+ - Fixture examples
155
+ - Custom matchers
156
+ - Common mistakes
157
+
158
+ ## 🚀 Available Commands
159
+
160
+ ```bash
161
+ npm test # Run tests (watch mode)
162
+ npm run test:run # Run tests once
163
+ npm run test:ui # Open visual UI
164
+ npm run test:watch # Run in watch mode
165
+ npm run test:coverage # Generate coverage report
166
+ ```
167
+
168
+ ## 📂 File Tree
169
+
170
+ ```
171
+ ├── vitest.config.ts ✨ New
172
+ ├── TESTING.md ✨ New
173
+ ├── TEST_SETUP_SUMMARY.md ✨ New
174
+ └── tests/ ✨ New
175
+ ├── README.md 📖 Documentation
176
+ ├── setup.ts ⚙️ Global setup
177
+ ├── unit/
178
+ │ └── basic.test.ts ✅ Sample tests
179
+ ├── integration/ (coming soon)
180
+ ├── helpers/
181
+ │ └── dom-helpers.ts 🛠️ DOM utilities
182
+ ├── mocks/
183
+ │ ├── canvas-mock.ts 🎭 Canvas mocks
184
+ │ ├── image-mock.ts 📸 Image mocks
185
+ │ └── xhr-mock.ts 🌐 Network mocks
186
+ └── fixtures/
187
+ ├── html.ts 📝 HTML fixtures
188
+ ├── images.ts 🖼️ Image fixtures
189
+ └── styles.ts 🎨 CSS fixtures
190
+ ```
191
+
192
+ ## 🎯 Testing Stack
193
+
194
+ | Component | Package | Version | Purpose |
195
+ |-----------|---------|---------|---------|
196
+ | Test Runner | vitest | ^4.0.8 | Fast, ESM-native test runner |
197
+ | DOM | jsdom | ^27.1.0 | DOM simulation for Node.js |
198
+ | Assertions | chai | ^6.2.0 | Assertion library |
199
+ | Promises | chai-as-promised | ^8.0.2 | Promise assertions |
200
+ | Mocking | sinon | ^21.0.0 | Spies, stubs, mocks |
201
+ | DOM Testing | @testing-library/dom | ^10.4.1 | DOM utilities |
202
+ | HTTP Mocking | nock | ^14.0.10 | HTTP interception |
203
+ | Coverage | @vitest/coverage-v8 | ^4.0.8 | Code coverage |
204
+ | UI | @vitest/ui | ^4.0.8 | Visual dashboard |
205
+
206
+ ## 🎓 What You Can Do Now
207
+
208
+ ### ✅ Quick Start
209
+ ```bash
210
+ npm test
211
+ ```
212
+ Runs tests in watch mode - perfect for development!
213
+
214
+ ### ✅ Write Tests
215
+ ```bash
216
+ # Create new test file
217
+ # tests/unit/my-feature.test.ts
218
+
219
+ import { describe, it, expect } from 'vitest';
220
+ import { domtoimage } from '../../src/dom-screenshot';
221
+ import { createStyledDiv } from '../helpers/dom-helpers';
222
+
223
+ describe('My Feature', () => {
224
+ it('should work', async () => {
225
+ const div = createStyledDiv('Test', { backgroundColor: 'blue' });
226
+ const result = await domtoimage.toSvg(div);
227
+ expect(result).toBeValidSvgDataUrl();
228
+ });
229
+ });
230
+ ```
231
+
232
+ ### ✅ Mock External Dependencies
233
+ ```typescript
234
+ import { mockCanvasToDataUrl, createValidPngDataUrl } from '../mocks/canvas-mock';
235
+ import { mockImageSuccess } from '../mocks/image-mock';
236
+
237
+ beforeEach(() => {
238
+ mockCanvasToDataUrl(createValidPngDataUrl());
239
+ mockImageSuccess(10);
240
+ });
241
+ ```
242
+
243
+ ### ✅ Use Test Fixtures
244
+ ```typescript
245
+ import { SIMPLE_HTML, PNG_1X1_TRANSPARENT, CSS_FIXTURES } from '../fixtures';
246
+
247
+ container.innerHTML = SIMPLE_HTML;
248
+ const img = new Image();
249
+ img.src = PNG_1X1_TRANSPARENT;
250
+ ```
251
+
252
+ ### ✅ Generate Coverage
253
+ ```bash
254
+ npm run test:coverage
255
+ # Opens: coverage/index.html
256
+ ```
257
+
258
+ ### ✅ Visual Debugging
259
+ ```bash
260
+ npm run test:ui
261
+ # Opens: http://localhost:51204/__vitest__/
262
+ ```
263
+
264
+ ## 🔄 Next Steps
265
+
266
+ 1. **Run the sample tests**
267
+ ```bash
268
+ npm test
269
+ ```
270
+
271
+ 2. **Read the documentation**
272
+ - [TESTING.md](./TESTING.md) - Quick reference
273
+ - [tests/README.md](./tests/README.md) - Comprehensive guide
274
+
275
+ 3. **Write your own tests**
276
+ - Create `tests/unit/my-feature.test.ts`
277
+ - Use helpers, mocks, and fixtures
278
+ - Run with `npm test`
279
+
280
+ 4. **Expand test coverage**
281
+ - Add integration tests
282
+ - Test edge cases
283
+ - Test error scenarios
284
+
285
+ ## 📊 Test Categories Ready to Write
286
+
287
+ ### Unit Tests (Ready Now)
288
+ - ✅ Utility functions
289
+ - ✅ Single DOM elements
290
+ - ✅ Format conversions
291
+ - ✅ Options handling
292
+ - ✅ Error cases
293
+
294
+ ### Integration Tests (Structure Ready)
295
+ - Complex DOM trees
296
+ - Multiple resources
297
+ - Style inheritance
298
+ - Font loading
299
+ - Image inlining
300
+
301
+ ### E2E Tests (Future)
302
+ - Real browser testing
303
+ - Visual regression
304
+ - Performance benchmarks
305
+
306
+ ## 🎉 Summary
307
+
308
+ **Complete testing infrastructure is now in place:**
309
+ - ✅ Test runner configured
310
+ - ✅ Mock utilities created
311
+ - ✅ Test fixtures prepared
312
+ - ✅ Helper utilities built
313
+ - ✅ Sample tests written
314
+ - ✅ Documentation provided
315
+ - ✅ npm scripts added
316
+
317
+ **You can now:**
318
+ - Write unit tests with confidence
319
+ - Mock Canvas, Image, and XHR
320
+ - Use pre-built fixtures
321
+ - Generate coverage reports
322
+ - Debug with visual UI
323
+
324
+ **Total files created:** 10
325
+ - Configuration: 1
326
+ - Setup: 1
327
+ - Helpers: 1
328
+ - Mocks: 3
329
+ - Fixtures: 3
330
+ - Tests: 1
331
+ - Documentation: 3
332
+
333
+ ---
334
+
335
+ **Ready to test!** Run `npm test` to get started. 🚀
@@ -1,277 +1,49 @@
1
+ import type { DomScreenshotOptions } from './types/options';
1
2
  /**
2
- * @param {Node} node - The DOM Node object to render
3
- * @param {Options} options - Rendering options
4
- * @return {Promise} - A promise that is fulfilled with a SVG image data URL
5
- * */
6
- export function toSvg(node: Node, options: {
7
- /**
8
- * - Should return true if passed node should be included in the output
9
- * (excluding node means excluding it's children as well). Not called on the root node.
10
- */
11
- filter?: Function | undefined;
12
- /**
13
- * - color for the background, any valid CSS color value.
14
- */
15
- bgcolor?: string | undefined;
16
- /**
17
- * - width to be applied to node before rendering.
18
- */
19
- width?: number | undefined;
20
- /**
21
- * - height to be applied to node before rendering.
22
- */
23
- height?: number | undefined;
24
- /**
25
- * - an object whose properties to be copied to node's style before rendering.
26
- */
27
- style?: any | undefined;
28
- /**
29
- * - a Number between 0 and 1 indicating image quality (applicable to JPEG only),
30
- * defaults to 1.0.
31
- */
32
- quality?: number | undefined;
33
- /**
34
- * - dataURL to use as a placeholder for failed images, default behaviour is to fail fast on images we can't fetch
35
- */
36
- imagePlaceholder?: string | undefined;
37
- /**
38
- * - set to true to cache bust by appending the time to the request url
39
- */
40
- cacheBust?: boolean;
41
- }): Promise<any>;
3
+ * Main domtoimage module export
4
+ */
5
+ export declare const domtoimage: {
6
+ toSvg: typeof toSvg;
7
+ toPng: typeof toPng;
8
+ toJpeg: typeof toJpeg;
9
+ toBlob: typeof toBlob;
10
+ toPixelData: typeof toPixelData;
11
+ impl: any;
12
+ };
13
+ export { toSvg, toPng, toJpeg, toBlob, toPixelData };
42
14
  /**
43
- * @param {Node} node - The DOM Node object to render
44
- * @param {Options} options - Rendering options
45
- * @return {Promise} - A promise that is fulfilled with a PNG image data URL
46
- * */
47
- export function toPng(node: Node, options: {
48
- /**
49
- * - Should return true if passed node should be included in the output
50
- * (excluding node means excluding it's children as well). Not called on the root node.
51
- */
52
- filter?: Function | undefined;
53
- /**
54
- * - color for the background, any valid CSS color value.
55
- */
56
- bgcolor?: string | undefined;
57
- /**
58
- * - width to be applied to node before rendering.
59
- */
60
- width?: number | undefined;
61
- /**
62
- * - height to be applied to node before rendering.
63
- */
64
- height?: number | undefined;
65
- /**
66
- * - an object whose properties to be copied to node's style before rendering.
67
- */
68
- style?: any | undefined;
69
- /**
70
- * - a Number between 0 and 1 indicating image quality (applicable to JPEG only),
71
- * defaults to 1.0.
72
- */
73
- quality?: number | undefined;
74
- /**
75
- * - dataURL to use as a placeholder for failed images, default behaviour is to fail fast on images we can't fetch
76
- */
77
- imagePlaceholder?: string | undefined;
78
- /**
79
- * - set to true to cache bust by appending the time to the request url
80
- */
81
- cacheBust?: boolean;
82
- }): Promise<any>;
15
+ * Render DOM node to SVG data URL
16
+ * @param node - The DOM Node object to render
17
+ * @param options - Rendering options
18
+ * @returns Promise fulfilled with a SVG image data URL
19
+ */
20
+ declare function toSvg(node: Node, options?: DomScreenshotOptions): Promise<string>;
83
21
  /**
84
- * @param {Node} node - The DOM Node object to render
85
- * @param {Options} options - Rendering options
86
- * @return {Promise} - A promise that is fulfilled with a JPEG image data URL
87
- * */
88
- export function toJpeg(node: Node, options: {
89
- /**
90
- * - Should return true if passed node should be included in the output
91
- * (excluding node means excluding it's children as well). Not called on the root node.
92
- */
93
- filter?: Function | undefined;
94
- /**
95
- * - color for the background, any valid CSS color value.
96
- */
97
- bgcolor?: string | undefined;
98
- /**
99
- * - width to be applied to node before rendering.
100
- */
101
- width?: number | undefined;
102
- /**
103
- * - height to be applied to node before rendering.
104
- */
105
- height?: number | undefined;
106
- /**
107
- * - an object whose properties to be copied to node's style before rendering.
108
- */
109
- style?: any | undefined;
110
- /**
111
- * - a Number between 0 and 1 indicating image quality (applicable to JPEG only),
112
- * defaults to 1.0.
113
- */
114
- quality?: number | undefined;
115
- /**
116
- * - dataURL to use as a placeholder for failed images, default behaviour is to fail fast on images we can't fetch
117
- */
118
- imagePlaceholder?: string | undefined;
119
- /**
120
- * - set to true to cache bust by appending the time to the request url
121
- */
122
- cacheBust?: boolean;
123
- }): Promise<any>;
22
+ * Render DOM node to PNG data URL
23
+ * @param node - The DOM Node object to render
24
+ * @param options - Rendering options
25
+ * @returns Promise fulfilled with a PNG image data URL
26
+ */
27
+ declare function toPng(node: Node, options?: DomScreenshotOptions): Promise<string>;
124
28
  /**
125
- * @param {Node} node - The DOM Node object to render
126
- * @param {Options} options - Rendering options
127
- * @return {Promise} - A promise that is fulfilled with a Blob image data URL
128
- * */
129
- export function toBlob(node: Node, options: {
130
- /**
131
- * - Should return true if passed node should be included in the output
132
- * (excluding node means excluding it's children as well). Not called on the root node.
133
- */
134
- filter?: Function | undefined;
135
- /**
136
- * - color for the background, any valid CSS color value.
137
- */
138
- bgcolor?: string | undefined;
139
- /**
140
- * - width to be applied to node before rendering.
141
- */
142
- width?: number | undefined;
143
- /**
144
- * - height to be applied to node before rendering.
145
- */
146
- height?: number | undefined;
147
- /**
148
- * - an object whose properties to be copied to node's style before rendering.
149
- */
150
- style?: any | undefined;
151
- /**
152
- * - a Number between 0 and 1 indicating image quality (applicable to JPEG only),
153
- * defaults to 1.0.
154
- */
155
- quality?: number | undefined;
156
- /**
157
- * - dataURL to use as a placeholder for failed images, default behaviour is to fail fast on images we can't fetch
158
- */
159
- imagePlaceholder?: string | undefined;
160
- /**
161
- * - set to true to cache bust by appending the time to the request url
162
- */
163
- cacheBust?: boolean;
164
- }): Promise<any>;
29
+ * Render DOM node to JPEG data URL
30
+ * @param node - The DOM Node object to render
31
+ * @param options - Rendering options
32
+ * @returns Promise fulfilled with a JPEG image data URL
33
+ */
34
+ declare function toJpeg(node: Node, options?: DomScreenshotOptions): Promise<string>;
165
35
  /**
166
- * @param {Node} node - The DOM Node object to render
167
- * @param {Options} options - Rendering options
168
- * @return {Promise} - A promise that is fulfilled with a PixelData image data URL
169
- * */
170
- export function toPixelData(node: Node, options: {
171
- /**
172
- * - Should return true if passed node should be included in the output
173
- * (excluding node means excluding it's children as well). Not called on the root node.
174
- */
175
- filter?: Function | undefined;
176
- /**
177
- * - color for the background, any valid CSS color value.
178
- */
179
- bgcolor?: string | undefined;
180
- /**
181
- * - width to be applied to node before rendering.
182
- */
183
- width?: number | undefined;
184
- /**
185
- * - height to be applied to node before rendering.
186
- */
187
- height?: number | undefined;
188
- /**
189
- * - an object whose properties to be copied to node's style before rendering.
190
- */
191
- style?: any | undefined;
192
- /**
193
- * - a Number between 0 and 1 indicating image quality (applicable to JPEG only),
194
- * defaults to 1.0.
195
- */
196
- quality?: number | undefined;
197
- /**
198
- * - dataURL to use as a placeholder for failed images, default behaviour is to fail fast on images we can't fetch
199
- */
200
- imagePlaceholder?: string | undefined;
201
- /**
202
- * - set to true to cache bust by appending the time to the request url
203
- */
204
- cacheBust?: boolean;
205
- }): Promise<any>;
206
- declare namespace fontFaces {
207
- export { resolveAll };
208
- export namespace impl_1 {
209
- export { readAll };
210
- }
211
- export { impl_1 as impl };
212
- }
213
- declare namespace images {
214
- export { inlineAll };
215
- export namespace impl_2 {
216
- export { newImage };
217
- }
218
- export { impl_2 as impl };
219
- }
220
- declare namespace util {
221
- export { escapeMain };
222
- export { parseExtension };
223
- export { mimeType };
224
- export { dataAsUrl };
225
- export { isDataUrl };
226
- export { canvasToBlob };
227
- export { resolveUrl };
228
- export { getAndEncode };
229
- export function uid(): string;
230
- export { delay };
231
- export { asArray };
232
- export { escapeXhtml };
233
- export { makeImage };
234
- export { width };
235
- export { height };
236
- }
237
- declare namespace inliner {
238
- export { inlineAll };
239
- export { shouldProcess };
240
- export namespace impl_3 {
241
- export { readUrls };
242
- export { inline };
243
- }
244
- export { impl_3 as impl };
245
- }
246
- declare function resolveAll(): Promise<string>;
247
- declare function readAll(): Promise<any>;
248
- declare function inlineAll(node: any): any;
249
- declare function newImage(element: any): {
250
- inline: (get: any) => Promise<any>;
251
- };
252
- declare function escapeMain(string: any): any;
253
- declare function parseExtension(url: any): string;
254
- declare function mimeType(url: any): any;
255
- declare function dataAsUrl(content: any, type: any): string;
256
- declare function isDataUrl(url: any): boolean;
257
- declare function canvasToBlob(canvas: any): Promise<any>;
258
- declare function resolveUrl(url: any, baseUrl: any): string;
259
- declare function getAndEncode(url: any): Promise<any>;
260
- declare function delay(ms: any): (arg: any) => Promise<any>;
261
- declare function asArray(arrayLike: any): any[];
262
- declare function escapeXhtml(string: any): any;
263
- declare function makeImage(uri: any): Promise<any>;
264
- declare function width(node: any): any;
265
- declare function height(node: any): any;
266
- declare function inlineAll_1(string: any, baseUrl: any, get: any): Promise<any>;
267
- declare function shouldProcess(string: any): boolean;
268
- declare function readUrls(string: any): string[];
269
- declare function inline(string: any, url: any, baseUrl: any, get: any): Promise<any>;
270
- export declare namespace impl {
271
- export { fontFaces };
272
- export { images };
273
- export { util };
274
- export { inliner };
275
- export const options: {};
276
- }
277
- export {};
36
+ * Render DOM node to Blob
37
+ * @param node - The DOM Node object to render
38
+ * @param options - Rendering options
39
+ * @returns Promise fulfilled with a Blob
40
+ */
41
+ declare function toBlob(node: Node, options?: DomScreenshotOptions): Promise<Blob>;
42
+ /**
43
+ * Render DOM node to PixelData
44
+ * @param node - The DOM Node object to render
45
+ * @param options - Rendering options
46
+ * @returns Promise fulfilled with pixel data array
47
+ */
48
+ declare function toPixelData(node: Node, options?: DomScreenshotOptions): Promise<Uint8ClampedArray>;
49
+ //# sourceMappingURL=dom-screenshot.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dom-screenshot.d.ts","sourceRoot":"","sources":["../src/dom-screenshot.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,oBAAoB,EAUrB,MAAM,iBAAiB,CAAC;AAazB;;GAEG;AACH,eAAO,MAAM,UAAU;;;;;;UAMT,GAAG;CAChB,CAAC;AAeF,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,CAAC;AAErD;;;;;GAKG;AACH,iBAAS,KAAK,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,EAAE,oBAAoB,GAAG,OAAO,CAAC,MAAM,CAAC,CAoC1E;AAED;;;;;GAKG;AACH,iBAAS,KAAK,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,EAAE,oBAAoB,GAAG,OAAO,CAAC,MAAM,CAAC,CAI1E;AAED;;;;;GAKG;AACH,iBAAS,MAAM,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,EAAE,oBAAoB,GAAG,OAAO,CAAC,MAAM,CAAC,CAK3E;AAED;;;;;GAKG;AACH,iBAAS,MAAM,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC,CAKzE;AAED;;;;;GAKG;AACH,iBAAS,WAAW,CAClB,IAAI,EAAE,IAAI,EACV,OAAO,CAAC,EAAE,oBAAoB,GAC7B,OAAO,CAAC,iBAAiB,CAAC,CAO5B"}