react-native-unistyles 1.1.6 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (394) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +30 -38
  3. package/android/CMakeLists.txt +27 -0
  4. package/android/build.gradle +75 -0
  5. package/android/src/main/cxx/cpp-adapter.cpp +132 -0
  6. package/android/src/main/java/com/unistyles/UnistylesModule.kt +189 -0
  7. package/android/src/main/java/com/unistyles/UnistylesPackage.kt +18 -0
  8. package/cxx/UnistylesRuntime.cpp +318 -0
  9. package/cxx/UnistylesRuntime.h +74 -0
  10. package/ios/UnistylesHelpers.h +3 -0
  11. package/ios/UnistylesHelpers.mm +5 -0
  12. package/ios/UnistylesModule.h +16 -0
  13. package/ios/UnistylesModule.mm +138 -0
  14. package/ios/platform/Platform_iOS.h +21 -0
  15. package/ios/platform/Platform_iOS.mm +132 -0
  16. package/ios/platform/Platform_macOS.h +20 -0
  17. package/ios/platform/Platform_macOS.mm +83 -0
  18. package/lib/commonjs/common.js +60 -0
  19. package/lib/commonjs/common.js.map +1 -0
  20. package/lib/commonjs/core/UnistyleRegistry.js +94 -0
  21. package/lib/commonjs/core/UnistyleRegistry.js.map +1 -0
  22. package/lib/commonjs/core/Unistyles.js +32 -0
  23. package/lib/commonjs/core/Unistyles.js.map +1 -0
  24. package/lib/commonjs/core/UnistylesModule.js +197 -0
  25. package/lib/commonjs/core/UnistylesModule.js.map +1 -0
  26. package/lib/commonjs/core/UnistylesModule.native.js +9 -0
  27. package/lib/commonjs/core/UnistylesModule.native.js.map +1 -0
  28. package/lib/commonjs/core/UnistylesRuntime.js +140 -0
  29. package/lib/commonjs/core/UnistylesRuntime.js.map +1 -0
  30. package/lib/commonjs/core/index.js +13 -0
  31. package/lib/commonjs/core/index.js.map +1 -0
  32. package/lib/commonjs/createStyleSheet.js +14 -0
  33. package/lib/commonjs/createStyleSheet.js.map +1 -0
  34. package/lib/commonjs/global.js +2 -0
  35. package/lib/commonjs/global.js.map +1 -0
  36. package/lib/commonjs/hooks/index.js +24 -3
  37. package/lib/commonjs/hooks/index.js.map +1 -1
  38. package/lib/commonjs/hooks/useCSS.js +44 -0
  39. package/lib/commonjs/hooks/useCSS.js.map +1 -0
  40. package/lib/commonjs/hooks/useCSS.native.js +9 -0
  41. package/lib/commonjs/hooks/useCSS.native.js.map +1 -0
  42. package/lib/commonjs/hooks/useInitialTheme.js +17 -0
  43. package/lib/commonjs/hooks/useInitialTheme.js.map +1 -0
  44. package/lib/commonjs/hooks/useUnistyles.js +64 -0
  45. package/lib/commonjs/hooks/useUnistyles.js.map +1 -0
  46. package/lib/commonjs/hooks/useVariants.js +14 -0
  47. package/lib/commonjs/hooks/useVariants.js.map +1 -0
  48. package/lib/commonjs/index.js +63 -6
  49. package/lib/commonjs/index.js.map +1 -1
  50. package/lib/commonjs/normalizer/index.js +32 -0
  51. package/lib/commonjs/normalizer/index.js.map +1 -0
  52. package/lib/commonjs/normalizer/module.d.js.map +1 -0
  53. package/lib/commonjs/{utils/normalizeStyles.web.js → normalizer/normalizeStyle.js} +5 -5
  54. package/lib/commonjs/normalizer/normalizeStyle.js.map +1 -0
  55. package/lib/commonjs/{utils → normalizer}/normalizer.js +2 -3
  56. package/lib/commonjs/normalizer/normalizer.js.map +1 -0
  57. package/lib/commonjs/normalizer/normalizer.macos.js +3 -0
  58. package/lib/commonjs/normalizer/normalizer.macos.js.map +1 -0
  59. package/lib/commonjs/plugins/cssMediaQueriesPlugin.js +14 -0
  60. package/lib/commonjs/plugins/cssMediaQueriesPlugin.js.map +1 -0
  61. package/lib/commonjs/plugins/index.js +20 -0
  62. package/lib/commonjs/plugins/index.js.map +1 -0
  63. package/lib/commonjs/plugins/normalizeWebStylesPlugin.js +12 -0
  64. package/lib/commonjs/plugins/normalizeWebStylesPlugin.js.map +1 -0
  65. package/lib/commonjs/types/common.js +2 -0
  66. package/lib/{module/utils/module.d.js.map → commonjs/types/common.js.map} +1 -1
  67. package/lib/commonjs/types/index.js +11 -0
  68. package/lib/commonjs/types/index.js.map +1 -1
  69. package/lib/commonjs/types/plugin.js +6 -0
  70. package/lib/commonjs/{utils/module.d.js.map → types/plugin.js.map} +1 -1
  71. package/lib/commonjs/types/stylesheet.js +6 -0
  72. package/lib/commonjs/types/{mediaQueries.js.map → stylesheet.js.map} +1 -1
  73. package/lib/commonjs/types/unistyles.js +6 -0
  74. package/lib/{module/types/mediaQueries.js.map → commonjs/types/unistyles.js.map} +1 -1
  75. package/lib/commonjs/types/variants.js +2 -0
  76. package/lib/commonjs/types/variants.js.map +1 -0
  77. package/lib/commonjs/useStyles.js +47 -0
  78. package/lib/commonjs/useStyles.js.map +1 -0
  79. package/lib/commonjs/utils/breakpoints.js +20 -122
  80. package/lib/commonjs/utils/breakpoints.js.map +1 -1
  81. package/lib/commonjs/utils/cssMediaQuery.js +244 -0
  82. package/lib/commonjs/utils/cssMediaQuery.js.map +1 -0
  83. package/lib/commonjs/utils/generateId.js +15 -0
  84. package/lib/commonjs/utils/generateId.js.map +1 -0
  85. package/lib/commonjs/utils/hash32.js +43 -0
  86. package/lib/commonjs/utils/hash32.js.map +1 -0
  87. package/lib/commonjs/utils/index.js +22 -54
  88. package/lib/commonjs/utils/index.js.map +1 -1
  89. package/lib/commonjs/utils/mq.js +38 -0
  90. package/lib/commonjs/utils/mq.js.map +1 -0
  91. package/lib/commonjs/utils/mqParser.js +89 -0
  92. package/lib/commonjs/utils/mqParser.js.map +1 -0
  93. package/lib/commonjs/utils/styles.js +52 -72
  94. package/lib/commonjs/utils/styles.js.map +1 -1
  95. package/lib/commonjs/utils/withPlugins.js +15 -0
  96. package/lib/commonjs/utils/withPlugins.js.map +1 -0
  97. package/lib/module/common.js +53 -0
  98. package/lib/module/common.js.map +1 -0
  99. package/lib/module/core/UnistyleRegistry.js +87 -0
  100. package/lib/module/core/UnistyleRegistry.js.map +1 -0
  101. package/lib/module/core/Unistyles.js +26 -0
  102. package/lib/module/core/Unistyles.js.map +1 -0
  103. package/lib/module/core/UnistylesModule.js +190 -0
  104. package/lib/module/core/UnistylesModule.js.map +1 -0
  105. package/lib/module/core/UnistylesModule.native.js +3 -0
  106. package/lib/module/core/UnistylesModule.native.js.map +1 -0
  107. package/lib/module/core/UnistylesRuntime.js +133 -0
  108. package/lib/module/core/UnistylesRuntime.js.map +1 -0
  109. package/lib/module/core/index.js +2 -0
  110. package/lib/module/core/index.js.map +1 -0
  111. package/lib/module/createStyleSheet.js +7 -0
  112. package/lib/module/createStyleSheet.js.map +1 -0
  113. package/lib/module/global.js +2 -0
  114. package/lib/module/global.js.map +1 -0
  115. package/lib/module/hooks/index.js +4 -1
  116. package/lib/module/hooks/index.js.map +1 -1
  117. package/lib/module/hooks/useCSS.js +37 -0
  118. package/lib/module/hooks/useCSS.js.map +1 -0
  119. package/lib/module/hooks/useCSS.native.js +2 -0
  120. package/lib/module/hooks/useCSS.native.js.map +1 -0
  121. package/lib/module/hooks/useInitialTheme.js +10 -0
  122. package/lib/module/hooks/useInitialTheme.js.map +1 -0
  123. package/lib/module/hooks/useUnistyles.js +57 -0
  124. package/lib/module/hooks/useUnistyles.js.map +1 -0
  125. package/lib/module/hooks/useVariants.js +7 -0
  126. package/lib/module/hooks/useVariants.js.map +1 -0
  127. package/lib/module/index.js +30 -2
  128. package/lib/module/index.js.map +1 -1
  129. package/lib/module/normalizer/index.js +3 -0
  130. package/lib/module/normalizer/index.js.map +1 -0
  131. package/lib/module/normalizer/module.d.js.map +1 -0
  132. package/lib/module/{utils/normalizeStyles.web.js → normalizer/normalizeStyle.js} +3 -3
  133. package/lib/module/normalizer/normalizeStyle.js.map +1 -0
  134. package/lib/module/{utils → normalizer}/normalizer.js +2 -3
  135. package/lib/module/normalizer/normalizer.js.map +1 -0
  136. package/lib/module/normalizer/normalizer.macos.js +2 -0
  137. package/lib/module/normalizer/normalizer.macos.js.map +1 -0
  138. package/lib/module/plugins/cssMediaQueriesPlugin.js +7 -0
  139. package/lib/module/plugins/cssMediaQueriesPlugin.js.map +1 -0
  140. package/lib/module/plugins/index.js +3 -0
  141. package/lib/module/plugins/index.js.map +1 -0
  142. package/lib/module/plugins/normalizeWebStylesPlugin.js +6 -0
  143. package/lib/module/plugins/normalizeWebStylesPlugin.js.map +1 -0
  144. package/lib/module/types/common.js +2 -0
  145. package/lib/module/types/common.js.map +1 -0
  146. package/lib/module/types/index.js +1 -0
  147. package/lib/module/types/index.js.map +1 -1
  148. package/lib/module/types/plugin.js +2 -0
  149. package/lib/module/types/plugin.js.map +1 -0
  150. package/lib/module/types/stylesheet.js +2 -0
  151. package/lib/module/types/stylesheet.js.map +1 -0
  152. package/lib/module/types/unistyles.js +2 -0
  153. package/lib/module/types/unistyles.js.map +1 -0
  154. package/lib/module/types/variants.js +2 -0
  155. package/lib/module/types/variants.js.map +1 -0
  156. package/lib/module/useStyles.js +40 -0
  157. package/lib/module/useStyles.js.map +1 -0
  158. package/lib/module/utils/breakpoints.js +19 -120
  159. package/lib/module/utils/breakpoints.js.map +1 -1
  160. package/lib/module/utils/cssMediaQuery.js +237 -0
  161. package/lib/module/utils/cssMediaQuery.js.map +1 -0
  162. package/lib/module/utils/generateId.js +7 -0
  163. package/lib/module/utils/generateId.js.map +1 -0
  164. package/lib/module/utils/hash32.js +36 -0
  165. package/lib/module/utils/hash32.js.map +1 -0
  166. package/lib/module/utils/index.js +6 -6
  167. package/lib/module/utils/index.js.map +1 -1
  168. package/lib/module/utils/mq.js +32 -0
  169. package/lib/module/utils/mq.js.map +1 -0
  170. package/lib/module/utils/mqParser.js +78 -0
  171. package/lib/module/utils/mqParser.js.map +1 -0
  172. package/lib/module/utils/styles.js +50 -72
  173. package/lib/module/utils/styles.js.map +1 -1
  174. package/lib/module/utils/withPlugins.js +8 -0
  175. package/lib/module/utils/withPlugins.js.map +1 -0
  176. package/lib/typescript/src/common.d.ts +46 -0
  177. package/lib/typescript/src/common.d.ts.map +1 -0
  178. package/lib/typescript/src/core/UnistyleRegistry.d.ts +56 -0
  179. package/lib/typescript/src/core/UnistyleRegistry.d.ts.map +1 -0
  180. package/lib/typescript/src/core/Unistyles.d.ts +13 -0
  181. package/lib/typescript/src/core/Unistyles.d.ts.map +1 -0
  182. package/lib/typescript/src/core/UnistylesModule.d.ts +19 -0
  183. package/lib/typescript/src/core/UnistylesModule.d.ts.map +1 -0
  184. package/lib/typescript/src/core/UnistylesModule.native.d.ts +6 -0
  185. package/lib/typescript/src/core/UnistylesModule.native.d.ts.map +1 -0
  186. package/lib/typescript/src/core/UnistylesRuntime.d.ts +81 -0
  187. package/lib/typescript/src/core/UnistylesRuntime.d.ts.map +1 -0
  188. package/lib/typescript/src/core/index.d.ts +3 -0
  189. package/lib/typescript/src/core/index.d.ts.map +1 -0
  190. package/lib/typescript/src/createStyleSheet.d.ts +8 -0
  191. package/lib/typescript/src/createStyleSheet.d.ts.map +1 -0
  192. package/lib/typescript/src/global.d.ts +7 -0
  193. package/lib/typescript/src/global.d.ts.map +1 -0
  194. package/lib/typescript/src/hooks/index.d.ts +4 -1
  195. package/lib/typescript/src/hooks/index.d.ts.map +1 -1
  196. package/lib/typescript/src/hooks/useCSS.d.ts +3 -0
  197. package/lib/typescript/src/hooks/useCSS.d.ts.map +1 -0
  198. package/lib/typescript/src/hooks/useCSS.native.d.ts +3 -0
  199. package/lib/typescript/src/hooks/useCSS.native.d.ts.map +1 -0
  200. package/lib/typescript/src/hooks/useInitialTheme.d.ts +3 -0
  201. package/lib/typescript/src/hooks/useInitialTheme.d.ts.map +1 -0
  202. package/lib/typescript/src/hooks/useUnistyles.d.ts +14 -0
  203. package/lib/typescript/src/hooks/useUnistyles.d.ts.map +1 -0
  204. package/lib/typescript/src/hooks/useVariants.d.ts +3 -0
  205. package/lib/typescript/src/hooks/useVariants.d.ts.map +1 -0
  206. package/lib/typescript/src/index.d.ts +76 -2
  207. package/lib/typescript/src/index.d.ts.map +1 -1
  208. package/lib/typescript/src/normalizer/index.d.ts +3 -0
  209. package/lib/typescript/src/normalizer/index.d.ts.map +1 -0
  210. package/lib/typescript/src/normalizer/normalizeStyle.d.ts +3 -0
  211. package/lib/typescript/src/normalizer/normalizeStyle.d.ts.map +1 -0
  212. package/lib/typescript/src/normalizer/normalizer.d.ts.map +1 -0
  213. package/lib/typescript/src/normalizer/normalizer.macos.d.ts +1 -0
  214. package/lib/typescript/src/normalizer/normalizer.macos.d.ts.map +1 -0
  215. package/lib/typescript/src/plugins/cssMediaQueriesPlugin.d.ts +3 -0
  216. package/lib/typescript/src/plugins/cssMediaQueriesPlugin.d.ts.map +1 -0
  217. package/lib/typescript/src/plugins/index.d.ts +3 -0
  218. package/lib/typescript/src/plugins/index.d.ts.map +1 -0
  219. package/lib/typescript/src/plugins/normalizeWebStylesPlugin.d.ts +3 -0
  220. package/lib/typescript/src/plugins/normalizeWebStylesPlugin.d.ts.map +1 -0
  221. package/lib/typescript/src/types/breakpoints.d.ts +25 -16
  222. package/lib/typescript/src/types/breakpoints.d.ts.map +1 -1
  223. package/lib/typescript/src/types/common.d.ts +3 -0
  224. package/lib/typescript/src/types/common.d.ts.map +1 -0
  225. package/lib/typescript/src/types/core.d.ts +11 -25
  226. package/lib/typescript/src/types/core.d.ts.map +1 -1
  227. package/lib/typescript/src/types/index.d.ts +7 -2
  228. package/lib/typescript/src/types/index.d.ts.map +1 -1
  229. package/lib/typescript/src/types/plugin.d.ts +7 -0
  230. package/lib/typescript/src/types/plugin.d.ts.map +1 -0
  231. package/lib/typescript/src/types/stylesheet.d.ts +40 -0
  232. package/lib/typescript/src/types/stylesheet.d.ts.map +1 -0
  233. package/lib/typescript/src/types/unistyles.d.ts +53 -0
  234. package/lib/typescript/src/types/unistyles.d.ts.map +1 -0
  235. package/lib/typescript/src/types/variants.d.ts +14 -0
  236. package/lib/typescript/src/types/variants.d.ts.map +1 -0
  237. package/lib/typescript/src/useStyles.d.ts +16 -0
  238. package/lib/typescript/src/useStyles.d.ts.map +1 -0
  239. package/lib/typescript/src/utils/breakpoints.d.ts +2 -62
  240. package/lib/typescript/src/utils/breakpoints.d.ts.map +1 -1
  241. package/lib/typescript/src/utils/cssMediaQuery.d.ts +4 -0
  242. package/lib/typescript/src/utils/cssMediaQuery.d.ts.map +1 -0
  243. package/lib/typescript/src/utils/generateId.d.ts +2 -0
  244. package/lib/typescript/src/utils/generateId.d.ts.map +1 -0
  245. package/lib/typescript/src/utils/hash32.d.ts +2 -0
  246. package/lib/typescript/src/utils/hash32.d.ts.map +1 -0
  247. package/lib/typescript/src/utils/index.d.ts +7 -6
  248. package/lib/typescript/src/utils/index.d.ts.map +1 -1
  249. package/lib/typescript/src/utils/mq.d.ts +26 -0
  250. package/lib/typescript/src/utils/mq.d.ts.map +1 -0
  251. package/lib/typescript/src/utils/mqParser.d.ts +16 -0
  252. package/lib/typescript/src/utils/mqParser.d.ts.map +1 -0
  253. package/lib/typescript/src/utils/styles.d.ts +4 -49
  254. package/lib/typescript/src/utils/styles.d.ts.map +1 -1
  255. package/lib/typescript/src/utils/withPlugins.d.ts +3 -0
  256. package/lib/typescript/src/utils/withPlugins.d.ts.map +1 -0
  257. package/package.json +46 -25
  258. package/react-native-unistyles.podspec +22 -0
  259. package/src/__tests__/mocks.ts +24 -0
  260. package/src/common.ts +55 -0
  261. package/src/core/UnistyleRegistry.ts +108 -0
  262. package/src/core/Unistyles.ts +35 -0
  263. package/src/core/UnistylesModule.native.ts +7 -0
  264. package/src/core/UnistylesModule.ts +230 -0
  265. package/src/core/UnistylesRuntime.ts +135 -0
  266. package/src/core/index.ts +2 -0
  267. package/src/createStyleSheet.ts +8 -0
  268. package/src/global.ts +6 -0
  269. package/src/hooks/index.ts +4 -1
  270. package/src/hooks/useCSS.native.ts +3 -0
  271. package/src/hooks/useCSS.ts +51 -0
  272. package/src/hooks/useInitialTheme.ts +11 -0
  273. package/src/hooks/useUnistyles.ts +64 -0
  274. package/src/hooks/useVariants.ts +10 -0
  275. package/src/index.ts +50 -2
  276. package/src/normalizer/index.ts +2 -0
  277. package/src/{utils/normalizeStyles.web.ts → normalizer/normalizeStyle.ts} +3 -3
  278. package/src/normalizer/normalizer.macos.ts +1 -0
  279. package/src/{utils → normalizer}/normalizer.ts +5 -4
  280. package/src/plugins/cssMediaQueriesPlugin.ts +8 -0
  281. package/src/plugins/index.ts +2 -0
  282. package/src/plugins/normalizeWebStylesPlugin.ts +7 -0
  283. package/src/types/breakpoints.ts +55 -27
  284. package/src/types/common.ts +2 -0
  285. package/src/types/core.ts +11 -36
  286. package/src/types/index.ts +12 -7
  287. package/src/types/plugin.ts +7 -0
  288. package/src/types/stylesheet.ts +49 -0
  289. package/src/types/unistyles.ts +63 -0
  290. package/src/types/variants.ts +19 -0
  291. package/src/useStyles.ts +60 -0
  292. package/src/utils/breakpoints.ts +28 -124
  293. package/src/utils/cssMediaQuery.ts +268 -0
  294. package/src/utils/generateId.ts +10 -0
  295. package/src/utils/hash32.ts +53 -0
  296. package/src/utils/index.ts +7 -13
  297. package/src/utils/mq.ts +57 -0
  298. package/src/utils/mqParser.ts +99 -0
  299. package/src/utils/styles.ts +62 -102
  300. package/src/utils/withPlugins.ts +13 -0
  301. package/lib/commonjs/UnistylesTheme.js +0 -21
  302. package/lib/commonjs/UnistylesTheme.js.map +0 -1
  303. package/lib/commonjs/createUnistyles.js +0 -57
  304. package/lib/commonjs/createUnistyles.js.map +0 -1
  305. package/lib/commonjs/hooks/useDimensions.js +0 -10
  306. package/lib/commonjs/hooks/useDimensions.js.map +0 -1
  307. package/lib/commonjs/hooks/useDimensions.web.js +0 -34
  308. package/lib/commonjs/hooks/useDimensions.web.js.map +0 -1
  309. package/lib/commonjs/types/mediaQueries.js +0 -2
  310. package/lib/commonjs/utils/common.js +0 -18
  311. package/lib/commonjs/utils/common.js.map +0 -1
  312. package/lib/commonjs/utils/mediaQueries.js +0 -189
  313. package/lib/commonjs/utils/mediaQueries.js.map +0 -1
  314. package/lib/commonjs/utils/normalizeStyles.js +0 -10
  315. package/lib/commonjs/utils/normalizeStyles.js.map +0 -1
  316. package/lib/commonjs/utils/normalizeStyles.web.js.map +0 -1
  317. package/lib/commonjs/utils/normalizer.js.map +0 -1
  318. package/lib/module/UnistylesTheme.js +0 -12
  319. package/lib/module/UnistylesTheme.js.map +0 -1
  320. package/lib/module/createUnistyles.js +0 -50
  321. package/lib/module/createUnistyles.js.map +0 -1
  322. package/lib/module/hooks/useDimensions.js +0 -3
  323. package/lib/module/hooks/useDimensions.js.map +0 -1
  324. package/lib/module/hooks/useDimensions.web.js +0 -27
  325. package/lib/module/hooks/useDimensions.web.js.map +0 -1
  326. package/lib/module/types/mediaQueries.js +0 -2
  327. package/lib/module/utils/common.js +0 -10
  328. package/lib/module/utils/common.js.map +0 -1
  329. package/lib/module/utils/mediaQueries.js +0 -176
  330. package/lib/module/utils/mediaQueries.js.map +0 -1
  331. package/lib/module/utils/normalizeStyles.js +0 -3
  332. package/lib/module/utils/normalizeStyles.js.map +0 -1
  333. package/lib/module/utils/normalizeStyles.web.js.map +0 -1
  334. package/lib/module/utils/normalizer.js.map +0 -1
  335. package/lib/typescript/examples/expo/src/App.d.ts +0 -3
  336. package/lib/typescript/examples/expo/src/App.d.ts.map +0 -1
  337. package/lib/typescript/examples/expo/src/examples/Breakpoints.d.ts +0 -3
  338. package/lib/typescript/examples/expo/src/examples/Breakpoints.d.ts.map +0 -1
  339. package/lib/typescript/examples/expo/src/examples/EmptyStyles.d.ts +0 -3
  340. package/lib/typescript/examples/expo/src/examples/EmptyStyles.d.ts.map +0 -1
  341. package/lib/typescript/examples/expo/src/examples/Extreme.d.ts +0 -7
  342. package/lib/typescript/examples/expo/src/examples/Extreme.d.ts.map +0 -1
  343. package/lib/typescript/examples/expo/src/examples/MediaQueries.d.ts +0 -3
  344. package/lib/typescript/examples/expo/src/examples/MediaQueries.d.ts.map +0 -1
  345. package/lib/typescript/examples/expo/src/examples/Memoization.d.ts +0 -3
  346. package/lib/typescript/examples/expo/src/examples/Memoization.d.ts.map +0 -1
  347. package/lib/typescript/examples/expo/src/examples/Minimal.d.ts +0 -3
  348. package/lib/typescript/examples/expo/src/examples/Minimal.d.ts.map +0 -1
  349. package/lib/typescript/examples/expo/src/examples/MinimalWithCreateStyleSheet.d.ts +0 -3
  350. package/lib/typescript/examples/expo/src/examples/MinimalWithCreateStyleSheet.d.ts.map +0 -1
  351. package/lib/typescript/examples/expo/src/examples/Theme.d.ts +0 -3
  352. package/lib/typescript/examples/expo/src/examples/Theme.d.ts.map +0 -1
  353. package/lib/typescript/examples/expo/src/examples/index.d.ts +0 -8
  354. package/lib/typescript/examples/expo/src/examples/index.d.ts.map +0 -1
  355. package/lib/typescript/examples/expo/src/index.d.ts +0 -2
  356. package/lib/typescript/examples/expo/src/index.d.ts.map +0 -1
  357. package/lib/typescript/examples/expo/src/styles/breakpoints.d.ts +0 -8
  358. package/lib/typescript/examples/expo/src/styles/breakpoints.d.ts.map +0 -1
  359. package/lib/typescript/examples/expo/src/styles/index.d.ts +0 -46
  360. package/lib/typescript/examples/expo/src/styles/index.d.ts.map +0 -1
  361. package/lib/typescript/examples/expo/src/styles/theme.d.ts +0 -24
  362. package/lib/typescript/examples/expo/src/styles/theme.d.ts.map +0 -1
  363. package/lib/typescript/src/UnistylesTheme.d.ts +0 -9
  364. package/lib/typescript/src/UnistylesTheme.d.ts.map +0 -1
  365. package/lib/typescript/src/createUnistyles.d.ts +0 -10
  366. package/lib/typescript/src/createUnistyles.d.ts.map +0 -1
  367. package/lib/typescript/src/hooks/useDimensions.d.ts +0 -3
  368. package/lib/typescript/src/hooks/useDimensions.d.ts.map +0 -1
  369. package/lib/typescript/src/hooks/useDimensions.web.d.ts +0 -3
  370. package/lib/typescript/src/hooks/useDimensions.web.d.ts.map +0 -1
  371. package/lib/typescript/src/types/mediaQueries.d.ts +0 -8
  372. package/lib/typescript/src/types/mediaQueries.d.ts.map +0 -1
  373. package/lib/typescript/src/utils/common.d.ts +0 -5
  374. package/lib/typescript/src/utils/common.d.ts.map +0 -1
  375. package/lib/typescript/src/utils/mediaQueries.d.ts +0 -130
  376. package/lib/typescript/src/utils/mediaQueries.d.ts.map +0 -1
  377. package/lib/typescript/src/utils/normalizeStyles.d.ts +0 -2
  378. package/lib/typescript/src/utils/normalizeStyles.d.ts.map +0 -1
  379. package/lib/typescript/src/utils/normalizeStyles.web.d.ts +0 -5
  380. package/lib/typescript/src/utils/normalizeStyles.web.d.ts.map +0 -1
  381. package/lib/typescript/src/utils/normalizer.d.ts.map +0 -1
  382. package/src/UnistylesTheme.tsx +0 -17
  383. package/src/__tests__/createUnistyles.spec.tsx +0 -192
  384. package/src/createUnistyles.ts +0 -70
  385. package/src/hooks/useDimensions.ts +0 -4
  386. package/src/hooks/useDimensions.web.ts +0 -34
  387. package/src/types/mediaQueries.ts +0 -10
  388. package/src/utils/common.ts +0 -12
  389. package/src/utils/mediaQueries.ts +0 -201
  390. package/src/utils/normalizeStyles.ts +0 -2
  391. /package/lib/commonjs/{utils → normalizer}/module.d.js +0 -0
  392. /package/lib/module/{utils → normalizer}/module.d.js +0 -0
  393. /package/lib/typescript/src/{utils → normalizer}/normalizer.d.ts +0 -0
  394. /package/src/{utils → normalizer}/module.d.ts +0 -0
