react-native-unistyles 2.0.0-alpha.9 → 2.0.0-beta.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (228) hide show
  1. package/android/CMakeLists.txt +28 -0
  2. package/android/build.gradle +40 -0
  3. package/android/src/main/cxx/cpp-adapter.cpp +108 -0
  4. package/android/src/main/java/com/unistyles/UnistylesModule.kt +159 -0
  5. package/android/src/main/java/com/unistyles/UnistylesPackage.kt +18 -0
  6. package/cxx/UnistylesRuntime.cpp +55 -2
  7. package/cxx/UnistylesRuntime.h +15 -9
  8. package/ios/UnistylesModule.mm +16 -6
  9. package/lib/commonjs/common.js +30 -16
  10. package/lib/commonjs/common.js.map +1 -1
  11. package/lib/commonjs/core/UnistyleRegistry.js +65 -3
  12. package/lib/commonjs/core/UnistyleRegistry.js.map +1 -1
  13. package/lib/commonjs/core/Unistyles.js +1 -1
  14. package/lib/commonjs/core/Unistyles.js.map +1 -1
  15. package/lib/commonjs/core/UnistylesModule.web.js +187 -0
  16. package/lib/commonjs/core/UnistylesModule.web.js.map +1 -0
  17. package/lib/commonjs/core/UnistylesRuntime.js +15 -16
  18. package/lib/commonjs/core/UnistylesRuntime.js.map +1 -1
  19. package/lib/commonjs/createStyleSheet.js +1 -6
  20. package/lib/commonjs/createStyleSheet.js.map +1 -1
  21. package/lib/commonjs/hooks/index.js +7 -0
  22. package/lib/commonjs/hooks/index.js.map +1 -1
  23. package/lib/commonjs/hooks/useUnistyles.js +12 -9
  24. package/lib/commonjs/hooks/useUnistyles.js.map +1 -1
  25. package/lib/commonjs/hooks/useVariants.js +14 -0
  26. package/lib/commonjs/hooks/useVariants.js.map +1 -0
  27. package/lib/commonjs/index.js.map +1 -1
  28. package/lib/commonjs/plugins/index.js +38 -0
  29. package/lib/commonjs/plugins/index.js.map +1 -0
  30. package/lib/commonjs/plugins/normalizeWebStylesPlugin.js +12 -0
  31. package/lib/commonjs/plugins/normalizeWebStylesPlugin.js.map +1 -0
  32. package/lib/commonjs/plugins/normalizer/index.js +32 -0
  33. package/lib/commonjs/plugins/normalizer/index.js.map +1 -0
  34. package/lib/commonjs/plugins/normalizer/module.d.js.map +1 -0
  35. package/lib/commonjs/{utils/normalizeStyles.web.js → plugins/normalizer/normalizeStyle.js} +5 -5
  36. package/lib/commonjs/plugins/normalizer/normalizeStyle.js.map +1 -0
  37. package/lib/commonjs/{utils → plugins/normalizer}/normalizer.js +1 -1
  38. package/lib/commonjs/plugins/normalizer/normalizer.js.map +1 -0
  39. package/lib/commonjs/types/{mq.js → plugin.js} +1 -1
  40. package/lib/commonjs/types/{mq.js.map → plugin.js.map} +1 -1
  41. package/lib/commonjs/types/stylesheet.js +6 -0
  42. package/lib/commonjs/types/stylesheet.js.map +1 -0
  43. package/lib/commonjs/types/variants.js +2 -0
  44. package/lib/commonjs/{utils/module.d.js.map → types/variants.js.map} +1 -1
  45. package/lib/commonjs/useStyles.js +10 -20
  46. package/lib/commonjs/useStyles.js.map +1 -1
  47. package/lib/commonjs/utils/breakpoints.js +13 -59
  48. package/lib/commonjs/utils/breakpoints.js.map +1 -1
  49. package/lib/commonjs/utils/index.js +13 -51
  50. package/lib/commonjs/utils/index.js.map +1 -1
  51. package/lib/commonjs/utils/mq.js +36 -68
  52. package/lib/commonjs/utils/mq.js.map +1 -1
  53. package/lib/commonjs/utils/mqParser.js +4 -1
  54. package/lib/commonjs/utils/mqParser.js.map +1 -1
  55. package/lib/commonjs/utils/styles.js +35 -20
  56. package/lib/commonjs/utils/styles.js.map +1 -1
  57. package/lib/commonjs/utils/withPlugins.js +15 -0
  58. package/lib/commonjs/utils/withPlugins.js.map +1 -0
  59. package/lib/module/common.js +28 -17
  60. package/lib/module/common.js.map +1 -1
  61. package/lib/module/core/UnistyleRegistry.js +65 -3
  62. package/lib/module/core/UnistyleRegistry.js.map +1 -1
  63. package/lib/module/core/Unistyles.js +2 -2
  64. package/lib/module/core/Unistyles.js.map +1 -1
  65. package/lib/module/core/UnistylesModule.web.js +180 -0
  66. package/lib/module/core/UnistylesModule.web.js.map +1 -0
  67. package/lib/module/core/UnistylesRuntime.js +15 -16
  68. package/lib/module/core/UnistylesRuntime.js.map +1 -1
  69. package/lib/module/createStyleSheet.js +1 -6
  70. package/lib/module/createStyleSheet.js.map +1 -1
  71. package/lib/module/hooks/index.js +1 -0
  72. package/lib/module/hooks/index.js.map +1 -1
  73. package/lib/module/hooks/useUnistyles.js +13 -10
  74. package/lib/module/hooks/useUnistyles.js.map +1 -1
  75. package/lib/module/hooks/useVariants.js +7 -0
  76. package/lib/module/hooks/useVariants.js.map +1 -0
  77. package/lib/module/index.js.map +1 -1
  78. package/lib/module/plugins/index.js +3 -0
  79. package/lib/module/plugins/index.js.map +1 -0
  80. package/lib/module/plugins/normalizeWebStylesPlugin.js +6 -0
  81. package/lib/module/plugins/normalizeWebStylesPlugin.js.map +1 -0
  82. package/lib/module/plugins/normalizer/index.js +3 -0
  83. package/lib/module/plugins/normalizer/index.js.map +1 -0
  84. package/lib/module/plugins/normalizer/module.d.js.map +1 -0
  85. package/lib/module/{utils/normalizeStyles.web.js → plugins/normalizer/normalizeStyle.js} +3 -3
  86. package/lib/module/plugins/normalizer/normalizeStyle.js.map +1 -0
  87. package/lib/module/{utils → plugins/normalizer}/normalizer.js +1 -1
  88. package/lib/module/plugins/normalizer/normalizer.js.map +1 -0
  89. package/lib/module/types/plugin.js +2 -0
  90. package/lib/module/types/{mq.js.map → plugin.js.map} +1 -1
  91. package/lib/module/types/stylesheet.js +2 -0
  92. package/lib/module/types/stylesheet.js.map +1 -0
  93. package/lib/module/types/variants.js +2 -0
  94. package/lib/module/{utils/module.d.js.map → types/variants.js.map} +1 -1
  95. package/lib/module/useStyles.js +12 -22
  96. package/lib/module/useStyles.js.map +1 -1
  97. package/lib/module/utils/breakpoints.js +12 -56
  98. package/lib/module/utils/breakpoints.js.map +1 -1
  99. package/lib/module/utils/index.js +4 -6
  100. package/lib/module/utils/index.js.map +1 -1
  101. package/lib/module/utils/mq.js +35 -67
  102. package/lib/module/utils/mq.js.map +1 -1
  103. package/lib/module/utils/mqParser.js +3 -3
  104. package/lib/module/utils/mqParser.js.map +1 -1
  105. package/lib/module/utils/styles.js +35 -20
  106. package/lib/module/utils/styles.js.map +1 -1
  107. package/lib/module/utils/withPlugins.js +8 -0
  108. package/lib/module/utils/withPlugins.js.map +1 -0
  109. package/lib/typescript/src/common.d.ts +23 -12
  110. package/lib/typescript/src/common.d.ts.map +1 -1
  111. package/lib/typescript/src/core/UnistyleRegistry.d.ts +45 -4
  112. package/lib/typescript/src/core/UnistyleRegistry.d.ts.map +1 -1
  113. package/lib/typescript/src/core/UnistylesModule.web.d.ts +19 -0
  114. package/lib/typescript/src/core/UnistylesModule.web.d.ts.map +1 -0
  115. package/lib/typescript/src/core/UnistylesRuntime.d.ts +8 -9
  116. package/lib/typescript/src/core/UnistylesRuntime.d.ts.map +1 -1
  117. package/lib/typescript/src/core/index.d.ts +1 -0
  118. package/lib/typescript/src/core/index.d.ts.map +1 -1
  119. package/lib/typescript/src/createStyleSheet.d.ts +2 -2
  120. package/lib/typescript/src/createStyleSheet.d.ts.map +1 -1
  121. package/lib/typescript/src/global.d.ts.map +1 -1
  122. package/lib/typescript/src/hooks/index.d.ts +1 -0
  123. package/lib/typescript/src/hooks/index.d.ts.map +1 -1
  124. package/lib/typescript/src/hooks/useUnistyles.d.ts +2 -1
  125. package/lib/typescript/src/hooks/useUnistyles.d.ts.map +1 -1
  126. package/lib/typescript/src/hooks/useVariants.d.ts +3 -0
  127. package/lib/typescript/src/hooks/useVariants.d.ts.map +1 -0
  128. package/lib/typescript/src/index.d.ts +51 -5
  129. package/lib/typescript/src/index.d.ts.map +1 -1
  130. package/lib/typescript/src/plugins/index.d.ts +3 -0
  131. package/lib/typescript/src/plugins/index.d.ts.map +1 -0
  132. package/lib/typescript/src/plugins/normalizeWebStylesPlugin.d.ts +3 -0
  133. package/lib/typescript/src/plugins/normalizeWebStylesPlugin.d.ts.map +1 -0
  134. package/lib/typescript/src/plugins/normalizer/index.d.ts +3 -0
  135. package/lib/typescript/src/plugins/normalizer/index.d.ts.map +1 -0
  136. package/lib/typescript/src/plugins/normalizer/normalizeStyle.d.ts +3 -0
  137. package/lib/typescript/src/plugins/normalizer/normalizeStyle.d.ts.map +1 -0
  138. package/lib/typescript/src/{utils → plugins/normalizer}/normalizer.d.ts +1 -1
  139. package/lib/typescript/src/plugins/normalizer/normalizer.d.ts.map +1 -0
  140. package/lib/typescript/src/types/breakpoints.d.ts +25 -12
  141. package/lib/typescript/src/types/breakpoints.d.ts.map +1 -1
  142. package/lib/typescript/src/types/core.d.ts +6 -27
  143. package/lib/typescript/src/types/core.d.ts.map +1 -1
  144. package/lib/typescript/src/types/index.d.ts +4 -2
  145. package/lib/typescript/src/types/index.d.ts.map +1 -1
  146. package/lib/typescript/src/types/plugin.d.ts +7 -0
  147. package/lib/typescript/src/types/plugin.d.ts.map +1 -0
  148. package/lib/typescript/src/types/stylesheet.d.ts +40 -0
  149. package/lib/typescript/src/types/stylesheet.d.ts.map +1 -0
  150. package/lib/typescript/src/types/unistyles.d.ts +16 -11
  151. package/lib/typescript/src/types/unistyles.d.ts.map +1 -1
  152. package/lib/typescript/src/types/variants.d.ts +14 -0
  153. package/lib/typescript/src/types/variants.d.ts.map +1 -0
  154. package/lib/typescript/src/useStyles.d.ts +3 -3
  155. package/lib/typescript/src/useStyles.d.ts.map +1 -1
  156. package/lib/typescript/src/utils/breakpoints.d.ts +2 -5
  157. package/lib/typescript/src/utils/breakpoints.d.ts.map +1 -1
  158. package/lib/typescript/src/utils/index.d.ts +4 -6
  159. package/lib/typescript/src/utils/index.d.ts.map +1 -1
  160. package/lib/typescript/src/utils/mq.d.ts +15 -14
  161. package/lib/typescript/src/utils/mq.d.ts.map +1 -1
  162. package/lib/typescript/src/utils/mqParser.d.ts +14 -2
  163. package/lib/typescript/src/utils/mqParser.d.ts.map +1 -1
  164. package/lib/typescript/src/utils/styles.d.ts +3 -4
  165. package/lib/typescript/src/utils/styles.d.ts.map +1 -1
  166. package/lib/typescript/src/utils/withPlugins.d.ts +3 -0
  167. package/lib/typescript/src/utils/withPlugins.d.ts.map +1 -0
  168. package/package.json +19 -16
  169. package/src/__tests__/mocks.ts +24 -0
  170. package/src/common.ts +30 -14
  171. package/src/core/UnistyleRegistry.ts +66 -4
  172. package/src/core/Unistyles.ts +2 -2
  173. package/src/core/UnistylesModule.web.ts +214 -0
  174. package/src/core/UnistylesRuntime.ts +18 -20
  175. package/src/core/index.ts +1 -0
  176. package/src/createStyleSheet.ts +2 -8
  177. package/src/global.ts +1 -0
  178. package/src/hooks/index.ts +1 -0
  179. package/src/hooks/useUnistyles.ts +12 -10
  180. package/src/hooks/useVariants.ts +10 -0
  181. package/src/index.ts +3 -1
  182. package/src/plugins/index.ts +2 -0
  183. package/src/plugins/normalizeWebStylesPlugin.ts +7 -0
  184. package/src/plugins/normalizer/index.ts +2 -0
  185. package/src/{utils/normalizeStyles.web.ts → plugins/normalizer/normalizeStyle.ts} +3 -3
  186. package/src/{utils → plugins/normalizer}/normalizer.ts +3 -3
  187. package/src/types/breakpoints.ts +57 -25
  188. package/src/types/core.ts +9 -43
  189. package/src/types/index.ts +11 -2
  190. package/src/types/plugin.ts +7 -0
  191. package/src/types/stylesheet.ts +49 -0
  192. package/src/types/unistyles.ts +18 -13
  193. package/src/types/variants.ts +19 -0
  194. package/src/useStyles.ts +18 -25
  195. package/src/utils/breakpoints.ts +11 -67
  196. package/src/utils/index.ts +4 -6
  197. package/src/utils/mq.ts +31 -84
  198. package/src/utils/mqParser.ts +5 -5
  199. package/src/utils/styles.ts +44 -50
  200. package/src/utils/withPlugins.ts +13 -0
  201. package/lib/commonjs/utils/common.js +0 -25
  202. package/lib/commonjs/utils/common.js.map +0 -1
  203. package/lib/commonjs/utils/normalizeStyles.js +0 -10
  204. package/lib/commonjs/utils/normalizeStyles.js.map +0 -1
  205. package/lib/commonjs/utils/normalizeStyles.web.js.map +0 -1
  206. package/lib/commonjs/utils/normalizer.js.map +0 -1
  207. package/lib/module/types/mq.js +0 -2
  208. package/lib/module/utils/common.js +0 -17
  209. package/lib/module/utils/common.js.map +0 -1
  210. package/lib/module/utils/normalizeStyles.js +0 -3
  211. package/lib/module/utils/normalizeStyles.js.map +0 -1
  212. package/lib/module/utils/normalizeStyles.web.js.map +0 -1
  213. package/lib/module/utils/normalizer.js.map +0 -1
  214. package/lib/typescript/src/types/mq.d.ts +0 -3
  215. package/lib/typescript/src/types/mq.d.ts.map +0 -1
  216. package/lib/typescript/src/utils/common.d.ts +0 -12
  217. package/lib/typescript/src/utils/common.d.ts.map +0 -1
  218. package/lib/typescript/src/utils/normalizeStyles.d.ts +0 -2
  219. package/lib/typescript/src/utils/normalizeStyles.d.ts.map +0 -1
  220. package/lib/typescript/src/utils/normalizeStyles.web.d.ts +0 -5
  221. package/lib/typescript/src/utils/normalizeStyles.web.d.ts.map +0 -1
  222. package/lib/typescript/src/utils/normalizer.d.ts.map +0 -1
  223. package/src/types/mq.ts +0 -3
  224. package/src/utils/common.ts +0 -20
  225. package/src/utils/normalizeStyles.ts +0 -2
  226. /package/lib/commonjs/{utils → plugins/normalizer}/module.d.js +0 -0
  227. /package/lib/module/{utils → plugins/normalizer}/module.d.js +0 -0
  228. /package/src/{utils → plugins/normalizer}/module.d.ts +0 -0
