react-native-unistyles 1.1.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 (157) hide show
  1. package/ios/UnistylesModule.h +10 -0
  2. package/ios/UnistylesModule.mm +108 -0
  3. package/ios/UnistylesRuntime.h +30 -0
  4. package/ios/UnistylesRuntime.mm +191 -0
  5. package/lib/commonjs/UnistyleRegistry.js +37 -0
  6. package/lib/commonjs/UnistyleRegistry.js.map +1 -0
  7. package/lib/commonjs/Unistyles.js +36 -0
  8. package/lib/commonjs/Unistyles.js.map +1 -0
  9. package/lib/commonjs/UnistylesEngine.js +22 -0
  10. package/lib/commonjs/UnistylesEngine.js.map +1 -0
  11. package/lib/commonjs/UnistylesModule.js +9 -0
  12. package/lib/commonjs/UnistylesModule.js.map +1 -0
  13. package/lib/commonjs/UnistylesRuntime.js +52 -0
  14. package/lib/commonjs/UnistylesRuntime.js.map +1 -0
  15. package/lib/commonjs/createStyleSheet.js +14 -0
  16. package/lib/commonjs/createStyleSheet.js.map +1 -0
  17. package/lib/commonjs/global.js +2 -0
  18. package/lib/commonjs/global.js.map +1 -0
  19. package/lib/commonjs/index.js +33 -6
  20. package/lib/commonjs/index.js.map +1 -1
  21. package/lib/commonjs/types/cxx.js +23 -0
  22. package/lib/commonjs/types/cxx.js.map +1 -0
  23. package/lib/commonjs/types/index.js +11 -0
  24. package/lib/commonjs/types/index.js.map +1 -1
  25. package/lib/commonjs/useInitialTheme.js +13 -0
  26. package/lib/commonjs/useInitialTheme.js.map +1 -0
  27. package/lib/commonjs/useStyles.js +48 -0
  28. package/lib/commonjs/useStyles.js.map +1 -0
  29. package/lib/commonjs/useUnistyles.js +59 -0
  30. package/lib/commonjs/useUnistyles.js.map +1 -0
  31. package/lib/commonjs/utils/breakpoints.js +4 -2
  32. package/lib/commonjs/utils/breakpoints.js.map +1 -1
  33. package/lib/commonjs/utils/styles.js +6 -6
  34. package/lib/commonjs/utils/styles.js.map +1 -1
  35. package/lib/module/UnistyleRegistry.js +30 -0
  36. package/lib/module/UnistyleRegistry.js.map +1 -0
  37. package/lib/module/Unistyles.js +30 -0
  38. package/lib/module/Unistyles.js.map +1 -0
  39. package/lib/module/UnistylesEngine.js +15 -0
  40. package/lib/module/UnistylesEngine.js.map +1 -0
  41. package/lib/module/UnistylesModule.js +3 -0
  42. package/lib/module/UnistylesModule.js.map +1 -0
  43. package/lib/module/UnistylesRuntime.js +45 -0
  44. package/lib/module/UnistylesRuntime.js.map +1 -0
  45. package/lib/module/createStyleSheet.js +7 -0
  46. package/lib/module/createStyleSheet.js.map +1 -0
  47. package/lib/module/global.js +2 -0
  48. package/lib/module/global.js.map +1 -0
  49. package/lib/module/index.js +18 -2
  50. package/lib/module/index.js.map +1 -1
  51. package/lib/module/types/cxx.js +17 -0
  52. package/lib/module/types/cxx.js.map +1 -0
  53. package/lib/module/types/index.js +1 -0
  54. package/lib/module/types/index.js.map +1 -1
  55. package/lib/module/useInitialTheme.js +6 -0
  56. package/lib/module/useInitialTheme.js.map +1 -0
  57. package/lib/module/useStyles.js +42 -0
  58. package/lib/module/useStyles.js.map +1 -0
  59. package/lib/module/useUnistyles.js +52 -0
  60. package/lib/module/useUnistyles.js.map +1 -0
  61. package/lib/module/utils/breakpoints.js +4 -3
  62. package/lib/module/utils/breakpoints.js.map +1 -1
  63. package/lib/module/utils/styles.js +6 -7
  64. package/lib/module/utils/styles.js.map +1 -1
  65. package/lib/typescript/examples/expo/src/App.d.ts.map +1 -1
  66. package/lib/typescript/examples/expo/src/examples/Cxx.d.ts +3 -0
  67. package/lib/typescript/examples/expo/src/examples/Cxx.d.ts.map +1 -0
  68. package/lib/typescript/examples/expo/src/examples/index.d.ts +1 -7
  69. package/lib/typescript/examples/expo/src/examples/index.d.ts.map +1 -1
  70. package/lib/typescript/examples/expo/src/styles/index.d.ts +15 -45
  71. package/lib/typescript/examples/expo/src/styles/index.d.ts.map +1 -1
  72. package/lib/typescript/examples/expo/src/styles/theme.d.ts +17 -1
  73. package/lib/typescript/examples/expo/src/styles/theme.d.ts.map +1 -1
  74. package/lib/typescript/src/UnistyleRegistry.d.ts +15 -0
  75. package/lib/typescript/src/UnistyleRegistry.d.ts.map +1 -0
  76. package/lib/typescript/src/Unistyles.d.ts +16 -0
  77. package/lib/typescript/src/Unistyles.d.ts.map +1 -0
  78. package/lib/typescript/src/UnistylesEngine.d.ts +8 -0
  79. package/lib/typescript/src/UnistylesEngine.d.ts.map +1 -0
  80. package/lib/typescript/src/UnistylesModule.d.ts +6 -0
  81. package/lib/typescript/src/UnistylesModule.d.ts.map +1 -0
  82. package/lib/typescript/src/UnistylesRuntime.d.ts +56 -0
  83. package/lib/typescript/src/UnistylesRuntime.d.ts.map +1 -0
  84. package/lib/typescript/src/createStyleSheet.d.ts +6 -0
  85. package/lib/typescript/src/createStyleSheet.d.ts.map +1 -0
  86. package/lib/typescript/src/global.d.ts +5 -0
  87. package/lib/typescript/src/global.d.ts.map +1 -0
  88. package/lib/typescript/src/index.d.ts +14 -2
  89. package/lib/typescript/src/index.d.ts.map +1 -1
  90. package/lib/typescript/src/types/breakpoints.d.ts +6 -7
  91. package/lib/typescript/src/types/breakpoints.d.ts.map +1 -1
  92. package/lib/typescript/src/types/core.d.ts +4 -4
  93. package/lib/typescript/src/types/core.d.ts.map +1 -1
  94. package/lib/typescript/src/types/cxx.d.ts +50 -0
  95. package/lib/typescript/src/types/cxx.d.ts.map +1 -0
  96. package/lib/typescript/src/types/index.d.ts +3 -1
  97. package/lib/typescript/src/types/index.d.ts.map +1 -1
  98. package/lib/typescript/src/useInitialTheme.d.ts +3 -0
  99. package/lib/typescript/src/useInitialTheme.d.ts.map +1 -0
  100. package/lib/typescript/src/useStyles.d.ts +46 -0
  101. package/lib/typescript/src/useStyles.d.ts.map +1 -0
  102. package/lib/typescript/src/useUnistyles.d.ts +45 -0
  103. package/lib/typescript/src/useUnistyles.d.ts.map +1 -0
  104. package/lib/typescript/src/utils/breakpoints.d.ts +5 -4
  105. package/lib/typescript/src/utils/breakpoints.d.ts.map +1 -1
  106. package/lib/typescript/src/utils/styles.d.ts +4 -3
  107. package/lib/typescript/src/utils/styles.d.ts.map +1 -1
  108. package/package.json +11 -8
  109. package/react-native-unistyles.podspec +21 -0
  110. package/src/UnistyleRegistry.ts +39 -0
  111. package/src/Unistyles.ts +41 -0
  112. package/src/UnistylesEngine.ts +15 -0
  113. package/src/UnistylesModule.ts +7 -0
  114. package/src/UnistylesRuntime.ts +58 -0
  115. package/src/createStyleSheet.ts +12 -0
  116. package/src/global.ts +2 -0
  117. package/src/index.ts +30 -2
  118. package/src/types/breakpoints.ts +9 -11
  119. package/src/types/core.ts +6 -6
  120. package/src/types/cxx.ts +61 -0
  121. package/src/types/index.ts +3 -3
  122. package/src/useInitialTheme.ts +7 -0
  123. package/src/useStyles.ts +49 -0
  124. package/src/useUnistyles.ts +67 -0
  125. package/src/utils/breakpoints.ts +16 -14
  126. package/src/utils/styles.ts +16 -18
  127. package/lib/commonjs/UnistylesTheme.js +0 -21
  128. package/lib/commonjs/UnistylesTheme.js.map +0 -1
  129. package/lib/commonjs/createUnistyles.js +0 -57
  130. package/lib/commonjs/createUnistyles.js.map +0 -1
  131. package/lib/module/UnistylesTheme.js +0 -12
  132. package/lib/module/UnistylesTheme.js.map +0 -1
  133. package/lib/module/createUnistyles.js +0 -50
  134. package/lib/module/createUnistyles.js.map +0 -1
  135. package/lib/typescript/examples/expo/src/examples/Breakpoints.d.ts +0 -3
  136. package/lib/typescript/examples/expo/src/examples/Breakpoints.d.ts.map +0 -1
  137. package/lib/typescript/examples/expo/src/examples/EmptyStyles.d.ts +0 -3
  138. package/lib/typescript/examples/expo/src/examples/EmptyStyles.d.ts.map +0 -1
  139. package/lib/typescript/examples/expo/src/examples/Extreme.d.ts +0 -7
  140. package/lib/typescript/examples/expo/src/examples/Extreme.d.ts.map +0 -1
  141. package/lib/typescript/examples/expo/src/examples/MediaQueries.d.ts +0 -3
  142. package/lib/typescript/examples/expo/src/examples/MediaQueries.d.ts.map +0 -1
  143. package/lib/typescript/examples/expo/src/examples/Memoization.d.ts +0 -3
  144. package/lib/typescript/examples/expo/src/examples/Memoization.d.ts.map +0 -1
  145. package/lib/typescript/examples/expo/src/examples/Minimal.d.ts +0 -3
  146. package/lib/typescript/examples/expo/src/examples/Minimal.d.ts.map +0 -1
  147. package/lib/typescript/examples/expo/src/examples/MinimalWithCreateStyleSheet.d.ts +0 -3
  148. package/lib/typescript/examples/expo/src/examples/MinimalWithCreateStyleSheet.d.ts.map +0 -1
  149. package/lib/typescript/examples/expo/src/examples/Theme.d.ts +0 -3
  150. package/lib/typescript/examples/expo/src/examples/Theme.d.ts.map +0 -1
  151. package/lib/typescript/src/UnistylesTheme.d.ts +0 -9
  152. package/lib/typescript/src/UnistylesTheme.d.ts.map +0 -1
  153. package/lib/typescript/src/createUnistyles.d.ts +0 -10
  154. package/lib/typescript/src/createUnistyles.d.ts.map +0 -1
  155. package/src/UnistylesTheme.tsx +0 -17
  156. package/src/__tests__/createUnistyles.spec.tsx +0 -192
  157. package/src/createUnistyles.ts +0 -70
