@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
|
@@ -40,12 +40,18 @@ function symbol(name) {
|
|
|
40
40
|
}
|
|
41
41
|
//#endregion
|
|
42
42
|
//#region utils/global.ts
|
|
43
|
+
function getGlobalData(key) {
|
|
44
|
+
return globalThis[symbol(key)];
|
|
45
|
+
}
|
|
43
46
|
function globalData(key, data) {
|
|
44
47
|
const id = symbol(key);
|
|
45
48
|
const root = globalThis;
|
|
46
49
|
if (root[id] === void 0) assign(root, id, data());
|
|
47
50
|
return root[id];
|
|
48
51
|
}
|
|
52
|
+
function clearGlobalData(key) {
|
|
53
|
+
delete globalThis[symbol(key)];
|
|
54
|
+
}
|
|
49
55
|
function assign(target, id, value) {
|
|
50
56
|
Object.defineProperty(target, id, {
|
|
51
57
|
value,
|
|
@@ -72,12 +78,9 @@ function isStyleLayerEnabled(layer = CSS_CONFIG.layer) {
|
|
|
72
78
|
function isSheetLayerOption(value) {
|
|
73
79
|
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);
|
|
74
80
|
}
|
|
75
|
-
function resolveSheetLayerOption(layer, namespace) {
|
|
76
|
-
if (typeof layer !== "string") return layer ? "
|
|
77
|
-
return { name: layer.startsWith(".") ? namespace ? namespace + layer : layer.slice(1) : layer };
|
|
78
|
-
}
|
|
79
|
-
function isSheetLayerEnabled(layer = CSS_CONFIG.layer) {
|
|
80
|
-
return typeof layer === "object" && (layer.sheet ?? false);
|
|
81
|
+
function resolveSheetLayerOption(layer, namespace, mainLayerEnabled = isStyleLayerEnabled()) {
|
|
82
|
+
if (typeof layer !== "string") return layer && mainLayerEnabled ? "style" : false;
|
|
83
|
+
return { name: layer.startsWith(".") ? mainLayerEnabled && namespace ? namespace + layer : layer.slice(1) : layer };
|
|
81
84
|
}
|
|
82
85
|
//#endregion
|
|
83
86
|
//#region config/utils.ts
|
|
@@ -110,6 +113,21 @@ const DEFAULT_DEBUG_CONFIG = {
|
|
|
110
113
|
};
|
|
111
114
|
const DEBUG_CONFIG = globalData("config.debug", () => ({ ...DEFAULT_DEBUG_CONFIG }));
|
|
112
115
|
//#endregion
|
|
116
|
+
//#region config/document.ts
|
|
117
|
+
const state$2 = globalData("config.document", () => ({
|
|
118
|
+
target: true,
|
|
119
|
+
listeners: /* @__PURE__ */ new Set()
|
|
120
|
+
}));
|
|
121
|
+
function getRuntimeDocument(documentOverride) {
|
|
122
|
+
if (state$2.target === false) return null;
|
|
123
|
+
if (state$2.target !== true) return state$2.target;
|
|
124
|
+
if (documentOverride) return documentOverride;
|
|
125
|
+
return typeof globalThis.document === "undefined" ? null : globalThis.document;
|
|
126
|
+
}
|
|
127
|
+
function onRuntimeDocumentChange(listener) {
|
|
128
|
+
state$2.listeners.add(listener);
|
|
129
|
+
}
|
|
130
|
+
//#endregion
|
|
113
131
|
//#region utils/hash.ts
|
|
114
132
|
function hashString(str) {
|
|
115
133
|
let hash = 2166136261;
|
|
@@ -124,6 +142,41 @@ function normalizeHashLength(length) {
|
|
|
124
142
|
function compareLayerPriority(p1, p2) {
|
|
125
143
|
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];
|
|
126
144
|
}
|
|
145
|
+
function createLayerNamePool() {
|
|
146
|
+
const lookup = /* @__PURE__ */ new Map();
|
|
147
|
+
const getLayerId = (priority) => {
|
|
148
|
+
const key = priority.join("|");
|
|
149
|
+
let name = lookup.get(key);
|
|
150
|
+
if (name) return name;
|
|
151
|
+
name = "p" + hashString(key);
|
|
152
|
+
lookup.set(key, name);
|
|
153
|
+
return name;
|
|
154
|
+
};
|
|
155
|
+
const getLayerName = (layerNamespace, priority) => {
|
|
156
|
+
const layerId = getLayerId(priority);
|
|
157
|
+
return layerNamespace ? layerNamespace + "." + layerId : layerId;
|
|
158
|
+
};
|
|
159
|
+
return {
|
|
160
|
+
getLayerName,
|
|
161
|
+
getLayerId
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
function createLayerPool(layerNamespace) {
|
|
165
|
+
const namePool = createLayerNamePool();
|
|
166
|
+
const priorities = /* @__PURE__ */ new Map();
|
|
167
|
+
const getName = (priority) => {
|
|
168
|
+
const key = priority.join("|");
|
|
169
|
+
if (!priorities.has(key)) priorities.set(key, priority);
|
|
170
|
+
return namePool.getLayerName(layerNamespace, priority);
|
|
171
|
+
};
|
|
172
|
+
const getNames = () => {
|
|
173
|
+
return Array.from(priorities.values()).sort(compareLayerPriority).map((priority) => namePool.getLayerName(layerNamespace, priority));
|
|
174
|
+
};
|
|
175
|
+
return {
|
|
176
|
+
getName,
|
|
177
|
+
getNames
|
|
178
|
+
};
|
|
179
|
+
}
|
|
127
180
|
function flattenCssLayers(layers, layerNames) {
|
|
128
181
|
const names = typeof layerNames === "string" ? [layerNames] : layerNames;
|
|
129
182
|
return [...new Set(layers.flatMap((layer) => layer === "$layer" ? names.filter((name) => !layers.includes(name)) : layer).filter(Boolean))];
|
|
@@ -182,6 +235,108 @@ function createCssCollector() {
|
|
|
182
235
|
}
|
|
183
236
|
};
|
|
184
237
|
}
|
|
238
|
+
function getSheetRulePriority(priority) {
|
|
239
|
+
return priority ?? LayerDefaultPriority;
|
|
240
|
+
}
|
|
241
|
+
function getSheetRuleLayerPriority(priority, important) {
|
|
242
|
+
const resolved = getSheetRulePriority(priority);
|
|
243
|
+
return important ? [
|
|
244
|
+
-resolved[0],
|
|
245
|
+
-resolved[1],
|
|
246
|
+
-resolved[2],
|
|
247
|
+
-resolved[3],
|
|
248
|
+
-resolved[4],
|
|
249
|
+
-resolved[5],
|
|
250
|
+
-resolved[6]
|
|
251
|
+
] : resolved;
|
|
252
|
+
}
|
|
253
|
+
//#endregion
|
|
254
|
+
//#region sheet/ordering.ts
|
|
255
|
+
function sheetRuleLayer(rule, config = CSS_CONFIG) {
|
|
256
|
+
const mainEnabled = isStyleLayerEnabled(config.layer);
|
|
257
|
+
let layer = rule.layer ?? "style";
|
|
258
|
+
if (layer === "style" && !mainEnabled) layer = false;
|
|
259
|
+
if (rule.sheet && rule.important && !rule.importantNative && layer !== false) return { name: (typeof layer === "object" ? layer.name : config.layerNamespace || "css") + ".important" };
|
|
260
|
+
return layer;
|
|
261
|
+
}
|
|
262
|
+
function sheetRuleGroup(rule, config = CSS_CONFIG) {
|
|
263
|
+
if (rule.globalSheet) return "global:" + rule.globalSheet.id;
|
|
264
|
+
return rule.sheet && sheetRuleLayer(rule, config) === false ? "local-unlayered" : "regular";
|
|
265
|
+
}
|
|
266
|
+
function compareSheetGroups(a, b) {
|
|
267
|
+
const region = (rule) => rule.globalSheet ? rule.globalSheet.order <= 0 ? 0 : 2 : 1;
|
|
268
|
+
const order = region(a) - region(b);
|
|
269
|
+
if (order) return order;
|
|
270
|
+
if (a.globalSheet && b.globalSheet) return a.globalSheet.order - b.globalSheet.order;
|
|
271
|
+
return 0;
|
|
272
|
+
}
|
|
273
|
+
function compareSheetRules(a, b, config = CSS_CONFIG) {
|
|
274
|
+
const layerRank = (rule) => {
|
|
275
|
+
const layer = sheetRuleLayer(rule, config);
|
|
276
|
+
const main = config.layerNamespace || "css";
|
|
277
|
+
return layer === false ? 2 : layer === "style" || typeof layer === "object" && layer.name === main ? 0 : 1;
|
|
278
|
+
};
|
|
279
|
+
return layerRank(a) - layerRank(b) || compareLayerPriority(getSheetRulePriority(a.priority), getSheetRulePriority(b.priority));
|
|
280
|
+
}
|
|
281
|
+
/** Stable group sort: equal global orders keep the first-discovered sheet first. */
|
|
282
|
+
function orderSheetRules(rules, config = CSS_CONFIG) {
|
|
283
|
+
const groups = /* @__PURE__ */ new Map();
|
|
284
|
+
for (const rule of rules) {
|
|
285
|
+
const key = sheetRuleGroup(rule, config);
|
|
286
|
+
const group = groups.get(key) ?? [];
|
|
287
|
+
group.push(rule);
|
|
288
|
+
groups.set(key, group);
|
|
289
|
+
}
|
|
290
|
+
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)));
|
|
291
|
+
}
|
|
292
|
+
/** Reserve each parent's first child for managed important declarations. */
|
|
293
|
+
function sheetLayerOrder(names, config = CSS_CONFIG, reservedParents = names) {
|
|
294
|
+
const roots = [];
|
|
295
|
+
const children = /* @__PURE__ */ new Map();
|
|
296
|
+
const add = (name) => {
|
|
297
|
+
const parts = name.split(".");
|
|
298
|
+
if (!roots.includes(parts[0])) roots.push(parts[0]);
|
|
299
|
+
for (let i = 1; i < parts.length; i++) {
|
|
300
|
+
const parent = parts.slice(0, i).join(".");
|
|
301
|
+
const child = parts.slice(0, i + 1).join(".");
|
|
302
|
+
const list = children.get(parent) ?? [];
|
|
303
|
+
if (!list.includes(child)) list.push(child);
|
|
304
|
+
children.set(parent, list);
|
|
305
|
+
}
|
|
306
|
+
if (!name.endsWith(".important") && reservedParents.includes(name)) children.set(name, children.get(name) ?? []);
|
|
307
|
+
};
|
|
308
|
+
for (const name of [...(config.layers ?? CSS_CONFIG_DEFAULT.layers ?? []).filter((name) => name !== "$layer"), ...names]) add(name);
|
|
309
|
+
const declarations = [getLayerOrderCss((config.layers ?? CSS_CONFIG_DEFAULT.layers ?? []).map((name) => name === "$layer" ? name : name.split(".")[0]), roots)];
|
|
310
|
+
for (const [parent, list] of children) {
|
|
311
|
+
if (parent.endsWith(".important")) continue;
|
|
312
|
+
declarations.push("@layer " + [...new Set([parent + ".important", ...list])].join(", ") + ";");
|
|
313
|
+
}
|
|
314
|
+
return declarations.filter(Boolean).join("\n");
|
|
315
|
+
}
|
|
316
|
+
function layerNameForRule(rule, config, mode, pool) {
|
|
317
|
+
const layer = sheetRuleLayer(rule, config);
|
|
318
|
+
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";
|
|
319
|
+
}
|
|
320
|
+
/** Build only ordering declarations; runtime flushing need not serialize rule bodies. */
|
|
321
|
+
function sheetOrderingPreamble(rules, config = CSS_CONFIG, mode = "sort") {
|
|
322
|
+
const pool = createLayerPool(config.layerNamespace || "css");
|
|
323
|
+
const names = /* @__PURE__ */ new Set();
|
|
324
|
+
for (const rule of orderSheetRules(rules, config)) {
|
|
325
|
+
const name = layerNameForRule(rule, config, mode, pool);
|
|
326
|
+
if (name) names.add(name);
|
|
327
|
+
}
|
|
328
|
+
const priorities = pool.getNames();
|
|
329
|
+
const named = [...names].filter((name) => !priorities.includes(name));
|
|
330
|
+
return sheetLayerOrder([...priorities, ...named], config, named);
|
|
331
|
+
}
|
|
332
|
+
function serializeOrderedRules(rules, config = CSS_CONFIG, mode = "sort") {
|
|
333
|
+
const pool = createLayerPool(config.layerNamespace || "css");
|
|
334
|
+
const rendered = orderSheetRules(rules, config).map((rule) => {
|
|
335
|
+
const name = layerNameForRule(rule, config, mode, pool);
|
|
336
|
+
return name ? getLayerBlockCss(name, rule.css) : rule.css;
|
|
337
|
+
});
|
|
338
|
+
return [sheetOrderingPreamble(rules, config, mode), ...rendered].filter(Boolean).join("\n");
|
|
339
|
+
}
|
|
185
340
|
const STYLE_IMPORT_PATH = "@fluentic/style";
|
|
186
341
|
const STYLE_CSS_IMPORT_PATH = "@fluentic/style/css";
|
|
187
342
|
const STYLE_DIALECT_IMPORT_PATH = "@fluentic/style/dialect";
|
|
@@ -213,6 +368,7 @@ const FN_CREATE_EXTRACTED_SHEET = "createExtractedSheet";
|
|
|
213
368
|
const FN_CREATE_EXTRACTED_SLOT = "createExtractedSlot";
|
|
214
369
|
const FN_CREATE_EXTRACTED_SCOPE = "createExtractedScope";
|
|
215
370
|
const FN_CREATE_EXTRACTED_TOKEN = "createExtractedToken";
|
|
371
|
+
const FN_CREATE_EXTRACTED_VALUES = "createExtractedValues";
|
|
216
372
|
const FN_CREATE_EXTRACTED_THEME = "createExtractedTheme";
|
|
217
373
|
const FN_CREATE_EXTRACTED_STYLE_MERGE = "createExtractedStyleMerge";
|
|
218
374
|
const FN_WITH_TOKENS = "withTokens";
|
|
@@ -221,46 +377,26 @@ const DEBUG_SOURCE_CONTENT_VAR = "_styleDebugSourceContent";
|
|
|
221
377
|
//#endregion
|
|
222
378
|
//#region compiler/extract/extract.ts
|
|
223
379
|
function extractCss(items, args) {
|
|
224
|
-
return getExtractedCssItems(items, args);
|
|
225
|
-
}
|
|
226
|
-
function getExtractedCssItems(items, args) {
|
|
227
|
-
const sortedItems = items.slice().sort((a, b) => compareLayerPriority(a.priority, b.priority));
|
|
228
380
|
const seen = /* @__PURE__ */ new Set();
|
|
229
|
-
const
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
381
|
+
const unique = items.filter((item) => {
|
|
382
|
+
const key = JSON.stringify([
|
|
383
|
+
item.globalSheet?.id,
|
|
384
|
+
item.globalSheet?.order,
|
|
385
|
+
item.sheet,
|
|
386
|
+
item.layer,
|
|
387
|
+
item.importantNative,
|
|
388
|
+
item.css
|
|
389
|
+
]);
|
|
390
|
+
if (seen.has(key)) return false;
|
|
233
391
|
seen.add(key);
|
|
234
|
-
|
|
235
|
-
}
|
|
236
|
-
if (!
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
const styleItems = [];
|
|
243
|
-
const sheetItems = /* @__PURE__ */ new Map();
|
|
244
|
-
const unlayeredItems = [];
|
|
245
|
-
for (let i = 0, len = css.length; i < len; i++) {
|
|
246
|
-
const item = css[i];
|
|
247
|
-
if (item.layer === "sheet" || typeof item.layer === "object") {
|
|
248
|
-
const name = typeof item.layer === "object" ? item.layer.name : sheetLayerName;
|
|
249
|
-
const rules = sheetItems.get(name) ?? [];
|
|
250
|
-
rules.push(item.css);
|
|
251
|
-
sheetItems.set(name, rules);
|
|
252
|
-
} else if (item.layer === false || !styleLayer) unlayeredItems.push(item.css);
|
|
253
|
-
else styleItems.push(item.css);
|
|
254
|
-
}
|
|
255
|
-
const styleLayerName = [...sheetItems.keys()].some((name) => name.startsWith(layerNamespace + ".")) && layerNamespace ? layerNamespace + ".style" : layerNamespace;
|
|
256
|
-
const layerNames = [styleItems.length ? styleLayerName : "", ...sheetItems.keys()].filter(Boolean);
|
|
257
|
-
const output = [];
|
|
258
|
-
const layerOrder = getLayerOrderCss(layers, layerNames);
|
|
259
|
-
if (layerOrder) output.push(layerOrder);
|
|
260
|
-
if (styleItems.length) output.push(getLayerBlockCss(styleLayerName, "\n" + styleItems.join("\n") + "\n"));
|
|
261
|
-
for (const [name, rules] of sheetItems) output.push(getLayerBlockCss(name, "\n" + rules.join("\n") + "\n"));
|
|
262
|
-
output.push(...unlayeredItems);
|
|
263
|
-
return output.join("\n");
|
|
392
|
+
return true;
|
|
393
|
+
});
|
|
394
|
+
if (!unique.length) return "";
|
|
395
|
+
return serializeOrderedRules(unique, {
|
|
396
|
+
layer: args.layer ?? DEFAULT_CONFIG.layer ?? true,
|
|
397
|
+
layers: args.layers ?? DEFAULT_CONFIG.layers,
|
|
398
|
+
layerNamespace: args.layerNamespace ?? DEFAULT_CONFIG.layerNamespace
|
|
399
|
+
});
|
|
264
400
|
}
|
|
265
401
|
//#endregion
|
|
266
402
|
//#region compiler/utils/path.ts
|
|
@@ -485,7 +621,7 @@ function babelTransform(args) {
|
|
|
485
621
|
error.stack = void 0;
|
|
486
622
|
throw error;
|
|
487
623
|
}
|
|
488
|
-
if (!result ||
|
|
624
|
+
if (!result || result.code == null) return null;
|
|
489
625
|
return {
|
|
490
626
|
code: result.code,
|
|
491
627
|
sourcemap: result.map ? JSON.stringify(result.map) : null
|
|
@@ -609,6 +745,7 @@ const BUILDER_SCOPE_ID = symbol("builder.scopeId");
|
|
|
609
745
|
const BUILDER_SCOPE = symbol("builder.scope");
|
|
610
746
|
const BUILDER_SELECTOR = symbol("builder.selector");
|
|
611
747
|
const BUILDER_SHEET_OPTIONS = symbol("builder.sheetOptions");
|
|
748
|
+
const GLOBAL_SHEET_SELECTOR_ANCHOR = "\0global";
|
|
612
749
|
const SHEET_SELECTOR_ANCHOR = "\0sheet";
|
|
613
750
|
//#endregion
|
|
614
751
|
//#region utils/object.ts
|
|
@@ -719,7 +856,7 @@ function createStackFrameLine(frame) {
|
|
|
719
856
|
}
|
|
720
857
|
function isInternalCallsite(filePath) {
|
|
721
858
|
const normalized = filePath.replace(/\\/g, "/");
|
|
722
|
-
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.");
|
|
859
|
+
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.");
|
|
723
860
|
}
|
|
724
861
|
function traceError(message, options = {}) {
|
|
725
862
|
const error = new Error(message || "");
|
|
@@ -848,6 +985,9 @@ function getStyleTokenId(token) {
|
|
|
848
985
|
function getStyleTokenName(token) {
|
|
849
986
|
return token[TOKEN_NAME] ?? null;
|
|
850
987
|
}
|
|
988
|
+
function getStyleTokenVarName(token) {
|
|
989
|
+
return token[TOKEN_VAR_NAME] ?? null;
|
|
990
|
+
}
|
|
851
991
|
//#endregion
|
|
852
992
|
//#region builder/token/name.ts
|
|
853
993
|
function getStyleTokenNameFromId(id) {
|
|
@@ -907,12 +1047,14 @@ function createStyleTokenOverride(token, value, debug) {
|
|
|
907
1047
|
[TOKEN_ID]: getStyleTokenId(token),
|
|
908
1048
|
[TOKEN_OVERRIDE]: true,
|
|
909
1049
|
[TOKEN_NAME]: getStyleTokenName(token),
|
|
1050
|
+
[TOKEN_VAR_NAME]: token[TOKEN_VAR_NAME] ?? null,
|
|
910
1051
|
value: value.value,
|
|
911
1052
|
ref: value
|
|
912
1053
|
} : {
|
|
913
1054
|
[TOKEN_ID]: getStyleTokenId(token),
|
|
914
1055
|
[TOKEN_OVERRIDE]: true,
|
|
915
1056
|
[TOKEN_NAME]: getStyleTokenName(token),
|
|
1057
|
+
[TOKEN_VAR_NAME]: token[TOKEN_VAR_NAME] ?? null,
|
|
916
1058
|
value,
|
|
917
1059
|
ref: null
|
|
918
1060
|
};
|
|
@@ -1465,7 +1607,9 @@ function getIdentifierSafeHashValue(hash) {
|
|
|
1465
1607
|
//#endregion
|
|
1466
1608
|
//#region atomic/utils/selector.ts
|
|
1467
1609
|
function getSelectorText$1(selector) {
|
|
1468
|
-
|
|
1610
|
+
const text = Array.isArray(selector) ? selector[0] : selector;
|
|
1611
|
+
if (text.startsWith("\0global")) return text.slice(text.indexOf("\0", 7) + 1);
|
|
1612
|
+
return stripSheetSelectorAnchor(text);
|
|
1469
1613
|
}
|
|
1470
1614
|
function getSelectorHash(selector) {
|
|
1471
1615
|
return Array.isArray(selector) ? selector.join("|") : selector;
|
|
@@ -1477,14 +1621,15 @@ function getSelectorPriority$1(selector) {
|
|
|
1477
1621
|
function hasSheetSelectorAnchor(selector) {
|
|
1478
1622
|
return (selector ? Array.isArray(selector) ? selector[0] : selector : "").startsWith(SHEET_SELECTOR_ANCHOR);
|
|
1479
1623
|
}
|
|
1480
|
-
function
|
|
1624
|
+
function getSheetSelectorSpecificity(selector) {
|
|
1481
1625
|
const text = selector ? Array.isArray(selector) ? selector[0] : selector : "";
|
|
1482
1626
|
if (!text.startsWith("\0sheet:")) return null;
|
|
1483
1627
|
const end = text.indexOf("\0", 6);
|
|
1484
1628
|
if (end < 0) return null;
|
|
1485
1629
|
const [weightValue] = text.slice(7, end).split(":");
|
|
1630
|
+
if (!weightValue) return null;
|
|
1486
1631
|
const weight = Number(weightValue);
|
|
1487
|
-
return Number.isInteger(weight) && weight
|
|
1632
|
+
return Number.isInteger(weight) && weight >= 0 ? weight : null;
|
|
1488
1633
|
}
|
|
1489
1634
|
function stripSheetSelectorAnchor(selector) {
|
|
1490
1635
|
if (!selector.startsWith("\0sheet")) return selector;
|
|
@@ -1494,12 +1639,16 @@ function stripSheetSelectorAnchor(selector) {
|
|
|
1494
1639
|
}
|
|
1495
1640
|
return selector.slice(6);
|
|
1496
1641
|
}
|
|
1642
|
+
function hasGlobalSheetSelectorAnchor(selector) {
|
|
1643
|
+
return (selector ? Array.isArray(selector) ? selector[0] : selector : "").startsWith(GLOBAL_SHEET_SELECTOR_ANCHOR);
|
|
1644
|
+
}
|
|
1497
1645
|
//#endregion
|
|
1498
1646
|
//#region atomic/className.ts
|
|
1499
|
-
function getAtomicClassName(property, priority, important, value, selector, parentSelector, atRule, callsite, localClassName, debugClassName, classNameFormat, transformClassName, transformClassNameFormat, sheetClassNameFormat = null, hashLength = null) {
|
|
1647
|
+
function getAtomicClassName(property, priority, important, value, selector, parentSelector, atRule, callsite, localClassName, debugClassName, classNameFormat, transformClassName, transformClassNameFormat, sheetClassNameFormat = null, hashLength = null, importantNative = false) {
|
|
1500
1648
|
let hash = property;
|
|
1501
1649
|
hash += "\n" + (priority || "");
|
|
1502
1650
|
if (important) hash += "\nimportant";
|
|
1651
|
+
if (importantNative) hash += "\nnative-important";
|
|
1503
1652
|
hash += "\n" + value;
|
|
1504
1653
|
hash += "\n" + (selector ? getSelectorHash(selector) : "");
|
|
1505
1654
|
hash += "\n" + (parentSelector ? getSelectorHash(parentSelector) : "");
|
|
@@ -1530,10 +1679,11 @@ function getClassNameHashLength(options) {
|
|
|
1530
1679
|
if (options.debugClassName && options.isDev) return options.devHashLength ?? options.cssHashLength ?? 5;
|
|
1531
1680
|
return options.cssHashLength ?? 7;
|
|
1532
1681
|
}
|
|
1533
|
-
function getClassNameDedupe(property, priority, important, selector, parentSelector, atRule) {
|
|
1682
|
+
function getClassNameDedupe(property, priority, important, selector, parentSelector, atRule, importantNative = false) {
|
|
1534
1683
|
let hash = property;
|
|
1535
1684
|
hash += "\n" + (priority || "");
|
|
1536
1685
|
if (important) hash += "\nimportant";
|
|
1686
|
+
if (importantNative) hash += "\nnative-important";
|
|
1537
1687
|
hash += "\n" + (selector ? getSelectorHash(selector) : "");
|
|
1538
1688
|
hash += "\n" + (parentSelector ? getSelectorHash(parentSelector) : "");
|
|
1539
1689
|
hash += "\n" + (atRule ? atRule.map(getSelectorHash).join("\n") : "");
|
|
@@ -1613,8 +1763,8 @@ function mergeScopeData(scope, callsite, items, debug, parentSelector, scopeAtRu
|
|
|
1613
1763
|
value = scopeItem.value;
|
|
1614
1764
|
weight = scopeItem.weight;
|
|
1615
1765
|
important = scopeItem.important;
|
|
1616
|
-
dedupe = getClassNameDedupe(scopeItem.property, weight, important, scopeItem.selector, scopeItem.parentSelector, scopeItem.atRule);
|
|
1617
|
-
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);
|
|
1766
|
+
dedupe = getClassNameDedupe(scopeItem.property, weight, important, scopeItem.selector, scopeItem.parentSelector, scopeItem.atRule, scopeItem.importantNative);
|
|
1767
|
+
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);
|
|
1618
1768
|
scopeItem.dedupe = dedupe;
|
|
1619
1769
|
scopeItem.className = className;
|
|
1620
1770
|
scopeItem.callsite = itemCallsite;
|
|
@@ -1653,6 +1803,7 @@ function mergeScopeData(scope, callsite, items, debug, parentSelector, scopeAtRu
|
|
|
1653
1803
|
property: overrideItem.property,
|
|
1654
1804
|
weight: overrideItem.weight,
|
|
1655
1805
|
important: overrideItem.important,
|
|
1806
|
+
importantNative: overrideItem.importantNative,
|
|
1656
1807
|
value: overrideItem.value,
|
|
1657
1808
|
transformClassName: overrideItem.transformClassName,
|
|
1658
1809
|
token: overrideItem.token,
|
|
@@ -1666,8 +1817,8 @@ function mergeScopeData(scope, callsite, items, debug, parentSelector, scopeAtRu
|
|
|
1666
1817
|
value = scopeItem.value;
|
|
1667
1818
|
weight = scopeItem.weight;
|
|
1668
1819
|
important = scopeItem.important;
|
|
1669
|
-
dedupe = getClassNameDedupe(scopeItem.property, weight, important, scopeItem.selector, parentSelector, scopeItem.atRule);
|
|
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);
|
|
1820
|
+
dedupe = getClassNameDedupe(scopeItem.property, weight, important, scopeItem.selector, parentSelector, scopeItem.atRule, scopeItem.importantNative);
|
|
1821
|
+
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);
|
|
1671
1822
|
scopeItem.dedupe = dedupe;
|
|
1672
1823
|
scopeItem.className = className;
|
|
1673
1824
|
const lookupKey = getScopeLookupKey(slotId, dedupe);
|
|
@@ -1746,6 +1897,8 @@ function escapeCssValue(value) {
|
|
|
1746
1897
|
}
|
|
1747
1898
|
const formatTokenName = createNameFormatter(["name"]);
|
|
1748
1899
|
function getTokenVarName(token, format) {
|
|
1900
|
+
const explicitName = getStyleTokenVarName(token);
|
|
1901
|
+
if (explicitName) return explicitName;
|
|
1749
1902
|
const id = getStyleTokenId(token);
|
|
1750
1903
|
const debugName = getStyleTokenName(token);
|
|
1751
1904
|
return "--" + formatTokenName(format || "token[-(name)]-$hash", getIdentifierSafeHash(id, CSS_CONFIG.hashLength), { name: debugName });
|
|
@@ -1825,10 +1978,11 @@ function shouldAppendCssPx(property) {
|
|
|
1825
1978
|
//#endregion
|
|
1826
1979
|
//#region style/important.ts
|
|
1827
1980
|
const STYLE_IMPORTANT = symbol("style.important");
|
|
1828
|
-
function importantValue(value) {
|
|
1981
|
+
function importantValue(value, native = false) {
|
|
1829
1982
|
return {
|
|
1830
1983
|
[STYLE_IMPORTANT]: true,
|
|
1831
|
-
value
|
|
1984
|
+
value,
|
|
1985
|
+
native
|
|
1832
1986
|
};
|
|
1833
1987
|
}
|
|
1834
1988
|
function isStyleImportantValue(value) {
|
|
@@ -1885,6 +2039,7 @@ function mergeBuilderData(create, callsite, source, style, debug, selector, atRu
|
|
|
1885
2039
|
let value;
|
|
1886
2040
|
let weight;
|
|
1887
2041
|
let important;
|
|
2042
|
+
let importantNative;
|
|
1888
2043
|
let itemCallsite;
|
|
1889
2044
|
let className;
|
|
1890
2045
|
let dedupe;
|
|
@@ -1926,7 +2081,7 @@ function mergeBuilderData(create, callsite, source, style, debug, selector, atRu
|
|
|
1926
2081
|
}
|
|
1927
2082
|
} else for (const property in style) {
|
|
1928
2083
|
valueRaw = style[property];
|
|
1929
|
-
[valueRaw, weight, important] = unwrapAuthoredStyleValue(valueRaw);
|
|
2084
|
+
[valueRaw, weight, important, importantNative] = unwrapAuthoredStyleValue(valueRaw);
|
|
1930
2085
|
const sourceType = source[BUILDER_TYPE];
|
|
1931
2086
|
checkImportantUsage(valueRaw, important, sourceType === 9 || sourceType === 8);
|
|
1932
2087
|
transformClassName = null;
|
|
@@ -1949,6 +2104,7 @@ function mergeBuilderData(create, callsite, source, style, debug, selector, atRu
|
|
|
1949
2104
|
property,
|
|
1950
2105
|
weight,
|
|
1951
2106
|
important,
|
|
2107
|
+
importantNative,
|
|
1952
2108
|
value,
|
|
1953
2109
|
transformClassName,
|
|
1954
2110
|
variable: ref ? [3, ref] : variableName && token ? [
|
|
@@ -2011,8 +2167,8 @@ function mergeBuilderData(create, callsite, source, style, debug, selector, atRu
|
|
|
2011
2167
|
value = runtimeItem.value;
|
|
2012
2168
|
weight = runtimeItem.weight;
|
|
2013
2169
|
important = runtimeItem.important;
|
|
2014
|
-
dedupe = getClassNameDedupe(runtimeItem.property, weight, important, runtimeItem.selector, null, runtimeItem.atRule);
|
|
2015
|
-
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);
|
|
2170
|
+
dedupe = getClassNameDedupe(runtimeItem.property, weight, important, runtimeItem.selector, null, runtimeItem.atRule, runtimeItem.importantNative);
|
|
2171
|
+
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);
|
|
2016
2172
|
runtimeItem.dedupe = dedupe;
|
|
2017
2173
|
runtimeItem.className = className;
|
|
2018
2174
|
lookupIndex = lookup[dedupe];
|
|
@@ -2024,9 +2180,11 @@ function mergeBuilderData(create, callsite, source, style, debug, selector, atRu
|
|
|
2024
2180
|
function unwrapAuthoredStyleValue(value) {
|
|
2025
2181
|
let weight = null;
|
|
2026
2182
|
let important = false;
|
|
2183
|
+
let native = false;
|
|
2027
2184
|
while (true) {
|
|
2028
2185
|
if (isStyleImportantValue(value)) {
|
|
2029
2186
|
important = true;
|
|
2187
|
+
native ||= value.native === true;
|
|
2030
2188
|
value = value.value;
|
|
2031
2189
|
continue;
|
|
2032
2190
|
}
|
|
@@ -2040,7 +2198,8 @@ function unwrapAuthoredStyleValue(value) {
|
|
|
2040
2198
|
return [
|
|
2041
2199
|
value,
|
|
2042
2200
|
weight,
|
|
2043
|
-
important
|
|
2201
|
+
important,
|
|
2202
|
+
native
|
|
2044
2203
|
];
|
|
2045
2204
|
}
|
|
2046
2205
|
function checkImportantUsage(value, important, isSheet) {
|
|
@@ -2126,9 +2285,9 @@ function assertManualSelectorSyntax(selector) {
|
|
|
2126
2285
|
if (ampersandIndex === 0 && ampersandSelector && /^\s/.test(ampersandSelector)) throw new Error("selector cannot have whitespace after \"&\"; omit \"&\" for descendant selectors");
|
|
2127
2286
|
}
|
|
2128
2287
|
function setSheetSelectorOptions(selector, options) {
|
|
2129
|
-
if (options.
|
|
2288
|
+
if (options.specificity === void 0 && options.layer === void 0) return selector;
|
|
2130
2289
|
const text = Array.isArray(selector) ? selector[0] : selector;
|
|
2131
|
-
const weighted = SHEET_SELECTOR_ANCHOR + (":" + (options.
|
|
2290
|
+
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);
|
|
2132
2291
|
return Array.isArray(selector) ? [weighted, selector[1]] : weighted;
|
|
2133
2292
|
}
|
|
2134
2293
|
function normalizeManualSelector(selector, assertManualSelector) {
|
|
@@ -2140,6 +2299,13 @@ function normalizeManualSelector(selector, assertManualSelector) {
|
|
|
2140
2299
|
}
|
|
2141
2300
|
return [SHEET_SELECTOR_ANCHOR + (value.startsWith("&") ? value.slice(1) : " " + value)];
|
|
2142
2301
|
}
|
|
2302
|
+
/** Convert a normalized explicit selector into an unscoped sheet selector. */
|
|
2303
|
+
function setGlobalSheetSelectorOptions(selector, options) {
|
|
2304
|
+
const suffix = (Array.isArray(selector) ? selector[0] : selector).slice(6);
|
|
2305
|
+
if (!suffix.startsWith(" ") || !suffix.trim()) throw new Error("createGlobalSheet requires explicit selectors without an ampersand anchor");
|
|
2306
|
+
const global = GLOBAL_SHEET_SELECTOR_ANCHOR + JSON.stringify(options.layer ?? null) + "\0" + suffix.trimStart();
|
|
2307
|
+
return Array.isArray(selector) ? [global, selector[1]] : global;
|
|
2308
|
+
}
|
|
2143
2309
|
//#endregion
|
|
2144
2310
|
//#region builder/selector_override.ts
|
|
2145
2311
|
function normalizeManualSelectors(input) {
|
|
@@ -3165,63 +3331,19 @@ function buildFontPaletteValuesCss(format, name, id, descriptors, tokens, tokenL
|
|
|
3165
3331
|
};
|
|
3166
3332
|
}
|
|
3167
3333
|
createIdCounter("fontPaletteValues");
|
|
3168
|
-
|
|
3169
|
-
|
|
3170
|
-
const KEYFRAMES_AT_RULE = "keyframes";
|
|
3171
|
-
const formatKeyFramesName = createAtRuleNameFormatter("keyframes[-(name)]-$hash");
|
|
3172
|
-
function buildKeyframesCss(format, name, id, frames, tokens, tokenLookup, tokenNameFormat) {
|
|
3173
|
-
name = formatKeyFramesName(format, id, { name });
|
|
3174
|
-
let css = `@${KEYFRAMES_AT_RULE} ${name} {`;
|
|
3175
|
-
for (const selector in frames) {
|
|
3176
|
-
const frame = frames[selector];
|
|
3177
|
-
if (!frame) continue;
|
|
3178
|
-
css += selector + "{";
|
|
3179
|
-
css += buildAtRuleDeclarationCss(frame, tokens, tokenLookup, tokenNameFormat, false);
|
|
3180
|
-
css += "}";
|
|
3181
|
-
}
|
|
3182
|
-
css += "}";
|
|
3183
|
-
return {
|
|
3184
|
-
name,
|
|
3185
|
-
css
|
|
3186
|
-
};
|
|
3187
|
-
}
|
|
3188
|
-
//#endregion
|
|
3189
|
-
//#region css/keyframes.ts
|
|
3190
|
-
const idCounter$2 = createIdCounter("keyframes");
|
|
3191
|
-
function createKeyframes(frames, stableId) {
|
|
3192
|
-
return createNamedAtRuleRef({
|
|
3193
|
-
format: CSS_EXTRA_CONFIG.namedRuleFormat.keyframes,
|
|
3194
|
-
buildCss: buildKeyframesCss,
|
|
3195
|
-
value: frames,
|
|
3196
|
-
idCounter: idCounter$2,
|
|
3197
|
-
stableId
|
|
3198
|
-
});
|
|
3199
|
-
}
|
|
3200
|
-
//#endregion
|
|
3201
|
-
//#region atomic/atRule/positionTry.ts
|
|
3202
|
-
const POSITION_TRY_AT_RULE = "position-try";
|
|
3203
|
-
const formatPositionTryName = createAtRuleNameFormatter("position-try[-(name)]-$hash", "--");
|
|
3204
|
-
function buildPositionTryCss(format, name, id, descriptors, tokens, tokenLookup, tokenNameFormat) {
|
|
3205
|
-
name = formatPositionTryName(format, id, { name });
|
|
3206
|
-
const css = buildNamedAtRuleCss(POSITION_TRY_AT_RULE, name, descriptors, tokens, tokenLookup, tokenNameFormat);
|
|
3207
|
-
return {
|
|
3208
|
-
name,
|
|
3209
|
-
css
|
|
3210
|
-
};
|
|
3334
|
+
function appendStyleTag(document, tag) {
|
|
3335
|
+
(document.head || document.getElementsByTagName("head")[0] || document.documentElement).appendChild(tag);
|
|
3211
3336
|
}
|
|
3212
|
-
|
|
3213
|
-
|
|
3214
|
-
|
|
3215
|
-
const
|
|
3216
|
-
|
|
3217
|
-
|
|
3218
|
-
|
|
3219
|
-
return
|
|
3220
|
-
css: buildNamedAtRuleCss(PROPERTY_AT_RULE, name, descriptors, tokens, tokenLookup, tokenNameFormat),
|
|
3221
|
-
name
|
|
3222
|
-
};
|
|
3337
|
+
function getFirstCssSheetTag(head) {
|
|
3338
|
+
const nodes = head.childNodes;
|
|
3339
|
+
for (let i = 0, len = nodes.length; i < len; i++) {
|
|
3340
|
+
const node = nodes[i];
|
|
3341
|
+
if (typeof node.getAttribute !== "function") continue;
|
|
3342
|
+
if (node.getAttribute("data-css-sheet")) return node;
|
|
3343
|
+
}
|
|
3344
|
+
return null;
|
|
3223
3345
|
}
|
|
3224
|
-
|
|
3346
|
+
globalData("sheet.ordered.refreshers", () => /* @__PURE__ */ new Set());
|
|
3225
3347
|
//#endregion
|
|
3226
3348
|
//#region sheet/utils/sourcemap.ts
|
|
3227
3349
|
const VLQ_BASE_SHIFT = 5;
|
|
@@ -3230,6 +3352,45 @@ const VLQ_BASE_MASK = VLQ_BASE - 1;
|
|
|
3230
3352
|
const VLQ_CONTINUATION_BIT = VLQ_BASE;
|
|
3231
3353
|
const BASE64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
3232
3354
|
const SOURCE_URL_PREFIX = "source://";
|
|
3355
|
+
function createSourceMapComment$1(rules) {
|
|
3356
|
+
const sources = [];
|
|
3357
|
+
const sourceLookup = Object.create(null);
|
|
3358
|
+
let generatedLine = 0;
|
|
3359
|
+
let previousSource = 0;
|
|
3360
|
+
let previousOriginalLine = 0;
|
|
3361
|
+
let previousOriginalColumn = 0;
|
|
3362
|
+
const mappingLines = [];
|
|
3363
|
+
for (let i = 0, len = rules.length; i < len; i++) {
|
|
3364
|
+
const rule = rules[i];
|
|
3365
|
+
const sourceData = rule.source;
|
|
3366
|
+
let mapping = "";
|
|
3367
|
+
if (sourceData) {
|
|
3368
|
+
const source = getSource(sources, sourceLookup, getSourceMapSourceUrl(sourceData), sourceData.sourceContent);
|
|
3369
|
+
const originalLine = Math.max(sourceData.line - 1, 0);
|
|
3370
|
+
const originalColumn = Math.max(sourceData.column - 1, 0);
|
|
3371
|
+
mapping += encodeVlq(0);
|
|
3372
|
+
mapping += encodeVlq(source.sourceIndex - previousSource);
|
|
3373
|
+
mapping += encodeVlq(originalLine - previousOriginalLine);
|
|
3374
|
+
mapping += encodeVlq(originalColumn - previousOriginalColumn);
|
|
3375
|
+
previousSource = source.sourceIndex;
|
|
3376
|
+
previousOriginalLine = originalLine;
|
|
3377
|
+
previousOriginalColumn = originalColumn;
|
|
3378
|
+
}
|
|
3379
|
+
mappingLines[generatedLine] = mapping;
|
|
3380
|
+
const lineCount = getLineCount(rule.css);
|
|
3381
|
+
for (let j = 1; j < lineCount; j++) mappingLines[generatedLine + j] = "";
|
|
3382
|
+
generatedLine += lineCount;
|
|
3383
|
+
}
|
|
3384
|
+
if (!sources.length) return "";
|
|
3385
|
+
const data = {
|
|
3386
|
+
version: 3,
|
|
3387
|
+
sources: sources.map((source) => source.filePath),
|
|
3388
|
+
sourcesContent: sources.some((source) => source.sourceContent !== void 0) ? sources.map((source) => source.sourceContent ?? null) : void 0,
|
|
3389
|
+
names: [],
|
|
3390
|
+
mappings: mappingLines.join(";")
|
|
3391
|
+
};
|
|
3392
|
+
return "/*# sourceMappingURL=data:application/json;charset=utf-8;base64," + encodeBase64(JSON.stringify(data)) + " */";
|
|
3393
|
+
}
|
|
3233
3394
|
function encodeBase64(text) {
|
|
3234
3395
|
const bytes = new TextEncoder().encode(text);
|
|
3235
3396
|
let binary = "";
|
|
@@ -3330,8 +3491,21 @@ function normalizeRuleCallsite(callsite) {
|
|
|
3330
3491
|
sourceUrl: callsite.sourceUrl ? normalizeCallsiteSourceUrl(callsite.sourceUrl) : callsite.sourceUrl
|
|
3331
3492
|
};
|
|
3332
3493
|
}
|
|
3494
|
+
function getSourcemapRuleCallsite(rule) {
|
|
3495
|
+
return getRuleCallsite(rule.callsite, rule.debug, rule.debugField);
|
|
3496
|
+
}
|
|
3333
3497
|
globalData("sheet.dev.sourcemapTags", () => []);
|
|
3334
3498
|
globalData("sheet.dev.sheets", () => /* @__PURE__ */ new Set());
|
|
3499
|
+
//#endregion
|
|
3500
|
+
//#region runtime/sheet/document.ts
|
|
3501
|
+
const GLOBAL_KEY = "runtime.sheet.global";
|
|
3502
|
+
const state$1 = globalData("runtime.sheet.document", () => ({ document: getRuntimeDocument() }));
|
|
3503
|
+
function resetSheet() {
|
|
3504
|
+
getGlobalData(GLOBAL_KEY)?.destroy?.();
|
|
3505
|
+
clearGlobalData(GLOBAL_KEY);
|
|
3506
|
+
state$1.document = getRuntimeDocument();
|
|
3507
|
+
}
|
|
3508
|
+
onRuntimeDocumentChange(resetSheet);
|
|
3335
3509
|
globalData("runtime.combinedStyle.targets", () => /* @__PURE__ */ new WeakMap());
|
|
3336
3510
|
//#endregion
|
|
3337
3511
|
//#region runtime/core/cache/resolvedItem.ts
|
|
@@ -3629,10 +3803,10 @@ function buildAtomicRule(className, property, value, important, selector, parent
|
|
|
3629
3803
|
const cssProp = getCssPropertyName(property);
|
|
3630
3804
|
const cssValue = getCssPropertyValue(property, value) + (important ? " !important" : "");
|
|
3631
3805
|
const escapedClass = escapeCssIdent(className);
|
|
3632
|
-
const
|
|
3633
|
-
const classSelector =
|
|
3806
|
+
const specificity = hasSheetSelectorAnchor(selector) ? getSheetSelectorSpecificity(selector) ?? 1 : 1;
|
|
3807
|
+
const classSelector = specificity === 0 ? `:where(.${escapedClass})` : Array(specificity).fill("." + escapedClass).join("");
|
|
3634
3808
|
const itemSelector = selector ? getSelectorText$1(selector) : "";
|
|
3635
|
-
let selectorStr = classSelector + itemSelector;
|
|
3809
|
+
let selectorStr = hasGlobalSheetSelectorAnchor(selector) ? itemSelector : classSelector + itemSelector;
|
|
3636
3810
|
if (parentSelector) {
|
|
3637
3811
|
const parentWhere = `:where(${"." + escapeCssIdent(getScopeClassName(className, scopeClassNameFormat)) + getSelectorText$1(parentSelector)})`;
|
|
3638
3812
|
selectorStr = classSelector + parentWhere + itemSelector + "," + parentWhere + " " + selectorStr;
|
|
@@ -3712,8 +3886,71 @@ function stripGenericThemePrefix(value) {
|
|
|
3712
3886
|
function isGeneratedNameHash(value) {
|
|
3713
3887
|
return /^[a-z0-9]{7}$/.test(value) && /\d/.test(value);
|
|
3714
3888
|
}
|
|
3889
|
+
//#endregion
|
|
3890
|
+
//#region atomic/atRule/keyframes.ts
|
|
3891
|
+
const KEYFRAMES_AT_RULE = "keyframes";
|
|
3892
|
+
const formatKeyFramesName = createAtRuleNameFormatter("keyframes[-(name)]-$hash");
|
|
3893
|
+
function buildKeyframesCss(format, name, id, frames, tokens, tokenLookup, tokenNameFormat) {
|
|
3894
|
+
name = formatKeyFramesName(format, id, { name });
|
|
3895
|
+
let css = `@${KEYFRAMES_AT_RULE} ${name} {`;
|
|
3896
|
+
for (const selector in frames) {
|
|
3897
|
+
const frame = frames[selector];
|
|
3898
|
+
if (!frame) continue;
|
|
3899
|
+
css += selector + "{";
|
|
3900
|
+
css += buildAtRuleDeclarationCss(frame, tokens, tokenLookup, tokenNameFormat, false);
|
|
3901
|
+
css += "}";
|
|
3902
|
+
}
|
|
3903
|
+
css += "}";
|
|
3904
|
+
return {
|
|
3905
|
+
name,
|
|
3906
|
+
css
|
|
3907
|
+
};
|
|
3908
|
+
}
|
|
3909
|
+
//#endregion
|
|
3910
|
+
//#region css/keyframes.ts
|
|
3911
|
+
const idCounter$2 = createIdCounter("keyframes");
|
|
3912
|
+
function createKeyframes(frames, stableId) {
|
|
3913
|
+
return createNamedAtRuleRef({
|
|
3914
|
+
format: CSS_EXTRA_CONFIG.namedRuleFormat.keyframes,
|
|
3915
|
+
buildCss: buildKeyframesCss,
|
|
3916
|
+
value: frames,
|
|
3917
|
+
idCounter: idCounter$2,
|
|
3918
|
+
stableId
|
|
3919
|
+
});
|
|
3920
|
+
}
|
|
3921
|
+
//#endregion
|
|
3922
|
+
//#region atomic/atRule/positionTry.ts
|
|
3923
|
+
const POSITION_TRY_AT_RULE = "position-try";
|
|
3924
|
+
const formatPositionTryName = createAtRuleNameFormatter("position-try[-(name)]-$hash", "--");
|
|
3925
|
+
function buildPositionTryCss(format, name, id, descriptors, tokens, tokenLookup, tokenNameFormat) {
|
|
3926
|
+
name = formatPositionTryName(format, id, { name });
|
|
3927
|
+
const css = buildNamedAtRuleCss(POSITION_TRY_AT_RULE, name, descriptors, tokens, tokenLookup, tokenNameFormat);
|
|
3928
|
+
return {
|
|
3929
|
+
name,
|
|
3930
|
+
css
|
|
3931
|
+
};
|
|
3932
|
+
}
|
|
3933
|
+
createIdCounter("positionTry");
|
|
3934
|
+
//#endregion
|
|
3935
|
+
//#region atomic/atRule/property.ts
|
|
3936
|
+
const PROPERTY_AT_RULE = "property";
|
|
3937
|
+
const formatPropertyName = createAtRuleNameFormatter("[-(name)]-$hash", "--");
|
|
3938
|
+
function buildPropertyCss(format, name, id, descriptors, tokens, tokenLookup, tokenNameFormat) {
|
|
3939
|
+
name = formatPropertyName(format, id, { name });
|
|
3940
|
+
return {
|
|
3941
|
+
css: buildNamedAtRuleCss(PROPERTY_AT_RULE, name, descriptors, tokens, tokenLookup, tokenNameFormat),
|
|
3942
|
+
name
|
|
3943
|
+
};
|
|
3944
|
+
}
|
|
3945
|
+
createIdCounter("property");
|
|
3715
3946
|
createNameFormatter(["name"]);
|
|
3716
|
-
|
|
3947
|
+
//#endregion
|
|
3948
|
+
//#region runtime/core/elementMarker.ts
|
|
3949
|
+
const ELEMENT_MARKER_SHEET = globalData("runtime.elementMarkerSheet", () => ({ sheet: null }));
|
|
3950
|
+
onRuntimeDocumentChange(() => {
|
|
3951
|
+
ELEMENT_MARKER_SHEET.sheet?.sheet.destroy?.();
|
|
3952
|
+
ELEMENT_MARKER_SHEET.sheet = null;
|
|
3953
|
+
});
|
|
3717
3954
|
//#endregion
|
|
3718
3955
|
//#region style/keyframes.ts
|
|
3719
3956
|
function transformKeyframes(frames, transform) {
|
|
@@ -3745,7 +3982,7 @@ function createStyleFn(args) {
|
|
|
3745
3982
|
const fnWeight = (value, weight) => {
|
|
3746
3983
|
return weightValue(value, weight);
|
|
3747
3984
|
};
|
|
3748
|
-
const fnImportant = (value) => importantValue(value);
|
|
3985
|
+
const fnImportant = (value, native) => importantValue(value, native);
|
|
3749
3986
|
const fnRaw = (style) => style;
|
|
3750
3987
|
const fnPlain = (style) => style;
|
|
3751
3988
|
const fnKeyframes = ((frames, stableId) => createStyleKeyframes(frames, transform ?? null, stableId));
|
|
@@ -3996,8 +4233,9 @@ function appendExtractedStyleTuples(target, source) {
|
|
|
3996
4233
|
//#region dialect/namedTokens.ts
|
|
3997
4234
|
const ROOT = Symbol("fluentic.namedTokens.root");
|
|
3998
4235
|
function createNamedToken(id, value) {
|
|
3999
|
-
const
|
|
4000
|
-
token
|
|
4236
|
+
const tokenId = createNamedTokenId(id);
|
|
4237
|
+
const token = createStyleToken(value, tokenId);
|
|
4238
|
+
token[TOKEN_VAR_NAME] = "--token-" + tokenId;
|
|
4001
4239
|
return token;
|
|
4002
4240
|
}
|
|
4003
4241
|
function createNamedTokens(namespace, values) {
|
|
@@ -4009,7 +4247,10 @@ function createNamedTokens(namespace, values) {
|
|
|
4009
4247
|
}, []);
|
|
4010
4248
|
}
|
|
4011
4249
|
function createNamedTokenId(id) {
|
|
4012
|
-
return
|
|
4250
|
+
return id.split(".").map(encodeNamedTokenSegment).join("-");
|
|
4251
|
+
}
|
|
4252
|
+
function encodeNamedTokenSegment(segment) {
|
|
4253
|
+
return segment.replace(/[^a-zA-Z0-9]/gu, (char) => "_x" + char.codePointAt(0).toString(16) + "_");
|
|
4013
4254
|
}
|
|
4014
4255
|
function createNamedTokenProxy(root, path) {
|
|
4015
4256
|
return new Proxy(noop, {
|
|
@@ -4031,11 +4272,13 @@ function createNamedTokenProxy(root, path) {
|
|
|
4031
4272
|
});
|
|
4032
4273
|
}
|
|
4033
4274
|
function getNamedTokenAtPath(root, path) {
|
|
4034
|
-
const key =
|
|
4275
|
+
const key = JSON.stringify(path);
|
|
4035
4276
|
const cached = root.cache.get(key);
|
|
4036
4277
|
if (cached) return cached;
|
|
4037
4278
|
const value = getValueAtPath(root.values, path);
|
|
4038
|
-
const
|
|
4279
|
+
const id = root.namespace.split(".").concat(path).map(encodeNamedTokenSegment).join("-");
|
|
4280
|
+
const token = createStyleToken(value, id);
|
|
4281
|
+
token[TOKEN_VAR_NAME] = "--token-" + id;
|
|
4039
4282
|
root.cache.set(key, token);
|
|
4040
4283
|
return token;
|
|
4041
4284
|
}
|
|
@@ -4072,6 +4315,7 @@ function exposeStyleValue(value) {
|
|
|
4072
4315
|
//#region compiler/transform/evaluator/evaluator.ts
|
|
4073
4316
|
const STYLE_IMPORT_PATHS = new Set(IMPORT_PATHS);
|
|
4074
4317
|
const COMPILED_RUNTIME_VALUE = Symbol();
|
|
4318
|
+
const COMPILED_TOKEN_REFERENCE = Symbol();
|
|
4075
4319
|
const COMPILED_STYLE_OBJECT_LOCATIONS = Symbol();
|
|
4076
4320
|
const COMPILED_TOKEN_FACTORY = Symbol();
|
|
4077
4321
|
function evalOk(value) {
|
|
@@ -4094,11 +4338,11 @@ function evaluateNode(node, scope) {
|
|
|
4094
4338
|
case "BooleanLiteral": return evalOk(node.value);
|
|
4095
4339
|
case "NullLiteral": return evalOk(null);
|
|
4096
4340
|
case "TemplateLiteral": return evaluateTemplate(node, scope);
|
|
4097
|
-
case "Identifier": return evaluateIdentifier(node, scope);
|
|
4098
|
-
case "MemberExpression": return evaluateMember(node, scope);
|
|
4341
|
+
case "Identifier": return referenceResult(evaluateIdentifier(node, scope), node, scope);
|
|
4342
|
+
case "MemberExpression": return referenceResult(evaluateMember(node, scope), node, scope);
|
|
4099
4343
|
case "ObjectExpression": return evaluateObject(node, scope);
|
|
4100
4344
|
case "ArrayExpression": return evaluateArray(node, scope);
|
|
4101
|
-
case "CallExpression": return evaluateCall(node, scope);
|
|
4345
|
+
case "CallExpression": return referenceCallResult(evaluateCall(node, scope), node, scope);
|
|
4102
4346
|
case "BinaryExpression": return evaluateBinary(node, scope);
|
|
4103
4347
|
case "UnaryExpression": return evaluateUnary(node, scope);
|
|
4104
4348
|
case "ParenthesizedExpression":
|
|
@@ -4422,7 +4666,7 @@ function evaluateCall(node, scope) {
|
|
|
4422
4666
|
if (imp && STYLE_IMPORT_PATHS.has(imp.source) && imp.name === "getToken") {
|
|
4423
4667
|
const value = evaluateNode(node.arguments[0], scope);
|
|
4424
4668
|
if (!value.ok) return value;
|
|
4425
|
-
if (isStyleTokenData(value.value)) return evalOk(getTokenVar(value.value, CSS_CONFIG.tokenNameFormat || null));
|
|
4669
|
+
if (isStyleTokenData(value.value)) return evalOk(getTokenVar(value.value, scope.tokenNameFormat === void 0 ? CSS_CONFIG.tokenNameFormat || null : scope.tokenNameFormat));
|
|
4426
4670
|
return evalOk(value.value);
|
|
4427
4671
|
}
|
|
4428
4672
|
if (imp && imp.source === "@fluentic/style/utils" && imp.name === "exposeStyle") {
|
|
@@ -4460,7 +4704,7 @@ function evaluateCall(node, scope) {
|
|
|
4460
4704
|
if (!provide.ok) return provide;
|
|
4461
4705
|
return evalOk(createCompiledTokenOverride(target, provide.value, node));
|
|
4462
4706
|
}
|
|
4463
|
-
return evalOk(withRuntimeValue(node, target));
|
|
4707
|
+
return referenceResult(evalOk(withRuntimeValue(node, target)), node, scope);
|
|
4464
4708
|
}
|
|
4465
4709
|
}
|
|
4466
4710
|
if (node.callee.type === "MemberExpression") {
|
|
@@ -4478,7 +4722,7 @@ function evaluateCall(node, scope) {
|
|
|
4478
4722
|
if (!stableId.ok) return stableId;
|
|
4479
4723
|
const stable = stableId.value ?? createCompiledAtRuleStableId(scope, node.loc?.start, frames.value);
|
|
4480
4724
|
const meta = scope.styleMetas?.get(node.callee.object.name);
|
|
4481
|
-
const transformedFrames = transformKeyframes(frames.value, meta?.transform ?? scope.styleTransform ?? null);
|
|
4725
|
+
const transformedFrames = transformKeyframes(frames.value, (meta?.mode === "StyleObject" ? meta.transform : null) ?? scope.styleTransform ?? null);
|
|
4482
4726
|
const format = CSS_EXTRA_CONFIG.namedRuleFormat.keyframes ?? null;
|
|
4483
4727
|
return evalOk(createCompiledAtRuleRef({
|
|
4484
4728
|
value: formatKeyFramesName(format, stable.id, { name: stable.name }),
|
|
@@ -4496,7 +4740,10 @@ function evaluateCall(node, scope) {
|
|
|
4496
4740
|
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)) {
|
|
4497
4741
|
const value = evaluateNode(node.arguments[0], scope);
|
|
4498
4742
|
if (!value.ok) return value;
|
|
4499
|
-
|
|
4743
|
+
const native = node.arguments[1] ? evaluateNode(node.arguments[1], scope) : evalOk(false);
|
|
4744
|
+
if (!native.ok) return native;
|
|
4745
|
+
if (typeof native.value !== "boolean") return evalFail("style.important second argument must be a boolean");
|
|
4746
|
+
return evalOk(importantValue(value.value, native.value));
|
|
4500
4747
|
}
|
|
4501
4748
|
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);
|
|
4502
4749
|
return evalFail(`Cannot statically evaluate: ${node.type}`);
|
|
@@ -4534,6 +4781,7 @@ function createCompiledTokenOverride(token, value, runtimeValue) {
|
|
|
4534
4781
|
[TOKEN_ID]: getStyleTokenId(token),
|
|
4535
4782
|
[TOKEN_OVERRIDE]: true,
|
|
4536
4783
|
[TOKEN_NAME]: getStyleTokenName(token),
|
|
4784
|
+
[TOKEN_VAR_NAME]: token[TOKEN_VAR_NAME] ?? null,
|
|
4537
4785
|
value: value.value,
|
|
4538
4786
|
ref: value
|
|
4539
4787
|
});
|
|
@@ -4541,6 +4789,7 @@ function createCompiledTokenOverride(token, value, runtimeValue) {
|
|
|
4541
4789
|
[TOKEN_ID]: getStyleTokenId(token),
|
|
4542
4790
|
[TOKEN_OVERRIDE]: true,
|
|
4543
4791
|
[TOKEN_NAME]: getStyleTokenName(token),
|
|
4792
|
+
[TOKEN_VAR_NAME]: token[TOKEN_VAR_NAME] ?? null,
|
|
4544
4793
|
value,
|
|
4545
4794
|
ref: null
|
|
4546
4795
|
});
|
|
@@ -4599,6 +4848,7 @@ function assignCompiledTokenRecord(target, value, scope, loc, runtimeValue, stab
|
|
|
4599
4848
|
}
|
|
4600
4849
|
}
|
|
4601
4850
|
function createCompiledValues(values, scope, loc, runtimeValue, stableId, isNumber) {
|
|
4851
|
+
if (!values.length) throw new Error("[Style.values] NO_VALUES");
|
|
4602
4852
|
const tokens = /* @__PURE__ */ new Map();
|
|
4603
4853
|
const groupName = getStyleTokenNameFromId(stableId);
|
|
4604
4854
|
for (let i = 0, len = values.length; i < len; i++) {
|
|
@@ -4615,7 +4865,7 @@ function parseCompiledValue(value, isNumber) {
|
|
|
4615
4865
|
value = String(value).split(/[;|]/)[0].trim();
|
|
4616
4866
|
if (!isNumber) return value;
|
|
4617
4867
|
const number = Number(value);
|
|
4618
|
-
if (!Number.isFinite(number))
|
|
4868
|
+
if (!Number.isFinite(number)) throw new Error(`[Style.values] INVALID_NUMBER_VALUE: ${String(value)}`);
|
|
4619
4869
|
return number;
|
|
4620
4870
|
}
|
|
4621
4871
|
function isCompiledTokenFactory(value) {
|
|
@@ -4663,9 +4913,14 @@ function sanitizeTokenDebugName(value) {
|
|
|
4663
4913
|
return value.replace(/[^a-zA-Z0-9_-]+/g, "-").replace(/^-+|-+$/g, "") || null;
|
|
4664
4914
|
}
|
|
4665
4915
|
function withRuntimeValue(runtimeValue, token) {
|
|
4916
|
+
if (typeof token === "function") return new Proxy(token, { get(target, key) {
|
|
4917
|
+
if (key === COMPILED_RUNTIME_VALUE) return runtimeValue;
|
|
4918
|
+
return Reflect.get(target, key);
|
|
4919
|
+
} });
|
|
4666
4920
|
return Object.assign({}, token, {
|
|
4667
4921
|
[TOKEN_ID]: token[TOKEN_ID],
|
|
4668
4922
|
[TOKEN_NAME]: token[TOKEN_NAME] ?? null,
|
|
4923
|
+
[TOKEN_VAR_NAME]: token[TOKEN_VAR_NAME] ?? null,
|
|
4669
4924
|
[COMPILED_RUNTIME_VALUE]: runtimeValue
|
|
4670
4925
|
});
|
|
4671
4926
|
}
|
|
@@ -4696,6 +4951,34 @@ function evaluateUnary(node, scope) {
|
|
|
4696
4951
|
default: return evalFail(`Unsupported unary operator: ${node.operator}`);
|
|
4697
4952
|
}
|
|
4698
4953
|
}
|
|
4954
|
+
function referenceResult(result, expression, scope) {
|
|
4955
|
+
if (!result.ok) return result;
|
|
4956
|
+
return evalOk(referenceValue(result.value, expression, scope));
|
|
4957
|
+
}
|
|
4958
|
+
function referenceValue(value, expression, scope, nested = false) {
|
|
4959
|
+
if (isStyleTokenData(value) || isStyleTokenOverrideData(value)) {
|
|
4960
|
+
if (nested && value[COMPILED_TOKEN_REFERENCE]?.filePath === scope.filePath) return value;
|
|
4961
|
+
const reference = {
|
|
4962
|
+
expression,
|
|
4963
|
+
filePath: scope.filePath
|
|
4964
|
+
};
|
|
4965
|
+
if (typeof value === "function") return new Proxy(value, { get(target, key) {
|
|
4966
|
+
if (key === COMPILED_TOKEN_REFERENCE) return reference;
|
|
4967
|
+
return Reflect.get(target, key);
|
|
4968
|
+
} });
|
|
4969
|
+
return Object.assign(withRuntimeValue(value[COMPILED_RUNTIME_VALUE] ?? expression, value), { [COMPILED_TOKEN_REFERENCE]: reference });
|
|
4970
|
+
}
|
|
4971
|
+
if (!value || typeof value !== "object" || isCompiledTokenFactory(value)) return value;
|
|
4972
|
+
if (Object.getOwnPropertySymbols(value).some((key) => key !== COMPILED_STYLE_OBJECT_LOCATIONS)) return value;
|
|
4973
|
+
const result = Object.defineProperties(Array.isArray(value) ? [] : {}, Object.getOwnPropertyDescriptors(value));
|
|
4974
|
+
for (const key of Object.keys(value)) result[key] = referenceValue(value[key], _babel_core.types.memberExpression(expression, _babel_core.types.stringLiteral(key), true), scope, true);
|
|
4975
|
+
return result;
|
|
4976
|
+
}
|
|
4977
|
+
function referenceCallResult(result, node, scope) {
|
|
4978
|
+
const imp = node.callee.type === "Identifier" ? scope.imports.get(node.callee.name) : void 0;
|
|
4979
|
+
if (imp && STYLE_IMPORT_PATHS.has(imp.source)) return result;
|
|
4980
|
+
return result.ok && (isStyleTokenData(result.value) || isStyleTokenOverrideData(result.value)) ? referenceResult(result, node, scope) : result;
|
|
4981
|
+
}
|
|
4699
4982
|
//#endregion
|
|
4700
4983
|
//#region compiler/transform/syntax/isStaticStyleValue.ts
|
|
4701
4984
|
function isStaticStyleValue(value) {
|
|
@@ -5162,6 +5445,15 @@ function createDebugPlugin(args) {
|
|
|
5162
5445
|
});
|
|
5163
5446
|
},
|
|
5164
5447
|
CallExpression(path, state) {
|
|
5448
|
+
if (path.node.callee.type === "Identifier") {
|
|
5449
|
+
const imported = state.imports.get(path.node.callee.name);
|
|
5450
|
+
if (imported?.source === "@fluentic/style/css" && imported.name === "createGlobalSheet" && !hasDebugArgument(path.node.arguments)) {
|
|
5451
|
+
const debug = buildDebugDataObject(t, path.node, state.fileId, getSourceUrlId(t, state), sourceContent ? getSourceContentId(t, state) : null);
|
|
5452
|
+
if (!path.getFunctionParent()) debug.properties.push(t.objectProperty(t.identifier("globalModule"), t.stringLiteral(state.filePath)));
|
|
5453
|
+
if (!path.node.arguments.length) path.node.arguments.push(t.arrayExpression([]));
|
|
5454
|
+
path.node.arguments.push(debug);
|
|
5455
|
+
}
|
|
5456
|
+
}
|
|
5165
5457
|
annotateThemeCall(path.node, state, t);
|
|
5166
5458
|
annotateThemeCallsite(t, path, state, sourceContent);
|
|
5167
5459
|
if (!state.styleNames.size) return;
|
|
@@ -6067,12 +6359,23 @@ function compileSheetChain(chain, fileId, scope, cssConfig, options) {
|
|
|
6067
6359
|
const items = [];
|
|
6068
6360
|
const rules = [];
|
|
6069
6361
|
const hasOptions = chain.baseArgs.length === 2;
|
|
6070
|
-
const sheetOptions = hasOptions ? evaluateCreateSheetOptions(chain.baseArgs[0], scope) : {};
|
|
6362
|
+
const sheetOptions = hasOptions ? evaluateCreateSheetOptions(chain.baseArgs[0], scope, chain.global) : {};
|
|
6071
6363
|
if (!sheetOptions) return null;
|
|
6364
|
+
if (chain.global) {
|
|
6365
|
+
if (sheetOptions.specificity !== void 0) throw new Error("createGlobalSheet does not support specificity");
|
|
6366
|
+
sheetOptions.global = true;
|
|
6367
|
+
}
|
|
6072
6368
|
const sheetItems = chain.baseArgs[hasOptions ? 1 : 0];
|
|
6073
6369
|
if (sheetItems && !compileSheetItemsArg(sheetItems, fileId, scope, cssConfig, options, items, rules, sheetOptions)) return null;
|
|
6074
|
-
const sheetLayer = sheetOptions.layer ??
|
|
6075
|
-
for (let i = 0, len = rules.length; i < len; i++)
|
|
6370
|
+
const sheetLayer = sheetOptions.layer ?? false;
|
|
6371
|
+
for (let i = 0, len = rules.length; i < len; i++) {
|
|
6372
|
+
rules[i].layer = resolveSheetLayerOption(sheetLayer, options.css?.layerNamespace ?? DEFAULT_CONFIG.layerNamespace ?? "", isStyleLayerEnabled(options.css?.layer ?? DEFAULT_CONFIG.layer));
|
|
6373
|
+
rules[i].sheet = true;
|
|
6374
|
+
if (chain.global) rules[i].globalSheet = {
|
|
6375
|
+
id: chain.sheetId ?? fileId,
|
|
6376
|
+
order: sheetOptions.order ?? 0
|
|
6377
|
+
};
|
|
6378
|
+
}
|
|
6076
6379
|
return {
|
|
6077
6380
|
type: "sheet",
|
|
6078
6381
|
items,
|
|
@@ -6080,17 +6383,17 @@ function compileSheetChain(chain, fileId, scope, cssConfig, options) {
|
|
|
6080
6383
|
sheetOptions
|
|
6081
6384
|
};
|
|
6082
6385
|
}
|
|
6083
|
-
function evaluateCreateSheetOptions(node, scope) {
|
|
6386
|
+
function evaluateCreateSheetOptions(node, scope, global = false) {
|
|
6084
6387
|
const result = evaluateNode(node, scope);
|
|
6085
6388
|
if (!result.ok || !result.value || typeof result.value !== "object" || Array.isArray(result.value)) return null;
|
|
6086
6389
|
const value = result.value;
|
|
6087
|
-
if (
|
|
6088
|
-
|
|
6089
|
-
if (value.
|
|
6090
|
-
|
|
6091
|
-
|
|
6092
|
-
|
|
6093
|
-
|
|
6390
|
+
if (hasGlobalRuntimeValue(value)) return null;
|
|
6391
|
+
const allowed = global ? ["layer", "order"] : ["layer", "specificity"];
|
|
6392
|
+
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");
|
|
6393
|
+
if (!isSheetLayerOption(value.layer)) throw new Error("invalid sheet layer");
|
|
6394
|
+
if (value.specificity !== void 0 && (!Number.isInteger(value.specificity) || value.specificity < 0)) throw new Error("specificity must be a non-negative integer");
|
|
6395
|
+
if (value.order !== void 0 && (typeof value.order !== "number" || !Number.isFinite(value.order))) throw new Error("order must be a finite number");
|
|
6396
|
+
return value;
|
|
6094
6397
|
}
|
|
6095
6398
|
function compileSheetItemsArg(node, fileId, scope, cssConfig, options, items, rules, sheetOptions) {
|
|
6096
6399
|
if (node.type === "ArrayExpression") {
|
|
@@ -6102,7 +6405,9 @@ function compileSheetItemsArg(node, fileId, scope, cssConfig, options, items, ru
|
|
|
6102
6405
|
return true;
|
|
6103
6406
|
}
|
|
6104
6407
|
const tokenOverride = evaluateNode(node, scope);
|
|
6408
|
+
if (tokenOverride.ok && !tokenOverride.value) return true;
|
|
6105
6409
|
if (tokenOverride.ok && isStyleTokenOverrideData(tokenOverride.value)) {
|
|
6410
|
+
if (sheetOptions.global) throw new Error("createGlobalSheet requires token overrides inside an explicit selector");
|
|
6106
6411
|
addCompiledTokenItem(getStyleTokenId(tokenOverride.value), tokenOverride.value, getCompiledRuntimeValue(tokenOverride.value) ?? node, items);
|
|
6107
6412
|
return true;
|
|
6108
6413
|
}
|
|
@@ -6111,6 +6416,7 @@ function compileSheetItemsArg(node, fileId, scope, cssConfig, options, items, ru
|
|
|
6111
6416
|
const item = tokenOverride.value[i];
|
|
6112
6417
|
if (!item) continue;
|
|
6113
6418
|
if (!isStyleTokenOverrideData(item)) return false;
|
|
6419
|
+
if (sheetOptions.global) throw new Error("createGlobalSheet requires token overrides inside an explicit selector");
|
|
6114
6420
|
addCompiledTokenItem(getStyleTokenId(item), item, getCompiledRuntimeValue(item) ?? null, items);
|
|
6115
6421
|
}
|
|
6116
6422
|
return true;
|
|
@@ -6124,10 +6430,16 @@ function compileSheetItemsArg(node, fileId, scope, cssConfig, options, items, ru
|
|
|
6124
6430
|
}
|
|
6125
6431
|
function compileSelectorOverrideChain(chain, selectors, fileId, scope, cssConfig, transform, styleNames, options, items, rules, sheetOptions) {
|
|
6126
6432
|
if (chain.baseArgs.length === 0 || chain.baseArgs.length > 2) return false;
|
|
6433
|
+
if (sheetOptions.global) {
|
|
6434
|
+
if ([...chain.baseArgs, ...chain.methods.flatMap((method) => method.args)].some((arg) => {
|
|
6435
|
+
const result = evaluateNode(arg, scope);
|
|
6436
|
+
return !result.ok || hasGlobalRuntimeValue(result.value);
|
|
6437
|
+
})) return false;
|
|
6438
|
+
}
|
|
6127
6439
|
const selectorArg = evaluateNode(chain.baseArgs[0], scope);
|
|
6128
6440
|
if (!selectorArg.ok) return false;
|
|
6129
6441
|
const manualSelectors = normalizeManualSelectors(Array.isArray(selectorArg.value) ? selectorArg.value.map(String) : String(selectorArg.value ?? ""));
|
|
6130
|
-
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;
|
|
6442
|
+
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;
|
|
6131
6443
|
return true;
|
|
6132
6444
|
}
|
|
6133
6445
|
function compileSelectorOverrideInto(chain, selectors, fileId, scope, cssConfig, transform, styleNames, options, items, rules, selectorPrefix) {
|
|
@@ -6335,7 +6647,7 @@ function decorateClassNameStyle(style, className) {
|
|
|
6335
6647
|
}
|
|
6336
6648
|
function decorateClassNameValue(value, className) {
|
|
6337
6649
|
if (isClassNameValue(value)) return value;
|
|
6338
|
-
if (isStyleImportantValue(value)) return importantValue(decorateClassNameValue(value.value, className));
|
|
6650
|
+
if (isStyleImportantValue(value)) return importantValue(decorateClassNameValue(value.value, className), value.native);
|
|
6339
6651
|
if (isStyleWeightValue(value)) return weightValue(decorateClassNameValue(value.value, className), value.weight);
|
|
6340
6652
|
return classNameValue(value, className);
|
|
6341
6653
|
}
|
|
@@ -6939,6 +7251,7 @@ function addSlotOverrideDataItems(value, parentSelector, atRules, fileId, items,
|
|
|
6939
7251
|
property: overrideItem.property,
|
|
6940
7252
|
weight: overrideItem.weight,
|
|
6941
7253
|
important: overrideItem.important,
|
|
7254
|
+
importantNative: overrideItem.importantNative,
|
|
6942
7255
|
value: overrideItem.value,
|
|
6943
7256
|
variable: overrideItem.variable,
|
|
6944
7257
|
token: overrideItem.token,
|
|
@@ -6990,8 +7303,8 @@ function addRuntimeScopeItem(sourceItem, parentSelector, atRules, fileId, items,
|
|
|
6990
7303
|
const itemAtRules = mergeAtRules(atRules, sourceItem.atRule);
|
|
6991
7304
|
const traceCallsite = callsiteOverride ?? sourceItem.callsite;
|
|
6992
7305
|
const valueStr = String(value ?? "");
|
|
6993
|
-
const dedupe = getClassNameDedupe(sourceItem.property, weight, important, sourceItem.selector, itemParentSelector, itemAtRules);
|
|
6994
|
-
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);
|
|
7306
|
+
const dedupe = getClassNameDedupe(sourceItem.property, weight, important, sourceItem.selector, itemParentSelector, itemAtRules, sourceItem.importantNative);
|
|
7307
|
+
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);
|
|
6995
7308
|
const item = createCompiledItem(4, sourceItem.slotId, dedupe, className, !!itemParentSelector);
|
|
6996
7309
|
items.push(item);
|
|
6997
7310
|
const css = buildAtomicRule(className, sourceItem.property, valueStr, important, sourceItem.selector, itemParentSelector, itemAtRules, cssConfig.scopeTargetPrefix);
|
|
@@ -7002,6 +7315,7 @@ function addRuntimeScopeItem(sourceItem, parentSelector, atRules, fileId, items,
|
|
|
7002
7315
|
css,
|
|
7003
7316
|
priority: layerPriority,
|
|
7004
7317
|
important,
|
|
7318
|
+
importantNative: sourceItem.importantNative,
|
|
7005
7319
|
trace: traceCallsite ? {
|
|
7006
7320
|
filePath: traceCallsite.filePath ?? fileId,
|
|
7007
7321
|
line: traceCallsite.line,
|
|
@@ -7068,9 +7382,9 @@ function addRuntimeStyleItem(sourceItem, selector, parentSelector, atRules, file
|
|
|
7068
7382
|
const runtimeValue = variable?.[0] === 1 ? getCompiledRuntimeValue(variable[2]) : void 0;
|
|
7069
7383
|
const shouldUseVariable = !!variable && (variable[0] !== 1 || !!sourceItem.token || !!runtimeValue);
|
|
7070
7384
|
const valueStr = variable?.[0] === 1 && !shouldUseVariable ? String(variable[2] ?? "") : String(value ?? "");
|
|
7071
|
-
const dedupe = getClassNameDedupe(sourceItem.property, weight, important, itemSelector, parentSelector, itemAtRules);
|
|
7385
|
+
const dedupe = getClassNameDedupe(sourceItem.property, weight, important, itemSelector, parentSelector, itemAtRules, sourceItem.importantNative);
|
|
7072
7386
|
const traceCallsite = callsiteOverride ?? sourceItem.callsite;
|
|
7073
|
-
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);
|
|
7387
|
+
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);
|
|
7074
7388
|
const item = createCompiledItem(type, slotId, dedupe, className, !!parentSelector);
|
|
7075
7389
|
item.sourceTrace = getRuntimeStyleItemSourceTrace(sourceItem, fileId);
|
|
7076
7390
|
if (type !== 4 && variable && shouldUseVariable) {
|
|
@@ -7086,6 +7400,7 @@ function addRuntimeStyleItem(sourceItem, selector, parentSelector, atRules, file
|
|
|
7086
7400
|
css,
|
|
7087
7401
|
priority: layerPriority,
|
|
7088
7402
|
important,
|
|
7403
|
+
importantNative: sourceItem.importantNative,
|
|
7089
7404
|
trace: traceCallsite ? {
|
|
7090
7405
|
filePath: traceCallsite.filePath ?? fileId,
|
|
7091
7406
|
line: traceCallsite.line,
|
|
@@ -7152,9 +7467,10 @@ function addStyleItems(styleObj, selector, parentSelector, atRules, fileId, type
|
|
|
7152
7467
|
const rawValue = styleObj[property];
|
|
7153
7468
|
let weight = null;
|
|
7154
7469
|
let important = false;
|
|
7470
|
+
let importantNative = false;
|
|
7155
7471
|
let value = rawValue;
|
|
7156
7472
|
let transformClassName = null;
|
|
7157
|
-
[value, weight, important] = unwrapStaticStyleValue(value);
|
|
7473
|
+
[value, weight, important, importantNative] = unwrapStaticStyleValue(value);
|
|
7158
7474
|
if (isClassNameValue(value)) {
|
|
7159
7475
|
transformClassName = value.className;
|
|
7160
7476
|
value = value.value;
|
|
@@ -7177,8 +7493,8 @@ function addStyleItems(styleObj, selector, parentSelector, atRules, fileId, type
|
|
|
7177
7493
|
const shouldUseVariable = !!(token || runtimeValue);
|
|
7178
7494
|
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;
|
|
7179
7495
|
const valueStr = variableName ? token ? getCssVarRawFallback(variableName, getTokenVar(token, cssConfig.tokenNameFormat)) : `var(${variableName})` : token ? getTokenVar(token, cssConfig.tokenNameFormat) : String(value);
|
|
7180
|
-
const dedupe = getClassNameDedupe(property, weight, important, selector, parentSelector, atRules);
|
|
7181
|
-
const className = getAtomicClassName(property, weight, important, valueStr, selector, parentSelector, atRules, propertyCallsite, cssConfig.localClassName, cssConfig.debugClassName, cssConfig.classNameFormat, transformClassName, cssConfig.transformClassNameFormat, cssConfig.sheetClassNameFormat, cssConfig.hashLength);
|
|
7496
|
+
const dedupe = getClassNameDedupe(property, weight, important, selector, parentSelector, atRules, importantNative);
|
|
7497
|
+
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);
|
|
7182
7498
|
const item = createCompiledItem(type, slotId, dedupe, className, !!parentSelector);
|
|
7183
7499
|
item.sourceTrace = propertyCallsite ? {
|
|
7184
7500
|
property,
|
|
@@ -7211,6 +7527,7 @@ function addStyleItems(styleObj, selector, parentSelector, atRules, fileId, type
|
|
|
7211
7527
|
css,
|
|
7212
7528
|
priority: layerPriority,
|
|
7213
7529
|
important,
|
|
7530
|
+
importantNative,
|
|
7214
7531
|
trace: propertyCallsite ? {
|
|
7215
7532
|
filePath: propertyCallsite.filePath ?? fileId,
|
|
7216
7533
|
line: propertyCallsite.line,
|
|
@@ -7236,9 +7553,11 @@ function addStyleItems(styleObj, selector, parentSelector, atRules, fileId, type
|
|
|
7236
7553
|
function unwrapStaticStyleValue(value) {
|
|
7237
7554
|
let weight = null;
|
|
7238
7555
|
let important = false;
|
|
7556
|
+
let native = false;
|
|
7239
7557
|
while (true) {
|
|
7240
7558
|
if (isStyleImportantValue(value)) {
|
|
7241
7559
|
important = true;
|
|
7560
|
+
native ||= value.native === true;
|
|
7242
7561
|
value = value.value;
|
|
7243
7562
|
continue;
|
|
7244
7563
|
}
|
|
@@ -7252,7 +7571,8 @@ function unwrapStaticStyleValue(value) {
|
|
|
7252
7571
|
return [
|
|
7253
7572
|
value,
|
|
7254
7573
|
weight,
|
|
7255
|
-
important
|
|
7574
|
+
important,
|
|
7575
|
+
native
|
|
7256
7576
|
];
|
|
7257
7577
|
}
|
|
7258
7578
|
function throwIfRequiredStaticStyleValue(result) {
|
|
@@ -7309,6 +7629,13 @@ function getCompiledRuntimeValue(value) {
|
|
|
7309
7629
|
if (!value || typeof value !== "object") return void 0;
|
|
7310
7630
|
return value[COMPILED_RUNTIME_VALUE];
|
|
7311
7631
|
}
|
|
7632
|
+
function hasGlobalRuntimeValue(value, seen = /* @__PURE__ */ new Set()) {
|
|
7633
|
+
if (!value || typeof value !== "object" || isStyleTokenData(value) || isAtRuleRef(value)) return false;
|
|
7634
|
+
if (getCompiledRuntimeValue(value)) return true;
|
|
7635
|
+
if (seen.has(value)) return false;
|
|
7636
|
+
seen.add(value);
|
|
7637
|
+
return Object.values(value).some((item) => hasGlobalRuntimeValue(item, seen));
|
|
7638
|
+
}
|
|
7312
7639
|
//#endregion
|
|
7313
7640
|
//#region compiler/transform/evaluator/tracer.ts
|
|
7314
7641
|
const CACHE_TYPE = "transform-trace";
|
|
@@ -7452,12 +7779,15 @@ function parseAndExtractModule(projectDir, filePath, content, babel, resolveImpo
|
|
|
7452
7779
|
if (spec.type !== "ExportSpecifier") continue;
|
|
7453
7780
|
const local = spec.local.name;
|
|
7454
7781
|
const exported = spec.exported.type === "Identifier" ? spec.exported.name : spec.exported.value;
|
|
7455
|
-
if (stmt.source)
|
|
7456
|
-
|
|
7457
|
-
|
|
7458
|
-
|
|
7459
|
-
|
|
7782
|
+
if (stmt.source) {
|
|
7783
|
+
imports.set(exported, {
|
|
7784
|
+
source: stmt.source.value,
|
|
7785
|
+
name: local
|
|
7786
|
+
});
|
|
7787
|
+
rawBindings.set(exported, t.identifier(exported));
|
|
7788
|
+
} else if (rawBindings.has(local)) rawBindings.set(exported, rawBindings.get(local));
|
|
7460
7789
|
else if (bindings.has(local)) bindings.set(exported, bindings.get(local));
|
|
7790
|
+
else if (imports.has(local)) rawBindings.set(exported, t.identifier(local));
|
|
7461
7791
|
}
|
|
7462
7792
|
continue;
|
|
7463
7793
|
}
|
|
@@ -7470,6 +7800,7 @@ function parseAndExtractModule(projectDir, filePath, content, babel, resolveImpo
|
|
|
7470
7800
|
if (stmt.type === "ExportDefaultDeclaration") rawBindings.set("default", stmt.declaration);
|
|
7471
7801
|
}
|
|
7472
7802
|
const scope = {
|
|
7803
|
+
tokenNameFormat: options.css?.tokenNameFormat ?? null,
|
|
7473
7804
|
bindings,
|
|
7474
7805
|
imports,
|
|
7475
7806
|
styleNames,
|
|
@@ -7777,7 +8108,14 @@ function isExtractRuntimeImportSpecifier(spec) {
|
|
|
7777
8108
|
return EXTRACT_RUNTIME_IMPORT_NAMES.has(imported);
|
|
7778
8109
|
}
|
|
7779
8110
|
function isCompilerHandledImport(source, name) {
|
|
7780
|
-
return IMPORT_PATHS.includes(source) &&
|
|
8111
|
+
return IMPORT_PATHS.includes(source) && [
|
|
8112
|
+
"createTheme",
|
|
8113
|
+
"createToken",
|
|
8114
|
+
"createTokens",
|
|
8115
|
+
"createValues",
|
|
8116
|
+
"createSheet",
|
|
8117
|
+
"createGlobalSheet"
|
|
8118
|
+
].includes(name);
|
|
7781
8119
|
}
|
|
7782
8120
|
//#endregion
|
|
7783
8121
|
//#region compiler/transform/extract/utils/replacement.ts
|
|
@@ -7805,7 +8143,7 @@ function buildSheetOptions(t, chain) {
|
|
|
7805
8143
|
const options = chain.sheetOptions ?? {};
|
|
7806
8144
|
const properties = [];
|
|
7807
8145
|
if (options.layer !== void 0) properties.push(t.objectProperty(t.identifier("layer"), typeof options.layer === "string" ? t.stringLiteral(options.layer) : t.booleanLiteral(options.layer)));
|
|
7808
|
-
if (options.
|
|
8146
|
+
if (options.specificity !== void 0) properties.push(t.objectProperty(t.identifier("specificity"), t.numericLiteral(options.specificity)));
|
|
7809
8147
|
return t.objectExpression(properties);
|
|
7810
8148
|
}
|
|
7811
8149
|
function buildStyleMergeArgs(t, chain, state, options) {
|
|
@@ -7916,7 +8254,11 @@ function buildAtRuleRefExpression(t, ref, state) {
|
|
|
7916
8254
|
}
|
|
7917
8255
|
function buildVariableValueExpression(t, value, state, item, options) {
|
|
7918
8256
|
if (isStyleTokenData(value)) {
|
|
7919
|
-
|
|
8257
|
+
const reference = value[COMPILED_TOKEN_REFERENCE];
|
|
8258
|
+
if (reference?.filePath === state.filePath) {
|
|
8259
|
+
const runtimeToken = options.getRuntimeToken?.(item, reference.expression);
|
|
8260
|
+
if (runtimeToken) return runtimeToken;
|
|
8261
|
+
}
|
|
7920
8262
|
return buildExtractedTokenExpression(t, value, state);
|
|
7921
8263
|
}
|
|
7922
8264
|
const valueNode = item.valueNode;
|
|
@@ -7924,7 +8266,9 @@ function buildVariableValueExpression(t, value, state, item, options) {
|
|
|
7924
8266
|
if (runtimeToken) return runtimeToken;
|
|
7925
8267
|
return valueNode ? t.cloneNode(valueNode) : literalExpression(t, value);
|
|
7926
8268
|
}
|
|
7927
|
-
function buildExtractedTokenExpression(t, token, state) {
|
|
8269
|
+
function buildExtractedTokenExpression(t, token, state, preserveReference = true) {
|
|
8270
|
+
const reference = token[COMPILED_TOKEN_REFERENCE];
|
|
8271
|
+
if (preserveReference && reference?.filePath === state.filePath) return t.cloneNode(reference.expression, true);
|
|
7928
8272
|
state.usedHelpers.add(FN_CREATE_EXTRACTED_TOKEN);
|
|
7929
8273
|
const tokenNameFormat = state.options.css?.tokenNameFormat ?? DEFAULT_CONFIG.tokenNameFormat ?? null;
|
|
7930
8274
|
return t.callExpression(t.identifier(FN_CREATE_EXTRACTED_TOKEN), [
|
|
@@ -7936,6 +8280,8 @@ function buildExtractedTokenExpression(t, token, state) {
|
|
|
7936
8280
|
]);
|
|
7937
8281
|
}
|
|
7938
8282
|
function buildExtractedTokenOverrideExpression(t, token, state) {
|
|
8283
|
+
const reference = token[COMPILED_TOKEN_REFERENCE];
|
|
8284
|
+
if (reference?.filePath === state.filePath) return t.cloneNode(reference.expression, true);
|
|
7939
8285
|
state.usedHelpers.add(FN_CREATE_EXTRACTED_TOKEN);
|
|
7940
8286
|
const tokenNameFormat = state.options.css?.tokenNameFormat ?? DEFAULT_CONFIG.tokenNameFormat ?? null;
|
|
7941
8287
|
const extractedToken = t.callExpression(t.identifier(FN_CREATE_EXTRACTED_TOKEN), [
|
|
@@ -7952,7 +8298,7 @@ function literalExpression(t, value) {
|
|
|
7952
8298
|
if (typeof value === "number") return t.numericLiteral(value);
|
|
7953
8299
|
if (typeof value === "boolean") return t.booleanLiteral(value);
|
|
7954
8300
|
if (value === null || value === void 0) return t.nullLiteral();
|
|
7955
|
-
return t.
|
|
8301
|
+
return t.valueToNode(value);
|
|
7956
8302
|
}
|
|
7957
8303
|
//#endregion
|
|
7958
8304
|
//#region compiler/transform/extract/utils/slot.ts
|
|
@@ -8071,7 +8417,8 @@ function getEvalScope(state) {
|
|
|
8071
8417
|
sheetNames: state.sheetNames,
|
|
8072
8418
|
styleMetas: state.styleMetas,
|
|
8073
8419
|
bindingNodes: state.bindingNodes,
|
|
8074
|
-
runtimeMode: state.runtimeMode
|
|
8420
|
+
runtimeMode: state.runtimeMode,
|
|
8421
|
+
tokenNameFormat: state.options.css?.tokenNameFormat ?? null
|
|
8075
8422
|
};
|
|
8076
8423
|
}
|
|
8077
8424
|
//#endregion
|
|
@@ -8117,6 +8464,62 @@ function compileThemeCall(path, state, opts) {
|
|
|
8117
8464
|
};
|
|
8118
8465
|
}
|
|
8119
8466
|
//#endregion
|
|
8467
|
+
//#region compiler/transform/extract/utils/token.ts
|
|
8468
|
+
function compileTokenFactory(node, state, t) {
|
|
8469
|
+
if (node.callee.type !== "Identifier") return null;
|
|
8470
|
+
const imp = state.imports.get(node.callee.name);
|
|
8471
|
+
if (!imp || !IMPORT_PATHS.includes(imp.source)) return null;
|
|
8472
|
+
if (![
|
|
8473
|
+
"createToken",
|
|
8474
|
+
"createTokens",
|
|
8475
|
+
"createValues"
|
|
8476
|
+
].includes(imp.name)) return null;
|
|
8477
|
+
const inputValue = evaluateNode(node.arguments[0], getEvalScope(state));
|
|
8478
|
+
if (inputValue.ok && hasUnresolvedValue(inputValue.value)) throw new Error(`Cannot extract ${imp.name}: factory inputs must be statically resolvable`);
|
|
8479
|
+
const result = evaluateNode(node, getEvalScope(state));
|
|
8480
|
+
if (!result.ok) throw new Error(`Cannot extract ${imp.name}: ${result.reason}`);
|
|
8481
|
+
if (isCompiledTokenFactory(result.value)) {
|
|
8482
|
+
state.usedHelpers.add(FN_CREATE_EXTRACTED_VALUES);
|
|
8483
|
+
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)])))]);
|
|
8484
|
+
t.addComment(expression, "leading", "#__PURE__");
|
|
8485
|
+
return expression;
|
|
8486
|
+
}
|
|
8487
|
+
const input = node.arguments[0];
|
|
8488
|
+
if (imp.name === "createToken") return buildGroup(result.value, input);
|
|
8489
|
+
const raw = evaluateNode(input, getEvalScope(state));
|
|
8490
|
+
const array = raw.ok && Array.isArray(raw.value) ? raw.value : null;
|
|
8491
|
+
if (array) return t.objectExpression(Object.entries(result.value).map(([key, token]) => {
|
|
8492
|
+
let index = array.length - 1;
|
|
8493
|
+
while (index >= 0 && String(array[index]) !== key) index--;
|
|
8494
|
+
return t.objectProperty(t.stringLiteral(key), buildGroup(token, member(input, String(index))), key === "__proto__");
|
|
8495
|
+
}));
|
|
8496
|
+
return buildGroup(result.value, input);
|
|
8497
|
+
function buildGroup(value, source) {
|
|
8498
|
+
if (isStyleTokenData(value)) {
|
|
8499
|
+
const expression = buildExtractedTokenExpression(t, value, state, false);
|
|
8500
|
+
if (!value.ref) expression.arguments[1] = t.cloneNode(source, true);
|
|
8501
|
+
t.addComment(expression, "leading", "#__PURE__");
|
|
8502
|
+
return expression;
|
|
8503
|
+
}
|
|
8504
|
+
if (!value || typeof value !== "object") throw new Error(`Invalid ${imp.name} token group`);
|
|
8505
|
+
return t.objectExpression(Object.entries(value).map(([key, child]) => t.objectProperty(t.stringLiteral(key), buildGroup(child, member(source, key)), key === "__proto__")));
|
|
8506
|
+
}
|
|
8507
|
+
function member(source, key) {
|
|
8508
|
+
if (source.type === "ObjectExpression") for (let index = source.properties.length - 1; index >= 0; index--) {
|
|
8509
|
+
const property = source.properties[index];
|
|
8510
|
+
if (property.type !== "ObjectProperty" || property.computed) break;
|
|
8511
|
+
if (getObjectPropertyKey$1(property) === key) return property.value;
|
|
8512
|
+
}
|
|
8513
|
+
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)];
|
|
8514
|
+
return t.memberExpression(t.cloneNode(source, true), t.stringLiteral(key), true);
|
|
8515
|
+
}
|
|
8516
|
+
}
|
|
8517
|
+
function hasUnresolvedValue(value) {
|
|
8518
|
+
if (!value || typeof value !== "object" || isStyleTokenData(value)) return false;
|
|
8519
|
+
if (value[COMPILED_RUNTIME_VALUE]) return true;
|
|
8520
|
+
return Object.values(value).some(hasUnresolvedValue);
|
|
8521
|
+
}
|
|
8522
|
+
//#endregion
|
|
8120
8523
|
//#region compiler/transform/extract/plugin.ts
|
|
8121
8524
|
function createExtractPlugin(args) {
|
|
8122
8525
|
const { options } = args;
|
|
@@ -8125,6 +8528,7 @@ function createExtractPlugin(args) {
|
|
|
8125
8528
|
const { types: t } = babel;
|
|
8126
8529
|
return {
|
|
8127
8530
|
pre() {
|
|
8531
|
+
this.tokenFactoryReplacements = /* @__PURE__ */ new Map();
|
|
8128
8532
|
this.styleNames = /* @__PURE__ */ new Set();
|
|
8129
8533
|
this.sheetNames = /* @__PURE__ */ new Set();
|
|
8130
8534
|
this.styleMetas = /* @__PURE__ */ new Map();
|
|
@@ -8173,7 +8577,7 @@ function createExtractPlugin(args) {
|
|
|
8173
8577
|
state.styleNames.add(spec.local.name);
|
|
8174
8578
|
state.styleMetas.set(spec.local.name, meta);
|
|
8175
8579
|
}
|
|
8176
|
-
if (sourceName === "@fluentic/style/css" && imported === "createSheet") state.sheetNames.add(spec.local.name);
|
|
8580
|
+
if (sourceName === "@fluentic/style/css" && (imported === "createSheet" || imported === "createGlobalSheet")) state.sheetNames.add(spec.local.name);
|
|
8177
8581
|
});
|
|
8178
8582
|
},
|
|
8179
8583
|
VariableDeclaration(path, state) {
|
|
@@ -8209,6 +8613,12 @@ function createExtractPlugin(args) {
|
|
|
8209
8613
|
state.bindings.set(name, evaluateEnumDeclaration(path.node, scope));
|
|
8210
8614
|
},
|
|
8211
8615
|
CallExpression(path, state) {
|
|
8616
|
+
if (mode === "extract") try {
|
|
8617
|
+
const tokenFactory = compileTokenFactory(path.node, state, t);
|
|
8618
|
+
if (tokenFactory) state.tokenFactoryReplacements.set(path.node, tokenFactory);
|
|
8619
|
+
} catch (error) {
|
|
8620
|
+
throw path.buildCodeFrameError(error instanceof Error ? error.message : String(error));
|
|
8621
|
+
}
|
|
8212
8622
|
if (path.parent.type === "MemberExpression" && !path.parent.computed) return;
|
|
8213
8623
|
const theme = compileThemeCall(path, state, options);
|
|
8214
8624
|
if (theme) {
|
|
@@ -8223,6 +8633,8 @@ function createExtractPlugin(args) {
|
|
|
8223
8633
|
if (!state.styleNames.size && !state.sheetNames.size) return;
|
|
8224
8634
|
const chain = extractStyleChain(path.node, state.styleNames, state.sheetNames);
|
|
8225
8635
|
if (!chain) return;
|
|
8636
|
+
chain.global = chain.kind === "sheet" && state.imports.get(chain.rootName)?.name === "createGlobalSheet";
|
|
8637
|
+
if (chain.global) chain.sheetId = state.fileId + ":" + path.node.start;
|
|
8226
8638
|
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.");
|
|
8227
8639
|
const scope = getEvalScope(state);
|
|
8228
8640
|
const loc = path.node.loc?.start;
|
|
@@ -8244,6 +8656,12 @@ function createExtractPlugin(args) {
|
|
|
8244
8656
|
state.collector.add(rule);
|
|
8245
8657
|
});
|
|
8246
8658
|
if (mode === "collect") return;
|
|
8659
|
+
if (chain.global) {
|
|
8660
|
+
if (path.parentPath.isExpressionStatement()) path.parentPath.remove();
|
|
8661
|
+
else path.replaceWith(t.unaryExpression("void", t.numericLiteral(0)));
|
|
8662
|
+
path.skip();
|
|
8663
|
+
return;
|
|
8664
|
+
}
|
|
8247
8665
|
const replacement = createChainReplacement({
|
|
8248
8666
|
t,
|
|
8249
8667
|
path,
|
|
@@ -8265,6 +8683,13 @@ function createExtractPlugin(args) {
|
|
|
8265
8683
|
},
|
|
8266
8684
|
Program: { exit(path, state) {
|
|
8267
8685
|
if (mode === "collect") return;
|
|
8686
|
+
path.traverse({ CallExpression(factoryPath) {
|
|
8687
|
+
const replacement = state.tokenFactoryReplacements.get(factoryPath.node);
|
|
8688
|
+
if (!replacement) return;
|
|
8689
|
+
factoryPath.replaceWith(replacement);
|
|
8690
|
+
factoryPath.skip();
|
|
8691
|
+
state.needsExtractImport = true;
|
|
8692
|
+
} });
|
|
8268
8693
|
pruneUnusedStyleInputDeclarations(path, state);
|
|
8269
8694
|
pruneUnusedStyleImports(path, state);
|
|
8270
8695
|
if (!state.needsExtractImport) return;
|
|
@@ -8291,23 +8716,35 @@ function checkCompiledImportantUsage(result, options, report) {
|
|
|
8291
8716
|
if (hasOutsideSheet && options.outsideSheet) report(options.outsideSheet, "style.important(...) outside createSheet is discouraged. Prefer style.weight(...) for Fluentic style priority.");
|
|
8292
8717
|
}
|
|
8293
8718
|
function pruneUnusedStyleInputDeclarations(path, state) {
|
|
8294
|
-
|
|
8295
|
-
|
|
8296
|
-
|
|
8297
|
-
|
|
8298
|
-
|
|
8299
|
-
|
|
8300
|
-
|
|
8301
|
-
|
|
8302
|
-
|
|
8303
|
-
|
|
8304
|
-
|
|
8305
|
-
|
|
8306
|
-
|
|
8719
|
+
const dependencies = /* @__PURE__ */ new Set();
|
|
8720
|
+
let changed;
|
|
8721
|
+
do {
|
|
8722
|
+
changed = false;
|
|
8723
|
+
path.scope.crawl();
|
|
8724
|
+
path.traverse({ VariableDeclarator(declaratorPath) {
|
|
8725
|
+
const node = declaratorPath.node;
|
|
8726
|
+
if (declaratorPath.parentPath?.parentPath?.isExportNamedDeclaration()) return;
|
|
8727
|
+
if (node.id.type !== "Identifier") return;
|
|
8728
|
+
const binding = declaratorPath.scope.getBinding(node.id.name);
|
|
8729
|
+
if (!binding || !binding.constant || binding.referencePaths.length) return;
|
|
8730
|
+
if (!isStyleInputCall(node.init, state) && !(dependencies.has(node) && declaratorPath.get("init").isPure())) return;
|
|
8731
|
+
declaratorPath.get("init").traverse({ ReferencedIdentifier(reference) {
|
|
8732
|
+
const dependency = reference.scope.getBinding(reference.node.name);
|
|
8733
|
+
if (dependency?.path.isVariableDeclarator()) dependencies.add(dependency.path.node);
|
|
8734
|
+
} });
|
|
8735
|
+
const declarationPath = declaratorPath.parentPath;
|
|
8736
|
+
if (!declarationPath?.isVariableDeclaration()) return;
|
|
8737
|
+
if (declarationPath.node.declarations.length > 1) declaratorPath.remove();
|
|
8738
|
+
else declarationPath.remove();
|
|
8739
|
+
changed = true;
|
|
8740
|
+
} });
|
|
8741
|
+
} while (changed);
|
|
8307
8742
|
path.scope.crawl();
|
|
8308
8743
|
}
|
|
8309
8744
|
function isStyleInputCall(node, state) {
|
|
8310
8745
|
if (!node || node.type !== "CallExpression") return false;
|
|
8746
|
+
const selectorChain = extractStyleChain(node, state.styleNames, state.sheetNames);
|
|
8747
|
+
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));
|
|
8311
8748
|
const callee = node.callee;
|
|
8312
8749
|
if (callee.type !== "MemberExpression" || callee.computed) return false;
|
|
8313
8750
|
if (callee.object.type !== "Identifier") return false;
|
|
@@ -8365,7 +8802,8 @@ function createRuntimeTokenCollector(args) {
|
|
|
8365
8802
|
return {
|
|
8366
8803
|
overrides,
|
|
8367
8804
|
addOverride(item) {
|
|
8368
|
-
|
|
8805
|
+
const reference = item.value[COMPILED_TOKEN_REFERENCE];
|
|
8806
|
+
overrides.push(args.t.cloneNode(reference?.filePath === args.state.filePath ? reference.expression : item.valueNode, true));
|
|
8369
8807
|
},
|
|
8370
8808
|
add(item, valueNode) {
|
|
8371
8809
|
if (canHoistRuntimeValue(args.path, valueNode)) return null;
|
|
@@ -9370,4 +9808,4 @@ Object.defineProperty(exports, "writeParcelVirtualRuntimeFile", {
|
|
|
9370
9808
|
}
|
|
9371
9809
|
});
|
|
9372
9810
|
|
|
9373
|
-
//# sourceMappingURL=shared-
|
|
9811
|
+
//# sourceMappingURL=shared-DY0kuBcN.cjs.map
|