react-native-unistyles 2.0.0-alpha.1 → 2.0.0-alpha.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (193) hide show
  1. package/README.md +4 -4
  2. package/ios/UnistylesModule.h +10 -0
  3. package/ios/UnistylesModule.mm +108 -0
  4. package/ios/UnistylesRuntime.h +30 -0
  5. package/ios/UnistylesRuntime.mm +191 -0
  6. package/lib/commonjs/UnistyleRegistry.js +37 -0
  7. package/lib/commonjs/UnistyleRegistry.js.map +1 -0
  8. package/lib/commonjs/Unistyles.js +36 -0
  9. package/lib/commonjs/Unistyles.js.map +1 -0
  10. package/lib/commonjs/UnistylesEngine.js +22 -0
  11. package/lib/commonjs/UnistylesEngine.js.map +1 -0
  12. package/lib/commonjs/UnistylesModule.js +9 -0
  13. package/lib/commonjs/UnistylesModule.js.map +1 -0
  14. package/lib/commonjs/UnistylesRuntime.js +52 -0
  15. package/lib/commonjs/UnistylesRuntime.js.map +1 -0
  16. package/lib/commonjs/createStyleSheet.js +14 -0
  17. package/lib/commonjs/createStyleSheet.js.map +1 -0
  18. package/lib/commonjs/global.js +2 -0
  19. package/lib/commonjs/global.js.map +1 -0
  20. package/lib/commonjs/hooks/useDimensions.web.js +3 -2
  21. package/lib/commonjs/hooks/useDimensions.web.js.map +1 -1
  22. package/lib/commonjs/index.js +33 -6
  23. package/lib/commonjs/index.js.map +1 -1
  24. package/lib/commonjs/types/cxx.js +23 -0
  25. package/lib/commonjs/types/cxx.js.map +1 -0
  26. package/lib/commonjs/types/index.js +26 -0
  27. package/lib/commonjs/types/index.js.map +1 -1
  28. package/lib/commonjs/types/normalizer.js +6 -0
  29. package/lib/commonjs/types/normalizer.js.map +1 -0
  30. package/lib/commonjs/useInitialTheme.js +13 -0
  31. package/lib/commonjs/useInitialTheme.js.map +1 -0
  32. package/lib/commonjs/useStyles.js +48 -0
  33. package/lib/commonjs/useStyles.js.map +1 -0
  34. package/lib/commonjs/useUnistyles.js +59 -0
  35. package/lib/commonjs/useUnistyles.js.map +1 -0
  36. package/lib/commonjs/utils/breakpoints.js +4 -2
  37. package/lib/commonjs/utils/breakpoints.js.map +1 -1
  38. package/lib/commonjs/utils/common.js +3 -3
  39. package/lib/commonjs/utils/common.js.map +1 -1
  40. package/lib/commonjs/utils/index.js +34 -0
  41. package/lib/commonjs/utils/index.js.map +1 -1
  42. package/lib/commonjs/utils/module.d.js +2 -0
  43. package/lib/commonjs/utils/module.d.js.map +1 -0
  44. package/lib/commonjs/utils/normalizeStyles.web.js +13 -13
  45. package/lib/commonjs/utils/normalizeStyles.web.js.map +1 -1
  46. package/lib/commonjs/utils/normalizer.js +89 -0
  47. package/lib/commonjs/utils/normalizer.js.map +1 -0
  48. package/lib/commonjs/utils/styles.js +7 -7
  49. package/lib/commonjs/utils/styles.js.map +1 -1
  50. package/lib/module/UnistyleRegistry.js +30 -0
  51. package/lib/module/UnistyleRegistry.js.map +1 -0
  52. package/lib/module/Unistyles.js +30 -0
  53. package/lib/module/Unistyles.js.map +1 -0
  54. package/lib/module/UnistylesEngine.js +15 -0
  55. package/lib/module/UnistylesEngine.js.map +1 -0
  56. package/lib/module/UnistylesModule.js +3 -0
  57. package/lib/module/UnistylesModule.js.map +1 -0
  58. package/lib/module/UnistylesRuntime.js +45 -0
  59. package/lib/module/UnistylesRuntime.js.map +1 -0
  60. package/lib/module/createStyleSheet.js +7 -0
  61. package/lib/module/createStyleSheet.js.map +1 -0
  62. package/lib/module/global.js +2 -0
  63. package/lib/module/global.js.map +1 -0
  64. package/lib/module/hooks/useDimensions.web.js +3 -2
  65. package/lib/module/hooks/useDimensions.web.js.map +1 -1
  66. package/lib/module/index.js +18 -2
  67. package/lib/module/index.js.map +1 -1
  68. package/lib/module/types/cxx.js +17 -0
  69. package/lib/module/types/cxx.js.map +1 -0
  70. package/lib/module/types/index.js +2 -1
  71. package/lib/module/types/index.js.map +1 -1
  72. package/lib/module/types/normalizer.js +2 -0
  73. package/lib/module/types/normalizer.js.map +1 -0
  74. package/lib/module/useInitialTheme.js +6 -0
  75. package/lib/module/useInitialTheme.js.map +1 -0
  76. package/lib/module/useStyles.js +42 -0
  77. package/lib/module/useStyles.js.map +1 -0
  78. package/lib/module/useUnistyles.js +52 -0
  79. package/lib/module/useUnistyles.js.map +1 -0
  80. package/lib/module/utils/breakpoints.js +4 -3
  81. package/lib/module/utils/breakpoints.js.map +1 -1
  82. package/lib/module/utils/common.js +2 -1
  83. package/lib/module/utils/common.js.map +1 -1
  84. package/lib/module/utils/index.js +2 -0
  85. package/lib/module/utils/index.js.map +1 -1
  86. package/lib/module/utils/module.d.js +2 -0
  87. package/lib/module/utils/module.d.js.map +1 -0
  88. package/lib/module/utils/normalizeStyles.web.js +13 -13
  89. package/lib/module/utils/normalizeStyles.web.js.map +1 -1
  90. package/lib/module/utils/normalizer.js +79 -0
  91. package/lib/module/utils/normalizer.js.map +1 -0
  92. package/lib/module/utils/styles.js +7 -8
  93. package/lib/module/utils/styles.js.map +1 -1
  94. package/lib/typescript/examples/expo/src/App.d.ts +3 -0
  95. package/lib/typescript/examples/expo/src/App.d.ts.map +1 -0
  96. package/lib/typescript/examples/expo/src/examples/Cxx.d.ts +3 -0
  97. package/lib/typescript/examples/expo/src/examples/Cxx.d.ts.map +1 -0
  98. package/lib/typescript/examples/expo/src/examples/index.d.ts +2 -0
  99. package/lib/typescript/examples/expo/src/examples/index.d.ts.map +1 -0
  100. package/lib/typescript/examples/expo/src/index.d.ts +2 -0
  101. package/lib/typescript/examples/expo/src/index.d.ts.map +1 -0
  102. package/lib/typescript/examples/expo/src/styles/breakpoints.d.ts +8 -0
  103. package/lib/typescript/examples/expo/src/styles/breakpoints.d.ts.map +1 -0
  104. package/lib/typescript/examples/expo/src/styles/index.d.ts +16 -0
  105. package/lib/typescript/examples/expo/src/styles/index.d.ts.map +1 -0
  106. package/lib/typescript/examples/expo/src/styles/theme.d.ts +40 -0
  107. package/lib/typescript/examples/expo/src/styles/theme.d.ts.map +1 -0
  108. package/lib/typescript/src/UnistyleRegistry.d.ts +15 -0
  109. package/lib/typescript/src/UnistyleRegistry.d.ts.map +1 -0
  110. package/lib/typescript/src/Unistyles.d.ts +16 -0
  111. package/lib/typescript/src/Unistyles.d.ts.map +1 -0
  112. package/lib/typescript/src/UnistylesEngine.d.ts +8 -0
  113. package/lib/typescript/src/UnistylesEngine.d.ts.map +1 -0
  114. package/lib/typescript/src/UnistylesModule.d.ts +6 -0
  115. package/lib/typescript/src/UnistylesModule.d.ts.map +1 -0
  116. package/lib/typescript/src/UnistylesRuntime.d.ts +56 -0
  117. package/lib/typescript/src/UnistylesRuntime.d.ts.map +1 -0
  118. package/lib/typescript/src/createStyleSheet.d.ts +6 -0
  119. package/lib/typescript/src/createStyleSheet.d.ts.map +1 -0
  120. package/lib/typescript/src/global.d.ts +5 -0
  121. package/lib/typescript/src/global.d.ts.map +1 -0
  122. package/lib/typescript/src/hooks/useDimensions.web.d.ts.map +1 -1
  123. package/lib/typescript/src/index.d.ts +14 -2
  124. package/lib/typescript/src/index.d.ts.map +1 -1
  125. package/lib/typescript/src/types/breakpoints.d.ts +6 -7
  126. package/lib/typescript/src/types/breakpoints.d.ts.map +1 -1
  127. package/lib/typescript/src/types/core.d.ts +4 -4
  128. package/lib/typescript/src/types/core.d.ts.map +1 -1
  129. package/lib/typescript/src/types/cxx.d.ts +50 -0
  130. package/lib/typescript/src/types/cxx.d.ts.map +1 -0
  131. package/lib/typescript/src/types/index.d.ts +4 -1
  132. package/lib/typescript/src/types/index.d.ts.map +1 -1
  133. package/lib/typescript/src/types/normalizer.d.ts +20 -0
  134. package/lib/typescript/src/types/normalizer.d.ts.map +1 -0
  135. package/lib/typescript/src/useInitialTheme.d.ts +3 -0
  136. package/lib/typescript/src/useInitialTheme.d.ts.map +1 -0
  137. package/lib/typescript/src/useStyles.d.ts +46 -0
  138. package/lib/typescript/src/useStyles.d.ts.map +1 -0
  139. package/lib/typescript/src/useUnistyles.d.ts +45 -0
  140. package/lib/typescript/src/useUnistyles.d.ts.map +1 -0
  141. package/lib/typescript/src/utils/breakpoints.d.ts +5 -4
  142. package/lib/typescript/src/utils/breakpoints.d.ts.map +1 -1
  143. package/lib/typescript/src/utils/common.d.ts +2 -1
  144. package/lib/typescript/src/utils/common.d.ts.map +1 -1
  145. package/lib/typescript/src/utils/index.d.ts +2 -0
  146. package/lib/typescript/src/utils/index.d.ts.map +1 -1
  147. package/lib/typescript/src/utils/normalizeStyles.web.d.ts +4 -1
  148. package/lib/typescript/src/utils/normalizeStyles.web.d.ts.map +1 -1
  149. package/lib/typescript/src/utils/normalizer.d.ts +11 -0
  150. package/lib/typescript/src/utils/normalizer.d.ts.map +1 -0
  151. package/lib/typescript/src/utils/styles.d.ts +4 -3
  152. package/lib/typescript/src/utils/styles.d.ts.map +1 -1
  153. package/package.json +13 -3
  154. package/react-native-unistyles.podspec +21 -0
  155. package/src/UnistyleRegistry.ts +39 -0
  156. package/src/Unistyles.ts +41 -0
  157. package/src/UnistylesEngine.ts +15 -0
  158. package/src/UnistylesModule.ts +7 -0
  159. package/src/UnistylesRuntime.ts +58 -0
  160. package/src/createStyleSheet.ts +12 -0
  161. package/src/global.ts +2 -0
  162. package/src/hooks/useDimensions.web.ts +3 -2
  163. package/src/index.ts +30 -2
  164. package/src/types/breakpoints.ts +9 -11
  165. package/src/types/core.ts +6 -6
  166. package/src/types/cxx.ts +61 -0
  167. package/src/types/index.ts +4 -3
  168. package/src/types/normalizer.ts +29 -0
  169. package/src/useInitialTheme.ts +7 -0
  170. package/src/useStyles.ts +49 -0
  171. package/src/useUnistyles.ts +67 -0
  172. package/src/utils/breakpoints.ts +16 -14
  173. package/src/utils/common.ts +2 -1
  174. package/src/utils/index.ts +2 -0
  175. package/src/utils/module.d.ts +3 -0
  176. package/src/utils/normalizeStyles.web.ts +21 -42
  177. package/src/utils/normalizer.ts +99 -0
  178. package/src/utils/styles.ts +17 -19
  179. package/lib/commonjs/UnistylesTheme.js +0 -21
  180. package/lib/commonjs/UnistylesTheme.js.map +0 -1
  181. package/lib/commonjs/createUnistyles.js +0 -57
  182. package/lib/commonjs/createUnistyles.js.map +0 -1
  183. package/lib/module/UnistylesTheme.js +0 -12
  184. package/lib/module/UnistylesTheme.js.map +0 -1
  185. package/lib/module/createUnistyles.js +0 -50
  186. package/lib/module/createUnistyles.js.map +0 -1
  187. package/lib/typescript/src/UnistylesTheme.d.ts +0 -9
  188. package/lib/typescript/src/UnistylesTheme.d.ts.map +0 -1
  189. package/lib/typescript/src/createUnistyles.d.ts +0 -10
  190. package/lib/typescript/src/createUnistyles.d.ts.map +0 -1
  191. package/src/UnistylesTheme.tsx +0 -17
  192. package/src/__tests__/createUnistyles.spec.tsx +0 -192
  193. package/src/createUnistyles.ts +0 -70
