@niibase/uniwind 1.6.3 → 1.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (326) hide show
  1. package/CHANGELOG.md +58 -0
  2. package/dist/common/{css → bundler/artifacts/css}/index.js +1 -4
  3. package/dist/common/{css → bundler/artifacts/css}/themes.js +1 -1
  4. package/dist/common/{utils/buildDtsFile.js → bundler/artifacts/dts.js} +1 -2
  5. package/dist/common/bundler/config.js +69 -0
  6. package/dist/common/bundler/css-compiler/compileCSS.js +18 -0
  7. package/dist/common/bundler/css-compiler/compileNativeCSS.js +19 -0
  8. package/dist/common/bundler/css-compiler/compileTailwind.js +27 -0
  9. package/dist/common/bundler/css-compiler/compileWebCSS.js +15 -0
  10. package/dist/common/{vite → bundler/css-compiler}/index.js +4 -4
  11. package/dist/common/bundler/css-processor/addMetaToStylesTemplate.js +130 -0
  12. package/dist/common/bundler/css-processor/animation.js +112 -0
  13. package/dist/common/bundler/css-processor/color.js +66 -0
  14. package/dist/common/bundler/css-processor/css.js +510 -0
  15. package/dist/common/bundler/css-processor/functions.js +145 -0
  16. package/dist/common/bundler/css-processor/index.js +38 -0
  17. package/dist/common/bundler/css-processor/mq.js +87 -0
  18. package/dist/common/bundler/css-processor/processor.js +353 -0
  19. package/dist/common/bundler/css-processor/rn.js +356 -0
  20. package/dist/common/bundler/css-processor/serialize.js +86 -0
  21. package/dist/common/bundler/css-processor/types.js +1 -0
  22. package/dist/common/bundler/css-processor/units.js +55 -0
  23. package/dist/common/bundler/css-processor/utils.js +63 -0
  24. package/dist/common/bundler/css-processor/var.js +20 -0
  25. package/dist/common/{css-visitor → bundler/css-visitor}/rule-visitor.js +5 -5
  26. package/dist/common/{css-visitor → bundler/css-visitor}/visitor.js +5 -6
  27. package/dist/common/bundler/logger.js +41 -0
  28. package/dist/common/bundler/types.js +1 -0
  29. package/dist/common/common/consts.js +26 -2
  30. package/dist/common/components/index.js +0 -3
  31. package/dist/common/components/web/rnw.js +2 -2
  32. package/dist/common/core/config/config.common.js +15 -9
  33. package/dist/common/core/config/config.js +2 -2
  34. package/dist/common/core/config/config.native.js +3 -3
  35. package/dist/common/core/listener.js +10 -10
  36. package/dist/common/core/native/runtime.js +7 -3
  37. package/dist/common/core/native/store.js +3 -4
  38. package/dist/common/core/web/cssListener.js +2 -2
  39. package/dist/common/hoc/withUniwind.js +5 -5
  40. package/dist/common/hoc/withUniwind.native.js +5 -5
  41. package/dist/common/hooks/useCSSVariable/index.js +7 -11
  42. package/dist/common/hooks/useCSSVariable/useCSSVariable.js +26 -18
  43. package/dist/common/hooks/useUniwind.js +2 -2
  44. package/dist/metro/index.cjs +14 -24
  45. package/dist/metro/index.d.ts +2 -0
  46. package/dist/metro/index.mjs +7 -17
  47. package/dist/metro/{metro-transformer.cjs → transformer.cjs} +306 -173
  48. package/dist/metro/{metro-transformer.mjs → transformer.mjs} +249 -116
  49. package/dist/module/{css → bundler/artifacts/css}/index.d.ts +1 -1
  50. package/dist/module/{css → bundler/artifacts/css}/index.js +1 -4
  51. package/dist/module/{css → bundler/artifacts/css}/themes.js +1 -1
  52. package/dist/module/{utils/buildDtsFile.js → bundler/artifacts/dts.js} +3 -4
  53. package/dist/module/bundler/config.d.ts +16 -0
  54. package/dist/module/bundler/config.js +69 -0
  55. package/dist/module/bundler/css-compiler/compileCSS.d.ts +2 -0
  56. package/dist/module/bundler/css-compiler/compileCSS.js +11 -0
  57. package/dist/module/bundler/css-compiler/compileNativeCSS.d.ts +2 -0
  58. package/dist/module/bundler/css-compiler/compileNativeCSS.js +33 -0
  59. package/dist/module/bundler/css-compiler/compileTailwind.d.ts +2 -0
  60. package/dist/module/bundler/css-compiler/compileTailwind.js +22 -0
  61. package/dist/module/bundler/css-compiler/compileWebCSS.d.ts +2 -0
  62. package/dist/module/bundler/css-compiler/compileWebCSS.js +8 -0
  63. package/dist/module/bundler/css-compiler/index.d.ts +1 -0
  64. package/dist/module/bundler/css-compiler/index.js +1 -0
  65. package/dist/module/bundler/css-processor/addMetaToStylesTemplate.d.ts +3 -0
  66. package/dist/module/bundler/css-processor/addMetaToStylesTemplate.js +136 -0
  67. package/dist/module/bundler/css-processor/animation.d.ts +6 -0
  68. package/dist/module/bundler/css-processor/animation.js +112 -0
  69. package/dist/module/bundler/css-processor/color.d.ts +12 -0
  70. package/dist/module/bundler/css-processor/color.js +63 -0
  71. package/dist/module/bundler/css-processor/css.d.ts +23 -0
  72. package/dist/module/bundler/css-processor/css.js +566 -0
  73. package/dist/module/bundler/css-processor/functions.d.ts +12 -0
  74. package/dist/module/bundler/css-processor/functions.js +190 -0
  75. package/dist/module/bundler/css-processor/index.d.ts +3 -0
  76. package/dist/module/bundler/css-processor/index.js +3 -0
  77. package/dist/module/bundler/css-processor/mq.d.ts +12 -0
  78. package/dist/module/bundler/css-processor/mq.js +78 -0
  79. package/dist/module/bundler/css-processor/processor.d.ts +36 -0
  80. package/dist/module/bundler/css-processor/processor.js +336 -0
  81. package/dist/module/bundler/css-processor/rn.d.ts +10 -0
  82. package/dist/module/bundler/css-processor/rn.js +400 -0
  83. package/dist/module/bundler/css-processor/serialize.d.ts +2 -0
  84. package/dist/module/bundler/css-processor/serialize.js +101 -0
  85. package/dist/module/bundler/css-processor/types.d.ts +28 -0
  86. package/dist/module/bundler/css-processor/types.js +0 -0
  87. package/dist/module/bundler/css-processor/units.d.ts +10 -0
  88. package/dist/module/bundler/css-processor/units.js +48 -0
  89. package/dist/module/bundler/css-processor/utils.d.ts +24 -0
  90. package/dist/{shared/uniwind.PtWWxxnh.mjs → module/bundler/css-processor/utils.js} +11 -15
  91. package/dist/module/bundler/css-processor/var.d.ts +7 -0
  92. package/dist/module/bundler/css-processor/var.js +13 -0
  93. package/dist/module/{css-visitor → bundler/css-visitor}/function-visitor.d.ts +1 -1
  94. package/dist/module/{css-visitor → bundler/css-visitor}/rule-visitor.d.ts +4 -3
  95. package/dist/module/{css-visitor → bundler/css-visitor}/rule-visitor.js +5 -5
  96. package/dist/module/{css-visitor → bundler/css-visitor}/visitor.d.ts +3 -3
  97. package/dist/module/{css-visitor → bundler/css-visitor}/visitor.js +5 -6
  98. package/dist/module/bundler/logger.d.ts +11 -0
  99. package/dist/module/bundler/logger.js +34 -0
  100. package/dist/module/bundler/types.d.ts +15 -0
  101. package/dist/module/bundler/types.js +0 -0
  102. package/dist/module/common/consts.d.ts +21 -0
  103. package/dist/module/common/consts.js +24 -0
  104. package/dist/module/components/ScopedTheme/ScopedTheme.native.d.ts +1 -1
  105. package/dist/module/components/index.js +0 -3
  106. package/dist/module/components/native/Pressable.d.ts +1 -1
  107. package/dist/module/components/native/TouchableHighlight.d.ts +1 -1
  108. package/dist/module/components/native/TouchableOpacity.d.ts +1 -1
  109. package/dist/module/components/native/useAccentColor.d.ts +1 -1
  110. package/dist/module/components/native/useStyle.d.ts +2 -2
  111. package/dist/module/components/react-native-gesture-handler/native/BaseButton.d.ts +1 -1
  112. package/dist/module/components/react-native-gesture-handler/native/BorderlessButton.d.ts +1 -1
  113. package/dist/module/components/react-native-gesture-handler/native/DrawerLayoutAndroid.d.ts +1 -1
  114. package/dist/module/components/react-native-gesture-handler/native/FlatList.d.ts +1 -1
  115. package/dist/module/components/react-native-gesture-handler/native/Pressable.d.ts +1 -1
  116. package/dist/module/components/react-native-gesture-handler/native/PureNativeButton.d.ts +1 -1
  117. package/dist/module/components/react-native-gesture-handler/native/RawButton.d.ts +1 -1
  118. package/dist/module/components/react-native-gesture-handler/native/RectButton.d.ts +1 -1
  119. package/dist/module/components/react-native-gesture-handler/native/RefreshControl.d.ts +1 -1
  120. package/dist/module/components/react-native-gesture-handler/native/ScrollView.d.ts +1 -1
  121. package/dist/module/components/react-native-gesture-handler/native/Switch.d.ts +1 -1
  122. package/dist/module/components/react-native-gesture-handler/native/TextInput.d.ts +1 -1
  123. package/dist/module/components/web/Pressable.d.ts +1 -1
  124. package/dist/module/components/web/TouchableHighlight.d.ts +1 -1
  125. package/dist/module/components/web/TouchableOpacity.d.ts +1 -1
  126. package/dist/module/components/web/rnw.js +1 -1
  127. package/dist/module/core/config/config.common.d.ts +7 -6
  128. package/dist/module/core/config/config.common.js +6 -2
  129. package/dist/module/core/config/config.d.ts +1 -1
  130. package/dist/module/core/config/config.js +1 -1
  131. package/dist/module/core/config/config.native.d.ts +2 -2
  132. package/dist/module/core/config/config.native.js +1 -1
  133. package/dist/module/core/listener.d.ts +1 -1
  134. package/dist/module/core/listener.js +1 -1
  135. package/dist/module/core/native/runtime.js +5 -1
  136. package/dist/module/core/native/store.d.ts +2 -2
  137. package/dist/module/core/native/store.js +1 -2
  138. package/dist/module/core/types.d.ts +6 -3
  139. package/dist/module/core/web/cssListener.js +1 -1
  140. package/dist/module/core/web/getWebStyles.d.ts +1 -1
  141. package/dist/module/hoc/types.d.ts +2 -2
  142. package/dist/module/hoc/withUniwind.d.ts +1 -1
  143. package/dist/module/hoc/withUniwind.js +5 -5
  144. package/dist/module/hoc/withUniwind.native.d.ts +1 -1
  145. package/dist/module/hoc/withUniwind.native.js +5 -5
  146. package/dist/module/hooks/useCSSVariable/getVariableValue.native.d.ts +1 -1
  147. package/dist/module/hooks/useCSSVariable/index.d.ts +1 -1
  148. package/dist/module/hooks/useCSSVariable/index.js +1 -1
  149. package/dist/module/hooks/useCSSVariable/useCSSVariable.d.ts +4 -2
  150. package/dist/module/hooks/useCSSVariable/useCSSVariable.js +23 -16
  151. package/dist/module/hooks/useResolveClassNames.d.ts +1 -1
  152. package/dist/module/hooks/useUniwind.d.ts +1 -1
  153. package/dist/module/hooks/useUniwind.js +1 -1
  154. package/dist/module/index.d.ts +1 -2
  155. package/dist/shared/{uniwind.r2i22V6d.cjs → uniwind.CFiAZ3D-.cjs} +307 -217
  156. package/dist/shared/{uniwind.BGiqYvxb.mjs → uniwind.u-s1XVU8.mjs} +299 -214
  157. package/dist/vite/index.cjs +12 -22
  158. package/dist/vite/index.mjs +9 -19
  159. package/package.json +1 -1
  160. package/src/{metro → bundler/adapters/metro}/index.d.ts +2 -0
  161. package/src/bundler/adapters/metro/index.ts +1 -0
  162. package/src/{metro/withUniwindConfig.ts → bundler/adapters/metro/metro.ts} +7 -22
  163. package/src/{metro/metro-css-patches.ts → bundler/adapters/metro/patches.ts} +2 -1
  164. package/src/{metro → bundler/adapters/metro}/resolvers.ts +8 -8
  165. package/src/bundler/adapters/metro/transformer.ts +85 -0
  166. package/src/{vite → bundler/adapters/vite}/vite.ts +10 -28
  167. package/src/{css → bundler/artifacts/css}/extraUtilities.ts +1 -1
  168. package/src/{css → bundler/artifacts/css}/index.ts +1 -5
  169. package/src/{css → bundler/artifacts/css}/themes.ts +1 -1
  170. package/src/{utils/buildDtsFile.ts → bundler/artifacts/dts.ts} +3 -4
  171. package/src/bundler/config.ts +84 -0
  172. package/src/bundler/css-compiler/compileCSS.ts +15 -0
  173. package/src/bundler/css-compiler/compileNativeCSS.ts +41 -0
  174. package/src/bundler/css-compiler/compileTailwind.ts +25 -0
  175. package/src/bundler/css-compiler/compileWebCSS.ts +10 -0
  176. package/src/bundler/css-compiler/index.ts +1 -0
  177. package/src/{metro → bundler/css-processor}/addMetaToStylesTemplate.ts +33 -14
  178. package/src/{metro/processor → bundler/css-processor}/animation.ts +4 -4
  179. package/src/{metro/processor → bundler/css-processor}/color.ts +4 -3
  180. package/src/{metro/processor → bundler/css-processor}/css.ts +17 -9
  181. package/src/{metro/processor → bundler/css-processor}/functions.ts +2 -2
  182. package/src/bundler/css-processor/index.ts +3 -0
  183. package/src/{metro/processor → bundler/css-processor}/mq.ts +4 -4
  184. package/src/{metro/processor → bundler/css-processor}/processor.ts +13 -11
  185. package/src/{metro/processor → bundler/css-processor}/rn.ts +115 -3
  186. package/src/{metro/utils → bundler/css-processor}/serialize.ts +2 -2
  187. package/src/{metro → bundler/css-processor}/types.ts +3 -17
  188. package/src/{metro/processor → bundler/css-processor}/units.ts +1 -1
  189. package/src/{metro/processor → bundler/css-processor}/var.ts +1 -1
  190. package/src/{css-visitor → bundler/css-visitor}/function-visitor.ts +1 -1
  191. package/src/{css-visitor → bundler/css-visitor}/rule-visitor.ts +6 -5
  192. package/src/{css-visitor → bundler/css-visitor}/visitor.ts +4 -3
  193. package/src/bundler/types.ts +17 -0
  194. package/src/common/consts.ts +25 -0
  195. package/src/components/ScopedTheme/ScopedTheme.native.tsx +1 -1
  196. package/src/components/index.ts +0 -3
  197. package/src/components/native/ActivityIndicator.tsx +2 -1
  198. package/src/components/native/Button.tsx +2 -1
  199. package/src/components/native/FlatList.tsx +2 -1
  200. package/src/components/native/Image.tsx +2 -1
  201. package/src/components/native/ImageBackground.tsx +2 -1
  202. package/src/components/native/InputAccessoryView.tsx +3 -2
  203. package/src/components/native/KeyboardAvoidingView.tsx +2 -1
  204. package/src/components/native/Modal.tsx +2 -1
  205. package/src/components/native/Pressable.tsx +1 -1
  206. package/src/components/native/RefreshControl.tsx +2 -1
  207. package/src/components/native/SafeAreaView.tsx +2 -1
  208. package/src/components/native/ScrollView.tsx +2 -1
  209. package/src/components/native/SectionList.tsx +2 -1
  210. package/src/components/native/Switch.tsx +3 -2
  211. package/src/components/native/Text.tsx +3 -2
  212. package/src/components/native/TextInput.tsx +3 -2
  213. package/src/components/native/TouchableHighlight.tsx +3 -2
  214. package/src/components/native/TouchableNativeFeedback.tsx +3 -2
  215. package/src/components/native/TouchableOpacity.tsx +3 -2
  216. package/src/components/native/TouchableWithoutFeedback.tsx +3 -2
  217. package/src/components/native/View.tsx +2 -1
  218. package/src/components/native/VirtualizedList.tsx +2 -1
  219. package/src/components/native/useAccentColor.ts +1 -1
  220. package/src/components/native/useStyle.ts +2 -2
  221. package/src/components/react-native-gesture-handler/native/BaseButton.tsx +1 -1
  222. package/src/components/react-native-gesture-handler/native/BorderlessButton.tsx +1 -1
  223. package/src/components/react-native-gesture-handler/native/DrawerLayoutAndroid.tsx +1 -1
  224. package/src/components/react-native-gesture-handler/native/FlatList.tsx +1 -1
  225. package/src/components/react-native-gesture-handler/native/GestureHandlerRootView.tsx +1 -1
  226. package/src/components/react-native-gesture-handler/native/Pressable.tsx +1 -1
  227. package/src/components/react-native-gesture-handler/native/PureNativeButton.tsx +1 -1
  228. package/src/components/react-native-gesture-handler/native/RawButton.tsx +1 -1
  229. package/src/components/react-native-gesture-handler/native/RectButton.tsx +1 -1
  230. package/src/components/react-native-gesture-handler/native/RefreshControl.tsx +1 -1
  231. package/src/components/react-native-gesture-handler/native/ScrollView.tsx +1 -1
  232. package/src/components/react-native-gesture-handler/native/Switch.tsx +2 -2
  233. package/src/components/react-native-gesture-handler/native/Text.tsx +2 -2
  234. package/src/components/react-native-gesture-handler/native/TextInput.tsx +2 -2
  235. package/src/components/react-native-gesture-handler/native/TouchableNativeFeedback.tsx +2 -2
  236. package/src/components/react-native-gesture-handler/native/TouchableOpacity.tsx +2 -2
  237. package/src/components/react-native-gesture-handler/native/TouchableWithoutFeedback.tsx +2 -2
  238. package/src/components/web/ActivityIndicator.tsx +2 -1
  239. package/src/components/web/Button.tsx +2 -1
  240. package/src/components/web/FlatList.tsx +2 -1
  241. package/src/components/web/Image.tsx +2 -1
  242. package/src/components/web/ImageBackground.tsx +2 -1
  243. package/src/components/web/KeyboardAvoidingView.tsx +2 -1
  244. package/src/components/web/Modal.tsx +2 -1
  245. package/src/components/web/Pressable.tsx +2 -1
  246. package/src/components/web/RefreshControl.tsx +2 -1
  247. package/src/components/web/SafeAreaView.tsx +2 -1
  248. package/src/components/web/ScrollView.tsx +2 -1
  249. package/src/components/web/SectionList.tsx +2 -1
  250. package/src/components/web/Switch.tsx +2 -1
  251. package/src/components/web/Text.tsx +2 -1
  252. package/src/components/web/TextInput.tsx +2 -1
  253. package/src/components/web/TouchableHighlight.tsx +2 -1
  254. package/src/components/web/TouchableOpacity.tsx +2 -1
  255. package/src/components/web/TouchableWithoutFeedback.tsx +2 -1
  256. package/src/components/web/View.tsx +2 -1
  257. package/src/components/web/VirtualizedList.tsx +2 -1
  258. package/src/components/web/rnw.ts +1 -1
  259. package/src/core/config/config.common.ts +15 -8
  260. package/src/core/config/config.native.ts +3 -3
  261. package/src/core/config/config.ts +2 -2
  262. package/src/core/listener.ts +1 -1
  263. package/src/core/native/runtime.ts +7 -2
  264. package/src/core/native/store.ts +3 -4
  265. package/src/core/types.ts +6 -3
  266. package/src/core/web/cssListener.ts +1 -1
  267. package/src/core/web/getWebStyles.ts +1 -1
  268. package/src/hoc/types.ts +2 -2
  269. package/src/hoc/withUniwind.native.tsx +4 -3
  270. package/src/hoc/withUniwind.tsx +3 -2
  271. package/src/hooks/useCSSVariable/getVariableValue.native.ts +1 -1
  272. package/src/hooks/useCSSVariable/index.ts +1 -1
  273. package/src/hooks/useCSSVariable/useCSSVariable.ts +34 -25
  274. package/src/hooks/useResolveClassNames.ts +1 -1
  275. package/src/hooks/useUniwind.ts +2 -2
  276. package/src/index.ts +1 -2
  277. package/dist/common/types.js +0 -28
  278. package/dist/common/utils/stringifyThemes.js +0 -8
  279. package/dist/common/vite/vite.js +0 -95
  280. package/dist/module/types.d.ts +0 -21
  281. package/dist/module/types.js +0 -22
  282. package/dist/module/utils/stringifyThemes.d.ts +0 -1
  283. package/dist/module/utils/stringifyThemes.js +0 -1
  284. package/dist/module/vite/index.d.ts +0 -9
  285. package/dist/module/vite/index.js +0 -1
  286. package/dist/module/vite/vite.d.ts +0 -8
  287. package/dist/module/vite/vite.js +0 -98
  288. package/dist/shared/uniwind.B5q8hBGv.cjs +0 -18
  289. package/dist/shared/uniwind.Cv73KtI-.cjs +0 -86
  290. package/dist/shared/uniwind.JSWK3vHl.mjs +0 -14
  291. package/src/metro/compileVirtual.ts +0 -85
  292. package/src/metro/index.ts +0 -1
  293. package/src/metro/injectThemes.ts +0 -23
  294. package/src/metro/metro-transformer.ts +0 -116
  295. package/src/metro/processor/index.ts +0 -1
  296. package/src/metro/utils/index.ts +0 -2
  297. package/src/types.ts +0 -23
  298. package/src/utils/stringifyThemes.ts +0 -1
  299. package/src/vite/index.d.ts +0 -9
  300. /package/dist/common/{css → bundler/artifacts/css}/extraUtilities.js +0 -0
  301. /package/dist/common/{css → bundler/artifacts/css}/insets.js +0 -0
  302. /package/dist/common/{css → bundler/artifacts/css}/overwrite.js +0 -0
  303. /package/dist/common/{css → bundler/artifacts/css}/variants.js +0 -0
  304. /package/dist/common/{css-visitor → bundler/css-visitor}/function-visitor.js +0 -0
  305. /package/dist/common/{css-visitor → bundler/css-visitor}/index.js +0 -0
  306. /package/dist/module/{css → bundler/artifacts/css}/extraUtilities.d.ts +0 -0
  307. /package/dist/module/{css → bundler/artifacts/css}/extraUtilities.js +0 -0
  308. /package/dist/module/{css → bundler/artifacts/css}/insets.d.ts +0 -0
  309. /package/dist/module/{css → bundler/artifacts/css}/insets.js +0 -0
  310. /package/dist/module/{css → bundler/artifacts/css}/overwrite.d.ts +0 -0
  311. /package/dist/module/{css → bundler/artifacts/css}/overwrite.js +0 -0
  312. /package/dist/module/{css → bundler/artifacts/css}/themes.d.ts +0 -0
  313. /package/dist/module/{css → bundler/artifacts/css}/variants.d.ts +0 -0
  314. /package/dist/module/{css → bundler/artifacts/css}/variants.js +0 -0
  315. /package/dist/module/{utils/buildDtsFile.d.ts → bundler/artifacts/dts.d.ts} +0 -0
  316. /package/dist/module/{css-visitor → bundler/css-visitor}/function-visitor.js +0 -0
  317. /package/dist/module/{css-visitor → bundler/css-visitor}/index.d.ts +0 -0
  318. /package/dist/module/{css-visitor → bundler/css-visitor}/index.js +0 -0
  319. /package/{dist/common → src/bundler/adapters}/vite/index.d.ts +0 -0
  320. /package/src/{vite → bundler/adapters/vite}/index.ts +0 -0
  321. /package/src/{css → bundler/artifacts/css}/insets.ts +0 -0
  322. /package/src/{css → bundler/artifacts/css}/overwrite.ts +0 -0
  323. /package/src/{css → bundler/artifacts/css}/variants.ts +0 -0
  324. /package/src/{metro/utils/common.ts → bundler/css-processor/utils.ts} +0 -0
  325. /package/src/{css-visitor → bundler/css-visitor}/index.ts +0 -0
  326. /package/src/{metro → bundler}/logger.ts +0 -0
