@fluentic/style 0.1.0-beta.1 → 0.1.0-beta.10
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 +150 -2
- package/README.md +181 -49
- package/atomic/atRule/utils.ts +3 -2
- package/atomic/className.ts +50 -12
- package/atomic/debug/className/className.ts +24 -8
- package/atomic/element.ts +5 -2
- package/atomic/rule.ts +11 -5
- package/atomic/scope.ts +19 -0
- package/atomic/theme.ts +44 -3
- package/atomic/token.ts +7 -4
- package/atomic/utils/cssIdent.ts +54 -0
- package/atomic/utils/cssVar.ts +19 -0
- package/atomic/utils/debug.ts +1 -1
- package/atomic/utils/format.ts +1 -1
- package/atomic/utils/hash.ts +14 -0
- package/atomic/utils/selector.ts +31 -1
- package/atomic/var.ts +3 -2
- package/builder/classname/class_name_builder.ts +491 -0
- package/builder/classname/fns.ts +77 -0
- package/builder/classname/index.ts +3 -0
- package/builder/classname/types.ts +41 -0
- package/builder/data/const.ts +8 -1
- package/builder/data/create.ts +52 -6
- package/builder/data/data.ts +33 -8
- package/builder/data/debug.ts +1 -0
- package/builder/data/index.ts +0 -1
- package/builder/data/is.ts +26 -3
- package/builder/data/merge/scope.ts +38 -38
- package/builder/data/merge/style.ts +115 -20
- package/builder/data/state.ts +17 -2
- package/builder/extract/index.ts +1 -0
- package/builder/extract/sheet.ts +30 -0
- package/builder/extract/token.ts +30 -14
- package/builder/extract/utils.ts +2 -0
- package/builder/extract/withTokens.ts +2 -1
- package/builder/selector_override.noop.ts +11 -0
- package/builder/selector_override.ts +31 -0
- package/builder/selector_override_core.ts +79 -0
- package/builder/style_builder.ts +144 -20
- package/builder/style_data.ts +25 -0
- package/builder/style_fns.ts +57 -57
- package/builder/token/data.ts +30 -0
- package/builder/token/index.ts +3 -0
- package/builder/token/name.ts +54 -0
- package/builder/token/symbols.ts +6 -0
- package/builder/types/alias.ts +44 -16
- package/builder/types/fns.ts +24 -16
- package/builder/types/types.ts +37 -7
- package/builder/utils.ts +1 -0
- package/compiler/compiler/compiler.ts +88 -14
- package/compiler/compiler/constants.ts +6 -0
- package/compiler/compiler/index.ts +1 -0
- package/compiler/compiler/types.ts +4 -1
- package/compiler/cssProp.ts +21 -0
- package/compiler/extract/extract.ts +42 -14
- package/compiler/extract/types.ts +2 -0
- package/compiler/index.ts +1 -0
- package/compiler/transform/cssProp/index.ts +1 -0
- package/compiler/transform/cssProp/plugin.ts +161 -0
- package/compiler/transform/debug/plugin.ts +93 -4
- package/compiler/transform/debug/transform.ts +2 -1
- package/compiler/transform/debug/utils/debug_data.ts +73 -0
- package/compiler/transform/evaluator/evaluator.ts +169 -32
- package/compiler/transform/evaluator/tracer.ts +48 -11
- package/compiler/transform/extract/chain/chain.ts +1370 -162
- package/compiler/transform/extract/chain/extract_chain.ts +12 -4
- package/compiler/transform/extract/chain/types.ts +3 -1
- package/compiler/transform/extract/plugin.ts +64 -6
- package/compiler/transform/extract/transform.ts +2 -1
- package/compiler/transform/extract/utils/replacement.ts +72 -2
- package/compiler/transform/extract/utils/state.ts +3 -0
- package/compiler/transform/extract/utils/theme.ts +6 -6
- package/compiler/transform/index.ts +1 -0
- package/compiler/transform/syntax/isStaticStyleValue.ts +15 -9
- package/compiler/transform/syntax/static_ids.ts +1 -1
- package/compiler/utils/constants.ts +12 -5
- package/compiler/utils/file_resolver.ts +2 -0
- package/compiler/utils/import_source.ts +19 -8
- package/compiler/utils/imports.ts +11 -1
- package/config/build.ts +9 -2
- package/config/config/check.ts +25 -0
- package/config/config/css.ts +18 -1
- package/config/config/debug.ts +24 -1
- package/config/config/dev.ts +17 -1
- package/config/configure.ts +19 -2
- package/config/types.ts +7 -0
- package/css/index.ts +2 -0
- package/css/sheet.ts +152 -0
- package/css/styleTarget.ts +251 -0
- package/dev/config.ts +2 -3
- package/dev/utils.ts +3 -3
- package/dialect/extracted/index.ts +5 -0
- package/dialect/index.ts +1 -0
- package/dialect/namedTokens.ts +153 -0
- package/dist/adapter/preact.js +2 -0
- package/dist/adapter/react.js +2 -0
- package/dist/adapter/solid.js +2 -0
- package/dist/className-yhJCGT0F.js +304 -0
- package/dist/className-yhJCGT0F.js.map +1 -0
- package/dist/combine-Bww7VnSr.js +1254 -0
- package/dist/combine-Bww7VnSr.js.map +1 -0
- package/dist/compiler/index.mjs +2 -2
- package/dist/{compiler-DENc3a2R.mjs → compiler-C3CEGGtI.mjs} +2335 -638
- package/dist/compiler-C3CEGGtI.mjs.map +1 -0
- package/dist/config/index.js +2 -2
- package/dist/config-BAEzRmSJ.js +6 -0
- package/dist/{config-Di2VYYKV.js.map → config-BAEzRmSJ.js.map} +1 -1
- package/dist/config-BKP5LOkt.js +35 -0
- package/dist/config-BKP5LOkt.js.map +1 -0
- package/dist/config-C5VWvTav.js +34 -0
- package/dist/config-C5VWvTav.js.map +1 -0
- package/dist/config-CB4lm2tM.js +1 -0
- package/dist/config-CDjbHwb-.js +6 -0
- package/dist/config-CDjbHwb-.js.map +1 -0
- package/dist/config-DNEnHEf3.js +36 -0
- package/dist/config-DNEnHEf3.js.map +1 -0
- package/dist/createTransformElement-D8fXZ3wA.js +34 -0
- package/dist/createTransformElement-D8fXZ3wA.js.map +1 -0
- package/dist/css-BDn0epJ8.js +1339 -0
- package/dist/css-BDn0epJ8.js.map +1 -0
- package/dist/css-CFxNrYt3.js +4040 -0
- package/dist/css-CFxNrYt3.js.map +1 -0
- package/dist/css-DEYgrj76.js +524 -0
- package/dist/css-DEYgrj76.js.map +1 -0
- package/dist/{runtime-CYqNCiaM.js → css-DWBWsyxZ.js} +16 -19
- package/dist/css-DWBWsyxZ.js.map +1 -0
- package/dist/css.js +2 -2
- package/dist/{css_extra-oIi3UEPK.js → css_extra-nTq_Gw0E.js} +2 -2
- package/dist/{css_extra-DlOnsnR1.js.map → css_extra-nTq_Gw0E.js.map} +1 -1
- package/dist/data-CDrS1Bq4.js +785 -0
- package/dist/data-CDrS1Bq4.js.map +1 -0
- package/dist/debug-BkVbf0Cz.js +52 -0
- package/dist/debug-BkVbf0Cz.js.map +1 -0
- package/dist/{debug-n2aZQBSa.js → debug-YuhEIQVO.js} +80 -4
- package/dist/debug-YuhEIQVO.js.map +1 -0
- package/dist/dev/rsc.js +10 -9
- package/dist/dev/rsc.js.map +1 -1
- package/dist/{dev-CcphAa3R.js → dev-0imWmSVb.js} +10 -10
- package/dist/dev-0imWmSVb.js.map +1 -0
- package/dist/dev.js +1 -1
- package/dist/dialect/extracted/index.js +2 -0
- package/dist/dialect/index.js +2 -0
- package/dist/{elementMarker-Bu7gDAkE.js → elementMarker-kvpMjB49.js} +164 -30
- package/dist/elementMarker-kvpMjB49.js.map +1 -0
- package/dist/entry/dev/adapter/preact.js +12 -0
- package/dist/entry/dev/adapter/preact.js.map +1 -0
- package/dist/entry/dev/adapter/react.js +12 -0
- package/dist/entry/dev/adapter/react.js.map +1 -0
- package/dist/entry/dev/adapter/solid.js +12 -0
- package/dist/entry/dev/adapter/solid.js.map +1 -0
- package/dist/entry/dev/css.js +3 -3
- package/dist/entry/dev/jsx-dev-runtime.js +2 -1
- package/dist/entry/dev/jsx-runtime.js +2 -1
- package/dist/entry/dev.js +13 -9
- package/dist/entry/prod/adapter/preact.js +12 -0
- package/dist/entry/prod/adapter/preact.js.map +1 -0
- package/dist/entry/prod/adapter/react.js +12 -0
- package/dist/entry/prod/adapter/react.js.map +1 -0
- package/dist/entry/prod/adapter/solid.js +12 -0
- package/dist/entry/prod/adapter/solid.js.map +1 -0
- package/dist/entry/prod/css.js +3 -3
- package/dist/entry/prod/extract.js +242 -3
- package/dist/entry/prod/extract.js.map +1 -0
- package/dist/entry/prod/jsx-dev-runtime.js +2 -2
- package/dist/entry/prod/jsx-runtime.js +2 -2
- package/dist/entry/prod/runtime.js +3 -4
- package/dist/entry/prod.js +84 -1201
- package/dist/entry/prod.js.map +1 -1
- package/dist/entry/rsc-dev/adapter/preact.js +13 -0
- package/dist/entry/rsc-dev/adapter/preact.js.map +1 -0
- package/dist/entry/rsc-dev/adapter/react.js +13 -0
- package/dist/entry/rsc-dev/adapter/react.js.map +1 -0
- package/dist/entry/rsc-dev/adapter/solid.js +13 -0
- package/dist/entry/rsc-dev/adapter/solid.js.map +1 -0
- package/dist/entry/rsc-dev/css.js +3 -3
- package/dist/entry/rsc-dev/dev.js +11 -13
- package/dist/entry/rsc-dev/dev.js.map +1 -1
- package/dist/entry/rsc-dev/jsx-dev-runtime.js +2 -2
- package/dist/entry/rsc-dev/jsx-runtime.js +2 -2
- package/dist/entry/rsc-dev.js +582 -664
- package/dist/entry/rsc-dev.js.map +1 -1
- package/dist/entry/rsc-prod/adapter/preact.js +2 -0
- package/dist/entry/rsc-prod/adapter/react.js +2 -0
- package/dist/entry/rsc-prod/adapter/solid.js +2 -0
- package/dist/entry/rsc-prod/css.js +9 -3
- package/dist/entry/rsc-prod/css.js.map +1 -0
- package/dist/entry/rsc-prod/jsx-dev-runtime.js +2 -2
- package/dist/entry/rsc-prod/jsx-runtime.js +2 -2
- package/dist/entry/rsc-prod/runtime.js +3 -4
- package/dist/entry/rsc-prod.js +242 -10
- package/dist/entry/rsc-prod.js.map +1 -0
- package/dist/{styleStore-Dea_WVbr.js → env-Cz8frh6e.js} +1335 -372
- package/dist/env-Cz8frh6e.js.map +1 -0
- package/dist/getClassName-9CsXbNls.js +545 -0
- package/dist/getClassName-9CsXbNls.js.map +1 -0
- package/dist/{utils-D7FAOyg6.js → getClassName-DGm-VNDo.js} +28 -65
- package/dist/getClassName-DGm-VNDo.js.map +1 -0
- package/dist/getClassName-Dtc4yyYI.js +47 -0
- package/dist/getClassName-Dtc4yyYI.js.map +1 -0
- package/dist/{getClassName-BlvXHYuf.js → getClassName-DtkplEIt.js} +56 -14
- package/dist/getClassName-DtkplEIt.js.map +1 -0
- package/dist/global-CAc9OjKx.js +14 -0
- package/dist/global-CAc9OjKx.js.map +1 -0
- package/dist/{format-3nKBE_5t.js → hash-Cr-LCWDt.js} +51 -29
- package/dist/hash-Cr-LCWDt.js.map +1 -0
- package/dist/index.js +10 -8
- package/dist/jsx/jsx-dev-runtime.js +2 -2
- package/dist/jsx/jsx-dev-runtime.server.js +1 -1
- package/dist/jsx/jsx-runtime.js +2 -2
- package/dist/jsx/jsx-runtime.server.js +1 -1
- package/dist/jsx-CVxpkS04.js +39 -0
- package/dist/jsx-CVxpkS04.js.map +1 -0
- package/dist/{jsx_dev_runtime-B6xs4by8.js → jsx_dev_runtime-D068tAsT.js} +2 -3
- package/dist/{jsx_dev_runtime-B6xs4by8.js.map → jsx_dev_runtime-D068tAsT.js.map} +1 -1
- package/dist/{jsx_runtime-iHLDwpcW.js → jsx_runtime-6Qa1lmz2.js} +2 -2
- package/dist/{jsx_runtime-iHLDwpcW.js.map → jsx_runtime-6Qa1lmz2.js.map} +1 -1
- package/dist/{jsx_runtime-04xfnsi7.js → jsx_runtime-DT1Tr9cH.js} +2 -3
- package/dist/{jsx_runtime-04xfnsi7.js.map → jsx_runtime-DT1Tr9cH.js.map} +1 -1
- package/dist/{loader-B5Kw0DD-.mjs → loader-_-VjzlrX.mjs} +13 -14
- package/dist/loader-_-VjzlrX.mjs.map +1 -0
- package/dist/{misc-DCdYYyhK.mjs → misc-B76PUnWe.mjs} +11 -6
- package/dist/misc-B76PUnWe.mjs.map +1 -0
- package/dist/namedTokens-5AayGokX.js +85 -0
- package/dist/namedTokens-5AayGokX.js.map +1 -0
- package/dist/plugin/farm/index.mjs +4 -3
- package/dist/plugin/farm/index.mjs.map +1 -1
- package/dist/plugin/nextjs/index.mjs +121 -17
- package/dist/plugin/nextjs/index.mjs.map +1 -1
- package/dist/plugin/nextjs/loader.mjs +4 -4
- package/dist/plugin/parcel/index.cjs +2 -0
- package/dist/plugin/parcel/index.mjs +3 -1
- package/dist/plugin/parcel/optimizer.cjs +3 -2
- package/dist/plugin/parcel/optimizer.cjs.map +1 -1
- package/dist/plugin/parcel/optimizer.mjs +3 -2
- package/dist/plugin/parcel/optimizer.mjs.map +1 -1
- 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 +3 -2
- package/dist/plugin/rspack/index.mjs.map +1 -1
- package/dist/plugin/vite/index.mjs +13 -10
- package/dist/plugin/vite/index.mjs.map +1 -1
- package/dist/plugin/webpack/index.mjs +3 -2
- package/dist/plugin/webpack/loader.mjs +2 -2
- package/dist/presets/tailwind/index.js +995 -0
- package/dist/presets/tailwind/index.js.map +1 -0
- package/dist/{assert-BGdigdr5.js → presets-DSanixJV.js} +106 -2
- package/dist/presets-DSanixJV.js.map +1 -0
- package/dist/{registry-yHLRxyoo.mjs → registry-w8ET5R7v.mjs} +2 -2
- package/dist/{registry-yHLRxyoo.mjs.map → registry-w8ET5R7v.mjs.map} +1 -1
- package/dist/resolveClassNameRuntime-CJjlUP93.js +63 -0
- package/dist/resolveClassNameRuntime-CJjlUP93.js.map +1 -0
- package/dist/{rules-9HSO1pxL.js → rules-DaMaMHgb.js} +618 -138
- package/dist/rules-DaMaMHgb.js.map +1 -0
- package/dist/scope-CZdGAnl_.js +601 -0
- package/dist/scope-CZdGAnl_.js.map +1 -0
- package/dist/selector/index.js +1 -2
- package/dist/server.js +17 -11
- package/dist/server.js.map +1 -1
- package/dist/{shared-CxbHR89f.mjs → shared-C_cYxNzz.mjs} +4 -4
- package/dist/{shared-CxbHR89f.mjs.map → shared-C_cYxNzz.mjs.map} +1 -1
- package/dist/{shared-CBArHB9-.cjs → shared-PK52rW6T.cjs} +2338 -635
- package/dist/shared-PK52rW6T.cjs.map +1 -0
- package/dist/sheet-CxkO1Hwt.js +7 -0
- package/dist/sheet-CxkO1Hwt.js.map +1 -0
- package/dist/{sidecar-BFakLl0X.mjs → sidecar-BhvmXYsD.mjs} +3 -3
- package/dist/{sidecar-BFakLl0X.mjs.map → sidecar-BhvmXYsD.mjs.map} +1 -1
- package/dist/style-CAhAnRni.js +1129 -0
- package/dist/style-CAhAnRni.js.map +1 -0
- package/dist/{styleStore-DyNXBcUK.js → styleStore-BzLZwpwy.js} +8 -7
- package/dist/styleStore-BzLZwpwy.js.map +1 -0
- package/dist/styleStore-DaIJ4OPV.js +58 -0
- package/dist/styleStore-DaIJ4OPV.js.map +1 -0
- package/dist/token-D33mKTka.js +138 -0
- package/dist/token-D33mKTka.js.map +1 -0
- package/dist/{trace-Bu_qOqRy.js → trace-B3dpTRJp.js} +3 -3
- package/dist/{trace-Bu_qOqRy.js.map → trace-B3dpTRJp.js.map} +1 -1
- package/dist/{trace-CU0rvNYr.js → trace-c2WmBbmX.js} +2 -2
- package/dist/{trace-CU0rvNYr.js.map → trace-c2WmBbmX.js.map} +1 -1
- package/dist/transform-DSpimwwC.js +23 -0
- package/dist/transform-DSpimwwC.js.map +1 -0
- package/dist/{utils-Bdbqn0f8.mjs → utils-DND33M6y.mjs} +3 -3
- package/dist/{utils-Bdbqn0f8.mjs.map → utils-DND33M6y.mjs.map} +1 -1
- package/dist/utils-DZK0mfmY.js +42 -0
- package/dist/utils-DZK0mfmY.js.map +1 -0
- package/dist/utils-D_XgtMtn.js +72 -0
- package/dist/utils-D_XgtMtn.js.map +1 -0
- package/dist/utils-DxCpyV2E.js +62 -0
- package/dist/utils-DxCpyV2E.js.map +1 -0
- package/dist/{utils-BbehLOby.js → utils-H1VInWpd.js} +407 -234
- package/dist/utils-H1VInWpd.js.map +1 -0
- package/dist/utils-NdisireF.mjs +182 -0
- package/dist/utils-NdisireF.mjs.map +1 -0
- package/dist/utils.js +4 -4
- package/dist/utils.js.map +1 -1
- package/dist/value-CK0-Xbov.js +160 -0
- package/dist/value-CK0-Xbov.js.map +1 -0
- package/dist/{webpack-Dh6lox2l.mjs → webpack-D7QO0bKN.mjs} +5 -5
- package/dist/webpack-D7QO0bKN.mjs.map +1 -0
- package/entry/dev/adapter/preact.ts +8 -0
- package/entry/dev/adapter/react.ts +8 -0
- package/entry/dev/adapter/solid.ts +8 -0
- package/entry/dev/config.ts +1 -1
- package/entry/dev/index.ts +1 -0
- package/entry/dev/jsx_dev_runtime.ts +1 -0
- package/entry/dev/jsx_runtime.ts +1 -0
- package/entry/dev/sheet.ts +4 -0
- package/entry/prod/adapter/preact.ts +8 -0
- package/entry/prod/adapter/react.ts +8 -0
- package/entry/prod/adapter/solid.ts +8 -0
- package/entry/prod/config_debug.ts +2 -0
- package/entry/prod/index.ts +1 -1
- package/entry/prod/runtime.ts +4 -2
- package/entry/rsc_dev/adapter/preact.ts +9 -0
- package/entry/rsc_dev/adapter/react.ts +9 -0
- package/entry/rsc_dev/adapter/solid.ts +9 -0
- package/entry/rsc_dev/config.ts +1 -1
- package/entry/rsc_dev/server.ts +1 -1
- package/entry/rsc_prod/adapter/preact.ts +1 -0
- package/entry/rsc_prod/adapter/react.ts +1 -0
- package/entry/rsc_prod/adapter/solid.ts +1 -0
- package/entry/rsc_prod/config_debug.ts +6 -0
- package/entry/rsc_prod/index.ts +1 -1
- package/entry/rsc_prod/runtime.ts +1 -1
- package/entry/rsc_prod/server.ts +1 -1
- package/entry/shared/config_debug.ts +9 -0
- package/entry/shared/config_dev.ts +14 -0
- package/entry/shared/dev.ts +11 -2
- package/entry/shared/utils.ts +28 -0
- package/jsx/types/index.ts +1 -0
- package/jsx/types/preact.ts +14 -0
- package/jsx/{types.ts → types/react.ts} +2 -2
- package/jsx/types/solid.ts +32 -0
- package/package.json +110 -8
- package/plugin/bundler/farm/plugin.ts +2 -0
- package/plugin/bundler/parcel/optimizer.ts +1 -0
- package/plugin/bundler/parcel/plugin.ts +2 -0
- package/plugin/bundler/rspack/plugin.ts +1 -0
- package/plugin/bundler/vite/plugin.ts +5 -9
- package/plugin/bundler/vite/state.ts +11 -6
- package/plugin/bundler/webpack/plugin.ts +2 -1
- package/plugin/bundler/webpack/shared/loader.ts +9 -7
- package/plugin/nextjs/plugin.ts +208 -15
- package/plugin/nextjs/types.ts +1 -2
- package/plugin/nextjs/utils.ts +121 -0
- package/plugin/utils/compiler.ts +2 -0
- package/plugin/utils/runtimeEntry.ts +15 -2
- package/presets/tailwind/classname/index.ts +2 -0
- package/presets/tailwind/classname/transform.ts +239 -0
- package/presets/tailwind/classname/types.ts +124 -0
- package/presets/tailwind/index.ts +5 -0
- package/presets/tailwind/selectors.ts +27 -0
- package/presets/tailwind/style/index.ts +2 -0
- package/presets/tailwind/style/transform.ts +436 -0
- package/presets/tailwind/style/types.ts +346 -0
- package/presets/tailwind/theme.ts +479 -0
- package/presets/tailwind/types.ts +147 -0
- package/runtime/adapter/utils.ts +120 -0
- package/runtime/core/cache/combine.ts +76 -28
- package/runtime/core/cache/combineRuntime.ts +4 -0
- package/runtime/core/cache/index.ts +2 -1
- package/runtime/core/cache/item.ts +32 -13
- package/runtime/core/cache/itemWithResolver.ts +44 -0
- package/runtime/core/cache/pool.ts +16 -31
- package/runtime/core/cache/prop.ts +10 -8
- package/runtime/core/cache/result.ts +2 -2
- package/runtime/core/cache/stateItem.ts +16 -1
- package/runtime/core/cache/token.ts +20 -0
- package/runtime/core/cache/tokenValues.ts +19 -11
- package/runtime/core/combinedStyle.ts +4 -4
- package/runtime/extract/combineStyle.ts +211 -0
- package/runtime/extract/getClassName.ts +55 -23
- package/runtime/extract/index.ts +4 -2
- package/runtime/extract/token.ts +41 -0
- package/runtime/extract/tokenResolver.ts +17 -0
- package/runtime/index.ts +8 -1
- package/runtime/rsc/getClassName.ts +4 -0
- package/runtime/rsc/observer.ts +4 -0
- package/runtime/rsc/styleStore.ts +18 -7
- package/runtime/sheet/rule.ts +16 -12
- package/runtime/sheet/rules.ts +8 -3
- package/runtime/style/scope.ts +0 -24
- package/runtime/style/style.ts +181 -6
- package/runtime/types.ts +6 -4
- package/sheet/dev/dev_layer.ts +18 -7
- package/sheet/dev/dev_sort.ts +45 -11
- package/sheet/prod.ts +18 -7
- package/sheet/types.ts +2 -0
- package/sheet/utils/layer.ts +33 -0
- package/style/classname.ts +47 -0
- package/style/important.ts +19 -0
- package/style/index.ts +3 -0
- package/style/style.ts +47 -16
- package/style/theme.ts +4 -3
- package/style/token.ts +26 -21
- package/style/tokens.ts +18 -12
- package/style/transform.ts +41 -2
- package/style/types.ts +6 -4
- package/style/utils/expose.ts +4 -3
- package/style/value.ts +26 -11
- package/style/valueRef.ts +1 -1
- package/style/weight.ts +21 -0
- package/utils/global.ts +1 -3
- package/utils/hash.ts +4 -0
- package/utils/symbol.ts +3 -0
- package/atomic/layer/README.md +0 -116
- package/atomic/utils/css.ts +0 -49
- package/dist/assert-BGdigdr5.js.map +0 -1
- package/dist/className-C1Ht5Wvv.js +0 -144
- package/dist/className-C1Ht5Wvv.js.map +0 -1
- package/dist/className-DC2Cq8p3.js +0 -251
- package/dist/className-DC2Cq8p3.js.map +0 -1
- package/dist/compiler-DENc3a2R.mjs.map +0 -1
- package/dist/config-BryWDfQX.js +0 -25
- package/dist/config-BryWDfQX.js.map +0 -1
- package/dist/config-DKHXWhe1.js +0 -1
- package/dist/config-Di2VYYKV.js +0 -6
- package/dist/config-DloHOG6I.js +0 -13
- package/dist/config-DloHOG6I.js.map +0 -1
- package/dist/css-BowBszUt.js +0 -243
- package/dist/css-BowBszUt.js.map +0 -1
- package/dist/css-ByOrugEX.js +0 -805
- package/dist/css-ByOrugEX.js.map +0 -1
- package/dist/css-DcazYor9.js +0 -235
- package/dist/css-DcazYor9.js.map +0 -1
- package/dist/css_extra-DlOnsnR1.js +0 -8
- package/dist/css_extra-oIi3UEPK.js.map +0 -1
- package/dist/data-BsqOa5br.js +0 -473
- package/dist/data-BsqOa5br.js.map +0 -1
- package/dist/debug-BAw63qX6.js +0 -15
- package/dist/debug-BAw63qX6.js.map +0 -1
- package/dist/debug-DGki_v7g.js +0 -15
- package/dist/debug-DGki_v7g.js.map +0 -1
- package/dist/debug-n2aZQBSa.js.map +0 -1
- package/dist/dev-CcphAa3R.js.map +0 -1
- package/dist/dev-DfBbuLeE.js +0 -71
- package/dist/dev-DfBbuLeE.js.map +0 -1
- package/dist/elementMarker-Bu7gDAkE.js.map +0 -1
- package/dist/extract-CzWJeQi8.js +0 -121
- package/dist/extract-CzWJeQi8.js.map +0 -1
- package/dist/extract-DEwSDJ9Z.js +0 -2
- package/dist/format-3nKBE_5t.js.map +0 -1
- package/dist/getClassName-BlvXHYuf.js.map +0 -1
- package/dist/global-CvfmFLsK.js +0 -11
- package/dist/global-CvfmFLsK.js.map +0 -1
- package/dist/jsx-CwTeyUxr.js +0 -39
- package/dist/jsx-CwTeyUxr.js.map +0 -1
- package/dist/jsx-D2BksHSv.js +0 -38
- package/dist/jsx-D2BksHSv.js.map +0 -1
- package/dist/layer-D1SaH07m.js +0 -94
- package/dist/layer-D1SaH07m.js.map +0 -1
- package/dist/loader-B5Kw0DD-.mjs.map +0 -1
- package/dist/misc-DCdYYyhK.mjs.map +0 -1
- package/dist/presets-BhXa232U.js +0 -108
- package/dist/presets-BhXa232U.js.map +0 -1
- package/dist/property-CnLFt5kx.js +0 -406
- package/dist/property-CnLFt5kx.js.map +0 -1
- package/dist/rules-9HSO1pxL.js.map +0 -1
- package/dist/runtime-CYqNCiaM.js.map +0 -1
- package/dist/shared-CBArHB9-.cjs.map +0 -1
- package/dist/style-B-6jHipw.js +0 -5
- package/dist/style-B1UUqjj5.js +0 -743
- package/dist/style-B1UUqjj5.js.map +0 -1
- package/dist/style-DgHbdbdF.js +0 -752
- package/dist/style-DgHbdbdF.js.map +0 -1
- package/dist/style-v2bf70TZ.js +0 -1269
- package/dist/style-v2bf70TZ.js.map +0 -1
- package/dist/styleStore-Dea_WVbr.js.map +0 -1
- package/dist/styleStore-DyNXBcUK.js.map +0 -1
- package/dist/token-CKXUECuU.js +0 -76
- package/dist/token-CKXUECuU.js.map +0 -1
- package/dist/token-u_tM-mtg.js +0 -204
- package/dist/token-u_tM-mtg.js.map +0 -1
- package/dist/utils-BbehLOby.js.map +0 -1
- package/dist/utils-CEaq_c-A.mjs +0 -97
- package/dist/utils-CEaq_c-A.mjs.map +0 -1
- package/dist/utils-CWNHx4EC.js +0 -170
- package/dist/utils-CWNHx4EC.js.map +0 -1
- package/dist/utils-D7FAOyg6.js.map +0 -1
- package/dist/value-BR4e2MKt.js +0 -910
- package/dist/value-BR4e2MKt.js.map +0 -1
- package/dist/value-E8rEv2Oe.js +0 -136
- package/dist/value-E8rEv2Oe.js.map +0 -1
- package/dist/valueRef-lshFk1Cs.js +0 -16
- package/dist/valueRef-lshFk1Cs.js.map +0 -1
- package/dist/webpack-Dh6lox2l.mjs.map +0 -1
- package/dist/withTokens-LRidu3Vc.js +0 -95
- package/dist/withTokens-LRidu3Vc.js.map +0 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as crypto from "node:crypto";
|
|
2
2
|
import * as fs$1 from "node:fs";
|
|
3
3
|
import * as path$1 from "node:path";
|
|
4
|
+
import * as BabelCore from "@babel/core";
|
|
4
5
|
import picomatch from "picomatch";
|
|
5
6
|
import { SelectorType, parse } from "css-what";
|
|
6
|
-
import * as BabelCore from "@babel/core";
|
|
7
7
|
import { ResolverFactory } from "oxc-resolver";
|
|
8
8
|
//#region compiler/compiler/cache.ts
|
|
9
9
|
function createCompilerCache(args) {
|
|
@@ -97,10 +97,12 @@ function createCssCollector() {
|
|
|
97
97
|
};
|
|
98
98
|
}
|
|
99
99
|
//#endregion
|
|
100
|
-
//#region utils/
|
|
100
|
+
//#region utils/symbol.ts
|
|
101
101
|
function symbol(name) {
|
|
102
102
|
return Symbol.for(`@fluentic/style.${name}`);
|
|
103
103
|
}
|
|
104
|
+
//#endregion
|
|
105
|
+
//#region utils/global.ts
|
|
104
106
|
function globalData(key, data) {
|
|
105
107
|
const id = symbol(key);
|
|
106
108
|
const root = globalThis;
|
|
@@ -116,6 +118,10 @@ function assign(target, id, value) {
|
|
|
116
118
|
});
|
|
117
119
|
}
|
|
118
120
|
//#endregion
|
|
121
|
+
//#region config/config/check.ts
|
|
122
|
+
const CHECK_CONFIG_DEFAULT = {};
|
|
123
|
+
const CHECK_CONFIG = globalData("config.check", () => ({ ...CHECK_CONFIG_DEFAULT }));
|
|
124
|
+
//#endregion
|
|
119
125
|
//#region config/config/css.ts
|
|
120
126
|
const CSS_CONFIG_DEFAULT = {
|
|
121
127
|
layer: true,
|
|
@@ -123,6 +129,12 @@ const CSS_CONFIG_DEFAULT = {
|
|
|
123
129
|
layerNamespace: "css"
|
|
124
130
|
};
|
|
125
131
|
const CSS_CONFIG = globalData("config.css", () => ({ ...CSS_CONFIG_DEFAULT }));
|
|
132
|
+
function isStyleLayerEnabled(layer = CSS_CONFIG.layer) {
|
|
133
|
+
return typeof layer === "boolean" ? layer : layer.style ?? true;
|
|
134
|
+
}
|
|
135
|
+
function isSheetLayerEnabled(layer = CSS_CONFIG.layer) {
|
|
136
|
+
return typeof layer === "object" && (layer.sheet ?? false);
|
|
137
|
+
}
|
|
126
138
|
//#endregion
|
|
127
139
|
//#region config/utils.ts
|
|
128
140
|
const SIDECAR_URL_GLOBAL_SYMBOL = "FLUENTIC_STYLE_SIDECAR_URL";
|
|
@@ -139,15 +151,30 @@ const RUNTIME_CONFIG_DEFAULT = {
|
|
|
139
151
|
isRSC: false,
|
|
140
152
|
runtimeCacheTTL: getCacheTTL(true)
|
|
141
153
|
};
|
|
142
|
-
globalData("config.runtime", () => ({ ...RUNTIME_CONFIG_DEFAULT }));
|
|
154
|
+
const RUNTIME_CONFIG = globalData("config.runtime", () => ({ ...RUNTIME_CONFIG_DEFAULT }));
|
|
143
155
|
globalData("config.build", () => ({ current: null }));
|
|
144
156
|
//#endregion
|
|
157
|
+
//#region config/config/debug.ts
|
|
158
|
+
const DEFAULT_DEBUG_CONFIG = {
|
|
159
|
+
isDebugClassNameEnabled: false,
|
|
160
|
+
isDebugClassNameConfigured: false,
|
|
161
|
+
maxPropertyLength: 24,
|
|
162
|
+
maxValueLength: 8,
|
|
163
|
+
maxSelectorLength: 8,
|
|
164
|
+
maxParentSelectorLength: 8,
|
|
165
|
+
maxAtRuleLength: 10
|
|
166
|
+
};
|
|
167
|
+
const DEBUG_CONFIG = globalData("config.debug", () => ({ ...DEFAULT_DEBUG_CONFIG }));
|
|
168
|
+
//#endregion
|
|
145
169
|
//#region utils/hash.ts
|
|
146
170
|
function hashString(str) {
|
|
147
171
|
let hash = 2166136261;
|
|
148
172
|
for (let i = 0; i < str.length; i++) hash = Math.imul(hash ^ str.charCodeAt(i), 16777619);
|
|
149
173
|
return (hash >>> 0).toString(36).padEnd(7, "0");
|
|
150
174
|
}
|
|
175
|
+
function normalizeHashLength(length) {
|
|
176
|
+
return Number.isFinite(length) ? Math.max(1, Math.floor(length)) : 7;
|
|
177
|
+
}
|
|
151
178
|
//#endregion
|
|
152
179
|
//#region atomic/layer/layer.ts
|
|
153
180
|
function compareLayerPriority(p1, p2) {
|
|
@@ -157,8 +184,6 @@ function flattenCssLayers(layers, layerNames) {
|
|
|
157
184
|
const names = typeof layerNames === "string" ? [layerNames] : layerNames;
|
|
158
185
|
return layers.flatMap((layer) => layer === "$layer" ? names : layer).filter(Boolean);
|
|
159
186
|
}
|
|
160
|
-
//#endregion
|
|
161
|
-
//#region atomic/layer/types.ts
|
|
162
187
|
const LayerDefaultPriority = [
|
|
163
188
|
0,
|
|
164
189
|
0,
|
|
@@ -194,67 +219,18 @@ function getLayerOrderCss(layers, layerNames) {
|
|
|
194
219
|
function getLayerBlockCss(layerName, css) {
|
|
195
220
|
return "@layer " + layerName + " {" + css + "}";
|
|
196
221
|
}
|
|
197
|
-
function getLayerBundleCss(layers, layerName, css) {
|
|
198
|
-
const output = [];
|
|
199
|
-
const layerOrder = getLayerOrderCss(layers, layerName);
|
|
200
|
-
if (layerOrder) output.push(layerOrder);
|
|
201
|
-
output.push(getLayerBlockCss(layerName, "\n" + css.join("\n") + "\n"));
|
|
202
|
-
return output.join("\n");
|
|
203
|
-
}
|
|
204
|
-
//#endregion
|
|
205
|
-
//#region config/config/debug.ts
|
|
206
|
-
const DEFAULT_DEBUG_CONFIG = {
|
|
207
|
-
isDebugClassNameEnabled: true,
|
|
208
|
-
maxPropertyLength: 24,
|
|
209
|
-
maxValueLength: 8,
|
|
210
|
-
maxSelectorLength: 8,
|
|
211
|
-
maxParentSelectorLength: 8,
|
|
212
|
-
maxAtRuleLength: 10
|
|
213
|
-
};
|
|
214
|
-
const DEBUG_CONFIG = globalData("config.debug", () => ({ ...DEFAULT_DEBUG_CONFIG }));
|
|
215
|
-
//#endregion
|
|
216
|
-
//#region utils/object.ts
|
|
217
|
-
function toArray(value) {
|
|
218
|
-
return Array.isArray(value) ? value : value ? [value] : [];
|
|
219
|
-
}
|
|
220
|
-
function isFunction(value) {
|
|
221
|
-
return typeof value === "function";
|
|
222
|
-
}
|
|
223
|
-
function isPromiseLike(value) {
|
|
224
|
-
return typeof value === "object" && value !== null && "then" in value;
|
|
225
|
-
}
|
|
226
|
-
//#endregion
|
|
227
|
-
//#region config/config/dev.ts
|
|
228
|
-
const DEV_CONFIG_DEFAULT = {
|
|
229
|
-
isDev: false,
|
|
230
|
-
isCheckSelectorEnabled: true,
|
|
231
|
-
isSourcemapEnabled: true,
|
|
232
|
-
isLocalClassNameEnabled: true,
|
|
233
|
-
sheetMaxRules: 1e3,
|
|
234
|
-
sheetStyleTagNonce: null,
|
|
235
|
-
stylePriorityMode: "layer",
|
|
236
|
-
sourcemapLocationMode: "style",
|
|
237
|
-
isElementClassNameEnabled: true
|
|
238
|
-
};
|
|
239
|
-
globalData("config.dev.isDev", () => ({ isDev: false }));
|
|
240
|
-
const DEV_CONFIG = globalData("config.dev", () => ({ ...DEV_CONFIG_DEFAULT }));
|
|
241
|
-
globalData("config.dev.plugin", () => ({ config: null }));
|
|
242
|
-
globalData("config.dev.base", () => ({ config: null }));
|
|
243
|
-
globalData("config.dev.utils", () => ({ config: null }));
|
|
244
222
|
const STYLE_IMPORT_PATH = "@fluentic/style";
|
|
245
223
|
const STYLE_CSS_IMPORT_PATH = "@fluentic/style/css";
|
|
224
|
+
const STYLE_DIALECT_IMPORT_PATH = "@fluentic/style/dialect";
|
|
246
225
|
const STYLE_DEV_RSC_IMPORT_PATH = "@fluentic/style/dev/rsc";
|
|
247
226
|
const STYLE_ENTRY_PROD_EXTRACT_IMPORT_PATH = "@fluentic/style/entry/prod/extract";
|
|
248
227
|
const STYLE_EXTRACT_RUNTIME_IMPORT_PATH = "@fluentic/style/entry/prod/runtime";
|
|
249
228
|
const STYLE_RSC_EXTRACT_RUNTIME_IMPORT_PATH = "@fluentic/style/entry/rsc-prod/runtime";
|
|
250
|
-
const DEFAULT_CONFIG = {
|
|
251
|
-
...CSS_CONFIG_DEFAULT,
|
|
252
|
-
localClassName: DEV_CONFIG_DEFAULT.isLocalClassNameEnabled,
|
|
253
|
-
debugClassName: DEFAULT_DEBUG_CONFIG.isDebugClassNameEnabled
|
|
254
|
-
};
|
|
229
|
+
const DEFAULT_CONFIG = { ...CSS_CONFIG_DEFAULT };
|
|
255
230
|
const IMPORT_PATHS = [
|
|
256
231
|
STYLE_IMPORT_PATH,
|
|
257
232
|
STYLE_CSS_IMPORT_PATH,
|
|
233
|
+
STYLE_DIALECT_IMPORT_PATH,
|
|
258
234
|
STYLE_DEV_RSC_IMPORT_PATH
|
|
259
235
|
];
|
|
260
236
|
const IMPORT_EXTRACT = STYLE_ENTRY_PROD_EXTRACT_IMPORT_PATH;
|
|
@@ -270,6 +246,7 @@ const FN_CREATE_FONT_PALETTE_VALUES = "createFontPaletteValues";
|
|
|
270
246
|
const FN_CREATE_POSITION_TRY = "createPositionTry";
|
|
271
247
|
const FN_CREATE_COUNTER_STYLE = "createCounterStyle";
|
|
272
248
|
const FN_CREATE_EXTRACTED_STYLE = "createExtractedStyle";
|
|
249
|
+
const FN_CREATE_EXTRACTED_SHEET = "createExtractedSheet";
|
|
273
250
|
const FN_CREATE_EXTRACTED_SLOT = "createExtractedSlot";
|
|
274
251
|
const FN_CREATE_EXTRACTED_SCOPE = "createExtractedScope";
|
|
275
252
|
const FN_CREATE_EXTRACTED_TOKEN = "createExtractedToken";
|
|
@@ -292,13 +269,169 @@ function getExtractedCssItems(items, args) {
|
|
|
292
269
|
seen.add(item.css);
|
|
293
270
|
css.push(item);
|
|
294
271
|
}
|
|
295
|
-
if (
|
|
272
|
+
if (!css.length) return "";
|
|
296
273
|
const defaults = DEFAULT_CONFIG;
|
|
297
274
|
const layerNamespace = args.layerNamespace ?? defaults.layerNamespace ?? "";
|
|
298
|
-
|
|
275
|
+
const layers = args.layers ?? defaults.layers ?? [];
|
|
276
|
+
const styleLayer = isStyleLayerEnabled(args.layer ?? defaults.layer);
|
|
277
|
+
const sheetLayerName = layerNamespace ? layerNamespace + ".sheet" : "sheet";
|
|
278
|
+
const styleItems = [];
|
|
279
|
+
const sheetItems = [];
|
|
280
|
+
const unlayeredItems = [];
|
|
281
|
+
for (let i = 0, len = css.length; i < len; i++) {
|
|
282
|
+
const item = css[i];
|
|
283
|
+
if (item.layer === "sheet") sheetItems.push(item.css);
|
|
284
|
+
else if (item.layer === false || !styleLayer) unlayeredItems.push(item.css);
|
|
285
|
+
else styleItems.push(item.css);
|
|
286
|
+
}
|
|
287
|
+
const styleLayerName = sheetItems.length && layerNamespace ? layerNamespace + ".style" : layerNamespace;
|
|
288
|
+
const layerNames = [styleItems.length ? styleLayerName : "", sheetItems.length ? sheetLayerName : ""].filter(Boolean);
|
|
289
|
+
const output = [];
|
|
290
|
+
const layerOrder = getLayerOrderCss(layers, layerNames);
|
|
291
|
+
if (layerOrder) output.push(layerOrder);
|
|
292
|
+
if (styleItems.length) output.push(getLayerBlockCss(styleLayerName, "\n" + styleItems.join("\n") + "\n"));
|
|
293
|
+
if (sheetItems.length) output.push(getLayerBlockCss(sheetLayerName, "\n" + sheetItems.join("\n") + "\n"));
|
|
294
|
+
output.push(...unlayeredItems);
|
|
295
|
+
return output.join("\n");
|
|
299
296
|
}
|
|
300
|
-
|
|
301
|
-
|
|
297
|
+
//#endregion
|
|
298
|
+
//#region compiler/transform/utils/babel.ts
|
|
299
|
+
function babelPlugin(factory) {
|
|
300
|
+
return factory;
|
|
301
|
+
}
|
|
302
|
+
function babelTransform(args) {
|
|
303
|
+
let result = null;
|
|
304
|
+
try {
|
|
305
|
+
const inputSourceMap = parseInputSourceMap(args.sourcemap);
|
|
306
|
+
result = BabelCore.transformSync(args.code, {
|
|
307
|
+
...babelTransformOptions(),
|
|
308
|
+
inputSourceMap,
|
|
309
|
+
filename: args.filePath,
|
|
310
|
+
sourceFileName: args.filePath,
|
|
311
|
+
plugins: args.plugins,
|
|
312
|
+
sourceMaps: true,
|
|
313
|
+
generatorOpts: { retainLines: args.retainLines ?? false }
|
|
314
|
+
});
|
|
315
|
+
} catch (err) {
|
|
316
|
+
if (!args.errorLabel) throw err;
|
|
317
|
+
const message = getBabelError(err, args);
|
|
318
|
+
const error = new Error(message);
|
|
319
|
+
error.stack = void 0;
|
|
320
|
+
throw error;
|
|
321
|
+
}
|
|
322
|
+
if (!result || !result.code) return null;
|
|
323
|
+
return {
|
|
324
|
+
code: result.code,
|
|
325
|
+
sourcemap: result.map ? JSON.stringify(result.map) : null
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
function babelTransformOptions() {
|
|
329
|
+
return {
|
|
330
|
+
configFile: false,
|
|
331
|
+
babelrc: false,
|
|
332
|
+
parserOpts: {
|
|
333
|
+
plugins: ["typescript", "jsx"],
|
|
334
|
+
strictMode: false,
|
|
335
|
+
allowImportExportEverywhere: true
|
|
336
|
+
}
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
function parseInputSourceMap(sourcemap) {
|
|
340
|
+
if (!sourcemap) return void 0;
|
|
341
|
+
if (typeof sourcemap !== "string") return sourcemap;
|
|
342
|
+
return JSON.parse(sourcemap);
|
|
343
|
+
}
|
|
344
|
+
function getBabelError(err, args) {
|
|
345
|
+
const babelErr = err;
|
|
346
|
+
const msg = babelErr instanceof Error ? babelErr.message : String(err);
|
|
347
|
+
const codeFrame = babelErr?.codeFrame;
|
|
348
|
+
const suffix = codeFrame ? `\n\n${codeFrame}` : "";
|
|
349
|
+
return `${args.errorLabel} in ${args.filePath}:\n${msg}${suffix}`;
|
|
350
|
+
}
|
|
351
|
+
//#endregion
|
|
352
|
+
//#region compiler/transform/cssProp/plugin.ts
|
|
353
|
+
function createCssPropPlugin(args) {
|
|
354
|
+
return babelPlugin((babel) => {
|
|
355
|
+
const { types: t } = babel;
|
|
356
|
+
return {
|
|
357
|
+
pre() {
|
|
358
|
+
this.options = args.options;
|
|
359
|
+
this.mergeId = null;
|
|
360
|
+
this.programPath = null;
|
|
361
|
+
this.changed = false;
|
|
362
|
+
},
|
|
363
|
+
visitor: {
|
|
364
|
+
Program: {
|
|
365
|
+
enter(path, state) {
|
|
366
|
+
state.programPath = path;
|
|
367
|
+
state.mergeId = path.scope.generateUidIdentifier("fluenticMergeJsxProps");
|
|
368
|
+
},
|
|
369
|
+
exit(path, state) {
|
|
370
|
+
const options = getCssPropOptions(state.options);
|
|
371
|
+
if (!state.changed || !options || !state.mergeId) return;
|
|
372
|
+
path.unshiftContainer("body", t.importDeclaration([t.importSpecifier(state.mergeId, t.identifier("mergeJsxProps"))], t.stringLiteral(options.adapter)));
|
|
373
|
+
}
|
|
374
|
+
},
|
|
375
|
+
JSXOpeningElement(path, state) {
|
|
376
|
+
const keyHoistedAttributes = hoistKeyAttributes(path.node.attributes);
|
|
377
|
+
if (keyHoistedAttributes) path.node.attributes = keyHoistedAttributes;
|
|
378
|
+
if (!getCssPropOptions(state.options) || !state.mergeId) return;
|
|
379
|
+
if (!isIntrinsicElement(path.node.name)) return;
|
|
380
|
+
if (!hasCssAttribute(path.node.attributes)) return;
|
|
381
|
+
const keyAttributes = path.node.attributes.filter(isKeyAttribute);
|
|
382
|
+
const parts = path.node.attributes.filter((attr) => !isKeyAttribute(attr)).map((attr) => buildPart(t, attr));
|
|
383
|
+
path.node.attributes = [...keyAttributes, t.jsxSpreadAttribute(t.callExpression(state.mergeId, [t.arrayExpression(parts)]))];
|
|
384
|
+
state.changed = true;
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
};
|
|
388
|
+
});
|
|
389
|
+
}
|
|
390
|
+
function getCssPropOptions(options) {
|
|
391
|
+
return options.cssProp || null;
|
|
392
|
+
}
|
|
393
|
+
function isIntrinsicElement(name) {
|
|
394
|
+
return name.type === "JSXIdentifier" && /^[a-z]/.test(name.name);
|
|
395
|
+
}
|
|
396
|
+
function hasCssAttribute(attrs) {
|
|
397
|
+
return attrs.some((attr) => {
|
|
398
|
+
return attr.type === "JSXAttribute" && attr.name.type === "JSXIdentifier" && attr.name.name === "css";
|
|
399
|
+
});
|
|
400
|
+
}
|
|
401
|
+
function hoistKeyAttributes(attrs) {
|
|
402
|
+
const keyAttributes = attrs.filter(isKeyAttribute);
|
|
403
|
+
if (!keyAttributes.length) return null;
|
|
404
|
+
const firstKeyIndex = attrs.findIndex(isKeyAttribute);
|
|
405
|
+
const firstSpreadIndex = attrs.findIndex((attr) => attr.type === "JSXSpreadAttribute");
|
|
406
|
+
if (firstSpreadIndex < 0 || firstKeyIndex < firstSpreadIndex) return null;
|
|
407
|
+
return [...keyAttributes, ...attrs.filter((attr) => !isKeyAttribute(attr))];
|
|
408
|
+
}
|
|
409
|
+
function isKeyAttribute(attr) {
|
|
410
|
+
return attr.type === "JSXAttribute" && attr.name.type === "JSXIdentifier" && attr.name.name === "key";
|
|
411
|
+
}
|
|
412
|
+
function buildPart(t, attr) {
|
|
413
|
+
if (attr.type === "JSXSpreadAttribute") return attr.argument;
|
|
414
|
+
return t.objectExpression([t.objectProperty(getObjectKey(t, attr.name), getAttributeValue(t, attr))]);
|
|
415
|
+
}
|
|
416
|
+
function getObjectKey(t, name) {
|
|
417
|
+
if (name.type === "JSXIdentifier" && isValidIdentifierName(name.name)) return t.identifier(name.name);
|
|
418
|
+
return t.stringLiteral(getAttributeName(name));
|
|
419
|
+
}
|
|
420
|
+
function getAttributeName(name) {
|
|
421
|
+
if (name.type === "JSXIdentifier") return name.name;
|
|
422
|
+
return `${name.namespace.name}:${name.name.name}`;
|
|
423
|
+
}
|
|
424
|
+
function getAttributeValue(t, attr) {
|
|
425
|
+
if (!attr.value) return t.booleanLiteral(true);
|
|
426
|
+
if (attr.value.type === "StringLiteral") return t.stringLiteral(attr.value.value);
|
|
427
|
+
if (attr.value.type === "JSXExpressionContainer") {
|
|
428
|
+
if (attr.value.expression.type === "JSXEmptyExpression") return t.booleanLiteral(true);
|
|
429
|
+
return attr.value.expression;
|
|
430
|
+
}
|
|
431
|
+
return attr.value;
|
|
432
|
+
}
|
|
433
|
+
function isValidIdentifierName(name) {
|
|
434
|
+
return /^[$A-Z_a-z][$\w]*$/.test(name);
|
|
302
435
|
}
|
|
303
436
|
//#endregion
|
|
304
437
|
//#region builder/data/const.ts
|
|
@@ -308,6 +441,42 @@ const BUILDER_CALLSITE = symbol("builder.callsite");
|
|
|
308
441
|
const BUILDER_SLOT_ID = symbol("builder.slotId");
|
|
309
442
|
const BUILDER_SCOPE_ID = symbol("builder.scopeId");
|
|
310
443
|
const BUILDER_SCOPE = symbol("builder.scope");
|
|
444
|
+
const BUILDER_SELECTOR = symbol("builder.selector");
|
|
445
|
+
const BUILDER_SHEET_OPTIONS = symbol("builder.sheetOptions");
|
|
446
|
+
const SHEET_SELECTOR_ANCHOR = "\0sheet";
|
|
447
|
+
//#endregion
|
|
448
|
+
//#region utils/object.ts
|
|
449
|
+
function hasOwn(target, field) {
|
|
450
|
+
return Object.prototype.hasOwnProperty.call(target, field);
|
|
451
|
+
}
|
|
452
|
+
function toArray(value) {
|
|
453
|
+
return Array.isArray(value) ? value : value ? [value] : [];
|
|
454
|
+
}
|
|
455
|
+
function isFunction(value) {
|
|
456
|
+
return typeof value === "function";
|
|
457
|
+
}
|
|
458
|
+
function isPromiseLike(value) {
|
|
459
|
+
return typeof value === "object" && value !== null && "then" in value;
|
|
460
|
+
}
|
|
461
|
+
//#endregion
|
|
462
|
+
//#region config/config/dev.ts
|
|
463
|
+
const DEV_CONFIG_DEFAULT = {
|
|
464
|
+
isDev: false,
|
|
465
|
+
isCheckSelectorEnabled: true,
|
|
466
|
+
isSourcemapEnabled: true,
|
|
467
|
+
isLocalClassNameEnabled: true,
|
|
468
|
+
sheetMaxRules: 1e3,
|
|
469
|
+
sheetStyleTagNonce: null,
|
|
470
|
+
hashLength: null,
|
|
471
|
+
stylePriorityMode: "sort",
|
|
472
|
+
sourcemapLocationMode: "style",
|
|
473
|
+
isElementClassNameEnabled: true
|
|
474
|
+
};
|
|
475
|
+
globalData("config.dev.isDev", () => ({ isDev: false }));
|
|
476
|
+
const DEV_CONFIG = globalData("config.dev", () => ({ ...DEV_CONFIG_DEFAULT }));
|
|
477
|
+
globalData("config.dev.plugin", () => ({ config: null }));
|
|
478
|
+
globalData("config.dev.base", () => ({ config: null }));
|
|
479
|
+
globalData("config.dev.utils", () => ({ config: null }));
|
|
311
480
|
//#endregion
|
|
312
481
|
//#region utils/trace.ts
|
|
313
482
|
const FN_MARKER = "$fn_";
|
|
@@ -459,6 +628,15 @@ function createDebugCallsite(loc, debug) {
|
|
|
459
628
|
}
|
|
460
629
|
//#endregion
|
|
461
630
|
//#region builder/data/is.ts
|
|
631
|
+
function getSlotId(data) {
|
|
632
|
+
return data[BUILDER_SLOT_ID];
|
|
633
|
+
}
|
|
634
|
+
function getScopeTargetSlotId(data) {
|
|
635
|
+
return data[BUILDER_SCOPE_ID];
|
|
636
|
+
}
|
|
637
|
+
function getScopeTargetScope(data) {
|
|
638
|
+
return data[BUILDER_SCOPE];
|
|
639
|
+
}
|
|
462
640
|
function isStyleData(value) {
|
|
463
641
|
return getBuilderType(value) === 1;
|
|
464
642
|
}
|
|
@@ -468,19 +646,33 @@ function isSlotData(value) {
|
|
|
468
646
|
function isSlotOverrideData(value) {
|
|
469
647
|
return getBuilderType(value) === 3;
|
|
470
648
|
}
|
|
649
|
+
function isSelectorData(value) {
|
|
650
|
+
return getBuilderType(value) === 7;
|
|
651
|
+
}
|
|
652
|
+
function isSheetData(value) {
|
|
653
|
+
return getBuilderType(value) === 9;
|
|
654
|
+
}
|
|
471
655
|
function isScopeData(value) {
|
|
472
656
|
return getBuilderType(value) === 4;
|
|
473
657
|
}
|
|
658
|
+
function isThemeData(value) {
|
|
659
|
+
return getBuilderType(value) === 6;
|
|
660
|
+
}
|
|
474
661
|
function getBuilderType(value) {
|
|
475
662
|
if (!value || typeof value !== "object" && typeof value !== "function") return null;
|
|
476
663
|
return value[BUILDER_TYPE];
|
|
477
664
|
}
|
|
665
|
+
function normalizeSelectorArg(arg) {
|
|
666
|
+
return arg.includes("\n") ? arg.replace(/\n/g, "") : arg;
|
|
667
|
+
}
|
|
478
668
|
//#endregion
|
|
479
|
-
//#region
|
|
669
|
+
//#region builder/token/symbols.ts
|
|
480
670
|
const TOKEN_ID = symbol("style:token");
|
|
481
671
|
const TOKEN_OVERRIDE = symbol("style:token.override");
|
|
482
|
-
symbol("style:token.
|
|
483
|
-
|
|
672
|
+
const TOKEN_NAME = symbol("style:token.name");
|
|
673
|
+
const TOKEN_VAR_NAME = symbol("style:token.varName");
|
|
674
|
+
//#endregion
|
|
675
|
+
//#region builder/token/data.ts
|
|
484
676
|
function isStyleTokenData(value) {
|
|
485
677
|
return !!value && typeof value[TOKEN_ID] === "string" && value[TOKEN_OVERRIDE] !== true;
|
|
486
678
|
}
|
|
@@ -490,6 +682,84 @@ function isStyleTokenOverrideData(value) {
|
|
|
490
682
|
function getStyleTokenId(token) {
|
|
491
683
|
return token[TOKEN_ID];
|
|
492
684
|
}
|
|
685
|
+
function getStyleTokenName(token) {
|
|
686
|
+
return token[TOKEN_NAME] ?? null;
|
|
687
|
+
}
|
|
688
|
+
//#endregion
|
|
689
|
+
//#region builder/token/name.ts
|
|
690
|
+
function getStyleTokenNameFromId(id) {
|
|
691
|
+
if (!id) return null;
|
|
692
|
+
const parts = id.split("--");
|
|
693
|
+
const first = normalizeStyleTokenName(parts[0]);
|
|
694
|
+
if (!first) return parts.length > 1 ? normalizeStyleTokenName(parts.slice(1).join("--")) : null;
|
|
695
|
+
return normalizeStyleTokenName([first, ...parts.slice(1)].join("--"));
|
|
696
|
+
}
|
|
697
|
+
function getChildStyleTokenName(name, child) {
|
|
698
|
+
const childName = normalizeStyleTokenName(child);
|
|
699
|
+
if (!childName) return normalizeStyleTokenName(name);
|
|
700
|
+
const parentName = normalizeStyleTokenName(name);
|
|
701
|
+
return parentName ? parentName + "--" + childName : childName;
|
|
702
|
+
}
|
|
703
|
+
function normalizeStyleTokenName(value) {
|
|
704
|
+
if (!value) return null;
|
|
705
|
+
value = value.trim();
|
|
706
|
+
if (!value) return null;
|
|
707
|
+
if (/^\d+$/.test(value)) return null;
|
|
708
|
+
if (isGeneratedTokenHash(value)) return null;
|
|
709
|
+
value = stripGenericTokenPrefix(value);
|
|
710
|
+
if (!value) return null;
|
|
711
|
+
const stableSuffix = value.match(/^(.+)-[a-z0-9]{7}$/);
|
|
712
|
+
if (stableSuffix?.[1] && isGeneratedTokenHash(value.slice(-7))) return normalizeStyleTokenName(stableSuffix[1]);
|
|
713
|
+
return value;
|
|
714
|
+
}
|
|
715
|
+
function isGeneratedTokenHash(value) {
|
|
716
|
+
return /^[a-z0-9]{7}$/.test(value) && /\d/.test(value);
|
|
717
|
+
}
|
|
718
|
+
function stripGenericTokenPrefix(value) {
|
|
719
|
+
const parts = value.split("--");
|
|
720
|
+
while (parts[0] === "token" || parts[0] === "tokens") parts.shift();
|
|
721
|
+
return parts.join("--");
|
|
722
|
+
}
|
|
723
|
+
//#endregion
|
|
724
|
+
//#region style/token.ts
|
|
725
|
+
const TOKEN_DEBUG = symbol("style:token.debug");
|
|
726
|
+
const idCounter$6 = globalData("style.token.idCounter", () => ({ value: 0 }));
|
|
727
|
+
function createStyleToken(value, stableId, debugName) {
|
|
728
|
+
const token = (value, debug) => {
|
|
729
|
+
return createStyleTokenOverride(token, value, debug);
|
|
730
|
+
};
|
|
731
|
+
token[TOKEN_ID] = stableId || String(idCounter$6.value++);
|
|
732
|
+
token[TOKEN_NAME] = debugName === void 0 ? getStyleTokenNameFromId(stableId) : normalizeStyleTokenName(debugName);
|
|
733
|
+
if (isStyleTokenData(value)) {
|
|
734
|
+
token.value = value.value;
|
|
735
|
+
token.ref = value;
|
|
736
|
+
} else {
|
|
737
|
+
token.value = value;
|
|
738
|
+
token.ref = null;
|
|
739
|
+
}
|
|
740
|
+
return token;
|
|
741
|
+
}
|
|
742
|
+
function createStyleTokenOverride(token, value, debug) {
|
|
743
|
+
const override = isStyleTokenData(value) ? {
|
|
744
|
+
[TOKEN_ID]: getStyleTokenId(token),
|
|
745
|
+
[TOKEN_OVERRIDE]: true,
|
|
746
|
+
[TOKEN_NAME]: getStyleTokenName(token),
|
|
747
|
+
value: value.value,
|
|
748
|
+
ref: value
|
|
749
|
+
} : {
|
|
750
|
+
[TOKEN_ID]: getStyleTokenId(token),
|
|
751
|
+
[TOKEN_OVERRIDE]: true,
|
|
752
|
+
[TOKEN_NAME]: getStyleTokenName(token),
|
|
753
|
+
value,
|
|
754
|
+
ref: null
|
|
755
|
+
};
|
|
756
|
+
if (debug) Object.defineProperty(override, TOKEN_DEBUG, {
|
|
757
|
+
configurable: true,
|
|
758
|
+
enumerable: false,
|
|
759
|
+
value: debug
|
|
760
|
+
});
|
|
761
|
+
return override;
|
|
762
|
+
}
|
|
493
763
|
//#endregion
|
|
494
764
|
//#region selector/selector.ts
|
|
495
765
|
function selector(selector, ...args) {
|
|
@@ -602,135 +872,27 @@ const PrioritySelectors = selectorPriority({
|
|
|
602
872
|
"focusWithin",
|
|
603
873
|
"focus",
|
|
604
874
|
"focusVisible",
|
|
605
|
-
"active",
|
|
606
|
-
"disabled"
|
|
607
|
-
]);
|
|
608
|
-
selectorPriority({
|
|
609
|
-
hover: PseudoSelectors.hover,
|
|
610
|
-
active: PseudoSelectors.active,
|
|
611
|
-
focus: PseudoSelectors.focus,
|
|
612
|
-
focusWithin: PseudoSelectors.focusWithin,
|
|
613
|
-
disabled: PseudoSelectors.disabled,
|
|
614
|
-
firstChild: PseudoSelectors.firstChild,
|
|
615
|
-
lastChild: PseudoSelectors.lastChild,
|
|
616
|
-
nthChild: PseudoArgSelectors.nthChild,
|
|
617
|
-
nthOfType: PseudoArgSelectors.nthOfType,
|
|
618
|
-
is: PseudoArgSelectors.is,
|
|
619
|
-
where: PseudoArgSelectors.where,
|
|
620
|
-
not: PseudoArgSelectors.not,
|
|
621
|
-
has: PseudoArgSelectors.has,
|
|
622
|
-
...PseudoElementSelectors,
|
|
623
|
-
...ArgSelectors,
|
|
624
|
-
...AtRuleSelectors
|
|
625
|
-
}, PrioritySelectors);
|
|
626
|
-
//#endregion
|
|
627
|
-
//#region selector/validate.ts
|
|
628
|
-
function isLocalSelector(selector) {
|
|
629
|
-
const groups = parseSelector(selector);
|
|
630
|
-
if (!groups || groups.length !== 1) return false;
|
|
631
|
-
return isSelectorGroupsSelf(groups, false);
|
|
632
|
-
}
|
|
633
|
-
function isPseudoArgSelector(selector) {
|
|
634
|
-
const groups = parseSelector(selector);
|
|
635
|
-
if (!groups || groups.length !== 1) return false;
|
|
636
|
-
return isSelectorGroupsSelf(groups, true);
|
|
637
|
-
}
|
|
638
|
-
function isTagSelector(selector) {
|
|
639
|
-
const groups = parseSelector(selector);
|
|
640
|
-
if (!groups || groups.length !== 1) return false;
|
|
641
|
-
const group = groups[0];
|
|
642
|
-
return group.length === 1 && group[0].type === SelectorType.Tag;
|
|
643
|
-
}
|
|
644
|
-
function isAttrArg(value) {
|
|
645
|
-
if (!value) return false;
|
|
646
|
-
if (value.includes("[") || value.includes("]")) return false;
|
|
647
|
-
return true;
|
|
648
|
-
}
|
|
649
|
-
function isRawValue(value) {
|
|
650
|
-
if (!value) return false;
|
|
651
|
-
if (value.includes("{") || value.includes("}")) return false;
|
|
652
|
-
return true;
|
|
653
|
-
}
|
|
654
|
-
function parseSelector(selector) {
|
|
655
|
-
try {
|
|
656
|
-
return parse(selector);
|
|
657
|
-
} catch {
|
|
658
|
-
return;
|
|
659
|
-
}
|
|
660
|
-
}
|
|
661
|
-
function isSelectorGroupsSelf(groups, allowTag) {
|
|
662
|
-
for (let i = 0; i < groups.length; i++) {
|
|
663
|
-
const group = groups[i];
|
|
664
|
-
for (let j = 0; j < group.length; j++) {
|
|
665
|
-
const token = group[j];
|
|
666
|
-
if (!isAllowedSelectorType(token.type, allowTag)) return false;
|
|
667
|
-
if (token.type === SelectorType.Pseudo && Array.isArray(token.data) && !isSelectorGroupsSelf(token.data, allowTag)) return false;
|
|
668
|
-
}
|
|
669
|
-
}
|
|
670
|
-
return true;
|
|
671
|
-
}
|
|
672
|
-
function isAllowedSelectorType(type, allowTag) {
|
|
673
|
-
return type === SelectorType.Attribute || type === SelectorType.Pseudo || type === SelectorType.PseudoElement || allowTag && type === SelectorType.Tag;
|
|
674
|
-
}
|
|
675
|
-
//#endregion
|
|
676
|
-
//#region selector/assert.ts
|
|
677
|
-
function assertSelector(type, value) {
|
|
678
|
-
assertSelectorNotEmpty(value);
|
|
679
|
-
if (!type) return;
|
|
680
|
-
if (typeof type === "function") return type(value);
|
|
681
|
-
switch (type) {
|
|
682
|
-
case "local": return assertLocalSelector(value);
|
|
683
|
-
case "arg": return assertPseudoArgSelector(value);
|
|
684
|
-
case "tag": return assertTagSelector(value);
|
|
685
|
-
case "attr": return assertAttrSelector(value);
|
|
686
|
-
case "value": return assertRawValue(value);
|
|
687
|
-
case "media": return assertMediaQuery(value);
|
|
688
|
-
case "supports": return assertSupportsQuery(value);
|
|
689
|
-
case "container": return assertContainerQuery(value);
|
|
690
|
-
default: throw new Error("unsupported selector type: " + value);
|
|
691
|
-
}
|
|
692
|
-
}
|
|
693
|
-
const assertSelectorNotEmpty = createSelectorAssert((value) => {
|
|
694
|
-
if (!value) throw new Error("selector cannot be empty");
|
|
695
|
-
});
|
|
696
|
-
const assertLocalSelector = createSelectorAssert((value) => {
|
|
697
|
-
if (!isLocalSelector(value)) throw new Error("selector must target the current element only and cannot contain tags, combinators, or multiple selectors");
|
|
698
|
-
});
|
|
699
|
-
const assertPseudoArgSelector = createSelectorAssert((value) => {
|
|
700
|
-
if (!isPseudoArgSelector(value)) throw new Error("pseudo selector argument must contain only tags or selectors targeting the current element");
|
|
701
|
-
});
|
|
702
|
-
const assertTagSelector = createSelectorAssert((value) => {
|
|
703
|
-
if (!isTagSelector(value)) throw new Error("selector must be a single tag selector");
|
|
704
|
-
});
|
|
705
|
-
const assertAttrSelector = createSelectorAssert((value) => {
|
|
706
|
-
if (!isAttrArg(value)) throw new Error("attribute selector value must not include \"[\" or \"]\"");
|
|
707
|
-
});
|
|
708
|
-
const assertRawValue = createSelectorAssert((value) => {
|
|
709
|
-
if (!isRawValue(value)) throw new Error("value must not contain \"{\" or \"}\"");
|
|
710
|
-
});
|
|
711
|
-
const assertMediaQuery = createSelectorAssert((value) => {
|
|
712
|
-
if (!isRawValue(value)) throw new Error("media query must not contain \"{\" or \"}\"");
|
|
713
|
-
});
|
|
714
|
-
const assertSupportsQuery = createSelectorAssert((value) => {
|
|
715
|
-
if (!isRawValue(value)) throw new Error("supports query must not contain \"{\" or \"}\"");
|
|
716
|
-
});
|
|
717
|
-
const assertContainerQuery = createSelectorAssert((value) => {
|
|
718
|
-
if (!isRawValue(value)) throw new Error("container query must not contain \"{\" or \"}\"");
|
|
719
|
-
});
|
|
720
|
-
//#endregion
|
|
721
|
-
//#region builder/data/check_selector.ts
|
|
722
|
-
function checkSelector(fnPrefix, fnName, fnSelector, arg) {
|
|
723
|
-
let message = null;
|
|
724
|
-
try {
|
|
725
|
-
assertSelector(fnSelector.assert, arg);
|
|
726
|
-
} catch (error) {
|
|
727
|
-
if (typeof error === "string" && error.trim()) message = error;
|
|
728
|
-
else if (typeof error === "object" && error && error instanceof Error) message = (error.message || "").trim();
|
|
729
|
-
else message = "selector is invalid: " + arg;
|
|
730
|
-
}
|
|
731
|
-
if (!message) return;
|
|
732
|
-
throw traceError(`${fnPrefix}${fnName}(${arg || ""}): ${message}`);
|
|
733
|
-
}
|
|
875
|
+
"active",
|
|
876
|
+
"disabled"
|
|
877
|
+
]);
|
|
878
|
+
selectorPriority({
|
|
879
|
+
hover: PseudoSelectors.hover,
|
|
880
|
+
active: PseudoSelectors.active,
|
|
881
|
+
focus: PseudoSelectors.focus,
|
|
882
|
+
focusWithin: PseudoSelectors.focusWithin,
|
|
883
|
+
disabled: PseudoSelectors.disabled,
|
|
884
|
+
firstChild: PseudoSelectors.firstChild,
|
|
885
|
+
lastChild: PseudoSelectors.lastChild,
|
|
886
|
+
nthChild: PseudoArgSelectors.nthChild,
|
|
887
|
+
nthOfType: PseudoArgSelectors.nthOfType,
|
|
888
|
+
is: PseudoArgSelectors.is,
|
|
889
|
+
where: PseudoArgSelectors.where,
|
|
890
|
+
not: PseudoArgSelectors.not,
|
|
891
|
+
has: PseudoArgSelectors.has,
|
|
892
|
+
...PseudoElementSelectors,
|
|
893
|
+
...ArgSelectors,
|
|
894
|
+
...AtRuleSelectors
|
|
895
|
+
}, PrioritySelectors);
|
|
734
896
|
//#endregion
|
|
735
897
|
//#region builder/data/create.ts
|
|
736
898
|
function createStyleData(callsite) {
|
|
@@ -765,6 +927,28 @@ function createSlotOverrideData(callsite, slotId) {
|
|
|
765
927
|
[BUILDER_SLOT_ID]: slotId
|
|
766
928
|
};
|
|
767
929
|
}
|
|
930
|
+
function createSelectorOverrideData(callsite, selectors) {
|
|
931
|
+
return {
|
|
932
|
+
[BUILDER_TYPE]: 8,
|
|
933
|
+
[BUILDER_STATE]: {
|
|
934
|
+
items: [],
|
|
935
|
+
lookup: {}
|
|
936
|
+
},
|
|
937
|
+
[BUILDER_CALLSITE]: callsite,
|
|
938
|
+
[BUILDER_SELECTOR]: selectors
|
|
939
|
+
};
|
|
940
|
+
}
|
|
941
|
+
function createSelectorData(callsite, selectors) {
|
|
942
|
+
return {
|
|
943
|
+
[BUILDER_TYPE]: 7,
|
|
944
|
+
[BUILDER_STATE]: {
|
|
945
|
+
items: [],
|
|
946
|
+
lookup: {}
|
|
947
|
+
},
|
|
948
|
+
[BUILDER_CALLSITE]: callsite,
|
|
949
|
+
[BUILDER_SELECTOR]: selectors
|
|
950
|
+
};
|
|
951
|
+
}
|
|
768
952
|
function createScopeData(callsite) {
|
|
769
953
|
return {
|
|
770
954
|
[BUILDER_TYPE]: 4,
|
|
@@ -803,7 +987,7 @@ function createNameFormatter(keys) {
|
|
|
803
987
|
const name = getFormatFn(format)(info);
|
|
804
988
|
if (!hash) return name;
|
|
805
989
|
if (name.includes(HASH_TOKEN)) return name.replace(HASH_TOKEN, hash);
|
|
806
|
-
return name ? name + "
|
|
990
|
+
return name ? name + "--" + hash : hash;
|
|
807
991
|
};
|
|
808
992
|
}
|
|
809
993
|
function compileFormat(format, keySet) {
|
|
@@ -896,40 +1080,51 @@ const formatClassName = createNameFormatter([
|
|
|
896
1080
|
"selector",
|
|
897
1081
|
"value"
|
|
898
1082
|
]);
|
|
899
|
-
const
|
|
1083
|
+
const formatTransformClassName = createNameFormatter(["className"]);
|
|
900
1084
|
function getDebugClassName(format, hash, info) {
|
|
901
|
-
return formatClassName(format || "[(atRule)-][(scopeSelector)-](property)[-(selector)][-(value)]
|
|
902
|
-
}
|
|
903
|
-
function getDebugScopeClassName(format, info) {
|
|
904
|
-
return formatScopeClassName(format || "-(className)", null, info);
|
|
905
|
-
}
|
|
906
|
-
//#endregion
|
|
907
|
-
//#region atomic/utils/css.ts
|
|
908
|
-
function getCssVar(varName, value) {
|
|
909
|
-
return "var(" + varName + ", " + escapeCssValue(value) + ")";
|
|
1085
|
+
return formatClassName(format || "[(atRule)-][(scopeSelector)-](property)[-(selector)][-(value)]--$hash", hash, info);
|
|
910
1086
|
}
|
|
911
|
-
function
|
|
912
|
-
return
|
|
1087
|
+
function getDebugSheetClassName(format, hash, info) {
|
|
1088
|
+
return formatClassName(format || "sheet-(property)[-(value)]--$hash", hash, info);
|
|
913
1089
|
}
|
|
914
|
-
function
|
|
915
|
-
|
|
916
|
-
return value.trim().replace(/\\/g, "\\\\").replace(/"/g, "\\\"").replace(/'/g, "\\'").replace(/;/g, "\\;");
|
|
1090
|
+
function getDebugTransformClassName(format, hash, info) {
|
|
1091
|
+
return formatTransformClassName(format || "(className)--$hash", hash, info);
|
|
917
1092
|
}
|
|
1093
|
+
//#endregion
|
|
1094
|
+
//#region atomic/utils/cssIdent.ts
|
|
918
1095
|
function escapeCssIdent(ident) {
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
1096
|
+
let result = "";
|
|
1097
|
+
for (let i = 0; i < ident.length; i++) {
|
|
1098
|
+
const char = ident.charAt(i);
|
|
1099
|
+
const code = ident.charCodeAt(i);
|
|
1100
|
+
const nextCode = ident.charCodeAt(i + 1);
|
|
1101
|
+
if (code === 0) {
|
|
1102
|
+
result += "�";
|
|
1103
|
+
continue;
|
|
1104
|
+
}
|
|
1105
|
+
if (code >= 1 && code <= 31 || code === 127 || i === 0 && code >= 48 && code <= 57 || i === 1 && code >= 48 && code <= 57 && ident.charCodeAt(0) === 45) {
|
|
1106
|
+
result += "\\" + code.toString(16) + " ";
|
|
1107
|
+
continue;
|
|
1108
|
+
}
|
|
1109
|
+
if (i === 0 && code === 45 && ident.length === 1) {
|
|
1110
|
+
result += "\\-";
|
|
1111
|
+
continue;
|
|
1112
|
+
}
|
|
1113
|
+
if (code >= 55296 && code <= 56319 && nextCode >= 56320 && nextCode <= 57343) {
|
|
1114
|
+
result += char + ident.charAt(++i);
|
|
1115
|
+
continue;
|
|
1116
|
+
}
|
|
1117
|
+
if (code >= 128 || code === 45 || code === 95 || code >= 48 && code <= 57 || code >= 65 && code <= 90 || code >= 97 && code <= 122) {
|
|
1118
|
+
result += char;
|
|
1119
|
+
continue;
|
|
1120
|
+
}
|
|
1121
|
+
result += "\\" + char;
|
|
1122
|
+
}
|
|
1123
|
+
return result;
|
|
923
1124
|
}
|
|
924
1125
|
function sanitizeCssIdentName(value, fallback = "") {
|
|
925
1126
|
return value.replace(/[^a-zA-Z0-9_-]+/g, "-").replace(/^-+|-+$/g, "") || fallback;
|
|
926
1127
|
}
|
|
927
|
-
function getIdentifierSafeHash(value) {
|
|
928
|
-
const hash = hashString(value);
|
|
929
|
-
const first = hash.charCodeAt(0);
|
|
930
|
-
if (first < 48 || first > 57) return hash;
|
|
931
|
-
return String.fromCharCode(97 + first - 48) + hash.slice(1);
|
|
932
|
-
}
|
|
933
1128
|
//#endregion
|
|
934
1129
|
//#region atomic/utils/debug.ts
|
|
935
1130
|
function normalizeDebugKeywordValue(value) {
|
|
@@ -1086,45 +1281,96 @@ function parseAtRule(rule) {
|
|
|
1086
1281
|
if (normalized.startsWith("@supports")) return compressQuery(normalized.slice(9));
|
|
1087
1282
|
return compressQuery(normalized);
|
|
1088
1283
|
}
|
|
1284
|
+
function getScopeClassName(className, scopeClassNameFormat) {
|
|
1285
|
+
return formatScopeClassName$1(scopeClassNameFormat || "-(className)", { className });
|
|
1286
|
+
}
|
|
1287
|
+
function formatScopeClassName$1(format, info) {
|
|
1288
|
+
if (typeof format === "function") return format(info);
|
|
1289
|
+
return format.replace(/\[|\]/g, "").replace(/\(className\)/g, info.className);
|
|
1290
|
+
}
|
|
1291
|
+
//#endregion
|
|
1292
|
+
//#region atomic/utils/hash.ts
|
|
1293
|
+
function getIdentifierSafeHash(value, startLength = 7) {
|
|
1294
|
+
const normalizedStartLength = normalizeHashLength(startLength);
|
|
1295
|
+
return getIdentifierSafeHashValue(hashString(value)).slice(0, normalizedStartLength);
|
|
1296
|
+
}
|
|
1297
|
+
function getIdentifierSafeHashValue(hash) {
|
|
1298
|
+
const first = hash.charCodeAt(0);
|
|
1299
|
+
if (first < 48 || first > 57) return hash;
|
|
1300
|
+
return String.fromCharCode(97 + first - 48) + hash.slice(1);
|
|
1301
|
+
}
|
|
1089
1302
|
//#endregion
|
|
1090
1303
|
//#region atomic/utils/selector.ts
|
|
1091
|
-
function getSelectorText(selector) {
|
|
1092
|
-
return Array.isArray(selector) ? selector[0] : selector;
|
|
1304
|
+
function getSelectorText$1(selector) {
|
|
1305
|
+
return stripSheetSelectorAnchor(Array.isArray(selector) ? selector[0] : selector);
|
|
1093
1306
|
}
|
|
1094
1307
|
function getSelectorHash(selector) {
|
|
1095
1308
|
return Array.isArray(selector) ? selector.join("|") : selector;
|
|
1096
1309
|
}
|
|
1097
|
-
function getSelectorPriority(selector) {
|
|
1310
|
+
function getSelectorPriority$1(selector) {
|
|
1098
1311
|
if (!selector) return 0;
|
|
1099
1312
|
return Array.isArray(selector) ? selector[1] : 0;
|
|
1100
1313
|
}
|
|
1314
|
+
function hasSheetSelectorAnchor(selector) {
|
|
1315
|
+
return (selector ? Array.isArray(selector) ? selector[0] : selector : "").startsWith(SHEET_SELECTOR_ANCHOR);
|
|
1316
|
+
}
|
|
1317
|
+
function getSheetSelectorWeight(selector) {
|
|
1318
|
+
const text = selector ? Array.isArray(selector) ? selector[0] : selector : "";
|
|
1319
|
+
if (!text.startsWith("\0sheet:")) return null;
|
|
1320
|
+
const end = text.indexOf("\0", 6);
|
|
1321
|
+
if (end < 0) return null;
|
|
1322
|
+
const [weightValue] = text.slice(7, end).split(":");
|
|
1323
|
+
const weight = Number(weightValue);
|
|
1324
|
+
return Number.isInteger(weight) && weight > 0 ? weight : null;
|
|
1325
|
+
}
|
|
1326
|
+
function stripSheetSelectorAnchor(selector) {
|
|
1327
|
+
if (!selector.startsWith("\0sheet")) return selector;
|
|
1328
|
+
if (selector.startsWith("\0sheet:")) {
|
|
1329
|
+
const end = selector.indexOf("\0", 6);
|
|
1330
|
+
if (end >= 0) return selector.slice(end + 1);
|
|
1331
|
+
}
|
|
1332
|
+
return selector.slice(6);
|
|
1333
|
+
}
|
|
1101
1334
|
//#endregion
|
|
1102
1335
|
//#region atomic/className.ts
|
|
1103
|
-
function getAtomicClassName(property, priority, value, selector, parentSelector, atRule, callsite, localClassName, debugClassName, classNameFormat) {
|
|
1336
|
+
function getAtomicClassName(property, priority, important, value, selector, parentSelector, atRule, callsite, localClassName, debugClassName, classNameFormat, transformClassName, transformClassNameFormat, sheetClassNameFormat = null, hashLength = null) {
|
|
1104
1337
|
let hash = property;
|
|
1105
1338
|
hash += "\n" + (priority || "");
|
|
1339
|
+
if (important) hash += "\nimportant";
|
|
1106
1340
|
hash += "\n" + value;
|
|
1107
1341
|
hash += "\n" + (selector ? getSelectorHash(selector) : "");
|
|
1108
1342
|
hash += "\n" + (parentSelector ? getSelectorHash(parentSelector) : "");
|
|
1109
1343
|
hash += "\n" + (atRule ? atRule.map(getSelectorHash).join("\n") : "");
|
|
1110
1344
|
hash += "\n" + getCallsiteHash(callsite, localClassName);
|
|
1111
|
-
hash = getIdentifierSafeHash(hash);
|
|
1345
|
+
hash = getIdentifierSafeHash(hash, hashLength ?? getRuntimeClassNameHashLength(debugClassName));
|
|
1112
1346
|
if (!debugClassName) return hash;
|
|
1347
|
+
if (transformClassName) return getDebugTransformClassName(transformClassNameFormat, hash, { className: transformClassName });
|
|
1113
1348
|
const propertyName = getDebugPropertyName(property, value);
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1349
|
+
const isSheetClassName = hasSheetSelectorAnchor(selector);
|
|
1350
|
+
return (isSheetClassName ? getDebugSheetClassName : getDebugClassName)(isSheetClassName ? sheetClassNameFormat : classNameFormat, hash, {
|
|
1351
|
+
atRule: atRule ? getDebugAtRuleName(atRule.map(getSelectorText$1)) : null,
|
|
1352
|
+
scopeSelector: parentSelector ? getDebugSelectorName(getSelectorText$1(parentSelector)) : null,
|
|
1353
|
+
selector: selector ? getDebugSelectorName(getSelectorText$1(selector)) : null,
|
|
1118
1354
|
property: propertyName ? propertyName.property : property,
|
|
1119
1355
|
value: propertyName ? propertyName.value ?? propertyName.arbitraryValue : null
|
|
1120
1356
|
});
|
|
1121
1357
|
}
|
|
1122
|
-
function
|
|
1123
|
-
return
|
|
1358
|
+
function getRuntimeClassNameHashLength(debugClassName) {
|
|
1359
|
+
return getClassNameHashLength({
|
|
1360
|
+
debugClassName,
|
|
1361
|
+
isDev: DEV_CONFIG.isDev,
|
|
1362
|
+
devHashLength: DEV_CONFIG.hashLength,
|
|
1363
|
+
cssHashLength: CSS_CONFIG.hashLength
|
|
1364
|
+
});
|
|
1365
|
+
}
|
|
1366
|
+
function getClassNameHashLength(options) {
|
|
1367
|
+
if (options.debugClassName && options.isDev) return options.devHashLength ?? options.cssHashLength ?? 5;
|
|
1368
|
+
return options.cssHashLength ?? 7;
|
|
1124
1369
|
}
|
|
1125
|
-
function getClassNameDedupe(property, priority, selector, parentSelector, atRule) {
|
|
1370
|
+
function getClassNameDedupe(property, priority, important, selector, parentSelector, atRule) {
|
|
1126
1371
|
let hash = property;
|
|
1127
1372
|
hash += "\n" + (priority || "");
|
|
1373
|
+
if (important) hash += "\nimportant";
|
|
1128
1374
|
hash += "\n" + (selector ? getSelectorHash(selector) : "");
|
|
1129
1375
|
hash += "\n" + (parentSelector ? getSelectorHash(parentSelector) : "");
|
|
1130
1376
|
hash += "\n" + (atRule ? atRule.map(getSelectorHash).join("\n") : "");
|
|
@@ -1161,7 +1407,8 @@ function mergeScopeData(scope, callsite, items, debug, parentSelector, scopeAtRu
|
|
|
1161
1407
|
let source;
|
|
1162
1408
|
let item;
|
|
1163
1409
|
let lookupIndex;
|
|
1164
|
-
let
|
|
1410
|
+
let weight;
|
|
1411
|
+
let important;
|
|
1165
1412
|
let value;
|
|
1166
1413
|
let atRule;
|
|
1167
1414
|
let dedupe;
|
|
@@ -1172,7 +1419,7 @@ function mergeScopeData(scope, callsite, items, debug, parentSelector, scopeAtRu
|
|
|
1172
1419
|
source = sourceItems[i];
|
|
1173
1420
|
if (!source) continue;
|
|
1174
1421
|
if (isStyleTokenOverrideData(source)) {
|
|
1175
|
-
addTokenOverride(source, styles, lookup);
|
|
1422
|
+
addTokenOverride$1(source, styles, lookup);
|
|
1176
1423
|
continue;
|
|
1177
1424
|
}
|
|
1178
1425
|
if (isScopeData(source)) {
|
|
@@ -1180,7 +1427,7 @@ function mergeScopeData(scope, callsite, items, debug, parentSelector, scopeAtRu
|
|
|
1180
1427
|
for (let j = 0, len = scopeItems.length; j < len; j++) {
|
|
1181
1428
|
item = scopeItems[j];
|
|
1182
1429
|
if (isStyleTokenOverrideData(item)) {
|
|
1183
|
-
addTokenOverride(item, styles, lookup);
|
|
1430
|
+
addTokenOverride$1(item, styles, lookup);
|
|
1184
1431
|
continue;
|
|
1185
1432
|
}
|
|
1186
1433
|
if (Array.isArray(item) || item.type !== 4) {
|
|
@@ -1201,13 +1448,10 @@ function mergeScopeData(scope, callsite, items, debug, parentSelector, scopeAtRu
|
|
|
1201
1448
|
itemDebug = getMergedScopeDebug(debug, scopeItem);
|
|
1202
1449
|
itemCallsite = getDebugFieldCallsite(itemDebug ?? null, scopeItem.property) ?? callsite ?? scopeItem.callsite;
|
|
1203
1450
|
value = scopeItem.value;
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
}
|
|
1209
|
-
dedupe = getClassNameDedupe(scopeItem.property, priority, scopeItem.selector, scopeItem.parentSelector, scopeItem.atRule);
|
|
1210
|
-
className = getAtomicClassName(scopeItem.property, priority, value, scopeItem.selector, scopeItem.parentSelector, scopeItem.atRule, itemCallsite, DEV_CONFIG.isLocalClassNameEnabled, DEBUG_CONFIG.isDebugClassNameEnabled, CSS_CONFIG.classNameFormat ?? null);
|
|
1451
|
+
weight = scopeItem.weight;
|
|
1452
|
+
important = scopeItem.important;
|
|
1453
|
+
dedupe = getClassNameDedupe(scopeItem.property, weight, important, scopeItem.selector, scopeItem.parentSelector, scopeItem.atRule);
|
|
1454
|
+
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);
|
|
1211
1455
|
scopeItem.dedupe = dedupe;
|
|
1212
1456
|
scopeItem.className = className;
|
|
1213
1457
|
scopeItem.callsite = itemCallsite;
|
|
@@ -1244,7 +1488,10 @@ function mergeScopeData(scope, callsite, items, debug, parentSelector, scopeAtRu
|
|
|
1244
1488
|
dedupe: "",
|
|
1245
1489
|
className: "",
|
|
1246
1490
|
property: overrideItem.property,
|
|
1491
|
+
weight: overrideItem.weight,
|
|
1492
|
+
important: overrideItem.important,
|
|
1247
1493
|
value: overrideItem.value,
|
|
1494
|
+
transformClassName: overrideItem.transformClassName,
|
|
1248
1495
|
token: overrideItem.token,
|
|
1249
1496
|
selector: overrideItem.selector,
|
|
1250
1497
|
atRule,
|
|
@@ -1254,13 +1501,10 @@ function mergeScopeData(scope, callsite, items, debug, parentSelector, scopeAtRu
|
|
|
1254
1501
|
parentSelector
|
|
1255
1502
|
};
|
|
1256
1503
|
value = scopeItem.value;
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
}
|
|
1262
|
-
dedupe = getClassNameDedupe(scopeItem.property, priority, scopeItem.selector, parentSelector, scopeItem.atRule);
|
|
1263
|
-
className = getAtomicClassName(scopeItem.property, priority, value, scopeItem.selector, parentSelector, scopeItem.atRule, scopeItem.callsite, DEV_CONFIG.isLocalClassNameEnabled, DEBUG_CONFIG.isDebugClassNameEnabled, CSS_CONFIG.classNameFormat ?? null);
|
|
1504
|
+
weight = scopeItem.weight;
|
|
1505
|
+
important = scopeItem.important;
|
|
1506
|
+
dedupe = getClassNameDedupe(scopeItem.property, weight, important, scopeItem.selector, parentSelector, scopeItem.atRule);
|
|
1507
|
+
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);
|
|
1264
1508
|
scopeItem.dedupe = dedupe;
|
|
1265
1509
|
scopeItem.className = className;
|
|
1266
1510
|
const lookupKey = getScopeLookupKey(slotId, dedupe);
|
|
@@ -1271,7 +1515,7 @@ function mergeScopeData(scope, callsite, items, debug, parentSelector, scopeAtRu
|
|
|
1271
1515
|
}
|
|
1272
1516
|
return data;
|
|
1273
1517
|
}
|
|
1274
|
-
function addTokenOverride(item, styles, lookup) {
|
|
1518
|
+
function addTokenOverride$1(item, styles, lookup) {
|
|
1275
1519
|
const lookupKey = getTokenLookupKey(getStyleTokenId(item));
|
|
1276
1520
|
const lookupIndex = lookup[lookupKey];
|
|
1277
1521
|
if (typeof lookupIndex === "number") styles[lookupIndex] = item;
|
|
@@ -1325,10 +1569,23 @@ function getScopeLookupKey(slotId, dedupe) {
|
|
|
1325
1569
|
function getTokenLookupKey(tokenId) {
|
|
1326
1570
|
return "token\0" + tokenId;
|
|
1327
1571
|
}
|
|
1572
|
+
//#endregion
|
|
1573
|
+
//#region atomic/utils/cssVar.ts
|
|
1574
|
+
function getCssVar(varName, value) {
|
|
1575
|
+
return "var(" + varName + ", " + escapeCssValue(value) + ")";
|
|
1576
|
+
}
|
|
1577
|
+
function getCssVarRawFallback(varName, fallbackCss) {
|
|
1578
|
+
return "var(" + varName + ", " + fallbackCss + ")";
|
|
1579
|
+
}
|
|
1580
|
+
function escapeCssValue(value) {
|
|
1581
|
+
if (!value) return "";
|
|
1582
|
+
return value.trim().replace(/\\/g, "\\\\").replace(/"/g, "\\\"").replace(/'/g, "\\'").replace(/;/g, "\\;");
|
|
1583
|
+
}
|
|
1328
1584
|
const formatTokenName = createNameFormatter(["name"]);
|
|
1329
1585
|
function getTokenVarName(token, format) {
|
|
1330
1586
|
const id = getStyleTokenId(token);
|
|
1331
|
-
|
|
1587
|
+
const debugName = getStyleTokenName(token);
|
|
1588
|
+
return "--" + formatTokenName(format || "token[-(name)]-$hash", getIdentifierSafeHash(id, CSS_CONFIG.hashLength), { name: debugName });
|
|
1332
1589
|
}
|
|
1333
1590
|
function getTokenVar(token, format) {
|
|
1334
1591
|
return getTokenVarFallback(token, format);
|
|
@@ -1403,6 +1660,31 @@ function shouldAppendCssPx(property) {
|
|
|
1403
1660
|
return !UNITLESS.has(property);
|
|
1404
1661
|
}
|
|
1405
1662
|
//#endregion
|
|
1663
|
+
//#region style/important.ts
|
|
1664
|
+
const STYLE_IMPORTANT = symbol("style.important");
|
|
1665
|
+
function importantValue(value) {
|
|
1666
|
+
return {
|
|
1667
|
+
[STYLE_IMPORTANT]: true,
|
|
1668
|
+
value
|
|
1669
|
+
};
|
|
1670
|
+
}
|
|
1671
|
+
function isStyleImportantValue(value) {
|
|
1672
|
+
return !!value && typeof value === "object" && value[STYLE_IMPORTANT] === true;
|
|
1673
|
+
}
|
|
1674
|
+
//#endregion
|
|
1675
|
+
//#region style/transform.ts
|
|
1676
|
+
const CLASS_NAME_VALUE = symbol("transform.classNameValue");
|
|
1677
|
+
function classNameValue(value, className) {
|
|
1678
|
+
return {
|
|
1679
|
+
[CLASS_NAME_VALUE]: true,
|
|
1680
|
+
value,
|
|
1681
|
+
className
|
|
1682
|
+
};
|
|
1683
|
+
}
|
|
1684
|
+
function isClassNameValue(value) {
|
|
1685
|
+
return !!value && typeof value === "object" && value[CLASS_NAME_VALUE] === true && typeof value.className === "string";
|
|
1686
|
+
}
|
|
1687
|
+
//#endregion
|
|
1406
1688
|
//#region style/valueRef.ts
|
|
1407
1689
|
const AT_RULE_REF = symbol("atRule.ref");
|
|
1408
1690
|
function createAtRuleRef(data) {
|
|
@@ -1415,6 +1697,19 @@ function isAtRuleRef(value) {
|
|
|
1415
1697
|
return !!value && typeof value === "object" && value[AT_RULE_REF] === true;
|
|
1416
1698
|
}
|
|
1417
1699
|
//#endregion
|
|
1700
|
+
//#region style/weight.ts
|
|
1701
|
+
const STYLE_WEIGHT = symbol("style.weight");
|
|
1702
|
+
function weightValue(value, weight) {
|
|
1703
|
+
return {
|
|
1704
|
+
[STYLE_WEIGHT]: true,
|
|
1705
|
+
value,
|
|
1706
|
+
weight
|
|
1707
|
+
};
|
|
1708
|
+
}
|
|
1709
|
+
function isStyleWeightValue(value) {
|
|
1710
|
+
return !!value && typeof value === "object" && value[STYLE_WEIGHT] === true;
|
|
1711
|
+
}
|
|
1712
|
+
//#endregion
|
|
1418
1713
|
//#region builder/data/merge/style.ts
|
|
1419
1714
|
function mergeBuilderData(create, callsite, source, style, debug, selector, atRule, type) {
|
|
1420
1715
|
if (!style) return source;
|
|
@@ -1425,13 +1720,15 @@ function mergeBuilderData(create, callsite, source, style, debug, selector, atRu
|
|
|
1425
1720
|
let itemData;
|
|
1426
1721
|
let valueRaw;
|
|
1427
1722
|
let value;
|
|
1428
|
-
let
|
|
1723
|
+
let weight;
|
|
1724
|
+
let important;
|
|
1429
1725
|
let itemCallsite;
|
|
1430
1726
|
let className;
|
|
1431
1727
|
let dedupe;
|
|
1432
1728
|
let token;
|
|
1433
1729
|
let ref;
|
|
1434
1730
|
let variableName;
|
|
1731
|
+
let transformClassName;
|
|
1435
1732
|
let lookupIndex;
|
|
1436
1733
|
if (isStyleData(style)) {
|
|
1437
1734
|
const stylesItems = style[BUILDER_STATE].items;
|
|
@@ -1445,6 +1742,7 @@ function mergeBuilderData(create, callsite, source, style, debug, selector, atRu
|
|
|
1445
1742
|
continue;
|
|
1446
1743
|
}
|
|
1447
1744
|
if (atRule) item = Object.assign({}, item, { atRule: item.atRule ? atRule.concat(item.atRule) : atRule });
|
|
1745
|
+
if (selector) item = Object.assign({}, item, { selector: item.selector ? combineSelectors$1(selector, item.selector) : selector });
|
|
1448
1746
|
if (type === 2 && slotId !== null) item = Object.assign({}, item, {
|
|
1449
1747
|
type: 2,
|
|
1450
1748
|
slotId
|
|
@@ -1453,6 +1751,7 @@ function mergeBuilderData(create, callsite, source, style, debug, selector, atRu
|
|
|
1453
1751
|
type: 3,
|
|
1454
1752
|
slotId
|
|
1455
1753
|
});
|
|
1754
|
+
else if (type === 8) item = Object.assign({}, item, { type: 1 });
|
|
1456
1755
|
const itemDebug = getMergedStyleDebug(debug, item);
|
|
1457
1756
|
const debugCallsite = getDebugFieldCallsite(itemDebug, item.property);
|
|
1458
1757
|
if (debugCallsite) item = Object.assign({}, item, {
|
|
@@ -1464,17 +1763,19 @@ function mergeBuilderData(create, callsite, source, style, debug, selector, atRu
|
|
|
1464
1763
|
}
|
|
1465
1764
|
} else for (const property in style) {
|
|
1466
1765
|
valueRaw = style[property];
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1766
|
+
[valueRaw, weight, important] = unwrapAuthoredStyleValue(valueRaw);
|
|
1767
|
+
const sourceType = source[BUILDER_TYPE];
|
|
1768
|
+
checkImportantUsage(valueRaw, important, sourceType === 9 || sourceType === 8);
|
|
1769
|
+
transformClassName = null;
|
|
1770
|
+
if (isClassNameValue(valueRaw)) {
|
|
1771
|
+
transformClassName = valueRaw.className;
|
|
1772
|
+
valueRaw = valueRaw.value;
|
|
1471
1773
|
}
|
|
1472
1774
|
ref = isAtRuleRef(valueRaw) ? valueRaw : null;
|
|
1473
1775
|
if (ref) valueRaw = ref.value;
|
|
1474
1776
|
token = isStyleTokenData(valueRaw) ? valueRaw : null;
|
|
1475
1777
|
variableName = getDebugFieldVarName(debug, property);
|
|
1476
1778
|
value = variableName && token ? getCssVarRawFallback(variableName, getTokenVar(token, CSS_CONFIG.tokenNameFormat ?? null)) : token ? getTokenVar(token, CSS_CONFIG.tokenNameFormat ?? null) : String(valueRaw ?? "");
|
|
1477
|
-
value = priority !== null ? [value, priority] : value;
|
|
1478
1779
|
itemCallsite = getDebugFieldCallsite(debug, property) ?? callsite;
|
|
1479
1780
|
itemData = {
|
|
1480
1781
|
runtime: runtimeType,
|
|
@@ -1483,7 +1784,10 @@ function mergeBuilderData(create, callsite, source, style, debug, selector, atRu
|
|
|
1483
1784
|
dedupe: "",
|
|
1484
1785
|
className: "",
|
|
1485
1786
|
property,
|
|
1787
|
+
weight,
|
|
1788
|
+
important,
|
|
1486
1789
|
value,
|
|
1790
|
+
transformClassName,
|
|
1487
1791
|
variable: ref ? [3, ref] : variableName && token ? [
|
|
1488
1792
|
1,
|
|
1489
1793
|
variableName,
|
|
@@ -1495,7 +1799,7 @@ function mergeBuilderData(create, callsite, source, style, debug, selector, atRu
|
|
|
1495
1799
|
atRule,
|
|
1496
1800
|
callsite: itemCallsite
|
|
1497
1801
|
};
|
|
1498
|
-
if (type === 1) {
|
|
1802
|
+
if (type === 1 || type === 8) {
|
|
1499
1803
|
items.push({
|
|
1500
1804
|
...itemData,
|
|
1501
1805
|
type: 1
|
|
@@ -1542,13 +1846,10 @@ function mergeBuilderData(create, callsite, source, style, debug, selector, atRu
|
|
|
1542
1846
|
}
|
|
1543
1847
|
const runtimeItem = item;
|
|
1544
1848
|
value = runtimeItem.value;
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
}
|
|
1550
|
-
dedupe = getClassNameDedupe(runtimeItem.property, priority, runtimeItem.selector, null, runtimeItem.atRule);
|
|
1551
|
-
className = getAtomicClassName(runtimeItem.property, priority, value, runtimeItem.selector, null, runtimeItem.atRule, runtimeItem.callsite, DEV_CONFIG.isLocalClassNameEnabled, DEBUG_CONFIG.isDebugClassNameEnabled, CSS_CONFIG.classNameFormat ?? null);
|
|
1849
|
+
weight = runtimeItem.weight;
|
|
1850
|
+
important = runtimeItem.important;
|
|
1851
|
+
dedupe = getClassNameDedupe(runtimeItem.property, weight, important, runtimeItem.selector, null, runtimeItem.atRule);
|
|
1852
|
+
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);
|
|
1552
1853
|
runtimeItem.dedupe = dedupe;
|
|
1553
1854
|
runtimeItem.className = className;
|
|
1554
1855
|
lookupIndex = lookup[dedupe];
|
|
@@ -1557,6 +1858,52 @@ function mergeBuilderData(create, callsite, source, style, debug, selector, atRu
|
|
|
1557
1858
|
}
|
|
1558
1859
|
return data;
|
|
1559
1860
|
}
|
|
1861
|
+
function unwrapAuthoredStyleValue(value) {
|
|
1862
|
+
let weight = null;
|
|
1863
|
+
let important = false;
|
|
1864
|
+
while (true) {
|
|
1865
|
+
if (isStyleImportantValue(value)) {
|
|
1866
|
+
important = true;
|
|
1867
|
+
value = value.value;
|
|
1868
|
+
continue;
|
|
1869
|
+
}
|
|
1870
|
+
if (isStyleWeightValue(value)) {
|
|
1871
|
+
weight = value.weight;
|
|
1872
|
+
value = value.value;
|
|
1873
|
+
continue;
|
|
1874
|
+
}
|
|
1875
|
+
break;
|
|
1876
|
+
}
|
|
1877
|
+
return [
|
|
1878
|
+
value,
|
|
1879
|
+
weight,
|
|
1880
|
+
important
|
|
1881
|
+
];
|
|
1882
|
+
}
|
|
1883
|
+
function checkImportantUsage(value, important, isSheet) {
|
|
1884
|
+
const options = CHECK_CONFIG.important;
|
|
1885
|
+
if (!options) return;
|
|
1886
|
+
if (typeof value === "string" && /!\s*important\b/i.test(value)) reportImportantCheck(options.rawValue, "Do not write raw \"!important\" values. Wrap the value with style.important(...) instead.");
|
|
1887
|
+
if (important && !isSheet) reportImportantCheck(options.outsideSheet, "style.important(...) outside createSheet is discouraged. Prefer style.weight(...) for Fluentic style priority.");
|
|
1888
|
+
}
|
|
1889
|
+
function reportImportantCheck(level, message) {
|
|
1890
|
+
if (!level) return;
|
|
1891
|
+
if (level === "error") throw new Error(message);
|
|
1892
|
+
if (DEV_CONFIG.isDev) console.warn("[fluentic-style] " + message);
|
|
1893
|
+
}
|
|
1894
|
+
function combineSelectors$1(parent, child) {
|
|
1895
|
+
const parentText = getSelectorText(parent);
|
|
1896
|
+
const childText = getSelectorText(child);
|
|
1897
|
+
const priority = Math.max(getSelectorPriority(parent), getSelectorPriority(child));
|
|
1898
|
+
const selector = parentText + childText;
|
|
1899
|
+
return priority > 0 ? [selector, priority] : selector;
|
|
1900
|
+
}
|
|
1901
|
+
function getSelectorText(selector) {
|
|
1902
|
+
return Array.isArray(selector) ? selector[0] : selector;
|
|
1903
|
+
}
|
|
1904
|
+
function getSelectorPriority(selector) {
|
|
1905
|
+
return Array.isArray(selector) ? selector[1] : 0;
|
|
1906
|
+
}
|
|
1560
1907
|
function getMergedStyleDebug(debug, item) {
|
|
1561
1908
|
if (!debug) return null;
|
|
1562
1909
|
if (debug.fields?.[item.property]) return debug;
|
|
@@ -1600,29 +1947,189 @@ function withDebugSource$1(loc, debug) {
|
|
|
1600
1947
|
];
|
|
1601
1948
|
}
|
|
1602
1949
|
//#endregion
|
|
1603
|
-
//#region builder/
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
const
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1950
|
+
//#region builder/selector_override_core.ts
|
|
1951
|
+
function normalizeManualSelectors$1(input, assertManualSelector) {
|
|
1952
|
+
const selectors = Array.isArray(input) ? input : [input];
|
|
1953
|
+
if (!selectors.length) throw new Error("selector array cannot be empty");
|
|
1954
|
+
return selectors.flatMap((selector) => normalizeManualSelector(selector, assertManualSelector));
|
|
1955
|
+
}
|
|
1956
|
+
function assertManualSelectorSyntax(selector) {
|
|
1957
|
+
if (!selector) throw new Error("selector cannot be empty");
|
|
1958
|
+
if (selector.includes("{") || selector.includes("}")) throw new Error("selector must not contain \"{\" or \"}\"");
|
|
1959
|
+
if (selector.includes(",")) throw new Error("selector must not contain \",\"; use an array of selectors instead");
|
|
1960
|
+
const ampersandIndex = selector.indexOf("&");
|
|
1961
|
+
if (ampersandIndex > 0) throw new Error("selector can only use \"&\" at the beginning");
|
|
1962
|
+
const ampersandSelector = selector.startsWith("&?") ? selector.slice(2) : selector.slice(1);
|
|
1963
|
+
if (ampersandIndex === 0 && ampersandSelector && /^\s/.test(ampersandSelector)) throw new Error("selector cannot have whitespace after \"&\"; omit \"&\" for descendant selectors");
|
|
1964
|
+
}
|
|
1965
|
+
function setSheetSelectorOptions(selector, options) {
|
|
1966
|
+
if (options.weight === void 0 && options.layer === void 0) return selector;
|
|
1967
|
+
const text = Array.isArray(selector) ? selector[0] : selector;
|
|
1968
|
+
const weighted = SHEET_SELECTOR_ANCHOR + (":" + (options.weight ?? "") + ":" + (options.layer === void 0 ? "" : options.layer ? "1" : "0")) + "\0" + text.slice(6);
|
|
1969
|
+
return Array.isArray(selector) ? [weighted, selector[1]] : weighted;
|
|
1970
|
+
}
|
|
1971
|
+
function normalizeManualSelector(selector, assertManualSelector) {
|
|
1972
|
+
const value = selector.trim();
|
|
1973
|
+
assertManualSelector(value);
|
|
1974
|
+
if (value.startsWith("&?")) {
|
|
1975
|
+
const suffix = value.slice(2);
|
|
1976
|
+
return suffix ? [SHEET_SELECTOR_ANCHOR + suffix, "\0sheet " + suffix] : [SHEET_SELECTOR_ANCHOR];
|
|
1977
|
+
}
|
|
1978
|
+
return [SHEET_SELECTOR_ANCHOR + (value.startsWith("&") ? value.slice(1) : " " + value)];
|
|
1979
|
+
}
|
|
1980
|
+
//#endregion
|
|
1981
|
+
//#region builder/selector_override.ts
|
|
1982
|
+
function normalizeManualSelectors(input) {
|
|
1983
|
+
return normalizeManualSelectors$1(input, assertManualSelector);
|
|
1984
|
+
}
|
|
1985
|
+
function assertManualSelector(selector) {
|
|
1986
|
+
assertManualSelectorSyntax(selector);
|
|
1987
|
+
const ampersandIndex = selector.indexOf("&");
|
|
1988
|
+
const ampersandSelector = selector.startsWith("&?") ? selector.slice(2) : selector.slice(1);
|
|
1989
|
+
const parsedSelector = ampersandIndex === 0 ? "*" + ampersandSelector : selector;
|
|
1990
|
+
try {
|
|
1991
|
+
parse(parsedSelector);
|
|
1992
|
+
} catch {
|
|
1993
|
+
throw new Error("selector is invalid: " + selector);
|
|
1994
|
+
}
|
|
1995
|
+
}
|
|
1996
|
+
//#endregion
|
|
1997
|
+
//#region builder/style_data.ts
|
|
1998
|
+
const mergeStyleCreate = (callsite) => {
|
|
1999
|
+
return createStyleData(callsite);
|
|
2000
|
+
};
|
|
2001
|
+
const mergeStyleData = createMerge(mergeStyleCreate, 1);
|
|
2002
|
+
const mergeSlotCreate = (callsite, data) => {
|
|
2003
|
+
return createSlotData(callsite, data[BUILDER_SLOT_ID]);
|
|
2004
|
+
};
|
|
2005
|
+
const mergeSlotData = createMerge(mergeSlotCreate, 2);
|
|
2006
|
+
const mergeSlotOverrideCreate = (callsite, data) => {
|
|
2007
|
+
return createSlotOverrideData(callsite, data[BUILDER_SLOT_ID]);
|
|
2008
|
+
};
|
|
2009
|
+
const mergeSlotOverrideData = createMerge(mergeSlotOverrideCreate, 3);
|
|
2010
|
+
const mergeSelectorOverrideCreate = (callsite, data) => {
|
|
2011
|
+
return createSelectorOverrideData(callsite, data[BUILDER_SELECTOR]);
|
|
2012
|
+
};
|
|
2013
|
+
const mergeSelectorOverrideData = createMerge(mergeSelectorOverrideCreate, 8);
|
|
2014
|
+
function createMerge(create, type) {
|
|
2015
|
+
return (data, callsite, style, debug, selector, atRule) => {
|
|
2016
|
+
return mergeBuilderData(create, callsite, data, style, debug, selector, atRule, type);
|
|
2017
|
+
};
|
|
2018
|
+
}
|
|
2019
|
+
//#endregion
|
|
2020
|
+
//#region selector/validate.ts
|
|
2021
|
+
function isLocalSelector(selector) {
|
|
2022
|
+
const groups = parseSelector(selector);
|
|
2023
|
+
if (!groups || groups.length !== 1) return false;
|
|
2024
|
+
return isSelectorGroupsSelf(groups, false);
|
|
2025
|
+
}
|
|
2026
|
+
function isPseudoArgSelector(selector) {
|
|
2027
|
+
const groups = parseSelector(selector);
|
|
2028
|
+
if (!groups || groups.length !== 1) return false;
|
|
2029
|
+
return isSelectorGroupsSelf(groups, true);
|
|
2030
|
+
}
|
|
2031
|
+
function isTagSelector(selector) {
|
|
2032
|
+
const groups = parseSelector(selector);
|
|
2033
|
+
if (!groups || groups.length !== 1) return false;
|
|
2034
|
+
const group = groups[0];
|
|
2035
|
+
return group.length === 1 && group[0].type === SelectorType.Tag;
|
|
2036
|
+
}
|
|
2037
|
+
function isAttrArg(value) {
|
|
2038
|
+
if (!value) return false;
|
|
2039
|
+
if (value.includes("[") || value.includes("]")) return false;
|
|
2040
|
+
return true;
|
|
2041
|
+
}
|
|
2042
|
+
function isRawValue(value) {
|
|
2043
|
+
if (!value) return false;
|
|
2044
|
+
if (value.includes("{") || value.includes("}")) return false;
|
|
2045
|
+
return true;
|
|
2046
|
+
}
|
|
2047
|
+
function parseSelector(selector) {
|
|
2048
|
+
try {
|
|
2049
|
+
return parse(selector);
|
|
2050
|
+
} catch {
|
|
2051
|
+
return;
|
|
2052
|
+
}
|
|
2053
|
+
}
|
|
2054
|
+
function isSelectorGroupsSelf(groups, allowTag) {
|
|
2055
|
+
for (let i = 0; i < groups.length; i++) {
|
|
2056
|
+
const group = groups[i];
|
|
2057
|
+
for (let j = 0; j < group.length; j++) {
|
|
2058
|
+
const token = group[j];
|
|
2059
|
+
if (!isAllowedSelectorType(token.type, allowTag)) return false;
|
|
2060
|
+
if (token.type === SelectorType.Pseudo && Array.isArray(token.data) && !isSelectorGroupsSelf(token.data, allowTag)) return false;
|
|
2061
|
+
}
|
|
2062
|
+
}
|
|
2063
|
+
return true;
|
|
2064
|
+
}
|
|
2065
|
+
function isAllowedSelectorType(type, allowTag) {
|
|
2066
|
+
return type === SelectorType.Attribute || type === SelectorType.Pseudo || type === SelectorType.PseudoElement || allowTag && type === SelectorType.Tag;
|
|
2067
|
+
}
|
|
2068
|
+
//#endregion
|
|
2069
|
+
//#region selector/assert.ts
|
|
2070
|
+
function assertSelector(type, value) {
|
|
2071
|
+
assertSelectorNotEmpty(value);
|
|
2072
|
+
if (!type) return;
|
|
2073
|
+
if (typeof type === "function") return type(value);
|
|
2074
|
+
switch (type) {
|
|
2075
|
+
case "local": return assertLocalSelector(value);
|
|
2076
|
+
case "arg": return assertPseudoArgSelector(value);
|
|
2077
|
+
case "tag": return assertTagSelector(value);
|
|
2078
|
+
case "attr": return assertAttrSelector(value);
|
|
2079
|
+
case "value": return assertRawValue(value);
|
|
2080
|
+
case "media": return assertMediaQuery(value);
|
|
2081
|
+
case "supports": return assertSupportsQuery(value);
|
|
2082
|
+
case "container": return assertContainerQuery(value);
|
|
2083
|
+
default: throw new Error("unsupported selector type: " + value);
|
|
2084
|
+
}
|
|
2085
|
+
}
|
|
2086
|
+
const assertSelectorNotEmpty = createSelectorAssert((value) => {
|
|
2087
|
+
if (!value) throw new Error("selector cannot be empty");
|
|
2088
|
+
});
|
|
2089
|
+
const assertLocalSelector = createSelectorAssert((value) => {
|
|
2090
|
+
if (!isLocalSelector(value)) throw new Error("selector must target the current element only and cannot contain tags, combinators, or multiple selectors");
|
|
2091
|
+
});
|
|
2092
|
+
const assertPseudoArgSelector = createSelectorAssert((value) => {
|
|
2093
|
+
if (!isPseudoArgSelector(value)) throw new Error("pseudo selector argument must contain only tags or selectors targeting the current element");
|
|
2094
|
+
});
|
|
2095
|
+
const assertTagSelector = createSelectorAssert((value) => {
|
|
2096
|
+
if (!isTagSelector(value)) throw new Error("selector must be a single tag selector");
|
|
2097
|
+
});
|
|
2098
|
+
const assertAttrSelector = createSelectorAssert((value) => {
|
|
2099
|
+
if (!isAttrArg(value)) throw new Error("attribute selector value must not include \"[\" or \"]\"");
|
|
2100
|
+
});
|
|
2101
|
+
const assertRawValue = createSelectorAssert((value) => {
|
|
2102
|
+
if (!isRawValue(value)) throw new Error("value must not contain \"{\" or \"}\"");
|
|
2103
|
+
});
|
|
2104
|
+
const assertMediaQuery = createSelectorAssert((value) => {
|
|
2105
|
+
if (!isRawValue(value)) throw new Error("media query must not contain \"{\" or \"}\"");
|
|
2106
|
+
});
|
|
2107
|
+
const assertSupportsQuery = createSelectorAssert((value) => {
|
|
2108
|
+
if (!isRawValue(value)) throw new Error("supports query must not contain \"{\" or \"}\"");
|
|
2109
|
+
});
|
|
2110
|
+
const assertContainerQuery = createSelectorAssert((value) => {
|
|
2111
|
+
if (!isRawValue(value)) throw new Error("container query must not contain \"{\" or \"}\"");
|
|
2112
|
+
});
|
|
2113
|
+
//#endregion
|
|
2114
|
+
//#region builder/data/check_selector.ts
|
|
2115
|
+
function checkSelector(fnPrefix, fnName, fnSelector, arg) {
|
|
2116
|
+
let message = null;
|
|
2117
|
+
try {
|
|
2118
|
+
assertSelector(fnSelector.assert, arg);
|
|
2119
|
+
} catch (error) {
|
|
2120
|
+
if (typeof error === "string" && error.trim()) message = error;
|
|
2121
|
+
else if (typeof error === "object" && error && error instanceof Error) message = (error.message || "").trim();
|
|
2122
|
+
else message = "selector is invalid: " + arg;
|
|
2123
|
+
}
|
|
2124
|
+
if (!message) return;
|
|
2125
|
+
throw traceError(`${fnPrefix}${fnName}(${arg || ""}): ${message}`);
|
|
1620
2126
|
}
|
|
1621
2127
|
//#endregion
|
|
1622
2128
|
//#region builder/utils.ts
|
|
1623
2129
|
const FnPrefixStyle = "style.";
|
|
1624
2130
|
const FnPrefixSlot = "slot.";
|
|
1625
2131
|
const FnPrefixScope = "scope.";
|
|
2132
|
+
const FnPrefixSelector = "selector.";
|
|
1626
2133
|
function runtimeCallsite() {
|
|
1627
2134
|
return traceCallsite();
|
|
1628
2135
|
}
|
|
@@ -1683,9 +2190,9 @@ function createAtRuleFn(mergeData, fns, createFnResult, fnPrefix, fnName, fnSele
|
|
|
1683
2190
|
let arg;
|
|
1684
2191
|
let style;
|
|
1685
2192
|
let debug;
|
|
1686
|
-
let
|
|
2193
|
+
let weight = null;
|
|
1687
2194
|
if (hasArg) if (isMedia && typeof params[0] === "number") {
|
|
1688
|
-
|
|
2195
|
+
weight = params[0];
|
|
1689
2196
|
arg = params[1];
|
|
1690
2197
|
style = params[2];
|
|
1691
2198
|
debug = params[3];
|
|
@@ -1695,7 +2202,7 @@ function createAtRuleFn(mergeData, fns, createFnResult, fnPrefix, fnName, fnSele
|
|
|
1695
2202
|
debug = params[2];
|
|
1696
2203
|
}
|
|
1697
2204
|
else if (isMedia && typeof params[0] === "number") {
|
|
1698
|
-
|
|
2205
|
+
weight = params[0];
|
|
1699
2206
|
arg = fnSelector.selector;
|
|
1700
2207
|
style = params[1];
|
|
1701
2208
|
debug = params[2];
|
|
@@ -1715,7 +2222,7 @@ function createAtRuleFn(mergeData, fns, createFnResult, fnPrefix, fnName, fnSele
|
|
|
1715
2222
|
selector = hasArg ? before + normalizeSelectorArg(selector) + after : selector;
|
|
1716
2223
|
for (let j = 0, len = items.length; j < len; j++) {
|
|
1717
2224
|
const item = items[j];
|
|
1718
|
-
data = mergeData(data, callsite, isStyleData(item) ? item : transformStyle(item, transform), debug ?? null, null, [
|
|
2225
|
+
data = mergeData(data, callsite, isStyleData(item) ? item : transformStyle(item, transform), debug ?? null, null, [weight !== null ? [selector, weight] : selector]);
|
|
1719
2226
|
}
|
|
1720
2227
|
}
|
|
1721
2228
|
return createFnResult(data, fns);
|
|
@@ -1782,9 +2289,9 @@ function createScopeAtRuleFn(fnPrefix, fnName, fnSelector, cloneScope) {
|
|
|
1782
2289
|
let arg;
|
|
1783
2290
|
let data;
|
|
1784
2291
|
let debug;
|
|
1785
|
-
let
|
|
2292
|
+
let weight = null;
|
|
1786
2293
|
if (hasArg) if (isMedia && typeof params[0] === "number") {
|
|
1787
|
-
|
|
2294
|
+
weight = params[0];
|
|
1788
2295
|
arg = params[1];
|
|
1789
2296
|
data = params[2];
|
|
1790
2297
|
debug = params[3];
|
|
@@ -1794,7 +2301,7 @@ function createScopeAtRuleFn(fnPrefix, fnName, fnSelector, cloneScope) {
|
|
|
1794
2301
|
debug = params[2];
|
|
1795
2302
|
}
|
|
1796
2303
|
else if (isMedia && typeof params[0] === "number") {
|
|
1797
|
-
|
|
2304
|
+
weight = params[0];
|
|
1798
2305
|
arg = fnSelector.selector;
|
|
1799
2306
|
data = params[1];
|
|
1800
2307
|
debug = params[2];
|
|
@@ -1811,7 +2318,7 @@ function createScopeAtRuleFn(fnPrefix, fnName, fnSelector, cloneScope) {
|
|
|
1811
2318
|
selector = args[i];
|
|
1812
2319
|
if (hasArg && DEV_CONFIG.isCheckSelectorEnabled) checkSelector(fnPrefix, fnName, fnSelector, selector);
|
|
1813
2320
|
selector = hasArg ? before + normalizeSelectorArg(selector) + after : selector;
|
|
1814
|
-
result = mergeScopeItems(result, callsite, data, debug ?? null, null,
|
|
2321
|
+
result = mergeScopeItems(result, callsite, data, debug ?? null, null, weight !== null ? [selector, weight] : selector, cloneScope);
|
|
1815
2322
|
}
|
|
1816
2323
|
return result;
|
|
1817
2324
|
};
|
|
@@ -1888,6 +2395,20 @@ function createSlotBuilder(selectors, transform) {
|
|
|
1888
2395
|
traceMarker(fn, "slot");
|
|
1889
2396
|
return fn;
|
|
1890
2397
|
}
|
|
2398
|
+
function createSelectorBuilder(selectors, transform) {
|
|
2399
|
+
const fns = createStyleFns(mergeSelectorOverrideData, selectors, FnPrefixSelector, transform, null);
|
|
2400
|
+
const fn = (selector, style, debug) => {
|
|
2401
|
+
if (isDebugData(style) && debug === void 0) {
|
|
2402
|
+
debug = style;
|
|
2403
|
+
style = void 0;
|
|
2404
|
+
}
|
|
2405
|
+
const target = createCallableSelector(createSelectorData(resolveCallsite(debug), normalizeManualSelectors(selector)), fns, transform);
|
|
2406
|
+
if (style === void 0) return target;
|
|
2407
|
+
return target(style, debug);
|
|
2408
|
+
};
|
|
2409
|
+
traceMarker(fn, "style.selector");
|
|
2410
|
+
return fn;
|
|
2411
|
+
}
|
|
1891
2412
|
function createScopeBuilder(selectors) {
|
|
1892
2413
|
const fns = createScopeFns(selectors, FnPrefixScope, cloneScope);
|
|
1893
2414
|
const fn = (items, debug) => {
|
|
@@ -1903,6 +2424,34 @@ function createScopeBuilder(selectors) {
|
|
|
1903
2424
|
traceMarker(fn, "scope");
|
|
1904
2425
|
return fn;
|
|
1905
2426
|
}
|
|
2427
|
+
function createCallableSelectorOverride(data, fns, transform) {
|
|
2428
|
+
const callable = ((style, debug) => {
|
|
2429
|
+
if (isDebugData(style) && debug === void 0) {
|
|
2430
|
+
debug = style;
|
|
2431
|
+
style = void 0;
|
|
2432
|
+
}
|
|
2433
|
+
const callsite = resolveCallsite(debug);
|
|
2434
|
+
return createCallableSelectorOverride(mergeSelectorOverrideData(createSelectorOverrideData(callsite, data[BUILDER_SELECTOR]), callsite, style ? isStyleData(style) ? style : transformStyle(style, transform) : null, debug ?? null, null, null), fns, transform);
|
|
2435
|
+
});
|
|
2436
|
+
traceMarker(callable, "selector.override");
|
|
2437
|
+
Object.setPrototypeOf(callable, fns);
|
|
2438
|
+
Object.assign(callable, data);
|
|
2439
|
+
return callable;
|
|
2440
|
+
}
|
|
2441
|
+
function createCallableSelector(data, overrideFns, transform) {
|
|
2442
|
+
const callable = ((style, debug) => {
|
|
2443
|
+
if (isDebugData(style) && debug === void 0) {
|
|
2444
|
+
debug = style;
|
|
2445
|
+
style = void 0;
|
|
2446
|
+
}
|
|
2447
|
+
const callsite = resolveCallsite(debug);
|
|
2448
|
+
return createCallableSelectorOverride(mergeSelectorOverrideData(createSelectorOverrideData(callsite, data[BUILDER_SELECTOR]), callsite, style ? isStyleData(style) ? style : transformStyle(style, transform) : null, debug ?? null, null, null), overrideFns, transform);
|
|
2449
|
+
});
|
|
2450
|
+
traceMarker(callable, "selector");
|
|
2451
|
+
Object.setPrototypeOf(callable, overrideFns);
|
|
2452
|
+
Object.assign(callable, data);
|
|
2453
|
+
return callable;
|
|
2454
|
+
}
|
|
1906
2455
|
function createCallableSlot(data, fns, overrideFns, transform) {
|
|
1907
2456
|
const slotId = data[BUILDER_SLOT_ID];
|
|
1908
2457
|
const callable = ((style, debug) => {
|
|
@@ -2345,7 +2894,7 @@ function getCssPropertyName(property) {
|
|
|
2345
2894
|
function createAtRuleNameFormatter(defaultFormat, prefix) {
|
|
2346
2895
|
const formatter = createNameFormatter(["name"]);
|
|
2347
2896
|
return (format, id, info) => {
|
|
2348
|
-
const hash = getIdentifierSafeHash(id);
|
|
2897
|
+
const hash = getIdentifierSafeHash(id, CSS_CONFIG.hashLength);
|
|
2349
2898
|
const name = formatter(format || defaultFormat, hash, info);
|
|
2350
2899
|
if (!prefix) return name;
|
|
2351
2900
|
return name.startsWith(prefix) ? name : prefix + name;
|
|
@@ -2509,7 +3058,499 @@ function buildPropertyCss(format, name, id, descriptors, tokens, tokenLookup, to
|
|
|
2509
3058
|
name
|
|
2510
3059
|
};
|
|
2511
3060
|
}
|
|
2512
|
-
createIdCounter("property");
|
|
3061
|
+
createIdCounter("property");
|
|
3062
|
+
//#endregion
|
|
3063
|
+
//#region sheet/utils/sourcemap.ts
|
|
3064
|
+
const VLQ_BASE_SHIFT = 5;
|
|
3065
|
+
const VLQ_BASE = 1 << VLQ_BASE_SHIFT;
|
|
3066
|
+
const VLQ_BASE_MASK = VLQ_BASE - 1;
|
|
3067
|
+
const VLQ_CONTINUATION_BIT = VLQ_BASE;
|
|
3068
|
+
const BASE64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
3069
|
+
const SOURCE_URL_PREFIX = "source://";
|
|
3070
|
+
function encodeBase64(text) {
|
|
3071
|
+
const bytes = new TextEncoder().encode(text);
|
|
3072
|
+
let binary = "";
|
|
3073
|
+
for (let i = 0, len = bytes.length; i < len; i++) binary += String.fromCharCode(bytes[i]);
|
|
3074
|
+
return btoa(binary);
|
|
3075
|
+
}
|
|
3076
|
+
function getSource(sources, sourceLookup, filePath, sourceContent) {
|
|
3077
|
+
let source = sourceLookup[filePath];
|
|
3078
|
+
if (source) {
|
|
3079
|
+
if (source.sourceContent === void 0) source.sourceContent = sourceContent;
|
|
3080
|
+
return source;
|
|
3081
|
+
}
|
|
3082
|
+
source = {
|
|
3083
|
+
filePath,
|
|
3084
|
+
sourceIndex: sources.length,
|
|
3085
|
+
sourceContent
|
|
3086
|
+
};
|
|
3087
|
+
sources.push(source);
|
|
3088
|
+
sourceLookup[filePath] = source;
|
|
3089
|
+
return source;
|
|
3090
|
+
}
|
|
3091
|
+
function normalizeSourcePath(filePath) {
|
|
3092
|
+
filePath = normalizeCallsiteSourceUrl(filePath);
|
|
3093
|
+
const atIndex = filePath.indexOf("/at ");
|
|
3094
|
+
if (atIndex !== -1) return filePath.slice(atIndex + 4);
|
|
3095
|
+
return filePath.replace(/^at\s+/, "");
|
|
3096
|
+
}
|
|
3097
|
+
function getSourceMapSourceUrl(sourceData) {
|
|
3098
|
+
const sourceUrl = sourceData.sourceUrl || sourceData.filePath;
|
|
3099
|
+
if (sourceData.sourceContent !== void 0) return normalizeSourcePath(sourceUrl);
|
|
3100
|
+
return normalizeSourcePath(resolveSidecarSourceUrl(sourceUrl));
|
|
3101
|
+
}
|
|
3102
|
+
function resolveSidecarSourceUrl(sourceUrl) {
|
|
3103
|
+
const sidecarUrl = getSidecarUrl();
|
|
3104
|
+
if (!sidecarUrl) return sourceUrl;
|
|
3105
|
+
return joinSourceUrl(sidecarUrl, getSourceUrlPath(sourceUrl));
|
|
3106
|
+
}
|
|
3107
|
+
function getSidecarUrl() {
|
|
3108
|
+
const value = globalThis[Symbol.for(SIDECAR_URL_GLOBAL_SYMBOL)];
|
|
3109
|
+
return typeof value === "string" && value ? value : null;
|
|
3110
|
+
}
|
|
3111
|
+
function getSourceUrlPath(sourceUrl) {
|
|
3112
|
+
if (sourceUrl.startsWith(SOURCE_URL_PREFIX)) return sourceUrl.slice(9).replace(/^\/+/, "");
|
|
3113
|
+
try {
|
|
3114
|
+
return new URL(sourceUrl).pathname.replace(/^\/+/, "");
|
|
3115
|
+
} catch {
|
|
3116
|
+
return sourceUrl.replace(/^[a-zA-Z][a-zA-Z\d+.-]*:\/+/, "").replace(/^\/+/, "");
|
|
3117
|
+
}
|
|
3118
|
+
}
|
|
3119
|
+
function joinSourceUrl(baseUrl, sourcePath) {
|
|
3120
|
+
const base = baseUrl.replace(/\/+$/, "");
|
|
3121
|
+
const path = sourcePath.replace(/^\/+/, "");
|
|
3122
|
+
return path ? `${base}/${path}` : base;
|
|
3123
|
+
}
|
|
3124
|
+
function getLineCount(css) {
|
|
3125
|
+
let count = 1;
|
|
3126
|
+
for (let i = 0, len = css.length; i < len; i++) if (css.charCodeAt(i) === 10) count++;
|
|
3127
|
+
return count;
|
|
3128
|
+
}
|
|
3129
|
+
function encodeVlq(value) {
|
|
3130
|
+
let vlq = value < 0 ? (-value << 1) + 1 : value << 1;
|
|
3131
|
+
let encoded = "";
|
|
3132
|
+
do {
|
|
3133
|
+
let digit = vlq & VLQ_BASE_MASK;
|
|
3134
|
+
vlq >>>= VLQ_BASE_SHIFT;
|
|
3135
|
+
if (vlq > 0) digit |= VLQ_CONTINUATION_BIT;
|
|
3136
|
+
encoded += BASE64[digit];
|
|
3137
|
+
} while (vlq > 0);
|
|
3138
|
+
return encoded;
|
|
3139
|
+
}
|
|
3140
|
+
//#endregion
|
|
3141
|
+
//#region sheet/sourcemap.ts
|
|
3142
|
+
function getRuleCallsite(callsite, debug, debugField) {
|
|
3143
|
+
if (debug && debugField) {
|
|
3144
|
+
const loc = getDebugFieldLoc(debug, debugField);
|
|
3145
|
+
if (loc) return normalizeRuleCallsite({
|
|
3146
|
+
filePath: loc[3] ?? debug.sourceUrl,
|
|
3147
|
+
sourceUrl: loc[3] ?? debug.sourceUrl,
|
|
3148
|
+
sourceContent: loc[4] ?? debug.code,
|
|
3149
|
+
line: loc[0],
|
|
3150
|
+
column: loc[1]
|
|
3151
|
+
});
|
|
3152
|
+
}
|
|
3153
|
+
if (callsite) return normalizeRuleCallsite(callsite);
|
|
3154
|
+
if (debug) return normalizeRuleCallsite({
|
|
3155
|
+
filePath: debug.sourceUrl,
|
|
3156
|
+
sourceUrl: debug.sourceUrl,
|
|
3157
|
+
sourceContent: debug.code,
|
|
3158
|
+
line: debug.loc[0],
|
|
3159
|
+
column: debug.loc[1]
|
|
3160
|
+
});
|
|
3161
|
+
return callsite || null;
|
|
3162
|
+
}
|
|
3163
|
+
function normalizeRuleCallsite(callsite) {
|
|
3164
|
+
return {
|
|
3165
|
+
...callsite,
|
|
3166
|
+
filePath: normalizeCallsiteSourceUrl(callsite.filePath),
|
|
3167
|
+
sourceUrl: callsite.sourceUrl ? normalizeCallsiteSourceUrl(callsite.sourceUrl) : callsite.sourceUrl
|
|
3168
|
+
};
|
|
3169
|
+
}
|
|
3170
|
+
globalData("sheet.dev.sourcemapTags", () => []);
|
|
3171
|
+
globalData("sheet.dev.sheets", () => /* @__PURE__ */ new Set());
|
|
3172
|
+
globalData("runtime.combinedStyle.targets", () => /* @__PURE__ */ new WeakMap());
|
|
3173
|
+
//#endregion
|
|
3174
|
+
//#region runtime/core/cache/resolvedItem.ts
|
|
3175
|
+
const resolvedStyleItems = globalData("runtime.resolvedStyleItems", () => /* @__PURE__ */ new WeakSet());
|
|
3176
|
+
const resolvedStyleItemTokenValues = globalData("runtime.styleItemTokenValues", () => /* @__PURE__ */ new WeakMap());
|
|
3177
|
+
function markResolvedStyleItem(item) {
|
|
3178
|
+
resolvedStyleItems.add(item);
|
|
3179
|
+
}
|
|
3180
|
+
function isResolvedStyleItem$1(value) {
|
|
3181
|
+
return !!value && typeof value === "object" && resolvedStyleItems.has(value);
|
|
3182
|
+
}
|
|
3183
|
+
function setResolvedStyleItemTokenValues(item, tokens) {
|
|
3184
|
+
resolvedStyleItemTokenValues.set(item, tokens);
|
|
3185
|
+
}
|
|
3186
|
+
//#endregion
|
|
3187
|
+
//#region runtime/core/cache/tokenValues.ts
|
|
3188
|
+
function createMutableTokenValues(base) {
|
|
3189
|
+
return {
|
|
3190
|
+
ids: base ? base.ids.slice() : null,
|
|
3191
|
+
values: base ? base.values.slice() : null,
|
|
3192
|
+
lookup: base ? { ...base.lookup } : null,
|
|
3193
|
+
index: base ? createTokenIndexLookup(base.ids) : null
|
|
3194
|
+
};
|
|
3195
|
+
}
|
|
3196
|
+
function addTokenOverride(values, item, resolver) {
|
|
3197
|
+
if (!resolver.is(item)) return false;
|
|
3198
|
+
addTokenValue(values, resolver.id(item), resolver.value(item));
|
|
3199
|
+
return true;
|
|
3200
|
+
}
|
|
3201
|
+
function addTokenValue(values, id, value) {
|
|
3202
|
+
if (!values.ids) values.ids = [];
|
|
3203
|
+
if (!values.values) values.values = [];
|
|
3204
|
+
if (!values.lookup) values.lookup = Object.create(null);
|
|
3205
|
+
if (!values.index) values.index = Object.create(null);
|
|
3206
|
+
const ids = values.ids;
|
|
3207
|
+
const tokenValues = values.values;
|
|
3208
|
+
const lookup = values.lookup;
|
|
3209
|
+
const indexLookup = values.index;
|
|
3210
|
+
const index = indexLookup[id];
|
|
3211
|
+
if (index === void 0) {
|
|
3212
|
+
indexLookup[id] = ids.push(id) - 1;
|
|
3213
|
+
tokenValues.push(value);
|
|
3214
|
+
} else tokenValues[index] = value;
|
|
3215
|
+
lookup[id] = value;
|
|
3216
|
+
}
|
|
3217
|
+
function addTokenValues(values, next) {
|
|
3218
|
+
if (!next) return;
|
|
3219
|
+
for (let i = 0, len = next.ids.length; i < len; i++) addTokenValue(values, next.ids[i], next.values[i]);
|
|
3220
|
+
}
|
|
3221
|
+
function addTokenOverrides(values, overrides, resolver) {
|
|
3222
|
+
for (let i = 0, len = overrides.length; i < len; i++) addTokenOverride(values, overrides[i], resolver);
|
|
3223
|
+
}
|
|
3224
|
+
function finishTokenValues(base, values) {
|
|
3225
|
+
if (!values.ids || !values.values || !values.lookup) return null;
|
|
3226
|
+
if (isSameTokenValues(base, values.ids, values.values)) return base;
|
|
3227
|
+
return {
|
|
3228
|
+
ids: values.ids,
|
|
3229
|
+
values: values.values,
|
|
3230
|
+
lookup: values.lookup
|
|
3231
|
+
};
|
|
3232
|
+
}
|
|
3233
|
+
function mergeTokenValues(base, next) {
|
|
3234
|
+
if (!next) return base;
|
|
3235
|
+
if (!base) return next;
|
|
3236
|
+
const values = createMutableTokenValues(base);
|
|
3237
|
+
addTokenValues(values, next);
|
|
3238
|
+
return finishTokenValues(base, values);
|
|
3239
|
+
}
|
|
3240
|
+
function mergeTokenOverrides(base, overrides, resolver) {
|
|
3241
|
+
if (!overrides.length) return base;
|
|
3242
|
+
const values = createMutableTokenValues(base);
|
|
3243
|
+
addTokenOverrides(values, overrides, resolver);
|
|
3244
|
+
return finishTokenValues(base, values);
|
|
3245
|
+
}
|
|
3246
|
+
function createTokenIndexLookup(ids) {
|
|
3247
|
+
const lookup = Object.create(null);
|
|
3248
|
+
for (let i = 0, len = ids.length; i < len; i++) lookup[ids[i]] = i;
|
|
3249
|
+
return lookup;
|
|
3250
|
+
}
|
|
3251
|
+
function isSameTokenValues(base, ids, values) {
|
|
3252
|
+
if (!base || base.ids.length !== ids.length) return false;
|
|
3253
|
+
const baseLookup = base.lookup;
|
|
3254
|
+
for (let i = 0, len = ids.length; i < len; i++) {
|
|
3255
|
+
if (!hasOwn(baseLookup, ids[i])) return false;
|
|
3256
|
+
if (baseLookup[ids[i]] !== values[i]) return false;
|
|
3257
|
+
}
|
|
3258
|
+
return true;
|
|
3259
|
+
}
|
|
3260
|
+
globalData("runtime.directStyleItemCache", () => /* @__PURE__ */ new WeakMap());
|
|
3261
|
+
function isResolvedStyleItem(value) {
|
|
3262
|
+
return isResolvedStyleItem$1(value);
|
|
3263
|
+
}
|
|
3264
|
+
function createResolvedStyleItem(data, scopes, tokens = null) {
|
|
3265
|
+
return createStyleItem({
|
|
3266
|
+
data,
|
|
3267
|
+
items: resolveItems(data, scopes)
|
|
3268
|
+
}, tokens);
|
|
3269
|
+
}
|
|
3270
|
+
function createStyleItem(item, tokens = null) {
|
|
3271
|
+
markResolvedStyleItem(item);
|
|
3272
|
+
if (tokens) setResolvedStyleItemTokenValues(item, tokens);
|
|
3273
|
+
return item;
|
|
3274
|
+
}
|
|
3275
|
+
function resolveItems(data, scopes) {
|
|
3276
|
+
const items = [];
|
|
3277
|
+
const stateItems = data[BUILDER_STATE]?.items ?? [];
|
|
3278
|
+
const slotId = isSlotData(data) ? getSlotId(data) : null;
|
|
3279
|
+
for (let i = 0, len = stateItems.length; i < len; i++) {
|
|
3280
|
+
const item = stateItems[i];
|
|
3281
|
+
if (Array.isArray(item)) {
|
|
3282
|
+
items.push(item);
|
|
3283
|
+
continue;
|
|
3284
|
+
}
|
|
3285
|
+
if (isStyleTokenOverrideData(item)) {
|
|
3286
|
+
items.push(item);
|
|
3287
|
+
continue;
|
|
3288
|
+
}
|
|
3289
|
+
if (slotId && item.type !== 2) continue;
|
|
3290
|
+
items.push(item);
|
|
3291
|
+
}
|
|
3292
|
+
if (!slotId || isSheetData(data)) return items;
|
|
3293
|
+
for (let i = 0, len = scopes.length; i < len; i++) {
|
|
3294
|
+
const boundScope = scopes[i];
|
|
3295
|
+
const scope = getScopeTargetScope(boundScope);
|
|
3296
|
+
if (!scope) continue;
|
|
3297
|
+
const scopeItems = scope[BUILDER_STATE]?.items;
|
|
3298
|
+
if (!scopeItems) continue;
|
|
3299
|
+
const targetSlotId = getScopeTargetSlotId(boundScope);
|
|
3300
|
+
for (let j = 0, len = scopeItems.length; j < len; j++) {
|
|
3301
|
+
const item = scopeItems[j];
|
|
3302
|
+
if (Array.isArray(item)) {
|
|
3303
|
+
if (item[1] === slotId) items.push(item);
|
|
3304
|
+
const hasParentSelector = isExtractedScopeParentMarker$2(item[4]) || isExtractedScopeParentMarker$2(item[5]);
|
|
3305
|
+
if (targetSlotId === slotId && hasParentSelector) items.push(getScopeParentItem(String(item[3])));
|
|
3306
|
+
continue;
|
|
3307
|
+
}
|
|
3308
|
+
if (isStyleTokenOverrideData(item)) continue;
|
|
3309
|
+
if (item.type !== 4) continue;
|
|
3310
|
+
if (item.slotId === slotId) items.push(item);
|
|
3311
|
+
if (item.parentSelector && targetSlotId === slotId) items.push(getScopeParentItem(item.className));
|
|
3312
|
+
}
|
|
3313
|
+
}
|
|
3314
|
+
return items;
|
|
3315
|
+
}
|
|
3316
|
+
function getScopeParentItem(className) {
|
|
3317
|
+
const parentClassName = formatScopeClassName(className);
|
|
3318
|
+
return [parentClassName, parentClassName];
|
|
3319
|
+
}
|
|
3320
|
+
function formatScopeClassName(className) {
|
|
3321
|
+
const format = CSS_CONFIG.scopeClassNameFormat;
|
|
3322
|
+
if (!format) return "-" + className;
|
|
3323
|
+
if (typeof format === "function") return format({ className });
|
|
3324
|
+
return format.replace(/\[|\]/g, "").replace(/\(className\)/g, className);
|
|
3325
|
+
}
|
|
3326
|
+
function isExtractedScopeParentMarker$2(value) {
|
|
3327
|
+
return value === 1 || value === true;
|
|
3328
|
+
}
|
|
3329
|
+
//#endregion
|
|
3330
|
+
//#region builder/extract/utils.ts
|
|
3331
|
+
function createExtractedData(type, slotId) {
|
|
3332
|
+
const data = {
|
|
3333
|
+
[BUILDER_TYPE]: type,
|
|
3334
|
+
[BUILDER_STATE]: {
|
|
3335
|
+
items: [],
|
|
3336
|
+
lookup: {}
|
|
3337
|
+
},
|
|
3338
|
+
[BUILDER_CALLSITE]: null
|
|
3339
|
+
};
|
|
3340
|
+
if (slotId !== void 0) data[BUILDER_SLOT_ID] = slotId;
|
|
3341
|
+
return data;
|
|
3342
|
+
}
|
|
3343
|
+
function copyExtractedData(target, source) {
|
|
3344
|
+
const mutable = target;
|
|
3345
|
+
mutable[BUILDER_TYPE] = source[BUILDER_TYPE];
|
|
3346
|
+
mutable[BUILDER_STATE] = source[BUILDER_STATE];
|
|
3347
|
+
mutable[BUILDER_CALLSITE] = source[BUILDER_CALLSITE];
|
|
3348
|
+
if (source[BUILDER_SLOT_ID] !== void 0) mutable[BUILDER_SLOT_ID] = source[BUILDER_SLOT_ID];
|
|
3349
|
+
}
|
|
3350
|
+
function createExtractedScopeTarget(scope, slot) {
|
|
3351
|
+
return {
|
|
3352
|
+
[BUILDER_TYPE]: 5,
|
|
3353
|
+
[BUILDER_SCOPE]: scope,
|
|
3354
|
+
[BUILDER_SCOPE_ID]: slot[BUILDER_SLOT_ID]
|
|
3355
|
+
};
|
|
3356
|
+
}
|
|
3357
|
+
function normalizeExtractedItems(type, slotId, items) {
|
|
3358
|
+
const normalized = [];
|
|
3359
|
+
let i = 0;
|
|
3360
|
+
while (i < items.length) {
|
|
3361
|
+
const item = items[i];
|
|
3362
|
+
const value = item[2];
|
|
3363
|
+
normalized.push(value === void 0 ? slotId === null ? [
|
|
3364
|
+
type,
|
|
3365
|
+
item[0],
|
|
3366
|
+
item[1]
|
|
3367
|
+
] : [
|
|
3368
|
+
type,
|
|
3369
|
+
slotId,
|
|
3370
|
+
item[0],
|
|
3371
|
+
item[1]
|
|
3372
|
+
] : slotId === null ? [
|
|
3373
|
+
type,
|
|
3374
|
+
item[0],
|
|
3375
|
+
item[1],
|
|
3376
|
+
value
|
|
3377
|
+
] : [
|
|
3378
|
+
type,
|
|
3379
|
+
slotId,
|
|
3380
|
+
item[0],
|
|
3381
|
+
item[1],
|
|
3382
|
+
value
|
|
3383
|
+
]);
|
|
3384
|
+
i++;
|
|
3385
|
+
}
|
|
3386
|
+
return normalized;
|
|
3387
|
+
}
|
|
3388
|
+
//#endregion
|
|
3389
|
+
//#region builder/extract/withTokens.ts
|
|
3390
|
+
const tokenBoundData = /* @__PURE__ */ new WeakMap();
|
|
3391
|
+
function isExtractedTokenBoundData(value) {
|
|
3392
|
+
return !!value && (typeof value === "object" || typeof value === "function") && tokenBoundData.has(value);
|
|
3393
|
+
}
|
|
3394
|
+
function getExtractedTokenBoundData(value) {
|
|
3395
|
+
return tokenBoundData.get(value);
|
|
3396
|
+
}
|
|
3397
|
+
function isElementDebugData(value) {
|
|
3398
|
+
if (!value || typeof value !== "object") return false;
|
|
3399
|
+
return value.$$elementDebug === true;
|
|
3400
|
+
}
|
|
3401
|
+
//#endregion
|
|
3402
|
+
//#region runtime/core/cache/itemWithResolver.ts
|
|
3403
|
+
function createResolvedStyleItemWithResolver(data, tokens, resolver) {
|
|
3404
|
+
return createResolvedStyleItem(data, [], mergeTokenValues(getDataTokenValues(data, resolver), tokens));
|
|
3405
|
+
}
|
|
3406
|
+
function getDirectStyleItemWithResolver(item, resolver) {
|
|
3407
|
+
return createResolvedStyleItemWithResolver(item, null, resolver);
|
|
3408
|
+
}
|
|
3409
|
+
function getDataTokenValues(data, resolver) {
|
|
3410
|
+
const stateItems = data[BUILDER_STATE]?.items ?? [];
|
|
3411
|
+
const values = createMutableTokenValues(null);
|
|
3412
|
+
for (let i = 0, len = stateItems.length; i < len; i++) addTokenOverride(values, stateItems[i], resolver);
|
|
3413
|
+
return finishTokenValues(null, values);
|
|
3414
|
+
}
|
|
3415
|
+
createCacheValue();
|
|
3416
|
+
function createCacheValue() {
|
|
3417
|
+
return {
|
|
3418
|
+
d: null,
|
|
3419
|
+
c: RUNTIME_CONFIG.changes
|
|
3420
|
+
};
|
|
3421
|
+
}
|
|
3422
|
+
//#endregion
|
|
3423
|
+
//#region runtime/core/cache/token.ts
|
|
3424
|
+
const runtimeTokenValueResolver = {
|
|
3425
|
+
get key() {
|
|
3426
|
+
return CSS_CONFIG.tokenNameFormat;
|
|
3427
|
+
},
|
|
3428
|
+
is: isStyleTokenOverrideData,
|
|
3429
|
+
id(token) {
|
|
3430
|
+
return getStyleTokenId(token);
|
|
3431
|
+
},
|
|
3432
|
+
value(token) {
|
|
3433
|
+
return getTokenOverrideValue(token, CSS_CONFIG.tokenNameFormat ?? null);
|
|
3434
|
+
}
|
|
3435
|
+
};
|
|
3436
|
+
function normalizeStylePropItem(item, stableTokenBound) {
|
|
3437
|
+
if (isElementDebugData(item)) return null;
|
|
3438
|
+
if (RUNTIME_CONFIG.isHoist && isExtractedTokenBoundData(item)) {
|
|
3439
|
+
const bound = getExtractedTokenBoundData(item);
|
|
3440
|
+
if (stableTokenBound) return normalizeStylePropItem(bound.data, true);
|
|
3441
|
+
const tokens = mergeTokenOverrides(null, bound.tokens, runtimeTokenValueResolver);
|
|
3442
|
+
if (isStyleData(bound.data) || isSheetData(bound.data) || isSlotData(bound.data)) return createResolvedStyleItemWithResolver(bound.data, tokens, runtimeTokenValueResolver);
|
|
3443
|
+
return normalizeStylePropItem(bound.data, false);
|
|
3444
|
+
}
|
|
3445
|
+
if (isResolvedStyleItem(item) || isThemeData(item)) return item;
|
|
3446
|
+
if (isStyleData(item) || isSheetData(item) || isSlotData(item)) return getDirectStyleItemWithResolver(item, runtimeTokenValueResolver);
|
|
3447
|
+
return null;
|
|
3448
|
+
}
|
|
3449
|
+
function getStylePropCacheKey(item, tokenBindings) {
|
|
3450
|
+
if (RUNTIME_CONFIG.isHoist && isExtractedTokenBoundData(item)) {
|
|
3451
|
+
const bound = getExtractedTokenBoundData(item);
|
|
3452
|
+
const key = getStylePropCacheKey(bound.data, tokenBindings);
|
|
3453
|
+
const tokens = mergeTokenOverrides(null, bound.tokens, runtimeTokenValueResolver);
|
|
3454
|
+
if (key && tokens) tokenBindings.push({
|
|
3455
|
+
data: key,
|
|
3456
|
+
tokens
|
|
3457
|
+
});
|
|
3458
|
+
return key;
|
|
3459
|
+
}
|
|
3460
|
+
if (isResolvedStyleItem(item) || isThemeData(item) || isStyleData(item) || isSheetData(item) || isSlotData(item)) return item;
|
|
3461
|
+
return null;
|
|
3462
|
+
}
|
|
3463
|
+
//#endregion
|
|
3464
|
+
//#region atomic/rule.ts
|
|
3465
|
+
function buildAtomicRule(className, property, value, important, selector, parentSelector, atRules, scopeClassNameFormat) {
|
|
3466
|
+
const cssProp = getCssPropertyName(property);
|
|
3467
|
+
const cssValue = getCssPropertyValue(property, value) + (important ? " !important" : "");
|
|
3468
|
+
const escapedClass = escapeCssIdent(className);
|
|
3469
|
+
const sheetWeight = getSheetSelectorWeight(selector);
|
|
3470
|
+
const classSelector = sheetWeight ? Array(sheetWeight).fill("." + escapedClass).join("") : hasSheetSelectorAnchor(selector) ? `:where(.${escapedClass})` : "." + escapedClass;
|
|
3471
|
+
const itemSelector = selector ? getSelectorText$1(selector) : "";
|
|
3472
|
+
let selectorStr = classSelector + itemSelector;
|
|
3473
|
+
if (parentSelector) {
|
|
3474
|
+
const parentWhere = `:where(${"." + escapeCssIdent(getScopeClassName(className, scopeClassNameFormat)) + getSelectorText$1(parentSelector)})`;
|
|
3475
|
+
selectorStr = classSelector + parentWhere + itemSelector + "," + parentWhere + " " + selectorStr;
|
|
3476
|
+
}
|
|
3477
|
+
let rule = `${selectorStr}{${cssProp}: ${cssValue}}`;
|
|
3478
|
+
if (atRules) for (let i = atRules.length - 1; i >= 0; i--) rule = `${getSelectorText$1(atRules[i])}{${rule}}`;
|
|
3479
|
+
return rule;
|
|
3480
|
+
}
|
|
3481
|
+
function getAtomicRuleLayerPriority(property, priority, selector, parentSelector, atRules, isScopeRule = false) {
|
|
3482
|
+
const selectorPriority = getSelectorPriority$1(selector);
|
|
3483
|
+
const parentSelectorPriority = getSelectorPriority$1(parentSelector);
|
|
3484
|
+
const atRulePriority = getAtRulePriority$1(atRules);
|
|
3485
|
+
return [
|
|
3486
|
+
priority ?? 0,
|
|
3487
|
+
getLayerSelectorPriority(selector, parentSelector, selectorPriority),
|
|
3488
|
+
getParentSelectorPriority(parentSelector, parentSelectorPriority),
|
|
3489
|
+
getMediaPriority(atRules, atRulePriority),
|
|
3490
|
+
atRules ? atRules.length : 0,
|
|
3491
|
+
isScopeRule && !parentSelector ? 1 : 0,
|
|
3492
|
+
getPropertyPriority(property)
|
|
3493
|
+
];
|
|
3494
|
+
}
|
|
3495
|
+
function getMediaPriority(atRules, priority) {
|
|
3496
|
+
if (!atRules?.length) return LayerMediaPriorities.base;
|
|
3497
|
+
if (priority <= 0) return LayerMediaPriorities.media;
|
|
3498
|
+
return LayerMediaPriorities.priorityMedia + priority;
|
|
3499
|
+
}
|
|
3500
|
+
function getLayerSelectorPriority(selector, parentSelector, priority) {
|
|
3501
|
+
if (selector) return priority > 0 ? LayerSelectorPriorities.prioritySelector + priority : LayerSelectorPriorities.selector;
|
|
3502
|
+
if (parentSelector) return LayerSelectorPriorities.parentSelector;
|
|
3503
|
+
return LayerSelectorPriorities.base;
|
|
3504
|
+
}
|
|
3505
|
+
function getParentSelectorPriority(parentSelector, priority) {
|
|
3506
|
+
if (!parentSelector) return 0;
|
|
3507
|
+
return priority > 0 ? priority + 1 : 1;
|
|
3508
|
+
}
|
|
3509
|
+
function getAtRulePriority$1(atRules) {
|
|
3510
|
+
if (!atRules?.length) return 0;
|
|
3511
|
+
let priority = 0;
|
|
3512
|
+
for (let i = 0, len = atRules.length; i < len; i++) priority = Math.max(priority, getSelectorPriority$1(atRules[i]));
|
|
3513
|
+
return priority;
|
|
3514
|
+
}
|
|
3515
|
+
const formatThemeName = createNameFormatter(["name"]);
|
|
3516
|
+
function createThemeClassName(name, id, themeNameFormat) {
|
|
3517
|
+
return formatThemeName(themeNameFormat || "theme[-(name)]-$hash", getIdentifierSafeHash(id, CSS_CONFIG.hashLength), { name: normalizeThemeName(name) });
|
|
3518
|
+
}
|
|
3519
|
+
function getThemeRuleCss(className, tokens, tokenNameFormat) {
|
|
3520
|
+
const declarations = [];
|
|
3521
|
+
for (let i = 0, len = tokens.length; i < len; i++) declarations.push(getThemeDeclaration(tokens[i], tokenNameFormat));
|
|
3522
|
+
return "." + escapeCssIdent(className) + "{" + declarations.join(";") + "}";
|
|
3523
|
+
}
|
|
3524
|
+
function getThemeDeclaration(token, tokenNameFormat) {
|
|
3525
|
+
const name = getTokenVarName(token, tokenNameFormat);
|
|
3526
|
+
const value = token.ref ? getTokenOverrideValue(token, tokenNameFormat) : escapeCssValue(String(token.value ?? ""));
|
|
3527
|
+
return name + ":" + value;
|
|
3528
|
+
}
|
|
3529
|
+
function normalizeThemeName(value) {
|
|
3530
|
+
if (!value) return null;
|
|
3531
|
+
value = value.trim();
|
|
3532
|
+
if (!value) return null;
|
|
3533
|
+
if (/^\d+$/.test(value)) return null;
|
|
3534
|
+
if (isGeneratedNameHash(value)) return null;
|
|
3535
|
+
const stableSuffix = value.match(/^(.+)-[a-z0-9]{7}$/);
|
|
3536
|
+
if (stableSuffix?.[1] && isGeneratedNameHash(value.slice(-7))) return normalizeThemeName(stableSuffix[1]);
|
|
3537
|
+
value = stripGenericThemePrefix(value);
|
|
3538
|
+
if (!value) return null;
|
|
3539
|
+
return value;
|
|
3540
|
+
}
|
|
3541
|
+
function stripGenericThemePrefix(value) {
|
|
3542
|
+
const parts = value.split("--");
|
|
3543
|
+
while (parts[0] === "theme" || parts[0] === "themes") parts.shift();
|
|
3544
|
+
value = parts.join("--");
|
|
3545
|
+
if (value.startsWith("theme-")) return value.slice(6);
|
|
3546
|
+
if (value.startsWith("themes-")) return value.slice(7);
|
|
3547
|
+
return value;
|
|
3548
|
+
}
|
|
3549
|
+
function isGeneratedNameHash(value) {
|
|
3550
|
+
return /^[a-z0-9]{7}$/.test(value) && /\d/.test(value);
|
|
3551
|
+
}
|
|
3552
|
+
createNameFormatter(["name"]);
|
|
3553
|
+
globalData("runtime.elementMarkerSheet", () => ({ sheet: null }));
|
|
2513
3554
|
//#endregion
|
|
2514
3555
|
//#region style/keyframes.ts
|
|
2515
3556
|
function transformKeyframes(frames, transform) {
|
|
@@ -2537,9 +3578,11 @@ function createStyleFn(args) {
|
|
|
2537
3578
|
const fnStyle = createStyleBuilder(selectors, transform);
|
|
2538
3579
|
const fnSlot = createSlotBuilder(selectors, transform);
|
|
2539
3580
|
const fnScope = createScopeBuilder(selectors);
|
|
2540
|
-
const
|
|
2541
|
-
|
|
3581
|
+
const fnSelector = createSelectorBuilder(selectors, transform);
|
|
3582
|
+
const fnWeight = (value, weight) => {
|
|
3583
|
+
return weightValue(value, weight);
|
|
2542
3584
|
};
|
|
3585
|
+
const fnImportant = (value) => importantValue(value);
|
|
2543
3586
|
const fnRaw = (style) => style;
|
|
2544
3587
|
const fnPlain = (style) => style;
|
|
2545
3588
|
const fnKeyframes = ((frames, stableId) => createStyleKeyframes(frames, transform ?? null, stableId));
|
|
@@ -2551,16 +3594,18 @@ function createStyleFn(args) {
|
|
|
2551
3594
|
const style = fnStyle;
|
|
2552
3595
|
style.slot = fnSlot;
|
|
2553
3596
|
style.scope = fnScope;
|
|
2554
|
-
style.
|
|
3597
|
+
style.weight = fnWeight;
|
|
3598
|
+
style.important = fnImportant;
|
|
2555
3599
|
style.raw = fnRaw;
|
|
2556
3600
|
style.plain = fnPlain;
|
|
2557
3601
|
style.keyframes = fnKeyframes;
|
|
2558
3602
|
style.merge = fnMerge;
|
|
2559
|
-
|
|
3603
|
+
style.selector = fnSelector;
|
|
3604
|
+
assignStyleFnMeta(style, {
|
|
3605
|
+
mode: "StyleObject",
|
|
2560
3606
|
selectors,
|
|
2561
3607
|
transform: transform ?? null
|
|
2562
|
-
};
|
|
2563
|
-
Object.assign(style, { [META]: meta });
|
|
3608
|
+
});
|
|
2564
3609
|
return { style };
|
|
2565
3610
|
}
|
|
2566
3611
|
function mergeStyleResult(target, style) {
|
|
@@ -2569,12 +3614,17 @@ function mergeStyleResult(target, style) {
|
|
|
2569
3614
|
if (typeof chainMerge === "function") return chainMerge.call(target, style);
|
|
2570
3615
|
return target;
|
|
2571
3616
|
}
|
|
3617
|
+
function assignStyleFnMeta(styleFn, meta) {
|
|
3618
|
+
Object.assign(styleFn, { [META]: meta });
|
|
3619
|
+
return styleFn;
|
|
3620
|
+
}
|
|
2572
3621
|
function getStyleFnMeta(styleFn) {
|
|
2573
3622
|
return styleFn[META];
|
|
2574
3623
|
}
|
|
2575
3624
|
//#endregion
|
|
2576
3625
|
//#region compiler/utils/import_source.ts
|
|
2577
3626
|
const DefaultStyleFnMeta = {
|
|
3627
|
+
mode: "StyleObject",
|
|
2578
3628
|
selectors: PrioritySelectors,
|
|
2579
3629
|
transform: null
|
|
2580
3630
|
};
|
|
@@ -2591,9 +3641,11 @@ function createImportSourceMatcher(importSources) {
|
|
|
2591
3641
|
meta: DefaultStyleFnMeta
|
|
2592
3642
|
});
|
|
2593
3643
|
importSources?.forEach((entry) => {
|
|
3644
|
+
const meta = entry.meta ?? (entry.styleFn ? getStyleFnMeta(entry.styleFn) : null);
|
|
3645
|
+
if (!meta) return;
|
|
2594
3646
|
addImportSourceEntry(state, {
|
|
2595
3647
|
...entry,
|
|
2596
|
-
meta
|
|
3648
|
+
meta
|
|
2597
3649
|
});
|
|
2598
3650
|
});
|
|
2599
3651
|
return (source) => {
|
|
@@ -2685,65 +3737,6 @@ function isGlobPattern(source) {
|
|
|
2685
3737
|
return /[*?[\]{}]/.test(source) || /[!+@?*]\(/.test(source);
|
|
2686
3738
|
}
|
|
2687
3739
|
//#endregion
|
|
2688
|
-
//#region builder/extract/utils.ts
|
|
2689
|
-
function createExtractedData(type, slotId) {
|
|
2690
|
-
const data = {
|
|
2691
|
-
[BUILDER_TYPE]: type,
|
|
2692
|
-
[BUILDER_STATE]: {
|
|
2693
|
-
items: [],
|
|
2694
|
-
lookup: {}
|
|
2695
|
-
},
|
|
2696
|
-
[BUILDER_CALLSITE]: null
|
|
2697
|
-
};
|
|
2698
|
-
if (slotId !== void 0) data[BUILDER_SLOT_ID] = slotId;
|
|
2699
|
-
return data;
|
|
2700
|
-
}
|
|
2701
|
-
function copyExtractedData(target, source) {
|
|
2702
|
-
const mutable = target;
|
|
2703
|
-
mutable[BUILDER_TYPE] = source[BUILDER_TYPE];
|
|
2704
|
-
mutable[BUILDER_STATE] = source[BUILDER_STATE];
|
|
2705
|
-
mutable[BUILDER_CALLSITE] = source[BUILDER_CALLSITE];
|
|
2706
|
-
if (source[BUILDER_SLOT_ID] !== void 0) mutable[BUILDER_SLOT_ID] = source[BUILDER_SLOT_ID];
|
|
2707
|
-
}
|
|
2708
|
-
function createExtractedScopeTarget(scope, slot) {
|
|
2709
|
-
return {
|
|
2710
|
-
[BUILDER_TYPE]: 5,
|
|
2711
|
-
[BUILDER_SCOPE]: scope,
|
|
2712
|
-
[BUILDER_SCOPE_ID]: slot[BUILDER_SLOT_ID]
|
|
2713
|
-
};
|
|
2714
|
-
}
|
|
2715
|
-
function normalizeExtractedItems(type, slotId, items) {
|
|
2716
|
-
const normalized = [];
|
|
2717
|
-
let i = 0;
|
|
2718
|
-
while (i < items.length) {
|
|
2719
|
-
const item = items[i];
|
|
2720
|
-
const value = item[2];
|
|
2721
|
-
normalized.push(value === void 0 ? slotId === null ? [
|
|
2722
|
-
type,
|
|
2723
|
-
item[0],
|
|
2724
|
-
item[1]
|
|
2725
|
-
] : [
|
|
2726
|
-
type,
|
|
2727
|
-
slotId,
|
|
2728
|
-
item[0],
|
|
2729
|
-
item[1]
|
|
2730
|
-
] : slotId === null ? [
|
|
2731
|
-
type,
|
|
2732
|
-
item[0],
|
|
2733
|
-
item[1],
|
|
2734
|
-
value
|
|
2735
|
-
] : [
|
|
2736
|
-
type,
|
|
2737
|
-
slotId,
|
|
2738
|
-
item[0],
|
|
2739
|
-
item[1],
|
|
2740
|
-
value
|
|
2741
|
-
]);
|
|
2742
|
-
i++;
|
|
2743
|
-
}
|
|
2744
|
-
return normalized;
|
|
2745
|
-
}
|
|
2746
|
-
//#endregion
|
|
2747
3740
|
//#region builder/extract/scope.ts
|
|
2748
3741
|
function createExtractedScope(items) {
|
|
2749
3742
|
const scope = ((slot) => {
|
|
@@ -2754,6 +3747,16 @@ function createExtractedScope(items) {
|
|
|
2754
3747
|
return scope;
|
|
2755
3748
|
}
|
|
2756
3749
|
//#endregion
|
|
3750
|
+
//#region builder/extract/sheet.ts
|
|
3751
|
+
function createExtractedSheet(items, options = {}) {
|
|
3752
|
+
const data = createExtractedData(9);
|
|
3753
|
+
data[BUILDER_SHEET_OPTIONS] = options;
|
|
3754
|
+
const normalizedItems = items.filter((item) => Array.isArray(item));
|
|
3755
|
+
const tokenItems = items.filter((item) => !Array.isArray(item));
|
|
3756
|
+
data[BUILDER_STATE].items = [...tokenItems, ...normalizeExtractedItems(9, null, normalizedItems)];
|
|
3757
|
+
return data;
|
|
3758
|
+
}
|
|
3759
|
+
//#endregion
|
|
2757
3760
|
//#region builder/extract/slot.ts
|
|
2758
3761
|
function createExtractedSlot(slotId, items) {
|
|
2759
3762
|
const slot = ((items) => {
|
|
@@ -2827,6 +3830,62 @@ function appendExtractedStyleTuples(target, source) {
|
|
|
2827
3830
|
}
|
|
2828
3831
|
}
|
|
2829
3832
|
//#endregion
|
|
3833
|
+
//#region dialect/namedTokens.ts
|
|
3834
|
+
const ROOT = Symbol("fluentic.namedTokens.root");
|
|
3835
|
+
function createNamedToken(id, value) {
|
|
3836
|
+
const token = createStyleToken(value, createNamedTokenId(id));
|
|
3837
|
+
token[TOKEN_VAR_NAME] = getTokenVarName(token, CSS_CONFIG.tokenNameFormat ?? null);
|
|
3838
|
+
return token;
|
|
3839
|
+
}
|
|
3840
|
+
function createNamedTokens(namespace, values) {
|
|
3841
|
+
return createNamedTokenProxy({
|
|
3842
|
+
__fluenticNamedTokens: true,
|
|
3843
|
+
namespace,
|
|
3844
|
+
values,
|
|
3845
|
+
cache: /* @__PURE__ */ new Map()
|
|
3846
|
+
}, []);
|
|
3847
|
+
}
|
|
3848
|
+
function createNamedTokenId(id) {
|
|
3849
|
+
return sanitizeCssIdentName(id.replace(/\./g, "-"), "named-token");
|
|
3850
|
+
}
|
|
3851
|
+
function createNamedTokenProxy(root, path) {
|
|
3852
|
+
return new Proxy(noop, {
|
|
3853
|
+
get(_target, property) {
|
|
3854
|
+
if (property === ROOT) return root;
|
|
3855
|
+
if (property === "then") return void 0;
|
|
3856
|
+
if (property === Symbol.toStringTag) return "NamedTokens";
|
|
3857
|
+
if (property === TOKEN_ID || property === TOKEN_NAME || property === TOKEN_VAR_NAME || property === TOKEN_OVERRIDE || property === "value" || property === "ref") {
|
|
3858
|
+
if (!path.length) return void 0;
|
|
3859
|
+
return getNamedTokenAtPath(root, path)[property];
|
|
3860
|
+
}
|
|
3861
|
+
if (typeof property === "symbol") return void 0;
|
|
3862
|
+
return createNamedTokenProxy(root, path.concat(String(property)));
|
|
3863
|
+
},
|
|
3864
|
+
apply(_target, _thisArg, args) {
|
|
3865
|
+
if (!path.length) return void 0;
|
|
3866
|
+
return getNamedTokenAtPath(root, path).apply(void 0, args);
|
|
3867
|
+
}
|
|
3868
|
+
});
|
|
3869
|
+
}
|
|
3870
|
+
function getNamedTokenAtPath(root, path) {
|
|
3871
|
+
const key = path.join(".");
|
|
3872
|
+
const cached = root.cache.get(key);
|
|
3873
|
+
if (cached) return cached;
|
|
3874
|
+
const value = getValueAtPath(root.values, path);
|
|
3875
|
+
const token = createNamedToken(root.namespace + "." + key, value);
|
|
3876
|
+
root.cache.set(key, token);
|
|
3877
|
+
return token;
|
|
3878
|
+
}
|
|
3879
|
+
function getValueAtPath(values, path) {
|
|
3880
|
+
let current = values;
|
|
3881
|
+
for (let i = 0; i < path.length; i++) {
|
|
3882
|
+
if (!current || typeof current !== "object") return void 0;
|
|
3883
|
+
current = current[path[i]];
|
|
3884
|
+
}
|
|
3885
|
+
return current;
|
|
3886
|
+
}
|
|
3887
|
+
function noop() {}
|
|
3888
|
+
//#endregion
|
|
2830
3889
|
//#region style/utils/expose.ts
|
|
2831
3890
|
function exposeStyle(styles) {
|
|
2832
3891
|
return exposeStyleObject(styles);
|
|
@@ -2841,7 +3900,7 @@ function exposeStyleObject(source) {
|
|
|
2841
3900
|
return result;
|
|
2842
3901
|
}
|
|
2843
3902
|
function exposeStyleValue(value) {
|
|
2844
|
-
if (isStyleTokenData(value) || isSlotData(value)) return value;
|
|
3903
|
+
if (isStyleTokenData(value) || isSlotData(value) || isSelectorData(value)) return value;
|
|
2845
3904
|
if (!value || typeof value !== "object" || Array.isArray(value)) return void 0;
|
|
2846
3905
|
const exposed = exposeStyleObject(value);
|
|
2847
3906
|
return Reflect.ownKeys(exposed).length > 0 ? exposed : void 0;
|
|
@@ -2882,6 +3941,7 @@ function evaluateNode(node, scope) {
|
|
|
2882
3941
|
case "ParenthesizedExpression":
|
|
2883
3942
|
case "TSAsExpression":
|
|
2884
3943
|
case "TSNonNullExpression":
|
|
3944
|
+
case "TSSatisfiesExpression":
|
|
2885
3945
|
case "TSTypeAssertion": return evaluateNode(node.expression, scope);
|
|
2886
3946
|
default: return evalFail(`Cannot statically evaluate: ${node.type}`);
|
|
2887
3947
|
}
|
|
@@ -2954,14 +4014,14 @@ function evaluateMember(node, scope) {
|
|
|
2954
4014
|
if (!key.ok) return key;
|
|
2955
4015
|
const obj = evaluateNode(node.object, scope);
|
|
2956
4016
|
if (!obj.ok) return obj;
|
|
2957
|
-
if (obj.value && typeof obj.value === "object") return evalOk(obj.value[key.value]);
|
|
4017
|
+
if (obj.value && (typeof obj.value === "object" || typeof obj.value === "function")) return evalOk(obj.value[key.value]);
|
|
2958
4018
|
return evalFail("Cannot index non-object");
|
|
2959
4019
|
}
|
|
2960
4020
|
const prop = node.property.name;
|
|
2961
4021
|
const obj = evaluateNode(node.object, scope);
|
|
2962
4022
|
if (!obj.ok) return obj;
|
|
2963
4023
|
if (obj.value == null) return evalFail(`Cannot access .${prop} on null/undefined`);
|
|
2964
|
-
if (typeof obj.value !== "object" && typeof obj.value !== "string") return evalFail(`Cannot access .${prop} on ${typeof obj.value}`);
|
|
4024
|
+
if (typeof obj.value !== "object" && typeof obj.value !== "function" && typeof obj.value !== "string") return evalFail(`Cannot access .${prop} on ${typeof obj.value}`);
|
|
2965
4025
|
return evalOk(obj.value[prop]);
|
|
2966
4026
|
}
|
|
2967
4027
|
function evaluateObject(node, scope) {
|
|
@@ -3000,12 +4060,17 @@ function evaluateObject(node, scope) {
|
|
|
3000
4060
|
} else key = prop.key.type === "Identifier" ? prop.key.name : prop.key.value;
|
|
3001
4061
|
const val = evaluateNode(prop.value, scope);
|
|
3002
4062
|
if (!val.ok && isRequiredStaticStyleValueFail(val.reason)) return val;
|
|
3003
|
-
result[key] = val.ok ? val.value : createCompiledRuntimeValue(prop.value);
|
|
3004
|
-
if (prop.loc?.start)
|
|
3005
|
-
|
|
3006
|
-
|
|
3007
|
-
|
|
3008
|
-
|
|
4063
|
+
result[key] = val.ok ? val.value : createCompiledRuntimeValue$1(prop.value);
|
|
4064
|
+
if (prop.loc?.start) {
|
|
4065
|
+
const variableLoc = prop.value.loc?.start ?? prop.loc?.start;
|
|
4066
|
+
locations[key] = {
|
|
4067
|
+
line: prop.loc.start.line,
|
|
4068
|
+
column: prop.loc.start.column + 1,
|
|
4069
|
+
filePath: scope.styleFilePath ?? scope.filePath,
|
|
4070
|
+
variableLine: variableLoc?.line,
|
|
4071
|
+
variableColumn: variableLoc ? variableLoc.column + 1 : void 0
|
|
4072
|
+
};
|
|
4073
|
+
}
|
|
3009
4074
|
} else return evalFail(`Cannot evaluate ObjectMethod in style object`);
|
|
3010
4075
|
i++;
|
|
3011
4076
|
}
|
|
@@ -3054,6 +4119,15 @@ function evaluateCall(node, scope) {
|
|
|
3054
4119
|
if (!Array.isArray(items.value)) return evalFail("createExtractedStyle items must be an array");
|
|
3055
4120
|
return evalOk(createExtractedStyle(items.value));
|
|
3056
4121
|
}
|
|
4122
|
+
if (imp && imp.source === "@fluentic/style/entry/prod/extract" && imp.name === "createExtractedSheet") {
|
|
4123
|
+
const items = evaluateNode(node.arguments[0], scope);
|
|
4124
|
+
if (!items.ok) return items;
|
|
4125
|
+
if (!Array.isArray(items.value)) return evalFail("createExtractedSheet items must be an array");
|
|
4126
|
+
const options = node.arguments[1] ? evaluateNode(node.arguments[1], scope) : evalOk({});
|
|
4127
|
+
if (!options.ok) return options;
|
|
4128
|
+
if (!options.value || typeof options.value !== "object" || Array.isArray(options.value)) return evalFail("createExtractedSheet options must be an object");
|
|
4129
|
+
return evalOk(createExtractedSheet(items.value, options.value));
|
|
4130
|
+
}
|
|
3057
4131
|
if (imp && imp.source === "@fluentic/style/entry/prod/extract" && imp.name === "getExtractedStyleItems") {
|
|
3058
4132
|
const style = evaluateNode(node.arguments[0], scope);
|
|
3059
4133
|
if (!style.ok) return style;
|
|
@@ -3085,9 +4159,9 @@ function evaluateCall(node, scope) {
|
|
|
3085
4159
|
if (imp && STYLE_IMPORT_PATHS.has(imp.source) && imp.name === "createToken") {
|
|
3086
4160
|
const value = evaluateNode(node.arguments[0], scope);
|
|
3087
4161
|
if (!value.ok) return value;
|
|
3088
|
-
const
|
|
3089
|
-
if (!
|
|
3090
|
-
return evalOk(createCompiledToken(value.value, scope, node.loc?.start, node,
|
|
4162
|
+
const stableId = evaluateOptionalStableTokenId(node.arguments[1], scope);
|
|
4163
|
+
if (!stableId.ok) return stableId;
|
|
4164
|
+
return evalOk(createCompiledToken(value.value, scope, node.loc?.start, node, stableId.value));
|
|
3091
4165
|
}
|
|
3092
4166
|
if (imp && STYLE_IMPORT_PATHS.has(imp.source) && imp.name === "createKeyframes") {
|
|
3093
4167
|
const frames = evaluateNode(node.arguments[0], scope);
|
|
@@ -3154,16 +4228,39 @@ function evaluateCall(node, scope) {
|
|
|
3154
4228
|
const url = evaluateNode(node.arguments[0], scope);
|
|
3155
4229
|
if (!url.ok) return evalFail(`fontSrc url must be statically analyzable: ${url.reason}`);
|
|
3156
4230
|
if (typeof url.value !== "string") return evalFail("fontSrc url must be a static string");
|
|
3157
|
-
const format =
|
|
4231
|
+
const format = evaluateOptionalString(node.arguments[1], scope);
|
|
3158
4232
|
if (!format.ok) return evalFail(`fontSrc format must be statically analyzable: ${format.reason}`);
|
|
3159
4233
|
return evalOk(fontSrc(url.value, format.value));
|
|
3160
4234
|
}
|
|
3161
4235
|
if (imp && STYLE_IMPORT_PATHS.has(imp.source) && imp.name === "createTokens") {
|
|
3162
4236
|
const value = evaluateNode(node.arguments[0], scope);
|
|
3163
4237
|
if (!value.ok) return value;
|
|
3164
|
-
const
|
|
3165
|
-
if (!
|
|
3166
|
-
return evalOk(createCompiledTokens(value.value, scope, node.loc?.start, node,
|
|
4238
|
+
const stableId = evaluateOptionalStableTokenId(node.arguments[1], scope);
|
|
4239
|
+
if (!stableId.ok) return stableId;
|
|
4240
|
+
return evalOk(createCompiledTokens(value.value, scope, node.loc?.start, node, stableId.value));
|
|
4241
|
+
}
|
|
4242
|
+
if (imp && STYLE_IMPORT_PATHS.has(imp.source) && imp.name === "createNamedToken") {
|
|
4243
|
+
const id = evaluateNode(node.arguments[0], scope);
|
|
4244
|
+
if (!id.ok) return id;
|
|
4245
|
+
if (typeof id.value !== "string") return evalFail("createNamedToken id must be a static string");
|
|
4246
|
+
const value = evaluateNode(node.arguments[1], scope);
|
|
4247
|
+
if (!value.ok) return value;
|
|
4248
|
+
return evalOk(createNamedToken(id.value, value.value));
|
|
4249
|
+
}
|
|
4250
|
+
if (imp && STYLE_IMPORT_PATHS.has(imp.source) && imp.name === "createNamedTokens") {
|
|
4251
|
+
const namespace = evaluateNode(node.arguments[0], scope);
|
|
4252
|
+
if (!namespace.ok) return namespace;
|
|
4253
|
+
if (typeof namespace.value !== "string") return evalFail("createNamedTokens namespace must be a static string");
|
|
4254
|
+
const values = evaluateNode(node.arguments[1], scope);
|
|
4255
|
+
if (!values.ok) return values;
|
|
4256
|
+
if (!values.value || typeof values.value !== "object") return evalFail("createNamedTokens values must be a static object");
|
|
4257
|
+
return evalOk(createNamedTokens(namespace.value, values.value));
|
|
4258
|
+
}
|
|
4259
|
+
if (imp && STYLE_IMPORT_PATHS.has(imp.source) && imp.name === "getToken") {
|
|
4260
|
+
const value = evaluateNode(node.arguments[0], scope);
|
|
4261
|
+
if (!value.ok) return value;
|
|
4262
|
+
if (isStyleTokenData(value.value)) return evalOk(getTokenVar(value.value, CSS_CONFIG.tokenNameFormat || null));
|
|
4263
|
+
return evalOk(value.value);
|
|
3167
4264
|
}
|
|
3168
4265
|
if (imp && imp.source === "@fluentic/style/utils" && imp.name === "exposeStyle") {
|
|
3169
4266
|
const styles = evaluateNode(node.arguments[0], scope);
|
|
@@ -3174,13 +4271,13 @@ function evaluateCall(node, scope) {
|
|
|
3174
4271
|
if (imp && STYLE_IMPORT_PATHS.has(imp.source) && imp.name === "createValues") {
|
|
3175
4272
|
const hasNumberArg = node.arguments[0]?.type === "Identifier" && node.arguments[0].name === "Number";
|
|
3176
4273
|
const valuesNode = hasNumberArg ? node.arguments[1] : node.arguments[0];
|
|
3177
|
-
const
|
|
4274
|
+
const stableIdNode = hasNumberArg ? node.arguments[2] : node.arguments[1];
|
|
3178
4275
|
const values = evaluateNode(valuesNode, scope);
|
|
3179
4276
|
if (!values.ok) return values;
|
|
3180
|
-
const
|
|
3181
|
-
if (!
|
|
4277
|
+
const stableId = evaluateOptionalStableTokenId(stableIdNode, scope);
|
|
4278
|
+
if (!stableId.ok) return stableId;
|
|
3182
4279
|
if (!Array.isArray(values.value)) return evalFail("createValues values must be an array");
|
|
3183
|
-
return evalOk(createCompiledValues(values.value, scope, node.loc?.start, node,
|
|
4280
|
+
return evalOk(createCompiledValues(values.value, scope, node.loc?.start, node, stableId.value, hasNumberArg));
|
|
3184
4281
|
}
|
|
3185
4282
|
}
|
|
3186
4283
|
if (node.callee.type === "Identifier") {
|
|
@@ -3225,13 +4322,18 @@ function evaluateCall(node, scope) {
|
|
|
3225
4322
|
buildCss: (_name, tokens, tokenLookup, options) => buildKeyframesCss(format, stable.name, stable.id, transformedFrames, tokens, tokenLookup, options)
|
|
3226
4323
|
}));
|
|
3227
4324
|
}
|
|
3228
|
-
if (node.callee.type === "MemberExpression" && !node.callee.computed && node.callee.property.type === "Identifier" && node.callee.property.name === "
|
|
4325
|
+
if (node.callee.type === "MemberExpression" && !node.callee.computed && node.callee.property.type === "Identifier" && node.callee.property.name === "weight" && node.callee.object.type === "Identifier" && scope.styleNames?.has(node.callee.object.name)) {
|
|
3229
4326
|
const value = evaluateNode(node.arguments[0], scope);
|
|
3230
4327
|
if (!value.ok) return value;
|
|
3231
4328
|
const weight = evaluateNode(node.arguments[1], scope);
|
|
3232
4329
|
if (!weight.ok) return weight;
|
|
3233
|
-
if (typeof weight.value !== "number") return evalFail(
|
|
3234
|
-
return evalOk(
|
|
4330
|
+
if (typeof weight.value !== "number") return evalFail(`${node.callee.property.name} weight must be a number`);
|
|
4331
|
+
return evalOk(weightValue(value.value, weight.value));
|
|
4332
|
+
}
|
|
4333
|
+
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)) {
|
|
4334
|
+
const value = evaluateNode(node.arguments[0], scope);
|
|
4335
|
+
if (!value.ok) return value;
|
|
4336
|
+
return evalOk(importantValue(value.value));
|
|
3235
4337
|
}
|
|
3236
4338
|
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);
|
|
3237
4339
|
return evalFail(`Cannot statically evaluate: ${node.type}`);
|
|
@@ -3268,38 +4370,48 @@ function createCompiledTokenOverride(token, value, runtimeValue) {
|
|
|
3268
4370
|
if (isStyleTokenData(value)) return withRuntimeValue(runtimeValue, {
|
|
3269
4371
|
[TOKEN_ID]: getStyleTokenId(token),
|
|
3270
4372
|
[TOKEN_OVERRIDE]: true,
|
|
4373
|
+
[TOKEN_NAME]: getStyleTokenName(token),
|
|
3271
4374
|
value: value.value,
|
|
3272
4375
|
ref: value
|
|
3273
4376
|
});
|
|
3274
4377
|
return withRuntimeValue(runtimeValue, {
|
|
3275
4378
|
[TOKEN_ID]: getStyleTokenId(token),
|
|
3276
4379
|
[TOKEN_OVERRIDE]: true,
|
|
4380
|
+
[TOKEN_NAME]: getStyleTokenName(token),
|
|
3277
4381
|
value,
|
|
3278
4382
|
ref: null
|
|
3279
4383
|
});
|
|
3280
4384
|
}
|
|
3281
|
-
function createCompiledToken(value, scope, loc, runtimeValue,
|
|
3282
|
-
let tokenId =
|
|
4385
|
+
function createCompiledToken(value, scope, loc, runtimeValue, stableId, debugName) {
|
|
4386
|
+
let tokenId = stableId;
|
|
3283
4387
|
if (!tokenId) tokenId = hashString((scope.styleFilePath ?? scope.filePath) + "\n" + (loc ? loc.line + ":" + loc.column : String(value)));
|
|
4388
|
+
if (isStyleTokenData(value)) return withRuntimeValue(runtimeValue, {
|
|
4389
|
+
[TOKEN_ID]: tokenId,
|
|
4390
|
+
[TOKEN_NAME]: debugName === void 0 ? getStyleTokenNameFromId(stableId) : normalizeStyleTokenName(debugName),
|
|
4391
|
+
value: value.value,
|
|
4392
|
+
ref: value
|
|
4393
|
+
});
|
|
3284
4394
|
return withRuntimeValue(runtimeValue, {
|
|
3285
4395
|
[TOKEN_ID]: tokenId,
|
|
4396
|
+
[TOKEN_NAME]: debugName === void 0 ? getStyleTokenNameFromId(stableId) : normalizeStyleTokenName(debugName),
|
|
3286
4397
|
value,
|
|
3287
4398
|
ref: null
|
|
3288
4399
|
});
|
|
3289
4400
|
}
|
|
3290
|
-
function createCompiledTokens(value, scope, loc, runtimeValue,
|
|
3291
|
-
const tokenGroupId =
|
|
4401
|
+
function createCompiledTokens(value, scope, loc, runtimeValue, stableId) {
|
|
4402
|
+
const tokenGroupId = stableId ?? createCompiledTokenGroupId(scope, loc);
|
|
4403
|
+
const tokenGroupName = getStyleTokenNameFromId(stableId);
|
|
3292
4404
|
if (Array.isArray(value)) {
|
|
3293
4405
|
const result = {};
|
|
3294
4406
|
for (let i = 0, len = value.length; i < len; i++) {
|
|
3295
4407
|
const item = value[i];
|
|
3296
|
-
result[item] = createCompiledToken(item, scope, loc, runtimeValue,
|
|
4408
|
+
result[item] = createCompiledToken(item, scope, loc, runtimeValue, getChildStableId(tokenGroupId, String(i)), getChildStyleTokenName(tokenGroupName, String(i)));
|
|
3297
4409
|
}
|
|
3298
4410
|
return result;
|
|
3299
4411
|
}
|
|
3300
4412
|
if (!value || typeof value !== "object") return {};
|
|
3301
4413
|
const result = {};
|
|
3302
|
-
assignCompiledTokenRecord(result, value, scope, loc, runtimeValue, tokenGroupId);
|
|
4414
|
+
assignCompiledTokenRecord(result, value, scope, loc, runtimeValue, tokenGroupId, tokenGroupName);
|
|
3303
4415
|
return result;
|
|
3304
4416
|
}
|
|
3305
4417
|
function createCompiledTokenGroupId(scope, loc) {
|
|
@@ -3311,22 +4423,24 @@ function createCompiledAtRuleStableId(scope, loc, value) {
|
|
|
3311
4423
|
id: (scope.styleFilePath ?? scope.filePath) + "\n" + (loc ? loc.line + ":" + loc.column : String(value))
|
|
3312
4424
|
};
|
|
3313
4425
|
}
|
|
3314
|
-
function assignCompiledTokenRecord(target, value, scope, loc, runtimeValue,
|
|
4426
|
+
function assignCompiledTokenRecord(target, value, scope, loc, runtimeValue, stableId, debugName) {
|
|
3315
4427
|
for (const key of Object.keys(value)) {
|
|
3316
4428
|
const item = value[key];
|
|
3317
|
-
const
|
|
4429
|
+
const itemStableId = getChildStableId(stableId, key);
|
|
4430
|
+
const itemDebugName = getChildStyleTokenName(debugName, key);
|
|
3318
4431
|
if (item && typeof item === "object" && !Array.isArray(item) && !isStyleTokenData(item)) {
|
|
3319
4432
|
const child = {};
|
|
3320
4433
|
target[key] = child;
|
|
3321
|
-
assignCompiledTokenRecord(child, item, scope, loc, runtimeValue,
|
|
3322
|
-
} else target[key] = createCompiledToken(item, scope, loc, runtimeValue,
|
|
4434
|
+
assignCompiledTokenRecord(child, item, scope, loc, runtimeValue, itemStableId, itemDebugName);
|
|
4435
|
+
} else target[key] = createCompiledToken(item, scope, loc, runtimeValue, itemStableId, itemDebugName);
|
|
3323
4436
|
}
|
|
3324
4437
|
}
|
|
3325
|
-
function createCompiledValues(values, scope, loc, runtimeValue,
|
|
4438
|
+
function createCompiledValues(values, scope, loc, runtimeValue, stableId, isNumber) {
|
|
3326
4439
|
const tokens = /* @__PURE__ */ new Map();
|
|
4440
|
+
const groupName = getStyleTokenNameFromId(stableId);
|
|
3327
4441
|
for (let i = 0, len = values.length; i < len; i++) {
|
|
3328
4442
|
const value = values[i];
|
|
3329
|
-
tokens.set(value, createCompiledToken(parseCompiledValue(value, isNumber), scope, loc, runtimeValue,
|
|
4443
|
+
tokens.set(value, createCompiledToken(parseCompiledValue(value, isNumber), scope, loc, runtimeValue, getChildStableId(stableId, hashString(String(value))), getChildStyleTokenName(groupName, getValueDebugName(value))));
|
|
3330
4444
|
}
|
|
3331
4445
|
return {
|
|
3332
4446
|
[COMPILED_TOKEN_FACTORY]: true,
|
|
@@ -3344,7 +4458,10 @@ function parseCompiledValue(value, isNumber) {
|
|
|
3344
4458
|
function isCompiledTokenFactory(value) {
|
|
3345
4459
|
return !!value && typeof value === "object" && value[COMPILED_TOKEN_FACTORY] === true;
|
|
3346
4460
|
}
|
|
3347
|
-
function
|
|
4461
|
+
function evaluateOptionalStableTokenId(node, scope) {
|
|
4462
|
+
return evaluateOptionalString(node, scope);
|
|
4463
|
+
}
|
|
4464
|
+
function evaluateOptionalString(node, scope) {
|
|
3348
4465
|
if (!node) return evalOk(void 0);
|
|
3349
4466
|
const value = evaluateNode(node, scope);
|
|
3350
4467
|
if (!value.ok) return value;
|
|
@@ -3368,16 +4485,28 @@ function evaluateOptionalStableId(node, scope) {
|
|
|
3368
4485
|
id: stableId.id
|
|
3369
4486
|
});
|
|
3370
4487
|
}
|
|
3371
|
-
function
|
|
3372
|
-
return
|
|
4488
|
+
function getChildStableId(stableId, child) {
|
|
4489
|
+
return stableId ? stableId + "--" + child : void 0;
|
|
4490
|
+
}
|
|
4491
|
+
function getValueDebugName(value) {
|
|
4492
|
+
if (typeof value === "number") return String(value);
|
|
4493
|
+
if (typeof value !== "string") return null;
|
|
4494
|
+
const parts = value.split(/[;|]/);
|
|
4495
|
+
const label = parts[1]?.trim();
|
|
4496
|
+
if (label) return sanitizeTokenDebugName(label);
|
|
4497
|
+
return sanitizeTokenDebugName(parts[0]?.trim() ?? "");
|
|
4498
|
+
}
|
|
4499
|
+
function sanitizeTokenDebugName(value) {
|
|
4500
|
+
return value.replace(/[^a-zA-Z0-9_-]+/g, "-").replace(/^-+|-+$/g, "") || null;
|
|
3373
4501
|
}
|
|
3374
4502
|
function withRuntimeValue(runtimeValue, token) {
|
|
3375
4503
|
return Object.assign({}, token, {
|
|
3376
4504
|
[TOKEN_ID]: token[TOKEN_ID],
|
|
4505
|
+
[TOKEN_NAME]: token[TOKEN_NAME] ?? null,
|
|
3377
4506
|
[COMPILED_RUNTIME_VALUE]: runtimeValue
|
|
3378
4507
|
});
|
|
3379
4508
|
}
|
|
3380
|
-
function createCompiledRuntimeValue(runtimeValue) {
|
|
4509
|
+
function createCompiledRuntimeValue$1(runtimeValue) {
|
|
3381
4510
|
return { [COMPILED_RUNTIME_VALUE]: runtimeValue };
|
|
3382
4511
|
}
|
|
3383
4512
|
function evaluateBinary(node, scope) {
|
|
@@ -3409,14 +4538,14 @@ function evaluateUnary(node, scope) {
|
|
|
3409
4538
|
function isStaticStyleValue(value) {
|
|
3410
4539
|
if (value.type === "StringLiteral" || value.type === "NumericLiteral" || value.type === "BooleanLiteral" || value.type === "NullLiteral") return true;
|
|
3411
4540
|
if (value.type === "TemplateLiteral") return value.expressions.length === 0;
|
|
3412
|
-
if (value.type === "
|
|
3413
|
-
const [priority, itemValue] = value.elements;
|
|
3414
|
-
return !!priority && priority.type === "NumericLiteral" && !!itemValue && isStaticStyleValue(itemValue);
|
|
3415
|
-
}
|
|
3416
|
-
if (value.type === "CallExpression" && value.callee.type === "MemberExpression" && !value.callee.computed && value.callee.property.type === "Identifier" && value.callee.property.name === "value") {
|
|
4541
|
+
if (value.type === "CallExpression" && value.callee.type === "MemberExpression" && !value.callee.computed && value.callee.property.type === "Identifier" && value.callee.property.name === "weight") {
|
|
3417
4542
|
const [itemValue, weight] = value.arguments;
|
|
3418
4543
|
return !!itemValue && itemValue.type !== "SpreadElement" && isStaticStyleValue(itemValue) && !!weight && weight.type === "NumericLiteral";
|
|
3419
4544
|
}
|
|
4545
|
+
if (value.type === "CallExpression" && value.callee.type === "MemberExpression" && !value.callee.computed && value.callee.property.type === "Identifier" && value.callee.property.name === "important") {
|
|
4546
|
+
const [itemValue] = value.arguments;
|
|
4547
|
+
return !!itemValue && itemValue.type !== "SpreadElement" && isStaticStyleValue(itemValue);
|
|
4548
|
+
}
|
|
3420
4549
|
if (value.type === "UnaryExpression") return isStaticStyleValue(value.argument);
|
|
3421
4550
|
return false;
|
|
3422
4551
|
}
|
|
@@ -3431,20 +4560,6 @@ function isStyleChainCall(callee, styleNames) {
|
|
|
3431
4560
|
if (object.type === "MemberExpression") return isStyleChainCall(object, styleNames);
|
|
3432
4561
|
return false;
|
|
3433
4562
|
}
|
|
3434
|
-
const formatThemeName = createNameFormatter(["name"]);
|
|
3435
|
-
function createThemeClassName(name, id, themeNameFormat) {
|
|
3436
|
-
return formatThemeName(themeNameFormat || "theme[-(name)]-$hash", getIdentifierSafeHash(id), { name });
|
|
3437
|
-
}
|
|
3438
|
-
function getThemeRuleCss(className, tokens, tokenNameFormat) {
|
|
3439
|
-
const declarations = [];
|
|
3440
|
-
for (let i = 0, len = tokens.length; i < len; i++) declarations.push(getThemeDeclaration(tokens[i], tokenNameFormat));
|
|
3441
|
-
return "." + escapeCssIdent(className) + "{" + declarations.join(";") + "}";
|
|
3442
|
-
}
|
|
3443
|
-
function getThemeDeclaration(token, tokenNameFormat) {
|
|
3444
|
-
const name = getTokenVarName(token, tokenNameFormat);
|
|
3445
|
-
const value = token.ref ? getTokenOverrideValue(token, tokenNameFormat) : escapeCssValue(String(token.value ?? ""));
|
|
3446
|
-
return name + ":" + value;
|
|
3447
|
-
}
|
|
3448
4563
|
//#endregion
|
|
3449
4564
|
//#region compiler/transform/syntax/utils.ts
|
|
3450
4565
|
function getCallLabel(callee) {
|
|
@@ -3579,60 +4694,6 @@ function sanitizeTokenId(value) {
|
|
|
3579
4694
|
return sanitizeCssIdentName(value, "token");
|
|
3580
4695
|
}
|
|
3581
4696
|
//#endregion
|
|
3582
|
-
//#region compiler/transform/utils/babel.ts
|
|
3583
|
-
function babelPlugin(factory) {
|
|
3584
|
-
return factory;
|
|
3585
|
-
}
|
|
3586
|
-
function babelTransform(args) {
|
|
3587
|
-
let result = null;
|
|
3588
|
-
try {
|
|
3589
|
-
const inputSourceMap = parseInputSourceMap(args.sourcemap);
|
|
3590
|
-
result = BabelCore.transformSync(args.code, {
|
|
3591
|
-
...babelTransformOptions(),
|
|
3592
|
-
inputSourceMap,
|
|
3593
|
-
filename: args.filePath,
|
|
3594
|
-
sourceFileName: args.filePath,
|
|
3595
|
-
plugins: args.plugins,
|
|
3596
|
-
sourceMaps: true,
|
|
3597
|
-
generatorOpts: { retainLines: args.retainLines ?? false }
|
|
3598
|
-
});
|
|
3599
|
-
} catch (err) {
|
|
3600
|
-
if (!args.errorLabel) throw err;
|
|
3601
|
-
const message = getBabelError(err, args);
|
|
3602
|
-
const error = new Error(message);
|
|
3603
|
-
error.stack = void 0;
|
|
3604
|
-
throw error;
|
|
3605
|
-
}
|
|
3606
|
-
if (!result || !result.code) return null;
|
|
3607
|
-
return {
|
|
3608
|
-
code: result.code,
|
|
3609
|
-
sourcemap: result.map ? JSON.stringify(result.map) : null
|
|
3610
|
-
};
|
|
3611
|
-
}
|
|
3612
|
-
function babelTransformOptions() {
|
|
3613
|
-
return {
|
|
3614
|
-
configFile: false,
|
|
3615
|
-
babelrc: false,
|
|
3616
|
-
parserOpts: {
|
|
3617
|
-
plugins: ["typescript", "jsx"],
|
|
3618
|
-
strictMode: false,
|
|
3619
|
-
allowImportExportEverywhere: true
|
|
3620
|
-
}
|
|
3621
|
-
};
|
|
3622
|
-
}
|
|
3623
|
-
function parseInputSourceMap(sourcemap) {
|
|
3624
|
-
if (!sourcemap) return void 0;
|
|
3625
|
-
if (typeof sourcemap !== "string") return sourcemap;
|
|
3626
|
-
return JSON.parse(sourcemap);
|
|
3627
|
-
}
|
|
3628
|
-
function getBabelError(err, args) {
|
|
3629
|
-
const babelErr = err;
|
|
3630
|
-
const msg = babelErr instanceof Error ? babelErr.message : String(err);
|
|
3631
|
-
const codeFrame = babelErr?.codeFrame;
|
|
3632
|
-
const suffix = codeFrame ? `\n\n${codeFrame}` : "";
|
|
3633
|
-
return `${args.errorLabel} in ${args.filePath}:\n${msg}${suffix}`;
|
|
3634
|
-
}
|
|
3635
|
-
//#endregion
|
|
3636
4697
|
//#region compiler/utils/path.ts
|
|
3637
4698
|
function normalizePath(value) {
|
|
3638
4699
|
return value.replace(/\\/g, "/");
|
|
@@ -3758,12 +4819,12 @@ function normalizeSelectorMessage(message) {
|
|
|
3758
4819
|
}
|
|
3759
4820
|
const formatVarName = createNameFormatter(["name"]);
|
|
3760
4821
|
function getLocalVarName(filePath, line, column, format) {
|
|
3761
|
-
const hash = getIdentifierSafeHash(filePath + "\n" + line + ":" + column);
|
|
4822
|
+
const hash = getIdentifierSafeHash(filePath + "\n" + line + ":" + column, CSS_CONFIG.hashLength);
|
|
3762
4823
|
return "--" + formatVarName(format || "var[-(name)]-$hash", hash, { name: "" });
|
|
3763
4824
|
}
|
|
3764
4825
|
//#endregion
|
|
3765
4826
|
//#region compiler/transform/debug/utils/debug_data.ts
|
|
3766
|
-
function buildDebugDataObject(t, node, fileId, sourceUrlRef, sourceContentRef, tokenNameFormat = DEFAULT_CONFIG.tokenNameFormat, styleArg = node.arguments[0], locOverride) {
|
|
4827
|
+
function buildDebugDataObject(t, node, fileId, sourceUrlRef, sourceContentRef, tokenNameFormat = DEFAULT_CONFIG.tokenNameFormat, styleArg = node.arguments[0], locOverride, classNameArg = false) {
|
|
3767
4828
|
const loc = locOverride ?? node.loc?.start;
|
|
3768
4829
|
const line = loc?.line ?? 1;
|
|
3769
4830
|
const column = (loc?.column ?? 0) + 1;
|
|
@@ -3780,10 +4841,46 @@ function buildDebugDataObject(t, node, fileId, sourceUrlRef, sourceContentRef, t
|
|
|
3780
4841
|
t.objectProperty(t.identifier("fields"), buildFields(t, styleArg)),
|
|
3781
4842
|
t.objectProperty(t.identifier("vars"), buildVars(t, styleArg, fileId, tokenNameFormat))
|
|
3782
4843
|
];
|
|
4844
|
+
if (classNameArg) properties.push(t.objectProperty(t.identifier("classNames"), buildClassNames(t, node.arguments)));
|
|
3783
4845
|
properties.push(t.objectProperty(t.identifier("sourceUrl"), sourceUrlRef));
|
|
3784
4846
|
if (sourceContentRef) properties.push(t.objectProperty(t.identifier("code"), sourceContentRef));
|
|
3785
4847
|
return t.objectExpression(properties);
|
|
3786
4848
|
}
|
|
4849
|
+
function buildClassNames(t, args) {
|
|
4850
|
+
const classNames = /* @__PURE__ */ new Map();
|
|
4851
|
+
for (const arg of args) collectClassNameLoc(arg, classNames);
|
|
4852
|
+
const fields = [];
|
|
4853
|
+
for (const [className, loc] of classNames) fields.push(t.objectProperty(t.stringLiteral(className), buildLoc(t, loc.line, loc.column + 1)));
|
|
4854
|
+
return t.objectExpression(fields);
|
|
4855
|
+
}
|
|
4856
|
+
function collectClassNameLoc(arg, classNames) {
|
|
4857
|
+
if (!arg) return;
|
|
4858
|
+
if (arg.type === "StringLiteral") {
|
|
4859
|
+
const loc = arg.loc?.start;
|
|
4860
|
+
if (loc) classNames.set(arg.value, loc);
|
|
4861
|
+
return;
|
|
4862
|
+
}
|
|
4863
|
+
if (arg.type === "TemplateLiteral" && arg.expressions.length === 0) {
|
|
4864
|
+
const loc = arg.loc?.start;
|
|
4865
|
+
if (loc) classNames.set(arg.quasis[0]?.value.cooked ?? arg.quasis[0]?.value.raw ?? "", loc);
|
|
4866
|
+
return;
|
|
4867
|
+
}
|
|
4868
|
+
if (arg.type === "ArrayExpression") {
|
|
4869
|
+
for (const item of arg.elements) collectClassNameLoc(item, classNames);
|
|
4870
|
+
return;
|
|
4871
|
+
}
|
|
4872
|
+
if (arg.type === "ConditionalExpression") {
|
|
4873
|
+
collectClassNameLoc(arg.consequent, classNames);
|
|
4874
|
+
collectClassNameLoc(arg.alternate, classNames);
|
|
4875
|
+
return;
|
|
4876
|
+
}
|
|
4877
|
+
if (arg.type === "LogicalExpression") {
|
|
4878
|
+
collectClassNameLoc(arg.left, classNames);
|
|
4879
|
+
collectClassNameLoc(arg.right, classNames);
|
|
4880
|
+
return;
|
|
4881
|
+
}
|
|
4882
|
+
if (arg.type === "CallExpression" && arg.callee.type === "MemberExpression" && arg.callee.property.type === "Identifier" && arg.callee.property.name === "weight") collectClassNameLoc(arg.arguments[0], classNames);
|
|
4883
|
+
}
|
|
3787
4884
|
function getShortLabel(label) {
|
|
3788
4885
|
const parts = label.split(".");
|
|
3789
4886
|
return parts[parts.length - 1] || label;
|
|
@@ -3942,7 +5039,9 @@ function createDebugPlugin(args) {
|
|
|
3942
5039
|
if (hasDebugArgument(path.node.arguments)) return;
|
|
3943
5040
|
const sourceUrlRef = getSourceUrlId(t, state);
|
|
3944
5041
|
const sourceContentRef = sourceContent ? getSourceContentId(t, state) : null;
|
|
3945
|
-
|
|
5042
|
+
const rootName = getStyleChainRootName(path.node.callee, state.styleNames);
|
|
5043
|
+
const isClassNameCall = rootName ? state.styleMetas.get(rootName)?.mode === "ClassName" : false;
|
|
5044
|
+
path.node.arguments.push(buildDebugDataObject(t, path.node, state.fileId, sourceUrlRef, sourceContentRef, options.css?.tokenNameFormat ?? DEFAULT_CONFIG.tokenNameFormat, getDebugStyleArg(t, path, state, options.dev?.sourcemapMode ?? "style"), getDebugCallLoc(path, state), isClassNameCall));
|
|
3946
5045
|
},
|
|
3947
5046
|
JSXOpeningElement(path, state) {
|
|
3948
5047
|
if (options.dev?.elementClassName === false) return;
|
|
@@ -4132,14 +5231,16 @@ function getSelectorMethodPath(path) {
|
|
|
4132
5231
|
function getDebugStyleArg(t, path, state, sourcemapTrace) {
|
|
4133
5232
|
const arg = getStyleObjectArg(path, state);
|
|
4134
5233
|
if (!arg) return arg;
|
|
5234
|
+
const meta = getStyleCallMeta(path, state);
|
|
4135
5235
|
if (arg.type !== "ObjectExpression") return resolveDebugMergeObject(t, arg, path, state, sourcemapTrace) ?? arg;
|
|
4136
|
-
return flattenDebugObjectExpression(t, arg, path, state, sourcemapTrace, /* @__PURE__ */ new Set());
|
|
5236
|
+
return appendTransformDebugFieldAliases(t, flattenDebugObjectExpression(t, arg, path, state, sourcemapTrace, /* @__PURE__ */ new Set()), meta, state);
|
|
4137
5237
|
}
|
|
4138
5238
|
function getDebugCallLoc(path, state) {
|
|
4139
5239
|
return isSelectorStyleCall(path, state) || isScopeItemSelectorCall(path, state) ? getMergeStyleLoc(path.node.callee) : null;
|
|
4140
5240
|
}
|
|
4141
5241
|
function getStyleObjectArg(path, state) {
|
|
4142
5242
|
const methodName = getSelectorMethodName(path.node.callee);
|
|
5243
|
+
if (methodName === "selector") return path.node.arguments[1];
|
|
4143
5244
|
const rootName = getStyleChainRootName(path.node.callee, state.styleNames);
|
|
4144
5245
|
const selector = methodName && rootName ? state.styleMetas.get(rootName)?.selectors[methodName] : null;
|
|
4145
5246
|
if (!selector) return path.node.arguments[0];
|
|
@@ -4147,6 +5248,10 @@ function getStyleObjectArg(path, state) {
|
|
|
4147
5248
|
const styleArgIndex = selectorArgIndex === null ? 0 : selectorArgIndex + 1;
|
|
4148
5249
|
return path.node.arguments[styleArgIndex];
|
|
4149
5250
|
}
|
|
5251
|
+
function getStyleCallMeta(path, state) {
|
|
5252
|
+
const rootName = getStyleChainRootName(path.node.callee, state.styleNames);
|
|
5253
|
+
return rootName ? state.styleMetas.get(rootName) ?? null : null;
|
|
5254
|
+
}
|
|
4150
5255
|
function isSelectorStyleCall(path, state) {
|
|
4151
5256
|
const methodName = getSelectorMethodName(path.node.callee);
|
|
4152
5257
|
if (!methodName) return false;
|
|
@@ -4251,6 +5356,46 @@ function flattenDebugObjectExpression(t, node, path, state, sourcemapTrace, seen
|
|
|
4251
5356
|
}
|
|
4252
5357
|
return t.objectExpression(properties);
|
|
4253
5358
|
}
|
|
5359
|
+
function appendTransformDebugFieldAliases(t, node, meta, state) {
|
|
5360
|
+
if (!meta || meta.mode !== "StyleObject" || !meta.transform) return node;
|
|
5361
|
+
const existing = /* @__PURE__ */ new Set();
|
|
5362
|
+
for (const property of node.properties) {
|
|
5363
|
+
if (property.type !== "ObjectProperty" || property.computed) continue;
|
|
5364
|
+
const key = getObjectPropertyKey$1(property);
|
|
5365
|
+
if (key) existing.add(key);
|
|
5366
|
+
}
|
|
5367
|
+
const aliases = [];
|
|
5368
|
+
for (const property of node.properties) {
|
|
5369
|
+
if (property.type !== "ObjectProperty" || property.computed) continue;
|
|
5370
|
+
const key = getObjectPropertyKey$1(property);
|
|
5371
|
+
if (!key) continue;
|
|
5372
|
+
const value = evaluateNode(property.value, getDebugEvalScope(state));
|
|
5373
|
+
if (!value.ok) continue;
|
|
5374
|
+
let transformed;
|
|
5375
|
+
try {
|
|
5376
|
+
transformed = meta.transform.transform({ [key]: value.value });
|
|
5377
|
+
} catch {
|
|
5378
|
+
continue;
|
|
5379
|
+
}
|
|
5380
|
+
for (const transformedKey of Object.keys(transformed)) {
|
|
5381
|
+
if (existing.has(transformedKey)) continue;
|
|
5382
|
+
existing.add(transformedKey);
|
|
5383
|
+
aliases.push(createDebugFieldAlias(t, transformedKey, property));
|
|
5384
|
+
}
|
|
5385
|
+
}
|
|
5386
|
+
if (!aliases.length) return node;
|
|
5387
|
+
return t.objectExpression([...node.properties, ...aliases]);
|
|
5388
|
+
}
|
|
5389
|
+
function createDebugFieldAlias(t, key, source) {
|
|
5390
|
+
const alias = t.objectProperty(t.stringLiteral(key), t.nullLiteral());
|
|
5391
|
+
const sourceTrace = source;
|
|
5392
|
+
alias.loc = source.loc;
|
|
5393
|
+
alias.__styleSourcemapStyleLoc = sourceTrace.__styleSourcemapStyleLoc;
|
|
5394
|
+
alias.__styleSourcemapStyleSourceUrl = sourceTrace.__styleSourcemapStyleSourceUrl;
|
|
5395
|
+
alias.__styleSourcemapValueLoc = sourceTrace.__styleSourcemapValueLoc;
|
|
5396
|
+
alias.__styleSourcemapValueSourceUrl = sourceTrace.__styleSourcemapValueSourceUrl;
|
|
5397
|
+
return alias;
|
|
5398
|
+
}
|
|
4254
5399
|
function resolveDebugSpreadObject(t, spread, path, state, sourcemapTrace, seen) {
|
|
4255
5400
|
const node = spread.argument;
|
|
4256
5401
|
if (node.type !== "Identifier") return null;
|
|
@@ -4520,7 +5665,7 @@ function transformDebug(internal, args, deps) {
|
|
|
4520
5665
|
code: args.code,
|
|
4521
5666
|
filePath: args.filePath,
|
|
4522
5667
|
sourcemap: args.sourcemap,
|
|
4523
|
-
plugins: [plugin],
|
|
5668
|
+
plugins: [plugin, createCssPropPlugin({ options })],
|
|
4524
5669
|
retainLines: true
|
|
4525
5670
|
});
|
|
4526
5671
|
if (!result) return null;
|
|
@@ -4533,6 +5678,12 @@ function transformDebug(internal, args, deps) {
|
|
|
4533
5678
|
//#region compiler/utils/file_resolver.ts
|
|
4534
5679
|
const contentCache = /* @__PURE__ */ new Map();
|
|
4535
5680
|
const resolver = new ResolverFactory({
|
|
5681
|
+
conditionNames: [
|
|
5682
|
+
"import",
|
|
5683
|
+
"module",
|
|
5684
|
+
"default",
|
|
5685
|
+
"types"
|
|
5686
|
+
],
|
|
4536
5687
|
extensions: [
|
|
4537
5688
|
".ts",
|
|
4538
5689
|
".tsx",
|
|
@@ -4543,7 +5694,8 @@ const resolver = new ResolverFactory({
|
|
|
4543
5694
|
".mts",
|
|
4544
5695
|
".cts"
|
|
4545
5696
|
],
|
|
4546
|
-
mainFiles: ["index"]
|
|
5697
|
+
mainFiles: ["index"],
|
|
5698
|
+
tsconfig: "auto"
|
|
4547
5699
|
});
|
|
4548
5700
|
function clearResolverCache() {
|
|
4549
5701
|
contentCache.clear();
|
|
@@ -4583,59 +5735,18 @@ function resolveFilePath(source, fromFile) {
|
|
|
4583
5735
|
}
|
|
4584
5736
|
}
|
|
4585
5737
|
//#endregion
|
|
4586
|
-
//#region
|
|
4587
|
-
|
|
4588
|
-
|
|
4589
|
-
|
|
4590
|
-
|
|
4591
|
-
|
|
4592
|
-
|
|
4593
|
-
|
|
4594
|
-
const parentWhere = `:where(${"." + escapeCssIdent(getScopeClassName(className, scopeClassNameFormat)) + getSelectorText(parentSelector)})`;
|
|
4595
|
-
selectorStr = classSelector + parentWhere + itemSelector + "," + parentWhere + " " + selectorStr;
|
|
4596
|
-
}
|
|
4597
|
-
let rule = `${selectorStr}{${cssProp}: ${cssValue}}`;
|
|
4598
|
-
if (atRules) for (let i = atRules.length - 1; i >= 0; i--) rule = `${getSelectorText(atRules[i])}{${rule}}`;
|
|
4599
|
-
return rule;
|
|
4600
|
-
}
|
|
4601
|
-
function getAtomicRuleLayerPriority(property, priority, selector, parentSelector, atRules, isScopeRule = false) {
|
|
4602
|
-
const selectorPriority = getSelectorPriority(selector);
|
|
4603
|
-
const parentSelectorPriority = getSelectorPriority(parentSelector);
|
|
4604
|
-
const atRulePriority = getAtRulePriority$1(atRules);
|
|
4605
|
-
return [
|
|
4606
|
-
priority ?? 0,
|
|
4607
|
-
getLayerSelectorPriority(selector, parentSelector, selectorPriority),
|
|
4608
|
-
getParentSelectorPriority(parentSelector, parentSelectorPriority),
|
|
4609
|
-
getMediaPriority(atRules, atRulePriority),
|
|
4610
|
-
atRules ? atRules.length : 0,
|
|
4611
|
-
isScopeRule && !parentSelector ? 1 : 0,
|
|
4612
|
-
getPropertyPriority(property)
|
|
4613
|
-
];
|
|
4614
|
-
}
|
|
4615
|
-
function getMediaPriority(atRules, priority) {
|
|
4616
|
-
if (!atRules?.length) return LayerMediaPriorities.base;
|
|
4617
|
-
if (priority <= 0) return LayerMediaPriorities.media;
|
|
4618
|
-
return LayerMediaPriorities.priorityMedia + priority;
|
|
4619
|
-
}
|
|
4620
|
-
function getLayerSelectorPriority(selector, parentSelector, priority) {
|
|
4621
|
-
if (selector) return priority > 0 ? LayerSelectorPriorities.prioritySelector + priority : LayerSelectorPriorities.selector;
|
|
4622
|
-
if (parentSelector) return LayerSelectorPriorities.parentSelector;
|
|
4623
|
-
return LayerSelectorPriorities.base;
|
|
4624
|
-
}
|
|
4625
|
-
function getParentSelectorPriority(parentSelector, priority) {
|
|
4626
|
-
if (!parentSelector) return 0;
|
|
4627
|
-
return priority > 0 ? priority + 1 : 1;
|
|
4628
|
-
}
|
|
4629
|
-
function getAtRulePriority$1(atRules) {
|
|
4630
|
-
if (!atRules?.length) return 0;
|
|
4631
|
-
let priority = 0;
|
|
4632
|
-
for (let i = 0, len = atRules.length; i < len; i++) priority = Math.max(priority, getSelectorPriority(atRules[i]));
|
|
4633
|
-
return priority;
|
|
4634
|
-
}
|
|
5738
|
+
//#region compiler/compiler/constants.ts
|
|
5739
|
+
let CompilerRuntimeMode = /* @__PURE__ */ function(CompilerRuntimeMode) {
|
|
5740
|
+
CompilerRuntimeMode["Dev"] = "dev";
|
|
5741
|
+
CompilerRuntimeMode["Prod"] = "prod";
|
|
5742
|
+
CompilerRuntimeMode["RscDev"] = "rsc-dev";
|
|
5743
|
+
CompilerRuntimeMode["RscProd"] = "rsc-prod";
|
|
5744
|
+
return CompilerRuntimeMode;
|
|
5745
|
+
}({});
|
|
4635
5746
|
//#endregion
|
|
4636
5747
|
//#region compiler/transform/extract/chain/extract_chain.ts
|
|
4637
5748
|
const STATIC_MERGE_METHOD = "$$style.merge";
|
|
4638
|
-
function extractStyleChain(node, styleNames) {
|
|
5749
|
+
function extractStyleChain(node, styleNames, sheetNames = /* @__PURE__ */ new Set()) {
|
|
4639
5750
|
if (node.type !== "CallExpression") return null;
|
|
4640
5751
|
const callee = node.callee;
|
|
4641
5752
|
if (callee.type === "Identifier" && styleNames.has(callee.name)) return {
|
|
@@ -4644,6 +5755,12 @@ function extractStyleChain(node, styleNames) {
|
|
|
4644
5755
|
baseArgs: node.arguments,
|
|
4645
5756
|
methods: []
|
|
4646
5757
|
};
|
|
5758
|
+
if (callee.type === "Identifier" && sheetNames.has(callee.name)) return {
|
|
5759
|
+
kind: "sheet",
|
|
5760
|
+
rootName: callee.name,
|
|
5761
|
+
baseArgs: node.arguments,
|
|
5762
|
+
methods: []
|
|
5763
|
+
};
|
|
4647
5764
|
if (callee.type === "MemberExpression" && !callee.computed) {
|
|
4648
5765
|
const prop = callee.property.type === "Identifier" ? callee.property.name : null;
|
|
4649
5766
|
if (!prop) return null;
|
|
@@ -4661,10 +5778,16 @@ function extractStyleChain(node, styleNames) {
|
|
|
4661
5778
|
baseArgs: node.arguments,
|
|
4662
5779
|
methods: []
|
|
4663
5780
|
};
|
|
5781
|
+
if (prop === "selector") return {
|
|
5782
|
+
kind: "selector",
|
|
5783
|
+
rootName: obj.name,
|
|
5784
|
+
baseArgs: node.arguments,
|
|
5785
|
+
methods: []
|
|
5786
|
+
};
|
|
4664
5787
|
if (prop !== "merge") return null;
|
|
4665
5788
|
const target = node.arguments[0];
|
|
4666
5789
|
if (!target) return null;
|
|
4667
|
-
const targetChain = extractStyleChain(target, styleNames);
|
|
5790
|
+
const targetChain = extractStyleChain(target, styleNames, sheetNames);
|
|
4668
5791
|
if (!targetChain) return null;
|
|
4669
5792
|
return {
|
|
4670
5793
|
...targetChain,
|
|
@@ -4676,7 +5799,7 @@ function extractStyleChain(node, styleNames) {
|
|
|
4676
5799
|
};
|
|
4677
5800
|
}
|
|
4678
5801
|
if (obj.type === "CallExpression") {
|
|
4679
|
-
const inner = extractStyleChain(obj, styleNames);
|
|
5802
|
+
const inner = extractStyleChain(obj, styleNames, sheetNames);
|
|
4680
5803
|
if (!inner) return null;
|
|
4681
5804
|
return {
|
|
4682
5805
|
...inner,
|
|
@@ -4692,15 +5815,113 @@ function extractStyleChain(node, styleNames) {
|
|
|
4692
5815
|
}
|
|
4693
5816
|
//#endregion
|
|
4694
5817
|
//#region compiler/transform/extract/chain/chain.ts
|
|
4695
|
-
function applyTransform(styleObj, transform) {
|
|
4696
|
-
|
|
5818
|
+
function applyTransform(styleObj, transform, cssConfig) {
|
|
5819
|
+
if (!transform) return styleObj;
|
|
5820
|
+
const input = transformRuntimeValues(styleObj, transform, cssConfig);
|
|
5821
|
+
return carryTransformedLocations(input, transform.transform(input), transform);
|
|
5822
|
+
}
|
|
5823
|
+
function transformRuntimeValues(styleObj, transform, cssConfig) {
|
|
5824
|
+
let result = null;
|
|
5825
|
+
for (const [property, rawValue] of Object.entries(styleObj)) {
|
|
5826
|
+
const weighted = isStyleWeightValue(rawValue) ? rawValue : null;
|
|
5827
|
+
const runtimeValue = getCompiledRuntimeValue(weighted ? weighted.value : rawValue);
|
|
5828
|
+
if (!runtimeValue) continue;
|
|
5829
|
+
const transformedRuntimeValue = transformRuntimeExpression(property, runtimeValue, transform, cssConfig);
|
|
5830
|
+
if (transformedRuntimeValue === runtimeValue) continue;
|
|
5831
|
+
result ??= cloneCompiledStyleObject(styleObj);
|
|
5832
|
+
const transformed = createCompiledRuntimeValue(transformedRuntimeValue);
|
|
5833
|
+
result[property] = weighted ? weightValue(transformed, weighted.weight) : transformed;
|
|
5834
|
+
}
|
|
5835
|
+
return result ?? styleObj;
|
|
5836
|
+
}
|
|
5837
|
+
function cloneCompiledStyleObject(styleObj) {
|
|
5838
|
+
const cloned = { ...styleObj };
|
|
5839
|
+
const locations = styleObj[COMPILED_STYLE_OBJECT_LOCATIONS];
|
|
5840
|
+
if (locations) Object.defineProperty(cloned, COMPILED_STYLE_OBJECT_LOCATIONS, {
|
|
5841
|
+
configurable: true,
|
|
5842
|
+
enumerable: false,
|
|
5843
|
+
value: locations
|
|
5844
|
+
});
|
|
5845
|
+
return cloned;
|
|
5846
|
+
}
|
|
5847
|
+
function createCompiledRuntimeValue(runtimeValue) {
|
|
5848
|
+
return { [COMPILED_RUNTIME_VALUE]: runtimeValue };
|
|
5849
|
+
}
|
|
5850
|
+
function transformRuntimeExpression(property, expression, transform, cssConfig) {
|
|
5851
|
+
if (expression.type === "StringLiteral") return createPrimitiveExpression(expression, normalizeRuntimeTransformedValue(getSingleTransformedValue(transform.transform({ [property]: expression.value })), cssConfig)) ?? expression;
|
|
5852
|
+
if (expression.type === "ConditionalExpression") {
|
|
5853
|
+
const consequent = transformRuntimeExpression(property, expression.consequent, transform, cssConfig);
|
|
5854
|
+
const alternate = transformRuntimeExpression(property, expression.alternate, transform, cssConfig);
|
|
5855
|
+
return consequent === expression.consequent && alternate === expression.alternate ? expression : {
|
|
5856
|
+
...expression,
|
|
5857
|
+
consequent,
|
|
5858
|
+
alternate
|
|
5859
|
+
};
|
|
5860
|
+
}
|
|
5861
|
+
return expression;
|
|
5862
|
+
}
|
|
5863
|
+
function getSingleTransformedValue(transformed) {
|
|
5864
|
+
const values = Object.values(transformed);
|
|
5865
|
+
if (!values.length) return void 0;
|
|
5866
|
+
return values[0];
|
|
5867
|
+
}
|
|
5868
|
+
function normalizeRuntimeTransformedValue(value, cssConfig) {
|
|
5869
|
+
if (isStyleTokenOverrideData(value)) return getTokenOverrideValue(value, cssConfig.tokenNameFormat);
|
|
5870
|
+
if (isStyleTokenData(value)) return getTokenVar(value, cssConfig.tokenNameFormat);
|
|
5871
|
+
return value;
|
|
5872
|
+
}
|
|
5873
|
+
function createPrimitiveExpression(original, value) {
|
|
5874
|
+
if (original.type === "StringLiteral" && value === original.value) return null;
|
|
5875
|
+
if (typeof value === "string") return {
|
|
5876
|
+
...original,
|
|
5877
|
+
type: "StringLiteral",
|
|
5878
|
+
value
|
|
5879
|
+
};
|
|
5880
|
+
if (typeof value === "number") return {
|
|
5881
|
+
...original,
|
|
5882
|
+
type: "NumericLiteral",
|
|
5883
|
+
value
|
|
5884
|
+
};
|
|
5885
|
+
if (typeof value === "boolean") return {
|
|
5886
|
+
...original,
|
|
5887
|
+
type: "BooleanLiteral",
|
|
5888
|
+
value
|
|
5889
|
+
};
|
|
5890
|
+
if (value === null) return {
|
|
5891
|
+
...original,
|
|
5892
|
+
type: "NullLiteral"
|
|
5893
|
+
};
|
|
5894
|
+
return null;
|
|
5895
|
+
}
|
|
5896
|
+
function carryTransformedLocations(input, transformed, transform) {
|
|
5897
|
+
const inputLocations = input[COMPILED_STYLE_OBJECT_LOCATIONS];
|
|
5898
|
+
if (!inputLocations) return transformed;
|
|
5899
|
+
const locations = { ...transformed[COMPILED_STYLE_OBJECT_LOCATIONS] };
|
|
5900
|
+
for (const [property, loc] of Object.entries(inputLocations)) {
|
|
5901
|
+
if (property in transformed && !locations[property]) locations[property] = loc;
|
|
5902
|
+
const single = transform.transform({ [property]: input[property] });
|
|
5903
|
+
for (const transformedProperty of Object.keys(single)) locations[transformedProperty] ??= loc;
|
|
5904
|
+
}
|
|
5905
|
+
if (!Object.keys(locations).length) return transformed;
|
|
5906
|
+
Object.defineProperty(transformed, COMPILED_STYLE_OBJECT_LOCATIONS, {
|
|
5907
|
+
configurable: true,
|
|
5908
|
+
enumerable: false,
|
|
5909
|
+
value: locations
|
|
5910
|
+
});
|
|
5911
|
+
return transformed;
|
|
4697
5912
|
}
|
|
4698
5913
|
/**
|
|
4699
5914
|
* Compile a parsed chain into extracted items and CSS rules.
|
|
4700
5915
|
* Returns null if any argument cannot be statically evaluated.
|
|
4701
5916
|
*/
|
|
4702
|
-
function compileChain(chain, fileId, nodeLoc, scope, opts, meta, styleNames = /* @__PURE__ */ new Set()) {
|
|
4703
|
-
const css = getCssConfig(opts);
|
|
5917
|
+
function compileChain(chain, fileId, nodeLoc, scope, opts, runtimeMode, meta, styleNames = /* @__PURE__ */ new Set()) {
|
|
5918
|
+
const css = getCssConfig(opts, runtimeMode);
|
|
5919
|
+
if (chain.kind === "sheet") return compileSheetChain(chain, fileId, scope, css, opts);
|
|
5920
|
+
if (!meta) return null;
|
|
5921
|
+
if (meta.mode === "ClassName") {
|
|
5922
|
+
if (chain.kind !== "style") return null;
|
|
5923
|
+
return compileClassNameChain(chain, meta.selectors, fileId, nodeLoc, scope, css, meta.transform, styleNames, opts);
|
|
5924
|
+
}
|
|
4704
5925
|
const selectors = meta.selectors;
|
|
4705
5926
|
const transform = meta.transform;
|
|
4706
5927
|
if (chain.kind === "style") return compileStyleChain(chain, selectors, fileId, scope, css, transform, styleNames, opts);
|
|
@@ -4708,13 +5929,120 @@ function compileChain(chain, fileId, nodeLoc, scope, opts, meta, styleNames = /*
|
|
|
4708
5929
|
if (chain.kind === "scope") return compileScopeChain(chain, selectors, fileId, scope, css, transform, opts);
|
|
4709
5930
|
return null;
|
|
4710
5931
|
}
|
|
4711
|
-
function
|
|
5932
|
+
function compileSheetChain(chain, fileId, scope, cssConfig, options) {
|
|
5933
|
+
if (chain.methods.length > 0 || chain.baseArgs.length > 2) return null;
|
|
5934
|
+
const items = [];
|
|
5935
|
+
const rules = [];
|
|
5936
|
+
const hasOptions = chain.baseArgs.length === 2;
|
|
5937
|
+
const sheetOptions = hasOptions ? evaluateCreateSheetOptions(chain.baseArgs[0], scope) : {};
|
|
5938
|
+
if (!sheetOptions) return null;
|
|
5939
|
+
const sheetItems = chain.baseArgs[hasOptions ? 1 : 0];
|
|
5940
|
+
if (sheetItems && !compileSheetItemsArg(sheetItems, fileId, scope, cssConfig, options, items, rules, sheetOptions)) return null;
|
|
5941
|
+
const sheetLayer = sheetOptions.layer ?? isSheetLayerEnabled(options.css?.layer ?? DEFAULT_CONFIG.layer);
|
|
5942
|
+
for (let i = 0, len = rules.length; i < len; i++) rules[i].layer = sheetLayer ? "sheet" : false;
|
|
5943
|
+
return {
|
|
5944
|
+
type: "sheet",
|
|
5945
|
+
items,
|
|
5946
|
+
rules,
|
|
5947
|
+
sheetOptions
|
|
5948
|
+
};
|
|
5949
|
+
}
|
|
5950
|
+
function evaluateCreateSheetOptions(node, scope) {
|
|
5951
|
+
const result = evaluateNode(node, scope);
|
|
5952
|
+
if (!result.ok || !result.value || typeof result.value !== "object" || Array.isArray(result.value)) return null;
|
|
5953
|
+
const value = result.value;
|
|
5954
|
+
if (Object.keys(value).some((key) => key !== "layer" && key !== "weight")) return null;
|
|
5955
|
+
if (value.layer !== void 0 && typeof value.layer !== "boolean") return null;
|
|
5956
|
+
if (value.weight !== void 0 && (!Number.isInteger(value.weight) || value.weight < 1)) return null;
|
|
5957
|
+
return {
|
|
5958
|
+
layer: value.layer,
|
|
5959
|
+
weight: value.weight
|
|
5960
|
+
};
|
|
5961
|
+
}
|
|
5962
|
+
function compileSheetItemsArg(node, fileId, scope, cssConfig, options, items, rules, sheetOptions) {
|
|
5963
|
+
if (node.type === "ArrayExpression") {
|
|
5964
|
+
for (const element of node.elements) {
|
|
5965
|
+
if (!element) continue;
|
|
5966
|
+
if (element.type === "SpreadElement") return false;
|
|
5967
|
+
if (!compileSheetItemsArg(element, fileId, scope, cssConfig, options, items, rules, sheetOptions)) return false;
|
|
5968
|
+
}
|
|
5969
|
+
return true;
|
|
5970
|
+
}
|
|
5971
|
+
const tokenOverride = evaluateNode(node, scope);
|
|
5972
|
+
if (tokenOverride.ok && isStyleTokenOverrideData(tokenOverride.value)) {
|
|
5973
|
+
addCompiledTokenItem(getStyleTokenId(tokenOverride.value), tokenOverride.value, getCompiledRuntimeValue(tokenOverride.value) ?? node, items);
|
|
5974
|
+
return true;
|
|
5975
|
+
}
|
|
5976
|
+
if (tokenOverride.ok && Array.isArray(tokenOverride.value)) {
|
|
5977
|
+
for (let i = 0, len = tokenOverride.value.length; i < len; i++) {
|
|
5978
|
+
const item = tokenOverride.value[i];
|
|
5979
|
+
if (!item) continue;
|
|
5980
|
+
if (!isStyleTokenOverrideData(item)) return false;
|
|
5981
|
+
addCompiledTokenItem(getStyleTokenId(item), item, getCompiledRuntimeValue(item) ?? null, items);
|
|
5982
|
+
}
|
|
5983
|
+
return true;
|
|
5984
|
+
}
|
|
5985
|
+
const styleNames = scope.styleNames ?? /* @__PURE__ */ new Set();
|
|
5986
|
+
const sheetNames = scope.sheetNames ?? /* @__PURE__ */ new Set();
|
|
5987
|
+
const selectorChain = node.type === "CallExpression" ? extractStyleChain(node, styleNames, sheetNames) ?? getLocalSelectorTargetChain(node, scope, styleNames, sheetNames) : getLocalStyleChainArg(node, scope, styleNames, sheetNames);
|
|
5988
|
+
const selectorMeta = selectorChain ? scope.styleMetas?.get(selectorChain.rootName) : null;
|
|
5989
|
+
if (selectorChain?.kind !== "selector" || !selectorMeta || selectorMeta.mode !== "StyleObject") return false;
|
|
5990
|
+
return compileSelectorOverrideChain(selectorChain, selectorMeta.selectors, fileId, scope, cssConfig, selectorMeta.transform, scope.styleNames ?? /* @__PURE__ */ new Set(), options, items, rules, sheetOptions);
|
|
5991
|
+
}
|
|
5992
|
+
function compileSelectorOverrideChain(chain, selectors, fileId, scope, cssConfig, transform, styleNames, options, items, rules, sheetOptions) {
|
|
5993
|
+
if (chain.baseArgs.length === 0 || chain.baseArgs.length > 2) return false;
|
|
5994
|
+
const selectorArg = evaluateNode(chain.baseArgs[0], scope);
|
|
5995
|
+
if (!selectorArg.ok) return false;
|
|
5996
|
+
const manualSelectors = normalizeManualSelectors(Array.isArray(selectorArg.value) ? selectorArg.value.map(String) : String(selectorArg.value ?? ""));
|
|
5997
|
+
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;
|
|
5998
|
+
return true;
|
|
5999
|
+
}
|
|
6000
|
+
function compileSelectorOverrideInto(chain, selectors, fileId, scope, cssConfig, transform, styleNames, options, items, rules, selectorPrefix) {
|
|
6001
|
+
if (chain.baseArgs[1]) {
|
|
6002
|
+
if (!compileSelectorStyleArg(chain.baseArgs[1], fileId, scope, cssConfig, transform, items, rules, styleNames, options, selectorPrefix)) return false;
|
|
6003
|
+
}
|
|
6004
|
+
let i = 0;
|
|
6005
|
+
while (i < chain.methods.length) {
|
|
6006
|
+
const method = chain.methods[i];
|
|
6007
|
+
if (!compileChainMethod(method, selectors, null, fileId, scope, 1, cssConfig, items, rules, transform, null, styleNames, options, null, selectorPrefix)) return false;
|
|
6008
|
+
i++;
|
|
6009
|
+
}
|
|
6010
|
+
return true;
|
|
6011
|
+
}
|
|
6012
|
+
function compileSelectorStyleArg(styleArgNode, fileId, scope, cssConfig, transform, items, rules, styleNames, options, selectorPrefix) {
|
|
6013
|
+
const localChain = getLocalStyleChainArg(styleArgNode, scope, styleNames);
|
|
6014
|
+
const localMeta = localChain ? scope.styleMetas?.get(localChain.rootName) : null;
|
|
6015
|
+
if (localChain?.kind === "style" && localMeta) return compileStyleChainInto(localChain, localMeta.selectors, fileId, scope, cssConfig, localMeta.transform, 1, null, null, items, rules, styleNames, options, null, selectorPrefix);
|
|
6016
|
+
if (styleArgNode.type === "CallExpression") {
|
|
6017
|
+
const nestedChain = extractStyleChain(styleArgNode, styleNames);
|
|
6018
|
+
const nestedMeta = nestedChain ? scope.styleMetas?.get(nestedChain.rootName) : null;
|
|
6019
|
+
if (nestedChain?.kind === "style" && nestedMeta) return compileStyleChainInto(nestedChain, nestedMeta.selectors, fileId, scope, cssConfig, nestedMeta.transform, 1, null, null, items, rules, styleNames, options, null, selectorPrefix);
|
|
6020
|
+
}
|
|
6021
|
+
const styleArg = evaluateNode(styleArgNode, scope);
|
|
6022
|
+
if (!styleArg.ok) {
|
|
6023
|
+
throwIfRequiredStaticStyleValue(styleArg);
|
|
6024
|
+
return false;
|
|
6025
|
+
}
|
|
6026
|
+
if (isStyleData(styleArg.value)) return addStyleDataItems(styleArg.value, selectorPrefix, null, null, fileId, 1, null, items, rules, cssConfig, null);
|
|
6027
|
+
return addStyleItems(applyTransform(styleArg.value, transform, cssConfig), selectorPrefix, null, null, fileId, 1, null, items, rules, cssConfig, null);
|
|
6028
|
+
}
|
|
6029
|
+
function getCssConfig(opts, runtimeMode) {
|
|
4712
6030
|
const css = opts.css;
|
|
6031
|
+
const isDevRuntimeMode = runtimeMode === "dev" || runtimeMode === "rsc-dev";
|
|
6032
|
+
const debugClassName = css?.debugClassName ?? isDevRuntimeMode;
|
|
4713
6033
|
return {
|
|
4714
6034
|
classNameFormat: css?.classNameFormat ?? DEFAULT_CONFIG.classNameFormat ?? null,
|
|
6035
|
+
sheetClassNameFormat: css?.sheetClassNameFormat ?? DEFAULT_CONFIG.sheetClassNameFormat ?? null,
|
|
6036
|
+
transformClassNameFormat: css?.transformClassNameFormat ?? DEFAULT_CONFIG.transformClassNameFormat ?? null,
|
|
6037
|
+
hashLength: getClassNameHashLength({
|
|
6038
|
+
debugClassName,
|
|
6039
|
+
isDev: isDevRuntimeMode,
|
|
6040
|
+
cssHashLength: css?.hashLength ?? DEFAULT_CONFIG.hashLength
|
|
6041
|
+
}),
|
|
4715
6042
|
tokenNameFormat: css?.tokenNameFormat ?? DEFAULT_CONFIG.tokenNameFormat ?? null,
|
|
4716
|
-
localClassName:
|
|
4717
|
-
debugClassName
|
|
6043
|
+
localClassName: isDevRuntimeMode,
|
|
6044
|
+
debugClassName,
|
|
6045
|
+
runtimeMode,
|
|
4718
6046
|
scopeTargetPrefix: css?.scopeTargetPrefix ?? ""
|
|
4719
6047
|
};
|
|
4720
6048
|
}
|
|
@@ -4732,19 +6060,179 @@ function compileStyleChain(chain, selectors, fileId, scope, cssConfig, transform
|
|
|
4732
6060
|
rules
|
|
4733
6061
|
};
|
|
4734
6062
|
}
|
|
4735
|
-
function
|
|
6063
|
+
function compileClassNameChain(chain, selectors, fileId, nodeLoc, scope, cssConfig, transform, styleNames, options) {
|
|
6064
|
+
const items = [];
|
|
6065
|
+
const rules = [];
|
|
6066
|
+
if (!compileClassNameArgsInto(chain.baseArgs, 0, null, null, fileId, scope, createClassNameFallbackLocation(nodeLoc, scope, fileId), cssConfig, transform, 1, null, items, rules)) return null;
|
|
6067
|
+
let i = 0;
|
|
6068
|
+
while (i < chain.methods.length) {
|
|
6069
|
+
const method = chain.methods[i];
|
|
6070
|
+
if (!compileClassNameChainMethod(method, selectors, fileId, scope, cssConfig, transform, items, rules, styleNames, options)) return null;
|
|
6071
|
+
i++;
|
|
6072
|
+
}
|
|
6073
|
+
return {
|
|
6074
|
+
type: "style",
|
|
6075
|
+
items,
|
|
6076
|
+
rules
|
|
6077
|
+
};
|
|
6078
|
+
}
|
|
6079
|
+
function compileClassNameChainMethod(method, selectors, fileId, scope, cssConfig, transform, items, rules, styleNames, options) {
|
|
6080
|
+
const selector = selectors[method.name];
|
|
6081
|
+
if (!selector) return false;
|
|
6082
|
+
validateSelectorDefinition(options.dev?.checkSelector, `style.${method.name}`, selector, method.nameNode);
|
|
6083
|
+
const selectorStr = selector.selector.trim();
|
|
6084
|
+
if (selectorStr === "...") {
|
|
6085
|
+
const localChain = getLocalStyleChainArg(method.args[0], scope, styleNames);
|
|
6086
|
+
const localMeta = localChain ? scope.styleMetas?.get(localChain.rootName) : null;
|
|
6087
|
+
if (localChain?.kind === "style" && localMeta?.mode === "ClassName") {
|
|
6088
|
+
const result = compileClassNameChain(localChain, localMeta.selectors, fileId, method.nameNode.loc?.start, scope, cssConfig, localMeta.transform, styleNames, options);
|
|
6089
|
+
if (!result) return false;
|
|
6090
|
+
items.push(...result.items);
|
|
6091
|
+
rules.push(...result.rules);
|
|
6092
|
+
return true;
|
|
6093
|
+
}
|
|
6094
|
+
return false;
|
|
6095
|
+
}
|
|
6096
|
+
if (selectorStr.startsWith("@")) {
|
|
6097
|
+
const isMedia = selectorStr.startsWith("@media") || selectorStr.startsWith("@container");
|
|
6098
|
+
const hasArg = selectorStr.includes("$$");
|
|
6099
|
+
const priority = getAtRulePriority(selector.priority, isMedia, method.args[0]);
|
|
6100
|
+
let argOffset = 0;
|
|
6101
|
+
if (isMedia && isNumericLiteral(method.args[0])) argOffset = 1;
|
|
6102
|
+
let atRule = selectorStr;
|
|
6103
|
+
if (hasArg) {
|
|
6104
|
+
const queryArg = evaluateNode(method.args[argOffset], scope);
|
|
6105
|
+
validateResolvedSelectorValue(options.dev?.checkSelector, `style.${method.name}`, selector, queryArg, method.args[argOffset]);
|
|
6106
|
+
throwIfRequiredStaticSelectorValue(options, `style.${method.name}`, queryArg);
|
|
6107
|
+
if (!queryArg.ok) return false;
|
|
6108
|
+
const [before, after] = selectorStr.split("$$");
|
|
6109
|
+
atRule = before + String(queryArg.value) + (after ?? "");
|
|
6110
|
+
}
|
|
6111
|
+
const atRuleSelector = priority !== null ? [atRule, priority] : atRule;
|
|
6112
|
+
const classNameOffset = hasArg ? argOffset + 1 : argOffset;
|
|
6113
|
+
return compileClassNameArgsInto(method.args, classNameOffset, null, [atRuleSelector], fileId, scope, createClassNameFallbackLocation(method.nameNode.loc?.start, scope, fileId), cssConfig, transform, 1, null, items, rules);
|
|
6114
|
+
}
|
|
6115
|
+
if (selectorStr.includes("$$") || selectorStr.includes("$")) {
|
|
6116
|
+
const splitToken = selectorStr.includes("$$") ? "$$" : "$";
|
|
6117
|
+
const [before, after] = selectorStr.split(splitToken);
|
|
6118
|
+
const selectorArg = evaluateNode(method.args[0], scope);
|
|
6119
|
+
validateResolvedSelectorValue(options.dev?.checkSelector, `style.${method.name}`, selector, selectorArg, method.args[0]);
|
|
6120
|
+
if (!selectorArg.ok) return false;
|
|
6121
|
+
const selectorText = before + normalizeSelectorArg(String(selectorArg.value ?? "")) + (after ?? "");
|
|
6122
|
+
const itemSelector = selector.priority !== null ? [selectorText, selector.priority] : selectorText;
|
|
6123
|
+
return compileClassNameArgsInto(method.args, 1, itemSelector, null, fileId, scope, createClassNameFallbackLocation(method.nameNode.loc?.start, scope, fileId), cssConfig, transform, 1, null, items, rules);
|
|
6124
|
+
}
|
|
6125
|
+
const itemSelector = selector.priority !== null ? [selectorStr, selector.priority] : selectorStr;
|
|
6126
|
+
return compileClassNameArgsInto(method.args, 0, itemSelector, null, fileId, scope, createClassNameFallbackLocation(method.nameNode.loc?.start, scope, fileId), cssConfig, transform, 1, null, items, rules);
|
|
6127
|
+
}
|
|
6128
|
+
function compileClassNameArgsInto(args, startIndex, selector, atRules, fileId, scope, fallbackLocation, cssConfig, transform, type, slotId, items, rules) {
|
|
6129
|
+
if (startIndex >= args.length) return true;
|
|
6130
|
+
const styleObj = {};
|
|
6131
|
+
const locations = {};
|
|
6132
|
+
let i = startIndex;
|
|
6133
|
+
while (i < args.length) {
|
|
6134
|
+
const arg = evaluateNode(args[i], scope);
|
|
6135
|
+
if (!arg.ok) {
|
|
6136
|
+
throwIfRequiredStaticStyleValue(arg);
|
|
6137
|
+
return false;
|
|
6138
|
+
}
|
|
6139
|
+
if (!appendClassNameArgStyle(args[i], arg.value, transform, styleObj, locations, fallbackLocation, scope, fileId)) return false;
|
|
6140
|
+
i++;
|
|
6141
|
+
}
|
|
6142
|
+
if (Object.keys(locations).length) Object.defineProperty(styleObj, COMPILED_STYLE_OBJECT_LOCATIONS, {
|
|
6143
|
+
configurable: true,
|
|
6144
|
+
enumerable: false,
|
|
6145
|
+
value: locations
|
|
6146
|
+
});
|
|
6147
|
+
return addStyleItems(styleObj, selector, null, atRules, fileId, type, slotId, items, rules, cssConfig);
|
|
6148
|
+
}
|
|
6149
|
+
function appendClassNameArgStyle(node, value, transform, styleObj, locations, fallbackLocation, scope, fileId) {
|
|
6150
|
+
if (!value) return true;
|
|
6151
|
+
if (typeof value === "string") {
|
|
6152
|
+
const transformed = decorateClassNameStyle(transform.transform(value), value);
|
|
6153
|
+
Object.assign(styleObj, transformed);
|
|
6154
|
+
assignClassNameStyleLocations(transformed, locations, getClassNameArgLocation(node, fallbackLocation, scope, fileId));
|
|
6155
|
+
return true;
|
|
6156
|
+
}
|
|
6157
|
+
if (Array.isArray(value)) {
|
|
6158
|
+
const nodes = node.type === "ArrayExpression" ? node.elements : [];
|
|
6159
|
+
for (let i = 0; i < value.length; i++) if (!appendClassNameArgStyle(nodes[i] ?? node, value[i], transform, styleObj, locations, fallbackLocation, scope, fileId)) return false;
|
|
6160
|
+
return true;
|
|
6161
|
+
}
|
|
6162
|
+
if (isWeightedClassName(value)) {
|
|
6163
|
+
const transformed = decorateClassNameStyle(transform.transform(value.className), value.className);
|
|
6164
|
+
Object.assign(styleObj, applyClassNameWeight(transformed, value.weight));
|
|
6165
|
+
assignClassNameStyleLocations(transformed, locations, getWeightedClassNameArgLocation(node, fallbackLocation, scope, fileId));
|
|
6166
|
+
return true;
|
|
6167
|
+
}
|
|
6168
|
+
return false;
|
|
6169
|
+
}
|
|
6170
|
+
function assignClassNameStyleLocations(styleObj, locations, location) {
|
|
6171
|
+
if (!location) return;
|
|
6172
|
+
for (const property of Object.keys(styleObj)) locations[property] = location;
|
|
6173
|
+
}
|
|
6174
|
+
function getClassNameArgLocation(node, fallbackLocation, scope, fileId) {
|
|
6175
|
+
if (node.type === "StringLiteral") return createClassNameFallbackLocation(node.loc?.start, scope, fileId);
|
|
6176
|
+
if (node.type === "TemplateLiteral" && node.expressions.length === 0) return createClassNameFallbackLocation(node.loc?.start, scope, fileId);
|
|
6177
|
+
return fallbackLocation;
|
|
6178
|
+
}
|
|
6179
|
+
function getWeightedClassNameArgLocation(node, fallbackLocation, scope, fileId) {
|
|
6180
|
+
if (node.type === "CallExpression" && node.arguments[0] && node.callee.type === "MemberExpression" && !node.callee.computed && node.callee.property.type === "Identifier" && node.callee.property.name === "weight") return getClassNameArgLocation(node.arguments[0], fallbackLocation, scope, fileId);
|
|
6181
|
+
return fallbackLocation;
|
|
6182
|
+
}
|
|
6183
|
+
function createClassNameFallbackLocation(loc, scope, fileId) {
|
|
6184
|
+
if (!loc) return null;
|
|
6185
|
+
return {
|
|
6186
|
+
filePath: scope.styleFilePath ?? fileId,
|
|
6187
|
+
line: loc.line,
|
|
6188
|
+
column: loc.column + 1,
|
|
6189
|
+
variable: false
|
|
6190
|
+
};
|
|
6191
|
+
}
|
|
6192
|
+
function decorateClassNameStyle(style, className) {
|
|
6193
|
+
const result = {};
|
|
6194
|
+
for (const [property, value] of Object.entries(style)) {
|
|
6195
|
+
if (value === null || value === void 0) {
|
|
6196
|
+
result[property] = value;
|
|
6197
|
+
continue;
|
|
6198
|
+
}
|
|
6199
|
+
result[property] = decorateClassNameValue(value, className);
|
|
6200
|
+
}
|
|
6201
|
+
return result;
|
|
6202
|
+
}
|
|
6203
|
+
function decorateClassNameValue(value, className) {
|
|
6204
|
+
if (isClassNameValue(value)) return value;
|
|
6205
|
+
if (isStyleImportantValue(value)) return importantValue(decorateClassNameValue(value.value, className));
|
|
6206
|
+
if (isStyleWeightValue(value)) return weightValue(decorateClassNameValue(value.value, className), value.weight);
|
|
6207
|
+
return classNameValue(value, className);
|
|
6208
|
+
}
|
|
6209
|
+
function isWeightedClassName(value) {
|
|
6210
|
+
return !!value && typeof value === "object" && typeof value.className === "string" && typeof value.weight === "number";
|
|
6211
|
+
}
|
|
6212
|
+
function applyClassNameWeight(style, weight) {
|
|
6213
|
+
const weighted = {};
|
|
6214
|
+
for (const [property, value] of Object.entries(style)) {
|
|
6215
|
+
if (value === null || value === void 0) {
|
|
6216
|
+
weighted[property] = value;
|
|
6217
|
+
continue;
|
|
6218
|
+
}
|
|
6219
|
+
weighted[property] = weightValue(value, weight);
|
|
6220
|
+
}
|
|
6221
|
+
return weighted;
|
|
6222
|
+
}
|
|
6223
|
+
function compileStyleChainInto(chain, selectors, fileId, scope, cssConfig, transform, type, slotId, atRules, items, rules, styleNames, options, callsiteOverride = null, selectorPrefix = null) {
|
|
4736
6224
|
if (chain.baseArgs.length > 0) {
|
|
4737
6225
|
const styleArg = evaluateNode(chain.baseArgs[0], scope);
|
|
4738
6226
|
if (!styleArg.ok) {
|
|
4739
6227
|
throwIfRequiredStaticStyleValue(styleArg);
|
|
4740
6228
|
return false;
|
|
4741
6229
|
}
|
|
4742
|
-
if (!addStyleItems(applyTransform(styleArg.value, transform),
|
|
6230
|
+
if (!addStyleItems(applyTransform(styleArg.value, transform, cssConfig), selectorPrefix, null, atRules, fileId, type, slotId, items, rules, cssConfig, callsiteOverride)) return false;
|
|
4743
6231
|
}
|
|
4744
6232
|
let i = 0;
|
|
4745
6233
|
while (i < chain.methods.length) {
|
|
4746
6234
|
const method = chain.methods[i];
|
|
4747
|
-
if (!compileChainMethod(method, selectors, slotId, fileId, scope, type, cssConfig, items, rules, transform, atRules, styleNames, options, callsiteOverride)) return false;
|
|
6235
|
+
if (!compileChainMethod(method, selectors, slotId, fileId, scope, type, cssConfig, items, rules, transform, atRules, styleNames, options, callsiteOverride, selectorPrefix)) return false;
|
|
4748
6236
|
i++;
|
|
4749
6237
|
}
|
|
4750
6238
|
return true;
|
|
@@ -4758,7 +6246,7 @@ function compileSlotChain(chain, slotId, selectors, fileId, scope, cssConfig, tr
|
|
|
4758
6246
|
throwIfRequiredStaticStyleValue(styleArg);
|
|
4759
6247
|
return null;
|
|
4760
6248
|
}
|
|
4761
|
-
if (!addStyleItems(applyTransform(styleArg.value, transform), null, null, null, fileId, 2, slotId, items, rules, cssConfig)) return null;
|
|
6249
|
+
if (!addStyleItems(applyTransform(styleArg.value, transform, cssConfig), null, null, null, fileId, 2, slotId, items, rules, cssConfig)) return null;
|
|
4762
6250
|
}
|
|
4763
6251
|
let i = 0;
|
|
4764
6252
|
while (i < chain.methods.length) {
|
|
@@ -4791,7 +6279,7 @@ function compileScopeChain(chain, selectors, fileId, scope, cssConfig, transform
|
|
|
4791
6279
|
rules
|
|
4792
6280
|
};
|
|
4793
6281
|
}
|
|
4794
|
-
function compileScopeMethod(method, selectors, fileId, scope, cssConfig, items, cssRules, transform, options, callsiteOverride = null) {
|
|
6282
|
+
function compileScopeMethod(method, selectors, fileId, scope, cssConfig, items, cssRules, transform, options, callsiteOverride = null, _selectorPrefix = null) {
|
|
4795
6283
|
const selector = selectors[method.name];
|
|
4796
6284
|
if (!selector) return false;
|
|
4797
6285
|
validateSelectorDefinition(options.dev?.checkSelector, `style.${method.name}`, selector, method.nameNode);
|
|
@@ -4876,14 +6364,14 @@ function resolveSlotOverrideNode(node, parentSelector, atRules, selectors, fileI
|
|
|
4876
6364
|
return true;
|
|
4877
6365
|
}
|
|
4878
6366
|
if (node.type !== "CallExpression") return false;
|
|
4879
|
-
const overrideChain = extractOverrideChain(node, selectors, scope, fileId, transform, options);
|
|
6367
|
+
const overrideChain = extractOverrideChain(node, selectors, scope, fileId, cssConfig, transform, options);
|
|
4880
6368
|
if (!overrideChain) return false;
|
|
4881
6369
|
const { slotId, items: overrideItems } = overrideChain;
|
|
4882
6370
|
let i = 0;
|
|
4883
6371
|
while (i < overrideItems.length) {
|
|
4884
6372
|
const overrideItem = overrideItems[i];
|
|
4885
6373
|
const mergedAtRules = mergeAtRules(atRules, overrideItem.atRules);
|
|
4886
|
-
if (overrideItem.chain && overrideItem.meta) {
|
|
6374
|
+
if (overrideItem.chain && overrideItem.meta?.mode === "StyleObject") {
|
|
4887
6375
|
if (!compileStyleChainInto(overrideItem.chain, overrideItem.meta.selectors, fileId, scope, cssConfig, overrideItem.meta.transform, 4, slotId, mergedAtRules, items, cssRules, scope.styleNames ?? /* @__PURE__ */ new Set(), options, overrideItem.callsiteOverride)) return false;
|
|
4888
6376
|
} else if (overrideItem.styleData !== void 0) {
|
|
4889
6377
|
if (!addStyleDataItems(overrideItem.styleData, overrideItem.selector, parentSelector, mergedAtRules, fileId, 4, slotId, items, cssRules, cssConfig, overrideItem.callsiteOverride)) return false;
|
|
@@ -4892,15 +6380,15 @@ function resolveSlotOverrideNode(node, parentSelector, atRules, selectors, fileI
|
|
|
4892
6380
|
}
|
|
4893
6381
|
return true;
|
|
4894
6382
|
}
|
|
4895
|
-
function extractOverrideChain(node, selectors, scope, fileId, transform, options) {
|
|
6383
|
+
function extractOverrideChain(node, selectors, scope, fileId, cssConfig, transform, options) {
|
|
4896
6384
|
const callee = node.callee;
|
|
4897
6385
|
if (callee.type === "MemberExpression" && !callee.computed) {
|
|
4898
6386
|
const methodName = callee.property.name;
|
|
4899
6387
|
const obj = callee.object;
|
|
4900
6388
|
if (obj.type === "CallExpression") {
|
|
4901
|
-
const inner = extractOverrideChain(obj, selectors, scope, fileId, transform, options);
|
|
6389
|
+
const inner = extractOverrideChain(obj, selectors, scope, fileId, cssConfig, transform, options);
|
|
4902
6390
|
if (!inner) return null;
|
|
4903
|
-
const overrideItem = resolveOverrideMethod(methodName, node.arguments, callee.property, selectors, scope, transform, options);
|
|
6391
|
+
const overrideItem = resolveOverrideMethod(methodName, node.arguments, callee.property, selectors, scope, cssConfig, transform, options);
|
|
4904
6392
|
if (!overrideItem) return null;
|
|
4905
6393
|
return {
|
|
4906
6394
|
slotId: inner.slotId,
|
|
@@ -4915,7 +6403,7 @@ function extractOverrideChain(node, selectors, scope, fileId, transform, options
|
|
|
4915
6403
|
const styleArg = evaluateNode(node.arguments[0], scope);
|
|
4916
6404
|
if (!styleArg.ok) return null;
|
|
4917
6405
|
items.push({
|
|
4918
|
-
styleObj: applyTransform(styleArg.value ?? {}, transform),
|
|
6406
|
+
styleObj: applyTransform(styleArg.value ?? {}, transform, cssConfig),
|
|
4919
6407
|
selector: null,
|
|
4920
6408
|
atRules: null
|
|
4921
6409
|
});
|
|
@@ -4925,7 +6413,7 @@ function extractOverrideChain(node, selectors, scope, fileId, transform, options
|
|
|
4925
6413
|
items
|
|
4926
6414
|
};
|
|
4927
6415
|
}
|
|
4928
|
-
function resolveOverrideMethod(methodName, args, nameNode, selectors, scope, transform, options) {
|
|
6416
|
+
function resolveOverrideMethod(methodName, args, nameNode, selectors, scope, cssConfig, transform, options) {
|
|
4929
6417
|
const sel = selectors[methodName];
|
|
4930
6418
|
if (!sel) return null;
|
|
4931
6419
|
validateSelectorDefinition(options.dev?.checkSelector, `style.${methodName}`, sel);
|
|
@@ -4952,7 +6440,7 @@ function resolveOverrideMethod(methodName, args, nameNode, selectors, scope, tra
|
|
|
4952
6440
|
callsiteOverride
|
|
4953
6441
|
};
|
|
4954
6442
|
return {
|
|
4955
|
-
styleObj: applyTransform(styleArg.value ?? {}, transform),
|
|
6443
|
+
styleObj: applyTransform(styleArg.value ?? {}, transform, cssConfig),
|
|
4956
6444
|
selector: null,
|
|
4957
6445
|
atRules: null,
|
|
4958
6446
|
callsiteOverride
|
|
@@ -4977,7 +6465,7 @@ function resolveOverrideMethod(methodName, args, nameNode, selectors, scope, tra
|
|
|
4977
6465
|
if (!styleArg.ok) return null;
|
|
4978
6466
|
const atRuleSelector = priority !== null ? [atRule, priority] : atRule;
|
|
4979
6467
|
return {
|
|
4980
|
-
styleObj: applyTransform(styleArg.value, transform),
|
|
6468
|
+
styleObj: applyTransform(styleArg.value, transform, cssConfig),
|
|
4981
6469
|
selector: null,
|
|
4982
6470
|
atRules: [atRuleSelector]
|
|
4983
6471
|
};
|
|
@@ -4993,7 +6481,7 @@ function resolveOverrideMethod(methodName, args, nameNode, selectors, scope, tra
|
|
|
4993
6481
|
const selectorText = before + normalizeSelectorArg(String(selectorArg.value ?? "")) + (after ?? "");
|
|
4994
6482
|
const itemSelector = sel.priority !== null ? [selectorText, sel.priority] : selectorText;
|
|
4995
6483
|
return {
|
|
4996
|
-
styleObj: applyTransform(styleArg.value, transform),
|
|
6484
|
+
styleObj: applyTransform(styleArg.value, transform, cssConfig),
|
|
4997
6485
|
selector: itemSelector,
|
|
4998
6486
|
atRules: null
|
|
4999
6487
|
};
|
|
@@ -5001,7 +6489,7 @@ function resolveOverrideMethod(methodName, args, nameNode, selectors, scope, tra
|
|
|
5001
6489
|
const styleArg = evaluateNode(args[0], scope);
|
|
5002
6490
|
if (!styleArg.ok) return null;
|
|
5003
6491
|
return {
|
|
5004
|
-
styleObj: applyTransform(styleArg.value, transform),
|
|
6492
|
+
styleObj: applyTransform(styleArg.value, transform, cssConfig),
|
|
5005
6493
|
selector: sel.priority !== null ? [selectorStr, sel.priority] : selectorStr,
|
|
5006
6494
|
atRules: null
|
|
5007
6495
|
};
|
|
@@ -5064,10 +6552,10 @@ function getSlotIdFromValue(value) {
|
|
|
5064
6552
|
const slotId = value.slotId;
|
|
5065
6553
|
return typeof slotId === "string" ? slotId : null;
|
|
5066
6554
|
}
|
|
5067
|
-
function compileChainMethod(method, selectors, slotId, fileId, scope, type, cssConfig, items, cssRules, transform, atRules, styleNames, options, callsiteOverride = null) {
|
|
6555
|
+
function compileChainMethod(method, selectors, slotId, fileId, scope, type, cssConfig, items, cssRules, transform, atRules, styleNames, options, callsiteOverride = null, selectorPrefix = null) {
|
|
5068
6556
|
if (method.name === "$$style.merge") {
|
|
5069
6557
|
const mergeCallsite = callsiteOverride ?? getMergeStyleCallsite(method.nameNode, scope, options);
|
|
5070
|
-
return compileMergeArg(method.args[0], method.nameNode, fileId, scope, type, slotId, atRules, cssConfig, items, cssRules, styleNames, options, mergeCallsite);
|
|
6558
|
+
return compileMergeArg(method.args[0], method.nameNode, fileId, scope, type, slotId, atRules, cssConfig, items, cssRules, styleNames, options, mergeCallsite, selectorPrefix);
|
|
5071
6559
|
}
|
|
5072
6560
|
const selector = selectors[method.name];
|
|
5073
6561
|
if (!selector) return false;
|
|
@@ -5075,48 +6563,97 @@ function compileChainMethod(method, selectors, slotId, fileId, scope, type, cssC
|
|
|
5075
6563
|
const selectorStr = selector.selector.trim();
|
|
5076
6564
|
if (selectorStr === "...") {
|
|
5077
6565
|
const mergeCallsite = callsiteOverride ?? getMergeStyleCallsite(method.nameNode, scope, options);
|
|
5078
|
-
return compileMergeArg(method.args[0], method.nameNode, fileId, scope, type, slotId, atRules, cssConfig, items, cssRules, styleNames, options, mergeCallsite);
|
|
6566
|
+
return compileMergeArg(method.args[0], method.nameNode, fileId, scope, type, slotId, atRules, cssConfig, items, cssRules, styleNames, options, mergeCallsite, selectorPrefix);
|
|
5079
6567
|
}
|
|
5080
|
-
if (selectorStr.startsWith("@")) return compileAtRuleMethod(method, slotId, selector, selectorStr, fileId, scope, type, cssConfig, items, cssRules, transform, atRules, selectors, styleNames, options);
|
|
5081
|
-
if (selectorStr.includes("$$") || selectorStr.includes("$")) return compileArgMethod(method, selector, slotId, fileId, scope, type, cssConfig, items, cssRules, transform, atRules, options);
|
|
6568
|
+
if (selectorStr.startsWith("@")) return compileAtRuleMethod(method, slotId, selector, selectorStr, fileId, scope, type, cssConfig, items, cssRules, transform, atRules, selectors, styleNames, options, selectorPrefix);
|
|
6569
|
+
if (selectorStr.includes("$$") || selectorStr.includes("$")) return compileArgMethod(method, selector, slotId, fileId, scope, type, cssConfig, items, cssRules, transform, atRules, options, selectorPrefix);
|
|
5082
6570
|
const itemSelector = selector.priority !== null ? [selectorStr, selector.priority] : selectorStr;
|
|
6571
|
+
const compiledSelector = selectorPrefix ? combineSelectors(selectorPrefix, itemSelector) : itemSelector;
|
|
5083
6572
|
const styleArg = evaluateNode(method.args[0], scope);
|
|
5084
6573
|
if (!styleArg.ok) {
|
|
5085
6574
|
throwIfRequiredStaticStyleValue(styleArg);
|
|
5086
6575
|
return false;
|
|
5087
6576
|
}
|
|
5088
|
-
return addStyleItems(applyTransform(styleArg.value, transform),
|
|
6577
|
+
return addStyleItems(applyTransform(styleArg.value, transform, cssConfig), compiledSelector, null, atRules, fileId, type, slotId, items, cssRules, cssConfig, callsiteOverride);
|
|
5089
6578
|
}
|
|
5090
|
-
function compileMergeArg(styleArgNode, mergeNode, fileId, scope, type, slotId, atRules, cssConfig, items, cssRules, styleNames, options, callsiteOverride = null) {
|
|
6579
|
+
function compileMergeArg(styleArgNode, mergeNode, fileId, scope, type, slotId, atRules, cssConfig, items, cssRules, styleNames, options, callsiteOverride = null, selectorPrefix = null) {
|
|
5091
6580
|
if (!styleArgNode) return false;
|
|
5092
6581
|
const styleCallsite = callsiteOverride ?? getMergeStyleCallsite(mergeNode, scope, options);
|
|
5093
6582
|
const localChain = getLocalStyleChainArg(styleArgNode, scope, styleNames);
|
|
5094
6583
|
const localMeta = localChain ? scope.styleMetas?.get(localChain.rootName) : null;
|
|
5095
|
-
if (
|
|
6584
|
+
if (localChain?.kind === "style" && localMeta) return compileStyleChainInto(localChain, localMeta.selectors, fileId, scope, cssConfig, localMeta.transform, type, slotId, atRules, items, cssRules, styleNames, options, styleCallsite, selectorPrefix);
|
|
5096
6585
|
if (styleArgNode.type === "CallExpression") {
|
|
5097
6586
|
const nestedChain = extractStyleChain(styleArgNode, styleNames);
|
|
5098
6587
|
const nestedMeta = nestedChain ? scope.styleMetas?.get(nestedChain.rootName) : null;
|
|
5099
|
-
if (nestedChain?.kind === "style" && nestedMeta) return compileStyleChainInto(nestedChain, nestedMeta.selectors, fileId, scope, cssConfig, nestedMeta.transform, type, slotId, atRules, items, cssRules, styleNames, options, styleCallsite);
|
|
6588
|
+
if (nestedChain?.kind === "style" && nestedMeta) return compileStyleChainInto(nestedChain, nestedMeta.selectors, fileId, scope, cssConfig, nestedMeta.transform, type, slotId, atRules, items, cssRules, styleNames, options, styleCallsite, selectorPrefix);
|
|
5100
6589
|
}
|
|
5101
6590
|
const styleArg = evaluateNode(styleArgNode, scope);
|
|
5102
6591
|
if (!styleArg.ok) {
|
|
5103
6592
|
throwIfRequiredStaticStyleValue(styleArg);
|
|
5104
6593
|
return false;
|
|
5105
6594
|
}
|
|
5106
|
-
if (isStyleData(styleArg.value) && isStyleDataSpreadExpression(styleArgNode)) return addStyleDataSpreadItems(styleArg.value, styleArgNode,
|
|
5107
|
-
return addStyleDataItems(styleArg.value,
|
|
6595
|
+
if (isStyleData(styleArg.value) && isStyleDataSpreadExpression(styleArgNode)) return addStyleDataSpreadItems(styleArg.value, styleArgNode, selectorPrefix, null, atRules, fileId, type, slotId, items, cssRules, cssConfig, styleCallsite);
|
|
6596
|
+
return addStyleDataItems(styleArg.value, selectorPrefix, null, atRules, fileId, type, slotId, items, cssRules, cssConfig, styleCallsite);
|
|
5108
6597
|
}
|
|
5109
|
-
function getLocalStyleChainArg(node, scope, styleNames) {
|
|
6598
|
+
function getLocalStyleChainArg(node, scope, styleNames, sheetNames = /* @__PURE__ */ new Set()) {
|
|
5110
6599
|
if (node.type !== "Identifier") return null;
|
|
5111
6600
|
const init = scope.bindingNodes?.get(node.name);
|
|
5112
6601
|
if (!init) return null;
|
|
5113
|
-
return extractStyleChain(init, styleNames);
|
|
6602
|
+
return extractStyleChain(init, styleNames, sheetNames);
|
|
6603
|
+
}
|
|
6604
|
+
function getLocalSelectorTargetChain(node, scope, styleNames, sheetNames) {
|
|
6605
|
+
const callee = node.callee;
|
|
6606
|
+
if (callee.type === "Identifier") {
|
|
6607
|
+
const target = getLocalStyleChainArg(callee, scope, styleNames, sheetNames);
|
|
6608
|
+
if (!isBareSelectorTargetChain(target)) return null;
|
|
6609
|
+
return {
|
|
6610
|
+
...target,
|
|
6611
|
+
baseArgs: [...target.baseArgs, ...node.arguments]
|
|
6612
|
+
};
|
|
6613
|
+
}
|
|
6614
|
+
if (callee.type !== "MemberExpression" || callee.computed) return null;
|
|
6615
|
+
const memberTarget = getLocalMemberStyleChainArg(callee, scope, styleNames, sheetNames);
|
|
6616
|
+
if (isBareSelectorTargetChain(memberTarget)) return {
|
|
6617
|
+
...memberTarget,
|
|
6618
|
+
baseArgs: [...memberTarget.baseArgs, ...node.arguments]
|
|
6619
|
+
};
|
|
6620
|
+
const methodName = callee.property.type === "Identifier" ? callee.property.name : callee.property.type === "StringLiteral" ? callee.property.value : null;
|
|
6621
|
+
if (!methodName) return null;
|
|
6622
|
+
const object = callee.object;
|
|
6623
|
+
const target = object.type === "Identifier" ? getLocalStyleChainArg(object, scope, styleNames, sheetNames) : object.type === "MemberExpression" ? getLocalMemberStyleChainArg(object, scope, styleNames, sheetNames) : object.type === "CallExpression" ? getLocalSelectorTargetChain(object, scope, styleNames, sheetNames) : null;
|
|
6624
|
+
if (target?.kind !== "selector") return null;
|
|
6625
|
+
return {
|
|
6626
|
+
...target,
|
|
6627
|
+
methods: [...target.methods, {
|
|
6628
|
+
name: methodName,
|
|
6629
|
+
args: node.arguments,
|
|
6630
|
+
nameNode: callee.property
|
|
6631
|
+
}]
|
|
6632
|
+
};
|
|
6633
|
+
}
|
|
6634
|
+
function getLocalMemberStyleChainArg(node, scope, styleNames, sheetNames) {
|
|
6635
|
+
if (node.computed || node.object.type !== "Identifier") return null;
|
|
6636
|
+
const propertyName = node.property.type === "Identifier" ? node.property.name : node.property.type === "StringLiteral" ? node.property.value : null;
|
|
6637
|
+
if (!propertyName) return null;
|
|
6638
|
+
const objectInit = scope.bindingNodes?.get(node.object.name);
|
|
6639
|
+
if (objectInit?.type !== "ObjectExpression") return null;
|
|
6640
|
+
for (let i = 0, len = objectInit.properties.length; i < len; i++) {
|
|
6641
|
+
const property = objectInit.properties[i];
|
|
6642
|
+
if (property.type !== "ObjectProperty") continue;
|
|
6643
|
+
const key = property.key;
|
|
6644
|
+
if ((key.type === "Identifier" ? key.name : key.type === "StringLiteral" ? key.value : null) !== propertyName) continue;
|
|
6645
|
+
return extractStyleChain(property.value, styleNames, sheetNames);
|
|
6646
|
+
}
|
|
6647
|
+
return null;
|
|
6648
|
+
}
|
|
6649
|
+
function isBareSelectorTargetChain(chain) {
|
|
6650
|
+
return chain?.kind === "selector" && chain.baseArgs.length === 1 && chain.methods.length === 0;
|
|
5114
6651
|
}
|
|
5115
6652
|
function getLocalBindingNode(node, scope) {
|
|
5116
6653
|
return node?.type === "Identifier" ? scope.bindingNodes?.get(node.name) ?? null : null;
|
|
5117
6654
|
}
|
|
5118
6655
|
function getMergeStyleCallsite(node, scope, options) {
|
|
5119
|
-
if (options.dev?.sourcemapMode !== "style") return null;
|
|
6656
|
+
if ((options.dev?.sourcemapMode ?? (scope.runtimeMode === "rsc-dev" ? "style" : null)) !== "style") return null;
|
|
5120
6657
|
const loc = node?.loc?.start;
|
|
5121
6658
|
if (!loc) return null;
|
|
5122
6659
|
return {
|
|
@@ -5138,7 +6675,7 @@ function isStyleDataSpreadExpression(node) {
|
|
|
5138
6675
|
default: return false;
|
|
5139
6676
|
}
|
|
5140
6677
|
}
|
|
5141
|
-
function compileAtRuleMethod(method, slotId, selector, selectorStr, fileId, scope, type, cssConfig, items, cssRules, transform, atRules, selectors, styleNames, options) {
|
|
6678
|
+
function compileAtRuleMethod(method, slotId, selector, selectorStr, fileId, scope, type, cssConfig, items, cssRules, transform, atRules, selectors, styleNames, options, selectorPrefix = null) {
|
|
5142
6679
|
const isMedia = selectorStr.startsWith("@media") || selectorStr.startsWith("@container");
|
|
5143
6680
|
const hasArg = selectorStr.includes("$$");
|
|
5144
6681
|
validateSelectorDefinition(options.dev?.checkSelector, `style.${method.name}`, selector, method.nameNode);
|
|
@@ -5160,22 +6697,22 @@ function compileAtRuleMethod(method, slotId, selector, selectorStr, fileId, scop
|
|
|
5160
6697
|
if (styleArg.type === "CallExpression") {
|
|
5161
6698
|
const nestedChain = extractStyleChain(styleArg, styleNames);
|
|
5162
6699
|
const nestedMeta = nestedChain ? scope.styleMetas?.get(nestedChain.rootName) : null;
|
|
5163
|
-
if (nestedChain?.kind === "style" && nestedMeta) return compileStyleChainInto(nestedChain, nestedMeta.selectors, fileId, scope, cssConfig, nestedMeta.transform, type, slotId, nextAtRules, items, cssRules, styleNames, options);
|
|
6700
|
+
if (nestedChain?.kind === "style" && nestedMeta) return compileStyleChainInto(nestedChain, nestedMeta.selectors, fileId, scope, cssConfig, nestedMeta.transform, type, slotId, nextAtRules, items, cssRules, styleNames, options, null, selectorPrefix);
|
|
5164
6701
|
const evaled = evaluateNode(styleArg, scope);
|
|
5165
6702
|
if (!evaled.ok) {
|
|
5166
6703
|
throwIfRequiredStaticStyleValue(evaled);
|
|
5167
6704
|
return false;
|
|
5168
6705
|
}
|
|
5169
|
-
return addStyleItems(applyTransform(evaled.value, transform),
|
|
6706
|
+
return addStyleItems(applyTransform(evaled.value, transform, cssConfig), selectorPrefix, null, nextAtRules, fileId, type, slotId, items, cssRules, cssConfig);
|
|
5170
6707
|
}
|
|
5171
6708
|
const styleResult = evaluateNode(styleArg, scope);
|
|
5172
6709
|
if (!styleResult.ok) {
|
|
5173
6710
|
throwIfRequiredStaticStyleValue(styleResult);
|
|
5174
6711
|
return false;
|
|
5175
6712
|
}
|
|
5176
|
-
return addStyleItems(applyTransform(styleResult.value, transform),
|
|
6713
|
+
return addStyleItems(applyTransform(styleResult.value, transform, cssConfig), selectorPrefix, null, nextAtRules, fileId, type, slotId, items, cssRules, cssConfig);
|
|
5177
6714
|
}
|
|
5178
|
-
function compileArgMethod(method, selector, slotId, fileId, scope, type, cssConfig, items, cssRules, transform, atRules, options) {
|
|
6715
|
+
function compileArgMethod(method, selector, slotId, fileId, scope, type, cssConfig, items, cssRules, transform, atRules, options, selectorPrefix = null) {
|
|
5179
6716
|
const selectorStr = selector.selector.trim();
|
|
5180
6717
|
validateSelectorDefinition(options.dev?.checkSelector, `style.${method.name}`, selector, method.nameNode);
|
|
5181
6718
|
const splitToken = selectorStr.includes("$$") ? "$$" : "$";
|
|
@@ -5192,12 +6729,13 @@ function compileArgMethod(method, selector, slotId, fileId, scope, type, cssConf
|
|
|
5192
6729
|
const styleResult = evaluateNode(styleArg, scope);
|
|
5193
6730
|
if (!styleResult.ok) return false;
|
|
5194
6731
|
const selectorValues = Array.isArray(selectorArg.value) ? selectorArg.value : [selectorArg.value];
|
|
5195
|
-
const styleObj = applyTransform(styleResult.value, transform);
|
|
6732
|
+
const styleObj = applyTransform(styleResult.value, transform, cssConfig);
|
|
5196
6733
|
let i = 0;
|
|
5197
6734
|
while (i < selectorValues.length) {
|
|
5198
6735
|
const itemSelectorValue = selectorValues[i];
|
|
5199
6736
|
const selectorText = before + normalizeSelectorArg(String(itemSelectorValue ?? "")) + (after ?? "");
|
|
5200
|
-
|
|
6737
|
+
const compiledSelector = selector.priority !== null ? [selectorText, selector.priority] : selectorText;
|
|
6738
|
+
if (!addStyleItems(styleObj, selectorPrefix ? combineSelectors(selectorPrefix, compiledSelector) : compiledSelector, null, atRules, fileId, type, slotId, items, cssRules, cssConfig)) return false;
|
|
5201
6739
|
i++;
|
|
5202
6740
|
}
|
|
5203
6741
|
return true;
|
|
@@ -5266,6 +6804,8 @@ function addSlotOverrideDataItems(value, parentSelector, atRules, fileId, items,
|
|
|
5266
6804
|
dedupe: overrideItem.dedupe,
|
|
5267
6805
|
className: overrideItem.className,
|
|
5268
6806
|
property: overrideItem.property,
|
|
6807
|
+
weight: overrideItem.weight,
|
|
6808
|
+
important: overrideItem.important,
|
|
5269
6809
|
value: overrideItem.value,
|
|
5270
6810
|
variable: overrideItem.variable,
|
|
5271
6811
|
token: overrideItem.token,
|
|
@@ -5309,27 +6849,26 @@ function addExtractedScopeItem(sourceItem, items) {
|
|
|
5309
6849
|
items.push(item);
|
|
5310
6850
|
}
|
|
5311
6851
|
function addRuntimeScopeItem(sourceItem, parentSelector, atRules, fileId, items, cssRules, cssConfig, callsiteOverride = null) {
|
|
5312
|
-
|
|
6852
|
+
const weight = sourceItem.weight;
|
|
6853
|
+
let important = false;
|
|
5313
6854
|
let value = sourceItem.value;
|
|
5314
|
-
|
|
5315
|
-
priority = value[1];
|
|
5316
|
-
value = value[0];
|
|
5317
|
-
}
|
|
6855
|
+
important = sourceItem.important;
|
|
5318
6856
|
const itemParentSelector = parentSelector ?? sourceItem.parentSelector;
|
|
5319
6857
|
const itemAtRules = mergeAtRules(atRules, sourceItem.atRule);
|
|
5320
6858
|
const traceCallsite = callsiteOverride ?? sourceItem.callsite;
|
|
5321
6859
|
const valueStr = String(value ?? "");
|
|
5322
|
-
const dedupe = getClassNameDedupe(sourceItem.property,
|
|
5323
|
-
const className = getAtomicClassName(sourceItem.property,
|
|
6860
|
+
const dedupe = getClassNameDedupe(sourceItem.property, weight, important, sourceItem.selector, itemParentSelector, itemAtRules);
|
|
6861
|
+
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);
|
|
5324
6862
|
const item = createCompiledItem(4, sourceItem.slotId, dedupe, className, !!itemParentSelector);
|
|
5325
6863
|
items.push(item);
|
|
5326
|
-
const css = buildAtomicRule(className, sourceItem.property, valueStr, sourceItem.selector, itemParentSelector, itemAtRules, cssConfig.scopeTargetPrefix);
|
|
5327
|
-
const layerPriority = getAtomicRuleLayerPriority(sourceItem.property,
|
|
6864
|
+
const css = buildAtomicRule(className, sourceItem.property, valueStr, important, sourceItem.selector, itemParentSelector, itemAtRules, cssConfig.scopeTargetPrefix);
|
|
6865
|
+
const layerPriority = getAtomicRuleLayerPriority(sourceItem.property, weight, sourceItem.selector, itemParentSelector, itemAtRules, true);
|
|
5328
6866
|
cssRules.push({
|
|
5329
6867
|
dedupe,
|
|
5330
6868
|
className,
|
|
5331
6869
|
css,
|
|
5332
6870
|
priority: layerPriority,
|
|
6871
|
+
important,
|
|
5333
6872
|
trace: traceCallsite ? {
|
|
5334
6873
|
filePath: traceCallsite.filePath ?? fileId,
|
|
5335
6874
|
line: traceCallsite.line,
|
|
@@ -5387,21 +6926,18 @@ function addExtractedStyleItem(sourceItem, type, slotId, items) {
|
|
|
5387
6926
|
items.push(item);
|
|
5388
6927
|
}
|
|
5389
6928
|
function addRuntimeStyleItem(sourceItem, selector, parentSelector, atRules, fileId, type, slotId, items, cssRules, cssConfig, callsiteOverride = null) {
|
|
5390
|
-
|
|
6929
|
+
const weight = sourceItem.weight;
|
|
6930
|
+
const important = sourceItem.important;
|
|
5391
6931
|
let value = sourceItem.value;
|
|
5392
|
-
|
|
5393
|
-
priority = value[1];
|
|
5394
|
-
value = value[0];
|
|
5395
|
-
}
|
|
5396
|
-
const itemSelector = selector ?? sourceItem.selector;
|
|
6932
|
+
const itemSelector = selector && sourceItem.selector ? combineSelectors(selector, sourceItem.selector) : selector ?? sourceItem.selector;
|
|
5397
6933
|
const itemAtRules = mergeAtRules(atRules, sourceItem.atRule);
|
|
5398
6934
|
const variable = sourceItem.variable;
|
|
5399
6935
|
const runtimeValue = variable?.[0] === 1 ? getCompiledRuntimeValue(variable[2]) : void 0;
|
|
5400
6936
|
const shouldUseVariable = !!variable && (variable[0] !== 1 || !!sourceItem.token || !!runtimeValue);
|
|
5401
6937
|
const valueStr = variable?.[0] === 1 && !shouldUseVariable ? String(variable[2] ?? "") : String(value ?? "");
|
|
5402
|
-
const dedupe = getClassNameDedupe(sourceItem.property,
|
|
6938
|
+
const dedupe = getClassNameDedupe(sourceItem.property, weight, important, itemSelector, parentSelector, itemAtRules);
|
|
5403
6939
|
const traceCallsite = callsiteOverride ?? sourceItem.callsite;
|
|
5404
|
-
const className = getAtomicClassName(sourceItem.property,
|
|
6940
|
+
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);
|
|
5405
6941
|
const item = createCompiledItem(type, slotId, dedupe, className, !!parentSelector);
|
|
5406
6942
|
item.sourceTrace = getRuntimeStyleItemSourceTrace(sourceItem, fileId);
|
|
5407
6943
|
if (type !== 4 && variable && shouldUseVariable) {
|
|
@@ -5409,13 +6945,14 @@ function addRuntimeStyleItem(sourceItem, selector, parentSelector, atRules, file
|
|
|
5409
6945
|
if (runtimeValue) item.valueNode = runtimeValue;
|
|
5410
6946
|
}
|
|
5411
6947
|
items.push(item);
|
|
5412
|
-
const css = buildAtomicRule(className, sourceItem.property, valueStr, itemSelector, parentSelector, itemAtRules, cssConfig.scopeTargetPrefix);
|
|
5413
|
-
const layerPriority = getAtomicRuleLayerPriority(sourceItem.property,
|
|
6948
|
+
const css = buildAtomicRule(className, sourceItem.property, valueStr, important, itemSelector, parentSelector, itemAtRules, cssConfig.scopeTargetPrefix);
|
|
6949
|
+
const layerPriority = getAtomicRuleLayerPriority(sourceItem.property, weight, itemSelector, parentSelector, itemAtRules, type === 4);
|
|
5414
6950
|
cssRules.push({
|
|
5415
6951
|
dedupe,
|
|
5416
6952
|
className,
|
|
5417
6953
|
css,
|
|
5418
6954
|
priority: layerPriority,
|
|
6955
|
+
important,
|
|
5419
6956
|
trace: traceCallsite ? {
|
|
5420
6957
|
filePath: traceCallsite.filePath ?? fileId,
|
|
5421
6958
|
line: traceCallsite.line,
|
|
@@ -5423,6 +6960,19 @@ function addRuntimeStyleItem(sourceItem, selector, parentSelector, atRules, file
|
|
|
5423
6960
|
} : void 0
|
|
5424
6961
|
});
|
|
5425
6962
|
}
|
|
6963
|
+
function combineSelectors(parent, child) {
|
|
6964
|
+
const parentText = getItemSelectorText(parent);
|
|
6965
|
+
const childText = getItemSelectorText(child);
|
|
6966
|
+
const priority = Math.max(getItemSelectorPriority(parent), getItemSelectorPriority(child));
|
|
6967
|
+
const selector = parentText + childText;
|
|
6968
|
+
return priority > 0 ? [selector, priority] : selector;
|
|
6969
|
+
}
|
|
6970
|
+
function getItemSelectorText(selector) {
|
|
6971
|
+
return Array.isArray(selector) ? selector[0] : selector;
|
|
6972
|
+
}
|
|
6973
|
+
function getItemSelectorPriority(selector) {
|
|
6974
|
+
return Array.isArray(selector) ? selector[1] : 0;
|
|
6975
|
+
}
|
|
5426
6976
|
function getRuntimeStyleItemSourceTrace(item, fileId) {
|
|
5427
6977
|
const trace = getRuntimeStyleItemValueTrace(item);
|
|
5428
6978
|
if (!trace) return void 0;
|
|
@@ -5467,11 +7017,14 @@ function addStyleItems(styleObj, selector, parentSelector, atRules, fileId, type
|
|
|
5467
7017
|
while (i < keys.length) {
|
|
5468
7018
|
const property = keys[i];
|
|
5469
7019
|
const rawValue = styleObj[property];
|
|
5470
|
-
let
|
|
7020
|
+
let weight = null;
|
|
7021
|
+
let important = false;
|
|
5471
7022
|
let value = rawValue;
|
|
5472
|
-
|
|
5473
|
-
|
|
5474
|
-
|
|
7023
|
+
let transformClassName = null;
|
|
7024
|
+
[value, weight, important] = unwrapStaticStyleValue(value);
|
|
7025
|
+
if (isClassNameValue(value)) {
|
|
7026
|
+
transformClassName = value.className;
|
|
7027
|
+
value = value.value;
|
|
5475
7028
|
}
|
|
5476
7029
|
if (value === null || value === void 0) {
|
|
5477
7030
|
i++;
|
|
@@ -5489,10 +7042,10 @@ function addStyleItems(styleObj, selector, parentSelector, atRules, fileId, type
|
|
|
5489
7042
|
column: propertyLoc.column
|
|
5490
7043
|
} : null);
|
|
5491
7044
|
const shouldUseVariable = !!(token || runtimeValue);
|
|
5492
|
-
const variableName = shouldUseVariable && propertyLoc ? getLocalVarName(propertyLoc.filePath ?? fileId, propertyLoc.line, propertyLoc.column, cssConfig.tokenNameFormat) : null;
|
|
7045
|
+
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;
|
|
5493
7046
|
const valueStr = variableName ? token ? getCssVarRawFallback(variableName, getTokenVar(token, cssConfig.tokenNameFormat)) : `var(${variableName})` : token ? getTokenVar(token, cssConfig.tokenNameFormat) : String(value);
|
|
5494
|
-
const dedupe = getClassNameDedupe(property,
|
|
5495
|
-
const className = getAtomicClassName(property,
|
|
7047
|
+
const dedupe = getClassNameDedupe(property, weight, important, selector, parentSelector, atRules);
|
|
7048
|
+
const className = getAtomicClassName(property, weight, important, valueStr, selector, parentSelector, atRules, propertyCallsite, cssConfig.localClassName, cssConfig.debugClassName, cssConfig.classNameFormat, transformClassName, cssConfig.transformClassNameFormat, cssConfig.sheetClassNameFormat, cssConfig.hashLength);
|
|
5496
7049
|
const item = createCompiledItem(type, slotId, dedupe, className, !!parentSelector);
|
|
5497
7050
|
item.sourceTrace = propertyCallsite ? {
|
|
5498
7051
|
property,
|
|
@@ -5517,13 +7070,14 @@ function addStyleItems(styleObj, selector, parentSelector, atRules, fileId, type
|
|
|
5517
7070
|
item.valueNode = runtimeValue ?? token[COMPILED_RUNTIME_VALUE];
|
|
5518
7071
|
}
|
|
5519
7072
|
items.push(item);
|
|
5520
|
-
const css = buildAtomicRule(className, property, valueStr, selector, parentSelector, atRules, cssConfig.scopeTargetPrefix);
|
|
5521
|
-
const layerPriority = getAtomicRuleLayerPriority(property,
|
|
7073
|
+
const css = buildAtomicRule(className, property, valueStr, important, selector, parentSelector, atRules, cssConfig.scopeTargetPrefix);
|
|
7074
|
+
const layerPriority = getAtomicRuleLayerPriority(property, weight, selector, parentSelector, atRules, type === 4);
|
|
5522
7075
|
cssRules.push({
|
|
5523
7076
|
dedupe,
|
|
5524
7077
|
className,
|
|
5525
7078
|
css,
|
|
5526
7079
|
priority: layerPriority,
|
|
7080
|
+
important,
|
|
5527
7081
|
trace: propertyCallsite ? {
|
|
5528
7082
|
filePath: propertyCallsite.filePath ?? fileId,
|
|
5529
7083
|
line: propertyCallsite.line,
|
|
@@ -5546,6 +7100,28 @@ function addStyleItems(styleObj, selector, parentSelector, atRules, fileId, type
|
|
|
5546
7100
|
}
|
|
5547
7101
|
return true;
|
|
5548
7102
|
}
|
|
7103
|
+
function unwrapStaticStyleValue(value) {
|
|
7104
|
+
let weight = null;
|
|
7105
|
+
let important = false;
|
|
7106
|
+
while (true) {
|
|
7107
|
+
if (isStyleImportantValue(value)) {
|
|
7108
|
+
important = true;
|
|
7109
|
+
value = value.value;
|
|
7110
|
+
continue;
|
|
7111
|
+
}
|
|
7112
|
+
if (isStyleWeightValue(value)) {
|
|
7113
|
+
weight = value.weight;
|
|
7114
|
+
value = value.value;
|
|
7115
|
+
continue;
|
|
7116
|
+
}
|
|
7117
|
+
break;
|
|
7118
|
+
}
|
|
7119
|
+
return [
|
|
7120
|
+
value,
|
|
7121
|
+
weight,
|
|
7122
|
+
important
|
|
7123
|
+
];
|
|
7124
|
+
}
|
|
5549
7125
|
function throwIfRequiredStaticStyleValue(result) {
|
|
5550
7126
|
if (result.ok) return;
|
|
5551
7127
|
if (result.reason.includes("createCounterStyle") || result.reason.includes("createFontFace") || result.reason.includes("createFontPaletteValues") || result.reason.includes("createPositionTry") || result.reason.includes("createProperty") || result.reason.includes("fontSrc")) throw new Error(result.reason);
|
|
@@ -5681,6 +7257,12 @@ function parseAndExtractModule(projectDir, filePath, content, babel, resolveImpo
|
|
|
5681
7257
|
const styleMetas = /* @__PURE__ */ new Map();
|
|
5682
7258
|
const fileId = getProjectFileId$1(projectDir, filePath);
|
|
5683
7259
|
const importSourceMatcher = createImportSourceMatcher(options.importSources ?? null);
|
|
7260
|
+
const staticIdState = {
|
|
7261
|
+
fileId,
|
|
7262
|
+
imports,
|
|
7263
|
+
styleNames
|
|
7264
|
+
};
|
|
7265
|
+
const t = babel.types;
|
|
5684
7266
|
for (const stmt of ast.program.body) {
|
|
5685
7267
|
if (stmt.type === "ImportDeclaration") {
|
|
5686
7268
|
const source = stmt.source.value;
|
|
@@ -5705,6 +7287,7 @@ function parseAndExtractModule(projectDir, filePath, content, babel, resolveImpo
|
|
|
5705
7287
|
continue;
|
|
5706
7288
|
}
|
|
5707
7289
|
if (stmt.type === "VariableDeclaration") {
|
|
7290
|
+
annotateVariableDeclaration(stmt, staticIdState, t);
|
|
5708
7291
|
collectVariableBindings(rawBindings, stmt);
|
|
5709
7292
|
continue;
|
|
5710
7293
|
}
|
|
@@ -5728,6 +7311,7 @@ function parseAndExtractModule(projectDir, filePath, content, babel, resolveImpo
|
|
|
5728
7311
|
continue;
|
|
5729
7312
|
}
|
|
5730
7313
|
if (stmt.declaration?.type === "VariableDeclaration") {
|
|
7314
|
+
annotateVariableDeclaration(stmt.declaration, staticIdState, t);
|
|
5731
7315
|
collectVariableBindings(rawBindings, stmt.declaration);
|
|
5732
7316
|
continue;
|
|
5733
7317
|
}
|
|
@@ -5767,6 +7351,12 @@ function parseAndExtractModule(projectDir, filePath, content, babel, resolveImpo
|
|
|
5767
7351
|
});
|
|
5768
7352
|
return bindings;
|
|
5769
7353
|
}
|
|
7354
|
+
function annotateVariableDeclaration(declaration, state, t) {
|
|
7355
|
+
for (const decl of declaration.declarations) {
|
|
7356
|
+
annotateTokenDeclaration(decl, state, t);
|
|
7357
|
+
annotateAtRuleDeclaration(decl, state, t);
|
|
7358
|
+
}
|
|
7359
|
+
}
|
|
5770
7360
|
function collectVariableBindings(bindings, declaration) {
|
|
5771
7361
|
for (const decl of declaration.declarations) if (decl.id.type === "Identifier" && decl.init) bindings.set(decl.id.name, decl.init);
|
|
5772
7362
|
}
|
|
@@ -5777,7 +7367,7 @@ function evaluateResolvedNode(node, scope, styleNames, fileId, options) {
|
|
|
5777
7367
|
if (chain?.kind === "style" || chain?.kind === "scope") try {
|
|
5778
7368
|
const meta = scope.styleMetas?.get(chain.rootName);
|
|
5779
7369
|
if (!meta) return evalFail("Cannot resolve imported style function");
|
|
5780
|
-
const result = compileChain(chain, fileId, node.loc?.start, scope, options, meta, styleNames);
|
|
7370
|
+
const result = compileChain(chain, fileId, node.loc?.start, scope, options, scope.runtimeMode ?? null, meta, styleNames);
|
|
5781
7371
|
if (!result) return evalFail("Cannot compile imported style chain");
|
|
5782
7372
|
const extracted = createExtractedChainValue(result, options.dev?.sourcemapMode === "value" ? result : compileChain(chain, fileId, node.loc?.start, scope, {
|
|
5783
7373
|
...options,
|
|
@@ -5785,7 +7375,7 @@ function evaluateResolvedNode(node, scope, styleNames, fileId, options) {
|
|
|
5785
7375
|
...options.dev,
|
|
5786
7376
|
sourcemapMode: "value"
|
|
5787
7377
|
}
|
|
5788
|
-
}, meta, styleNames) ?? result);
|
|
7378
|
+
}, scope.runtimeMode ?? null, meta, styleNames) ?? result);
|
|
5789
7379
|
if (!extracted) return evalFail("Cannot extract imported style chain");
|
|
5790
7380
|
return evalOk(extracted);
|
|
5791
7381
|
} catch (error) {
|
|
@@ -5827,11 +7417,16 @@ function evaluateResolvedObject(node, scope, styleNames, fileId, options) {
|
|
|
5827
7417
|
const value = evaluateResolvedNode(prop.value, scope, styleNames, fileId, options);
|
|
5828
7418
|
if (!value.ok && value.reason !== "slot-ref") return value;
|
|
5829
7419
|
result[String(key.value)] = value.ok ? value.value : value;
|
|
5830
|
-
if (prop.loc?.start)
|
|
5831
|
-
|
|
5832
|
-
|
|
5833
|
-
|
|
5834
|
-
|
|
7420
|
+
if (prop.loc?.start) {
|
|
7421
|
+
const variableLoc = prop.value.loc?.start ?? prop.loc?.start;
|
|
7422
|
+
locations[String(key.value)] = {
|
|
7423
|
+
line: prop.loc.start.line,
|
|
7424
|
+
column: prop.loc.start.column + 1,
|
|
7425
|
+
filePath: scope.styleFilePath ?? scope.filePath,
|
|
7426
|
+
variableLine: variableLoc?.line,
|
|
7427
|
+
variableColumn: variableLoc ? variableLoc.column + 1 : void 0
|
|
7428
|
+
};
|
|
7429
|
+
}
|
|
5835
7430
|
}
|
|
5836
7431
|
if (Object.keys(locations).length) Object.defineProperty(result, COMPILED_STYLE_OBJECT_LOCATIONS, {
|
|
5837
7432
|
configurable: true,
|
|
@@ -5846,6 +7441,11 @@ function createExtractedChainValue(result, traceResult = result) {
|
|
|
5846
7441
|
defineCompiledStyleLocations(style, traceResult);
|
|
5847
7442
|
return style;
|
|
5848
7443
|
}
|
|
7444
|
+
if (result.type === "sheet") {
|
|
7445
|
+
const sheet = createExtractedSheet(result.items.filter(Array.isArray).map((item) => toExtractedStyleTuple(item)), result.sheetOptions);
|
|
7446
|
+
defineCompiledStyleLocations(sheet, traceResult);
|
|
7447
|
+
return sheet;
|
|
7448
|
+
}
|
|
5849
7449
|
if (result.type === "scope") return createExtractedScope(result.items.map(toExtractedScopeItem$1).filter((item) => item !== null));
|
|
5850
7450
|
return null;
|
|
5851
7451
|
}
|
|
@@ -5956,6 +7556,12 @@ function hashFileContent(filePath) {
|
|
|
5956
7556
|
function getStyleRuntimeImportPath(mode) {
|
|
5957
7557
|
return `${STYLE_IMPORT_PATH}/entry/${mode}`;
|
|
5958
7558
|
}
|
|
7559
|
+
function getStyleRuntimeAdapterImportPath(source, mode) {
|
|
7560
|
+
if (source === "@fluentic/style/adapter/solid") return `${getStyleRuntimeImportPath(mode)}/adapter/solid`;
|
|
7561
|
+
if (source === "@fluentic/style/adapter/preact") return `${getStyleRuntimeImportPath(mode)}/adapter/preact`;
|
|
7562
|
+
if (source === "@fluentic/style/adapter/react") return `${getStyleRuntimeImportPath(mode)}/adapter/react`;
|
|
7563
|
+
return null;
|
|
7564
|
+
}
|
|
5959
7565
|
function getStyleRuntimeCssImportPath(mode) {
|
|
5960
7566
|
return `${getStyleRuntimeImportPath(mode)}/css`;
|
|
5961
7567
|
}
|
|
@@ -6048,6 +7654,10 @@ function buildReplacement(t, chain, state, options = {}) {
|
|
|
6048
7654
|
state.usedHelpers.add(hasSpread ? FN_CREATE_EXTRACTED_STYLE_MERGE : FN_CREATE_EXTRACTED_STYLE);
|
|
6049
7655
|
return t.callExpression(t.identifier(hasSpread ? FN_CREATE_EXTRACTED_STYLE_MERGE : FN_CREATE_EXTRACTED_STYLE), hasSpread ? buildStyleMergeArgs(t, chain, state, options) : [buildItemsArray(t, chain, 1, state, options)]);
|
|
6050
7656
|
}
|
|
7657
|
+
if (chain.type === "sheet") {
|
|
7658
|
+
state.usedHelpers.add(FN_CREATE_EXTRACTED_SHEET);
|
|
7659
|
+
return t.callExpression(t.identifier(FN_CREATE_EXTRACTED_SHEET), [buildItemsArray(t, chain, 9, state, options), buildSheetOptions(t, chain)]);
|
|
7660
|
+
}
|
|
6051
7661
|
if (chain.type === "slot") {
|
|
6052
7662
|
state.usedHelpers.add(FN_CREATE_EXTRACTED_SLOT);
|
|
6053
7663
|
return t.callExpression(t.identifier(FN_CREATE_EXTRACTED_SLOT), [t.stringLiteral(chain.slotId), buildItemsArray(t, chain, 2, state, options)]);
|
|
@@ -6058,6 +7668,13 @@ function buildReplacement(t, chain, state, options = {}) {
|
|
|
6058
7668
|
}
|
|
6059
7669
|
return null;
|
|
6060
7670
|
}
|
|
7671
|
+
function buildSheetOptions(t, chain) {
|
|
7672
|
+
const options = chain.sheetOptions ?? {};
|
|
7673
|
+
const properties = [];
|
|
7674
|
+
if (options.layer !== void 0) properties.push(t.objectProperty(t.identifier("layer"), t.booleanLiteral(options.layer)));
|
|
7675
|
+
if (options.weight !== void 0) properties.push(t.objectProperty(t.identifier("weight"), t.numericLiteral(options.weight)));
|
|
7676
|
+
return t.objectExpression(properties);
|
|
7677
|
+
}
|
|
6061
7678
|
function buildStyleMergeArgs(t, chain, state, options) {
|
|
6062
7679
|
const args = [];
|
|
6063
7680
|
let chunk = [];
|
|
@@ -6086,7 +7703,7 @@ function buildItemsArray(t, chain, defaultType, state, options) {
|
|
|
6086
7703
|
chain.items.forEach((item) => {
|
|
6087
7704
|
if (isCompiledTokenItem(item)) {
|
|
6088
7705
|
if (options.getTokenOverride) options.getTokenOverride(item);
|
|
6089
|
-
else itemExpressions.push(t
|
|
7706
|
+
else itemExpressions.push(buildExtractedTokenOverrideExpression(t, item.value, state));
|
|
6090
7707
|
return;
|
|
6091
7708
|
}
|
|
6092
7709
|
if (isCompiledStyleSpreadItem(item)) return;
|
|
@@ -6176,11 +7793,26 @@ function buildVariableValueExpression(t, value, state, item, options) {
|
|
|
6176
7793
|
}
|
|
6177
7794
|
function buildExtractedTokenExpression(t, token, state) {
|
|
6178
7795
|
state.usedHelpers.add(FN_CREATE_EXTRACTED_TOKEN);
|
|
7796
|
+
const tokenNameFormat = state.options.css?.tokenNameFormat ?? DEFAULT_CONFIG.tokenNameFormat ?? null;
|
|
6179
7797
|
return t.callExpression(t.identifier(FN_CREATE_EXTRACTED_TOKEN), [
|
|
6180
7798
|
t.stringLiteral(getStyleTokenId(token)),
|
|
6181
7799
|
literalExpression(t, token.value),
|
|
6182
|
-
token.ref ? buildExtractedTokenExpression(t, token.ref, state) : t.nullLiteral()
|
|
7800
|
+
token.ref ? buildExtractedTokenExpression(t, token.ref, state) : t.nullLiteral(),
|
|
7801
|
+
getStyleTokenName(token) ? t.stringLiteral(getStyleTokenName(token)) : t.nullLiteral(),
|
|
7802
|
+
t.stringLiteral(getTokenVarName(token, tokenNameFormat))
|
|
7803
|
+
]);
|
|
7804
|
+
}
|
|
7805
|
+
function buildExtractedTokenOverrideExpression(t, token, state) {
|
|
7806
|
+
state.usedHelpers.add(FN_CREATE_EXTRACTED_TOKEN);
|
|
7807
|
+
const tokenNameFormat = state.options.css?.tokenNameFormat ?? DEFAULT_CONFIG.tokenNameFormat ?? null;
|
|
7808
|
+
const extractedToken = t.callExpression(t.identifier(FN_CREATE_EXTRACTED_TOKEN), [
|
|
7809
|
+
t.stringLiteral(getStyleTokenId(token)),
|
|
7810
|
+
t.nullLiteral(),
|
|
7811
|
+
t.nullLiteral(),
|
|
7812
|
+
getStyleTokenName(token) ? t.stringLiteral(getStyleTokenName(token)) : t.nullLiteral(),
|
|
7813
|
+
t.stringLiteral(getTokenVarName(token, tokenNameFormat))
|
|
6183
7814
|
]);
|
|
7815
|
+
return t.callExpression(extractedToken, [token.ref ? buildExtractedTokenExpression(t, token.ref, state) : literalExpression(t, token.value)]);
|
|
6184
7816
|
}
|
|
6185
7817
|
function literalExpression(t, value) {
|
|
6186
7818
|
if (typeof value === "string") return t.stringLiteral(value);
|
|
@@ -6303,8 +7935,10 @@ function getEvalScope(state) {
|
|
|
6303
7935
|
styleFilePath: state.styleFilePath,
|
|
6304
7936
|
sourcemapTrace: state.sourcemapTrace,
|
|
6305
7937
|
styleNames: state.styleNames,
|
|
7938
|
+
sheetNames: state.sheetNames,
|
|
6306
7939
|
styleMetas: state.styleMetas,
|
|
6307
|
-
bindingNodes: state.bindingNodes
|
|
7940
|
+
bindingNodes: state.bindingNodes,
|
|
7941
|
+
runtimeMode: state.runtimeMode
|
|
6308
7942
|
};
|
|
6309
7943
|
}
|
|
6310
7944
|
//#endregion
|
|
@@ -6318,8 +7952,8 @@ function compileThemeCall(path, state, opts) {
|
|
|
6318
7952
|
const tokenArg = evaluateNode(path.node.arguments[0], scope);
|
|
6319
7953
|
if (!tokenArg.ok) throw path.buildCodeFrameError(`createTheme tokens must be statically analyzable: ${tokenArg.reason}`);
|
|
6320
7954
|
if (!Array.isArray(tokenArg.value)) throw path.buildCodeFrameError("createTheme first argument must be a static array of token overrides.");
|
|
6321
|
-
const
|
|
6322
|
-
if (path.node.arguments[1] && !
|
|
7955
|
+
const stableIdArg = evaluateNode(path.node.arguments[1], scope);
|
|
7956
|
+
if (path.node.arguments[1] && !stableIdArg.ok) throw path.buildCodeFrameError(`createTheme stableId must be statically analyzable: ${stableIdArg.reason}`);
|
|
6323
7957
|
const tokens = [];
|
|
6324
7958
|
for (let i = 0, len = tokenArg.value.length; i < len; i++) {
|
|
6325
7959
|
const token = tokenArg.value[i];
|
|
@@ -6327,7 +7961,7 @@ function compileThemeCall(path, state, opts) {
|
|
|
6327
7961
|
tokens.push(token);
|
|
6328
7962
|
}
|
|
6329
7963
|
const loc = path.node.loc?.start;
|
|
6330
|
-
const id =
|
|
7964
|
+
const id = stableIdArg.ok && stableIdArg.value !== void 0 ? String(stableIdArg.value) : getStableThemeId(state.fileId, loc ? loc.line + ":" + loc.column : "createTheme");
|
|
6331
7965
|
const themeNameFormat = opts.css?.themeNameFormat || CSS_CONFIG.themeNameFormat || null;
|
|
6332
7966
|
const className = getStableThemeClassName(id, themeNameFormat);
|
|
6333
7967
|
return {
|
|
@@ -6359,6 +7993,7 @@ function createExtractPlugin(args) {
|
|
|
6359
7993
|
return {
|
|
6360
7994
|
pre() {
|
|
6361
7995
|
this.styleNames = /* @__PURE__ */ new Set();
|
|
7996
|
+
this.sheetNames = /* @__PURE__ */ new Set();
|
|
6362
7997
|
this.styleMetas = /* @__PURE__ */ new Map();
|
|
6363
7998
|
this.bindings = /* @__PURE__ */ new Map();
|
|
6364
7999
|
this.bindingNodes = /* @__PURE__ */ new Map();
|
|
@@ -6375,7 +8010,7 @@ function createExtractPlugin(args) {
|
|
|
6375
8010
|
this.filePath = this.file?.opts?.filename ?? "unknown";
|
|
6376
8011
|
this.styleFilePath = args.styleFilePath ?? this.filePath;
|
|
6377
8012
|
this.sourcemapTrace = options.dev?.sourcemapMode ?? "style";
|
|
6378
|
-
this.fileId = args.styleFilePath ?? getProjectFileId(args.projectDir, this.file?.opts?.filename);
|
|
8013
|
+
this.fileId = args.runtimeMode === "rsc-dev" ? getProjectFileId(args.projectDir, this.file?.opts?.filename) : args.styleFilePath ?? getProjectFileId(args.projectDir, this.file?.opts?.filename);
|
|
6379
8014
|
},
|
|
6380
8015
|
visitor: {
|
|
6381
8016
|
ImportDeclaration(path, state) {
|
|
@@ -6405,6 +8040,7 @@ function createExtractPlugin(args) {
|
|
|
6405
8040
|
state.styleNames.add(spec.local.name);
|
|
6406
8041
|
state.styleMetas.set(spec.local.name, meta);
|
|
6407
8042
|
}
|
|
8043
|
+
if (sourceName === "@fluentic/style/css" && imported === "createSheet") state.sheetNames.add(spec.local.name);
|
|
6408
8044
|
});
|
|
6409
8045
|
},
|
|
6410
8046
|
VariableDeclaration(path, state) {
|
|
@@ -6451,22 +8087,26 @@ function createExtractPlugin(args) {
|
|
|
6451
8087
|
state.needsExtractImport = true;
|
|
6452
8088
|
return;
|
|
6453
8089
|
}
|
|
6454
|
-
if (!state.styleNames.size) return;
|
|
6455
|
-
const chain = extractStyleChain(path.node, state.styleNames);
|
|
8090
|
+
if (!state.styleNames.size && !state.sheetNames.size) return;
|
|
8091
|
+
const chain = extractStyleChain(path.node, state.styleNames, state.sheetNames);
|
|
6456
8092
|
if (!chain) return;
|
|
6457
8093
|
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.");
|
|
6458
8094
|
const scope = getEvalScope(state);
|
|
6459
8095
|
const loc = path.node.loc?.start;
|
|
6460
8096
|
const meta = state.styleMetas.get(chain.rootName);
|
|
6461
|
-
if (!meta) return;
|
|
8097
|
+
if (chain.kind !== "sheet" && !meta) return;
|
|
6462
8098
|
let result;
|
|
6463
8099
|
try {
|
|
6464
|
-
result = compileChain(chain, state.fileId, loc, scope, options, meta, state.styleNames);
|
|
8100
|
+
result = compileChain(chain, state.fileId, loc, scope, options, state.runtimeMode, meta ?? null, state.styleNames);
|
|
6465
8101
|
} catch (error) {
|
|
6466
8102
|
const message = error instanceof Error ? error.message : String(error);
|
|
6467
8103
|
throw buildCodeFrameError(path, getSelectorCompileErrorNode(error) ?? path.node, message);
|
|
6468
8104
|
}
|
|
6469
8105
|
if (!result) return;
|
|
8106
|
+
checkCompiledImportantUsage(result, options.check?.important, (level, message) => {
|
|
8107
|
+
if (level === "error") throw path.buildCodeFrameError(message);
|
|
8108
|
+
console.warn("[fluentic-style] " + message);
|
|
8109
|
+
});
|
|
6470
8110
|
result.rules.forEach((rule) => {
|
|
6471
8111
|
state.collector.add(rule);
|
|
6472
8112
|
});
|
|
@@ -6505,6 +8145,18 @@ function createExtractPlugin(args) {
|
|
|
6505
8145
|
};
|
|
6506
8146
|
});
|
|
6507
8147
|
}
|
|
8148
|
+
function checkCompiledImportantUsage(result, options, report) {
|
|
8149
|
+
if (!options) return;
|
|
8150
|
+
let hasRawValue = false;
|
|
8151
|
+
let hasOutsideSheet = false;
|
|
8152
|
+
for (let i = 0, len = result.rules.length; i < len; i++) {
|
|
8153
|
+
const rule = result.rules[i];
|
|
8154
|
+
if (!rule.important && /!\s*important\b/i.test(rule.css)) hasRawValue = true;
|
|
8155
|
+
if (result.type !== "sheet" && rule.important) hasOutsideSheet = true;
|
|
8156
|
+
}
|
|
8157
|
+
if (hasRawValue && options.rawValue) report(options.rawValue, "Do not write raw \"!important\" values. Wrap the value with style.important(...) instead.");
|
|
8158
|
+
if (hasOutsideSheet && options.outsideSheet) report(options.outsideSheet, "style.important(...) outside createSheet is discouraged. Prefer style.weight(...) for Fluentic style priority.");
|
|
8159
|
+
}
|
|
6508
8160
|
function pruneUnusedStyleInputDeclarations(path, state) {
|
|
6509
8161
|
path.scope.crawl();
|
|
6510
8162
|
path.traverse({ VariableDeclarator(declaratorPath) {
|
|
@@ -6666,13 +8318,15 @@ function insertHoistedDeclarations(path, declarations) {
|
|
|
6666
8318
|
const body = path.node.body;
|
|
6667
8319
|
let firstRuntimeIndex = 0;
|
|
6668
8320
|
while (firstRuntimeIndex < body.length && body[firstRuntimeIndex].type === "ImportDeclaration") firstRuntimeIndex++;
|
|
8321
|
+
let runtimeInsertIndex = firstRuntimeIndex;
|
|
6669
8322
|
declarations.forEach((item) => {
|
|
6670
|
-
let insertIndex =
|
|
8323
|
+
let insertIndex = runtimeInsertIndex;
|
|
6671
8324
|
item.dependencies.forEach((name) => {
|
|
6672
8325
|
const dependencyIndex = findTopLevelDeclarationIndex(body, name);
|
|
6673
8326
|
if (dependencyIndex >= insertIndex) insertIndex = dependencyIndex + 1;
|
|
6674
8327
|
});
|
|
6675
8328
|
body.splice(insertIndex, 0, item.declaration);
|
|
8329
|
+
runtimeInsertIndex = insertIndex + 1;
|
|
6676
8330
|
});
|
|
6677
8331
|
}
|
|
6678
8332
|
function findTopLevelDeclarationIndex(body, name) {
|
|
@@ -6713,7 +8367,7 @@ function transformExtract(internal, args, deps) {
|
|
|
6713
8367
|
code: args.code,
|
|
6714
8368
|
filePath: args.filePath,
|
|
6715
8369
|
sourcemap: args.sourcemap,
|
|
6716
|
-
plugins: [plugin],
|
|
8370
|
+
plugins: [createCssPropPlugin({ options: internal.options }), plugin],
|
|
6717
8371
|
errorLabel: "[style] compiler error"
|
|
6718
8372
|
});
|
|
6719
8373
|
if (!result) return null;
|
|
@@ -6755,22 +8409,15 @@ function createPlugin(rewriteSource) {
|
|
|
6755
8409
|
}
|
|
6756
8410
|
//#endregion
|
|
6757
8411
|
//#region compiler/compiler/compiler.ts
|
|
6758
|
-
let CompilerRuntimeMode = /* @__PURE__ */ function(CompilerRuntimeMode) {
|
|
6759
|
-
CompilerRuntimeMode["Dev"] = "dev";
|
|
6760
|
-
CompilerRuntimeMode["Prod"] = "prod";
|
|
6761
|
-
CompilerRuntimeMode["RscDev"] = "rsc-dev";
|
|
6762
|
-
CompilerRuntimeMode["RscProd"] = "rsc-prod";
|
|
6763
|
-
return CompilerRuntimeMode;
|
|
6764
|
-
}({});
|
|
6765
8412
|
function createCompiler(args, options) {
|
|
6766
8413
|
const internal = createCompilerInternal(args, options);
|
|
6767
8414
|
const tracer = createTracer(internal);
|
|
6768
8415
|
const collector = createCssCollector();
|
|
6769
8416
|
const compileDebug = (args) => {
|
|
6770
|
-
return rewriteTransformResult(transformDebug(internal, args, { tracer }), internal.runtimeMode);
|
|
8417
|
+
return rewriteTransformResult(transformDebug(internal, args, { tracer }), internal.runtimeMode, args.code);
|
|
6771
8418
|
};
|
|
6772
8419
|
const compileDebugRSC = (args) => {
|
|
6773
|
-
const debugResult = rewriteTransformResult(transformDebug(internal, args, { tracer }), internal.runtimeMode);
|
|
8420
|
+
const debugResult = rewriteTransformResult(transformDebug(internal, args, { tracer }), internal.runtimeMode, args.code);
|
|
6774
8421
|
if (!debugResult) return null;
|
|
6775
8422
|
const rscCollector = createCssCollector();
|
|
6776
8423
|
transformExtract(internal, args, {
|
|
@@ -6799,7 +8446,7 @@ function createCompiler(args, options) {
|
|
|
6799
8446
|
return rewriteTransformResult({
|
|
6800
8447
|
...result,
|
|
6801
8448
|
rules: collector.getItems().slice(startIndex)
|
|
6802
|
-
}, internal.runtimeMode);
|
|
8449
|
+
}, internal.runtimeMode, args.code);
|
|
6803
8450
|
};
|
|
6804
8451
|
const getExtractedCss = () => {
|
|
6805
8452
|
return extractCss(collector.getItems(), {
|
|
@@ -6829,24 +8476,74 @@ function createCompilerInternal(args, options) {
|
|
|
6829
8476
|
options
|
|
6830
8477
|
};
|
|
6831
8478
|
}
|
|
6832
|
-
function rewriteTransformResult(result, runtimeMode) {
|
|
8479
|
+
function rewriteTransformResult(result, runtimeMode, sourceCode) {
|
|
6833
8480
|
if (!result || !runtimeMode) return result;
|
|
6834
8481
|
return {
|
|
6835
8482
|
...result,
|
|
6836
|
-
code: rewriteCompilerRuntimeImports(result.code, runtimeMode)
|
|
8483
|
+
code: rewriteCompilerRuntimeImports(result.code, runtimeMode, sourceCode)
|
|
6837
8484
|
};
|
|
6838
8485
|
}
|
|
6839
|
-
function rewriteCompilerRuntimeImports(code, runtimeMode) {
|
|
6840
|
-
|
|
8486
|
+
function rewriteCompilerRuntimeImports(code, runtimeMode, sourceCode) {
|
|
8487
|
+
const importRuntimeMode = getImportRuntimeMode(runtimeMode, sourceCode);
|
|
8488
|
+
return rewriteImportSources(code, (source) => getCompilerRuntimeImportSource(source, runtimeMode, importRuntimeMode));
|
|
6841
8489
|
}
|
|
6842
|
-
function
|
|
6843
|
-
if (
|
|
6844
|
-
|
|
8490
|
+
function getImportRuntimeMode(runtimeMode, sourceCode) {
|
|
8491
|
+
if (runtimeMode === "rsc-dev" && hasUseClientDirective(sourceCode)) return "dev";
|
|
8492
|
+
return runtimeMode;
|
|
8493
|
+
}
|
|
8494
|
+
function getCompilerRuntimeImportSource(source, runtimeMode, importRuntimeMode) {
|
|
8495
|
+
if (source === "@fluentic/style") return getStyleRuntimeImportPath(importRuntimeMode);
|
|
8496
|
+
const adapterImportPath = getStyleRuntimeAdapterImportPath(source, importRuntimeMode);
|
|
8497
|
+
if (adapterImportPath) return adapterImportPath;
|
|
8498
|
+
if (source === "@fluentic/style/css") return getStyleRuntimeCssImportPath(importRuntimeMode);
|
|
6845
8499
|
if (source === "@fluentic/style/entry/prod/runtime") return getStyleExtractRuntimeImportPath(runtimeMode);
|
|
6846
8500
|
if (runtimeMode === "rsc-dev" && source === "@fluentic/style/dev/rsc") return getStyleRuntimeDevRscImportPath(runtimeMode);
|
|
6847
8501
|
return null;
|
|
6848
8502
|
}
|
|
8503
|
+
function hasUseClientDirective(code) {
|
|
8504
|
+
let index = 0;
|
|
8505
|
+
while (index < code.length) {
|
|
8506
|
+
index = skipWhitespaceAndComments(code, index);
|
|
8507
|
+
const quote = code[index];
|
|
8508
|
+
if (quote !== "\"" && quote !== "'") return false;
|
|
8509
|
+
const end = code.indexOf(quote, index + 1);
|
|
8510
|
+
if (end < 0) return false;
|
|
8511
|
+
const directive = code.slice(index + 1, end);
|
|
8512
|
+
index = skipWhitespaceAndComments(code, end + 1);
|
|
8513
|
+
if (code[index] === ";") index += 1;
|
|
8514
|
+
else if (code[index] && code[index] !== "\n" && code[index] !== "\r") return false;
|
|
8515
|
+
if (directive === "use client") return true;
|
|
8516
|
+
}
|
|
8517
|
+
return false;
|
|
8518
|
+
}
|
|
8519
|
+
function skipWhitespaceAndComments(code, index) {
|
|
8520
|
+
let next = index;
|
|
8521
|
+
while (next < code.length) {
|
|
8522
|
+
const char = code[next];
|
|
8523
|
+
if (char === " " || char === " " || char === "\n" || char === "\r") {
|
|
8524
|
+
next += 1;
|
|
8525
|
+
continue;
|
|
8526
|
+
}
|
|
8527
|
+
if (char === "/" && code[next + 1] === "/") {
|
|
8528
|
+
const lineEnd = code.indexOf("\n", next + 2);
|
|
8529
|
+
next = lineEnd < 0 ? code.length : lineEnd + 1;
|
|
8530
|
+
continue;
|
|
8531
|
+
}
|
|
8532
|
+
if (char === "/" && code[next + 1] === "*") {
|
|
8533
|
+
const commentEnd = code.indexOf("*/", next + 2);
|
|
8534
|
+
next = commentEnd < 0 ? code.length : commentEnd + 2;
|
|
8535
|
+
continue;
|
|
8536
|
+
}
|
|
8537
|
+
break;
|
|
8538
|
+
}
|
|
8539
|
+
return next;
|
|
8540
|
+
}
|
|
8541
|
+
const CssPropPresets = {
|
|
8542
|
+
Solid: { adapter: "@fluentic/style/adapter/solid" },
|
|
8543
|
+
Preact: { adapter: "@fluentic/style/adapter/preact" },
|
|
8544
|
+
React: { adapter: "@fluentic/style/adapter/react" }
|
|
8545
|
+
};
|
|
6849
8546
|
//#endregion
|
|
6850
|
-
export {
|
|
8547
|
+
export { getDefaultSourcemapUrl as a, getStyleFnMeta as c, babelTransform as d, extractCss as f, createCompilerCache as g, globalData as h, CompilerRuntimeMode as i, isPromiseLike as l, SIDECAR_URL_GLOBAL_SYMBOL as m, createCompiler as n, normalizeSourcemapSourcePath as o, compareLayerPriority as p, getStyleRuntimeImportPath as r, normalizePath as s, CssPropPresets as t, babelPlugin as u };
|
|
6851
8548
|
|
|
6852
|
-
//# sourceMappingURL=compiler-
|
|
8549
|
+
//# sourceMappingURL=compiler-C3CEGGtI.mjs.map
|