rnwind 0.0.1 → 0.0.2

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 (330) hide show
  1. package/lib/cjs/core/parser/animation.cjs +427 -0
  2. package/lib/cjs/core/parser/animation.cjs.map +1 -0
  3. package/lib/cjs/core/parser/animation.d.ts +126 -0
  4. package/lib/cjs/core/parser/border-dispatcher.cjs +180 -0
  5. package/lib/cjs/core/parser/border-dispatcher.cjs.map +1 -0
  6. package/lib/cjs/core/parser/border-dispatcher.d.ts +15 -0
  7. package/lib/cjs/core/parser/case-convert.cjs +15 -0
  8. package/lib/cjs/core/parser/case-convert.cjs.map +1 -0
  9. package/lib/cjs/core/parser/case-convert.d.ts +6 -0
  10. package/lib/cjs/core/parser/color-properties-dispatcher.cjs +84 -0
  11. package/lib/cjs/core/parser/color-properties-dispatcher.cjs.map +1 -0
  12. package/lib/cjs/core/parser/color-properties-dispatcher.d.ts +19 -0
  13. package/lib/cjs/core/parser/color.cjs +164 -0
  14. package/lib/cjs/core/parser/color.cjs.map +1 -0
  15. package/lib/cjs/core/parser/color.d.ts +12 -0
  16. package/lib/cjs/core/parser/constants.cjs +21 -0
  17. package/lib/cjs/core/parser/constants.cjs.map +1 -0
  18. package/lib/cjs/core/parser/constants.d.ts +8 -0
  19. package/lib/cjs/core/parser/declaration.cjs +347 -0
  20. package/lib/cjs/core/parser/declaration.cjs.map +1 -0
  21. package/lib/cjs/core/parser/declaration.d.ts +15 -0
  22. package/lib/cjs/core/parser/gradient.cjs +132 -0
  23. package/lib/cjs/core/parser/gradient.cjs.map +1 -0
  24. package/lib/cjs/core/parser/gradient.d.ts +59 -0
  25. package/lib/cjs/core/parser/haptics.cjs +73 -0
  26. package/lib/cjs/core/parser/haptics.cjs.map +1 -0
  27. package/lib/cjs/core/parser/haptics.d.ts +47 -0
  28. package/lib/cjs/core/parser/index.d.ts +8 -0
  29. package/lib/cjs/core/parser/keyframes.cjs +95 -0
  30. package/lib/cjs/core/parser/keyframes.cjs.map +1 -0
  31. package/lib/cjs/core/parser/keyframes.d.ts +26 -0
  32. package/lib/cjs/core/parser/layout-dispatcher.cjs +100 -0
  33. package/lib/cjs/core/parser/layout-dispatcher.cjs.map +1 -0
  34. package/lib/cjs/core/parser/layout-dispatcher.d.ts +14 -0
  35. package/lib/cjs/core/parser/length.cjs +96 -0
  36. package/lib/cjs/core/parser/length.cjs.map +1 -0
  37. package/lib/cjs/core/parser/length.d.ts +48 -0
  38. package/lib/cjs/core/parser/motion-dispatcher.cjs +77 -0
  39. package/lib/cjs/core/parser/motion-dispatcher.cjs.map +1 -0
  40. package/lib/cjs/core/parser/motion-dispatcher.d.ts +11 -0
  41. package/lib/cjs/core/parser/property.cjs +22 -0
  42. package/lib/cjs/core/parser/property.cjs.map +1 -0
  43. package/lib/cjs/core/parser/property.d.ts +8 -0
  44. package/lib/cjs/core/parser/safe-area.cjs +404 -0
  45. package/lib/cjs/core/parser/safe-area.cjs.map +1 -0
  46. package/lib/cjs/core/parser/safe-area.d.ts +39 -0
  47. package/lib/cjs/core/parser/selector.cjs +22 -0
  48. package/lib/cjs/core/parser/selector.cjs.map +1 -0
  49. package/lib/cjs/core/parser/selector.d.ts +11 -0
  50. package/lib/cjs/core/parser/shorthand.cjs +156 -0
  51. package/lib/cjs/core/parser/shorthand.cjs.map +1 -0
  52. package/lib/cjs/core/parser/shorthand.d.ts +61 -0
  53. package/lib/cjs/core/parser/text-truncate.cjs +78 -0
  54. package/lib/cjs/core/parser/text-truncate.cjs.map +1 -0
  55. package/lib/cjs/core/parser/text-truncate.d.ts +44 -0
  56. package/lib/cjs/core/parser/theme-vars.cjs +414 -0
  57. package/lib/cjs/core/parser/theme-vars.cjs.map +1 -0
  58. package/lib/cjs/core/parser/theme-vars.d.ts +61 -0
  59. package/lib/cjs/core/parser/tokens.cjs +304 -0
  60. package/lib/cjs/core/parser/tokens.cjs.map +1 -0
  61. package/lib/cjs/core/parser/tokens.d.ts +45 -0
  62. package/lib/cjs/core/parser/transform.cjs +198 -0
  63. package/lib/cjs/core/parser/transform.cjs.map +1 -0
  64. package/lib/cjs/core/parser/transform.d.ts +36 -0
  65. package/lib/cjs/core/parser/tw-parser.cjs +1567 -0
  66. package/lib/cjs/core/parser/tw-parser.cjs.map +1 -0
  67. package/lib/cjs/core/parser/tw-parser.d.ts +194 -0
  68. package/lib/cjs/core/parser/types.d.ts +37 -0
  69. package/lib/cjs/core/parser/typography-dispatcher.cjs +93 -0
  70. package/lib/cjs/core/parser/typography-dispatcher.cjs.map +1 -0
  71. package/lib/cjs/core/parser/typography-dispatcher.d.ts +11 -0
  72. package/lib/cjs/core/parser/typography.cjs +97 -0
  73. package/lib/cjs/core/parser/typography.cjs.map +1 -0
  74. package/lib/cjs/core/parser/typography.d.ts +43 -0
  75. package/lib/cjs/core/style-builder/build-style.cjs +397 -0
  76. package/lib/cjs/core/style-builder/build-style.cjs.map +1 -0
  77. package/lib/cjs/core/style-builder/build-style.d.ts +54 -0
  78. package/lib/cjs/core/style-builder/index.d.ts +3 -0
  79. package/lib/cjs/core/style-builder/union-builder.cjs +326 -0
  80. package/lib/cjs/core/style-builder/union-builder.cjs.map +1 -0
  81. package/lib/cjs/core/style-builder/union-builder.d.ts +128 -0
  82. package/lib/cjs/core/types.d.ts +14 -0
  83. package/lib/cjs/metro/dts.cjs +127 -0
  84. package/lib/cjs/metro/dts.cjs.map +1 -0
  85. package/lib/cjs/metro/dts.d.ts +16 -0
  86. package/lib/cjs/metro/index.cjs +19 -0
  87. package/lib/cjs/metro/index.cjs.map +1 -0
  88. package/lib/cjs/metro/index.d.ts +9 -0
  89. package/lib/cjs/metro/resolver.cjs +47 -0
  90. package/lib/cjs/metro/resolver.cjs.map +1 -0
  91. package/lib/cjs/metro/resolver.d.ts +22 -0
  92. package/lib/cjs/metro/state.cjs +251 -0
  93. package/lib/cjs/metro/state.cjs.map +1 -0
  94. package/lib/cjs/metro/state.d.ts +72 -0
  95. package/lib/cjs/metro/transform-ast.cjs +1255 -0
  96. package/lib/cjs/metro/transform-ast.cjs.map +1 -0
  97. package/lib/cjs/metro/transform-ast.d.ts +73 -0
  98. package/lib/cjs/metro/transformer.cjs +345 -0
  99. package/lib/cjs/metro/transformer.cjs.map +1 -0
  100. package/lib/cjs/metro/transformer.d.ts +47 -0
  101. package/lib/cjs/metro/warn-unknown-classes.cjs +86 -0
  102. package/lib/cjs/metro/warn-unknown-classes.cjs.map +1 -0
  103. package/lib/cjs/metro/warn-unknown-classes.d.ts +21 -0
  104. package/lib/cjs/metro/with-config.cjs +196 -0
  105. package/lib/cjs/metro/with-config.cjs.map +1 -0
  106. package/lib/cjs/metro/with-config.d.ts +57 -0
  107. package/lib/cjs/runtime/chain-handlers.cjs +37 -0
  108. package/lib/cjs/runtime/chain-handlers.cjs.map +1 -0
  109. package/lib/cjs/runtime/chain-handlers.d.ts +33 -0
  110. package/lib/cjs/runtime/components/rnwind-provider.cjs +98 -0
  111. package/lib/cjs/runtime/components/rnwind-provider.cjs.map +1 -0
  112. package/lib/cjs/runtime/components/rnwind-provider.d.ts +84 -0
  113. package/lib/cjs/runtime/gradient-types.d.ts +58 -0
  114. package/lib/cjs/runtime/haptics.cjs +113 -0
  115. package/lib/cjs/runtime/haptics.cjs.map +1 -0
  116. package/lib/cjs/runtime/haptics.d.ts +48 -0
  117. package/lib/cjs/runtime/hooks/use-css.cjs +21 -0
  118. package/lib/cjs/runtime/hooks/use-css.cjs.map +1 -0
  119. package/lib/cjs/runtime/hooks/use-css.d.ts +11 -0
  120. package/lib/cjs/runtime/hooks/use-interact.cjs +46 -0
  121. package/lib/cjs/runtime/hooks/use-interact.cjs.map +1 -0
  122. package/lib/cjs/runtime/hooks/use-interact.d.ts +42 -0
  123. package/lib/cjs/runtime/hooks/use-scheme.cjs +68 -0
  124. package/lib/cjs/runtime/hooks/use-scheme.cjs.map +1 -0
  125. package/lib/cjs/runtime/hooks/use-scheme.d.ts +34 -0
  126. package/lib/cjs/runtime/index.cjs +45 -0
  127. package/lib/cjs/runtime/index.cjs.map +1 -0
  128. package/lib/cjs/runtime/index.d.ts +27 -0
  129. package/lib/cjs/runtime/interactive-box.cjs +35 -0
  130. package/lib/cjs/runtime/interactive-box.cjs.map +1 -0
  131. package/lib/cjs/runtime/interactive-box.d.ts +40 -0
  132. package/lib/cjs/runtime/lookup-css.cjs +542 -0
  133. package/lib/cjs/runtime/lookup-css.cjs.map +1 -0
  134. package/lib/cjs/runtime/lookup-css.d.ts +164 -0
  135. package/lib/cjs/runtime/types.d.ts +29 -0
  136. package/lib/cjs/testing/index.cjs +367 -0
  137. package/lib/cjs/testing/index.cjs.map +1 -0
  138. package/lib/cjs/testing/index.d.ts +145 -0
  139. package/lib/esm/core/parser/animation.d.ts +126 -0
  140. package/lib/esm/core/parser/animation.mjs +408 -0
  141. package/lib/esm/core/parser/animation.mjs.map +1 -0
  142. package/lib/esm/core/parser/border-dispatcher.d.ts +15 -0
  143. package/lib/esm/core/parser/border-dispatcher.mjs +178 -0
  144. package/lib/esm/core/parser/border-dispatcher.mjs.map +1 -0
  145. package/lib/esm/core/parser/case-convert.d.ts +6 -0
  146. package/lib/esm/core/parser/case-convert.mjs +13 -0
  147. package/lib/esm/core/parser/case-convert.mjs.map +1 -0
  148. package/lib/esm/core/parser/color-properties-dispatcher.d.ts +19 -0
  149. package/lib/esm/core/parser/color-properties-dispatcher.mjs +82 -0
  150. package/lib/esm/core/parser/color-properties-dispatcher.mjs.map +1 -0
  151. package/lib/esm/core/parser/color.d.ts +12 -0
  152. package/lib/esm/core/parser/color.mjs +162 -0
  153. package/lib/esm/core/parser/color.mjs.map +1 -0
  154. package/lib/esm/core/parser/constants.d.ts +8 -0
  155. package/lib/esm/core/parser/constants.mjs +13 -0
  156. package/lib/esm/core/parser/constants.mjs.map +1 -0
  157. package/lib/esm/core/parser/declaration.d.ts +15 -0
  158. package/lib/esm/core/parser/declaration.mjs +345 -0
  159. package/lib/esm/core/parser/declaration.mjs.map +1 -0
  160. package/lib/esm/core/parser/gradient.d.ts +59 -0
  161. package/lib/esm/core/parser/gradient.mjs +130 -0
  162. package/lib/esm/core/parser/gradient.mjs.map +1 -0
  163. package/lib/esm/core/parser/haptics.d.ts +47 -0
  164. package/lib/esm/core/parser/haptics.mjs +71 -0
  165. package/lib/esm/core/parser/haptics.mjs.map +1 -0
  166. package/lib/esm/core/parser/index.d.ts +8 -0
  167. package/lib/esm/core/parser/keyframes.d.ts +26 -0
  168. package/lib/esm/core/parser/keyframes.mjs +91 -0
  169. package/lib/esm/core/parser/keyframes.mjs.map +1 -0
  170. package/lib/esm/core/parser/layout-dispatcher.d.ts +14 -0
  171. package/lib/esm/core/parser/layout-dispatcher.mjs +98 -0
  172. package/lib/esm/core/parser/layout-dispatcher.mjs.map +1 -0
  173. package/lib/esm/core/parser/length.d.ts +48 -0
  174. package/lib/esm/core/parser/length.mjs +90 -0
  175. package/lib/esm/core/parser/length.mjs.map +1 -0
  176. package/lib/esm/core/parser/motion-dispatcher.d.ts +11 -0
  177. package/lib/esm/core/parser/motion-dispatcher.mjs +75 -0
  178. package/lib/esm/core/parser/motion-dispatcher.mjs.map +1 -0
  179. package/lib/esm/core/parser/property.d.ts +8 -0
  180. package/lib/esm/core/parser/property.mjs +20 -0
  181. package/lib/esm/core/parser/property.mjs.map +1 -0
  182. package/lib/esm/core/parser/safe-area.d.ts +39 -0
  183. package/lib/esm/core/parser/safe-area.mjs +402 -0
  184. package/lib/esm/core/parser/safe-area.mjs.map +1 -0
  185. package/lib/esm/core/parser/selector.d.ts +11 -0
  186. package/lib/esm/core/parser/selector.mjs +20 -0
  187. package/lib/esm/core/parser/selector.mjs.map +1 -0
  188. package/lib/esm/core/parser/shorthand.d.ts +61 -0
  189. package/lib/esm/core/parser/shorthand.mjs +148 -0
  190. package/lib/esm/core/parser/shorthand.mjs.map +1 -0
  191. package/lib/esm/core/parser/text-truncate.d.ts +44 -0
  192. package/lib/esm/core/parser/text-truncate.mjs +75 -0
  193. package/lib/esm/core/parser/text-truncate.mjs.map +1 -0
  194. package/lib/esm/core/parser/theme-vars.d.ts +61 -0
  195. package/lib/esm/core/parser/theme-vars.mjs +409 -0
  196. package/lib/esm/core/parser/theme-vars.mjs.map +1 -0
  197. package/lib/esm/core/parser/tokens.d.ts +45 -0
  198. package/lib/esm/core/parser/tokens.mjs +298 -0
  199. package/lib/esm/core/parser/tokens.mjs.map +1 -0
  200. package/lib/esm/core/parser/transform.d.ts +36 -0
  201. package/lib/esm/core/parser/transform.mjs +193 -0
  202. package/lib/esm/core/parser/transform.mjs.map +1 -0
  203. package/lib/esm/core/parser/tw-parser.d.ts +194 -0
  204. package/lib/esm/core/parser/tw-parser.mjs +1565 -0
  205. package/lib/esm/core/parser/tw-parser.mjs.map +1 -0
  206. package/lib/esm/core/parser/types.d.ts +37 -0
  207. package/lib/esm/core/parser/typography-dispatcher.d.ts +11 -0
  208. package/lib/esm/core/parser/typography-dispatcher.mjs +91 -0
  209. package/lib/esm/core/parser/typography-dispatcher.mjs.map +1 -0
  210. package/lib/esm/core/parser/typography.d.ts +43 -0
  211. package/lib/esm/core/parser/typography.mjs +91 -0
  212. package/lib/esm/core/parser/typography.mjs.map +1 -0
  213. package/lib/esm/core/style-builder/build-style.d.ts +54 -0
  214. package/lib/esm/core/style-builder/build-style.mjs +395 -0
  215. package/lib/esm/core/style-builder/build-style.mjs.map +1 -0
  216. package/lib/esm/core/style-builder/index.d.ts +3 -0
  217. package/lib/esm/core/style-builder/union-builder.d.ts +128 -0
  218. package/lib/esm/core/style-builder/union-builder.mjs +324 -0
  219. package/lib/esm/core/style-builder/union-builder.mjs.map +1 -0
  220. package/lib/esm/core/types.d.ts +14 -0
  221. package/lib/esm/metro/dts.d.ts +16 -0
  222. package/lib/esm/metro/dts.mjs +125 -0
  223. package/lib/esm/metro/dts.mjs.map +1 -0
  224. package/lib/esm/metro/index.d.ts +9 -0
  225. package/lib/esm/metro/index.mjs +6 -0
  226. package/lib/esm/metro/index.mjs.map +1 -0
  227. package/lib/esm/metro/resolver.d.ts +22 -0
  228. package/lib/esm/metro/resolver.mjs +43 -0
  229. package/lib/esm/metro/resolver.mjs.map +1 -0
  230. package/lib/esm/metro/state.d.ts +72 -0
  231. package/lib/esm/metro/state.mjs +243 -0
  232. package/lib/esm/metro/state.mjs.map +1 -0
  233. package/lib/esm/metro/transform-ast.d.ts +73 -0
  234. package/lib/esm/metro/transform-ast.mjs +1234 -0
  235. package/lib/esm/metro/transform-ast.mjs.map +1 -0
  236. package/lib/esm/metro/transformer.d.ts +47 -0
  237. package/lib/esm/metro/transformer.mjs +322 -0
  238. package/lib/esm/metro/transformer.mjs.map +1 -0
  239. package/lib/esm/metro/warn-unknown-classes.d.ts +21 -0
  240. package/lib/esm/metro/warn-unknown-classes.mjs +84 -0
  241. package/lib/esm/metro/warn-unknown-classes.mjs.map +1 -0
  242. package/lib/esm/metro/with-config.d.ts +57 -0
  243. package/lib/esm/metro/with-config.mjs +194 -0
  244. package/lib/esm/metro/with-config.mjs.map +1 -0
  245. package/lib/esm/runtime/chain-handlers.d.ts +33 -0
  246. package/lib/esm/runtime/chain-handlers.mjs +34 -0
  247. package/lib/esm/runtime/chain-handlers.mjs.map +1 -0
  248. package/lib/esm/runtime/components/rnwind-provider.d.ts +84 -0
  249. package/lib/esm/runtime/components/rnwind-provider.mjs +94 -0
  250. package/lib/esm/runtime/components/rnwind-provider.mjs.map +1 -0
  251. package/lib/esm/runtime/gradient-types.d.ts +58 -0
  252. package/lib/esm/runtime/haptics.d.ts +48 -0
  253. package/lib/esm/runtime/haptics.mjs +110 -0
  254. package/lib/esm/runtime/haptics.mjs.map +1 -0
  255. package/lib/esm/runtime/hooks/use-css.d.ts +11 -0
  256. package/lib/esm/runtime/hooks/use-css.mjs +19 -0
  257. package/lib/esm/runtime/hooks/use-css.mjs.map +1 -0
  258. package/lib/esm/runtime/hooks/use-interact.d.ts +42 -0
  259. package/lib/esm/runtime/hooks/use-interact.mjs +44 -0
  260. package/lib/esm/runtime/hooks/use-interact.mjs.map +1 -0
  261. package/lib/esm/runtime/hooks/use-scheme.d.ts +34 -0
  262. package/lib/esm/runtime/hooks/use-scheme.mjs +63 -0
  263. package/lib/esm/runtime/hooks/use-scheme.mjs.map +1 -0
  264. package/lib/esm/runtime/index.d.ts +27 -0
  265. package/lib/esm/runtime/index.mjs +18 -0
  266. package/lib/esm/runtime/index.mjs.map +1 -0
  267. package/lib/esm/runtime/interactive-box.d.ts +40 -0
  268. package/lib/esm/runtime/interactive-box.mjs +33 -0
  269. package/lib/esm/runtime/interactive-box.mjs.map +1 -0
  270. package/lib/esm/runtime/lookup-css.d.ts +164 -0
  271. package/lib/esm/runtime/lookup-css.mjs +531 -0
  272. package/lib/esm/runtime/lookup-css.mjs.map +1 -0
  273. package/lib/esm/runtime/types.d.ts +29 -0
  274. package/lib/esm/testing/index.d.ts +145 -0
  275. package/lib/esm/testing/index.mjs +344 -0
  276. package/lib/esm/testing/index.mjs.map +1 -0
  277. package/package.json +79 -13
  278. package/preset.css +1171 -0
  279. package/src/core/parser/animation.ts +404 -0
  280. package/src/core/parser/border-dispatcher.ts +176 -0
  281. package/src/core/parser/case-convert.ts +10 -0
  282. package/src/core/parser/color-properties-dispatcher.ts +78 -0
  283. package/src/core/parser/color.ts +157 -0
  284. package/src/core/parser/constants.ts +11 -0
  285. package/src/core/parser/declaration.ts +340 -0
  286. package/src/core/parser/gradient.ts +148 -0
  287. package/src/core/parser/haptics.ts +88 -0
  288. package/src/core/parser/index.ts +8 -0
  289. package/src/core/parser/keyframes.ts +84 -0
  290. package/src/core/parser/layout-dispatcher.ts +92 -0
  291. package/src/core/parser/length.ts +100 -0
  292. package/src/core/parser/motion-dispatcher.ts +89 -0
  293. package/src/core/parser/property.ts +15 -0
  294. package/src/core/parser/safe-area.ts +404 -0
  295. package/src/core/parser/selector.ts +17 -0
  296. package/src/core/parser/shorthand.ts +152 -0
  297. package/src/core/parser/text-truncate.ts +79 -0
  298. package/src/core/parser/theme-vars.ts +412 -0
  299. package/src/core/parser/tokens.ts +286 -0
  300. package/src/core/parser/transform.ts +195 -0
  301. package/src/core/parser/tw-parser.ts +1709 -0
  302. package/src/core/parser/types.ts +45 -0
  303. package/src/core/parser/typography-dispatcher.ts +83 -0
  304. package/src/core/parser/typography.ts +83 -0
  305. package/src/core/style-builder/build-style.ts +442 -0
  306. package/src/core/style-builder/index.ts +3 -0
  307. package/src/core/style-builder/union-builder.ts +328 -0
  308. package/src/core/types.ts +15 -0
  309. package/src/metro/dts.ts +128 -0
  310. package/src/metro/index.ts +9 -0
  311. package/src/metro/resolver.ts +42 -0
  312. package/src/metro/state.ts +257 -0
  313. package/src/metro/transform-ast.ts +1498 -0
  314. package/src/metro/transformer.ts +347 -0
  315. package/src/metro/warn-unknown-classes.ts +79 -0
  316. package/src/metro/with-config.ts +229 -0
  317. package/src/runtime/chain-handlers.ts +47 -0
  318. package/src/runtime/components/rnwind-provider.tsx +144 -0
  319. package/src/runtime/gradient-types.ts +60 -0
  320. package/src/runtime/haptics.ts +120 -0
  321. package/src/runtime/hooks/use-css.ts +16 -0
  322. package/src/runtime/hooks/use-interact.ts +65 -0
  323. package/src/runtime/hooks/use-scheme.ts +63 -0
  324. package/src/runtime/index.ts +54 -0
  325. package/src/runtime/interactive-box.tsx +57 -0
  326. package/src/runtime/lookup-css.ts +628 -0
  327. package/src/runtime/types.ts +32 -0
  328. package/src/testing/index.ts +507 -0
  329. package/src/types/tailwindcss-node.d.ts +33 -0
  330. package/src/index.ts +0 -1