@@ -1,12 +1,79 @@
1
- import fs from 'fs';
1
+ import { L as Logger, P as Platform, S as StyleDependency, i as isDefined, D as DEFAULT_SCREEN_HEIGHT, a as DEFAULT_SCREEN_WIDTH, b as UNIWIND_PLATFORM_VARIABLES, c as UNIWIND_THEME_VARIABLES, U as UniwindBundlerConfig, n as name } from '../shared/uniwind.u-s1XVU8.mjs';
2
2
  import path from 'path';
3
- import { p as pipe, r as roundToPrecision, i as isNumber, a as isValidJSValue, s as smartSplit, b as addMissingSpaces, t as toCamelCase, d as deepEqual, c as shouldBeSerialized, e as removeKeys, n as name } from '../shared/uniwind.PtWWxxnh.mjs';
4
- import { P as Platform, U as UNIWIND_PLATFORM_VARIABLES, a as UNIWIND_THEME_VARIABLES } from '../shared/uniwind.JSWK3vHl.mjs';
5
- import { compile } from '@tailwindcss/node';
6
- import { Scanner } from '@tailwindcss/oxide';
7
3
  import { transform as transform$1 } from 'lightningcss';
8
- import { L as Logger, U as UniwindCSSVisitor, s as stringifyThemes, b as buildDtsFile, a as buildCSS } from '../shared/uniwind.BGiqYvxb.mjs';
9
4
  import { converter, parse, formatHex, formatHex8 } from 'culori';