@@ -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
- 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,16 +1,15 @@
1
1
  {
2
2
  "name": "react-native-unistyles",
3
- "version": "1.1.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
7
  "test:coverage": "jest --coverage",
8
8
  "tsc": "node_modules/typescript/bin/tsc --noEmit",
9
9
  "lint": "eslint . --ext .ts,.tsx",
10
- "clean": "del-cli lib",
11
10
  "prepare": "husky install && bob build",
12
11
  "precommit": "concurrently 'yarn tsc' 'yarn lint' 'yarn test'",
13
- "release": "release-it"
12
+ "release": "release-it patch --preRelease=alpha --npm.tag=next"
14
13
  },
15
14
  "main": "lib/commonjs/index",
16
15
  "module": "lib/module/index",
@@ -20,7 +19,10 @@
20
19
  "files": [
21
20
  "src",
22
21
  "lib",
22
+ "ios",
23
+ "react-native-unistyles.podspec",
23
24
  "!**/*.spec.ts",
25
+ "!**/*.spec.tsx",
24
26
  "!**/.*"
25
27
  ],
26
28
  "keywords": [
@@ -42,9 +44,9 @@
42
44
  "@commitlint/config-conventional": "17.8.0",
43
45
  "@react-native/eslint-config": "0.74.0",
44
46
  "@react-native/normalize-colors": "0.74.1",
45
- "@release-it/conventional-changelog": "5.1.1",
47
+ "@release-it/conventional-changelog": "7.0.2",
46
48
  "@testing-library/react-hooks": "8.0.1",
47
- "@types/jest": "29.5.5",
49
+ "@types/jest": "29.5.6",
48
50
  "@types/react": "18.2.28",
49
51
  "@types/react-native": "0.72.3",
50
52
  "@typescript-eslint/eslint-plugin": "6.8.0",
@@ -52,7 +54,6 @@
52
54
  "@typescript-eslint/parser": "6.8.0",
53
55
  "commitlint": "17.8.0",
54
56
  "concurrently": "8.2.1",
55
- "del-cli": "5.1.0",
56
57
  "eslint": "8.51.0",
57
58
  "eslint-config-codemask": "1.1.7",
58
59
  "eslint-plugin-functional": "6.0.0",
@@ -120,11 +121,13 @@
120
121
  "publish": true
121
122
  },
