@fluentic/style 0.1.0-beta.12 → 0.1.0-beta.14

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 (229) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/README.md +3 -2
  3. package/atomic/layer/layer.ts +7 -3
  4. package/atomic/token.ts +10 -1
  5. package/builder/data/data.ts +1 -1
  6. package/builder/extract/token.ts +10 -0
  7. package/builder/selector_override_core.ts +7 -1
  8. package/compiler/extract/extract.ts +14 -9
  9. package/compiler/extract/types.ts +2 -1
  10. package/compiler/transform/evaluator/evaluator.ts +83 -9
  11. package/compiler/transform/evaluator/tracer.ts +4 -0
  12. package/compiler/transform/extract/chain/chain.ts +7 -4
  13. package/compiler/transform/extract/chain/extract_chain.ts +14 -0
  14. package/compiler/transform/extract/plugin.ts +30 -4
  15. package/compiler/transform/extract/utils/imports.ts +5 -1
  16. package/compiler/transform/extract/utils/replacement.ts +21 -4
  17. package/compiler/transform/extract/utils/state.ts +2 -0
  18. package/compiler/transform/extract/utils/token.ts +107 -0
  19. package/compiler/utils/constants.ts +1 -0
  20. package/config/config/css.ts +19 -0
  21. package/css/sheet.ts +3 -2
  22. package/dialect/namedTokens.ts +13 -8
  23. package/dist/{combine-Bww7VnSr.js → combine-CC9bY-hu.js} +2 -2
  24. package/dist/{combine-Bww7VnSr.js.map → combine-CC9bY-hu.js.map} +1 -1
  25. package/dist/compiler/index.mjs +1 -1
  26. package/dist/{compiler-mCfMhtX4.mjs → compiler-Ct5xGIeu.mjs} +197 -37
  27. package/dist/compiler-Ct5xGIeu.mjs.map +1 -0
  28. package/dist/config/index.js +2 -2
  29. package/dist/{config-DNEnHEf3.js → config-BiiMS4rU.js} +3 -3
  30. package/dist/{config-DNEnHEf3.js.map → config-BiiMS4rU.js.map} +1 -1
  31. package/dist/{config-CDjbHwb-.js → config-CCgsVvyR.js} +2 -2
  32. package/dist/{config-CDjbHwb-.js.map → config-CCgsVvyR.js.map} +1 -1
  33. package/dist/{config-C5VWvTav.js → config-DZKR6gH1.js} +4 -4
  34. package/dist/{config-C5VWvTav.js.map → config-DZKR6gH1.js.map} +1 -1
  35. package/dist/{config-BKP5LOkt.js → config-TyjNpRrV.js} +2 -2
  36. package/dist/{config-BKP5LOkt.js.map → config-TyjNpRrV.js.map} +1 -1
  37. package/dist/{createTransformElement-D8fXZ3wA.js → createTransformElement-BGznW-Mu.js} +2 -2
  38. package/dist/{createTransformElement-D8fXZ3wA.js.map → createTransformElement-BGznW-Mu.js.map} +1 -1
  39. package/dist/{css-BDn0epJ8.js → css-BhoclXaw.js} +7 -7
  40. package/dist/css-BhoclXaw.js.map +1 -0
  41. package/dist/{css-DEYgrj76.js → css-IecKRNxs.js} +13 -13
  42. package/dist/css-IecKRNxs.js.map +1 -0
  43. package/dist/{css-CFxNrYt3.js → css-WaHZ6gxv.js} +46 -21
  44. package/dist/css-WaHZ6gxv.js.map +1 -0
  45. package/dist/css.js +1 -1
  46. package/dist/{css_extra-nTq_Gw0E.js → css_extra-DDeJc2Cu.js} +2 -2
  47. package/dist/{css_extra-nTq_Gw0E.js.map → css_extra-DDeJc2Cu.js.map} +1 -1
  48. package/dist/{data-CDrS1Bq4.js → data-BgZmL55Y.js} +7 -8
  49. package/dist/{data-CDrS1Bq4.js.map → data-BgZmL55Y.js.map} +1 -1
  50. package/dist/{debug-BkVbf0Cz.js → debug-D-1hhd0G.js} +27 -3
  51. package/dist/debug-D-1hhd0G.js.map +1 -0
  52. package/dist/dev/rsc.js +7 -7
  53. package/dist/dev/rsc.js.map +1 -1
  54. package/dist/{dev-0imWmSVb.js → dev-CBRbVaeq.js} +6 -7
  55. package/dist/{dev-0imWmSVb.js.map → dev-CBRbVaeq.js.map} +1 -1
  56. package/dist/dev.js +1 -1
  57. package/dist/dialect/extracted/index.js +1 -1
  58. package/dist/dialect/index.js +1 -1
  59. package/dist/{elementMarker-kvpMjB49.js → elementMarker-CJcfpKL1.js} +35 -22
  60. package/dist/elementMarker-CJcfpKL1.js.map +1 -0
  61. package/dist/entry/dev/adapter/preact.js +1 -1
  62. package/dist/entry/dev/adapter/react.js +1 -1
  63. package/dist/entry/dev/adapter/solid.js +1 -1
  64. package/dist/entry/dev/css.js +2 -2
  65. package/dist/entry/dev/jsx-dev-runtime.js +2 -2
  66. package/dist/entry/dev/jsx-runtime.js +2 -2
  67. package/dist/entry/dev.js +11 -11
  68. package/dist/entry/prod/css.js +2 -2
  69. package/dist/entry/prod/extract.js +10 -1
  70. package/dist/entry/prod/extract.js.map +1 -1
  71. package/dist/entry/prod.js +2 -2
  72. package/dist/entry/rsc-dev/adapter/preact.js +1 -1
  73. package/dist/entry/rsc-dev/adapter/react.js +1 -1
  74. package/dist/entry/rsc-dev/adapter/solid.js +1 -1
  75. package/dist/entry/rsc-dev/css.js +2 -2
  76. package/dist/entry/rsc-dev/dev.js +6 -6
  77. package/dist/entry/rsc-dev/dev.js.map +1 -1
  78. package/dist/entry/rsc-dev/jsx-dev-runtime.js +2 -2
  79. package/dist/entry/rsc-dev/jsx-runtime.js +2 -2
  80. package/dist/entry/rsc-dev.js +5 -5
  81. package/dist/entry/rsc-prod/css.js +2 -2
  82. package/dist/entry/rsc-prod.js +12 -3
  83. package/dist/entry/rsc-prod.js.map +1 -1
  84. package/dist/{env-Cz8frh6e.js → env-C8TRVSyb.js} +44 -19
  85. package/dist/env-C8TRVSyb.js.map +1 -0
  86. package/dist/getClassName-9CsXbNls.js.map +1 -1
  87. package/dist/{getClassName-DGm-VNDo.js → getClassName-BNe3Ycyy.js} +4 -5
  88. package/dist/{getClassName-DGm-VNDo.js.map → getClassName-BNe3Ycyy.js.map} +1 -1
  89. package/dist/{getClassName-Dtc4yyYI.js → getClassName-CeoxISNW.js} +4 -4
  90. package/dist/{getClassName-Dtc4yyYI.js.map → getClassName-CeoxISNW.js.map} +1 -1
  91. package/dist/getClassName-DtkplEIt.js.map +1 -1
  92. package/dist/{global-CAc9OjKx.js → global-CWYOol4o.js} +2 -2
  93. package/dist/{global-CAc9OjKx.js.map → global-CWYOol4o.js.map} +1 -1
  94. package/dist/global-UOHFwqHN.js +33 -0
  95. package/dist/global-UOHFwqHN.js.map +1 -0
  96. package/dist/{debug-YuhEIQVO.js → hash-DlXmmPPm.js} +167 -5
  97. package/dist/hash-DlXmmPPm.js.map +1 -0
  98. package/dist/index.js +9 -9
  99. package/dist/jsx/jsx-dev-runtime.js +1 -1
  100. package/dist/jsx/jsx-dev-runtime.server.js +1 -1
  101. package/dist/jsx/jsx-runtime.js +1 -1
  102. package/dist/jsx/jsx-runtime.server.js +1 -1
  103. package/dist/{jsx-CVxpkS04.js → jsx-8TwYuvgM.js} +4 -4
  104. package/dist/{jsx-CVxpkS04.js.map → jsx-8TwYuvgM.js.map} +1 -1
  105. package/dist/{jsx_runtime-6Qa1lmz2.js → jsx_runtime-CPojW0KD.js} +2 -2
  106. package/dist/{jsx_runtime-6Qa1lmz2.js.map → jsx_runtime-CPojW0KD.js.map} +1 -1
  107. package/dist/{loader-DUS2i9Zb.mjs → loader-BVebGteg.mjs} +3 -3
  108. package/dist/{loader-DUS2i9Zb.mjs.map → loader-BVebGteg.mjs.map} +1 -1
  109. package/dist/{misc-vGtt_SX7.mjs → misc-Bs2DgdG7.mjs} +2 -2
  110. package/dist/{misc-vGtt_SX7.mjs.map → misc-Bs2DgdG7.mjs.map} +1 -1
  111. package/dist/{namedTokens-5AayGokX.js → namedTokens-CwniouKk.js} +13 -9
  112. package/dist/namedTokens-CwniouKk.js.map +1 -0
  113. package/dist/plugin/farm/index.mjs +3 -3
  114. package/dist/plugin/nextjs/index.mjs +4 -4
  115. package/dist/plugin/nextjs/loader.mjs +4 -4
  116. package/dist/plugin/parcel/index.cjs +1 -1
  117. package/dist/plugin/parcel/index.mjs +2 -2
  118. package/dist/plugin/parcel/optimizer.cjs +1 -1
  119. package/dist/plugin/parcel/optimizer.mjs +2 -2
  120. package/dist/plugin/parcel/resolver.cjs +1 -1
  121. package/dist/plugin/parcel/resolver.mjs +2 -2
  122. package/dist/plugin/parcel/runtime.cjs +1 -1
  123. package/dist/plugin/parcel/runtime.mjs +1 -1
  124. package/dist/plugin/parcel/transformer.cjs +1 -1
  125. package/dist/plugin/parcel/transformer.mjs +2 -2
  126. package/dist/plugin/rspack/index.mjs +2 -2
  127. package/dist/plugin/vite/index.mjs +3 -3
  128. package/dist/plugin/webpack/index.mjs +2 -2
  129. package/dist/plugin/webpack/loader.mjs +2 -2
  130. package/dist/presets/tailwind/index.js +3 -3
  131. package/dist/{registry-BJqMbdMu.mjs → registry-D1n78rd7.mjs} +2 -2
  132. package/dist/{registry-BJqMbdMu.mjs.map → registry-D1n78rd7.mjs.map} +1 -1
  133. package/dist/{resolveClassNameRuntime-CJjlUP93.js → resolveClassNameRuntime-BJcykzdl.js} +2 -2
  134. package/dist/{resolveClassNameRuntime-CJjlUP93.js.map → resolveClassNameRuntime-BJcykzdl.js.map} +1 -1
  135. package/dist/{rules-DaMaMHgb.js → rules-Dz-szpPu.js} +8 -9
  136. package/dist/{rules-DaMaMHgb.js.map → rules-Dz-szpPu.js.map} +1 -1
  137. package/dist/server.js +13 -13
  138. package/dist/{shared-BRUPuZdH.cjs → shared-C9XQd8p_.cjs} +197 -37
  139. package/dist/shared-C9XQd8p_.cjs.map +1 -0
  140. package/dist/{shared-DDzZd0tM.mjs → shared-D4-AKGn6.mjs} +4 -4
  141. package/dist/{shared-DDzZd0tM.mjs.map → shared-D4-AKGn6.mjs.map} +1 -1
  142. package/dist/sheet-LU89fcH_.js +7 -0
  143. package/dist/{sheet-CxkO1Hwt.js.map → sheet-LU89fcH_.js.map} +1 -1
  144. package/dist/{sidecar-BTT0veLU.mjs → sidecar-CZTYX2vA.mjs} +3 -3
  145. package/dist/{sidecar-BTT0veLU.mjs.map → sidecar-CZTYX2vA.mjs.map} +1 -1
  146. package/dist/{style-CAhAnRni.js → style-CmXHCPF4.js} +10 -11
  147. package/dist/{style-CAhAnRni.js.map → style-CmXHCPF4.js.map} +1 -1
  148. package/dist/{styleStore-DaIJ4OPV.js → styleStore-B0x4Ahpx.js} +9 -7
  149. package/dist/styleStore-B0x4Ahpx.js.map +1 -0
  150. package/dist/{styleStore-BzLZwpwy.js → styleStore-BrpgLNgc.js} +6 -4
  151. package/dist/styleStore-BrpgLNgc.js.map +1 -0
  152. package/dist/{token-D33mKTka.js → token-DMrBbat8.js} +5 -33
  153. package/dist/token-DMrBbat8.js.map +1 -0
  154. package/dist/{trace-B3dpTRJp.js → trace-C7EzEj2Q.js} +3 -3
  155. package/dist/{trace-B3dpTRJp.js.map → trace-C7EzEj2Q.js.map} +1 -1
  156. package/dist/{trace-c2WmBbmX.js → trace-DzCntvK4.js} +2 -2
  157. package/dist/{trace-c2WmBbmX.js.map → trace-DzCntvK4.js.map} +1 -1
  158. package/dist/{transform-DSpimwwC.js → transform-CSZMklMb.js} +2 -2
  159. package/dist/{transform-DSpimwwC.js.map → transform-CSZMklMb.js.map} +1 -1
  160. package/dist/types/builder/data/data.d.ts +1 -1
  161. package/dist/types/builder/data/merge/utils.d.ts +6 -1
  162. package/dist/types/builder/data/state.d.ts +16 -2
  163. package/dist/types/builder/extract/token.d.ts +6 -1
  164. package/dist/types/builder/style_fns.d.ts +1 -1
  165. package/dist/types/builder/utils.d.ts +1 -1
  166. package/dist/types/compiler/extract/types.d.ts +2 -1
  167. package/dist/types/compiler/transform/evaluator/evaluator.d.ts +18 -1
  168. package/dist/types/compiler/transform/extract/utils/replacement.d.ts +2 -0
  169. package/dist/types/compiler/transform/extract/utils/state.d.ts +1 -0
  170. package/dist/types/compiler/transform/extract/utils/token.d.ts +3 -0
  171. package/dist/types/compiler/utils/constants.d.ts +1 -0
  172. package/dist/types/compiler/utils/import_source.d.ts +8 -2
  173. package/dist/types/config/config/css.d.ts +5 -0
  174. package/dist/types/plugin/bundler/farm/plugin.d.ts +8 -2
  175. package/dist/types/presets/tailwind/selectors.d.ts +24 -24
  176. package/dist/types/presets/tailwind/theme.d.ts +361 -361
  177. package/dist/types/runtime/core/cache/itemWithResolver.d.ts +1 -1
  178. package/dist/types/runtime/core/cache/stateItem.d.ts +8 -2
  179. package/dist/types/runtime/types.d.ts +4 -1
  180. package/dist/types/selector/presets/default.d.ts +28 -28
  181. package/dist/types/selector/presets/minimal.d.ts +10 -10
  182. package/dist/types/selector/selector.d.ts +15 -2
  183. package/dist/types/sheet/types.d.ts +2 -1
  184. package/dist/types/sheet/utils/layer.d.ts +1 -1
  185. package/dist/types/style/style.d.ts +93 -93
  186. package/dist/{utils-DZK0mfmY.js → utils-B7QcJ-Yw.js} +3 -3
  187. package/dist/{utils-DZK0mfmY.js.map → utils-B7QcJ-Yw.js.map} +1 -1
  188. package/dist/{utils-D4UympcZ.mjs → utils-BYpkJ-uE.mjs} +3 -3
  189. package/dist/{utils-D4UympcZ.mjs.map → utils-BYpkJ-uE.mjs.map} +1 -1
  190. package/dist/{utils-D75HPJWv.mjs → utils-CoMwEfhG.mjs} +4 -4
  191. package/dist/{utils-D75HPJWv.mjs.map → utils-CoMwEfhG.mjs.map} +1 -1
  192. package/dist/{utils-H1VInWpd.js → utils-D4KMqCu2.js} +37 -16
  193. package/dist/utils-D4KMqCu2.js.map +1 -0
  194. package/dist/utils.js +3 -3
  195. package/dist/{value-CK0-Xbov.js → value-yd2SZ1XQ.js} +37 -3
  196. package/dist/value-yd2SZ1XQ.js.map +1 -0
  197. package/dist/{webpack-_BpgAUEy.mjs → webpack-B6z1UHh9.mjs} +5 -5
  198. package/dist/{webpack-_BpgAUEy.mjs.map → webpack-B6z1UHh9.mjs.map} +1 -1
  199. package/package.json +5 -4
  200. package/runtime/extract/getClassName.ts +1 -1
  201. package/runtime/rsc/observer.ts +4 -1
  202. package/runtime/rsc/styleStore.ts +6 -2
  203. package/runtime/sheet/rule.ts +2 -2
  204. package/sheet/dev/dev_layer.ts +7 -3
  205. package/sheet/dev/dev_sort.ts +18 -11
  206. package/sheet/prod.ts +7 -3
  207. package/sheet/types.ts +2 -1
  208. package/sheet/utils/layer.ts +2 -1
  209. package/style/token.ts +2 -0
  210. package/dist/compiler-mCfMhtX4.mjs.map +0 -1
  211. package/dist/css-BDn0epJ8.js.map +0 -1
  212. package/dist/css-CFxNrYt3.js.map +0 -1
  213. package/dist/css-DEYgrj76.js.map +0 -1
  214. package/dist/css-DWBWsyxZ.js +0 -50
  215. package/dist/css-DWBWsyxZ.js.map +0 -1
  216. package/dist/debug-BkVbf0Cz.js.map +0 -1
  217. package/dist/debug-YuhEIQVO.js.map +0 -1
  218. package/dist/elementMarker-kvpMjB49.js.map +0 -1
  219. package/dist/env-Cz8frh6e.js.map +0 -1
  220. package/dist/hash-Cr-LCWDt.js +0 -166
  221. package/dist/hash-Cr-LCWDt.js.map +0 -1
  222. package/dist/namedTokens-5AayGokX.js.map +0 -1
  223. package/dist/shared-BRUPuZdH.cjs.map +0 -1
  224. package/dist/sheet-CxkO1Hwt.js +0 -7
  225. package/dist/styleStore-BzLZwpwy.js.map +0 -1
  226. package/dist/styleStore-DaIJ4OPV.js.map +0 -1
  227. package/dist/token-D33mKTka.js.map +0 -1
  228. package/dist/utils-H1VInWpd.js.map +0 -1
  229. package/dist/value-CK0-Xbov.js.map +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # @fluentic/style