@@ -1 +0,0 @@
1
- {"version":3,"file":"normalizeStyles.d.ts","sourceRoot":"","sources":["../../../../src/utils/normalizeStyles.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,eAAe,qBAAgC,CAAA"}
@@ -1,5 +0,0 @@
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;
5
- //# sourceMappingURL=normalizeStyles.web.d.ts.map
@@ -1 +0,0 @@
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"}
@@ -1 +0,0 @@
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,17 +0,0 @@
1
- import React, { createContext } from 'react'
2
- import type { PropsWithChildren } from 'react'
3
-
4
- interface UnistylesThemeProps extends PropsWithChildren {
5
- theme: any
6
- }
7
-
8
- export const UnistylesContext = createContext({})
9
-
10
- export const UnistylesTheme: React.FunctionComponent<UnistylesThemeProps> = ({
11
- theme,
12
- children
13
- }) => (
14
- <UnistylesContext.Provider value={theme}>
15
- {children}
16
- </UnistylesContext.Provider>
17
- )
@@ -1,192 +0,0 @@
1
- import React from 'react'
2
- import { StyleSheet } from 'react-native'
3
- import type { ViewStyle } from 'react-native'
4
- import { renderHook } from '@testing-library/react-hooks'
5
- import { createUnistyles } from '../createUnistyles'
6
- import { UnistylesTheme } from '../UnistylesTheme'
7
- import type { CustomNamedStyles } from '../types'
8
-
9
- jest.mock('../hooks', () => ({
10
- useDimensions: jest.fn(() => ({
11
- width: 500,
12
- height: 1000
13
- }))
14
- }))
15
-
16
- describe('createUnistyles', () => {
17
- describe('createStyleSheet', () => {
18
- it('should work exactly the same like StyleSheet.create', () => {
19
- const breakpoints = {
20
- xs: 0
21
- }
22
- const { createStyleSheet } = createUnistyles(breakpoints)
23
-
24
- const styles = {
25
- container: {
26
- flex: 1,
27
- justifyContent: 'center',
28
- alignItems: 'center'
29
- },
30
- text: {
31
- fontWeight: 'bold',
32
- fontSize: 32
33
- }
34
- } as const
35
-
36
- expect(createStyleSheet(styles)).toEqual(StyleSheet.create(styles))
37
- })
38
-
39
- it('should inject the theme to the createStyleSheet', () => {
40
- const theme = {
41
- colors: {
42
- barbie: '#ff9ff3',
43
- oak: '#1dd1a1',
44
- sky: '#48dbfb',
45
- fog: '#c8d6e5',
46
- aloes: '#00d2d3'
47
- }
48
- }
49
- const breakpoints = {
50
- xs: 0
51
- }
52
- const { useStyles, createStyleSheet } = createUnistyles<typeof breakpoints, typeof theme>(breakpoints)
53
- const stylesheet = createStyleSheet(theme => ({
54
- container: {
55
- backgroundColor: theme.colors.barbie
56
- }
57
- }))
58
- const { result } = renderHook(() => useStyles(stylesheet), {
59
- // @ts-ignore
60
- wrapper: ({ children }) => (
61
- <UnistylesTheme theme={theme}>
62
- {children}
63
- </UnistylesTheme>
64
- )
65
- })
66
-
67
- expect(result.current.theme).toEqual(theme)
68
- expect(result.current.styles).not.toBe(Function)
69
- expect(result.current.styles.container.backgroundColor).toEqual(theme.colors.barbie)
70
- })
71
- })
72
-
73
- describe('useStyles', () => {
74
- it('should return empty object for optional stylesheet', () => {
75
- const breakpoints = {
76
- xs: 0
77
- }
78
- const { useStyles } = createUnistyles(breakpoints)
79
- const { result } = renderHook(() => useStyles())
80
-
81
- expect(result.current.styles).toEqual({})
82
- expect(result.current.theme).toEqual({})
83
- })
84
-
85
- it ('should choose single value from breakpoints', () => {
86
- const breakpoints = {
87
- xs: 0,
88
- sm: 200,
89
- md: 500,
90
- lg: 1000
91
- }
92
-
93
- const { useStyles, createStyleSheet } = createUnistyles(breakpoints)
94
- const stylesheet = createStyleSheet({
95
- container: {
96
- flex: 1,
97
- justifyContent: 'center',
98
- alignItems: {
99
- xs: 'row',
100
- md: 'column'
101
- }
102
- }
103
- })
104
- const { result } = renderHook(() => useStyles(stylesheet))
105
-
106
- expect(result.current.styles.container.alignItems).toEqual('column')
107
- })
108
-
109
- it ('should choose single value from media queries', () => {
110
- const breakpoints = {
111
- xs: 0
112
- }
113
-
114
- const { useStyles, createStyleSheet } = createUnistyles(breakpoints)
115
- const stylesheet = createStyleSheet({
116
- container: {
117
- flex: 1,
118
- justifyContent: 'center',
119
- alignItems: {
120
- xs: 'row',
121
- ':w[300, 490]': 'column',
122
- ':w[491]': 'row'
123
- }
124
- }
125
- })
126
- const { result } = renderHook(() => useStyles(stylesheet as CustomNamedStyles<typeof stylesheet, typeof breakpoints>))
127
-
128
- expect(result.current.styles.container.alignItems).toEqual('row')
129
- })
130
-
131
- it ('should choose wrap dynamic functions in Proxy', () => {
132
- const breakpoints = {
133
- xs: 0
134
- }
135
-
136
- const { useStyles, createStyleSheet } = createUnistyles<typeof breakpoints, {}>(breakpoints)
137
- const stylesheet = createStyleSheet({
138
- container: (flex: number) => ({
139
- flex,
140
- justifyContent: 'center',
141
- alignItems: {
142
- xs: 'row',
143
- ':w[300, 490]': 'column',
144
- ':w[491]': 'row'
145
- }
146
- })
147
- })
148
- const { result } = renderHook(() => useStyles(stylesheet as CustomNamedStyles<typeof stylesheet, typeof breakpoints>))
149
-
150
- expect(result.current.styles.container).toBeInstanceOf(Function)
151
- expect((result.current.styles.container as (flex: number) => ViewStyle)(2)).toEqual({
152
- flex: 2,
153
- justifyContent: 'center',
154
- alignItems: 'row'
155
- })
156
- })
157
-
158
- it ('should return breakpoint even if no stylesheet has been provided', () => {
159
- const breakpoints = {
160
- xs: 0,
161
- sm: 200,
162
- md: 500,
163
- lg: 1000
164
- }
165
-
166
- const { useStyles } = createUnistyles<typeof breakpoints, {}>(breakpoints)
167
- const { result } = renderHook(() => useStyles())
168
-
169
- expect(result.current.breakpoint).toEqual('md')
170
- })
171
-
172
- it ('should return breakpoint for stylesheet', () => {
173
- const breakpoints = {
174
- xs: 0,
175
- sm: 200,
176
- lg: 1000
177
- }
178
-
179
- const { useStyles, createStyleSheet } = createUnistyles<typeof breakpoints, {}>(breakpoints)
180
- const stylesheet = createStyleSheet({
181
- container: {
182
- flex: 1,
183
- justifyContent: 'center',
184
- alignItems: 'center'
185
- }
186
- })
187
- const { result } = renderHook(() => useStyles(stylesheet as CustomNamedStyles<typeof stylesheet, typeof breakpoints>))
188
-
189
- expect(result.current.breakpoint).toEqual('sm')
190
- })
191
- })
192
- })
@@ -1,70 +0,0 @@
1
- import { useContext, useMemo } from 'react'
2
- import { StyleSheet } from 'react-native'
3
- import type {
4
- Breakpoints,
5
- CreateStylesFactory,
6
- CustomNamedStyles,
7
- ExtractBreakpoints,
8
- RemoveKeysWithPrefix,
9
- SortedBreakpointEntries
10
- } from './types'
11
- import { UnistylesContext } from './UnistylesTheme'
12
- import { useDimensions } from './hooks'
13
- import { getBreakpointFromScreenWidth, proxifyFunction, parseStyle, sortAndValidateBreakpoints } from './utils'
14
-
15
- export const createUnistyles = <B extends Breakpoints, T = {}>(breakpoints: B) => {
16
- const sortedBreakpoints = sortAndValidateBreakpoints(breakpoints)
17
- const sortedBreakpointEntries = Object
18
- .entries(sortedBreakpoints) as SortedBreakpointEntries<B>
19
-
20
- return {
21
- createStyleSheet: <S extends CustomNamedStyles<S, B>, X>(styles: S | CustomNamedStyles<S, B> | X | ((theme: T) => X | CustomNamedStyles<X, B>)): S | X => {
22
- if (typeof styles === 'function') {
23
- return styles as X
24
- }
25
-
26
- return styles as S
27
- },
28
- useStyles: <ST extends CustomNamedStyles<ST, B>>(stylesheet?: ST | CreateStylesFactory<ST, T>) => {
29
- const theme = useContext(UnistylesContext) as T
30
- const screenSize = useDimensions()
31
- const breakpoint = getBreakpointFromScreenWidth<B>(screenSize.width, sortedBreakpointEntries)
32
-
33
- if (!stylesheet) {
34
- return {
35
- theme,
36
- breakpoint,
37
- styles: {} as ExtractBreakpoints<RemoveKeysWithPrefix<ST, B>, B>
38
- }
39
- }
40
-
41
- const parsedStyles = useMemo(() => typeof stylesheet === 'function'
42
- ? stylesheet(theme)
43
- : stylesheet, [theme, stylesheet])
44
-
45
- const dynamicStyleSheet = useMemo(() => Object
46
- .entries(parsedStyles)
47
- .reduce((acc, [key, value]) => {
48
- const style = value as CustomNamedStyles<ST, B>
49
-
50
- if (typeof value === 'function') {
51
- return {
52
- ...acc,
53
- [key]: proxifyFunction<B>(value, breakpoint, screenSize, sortedBreakpointEntries)
54
- }
55
- }
56
-
57
- return StyleSheet.create({
58
- ...acc,
59
- [key]: parseStyle<ST, B>(style, breakpoint, screenSize, sortedBreakpointEntries)
60
- })
61
- }, {} as ST), [breakpoint, screenSize, parsedStyles])
62
-
63
- return {
64
- theme,
65
- breakpoint,
66
- styles: dynamicStyleSheet as ExtractBreakpoints<RemoveKeysWithPrefix<ST, B>, B>
67
- }
68
- }
69
- }
70
- }
@@ -1,4 +0,0 @@
1
- import { useWindowDimensions } from 'react-native'
2
- import type { ScreenSize } from '../types'
3
-
4
- export const useDimensions = (): ScreenSize => useWindowDimensions()
@@ -1,34 +0,0 @@
1
- import { useEffect, useLayoutEffect, useRef, useState } from 'react'
2
- import type { ScreenSize } from '../types'
3
-
4
- export const useDimensions = (): ScreenSize => {
5
- const timerRef = useRef<ReturnType<typeof setTimeout>>()
6
- const [screenSize, setScreenSize] = useState<ScreenSize>({} as ScreenSize)
7
-
8
- useLayoutEffect(() => {
9
- setScreenSize({
10
- width: window.innerWidth,
11
- height: window.innerHeight
12
- })
13
- }, [])
14
-
15
- useEffect(() => {
16
- const handleResize = () => {
17
- clearTimeout(timerRef.current)
18
-
19
- timerRef.current = setTimeout(() => setScreenSize({
20
- width: window.innerWidth,
21
- height: window.innerHeight
22
- }), 100)
23
- }
24
-
25
- window.addEventListener('resize', handleResize)
26
-
27
- return () => {
28
- window.removeEventListener('resize', handleResize)
29
- clearTimeout(timerRef.current)
30
- }
31
- }, [])
32
-
33
- return screenSize
34
- }
@@ -1,10 +0,0 @@
1
- type Optional<TOptional extends string> = TOptional | ''
2
- type Separator = ',' | ', '
3
- // this is super weird, but number passes empty string and bigint does not
4
- type MediaQuery = `[${Separator}${bigint}]` | `[${bigint}${Optional<`${Separator}${bigint}`>}]`
5
- type WidthMediaQuery = `:w${MediaQuery}`
6
- type HeightMediaQuery = `:h${MediaQuery}`
7
-
8
- export type MediaQueries =
9
- | `${WidthMediaQuery}${Optional<HeightMediaQuery>}`
10
- | `${HeightMediaQuery}${Optional<WidthMediaQuery>}`
@@ -1,12 +0,0 @@
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 isServer = typeof window === 'undefined'
@@ -1,201 +0,0 @@
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
- }
@@ -1,2 +0,0 @@
1
- // nothing to do here
2
- export const normalizeStyles = <T>(styles: T) => styles as T
File without changes
File without changes
File without changes