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.
Files changed (101) hide show
  1. package/cxx/UnistylesRuntime.h +3 -3
  2. package/lib/commonjs/common.js +11 -10
  3. package/lib/commonjs/common.js.map +1 -1
  4. package/lib/commonjs/core/UnistyleRegistry.js +17 -4
  5. package/lib/commonjs/core/UnistyleRegistry.js.map +1 -1
  6. package/lib/commonjs/core/UnistylesRuntime.js +4 -1
  7. package/lib/commonjs/core/UnistylesRuntime.js.map +1 -1
  8. package/lib/commonjs/hooks/useVariants.js +1 -11
  9. package/lib/commonjs/hooks/useVariants.js.map +1 -1
  10. package/lib/commonjs/plugins/index.js +0 -7
  11. package/lib/commonjs/plugins/index.js.map +1 -1
  12. package/lib/commonjs/useStyles.js +4 -12
  13. package/lib/commonjs/useStyles.js.map +1 -1
  14. package/lib/commonjs/utils/breakpoints.js.map +1 -1
  15. package/lib/commonjs/utils/index.js +7 -0
  16. package/lib/commonjs/utils/index.js.map +1 -1
  17. package/lib/commonjs/utils/mqParser.js.map +1 -1
  18. package/lib/commonjs/utils/styles.js +26 -18
  19. package/lib/commonjs/utils/styles.js.map +1 -1
  20. package/lib/commonjs/utils/withPlugins.js +15 -0
  21. package/lib/commonjs/utils/withPlugins.js.map +1 -0
  22. package/lib/module/common.js +11 -10
  23. package/lib/module/common.js.map +1 -1
  24. package/lib/module/core/UnistyleRegistry.js +17 -4
  25. package/lib/module/core/UnistyleRegistry.js.map +1 -1
  26. package/lib/module/core/UnistylesRuntime.js +4 -1
  27. package/lib/module/core/UnistylesRuntime.js.map +1 -1
  28. package/lib/module/hooks/useVariants.js +1 -11
  29. package/lib/module/hooks/useVariants.js.map +1 -1
  30. package/lib/module/plugins/index.js +0 -1
  31. package/lib/module/plugins/index.js.map +1 -1
  32. package/lib/module/useStyles.js +5 -13
  33. package/lib/module/useStyles.js.map +1 -1
  34. package/lib/module/utils/breakpoints.js.map +1 -1
  35. package/lib/module/utils/index.js +1 -0
  36. package/lib/module/utils/index.js.map +1 -1
  37. package/lib/module/utils/mqParser.js.map +1 -1
  38. package/lib/module/utils/styles.js +26 -18
  39. package/lib/module/utils/styles.js.map +1 -1
  40. package/lib/module/utils/withPlugins.js +8 -0
  41. package/lib/module/utils/withPlugins.js.map +1 -0
  42. package/lib/typescript/src/common.d.ts +11 -10
  43. package/lib/typescript/src/common.d.ts.map +1 -1
  44. package/lib/typescript/src/core/UnistyleRegistry.d.ts +39 -3
  45. package/lib/typescript/src/core/UnistyleRegistry.d.ts.map +1 -1
  46. package/lib/typescript/src/core/UnistylesRuntime.d.ts +1 -1
  47. package/lib/typescript/src/core/UnistylesRuntime.d.ts.map +1 -1
  48. package/lib/typescript/src/hooks/useVariants.d.ts.map +1 -1
  49. package/lib/typescript/src/index.d.ts +48 -3
  50. package/lib/typescript/src/index.d.ts.map +1 -1
  51. package/lib/typescript/src/plugins/index.d.ts +0 -1
  52. package/lib/typescript/src/plugins/index.d.ts.map +1 -1
  53. package/lib/typescript/src/types/breakpoints.d.ts +2 -1
  54. package/lib/typescript/src/types/breakpoints.d.ts.map +1 -1
  55. package/lib/typescript/src/types/core.d.ts +2 -3
  56. package/lib/typescript/src/types/core.d.ts.map +1 -1
  57. package/lib/typescript/src/types/index.d.ts +2 -2
  58. package/lib/typescript/src/types/index.d.ts.map +1 -1
  59. package/lib/typescript/src/types/stylesheet.d.ts +5 -5
  60. package/lib/typescript/src/types/stylesheet.d.ts.map +1 -1
  61. package/lib/typescript/src/useStyles.d.ts.map +1 -1
  62. package/lib/typescript/src/utils/breakpoints.d.ts +2 -2
  63. package/lib/typescript/src/utils/breakpoints.d.ts.map +1 -1
  64. package/lib/typescript/src/utils/index.d.ts +1 -0
  65. package/lib/typescript/src/utils/index.d.ts.map +1 -1
  66. package/lib/typescript/src/utils/mqParser.d.ts +2 -2
  67. package/lib/typescript/src/utils/mqParser.d.ts.map +1 -1
  68. package/lib/typescript/src/utils/styles.d.ts +3 -4
  69. package/lib/typescript/src/utils/styles.d.ts.map +1 -1
  70. package/lib/typescript/src/utils/withPlugins.d.ts +3 -0
  71. package/lib/typescript/src/utils/withPlugins.d.ts.map +1 -0
  72. package/package.json +1 -1
  73. package/src/common.ts +11 -10
  74. package/src/core/UnistyleRegistry.ts +19 -4
  75. package/src/core/UnistylesRuntime.ts +5 -1
  76. package/src/hooks/useVariants.ts +1 -14
  77. package/src/plugins/index.ts +0 -1
  78. package/src/types/breakpoints.ts +4 -1
  79. package/src/types/core.ts +2 -3
  80. package/src/types/index.ts +1 -2
  81. package/src/types/stylesheet.ts +5 -5
  82. package/src/useStyles.ts +8 -30
  83. package/src/utils/breakpoints.ts +3 -3
  84. package/src/utils/index.ts +1 -0
  85. package/src/utils/mqParser.ts +2 -2
  86. package/src/utils/styles.ts +40 -49
  87. package/src/utils/withPlugins.ts +13 -0
  88. package/lib/commonjs/plugins/withPlugins.js +0 -14
  89. package/lib/commonjs/plugins/withPlugins.js.map +0 -1
  90. package/lib/commonjs/utils/variants.js +0 -52
  91. package/lib/commonjs/utils/variants.js.map +0 -1
  92. package/lib/module/plugins/withPlugins.js +0 -7
  93. package/lib/module/plugins/withPlugins.js.map +0 -1
  94. package/lib/module/utils/variants.js +0 -45
  95. package/lib/module/utils/variants.js.map +0 -1
  96. package/lib/typescript/src/plugins/withPlugins.d.ts +0 -4
  97. package/lib/typescript/src/plugins/withPlugins.d.ts.map +0 -1
  98. package/lib/typescript/src/utils/variants.d.ts +0 -3
  99. package/lib/typescript/src/utils/variants.d.ts.map +0 -1
  100. package/src/plugins/withPlugins.ts +0 -15
  101. 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)
@@ -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
- }