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.
- package/lib/commonjs/utils/module.d.js +2 -0
- package/lib/commonjs/utils/module.d.js.map +1 -0
- package/lib/commonjs/utils/normalizer.js +15 -9
- package/lib/commonjs/utils/normalizer.js.map +1 -1
- package/lib/module/utils/module.d.js +2 -0
- package/lib/module/utils/module.d.js.map +1 -0
- package/lib/module/utils/normalizer.js +14 -10
- package/lib/module/utils/normalizer.js.map +1 -1
- package/lib/typescript/src/utils/normalizer.d.ts.map +1 -1
- package/package.json +3 -1
- package/src/utils/module.d.ts +3 -0
- package/src/utils/normalizer.ts +16 -22
@@ -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
|
-
|
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
|
-
|
19
|
-
|
20
|
-
|
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
|
-
|
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":["
|
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,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AAG,CAAE,GAAE;IAC1D;MACI,OAAQ,GAAEtB,GAAI,IAAGD,kBAAkB,CAACC,GAAG,EAAEF,KAAK,CAAE,GAAE;EAC1D;AACJ,CAAC,CAAC,CACDL,MAAM,CAAC8B,OAAO,CAAC,CACfD,IAAI,CAAC,GAAG,CAAC;AAEP,MAAME,YAA0B,GAAA5B,OAAA,CAAA4B,YAAA,GAAG;EACtCtB,qBAAqB;EACrBU,oBAAoB;EACpBK;AACJ,CAAC"}
|
@@ -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
|
-
|
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
|
-
|
13
|
-
|
14
|
-
|
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
|
-
|
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","
|
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,GA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MI,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,MAAMvC,KAAK,GAAGD,cAAc,CAACqC,WAAW,EAAYE,aAAuB,CAAC;EAE5E,OAAQ,GAAER,OAAQ,IAAGE,OAAQ,IAAGE,MAAO,IAAGlC,KAAM,EAAC;AACrD,CAAC;AAED,MAAMwC,oBAAoB,GAAIC,UAAsB,IAAKA,UAAU,CAC9D3B,GAAG,CAAC4B,SAAS,IAAI;EACd,MAAM,CAACnB,GAAG,CAAC,GAAGoB,MAAM,CAACC,IAAI,CAACF,SAAS,CAAC;EAEpC,IAAI,CAACnB,GAAG,EAAE;IACN,OAAOnB,SAAS;EACpB;EAEA,MAAMiB,KAAK,GAAGqB,SAAS,CAACnB,GAAG,CAA2B;EAEtD,QAAOA,GAAG;IACN,KAAK,QAAQ;IACb,KAAK,UAAU;MACX,OAAQ,GAAEA,GAAI,IAAIF,KAAK,CAAmBwB,IAAI,CAAC,GAAG,CAAE,GAAE;IAC1D;MACI,OAAQ,GAAEtB,GAAI,IAAGD,kBAAkB,CAACC,GAAG,EAAEF,KAAK,CAAE,GAAE;EAC1D;AACJ,CAAC,CAAC,CACDJ,MAAM,CAAC6B,OAAO,CAAC,CACfD,IAAI,CAAC,GAAG,CAAC;AAEd,OAAO,MAAME,YAA0B,GAAG;EACtCtB,qBAAqB;EACrBU,oBAAoB;EACpBK;AACJ,CAAC"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"normalizer.d.ts","sourceRoot":"","sources":["../../../../src/utils/normalizer.ts"],"names":[],"mappings":"
|
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.
|
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": "*"
|
package/src/utils/normalizer.ts
CHANGED
@@ -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
|
-
|
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
|
-
|
20
|
-
|
21
|
-
|
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
|
-
|
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
|