2
2
 
3
+ ## 0.1.0-beta.14
4
+
5
+ ### Patch Changes
6
+
7
+ - Compile token factories at their definitions and preserve token references in extracted styles. Token groups become nested objects of extracted token leaves; value scales use a small precompiled lookup helper. Standalone getToken calls now receive CSS-variable metadata, including values imported through re-exports.
8
+
9
+ Named tokens now use global, hash-free CSS variable names derived from their explicit namespace and property path, independent of tokenNameFormat and hashLength. Rebuild all consumers together and update external CSS references to the new names. Path segments escape punctuation to avoid collisions.
10
+
11
+ - Use native TypeScript 7.0.2 for workspace checks and declaration emission, with TypeScript 6.0.2 API compatibility for tooling. Validate packed declarations with both TypeScript 5.9 and 7.
12
+
13
+ ## 0.1.0-beta.13
14
+
15
+ ### Patch Changes
16
+
17
+ - Allow individual `createSheet` calls to select named cascade layers. Absolute names such as `reset` are used as written; names beginning with `.` are prefixed with `css.layerNamespace`. Preserve selector scoping and boolean options across compiler extraction, browser runtime, and server rendering. Explicit entries in `css.layers` control named layer order without duplicates at `$layer`.
18
+
19
+ Fix compiler extraction of inline curried selector calls such as `style.selector('h1')({ fontSize: '1.5rem' })`, including chained conditions. Prefer the direct second-argument form for inline styles; both forms remain supported.
20
+
21
+ Add scoped reset documentation and packed declaration consumer checks for string layer options. Use Node's URL type explicitly in Node-only test/build files to keep release validation compatible with the installed Node declarations.
22
+
3
23
  ## 0.1.0-beta.12
