react-native-unistyles 2.0.0-alpha.17 → 2.0.0-alpha.18
Sign up to get free protection for your applications and to get access to all the features.
- package/cxx/UnistylesRuntime.h +3 -3
- package/lib/commonjs/common.js +1 -1
- package/lib/commonjs/common.js.map +1 -1
- package/lib/commonjs/core/UnistylesRuntime.js +4 -1
- package/lib/commonjs/core/UnistylesRuntime.js.map +1 -1
- package/lib/commonjs/hooks/useVariants.js +1 -11
- package/lib/commonjs/hooks/useVariants.js.map +1 -1
- package/lib/commonjs/plugins/index.js +0 -7
- package/lib/commonjs/plugins/index.js.map +1 -1
- package/lib/commonjs/useStyles.js +3 -4
- package/lib/commonjs/useStyles.js.map +1 -1
- package/lib/commonjs/utils/breakpoints.js.map +1 -1
- package/lib/commonjs/utils/index.js +7 -0
- package/lib/commonjs/utils/index.js.map +1 -1
- package/lib/commonjs/utils/mqParser.js.map +1 -1
- package/lib/commonjs/utils/styles.js +26 -18
- package/lib/commonjs/utils/styles.js.map +1 -1
- package/lib/commonjs/utils/withPlugins.js +15 -0
- package/lib/commonjs/utils/withPlugins.js.map +1 -0
- package/lib/module/common.js +1 -1
- package/lib/module/common.js.map +1 -1
- package/lib/module/core/UnistylesRuntime.js +4 -1
- package/lib/module/core/UnistylesRuntime.js.map +1 -1
- package/lib/module/hooks/useVariants.js +1 -11
- package/lib/module/hooks/useVariants.js.map +1 -1
- package/lib/module/plugins/index.js +0 -1
- package/lib/module/plugins/index.js.map +1 -1
- package/lib/module/useStyles.js +4 -5
- package/lib/module/useStyles.js.map +1 -1
- package/lib/module/utils/breakpoints.js.map +1 -1
- package/lib/module/utils/index.js +1 -0
- package/lib/module/utils/index.js.map +1 -1
- package/lib/module/utils/mqParser.js.map +1 -1
- package/lib/module/utils/styles.js +26 -18
- package/lib/module/utils/styles.js.map +1 -1
- package/lib/module/utils/withPlugins.js +8 -0
- package/lib/module/utils/withPlugins.js.map +1 -0
- package/lib/typescript/src/common.d.ts +1 -1
- package/lib/typescript/src/common.d.ts.map +1 -1
- package/lib/typescript/src/core/UnistylesRuntime.d.ts +1 -1
- package/lib/typescript/src/core/UnistylesRuntime.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useVariants.d.ts.map +1 -1
- package/lib/typescript/src/plugins/index.d.ts +0 -1
- package/lib/typescript/src/plugins/index.d.ts.map +1 -1
- package/lib/typescript/src/types/breakpoints.d.ts +2 -1
- package/lib/typescript/src/types/breakpoints.d.ts.map +1 -1
- package/lib/typescript/src/types/core.d.ts +2 -3
- package/lib/typescript/src/types/core.d.ts.map +1 -1
- package/lib/typescript/src/types/index.d.ts +2 -2
- package/lib/typescript/src/types/index.d.ts.map +1 -1
- package/lib/typescript/src/types/stylesheet.d.ts +5 -5
- package/lib/typescript/src/types/stylesheet.d.ts.map +1 -1
- package/lib/typescript/src/useStyles.d.ts.map +1 -1
- package/lib/typescript/src/utils/breakpoints.d.ts +2 -2
- package/lib/typescript/src/utils/breakpoints.d.ts.map +1 -1
- package/lib/typescript/src/utils/index.d.ts +1 -0
- package/lib/typescript/src/utils/index.d.ts.map +1 -1
- package/lib/typescript/src/utils/mqParser.d.ts +2 -2
- package/lib/typescript/src/utils/mqParser.d.ts.map +1 -1
- package/lib/typescript/src/utils/styles.d.ts +3 -4
- package/lib/typescript/src/utils/styles.d.ts.map +1 -1
- package/lib/typescript/src/utils/withPlugins.d.ts +3 -0
- package/lib/typescript/src/utils/withPlugins.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/common.ts +1 -1
- package/src/core/UnistylesRuntime.ts +5 -1
- package/src/hooks/useVariants.ts +1 -14
- package/src/plugins/index.ts +0 -1
- package/src/types/breakpoints.ts +4 -1
- package/src/types/core.ts +2 -3
- package/src/types/index.ts +1 -2
- package/src/types/stylesheet.ts +5 -5
- package/src/useStyles.ts +5 -17
- package/src/utils/breakpoints.ts +3 -3
- package/src/utils/index.ts +1 -0
- package/src/utils/mqParser.ts +2 -2
- package/src/utils/styles.ts +40 -49
- package/src/utils/withPlugins.ts +13 -0
- package/lib/commonjs/plugins/withPlugins.js +0 -14
- package/lib/commonjs/plugins/withPlugins.js.map +0 -1
- package/lib/commonjs/utils/variants.js +0 -52
- package/lib/commonjs/utils/variants.js.map +0 -1
- package/lib/module/plugins/withPlugins.js +0 -7
- package/lib/module/plugins/withPlugins.js.map +0 -1
- package/lib/module/utils/variants.js +0 -45
- package/lib/module/utils/variants.js.map +0 -1
- package/lib/typescript/src/plugins/withPlugins.d.ts +0 -4
- package/lib/typescript/src/plugins/withPlugins.d.ts.map +0 -1
- package/lib/typescript/src/utils/variants.d.ts +0 -3
- package/lib/typescript/src/utils/variants.d.ts.map +0 -1
- package/src/plugins/withPlugins.ts +0 -15
- package/src/utils/variants.ts +0 -61
@@ -1,52 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
4
|
-
value: true
|
5
|
-
});
|
6
|
-
exports.getStyleWithVariants = void 0;
|
7
|
-
const getKeysForVariants = (value, variants) => {
|
8
|
-
// case for no specified variants by user, we should fallback to 'default'
|
9
|
-
if (!variants.length) {
|
10
|
-
return Object.entries(value).map(_ref => {
|
11
|
-
let [key, value] = _ref;
|
12
|
-
if ('default' in value) {
|
13
|
-
return [key, 'default'];
|
14
|
-
}
|
15
|
-
return undefined;
|
16
|
-
}).filter(Boolean);
|
17
|
-
}
|
18
|
-
return variants.map(_ref2 => {
|
19
|
-
let [variantKey, variantValue] = _ref2;
|
20
|
-
const variantStyle = value[variantKey];
|
21
|
-
if (variantStyle && variantValue && variantValue in variantStyle) {
|
22
|
-
return [variantKey, variantValue];
|
23
|
-
}
|
24
|
-
if (variantStyle && 'default' in variantStyle) {
|
25
|
-
return [variantKey, 'default'];
|
26
|
-
}
|
27
|
-
return undefined;
|
28
|
-
}).filter(Boolean);
|
29
|
-
};
|
30
|
-
const getStyleWithVariants = (style, variantValues) => {
|
31
|
-
if (!('variants' in style)) {
|
32
|
-
return style;
|
33
|
-
}
|
34
|
-
const keys = getKeysForVariants(style.variants, Object.entries(variantValues || {}));
|
35
|
-
const variantsValues = keys.map(_ref3 => {
|
36
|
-
let [key, nestedKey] = _ref3;
|
37
|
-
return style.variants[key][nestedKey];
|
38
|
-
}).reduce((acc, styles) => ({
|
39
|
-
...acc,
|
40
|
-
...styles
|
41
|
-
}), {});
|
42
|
-
const {
|
43
|
-
variants,
|
44
|
-
...otherStyles
|
45
|
-
} = style;
|
46
|
-
return {
|
47
|
-
...otherStyles,
|
48
|
-
...variantsValues
|
49
|
-
};
|
50
|
-
};
|
51
|
-
exports.getStyleWithVariants = getStyleWithVariants;
|
52
|
-
//# sourceMappingURL=variants.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"names":["getKeysForVariants","value","variants","length","Object","entries","map","_ref","key","undefined","filter","Boolean","_ref2","variantKey","variantValue","variantStyle","getStyleWithVariants","style","variantValues","keys","variantsValues","_ref3","nestedKey","reduce","acc","styles","otherStyles","exports"],"sourceRoot":"../../../src","sources":["utils/variants.ts"],"mappings":";;;;;;AAEA,MAAMA,kBAAkB,GAAGA,CACvBC,KAAkC,EAClCC,QAA2C,KACjB;EAC1B;EACA,IAAI,CAACA,QAAQ,CAACC,MAAM,EAAE;IAClB,OAAOC,MAAM,CACRC,OAAO,CAACJ,KAAK,CAAC,CACdK,GAAG,CAACC,IAAA,IAAkB;MAAA,IAAjB,CAACC,GAAG,EAAEP,KAAK,CAAC,GAAAM,IAAA;MACd,IAAI,SAAS,IAAIN,KAAK,EAAE;QACpB,OAAO,CAACO,GAAG,EAAE,SAAS,CAAC;MAC3B;MAEA,OAAOC,SAAS;IACpB,CAAC,CAAC,CACDC,MAAM,CAACC,OAAO,CAAC;EACxB;EAEA,OAAOT,QAAQ,CACVI,GAAG,CAACM,KAAA,IAAgC;IAAA,IAA/B,CAACC,UAAU,EAAEC,YAAY,CAAC,GAAAF,KAAA;IAC5B,MAAMG,YAAY,GAAGd,KAAK,CAACY,UAAU,CAAC;IAEtC,IAAIE,YAAY,IAAID,YAAY,IAAIA,YAAY,IAAIC,YAAY,EAAE;MAC9D,OAAO,CAACF,UAAU,EAAEC,YAAY,CAAC;IACrC;IAEA,IAAIC,YAAY,IAAI,SAAS,IAAIA,YAAY,EAAE;MAC3C,OAAO,CAACF,UAAU,EAAE,SAAS,CAAC;IAClC;IAEA,OAAOJ,SAAS;EACpB,CAAC,CAAC,CACDC,MAAM,CAACC,OAAO,CAAC;AACxB,CAAC;AAEM,MAAMK,oBAAoB,GAAGA,CAChCC,KAAiB,EACjBC,aAAgD,KAC/C;EACD,IAAI,EAAE,UAAU,IAAID,KAAK,CAAC,EAAE;IACxB,OAAOA,KAAK;EAChB;EAEA,MAAME,IAAI,GAAGnB,kBAAkB,CAC3BiB,KAAK,CAACf,QAAQ,EACdE,MAAM,CAACC,OAAO,CAACa,aAAa,IAAI,CAAC,CAAC,CACtC,CAAC;EAED,MAAME,cAAc,GAAGD,IAAI,CACtBb,GAAG,CAACe,KAAA;IAAA,IAAC,CAACb,GAAG,EAAEc,SAAS,CAAC,GAAAD,KAAA;IAAA,OAAOJ,KAAK,CAACf,QAAQ,CAAiDM,GAAG,CAAC,CAAiCc,SAAS,CAAC;EAAA,EAAC,CAC3IC,MAAM,CAAC,CAACC,GAAG,EAAEC,MAAM,MAAM;IAAE,GAAGD,GAAG;IAAE,GAAGC;EAAO,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;EAEzD,MAAM;IAAEvB,QAAQ;IAAE,GAAGwB;EAAY,CAAC,GAAGT,KAAK;EAE1C,OAAO;IACH,GAAGS,WAAW;IACd,GAAGN;EACP,CAAC;AACL,CAAC;AAAAO,OAAA,CAAAX,oBAAA,GAAAA,oBAAA"}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"names":["withPlugins","key","style","plugins","runtime","reduce","acc","plugin","onParsedStyle"],"sourceRoot":"../../../src","sources":["plugins/withPlugins.ts"],"mappings":"AAGA,OAAO,MAAMA,WAAW,GAAGA,CACvBC,GAAW,EACXC,KAAc,EACdC,OAA+B,EAC/BC,OAAyB,KACxBD,OAAO,CAACE,MAAM,CAAC,CAACC,GAAG,EAAEC,MAAM,KAAK;EACjC,IAAIA,MAAM,CAACC,aAAa,EAAE;IACtB,OAAOD,MAAM,CAACC,aAAa,CAACP,GAAG,EAAEK,GAAG,EAAEF,OAAO,CAAC;EAClD;EAEA,OAAOE,GAAG;AACd,CAAC,EAAEJ,KAAK,CAAC"}
|
@@ -1,45 +0,0 @@
|
|
1
|
-
const getKeysForVariants = (value, variants) => {
|
2
|
-
// case for no specified variants by user, we should fallback to 'default'
|
3
|
-
if (!variants.length) {
|
4
|
-
return Object.entries(value).map(_ref => {
|
5
|
-
let [key, value] = _ref;
|
6
|
-
if ('default' in value) {
|
7
|
-
return [key, 'default'];
|
8
|
-
}
|
9
|
-
return undefined;
|
10
|
-
}).filter(Boolean);
|
11
|
-
}
|
12
|
-
return variants.map(_ref2 => {
|
13
|
-
let [variantKey, variantValue] = _ref2;
|
14
|
-
const variantStyle = value[variantKey];
|
15
|
-
if (variantStyle && variantValue && variantValue in variantStyle) {
|
16
|
-
return [variantKey, variantValue];
|
17
|
-
}
|
18
|
-
if (variantStyle && 'default' in variantStyle) {
|
19
|
-
return [variantKey, 'default'];
|
20
|
-
}
|
21
|
-
return undefined;
|
22
|
-
}).filter(Boolean);
|
23
|
-
};
|
24
|
-
export const getStyleWithVariants = (style, variantValues) => {
|
25
|
-
if (!('variants' in style)) {
|
26
|
-
return style;
|
27
|
-
}
|
28
|
-
const keys = getKeysForVariants(style.variants, Object.entries(variantValues || {}));
|
29
|
-
const variantsValues = keys.map(_ref3 => {
|
30
|
-
let [key, nestedKey] = _ref3;
|
31
|
-
return style.variants[key][nestedKey];
|
32
|
-
}).reduce((acc, styles) => ({
|
33
|
-
...acc,
|
34
|
-
...styles
|
35
|
-
}), {});
|
36
|
-
const {
|
37
|
-
variants,
|
38
|
-
...otherStyles
|
39
|
-
} = style;
|
40
|
-
return {
|
41
|
-
...otherStyles,
|
42
|
-
...variantsValues
|
43
|
-
};
|
44
|
-
};
|
45
|
-
//# sourceMappingURL=variants.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"names":["getKeysForVariants","value","variants","length","Object","entries","map","_ref","key","undefined","filter","Boolean","_ref2","variantKey","variantValue","variantStyle","getStyleWithVariants","style","variantValues","keys","variantsValues","_ref3","nestedKey","reduce","acc","styles","otherStyles"],"sourceRoot":"../../../src","sources":["utils/variants.ts"],"mappings":"AAEA,MAAMA,kBAAkB,GAAGA,CACvBC,KAAkC,EAClCC,QAA2C,KACjB;EAC1B;EACA,IAAI,CAACA,QAAQ,CAACC,MAAM,EAAE;IAClB,OAAOC,MAAM,CACRC,OAAO,CAACJ,KAAK,CAAC,CACdK,GAAG,CAACC,IAAA,IAAkB;MAAA,IAAjB,CAACC,GAAG,EAAEP,KAAK,CAAC,GAAAM,IAAA;MACd,IAAI,SAAS,IAAIN,KAAK,EAAE;QACpB,OAAO,CAACO,GAAG,EAAE,SAAS,CAAC;MAC3B;MAEA,OAAOC,SAAS;IACpB,CAAC,CAAC,CACDC,MAAM,CAACC,OAAO,CAAC;EACxB;EAEA,OAAOT,QAAQ,CACVI,GAAG,CAACM,KAAA,IAAgC;IAAA,IAA/B,CAACC,UAAU,EAAEC,YAAY,CAAC,GAAAF,KAAA;IAC5B,MAAMG,YAAY,GAAGd,KAAK,CAACY,UAAU,CAAC;IAEtC,IAAIE,YAAY,IAAID,YAAY,IAAIA,YAAY,IAAIC,YAAY,EAAE;MAC9D,OAAO,CAACF,UAAU,EAAEC,YAAY,CAAC;IACrC;IAEA,IAAIC,YAAY,IAAI,SAAS,IAAIA,YAAY,EAAE;MAC3C,OAAO,CAACF,UAAU,EAAE,SAAS,CAAC;IAClC;IAEA,OAAOJ,SAAS;EACpB,CAAC,CAAC,CACDC,MAAM,CAACC,OAAO,CAAC;AACxB,CAAC;AAED,OAAO,MAAMK,oBAAoB,GAAGA,CAChCC,KAAiB,EACjBC,aAAgD,KAC/C;EACD,IAAI,EAAE,UAAU,IAAID,KAAK,CAAC,EAAE;IACxB,OAAOA,KAAK;EAChB;EAEA,MAAME,IAAI,GAAGnB,kBAAkB,CAC3BiB,KAAK,CAACf,QAAQ,EACdE,MAAM,CAACC,OAAO,CAACa,aAAa,IAAI,CAAC,CAAC,CACtC,CAAC;EAED,MAAME,cAAc,GAAGD,IAAI,CACtBb,GAAG,CAACe,KAAA;IAAA,IAAC,CAACb,GAAG,EAAEc,SAAS,CAAC,GAAAD,KAAA;IAAA,OAAOJ,KAAK,CAACf,QAAQ,CAAiDM,GAAG,CAAC,CAAiCc,SAAS,CAAC;EAAA,EAAC,CAC3IC,MAAM,CAAC,CAACC,GAAG,EAAEC,MAAM,MAAM;IAAE,GAAGD,GAAG;IAAE,GAAGC;EAAO,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;EAEzD,MAAM;IAAEvB,QAAQ;IAAE,GAAGwB;EAAY,CAAC,GAAGT,KAAK;EAE1C,OAAO;IACH,GAAGS,WAAW;IACd,GAAGN;EACP,CAAC;AACL,CAAC"}
|
@@ -1,4 +0,0 @@
|
|
1
|
-
import type { RNStyle, UnistylesPlugin } from '../types';
|
2
|
-
import type { UnistylesRuntime } from '../core';
|
3
|
-
export declare const withPlugins: (key: string, style: RNStyle, plugins: Array<UnistylesPlugin>, runtime: UnistylesRuntime) => RNStyle;
|
4
|
-
//# sourceMappingURL=withPlugins.d.ts.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"withPlugins.d.ts","sourceRoot":"","sources":["../../../../src/plugins/withPlugins.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AACxD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAE/C,eAAO,MAAM,WAAW,QACf,MAAM,SACJ,OAAO,WACL,MAAM,eAAe,CAAC,WACtB,gBAAgB,YAOpB,CAAA"}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"variants.d.ts","sourceRoot":"","sources":["../../../../src/utils/variants.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAe,MAAM,UAAU,CAAA;AAqCjE,eAAO,MAAM,oBAAoB,UACtB,UAAU,kBACD,OAAO,MAAM,EAAE,SAAS,MAAM,CAAC,CAAC,eAqBnD,CAAA"}
|
@@ -1,15 +0,0 @@
|
|
1
|
-
import type { RNStyle, UnistylesPlugin } from '../types'
|
2
|
-
import type { UnistylesRuntime } from '../core'
|
3
|
-
|
4
|
-
export const withPlugins = (
|
5
|
-
key: string,
|
6
|
-
style: RNStyle,
|
7
|
-
plugins: Array<UnistylesPlugin>,
|
8
|
-
runtime: UnistylesRuntime
|
9
|
-
) => plugins.reduce((acc, plugin) => {
|
10
|
-
if (plugin.onParsedStyle) {
|
11
|
-
return plugin.onParsedStyle(key, acc, runtime)
|
12
|
-
}
|
13
|
-
|
14
|
-
return acc
|
15
|
-
}, style)
|
package/src/utils/variants.ts
DELETED
@@ -1,61 +0,0 @@
|
|
1
|
-
import type { Optional, StyleSheet, NestedStyle } from '../types'
|
2
|
-
|
3
|
-
const getKeysForVariants = (
|
4
|
-
value: Record<string, NestedStyle>,
|
5
|
-
variants: Array<[string, Optional<string>]>
|
6
|
-
): Array<[string, string]> => {
|
7
|
-
// case for no specified variants by user, we should fallback to 'default'
|
8
|
-
if (!variants.length) {
|
9
|
-
return Object
|
10
|
-
.entries(value)
|
11
|
-
.map(([key, value]) => {
|
12
|
-
if ('default' in value) {
|
13
|
-
return [key, 'default']
|
14
|
-
}
|
15
|
-
|
16
|
-
return undefined
|
17
|
-
})
|
18
|
-
.filter(Boolean) as Array<[string, string]>
|
19
|
-
}
|
20
|
-
|
21
|
-
return variants
|
22
|
-
.map(([variantKey, variantValue]) => {
|
23
|
-
const variantStyle = value[variantKey]
|
24
|
-
|
25
|
-
if (variantStyle && variantValue && variantValue in variantStyle) {
|
26
|
-
return [variantKey, variantValue]
|
27
|
-
}
|
28
|
-
|
29
|
-
if (variantStyle && 'default' in variantStyle) {
|
30
|
-
return [variantKey, 'default']
|
31
|
-
}
|
32
|
-
|
33
|
-
return undefined
|
34
|
-
})
|
35
|
-
.filter(Boolean) as Array<[string, string]>
|
36
|
-
}
|
37
|
-
|
38
|
-
export const getStyleWithVariants = (
|
39
|
-
style: StyleSheet,
|
40
|
-
variantValues?: Record<string, Optional<string>>
|
41
|
-
) => {
|
42
|
-
if (!('variants' in style)) {
|
43
|
-
return style
|
44
|
-
}
|
45
|
-
|
46
|
-
const keys = getKeysForVariants(
|
47
|
-
style.variants as Record<string, NestedStyle>,
|
48
|
-
Object.entries(variantValues || {})
|
49
|
-
)
|
50
|
-
|
51
|
-
const variantsValues = keys
|
52
|
-
.map(([key, nestedKey]) => ((style.variants as Record<string, Record<string, NestedStyle>>)[key] as Record<string, NestedStyle>)[nestedKey])
|
53
|
-
.reduce((acc, styles) => ({ ...acc, ...styles }), {})
|
54
|
-
|
55
|
-
const { variants, ...otherStyles } = style
|
56
|
-
|
57
|
-
return {
|
58
|
-
...otherStyles,
|
59
|
-
...variantsValues
|
60
|
-
}
|
61
|
-
}
|