@fluentic/style 0.1.0-beta.13 → 0.1.0-beta.15
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.
- package/CHANGELOG.md +22 -0
- package/README.md +3 -2
- package/atomic/className.ts +4 -0
- package/atomic/rule.ts +15 -7
- package/atomic/token.ts +10 -1
- package/atomic/utils/selector.ts +12 -3
- package/builder/classname/class_name_builder.ts +1 -1
- package/builder/data/const.ts +2 -0
- package/builder/data/data.ts +1 -1
- package/builder/data/merge/scope.ts +7 -0
- package/builder/data/merge/style.ts +12 -3
- package/builder/data/state.ts +1 -0
- package/builder/extract/token.ts +10 -0
- package/builder/selector_override.ts +1 -1
- package/builder/selector_override_core.ts +17 -3
- package/builder/types/alias.ts +1 -1
- package/compiler/extract/extract.ts +21 -75
- package/compiler/extract/types.ts +4 -1
- package/compiler/transform/debug/plugin.ts +22 -0
- package/compiler/transform/evaluator/evaluator.ts +87 -10
- package/compiler/transform/evaluator/tracer.ts +4 -0
- package/compiler/transform/extract/chain/chain.ts +82 -22
- package/compiler/transform/extract/chain/extract_chain.ts +2 -0
- package/compiler/transform/extract/plugin.ts +81 -29
- package/compiler/transform/extract/utils/imports.ts +8 -1
- package/compiler/transform/extract/utils/replacement.ts +17 -5
- package/compiler/transform/extract/utils/state.ts +2 -0
- package/compiler/transform/extract/utils/token.ts +107 -0
- package/compiler/transform/utils/babel.ts +1 -1
- package/compiler/utils/constants.ts +2 -0
- package/config/config/css.ts +5 -3
- package/config/configure.ts +4 -0
- package/config/document.ts +23 -0
- package/css/globalSheet.ts +66 -0
- package/css/index.ts +4 -1
- package/css/sheet.ts +34 -14
- package/dialect/namedTokens.ts +13 -8
- package/dist/{className-yhJCGT0F.js → className-CC5PHcXI.js} +9 -2
- package/dist/className-CC5PHcXI.js.map +1 -0
- package/dist/{combine-yuoQ_qpx.js → combine-BpOQWCtM.js} +5 -5
- package/dist/combine-BpOQWCtM.js.map +1 -0
- package/dist/compiler/index.mjs +1 -1
- package/dist/{compiler-BEHxZYjz.mjs → compiler-AOb_VaKQ.mjs} +626 -188
- package/dist/compiler-AOb_VaKQ.mjs.map +1 -0
- package/dist/config/index.js +2 -2
- package/dist/{config-B5nEd-TV.js → config-B70LIQhi.js} +2 -2
- package/dist/{config-B5nEd-TV.js.map → config-B70LIQhi.js.map} +1 -1
- package/dist/{config-BWGBkVrM.js → config-BF-mxuPk.js} +4 -4
- package/dist/{config-BWGBkVrM.js.map → config-BF-mxuPk.js.map} +1 -1
- package/dist/config-B_OQYZSm.js +57 -0
- package/dist/config-B_OQYZSm.js.map +1 -0
- package/dist/{css-BQRIvzwZ.js → css-C7tcD3IO.js} +615 -213
- package/dist/css-C7tcD3IO.js.map +1 -0
- package/dist/css-Cdxkur4h.js +414 -0
- package/dist/css-Cdxkur4h.js.map +1 -0
- package/dist/{css-p_5ZNny_.js → css-RohOR3Vq.js} +112 -73
- package/dist/css-RohOR3Vq.js.map +1 -0
- package/dist/css.js +2 -2
- package/dist/css_extra-BC1Z_hDy.js +8 -0
- package/dist/{css_extra-DuVzUIYx.js.map → css_extra-BC1Z_hDy.js.map} +1 -1
- package/dist/{css_extra-DuVzUIYx.js → css_extra-CuzJtAR_.js} +2 -2
- package/dist/css_extra-CuzJtAR_.js.map +1 -0
- package/dist/{data-QXDBLlWs.js → data-Bw3Xod5J.js} +28 -20
- package/dist/data-Bw3Xod5J.js.map +1 -0
- package/dist/{debug-CkgcZDaX.js → debug-CVO3xx4C.js} +24 -3
- package/dist/debug-CVO3xx4C.js.map +1 -0
- package/dist/dev/rsc.js +134 -25
- package/dist/dev/rsc.js.map +1 -1
- package/dist/{dev-DocaGP3_.js → dev-BnQXPLQB.js} +6 -7
- package/dist/{dev-DocaGP3_.js.map → dev-BnQXPLQB.js.map} +1 -1
- package/dist/dev.js +1 -1
- package/dist/dialect/extracted/index.js +1 -1
- package/dist/dialect/index.js +1 -1
- package/dist/{elementMarker-DZjd1NuA.js → elementMarker-BrHXg161.js} +334 -54
- package/dist/elementMarker-BrHXg161.js.map +1 -0
- package/dist/entry/dev/adapter/preact.js +1 -1
- package/dist/entry/dev/adapter/react.js +1 -1
- package/dist/entry/dev/adapter/solid.js +1 -1
- package/dist/entry/dev/css.js +3 -3
- package/dist/entry/dev/jsx-dev-runtime.js +2 -2
- package/dist/entry/dev/jsx-runtime.js +2 -2
- package/dist/entry/dev.js +11 -11
- package/dist/entry/prod/adapter/preact.js +1 -1
- package/dist/entry/prod/adapter/react.js +1 -1
- package/dist/entry/prod/adapter/solid.js +1 -1
- package/dist/entry/prod/css.js +3 -3
- package/dist/entry/prod/extract.js +10 -1
- package/dist/entry/prod/extract.js.map +1 -1
- package/dist/entry/prod.js +3 -3
- package/dist/entry/rsc-dev/adapter/preact.js +1 -1
- package/dist/entry/rsc-dev/adapter/react.js +1 -1
- package/dist/entry/rsc-dev/adapter/solid.js +1 -1
- package/dist/entry/rsc-dev/css.js +4 -3
- package/dist/entry/rsc-dev/dev.js +129 -24
- package/dist/entry/rsc-dev/dev.js.map +1 -1
- package/dist/entry/rsc-dev/jsx-dev-runtime.js +5 -4
- package/dist/entry/rsc-dev/jsx-dev-runtime.js.map +1 -1
- package/dist/entry/rsc-dev/jsx-runtime.js +2 -2
- package/dist/entry/rsc-dev.js +8 -7
- package/dist/entry/rsc-dev.js.map +1 -1
- package/dist/entry/rsc-prod/css.js +4 -4
- package/dist/entry/rsc-prod.js +14 -5
- package/dist/entry/rsc-prod.js.map +1 -1
- package/dist/{rules-znG9bsKI.js → env-D6daex-9.js} +64 -20
- package/dist/env-D6daex-9.js.map +1 -0
- package/dist/{getClassName-DtkplEIt.js → getClassName-5yYUibKw.js} +2 -2
- package/dist/{getClassName-DtkplEIt.js.map → getClassName-5yYUibKw.js.map} +1 -1
- package/dist/getClassName-9CsXbNls.js.map +1 -1
- package/dist/{getClassName-BIqt1S41.js → getClassName-B3azD1TO.js} +6 -4
- package/dist/getClassName-B3azD1TO.js.map +1 -0
- package/dist/{getClassName-BB_L7U_v.js → getClassName-m5DOkMFQ.js} +4 -5
- package/dist/{getClassName-BB_L7U_v.js.map → getClassName-m5DOkMFQ.js.map} +1 -1
- package/dist/global-DeIYtcdl.js +36 -0
- package/dist/global-DeIYtcdl.js.map +1 -0
- package/dist/{css-CGMAis1n.js → globalSheet-CdgVpvCb.js} +185 -426
- package/dist/globalSheet-CdgVpvCb.js.map +1 -0
- package/dist/{debug-0iaVEC7z.js → hash-DCJkLls_.js} +168 -6
- package/dist/hash-DCJkLls_.js.map +1 -0
- package/dist/index.js +9 -9
- package/dist/jsx/jsx-dev-runtime.js +1 -1
- package/dist/jsx/jsx-dev-runtime.server.js +3 -3
- package/dist/jsx/jsx-dev-runtime.server.js.map +1 -1
- package/dist/jsx/jsx-runtime.js +1 -1
- package/dist/jsx/jsx-runtime.server.js +4 -4
- package/dist/jsx/jsx-runtime.server.js.map +1 -1
- package/dist/{jsx-BCufpzdb.js → jsx-CvloSSpb.js} +4 -4
- package/dist/{jsx-BCufpzdb.js.map → jsx-CvloSSpb.js.map} +1 -1
- package/dist/jsx_runtime-pt7DOZOE.js +13 -0
- package/dist/jsx_runtime-pt7DOZOE.js.map +1 -0
- package/dist/{loader-vMHuD1zT.mjs → loader-fAuIjIik.mjs} +3 -3
- package/dist/{loader-vMHuD1zT.mjs.map → loader-fAuIjIik.mjs.map} +1 -1
- package/dist/{misc-9EGKYkZo.mjs → misc-CyZgGtc9.mjs} +3 -3
- package/dist/{misc-9EGKYkZo.mjs.map → misc-CyZgGtc9.mjs.map} +1 -1
- package/dist/{namedTokens-DnpyC5XT.js → namedTokens-DwgmUMBM.js} +13 -9
- package/dist/namedTokens-DwgmUMBM.js.map +1 -0
- package/dist/plugin/farm/index.mjs +3 -3
- package/dist/plugin/nextjs/index.mjs +4 -4
- package/dist/plugin/nextjs/loader.mjs +7 -5
- package/dist/plugin/nextjs/loader.mjs.map +1 -1
- package/dist/plugin/parcel/index.cjs +1 -1
- package/dist/plugin/parcel/index.mjs +2 -2
- package/dist/plugin/parcel/optimizer.cjs +1 -1
- package/dist/plugin/parcel/optimizer.mjs +2 -2
- package/dist/plugin/parcel/resolver.cjs +1 -1
- package/dist/plugin/parcel/resolver.mjs +2 -2
- package/dist/plugin/parcel/runtime.cjs +1 -1
- package/dist/plugin/parcel/runtime.mjs +1 -1
- package/dist/plugin/parcel/transformer.cjs +1 -1
- package/dist/plugin/parcel/transformer.mjs +2 -2
- package/dist/plugin/rspack/index.mjs +2 -2
- package/dist/plugin/vite/index.mjs +3 -3
- package/dist/plugin/webpack/index.mjs +2 -2
- package/dist/plugin/webpack/loader.mjs +2 -2
- package/dist/presets/tailwind/index.js +3 -3
- package/dist/{registry-DVB7n6V-.mjs → registry-BMijh1CM.mjs} +2 -2
- package/dist/{registry-DVB7n6V-.mjs.map → registry-BMijh1CM.mjs.map} +1 -1
- package/dist/{resolveClassNameRuntime-DvH6j_4N.js → resolveClassNameRuntime-B6vKNL5y.js} +2 -2
- package/dist/{resolveClassNameRuntime-DvH6j_4N.js.map → resolveClassNameRuntime-B6vKNL5y.js.map} +1 -1
- package/dist/server.js +87 -17
- package/dist/server.js.map +1 -1
- package/dist/{shared-O-5Fcsxa.mjs → shared-BfASWZo1.mjs} +4 -4
- package/dist/{shared-O-5Fcsxa.mjs.map → shared-BfASWZo1.mjs.map} +1 -1
- package/dist/{shared-DaEDCb8I.cjs → shared-DY0kuBcN.cjs} +622 -184
- package/dist/shared-DY0kuBcN.cjs.map +1 -0
- package/dist/sheet-B-5idGtZ.js +9 -0
- package/dist/sheet-B-5idGtZ.js.map +1 -0
- package/dist/{config-Bqe8Y-4_.js → sheet-C6ymGhKV.js} +23 -2
- package/dist/sheet-C6ymGhKV.js.map +1 -0
- package/dist/sheet-D4f9KYPf.js +1 -0
- package/dist/{sidecar-DiYLwXbk.mjs → sidecar-cCzTDkzg.mjs} +3 -3
- package/dist/{sidecar-DiYLwXbk.mjs.map → sidecar-cCzTDkzg.mjs.map} +1 -1
- package/dist/{style-CtXEZqgx.js → style-a6ccye6R.js} +12 -13
- package/dist/style-a6ccye6R.js.map +1 -0
- package/dist/styleStore-Ceoaqa5U.js +45 -0
- package/dist/styleStore-Ceoaqa5U.js.map +1 -0
- package/dist/{env-DJyXPJ9q.js → styleStore-D1IEmq1v.js} +439 -63
- package/dist/styleStore-D1IEmq1v.js.map +1 -0
- package/dist/{token-DyLO6Hnf.js → token-Ci73NE6h.js} +5 -33
- package/dist/token-Ci73NE6h.js.map +1 -0
- package/dist/{trace-C1_6fM21.js → trace-DDsvwdF0.js} +3 -3
- package/dist/{trace-C1_6fM21.js.map → trace-DDsvwdF0.js.map} +1 -1
- package/dist/{trace-Bsh-Kkg_.js → trace-uHVvnYiw.js} +2 -2
- package/dist/{trace-Bsh-Kkg_.js.map → trace-uHVvnYiw.js.map} +1 -1
- package/dist/{transform-8TIMiF5A.js → transform-BkxIouPX.js} +2 -2
- package/dist/{transform-8TIMiF5A.js.map → transform-BkxIouPX.js.map} +1 -1
- package/dist/types/atomic/className.d.ts +2 -2
- package/dist/types/atomic/utils/selector.d.ts +2 -1
- package/dist/types/builder/data/const.d.ts +1 -0
- package/dist/types/builder/data/data.d.ts +1 -1
- package/dist/types/builder/data/merge/utils.d.ts +6 -1
- package/dist/types/builder/data/state.d.ts +17 -2
- package/dist/types/builder/extract/token.d.ts +6 -1
- package/dist/types/builder/selector_override.d.ts +1 -1
- package/dist/types/builder/selector_override_core.d.ts +2 -0
- package/dist/types/builder/style_fns.d.ts +1 -1
- package/dist/types/builder/types/alias.d.ts +2 -2
- package/dist/types/builder/utils.d.ts +1 -1
- package/dist/types/compiler/extract/types.d.ts +7 -1
- package/dist/types/compiler/transform/evaluator/evaluator.d.ts +18 -1
- package/dist/types/compiler/transform/extract/chain/extract_chain.d.ts +2 -0
- package/dist/types/compiler/transform/extract/utils/replacement.d.ts +2 -0
- package/dist/types/compiler/transform/extract/utils/state.d.ts +1 -0
- package/dist/types/compiler/transform/extract/utils/token.d.ts +3 -0
- package/dist/types/compiler/transform/utils/selector.d.ts +1 -1
- package/dist/types/compiler/utils/constants.d.ts +2 -0
- package/dist/types/compiler/utils/import_source.d.ts +8 -2
- package/dist/types/config/config/css.d.ts +2 -1
- package/dist/types/config/configure.d.ts +2 -0
- package/dist/types/config/document.d.ts +3 -0
- package/dist/types/css/globalSheet.d.ts +24 -0
- package/dist/types/css/index.d.ts +4 -1
- package/dist/types/css/sheet.d.ts +3 -2
- package/dist/types/entry/rsc_dev/css.d.ts +1 -0
- package/dist/types/plugin/bundler/farm/plugin.d.ts +8 -2
- package/dist/types/presets/tailwind/selectors.d.ts +24 -24
- package/dist/types/presets/tailwind/theme.d.ts +361 -361
- package/dist/types/runtime/core/cache/itemWithResolver.d.ts +1 -1
- package/dist/types/runtime/core/cache/stateItem.d.ts +8 -2
- package/dist/types/runtime/rsc/constants.d.ts +2 -0
- package/dist/types/runtime/rsc/dev.d.ts +5 -0
- package/dist/types/runtime/rsc/getClassName.d.ts +3 -0
- package/dist/types/runtime/rsc/globalSheet.d.ts +22 -0
- package/dist/types/runtime/rsc/observer.d.ts +5 -0
- package/dist/types/runtime/rsc/styleStore.d.ts +2 -0
- package/dist/types/runtime/sheet/document.d.ts +3 -0
- package/dist/types/runtime/types.d.ts +4 -1
- package/dist/types/selector/presets/default.d.ts +28 -28
- package/dist/types/selector/presets/minimal.d.ts +10 -10
- package/dist/types/selector/selector.d.ts +15 -2
- package/dist/types/sheet/ordered.d.ts +4 -0
- package/dist/types/sheet/ordering.d.ts +15 -0
- package/dist/types/sheet/types.d.ts +7 -0
- package/dist/types/style/important.d.ts +2 -1
- package/dist/types/style/style.d.ts +95 -95
- package/dist/{utils-BBN9msTv.mjs → utils-BO6Ix8t5.mjs} +4 -4
- package/dist/{utils-BBN9msTv.mjs.map → utils-BO6Ix8t5.mjs.map} +1 -1
- package/dist/{utils-DoKJnvxk.js → utils-CB70kIh6.js} +3 -3
- package/dist/{utils-DoKJnvxk.js.map → utils-CB70kIh6.js.map} +1 -1
- package/dist/{utils-Bjh9pO87.mjs → utils-EG9gh2g3.mjs} +3 -3
- package/dist/{utils-Bjh9pO87.mjs.map → utils-EG9gh2g3.mjs.map} +1 -1
- package/dist/{utils-10MTZOuB.js → utils-sG7IWYP6.js} +1091 -643
- package/dist/utils-sG7IWYP6.js.map +1 -0
- package/dist/utils.js +3 -3
- package/dist/{value-Dg6ALjjj.js → value-B-ThmbY-.js} +47 -6
- package/dist/value-B-ThmbY-.js.map +1 -0
- package/dist/{webpack-C1j49Psk.mjs → webpack-WXAJ3IYn.mjs} +5 -5
- package/dist/{webpack-C1j49Psk.mjs.map → webpack-WXAJ3IYn.mjs.map} +1 -1
- package/entry/dev/sheet.ts +4 -1
- package/entry/rsc_dev/css.ts +2 -0
- package/jsx/rsc/jsx_dev_runtime.ts +11 -2
- package/jsx/rsc/jsx_runtime.ts +14 -3
- package/package.json +5 -4
- package/plugin/nextjs/loader.ts +18 -2
- package/runtime/core/elementMarker.ts +9 -3
- package/runtime/extract/getClassName.ts +1 -1
- package/runtime/rsc/constants.ts +3 -0
- package/runtime/rsc/dev.ts +31 -15
- package/runtime/rsc/getClassName.ts +6 -0
- package/runtime/rsc/globalSheet.ts +130 -0
- package/runtime/rsc/observer.ts +118 -15
- package/runtime/rsc/styleStore.ts +12 -36
- package/runtime/sheet/document.ts +28 -0
- package/runtime/sheet/global-prod.ts +3 -5
- package/runtime/sheet/global.ts +3 -5
- package/runtime/sheet/rule.ts +4 -2
- package/runtime/sheet/rules.ts +3 -0
- package/sheet/dev/dev_sort.ts +5 -1
- package/sheet/dev/index.ts +23 -3
- package/sheet/ordered.ts +188 -0
- package/sheet/ordering.ts +138 -0
- package/sheet/prod.ts +17 -5
- package/sheet/types.ts +4 -0
- package/style/important.ts +3 -1
- package/style/style.ts +1 -1
- package/style/token.ts +2 -0
- package/utils/trace.ts +1 -0
- package/dist/className-yhJCGT0F.js.map +0 -1
- package/dist/combine-yuoQ_qpx.js.map +0 -1
- package/dist/compiler-BEHxZYjz.mjs.map +0 -1
- package/dist/config-Bqe8Y-4_.js.map +0 -1
- package/dist/config-DggQEE-4.js +0 -36
- package/dist/config-DggQEE-4.js.map +0 -1
- package/dist/createTransformElement-B2jSnugo.js +0 -34
- package/dist/createTransformElement-B2jSnugo.js.map +0 -1
- package/dist/css-BQRIvzwZ.js.map +0 -1
- package/dist/css-CGMAis1n.js.map +0 -1
- package/dist/css-D7eTqvMH.js +0 -57
- package/dist/css-D7eTqvMH.js.map +0 -1
- package/dist/css-p_5ZNny_.js.map +0 -1
- package/dist/data-QXDBLlWs.js.map +0 -1
- package/dist/debug-0iaVEC7z.js.map +0 -1
- package/dist/debug-CkgcZDaX.js.map +0 -1
- package/dist/elementMarker-DZjd1NuA.js.map +0 -1
- package/dist/env-DJyXPJ9q.js.map +0 -1
- package/dist/getClassName-BIqt1S41.js.map +0 -1
- package/dist/global-CBQGormL.js +0 -14
- package/dist/global-CBQGormL.js.map +0 -1
- package/dist/hash-Cr-LCWDt.js +0 -166
- package/dist/hash-Cr-LCWDt.js.map +0 -1
- package/dist/jsx_runtime-Bu_A8mr4.js +0 -12
- package/dist/jsx_runtime-Bu_A8mr4.js.map +0 -1
- package/dist/namedTokens-DnpyC5XT.js.map +0 -1
- package/dist/rules-znG9bsKI.js.map +0 -1
- package/dist/shared-DaEDCb8I.cjs.map +0 -1
- package/dist/sheet-SlZRjOmw.js +0 -7
- package/dist/sheet-SlZRjOmw.js.map +0 -1
- package/dist/style-CtXEZqgx.js.map +0 -1
- package/dist/styleStore-BImBZdt6.js +0 -57
- package/dist/styleStore-BImBZdt6.js.map +0 -1
- package/dist/styleStore-CBan0gHQ.js +0 -60
- package/dist/styleStore-CBan0gHQ.js.map +0 -1
- package/dist/token-DyLO6Hnf.js.map +0 -1
- package/dist/utils-10MTZOuB.js.map +0 -1
- package/dist/value-Dg6ALjjj.js.map +0 -1
|
@@ -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,
|
|
@@ -15,7 +16,12 @@ import {
|
|
|
15
16
|
} from '../../utils/constants';
|
|
16
17
|
import { createImportSourceMatcher } from '../../utils/import_source';
|
|
17
18
|
import { normalizePath } from '../../utils/path';
|
|
18
|
-
import {
|
|
19
|
+
import {
|
|
20
|
+
COMPILED_TOKEN_REFERENCE,
|
|
21
|
+
type CompiledTokenReference,
|
|
22
|
+
evaluateEnumDeclaration,
|
|
23
|
+
evaluateNode,
|
|
24
|
+
} from '../evaluator/evaluator';
|
|
19
25
|
import { getImportedName } from '../syntax';
|
|
20
26
|
import { annotateAtRuleDeclaration } from '../syntax/static_ids';
|
|
21
27
|
import { BabelCore } from '../utils/babel';
|
|
@@ -28,7 +34,7 @@ import { buildReplacement } from './utils/replacement';
|
|
|
28
34
|
import { recordCompiledBinding } from './utils/slot';
|
|
29
35
|
import { type ExtractPluginState, getEvalScope, type HoistedDeclaration } from './utils/state';
|
|
30
36
|
import { compileThemeCall } from './utils/theme';
|
|
31
|
-
import { annotateTokenDeclaration } from './utils/token';
|
|
37
|
+
import { annotateTokenDeclaration, compileTokenFactory } from './utils/token';
|
|
32
38
|
|
|
33
39
|
export type PluginState = BabelCore.PluginPass & ExtractPluginState;
|
|
34
40
|
|
|
@@ -59,6 +65,7 @@ export function createExtractPlugin(args: PluginArgs) {
|
|
|
59
65
|
|
|
60
66
|
return {
|
|
61
67
|
pre(this) {
|
|
68
|
+
this.tokenFactoryReplacements = new Map();
|
|
62
69
|
this.styleNames = new Set();
|
|
63
70
|
this.sheetNames = new Set();
|
|
64
71
|
this.styleMetas = new Map();
|
|
@@ -111,7 +118,10 @@ export function createExtractPlugin(args: PluginArgs) {
|
|
|
111
118
|
state.styleMetas.set(spec.local.name, meta);
|
|
112
119
|
}
|
|
113
120
|
|
|
114
|
-
if (
|
|
121
|
+
if (
|
|
122
|
+
sourceName === STYLE_CSS_IMPORT_PATH &&
|
|
123
|
+
(imported === FN_CREATE_SHEET || imported === FN_CREATE_GLOBAL_SHEET)
|
|
124
|
+
) {
|
|
115
125
|
state.sheetNames.add(spec.local.name);
|
|
116
126
|
}
|
|
117
127
|
});
|
|
@@ -161,6 +171,14 @@ export function createExtractPlugin(args: PluginArgs) {
|
|
|
161
171
|
},
|
|
162
172
|
|
|
163
173
|
CallExpression(path, state) {
|
|
174
|
+
if (mode === 'extract') {
|
|
175
|
+
try {
|
|
176
|
+
const tokenFactory = compileTokenFactory(path.node, state, t);
|
|
177
|
+
if (tokenFactory) state.tokenFactoryReplacements.set(path.node, tokenFactory);
|
|
178
|
+
} catch (error) {
|
|
179
|
+
throw path.buildCodeFrameError(error instanceof Error ? error.message : String(error));
|
|
180
|
+
}
|
|
181
|
+
}
|
|
164
182
|
if (
|
|
165
183
|
path.parent.type === 'MemberExpression' &&
|
|
166
184
|
!(path.parent.computed)
|
|
@@ -194,6 +212,8 @@ export function createExtractPlugin(args: PluginArgs) {
|
|
|
194
212
|
|
|
195
213
|
const chain = extractStyleChain(path.node, state.styleNames, state.sheetNames);
|
|
196
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;
|
|
197
217
|
|
|
198
218
|
if (
|
|
199
219
|
chain.kind === 'slot' &&
|
|
@@ -242,6 +262,13 @@ export function createExtractPlugin(args: PluginArgs) {
|
|
|
242
262
|
return;
|
|
243
263
|
}
|
|
244
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
|
+
|
|
245
272
|
const replacement = createChainReplacement({
|
|
246
273
|
t,
|
|
247
274
|
path,
|
|
@@ -270,6 +297,15 @@ export function createExtractPlugin(args: PluginArgs) {
|
|
|
270
297
|
exit(path, state) {
|
|
271
298
|
if (mode === 'collect') return;
|
|
272
299
|
|
|
300
|
+
path.traverse({
|
|
301
|
+
CallExpression(factoryPath) {
|
|
302
|
+
const replacement = state.tokenFactoryReplacements.get(factoryPath.node);
|
|
303
|
+
if (!replacement) return;
|
|
304
|
+
factoryPath.replaceWith(replacement);
|
|
305
|
+
factoryPath.skip();
|
|
306
|
+
state.needsExtractImport = true;
|
|
307
|
+
},
|
|
308
|
+
});
|
|
273
309
|
pruneUnusedStyleInputDeclarations(path, state);
|
|
274
310
|
pruneUnusedStyleImports(path, state);
|
|
275
311
|
|
|
@@ -327,30 +363,37 @@ function pruneUnusedStyleInputDeclarations(
|
|
|
327
363
|
path: BabelCore.NodePath<BabelTypes.Program>,
|
|
328
364
|
state: PluginState,
|
|
329
365
|
) {
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
declaratorPath.
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
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);
|
|
354
397
|
path.scope.crawl();
|
|
355
398
|
}
|
|
356
399
|
|
|
@@ -360,6 +403,12 @@ function isStyleInputCall(
|
|
|
360
403
|
) {
|
|
361
404
|
if (!node || node.type !== 'CallExpression') return false;
|
|
362
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
|
+
|
|
363
412
|
const callee = node.callee;
|
|
364
413
|
if (callee.type !== 'MemberExpression' || callee.computed) return false;
|
|
365
414
|
if (callee.object.type !== 'Identifier') return false;
|
|
@@ -466,8 +515,11 @@ function createRuntimeTokenCollector(
|
|
|
466
515
|
|
|
467
516
|
return {
|
|
468
517
|
overrides,
|
|
469
|
-
addOverride(item: { valueNode: BabelTypes.Expression; }) {
|
|
470
|
-
|
|
518
|
+
addOverride(item: { valueNode: BabelTypes.Expression; value: unknown; }) {
|
|
519
|
+
const reference = (item.value as CompiledTokenReference)[COMPILED_TOKEN_REFERENCE];
|
|
520
|
+
overrides.push(
|
|
521
|
+
args.t.cloneNode(reference?.filePath === args.state.filePath ? reference.expression : item.valueNode, true),
|
|
522
|
+
);
|
|
471
523
|
},
|
|
472
524
|
add(item: object, valueNode: BabelTypes.Expression) {
|
|
473
525
|
if (canHoistRuntimeValue(args.path, valueNode)) {
|
|
@@ -2,7 +2,12 @@ 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,
|
|
8
|
+
FN_CREATE_TOKEN,
|
|
9
|
+
FN_CREATE_TOKENS,
|
|
10
|
+
FN_CREATE_VALUES,
|
|
6
11
|
FN_GET_CLASS_NAME,
|
|
7
12
|
FN_GET_TOKEN,
|
|
8
13
|
IMPORT_PATHS,
|
|
@@ -128,5 +133,7 @@ function isCompilerHandledImport(
|
|
|
128
133
|
source: string,
|
|
129
134
|
name: string,
|
|
130
135
|
) {
|
|
131
|
-
return IMPORT_PATHS.includes(source) &&
|
|
136
|
+
return IMPORT_PATHS.includes(source) &&
|
|
137
|
+
[FN_CREATE_THEME, FN_CREATE_TOKEN, FN_CREATE_TOKENS, FN_CREATE_VALUES, FN_CREATE_SHEET, FN_CREATE_GLOBAL_SHEET]
|
|
138
|
+
.includes(name);
|
|
132
139
|
}
|
|
@@ -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,
|
|
@@ -111,8 +112,8 @@ function buildSheetOptions(
|
|
|
111
112
|
),
|
|
112
113
|
);
|
|
113
114
|
}
|
|
114
|
-
if (options.
|
|
115
|
-
properties.push(t.objectProperty(t.identifier('
|
|
115
|
+
if (options.specificity !== undefined) {
|
|
116
|
+
properties.push(t.objectProperty(t.identifier('specificity'), t.numericLiteral(options.specificity)));
|
|
116
117
|
}
|
|
117
118
|
|
|
118
119
|
return t.objectExpression(properties);
|
|
@@ -352,7 +353,11 @@ function buildVariableValueExpression(
|
|
|
352
353
|
options: BuildReplacementOptions,
|
|
353
354
|
): BabelTypes.Expression {
|
|
354
355
|
if (isStyleTokenData(value)) {
|
|
355
|
-
|
|
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
|
+
}
|
|
356
361
|
return buildExtractedTokenExpression(t, value, state);
|
|
357
362
|
}
|
|
358
363
|
|
|
@@ -363,11 +368,16 @@ function buildVariableValueExpression(
|
|
|
363
368
|
return valueNode ? t.cloneNode(valueNode) : literalExpression(t, value);
|
|
364
369
|
}
|
|
365
370
|
|
|
366
|
-
function buildExtractedTokenExpression(
|
|
371
|
+
export function buildExtractedTokenExpression(
|
|
367
372
|
t: typeof BabelTypes,
|
|
368
373
|
token: StyleTokenData,
|
|
369
374
|
state: ExtractPluginState,
|
|
375
|
+
preserveReference = true,
|
|
370
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
|
+
}
|
|
371
381
|
state.usedHelpers.add(FN_CREATE_EXTRACTED_TOKEN);
|
|
372
382
|
const tokenNameFormat = state.options.css?.tokenNameFormat ?? DEFAULT_CONFIG.tokenNameFormat ?? null;
|
|
373
383
|
|
|
@@ -388,6 +398,8 @@ function buildExtractedTokenOverrideExpression(
|
|
|
388
398
|
token: StyleTokenOverride,
|
|
389
399
|
state: ExtractPluginState,
|
|
390
400
|
): BabelTypes.Expression {
|
|
401
|
+
const reference = (token as CompiledTokenReference)[COMPILED_TOKEN_REFERENCE];
|
|
402
|
+
if (reference?.filePath === state.filePath) return t.cloneNode(reference.expression, true);
|
|
391
403
|
state.usedHelpers.add(FN_CREATE_EXTRACTED_TOKEN);
|
|
392
404
|
const tokenNameFormat = state.options.css?.tokenNameFormat ?? DEFAULT_CONFIG.tokenNameFormat ?? null;
|
|
393
405
|
const extractedToken = t.callExpression(
|
|
@@ -420,5 +432,5 @@ function literalExpression(
|
|
|
420
432
|
if (typeof value === 'boolean') return t.booleanLiteral(value);
|
|
421
433
|
if (value === null || value === undefined) return t.nullLiteral();
|
|
422
434
|
|
|
423
|
-
return t.
|
|
435
|
+
return t.valueToNode(value) as BabelTypes.Expression;
|
|
424
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
|
}
|
|
@@ -1 +1,108 @@
|
|
|
1
|
+
import { isStyleTokenData } from '../../../../style/token';
|
|
2
|
+
import {
|
|
3
|
+
FN_CREATE_EXTRACTED_VALUES,
|
|
4
|
+
FN_CREATE_TOKEN,
|
|
5
|
+
FN_CREATE_TOKENS,
|
|
6
|
+
FN_CREATE_VALUES,
|
|
7
|
+
IMPORT_PATHS,
|
|
8
|
+
} from '../../../utils/constants';
|
|
9
|
+
import {
|
|
10
|
+
COMPILED_RUNTIME_VALUE,
|
|
11
|
+
type CompiledRuntimeValue,
|
|
12
|
+
evaluateNode,
|
|
13
|
+
isCompiledTokenFactory,
|
|
14
|
+
} from '../../evaluator/evaluator';
|
|
15
|
+
import { getObjectPropertyKey } from '../../syntax/utils';
|
|
16
|
+
import type { BabelTypes } from '../../utils/babel';
|
|
17
|
+
import { buildExtractedTokenExpression } from './replacement';
|
|
18
|
+
import { type ExtractPluginState, getEvalScope } from './state';
|
|
19
|
+
|
|
1
20
|
export { annotateTokenDeclaration } from '../../syntax/static_ids';
|
|
21
|
+
|
|
22
|
+
export function compileTokenFactory(
|
|
23
|
+
node: BabelTypes.CallExpression,
|
|
24
|
+
state: ExtractPluginState,
|
|
25
|
+
t: typeof BabelTypes,
|
|
26
|
+
): BabelTypes.Expression | null {
|
|
27
|
+
if (node.callee.type !== 'Identifier') return null;
|
|
28
|
+
const imp = state.imports.get(node.callee.name);
|
|
29
|
+
if (!imp || !IMPORT_PATHS.includes(imp.source)) return null;
|
|
30
|
+
if (![FN_CREATE_TOKEN, FN_CREATE_TOKENS, FN_CREATE_VALUES].includes(imp.name)) return null;
|
|
31
|
+
|
|
32
|
+
const inputValue = evaluateNode(node.arguments[0] as BabelTypes.Node, getEvalScope(state));
|
|
33
|
+
if (inputValue.ok && hasUnresolvedValue(inputValue.value)) {
|
|
34
|
+
throw new Error(`Cannot extract ${imp.name}: factory inputs must be statically resolvable`);
|
|
35
|
+
}
|
|
36
|
+
const result = evaluateNode(node, getEvalScope(state));
|
|
37
|
+
if (!result.ok) throw new Error(`Cannot extract ${imp.name}: ${result.reason}`);
|
|
38
|
+
|
|
39
|
+
if (isCompiledTokenFactory(result.value)) {
|
|
40
|
+
state.usedHelpers.add(FN_CREATE_EXTRACTED_VALUES);
|
|
41
|
+
const expression = t.callExpression(t.identifier(FN_CREATE_EXTRACTED_VALUES), [
|
|
42
|
+
t.arrayExpression([...result.value.tokens].map(([key, token]) =>
|
|
43
|
+
t.arrayExpression([
|
|
44
|
+
t.valueToNode(key) as BabelTypes.Expression,
|
|
45
|
+
buildExtractedTokenExpression(t, token, state, false),
|
|
46
|
+
])
|
|
47
|
+
)),
|
|
48
|
+
]);
|
|
49
|
+
t.addComment(expression, 'leading', '#__PURE__');
|
|
50
|
+
return expression;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const input = node.arguments[0] as BabelTypes.Expression;
|
|
54
|
+
if (imp.name === FN_CREATE_TOKEN) return buildGroup(result.value, input);
|
|
55
|
+
const raw = evaluateNode(input, getEvalScope(state));
|
|
56
|
+
const array = raw.ok && Array.isArray(raw.value) ? raw.value : null;
|
|
57
|
+
if (array) {
|
|
58
|
+
return t.objectExpression(
|
|
59
|
+
Object.entries(result.value as object).map(([key, token]) => {
|
|
60
|
+
let index = array.length - 1;
|
|
61
|
+
while (index >= 0 && String(array[index]) !== key) index--;
|
|
62
|
+
return t.objectProperty(
|
|
63
|
+
t.stringLiteral(key),
|
|
64
|
+
buildGroup(token, member(input, String(index))),
|
|
65
|
+
key === '__proto__',
|
|
66
|
+
);
|
|
67
|
+
}),
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
return buildGroup(result.value, input);
|
|
71
|
+
|
|
72
|
+
function buildGroup(value: unknown, source: BabelTypes.Expression): BabelTypes.Expression {
|
|
73
|
+
if (isStyleTokenData(value)) {
|
|
74
|
+
const expression = buildExtractedTokenExpression(t, value, state, false) as BabelTypes.CallExpression;
|
|
75
|
+
if (!value.ref) expression.arguments[1] = t.cloneNode(source, true);
|
|
76
|
+
t.addComment(expression, 'leading', '#__PURE__');
|
|
77
|
+
return expression;
|
|
78
|
+
}
|
|
79
|
+
if (!value || typeof value !== 'object') throw new Error(`Invalid ${imp!.name} token group`);
|
|
80
|
+
return t.objectExpression(
|
|
81
|
+
Object.entries(value).map(([key, child]) =>
|
|
82
|
+
t.objectProperty(t.stringLiteral(key), buildGroup(child, member(source, key)), key === '__proto__')
|
|
83
|
+
),
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
function member(source: BabelTypes.Expression, key: string): BabelTypes.Expression {
|
|
87
|
+
if (source.type === 'ObjectExpression') {
|
|
88
|
+
for (let index = source.properties.length - 1; index >= 0; index--) {
|
|
89
|
+
const property = source.properties[index]!;
|
|
90
|
+
if (property.type !== 'ObjectProperty' || property.computed) break;
|
|
91
|
+
if (getObjectPropertyKey(property) === key) return property.value as BabelTypes.Expression;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
if (
|
|
95
|
+
source.type === 'ArrayExpression' && !source.elements.some((item) => item?.type === 'SpreadElement') &&
|
|
96
|
+
source.elements[Number(key)] && t.isExpression(source.elements[Number(key)])
|
|
97
|
+
) {
|
|
98
|
+
return source.elements[Number(key)] as BabelTypes.Expression;
|
|
99
|
+
}
|
|
100
|
+
return t.memberExpression(t.cloneNode(source, true), t.stringLiteral(key), true);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function hasUnresolvedValue(value: unknown): boolean {
|
|
105
|
+
if (!value || typeof value !== 'object' || isStyleTokenData(value)) return false;
|
|
106
|
+
if ((value as CompiledRuntimeValue)[COMPILED_RUNTIME_VALUE]) return true;
|
|
107
|
+
return Object.values(value).some(hasUnresolvedValue);
|
|
108
|
+
}
|
|
@@ -61,12 +61,14 @@ 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';
|
|
67
68
|
export const FN_CREATE_EXTRACTED_SLOT = 'createExtractedSlot';
|
|
68
69
|
export const FN_CREATE_EXTRACTED_SCOPE = 'createExtractedScope';
|
|
69
70
|
export const FN_CREATE_EXTRACTED_TOKEN = 'createExtractedToken';
|
|
71
|
+
export const FN_CREATE_EXTRACTED_VALUES = 'createExtractedValues';
|
|
70
72
|
export const FN_CREATE_EXTRACTED_THEME = 'createExtractedTheme';
|
|
71
73
|
export const FN_GET_EXTRACTED_STYLE_ITEMS = 'getExtractedStyleItems';
|
|
72
74
|
export const FN_CREATE_EXTRACTED_STYLE_MERGE = 'createExtractedStyleMerge';
|
package/config/config/css.ts
CHANGED
|
@@ -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
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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) {
|
package/config/configure.ts
CHANGED
|
@@ -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
|
|
11
|
+
export { createSheet } from './sheet';
|
|
12
|
+
export type { CreateSheetOptions, SheetBuilder } from './sheet';
|
|
10
13
|
export * from './styleTarget';
|