1 | var React = require('react');
|
2 | var styleToJS = require('style-to-js').default;
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | function invertObject(obj, override) {
|
12 | if (!obj || typeof obj !== 'object') {
|
13 | throw new TypeError('First argument must be an object');
|
14 | }
|
15 |
|
16 | var key;
|
17 | var value;
|
18 | var isOverridePresent = typeof override === 'function';
|
19 | var overrides = {};
|
20 | var result = {};
|
21 |
|
22 | for (key in obj) {
|
23 | value = obj[key];
|
24 |
|
25 | if (isOverridePresent) {
|
26 | overrides = override(key, value);
|
27 | if (overrides && overrides.length === 2) {
|
28 | result[overrides[0]] = overrides[1];
|
29 | continue;
|
30 | }
|
31 | }
|
32 |
|
33 | if (typeof value === 'string') {
|
34 | result[value] = key;
|
35 | }
|
36 | }
|
37 |
|
38 | return result;
|
39 | }
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 | function isCustomComponent(tagName, props) {
|
51 | if (tagName.indexOf('-') === -1) {
|
52 | return props && typeof props.is === 'string';
|
53 | }
|
54 |
|
55 | switch (tagName) {
|
56 |
|
57 |
|
58 |
|
59 |
|
60 | case 'annotation-xml':
|
61 | case 'color-profile':
|
62 | case 'font-face':
|
63 | case 'font-face-src':
|
64 | case 'font-face-uri':
|
65 | case 'font-face-format':
|
66 | case 'font-face-name':
|
67 | case 'missing-glyph':
|
68 | return false;
|
69 | default:
|
70 | return true;
|
71 | }
|
72 | }
|
73 |
|
74 | var styleToJSOptions = { reactCompat: true };
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 |
|
82 | function setStyleProp(style, props) {
|
83 | if (style === null || style === undefined) {
|
84 | return;
|
85 | }
|
86 | props.style = styleToJS(style, styleToJSOptions);
|
87 | }
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 | var PRESERVE_CUSTOM_ATTRIBUTES = React.version.split('.')[0] >= 16;
|
94 |
|
95 | module.exports = {
|
96 | PRESERVE_CUSTOM_ATTRIBUTES: PRESERVE_CUSTOM_ATTRIBUTES,
|
97 | invertObject: invertObject,
|
98 | isCustomComponent: isCustomComponent,
|
99 | setStyleProp: setStyleProp
|
100 | };
|