react-native-unistyles 1.3.0 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (396) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +38 -30
  3. package/lib/commonjs/UnistylesTheme.js +21 -0
  4. package/lib/commonjs/UnistylesTheme.js.map +1 -0
  5. package/lib/commonjs/createUnistyles.js +57 -0
  6. package/lib/commonjs/createUnistyles.js.map +1 -0
  7. package/lib/commonjs/hooks/index.js +3 -24
  8. package/lib/commonjs/hooks/index.js.map +1 -1
  9. package/lib/commonjs/hooks/useDimensions.js +10 -0
  10. package/lib/commonjs/hooks/useDimensions.js.map +1 -0
  11. package/lib/commonjs/hooks/useDimensions.web.js +34 -0
  12. package/lib/commonjs/hooks/useDimensions.web.js.map +1 -0
  13. package/lib/commonjs/index.js +6 -63
  14. package/lib/commonjs/index.js.map +1 -1
  15. package/lib/commonjs/types/index.js +0 -11
  16. package/lib/commonjs/types/index.js.map +1 -1
  17. package/lib/commonjs/types/mediaQueries.js +2 -0
  18. package/lib/commonjs/types/{unistyles.js.map → mediaQueries.js.map} +1 -1
  19. package/lib/commonjs/utils/breakpoints.js +122 -20
  20. package/lib/commonjs/utils/breakpoints.js.map +1 -1
  21. package/lib/commonjs/utils/common.js +20 -0
  22. package/lib/commonjs/utils/common.js.map +1 -0
  23. package/lib/commonjs/utils/index.js +54 -22
  24. package/lib/commonjs/utils/index.js.map +1 -1
  25. package/lib/commonjs/utils/mediaQueries.js +189 -0
  26. package/lib/commonjs/utils/mediaQueries.js.map +1 -0
  27. package/lib/{module/types/common.js.map → commonjs/utils/module.d.js.map} +1 -1
  28. package/lib/commonjs/utils/normalizeStyles.js +10 -0
  29. package/lib/commonjs/utils/normalizeStyles.js.map +1 -0
  30. package/lib/commonjs/{normalizer/normalizeStyle.js → utils/normalizeStyles.web.js} +5 -5
  31. package/lib/commonjs/utils/normalizeStyles.web.js.map +1 -0
  32. package/lib/commonjs/{normalizer → utils}/normalizer.js +3 -2
  33. package/lib/commonjs/utils/normalizer.js.map +1 -0
  34. package/lib/commonjs/utils/styles.js +72 -45
  35. package/lib/commonjs/utils/styles.js.map +1 -1
  36. package/lib/module/UnistylesTheme.js +12 -0
  37. package/lib/module/UnistylesTheme.js.map +1 -0
  38. package/lib/module/createUnistyles.js +50 -0
  39. package/lib/module/createUnistyles.js.map +1 -0
  40. package/lib/module/hooks/index.js +1 -4
  41. package/lib/module/hooks/index.js.map +1 -1
  42. package/lib/module/hooks/useDimensions.js +3 -0
  43. package/lib/module/hooks/useDimensions.js.map +1 -0
  44. package/lib/module/hooks/useDimensions.web.js +27 -0
  45. package/lib/module/hooks/useDimensions.web.js.map +1 -0
  46. package/lib/module/index.js +2 -30
  47. package/lib/module/index.js.map +1 -1
  48. package/lib/module/types/index.js +0 -1
  49. package/lib/module/types/index.js.map +1 -1
  50. package/lib/module/types/mediaQueries.js +2 -0
  51. package/lib/{commonjs/types/stylesheet.js.map → module/types/mediaQueries.js.map} +1 -1
  52. package/lib/module/utils/breakpoints.js +120 -19
  53. package/lib/module/utils/breakpoints.js.map +1 -1
  54. package/lib/module/utils/common.js +12 -0
  55. package/lib/module/utils/common.js.map +1 -0
  56. package/lib/module/utils/index.js +6 -6
  57. package/lib/module/utils/index.js.map +1 -1
  58. package/lib/module/utils/mediaQueries.js +176 -0
  59. package/lib/module/utils/mediaQueries.js.map +1 -0
  60. package/lib/{commonjs/types/variants.js.map → module/utils/module.d.js.map} +1 -1
  61. package/lib/module/utils/normalizeStyles.js +3 -0
  62. package/lib/module/utils/normalizeStyles.js.map +1 -0
  63. package/lib/module/{normalizer/normalizeStyle.js → utils/normalizeStyles.web.js} +3 -3
  64. package/lib/module/utils/normalizeStyles.web.js.map +1 -0
  65. package/lib/module/{normalizer → utils}/normalizer.js +3 -2
  66. package/lib/module/utils/normalizer.js.map +1 -0
  67. package/lib/module/utils/styles.js +72 -44
  68. package/lib/module/utils/styles.js.map +1 -1
  69. package/lib/typescript/examples/expo/src/App.d.ts +3 -0
  70. package/lib/typescript/examples/expo/src/App.d.ts.map +1 -0
  71. package/lib/typescript/examples/expo/src/examples/Breakpoints.d.ts +3 -0
  72. package/lib/typescript/examples/expo/src/examples/Breakpoints.d.ts.map +1 -0
  73. package/lib/typescript/examples/expo/src/examples/EmptyStyles.d.ts +3 -0
  74. package/lib/typescript/examples/expo/src/examples/EmptyStyles.d.ts.map +1 -0
  75. package/lib/typescript/examples/expo/src/examples/Extreme.d.ts +7 -0
  76. package/lib/typescript/examples/expo/src/examples/Extreme.d.ts.map +1 -0
  77. package/lib/typescript/examples/expo/src/examples/MediaQueries.d.ts +3 -0
  78. package/lib/typescript/examples/expo/src/examples/MediaQueries.d.ts.map +1 -0
  79. package/lib/typescript/examples/expo/src/examples/Memoization.d.ts +3 -0
  80. package/lib/typescript/examples/expo/src/examples/Memoization.d.ts.map +1 -0
  81. package/lib/typescript/examples/expo/src/examples/Minimal.d.ts +3 -0
  82. package/lib/typescript/examples/expo/src/examples/Minimal.d.ts.map +1 -0
  83. package/lib/typescript/examples/expo/src/examples/MinimalWithCreateStyleSheet.d.ts +3 -0
  84. package/lib/typescript/examples/expo/src/examples/MinimalWithCreateStyleSheet.d.ts.map +1 -0
  85. package/lib/typescript/examples/expo/src/examples/PlatformColors.d.ts +3 -0
  86. package/lib/typescript/examples/expo/src/examples/PlatformColors.d.ts.map +1 -0
  87. package/lib/typescript/examples/expo/src/examples/Theme.d.ts +3 -0
  88. package/lib/typescript/examples/expo/src/examples/Theme.d.ts.map +1 -0
  89. package/lib/typescript/examples/expo/src/examples/index.d.ts +9 -0
  90. package/lib/typescript/examples/expo/src/examples/index.d.ts.map +1 -0
  91. package/lib/typescript/examples/expo/src/index.d.ts +2 -0
  92. package/lib/typescript/examples/expo/src/index.d.ts.map +1 -0
  93. package/lib/typescript/examples/expo/src/styles/breakpoints.d.ts +8 -0
  94. package/lib/typescript/examples/expo/src/styles/breakpoints.d.ts.map +1 -0
  95. package/lib/typescript/examples/expo/src/styles/index.d.ts +46 -0
  96. package/lib/typescript/examples/expo/src/styles/index.d.ts.map +1 -0
  97. package/lib/typescript/examples/expo/src/styles/theme.d.ts +24 -0
  98. package/lib/typescript/examples/expo/src/styles/theme.d.ts.map +1 -0
  99. package/lib/typescript/src/UnistylesTheme.d.ts +9 -0
  100. package/lib/typescript/src/UnistylesTheme.d.ts.map +1 -0
  101. package/lib/typescript/src/createUnistyles.d.ts +10 -0
  102. package/lib/typescript/src/createUnistyles.d.ts.map +1 -0
  103. package/lib/typescript/src/hooks/index.d.ts +1 -4
  104. package/lib/typescript/src/hooks/index.d.ts.map +1 -1
  105. package/lib/typescript/src/hooks/useDimensions.d.ts +3 -0
  106. package/lib/typescript/src/hooks/useDimensions.d.ts.map +1 -0
  107. package/lib/typescript/src/hooks/useDimensions.web.d.ts +3 -0
  108. package/lib/typescript/src/hooks/useDimensions.web.d.ts.map +1 -0
  109. package/lib/typescript/src/index.d.ts +2 -76
  110. package/lib/typescript/src/index.d.ts.map +1 -1
  111. package/lib/typescript/src/types/breakpoints.d.ts +17 -25
  112. package/lib/typescript/src/types/breakpoints.d.ts.map +1 -1
  113. package/lib/typescript/src/types/core.d.ts +25 -11
  114. package/lib/typescript/src/types/core.d.ts.map +1 -1
  115. package/lib/typescript/src/types/index.d.ts +2 -7
  116. package/lib/typescript/src/types/index.d.ts.map +1 -1
  117. package/lib/typescript/src/types/mediaQueries.d.ts +8 -0
  118. package/lib/typescript/src/types/mediaQueries.d.ts.map +1 -0
  119. package/lib/typescript/src/utils/breakpoints.d.ts +62 -2
  120. package/lib/typescript/src/utils/breakpoints.d.ts.map +1 -1
  121. package/lib/typescript/src/utils/common.d.ts +7 -0
  122. package/lib/typescript/src/utils/common.d.ts.map +1 -0
  123. package/lib/typescript/src/utils/index.d.ts +6 -7
  124. package/lib/typescript/src/utils/index.d.ts.map +1 -1
  125. package/lib/typescript/src/utils/mediaQueries.d.ts +130 -0
  126. package/lib/typescript/src/utils/mediaQueries.d.ts.map +1 -0
  127. package/lib/typescript/src/utils/normalizeStyles.d.ts +2 -0
  128. package/lib/typescript/src/utils/normalizeStyles.d.ts.map +1 -0
  129. package/lib/typescript/src/utils/normalizeStyles.web.d.ts +5 -0
  130. package/lib/typescript/src/utils/normalizeStyles.web.d.ts.map +1 -0
  131. package/lib/typescript/src/utils/normalizer.d.ts.map +1 -0
  132. package/lib/typescript/src/utils/styles.d.ts +49 -3
  133. package/lib/typescript/src/utils/styles.d.ts.map +1 -1
  134. package/package.json +25 -46
  135. package/src/UnistylesTheme.tsx +17 -0
  136. package/src/__tests__/createUnistyles.spec.tsx +192 -0
  137. package/src/createUnistyles.ts +70 -0
  138. package/src/hooks/index.ts +1 -4
  139. package/src/hooks/useDimensions.ts +4 -0
  140. package/src/hooks/useDimensions.web.ts +34 -0
  141. package/src/index.ts +2 -50
  142. package/src/types/breakpoints.ts +33 -58
  143. package/src/types/core.ts +36 -11
  144. package/src/types/index.ts +7 -12
  145. package/src/types/mediaQueries.ts +10 -0
  146. package/src/utils/breakpoints.ts +124 -28
  147. package/src/utils/common.ts +14 -0
  148. package/src/utils/index.ts +13 -7
  149. package/src/utils/mediaQueries.ts +201 -0
  150. package/src/utils/normalizeStyles.ts +2 -0
  151. package/src/{normalizer/normalizeStyle.ts → utils/normalizeStyles.web.ts} +3 -3
  152. package/src/{normalizer → utils}/normalizer.ts +4 -5
  153. package/src/utils/styles.ts +102 -54
  154. package/android/CMakeLists.txt +0 -27
  155. package/android/build.gradle +0 -75
  156. package/android/src/main/cxx/cpp-adapter.cpp +0 -132
  157. package/android/src/main/java/com/unistyles/UnistylesModule.kt +0 -189
  158. package/android/src/main/java/com/unistyles/UnistylesPackage.kt +0 -18
  159. package/cxx/UnistylesRuntime.cpp +0 -318
  160. package/cxx/UnistylesRuntime.h +0 -74
  161. package/ios/UnistylesHelpers.h +0 -3
  162. package/ios/UnistylesHelpers.mm +0 -5
  163. package/ios/UnistylesModule.h +0 -16
  164. package/ios/UnistylesModule.mm +0 -138
  165. package/ios/platform/Platform_iOS.h +0 -21
  166. package/ios/platform/Platform_iOS.mm +0 -132
  167. package/ios/platform/Platform_macOS.h +0 -20
  168. package/ios/platform/Platform_macOS.mm +0 -83
  169. package/lib/commonjs/common.js +0 -60
  170. package/lib/commonjs/common.js.map +0 -1
  171. package/lib/commonjs/core/UnistyleRegistry.js +0 -94
  172. package/lib/commonjs/core/UnistyleRegistry.js.map +0 -1
  173. package/lib/commonjs/core/Unistyles.js +0 -32
  174. package/lib/commonjs/core/Unistyles.js.map +0 -1
  175. package/lib/commonjs/core/UnistylesModule.js +0 -197
  176. package/lib/commonjs/core/UnistylesModule.js.map +0 -1
  177. package/lib/commonjs/core/UnistylesModule.native.js +0 -9
  178. package/lib/commonjs/core/UnistylesModule.native.js.map +0 -1
  179. package/lib/commonjs/core/UnistylesRuntime.js +0 -140
  180. package/lib/commonjs/core/UnistylesRuntime.js.map +0 -1
  181. package/lib/commonjs/core/index.js +0 -13
  182. package/lib/commonjs/core/index.js.map +0 -1
  183. package/lib/commonjs/createStyleSheet.js +0 -14
  184. package/lib/commonjs/createStyleSheet.js.map +0 -1
  185. package/lib/commonjs/global.js +0 -2
  186. package/lib/commonjs/global.js.map +0 -1
  187. package/lib/commonjs/hooks/useCSS.js +0 -44
  188. package/lib/commonjs/hooks/useCSS.js.map +0 -1
  189. package/lib/commonjs/hooks/useCSS.native.js +0 -9
  190. package/lib/commonjs/hooks/useCSS.native.js.map +0 -1
  191. package/lib/commonjs/hooks/useInitialTheme.js +0 -17
  192. package/lib/commonjs/hooks/useInitialTheme.js.map +0 -1
  193. package/lib/commonjs/hooks/useUnistyles.js +0 -64
  194. package/lib/commonjs/hooks/useUnistyles.js.map +0 -1
  195. package/lib/commonjs/hooks/useVariants.js +0 -14
  196. package/lib/commonjs/hooks/useVariants.js.map +0 -1
  197. package/lib/commonjs/normalizer/index.js +0 -32
  198. package/lib/commonjs/normalizer/index.js.map +0 -1
  199. package/lib/commonjs/normalizer/module.d.js.map +0 -1
  200. package/lib/commonjs/normalizer/normalizeStyle.js.map +0 -1
  201. package/lib/commonjs/normalizer/normalizer.js.map +0 -1
  202. package/lib/commonjs/normalizer/normalizer.macos.js +0 -3
  203. package/lib/commonjs/normalizer/normalizer.macos.js.map +0 -1
  204. package/lib/commonjs/plugins/cssMediaQueriesPlugin.js +0 -14
  205. package/lib/commonjs/plugins/cssMediaQueriesPlugin.js.map +0 -1
  206. package/lib/commonjs/plugins/index.js +0 -20
  207. package/lib/commonjs/plugins/index.js.map +0 -1
  208. package/lib/commonjs/plugins/normalizeWebStylesPlugin.js +0 -12
  209. package/lib/commonjs/plugins/normalizeWebStylesPlugin.js.map +0 -1
  210. package/lib/commonjs/types/common.js +0 -2
  211. package/lib/commonjs/types/common.js.map +0 -1
  212. package/lib/commonjs/types/plugin.js +0 -6
  213. package/lib/commonjs/types/plugin.js.map +0 -1
  214. package/lib/commonjs/types/stylesheet.js +0 -6
  215. package/lib/commonjs/types/unistyles.js +0 -6
  216. package/lib/commonjs/types/variants.js +0 -2
  217. package/lib/commonjs/useStyles.js +0 -47
  218. package/lib/commonjs/useStyles.js.map +0 -1
  219. package/lib/commonjs/utils/cssMediaQuery.js +0 -244
  220. package/lib/commonjs/utils/cssMediaQuery.js.map +0 -1
  221. package/lib/commonjs/utils/generateId.js +0 -15
  222. package/lib/commonjs/utils/generateId.js.map +0 -1
  223. package/lib/commonjs/utils/hash32.js +0 -43
  224. package/lib/commonjs/utils/hash32.js.map +0 -1
  225. package/lib/commonjs/utils/mq.js +0 -38
  226. package/lib/commonjs/utils/mq.js.map +0 -1
  227. package/lib/commonjs/utils/mqParser.js +0 -89
  228. package/lib/commonjs/utils/mqParser.js.map +0 -1
  229. package/lib/commonjs/utils/withPlugins.js +0 -15
  230. package/lib/commonjs/utils/withPlugins.js.map +0 -1
  231. package/lib/module/common.js +0 -53
  232. package/lib/module/common.js.map +0 -1
  233. package/lib/module/core/UnistyleRegistry.js +0 -87
  234. package/lib/module/core/UnistyleRegistry.js.map +0 -1
  235. package/lib/module/core/Unistyles.js +0 -26
  236. package/lib/module/core/Unistyles.js.map +0 -1
  237. package/lib/module/core/UnistylesModule.js +0 -190
  238. package/lib/module/core/UnistylesModule.js.map +0 -1
  239. package/lib/module/core/UnistylesModule.native.js +0 -3
  240. package/lib/module/core/UnistylesModule.native.js.map +0 -1
  241. package/lib/module/core/UnistylesRuntime.js +0 -133
  242. package/lib/module/core/UnistylesRuntime.js.map +0 -1
  243. package/lib/module/core/index.js +0 -2
  244. package/lib/module/core/index.js.map +0 -1
  245. package/lib/module/createStyleSheet.js +0 -7
  246. package/lib/module/createStyleSheet.js.map +0 -1
  247. package/lib/module/global.js +0 -2
  248. package/lib/module/global.js.map +0 -1
  249. package/lib/module/hooks/useCSS.js +0 -37
  250. package/lib/module/hooks/useCSS.js.map +0 -1
  251. package/lib/module/hooks/useCSS.native.js +0 -2
  252. package/lib/module/hooks/useCSS.native.js.map +0 -1
  253. package/lib/module/hooks/useInitialTheme.js +0 -10
  254. package/lib/module/hooks/useInitialTheme.js.map +0 -1
  255. package/lib/module/hooks/useUnistyles.js +0 -57
  256. package/lib/module/hooks/useUnistyles.js.map +0 -1
  257. package/lib/module/hooks/useVariants.js +0 -7
  258. package/lib/module/hooks/useVariants.js.map +0 -1
  259. package/lib/module/normalizer/index.js +0 -3
  260. package/lib/module/normalizer/index.js.map +0 -1
  261. package/lib/module/normalizer/module.d.js.map +0 -1
  262. package/lib/module/normalizer/normalizeStyle.js.map +0 -1
  263. package/lib/module/normalizer/normalizer.js.map +0 -1
  264. package/lib/module/normalizer/normalizer.macos.js +0 -2
  265. package/lib/module/normalizer/normalizer.macos.js.map +0 -1
  266. package/lib/module/plugins/cssMediaQueriesPlugin.js +0 -7
  267. package/lib/module/plugins/cssMediaQueriesPlugin.js.map +0 -1
  268. package/lib/module/plugins/index.js +0 -3
  269. package/lib/module/plugins/index.js.map +0 -1
  270. package/lib/module/plugins/normalizeWebStylesPlugin.js +0 -6
  271. package/lib/module/plugins/normalizeWebStylesPlugin.js.map +0 -1
  272. package/lib/module/types/common.js +0 -2
  273. package/lib/module/types/plugin.js +0 -2
  274. package/lib/module/types/plugin.js.map +0 -1
  275. package/lib/module/types/stylesheet.js +0 -2
  276. package/lib/module/types/stylesheet.js.map +0 -1
  277. package/lib/module/types/unistyles.js +0 -2
  278. package/lib/module/types/unistyles.js.map +0 -1
  279. package/lib/module/types/variants.js +0 -2
  280. package/lib/module/types/variants.js.map +0 -1
  281. package/lib/module/useStyles.js +0 -40
  282. package/lib/module/useStyles.js.map +0 -1
  283. package/lib/module/utils/cssMediaQuery.js +0 -237
  284. package/lib/module/utils/cssMediaQuery.js.map +0 -1
  285. package/lib/module/utils/generateId.js +0 -7
  286. package/lib/module/utils/generateId.js.map +0 -1
  287. package/lib/module/utils/hash32.js +0 -36
  288. package/lib/module/utils/hash32.js.map +0 -1
  289. package/lib/module/utils/mq.js +0 -32
  290. package/lib/module/utils/mq.js.map +0 -1
  291. package/lib/module/utils/mqParser.js +0 -78
  292. package/lib/module/utils/mqParser.js.map +0 -1
  293. package/lib/module/utils/withPlugins.js +0 -8
  294. package/lib/module/utils/withPlugins.js.map +0 -1
  295. package/lib/typescript/src/common.d.ts +0 -46
  296. package/lib/typescript/src/common.d.ts.map +0 -1
  297. package/lib/typescript/src/core/UnistyleRegistry.d.ts +0 -56
  298. package/lib/typescript/src/core/UnistyleRegistry.d.ts.map +0 -1
  299. package/lib/typescript/src/core/Unistyles.d.ts +0 -13
  300. package/lib/typescript/src/core/Unistyles.d.ts.map +0 -1
  301. package/lib/typescript/src/core/UnistylesModule.d.ts +0 -19
  302. package/lib/typescript/src/core/UnistylesModule.d.ts.map +0 -1
  303. package/lib/typescript/src/core/UnistylesModule.native.d.ts +0 -6
  304. package/lib/typescript/src/core/UnistylesModule.native.d.ts.map +0 -1
  305. package/lib/typescript/src/core/UnistylesRuntime.d.ts +0 -81
  306. package/lib/typescript/src/core/UnistylesRuntime.d.ts.map +0 -1
  307. package/lib/typescript/src/core/index.d.ts +0 -3
  308. package/lib/typescript/src/core/index.d.ts.map +0 -1
  309. package/lib/typescript/src/createStyleSheet.d.ts +0 -8
  310. package/lib/typescript/src/createStyleSheet.d.ts.map +0 -1
  311. package/lib/typescript/src/global.d.ts +0 -7
  312. package/lib/typescript/src/global.d.ts.map +0 -1
  313. package/lib/typescript/src/hooks/useCSS.d.ts +0 -3
  314. package/lib/typescript/src/hooks/useCSS.d.ts.map +0 -1
  315. package/lib/typescript/src/hooks/useCSS.native.d.ts +0 -3
  316. package/lib/typescript/src/hooks/useCSS.native.d.ts.map +0 -1
  317. package/lib/typescript/src/hooks/useInitialTheme.d.ts +0 -3
  318. package/lib/typescript/src/hooks/useInitialTheme.d.ts.map +0 -1
  319. package/lib/typescript/src/hooks/useUnistyles.d.ts +0 -14
  320. package/lib/typescript/src/hooks/useUnistyles.d.ts.map +0 -1
  321. package/lib/typescript/src/hooks/useVariants.d.ts +0 -3
  322. package/lib/typescript/src/hooks/useVariants.d.ts.map +0 -1
  323. package/lib/typescript/src/normalizer/index.d.ts +0 -3
  324. package/lib/typescript/src/normalizer/index.d.ts.map +0 -1
  325. package/lib/typescript/src/normalizer/normalizeStyle.d.ts +0 -3
  326. package/lib/typescript/src/normalizer/normalizeStyle.d.ts.map +0 -1
  327. package/lib/typescript/src/normalizer/normalizer.d.ts.map +0 -1
  328. package/lib/typescript/src/normalizer/normalizer.macos.d.ts +0 -1
  329. package/lib/typescript/src/normalizer/normalizer.macos.d.ts.map +0 -1
  330. package/lib/typescript/src/plugins/cssMediaQueriesPlugin.d.ts +0 -3
  331. package/lib/typescript/src/plugins/cssMediaQueriesPlugin.d.ts.map +0 -1
  332. package/lib/typescript/src/plugins/index.d.ts +0 -3
  333. package/lib/typescript/src/plugins/index.d.ts.map +0 -1
  334. package/lib/typescript/src/plugins/normalizeWebStylesPlugin.d.ts +0 -3
  335. package/lib/typescript/src/plugins/normalizeWebStylesPlugin.d.ts.map +0 -1
  336. package/lib/typescript/src/types/common.d.ts +0 -3
  337. package/lib/typescript/src/types/common.d.ts.map +0 -1
  338. package/lib/typescript/src/types/plugin.d.ts +0 -7
  339. package/lib/typescript/src/types/plugin.d.ts.map +0 -1
  340. package/lib/typescript/src/types/stylesheet.d.ts +0 -40
  341. package/lib/typescript/src/types/stylesheet.d.ts.map +0 -1
  342. package/lib/typescript/src/types/unistyles.d.ts +0 -53
  343. package/lib/typescript/src/types/unistyles.d.ts.map +0 -1
  344. package/lib/typescript/src/types/variants.d.ts +0 -14
  345. package/lib/typescript/src/types/variants.d.ts.map +0 -1
  346. package/lib/typescript/src/useStyles.d.ts +0 -16
  347. package/lib/typescript/src/useStyles.d.ts.map +0 -1
  348. package/lib/typescript/src/utils/cssMediaQuery.d.ts +0 -4
  349. package/lib/typescript/src/utils/cssMediaQuery.d.ts.map +0 -1
  350. package/lib/typescript/src/utils/generateId.d.ts +0 -2
  351. package/lib/typescript/src/utils/generateId.d.ts.map +0 -1
  352. package/lib/typescript/src/utils/hash32.d.ts +0 -2
  353. package/lib/typescript/src/utils/hash32.d.ts.map +0 -1
  354. package/lib/typescript/src/utils/mq.d.ts +0 -26
  355. package/lib/typescript/src/utils/mq.d.ts.map +0 -1
  356. package/lib/typescript/src/utils/mqParser.d.ts +0 -16
  357. package/lib/typescript/src/utils/mqParser.d.ts.map +0 -1
  358. package/lib/typescript/src/utils/withPlugins.d.ts +0 -3
  359. package/lib/typescript/src/utils/withPlugins.d.ts.map +0 -1
  360. package/react-native-unistyles.podspec +0 -22
  361. package/src/__tests__/mocks.ts +0 -24
  362. package/src/common.ts +0 -55
  363. package/src/core/UnistyleRegistry.ts +0 -108
  364. package/src/core/Unistyles.ts +0 -35
  365. package/src/core/UnistylesModule.native.ts +0 -7
  366. package/src/core/UnistylesModule.ts +0 -230
  367. package/src/core/UnistylesRuntime.ts +0 -135
  368. package/src/core/index.ts +0 -2
  369. package/src/createStyleSheet.ts +0 -8
  370. package/src/global.ts +0 -6
  371. package/src/hooks/useCSS.native.ts +0 -3
  372. package/src/hooks/useCSS.ts +0 -51
  373. package/src/hooks/useInitialTheme.ts +0 -11
  374. package/src/hooks/useUnistyles.ts +0 -64
  375. package/src/hooks/useVariants.ts +0 -10
  376. package/src/normalizer/index.ts +0 -2
  377. package/src/normalizer/normalizer.macos.ts +0 -1
  378. package/src/plugins/cssMediaQueriesPlugin.ts +0 -8
  379. package/src/plugins/index.ts +0 -2
  380. package/src/plugins/normalizeWebStylesPlugin.ts +0 -7
  381. package/src/types/common.ts +0 -2
  382. package/src/types/plugin.ts +0 -7
  383. package/src/types/stylesheet.ts +0 -49
  384. package/src/types/unistyles.ts +0 -63
  385. package/src/types/variants.ts +0 -19
  386. package/src/useStyles.ts +0 -60
  387. package/src/utils/cssMediaQuery.ts +0 -268
  388. package/src/utils/generateId.ts +0 -10
  389. package/src/utils/hash32.ts +0 -53
  390. package/src/utils/mq.ts +0 -57
  391. package/src/utils/mqParser.ts +0 -99
  392. package/src/utils/withPlugins.ts +0 -13
  393. /package/lib/commonjs/{normalizer → utils}/module.d.js +0 -0
  394. /package/lib/module/{normalizer → utils}/module.d.js +0 -0
  395. /package/lib/typescript/src/{normalizer → utils}/normalizer.d.ts +0 -0
  396. /package/src/{normalizer → utils}/module.d.ts +0 -0
