@fluentic/style 0.1.0-beta.1 → 0.1.0-beta.11

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 (491) hide show
  1. package/CHANGELOG.md +156 -2
  2. package/README.md +181 -49
  3. package/atomic/atRule/utils.ts +3 -2
  4. package/atomic/className.ts +50 -12
  5. package/atomic/debug/className/className.ts +24 -8
  6. package/atomic/element.ts +5 -2
  7. package/atomic/rule.ts +11 -5
  8. package/atomic/scope.ts +19 -0
  9. package/atomic/theme.ts +44 -3
  10. package/atomic/token.ts +7 -4
  11. package/atomic/utils/cssIdent.ts +54 -0
  12. package/atomic/utils/cssVar.ts +19 -0
  13. package/atomic/utils/debug.ts +1 -1
  14. package/atomic/utils/format.ts +1 -1
  15. package/atomic/utils/hash.ts +14 -0
  16. package/atomic/utils/selector.ts +31 -1
  17. package/atomic/var.ts +3 -2
  18. package/builder/classname/class_name_builder.ts +491 -0
  19. package/builder/classname/fns.ts +77 -0
  20. package/builder/classname/index.ts +3 -0
  21. package/builder/classname/types.ts +41 -0
  22. package/builder/data/const.ts +8 -1
  23. package/builder/data/create.ts +52 -6
  24. package/builder/data/data.ts +33 -8
  25. package/builder/data/debug.ts +1 -0
  26. package/builder/data/index.ts +0 -1
  27. package/builder/data/is.ts +26 -3
  28. package/builder/data/merge/scope.ts +38 -38
  29. package/builder/data/merge/style.ts +115 -20
  30. package/builder/data/state.ts +17 -2
  31. package/builder/extract/index.ts +1 -0
  32. package/builder/extract/sheet.ts +30 -0
  33. package/builder/extract/token.ts +30 -14
  34. package/builder/extract/utils.ts +2 -0
  35. package/builder/extract/withTokens.ts +2 -1
  36. package/builder/selector_override.noop.ts +11 -0
  37. package/builder/selector_override.ts +31 -0
  38. package/builder/selector_override_core.ts +79 -0
  39. package/builder/style_builder.ts +144 -20
  40. package/builder/style_data.ts +25 -0
  41. package/builder/style_fns.ts +57 -57
  42. package/builder/token/data.ts +30 -0
  43. package/builder/token/index.ts +3 -0
  44. package/builder/token/name.ts +54 -0
  45. package/builder/token/symbols.ts +6 -0
  46. package/builder/types/alias.ts +44 -16
  47. package/builder/types/fns.ts +24 -16
  48. package/builder/types/types.ts +37 -7
  49. package/builder/utils.ts +1 -0
  50. package/compiler/compiler/compiler.ts +88 -14
  51. package/compiler/compiler/constants.ts +6 -0
  52. package/compiler/compiler/index.ts +1 -0
  53. package/compiler/compiler/types.ts +4 -1
  54. package/compiler/cssProp.ts +21 -0
  55. package/compiler/extract/extract.ts +42 -14
  56. package/compiler/extract/types.ts +2 -0
  57. package/compiler/index.ts +1 -0
  58. package/compiler/transform/cssProp/index.ts +1 -0
  59. package/compiler/transform/cssProp/plugin.ts +161 -0
  60. package/compiler/transform/debug/plugin.ts +93 -4
  61. package/compiler/transform/debug/transform.ts +2 -1
  62. package/compiler/transform/debug/utils/debug_data.ts +73 -0
  63. package/compiler/transform/evaluator/evaluator.ts +169 -32
  64. package/compiler/transform/evaluator/tracer.ts +48 -11
  65. package/compiler/transform/extract/chain/chain.ts +1370 -162
  66. package/compiler/transform/extract/chain/extract_chain.ts +12 -4
  67. package/compiler/transform/extract/chain/types.ts +3 -1
  68. package/compiler/transform/extract/plugin.ts +64 -6
  69. package/compiler/transform/extract/transform.ts +2 -1
  70. package/compiler/transform/extract/utils/replacement.ts +72 -2
  71. package/compiler/transform/extract/utils/state.ts +3 -0
  72. package/compiler/transform/extract/utils/theme.ts +6 -6
  73. package/compiler/transform/index.ts +1 -0
  74. package/compiler/transform/syntax/isStaticStyleValue.ts +15 -9
  75. package/compiler/transform/syntax/static_ids.ts +1 -1
  76. package/compiler/utils/constants.ts +12 -5
  77. package/compiler/utils/file_resolver.ts +2 -0
  78. package/compiler/utils/import_source.ts +19 -8
  79. package/compiler/utils/imports.ts +11 -1
  80. package/config/build.ts +9 -2
  81. package/config/config/check.ts +25 -0
  82. package/config/config/css.ts +18 -1
  83. package/config/config/debug.ts +24 -1
  84. package/config/config/dev.ts +17 -1
  85. package/config/configure.ts +19 -2
  86. package/config/types.ts +7 -0
  87. package/css/index.ts +2 -0
  88. package/css/sheet.ts +152 -0
  89. package/css/styleTarget.ts +251 -0
  90. package/dev/config.ts +2 -3
  91. package/dev/utils.ts +3 -3
  92. package/dialect/extracted/index.ts +5 -0
  93. package/dialect/index.ts +1 -0
  94. package/dialect/namedTokens.ts +153 -0
  95. package/dist/adapter/preact.js +2 -0
  96. package/dist/adapter/react.js +2 -0
  97. package/dist/adapter/solid.js +2 -0
  98. package/dist/className-yhJCGT0F.js +304 -0
  99. package/dist/className-yhJCGT0F.js.map +1 -0
  100. package/dist/combine-Bww7VnSr.js +1254 -0
  101. package/dist/combine-Bww7VnSr.js.map +1 -0
  102. package/dist/compiler/index.mjs +2 -2
  103. package/dist/{compiler-DENc3a2R.mjs → compiler-C3CEGGtI.mjs} +2335 -638
  104. package/dist/compiler-C3CEGGtI.mjs.map +1 -0
  105. package/dist/config/index.js +2 -2
  106. package/dist/config-BAEzRmSJ.js +6 -0
  107. package/dist/{config-Di2VYYKV.js.map → config-BAEzRmSJ.js.map} +1 -1
  108. package/dist/config-BKP5LOkt.js +35 -0
  109. package/dist/config-BKP5LOkt.js.map +1 -0
  110. package/dist/config-C5VWvTav.js +34 -0
  111. package/dist/config-C5VWvTav.js.map +1 -0
  112. package/dist/config-CB4lm2tM.js +1 -0
  113. package/dist/config-CDjbHwb-.js +6 -0
  114. package/dist/config-CDjbHwb-.js.map +1 -0
  115. package/dist/config-DNEnHEf3.js +36 -0
  116. package/dist/config-DNEnHEf3.js.map +1 -0
  117. package/dist/createTransformElement-D8fXZ3wA.js +34 -0
  118. package/dist/createTransformElement-D8fXZ3wA.js.map +1 -0
  119. package/dist/css-BDn0epJ8.js +1339 -0
  120. package/dist/css-BDn0epJ8.js.map +1 -0
  121. package/dist/css-CFxNrYt3.js +4040 -0
  122. package/dist/css-CFxNrYt3.js.map +1 -0
  123. package/dist/css-DEYgrj76.js +524 -0
  124. package/dist/css-DEYgrj76.js.map +1 -0
  125. package/dist/{runtime-CYqNCiaM.js → css-DWBWsyxZ.js} +16 -19
  126. package/dist/css-DWBWsyxZ.js.map +1 -0
  127. package/dist/css.js +2 -2
  128. package/dist/{css_extra-oIi3UEPK.js → css_extra-nTq_Gw0E.js} +2 -2
  129. package/dist/{css_extra-DlOnsnR1.js.map → css_extra-nTq_Gw0E.js.map} +1 -1
  130. package/dist/data-CDrS1Bq4.js +785 -0
  131. package/dist/data-CDrS1Bq4.js.map +1 -0
  132. package/dist/debug-BkVbf0Cz.js +52 -0
  133. package/dist/debug-BkVbf0Cz.js.map +1 -0
  134. package/dist/{debug-n2aZQBSa.js → debug-YuhEIQVO.js} +80 -4
  135. package/dist/debug-YuhEIQVO.js.map +1 -0
  136. package/dist/dev/rsc.js +10 -9
  137. package/dist/dev/rsc.js.map +1 -1
  138. package/dist/{dev-CcphAa3R.js → dev-0imWmSVb.js} +10 -10
  139. package/dist/dev-0imWmSVb.js.map +1 -0
  140. package/dist/dev.js +1 -1
  141. package/dist/dialect/extracted/index.js +2 -0
  142. package/dist/dialect/index.js +2 -0
  143. package/dist/{elementMarker-Bu7gDAkE.js → elementMarker-kvpMjB49.js} +164 -30
  144. package/dist/elementMarker-kvpMjB49.js.map +1 -0
  145. package/dist/entry/dev/adapter/preact.js +12 -0
  146. package/dist/entry/dev/adapter/preact.js.map +1 -0
  147. package/dist/entry/dev/adapter/react.js +12 -0
  148. package/dist/entry/dev/adapter/react.js.map +1 -0
  149. package/dist/entry/dev/adapter/solid.js +12 -0
  150. package/dist/entry/dev/adapter/solid.js.map +1 -0
  151. package/dist/entry/dev/css.js +3 -3
  152. package/dist/entry/dev/jsx-dev-runtime.js +2 -1
  153. package/dist/entry/dev/jsx-runtime.js +2 -1
  154. package/dist/entry/dev.js +13 -9
  155. package/dist/entry/prod/adapter/preact.js +12 -0
  156. package/dist/entry/prod/adapter/preact.js.map +1 -0
  157. package/dist/entry/prod/adapter/react.js +12 -0
  158. package/dist/entry/prod/adapter/react.js.map +1 -0
  159. package/dist/entry/prod/adapter/solid.js +12 -0
  160. package/dist/entry/prod/adapter/solid.js.map +1 -0
  161. package/dist/entry/prod/css.js +3 -3
  162. package/dist/entry/prod/extract.js +242 -3
  163. package/dist/entry/prod/extract.js.map +1 -0
  164. package/dist/entry/prod/jsx-dev-runtime.js +2 -2
  165. package/dist/entry/prod/jsx-runtime.js +2 -2
  166. package/dist/entry/prod/runtime.js +3 -4
  167. package/dist/entry/prod.js +84 -1201
  168. package/dist/entry/prod.js.map +1 -1
  169. package/dist/entry/rsc-dev/adapter/preact.js +13 -0
  170. package/dist/entry/rsc-dev/adapter/preact.js.map +1 -0
  171. package/dist/entry/rsc-dev/adapter/react.js +13 -0
  172. package/dist/entry/rsc-dev/adapter/react.js.map +1 -0
  173. package/dist/entry/rsc-dev/adapter/solid.js +13 -0
  174. package/dist/entry/rsc-dev/adapter/solid.js.map +1 -0
  175. package/dist/entry/rsc-dev/css.js +3 -3
  176. package/dist/entry/rsc-dev/dev.js +11 -13
  177. package/dist/entry/rsc-dev/dev.js.map +1 -1
  178. package/dist/entry/rsc-dev/jsx-dev-runtime.js +2 -2
  179. package/dist/entry/rsc-dev/jsx-runtime.js +2 -2
  180. package/dist/entry/rsc-dev.js +582 -664
  181. package/dist/entry/rsc-dev.js.map +1 -1
  182. package/dist/entry/rsc-prod/adapter/preact.js +2 -0
  183. package/dist/entry/rsc-prod/adapter/react.js +2 -0
  184. package/dist/entry/rsc-prod/adapter/solid.js +2 -0
  185. package/dist/entry/rsc-prod/css.js +9 -3
  186. package/dist/entry/rsc-prod/css.js.map +1 -0
  187. package/dist/entry/rsc-prod/jsx-dev-runtime.js +2 -2
  188. package/dist/entry/rsc-prod/jsx-runtime.js +2 -2
  189. package/dist/entry/rsc-prod/runtime.js +3 -4
  190. package/dist/entry/rsc-prod.js +242 -10
  191. package/dist/entry/rsc-prod.js.map +1 -0
  192. package/dist/{styleStore-Dea_WVbr.js → env-Cz8frh6e.js} +1335 -372
  193. package/dist/env-Cz8frh6e.js.map +1 -0
  194. package/dist/getClassName-9CsXbNls.js +545 -0
  195. package/dist/getClassName-9CsXbNls.js.map +1 -0
  196. package/dist/{utils-D7FAOyg6.js → getClassName-DGm-VNDo.js} +28 -65
  197. package/dist/getClassName-DGm-VNDo.js.map +1 -0
  198. package/dist/getClassName-Dtc4yyYI.js +47 -0
  199. package/dist/getClassName-Dtc4yyYI.js.map +1 -0
  200. package/dist/{getClassName-BlvXHYuf.js → getClassName-DtkplEIt.js} +56 -14
  201. package/dist/getClassName-DtkplEIt.js.map +1 -0
  202. package/dist/global-CAc9OjKx.js +14 -0
  203. package/dist/global-CAc9OjKx.js.map +1 -0
  204. package/dist/{format-3nKBE_5t.js → hash-Cr-LCWDt.js} +51 -29
  205. package/dist/hash-Cr-LCWDt.js.map +1 -0
  206. package/dist/index.js +10 -8
  207. package/dist/jsx/jsx-dev-runtime.js +2 -2
  208. package/dist/jsx/jsx-dev-runtime.server.js +1 -1
  209. package/dist/jsx/jsx-runtime.js +2 -2
  210. package/dist/jsx/jsx-runtime.server.js +1 -1
  211. package/dist/jsx-CVxpkS04.js +39 -0
  212. package/dist/jsx-CVxpkS04.js.map +1 -0
  213. package/dist/{jsx_dev_runtime-B6xs4by8.js → jsx_dev_runtime-D068tAsT.js} +2 -3
  214. package/dist/{jsx_dev_runtime-B6xs4by8.js.map → jsx_dev_runtime-D068tAsT.js.map} +1 -1
  215. package/dist/{jsx_runtime-iHLDwpcW.js → jsx_runtime-6Qa1lmz2.js} +2 -2
  216. package/dist/{jsx_runtime-iHLDwpcW.js.map → jsx_runtime-6Qa1lmz2.js.map} +1 -1
  217. package/dist/{jsx_runtime-04xfnsi7.js → jsx_runtime-DT1Tr9cH.js} +2 -3
  218. package/dist/{jsx_runtime-04xfnsi7.js.map → jsx_runtime-DT1Tr9cH.js.map} +1 -1
  219. package/dist/{loader-B5Kw0DD-.mjs → loader-_-VjzlrX.mjs} +13 -14
  220. package/dist/loader-_-VjzlrX.mjs.map +1 -0
  221. package/dist/{misc-DCdYYyhK.mjs → misc-B76PUnWe.mjs} +11 -6
  222. package/dist/misc-B76PUnWe.mjs.map +1 -0
  223. package/dist/namedTokens-5AayGokX.js +85 -0
  224. package/dist/namedTokens-5AayGokX.js.map +1 -0
  225. package/dist/plugin/farm/index.mjs +4 -3
  226. package/dist/plugin/farm/index.mjs.map +1 -1
  227. package/dist/plugin/nextjs/index.mjs +151 -31
  228. package/dist/plugin/nextjs/index.mjs.map +1 -1
  229. package/dist/plugin/nextjs/loader.mjs +4 -4
  230. package/dist/plugin/parcel/index.cjs +2 -0
  231. package/dist/plugin/parcel/index.mjs +3 -1
  232. package/dist/plugin/parcel/optimizer.cjs +3 -2
  233. package/dist/plugin/parcel/optimizer.cjs.map +1 -1
  234. package/dist/plugin/parcel/optimizer.mjs +3 -2
  235. package/dist/plugin/parcel/optimizer.mjs.map +1 -1
  236. package/dist/plugin/parcel/resolver.cjs +1 -1
  237. package/dist/plugin/parcel/resolver.mjs +2 -2
  238. package/dist/plugin/parcel/runtime.cjs +1 -1
  239. package/dist/plugin/parcel/runtime.mjs +1 -1
  240. package/dist/plugin/parcel/transformer.cjs +1 -1
  241. package/dist/plugin/parcel/transformer.mjs +2 -2
  242. package/dist/plugin/rspack/index.mjs +3 -2
  243. package/dist/plugin/rspack/index.mjs.map +1 -1
  244. package/dist/plugin/vite/index.mjs +13 -10
  245. package/dist/plugin/vite/index.mjs.map +1 -1
  246. package/dist/plugin/webpack/index.mjs +3 -2
  247. package/dist/plugin/webpack/loader.mjs +2 -2
  248. package/dist/presets/tailwind/index.js +995 -0
  249. package/dist/presets/tailwind/index.js.map +1 -0
  250. package/dist/{assert-BGdigdr5.js → presets-DSanixJV.js} +106 -2
  251. package/dist/presets-DSanixJV.js.map +1 -0
  252. package/dist/{registry-yHLRxyoo.mjs → registry-w8ET5R7v.mjs} +2 -2
  253. package/dist/{registry-yHLRxyoo.mjs.map → registry-w8ET5R7v.mjs.map} +1 -1
  254. package/dist/resolveClassNameRuntime-CJjlUP93.js +63 -0
  255. package/dist/resolveClassNameRuntime-CJjlUP93.js.map +1 -0
  256. package/dist/{rules-9HSO1pxL.js → rules-DaMaMHgb.js} +618 -138
  257. package/dist/rules-DaMaMHgb.js.map +1 -0
  258. package/dist/scope-CZdGAnl_.js +601 -0
  259. package/dist/scope-CZdGAnl_.js.map +1 -0
  260. package/dist/selector/index.js +1 -2
  261. package/dist/server.js +17 -11
  262. package/dist/server.js.map +1 -1
  263. package/dist/{shared-CxbHR89f.mjs → shared-C_cYxNzz.mjs} +4 -4
  264. package/dist/{shared-CxbHR89f.mjs.map → shared-C_cYxNzz.mjs.map} +1 -1
  265. package/dist/{shared-CBArHB9-.cjs → shared-PK52rW6T.cjs} +2338 -635
  266. package/dist/shared-PK52rW6T.cjs.map +1 -0
  267. package/dist/sheet-CxkO1Hwt.js +7 -0
  268. package/dist/sheet-CxkO1Hwt.js.map +1 -0
  269. package/dist/{sidecar-BFakLl0X.mjs → sidecar-BhvmXYsD.mjs} +3 -3
  270. package/dist/{sidecar-BFakLl0X.mjs.map → sidecar-BhvmXYsD.mjs.map} +1 -1
  271. package/dist/style-CAhAnRni.js +1129 -0
  272. package/dist/style-CAhAnRni.js.map +1 -0
  273. package/dist/{styleStore-DyNXBcUK.js → styleStore-BzLZwpwy.js} +8 -7
  274. package/dist/styleStore-BzLZwpwy.js.map +1 -0
  275. package/dist/styleStore-DaIJ4OPV.js +58 -0
  276. package/dist/styleStore-DaIJ4OPV.js.map +1 -0
  277. package/dist/token-D33mKTka.js +138 -0
  278. package/dist/token-D33mKTka.js.map +1 -0
  279. package/dist/{trace-Bu_qOqRy.js → trace-B3dpTRJp.js} +3 -3
  280. package/dist/{trace-Bu_qOqRy.js.map → trace-B3dpTRJp.js.map} +1 -1
  281. package/dist/{trace-CU0rvNYr.js → trace-c2WmBbmX.js} +2 -2
  282. package/dist/{trace-CU0rvNYr.js.map → trace-c2WmBbmX.js.map} +1 -1
  283. package/dist/transform-DSpimwwC.js +23 -0
  284. package/dist/transform-DSpimwwC.js.map +1 -0
  285. package/dist/{utils-Bdbqn0f8.mjs → utils-DND33M6y.mjs} +3 -3
  286. package/dist/{utils-Bdbqn0f8.mjs.map → utils-DND33M6y.mjs.map} +1 -1
  287. package/dist/utils-DZK0mfmY.js +42 -0
  288. package/dist/utils-DZK0mfmY.js.map +1 -0
  289. package/dist/utils-D_XgtMtn.js +72 -0
  290. package/dist/utils-D_XgtMtn.js.map +1 -0
  291. package/dist/utils-DxCpyV2E.js +62 -0
  292. package/dist/utils-DxCpyV2E.js.map +1 -0
  293. package/dist/{utils-BbehLOby.js → utils-H1VInWpd.js} +407 -234
  294. package/dist/utils-H1VInWpd.js.map +1 -0
  295. package/dist/utils-NdisireF.mjs +182 -0
  296. package/dist/utils-NdisireF.mjs.map +1 -0
  297. package/dist/utils.js +4 -4
  298. package/dist/utils.js.map +1 -1
  299. package/dist/value-CK0-Xbov.js +160 -0
  300. package/dist/value-CK0-Xbov.js.map +1 -0
  301. package/dist/{webpack-Dh6lox2l.mjs → webpack-D7QO0bKN.mjs} +5 -5
  302. package/dist/webpack-D7QO0bKN.mjs.map +1 -0
  303. package/entry/dev/adapter/preact.ts +8 -0
  304. package/entry/dev/adapter/react.ts +8 -0
  305. package/entry/dev/adapter/solid.ts +8 -0
  306. package/entry/dev/config.ts +1 -1
  307. package/entry/dev/index.ts +1 -0
  308. package/entry/dev/jsx_dev_runtime.ts +1 -0
  309. package/entry/dev/jsx_runtime.ts +1 -0
  310. package/entry/dev/sheet.ts +4 -0
  311. package/entry/prod/adapter/preact.ts +8 -0
  312. package/entry/prod/adapter/react.ts +8 -0
  313. package/entry/prod/adapter/solid.ts +8 -0
  314. package/entry/prod/config_debug.ts +2 -0
  315. package/entry/prod/index.ts +1 -1
  316. package/entry/prod/runtime.ts +4 -2
  317. package/entry/rsc_dev/adapter/preact.ts +9 -0
  318. package/entry/rsc_dev/adapter/react.ts +9 -0
  319. package/entry/rsc_dev/adapter/solid.ts +9 -0
  320. package/entry/rsc_dev/config.ts +1 -1
  321. package/entry/rsc_dev/server.ts +1 -1
  322. package/entry/rsc_prod/adapter/preact.ts +1 -0
  323. package/entry/rsc_prod/adapter/react.ts +1 -0
  324. package/entry/rsc_prod/adapter/solid.ts +1 -0
  325. package/entry/rsc_prod/config_debug.ts +6 -0
  326. package/entry/rsc_prod/index.ts +1 -1
  327. package/entry/rsc_prod/runtime.ts +1 -1
  328. package/entry/rsc_prod/server.ts +1 -1
  329. package/entry/shared/config_debug.ts +9 -0
  330. package/entry/shared/config_dev.ts +14 -0
  331. package/entry/shared/dev.ts +11 -2
  332. package/entry/shared/utils.ts +28 -0
  333. package/jsx/types/index.ts +1 -0
  334. package/jsx/types/preact.ts +14 -0
  335. package/jsx/{types.ts → types/react.ts} +2 -2
  336. package/jsx/types/solid.ts +32 -0
  337. package/package.json +110 -8
  338. package/plugin/bundler/farm/plugin.ts +2 -0
  339. package/plugin/bundler/parcel/optimizer.ts +1 -0
  340. package/plugin/bundler/parcel/plugin.ts +2 -0
  341. package/plugin/bundler/rspack/plugin.ts +1 -0
  342. package/plugin/bundler/vite/plugin.ts +5 -9
  343. package/plugin/bundler/vite/state.ts +11 -6
  344. package/plugin/bundler/webpack/plugin.ts +2 -1
  345. package/plugin/bundler/webpack/shared/loader.ts +9 -7
  346. package/plugin/nextjs/plugin.ts +249 -35
  347. package/plugin/nextjs/types.ts +1 -2
  348. package/plugin/nextjs/utils.ts +121 -0
  349. package/plugin/utils/compiler.ts +2 -0
  350. package/plugin/utils/runtimeEntry.ts +15 -2
  351. package/presets/tailwind/classname/index.ts +2 -0
  352. package/presets/tailwind/classname/transform.ts +239 -0
  353. package/presets/tailwind/classname/types.ts +124 -0
  354. package/presets/tailwind/index.ts +5 -0
  355. package/presets/tailwind/selectors.ts +27 -0
  356. package/presets/tailwind/style/index.ts +2 -0
  357. package/presets/tailwind/style/transform.ts +436 -0
  358. package/presets/tailwind/style/types.ts +346 -0
  359. package/presets/tailwind/theme.ts +479 -0
  360. package/presets/tailwind/types.ts +147 -0
  361. package/runtime/adapter/utils.ts +120 -0
  362. package/runtime/core/cache/combine.ts +76 -28
  363. package/runtime/core/cache/combineRuntime.ts +4 -0
  364. package/runtime/core/cache/index.ts +2 -1
  365. package/runtime/core/cache/item.ts +32 -13
  366. package/runtime/core/cache/itemWithResolver.ts +44 -0
  367. package/runtime/core/cache/pool.ts +16 -31
  368. package/runtime/core/cache/prop.ts +10 -8
  369. package/runtime/core/cache/result.ts +2 -2
  370. package/runtime/core/cache/stateItem.ts +16 -1
  371. package/runtime/core/cache/token.ts +20 -0
  372. package/runtime/core/cache/tokenValues.ts +19 -11
  373. package/runtime/core/combinedStyle.ts +4 -4
  374. package/runtime/extract/combineStyle.ts +211 -0
  375. package/runtime/extract/getClassName.ts +55 -23
  376. package/runtime/extract/index.ts +4 -2
  377. package/runtime/extract/token.ts +41 -0
  378. package/runtime/extract/tokenResolver.ts +17 -0
  379. package/runtime/index.ts +8 -1
  380. package/runtime/rsc/getClassName.ts +4 -0
  381. package/runtime/rsc/observer.ts +4 -0
  382. package/runtime/rsc/styleStore.ts +18 -7
  383. package/runtime/sheet/rule.ts +16 -12
  384. package/runtime/sheet/rules.ts +8 -3
  385. package/runtime/style/scope.ts +0 -24
  386. package/runtime/style/style.ts +181 -6
  387. package/runtime/types.ts +6 -4
  388. package/sheet/dev/dev_layer.ts +18 -7
  389. package/sheet/dev/dev_sort.ts +45 -11
  390. package/sheet/prod.ts +18 -7
  391. package/sheet/types.ts +2 -0
  392. package/sheet/utils/layer.ts +33 -0
  393. package/style/classname.ts +47 -0
  394. package/style/important.ts +19 -0
  395. package/style/index.ts +3 -0
  396. package/style/style.ts +47 -16
  397. package/style/theme.ts +4 -3
  398. package/style/token.ts +26 -21
  399. package/style/tokens.ts +18 -12
  400. package/style/transform.ts +41 -2
  401. package/style/types.ts +6 -4
  402. package/style/utils/expose.ts +4 -3
  403. package/style/value.ts +26 -11
  404. package/style/valueRef.ts +1 -1
  405. package/style/weight.ts +21 -0
  406. package/utils/global.ts +1 -3
  407. package/utils/hash.ts +4 -0
  408. package/utils/symbol.ts +3 -0
  409. package/atomic/layer/README.md +0 -116
  410. package/atomic/utils/css.ts +0 -49
  411. package/dist/assert-BGdigdr5.js.map +0 -1
  412. package/dist/className-C1Ht5Wvv.js +0 -144
  413. package/dist/className-C1Ht5Wvv.js.map +0 -1
  414. package/dist/className-DC2Cq8p3.js +0 -251
  415. package/dist/className-DC2Cq8p3.js.map +0 -1
  416. package/dist/compiler-DENc3a2R.mjs.map +0 -1
  417. package/dist/config-BryWDfQX.js +0 -25
  418. package/dist/config-BryWDfQX.js.map +0 -1
  419. package/dist/config-DKHXWhe1.js +0 -1
  420. package/dist/config-Di2VYYKV.js +0 -6
  421. package/dist/config-DloHOG6I.js +0 -13
  422. package/dist/config-DloHOG6I.js.map +0 -1
  423. package/dist/css-BowBszUt.js +0 -243
  424. package/dist/css-BowBszUt.js.map +0 -1
  425. package/dist/css-ByOrugEX.js +0 -805
  426. package/dist/css-ByOrugEX.js.map +0 -1
  427. package/dist/css-DcazYor9.js +0 -235
  428. package/dist/css-DcazYor9.js.map +0 -1
  429. package/dist/css_extra-DlOnsnR1.js +0 -8
  430. package/dist/css_extra-oIi3UEPK.js.map +0 -1
  431. package/dist/data-BsqOa5br.js +0 -473
  432. package/dist/data-BsqOa5br.js.map +0 -1
  433. package/dist/debug-BAw63qX6.js +0 -15
  434. package/dist/debug-BAw63qX6.js.map +0 -1
  435. package/dist/debug-DGki_v7g.js +0 -15
  436. package/dist/debug-DGki_v7g.js.map +0 -1
  437. package/dist/debug-n2aZQBSa.js.map +0 -1
  438. package/dist/dev-CcphAa3R.js.map +0 -1
  439. package/dist/dev-DfBbuLeE.js +0 -71
  440. package/dist/dev-DfBbuLeE.js.map +0 -1
  441. package/dist/elementMarker-Bu7gDAkE.js.map +0 -1
  442. package/dist/extract-CzWJeQi8.js +0 -121
  443. package/dist/extract-CzWJeQi8.js.map +0 -1
  444. package/dist/extract-DEwSDJ9Z.js +0 -2
  445. package/dist/format-3nKBE_5t.js.map +0 -1
  446. package/dist/getClassName-BlvXHYuf.js.map +0 -1
  447. package/dist/global-CvfmFLsK.js +0 -11
  448. package/dist/global-CvfmFLsK.js.map +0 -1
  449. package/dist/jsx-CwTeyUxr.js +0 -39
  450. package/dist/jsx-CwTeyUxr.js.map +0 -1
  451. package/dist/jsx-D2BksHSv.js +0 -38
  452. package/dist/jsx-D2BksHSv.js.map +0 -1
  453. package/dist/layer-D1SaH07m.js +0 -94
  454. package/dist/layer-D1SaH07m.js.map +0 -1
  455. package/dist/loader-B5Kw0DD-.mjs.map +0 -1
  456. package/dist/misc-DCdYYyhK.mjs.map +0 -1
  457. package/dist/presets-BhXa232U.js +0 -108
  458. package/dist/presets-BhXa232U.js.map +0 -1
  459. package/dist/property-CnLFt5kx.js +0 -406
  460. package/dist/property-CnLFt5kx.js.map +0 -1
  461. package/dist/rules-9HSO1pxL.js.map +0 -1
  462. package/dist/runtime-CYqNCiaM.js.map +0 -1
  463. package/dist/shared-CBArHB9-.cjs.map +0 -1
  464. package/dist/style-B-6jHipw.js +0 -5
  465. package/dist/style-B1UUqjj5.js +0 -743
  466. package/dist/style-B1UUqjj5.js.map +0 -1
  467. package/dist/style-DgHbdbdF.js +0 -752
  468. package/dist/style-DgHbdbdF.js.map +0 -1
  469. package/dist/style-v2bf70TZ.js +0 -1269
  470. package/dist/style-v2bf70TZ.js.map +0 -1
  471. package/dist/styleStore-Dea_WVbr.js.map +0 -1
  472. package/dist/styleStore-DyNXBcUK.js.map +0 -1
  473. package/dist/token-CKXUECuU.js +0 -76
  474. package/dist/token-CKXUECuU.js.map +0 -1
  475. package/dist/token-u_tM-mtg.js +0 -204
  476. package/dist/token-u_tM-mtg.js.map +0 -1
  477. package/dist/utils-BbehLOby.js.map +0 -1
  478. package/dist/utils-CEaq_c-A.mjs +0 -97
  479. package/dist/utils-CEaq_c-A.mjs.map +0 -1
  480. package/dist/utils-CWNHx4EC.js +0 -170
  481. package/dist/utils-CWNHx4EC.js.map +0 -1
  482. package/dist/utils-D7FAOyg6.js.map +0 -1
  483. package/dist/value-BR4e2MKt.js +0 -910
  484. package/dist/value-BR4e2MKt.js.map +0 -1
  485. package/dist/value-E8rEv2Oe.js +0 -136
  486. package/dist/value-E8rEv2Oe.js.map +0 -1
  487. package/dist/valueRef-lshFk1Cs.js +0 -16
  488. package/dist/valueRef-lshFk1Cs.js.map +0 -1
  489. package/dist/webpack-Dh6lox2l.mjs.map +0 -1
  490. package/dist/withTokens-LRidu3Vc.js +0 -95
  491. package/dist/withTokens-LRidu3Vc.js.map +0 -1