122
123
  "github": {
123
- "release": true
124
+ "release": false
124
125
  },
125
126
  "plugins": {
126
127
  "@release-it/conventional-changelog": {
127
- "preset": "angular"
128
+ "preset": {
129
+ "name": "conventionalcommits"
130
+ }
128
131
  }
129
132
  }
130
133
  },
@@ -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 {}
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
  }
@@ -0,0 +1,61 @@
1
+ import type { UnistylesThemes, UnistylesBreakpoints } from '../global'
2
+
3
+ export type Nullable<T> = T | null
4
+ export enum UnistylesColorScheme {
5
+ System = 'system',
6
+ Manual = 'manual'
7
+ }
8
+
9
+ export type UnistylesConfig = {
10
+ colorScheme?: UnistylesColorScheme,
11
+ featureFlags?: Array<string>
12
+ }
13
+
14
+ export type UnistylesBridge = {
15
+ // getters
16
+ theme: keyof UnistylesThemes
17
+ breakpoint: keyof UnistylesBreakpoints,
18
+ colorScheme: UnistylesColorScheme,
19
+ sortedBreakpointPairs: Array<[keyof UnistylesBreakpoints, UnistylesBreakpoints[keyof UnistylesBreakpoints]]>
20
+
21
+ // setters
22
+ useBreakpoints(breakpoints: UnistylesBreakpoints): void,
23
+ useTheme(name: keyof UnistylesThemes): void,
24
+ useColorScheme(scheme: UnistylesColorScheme): void,
25
+ useFeatureFlags(flags: Array<string>): void
26
+ }
27
+
28
+ export enum CxxUnistylesEventTypes {
29
+ Theme = 'theme',
30
+ Size = 'size',
31
+ Breakpoint = 'breakpoint'
32
+ }
33
+
34
+ export type CxxUnistylesThemeEvent = {
35
+ type: CxxUnistylesEventTypes.Theme,
36
+ payload: {
37
+ currentTheme: keyof UnistylesThemes
38
+ }
39
+ }
40
+
41
+ export type CxxUnistylesSizeEvent = {
42
+ type: CxxUnistylesEventTypes.Size,
43
+ payload: {
44
+ width: number,
45
+ height: number
46
+ }
47
+ }
48
+
49
+ export type CxxUnistylesBreakpointEvent = {
50
+ type: CxxUnistylesEventTypes.Breakpoint,
51
+ payload: {
52
+ currentBreakpoint: keyof UnistylesBreakpoints
53
+ }
54
+ }
55
+
56
+ export type UnistylesEvents = CxxUnistylesThemeEvent | CxxUnistylesSizeEvent | CxxUnistylesBreakpointEvent
57
+
58
+ export enum UnistylesError {
59
+ RuntimeUnavailable = 'UNISTYLES_ERROR_RUNTIME_UNAVAILABLE',
60
+ ThemeNotFound = 'UNISTYLES_ERROR_THEME_NOT_FOUND'
61
+ }
@@ -1,10 +1,10 @@
1
1
  export * from './normalizer'
2
+ export * from './cxx'
2
3
  export type { CustomNamedStyles } from './core'
4
+ export type { MediaQueries } from './mediaQueries'
3
5
  export type {
4
6
  ScreenSize,
5
- Breakpoints,
6
7
  CreateStylesFactory,
7
8
  ExtractBreakpoints,
8
- RemoveKeysWithPrefix,
9
- SortedBreakpointEntries
9
+ RemoveKeysWithPrefix
10
10
  } from './breakpoints'
@@ -0,0 +1,7 @@
1
+ import { useRef } from 'react'
2
+ import { unistyles } from './Unistyles'
3
+ import type { UnistylesThemes } from './global'
4
+
5
+ export const useInitialTheme = (forName: keyof UnistylesThemes) => {
6
+ useRef(unistyles.runtime.setTheme(forName))
7
+ }