rn-css 1.6.12 → 1.6.14-1

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.
@@ -89,8 +89,9 @@ function placeContent(value) {
89
89
  exports.placeContent = placeContent;
90
90
  function background(value) {
91
91
  const values = value.split(/\s+/mg);
92
+ const color = values.pop();
92
93
  // The background-color is the only one that we support and it's the last value
93
- return { backgroundColor: values.pop() };
94
+ return { backgroundColor: isColor(color) ? color : 'transparent' };
94
95
  }
95
96
  exports.background = background;
96
97
  function textDecoration(value) {
@@ -212,3 +213,160 @@ function cornerValue(prefixKey, value, postFix) {
212
213
  };
213
214
  }
214
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
+ }
@@ -101,7 +101,7 @@ function parseConstraintValue(constraintString) {
101
101
  return (context) => evaluateConstraint(constraint, context);
102
102
  }
103
103
  function parse(constraint, previous) {
104
- const result = constraint.match(/\sand\s|,|\sonly\s|\(|\snot\s/ims);
104
+ const result = constraint.match(/\sand\s|,|\sonly\s|\(|\snot\s/im);
105
105
  if (!result) {
106
106
  // If we reached the end of the string, we just return the last constraint
107
107
  if (constraint.match(/\w/))
@@ -147,7 +147,8 @@ function parse(constraint, previous) {
147
147
  }
148
148
  }
149
149
  const createMedia = (query) => {
150
- const parsed = query.match(/@media(.*?){([^{}]*)}/mis);
150
+ // We use [\s\S] instead of dotall flag (s) because it is not supported by react-native-windows
151
+ const parsed = query.match(/@media([\s\S]*?){([^{}]*)}/mi);
151
152
  if (!parsed)
152
153
  throw new Error(`Parsing error: check the syntax of media query ${query}.`);
153
154
  const [, constraints, css] = parsed;
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.12",
3
+ "version": "1.6.14-1",
4
4
  "scripts": {
5
5
  "test": "jest",
6
6
  "prepare": "tsc",
@@ -9,7 +9,7 @@
9
9
  "start": "react-native start",
10
10
  "lint": "eslint --fix .",
11
11
  "build": "webpack",
12
- "release": "release-it",
12
+ "release": "npm run prepare && release-it",
13
13
  "web": "webpack serve --open --mode development"
14
14
  },
15
15
  "peerDependencies": {
@@ -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"
@@ -77,8 +77,9 @@ export function placeContent (value: string) {
77
77
 
78
78
  export function background (value: string) {
79
79
  const values = value.split(/\s+/mg)
80
+ const color = values.pop()
80
81
  // The background-color is the only one that we support and it's the last value
81
- return { backgroundColor: values.pop() }
82
+ return { backgroundColor: isColor(color) ? color : 'transparent' }
82
83
  }
83
84
 
84
85
  export function textDecoration (value: string) {
@@ -184,3 +185,159 @@ export function cornerValue (prefixKey: 'border', value: string, postFix: 'Radiu
184
185
  [prefixKey + 'BottomRight' + postFix]: bottomRight
185
186
  }
186
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
+ }
@@ -159,7 +159,7 @@ function parseConstraintValue (constraintString: string): Evaluation {
159
159
  export type Evaluation = (context: Context) => boolean
160
160
 
161
161
  function parse (constraint: string, previous?: Evaluation): Evaluation {
162
- const result = constraint.match(/\sand\s|,|\sonly\s|\(|\snot\s/ims)
162
+ const result = constraint.match(/\sand\s|,|\sonly\s|\(|\snot\s/im)
163
163
 
164
164
  if (!result) {
165
165
  // If we reached the end of the string, we just return the last constraint
@@ -206,7 +206,8 @@ function parse (constraint: string, previous?: Evaluation): Evaluation {
206
206
  }
207
207
 
208
208
  export const createMedia = (query: string) => {
209
- const parsed = query.match(/@media(.*?){([^{}]*)}/mis)
209
+ // We use [\s\S] instead of dotall flag (s) because it is not supported by react-native-windows
210
+ const parsed = query.match(/@media([\s\S]*?){([^{}]*)}/mi)
210
211
  if (!parsed) throw new Error(`Parsing error: check the syntax of media query ${query}.`)
211
212
  const [, constraints, css] = parsed
212
213
  const isValid = parse(constraints)
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
+ }