rn-css 1.11.8 → 1.11.9
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 +5 -5
- package/dist/cssToRN/index.js +6 -0
- package/dist/features.d.ts +6 -0
- package/dist/features.js +10 -1
- package/dist/types.d.ts +6 -0
- package/package.json +1 -1
- package/src/convertUnits.ts +5 -5
- package/src/cssToRN/index.ts +7 -1
- package/src/features.tsx +10 -1
- package/src/types.ts +6 -0
package/dist/convertUnits.js
CHANGED
|
@@ -7,7 +7,7 @@ const react_native_1 = require("./react-native");
|
|
|
7
7
|
function parseValue(value) {
|
|
8
8
|
// Match a single unit
|
|
9
9
|
const unit = value.match(/([+-]?\b\d+(\.\d+)?)([a-z]+\b|%)?/i);
|
|
10
|
-
return [parseFloat(unit[1]), unit[3]];
|
|
10
|
+
return unit ? [parseFloat(unit[1]), unit[3]] : [0, undefined];
|
|
11
11
|
}
|
|
12
12
|
exports.parseValue = parseValue;
|
|
13
13
|
/** Convert a value using the provided unit transform table */
|
|
@@ -30,13 +30,13 @@ function convertValue(key, value, units) {
|
|
|
30
30
|
else if (['marginLeft', 'marginRight', 'translateX'].includes(key) || key.startsWith('borderLeft') || key.startsWith('borderRight'))
|
|
31
31
|
finalUnits['%'] = units.width / 100;
|
|
32
32
|
else if (key.startsWith('border') && key.endsWith('Radius'))
|
|
33
|
-
finalUnits['%'] = (units.width + units.height) / 200;
|
|
33
|
+
finalUnits['%'] = ((units.width || 0) + (units.height || 0)) / 200;
|
|
34
34
|
else if (['width', 'height', 'minWidth', 'minHeight', 'maxWidth', 'maxHeight', 'top', 'left', 'bottom', 'right', 'flexBasis', 'rotate3d'].includes(key)) {
|
|
35
35
|
if (value.startsWith('calc') || value.startsWith('max') || value.startsWith('min')) {
|
|
36
36
|
if (['height', 'minHeight', 'maxHeight', 'top', 'bottom'].includes(key))
|
|
37
|
-
finalUnits['%'] = units.height / 100;
|
|
37
|
+
finalUnits['%'] = (units.height || 0) / 100;
|
|
38
38
|
else
|
|
39
|
-
finalUnits['%'] = units.width / 100;
|
|
39
|
+
finalUnits['%'] = (units.width || 0) / 100;
|
|
40
40
|
}
|
|
41
41
|
// width: 100%, height: 100% are supported
|
|
42
42
|
else
|
|
@@ -53,7 +53,7 @@ function convertValue(key, value, units) {
|
|
|
53
53
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
54
54
|
if (['deg', 'rad', 'turn', 's'].includes(unit))
|
|
55
55
|
return occ; // We don't want to convert deg, rad, turn, second units
|
|
56
|
-
return val * (finalUnits[unit || 'px']) + '';
|
|
56
|
+
return val * (finalUnits[unit || 'px'] || 1) + '';
|
|
57
57
|
});
|
|
58
58
|
// We handle extra calculations (calc, min, max, parsing...)
|
|
59
59
|
if (convertedValue.startsWith('calc('))
|
package/dist/cssToRN/index.js
CHANGED
|
@@ -56,6 +56,12 @@ function cssToRNStyle(css, units = {}) {
|
|
|
56
56
|
vh: height / 100,
|
|
57
57
|
vmin: Math.min(width, height) / 100,
|
|
58
58
|
vmax: Math.max(width, height) / 100,
|
|
59
|
+
lvw: width / 100,
|
|
60
|
+
lvh: height / 100,
|
|
61
|
+
svw: width / 100,
|
|
62
|
+
svh: height / 100,
|
|
63
|
+
dvw: width / 100,
|
|
64
|
+
dvh: height / 100,
|
|
59
65
|
width: 100,
|
|
60
66
|
height: 100,
|
|
61
67
|
rem: 16,
|
package/dist/features.d.ts
CHANGED
|
@@ -7,6 +7,12 @@ export declare const useScreenSize: () => {
|
|
|
7
7
|
vh: number;
|
|
8
8
|
vmin: number;
|
|
9
9
|
vmax: number;
|
|
10
|
+
dvw: number;
|
|
11
|
+
dvh: number;
|
|
12
|
+
lvw: number;
|
|
13
|
+
lvh: number;
|
|
14
|
+
svw: number;
|
|
15
|
+
svh: number;
|
|
10
16
|
};
|
|
11
17
|
/** Hook that will apply the style reserved for hover state if needed */
|
|
12
18
|
export declare const useHover: (onMouseEnter: ((event: MouseEvent) => void) | undefined, onMouseLeave: ((event: MouseEvent) => void | undefined) | undefined, needsHover: boolean) => {
|
package/dist/features.js
CHANGED
|
@@ -13,7 +13,16 @@ const mediaQueries_1 = require("./cssToRN/mediaQueries");
|
|
|
13
13
|
const useScreenSize = () => {
|
|
14
14
|
const { width, height } = (0, react_native_1.useWindowDimensions)();
|
|
15
15
|
return react_1.default.useMemo(() => ({
|
|
16
|
-
vw: width / 100,
|
|
16
|
+
vw: width / 100,
|
|
17
|
+
vh: height / 100,
|
|
18
|
+
vmin: Math.min(width, height) / 100,
|
|
19
|
+
vmax: Math.max(width, height) / 100,
|
|
20
|
+
dvw: width / 100,
|
|
21
|
+
dvh: height / 100,
|
|
22
|
+
lvw: width / 100,
|
|
23
|
+
lvh: height / 100,
|
|
24
|
+
svw: width / 100,
|
|
25
|
+
svh: height / 100
|
|
17
26
|
}), [height, width]);
|
|
18
27
|
};
|
|
19
28
|
exports.useScreenSize = useScreenSize;
|
package/dist/types.d.ts
CHANGED
package/package.json
CHANGED
package/src/convertUnits.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { Platform } from './react-native'
|
|
|
6
6
|
export function parseValue (value: string): [number, string | undefined] {
|
|
7
7
|
// Match a single unit
|
|
8
8
|
const unit = value.match(/([+-]?\b\d+(\.\d+)?)([a-z]+\b|%)?/i)
|
|
9
|
-
return [parseFloat(unit
|
|
9
|
+
return unit ? [parseFloat(unit[1]), unit[3] as (string | undefined)] : [0, undefined]
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
/** Convert a value using the provided unit transform table */
|
|
@@ -25,11 +25,11 @@ export function convertValue (key: keyof PartialStyle | keyof Transform, value:
|
|
|
25
25
|
if (Platform.OS === 'web' && (!key.toLowerCase().includes('border') || key.toLowerCase().includes('radius'))) return value
|
|
26
26
|
if (['marginTop', 'marginBottom', 'translateY'].includes(key) || key.startsWith('borderTop') || key.startsWith('borderBottom')) finalUnits['%'] = units.height! / 100
|
|
27
27
|
else if (['marginLeft', 'marginRight', 'translateX'].includes(key) || key.startsWith('borderLeft') || key.startsWith('borderRight')) finalUnits['%'] = units.width! / 100
|
|
28
|
-
else if (key.startsWith('border') && key.endsWith('Radius')) finalUnits['%'] = (units.width
|
|
28
|
+
else if (key.startsWith('border') && key.endsWith('Radius')) finalUnits['%'] = ((units.width || 0) + (units.height || 0)) / 200
|
|
29
29
|
else if (['width', 'height', 'minWidth', 'minHeight', 'maxWidth', 'maxHeight', 'top', 'left', 'bottom', 'right', 'flexBasis', 'rotate3d'].includes(key)) {
|
|
30
30
|
if (value.startsWith('calc') || value.startsWith('max') || value.startsWith('min')) {
|
|
31
|
-
if (['height', 'minHeight', 'maxHeight', 'top', 'bottom'].includes(key)) finalUnits['%'] = units.height
|
|
32
|
-
else finalUnits['%'] = units.width
|
|
31
|
+
if (['height', 'minHeight', 'maxHeight', 'top', 'bottom'].includes(key)) finalUnits['%'] = (units.height || 0) / 100
|
|
32
|
+
else finalUnits['%'] = (units.width || 0) / 100
|
|
33
33
|
}
|
|
34
34
|
// width: 100%, height: 100% are supported
|
|
35
35
|
else return value
|
|
@@ -43,7 +43,7 @@ export function convertValue (key: keyof PartialStyle | keyof Transform, value:
|
|
|
43
43
|
const [val, unit] = parseValue(occ)
|
|
44
44
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
45
45
|
if (['deg', 'rad', 'turn', 's'].includes(unit!)) return occ // We don't want to convert deg, rad, turn, second units
|
|
46
|
-
return val * (finalUnits[unit as keyof Units || 'px']
|
|
46
|
+
return val * (finalUnits[unit as keyof Units || 'px'] || 1) + ''
|
|
47
47
|
})
|
|
48
48
|
|
|
49
49
|
// We handle extra calculations (calc, min, max, parsing...)
|
package/src/cssToRN/index.ts
CHANGED
|
@@ -20,7 +20,7 @@ function cssToStyle (css: string) {
|
|
|
20
20
|
const style = cssChunkToStyle(css)
|
|
21
21
|
const mediaQuery = (context: Context) => isValid(context) && style
|
|
22
22
|
if (!result.media) result.media = []
|
|
23
|
-
result.media
|
|
23
|
+
result.media.push(mediaQuery)
|
|
24
24
|
return ''
|
|
25
25
|
})
|
|
26
26
|
// Find hover (we don't support hover within media queries) (We use [\s\S] instead of . because dotall flag (s) is not supported by react-native-windows)
|
|
@@ -54,6 +54,12 @@ export function cssToRNStyle (css: string, units: { em?: number, width?: number,
|
|
|
54
54
|
vh: height / 100,
|
|
55
55
|
vmin: Math.min(width, height) / 100,
|
|
56
56
|
vmax: Math.max(width, height) / 100,
|
|
57
|
+
lvw: width / 100,
|
|
58
|
+
lvh: height / 100,
|
|
59
|
+
svw: width / 100,
|
|
60
|
+
svh: height / 100,
|
|
61
|
+
dvw: width / 100,
|
|
62
|
+
dvh: height / 100,
|
|
57
63
|
width: 100,
|
|
58
64
|
height: 100,
|
|
59
65
|
rem: 16,
|
package/src/features.tsx
CHANGED
|
@@ -9,7 +9,16 @@ import { createContext } from './cssToRN/mediaQueries'
|
|
|
9
9
|
export const useScreenSize = () => {
|
|
10
10
|
const { width, height } = useWindowDimensions()
|
|
11
11
|
return React.useMemo(() => ({
|
|
12
|
-
vw: width / 100,
|
|
12
|
+
vw: width / 100,
|
|
13
|
+
vh: height / 100,
|
|
14
|
+
vmin: Math.min(width, height) / 100,
|
|
15
|
+
vmax: Math.max(width, height) / 100,
|
|
16
|
+
dvw: width / 100,
|
|
17
|
+
dvh: height / 100,
|
|
18
|
+
lvw: width / 100,
|
|
19
|
+
lvh: height / 100,
|
|
20
|
+
svw: width / 100,
|
|
21
|
+
svh: height / 100
|
|
13
22
|
}), [height, width])
|
|
14
23
|
}
|
|
15
24
|
|