rnwind 0.0.1 → 0.0.3

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 +193 -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 +120 -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 +110 -0
  36. package/lib/cjs/core/parser/length.cjs.map +1 -0
  37. package/lib/cjs/core/parser/length.d.ts +51 -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 +188 -0
  51. package/lib/cjs/core/parser/shorthand.cjs.map +1 -0
  52. package/lib/cjs/core/parser/shorthand.d.ts +67 -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 +467 -0
  57. package/lib/cjs/core/parser/theme-vars.cjs.map +1 -0
  58. package/lib/cjs/core/parser/theme-vars.d.ts +82 -0
  59. package/lib/cjs/core/parser/tokens.cjs +486 -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 +1680 -0
  66. package/lib/cjs/core/parser/tw-parser.cjs.map +1 -0
  67. package/lib/cjs/core/parser/tw-parser.d.ts +210 -0
  68. package/lib/cjs/core/parser/types.d.ts +37 -0
  69. package/lib/cjs/core/parser/typography-dispatcher.cjs +108 -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 +444 -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 +301 -0
  93. package/lib/cjs/metro/state.cjs.map +1 -0
  94. package/lib/cjs/metro/state.d.ts +88 -0
  95. package/lib/cjs/metro/transform-ast.cjs +1472 -0
  96. package/lib/cjs/metro/transform-ast.cjs.map +1 -0
  97. package/lib/cjs/metro/transform-ast.d.ts +88 -0
  98. package/lib/cjs/metro/transformer.cjs +372 -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 +79 -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 +191 -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 +118 -0
  172. package/lib/esm/core/parser/layout-dispatcher.mjs.map +1 -0
  173. package/lib/esm/core/parser/length.d.ts +51 -0
  174. package/lib/esm/core/parser/length.mjs +104 -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 +67 -0
  189. package/lib/esm/core/parser/shorthand.mjs +180 -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 +82 -0
  195. package/lib/esm/core/parser/theme-vars.mjs +461 -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 +480 -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 +210 -0
  204. package/lib/esm/core/parser/tw-parser.mjs +1678 -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 +106 -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 +442 -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 +88 -0
  231. package/lib/esm/metro/state.mjs +291 -0
  232. package/lib/esm/metro/state.mjs.map +1 -0
  233. package/lib/esm/metro/transform-ast.d.ts +88 -0
  234. package/lib/esm/metro/transform-ast.mjs +1451 -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 +349 -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 +79 -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 +80 -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 +191 -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 +111 -0
  291. package/src/core/parser/length.ts +114 -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 +182 -0
  297. package/src/core/parser/text-truncate.ts +79 -0
  298. package/src/core/parser/theme-vars.ts +465 -0
  299. package/src/core/parser/tokens.ts +456 -0
  300. package/src/core/parser/transform.ts +195 -0
  301. package/src/core/parser/tw-parser.ts +1828 -0
  302. package/src/core/parser/types.ts +45 -0
  303. package/src/core/parser/typography-dispatcher.ts +97 -0
  304. package/src/core/parser/typography.ts +83 -0
  305. package/src/core/style-builder/build-style.ts +500 -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 +305 -0
  313. package/src/metro/transform-ast.ts +1729 -0
  314. package/src/metro/transformer.ts +372 -0
  315. package/src/metro/warn-unknown-classes.ts +79 -0
  316. package/src/metro/with-config.ts +251 -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,305 @@
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
+ /** Env var carrying extra import sources whose JSX exports get className→style rewrites. Comma-separated. */
54
+ const HOST_SOURCES_ENV = 'RNWIND_HOST_SOURCES'
55
+ /** Env var carrying extra JSX tag names (verbatim, may contain `.`) treated as hosts. Comma-separated. */
56
+ const HOST_COMPONENTS_ENV = 'RNWIND_HOST_COMPONENTS'
57
+
58
+ /** Memoised library fingerprint — read once per worker process. */
59
+ let libraryFingerprint: string | undefined
60
+
61
+ /** Live state shared across one Metro transform worker. */
62
+ let cached: RnwindState | null = null
63
+
64
+ /**
65
+ * Cheap content-hash readout. SHA-256 prefix of the CSS bytes plus the
66
+ * file's mtime nanoseconds (so identical content with different mtime
67
+ * — atomic rewrites — still picks up the change). Returns `'missing'`
68
+ * when the file can't be read so the cache key is still deterministic.
69
+ * @param cssPath Absolute CSS path.
70
+ * @returns 16-char hex content hash.
71
+ */
72
+ function readThemeHashFor(cssPath: string): string {
73
+ if (!existsSync(cssPath)) return 'missing'
74
+ try {
75
+ const bytes = readFileSync(cssPath)
76
+ const mtime = statSync(cssPath).mtimeMs.toString()
77
+ return createHash('sha256').update(bytes).update(mtime).digest('hex').slice(0, 16)
78
+ } catch {
79
+ return 'missing'
80
+ }
81
+ }
82
+
83
+ /**
84
+ * Hash a small set of rnwind library files whose changes affect the
85
+ * generated transform output. When the library is rebuilt (workspace
86
+ * dev OR npm install of a new version) the file bytes change, the
87
+ * fingerprint rotates, and Metro's transform cache invalidates.
88
+ *
89
+ * Includes the JSX rewriter (`transform-ast`) alongside the parser /
90
+ * style-builder so a change to the transformer — e.g. renaming the
91
+ * injected context hook — invalidates every stale per-file cache entry
92
+ * on the next dev run. Without this, a user upgrading rnwind in-place
93
+ * would keep loading the old transformed bytes; React-refresh would
94
+ * then preserve fiber state across the version bump and the rendered
95
+ * hook list could shift, surfacing as "change in the order of Hooks"
96
+ * runtime errors.
97
+ * Memoised — read once per worker process.
98
+ * @returns 16-char hex fingerprint.
99
+ */
100
+ function getLibraryFingerprint(): string {
101
+ if (libraryFingerprint !== undefined) return libraryFingerprint
102
+ const here = path.dirname(__filename)
103
+ const candidates = [
104
+ path.resolve(here, '..', 'core', 'style-builder', 'build-style.mjs'),
105
+ path.resolve(here, '..', 'core', 'style-builder', 'build-style.cjs'),
106
+ path.resolve(here, '..', 'core', 'parser', 'tw-parser.mjs'),
107
+ path.resolve(here, '..', 'core', 'parser', 'tw-parser.cjs'),
108
+ path.resolve(here, 'transform-ast.mjs'),
109
+ path.resolve(here, 'transform-ast.cjs'),
110
+ path.resolve(here, 'transformer.mjs'),
111
+ path.resolve(here, 'transformer.cjs'),
112
+ // Source-tree fallback for tests + workspace dev (no built lib yet).
113
+ path.resolve(here, '..', '..', 'src', 'core', 'style-builder', 'build-style.ts'),
114
+ path.resolve(here, '..', '..', 'src', 'core', 'parser', 'tw-parser.ts'),
115
+ path.resolve(here, '..', '..', 'src', 'metro', 'transform-ast.ts'),
116
+ path.resolve(here, '..', '..', 'src', 'metro', 'transformer.ts'),
117
+ ]
118
+ const hash = createHash('sha256')
119
+ let included = 0
120
+ for (const file of candidates) {
121
+ if (!existsSync(file)) continue
122
+ try {
123
+ hash.update(readFileSync(file))
124
+ included += 1
125
+ } catch {
126
+ // Unreadable file — skip; fingerprint still derives from whatever WE could read.
127
+ }
128
+ }
129
+ libraryFingerprint = included > 0 ? hash.digest('hex').slice(0, 16) : '0'.repeat(16)
130
+ return libraryFingerprint
131
+ }
132
+
133
+ /**
134
+ * Worker-local state. Lazy-initialised on first access so files that
135
+ * bypass the transform don't pay for construction.
136
+ */
137
+ export interface RnwindState {
138
+ parser: TailwindParser
139
+ builder: UnionBuilder
140
+ themeCss: string
141
+ themeHash: string
142
+ projectRoot: string
143
+ }
144
+
145
+ /**
146
+ * Publish the theme CSS path + cache dir to the environment so worker
147
+ * subprocesses (spawned by Metro once `babelTransformerPath` is set)
148
+ * can rebuild the same state without re-reading the Metro config.
149
+ * @param cssEntryFile Absolute path to the user's theme CSS.
150
+ * @param cacheDir Absolute path to the cache dir (`.rnwind`).
151
+ * @param watchFolders
152
+ * @param classNamePrefixes Extra JSX prop-name prefixes to rewrite.
153
+ * @param hostSources
154
+ * @param hostComponents
155
+ */
156
+ export function configureRnwindState(
157
+ cssEntryFile: string,
158
+ cacheDir: string,
159
+ watchFolders: readonly string[] = [],
160
+ classNamePrefixes?: readonly string[],
161
+ hostSources?: readonly string[],
162
+ hostComponents?: readonly string[],
163
+ ): void {
164
+ process.env[CSS_ENTRY_ENV] = cssEntryFile
165
+ process.env[CACHE_DIR_ENV] = cacheDir
166
+ if (watchFolders.length === 0) {
167
+ delete process.env[WATCH_FOLDERS_ENV]
168
+ } else {
169
+ process.env[WATCH_FOLDERS_ENV] = watchFolders.join('\0')
170
+ }
171
+ if (!classNamePrefixes || classNamePrefixes.length === 0) {
172
+ delete process.env[CLASSNAME_PREFIXES_ENV]
173
+ } else {
174
+ process.env[CLASSNAME_PREFIXES_ENV] = classNamePrefixes.join(',')
175
+ }
176
+ if (!hostSources || hostSources.length === 0) {
177
+ delete process.env[HOST_SOURCES_ENV]
178
+ } else {
179
+ process.env[HOST_SOURCES_ENV] = hostSources.join(',')
180
+ }
181
+ if (!hostComponents || hostComponents.length === 0) {
182
+ delete process.env[HOST_COMPONENTS_ENV]
183
+ } else {
184
+ process.env[HOST_COMPONENTS_ENV] = hostComponents.join(',')
185
+ }
186
+ cached = null
187
+ }
188
+
189
+ /**
190
+ * Read the caller-configured extra className prefixes out of the
191
+ * worker environment. Returns an empty array when unset — the
192
+ * transformer applies the built-in `contentContainer` default on top
193
+ * either way.
194
+ * @returns User-supplied extra prefixes.
195
+ */
196
+ export function getClassNamePrefixes(): readonly string[] {
197
+ const raw = process.env[CLASSNAME_PREFIXES_ENV]
198
+ if (!raw || raw.length === 0) return []
199
+ return raw.split(',').filter((entry) => entry.length > 0)
200
+ }
201
+
202
+ /**
203
+ * Read the caller-configured extra host module sources out of the
204
+ * worker environment. Empty array when unset — the transformer applies
205
+ * its built-in default list on top either way.
206
+ * @returns User-supplied extra host sources.
207
+ */
208
+ export function getHostSources(): readonly string[] {
209
+ const raw = process.env[HOST_SOURCES_ENV]
210
+ if (!raw || raw.length === 0) return []
211
+ return raw.split(',').filter((entry) => entry.length > 0)
212
+ }
213
+
214
+ /**
215
+ * Read the caller-configured extra host JSX tag names out of the worker
216
+ * environment. Verbatim names — may include `.` for member expressions
217
+ * like `'Animated.View'`.
218
+ * @returns User-supplied extra host component names.
219
+ */
220
+ export function getHostComponents(): readonly string[] {
221
+ const raw = process.env[HOST_COMPONENTS_ENV]
222
+ if (!raw || raw.length === 0) return []
223
+ return raw.split(',').filter((entry) => entry.length > 0)
224
+ }
225
+
226
+ /**
227
+ * Fetch (or build) the worker-local rnwind state. Re-reads the theme
228
+ * CSS hash on every call: if the user edited `global.css` while Metro
229
+ * is running, the cached state is dropped and a fresh parser + ledger
230
+ * is built. Combined with the `getCacheKey()` export on the
231
+ * transformer (which folds the same hash into Metro's per-file cache
232
+ * key) every CSS edit produces a full, correct re-bundle.
233
+ * @param projectRoot
234
+ * @returns The live rnwind state.
235
+ */
236
+ export function getRnwindState(projectRoot: string): RnwindState {
237
+ const cssEntry = process.env[CSS_ENTRY_ENV]
238
+ const cacheDir = process.env[CACHE_DIR_ENV]
239
+ if (!cssEntry) throw new Error('rnwind: RNWIND_CSS_ENTRY_FILE is not set — did `withRnwindConfig` run?')
240
+ if (!cacheDir) throw new Error('rnwind: RNWIND_CACHE_DIR is not set — did `withRnwindConfig` run?')
241
+ const currentHash = readThemeHashFor(cssEntry)
242
+ if (cached?.themeHash === currentHash && cached.projectRoot === projectRoot) return cached
243
+ const themeCss = readFileSync(cssEntry, 'utf8')
244
+ const parser = new TailwindParser({
245
+ themeCss,
246
+ sources: defaultSources(projectRoot, cacheDir, readWatchFolders()),
247
+ })
248
+ const builder = new UnionBuilder(cacheDir, parser)
249
+ cached = { parser, builder, themeCss, themeHash: currentHash, projectRoot }
250
+ return cached
251
+ }
252
+
253
+ /**
254
+ * Compute the rnwind cache-key suffix Metro mixes into every per-file
255
+ * transform cache entry via the transformer's `getCacheKey()` export.
256
+ * Includes the CSS path + its current content hash + the rnwind
257
+ * library fingerprint, so any edit to `global.css` OR a library
258
+ * upgrade flips the cache key and forces Metro to re-run the
259
+ * transformer.
260
+ * @returns Deterministic string suitable for appending to Metro's cache key.
261
+ */
262
+ export function getRnwindCacheKey(): string {
263
+ const cssEntry = process.env[CSS_ENTRY_ENV] ?? ''
264
+ const prefixes = process.env[CLASSNAME_PREFIXES_ENV] ?? ''
265
+ // Host source / component config changes which JSX tags get rewritten,
266
+ // so it MUST flip the cache key — otherwise Metro replays stale
267
+ // transforms (a newly-opted-in host keeps its raw className, a removed
268
+ // one keeps the rewrite).
269
+ const hostSources = process.env[HOST_SOURCES_ENV] ?? ''
270
+ const hostComponents = process.env[HOST_COMPONENTS_ENV] ?? ''
271
+ return `rnwind:${cssEntry}:${readThemeHashFor(cssEntry)}|lib:${getLibraryFingerprint()}|pfx:${prefixes}|hs:${hostSources}|hc:${hostComponents}`
272
+ }
273
+
274
+ /** Drop the cached state — call after editing the theme CSS. */
275
+ export function resetRnwindState(): void {
276
+ cached = null
277
+ }
278
+
279
+ /**
280
+ * Drop cached state, rebuild parser/builder with the fresh CSS, rescan
281
+ * the project, and rewrite every scheme file on disk. This is what
282
+ * `withRnwindConfig`'s CSS file-watcher invokes so `global.css` edits
283
+ * propagate to the app via Metro's HMR — without this, the CSS-as-JS
284
+ * module would re-emit `export {}` whose bytes never change, so Metro
285
+ * would never invalidate downstream modules.
286
+ * @param projectRoot Absolute project root (from `metroConfig.projectRoot`).
287
+ */
288
+ export async function onThemeChange(projectRoot: string): Promise<void> {
289
+ resetRnwindState()
290
+ const state = getRnwindState(projectRoot)
291
+ await state.builder.writeSchemes()
292
+ }
293
+
294
+ /**
295
+ * Resolve the on-disk path of the scheme manifest module for the
296
+ * resolver. The manifest eager-imports `common.style.js` and
297
+ * lazy-requires each variant scheme; SchemeProvider calls its
298
+ * `ensureSchemeLoaded` export to trigger per-scheme requires.
299
+ * @returns Absolute path to `<cacheDir>/schemes.js`.
300
+ */
301
+ export function manifestPathFor(): string {
302
+ const cacheDir = process.env[CACHE_DIR_ENV]
303
+ if (!cacheDir) throw new Error('rnwind: RNWIND_CACHE_DIR is not set')
304
+ return path.join(cacheDir, 'schemes.js')
305
+ }