5
+ import { compile } from '@tailwindcss/node';
6
+ import { Scanner } from '@tailwindcss/oxide';
7
+ import fs from 'fs';
8
+
9
+ const toCamelCase = (str) => str.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
10
+ const pipe = (data) => ((...fns) => fns.reduce((acc, fn) => fn(acc), data));
11
+ const isNumber = (data) => {
12
+ if (typeof data === "number") {
13
+ return true;
14
+ }
15
+ if (typeof data === "string" && data !== "") {
16
+ return !isNaN(Number(data));
17
+ }
18
+ return false;
19
+ };
20
+ const smartSplit = (str, separator = " ") => {
21
+ const escaper = "&&&";
22
+ return pipe(str)(
23
+ (x) => x.replace(/\s\?\?\s/g, `${escaper}??${escaper}`),
24
+ (x) => x.replace(/\s([+\-*/])\s/g, `${escaper}$1${escaper}`),
25
+ (x) => x.split(separator),
26
+ (x) => x.map((token) => token.replace(new RegExp(escaper, "g"), " "))
27
+ );
28
+ };
29
+ const addMissingSpaces = (str) => pipe(str)(
30
+ (x) => x.trim(),
31
+ (x) => x.replace(/([^ {])this/g, "$1 this"),
32
+ (x) => x.replace(/\](?=\d)/g, "] "),
33
+ (x) => x.replace(/\](?=")/g, "] "),
34
+ (x) => x.replace(/\)(?=\S)/g, ") "),
35
+ (x) => x.replace(/(?<!^)(?<!\s)"(?=\d)/g, '" ')
36
+ );
37
+ const isValidJSValue = (jsValueString) => {
38
+ try {
39
+ new Function(`const test = ${jsValueString}`);
40
+ return true;
41
+ } catch {
42
+ return false;
43
+ }
44
+ };
45
+ const shouldBeSerialized = (value) => {
46
+ if (value.includes("-")) {
47
+ return value.split("-").some(shouldBeSerialized);
48
+ }
49
+ return [
50
+ isNumber(value),
51
+ value.startsWith("this["),
52
+ value.startsWith("rt."),
53
+ /[*/+-]/.test(value),
54
+ value.includes('"'),
55
+ value.includes(" "),
56
+ value === "(",
57
+ value === ")"
58
+ ].some(Boolean);
59
+ };
60
+ const roundToPrecision = (value, precision) => parseFloat(value.toFixed(precision));
61
+ const deepEqual = (a, b) => {
62
+ if (Object.is(a, b)) {
63
+ return true;
64
+ }
65
+ if (typeof a !== "object" || a === null || typeof b !== "object" || b === null) {
66
+ return false;
67
+ }
68
+ const keysA = Object.keys(a);
69
+ if (keysA.length !== Object.keys(b).length) {
70
+ return false;
71
+ }
72
+ return keysA.every((key) => deepEqual(a[key], b[key]) && Object.prototype.hasOwnProperty.call(b, key));
73
+ };
74
+ const removeKeys = (obj, keysToRemove) => Object.fromEntries(
75
+ Object.entries(obj).filter(([key]) => !keysToRemove.includes(key))
76
+ );
10
77
 