@@ -0,0 +1,3 @@
1
+ import type { UnistylesThemes } from './global';
2
+ export declare const useInitialTheme: (forName: keyof UnistylesThemes) => void;
3
+ //# sourceMappingURL=useInitialTheme.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useInitialTheme.d.ts","sourceRoot":"","sources":["../../../src/useInitialTheme.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAE/C,eAAO,MAAM,eAAe,YAAa,MAAM,eAAe,SAE7D,CAAA"}
@@ -0,0 +1,46 @@
1
+ import type { CreateStylesFactory, CustomNamedStyles, ExtractBreakpoints, RemoveKeysWithPrefix } from './types';
2
+ import type { UnistylesThemes } from './global';
3
+ type T = UnistylesThemes[keyof UnistylesThemes];
4
+ export declare const useStyles: <ST extends CustomNamedStyles<ST>>(stylesheet?: ST | CreateStylesFactory<ST, T> | undefined) => {
5
+ theme: {
6
+ colors: {
7
+ backgroundColor: string;
8
+ typography: string;
9
+ accent: string;
10
+ barbie: string;
11
+ oak: string;
12
+ sky: string;
13
+ fog: string;
14
+ aloes: string;
15
+ blood: string;
16
+ };
17
+ } | {
18
+ colors: {
19
+ backgroundColor: string;
20
+ typography: string;
21
+ accent: string;
22
+ barbie: string;
23
+ oak: string;
24
+ sky: string;
25
+ fog: string;
26
+ aloes: string;
27
+ blood: string;
28
+ };
29
+ } | {
30
+ colors: {
31
+ backgroundColor: string;
32
+ typography: string;
33
+ accent: string;
34
+ barbie: string;
35
+ oak: string;
36
+ sky: string;
37
+ fog: string;
38
+ aloes: string;
39
+ blood: string;
40
+ };
41
+ };
42
+ breakpoint: "xs" | "sm" | "md" | "lg" | "xl";
43
+ styles: ExtractBreakpoints<RemoveKeysWithPrefix<ST>>;
44
+ };
45
+ export {};
46
+ //# sourceMappingURL=useStyles.d.ts.map
@@ -0,0 +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,eAAe,EAAE,MAAM,UAAU,CAAA;AAG/C,KAAK,CAAC,GAAG,eAAe,CAAC,MAAM,eAAe,CAAC,CAAA;AAE/C,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAsCrB,CAAA"}
@@ -0,0 +1,45 @@
1
+ export declare const useUnistyles: () => {
2
+ theme: {
3
+ colors: {
4
+ backgroundColor: string;
5
+ typography: string;
6
+ accent: string;
7
+ barbie: string;
8
+ oak: string;
9
+ sky: string;
10
+ fog: string;
11
+ aloes: string;
12
+ blood: string;
13
+ };
14
+ } | {
15
+ colors: {
16
+ backgroundColor: string;
17
+ typography: string;
18
+ accent: string;
19
+ barbie: string;
20
+ oak: string;
21
+ sky: string;
22
+ fog: string;
23
+ aloes: string;
24
+ blood: string;
25
+ };
26
+ } | {
27
+ colors: {
28
+ backgroundColor: string;
29
+ typography: string;
30
+ accent: string;
31
+ barbie: string;
32
+ oak: string;
33
+ sky: string;
34
+ fog: string;
35
+ aloes: string;
36
+ blood: string;
37
+ };
38
+ };
39
+ breakpoint: "xs" | "sm" | "md" | "lg" | "xl";
40
+ screenSize: {
41
+ width: number;
42
+ height: number;
43
+ };
44
+ };
45
+ //# sourceMappingURL=useUnistyles.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useUnistyles.d.ts","sourceRoot":"","sources":["../../../src/useUnistyles.ts"],"names":[],"mappings":"AAaA,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAqDxB,CAAA"}
@@ -1,4 +1,5 @@
1
- import type { Breakpoints, ScreenSize, SortedBreakpointEntries } from '../types';
1
+ import type { ScreenSize, MediaQueries } from '../types';
2
+ import type { UnistylesBreakpoints } from '../global';
2
3
  /**
3
4
  * Sorts the breakpoints object based on its numeric values in ascending order and validates them.
4
5
  *
@@ -18,7 +19,7 @@ import type { Breakpoints, ScreenSize, SortedBreakpointEntries } from '../types'
18
19
  * const input = { md: 768, lg: 1024, sm: 0 }
19
20
  * sortAndValidateBreakpoints(input) // returns { sm: 0, md: 768, lg: 1024 }
20
21
  */