@@ -1,14 +1,16 @@
1
1
  import type { NextConfig } from 'next';
2
2
  import { PHASE_DEVELOPMENT_SERVER } from 'next/constants';
3
+ import { createHash } from 'node:crypto';
3
4
  import fs from 'node:fs';
4
5
  import path from 'node:path';
5
- import type { Compiler, RuleSetRule } from 'webpack';
6
+ import type { Compilation, Compiler, RuleSetRule } from 'webpack';
6
7
  import type { BuildConfig, BuildDevConfig } from '../../config/build';
7
8
  import { isPromiseLike } from '../../utils/object';
8
9
  import {
9
10
  BUNDLE_CSS_FILE,
10
11
  createCompilerId,
11
12
  createFileCssCache,
13
+ createFileCssContentHash,
12
14
  createPluginCompiler,
13
15
  DEFAULT_TRANSFORM_EXCLUDE,
14
16
  DEFAULT_TRANSFORM_INCLUDE,
@@ -42,6 +44,7 @@ import {
42
44
  createNextBuildConfig,
43
45
  createNextBuildDevConfig,
44
46
  createNextConfigHash,
47
+ createSerializableImportSources,
45
48
  getNextCacheDir,
46
49
  getNextPrecollectCacheSubdir,
47
50
  getTransformLoaderPath,
@@ -49,15 +52,16 @@ import {
49
52
  type NextLoaderState,
50
53
  nextRegistry,
51
54
  removeUndefinedValues,
52
- replaceCssMarkerAsset,
53
55
  resolveNextCompilerOptions,
56
+ replaceCssMarkerAsset,
54
57
  } from './utils';
55
58
 
59
+ export { CssPropPresets } from '../utils';
60
+ export type { CompilerCssPropOptions } from '../utils';
61
+
56
62
  export default plugin;
57
63
 
58
64
  const TURBOPACK_TRANSFORM_EXTENSIONS: readonly string[] = ['*.ts', '*.tsx', '*.js', '*.jsx'];
59
- const clearedPrecollectCacheRoots = new Set<string>();
60
-
61
65
  type NextPhaseState = {
62
66
  buildConfig: BuildConfig;
63
67
  buildDevConfig: BuildDevConfig | null;
@@ -107,17 +111,20 @@ function createNextConfig(
107
111
  phaseState.configHash = createNextConfigHash(
108
112
  phaseState.buildConfig,
109
113
  phaseState.dev,
114
+ options.importSources,
110
115
  );
111
116
 
112
117
  let sidecar: SourcemapSidecar | null = null;
113
118
 
114
119
  if (dev) {
115
- const route: SidecarRouteHandler = () => ({
120
+ const getDevCss = () => cssCache.getCss({
121
+ ...phaseState.buildConfig.css,
122
+ configHash: phaseState.configHash,
123
+ });
124
+
125
+ const route: SidecarRouteHandler = async () => ({
116
126
  contentType: 'text/css; charset=utf-8',
117
- body: cssCache.getCss({
118
- ...phaseState.buildConfig.css,
119
- configHash: phaseState.configHash,
120
- }),
127
+ body: await waitForDevCss(getDevCss),
121
128
  });
122
129
 
123
130
  sidecar = getSourcemapSidecar({
@@ -143,6 +150,22 @@ function createNextConfig(
143
150
  : finish();
144
151
  }
145
152
 
153
+ async function waitForDevCss(getCss: () => string) {
154
+ let css = getCss();
155
+ if (css) return css;
156
+
157
+ const deadline = Date.now() + 5000;
158
+
159
+ while (Date.now() < deadline) {
160
+ await new Promise((resolve) => setTimeout(resolve, 25));
161
+
162
+ css = getCss();
163
+ if (css) return css;
164
+ }
165
+
166
+ return css;
167
+ }
168
+
146
169
  function createFluenticNextConfigResolved(
147
170
  nextConfig: NextConfig,
148
171
  options: PluginOptions,
@@ -159,7 +182,7 @@ function createFluenticNextConfigResolved(
159
182
  const projectDir = process.cwd();
160
183
 
161
184
  const devCssHref = dev && sidecar
162
- ? sidecar.getRouteUrl(DEV_CSS_ROUTE)
185
+ ? DEV_CSS_ROUTE
163
186
  : null;
164
187
 
165
188
  const turbopackCompilerId = createCompilerId(NEXT_COMPILER_IDS.turbopack);
@@ -201,6 +224,7 @@ function createFluenticNextConfigResolved(
201
224
  return {
202
225
  ...nextConfig,
203
226
  env: nextConfig.env,
227
+ rewrites: createNextRewrites(nextConfig.rewrites, dev && sidecar ? sidecar : null),
204
228
  compiler: {
205
229
  ...originalCompiler,
206
230
  define: {
@@ -243,6 +267,7 @@ function createFluenticNextConfigResolved(
243
267
  cssAliases: turbopackCssAliases,
244
268
  dev,
245
269
  devCssHref,
270
+ options,
246
271
  projectDir,
247
272
  }),
248
273
  webpack(config: WebpackConfiguration, context: WebpackConfigContext) {
@@ -299,6 +324,7 @@ function createFluenticNextConfigResolved(
299
324
  cssOutput: options.cssOutput,
300
325
  cssCache,
301
326
  dev: context.dev,
327
+ filter: state.filter,
302
328
  sidecar,
303
329
  });
304
330
 
@@ -307,6 +333,45 @@ function createFluenticNextConfigResolved(
307
333
  };
308
334
  }
309
335
 
336
+ function createNextRewrites(
337
+ originalRewrites: NextConfig['rewrites'],
338
+ sidecar: SourcemapSidecar | null,
339
+ ): NextConfig['rewrites'] {
340
+ if (!sidecar) return originalRewrites;
341
+
342
+ return async () => {
343
+ await sidecar.ensureStarted();
344
+
345
+ const devCssRewrite = {
346
+ source: DEV_CSS_ROUTE,
347
+ destination: sidecar.getRouteUrl(DEV_CSS_ROUTE),
348
+ };
349
+
350
+ const original = await originalRewrites?.();
351
+
352
+ if (!original) {
353
+ return {
354
+ beforeFiles: [devCssRewrite],
355
+ afterFiles: [],
356
+ fallback: [],
357
+ };
358
+ }
359
+
360
+ if (Array.isArray(original)) {
361
+ return {
362
+ beforeFiles: [devCssRewrite],
363
+ afterFiles: original,
364
+ fallback: [],
365
+ };
366
+ }
367
+
368
+ return {
369
+ ...original,
370
+ beforeFiles: [devCssRewrite, ...(original.beforeFiles ?? [])],
371
+ };
372
+ };
373
+ }
374
+
310
375
  function getImportableCssCacheDir(projectDir: string) {
311
376
  return path.join(projectDir, PLUGIN_CACHE_DIR);
312
377
  }
@@ -322,6 +387,7 @@ function createTurbopackConfig(
322
387
  cssAliases: Record<string, string>;
323
388
  dev: boolean;
324
389
  devCssHref: string | null;
390
+ options: PluginOptions;
325
391
  projectDir: string;
326
392
  },
327
393
  ): TurbopackConfig {
@@ -351,12 +417,16 @@ function mergeTurbopackRules(
351
417
  cssAliases: Record<string, string>;
352
418
  dev: boolean;
353
419
  devCssHref: string | null;
420
+ options: PluginOptions;
354
421
  projectDir: string;
355
422
  },
356
423
  ): TurbopackRules {
424
+ const compilerOptions = createSerializableTurbopackCompilerOptions(args.options);
425
+
357
426
  const loaderItem: TurbopackLoaderItem = {
358
427
  loader: LOADER_IMPORT_PATH,
359
428
  options: removeUndefinedValues({
429
+ ...compilerOptions,
360
430
  buildConfig: args.buildConfig,
361
431
  buildDevConfig: args.buildDevConfig,
362
432
  cacheDir: args.cacheDir,
@@ -379,6 +449,55 @@ function mergeTurbopackRules(
379
449
  return nextRules as TurbopackRules;
380
450
  }
381
451
 
452
+ function createSerializableTurbopackCompilerOptions(
453
+ options: PluginOptions,
454
+ ): Partial<PluginOptions> {
455
+ return removeUndefinedValues({
456
+ css: options.css,
457
+ cssProp: options.cssProp,
458
+ dev: options.dev,
459
+ hoist: options.hoist,
460
+ importSources: createSerializableTurbopackImportSources(options.importSources),
461
+ });
462
+ }
463
+
464
+ function createSerializableTurbopackImportSources(
465
+ importSources: PluginOptions['importSources'],
466
+ ): PluginOptions['importSources'] | undefined {
467
+ const serialized = createSerializableImportSources(importSources);
468
+ if (!serialized) return undefined;
469
+
470
+ const result = serialized.filter((entry) => isSerializableLoaderValue(entry));
471
+ return result.length ? result : undefined;
472
+ }
473
+
474
+ function isSerializableLoaderValue(value: unknown): boolean {
475
+ if (value === null) return true;
476
+
477
+ const valueType = typeof value;
478
+
479
+ if (
480
+ valueType === 'string' ||
481
+ valueType === 'number' ||
482
+ valueType === 'boolean'
483
+ ) {
484
+ return true;
485
+ }
486
+
487
+ if (valueType !== 'object') return false;
488
+
489
+ if (Array.isArray(value)) {
490
+ return value.every((item) => isSerializableLoaderValue(item));
491
+ }
492
+
493
+ const prototype = Object.getPrototypeOf(value);
494
+ if (prototype !== Object.prototype && prototype !== null) return false;
495
+
496
+ return Object.values(value as Record<string, unknown>).every((item) =>
497
+ isSerializableLoaderValue(item),
498
+ );
499
+ }
500
+
382
501
  function prependTurbopackLoader(rule: unknown, loader: TurbopackLoaderItem) {
383
502
  if (!rule || typeof rule !== 'object' || Array.isArray(rule)) {
384
503
  return { loaders: [loader] };
@@ -428,41 +547,61 @@ function patchTurbopackExtractedCss(args: {
428
547
  distDir: string;
429
548
  projectDir: string;
430
549
  }) {
431
- if (!args.css) return;
432
-
433
- const distDir = path.isAbsolute(args.distDir)
434
- ? args.distDir
435
- : path.join(args.projectDir, args.distDir);
550
+ const distDir = path.resolve(args.projectDir, args.distDir);
551
+ const renamed = new Map<string, string>();
436
552
 
437
- for (const filePath of findCssFiles(distDir)) {
553
+ for (const filePath of findBuildFiles(path.join(distDir, 'static'), /\.css$/)) {
438
554
  const source = fs.readFileSync(filePath, 'utf8');
439
555
  if (!source.includes(EXTRACTED_CSS_MARKER)) continue;
440
556
 
441
- fs.writeFileSync(filePath, source.split(EXTRACTED_CSS_MARKER).join(args.css), 'utf8');
557
+ const css = source.split(EXTRACTED_CSS_MARKER).join(args.css);
558
+ const hash = createHash('sha256').update(css).digest('hex').slice(0, 32);
559
+ const asset = path.relative(distDir, filePath).split(path.sep).join('/');
560
+ const hashedAsset = path.posix.join(path.posix.dirname(asset), hash + '.css');
561
+ fs.writeFileSync(path.join(distDir, hashedAsset), css, 'utf8');
562
+ renamed.set(asset, hashedAsset);
442
563
  }
443
- }
444
564
 
445
- function findCssFiles(dir: string): string[] {
446
- let entries: fs.Dirent[];
565
+ if (!renamed.size) return;
566
+
567
+ // Update Next's manifests before it renders HTML and RSC payloads. The App
568
+ // Router can also embed the stylesheet directly in its client reference manifest.
569
+ const manifestName = /manifest.*\.(js|json)$/i;
570
+ const manifests = [
571
+ ...fs.readdirSync(distDir).filter((name) => manifestName.test(name)).map((name) => path.join(distDir, name)),
572
+ ...findBuildFiles(path.join(distDir, 'server'), manifestName),
573
+ ...findBuildFiles(path.join(distDir, 'static'), /^_buildManifest\.js$/),
574
+ ];
575
+ const inlineCss = JSON.stringify(args.css).slice(1, -1);
576
+ for (const filePath of manifests) {
577
+ const source = fs.readFileSync(filePath, 'utf8');
578
+ let updated = source;
579
+
580
+ for (const [asset, hashedAsset] of renamed) {
581
+ updated = updated.split(asset).join(hashedAsset);
582
+ }
583
+ if (updated !== source) {
584
+ fs.writeFileSync(filePath, updated.split(EXTRACTED_CSS_MARKER).join(inlineCss), 'utf8');
585
+ }
586
+ }
447
587
 
448
- try {
449
- entries = fs.readdirSync(dir, { withFileTypes: true });
450
- } catch {
451
- return [];
588
+ for (const asset of renamed.keys()) {
589
+ fs.unlinkSync(path.join(distDir, asset));
452
590
  }
591
+ }
453
592
 
454
- const files: string[] = [];
593
+ function findBuildFiles(dir: string, pattern: RegExp): string[] {
594
+ if (!fs.existsSync(dir)) return [];
455
595
 
456
- for (const entry of entries) {
596
+ const files: string[] = [];
597
+ for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
457
598
  const filePath = path.join(dir, entry.name);
458
-
459
599
  if (entry.isDirectory()) {
460
- files.push(...findCssFiles(filePath));
461
- } else if (entry.isFile() && entry.name.endsWith('.css')) {
600
+ files.push(...findBuildFiles(filePath, pattern));
601
+ } else if (entry.isFile() && pattern.test(entry.name)) {
462
602
  files.push(filePath);
463
603
  }
464
604
  }
465
-
466
605
  return files;
467
606
  }
468
607
 
@@ -475,6 +614,7 @@ function addLifecyclePlugin(
475
614
  cssOutput: PluginCssOutputOptions | undefined;
476
615
  cssCache: ReturnType<typeof createFileCssCache>;
477
616
  dev: boolean;
617
+ filter: NextLoaderState['filter'];
478
618
  sidecar: SourcemapSidecar | null;
479
619
  },
480
620
  ) {
@@ -482,11 +622,6 @@ function addLifecyclePlugin(
482
622
  apply(webpackCompiler: Compiler) {
483
623
  webpackCompiler.hooks.beforeRun.tapPromise(PLUGIN_NAME, async () => {
484
624
  await args.sidecar?.ensureStarted();
485
-
486
- if (!args.dev && !clearedPrecollectCacheRoots.has(args.cssCache.rootDir)) {
487
- clearedPrecollectCacheRoots.add(args.cssCache.rootDir);
488
- args.cssCache.clear();
489
- }
490
625
  });
491
626
 
492
627
  webpackCompiler.hooks.watchRun.tapPromise(PLUGIN_NAME, async (watchCompiler) => {
@@ -507,6 +642,8 @@ function addLifecyclePlugin(
507
642
  stage: webpackCompiler.webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS,
508
643
  },
509
644
  async () => {
645
+ precollectProductionCssFromCompilation(args, compilation, webpackCompiler);
646
+
510
647
  const css = await transformCssOutput(
511
648
  args.cssCache.getCss({
512
649
  ...args.buildConfig.css,
@@ -530,3 +667,80 @@ function addLifecyclePlugin(
530
667
  },
531
668
  });
532
669
  }
670
+
671
+ function precollectProductionCssFromCompilation(
672
+ args: {
673
+ configHash: string;
674
+ compiler: NextLoaderState['compiler'];
675
+ cssCache: ReturnType<typeof createFileCssCache>;
676
+ dev: boolean;
677
+ filter: NextLoaderState['filter'];
678
+ },
679
+ compilation: Compilation,
680
+ webpackCompiler: Compiler,
681
+ ) {
682
+ if (args.dev) return;
683
+
684
+ const existingCss = args.cssCache.getCss({
685
+ configHash: args.configHash,
686
+ });
687
+
688
+ if (existingCss) return;
689
+
690
+ const files = getCompilationSourceFiles(compilation, webpackCompiler.context, args.filter);
691
+
692
+ for (const filePath of files) {
693
+ let code: string;
694
+
695
+ try {
696
+ code = fs.readFileSync(filePath, 'utf8');
697
+ } catch {
698
+ continue;
699
+ }
700
+
701
+ const result = args.compiler.compileExtract({
702
+ code,
703
+ filePath,
704
+ sourcemap: null,
705
+ });
706
+
707
+ if (!result) continue;
708
+
709
+ args.cssCache.setFileCss({
710
+ filePath,
711
+ contentHash: createFileCssContentHash(code),
712
+ configHash: args.configHash,
713
+ rules: result.rules,
714
+ });
715
+ }
716
+ }
717
+
718
+ function getCompilationSourceFiles(
719
+ compilation: Compilation,
720
+ projectDir: string,
721
+ filter: NextLoaderState['filter'],
722
+ ) {
723
+ const files = new Set<string>();
724
+ const dependencies = compilation.fileDependencies ?? new Set<string>();
725
+
726
+ for (const filePath of dependencies) {
727
+ if (!isProjectSourceFile(filePath, projectDir, filter)) continue;
728
+ files.add(path.normalize(filePath));
729
+ }
730
+
731
+ return [...files].sort();
732
+ }
733
+
734
+ function isProjectSourceFile(
735
+ filePath: string,
736
+ projectDir: string,
737
+ filter: NextLoaderState['filter'],
738
+ ) {
739
+ if (!path.isAbsolute(filePath)) return false;
740
+ if (!filePath.startsWith(projectDir + path.sep)) return false;
741
+ if (filePath.includes(`${path.sep}.next${path.sep}`)) return false;
742
+ if (filePath.includes(`${path.sep}.git${path.sep}`)) return false;
743
+ if (!filter(filePath)) return false;
744
+
745
+ return true;
746
+ }
@@ -1,5 +1,4 @@
1
1
  import type { NextConfig } from 'next';
2
- import type { PHASE_TYPE } from 'next/constants';
3
2
  import type { OmitProps } from '../../utils/type';
4
3
  import type { PluginOptions as BasePluginOptions } from '../utils';
5
4
 
@@ -12,7 +11,7 @@ export type NextConfigContext = {
12
11
  };
13
12
 
14
13
  export type NextConfigFunction = (
15
- phase: PHASE_TYPE,
14
+ phase: string,
16
15
  context: NextConfigContext,
17
16
  ) => MaybePromise<NextConfig>;
18
17
 
@@ -1,10 +1,14 @@
1
1
  import { createHash } from 'node:crypto';
2
+ import fs from 'node:fs';
2
3
  import { createRequire } from 'node:module';
3
4
  import path from 'node:path';
5
+ import { fileURLToPath } from 'node:url';
4
6
  import type { Compilation, Compiler, WebpackPluginInstance } from 'webpack';
5
7
  import type { Compiler as PluginCompiler } from '../../compiler';
8
+ import type { ImportSource } from '../../compiler/utils/import_source';
6
9
  import { normalizePath } from '../../compiler/utils/path';
7
10
  import type { BuildConfig, BuildDevConfig } from '../../config/build';
11
+ import { getStyleFnMeta } from '../../style/style';
8
12
  import { createWebpackRegistry } from '../bundler/webpack/shared/registry';
9
13
  import type { FileCssCache } from '../utils/cache';
10
14
  import type { PluginOptions as BasePluginOptions } from '../utils/compiler';
@@ -69,15 +73,132 @@ export function createNextBuildDevConfig(options: PluginOptions): BuildDevConfig
69
73
  export function createNextConfigHash(
70
74
  buildConfig: BuildConfig,
71
75
  dev: boolean,
76
+ importSources?: readonly ImportSource[] | null,
72
77
  ) {
73
78
  const values = [
79
+ createPackageCacheIdentity(),
74
80
  dev ? 'dev' : 'prod',
75
81
  buildConfig.hoist ? 'hoist' : 'no-hoist',
82
+ JSON.stringify(createSerializableImportSources(importSources)),
76
83
  ];
77
84
 
78
85
  return createHash('sha256').update(values.join('\0')).digest('hex');
79
86
  }
80
87
 
88
+ function createPackageCacheIdentity() {
89
+ const require = createRequire(import.meta.url);
90
+ let entryPath = '';
91
+
92
+ try {
93
+ entryPath = require.resolve('@fluentic/style/plugin/nextjs');
94
+ } catch {
95
+ entryPath = fileURLToPath(import.meta.url);
96
+ }
97
+
98
+ const packageInfo = findPackageInfo(entryPath);
99
+ const parts = [
100
+ packageInfo.version,
101
+ normalizePath(packageInfo.packageRoot),
102
+ normalizePath(entryPath),
103
+ getStatIdentity(packageInfo.packageJsonPath),
104
+ getStatIdentity(entryPath),
105
+ ];
106
+
107
+ return parts.join('\0');
108
+ }
109
+
110
+ function findPackageInfo(entryPath: string) {
111
+ let current = path.dirname(entryPath);
112
+
113
+ while (true) {
114
+ const packageJsonPath = path.join(current, 'package.json');
115
+
116
+ try {
117
+ const pkg = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8')) as {
118
+ name?: string;
119
+ version?: string;
120
+ };
121
+
122
+ if (pkg.name === '@fluentic/style') {
123
+ return {
124
+ packageRoot: current,
125
+ packageJsonPath,
126
+ version: pkg.version ?? '',
127
+ };
128
+ }
129
+ } catch {
130
+ // Keep walking toward the filesystem root.
131
+ }
132
+
133
+ const parent = path.dirname(current);
134
+ if (parent === current) break;
135
+ current = parent;
136
+ }
137
+
138
+ return {
139
+ packageRoot: path.dirname(entryPath),
140
+ packageJsonPath: '',
141
+ version: '',
142
+ };
143
+ }
144
+
145
+ function getStatIdentity(filePath: string) {
146
+ if (!filePath) return '';
147
+
148
+ try {
149
+ const stat = fs.statSync(filePath);
150
+ return `${stat.size}:${stat.mtimeMs}`;
151
+ } catch {
152
+ return '';
153
+ }
154
+ }
155
+
156
+ export function createSerializableImportSources(
157
+ importSources: readonly ImportSource[] | null | undefined,
158
+ ): ImportSource[] | undefined {
159
+ if (!importSources?.length) return undefined;
160
+
161
+ const result: ImportSource[] = [];
162
+
163
+ for (const entry of importSources) {
164
+ if (entry.check) continue;
165
+
166
+ const source = serializeImportSourcePattern(entry.source);
167
+ const name = entry.name;
168
+ const meta = entry.meta ?? (entry.styleFn ? getStyleFnMeta(entry.styleFn) : null);
169
+
170
+ if (!meta) continue;
171
+ if (entry.source !== undefined && source === undefined) continue;
172
+
173
+ result.push(removeUndefinedValues({
174
+ source,
175
+ name,
176
+ meta,
177
+ }));
178
+ }
179
+
180
+ return result.length ? result : undefined;
181
+ }
182
+
183
+ function serializeImportSourcePattern(
184
+ source: ImportSource['source'],
185
+ ): string | string[] | undefined {
186
+ if (source === undefined) return undefined;
187
+
188
+ if (Array.isArray(source)) {
189
+ const result: string[] = [];
190
+
191
+ for (const item of source) {
192
+ if (typeof item !== 'string') return undefined;
193
+ result.push(item);
194
+ }
195
+
196
+ return result;
197
+ }
198
+
199
+ return typeof source === 'string' ? source : undefined;
200
+ }
201
+
81
202
  export function resolveNextCompilerOptions(
82
203
  options: PluginOptions,
83
204
  sidecar: SourcemapSidecar | null,
@@ -7,6 +7,8 @@ import { createTransformFilter, normalizeModuleId, type TransformFilterOptions }
7
7
  import type { BundlerSourceMap } from './sourcemap';
8
8
 
9
9
  export type PluginCssOptions = CompilerCssOptions;
10
+ export { CssPropPresets } from '../../compiler';
11
+ export type { CompilerCssPropOptions } from '../../compiler';
10
12
 
11
13
  export type PluginOptions = CompilerOptions & TransformFilterOptions & {
12
14
  cacheDir?: string;
@@ -10,12 +10,13 @@ export function getStyleRuntimeMode(dev: boolean, rsc = false): CompilerRuntimeM
10
10
  return dev ? CompilerRuntimeMode.Dev : CompilerRuntimeMode.Prod;
11
11
  }
12
12
 
13
- export function getPluginBuildConfig(options: PluginOptions): BuildConfig {
13
+ export function getPluginBuildConfig(options: PluginOptions, dev = false): BuildConfig {
14
14
  const css: CompilerCssOptions = hasBuildConfig(options.css) ? options.css! : {};
15
15
 
16
16
  return {
17
- hoist: options.hoist !== false,
17
+ hoist: !dev && options.hoist !== false,
18
18
  css,
19
+ check: options.check,
19
20
  };
20
21
  }
21
22
 
@@ -55,3 +56,15 @@ export function getStyleEntryDefines(
55
56
 
56
57
  return defines;
57
58
  }
59
+
60
+ export function createStyleEntryGlobalSource(
61
+ buildConfig: BuildConfig,
62
+ buildDevConfig: BuildDevConfig | null,
63
+ sidecarUrl: string | null,
64
+ ) {
65
+ const defines = getStyleEntryDefines(buildConfig, buildDevConfig, sidecarUrl, false);
66
+
67
+ return Object.entries(defines)
68
+ .map(([key, value]) => `globalThis[${JSON.stringify(key)}] = ${JSON.stringify(value)};`)
69
+ .join('\n');
70
+ }
@@ -0,0 +1,2 @@
1
+ export * from './transform';
2
+ export type * from './types';