@@ -1,44 +1,140 @@
1
- import { unistyles } from '../core'
2
- import type { Optional, RNValue } from '../types'
3
- import type { UnistylesBreakpoints } from '../global'
4
- import { ScreenOrientation, isMobile } from '../common'
5
- import { getKeyForUnistylesMediaQuery } from './mqParser'
6
-
7
- export const getValueForBreakpoint = (value: Record<string, RNValue>): Optional<RNValue> => {
8
- const customMediaQueryKey = getKeyForUnistylesMediaQuery(
9
- Object.entries(value),
10
- unistyles.runtime.screen
11
- ) as keyof typeof value
12
-
13
- if (customMediaQueryKey) {
14
- return value[customMediaQueryKey]
15
- }
1
+ import { throwError } from './common'
2
+ import type { Breakpoints, ScreenSize, SortedBreakpointEntries } from '../types'
3
+ import { getKeyForCustomMediaQuery, isMediaQuery } from './mediaQueries'
4
+
5
+ /**
6
+ * Sorts the breakpoints object based on its numeric values in ascending order and validates them.
7
+ *
8
+ * This function takes an object where keys represent breakpoint names and values are numeric.
9
+ * It returns a new object with the same keys but sorted based on their corresponding numeric values.
10
+ * Additionally, it validates that:
11
+ * 1. The first breakpoint starts with a value of 0.
12
+ * 2. No duplicate breakpoint values exist.
13
+ *
14
+ * If the validation fails, appropriate error messages are logged to the console.
15
+ *
16
+ * @template B - An object type where keys are strings and values are numbers.
17
+ * @param {B} breakpoints - The breakpoints object to be sorted and validated.
18
+ * @returns {B} A new object with sorted and validated breakpoints.
19
+ *
20
+ * @example
21
+ * const input = { md: 768, lg: 1024, sm: 0 }
22
+ * sortAndValidateBreakpoints(input) // returns { sm: 0, md: 768, lg: 1024 }
23
+ */
24
+ export const sortAndValidateBreakpoints = <B extends Breakpoints>(breakpoints: B): B => {
25
+ const sortedPairs = Object
26
+ .entries(breakpoints)
27
+ .sort((breakpoint1, breakpoint2) => {
28
+ const [, value1] = breakpoint1
29
+ const [, value2] = breakpoint2
30
+
31
+ return value1 - value2
32
+ })
16
33
 
17
- const hasBreakpoints = unistyles.registry.sortedBreakpointPairs.length > 0
34
+ const sortedBreakpoints = Object.freeze(Object.fromEntries(sortedPairs)) as B
35
+ const breakpointValues = Object.values(sortedBreakpoints)
36
+ const [firstBreakpoint] = breakpointValues
18
37
 
19
- if (!hasBreakpoints && isMobile && (ScreenOrientation.Landscape in value || ScreenOrientation.Portrait in value)) {
20
- return value[unistyles.runtime.orientation]
38
+ if (firstBreakpoint !== 0) {
39
+ throwError('first breakpoint must start with 0')
21
40
  }
22
41
 
23
- const breakpoint = unistyles.runtime.breakpoint
42
+ if (breakpointValues.length !== new Set(breakpointValues).size) {
43
+ throwError('breakpoint values are duplicated')
44
+ }
45
+
46
+ return sortedBreakpoints
47
+ }
48
+
49
+ /**
50
+ * Determines the appropriate breakpoint key for a given screen width based on provided breakpoints.
51
+ *
52
+ * This function takes a screen width and an object of breakpoints. It returns the key of the breakpoint
53
+ * that the screen width falls into. The breakpoints are assumed to be sorted in ascending order.
54
+ *
55
+ * @template B - An object type where keys are strings and values are numbers representing screen widths.
56
+ * @param {number} width - The screen width to determine the breakpoint for.
57
+ * @param breakpointEntries - sorted pairs of breakpoints
58
+ * @returns {keyof B & string} The key of the breakpoint that the screen width falls into.
59
+ *
60
+ * @example
61
+ * const breakpoints = { sm: 0, md: 768, lg: 1024 }
62
+ * getBreakpointFromScreenWidth(800, breakpoints) // returns 'md'
63
+ */
64
+ export const getBreakpointFromScreenWidth = <B extends Breakpoints>(width: number, breakpointEntries: SortedBreakpointEntries<B>): keyof B & string => {
65
+ const [key] = breakpointEntries
66
+ .find(([, value], index, otherBreakpoints) => {
67
+ const minVal = value
68
+ const maxVal = otherBreakpoints[index + 1]?.[1]
69
+
70
+ if (!maxVal) {
71
+ return true
72
+ }
24
73
 
25
- if (!breakpoint) {
26
- return undefined
74
+ return width >= minVal && width < maxVal
75
+ }) as [keyof B & string, number]
76
+
77
+ return key
78
+ }
79
+
80
+ /**
81
+ * Retrieves the value associated with a given breakpoint or custom media query based on the provided screen size.
82
+ *
83
+ * The function first checks for custom media queries. If a matching custom media query is found, its associated value is returned.
84
+ * If no custom media query matches, the function then checks for a direct breakpoint match.
85
+ * If there's no direct breakpoint match, the function simulates CSS cascading to find the closest matching breakpoint.
86
+ *
87
+ * @template B - An object type where keys represent breakpoint names and values represent breakpoint values.
88
+ *
89
+ * @param {Record<keyof B & string, string | number>} value - An object containing values associated with breakpoints or custom media queries.
90
+ * @param {keyof B & string} breakpoint - The breakpoint name to check against.
91
+ * @param {ScreenSize} screenSize - An object representing the screen size to be checked against the media queries.
92
+ * @param breakpointPairs - sorted pairs of breakpoints
93
+ *
94
+ * @returns {string | number | undefined} Returns the value associated with the matching breakpoint or custom media query, or `undefined` if no match is found.
95
+ *
96
+ * @example
97
+ *
98
+ * const values = { ':w[200]': 'value1', sm: 'value2', md: 'value3' }
99
+ * const screenSize = { width: 250, height: 400 }
100
+ * const breakpoints = { sm: 300, md: 600, lg: 900 }
101
+ *
102
+ * getValueForBreakpoint(values, 'sm', screenSize, breakpoints); // 'value1'
103
+ */
104
+ export const getValueForBreakpoint = <B extends Breakpoints>(
105
+ value: Record<keyof B & string, string | number | undefined>,
106
+ breakpoint: keyof B & string,
107
+ screenSize: ScreenSize,
108
+ breakpointPairs: SortedBreakpointEntries<B>
109
+ ): string | number | undefined => {
110
+ // the highest priority is for custom media queries
111
+ const customMediaQueries = Object
112
+ .entries(value)
113
+ .filter(([key]) => isMediaQuery(key))
114
+ const customMediaQueryKey = getKeyForCustomMediaQuery(customMediaQueries, screenSize)
115
+
116
+ if (customMediaQueryKey && customMediaQueryKey in value) {
117
+ return value[customMediaQueryKey]
27
118
  }
28
119
 
29
- const directBreakpoint = value[breakpoint]
120
+ // if no custom media query, or didn't match, proceed with defined breakpoints
121
+ const unifiedKey = breakpoint
122
+ const directBreakpoint = value[unifiedKey]
30
123
 
31
- if (directBreakpoint || (breakpoint in value)) {
124
+ // if there is a direct key like 'sm' or 'md', or value for this key exists but its undefined
125
+ if (directBreakpoint || (unifiedKey in value)) {
32
126
  return directBreakpoint
33
127
  }
34
128
 
35
- const breakpointPairs = unistyles.registry.sortedBreakpointPairs
36
- const currentBreakpointIndex = breakpointPairs
37
- .findIndex(([key]) => key === breakpoint)
129
+ // there is no direct hit for breakpoint nor media-query, so let's simulate CSS cascading
130
+ const currentBreakpoint = breakpointPairs
131
+ .findIndex(([key]) => key === unifiedKey)
38
132
 
39
133
  const availableBreakpoints = breakpointPairs
40
- .filter(([key], index) => index < currentBreakpointIndex && key in value)
134
+ .filter(([key], index) => index < currentBreakpoint && key && key in value)
41
135
  .map(([key]) => key)
42
136
 
43
- return value[availableBreakpoints[availableBreakpoints.length - 1] as keyof UnistylesBreakpoints & string]
137
+ return breakpointPairs.length > 0
138
+ ? value[availableBreakpoints[availableBreakpoints.length - 1] as keyof B & string]
139
+ : undefined
44
140
  }
@@ -0,0 +1,14 @@
1
+ import { Platform } from 'react-native'
2
+
3
+ export const throwError = (message: string) => {
4
+ throw new Error(`🦄 [react-native-unistyles]: ${message}`)
5
+ }
6
+
7
+ export const warn = (message: string) => {
8
+ console.warn(`🦄 [react-native-unistyles]: ${message}`)
9
+ }
10
+
11
+ export const isWeb = Platform.OS === 'web'
12
+ export const isIOS = Platform.OS === 'ios'
13
+ export const isAndroid = Platform.OS === 'android'
14
+ export const isServer = typeof window === 'undefined'
@@ -1,7 +1,13 @@
1
- export { mq } from './mq'
2
- export type { UnistylesParsedMq } from './mqParser'
3
- export { getKeyForUnistylesMediaQuery, isWithinTheWidthAndHeight, isValidMq, parseMq, isUnistylesMq } from './mqParser'
4
- export { getValueForBreakpoint } from './breakpoints'
5
- export { proxifyFunction, parseStyle, isPlatformColor } from './styles'
6
- export { withPlugins } from './withPlugins'
7
- export { generateReactNativeWebId } from './generateId'
1
+ export { normalizeStyles } from './normalizeStyles'
2
+ export * from './normalizer'
3
+ export { getBreakpointFromScreenWidth, sortAndValidateBreakpoints, getValueForBreakpoint } from './breakpoints'
4
+ export { proxifyFunction, parseStyle } from './styles'
5
+ export { isServer } from './common'
6
+ export {
7
+ extractValues,
8
+ getKeyForCustomMediaQuery,
9
+ isMediaQuery,
10
+ isWithinTheHeight,
11
+ isWithinTheWidth,
12
+ isWithinTheWidthAndHeight
13
+ } from './mediaQueries'
@@ -0,0 +1,201 @@
1
+ import type { ScreenSize } from '../types'
2
+
3
+ /**
4
+ * Extracts numeric values from a coded string.
5
+ *
6
+ * The function is designed to process strings that have a format like "w[100,200]" or "h[300]".
7
+ * It removes characters 'w', 'h', '[', and ']' from the input string and then extracts the numbers.
8
+ *
9
+ * @param {string} codedValue - The input string to extract values from.
10
+ * @returns {Array<number>} An array of extracted numbers. Can contain one or two numbers based on the input format.
11
+ *
12
+ * @example
13
+ * extractValues("w[100,200]") // returns [100, 200]
14
+ * extractValues("h[300]") // returns [300]
15
+ * extractValues("h[,300]") // returns [0,300]
16
+ * extractValues("h[100,]") // returns [100]
17
+ */
18
+ export const extractValues = (codedValue: string): Array<number> => {
19
+ const [lh, rh] = codedValue
20
+ .replace(/[wh[\]]/g, '')
21
+ .split(',')
22
+
23
+ return rh
24
+ ? [Number(lh), Number(rh)]
25
+ : [Number(lh)]
26
+ }
27
+
28
+ /**
29
+ * Determines if the given screen size matches the specified breakpoint query.
30
+ *
31
+ * The function checks if the screen size (width and/or height) falls within the range
32
+ * specified by the breakpoint query. The query can specify width (using 'w'), height (using 'h'),
33
+ * or both.
34
+ *
35
+ * @param {string} query - The breakpoint query string. Examples: 'w[100,200]', 'h[300]', 'w[100,200]h[300,400]'.
36
+ * @param {ScreenSize} screenSize - The screen size to check against the breakpoint query.
37
+ * @returns {boolean} True if the screen size matches the breakpoint query, false otherwise.
38
+ *
39
+ * @example
40
+ * const screenSize = { width: 150, height: 350 }
41
+ * isWithinBreakpoint('w[100,200]', screenSize) // returns true
42
+ * isWithinBreakpoint('h[400]', screenSize) // returns false
43
+ */
44
+ export const isWithinBreakpoint = (query: string, screenSize: ScreenSize): boolean => {
45
+ if (query.includes('w') && query.includes('h')) {
46
+ return isWithinTheWidthAndHeight(query, screenSize)
47
+ }
48
+
49
+ if (query.charAt(0) === 'w') {
50
+ return isWithinTheWidth(query, screenSize.width)
51
+ }
52
+
53
+ if (query.charAt(0) === 'h') {
54
+ return isWithinTheHeight(query, screenSize.height)
55
+ }
56
+
57
+ return false
58
+ }
59
+
60
+ /**
61
+ * Determines if the given width matches the specified width range in the query.
62
+ *
63
+ * The function checks if the provided width falls within the range specified by the query.
64
+ * The query specifies a width range using a format like 'w[100,200]'. If only one value is provided,
65
+ * it's treated as a minimum width.
66
+ *
67
+ * @param {string} query - The width query string. Examples: 'w[100,200]' or 'w[100]'.
68
+ * @param {number} width - The width to check against the query.
69
+ * @returns {boolean} True if the width matches the query range, false otherwise.
70
+ *
71
+ * @example
72
+ * isWithinTheWidth('w[100,200]', 150) // returns true
73
+ * isWithinTheWidth('w[100]', 50) // returns false
74
+ * isWithinTheWidth('w[100]', 150) // returns true
75
+ */
76
+ export const isWithinTheWidth = (query: string, width: number): boolean => {
77
+ const [minWidth, maxWidth] = extractValues(query) as [number, number | undefined]
78
+
79
+ if (maxWidth && width >= minWidth && width <= maxWidth) {
80
+ return true
81
+ }
82
+
83
+ return !maxWidth && width >= minWidth
84
+ }
85
+
86
+ /**
87
+ * Determines if the given height matches the specified height range in the query.
88
+ *
89
+ * The function checks if the provided height falls within the range specified by the query.
90
+ * The query specifies a height range using a format like 'h[100,200]'. If only one value is provided,
91
+ * it's treated as a minimum height.
92
+ *
93
+ * @param {string} query - The height query string. Examples: 'h[100,200]' or 'h[100]'.
94
+ * @param {number} height - The height to check against the query.
95
+ * @returns {boolean} True if the height matches the query range, false otherwise.
96
+ *
97
+ * @example
98
+ * isWithinTheHeight('h[100,200]', 150) // returns true
99
+ * isWithinTheHeight('h[100]', 50) // returns false
100
+ * isWithinTheHeight('h[100]', 150) // returns true
101
+ */
102
+ export const isWithinTheHeight = (query: string, height: number): boolean => {
103
+ const [minHeight, maxHeight] = extractValues(query) as [number, number | undefined]
104
+
105
+ if (maxHeight && height >= minHeight && height <= maxHeight) {
106
+ return true
107
+ }
108
+
109
+ return !maxHeight && height >= minHeight
110
+ }
111
+
112
+ /**
113
+ * Determines if the given screen size matches both the specified width and height ranges in the query.
114
+ *
115
+ * The function checks if the provided screen size (both width and height) falls within the ranges
116
+ * specified by the query. The query can specify both width and height using a format like 'w[100,200]:h[300,400]'.
117
+ *
118
+ * @param {string} query - The combined width and height query string. Example: 'w[100,200]:h[300,400]'.
119
+ * @param {ScreenSize} screenSize - The screen size to check against the query.
120
+ * @returns {boolean} True if the screen size matches both the width and height ranges in the query, false otherwise.
121
+ *
122
+ * @example
123
+ * const screenSize = { width: 150, height: 350 }
124
+ * isWithinTheWidthAndHeight('w[100,200]:h[300,400]', screenSize) // returns true
125
+ * isWithinTheWidthAndHeight('w[100,200]:h[400,500]', screenSize) // returns false
126
+ */
127
+ export const isWithinTheWidthAndHeight = (query: string, screenSize: ScreenSize): boolean => {
128
+ const result = query
129
+ .split(':')
130
+ .filter(Boolean)
131
+ .map(q => isWithinBreakpoint(q, screenSize))
132
+ .filter(Boolean)
133
+
134
+ return result.length === 2
135
+ }
136
+
137
+ /**
138
+ * Checks if the given query string is a valid custom media query.
139
+ *
140
+ * The valid custom media query formats include:
141
+ * - :w[200]
142
+ * - :w[0, 200]
143
+ * - :w[, 300]
144
+ * - :h[200]
145
+ * - :h[0, 500]
146
+ * - :h[,200]
147
+ * - :w[100, 300]:h[200,500]
148
+ * - :h[200,500]:w[100, 300]
149
+ *
150
+ * @param {string} query - The query string to be checked.
151
+ * @returns {boolean} Returns `true` if the query is a valid custom media query, otherwise `false`.
152
+ * @example
153
+ *
154
+ * isMediaQuery(':w[200]') // true
155
+ * isMediaQuery(':w100]') // false
156
+ */
157
+ export const isMediaQuery = (query: string): boolean => {
158
+ const regex = /^(?:(:w\[\d*(?:,\s?\d+)?])?(:h\[\d*(?:,\s?\d+)?])?|(:h\[\d*(?:,\s?\d+)?])?(:w\[\d*(?:,\s?\d+)?])?)$/
159
+
160
+ return query.length > 0 && regex.test(query)
161
+ }
162
+
163
+ /**
164
+ * Retrieves the first matching custom media query key based on the provided screen size.
165
+ *
166
+ * The function processes an array of media queries and returns the first query that matches
167
+ * the given screen size. The media queries can be in formats like:
168
+ * - w[200]
169
+ * - w[0, 200]
170
+ * - w[, 300]
171
+ * - h[200]
172
+ * - h[0, 500]
173
+ * - h[,200]
174
+ * - w[100, 300]:h[200,500]
175
+ * - h[200,500]:w[100, 300]
176
+ *
177
+ * @param {Array<[string, string | number]>} mediaQueries - An array of tuples containing media query keys and associated values.
178
+ * @param {ScreenSize} screenSize - An object representing the screen size to be checked against the media queries.
179
+ * @returns {string | undefined} Returns the first matching media query key or `undefined` if no match is found.
180
+ * @example
181
+ *
182
+ * const queries = [[':w[200]', 'value1'], [':h[300,500]', 'value2']]
183
+ * const size = { width: 250, height: 400 }
184
+ * getKeyForCustomMediaQuery(queries, size) // ':w[200]
185
+ */
186
+ export const getKeyForCustomMediaQuery = (mediaQueries: Array<[string, string | number | undefined]>, screenSize: ScreenSize): string | undefined => {
187
+ const [matchedQuery] = mediaQueries
188
+ .flatMap(([key]) => {
189
+ if (key.includes('w') && key.includes('h')) {
190
+ return isWithinBreakpoint(key, screenSize) ? key : undefined
191
+ }
192
+
193
+ return key
194
+ .split(':')
195
+ .filter(Boolean)
196
+ .map(query => isWithinBreakpoint(query, screenSize) ? key : undefined)
197
+ })
198
+ .filter(Boolean)
199
+
200
+ return matchedQuery
201
+ }
@@ -0,0 +1,2 @@
1
+ // nothing to do here
2
+ export const normalizeStyles = <T>(styles: T) => styles as T
@@ -1,6 +1,6 @@
1
+ import { warn } from './common'
1
2
  import { preprocessor } from './normalizer'
2
- import { warn } from '../common'
3
- import type { NormalizedBoxShadow, NormalizedTextShadow, BoxShadow, TextShadow, RNStyle } from '../types'
3
+ import type { NormalizedBoxShadow, NormalizedTextShadow, BoxShadow, TextShadow, Transforms } from '../types'
4
4
 
5
5
  const normalizeBoxShadow = <T extends BoxShadow>(style: T): NormalizedBoxShadow => {
6
6
  const requiredBoxShadowProperties = [
@@ -55,7 +55,7 @@ const normalizeTextShadow = <T extends TextShadow>(style: T): NormalizedTextShad
55
55
  }
56
56
  }
57
57
 
58
- export const normalizeStyle = <T extends RNStyle>(style: T): T => {
58
+ export const normalizeStyles = <T extends BoxShadow | TextShadow | { transform: Transforms }>(style: T): T => {
59
59
  const normalizedTransform = ('transform' in style && Array.isArray(style.transform))
60
60
  ? { transform: preprocessor.createTransformValue(style.transform) }
61
61
  : {}
@@ -1,7 +1,7 @@
1
1
  // based on react-native-web normalizer
2
2
  // https://github.com/necolas/react-native-web
3
3
  import normalizeColors from '@react-native/normalize-colors'
4
- import type { TextShadow, Transforms, BoxShadow, Nullable } from '../types'
4
+ import type { TextShadow, Transforms, BoxShadow } from '../types'
5
5
 
6
6
  type Preprocessor = {
7
7
  createTextShadowValue(style: TextShadow): string,
@@ -15,9 +15,9 @@ export const normalizeColor = (color: string, opacity: number = 1) => {
15
15
  return color
16
16
  }
17
17
 
18
- const integer = normalizeColors(color) as Nullable<number>
18
+ const integer = normalizeColors(color) as number | null
19
19
 
20
- // If the color is an unknown format, the return value is null
20
+ // If the colour is an unknown format, the return value is null
21
21
  if (integer === null) {
22
22
  return color
23
23
  }
@@ -37,8 +37,7 @@ export const normalizeColor = (color: string, opacity: number = 1) => {
37
37
  }
38
38
 
39
39
  export const normalizeNumericValue = (value: number) => value ? `${value}px` : value
40
-
41
- const normalizeTransform = <T>(key: string, value: T) => {
40
+ const normalizeTransform = (key: string, value: number | string) => {
42
41
  if (key.includes('scale')) {
43
42
  return value
44
43
  }
@@ -1,14 +1,36 @@
1
- import type { Optional, RNStyle, RNValue } from '../types'
1
+ import type { Breakpoints, CustomNamedStyles, ScreenSize, SortedBreakpointEntries } from '../types'
2
2
  import { getValueForBreakpoint } from './breakpoints'
3
- import { isAndroid, isIOS } from '../common'
4
- import { withPlugins } from './withPlugins'
3
+ import { normalizeStyles } from './normalizeStyles'
4
+ import { isAndroid, isIOS, isWeb } from './common'
5
5
 
6
- export const proxifyFunction = (
7
- key: string,
8
- fn: Function,
9
- variant?: Record<string, Optional<string>>
6
+ /**
7
+ * Proxies a function to parse its return value for custom media queries or breakpoints.
8
+ *
9
+ * @template B - An object type where keys represent breakpoint names and values represent breakpoint values.
10
+ *
11
+ * @param {Function} fn - The function to be proxified.
12
+ * @param {keyof B & string} breakpoint - The breakpoint name to check against.
13
+ * @param {ScreenSize} screenSize - An object representing the screen size to be checked against the media queries.
14
+ * @param breakpointPairs - sorted pairs of breakpoints
15
+ *
16
+ * @returns {Function} Returns the proxified function
17
+ *
18
+ * @example
19
+ *
20
+ * const myFunction = () => ({ ':w[200]': 'value1', sm: 'value2' })
21
+ * const screenSize = { width: 250, height: 400 }
22
+ * const breakpoints = { sm: 300, md: 600 }
23
+ *
24
+ * const proxifiedFunction = proxifyFunction(myFunction, 'sm', screenSize, breakpoints)
25
+ * proxifiedFunction() // parsed style based on screenSize and breakpoints
26
+ */
27
+ export const proxifyFunction = <B extends Breakpoints>(
28
+ fn: Function, breakpoint: keyof B & string,
29
+ screenSize: ScreenSize,
30
+ breakpointPairs: SortedBreakpointEntries<B>
10
31
  ): Function => new Proxy(fn, {
11
- apply: (target, thisArg, argumentsList) => withPlugins(key, parseStyle(target.apply(thisArg, argumentsList), variant))
32
+ apply: (target, thisArg, argumentsList) =>
33
+ parseStyle(target.apply(thisArg, argumentsList), breakpoint, screenSize, breakpointPairs)
12
34
  })
13
35
 
14
36
  export const isPlatformColor = <T extends {}>(value: T): boolean => {
@@ -19,57 +41,83 @@ export const isPlatformColor = <T extends {}>(value: T): boolean => {
19
41
  return isAndroid && 'resource_paths' in value && typeof value.resource_paths === 'object'
20
42
  }
21
43
 
22
- export const parseStyle = <T extends RNStyle>(
23
- style: T,
24
- variant: Record<string, Optional<string>> = {},
25
- parseMediaQueries = true
26
- ): T => Object
27
- .entries(style || {})
28
- .reduce((acc, [key, value]) => {
29
- // nested objects
30
- if (key === 'shadowOffset' || key === 'textShadowOffset') {
31
- acc[key] = parseStyle(value, variant)
44
+ /**
45
+ * Parses a style object to resolve custom media queries or breakpoints based on the provided screen size and breakpoints.
46
+ *
47
+ * The function processes each key-value pair in the style object. If the value is a function or a valid style (not an object or a 'transform' key),
48
+ * it is returned as-is. Otherwise, the function attempts to resolve the value based on the provided breakpoint, screen size, and defined breakpoints.
49
+ *
50
+ * @template T - The type of the style object.
51
+ * @template B - An object type where keys represent breakpoint names and values represent breakpoint values.
52
+ *
53
+ * @param {CustomNamedStyles<T, B>} style - The style object to be parsed.
54
+ * @param {keyof B & string} breakpoint - The breakpoint name to check against.
55
+ * @param {ScreenSize} screenSize - An object representing the screen size to be checked against the media queries.
56
+ * @param breakpointPairs - sorted pairs of breakpoints
57
+ *
58
+ * @returns {Record<string, string | number | Function>} Returns the parsed style object with resolved custom media queries or breakpoints.
59
+ *
60
+ * @example
61
+ *
62
+ * const style = { fontSize: { sm: '12px', md: '16px' } }
63
+ * const screenSize = { width: 300, height: 400 }
64
+ * const breakpoints = { xs: 0, sm: 300, md: 600 }
65
+ *
66
+ * const parsedStyle = parseStyle(style, 'sm', screenSize, breakpoints)
67
+ * // { fontSize: '12px' }
68
+ */
69
+ export const parseStyle = <T, B extends Breakpoints>(
70
+ style: CustomNamedStyles<T, B>,
71
+ breakpoint: keyof B & string,
72
+ screenSize: ScreenSize,
73
+ breakpointPairs: SortedBreakpointEntries<B>
74
+ ): T => {
75
+ const entries = Object.entries(style || {}) as [[
76
+ keyof T,
77
+ CustomNamedStyles<T, B> | Record<keyof B & string, string | number | undefined>]
78
+ ]
32
79
 
33
- return acc
34
- }
80
+ const parsedStyles = Object
81
+ .fromEntries(entries
82
+ .map(([key, value]) => {
83
+ const hasNestedProperties = key === 'shadowOffset' || key === 'textShadowOffset'
35
84
 
36
- // transforms
37
- if (key === 'transform' && Array.isArray(value)) {
38
- acc[key] = value.map(value => parseStyle(value, variant))
85
+ if (hasNestedProperties) {
86
+ return [
87
+ key,
88
+ parseStyle(value as CustomNamedStyles<T, B>, breakpoint, screenSize, breakpointPairs)
89
+ ]
90
+ }
39
91
 
40
- return acc
41
- }
92
+ const isTransform = key === 'transform'
42
93
 
43
- // values or platform colors
44
- if (typeof value !== 'object' || isPlatformColor(value)) {
45
- acc[key as keyof T] = value
94
+ if (isTransform && Array.isArray(value)) {
95
+ return [
96
+ key,
97
+ value.map(value => parseStyle(value, breakpoint, screenSize, breakpointPairs))
98
+ ]
99
+ }
46
100
 
47
- return acc
48
- }
101
+ const isDynamicFunction = typeof value === 'function'
102
+ const isValidStyle = typeof value !== 'object' || isPlatformColor(value)
49
103
 
50
- if (key === 'variants') {
51
- return {
52
- ...acc,
53
- ...(Object
54
- .keys(value) as Array<keyof typeof value>)
55
- .reduce((acc, key) => ({
56
- ...acc,
57
- // this will parse the styles of the selected variant (or default if it is undefined), if selected variant has no styles then it will fallback to default styles
58
- ...parseStyle((value)[key][variant[key as keyof typeof variant] || 'default'] ?? (value)[key].default ?? {})
59
- }), {})
60
- }
61
- }
104
+ if (isDynamicFunction || isValidStyle) {
105
+ return [key, value]
106
+ }
62
107
 
63
- // don't parse media queries and breakpoints
64
- if (!parseMediaQueries) {
65
- return {
66
- ...acc,
67
- [key]: value
68
- }
69
- }
108
+ return [
109
+ key,
110
+ getValueForBreakpoint<B>(
111
+ value as Record<keyof B & string, string | number | undefined>,
112
+ breakpoint,
113
+ screenSize,
114
+ breakpointPairs
115
+ )
116
+ ]
117
+ })
118
+ )
70
119
 
71
- return {
72
- ...acc,
73
- [key]: getValueForBreakpoint(value as Record<string, RNValue>)
74
- }
75
- }, {} as T)
120
+ return isWeb
121
+ ? normalizeStyles(parsedStyles)
122
+ : parsedStyles
123
+ }
@@ -1,27 +0,0 @@
1
- cmake_minimum_required(VERSION 3.9.0)
2
-
3
- project(unistyles)
4
-
5
- add_library(unistyles
6
- SHARED
7
- ../cxx/UnistylesRuntime.cpp
8
- ./src/main/cxx/cpp-adapter.cpp
9
- )
10
-
11
- include_directories(
12
- ../cxx
13
- )
14
-
15
- set_target_properties(unistyles PROPERTIES
16
- CXX_STANDARD 17
17
- CXX_STANDARD_REQUIRED ON
18
- CXX_EXTENSIONS OFF
19
- POSITION_INDEPENDENT_CODE ON
20
- )
21
-
22
- find_package(ReactAndroid REQUIRED CONFIG)
23
-
24
- target_link_libraries(unistyles
25
- ReactAndroid::jsi
26
- android
27
- )