@@ -1,7 +1,9 @@
1
1
  export * from './normalizer';
2
2
  export * from './unistyles';
3
3
  export type { Optional, Nullable } from './common';
4
- export type { MediaQuery } from './mq';
5
- export type { CustomNamedStyles, NestedKeys, UnistylesTheme, CreateStylesFactory, ScreenSize } from './core';
4
+ export type { NestedStylePairs, UnistylesTheme, ScreenSize, NestedStyle, RNValue, RNStyle } from './core';
5
+ export type { StyleSheetWithSuperPowers, StyleSheet, AllAvailableKeys } from './stylesheet';
6
6
  export type { ReactNativeStyleSheet } from './breakpoints';
7
+ export type { ExtractVariantNames } from './variants';
8
+ export type { UnistylesPlugin } from './plugin';
7
9
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAC3B,YAAY,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AAClD,YAAY,EAAE,UAAU,EAAE,MAAM,MAAM,CAAA;AACtC,YAAY,EAAE,iBAAiB,EAAE,UAAU,EAAE,cAAc,EAAE,mBAAmB,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAA;AAC5G,YAAY,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAC3B,YAAY,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AAClD,YAAY,EACR,gBAAgB,EAChB,cAAc,EACd,UAAU,EACV,WAAW,EACX,OAAO,EACP,OAAO,EACV,MAAM,QAAQ,CAAA;AACf,YAAY,EAAE,yBAAyB,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAC3F,YAAY,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAA;AAC1D,YAAY,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AACrD,YAAY,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA"}
@@ -0,0 +1,7 @@
1
+ import type { RNStyle } from './core';
2
+ import type { UnistylesRuntime } from '../core';
3
+ export type UnistylesPlugin = {
4
+ name: string;
5
+ onParsedStyle?: (styleKey: string, style: RNStyle, runtime: UnistylesRuntime) => RNStyle;
6
+ };
7
+ //# sourceMappingURL=plugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../../../src/types/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAA;AACrC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAE/C,MAAM,MAAM,eAAe,GAAG;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,aAAa,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,gBAAgB,KAAK,OAAO,CAAA;CAC3F,CAAA"}
@@ -0,0 +1,40 @@
1
+ import type { ImageStyle, TextStyle, ViewStyle } from 'react-native';
2
+ import type { ShadowOffset, TransformStyles, UnistylesTheme } from './core';
3
+ import type { UnistylesBreakpoints } from '../global';
4
+ type NestedKeys = 'shadowOffset' | 'transform' | 'textShadowOffset';
5
+ type UnistyleView = Omit<ViewStyle, NestedKeys>;
6
+ type UnistyleText = Omit<TextStyle, NestedKeys>;
7
+ type UnistyleImage = Omit<ImageStyle, NestedKeys>;
8
+ type UnistyleNestedStyles = {
9
+ shadowOffset?: ToDeepUnistyles<ShadowOffset>;
10
+ textShadowOffset?: ToDeepUnistyles<ShadowOffset>;
11
+ transform?: Array<ToDeepUnistyles<TransformStyles>>;
12
+ };
13
+ type Variants = {
14
+ variants?: {
15
+ [variantName: string]: {
16
+ [variant: string]: Omit<UnistylesValues, 'variants'>;
17
+ };
18
+ };
19
+ };
20
+ export type ToDeepUnistyles<T> = {
21
+ [K in keyof T]?: T[K] | {
22
+ [key in BreakpointsOrMediaQueries]?: T[K];
23
+ };
24
+ };
25
+ type AllAvailableStyles = UnistyleView & UnistyleText & UnistyleImage & UnistyleNestedStyles;
26
+ export type AllAvailableKeys = keyof (UnistyleView & UnistyleText & UnistyleImage);
27
+ export type BreakpointsOrMediaQueries = keyof UnistylesBreakpoints | symbol;
28
+ export type UnistylesValues = {
29
+ [propName in AllAvailableKeys]?: AllAvailableStyles[propName] | {
30
+ [key in BreakpointsOrMediaQueries]?: AllAvailableStyles[propName];
31
+ };
32
+ } & Variants & {
33
+ [propName in NestedKeys]?: UnistyleNestedStyles[propName];
34
+ };
35
+ export type StyleSheet = {
36
+ [styleName: string]: UnistylesValues | ((...args: any) => UnistylesValues);
37
+ };
38
+ export type StyleSheetWithSuperPowers = ((theme: UnistylesTheme) => StyleSheet) | StyleSheet;
39
+ export {};
40
+ //# sourceMappingURL=stylesheet.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stylesheet.d.ts","sourceRoot":"","sources":["../../../../src/types/stylesheet.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AACpE,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAA;AAC3E,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAA;AAGrD,KAAK,UAAU,GAAG,cAAc,GAAG,WAAW,GAAG,kBAAkB,CAAA;AAEnE,KAAK,YAAY,GAAG,IAAI,CAAC,SAAS,EAAE,UAAU,CAAC,CAAA;AAC/C,KAAK,YAAY,GAAG,IAAI,CAAC,SAAS,EAAE,UAAU,CAAC,CAAA;AAC/C,KAAK,aAAa,GAAG,IAAI,CAAC,UAAU,EAAE,UAAU,CAAC,CAAA;AAEjD,KAAK,oBAAoB,GAAG;IACxB,YAAY,CAAC,EAAE,eAAe,CAAC,YAAY,CAAC,CAAC;IAC7C,gBAAgB,CAAC,EAAE,eAAe,CAAC,YAAY,CAAC,CAAC;IACjD,SAAS,CAAC,EAAE,KAAK,CAAC,eAAe,CAAC,eAAe,CAAC,CAAC,CAAA;CACtD,CAAA;AAED,KAAK,QAAQ,GAAG;IACZ,QAAQ,CAAC,EAAE;QACP,CAAC,WAAW,EAAE,MAAM,GAAG;YACnB,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC,eAAe,EAAE,UAAU,CAAC,CAAA;SACvD,CAAA;KACJ,CAAA;CACJ,CAAA;AAED,MAAM,MAAM,eAAe,CAAC,CAAC,IAAI;KAC5B,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG;SACnB,GAAG,IAAI,yBAAyB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;KAC5C;CACJ,CAAA;AAED,KAAK,kBAAkB,GAAG,YAAY,GAAG,YAAY,GAAG,aAAa,GAAG,oBAAoB,CAAA;AAE5F,MAAM,MAAM,gBAAgB,GAAG,MAAM,CAAC,YAAY,GAAG,YAAY,GAAG,aAAa,CAAC,CAAA;AAClF,MAAM,MAAM,yBAAyB,GAAG,MAAM,oBAAoB,GAAG,MAAM,CAAA;AAE3E,MAAM,MAAM,eAAe,GAAG;KACzB,QAAQ,IAAI,gBAAgB,CAAC,CAAC,EAAE,kBAAkB,CAAC,QAAQ,CAAC,GAAG;SAC3D,GAAG,IAAI,yBAAyB,CAAC,CAAC,EAAE,kBAAkB,CAAC,QAAQ,CAAC;KACpE;CACJ,GAAG,QAAQ,GAAG;KACV,QAAQ,IAAI,UAAU,CAAC,CAAC,EAAE,oBAAoB,CAAC,QAAQ,CAAC;CAC5D,CAAA;AAED,MAAM,MAAM,UAAU,GAAG;IACrB,CAAC,SAAS,EAAE,MAAM,GAAG,eAAe,GAAG,CAAC,CAAC,GAAG,IAAI,EAAE,GAAG,KAAK,eAAe,CAAC,CAAA;CAC7E,CAAA;AAED,MAAM,MAAM,yBAAyB,GAAG,CAAC,CAAC,KAAK,EAAE,cAAc,KAAK,UAAU,CAAC,GAAG,UAAU,CAAA"}
@@ -1,14 +1,17 @@
1
- import { CxxUnistylesEventTypes, ScreenOrientation } from '../common';
1
+ import { UnistylesEventType, ScreenOrientation } from '../common';
2
2
  import type { UnistylesThemes, UnistylesBreakpoints } from '../global';