@@ -0,0 +1,257 @@
1
+ import { existsSync, readFileSync, statSync } from 'node:fs'
2
+ import path from 'node:path'
3
+ import { createHash } from 'node:crypto'
4
+ import { UnionBuilder } from '../core/style-builder'
5
+ import { TailwindParser, type SourceEntry } from '../core/parser'
6
+
7
+ /**
8
+ * Default oxide Scanner globs — walk every JS/TS source under the
9
+ * project root AND every monorepo watch folder, excluding
10
+ * `node_modules` and rnwind's own cache dir so we don't rescan
11
+ * generated scheme files.
12
+ *
13
+ * Monorepo layouts (Yarn workspaces, pnpm workspaces, Nx) surface
14
+ * sibling package roots as `metroConfig.watchFolders`. Every folder
15
+ * Metro watches must also be scanned so atoms declared in shared UI
16
+ * packages make it into the union — without this, only the app's
17
+ * own files would be scanned and every UI-package atom would resolve
18
+ * to `undefined` at runtime.
19
+ * @param projectRoot Absolute project root.
20
+ * @param cacheDir Absolute rnwind cache dir (to exclude).
21
+ * @param watchFolders Extra monorepo roots Metro is watching.
22
+ * @returns Scanner sources suitable for `parser.parseProject()`.
23
+ */
24
+ function defaultSources(projectRoot: string, cacheDir: string, watchFolders: readonly string[]): readonly SourceEntry[] {
25
+ const cacheBaseName = path.basename(cacheDir)
26
+ const roots = new Set<string>([projectRoot, ...watchFolders])
27
+ const sources: SourceEntry[] = []
28
+ for (const root of roots) {
29
+ sources.push({ base: root, pattern: '**/*.{ts,tsx,js,jsx}', negated: false }, { base: root, pattern: '**/node_modules/**', negated: true }, { base: root, pattern: `**/${cacheBaseName}/**`, negated: true })
30
+ }
31
+ return sources
32
+ }
33
+
34
+ /**
35
+ * Read monorepo watch-folder paths out of the worker environment.
36
+ * Empty array when the host isn't a monorepo.
37
+ * @returns Absolute paths Metro also watches (sibling packages).
38
+ */
39
+ function readWatchFolders(): readonly string[] {
40
+ const raw = process.env[WATCH_FOLDERS_ENV]
41
+ if (!raw || raw.length === 0) return []
42
+ return raw.split('\0').filter((entry) => entry.length > 0)
43
+ }
44
+
45
+ /** Env var Metro workers read to locate the theme CSS on disk. */
46
+ const CSS_ENTRY_ENV = 'RNWIND_CSS_ENTRY_FILE'
47
+ /** Env var Metro workers read to locate the cache directory (`.rnwind`). */
48
+ const CACHE_DIR_ENV = 'RNWIND_CACHE_DIR'
49
+ /** Env var carrying `watchFolders` from Metro config (NUL-separated). */
50
+ const WATCH_FOLDERS_ENV = 'RNWIND_WATCH_FOLDERS'
51
+ /** Env var carrying extra className prefixes the Metro config supplied. */
52
+ const CLASSNAME_PREFIXES_ENV = 'RNWIND_CLASSNAME_PREFIXES'
53
+
54
+ /** Memoised library fingerprint — read once per worker process. */
55
+ let libraryFingerprint: string | undefined
56
+
57
+ /** Live state shared across one Metro transform worker. */
58
+ let cached: RnwindState | null = null
59
+
60
+ /**
61
+ * Cheap content-hash readout. SHA-256 prefix of the CSS bytes plus the
62
+ * file's mtime nanoseconds (so identical content with different mtime
63
+ * — atomic rewrites — still picks up the change). Returns `'missing'`
64
+ * when the file can't be read so the cache key is still deterministic.
65
+ * @param cssPath Absolute CSS path.
66
+ * @returns 16-char hex content hash.
67
+ */
68
+ function readThemeHashFor(cssPath: string): string {
69
+ if (!existsSync(cssPath)) return 'missing'
70
+ try {
71
+ const bytes = readFileSync(cssPath)
72
+ const mtime = statSync(cssPath).mtimeMs.toString()
73
+ return createHash('sha256').update(bytes).update(mtime).digest('hex').slice(0, 16)
74
+ } catch {
75
+ return 'missing'
76
+ }
77
+ }
78
+
79
+ /**
80
+ * Hash a small set of rnwind library files whose changes affect the
81
+ * generated transform output. When the library is rebuilt (workspace
82
+ * dev OR npm install of a new version) the file bytes change, the
83
+ * fingerprint rotates, and Metro's transform cache invalidates.
84
+ *
85
+ * Includes the JSX rewriter (`transform-ast`) alongside the parser /
86
+ * style-builder so a change to the transformer — e.g. renaming the
87
+ * injected context hook — invalidates every stale per-file cache entry
88
+ * on the next dev run. Without this, a user upgrading rnwind in-place
89
+ * would keep loading the old transformed bytes; React-refresh would
90
+ * then preserve fiber state across the version bump and the rendered
91
+ * hook list could shift, surfacing as "change in the order of Hooks"
92
+ * runtime errors.
93
+ * Memoised — read once per worker process.
94
+ * @returns 16-char hex fingerprint.
95
+ */
96
+ function getLibraryFingerprint(): string {
97
+ if (libraryFingerprint !== undefined) return libraryFingerprint
98
+ const here = path.dirname(__filename)
99
+ const candidates = [
100
+ path.resolve(here, '..', 'core', 'style-builder', 'build-style.mjs'),
101
+ path.resolve(here, '..', 'core', 'style-builder', 'build-style.cjs'),
102
+ path.resolve(here, '..', 'core', 'parser', 'tw-parser.mjs'),
103
+ path.resolve(here, '..', 'core', 'parser', 'tw-parser.cjs'),
104
+ path.resolve(here, 'transform-ast.mjs'),
105
+ path.resolve(here, 'transform-ast.cjs'),
106
+ path.resolve(here, 'transformer.mjs'),
107
+ path.resolve(here, 'transformer.cjs'),
108
+ // Source-tree fallback for tests + workspace dev (no built lib yet).
109
+ path.resolve(here, '..', '..', 'src', 'core', 'style-builder', 'build-style.ts'),
110
+ path.resolve(here, '..', '..', 'src', 'core', 'parser', 'tw-parser.ts'),
111
+ path.resolve(here, '..', '..', 'src', 'metro', 'transform-ast.ts'),
112
+ path.resolve(here, '..', '..', 'src', 'metro', 'transformer.ts'),
113
+ ]
114
+ const hash = createHash('sha256')
115
+ let included = 0
116
+ for (const file of candidates) {
117
+ if (!existsSync(file)) continue
118
+ try {
119
+ hash.update(readFileSync(file))
120
+ included += 1
121
+ } catch {
122
+ // Unreadable file — skip; fingerprint still derives from whatever WE could read.
123
+ }
124
+ }
125
+ libraryFingerprint = included > 0 ? hash.digest('hex').slice(0, 16) : '0'.repeat(16)
126
+ return libraryFingerprint
127
+ }
128
+
129
+ /**
130
+ * Worker-local state. Lazy-initialised on first access so files that
131
+ * bypass the transform don't pay for construction.
132
+ */
133
+ export interface RnwindState {
134
+ parser: TailwindParser
135
+ builder: UnionBuilder
136
+ themeCss: string
137
+ themeHash: string
138
+ projectRoot: string
139
+ }
140
+
141
+ /**
142
+ * Publish the theme CSS path + cache dir to the environment so worker
143
+ * subprocesses (spawned by Metro once `babelTransformerPath` is set)
144
+ * can rebuild the same state without re-reading the Metro config.
145
+ * @param cssEntryFile Absolute path to the user's theme CSS.
146
+ * @param cacheDir Absolute path to the cache dir (`.rnwind`).
147
+ * @param watchFolders
148
+ * @param classNamePrefixes Extra JSX prop-name prefixes to rewrite.
149
+ */
150
+ export function configureRnwindState(
151
+ cssEntryFile: string,
152
+ cacheDir: string,
153
+ watchFolders: readonly string[] = [],
154
+ classNamePrefixes?: readonly string[],
155
+ ): void {
156
+ process.env[CSS_ENTRY_ENV] = cssEntryFile
157
+ process.env[CACHE_DIR_ENV] = cacheDir
158
+ if (watchFolders.length === 0) {
159
+ delete process.env[WATCH_FOLDERS_ENV]
160
+ } else {
161
+ process.env[WATCH_FOLDERS_ENV] = watchFolders.join('\0')
162
+ }
163
+ if (!classNamePrefixes || classNamePrefixes.length === 0) {
164
+ delete process.env[CLASSNAME_PREFIXES_ENV]
165
+ } else {
166
+ process.env[CLASSNAME_PREFIXES_ENV] = classNamePrefixes.join(',')
167
+ }
168
+ cached = null
169
+ }
170
+
171
+ /**
172
+ * Read the caller-configured extra className prefixes out of the
173
+ * worker environment. Returns an empty array when unset — the
174
+ * transformer applies the built-in `contentContainer` default on top
175
+ * either way.
176
+ * @returns User-supplied extra prefixes.
177
+ */
178
+ export function getClassNamePrefixes(): readonly string[] {
179
+ const raw = process.env[CLASSNAME_PREFIXES_ENV]
180
+ if (!raw || raw.length === 0) return []
181
+ return raw.split(',').filter((entry) => entry.length > 0)
182
+ }
183
+
184
+ /**
185
+ * Fetch (or build) the worker-local rnwind state. Re-reads the theme
186
+ * CSS hash on every call: if the user edited `global.css` while Metro
187
+ * is running, the cached state is dropped and a fresh parser + ledger
188
+ * is built. Combined with the `getCacheKey()` export on the
189
+ * transformer (which folds the same hash into Metro's per-file cache
190
+ * key) every CSS edit produces a full, correct re-bundle.
191
+ * @param projectRoot
192
+ * @returns The live rnwind state.
193
+ */
194
+ export function getRnwindState(projectRoot: string): RnwindState {
195
+ const cssEntry = process.env[CSS_ENTRY_ENV]
196
+ const cacheDir = process.env[CACHE_DIR_ENV]
197
+ if (!cssEntry) throw new Error('rnwind: RNWIND_CSS_ENTRY_FILE is not set — did `withRnwindConfig` run?')
198
+ if (!cacheDir) throw new Error('rnwind: RNWIND_CACHE_DIR is not set — did `withRnwindConfig` run?')
199
+ const currentHash = readThemeHashFor(cssEntry)
200
+ if (cached?.themeHash === currentHash && cached.projectRoot === projectRoot) return cached
201
+ const themeCss = readFileSync(cssEntry, 'utf8')
202
+ const parser = new TailwindParser({
203
+ themeCss,
204
+ sources: defaultSources(projectRoot, cacheDir, readWatchFolders()),
205
+ })
206
+ const builder = new UnionBuilder(cacheDir, parser)
207
+ cached = { parser, builder, themeCss, themeHash: currentHash, projectRoot }
208
+ return cached
209
+ }
210
+
211
+ /**
212
+ * Compute the rnwind cache-key suffix Metro mixes into every per-file
213
+ * transform cache entry via the transformer's `getCacheKey()` export.
214
+ * Includes the CSS path + its current content hash + the rnwind
215
+ * library fingerprint, so any edit to `global.css` OR a library
216
+ * upgrade flips the cache key and forces Metro to re-run the
217
+ * transformer.
218
+ * @returns Deterministic string suitable for appending to Metro's cache key.
219
+ */
220
+ export function getRnwindCacheKey(): string {
221
+ const cssEntry = process.env[CSS_ENTRY_ENV] ?? ''
222
+ const prefixes = process.env[CLASSNAME_PREFIXES_ENV] ?? ''
223
+ return `rnwind:${cssEntry}:${readThemeHashFor(cssEntry)}|lib:${getLibraryFingerprint()}|pfx:${prefixes}`
224
+ }
225
+
226
+ /** Drop the cached state — call after editing the theme CSS. */
227
+ export function resetRnwindState(): void {
228
+ cached = null
229
+ }
230
+
231
+ /**
232
+ * Drop cached state, rebuild parser/builder with the fresh CSS, rescan
233
+ * the project, and rewrite every scheme file on disk. This is what
234
+ * `withRnwindConfig`'s CSS file-watcher invokes so `global.css` edits
235
+ * propagate to the app via Metro's HMR — without this, the CSS-as-JS
236
+ * module would re-emit `export {}` whose bytes never change, so Metro
237
+ * would never invalidate downstream modules.
238
+ * @param projectRoot Absolute project root (from `metroConfig.projectRoot`).
239
+ */
240
+ export async function onThemeChange(projectRoot: string): Promise<void> {
241
+ resetRnwindState()
242
+ const state = getRnwindState(projectRoot)
243
+ await state.builder.writeSchemes()
244
+ }
245
+
246
+ /**
247
+ * Resolve the on-disk path of the scheme manifest module for the
248
+ * resolver. The manifest eager-imports `common.style.js` and
249
+ * lazy-requires each variant scheme; SchemeProvider calls its
250
+ * `ensureSchemeLoaded` export to trigger per-scheme requires.
251
+ * @returns Absolute path to `<cacheDir>/schemes.js`.
252
+ */
253
+ export function manifestPathFor(): string {
254
+ const cacheDir = process.env[CACHE_DIR_ENV]
255
+ if (!cacheDir) throw new Error('rnwind: RNWIND_CACHE_DIR is not set')
256
+ return path.join(cacheDir, 'schemes.js')
257
+ }