rn-css 1.6.14-2 → 1.6.16
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/dist/convertUnits.js +2 -2
- package/dist/cssToRN/convert.d.ts +6 -2
- package/dist/cssToRN/convert.js +30 -4
- package/dist/cssToRN/index.js +7 -3
- package/package.json +1 -1
- package/src/convertUnits.ts +1 -1
- package/src/cssToRN/convert.ts +25 -3
- package/src/cssToRN/index.ts +8 -4
package/dist/convertUnits.js
CHANGED
|
@@ -50,8 +50,8 @@ function convertValue(key, value, units) {
|
|
|
50
50
|
const convertedValue = value.replace(/(\b\d+(\.\d+)?)([a-z]+\b|%)/ig, occ => {
|
|
51
51
|
const [val, unit] = parseValue(occ);
|
|
52
52
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
53
|
-
if (['deg', 'rad', 'turn'].includes(unit))
|
|
54
|
-
return occ; // We don't want to convert deg
|
|
53
|
+
if (['deg', 'rad', 'turn', 's'].includes(unit))
|
|
54
|
+
return occ; // We don't want to convert deg, rad, turn, second units
|
|
55
55
|
return val * (finalUnits[unit || 'px']) + '';
|
|
56
56
|
});
|
|
57
57
|
// We handle extra calculations (calc, min, max, parsing...)
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import type { Style, Transform } from '../types';
|
|
2
2
|
/** Parse a css value for border */
|
|
3
|
-
export declare function border(
|
|
3
|
+
export declare function border(value: string): {
|
|
4
|
+
[x: string]: string;
|
|
5
|
+
};
|
|
6
|
+
/** Parse a css value for border-like elements */
|
|
7
|
+
export declare function borderLike(prefixKey: 'outline' | 'borderLeft' | 'borderRight' | 'borderTop' | 'borderBottom', value: string): {
|
|
4
8
|
[x: string]: string;
|
|
5
9
|
};
|
|
6
10
|
export declare function shadow(prefix: 'textShadow' | 'shadow', value: string): {
|
|
@@ -42,7 +46,7 @@ export declare function transform(value: string): {
|
|
|
42
46
|
};
|
|
43
47
|
export declare function font(value: string): Style;
|
|
44
48
|
/** Parses a css value for the side of an element (border-width, margin, padding) */
|
|
45
|
-
export declare function sideValue
|
|
49
|
+
export declare function sideValue<T extends 'padding' | 'margin' | 'border'>(prefixKey: T, value: string, postFix?: T extends 'border' ? 'Width' | 'Style' | 'Color' | '' : ''): {
|
|
46
50
|
[x: string]: string;
|
|
47
51
|
};
|
|
48
52
|
/** Parses a css value for the corner of an element (border-radius) */
|
package/dist/cssToRN/convert.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.cornerValue = exports.sideValue = exports.font = exports.transform = exports.textDecoration = exports.background = exports.placeContent = exports.flexFlow = exports.flex = exports.shadow = exports.border = void 0;
|
|
3
|
+
exports.cornerValue = exports.sideValue = exports.font = exports.transform = exports.textDecoration = exports.background = exports.placeContent = exports.flexFlow = exports.flex = exports.shadow = exports.borderLike = exports.border = void 0;
|
|
4
4
|
/** Check if the value is a number. Numbers start with a digit, a decimal point or calc(, max( ou min( */
|
|
5
5
|
function isNumber(value) {
|
|
6
6
|
return value.match(/^[+-]?(\.\d|\d|calc\(|max\(|min\()/mg);
|
|
@@ -26,7 +26,33 @@ function findNumbers(value) {
|
|
|
26
26
|
return result;
|
|
27
27
|
}
|
|
28
28
|
/** Parse a css value for border */
|
|
29
|
-
function border(
|
|
29
|
+
function border(value) {
|
|
30
|
+
const values = value.split(/\s+/mg);
|
|
31
|
+
const result = {
|
|
32
|
+
borderWidth: '0',
|
|
33
|
+
borderColor: 'black',
|
|
34
|
+
borderStyle: 'solid'
|
|
35
|
+
};
|
|
36
|
+
values.forEach((value) => {
|
|
37
|
+
if (['solid', 'dotted', 'dashed'].includes(value))
|
|
38
|
+
result.borderStyle = value;
|
|
39
|
+
else if (isNumber(value))
|
|
40
|
+
result.borderWidth = value;
|
|
41
|
+
// eslint-disable-next-line no-useless-return
|
|
42
|
+
else if (value === 'none')
|
|
43
|
+
return;
|
|
44
|
+
else
|
|
45
|
+
result.borderColor = value;
|
|
46
|
+
});
|
|
47
|
+
return {
|
|
48
|
+
...sideValue('border', result.borderWidth, 'Width'),
|
|
49
|
+
...sideValue('border', result.borderColor, 'Color'),
|
|
50
|
+
...sideValue('border', result.borderStyle, 'Style')
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
exports.border = border;
|
|
54
|
+
/** Parse a css value for border-like elements */
|
|
55
|
+
function borderLike(prefixKey, value) {
|
|
30
56
|
const values = value.split(/\s+/mg);
|
|
31
57
|
const result = {
|
|
32
58
|
[prefixKey + 'Width']: '0',
|
|
@@ -45,7 +71,7 @@ function border(prefixKey, value) {
|
|
|
45
71
|
});
|
|
46
72
|
return result;
|
|
47
73
|
}
|
|
48
|
-
exports.
|
|
74
|
+
exports.borderLike = borderLike;
|
|
49
75
|
function shadow(prefix, value) {
|
|
50
76
|
if (value === 'none')
|
|
51
77
|
return shadow(prefix, '0 0 0 black');
|
|
@@ -193,7 +219,7 @@ exports.font = font;
|
|
|
193
219
|
function sideValue(prefixKey, value, postFix = '') {
|
|
194
220
|
if (value === 'none')
|
|
195
221
|
return sideValue(prefixKey, '0', postFix);
|
|
196
|
-
const [top, right = top, bottom = top, left = right] = findNumbers(value).numbers;
|
|
222
|
+
const [top = value, right = top, bottom = top, left = right] = findNumbers(value).numbers;
|
|
197
223
|
return {
|
|
198
224
|
[prefixKey + 'Top' + postFix]: top,
|
|
199
225
|
[prefixKey + 'Left' + postFix]: left,
|
package/dist/cssToRN/index.js
CHANGED
|
@@ -69,16 +69,20 @@ function cssChunkToStyle(css) {
|
|
|
69
69
|
const key = kebab2camel(rawKey.trim());
|
|
70
70
|
const value = stripSpaces(rawValue.trim()); // We need this to correctly read calc() values
|
|
71
71
|
switch (key) {
|
|
72
|
-
case 'outline':
|
|
73
72
|
case 'border':
|
|
73
|
+
Object.assign(result, (0, convert_1.border)(value));
|
|
74
|
+
break;
|
|
74
75
|
case 'borderTop':
|
|
75
76
|
case 'borderLeft':
|
|
76
77
|
case 'borderRight':
|
|
77
78
|
case 'borderBottom':
|
|
78
|
-
|
|
79
|
+
case 'outline':
|
|
80
|
+
Object.assign(result, (0, convert_1.borderLike)(key, value));
|
|
79
81
|
break;
|
|
82
|
+
case 'borderStyle':
|
|
83
|
+
case 'borderColor':
|
|
80
84
|
case 'borderWidth':
|
|
81
|
-
Object.assign(result, (0, convert_1.sideValue)('border', value, '
|
|
85
|
+
Object.assign(result, (0, convert_1.sideValue)('border', value, key.split('border').pop()));
|
|
82
86
|
break;
|
|
83
87
|
case 'background':
|
|
84
88
|
Object.assign(result, (0, convert_1.background)(value));
|
package/package.json
CHANGED
package/src/convertUnits.ts
CHANGED
|
@@ -41,7 +41,7 @@ export function convertValue (key: keyof PartialStyle | keyof Transform, value:
|
|
|
41
41
|
const convertedValue = value.replace(/(\b\d+(\.\d+)?)([a-z]+\b|%)/ig, occ => {
|
|
42
42
|
const [val, unit] = parseValue(occ)
|
|
43
43
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
44
|
-
if (['deg', 'rad', 'turn'].includes(unit!)) return occ // We don't want to convert deg
|
|
44
|
+
if (['deg', 'rad', 'turn', 's'].includes(unit!)) return occ // We don't want to convert deg, rad, turn, second units
|
|
45
45
|
return val * (finalUnits[unit as keyof Units || 'px']!) + ''
|
|
46
46
|
})
|
|
47
47
|
|
package/src/cssToRN/convert.ts
CHANGED
|
@@ -23,7 +23,29 @@ function findNumbers (value: string) {
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
/** Parse a css value for border */
|
|
26
|
-
export function border (
|
|
26
|
+
export function border (value: string): { [x:string]: string } {
|
|
27
|
+
const values = value.split(/\s+/mg)
|
|
28
|
+
const result = {
|
|
29
|
+
borderWidth: '0',
|
|
30
|
+
borderColor: 'black',
|
|
31
|
+
borderStyle: 'solid'
|
|
32
|
+
}
|
|
33
|
+
values.forEach((value: string) => {
|
|
34
|
+
if (['solid', 'dotted', 'dashed'].includes(value)) result.borderStyle = value
|
|
35
|
+
else if (isNumber(value)) result.borderWidth = value
|
|
36
|
+
// eslint-disable-next-line no-useless-return
|
|
37
|
+
else if (value === 'none') return
|
|
38
|
+
else result.borderColor = value
|
|
39
|
+
})
|
|
40
|
+
return {
|
|
41
|
+
...sideValue('border', result.borderWidth, 'Width'),
|
|
42
|
+
...sideValue('border', result.borderColor, 'Color'),
|
|
43
|
+
...sideValue('border', result.borderStyle, 'Style')
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Parse a css value for border-like elements */
|
|
48
|
+
export function borderLike (prefixKey: 'outline' | 'borderLeft' | 'borderRight' | 'borderTop' | 'borderBottom', value: string): { [x:string]: string } {
|
|
27
49
|
const values = value.split(/\s+/mg)
|
|
28
50
|
const result = {
|
|
29
51
|
[prefixKey + 'Width']: '0',
|
|
@@ -164,9 +186,9 @@ export function font (value: string) {
|
|
|
164
186
|
}
|
|
165
187
|
|
|
166
188
|
/** Parses a css value for the side of an element (border-width, margin, padding) */
|
|
167
|
-
export function sideValue
|
|
189
|
+
export function sideValue <T extends 'padding' | 'margin' | 'border'> (prefixKey: T, value: string, postFix: T extends 'border' ? 'Width' | 'Style' | 'Color' | '' : '' = ''): { [x: string]: string} {
|
|
168
190
|
if (value === 'none') return sideValue(prefixKey, '0', postFix)
|
|
169
|
-
const [top, right = top, bottom = top, left = right] = findNumbers(value).numbers
|
|
191
|
+
const [top = value, right = top, bottom = top, left = right] = findNumbers(value).numbers
|
|
170
192
|
return {
|
|
171
193
|
[prefixKey + 'Top' + postFix]: top,
|
|
172
194
|
[prefixKey + 'Left' + postFix]: left,
|
package/src/cssToRN/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Dimensions } from 'react-native'
|
|
2
2
|
import convertStyle from '../convertStyle'
|
|
3
3
|
import type { Context, PartialStyle, Style, Units } from '../types'
|
|
4
|
-
import { sideValue, border, cornerValue, font, textDecoration, shadow, placeContent, flex, flexFlow, transform, background } from './convert'
|
|
4
|
+
import { sideValue, border, borderLike, cornerValue, font, textDecoration, shadow, placeContent, flex, flexFlow, transform, background } from './convert'
|
|
5
5
|
import { createMedia } from './mediaQueries'
|
|
6
6
|
|
|
7
7
|
function kebab2camel (string: string) {
|
|
@@ -66,16 +66,20 @@ function cssChunkToStyle (css: string) {
|
|
|
66
66
|
const key = kebab2camel(rawKey.trim())
|
|
67
67
|
const value = stripSpaces(rawValue.trim())// We need this to correctly read calc() values
|
|
68
68
|
switch (key) {
|
|
69
|
-
case 'outline':
|
|
70
69
|
case 'border':
|
|
70
|
+
Object.assign(result, border(value))
|
|
71
|
+
break
|
|
71
72
|
case 'borderTop':
|
|
72
73
|
case 'borderLeft':
|
|
73
74
|
case 'borderRight':
|
|
74
75
|
case 'borderBottom':
|
|
75
|
-
|
|
76
|
+
case 'outline':
|
|
77
|
+
Object.assign(result, borderLike(key, value))
|
|
76
78
|
break
|
|
79
|
+
case 'borderStyle':
|
|
80
|
+
case 'borderColor':
|
|
77
81
|
case 'borderWidth':
|
|
78
|
-
Object.assign(result, sideValue('border', value, 'Width'))
|
|
82
|
+
Object.assign(result, sideValue('border', value, key.split('border').pop() as '' | 'Width' | 'Style' | 'Color'))
|
|
79
83
|
break
|
|
80
84
|
case 'background':
|
|
81
85
|
Object.assign(result, background(value))
|