21
- export declare const sortAndValidateBreakpoints: <B extends Breakpoints>(breakpoints: B) => B;
22
+ export declare const sortAndValidateBreakpoints: (breakpoints: UnistylesBreakpoints) => UnistylesBreakpoints;
22
23
  /**
23
24
  * Determines the appropriate breakpoint key for a given screen width based on provided breakpoints.
24
25
  *
@@ -34,7 +35,7 @@ export declare const sortAndValidateBreakpoints: <B extends Breakpoints>(breakpo
34
35
  * const breakpoints = { sm: 0, md: 768, lg: 1024 }
35
36
  * getBreakpointFromScreenWidth(800, breakpoints) // returns 'md'
36
37
  */
37
- export declare const getBreakpointFromScreenWidth: <B extends Breakpoints>(width: number, breakpointEntries: SortedBreakpointEntries<B>) => keyof B & string;
38
+ export declare const getBreakpointFromScreenWidth: (width: number, breakpointEntries: Array<[keyof UnistylesBreakpoints, UnistylesBreakpoints[keyof UnistylesBreakpoints]]>) => keyof UnistylesBreakpoints & string;
38
39
  /**
39
40
  * Retrieves the value associated with a given breakpoint or custom media query based on the provided screen size.
40
41
  *
@@ -59,5 +60,5 @@ export declare const getBreakpointFromScreenWidth: <B extends Breakpoints>(width
59
60
  *
60
61
  * getValueForBreakpoint(values, 'sm', screenSize, breakpoints); // 'value1'
61
62
  */
