react-native-unistyles 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ //# sourceMappingURL=module.d.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sourceRoot":"../../../src","sources":["utils/module.d.ts"],"mappings":""}
@@ -4,23 +4,29 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.preprocessor = exports.normalizeNumericValue = exports.normalizeColor = void 0;
7
+ var _normalizeColors = _interopRequireDefault(require("@react-native/normalize-colors"));
8
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
7
9
  // based on react-native-web normalizer
8
10
  // https://github.com/necolas/react-native-web
9
11
 
10
- // for now supports
11
- // hex colors (3, 6, 8) chars
12
- // colors like orange red etc.
13
12
  const normalizeColor = function (color) {
14
13
  let opacity = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
15
- if (!color.startsWith('#')) {
14
+ // If the opacity is 1 there's no need to normalize the color
15
+ if (opacity === 1) {
16
16
  return color;
17
17
  }
18
- if (color.length === 9) {
19
- const [r, g, b, a] = color.slice(1).split(/(?=(?:..)*$)/).map(x => parseInt(x, 16)).filter(num => !isNaN(num));
20
- return `rgba(${r},${g},${b},${a / 255})`;
18
+ const integer = (0, _normalizeColors.default)(color);
19
+
20
+ // If the colour is an unknown format, the return value is null
21
+ if (integer === null) {
22
+ return color;
23
+ }
24
+ const hex = integer.toString(16).padStart(8, '0');
25
+ if (hex.length === 8) {
26
+ const [r = 0, g = 0, b = 0, a = 1] = hex.split(/(?=(?:..)*$)/).map(x => parseInt(x, 16)).filter(num => !isNaN(num));
27
+ return `rgba(${r},${g},${b},${a / 255 * opacity})`;
21
28
  }
22
- const sanitizedHex = color.length === 4 ? color.slice(1).split('').map(char => `${char}${char}`).join('') : color.slice(1);
23
- return sanitizedHex.split(/(?=(?:..)*$)/).map(x => parseInt(x, 16)).filter(num => !isNaN(num)).reduce((acc, color) => `${acc}${color},`, 'rgba(').concat(`${opacity})`);
29
+ return color;
24
30
  };
25
31
  exports.normalizeColor = normalizeColor;
26
32
  const normalizeNumericValue = value => value ? `${value}px` : value;
@@ -1 +1 @@
1
- {"version":3,"names":["normalizeColor","color","opacity","arguments","length","undefined","startsWith","r","g","b","a","slice","split","map","x","parseInt","filter","num","isNaN","sanitizedHex","char","join","reduce","acc","concat","exports","normalizeNumericValue","value","normalizeTransform","key","includes","createTextShadowValue","style","textShadowColor","textShadowOffset","textShadowRadius","offsetX","width","offsetY","height","radius","createBoxShadowValue","shadowColor","shadowOffset","shadowOpacity","shadowRadius","createTransformValue","transforms","transform","Object","keys","Boolean","preprocessor"],"sourceRoot":"../../../src","sources":["utils/normalizer.ts"],"mappings":";;;;;;AAAA;AACA;;AASA;AACA;AACA;AACO,MAAMA,cAAc,GAAG,SAAAA,CAACC,KAAa,EAA0B;EAAA,IAAxBC,OAAe,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC;EAC7D,IAAI,CAACF,KAAK,CAACK,UAAU,CAAC,GAAG,CAAC,EAAE;IACxB,OAAOL,KAAK;EAChB;EAEA,IAAIA,KAAK,CAACG,MAAM,KAAK,CAAC,EAAE;IACpB,MAAM,CAACG,CAAC,EAAEC,CAAC,EAAEC,CAAC,EAAEC,CAAC,CAAC,GAAGT,KAAK,CACrBU,KAAK,CAAC,CAAC,CAAC,CACRC,KAAK,CAAC,cAAc,CAAC,CACrBC,GAAG,CAACC,CAAC,IAAIC,QAAQ,CAACD,CAAC,EAAE,EAAE,CAAC,CAAC,CACzBE,MAAM,CAACC,GAAG,IAAI,CAACC,KAAK,CAACD,GAAG,CAAC,CAAC;IAE/B,OAAQ,QAAOV,CAAE,IAAGC,CAAE,IAAGC,CAAE,IAAIC,CAAC,GAAc,GAAI,GAAE;EACxD;EAEA,MAAMS,YAAY,GAAGlB,KAAK,CAACG,MAAM,KAAK,CAAC,GAC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AAC,CACDX,MAAM,CAACmC,OAAO,CAAC,CACf9B,IAAI,CAAC,GAAG,CAAC;AAEP,MAAM+B,YAA0B,GAAA3B,OAAA,CAAA2B,YAAA,GAAG;EACtCrB,qBAAqB;EACrBU,oBAAoB;EACpBK;AACJ,CAAC"}
1
+ {"version":3,"names":["_normalizeColors","_interopRequireDefault","require","obj","__esModule","default","normalizeColor","color","opacity","arguments","length","undefined","integer","normalizeColors","hex","toString","padStart","r","g","b","a","split","map","x","parseInt","filter","num","isNaN","exports","normalizeNumericValue","value","normalizeTransform","key","includes","createTextShadowValue","style","textShadowColor","textShadowOffset","textShadowRadius","offsetX","width","offsetY","height","radius","createBoxShadowValue","shadowColor","shadowOffset","shadowOpacity","shadowRadius","createTransformValue","transforms","transform","Object","keys","join","Boolean","preprocessor"],"sourceRoot":"../../../src","sources":["utils/normalizer.ts"],"mappings":";;;;;;AAEA,IAAAA,gBAAA,GAAAC,sBAAA,CAAAC,OAAA;AAA4D,SAAAD,uBAAAE,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAF5D;AACA;;AAUO,MAAMG,cAAc,GAAG,SAAAA,CAACC,KAAa,EAA0B;EAAA,IAAxBC,OAAe,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC;EAC7D;EACA,IAAID,OAAO,KAAK,CAAC,EAAE;IACf,OAAOD,KAAK;EAChB;EAEA,MAAMK,OAAO,GAAG,IAAAC,wBAAe,EAACN,KAAK,CAAkB;;EAEvD;EACA,IAAIK,OAAO,KAAK,IAAI,EAAE;IAClB,OAAOL,KAAK;EAChB;EAEA,MAAMO,GAAG,GAAGF,OAAO,CAACG,QAAQ,CAAC,EAAE,CAAC,CAACC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC;EAEjD,IAAIF,GAAG,CAACJ,MAAM,KAAK,CAAC,EAAE;IAClB,MAA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rBU,oBAAoB;EACpBK;AACJ,CAAC"}
@@ -0,0 +1,2 @@
1
+
2
+ //# sourceMappingURL=module.d.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sourceRoot":"../../../src","sources":["utils/module.d.ts"],"mappings":""}
@@ -1,20 +1,24 @@
1
1
  // based on react-native-web normalizer
2
2
  // https://github.com/necolas/react-native-web
3
-
4
- // for now supports
5
- // hex colors (3, 6, 8) chars
6
- // colors like orange red etc.
3
+ import normalizeColors from '@react-native/normalize-colors';
7
4
  export const normalizeColor = function (color) {
8
5
  let opacity = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
9
- if (!color.startsWith('#')) {
6
+ // If the opacity is 1 there's no need to normalize the color
7
+ if (opacity === 1) {
8
+ return color;
9
+ }
10
+ const integer = normalizeColors(color);
11
+
12
+ // If the colour is an unknown format, the return value is null
13
+ if (integer === null) {
10
14
  return color;
11
15
  }
12
- if (color.length === 9) {
13
- const [r, g, b, a] = color.slice(1).split(/(?=(?:..)*$)/).map(x => parseInt(x, 16)).filter(num => !isNaN(num));
14
- return `rgba(${r},${g},${b},${a / 255})`;
16
+ const hex = integer.toString(16).padStart(8, '0');
17
+ if (hex.length === 8) {
18
+ const [r = 0, g = 0, b = 0, a = 1] = hex.split(/(?=(?:..)*$)/).map(x => parseInt(x, 16)).filter(num => !isNaN(num));
19
+ return `rgba(${r},${g},${b},${a / 255 * opacity})`;
15
20
  }
16
- const sanitizedHex = color.length === 4 ? color.slice(1).split('').map(char => `${char}${char}`).join('') : color.slice(1);
17
- return sanitizedHex.split(/(?=(?:..)*$)/).map(x => parseInt(x, 16)).filter(num => !isNaN(num)).reduce((acc, color) => `${acc}${color},`, 'rgba(').concat(`${opacity})`);
21
+ return color;
18
22
  };
19
23
  export const normalizeNumericValue = value => value ? `${value}px` : value;
20
24
  const normalizeTransform = (key, value) => {
@@ -1 +1 @@
1
- {"version":3,"names":["normalizeColor","color","opacity","arguments","length","undefined","startsWith","r","g","b","a","slice","split","map","x","parseInt","filter","num","isNaN","sanitizedHex","char","join","reduce","acc","concat","normalizeNumericValue","value","normalizeTransform","key","includes","createTextShadowValue","style","textShadowColor","textShadowOffset","textShadowRadius","offsetX","width","offsetY","height","radius","createBoxShadowValue","shadowColor","shadowOffset","shadowOpacity","shadowRadius","createTransformValue","transforms","transform","Object","keys","Boolean","preprocessor"],"sourceRoot":"../../../src","sources":["utils/normalizer.ts"],"mappings":"AAAA;AACA;;AASA;AACA;AACA;AACA,OAAO,MAAMA,cAAc,GAAG,SAAAA,CAACC,KAAa,EAA0B;EAAA,IAAxBC,OAAe,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC;EAC7D,IAAI,CAACF,KAAK,CAACK,UAAU,CAAC,GAAG,CAAC,EAAE;IACxB,OAAOL,KAAK;EAChB;EAEA,IAAIA,KAAK,CAACG,MAAM,KAAK,CAAC,EAAE;IACpB,MAAM,CAACG,CAAC,EAAEC,CAAC,EAAEC,CAAC,EAAEC,CAAC,CAAC,GAAGT,KAAK,CACrBU,KAAK,CAAC,CAAC,CAAC,CACRC,KAAK,CAAC,cAAc,CAAC,CACrBC,GAAG,CAACC,CAAC,IAAIC,QAAQ,CAACD,CAAC,EAAE,EAAE,CAAC,CAAC,CACzBE,MAAM,CAACC,GAAG,IAAI,CAACC,KAAK,CAACD,GAAG,CAAC,CAAC;IAE/B,OAAQ,QAAOV,CAAE,IAAGC,CAAE,IAAGC,CAAE,IAAIC,CAAC,GAAc,GAAI,GAAE;EACxD;EAEA,MAAMS,YAAY,GAAGlB,KAAK,CAACG,MAAM,KAAK,CAAC,GACjCH,KAAK,CACFU,KAAK,CAAC,CAAC,CAAC,CACRC,KAAK,CAAC,EAAE,CAAC,CACTC,GAAG,CAACO,IAAI,IAAK,GAAEA,IAAK,GAAEA,IAAK,EAAC,CAAC,CAC7BC,IAAI,CAAC,EAAE,CAAC,GACXpB,KAAK,CAACU,KAAK,CAAC,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K;EAC/C;EACA,MAAM;IAAEU,WAAW;IAAEC,YAAY;IAAEC,aAAa;IAAEC;EAAa,CAAC,GAAGb,KAAK;EACxE,MAAMI,OAAO,GAAGV,qBAAqB,CAACiB,YAAY,CAACN,KAAK,CAAC;EACzD,MAAMC,OAAO,GAAGZ,qBAAqB,CAACiB,YAAY,CAACJ,MAAM,CAAC;EAC1D,MAAMC,MAAM,GAAGd,qBAAqB,CAACmB,YAAY,CAAC;EAClD,MAAM3C,KAAK,GAAGD,cAAc,CAACyC,WAAW,EAAYE,aAAuB,CAAC;EAE5E,OAAQ,GAAER,OAAQ,IAAGE,OAAQ,IAAGE,MAAO,IAAGtC,KAAM,EAAC;AACrD,CAAC;AAED,MAAM4C,oBAAoB,GAAIC,UAAsB,IAAKA,UAAU,CAC9DjC,GAAG,CAACkC,SAAS,IAAI;EACd,MAAM,CAACnB,GAAG,CAAC,GAAGoB,MAAM,CAACC,IAAI,CAACF,SAAS,CAAC;EAEpC,IAAI,CAACnB,GAAG,EAAE;IACN,OAAOvB,SAAS;EACpB;EAEA,MAAMqB,KAAK,GAAGqB,SAAS,CAACnB,GAAG,CAA2B;EAEtD,QAAOA,GAAG;IACN,KAAK,QAAQ;IACb,KAAK,UAAU;MACX,OAAQ,GAAEA,GAAI,IAAIF,KAAK,CAAmBL,IAAI,CAAC,GAAG,CAAE,GAAE;IAC1D;MACI,OAAQ,GAAEO,GAAI,IAAGD,kBAAkB,CAACC,GAAG,EAAEF,KAAK,CAAE,GAAE;EAC1D;AACJ,CAAC,CAAC,CACDV,MAAM,CAACkC,OAAO,CAAC,CACf7B,IAAI,CAAC,GAAG,CAAC;AAEd,OAAO,MAAM8B,YAA0B,GAAG;EACtCrB,qBAAqB;EACrBU,oBAAoB;EACpBK;AACJ,CAAC"}
1
+ {"version":3,"names":["normalizeColors","normalizeColor","color","opacity","arguments","length","undefined","integer","hex","toString","padStart","r","g","b","a","split","map","x","parseInt","filter","num","isNaN","normalizeNumericValue","value","normalizeTransform","key","includes","createTextShadowValue","style","textShadowColor","textShadowOffset","textShadowRadius","offsetX","width","offsetY","height","radius","createBoxShadowValue","shadowColor","shadowOffset","shadowOpacity","shadowRadius","createTransformValue","transforms","transform","Object","keys","join","Boolean","preprocessor"],"sourceRoot":"../../../src","sources":["utils/normalizer.ts"],"mappings":"AAAA;AACA;AACA,OAAOA,eAAe,MAAM,gCAAgC;AAS5D,OAAO,MAAMC,cAAc,GAAG,SAAAA,CAACC,KAAa,EAA0B;EAAA,IAAxBC,OAAe,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC;EAC7D;EACA,IAAID,OAAO,KAAK,CAAC,EAAE;IACf,OAAOD,KAAK;EAChB;EAEA,MAAMK,OAAO,GAAGP,eAAe,CAACE,KAAK,CAAkB;;EAEvD;EACA,IAAIK,OAAO,KAAK,IAAI,EAAE;IAClB,OAAOL,KAAK;EAChB;EAEA,MAAMM,GAAG,GAAGD,OAAO,CAACE,QAAQ,CAAC,EAAE,CAAC,CAACC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC;EAEjD,IAAIF,GAAG,CAACH,MAAM,KAAK,CAAC,EAAE;IAClB,MAAM,CAACM,CAAC,GAAG,CAAC,EAAEC,CAAC,GAAG,CAAC,EAAEC,CAAC,GAAG,CAAC,EAAEC,CAAC,GAAG,CAAC,CAAC,GAAGN,GAAG,CACnCO,KAAK,CAAC,cAAc,CAAC,CACrBC,GAAG,CAACC,CAAC,IAAIC,QAAQ,CAACD,CAAC,EAAE,EAAE,CAAC,CAAC,CACzBE,MAAM,CAACC,GAAG,IAAI,CAACC,KAAK,CAACD,GAAG,CAAC,CAAC;IAE/B,OAAQ,QAAOT,CAAE,IAAGC,CAAE,IAAGC,CAAE,IAAKC,CAAC,GAAc,GAAG,GAAIX,OAAQ,GAAE;EACpE;EAEA,OAAOD,KAAK;AAChB,CAAC;AAED,OAAO,MAAMoB,qBAAqB,GAAIC,KAAa,IAAKA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AAM,YAAY,EAAE,YAI1B,CAAA"}
1
+ {"version":3,"file":"normalizer.d.ts","sourceRoot":"","sources":["../../../../src/utils/normalizer.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAEjE,KAAK,YAAY,GAAG;IAChB,qBAAqB,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAAC;IACjD,oBAAoB,CAAC,KAAK,EAAE,QAAQ,CAAC,SAAS,CAAC,GAAG,MAAM,CAAC;IACzD,oBAAoB,CAAC,UAAU,EAAE,QAAQ,CAAC,UAAU,CAAC,GAAG,MAAM,CAAC;CAClE,CAAA;AAED,eAAO,MAAM,cAAc,UAAW,MAAM,YAAW,MAAM,WAyB5D,CAAA;AAED,eAAO,MAAM,qBAAqB,UAAW,MAAM,oBAAiC,CAAA;AAwDpF,eAAO,MAAM,YAAY,EAAE,YAI1B,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-unistyles",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "Level up your React Native StyleSheet",
5
5
  "scripts": {
6
6
  "test": "jest",
@@ -41,6 +41,7 @@
41
41
  "devDependencies": {
42
42
  "@commitlint/config-conventional": "17.8.0",
43
43
  "@react-native/eslint-config": "0.74.0",
44
+ "@react-native/normalize-colors": "0.74.1",
44
45
  "@release-it/conventional-changelog": "5.1.1",
45
46
  "@testing-library/react-hooks": "8.0.1",
46
47
  "@types/jest": "29.5.5",
@@ -75,6 +76,7 @@
75
76
  "typescript": "5.2.2"
76
77
  },
77
78
  "peerDependencies": {
79
+ "@react-native/normalize-colors": "*",
78
80
  "react": "*",
79
81
  "react-native": "*",
80
82
  "react-native-web": "*"
@@ -0,0 +1,3 @@
1
+ declare module '@react-native/normalize-colors' {
2
+ export default function normalizeColor(color: string): number | null
3
+ }
@@ -1,5 +1,6 @@
1
1
  // based on react-native-web normalizer
2
2
  // https://github.com/necolas/react-native-web
3
+ import normalizeColors from '@react-native/normalize-colors'
3
4
  import type { TextShadow, Transforms, BoxShadow } from '../types'
4
5
 
5
6
  type Preprocessor = {
@@ -8,38 +9,31 @@ type Preprocessor = {
8
9
  createTransformValue(transforms: Required<Transforms>): string,
9
10
  }
10
11
 
11
- // for now supports
12
- // hex colors (3, 6, 8) chars
13
- // colors like orange red etc.
14
12
  export const normalizeColor = (color: string, opacity: number = 1) => {
15
- if (!color.startsWith('#')) {
13
+ // If the opacity is 1 there's no need to normalize the color
14
+ if (opacity === 1) {
16
15
  return color
17
16
  }
18
17
 
19
- if (color.length === 9) {
20
- const [r, g, b, a] = color
21
- .slice(1)
18
+ const integer = normalizeColors(color) as number | null
19
+
20
+ // If the colour is an unknown format, the return value is null
21
+ if (integer === null) {
22
+ return color
23
+ }
24
+
25
+ const hex = integer.toString(16).padStart(8, '0')
26
+
27
+ if (hex.length === 8) {
28
+ const [r = 0, g = 0, b = 0, a = 1] = hex
22
29
  .split(/(?=(?:..)*$)/)
23
30
  .map(x => parseInt(x, 16))
24
31
  .filter(num => !isNaN(num))
25
32
 
26
- return `rgba(${r},${g},${b},${(a as number) / 255})`
33
+ return `rgba(${r},${g},${b},${((a as number) / 255) * opacity})`
27
34
  }
28
35
 
29
- const sanitizedHex = color.length === 4
30
- ? color
31
- .slice(1)
32
- .split('')
33
- .map(char => `${char}${char}`)
34
- .join('')
35
- : color.slice(1)
36
-
37
- return sanitizedHex
38
- .split(/(?=(?:..)*$)/)
39
- .map(x => parseInt(x, 16))
40
- .filter(num => !isNaN(num))
41
- .reduce((acc, color) => `${acc}${color},`, 'rgba(')
42
- .concat(`${opacity})`)
36
+ return color
43
37
  }
44
38
 
45
39
  export const normalizeNumericValue = (value: number) => value ? `${value}px` : value