react-native-unistyles 2.0.0-alpha.7 → 2.0.0-alpha.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (203) hide show
  1. package/lib/commonjs/{types/cxx.js → common.js} +6 -6
  2. package/lib/commonjs/common.js.map +1 -0
  3. package/lib/commonjs/core/UnistyleRegistry.js.map +1 -0
  4. package/lib/commonjs/{Unistyles.js → core/Unistyles.js} +2 -7
  5. package/lib/commonjs/core/Unistyles.js.map +1 -0
  6. package/lib/commonjs/core/UnistylesModule.js.map +1 -0
  7. package/lib/commonjs/{UnistylesRuntime.js → core/UnistylesRuntime.js} +5 -5
  8. package/lib/commonjs/core/UnistylesRuntime.js.map +1 -0
  9. package/lib/commonjs/core/index.js +13 -0
  10. package/lib/commonjs/core/index.js.map +1 -0
  11. package/lib/commonjs/hooks/index.js +10 -3
  12. package/lib/commonjs/hooks/index.js.map +1 -1
  13. package/lib/commonjs/{useInitialTheme.js → hooks/useInitialTheme.js} +2 -2
  14. package/lib/commonjs/hooks/useInitialTheme.js.map +1 -0
  15. package/lib/commonjs/hooks/useUnistyles.js +54 -0
  16. package/lib/commonjs/hooks/useUnistyles.js.map +1 -0
  17. package/lib/commonjs/index.js +8 -8
  18. package/lib/commonjs/index.js.map +1 -1
  19. package/lib/commonjs/types/common.js +2 -0
  20. package/lib/commonjs/types/{mediaQueries.js.map → common.js.map} +1 -1
  21. package/lib/commonjs/types/index.js +4 -4
  22. package/lib/commonjs/types/index.js.map +1 -1
  23. package/lib/commonjs/types/mq.js +6 -0
  24. package/lib/{module/types/mediaQueries.js.map → commonjs/types/mq.js.map} +1 -1
  25. package/lib/commonjs/types/unistyles.js +6 -0
  26. package/lib/commonjs/types/unistyles.js.map +1 -0
  27. package/lib/commonjs/useStyles.js +7 -4
  28. package/lib/commonjs/useStyles.js.map +1 -1
  29. package/lib/commonjs/utils/breakpoints.js +18 -20
  30. package/lib/commonjs/utils/breakpoints.js.map +1 -1
  31. package/lib/commonjs/utils/index.js +10 -38
  32. package/lib/commonjs/utils/index.js.map +1 -1
  33. package/lib/commonjs/utils/mq.js +67 -53
  34. package/lib/commonjs/utils/mq.js.map +1 -1
  35. package/lib/commonjs/utils/mqParser.js +86 -0
  36. package/lib/commonjs/utils/mqParser.js.map +1 -0
  37. package/lib/commonjs/utils/styles.js.map +1 -1
  38. package/lib/module/{types/cxx.js → common.js} +6 -6
  39. package/lib/module/common.js.map +1 -0
  40. package/lib/module/core/UnistyleRegistry.js.map +1 -0
  41. package/lib/module/{Unistyles.js → core/Unistyles.js} +1 -6
  42. package/lib/module/core/Unistyles.js.map +1 -0
  43. package/lib/module/core/UnistylesModule.js.map +1 -0
  44. package/lib/module/{UnistylesRuntime.js → core/UnistylesRuntime.js} +1 -1
  45. package/lib/module/core/UnistylesRuntime.js.map +1 -0
  46. package/lib/module/core/index.js +2 -0
  47. package/lib/module/core/index.js.map +1 -0
  48. package/lib/module/hooks/index.js +2 -1
  49. package/lib/module/hooks/index.js.map +1 -1
  50. package/lib/module/{useInitialTheme.js → hooks/useInitialTheme.js} +1 -1
  51. package/lib/module/hooks/useInitialTheme.js.map +1 -0
  52. package/lib/module/hooks/useUnistyles.js +47 -0
  53. package/lib/module/hooks/useUnistyles.js.map +1 -0
  54. package/lib/module/index.js +7 -7
  55. package/lib/module/index.js.map +1 -1
  56. package/lib/module/types/common.js +2 -0
  57. package/lib/module/types/common.js.map +1 -0
  58. package/lib/module/types/index.js +1 -1
  59. package/lib/module/types/index.js.map +1 -1
  60. package/lib/module/types/mq.js +2 -0
  61. package/lib/module/types/mq.js.map +1 -0
  62. package/lib/module/types/unistyles.js +2 -0
  63. package/lib/module/types/unistyles.js.map +1 -0
  64. package/lib/module/useStyles.js +6 -3
  65. package/lib/module/useStyles.js.map +1 -1
  66. package/lib/module/utils/breakpoints.js +14 -16
  67. package/lib/module/utils/breakpoints.js.map +1 -1
  68. package/lib/module/utils/index.js +2 -2
  69. package/lib/module/utils/index.js.map +1 -1
  70. package/lib/module/utils/mq.js +65 -51
  71. package/lib/module/utils/mq.js.map +1 -1
  72. package/lib/module/utils/mqParser.js +79 -0
  73. package/lib/module/utils/mqParser.js.map +1 -0
  74. package/lib/module/utils/styles.js.map +1 -1
  75. package/lib/typescript/src/common.d.ts +17 -0
  76. package/lib/typescript/src/common.d.ts.map +1 -0
  77. package/lib/typescript/src/{UnistyleRegistry.d.ts → core/UnistyleRegistry.d.ts} +2 -2
  78. package/lib/typescript/src/core/UnistyleRegistry.d.ts.map +1 -0
  79. package/lib/typescript/src/{Unistyles.d.ts → core/Unistyles.d.ts} +0 -3
  80. package/lib/typescript/src/core/Unistyles.d.ts.map +1 -0
  81. package/lib/typescript/src/core/UnistylesModule.d.ts.map +1 -0
  82. package/lib/typescript/src/{UnistylesRuntime.d.ts → core/UnistylesRuntime.d.ts} +6 -6
  83. package/lib/typescript/src/core/UnistylesRuntime.d.ts.map +1 -0
  84. package/lib/typescript/src/core/index.d.ts +2 -0
  85. package/lib/typescript/src/core/index.d.ts.map +1 -0
  86. package/lib/typescript/src/hooks/index.d.ts +2 -1
  87. package/lib/typescript/src/hooks/index.d.ts.map +1 -1
  88. package/lib/typescript/src/hooks/useInitialTheme.d.ts +3 -0
  89. package/lib/typescript/src/hooks/useInitialTheme.d.ts.map +1 -0
  90. package/lib/typescript/src/hooks/useUnistyles.d.ts +12 -0
  91. package/lib/typescript/src/hooks/useUnistyles.d.ts.map +1 -0
  92. package/lib/typescript/src/index.d.ts +10 -10
  93. package/lib/typescript/src/index.d.ts.map +1 -1
  94. package/lib/typescript/src/types/breakpoints.d.ts +5 -9
  95. package/lib/typescript/src/types/breakpoints.d.ts.map +1 -1
  96. package/lib/typescript/src/types/common.d.ts +3 -0
  97. package/lib/typescript/src/types/common.d.ts.map +1 -0
  98. package/lib/typescript/src/types/core.d.ts +9 -4
  99. package/lib/typescript/src/types/core.d.ts.map +1 -1
  100. package/lib/typescript/src/types/index.d.ts +5 -4
  101. package/lib/typescript/src/types/index.d.ts.map +1 -1
  102. package/lib/typescript/src/types/mq.d.ts +3 -0
  103. package/lib/typescript/src/types/mq.d.ts.map +1 -0
  104. package/lib/typescript/src/types/{cxx.d.ts → unistyles.d.ts} +4 -22
  105. package/lib/typescript/src/types/unistyles.d.ts.map +1 -0
  106. package/lib/typescript/src/useStyles.d.ts +8 -6
  107. package/lib/typescript/src/useStyles.d.ts.map +1 -1
  108. package/lib/typescript/src/utils/breakpoints.d.ts +2 -2
  109. package/lib/typescript/src/utils/breakpoints.d.ts.map +1 -1
  110. package/lib/typescript/src/utils/index.d.ts +2 -2
  111. package/lib/typescript/src/utils/index.d.ts.map +1 -1
  112. package/lib/typescript/src/utils/mq.d.ts +15 -9
  113. package/lib/typescript/src/utils/mq.d.ts.map +1 -1
  114. package/lib/typescript/src/utils/mqParser.d.ts +3 -0
  115. package/lib/typescript/src/utils/mqParser.d.ts.map +1 -0
  116. package/lib/typescript/src/utils/styles.d.ts.map +1 -1
  117. package/package.json +1 -1
  118. package/src/common.ts +18 -0
  119. package/src/{UnistyleRegistry.ts → core/UnistyleRegistry.ts} +2 -2
  120. package/src/{Unistyles.ts → core/Unistyles.ts} +2 -9
  121. package/src/{UnistylesRuntime.ts → core/UnistylesRuntime.ts} +3 -3
  122. package/src/core/index.ts +1 -0
  123. package/src/hooks/index.ts +2 -1
  124. package/src/{useInitialTheme.ts → hooks/useInitialTheme.ts} +2 -2
  125. package/src/hooks/useUnistyles.ts +55 -0
  126. package/src/index.ts +10 -8
  127. package/src/types/breakpoints.ts +6 -11
  128. package/src/types/common.ts +2 -0
  129. package/src/types/core.ts +10 -4
  130. package/src/types/index.ts +5 -9
  131. package/src/types/mq.ts +3 -0
  132. package/src/types/{cxx.ts → unistyles.ts} +3 -24
  133. package/src/useStyles.ts +15 -8
  134. package/src/utils/breakpoints.ts +13 -12
  135. package/src/utils/index.ts +2 -9
  136. package/src/utils/mq.ts +75 -46
  137. package/src/utils/mqParser.ts +99 -0
  138. package/src/utils/styles.ts +2 -2
  139. package/lib/commonjs/UnistyleRegistry.js.map +0 -1
  140. package/lib/commonjs/Unistyles.js.map +0 -1
  141. package/lib/commonjs/UnistylesEngine.js +0 -26
  142. package/lib/commonjs/UnistylesEngine.js.map +0 -1
  143. package/lib/commonjs/UnistylesModule.js.map +0 -1
  144. package/lib/commonjs/UnistylesRuntime.js.map +0 -1
  145. package/lib/commonjs/hooks/useDimensions.js +0 -10
  146. package/lib/commonjs/hooks/useDimensions.js.map +0 -1
  147. package/lib/commonjs/hooks/useDimensions.web.js +0 -34
  148. package/lib/commonjs/hooks/useDimensions.web.js.map +0 -1
  149. package/lib/commonjs/types/cxx.js.map +0 -1
  150. package/lib/commonjs/types/mediaQueries.js +0 -2
  151. package/lib/commonjs/useInitialTheme.js.map +0 -1
  152. package/lib/commonjs/useUnistyles.js +0 -51
  153. package/lib/commonjs/useUnistyles.js.map +0 -1
  154. package/lib/commonjs/utils/mediaQueries.js +0 -98
  155. package/lib/commonjs/utils/mediaQueries.js.map +0 -1
  156. package/lib/module/UnistyleRegistry.js.map +0 -1
  157. package/lib/module/Unistyles.js.map +0 -1
  158. package/lib/module/UnistylesEngine.js +0 -19
  159. package/lib/module/UnistylesEngine.js.map +0 -1
  160. package/lib/module/UnistylesModule.js.map +0 -1
  161. package/lib/module/UnistylesRuntime.js.map +0 -1
  162. package/lib/module/hooks/useDimensions.js +0 -3
  163. package/lib/module/hooks/useDimensions.js.map +0 -1
  164. package/lib/module/hooks/useDimensions.web.js +0 -27
  165. package/lib/module/hooks/useDimensions.web.js.map +0 -1
  166. package/lib/module/types/cxx.js.map +0 -1
  167. package/lib/module/types/mediaQueries.js +0 -2
  168. package/lib/module/useInitialTheme.js.map +0 -1
  169. package/lib/module/useUnistyles.js +0 -44
  170. package/lib/module/useUnistyles.js.map +0 -1
  171. package/lib/module/utils/mediaQueries.js +0 -85
  172. package/lib/module/utils/mediaQueries.js.map +0 -1
  173. package/lib/typescript/src/UnistyleRegistry.d.ts.map +0 -1
  174. package/lib/typescript/src/Unistyles.d.ts.map +0 -1
  175. package/lib/typescript/src/UnistylesEngine.d.ts +0 -11
  176. package/lib/typescript/src/UnistylesEngine.d.ts.map +0 -1
  177. package/lib/typescript/src/UnistylesModule.d.ts.map +0 -1
  178. package/lib/typescript/src/UnistylesRuntime.d.ts.map +0 -1
  179. package/lib/typescript/src/hooks/useDimensions.d.ts +0 -3
  180. package/lib/typescript/src/hooks/useDimensions.d.ts.map +0 -1
  181. package/lib/typescript/src/hooks/useDimensions.web.d.ts +0 -3
  182. package/lib/typescript/src/hooks/useDimensions.web.d.ts.map +0 -1
  183. package/lib/typescript/src/types/cxx.d.ts.map +0 -1
  184. package/lib/typescript/src/types/mediaQueries.d.ts +0 -10
  185. package/lib/typescript/src/types/mediaQueries.d.ts.map +0 -1
  186. package/lib/typescript/src/useInitialTheme.d.ts +0 -3
  187. package/lib/typescript/src/useInitialTheme.d.ts.map +0 -1
  188. package/lib/typescript/src/useUnistyles.d.ts +0 -10
  189. package/lib/typescript/src/useUnistyles.d.ts.map +0 -1
  190. package/lib/typescript/src/utils/mediaQueries.d.ts +0 -11
  191. package/lib/typescript/src/utils/mediaQueries.d.ts.map +0 -1
  192. package/src/UnistylesEngine.ts +0 -24
  193. package/src/hooks/useDimensions.ts +0 -4
  194. package/src/hooks/useDimensions.web.ts +0 -34
  195. package/src/types/mediaQueries.ts +0 -15
  196. package/src/useUnistyles.ts +0 -61
  197. package/src/utils/mediaQueries.ts +0 -152
  198. /package/lib/commonjs/{UnistyleRegistry.js → core/UnistyleRegistry.js} +0 -0
  199. /package/lib/commonjs/{UnistylesModule.js → core/UnistylesModule.js} +0 -0
  200. /package/lib/module/{UnistyleRegistry.js → core/UnistyleRegistry.js} +0 -0
  201. /package/lib/module/{UnistylesModule.js → core/UnistylesModule.js} +0 -0
  202. /package/lib/typescript/src/{UnistylesModule.d.ts → core/UnistylesModule.d.ts} +0 -0
  203. /package/src/{UnistylesModule.ts → core/UnistylesModule.ts} +0 -0
