rn-css 1.6.10 → 1.6.13

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.
@@ -1,6 +1,6 @@
1
1
  import type { Style, Transform } from '../types';
2
2
  /** Parse a css value for border */
3
- export declare function border(prefixKey: 'border' | 'borderLeft' | 'borderRight' | 'borderTop' | 'borderBottom', value: string): {
3
+ export declare function border(prefixKey: 'border' | 'borderLeft' | 'borderRight' | 'borderTop' | 'borderBottom' | 'outline', value: string): {
4
4
  [x: string]: string;
5
5
  };
6
6
  export declare function shadow(prefix: 'textShadow' | 'shadow', value: string): {
@@ -29,6 +29,9 @@ export declare function placeContent(value: string): {
29
29
  alignContent: string;
30
30
  justifyContent: string;
31
31
  };
32
+ export declare function background(value: string): {
33
+ backgroundColor: string | undefined;
34
+ };
32
35
  export declare function textDecoration(value: string): {
33
36
  textDecorationLine: string;
34
37
  textDecorationStyle: string;
@@ -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.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.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);
@@ -87,6 +87,13 @@ function placeContent(value) {
87
87
  return { alignContent, justifyContent };
88
88
  }
89
89
  exports.placeContent = placeContent;
90
+ function background(value) {
91
+ const values = value.split(/\s+/mg);
92
+ const color = values.pop();
93
+ // The background-color is the only one that we support and it's the last value
94
+ return { backgroundColor: isColor(color) ? color : 'transparent' };
95
+ }
96
+ exports.background = background;
90
97
  function textDecoration(value) {
91
98
  const values = value.split(/\s+/mg);
92
99
  const result = {
@@ -206,3 +213,160 @@ function cornerValue(prefixKey, value, postFix) {
206
213
  };
207
214
  }
208
215
  exports.cornerValue = cornerValue;
216
+ function isColor(value) {
217
+ if (!value)
218
+ return false;
219
+ if (value.startsWith('#') || value.startsWith('rgb') || value.startsWith('hsl'))
220
+ return true;
221
+ const CSS_COLOR_NAMES = [
222
+ 'aliceblue',
223
+ 'antiquewhite',
224
+ 'aqua',
225
+ 'aquamarine',
226
+ 'azure',
227
+ 'beige',
228
+ 'bisque',
229
+ 'black',
230
+ 'blanchedalmond',
231
+ 'blue',
232
+ 'blueviolet',
233
+ 'brown',
234
+ 'burlywood',
235
+ 'cadetblue',
236
+ 'chartreuse',
237
+ 'chocolate',
238
+ 'coral',
239
+ 'cornflowerblue',
240
+ 'cornsilk',
241
+ 'crimson',
242
+ 'cyan',
243
+ 'darkblue',
244
+ 'darkcyan',
245
+ 'darkgoldenrod',
246
+ 'darkgray',
247
+ 'darkgrey',
248
+ 'darkgreen',
249
+ 'darkkhaki',
250
+ 'darkmagenta',
251
+ 'darkolivegreen',
252
+ 'darkorange',
253
+ 'darkorchid',
254
+ 'darkred',
255
+ 'darksalmon',
256
+ 'darkseagreen',
257
+ 'darkslateblue',
258
+ 'darkslategray',
259
+ 'darkslategrey',
260
+ 'darkturquoise',
261
+ 'darkviolet',
262
+ 'deeppink',
263
+ 'deepskyblue',
264
+ 'dimgray',
265
+ 'dimgrey',
266
+ 'dodgerblue',
267
+ 'firebrick',
268
+ 'floralwhite',
269
+ 'forestgreen',
270
+ 'fuchsia',
271
+ 'gainsboro',
272
+ 'ghostwhite',
273
+ 'gold',
274
+ 'goldenrod',
275
+ 'gray',
276
+ 'grey',
277
+ 'green',
278
+ 'greenyellow',
279
+ 'honeydew',
280
+ 'hotpink',
281
+ 'indianred',
282
+ 'indigo',
283
+ 'ivory',
284
+ 'khaki',
285
+ 'lavender',
286
+ 'lavenderblush',
287
+ 'lawngreen',
288
+ 'lemonchiffon',
289
+ 'lightblue',
290
+ 'lightcoral',
291
+ 'lightcyan',
292
+ 'lightgoldenrodyellow',
293
+ 'lightgray',
294
+ 'lightgrey',
295
+ 'lightgreen',
296
+ 'lightpink',
297
+ 'lightsalmon',
298
+ 'lightseagreen',
299
+ 'lightskyblue',
300
+ 'lightslategray',
301
+ 'lightslategrey',
302
+ 'lightsteelblue',
303
+ 'lightyellow',
304
+ 'lime',
305
+ 'limegreen',
306
+ 'linen',
307
+ 'magenta',
308
+ 'maroon',
309
+ 'mediumaquamarine',
310
+ 'mediumblue',
311
+ 'mediumorchid',
312
+ 'mediumpurple',
313
+ 'mediumseagreen',
314
+ 'mediumslateblue',
315
+ 'mediumspringgreen',
316
+ 'mediumturquoise',
317
+ 'mediumvioletred',
318
+ 'midnightblue',
319
+ 'mintcream',
320
+ 'mistyrose',
321
+ 'moccasin',
322
+ 'navajowhite',
323
+ 'navy',
324
+ 'oldlace',
325
+ 'olive',
326
+ 'olivedrab',
327
+ 'orange',
328
+ 'orangered',
329
+ 'orchid',
330
+ 'palegoldenrod',
331
+ 'palegreen',
332
+ 'paleturquoise',
333
+ 'palevioletred',
334
+ 'papayawhip',
335
+ 'peachpuff',
336
+ 'peru',
337
+ 'pink',
338
+ 'plum',
339
+ 'powderblue',
340
+ 'purple',
341
+ 'rebeccapurple',
342
+ 'red',
343
+ 'rosybrown',
344
+ 'royalblue',
345
+ 'saddlebrown',
346
+ 'salmon',
347
+ 'sandybrown',
348
+ 'seagreen',
349
+ 'seashell',
350
+ 'sienna',
351
+ 'silver',
352
+ 'skyblue',
353
+ 'slateblue',
354
+ 'slategray',
355
+ 'slategrey',
356
+ 'snow',
357
+ 'springgreen',
358
+ 'steelblue',
359
+ 'tan',
360
+ 'teal',
361
+ 'thistle',
362
+ 'tomato',
363
+ 'turquoise',
364
+ 'violet',
365
+ 'wheat',
366
+ 'white',
367
+ 'whitesmoke',
368
+ 'yellow',
369
+ 'yellowgreen'
370
+ ];
371
+ return CSS_COLOR_NAMES.includes(value);
372
+ }
@@ -69,6 +69,7 @@ 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':
72
73
  case 'border':
73
74
  case 'borderTop':
74
75
  case 'borderLeft':
@@ -80,7 +81,7 @@ function cssChunkToStyle(css) {
80
81
  Object.assign(result, (0, convert_1.sideValue)('border', value, 'Width'));
81
82
  break;
82
83
  case 'background':
83
- Object.assign(result, { backgroundColor: value });
84
+ Object.assign(result, (0, convert_1.background)(value));
84
85
  break;
85
86
  case 'padding':
86
87
  case 'margin':
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rn-css",
3
- "version": "1.6.10",
3
+ "version": "1.6.13",
4
4
  "scripts": {
5
5
  "test": "jest",
6
6
  "prepare": "tsc",
@@ -23,7 +23,7 @@ function findNumbers (value: string) {
23
23
  }
24
24
 
25
25
  /** Parse a css value for border */
26
- export function border (prefixKey: 'border' | 'borderLeft' | 'borderRight' | 'borderTop' | 'borderBottom', value: string): { [x:string]: string } {
26
+ export function border (prefixKey: 'border' | 'borderLeft' | 'borderRight' | 'borderTop' | 'borderBottom' | 'outline', value: string): { [x:string]: string } {
27
27
  const values = value.split(/\s+/mg)
28
28
  const result = {
29
29
  [prefixKey + 'Width']: '0',
@@ -75,6 +75,13 @@ export function placeContent (value: string) {
75
75
  return { alignContent, justifyContent }
76
76
  }
77
77
 
78
+ export function background (value: string) {
79
+ const values = value.split(/\s+/mg)
80
+ const color = values.pop()
81
+ // The background-color is the only one that we support and it's the last value
82
+ return { backgroundColor: isColor(color) ? color : 'transparent' }
83
+ }
84
+
78
85
  export function textDecoration (value: string) {
79
86
  const values = value.split(/\s+/mg)
80
87
  const result = {
@@ -178,3 +185,159 @@ export function cornerValue (prefixKey: 'border', value: string, postFix: 'Radiu
178
185
  [prefixKey + 'BottomRight' + postFix]: bottomRight
179
186
  }
180
187
  }
188
+
189
+ function isColor (value?: string) {
190
+ if (!value) return false
191
+ if (value.startsWith('#') || value.startsWith('rgb') || value.startsWith('hsl')) return true
192
+ const CSS_COLOR_NAMES = [
193
+ 'aliceblue',
194
+ 'antiquewhite',
195
+ 'aqua',
196
+ 'aquamarine',
197
+ 'azure',
198
+ 'beige',
199
+ 'bisque',
200
+ 'black',
201
+ 'blanchedalmond',
202
+ 'blue',
203
+ 'blueviolet',
204
+ 'brown',
205
+ 'burlywood',
206
+ 'cadetblue',
207
+ 'chartreuse',
208
+ 'chocolate',
209
+ 'coral',
210
+ 'cornflowerblue',
211
+ 'cornsilk',
212
+ 'crimson',
213
+ 'cyan',
214
+ 'darkblue',
215
+ 'darkcyan',
216
+ 'darkgoldenrod',
217
+ 'darkgray',
218
+ 'darkgrey',
219
+ 'darkgreen',
220
+ 'darkkhaki',
221
+ 'darkmagenta',
222
+ 'darkolivegreen',
223
+ 'darkorange',
224
+ 'darkorchid',
225
+ 'darkred',
226
+ 'darksalmon',
227
+ 'darkseagreen',
228
+ 'darkslateblue',
229
+ 'darkslategray',
230
+ 'darkslategrey',
231
+ 'darkturquoise',
232
+ 'darkviolet',
233
+ 'deeppink',
234
+ 'deepskyblue',
235
+ 'dimgray',
236
+ 'dimgrey',
237
+ 'dodgerblue',
238
+ 'firebrick',
239
+ 'floralwhite',
240
+ 'forestgreen',
241
+ 'fuchsia',
242
+ 'gainsboro',
243
+ 'ghostwhite',
244
+ 'gold',
245
+ 'goldenrod',
246
+ 'gray',
247
+ 'grey',
248
+ 'green',
249
+ 'greenyellow',
250
+ 'honeydew',
251
+ 'hotpink',
252
+ 'indianred',
253
+ 'indigo',
254
+ 'ivory',
255
+ 'khaki',
256
+ 'lavender',
257
+ 'lavenderblush',
258
+ 'lawngreen',
259
+ 'lemonchiffon',
260
+ 'lightblue',
261
+ 'lightcoral',
262
+ 'lightcyan',
263
+ 'lightgoldenrodyellow',
264
+ 'lightgray',
265
+ 'lightgrey',
266
+ 'lightgreen',
267
+ 'lightpink',
268
+ 'lightsalmon',
269
+ 'lightseagreen',
270
+ 'lightskyblue',
271
+ 'lightslategray',
272
+ 'lightslategrey',
273
+ 'lightsteelblue',
274
+ 'lightyellow',
275
+ 'lime',
276
+ 'limegreen',
277
+ 'linen',
278
+ 'magenta',
279
+ 'maroon',
280
+ 'mediumaquamarine',
281
+ 'mediumblue',
282
+ 'mediumorchid',
283
+ 'mediumpurple',
284
+ 'mediumseagreen',
285
+ 'mediumslateblue',
286
+ 'mediumspringgreen',
287
+ 'mediumturquoise',
288
+ 'mediumvioletred',
289
+ 'midnightblue',
290
+ 'mintcream',
291
+ 'mistyrose',
292
+ 'moccasin',
293
+ 'navajowhite',
294
+ 'navy',
295
+ 'oldlace',
296
+ 'olive',
297
+ 'olivedrab',
298
+ 'orange',
299
+ 'orangered',
300
+ 'orchid',
301
+ 'palegoldenrod',
302
+ 'palegreen',
303
+ 'paleturquoise',
304
+ 'palevioletred',
305
+ 'papayawhip',
306
+ 'peachpuff',
307
+ 'peru',
308
+ 'pink',
309
+ 'plum',
310
+ 'powderblue',
311
+ 'purple',
312
+ 'rebeccapurple',
313
+ 'red',
314
+ 'rosybrown',
315
+ 'royalblue',
316
+ 'saddlebrown',
317
+ 'salmon',
318
+ 'sandybrown',
319
+ 'seagreen',
320
+ 'seashell',
321
+ 'sienna',
322
+ 'silver',
323
+ 'skyblue',
324
+ 'slateblue',
325
+ 'slategray',
326
+ 'slategrey',
327
+ 'snow',
328
+ 'springgreen',
329
+ 'steelblue',
330
+ 'tan',
331
+ 'teal',
332
+ 'thistle',
333
+ 'tomato',
334
+ 'turquoise',
335
+ 'violet',
336
+ 'wheat',
337
+ 'white',
338
+ 'whitesmoke',
339
+ 'yellow',
340
+ 'yellowgreen'
341
+ ]
342
+ return CSS_COLOR_NAMES.includes(value)
343
+ }
@@ -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 } from './convert'
4
+ import { sideValue, border, 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,6 +66,7 @@ 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':
69
70
  case 'border':
70
71
  case 'borderTop':
71
72
  case 'borderLeft':
@@ -77,7 +78,7 @@ function cssChunkToStyle (css: string) {
77
78
  Object.assign(result, sideValue('border', value, 'Width'))
78
79
  break
79
80
  case 'background':
80
- Object.assign(result, { backgroundColor: value })
81
+ Object.assign(result, background(value))
81
82
  break
82
83
  case 'padding':
83
84
  case 'margin':