4
24
 
5
25
  ### Patch Changes
package/README.md CHANGED
@@ -455,8 +455,9 @@ production builds. Current benchmark snapshots:
455
455
  The main production checks are runtime cost and bundle size. In the production
456
456
  path most apps use, Fluentic extracts CSS at build time and ships the extracted
457
457
  production runtime for `css` prop composition, dynamic values, class-name
458
- merging, and token resolution. That runtime entry currently reports `4.92 KB`
459
- min+gzip.
458
+ merging, and token resolution. The measured runtime surface reports `4.98 KiB`
459
+ (5,097 bytes) min+gzip in the refreshed beta.14 report; generated helpers and the optional JSX/dialect surfaces are
460
+ reported separately.
460
461
  Browser and SSR benchmarks track whether style resolution stays fast in
461
462
  app-shaped renders. See the
462
463
  [Bundle Size](https://fluenticstack.com/style/docs/benchmark/bundle-size/),
@@ -89,7 +89,11 @@ export function flattenCssLayers(
89
89
  ? [layerNames]
90
90
  : layerNames;
91
91
 
92
- return layers
93
- .flatMap((layer) => layer === LayerPlaceholder ? names : layer)
94
- .filter(Boolean);
92
+ return [
93
+ ...new Set(
94
+ layers
95
+ .flatMap((layer) => layer === LayerPlaceholder ? names.filter((name) => !layers.includes(name)) : layer)
96
+ .filter(Boolean),
97
+ ),
98
+ ];
95
99
  }
package/atomic/token.ts CHANGED
@@ -1,6 +1,12 @@
1
1
  import { CSS_CONFIG } from '../config/config/css';
2
2
  import type { TokenNameFormat, TokenNameInfo } from '../config/types';
3
- import { getStyleTokenId, getStyleTokenName, type StyleTokenData, type StyleTokenOverride } from '../style/token';
3
+ import {
4
+ getStyleTokenId,
5
+ getStyleTokenName,
6
+ getStyleTokenVarName,
7
+ type StyleTokenData,
8
+ type StyleTokenOverride,
9
+ } from '../style/token';
4
10
  import { getCssVar, getCssVarRawFallback } from './utils/cssVar';
5
11
  import { createNameFormatter } from './utils/format';
6
12
  import { getIdentifierSafeHash } from './utils/hash';
@@ -13,6 +19,9 @@ export function getTokenVarName(
13
19
  token: StyleTokenData | StyleTokenOverride,
14
20
  format: TokenNameFormat | null,
15
21
  ) {
22
+ const explicitName = getStyleTokenVarName(token);
23
+ if (explicitName) return explicitName;
24
+
16
25
  const id = getStyleTokenId(token);
17
26
  const debugName = getStyleTokenName(token);
18
27
 
@@ -65,7 +65,7 @@ export type SheetData<Style = unknown> =
65
65
  & { [BUILDER_SHEET_OPTIONS]: CreateSheetOptions; };
66
66
 
67
67
  export type CreateSheetOptions = {
68
- layer?: boolean;
68
+ layer?: boolean | string;
69
69
  weight?: number;
70
70
  };
71
71
 
@@ -55,3 +55,13 @@ function isExtractedTokenRef(value: unknown): value is StyleTokenData {
55
55
  typeof (value as StyleTokenData)[TOKEN_ID] === 'string' &&
56
56
  (value as { [TOKEN_OVERRIDE]?: true; })[TOKEN_OVERRIDE] !== true;
57
57
  }
58
+
59
+ /** A compiled value scale: parsing and CSS variable naming happen in the compiler. */
60
+ export function createExtractedValues(entries: readonly (readonly [string | number, StyleToken<unknown>])[]) {
61
+ const tokens = new Map(entries);
62
+ return function(key: string | number, value?: unknown) {
63
+ const token = tokens.get(key);
64
+ if (!token) throw new Error(`[Style.values] VALUE_NOT_FOUND: ${String(key)}`);
65
+ return arguments.length >= 2 ? token(value) : token;
66
+ };
67
+ }
@@ -49,7 +49,13 @@ export function setSheetSelectorOptions(selector: ItemSelector, options: CreateS
49
49
 
50
50
  const text = Array.isArray(selector) ? selector[0] : selector;
51
51
  const optionMarker = ':' + (options.weight ?? '') + ':' + (
52
- options.layer === undefined ? '' : options.layer ? '1' : '0'
52
+ typeof options.layer === 'string'
53
+ ? JSON.stringify(options.layer)
54
+ : options.layer === undefined
55
+ ? ''
56
+ : options.layer
57
+ ? '1'
58
+ : '0'
53
59
  );
54
60
  const weighted = SHEET_SELECTOR_ANCHOR + optionMarker + '\0' + text.slice(SHEET_SELECTOR_ANCHOR.length);
55
61
 
@@ -26,9 +26,10 @@ function getExtractedCssItems(
26
26
  const css: CssExtractRule[] = [];
27
27
 
28
28
  for (const item of sortedItems) {
29
- if (seen.has(item.css)) continue;
29
+ const key = JSON.stringify([item.layer, item.css]);
30
+ if (seen.has(key)) continue;
30
31
 
31
- seen.add(item.css);
32
+ seen.add(key);
32
33
  css.push(item);
33
34
  }
34
35
 
@@ -41,13 +42,16 @@ function getExtractedCssItems(
41
42
  const styleLayer = isStyleLayerEnabled(args.layer ?? defaults.layer);
42
43
  const sheetLayerName = layerNamespace ? layerNamespace + '.sheet' : 'sheet';
43
44
  const styleItems: string[] = [];
44
- const sheetItems: string[] = [];
45
+ const sheetItems = new Map<string, string[]>();
45
46
  const unlayeredItems: string[] = [];
46
47
 
47
48
  for (let i = 0, len = css.length; i < len; i++) {
48
49
  const item = css[i];
49
- if (item.layer === 'sheet') {
50
- sheetItems.push(item.css);
50
+ if (item.layer === 'sheet' || typeof item.layer === 'object') {
51
+ const name = typeof item.layer === 'object' ? item.layer.name : sheetLayerName;
52
+ const rules = sheetItems.get(name) ?? [];
53
+ rules.push(item.css);
54
+ sheetItems.set(name, rules);
51
55
  } else if (item.layer === false || !styleLayer) {
52
56
  unlayeredItems.push(item.css);
53
57
  } else {
@@ -55,13 +59,14 @@ function getExtractedCssItems(
55
59
  }
56
60
  }
57
61
 
58
- const styleLayerName = sheetItems.length && layerNamespace
62
+ const hasNestedSheetLayer = [...sheetItems.keys()].some((name) => name.startsWith(layerNamespace + '.'));
63
+ const styleLayerName = hasNestedSheetLayer && layerNamespace
59
64
  ? layerNamespace + '.style'
60
65
  : layerNamespace;
61
66
 
62
67
  const layerNames = [
63
68
  styleItems.length ? styleLayerName : '',
64
- sheetItems.length ? sheetLayerName : '',
69
+ ...sheetItems.keys(),
65
70
  ].filter(Boolean);
66
71
  const output: string[] = [];
67
72
  const layerOrder = getLayerOrderCss(layers, layerNames);
@@ -70,8 +75,8 @@ function getExtractedCssItems(
70
75
  if (styleItems.length) {
71
76
  output.push(getLayerBlockCss(styleLayerName, '\n' + styleItems.join('\n') + '\n'));
72
77
  }
73
- if (sheetItems.length) {
74
- output.push(getLayerBlockCss(sheetLayerName, '\n' + sheetItems.join('\n') + '\n'));
78
+ for (const [name, rules] of sheetItems) {
79
+ output.push(getLayerBlockCss(name, '\n' + rules.join('\n') + '\n'));
75
80
  }
76
81
  output.push(...unlayeredItems);
77
82
 
@@ -6,6 +6,7 @@ import type {
6
6
  ExtractedStyleItem,
7
7
  } from '../../builder/data';
8
8
  import type { TRACE_STYLE, TRACE_VALUE } from '../../builder/data/debug';
9
+ import type { NamedSheetLayer } from '../../config/config/css';
9
10
 
10
11
  export type CssExtractStyleItem = ExtractedStyleItem;
11
12
 
@@ -27,7 +28,7 @@ export type CssExtractRule = {
27
28
  css: string;
28
29
  priority: LayerPriority;
29
30
  important?: boolean;
30
- layer?: 'sheet' | false;
31
+ layer?: 'sheet' | false | NamedSheetLayer;
31
32
  trace?: {
32
33
  filePath: string;
33
34
  line: number;
@@ -27,11 +27,13 @@ import {
27
27
  getStyleTokenId,
28
28
  getStyleTokenName,
29
29
  isStyleTokenData,
30
+ isStyleTokenOverrideData,
30
31
  type StyleTokenData,
31
32
  type StyleTokenOverride,
32
33
  TOKEN_ID,
33
34
  TOKEN_NAME,
34
35
  TOKEN_OVERRIDE,
36
+ TOKEN_VAR_NAME,
35
37
  } from '../../../style/token';
36
38
  import type { StyleTransform } from '../../../style/transform';
37
39
  import { exposeStyle } from '../../../style/utils';
@@ -70,12 +72,16 @@ import {
70
72
  IMPORT_PATHS,
71
73
  STYLE_UTILS_IMPORT_PATH,
72
74
  } from '../../utils/constants';
73
- import type { BabelTypes } from '../utils/babel';
75
+ import { BabelCore, type BabelTypes } from '../utils/babel';
74
76
  import type { EvalFail, EvalModuleBindings, EvalOk, EvalResult, ImportMap, ResolveImportFn } from './types';
75
77
 
76
78
  const STYLE_IMPORT_PATHS = new Set(IMPORT_PATHS);
77
79
 
78
80
  export const COMPILED_RUNTIME_VALUE = Symbol();
81
+ export const COMPILED_TOKEN_REFERENCE = Symbol();
82
+ export type CompiledTokenReference = {
83
+ [COMPILED_TOKEN_REFERENCE]?: { expression: BabelTypes.Expression; filePath: string; };
84
+ };
79
85
  export const COMPILED_STYLE_OBJECT_LOCATIONS = Symbol();
80
86
  const COMPILED_TOKEN_FACTORY = Symbol();
81
87
 
@@ -123,6 +129,7 @@ export type EvalScope = {
123
129
  styleTransform?: StyleTransform | null;
124
130
  sourcemapTrace?: 'style' | 'value';
125
131
  runtimeMode?: CompilerRuntimeMode | null;
132
+ tokenNameFormat?: TokenNameFormat | null;
126
133
  };
127
134
 
128
135
  export function evaluateNode(
@@ -148,10 +155,10 @@ export function evaluateNode(
148
155
  return evaluateTemplate(node, scope);
149
156
 
150
157
  case 'Identifier':
151
- return evaluateIdentifier(node, scope);
158
+ return referenceResult(evaluateIdentifier(node, scope), node, scope);
152
159
 
153
160
  case 'MemberExpression':
154
- return evaluateMember(node as BabelTypes.MemberExpression, scope);
161
+ return referenceResult(evaluateMember(node as BabelTypes.MemberExpression, scope), node, scope);
155
162
 
156
163
  case 'ObjectExpression':
157
164
  return evaluateObject(node as BabelTypes.ObjectExpression, scope);
@@ -160,7 +167,7 @@ export function evaluateNode(
160
167
  return evaluateArray(node as BabelTypes.ArrayExpression, scope);
161
168
 
162
169
  case 'CallExpression':
163
- return evaluateCall(node as BabelTypes.CallExpression, scope);
170
+ return referenceCallResult(evaluateCall(node as BabelTypes.CallExpression, scope), node, scope);
164
171
 
165
172
  case 'BinaryExpression':
166
173
  return evaluateBinary(node as BabelTypes.BinaryExpression, scope);
@@ -679,7 +686,12 @@ function evaluateCall(node: BabelTypes.CallExpression, scope: EvalScope): EvalRe
679
686
  if (!value.ok) return value;
680
687
 
681
688
  if (isStyleTokenData(value.value)) {
682
- return evalOk(getTokenVar(value.value, CSS_CONFIG.tokenNameFormat || null));
689
+ return evalOk(
690
+ getTokenVar(
691
+ value.value,
692
+ scope.tokenNameFormat === undefined ? CSS_CONFIG.tokenNameFormat || null : scope.tokenNameFormat,
693
+ ),
694
+ );
683
695
  }
684
696
 
685
697
  return evalOk(value.value);
@@ -740,7 +752,7 @@ function evaluateCall(node: BabelTypes.CallExpression, scope: EvalScope): EvalRe
740
752
  return evalOk(createCompiledTokenOverride(target, provide.value, node));
741
753
  }
742
754
 
743
- return evalOk(withRuntimeValue(node, target));
755
+ return referenceResult(evalOk(withRuntimeValue(node, target)), node, scope);
744
756
  }
745
757
  }
746
758
 
@@ -773,7 +785,7 @@ function evaluateCall(node: BabelTypes.CallExpression, scope: EvalScope): EvalRe
773
785
  const meta = scope.styleMetas?.get(node.callee.object.name);
774
786
  const transformedFrames = transformKeyframes(
775
787
  frames.value as KeyframesObject,
776
- meta?.transform ?? scope.styleTransform ?? null,
788
+ (meta?.mode === 'StyleObject' ? meta.transform : null) ?? scope.styleTransform ?? null,
777
789
  );
778
790
  const format = CSS_EXTRA_CONFIG.namedRuleFormat.keyframes ?? null;
779
791
 
@@ -941,6 +953,7 @@ function createCompiledTokenOverride(
941
953
  [TOKEN_ID]: getStyleTokenId(token),
942
954
  [TOKEN_OVERRIDE]: true,
943
955
  [TOKEN_NAME]: getStyleTokenName(token),
956
+ [TOKEN_VAR_NAME]: token[TOKEN_VAR_NAME] ?? null,
944
957
  value: value.value,
945
958
  ref: value,
946
959
  });
@@ -950,6 +963,7 @@ function createCompiledTokenOverride(
950
963
  [TOKEN_ID]: getStyleTokenId(token),
951
964
  [TOKEN_OVERRIDE]: true,
952
965
  [TOKEN_NAME]: getStyleTokenName(token),
966
+ [TOKEN_VAR_NAME]: token[TOKEN_VAR_NAME] ?? null,
953
967
  value,
954
968
  ref: null,
955
969
  });
@@ -1108,6 +1122,7 @@ function createCompiledValues(
1108
1122
  stableId: string | undefined,
1109
1123
  isNumber: boolean,
1110
1124
  ): CompiledTokenFactory {
1125
+ if (!values.length) throw new Error('[Style.values] NO_VALUES');
1111
1126
  const tokens = new Map<unknown, StyleTokenData>();
1112
1127
  const groupName = getStyleTokenNameFromId(stableId);
1113
1128
 
@@ -1138,12 +1153,12 @@ function parseCompiledValue(value: unknown, isNumber: boolean) {
1138
1153
  if (!isNumber) return value;
1139
1154
 
1140
1155
  const number = Number(value);
1141
- if (!Number.isFinite(number)) return value;
1156
+ if (!Number.isFinite(number)) throw new Error(`[Style.values] INVALID_NUMBER_VALUE: ${String(value)}`);
1142
1157
 
1143
1158
  return number;
1144
1159
  }
1145
1160
 
1146
- function isCompiledTokenFactory(value: unknown): value is CompiledTokenFactory {
1161
+ export function isCompiledTokenFactory(value: unknown): value is CompiledTokenFactory {
1147
1162
  return !!value && typeof value === 'object' && (value as CompiledTokenFactory)[COMPILED_TOKEN_FACTORY] === true;
1148
1163
  }
1149
1164
 
@@ -1224,9 +1239,18 @@ function withRuntimeValue<T extends StyleTokenData | StyleTokenOverride>(
1224
1239
  runtimeValue: BabelTypes.Expression,
1225
1240
  token: T,
1226
1241
  ): T {
1242
+ if (typeof token === 'function') {
1243
+ return new Proxy(token, {
1244
+ get(target, key) {
1245
+ if (key === COMPILED_RUNTIME_VALUE) return runtimeValue;
1246
+ return Reflect.get(target, key);
1247
+ },
1248
+ });
1249
+ }
1227
1250
  return Object.assign({}, token, {
1228
1251
  [TOKEN_ID]: token[TOKEN_ID],
1229
1252
  [TOKEN_NAME]: token[TOKEN_NAME] ?? null,
1253
+ [TOKEN_VAR_NAME]: token[TOKEN_VAR_NAME] ?? null,
1230
1254
  [COMPILED_RUNTIME_VALUE]: runtimeValue,
1231
1255
  });
1232
1256
  }
@@ -1277,3 +1301,53 @@ function evaluateUnary(node: BabelTypes.UnaryExpression, scope: EvalScope): Eval
1277
1301
  return evalFail(`Unsupported unary operator: ${node.operator}`);
1278
1302
  }
1279
1303
  }
1304
+
1305
+ function referenceResult(result: EvalResult, expression: BabelTypes.Expression, scope: EvalScope): EvalResult {
1306
+ if (!result.ok) return result;
1307
+ return evalOk(referenceValue(result.value, expression, scope));
1308
+ }
1309
+
1310
+ function referenceValue(value: unknown, expression: BabelTypes.Expression, scope: EvalScope, nested = false): unknown {
1311
+ if (isStyleTokenData(value) || isStyleTokenOverrideData(value)) {
1312
+ if (nested && (value as CompiledTokenReference)[COMPILED_TOKEN_REFERENCE]?.filePath === scope.filePath) {
1313
+ return value;
1314
+ }
1315
+ const reference = { expression, filePath: scope.filePath };
1316
+ if (typeof value === 'function') {
1317
+ return new Proxy(value, {
1318
+ get(target, key) {
1319
+ if (key === COMPILED_TOKEN_REFERENCE) return reference;
1320
+ return Reflect.get(target, key);
1321
+ },
1322
+ });
1323
+ }
1324
+ return Object.assign(
1325
+ withRuntimeValue((value as CompiledRuntimeValue)[COMPILED_RUNTIME_VALUE] ?? expression, value),
1326
+ {
1327
+ [COMPILED_TOKEN_REFERENCE]: reference,
1328
+ },
1329
+ );
1330
+ }
1331
+ if (!value || typeof value !== 'object' || isCompiledTokenFactory(value)) return value;
1332
+ // Only recurse through ordinary data records; compiled styles and other tagged data stay intact.
1333
+ if (Object.getOwnPropertySymbols(value).some((key) => key !== COMPILED_STYLE_OBJECT_LOCATIONS)) return value;
1334
+ const result = Object.defineProperties(Array.isArray(value) ? [] : {}, Object.getOwnPropertyDescriptors(value));
1335
+ for (const key of Object.keys(value)) {
1336
+ (result as Record<string, unknown>)[key] = referenceValue(
1337
+ (value as Record<string, unknown>)[key],
1338
+ BabelCore.types.memberExpression(expression, BabelCore.types.stringLiteral(key), true),
1339
+ scope,
1340
+ true,
1341
+ );
1342
+ }
1343
+ return result;
1344
+ }
1345
+
1346
+ function referenceCallResult(result: EvalResult, node: BabelTypes.CallExpression, scope: EvalScope): EvalResult {
1347
+ // Factory calls are rewritten separately. Ordinary token/value calls retain their expression.
1348
+ const imp = node.callee.type === 'Identifier' ? scope.imports.get(node.callee.name) : undefined;
1349
+ if (imp && STYLE_IMPORT_PATHS.has(imp.source)) return result;
1350
+ return result.ok && (isStyleTokenData(result.value) || isStyleTokenOverrideData(result.value))
1351
+ ? referenceResult(result, node, scope)
1352
+ : result;
1353
+ }
@@ -245,10 +245,13 @@ function parseAndExtractModule(
245
245
 
246
246
  if (stmt.source) {
247
247
  imports.set(exported, { source: stmt.source.value, name: local });
248
+ rawBindings.set(exported, t.identifier(exported));
248
249
  } else if (rawBindings.has(local)) {
249
250
  rawBindings.set(exported, rawBindings.get(local)!);
250
251
  } else if (bindings.has(local)) {
251
252
  bindings.set(exported, bindings.get(local)!);
253
+ } else if (imports.has(local)) {
254
+ rawBindings.set(exported, t.identifier(local));
252
255
  }
253
256
  }
254
257
 
@@ -270,6 +273,7 @@ function parseAndExtractModule(
270
273
  }
271
274
 
272
275
  const scope: EvalScope = {
276
+ tokenNameFormat: options.css?.tokenNameFormat ?? null,
273
277
  bindings,
274
278
  imports,
275
279
  styleNames,
@@ -36,7 +36,7 @@ import type {
36
36
  RuntimeStyleItem,
37
37
  } from '../../../../builder/data/state';
38
38
  import { normalizeManualSelectors, setSheetSelectorOptions } from '../../../../builder/selector_override';
39
- import { isSheetLayerEnabled } from '../../../../config/config/css';
39
+ import { isSheetLayerEnabled, isSheetLayerOption, resolveSheetLayerOption } from '../../../../config/config/css';
40
40
  import type { ClassNameFormat, TokenNameFormat, TransformClassNameFormat } from '../../../../config/types';
41
41
  import type { Selector } from '../../../../selector/types';
42
42
  import { importantValue, isStyleImportantValue } from '../../../../style/important';
@@ -392,7 +392,10 @@ function compileSheetChain(
392
392
 
393
393
  const sheetLayer = sheetOptions.layer ?? isSheetLayerEnabled(options.css?.layer ?? DEFAULT_CONFIG.layer);
394
394
  for (let i = 0, len = rules.length; i < len; i++) {
395
- rules[i].layer = sheetLayer ? 'sheet' : false;
395
+ rules[i].layer = resolveSheetLayerOption(
396
+ sheetLayer,
397
+ options.css?.layerNamespace ?? DEFAULT_CONFIG.layerNamespace ?? '',
398
+ );
396
399
  }
397
400
 
398
401
  return { type: 'sheet', items, rules, sheetOptions };
@@ -407,11 +410,11 @@ function evaluateCreateSheetOptions(
407
410
 
408
411
  const value = result.value as Record<string, unknown>;
409
412
  if (Object.keys(value).some((key) => key !== 'layer' && key !== 'weight')) return null;
410
- if (value.layer !== undefined && typeof value.layer !== 'boolean') return null;
413
+ if (!isSheetLayerOption(value.layer)) return null;
411
414
  if (value.weight !== undefined && (!Number.isInteger(value.weight) || (value.weight as number) < 1)) return null;
412
415
 
413
416
  return {
414
- layer: value.layer as boolean | undefined,
417
+ layer: value.layer as boolean | string | undefined,
415
418
  weight: value.weight as number | undefined,
416
419
  };
417
420
  }
@@ -31,6 +31,20 @@ export function extractStyleChain(
31
31
 
32
32
  const callee = node.callee;
33
33
 
34
+ if (callee.type === 'CallExpression') {
35
+ const target = extractStyleChain(callee, styleNames, sheetNames);
36
+ if (
37
+ target?.kind !== 'selector' || target.baseArgs.length !== 1 ||
38
+ target.methods.length !== 0 || node.arguments.length > 1
39
+ ) return null;
40
+
41
+ // style.selector(selector)(styles) is the inline form of a selector target call.
42
+ return {
43
+ ...target,
44
+ baseArgs: [...target.baseArgs, ...(node.arguments as BabelTypes.Node[])],
45
+ };
46
+ }
47
+
34
48
  if (callee.type === 'Identifier' && styleNames.has(callee.name)) {
35
49
  return { kind: 'style', rootName: callee.name, baseArgs: node.arguments as BabelTypes.Node[], methods: [] };
36
50
  }
@@ -15,7 +15,12 @@ import {
15
15
  } from '../../utils/constants';
16
16
  import { createImportSourceMatcher } from '../../utils/import_source';
17
17
  import { normalizePath } from '../../utils/path';
18
- import { evaluateEnumDeclaration, evaluateNode } from '../evaluator/evaluator';
18
+ import {
19
+ COMPILED_TOKEN_REFERENCE,
20
+ type CompiledTokenReference,
21
+ evaluateEnumDeclaration,
22
+ evaluateNode,
23
+ } from '../evaluator/evaluator';
19
24
  import { getImportedName } from '../syntax';
20
25
  import { annotateAtRuleDeclaration } from '../syntax/static_ids';
21
26
  import { BabelCore } from '../utils/babel';
@@ -28,7 +33,7 @@ import { buildReplacement } from './utils/replacement';
28
33
  import { recordCompiledBinding } from './utils/slot';
29
34
  import { type ExtractPluginState, getEvalScope, type HoistedDeclaration } from './utils/state';
30
35
  import { compileThemeCall } from './utils/theme';
31
- import { annotateTokenDeclaration } from './utils/token';
36
+ import { annotateTokenDeclaration, compileTokenFactory } from './utils/token';
32
37
 
33
38
  export type PluginState = BabelCore.PluginPass & ExtractPluginState;
34
39
 
@@ -59,6 +64,7 @@ export function createExtractPlugin(args: PluginArgs) {
59
64
 
60
65
  return {
61
66
  pre(this) {
67
+ this.tokenFactoryReplacements = new Map();
62
68
  this.styleNames = new Set();
63
69
  this.sheetNames = new Set();
64
70
  this.styleMetas = new Map();
@@ -161,6 +167,14 @@ export function createExtractPlugin(args: PluginArgs) {
161
167
  },
162
168
 
163
169
  CallExpression(path, state) {
170
+ if (mode === 'extract') {
171
+ try {
172
+ const tokenFactory = compileTokenFactory(path.node, state, t);
173
+ if (tokenFactory) state.tokenFactoryReplacements.set(path.node, tokenFactory);
174
+ } catch (error) {
175
+ throw path.buildCodeFrameError(error instanceof Error ? error.message : String(error));
176
+ }
177
+ }
164
178
  if (
165
179
  path.parent.type === 'MemberExpression' &&
166
180
  !(path.parent.computed)
@@ -270,6 +284,15 @@ export function createExtractPlugin(args: PluginArgs) {
270
284
  exit(path, state) {
271
285
  if (mode === 'collect') return;
272
286
 
287
+ path.traverse({
288
+ CallExpression(factoryPath) {
289
+ const replacement = state.tokenFactoryReplacements.get(factoryPath.node);
290
+ if (!replacement) return;
291
+ factoryPath.replaceWith(replacement);
292
+ factoryPath.skip();
293
+ state.needsExtractImport = true;
294
+ },
295
+ });
273
296
  pruneUnusedStyleInputDeclarations(path, state);
274
297
  pruneUnusedStyleImports(path, state);
275
298
 
@@ -466,8 +489,11 @@ function createRuntimeTokenCollector(
466
489
 
467
490
  return {
468
491
  overrides,
469
- addOverride(item: { valueNode: BabelTypes.Expression; }) {
470
- overrides.push(args.t.cloneNode(item.valueNode));
492
+ addOverride(item: { valueNode: BabelTypes.Expression; value: unknown; }) {
493
+ const reference = (item.value as CompiledTokenReference)[COMPILED_TOKEN_REFERENCE];
494
+ overrides.push(
495
+ args.t.cloneNode(reference?.filePath === args.state.filePath ? reference.expression : item.valueNode, true),
496
+ );
471
497
  },
472
498
  add(item: object, valueNode: BabelTypes.Expression) {
473
499
  if (canHoistRuntimeValue(args.path, valueNode)) {
@@ -3,6 +3,9 @@ import {
3
3
  FN_COMBINE_SCOPE,
4
4
  FN_COMBINE_STYLE,
5
5
  FN_CREATE_THEME,
6
+ FN_CREATE_TOKEN,
7
+ FN_CREATE_TOKENS,
8
+ FN_CREATE_VALUES,
6
9
  FN_GET_CLASS_NAME,
7
10
  FN_GET_TOKEN,
8
11
  IMPORT_PATHS,
@@ -128,5 +131,6 @@ function isCompilerHandledImport(
128
131
  source: string,
129
132
  name: string,
130
133
  ) {
131
- return IMPORT_PATHS.includes(source) && name === FN_CREATE_THEME;
134
+ return IMPORT_PATHS.includes(source) &&
135
+ [FN_CREATE_THEME, FN_CREATE_TOKEN, FN_CREATE_TOKENS, FN_CREATE_VALUES].includes(name);
132
136
  }
@@ -27,6 +27,7 @@ import {
27
27
  FN_CREATE_EXTRACTED_STYLE_MERGE,
28
28
  FN_CREATE_EXTRACTED_TOKEN,
29
29
  } from '../../../utils/constants';
30
+ import { COMPILED_TOKEN_REFERENCE, type CompiledTokenReference } from '../../evaluator/evaluator';
30
31
  import type { BabelTypes } from '../../utils/babel';
31
32
  import type {
32
33
  CompiledChainData,
@@ -104,7 +105,12 @@ function buildSheetOptions(
104
105
  const properties: BabelTypes.ObjectProperty[] = [];
105
106
 
106
107
  if (options.layer !== undefined) {
107
- properties.push(t.objectProperty(t.identifier('layer'), t.booleanLiteral(options.layer)));
108
+ properties.push(
109
+ t.objectProperty(
110
+ t.identifier('layer'),
111
+ typeof options.layer === 'string' ? t.stringLiteral(options.layer) : t.booleanLiteral(options.layer),
112
+ ),
113
+ );
108
114
  }
109
115
  if (options.weight !== undefined) {
110
116
  properties.push(t.objectProperty(t.identifier('weight'), t.numericLiteral(options.weight)));
@@ -347,7 +353,11 @@ function buildVariableValueExpression(
347
353
  options: BuildReplacementOptions,
348
354
  ): BabelTypes.Expression {
349
355
  if (isStyleTokenData(value)) {
350
- state.usedHelpers.add(FN_CREATE_EXTRACTED_TOKEN);
356
+ const reference = (value as CompiledTokenReference)[COMPILED_TOKEN_REFERENCE];
357
+ if (reference?.filePath === state.filePath) {
358
+ const runtimeToken = options.getRuntimeToken?.(item, reference.expression);
359
+ if (runtimeToken) return runtimeToken;
360
+ }
351
361
  return buildExtractedTokenExpression(t, value, state);
352
362
  }
353
363
 
@@ -358,11 +368,16 @@ function buildVariableValueExpression(
358
368
  return valueNode ? t.cloneNode(valueNode) : literalExpression(t, value);
359
369
  }
360
370
 
361
- function buildExtractedTokenExpression(
371
+ export function buildExtractedTokenExpression(
362
372
  t: typeof BabelTypes,
363
373
  token: StyleTokenData,
364
374
  state: ExtractPluginState,
375
+ preserveReference = true,
365
376
  ): BabelTypes.Expression {
377
+ const reference = (token as CompiledTokenReference)[COMPILED_TOKEN_REFERENCE];
378
+ if (preserveReference && reference?.filePath === state.filePath) {
379
+ return t.cloneNode(reference.expression, true);
380
+ }
366
381
  state.usedHelpers.add(FN_CREATE_EXTRACTED_TOKEN);
367
382
  const tokenNameFormat = state.options.css?.tokenNameFormat ?? DEFAULT_CONFIG.tokenNameFormat ?? null;
368
383
 
@@ -383,6 +398,8 @@ function buildExtractedTokenOverrideExpression(
383
398
  token: StyleTokenOverride,
384
399
  state: ExtractPluginState,
385
400
  ): BabelTypes.Expression {
401
+ const reference = (token as CompiledTokenReference)[COMPILED_TOKEN_REFERENCE];
402
+ if (reference?.filePath === state.filePath) return t.cloneNode(reference.expression, true);
386
403
  state.usedHelpers.add(FN_CREATE_EXTRACTED_TOKEN);
387
404
  const tokenNameFormat = state.options.css?.tokenNameFormat ?? DEFAULT_CONFIG.tokenNameFormat ?? null;
388
405
  const extractedToken = t.callExpression(
@@ -415,5 +432,5 @@ function literalExpression(
415
432
  if (typeof value === 'boolean') return t.booleanLiteral(value);
416
433
  if (value === null || value === undefined) return t.nullLiteral();
417
434
 
418
- return t.stringLiteral(String(value));
435
+ return t.valueToNode(value) as BabelTypes.Expression;
419
436
  }
@@ -13,6 +13,7 @@ export type HoistedDeclaration = {
13
13
  };
14
14
 
15
15
  export type ExtractPluginState = {
16
+ tokenFactoryReplacements: Map<BabelTypes.CallExpression, BabelTypes.Expression>;
16
17
  fileId: string;
17
18
  filePath: string;
18
19
  styleFilePath: string;
@@ -47,5 +48,6 @@ export function getEvalScope(state: ExtractPluginState): EvalScope {
47
48
  styleMetas: state.styleMetas,
48
49
  bindingNodes: state.bindingNodes,
49
50
  runtimeMode: state.runtimeMode,
51
+ tokenNameFormat: state.options.css?.tokenNameFormat ?? null,
50
52
  };
51
53
  }