rn-css 1.6.13 → 1.6.14-2

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.
@@ -16,8 +16,8 @@ function stripSpaces(string) {
16
16
  }
17
17
  function cssToStyle(css) {
18
18
  const result = {};
19
- // Find media queries
20
- const cssWithoutMediaQueries = css.replace(/@media(.*?){[^{}]*}/gmis, res => {
19
+ // Find media queries (We use [\s\S] instead of . because dotall flag (s) is not supported by react-native-windows)
20
+ const cssWithoutMediaQueries = css.replace(/@media([\s\S]*?){[^{}]*}/gmi, res => {
21
21
  const { css, isValid } = (0, mediaQueries_1.createMedia)(res);
22
22
  const style = cssChunkToStyle(css);
23
23
  const mediaQuery = (context) => isValid(context) && style;
@@ -26,9 +26,9 @@ function cssToStyle(css) {
26
26
  result.media.push(mediaQuery);
27
27
  return '';
28
28
  });
29
- // Find hover (we don't support hover within media queries)
30
- const cssWithoutHover = cssWithoutMediaQueries.replace(/&:hover\s*{(.*?)}/gmis, res => {
31
- const hoverInstructions = res.substring(0, res.length - 1).replace(/&:hover\s*{/mis, ''); // We remove the `&:hover {` and `}`
29
+ // 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)
30
+ const cssWithoutHover = cssWithoutMediaQueries.replace(/&:hover\s*{([\s\S]*?)}/gmi, res => {
31
+ const hoverInstructions = res.substring(0, res.length - 1).replace(/&:hover\s*{/mi, ''); // We remove the `&:hover {` and `}`
32
32
  result.hover = cssChunkToStyle(hoverInstructions);
33
33
  return '';
34
34
  });
@@ -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.13",
3
+ "version": "1.6.14-2",
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"
@@ -14,8 +14,8 @@ function stripSpaces (string: string) {
14
14
 
15
15
  function cssToStyle (css: string) {
16
16
  const result: Style = {}
17
- // Find media queries
18
- const cssWithoutMediaQueries = css.replace(/@media(.*?){[^{}]*}/gmis, res => {
17
+ // Find media queries (We use [\s\S] instead of . because dotall flag (s) is not supported by react-native-windows)
18
+ const cssWithoutMediaQueries = css.replace(/@media([\s\S]*?){[^{}]*}/gmi, res => {
19
19
  const { css, isValid } = createMedia(res)
20
20
  const style = cssChunkToStyle(css)
21
21
  const mediaQuery = (context: Context) => isValid(context) && style
@@ -23,9 +23,9 @@ function cssToStyle (css: string) {
23
23
  result.media!.push(mediaQuery)
24
24
  return ''
25
25
  })
26
- // Find hover (we don't support hover within media queries)
27
- const cssWithoutHover = cssWithoutMediaQueries.replace(/&:hover\s*{(.*?)}/gmis, res => {
28
- const hoverInstructions = res.substring(0, res.length - 1).replace(/&:hover\s*{/mis, '')// We remove the `&:hover {` and `}`
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)
27
+ const cssWithoutHover = cssWithoutMediaQueries.replace(/&:hover\s*{([\s\S]*?)}/gmi, res => {
28
+ const hoverInstructions = res.substring(0, res.length - 1).replace(/&:hover\s*{/mi, '')// We remove the `&:hover {` and `}`
29
29
  result.hover = cssChunkToStyle(hoverInstructions)
30
30
  return ''
31
31
  })
@@ -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
+ }