-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrpx2vw4style.js
29 lines (27 loc) · 961 Bytes
/
rpx2vw4style.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import rpx2vw from './rpx2vw';
import { RPX_PROPERTY_JSX } from './constants';
function rpx2vw4style(input, options = {}) {
const inputType = toString.call(input);
if (inputType === '[object Object]') {
for (const cssProperty in input) {
if (input.hasOwnProperty(cssProperty)) {
const value = input[cssProperty];
if (RPX_PROPERTY_JSX.indexOf(cssProperty) !== -1) {
const v = typeof value === 'number' ? value + 'rpx' : value
input[cssProperty] = rpx2vw(v, options);
}
}
}
} else if (inputType === '[object String]') {
const styles = input.split(';');
const newStyles = styles.map((style) => {
if (!style) return;
const [key, value] = style.split(':');
const v = typeof value === 'number' ? value + 'rpx' : value
return `${key.trim()}: ${rpx2vw(v.trim(), options)}`;
});
return newStyles.join(';');
}
return input;
}
export default rpx2vw4style;