rn-css 1.6.11 → 1.6.14-0

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.
@@ -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
+ }
@@ -81,7 +81,7 @@ function cssChunkToStyle(css) {
81
81
  Object.assign(result, (0, convert_1.sideValue)('border', value, 'Width'));
82
82
  break;
83
83
  case 'background':
84
- Object.assign(result, { backgroundColor: value });
84
+ Object.assign(result, (0, convert_1.background)(value));
85
85
  break;
86
86
  case 'padding':
87
87
  case 'margin':
package/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import React from 'react';
2
2
  import * as RN from 'react-native';
3
+ import './polyfill';
3
4
  export { cssToRNStyle } from './cssToRN';
4
5
  export { SharedValue, FontSizeContext, RemContext } from './styleComponent';
5
6
  export * from './useTheme';
package/dist/index.js CHANGED
@@ -24,6 +24,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
24
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
25
  exports.RemContext = exports.FontSizeContext = exports.SharedValue = exports.cssToRNStyle = void 0;
26
26
  const RN = __importStar(require("react-native"));
27
+ require("./polyfill");
27
28
  const styleComponent_1 = __importStar(require("./styleComponent"));
28
29
  var cssToRN_1 = require("./cssToRN");
29
30
  Object.defineProperty(exports, "cssToRNStyle", { enumerable: true, get: function () { return cssToRN_1.cssToRNStyle; } });
@@ -0,0 +1,3 @@
1
+ /** polyfill for Node < 12 */
2
+ declare function flat<A, D extends number = 1>(array: A, depth?: number): FlatArray<A, D>[];
3
+ declare function matchAll(str: string, regex: RegExp): IterableIterator<RegExpMatchArray>;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ /** polyfill for Node < 12 */
3
+ // eslint-disable-next-line no-extend-native
4
+ if (!Array.prototype.flat)
5
+ Array.prototype.flat = function (depth) { return flat(this, depth); };
6
+ // eslint-disable-next-line no-extend-native
7
+ if (!String.prototype.matchAll)
8
+ String.prototype.matchAll = function (regex) { return matchAll(this, regex); };
9
+ /** polyfill for Node < 12 */
10
+ function flat(array, depth = 1) {
11
+ if (!depth || depth < 1 || !Array.isArray(array))
12
+ return array;
13
+ return array.reduce((result, current) => result.concat(flat(current, depth - 1)), []);
14
+ }
15
+ function matchAll(str, regex) {
16
+ const matches = [];
17
+ let groups;
18
+ // eslint-disable-next-line no-cond-assign
19
+ while (groups = regex.exec(str)) {
20
+ matches.push(groups);
21
+ }
22
+ return matches[Symbol.iterator]();
23
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rn-css",
3
- "version": "1.6.11",
3
+ "version": "1.6.14-0",
4
4
  "scripts": {
5
5
  "test": "jest",
6
6
  "prepare": "tsc",
@@ -53,9 +53,9 @@
53
53
  "ts-jest": "^27.1.1",
54
54
  "ts-loader": "^9.2.6",
55
55
  "typescript": "^4.5.4",
56
- "webpack": "^5.65.0",
57
- "webpack-cli": "^4.9.1",
58
- "webpack-dev-server": "^4.6.0"
56
+ "webpack": "^5.72.0",
57
+ "webpack-cli": "^4.9.2",
58
+ "webpack-dev-server": "^4.8.1"
59
59
  },
60
60
  "jest": {
61
61
  "preset": "react-native"
@@ -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) {
@@ -78,7 +78,7 @@ function cssChunkToStyle (css: string) {
78
78
  Object.assign(result, sideValue('border', value, 'Width'))
79
79
  break
80
80
  case 'background':
81
- Object.assign(result, { backgroundColor: value })
81
+ Object.assign(result, background(value))
82
82
  break
83
83
  case 'padding':
84
84
  case 'margin':
package/src/index.tsx CHANGED
@@ -1,5 +1,6 @@
1
1
  import React from 'react'
2
2
  import * as RN from 'react-native'
3
+ import './polyfill'
3
4
  import styledComponent, { styledFlatList, styledSectionList, styledVirtualizedList } from './styleComponent'
4
5
  export { cssToRNStyle } from './cssToRN'
5
6
  export { SharedValue, FontSizeContext, RemContext } from './styleComponent'
@@ -0,0 +1,23 @@
1
+ /** polyfill for Node < 12 */
2
+ // eslint-disable-next-line no-extend-native
3
+ if (!Array.prototype.flat) Array.prototype.flat = function <A, D extends number = 1> (depth?: number) { return flat<A, D>(this as unknown as A, depth) }
4
+ // eslint-disable-next-line no-extend-native
5
+ if (!String.prototype.matchAll) String.prototype.matchAll = function (regex: RegExp) { return matchAll(this as unknown as string, regex) }
6
+
7
+ /** polyfill for Node < 12 */
8
+ function flat <A, D extends number = 1> (array: A, depth = 1): FlatArray<A, D>[] {
9
+ if (!depth || depth < 1 || !Array.isArray(array)) return array as unknown as FlatArray<A, D>[]
10
+ return array.reduce((result, current) => result.concat(flat(current as unknown as unknown[], depth - 1)),
11
+ []
12
+ ) as FlatArray<A, D>[]
13
+ }
14
+
15
+ function matchAll (str: string, regex: RegExp): IterableIterator<RegExpMatchArray> {
16
+ const matches = []
17
+ let groups
18
+ // eslint-disable-next-line no-cond-assign
19
+ while (groups = regex.exec(str)) {
20
+ matches.push(groups)
21
+ }
22
+ return matches[Symbol.iterator]()
23
+ }