11
78
  const parseStringValue = (value) => {
12
79
  if (isValidJSValue(value)) {
@@ -107,21 +174,6 @@ const serializeJSObject = (obj, serializer) => {
107
174
  return serializedObject;
108
175
  };
109
176
 
110
- const isDefined = (value) => value !== void 0 && value !== null;
111
-
112
- var StyleDependency = /* @__PURE__ */ ((StyleDependency2) => {
113
- StyleDependency2[StyleDependency2["ColorScheme"] = 1] = "ColorScheme";
114
- StyleDependency2[StyleDependency2["Theme"] = 2] = "Theme";
115
- StyleDependency2[StyleDependency2["Dimensions"] = 3] = "Dimensions";
116
- StyleDependency2[StyleDependency2["Orientation"] = 4] = "Orientation";
117
- StyleDependency2[StyleDependency2["Insets"] = 5] = "Insets";
118
- StyleDependency2[StyleDependency2["FontScale"] = 6] = "FontScale";
119
- StyleDependency2[StyleDependency2["Rtl"] = 7] = "Rtl";
120
- StyleDependency2[StyleDependency2["AdaptiveThemes"] = 8] = "AdaptiveThemes";
121
- StyleDependency2[StyleDependency2["Variables"] = 9] = "Variables";
122
- return StyleDependency2;
123
- })(StyleDependency || {});
124
-
125
177
  const extractVarsFromString = (value) => {
126
178
  const thisIndexes = [...value.matchAll(/this\[/g)].map((m) => m.index);
127
179
  return thisIndexes.map((index) => {
@@ -140,6 +192,23 @@ const makeSafeForSerialization = (value) => {
140
192
  }
141
193
  return value;
142
194
  };
195
+ const hasThemedVarDependency = (varName, Processor, visited = /* @__PURE__ */ new Set()) => {
196
+ if (visited.has(varName)) {
197
+ return false;
198
+ }
199
+ visited.add(varName);
200
+ const isScopedVar = Object.values(Processor.scopedVars).some((scopedVars) => varName in scopedVars);
201
+ if (isScopedVar) {
202
+ return true;
203
+ }
204
+ const globalVarValue = Processor.vars[varName];
205
+ if (typeof globalVarValue !== "string") {
206
+ return false;
207
+ }
208
+ return extractVarsFromString(globalVarValue).some((usedVarName) => {
209
+ return hasThemedVarDependency(usedVarName, Processor, visited);
210
+ });
211
+ };
143
212
  const addMetaToStylesTemplate = (Processor, currentPlatform) => {
144
213
  const stylesheetsEntries = Object.entries(Processor.stylesheets).map(([className, stylesPerMediaQuery]) => {
145
214
  const styles = stylesPerMediaQuery.map((style, index) => {
@@ -173,12 +242,7 @@ const addMetaToStylesTemplate = (Processor, currentPlatform) => {
173
242
  const dependencies = [];
174
243
  const stringifiedEntries = JSON.stringify(entries);
175
244
  const usedVars = extractVarsFromString(stringifiedEntries);
176
- const isUsingThemedVar = usedVars.some((usedVarName) => {
177
- return Object.values(Processor.scopedVars).some((scopedVars) => {
178
- const scopedVarsNames = Object.keys(scopedVars);
179
- return scopedVarsNames.includes(usedVarName);
180
- });
181
- });
245
+ const isUsingThemedVar = usedVars.some((usedVarName) => hasThemedVarDependency(usedVarName, Processor));
182
246
  if (usedVars.length > 0) {
183
247
  dependencies.push(StyleDependency.Variables);
184
248
  }
@@ -191,7 +255,7 @@ const addMetaToStylesTemplate = (Processor, currentPlatform) => {
191
255
  if (rtl !== null) {
192
256
  dependencies.push(StyleDependency.Rtl);
193
257
  }
194
- if (Number(minWidth) !== 0 || Number(maxWidth) !== Number.MAX_VALUE || stringifiedEntries.includes("rt.screen")) {
258
+ if (Number(minWidth) !== 0 || Number(maxWidth) !== Number.MAX_VALUE || stringifiedEntries.includes("rt.makeResponsive") || stringifiedEntries.includes("rt.screen")) {
195
259
  dependencies.push(StyleDependency.Dimensions);
196
260
  }
197
261
  if (stringifiedEntries.includes("rt.insets")) {
@@ -215,7 +279,7 @@ const addMetaToStylesTemplate = (Processor, currentPlatform) => {
215
279
  active,
216
280
  focus,
217
281
  disabled,
218
- importantProperties: importantProperties?.map((property) => property.startsWith("--") ? property : toCamelCase).map(makeSafeForSerialization) ?? [],
282
+ importantProperties: importantProperties?.map((property) => property.startsWith("--") ? property : toCamelCase(property)).map(makeSafeForSerialization) ?? [],
219
283
  dataAttributes,
220
284
  complexity: [
221
285
  minWidth !== 0,
@@ -473,8 +537,8 @@ class CSS {
473
537
  this.Processor = Processor;
474
538
  }
475
539
  logger = new Logger("CSS");
476
- processValue(declarationValue) {
477
- const processedValue = this.getProcessedValue(declarationValue);
540
+ processValue(declarationValue, declarationProperty) {
541
+ const processedValue = this.getProcessedValue(declarationValue, declarationProperty);
478
542
  if (typeof processedValue === "string") {
479
543
  return this.makeSafeForSerialization(processedValue);
480
544
  }
@@ -545,7 +609,7 @@ class CSS {
545
609
  });
546
610
  return filterStrings.join(" ");
547
611
  }
548
- getProcessedValue(declarationValue) {
612
+ getProcessedValue(declarationValue, declarationProperty) {
549
613
  if (typeof declarationValue !== "object") {
550
614
  return declarationValue;
551
615
  }
@@ -830,11 +894,17 @@ class CSS {
830
894
  };
831
895
  }
832
896
  if ("grow" in declarationValue) {
833
- return {
897
+ const parsedFlex = {
834
898
  flexGrow: declarationValue.grow,
835
899
  flexShrink: declarationValue.shrink,
836
900
  flexBasis: this.processValue(declarationValue.basis)
837
901
  };
902
+ if (declarationProperty === "flex" && parsedFlex.flexGrow === 1 && parsedFlex.flexShrink === 1 && parsedFlex.flexBasis === '"0%"') {
903
+ return {
904
+ flex: 1
905
+ };
906
+ }
907
+ return parsedFlex;
838
908
  }
839
909
  if (Array.isArray(declarationValue)) {
840
910
  if (declarationValue.length === 1) {
@@ -1478,6 +1548,59 @@ const cssToRNMap = {
1478
1548
  };
1479
1549
  const BORDER_WIDTH_KEYS = ["borderTopWidth", "borderRightWidth", "borderBottomWidth", "borderLeftWidth"];
1480
1550
  const BORDER_COLOR_KEYS = ["borderTopColor", "borderRightColor", "borderBottomColor", "borderLeftColor"];
1551
+ const BORDER_RADIUS_KEYS = ["borderTopLeftRadius", "borderTopRightRadius", "borderBottomLeftRadius", "borderBottomRightRadius"];
1552
+ const COMPONENT_RESPONSIVE_PROPS = /* @__PURE__ */ new Set([
1553
+ "width",
1554
+ "height",
1555
+ "minWidth",
1556
+ "maxWidth",
1557
+ "minHeight",
1558
+ "maxHeight",
1559
+ "padding",
1560
+ "paddingTop",
1561
+ "paddingRight",
1562
+ "paddingBottom",
1563
+ "paddingLeft",
1564
+ "paddingHorizontal",
1565
+ "paddingVertical",
1566
+ "paddingStart",
1567
+ "paddingEnd",
1568
+ "margin",
1569
+ "marginTop",
1570
+ "marginRight",
1571
+ "marginBottom",
1572
+ "marginLeft",
1573
+ "marginHorizontal",
1574
+ "marginVertical",
1575
+ "marginStart",
1576
+ "marginEnd",
1577
+ "top",
1578
+ "right",
1579
+ "bottom",
1580
+ "left",
1581
+ "gap",
1582
+ "rowGap",
1583
+ "columnGap",
1584
+ "borderWidth",
1585
+ "borderTopWidth",
1586
+ "borderRightWidth",
1587
+ "borderBottomWidth",
1588
+ "borderLeftWidth",
1589
+ "borderStartWidth",
1590
+ "borderEndWidth",
1591
+ "borderRadius",
1592
+ "borderTopLeftRadius",
1593
+ "borderTopRightRadius",
1594
+ "borderBottomLeftRadius",
1595
+ "borderBottomRightRadius",
1596
+ "borderTopStartRadius",
1597
+ "borderTopEndRadius",
1598
+ "borderBottomStartRadius",
1599
+ "borderBottomEndRadius",
1600
+ "flexBasis",
1601
+ "translateX",
1602
+ "translateY"
1603
+ ]);
1481
1604
  class RN {
1482
1605
  constructor(Processor) {
1483
1606
  this.Processor = Processor;
@@ -1489,6 +1612,9 @@ class RN {
1489
1612
  if (x.includes("padding") || x.includes("margin")) {
1490
1613
  return x.replace("InlineStart", "Start").replace("InlineEnd", "End").replace("Inline", "Horizontal").replace("Block", "Vertical");
1491
1614
  }
1615
+ if (x.includes("border")) {
1616
+ return x.replace("InlineStart", "Start").replace("InlineEnd", "End");
1617
+ }
1492
1618
  return x;
1493
1619
  }
1494
1620
  );
@@ -1497,7 +1623,34 @@ class RN {
1497
1623
  typeof value === "string" ? addMissingSpaces(value) : value
1498
1624
  );
1499
1625
  const joinedStyles = this.joinStyles(rn);
1500
- return Object.entries(joinedStyles).filter(([, value2]) => isDefined(value2));
1626
+ return Object.entries(joinedStyles).filter(([, value2]) => isDefined(value2)).map(([prop, val]) => [prop, this.makeResponsive(prop, val)]);
1627
+ }
1628
+ makeResponsive(property, value) {
1629
+ const mode = this.Processor.bundlerConfig.polyfills?.responsive;
1630
+ if (!mode) {
1631
+ return value;
1632
+ }
1633
+ if (typeof value === "string") {
1634
+ const rawValue = value.startsWith('"') && value.endsWith('"') ? value.slice(1, -1) : value;
1635
+ if (rawValue.endsWith("%")) {
1636
+ const numValue = parseFloat(rawValue);
1637
+ if (!isNaN(numValue)) {
1638
+ return `rt.makeResponsive(${numValue}, 100, true)`;
1639
+ }
1640
+ }
1641
+ }
1642
+ if (typeof value !== "number") {
1643
+ return value;
1644
+ }
1645
+ const isTextMode = mode === true || mode === "text";
1646
+ const isComponentMode = mode === true || mode === "components";
1647
+ if (isTextMode && (property === "fontSize" || property === "--uniwind-em")) {
1648
+ return `rt.makeResponsive(${value}, ${DEFAULT_SCREEN_HEIGHT}, true)`;
1649
+ }
1650
+ if (isComponentMode && COMPONENT_RESPONSIVE_PROPS.has(property)) {
1651
+ return `rt.makeResponsive(${value}, ${DEFAULT_SCREEN_WIDTH})`;
1652
+ }
1653
+ return value;
1501
1654
  }
1502
1655
  transformProperty(property, value) {
1503
1656
  if (property in cssToRNMap) {
@@ -1592,6 +1745,15 @@ class RN {
1592
1745
  };
1593
1746
  }
1594
1747
  }
1748
+ if (BORDER_RADIUS_KEYS.every((key) => keys.includes(key))) {
1749
+ const borderRadius = styles.borderTopLeftRadius;
1750
+ if (BORDER_RADIUS_KEYS.every((key) => styles[key] === borderRadius)) {
1751
+ return {
1752
+ ...removeKeys(styles, BORDER_RADIUS_KEYS),
1753
+ borderRadius
1754
+ };
1755
+ }
1756
+ }
1595
1757
  return styles;
1596
1758
  }
1597
1759
  }
@@ -1659,10 +1821,9 @@ class Var {
1659
1821
  }
1660
1822
 
1661
1823
  class ProcessorBuilder {
1662
- constructor(themes, polyfills) {
1663
- this.themes = themes;
1664
- this.polyfills = polyfills;
1665
- this.vars["--uniwind-em"] = polyfills?.rem ?? 16;
1824
+ constructor(bundlerConfig) {
1825
+ this.bundlerConfig = bundlerConfig;
1826
+ this.vars["--uniwind-em"] = this.bundlerConfig.polyfills?.rem ?? 16;
1666
1827
  }
1667
1828
  stylesheets = {};
1668
1829
  vars = {};
@@ -1823,7 +1984,7 @@ class ProcessorBuilder {
1823
1984
  if (property === "animation") {
1824
1985
  return this.CSS.processAnimation(value);
1825
1986
  }
1826
- return this.CSS.processValue(value);
1987
+ return this.CSS.processValue(value, property);
1827
1988
  };
1828
1989
  if (declaration.property === "unparsed") {
1829
1990
  const property = declaration.value.propertyId.property;
@@ -1874,7 +2035,7 @@ class ProcessorBuilder {
1874
2035
  if (selector2.type === "pseudo-class" && selector2.kind === "where") {
1875
2036
  selector2.selectors.forEach((selector3) => {
1876
2037
  selector3.forEach((selector4) => {
1877
- if (selector4.type === "class" && this.themes.includes(selector4.name)) {
2038
+ if (selector4.type === "class" && this.bundlerConfig.themes.includes(selector4.name)) {
1878
2039
  theme = selector4.name;
1879
2040
  }
1880
2041
  if (selector4.type === "pseudo-class" && selector4.kind === "dir") {
@@ -1986,50 +2147,27 @@ class ProcessorBuilder {
1986
2147
  }
1987
2148
  }
1988
2149
 
1989
- const compileVirtual = async ({ css, cssPath, platform, themes, polyfills, debug, candidates }) => {
1990
- const compiler = await compile(css, {
1991
- base: path.dirname(cssPath),
1992
- onDependency: () => void 0
1993
- });
1994
- const scanner = new Scanner({
1995
- sources: [
1996
- ...compiler.sources,
1997
- {
1998
- negated: false,
1999
- pattern: "**/*",
2000
- base: path.dirname(cssPath)
2001
- }
2002
- ]
2003
- });
2004
- const tailwindCSS = compiler.build(candidates ?? scanner.scan());
2005
- if (platform === Platform.Web) {
2006
- return transform$1({
2007
- code: Buffer.from(tailwindCSS),
2008
- filename: "uniwind.css",
2009
- visitor: new UniwindCSSVisitor(themes)
2010
- }).code.toString();
2011
- }
2012
- const Processor = new ProcessorBuilder(themes, polyfills);
2013
- Logger.debug = debug === true;
2150
+ const compileNativeCSS = (bundlerConfig, tailwindCSS) => {
2151
+ const Processor = new ProcessorBuilder(bundlerConfig);
2014
2152
  Processor.transform(tailwindCSS);
2015
2153
  const stylesheet = serializeJSObject(
2016
- addMetaToStylesTemplate(Processor, platform),
2154
+ addMetaToStylesTemplate(Processor, bundlerConfig.platform),
2017
2155
  (key, value) => `"${key}": ${value}`
2018
2156
  );
2019
2157
  const vars = serializeJSObject(
2020
2158
  Processor.vars,
2021
2159
  (key, value) => `get "${key}"() { return ${value} }`
2022
2160
  );
2161
+ const keyframes = serializeJSObject(
2162
+ Processor.keyframes,
2163
+ (key, value) => `get "${key}"() { return ${value} }`
2164
+ );
2023
2165
  const scopedVars = Object.fromEntries(
2024
2166
  Object.entries(Processor.scopedVars).map(([scopedVarsName, scopedVars2]) => [
2025
2167
  scopedVarsName,
2026
2168
  serializeJSObject(scopedVars2, (key, value) => `get "${key}"() { return ${value} }`)
2027
2169
  ])
2028
2170
  );
2029
- const keyframes = serializeJSObject(
2030
- Processor.keyframes,
2031
- (key, value) => `get "${key}"() { return ${value} }`
2032
- );
2033
2171
  const serializedScopedVars = Object.entries(scopedVars).map(([scopedVarsName, scopedVars2]) => `"${scopedVarsName}": ({ ${scopedVars2} }),`).join("");
2034
2172
  const currentColorVar = `get currentColor() { return rt.colorScheme === 'dark' ? '#ffffff' : '#000000' },`;
2035
2173
  return [
@@ -2042,17 +2180,42 @@ const compileVirtual = async ({ css, cssPath, platform, themes, polyfills, debug
2042
2180
  ].join("");
2043
2181
  };
2044
2182
 
2045
- const injectThemes = async ({
2046
- themes,
2047
- dtsPath = "uniwind-types.d.ts",
2048
- input
2049
- }) => {
2050
- const stringifiedThemes = stringifyThemes(themes);
2051
- buildDtsFile(dtsPath, stringifiedThemes);
2052
- await buildCSS(themes, input);
2053
- return stringifiedThemes;
2183
+ const compileTailwind = async (bundlerConfig) => {
2184
+ const css = await fs.promises.readFile(bundlerConfig.cssPath, "utf-8");
2185
+ const compiler = await compile(css, {
2186
+ base: path.dirname(bundlerConfig.cssPath),
2187
+ onDependency: () => void 0
2188
+ });
2189
+ const scanner = new Scanner({
2190
+ sources: [
2191
+ ...compiler.sources,
2192
+ {
2193
+ negated: false,
2194
+ pattern: "**/*",
2195
+ base: path.dirname(bundlerConfig.cssPath)
2196
+ }
2197
+ ]
2198
+ });
2199
+ return compiler.build(scanner.scan());
2200
+ };
2201
+
2202
+ const compileWebCSS = (bundlerConfig, tailwindCSS) => {
2203
+ return transform$1({
2204
+ code: Buffer.from(tailwindCSS),
2205
+ filename: "uniwind.css",
2206
+ visitor: bundlerConfig.cssVisitor
2207
+ }).code.toString();
2208
+ };
2209
+
2210
+ const compileCSS = async (bundlerConfig) => {
2211
+ const tailwindCSS = await compileTailwind(bundlerConfig);
2212
+ if (bundlerConfig.platform === Platform.Web) {
2213
+ return compileWebCSS(bundlerConfig, tailwindCSS);
2214
+ }
2215
+ return compileNativeCSS(bundlerConfig, tailwindCSS);
2054
2216
  };
2055
2217
 
2218
+ const cssArtifactPath = path.resolve(__dirname, "../../uniwind.css");
2056
2219
  let worker;
2057
2220
  try {
2058
2221
  try {
@@ -2067,16 +2230,11 @@ try {
2067
2230
  const transform = async (config, projectRoot, filePath, data, options) => {
2068
2231
  const isCss = options.type !== "asset" && path.join(process.cwd(), config.uniwind.cssEntryFile) === path.join(projectRoot, filePath);
2069
2232
  if (filePath.endsWith("/components/web/metro-injected.js")) {
2070
- const cssPath2 = path.join(process.cwd(), config.uniwind.cssEntryFile);
2071
- const injectedThemesCode2 = await injectThemes({
2072
- input: cssPath2,
2073
- themes: config.uniwind.themes,
2074
- dtsPath: config.uniwind.dtsFile
2075
- });
2233
+ const bundlerConfig2 = UniwindBundlerConfig.fromMetroConfig(config.uniwind, Platform.Web);
2076
2234
  data = Buffer.from(
2077
2235
  [
2078
2236
  `import { Uniwind } from '${name}';`,
2079
- `Uniwind.__reinit(() => ({}), ${injectedThemesCode2});`
2237
+ `Uniwind.__reinit(() => ({}), ${bundlerConfig2.stringifiedThemes});`
2080
2238
  ].join(""),
2081
2239
  "utf-8"
2082
2240
  );
@@ -2084,39 +2242,14 @@ const transform = async (config, projectRoot, filePath, data, options) => {
2084
2242
  if (!isCss) {
2085
2243
  return worker.transform(config, projectRoot, filePath, data, options);
2086
2244
  }
2087
- const getPlatform = () => {
2088
- if (!config.uniwind.isTV) {
2089
- return options.platform;
2090
- }
2091
- if (options.platform === Platform.Android) {
2092
- return Platform.AndroidTV;
2093
- }
2094
- if (options.platform === Platform.iOS) {
2095
- return Platform.AppleTV;
2096
- }
2097
- throw new Error(`Platform ${options.platform} not supported`);
2098
- };
2099
- const cssPath = path.join(process.cwd(), config.uniwind.cssEntryFile);
2100
- const injectedThemesCode = await injectThemes({
2101
- input: cssPath,
2102
- themes: config.uniwind.themes,
2103
- dtsPath: config.uniwind.dtsFile
2104
- });
2105
- const css = fs.readFileSync(cssPath, "utf-8");
2106
- const platform = getPlatform();
2107
- const virtualCode = await compileVirtual({
2108
- css,
2109
- platform,
2110
- themes: config.uniwind.themes,
2111
- polyfills: config.uniwind.polyfills,
2112
- cssPath,
2113
- debug: config.uniwind.debug
2114
- });
2115
- const isWeb = platform === Platform.Web;
2245
+ const bundlerConfig = UniwindBundlerConfig.fromMetroConfig(config.uniwind, options.platform);
2246
+ await bundlerConfig.generateArtifacts(cssArtifactPath);
2247
+ const virtualCode = await compileCSS(bundlerConfig);
2248
+ const isWeb = bundlerConfig.platform === Platform.Web;
2116
2249
  data = Buffer.from(
2117
2250
  isWeb ? virtualCode : [
2118
2251
  `const { Uniwind } = require('${name}');`,
2119
- `Uniwind.__reinit(rt => ${virtualCode}, ${injectedThemesCode});`
2252
+ `Uniwind.__reinit(rt => ${virtualCode}, ${bundlerConfig.stringifiedThemes});`
2120
2253
  ].join(""),
2121
2254
  "utf-8"
2122
2255
  );
@@ -1 +1 @@
1
- export declare const buildCSS: (themes: Array<string>, input: string) => Promise<void>;
1
+ export declare const buildCSS: (themes: Array<string>, input: string, cssFilePath: string) => Promise<void>;
@@ -1,14 +1,11 @@
1
1
  import fs from "fs";
2
- import path from "path";
3
2
  import { EXTRA_UTILITIES_CSS } from "./extraUtilities.js";
4
3
  import { INSETS_CSS } from "./insets.js";
5
4
  import { OVERWRITE_CSS } from "./overwrite.js";
6
5
  import { generateCSSForThemes } from "./themes.js";
7
6
  import { VARIANTS_CSS } from "./variants.js";
8
- const dirname = typeof __dirname !== "undefined" ? __dirname : import.meta.dirname;
9
- export const buildCSS = async (themes, input) => {
7
+ export const buildCSS = async (themes, input, cssFilePath) => {
10
8
  const themesCSS = await generateCSSForThemes(themes, input);
11
- const cssFilePath = path.join(dirname, "../../uniwind.css");
12
9
  const oldCSSFile = fs.existsSync(cssFilePath) ? fs.readFileSync(cssFilePath, "utf-8") : "";
13
10
  const newCssFile = [
14
11
  VARIANTS_CSS,
@@ -1,8 +1,8 @@
1
+ import { Logger } from "@/bundler/logger";
1
2
  import { compile } from "@tailwindcss/node";
2
3
  import fs from "fs";
3
4
  import { transform } from "lightningcss";
4
5
  import path from "path";
5
- import { Logger } from "../metro/logger";
6
6
  const readFileSafe = (filePath) => {
7
7
  try {
8
8
  return fs.readFileSync(filePath, "utf-8");
@@ -1,12 +1,11 @@
1
1
  import fs from "fs";
2
- import { name } from "../../package.json";
3
2
  export const buildDtsFile = (dtsPath, stringifiedThemes) => {
4
3
  const oldDtsContent = fs.existsSync(dtsPath) ? fs.readFileSync(dtsPath, "utf-8") : "";
5
4
  const dtsContent = [
6
- `// NOTE: This file is generated by ${name} and it should not be edited manually.`,
7
- `/// <reference types="${name}/types" />`,
5
+ `// NOTE: This file is generated by uniwind and it should not be edited manually.`,
6
+ `/// <reference types="uniwind/types" />`,
8
7
  "",
9
- `declare module '${name}' {`,
8
+ `declare module 'uniwind' {`,
10
9
  ` export interface UniwindConfig {`,
11
10
  ` themes: readonly ${stringifiedThemes}`,
12
11
  ` }`,
@@ -0,0 +1,16 @@
1
+ import type { UniwindConfig, UniwindMetroConfig } from '@/bundler/types';
2
+ import { Platform } from '@/common/consts';
3
+ export declare class UniwindBundlerConfig {
4
+ private readonly config;
5
+ readonly platform: Platform;
6
+ static fromMetroConfig(config: UniwindMetroConfig, platform?: string | null): UniwindBundlerConfig;
7
+ static fromViteConfig(config: UniwindConfig): UniwindBundlerConfig;
8
+ constructor(config: UniwindMetroConfig, platform: Platform);
9
+ get cssPath(): any;
10
+ get themes(): any[];
11
+ get cssVisitor(): any;
12
+ get polyfills(): any;
13
+ get stringifiedThemes(): string;
14
+ toMetroConfig(): UniwindMetroConfig;
15
+ generateArtifacts(cssArtifactPath: string): Promise<void>;
16
+ }
@@ -0,0 +1,69 @@
1
+ import { buildCSS } from "@/bundler/artifacts/css";
2
+ import { buildDtsFile } from "@/bundler/artifacts/dts";
3
+ import { UniwindCSSVisitor } from "@/bundler/css-visitor";
4
+ import { Platform } from "@/common/consts";
5
+ import { isDefined } from "@/common/utils";
6
+ import path from "path";
7
+ export class UniwindBundlerConfig {
8
+ constructor(config, platform) {
9
+ this.config = config;
10
+ this.platform = platform;
11
+ }
12
+ static fromMetroConfig(config, platform) {
13
+ const getPlatform = () => {
14
+ if (!isDefined(platform)) {
15
+ return Platform.Native;
16
+ }
17
+ if (!config.isTV) {
18
+ return platform;
19
+ }
20
+ if (platform === Platform.Android) {
21
+ return Platform.AndroidTV;
22
+ }
23
+ if (platform === Platform.iOS) {
24
+ return Platform.AppleTV;
25
+ }
26
+ throw new Error(`Platform ${platform} not supported`);
27
+ };
28
+ if (typeof config === "undefined") {
29
+ throw new Error("Uniwind: You need to pass second parameter to withUniwindConfig");
30
+ }
31
+ if (typeof config.cssEntryFile === "undefined") {
32
+ throw new Error(
33
+ 'Uniwind: You need to pass css css entry file to withUniwindConfig, e.g. withUniwindConfig(config, { cssEntryFile: "./global.css" })'
34
+ );
35
+ }
36
+ return new UniwindBundlerConfig(config, getPlatform());
37
+ }
38
+ static fromViteConfig(config) {
39
+ return new UniwindBundlerConfig(config, Platform.Web);
40
+ }
41
+ get cssPath() {
42
+ return path.join(process.cwd(), this.config.cssEntryFile);
43
+ }
44
+ get themes() {
45
+ return Array.from(
46
+ /* @__PURE__ */ new Set([
47
+ "light",
48
+ "dark",
49
+ ...this.config.extraThemes ?? []
50
+ ])
51
+ );
52
+ }
53
+ get cssVisitor() {
54
+ return new UniwindCSSVisitor(this);
55
+ }
56
+ get polyfills() {
57
+ return this.config.polyfills;
58
+ }
59
+ get stringifiedThemes() {
60
+ return `[${this.themes.map((theme) => `'${theme}'`).join(", ")}]`;
61
+ }
62
+ toMetroConfig() {
63
+ return this.config;
64
+ }
65
+ async generateArtifacts(cssArtifactPath) {
66
+ await buildCSS(this.themes, this.config.cssEntryFile, cssArtifactPath);
67
+ buildDtsFile(this.config.dtsFile ?? "uniwind-types.d.ts", this.stringifiedThemes);
68
+ }
69
+ }
@@ -0,0 +1,2 @@
1
+ import type { UniwindBundlerConfig } from '../config';
2
+ export declare const compileCSS: (bundlerConfig: UniwindBundlerConfig) => Promise<string>;
@@ -0,0 +1,11 @@
1
+ import { Platform } from "@/common/consts";
2
+ import { compileNativeCSS } from "./compileNativeCSS.js";
3
+ import { compileTailwind } from "./compileTailwind.js";
4
+ import { compileWebCSS } from "./compileWebCSS.js";
5
+ export const compileCSS = async (bundlerConfig) => {
6
+ const tailwindCSS = await compileTailwind(bundlerConfig);
7
+ if (bundlerConfig.platform === Platform.Web) {
8
+ return compileWebCSS(bundlerConfig, tailwindCSS);
9
+ }
10
+ return compileNativeCSS(bundlerConfig, tailwindCSS);
11
+ };
@@ -0,0 +1,2 @@
1
+ import type { UniwindBundlerConfig } from '../config';
2
+ export declare const compileNativeCSS: (bundlerConfig: UniwindBundlerConfig, tailwindCSS: string) => string;