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

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 (277) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/atomic/className.ts +4 -0
  3. package/atomic/rule.ts +15 -7
  4. package/atomic/utils/selector.ts +12 -3
  5. package/builder/classname/class_name_builder.ts +1 -1
  6. package/builder/data/const.ts +2 -0
  7. package/builder/data/data.ts +1 -1
  8. package/builder/data/merge/scope.ts +7 -0
  9. package/builder/data/merge/style.ts +12 -3
  10. package/builder/data/state.ts +1 -0
  11. package/builder/selector_override.ts +1 -1
  12. package/builder/selector_override_core.ts +17 -3
  13. package/builder/types/alias.ts +1 -1
  14. package/compiler/extract/extract.ts +21 -75
  15. package/compiler/extract/types.ts +4 -1
  16. package/compiler/transform/debug/plugin.ts +22 -0
  17. package/compiler/transform/evaluator/evaluator.ts +4 -1
  18. package/compiler/transform/extract/chain/chain.ts +82 -22
  19. package/compiler/transform/extract/chain/extract_chain.ts +2 -0
  20. package/compiler/transform/extract/plugin.ts +51 -25
  21. package/compiler/transform/extract/utils/imports.ts +4 -1
  22. package/compiler/transform/extract/utils/replacement.ts +2 -2
  23. package/compiler/transform/utils/babel.ts +1 -1
  24. package/compiler/utils/constants.ts +1 -0
  25. package/config/config/css.ts +5 -3
  26. package/config/configure.ts +4 -0
  27. package/config/document.ts +23 -0
  28. package/css/globalSheet.ts +66 -0
  29. package/css/index.ts +4 -1
  30. package/css/sheet.ts +34 -14
  31. package/dist/{className-yhJCGT0F.js → className-CC5PHcXI.js} +9 -2
  32. package/dist/className-CC5PHcXI.js.map +1 -0
  33. package/dist/{combine-CC9bY-hu.js → combine-BpOQWCtM.js} +5 -5
  34. package/dist/combine-BpOQWCtM.js.map +1 -0
  35. package/dist/compiler/index.mjs +1 -1
  36. package/dist/{compiler-Ct5xGIeu.mjs → compiler-AOb_VaKQ.mjs} +464 -166
  37. package/dist/compiler-AOb_VaKQ.mjs.map +1 -0
  38. package/dist/config/index.js +2 -2
  39. package/dist/{config-CCgsVvyR.js → config-B70LIQhi.js} +2 -2
  40. package/dist/{config-CCgsVvyR.js.map → config-B70LIQhi.js.map} +1 -1
  41. package/dist/{config-BiiMS4rU.js → config-BK7oK4Hx.js} +25 -4
  42. package/dist/config-BK7oK4Hx.js.map +1 -0
  43. package/dist/{config-DZKR6gH1.js → config-DFxeuT46.js} +4 -4
  44. package/dist/{config-DZKR6gH1.js.map → config-DFxeuT46.js.map} +1 -1
  45. package/dist/{css-IecKRNxs.js → css-BkNqUfLD.js} +112 -73
  46. package/dist/css-BkNqUfLD.js.map +1 -0
  47. package/dist/{css-WaHZ6gxv.js → css-C7tcD3IO.js} +611 -213
  48. package/dist/css-C7tcD3IO.js.map +1 -0
  49. package/dist/css-Cdxkur4h.js +414 -0
  50. package/dist/css-Cdxkur4h.js.map +1 -0
  51. package/dist/css.js +2 -2
  52. package/dist/css_extra-BC1Z_hDy.js +8 -0
  53. package/dist/{css_extra-DDeJc2Cu.js.map → css_extra-BC1Z_hDy.js.map} +1 -1
  54. package/dist/{css_extra-DDeJc2Cu.js → css_extra-qzi_eFFf.js} +2 -2
  55. package/dist/css_extra-qzi_eFFf.js.map +1 -0
  56. package/dist/{data-BgZmL55Y.js → data-MrBhvIQZ.js} +28 -19
  57. package/dist/data-MrBhvIQZ.js.map +1 -0
  58. package/dist/{debug-D-1hhd0G.js → debug-Bo43rBKc.js} +6 -9
  59. package/dist/debug-Bo43rBKc.js.map +1 -0
  60. package/dist/dev/rsc.js +134 -25
  61. package/dist/dev/rsc.js.map +1 -1
  62. package/dist/{dev-CBRbVaeq.js → dev-BoEgFs_x.js} +6 -6
  63. package/dist/{dev-CBRbVaeq.js.map → dev-BoEgFs_x.js.map} +1 -1
  64. package/dist/dev.js +1 -1
  65. package/dist/dialect/extracted/index.js +1 -1
  66. package/dist/dialect/index.js +1 -1
  67. package/dist/{elementMarker-CJcfpKL1.js → elementMarker-nYeJnJPQ.js} +334 -53
  68. package/dist/elementMarker-nYeJnJPQ.js.map +1 -0
  69. package/dist/entry/dev/adapter/preact.js +1 -1
  70. package/dist/entry/dev/adapter/react.js +1 -1
  71. package/dist/entry/dev/adapter/solid.js +1 -1
  72. package/dist/entry/dev/css.js +3 -3
  73. package/dist/entry/dev/jsx-dev-runtime.js +2 -2
  74. package/dist/entry/dev/jsx-runtime.js +2 -2
  75. package/dist/entry/dev.js +11 -11
  76. package/dist/entry/prod/adapter/preact.js +1 -1
  77. package/dist/entry/prod/adapter/react.js +1 -1
  78. package/dist/entry/prod/adapter/solid.js +1 -1
  79. package/dist/entry/prod/css.js +3 -3
  80. package/dist/entry/prod/extract.js.map +1 -1
  81. package/dist/entry/prod.js +3 -3
  82. package/dist/entry/rsc-dev/adapter/preact.js +1 -1
  83. package/dist/entry/rsc-dev/adapter/react.js +1 -1
  84. package/dist/entry/rsc-dev/adapter/solid.js +1 -1
  85. package/dist/entry/rsc-dev/css.js +4 -3
  86. package/dist/entry/rsc-dev/dev.js +129 -24
  87. package/dist/entry/rsc-dev/dev.js.map +1 -1
  88. package/dist/entry/rsc-dev/jsx-dev-runtime.js +5 -4
  89. package/dist/entry/rsc-dev/jsx-dev-runtime.js.map +1 -1
  90. package/dist/entry/rsc-dev/jsx-runtime.js +2 -2
  91. package/dist/entry/rsc-dev.js +8 -7
  92. package/dist/entry/rsc-dev.js.map +1 -1
  93. package/dist/entry/rsc-prod/css.js +4 -4
  94. package/dist/entry/rsc-prod.js +4 -4
  95. package/dist/{rules-Dz-szpPu.js → env-BcNl1tsJ.js} +59 -21
  96. package/dist/env-BcNl1tsJ.js.map +1 -0
  97. package/dist/{getClassName-DtkplEIt.js → getClassName-5yYUibKw.js} +2 -2
  98. package/dist/{getClassName-DtkplEIt.js.map → getClassName-5yYUibKw.js.map} +1 -1
  99. package/dist/getClassName-9CsXbNls.js.map +1 -1
  100. package/dist/{getClassName-CeoxISNW.js → getClassName-B3azD1TO.js} +6 -4
  101. package/dist/getClassName-B3azD1TO.js.map +1 -0
  102. package/dist/{getClassName-BNe3Ycyy.js → getClassName-CkTq92nR.js} +4 -4
  103. package/dist/{getClassName-BNe3Ycyy.js.map → getClassName-CkTq92nR.js.map} +1 -1
  104. package/dist/{global-UOHFwqHN.js → global-DGcWZODV.js} +4 -7
  105. package/dist/{global-UOHFwqHN.js.map → global-DGcWZODV.js.map} +1 -1
  106. package/dist/{css-BhoclXaw.js → globalSheet-CdgVpvCb.js} +185 -426
  107. package/dist/globalSheet-CdgVpvCb.js.map +1 -0
  108. package/dist/{hash-DlXmmPPm.js → hash-CjTP-uES.js} +4 -4
  109. package/dist/hash-CjTP-uES.js.map +1 -0
  110. package/dist/index.js +9 -9
  111. package/dist/jsx/jsx-dev-runtime.js +1 -1
  112. package/dist/jsx/jsx-dev-runtime.server.js +3 -3
  113. package/dist/jsx/jsx-dev-runtime.server.js.map +1 -1
  114. package/dist/jsx/jsx-runtime.js +1 -1
  115. package/dist/jsx/jsx-runtime.server.js +4 -4
  116. package/dist/jsx/jsx-runtime.server.js.map +1 -1
  117. package/dist/{jsx-8TwYuvgM.js → jsx-DA1LD8nU.js} +4 -4
  118. package/dist/{jsx-8TwYuvgM.js.map → jsx-DA1LD8nU.js.map} +1 -1
  119. package/dist/jsx_runtime-pt7DOZOE.js +13 -0
  120. package/dist/jsx_runtime-pt7DOZOE.js.map +1 -0
  121. package/dist/{loader-BVebGteg.mjs → loader-fAuIjIik.mjs} +3 -3
  122. package/dist/{loader-BVebGteg.mjs.map → loader-fAuIjIik.mjs.map} +1 -1
  123. package/dist/{misc-Bs2DgdG7.mjs → misc-CyZgGtc9.mjs} +3 -3
  124. package/dist/{misc-Bs2DgdG7.mjs.map → misc-CyZgGtc9.mjs.map} +1 -1
  125. package/dist/{namedTokens-CwniouKk.js → namedTokens-paLD-Pdk.js} +2 -2
  126. package/dist/{namedTokens-CwniouKk.js.map → namedTokens-paLD-Pdk.js.map} +1 -1
  127. package/dist/plugin/farm/index.mjs +3 -3
  128. package/dist/plugin/nextjs/index.mjs +4 -4
  129. package/dist/plugin/nextjs/loader.mjs +7 -5
  130. package/dist/plugin/nextjs/loader.mjs.map +1 -1
  131. package/dist/plugin/parcel/index.cjs +1 -1
  132. package/dist/plugin/parcel/index.mjs +2 -2
  133. package/dist/plugin/parcel/optimizer.cjs +1 -1
  134. package/dist/plugin/parcel/optimizer.mjs +2 -2
  135. package/dist/plugin/parcel/resolver.cjs +1 -1
  136. package/dist/plugin/parcel/resolver.mjs +2 -2
  137. package/dist/plugin/parcel/runtime.cjs +1 -1
  138. package/dist/plugin/parcel/runtime.mjs +1 -1
  139. package/dist/plugin/parcel/transformer.cjs +1 -1
  140. package/dist/plugin/parcel/transformer.mjs +2 -2
  141. package/dist/plugin/rspack/index.mjs +2 -2
  142. package/dist/plugin/vite/index.mjs +3 -3
  143. package/dist/plugin/webpack/index.mjs +2 -2
  144. package/dist/plugin/webpack/loader.mjs +2 -2
  145. package/dist/presets/tailwind/index.js +3 -3
  146. package/dist/{registry-D1n78rd7.mjs → registry-BMijh1CM.mjs} +2 -2
  147. package/dist/{registry-D1n78rd7.mjs.map → registry-BMijh1CM.mjs.map} +1 -1
  148. package/dist/{resolveClassNameRuntime-BJcykzdl.js → resolveClassNameRuntime-B6vKNL5y.js} +2 -2
  149. package/dist/{resolveClassNameRuntime-BJcykzdl.js.map → resolveClassNameRuntime-B6vKNL5y.js.map} +1 -1
  150. package/dist/server.js +87 -17
  151. package/dist/server.js.map +1 -1
  152. package/dist/{shared-D4-AKGn6.mjs → shared-BfASWZo1.mjs} +4 -4
  153. package/dist/{shared-D4-AKGn6.mjs.map → shared-BfASWZo1.mjs.map} +1 -1
  154. package/dist/{shared-C9XQd8p_.cjs → shared-DY0kuBcN.cjs} +460 -162
  155. package/dist/shared-DY0kuBcN.cjs.map +1 -0
  156. package/dist/sheet-Biw_rI4_.js +1 -0
  157. package/dist/{config-TyjNpRrV.js → sheet-C6ymGhKV.js} +23 -2
  158. package/dist/sheet-C6ymGhKV.js.map +1 -0
  159. package/dist/sheet-D_grHnaJ.js +7 -0
  160. package/dist/sheet-D_grHnaJ.js.map +1 -0
  161. package/dist/{sidecar-CZTYX2vA.mjs → sidecar-cCzTDkzg.mjs} +3 -3
  162. package/dist/{sidecar-CZTYX2vA.mjs.map → sidecar-cCzTDkzg.mjs.map} +1 -1
  163. package/dist/{style-CmXHCPF4.js → style-CRs-vfY1.js} +12 -12
  164. package/dist/style-CRs-vfY1.js.map +1 -0
  165. package/dist/{env-C8TRVSyb.js → styleStore-D1IEmq1v.js} +435 -63
  166. package/dist/styleStore-D1IEmq1v.js.map +1 -0
  167. package/dist/styleStore-HI4V2puu.js +45 -0
  168. package/dist/styleStore-HI4V2puu.js.map +1 -0
  169. package/dist/{token-DMrBbat8.js → token-BX5jRxMb.js} +2 -2
  170. package/dist/{token-DMrBbat8.js.map → token-BX5jRxMb.js.map} +1 -1
  171. package/dist/{trace-C7EzEj2Q.js → trace-DdFJPELS.js} +3 -3
  172. package/dist/{trace-C7EzEj2Q.js.map → trace-DdFJPELS.js.map} +1 -1
  173. package/dist/{trace-DzCntvK4.js → trace-uHVvnYiw.js} +2 -2
  174. package/dist/{trace-DzCntvK4.js.map → trace-uHVvnYiw.js.map} +1 -1
  175. package/dist/{transform-CSZMklMb.js → transform-BZ4jPwy3.js} +2 -2
  176. package/dist/{transform-CSZMklMb.js.map → transform-BZ4jPwy3.js.map} +1 -1
  177. package/dist/types/atomic/className.d.ts +2 -2
  178. package/dist/types/atomic/utils/selector.d.ts +2 -1
  179. package/dist/types/builder/data/const.d.ts +1 -0
  180. package/dist/types/builder/data/data.d.ts +1 -1
  181. package/dist/types/builder/data/state.d.ts +1 -0
  182. package/dist/types/builder/selector_override.d.ts +1 -1
  183. package/dist/types/builder/selector_override_core.d.ts +2 -0
  184. package/dist/types/builder/types/alias.d.ts +2 -2
  185. package/dist/types/compiler/extract/types.d.ts +7 -1
  186. package/dist/types/compiler/transform/extract/chain/extract_chain.d.ts +2 -0
  187. package/dist/types/compiler/utils/constants.d.ts +1 -0
  188. package/dist/types/config/config/css.d.ts +2 -1
  189. package/dist/types/config/configure.d.ts +2 -0
  190. package/dist/types/config/document.d.ts +3 -0
  191. package/dist/types/css/globalSheet.d.ts +24 -0
  192. package/dist/types/css/index.d.ts +4 -1
  193. package/dist/types/css/sheet.d.ts +3 -2
  194. package/dist/types/entry/rsc_dev/css.d.ts +1 -0
  195. package/dist/types/runtime/rsc/constants.d.ts +2 -0
  196. package/dist/types/runtime/rsc/dev.d.ts +5 -0
  197. package/dist/types/runtime/rsc/getClassName.d.ts +3 -0
  198. package/dist/types/runtime/rsc/globalSheet.d.ts +22 -0
  199. package/dist/types/runtime/rsc/observer.d.ts +5 -0
  200. package/dist/types/runtime/rsc/styleStore.d.ts +2 -0
  201. package/dist/types/runtime/sheet/document.d.ts +3 -0
  202. package/dist/types/sheet/ordered.d.ts +4 -0
  203. package/dist/types/sheet/ordering.d.ts +15 -0
  204. package/dist/types/sheet/types.d.ts +7 -0
  205. package/dist/types/style/important.d.ts +2 -1
  206. package/dist/types/style/style.d.ts +2 -2
  207. package/dist/{utils-CoMwEfhG.mjs → utils-BO6Ix8t5.mjs} +4 -4
  208. package/dist/{utils-CoMwEfhG.mjs.map → utils-BO6Ix8t5.mjs.map} +1 -1
  209. package/dist/{utils-B7QcJ-Yw.js → utils-CB70kIh6.js} +3 -3
  210. package/dist/{utils-B7QcJ-Yw.js.map → utils-CB70kIh6.js.map} +1 -1
  211. package/dist/{utils-BYpkJ-uE.mjs → utils-EG9gh2g3.mjs} +3 -3
  212. package/dist/{utils-BYpkJ-uE.mjs.map → utils-EG9gh2g3.mjs.map} +1 -1
  213. package/dist/{utils-D4KMqCu2.js → utils-sG7IWYP6.js} +1089 -646
  214. package/dist/utils-sG7IWYP6.js.map +1 -0
  215. package/dist/utils.js +3 -3
  216. package/dist/{value-yd2SZ1XQ.js → value-BhyWGLkf.js} +16 -9
  217. package/dist/value-BhyWGLkf.js.map +1 -0
  218. package/dist/{webpack-B6z1UHh9.mjs → webpack-WXAJ3IYn.mjs} +5 -5
  219. package/dist/{webpack-B6z1UHh9.mjs.map → webpack-WXAJ3IYn.mjs.map} +1 -1
  220. package/entry/dev/sheet.ts +4 -2
  221. package/entry/rsc_dev/css.ts +2 -0
  222. package/jsx/rsc/jsx_dev_runtime.ts +11 -2
  223. package/jsx/rsc/jsx_runtime.ts +14 -3
  224. package/package.json +16 -1
  225. package/plugin/nextjs/loader.ts +18 -2
  226. package/runtime/core/elementMarker.ts +9 -3
  227. package/runtime/rsc/constants.ts +3 -0
  228. package/runtime/rsc/dev.ts +31 -15
  229. package/runtime/rsc/getClassName.ts +6 -0
  230. package/runtime/rsc/globalSheet.ts +130 -0
  231. package/runtime/rsc/observer.ts +118 -15
  232. package/runtime/rsc/styleStore.ts +12 -36
  233. package/runtime/sheet/document.ts +28 -0
  234. package/runtime/sheet/global-prod.ts +3 -5
  235. package/runtime/sheet/global.ts +3 -5
  236. package/runtime/sheet/rule.ts +4 -2
  237. package/runtime/sheet/rules.ts +3 -0
  238. package/sheet/dev/dev_sort.ts +5 -1
  239. package/sheet/dev/index.ts +23 -3
  240. package/sheet/ordered.ts +188 -0
  241. package/sheet/ordering.ts +138 -0
  242. package/sheet/prod.ts +17 -5
  243. package/sheet/types.ts +4 -0
  244. package/style/important.ts +3 -1
  245. package/style/style.ts +1 -1
  246. package/utils/trace.ts +1 -0
  247. package/dist/className-yhJCGT0F.js.map +0 -1
  248. package/dist/combine-CC9bY-hu.js.map +0 -1
  249. package/dist/compiler-Ct5xGIeu.mjs.map +0 -1
  250. package/dist/config-BiiMS4rU.js.map +0 -1
  251. package/dist/config-TyjNpRrV.js.map +0 -1
  252. package/dist/createTransformElement-BGznW-Mu.js +0 -34
  253. package/dist/createTransformElement-BGznW-Mu.js.map +0 -1
  254. package/dist/css-BhoclXaw.js.map +0 -1
  255. package/dist/css-IecKRNxs.js.map +0 -1
  256. package/dist/css-WaHZ6gxv.js.map +0 -1
  257. package/dist/data-BgZmL55Y.js.map +0 -1
  258. package/dist/debug-D-1hhd0G.js.map +0 -1
  259. package/dist/elementMarker-CJcfpKL1.js.map +0 -1
  260. package/dist/env-C8TRVSyb.js.map +0 -1
  261. package/dist/getClassName-CeoxISNW.js.map +0 -1
  262. package/dist/global-CWYOol4o.js +0 -14
  263. package/dist/global-CWYOol4o.js.map +0 -1
  264. package/dist/hash-DlXmmPPm.js.map +0 -1
  265. package/dist/jsx_runtime-CPojW0KD.js +0 -12
  266. package/dist/jsx_runtime-CPojW0KD.js.map +0 -1
  267. package/dist/rules-Dz-szpPu.js.map +0 -1
  268. package/dist/shared-C9XQd8p_.cjs.map +0 -1
  269. package/dist/sheet-LU89fcH_.js +0 -7
  270. package/dist/sheet-LU89fcH_.js.map +0 -1
  271. package/dist/style-CmXHCPF4.js.map +0 -1
  272. package/dist/styleStore-B0x4Ahpx.js +0 -60
  273. package/dist/styleStore-B0x4Ahpx.js.map +0 -1
  274. package/dist/styleStore-BrpgLNgc.js +0 -57
  275. package/dist/styleStore-BrpgLNgc.js.map +0 -1
  276. package/dist/utils-D4KMqCu2.js.map +0 -1
  277. package/dist/value-yd2SZ1XQ.js.map +0 -1
