rn-css 1.11.9 → 1.11.11

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.
@@ -17,7 +17,7 @@ function convertValue(key, value, units) {
17
17
  return 0;
18
18
  }
19
19
  // colors should be left untouched
20
- if (value.startsWith('#'))
20
+ if (value.startsWith('#') || value.startsWith('linear-gradient'))
21
21
  return value;
22
22
  // Percentage values need to rely on an other unit as reference
23
23
  const finalUnits = { ...units };
@@ -26,9 +26,9 @@ function convertValue(key, value, units) {
26
26
  if (react_native_1.Platform.OS === 'web' && (!key.toLowerCase().includes('border') || key.toLowerCase().includes('radius')))
27
27
  return value;
28
28
  if (['marginTop', 'marginBottom', 'translateY'].includes(key) || key.startsWith('borderTop') || key.startsWith('borderBottom'))
29
- finalUnits['%'] = units.height / 100;
29
+ finalUnits['%'] = (units.height || 0) / 100;
30
30
  else if (['marginLeft', 'marginRight', 'translateX'].includes(key) || key.startsWith('borderLeft') || key.startsWith('borderRight'))
31
- finalUnits['%'] = units.width / 100;
31
+ finalUnits['%'] = (units.width || 0) / 100;
32
32
  else if (key.startsWith('border') && key.endsWith('Radius'))
33
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)) {
@@ -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'] || 1) + '';
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('))
@@ -136,7 +136,9 @@ function placeContent(value) {
136
136
  exports.placeContent = placeContent;
137
137
  function background(value) {
138
138
  const values = value.match(/(linear-gradient\(|url\().*?\)|[^\s]+/mg) || [];
139
- const backgroundColor = values.reverse().find(isColor) || 'transparent';
139
+ const backgroundColor = values.reverse().find(isColor) ||
140
+ (values[0]?.startsWith('linear-gradient') && values[0].split(',').map(val => val.trim()).find(isColor)) ||
141
+ 'transparent';
140
142
  // We support everything on web
141
143
  return react_native_1.Platform.OS === 'web' ? { backgroundColor, background: value } : { backgroundColor };
142
144
  }
@@ -26,7 +26,7 @@ function buildCSSString(chunks, functs, props, shared) {
26
26
  .map((chunk, i) => ([chunk, (functs[i] instanceof Function) ? functs[i]({ shared, theme: shared, ...props }) : functs[i]]))
27
27
  .flat()
28
28
  // Convert the objects to string if the result is not a primitive
29
- .map(chunk => typeof chunk === 'object' ? (0, rnToCss_1.default)(chunk) : chunk)
29
+ .map(chunk => chunk && typeof chunk === 'object' ? (0, rnToCss_1.default)(chunk) : chunk)
30
30
  .join('');
31
31
  if (props.rnCSS)
32
32
  computedString += props.rnCSS.replace(/=/gm, ':') + ';';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rn-css",
3
- "version": "1.11.9",
3
+ "version": "1.11.11",
4
4
  "exports": {
5
5
  ".": {
6
6
  "import": "./dist/index.js",
@@ -16,15 +16,15 @@ export function convertValue (key: keyof PartialStyle | keyof Transform, value:
16
16
  return 0
17
17
  }
18
18
  // colors should be left untouched
19
- if (value.startsWith('#')) return value
19
+ if (value.startsWith('#') || value.startsWith('linear-gradient')) return value
20
20
 
21
21
  // Percentage values need to rely on an other unit as reference
22
22
  const finalUnits = { ...units }
23
23
  if (value.includes('%')) {
24
24
  // Percentage is not supported on borders in web
25
25
  if (Platform.OS === 'web' && (!key.toLowerCase().includes('border') || key.toLowerCase().includes('radius'))) return value
26
- if (['marginTop', 'marginBottom', 'translateY'].includes(key) || key.startsWith('borderTop') || key.startsWith('borderBottom')) finalUnits['%'] = units.height! / 100
27
- else if (['marginLeft', 'marginRight', 'translateX'].includes(key) || key.startsWith('borderLeft') || key.startsWith('borderRight')) finalUnits['%'] = units.width! / 100
26
+ if (['marginTop', 'marginBottom', 'translateY'].includes(key) || key.startsWith('borderTop') || key.startsWith('borderBottom')) finalUnits['%'] = (units.height || 0) / 100
27
+ else if (['marginLeft', 'marginRight', 'translateX'].includes(key) || key.startsWith('borderLeft') || key.startsWith('borderRight')) finalUnits['%'] = (units.width || 0) / 100
28
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')) {
@@ -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'] || 1) + ''
46
+ return val * (finalUnits[unit as keyof Units || 'px'] ?? 1) + ''
47
47
  })
48
48
 
49
49
  // We handle extra calculations (calc, min, max, parsing...)
@@ -119,7 +119,9 @@ export function placeContent (value: string) {
119
119
 
120
120
  export function background (value: string) {
121
121
  const values = value.match(/(linear-gradient\(|url\().*?\)|[^\s]+/mg) || []
122
- const backgroundColor = values.reverse().find(isColor) || 'transparent'
122
+ const backgroundColor = values.reverse().find(isColor) ||
123
+ (values[0]?.startsWith('linear-gradient') && values[0].split(',').map(val => val.trim()).find(isColor)) ||
124
+ 'transparent'
123
125
  // We support everything on web
124
126
  return Platform.OS === 'web' ? { backgroundColor, background: value } : { backgroundColor }
125
127
  }
@@ -44,7 +44,7 @@ function buildCSSString<T extends { rnCSS?: string }> (chunks: TemplateStringsAr
44
44
  .map((chunk, i) => ([chunk, (functs[i] instanceof Function) ? (functs[i] as Functs<T>)({ shared, theme: (shared as DefaultTheme), ...props }) : functs[i]]))
45
45
  .flat()
46
46
  // Convert the objects to string if the result is not a primitive
47
- .map(chunk => typeof chunk === 'object' ? rnToCSS(chunk as Partial<CompleteStyle>) : chunk)
47
+ .map(chunk => chunk && typeof chunk === 'object' ? rnToCSS(chunk as Partial<CompleteStyle>) : chunk)
48
48
  .join('')
49
49
  if (props.rnCSS) computedString += props.rnCSS.replace(/=/gm, ':') + ';'
50
50
  return computedString