62
- export declare const getValueForBreakpoint: <B extends Breakpoints>(value: Record<keyof B & string, string | number | undefined>, breakpoint: keyof B & string, screenSize: ScreenSize, breakpointPairs: SortedBreakpointEntries<B>) => string | number | undefined;
63
+ export declare const getValueForBreakpoint: (value: Record<keyof UnistylesBreakpoints | MediaQueries, string | number | undefined>, breakpoint: keyof UnistylesBreakpoints, screenSize: ScreenSize) => string | number | undefined;
63
64
  //# sourceMappingURL=breakpoints.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"breakpoints.d.ts","sourceRoot":"","sources":["../../../../src/utils/breakpoints.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,uBAAuB,EAAE,MAAM,UAAU,CAAA;AAGhF;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,0BAA0B,8CAuBtC,CAAA;AAED;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,4BAA4B,iCAAkC,MAAM,oEAchF,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,eAAO,MAAM,qBAAqB,kIAGlB,UAAU,kDAEvB,MAAM,GAAG,MAAM,GAAG,SA+BpB,CAAA"}
1
+ {"version":3,"file":"breakpoints.d.ts","sourceRoot":"","sources":["../../../../src/utils/breakpoints.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AAExD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAA;AAErD;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,0BAA0B,gBAAiB,oBAAoB,KAAG,oBAuB9E,CAAA;AAED;;;;;;;;;;;;;;GAcG;AACH,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;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,eAAO,MAAM,qBAAqB,UACvB,OAAO,MAAM,oBAAoB,GAAG,YAAY,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC,cACzE,MAAM,oBAAoB,cAC1B,UAAU,KACvB,MAAM,GAAG,MAAM,GAAG,SAgCpB,CAAA"}
@@ -1,4 +1,5 @@
1
1
  export declare const throwError: (message: string) => never;
2
2
  export declare const warn: (message: string) => void;
3
- export declare const isWeb: () => boolean;
3
+ export declare const isWeb: boolean;
4
+ export declare const isServer: boolean;
4
5
  //# sourceMappingURL=common.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../../src/utils/common.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,UAAU,YAAa,MAAM,UAEzC,CAAA;AAED,eAAO,MAAM,IAAI,YAAa,MAAM,SAEnC,CAAA;AAED,eAAO,MAAM,KAAK,eAA8B,CAAA"}
1
+ {"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../../src/utils/common.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,UAAU,YAAa,MAAM,UAEzC,CAAA;AAED,eAAO,MAAM,IAAI,YAAa,MAAM,SAEnC,CAAA;AAED,eAAO,MAAM,KAAK,SAAwB,CAAA;AAC1C,eAAO,MAAM,QAAQ,SAAgC,CAAA"}
@@ -1,5 +1,7 @@
1
1
  export { normalizeStyles } from './normalizeStyles';
2
+ export * from './normalizer';
2
3
  export { getBreakpointFromScreenWidth, sortAndValidateBreakpoints, getValueForBreakpoint } from './breakpoints';
3
4
  export { proxifyFunction, parseStyle } from './styles';
5
+ export { isServer } from './common';
4
6
  export { extractValues, getKeyForCustomMediaQuery, isMediaQuery, isWithinTheHeight, isWithinTheWidth, isWithinTheWidthAndHeight } from './mediaQueries';
5
7
  //# 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,OAAO,EAAE,4BAA4B,EAAE,0BAA0B,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAA;AAC/G,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AACtD,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,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,MAAM,UAAU,CAAA;AACnC,OAAO,EACH,aAAa,EACb,yBAAyB,EACzB,YAAY,EACZ,iBAAiB,EACjB,gBAAgB,EAChB,yBAAyB,EAC5B,MAAM,gBAAgB,CAAA"}
@@ -1,2 +1,5 @@
1
- export declare const normalizeStyles: <T extends {}>(styles: T) => T;
1
+ import type { Transforms } from '../types';
2
+ export declare const normalizeStyles: <T extends Required<import("react-native").ShadowStyleIOS> | Required<Pick<import("react-native").TextStyle, "textShadowColor" | "textShadowOffset" | "textShadowRadius">> | {
3
+ transform: Transforms;
4
+ }>(style: T) => T;
2
5
  //# sourceMappingURL=normalizeStyles.web.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"normalizeStyles.web.d.ts","sourceRoot":"","sources":["../../../../src/utils/normalizeStyles.web.ts"],"names":[],"mappings":"AA8EA,eAAO,MAAM,eAAe,gCAwB3B,CAAA"}
1
+ {"version":3,"file":"normalizeStyles.web.d.ts","sourceRoot":"","sources":["../../../../src/utils/normalizeStyles.web.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAoE,UAAU,EAAE,MAAM,UAAU,CAAA;AAuD5G,eAAO,MAAM,eAAe;;iBAwB3B,CAAA"}
@@ -0,0 +1,11 @@
1
+ import type { TextShadow, Transforms, BoxShadow } from '../types';
2
+ type Preprocessor = {
3
+ createTextShadowValue(style: TextShadow): string;
4
+ createBoxShadowValue(style: Required<BoxShadow>): string;
5
+ createTransformValue(transforms: Required<Transforms>): string;
6
+ };
7
+ export declare const normalizeColor: (color: string, opacity?: number) => string;
8
+ export declare const normalizeNumericValue: (value: number) => string | number;
9
+ export declare const preprocessor: Preprocessor;
10
+ export {};
11
+ //# sourceMappingURL=normalizer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"normalizer.d.ts","sourceRoot":"","sources":["../../../../src/utils/normalizer.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,UAAU,CAAA;AAEjE,KAAK,YAAY,GAAG;IAChB,qBAAqB,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAAC;IACjD,oBAAoB,CAAC,KAAK,EAAE,QAAQ,CAAC,SAAS,CAAC,GAAG,MAAM,CAAC;IACzD,oBAAoB,CAAC,UAAU,EAAE,QAAQ,CAAC,UAAU,CAAC,GAAG,MAAM,CAAC;CAClE,CAAA;AAED,eAAO,MAAM,cAAc,UAAW,MAAM,YAAW,MAAM,WAyB5D,CAAA;AAED,eAAO,MAAM,qBAAqB,UAAW,MAAM,oBAAiC,CAAA;AAwDpF,eAAO,MAAM,YAAY,EAAE,YAI1B,CAAA"}
@@ -1,4 +1,5 @@
1
- import type { Breakpoints, CustomNamedStyles, ScreenSize, SortedBreakpointEntries } from '../types';
1
+ import type { CustomNamedStyles, ScreenSize } from '../types';
2
+ import type { UnistylesBreakpoints } from '../global';
2
3
  /**
3
4
  * Proxies a function to parse its return value for custom media queries or breakpoints.
4
5
  *
@@ -20,7 +21,7 @@ import type { Breakpoints, CustomNamedStyles, ScreenSize, SortedBreakpointEntrie
20
21
  * const proxifiedFunction = proxifyFunction(myFunction, 'sm', screenSize, breakpoints)
21
22
  * proxifiedFunction() // parsed style based on screenSize and breakpoints
22
23
  */
23
- export declare const proxifyFunction: <B extends Breakpoints>(fn: Function, breakpoint: keyof B & string, screenSize: ScreenSize, breakpointPairs: SortedBreakpointEntries<B>) => Function;
24
+ export declare const proxifyFunction: (fn: Function, breakpoint: keyof UnistylesBreakpoints & string, screenSize: ScreenSize) => Function;
24
25
  /**
25
26
  * Parses a style object to resolve custom media queries or breakpoints based on the provided screen size and breakpoints.
26
27
  *
@@ -46,5 +47,5 @@ export declare const proxifyFunction: <B extends Breakpoints>(fn: Function, brea
46
47
  * const parsedStyle = parseStyle(style, 'sm', screenSize, breakpoints)
47
48
  * // { fontSize: '12px' }
48
49
  */
49
- export declare const parseStyle: <T, B extends Breakpoints>(style: CustomNamedStyles<T, B>, breakpoint: keyof B & string, screenSize: ScreenSize, breakpointPairs: SortedBreakpointEntries<B>) => T;
50
+ export declare const parseStyle: <T>(style: CustomNamedStyles<T>, breakpoint: keyof UnistylesBreakpoints & string, screenSize: ScreenSize) => T;
50
51
  //# 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,WAAW,EAAE,iBAAiB,EAAE,UAAU,EAAE,uBAAuB,EAAE,MAAM,UAAU,CAAA;AAKnG;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,eAAe,8BACpB,QAAQ,4CACA,UAAU,kDAEvB,QAGD,CAAA;AAEF;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,eAAO,MAAM,UAAU,uGAGP,UAAU,mDAmDzB,CAAA"}
1
+ {"version":3,"file":"styles.d.ts","sourceRoot":"","sources":["../../../../src/utils/styles.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAI7D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAA;AAErD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,eAAe,OACpB,QAAQ,cAAc,MAAM,oBAAoB,GAAG,MAAM,cACjD,UAAU,KACvB,QAGD,CAAA;AAEF;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,eAAO,MAAM,UAAU,+CAEP,MAAM,oBAAoB,GAAG,MAAM,cACnC,UAAU,MAiDzB,CAAA"}
package/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "react-native-unistyles",
3
- "version": "2.0.0-alpha.1",
3
+ "version": "2.0.0-alpha.2",
4
4
  "description": "Level up your React Native StyleSheet",
5
5
  "scripts": {
6
6
  "test": "jest",
7
+ "test:coverage": "jest --coverage",
7
8
  "tsc": "node_modules/typescript/bin/tsc --noEmit",
8
9
  "lint": "eslint . --ext .ts,.tsx",
9
10
  "prepare": "husky install && bob build",
@@ -18,7 +19,10 @@
18
19
  "files": [
19
20
  "src",
20
21
  "lib",
22
+ "ios",
23
+ "react-native-unistyles.podspec",
21
24
  "!**/*.spec.ts",
25
+ "!**/*.spec.tsx",
22
26
  "!**/.*"
23
27
  ],
24
28
  "keywords": [
@@ -39,6 +43,7 @@
39
43
  "devDependencies": {
40
44
  "@commitlint/config-conventional": "17.8.0",
41
45
  "@react-native/eslint-config": "0.74.0",
46
+ "@react-native/normalize-colors": "0.74.1",
42
47
  "@release-it/conventional-changelog": "7.0.2",
43
48
  "@testing-library/react-hooks": "8.0.1",
44
49
  "@types/jest": "29.5.6",
@@ -72,6 +77,7 @@
72
77
  "typescript": "5.2.2"
73
78
  },
74
79
  "peerDependencies": {
80
+ "@react-native/normalize-colors": "*",
75
81
  "react": "*",
76
82
  "react-native": "*",
77
83
  "react-native-web": "*"
@@ -82,7 +88,7 @@
82
88
  }
83
89
  },
84
90
  "workspaces": [
85
- "example",
91
+ "examples/expo",
86
92
  "docs"
87
93
  ],
88
94
  "packageManager": "yarn@3.6.1",
@@ -92,9 +98,13 @@
92
98
  "jest": {
93
99
  "preset": "react-native",
94
100
  "modulePathIgnorePatterns": [
95
- "<rootDir>/example/node_modules",
101
+ "<rootDir>/examples/expo/node_modules",
102
+ "<rootDir>/examples/ssr/node_modules",
96
103
  "<rootDir>/docs/node_modules",
97
104
  "<rootDir>/lib/"
105
+ ],
106
+ "coverageReporters": [
107
+ "html"
98
108
  ]
99
109
  },
100
110
  "commitlint": {
@@ -0,0 +1,21 @@
1
+ require "json"
2
+
3
+ package = JSON.parse(File.read(File.join(__dir__, "package.json")))
4
+
5
+ Pod::Spec.new do |s|
6
+ s.name = package["name"]
7
+ s.version = package["version"]
8
+ s.summary = package["description"]
9
+ s.homepage = package["homepage"]
10
+ s.license = package["license"]
11
+ s.authors = package["author"]
12
+
13
+ s.platforms = { :ios => min_ios_version_supported }
14
+ s.source = { :git => package["repository"], :tag => "#{s.version}" }
15
+
16
+ s.source_files = [
17
+ "ios/*.{h,m,mm}"
18
+ ]
19
+
20
+ s.dependency "React-Core"
21
+ end
@@ -0,0 +1,39 @@
1
+ import type { UnistylesBridge, UnistylesConfig } from './types'
2
+ import type { UnistylesThemes, UnistylesBreakpoints } from './global'
3
+
4
+ export class UnistyleRegistry {
5
+ public isClosed = false
6
+ public themes: UnistylesThemes = {} as UnistylesThemes
7
+ public breakpoints: UnistylesBreakpoints = {} as UnistylesBreakpoints
8
+ public sortedBreakpointPairs: Array<[keyof UnistylesBreakpoints, UnistylesBreakpoints[keyof UnistylesBreakpoints]]> = []
9
+ public config: UnistylesConfig = {}
10
+
11
+ constructor(private unistylesBridge: UnistylesBridge) {}
12
+
13
+ public addThemes = (themes: UnistylesThemes) => {
14
+ this.themes = themes
15
+
16
+ return this
17
+ }
18
+
19
+ public addBreakpoints = (breakpoints: UnistylesBreakpoints) => {
20
+ this.unistylesBridge.useBreakpoints(breakpoints)
21
+ this.sortedBreakpointPairs = this.unistylesBridge.sortedBreakpointPairs
22
+
23
+ return this
24
+ }
25
+
26
+ public addConfig = (config: UnistylesConfig) => {
27
+ this.config = config
28
+
29
+ if (config.featureFlags && config.featureFlags.length > 0) {
30
+ this.unistylesBridge.useFeatureFlags(config.featureFlags)
31
+ }
32
+
33
+ if (config.colorScheme) {
34
+ this.unistylesBridge.useColorScheme(config.colorScheme)
35
+ }
36
+
37
+ return this
38
+ }
39
+ }
@@ -0,0 +1,41 @@
1
+ import { UnistylesModule } from './UnistylesModule'
2
+ import { UnistylesRuntime } from './UnistylesRuntime'
3
+ import { UnistylesEngine } from './UnistylesEngine'
4
+ import { UnistyleRegistry } from './UnistyleRegistry'
5
+ import type { UnistylesBridge } from './types'
6
+ import { UnistylesError } from './types'
7
+
8
+ class Unistyles {
9
+ private _runtime: UnistylesRuntime
10
+ private _engine: UnistylesEngine
11
+ private _registry: UnistyleRegistry
12
+ private _bridge: UnistylesBridge
13
+
14
+ constructor() {
15
+ const isInstalled = UnistylesModule?.install() ?? false
16
+
17
+ if (!isInstalled) {
18
+ throw new Error(UnistylesError.RuntimeUnavailable)
19
+ }
20
+
21
+ // @ts-ignore
22
+ this._bridge = global.__UNISTYLES__ as UnistylesBridge
23
+ this._registry = new UnistyleRegistry(this._bridge)
24
+ this._runtime = new UnistylesRuntime(this._bridge, this._registry)
25
+ this._engine = new UnistylesEngine(this._registry, this._runtime)
26
+ }
27
+
28
+ public get registry() {
29
+ return this._registry
30
+ }
31
+
32
+ public get runtime() {
33
+ return this._runtime
34
+ }
35
+
36
+ public get engine() {
37
+ return this._engine
38
+ }
39
+ }
40
+
41
+ export const unistyles = new Unistyles()
@@ -0,0 +1,15 @@
1
+ import type { UnistyleRegistry } from './UnistyleRegistry'
2
+ import type { UnistylesRuntime } from './UnistylesRuntime'
3
+
4
+ // todo implement engine
5
+ export class UnistylesEngine {
6
+ // @ts-ignore
7
+ constructor(private registry: UnistyleRegistry, private runtime: UnistylesRuntime) {
8
+ this.registry = registry
9
+ this.runtime = runtime
10
+ }
11
+
12
+ // UnistylesEngine.parseStyleSheet
13
+ // UnistylesEngine.parseStyle
14
+ // UnistylesEngine.proxify
15
+ }
@@ -0,0 +1,7 @@
1
+ import { NativeModules } from 'react-native'
2
+
3
+ type UnistylesNativeModule = {
4
+ install(): boolean
5
+ }
6
+
7
+ export const UnistylesModule = NativeModules?.Unistyles as UnistylesNativeModule
@@ -0,0 +1,58 @@
1
+ import type { UnistylesBridge } from './types'
2
+ import type { UnistyleRegistry } from './UnistyleRegistry'
3
+ import { UnistylesColorScheme, UnistylesError } from './types'
4
+ import type { UnistylesThemes } from './global'
5
+
6
+ export class UnistylesRuntime {
7
+ constructor(private unistylesBridge: UnistylesBridge, private registry: UnistyleRegistry) {}
8
+
9
+ public get colorScheme() {
10
+ return this.unistylesBridge.colorScheme
11
+ }
12
+
13
+ public get breakpoints() {
14
+ return this.registry.breakpoints
15
+ }
16
+
17
+ public get sortedBreakpoints() {
18
+ return this.registry.sortedBreakpointPairs
19
+ }
20
+
21
+ public get config() {
22
+ return this.registry.config
23
+ }
24
+
25
+ public get theme() {
26
+ return this.unistylesBridge.theme
27
+ }
28
+
29
+ public get currentBreakpoint() {
30
+ return this.unistylesBridge.breakpoint
31
+ }
32
+
33
+ public setColorScheme = (scheme: UnistylesColorScheme) => {
34
+ if (scheme !== this.colorScheme) {
35
+ this.unistylesBridge.useColorScheme(scheme)
36
+ }
37
+ }
38
+
39
+ public setTheme = (name: keyof UnistylesThemes) => {
40
+ if (name !== this.theme && this.hasTheme(name)) {
41
+ this.unistylesBridge.useTheme(name)
42
+
43
+ return true
44
+ }
45
+
46
+ return false
47
+ }
48
+
49
+ public hasTheme = (name: keyof UnistylesThemes) => name in this.registry.themes
50
+
51
+ public getTheme = (forName: keyof UnistylesThemes) => {
52
+ if (!this.hasTheme(forName)) {
53
+ throw new Error(UnistylesError.ThemeNotFound)
54
+ }
55
+
56
+ return this.registry.themes[forName]
57
+ }
58
+ }
@@ -0,0 +1,12 @@
1
+ import type { CustomNamedStyles } from './types'
2
+ import type { UnistylesThemes } from './global'
3
+
4
+ type T = UnistylesThemes[keyof UnistylesThemes]
5
+
6
+ export const createStyleSheet = <S extends CustomNamedStyles<S>, X>(styles: S | CustomNamedStyles<S> | X | ((theme: T) => X | CustomNamedStyles<X>)): S | X => {
7
+ if (typeof styles === 'function') {
8
+ return styles as X
9
+ }
10
+
11
+ return styles as S
12
+ }
package/src/global.ts ADDED
@@ -0,0 +1,2 @@
1
+ export interface UnistylesThemes {}
2
+ export interface UnistylesBreakpoints {}
@@ -1,11 +1,12 @@
1
1
  import { useEffect, useRef, useState } from 'react'
2
2
  import type { ScreenSize } from '../types'
3
+ import { isServer } from '../utils'
3
4
 
4
5
  export const useDimensions = (): ScreenSize => {
5
6
  const timerRef = useRef<ReturnType<typeof setTimeout>>()
6
7
  const [screenSize, setScreenSize] = useState<ScreenSize>({
7
- width: window.innerWidth,
8
- height: window.innerHeight
8
+ width: isServer ? 0 : window.innerWidth,
9
+ height: isServer ? 0 : window.innerHeight
9
10
  })
10
11
 
11
12
  useEffect(() => {
package/src/index.ts CHANGED
@@ -1,2 +1,30 @@
1
- export { UnistylesTheme } from './UnistylesTheme'
2
- export { createUnistyles } from './createUnistyles'
1
+ import { unistyles } from './Unistyles'
2
+ import type { UnistylesThemes, UnistylesBreakpoints } from './global'
3
+ import { UnistylesColorScheme } from './types'
4
+
5
+ export { useInitialTheme } from './useInitialTheme'
6
+
7
+ export { useStyles } from './useStyles'
8
+ export { createStyleSheet } from './createStyleSheet'
9
+
10
+ const { addThemes, addBreakpoints, addConfig } = unistyles.registry
11
+ const UnistylesRuntime = unistyles.runtime
12
+ const UnistylesRegistry = {
13
+ addThemes,
14
+ addBreakpoints,
15
+ addConfig
16
+ }
17
+
18
+ export {
19
+ UnistylesRuntime,
20
+ UnistylesRegistry
21
+ }
22
+
23
+ export {
24
+ UnistylesColorScheme
25
+ }
26
+
27
+ export type {
28
+ UnistylesThemes,
29
+ UnistylesBreakpoints
30
+ }
@@ -1,8 +1,6 @@
1
+ import type { UnistylesBreakpoints } from '../global'
1
2
  import type { MediaQueries } from './mediaQueries'
2
3
 
3
- export type Breakpoints = Record<string, number>
4
- export type SortedBreakpointEntries<B extends Breakpoints> = [[keyof B & string, number]]
5
-
6
4
  export type ScreenSize = {
7
5
  width: number,
8
6
  height: number
@@ -12,22 +10,22 @@ export type CreateStylesFactory<ST, Theme> = (theme: Theme) => ST
12
10
 
13
11
  type WithEmptyObject<V> = keyof V extends never ? {} : V
14
12
 
15
- export type ExtractBreakpoints<T, B extends Breakpoints> = T extends Partial<Record<keyof B & string, infer V>>
13
+ export type ExtractBreakpoints<T> = T extends Partial<Record<keyof UnistylesBreakpoints & string, infer V>>
16
14
  ? WithEmptyObject<V>
17
15
  : T extends (...args: infer A) => infer R
18
- ? (...args: A) => ExtractBreakpoints<R, B>
16
+ ? (...args: A) => ExtractBreakpoints<R>
19
17
  : {
20
18
  [K in keyof T]: T[K] extends (...args: infer A) => infer R
21
- ? (...args: A) => ExtractBreakpoints<R, B>
19
+ ? (...args: A) => ExtractBreakpoints<R>
22
20
  : T[K] extends object
23
- ? ExtractBreakpoints<T[K], B>
21
+ ? ExtractBreakpoints<T[K]>
24
22
  : T[K]
25
23
  }
26
24
 
27
- export type RemoveKeysWithPrefix<T, B extends Breakpoints> = T extends (...args: Array<any>) => infer R
28
- ? (...args: Parameters<T>) => RemoveKeysWithPrefix<R, B>
25
+ export type RemoveKeysWithPrefix<T> = T extends (...args: Array<any>) => infer R
26
+ ? (...args: Parameters<T>) => RemoveKeysWithPrefix<R>
29
27
  : T extends object
30
28
  ? T extends Record<string, infer _V>
31
- ? { [K in keyof T as K extends MediaQueries ? keyof B & string : K]: RemoveKeysWithPrefix<T[K], B> }
32
- : { [K in keyof T]: RemoveKeysWithPrefix<T[K], B> }
29
+ ? { [K in keyof T as K extends MediaQueries ? keyof UnistylesBreakpoints & string : K]: RemoveKeysWithPrefix<T[K]> }
30
+ : { [K in keyof T]: RemoveKeysWithPrefix<T[K]> }
33
31
  : T
package/src/types/core.ts CHANGED
@@ -14,8 +14,8 @@ 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 { Breakpoints } from './breakpoints'
18
17
  import type { MediaQueries } from './mediaQueries'
18
+ import type { UnistylesBreakpoints } from '../global'
19
19
 
20
20
  type ShadowOffset = {
21
21
  width: number,
@@ -60,14 +60,14 @@ type UnistyleView<B> = DeepUniStyle<Omit<ViewStyle, NestedTypes>, B>
60
60
  type UnistyleText<B> = DeepUniStyle<Omit<TextStyle, NestedTypes>, B>
61
61
  type UnistyleImage<B> = DeepUniStyle<Omit<ImageStyle, NestedTypes>, B>
62
62
 
63
- export type StaticStyles<B extends Breakpoints> =
63
+ export type StaticStyles<B> =
64
64
  | UnistyleView<B>
65
65
  | UnistyleText<B>
66
66
  | UnistyleImage<B>
67
67
  & UnistyleNested<B>
68
68
 
69
- export type CustomNamedStyles<T, B extends Breakpoints> = {
70
- [K in keyof T]: T[K] extends (...args: infer A) => StaticStyles<B>
71
- ? (...args: A) => StaticStyles<B>
72
- : StaticStyles<B>
69
+ export type CustomNamedStyles<T> = {
70
+ [K in keyof T]: T[K] extends (...args: infer A) => StaticStyles<UnistylesBreakpoints>
71
+ ? (...args: A) => StaticStyles<UnistylesBreakpoints>
72
+ : StaticStyles<UnistylesBreakpoints>
73
73
  }