@mkhuda/dom-screenshot 0.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.
- package/.travis.yml +23 -0
- package/LICENSE +21 -0
- package/README.md +37 -0
- package/dist/dom-screenshot.d.ts +277 -0
- package/dist/dom-screenshot.min.js +1 -0
- package/package.json +46 -0
- package/rollup.config.js +20 -0
- package/tsconfig.json +21 -0
package/.travis.yml
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
language: node_js
|
|
2
|
+
node_js: 16
|
|
3
|
+
jobs:
|
|
4
|
+
include:
|
|
5
|
+
- stage: build
|
|
6
|
+
script:
|
|
7
|
+
- yarn build
|
|
8
|
+
before_deploy:
|
|
9
|
+
- yarn build
|
|
10
|
+
deploy:
|
|
11
|
+
- provider: npm
|
|
12
|
+
email: "$NPM_EMAIL"
|
|
13
|
+
api_key: "$NPM_TOKEN"
|
|
14
|
+
skip_cleanup: true
|
|
15
|
+
on:
|
|
16
|
+
branch: main
|
|
17
|
+
- provider: npm
|
|
18
|
+
tag: beta
|
|
19
|
+
email: "$NPM_EMAIL"
|
|
20
|
+
api_key: "$NPM_TOKEN"
|
|
21
|
+
skip_cleanup: true
|
|
22
|
+
on:
|
|
23
|
+
branch: beta
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Lek Huda
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# dom-screenshot
|
|
2
|
+
DOM screenshot by dom-to-image forked & modified from [dom-to-image](https://github.com/tsayen/dom-to-image)
|
|
3
|
+
|
|
4
|
+
## Added Fix:
|
|
5
|
+
- Add encodeURIComponent on makeSvgDataUri. Based on (this)[https://github.com/tsayen/dom-to-image/issues/78] issue
|
|
6
|
+
- Add Typescript support, (.d.ts) battery included.
|
|
7
|
+
|
|
8
|
+
## Usages (React)
|
|
9
|
+
```typescript
|
|
10
|
+
import DomToImage from "@mkhuda/dom-screenshot";
|
|
11
|
+
....
|
|
12
|
+
|
|
13
|
+
return(
|
|
14
|
+
<button
|
|
15
|
+
onClick={() => {
|
|
16
|
+
const getElement = document.getElementById("root") as HTMLElement;
|
|
17
|
+
const image = DomToImage.toPng(document.body, {});
|
|
18
|
+
image.then((generatedImage) => {
|
|
19
|
+
window.open(generatedImage);
|
|
20
|
+
});
|
|
21
|
+
}}
|
|
22
|
+
>
|
|
23
|
+
Test
|
|
24
|
+
</button>
|
|
25
|
+
)
|
|
26
|
+
...
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Contributing
|
|
30
|
+
|
|
31
|
+
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
|
|
32
|
+
|
|
33
|
+
Please make sure to update tests as appropriate.
|
|
34
|
+
|
|
35
|
+
## License
|
|
36
|
+
|
|
37
|
+
[MIT](https://choosealicense.com/licenses/mit/)
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
/**
|
|
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>;
|
|
42
|
+
/**
|
|
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>;
|
|
83
|
+
/**
|
|
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>;
|
|
124
|
+
/**
|
|
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>;
|
|
165
|
+
/**
|
|
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 {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
!function(){"use strict";!function(e){var t=function(){return{escapeMain:function(e){return e.replace(/([.*+?^${}()|\[\]\/\\])/g,"\\$1")},parseExtension:t,mimeType:function(e){var n=t(e).toLowerCase();return(r="application/font-woff",o="image/jpeg",{woff:r,woff2:r,ttf:"application/font-truetype",eot:"application/vnd.ms-fontobject",png:"image/png",jpg:o,jpeg:o,gif:"image/gif",tiff:"image/tiff",svg:"image/svg+xml"})[n]||"";var r,o},dataAsUrl:function(e,t){return"data:"+t+";base64,"+e},isDataUrl:function(e){return-1!==e.search(/^(data:)/)},canvasToBlob:function(e){return e.toBlob?new Promise((function(t){e.toBlob(t)})):function(e){return new Promise((function(t){for(var n=window.atob(e.toDataURL().split(",")[1]),r=n.length,o=new Uint8Array(r),i=0;i<r;i++)o[i]=n.charCodeAt(i);t(new Blob([o],{type:"image/png"}))}))}(e)},resolveUrl:function(e,t){var n=document.implementation.createHTMLDocument(),r=n.createElement("base");n.head.appendChild(r);var o=n.createElement("a");return n.body.appendChild(o),r.href=t,o.href=e,o.href},getAndEncode:function(e){var t=3e4;u.impl.options.cacheBust&&(e+=(/\?/.test(e)?"&":"?")+(new Date).getTime());return new Promise((function(n){var r,o=new XMLHttpRequest;if(o.onreadystatechange=a,o.ontimeout=c,o.responseType="blob",o.timeout=t,o.open("GET",e,!0),o.send(),u.impl.options.imagePlaceholder){var i=u.impl.options.imagePlaceholder.split(/,/);i&&i[1]&&(r=i[1])}function a(){if(4===o.readyState)if(200===o.status){var t=new FileReader;t.onloadend=function(){var e=t.result.split(/,/)[1];n(e)},t.readAsDataURL(o.response)}else r?n(r):l("cannot fetch resource: "+e+", status: "+o.status)}function c(){r?n(r):l("timeout of "+t+"ms occured while fetching resource: "+e)}function l(e){console.error(e),n("")}}))},uid:(e=0,function(){return"u"+t()+e++;function t(){return("0000"+(Math.random()*Math.pow(36,4)<<0).toString(36)).slice(-4)}}),delay:function(e){return function(t){return new Promise((function(n){setTimeout((function(){n(t)}),e)}))}},asArray:function(e){for(var t=[],n=e.length,r=0;r<n;r++)t.push(e[r]);return t},escapeXhtml:function(e){return e.replace(/#/g,"%23").replace(/\n/g,"%0A")},makeImage:function(e){return new Promise((function(t,n){var r=new Image;r.onload=function(){t(r)},r.onerror=n,r.src=e}))},width:function(e){var t=n(e,"border-left-width"),r=n(e,"border-right-width");return e.scrollWidth+t+r},height:function(e){var t=n(e,"border-top-width"),r=n(e,"border-bottom-width");return e.scrollHeight+t+r}};var e;function t(e){var t=/\.([^\.\/]*?)$/g.exec(e);return t?t[1]:""}function n(e,t){var n=window.getComputedStyle(e).getPropertyValue(t);return parseFloat(n.replace("px",""))}}(),n=function(){var e=/url\(['"]?([^'"]+?)['"]?\)/g;return{inlineAll:function(e,t,i){return u()?Promise.resolve(e):Promise.resolve(e).then(r).then((function(n){var r=Promise.resolve(e);return n.forEach((function(e){r=r.then((function(n){return o(n,e,t,i)}))})),r}));function u(){return!n(e)}},shouldProcess:n,impl:{readUrls:r,inline:o}};function n(t){return-1!==t.search(e)}function r(n){for(var r,o=[];null!==(r=e.exec(n));)o.push(r[1]);return o.filter((function(e){return!t.isDataUrl(e)}))}function o(e,n,r,o){return Promise.resolve(n).then((function(e){return r?t.resolveUrl(e,r):e})).then(o||t.getAndEncode).then((function(e){return t.dataAsUrl(e,t.mimeType(n))})).then((function(r){return e.replace(function(e){return new RegExp("(url\\(['\"]?)("+t.escapeMain(e)+")(['\"]?\\))","g")}(n),"$1"+r+"$3")}))}}(),r=function(){return{resolveAll:function(){return e().then((function(e){return Promise.all(e.map((function(e){return e.resolve()})))})).then((function(e){return e.join("\n")}))},impl:{readAll:e}};function e(){return Promise.resolve(t.asArray(document.styleSheets)).then((function(e){var n=[];return e.forEach((function(e){try{t.asArray(e.cssRules||[]).forEach(n.push.bind(n))}catch(t){console.log("Error while reading CSS rules from "+e.href,t.toString())}})),n})).then((function(e){return e.filter((function(e){return e.type===CSSRule.FONT_FACE_RULE})).filter((function(e){return n.shouldProcess(e.style.getPropertyValue("src"))}))})).then((function(t){return t.map(e)}));function e(e){return{resolve:function(){var t=(e.parentStyleSheet||{}).href;return n.inlineAll(e.cssText,t)},src:function(){return e.style.getPropertyValue("src")}}}}}(),o=function(){return{inlineAll:function r(o){return o instanceof Element?i(o).then((function(){return o instanceof HTMLImageElement?e(o).inline():Promise.all(t.asArray(o.childNodes).map((function(e){return r(e)})))})):Promise.resolve(o);function i(e){var t=e.style.getPropertyValue("background");return t?n.inlineAll(t).then((function(t){e.style.setProperty("background",t,e.style.getPropertyPriority("background"))})).then((function(){return e})):Promise.resolve(e)}},impl:{newImage:e}};function e(e){return{inline:function(n){return t.isDataUrl(e.src)?Promise.resolve():Promise.resolve(e.src).then(n||t.getAndEncode).then((function(n){return t.dataAsUrl(n,t.mimeType(e.src))})).then((function(t){return new Promise((function(n,r){e.onload=n,e.onerror=r,e.src=t}))}))}}}}(),i={imagePlaceholder:void 0,cacheBust:!1},u={toSvg:a,toPng:function(e,t){return c(e,t||{}).then((function(e){return e.toDataURL()}))},toJpeg:function(e,t){return c(e,t=t||{}).then((function(e){return e.toDataURL("image/jpeg",t.quality||1)}))},toBlob:function(e,n){return c(e,n||{}).then(t.canvasToBlob)},toPixelData:function(e,n){return c(e,n||{}).then((function(n){return n.getContext("2d").getImageData(0,0,t.width(e),t.height(e)).data}))},impl:{fontFaces:r,images:o,util:t,inliner:n,options:{}}};function a(e,n){return function(e){void 0===e.imagePlaceholder?u.impl.options.imagePlaceholder=i.imagePlaceholder:u.impl.options.imagePlaceholder=e.imagePlaceholder;void 0===e.cacheBust?u.impl.options.cacheBust=i.cacheBust:u.impl.options.cacheBust=e.cacheBust}(n=n||{}),Promise.resolve(e).then((function(e){return l(e,n.filter,!0)})).then(s).then(f).then((function(e){n.bgcolor&&(e.style.backgroundColor=n.bgcolor);n.width&&(e.style.width=n.width+"px");n.height&&(e.style.height=n.height+"px");n.style&&Object.keys(n.style).forEach((function(t){e.style[t]=n.style[t]}));return e})).then((function(r){return function(e,t,n){return Promise.resolve(e).then((function(e){return e.setAttribute("xmlns","http://www.w3.org/1999/xhtml"),(new XMLSerializer).serializeToString(e)})).then((function(e){return'<foreignObject x="0" y="0" width="100%" height="100%">'+e+"</foreignObject>"})).then((function(e){return'<svg xmlns="http://www.w3.org/2000/svg" width="'+t+'" height="'+n+'">'+e+"</svg>"})).then((function(e){return"data:image/svg+xml;charset=utf-8,"+encodeURIComponent(e)}))}(r,n.width||t.width(e),n.height||t.height(e))}))}function c(e,n){return a(e,n).then(t.makeImage).then(t.delay(100)).then((function(r){var o=function(e){var r=document.createElement("canvas");if(r.width=n.width||t.width(e),r.height=n.height||t.height(e),n.bgcolor){var o=r.getContext("2d");o.fillStyle=n.bgcolor,o.fillRect(0,0,r.width,r.height)}return r}(e);return o.getContext("2d").drawImage(r,0,0),o}))}function l(e,n,r){return r||!n||n(e)?Promise.resolve(e).then((function(e){return e instanceof HTMLCanvasElement?t.makeImage(e.toDataURL()):e.cloneNode(!1)})).then((function(r){return function(e,n,r){var o=e.childNodes;return 0===o.length?Promise.resolve(n):i(n,t.asArray(o),r).then((function(){return n}));function i(e,t,n){var r=Promise.resolve();return t.forEach((function(t){r=r.then((function(){return l(t,n)})).then((function(t){t&&e.appendChild(t)}))})),r}}(e,r,n)})).then((function(n){return function(e,n){var r=n;return r instanceof Element?Promise.resolve().then(o).then(i).then(u).then(a).then(c).then((function(){return r})):r;function o(){if(r instanceof HTMLVideoElement){var t=window.getComputedStyle(e),n=document.createElement("canvas");n.width=parseInt(t.width,10),n.height=parseInt(t.height,10);var o=Math.max(e.videoWidth/n.width,e.videoHeight/n.height),i=e.videoWidth/o,u=e.videoHeight/o,a=n.width/2-i/2,c=n.height/2-u/2;n.getContext("2d").drawImage(e,a,c,i,u),r=new Image;try{r.src=n.toDataURL()}catch(e){r.src="data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=="}}}function i(){function n(e,n){function r(e,n){t.asArray(e).forEach((function(t){n.setProperty(t,e.getPropertyValue(t),e.getPropertyPriority(t))}))}e.cssText?n.cssText=e.cssText:r(e,n)}n(window.getComputedStyle(e),r.style)}function u(){function n(n){var o=window.getComputedStyle(e,n),i=o.getPropertyValue("content");if(""!==i&&"none"!==i){var u=t.uid();r.className=r.className+" "+u;var a=document.createElement("style");a.appendChild(c(u,n,o)),r.appendChild(a)}function c(e,n,r){var o="."+e+":"+n,i=r.cssText?u(r):a(r);return document.createTextNode(o+"{"+i+"}");function u(e){var t=e.getPropertyValue("content");return e.cssText+" content: "+t+";"}function a(e){return t.asArray(e).map(n).join("; ")+";";function n(t){return t+": "+e.getPropertyValue(t)+(e.getPropertyPriority(t)?" !important":"")}}}}[":before",":after"].forEach((function(e){n(e)}))}function a(){e instanceof HTMLTextAreaElement&&(r.innerHTML=e.value),e instanceof HTMLInputElement&&r.setAttribute("value",e.value)}function c(){r instanceof SVGElement&&(r.setAttribute("xmlns","http://www.w3.org/2000/svg"),r instanceof SVGRectElement&&["width","height"].forEach((function(e){var t=r.getAttribute(e);t&&r.style.setProperty(e,t)})))}}(e,n)})):Promise.resolve()}function s(e){return r.resolveAll().then((function(t){var n=document.createElement("style");return e.appendChild(n),n.appendChild(document.createTextNode(t)),e}))}function f(e){return o.inlineAll(e).then((function(){return e}))}"undefined"!=typeof module?module.exports=u:e.domtoimage=u}(void 0)}();
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mkhuda/dom-screenshot",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "DOM screenshot by dom-to-image",
|
|
5
|
+
"main": "dist/dom-screenshot.min.js",
|
|
6
|
+
"types": "dist/dom-screenshot.d.ts",
|
|
7
|
+
"author": "Muhammad K. Huda",
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"scripts": {
|
|
10
|
+
"nodeminify": "node ./node_modules/.bin/node-minify",
|
|
11
|
+
"build": "rimraf dist && rollup -c --perf",
|
|
12
|
+
"build-dts": "npx -p typescript tsc src/dom-screenshot.js --declaration --allowJs --emitDeclarationOnly --outDir types",
|
|
13
|
+
"start": "yarn build",
|
|
14
|
+
"test": "jest",
|
|
15
|
+
"watch": "rollup -c --watch"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"prettier": "^2.3.2",
|
|
19
|
+
"rimraf": "^3.0.2",
|
|
20
|
+
"rollup": "^2.56.3",
|
|
21
|
+
"rollup-plugin-copy": "^3.4.0",
|
|
22
|
+
"rollup-plugin-terser": "^7.0.2",
|
|
23
|
+
"tslib": "^2.3.1",
|
|
24
|
+
"typescript": "^4.3.5"
|
|
25
|
+
},
|
|
26
|
+
"repository": {
|
|
27
|
+
"type": "git",
|
|
28
|
+
"url": "git+https://github.com/mkhuda/dom-screenshot.git"
|
|
29
|
+
},
|
|
30
|
+
"bugs": {
|
|
31
|
+
"url": "https://github.com/mkhuda/dom-screenshot/issues"
|
|
32
|
+
},
|
|
33
|
+
"homepage": "https://github.com/mkhuda/dom-screenshot#readme",
|
|
34
|
+
"publishConfig": {
|
|
35
|
+
"access": "public",
|
|
36
|
+
"registry": "https://registry.npmjs.org/"
|
|
37
|
+
},
|
|
38
|
+
"keywords": [
|
|
39
|
+
"dom",
|
|
40
|
+
"screenshot",
|
|
41
|
+
"capture",
|
|
42
|
+
"image",
|
|
43
|
+
"dom-to-image"
|
|
44
|
+
],
|
|
45
|
+
"dependencies": {}
|
|
46
|
+
}
|
package/rollup.config.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { terser } from "rollup-plugin-terser";
|
|
2
|
+
import copy from 'rollup-plugin-copy'
|
|
3
|
+
|
|
4
|
+
export default {
|
|
5
|
+
input: "src/dom-screenshot.js",
|
|
6
|
+
output: [
|
|
7
|
+
{
|
|
8
|
+
file: "dist/dom-screenshot.min.js",
|
|
9
|
+
format: "iife",
|
|
10
|
+
name: "version",
|
|
11
|
+
plugins: [
|
|
12
|
+
terser(),
|
|
13
|
+
copy({
|
|
14
|
+
targets: [{ src: "types/dom-screenshot.d.ts", dest: "dist" }],
|
|
15
|
+
hook: 'writeBundle'
|
|
16
|
+
}),
|
|
17
|
+
],
|
|
18
|
+
},
|
|
19
|
+
],
|
|
20
|
+
};
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
// Change this to match your project
|
|
3
|
+
"include": ["src/**/*"],
|
|
4
|
+
"compilerOptions": {
|
|
5
|
+
// Tells TypeScript to read JS files, as
|
|
6
|
+
// normally they are ignored as source files
|
|
7
|
+
"allowJs": true,
|
|
8
|
+
// Generate d.ts files
|
|
9
|
+
"declaration": true,
|
|
10
|
+
// This compiler run should
|
|
11
|
+
// only output d.ts files
|
|
12
|
+
"emitDeclarationOnly": true,
|
|
13
|
+
// Types should go into this directory.
|
|
14
|
+
// Removing this would place the .d.ts files
|
|
15
|
+
// next to the .js files
|
|
16
|
+
"outDir": "dist",
|
|
17
|
+
// go to js file when using IDE functions like
|
|
18
|
+
// "Go to Definition" in VSCode
|
|
19
|
+
"declarationMap": true
|
|
20
|
+
}
|
|
21
|
+
}
|