@@ -1,16 +1,11 @@
1
+ import { CxxUnistylesEventTypes, ScreenOrientation } from '../common';
1
2
  import type { UnistylesThemes, UnistylesBreakpoints } from '../global';
2
- import type { ScreenSize } from './breakpoints';
3
- import type { NestedKeys } from './core';
4
- export type Optional<T> = T | undefined;
5
- export type Nullable<T> = T | null;
3
+ import type { NestedKeys, ScreenSize } from './core';
4
+ import type { Optional } from './common';
6
5
  export type ColorSchemeName = Optional<'light' | 'dark'>;
7
6
  export type UnistylesConfig = {
8
7
  adaptiveThemes?: boolean;
9
8
  };
10
- export declare enum ScreenOrientation {
11
- Portrait = 1,
12
- Landscape = 2
13
- }
14
9
  export type UnistylesBridge = {
15
10
  screenWidth: number;
16
11
  screenHeight: number;
@@ -25,10 +20,6 @@ export type UnistylesBridge = {
25
20
  useAdaptiveThemes(enable: boolean): void;
26
21
  unregister(): void;
27
22
  };
28
- export declare enum CxxUnistylesEventTypes {
29
- Theme = "theme",
30
- Layout = "layout"
31
- }
32
23
  export type UnistylesThemeEvent = {
33
24
  type: CxxUnistylesEventTypes.Theme;
34
25
  payload: {
@@ -44,16 +35,7 @@ export type UnistylesMobileLayoutEvent = {
44
35
  };
45
36
  };
46
37
  export type UnistylesEvents = UnistylesThemeEvent | UnistylesMobileLayoutEvent;
47
- export declare enum UnistylesError {
48
- RuntimeUnavailable = "UNISTYLES_ERROR_RUNTIME_UNAVAILABLE",
49
- ThemeNotFound = "UNISTYLES_ERROR_THEME_NOT_FOUND",
50
- ThemeNotRegistered = "UNISTYLES_ERROR_THEME_NOT_REGISTERED",
51
- ThemesCannotBeEmpty = "UNISTYLES_ERROR_THEMES_CANNOT_BE_EMPTY",
52
- BreakpointsCannotBeEmpty = "UNISTYLES_ERROR_BREAKPOINTS_CANNOT_BE_EMPTY",
53
- BreakpointsMustStartFromZero = "UNISTYLES_ERROR_BREAKPOINTS_MUST_START_FROM_ZERO"
54
- }
55
38
  export interface UnistylesEngine {
56
- isMediaQuery(key: string): boolean;
57
39
  didMatchMediaQuery(keys: NestedKeys): Optional<string>;
58
40
  }
59
- //# sourceMappingURL=cxx.d.ts.map
41
+ //# sourceMappingURL=unistyles.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unistyles.d.ts","sourceRoot":"","sources":["../../../../src/types/unistyles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAA;AACrE,OAAO,KAAK,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAA;AACtE,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAA;AACpD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AAExC,MAAM,MAAM,eAAe,GAAG,QAAQ,CAAC,OAAO,GAAG,MAAM,CAAC,CAAA;AAExD,MAAM,MAAM,eAAe,GAAG;IAC1B,cAAc,CAAC,EAAE,OAAO,CAAA;CAC3B,CAAA;AAED,MAAM,MAAM,eAAe,GAAG;IAE1B,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,iBAAiB,EAAE,OAAO,CAAC;IAC3B,SAAS,EAAE,MAAM,eAAe,CAAC;IACjC,UAAU,EAAE,MAAM,oBAAoB,CAAC;IACvC,WAAW,EAAE,eAAe,CAAC;IAC7B,qBAAqB,EAAE,KAAK,CAAC,CAAC,MAAM,oBAAoB,EAAE,oBAAoB,CAAC,MAAM,oBAAoB,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;IAGzC,UAAU,IAAI,IAAI,CAAA;CACrB,CAAA;AAED,MAAM,MAAM,mBAAmB,GAAG;IAC9B,IAAI,EAAE,sBAAsB,CAAC,KAAK,CAAC;IACnC,OAAO,EAAE;QACL,SAAS,EAAE,MAAM,eAAe,CAAA;KACnC,CAAA;CACJ,CAAA;AAED,MAAM,MAAM,0BAA0B,GAAG;IACrC,IAAI,EAAE,sBAAsB,CAAC,MAAM,CAAC;IACpC,OAAO,EAAE;QACL,MAAM,EAAE,UAAU,CAAC;QACnB,UAAU,EAAE,MAAM,oBAAoB,CAAC;QACvC,WAAW,EAAE,iBAAiB,CAAA;KACjC,CAAA;CACJ,CAAA;AAED,MAAM,MAAM,eAAe,GAAG,mBAAmB,GAAG,0BAA0B,CAAA;AAE9E,MAAM,WAAW,eAAe;IAC5B,kBAAkB,CAAC,IAAI,EAAE,UAAU,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC;CAC1D"}
@@ -1,8 +1,10 @@
1
- import type { CreateStylesFactory, CustomNamedStyles, ExtractBreakpoints, RemoveKeysWithPrefix } from './types';
2
- import type { UnistylesTheme } from './types';
3
- export declare const useStyles: <ST extends CustomNamedStyles<ST>>(stylesheet?: ST | CreateStylesFactory<ST, never> | undefined) => {
4
- theme: never;
5
- breakpoint: keyof import("./global").UnistylesBreakpoints;
6
- styles: ExtractBreakpoints<RemoveKeysWithPrefix<ST>>;
1
+ import type { CreateStylesFactory, CustomNamedStyles, ReactNativeStyleSheet, UnistylesTheme } from './types';
2
+ import type { UnistylesBreakpoints } from './global';
3
+ type ParsedStylesheet<ST extends CustomNamedStyles<ST>> = {
4
+ theme: UnistylesTheme;
5
+ breakpoint: keyof UnistylesBreakpoints;
6
+ styles: ReactNativeStyleSheet<ST>;
7
7
  };
8
+ export declare const useStyles: <ST extends CustomNamedStyles<ST>>(stylesheet?: ST | CreateStylesFactory<ST, never> | undefined) => ParsedStylesheet<ST>;
9
+ export {};
8
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,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAA;AAE/G,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAE7C,eAAO,MAAM,SAAS;;;;CAsCrB,CAAA"}
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,6 +1,6 @@
1
- import type { MediaQueries } from '../types';
1
+ import type { MediaQuery } from '../types';
2
2
  import type { UnistylesBreakpoints } from '../global';
3
3
  export declare const sortAndValidateBreakpoints: (breakpoints: UnistylesBreakpoints) => UnistylesBreakpoints;
4
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 | MediaQueries, string | number | undefined>) => string | number | undefined;
5
+ export declare const getValueForBreakpoint: (value: Record<keyof UnistylesBreakpoints | MediaQuery, string | number | undefined>) => string | number | undefined;
6
6
  //# 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,YAAY,EAAE,MAAM,UAAU,CAAA;AAE5C,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAA;AAErD,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,YAAY,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC,KAAG,MAAM,GAAG,MAAM,GAAG,SAmD/I,CAAA"}
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,8 +1,8 @@
1
1
  export { normalizeStyles } from './normalizeStyles';
2
2
  export * from './normalizer';
3
- export { mq } from './mq';
3
+ export { mq, MQSymbol } from './mq';
4
+ export { getKeyForUnistylesMediaQuery } from './mqParser';
4
5
  export { getBreakpointFromScreenWidth, sortAndValidateBreakpoints, getValueForBreakpoint } from './breakpoints';
5
6
  export { proxifyFunction, parseStyle } from './styles';
6
7
  export { isServer, Orientation } from './common';
7
- export { extractValues, getKeyForCustomMediaQuery, isMediaQuery, isWithinTheHeight, isWithinTheWidth, isWithinTheWidthAndHeight } from './mediaQueries';
8
8
  //# 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,MAAM,MAAM,CAAA;AACzB,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;AAChD,OAAO,EACH,aAAa,EACb,yBAAyB,EACzB,YAAY,EACZ,iBAAiB,EACjB,gBAAgB,EAChB,yBAAyB,EAC5B,MAAM,gBAAgB,CAAA"}
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,15 +1,21 @@
1
+ import type { MediaQuery, Nullable } from '../types';
1
2
  import type { UnistylesBreakpoints } from '../global';
2
- declare const MQSymbol: unique symbol;
3
+ export declare const MQSymbol: unique symbol;
3
4
  type MQValue = keyof UnistylesBreakpoints | number;
5
+ 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;
10
+ };
4
11
  type HeightHandler = {
5
- width(wMin?: MQValue, wMax?: MQValue): typeof MQSymbol;
6
- } & typeof MQSymbol;
12
+ w(wMin?: Nullable<MQValue>, wMax?: MQValue): MediaQuery;
13
+ width(wMin?: Nullable<MQValue>, wMax?: MQValue): MediaQuery;
14
+ } & MediaQuery;
7
15
  type WidthHandler = {
8
- height(hMin?: MQValue, hMax?: MQValue): typeof MQSymbol;
9
- } & typeof MQSymbol;
10
- export declare const mq: {
11
- height: (hMin?: MQValue, hMax?: MQValue) => HeightHandler;
12
- width: (wMin?: MQValue, wMax?: MQValue) => WidthHandler;
13
- };
16
+ h(hMin?: Nullable<MQValue>, hMax?: MQValue): MediaQuery;
17
+ height(hMin?: Nullable<MQValue>, hMax?: MQValue): MediaQuery;
18
+ } & MediaQuery;
19
+ export declare const mq: MQHandler;
14
20
  export {};
