rn-css 1.11.7 → 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.
@@ -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('))
@@ -34,10 +34,10 @@ export declare function placeContent(value: string): {
34
34
  justifyContent: string;
35
35
  };
36
36
  export declare function background(value: string): {
37
+ backgroundColor: string;
37
38
  background: string;
38
- backgroundColor?: undefined;
39
39
  } | {
40
- backgroundColor: string | undefined;
40
+ backgroundColor: string;
41
41
  background?: undefined;
42
42
  };
43
43
  export declare function textDecoration(value: string): {
@@ -50,7 +50,7 @@ export declare function transform(value: string): {
50
50
  };
51
51
  export declare function font(value: string): Style;
52
52
  /** Parses a css value for the side of an element (border-width, margin, padding) */
53
- export declare function sideValue<T extends 'padding' | 'margin' | 'border'>(prefixKey: T, value: string, postFix?: T extends 'border' ? 'Width' | 'Style' | 'Color' | '' : ''): {
53
+ export declare function sideValue<T extends 'padding' | 'margin' | 'border' | 'outline'>(prefixKey: T, value: string, postFix?: T extends 'border' | 'outline' ? 'Width' | 'Style' | 'Color' | '' : ''): {
54
54
  [x: string]: string;
55
55
  };
56
56
  /** Parses a css value for the corner of an element (border-radius) */
@@ -135,15 +135,10 @@ function placeContent(value) {
135
135
  }
136
136
  exports.placeContent = placeContent;
137
137
  function background(value) {
138
+ const values = value.match(/(linear-gradient\(|url\().*?\)|[^\s]+/mg) || [];
139
+ const backgroundColor = values.reverse().find(isColor) || 'transparent';
138
140
  // We support everything on web
139
- if (react_native_1.Platform.OS === 'web')
140
- return { background: value };
141
- else {
142
- const values = value.split(/\s+/mg);
143
- const color = values.pop();
144
- // The background-color is the only one that we support on RN and it's the last value
145
- return { backgroundColor: isColor(color) ? color : 'transparent' };
146
- }
141
+ return react_native_1.Platform.OS === 'web' ? { backgroundColor, background: value } : { backgroundColor };
147
142
  }
148
143
  exports.background = background;
149
144
  function textDecoration(value) {
@@ -270,6 +265,8 @@ function isColor(value) {
270
265
  return false;
271
266
  if (value.startsWith('#') || value.startsWith('rgb') || value.startsWith('hsl'))
272
267
  return true;
268
+ if (react_native_1.Platform.OS === 'web' && value.match(/^\s*linear-gradient\(.*\)/s))
269
+ return true;
273
270
  const CSS_COLOR_NAMES = [
274
271
  'aliceblue',
275
272
  'antiquewhite',
@@ -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,
@@ -96,6 +102,11 @@ function cssChunkToStyle(css) {
96
102
  case 'borderWidth':
97
103
  Object.assign(result, (0, convert_1.sideValue)('border', value, key.split('border').pop()));
98
104
  break;
105
+ case 'outlineStyle':
106
+ case 'outlineColor':
107
+ case 'outlineWidth':
108
+ Object.assign(result, (0, convert_1.sideValue)('outline', value, key.split('outline').pop()));
109
+ break;
99
110
  case 'background':
100
111
  Object.assign(result, (0, convert_1.background)(value));
101
112
  break;
@@ -133,6 +144,9 @@ function cssChunkToStyle(css) {
133
144
  else
134
145
  Object.assign(result, (0, convert_1.shadow)(key === 'boxShadow' ? 'shadow' : key, value));
135
146
  break;
147
+ case 'userSelect':
148
+ Object.assign(result, { userSelect: value, WebkitUserSelect: value });
149
+ break;
136
150
  // Other keys don't require any special treatment
137
151
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
138
152
  // @ts-ignore
@@ -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, vh: height / 100, vmin: Math.min(width, height) / 100, vmax: Math.max(width, height) / 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
@@ -3,6 +3,12 @@ export declare type Units = {
3
3
  '%'?: number;
4
4
  vw?: number;
5
5
  vh?: number;
6
+ dvw?: number;
7
+ dvh?: number;
8
+ lvw?: number;
9
+ lvh?: number;
10
+ svw?: number;
11
+ svh?: number;
6
12
  vmin?: number;
7
13
  vmax?: number;
8
14
  em: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rn-css",
3
- "version": "1.11.7",
3
+ "version": "1.11.9",
4
4
  "exports": {
5
5
  ".": {
6
6
  "import": "./dist/index.js",
@@ -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![1]), unit![3] as (string | undefined)]
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! + units.height!) / 200
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! / 100
32
- else finalUnits['%'] = units.width! / 100
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...)
@@ -118,14 +118,10 @@ export function placeContent (value: string) {
118
118
  }
119
119
 
120
120
  export function background (value: string) {
121
+ const values = value.match(/(linear-gradient\(|url\().*?\)|[^\s]+/mg) || []
122
+ const backgroundColor = values.reverse().find(isColor) || 'transparent'
121
123
  // We support everything on web
122
- if (Platform.OS === 'web') return { background: value }
123
- else {
124
- const values = value.split(/\s+/mg)
125
- const color = values.pop()
126
- // The background-color is the only one that we support on RN and it's the last value
127
- return { backgroundColor: isColor(color) ? color : 'transparent' }
128
- }
124
+ return Platform.OS === 'web' ? { backgroundColor, background: value } : { backgroundColor }
129
125
  }
130
126
 
131
127
  export function textDecoration (value: string) {
@@ -210,7 +206,7 @@ export function font (value: string) {
210
206
  }
211
207
 
212
208
  /** Parses a css value for the side of an element (border-width, margin, padding) */
213
- export function sideValue <T extends 'padding' | 'margin' | 'border'> (prefixKey: T, value: string, postFix: T extends 'border' ? 'Width' | 'Style' | 'Color' | '' : '' = ''): { [x: string]: string} {
209
+ export function sideValue <T extends 'padding' | 'margin' | 'border' | 'outline'> (prefixKey: T, value: string, postFix: T extends 'border' | 'outline' ? 'Width' | 'Style' | 'Color' | '' : '' = ''): { [x: string]: string} {
214
210
  if (value === 'none') return sideValue(prefixKey, '0', postFix)
215
211
  const [top = value, right = top, bottom = top, left = right] = findNumbers(value, prefixKey === 'margin').numbers
216
212
  return {
@@ -235,6 +231,7 @@ export function cornerValue (prefixKey: 'border', value: string, postFix: 'Radiu
235
231
  function isColor (value?: string) {
236
232
  if (!value) return false
237
233
  if (value.startsWith('#') || value.startsWith('rgb') || value.startsWith('hsl')) return true
234
+ if (Platform.OS === 'web' && value.match(/^\s*linear-gradient\(.*\)/s)) return true
238
235
  const CSS_COLOR_NAMES = [
239
236
  'aliceblue',
240
237
  'antiquewhite',
@@ -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!.push(mediaQuery)
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,
@@ -93,6 +99,11 @@ function cssChunkToStyle (css: string) {
93
99
  case 'borderWidth':
94
100
  Object.assign(result, sideValue('border', value, key.split('border').pop() as '' | 'Width' | 'Style' | 'Color'))
95
101
  break
102
+ case 'outlineStyle':
103
+ case 'outlineColor':
104
+ case 'outlineWidth':
105
+ Object.assign(result, sideValue('outline', value, key.split('outline').pop() as '' | 'Width' | 'Style' | 'Color'))
106
+ break
96
107
  case 'background':
97
108
  Object.assign(result, background(value))
98
109
  break
@@ -128,6 +139,9 @@ function cssChunkToStyle (css: string) {
128
139
  // We need to replace boxShadow by shadow
129
140
  else Object.assign(result, shadow(key === 'boxShadow' ? 'shadow' : key, value))
130
141
  break
142
+ case 'userSelect':
143
+ Object.assign(result, { userSelect: value, WebkitUserSelect: value })
144
+ break
131
145
  // Other keys don't require any special treatment
132
146
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
133
147
  // @ts-ignore
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, vh: height / 100, vmin: Math.min(width, height) / 100, vmax: Math.max(width, height) / 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
 
package/src/types.ts CHANGED
@@ -4,6 +4,12 @@ export type Units = {
4
4
  '%'?: number;
5
5
  vw?: number;
6
6
  vh?: number;
7
+ dvw?: number;
8
+ dvh?: number;
9
+ lvw?: number;
10
+ lvh?: number;
11
+ svw?: number;
12
+ svh?: number;
7
13
  vmin?: number;
8
14
  vmax?: number;
9
15
  em: number;