3
- import type { NestedKeys, ScreenSize } from './core';
4
- import type { Optional } from './common';
5
- export type ColorSchemeName = Optional<'light' | 'dark'>;
3
+ import type { ScreenSize } from './core';
4
+ import type { UnistylesPlugin } from './plugin';
5
+ export type ColorSchemeName = 'light' | 'dark' | 'unspecified';
6
6
  export type UnistylesConfig = {
7
7
  adaptiveThemes?: boolean;
8
+ experimentalPlugins?: Array<UnistylesPlugin>;
9
+ initialTheme?: keyof UnistylesThemes;
8
10
  };
9
11
  export type UnistylesBridge = {
10
12
  screenWidth: number;
11
13
  screenHeight: number;
14
+ enabledPlugins: Array<string>;
12
15
  hasAdaptiveThemes: boolean;
13
16
  themeName: keyof UnistylesThemes;
14
17
  breakpoint: keyof UnistylesBreakpoints;
@@ -18,23 +21,25 @@ export type UnistylesBridge = {
18
21
  useBreakpoints(breakpoints: UnistylesBreakpoints): void;
19
22
  useTheme(name: keyof UnistylesThemes): void;
20
23
  useAdaptiveThemes(enable: boolean): void;
24
+ addPlugin(pluginName: string, notify: boolean): void;
25
+ removePlugin(pluginName: string): void;
21
26
  };
22
27
  export type UnistylesThemeEvent = {
23
- type: CxxUnistylesEventTypes.Theme;
28
+ type: UnistylesEventType.Theme;
24
29
  payload: {
25
30
  themeName: keyof UnistylesThemes;
26
31
  };
27
32
  };
28
33
  export type UnistylesMobileLayoutEvent = {
29
- type: CxxUnistylesEventTypes.Layout;
34
+ type: UnistylesEventType.Layout;
30
35
  payload: {
31
36
  screen: ScreenSize;
32
37
  breakpoint: keyof UnistylesBreakpoints;
33
- orientation: ScreenOrientation;
38
+ orientation: typeof ScreenOrientation[keyof typeof ScreenOrientation];
34
39
  };
35
40
  };
36
- export type UnistylesEvents = UnistylesThemeEvent | UnistylesMobileLayoutEvent;
37
- export interface UnistylesEngine {
38
- didMatchMediaQuery(keys: NestedKeys): Optional<string>;
39
- }
41
+ export type UnistylesPluginEvent = {
42
+ type: UnistylesEventType.Plugin;
43
+ };
44
+ export type UnistylesEvents = UnistylesThemeEvent | UnistylesMobileLayoutEvent | UnistylesPluginEvent;
40
45
  //# sourceMappingURL=unistyles.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"unistyles.d.ts","sourceRoot":"","sources":["../../../../src/types/unistyles.ts"],"names":[],"mappings":"AAAA,O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B,CAAC,CAAC,CAAC,CAAC;IAG7G,MAAM,EAAE,KAAK,CAAC,MAAM,eAAe,CAAC,CAAC;IACrC,cAAc,CAAC,WAAW,EAAE,oBAAoB,GAAG,IAAI,CAAC;IACxD,QAAQ,CAAC,IAAI,EAAE,MAAM,eAAe,GAAG,IAAI,CAAC;IAC5C,iBAAiB,CAAC,MAAM,EAAE,OAAO,GAAG,IAAI,CAAC;IACzC,SAAS,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,GAAG,IAAI,CAAC;IACrD,YAAY,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI,CAAA;CACzC,CAAA;AAED,MAAM,MAAM,mBAAmB,GAAG;IAC9B,IAAI,EAAE,kBAAkB,CAAC,KAAK,CAAC;IAC/B,OAAO,EAAE;QACL,SAAS,EAAE,MAAM,eAAe,CAAA;KACnC,CAAA;CACJ,CAAA;AAED,MAAM,MAAM,0BAA0B,GAAG;IACrC,IAAI,EAAE,kBAAkB,CAAC,MAAM,CAAC;IAChC,OAAO,EAAE;QACL,MAAM,EAAE,UAAU,CAAC;QACnB,UAAU,EAAE,MAAM,oBAAoB,CAAC;QACvC,WAAW,EAAE,OAAO,iBAAiB,CAAC,MAAM,OAAO,iBAAiB,CAAC,CAAA;KACxE,CAAA;CACJ,CAAA;AAED,MAAM,MAAM,oBAAoB,GAAG;IAC/B,IAAI,EAAE,kBAAkB,CAAC,MAAM,CAAA;CAClC,CAAA;AAED,MAAM,MAAM,eAAe,GAAG,mBAAmB,GAAG,0BAA0B,GAAG,oBAAoB,CAAA"}
@@ -0,0 +1,14 @@
1
+ export type ExtractVariantNames<T> = T extends (...args: any) => infer R ? ExtractVariantKeys<R> : ExtractVariantKeys<T>;
2
+ type ExtractVariantKeys<T> = T extends object ? ExtractVariant<T[keyof T]> : never;
3
+ type ExtractSubVariantKeys<T> = T extends object ? keyof Omit<T, 'default'> | undefined : never;
4
+ type ExtractVariant<T> = T extends (...args: any) => infer R ? R extends {
5
+ variants: infer V;
6
+ } ? {
7
+ [key in keyof V]?: ExtractSubVariantKeys<V[key]>;
8
+ } : never : T extends {
9
+ variants: infer V;
10
+ } ? {
11
+ [key in keyof V]?: ExtractSubVariantKeys<V[key]>;
12
+ } : never;
13
+ export {};
14
+ //# sourceMappingURL=variants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"variants.d.ts","sourceRoot":"","sources":["../../../../src/types/variants.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,mBAAmB,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,KAAK,MAAM,CAAC,GAClE,kBAAkB,CAAC,CAAC,CAAC,GACrB,kBAAkB,CAAC,CAAC,CAAC,CAAA;AAE3B,KAAK,kBAAkB,CAAC,CAAC,IAAI,CAAC,SAAS,MAAM,GACvC,cAAc,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAC1B,KAAK,CAAA;AAEX,KAAK,qBAAqB,CAAC,CAAC,IAAI,CAAC,SAAS,MAAM,GAC1C,MAAM,IAAI,CAAC,CAAC,EAAE,SAAS,CAAC,GAAG,SAAS,GACpC,KAAK,CAAA;AAEX,KAAK,cAAc,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,KAAK,MAAM,CAAC,GACtD,CAAC,SAAS;IAAE,QAAQ,EAAE,MAAM,CAAC,CAAA;CAAE,GAC3B;KAAG,GAAG,IAAI,MAAM,CAAC,CAAC,CAAC,EAAE,qBAAqB,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;CAAE,GACpD,KAAK,GACT,CAAC,SAAS;IAAE,QAAQ,EAAE,MAAM,CAAC,CAAA;CAAE,GAC3B;KAAG,GAAG,IAAI,MAAM,CAAC,CAAC,CAAC,EAAE,qBAAqB,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;CAAE,GACpD,KAAK,CAAA"}
@@ -1,10 +1,10 @@
1
- import type { CreateStylesFactory, CustomNamedStyles, ReactNativeStyleSheet, UnistylesTheme } from './types';
2
1
  import type { UnistylesBreakpoints } from './global';
3
- type ParsedStylesheet<ST extends CustomNamedStyles<ST>> = {
2
+ import type { ExtractVariantNames, ReactNativeStyleSheet, StyleSheetWithSuperPowers, UnistylesTheme } from './types';
3
+ type ParsedStylesheet<ST extends StyleSheetWithSuperPowers> = {
4
4
  theme: UnistylesTheme;
5
5
  breakpoint: keyof UnistylesBreakpoints;
6
6
  styles: ReactNativeStyleSheet<ST>;
7
7
  };
8
- export declare const useStyles: <ST extends CustomNamedStyles<ST>>(stylesheet?: ST | CreateStylesFactory<ST, never> | undefined) => ParsedStylesheet<ST>;
8
+ export declare const useStyles: <ST extends StyleSheetWithSuperPowers>(stylesheet?: ST | undefined, variantsMap?: ExtractVariantNames<ST> | undefined) => ParsedStylesheet<ST>;
9
9
  export {};
10
10
  //# sourceMappingURL=useStyles.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useStyles.d.ts","sourceRoot":"","sources":["../../../src/useStyles.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAE5G,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAA;AAEpD,KAAK,gBAAgB,CAAC,EAAE,SAAS,iBAAiB,CAAC,EAAE,CAAC,IAAI;IACtD,KAAK,EAAE,cAAc,CAAC;IACtB,UAAU,EAAE,MAAM,oBAAoB,CAAC;IACvC,MAAM,EAAE,qBAAqB,CAAC,EAAE,CAAC,CAAA;CACpC,CAAA;AAED,eAAO,MAAM,SAAS,0HAuCrB,CAAA"}
1
+ {"version":3,"file":"useStyles.d.ts","sourceRoot":"","sources":["../../../src/useStyles.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAA;AACpD,OAAO,KAAK,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,yBAAyB,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAEpH,KAAK,gBAAgB,CAAC,EAAE,SAAS,yBAAyB,IAAI;IAC1D,KAAK,EAAE,cAAc,CAAC;IACtB,UAAU,EAAE,MAAM,oBAAoB,CAAC;IACvC,MAAM,EAAE,qBAAqB,CAAC,EAAE,CAAC,CAAA;CACpC,CAAA;AAED,eAAO,MAAM,SAAS,gJAgCrB,CAAA"}
@@ -1,6 +1,3 @@
1
- import type { MediaQuery } from '../types';
2
- import type { UnistylesBreakpoints } from '../global';
3
- export declare const sortAndValidateBreakpoints: (breakpoints: UnistylesBreakpoints) => UnistylesBreakpoints;
4
- export declare const getBreakpointFromScreenWidth: (width: number, breakpointEntries: Array<[keyof UnistylesBreakpoints, UnistylesBreakpoints[keyof UnistylesBreakpoints]]>) => keyof UnistylesBreakpoints & string;
5
- export declare const getValueForBreakpoint: (value: Record<keyof UnistylesBreakpoints | MediaQuery, string | number | undefined>) => string | number | undefined;
1
+ import type { Optional, RNValue } from '../types';
2
+ export declare const getValueForBreakpoint: (value: Record<string, RNValue>) => Optional<RNValue>;
6
3
  //# sourceMappingURL=breakpoints.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"breakpoints.d.ts","sourceRoot":"","sources":["../../../../src/utils/breakpoints.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAc,MAAM,UAAU,CAAA;AACtD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAA;AAIrD,eAAO,MAAM,0BAA0B,gBAAiB,oBAAoB,KAAG,oBAuB9E,CAAA;AAED,eAAO,MAAM,4BAA4B,UAAW,MAAM,qBAAqB,MAAM,CAAC,MAAM,oBAAoB,EAAE,oBAAoB,CAAC,MAAM,oBAAoB,CAAC,CAAC,CAAC,KAAG,MAAM,oBAAoB,GAAG,MAcnM,CAAA;AAED,eAAO,MAAM,qBAAqB,UAAW,OAAO,MAAM,oBAAoB,GAAG,UAAU,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC,KAAG,MAAM,GAAG,MAAM,GAAG,SAmD7I,CAAA"}
1
+ {"version":3,"file":"breakpoints.d.ts","sourceRoot":"","sources":["../../../../src/utils/breakpoints.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA;AAKjD,eAAO,MAAM,qBAAqB,UAAW,OAAO,MAAM,EAAE,OAAO,CAAC,KAAG,SAAS,OAAO,CAqCtF,CAAA"}
@@ -1,8 +1,6 @@
1
- export { normalizeStyles } from './normalizeStyles';
2
- export * from './normalizer';
3
- export { mq, MQSymbol } from './mq';
4
- export { getKeyForUnistylesMediaQuery } from './mqParser';
5
- export { getBreakpointFromScreenWidth, sortAndValidateBreakpoints, getValueForBreakpoint } from './breakpoints';
1
+ export { mq } from './mq';
2
+ export { getKeyForUnistylesMediaQuery, isWithinTheWidthAndHeight, isValidMq, parseMq } from './mqParser';
3
+ export { getValueForBreakpoint } from './breakpoints';
6
4
  export { proxifyFunction, parseStyle } from './styles';
7
- export { isServer, Orientation } from './common';
5
+ export { withPlugins } from './withPlugins';
8
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACnD,cAAc,cAAc,CAAA;AAC5B,OAAO,EAAE,EAAE,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAA;AACnC,OAAO,EAAE,4BAA4B,EAAE,MAAM,YAAY,CAAA;AACzD,OAAO,EAAE,4BAA4B,EAAE,0BAA0B,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAA;AAC/G,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AACtD,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,MAAM,CAAA;AACzB,OAAO,EAAE,4BAA4B,EAAE,yBAAyB,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AACxG,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAA;AACrD,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA"}
@@ -1,21 +1,22 @@
1
- import type { MediaQuery, Nullable } from '../types';
1
+ import type { Nullable } from '../types';
2
2
  import type { UnistylesBreakpoints } from '../global';
3
- export declare const MQSymbol: unique symbol;
4
3
  type MQValue = keyof UnistylesBreakpoints | number;
5
4
  type MQHandler = {
6
- w(wMin?: Nullable<MQValue>, wMax?: MQValue): WidthHandler;
7
- width(wMin?: Nullable<MQValue>, wMax?: MQValue): WidthHandler;
8
- h(hMin?: Nullable<MQValue>, hMax?: MQValue): HeightHandler;
9
- height(hMin?: Nullable<MQValue>, hMax?: MQValue): HeightHandler;
5
+ only: {
6
+ width(wMin?: Nullable<MQValue>, wMax?: MQValue): symbol;
7
+ height(hMin?: Nullable<MQValue>, hMax?: MQValue): symbol;
8
+ };
9
+ width(wMin?: Nullable<MQValue>, wMax?: MQValue): {
10
+ and: {
11
+ height(hMin?: Nullable<MQValue>, hMax?: MQValue): symbol;
12
+ };
13
+ };
14
+ height(hMin?: Nullable<MQValue>, hMax?: MQValue): {
15
+ and: {
16
+ width(wMin?: Nullable<MQValue>, wMax?: MQValue): symbol;
17
+ };
18
+ };
10
19
  };
11
- type HeightHandler = {
12
- w(wMin?: Nullable<MQValue>, wMax?: MQValue): MediaQuery;
13
- width(wMin?: Nullable<MQValue>, wMax?: MQValue): MediaQuery;
14
- } & MediaQuery;
15
- type WidthHandler = {
16
- h(hMin?: Nullable<MQValue>, hMax?: MQValue): MediaQuery;
17
- height(hMin?: Nullable<MQValue>, hMax?: MQValue): MediaQuery;
18
- } & MediaQuery;
19
20
  export declare const mq: MQHandler;
20
21
  export {};
21
22
  //# sourceMappingURL=mq.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"mq.d.ts","sourceRoot":"","sources":["../../../../src/utils/mq.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AACpD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAA;AAGrD,eAAO,MAAM,QAAQ,eAAyB,CAAA;AAE9C,KAAK,OAAO,GAAG,MAAM,oBAAoB,GAAG,MAAM,CAAA;AAElD,KAAK,SAAS,GAAG;IACb,CAAC,CAAC,IAAI,CAAC,EAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,YAAY,CAAC;IAC1D,KAAK,CAAC,IAAI,CAAC,EAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,YAAY,CAAC;IAC9D,CAAC,CAAC,IAAI,CAAC,EAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,aAAa,CAAC;IAC3D,MAAM,CAAC,IAAI,CAAC,EAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,aAAa,CAAA;CAClE,CAAA;AAED,KAAK,aAAa,GAAG;IACjB,CAAC,CAAC,IAAI,CAAC,EAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,UAAU,CAAC;IACxD,KAAK,CAAC,IAAI,CAAC,EAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,UAAU,CAAA;CAC9D,GAAG,UAAU,CAAA;AAEd,KAAK,YAAY,GAAG;I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AI,CAAC,EAAE,OAAO,GAAG,MAAM,CAAA;SAC1D,CAAA;KACJ,CAAA;CACJ,CAAA;AAcD,eAAO,MAAM,EAAE,EAAE,SAiBhB,CAAA"}
@@ -1,3 +1,15 @@
1
- import type { NestedKeys, Optional, ScreenSize } from '../types';
2
- export declare const getKeyForUnistylesMediaQuery: (mediaQueries: NestedKeys, screenSize: ScreenSize) => Optional<string>;
1
+ import type { Optional, RNValue, ScreenSize } from '../types';
2
+ type ParsedMqDimension = {
3
+ from: number;
4
+ to: number;
5
+ };
6
+ type UnistylesParsedMq = {
7
+ width?: ParsedMqDimension;
8
+ height?: ParsedMqDimension;
9
+ };
10
+ export declare const parseMq: (mq: string) => UnistylesParsedMq;
11
+ export declare const isValidMq: (parsedMq: UnistylesParsedMq) => boolean;
12
+ export declare const isWithinTheWidthAndHeight: (parsedMq: UnistylesParsedMq, screenSize: ScreenSize) => boolean;
13
+ export declare const getKeyForUnistylesMediaQuery: (mediaQueries: Array<[string, RNValue]>, screenSize: ScreenSize) => Optional<string>;
14
+ export {};
3
15
  //# sourceMappingURL=mqParser.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"mqParser.d.ts","sourceRoot":"","sources":["../../../../src/utils/mqParser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAkFhE,eAAO,MAAM,4BAA4B,yCAA0C,UAAU,qBAgB5F,CAAA"}
1
+ {"version":3,"file":"mqParser.d.ts","sourceRoot":"","sources":["../../../../src/utils/mqParser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAM7D,KAAK,iBAAiB,GAAG;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAA;CACb,CAAA;AAED,KAAK,iBAAiB,GAAG;IACrB,KAAK,CAAC,EAAE,iBAAiB,CAAC;IAC1B,MAAM,CAAC,EAAE,iBAAiB,CAAA;CAC7B,CAAA;AAED,eAAO,MAAM,OAAO,OAAQ,MAAM,KAAG,iBAcpC,CAAA;AAID,eAAO,MAAM,SAAS,aAAc,iBAAiB,YAgBpD,CAAA;AAED,eAAO,MAAM,yBAAyB,aAAc,iBAAiB,cAAc,UAAU,KAAG,OAgB/F,CAAA;AAcD,eAAO,MAAM,4BAA4B,iBAAkB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,cAAc,UAAU,KAAG,SAAS,MAAM,CAgB5H,CAAA"}
@@ -1,6 +1,5 @@
1
- import type { CustomNamedStyles, ScreenSize } from '../types';
2
- import type { UnistylesBreakpoints } from '../global';
3
- export declare const proxifyFunction: (fn: Function, breakpoint: keyof UnistylesBreakpoints & string, screenSize: ScreenSize) => Function;
1
+ import type { Optional, RNStyle } from '../types';
2
+ export declare const proxifyFunction: (key: string, fn: Function, variant?: Record<string, Optional<string>>) => Function;
4
3
  export declare const isPlatformColor: <T extends {}>(value: T) => boolean;
5
- export declare const parseStyle: <T>(style: CustomNamedStyles<T>, breakpoint: keyof UnistylesBreakpoints & string, screenSize: ScreenSize) => T;
4
+ export declare const parseStyle: <T extends RNStyle>(style: T, variant?: Record<string, Optional<string>>) => T;
6
5
  //# sourceMappingURL=styles.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"styles.d.ts","sourceRoot":"","sources":["../../../../src/utils/styles.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,UAAU,EAAc,MAAM,UAAU,CAAA;AAGzE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAA;AAGrD,eAAO,MAAM,eAAe,OACpB,QAAQ,cAAc,MAAM,oBAAoB,GAAG,MAAM,cACjD,UAAU,KACvB,QAGD,CAAA;AAEF,eAAO,MAAM,eAAe,8BAA6B,OAMxD,CAAA;AAED,eAAO,MAAM,UAAU,+CAEP,MAAM,oBAAoB,GAAG,MAAM,cACnC,UAAU,MA6CzB,CAAA"}
1
+ {"version":3,"file":"styles.d.ts","sourceRoot":"","sources":["../../../../src/utils/styles.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAW,MAAM,UAAU,CAAA;AAK1D,eAAO,MAAM,eAAe,QACnB,MAAM,MACP,QAAQ,YACF,OAAO,MAAM,EAAE,SAAS,MAAM,CAAC,CAAC,KAC3C,QAED,CAAA;AAEF,eAAO,MAAM,eAAe,8BAA6B,OAMxD,CAAA;AAED,eAAO,MAAM,UAAU,0CAEV,OAAO,MAAM,EAAE,SAAS,MAAM,CAAC,CAAC,MAyC9B,CAAA"}
@@ -0,0 +1,3 @@
1
+ import type { RNStyle } from '../types';
2
+ export declare const withPlugins: (key: string, style: RNStyle) => RNStyle;
3
+ //# sourceMappingURL=withPlugins.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"withPlugins.d.ts","sourceRoot":"","sources":["../../../../src/utils/withPlugins.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA;AAGvC,eAAO,MAAM,WAAW,QACf,MAAM,SACJ,OAAO,YAOT,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-unistyles",
3
- "version": "2.0.0-alpha.9",
3
+ "version": "2.0.0-beta.2",
4
4
  "description": "Level up your React Native StyleSheet",
5
5
  "scripts": {
6
6
  "test": "jest",
@@ -9,7 +9,7 @@
9
9
  "lint": "eslint . --ext .ts,.tsx",
10
10
  "prepare": "husky install && bob build",
11
11
  "precommit": "concurrently 'yarn tsc' 'yarn lint' 'yarn test'",
12
- "release": "release-it patch --preRelease=alpha --npm.tag=next"
12
+ "release": "release-it patch --preRelease=beta --npm.tag=next"
13
13
  },
14
14
  "main": "lib/commonjs/index",
15
15
  "module": "lib/module/index",
@@ -50,23 +50,23 @@
50
50
  "registry": "https://registry.npmjs.org/"
51
51
  },
52
52
  "devDependencies": {
53
- "@commitlint/config-conventional": "18.1.0",
53
+ "@commitlint/config-conventional": "18.4.3",
54
54
  "@react-native/eslint-config": "0.74.0",
55
55
  "@react-native/normalize-colors": "0.74.1",
56
- "@release-it/conventional-changelog": "7.0.2",
56
+ "@release-it/conventional-changelog": "8.0.1",
57
57
  "@testing-library/react-hooks": "8.0.1",
58
- "@types/jest": "29.5.7",
59
- "@types/react": "18.2.34",
60
- "@typescript-eslint/eslint-plugin": "6.9.1",
61
- "@typescript-eslint/eslint-plugin-tslint": "6.9.1",
62
- "@typescript-eslint/parser": "6.9.1",
63
- "commitlint": "18.2.0",
58
+ "@types/jest": "29.5.10",
59
+ "@types/react": "18.2.39",
60
+ "@typescript-eslint/eslint-plugin": "6.13.1",
61
+ "@typescript-eslint/eslint-plugin-tslint": "6.13.1",
62
+ "@typescript-eslint/parser": "6.13.1",
63
+ "commitlint": "18.4.3",
64
64
  "concurrently": "8.2.2",
65
- "eslint": "8.53.0",
65
+ "eslint": "8.54.0",
66
66
  "eslint-config-codemask": "1.1.7",
67
67
  "eslint-plugin-functional": "6.0.0",
68
68
  "eslint-plugin-import": "2.29.0",
69
- "eslint-plugin-jsdoc": "46.8.2",
69
+ "eslint-plugin-jsdoc": "46.9.0",
70
70
  "eslint-plugin-jsx-a11y": "6.8.0",
71
71
  "eslint-plugin-nested-if": "1.0.0",
72
72
  "eslint-plugin-no-else": "0.2.2",
@@ -77,12 +77,12 @@
77
77
  "husky": "8.0.3",
78
78
  "jest": "29.7.0",
79
79
  "react": "18.2.0",
80
- "react-native": "0.72.6",
81
- "react-native-builder-bob": "0.23.1",
80
+ "react-native": "0.72.7",
81
+ "react-native-builder-bob": "0.23.2",
82
82
  "react-native-web": "0.19.9",
83
83
  "react-test-renderer": "18.2.0",
84
- "release-it": "16.2.1",
85
- "typescript": "5.2.2"
84
+ "release-it": "17.0.0",
85
+ "typescript": "5.3.2"
86
86
  },
87
87
  "peerDependencies": {
88
88
  "@react-native/normalize-colors": "*",
@@ -111,6 +111,9 @@
111
111
  "<rootDir>/docs/node_modules",
112
112
  "<rootDir>/lib/"
113
113
  ],
114
+ "testMatch": [
115
+ "**/*.spec.(ts|tsx)"
116
+ ],
114
117
  "coverageReporters": [
115
118
  "html"
116
119
  ]
@@ -0,0 +1,24 @@
1
+ import type { ScreenSize } from '../types'
2
+
3
+ const TEST_BREAKPOINTS = {
4
+ xs: 0,
5
+ sm: 300,
6
+ md: 500,
7
+ lg: 750,
8
+ xl: 1000
9
+ } as const
10
+
11
+ export const mockRuntime = (screenSize: ScreenSize) => ({
12
+ breakpoint: Object.entries(TEST_BREAKPOINTS)
13
+ .reverse()
14
+ .find(([, value]) => screenSize.width >= value)?.at(0),
15
+ orientation: screenSize.width > screenSize.height
16
+ ? 'landscape'
17
+ : 'portrait',
18
+ screen: screenSize
19
+ })
20
+
21
+ export const mockRegistry = () => ({
22
+ sortedBreakpointPairs: Object.entries(TEST_BREAKPOINTS),
23
+ plugins: []
24
+ })
package/src/common.ts CHANGED
@@ -1,19 +1,35 @@
1
- export enum CxxUnistylesEventTypes {
2
- Theme = 'theme',
3
- Layout = 'layout'
1
+ import { Platform } from 'react-native'
2
+
3
+ export const warn = (message: string) => {
4
+ console.warn(`🦄 [react-native-unistyles]: ${message}`)
4
5
  }
5
6
 
6
- export enum UnistylesError {
7
- RuntimeUnavailable = 'UNISTYLES_ERROR_RUNTIME_UNAVAILABLE',
8
- ThemeNotFound = 'UNISTYLES_ERROR_THEME_NOT_FOUND',
9
- ThemeNotRegistered = 'UNISTYLES_ERROR_THEME_NOT_REGISTERED',
10
- ThemesCannotBeEmpty = 'UNISTYLES_ERROR_THEMES_CANNOT_BE_EMPTY',
11
- BreakpointsCannotBeEmpty = 'UNISTYLES_ERROR_BREAKPOINTS_CANNOT_BE_EMPTY',
12
- BreakpointsMustStartFromZero = 'UNISTYLES_ERROR_BREAKPOINTS_MUST_START_FROM_ZERO',
7
+ export const isWeb = Platform.OS === 'web'
8
+ export const isIOS = Platform.OS === 'ios'
9
+ export const isAndroid = Platform.OS === 'android'
10
+ export const isMobile = isIOS || isAndroid
11
+ export const isServer = typeof window === 'undefined'
12
+
13
+ export const ScreenOrientation = {
14
+ Landscape: 'landscape',
15
+ Portrait: 'portrait'
16
+ } as const
17
+
18
+ export enum UnistylesEventType {
19
+ Theme = 'theme',
20
+ Layout = 'layout',
21
+ Plugin = 'plugin'
13
22
  }
14
23
 
15
- // todo to string?
16
- export enum ScreenOrientation {
17
- Portrait = 1,
18
- Landscape = 2
24
+ export enum UnistylesError {
25
+ RuntimeUnavailable = 'Unistyles runtime is not available. Make sure you followed the installation instructions',
26
+ ThemeNotFound = 'You are trying to get a theme that is not registered with UnistylesRegistry',
27
+ ThemeNotRegistered = 'You are trying to set a theme that was not registered with UnistylesRegistry',
28
+ ThemeNotSelected = 'Your themes are registered, but you didn\'t select the initial theme',
29
+ ThemesCannotBeEmpty = 'You are trying to register empty themes object',
30
+ BreakpointsCannotBeEmpty = 'You are trying to register empty breakpoints object',
31
+ BreakpointsMustStartFromZero = 'You are trying to register breakpoints that don\'t start from 0',
32
+ InvalidPluginName = 'Plugin name can\'t start from reserved prefix __unistyles',
33
+ DuplicatePluginName = 'You are trying to register a plugin with a name that is already registered',
34
+ CantRemoveInternalPlugin = 'You are trying to remove an internal unistyles plugin'
19
35
  }
@@ -1,8 +1,13 @@
1
- import type { UnistylesBridge, UnistylesConfig } from '../types'
1
+ import type { UnistylesBridge, UnistylesConfig, UnistylesPlugin } from '../types'
2
2
  import type { UnistylesBreakpoints, UnistylesThemes } from '../global'
3
+ import { isWeb, UnistylesError } from '../common'
4
+ import { normalizeWebStylesPlugin } from '../plugins'
3
5
 
4
6
  export class UnistyleRegistry {
5
7
  public config: UnistylesConfig = {}
8
+ public plugins: Array<UnistylesPlugin> = isWeb
9
+ ? [normalizeWebStylesPlugin]
10
+ : []
6
11
  public themeNames: Array<keyof UnistylesThemes> = []
7
12
  public themes: UnistylesThemes = {} as UnistylesThemes
8
13
  public breakpoints: UnistylesBreakpoints = {} as UnistylesBreakpoints
@@ -18,7 +23,10 @@ export class UnistyleRegistry {
18
23
  this.unistylesBridge.themes = keys
19
24
  this.themeNames = keys
20
25
 
21
- return this
26
+ return {
27
+ addBreakpoints: this.addBreakpoints,
28
+ addConfig: this.addConfig
29
+ }
22
30
  }
23
31
 
24
32
  public addBreakpoints = (breakpoints: UnistylesBreakpoints) => {
@@ -26,7 +34,10 @@ export class UnistyleRegistry {
26
34
  this.unistylesBridge.useBreakpoints(breakpoints)
27
35
  this.sortedBreakpointPairs = this.unistylesBridge.sortedBreakpointPairs
28
36
 
29
- return this
37
+ return {
38
+ addThemes: this.addThemes,
39
+ addConfig: this.addConfig
40
+ }
30
41
  }
31
42
 
32
43
  public addConfig = (config: UnistylesConfig) => {
@@ -36,6 +47,57 @@ export class UnistyleRegistry {
36
47
  this.unistylesBridge.useAdaptiveThemes(config.adaptiveThemes)
37
48
  }
38
49
 
39
- return this
50
+ if (config.experimentalPlugins) {
51
+ config.experimentalPlugins.forEach(plugin => this.addPlugin(plugin, false))
52
+ }
53
+
54
+ if (config.initialTheme) {
55
+ this.unistylesBridge.useTheme(config.initialTheme)
56
+ }
57
+
58
+ return {
59
+ addBreakpoints: this.addBreakpoints,
60
+ addThemes: this.addThemes
61
+ }
62
+ }
63
+
64
+ public getTheme = (forName: keyof UnistylesThemes) => {
65
+ if (this.themeNames.length === 0) {
66
+ return {} as UnistylesThemes[keyof UnistylesThemes]
67
+ }
68
+
69
+ if (this.hasTheme(forName)) {
70
+ return this.themes[forName]
71
+ }
72
+
73
+ if (this.unistylesBridge.themeName) {
74
+ throw new Error(UnistylesError.ThemeNotFound)
75
+ }
76
+
77
+ throw new Error(UnistylesError.ThemeNotSelected)
40
78
  }
79
+
80
+ public addPlugin = (plugin: UnistylesPlugin, notify: boolean = true) => {
81
+ if (plugin.name.startsWith('__unistyles')) {
82
+ throw new Error(UnistylesError.InvalidPluginName)
83
+ }
84
+
85
+ if (this.plugins.some(({ name }) => name === plugin.name)) {
86
+ throw new Error(UnistylesError.DuplicatePluginName)
87
+ }
88
+
89
+ this.plugins = [plugin].concat(this.plugins)
90
+ this.unistylesBridge.addPlugin(plugin.name, notify)
91
+ }
92
+
93
+ public removePlugin = (plugin: UnistylesPlugin) => {
94
+ if (plugin.name.startsWith('__unistyles')) {
95
+ throw new Error(UnistylesError.CantRemoveInternalPlugin)
96
+ }
97
+
98
+ this.plugins = this.plugins.filter(({ name }) => name !== plugin.name)
99
+ this.unistylesBridge.removePlugin(plugin.name)
100
+ }
101
+
102
+ public hasTheme = (name: keyof UnistylesThemes) => name in this.themes
41
103
  }
@@ -2,7 +2,7 @@ import { UnistylesModule } from './UnistylesModule'
2
2
  import { UnistylesRuntime } from './UnistylesRuntime'
3
3
  import { UnistyleRegistry } from './UnistyleRegistry'
4
4
  import type { UnistylesBridge } from '../types'
5
- import { UnistylesError } from '../common'
5
+ import { UnistylesError, isWeb } from '../common'
6
6
 
7
7
  class Unistyles {
8
8
  private _runtime: UnistylesRuntime
@@ -17,7 +17,7 @@ class Unistyles {
17
17
  }
18
18
 
19
19
  // @ts-ignore
20
- this._bridge = global.__UNISTYLES__ as UnistylesBridge
20
+ this._bridge = (isWeb ? window : global).__UNISTYLES__ as UnistylesBridge
21
21
  this._registry = new UnistyleRegistry(this._bridge)
22
22
  this._runtime = new UnistylesRuntime(this._bridge, this._registry)
23
23
  }