15
21
  //# 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,oBAAoB,EAAE,MAAM,WAAW,CAAA;AAGrD,QAAA,MAAM,QAAQ,eAAyB,CAAA;AAEvC,KAAK,OAAO,GAAG,MAAM,oBAAoB,GAAG,MAAM,CAAA;AAElD,KAAK,aAAa,GAAG;IACjB,KAAK,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,OAAO,QAAQ,CAAA;CACzD,GAAG,OAAO,QAAQ,CAAA;AAEnB,KAAK,YAAY,GAAG;IAChB,MAAM,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,OAAO,QAAQ,CAAA;CAC1D,GAAG,OAAO,QAAQ,CAAA;AAoBnB,eAAO,MAAM,EAAE;oBACI,OAAO,SAAY,OAAO;mBAqB3B,OAAO,SAAY,OAAO;CAqB3C,CAAA"}
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;IAChB,CAAC,CAAC,IAAI,CAAC,EAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,UAAU,CAAC;IACxD,MAAM,CAAC,IAAI,CAAC,EAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,UAAU,CAAA;CAC/D,GAAG,UAAU,CAAA;AAsEd,eAAO,MAAM,EAAE,WAYb,CAAA"}
@@ -0,0 +1,3 @@
1
+ import type { NestedKeys, Optional, ScreenSize } from '../types';
2
+ export declare const getKeyForUnistylesMediaQuery: (mediaQueries: NestedKeys, screenSize: ScreenSize) => Optional<string>;
3
+ //# sourceMappingURL=mqParser.d.ts.map
@@ -0,0 +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 +1 @@
1
- {"version":3,"file":"styles.d.ts","sourceRoot":"","sources":["../../../../src/utils/styles.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAgB,UAAU,EAAE,MAAM,UAAU,CAAA;AAG3E,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,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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-unistyles",
3
- "version": "2.0.0-alpha.7",
3
+ "version": "2.0.0-alpha.8",
4
4
  "description": "Level up your React Native StyleSheet",
5
5
  "scripts": {
6
6
  "test": "jest",
package/src/common.ts ADDED
@@ -0,0 +1,18 @@
1
+ export enum CxxUnistylesEventTypes {
2
+ Theme = 'theme',
3
+ Layout = 'layout'
4
+ }
5
+
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',
13
+ }
14
+
15
+ export enum ScreenOrientation {
16
+ Portrait = 1,
17
+ Landscape = 2
18
+ }
@@ -1,5 +1,5 @@
1
- import type { UnistylesBridge, UnistylesConfig } from './types'
2
- import type { UnistylesThemes, UnistylesBreakpoints } from './global'
1
+ import type { UnistylesBridge, UnistylesConfig } from '../types'
2
+ import type { UnistylesBreakpoints, UnistylesThemes } from '../global'
3
3
 
4
4
  export class UnistyleRegistry {
5
5
  public config: UnistylesConfig = {}
@@ -1,13 +1,11 @@
1
1
  import { UnistylesModule } from './UnistylesModule'
2
2
  import { UnistylesRuntime } from './UnistylesRuntime'
3
- import { UnistylesBuiltInEngine } from './UnistylesEngine'
4
3
  import { UnistyleRegistry } from './UnistyleRegistry'
5
- import type { UnistylesBridge } from './types'
6
- import { UnistylesError } from './types'
4
+ import type { UnistylesBridge } from '../types'
5
+ import { UnistylesError } from '../common'
7
6
 
8
7
  class Unistyles {
9
8
  private _runtime: UnistylesRuntime
10
- private _engine: UnistylesBuiltInEngine
11
9
  private _registry: UnistyleRegistry
12
10
  private _bridge: UnistylesBridge
13
11
 
@@ -22,7 +20,6 @@ class Unistyles {
22
20
  this._bridge = global.__UNISTYLES__ as UnistylesBridge
23
21
  this._registry = new UnistyleRegistry(this._bridge)
24
22
  this._runtime = new UnistylesRuntime(this._bridge, this._registry)
25
- this._engine = new UnistylesBuiltInEngine(this._registry, this._runtime)
26
23
  }
27
24
 
28
25
  public get registry() {
@@ -32,10 +29,6 @@ class Unistyles {
32
29
  public get runtime() {
33
30
  return this._runtime
34
31
  }
35
-
36
- public get engine() {
37
- return this._engine
38
- }
39
32
  }
40
33
 
41
34
  export const unistyles = new Unistyles()
@@ -1,7 +1,7 @@
1
- import type { UnistylesBridge } from './types'
1
+ import { ScreenOrientation, UnistylesError } from '../common'
2
+ import type { UnistylesBridge } from '../types'
3
+ import type { UnistylesThemes } from '../global'
2
4
  import type { UnistyleRegistry } from './UnistyleRegistry'
3
- import { ScreenOrientation, UnistylesError } from './types'
4
- import type { UnistylesThemes } from './global'
5
5
 
6
6
  export class UnistylesRuntime {
7
7
  constructor(private unistylesBridge: UnistylesBridge, private registry: UnistyleRegistry) {}
@@ -0,0 +1 @@
1
+ export { unistyles } from './Unistyles'
@@ -1 +1,2 @@
1
- export { useDimensions } from './useDimensions'
1
+ export { useInitialTheme } from './useInitialTheme'
2
+ export { useUnistyles } from './useUnistyles'
@@ -1,6 +1,6 @@
1
1
  import { useMemo } from 'react'
2
- import { unistyles } from './Unistyles'
3
- import type { UnistylesThemes } from './global'
2
+ import { unistyles } from '../core'
3
+ import type { UnistylesThemes } from '../global'
4
4
 
5
5
  export const useInitialTheme = (forName: keyof UnistylesThemes) => {
6
6
  useMemo(() => unistyles.runtime.setTheme(forName), [])
@@ -0,0 +1,55 @@
1
+ import { NativeEventEmitter, NativeModules } from 'react-native'
2
+ import { useEffect, useState } from 'react'
3
+ import { unistyles } from '../core'
4
+ import { CxxUnistylesEventTypes } from '../common'
5
+ import type { UnistylesEvents, UnistylesMobileLayoutEvent, UnistylesThemeEvent } from '../types'
6
+
7
+ const unistylesEvents = new NativeEventEmitter(NativeModules.Unistyles)
8
+
9
+ export const useUnistyles = () => {
10
+ const [theme, setTheme] = useState(unistyles.runtime.getTheme(unistyles.runtime.themeName))
11
+ const [layout, setLayout] = useState({
12
+ breakpoint: unistyles.runtime.breakpoint,
13
+ orientation: unistyles.runtime.orientation,
14
+ screenSize: {
15
+ width: unistyles.runtime.screen.width,
16
+ height: unistyles.runtime.screen.height
17
+ }
18
+ })
19
+
20
+ useEffect(() => {
21
+ const subscription = unistylesEvents.addListener(
22
+ 'onChange',
23
+ (event: UnistylesEvents) => {
24
+ switch (event.type) {
25
+ case CxxUnistylesEventTypes.Theme: {
26
+ const themeEvent = event as UnistylesThemeEvent
27
+
28
+ return setTheme(unistyles.runtime.getTheme(themeEvent.payload.themeName))
29
+ }
30
+ case CxxUnistylesEventTypes.Layout: {
31
+ const layoutEvent = event as UnistylesMobileLayoutEvent
32
+
33
+ return setLayout({
34
+ breakpoint: layoutEvent.payload.breakpoint,
35
+ orientation: layoutEvent.payload.orientation,
36
+ screenSize: {
37
+ width: layoutEvent.payload.screen.width,
38
+ height: layoutEvent.payload.screen.height
39
+ }
40
+ })
41
+ }
42
+ default:
43
+ return
44
+ }
45
+ }
46
+ )
47
+
48
+ return subscription.remove
49
+ }, [])
50
+
51
+ return {
52
+ theme,
53
+ layout
54
+ }
55
+ }
package/src/index.ts CHANGED
@@ -1,12 +1,10 @@
1
- import { unistyles } from './Unistyles'
1
+ import { unistyles } from './core'
2
+ import { mq } from './utils'
3
+ import { useInitialTheme } from './hooks'
2
4
  import type { UnistylesThemes, UnistylesBreakpoints } from './global'
3
- import { ScreenOrientation } from './types'
4
-
5
- export { mq } from './utils'
6
- export { useInitialTheme } from './useInitialTheme'
7
-
8
- export { useStyles } from './useStyles'
9
- export { createStyleSheet } from './createStyleSheet'
5
+ import { ScreenOrientation } from './common'
6
+ import { useStyles } from './useStyles'
7
+ import { createStyleSheet } from './createStyleSheet'
10
8
 
11
9
  const { addThemes, addBreakpoints, addConfig } = unistyles.registry
12
10
  const UnistylesRuntime = unistyles.runtime
@@ -24,6 +22,10 @@ export {
24
22
  }
25
23
 
26
24
  export {
25
+ mq,
26
+ useInitialTheme,
27
+ useStyles,
28
+ createStyleSheet,
27
29
  ScreenOrientation
28
30
  }
29
31
 
@@ -1,17 +1,10 @@
1
1
  import type { OpaqueColorValue } from 'react-native'
2
2
  import type { UnistylesBreakpoints } from '../global'
3
- import type { MediaQueries } from './mediaQueries'
4
-
5
- export type ScreenSize = {
6
- width: number,
7
- height: number
8
- }
9
-
10
- export type CreateStylesFactory<ST, Theme> = (theme: Theme) => ST
3
+ import type { MediaQuery } from './mq'
11
4
 
12
5
  type WithEmptyObject<V> = keyof V extends never ? {} : V
13
6
 
14
- export type ExtractBreakpoints<T> = T extends Partial<Record<keyof UnistylesBreakpoints & string, infer V>>
7
+ type ExtractBreakpoints<T> = T extends Partial<Record<keyof UnistylesBreakpoints & string, infer V>>
15
8
  ? WithEmptyObject<V>
16
9
  : T extends (...args: infer A) => infer R
17
10
  ? (...args: A) => ExtractBreakpoints<R>
@@ -23,12 +16,14 @@ export type ExtractBreakpoints<T> = T extends Partial<Record<keyof UnistylesBrea
23
16
  : T[K]
24
17
  }
25
18
 
26
- export type RemoveKeysWithPrefix<T> = T extends (...args: Array<any>) => infer R
19
+ type RemoveKeysWithPrefix<T> = T extends (...args: Array<any>) => infer R
27
20
  ? (...args: Parameters<T>) => RemoveKeysWithPrefix<R>
28
21
  : T extends object
29
22
  ? T extends OpaqueColorValue
30
23
  ? string
31
24
  : T extends Record<string, infer _V>
32
- ? { [K in keyof T as K extends MediaQueries ? keyof UnistylesBreakpoints & string : K]: RemoveKeysWithPrefix<T[K]> }
25
+ ? { [K in keyof T as K extends MediaQuery ? keyof UnistylesBreakpoints & string : K]: RemoveKeysWithPrefix<T[K]> }
33
26
  : { [K in keyof T]: RemoveKeysWithPrefix<T[K]> }
34
27
  : T
28
+
29
+ export type ReactNativeStyleSheet<T> = ExtractBreakpoints<RemoveKeysWithPrefix<T>>
@@ -0,0 +1,2 @@
1
+ export type Optional<T> = T | undefined
2
+ export type Nullable<T> = T | null
package/src/types/core.ts CHANGED
@@ -14,14 +14,19 @@ import type {
14
14
  TranslateYTransform
15
15
  } from 'react-native/Libraries/StyleSheet/StyleSheetTypes'
16
16
  import type { ImageStyle, TextStyle, ViewStyle } from 'react-native'
17
- import type { MediaQueries } from './mediaQueries'
18
17
  import type { UnistylesBreakpoints, UnistylesThemes } from '../global'
18
+ import type { MediaQuery } from './mq'
19
19
 
20
20
  type ShadowOffset = {
21
21
  width: number,
22
22
  height: number
23
23
  }
24
24
 
25
+ export type ScreenSize = {
26
+ width: number,
27
+ height: number
28
+ }
29
+
25
30
  type TransformStyles =
26
31
  & PerpectiveTransform
27
32
  & RotateTransform
@@ -44,9 +49,9 @@ type UnistyleNested = {
44
49
  }
45
50
 
46
51
  type UniStyle<V> = {
47
- [innerKey in keyof UnistylesBreakpoints]: V
52
+ [innerKey in keyof UnistylesBreakpoints]?: V
48
53
  } | {
49
- [innerKey in MediaQueries]: V
54
+ [innerKey in MediaQuery]: V
50
55
  }
51
56
 
52
57
  type DeepUniStyle<T> = {
@@ -72,5 +77,6 @@ export type CustomNamedStyles<T> = {
72
77
  : StaticStyles
73
78
  }
74
79
 
75
- export type NestedKeys = Array<[keyof UnistylesBreakpoints | MediaQueries, string | number | undefined]>
80
+ export type NestedKeys = Array<[keyof UnistylesBreakpoints | MediaQuery, string | number | undefined]>
76
81
  export type UnistylesTheme = UnistylesThemes[keyof UnistylesThemes]
82
+ export type CreateStylesFactory<ST, Theme> = (theme: Theme) => ST
@@ -1,10 +1,6 @@
1
1
  export * from './normalizer'
2
- export * from './cxx'
3
- export type { CustomNamedStyles, NestedKeys, UnistylesTheme } from './core'
4
- export type { MediaQueries } from './mediaQueries'
5
- export type {
6
- ScreenSize,
7
- CreateStylesFactory,
8
- ExtractBreakpoints,
9
- RemoveKeysWithPrefix
10
- } from './breakpoints'
2
+ export * from './unistyles'
3
+ export type { Optional, Nullable } from './common'
4
+ export type { MediaQuery } from './mq'
5
+ export type { CustomNamedStyles, NestedKeys, UnistylesTheme, CreateStylesFactory, ScreenSize } from './core'
6
+ export type { ReactNativeStyleSheet } from './breakpoints'
@@ -0,0 +1,3 @@
1
+ import { MQSymbol } from '../utils'
2
+
3
+ export type MediaQuery = typeof MQSymbol
@@ -1,20 +1,14 @@
1
+ import { CxxUnistylesEventTypes, ScreenOrientation } from '../common'
1
2
  import type { UnistylesThemes, UnistylesBreakpoints } from '../global'
2
- import type { ScreenSize } from './breakpoints'
3
- import type { NestedKeys } from './core'
3
+ import type { NestedKeys, ScreenSize } from './core'
4
+ import type { Optional } from './common'
4
5
 
5
- export type Optional<T> = T | undefined
6
- export type Nullable<T> = T | null
7
6
  export type ColorSchemeName = Optional<'light' | 'dark'>
8
7
 
9
8
  export type UnistylesConfig = {
10
9
  adaptiveThemes?: boolean
11
10
  }
12
11
 
13
- export enum ScreenOrientation {
14
- Portrait = 1,
15
- Landscape = 2
16
- }
17
-
18
12
  export type UnistylesBridge = {
19
13
  // getters
20
14
  screenWidth: number,
@@ -35,11 +29,6 @@ export type UnistylesBridge = {
35
29
  unregister(): void
36
30
  }
37
31
 
38
- export enum CxxUnistylesEventTypes {
39
- Theme = 'theme',
40
- Layout = 'layout'
41
- }
42
-
43
32
  export type UnistylesThemeEvent = {
44
33
  type: CxxUnistylesEventTypes.Theme,
45
34
  payload: {
@@ -58,16 +47,6 @@ export type UnistylesMobileLayoutEvent = {
58
47
 
59
48
  export type UnistylesEvents = UnistylesThemeEvent | UnistylesMobileLayoutEvent
60
49
 
61
- export enum UnistylesError {
62
- RuntimeUnavailable = 'UNISTYLES_ERROR_RUNTIME_UNAVAILABLE',
63
- ThemeNotFound = 'UNISTYLES_ERROR_THEME_NOT_FOUND',
64
- ThemeNotRegistered = 'UNISTYLES_ERROR_THEME_NOT_REGISTERED',
65
- ThemesCannotBeEmpty = 'UNISTYLES_ERROR_THEMES_CANNOT_BE_EMPTY',
66
- BreakpointsCannotBeEmpty = 'UNISTYLES_ERROR_BREAKPOINTS_CANNOT_BE_EMPTY',
67
- BreakpointsMustStartFromZero = 'UNISTYLES_ERROR_BREAKPOINTS_MUST_START_FROM_ZERO',
68
- }
69
-
70
50
  export interface UnistylesEngine {
71
- isMediaQuery(key: string): boolean,
72
51
  didMatchMediaQuery(keys: NestedKeys): Optional<string>,
73
52
  }
package/src/useStyles.ts CHANGED
@@ -1,18 +1,25 @@
1
1
  import { useMemo } from 'react'
2
2
  import { StyleSheet } from 'react-native'
3
3
  import { parseStyle, proxifyFunction } from './utils'
4
- import type { CreateStylesFactory, CustomNamedStyles, ExtractBreakpoints, RemoveKeysWithPrefix } from './types'
5
- import { useUnistyles } from './useUnistyles'
6
- import type { UnistylesTheme } from './types'
4
+ import type { CreateStylesFactory, CustomNamedStyles, ReactNativeStyleSheet, UnistylesTheme } from './types'
5
+ import { useUnistyles } from './hooks'
6
+ import type { UnistylesBreakpoints } from './global'
7
7
 
8
- export const useStyles = <ST extends CustomNamedStyles<ST>>(stylesheet?: ST | CreateStylesFactory<ST, UnistylesTheme>) => {
9
- const { theme, breakpoint, screenSize } = useUnistyles()
8
+ type ParsedStylesheet<ST extends CustomNamedStyles<ST>> = {
9
+ theme: UnistylesTheme,
10
+ breakpoint: keyof UnistylesBreakpoints,
11
+ styles: ReactNativeStyleSheet<ST>
12
+ }
13
+
14
+ export const useStyles = <ST extends CustomNamedStyles<ST>>(stylesheet?: ST | CreateStylesFactory<ST, UnistylesTheme>): ParsedStylesheet<ST> => {
15
+ const { theme, layout } = useUnistyles()
16
+ const { screenSize, breakpoint } = layout
10
17
 
11
18
  if (!stylesheet) {
12
19
  return {
13
20
  theme,
14
21
  breakpoint,
15
- styles: {} as ExtractBreakpoints<RemoveKeysWithPrefix<ST>>
22
+ styles: {} as ReactNativeStyleSheet<ST>
16
23
  }
17
24
  }
18
25
 
@@ -36,11 +43,11 @@ export const useStyles = <ST extends CustomNamedStyles<ST>>(stylesheet?: ST | Cr
36
43
  ...acc,
37
44
  [key]: parseStyle<ST>(style, breakpoint, screenSize)
38
45
  })
39
- }, {} as ST), [breakpoint, screenSize, parsedStyles])
46
+ }, {} as ST), [breakpoint, screenSize, parsedStyles]) as ReactNativeStyleSheet<ST>
40
47
 
41
48
  return {
42
49
  theme,
43
50
  breakpoint,
44
- styles: dynamicStyleSheet as ExtractBreakpoints<RemoveKeysWithPrefix<ST>>
51
+ styles: dynamicStyleSheet
45
52
  }
46
53
  }
@@ -1,8 +1,9 @@
1
- import { unistyles } from '../Unistyles'
1
+ import { unistyles } from '../core'
2
2
  import { isMobile, Orientation, throwError } from './common'
3
- import type { MediaQueries } from '../types'
4
- import { ScreenOrientation } from '../types'
3
+ import type { MediaQuery, NestedKeys } from '../types'
5
4
  import type { UnistylesBreakpoints } from '../global'
5
+ import { ScreenOrientation } from '../common'
6
+ import { getKeyForUnistylesMediaQuery } from './mqParser'
6
7
 
7
8
  export const sortAndValidateBreakpoints = (breakpoints: UnistylesBreakpoints): UnistylesBreakpoints => {
8
9
  const sortedPairs = Object
@@ -45,15 +46,14 @@ export const getBreakpointFromScreenWidth = (width: number, breakpointEntries: A
45
46
  return key
46
47
  }
47
48
 
48
- export const getValueForBreakpoint = (value: Record<keyof UnistylesBreakpoints | MediaQueries, string | number | undefined>): string | number | undefined => {
49
+ export const getValueForBreakpoint = (value: Record<keyof UnistylesBreakpoints | MediaQuery, string | number | undefined>): string | number | undefined => {
49
50
  // the highest priority is for custom media queries
50
- const customMediaQueries = Object
51
- .entries(value)
52
- .filter(([key]) => unistyles.engine.isMediaQuery(key)) as Array<[keyof UnistylesBreakpoints | MediaQueries, string | number | undefined]>
53
- // const customMediaQueryKey = getKeyForCustomMediaQuery(customMediaQueries, screenSize) as keyof typeof value
54
- const customMediaQueryKey = unistyles.engine.didMatchMediaQuery(customMediaQueries) as keyof typeof value
51
+ const customMediaQueryKey = getKeyForUnistylesMediaQuery(
52
+ Object.entries(value) as NestedKeys,
53
+ unistyles.runtime.screen
54
+ ) as keyof typeof value
55
55
 
56
- if (customMediaQueryKey && customMediaQueryKey in value) {
56
+ if (customMediaQueryKey) {
57
57
  return value[customMediaQueryKey]
58
58
  }
59
59
 
@@ -61,8 +61,8 @@ export const getValueForBreakpoint = (value: Record<keyof UnistylesBreakpoints |
61
61
  // check if user defined any breakpoints
62
62
  const hasBreakpoints = unistyles.runtime.sortedBreakpoints.length > 0
63
63
 
64
- // if not then we can fallback to horizontal and portrait (mobile only)
65
- if (!hasBreakpoints && isMobile && (Orientation.Landscape in value || Orientation.Portrait in value)) {
64
+ // if not then we can fall back to horizontal and portrait (mobile only)
65
+ if (!hasBreakpoints && isMobile && (Orientation.Landscape in value || Orientation.Portrait in value)) {
66
66
  return value[
67
67
  unistyles.runtime.orientation === ScreenOrientation.Portrait
68
68
  ? Orientation.Portrait
@@ -70,6 +70,7 @@ export const getValueForBreakpoint = (value: Record<keyof UnistylesBreakpoints |
70
70
  ]
71
71
  }
72
72
 
73
+ // let's get the current breakpoint
73
74
  const breakpoint = unistyles.runtime.breakpoint
74
75
 
75
76
  if (!breakpoint) {
@@ -1,14 +1,7 @@
1
1
  export { normalizeStyles } from './normalizeStyles'
2
2
  export * from './normalizer'
3
- export { mq } from './mq'
3
+ export { mq, MQSymbol } from './mq'
4
+ export { getKeyForUnistylesMediaQuery } from './mqParser'
4
5
  export { getBreakpointFromScreenWidth, sortAndValidateBreakpoints, getValueForBreakpoint } from './breakpoints'
5
6
  export { proxifyFunction, parseStyle } from './styles'
6
7
  export { isServer, Orientation } from './common'
7
- export {
8
- extractValues,
9
- getKeyForCustomMediaQuery,
10
- isMediaQuery,
11
- isWithinTheHeight,
12
- isWithinTheWidth,
13
- isWithinTheWidthAndHeight
14
- } from './mediaQueries'