@fluentic/style 0.1.0-beta.0 → 0.1.0-beta.10

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 (494) hide show
  1. package/CHANGELOG.md +154 -0
  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 +173 -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-DweanHoB.mjs → compiler-C3CEGGtI.mjs} +2349 -647
  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 +634 -713
  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-DS61nRqr.mjs → loader-_-VjzlrX.mjs} +13 -14
  220. package/dist/loader-_-VjzlrX.mjs.map +1 -0
  221. package/dist/{misc-B9kqEb2N.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 +121 -17
  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/presets-DSanixJV.js +243 -0
  251. package/dist/presets-DSanixJV.js.map +1 -0
  252. package/dist/{registry-CyIj8LYK.mjs → registry-w8ET5R7v.mjs} +2 -2
  253. package/dist/{registry-CyIj8LYK.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 +2 -3
  261. package/dist/server.js +17 -11
  262. package/dist/server.js.map +1 -1
  263. package/dist/{shared-CCpq1zqA.mjs → shared-C_cYxNzz.mjs} +4 -4
  264. package/dist/{shared-CCpq1zqA.mjs.map → shared-C_cYxNzz.mjs.map} +1 -1
  265. package/dist/{shared-BAL9peIw.cjs → shared-PK52rW6T.cjs} +2352 -644
  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-4u6GnlQG.mjs → sidecar-BhvmXYsD.mjs} +3 -3
  270. package/dist/{sidecar-4u6GnlQG.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-DMFgOOtA.mjs → utils-DND33M6y.mjs} +3 -3
  286. package/dist/{utils-DMFgOOtA.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-CxS2FDYU.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 +118 -18
  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 +12 -7
  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 +208 -15
  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/selector/assert.ts +24 -25
  389. package/selector/selector.ts +6 -0
  390. package/sheet/dev/dev_layer.ts +18 -7
  391. package/sheet/dev/dev_sort.ts +45 -11
  392. package/sheet/prod.ts +18 -7
  393. package/sheet/types.ts +2 -0
  394. package/sheet/utils/layer.ts +33 -0
  395. package/style/classname.ts +47 -0
  396. package/style/important.ts +19 -0
  397. package/style/index.ts +3 -0
  398. package/style/style.ts +47 -16
  399. package/style/theme.ts +4 -3
  400. package/style/token.ts +26 -21
  401. package/style/tokens.ts +18 -12
  402. package/style/transform.ts +41 -2
  403. package/style/types.ts +6 -4
  404. package/style/utils/expose.ts +4 -3
  405. package/style/value.ts +26 -11
  406. package/style/valueRef.ts +1 -1
  407. package/style/weight.ts +21 -0
  408. package/utils/global.ts +1 -3
  409. package/utils/hash.ts +4 -0
  410. package/utils/symbol.ts +3 -0
  411. package/atomic/layer/README.md +0 -116
  412. package/atomic/utils/css.ts +0 -49
  413. package/dist/assert-h_Zkqc4E.js +0 -105
  414. package/dist/assert-h_Zkqc4E.js.map +0 -1
  415. package/dist/className-C1Ht5Wvv.js +0 -144
  416. package/dist/className-C1Ht5Wvv.js.map +0 -1
  417. package/dist/className-DC2Cq8p3.js +0 -251
  418. package/dist/className-DC2Cq8p3.js.map +0 -1
  419. package/dist/compiler-DweanHoB.mjs.map +0 -1
  420. package/dist/config-BryWDfQX.js +0 -25
  421. package/dist/config-BryWDfQX.js.map +0 -1
  422. package/dist/config-DKHXWhe1.js +0 -1
  423. package/dist/config-Di2VYYKV.js +0 -6
  424. package/dist/config-DloHOG6I.js +0 -13
  425. package/dist/config-DloHOG6I.js.map +0 -1
  426. package/dist/css-BowBszUt.js +0 -243
  427. package/dist/css-BowBszUt.js.map +0 -1
  428. package/dist/css-ByOrugEX.js +0 -805
  429. package/dist/css-ByOrugEX.js.map +0 -1
  430. package/dist/css-DcazYor9.js +0 -235
  431. package/dist/css-DcazYor9.js.map +0 -1
  432. package/dist/css_extra-DlOnsnR1.js +0 -8
  433. package/dist/css_extra-oIi3UEPK.js.map +0 -1
  434. package/dist/data-_te7t0M4.js +0 -473
  435. package/dist/data-_te7t0M4.js.map +0 -1
  436. package/dist/debug-BAw63qX6.js +0 -15
  437. package/dist/debug-BAw63qX6.js.map +0 -1
  438. package/dist/debug-DGki_v7g.js +0 -15
  439. package/dist/debug-DGki_v7g.js.map +0 -1
  440. package/dist/debug-n2aZQBSa.js.map +0 -1
  441. package/dist/dev-CcphAa3R.js.map +0 -1
  442. package/dist/dev-DfBbuLeE.js +0 -71
  443. package/dist/dev-DfBbuLeE.js.map +0 -1
  444. package/dist/elementMarker-Bu7gDAkE.js.map +0 -1
  445. package/dist/extract-CzWJeQi8.js +0 -121
  446. package/dist/extract-CzWJeQi8.js.map +0 -1
  447. package/dist/extract-DEwSDJ9Z.js +0 -2
  448. package/dist/format-3nKBE_5t.js.map +0 -1
  449. package/dist/getClassName-BlvXHYuf.js.map +0 -1
  450. package/dist/global-CvfmFLsK.js +0 -11
  451. package/dist/global-CvfmFLsK.js.map +0 -1
  452. package/dist/jsx-CwTeyUxr.js +0 -39
  453. package/dist/jsx-CwTeyUxr.js.map +0 -1
  454. package/dist/jsx-D2BksHSv.js +0 -38
  455. package/dist/jsx-D2BksHSv.js.map +0 -1
  456. package/dist/layer-D1SaH07m.js +0 -94
  457. package/dist/layer-D1SaH07m.js.map +0 -1
  458. package/dist/loader-DS61nRqr.mjs.map +0 -1
  459. package/dist/misc-B9kqEb2N.mjs.map +0 -1
  460. package/dist/presets-Bye3ea2x.js +0 -139
  461. package/dist/presets-Bye3ea2x.js.map +0 -1
  462. package/dist/property-CnLFt5kx.js +0 -406
  463. package/dist/property-CnLFt5kx.js.map +0 -1
  464. package/dist/rules-9HSO1pxL.js.map +0 -1
  465. package/dist/runtime-CYqNCiaM.js.map +0 -1
  466. package/dist/shared-BAL9peIw.cjs.map +0 -1
  467. package/dist/style-4rFUy-zW.js +0 -752
  468. package/dist/style-4rFUy-zW.js.map +0 -1
  469. package/dist/style-B1UUqjj5.js +0 -743
  470. package/dist/style-B1UUqjj5.js.map +0 -1
  471. package/dist/style-Cw3NtvR0.js +0 -5
  472. package/dist/style-DNqQ6H-7.js +0 -1255
  473. package/dist/style-DNqQ6H-7.js.map +0 -1
  474. package/dist/styleStore-Dea_WVbr.js.map +0 -1
  475. package/dist/styleStore-DyNXBcUK.js.map +0 -1
  476. package/dist/token-CKXUECuU.js +0 -76
  477. package/dist/token-CKXUECuU.js.map +0 -1
  478. package/dist/token-u_tM-mtg.js +0 -204
  479. package/dist/token-u_tM-mtg.js.map +0 -1
  480. package/dist/utils-BbehLOby.js.map +0 -1
  481. package/dist/utils-C7xfDxtM.mjs +0 -97
  482. package/dist/utils-C7xfDxtM.mjs.map +0 -1
  483. package/dist/utils-CWNHx4EC.js +0 -170
  484. package/dist/utils-CWNHx4EC.js.map +0 -1
  485. package/dist/utils-D7FAOyg6.js.map +0 -1
  486. package/dist/value-BR4e2MKt.js +0 -910
  487. package/dist/value-BR4e2MKt.js.map +0 -1
  488. package/dist/value-E8rEv2Oe.js +0 -136
  489. package/dist/value-E8rEv2Oe.js.map +0 -1
  490. package/dist/valueRef-lshFk1Cs.js +0 -16
  491. package/dist/valueRef-lshFk1Cs.js.map +0 -1
  492. package/dist/webpack-CxS2FDYU.mjs.map +0 -1
  493. package/dist/withTokens-LRidu3Vc.js +0 -95
  494. package/dist/withTokens-LRidu3Vc.js.map +0 -1
@@ -1,8 +1,8 @@
1
- import { getAtomicClassName, getClassNameDedupe } from '../../../../atomic/className';
1
+ import { getAtomicClassName, getClassNameDedupe, getClassNameHashLength } from '../../../../atomic/className';
2
2
  import { LayerDefaultPriority } from '../../../../atomic/layer';
3
3
  import { buildAtomicRule, getAtomicRuleLayerPriority } from '../../../../atomic/rule';
4
- import { getTokenVar, getTokenVarName } from '../../../../atomic/token';
5
- import { getCssVarRawFallback } from '../../../../atomic/utils/css';
4
+ import { getTokenOverrideValue, getTokenVar, getTokenVarName } from '../../../../atomic/token';
5
+ import { getCssVarRawFallback } from '../../../../atomic/utils/cssVar';
6
6
  import { shouldAppendCssPx } from '../../../../atomic/value';
7
7
  import { getLocalVarName } from '../../../../atomic/var';
8
8
  import {
@@ -14,9 +14,10 @@ import {
14
14
  SELECTOR_MEDIA,
15
15
  SELECTOR_MERGE,
16
16
  } from '../../../../builder/data';
17
+ import type { CreateSheetOptions } from '../../../../builder/data';
17
18
  import {
18
- BUILDER_STATE,
19
19
  BUILDER_SLOT_ID,
20
+ BUILDER_STATE,
20
21
  BUILDER_TYPE_SCOPE,
21
22
  BUILDER_TYPE_SLOT,
22
23
  BUILDER_TYPE_SLOT_OVERRIDE,
@@ -34,8 +35,11 @@ import type {
34
35
  RuntimeSlotOverrideItem,
35
36
  RuntimeStyleItem,
36
37
  } from '../../../../builder/data/state';
37
- import type { ClassNameFormat, TokenNameFormat } from '../../../../config/types';
38
+ import { normalizeManualSelectors, setSheetSelectorOptions } from '../../../../builder/selector_override';
39
+ import { isSheetLayerEnabled } from '../../../../config/config/css';
40
+ import type { ClassNameFormat, TokenNameFormat, TransformClassNameFormat } from '../../../../config/types';
38
41
  import type { Selector } from '../../../../selector/types';
42
+ import { importantValue, isStyleImportantValue } from '../../../../style/important';
39
43
  import type { StyleFnMeta } from '../../../../style/style';
40
44
  import {
41
45
  getStyleTokenId,
@@ -43,9 +47,16 @@ import {
43
47
  isStyleTokenOverrideData,
44
48
  type StyleTokenOverride,
45
49
  } from '../../../../style/token';
46
- import type { StyleTransform } from '../../../../style/transform';
50
+ import {
51
+ type ClassNameTransform,
52
+ classNameValue,
53
+ isClassNameValue,
54
+ type StyleTransform,
55
+ } from '../../../../style/transform';
47
56
  import { isAtRuleRef } from '../../../../style/valueRef';
57
+ import { isStyleWeightValue, weightValue } from '../../../../style/weight';
48
58
  import { hashString } from '../../../../utils/hash';
59
+ import { CompilerRuntimeMode } from '../../../compiler/constants';
49
60
  import type { CompilerOptions } from '../../../compiler/types';
50
61
  import { DEFAULT_CONFIG } from '../../../utils/constants';
51
62
  import {
@@ -53,13 +64,19 @@ import {
53
64
  COMPILED_STYLE_OBJECT_LOCATIONS,
54
65
  type CompiledRuntimeValue,
55
66
  type CompiledStyleObject,
67
+ type CompiledStyleObjectLocations,
56
68
  type EvalScope,
57
69
  evaluateNode,
58
70
  } from '../../evaluator/evaluator';
59
71
  import type { EvalResult } from '../../evaluator/types';
60
72
  import type { BabelTypes } from '../../utils/babel';
61
73
  import { validateResolvedSelectorValue, validateSelectorDefinition } from '../../utils/selector';
62
- import { extractStyleChain, STATIC_MERGE_METHOD, type StyleChainParseResult } from './extract_chain';
74
+ import {
75
+ extractStyleChain,
76
+ STATIC_MERGE_METHOD,
77
+ type StyleChainMethod,
78
+ type StyleChainParseResult,
79
+ } from './extract_chain';
63
80
  import type {
64
81
  CompiledChainData,
65
82
  CompiledCssItem,
@@ -68,133 +85,1126 @@ import type {
68
85
  CssExtractRule,
69
86
  } from './types';
70
87
 
71
- type SelectorsMap = Record<string, Selector>;
88
+ type SelectorsMap = Record<string, Selector>;
89
+
90
+ type CssConfig = {
91
+ classNameFormat: ClassNameFormat | null;
92
+ sheetClassNameFormat: ClassNameFormat | null;
93
+ transformClassNameFormat: TransformClassNameFormat | null;
94
+ hashLength: number;
95
+ tokenNameFormat: TokenNameFormat | null;
96
+ localClassName: boolean;
97
+ debugClassName: boolean;
98
+ runtimeMode: CompilerRuntimeMode | null;
99
+ scopeTargetPrefix: string;
100
+ };
101
+
102
+ type ExtractCssOptions = NonNullable<CompilerOptions['css']> & {
103
+ debugClassName?: boolean;
104
+ scopeTargetPrefix?: string;
105
+ };
106
+
107
+ type StyleChainBuilderType =
108
+ | typeof BUILDER_TYPE_STYLE
109
+ | typeof BUILDER_TYPE_SLOT
110
+ | typeof BUILDER_TYPE_SLOT_OVERRIDE;
111
+
112
+ type ExtractedCssBuilderType =
113
+ | StyleChainBuilderType
114
+ | typeof BUILDER_TYPE_SCOPE;
115
+
116
+ type TraceCallsiteOverride = RuntimeStyleItem['callsite'];
117
+
118
+ function applyTransform(
119
+ styleObj: Record<string, unknown>,
120
+ transform: StyleTransform | null,
121
+ cssConfig: CssConfig,
122
+ ): Record<string, unknown> {
123
+ if (!transform) return styleObj;
124
+
125
+ const input = transformRuntimeValues(styleObj, transform, cssConfig);
126
+ const transformed = transform.transform(input);
127
+
128
+ return carryTransformedLocations(input, transformed, transform);
129
+ }
130
+
131
+ function transformRuntimeValues(
132
+ styleObj: Record<string, unknown>,
133
+ transform: StyleTransform,
134
+ cssConfig: CssConfig,
135
+ ): Record<string, unknown> {
136
+ let result: Record<string, unknown> | null = null;
137
+
138
+ for (const [property, rawValue] of Object.entries(styleObj)) {
139
+ const weighted = isStyleWeightValue(rawValue) ? rawValue : null;
140
+ const value = weighted ? weighted.value : rawValue;
141
+ const runtimeValue = getCompiledRuntimeValue(value);
142
+ if (!runtimeValue) continue;
143
+
144
+ const transformedRuntimeValue = transformRuntimeExpression(property, runtimeValue, transform, cssConfig);
145
+ if (transformedRuntimeValue === runtimeValue) continue;
146
+
147
+ result ??= cloneCompiledStyleObject(styleObj);
148
+ const transformed = createCompiledRuntimeValue(transformedRuntimeValue);
149
+ result[property] = weighted ? weightValue(transformed, weighted.weight) : transformed;
150
+ }
151
+
152
+ return result ?? styleObj;
153
+ }
154
+
155
+ function cloneCompiledStyleObject(
156
+ styleObj: Record<string, unknown>,
157
+ ): Record<string, unknown> {
158
+ const cloned = { ...styleObj };
159
+ const locations = (styleObj as CompiledStyleObject)[COMPILED_STYLE_OBJECT_LOCATIONS];
160
+
161
+ if (locations) {
162
+ Object.defineProperty(cloned, COMPILED_STYLE_OBJECT_LOCATIONS, {
163
+ configurable: true,
164
+ enumerable: false,
165
+ value: locations,
166
+ });
167
+ }
168
+
169
+ return cloned;
170
+ }
171
+
172
+ function createCompiledRuntimeValue(
173
+ runtimeValue: BabelTypes.Expression,
174
+ ): CompiledRuntimeValue {
175
+ return {
176
+ [COMPILED_RUNTIME_VALUE]: runtimeValue,
177
+ };
178
+ }
179
+
180
+ function transformRuntimeExpression(
181
+ property: string,
182
+ expression: BabelTypes.Expression,
183
+ transform: StyleTransform,
184
+ cssConfig: CssConfig,
185
+ ): BabelTypes.Expression {
186
+ if (expression.type === 'StringLiteral') {
187
+ const transformed = transform.transform({ [property]: expression.value });
188
+ const transformedValue = normalizeRuntimeTransformedValue(
189
+ getSingleTransformedValue(transformed),
190
+ cssConfig,
191
+ );
192
+
193
+ return createPrimitiveExpression(expression, transformedValue) ?? expression;
194
+ }
195
+
196
+ if (expression.type === 'ConditionalExpression') {
197
+ const consequent = transformRuntimeExpression(
198
+ property,
199
+ expression.consequent as BabelTypes.Expression,
200
+ transform,
201
+ cssConfig,
202
+ );
203
+ const alternate = transformRuntimeExpression(
204
+ property,
205
+ expression.alternate as BabelTypes.Expression,
206
+ transform,
207
+ cssConfig,
208
+ );
209
+
210
+ return consequent === expression.consequent && alternate === expression.alternate
211
+ ? expression
212
+ : ({
213
+ ...expression,
214
+ consequent,
215
+ alternate,
216
+ } as BabelTypes.Expression);
217
+ }
218
+
219
+ return expression;
220
+ }
221
+
222
+ function getSingleTransformedValue(
223
+ transformed: Record<string, unknown>,
224
+ ) {
225
+ const values = Object.values(transformed);
226
+ if (!values.length) return undefined;
227
+
228
+ return values[0];
229
+ }
230
+
231
+ function normalizeRuntimeTransformedValue(
232
+ value: unknown,
233
+ cssConfig: CssConfig,
234
+ ) {
235
+ if (isStyleTokenOverrideData(value)) {
236
+ return getTokenOverrideValue(value, cssConfig.tokenNameFormat);
237
+ }
238
+
239
+ if (isStyleTokenData(value)) {
240
+ return getTokenVar(value, cssConfig.tokenNameFormat);
241
+ }
242
+
243
+ return value;
244
+ }
245
+
246
+ function createPrimitiveExpression(
247
+ original: BabelTypes.Expression,
248
+ value: unknown,
249
+ ): BabelTypes.Expression | null {
250
+ if (original.type === 'StringLiteral' && value === original.value) return null;
251
+
252
+ if (typeof value === 'string') {
253
+ return {
254
+ ...original,
255
+ type: 'StringLiteral',
256
+ value,
257
+ } as BabelTypes.Expression;
258
+ }
259
+
260
+ if (typeof value === 'number') {
261
+ return {
262
+ ...original,
263
+ type: 'NumericLiteral',
264
+ value,
265
+ } as BabelTypes.Expression;
266
+ }
267
+
268
+ if (typeof value === 'boolean') {
269
+ return {
270
+ ...original,
271
+ type: 'BooleanLiteral',
272
+ value,
273
+ } as BabelTypes.Expression;
274
+ }
275
+
276
+ if (value === null) {
277
+ return {
278
+ ...original,
279
+ type: 'NullLiteral',
280
+ } as BabelTypes.Expression;
281
+ }
282
+
283
+ return null;
284
+ }
285
+
286
+ function carryTransformedLocations(
287
+ input: Record<string, unknown>,
288
+ transformed: Record<string, unknown>,
289
+ transform: StyleTransform,
290
+ ): Record<string, unknown> {
291
+ const inputLocations = (input as CompiledStyleObject)[COMPILED_STYLE_OBJECT_LOCATIONS];
292
+ if (!inputLocations) return transformed;
293
+
294
+ const transformedLocations = (transformed as CompiledStyleObject)[COMPILED_STYLE_OBJECT_LOCATIONS];
295
+ const locations: typeof inputLocations = {
296
+ ...transformedLocations,
297
+ };
298
+
299
+ for (const [property, loc] of Object.entries(inputLocations)) {
300
+ if (property in transformed && !locations[property]) {
301
+ locations[property] = loc;
302
+ }
303
+
304
+ const single = transform.transform({ [property]: input[property] });
305
+ for (const transformedProperty of Object.keys(single)) {
306
+ locations[transformedProperty] ??= loc;
307
+ }
308
+ }
309
+
310
+ if (!Object.keys(locations).length) return transformed;
311
+
312
+ Object.defineProperty(transformed, COMPILED_STYLE_OBJECT_LOCATIONS, {
313
+ configurable: true,
314
+ enumerable: false,
315
+ value: locations,
316
+ });
317
+
318
+ return transformed;
319
+ }
320
+
321
+ /**
322
+ * Compile a parsed chain into extracted items and CSS rules.
323
+ * Returns null if any argument cannot be statically evaluated.
324
+ */
325
+ export function compileChain(
326
+ chain: NonNullable<StyleChainParseResult>,
327
+ fileId: string,
328
+ nodeLoc: { line: number; column: number; } | null | undefined,
329
+ scope: EvalScope,
330
+ opts: CompilerOptions,
331
+ runtimeMode: CompilerRuntimeMode | null,
332
+ meta: StyleFnMeta | null,
333
+ styleNames: Set<string> = new Set(),
334
+ ): CompiledChainData | null {
335
+ const css = getCssConfig(opts, runtimeMode);
336
+
337
+ if (chain.kind === 'sheet') {
338
+ return compileSheetChain(chain, fileId, scope, css, opts);
339
+ }
340
+
341
+ if (!meta) return null;
342
+
343
+ if (meta.mode === 'ClassName') {
344
+ if (chain.kind !== 'style') return null;
345
+ return compileClassNameChain(chain, meta.selectors, fileId, nodeLoc, scope, css, meta.transform, styleNames, opts);
346
+ }
347
+
348
+ const selectors = meta.selectors;
349
+ const transform = meta.transform;
350
+
351
+ if (chain.kind === 'style') {
352
+ return compileStyleChain(chain, selectors, fileId, scope, css, transform, styleNames, opts);
353
+ }
354
+
355
+ if (chain.kind === 'slot') {
356
+ const slotId = computeSlotId(fileId, nodeLoc);
357
+ return compileSlotChain(chain, slotId, selectors, fileId, scope, css, transform, styleNames, opts);
358
+ }
359
+
360
+ if (chain.kind === 'scope') {
361
+ return compileScopeChain(chain, selectors, fileId, scope, css, transform, opts);
362
+ }
363
+
364
+ return null;
365
+ }
366
+
367
+ function compileSheetChain(
368
+ chain: NonNullable<StyleChainParseResult>,
369
+ fileId: string,
370
+ scope: EvalScope,
371
+ cssConfig: CssConfig,
372
+ options: CompilerOptions,
373
+ ): CompiledChainData | null {
374
+ if (chain.methods.length > 0 || chain.baseArgs.length > 2) return null;
375
+
376
+ const items: CompiledItem[] = [];
377
+ const rules: CssExtractRule[] = [];
378
+ const hasOptions = chain.baseArgs.length === 2;
379
+ const sheetOptions = hasOptions
380
+ ? evaluateCreateSheetOptions(chain.baseArgs[0], scope)
381
+ : {};
382
+ if (!sheetOptions) return null;
383
+
384
+ const sheetItems = chain.baseArgs[hasOptions ? 1 : 0];
385
+
386
+ if (
387
+ sheetItems &&
388
+ !compileSheetItemsArg(sheetItems, fileId, scope, cssConfig, options, items, rules, sheetOptions)
389
+ ) {
390
+ return null;
391
+ }
392
+
393
+ const sheetLayer = sheetOptions.layer ?? isSheetLayerEnabled(options.css?.layer ?? DEFAULT_CONFIG.layer);
394
+ for (let i = 0, len = rules.length; i < len; i++) {
395
+ rules[i].layer = sheetLayer ? 'sheet' : false;
396
+ }
397
+
398
+ return { type: 'sheet', items, rules, sheetOptions };
399
+ }
400
+
401
+ function evaluateCreateSheetOptions(
402
+ node: BabelTypes.Node,
403
+ scope: EvalScope,
404
+ ): CreateSheetOptions | null {
405
+ const result = evaluateNode(node, scope);
406
+ if (!result.ok || !result.value || typeof result.value !== 'object' || Array.isArray(result.value)) return null;
407
+
408
+ const value = result.value as Record<string, unknown>;
409
+ if (Object.keys(value).some((key) => key !== 'layer' && key !== 'weight')) return null;
410
+ if (value.layer !== undefined && typeof value.layer !== 'boolean') return null;
411
+ if (value.weight !== undefined && (!Number.isInteger(value.weight) || (value.weight as number) < 1)) return null;
412
+
413
+ return {
414
+ layer: value.layer as boolean | undefined,
415
+ weight: value.weight as number | undefined,
416
+ };
417
+ }
418
+
419
+ function compileSheetItemsArg(
420
+ node: BabelTypes.Node,
421
+ fileId: string,
422
+ scope: EvalScope,
423
+ cssConfig: CssConfig,
424
+ options: CompilerOptions,
425
+ items: CompiledItem[],
426
+ rules: CssExtractRule[],
427
+ sheetOptions: CreateSheetOptions,
428
+ ): boolean {
429
+ if (node.type === 'ArrayExpression') {
430
+ for (const element of node.elements) {
431
+ if (!element) continue;
432
+ if (element.type === 'SpreadElement') return false;
433
+ if (!compileSheetItemsArg(element, fileId, scope, cssConfig, options, items, rules, sheetOptions)) return false;
434
+ }
435
+
436
+ return true;
437
+ }
438
+
439
+ const tokenOverride = evaluateNode(node, scope);
440
+ if (tokenOverride.ok && isStyleTokenOverrideData(tokenOverride.value)) {
441
+ addCompiledTokenItem(
442
+ getStyleTokenId(tokenOverride.value),
443
+ tokenOverride.value,
444
+ getCompiledRuntimeValue(tokenOverride.value) ?? node as BabelTypes.Expression,
445
+ items,
446
+ );
447
+ return true;
448
+ }
449
+
450
+ if (tokenOverride.ok && Array.isArray(tokenOverride.value)) {
451
+ for (let i = 0, len = tokenOverride.value.length; i < len; i++) {
452
+ const item = tokenOverride.value[i];
453
+ if (!item) continue;
454
+ if (!isStyleTokenOverrideData(item)) return false;
455
+
456
+ addCompiledTokenItem(
457
+ getStyleTokenId(item),
458
+ item,
459
+ getCompiledRuntimeValue(item) ?? null,
460
+ items,
461
+ );
462
+ }
463
+
464
+ return true;
465
+ }
466
+
467
+ const styleNames = scope.styleNames ?? new Set();
468
+ const sheetNames = scope.sheetNames ?? new Set();
469
+ const selectorChain = node.type === 'CallExpression'
470
+ ? extractStyleChain(node, styleNames, sheetNames) ??
471
+ getLocalSelectorTargetChain(node, scope, styleNames, sheetNames)
472
+ : getLocalStyleChainArg(node, scope, styleNames, sheetNames);
473
+ const selectorMeta = selectorChain ? scope.styleMetas?.get(selectorChain.rootName) : null;
474
+
475
+ if (selectorChain?.kind !== 'selector' || !selectorMeta || selectorMeta.mode !== 'StyleObject') {
476
+ return false;
477
+ }
478
+
479
+ return compileSelectorOverrideChain(
480
+ selectorChain,
481
+ selectorMeta.selectors,
482
+ fileId,
483
+ scope,
484
+ cssConfig,
485
+ selectorMeta.transform,
486
+ scope.styleNames ?? new Set(),
487
+ options,
488
+ items,
489
+ rules,
490
+ sheetOptions,
491
+ );
492
+ }
493
+
494
+ function compileSelectorOverrideChain(
495
+ chain: NonNullable<StyleChainParseResult>,
496
+ selectors: SelectorsMap,
497
+ fileId: string,
498
+ scope: EvalScope,
499
+ cssConfig: CssConfig,
500
+ transform: StyleTransform | null,
501
+ styleNames: Set<string>,
502
+ options: CompilerOptions,
503
+ items: CompiledItem[],
504
+ rules: CssExtractRule[],
505
+ sheetOptions: CreateSheetOptions,
506
+ ): boolean {
507
+ if (chain.baseArgs.length === 0 || chain.baseArgs.length > 2) return false;
508
+
509
+ const selectorArg = evaluateNode(chain.baseArgs[0], scope);
510
+ if (!selectorArg.ok) return false;
511
+
512
+ const manualSelectors = normalizeManualSelectors(
513
+ Array.isArray(selectorArg.value)
514
+ ? selectorArg.value.map(String)
515
+ : String(selectorArg.value ?? ''),
516
+ );
517
+
518
+ for (let i = 0, len = manualSelectors.length; i < len; i++) {
519
+ if (
520
+ !compileSelectorOverrideInto(
521
+ chain,
522
+ selectors,
523
+ fileId,
524
+ scope,
525
+ cssConfig,
526
+ transform,
527
+ styleNames,
528
+ options,
529
+ items,
530
+ rules,
531
+ setSheetSelectorOptions(manualSelectors[i], sheetOptions),
532
+ )
533
+ ) {
534
+ return false;
535
+ }
536
+ }
537
+
538
+ return true;
539
+ }
540
+
541
+ function compileSelectorOverrideInto(
542
+ chain: NonNullable<StyleChainParseResult>,
543
+ selectors: SelectorsMap,
544
+ fileId: string,
545
+ scope: EvalScope,
546
+ cssConfig: CssConfig,
547
+ transform: StyleTransform | null,
548
+ styleNames: Set<string>,
549
+ options: CompilerOptions,
550
+ items: CompiledItem[],
551
+ rules: CssExtractRule[],
552
+ selectorPrefix: ItemSelector,
553
+ ): boolean {
554
+ if (chain.baseArgs[1]) {
555
+ if (
556
+ !compileSelectorStyleArg(
557
+ chain.baseArgs[1],
558
+ fileId,
559
+ scope,
560
+ cssConfig,
561
+ transform,
562
+ items,
563
+ rules,
564
+ styleNames,
565
+ options,
566
+ selectorPrefix,
567
+ )
568
+ ) {
569
+ return false;
570
+ }
571
+ }
572
+
573
+ let i = 0;
574
+ while (i < chain.methods.length) {
575
+ const method = chain.methods[i];
576
+ if (
577
+ !compileChainMethod(
578
+ method,
579
+ selectors,
580
+ null,
581
+ fileId,
582
+ scope,
583
+ BUILDER_TYPE_STYLE,
584
+ cssConfig,
585
+ items,
586
+ rules,
587
+ transform,
588
+ null,
589
+ styleNames,
590
+ options,
591
+ null,
592
+ selectorPrefix,
593
+ )
594
+ ) {
595
+ return false;
596
+ }
597
+ i++;
598
+ }
599
+
600
+ return true;
601
+ }
602
+
603
+ function compileSelectorStyleArg(
604
+ styleArgNode: BabelTypes.Node,
605
+ fileId: string,
606
+ scope: EvalScope,
607
+ cssConfig: CssConfig,
608
+ transform: StyleTransform | null,
609
+ items: CompiledItem[],
610
+ rules: CssExtractRule[],
611
+ styleNames: Set<string>,
612
+ options: CompilerOptions,
613
+ selectorPrefix: ItemSelector,
614
+ ): boolean {
615
+ const localChain = getLocalStyleChainArg(styleArgNode, scope, styleNames);
616
+ const localMeta = localChain ? scope.styleMetas?.get(localChain.rootName) : null;
617
+
618
+ if (localChain?.kind === 'style' && localMeta) {
619
+ return compileStyleChainInto(
620
+ localChain,
621
+ localMeta.selectors,
622
+ fileId,
623
+ scope,
624
+ cssConfig,
625
+ localMeta.transform,
626
+ BUILDER_TYPE_STYLE,
627
+ null,
628
+ null,
629
+ items,
630
+ rules,
631
+ styleNames,
632
+ options,
633
+ null,
634
+ selectorPrefix,
635
+ );
636
+ }
637
+
638
+ if (styleArgNode.type === 'CallExpression') {
639
+ const nestedChain = extractStyleChain(styleArgNode, styleNames);
640
+ const nestedMeta = nestedChain ? scope.styleMetas?.get(nestedChain.rootName) : null;
641
+
642
+ if (nestedChain?.kind === 'style' && nestedMeta) {
643
+ return compileStyleChainInto(
644
+ nestedChain,
645
+ nestedMeta.selectors,
646
+ fileId,
647
+ scope,
648
+ cssConfig,
649
+ nestedMeta.transform,
650
+ BUILDER_TYPE_STYLE,
651
+ null,
652
+ null,
653
+ items,
654
+ rules,
655
+ styleNames,
656
+ options,
657
+ null,
658
+ selectorPrefix,
659
+ );
660
+ }
661
+ }
662
+
663
+ const styleArg = evaluateNode(styleArgNode, scope);
664
+ if (!styleArg.ok) {
665
+ throwIfRequiredStaticStyleValue(styleArg);
666
+ return false;
667
+ }
668
+
669
+ if (isStyleData(styleArg.value)) {
670
+ return addStyleDataItems(
671
+ styleArg.value,
672
+ selectorPrefix,
673
+ null,
674
+ null,
675
+ fileId,
676
+ BUILDER_TYPE_STYLE,
677
+ null,
678
+ items,
679
+ rules,
680
+ cssConfig,
681
+ null,
682
+ );
683
+ }
684
+
685
+ const styleObj = applyTransform(styleArg.value as Record<string, unknown>, transform, cssConfig);
686
+
687
+ return addStyleItems(
688
+ styleObj,
689
+ selectorPrefix,
690
+ null,
691
+ null,
692
+ fileId,
693
+ BUILDER_TYPE_STYLE,
694
+ null,
695
+ items,
696
+ rules,
697
+ cssConfig,
698
+ null,
699
+ );
700
+ }
701
+
702
+ function getCssConfig(
703
+ opts: CompilerOptions,
704
+ runtimeMode: CompilerRuntimeMode | null,
705
+ ): CssConfig {
706
+ const css = opts.css as ExtractCssOptions | undefined;
707
+ const isDevRuntimeMode = runtimeMode === CompilerRuntimeMode.Dev || runtimeMode === CompilerRuntimeMode.RscDev;
708
+ const debugClassName = css?.debugClassName ?? isDevRuntimeMode;
709
+
710
+ return {
711
+ classNameFormat: css?.classNameFormat ?? DEFAULT_CONFIG.classNameFormat ?? null,
712
+ sheetClassNameFormat: css?.sheetClassNameFormat ?? DEFAULT_CONFIG.sheetClassNameFormat ?? null,
713
+ transformClassNameFormat: css?.transformClassNameFormat ?? DEFAULT_CONFIG.transformClassNameFormat ?? null,
714
+ hashLength: getClassNameHashLength({
715
+ debugClassName,
716
+ isDev: isDevRuntimeMode,
717
+ cssHashLength: css?.hashLength ?? DEFAULT_CONFIG.hashLength,
718
+ }),
719
+ tokenNameFormat: css?.tokenNameFormat ?? DEFAULT_CONFIG.tokenNameFormat ?? null,
720
+ localClassName: isDevRuntimeMode,
721
+ debugClassName,
722
+ runtimeMode,
723
+ scopeTargetPrefix: css?.scopeTargetPrefix ?? '',
724
+ };
725
+ }
726
+
727
+ export function computeSlotId(
728
+ fileId: string,
729
+ loc: { line: number; column: number; } | null | undefined,
730
+ ): string {
731
+ if (loc) {
732
+ return hashString(fileId + '\n' + loc.line + ':' + loc.column);
733
+ }
734
+ return hashString(fileId + '\n' + Math.random());
735
+ }
736
+
737
+ // ─── style chain ─────────────────────────────────────────────────────────────
738
+
739
+ function compileStyleChain(
740
+ chain: NonNullable<StyleChainParseResult>,
741
+ selectors: SelectorsMap,
742
+ fileId: string,
743
+ scope: EvalScope,
744
+ cssConfig: CssConfig,
745
+ transform: StyleTransform | null,
746
+ styleNames: Set<string>,
747
+ options: CompilerOptions,
748
+ ): CompiledChainData | null {
749
+ const items: CompiledItem[] = [];
750
+ const rules: CssExtractRule[] = [];
751
+
752
+ if (
753
+ !compileStyleChainInto(
754
+ chain,
755
+ selectors,
756
+ fileId,
757
+ scope,
758
+ cssConfig,
759
+ transform,
760
+ BUILDER_TYPE_STYLE,
761
+ null,
762
+ null,
763
+ items,
764
+ rules,
765
+ styleNames,
766
+ options,
767
+ )
768
+ ) {
769
+ return null;
770
+ }
771
+
772
+ return { type: 'style', items, rules };
773
+ }
774
+
775
+ function compileClassNameChain(
776
+ chain: NonNullable<StyleChainParseResult>,
777
+ selectors: SelectorsMap,
778
+ fileId: string,
779
+ nodeLoc: { line: number; column: number; } | null | undefined,
780
+ scope: EvalScope,
781
+ cssConfig: CssConfig,
782
+ transform: ClassNameTransform,
783
+ styleNames: Set<string>,
784
+ options: CompilerOptions,
785
+ ): CompiledChainData | null {
786
+ const items: CompiledItem[] = [];
787
+ const rules: CssExtractRule[] = [];
788
+
789
+ if (
790
+ !compileClassNameArgsInto(
791
+ chain.baseArgs,
792
+ 0,
793
+ null,
794
+ null,
795
+ fileId,
796
+ scope,
797
+ createClassNameFallbackLocation(nodeLoc, scope, fileId),
798
+ cssConfig,
799
+ transform,
800
+ BUILDER_TYPE_STYLE,
801
+ null,
802
+ items,
803
+ rules,
804
+ )
805
+ ) {
806
+ return null;
807
+ }
808
+
809
+ let i = 0;
810
+ while (i < chain.methods.length) {
811
+ const method = chain.methods[i];
812
+ const result = compileClassNameChainMethod(
813
+ method,
814
+ selectors,
815
+ fileId,
816
+ scope,
817
+ cssConfig,
818
+ transform,
819
+ items,
820
+ rules,
821
+ styleNames,
822
+ options,
823
+ );
824
+ if (!result) return null;
825
+ i++;
826
+ }
827
+
828
+ return { type: 'style', items, rules };
829
+ }
830
+
831
+ function compileClassNameChainMethod(
832
+ method: StyleChainMethod,
833
+ selectors: SelectorsMap,
834
+ fileId: string,
835
+ scope: EvalScope,
836
+ cssConfig: CssConfig,
837
+ transform: ClassNameTransform,
838
+ items: CompiledItem[],
839
+ rules: CssExtractRule[],
840
+ styleNames: Set<string>,
841
+ options: CompilerOptions,
842
+ ): boolean {
843
+ const selector = selectors[method.name];
844
+ if (!selector) return false;
845
+ validateSelectorDefinition(options.dev?.checkSelector, `style.${method.name}`, selector, method.nameNode);
846
+
847
+ const selectorStr = selector.selector.trim();
848
+
849
+ if (selectorStr === SELECTOR_MERGE) {
850
+ const localChain = getLocalStyleChainArg(method.args[0], scope, styleNames);
851
+ const localMeta = localChain ? scope.styleMetas?.get(localChain.rootName) : null;
852
+
853
+ if (localChain?.kind === 'style' && localMeta?.mode === 'ClassName') {
854
+ const result = compileClassNameChain(
855
+ localChain,
856
+ localMeta.selectors,
857
+ fileId,
858
+ method.nameNode.loc?.start,
859
+ scope,
860
+ cssConfig,
861
+ localMeta.transform,
862
+ styleNames,
863
+ options,
864
+ );
865
+ if (!result) return false;
866
+ items.push(...result.items);
867
+ rules.push(...result.rules);
868
+ return true;
869
+ }
870
+
871
+ return false;
872
+ }
873
+
874
+ if (selectorStr.startsWith(SELECTOR_AT_RULE)) {
875
+ const isMedia = selectorStr.startsWith(SELECTOR_MEDIA) || selectorStr.startsWith(SELECTOR_CONTAINER);
876
+ const hasArg = selectorStr.includes(SELECTOR_ARGS);
877
+ const priority = getAtRulePriority(selector.priority, isMedia, method.args[0]);
878
+ let argOffset = 0;
879
+
880
+ if (isMedia && isNumericLiteral(method.args[0])) {
881
+ argOffset = 1;
882
+ }
883
+
884
+ let atRule = selectorStr;
885
+ if (hasArg) {
886
+ const queryArg = evaluateNode(method.args[argOffset], scope);
887
+ validateResolvedSelectorValue(
888
+ options.dev?.checkSelector,
889
+ `style.${method.name}`,
890
+ selector,
891
+ queryArg,
892
+ method.args[argOffset],
893
+ );
894
+ throwIfRequiredStaticSelectorValue(options, `style.${method.name}`, queryArg);
895
+ if (!queryArg.ok) return false;
896
+
897
+ const [before, after] = selectorStr.split(SELECTOR_ARGS);
898
+ atRule = before + String(queryArg.value) + (after ?? '');
899
+ }
900
+
901
+ const atRuleSelector: ItemSelector = priority !== null ? [atRule, priority] : atRule;
902
+ const classNameOffset = hasArg ? argOffset + 1 : argOffset;
903
+
904
+ return compileClassNameArgsInto(
905
+ method.args,
906
+ classNameOffset,
907
+ null,
908
+ [atRuleSelector],
909
+ fileId,
910
+ scope,
911
+ createClassNameFallbackLocation(method.nameNode.loc?.start, scope, fileId),
912
+ cssConfig,
913
+ transform,
914
+ BUILDER_TYPE_STYLE,
915
+ null,
916
+ items,
917
+ rules,
918
+ );
919
+ }
920
+
921
+ if (selectorStr.includes(SELECTOR_ARGS) || selectorStr.includes(SELECTOR_ARG)) {
922
+ const hasArgsTemplate = selectorStr.includes(SELECTOR_ARGS);
923
+ const splitToken = hasArgsTemplate ? SELECTOR_ARGS : SELECTOR_ARG;
924
+ const [before, after] = selectorStr.split(splitToken);
925
+
926
+ const selectorArg = evaluateNode(method.args[0], scope);
927
+ validateResolvedSelectorValue(
928
+ options.dev?.checkSelector,
929
+ `style.${method.name}`,
930
+ selector,
931
+ selectorArg,
932
+ method.args[0],
933
+ );
934
+ if (!selectorArg.ok) return false;
935
+
936
+ const selectorText = before + normalizeSelectorArg(String(selectorArg.value ?? '')) + (after ?? '');
937
+ const itemSelector: ItemSelector = selector.priority !== null ? [selectorText, selector.priority] : selectorText;
938
+
939
+ return compileClassNameArgsInto(
940
+ method.args,
941
+ 1,
942
+ itemSelector,
943
+ null,
944
+ fileId,
945
+ scope,
946
+ createClassNameFallbackLocation(method.nameNode.loc?.start, scope, fileId),
947
+ cssConfig,
948
+ transform,
949
+ BUILDER_TYPE_STYLE,
950
+ null,
951
+ items,
952
+ rules,
953
+ );
954
+ }
955
+
956
+ const itemSelector: ItemSelector = selector.priority !== null
957
+ ? [selectorStr, selector.priority]
958
+ : selectorStr;
959
+
960
+ return compileClassNameArgsInto(
961
+ method.args,
962
+ 0,
963
+ itemSelector,
964
+ null,
965
+ fileId,
966
+ scope,
967
+ createClassNameFallbackLocation(method.nameNode.loc?.start, scope, fileId),
968
+ cssConfig,
969
+ transform,
970
+ BUILDER_TYPE_STYLE,
971
+ null,
972
+ items,
973
+ rules,
974
+ );
975
+ }
976
+
977
+ function compileClassNameArgsInto(
978
+ args: readonly BabelTypes.Node[],
979
+ startIndex: number,
980
+ selector: ItemSelector | null,
981
+ atRules: ItemSelector[] | null,
982
+ fileId: string,
983
+ scope: EvalScope,
984
+ fallbackLocation: CompiledStyleObjectLocations[string] | null,
985
+ cssConfig: CssConfig,
986
+ transform: ClassNameTransform,
987
+ type: ExtractedCssBuilderType,
988
+ slotId: string | null,
989
+ items: CompiledItem[],
990
+ rules: CssExtractRule[],
991
+ ): boolean {
992
+ if (startIndex >= args.length) return true;
993
+
994
+ const styleObj: CompiledStyleObject = {};
995
+ const locations: CompiledStyleObjectLocations = {};
996
+
997
+ let i = startIndex;
998
+ while (i < args.length) {
999
+ const arg = evaluateNode(args[i], scope);
1000
+ if (!arg.ok) {
1001
+ throwIfRequiredStaticStyleValue(arg);
1002
+ return false;
1003
+ }
1004
+
1005
+ if (!appendClassNameArgStyle(args[i], arg.value, transform, styleObj, locations, fallbackLocation, scope, fileId)) {
1006
+ return false;
1007
+ }
1008
+ i++;
1009
+ }
72
1010
 
73
- type CssConfig = {
74
- classNameFormat: ClassNameFormat | null;
75
- tokenNameFormat: TokenNameFormat | null;
76
- localClassName: boolean;
77
- debugClassName: boolean;
78
- scopeTargetPrefix: string;
79
- };
1011
+ if (Object.keys(locations).length) {
1012
+ Object.defineProperty(styleObj, COMPILED_STYLE_OBJECT_LOCATIONS, {
1013
+ configurable: true,
1014
+ enumerable: false,
1015
+ value: locations,
1016
+ });
1017
+ }
80
1018
 
81
- type ExtractCssOptions = NonNullable<CompilerOptions['css']> & {
82
- localClassName?: boolean;
83
- debugClassName?: boolean;
84
- scopeTargetPrefix?: string;
85
- };
1019
+ return addStyleItems(
1020
+ styleObj,
1021
+ selector,
1022
+ null,
1023
+ atRules,
1024
+ fileId,
1025
+ type,
1026
+ slotId,
1027
+ items,
1028
+ rules,
1029
+ cssConfig,
1030
+ );
1031
+ }
86
1032
 
87
- type StyleChainBuilderType =
88
- | typeof BUILDER_TYPE_STYLE
89
- | typeof BUILDER_TYPE_SLOT
90
- | typeof BUILDER_TYPE_SLOT_OVERRIDE;
1033
+ function appendClassNameArgStyle(
1034
+ node: BabelTypes.Node,
1035
+ value: unknown,
1036
+ transform: ClassNameTransform,
1037
+ styleObj: CompiledStyleObject,
1038
+ locations: CompiledStyleObjectLocations,
1039
+ fallbackLocation: CompiledStyleObjectLocations[string] | null,
1040
+ scope: EvalScope,
1041
+ fileId: string,
1042
+ ): boolean {
1043
+ if (!value) return true;
1044
+
1045
+ if (typeof value === 'string') {
1046
+ const transformed = decorateClassNameStyle(transform.transform(value), value);
1047
+ Object.assign(styleObj, transformed);
1048
+ assignClassNameStyleLocations(
1049
+ transformed,
1050
+ locations,
1051
+ getClassNameArgLocation(node, fallbackLocation, scope, fileId),
1052
+ );
1053
+ return true;
1054
+ }
91
1055
 
92
- type ExtractedCssBuilderType =
93
- | StyleChainBuilderType
94
- | typeof BUILDER_TYPE_SCOPE;
1056
+ if (Array.isArray(value)) {
1057
+ const nodes = node.type === 'ArrayExpression' ? node.elements : [];
95
1058
 
96
- type TraceCallsiteOverride = RuntimeStyleItem['callsite'];
1059
+ for (let i = 0; i < value.length; i++) {
1060
+ const itemNode = nodes[i] ?? node;
1061
+ if (
1062
+ !appendClassNameArgStyle(itemNode, value[i], transform, styleObj, locations, fallbackLocation, scope, fileId)
1063
+ ) {
1064
+ return false;
1065
+ }
1066
+ }
1067
+ return true;
1068
+ }
97
1069
 
98
- function applyTransform(
1070
+ if (isWeightedClassName(value)) {
1071
+ const transformed = decorateClassNameStyle(transform.transform(value.className), value.className);
1072
+ Object.assign(styleObj, applyClassNameWeight(transformed, value.weight));
1073
+ assignClassNameStyleLocations(
1074
+ transformed,
1075
+ locations,
1076
+ getWeightedClassNameArgLocation(node, fallbackLocation, scope, fileId),
1077
+ );
1078
+ return true;
1079
+ }
1080
+
1081
+ return false;
1082
+ }
1083
+
1084
+ function assignClassNameStyleLocations(
99
1085
  styleObj: Record<string, unknown>,
100
- transform: StyleTransform | null,
101
- ): Record<string, unknown> {
102
- return transform ? transform.transform(styleObj) : styleObj;
1086
+ locations: CompiledStyleObjectLocations,
1087
+ location: CompiledStyleObjectLocations[string] | null,
1088
+ ) {
1089
+ if (!location) return;
1090
+
1091
+ for (const property of Object.keys(styleObj)) {
1092
+ locations[property] = location;
1093
+ }
103
1094
  }
104
1095
 
105
- /**
106
- * Compile a parsed chain into extracted items and CSS rules.
107
- * Returns null if any argument cannot be statically evaluated.
108
- */
109
- export function compileChain(
110
- chain: NonNullable<StyleChainParseResult>,
111
- fileId: string,
112
- nodeLoc: { line: number; column: number; } | null | undefined,
1096
+ function getClassNameArgLocation(
1097
+ node: BabelTypes.Node,
1098
+ fallbackLocation: CompiledStyleObjectLocations[string] | null,
113
1099
  scope: EvalScope,
114
- opts: CompilerOptions,
115
- meta: StyleFnMeta,
116
- styleNames: Set<string> = new Set(),
117
- ): CompiledChainData | null {
118
- const css = getCssConfig(opts);
119
- const selectors = meta.selectors;
120
- const transform = meta.transform;
121
-
122
- if (chain.kind === 'style') {
123
- return compileStyleChain(chain, selectors, fileId, scope, css, transform, styleNames, opts);
1100
+ fileId: string,
1101
+ ): CompiledStyleObjectLocations[string] | null {
1102
+ if (node.type === 'StringLiteral') {
1103
+ return createClassNameFallbackLocation(node.loc?.start, scope, fileId);
124
1104
  }
125
1105
 
126
- if (chain.kind === 'slot') {
127
- const slotId = computeSlotId(fileId, nodeLoc);
128
- return compileSlotChain(chain, slotId, selectors, fileId, scope, css, transform, styleNames, opts);
1106
+ if (node.type === 'TemplateLiteral' && node.expressions.length === 0) {
1107
+ return createClassNameFallbackLocation(node.loc?.start, scope, fileId);
129
1108
  }
130
1109
 
131
- if (chain.kind === 'scope') {
132
- return compileScopeChain(chain, selectors, fileId, scope, css, transform, opts);
1110
+ return fallbackLocation;
1111
+ }
1112
+
1113
+ function getWeightedClassNameArgLocation(
1114
+ node: BabelTypes.Node,
1115
+ fallbackLocation: CompiledStyleObjectLocations[string] | null,
1116
+ scope: EvalScope,
1117
+ fileId: string,
1118
+ ): CompiledStyleObjectLocations[string] | null {
1119
+ if (
1120
+ node.type === 'CallExpression' &&
1121
+ node.arguments[0] &&
1122
+ node.callee.type === 'MemberExpression' &&
1123
+ !node.callee.computed &&
1124
+ node.callee.property.type === 'Identifier' &&
1125
+ node.callee.property.name === 'weight'
1126
+ ) {
1127
+ return getClassNameArgLocation(node.arguments[0] as BabelTypes.Node, fallbackLocation, scope, fileId);
133
1128
  }
134
1129
 
135
- return null;
1130
+ return fallbackLocation;
136
1131
  }
137
1132
 
138
- function getCssConfig(
139
- opts: CompilerOptions,
140
- ): CssConfig {
141
- const css = opts.css as ExtractCssOptions | undefined;
1133
+ function createClassNameFallbackLocation(
1134
+ loc: { line: number; column: number; } | null | undefined,
1135
+ scope: EvalScope,
1136
+ fileId: string,
1137
+ ): CompiledStyleObjectLocations[string] | null {
1138
+ if (!loc) return null;
142
1139
 
143
1140
  return {
144
- classNameFormat: css?.classNameFormat ?? DEFAULT_CONFIG.classNameFormat ?? null,
145
- tokenNameFormat: css?.tokenNameFormat ?? DEFAULT_CONFIG.tokenNameFormat ?? null,
146
- localClassName: css?.localClassName ?? DEFAULT_CONFIG.localClassName,
147
- debugClassName: css?.debugClassName ?? DEFAULT_CONFIG.debugClassName,
148
- scopeTargetPrefix: css?.scopeTargetPrefix ?? '',
1141
+ filePath: scope.styleFilePath ?? fileId,
1142
+ line: loc.line,
1143
+ column: loc.column + 1,
1144
+ variable: false,
149
1145
  };
150
1146
  }
151
1147
 
152
- export function computeSlotId(
153
- fileId: string,
154
- loc: { line: number; column: number; } | null | undefined,
155
- ): string {
156
- if (loc) {
157
- return hashString(fileId + '\n' + loc.line + ':' + loc.column);
1148
+ function decorateClassNameStyle(
1149
+ style: Record<string, unknown>,
1150
+ className: string,
1151
+ ): Record<string, unknown> {
1152
+ const result: Record<string, unknown> = {};
1153
+
1154
+ for (const [property, value] of Object.entries(style)) {
1155
+ if (value === null || value === undefined) {
1156
+ result[property] = value;
1157
+ continue;
1158
+ }
1159
+
1160
+ result[property] = decorateClassNameValue(value, className);
158
1161
  }
159
- return hashString(fileId + '\n' + Math.random());
1162
+
1163
+ return result;
160
1164
  }
161
1165
 
162
- // ─── style chain ─────────────────────────────────────────────────────────────
1166
+ function decorateClassNameValue(
1167
+ value: unknown,
1168
+ className: string,
1169
+ ): unknown {
1170
+ if (isClassNameValue(value)) return value;
163
1171
 
164
- function compileStyleChain(
165
- chain: NonNullable<StyleChainParseResult>,
166
- selectors: SelectorsMap,
167
- fileId: string,
168
- scope: EvalScope,
169
- cssConfig: CssConfig,
170
- transform: StyleTransform | null,
171
- styleNames: Set<string>,
172
- options: CompilerOptions,
173
- ): CompiledChainData | null {
174
- const items: CompiledItem[] = [];
175
- const rules: CssExtractRule[] = [];
1172
+ if (isStyleImportantValue(value)) {
1173
+ return importantValue(decorateClassNameValue(value.value, className));
1174
+ }
176
1175
 
177
- if (
178
- !compileStyleChainInto(
179
- chain,
180
- selectors,
181
- fileId,
182
- scope,
183
- cssConfig,
184
- transform,
185
- BUILDER_TYPE_STYLE,
186
- null,
187
- null,
188
- items,
189
- rules,
190
- styleNames,
191
- options,
192
- )
193
- ) {
194
- return null;
1176
+ if (isStyleWeightValue(value)) {
1177
+ return weightValue(decorateClassNameValue(value.value, className), value.weight);
195
1178
  }
196
1179
 
197
- return { type: 'style', items, rules };
1180
+ return classNameValue(value, className);
1181
+ }
1182
+
1183
+ function isWeightedClassName(
1184
+ value: unknown,
1185
+ ): value is { className: string; weight: number; } {
1186
+ return !!value &&
1187
+ typeof value === 'object' &&
1188
+ typeof (value as { className?: unknown; }).className === 'string' &&
1189
+ typeof (value as { weight?: unknown; }).weight === 'number';
1190
+ }
1191
+
1192
+ function applyClassNameWeight(
1193
+ style: Record<string, unknown>,
1194
+ weight: number,
1195
+ ): Record<string, unknown> {
1196
+ const weighted: Record<string, unknown> = {};
1197
+
1198
+ for (const [property, value] of Object.entries(style)) {
1199
+ if (value === null || value === undefined) {
1200
+ weighted[property] = value;
1201
+ continue;
1202
+ }
1203
+
1204
+ weighted[property] = weightValue(value, weight);
1205
+ }
1206
+
1207
+ return weighted;
198
1208
  }
199
1209
 
200
1210
  function compileStyleChainInto(
@@ -212,6 +1222,7 @@ function compileStyleChainInto(
212
1222
  styleNames: Set<string>,
213
1223
  options: CompilerOptions,
214
1224
  callsiteOverride: TraceCallsiteOverride = null,
1225
+ selectorPrefix: ItemSelector | null = null,
215
1226
  ): boolean {
216
1227
  if (chain.baseArgs.length > 0) {
217
1228
  const styleArg = evaluateNode(chain.baseArgs[0], scope);
@@ -219,11 +1230,11 @@ function compileStyleChainInto(
219
1230
  throwIfRequiredStaticStyleValue(styleArg);
220
1231
  return false;
221
1232
  }
222
- const styleObj = applyTransform(styleArg.value as Record<string, unknown>, transform);
1233
+ const styleObj = applyTransform(styleArg.value as Record<string, unknown>, transform, cssConfig);
223
1234
  if (
224
1235
  !addStyleItems(
225
1236
  styleObj,
226
- null,
1237
+ selectorPrefix,
227
1238
  null,
228
1239
  atRules,
229
1240
  fileId,
@@ -258,6 +1269,7 @@ function compileStyleChainInto(
258
1269
  styleNames,
259
1270
  options,
260
1271
  callsiteOverride,
1272
+ selectorPrefix,
261
1273
  );
262
1274
  if (!result) return false;
263
1275
  i++;
@@ -289,7 +1301,7 @@ function compileSlotChain(
289
1301
  throwIfRequiredStaticStyleValue(styleArg);
290
1302
  return null;
291
1303
  }
292
- const styleObj = applyTransform(styleArg.value as Record<string, unknown>, transform);
1304
+ const styleObj = applyTransform(styleArg.value as Record<string, unknown>, transform, cssConfig);
293
1305
  if (!addStyleItems(styleObj, null, null, null, fileId, BUILDER_TYPE_SLOT, slotId, items, rules, cssConfig)) {
294
1306
  return null;
295
1307
  }
@@ -391,6 +1403,7 @@ function compileScopeMethod(
391
1403
  transform: StyleTransform | null,
392
1404
  options: CompilerOptions,
393
1405
  callsiteOverride: TraceCallsiteOverride = null,
1406
+ _selectorPrefix: ItemSelector | null = null,
394
1407
  ): boolean {
395
1408
  const selector = selectors[method.name];
396
1409
  if (!selector) return false;
@@ -549,10 +1562,10 @@ function compileScopeMethod(
549
1562
  cssConfig,
550
1563
  items,
551
1564
  cssRules,
552
- transform,
553
- options,
554
- callsiteOverride,
555
- )
1565
+ transform,
1566
+ options,
1567
+ callsiteOverride,
1568
+ )
556
1569
  ) {
557
1570
  return false;
558
1571
  }
@@ -674,7 +1687,7 @@ function resolveSlotOverrideNode(
674
1687
  if (node.type !== 'CallExpression') return false;
675
1688
 
676
1689
  // Extract the call chain to find the slot reference
677
- const overrideChain = extractOverrideChain(node, selectors, scope, fileId, transform, options);
1690
+ const overrideChain = extractOverrideChain(node, selectors, scope, fileId, cssConfig, transform, options);
678
1691
  if (!overrideChain) return false;
679
1692
 
680
1693
  const { slotId, items: overrideItems } = overrideChain;
@@ -685,7 +1698,7 @@ function resolveSlotOverrideNode(
685
1698
  const overrideItem = overrideItems[i];
686
1699
  const mergedAtRules = mergeAtRules(atRules, overrideItem.atRules);
687
1700
 
688
- if (overrideItem.chain && overrideItem.meta) {
1701
+ if (overrideItem.chain && overrideItem.meta?.mode === 'StyleObject') {
689
1702
  if (
690
1703
  !compileStyleChainInto(
691
1704
  overrideItem.chain,
@@ -768,6 +1781,7 @@ function extractOverrideChain(
768
1781
  selectors: SelectorsMap,
769
1782
  scope: EvalScope,
770
1783
  fileId: string,
1784
+ cssConfig: CssConfig,
771
1785
  transform: StyleTransform | null,
772
1786
  options: CompilerOptions,
773
1787
  ): OverrideChain | null {
@@ -783,7 +1797,7 @@ function extractOverrideChain(
783
1797
  const obj = callee.object;
784
1798
 
785
1799
  if (obj.type === 'CallExpression') {
786
- const inner = extractOverrideChain(obj, selectors, scope, fileId, transform, options);
1800
+ const inner = extractOverrideChain(obj, selectors, scope, fileId, cssConfig, transform, options);
787
1801
  if (!inner) return null;
788
1802
 
789
1803
  const overrideItem = resolveOverrideMethod(
@@ -792,6 +1806,7 @@ function extractOverrideChain(
792
1806
  callee.property as BabelTypes.Node,
793
1807
  selectors,
794
1808
  scope,
1809
+ cssConfig,
795
1810
  transform,
796
1811
  options,
797
1812
  );
@@ -813,7 +1828,7 @@ function extractOverrideChain(
813
1828
  const styleArg = evaluateNode(node.arguments[0] as BabelTypes.Node, scope);
814
1829
  if (!styleArg.ok) return null;
815
1830
  items.push({
816
- styleObj: applyTransform((styleArg.value as Record<string, unknown>) ?? {}, transform),
1831
+ styleObj: applyTransform((styleArg.value as Record<string, unknown>) ?? {}, transform, cssConfig),
817
1832
  selector: null,
818
1833
  atRules: null,
819
1834
  });
@@ -828,6 +1843,7 @@ function resolveOverrideMethod(
828
1843
  nameNode: BabelTypes.Node | undefined,
829
1844
  selectors: SelectorsMap,
830
1845
  scope: EvalScope,
1846
+ cssConfig: CssConfig,
831
1847
  transform: StyleTransform | null,
832
1848
  options: CompilerOptions,
833
1849
  ): OverrideItem | null {
@@ -867,7 +1883,7 @@ function resolveOverrideMethod(
867
1883
  }
868
1884
 
869
1885
  return {
870
- styleObj: applyTransform((styleArg.value as Record<string, unknown>) ?? {}, transform),
1886
+ styleObj: applyTransform((styleArg.value as Record<string, unknown>) ?? {}, transform, cssConfig),
871
1887
  selector: null,
872
1888
  atRules: null,
873
1889
  callsiteOverride,
@@ -901,7 +1917,7 @@ function resolveOverrideMethod(
901
1917
  const atRuleSelector: ItemSelector = priority !== null ? [atRule, priority] : atRule;
902
1918
 
903
1919
  return {
904
- styleObj: applyTransform(styleArg.value as Record<string, unknown>, transform),
1920
+ styleObj: applyTransform(styleArg.value as Record<string, unknown>, transform, cssConfig),
905
1921
  selector: null,
906
1922
  atRules: [atRuleSelector],
907
1923
  };
@@ -923,7 +1939,7 @@ function resolveOverrideMethod(
923
1939
  const itemSelector: ItemSelector = sel.priority !== null ? [selectorText, sel.priority] : selectorText;
924
1940
 
925
1941
  return {
926
- styleObj: applyTransform(styleArg.value as Record<string, unknown>, transform),
1942
+ styleObj: applyTransform(styleArg.value as Record<string, unknown>, transform, cssConfig),
927
1943
  selector: itemSelector,
928
1944
  atRules: null,
929
1945
  };
@@ -933,7 +1949,7 @@ function resolveOverrideMethod(
933
1949
  if (!styleArg.ok) return null;
934
1950
 
935
1951
  return {
936
- styleObj: applyTransform(styleArg.value as Record<string, unknown>, transform),
1952
+ styleObj: applyTransform(styleArg.value as Record<string, unknown>, transform, cssConfig),
937
1953
  selector: sel.priority !== null ? [selectorStr, sel.priority] : selectorStr,
938
1954
  atRules: null,
939
1955
  };
@@ -1042,6 +2058,7 @@ function compileChainMethod(
1042
2058
  styleNames: Set<string>,
1043
2059
  options: CompilerOptions,
1044
2060
  callsiteOverride: TraceCallsiteOverride = null,
2061
+ selectorPrefix: ItemSelector | null = null,
1045
2062
  ): boolean {
1046
2063
  if (method.name === STATIC_MERGE_METHOD) {
1047
2064
  const mergeCallsite = callsiteOverride ?? getMergeStyleCallsite(method.nameNode, scope, options);
@@ -1059,6 +2076,7 @@ function compileChainMethod(
1059
2076
  styleNames,
1060
2077
  options,
1061
2078
  mergeCallsite,
2079
+ selectorPrefix,
1062
2080
  );
1063
2081
  }
1064
2082
 
@@ -1084,6 +2102,7 @@ function compileChainMethod(
1084
2102
  styleNames,
1085
2103
  options,
1086
2104
  mergeCallsite,
2105
+ selectorPrefix,
1087
2106
  );
1088
2107
  }
1089
2108
 
@@ -1104,6 +2123,7 @@ function compileChainMethod(
1104
2123
  selectors,
1105
2124
  styleNames,
1106
2125
  options,
2126
+ selectorPrefix,
1107
2127
  );
1108
2128
  }
1109
2129
 
@@ -1122,23 +2142,25 @@ function compileChainMethod(
1122
2142
  transform,
1123
2143
  atRules,
1124
2144
  options,
2145
+ selectorPrefix,
1125
2146
  );
1126
2147
  }
1127
2148
 
1128
2149
  const itemSelector: ItemSelector = selector.priority !== null
1129
2150
  ? [selectorStr, selector.priority]
1130
2151
  : selectorStr;
2152
+ const compiledSelector = selectorPrefix ? combineSelectors(selectorPrefix, itemSelector) : itemSelector;
1131
2153
 
1132
2154
  const styleArg = evaluateNode(method.args[0], scope);
1133
2155
  if (!styleArg.ok) {
1134
2156
  throwIfRequiredStaticStyleValue(styleArg);
1135
2157
  return false;
1136
2158
  }
1137
- const styleObj = applyTransform(styleArg.value as Record<string, unknown>, transform);
2159
+ const styleObj = applyTransform(styleArg.value as Record<string, unknown>, transform, cssConfig);
1138
2160
 
1139
2161
  return addStyleItems(
1140
2162
  styleObj,
1141
- itemSelector,
2163
+ compiledSelector,
1142
2164
  null,
1143
2165
  atRules,
1144
2166
  fileId,
@@ -1165,13 +2187,14 @@ function compileMergeArg(
1165
2187
  styleNames: Set<string>,
1166
2188
  options: CompilerOptions,
1167
2189
  callsiteOverride: TraceCallsiteOverride = null,
2190
+ selectorPrefix: ItemSelector | null = null,
1168
2191
  ): boolean {
1169
2192
  if (!styleArgNode) return false;
1170
2193
  const styleCallsite = callsiteOverride ?? getMergeStyleCallsite(mergeNode, scope, options);
1171
2194
  const localChain = getLocalStyleChainArg(styleArgNode, scope, styleNames);
1172
2195
  const localMeta = localChain ? scope.styleMetas?.get(localChain.rootName) : null;
1173
2196
 
1174
- if ((styleCallsite || options.dev?.sourcemapMode === 'value') && localChain?.kind === 'style' && localMeta) {
2197
+ if (localChain?.kind === 'style' && localMeta) {
1175
2198
  return compileStyleChainInto(
1176
2199
  localChain,
1177
2200
  localMeta.selectors,
@@ -1187,6 +2210,7 @@ function compileMergeArg(
1187
2210
  styleNames,
1188
2211
  options,
1189
2212
  styleCallsite,
2213
+ selectorPrefix,
1190
2214
  );
1191
2215
  }
1192
2216
 
@@ -1210,6 +2234,7 @@ function compileMergeArg(
1210
2234
  styleNames,
1211
2235
  options,
1212
2236
  styleCallsite,
2237
+ selectorPrefix,
1213
2238
  );
1214
2239
  }
1215
2240
  }
@@ -1224,7 +2249,7 @@ function compileMergeArg(
1224
2249
  return addStyleDataSpreadItems(
1225
2250
  styleArg.value,
1226
2251
  styleArgNode,
1227
- null,
2252
+ selectorPrefix,
1228
2253
  null,
1229
2254
  atRules,
1230
2255
  fileId,
@@ -1239,7 +2264,7 @@ function compileMergeArg(
1239
2264
 
1240
2265
  return addStyleDataItems(
1241
2266
  styleArg.value,
1242
- null,
2267
+ selectorPrefix,
1243
2268
  null,
1244
2269
  atRules,
1245
2270
  fileId,
@@ -1256,13 +2281,114 @@ function getLocalStyleChainArg(
1256
2281
  node: BabelTypes.Node,
1257
2282
  scope: EvalScope,
1258
2283
  styleNames: Set<string>,
2284
+ sheetNames: Set<string> = new Set(),
1259
2285
  ) {
1260
2286
  if (node.type !== 'Identifier') return null;
1261
2287
 
1262
2288
  const init = scope.bindingNodes?.get(node.name);
1263
2289
  if (!init) return null;
1264
2290
 
1265
- return extractStyleChain(init, styleNames);
2291
+ return extractStyleChain(init, styleNames, sheetNames);
2292
+ }
2293
+
2294
+ function getLocalSelectorTargetChain(
2295
+ node: BabelTypes.CallExpression,
2296
+ scope: EvalScope,
2297
+ styleNames: Set<string>,
2298
+ sheetNames: Set<string>,
2299
+ ): StyleChainParseResult {
2300
+ const callee = node.callee;
2301
+
2302
+ if (callee.type === 'Identifier') {
2303
+ const target = getLocalStyleChainArg(callee, scope, styleNames, sheetNames);
2304
+ if (!isBareSelectorTargetChain(target)) return null;
2305
+
2306
+ return {
2307
+ ...target,
2308
+ baseArgs: [...target.baseArgs, ...(node.arguments as BabelTypes.Node[])],
2309
+ };
2310
+ }
2311
+
2312
+ if (callee.type !== 'MemberExpression' || callee.computed) return null;
2313
+
2314
+ const memberTarget = getLocalMemberStyleChainArg(callee, scope, styleNames, sheetNames);
2315
+ if (isBareSelectorTargetChain(memberTarget)) {
2316
+ return {
2317
+ ...memberTarget,
2318
+ baseArgs: [...memberTarget.baseArgs, ...(node.arguments as BabelTypes.Node[])],
2319
+ };
2320
+ }
2321
+
2322
+ const methodName = callee.property.type === 'Identifier'
2323
+ ? callee.property.name
2324
+ : callee.property.type === 'StringLiteral'
2325
+ ? callee.property.value
2326
+ : null;
2327
+
2328
+ if (!methodName) return null;
2329
+
2330
+ const object = callee.object;
2331
+ const target = object.type === 'Identifier'
2332
+ ? getLocalStyleChainArg(object, scope, styleNames, sheetNames)
2333
+ : object.type === 'MemberExpression'
2334
+ ? getLocalMemberStyleChainArg(object, scope, styleNames, sheetNames)
2335
+ : object.type === 'CallExpression'
2336
+ ? getLocalSelectorTargetChain(object, scope, styleNames, sheetNames)
2337
+ : null;
2338
+
2339
+ if (target?.kind !== 'selector') return null;
2340
+
2341
+ return {
2342
+ ...target,
2343
+ methods: [
2344
+ ...target.methods,
2345
+ { name: methodName, args: node.arguments as BabelTypes.Node[], nameNode: callee.property },
2346
+ ],
2347
+ };
2348
+ }
2349
+
2350
+ function getLocalMemberStyleChainArg(
2351
+ node: BabelTypes.MemberExpression,
2352
+ scope: EvalScope,
2353
+ styleNames: Set<string>,
2354
+ sheetNames: Set<string>,
2355
+ ) {
2356
+ if (node.computed || node.object.type !== 'Identifier') return null;
2357
+
2358
+ const propertyName = node.property.type === 'Identifier'
2359
+ ? node.property.name
2360
+ : node.property.type === 'StringLiteral'
2361
+ ? node.property.value
2362
+ : null;
2363
+
2364
+ if (!propertyName) return null;
2365
+
2366
+ const objectInit = scope.bindingNodes?.get(node.object.name);
2367
+ if (objectInit?.type !== 'ObjectExpression') return null;
2368
+
2369
+ for (let i = 0, len = objectInit.properties.length; i < len; i++) {
2370
+ const property = objectInit.properties[i];
2371
+ if (property.type !== 'ObjectProperty') continue;
2372
+
2373
+ const key = property.key;
2374
+ const keyName = key.type === 'Identifier'
2375
+ ? key.name
2376
+ : key.type === 'StringLiteral'
2377
+ ? key.value
2378
+ : null;
2379
+
2380
+ if (keyName !== propertyName) continue;
2381
+
2382
+ return extractStyleChain(property.value as BabelTypes.Node, styleNames, sheetNames);
2383
+ }
2384
+
2385
+ return null;
2386
+ }
2387
+
2388
+ function isBareSelectorTargetChain(
2389
+ chain: StyleChainParseResult,
2390
+ ): chain is NonNullable<StyleChainParseResult> {
2391
+ return chain?.kind === 'selector' && chain.baseArgs.length === 1 && chain.methods.length === 0;
1266
2392
  }
1267
2393
 
1268
2394
  function getLocalBindingNode(
@@ -1279,7 +2405,10 @@ function getMergeStyleCallsite(
1279
2405
  scope: EvalScope,
1280
2406
  options: CompilerOptions,
1281
2407
  ): TraceCallsiteOverride {
1282
- if (options.dev?.sourcemapMode !== 'style') return null;
2408
+ const sourcemapMode = options.dev?.sourcemapMode ?? (
2409
+ scope.runtimeMode === CompilerRuntimeMode.RscDev ? 'style' : null
2410
+ );
2411
+ if (sourcemapMode !== 'style') return null;
1283
2412
 
1284
2413
  const loc = node?.loc?.start;
1285
2414
  if (!loc) return null;
@@ -1325,6 +2454,7 @@ function compileAtRuleMethod(
1325
2454
  selectors: SelectorsMap,
1326
2455
  styleNames: Set<string>,
1327
2456
  options: CompilerOptions,
2457
+ selectorPrefix: ItemSelector | null = null,
1328
2458
  ): boolean {
1329
2459
  const isMedia = selectorStr.startsWith(SELECTOR_MEDIA) || selectorStr.startsWith(SELECTOR_CONTAINER);
1330
2460
  const hasArg = selectorStr.includes(SELECTOR_ARGS);
@@ -1379,6 +2509,8 @@ function compileAtRuleMethod(
1379
2509
  cssRules,
1380
2510
  styleNames,
1381
2511
  options,
2512
+ null,
2513
+ selectorPrefix,
1382
2514
  );
1383
2515
  }
1384
2516
  // Could not parse as chain — try to evaluate as static object
@@ -1388,8 +2520,8 @@ function compileAtRuleMethod(
1388
2520
  return false;
1389
2521
  }
1390
2522
  return addStyleItems(
1391
- applyTransform(evaled.value as Record<string, unknown>, transform),
1392
- null,
2523
+ applyTransform(evaled.value as Record<string, unknown>, transform, cssConfig),
2524
+ selectorPrefix,
1393
2525
  null,
1394
2526
  nextAtRules,
1395
2527
  fileId,
@@ -1408,8 +2540,8 @@ function compileAtRuleMethod(
1408
2540
  }
1409
2541
 
1410
2542
  return addStyleItems(
1411
- applyTransform(styleResult.value as Record<string, unknown>, transform),
1412
- null,
2543
+ applyTransform(styleResult.value as Record<string, unknown>, transform, cssConfig),
2544
+ selectorPrefix,
1413
2545
  null,
1414
2546
  nextAtRules,
1415
2547
  fileId,
@@ -1434,6 +2566,7 @@ function compileArgMethod(
1434
2566
  transform: StyleTransform | null,
1435
2567
  atRules: ItemSelector[] | null,
1436
2568
  options: CompilerOptions,
2569
+ selectorPrefix: ItemSelector | null = null,
1437
2570
  ): boolean {
1438
2571
  const selectorStr = selector.selector.trim();
1439
2572
  validateSelectorDefinition(options.dev?.checkSelector, `style.${method.name}`, selector, method.nameNode);
@@ -1459,7 +2592,7 @@ function compileArgMethod(
1459
2592
  ? selectorArg.value
1460
2593
  : [selectorArg.value];
1461
2594
 
1462
- const styleObj = applyTransform(styleResult.value as Record<string, unknown>, transform);
2595
+ const styleObj = applyTransform(styleResult.value as Record<string, unknown>, transform, cssConfig);
1463
2596
 
1464
2597
  let i = 0;
1465
2598
  while (i < selectorValues.length) {
@@ -1468,8 +2601,9 @@ function compileArgMethod(
1468
2601
  const compiledSelector: ItemSelector = selector.priority !== null
1469
2602
  ? [selectorText, selector.priority]
1470
2603
  : selectorText;
2604
+ const itemSelector = selectorPrefix ? combineSelectors(selectorPrefix, compiledSelector) : compiledSelector;
1471
2605
 
1472
- if (!addStyleItems(styleObj, compiledSelector, null, atRules, fileId, type, slotId, items, cssRules, cssConfig)) {
2606
+ if (!addStyleItems(styleObj, itemSelector, null, atRules, fileId, type, slotId, items, cssRules, cssConfig)) {
1473
2607
  return false;
1474
2608
  }
1475
2609
 
@@ -1612,6 +2746,8 @@ function addSlotOverrideDataItems(
1612
2746
  dedupe: overrideItem.dedupe,
1613
2747
  className: overrideItem.className,
1614
2748
  property: overrideItem.property,
2749
+ weight: overrideItem.weight,
2750
+ important: overrideItem.important,
1615
2751
  value: overrideItem.value,
1616
2752
  variable: overrideItem.variable,
1617
2753
  token: overrideItem.token,
@@ -1698,13 +2834,10 @@ function addRuntimeScopeItem(
1698
2834
  cssConfig: CssConfig,
1699
2835
  callsiteOverride: TraceCallsiteOverride = null,
1700
2836
  ) {
1701
- let priority: number | null = null;
2837
+ const weight = sourceItem.weight;
2838
+ let important = false;
1702
2839
  let value = sourceItem.value;
1703
-
1704
- if (Array.isArray(value)) {
1705
- priority = value[1];
1706
- value = value[0];
1707
- }
2840
+ important = sourceItem.important;
1708
2841
 
1709
2842
  const itemParentSelector = parentSelector ?? sourceItem.parentSelector;
1710
2843
  const itemAtRules = mergeAtRules(atRules, sourceItem.atRule);
@@ -1713,7 +2846,8 @@ function addRuntimeScopeItem(
1713
2846
 
1714
2847
  const dedupe = getClassNameDedupe(
1715
2848
  sourceItem.property,
1716
- priority,
2849
+ weight,
2850
+ important,
1717
2851
  sourceItem.selector,
1718
2852
  itemParentSelector,
1719
2853
  itemAtRules,
@@ -1721,7 +2855,8 @@ function addRuntimeScopeItem(
1721
2855
 
1722
2856
  const className = getAtomicClassName(
1723
2857
  sourceItem.property,
1724
- priority,
2858
+ weight,
2859
+ important,
1725
2860
  valueStr,
1726
2861
  sourceItem.selector,
1727
2862
  itemParentSelector,
@@ -1730,6 +2865,10 @@ function addRuntimeScopeItem(
1730
2865
  cssConfig.localClassName,
1731
2866
  cssConfig.debugClassName,
1732
2867
  cssConfig.classNameFormat,
2868
+ sourceItem.transformClassName ?? null,
2869
+ cssConfig.transformClassNameFormat,
2870
+ cssConfig.sheetClassNameFormat,
2871
+ cssConfig.hashLength,
1733
2872
  );
1734
2873
 
1735
2874
  const item: CompiledItem = createCompiledItem(
@@ -1746,6 +2885,7 @@ function addRuntimeScopeItem(
1746
2885
  className,
1747
2886
  sourceItem.property,
1748
2887
  valueStr,
2888
+ important,
1749
2889
  sourceItem.selector,
1750
2890
  itemParentSelector,
1751
2891
  itemAtRules,
@@ -1754,7 +2894,7 @@ function addRuntimeScopeItem(
1754
2894
 
1755
2895
  const layerPriority = getAtomicRuleLayerPriority(
1756
2896
  sourceItem.property,
1757
- priority,
2897
+ weight,
1758
2898
  sourceItem.selector,
1759
2899
  itemParentSelector,
1760
2900
  itemAtRules,
@@ -1766,6 +2906,7 @@ function addRuntimeScopeItem(
1766
2906
  className,
1767
2907
  css,
1768
2908
  priority: layerPriority,
2909
+ important,
1769
2910
  trace: traceCallsite
1770
2911
  ? {
1771
2912
  filePath: traceCallsite.filePath ?? fileId,
@@ -1921,15 +3062,13 @@ function addRuntimeStyleItem(
1921
3062
  cssConfig: CssConfig,
1922
3063
  callsiteOverride: TraceCallsiteOverride = null,
1923
3064
  ) {
1924
- let priority: number | null = null;
3065
+ const weight = sourceItem.weight;
3066
+ const important = sourceItem.important;
1925
3067
  let value = sourceItem.value;
1926
3068
 
1927
- if (Array.isArray(value)) {
1928
- priority = value[1];
1929
- value = value[0];
1930
- }
1931
-
1932
- const itemSelector = selector ?? sourceItem.selector;
3069
+ const itemSelector = selector && sourceItem.selector
3070
+ ? combineSelectors(selector, sourceItem.selector)
3071
+ : selector ?? sourceItem.selector;
1933
3072
  const itemAtRules = mergeAtRules(atRules, sourceItem.atRule);
1934
3073
  const variable = sourceItem.variable;
1935
3074
  const runtimeValue = variable?.[0] === ITEM_VALUE_TYPE_VARIABLE
@@ -1947,7 +3086,8 @@ function addRuntimeStyleItem(
1947
3086
 
1948
3087
  const dedupe = getClassNameDedupe(
1949
3088
  sourceItem.property,
1950
- priority,
3089
+ weight,
3090
+ important,
1951
3091
  itemSelector,
1952
3092
  parentSelector,
1953
3093
  itemAtRules,
@@ -1957,7 +3097,8 @@ function addRuntimeStyleItem(
1957
3097
 
1958
3098
  const className = getAtomicClassName(
1959
3099
  sourceItem.property,
1960
- priority,
3100
+ weight,
3101
+ important,
1961
3102
  valueStr,
1962
3103
  itemSelector,
1963
3104
  parentSelector,
@@ -1966,6 +3107,10 @@ function addRuntimeStyleItem(
1966
3107
  cssConfig.localClassName,
1967
3108
  cssConfig.debugClassName,
1968
3109
  cssConfig.classNameFormat,
3110
+ sourceItem.transformClassName ?? null,
3111
+ cssConfig.transformClassNameFormat,
3112
+ cssConfig.sheetClassNameFormat,
3113
+ cssConfig.hashLength,
1969
3114
  );
1970
3115
 
1971
3116
  const item: CompiledItem = createCompiledItem(
@@ -1988,6 +3133,7 @@ function addRuntimeStyleItem(
1988
3133
  className,
1989
3134
  sourceItem.property,
1990
3135
  valueStr,
3136
+ important,
1991
3137
  itemSelector,
1992
3138
  parentSelector,
1993
3139
  itemAtRules,
@@ -1996,7 +3142,7 @@ function addRuntimeStyleItem(
1996
3142
 
1997
3143
  const layerPriority = getAtomicRuleLayerPriority(
1998
3144
  sourceItem.property,
1999
- priority,
3145
+ weight,
2000
3146
  itemSelector,
2001
3147
  parentSelector,
2002
3148
  itemAtRules,
@@ -2008,6 +3154,7 @@ function addRuntimeStyleItem(
2008
3154
  className,
2009
3155
  css,
2010
3156
  priority: layerPriority,
3157
+ important,
2011
3158
  trace: traceCallsite
2012
3159
  ? {
2013
3160
  filePath: traceCallsite.filePath ?? fileId,
@@ -2018,6 +3165,26 @@ function addRuntimeStyleItem(
2018
3165
  });
2019
3166
  }
2020
3167
 
3168
+ function combineSelectors(
3169
+ parent: ItemSelector,
3170
+ child: ItemSelector,
3171
+ ): ItemSelector {
3172
+ const parentText = getItemSelectorText(parent);
3173
+ const childText = getItemSelectorText(child);
3174
+ const priority = Math.max(getItemSelectorPriority(parent), getItemSelectorPriority(child));
3175
+ const selector = parentText + childText;
3176
+
3177
+ return priority > 0 ? [selector, priority] : selector;
3178
+ }
3179
+
3180
+ function getItemSelectorText(selector: ItemSelector) {
3181
+ return Array.isArray(selector) ? selector[0] : selector;
3182
+ }
3183
+
3184
+ function getItemSelectorPriority(selector: ItemSelector) {
3185
+ return Array.isArray(selector) ? selector[1] : 0;
3186
+ }
3187
+
2021
3188
  function getRuntimeStyleItemSourceTrace(
2022
3189
  item: RuntimeStyleItem,
2023
3190
  fileId: string,
@@ -2099,12 +3266,16 @@ function addStyleItems(
2099
3266
  const property = keys[i];
2100
3267
  const rawValue = styleObj[property];
2101
3268
 
2102
- let priority: number | null = null;
3269
+ let weight: number | null = null;
3270
+ let important = false;
2103
3271
  let value: unknown = rawValue;
3272
+ let transformClassName: string | null = null;
2104
3273
 
2105
- if (Array.isArray(rawValue) && rawValue.length === 2 && typeof rawValue[0] === 'number') {
2106
- priority = rawValue[0];
2107
- value = rawValue[1];
3274
+ [value, weight, important] = unwrapStaticStyleValue(value);
3275
+
3276
+ if (isClassNameValue(value)) {
3277
+ transformClassName = value.className;
3278
+ value = value.value;
2108
3279
  }
2109
3280
 
2110
3281
  if (value === null || value === undefined) {
@@ -2132,11 +3303,17 @@ function addStyleItems(
2132
3303
 
2133
3304
  const shouldUseVariable = !!(token || runtimeValue);
2134
3305
 
2135
- const variableName = shouldUseVariable && propertyLoc
3306
+ const variableName = shouldUseVariable && propertyLoc && propertyLoc.variable !== false
2136
3307
  ? getLocalVarName(
2137
- propertyLoc.filePath ?? fileId,
2138
- propertyLoc.line,
2139
- propertyLoc.column,
3308
+ cssConfig.runtimeMode === CompilerRuntimeMode.RscDev
3309
+ ? fileId
3310
+ : propertyLoc.filePath ?? fileId,
3311
+ cssConfig.runtimeMode === CompilerRuntimeMode.RscDev
3312
+ ? propertyLoc.variableLine ?? propertyLoc.line
3313
+ : propertyLoc.line,
3314
+ cssConfig.runtimeMode === CompilerRuntimeMode.RscDev
3315
+ ? propertyLoc.variableColumn ?? propertyLoc.column
3316
+ : propertyLoc.column,
2140
3317
  cssConfig.tokenNameFormat,
2141
3318
  )
2142
3319
  : null;
@@ -2151,7 +3328,8 @@ function addStyleItems(
2151
3328
 
2152
3329
  const dedupe = getClassNameDedupe(
2153
3330
  property,
2154
- priority,
3331
+ weight,
3332
+ important,
2155
3333
  selector,
2156
3334
  parentSelector,
2157
3335
  atRules,
@@ -2159,7 +3337,8 @@ function addStyleItems(
2159
3337
 
2160
3338
  const className = getAtomicClassName(
2161
3339
  property,
2162
- priority,
3340
+ weight,
3341
+ important,
2163
3342
  valueStr,
2164
3343
  selector,
2165
3344
  parentSelector,
@@ -2168,6 +3347,10 @@ function addStyleItems(
2168
3347
  cssConfig.localClassName,
2169
3348
  cssConfig.debugClassName,
2170
3349
  cssConfig.classNameFormat,
3350
+ transformClassName,
3351
+ cssConfig.transformClassNameFormat,
3352
+ cssConfig.sheetClassNameFormat,
3353
+ cssConfig.hashLength,
2171
3354
  );
2172
3355
 
2173
3356
  const item: CompiledItem = createCompiledItem(
@@ -2214,6 +3397,7 @@ function addStyleItems(
2214
3397
  className,
2215
3398
  property,
2216
3399
  valueStr,
3400
+ important,
2217
3401
  selector,
2218
3402
  parentSelector,
2219
3403
  atRules,
@@ -2222,7 +3406,7 @@ function addStyleItems(
2222
3406
 
2223
3407
  const layerPriority = getAtomicRuleLayerPriority(
2224
3408
  property,
2225
- priority,
3409
+ weight,
2226
3410
  selector,
2227
3411
  parentSelector,
2228
3412
  atRules,
@@ -2234,6 +3418,7 @@ function addStyleItems(
2234
3418
  className,
2235
3419
  css,
2236
3420
  priority: layerPriority,
3421
+ important,
2237
3422
  trace: propertyCallsite
2238
3423
  ? {
2239
3424
  filePath: propertyCallsite.filePath ?? fileId,
@@ -2266,6 +3451,29 @@ function addStyleItems(
2266
3451
  return true;
2267
3452
  }
2268
3453
 
3454
+ function unwrapStaticStyleValue(value: unknown): [value: unknown, weight: number | null, important: boolean] {
3455
+ let weight: number | null = null;
3456
+ let important = false;
3457
+
3458
+ while (true) {
3459
+ if (isStyleImportantValue(value)) {
3460
+ important = true;
3461
+ value = value.value;
3462
+ continue;
3463
+ }
3464
+
3465
+ if (isStyleWeightValue(value)) {
3466
+ weight = value.weight;
3467
+ value = value.value;
3468
+ continue;
3469
+ }
3470
+
3471
+ break;
3472
+ }
3473
+
3474
+ return [value, weight, important];
3475
+ }
3476
+
2269
3477
  function throwIfRequiredStaticStyleValue(result: EvalResult) {
2270
3478
  if (result.ok) return;
2271
3479
  if (