react-native-unistyles 2.0.0-alpha.16 → 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 +11 -10
- package/lib/commonjs/common.js.map +1 -1
- package/lib/commonjs/core/UnistyleRegistry.js +17 -4
- package/lib/commonjs/core/UnistyleRegistry.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 +4 -12
- 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 +11 -10
- package/lib/module/common.js.map +1 -1
- package/lib/module/core/UnistyleRegistry.js +17 -4
- package/lib/module/core/UnistyleRegistry.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 +5 -13
- 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 +11 -10
- package/lib/typescript/src/common.d.ts.map +1 -1
- package/lib/typescript/src/core/UnistyleRegistry.d.ts +39 -3
- package/lib/typescript/src/core/UnistyleRegistry.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/index.d.ts +48 -3
- package/lib/typescript/src/index.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 +11 -10
- package/src/core/UnistyleRegistry.ts +19 -4
- 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 +8 -30
- 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,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
|
-
}
|