1 | import { findDOMNode } from 'react-dom';
|
2 | import * as Creator from './Creator.web';
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | export default async function captureRef(component, options = {}) {
|
9 | const element = getElement(component || document.body);
|
10 | const { format = 'png' } = options;
|
11 | const finalFormat = format.toLowerCase();
|
12 | switch (finalFormat) {
|
13 | case 'jpg':
|
14 | return Creator.createJPEGAsync(element, options);
|
15 | case 'png':
|
16 | return Creator.createPNGAsync(element, options);
|
17 | case 'raw':
|
18 | return Creator.createPixelDataAsync(element, options);
|
19 | case 'svg':
|
20 | return Creator.createSVGAsync(element, options);
|
21 | case 'blob':
|
22 | return Creator.createBlobAsync(element, options);
|
23 | default:
|
24 | throw new Error(`takeSnapshotAsync: Unsupported format: ${finalFormat}`);
|
25 | }
|
26 | }
|
27 | const getElement = component => {
|
28 | try {
|
29 | return findDOMNode(component);
|
30 | }
|
31 | catch (e) {
|
32 | return component;
|
33 | }
|
34 | };
|
35 |
|
\ | No newline at end of file |