@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
|
@@ -103,12 +103,18 @@ function symbol(name) {
|
|
|
103
103
|
}
|
|
104
104
|
//#endregion
|
|
105
105
|
//#region utils/global.ts
|
|
106
|
+
function getGlobalData(key) {
|
|
107
|
+
return globalThis[symbol(key)];
|
|
108
|
+
}
|
|
106
109
|
function globalData(key, data) {
|
|
107
110
|
const id = symbol(key);
|
|
108
111
|
const root = globalThis;
|
|
109
112
|
if (root[id] === void 0) assign(root, id, data());
|
|
110
113
|
return root[id];
|
|
111
114
|
}
|
|
115
|
+
function clearGlobalData(key) {
|
|
116
|
+
delete globalThis[symbol(key)];
|
|
117
|
+
}
|
|
112
118
|
function assign(target, id, value) {
|
|
113
119
|
Object.defineProperty(target, id, {
|
|
114
120
|
value,
|
|
@@ -118,10 +124,6 @@ function assign(target, id, value) {
|
|
|
118
124
|
});
|
|
119
125
|
}
|
|
120
126
|
//#endregion
|
|
121
|
-
//#region config/config/check.ts
|
|
122
|
-
const CHECK_CONFIG_DEFAULT = {};
|
|
123
|
-
const CHECK_CONFIG = globalData("config.check", () => ({ ...CHECK_CONFIG_DEFAULT }));
|
|
124
|
-
//#endregion
|
|
125
127
|
//#region config/config/css.ts
|
|
126
128
|
const CSS_CONFIG_DEFAULT = {
|
|
127
129
|
layer: true,
|
|
@@ -135,14 +137,15 @@ function isStyleLayerEnabled(layer = CSS_CONFIG.layer) {
|
|
|
135
137
|
function isSheetLayerOption(value) {
|
|
136
138
|
return value === void 0 || typeof value === "boolean" || typeof value === "string" && /^\.?(?:--|-?[a-zA-Z_\u0080-\uFFFF])[\w\u0080-\uFFFF-]*(?:\.(?:--|-?[a-zA-Z_\u0080-\uFFFF])[\w\u0080-\uFFFF-]*)*$/.test(value);
|
|
137
139
|
}
|
|
138
|
-
function resolveSheetLayerOption(layer, namespace) {
|
|
139
|
-
if (typeof layer !== "string") return layer ? "
|
|
140
|
-
return { name: layer.startsWith(".") ? namespace ? namespace + layer : layer.slice(1) : layer };
|
|
141
|
-
}
|
|
142
|
-
function isSheetLayerEnabled(layer = CSS_CONFIG.layer) {
|
|
143
|
-
return typeof layer === "object" && (layer.sheet ?? false);
|
|
140
|
+
function resolveSheetLayerOption(layer, namespace, mainLayerEnabled = isStyleLayerEnabled()) {
|
|
141
|
+
if (typeof layer !== "string") return layer && mainLayerEnabled ? "style" : false;
|
|
142
|
+
return { name: layer.startsWith(".") ? mainLayerEnabled && namespace ? namespace + layer : layer.slice(1) : layer };
|
|
144
143
|
}
|
|
145
144
|
//#endregion
|
|
145
|
+
//#region config/config/check.ts
|
|
146
|
+
const CHECK_CONFIG_DEFAULT = {};
|
|
147
|
+
const CHECK_CONFIG = globalData("config.check", () => ({ ...CHECK_CONFIG_DEFAULT }));
|
|
148
|
+
//#endregion
|
|
146
149
|
//#region config/utils.ts
|
|
147
150
|
const SIDECAR_URL_GLOBAL_SYMBOL = "FLUENTIC_STYLE_SIDECAR_URL";
|
|
148
151
|
function getCacheTTL(cache) {
|
|
@@ -173,6 +176,21 @@ const DEFAULT_DEBUG_CONFIG = {
|
|
|
173
176
|
};
|
|
174
177
|
const DEBUG_CONFIG = globalData("config.debug", () => ({ ...DEFAULT_DEBUG_CONFIG }));
|
|
175
178
|
//#endregion
|
|
179
|
+
//#region config/document.ts
|
|
180
|
+
const state$1 = globalData("config.document", () => ({
|
|
181
|
+
target: true,
|
|
182
|
+
listeners: /* @__PURE__ */ new Set()
|
|
183
|
+
}));
|
|
184
|
+
function getRuntimeDocument(documentOverride) {
|
|
185
|
+
if (state$1.target === false) return null;
|
|
186
|
+
if (state$1.target !== true) return state$1.target;
|
|
187
|
+
if (documentOverride) return documentOverride;
|
|
188
|
+
return typeof globalThis.document === "undefined" ? null : globalThis.document;
|
|
189
|
+
}
|
|
190
|
+
function onRuntimeDocumentChange(listener) {
|
|
191
|
+
state$1.listeners.add(listener);
|
|
192
|
+
}
|
|
193
|
+
//#endregion
|
|
176
194
|
//#region utils/hash.ts
|
|
177
195
|
function hashString(str) {
|
|
178
196
|
let hash = 2166136261;
|
|
@@ -187,6 +205,41 @@ function normalizeHashLength(length) {
|
|
|
187
205
|
function compareLayerPriority(p1, p2) {
|
|
188
206
|
return p1[0] - p2[0] || p1[1] - p2[1] || p1[2] - p2[2] || p1[3] - p2[3] || p1[4] - p2[4] || p1[5] - p2[5] || p1[6] - p2[6];
|
|
189
207
|
}
|
|
208
|
+
function createLayerNamePool() {
|
|
209
|
+
const lookup = /* @__PURE__ */ new Map();
|
|
210
|
+
const getLayerId = (priority) => {
|
|
211
|
+
const key = priority.join("|");
|
|
212
|
+
let name = lookup.get(key);
|
|
213
|
+
if (name) return name;
|
|
214
|
+
name = "p" + hashString(key);
|
|
215
|
+
lookup.set(key, name);
|
|
216
|
+
return name;
|
|
217
|
+
};
|
|
218
|
+
const getLayerName = (layerNamespace, priority) => {
|
|
219
|
+
const layerId = getLayerId(priority);
|
|
220
|
+
return layerNamespace ? layerNamespace + "." + layerId : layerId;
|
|
221
|
+
};
|
|
222
|
+
return {
|
|
223
|
+
getLayerName,
|
|
224
|
+
getLayerId
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
function createLayerPool(layerNamespace) {
|
|
228
|
+
const namePool = createLayerNamePool();
|
|
229
|
+
const priorities = /* @__PURE__ */ new Map();
|
|
230
|
+
const getName = (priority) => {
|
|
231
|
+
const key = priority.join("|");
|
|
232
|
+
if (!priorities.has(key)) priorities.set(key, priority);
|
|
233
|
+
return namePool.getLayerName(layerNamespace, priority);
|
|
234
|
+
};
|
|
235
|
+
const getNames = () => {
|
|
236
|
+
return Array.from(priorities.values()).sort(compareLayerPriority).map((priority) => namePool.getLayerName(layerNamespace, priority));
|
|
237
|
+
};
|
|
238
|
+
return {
|
|
239
|
+
getName,
|
|
240
|
+
getNames
|
|
241
|
+
};
|
|
242
|
+
}
|
|
190
243
|
function flattenCssLayers(layers, layerNames) {
|
|
191
244
|
const names = typeof layerNames === "string" ? [layerNames] : layerNames;
|
|
192
245
|
return [...new Set(layers.flatMap((layer) => layer === "$layer" ? names.filter((name) => !layers.includes(name)) : layer).filter(Boolean))];
|
|
@@ -226,6 +279,108 @@ function getLayerOrderCss(layers, layerNames) {
|
|
|
226
279
|
function getLayerBlockCss(layerName, css) {
|
|
227
280
|
return "@layer " + layerName + " {" + css + "}";
|
|
228
281
|
}
|
|
282
|
+
function getSheetRulePriority(priority) {
|
|
283
|
+
return priority ?? LayerDefaultPriority;
|
|
284
|
+
}
|
|
285
|
+
function getSheetRuleLayerPriority(priority, important) {
|
|
286
|
+
const resolved = getSheetRulePriority(priority);
|
|
287
|
+
return important ? [
|
|
288
|
+
-resolved[0],
|
|
289
|
+
-resolved[1],
|
|
290
|
+
-resolved[2],
|
|
291
|
+
-resolved[3],
|
|
292
|
+
-resolved[4],
|
|
293
|
+
-resolved[5],
|
|
294
|
+
-resolved[6]
|
|
295
|
+
] : resolved;
|
|
296
|
+
}
|
|
297
|
+
//#endregion
|
|
298
|
+
//#region sheet/ordering.ts
|
|
299
|
+
function sheetRuleLayer(rule, config = CSS_CONFIG) {
|
|
300
|
+
const mainEnabled = isStyleLayerEnabled(config.layer);
|
|
301
|
+
let layer = rule.layer ?? "style";
|
|
302
|
+
if (layer === "style" && !mainEnabled) layer = false;
|
|
303
|
+
if (rule.sheet && rule.important && !rule.importantNative && layer !== false) return { name: (typeof layer === "object" ? layer.name : config.layerNamespace || "css") + ".important" };
|
|
304
|
+
return layer;
|
|
305
|
+
}
|
|
306
|
+
function sheetRuleGroup(rule, config = CSS_CONFIG) {
|
|
307
|
+
if (rule.globalSheet) return "global:" + rule.globalSheet.id;
|
|
308
|
+
return rule.sheet && sheetRuleLayer(rule, config) === false ? "local-unlayered" : "regular";
|
|
309
|
+
}
|
|
310
|
+
function compareSheetGroups(a, b) {
|
|
311
|
+
const region = (rule) => rule.globalSheet ? rule.globalSheet.order <= 0 ? 0 : 2 : 1;
|
|
312
|
+
const order = region(a) - region(b);
|
|
313
|
+
if (order) return order;
|
|
314
|
+
if (a.globalSheet && b.globalSheet) return a.globalSheet.order - b.globalSheet.order;
|
|
315
|
+
return 0;
|
|
316
|
+
}
|
|
317
|
+
function compareSheetRules(a, b, config = CSS_CONFIG) {
|
|
318
|
+
const layerRank = (rule) => {
|
|
319
|
+
const layer = sheetRuleLayer(rule, config);
|
|
320
|
+
const main = config.layerNamespace || "css";
|
|
321
|
+
return layer === false ? 2 : layer === "style" || typeof layer === "object" && layer.name === main ? 0 : 1;
|
|
322
|
+
};
|
|
323
|
+
return layerRank(a) - layerRank(b) || compareLayerPriority(getSheetRulePriority(a.priority), getSheetRulePriority(b.priority));
|
|
324
|
+
}
|
|
325
|
+
/** Stable group sort: equal global orders keep the first-discovered sheet first. */
|
|
326
|
+
function orderSheetRules(rules, config = CSS_CONFIG) {
|
|
327
|
+
const groups = /* @__PURE__ */ new Map();
|
|
328
|
+
for (const rule of rules) {
|
|
329
|
+
const key = sheetRuleGroup(rule, config);
|
|
330
|
+
const group = groups.get(key) ?? [];
|
|
331
|
+
group.push(rule);
|
|
332
|
+
groups.set(key, group);
|
|
333
|
+
}
|
|
334
|
+
return [...groups.entries()].sort(([ak, a], [bk, b]) => compareSheetGroups(a[0], b[0]) || (!a[0].globalSheet && !b[0].globalSheet ? Number(ak === "local-unlayered") - Number(bk === "local-unlayered") : 0)).flatMap(([, group]) => group.slice().sort((a, b) => compareSheetRules(a, b, config)));
|
|
335
|
+
}
|
|
336
|
+
/** Reserve each parent's first child for managed important declarations. */
|
|
337
|
+
function sheetLayerOrder(names, config = CSS_CONFIG, reservedParents = names) {
|
|
338
|
+
const roots = [];
|
|
339
|
+
const children = /* @__PURE__ */ new Map();
|
|
340
|
+
const add = (name) => {
|
|
341
|
+
const parts = name.split(".");
|
|
342
|
+
if (!roots.includes(parts[0])) roots.push(parts[0]);
|
|
343
|
+
for (let i = 1; i < parts.length; i++) {
|
|
344
|
+
const parent = parts.slice(0, i).join(".");
|
|
345
|
+
const child = parts.slice(0, i + 1).join(".");
|
|
346
|
+
const list = children.get(parent) ?? [];
|
|
347
|
+
if (!list.includes(child)) list.push(child);
|
|
348
|
+
children.set(parent, list);
|
|
349
|
+
}
|
|
350
|
+
if (!name.endsWith(".important") && reservedParents.includes(name)) children.set(name, children.get(name) ?? []);
|
|
351
|
+
};
|
|
352
|
+
for (const name of [...(config.layers ?? CSS_CONFIG_DEFAULT.layers ?? []).filter((name) => name !== "$layer"), ...names]) add(name);
|
|
353
|
+
const declarations = [getLayerOrderCss((config.layers ?? CSS_CONFIG_DEFAULT.layers ?? []).map((name) => name === "$layer" ? name : name.split(".")[0]), roots)];
|
|
354
|
+
for (const [parent, list] of children) {
|
|
355
|
+
if (parent.endsWith(".important")) continue;
|
|
356
|
+
declarations.push("@layer " + [...new Set([parent + ".important", ...list])].join(", ") + ";");
|
|
357
|
+
}
|
|
358
|
+
return declarations.filter(Boolean).join("\n");
|
|
359
|
+
}
|
|
360
|
+
function layerNameForRule(rule, config, mode, pool) {
|
|
361
|
+
const layer = sheetRuleLayer(rule, config);
|
|
362
|
+
return typeof layer === "object" ? layer.name : layer === false ? null : layer === "sheet" ? (config.layerNamespace || "css") + ".sheet" : mode === "layer" ? pool.getName(getSheetRuleLayerPriority(rule.priority, rule.important)) : config.layerNamespace || "css";
|
|
363
|
+
}
|
|
364
|
+
/** Build only ordering declarations; runtime flushing need not serialize rule bodies. */
|
|
365
|
+
function sheetOrderingPreamble(rules, config = CSS_CONFIG, mode = "sort") {
|
|
366
|
+
const pool = createLayerPool(config.layerNamespace || "css");
|
|
367
|
+
const names = /* @__PURE__ */ new Set();
|
|
368
|
+
for (const rule of orderSheetRules(rules, config)) {
|
|
369
|
+
const name = layerNameForRule(rule, config, mode, pool);
|
|
370
|
+
if (name) names.add(name);
|
|
371
|
+
}
|
|
372
|
+
const priorities = pool.getNames();
|
|
373
|
+
const named = [...names].filter((name) => !priorities.includes(name));
|
|
374
|
+
return sheetLayerOrder([...priorities, ...named], config, named);
|
|
375
|
+
}
|
|
376
|
+
function serializeOrderedRules(rules, config = CSS_CONFIG, mode = "sort") {
|
|
377
|
+
const pool = createLayerPool(config.layerNamespace || "css");
|
|
378
|
+
const rendered = orderSheetRules(rules, config).map((rule) => {
|
|
379
|
+
const name = layerNameForRule(rule, config, mode, pool);
|
|
380
|
+
return name ? getLayerBlockCss(name, rule.css) : rule.css;
|
|
381
|
+
});
|
|
382
|
+
return [sheetOrderingPreamble(rules, config, mode), ...rendered].filter(Boolean).join("\n");
|
|
383
|
+
}
|
|
229
384
|
const STYLE_IMPORT_PATH = "@fluentic/style";
|
|
230
385
|
const STYLE_CSS_IMPORT_PATH = "@fluentic/style/css";
|
|
231
386
|
const STYLE_DIALECT_IMPORT_PATH = "@fluentic/style/dialect";
|
|
@@ -257,6 +412,7 @@ const FN_CREATE_EXTRACTED_SHEET = "createExtractedSheet";
|
|
|
257
412
|
const FN_CREATE_EXTRACTED_SLOT = "createExtractedSlot";
|
|
258
413
|
const FN_CREATE_EXTRACTED_SCOPE = "createExtractedScope";
|
|
259
414
|
const FN_CREATE_EXTRACTED_TOKEN = "createExtractedToken";
|
|
415
|
+
const FN_CREATE_EXTRACTED_VALUES = "createExtractedValues";
|
|
260
416
|
const FN_CREATE_EXTRACTED_THEME = "createExtractedTheme";
|
|
261
417
|
const FN_CREATE_EXTRACTED_STYLE_MERGE = "createExtractedStyleMerge";
|
|
262
418
|
const FN_WITH_TOKENS = "withTokens";
|
|
@@ -265,46 +421,26 @@ const DEBUG_SOURCE_CONTENT_VAR = "_styleDebugSourceContent";
|
|
|
265
421
|
//#endregion
|
|
266
422
|
//#region compiler/extract/extract.ts
|
|
267
423
|
function extractCss(items, args) {
|
|
268
|
-
return getExtractedCssItems(items, args);
|
|
269
|
-
}
|
|
270
|
-
function getExtractedCssItems(items, args) {
|
|
271
|
-
const sortedItems = items.slice().sort((a, b) => compareLayerPriority(a.priority, b.priority));
|
|
272
424
|
const seen = /* @__PURE__ */ new Set();
|
|
273
|
-
const
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
425
|
+
const unique = items.filter((item) => {
|
|
426
|
+
const key = JSON.stringify([
|
|
427
|
+
item.globalSheet?.id,
|
|
428
|
+
item.globalSheet?.order,
|
|
429
|
+
item.sheet,
|
|
430
|
+
item.layer,
|
|
431
|
+
item.importantNative,
|
|
432
|
+
item.css
|
|
433
|
+
]);
|
|
434
|
+
if (seen.has(key)) return false;
|
|
277
435
|
seen.add(key);
|
|
278
|
-
|
|
279
|
-
}
|
|
280
|
-
if (!
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
const styleItems = [];
|
|
287
|
-
const sheetItems = /* @__PURE__ */ new Map();
|
|
288
|
-
const unlayeredItems = [];
|
|
289
|
-
for (let i = 0, len = css.length; i < len; i++) {
|
|
290
|
-
const item = css[i];
|
|
291
|
-
if (item.layer === "sheet" || typeof item.layer === "object") {
|
|
292
|
-
const name = typeof item.layer === "object" ? item.layer.name : sheetLayerName;
|
|
293
|
-
const rules = sheetItems.get(name) ?? [];
|
|
294
|
-
rules.push(item.css);
|
|
295
|
-
sheetItems.set(name, rules);
|
|
296
|
-
} else if (item.layer === false || !styleLayer) unlayeredItems.push(item.css);
|
|
297
|
-
else styleItems.push(item.css);
|
|
298
|
-
}
|
|
299
|
-
const styleLayerName = [...sheetItems.keys()].some((name) => name.startsWith(layerNamespace + ".")) && layerNamespace ? layerNamespace + ".style" : layerNamespace;
|
|
300
|
-
const layerNames = [styleItems.length ? styleLayerName : "", ...sheetItems.keys()].filter(Boolean);
|
|
301
|
-
const output = [];
|
|
302
|
-
const layerOrder = getLayerOrderCss(layers, layerNames);
|
|
303
|
-
if (layerOrder) output.push(layerOrder);
|
|
304
|
-
if (styleItems.length) output.push(getLayerBlockCss(styleLayerName, "\n" + styleItems.join("\n") + "\n"));
|
|
305
|
-
for (const [name, rules] of sheetItems) output.push(getLayerBlockCss(name, "\n" + rules.join("\n") + "\n"));
|
|
306
|
-
output.push(...unlayeredItems);
|
|
307
|
-
return output.join("\n");
|
|
436
|
+
return true;
|
|
437
|
+
});
|
|
438
|
+
if (!unique.length) return "";
|
|
439
|
+
return serializeOrderedRules(unique, {
|
|
440
|
+
layer: args.layer ?? DEFAULT_CONFIG.layer ?? true,
|
|
441
|
+
layers: args.layers ?? DEFAULT_CONFIG.layers,
|
|
442
|
+
layerNamespace: args.layerNamespace ?? DEFAULT_CONFIG.layerNamespace
|
|
443
|
+
});
|
|
308
444
|
}
|
|
309
445
|
//#endregion
|
|
310
446
|
//#region compiler/transform/utils/babel.ts
|
|
@@ -331,7 +467,7 @@ function babelTransform(args) {
|
|
|
331
467
|
error.stack = void 0;
|
|
332
468
|
throw error;
|
|
333
469
|
}
|
|
334
|
-
if (!result ||
|
|
470
|
+
if (!result || result.code == null) return null;
|
|
335
471
|
return {
|
|
336
472
|
code: result.code,
|
|
337
473
|
sourcemap: result.map ? JSON.stringify(result.map) : null
|
|
@@ -455,6 +591,7 @@ const BUILDER_SCOPE_ID = symbol("builder.scopeId");
|
|
|
455
591
|
const BUILDER_SCOPE = symbol("builder.scope");
|
|
456
592
|
const BUILDER_SELECTOR = symbol("builder.selector");
|
|
457
593
|
const BUILDER_SHEET_OPTIONS = symbol("builder.sheetOptions");
|
|
594
|
+
const GLOBAL_SHEET_SELECTOR_ANCHOR = "\0global";
|
|
458
595
|
const SHEET_SELECTOR_ANCHOR = "\0sheet";
|
|
459
596
|
//#endregion
|
|
460
597
|
//#region utils/object.ts
|
|
@@ -568,7 +705,7 @@ function createStackFrameLine(frame) {
|
|
|
568
705
|
}
|
|
569
706
|
function isInternalCallsite(filePath) {
|
|
570
707
|
const normalized = filePath.replace(/\\/g, "/");
|
|
571
|
-
return normalized.startsWith("node:") || normalized.startsWith("internal/") || normalized.includes("/node_modules/") || normalized.includes("/packages/style/dist/") || normalized.includes("/packages/style/builder/") || normalized.includes("/packages/style/runtime/") || normalized.includes("/packages/style/utils/trace.");
|
|
708
|
+
return normalized.startsWith("node:") || normalized.startsWith("internal/") || normalized.includes("/node_modules/") || normalized.includes("/packages/style/dist/") || normalized.includes("/packages/style/builder/") || normalized.includes("/packages/style/css/") || normalized.includes("/packages/style/runtime/") || normalized.includes("/packages/style/utils/trace.");
|
|
572
709
|
}
|
|
573
710
|
function traceError(message, options = {}) {
|
|
574
711
|
const error = new Error(message || "");
|
|
@@ -697,6 +834,9 @@ function getStyleTokenId(token) {
|
|
|
697
834
|
function getStyleTokenName(token) {
|
|
698
835
|
return token[TOKEN_NAME] ?? null;
|
|
699
836
|
}
|
|
837
|
+
function getStyleTokenVarName(token) {
|
|
838
|
+
return token[TOKEN_VAR_NAME] ?? null;
|
|
839
|
+
}
|
|
700
840
|
//#endregion
|
|
701
841
|
//#region builder/token/name.ts
|
|
702
842
|
function getStyleTokenNameFromId(id) {
|
|
@@ -756,12 +896,14 @@ function createStyleTokenOverride(token, value, debug) {
|
|
|
756
896
|
[TOKEN_ID]: getStyleTokenId(token),
|
|
757
897
|
[TOKEN_OVERRIDE]: true,
|
|
758
898
|
[TOKEN_NAME]: getStyleTokenName(token),
|
|
899
|
+
[TOKEN_VAR_NAME]: token[TOKEN_VAR_NAME] ?? null,
|
|
759
900
|
value: value.value,
|
|
760
901
|
ref: value
|
|
761
902
|
} : {
|
|
762
903
|
[TOKEN_ID]: getStyleTokenId(token),
|
|
763
904
|
[TOKEN_OVERRIDE]: true,
|
|
764
905
|
[TOKEN_NAME]: getStyleTokenName(token),
|
|
906
|
+
[TOKEN_VAR_NAME]: token[TOKEN_VAR_NAME] ?? null,
|
|
765
907
|
value,
|
|
766
908
|
ref: null
|
|
767
909
|
};
|
|
@@ -1314,7 +1456,9 @@ function getIdentifierSafeHashValue(hash) {
|
|
|
1314
1456
|
//#endregion
|
|
1315
1457
|
//#region atomic/utils/selector.ts
|
|
1316
1458
|
function getSelectorText$1(selector) {
|
|
1317
|
-
|
|
1459
|
+
const text = Array.isArray(selector) ? selector[0] : selector;
|
|
1460
|
+
if (text.startsWith("\0global")) return text.slice(text.indexOf("\0", 7) + 1);
|
|
1461
|
+
return stripSheetSelectorAnchor(text);
|
|
1318
1462
|
}
|
|
1319
1463
|
function getSelectorHash(selector) {
|
|
1320
1464
|
return Array.isArray(selector) ? selector.join("|") : selector;
|
|
@@ -1326,14 +1470,15 @@ function getSelectorPriority$1(selector) {
|
|
|
1326
1470
|
function hasSheetSelectorAnchor(selector) {
|
|
1327
1471
|
return (selector ? Array.isArray(selector) ? selector[0] : selector : "").startsWith(SHEET_SELECTOR_ANCHOR);
|
|
1328
1472
|
}
|
|
1329
|
-
function
|
|
1473
|
+
function getSheetSelectorSpecificity(selector) {
|
|
1330
1474
|
const text = selector ? Array.isArray(selector) ? selector[0] : selector : "";
|
|
1331
1475
|
if (!text.startsWith("\0sheet:")) return null;
|
|
1332
1476
|
const end = text.indexOf("\0", 6);
|
|
1333
1477
|
if (end < 0) return null;
|
|
1334
1478
|
const [weightValue] = text.slice(7, end).split(":");
|
|
1479
|
+
if (!weightValue) return null;
|
|
1335
1480
|
const weight = Number(weightValue);
|
|
1336
|
-
return Number.isInteger(weight) && weight
|
|
1481
|
+
return Number.isInteger(weight) && weight >= 0 ? weight : null;
|
|
1337
1482
|
}
|
|
1338
1483
|
function stripSheetSelectorAnchor(selector) {
|
|
1339
1484
|
if (!selector.startsWith("\0sheet")) return selector;
|
|
@@ -1343,12 +1488,16 @@ function stripSheetSelectorAnchor(selector) {
|
|
|
1343
1488
|
}
|
|
1344
1489
|
return selector.slice(6);
|
|
1345
1490
|
}
|
|
1491
|
+
function hasGlobalSheetSelectorAnchor(selector) {
|
|
1492
|
+
return (selector ? Array.isArray(selector) ? selector[0] : selector : "").startsWith(GLOBAL_SHEET_SELECTOR_ANCHOR);
|
|
1493
|
+
}
|
|
1346
1494
|
//#endregion
|
|
1347
1495
|
//#region atomic/className.ts
|
|
1348
|
-
function getAtomicClassName(property, priority, important, value, selector, parentSelector, atRule, callsite, localClassName, debugClassName, classNameFormat, transformClassName, transformClassNameFormat, sheetClassNameFormat = null, hashLength = null) {
|
|
1496
|
+
function getAtomicClassName(property, priority, important, value, selector, parentSelector, atRule, callsite, localClassName, debugClassName, classNameFormat, transformClassName, transformClassNameFormat, sheetClassNameFormat = null, hashLength = null, importantNative = false) {
|
|
1349
1497
|
let hash = property;
|
|
1350
1498
|
hash += "\n" + (priority || "");
|
|
1351
1499
|
if (important) hash += "\nimportant";
|
|
1500
|
+
if (importantNative) hash += "\nnative-important";
|
|
1352
1501
|
hash += "\n" + value;
|
|
1353
1502
|
hash += "\n" + (selector ? getSelectorHash(selector) : "");
|
|
1354
1503
|
hash += "\n" + (parentSelector ? getSelectorHash(parentSelector) : "");
|
|
@@ -1379,10 +1528,11 @@ function getClassNameHashLength(options) {
|
|
|
1379
1528
|
if (options.debugClassName && options.isDev) return options.devHashLength ?? options.cssHashLength ?? 5;
|
|
1380
1529
|
return options.cssHashLength ?? 7;
|
|
1381
1530
|
}
|
|
1382
|
-
function getClassNameDedupe(property, priority, important, selector, parentSelector, atRule) {
|
|
1531
|
+
function getClassNameDedupe(property, priority, important, selector, parentSelector, atRule, importantNative = false) {
|
|
1383
1532
|
let hash = property;
|
|
1384
1533
|
hash += "\n" + (priority || "");
|
|
1385
1534
|
if (important) hash += "\nimportant";
|
|
1535
|
+
if (importantNative) hash += "\nnative-important";
|
|
1386
1536
|
hash += "\n" + (selector ? getSelectorHash(selector) : "");
|
|
1387
1537
|
hash += "\n" + (parentSelector ? getSelectorHash(parentSelector) : "");
|
|
1388
1538
|
hash += "\n" + (atRule ? atRule.map(getSelectorHash).join("\n") : "");
|
|
@@ -1462,8 +1612,8 @@ function mergeScopeData(scope, callsite, items, debug, parentSelector, scopeAtRu
|
|
|
1462
1612
|
value = scopeItem.value;
|
|
1463
1613
|
weight = scopeItem.weight;
|
|
1464
1614
|
important = scopeItem.important;
|
|
1465
|
-
dedupe = getClassNameDedupe(scopeItem.property, weight, important, scopeItem.selector, scopeItem.parentSelector, scopeItem.atRule);
|
|
1466
|
-
className = getAtomicClassName(scopeItem.property, weight, important, value, scopeItem.selector, scopeItem.parentSelector, scopeItem.atRule, itemCallsite, DEV_CONFIG.isLocalClassNameEnabled, DEBUG_CONFIG.isDebugClassNameEnabled, CSS_CONFIG.classNameFormat ?? null, scopeItem.transformClassName ?? null, CSS_CONFIG.transformClassNameFormat ?? null, CSS_CONFIG.sheetClassNameFormat ?? null);
|
|
1615
|
+
dedupe = getClassNameDedupe(scopeItem.property, weight, important, scopeItem.selector, scopeItem.parentSelector, scopeItem.atRule, scopeItem.importantNative);
|
|
1616
|
+
className = getAtomicClassName(scopeItem.property, weight, important, value, scopeItem.selector, scopeItem.parentSelector, scopeItem.atRule, itemCallsite, DEV_CONFIG.isLocalClassNameEnabled, DEBUG_CONFIG.isDebugClassNameEnabled, CSS_CONFIG.classNameFormat ?? null, scopeItem.transformClassName ?? null, CSS_CONFIG.transformClassNameFormat ?? null, CSS_CONFIG.sheetClassNameFormat ?? null, null, scopeItem.importantNative);
|
|
1467
1617
|
scopeItem.dedupe = dedupe;
|
|
1468
1618
|
scopeItem.className = className;
|
|
1469
1619
|
scopeItem.callsite = itemCallsite;
|
|
@@ -1502,6 +1652,7 @@ function mergeScopeData(scope, callsite, items, debug, parentSelector, scopeAtRu
|
|
|
1502
1652
|
property: overrideItem.property,
|
|
1503
1653
|
weight: overrideItem.weight,
|
|
1504
1654
|
important: overrideItem.important,
|
|
1655
|
+
importantNative: overrideItem.importantNative,
|
|
1505
1656
|
value: overrideItem.value,
|
|
1506
1657
|
transformClassName: overrideItem.transformClassName,
|
|
1507
1658
|
token: overrideItem.token,
|
|
@@ -1515,8 +1666,8 @@ function mergeScopeData(scope, callsite, items, debug, parentSelector, scopeAtRu
|
|
|
1515
1666
|
value = scopeItem.value;
|
|
1516
1667
|
weight = scopeItem.weight;
|
|
1517
1668
|
important = scopeItem.important;
|
|
1518
|
-
dedupe = getClassNameDedupe(scopeItem.property, weight, important, scopeItem.selector, parentSelector, scopeItem.atRule);
|
|
1519
|
-
className = getAtomicClassName(scopeItem.property, weight, important, value, scopeItem.selector, parentSelector, scopeItem.atRule, scopeItem.callsite, DEV_CONFIG.isLocalClassNameEnabled, DEBUG_CONFIG.isDebugClassNameEnabled, CSS_CONFIG.classNameFormat ?? null, scopeItem.transformClassName ?? null, CSS_CONFIG.transformClassNameFormat ?? null, CSS_CONFIG.sheetClassNameFormat ?? null);
|
|
1669
|
+
dedupe = getClassNameDedupe(scopeItem.property, weight, important, scopeItem.selector, parentSelector, scopeItem.atRule, scopeItem.importantNative);
|
|
1670
|
+
className = getAtomicClassName(scopeItem.property, weight, important, value, scopeItem.selector, parentSelector, scopeItem.atRule, scopeItem.callsite, DEV_CONFIG.isLocalClassNameEnabled, DEBUG_CONFIG.isDebugClassNameEnabled, CSS_CONFIG.classNameFormat ?? null, scopeItem.transformClassName ?? null, CSS_CONFIG.transformClassNameFormat ?? null, CSS_CONFIG.sheetClassNameFormat ?? null, null, scopeItem.importantNative);
|
|
1520
1671
|
scopeItem.dedupe = dedupe;
|
|
1521
1672
|
scopeItem.className = className;
|
|
1522
1673
|
const lookupKey = getScopeLookupKey(slotId, dedupe);
|
|
@@ -1595,6 +1746,8 @@ function escapeCssValue(value) {
|
|
|
1595
1746
|
}
|
|
1596
1747
|
const formatTokenName = createNameFormatter(["name"]);
|
|
1597
1748
|
function getTokenVarName(token, format) {
|
|
1749
|
+
const explicitName = getStyleTokenVarName(token);
|
|
1750
|
+
if (explicitName) return explicitName;
|
|
1598
1751
|
const id = getStyleTokenId(token);
|
|
1599
1752
|
const debugName = getStyleTokenName(token);
|
|
1600
1753
|
return "--" + formatTokenName(format || "token[-(name)]-$hash", getIdentifierSafeHash(id, CSS_CONFIG.hashLength), { name: debugName });
|
|
@@ -1674,10 +1827,11 @@ function shouldAppendCssPx(property) {
|
|
|
1674
1827
|
//#endregion
|
|
1675
1828
|
//#region style/important.ts
|
|
1676
1829
|
const STYLE_IMPORTANT = symbol("style.important");
|
|
1677
|
-
function importantValue(value) {
|
|
1830
|
+
function importantValue(value, native = false) {
|
|
1678
1831
|
return {
|
|
1679
1832
|
[STYLE_IMPORTANT]: true,
|
|
1680
|
-
value
|
|
1833
|
+
value,
|
|
1834
|
+
native
|
|
1681
1835
|
};
|
|
1682
1836
|
}
|
|
1683
1837
|
function isStyleImportantValue(value) {
|
|
@@ -1734,6 +1888,7 @@ function mergeBuilderData(create, callsite, source, style, debug, selector, atRu
|
|
|
1734
1888
|
let value;
|
|
1735
1889
|
let weight;
|
|
1736
1890
|
let important;
|
|
1891
|
+
let importantNative;
|
|
1737
1892
|
let itemCallsite;
|
|
1738
1893
|
let className;
|
|
1739
1894
|
let dedupe;
|
|
@@ -1775,7 +1930,7 @@ function mergeBuilderData(create, callsite, source, style, debug, selector, atRu
|
|
|
1775
1930
|
}
|
|
1776
1931
|
} else for (const property in style) {
|
|
1777
1932
|
valueRaw = style[property];
|
|
1778
|
-
[valueRaw, weight, important] = unwrapAuthoredStyleValue(valueRaw);
|
|
1933
|
+
[valueRaw, weight, important, importantNative] = unwrapAuthoredStyleValue(valueRaw);
|
|
1779
1934
|
const sourceType = source[BUILDER_TYPE];
|
|
1780
1935
|
checkImportantUsage(valueRaw, important, sourceType === 9 || sourceType === 8);
|
|
1781
1936
|
transformClassName = null;
|
|
@@ -1798,6 +1953,7 @@ function mergeBuilderData(create, callsite, source, style, debug, selector, atRu
|
|
|
1798
1953
|
property,
|
|
1799
1954
|
weight,
|
|
1800
1955
|
important,
|
|
1956
|
+
importantNative,
|
|
1801
1957
|
value,
|
|
1802
1958
|
transformClassName,
|
|
1803
1959
|
variable: ref ? [3, ref] : variableName && token ? [
|
|
@@ -1860,8 +2016,8 @@ function mergeBuilderData(create, callsite, source, style, debug, selector, atRu
|
|
|
1860
2016
|
value = runtimeItem.value;
|
|
1861
2017
|
weight = runtimeItem.weight;
|
|
1862
2018
|
important = runtimeItem.important;
|
|
1863
|
-
dedupe = getClassNameDedupe(runtimeItem.property, weight, important, runtimeItem.selector, null, runtimeItem.atRule);
|
|
1864
|
-
className = getAtomicClassName(runtimeItem.property, weight, important, value, runtimeItem.selector, null, runtimeItem.atRule, runtimeItem.callsite, DEV_CONFIG.isLocalClassNameEnabled, DEBUG_CONFIG.isDebugClassNameEnabled, CSS_CONFIG.classNameFormat ?? null, runtimeItem.transformClassName ?? null, CSS_CONFIG.transformClassNameFormat ?? null, CSS_CONFIG.sheetClassNameFormat ?? null);
|
|
2019
|
+
dedupe = getClassNameDedupe(runtimeItem.property, weight, important, runtimeItem.selector, null, runtimeItem.atRule, runtimeItem.importantNative);
|
|
2020
|
+
className = getAtomicClassName(runtimeItem.property, weight, important, value, runtimeItem.selector, null, runtimeItem.atRule, runtimeItem.callsite, DEV_CONFIG.isLocalClassNameEnabled, DEBUG_CONFIG.isDebugClassNameEnabled, CSS_CONFIG.classNameFormat ?? null, runtimeItem.transformClassName ?? null, CSS_CONFIG.transformClassNameFormat ?? null, CSS_CONFIG.sheetClassNameFormat ?? null, null, runtimeItem.importantNative);
|
|
1865
2021
|
runtimeItem.dedupe = dedupe;
|
|
1866
2022
|
runtimeItem.className = className;
|
|
1867
2023
|
lookupIndex = lookup[dedupe];
|
|
@@ -1873,9 +2029,11 @@ function mergeBuilderData(create, callsite, source, style, debug, selector, atRu
|
|
|
1873
2029
|
function unwrapAuthoredStyleValue(value) {
|
|
1874
2030
|
let weight = null;
|
|
1875
2031
|
let important = false;
|
|
2032
|
+
let native = false;
|
|
1876
2033
|
while (true) {
|
|
1877
2034
|
if (isStyleImportantValue(value)) {
|
|
1878
2035
|
important = true;
|
|
2036
|
+
native ||= value.native === true;
|
|
1879
2037
|
value = value.value;
|
|
1880
2038
|
continue;
|
|
1881
2039
|
}
|
|
@@ -1889,7 +2047,8 @@ function unwrapAuthoredStyleValue(value) {
|
|
|
1889
2047
|
return [
|
|
1890
2048
|
value,
|
|
1891
2049
|
weight,
|
|
1892
|
-
important
|
|
2050
|
+
important,
|
|
2051
|
+
native
|
|
1893
2052
|
];
|
|
1894
2053
|
}
|
|
1895
2054
|
function checkImportantUsage(value, important, isSheet) {
|
|
@@ -1975,9 +2134,9 @@ function assertManualSelectorSyntax(selector) {
|
|
|
1975
2134
|
if (ampersandIndex === 0 && ampersandSelector && /^\s/.test(ampersandSelector)) throw new Error("selector cannot have whitespace after \"&\"; omit \"&\" for descendant selectors");
|
|
1976
2135
|
}
|
|
1977
2136
|
function setSheetSelectorOptions(selector, options) {
|
|
1978
|
-
if (options.
|
|
2137
|
+
if (options.specificity === void 0 && options.layer === void 0) return selector;
|
|
1979
2138
|
const text = Array.isArray(selector) ? selector[0] : selector;
|
|
1980
|
-
const weighted = SHEET_SELECTOR_ANCHOR + (":" + (options.
|
|
2139
|
+
const weighted = SHEET_SELECTOR_ANCHOR + (":" + (options.specificity ?? "") + ":" + (typeof options.layer === "string" ? JSON.stringify(options.layer) : options.layer === void 0 ? "" : options.layer ? "1" : "0")) + "\0" + text.slice(6);
|
|
1981
2140
|
return Array.isArray(selector) ? [weighted, selector[1]] : weighted;
|
|
1982
2141
|
}
|
|
1983
2142
|
function normalizeManualSelector(selector, assertManualSelector) {
|
|
@@ -1989,6 +2148,13 @@ function normalizeManualSelector(selector, assertManualSelector) {
|
|
|
1989
2148
|
}
|
|
1990
2149
|
return [SHEET_SELECTOR_ANCHOR + (value.startsWith("&") ? value.slice(1) : " " + value)];
|
|
1991
2150
|
}
|
|
2151
|
+
/** Convert a normalized explicit selector into an unscoped sheet selector. */
|
|
2152
|
+
function setGlobalSheetSelectorOptions(selector, options) {
|
|
2153
|
+
const suffix = (Array.isArray(selector) ? selector[0] : selector).slice(6);
|
|
2154
|
+
if (!suffix.startsWith(" ") || !suffix.trim()) throw new Error("createGlobalSheet requires explicit selectors without an ampersand anchor");
|
|
2155
|
+
const global = GLOBAL_SHEET_SELECTOR_ANCHOR + JSON.stringify(options.layer ?? null) + "\0" + suffix.trimStart();
|
|
2156
|
+
return Array.isArray(selector) ? [global, selector[1]] : global;
|
|
2157
|
+
}
|
|
1992
2158
|
//#endregion
|
|
1993
2159
|
//#region builder/selector_override.ts
|
|
1994
2160
|
function normalizeManualSelectors(input) {
|
|
@@ -3014,63 +3180,19 @@ function buildFontPaletteValuesCss(format, name, id, descriptors, tokens, tokenL
|
|
|
3014
3180
|
};
|
|
3015
3181
|
}
|
|
3016
3182
|
createIdCounter("fontPaletteValues");
|
|
3017
|
-
|
|
3018
|
-
|
|
3019
|
-
const KEYFRAMES_AT_RULE = "keyframes";
|
|
3020
|
-
const formatKeyFramesName = createAtRuleNameFormatter("keyframes[-(name)]-$hash");
|
|
3021
|
-
function buildKeyframesCss(format, name, id, frames, tokens, tokenLookup, tokenNameFormat) {
|
|
3022
|
-
name = formatKeyFramesName(format, id, { name });
|
|
3023
|
-
let css = `@${KEYFRAMES_AT_RULE} ${name} {`;
|
|
3024
|
-
for (const selector in frames) {
|
|
3025
|
-
const frame = frames[selector];
|
|
3026
|
-
if (!frame) continue;
|
|
3027
|
-
css += selector + "{";
|
|
3028
|
-
css += buildAtRuleDeclarationCss(frame, tokens, tokenLookup, tokenNameFormat, false);
|
|
3029
|
-
css += "}";
|
|
3030
|
-
}
|
|
3031
|
-
css += "}";
|
|
3032
|
-
return {
|
|
3033
|
-
name,
|
|
3034
|
-
css
|
|
3035
|
-
};
|
|
3036
|
-
}
|
|
3037
|
-
//#endregion
|
|
3038
|
-
//#region css/keyframes.ts
|
|
3039
|
-
const idCounter$2 = createIdCounter("keyframes");
|
|
3040
|
-
function createKeyframes(frames, stableId) {
|
|
3041
|
-
return createNamedAtRuleRef({
|
|
3042
|
-
format: CSS_EXTRA_CONFIG.namedRuleFormat.keyframes,
|
|
3043
|
-
buildCss: buildKeyframesCss,
|
|
3044
|
-
value: frames,
|
|
3045
|
-
idCounter: idCounter$2,
|
|
3046
|
-
stableId
|
|
3047
|
-
});
|
|
3183
|
+
function appendStyleTag(document, tag) {
|
|
3184
|
+
(document.head || document.getElementsByTagName("head")[0] || document.documentElement).appendChild(tag);
|
|
3048
3185
|
}
|
|
3049
|
-
|
|
3050
|
-
|
|
3051
|
-
|
|
3052
|
-
const
|
|
3053
|
-
|
|
3054
|
-
|
|
3055
|
-
|
|
3056
|
-
return
|
|
3057
|
-
name,
|
|
3058
|
-
css
|
|
3059
|
-
};
|
|
3060
|
-
}
|
|
3061
|
-
createIdCounter("positionTry");
|
|
3062
|
-
//#endregion
|
|
3063
|
-
//#region atomic/atRule/property.ts
|
|
3064
|
-
const PROPERTY_AT_RULE = "property";
|
|
3065
|
-
const formatPropertyName = createAtRuleNameFormatter("[-(name)]-$hash", "--");
|
|
3066
|
-
function buildPropertyCss(format, name, id, descriptors, tokens, tokenLookup, tokenNameFormat) {
|
|
3067
|
-
name = formatPropertyName(format, id, { name });
|
|
3068
|
-
return {
|
|
3069
|
-
css: buildNamedAtRuleCss(PROPERTY_AT_RULE, name, descriptors, tokens, tokenLookup, tokenNameFormat),
|
|
3070
|
-
name
|
|
3071
|
-
};
|
|
3186
|
+
function getFirstCssSheetTag(head) {
|
|
3187
|
+
const nodes = head.childNodes;
|
|
3188
|
+
for (let i = 0, len = nodes.length; i < len; i++) {
|
|
3189
|
+
const node = nodes[i];
|
|
3190
|
+
if (typeof node.getAttribute !== "function") continue;
|
|
3191
|
+
if (node.getAttribute("data-css-sheet")) return node;
|
|
3192
|
+
}
|
|
3193
|
+
return null;
|
|
3072
3194
|
}
|
|
3073
|
-
|
|
3195
|
+
globalData("sheet.ordered.refreshers", () => /* @__PURE__ */ new Set());
|
|
3074
3196
|
//#endregion
|
|
3075
3197
|
//#region sheet/utils/sourcemap.ts
|
|
3076
3198
|
const VLQ_BASE_SHIFT = 5;
|
|
@@ -3079,6 +3201,45 @@ const VLQ_BASE_MASK = VLQ_BASE - 1;
|
|
|
3079
3201
|
const VLQ_CONTINUATION_BIT = VLQ_BASE;
|
|
3080
3202
|
const BASE64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
3081
3203
|
const SOURCE_URL_PREFIX = "source://";
|
|
3204
|
+
function createSourceMapComment$1(rules) {
|
|
3205
|
+
const sources = [];
|
|
3206
|
+
const sourceLookup = Object.create(null);
|
|
3207
|
+
let generatedLine = 0;
|
|
3208
|
+
let previousSource = 0;
|
|
3209
|
+
let previousOriginalLine = 0;
|
|
3210
|
+
let previousOriginalColumn = 0;
|
|
3211
|
+
const mappingLines = [];
|
|
3212
|
+
for (let i = 0, len = rules.length; i < len; i++) {
|
|
3213
|
+
const rule = rules[i];
|
|
3214
|
+
const sourceData = rule.source;
|
|
3215
|
+
let mapping = "";
|
|
3216
|
+
if (sourceData) {
|
|
3217
|
+
const source = getSource(sources, sourceLookup, getSourceMapSourceUrl(sourceData), sourceData.sourceContent);
|
|
3218
|
+
const originalLine = Math.max(sourceData.line - 1, 0);
|
|
3219
|
+
const originalColumn = Math.max(sourceData.column - 1, 0);
|
|
3220
|
+
mapping += encodeVlq(0);
|
|
3221
|
+
mapping += encodeVlq(source.sourceIndex - previousSource);
|
|
3222
|
+
mapping += encodeVlq(originalLine - previousOriginalLine);
|
|
3223
|
+
mapping += encodeVlq(originalColumn - previousOriginalColumn);
|
|
3224
|
+
previousSource = source.sourceIndex;
|
|
3225
|
+
previousOriginalLine = originalLine;
|
|
3226
|
+
previousOriginalColumn = originalColumn;
|
|
3227
|
+
}
|
|
3228
|
+
mappingLines[generatedLine] = mapping;
|
|
3229
|
+
const lineCount = getLineCount(rule.css);
|
|
3230
|
+
for (let j = 1; j < lineCount; j++) mappingLines[generatedLine + j] = "";
|
|
3231
|
+
generatedLine += lineCount;
|
|
3232
|
+
}
|
|
3233
|
+
if (!sources.length) return "";
|
|
3234
|
+
const data = {
|
|
3235
|
+
version: 3,
|
|
3236
|
+
sources: sources.map((source) => source.filePath),
|
|
3237
|
+
sourcesContent: sources.some((source) => source.sourceContent !== void 0) ? sources.map((source) => source.sourceContent ?? null) : void 0,
|
|
3238
|
+
names: [],
|
|
3239
|
+
mappings: mappingLines.join(";")
|
|
3240
|
+
};
|
|
3241
|
+
return "/*# sourceMappingURL=data:application/json;charset=utf-8;base64," + encodeBase64(JSON.stringify(data)) + " */";
|
|
3242
|
+
}
|
|
3082
3243
|
function encodeBase64(text) {
|
|
3083
3244
|
const bytes = new TextEncoder().encode(text);
|
|
3084
3245
|
let binary = "";
|
|
@@ -3179,8 +3340,21 @@ function normalizeRuleCallsite(callsite) {
|
|
|
3179
3340
|
sourceUrl: callsite.sourceUrl ? normalizeCallsiteSourceUrl(callsite.sourceUrl) : callsite.sourceUrl
|
|
3180
3341
|
};
|
|
3181
3342
|
}
|
|
3343
|
+
function getSourcemapRuleCallsite(rule) {
|
|
3344
|
+
return getRuleCallsite(rule.callsite, rule.debug, rule.debugField);
|
|
3345
|
+
}
|
|
3182
3346
|
globalData("sheet.dev.sourcemapTags", () => []);
|
|
3183
3347
|
globalData("sheet.dev.sheets", () => /* @__PURE__ */ new Set());
|
|
3348
|
+
//#endregion
|
|
3349
|
+
//#region runtime/sheet/document.ts
|
|
3350
|
+
const GLOBAL_KEY = "runtime.sheet.global";
|
|
3351
|
+
const state = globalData("runtime.sheet.document", () => ({ document: getRuntimeDocument() }));
|
|
3352
|
+
function resetSheet() {
|
|
3353
|
+
getGlobalData(GLOBAL_KEY)?.destroy?.();
|
|
3354
|
+
clearGlobalData(GLOBAL_KEY);
|
|
3355
|
+
state.document = getRuntimeDocument();
|
|
3356
|
+
}
|
|
3357
|
+
onRuntimeDocumentChange(resetSheet);
|
|
3184
3358
|
globalData("runtime.combinedStyle.targets", () => /* @__PURE__ */ new WeakMap());
|
|
3185
3359
|
//#endregion
|
|
3186
3360
|
//#region runtime/core/cache/resolvedItem.ts
|
|
@@ -3478,10 +3652,10 @@ function buildAtomicRule(className, property, value, important, selector, parent
|
|
|
3478
3652
|
const cssProp = getCssPropertyName(property);
|
|
3479
3653
|
const cssValue = getCssPropertyValue(property, value) + (important ? " !important" : "");
|
|
3480
3654
|
const escapedClass = escapeCssIdent(className);
|
|
3481
|
-
const
|
|
3482
|
-
const classSelector =
|
|
3655
|
+
const specificity = hasSheetSelectorAnchor(selector) ? getSheetSelectorSpecificity(selector) ?? 1 : 1;
|
|
3656
|
+
const classSelector = specificity === 0 ? `:where(.${escapedClass})` : Array(specificity).fill("." + escapedClass).join("");
|
|
3483
3657
|
const itemSelector = selector ? getSelectorText$1(selector) : "";
|
|
3484
|
-
let selectorStr = classSelector + itemSelector;
|
|
3658
|
+
let selectorStr = hasGlobalSheetSelectorAnchor(selector) ? itemSelector : classSelector + itemSelector;
|
|
3485
3659
|
if (parentSelector) {
|
|
3486
3660
|
const parentWhere = `:where(${"." + escapeCssIdent(getScopeClassName(className, scopeClassNameFormat)) + getSelectorText$1(parentSelector)})`;
|
|
3487
3661
|
selectorStr = classSelector + parentWhere + itemSelector + "," + parentWhere + " " + selectorStr;
|
|
@@ -3561,8 +3735,71 @@ function stripGenericThemePrefix(value) {
|
|
|
3561
3735
|
function isGeneratedNameHash(value) {
|
|
3562
3736
|
return /^[a-z0-9]{7}$/.test(value) && /\d/.test(value);
|
|
3563
3737
|
}
|
|
3738
|
+
//#endregion
|
|
3739
|
+
//#region atomic/atRule/keyframes.ts
|
|
3740
|
+
const KEYFRAMES_AT_RULE = "keyframes";
|
|
3741
|
+
const formatKeyFramesName = createAtRuleNameFormatter("keyframes[-(name)]-$hash");
|
|
3742
|
+
function buildKeyframesCss(format, name, id, frames, tokens, tokenLookup, tokenNameFormat) {
|
|
3743
|
+
name = formatKeyFramesName(format, id, { name });
|
|
3744
|
+
let css = `@${KEYFRAMES_AT_RULE} ${name} {`;
|
|
3745
|
+
for (const selector in frames) {
|
|
3746
|
+
const frame = frames[selector];
|
|
3747
|
+
if (!frame) continue;
|
|
3748
|
+
css += selector + "{";
|
|
3749
|
+
css += buildAtRuleDeclarationCss(frame, tokens, tokenLookup, tokenNameFormat, false);
|
|
3750
|
+
css += "}";
|
|
3751
|
+
}
|
|
3752
|
+
css += "}";
|
|
3753
|
+
return {
|
|
3754
|
+
name,
|
|
3755
|
+
css
|
|
3756
|
+
};
|
|
3757
|
+
}
|
|
3758
|
+
//#endregion
|
|
3759
|
+
//#region css/keyframes.ts
|
|
3760
|
+
const idCounter$2 = createIdCounter("keyframes");
|
|
3761
|
+
function createKeyframes(frames, stableId) {
|
|
3762
|
+
return createNamedAtRuleRef({
|
|
3763
|
+
format: CSS_EXTRA_CONFIG.namedRuleFormat.keyframes,
|
|
3764
|
+
buildCss: buildKeyframesCss,
|
|
3765
|
+
value: frames,
|
|
3766
|
+
idCounter: idCounter$2,
|
|
3767
|
+
stableId
|
|
3768
|
+
});
|
|
3769
|
+
}
|
|
3770
|
+
//#endregion
|
|
3771
|
+
//#region atomic/atRule/positionTry.ts
|
|
3772
|
+
const POSITION_TRY_AT_RULE = "position-try";
|
|
3773
|
+
const formatPositionTryName = createAtRuleNameFormatter("position-try[-(name)]-$hash", "--");
|
|
3774
|
+
function buildPositionTryCss(format, name, id, descriptors, tokens, tokenLookup, tokenNameFormat) {
|
|
3775
|
+
name = formatPositionTryName(format, id, { name });
|
|
3776
|
+
const css = buildNamedAtRuleCss(POSITION_TRY_AT_RULE, name, descriptors, tokens, tokenLookup, tokenNameFormat);
|
|
3777
|
+
return {
|
|
3778
|
+
name,
|
|
3779
|
+
css
|
|
3780
|
+
};
|
|
3781
|
+
}
|
|
3782
|
+
createIdCounter("positionTry");
|
|
3783
|
+
//#endregion
|
|
3784
|
+
//#region atomic/atRule/property.ts
|
|
3785
|
+
const PROPERTY_AT_RULE = "property";
|
|
3786
|
+
const formatPropertyName = createAtRuleNameFormatter("[-(name)]-$hash", "--");
|
|
3787
|
+
function buildPropertyCss(format, name, id, descriptors, tokens, tokenLookup, tokenNameFormat) {
|
|
3788
|
+
name = formatPropertyName(format, id, { name });
|
|
3789
|
+
return {
|
|
3790
|
+
css: buildNamedAtRuleCss(PROPERTY_AT_RULE, name, descriptors, tokens, tokenLookup, tokenNameFormat),
|
|
3791
|
+
name
|
|
3792
|
+
};
|
|
3793
|
+
}
|
|
3794
|
+
createIdCounter("property");
|
|
3564
3795
|
createNameFormatter(["name"]);
|
|
3565
|
-
|
|
3796
|
+
//#endregion
|
|
3797
|
+
//#region runtime/core/elementMarker.ts
|
|
3798
|
+
const ELEMENT_MARKER_SHEET = globalData("runtime.elementMarkerSheet", () => ({ sheet: null }));
|
|
3799
|
+
onRuntimeDocumentChange(() => {
|
|
3800
|
+
ELEMENT_MARKER_SHEET.sheet?.sheet.destroy?.();
|
|
3801
|
+
ELEMENT_MARKER_SHEET.sheet = null;
|
|
3802
|
+
});
|
|
3566
3803
|
//#endregion
|
|
3567
3804
|
//#region style/keyframes.ts
|
|
3568
3805
|
function transformKeyframes(frames, transform) {
|
|
@@ -3594,7 +3831,7 @@ function createStyleFn(args) {
|
|
|
3594
3831
|
const fnWeight = (value, weight) => {
|
|
3595
3832
|
return weightValue(value, weight);
|
|
3596
3833
|
};
|
|
3597
|
-
const fnImportant = (value) => importantValue(value);
|
|
3834
|
+
const fnImportant = (value, native) => importantValue(value, native);
|
|
3598
3835
|
const fnRaw = (style) => style;
|
|
3599
3836
|
const fnPlain = (style) => style;
|
|
3600
3837
|
const fnKeyframes = ((frames, stableId) => createStyleKeyframes(frames, transform ?? null, stableId));
|
|
@@ -3845,8 +4082,9 @@ function appendExtractedStyleTuples(target, source) {
|
|
|
3845
4082
|
//#region dialect/namedTokens.ts
|
|
3846
4083
|
const ROOT = Symbol("fluentic.namedTokens.root");
|
|
3847
4084
|
function createNamedToken(id, value) {
|
|
3848
|
-
const
|
|
3849
|
-
token
|
|
4085
|
+
const tokenId = createNamedTokenId(id);
|
|
4086
|
+
const token = createStyleToken(value, tokenId);
|
|
4087
|
+
token[TOKEN_VAR_NAME] = "--token-" + tokenId;
|
|
3850
4088
|
return token;
|
|
3851
4089
|
}
|
|
3852
4090
|
function createNamedTokens(namespace, values) {
|
|
@@ -3858,7 +4096,10 @@ function createNamedTokens(namespace, values) {
|
|
|
3858
4096
|
}, []);
|
|
3859
4097
|
}
|
|
3860
4098
|
function createNamedTokenId(id) {
|
|
3861
|
-
return
|
|
4099
|
+
return id.split(".").map(encodeNamedTokenSegment).join("-");
|
|
4100
|
+
}
|
|
4101
|
+
function encodeNamedTokenSegment(segment) {
|
|
4102
|
+
return segment.replace(/[^a-zA-Z0-9]/gu, (char) => "_x" + char.codePointAt(0).toString(16) + "_");
|
|
3862
4103
|
}
|
|
3863
4104
|
function createNamedTokenProxy(root, path) {
|
|
3864
4105
|
return new Proxy(noop, {
|
|
@@ -3880,11 +4121,13 @@ function createNamedTokenProxy(root, path) {
|
|
|
3880
4121
|
});
|
|
3881
4122
|
}
|
|
3882
4123
|
function getNamedTokenAtPath(root, path) {
|
|
3883
|
-
const key =
|
|
4124
|
+
const key = JSON.stringify(path);
|
|
3884
4125
|
const cached = root.cache.get(key);
|
|
3885
4126
|
if (cached) return cached;
|
|
3886
4127
|
const value = getValueAtPath(root.values, path);
|
|
3887
|
-
const
|
|
4128
|
+
const id = root.namespace.split(".").concat(path).map(encodeNamedTokenSegment).join("-");
|
|
4129
|
+
const token = createStyleToken(value, id);
|
|
4130
|
+
token[TOKEN_VAR_NAME] = "--token-" + id;
|
|
3888
4131
|
root.cache.set(key, token);
|
|
3889
4132
|
return token;
|
|
3890
4133
|
}
|
|
@@ -3921,6 +4164,7 @@ function exposeStyleValue(value) {
|
|
|
3921
4164
|
//#region compiler/transform/evaluator/evaluator.ts
|
|
3922
4165
|
const STYLE_IMPORT_PATHS = new Set(IMPORT_PATHS);
|
|
3923
4166
|
const COMPILED_RUNTIME_VALUE = Symbol();
|
|
4167
|
+
const COMPILED_TOKEN_REFERENCE = Symbol();
|
|
3924
4168
|
const COMPILED_STYLE_OBJECT_LOCATIONS = Symbol();
|
|
3925
4169
|
const COMPILED_TOKEN_FACTORY = Symbol();
|
|
3926
4170
|
function evalOk(value) {
|
|
@@ -3943,11 +4187,11 @@ function evaluateNode(node, scope) {
|
|
|
3943
4187
|
case "BooleanLiteral": return evalOk(node.value);
|
|
3944
4188
|
case "NullLiteral": return evalOk(null);
|
|
3945
4189
|
case "TemplateLiteral": return evaluateTemplate(node, scope);
|
|
3946
|
-
case "Identifier": return evaluateIdentifier(node, scope);
|
|
3947
|
-
case "MemberExpression": return evaluateMember(node, scope);
|
|
4190
|
+
case "Identifier": return referenceResult(evaluateIdentifier(node, scope), node, scope);
|
|
4191
|
+
case "MemberExpression": return referenceResult(evaluateMember(node, scope), node, scope);
|
|
3948
4192
|
case "ObjectExpression": return evaluateObject(node, scope);
|
|
3949
4193
|
case "ArrayExpression": return evaluateArray(node, scope);
|
|
3950
|
-
case "CallExpression": return evaluateCall(node, scope);
|
|
4194
|
+
case "CallExpression": return referenceCallResult(evaluateCall(node, scope), node, scope);
|
|
3951
4195
|
case "BinaryExpression": return evaluateBinary(node, scope);
|
|
3952
4196
|
case "UnaryExpression": return evaluateUnary(node, scope);
|
|
3953
4197
|
case "ParenthesizedExpression":
|
|
@@ -4271,7 +4515,7 @@ function evaluateCall(node, scope) {
|
|
|
4271
4515
|
if (imp && STYLE_IMPORT_PATHS.has(imp.source) && imp.name === "getToken") {
|
|
4272
4516
|
const value = evaluateNode(node.arguments[0], scope);
|
|
4273
4517
|
if (!value.ok) return value;
|
|
4274
|
-
if (isStyleTokenData(value.value)) return evalOk(getTokenVar(value.value, CSS_CONFIG.tokenNameFormat || null));
|
|
4518
|
+
if (isStyleTokenData(value.value)) return evalOk(getTokenVar(value.value, scope.tokenNameFormat === void 0 ? CSS_CONFIG.tokenNameFormat || null : scope.tokenNameFormat));
|
|
4275
4519
|
return evalOk(value.value);
|
|
4276
4520
|
}
|
|
4277
4521
|
if (imp && imp.source === "@fluentic/style/utils" && imp.name === "exposeStyle") {
|
|
@@ -4309,7 +4553,7 @@ function evaluateCall(node, scope) {
|
|
|
4309
4553
|
if (!provide.ok) return provide;
|
|
4310
4554
|
return evalOk(createCompiledTokenOverride(target, provide.value, node));
|
|
4311
4555
|
}
|
|
4312
|
-
return evalOk(withRuntimeValue(node, target));
|
|
4556
|
+
return referenceResult(evalOk(withRuntimeValue(node, target)), node, scope);
|
|
4313
4557
|
}
|
|
4314
4558
|
}
|
|
4315
4559
|
if (node.callee.type === "MemberExpression") {
|
|
@@ -4327,7 +4571,7 @@ function evaluateCall(node, scope) {
|
|
|
4327
4571
|
if (!stableId.ok) return stableId;
|
|
4328
4572
|
const stable = stableId.value ?? createCompiledAtRuleStableId(scope, node.loc?.start, frames.value);
|
|
4329
4573
|
const meta = scope.styleMetas?.get(node.callee.object.name);
|
|
4330
|
-
const transformedFrames = transformKeyframes(frames.value, meta?.transform ?? scope.styleTransform ?? null);
|
|
4574
|
+
const transformedFrames = transformKeyframes(frames.value, (meta?.mode === "StyleObject" ? meta.transform : null) ?? scope.styleTransform ?? null);
|
|
4331
4575
|
const format = CSS_EXTRA_CONFIG.namedRuleFormat.keyframes ?? null;
|
|
4332
4576
|
return evalOk(createCompiledAtRuleRef({
|
|
4333
4577
|
value: formatKeyFramesName(format, stable.id, { name: stable.name }),
|
|
@@ -4345,7 +4589,10 @@ function evaluateCall(node, scope) {
|
|
|
4345
4589
|
if (node.callee.type === "MemberExpression" && !node.callee.computed && node.callee.property.type === "Identifier" && node.callee.property.name === "important" && node.callee.object.type === "Identifier" && scope.styleNames?.has(node.callee.object.name)) {
|
|
4346
4590
|
const value = evaluateNode(node.arguments[0], scope);
|
|
4347
4591
|
if (!value.ok) return value;
|
|
4348
|
-
|
|
4592
|
+
const native = node.arguments[1] ? evaluateNode(node.arguments[1], scope) : evalOk(false);
|
|
4593
|
+
if (!native.ok) return native;
|
|
4594
|
+
if (typeof native.value !== "boolean") return evalFail("style.important second argument must be a boolean");
|
|
4595
|
+
return evalOk(importantValue(value.value, native.value));
|
|
4349
4596
|
}
|
|
4350
4597
|
if (node.callee.type === "MemberExpression" && !node.callee.computed && node.callee.property.type === "Identifier" && (node.callee.property.name === "raw" || node.callee.property.name === "plain") && node.callee.object.type === "Identifier" && scope.styleNames?.has(node.callee.object.name)) return evaluateNode(node.arguments[0], scope);
|
|
4351
4598
|
return evalFail(`Cannot statically evaluate: ${node.type}`);
|
|
@@ -4383,6 +4630,7 @@ function createCompiledTokenOverride(token, value, runtimeValue) {
|
|
|
4383
4630
|
[TOKEN_ID]: getStyleTokenId(token),
|
|
4384
4631
|
[TOKEN_OVERRIDE]: true,
|
|
4385
4632
|
[TOKEN_NAME]: getStyleTokenName(token),
|
|
4633
|
+
[TOKEN_VAR_NAME]: token[TOKEN_VAR_NAME] ?? null,
|
|
4386
4634
|
value: value.value,
|
|
4387
4635
|
ref: value
|
|
4388
4636
|
});
|
|
@@ -4390,6 +4638,7 @@ function createCompiledTokenOverride(token, value, runtimeValue) {
|
|
|
4390
4638
|
[TOKEN_ID]: getStyleTokenId(token),
|
|
4391
4639
|
[TOKEN_OVERRIDE]: true,
|
|
4392
4640
|
[TOKEN_NAME]: getStyleTokenName(token),
|
|
4641
|
+
[TOKEN_VAR_NAME]: token[TOKEN_VAR_NAME] ?? null,
|
|
4393
4642
|
value,
|
|
4394
4643
|
ref: null
|
|
4395
4644
|
});
|
|
@@ -4448,6 +4697,7 @@ function assignCompiledTokenRecord(target, value, scope, loc, runtimeValue, stab
|
|
|
4448
4697
|
}
|
|
4449
4698
|
}
|
|
4450
4699
|
function createCompiledValues(values, scope, loc, runtimeValue, stableId, isNumber) {
|
|
4700
|
+
if (!values.length) throw new Error("[Style.values] NO_VALUES");
|
|
4451
4701
|
const tokens = /* @__PURE__ */ new Map();
|
|
4452
4702
|
const groupName = getStyleTokenNameFromId(stableId);
|
|
4453
4703
|
for (let i = 0, len = values.length; i < len; i++) {
|
|
@@ -4464,7 +4714,7 @@ function parseCompiledValue(value, isNumber) {
|
|
|
4464
4714
|
value = String(value).split(/[;|]/)[0].trim();
|
|
4465
4715
|
if (!isNumber) return value;
|
|
4466
4716
|
const number = Number(value);
|
|
4467
|
-
if (!Number.isFinite(number))
|
|
4717
|
+
if (!Number.isFinite(number)) throw new Error(`[Style.values] INVALID_NUMBER_VALUE: ${String(value)}`);
|
|
4468
4718
|
return number;
|
|
4469
4719
|
}
|
|
4470
4720
|
function isCompiledTokenFactory(value) {
|
|
@@ -4512,9 +4762,14 @@ function sanitizeTokenDebugName(value) {
|
|
|
4512
4762
|
return value.replace(/[^a-zA-Z0-9_-]+/g, "-").replace(/^-+|-+$/g, "") || null;
|
|
4513
4763
|
}
|
|
4514
4764
|
function withRuntimeValue(runtimeValue, token) {
|
|
4765
|
+
if (typeof token === "function") return new Proxy(token, { get(target, key) {
|
|
4766
|
+
if (key === COMPILED_RUNTIME_VALUE) return runtimeValue;
|
|
4767
|
+
return Reflect.get(target, key);
|
|
4768
|
+
} });
|
|
4515
4769
|
return Object.assign({}, token, {
|
|
4516
4770
|
[TOKEN_ID]: token[TOKEN_ID],
|
|
4517
4771
|
[TOKEN_NAME]: token[TOKEN_NAME] ?? null,
|
|
4772
|
+
[TOKEN_VAR_NAME]: token[TOKEN_VAR_NAME] ?? null,
|
|
4518
4773
|
[COMPILED_RUNTIME_VALUE]: runtimeValue
|
|
4519
4774
|
});
|
|
4520
4775
|
}
|
|
@@ -4545,6 +4800,34 @@ function evaluateUnary(node, scope) {
|
|
|
4545
4800
|
default: return evalFail(`Unsupported unary operator: ${node.operator}`);
|
|
4546
4801
|
}
|
|
4547
4802
|
}
|
|
4803
|
+
function referenceResult(result, expression, scope) {
|
|
4804
|
+
if (!result.ok) return result;
|
|
4805
|
+
return evalOk(referenceValue(result.value, expression, scope));
|
|
4806
|
+
}
|
|
4807
|
+
function referenceValue(value, expression, scope, nested = false) {
|
|
4808
|
+
if (isStyleTokenData(value) || isStyleTokenOverrideData(value)) {
|
|
4809
|
+
if (nested && value[COMPILED_TOKEN_REFERENCE]?.filePath === scope.filePath) return value;
|
|
4810
|
+
const reference = {
|
|
4811
|
+
expression,
|
|
4812
|
+
filePath: scope.filePath
|
|
4813
|
+
};
|
|
4814
|
+
if (typeof value === "function") return new Proxy(value, { get(target, key) {
|
|
4815
|
+
if (key === COMPILED_TOKEN_REFERENCE) return reference;
|
|
4816
|
+
return Reflect.get(target, key);
|
|
4817
|
+
} });
|
|
4818
|
+
return Object.assign(withRuntimeValue(value[COMPILED_RUNTIME_VALUE] ?? expression, value), { [COMPILED_TOKEN_REFERENCE]: reference });
|
|
4819
|
+
}
|
|
4820
|
+
if (!value || typeof value !== "object" || isCompiledTokenFactory(value)) return value;
|
|
4821
|
+
if (Object.getOwnPropertySymbols(value).some((key) => key !== COMPILED_STYLE_OBJECT_LOCATIONS)) return value;
|
|
4822
|
+
const result = Object.defineProperties(Array.isArray(value) ? [] : {}, Object.getOwnPropertyDescriptors(value));
|
|
4823
|
+
for (const key of Object.keys(value)) result[key] = referenceValue(value[key], BabelCore.types.memberExpression(expression, BabelCore.types.stringLiteral(key), true), scope, true);
|
|
4824
|
+
return result;
|
|
4825
|
+
}
|
|
4826
|
+
function referenceCallResult(result, node, scope) {
|
|
4827
|
+
const imp = node.callee.type === "Identifier" ? scope.imports.get(node.callee.name) : void 0;
|
|
4828
|
+
if (imp && STYLE_IMPORT_PATHS.has(imp.source)) return result;
|
|
4829
|
+
return result.ok && (isStyleTokenData(result.value) || isStyleTokenOverrideData(result.value)) ? referenceResult(result, node, scope) : result;
|
|
4830
|
+
}
|
|
4548
4831
|
//#endregion
|
|
4549
4832
|
//#region compiler/transform/syntax/isStaticStyleValue.ts
|
|
4550
4833
|
function isStaticStyleValue(value) {
|
|
@@ -5039,6 +5322,15 @@ function createDebugPlugin(args) {
|
|
|
5039
5322
|
});
|
|
5040
5323
|
},
|
|
5041
5324
|
CallExpression(path, state) {
|
|
5325
|
+
if (path.node.callee.type === "Identifier") {
|
|
5326
|
+
const imported = state.imports.get(path.node.callee.name);
|
|
5327
|
+
if (imported?.source === "@fluentic/style/css" && imported.name === "createGlobalSheet" && !hasDebugArgument(path.node.arguments)) {
|
|
5328
|
+
const debug = buildDebugDataObject(t, path.node, state.fileId, getSourceUrlId(t, state), sourceContent ? getSourceContentId(t, state) : null);
|
|
5329
|
+
if (!path.getFunctionParent()) debug.properties.push(t.objectProperty(t.identifier("globalModule"), t.stringLiteral(state.filePath)));
|
|
5330
|
+
if (!path.node.arguments.length) path.node.arguments.push(t.arrayExpression([]));
|
|
5331
|
+
path.node.arguments.push(debug);
|
|
5332
|
+
}
|
|
5333
|
+
}
|
|
5042
5334
|
annotateThemeCall(path.node, state, t);
|
|
5043
5335
|
annotateThemeCallsite(t, path, state, sourceContent);
|
|
5044
5336
|
if (!state.styleNames.size) return;
|
|
@@ -5953,12 +6245,23 @@ function compileSheetChain(chain, fileId, scope, cssConfig, options) {
|
|
|
5953
6245
|
const items = [];
|
|
5954
6246
|
const rules = [];
|
|
5955
6247
|
const hasOptions = chain.baseArgs.length === 2;
|
|
5956
|
-
const sheetOptions = hasOptions ? evaluateCreateSheetOptions(chain.baseArgs[0], scope) : {};
|
|
6248
|
+
const sheetOptions = hasOptions ? evaluateCreateSheetOptions(chain.baseArgs[0], scope, chain.global) : {};
|
|
5957
6249
|
if (!sheetOptions) return null;
|
|
6250
|
+
if (chain.global) {
|
|
6251
|
+
if (sheetOptions.specificity !== void 0) throw new Error("createGlobalSheet does not support specificity");
|
|
6252
|
+
sheetOptions.global = true;
|
|
6253
|
+
}
|
|
5958
6254
|
const sheetItems = chain.baseArgs[hasOptions ? 1 : 0];
|
|
5959
6255
|
if (sheetItems && !compileSheetItemsArg(sheetItems, fileId, scope, cssConfig, options, items, rules, sheetOptions)) return null;
|
|
5960
|
-
const sheetLayer = sheetOptions.layer ??
|
|
5961
|
-
for (let i = 0, len = rules.length; i < len; i++)
|
|
6256
|
+
const sheetLayer = sheetOptions.layer ?? false;
|
|
6257
|
+
for (let i = 0, len = rules.length; i < len; i++) {
|
|
6258
|
+
rules[i].layer = resolveSheetLayerOption(sheetLayer, options.css?.layerNamespace ?? DEFAULT_CONFIG.layerNamespace ?? "", isStyleLayerEnabled(options.css?.layer ?? DEFAULT_CONFIG.layer));
|
|
6259
|
+
rules[i].sheet = true;
|
|
6260
|
+
if (chain.global) rules[i].globalSheet = {
|
|
6261
|
+
id: chain.sheetId ?? fileId,
|
|
6262
|
+
order: sheetOptions.order ?? 0
|
|
6263
|
+
};
|
|
6264
|
+
}
|
|
5962
6265
|
return {
|
|
5963
6266
|
type: "sheet",
|
|
5964
6267
|
items,
|
|
@@ -5966,17 +6269,17 @@ function compileSheetChain(chain, fileId, scope, cssConfig, options) {
|
|
|
5966
6269
|
sheetOptions
|
|
5967
6270
|
};
|
|
5968
6271
|
}
|
|
5969
|
-
function evaluateCreateSheetOptions(node, scope) {
|
|
6272
|
+
function evaluateCreateSheetOptions(node, scope, global = false) {
|
|
5970
6273
|
const result = evaluateNode(node, scope);
|
|
5971
6274
|
if (!result.ok || !result.value || typeof result.value !== "object" || Array.isArray(result.value)) return null;
|
|
5972
6275
|
const value = result.value;
|
|
5973
|
-
if (
|
|
5974
|
-
|
|
5975
|
-
if (value.
|
|
5976
|
-
|
|
5977
|
-
|
|
5978
|
-
|
|
5979
|
-
|
|
6276
|
+
if (hasGlobalRuntimeValue(value)) return null;
|
|
6277
|
+
const allowed = global ? ["layer", "order"] : ["layer", "specificity"];
|
|
6278
|
+
if (Object.keys(value).some((key) => !allowed.includes(key))) throw new Error(global ? "createGlobalSheet only supports layer and order" : "createSheet only supports layer and specificity");
|
|
6279
|
+
if (!isSheetLayerOption(value.layer)) throw new Error("invalid sheet layer");
|
|
6280
|
+
if (value.specificity !== void 0 && (!Number.isInteger(value.specificity) || value.specificity < 0)) throw new Error("specificity must be a non-negative integer");
|
|
6281
|
+
if (value.order !== void 0 && (typeof value.order !== "number" || !Number.isFinite(value.order))) throw new Error("order must be a finite number");
|
|
6282
|
+
return value;
|
|
5980
6283
|
}
|
|
5981
6284
|
function compileSheetItemsArg(node, fileId, scope, cssConfig, options, items, rules, sheetOptions) {
|
|
5982
6285
|
if (node.type === "ArrayExpression") {
|
|
@@ -5988,7 +6291,9 @@ function compileSheetItemsArg(node, fileId, scope, cssConfig, options, items, ru
|
|
|
5988
6291
|
return true;
|
|
5989
6292
|
}
|
|
5990
6293
|
const tokenOverride = evaluateNode(node, scope);
|
|
6294
|
+
if (tokenOverride.ok && !tokenOverride.value) return true;
|
|
5991
6295
|
if (tokenOverride.ok && isStyleTokenOverrideData(tokenOverride.value)) {
|
|
6296
|
+
if (sheetOptions.global) throw new Error("createGlobalSheet requires token overrides inside an explicit selector");
|
|
5992
6297
|
addCompiledTokenItem(getStyleTokenId(tokenOverride.value), tokenOverride.value, getCompiledRuntimeValue(tokenOverride.value) ?? node, items);
|
|
5993
6298
|
return true;
|
|
5994
6299
|
}
|
|
@@ -5997,6 +6302,7 @@ function compileSheetItemsArg(node, fileId, scope, cssConfig, options, items, ru
|
|
|
5997
6302
|
const item = tokenOverride.value[i];
|
|
5998
6303
|
if (!item) continue;
|
|
5999
6304
|
if (!isStyleTokenOverrideData(item)) return false;
|
|
6305
|
+
if (sheetOptions.global) throw new Error("createGlobalSheet requires token overrides inside an explicit selector");
|
|
6000
6306
|
addCompiledTokenItem(getStyleTokenId(item), item, getCompiledRuntimeValue(item) ?? null, items);
|
|
6001
6307
|
}
|
|
6002
6308
|
return true;
|
|
@@ -6010,10 +6316,16 @@ function compileSheetItemsArg(node, fileId, scope, cssConfig, options, items, ru
|
|
|
6010
6316
|
}
|
|
6011
6317
|
function compileSelectorOverrideChain(chain, selectors, fileId, scope, cssConfig, transform, styleNames, options, items, rules, sheetOptions) {
|
|
6012
6318
|
if (chain.baseArgs.length === 0 || chain.baseArgs.length > 2) return false;
|
|
6319
|
+
if (sheetOptions.global) {
|
|
6320
|
+
if ([...chain.baseArgs, ...chain.methods.flatMap((method) => method.args)].some((arg) => {
|
|
6321
|
+
const result = evaluateNode(arg, scope);
|
|
6322
|
+
return !result.ok || hasGlobalRuntimeValue(result.value);
|
|
6323
|
+
})) return false;
|
|
6324
|
+
}
|
|
6013
6325
|
const selectorArg = evaluateNode(chain.baseArgs[0], scope);
|
|
6014
6326
|
if (!selectorArg.ok) return false;
|
|
6015
6327
|
const manualSelectors = normalizeManualSelectors(Array.isArray(selectorArg.value) ? selectorArg.value.map(String) : String(selectorArg.value ?? ""));
|
|
6016
|
-
for (let i = 0, len = manualSelectors.length; i < len; i++) if (!compileSelectorOverrideInto(chain, selectors, fileId, scope, cssConfig, transform, styleNames, options, items, rules, setSheetSelectorOptions(manualSelectors[i], sheetOptions))) return false;
|
|
6328
|
+
for (let i = 0, len = manualSelectors.length; i < len; i++) if (!compileSelectorOverrideInto(chain, selectors, fileId, scope, cssConfig, transform, styleNames, options, items, rules, sheetOptions.global ? setGlobalSheetSelectorOptions(manualSelectors[i], sheetOptions) : setSheetSelectorOptions(manualSelectors[i], sheetOptions))) return false;
|
|
6017
6329
|
return true;
|
|
6018
6330
|
}
|
|
6019
6331
|
function compileSelectorOverrideInto(chain, selectors, fileId, scope, cssConfig, transform, styleNames, options, items, rules, selectorPrefix) {
|
|
@@ -6221,7 +6533,7 @@ function decorateClassNameStyle(style, className) {
|
|
|
6221
6533
|
}
|
|
6222
6534
|
function decorateClassNameValue(value, className) {
|
|
6223
6535
|
if (isClassNameValue(value)) return value;
|
|
6224
|
-
if (isStyleImportantValue(value)) return importantValue(decorateClassNameValue(value.value, className));
|
|
6536
|
+
if (isStyleImportantValue(value)) return importantValue(decorateClassNameValue(value.value, className), value.native);
|
|
6225
6537
|
if (isStyleWeightValue(value)) return weightValue(decorateClassNameValue(value.value, className), value.weight);
|
|
6226
6538
|
return classNameValue(value, className);
|
|
6227
6539
|
}
|
|
@@ -6825,6 +7137,7 @@ function addSlotOverrideDataItems(value, parentSelector, atRules, fileId, items,
|
|
|
6825
7137
|
property: overrideItem.property,
|
|
6826
7138
|
weight: overrideItem.weight,
|
|
6827
7139
|
important: overrideItem.important,
|
|
7140
|
+
importantNative: overrideItem.importantNative,
|
|
6828
7141
|
value: overrideItem.value,
|
|
6829
7142
|
variable: overrideItem.variable,
|
|
6830
7143
|
token: overrideItem.token,
|
|
@@ -6876,8 +7189,8 @@ function addRuntimeScopeItem(sourceItem, parentSelector, atRules, fileId, items,
|
|
|
6876
7189
|
const itemAtRules = mergeAtRules(atRules, sourceItem.atRule);
|
|
6877
7190
|
const traceCallsite = callsiteOverride ?? sourceItem.callsite;
|
|
6878
7191
|
const valueStr = String(value ?? "");
|
|
6879
|
-
const dedupe = getClassNameDedupe(sourceItem.property, weight, important, sourceItem.selector, itemParentSelector, itemAtRules);
|
|
6880
|
-
const className = getAtomicClassName(sourceItem.property, weight, important, valueStr, sourceItem.selector, itemParentSelector, itemAtRules, traceCallsite, cssConfig.localClassName, cssConfig.debugClassName, cssConfig.classNameFormat, sourceItem.transformClassName ?? null, cssConfig.transformClassNameFormat, cssConfig.sheetClassNameFormat, cssConfig.hashLength);
|
|
7192
|
+
const dedupe = getClassNameDedupe(sourceItem.property, weight, important, sourceItem.selector, itemParentSelector, itemAtRules, sourceItem.importantNative);
|
|
7193
|
+
const className = getAtomicClassName(sourceItem.property, weight, important, valueStr, sourceItem.selector, itemParentSelector, itemAtRules, traceCallsite, cssConfig.localClassName, cssConfig.debugClassName, cssConfig.classNameFormat, sourceItem.transformClassName ?? null, cssConfig.transformClassNameFormat, cssConfig.sheetClassNameFormat, cssConfig.hashLength, sourceItem.importantNative);
|
|
6881
7194
|
const item = createCompiledItem(4, sourceItem.slotId, dedupe, className, !!itemParentSelector);
|
|
6882
7195
|
items.push(item);
|
|
6883
7196
|
const css = buildAtomicRule(className, sourceItem.property, valueStr, important, sourceItem.selector, itemParentSelector, itemAtRules, cssConfig.scopeTargetPrefix);
|
|
@@ -6888,6 +7201,7 @@ function addRuntimeScopeItem(sourceItem, parentSelector, atRules, fileId, items,
|
|
|
6888
7201
|
css,
|
|
6889
7202
|
priority: layerPriority,
|
|
6890
7203
|
important,
|
|
7204
|
+
importantNative: sourceItem.importantNative,
|
|
6891
7205
|
trace: traceCallsite ? {
|
|
6892
7206
|
filePath: traceCallsite.filePath ?? fileId,
|
|
6893
7207
|
line: traceCallsite.line,
|
|
@@ -6954,9 +7268,9 @@ function addRuntimeStyleItem(sourceItem, selector, parentSelector, atRules, file
|
|
|
6954
7268
|
const runtimeValue = variable?.[0] === 1 ? getCompiledRuntimeValue(variable[2]) : void 0;
|
|
6955
7269
|
const shouldUseVariable = !!variable && (variable[0] !== 1 || !!sourceItem.token || !!runtimeValue);
|
|
6956
7270
|
const valueStr = variable?.[0] === 1 && !shouldUseVariable ? String(variable[2] ?? "") : String(value ?? "");
|
|
6957
|
-
const dedupe = getClassNameDedupe(sourceItem.property, weight, important, itemSelector, parentSelector, itemAtRules);
|
|
7271
|
+
const dedupe = getClassNameDedupe(sourceItem.property, weight, important, itemSelector, parentSelector, itemAtRules, sourceItem.importantNative);
|
|
6958
7272
|
const traceCallsite = callsiteOverride ?? sourceItem.callsite;
|
|
6959
|
-
const className = getAtomicClassName(sourceItem.property, weight, important, valueStr, itemSelector, parentSelector, itemAtRules, traceCallsite, cssConfig.localClassName, cssConfig.debugClassName, cssConfig.classNameFormat, sourceItem.transformClassName ?? null, cssConfig.transformClassNameFormat, cssConfig.sheetClassNameFormat, cssConfig.hashLength);
|
|
7273
|
+
const className = getAtomicClassName(sourceItem.property, weight, important, valueStr, itemSelector, parentSelector, itemAtRules, traceCallsite, cssConfig.localClassName, cssConfig.debugClassName, cssConfig.classNameFormat, sourceItem.transformClassName ?? null, cssConfig.transformClassNameFormat, cssConfig.sheetClassNameFormat, cssConfig.hashLength, sourceItem.importantNative);
|
|
6960
7274
|
const item = createCompiledItem(type, slotId, dedupe, className, !!parentSelector);
|
|
6961
7275
|
item.sourceTrace = getRuntimeStyleItemSourceTrace(sourceItem, fileId);
|
|
6962
7276
|
if (type !== 4 && variable && shouldUseVariable) {
|
|
@@ -6972,6 +7286,7 @@ function addRuntimeStyleItem(sourceItem, selector, parentSelector, atRules, file
|
|
|
6972
7286
|
css,
|
|
6973
7287
|
priority: layerPriority,
|
|
6974
7288
|
important,
|
|
7289
|
+
importantNative: sourceItem.importantNative,
|
|
6975
7290
|
trace: traceCallsite ? {
|
|
6976
7291
|
filePath: traceCallsite.filePath ?? fileId,
|
|
6977
7292
|
line: traceCallsite.line,
|
|
@@ -7038,9 +7353,10 @@ function addStyleItems(styleObj, selector, parentSelector, atRules, fileId, type
|
|
|
7038
7353
|
const rawValue = styleObj[property];
|
|
7039
7354
|
let weight = null;
|
|
7040
7355
|
let important = false;
|
|
7356
|
+
let importantNative = false;
|
|
7041
7357
|
let value = rawValue;
|
|
7042
7358
|
let transformClassName = null;
|
|
7043
|
-
[value, weight, important] = unwrapStaticStyleValue(value);
|
|
7359
|
+
[value, weight, important, importantNative] = unwrapStaticStyleValue(value);
|
|
7044
7360
|
if (isClassNameValue(value)) {
|
|
7045
7361
|
transformClassName = value.className;
|
|
7046
7362
|
value = value.value;
|
|
@@ -7063,8 +7379,8 @@ function addStyleItems(styleObj, selector, parentSelector, atRules, fileId, type
|
|
|
7063
7379
|
const shouldUseVariable = !!(token || runtimeValue);
|
|
7064
7380
|
const variableName = shouldUseVariable && propertyLoc && propertyLoc.variable !== false ? getLocalVarName(cssConfig.runtimeMode === "rsc-dev" ? fileId : propertyLoc.filePath ?? fileId, cssConfig.runtimeMode === "rsc-dev" ? propertyLoc.variableLine ?? propertyLoc.line : propertyLoc.line, cssConfig.runtimeMode === "rsc-dev" ? propertyLoc.variableColumn ?? propertyLoc.column : propertyLoc.column, cssConfig.tokenNameFormat) : null;
|
|
7065
7381
|
const valueStr = variableName ? token ? getCssVarRawFallback(variableName, getTokenVar(token, cssConfig.tokenNameFormat)) : `var(${variableName})` : token ? getTokenVar(token, cssConfig.tokenNameFormat) : String(value);
|
|
7066
|
-
const dedupe = getClassNameDedupe(property, weight, important, selector, parentSelector, atRules);
|
|
7067
|
-
const className = getAtomicClassName(property, weight, important, valueStr, selector, parentSelector, atRules, propertyCallsite, cssConfig.localClassName, cssConfig.debugClassName, cssConfig.classNameFormat, transformClassName, cssConfig.transformClassNameFormat, cssConfig.sheetClassNameFormat, cssConfig.hashLength);
|
|
7382
|
+
const dedupe = getClassNameDedupe(property, weight, important, selector, parentSelector, atRules, importantNative);
|
|
7383
|
+
const className = getAtomicClassName(property, weight, important, valueStr, selector, parentSelector, atRules, propertyCallsite, cssConfig.localClassName, cssConfig.debugClassName, cssConfig.classNameFormat, transformClassName, cssConfig.transformClassNameFormat, cssConfig.sheetClassNameFormat, cssConfig.hashLength, importantNative);
|
|
7068
7384
|
const item = createCompiledItem(type, slotId, dedupe, className, !!parentSelector);
|
|
7069
7385
|
item.sourceTrace = propertyCallsite ? {
|
|
7070
7386
|
property,
|
|
@@ -7097,6 +7413,7 @@ function addStyleItems(styleObj, selector, parentSelector, atRules, fileId, type
|
|
|
7097
7413
|
css,
|
|
7098
7414
|
priority: layerPriority,
|
|
7099
7415
|
important,
|
|
7416
|
+
importantNative,
|
|
7100
7417
|
trace: propertyCallsite ? {
|
|
7101
7418
|
filePath: propertyCallsite.filePath ?? fileId,
|
|
7102
7419
|
line: propertyCallsite.line,
|
|
@@ -7122,9 +7439,11 @@ function addStyleItems(styleObj, selector, parentSelector, atRules, fileId, type
|
|
|
7122
7439
|
function unwrapStaticStyleValue(value) {
|
|
7123
7440
|
let weight = null;
|
|
7124
7441
|
let important = false;
|
|
7442
|
+
let native = false;
|
|
7125
7443
|
while (true) {
|
|
7126
7444
|
if (isStyleImportantValue(value)) {
|
|
7127
7445
|
important = true;
|
|
7446
|
+
native ||= value.native === true;
|
|
7128
7447
|
value = value.value;
|
|
7129
7448
|
continue;
|
|
7130
7449
|
}
|
|
@@ -7138,7 +7457,8 @@ function unwrapStaticStyleValue(value) {
|
|
|
7138
7457
|
return [
|
|
7139
7458
|
value,
|
|
7140
7459
|
weight,
|
|
7141
|
-
important
|
|
7460
|
+
important,
|
|
7461
|
+
native
|
|
7142
7462
|
];
|
|
7143
7463
|
}
|
|
7144
7464
|
function throwIfRequiredStaticStyleValue(result) {
|
|
@@ -7195,6 +7515,13 @@ function getCompiledRuntimeValue(value) {
|
|
|
7195
7515
|
if (!value || typeof value !== "object") return void 0;
|
|
7196
7516
|
return value[COMPILED_RUNTIME_VALUE];
|
|
7197
7517
|
}
|
|
7518
|
+
function hasGlobalRuntimeValue(value, seen = /* @__PURE__ */ new Set()) {
|
|
7519
|
+
if (!value || typeof value !== "object" || isStyleTokenData(value) || isAtRuleRef(value)) return false;
|
|
7520
|
+
if (getCompiledRuntimeValue(value)) return true;
|
|
7521
|
+
if (seen.has(value)) return false;
|
|
7522
|
+
seen.add(value);
|
|
7523
|
+
return Object.values(value).some((item) => hasGlobalRuntimeValue(item, seen));
|
|
7524
|
+
}
|
|
7198
7525
|
//#endregion
|
|
7199
7526
|
//#region compiler/transform/evaluator/tracer.ts
|
|
7200
7527
|
const CACHE_TYPE = "transform-trace";
|
|
@@ -7338,12 +7665,15 @@ function parseAndExtractModule(projectDir, filePath, content, babel, resolveImpo
|
|
|
7338
7665
|
if (spec.type !== "ExportSpecifier") continue;
|
|
7339
7666
|
const local = spec.local.name;
|
|
7340
7667
|
const exported = spec.exported.type === "Identifier" ? spec.exported.name : spec.exported.value;
|
|
7341
|
-
if (stmt.source)
|
|
7342
|
-
|
|
7343
|
-
|
|
7344
|
-
|
|
7345
|
-
|
|
7668
|
+
if (stmt.source) {
|
|
7669
|
+
imports.set(exported, {
|
|
7670
|
+
source: stmt.source.value,
|
|
7671
|
+
name: local
|
|
7672
|
+
});
|
|
7673
|
+
rawBindings.set(exported, t.identifier(exported));
|
|
7674
|
+
} else if (rawBindings.has(local)) rawBindings.set(exported, rawBindings.get(local));
|
|
7346
7675
|
else if (bindings.has(local)) bindings.set(exported, bindings.get(local));
|
|
7676
|
+
else if (imports.has(local)) rawBindings.set(exported, t.identifier(local));
|
|
7347
7677
|
}
|
|
7348
7678
|
continue;
|
|
7349
7679
|
}
|
|
@@ -7356,6 +7686,7 @@ function parseAndExtractModule(projectDir, filePath, content, babel, resolveImpo
|
|
|
7356
7686
|
if (stmt.type === "ExportDefaultDeclaration") rawBindings.set("default", stmt.declaration);
|
|
7357
7687
|
}
|
|
7358
7688
|
const scope = {
|
|
7689
|
+
tokenNameFormat: options.css?.tokenNameFormat ?? null,
|
|
7359
7690
|
bindings,
|
|
7360
7691
|
imports,
|
|
7361
7692
|
styleNames,
|
|
@@ -7663,7 +7994,14 @@ function isExtractRuntimeImportSpecifier(spec) {
|
|
|
7663
7994
|
return EXTRACT_RUNTIME_IMPORT_NAMES.has(imported);
|
|
7664
7995
|
}
|
|
7665
7996
|
function isCompilerHandledImport(source, name) {
|
|
7666
|
-
return IMPORT_PATHS.includes(source) &&
|
|
7997
|
+
return IMPORT_PATHS.includes(source) && [
|
|
7998
|
+
"createTheme",
|
|
7999
|
+
"createToken",
|
|
8000
|
+
"createTokens",
|
|
8001
|
+
"createValues",
|
|
8002
|
+
"createSheet",
|
|
8003
|
+
"createGlobalSheet"
|
|
8004
|
+
].includes(name);
|
|
7667
8005
|
}
|
|
7668
8006
|
//#endregion
|
|
7669
8007
|
//#region compiler/transform/extract/utils/replacement.ts
|
|
@@ -7691,7 +8029,7 @@ function buildSheetOptions(t, chain) {
|
|
|
7691
8029
|
const options = chain.sheetOptions ?? {};
|
|
7692
8030
|
const properties = [];
|
|
7693
8031
|
if (options.layer !== void 0) properties.push(t.objectProperty(t.identifier("layer"), typeof options.layer === "string" ? t.stringLiteral(options.layer) : t.booleanLiteral(options.layer)));
|
|
7694
|
-
if (options.
|
|
8032
|
+
if (options.specificity !== void 0) properties.push(t.objectProperty(t.identifier("specificity"), t.numericLiteral(options.specificity)));
|
|
7695
8033
|
return t.objectExpression(properties);
|
|
7696
8034
|
}
|
|
7697
8035
|
function buildStyleMergeArgs(t, chain, state, options) {
|
|
@@ -7802,7 +8140,11 @@ function buildAtRuleRefExpression(t, ref, state) {
|
|
|
7802
8140
|
}
|
|
7803
8141
|
function buildVariableValueExpression(t, value, state, item, options) {
|
|
7804
8142
|
if (isStyleTokenData(value)) {
|
|
7805
|
-
|
|
8143
|
+
const reference = value[COMPILED_TOKEN_REFERENCE];
|
|
8144
|
+
if (reference?.filePath === state.filePath) {
|
|
8145
|
+
const runtimeToken = options.getRuntimeToken?.(item, reference.expression);
|
|
8146
|
+
if (runtimeToken) return runtimeToken;
|
|
8147
|
+
}
|
|
7806
8148
|
return buildExtractedTokenExpression(t, value, state);
|
|
7807
8149
|
}
|
|
7808
8150
|
const valueNode = item.valueNode;
|
|
@@ -7810,7 +8152,9 @@ function buildVariableValueExpression(t, value, state, item, options) {
|
|
|
7810
8152
|
if (runtimeToken) return runtimeToken;
|
|
7811
8153
|
return valueNode ? t.cloneNode(valueNode) : literalExpression(t, value);
|
|
7812
8154
|
}
|
|
7813
|
-
function buildExtractedTokenExpression(t, token, state) {
|
|
8155
|
+
function buildExtractedTokenExpression(t, token, state, preserveReference = true) {
|
|
8156
|
+
const reference = token[COMPILED_TOKEN_REFERENCE];
|
|
8157
|
+
if (preserveReference && reference?.filePath === state.filePath) return t.cloneNode(reference.expression, true);
|
|
7814
8158
|
state.usedHelpers.add(FN_CREATE_EXTRACTED_TOKEN);
|
|
7815
8159
|
const tokenNameFormat = state.options.css?.tokenNameFormat ?? DEFAULT_CONFIG.tokenNameFormat ?? null;
|
|
7816
8160
|
return t.callExpression(t.identifier(FN_CREATE_EXTRACTED_TOKEN), [
|
|
@@ -7822,6 +8166,8 @@ function buildExtractedTokenExpression(t, token, state) {
|
|
|
7822
8166
|
]);
|
|
7823
8167
|
}
|
|
7824
8168
|
function buildExtractedTokenOverrideExpression(t, token, state) {
|
|
8169
|
+
const reference = token[COMPILED_TOKEN_REFERENCE];
|
|
8170
|
+
if (reference?.filePath === state.filePath) return t.cloneNode(reference.expression, true);
|
|
7825
8171
|
state.usedHelpers.add(FN_CREATE_EXTRACTED_TOKEN);
|
|
7826
8172
|
const tokenNameFormat = state.options.css?.tokenNameFormat ?? DEFAULT_CONFIG.tokenNameFormat ?? null;
|
|
7827
8173
|
const extractedToken = t.callExpression(t.identifier(FN_CREATE_EXTRACTED_TOKEN), [
|
|
@@ -7838,7 +8184,7 @@ function literalExpression(t, value) {
|
|
|
7838
8184
|
if (typeof value === "number") return t.numericLiteral(value);
|
|
7839
8185
|
if (typeof value === "boolean") return t.booleanLiteral(value);
|
|
7840
8186
|
if (value === null || value === void 0) return t.nullLiteral();
|
|
7841
|
-
return t.
|
|
8187
|
+
return t.valueToNode(value);
|
|
7842
8188
|
}
|
|
7843
8189
|
//#endregion
|
|
7844
8190
|
//#region compiler/transform/extract/utils/slot.ts
|
|
@@ -7957,7 +8303,8 @@ function getEvalScope(state) {
|
|
|
7957
8303
|
sheetNames: state.sheetNames,
|
|
7958
8304
|
styleMetas: state.styleMetas,
|
|
7959
8305
|
bindingNodes: state.bindingNodes,
|
|
7960
|
-
runtimeMode: state.runtimeMode
|
|
8306
|
+
runtimeMode: state.runtimeMode,
|
|
8307
|
+
tokenNameFormat: state.options.css?.tokenNameFormat ?? null
|
|
7961
8308
|
};
|
|
7962
8309
|
}
|
|
7963
8310
|
//#endregion
|
|
@@ -8003,6 +8350,62 @@ function compileThemeCall(path, state, opts) {
|
|
|
8003
8350
|
};
|
|
8004
8351
|
}
|
|
8005
8352
|
//#endregion
|
|
8353
|
+
//#region compiler/transform/extract/utils/token.ts
|
|
8354
|
+
function compileTokenFactory(node, state, t) {
|
|
8355
|
+
if (node.callee.type !== "Identifier") return null;
|
|
8356
|
+
const imp = state.imports.get(node.callee.name);
|
|
8357
|
+
if (!imp || !IMPORT_PATHS.includes(imp.source)) return null;
|
|
8358
|
+
if (![
|
|
8359
|
+
"createToken",
|
|
8360
|
+
"createTokens",
|
|
8361
|
+
"createValues"
|
|
8362
|
+
].includes(imp.name)) return null;
|
|
8363
|
+
const inputValue = evaluateNode(node.arguments[0], getEvalScope(state));
|
|
8364
|
+
if (inputValue.ok && hasUnresolvedValue(inputValue.value)) throw new Error(`Cannot extract ${imp.name}: factory inputs must be statically resolvable`);
|
|
8365
|
+
const result = evaluateNode(node, getEvalScope(state));
|
|
8366
|
+
if (!result.ok) throw new Error(`Cannot extract ${imp.name}: ${result.reason}`);
|
|
8367
|
+
if (isCompiledTokenFactory(result.value)) {
|
|
8368
|
+
state.usedHelpers.add(FN_CREATE_EXTRACTED_VALUES);
|
|
8369
|
+
const expression = t.callExpression(t.identifier(FN_CREATE_EXTRACTED_VALUES), [t.arrayExpression([...result.value.tokens].map(([key, token]) => t.arrayExpression([t.valueToNode(key), buildExtractedTokenExpression(t, token, state, false)])))]);
|
|
8370
|
+
t.addComment(expression, "leading", "#__PURE__");
|
|
8371
|
+
return expression;
|
|
8372
|
+
}
|
|
8373
|
+
const input = node.arguments[0];
|
|
8374
|
+
if (imp.name === "createToken") return buildGroup(result.value, input);
|
|
8375
|
+
const raw = evaluateNode(input, getEvalScope(state));
|
|
8376
|
+
const array = raw.ok && Array.isArray(raw.value) ? raw.value : null;
|
|
8377
|
+
if (array) return t.objectExpression(Object.entries(result.value).map(([key, token]) => {
|
|
8378
|
+
let index = array.length - 1;
|
|
8379
|
+
while (index >= 0 && String(array[index]) !== key) index--;
|
|
8380
|
+
return t.objectProperty(t.stringLiteral(key), buildGroup(token, member(input, String(index))), key === "__proto__");
|
|
8381
|
+
}));
|
|
8382
|
+
return buildGroup(result.value, input);
|
|
8383
|
+
function buildGroup(value, source) {
|
|
8384
|
+
if (isStyleTokenData(value)) {
|
|
8385
|
+
const expression = buildExtractedTokenExpression(t, value, state, false);
|
|
8386
|
+
if (!value.ref) expression.arguments[1] = t.cloneNode(source, true);
|
|
8387
|
+
t.addComment(expression, "leading", "#__PURE__");
|
|
8388
|
+
return expression;
|
|
8389
|
+
}
|
|
8390
|
+
if (!value || typeof value !== "object") throw new Error(`Invalid ${imp.name} token group`);
|
|
8391
|
+
return t.objectExpression(Object.entries(value).map(([key, child]) => t.objectProperty(t.stringLiteral(key), buildGroup(child, member(source, key)), key === "__proto__")));
|
|
8392
|
+
}
|
|
8393
|
+
function member(source, key) {
|
|
8394
|
+
if (source.type === "ObjectExpression") for (let index = source.properties.length - 1; index >= 0; index--) {
|
|
8395
|
+
const property = source.properties[index];
|
|
8396
|
+
if (property.type !== "ObjectProperty" || property.computed) break;
|
|
8397
|
+
if (getObjectPropertyKey$1(property) === key) return property.value;
|
|
8398
|
+
}
|
|
8399
|
+
if (source.type === "ArrayExpression" && !source.elements.some((item) => item?.type === "SpreadElement") && source.elements[Number(key)] && t.isExpression(source.elements[Number(key)])) return source.elements[Number(key)];
|
|
8400
|
+
return t.memberExpression(t.cloneNode(source, true), t.stringLiteral(key), true);
|
|
8401
|
+
}
|
|
8402
|
+
}
|
|
8403
|
+
function hasUnresolvedValue(value) {
|
|
8404
|
+
if (!value || typeof value !== "object" || isStyleTokenData(value)) return false;
|
|
8405
|
+
if (value[COMPILED_RUNTIME_VALUE]) return true;
|
|
8406
|
+
return Object.values(value).some(hasUnresolvedValue);
|
|
8407
|
+
}
|
|
8408
|
+
//#endregion
|
|
8006
8409
|
//#region compiler/transform/extract/plugin.ts
|
|
8007
8410
|
function createExtractPlugin(args) {
|
|
8008
8411
|
const { options } = args;
|
|
@@ -8011,6 +8414,7 @@ function createExtractPlugin(args) {
|
|
|
8011
8414
|
const { types: t } = babel;
|
|
8012
8415
|
return {
|
|
8013
8416
|
pre() {
|
|
8417
|
+
this.tokenFactoryReplacements = /* @__PURE__ */ new Map();
|
|
8014
8418
|
this.styleNames = /* @__PURE__ */ new Set();
|
|
8015
8419
|
this.sheetNames = /* @__PURE__ */ new Set();
|
|
8016
8420
|
this.styleMetas = /* @__PURE__ */ new Map();
|
|
@@ -8059,7 +8463,7 @@ function createExtractPlugin(args) {
|
|
|
8059
8463
|
state.styleNames.add(spec.local.name);
|
|
8060
8464
|
state.styleMetas.set(spec.local.name, meta);
|
|
8061
8465
|
}
|
|
8062
|
-
if (sourceName === "@fluentic/style/css" && imported === "createSheet") state.sheetNames.add(spec.local.name);
|
|
8466
|
+
if (sourceName === "@fluentic/style/css" && (imported === "createSheet" || imported === "createGlobalSheet")) state.sheetNames.add(spec.local.name);
|
|
8063
8467
|
});
|
|
8064
8468
|
},
|
|
8065
8469
|
VariableDeclaration(path, state) {
|
|
@@ -8095,6 +8499,12 @@ function createExtractPlugin(args) {
|
|
|
8095
8499
|
state.bindings.set(name, evaluateEnumDeclaration(path.node, scope));
|
|
8096
8500
|
},
|
|
8097
8501
|
CallExpression(path, state) {
|
|
8502
|
+
if (mode === "extract") try {
|
|
8503
|
+
const tokenFactory = compileTokenFactory(path.node, state, t);
|
|
8504
|
+
if (tokenFactory) state.tokenFactoryReplacements.set(path.node, tokenFactory);
|
|
8505
|
+
} catch (error) {
|
|
8506
|
+
throw path.buildCodeFrameError(error instanceof Error ? error.message : String(error));
|
|
8507
|
+
}
|
|
8098
8508
|
if (path.parent.type === "MemberExpression" && !path.parent.computed) return;
|
|
8099
8509
|
const theme = compileThemeCall(path, state, options);
|
|
8100
8510
|
if (theme) {
|
|
@@ -8109,6 +8519,8 @@ function createExtractPlugin(args) {
|
|
|
8109
8519
|
if (!state.styleNames.size && !state.sheetNames.size) return;
|
|
8110
8520
|
const chain = extractStyleChain(path.node, state.styleNames, state.sheetNames);
|
|
8111
8521
|
if (!chain) return;
|
|
8522
|
+
chain.global = chain.kind === "sheet" && state.imports.get(chain.rootName)?.name === "createGlobalSheet";
|
|
8523
|
+
if (chain.global) chain.sheetId = state.fileId + ":" + path.node.start;
|
|
8112
8524
|
if (chain.kind === "slot" && path.parent.type === "CallExpression" && path.parent.callee === path.node) throw path.buildCodeFrameError("Direct invocation `style.slot(...)()` is not allowed. Assign the slot to a variable first, then call it through that binding.");
|
|
8113
8525
|
const scope = getEvalScope(state);
|
|
8114
8526
|
const loc = path.node.loc?.start;
|
|
@@ -8130,6 +8542,12 @@ function createExtractPlugin(args) {
|
|
|
8130
8542
|
state.collector.add(rule);
|
|
8131
8543
|
});
|
|
8132
8544
|
if (mode === "collect") return;
|
|
8545
|
+
if (chain.global) {
|
|
8546
|
+
if (path.parentPath.isExpressionStatement()) path.parentPath.remove();
|
|
8547
|
+
else path.replaceWith(t.unaryExpression("void", t.numericLiteral(0)));
|
|
8548
|
+
path.skip();
|
|
8549
|
+
return;
|
|
8550
|
+
}
|
|
8133
8551
|
const replacement = createChainReplacement({
|
|
8134
8552
|
t,
|
|
8135
8553
|
path,
|
|
@@ -8151,6 +8569,13 @@ function createExtractPlugin(args) {
|
|
|
8151
8569
|
},
|
|
8152
8570
|
Program: { exit(path, state) {
|
|
8153
8571
|
if (mode === "collect") return;
|
|
8572
|
+
path.traverse({ CallExpression(factoryPath) {
|
|
8573
|
+
const replacement = state.tokenFactoryReplacements.get(factoryPath.node);
|
|
8574
|
+
if (!replacement) return;
|
|
8575
|
+
factoryPath.replaceWith(replacement);
|
|
8576
|
+
factoryPath.skip();
|
|
8577
|
+
state.needsExtractImport = true;
|
|
8578
|
+
} });
|
|
8154
8579
|
pruneUnusedStyleInputDeclarations(path, state);
|
|
8155
8580
|
pruneUnusedStyleImports(path, state);
|
|
8156
8581
|
if (!state.needsExtractImport) return;
|
|
@@ -8177,23 +8602,35 @@ function checkCompiledImportantUsage(result, options, report) {
|
|
|
8177
8602
|
if (hasOutsideSheet && options.outsideSheet) report(options.outsideSheet, "style.important(...) outside createSheet is discouraged. Prefer style.weight(...) for Fluentic style priority.");
|
|
8178
8603
|
}
|
|
8179
8604
|
function pruneUnusedStyleInputDeclarations(path, state) {
|
|
8180
|
-
|
|
8181
|
-
|
|
8182
|
-
|
|
8183
|
-
|
|
8184
|
-
|
|
8185
|
-
|
|
8186
|
-
|
|
8187
|
-
|
|
8188
|
-
|
|
8189
|
-
|
|
8190
|
-
|
|
8191
|
-
|
|
8192
|
-
|
|
8605
|
+
const dependencies = /* @__PURE__ */ new Set();
|
|
8606
|
+
let changed;
|
|
8607
|
+
do {
|
|
8608
|
+
changed = false;
|
|
8609
|
+
path.scope.crawl();
|
|
8610
|
+
path.traverse({ VariableDeclarator(declaratorPath) {
|
|
8611
|
+
const node = declaratorPath.node;
|
|
8612
|
+
if (declaratorPath.parentPath?.parentPath?.isExportNamedDeclaration()) return;
|
|
8613
|
+
if (node.id.type !== "Identifier") return;
|
|
8614
|
+
const binding = declaratorPath.scope.getBinding(node.id.name);
|
|
8615
|
+
if (!binding || !binding.constant || binding.referencePaths.length) return;
|
|
8616
|
+
if (!isStyleInputCall(node.init, state) && !(dependencies.has(node) && declaratorPath.get("init").isPure())) return;
|
|
8617
|
+
declaratorPath.get("init").traverse({ ReferencedIdentifier(reference) {
|
|
8618
|
+
const dependency = reference.scope.getBinding(reference.node.name);
|
|
8619
|
+
if (dependency?.path.isVariableDeclarator()) dependencies.add(dependency.path.node);
|
|
8620
|
+
} });
|
|
8621
|
+
const declarationPath = declaratorPath.parentPath;
|
|
8622
|
+
if (!declarationPath?.isVariableDeclaration()) return;
|
|
8623
|
+
if (declarationPath.node.declarations.length > 1) declaratorPath.remove();
|
|
8624
|
+
else declarationPath.remove();
|
|
8625
|
+
changed = true;
|
|
8626
|
+
} });
|
|
8627
|
+
} while (changed);
|
|
8193
8628
|
path.scope.crawl();
|
|
8194
8629
|
}
|
|
8195
8630
|
function isStyleInputCall(node, state) {
|
|
8196
8631
|
if (!node || node.type !== "CallExpression") return false;
|
|
8632
|
+
const selectorChain = extractStyleChain(node, state.styleNames, state.sheetNames);
|
|
8633
|
+
if (selectorChain?.kind === "selector") return selectorChain.baseArgs.every((arg) => evaluateNode(arg, getEvalScope(state)).ok) && selectorChain.methods.every((method) => method.args.every((arg) => evaluateNode(arg, getEvalScope(state)).ok));
|
|
8197
8634
|
const callee = node.callee;
|
|
8198
8635
|
if (callee.type !== "MemberExpression" || callee.computed) return false;
|
|
8199
8636
|
if (callee.object.type !== "Identifier") return false;
|
|
@@ -8251,7 +8688,8 @@ function createRuntimeTokenCollector(args) {
|
|
|
8251
8688
|
return {
|
|
8252
8689
|
overrides,
|
|
8253
8690
|
addOverride(item) {
|
|
8254
|
-
|
|
8691
|
+
const reference = item.value[COMPILED_TOKEN_REFERENCE];
|
|
8692
|
+
overrides.push(args.t.cloneNode(reference?.filePath === args.state.filePath ? reference.expression : item.valueNode, true));
|
|
8255
8693
|
},
|
|
8256
8694
|
add(item, valueNode) {
|
|
8257
8695
|
if (canHoistRuntimeValue(args.path, valueNode)) return null;
|
|
@@ -8565,4 +9003,4 @@ const CssPropPresets = {
|
|
|
8565
9003
|
//#endregion
|
|
8566
9004
|
export { getDefaultSourcemapUrl as a, getStyleFnMeta as c, babelTransform as d, extractCss as f, createCompilerCache as g, globalData as h, CompilerRuntimeMode as i, isPromiseLike as l, SIDECAR_URL_GLOBAL_SYMBOL as m, createCompiler as n, normalizeSourcemapSourcePath as o, compareLayerPriority as p, getStyleRuntimeImportPath as r, normalizePath as s, CssPropPresets as t, babelPlugin as u };
|
|
8567
9005
|
|
|
8568
|
-
//# sourceMappingURL=compiler-
|
|
9006
|
+
//# sourceMappingURL=compiler-AOb_VaKQ.mjs.map
|