@@ -35,8 +35,12 @@ import type {
35
35
  RuntimeSlotOverrideItem,
36
36
  RuntimeStyleItem,
37
37
  } from '../../../../builder/data/state';
38
- import { normalizeManualSelectors, setSheetSelectorOptions } from '../../../../builder/selector_override';
39
- import { isSheetLayerEnabled, isSheetLayerOption, resolveSheetLayerOption } from '../../../../config/config/css';
38
+ import {
39
+ normalizeManualSelectors,
40
+ setGlobalSheetSelectorOptions,
41
+ setSheetSelectorOptions,
42
+ } from '../../../../builder/selector_override';
43
+ import { isSheetLayerOption, isStyleLayerEnabled, resolveSheetLayerOption } from '../../../../config/config/css';
40
44
  import type { ClassNameFormat, TokenNameFormat, TransformClassNameFormat } from '../../../../config/types';
41
45
  import type { Selector } from '../../../../selector/types';
42
46
  import { importantValue, isStyleImportantValue } from '../../../../style/important';
@@ -376,10 +380,14 @@ function compileSheetChain(
376
380
  const items: CompiledItem[] = [];
377
381
  const rules: CssExtractRule[] = [];
378
382
  const hasOptions = chain.baseArgs.length === 2;
379
- const sheetOptions = hasOptions
380
- ? evaluateCreateSheetOptions(chain.baseArgs[0], scope)
383
+ const sheetOptions: (CreateSheetOptions & { global?: boolean; order?: number; }) | null = hasOptions
384
+ ? evaluateCreateSheetOptions(chain.baseArgs[0], scope, chain.global)
381
385
  : {};
382
386
  if (!sheetOptions) return null;
387
+ if (chain.global) {
388
+ if (sheetOptions.specificity !== undefined) throw new Error('createGlobalSheet does not support specificity');
389
+ sheetOptions.global = true;
390
+ }
383
391
 
384
392
  const sheetItems = chain.baseArgs[hasOptions ? 1 : 0];
385
393
 
@@ -390,12 +398,15 @@ function compileSheetChain(
390
398
  return null;
391
399
  }
392
400
 
393
- const sheetLayer = sheetOptions.layer ?? isSheetLayerEnabled(options.css?.layer ?? DEFAULT_CONFIG.layer);
401
+ const sheetLayer = sheetOptions.layer ?? false;
394
402
  for (let i = 0, len = rules.length; i < len; i++) {
395
403
  rules[i].layer = resolveSheetLayerOption(
396
404
  sheetLayer,
397
405
  options.css?.layerNamespace ?? DEFAULT_CONFIG.layerNamespace ?? '',
406
+ isStyleLayerEnabled(options.css?.layer ?? DEFAULT_CONFIG.layer),
398
407
  );
408
+ rules[i].sheet = true;
409
+ if (chain.global) rules[i].globalSheet = { id: chain.sheetId ?? fileId, order: sheetOptions.order ?? 0 };
399
410
  }
400
411
 
401
412
  return { type: 'sheet', items, rules, sheetOptions };
@@ -404,19 +415,26 @@ function compileSheetChain(
404
415
  function evaluateCreateSheetOptions(
405
416
  node: BabelTypes.Node,
406
417
  scope: EvalScope,
407
- ): CreateSheetOptions | null {
418
+ global = false,
419
+ ): (CreateSheetOptions & { order?: number; }) | null {
408
420
  const result = evaluateNode(node, scope);
409
421
  if (!result.ok || !result.value || typeof result.value !== 'object' || Array.isArray(result.value)) return null;
410
-
411
422
  const value = result.value as Record<string, unknown>;
412
- if (Object.keys(value).some((key) => key !== 'layer' && key !== 'weight')) return null;
413
- if (!isSheetLayerOption(value.layer)) return null;
414
- if (value.weight !== undefined && (!Number.isInteger(value.weight) || (value.weight as number) < 1)) return null;
415
-
416
- return {
417
- layer: value.layer as boolean | string | undefined,
418
- weight: value.weight as number | undefined,
419
- };
423
+ if (hasGlobalRuntimeValue(value)) return null;
424
+ const allowed = global ? ['layer', 'order'] : ['layer', 'specificity'];
425
+ if (Object.keys(value).some((key) => !allowed.includes(key))) {
426
+ throw new Error(
427
+ global ? 'createGlobalSheet only supports layer and order' : 'createSheet only supports layer and specificity',
428
+ );
429
+ }
430
+ if (!isSheetLayerOption(value.layer)) throw new Error('invalid sheet layer');
431
+ if (value.specificity !== undefined && (!Number.isInteger(value.specificity) || (value.specificity as number) < 0)) {
432
+ throw new Error('specificity must be a non-negative integer');
433
+ }
434
+ if (value.order !== undefined && (typeof value.order !== 'number' || !Number.isFinite(value.order))) {
435
+ throw new Error('order must be a finite number');
436
+ }
437
+ return value as CreateSheetOptions & { order?: number; };
420
438
  }
421
439
 
422
440
  function compileSheetItemsArg(
@@ -427,7 +445,7 @@ function compileSheetItemsArg(
427
445
  options: CompilerOptions,
428
446
  items: CompiledItem[],
429
447
  rules: CssExtractRule[],
430
- sheetOptions: CreateSheetOptions,
448
+ sheetOptions: CreateSheetOptions & { global?: boolean; order?: number; },
431
449
  ): boolean {
432
450
  if (node.type === 'ArrayExpression') {
433
451
  for (const element of node.elements) {
@@ -440,7 +458,9 @@ function compileSheetItemsArg(
440
458
  }
441
459
 
442
460
  const tokenOverride = evaluateNode(node, scope);
461
+ if (tokenOverride.ok && !tokenOverride.value) return true;
443
462
  if (tokenOverride.ok && isStyleTokenOverrideData(tokenOverride.value)) {
463
+ if (sheetOptions.global) throw new Error('createGlobalSheet requires token overrides inside an explicit selector');
444
464
  addCompiledTokenItem(
445
465
  getStyleTokenId(tokenOverride.value),
446
466
  tokenOverride.value,
@@ -455,6 +475,9 @@ function compileSheetItemsArg(
455
475
  const item = tokenOverride.value[i];
456
476
  if (!item) continue;
457
477
  if (!isStyleTokenOverrideData(item)) return false;
478
+ if (sheetOptions.global) {
479
+ throw new Error('createGlobalSheet requires token overrides inside an explicit selector');
480
+ }
458
481
 
459
482
  addCompiledTokenItem(
460
483
  getStyleTokenId(item),
@@ -505,10 +528,22 @@ function compileSelectorOverrideChain(
505
528
  options: CompilerOptions,
506
529
  items: CompiledItem[],
507
530
  rules: CssExtractRule[],
508
- sheetOptions: CreateSheetOptions,
531
+ sheetOptions: CreateSheetOptions & { global?: boolean; order?: number; },
509
532
  ): boolean {
510
533
  if (chain.baseArgs.length === 0 || chain.baseArgs.length > 2) return false;
511
534
 
535
+ // Unlike attached sheets, globals have no runtime replacement to supply dynamic values.
536
+ // Only erase the call when every selector/style argument is statically evaluable.
537
+ if (sheetOptions.global) {
538
+ const args = [...chain.baseArgs, ...chain.methods.flatMap((method) => method.args)];
539
+ if (
540
+ args.some((arg) => {
541
+ const result = evaluateNode(arg, scope);
542
+ return !result.ok || hasGlobalRuntimeValue(result.value);
543
+ })
544
+ ) return false;
545
+ }
546
+
512
547
  const selectorArg = evaluateNode(chain.baseArgs[0], scope);
513
548
  if (!selectorArg.ok) return false;
514
549
 
@@ -531,7 +566,9 @@ function compileSelectorOverrideChain(
531
566
  options,
532
567
  items,
533
568
  rules,
534
- setSheetSelectorOptions(manualSelectors[i], sheetOptions),
569
+ sheetOptions.global
570
+ ? setGlobalSheetSelectorOptions(manualSelectors[i], sheetOptions)
571
+ : setSheetSelectorOptions(manualSelectors[i], sheetOptions),
535
572
  )
536
573
  ) {
537
574
  return false;
@@ -1173,7 +1210,7 @@ function decorateClassNameValue(
1173
1210
  if (isClassNameValue(value)) return value;
1174
1211
 
1175
1212
  if (isStyleImportantValue(value)) {
1176
- return importantValue(decorateClassNameValue(value.value, className));
1213
+ return importantValue(decorateClassNameValue(value.value, className), value.native);
1177
1214
  }
1178
1215
 
1179
1216
  if (isStyleWeightValue(value)) {
@@ -2751,6 +2788,7 @@ function addSlotOverrideDataItems(
2751
2788
  property: overrideItem.property,
2752
2789
  weight: overrideItem.weight,
2753
2790
  important: overrideItem.important,
2791
+ importantNative: overrideItem.importantNative,
2754
2792
  value: overrideItem.value,
2755
2793
  variable: overrideItem.variable,
2756
2794
  token: overrideItem.token,
@@ -2854,6 +2892,7 @@ function addRuntimeScopeItem(
2854
2892
  sourceItem.selector,
2855
2893
  itemParentSelector,
2856
2894
  itemAtRules,
2895
+ sourceItem.importantNative,
2857
2896
  );
2858
2897
 
2859
2898
  const className = getAtomicClassName(
@@ -2872,6 +2911,7 @@ function addRuntimeScopeItem(
2872
2911
  cssConfig.transformClassNameFormat,
2873
2912
  cssConfig.sheetClassNameFormat,
2874
2913
  cssConfig.hashLength,
2914
+ sourceItem.importantNative,
2875
2915
  );
2876
2916
 
2877
2917
  const item: CompiledItem = createCompiledItem(
@@ -2910,6 +2950,7 @@ function addRuntimeScopeItem(
2910
2950
  css,
2911
2951
  priority: layerPriority,
2912
2952
  important,
2953
+ importantNative: sourceItem.importantNative,
2913
2954
  trace: traceCallsite
2914
2955
  ? {
2915
2956
  filePath: traceCallsite.filePath ?? fileId,
@@ -3094,6 +3135,7 @@ function addRuntimeStyleItem(
3094
3135
  itemSelector,
3095
3136
  parentSelector,
3096
3137
  itemAtRules,
3138
+ sourceItem.importantNative,
3097
3139
  );
3098
3140
 
3099
3141
  const traceCallsite = callsiteOverride ?? sourceItem.callsite;
@@ -3114,6 +3156,7 @@ function addRuntimeStyleItem(
3114
3156
  cssConfig.transformClassNameFormat,
3115
3157
  cssConfig.sheetClassNameFormat,
3116
3158
  cssConfig.hashLength,
3159
+ sourceItem.importantNative,
3117
3160
  );
3118
3161
 
3119
3162
  const item: CompiledItem = createCompiledItem(
@@ -3158,6 +3201,7 @@ function addRuntimeStyleItem(
3158
3201
  css,
3159
3202
  priority: layerPriority,
3160
3203
  important,
3204
+ importantNative: sourceItem.importantNative,
3161
3205
  trace: traceCallsite
3162
3206
  ? {
3163
3207
  filePath: traceCallsite.filePath ?? fileId,
@@ -3271,10 +3315,11 @@ function addStyleItems(
3271
3315
 
3272
3316
  let weight: number | null = null;
3273
3317
  let important = false;
3318
+ let importantNative = false;
3274
3319
  let value: unknown = rawValue;
3275
3320
  let transformClassName: string | null = null;
3276
3321
 
3277
- [value, weight, important] = unwrapStaticStyleValue(value);
3322
+ [value, weight, important, importantNative] = unwrapStaticStyleValue(value);
3278
3323
 
3279
3324
  if (isClassNameValue(value)) {
3280
3325
  transformClassName = value.className;
@@ -3336,6 +3381,7 @@ function addStyleItems(
3336
3381
  selector,
3337
3382
  parentSelector,
3338
3383
  atRules,
3384
+ importantNative,
3339
3385
  );
3340
3386
 
3341
3387
  const className = getAtomicClassName(
@@ -3354,6 +3400,7 @@ function addStyleItems(
3354
3400
  cssConfig.transformClassNameFormat,
3355
3401
  cssConfig.sheetClassNameFormat,
3356
3402
  cssConfig.hashLength,
3403
+ importantNative,
3357
3404
  );
3358
3405
 
3359
3406
  const item: CompiledItem = createCompiledItem(
@@ -3422,6 +3469,7 @@ function addStyleItems(
3422
3469
  css,
3423
3470
  priority: layerPriority,
3424
3471
  important,
3472
+ importantNative,
3425
3473
  trace: propertyCallsite
3426
3474
  ? {
3427
3475
  filePath: propertyCallsite.filePath ?? fileId,
@@ -3454,13 +3502,17 @@ function addStyleItems(
3454
3502
  return true;
3455
3503
  }
3456
3504
 
3457
- function unwrapStaticStyleValue(value: unknown): [value: unknown, weight: number | null, important: boolean] {
3505
+ function unwrapStaticStyleValue(
3506
+ value: unknown,
3507
+ ): [value: unknown, weight: number | null, important: boolean, native: boolean] {
3458
3508
  let weight: number | null = null;
3459
3509
  let important = false;
3510
+ let native = false;
3460
3511
 
3461
3512
  while (true) {
3462
3513
  if (isStyleImportantValue(value)) {
3463
3514
  important = true;
3515
+ native ||= value.native === true;
3464
3516
  value = value.value;
3465
3517
  continue;
3466
3518
  }
@@ -3474,7 +3526,7 @@ function unwrapStaticStyleValue(value: unknown): [value: unknown, weight: number
3474
3526
  break;
3475
3527
  }
3476
3528
 
3477
- return [value, weight, important];
3529
+ return [value, weight, important, native];
3478
3530
  }
3479
3531
 
3480
3532
  function throwIfRequiredStaticStyleValue(result: EvalResult) {
@@ -3552,3 +3604,11 @@ function getCompiledRuntimeValue(value: unknown): BabelTypes.Expression | undefi
3552
3604
  if (!value || typeof value !== 'object') return undefined;
3553
3605
  return (value as CompiledRuntimeValue)[COMPILED_RUNTIME_VALUE];
3554
3606
  }
3607
+
3608
+ function hasGlobalRuntimeValue(value: unknown, seen = new Set<object>()): boolean {
3609
+ if (!value || typeof value !== 'object' || isStyleTokenData(value) || isAtRuleRef(value)) return false;
3610
+ if (getCompiledRuntimeValue(value)) return true;
3611
+ if (seen.has(value)) return false;
3612
+ seen.add(value);
3613
+ return Object.values(value).some((item) => hasGlobalRuntimeValue(item, seen));
3614
+ }
@@ -10,6 +10,8 @@ export type StyleChainMethod = {
10
10
  };
11
11
 
12
12
  export type StyleChainParseResult = {
13
+ global?: boolean;
14
+ sheetId?: string;
13
15
  kind: 'style' | 'slot' | 'scope' | 'sheet' | 'selector';
14
16
  rootName: string;
15
17
  baseArgs: BabelTypes.Node[];
@@ -6,6 +6,7 @@ import type { CompilerCssCollector } from '../../extract/collector';
6
6
  import {
7
7
  FN_CREATE_EXTRACTED_THEME,
8
8
  FN_CREATE_EXTRACTED_TOKEN,
9
+ FN_CREATE_GLOBAL_SHEET,
9
10
  FN_CREATE_SHEET,
10
11
  FN_STYLE_PLAIN,
11
12
  FN_STYLE_RAW,
@@ -117,7 +118,10 @@ export function createExtractPlugin(args: PluginArgs) {
117
118
  state.styleMetas.set(spec.local.name, meta);
118
119
  }
119
120
 
120
- if (sourceName === STYLE_CSS_IMPORT_PATH && imported === FN_CREATE_SHEET) {
121
+ if (
122
+ sourceName === STYLE_CSS_IMPORT_PATH &&
123
+ (imported === FN_CREATE_SHEET || imported === FN_CREATE_GLOBAL_SHEET)
124
+ ) {
121
125
  state.sheetNames.add(spec.local.name);
122
126
  }
123
127
  });
@@ -208,6 +212,8 @@ export function createExtractPlugin(args: PluginArgs) {
208
212
 
209
213
  const chain = extractStyleChain(path.node, state.styleNames, state.sheetNames);
210
214
  if (!chain) return;
215
+ chain.global = chain.kind === 'sheet' && state.imports.get(chain.rootName)?.name === FN_CREATE_GLOBAL_SHEET;
216
+ if (chain.global) chain.sheetId = state.fileId + ':' + path.node.start;
211
217
 
212
218
  if (
213
219
  chain.kind === 'slot' &&
@@ -256,6 +262,13 @@ export function createExtractPlugin(args: PluginArgs) {
256
262
  return;
257
263
  }
258
264
 
265
+ if (chain.global) {
266
+ if (path.parentPath.isExpressionStatement()) path.parentPath.remove();
267
+ else path.replaceWith(t.unaryExpression('void', t.numericLiteral(0)));
268
+ path.skip();
269
+ return;
270
+ }
271
+
259
272
  const replacement = createChainReplacement({
260
273
  t,
261
274
  path,
@@ -350,30 +363,37 @@ function pruneUnusedStyleInputDeclarations(
350
363
  path: BabelCore.NodePath<BabelTypes.Program>,
351
364
  state: PluginState,
352
365
  ) {
353
- path.scope.crawl();
354
-
355
- path.traverse({
356
- VariableDeclarator(declaratorPath) {
357
- const node = declaratorPath.node;
358
-
359
- if (declaratorPath.parentPath?.parentPath?.isExportNamedDeclaration()) return;
360
- if (node.id.type !== 'Identifier') return;
361
- if (!isStyleInputCall(node.init, state)) return;
362
-
363
- const binding = declaratorPath.scope.getBinding(node.id.name);
364
- if (!binding || binding.referencePaths.length) return;
365
-
366
- const declarationPath = declaratorPath.parentPath;
367
- if (!declarationPath?.isVariableDeclaration()) return;
368
-
369
- if (declarationPath.node.declarations.length > 1) {
370
- declaratorPath.remove();
371
- } else {
372
- declarationPath.remove();
373
- }
374
- },
375
- });
376
-
366
+ const dependencies = new Set<BabelTypes.VariableDeclarator>();
367
+ let changed: boolean;
368
+ do {
369
+ changed = false;
370
+ path.scope.crawl();
371
+ path.traverse({
372
+ VariableDeclarator(declaratorPath) {
373
+ const node = declaratorPath.node;
374
+ if (declaratorPath.parentPath?.parentPath?.isExportNamedDeclaration()) return;
375
+ if (node.id.type !== 'Identifier') return;
376
+ const binding = declaratorPath.scope.getBinding(node.id.name);
377
+ if (!binding || !binding.constant || binding.referencePaths.length) return;
378
+ if (
379
+ !isStyleInputCall(node.init, state) &&
380
+ !(dependencies.has(node) && declaratorPath.get('init').isPure())
381
+ ) return;
382
+
383
+ declaratorPath.get('init').traverse({
384
+ ReferencedIdentifier(reference) {
385
+ const dependency = reference.scope.getBinding(reference.node.name);
386
+ if (dependency?.path.isVariableDeclarator()) dependencies.add(dependency.path.node);
387
+ },
388
+ });
389
+ const declarationPath = declaratorPath.parentPath;
390
+ if (!declarationPath?.isVariableDeclaration()) return;
391
+ if (declarationPath.node.declarations.length > 1) declaratorPath.remove();
392
+ else declarationPath.remove();
393
+ changed = true;
394
+ },
395
+ });
396
+ } while (changed);
377
397
  path.scope.crawl();
378
398
  }
379
399
 
@@ -383,6 +403,12 @@ function isStyleInputCall(
383
403
  ) {
384
404
  if (!node || node.type !== 'CallExpression') return false;
385
405
 
406
+ const selectorChain = extractStyleChain(node, state.styleNames, state.sheetNames);
407
+ if (selectorChain?.kind === 'selector') {
408
+ return selectorChain.baseArgs.every((arg) => evaluateNode(arg, getEvalScope(state)).ok) &&
409
+ selectorChain.methods.every((method) => method.args.every((arg) => evaluateNode(arg, getEvalScope(state)).ok));
410
+ }
411
+
386
412
  const callee = node.callee;
387
413
  if (callee.type !== 'MemberExpression' || callee.computed) return false;
388
414
  if (callee.object.type !== 'Identifier') return false;
@@ -2,6 +2,8 @@ import {
2
2
  FN_BIND_SCOPE,
3
3
  FN_COMBINE_SCOPE,
4
4
  FN_COMBINE_STYLE,
5
+ FN_CREATE_GLOBAL_SHEET,
6
+ FN_CREATE_SHEET,
5
7
  FN_CREATE_THEME,
6
8
  FN_CREATE_TOKEN,
7
9
  FN_CREATE_TOKENS,
@@ -132,5 +134,6 @@ function isCompilerHandledImport(
132
134
  name: string,
133
135
  ) {
134
136
  return IMPORT_PATHS.includes(source) &&
135
- [FN_CREATE_THEME, FN_CREATE_TOKEN, FN_CREATE_TOKENS, FN_CREATE_VALUES].includes(name);
137
+ [FN_CREATE_THEME, FN_CREATE_TOKEN, FN_CREATE_TOKENS, FN_CREATE_VALUES, FN_CREATE_SHEET, FN_CREATE_GLOBAL_SHEET]
138
+ .includes(name);
136
139
  }
@@ -112,8 +112,8 @@ function buildSheetOptions(
112
112
  ),
113
113
  );
114
114
  }
115
- if (options.weight !== undefined) {
116
- properties.push(t.objectProperty(t.identifier('weight'), t.numericLiteral(options.weight)));
115
+ if (options.specificity !== undefined) {
116
+ properties.push(t.objectProperty(t.identifier('specificity'), t.numericLiteral(options.specificity)));
117
117
  }
118
118
 
119
119
  return t.objectExpression(properties);
@@ -60,7 +60,7 @@ export function babelTransform(args: BabelTransformArgs): BabelTransformResult |
60
60
  throw error;
61
61
  }
62
62
 
63
- if (!result || !result.code) return null;
63
+ if (!result || result.code == null) return null;
64
64
 
65
65
  return {
66
66
  code: result.code,
@@ -61,6 +61,7 @@ export const FN_CREATE_COUNTER_STYLE = 'createCounterStyle';
61
61
  export const FN_CREATE_PROPERTY = 'createProperty';
62
62
  export const FN_FONT_SRC = 'fontSrc';
63
63
  export const FN_CREATE_SHEET = 'createSheet';
64
+ export const FN_CREATE_GLOBAL_SHEET = 'createGlobalSheet';
64
65
 
65
66
  export const FN_CREATE_EXTRACTED_STYLE = 'createExtractedStyle';
66
67
  export const FN_CREATE_EXTRACTED_SHEET = 'createExtractedSheet';
@@ -11,6 +11,7 @@ import type {
11
11
 
12
12
  export type CssLayerTargets = {
13
13
  style?: boolean;
14
+ /** @deprecated Set layer on each sheet; this legacy field is ignored. */
14
15
  sheet?: boolean;
15
16
  };
16
17
 
@@ -58,9 +59,10 @@ export function isSheetLayerOption(value: unknown): value is boolean | string |
58
59
  export function resolveSheetLayerOption(
59
60
  layer: boolean | string,
60
61
  namespace: string,
61
- ): 'sheet' | false | NamedSheetLayer {
62
- if (typeof layer !== 'string') return layer ? 'sheet' : false;
63
- return { name: layer.startsWith('.') ? (namespace ? namespace + layer : layer.slice(1)) : layer };
62
+ mainLayerEnabled = isStyleLayerEnabled(),
63
+ ): 'style' | false | NamedSheetLayer {
64
+ if (typeof layer !== 'string') return layer && mainLayerEnabled ? 'style' : false;
65
+ return { name: layer.startsWith('.') ? (mainLayerEnabled && namespace ? namespace + layer : layer.slice(1)) : layer };
64
66
  }
65
67
 
66
68
  export function isSheetLayerEnabled(layer: CssConfig['layer'] = CSS_CONFIG.layer) {
@@ -3,6 +3,7 @@ import { setStyleCheckOptions, type StyleCheckOptions } from './config/check';
3
3
  import { CSS_CONFIG, type CssConfig } from './config/css';
4
4
  import { setDebugClassNameEnabled } from './config/debug';
5
5
  import { RUNTIME_CONFIG } from './config/runtime';
6
+ import { setRuntimeDocument } from './document';
6
7
  import { getCacheTTL } from './utils';
7
8
 
8
9
  export type { CheckImportantOptions, StyleCheckLevel, StyleCheckOptions } from './config/check';
@@ -12,12 +13,15 @@ export type RuntimeCssOptions = Partial<CssConfig> & {
12
13
  };
13
14
 
14
15
  export type ConfigureStyleRuntimeOptions = {
16
+ /** false disables stylesheet injection; true uses the global document (default). */
17
+ document?: boolean | Document;
15
18
  css?: RuntimeCssOptions;
16
19
  check?: StyleCheckOptions;
17
20
  cacheTTL?: boolean | number;
18
21
  };
19
22
 
20
23
  export function configureStyleRuntime(options: ConfigureStyleRuntimeOptions = {}) {
24
+ if (options.document !== undefined) setRuntimeDocument(options.document);
21
25
  if (options.css) {
22
26
  checkBuildConfig('css');
23
27
  const { debugClassName, ...css } = options.css;
@@ -0,0 +1,23 @@
1
+ import { globalData } from '../utils/global';
2
+
3
+ const state = globalData<{
4
+ target: boolean | Document;
5
+ listeners: Set<() => void>;
6
+ }>('config.document', () => ({ target: true, listeners: new Set() }));
7
+
8
+ export function getRuntimeDocument(documentOverride?: Document): Document | null {
9
+ if (state.target === false) return null;
10
+ if (state.target !== true) return state.target;
11
+ if (documentOverride) return documentOverride;
12
+ return typeof globalThis.document === 'undefined' ? null : globalThis.document;
13
+ }
14
+
15
+ export function setRuntimeDocument(target: boolean | Document) {
16
+ if (state.target === target) return;
17
+ state.target = target;
18
+ state.listeners.forEach((listener) => listener());
19
+ }
20
+
21
+ export function onRuntimeDocumentChange(listener: () => void) {
22
+ state.listeners.add(listener);
23
+ }
@@ -0,0 +1,66 @@
1
+ import { type DebugData, isDebugData, type SelectorData, type SelectorOverrideData } from '../builder/data';
2
+ import { BUILDER_CALLSITE } from '../builder/data';
3
+ import { CSS_CONFIG, CSS_CONFIG_DEFAULT } from '../config/config/css';
4
+ import { collectStylePropSheetRules, getGlobalSheet } from '../runtime/sheet';
5
+ import { hashString } from '../utils/hash';
6
+ import { buildSheet } from './sheet';
7
+
8
+ export type CreateGlobalSheetOptions = { layer?: boolean | string; order?: number; };
9
+ export type GlobalSheetItem<Style = unknown> =
10
+ | false
11
+ | null
12
+ | undefined
13
+ | SelectorData<Style>
14
+ | SelectorOverrideData<Style>
15
+ | readonly GlobalSheetItem<Style>[];
16
+
17
+ export function createGlobalSheet<Style = unknown>(items?: GlobalSheetItem<Style>): void;
18
+ export function createGlobalSheet<Style = unknown>(
19
+ options: CreateGlobalSheetOptions,
20
+ items: GlobalSheetItem<Style>,
21
+ ): void;
22
+ export function createGlobalSheet<Style = unknown>(
23
+ optionsOrItems?: CreateGlobalSheetOptions | GlobalSheetItem<Style>,
24
+ items?: GlobalSheetItem<Style> | DebugData,
25
+ debug?: DebugData,
26
+ ): void {
27
+ const rules = buildGlobalSheetRules(optionsOrItems, items, debug, arguments.length >= 2 && !isDebugData(items));
28
+ const sheet = getGlobalSheet();
29
+ sheet.updateLayers(CSS_CONFIG.layers ?? CSS_CONFIG_DEFAULT.layers ?? []);
30
+ for (const rule of rules) sheet.insert(rule);
31
+ sheet.flush();
32
+ }
33
+
34
+ export function buildGlobalSheetRules<Style>(
35
+ optionsOrItems?: CreateGlobalSheetOptions | GlobalSheetItem<Style>,
36
+ items?: GlobalSheetItem<Style> | DebugData,
37
+ debug?: DebugData,
38
+ hasOptions = arguments.length >= 2 && !isDebugData(items),
39
+ ) {
40
+ const options = hasOptions ? optionsOrItems as CreateGlobalSheetOptions : {};
41
+ if (
42
+ !options || typeof options !== 'object' || Object.keys(options).some((key) => key !== 'layer' && key !== 'order')
43
+ ) {
44
+ throw new Error('createGlobalSheet only supports layer and order options');
45
+ }
46
+ if (options.order !== undefined && !Number.isFinite(options.order)) {
47
+ throw new Error('createGlobalSheet order must be a finite number');
48
+ }
49
+ const data = buildSheet(
50
+ { layer: options.layer },
51
+ hasOptions ? items as GlobalSheetItem<Style> : optionsOrItems as GlobalSheetItem<Style>,
52
+ isDebugData(items) ? items : debug,
53
+ true,
54
+ );
55
+ const rules = collectStylePropSheetRules(data);
56
+ // Only injected debug locations reliably identify a callsite in bundled code.
57
+ const site = (isDebugData(items) || debug) ? data[BUILDER_CALLSITE] : null;
58
+ const id = hashString(
59
+ JSON.stringify(site ? [site.filePath, site.line, site.column] : [options, rules.map((rule) => rule.css)]),
60
+ );
61
+ const globals = [];
62
+ for (const rule of rules) {
63
+ globals.push({ ...rule, key: id + ':' + rule.key, globalSheet: { id, order: options.order ?? 0 } });
64
+ }
65
+ return globals;
66
+ }
package/css/index.ts CHANGED
@@ -3,8 +3,11 @@ export type { CSS, CSSProperties, CSSPropertyName } from '../atomic/utils/types'
3
3
  export * from './counterStyle';
4
4
  export * from './fontFace';
5
5
  export * from './fontPaletteValues';
6
+ export { createGlobalSheet } from './globalSheet';
7
+ export type { CreateGlobalSheetOptions, GlobalSheetItem } from './globalSheet';
6
8
  export * from './keyframes';
7
9
  export * from './positionTry';
8
10
  export * from './property';
9
- export * from './sheet';
11
+ export { createSheet } from './sheet';
12
+ export type { CreateSheetOptions, SheetBuilder } from './sheet';
10
13
  export * from './styleTarget';