@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
|
@@ -26,18 +26,20 @@ let node_fs = require("node:fs");
|
|
|
26
26
|
node_fs = __toESM(node_fs, 1);
|
|
27
27
|
let node_path = require("node:path");
|
|
28
28
|
node_path = __toESM(node_path, 1);
|
|
29
|
+
let _babel_core = require("@babel/core");
|
|
30
|
+
_babel_core = __toESM(_babel_core, 1);
|
|
29
31
|
let picomatch = require("picomatch");
|
|
30
32
|
picomatch = __toESM(picomatch, 1);
|
|
31
33
|
let css_what = require("css-what");
|
|
32
|
-
let _babel_core = require("@babel/core");
|
|
33
|
-
_babel_core = __toESM(_babel_core, 1);
|
|
34
34
|
let oxc_resolver = require("oxc-resolver");
|
|
35
35
|
require("@parcel/plugin");
|
|
36
36
|
let node_http = require("node:http");
|
|
37
|
-
//#region utils/
|
|
37
|
+
//#region utils/symbol.ts
|
|
38
38
|
function symbol(name) {
|
|
39
39
|
return Symbol.for(`@fluentic/style.${name}`);
|
|
40
40
|
}
|
|
41
|
+
//#endregion
|
|
42
|
+
//#region utils/global.ts
|
|
41
43
|
function globalData(key, data) {
|
|
42
44
|
const id = symbol(key);
|
|
43
45
|
const root = globalThis;
|
|
@@ -53,6 +55,10 @@ function assign(target, id, value) {
|
|
|
53
55
|
});
|
|
54
56
|
}
|
|
55
57
|
//#endregion
|
|
58
|
+
//#region config/config/check.ts
|
|
59
|
+
const CHECK_CONFIG_DEFAULT = {};
|
|
60
|
+
const CHECK_CONFIG = globalData("config.check", () => ({ ...CHECK_CONFIG_DEFAULT }));
|
|
61
|
+
//#endregion
|
|
56
62
|
//#region config/config/css.ts
|
|
57
63
|
const CSS_CONFIG_DEFAULT = {
|
|
58
64
|
layer: true,
|
|
@@ -60,8 +66,15 @@ const CSS_CONFIG_DEFAULT = {
|
|
|
60
66
|
layerNamespace: "css"
|
|
61
67
|
};
|
|
62
68
|
const CSS_CONFIG = globalData("config.css", () => ({ ...CSS_CONFIG_DEFAULT }));
|
|
69
|
+
function isStyleLayerEnabled(layer = CSS_CONFIG.layer) {
|
|
70
|
+
return typeof layer === "boolean" ? layer : layer.style ?? true;
|
|
71
|
+
}
|
|
72
|
+
function isSheetLayerEnabled(layer = CSS_CONFIG.layer) {
|
|
73
|
+
return typeof layer === "object" && (layer.sheet ?? false);
|
|
74
|
+
}
|
|
63
75
|
//#endregion
|
|
64
76
|
//#region config/utils.ts
|
|
77
|
+
const SIDECAR_URL_GLOBAL_SYMBOL = "FLUENTIC_STYLE_SIDECAR_URL";
|
|
65
78
|
function getCacheTTL(cache) {
|
|
66
79
|
return cache === true ? 3e5 : cache === false ? 0 : Math.max(cache, 0);
|
|
67
80
|
}
|
|
@@ -75,15 +88,30 @@ const RUNTIME_CONFIG_DEFAULT = {
|
|
|
75
88
|
isRSC: false,
|
|
76
89
|
runtimeCacheTTL: getCacheTTL(true)
|
|
77
90
|
};
|
|
78
|
-
globalData("config.runtime", () => ({ ...RUNTIME_CONFIG_DEFAULT }));
|
|
91
|
+
const RUNTIME_CONFIG = globalData("config.runtime", () => ({ ...RUNTIME_CONFIG_DEFAULT }));
|
|
79
92
|
globalData("config.build", () => ({ current: null }));
|
|
80
93
|
//#endregion
|
|
94
|
+
//#region config/config/debug.ts
|
|
95
|
+
const DEFAULT_DEBUG_CONFIG = {
|
|
96
|
+
isDebugClassNameEnabled: false,
|
|
97
|
+
isDebugClassNameConfigured: false,
|
|
98
|
+
maxPropertyLength: 24,
|
|
99
|
+
maxValueLength: 8,
|
|
100
|
+
maxSelectorLength: 8,
|
|
101
|
+
maxParentSelectorLength: 8,
|
|
102
|
+
maxAtRuleLength: 10
|
|
103
|
+
};
|
|
104
|
+
const DEBUG_CONFIG = globalData("config.debug", () => ({ ...DEFAULT_DEBUG_CONFIG }));
|
|
105
|
+
//#endregion
|
|
81
106
|
//#region utils/hash.ts
|
|
82
107
|
function hashString(str) {
|
|
83
108
|
let hash = 2166136261;
|
|
84
109
|
for (let i = 0; i < str.length; i++) hash = Math.imul(hash ^ str.charCodeAt(i), 16777619);
|
|
85
110
|
return (hash >>> 0).toString(36).padEnd(7, "0");
|
|
86
111
|
}
|
|
112
|
+
function normalizeHashLength(length) {
|
|
113
|
+
return Number.isFinite(length) ? Math.max(1, Math.floor(length)) : 7;
|
|
114
|
+
}
|
|
87
115
|
//#endregion
|
|
88
116
|
//#region atomic/layer/layer.ts
|
|
89
117
|
function compareLayerPriority(p1, p2) {
|
|
@@ -93,8 +121,6 @@ function flattenCssLayers(layers, layerNames) {
|
|
|
93
121
|
const names = typeof layerNames === "string" ? [layerNames] : layerNames;
|
|
94
122
|
return layers.flatMap((layer) => layer === "$layer" ? names : layer).filter(Boolean);
|
|
95
123
|
}
|
|
96
|
-
//#endregion
|
|
97
|
-
//#region atomic/layer/types.ts
|
|
98
124
|
const LayerDefaultPriority = [
|
|
99
125
|
0,
|
|
100
126
|
0,
|
|
@@ -130,13 +156,6 @@ function getLayerOrderCss(layers, layerNames) {
|
|
|
130
156
|
function getLayerBlockCss(layerName, css) {
|
|
131
157
|
return "@layer " + layerName + " {" + css + "}";
|
|
132
158
|
}
|
|
133
|
-
function getLayerBundleCss(layers, layerName, css) {
|
|
134
|
-
const output = [];
|
|
135
|
-
const layerOrder = getLayerOrderCss(layers, layerName);
|
|
136
|
-
if (layerOrder) output.push(layerOrder);
|
|
137
|
-
output.push(getLayerBlockCss(layerName, "\n" + css.join("\n") + "\n"));
|
|
138
|
-
return output.join("\n");
|
|
139
|
-
}
|
|
140
159
|
//#endregion
|
|
141
160
|
//#region compiler/extract/collector.ts
|
|
142
161
|
function createCssCollector() {
|
|
@@ -156,57 +175,18 @@ function createCssCollector() {
|
|
|
156
175
|
}
|
|
157
176
|
};
|
|
158
177
|
}
|
|
159
|
-
//#endregion
|
|
160
|
-
//#region config/config/debug.ts
|
|
161
|
-
const DEFAULT_DEBUG_CONFIG = {
|
|
162
|
-
isDebugClassNameEnabled: true,
|
|
163
|
-
maxPropertyLength: 24,
|
|
164
|
-
maxValueLength: 8,
|
|
165
|
-
maxSelectorLength: 8,
|
|
166
|
-
maxParentSelectorLength: 8,
|
|
167
|
-
maxAtRuleLength: 10
|
|
168
|
-
};
|
|
169
|
-
const DEBUG_CONFIG = globalData("config.debug", () => ({ ...DEFAULT_DEBUG_CONFIG }));
|
|
170
|
-
//#endregion
|
|
171
|
-
//#region utils/object.ts
|
|
172
|
-
function toArray(value) {
|
|
173
|
-
return Array.isArray(value) ? value : value ? [value] : [];
|
|
174
|
-
}
|
|
175
|
-
function isFunction(value) {
|
|
176
|
-
return typeof value === "function";
|
|
177
|
-
}
|
|
178
|
-
//#endregion
|
|
179
|
-
//#region config/config/dev.ts
|
|
180
|
-
const DEV_CONFIG_DEFAULT = {
|
|
181
|
-
isDev: false,
|
|
182
|
-
isCheckSelectorEnabled: true,
|
|
183
|
-
isSourcemapEnabled: true,
|
|
184
|
-
isLocalClassNameEnabled: true,
|
|
185
|
-
sheetMaxRules: 1e3,
|
|
186
|
-
sheetStyleTagNonce: null,
|
|
187
|
-
stylePriorityMode: "layer",
|
|
188
|
-
sourcemapLocationMode: "style",
|
|
189
|
-
isElementClassNameEnabled: true
|
|
190
|
-
};
|
|
191
|
-
globalData("config.dev.isDev", () => ({ isDev: false }));
|
|
192
|
-
const DEV_CONFIG = globalData("config.dev", () => ({ ...DEV_CONFIG_DEFAULT }));
|
|
193
|
-
globalData("config.dev.plugin", () => ({ config: null }));
|
|
194
|
-
globalData("config.dev.base", () => ({ config: null }));
|
|
195
|
-
globalData("config.dev.utils", () => ({ config: null }));
|
|
196
178
|
const STYLE_IMPORT_PATH = "@fluentic/style";
|
|
197
179
|
const STYLE_CSS_IMPORT_PATH = "@fluentic/style/css";
|
|
180
|
+
const STYLE_DIALECT_IMPORT_PATH = "@fluentic/style/dialect";
|
|
198
181
|
const STYLE_DEV_RSC_IMPORT_PATH = "@fluentic/style/dev/rsc";
|
|
199
182
|
const STYLE_ENTRY_PROD_EXTRACT_IMPORT_PATH = "@fluentic/style/entry/prod/extract";
|
|
200
183
|
const STYLE_EXTRACT_RUNTIME_IMPORT_PATH = "@fluentic/style/entry/prod/runtime";
|
|
201
184
|
const STYLE_RSC_EXTRACT_RUNTIME_IMPORT_PATH = "@fluentic/style/entry/rsc-prod/runtime";
|
|
202
|
-
const DEFAULT_CONFIG = {
|
|
203
|
-
...CSS_CONFIG_DEFAULT,
|
|
204
|
-
localClassName: DEV_CONFIG_DEFAULT.isLocalClassNameEnabled,
|
|
205
|
-
debugClassName: DEFAULT_DEBUG_CONFIG.isDebugClassNameEnabled
|
|
206
|
-
};
|
|
185
|
+
const DEFAULT_CONFIG = { ...CSS_CONFIG_DEFAULT };
|
|
207
186
|
const IMPORT_PATHS = [
|
|
208
187
|
STYLE_IMPORT_PATH,
|
|
209
188
|
STYLE_CSS_IMPORT_PATH,
|
|
189
|
+
STYLE_DIALECT_IMPORT_PATH,
|
|
210
190
|
STYLE_DEV_RSC_IMPORT_PATH
|
|
211
191
|
];
|
|
212
192
|
const IMPORT_EXTRACT = STYLE_ENTRY_PROD_EXTRACT_IMPORT_PATH;
|
|
@@ -222,6 +202,7 @@ const FN_CREATE_FONT_PALETTE_VALUES = "createFontPaletteValues";
|
|
|
222
202
|
const FN_CREATE_POSITION_TRY = "createPositionTry";
|
|
223
203
|
const FN_CREATE_COUNTER_STYLE = "createCounterStyle";
|
|
224
204
|
const FN_CREATE_EXTRACTED_STYLE = "createExtractedStyle";
|
|
205
|
+
const FN_CREATE_EXTRACTED_SHEET = "createExtractedSheet";
|
|
225
206
|
const FN_CREATE_EXTRACTED_SLOT = "createExtractedSlot";
|
|
226
207
|
const FN_CREATE_EXTRACTED_SCOPE = "createExtractedScope";
|
|
227
208
|
const FN_CREATE_EXTRACTED_TOKEN = "createExtractedToken";
|
|
@@ -244,10 +225,30 @@ function getExtractedCssItems(items, args) {
|
|
|
244
225
|
seen.add(item.css);
|
|
245
226
|
css.push(item);
|
|
246
227
|
}
|
|
247
|
-
if (
|
|
228
|
+
if (!css.length) return "";
|
|
248
229
|
const defaults = DEFAULT_CONFIG;
|
|
249
230
|
const layerNamespace = args.layerNamespace ?? defaults.layerNamespace ?? "";
|
|
250
|
-
|
|
231
|
+
const layers = args.layers ?? defaults.layers ?? [];
|
|
232
|
+
const styleLayer = isStyleLayerEnabled(args.layer ?? defaults.layer);
|
|
233
|
+
const sheetLayerName = layerNamespace ? layerNamespace + ".sheet" : "sheet";
|
|
234
|
+
const styleItems = [];
|
|
235
|
+
const sheetItems = [];
|
|
236
|
+
const unlayeredItems = [];
|
|
237
|
+
for (let i = 0, len = css.length; i < len; i++) {
|
|
238
|
+
const item = css[i];
|
|
239
|
+
if (item.layer === "sheet") sheetItems.push(item.css);
|
|
240
|
+
else if (item.layer === false || !styleLayer) unlayeredItems.push(item.css);
|
|
241
|
+
else styleItems.push(item.css);
|
|
242
|
+
}
|
|
243
|
+
const styleLayerName = sheetItems.length && layerNamespace ? layerNamespace + ".style" : layerNamespace;
|
|
244
|
+
const layerNames = [styleItems.length ? styleLayerName : "", sheetItems.length ? sheetLayerName : ""].filter(Boolean);
|
|
245
|
+
const output = [];
|
|
246
|
+
const layerOrder = getLayerOrderCss(layers, layerNames);
|
|
247
|
+
if (layerOrder) output.push(layerOrder);
|
|
248
|
+
if (styleItems.length) output.push(getLayerBlockCss(styleLayerName, "\n" + styleItems.join("\n") + "\n"));
|
|
249
|
+
if (sheetItems.length) output.push(getLayerBlockCss(sheetLayerName, "\n" + sheetItems.join("\n") + "\n"));
|
|
250
|
+
output.push(...unlayeredItems);
|
|
251
|
+
return output.join("\n");
|
|
251
252
|
}
|
|
252
253
|
//#endregion
|
|
253
254
|
//#region compiler/utils/path.ts
|
|
@@ -447,8 +448,144 @@ function getCacheFilePath(cacheDir, args) {
|
|
|
447
448
|
function getCacheKey(args) {
|
|
448
449
|
return node_crypto.createHash("md5").update(args.cacheType).update("\0").update(node_path.resolve(args.filePath)).digest("hex");
|
|
449
450
|
}
|
|
450
|
-
|
|
451
|
-
|
|
451
|
+
//#endregion
|
|
452
|
+
//#region compiler/transform/utils/babel.ts
|
|
453
|
+
function babelPlugin(factory) {
|
|
454
|
+
return factory;
|
|
455
|
+
}
|
|
456
|
+
function babelTransform(args) {
|
|
457
|
+
let result = null;
|
|
458
|
+
try {
|
|
459
|
+
const inputSourceMap = parseInputSourceMap(args.sourcemap);
|
|
460
|
+
result = _babel_core.transformSync(args.code, {
|
|
461
|
+
...babelTransformOptions(),
|
|
462
|
+
inputSourceMap,
|
|
463
|
+
filename: args.filePath,
|
|
464
|
+
sourceFileName: args.filePath,
|
|
465
|
+
plugins: args.plugins,
|
|
466
|
+
sourceMaps: true,
|
|
467
|
+
generatorOpts: { retainLines: args.retainLines ?? false }
|
|
468
|
+
});
|
|
469
|
+
} catch (err) {
|
|
470
|
+
if (!args.errorLabel) throw err;
|
|
471
|
+
const message = getBabelError(err, args);
|
|
472
|
+
const error = new Error(message);
|
|
473
|
+
error.stack = void 0;
|
|
474
|
+
throw error;
|
|
475
|
+
}
|
|
476
|
+
if (!result || !result.code) return null;
|
|
477
|
+
return {
|
|
478
|
+
code: result.code,
|
|
479
|
+
sourcemap: result.map ? JSON.stringify(result.map) : null
|
|
480
|
+
};
|
|
481
|
+
}
|
|
482
|
+
function babelTransformOptions() {
|
|
483
|
+
return {
|
|
484
|
+
configFile: false,
|
|
485
|
+
babelrc: false,
|
|
486
|
+
parserOpts: {
|
|
487
|
+
plugins: ["typescript", "jsx"],
|
|
488
|
+
strictMode: false,
|
|
489
|
+
allowImportExportEverywhere: true
|
|
490
|
+
}
|
|
491
|
+
};
|
|
492
|
+
}
|
|
493
|
+
function parseInputSourceMap(sourcemap) {
|
|
494
|
+
if (!sourcemap) return void 0;
|
|
495
|
+
if (typeof sourcemap !== "string") return sourcemap;
|
|
496
|
+
return JSON.parse(sourcemap);
|
|
497
|
+
}
|
|
498
|
+
function getBabelError(err, args) {
|
|
499
|
+
const babelErr = err;
|
|
500
|
+
const msg = babelErr instanceof Error ? babelErr.message : String(err);
|
|
501
|
+
const codeFrame = babelErr?.codeFrame;
|
|
502
|
+
const suffix = codeFrame ? `\n\n${codeFrame}` : "";
|
|
503
|
+
return `${args.errorLabel} in ${args.filePath}:\n${msg}${suffix}`;
|
|
504
|
+
}
|
|
505
|
+
//#endregion
|
|
506
|
+
//#region compiler/transform/cssProp/plugin.ts
|
|
507
|
+
function createCssPropPlugin(args) {
|
|
508
|
+
return babelPlugin((babel) => {
|
|
509
|
+
const { types: t } = babel;
|
|
510
|
+
return {
|
|
511
|
+
pre() {
|
|
512
|
+
this.options = args.options;
|
|
513
|
+
this.mergeId = null;
|
|
514
|
+
this.programPath = null;
|
|
515
|
+
this.changed = false;
|
|
516
|
+
},
|
|
517
|
+
visitor: {
|
|
518
|
+
Program: {
|
|
519
|
+
enter(path, state) {
|
|
520
|
+
state.programPath = path;
|
|
521
|
+
state.mergeId = path.scope.generateUidIdentifier("fluenticMergeJsxProps");
|
|
522
|
+
},
|
|
523
|
+
exit(path, state) {
|
|
524
|
+
const options = getCssPropOptions(state.options);
|
|
525
|
+
if (!state.changed || !options || !state.mergeId) return;
|
|
526
|
+
path.unshiftContainer("body", t.importDeclaration([t.importSpecifier(state.mergeId, t.identifier("mergeJsxProps"))], t.stringLiteral(options.adapter)));
|
|
527
|
+
}
|
|
528
|
+
},
|
|
529
|
+
JSXOpeningElement(path, state) {
|
|
530
|
+
const keyHoistedAttributes = hoistKeyAttributes(path.node.attributes);
|
|
531
|
+
if (keyHoistedAttributes) path.node.attributes = keyHoistedAttributes;
|
|
532
|
+
if (!getCssPropOptions(state.options) || !state.mergeId) return;
|
|
533
|
+
if (!isIntrinsicElement(path.node.name)) return;
|
|
534
|
+
if (!hasCssAttribute(path.node.attributes)) return;
|
|
535
|
+
const keyAttributes = path.node.attributes.filter(isKeyAttribute);
|
|
536
|
+
const parts = path.node.attributes.filter((attr) => !isKeyAttribute(attr)).map((attr) => buildPart(t, attr));
|
|
537
|
+
path.node.attributes = [...keyAttributes, t.jsxSpreadAttribute(t.callExpression(state.mergeId, [t.arrayExpression(parts)]))];
|
|
538
|
+
state.changed = true;
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
};
|
|
542
|
+
});
|
|
543
|
+
}
|
|
544
|
+
function getCssPropOptions(options) {
|
|
545
|
+
return options.cssProp || null;
|
|
546
|
+
}
|
|
547
|
+
function isIntrinsicElement(name) {
|
|
548
|
+
return name.type === "JSXIdentifier" && /^[a-z]/.test(name.name);
|
|
549
|
+
}
|
|
550
|
+
function hasCssAttribute(attrs) {
|
|
551
|
+
return attrs.some((attr) => {
|
|
552
|
+
return attr.type === "JSXAttribute" && attr.name.type === "JSXIdentifier" && attr.name.name === "css";
|
|
553
|
+
});
|
|
554
|
+
}
|
|
555
|
+
function hoistKeyAttributes(attrs) {
|
|
556
|
+
const keyAttributes = attrs.filter(isKeyAttribute);
|
|
557
|
+
if (!keyAttributes.length) return null;
|
|
558
|
+
const firstKeyIndex = attrs.findIndex(isKeyAttribute);
|
|
559
|
+
const firstSpreadIndex = attrs.findIndex((attr) => attr.type === "JSXSpreadAttribute");
|
|
560
|
+
if (firstSpreadIndex < 0 || firstKeyIndex < firstSpreadIndex) return null;
|
|
561
|
+
return [...keyAttributes, ...attrs.filter((attr) => !isKeyAttribute(attr))];
|
|
562
|
+
}
|
|
563
|
+
function isKeyAttribute(attr) {
|
|
564
|
+
return attr.type === "JSXAttribute" && attr.name.type === "JSXIdentifier" && attr.name.name === "key";
|
|
565
|
+
}
|
|
566
|
+
function buildPart(t, attr) {
|
|
567
|
+
if (attr.type === "JSXSpreadAttribute") return attr.argument;
|
|
568
|
+
return t.objectExpression([t.objectProperty(getObjectKey(t, attr.name), getAttributeValue(t, attr))]);
|
|
569
|
+
}
|
|
570
|
+
function getObjectKey(t, name) {
|
|
571
|
+
if (name.type === "JSXIdentifier" && isValidIdentifierName(name.name)) return t.identifier(name.name);
|
|
572
|
+
return t.stringLiteral(getAttributeName(name));
|
|
573
|
+
}
|
|
574
|
+
function getAttributeName(name) {
|
|
575
|
+
if (name.type === "JSXIdentifier") return name.name;
|
|
576
|
+
return `${name.namespace.name}:${name.name.name}`;
|
|
577
|
+
}
|
|
578
|
+
function getAttributeValue(t, attr) {
|
|
579
|
+
if (!attr.value) return t.booleanLiteral(true);
|
|
580
|
+
if (attr.value.type === "StringLiteral") return t.stringLiteral(attr.value.value);
|
|
581
|
+
if (attr.value.type === "JSXExpressionContainer") {
|
|
582
|
+
if (attr.value.expression.type === "JSXEmptyExpression") return t.booleanLiteral(true);
|
|
583
|
+
return attr.value.expression;
|
|
584
|
+
}
|
|
585
|
+
return attr.value;
|
|
586
|
+
}
|
|
587
|
+
function isValidIdentifierName(name) {
|
|
588
|
+
return /^[$A-Z_a-z][$\w]*$/.test(name);
|
|
452
589
|
}
|
|
453
590
|
//#endregion
|
|
454
591
|
//#region builder/data/const.ts
|
|
@@ -458,6 +595,39 @@ const BUILDER_CALLSITE = symbol("builder.callsite");
|
|
|
458
595
|
const BUILDER_SLOT_ID = symbol("builder.slotId");
|
|
459
596
|
const BUILDER_SCOPE_ID = symbol("builder.scopeId");
|
|
460
597
|
const BUILDER_SCOPE = symbol("builder.scope");
|
|
598
|
+
const BUILDER_SELECTOR = symbol("builder.selector");
|
|
599
|
+
const BUILDER_SHEET_OPTIONS = symbol("builder.sheetOptions");
|
|
600
|
+
const SHEET_SELECTOR_ANCHOR = "\0sheet";
|
|
601
|
+
//#endregion
|
|
602
|
+
//#region utils/object.ts
|
|
603
|
+
function hasOwn(target, field) {
|
|
604
|
+
return Object.prototype.hasOwnProperty.call(target, field);
|
|
605
|
+
}
|
|
606
|
+
function toArray(value) {
|
|
607
|
+
return Array.isArray(value) ? value : value ? [value] : [];
|
|
608
|
+
}
|
|
609
|
+
function isFunction(value) {
|
|
610
|
+
return typeof value === "function";
|
|
611
|
+
}
|
|
612
|
+
//#endregion
|
|
613
|
+
//#region config/config/dev.ts
|
|
614
|
+
const DEV_CONFIG_DEFAULT = {
|
|
615
|
+
isDev: false,
|
|
616
|
+
isCheckSelectorEnabled: true,
|
|
617
|
+
isSourcemapEnabled: true,
|
|
618
|
+
isLocalClassNameEnabled: true,
|
|
619
|
+
sheetMaxRules: 1e3,
|
|
620
|
+
sheetStyleTagNonce: null,
|
|
621
|
+
hashLength: null,
|
|
622
|
+
stylePriorityMode: "sort",
|
|
623
|
+
sourcemapLocationMode: "style",
|
|
624
|
+
isElementClassNameEnabled: true
|
|
625
|
+
};
|
|
626
|
+
globalData("config.dev.isDev", () => ({ isDev: false }));
|
|
627
|
+
const DEV_CONFIG = globalData("config.dev", () => ({ ...DEV_CONFIG_DEFAULT }));
|
|
628
|
+
globalData("config.dev.plugin", () => ({ config: null }));
|
|
629
|
+
globalData("config.dev.base", () => ({ config: null }));
|
|
630
|
+
globalData("config.dev.utils", () => ({ config: null }));
|
|
461
631
|
//#endregion
|
|
462
632
|
//#region utils/trace.ts
|
|
463
633
|
const FN_MARKER = "$fn_";
|
|
@@ -609,6 +779,15 @@ function createDebugCallsite(loc, debug) {
|
|
|
609
779
|
}
|
|
610
780
|
//#endregion
|
|
611
781
|
//#region builder/data/is.ts
|
|
782
|
+
function getSlotId(data) {
|
|
783
|
+
return data[BUILDER_SLOT_ID];
|
|
784
|
+
}
|
|
785
|
+
function getScopeTargetSlotId(data) {
|
|
786
|
+
return data[BUILDER_SCOPE_ID];
|
|
787
|
+
}
|
|
788
|
+
function getScopeTargetScope(data) {
|
|
789
|
+
return data[BUILDER_SCOPE];
|
|
790
|
+
}
|
|
612
791
|
function isStyleData(value) {
|
|
613
792
|
return getBuilderType(value) === 1;
|
|
614
793
|
}
|
|
@@ -618,19 +797,33 @@ function isSlotData(value) {
|
|
|
618
797
|
function isSlotOverrideData(value) {
|
|
619
798
|
return getBuilderType(value) === 3;
|
|
620
799
|
}
|
|
800
|
+
function isSelectorData(value) {
|
|
801
|
+
return getBuilderType(value) === 7;
|
|
802
|
+
}
|
|
803
|
+
function isSheetData(value) {
|
|
804
|
+
return getBuilderType(value) === 9;
|
|
805
|
+
}
|
|
621
806
|
function isScopeData(value) {
|
|
622
807
|
return getBuilderType(value) === 4;
|
|
623
808
|
}
|
|
809
|
+
function isThemeData(value) {
|
|
810
|
+
return getBuilderType(value) === 6;
|
|
811
|
+
}
|
|
624
812
|
function getBuilderType(value) {
|
|
625
813
|
if (!value || typeof value !== "object" && typeof value !== "function") return null;
|
|
626
814
|
return value[BUILDER_TYPE];
|
|
627
815
|
}
|
|
816
|
+
function normalizeSelectorArg(arg) {
|
|
817
|
+
return arg.includes("\n") ? arg.replace(/\n/g, "") : arg;
|
|
818
|
+
}
|
|
628
819
|
//#endregion
|
|
629
|
-
//#region
|
|
820
|
+
//#region builder/token/symbols.ts
|
|
630
821
|
const TOKEN_ID = symbol("style:token");
|
|
631
822
|
const TOKEN_OVERRIDE = symbol("style:token.override");
|
|
632
|
-
symbol("style:token.
|
|
633
|
-
|
|
823
|
+
const TOKEN_NAME = symbol("style:token.name");
|
|
824
|
+
const TOKEN_VAR_NAME = symbol("style:token.varName");
|
|
825
|
+
//#endregion
|
|
826
|
+
//#region builder/token/data.ts
|
|
634
827
|
function isStyleTokenData(value) {
|
|
635
828
|
return !!value && typeof value[TOKEN_ID] === "string" && value[TOKEN_OVERRIDE] !== true;
|
|
636
829
|
}
|
|
@@ -640,6 +833,84 @@ function isStyleTokenOverrideData(value) {
|
|
|
640
833
|
function getStyleTokenId(token) {
|
|
641
834
|
return token[TOKEN_ID];
|
|
642
835
|
}
|
|
836
|
+
function getStyleTokenName(token) {
|
|
837
|
+
return token[TOKEN_NAME] ?? null;
|
|
838
|
+
}
|
|
839
|
+
//#endregion
|
|
840
|
+
//#region builder/token/name.ts
|
|
841
|
+
function getStyleTokenNameFromId(id) {
|
|
842
|
+
if (!id) return null;
|
|
843
|
+
const parts = id.split("--");
|
|
844
|
+
const first = normalizeStyleTokenName(parts[0]);
|
|
845
|
+
if (!first) return parts.length > 1 ? normalizeStyleTokenName(parts.slice(1).join("--")) : null;
|
|
846
|
+
return normalizeStyleTokenName([first, ...parts.slice(1)].join("--"));
|
|
847
|
+
}
|
|
848
|
+
function getChildStyleTokenName(name, child) {
|
|
849
|
+
const childName = normalizeStyleTokenName(child);
|
|
850
|
+
if (!childName) return normalizeStyleTokenName(name);
|
|
851
|
+
const parentName = normalizeStyleTokenName(name);
|
|
852
|
+
return parentName ? parentName + "--" + childName : childName;
|
|
853
|
+
}
|
|
854
|
+
function normalizeStyleTokenName(value) {
|
|
855
|
+
if (!value) return null;
|
|
856
|
+
value = value.trim();
|
|
857
|
+
if (!value) return null;
|
|
858
|
+
if (/^\d+$/.test(value)) return null;
|
|
859
|
+
if (isGeneratedTokenHash(value)) return null;
|
|
860
|
+
value = stripGenericTokenPrefix(value);
|
|
861
|
+
if (!value) return null;
|
|
862
|
+
const stableSuffix = value.match(/^(.+)-[a-z0-9]{7}$/);
|
|
863
|
+
if (stableSuffix?.[1] && isGeneratedTokenHash(value.slice(-7))) return normalizeStyleTokenName(stableSuffix[1]);
|
|
864
|
+
return value;
|
|
865
|
+
}
|
|
866
|
+
function isGeneratedTokenHash(value) {
|
|
867
|
+
return /^[a-z0-9]{7}$/.test(value) && /\d/.test(value);
|
|
868
|
+
}
|
|
869
|
+
function stripGenericTokenPrefix(value) {
|
|
870
|
+
const parts = value.split("--");
|
|
871
|
+
while (parts[0] === "token" || parts[0] === "tokens") parts.shift();
|
|
872
|
+
return parts.join("--");
|
|
873
|
+
}
|
|
874
|
+
//#endregion
|
|
875
|
+
//#region style/token.ts
|
|
876
|
+
const TOKEN_DEBUG = symbol("style:token.debug");
|
|
877
|
+
const idCounter$6 = globalData("style.token.idCounter", () => ({ value: 0 }));
|
|
878
|
+
function createStyleToken(value, stableId, debugName) {
|
|
879
|
+
const token = (value, debug) => {
|
|
880
|
+
return createStyleTokenOverride(token, value, debug);
|
|
881
|
+
};
|
|
882
|
+
token[TOKEN_ID] = stableId || String(idCounter$6.value++);
|
|
883
|
+
token[TOKEN_NAME] = debugName === void 0 ? getStyleTokenNameFromId(stableId) : normalizeStyleTokenName(debugName);
|
|
884
|
+
if (isStyleTokenData(value)) {
|
|
885
|
+
token.value = value.value;
|
|
886
|
+
token.ref = value;
|
|
887
|
+
} else {
|
|
888
|
+
token.value = value;
|
|
889
|
+
token.ref = null;
|
|
890
|
+
}
|
|
891
|
+
return token;
|
|
892
|
+
}
|
|
893
|
+
function createStyleTokenOverride(token, value, debug) {
|
|
894
|
+
const override = isStyleTokenData(value) ? {
|
|
895
|
+
[TOKEN_ID]: getStyleTokenId(token),
|
|
896
|
+
[TOKEN_OVERRIDE]: true,
|
|
897
|
+
[TOKEN_NAME]: getStyleTokenName(token),
|
|
898
|
+
value: value.value,
|
|
899
|
+
ref: value
|
|
900
|
+
} : {
|
|
901
|
+
[TOKEN_ID]: getStyleTokenId(token),
|
|
902
|
+
[TOKEN_OVERRIDE]: true,
|
|
903
|
+
[TOKEN_NAME]: getStyleTokenName(token),
|
|
904
|
+
value,
|
|
905
|
+
ref: null
|
|
906
|
+
};
|
|
907
|
+
if (debug) Object.defineProperty(override, TOKEN_DEBUG, {
|
|
908
|
+
configurable: true,
|
|
909
|
+
enumerable: false,
|
|
910
|
+
value: debug
|
|
911
|
+
});
|
|
912
|
+
return override;
|
|
913
|
+
}
|
|
643
914
|
//#endregion
|
|
644
915
|
//#region selector/selector.ts
|
|
645
916
|
function selector(selector, ...args) {
|
|
@@ -749,138 +1020,30 @@ const PrioritySelectors = selectorPriority({
|
|
|
749
1020
|
"link",
|
|
750
1021
|
"visited",
|
|
751
1022
|
"hover",
|
|
752
|
-
"focusWithin",
|
|
753
|
-
"focus",
|
|
754
|
-
"focusVisible",
|
|
755
|
-
"active",
|
|
756
|
-
"disabled"
|
|
757
|
-
]);
|
|
758
|
-
selectorPriority({
|
|
759
|
-
hover: PseudoSelectors.hover,
|
|
760
|
-
active: PseudoSelectors.active,
|
|
761
|
-
focus: PseudoSelectors.focus,
|
|
762
|
-
focusWithin: PseudoSelectors.focusWithin,
|
|
763
|
-
disabled: PseudoSelectors.disabled,
|
|
764
|
-
firstChild: PseudoSelectors.firstChild,
|
|
765
|
-
lastChild: PseudoSelectors.lastChild,
|
|
766
|
-
nthChild: PseudoArgSelectors.nthChild,
|
|
767
|
-
nthOfType: PseudoArgSelectors.nthOfType,
|
|
768
|
-
is: PseudoArgSelectors.is,
|
|
769
|
-
where: PseudoArgSelectors.where,
|
|
770
|
-
not: PseudoArgSelectors.not,
|
|
771
|
-
has: PseudoArgSelectors.has,
|
|
772
|
-
...PseudoElementSelectors,
|
|
773
|
-
...ArgSelectors,
|
|
774
|
-
...AtRuleSelectors
|
|
775
|
-
}, PrioritySelectors);
|
|
776
|
-
//#endregion
|
|
777
|
-
//#region selector/validate.ts
|
|
778
|
-
function isLocalSelector(selector) {
|
|
779
|
-
const groups = parseSelector(selector);
|
|
780
|
-
if (!groups || groups.length !== 1) return false;
|
|
781
|
-
return isSelectorGroupsSelf(groups, false);
|
|
782
|
-
}
|
|
783
|
-
function isPseudoArgSelector(selector) {
|
|
784
|
-
const groups = parseSelector(selector);
|
|
785
|
-
if (!groups || groups.length !== 1) return false;
|
|
786
|
-
return isSelectorGroupsSelf(groups, true);
|
|
787
|
-
}
|
|
788
|
-
function isTagSelector(selector) {
|
|
789
|
-
const groups = parseSelector(selector);
|
|
790
|
-
if (!groups || groups.length !== 1) return false;
|
|
791
|
-
const group = groups[0];
|
|
792
|
-
return group.length === 1 && group[0].type === css_what.SelectorType.Tag;
|
|
793
|
-
}
|
|
794
|
-
function isAttrArg(value) {
|
|
795
|
-
if (!value) return false;
|
|
796
|
-
if (value.includes("[") || value.includes("]")) return false;
|
|
797
|
-
return true;
|
|
798
|
-
}
|
|
799
|
-
function isRawValue(value) {
|
|
800
|
-
if (!value) return false;
|
|
801
|
-
if (value.includes("{") || value.includes("}")) return false;
|
|
802
|
-
return true;
|
|
803
|
-
}
|
|
804
|
-
function parseSelector(selector) {
|
|
805
|
-
try {
|
|
806
|
-
return (0, css_what.parse)(selector);
|
|
807
|
-
} catch {
|
|
808
|
-
return;
|
|
809
|
-
}
|
|
810
|
-
}
|
|
811
|
-
function isSelectorGroupsSelf(groups, allowTag) {
|
|
812
|
-
for (let i = 0; i < groups.length; i++) {
|
|
813
|
-
const group = groups[i];
|
|
814
|
-
for (let j = 0; j < group.length; j++) {
|
|
815
|
-
const token = group[j];
|
|
816
|
-
if (!isAllowedSelectorType(token.type, allowTag)) return false;
|
|
817
|
-
if (token.type === css_what.SelectorType.Pseudo && Array.isArray(token.data) && !isSelectorGroupsSelf(token.data, allowTag)) return false;
|
|
818
|
-
}
|
|
819
|
-
}
|
|
820
|
-
return true;
|
|
821
|
-
}
|
|
822
|
-
function isAllowedSelectorType(type, allowTag) {
|
|
823
|
-
return type === css_what.SelectorType.Attribute || type === css_what.SelectorType.Pseudo || type === css_what.SelectorType.PseudoElement || allowTag && type === css_what.SelectorType.Tag;
|
|
824
|
-
}
|
|
825
|
-
//#endregion
|
|
826
|
-
//#region selector/assert.ts
|
|
827
|
-
function assertSelector(type, value) {
|
|
828
|
-
assertSelectorNotEmpty(value);
|
|
829
|
-
if (!type) return;
|
|
830
|
-
if (typeof type === "function") return type(value);
|
|
831
|
-
switch (type) {
|
|
832
|
-
case "local": return assertLocalSelector(value);
|
|
833
|
-
case "arg": return assertPseudoArgSelector(value);
|
|
834
|
-
case "tag": return assertTagSelector(value);
|
|
835
|
-
case "attr": return assertAttrSelector(value);
|
|
836
|
-
case "value": return assertRawValue(value);
|
|
837
|
-
case "media": return assertMediaQuery(value);
|
|
838
|
-
case "supports": return assertSupportsQuery(value);
|
|
839
|
-
case "container": return assertContainerQuery(value);
|
|
840
|
-
default: throw new Error("unsupported selector type: " + value);
|
|
841
|
-
}
|
|
842
|
-
}
|
|
843
|
-
const assertSelectorNotEmpty = createSelectorAssert((value) => {
|
|
844
|
-
if (!value) throw new Error("selector cannot be empty");
|
|
845
|
-
});
|
|
846
|
-
const assertLocalSelector = createSelectorAssert((value) => {
|
|
847
|
-
if (!isLocalSelector(value)) throw new Error("selector must target the current element only and cannot contain tags, combinators, or multiple selectors");
|
|
848
|
-
});
|
|
849
|
-
const assertPseudoArgSelector = createSelectorAssert((value) => {
|
|
850
|
-
if (!isPseudoArgSelector(value)) throw new Error("pseudo selector argument must contain only tags or selectors targeting the current element");
|
|
851
|
-
});
|
|
852
|
-
const assertTagSelector = createSelectorAssert((value) => {
|
|
853
|
-
if (!isTagSelector(value)) throw new Error("selector must be a single tag selector");
|
|
854
|
-
});
|
|
855
|
-
const assertAttrSelector = createSelectorAssert((value) => {
|
|
856
|
-
if (!isAttrArg(value)) throw new Error("attribute selector value must not include \"[\" or \"]\"");
|
|
857
|
-
});
|
|
858
|
-
const assertRawValue = createSelectorAssert((value) => {
|
|
859
|
-
if (!isRawValue(value)) throw new Error("value must not contain \"{\" or \"}\"");
|
|
860
|
-
});
|
|
861
|
-
const assertMediaQuery = createSelectorAssert((value) => {
|
|
862
|
-
if (!isRawValue(value)) throw new Error("media query must not contain \"{\" or \"}\"");
|
|
863
|
-
});
|
|
864
|
-
const assertSupportsQuery = createSelectorAssert((value) => {
|
|
865
|
-
if (!isRawValue(value)) throw new Error("supports query must not contain \"{\" or \"}\"");
|
|
866
|
-
});
|
|
867
|
-
const assertContainerQuery = createSelectorAssert((value) => {
|
|
868
|
-
if (!isRawValue(value)) throw new Error("container query must not contain \"{\" or \"}\"");
|
|
869
|
-
});
|
|
870
|
-
//#endregion
|
|
871
|
-
//#region builder/data/check_selector.ts
|
|
872
|
-
function checkSelector(fnPrefix, fnName, fnSelector, arg) {
|
|
873
|
-
let message = null;
|
|
874
|
-
try {
|
|
875
|
-
assertSelector(fnSelector.assert, arg);
|
|
876
|
-
} catch (error) {
|
|
877
|
-
if (typeof error === "string" && error.trim()) message = error;
|
|
878
|
-
else if (typeof error === "object" && error && error instanceof Error) message = (error.message || "").trim();
|
|
879
|
-
else message = "selector is invalid: " + arg;
|
|
880
|
-
}
|
|
881
|
-
if (!message) return;
|
|
882
|
-
throw traceError(`${fnPrefix}${fnName}(${arg || ""}): ${message}`);
|
|
883
|
-
}
|
|
1023
|
+
"focusWithin",
|
|
1024
|
+
"focus",
|
|
1025
|
+
"focusVisible",
|
|
1026
|
+
"active",
|
|
1027
|
+
"disabled"
|
|
1028
|
+
]);
|
|
1029
|
+
selectorPriority({
|
|
1030
|
+
hover: PseudoSelectors.hover,
|
|
1031
|
+
active: PseudoSelectors.active,
|
|
1032
|
+
focus: PseudoSelectors.focus,
|
|
1033
|
+
focusWithin: PseudoSelectors.focusWithin,
|
|
1034
|
+
disabled: PseudoSelectors.disabled,
|
|
1035
|
+
firstChild: PseudoSelectors.firstChild,
|
|
1036
|
+
lastChild: PseudoSelectors.lastChild,
|
|
1037
|
+
nthChild: PseudoArgSelectors.nthChild,
|
|
1038
|
+
nthOfType: PseudoArgSelectors.nthOfType,
|
|
1039
|
+
is: PseudoArgSelectors.is,
|
|
1040
|
+
where: PseudoArgSelectors.where,
|
|
1041
|
+
not: PseudoArgSelectors.not,
|
|
1042
|
+
has: PseudoArgSelectors.has,
|
|
1043
|
+
...PseudoElementSelectors,
|
|
1044
|
+
...ArgSelectors,
|
|
1045
|
+
...AtRuleSelectors
|
|
1046
|
+
}, PrioritySelectors);
|
|
884
1047
|
//#endregion
|
|
885
1048
|
//#region builder/data/create.ts
|
|
886
1049
|
function createStyleData(callsite) {
|
|
@@ -915,6 +1078,28 @@ function createSlotOverrideData(callsite, slotId) {
|
|
|
915
1078
|
[BUILDER_SLOT_ID]: slotId
|
|
916
1079
|
};
|
|
917
1080
|
}
|
|
1081
|
+
function createSelectorOverrideData(callsite, selectors) {
|
|
1082
|
+
return {
|
|
1083
|
+
[BUILDER_TYPE]: 8,
|
|
1084
|
+
[BUILDER_STATE]: {
|
|
1085
|
+
items: [],
|
|
1086
|
+
lookup: {}
|
|
1087
|
+
},
|
|
1088
|
+
[BUILDER_CALLSITE]: callsite,
|
|
1089
|
+
[BUILDER_SELECTOR]: selectors
|
|
1090
|
+
};
|
|
1091
|
+
}
|
|
1092
|
+
function createSelectorData(callsite, selectors) {
|
|
1093
|
+
return {
|
|
1094
|
+
[BUILDER_TYPE]: 7,
|
|
1095
|
+
[BUILDER_STATE]: {
|
|
1096
|
+
items: [],
|
|
1097
|
+
lookup: {}
|
|
1098
|
+
},
|
|
1099
|
+
[BUILDER_CALLSITE]: callsite,
|
|
1100
|
+
[BUILDER_SELECTOR]: selectors
|
|
1101
|
+
};
|
|
1102
|
+
}
|
|
918
1103
|
function createScopeData(callsite) {
|
|
919
1104
|
return {
|
|
920
1105
|
[BUILDER_TYPE]: 4,
|
|
@@ -953,7 +1138,7 @@ function createNameFormatter(keys) {
|
|
|
953
1138
|
const name = getFormatFn(format)(info);
|
|
954
1139
|
if (!hash) return name;
|
|
955
1140
|
if (name.includes(HASH_TOKEN)) return name.replace(HASH_TOKEN, hash);
|
|
956
|
-
return name ? name + "
|
|
1141
|
+
return name ? name + "--" + hash : hash;
|
|
957
1142
|
};
|
|
958
1143
|
}
|
|
959
1144
|
function compileFormat(format, keySet) {
|
|
@@ -1046,40 +1231,51 @@ const formatClassName = createNameFormatter([
|
|
|
1046
1231
|
"selector",
|
|
1047
1232
|
"value"
|
|
1048
1233
|
]);
|
|
1049
|
-
const
|
|
1234
|
+
const formatTransformClassName = createNameFormatter(["className"]);
|
|
1050
1235
|
function getDebugClassName(format, hash, info) {
|
|
1051
|
-
return formatClassName(format || "[(atRule)-][(scopeSelector)-](property)[-(selector)][-(value)]
|
|
1236
|
+
return formatClassName(format || "[(atRule)-][(scopeSelector)-](property)[-(selector)][-(value)]--$hash", hash, info);
|
|
1052
1237
|
}
|
|
1053
|
-
function
|
|
1054
|
-
return
|
|
1238
|
+
function getDebugSheetClassName(format, hash, info) {
|
|
1239
|
+
return formatClassName(format || "sheet-(property)[-(value)]--$hash", hash, info);
|
|
1055
1240
|
}
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
function getCssVar(varName, value) {
|
|
1059
|
-
return "var(" + varName + ", " + escapeCssValue(value) + ")";
|
|
1060
|
-
}
|
|
1061
|
-
function getCssVarRawFallback(varName, fallbackCss) {
|
|
1062
|
-
return "var(" + varName + ", " + fallbackCss + ")";
|
|
1063
|
-
}
|
|
1064
|
-
function escapeCssValue(value) {
|
|
1065
|
-
if (!value) return "";
|
|
1066
|
-
return value.trim().replace(/\\/g, "\\\\").replace(/"/g, "\\\"").replace(/'/g, "\\'").replace(/;/g, "\\;");
|
|
1241
|
+
function getDebugTransformClassName(format, hash, info) {
|
|
1242
|
+
return formatTransformClassName(format || "(className)--$hash", hash, info);
|
|
1067
1243
|
}
|
|
1244
|
+
//#endregion
|
|
1245
|
+
//#region atomic/utils/cssIdent.ts
|
|
1068
1246
|
function escapeCssIdent(ident) {
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1247
|
+
let result = "";
|
|
1248
|
+
for (let i = 0; i < ident.length; i++) {
|
|
1249
|
+
const char = ident.charAt(i);
|
|
1250
|
+
const code = ident.charCodeAt(i);
|
|
1251
|
+
const nextCode = ident.charCodeAt(i + 1);
|
|
1252
|
+
if (code === 0) {
|
|
1253
|
+
result += "�";
|
|
1254
|
+
continue;
|
|
1255
|
+
}
|
|
1256
|
+
if (code >= 1 && code <= 31 || code === 127 || i === 0 && code >= 48 && code <= 57 || i === 1 && code >= 48 && code <= 57 && ident.charCodeAt(0) === 45) {
|
|
1257
|
+
result += "\\" + code.toString(16) + " ";
|
|
1258
|
+
continue;
|
|
1259
|
+
}
|
|
1260
|
+
if (i === 0 && code === 45 && ident.length === 1) {
|
|
1261
|
+
result += "\\-";
|
|
1262
|
+
continue;
|
|
1263
|
+
}
|
|
1264
|
+
if (code >= 55296 && code <= 56319 && nextCode >= 56320 && nextCode <= 57343) {
|
|
1265
|
+
result += char + ident.charAt(++i);
|
|
1266
|
+
continue;
|
|
1267
|
+
}
|
|
1268
|
+
if (code >= 128 || code === 45 || code === 95 || code >= 48 && code <= 57 || code >= 65 && code <= 90 || code >= 97 && code <= 122) {
|
|
1269
|
+
result += char;
|
|
1270
|
+
continue;
|
|
1271
|
+
}
|
|
1272
|
+
result += "\\" + char;
|
|
1273
|
+
}
|
|
1274
|
+
return result;
|
|
1073
1275
|
}
|
|
1074
1276
|
function sanitizeCssIdentName(value, fallback = "") {
|
|
1075
1277
|
return value.replace(/[^a-zA-Z0-9_-]+/g, "-").replace(/^-+|-+$/g, "") || fallback;
|
|
1076
1278
|
}
|
|
1077
|
-
function getIdentifierSafeHash(value) {
|
|
1078
|
-
const hash = hashString(value);
|
|
1079
|
-
const first = hash.charCodeAt(0);
|
|
1080
|
-
if (first < 48 || first > 57) return hash;
|
|
1081
|
-
return String.fromCharCode(97 + first - 48) + hash.slice(1);
|
|
1082
|
-
}
|
|
1083
1279
|
//#endregion
|
|
1084
1280
|
//#region atomic/utils/debug.ts
|
|
1085
1281
|
function normalizeDebugKeywordValue(value) {
|
|
@@ -1236,45 +1432,96 @@ function parseAtRule(rule) {
|
|
|
1236
1432
|
if (normalized.startsWith("@supports")) return compressQuery(normalized.slice(9));
|
|
1237
1433
|
return compressQuery(normalized);
|
|
1238
1434
|
}
|
|
1435
|
+
function getScopeClassName(className, scopeClassNameFormat) {
|
|
1436
|
+
return formatScopeClassName$1(scopeClassNameFormat || "-(className)", { className });
|
|
1437
|
+
}
|
|
1438
|
+
function formatScopeClassName$1(format, info) {
|
|
1439
|
+
if (typeof format === "function") return format(info);
|
|
1440
|
+
return format.replace(/\[|\]/g, "").replace(/\(className\)/g, info.className);
|
|
1441
|
+
}
|
|
1442
|
+
//#endregion
|
|
1443
|
+
//#region atomic/utils/hash.ts
|
|
1444
|
+
function getIdentifierSafeHash(value, startLength = 7) {
|
|
1445
|
+
const normalizedStartLength = normalizeHashLength(startLength);
|
|
1446
|
+
return getIdentifierSafeHashValue(hashString(value)).slice(0, normalizedStartLength);
|
|
1447
|
+
}
|
|
1448
|
+
function getIdentifierSafeHashValue(hash) {
|
|
1449
|
+
const first = hash.charCodeAt(0);
|
|
1450
|
+
if (first < 48 || first > 57) return hash;
|
|
1451
|
+
return String.fromCharCode(97 + first - 48) + hash.slice(1);
|
|
1452
|
+
}
|
|
1239
1453
|
//#endregion
|
|
1240
1454
|
//#region atomic/utils/selector.ts
|
|
1241
|
-
function getSelectorText(selector) {
|
|
1242
|
-
return Array.isArray(selector) ? selector[0] : selector;
|
|
1455
|
+
function getSelectorText$1(selector) {
|
|
1456
|
+
return stripSheetSelectorAnchor(Array.isArray(selector) ? selector[0] : selector);
|
|
1243
1457
|
}
|
|
1244
1458
|
function getSelectorHash(selector) {
|
|
1245
1459
|
return Array.isArray(selector) ? selector.join("|") : selector;
|
|
1246
1460
|
}
|
|
1247
|
-
function getSelectorPriority(selector) {
|
|
1461
|
+
function getSelectorPriority$1(selector) {
|
|
1248
1462
|
if (!selector) return 0;
|
|
1249
1463
|
return Array.isArray(selector) ? selector[1] : 0;
|
|
1250
1464
|
}
|
|
1465
|
+
function hasSheetSelectorAnchor(selector) {
|
|
1466
|
+
return (selector ? Array.isArray(selector) ? selector[0] : selector : "").startsWith(SHEET_SELECTOR_ANCHOR);
|
|
1467
|
+
}
|
|
1468
|
+
function getSheetSelectorWeight(selector) {
|
|
1469
|
+
const text = selector ? Array.isArray(selector) ? selector[0] : selector : "";
|
|
1470
|
+
if (!text.startsWith("\0sheet:")) return null;
|
|
1471
|
+
const end = text.indexOf("\0", 6);
|
|
1472
|
+
if (end < 0) return null;
|
|
1473
|
+
const [weightValue] = text.slice(7, end).split(":");
|
|
1474
|
+
const weight = Number(weightValue);
|
|
1475
|
+
return Number.isInteger(weight) && weight > 0 ? weight : null;
|
|
1476
|
+
}
|
|
1477
|
+
function stripSheetSelectorAnchor(selector) {
|
|
1478
|
+
if (!selector.startsWith("\0sheet")) return selector;
|
|
1479
|
+
if (selector.startsWith("\0sheet:")) {
|
|
1480
|
+
const end = selector.indexOf("\0", 6);
|
|
1481
|
+
if (end >= 0) return selector.slice(end + 1);
|
|
1482
|
+
}
|
|
1483
|
+
return selector.slice(6);
|
|
1484
|
+
}
|
|
1251
1485
|
//#endregion
|
|
1252
1486
|
//#region atomic/className.ts
|
|
1253
|
-
function getAtomicClassName(property, priority, value, selector, parentSelector, atRule, callsite, localClassName, debugClassName, classNameFormat) {
|
|
1487
|
+
function getAtomicClassName(property, priority, important, value, selector, parentSelector, atRule, callsite, localClassName, debugClassName, classNameFormat, transformClassName, transformClassNameFormat, sheetClassNameFormat = null, hashLength = null) {
|
|
1254
1488
|
let hash = property;
|
|
1255
1489
|
hash += "\n" + (priority || "");
|
|
1490
|
+
if (important) hash += "\nimportant";
|
|
1256
1491
|
hash += "\n" + value;
|
|
1257
1492
|
hash += "\n" + (selector ? getSelectorHash(selector) : "");
|
|
1258
1493
|
hash += "\n" + (parentSelector ? getSelectorHash(parentSelector) : "");
|
|
1259
1494
|
hash += "\n" + (atRule ? atRule.map(getSelectorHash).join("\n") : "");
|
|
1260
1495
|
hash += "\n" + getCallsiteHash(callsite, localClassName);
|
|
1261
|
-
hash = getIdentifierSafeHash(hash);
|
|
1496
|
+
hash = getIdentifierSafeHash(hash, hashLength ?? getRuntimeClassNameHashLength(debugClassName));
|
|
1262
1497
|
if (!debugClassName) return hash;
|
|
1498
|
+
if (transformClassName) return getDebugTransformClassName(transformClassNameFormat, hash, { className: transformClassName });
|
|
1263
1499
|
const propertyName = getDebugPropertyName(property, value);
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1500
|
+
const isSheetClassName = hasSheetSelectorAnchor(selector);
|
|
1501
|
+
return (isSheetClassName ? getDebugSheetClassName : getDebugClassName)(isSheetClassName ? sheetClassNameFormat : classNameFormat, hash, {
|
|
1502
|
+
atRule: atRule ? getDebugAtRuleName(atRule.map(getSelectorText$1)) : null,
|
|
1503
|
+
scopeSelector: parentSelector ? getDebugSelectorName(getSelectorText$1(parentSelector)) : null,
|
|
1504
|
+
selector: selector ? getDebugSelectorName(getSelectorText$1(selector)) : null,
|
|
1268
1505
|
property: propertyName ? propertyName.property : property,
|
|
1269
1506
|
value: propertyName ? propertyName.value ?? propertyName.arbitraryValue : null
|
|
1270
1507
|
});
|
|
1271
1508
|
}
|
|
1272
|
-
function
|
|
1273
|
-
return
|
|
1509
|
+
function getRuntimeClassNameHashLength(debugClassName) {
|
|
1510
|
+
return getClassNameHashLength({
|
|
1511
|
+
debugClassName,
|
|
1512
|
+
isDev: DEV_CONFIG.isDev,
|
|
1513
|
+
devHashLength: DEV_CONFIG.hashLength,
|
|
1514
|
+
cssHashLength: CSS_CONFIG.hashLength
|
|
1515
|
+
});
|
|
1274
1516
|
}
|
|
1275
|
-
function
|
|
1517
|
+
function getClassNameHashLength(options) {
|
|
1518
|
+
if (options.debugClassName && options.isDev) return options.devHashLength ?? options.cssHashLength ?? 5;
|
|
1519
|
+
return options.cssHashLength ?? 7;
|
|
1520
|
+
}
|
|
1521
|
+
function getClassNameDedupe(property, priority, important, selector, parentSelector, atRule) {
|
|
1276
1522
|
let hash = property;
|
|
1277
1523
|
hash += "\n" + (priority || "");
|
|
1524
|
+
if (important) hash += "\nimportant";
|
|
1278
1525
|
hash += "\n" + (selector ? getSelectorHash(selector) : "");
|
|
1279
1526
|
hash += "\n" + (parentSelector ? getSelectorHash(parentSelector) : "");
|
|
1280
1527
|
hash += "\n" + (atRule ? atRule.map(getSelectorHash).join("\n") : "");
|
|
@@ -1311,7 +1558,8 @@ function mergeScopeData(scope, callsite, items, debug, parentSelector, scopeAtRu
|
|
|
1311
1558
|
let source;
|
|
1312
1559
|
let item;
|
|
1313
1560
|
let lookupIndex;
|
|
1314
|
-
let
|
|
1561
|
+
let weight;
|
|
1562
|
+
let important;
|
|
1315
1563
|
let value;
|
|
1316
1564
|
let atRule;
|
|
1317
1565
|
let dedupe;
|
|
@@ -1322,7 +1570,7 @@ function mergeScopeData(scope, callsite, items, debug, parentSelector, scopeAtRu
|
|
|
1322
1570
|
source = sourceItems[i];
|
|
1323
1571
|
if (!source) continue;
|
|
1324
1572
|
if (isStyleTokenOverrideData(source)) {
|
|
1325
|
-
addTokenOverride(source, styles, lookup);
|
|
1573
|
+
addTokenOverride$1(source, styles, lookup);
|
|
1326
1574
|
continue;
|
|
1327
1575
|
}
|
|
1328
1576
|
if (isScopeData(source)) {
|
|
@@ -1330,7 +1578,7 @@ function mergeScopeData(scope, callsite, items, debug, parentSelector, scopeAtRu
|
|
|
1330
1578
|
for (let j = 0, len = scopeItems.length; j < len; j++) {
|
|
1331
1579
|
item = scopeItems[j];
|
|
1332
1580
|
if (isStyleTokenOverrideData(item)) {
|
|
1333
|
-
addTokenOverride(item, styles, lookup);
|
|
1581
|
+
addTokenOverride$1(item, styles, lookup);
|
|
1334
1582
|
continue;
|
|
1335
1583
|
}
|
|
1336
1584
|
if (Array.isArray(item) || item.type !== 4) {
|
|
@@ -1351,13 +1599,10 @@ function mergeScopeData(scope, callsite, items, debug, parentSelector, scopeAtRu
|
|
|
1351
1599
|
itemDebug = getMergedScopeDebug(debug, scopeItem);
|
|
1352
1600
|
itemCallsite = getDebugFieldCallsite(itemDebug ?? null, scopeItem.property) ?? callsite ?? scopeItem.callsite;
|
|
1353
1601
|
value = scopeItem.value;
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
}
|
|
1359
|
-
dedupe = getClassNameDedupe(scopeItem.property, priority, scopeItem.selector, scopeItem.parentSelector, scopeItem.atRule);
|
|
1360
|
-
className = getAtomicClassName(scopeItem.property, priority, value, scopeItem.selector, scopeItem.parentSelector, scopeItem.atRule, itemCallsite, DEV_CONFIG.isLocalClassNameEnabled, DEBUG_CONFIG.isDebugClassNameEnabled, CSS_CONFIG.classNameFormat ?? null);
|
|
1602
|
+
weight = scopeItem.weight;
|
|
1603
|
+
important = scopeItem.important;
|
|
1604
|
+
dedupe = getClassNameDedupe(scopeItem.property, weight, important, scopeItem.selector, scopeItem.parentSelector, scopeItem.atRule);
|
|
1605
|
+
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);
|
|
1361
1606
|
scopeItem.dedupe = dedupe;
|
|
1362
1607
|
scopeItem.className = className;
|
|
1363
1608
|
scopeItem.callsite = itemCallsite;
|
|
@@ -1394,7 +1639,10 @@ function mergeScopeData(scope, callsite, items, debug, parentSelector, scopeAtRu
|
|
|
1394
1639
|
dedupe: "",
|
|
1395
1640
|
className: "",
|
|
1396
1641
|
property: overrideItem.property,
|
|
1642
|
+
weight: overrideItem.weight,
|
|
1643
|
+
important: overrideItem.important,
|
|
1397
1644
|
value: overrideItem.value,
|
|
1645
|
+
transformClassName: overrideItem.transformClassName,
|
|
1398
1646
|
token: overrideItem.token,
|
|
1399
1647
|
selector: overrideItem.selector,
|
|
1400
1648
|
atRule,
|
|
@@ -1404,13 +1652,10 @@ function mergeScopeData(scope, callsite, items, debug, parentSelector, scopeAtRu
|
|
|
1404
1652
|
parentSelector
|
|
1405
1653
|
};
|
|
1406
1654
|
value = scopeItem.value;
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
}
|
|
1412
|
-
dedupe = getClassNameDedupe(scopeItem.property, priority, scopeItem.selector, parentSelector, scopeItem.atRule);
|
|
1413
|
-
className = getAtomicClassName(scopeItem.property, priority, value, scopeItem.selector, parentSelector, scopeItem.atRule, scopeItem.callsite, DEV_CONFIG.isLocalClassNameEnabled, DEBUG_CONFIG.isDebugClassNameEnabled, CSS_CONFIG.classNameFormat ?? null);
|
|
1655
|
+
weight = scopeItem.weight;
|
|
1656
|
+
important = scopeItem.important;
|
|
1657
|
+
dedupe = getClassNameDedupe(scopeItem.property, weight, important, scopeItem.selector, parentSelector, scopeItem.atRule);
|
|
1658
|
+
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);
|
|
1414
1659
|
scopeItem.dedupe = dedupe;
|
|
1415
1660
|
scopeItem.className = className;
|
|
1416
1661
|
const lookupKey = getScopeLookupKey(slotId, dedupe);
|
|
@@ -1421,7 +1666,7 @@ function mergeScopeData(scope, callsite, items, debug, parentSelector, scopeAtRu
|
|
|
1421
1666
|
}
|
|
1422
1667
|
return data;
|
|
1423
1668
|
}
|
|
1424
|
-
function addTokenOverride(item, styles, lookup) {
|
|
1669
|
+
function addTokenOverride$1(item, styles, lookup) {
|
|
1425
1670
|
const lookupKey = getTokenLookupKey(getStyleTokenId(item));
|
|
1426
1671
|
const lookupIndex = lookup[lookupKey];
|
|
1427
1672
|
if (typeof lookupIndex === "number") styles[lookupIndex] = item;
|
|
@@ -1475,10 +1720,23 @@ function getScopeLookupKey(slotId, dedupe) {
|
|
|
1475
1720
|
function getTokenLookupKey(tokenId) {
|
|
1476
1721
|
return "token\0" + tokenId;
|
|
1477
1722
|
}
|
|
1723
|
+
//#endregion
|
|
1724
|
+
//#region atomic/utils/cssVar.ts
|
|
1725
|
+
function getCssVar(varName, value) {
|
|
1726
|
+
return "var(" + varName + ", " + escapeCssValue(value) + ")";
|
|
1727
|
+
}
|
|
1728
|
+
function getCssVarRawFallback(varName, fallbackCss) {
|
|
1729
|
+
return "var(" + varName + ", " + fallbackCss + ")";
|
|
1730
|
+
}
|
|
1731
|
+
function escapeCssValue(value) {
|
|
1732
|
+
if (!value) return "";
|
|
1733
|
+
return value.trim().replace(/\\/g, "\\\\").replace(/"/g, "\\\"").replace(/'/g, "\\'").replace(/;/g, "\\;");
|
|
1734
|
+
}
|
|
1478
1735
|
const formatTokenName = createNameFormatter(["name"]);
|
|
1479
1736
|
function getTokenVarName(token, format) {
|
|
1480
1737
|
const id = getStyleTokenId(token);
|
|
1481
|
-
|
|
1738
|
+
const debugName = getStyleTokenName(token);
|
|
1739
|
+
return "--" + formatTokenName(format || "token[-(name)]-$hash", getIdentifierSafeHash(id, CSS_CONFIG.hashLength), { name: debugName });
|
|
1482
1740
|
}
|
|
1483
1741
|
function getTokenVar(token, format) {
|
|
1484
1742
|
return getTokenVarFallback(token, format);
|
|
@@ -1553,6 +1811,31 @@ function shouldAppendCssPx(property) {
|
|
|
1553
1811
|
return !UNITLESS.has(property);
|
|
1554
1812
|
}
|
|
1555
1813
|
//#endregion
|
|
1814
|
+
//#region style/important.ts
|
|
1815
|
+
const STYLE_IMPORTANT = symbol("style.important");
|
|
1816
|
+
function importantValue(value) {
|
|
1817
|
+
return {
|
|
1818
|
+
[STYLE_IMPORTANT]: true,
|
|
1819
|
+
value
|
|
1820
|
+
};
|
|
1821
|
+
}
|
|
1822
|
+
function isStyleImportantValue(value) {
|
|
1823
|
+
return !!value && typeof value === "object" && value[STYLE_IMPORTANT] === true;
|
|
1824
|
+
}
|
|
1825
|
+
//#endregion
|
|
1826
|
+
//#region style/transform.ts
|
|
1827
|
+
const CLASS_NAME_VALUE = symbol("transform.classNameValue");
|
|
1828
|
+
function classNameValue(value, className) {
|
|
1829
|
+
return {
|
|
1830
|
+
[CLASS_NAME_VALUE]: true,
|
|
1831
|
+
value,
|
|
1832
|
+
className
|
|
1833
|
+
};
|
|
1834
|
+
}
|
|
1835
|
+
function isClassNameValue(value) {
|
|
1836
|
+
return !!value && typeof value === "object" && value[CLASS_NAME_VALUE] === true && typeof value.className === "string";
|
|
1837
|
+
}
|
|
1838
|
+
//#endregion
|
|
1556
1839
|
//#region style/valueRef.ts
|
|
1557
1840
|
const AT_RULE_REF = symbol("atRule.ref");
|
|
1558
1841
|
function createAtRuleRef(data) {
|
|
@@ -1565,6 +1848,19 @@ function isAtRuleRef(value) {
|
|
|
1565
1848
|
return !!value && typeof value === "object" && value[AT_RULE_REF] === true;
|
|
1566
1849
|
}
|
|
1567
1850
|
//#endregion
|
|
1851
|
+
//#region style/weight.ts
|
|
1852
|
+
const STYLE_WEIGHT = symbol("style.weight");
|
|
1853
|
+
function weightValue(value, weight) {
|
|
1854
|
+
return {
|
|
1855
|
+
[STYLE_WEIGHT]: true,
|
|
1856
|
+
value,
|
|
1857
|
+
weight
|
|
1858
|
+
};
|
|
1859
|
+
}
|
|
1860
|
+
function isStyleWeightValue(value) {
|
|
1861
|
+
return !!value && typeof value === "object" && value[STYLE_WEIGHT] === true;
|
|
1862
|
+
}
|
|
1863
|
+
//#endregion
|
|
1568
1864
|
//#region builder/data/merge/style.ts
|
|
1569
1865
|
function mergeBuilderData(create, callsite, source, style, debug, selector, atRule, type) {
|
|
1570
1866
|
if (!style) return source;
|
|
@@ -1575,13 +1871,15 @@ function mergeBuilderData(create, callsite, source, style, debug, selector, atRu
|
|
|
1575
1871
|
let itemData;
|
|
1576
1872
|
let valueRaw;
|
|
1577
1873
|
let value;
|
|
1578
|
-
let
|
|
1874
|
+
let weight;
|
|
1875
|
+
let important;
|
|
1579
1876
|
let itemCallsite;
|
|
1580
1877
|
let className;
|
|
1581
1878
|
let dedupe;
|
|
1582
1879
|
let token;
|
|
1583
1880
|
let ref;
|
|
1584
1881
|
let variableName;
|
|
1882
|
+
let transformClassName;
|
|
1585
1883
|
let lookupIndex;
|
|
1586
1884
|
if (isStyleData(style)) {
|
|
1587
1885
|
const stylesItems = style[BUILDER_STATE].items;
|
|
@@ -1595,6 +1893,7 @@ function mergeBuilderData(create, callsite, source, style, debug, selector, atRu
|
|
|
1595
1893
|
continue;
|
|
1596
1894
|
}
|
|
1597
1895
|
if (atRule) item = Object.assign({}, item, { atRule: item.atRule ? atRule.concat(item.atRule) : atRule });
|
|
1896
|
+
if (selector) item = Object.assign({}, item, { selector: item.selector ? combineSelectors$1(selector, item.selector) : selector });
|
|
1598
1897
|
if (type === 2 && slotId !== null) item = Object.assign({}, item, {
|
|
1599
1898
|
type: 2,
|
|
1600
1899
|
slotId
|
|
@@ -1603,6 +1902,7 @@ function mergeBuilderData(create, callsite, source, style, debug, selector, atRu
|
|
|
1603
1902
|
type: 3,
|
|
1604
1903
|
slotId
|
|
1605
1904
|
});
|
|
1905
|
+
else if (type === 8) item = Object.assign({}, item, { type: 1 });
|
|
1606
1906
|
const itemDebug = getMergedStyleDebug(debug, item);
|
|
1607
1907
|
const debugCallsite = getDebugFieldCallsite(itemDebug, item.property);
|
|
1608
1908
|
if (debugCallsite) item = Object.assign({}, item, {
|
|
@@ -1614,17 +1914,19 @@ function mergeBuilderData(create, callsite, source, style, debug, selector, atRu
|
|
|
1614
1914
|
}
|
|
1615
1915
|
} else for (const property in style) {
|
|
1616
1916
|
valueRaw = style[property];
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1917
|
+
[valueRaw, weight, important] = unwrapAuthoredStyleValue(valueRaw);
|
|
1918
|
+
const sourceType = source[BUILDER_TYPE];
|
|
1919
|
+
checkImportantUsage(valueRaw, important, sourceType === 9 || sourceType === 8);
|
|
1920
|
+
transformClassName = null;
|
|
1921
|
+
if (isClassNameValue(valueRaw)) {
|
|
1922
|
+
transformClassName = valueRaw.className;
|
|
1923
|
+
valueRaw = valueRaw.value;
|
|
1621
1924
|
}
|
|
1622
1925
|
ref = isAtRuleRef(valueRaw) ? valueRaw : null;
|
|
1623
1926
|
if (ref) valueRaw = ref.value;
|
|
1624
1927
|
token = isStyleTokenData(valueRaw) ? valueRaw : null;
|
|
1625
1928
|
variableName = getDebugFieldVarName(debug, property);
|
|
1626
1929
|
value = variableName && token ? getCssVarRawFallback(variableName, getTokenVar(token, CSS_CONFIG.tokenNameFormat ?? null)) : token ? getTokenVar(token, CSS_CONFIG.tokenNameFormat ?? null) : String(valueRaw ?? "");
|
|
1627
|
-
value = priority !== null ? [value, priority] : value;
|
|
1628
1930
|
itemCallsite = getDebugFieldCallsite(debug, property) ?? callsite;
|
|
1629
1931
|
itemData = {
|
|
1630
1932
|
runtime: runtimeType,
|
|
@@ -1633,7 +1935,10 @@ function mergeBuilderData(create, callsite, source, style, debug, selector, atRu
|
|
|
1633
1935
|
dedupe: "",
|
|
1634
1936
|
className: "",
|
|
1635
1937
|
property,
|
|
1938
|
+
weight,
|
|
1939
|
+
important,
|
|
1636
1940
|
value,
|
|
1941
|
+
transformClassName,
|
|
1637
1942
|
variable: ref ? [3, ref] : variableName && token ? [
|
|
1638
1943
|
1,
|
|
1639
1944
|
variableName,
|
|
@@ -1645,7 +1950,7 @@ function mergeBuilderData(create, callsite, source, style, debug, selector, atRu
|
|
|
1645
1950
|
atRule,
|
|
1646
1951
|
callsite: itemCallsite
|
|
1647
1952
|
};
|
|
1648
|
-
if (type === 1) {
|
|
1953
|
+
if (type === 1 || type === 8) {
|
|
1649
1954
|
items.push({
|
|
1650
1955
|
...itemData,
|
|
1651
1956
|
type: 1
|
|
@@ -1692,13 +1997,10 @@ function mergeBuilderData(create, callsite, source, style, debug, selector, atRu
|
|
|
1692
1997
|
}
|
|
1693
1998
|
const runtimeItem = item;
|
|
1694
1999
|
value = runtimeItem.value;
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
}
|
|
1700
|
-
dedupe = getClassNameDedupe(runtimeItem.property, priority, runtimeItem.selector, null, runtimeItem.atRule);
|
|
1701
|
-
className = getAtomicClassName(runtimeItem.property, priority, value, runtimeItem.selector, null, runtimeItem.atRule, runtimeItem.callsite, DEV_CONFIG.isLocalClassNameEnabled, DEBUG_CONFIG.isDebugClassNameEnabled, CSS_CONFIG.classNameFormat ?? null);
|
|
2000
|
+
weight = runtimeItem.weight;
|
|
2001
|
+
important = runtimeItem.important;
|
|
2002
|
+
dedupe = getClassNameDedupe(runtimeItem.property, weight, important, runtimeItem.selector, null, runtimeItem.atRule);
|
|
2003
|
+
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);
|
|
1702
2004
|
runtimeItem.dedupe = dedupe;
|
|
1703
2005
|
runtimeItem.className = className;
|
|
1704
2006
|
lookupIndex = lookup[dedupe];
|
|
@@ -1707,6 +2009,52 @@ function mergeBuilderData(create, callsite, source, style, debug, selector, atRu
|
|
|
1707
2009
|
}
|
|
1708
2010
|
return data;
|
|
1709
2011
|
}
|
|
2012
|
+
function unwrapAuthoredStyleValue(value) {
|
|
2013
|
+
let weight = null;
|
|
2014
|
+
let important = false;
|
|
2015
|
+
while (true) {
|
|
2016
|
+
if (isStyleImportantValue(value)) {
|
|
2017
|
+
important = true;
|
|
2018
|
+
value = value.value;
|
|
2019
|
+
continue;
|
|
2020
|
+
}
|
|
2021
|
+
if (isStyleWeightValue(value)) {
|
|
2022
|
+
weight = value.weight;
|
|
2023
|
+
value = value.value;
|
|
2024
|
+
continue;
|
|
2025
|
+
}
|
|
2026
|
+
break;
|
|
2027
|
+
}
|
|
2028
|
+
return [
|
|
2029
|
+
value,
|
|
2030
|
+
weight,
|
|
2031
|
+
important
|
|
2032
|
+
];
|
|
2033
|
+
}
|
|
2034
|
+
function checkImportantUsage(value, important, isSheet) {
|
|
2035
|
+
const options = CHECK_CONFIG.important;
|
|
2036
|
+
if (!options) return;
|
|
2037
|
+
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.");
|
|
2038
|
+
if (important && !isSheet) reportImportantCheck(options.outsideSheet, "style.important(...) outside createSheet is discouraged. Prefer style.weight(...) for Fluentic style priority.");
|
|
2039
|
+
}
|
|
2040
|
+
function reportImportantCheck(level, message) {
|
|
2041
|
+
if (!level) return;
|
|
2042
|
+
if (level === "error") throw new Error(message);
|
|
2043
|
+
if (DEV_CONFIG.isDev) console.warn("[fluentic-style] " + message);
|
|
2044
|
+
}
|
|
2045
|
+
function combineSelectors$1(parent, child) {
|
|
2046
|
+
const parentText = getSelectorText(parent);
|
|
2047
|
+
const childText = getSelectorText(child);
|
|
2048
|
+
const priority = Math.max(getSelectorPriority(parent), getSelectorPriority(child));
|
|
2049
|
+
const selector = parentText + childText;
|
|
2050
|
+
return priority > 0 ? [selector, priority] : selector;
|
|
2051
|
+
}
|
|
2052
|
+
function getSelectorText(selector) {
|
|
2053
|
+
return Array.isArray(selector) ? selector[0] : selector;
|
|
2054
|
+
}
|
|
2055
|
+
function getSelectorPriority(selector) {
|
|
2056
|
+
return Array.isArray(selector) ? selector[1] : 0;
|
|
2057
|
+
}
|
|
1710
2058
|
function getMergedStyleDebug(debug, item) {
|
|
1711
2059
|
if (!debug) return null;
|
|
1712
2060
|
if (debug.fields?.[item.property]) return debug;
|
|
@@ -1750,29 +2098,189 @@ function withDebugSource$1(loc, debug) {
|
|
|
1750
2098
|
];
|
|
1751
2099
|
}
|
|
1752
2100
|
//#endregion
|
|
1753
|
-
//#region builder/
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
const
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
2101
|
+
//#region builder/selector_override_core.ts
|
|
2102
|
+
function normalizeManualSelectors$1(input, assertManualSelector) {
|
|
2103
|
+
const selectors = Array.isArray(input) ? input : [input];
|
|
2104
|
+
if (!selectors.length) throw new Error("selector array cannot be empty");
|
|
2105
|
+
return selectors.flatMap((selector) => normalizeManualSelector(selector, assertManualSelector));
|
|
2106
|
+
}
|
|
2107
|
+
function assertManualSelectorSyntax(selector) {
|
|
2108
|
+
if (!selector) throw new Error("selector cannot be empty");
|
|
2109
|
+
if (selector.includes("{") || selector.includes("}")) throw new Error("selector must not contain \"{\" or \"}\"");
|
|
2110
|
+
if (selector.includes(",")) throw new Error("selector must not contain \",\"; use an array of selectors instead");
|
|
2111
|
+
const ampersandIndex = selector.indexOf("&");
|
|
2112
|
+
if (ampersandIndex > 0) throw new Error("selector can only use \"&\" at the beginning");
|
|
2113
|
+
const ampersandSelector = selector.startsWith("&?") ? selector.slice(2) : selector.slice(1);
|
|
2114
|
+
if (ampersandIndex === 0 && ampersandSelector && /^\s/.test(ampersandSelector)) throw new Error("selector cannot have whitespace after \"&\"; omit \"&\" for descendant selectors");
|
|
2115
|
+
}
|
|
2116
|
+
function setSheetSelectorOptions(selector, options) {
|
|
2117
|
+
if (options.weight === void 0 && options.layer === void 0) return selector;
|
|
2118
|
+
const text = Array.isArray(selector) ? selector[0] : selector;
|
|
2119
|
+
const weighted = SHEET_SELECTOR_ANCHOR + (":" + (options.weight ?? "") + ":" + (options.layer === void 0 ? "" : options.layer ? "1" : "0")) + "\0" + text.slice(6);
|
|
2120
|
+
return Array.isArray(selector) ? [weighted, selector[1]] : weighted;
|
|
2121
|
+
}
|
|
2122
|
+
function normalizeManualSelector(selector, assertManualSelector) {
|
|
2123
|
+
const value = selector.trim();
|
|
2124
|
+
assertManualSelector(value);
|
|
2125
|
+
if (value.startsWith("&?")) {
|
|
2126
|
+
const suffix = value.slice(2);
|
|
2127
|
+
return suffix ? [SHEET_SELECTOR_ANCHOR + suffix, "\0sheet " + suffix] : [SHEET_SELECTOR_ANCHOR];
|
|
2128
|
+
}
|
|
2129
|
+
return [SHEET_SELECTOR_ANCHOR + (value.startsWith("&") ? value.slice(1) : " " + value)];
|
|
2130
|
+
}
|
|
2131
|
+
//#endregion
|
|
2132
|
+
//#region builder/selector_override.ts
|
|
2133
|
+
function normalizeManualSelectors(input) {
|
|
2134
|
+
return normalizeManualSelectors$1(input, assertManualSelector);
|
|
2135
|
+
}
|
|
2136
|
+
function assertManualSelector(selector) {
|
|
2137
|
+
assertManualSelectorSyntax(selector);
|
|
2138
|
+
const ampersandIndex = selector.indexOf("&");
|
|
2139
|
+
const ampersandSelector = selector.startsWith("&?") ? selector.slice(2) : selector.slice(1);
|
|
2140
|
+
const parsedSelector = ampersandIndex === 0 ? "*" + ampersandSelector : selector;
|
|
2141
|
+
try {
|
|
2142
|
+
(0, css_what.parse)(parsedSelector);
|
|
2143
|
+
} catch {
|
|
2144
|
+
throw new Error("selector is invalid: " + selector);
|
|
2145
|
+
}
|
|
2146
|
+
}
|
|
2147
|
+
//#endregion
|
|
2148
|
+
//#region builder/style_data.ts
|
|
2149
|
+
const mergeStyleCreate = (callsite) => {
|
|
2150
|
+
return createStyleData(callsite);
|
|
2151
|
+
};
|
|
2152
|
+
const mergeStyleData = createMerge(mergeStyleCreate, 1);
|
|
2153
|
+
const mergeSlotCreate = (callsite, data) => {
|
|
2154
|
+
return createSlotData(callsite, data[BUILDER_SLOT_ID]);
|
|
2155
|
+
};
|
|
2156
|
+
const mergeSlotData = createMerge(mergeSlotCreate, 2);
|
|
2157
|
+
const mergeSlotOverrideCreate = (callsite, data) => {
|
|
2158
|
+
return createSlotOverrideData(callsite, data[BUILDER_SLOT_ID]);
|
|
2159
|
+
};
|
|
2160
|
+
const mergeSlotOverrideData = createMerge(mergeSlotOverrideCreate, 3);
|
|
2161
|
+
const mergeSelectorOverrideCreate = (callsite, data) => {
|
|
2162
|
+
return createSelectorOverrideData(callsite, data[BUILDER_SELECTOR]);
|
|
2163
|
+
};
|
|
2164
|
+
const mergeSelectorOverrideData = createMerge(mergeSelectorOverrideCreate, 8);
|
|
2165
|
+
function createMerge(create, type) {
|
|
2166
|
+
return (data, callsite, style, debug, selector, atRule) => {
|
|
2167
|
+
return mergeBuilderData(create, callsite, data, style, debug, selector, atRule, type);
|
|
2168
|
+
};
|
|
2169
|
+
}
|
|
2170
|
+
//#endregion
|
|
2171
|
+
//#region selector/validate.ts
|
|
2172
|
+
function isLocalSelector(selector) {
|
|
2173
|
+
const groups = parseSelector(selector);
|
|
2174
|
+
if (!groups || groups.length !== 1) return false;
|
|
2175
|
+
return isSelectorGroupsSelf(groups, false);
|
|
2176
|
+
}
|
|
2177
|
+
function isPseudoArgSelector(selector) {
|
|
2178
|
+
const groups = parseSelector(selector);
|
|
2179
|
+
if (!groups || groups.length !== 1) return false;
|
|
2180
|
+
return isSelectorGroupsSelf(groups, true);
|
|
2181
|
+
}
|
|
2182
|
+
function isTagSelector(selector) {
|
|
2183
|
+
const groups = parseSelector(selector);
|
|
2184
|
+
if (!groups || groups.length !== 1) return false;
|
|
2185
|
+
const group = groups[0];
|
|
2186
|
+
return group.length === 1 && group[0].type === css_what.SelectorType.Tag;
|
|
2187
|
+
}
|
|
2188
|
+
function isAttrArg(value) {
|
|
2189
|
+
if (!value) return false;
|
|
2190
|
+
if (value.includes("[") || value.includes("]")) return false;
|
|
2191
|
+
return true;
|
|
2192
|
+
}
|
|
2193
|
+
function isRawValue(value) {
|
|
2194
|
+
if (!value) return false;
|
|
2195
|
+
if (value.includes("{") || value.includes("}")) return false;
|
|
2196
|
+
return true;
|
|
2197
|
+
}
|
|
2198
|
+
function parseSelector(selector) {
|
|
2199
|
+
try {
|
|
2200
|
+
return (0, css_what.parse)(selector);
|
|
2201
|
+
} catch {
|
|
2202
|
+
return;
|
|
2203
|
+
}
|
|
2204
|
+
}
|
|
2205
|
+
function isSelectorGroupsSelf(groups, allowTag) {
|
|
2206
|
+
for (let i = 0; i < groups.length; i++) {
|
|
2207
|
+
const group = groups[i];
|
|
2208
|
+
for (let j = 0; j < group.length; j++) {
|
|
2209
|
+
const token = group[j];
|
|
2210
|
+
if (!isAllowedSelectorType(token.type, allowTag)) return false;
|
|
2211
|
+
if (token.type === css_what.SelectorType.Pseudo && Array.isArray(token.data) && !isSelectorGroupsSelf(token.data, allowTag)) return false;
|
|
2212
|
+
}
|
|
2213
|
+
}
|
|
2214
|
+
return true;
|
|
2215
|
+
}
|
|
2216
|
+
function isAllowedSelectorType(type, allowTag) {
|
|
2217
|
+
return type === css_what.SelectorType.Attribute || type === css_what.SelectorType.Pseudo || type === css_what.SelectorType.PseudoElement || allowTag && type === css_what.SelectorType.Tag;
|
|
2218
|
+
}
|
|
2219
|
+
//#endregion
|
|
2220
|
+
//#region selector/assert.ts
|
|
2221
|
+
function assertSelector(type, value) {
|
|
2222
|
+
assertSelectorNotEmpty(value);
|
|
2223
|
+
if (!type) return;
|
|
2224
|
+
if (typeof type === "function") return type(value);
|
|
2225
|
+
switch (type) {
|
|
2226
|
+
case "local": return assertLocalSelector(value);
|
|
2227
|
+
case "arg": return assertPseudoArgSelector(value);
|
|
2228
|
+
case "tag": return assertTagSelector(value);
|
|
2229
|
+
case "attr": return assertAttrSelector(value);
|
|
2230
|
+
case "value": return assertRawValue(value);
|
|
2231
|
+
case "media": return assertMediaQuery(value);
|
|
2232
|
+
case "supports": return assertSupportsQuery(value);
|
|
2233
|
+
case "container": return assertContainerQuery(value);
|
|
2234
|
+
default: throw new Error("unsupported selector type: " + value);
|
|
2235
|
+
}
|
|
2236
|
+
}
|
|
2237
|
+
const assertSelectorNotEmpty = createSelectorAssert((value) => {
|
|
2238
|
+
if (!value) throw new Error("selector cannot be empty");
|
|
2239
|
+
});
|
|
2240
|
+
const assertLocalSelector = createSelectorAssert((value) => {
|
|
2241
|
+
if (!isLocalSelector(value)) throw new Error("selector must target the current element only and cannot contain tags, combinators, or multiple selectors");
|
|
2242
|
+
});
|
|
2243
|
+
const assertPseudoArgSelector = createSelectorAssert((value) => {
|
|
2244
|
+
if (!isPseudoArgSelector(value)) throw new Error("pseudo selector argument must contain only tags or selectors targeting the current element");
|
|
2245
|
+
});
|
|
2246
|
+
const assertTagSelector = createSelectorAssert((value) => {
|
|
2247
|
+
if (!isTagSelector(value)) throw new Error("selector must be a single tag selector");
|
|
2248
|
+
});
|
|
2249
|
+
const assertAttrSelector = createSelectorAssert((value) => {
|
|
2250
|
+
if (!isAttrArg(value)) throw new Error("attribute selector value must not include \"[\" or \"]\"");
|
|
2251
|
+
});
|
|
2252
|
+
const assertRawValue = createSelectorAssert((value) => {
|
|
2253
|
+
if (!isRawValue(value)) throw new Error("value must not contain \"{\" or \"}\"");
|
|
2254
|
+
});
|
|
2255
|
+
const assertMediaQuery = createSelectorAssert((value) => {
|
|
2256
|
+
if (!isRawValue(value)) throw new Error("media query must not contain \"{\" or \"}\"");
|
|
2257
|
+
});
|
|
2258
|
+
const assertSupportsQuery = createSelectorAssert((value) => {
|
|
2259
|
+
if (!isRawValue(value)) throw new Error("supports query must not contain \"{\" or \"}\"");
|
|
2260
|
+
});
|
|
2261
|
+
const assertContainerQuery = createSelectorAssert((value) => {
|
|
2262
|
+
if (!isRawValue(value)) throw new Error("container query must not contain \"{\" or \"}\"");
|
|
2263
|
+
});
|
|
2264
|
+
//#endregion
|
|
2265
|
+
//#region builder/data/check_selector.ts
|
|
2266
|
+
function checkSelector(fnPrefix, fnName, fnSelector, arg) {
|
|
2267
|
+
let message = null;
|
|
2268
|
+
try {
|
|
2269
|
+
assertSelector(fnSelector.assert, arg);
|
|
2270
|
+
} catch (error) {
|
|
2271
|
+
if (typeof error === "string" && error.trim()) message = error;
|
|
2272
|
+
else if (typeof error === "object" && error && error instanceof Error) message = (error.message || "").trim();
|
|
2273
|
+
else message = "selector is invalid: " + arg;
|
|
2274
|
+
}
|
|
2275
|
+
if (!message) return;
|
|
2276
|
+
throw traceError(`${fnPrefix}${fnName}(${arg || ""}): ${message}`);
|
|
1770
2277
|
}
|
|
1771
2278
|
//#endregion
|
|
1772
2279
|
//#region builder/utils.ts
|
|
1773
2280
|
const FnPrefixStyle = "style.";
|
|
1774
2281
|
const FnPrefixSlot = "slot.";
|
|
1775
2282
|
const FnPrefixScope = "scope.";
|
|
2283
|
+
const FnPrefixSelector = "selector.";
|
|
1776
2284
|
function runtimeCallsite() {
|
|
1777
2285
|
return traceCallsite();
|
|
1778
2286
|
}
|
|
@@ -1833,9 +2341,9 @@ function createAtRuleFn(mergeData, fns, createFnResult, fnPrefix, fnName, fnSele
|
|
|
1833
2341
|
let arg;
|
|
1834
2342
|
let style;
|
|
1835
2343
|
let debug;
|
|
1836
|
-
let
|
|
2344
|
+
let weight = null;
|
|
1837
2345
|
if (hasArg) if (isMedia && typeof params[0] === "number") {
|
|
1838
|
-
|
|
2346
|
+
weight = params[0];
|
|
1839
2347
|
arg = params[1];
|
|
1840
2348
|
style = params[2];
|
|
1841
2349
|
debug = params[3];
|
|
@@ -1845,7 +2353,7 @@ function createAtRuleFn(mergeData, fns, createFnResult, fnPrefix, fnName, fnSele
|
|
|
1845
2353
|
debug = params[2];
|
|
1846
2354
|
}
|
|
1847
2355
|
else if (isMedia && typeof params[0] === "number") {
|
|
1848
|
-
|
|
2356
|
+
weight = params[0];
|
|
1849
2357
|
arg = fnSelector.selector;
|
|
1850
2358
|
style = params[1];
|
|
1851
2359
|
debug = params[2];
|
|
@@ -1865,7 +2373,7 @@ function createAtRuleFn(mergeData, fns, createFnResult, fnPrefix, fnName, fnSele
|
|
|
1865
2373
|
selector = hasArg ? before + normalizeSelectorArg(selector) + after : selector;
|
|
1866
2374
|
for (let j = 0, len = items.length; j < len; j++) {
|
|
1867
2375
|
const item = items[j];
|
|
1868
|
-
data = mergeData(data, callsite, isStyleData(item) ? item : transformStyle(item, transform), debug ?? null, null, [
|
|
2376
|
+
data = mergeData(data, callsite, isStyleData(item) ? item : transformStyle(item, transform), debug ?? null, null, [weight !== null ? [selector, weight] : selector]);
|
|
1869
2377
|
}
|
|
1870
2378
|
}
|
|
1871
2379
|
return createFnResult(data, fns);
|
|
@@ -1932,9 +2440,9 @@ function createScopeAtRuleFn(fnPrefix, fnName, fnSelector, cloneScope) {
|
|
|
1932
2440
|
let arg;
|
|
1933
2441
|
let data;
|
|
1934
2442
|
let debug;
|
|
1935
|
-
let
|
|
2443
|
+
let weight = null;
|
|
1936
2444
|
if (hasArg) if (isMedia && typeof params[0] === "number") {
|
|
1937
|
-
|
|
2445
|
+
weight = params[0];
|
|
1938
2446
|
arg = params[1];
|
|
1939
2447
|
data = params[2];
|
|
1940
2448
|
debug = params[3];
|
|
@@ -1944,7 +2452,7 @@ function createScopeAtRuleFn(fnPrefix, fnName, fnSelector, cloneScope) {
|
|
|
1944
2452
|
debug = params[2];
|
|
1945
2453
|
}
|
|
1946
2454
|
else if (isMedia && typeof params[0] === "number") {
|
|
1947
|
-
|
|
2455
|
+
weight = params[0];
|
|
1948
2456
|
arg = fnSelector.selector;
|
|
1949
2457
|
data = params[1];
|
|
1950
2458
|
debug = params[2];
|
|
@@ -1961,7 +2469,7 @@ function createScopeAtRuleFn(fnPrefix, fnName, fnSelector, cloneScope) {
|
|
|
1961
2469
|
selector = args[i];
|
|
1962
2470
|
if (hasArg && DEV_CONFIG.isCheckSelectorEnabled) checkSelector(fnPrefix, fnName, fnSelector, selector);
|
|
1963
2471
|
selector = hasArg ? before + normalizeSelectorArg(selector) + after : selector;
|
|
1964
|
-
result = mergeScopeItems(result, callsite, data, debug ?? null, null,
|
|
2472
|
+
result = mergeScopeItems(result, callsite, data, debug ?? null, null, weight !== null ? [selector, weight] : selector, cloneScope);
|
|
1965
2473
|
}
|
|
1966
2474
|
return result;
|
|
1967
2475
|
};
|
|
@@ -2038,6 +2546,20 @@ function createSlotBuilder(selectors, transform) {
|
|
|
2038
2546
|
traceMarker(fn, "slot");
|
|
2039
2547
|
return fn;
|
|
2040
2548
|
}
|
|
2549
|
+
function createSelectorBuilder(selectors, transform) {
|
|
2550
|
+
const fns = createStyleFns(mergeSelectorOverrideData, selectors, FnPrefixSelector, transform, null);
|
|
2551
|
+
const fn = (selector, style, debug) => {
|
|
2552
|
+
if (isDebugData(style) && debug === void 0) {
|
|
2553
|
+
debug = style;
|
|
2554
|
+
style = void 0;
|
|
2555
|
+
}
|
|
2556
|
+
const target = createCallableSelector(createSelectorData(resolveCallsite(debug), normalizeManualSelectors(selector)), fns, transform);
|
|
2557
|
+
if (style === void 0) return target;
|
|
2558
|
+
return target(style, debug);
|
|
2559
|
+
};
|
|
2560
|
+
traceMarker(fn, "style.selector");
|
|
2561
|
+
return fn;
|
|
2562
|
+
}
|
|
2041
2563
|
function createScopeBuilder(selectors) {
|
|
2042
2564
|
const fns = createScopeFns(selectors, FnPrefixScope, cloneScope);
|
|
2043
2565
|
const fn = (items, debug) => {
|
|
@@ -2053,6 +2575,34 @@ function createScopeBuilder(selectors) {
|
|
|
2053
2575
|
traceMarker(fn, "scope");
|
|
2054
2576
|
return fn;
|
|
2055
2577
|
}
|
|
2578
|
+
function createCallableSelectorOverride(data, fns, transform) {
|
|
2579
|
+
const callable = ((style, debug) => {
|
|
2580
|
+
if (isDebugData(style) && debug === void 0) {
|
|
2581
|
+
debug = style;
|
|
2582
|
+
style = void 0;
|
|
2583
|
+
}
|
|
2584
|
+
const callsite = resolveCallsite(debug);
|
|
2585
|
+
return createCallableSelectorOverride(mergeSelectorOverrideData(createSelectorOverrideData(callsite, data[BUILDER_SELECTOR]), callsite, style ? isStyleData(style) ? style : transformStyle(style, transform) : null, debug ?? null, null, null), fns, transform);
|
|
2586
|
+
});
|
|
2587
|
+
traceMarker(callable, "selector.override");
|
|
2588
|
+
Object.setPrototypeOf(callable, fns);
|
|
2589
|
+
Object.assign(callable, data);
|
|
2590
|
+
return callable;
|
|
2591
|
+
}
|
|
2592
|
+
function createCallableSelector(data, overrideFns, transform) {
|
|
2593
|
+
const callable = ((style, debug) => {
|
|
2594
|
+
if (isDebugData(style) && debug === void 0) {
|
|
2595
|
+
debug = style;
|
|
2596
|
+
style = void 0;
|
|
2597
|
+
}
|
|
2598
|
+
const callsite = resolveCallsite(debug);
|
|
2599
|
+
return createCallableSelectorOverride(mergeSelectorOverrideData(createSelectorOverrideData(callsite, data[BUILDER_SELECTOR]), callsite, style ? isStyleData(style) ? style : transformStyle(style, transform) : null, debug ?? null, null, null), overrideFns, transform);
|
|
2600
|
+
});
|
|
2601
|
+
traceMarker(callable, "selector");
|
|
2602
|
+
Object.setPrototypeOf(callable, overrideFns);
|
|
2603
|
+
Object.assign(callable, data);
|
|
2604
|
+
return callable;
|
|
2605
|
+
}
|
|
2056
2606
|
function createCallableSlot(data, fns, overrideFns, transform) {
|
|
2057
2607
|
const slotId = data[BUILDER_SLOT_ID];
|
|
2058
2608
|
const callable = ((style, debug) => {
|
|
@@ -2495,7 +3045,7 @@ function getCssPropertyName(property) {
|
|
|
2495
3045
|
function createAtRuleNameFormatter(defaultFormat, prefix) {
|
|
2496
3046
|
const formatter = createNameFormatter(["name"]);
|
|
2497
3047
|
return (format, id, info) => {
|
|
2498
|
-
const hash = getIdentifierSafeHash(id);
|
|
3048
|
+
const hash = getIdentifierSafeHash(id, CSS_CONFIG.hashLength);
|
|
2499
3049
|
const name = formatter(format || defaultFormat, hash, info);
|
|
2500
3050
|
if (!prefix) return name;
|
|
2501
3051
|
return name.startsWith(prefix) ? name : prefix + name;
|
|
@@ -2659,7 +3209,499 @@ function buildPropertyCss(format, name, id, descriptors, tokens, tokenLookup, to
|
|
|
2659
3209
|
name
|
|
2660
3210
|
};
|
|
2661
3211
|
}
|
|
2662
|
-
createIdCounter("property");
|
|
3212
|
+
createIdCounter("property");
|
|
3213
|
+
//#endregion
|
|
3214
|
+
//#region sheet/utils/sourcemap.ts
|
|
3215
|
+
const VLQ_BASE_SHIFT = 5;
|
|
3216
|
+
const VLQ_BASE = 1 << VLQ_BASE_SHIFT;
|
|
3217
|
+
const VLQ_BASE_MASK = VLQ_BASE - 1;
|
|
3218
|
+
const VLQ_CONTINUATION_BIT = VLQ_BASE;
|
|
3219
|
+
const BASE64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
3220
|
+
const SOURCE_URL_PREFIX = "source://";
|
|
3221
|
+
function encodeBase64(text) {
|
|
3222
|
+
const bytes = new TextEncoder().encode(text);
|
|
3223
|
+
let binary = "";
|
|
3224
|
+
for (let i = 0, len = bytes.length; i < len; i++) binary += String.fromCharCode(bytes[i]);
|
|
3225
|
+
return btoa(binary);
|
|
3226
|
+
}
|
|
3227
|
+
function getSource(sources, sourceLookup, filePath, sourceContent) {
|
|
3228
|
+
let source = sourceLookup[filePath];
|
|
3229
|
+
if (source) {
|
|
3230
|
+
if (source.sourceContent === void 0) source.sourceContent = sourceContent;
|
|
3231
|
+
return source;
|
|
3232
|
+
}
|
|
3233
|
+
source = {
|
|
3234
|
+
filePath,
|
|
3235
|
+
sourceIndex: sources.length,
|
|
3236
|
+
sourceContent
|
|
3237
|
+
};
|
|
3238
|
+
sources.push(source);
|
|
3239
|
+
sourceLookup[filePath] = source;
|
|
3240
|
+
return source;
|
|
3241
|
+
}
|
|
3242
|
+
function normalizeSourcePath(filePath) {
|
|
3243
|
+
filePath = normalizeCallsiteSourceUrl(filePath);
|
|
3244
|
+
const atIndex = filePath.indexOf("/at ");
|
|
3245
|
+
if (atIndex !== -1) return filePath.slice(atIndex + 4);
|
|
3246
|
+
return filePath.replace(/^at\s+/, "");
|
|
3247
|
+
}
|
|
3248
|
+
function getSourceMapSourceUrl(sourceData) {
|
|
3249
|
+
const sourceUrl = sourceData.sourceUrl || sourceData.filePath;
|
|
3250
|
+
if (sourceData.sourceContent !== void 0) return normalizeSourcePath(sourceUrl);
|
|
3251
|
+
return normalizeSourcePath(resolveSidecarSourceUrl(sourceUrl));
|
|
3252
|
+
}
|
|
3253
|
+
function resolveSidecarSourceUrl(sourceUrl) {
|
|
3254
|
+
const sidecarUrl = getSidecarUrl();
|
|
3255
|
+
if (!sidecarUrl) return sourceUrl;
|
|
3256
|
+
return joinSourceUrl(sidecarUrl, getSourceUrlPath(sourceUrl));
|
|
3257
|
+
}
|
|
3258
|
+
function getSidecarUrl() {
|
|
3259
|
+
const value = globalThis[Symbol.for(SIDECAR_URL_GLOBAL_SYMBOL)];
|
|
3260
|
+
return typeof value === "string" && value ? value : null;
|
|
3261
|
+
}
|
|
3262
|
+
function getSourceUrlPath(sourceUrl) {
|
|
3263
|
+
if (sourceUrl.startsWith(SOURCE_URL_PREFIX)) return sourceUrl.slice(9).replace(/^\/+/, "");
|
|
3264
|
+
try {
|
|
3265
|
+
return new URL(sourceUrl).pathname.replace(/^\/+/, "");
|
|
3266
|
+
} catch {
|
|
3267
|
+
return sourceUrl.replace(/^[a-zA-Z][a-zA-Z\d+.-]*:\/+/, "").replace(/^\/+/, "");
|
|
3268
|
+
}
|
|
3269
|
+
}
|
|
3270
|
+
function joinSourceUrl(baseUrl, sourcePath) {
|
|
3271
|
+
const base = baseUrl.replace(/\/+$/, "");
|
|
3272
|
+
const path = sourcePath.replace(/^\/+/, "");
|
|
3273
|
+
return path ? `${base}/${path}` : base;
|
|
3274
|
+
}
|
|
3275
|
+
function getLineCount(css) {
|
|
3276
|
+
let count = 1;
|
|
3277
|
+
for (let i = 0, len = css.length; i < len; i++) if (css.charCodeAt(i) === 10) count++;
|
|
3278
|
+
return count;
|
|
3279
|
+
}
|
|
3280
|
+
function encodeVlq(value) {
|
|
3281
|
+
let vlq = value < 0 ? (-value << 1) + 1 : value << 1;
|
|
3282
|
+
let encoded = "";
|
|
3283
|
+
do {
|
|
3284
|
+
let digit = vlq & VLQ_BASE_MASK;
|
|
3285
|
+
vlq >>>= VLQ_BASE_SHIFT;
|
|
3286
|
+
if (vlq > 0) digit |= VLQ_CONTINUATION_BIT;
|
|
3287
|
+
encoded += BASE64[digit];
|
|
3288
|
+
} while (vlq > 0);
|
|
3289
|
+
return encoded;
|
|
3290
|
+
}
|
|
3291
|
+
//#endregion
|
|
3292
|
+
//#region sheet/sourcemap.ts
|
|
3293
|
+
function getRuleCallsite(callsite, debug, debugField) {
|
|
3294
|
+
if (debug && debugField) {
|
|
3295
|
+
const loc = getDebugFieldLoc(debug, debugField);
|
|
3296
|
+
if (loc) return normalizeRuleCallsite({
|
|
3297
|
+
filePath: loc[3] ?? debug.sourceUrl,
|
|
3298
|
+
sourceUrl: loc[3] ?? debug.sourceUrl,
|
|
3299
|
+
sourceContent: loc[4] ?? debug.code,
|
|
3300
|
+
line: loc[0],
|
|
3301
|
+
column: loc[1]
|
|
3302
|
+
});
|
|
3303
|
+
}
|
|
3304
|
+
if (callsite) return normalizeRuleCallsite(callsite);
|
|
3305
|
+
if (debug) return normalizeRuleCallsite({
|
|
3306
|
+
filePath: debug.sourceUrl,
|
|
3307
|
+
sourceUrl: debug.sourceUrl,
|
|
3308
|
+
sourceContent: debug.code,
|
|
3309
|
+
line: debug.loc[0],
|
|
3310
|
+
column: debug.loc[1]
|
|
3311
|
+
});
|
|
3312
|
+
return callsite || null;
|
|
3313
|
+
}
|
|
3314
|
+
function normalizeRuleCallsite(callsite) {
|
|
3315
|
+
return {
|
|
3316
|
+
...callsite,
|
|
3317
|
+
filePath: normalizeCallsiteSourceUrl(callsite.filePath),
|
|
3318
|
+
sourceUrl: callsite.sourceUrl ? normalizeCallsiteSourceUrl(callsite.sourceUrl) : callsite.sourceUrl
|
|
3319
|
+
};
|
|
3320
|
+
}
|
|
3321
|
+
globalData("sheet.dev.sourcemapTags", () => []);
|
|
3322
|
+
globalData("sheet.dev.sheets", () => /* @__PURE__ */ new Set());
|
|
3323
|
+
globalData("runtime.combinedStyle.targets", () => /* @__PURE__ */ new WeakMap());
|
|
3324
|
+
//#endregion
|
|
3325
|
+
//#region runtime/core/cache/resolvedItem.ts
|
|
3326
|
+
const resolvedStyleItems = globalData("runtime.resolvedStyleItems", () => /* @__PURE__ */ new WeakSet());
|
|
3327
|
+
const resolvedStyleItemTokenValues = globalData("runtime.styleItemTokenValues", () => /* @__PURE__ */ new WeakMap());
|
|
3328
|
+
function markResolvedStyleItem(item) {
|
|
3329
|
+
resolvedStyleItems.add(item);
|
|
3330
|
+
}
|
|
3331
|
+
function isResolvedStyleItem$1(value) {
|
|
3332
|
+
return !!value && typeof value === "object" && resolvedStyleItems.has(value);
|
|
3333
|
+
}
|
|
3334
|
+
function setResolvedStyleItemTokenValues(item, tokens) {
|
|
3335
|
+
resolvedStyleItemTokenValues.set(item, tokens);
|
|
3336
|
+
}
|
|
3337
|
+
//#endregion
|
|
3338
|
+
//#region runtime/core/cache/tokenValues.ts
|
|
3339
|
+
function createMutableTokenValues(base) {
|
|
3340
|
+
return {
|
|
3341
|
+
ids: base ? base.ids.slice() : null,
|
|
3342
|
+
values: base ? base.values.slice() : null,
|
|
3343
|
+
lookup: base ? { ...base.lookup } : null,
|
|
3344
|
+
index: base ? createTokenIndexLookup(base.ids) : null
|
|
3345
|
+
};
|
|
3346
|
+
}
|
|
3347
|
+
function addTokenOverride(values, item, resolver) {
|
|
3348
|
+
if (!resolver.is(item)) return false;
|
|
3349
|
+
addTokenValue(values, resolver.id(item), resolver.value(item));
|
|
3350
|
+
return true;
|
|
3351
|
+
}
|
|
3352
|
+
function addTokenValue(values, id, value) {
|
|
3353
|
+
if (!values.ids) values.ids = [];
|
|
3354
|
+
if (!values.values) values.values = [];
|
|
3355
|
+
if (!values.lookup) values.lookup = Object.create(null);
|
|
3356
|
+
if (!values.index) values.index = Object.create(null);
|
|
3357
|
+
const ids = values.ids;
|
|
3358
|
+
const tokenValues = values.values;
|
|
3359
|
+
const lookup = values.lookup;
|
|
3360
|
+
const indexLookup = values.index;
|
|
3361
|
+
const index = indexLookup[id];
|
|
3362
|
+
if (index === void 0) {
|
|
3363
|
+
indexLookup[id] = ids.push(id) - 1;
|
|
3364
|
+
tokenValues.push(value);
|
|
3365
|
+
} else tokenValues[index] = value;
|
|
3366
|
+
lookup[id] = value;
|
|
3367
|
+
}
|
|
3368
|
+
function addTokenValues(values, next) {
|
|
3369
|
+
if (!next) return;
|
|
3370
|
+
for (let i = 0, len = next.ids.length; i < len; i++) addTokenValue(values, next.ids[i], next.values[i]);
|
|
3371
|
+
}
|
|
3372
|
+
function addTokenOverrides(values, overrides, resolver) {
|
|
3373
|
+
for (let i = 0, len = overrides.length; i < len; i++) addTokenOverride(values, overrides[i], resolver);
|
|
3374
|
+
}
|
|
3375
|
+
function finishTokenValues(base, values) {
|
|
3376
|
+
if (!values.ids || !values.values || !values.lookup) return null;
|
|
3377
|
+
if (isSameTokenValues(base, values.ids, values.values)) return base;
|
|
3378
|
+
return {
|
|
3379
|
+
ids: values.ids,
|
|
3380
|
+
values: values.values,
|
|
3381
|
+
lookup: values.lookup
|
|
3382
|
+
};
|
|
3383
|
+
}
|
|
3384
|
+
function mergeTokenValues(base, next) {
|
|
3385
|
+
if (!next) return base;
|
|
3386
|
+
if (!base) return next;
|
|
3387
|
+
const values = createMutableTokenValues(base);
|
|
3388
|
+
addTokenValues(values, next);
|
|
3389
|
+
return finishTokenValues(base, values);
|
|
3390
|
+
}
|
|
3391
|
+
function mergeTokenOverrides(base, overrides, resolver) {
|
|
3392
|
+
if (!overrides.length) return base;
|
|
3393
|
+
const values = createMutableTokenValues(base);
|
|
3394
|
+
addTokenOverrides(values, overrides, resolver);
|
|
3395
|
+
return finishTokenValues(base, values);
|
|
3396
|
+
}
|
|
3397
|
+
function createTokenIndexLookup(ids) {
|
|
3398
|
+
const lookup = Object.create(null);
|
|
3399
|
+
for (let i = 0, len = ids.length; i < len; i++) lookup[ids[i]] = i;
|
|
3400
|
+
return lookup;
|
|
3401
|
+
}
|
|
3402
|
+
function isSameTokenValues(base, ids, values) {
|
|
3403
|
+
if (!base || base.ids.length !== ids.length) return false;
|
|
3404
|
+
const baseLookup = base.lookup;
|
|
3405
|
+
for (let i = 0, len = ids.length; i < len; i++) {
|
|
3406
|
+
if (!hasOwn(baseLookup, ids[i])) return false;
|
|
3407
|
+
if (baseLookup[ids[i]] !== values[i]) return false;
|
|
3408
|
+
}
|
|
3409
|
+
return true;
|
|
3410
|
+
}
|
|
3411
|
+
globalData("runtime.directStyleItemCache", () => /* @__PURE__ */ new WeakMap());
|
|
3412
|
+
function isResolvedStyleItem(value) {
|
|
3413
|
+
return isResolvedStyleItem$1(value);
|
|
3414
|
+
}
|
|
3415
|
+
function createResolvedStyleItem(data, scopes, tokens = null) {
|
|
3416
|
+
return createStyleItem({
|
|
3417
|
+
data,
|
|
3418
|
+
items: resolveItems(data, scopes)
|
|
3419
|
+
}, tokens);
|
|
3420
|
+
}
|
|
3421
|
+
function createStyleItem(item, tokens = null) {
|
|
3422
|
+
markResolvedStyleItem(item);
|
|
3423
|
+
if (tokens) setResolvedStyleItemTokenValues(item, tokens);
|
|
3424
|
+
return item;
|
|
3425
|
+
}
|
|
3426
|
+
function resolveItems(data, scopes) {
|
|
3427
|
+
const items = [];
|
|
3428
|
+
const stateItems = data[BUILDER_STATE]?.items ?? [];
|
|
3429
|
+
const slotId = isSlotData(data) ? getSlotId(data) : null;
|
|
3430
|
+
for (let i = 0, len = stateItems.length; i < len; i++) {
|
|
3431
|
+
const item = stateItems[i];
|
|
3432
|
+
if (Array.isArray(item)) {
|
|
3433
|
+
items.push(item);
|
|
3434
|
+
continue;
|
|
3435
|
+
}
|
|
3436
|
+
if (isStyleTokenOverrideData(item)) {
|
|
3437
|
+
items.push(item);
|
|
3438
|
+
continue;
|
|
3439
|
+
}
|
|
3440
|
+
if (slotId && item.type !== 2) continue;
|
|
3441
|
+
items.push(item);
|
|
3442
|
+
}
|
|
3443
|
+
if (!slotId || isSheetData(data)) return items;
|
|
3444
|
+
for (let i = 0, len = scopes.length; i < len; i++) {
|
|
3445
|
+
const boundScope = scopes[i];
|
|
3446
|
+
const scope = getScopeTargetScope(boundScope);
|
|
3447
|
+
if (!scope) continue;
|
|
3448
|
+
const scopeItems = scope[BUILDER_STATE]?.items;
|
|
3449
|
+
if (!scopeItems) continue;
|
|
3450
|
+
const targetSlotId = getScopeTargetSlotId(boundScope);
|
|
3451
|
+
for (let j = 0, len = scopeItems.length; j < len; j++) {
|
|
3452
|
+
const item = scopeItems[j];
|
|
3453
|
+
if (Array.isArray(item)) {
|
|
3454
|
+
if (item[1] === slotId) items.push(item);
|
|
3455
|
+
const hasParentSelector = isExtractedScopeParentMarker$2(item[4]) || isExtractedScopeParentMarker$2(item[5]);
|
|
3456
|
+
if (targetSlotId === slotId && hasParentSelector) items.push(getScopeParentItem(String(item[3])));
|
|
3457
|
+
continue;
|
|
3458
|
+
}
|
|
3459
|
+
if (isStyleTokenOverrideData(item)) continue;
|
|
3460
|
+
if (item.type !== 4) continue;
|
|
3461
|
+
if (item.slotId === slotId) items.push(item);
|
|
3462
|
+
if (item.parentSelector && targetSlotId === slotId) items.push(getScopeParentItem(item.className));
|
|
3463
|
+
}
|
|
3464
|
+
}
|
|
3465
|
+
return items;
|
|
3466
|
+
}
|
|
3467
|
+
function getScopeParentItem(className) {
|
|
3468
|
+
const parentClassName = formatScopeClassName(className);
|
|
3469
|
+
return [parentClassName, parentClassName];
|
|
3470
|
+
}
|
|
3471
|
+
function formatScopeClassName(className) {
|
|
3472
|
+
const format = CSS_CONFIG.scopeClassNameFormat;
|
|
3473
|
+
if (!format) return "-" + className;
|
|
3474
|
+
if (typeof format === "function") return format({ className });
|
|
3475
|
+
return format.replace(/\[|\]/g, "").replace(/\(className\)/g, className);
|
|
3476
|
+
}
|
|
3477
|
+
function isExtractedScopeParentMarker$2(value) {
|
|
3478
|
+
return value === 1 || value === true;
|
|
3479
|
+
}
|
|
3480
|
+
//#endregion
|
|
3481
|
+
//#region builder/extract/utils.ts
|
|
3482
|
+
function createExtractedData(type, slotId) {
|
|
3483
|
+
const data = {
|
|
3484
|
+
[BUILDER_TYPE]: type,
|
|
3485
|
+
[BUILDER_STATE]: {
|
|
3486
|
+
items: [],
|
|
3487
|
+
lookup: {}
|
|
3488
|
+
},
|
|
3489
|
+
[BUILDER_CALLSITE]: null
|
|
3490
|
+
};
|
|
3491
|
+
if (slotId !== void 0) data[BUILDER_SLOT_ID] = slotId;
|
|
3492
|
+
return data;
|
|
3493
|
+
}
|
|
3494
|
+
function copyExtractedData(target, source) {
|
|
3495
|
+
const mutable = target;
|
|
3496
|
+
mutable[BUILDER_TYPE] = source[BUILDER_TYPE];
|
|
3497
|
+
mutable[BUILDER_STATE] = source[BUILDER_STATE];
|
|
3498
|
+
mutable[BUILDER_CALLSITE] = source[BUILDER_CALLSITE];
|
|
3499
|
+
if (source[BUILDER_SLOT_ID] !== void 0) mutable[BUILDER_SLOT_ID] = source[BUILDER_SLOT_ID];
|
|
3500
|
+
}
|
|
3501
|
+
function createExtractedScopeTarget(scope, slot) {
|
|
3502
|
+
return {
|
|
3503
|
+
[BUILDER_TYPE]: 5,
|
|
3504
|
+
[BUILDER_SCOPE]: scope,
|
|
3505
|
+
[BUILDER_SCOPE_ID]: slot[BUILDER_SLOT_ID]
|
|
3506
|
+
};
|
|
3507
|
+
}
|
|
3508
|
+
function normalizeExtractedItems(type, slotId, items) {
|
|
3509
|
+
const normalized = [];
|
|
3510
|
+
let i = 0;
|
|
3511
|
+
while (i < items.length) {
|
|
3512
|
+
const item = items[i];
|
|
3513
|
+
const value = item[2];
|
|
3514
|
+
normalized.push(value === void 0 ? slotId === null ? [
|
|
3515
|
+
type,
|
|
3516
|
+
item[0],
|
|
3517
|
+
item[1]
|
|
3518
|
+
] : [
|
|
3519
|
+
type,
|
|
3520
|
+
slotId,
|
|
3521
|
+
item[0],
|
|
3522
|
+
item[1]
|
|
3523
|
+
] : slotId === null ? [
|
|
3524
|
+
type,
|
|
3525
|
+
item[0],
|
|
3526
|
+
item[1],
|
|
3527
|
+
value
|
|
3528
|
+
] : [
|
|
3529
|
+
type,
|
|
3530
|
+
slotId,
|
|
3531
|
+
item[0],
|
|
3532
|
+
item[1],
|
|
3533
|
+
value
|
|
3534
|
+
]);
|
|
3535
|
+
i++;
|
|
3536
|
+
}
|
|
3537
|
+
return normalized;
|
|
3538
|
+
}
|
|
3539
|
+
//#endregion
|
|
3540
|
+
//#region builder/extract/withTokens.ts
|
|
3541
|
+
const tokenBoundData = /* @__PURE__ */ new WeakMap();
|
|
3542
|
+
function isExtractedTokenBoundData(value) {
|
|
3543
|
+
return !!value && (typeof value === "object" || typeof value === "function") && tokenBoundData.has(value);
|
|
3544
|
+
}
|
|
3545
|
+
function getExtractedTokenBoundData(value) {
|
|
3546
|
+
return tokenBoundData.get(value);
|
|
3547
|
+
}
|
|
3548
|
+
function isElementDebugData(value) {
|
|
3549
|
+
if (!value || typeof value !== "object") return false;
|
|
3550
|
+
return value.$$elementDebug === true;
|
|
3551
|
+
}
|
|
3552
|
+
//#endregion
|
|
3553
|
+
//#region runtime/core/cache/itemWithResolver.ts
|
|
3554
|
+
function createResolvedStyleItemWithResolver(data, tokens, resolver) {
|
|
3555
|
+
return createResolvedStyleItem(data, [], mergeTokenValues(getDataTokenValues(data, resolver), tokens));
|
|
3556
|
+
}
|
|
3557
|
+
function getDirectStyleItemWithResolver(item, resolver) {
|
|
3558
|
+
return createResolvedStyleItemWithResolver(item, null, resolver);
|
|
3559
|
+
}
|
|
3560
|
+
function getDataTokenValues(data, resolver) {
|
|
3561
|
+
const stateItems = data[BUILDER_STATE]?.items ?? [];
|
|
3562
|
+
const values = createMutableTokenValues(null);
|
|
3563
|
+
for (let i = 0, len = stateItems.length; i < len; i++) addTokenOverride(values, stateItems[i], resolver);
|
|
3564
|
+
return finishTokenValues(null, values);
|
|
3565
|
+
}
|
|
3566
|
+
createCacheValue();
|
|
3567
|
+
function createCacheValue() {
|
|
3568
|
+
return {
|
|
3569
|
+
d: null,
|
|
3570
|
+
c: RUNTIME_CONFIG.changes
|
|
3571
|
+
};
|
|
3572
|
+
}
|
|
3573
|
+
//#endregion
|
|
3574
|
+
//#region runtime/core/cache/token.ts
|
|
3575
|
+
const runtimeTokenValueResolver = {
|
|
3576
|
+
get key() {
|
|
3577
|
+
return CSS_CONFIG.tokenNameFormat;
|
|
3578
|
+
},
|
|
3579
|
+
is: isStyleTokenOverrideData,
|
|
3580
|
+
id(token) {
|
|
3581
|
+
return getStyleTokenId(token);
|
|
3582
|
+
},
|
|
3583
|
+
value(token) {
|
|
3584
|
+
return getTokenOverrideValue(token, CSS_CONFIG.tokenNameFormat ?? null);
|
|
3585
|
+
}
|
|
3586
|
+
};
|
|
3587
|
+
function normalizeStylePropItem(item, stableTokenBound) {
|
|
3588
|
+
if (isElementDebugData(item)) return null;
|
|
3589
|
+
if (RUNTIME_CONFIG.isHoist && isExtractedTokenBoundData(item)) {
|
|
3590
|
+
const bound = getExtractedTokenBoundData(item);
|
|
3591
|
+
if (stableTokenBound) return normalizeStylePropItem(bound.data, true);
|
|
3592
|
+
const tokens = mergeTokenOverrides(null, bound.tokens, runtimeTokenValueResolver);
|
|
3593
|
+
if (isStyleData(bound.data) || isSheetData(bound.data) || isSlotData(bound.data)) return createResolvedStyleItemWithResolver(bound.data, tokens, runtimeTokenValueResolver);
|
|
3594
|
+
return normalizeStylePropItem(bound.data, false);
|
|
3595
|
+
}
|
|
3596
|
+
if (isResolvedStyleItem(item) || isThemeData(item)) return item;
|
|
3597
|
+
if (isStyleData(item) || isSheetData(item) || isSlotData(item)) return getDirectStyleItemWithResolver(item, runtimeTokenValueResolver);
|
|
3598
|
+
return null;
|
|
3599
|
+
}
|
|
3600
|
+
function getStylePropCacheKey(item, tokenBindings) {
|
|
3601
|
+
if (RUNTIME_CONFIG.isHoist && isExtractedTokenBoundData(item)) {
|
|
3602
|
+
const bound = getExtractedTokenBoundData(item);
|
|
3603
|
+
const key = getStylePropCacheKey(bound.data, tokenBindings);
|
|
3604
|
+
const tokens = mergeTokenOverrides(null, bound.tokens, runtimeTokenValueResolver);
|
|
3605
|
+
if (key && tokens) tokenBindings.push({
|
|
3606
|
+
data: key,
|
|
3607
|
+
tokens
|
|
3608
|
+
});
|
|
3609
|
+
return key;
|
|
3610
|
+
}
|
|
3611
|
+
if (isResolvedStyleItem(item) || isThemeData(item) || isStyleData(item) || isSheetData(item) || isSlotData(item)) return item;
|
|
3612
|
+
return null;
|
|
3613
|
+
}
|
|
3614
|
+
//#endregion
|
|
3615
|
+
//#region atomic/rule.ts
|
|
3616
|
+
function buildAtomicRule(className, property, value, important, selector, parentSelector, atRules, scopeClassNameFormat) {
|
|
3617
|
+
const cssProp = getCssPropertyName(property);
|
|
3618
|
+
const cssValue = getCssPropertyValue(property, value) + (important ? " !important" : "");
|
|
3619
|
+
const escapedClass = escapeCssIdent(className);
|
|
3620
|
+
const sheetWeight = getSheetSelectorWeight(selector);
|
|
3621
|
+
const classSelector = sheetWeight ? Array(sheetWeight).fill("." + escapedClass).join("") : hasSheetSelectorAnchor(selector) ? `:where(.${escapedClass})` : "." + escapedClass;
|
|
3622
|
+
const itemSelector = selector ? getSelectorText$1(selector) : "";
|
|
3623
|
+
let selectorStr = classSelector + itemSelector;
|
|
3624
|
+
if (parentSelector) {
|
|
3625
|
+
const parentWhere = `:where(${"." + escapeCssIdent(getScopeClassName(className, scopeClassNameFormat)) + getSelectorText$1(parentSelector)})`;
|
|
3626
|
+
selectorStr = classSelector + parentWhere + itemSelector + "," + parentWhere + " " + selectorStr;
|
|
3627
|
+
}
|
|
3628
|
+
let rule = `${selectorStr}{${cssProp}: ${cssValue}}`;
|
|
3629
|
+
if (atRules) for (let i = atRules.length - 1; i >= 0; i--) rule = `${getSelectorText$1(atRules[i])}{${rule}}`;
|
|
3630
|
+
return rule;
|
|
3631
|
+
}
|
|
3632
|
+
function getAtomicRuleLayerPriority(property, priority, selector, parentSelector, atRules, isScopeRule = false) {
|
|
3633
|
+
const selectorPriority = getSelectorPriority$1(selector);
|
|
3634
|
+
const parentSelectorPriority = getSelectorPriority$1(parentSelector);
|
|
3635
|
+
const atRulePriority = getAtRulePriority$1(atRules);
|
|
3636
|
+
return [
|
|
3637
|
+
priority ?? 0,
|
|
3638
|
+
getLayerSelectorPriority(selector, parentSelector, selectorPriority),
|
|
3639
|
+
getParentSelectorPriority(parentSelector, parentSelectorPriority),
|
|
3640
|
+
getMediaPriority(atRules, atRulePriority),
|
|
3641
|
+
atRules ? atRules.length : 0,
|
|
3642
|
+
isScopeRule && !parentSelector ? 1 : 0,
|
|
3643
|
+
getPropertyPriority(property)
|
|
3644
|
+
];
|
|
3645
|
+
}
|
|
3646
|
+
function getMediaPriority(atRules, priority) {
|
|
3647
|
+
if (!atRules?.length) return LayerMediaPriorities.base;
|
|
3648
|
+
if (priority <= 0) return LayerMediaPriorities.media;
|
|
3649
|
+
return LayerMediaPriorities.priorityMedia + priority;
|
|
3650
|
+
}
|
|
3651
|
+
function getLayerSelectorPriority(selector, parentSelector, priority) {
|
|
3652
|
+
if (selector) return priority > 0 ? LayerSelectorPriorities.prioritySelector + priority : LayerSelectorPriorities.selector;
|
|
3653
|
+
if (parentSelector) return LayerSelectorPriorities.parentSelector;
|
|
3654
|
+
return LayerSelectorPriorities.base;
|
|
3655
|
+
}
|
|
3656
|
+
function getParentSelectorPriority(parentSelector, priority) {
|
|
3657
|
+
if (!parentSelector) return 0;
|
|
3658
|
+
return priority > 0 ? priority + 1 : 1;
|
|
3659
|
+
}
|
|
3660
|
+
function getAtRulePriority$1(atRules) {
|
|
3661
|
+
if (!atRules?.length) return 0;
|
|
3662
|
+
let priority = 0;
|
|
3663
|
+
for (let i = 0, len = atRules.length; i < len; i++) priority = Math.max(priority, getSelectorPriority$1(atRules[i]));
|
|
3664
|
+
return priority;
|
|
3665
|
+
}
|
|
3666
|
+
const formatThemeName = createNameFormatter(["name"]);
|
|
3667
|
+
function createThemeClassName(name, id, themeNameFormat) {
|
|
3668
|
+
return formatThemeName(themeNameFormat || "theme[-(name)]-$hash", getIdentifierSafeHash(id, CSS_CONFIG.hashLength), { name: normalizeThemeName(name) });
|
|
3669
|
+
}
|
|
3670
|
+
function getThemeRuleCss(className, tokens, tokenNameFormat) {
|
|
3671
|
+
const declarations = [];
|
|
3672
|
+
for (let i = 0, len = tokens.length; i < len; i++) declarations.push(getThemeDeclaration(tokens[i], tokenNameFormat));
|
|
3673
|
+
return "." + escapeCssIdent(className) + "{" + declarations.join(";") + "}";
|
|
3674
|
+
}
|
|
3675
|
+
function getThemeDeclaration(token, tokenNameFormat) {
|
|
3676
|
+
const name = getTokenVarName(token, tokenNameFormat);
|
|
3677
|
+
const value = token.ref ? getTokenOverrideValue(token, tokenNameFormat) : escapeCssValue(String(token.value ?? ""));
|
|
3678
|
+
return name + ":" + value;
|
|
3679
|
+
}
|
|
3680
|
+
function normalizeThemeName(value) {
|
|
3681
|
+
if (!value) return null;
|
|
3682
|
+
value = value.trim();
|
|
3683
|
+
if (!value) return null;
|
|
3684
|
+
if (/^\d+$/.test(value)) return null;
|
|
3685
|
+
if (isGeneratedNameHash(value)) return null;
|
|
3686
|
+
const stableSuffix = value.match(/^(.+)-[a-z0-9]{7}$/);
|
|
3687
|
+
if (stableSuffix?.[1] && isGeneratedNameHash(value.slice(-7))) return normalizeThemeName(stableSuffix[1]);
|
|
3688
|
+
value = stripGenericThemePrefix(value);
|
|
3689
|
+
if (!value) return null;
|
|
3690
|
+
return value;
|
|
3691
|
+
}
|
|
3692
|
+
function stripGenericThemePrefix(value) {
|
|
3693
|
+
const parts = value.split("--");
|
|
3694
|
+
while (parts[0] === "theme" || parts[0] === "themes") parts.shift();
|
|
3695
|
+
value = parts.join("--");
|
|
3696
|
+
if (value.startsWith("theme-")) return value.slice(6);
|
|
3697
|
+
if (value.startsWith("themes-")) return value.slice(7);
|
|
3698
|
+
return value;
|
|
3699
|
+
}
|
|
3700
|
+
function isGeneratedNameHash(value) {
|
|
3701
|
+
return /^[a-z0-9]{7}$/.test(value) && /\d/.test(value);
|
|
3702
|
+
}
|
|
3703
|
+
createNameFormatter(["name"]);
|
|
3704
|
+
globalData("runtime.elementMarkerSheet", () => ({ sheet: null }));
|
|
2663
3705
|
//#endregion
|
|
2664
3706
|
//#region style/keyframes.ts
|
|
2665
3707
|
function transformKeyframes(frames, transform) {
|
|
@@ -2687,9 +3729,11 @@ function createStyleFn(args) {
|
|
|
2687
3729
|
const fnStyle = createStyleBuilder(selectors, transform);
|
|
2688
3730
|
const fnSlot = createSlotBuilder(selectors, transform);
|
|
2689
3731
|
const fnScope = createScopeBuilder(selectors);
|
|
2690
|
-
const
|
|
2691
|
-
|
|
3732
|
+
const fnSelector = createSelectorBuilder(selectors, transform);
|
|
3733
|
+
const fnWeight = (value, weight) => {
|
|
3734
|
+
return weightValue(value, weight);
|
|
2692
3735
|
};
|
|
3736
|
+
const fnImportant = (value) => importantValue(value);
|
|
2693
3737
|
const fnRaw = (style) => style;
|
|
2694
3738
|
const fnPlain = (style) => style;
|
|
2695
3739
|
const fnKeyframes = ((frames, stableId) => createStyleKeyframes(frames, transform ?? null, stableId));
|
|
@@ -2701,16 +3745,18 @@ function createStyleFn(args) {
|
|
|
2701
3745
|
const style = fnStyle;
|
|
2702
3746
|
style.slot = fnSlot;
|
|
2703
3747
|
style.scope = fnScope;
|
|
2704
|
-
style.
|
|
3748
|
+
style.weight = fnWeight;
|
|
3749
|
+
style.important = fnImportant;
|
|
2705
3750
|
style.raw = fnRaw;
|
|
2706
3751
|
style.plain = fnPlain;
|
|
2707
3752
|
style.keyframes = fnKeyframes;
|
|
2708
3753
|
style.merge = fnMerge;
|
|
2709
|
-
|
|
3754
|
+
style.selector = fnSelector;
|
|
3755
|
+
assignStyleFnMeta(style, {
|
|
3756
|
+
mode: "StyleObject",
|
|
2710
3757
|
selectors,
|
|
2711
3758
|
transform: transform ?? null
|
|
2712
|
-
};
|
|
2713
|
-
Object.assign(style, { [META]: meta });
|
|
3759
|
+
});
|
|
2714
3760
|
return { style };
|
|
2715
3761
|
}
|
|
2716
3762
|
function mergeStyleResult(target, style) {
|
|
@@ -2719,12 +3765,17 @@ function mergeStyleResult(target, style) {
|
|
|
2719
3765
|
if (typeof chainMerge === "function") return chainMerge.call(target, style);
|
|
2720
3766
|
return target;
|
|
2721
3767
|
}
|
|
3768
|
+
function assignStyleFnMeta(styleFn, meta) {
|
|
3769
|
+
Object.assign(styleFn, { [META]: meta });
|
|
3770
|
+
return styleFn;
|
|
3771
|
+
}
|
|
2722
3772
|
function getStyleFnMeta(styleFn) {
|
|
2723
3773
|
return styleFn[META];
|
|
2724
3774
|
}
|
|
2725
3775
|
//#endregion
|
|
2726
3776
|
//#region compiler/utils/import_source.ts
|
|
2727
3777
|
const DefaultStyleFnMeta = {
|
|
3778
|
+
mode: "StyleObject",
|
|
2728
3779
|
selectors: PrioritySelectors,
|
|
2729
3780
|
transform: null
|
|
2730
3781
|
};
|
|
@@ -2741,9 +3792,11 @@ function createImportSourceMatcher(importSources) {
|
|
|
2741
3792
|
meta: DefaultStyleFnMeta
|
|
2742
3793
|
});
|
|
2743
3794
|
importSources?.forEach((entry) => {
|
|
3795
|
+
const meta = entry.meta ?? (entry.styleFn ? getStyleFnMeta(entry.styleFn) : null);
|
|
3796
|
+
if (!meta) return;
|
|
2744
3797
|
addImportSourceEntry(state, {
|
|
2745
3798
|
...entry,
|
|
2746
|
-
meta
|
|
3799
|
+
meta
|
|
2747
3800
|
});
|
|
2748
3801
|
});
|
|
2749
3802
|
return (source) => {
|
|
@@ -2835,65 +3888,6 @@ function isGlobPattern(source) {
|
|
|
2835
3888
|
return /[*?[\]{}]/.test(source) || /[!+@?*]\(/.test(source);
|
|
2836
3889
|
}
|
|
2837
3890
|
//#endregion
|
|
2838
|
-
//#region builder/extract/utils.ts
|
|
2839
|
-
function createExtractedData(type, slotId) {
|
|
2840
|
-
const data = {
|
|
2841
|
-
[BUILDER_TYPE]: type,
|
|
2842
|
-
[BUILDER_STATE]: {
|
|
2843
|
-
items: [],
|
|
2844
|
-
lookup: {}
|
|
2845
|
-
},
|
|
2846
|
-
[BUILDER_CALLSITE]: null
|
|
2847
|
-
};
|
|
2848
|
-
if (slotId !== void 0) data[BUILDER_SLOT_ID] = slotId;
|
|
2849
|
-
return data;
|
|
2850
|
-
}
|
|
2851
|
-
function copyExtractedData(target, source) {
|
|
2852
|
-
const mutable = target;
|
|
2853
|
-
mutable[BUILDER_TYPE] = source[BUILDER_TYPE];
|
|
2854
|
-
mutable[BUILDER_STATE] = source[BUILDER_STATE];
|
|
2855
|
-
mutable[BUILDER_CALLSITE] = source[BUILDER_CALLSITE];
|
|
2856
|
-
if (source[BUILDER_SLOT_ID] !== void 0) mutable[BUILDER_SLOT_ID] = source[BUILDER_SLOT_ID];
|
|
2857
|
-
}
|
|
2858
|
-
function createExtractedScopeTarget(scope, slot) {
|
|
2859
|
-
return {
|
|
2860
|
-
[BUILDER_TYPE]: 5,
|
|
2861
|
-
[BUILDER_SCOPE]: scope,
|
|
2862
|
-
[BUILDER_SCOPE_ID]: slot[BUILDER_SLOT_ID]
|
|
2863
|
-
};
|
|
2864
|
-
}
|
|
2865
|
-
function normalizeExtractedItems(type, slotId, items) {
|
|
2866
|
-
const normalized = [];
|
|
2867
|
-
let i = 0;
|
|
2868
|
-
while (i < items.length) {
|
|
2869
|
-
const item = items[i];
|
|
2870
|
-
const value = item[2];
|
|
2871
|
-
normalized.push(value === void 0 ? slotId === null ? [
|
|
2872
|
-
type,
|
|
2873
|
-
item[0],
|
|
2874
|
-
item[1]
|
|
2875
|
-
] : [
|
|
2876
|
-
type,
|
|
2877
|
-
slotId,
|
|
2878
|
-
item[0],
|
|
2879
|
-
item[1]
|
|
2880
|
-
] : slotId === null ? [
|
|
2881
|
-
type,
|
|
2882
|
-
item[0],
|
|
2883
|
-
item[1],
|
|
2884
|
-
value
|
|
2885
|
-
] : [
|
|
2886
|
-
type,
|
|
2887
|
-
slotId,
|
|
2888
|
-
item[0],
|
|
2889
|
-
item[1],
|
|
2890
|
-
value
|
|
2891
|
-
]);
|
|
2892
|
-
i++;
|
|
2893
|
-
}
|
|
2894
|
-
return normalized;
|
|
2895
|
-
}
|
|
2896
|
-
//#endregion
|
|
2897
3891
|
//#region builder/extract/scope.ts
|
|
2898
3892
|
function createExtractedScope(items) {
|
|
2899
3893
|
const scope = ((slot) => {
|
|
@@ -2904,6 +3898,16 @@ function createExtractedScope(items) {
|
|
|
2904
3898
|
return scope;
|
|
2905
3899
|
}
|
|
2906
3900
|
//#endregion
|
|
3901
|
+
//#region builder/extract/sheet.ts
|
|
3902
|
+
function createExtractedSheet(items, options = {}) {
|
|
3903
|
+
const data = createExtractedData(9);
|
|
3904
|
+
data[BUILDER_SHEET_OPTIONS] = options;
|
|
3905
|
+
const normalizedItems = items.filter((item) => Array.isArray(item));
|
|
3906
|
+
const tokenItems = items.filter((item) => !Array.isArray(item));
|
|
3907
|
+
data[BUILDER_STATE].items = [...tokenItems, ...normalizeExtractedItems(9, null, normalizedItems)];
|
|
3908
|
+
return data;
|
|
3909
|
+
}
|
|
3910
|
+
//#endregion
|
|
2907
3911
|
//#region builder/extract/slot.ts
|
|
2908
3912
|
function createExtractedSlot(slotId, items) {
|
|
2909
3913
|
const slot = ((items) => {
|
|
@@ -2977,6 +3981,62 @@ function appendExtractedStyleTuples(target, source) {
|
|
|
2977
3981
|
}
|
|
2978
3982
|
}
|
|
2979
3983
|
//#endregion
|
|
3984
|
+
//#region dialect/namedTokens.ts
|
|
3985
|
+
const ROOT = Symbol("fluentic.namedTokens.root");
|
|
3986
|
+
function createNamedToken(id, value) {
|
|
3987
|
+
const token = createStyleToken(value, createNamedTokenId(id));
|
|
3988
|
+
token[TOKEN_VAR_NAME] = getTokenVarName(token, CSS_CONFIG.tokenNameFormat ?? null);
|
|
3989
|
+
return token;
|
|
3990
|
+
}
|
|
3991
|
+
function createNamedTokens(namespace, values) {
|
|
3992
|
+
return createNamedTokenProxy({
|
|
3993
|
+
__fluenticNamedTokens: true,
|
|
3994
|
+
namespace,
|
|
3995
|
+
values,
|
|
3996
|
+
cache: /* @__PURE__ */ new Map()
|
|
3997
|
+
}, []);
|
|
3998
|
+
}
|
|
3999
|
+
function createNamedTokenId(id) {
|
|
4000
|
+
return sanitizeCssIdentName(id.replace(/\./g, "-"), "named-token");
|
|
4001
|
+
}
|
|
4002
|
+
function createNamedTokenProxy(root, path) {
|
|
4003
|
+
return new Proxy(noop, {
|
|
4004
|
+
get(_target, property) {
|
|
4005
|
+
if (property === ROOT) return root;
|
|
4006
|
+
if (property === "then") return void 0;
|
|
4007
|
+
if (property === Symbol.toStringTag) return "NamedTokens";
|
|
4008
|
+
if (property === TOKEN_ID || property === TOKEN_NAME || property === TOKEN_VAR_NAME || property === TOKEN_OVERRIDE || property === "value" || property === "ref") {
|
|
4009
|
+
if (!path.length) return void 0;
|
|
4010
|
+
return getNamedTokenAtPath(root, path)[property];
|
|
4011
|
+
}
|
|
4012
|
+
if (typeof property === "symbol") return void 0;
|
|
4013
|
+
return createNamedTokenProxy(root, path.concat(String(property)));
|
|
4014
|
+
},
|
|
4015
|
+
apply(_target, _thisArg, args) {
|
|
4016
|
+
if (!path.length) return void 0;
|
|
4017
|
+
return getNamedTokenAtPath(root, path).apply(void 0, args);
|
|
4018
|
+
}
|
|
4019
|
+
});
|
|
4020
|
+
}
|
|
4021
|
+
function getNamedTokenAtPath(root, path) {
|
|
4022
|
+
const key = path.join(".");
|
|
4023
|
+
const cached = root.cache.get(key);
|
|
4024
|
+
if (cached) return cached;
|
|
4025
|
+
const value = getValueAtPath(root.values, path);
|
|
4026
|
+
const token = createNamedToken(root.namespace + "." + key, value);
|
|
4027
|
+
root.cache.set(key, token);
|
|
4028
|
+
return token;
|
|
4029
|
+
}
|
|
4030
|
+
function getValueAtPath(values, path) {
|
|
4031
|
+
let current = values;
|
|
4032
|
+
for (let i = 0; i < path.length; i++) {
|
|
4033
|
+
if (!current || typeof current !== "object") return void 0;
|
|
4034
|
+
current = current[path[i]];
|
|
4035
|
+
}
|
|
4036
|
+
return current;
|
|
4037
|
+
}
|
|
4038
|
+
function noop() {}
|
|
4039
|
+
//#endregion
|
|
2980
4040
|
//#region style/utils/expose.ts
|
|
2981
4041
|
function exposeStyle(styles) {
|
|
2982
4042
|
return exposeStyleObject(styles);
|
|
@@ -2991,7 +4051,7 @@ function exposeStyleObject(source) {
|
|
|
2991
4051
|
return result;
|
|
2992
4052
|
}
|
|
2993
4053
|
function exposeStyleValue(value) {
|
|
2994
|
-
if (isStyleTokenData(value) || isSlotData(value)) return value;
|
|
4054
|
+
if (isStyleTokenData(value) || isSlotData(value) || isSelectorData(value)) return value;
|
|
2995
4055
|
if (!value || typeof value !== "object" || Array.isArray(value)) return void 0;
|
|
2996
4056
|
const exposed = exposeStyleObject(value);
|
|
2997
4057
|
return Reflect.ownKeys(exposed).length > 0 ? exposed : void 0;
|
|
@@ -3032,6 +4092,7 @@ function evaluateNode(node, scope) {
|
|
|
3032
4092
|
case "ParenthesizedExpression":
|
|
3033
4093
|
case "TSAsExpression":
|
|
3034
4094
|
case "TSNonNullExpression":
|
|
4095
|
+
case "TSSatisfiesExpression":
|
|
3035
4096
|
case "TSTypeAssertion": return evaluateNode(node.expression, scope);
|
|
3036
4097
|
default: return evalFail(`Cannot statically evaluate: ${node.type}`);
|
|
3037
4098
|
}
|
|
@@ -3104,14 +4165,14 @@ function evaluateMember(node, scope) {
|
|
|
3104
4165
|
if (!key.ok) return key;
|
|
3105
4166
|
const obj = evaluateNode(node.object, scope);
|
|
3106
4167
|
if (!obj.ok) return obj;
|
|
3107
|
-
if (obj.value && typeof obj.value === "object") return evalOk(obj.value[key.value]);
|
|
4168
|
+
if (obj.value && (typeof obj.value === "object" || typeof obj.value === "function")) return evalOk(obj.value[key.value]);
|
|
3108
4169
|
return evalFail("Cannot index non-object");
|
|
3109
4170
|
}
|
|
3110
4171
|
const prop = node.property.name;
|
|
3111
4172
|
const obj = evaluateNode(node.object, scope);
|
|
3112
4173
|
if (!obj.ok) return obj;
|
|
3113
4174
|
if (obj.value == null) return evalFail(`Cannot access .${prop} on null/undefined`);
|
|
3114
|
-
if (typeof obj.value !== "object" && typeof obj.value !== "string") return evalFail(`Cannot access .${prop} on ${typeof obj.value}`);
|
|
4175
|
+
if (typeof obj.value !== "object" && typeof obj.value !== "function" && typeof obj.value !== "string") return evalFail(`Cannot access .${prop} on ${typeof obj.value}`);
|
|
3115
4176
|
return evalOk(obj.value[prop]);
|
|
3116
4177
|
}
|
|
3117
4178
|
function evaluateObject(node, scope) {
|
|
@@ -3150,12 +4211,17 @@ function evaluateObject(node, scope) {
|
|
|
3150
4211
|
} else key = prop.key.type === "Identifier" ? prop.key.name : prop.key.value;
|
|
3151
4212
|
const val = evaluateNode(prop.value, scope);
|
|
3152
4213
|
if (!val.ok && isRequiredStaticStyleValueFail(val.reason)) return val;
|
|
3153
|
-
result[key] = val.ok ? val.value : createCompiledRuntimeValue(prop.value);
|
|
3154
|
-
if (prop.loc?.start)
|
|
3155
|
-
|
|
3156
|
-
|
|
3157
|
-
|
|
3158
|
-
|
|
4214
|
+
result[key] = val.ok ? val.value : createCompiledRuntimeValue$1(prop.value);
|
|
4215
|
+
if (prop.loc?.start) {
|
|
4216
|
+
const variableLoc = prop.value.loc?.start ?? prop.loc?.start;
|
|
4217
|
+
locations[key] = {
|
|
4218
|
+
line: prop.loc.start.line,
|
|
4219
|
+
column: prop.loc.start.column + 1,
|
|
4220
|
+
filePath: scope.styleFilePath ?? scope.filePath,
|
|
4221
|
+
variableLine: variableLoc?.line,
|
|
4222
|
+
variableColumn: variableLoc ? variableLoc.column + 1 : void 0
|
|
4223
|
+
};
|
|
4224
|
+
}
|
|
3159
4225
|
} else return evalFail(`Cannot evaluate ObjectMethod in style object`);
|
|
3160
4226
|
i++;
|
|
3161
4227
|
}
|
|
@@ -3204,6 +4270,15 @@ function evaluateCall(node, scope) {
|
|
|
3204
4270
|
if (!Array.isArray(items.value)) return evalFail("createExtractedStyle items must be an array");
|
|
3205
4271
|
return evalOk(createExtractedStyle(items.value));
|
|
3206
4272
|
}
|
|
4273
|
+
if (imp && imp.source === "@fluentic/style/entry/prod/extract" && imp.name === "createExtractedSheet") {
|
|
4274
|
+
const items = evaluateNode(node.arguments[0], scope);
|
|
4275
|
+
if (!items.ok) return items;
|
|
4276
|
+
if (!Array.isArray(items.value)) return evalFail("createExtractedSheet items must be an array");
|
|
4277
|
+
const options = node.arguments[1] ? evaluateNode(node.arguments[1], scope) : evalOk({});
|
|
4278
|
+
if (!options.ok) return options;
|
|
4279
|
+
if (!options.value || typeof options.value !== "object" || Array.isArray(options.value)) return evalFail("createExtractedSheet options must be an object");
|
|
4280
|
+
return evalOk(createExtractedSheet(items.value, options.value));
|
|
4281
|
+
}
|
|
3207
4282
|
if (imp && imp.source === "@fluentic/style/entry/prod/extract" && imp.name === "getExtractedStyleItems") {
|
|
3208
4283
|
const style = evaluateNode(node.arguments[0], scope);
|
|
3209
4284
|
if (!style.ok) return style;
|
|
@@ -3235,9 +4310,9 @@ function evaluateCall(node, scope) {
|
|
|
3235
4310
|
if (imp && STYLE_IMPORT_PATHS.has(imp.source) && imp.name === "createToken") {
|
|
3236
4311
|
const value = evaluateNode(node.arguments[0], scope);
|
|
3237
4312
|
if (!value.ok) return value;
|
|
3238
|
-
const
|
|
3239
|
-
if (!
|
|
3240
|
-
return evalOk(createCompiledToken(value.value, scope, node.loc?.start, node,
|
|
4313
|
+
const stableId = evaluateOptionalStableTokenId(node.arguments[1], scope);
|
|
4314
|
+
if (!stableId.ok) return stableId;
|
|
4315
|
+
return evalOk(createCompiledToken(value.value, scope, node.loc?.start, node, stableId.value));
|
|
3241
4316
|
}
|
|
3242
4317
|
if (imp && STYLE_IMPORT_PATHS.has(imp.source) && imp.name === "createKeyframes") {
|
|
3243
4318
|
const frames = evaluateNode(node.arguments[0], scope);
|
|
@@ -3304,16 +4379,39 @@ function evaluateCall(node, scope) {
|
|
|
3304
4379
|
const url = evaluateNode(node.arguments[0], scope);
|
|
3305
4380
|
if (!url.ok) return evalFail(`fontSrc url must be statically analyzable: ${url.reason}`);
|
|
3306
4381
|
if (typeof url.value !== "string") return evalFail("fontSrc url must be a static string");
|
|
3307
|
-
const format =
|
|
4382
|
+
const format = evaluateOptionalString(node.arguments[1], scope);
|
|
3308
4383
|
if (!format.ok) return evalFail(`fontSrc format must be statically analyzable: ${format.reason}`);
|
|
3309
4384
|
return evalOk(fontSrc(url.value, format.value));
|
|
3310
4385
|
}
|
|
3311
4386
|
if (imp && STYLE_IMPORT_PATHS.has(imp.source) && imp.name === "createTokens") {
|
|
3312
4387
|
const value = evaluateNode(node.arguments[0], scope);
|
|
3313
4388
|
if (!value.ok) return value;
|
|
3314
|
-
const
|
|
3315
|
-
if (!
|
|
3316
|
-
return evalOk(createCompiledTokens(value.value, scope, node.loc?.start, node,
|
|
4389
|
+
const stableId = evaluateOptionalStableTokenId(node.arguments[1], scope);
|
|
4390
|
+
if (!stableId.ok) return stableId;
|
|
4391
|
+
return evalOk(createCompiledTokens(value.value, scope, node.loc?.start, node, stableId.value));
|
|
4392
|
+
}
|
|
4393
|
+
if (imp && STYLE_IMPORT_PATHS.has(imp.source) && imp.name === "createNamedToken") {
|
|
4394
|
+
const id = evaluateNode(node.arguments[0], scope);
|
|
4395
|
+
if (!id.ok) return id;
|
|
4396
|
+
if (typeof id.value !== "string") return evalFail("createNamedToken id must be a static string");
|
|
4397
|
+
const value = evaluateNode(node.arguments[1], scope);
|
|
4398
|
+
if (!value.ok) return value;
|
|
4399
|
+
return evalOk(createNamedToken(id.value, value.value));
|
|
4400
|
+
}
|
|
4401
|
+
if (imp && STYLE_IMPORT_PATHS.has(imp.source) && imp.name === "createNamedTokens") {
|
|
4402
|
+
const namespace = evaluateNode(node.arguments[0], scope);
|
|
4403
|
+
if (!namespace.ok) return namespace;
|
|
4404
|
+
if (typeof namespace.value !== "string") return evalFail("createNamedTokens namespace must be a static string");
|
|
4405
|
+
const values = evaluateNode(node.arguments[1], scope);
|
|
4406
|
+
if (!values.ok) return values;
|
|
4407
|
+
if (!values.value || typeof values.value !== "object") return evalFail("createNamedTokens values must be a static object");
|
|
4408
|
+
return evalOk(createNamedTokens(namespace.value, values.value));
|
|
4409
|
+
}
|
|
4410
|
+
if (imp && STYLE_IMPORT_PATHS.has(imp.source) && imp.name === "getToken") {
|
|
4411
|
+
const value = evaluateNode(node.arguments[0], scope);
|
|
4412
|
+
if (!value.ok) return value;
|
|
4413
|
+
if (isStyleTokenData(value.value)) return evalOk(getTokenVar(value.value, CSS_CONFIG.tokenNameFormat || null));
|
|
4414
|
+
return evalOk(value.value);
|
|
3317
4415
|
}
|
|
3318
4416
|
if (imp && imp.source === "@fluentic/style/utils" && imp.name === "exposeStyle") {
|
|
3319
4417
|
const styles = evaluateNode(node.arguments[0], scope);
|
|
@@ -3324,13 +4422,13 @@ function evaluateCall(node, scope) {
|
|
|
3324
4422
|
if (imp && STYLE_IMPORT_PATHS.has(imp.source) && imp.name === "createValues") {
|
|
3325
4423
|
const hasNumberArg = node.arguments[0]?.type === "Identifier" && node.arguments[0].name === "Number";
|
|
3326
4424
|
const valuesNode = hasNumberArg ? node.arguments[1] : node.arguments[0];
|
|
3327
|
-
const
|
|
4425
|
+
const stableIdNode = hasNumberArg ? node.arguments[2] : node.arguments[1];
|
|
3328
4426
|
const values = evaluateNode(valuesNode, scope);
|
|
3329
4427
|
if (!values.ok) return values;
|
|
3330
|
-
const
|
|
3331
|
-
if (!
|
|
4428
|
+
const stableId = evaluateOptionalStableTokenId(stableIdNode, scope);
|
|
4429
|
+
if (!stableId.ok) return stableId;
|
|
3332
4430
|
if (!Array.isArray(values.value)) return evalFail("createValues values must be an array");
|
|
3333
|
-
return evalOk(createCompiledValues(values.value, scope, node.loc?.start, node,
|
|
4431
|
+
return evalOk(createCompiledValues(values.value, scope, node.loc?.start, node, stableId.value, hasNumberArg));
|
|
3334
4432
|
}
|
|
3335
4433
|
}
|
|
3336
4434
|
if (node.callee.type === "Identifier") {
|
|
@@ -3375,13 +4473,18 @@ function evaluateCall(node, scope) {
|
|
|
3375
4473
|
buildCss: (_name, tokens, tokenLookup, options) => buildKeyframesCss(format, stable.name, stable.id, transformedFrames, tokens, tokenLookup, options)
|
|
3376
4474
|
}));
|
|
3377
4475
|
}
|
|
3378
|
-
if (node.callee.type === "MemberExpression" && !node.callee.computed && node.callee.property.type === "Identifier" && node.callee.property.name === "
|
|
4476
|
+
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)) {
|
|
3379
4477
|
const value = evaluateNode(node.arguments[0], scope);
|
|
3380
4478
|
if (!value.ok) return value;
|
|
3381
4479
|
const weight = evaluateNode(node.arguments[1], scope);
|
|
3382
4480
|
if (!weight.ok) return weight;
|
|
3383
|
-
if (typeof weight.value !== "number") return evalFail(
|
|
3384
|
-
return evalOk(
|
|
4481
|
+
if (typeof weight.value !== "number") return evalFail(`${node.callee.property.name} weight must be a number`);
|
|
4482
|
+
return evalOk(weightValue(value.value, weight.value));
|
|
4483
|
+
}
|
|
4484
|
+
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)) {
|
|
4485
|
+
const value = evaluateNode(node.arguments[0], scope);
|
|
4486
|
+
if (!value.ok) return value;
|
|
4487
|
+
return evalOk(importantValue(value.value));
|
|
3385
4488
|
}
|
|
3386
4489
|
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);
|
|
3387
4490
|
return evalFail(`Cannot statically evaluate: ${node.type}`);
|
|
@@ -3418,38 +4521,48 @@ function createCompiledTokenOverride(token, value, runtimeValue) {
|
|
|
3418
4521
|
if (isStyleTokenData(value)) return withRuntimeValue(runtimeValue, {
|
|
3419
4522
|
[TOKEN_ID]: getStyleTokenId(token),
|
|
3420
4523
|
[TOKEN_OVERRIDE]: true,
|
|
4524
|
+
[TOKEN_NAME]: getStyleTokenName(token),
|
|
3421
4525
|
value: value.value,
|
|
3422
4526
|
ref: value
|
|
3423
4527
|
});
|
|
3424
4528
|
return withRuntimeValue(runtimeValue, {
|
|
3425
4529
|
[TOKEN_ID]: getStyleTokenId(token),
|
|
3426
4530
|
[TOKEN_OVERRIDE]: true,
|
|
4531
|
+
[TOKEN_NAME]: getStyleTokenName(token),
|
|
3427
4532
|
value,
|
|
3428
4533
|
ref: null
|
|
3429
4534
|
});
|
|
3430
4535
|
}
|
|
3431
|
-
function createCompiledToken(value, scope, loc, runtimeValue,
|
|
3432
|
-
let tokenId =
|
|
4536
|
+
function createCompiledToken(value, scope, loc, runtimeValue, stableId, debugName) {
|
|
4537
|
+
let tokenId = stableId;
|
|
3433
4538
|
if (!tokenId) tokenId = hashString((scope.styleFilePath ?? scope.filePath) + "\n" + (loc ? loc.line + ":" + loc.column : String(value)));
|
|
4539
|
+
if (isStyleTokenData(value)) return withRuntimeValue(runtimeValue, {
|
|
4540
|
+
[TOKEN_ID]: tokenId,
|
|
4541
|
+
[TOKEN_NAME]: debugName === void 0 ? getStyleTokenNameFromId(stableId) : normalizeStyleTokenName(debugName),
|
|
4542
|
+
value: value.value,
|
|
4543
|
+
ref: value
|
|
4544
|
+
});
|
|
3434
4545
|
return withRuntimeValue(runtimeValue, {
|
|
3435
4546
|
[TOKEN_ID]: tokenId,
|
|
4547
|
+
[TOKEN_NAME]: debugName === void 0 ? getStyleTokenNameFromId(stableId) : normalizeStyleTokenName(debugName),
|
|
3436
4548
|
value,
|
|
3437
4549
|
ref: null
|
|
3438
4550
|
});
|
|
3439
4551
|
}
|
|
3440
|
-
function createCompiledTokens(value, scope, loc, runtimeValue,
|
|
3441
|
-
const tokenGroupId =
|
|
4552
|
+
function createCompiledTokens(value, scope, loc, runtimeValue, stableId) {
|
|
4553
|
+
const tokenGroupId = stableId ?? createCompiledTokenGroupId(scope, loc);
|
|
4554
|
+
const tokenGroupName = getStyleTokenNameFromId(stableId);
|
|
3442
4555
|
if (Array.isArray(value)) {
|
|
3443
4556
|
const result = {};
|
|
3444
4557
|
for (let i = 0, len = value.length; i < len; i++) {
|
|
3445
4558
|
const item = value[i];
|
|
3446
|
-
result[item] = createCompiledToken(item, scope, loc, runtimeValue,
|
|
4559
|
+
result[item] = createCompiledToken(item, scope, loc, runtimeValue, getChildStableId(tokenGroupId, String(i)), getChildStyleTokenName(tokenGroupName, String(i)));
|
|
3447
4560
|
}
|
|
3448
4561
|
return result;
|
|
3449
4562
|
}
|
|
3450
4563
|
if (!value || typeof value !== "object") return {};
|
|
3451
4564
|
const result = {};
|
|
3452
|
-
assignCompiledTokenRecord(result, value, scope, loc, runtimeValue, tokenGroupId);
|
|
4565
|
+
assignCompiledTokenRecord(result, value, scope, loc, runtimeValue, tokenGroupId, tokenGroupName);
|
|
3453
4566
|
return result;
|
|
3454
4567
|
}
|
|
3455
4568
|
function createCompiledTokenGroupId(scope, loc) {
|
|
@@ -3461,22 +4574,24 @@ function createCompiledAtRuleStableId(scope, loc, value) {
|
|
|
3461
4574
|
id: (scope.styleFilePath ?? scope.filePath) + "\n" + (loc ? loc.line + ":" + loc.column : String(value))
|
|
3462
4575
|
};
|
|
3463
4576
|
}
|
|
3464
|
-
function assignCompiledTokenRecord(target, value, scope, loc, runtimeValue,
|
|
4577
|
+
function assignCompiledTokenRecord(target, value, scope, loc, runtimeValue, stableId, debugName) {
|
|
3465
4578
|
for (const key of Object.keys(value)) {
|
|
3466
4579
|
const item = value[key];
|
|
3467
|
-
const
|
|
4580
|
+
const itemStableId = getChildStableId(stableId, key);
|
|
4581
|
+
const itemDebugName = getChildStyleTokenName(debugName, key);
|
|
3468
4582
|
if (item && typeof item === "object" && !Array.isArray(item) && !isStyleTokenData(item)) {
|
|
3469
4583
|
const child = {};
|
|
3470
4584
|
target[key] = child;
|
|
3471
|
-
assignCompiledTokenRecord(child, item, scope, loc, runtimeValue,
|
|
3472
|
-
} else target[key] = createCompiledToken(item, scope, loc, runtimeValue,
|
|
4585
|
+
assignCompiledTokenRecord(child, item, scope, loc, runtimeValue, itemStableId, itemDebugName);
|
|
4586
|
+
} else target[key] = createCompiledToken(item, scope, loc, runtimeValue, itemStableId, itemDebugName);
|
|
3473
4587
|
}
|
|
3474
4588
|
}
|
|
3475
|
-
function createCompiledValues(values, scope, loc, runtimeValue,
|
|
4589
|
+
function createCompiledValues(values, scope, loc, runtimeValue, stableId, isNumber) {
|
|
3476
4590
|
const tokens = /* @__PURE__ */ new Map();
|
|
4591
|
+
const groupName = getStyleTokenNameFromId(stableId);
|
|
3477
4592
|
for (let i = 0, len = values.length; i < len; i++) {
|
|
3478
4593
|
const value = values[i];
|
|
3479
|
-
tokens.set(value, createCompiledToken(parseCompiledValue(value, isNumber), scope, loc, runtimeValue,
|
|
4594
|
+
tokens.set(value, createCompiledToken(parseCompiledValue(value, isNumber), scope, loc, runtimeValue, getChildStableId(stableId, hashString(String(value))), getChildStyleTokenName(groupName, getValueDebugName(value))));
|
|
3480
4595
|
}
|
|
3481
4596
|
return {
|
|
3482
4597
|
[COMPILED_TOKEN_FACTORY]: true,
|
|
@@ -3494,7 +4609,10 @@ function parseCompiledValue(value, isNumber) {
|
|
|
3494
4609
|
function isCompiledTokenFactory(value) {
|
|
3495
4610
|
return !!value && typeof value === "object" && value[COMPILED_TOKEN_FACTORY] === true;
|
|
3496
4611
|
}
|
|
3497
|
-
function
|
|
4612
|
+
function evaluateOptionalStableTokenId(node, scope) {
|
|
4613
|
+
return evaluateOptionalString(node, scope);
|
|
4614
|
+
}
|
|
4615
|
+
function evaluateOptionalString(node, scope) {
|
|
3498
4616
|
if (!node) return evalOk(void 0);
|
|
3499
4617
|
const value = evaluateNode(node, scope);
|
|
3500
4618
|
if (!value.ok) return value;
|
|
@@ -3518,16 +4636,28 @@ function evaluateOptionalStableId(node, scope) {
|
|
|
3518
4636
|
id: stableId.id
|
|
3519
4637
|
});
|
|
3520
4638
|
}
|
|
3521
|
-
function
|
|
3522
|
-
return
|
|
4639
|
+
function getChildStableId(stableId, child) {
|
|
4640
|
+
return stableId ? stableId + "--" + child : void 0;
|
|
4641
|
+
}
|
|
4642
|
+
function getValueDebugName(value) {
|
|
4643
|
+
if (typeof value === "number") return String(value);
|
|
4644
|
+
if (typeof value !== "string") return null;
|
|
4645
|
+
const parts = value.split(/[;|]/);
|
|
4646
|
+
const label = parts[1]?.trim();
|
|
4647
|
+
if (label) return sanitizeTokenDebugName(label);
|
|
4648
|
+
return sanitizeTokenDebugName(parts[0]?.trim() ?? "");
|
|
4649
|
+
}
|
|
4650
|
+
function sanitizeTokenDebugName(value) {
|
|
4651
|
+
return value.replace(/[^a-zA-Z0-9_-]+/g, "-").replace(/^-+|-+$/g, "") || null;
|
|
3523
4652
|
}
|
|
3524
4653
|
function withRuntimeValue(runtimeValue, token) {
|
|
3525
4654
|
return Object.assign({}, token, {
|
|
3526
4655
|
[TOKEN_ID]: token[TOKEN_ID],
|
|
4656
|
+
[TOKEN_NAME]: token[TOKEN_NAME] ?? null,
|
|
3527
4657
|
[COMPILED_RUNTIME_VALUE]: runtimeValue
|
|
3528
4658
|
});
|
|
3529
4659
|
}
|
|
3530
|
-
function createCompiledRuntimeValue(runtimeValue) {
|
|
4660
|
+
function createCompiledRuntimeValue$1(runtimeValue) {
|
|
3531
4661
|
return { [COMPILED_RUNTIME_VALUE]: runtimeValue };
|
|
3532
4662
|
}
|
|
3533
4663
|
function evaluateBinary(node, scope) {
|
|
@@ -3559,14 +4689,14 @@ function evaluateUnary(node, scope) {
|
|
|
3559
4689
|
function isStaticStyleValue(value) {
|
|
3560
4690
|
if (value.type === "StringLiteral" || value.type === "NumericLiteral" || value.type === "BooleanLiteral" || value.type === "NullLiteral") return true;
|
|
3561
4691
|
if (value.type === "TemplateLiteral") return value.expressions.length === 0;
|
|
3562
|
-
if (value.type === "
|
|
3563
|
-
const [priority, itemValue] = value.elements;
|
|
3564
|
-
return !!priority && priority.type === "NumericLiteral" && !!itemValue && isStaticStyleValue(itemValue);
|
|
3565
|
-
}
|
|
3566
|
-
if (value.type === "CallExpression" && value.callee.type === "MemberExpression" && !value.callee.computed && value.callee.property.type === "Identifier" && value.callee.property.name === "value") {
|
|
4692
|
+
if (value.type === "CallExpression" && value.callee.type === "MemberExpression" && !value.callee.computed && value.callee.property.type === "Identifier" && value.callee.property.name === "weight") {
|
|
3567
4693
|
const [itemValue, weight] = value.arguments;
|
|
3568
4694
|
return !!itemValue && itemValue.type !== "SpreadElement" && isStaticStyleValue(itemValue) && !!weight && weight.type === "NumericLiteral";
|
|
3569
4695
|
}
|
|
4696
|
+
if (value.type === "CallExpression" && value.callee.type === "MemberExpression" && !value.callee.computed && value.callee.property.type === "Identifier" && value.callee.property.name === "important") {
|
|
4697
|
+
const [itemValue] = value.arguments;
|
|
4698
|
+
return !!itemValue && itemValue.type !== "SpreadElement" && isStaticStyleValue(itemValue);
|
|
4699
|
+
}
|
|
3570
4700
|
if (value.type === "UnaryExpression") return isStaticStyleValue(value.argument);
|
|
3571
4701
|
return false;
|
|
3572
4702
|
}
|
|
@@ -3581,20 +4711,6 @@ function isStyleChainCall(callee, styleNames) {
|
|
|
3581
4711
|
if (object.type === "MemberExpression") return isStyleChainCall(object, styleNames);
|
|
3582
4712
|
return false;
|
|
3583
4713
|
}
|
|
3584
|
-
const formatThemeName = createNameFormatter(["name"]);
|
|
3585
|
-
function createThemeClassName(name, id, themeNameFormat) {
|
|
3586
|
-
return formatThemeName(themeNameFormat || "theme[-(name)]-$hash", getIdentifierSafeHash(id), { name });
|
|
3587
|
-
}
|
|
3588
|
-
function getThemeRuleCss(className, tokens, tokenNameFormat) {
|
|
3589
|
-
const declarations = [];
|
|
3590
|
-
for (let i = 0, len = tokens.length; i < len; i++) declarations.push(getThemeDeclaration(tokens[i], tokenNameFormat));
|
|
3591
|
-
return "." + escapeCssIdent(className) + "{" + declarations.join(";") + "}";
|
|
3592
|
-
}
|
|
3593
|
-
function getThemeDeclaration(token, tokenNameFormat) {
|
|
3594
|
-
const name = getTokenVarName(token, tokenNameFormat);
|
|
3595
|
-
const value = token.ref ? getTokenOverrideValue(token, tokenNameFormat) : escapeCssValue(String(token.value ?? ""));
|
|
3596
|
-
return name + ":" + value;
|
|
3597
|
-
}
|
|
3598
4714
|
//#endregion
|
|
3599
4715
|
//#region compiler/transform/syntax/utils.ts
|
|
3600
4716
|
function getCallLabel(callee) {
|
|
@@ -3729,60 +4845,6 @@ function sanitizeTokenId(value) {
|
|
|
3729
4845
|
return sanitizeCssIdentName(value, "token");
|
|
3730
4846
|
}
|
|
3731
4847
|
//#endregion
|
|
3732
|
-
//#region compiler/transform/utils/babel.ts
|
|
3733
|
-
function babelPlugin(factory) {
|
|
3734
|
-
return factory;
|
|
3735
|
-
}
|
|
3736
|
-
function babelTransform(args) {
|
|
3737
|
-
let result = null;
|
|
3738
|
-
try {
|
|
3739
|
-
const inputSourceMap = parseInputSourceMap(args.sourcemap);
|
|
3740
|
-
result = _babel_core.transformSync(args.code, {
|
|
3741
|
-
...babelTransformOptions(),
|
|
3742
|
-
inputSourceMap,
|
|
3743
|
-
filename: args.filePath,
|
|
3744
|
-
sourceFileName: args.filePath,
|
|
3745
|
-
plugins: args.plugins,
|
|
3746
|
-
sourceMaps: true,
|
|
3747
|
-
generatorOpts: { retainLines: args.retainLines ?? false }
|
|
3748
|
-
});
|
|
3749
|
-
} catch (err) {
|
|
3750
|
-
if (!args.errorLabel) throw err;
|
|
3751
|
-
const message = getBabelError(err, args);
|
|
3752
|
-
const error = new Error(message);
|
|
3753
|
-
error.stack = void 0;
|
|
3754
|
-
throw error;
|
|
3755
|
-
}
|
|
3756
|
-
if (!result || !result.code) return null;
|
|
3757
|
-
return {
|
|
3758
|
-
code: result.code,
|
|
3759
|
-
sourcemap: result.map ? JSON.stringify(result.map) : null
|
|
3760
|
-
};
|
|
3761
|
-
}
|
|
3762
|
-
function babelTransformOptions() {
|
|
3763
|
-
return {
|
|
3764
|
-
configFile: false,
|
|
3765
|
-
babelrc: false,
|
|
3766
|
-
parserOpts: {
|
|
3767
|
-
plugins: ["typescript", "jsx"],
|
|
3768
|
-
strictMode: false,
|
|
3769
|
-
allowImportExportEverywhere: true
|
|
3770
|
-
}
|
|
3771
|
-
};
|
|
3772
|
-
}
|
|
3773
|
-
function parseInputSourceMap(sourcemap) {
|
|
3774
|
-
if (!sourcemap) return void 0;
|
|
3775
|
-
if (typeof sourcemap !== "string") return sourcemap;
|
|
3776
|
-
return JSON.parse(sourcemap);
|
|
3777
|
-
}
|
|
3778
|
-
function getBabelError(err, args) {
|
|
3779
|
-
const babelErr = err;
|
|
3780
|
-
const msg = babelErr instanceof Error ? babelErr.message : String(err);
|
|
3781
|
-
const codeFrame = babelErr?.codeFrame;
|
|
3782
|
-
const suffix = codeFrame ? `\n\n${codeFrame}` : "";
|
|
3783
|
-
return `${args.errorLabel} in ${args.filePath}:\n${msg}${suffix}`;
|
|
3784
|
-
}
|
|
3785
|
-
//#endregion
|
|
3786
4848
|
//#region compiler/transform/utils/path.ts
|
|
3787
4849
|
function getProjectFileId$1(projectDir, filePath) {
|
|
3788
4850
|
if (!filePath) return "unknown";
|
|
@@ -3880,12 +4942,12 @@ function normalizeSelectorMessage(message) {
|
|
|
3880
4942
|
}
|
|
3881
4943
|
const formatVarName = createNameFormatter(["name"]);
|
|
3882
4944
|
function getLocalVarName(filePath, line, column, format) {
|
|
3883
|
-
const hash = getIdentifierSafeHash(filePath + "\n" + line + ":" + column);
|
|
4945
|
+
const hash = getIdentifierSafeHash(filePath + "\n" + line + ":" + column, CSS_CONFIG.hashLength);
|
|
3884
4946
|
return "--" + formatVarName(format || "var[-(name)]-$hash", hash, { name: "" });
|
|
3885
4947
|
}
|
|
3886
4948
|
//#endregion
|
|
3887
4949
|
//#region compiler/transform/debug/utils/debug_data.ts
|
|
3888
|
-
function buildDebugDataObject(t, node, fileId, sourceUrlRef, sourceContentRef, tokenNameFormat = DEFAULT_CONFIG.tokenNameFormat, styleArg = node.arguments[0], locOverride) {
|
|
4950
|
+
function buildDebugDataObject(t, node, fileId, sourceUrlRef, sourceContentRef, tokenNameFormat = DEFAULT_CONFIG.tokenNameFormat, styleArg = node.arguments[0], locOverride, classNameArg = false) {
|
|
3889
4951
|
const loc = locOverride ?? node.loc?.start;
|
|
3890
4952
|
const line = loc?.line ?? 1;
|
|
3891
4953
|
const column = (loc?.column ?? 0) + 1;
|
|
@@ -3902,10 +4964,46 @@ function buildDebugDataObject(t, node, fileId, sourceUrlRef, sourceContentRef, t
|
|
|
3902
4964
|
t.objectProperty(t.identifier("fields"), buildFields(t, styleArg)),
|
|
3903
4965
|
t.objectProperty(t.identifier("vars"), buildVars(t, styleArg, fileId, tokenNameFormat))
|
|
3904
4966
|
];
|
|
4967
|
+
if (classNameArg) properties.push(t.objectProperty(t.identifier("classNames"), buildClassNames(t, node.arguments)));
|
|
3905
4968
|
properties.push(t.objectProperty(t.identifier("sourceUrl"), sourceUrlRef));
|
|
3906
4969
|
if (sourceContentRef) properties.push(t.objectProperty(t.identifier("code"), sourceContentRef));
|
|
3907
4970
|
return t.objectExpression(properties);
|
|
3908
4971
|
}
|
|
4972
|
+
function buildClassNames(t, args) {
|
|
4973
|
+
const classNames = /* @__PURE__ */ new Map();
|
|
4974
|
+
for (const arg of args) collectClassNameLoc(arg, classNames);
|
|
4975
|
+
const fields = [];
|
|
4976
|
+
for (const [className, loc] of classNames) fields.push(t.objectProperty(t.stringLiteral(className), buildLoc(t, loc.line, loc.column + 1)));
|
|
4977
|
+
return t.objectExpression(fields);
|
|
4978
|
+
}
|
|
4979
|
+
function collectClassNameLoc(arg, classNames) {
|
|
4980
|
+
if (!arg) return;
|
|
4981
|
+
if (arg.type === "StringLiteral") {
|
|
4982
|
+
const loc = arg.loc?.start;
|
|
4983
|
+
if (loc) classNames.set(arg.value, loc);
|
|
4984
|
+
return;
|
|
4985
|
+
}
|
|
4986
|
+
if (arg.type === "TemplateLiteral" && arg.expressions.length === 0) {
|
|
4987
|
+
const loc = arg.loc?.start;
|
|
4988
|
+
if (loc) classNames.set(arg.quasis[0]?.value.cooked ?? arg.quasis[0]?.value.raw ?? "", loc);
|
|
4989
|
+
return;
|
|
4990
|
+
}
|
|
4991
|
+
if (arg.type === "ArrayExpression") {
|
|
4992
|
+
for (const item of arg.elements) collectClassNameLoc(item, classNames);
|
|
4993
|
+
return;
|
|
4994
|
+
}
|
|
4995
|
+
if (arg.type === "ConditionalExpression") {
|
|
4996
|
+
collectClassNameLoc(arg.consequent, classNames);
|
|
4997
|
+
collectClassNameLoc(arg.alternate, classNames);
|
|
4998
|
+
return;
|
|
4999
|
+
}
|
|
5000
|
+
if (arg.type === "LogicalExpression") {
|
|
5001
|
+
collectClassNameLoc(arg.left, classNames);
|
|
5002
|
+
collectClassNameLoc(arg.right, classNames);
|
|
5003
|
+
return;
|
|
5004
|
+
}
|
|
5005
|
+
if (arg.type === "CallExpression" && arg.callee.type === "MemberExpression" && arg.callee.property.type === "Identifier" && arg.callee.property.name === "weight") collectClassNameLoc(arg.arguments[0], classNames);
|
|
5006
|
+
}
|
|
3909
5007
|
function getShortLabel(label) {
|
|
3910
5008
|
const parts = label.split(".");
|
|
3911
5009
|
return parts[parts.length - 1] || label;
|
|
@@ -4064,7 +5162,9 @@ function createDebugPlugin(args) {
|
|
|
4064
5162
|
if (hasDebugArgument(path.node.arguments)) return;
|
|
4065
5163
|
const sourceUrlRef = getSourceUrlId(t, state);
|
|
4066
5164
|
const sourceContentRef = sourceContent ? getSourceContentId(t, state) : null;
|
|
4067
|
-
|
|
5165
|
+
const rootName = getStyleChainRootName(path.node.callee, state.styleNames);
|
|
5166
|
+
const isClassNameCall = rootName ? state.styleMetas.get(rootName)?.mode === "ClassName" : false;
|
|
5167
|
+
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));
|
|
4068
5168
|
},
|
|
4069
5169
|
JSXOpeningElement(path, state) {
|
|
4070
5170
|
if (options.dev?.elementClassName === false) return;
|
|
@@ -4254,14 +5354,16 @@ function getSelectorMethodPath(path) {
|
|
|
4254
5354
|
function getDebugStyleArg(t, path, state, sourcemapTrace) {
|
|
4255
5355
|
const arg = getStyleObjectArg(path, state);
|
|
4256
5356
|
if (!arg) return arg;
|
|
5357
|
+
const meta = getStyleCallMeta(path, state);
|
|
4257
5358
|
if (arg.type !== "ObjectExpression") return resolveDebugMergeObject(t, arg, path, state, sourcemapTrace) ?? arg;
|
|
4258
|
-
return flattenDebugObjectExpression(t, arg, path, state, sourcemapTrace, /* @__PURE__ */ new Set());
|
|
5359
|
+
return appendTransformDebugFieldAliases(t, flattenDebugObjectExpression(t, arg, path, state, sourcemapTrace, /* @__PURE__ */ new Set()), meta, state);
|
|
4259
5360
|
}
|
|
4260
5361
|
function getDebugCallLoc(path, state) {
|
|
4261
5362
|
return isSelectorStyleCall(path, state) || isScopeItemSelectorCall(path, state) ? getMergeStyleLoc(path.node.callee) : null;
|
|
4262
5363
|
}
|
|
4263
5364
|
function getStyleObjectArg(path, state) {
|
|
4264
5365
|
const methodName = getSelectorMethodName(path.node.callee);
|
|
5366
|
+
if (methodName === "selector") return path.node.arguments[1];
|
|
4265
5367
|
const rootName = getStyleChainRootName(path.node.callee, state.styleNames);
|
|
4266
5368
|
const selector = methodName && rootName ? state.styleMetas.get(rootName)?.selectors[methodName] : null;
|
|
4267
5369
|
if (!selector) return path.node.arguments[0];
|
|
@@ -4269,6 +5371,10 @@ function getStyleObjectArg(path, state) {
|
|
|
4269
5371
|
const styleArgIndex = selectorArgIndex === null ? 0 : selectorArgIndex + 1;
|
|
4270
5372
|
return path.node.arguments[styleArgIndex];
|
|
4271
5373
|
}
|
|
5374
|
+
function getStyleCallMeta(path, state) {
|
|
5375
|
+
const rootName = getStyleChainRootName(path.node.callee, state.styleNames);
|
|
5376
|
+
return rootName ? state.styleMetas.get(rootName) ?? null : null;
|
|
5377
|
+
}
|
|
4272
5378
|
function isSelectorStyleCall(path, state) {
|
|
4273
5379
|
const methodName = getSelectorMethodName(path.node.callee);
|
|
4274
5380
|
if (!methodName) return false;
|
|
@@ -4373,6 +5479,46 @@ function flattenDebugObjectExpression(t, node, path, state, sourcemapTrace, seen
|
|
|
4373
5479
|
}
|
|
4374
5480
|
return t.objectExpression(properties);
|
|
4375
5481
|
}
|
|
5482
|
+
function appendTransformDebugFieldAliases(t, node, meta, state) {
|
|
5483
|
+
if (!meta || meta.mode !== "StyleObject" || !meta.transform) return node;
|
|
5484
|
+
const existing = /* @__PURE__ */ new Set();
|
|
5485
|
+
for (const property of node.properties) {
|
|
5486
|
+
if (property.type !== "ObjectProperty" || property.computed) continue;
|
|
5487
|
+
const key = getObjectPropertyKey$1(property);
|
|
5488
|
+
if (key) existing.add(key);
|
|
5489
|
+
}
|
|
5490
|
+
const aliases = [];
|
|
5491
|
+
for (const property of node.properties) {
|
|
5492
|
+
if (property.type !== "ObjectProperty" || property.computed) continue;
|
|
5493
|
+
const key = getObjectPropertyKey$1(property);
|
|
5494
|
+
if (!key) continue;
|
|
5495
|
+
const value = evaluateNode(property.value, getDebugEvalScope(state));
|
|
5496
|
+
if (!value.ok) continue;
|
|
5497
|
+
let transformed;
|
|
5498
|
+
try {
|
|
5499
|
+
transformed = meta.transform.transform({ [key]: value.value });
|
|
5500
|
+
} catch {
|
|
5501
|
+
continue;
|
|
5502
|
+
}
|
|
5503
|
+
for (const transformedKey of Object.keys(transformed)) {
|
|
5504
|
+
if (existing.has(transformedKey)) continue;
|
|
5505
|
+
existing.add(transformedKey);
|
|
5506
|
+
aliases.push(createDebugFieldAlias(t, transformedKey, property));
|
|
5507
|
+
}
|
|
5508
|
+
}
|
|
5509
|
+
if (!aliases.length) return node;
|
|
5510
|
+
return t.objectExpression([...node.properties, ...aliases]);
|
|
5511
|
+
}
|
|
5512
|
+
function createDebugFieldAlias(t, key, source) {
|
|
5513
|
+
const alias = t.objectProperty(t.stringLiteral(key), t.nullLiteral());
|
|
5514
|
+
const sourceTrace = source;
|
|
5515
|
+
alias.loc = source.loc;
|
|
5516
|
+
alias.__styleSourcemapStyleLoc = sourceTrace.__styleSourcemapStyleLoc;
|
|
5517
|
+
alias.__styleSourcemapStyleSourceUrl = sourceTrace.__styleSourcemapStyleSourceUrl;
|
|
5518
|
+
alias.__styleSourcemapValueLoc = sourceTrace.__styleSourcemapValueLoc;
|
|
5519
|
+
alias.__styleSourcemapValueSourceUrl = sourceTrace.__styleSourcemapValueSourceUrl;
|
|
5520
|
+
return alias;
|
|
5521
|
+
}
|
|
4376
5522
|
function resolveDebugSpreadObject(t, spread, path, state, sourcemapTrace, seen) {
|
|
4377
5523
|
const node = spread.argument;
|
|
4378
5524
|
if (node.type !== "Identifier") return null;
|
|
@@ -4642,7 +5788,7 @@ function transformDebug(internal, args, deps) {
|
|
|
4642
5788
|
code: args.code,
|
|
4643
5789
|
filePath: args.filePath,
|
|
4644
5790
|
sourcemap: args.sourcemap,
|
|
4645
|
-
plugins: [plugin],
|
|
5791
|
+
plugins: [plugin, createCssPropPlugin({ options })],
|
|
4646
5792
|
retainLines: true
|
|
4647
5793
|
});
|
|
4648
5794
|
if (!result) return null;
|
|
@@ -4655,6 +5801,12 @@ function transformDebug(internal, args, deps) {
|
|
|
4655
5801
|
//#region compiler/utils/file_resolver.ts
|
|
4656
5802
|
const contentCache = /* @__PURE__ */ new Map();
|
|
4657
5803
|
const resolver = new oxc_resolver.ResolverFactory({
|
|
5804
|
+
conditionNames: [
|
|
5805
|
+
"import",
|
|
5806
|
+
"module",
|
|
5807
|
+
"default",
|
|
5808
|
+
"types"
|
|
5809
|
+
],
|
|
4658
5810
|
extensions: [
|
|
4659
5811
|
".ts",
|
|
4660
5812
|
".tsx",
|
|
@@ -4665,7 +5817,8 @@ const resolver = new oxc_resolver.ResolverFactory({
|
|
|
4665
5817
|
".mts",
|
|
4666
5818
|
".cts"
|
|
4667
5819
|
],
|
|
4668
|
-
mainFiles: ["index"]
|
|
5820
|
+
mainFiles: ["index"],
|
|
5821
|
+
tsconfig: "auto"
|
|
4669
5822
|
});
|
|
4670
5823
|
function clearResolverCache() {
|
|
4671
5824
|
contentCache.clear();
|
|
@@ -4705,59 +5858,9 @@ function resolveFilePath(source, fromFile) {
|
|
|
4705
5858
|
}
|
|
4706
5859
|
}
|
|
4707
5860
|
//#endregion
|
|
4708
|
-
//#region atomic/rule.ts
|
|
4709
|
-
function buildAtomicRule(className, property, value, selector, parentSelector, atRules, scopeClassNameFormat) {
|
|
4710
|
-
const cssProp = getCssPropertyName(property);
|
|
4711
|
-
const cssValue = getCssPropertyValue(property, value);
|
|
4712
|
-
const classSelector = "." + escapeCssIdent(className);
|
|
4713
|
-
const itemSelector = selector ? getSelectorText(selector) : "";
|
|
4714
|
-
let selectorStr = classSelector + itemSelector;
|
|
4715
|
-
if (parentSelector) {
|
|
4716
|
-
const parentWhere = `:where(${"." + escapeCssIdent(getScopeClassName(className, scopeClassNameFormat)) + getSelectorText(parentSelector)})`;
|
|
4717
|
-
selectorStr = classSelector + parentWhere + itemSelector + "," + parentWhere + " " + selectorStr;
|
|
4718
|
-
}
|
|
4719
|
-
let rule = `${selectorStr}{${cssProp}: ${cssValue}}`;
|
|
4720
|
-
if (atRules) for (let i = atRules.length - 1; i >= 0; i--) rule = `${getSelectorText(atRules[i])}{${rule}}`;
|
|
4721
|
-
return rule;
|
|
4722
|
-
}
|
|
4723
|
-
function getAtomicRuleLayerPriority(property, priority, selector, parentSelector, atRules, isScopeRule = false) {
|
|
4724
|
-
const selectorPriority = getSelectorPriority(selector);
|
|
4725
|
-
const parentSelectorPriority = getSelectorPriority(parentSelector);
|
|
4726
|
-
const atRulePriority = getAtRulePriority$1(atRules);
|
|
4727
|
-
return [
|
|
4728
|
-
priority ?? 0,
|
|
4729
|
-
getLayerSelectorPriority(selector, parentSelector, selectorPriority),
|
|
4730
|
-
getParentSelectorPriority(parentSelector, parentSelectorPriority),
|
|
4731
|
-
getMediaPriority(atRules, atRulePriority),
|
|
4732
|
-
atRules ? atRules.length : 0,
|
|
4733
|
-
isScopeRule && !parentSelector ? 1 : 0,
|
|
4734
|
-
getPropertyPriority(property)
|
|
4735
|
-
];
|
|
4736
|
-
}
|
|
4737
|
-
function getMediaPriority(atRules, priority) {
|
|
4738
|
-
if (!atRules?.length) return LayerMediaPriorities.base;
|
|
4739
|
-
if (priority <= 0) return LayerMediaPriorities.media;
|
|
4740
|
-
return LayerMediaPriorities.priorityMedia + priority;
|
|
4741
|
-
}
|
|
4742
|
-
function getLayerSelectorPriority(selector, parentSelector, priority) {
|
|
4743
|
-
if (selector) return priority > 0 ? LayerSelectorPriorities.prioritySelector + priority : LayerSelectorPriorities.selector;
|
|
4744
|
-
if (parentSelector) return LayerSelectorPriorities.parentSelector;
|
|
4745
|
-
return LayerSelectorPriorities.base;
|
|
4746
|
-
}
|
|
4747
|
-
function getParentSelectorPriority(parentSelector, priority) {
|
|
4748
|
-
if (!parentSelector) return 0;
|
|
4749
|
-
return priority > 0 ? priority + 1 : 1;
|
|
4750
|
-
}
|
|
4751
|
-
function getAtRulePriority$1(atRules) {
|
|
4752
|
-
if (!atRules?.length) return 0;
|
|
4753
|
-
let priority = 0;
|
|
4754
|
-
for (let i = 0, len = atRules.length; i < len; i++) priority = Math.max(priority, getSelectorPriority(atRules[i]));
|
|
4755
|
-
return priority;
|
|
4756
|
-
}
|
|
4757
|
-
//#endregion
|
|
4758
5861
|
//#region compiler/transform/extract/chain/extract_chain.ts
|
|
4759
5862
|
const STATIC_MERGE_METHOD = "$$style.merge";
|
|
4760
|
-
function extractStyleChain(node, styleNames) {
|
|
5863
|
+
function extractStyleChain(node, styleNames, sheetNames = /* @__PURE__ */ new Set()) {
|
|
4761
5864
|
if (node.type !== "CallExpression") return null;
|
|
4762
5865
|
const callee = node.callee;
|
|
4763
5866
|
if (callee.type === "Identifier" && styleNames.has(callee.name)) return {
|
|
@@ -4766,6 +5869,12 @@ function extractStyleChain(node, styleNames) {
|
|
|
4766
5869
|
baseArgs: node.arguments,
|
|
4767
5870
|
methods: []
|
|
4768
5871
|
};
|
|
5872
|
+
if (callee.type === "Identifier" && sheetNames.has(callee.name)) return {
|
|
5873
|
+
kind: "sheet",
|
|
5874
|
+
rootName: callee.name,
|
|
5875
|
+
baseArgs: node.arguments,
|
|
5876
|
+
methods: []
|
|
5877
|
+
};
|
|
4769
5878
|
if (callee.type === "MemberExpression" && !callee.computed) {
|
|
4770
5879
|
const prop = callee.property.type === "Identifier" ? callee.property.name : null;
|
|
4771
5880
|
if (!prop) return null;
|
|
@@ -4783,10 +5892,16 @@ function extractStyleChain(node, styleNames) {
|
|
|
4783
5892
|
baseArgs: node.arguments,
|
|
4784
5893
|
methods: []
|
|
4785
5894
|
};
|
|
5895
|
+
if (prop === "selector") return {
|
|
5896
|
+
kind: "selector",
|
|
5897
|
+
rootName: obj.name,
|
|
5898
|
+
baseArgs: node.arguments,
|
|
5899
|
+
methods: []
|
|
5900
|
+
};
|
|
4786
5901
|
if (prop !== "merge") return null;
|
|
4787
5902
|
const target = node.arguments[0];
|
|
4788
5903
|
if (!target) return null;
|
|
4789
|
-
const targetChain = extractStyleChain(target, styleNames);
|
|
5904
|
+
const targetChain = extractStyleChain(target, styleNames, sheetNames);
|
|
4790
5905
|
if (!targetChain) return null;
|
|
4791
5906
|
return {
|
|
4792
5907
|
...targetChain,
|
|
@@ -4798,7 +5913,7 @@ function extractStyleChain(node, styleNames) {
|
|
|
4798
5913
|
};
|
|
4799
5914
|
}
|
|
4800
5915
|
if (obj.type === "CallExpression") {
|
|
4801
|
-
const inner = extractStyleChain(obj, styleNames);
|
|
5916
|
+
const inner = extractStyleChain(obj, styleNames, sheetNames);
|
|
4802
5917
|
if (!inner) return null;
|
|
4803
5918
|
return {
|
|
4804
5919
|
...inner,
|
|
@@ -4814,15 +5929,113 @@ function extractStyleChain(node, styleNames) {
|
|
|
4814
5929
|
}
|
|
4815
5930
|
//#endregion
|
|
4816
5931
|
//#region compiler/transform/extract/chain/chain.ts
|
|
4817
|
-
function applyTransform(styleObj, transform) {
|
|
4818
|
-
|
|
5932
|
+
function applyTransform(styleObj, transform, cssConfig) {
|
|
5933
|
+
if (!transform) return styleObj;
|
|
5934
|
+
const input = transformRuntimeValues(styleObj, transform, cssConfig);
|
|
5935
|
+
return carryTransformedLocations(input, transform.transform(input), transform);
|
|
5936
|
+
}
|
|
5937
|
+
function transformRuntimeValues(styleObj, transform, cssConfig) {
|
|
5938
|
+
let result = null;
|
|
5939
|
+
for (const [property, rawValue] of Object.entries(styleObj)) {
|
|
5940
|
+
const weighted = isStyleWeightValue(rawValue) ? rawValue : null;
|
|
5941
|
+
const runtimeValue = getCompiledRuntimeValue(weighted ? weighted.value : rawValue);
|
|
5942
|
+
if (!runtimeValue) continue;
|
|
5943
|
+
const transformedRuntimeValue = transformRuntimeExpression(property, runtimeValue, transform, cssConfig);
|
|
5944
|
+
if (transformedRuntimeValue === runtimeValue) continue;
|
|
5945
|
+
result ??= cloneCompiledStyleObject(styleObj);
|
|
5946
|
+
const transformed = createCompiledRuntimeValue(transformedRuntimeValue);
|
|
5947
|
+
result[property] = weighted ? weightValue(transformed, weighted.weight) : transformed;
|
|
5948
|
+
}
|
|
5949
|
+
return result ?? styleObj;
|
|
5950
|
+
}
|
|
5951
|
+
function cloneCompiledStyleObject(styleObj) {
|
|
5952
|
+
const cloned = { ...styleObj };
|
|
5953
|
+
const locations = styleObj[COMPILED_STYLE_OBJECT_LOCATIONS];
|
|
5954
|
+
if (locations) Object.defineProperty(cloned, COMPILED_STYLE_OBJECT_LOCATIONS, {
|
|
5955
|
+
configurable: true,
|
|
5956
|
+
enumerable: false,
|
|
5957
|
+
value: locations
|
|
5958
|
+
});
|
|
5959
|
+
return cloned;
|
|
5960
|
+
}
|
|
5961
|
+
function createCompiledRuntimeValue(runtimeValue) {
|
|
5962
|
+
return { [COMPILED_RUNTIME_VALUE]: runtimeValue };
|
|
5963
|
+
}
|
|
5964
|
+
function transformRuntimeExpression(property, expression, transform, cssConfig) {
|
|
5965
|
+
if (expression.type === "StringLiteral") return createPrimitiveExpression(expression, normalizeRuntimeTransformedValue(getSingleTransformedValue(transform.transform({ [property]: expression.value })), cssConfig)) ?? expression;
|
|
5966
|
+
if (expression.type === "ConditionalExpression") {
|
|
5967
|
+
const consequent = transformRuntimeExpression(property, expression.consequent, transform, cssConfig);
|
|
5968
|
+
const alternate = transformRuntimeExpression(property, expression.alternate, transform, cssConfig);
|
|
5969
|
+
return consequent === expression.consequent && alternate === expression.alternate ? expression : {
|
|
5970
|
+
...expression,
|
|
5971
|
+
consequent,
|
|
5972
|
+
alternate
|
|
5973
|
+
};
|
|
5974
|
+
}
|
|
5975
|
+
return expression;
|
|
5976
|
+
}
|
|
5977
|
+
function getSingleTransformedValue(transformed) {
|
|
5978
|
+
const values = Object.values(transformed);
|
|
5979
|
+
if (!values.length) return void 0;
|
|
5980
|
+
return values[0];
|
|
5981
|
+
}
|
|
5982
|
+
function normalizeRuntimeTransformedValue(value, cssConfig) {
|
|
5983
|
+
if (isStyleTokenOverrideData(value)) return getTokenOverrideValue(value, cssConfig.tokenNameFormat);
|
|
5984
|
+
if (isStyleTokenData(value)) return getTokenVar(value, cssConfig.tokenNameFormat);
|
|
5985
|
+
return value;
|
|
5986
|
+
}
|
|
5987
|
+
function createPrimitiveExpression(original, value) {
|
|
5988
|
+
if (original.type === "StringLiteral" && value === original.value) return null;
|
|
5989
|
+
if (typeof value === "string") return {
|
|
5990
|
+
...original,
|
|
5991
|
+
type: "StringLiteral",
|
|
5992
|
+
value
|
|
5993
|
+
};
|
|
5994
|
+
if (typeof value === "number") return {
|
|
5995
|
+
...original,
|
|
5996
|
+
type: "NumericLiteral",
|
|
5997
|
+
value
|
|
5998
|
+
};
|
|
5999
|
+
if (typeof value === "boolean") return {
|
|
6000
|
+
...original,
|
|
6001
|
+
type: "BooleanLiteral",
|
|
6002
|
+
value
|
|
6003
|
+
};
|
|
6004
|
+
if (value === null) return {
|
|
6005
|
+
...original,
|
|
6006
|
+
type: "NullLiteral"
|
|
6007
|
+
};
|
|
6008
|
+
return null;
|
|
6009
|
+
}
|
|
6010
|
+
function carryTransformedLocations(input, transformed, transform) {
|
|
6011
|
+
const inputLocations = input[COMPILED_STYLE_OBJECT_LOCATIONS];
|
|
6012
|
+
if (!inputLocations) return transformed;
|
|
6013
|
+
const locations = { ...transformed[COMPILED_STYLE_OBJECT_LOCATIONS] };
|
|
6014
|
+
for (const [property, loc] of Object.entries(inputLocations)) {
|
|
6015
|
+
if (property in transformed && !locations[property]) locations[property] = loc;
|
|
6016
|
+
const single = transform.transform({ [property]: input[property] });
|
|
6017
|
+
for (const transformedProperty of Object.keys(single)) locations[transformedProperty] ??= loc;
|
|
6018
|
+
}
|
|
6019
|
+
if (!Object.keys(locations).length) return transformed;
|
|
6020
|
+
Object.defineProperty(transformed, COMPILED_STYLE_OBJECT_LOCATIONS, {
|
|
6021
|
+
configurable: true,
|
|
6022
|
+
enumerable: false,
|
|
6023
|
+
value: locations
|
|
6024
|
+
});
|
|
6025
|
+
return transformed;
|
|
4819
6026
|
}
|
|
4820
6027
|
/**
|
|
4821
6028
|
* Compile a parsed chain into extracted items and CSS rules.
|
|
4822
6029
|
* Returns null if any argument cannot be statically evaluated.
|
|
4823
6030
|
*/
|
|
4824
|
-
function compileChain(chain, fileId, nodeLoc, scope, opts, meta, styleNames = /* @__PURE__ */ new Set()) {
|
|
4825
|
-
const css = getCssConfig(opts);
|
|
6031
|
+
function compileChain(chain, fileId, nodeLoc, scope, opts, runtimeMode, meta, styleNames = /* @__PURE__ */ new Set()) {
|
|
6032
|
+
const css = getCssConfig(opts, runtimeMode);
|
|
6033
|
+
if (chain.kind === "sheet") return compileSheetChain(chain, fileId, scope, css, opts);
|
|
6034
|
+
if (!meta) return null;
|
|
6035
|
+
if (meta.mode === "ClassName") {
|
|
6036
|
+
if (chain.kind !== "style") return null;
|
|
6037
|
+
return compileClassNameChain(chain, meta.selectors, fileId, nodeLoc, scope, css, meta.transform, styleNames, opts);
|
|
6038
|
+
}
|
|
4826
6039
|
const selectors = meta.selectors;
|
|
4827
6040
|
const transform = meta.transform;
|
|
4828
6041
|
if (chain.kind === "style") return compileStyleChain(chain, selectors, fileId, scope, css, transform, styleNames, opts);
|
|
@@ -4830,13 +6043,120 @@ function compileChain(chain, fileId, nodeLoc, scope, opts, meta, styleNames = /*
|
|
|
4830
6043
|
if (chain.kind === "scope") return compileScopeChain(chain, selectors, fileId, scope, css, transform, opts);
|
|
4831
6044
|
return null;
|
|
4832
6045
|
}
|
|
4833
|
-
function
|
|
6046
|
+
function compileSheetChain(chain, fileId, scope, cssConfig, options) {
|
|
6047
|
+
if (chain.methods.length > 0 || chain.baseArgs.length > 2) return null;
|
|
6048
|
+
const items = [];
|
|
6049
|
+
const rules = [];
|
|
6050
|
+
const hasOptions = chain.baseArgs.length === 2;
|
|
6051
|
+
const sheetOptions = hasOptions ? evaluateCreateSheetOptions(chain.baseArgs[0], scope) : {};
|
|
6052
|
+
if (!sheetOptions) return null;
|
|
6053
|
+
const sheetItems = chain.baseArgs[hasOptions ? 1 : 0];
|
|
6054
|
+
if (sheetItems && !compileSheetItemsArg(sheetItems, fileId, scope, cssConfig, options, items, rules, sheetOptions)) return null;
|
|
6055
|
+
const sheetLayer = sheetOptions.layer ?? isSheetLayerEnabled(options.css?.layer ?? DEFAULT_CONFIG.layer);
|
|
6056
|
+
for (let i = 0, len = rules.length; i < len; i++) rules[i].layer = sheetLayer ? "sheet" : false;
|
|
6057
|
+
return {
|
|
6058
|
+
type: "sheet",
|
|
6059
|
+
items,
|
|
6060
|
+
rules,
|
|
6061
|
+
sheetOptions
|
|
6062
|
+
};
|
|
6063
|
+
}
|
|
6064
|
+
function evaluateCreateSheetOptions(node, scope) {
|
|
6065
|
+
const result = evaluateNode(node, scope);
|
|
6066
|
+
if (!result.ok || !result.value || typeof result.value !== "object" || Array.isArray(result.value)) return null;
|
|
6067
|
+
const value = result.value;
|
|
6068
|
+
if (Object.keys(value).some((key) => key !== "layer" && key !== "weight")) return null;
|
|
6069
|
+
if (value.layer !== void 0 && typeof value.layer !== "boolean") return null;
|
|
6070
|
+
if (value.weight !== void 0 && (!Number.isInteger(value.weight) || value.weight < 1)) return null;
|
|
6071
|
+
return {
|
|
6072
|
+
layer: value.layer,
|
|
6073
|
+
weight: value.weight
|
|
6074
|
+
};
|
|
6075
|
+
}
|
|
6076
|
+
function compileSheetItemsArg(node, fileId, scope, cssConfig, options, items, rules, sheetOptions) {
|
|
6077
|
+
if (node.type === "ArrayExpression") {
|
|
6078
|
+
for (const element of node.elements) {
|
|
6079
|
+
if (!element) continue;
|
|
6080
|
+
if (element.type === "SpreadElement") return false;
|
|
6081
|
+
if (!compileSheetItemsArg(element, fileId, scope, cssConfig, options, items, rules, sheetOptions)) return false;
|
|
6082
|
+
}
|
|
6083
|
+
return true;
|
|
6084
|
+
}
|
|
6085
|
+
const tokenOverride = evaluateNode(node, scope);
|
|
6086
|
+
if (tokenOverride.ok && isStyleTokenOverrideData(tokenOverride.value)) {
|
|
6087
|
+
addCompiledTokenItem(getStyleTokenId(tokenOverride.value), tokenOverride.value, getCompiledRuntimeValue(tokenOverride.value) ?? node, items);
|
|
6088
|
+
return true;
|
|
6089
|
+
}
|
|
6090
|
+
if (tokenOverride.ok && Array.isArray(tokenOverride.value)) {
|
|
6091
|
+
for (let i = 0, len = tokenOverride.value.length; i < len; i++) {
|
|
6092
|
+
const item = tokenOverride.value[i];
|
|
6093
|
+
if (!item) continue;
|
|
6094
|
+
if (!isStyleTokenOverrideData(item)) return false;
|
|
6095
|
+
addCompiledTokenItem(getStyleTokenId(item), item, getCompiledRuntimeValue(item) ?? null, items);
|
|
6096
|
+
}
|
|
6097
|
+
return true;
|
|
6098
|
+
}
|
|
6099
|
+
const styleNames = scope.styleNames ?? /* @__PURE__ */ new Set();
|
|
6100
|
+
const sheetNames = scope.sheetNames ?? /* @__PURE__ */ new Set();
|
|
6101
|
+
const selectorChain = node.type === "CallExpression" ? extractStyleChain(node, styleNames, sheetNames) ?? getLocalSelectorTargetChain(node, scope, styleNames, sheetNames) : getLocalStyleChainArg(node, scope, styleNames, sheetNames);
|
|
6102
|
+
const selectorMeta = selectorChain ? scope.styleMetas?.get(selectorChain.rootName) : null;
|
|
6103
|
+
if (selectorChain?.kind !== "selector" || !selectorMeta || selectorMeta.mode !== "StyleObject") return false;
|
|
6104
|
+
return compileSelectorOverrideChain(selectorChain, selectorMeta.selectors, fileId, scope, cssConfig, selectorMeta.transform, scope.styleNames ?? /* @__PURE__ */ new Set(), options, items, rules, sheetOptions);
|
|
6105
|
+
}
|
|
6106
|
+
function compileSelectorOverrideChain(chain, selectors, fileId, scope, cssConfig, transform, styleNames, options, items, rules, sheetOptions) {
|
|
6107
|
+
if (chain.baseArgs.length === 0 || chain.baseArgs.length > 2) return false;
|
|
6108
|
+
const selectorArg = evaluateNode(chain.baseArgs[0], scope);
|
|
6109
|
+
if (!selectorArg.ok) return false;
|
|
6110
|
+
const manualSelectors = normalizeManualSelectors(Array.isArray(selectorArg.value) ? selectorArg.value.map(String) : String(selectorArg.value ?? ""));
|
|
6111
|
+
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;
|
|
6112
|
+
return true;
|
|
6113
|
+
}
|
|
6114
|
+
function compileSelectorOverrideInto(chain, selectors, fileId, scope, cssConfig, transform, styleNames, options, items, rules, selectorPrefix) {
|
|
6115
|
+
if (chain.baseArgs[1]) {
|
|
6116
|
+
if (!compileSelectorStyleArg(chain.baseArgs[1], fileId, scope, cssConfig, transform, items, rules, styleNames, options, selectorPrefix)) return false;
|
|
6117
|
+
}
|
|
6118
|
+
let i = 0;
|
|
6119
|
+
while (i < chain.methods.length) {
|
|
6120
|
+
const method = chain.methods[i];
|
|
6121
|
+
if (!compileChainMethod(method, selectors, null, fileId, scope, 1, cssConfig, items, rules, transform, null, styleNames, options, null, selectorPrefix)) return false;
|
|
6122
|
+
i++;
|
|
6123
|
+
}
|
|
6124
|
+
return true;
|
|
6125
|
+
}
|
|
6126
|
+
function compileSelectorStyleArg(styleArgNode, fileId, scope, cssConfig, transform, items, rules, styleNames, options, selectorPrefix) {
|
|
6127
|
+
const localChain = getLocalStyleChainArg(styleArgNode, scope, styleNames);
|
|
6128
|
+
const localMeta = localChain ? scope.styleMetas?.get(localChain.rootName) : null;
|
|
6129
|
+
if (localChain?.kind === "style" && localMeta) return compileStyleChainInto(localChain, localMeta.selectors, fileId, scope, cssConfig, localMeta.transform, 1, null, null, items, rules, styleNames, options, null, selectorPrefix);
|
|
6130
|
+
if (styleArgNode.type === "CallExpression") {
|
|
6131
|
+
const nestedChain = extractStyleChain(styleArgNode, styleNames);
|
|
6132
|
+
const nestedMeta = nestedChain ? scope.styleMetas?.get(nestedChain.rootName) : null;
|
|
6133
|
+
if (nestedChain?.kind === "style" && nestedMeta) return compileStyleChainInto(nestedChain, nestedMeta.selectors, fileId, scope, cssConfig, nestedMeta.transform, 1, null, null, items, rules, styleNames, options, null, selectorPrefix);
|
|
6134
|
+
}
|
|
6135
|
+
const styleArg = evaluateNode(styleArgNode, scope);
|
|
6136
|
+
if (!styleArg.ok) {
|
|
6137
|
+
throwIfRequiredStaticStyleValue(styleArg);
|
|
6138
|
+
return false;
|
|
6139
|
+
}
|
|
6140
|
+
if (isStyleData(styleArg.value)) return addStyleDataItems(styleArg.value, selectorPrefix, null, null, fileId, 1, null, items, rules, cssConfig, null);
|
|
6141
|
+
return addStyleItems(applyTransform(styleArg.value, transform, cssConfig), selectorPrefix, null, null, fileId, 1, null, items, rules, cssConfig, null);
|
|
6142
|
+
}
|
|
6143
|
+
function getCssConfig(opts, runtimeMode) {
|
|
4834
6144
|
const css = opts.css;
|
|
6145
|
+
const isDevRuntimeMode = runtimeMode === "dev" || runtimeMode === "rsc-dev";
|
|
6146
|
+
const debugClassName = css?.debugClassName ?? isDevRuntimeMode;
|
|
4835
6147
|
return {
|
|
4836
6148
|
classNameFormat: css?.classNameFormat ?? DEFAULT_CONFIG.classNameFormat ?? null,
|
|
6149
|
+
sheetClassNameFormat: css?.sheetClassNameFormat ?? DEFAULT_CONFIG.sheetClassNameFormat ?? null,
|
|
6150
|
+
transformClassNameFormat: css?.transformClassNameFormat ?? DEFAULT_CONFIG.transformClassNameFormat ?? null,
|
|
6151
|
+
hashLength: getClassNameHashLength({
|
|
6152
|
+
debugClassName,
|
|
6153
|
+
isDev: isDevRuntimeMode,
|
|
6154
|
+
cssHashLength: css?.hashLength ?? DEFAULT_CONFIG.hashLength
|
|
6155
|
+
}),
|
|
4837
6156
|
tokenNameFormat: css?.tokenNameFormat ?? DEFAULT_CONFIG.tokenNameFormat ?? null,
|
|
4838
|
-
localClassName:
|
|
4839
|
-
debugClassName
|
|
6157
|
+
localClassName: isDevRuntimeMode,
|
|
6158
|
+
debugClassName,
|
|
6159
|
+
runtimeMode,
|
|
4840
6160
|
scopeTargetPrefix: css?.scopeTargetPrefix ?? ""
|
|
4841
6161
|
};
|
|
4842
6162
|
}
|
|
@@ -4854,19 +6174,179 @@ function compileStyleChain(chain, selectors, fileId, scope, cssConfig, transform
|
|
|
4854
6174
|
rules
|
|
4855
6175
|
};
|
|
4856
6176
|
}
|
|
4857
|
-
function
|
|
6177
|
+
function compileClassNameChain(chain, selectors, fileId, nodeLoc, scope, cssConfig, transform, styleNames, options) {
|
|
6178
|
+
const items = [];
|
|
6179
|
+
const rules = [];
|
|
6180
|
+
if (!compileClassNameArgsInto(chain.baseArgs, 0, null, null, fileId, scope, createClassNameFallbackLocation(nodeLoc, scope, fileId), cssConfig, transform, 1, null, items, rules)) return null;
|
|
6181
|
+
let i = 0;
|
|
6182
|
+
while (i < chain.methods.length) {
|
|
6183
|
+
const method = chain.methods[i];
|
|
6184
|
+
if (!compileClassNameChainMethod(method, selectors, fileId, scope, cssConfig, transform, items, rules, styleNames, options)) return null;
|
|
6185
|
+
i++;
|
|
6186
|
+
}
|
|
6187
|
+
return {
|
|
6188
|
+
type: "style",
|
|
6189
|
+
items,
|
|
6190
|
+
rules
|
|
6191
|
+
};
|
|
6192
|
+
}
|
|
6193
|
+
function compileClassNameChainMethod(method, selectors, fileId, scope, cssConfig, transform, items, rules, styleNames, options) {
|
|
6194
|
+
const selector = selectors[method.name];
|
|
6195
|
+
if (!selector) return false;
|
|
6196
|
+
validateSelectorDefinition(options.dev?.checkSelector, `style.${method.name}`, selector, method.nameNode);
|
|
6197
|
+
const selectorStr = selector.selector.trim();
|
|
6198
|
+
if (selectorStr === "...") {
|
|
6199
|
+
const localChain = getLocalStyleChainArg(method.args[0], scope, styleNames);
|
|
6200
|
+
const localMeta = localChain ? scope.styleMetas?.get(localChain.rootName) : null;
|
|
6201
|
+
if (localChain?.kind === "style" && localMeta?.mode === "ClassName") {
|
|
6202
|
+
const result = compileClassNameChain(localChain, localMeta.selectors, fileId, method.nameNode.loc?.start, scope, cssConfig, localMeta.transform, styleNames, options);
|
|
6203
|
+
if (!result) return false;
|
|
6204
|
+
items.push(...result.items);
|
|
6205
|
+
rules.push(...result.rules);
|
|
6206
|
+
return true;
|
|
6207
|
+
}
|
|
6208
|
+
return false;
|
|
6209
|
+
}
|
|
6210
|
+
if (selectorStr.startsWith("@")) {
|
|
6211
|
+
const isMedia = selectorStr.startsWith("@media") || selectorStr.startsWith("@container");
|
|
6212
|
+
const hasArg = selectorStr.includes("$$");
|
|
6213
|
+
const priority = getAtRulePriority(selector.priority, isMedia, method.args[0]);
|
|
6214
|
+
let argOffset = 0;
|
|
6215
|
+
if (isMedia && isNumericLiteral(method.args[0])) argOffset = 1;
|
|
6216
|
+
let atRule = selectorStr;
|
|
6217
|
+
if (hasArg) {
|
|
6218
|
+
const queryArg = evaluateNode(method.args[argOffset], scope);
|
|
6219
|
+
validateResolvedSelectorValue(options.dev?.checkSelector, `style.${method.name}`, selector, queryArg, method.args[argOffset]);
|
|
6220
|
+
throwIfRequiredStaticSelectorValue(options, `style.${method.name}`, queryArg);
|
|
6221
|
+
if (!queryArg.ok) return false;
|
|
6222
|
+
const [before, after] = selectorStr.split("$$");
|
|
6223
|
+
atRule = before + String(queryArg.value) + (after ?? "");
|
|
6224
|
+
}
|
|
6225
|
+
const atRuleSelector = priority !== null ? [atRule, priority] : atRule;
|
|
6226
|
+
const classNameOffset = hasArg ? argOffset + 1 : argOffset;
|
|
6227
|
+
return compileClassNameArgsInto(method.args, classNameOffset, null, [atRuleSelector], fileId, scope, createClassNameFallbackLocation(method.nameNode.loc?.start, scope, fileId), cssConfig, transform, 1, null, items, rules);
|
|
6228
|
+
}
|
|
6229
|
+
if (selectorStr.includes("$$") || selectorStr.includes("$")) {
|
|
6230
|
+
const splitToken = selectorStr.includes("$$") ? "$$" : "$";
|
|
6231
|
+
const [before, after] = selectorStr.split(splitToken);
|
|
6232
|
+
const selectorArg = evaluateNode(method.args[0], scope);
|
|
6233
|
+
validateResolvedSelectorValue(options.dev?.checkSelector, `style.${method.name}`, selector, selectorArg, method.args[0]);
|
|
6234
|
+
if (!selectorArg.ok) return false;
|
|
6235
|
+
const selectorText = before + normalizeSelectorArg(String(selectorArg.value ?? "")) + (after ?? "");
|
|
6236
|
+
const itemSelector = selector.priority !== null ? [selectorText, selector.priority] : selectorText;
|
|
6237
|
+
return compileClassNameArgsInto(method.args, 1, itemSelector, null, fileId, scope, createClassNameFallbackLocation(method.nameNode.loc?.start, scope, fileId), cssConfig, transform, 1, null, items, rules);
|
|
6238
|
+
}
|
|
6239
|
+
const itemSelector = selector.priority !== null ? [selectorStr, selector.priority] : selectorStr;
|
|
6240
|
+
return compileClassNameArgsInto(method.args, 0, itemSelector, null, fileId, scope, createClassNameFallbackLocation(method.nameNode.loc?.start, scope, fileId), cssConfig, transform, 1, null, items, rules);
|
|
6241
|
+
}
|
|
6242
|
+
function compileClassNameArgsInto(args, startIndex, selector, atRules, fileId, scope, fallbackLocation, cssConfig, transform, type, slotId, items, rules) {
|
|
6243
|
+
if (startIndex >= args.length) return true;
|
|
6244
|
+
const styleObj = {};
|
|
6245
|
+
const locations = {};
|
|
6246
|
+
let i = startIndex;
|
|
6247
|
+
while (i < args.length) {
|
|
6248
|
+
const arg = evaluateNode(args[i], scope);
|
|
6249
|
+
if (!arg.ok) {
|
|
6250
|
+
throwIfRequiredStaticStyleValue(arg);
|
|
6251
|
+
return false;
|
|
6252
|
+
}
|
|
6253
|
+
if (!appendClassNameArgStyle(args[i], arg.value, transform, styleObj, locations, fallbackLocation, scope, fileId)) return false;
|
|
6254
|
+
i++;
|
|
6255
|
+
}
|
|
6256
|
+
if (Object.keys(locations).length) Object.defineProperty(styleObj, COMPILED_STYLE_OBJECT_LOCATIONS, {
|
|
6257
|
+
configurable: true,
|
|
6258
|
+
enumerable: false,
|
|
6259
|
+
value: locations
|
|
6260
|
+
});
|
|
6261
|
+
return addStyleItems(styleObj, selector, null, atRules, fileId, type, slotId, items, rules, cssConfig);
|
|
6262
|
+
}
|
|
6263
|
+
function appendClassNameArgStyle(node, value, transform, styleObj, locations, fallbackLocation, scope, fileId) {
|
|
6264
|
+
if (!value) return true;
|
|
6265
|
+
if (typeof value === "string") {
|
|
6266
|
+
const transformed = decorateClassNameStyle(transform.transform(value), value);
|
|
6267
|
+
Object.assign(styleObj, transformed);
|
|
6268
|
+
assignClassNameStyleLocations(transformed, locations, getClassNameArgLocation(node, fallbackLocation, scope, fileId));
|
|
6269
|
+
return true;
|
|
6270
|
+
}
|
|
6271
|
+
if (Array.isArray(value)) {
|
|
6272
|
+
const nodes = node.type === "ArrayExpression" ? node.elements : [];
|
|
6273
|
+
for (let i = 0; i < value.length; i++) if (!appendClassNameArgStyle(nodes[i] ?? node, value[i], transform, styleObj, locations, fallbackLocation, scope, fileId)) return false;
|
|
6274
|
+
return true;
|
|
6275
|
+
}
|
|
6276
|
+
if (isWeightedClassName(value)) {
|
|
6277
|
+
const transformed = decorateClassNameStyle(transform.transform(value.className), value.className);
|
|
6278
|
+
Object.assign(styleObj, applyClassNameWeight(transformed, value.weight));
|
|
6279
|
+
assignClassNameStyleLocations(transformed, locations, getWeightedClassNameArgLocation(node, fallbackLocation, scope, fileId));
|
|
6280
|
+
return true;
|
|
6281
|
+
}
|
|
6282
|
+
return false;
|
|
6283
|
+
}
|
|
6284
|
+
function assignClassNameStyleLocations(styleObj, locations, location) {
|
|
6285
|
+
if (!location) return;
|
|
6286
|
+
for (const property of Object.keys(styleObj)) locations[property] = location;
|
|
6287
|
+
}
|
|
6288
|
+
function getClassNameArgLocation(node, fallbackLocation, scope, fileId) {
|
|
6289
|
+
if (node.type === "StringLiteral") return createClassNameFallbackLocation(node.loc?.start, scope, fileId);
|
|
6290
|
+
if (node.type === "TemplateLiteral" && node.expressions.length === 0) return createClassNameFallbackLocation(node.loc?.start, scope, fileId);
|
|
6291
|
+
return fallbackLocation;
|
|
6292
|
+
}
|
|
6293
|
+
function getWeightedClassNameArgLocation(node, fallbackLocation, scope, fileId) {
|
|
6294
|
+
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);
|
|
6295
|
+
return fallbackLocation;
|
|
6296
|
+
}
|
|
6297
|
+
function createClassNameFallbackLocation(loc, scope, fileId) {
|
|
6298
|
+
if (!loc) return null;
|
|
6299
|
+
return {
|
|
6300
|
+
filePath: scope.styleFilePath ?? fileId,
|
|
6301
|
+
line: loc.line,
|
|
6302
|
+
column: loc.column + 1,
|
|
6303
|
+
variable: false
|
|
6304
|
+
};
|
|
6305
|
+
}
|
|
6306
|
+
function decorateClassNameStyle(style, className) {
|
|
6307
|
+
const result = {};
|
|
6308
|
+
for (const [property, value] of Object.entries(style)) {
|
|
6309
|
+
if (value === null || value === void 0) {
|
|
6310
|
+
result[property] = value;
|
|
6311
|
+
continue;
|
|
6312
|
+
}
|
|
6313
|
+
result[property] = decorateClassNameValue(value, className);
|
|
6314
|
+
}
|
|
6315
|
+
return result;
|
|
6316
|
+
}
|
|
6317
|
+
function decorateClassNameValue(value, className) {
|
|
6318
|
+
if (isClassNameValue(value)) return value;
|
|
6319
|
+
if (isStyleImportantValue(value)) return importantValue(decorateClassNameValue(value.value, className));
|
|
6320
|
+
if (isStyleWeightValue(value)) return weightValue(decorateClassNameValue(value.value, className), value.weight);
|
|
6321
|
+
return classNameValue(value, className);
|
|
6322
|
+
}
|
|
6323
|
+
function isWeightedClassName(value) {
|
|
6324
|
+
return !!value && typeof value === "object" && typeof value.className === "string" && typeof value.weight === "number";
|
|
6325
|
+
}
|
|
6326
|
+
function applyClassNameWeight(style, weight) {
|
|
6327
|
+
const weighted = {};
|
|
6328
|
+
for (const [property, value] of Object.entries(style)) {
|
|
6329
|
+
if (value === null || value === void 0) {
|
|
6330
|
+
weighted[property] = value;
|
|
6331
|
+
continue;
|
|
6332
|
+
}
|
|
6333
|
+
weighted[property] = weightValue(value, weight);
|
|
6334
|
+
}
|
|
6335
|
+
return weighted;
|
|
6336
|
+
}
|
|
6337
|
+
function compileStyleChainInto(chain, selectors, fileId, scope, cssConfig, transform, type, slotId, atRules, items, rules, styleNames, options, callsiteOverride = null, selectorPrefix = null) {
|
|
4858
6338
|
if (chain.baseArgs.length > 0) {
|
|
4859
6339
|
const styleArg = evaluateNode(chain.baseArgs[0], scope);
|
|
4860
6340
|
if (!styleArg.ok) {
|
|
4861
6341
|
throwIfRequiredStaticStyleValue(styleArg);
|
|
4862
6342
|
return false;
|
|
4863
6343
|
}
|
|
4864
|
-
if (!addStyleItems(applyTransform(styleArg.value, transform),
|
|
6344
|
+
if (!addStyleItems(applyTransform(styleArg.value, transform, cssConfig), selectorPrefix, null, atRules, fileId, type, slotId, items, rules, cssConfig, callsiteOverride)) return false;
|
|
4865
6345
|
}
|
|
4866
6346
|
let i = 0;
|
|
4867
6347
|
while (i < chain.methods.length) {
|
|
4868
6348
|
const method = chain.methods[i];
|
|
4869
|
-
if (!compileChainMethod(method, selectors, slotId, fileId, scope, type, cssConfig, items, rules, transform, atRules, styleNames, options, callsiteOverride)) return false;
|
|
6349
|
+
if (!compileChainMethod(method, selectors, slotId, fileId, scope, type, cssConfig, items, rules, transform, atRules, styleNames, options, callsiteOverride, selectorPrefix)) return false;
|
|
4870
6350
|
i++;
|
|
4871
6351
|
}
|
|
4872
6352
|
return true;
|
|
@@ -4880,7 +6360,7 @@ function compileSlotChain(chain, slotId, selectors, fileId, scope, cssConfig, tr
|
|
|
4880
6360
|
throwIfRequiredStaticStyleValue(styleArg);
|
|
4881
6361
|
return null;
|
|
4882
6362
|
}
|
|
4883
|
-
if (!addStyleItems(applyTransform(styleArg.value, transform), null, null, null, fileId, 2, slotId, items, rules, cssConfig)) return null;
|
|
6363
|
+
if (!addStyleItems(applyTransform(styleArg.value, transform, cssConfig), null, null, null, fileId, 2, slotId, items, rules, cssConfig)) return null;
|
|
4884
6364
|
}
|
|
4885
6365
|
let i = 0;
|
|
4886
6366
|
while (i < chain.methods.length) {
|
|
@@ -4913,7 +6393,7 @@ function compileScopeChain(chain, selectors, fileId, scope, cssConfig, transform
|
|
|
4913
6393
|
rules
|
|
4914
6394
|
};
|
|
4915
6395
|
}
|
|
4916
|
-
function compileScopeMethod(method, selectors, fileId, scope, cssConfig, items, cssRules, transform, options, callsiteOverride = null) {
|
|
6396
|
+
function compileScopeMethod(method, selectors, fileId, scope, cssConfig, items, cssRules, transform, options, callsiteOverride = null, _selectorPrefix = null) {
|
|
4917
6397
|
const selector = selectors[method.name];
|
|
4918
6398
|
if (!selector) return false;
|
|
4919
6399
|
validateSelectorDefinition(options.dev?.checkSelector, `style.${method.name}`, selector, method.nameNode);
|
|
@@ -4998,14 +6478,14 @@ function resolveSlotOverrideNode(node, parentSelector, atRules, selectors, fileI
|
|
|
4998
6478
|
return true;
|
|
4999
6479
|
}
|
|
5000
6480
|
if (node.type !== "CallExpression") return false;
|
|
5001
|
-
const overrideChain = extractOverrideChain(node, selectors, scope, fileId, transform, options);
|
|
6481
|
+
const overrideChain = extractOverrideChain(node, selectors, scope, fileId, cssConfig, transform, options);
|
|
5002
6482
|
if (!overrideChain) return false;
|
|
5003
6483
|
const { slotId, items: overrideItems } = overrideChain;
|
|
5004
6484
|
let i = 0;
|
|
5005
6485
|
while (i < overrideItems.length) {
|
|
5006
6486
|
const overrideItem = overrideItems[i];
|
|
5007
6487
|
const mergedAtRules = mergeAtRules(atRules, overrideItem.atRules);
|
|
5008
|
-
if (overrideItem.chain && overrideItem.meta) {
|
|
6488
|
+
if (overrideItem.chain && overrideItem.meta?.mode === "StyleObject") {
|
|
5009
6489
|
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;
|
|
5010
6490
|
} else if (overrideItem.styleData !== void 0) {
|
|
5011
6491
|
if (!addStyleDataItems(overrideItem.styleData, overrideItem.selector, parentSelector, mergedAtRules, fileId, 4, slotId, items, cssRules, cssConfig, overrideItem.callsiteOverride)) return false;
|
|
@@ -5014,15 +6494,15 @@ function resolveSlotOverrideNode(node, parentSelector, atRules, selectors, fileI
|
|
|
5014
6494
|
}
|
|
5015
6495
|
return true;
|
|
5016
6496
|
}
|
|
5017
|
-
function extractOverrideChain(node, selectors, scope, fileId, transform, options) {
|
|
6497
|
+
function extractOverrideChain(node, selectors, scope, fileId, cssConfig, transform, options) {
|
|
5018
6498
|
const callee = node.callee;
|
|
5019
6499
|
if (callee.type === "MemberExpression" && !callee.computed) {
|
|
5020
6500
|
const methodName = callee.property.name;
|
|
5021
6501
|
const obj = callee.object;
|
|
5022
6502
|
if (obj.type === "CallExpression") {
|
|
5023
|
-
const inner = extractOverrideChain(obj, selectors, scope, fileId, transform, options);
|
|
6503
|
+
const inner = extractOverrideChain(obj, selectors, scope, fileId, cssConfig, transform, options);
|
|
5024
6504
|
if (!inner) return null;
|
|
5025
|
-
const overrideItem = resolveOverrideMethod(methodName, node.arguments, callee.property, selectors, scope, transform, options);
|
|
6505
|
+
const overrideItem = resolveOverrideMethod(methodName, node.arguments, callee.property, selectors, scope, cssConfig, transform, options);
|
|
5026
6506
|
if (!overrideItem) return null;
|
|
5027
6507
|
return {
|
|
5028
6508
|
slotId: inner.slotId,
|
|
@@ -5037,7 +6517,7 @@ function extractOverrideChain(node, selectors, scope, fileId, transform, options
|
|
|
5037
6517
|
const styleArg = evaluateNode(node.arguments[0], scope);
|
|
5038
6518
|
if (!styleArg.ok) return null;
|
|
5039
6519
|
items.push({
|
|
5040
|
-
styleObj: applyTransform(styleArg.value ?? {}, transform),
|
|
6520
|
+
styleObj: applyTransform(styleArg.value ?? {}, transform, cssConfig),
|
|
5041
6521
|
selector: null,
|
|
5042
6522
|
atRules: null
|
|
5043
6523
|
});
|
|
@@ -5047,7 +6527,7 @@ function extractOverrideChain(node, selectors, scope, fileId, transform, options
|
|
|
5047
6527
|
items
|
|
5048
6528
|
};
|
|
5049
6529
|
}
|
|
5050
|
-
function resolveOverrideMethod(methodName, args, nameNode, selectors, scope, transform, options) {
|
|
6530
|
+
function resolveOverrideMethod(methodName, args, nameNode, selectors, scope, cssConfig, transform, options) {
|
|
5051
6531
|
const sel = selectors[methodName];
|
|
5052
6532
|
if (!sel) return null;
|
|
5053
6533
|
validateSelectorDefinition(options.dev?.checkSelector, `style.${methodName}`, sel);
|
|
@@ -5074,7 +6554,7 @@ function resolveOverrideMethod(methodName, args, nameNode, selectors, scope, tra
|
|
|
5074
6554
|
callsiteOverride
|
|
5075
6555
|
};
|
|
5076
6556
|
return {
|
|
5077
|
-
styleObj: applyTransform(styleArg.value ?? {}, transform),
|
|
6557
|
+
styleObj: applyTransform(styleArg.value ?? {}, transform, cssConfig),
|
|
5078
6558
|
selector: null,
|
|
5079
6559
|
atRules: null,
|
|
5080
6560
|
callsiteOverride
|
|
@@ -5099,7 +6579,7 @@ function resolveOverrideMethod(methodName, args, nameNode, selectors, scope, tra
|
|
|
5099
6579
|
if (!styleArg.ok) return null;
|
|
5100
6580
|
const atRuleSelector = priority !== null ? [atRule, priority] : atRule;
|
|
5101
6581
|
return {
|
|
5102
|
-
styleObj: applyTransform(styleArg.value, transform),
|
|
6582
|
+
styleObj: applyTransform(styleArg.value, transform, cssConfig),
|
|
5103
6583
|
selector: null,
|
|
5104
6584
|
atRules: [atRuleSelector]
|
|
5105
6585
|
};
|
|
@@ -5115,7 +6595,7 @@ function resolveOverrideMethod(methodName, args, nameNode, selectors, scope, tra
|
|
|
5115
6595
|
const selectorText = before + normalizeSelectorArg(String(selectorArg.value ?? "")) + (after ?? "");
|
|
5116
6596
|
const itemSelector = sel.priority !== null ? [selectorText, sel.priority] : selectorText;
|
|
5117
6597
|
return {
|
|
5118
|
-
styleObj: applyTransform(styleArg.value, transform),
|
|
6598
|
+
styleObj: applyTransform(styleArg.value, transform, cssConfig),
|
|
5119
6599
|
selector: itemSelector,
|
|
5120
6600
|
atRules: null
|
|
5121
6601
|
};
|
|
@@ -5123,7 +6603,7 @@ function resolveOverrideMethod(methodName, args, nameNode, selectors, scope, tra
|
|
|
5123
6603
|
const styleArg = evaluateNode(args[0], scope);
|
|
5124
6604
|
if (!styleArg.ok) return null;
|
|
5125
6605
|
return {
|
|
5126
|
-
styleObj: applyTransform(styleArg.value, transform),
|
|
6606
|
+
styleObj: applyTransform(styleArg.value, transform, cssConfig),
|
|
5127
6607
|
selector: sel.priority !== null ? [selectorStr, sel.priority] : selectorStr,
|
|
5128
6608
|
atRules: null
|
|
5129
6609
|
};
|
|
@@ -5186,10 +6666,10 @@ function getSlotIdFromValue(value) {
|
|
|
5186
6666
|
const slotId = value.slotId;
|
|
5187
6667
|
return typeof slotId === "string" ? slotId : null;
|
|
5188
6668
|
}
|
|
5189
|
-
function compileChainMethod(method, selectors, slotId, fileId, scope, type, cssConfig, items, cssRules, transform, atRules, styleNames, options, callsiteOverride = null) {
|
|
6669
|
+
function compileChainMethod(method, selectors, slotId, fileId, scope, type, cssConfig, items, cssRules, transform, atRules, styleNames, options, callsiteOverride = null, selectorPrefix = null) {
|
|
5190
6670
|
if (method.name === "$$style.merge") {
|
|
5191
6671
|
const mergeCallsite = callsiteOverride ?? getMergeStyleCallsite(method.nameNode, scope, options);
|
|
5192
|
-
return compileMergeArg(method.args[0], method.nameNode, fileId, scope, type, slotId, atRules, cssConfig, items, cssRules, styleNames, options, mergeCallsite);
|
|
6672
|
+
return compileMergeArg(method.args[0], method.nameNode, fileId, scope, type, slotId, atRules, cssConfig, items, cssRules, styleNames, options, mergeCallsite, selectorPrefix);
|
|
5193
6673
|
}
|
|
5194
6674
|
const selector = selectors[method.name];
|
|
5195
6675
|
if (!selector) return false;
|
|
@@ -5197,48 +6677,97 @@ function compileChainMethod(method, selectors, slotId, fileId, scope, type, cssC
|
|
|
5197
6677
|
const selectorStr = selector.selector.trim();
|
|
5198
6678
|
if (selectorStr === "...") {
|
|
5199
6679
|
const mergeCallsite = callsiteOverride ?? getMergeStyleCallsite(method.nameNode, scope, options);
|
|
5200
|
-
return compileMergeArg(method.args[0], method.nameNode, fileId, scope, type, slotId, atRules, cssConfig, items, cssRules, styleNames, options, mergeCallsite);
|
|
6680
|
+
return compileMergeArg(method.args[0], method.nameNode, fileId, scope, type, slotId, atRules, cssConfig, items, cssRules, styleNames, options, mergeCallsite, selectorPrefix);
|
|
5201
6681
|
}
|
|
5202
|
-
if (selectorStr.startsWith("@")) return compileAtRuleMethod(method, slotId, selector, selectorStr, fileId, scope, type, cssConfig, items, cssRules, transform, atRules, selectors, styleNames, options);
|
|
5203
|
-
if (selectorStr.includes("$$") || selectorStr.includes("$")) return compileArgMethod(method, selector, slotId, fileId, scope, type, cssConfig, items, cssRules, transform, atRules, options);
|
|
6682
|
+
if (selectorStr.startsWith("@")) return compileAtRuleMethod(method, slotId, selector, selectorStr, fileId, scope, type, cssConfig, items, cssRules, transform, atRules, selectors, styleNames, options, selectorPrefix);
|
|
6683
|
+
if (selectorStr.includes("$$") || selectorStr.includes("$")) return compileArgMethod(method, selector, slotId, fileId, scope, type, cssConfig, items, cssRules, transform, atRules, options, selectorPrefix);
|
|
5204
6684
|
const itemSelector = selector.priority !== null ? [selectorStr, selector.priority] : selectorStr;
|
|
6685
|
+
const compiledSelector = selectorPrefix ? combineSelectors(selectorPrefix, itemSelector) : itemSelector;
|
|
5205
6686
|
const styleArg = evaluateNode(method.args[0], scope);
|
|
5206
6687
|
if (!styleArg.ok) {
|
|
5207
6688
|
throwIfRequiredStaticStyleValue(styleArg);
|
|
5208
6689
|
return false;
|
|
5209
6690
|
}
|
|
5210
|
-
return addStyleItems(applyTransform(styleArg.value, transform),
|
|
6691
|
+
return addStyleItems(applyTransform(styleArg.value, transform, cssConfig), compiledSelector, null, atRules, fileId, type, slotId, items, cssRules, cssConfig, callsiteOverride);
|
|
5211
6692
|
}
|
|
5212
|
-
function compileMergeArg(styleArgNode, mergeNode, fileId, scope, type, slotId, atRules, cssConfig, items, cssRules, styleNames, options, callsiteOverride = null) {
|
|
6693
|
+
function compileMergeArg(styleArgNode, mergeNode, fileId, scope, type, slotId, atRules, cssConfig, items, cssRules, styleNames, options, callsiteOverride = null, selectorPrefix = null) {
|
|
5213
6694
|
if (!styleArgNode) return false;
|
|
5214
6695
|
const styleCallsite = callsiteOverride ?? getMergeStyleCallsite(mergeNode, scope, options);
|
|
5215
6696
|
const localChain = getLocalStyleChainArg(styleArgNode, scope, styleNames);
|
|
5216
6697
|
const localMeta = localChain ? scope.styleMetas?.get(localChain.rootName) : null;
|
|
5217
|
-
if (
|
|
6698
|
+
if (localChain?.kind === "style" && localMeta) return compileStyleChainInto(localChain, localMeta.selectors, fileId, scope, cssConfig, localMeta.transform, type, slotId, atRules, items, cssRules, styleNames, options, styleCallsite, selectorPrefix);
|
|
5218
6699
|
if (styleArgNode.type === "CallExpression") {
|
|
5219
6700
|
const nestedChain = extractStyleChain(styleArgNode, styleNames);
|
|
5220
6701
|
const nestedMeta = nestedChain ? scope.styleMetas?.get(nestedChain.rootName) : null;
|
|
5221
|
-
if (nestedChain?.kind === "style" && nestedMeta) return compileStyleChainInto(nestedChain, nestedMeta.selectors, fileId, scope, cssConfig, nestedMeta.transform, type, slotId, atRules, items, cssRules, styleNames, options, styleCallsite);
|
|
6702
|
+
if (nestedChain?.kind === "style" && nestedMeta) return compileStyleChainInto(nestedChain, nestedMeta.selectors, fileId, scope, cssConfig, nestedMeta.transform, type, slotId, atRules, items, cssRules, styleNames, options, styleCallsite, selectorPrefix);
|
|
5222
6703
|
}
|
|
5223
6704
|
const styleArg = evaluateNode(styleArgNode, scope);
|
|
5224
6705
|
if (!styleArg.ok) {
|
|
5225
6706
|
throwIfRequiredStaticStyleValue(styleArg);
|
|
5226
6707
|
return false;
|
|
5227
6708
|
}
|
|
5228
|
-
if (isStyleData(styleArg.value) && isStyleDataSpreadExpression(styleArgNode)) return addStyleDataSpreadItems(styleArg.value, styleArgNode,
|
|
5229
|
-
return addStyleDataItems(styleArg.value,
|
|
6709
|
+
if (isStyleData(styleArg.value) && isStyleDataSpreadExpression(styleArgNode)) return addStyleDataSpreadItems(styleArg.value, styleArgNode, selectorPrefix, null, atRules, fileId, type, slotId, items, cssRules, cssConfig, styleCallsite);
|
|
6710
|
+
return addStyleDataItems(styleArg.value, selectorPrefix, null, atRules, fileId, type, slotId, items, cssRules, cssConfig, styleCallsite);
|
|
5230
6711
|
}
|
|
5231
|
-
function getLocalStyleChainArg(node, scope, styleNames) {
|
|
6712
|
+
function getLocalStyleChainArg(node, scope, styleNames, sheetNames = /* @__PURE__ */ new Set()) {
|
|
5232
6713
|
if (node.type !== "Identifier") return null;
|
|
5233
6714
|
const init = scope.bindingNodes?.get(node.name);
|
|
5234
6715
|
if (!init) return null;
|
|
5235
|
-
return extractStyleChain(init, styleNames);
|
|
6716
|
+
return extractStyleChain(init, styleNames, sheetNames);
|
|
6717
|
+
}
|
|
6718
|
+
function getLocalSelectorTargetChain(node, scope, styleNames, sheetNames) {
|
|
6719
|
+
const callee = node.callee;
|
|
6720
|
+
if (callee.type === "Identifier") {
|
|
6721
|
+
const target = getLocalStyleChainArg(callee, scope, styleNames, sheetNames);
|
|
6722
|
+
if (!isBareSelectorTargetChain(target)) return null;
|
|
6723
|
+
return {
|
|
6724
|
+
...target,
|
|
6725
|
+
baseArgs: [...target.baseArgs, ...node.arguments]
|
|
6726
|
+
};
|
|
6727
|
+
}
|
|
6728
|
+
if (callee.type !== "MemberExpression" || callee.computed) return null;
|
|
6729
|
+
const memberTarget = getLocalMemberStyleChainArg(callee, scope, styleNames, sheetNames);
|
|
6730
|
+
if (isBareSelectorTargetChain(memberTarget)) return {
|
|
6731
|
+
...memberTarget,
|
|
6732
|
+
baseArgs: [...memberTarget.baseArgs, ...node.arguments]
|
|
6733
|
+
};
|
|
6734
|
+
const methodName = callee.property.type === "Identifier" ? callee.property.name : callee.property.type === "StringLiteral" ? callee.property.value : null;
|
|
6735
|
+
if (!methodName) return null;
|
|
6736
|
+
const object = callee.object;
|
|
6737
|
+
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;
|
|
6738
|
+
if (target?.kind !== "selector") return null;
|
|
6739
|
+
return {
|
|
6740
|
+
...target,
|
|
6741
|
+
methods: [...target.methods, {
|
|
6742
|
+
name: methodName,
|
|
6743
|
+
args: node.arguments,
|
|
6744
|
+
nameNode: callee.property
|
|
6745
|
+
}]
|
|
6746
|
+
};
|
|
6747
|
+
}
|
|
6748
|
+
function getLocalMemberStyleChainArg(node, scope, styleNames, sheetNames) {
|
|
6749
|
+
if (node.computed || node.object.type !== "Identifier") return null;
|
|
6750
|
+
const propertyName = node.property.type === "Identifier" ? node.property.name : node.property.type === "StringLiteral" ? node.property.value : null;
|
|
6751
|
+
if (!propertyName) return null;
|
|
6752
|
+
const objectInit = scope.bindingNodes?.get(node.object.name);
|
|
6753
|
+
if (objectInit?.type !== "ObjectExpression") return null;
|
|
6754
|
+
for (let i = 0, len = objectInit.properties.length; i < len; i++) {
|
|
6755
|
+
const property = objectInit.properties[i];
|
|
6756
|
+
if (property.type !== "ObjectProperty") continue;
|
|
6757
|
+
const key = property.key;
|
|
6758
|
+
if ((key.type === "Identifier" ? key.name : key.type === "StringLiteral" ? key.value : null) !== propertyName) continue;
|
|
6759
|
+
return extractStyleChain(property.value, styleNames, sheetNames);
|
|
6760
|
+
}
|
|
6761
|
+
return null;
|
|
6762
|
+
}
|
|
6763
|
+
function isBareSelectorTargetChain(chain) {
|
|
6764
|
+
return chain?.kind === "selector" && chain.baseArgs.length === 1 && chain.methods.length === 0;
|
|
5236
6765
|
}
|
|
5237
6766
|
function getLocalBindingNode(node, scope) {
|
|
5238
6767
|
return node?.type === "Identifier" ? scope.bindingNodes?.get(node.name) ?? null : null;
|
|
5239
6768
|
}
|
|
5240
6769
|
function getMergeStyleCallsite(node, scope, options) {
|
|
5241
|
-
if (options.dev?.sourcemapMode !== "style") return null;
|
|
6770
|
+
if ((options.dev?.sourcemapMode ?? (scope.runtimeMode === "rsc-dev" ? "style" : null)) !== "style") return null;
|
|
5242
6771
|
const loc = node?.loc?.start;
|
|
5243
6772
|
if (!loc) return null;
|
|
5244
6773
|
return {
|
|
@@ -5260,7 +6789,7 @@ function isStyleDataSpreadExpression(node) {
|
|
|
5260
6789
|
default: return false;
|
|
5261
6790
|
}
|
|
5262
6791
|
}
|
|
5263
|
-
function compileAtRuleMethod(method, slotId, selector, selectorStr, fileId, scope, type, cssConfig, items, cssRules, transform, atRules, selectors, styleNames, options) {
|
|
6792
|
+
function compileAtRuleMethod(method, slotId, selector, selectorStr, fileId, scope, type, cssConfig, items, cssRules, transform, atRules, selectors, styleNames, options, selectorPrefix = null) {
|
|
5264
6793
|
const isMedia = selectorStr.startsWith("@media") || selectorStr.startsWith("@container");
|
|
5265
6794
|
const hasArg = selectorStr.includes("$$");
|
|
5266
6795
|
validateSelectorDefinition(options.dev?.checkSelector, `style.${method.name}`, selector, method.nameNode);
|
|
@@ -5282,22 +6811,22 @@ function compileAtRuleMethod(method, slotId, selector, selectorStr, fileId, scop
|
|
|
5282
6811
|
if (styleArg.type === "CallExpression") {
|
|
5283
6812
|
const nestedChain = extractStyleChain(styleArg, styleNames);
|
|
5284
6813
|
const nestedMeta = nestedChain ? scope.styleMetas?.get(nestedChain.rootName) : null;
|
|
5285
|
-
if (nestedChain?.kind === "style" && nestedMeta) return compileStyleChainInto(nestedChain, nestedMeta.selectors, fileId, scope, cssConfig, nestedMeta.transform, type, slotId, nextAtRules, items, cssRules, styleNames, options);
|
|
6814
|
+
if (nestedChain?.kind === "style" && nestedMeta) return compileStyleChainInto(nestedChain, nestedMeta.selectors, fileId, scope, cssConfig, nestedMeta.transform, type, slotId, nextAtRules, items, cssRules, styleNames, options, null, selectorPrefix);
|
|
5286
6815
|
const evaled = evaluateNode(styleArg, scope);
|
|
5287
6816
|
if (!evaled.ok) {
|
|
5288
6817
|
throwIfRequiredStaticStyleValue(evaled);
|
|
5289
6818
|
return false;
|
|
5290
6819
|
}
|
|
5291
|
-
return addStyleItems(applyTransform(evaled.value, transform),
|
|
6820
|
+
return addStyleItems(applyTransform(evaled.value, transform, cssConfig), selectorPrefix, null, nextAtRules, fileId, type, slotId, items, cssRules, cssConfig);
|
|
5292
6821
|
}
|
|
5293
6822
|
const styleResult = evaluateNode(styleArg, scope);
|
|
5294
6823
|
if (!styleResult.ok) {
|
|
5295
6824
|
throwIfRequiredStaticStyleValue(styleResult);
|
|
5296
6825
|
return false;
|
|
5297
6826
|
}
|
|
5298
|
-
return addStyleItems(applyTransform(styleResult.value, transform),
|
|
6827
|
+
return addStyleItems(applyTransform(styleResult.value, transform, cssConfig), selectorPrefix, null, nextAtRules, fileId, type, slotId, items, cssRules, cssConfig);
|
|
5299
6828
|
}
|
|
5300
|
-
function compileArgMethod(method, selector, slotId, fileId, scope, type, cssConfig, items, cssRules, transform, atRules, options) {
|
|
6829
|
+
function compileArgMethod(method, selector, slotId, fileId, scope, type, cssConfig, items, cssRules, transform, atRules, options, selectorPrefix = null) {
|
|
5301
6830
|
const selectorStr = selector.selector.trim();
|
|
5302
6831
|
validateSelectorDefinition(options.dev?.checkSelector, `style.${method.name}`, selector, method.nameNode);
|
|
5303
6832
|
const splitToken = selectorStr.includes("$$") ? "$$" : "$";
|
|
@@ -5314,12 +6843,13 @@ function compileArgMethod(method, selector, slotId, fileId, scope, type, cssConf
|
|
|
5314
6843
|
const styleResult = evaluateNode(styleArg, scope);
|
|
5315
6844
|
if (!styleResult.ok) return false;
|
|
5316
6845
|
const selectorValues = Array.isArray(selectorArg.value) ? selectorArg.value : [selectorArg.value];
|
|
5317
|
-
const styleObj = applyTransform(styleResult.value, transform);
|
|
6846
|
+
const styleObj = applyTransform(styleResult.value, transform, cssConfig);
|
|
5318
6847
|
let i = 0;
|
|
5319
6848
|
while (i < selectorValues.length) {
|
|
5320
6849
|
const itemSelectorValue = selectorValues[i];
|
|
5321
6850
|
const selectorText = before + normalizeSelectorArg(String(itemSelectorValue ?? "")) + (after ?? "");
|
|
5322
|
-
|
|
6851
|
+
const compiledSelector = selector.priority !== null ? [selectorText, selector.priority] : selectorText;
|
|
6852
|
+
if (!addStyleItems(styleObj, selectorPrefix ? combineSelectors(selectorPrefix, compiledSelector) : compiledSelector, null, atRules, fileId, type, slotId, items, cssRules, cssConfig)) return false;
|
|
5323
6853
|
i++;
|
|
5324
6854
|
}
|
|
5325
6855
|
return true;
|
|
@@ -5388,6 +6918,8 @@ function addSlotOverrideDataItems(value, parentSelector, atRules, fileId, items,
|
|
|
5388
6918
|
dedupe: overrideItem.dedupe,
|
|
5389
6919
|
className: overrideItem.className,
|
|
5390
6920
|
property: overrideItem.property,
|
|
6921
|
+
weight: overrideItem.weight,
|
|
6922
|
+
important: overrideItem.important,
|
|
5391
6923
|
value: overrideItem.value,
|
|
5392
6924
|
variable: overrideItem.variable,
|
|
5393
6925
|
token: overrideItem.token,
|
|
@@ -5431,27 +6963,26 @@ function addExtractedScopeItem(sourceItem, items) {
|
|
|
5431
6963
|
items.push(item);
|
|
5432
6964
|
}
|
|
5433
6965
|
function addRuntimeScopeItem(sourceItem, parentSelector, atRules, fileId, items, cssRules, cssConfig, callsiteOverride = null) {
|
|
5434
|
-
|
|
6966
|
+
const weight = sourceItem.weight;
|
|
6967
|
+
let important = false;
|
|
5435
6968
|
let value = sourceItem.value;
|
|
5436
|
-
|
|
5437
|
-
priority = value[1];
|
|
5438
|
-
value = value[0];
|
|
5439
|
-
}
|
|
6969
|
+
important = sourceItem.important;
|
|
5440
6970
|
const itemParentSelector = parentSelector ?? sourceItem.parentSelector;
|
|
5441
6971
|
const itemAtRules = mergeAtRules(atRules, sourceItem.atRule);
|
|
5442
6972
|
const traceCallsite = callsiteOverride ?? sourceItem.callsite;
|
|
5443
6973
|
const valueStr = String(value ?? "");
|
|
5444
|
-
const dedupe = getClassNameDedupe(sourceItem.property,
|
|
5445
|
-
const className = getAtomicClassName(sourceItem.property,
|
|
6974
|
+
const dedupe = getClassNameDedupe(sourceItem.property, weight, important, sourceItem.selector, itemParentSelector, itemAtRules);
|
|
6975
|
+
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);
|
|
5446
6976
|
const item = createCompiledItem(4, sourceItem.slotId, dedupe, className, !!itemParentSelector);
|
|
5447
6977
|
items.push(item);
|
|
5448
|
-
const css = buildAtomicRule(className, sourceItem.property, valueStr, sourceItem.selector, itemParentSelector, itemAtRules, cssConfig.scopeTargetPrefix);
|
|
5449
|
-
const layerPriority = getAtomicRuleLayerPriority(sourceItem.property,
|
|
6978
|
+
const css = buildAtomicRule(className, sourceItem.property, valueStr, important, sourceItem.selector, itemParentSelector, itemAtRules, cssConfig.scopeTargetPrefix);
|
|
6979
|
+
const layerPriority = getAtomicRuleLayerPriority(sourceItem.property, weight, sourceItem.selector, itemParentSelector, itemAtRules, true);
|
|
5450
6980
|
cssRules.push({
|
|
5451
6981
|
dedupe,
|
|
5452
6982
|
className,
|
|
5453
6983
|
css,
|
|
5454
6984
|
priority: layerPriority,
|
|
6985
|
+
important,
|
|
5455
6986
|
trace: traceCallsite ? {
|
|
5456
6987
|
filePath: traceCallsite.filePath ?? fileId,
|
|
5457
6988
|
line: traceCallsite.line,
|
|
@@ -5509,21 +7040,18 @@ function addExtractedStyleItem(sourceItem, type, slotId, items) {
|
|
|
5509
7040
|
items.push(item);
|
|
5510
7041
|
}
|
|
5511
7042
|
function addRuntimeStyleItem(sourceItem, selector, parentSelector, atRules, fileId, type, slotId, items, cssRules, cssConfig, callsiteOverride = null) {
|
|
5512
|
-
|
|
7043
|
+
const weight = sourceItem.weight;
|
|
7044
|
+
const important = sourceItem.important;
|
|
5513
7045
|
let value = sourceItem.value;
|
|
5514
|
-
|
|
5515
|
-
priority = value[1];
|
|
5516
|
-
value = value[0];
|
|
5517
|
-
}
|
|
5518
|
-
const itemSelector = selector ?? sourceItem.selector;
|
|
7046
|
+
const itemSelector = selector && sourceItem.selector ? combineSelectors(selector, sourceItem.selector) : selector ?? sourceItem.selector;
|
|
5519
7047
|
const itemAtRules = mergeAtRules(atRules, sourceItem.atRule);
|
|
5520
7048
|
const variable = sourceItem.variable;
|
|
5521
7049
|
const runtimeValue = variable?.[0] === 1 ? getCompiledRuntimeValue(variable[2]) : void 0;
|
|
5522
7050
|
const shouldUseVariable = !!variable && (variable[0] !== 1 || !!sourceItem.token || !!runtimeValue);
|
|
5523
7051
|
const valueStr = variable?.[0] === 1 && !shouldUseVariable ? String(variable[2] ?? "") : String(value ?? "");
|
|
5524
|
-
const dedupe = getClassNameDedupe(sourceItem.property,
|
|
7052
|
+
const dedupe = getClassNameDedupe(sourceItem.property, weight, important, itemSelector, parentSelector, itemAtRules);
|
|
5525
7053
|
const traceCallsite = callsiteOverride ?? sourceItem.callsite;
|
|
5526
|
-
const className = getAtomicClassName(sourceItem.property,
|
|
7054
|
+
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);
|
|
5527
7055
|
const item = createCompiledItem(type, slotId, dedupe, className, !!parentSelector);
|
|
5528
7056
|
item.sourceTrace = getRuntimeStyleItemSourceTrace(sourceItem, fileId);
|
|
5529
7057
|
if (type !== 4 && variable && shouldUseVariable) {
|
|
@@ -5531,13 +7059,14 @@ function addRuntimeStyleItem(sourceItem, selector, parentSelector, atRules, file
|
|
|
5531
7059
|
if (runtimeValue) item.valueNode = runtimeValue;
|
|
5532
7060
|
}
|
|
5533
7061
|
items.push(item);
|
|
5534
|
-
const css = buildAtomicRule(className, sourceItem.property, valueStr, itemSelector, parentSelector, itemAtRules, cssConfig.scopeTargetPrefix);
|
|
5535
|
-
const layerPriority = getAtomicRuleLayerPriority(sourceItem.property,
|
|
7062
|
+
const css = buildAtomicRule(className, sourceItem.property, valueStr, important, itemSelector, parentSelector, itemAtRules, cssConfig.scopeTargetPrefix);
|
|
7063
|
+
const layerPriority = getAtomicRuleLayerPriority(sourceItem.property, weight, itemSelector, parentSelector, itemAtRules, type === 4);
|
|
5536
7064
|
cssRules.push({
|
|
5537
7065
|
dedupe,
|
|
5538
7066
|
className,
|
|
5539
7067
|
css,
|
|
5540
7068
|
priority: layerPriority,
|
|
7069
|
+
important,
|
|
5541
7070
|
trace: traceCallsite ? {
|
|
5542
7071
|
filePath: traceCallsite.filePath ?? fileId,
|
|
5543
7072
|
line: traceCallsite.line,
|
|
@@ -5545,6 +7074,19 @@ function addRuntimeStyleItem(sourceItem, selector, parentSelector, atRules, file
|
|
|
5545
7074
|
} : void 0
|
|
5546
7075
|
});
|
|
5547
7076
|
}
|
|
7077
|
+
function combineSelectors(parent, child) {
|
|
7078
|
+
const parentText = getItemSelectorText(parent);
|
|
7079
|
+
const childText = getItemSelectorText(child);
|
|
7080
|
+
const priority = Math.max(getItemSelectorPriority(parent), getItemSelectorPriority(child));
|
|
7081
|
+
const selector = parentText + childText;
|
|
7082
|
+
return priority > 0 ? [selector, priority] : selector;
|
|
7083
|
+
}
|
|
7084
|
+
function getItemSelectorText(selector) {
|
|
7085
|
+
return Array.isArray(selector) ? selector[0] : selector;
|
|
7086
|
+
}
|
|
7087
|
+
function getItemSelectorPriority(selector) {
|
|
7088
|
+
return Array.isArray(selector) ? selector[1] : 0;
|
|
7089
|
+
}
|
|
5548
7090
|
function getRuntimeStyleItemSourceTrace(item, fileId) {
|
|
5549
7091
|
const trace = getRuntimeStyleItemValueTrace(item);
|
|
5550
7092
|
if (!trace) return void 0;
|
|
@@ -5589,11 +7131,14 @@ function addStyleItems(styleObj, selector, parentSelector, atRules, fileId, type
|
|
|
5589
7131
|
while (i < keys.length) {
|
|
5590
7132
|
const property = keys[i];
|
|
5591
7133
|
const rawValue = styleObj[property];
|
|
5592
|
-
let
|
|
7134
|
+
let weight = null;
|
|
7135
|
+
let important = false;
|
|
5593
7136
|
let value = rawValue;
|
|
5594
|
-
|
|
5595
|
-
|
|
5596
|
-
|
|
7137
|
+
let transformClassName = null;
|
|
7138
|
+
[value, weight, important] = unwrapStaticStyleValue(value);
|
|
7139
|
+
if (isClassNameValue(value)) {
|
|
7140
|
+
transformClassName = value.className;
|
|
7141
|
+
value = value.value;
|
|
5597
7142
|
}
|
|
5598
7143
|
if (value === null || value === void 0) {
|
|
5599
7144
|
i++;
|
|
@@ -5611,10 +7156,10 @@ function addStyleItems(styleObj, selector, parentSelector, atRules, fileId, type
|
|
|
5611
7156
|
column: propertyLoc.column
|
|
5612
7157
|
} : null);
|
|
5613
7158
|
const shouldUseVariable = !!(token || runtimeValue);
|
|
5614
|
-
const variableName = shouldUseVariable && propertyLoc ? getLocalVarName(propertyLoc.filePath ?? fileId, propertyLoc.line, propertyLoc.column, cssConfig.tokenNameFormat) : null;
|
|
7159
|
+
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;
|
|
5615
7160
|
const valueStr = variableName ? token ? getCssVarRawFallback(variableName, getTokenVar(token, cssConfig.tokenNameFormat)) : `var(${variableName})` : token ? getTokenVar(token, cssConfig.tokenNameFormat) : String(value);
|
|
5616
|
-
const dedupe = getClassNameDedupe(property,
|
|
5617
|
-
const className = getAtomicClassName(property,
|
|
7161
|
+
const dedupe = getClassNameDedupe(property, weight, important, selector, parentSelector, atRules);
|
|
7162
|
+
const className = getAtomicClassName(property, weight, important, valueStr, selector, parentSelector, atRules, propertyCallsite, cssConfig.localClassName, cssConfig.debugClassName, cssConfig.classNameFormat, transformClassName, cssConfig.transformClassNameFormat, cssConfig.sheetClassNameFormat, cssConfig.hashLength);
|
|
5618
7163
|
const item = createCompiledItem(type, slotId, dedupe, className, !!parentSelector);
|
|
5619
7164
|
item.sourceTrace = propertyCallsite ? {
|
|
5620
7165
|
property,
|
|
@@ -5639,13 +7184,14 @@ function addStyleItems(styleObj, selector, parentSelector, atRules, fileId, type
|
|
|
5639
7184
|
item.valueNode = runtimeValue ?? token[COMPILED_RUNTIME_VALUE];
|
|
5640
7185
|
}
|
|
5641
7186
|
items.push(item);
|
|
5642
|
-
const css = buildAtomicRule(className, property, valueStr, selector, parentSelector, atRules, cssConfig.scopeTargetPrefix);
|
|
5643
|
-
const layerPriority = getAtomicRuleLayerPriority(property,
|
|
7187
|
+
const css = buildAtomicRule(className, property, valueStr, important, selector, parentSelector, atRules, cssConfig.scopeTargetPrefix);
|
|
7188
|
+
const layerPriority = getAtomicRuleLayerPriority(property, weight, selector, parentSelector, atRules, type === 4);
|
|
5644
7189
|
cssRules.push({
|
|
5645
7190
|
dedupe,
|
|
5646
7191
|
className,
|
|
5647
7192
|
css,
|
|
5648
7193
|
priority: layerPriority,
|
|
7194
|
+
important,
|
|
5649
7195
|
trace: propertyCallsite ? {
|
|
5650
7196
|
filePath: propertyCallsite.filePath ?? fileId,
|
|
5651
7197
|
line: propertyCallsite.line,
|
|
@@ -5668,6 +7214,28 @@ function addStyleItems(styleObj, selector, parentSelector, atRules, fileId, type
|
|
|
5668
7214
|
}
|
|
5669
7215
|
return true;
|
|
5670
7216
|
}
|
|
7217
|
+
function unwrapStaticStyleValue(value) {
|
|
7218
|
+
let weight = null;
|
|
7219
|
+
let important = false;
|
|
7220
|
+
while (true) {
|
|
7221
|
+
if (isStyleImportantValue(value)) {
|
|
7222
|
+
important = true;
|
|
7223
|
+
value = value.value;
|
|
7224
|
+
continue;
|
|
7225
|
+
}
|
|
7226
|
+
if (isStyleWeightValue(value)) {
|
|
7227
|
+
weight = value.weight;
|
|
7228
|
+
value = value.value;
|
|
7229
|
+
continue;
|
|
7230
|
+
}
|
|
7231
|
+
break;
|
|
7232
|
+
}
|
|
7233
|
+
return [
|
|
7234
|
+
value,
|
|
7235
|
+
weight,
|
|
7236
|
+
important
|
|
7237
|
+
];
|
|
7238
|
+
}
|
|
5671
7239
|
function throwIfRequiredStaticStyleValue(result) {
|
|
5672
7240
|
if (result.ok) return;
|
|
5673
7241
|
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);
|
|
@@ -5803,6 +7371,12 @@ function parseAndExtractModule(projectDir, filePath, content, babel, resolveImpo
|
|
|
5803
7371
|
const styleMetas = /* @__PURE__ */ new Map();
|
|
5804
7372
|
const fileId = getProjectFileId$1(projectDir, filePath);
|
|
5805
7373
|
const importSourceMatcher = createImportSourceMatcher(options.importSources ?? null);
|
|
7374
|
+
const staticIdState = {
|
|
7375
|
+
fileId,
|
|
7376
|
+
imports,
|
|
7377
|
+
styleNames
|
|
7378
|
+
};
|
|
7379
|
+
const t = babel.types;
|
|
5806
7380
|
for (const stmt of ast.program.body) {
|
|
5807
7381
|
if (stmt.type === "ImportDeclaration") {
|
|
5808
7382
|
const source = stmt.source.value;
|
|
@@ -5827,6 +7401,7 @@ function parseAndExtractModule(projectDir, filePath, content, babel, resolveImpo
|
|
|
5827
7401
|
continue;
|
|
5828
7402
|
}
|
|
5829
7403
|
if (stmt.type === "VariableDeclaration") {
|
|
7404
|
+
annotateVariableDeclaration(stmt, staticIdState, t);
|
|
5830
7405
|
collectVariableBindings(rawBindings, stmt);
|
|
5831
7406
|
continue;
|
|
5832
7407
|
}
|
|
@@ -5850,6 +7425,7 @@ function parseAndExtractModule(projectDir, filePath, content, babel, resolveImpo
|
|
|
5850
7425
|
continue;
|
|
5851
7426
|
}
|
|
5852
7427
|
if (stmt.declaration?.type === "VariableDeclaration") {
|
|
7428
|
+
annotateVariableDeclaration(stmt.declaration, staticIdState, t);
|
|
5853
7429
|
collectVariableBindings(rawBindings, stmt.declaration);
|
|
5854
7430
|
continue;
|
|
5855
7431
|
}
|
|
@@ -5889,6 +7465,12 @@ function parseAndExtractModule(projectDir, filePath, content, babel, resolveImpo
|
|
|
5889
7465
|
});
|
|
5890
7466
|
return bindings;
|
|
5891
7467
|
}
|
|
7468
|
+
function annotateVariableDeclaration(declaration, state, t) {
|
|
7469
|
+
for (const decl of declaration.declarations) {
|
|
7470
|
+
annotateTokenDeclaration(decl, state, t);
|
|
7471
|
+
annotateAtRuleDeclaration(decl, state, t);
|
|
7472
|
+
}
|
|
7473
|
+
}
|
|
5892
7474
|
function collectVariableBindings(bindings, declaration) {
|
|
5893
7475
|
for (const decl of declaration.declarations) if (decl.id.type === "Identifier" && decl.init) bindings.set(decl.id.name, decl.init);
|
|
5894
7476
|
}
|
|
@@ -5899,7 +7481,7 @@ function evaluateResolvedNode(node, scope, styleNames, fileId, options) {
|
|
|
5899
7481
|
if (chain?.kind === "style" || chain?.kind === "scope") try {
|
|
5900
7482
|
const meta = scope.styleMetas?.get(chain.rootName);
|
|
5901
7483
|
if (!meta) return evalFail("Cannot resolve imported style function");
|
|
5902
|
-
const result = compileChain(chain, fileId, node.loc?.start, scope, options, meta, styleNames);
|
|
7484
|
+
const result = compileChain(chain, fileId, node.loc?.start, scope, options, scope.runtimeMode ?? null, meta, styleNames);
|
|
5903
7485
|
if (!result) return evalFail("Cannot compile imported style chain");
|
|
5904
7486
|
const extracted = createExtractedChainValue(result, options.dev?.sourcemapMode === "value" ? result : compileChain(chain, fileId, node.loc?.start, scope, {
|
|
5905
7487
|
...options,
|
|
@@ -5907,7 +7489,7 @@ function evaluateResolvedNode(node, scope, styleNames, fileId, options) {
|
|
|
5907
7489
|
...options.dev,
|
|
5908
7490
|
sourcemapMode: "value"
|
|
5909
7491
|
}
|
|
5910
|
-
}, meta, styleNames) ?? result);
|
|
7492
|
+
}, scope.runtimeMode ?? null, meta, styleNames) ?? result);
|
|
5911
7493
|
if (!extracted) return evalFail("Cannot extract imported style chain");
|
|
5912
7494
|
return evalOk(extracted);
|
|
5913
7495
|
} catch (error) {
|
|
@@ -5949,11 +7531,16 @@ function evaluateResolvedObject(node, scope, styleNames, fileId, options) {
|
|
|
5949
7531
|
const value = evaluateResolvedNode(prop.value, scope, styleNames, fileId, options);
|
|
5950
7532
|
if (!value.ok && value.reason !== "slot-ref") return value;
|
|
5951
7533
|
result[String(key.value)] = value.ok ? value.value : value;
|
|
5952
|
-
if (prop.loc?.start)
|
|
5953
|
-
|
|
5954
|
-
|
|
5955
|
-
|
|
5956
|
-
|
|
7534
|
+
if (prop.loc?.start) {
|
|
7535
|
+
const variableLoc = prop.value.loc?.start ?? prop.loc?.start;
|
|
7536
|
+
locations[String(key.value)] = {
|
|
7537
|
+
line: prop.loc.start.line,
|
|
7538
|
+
column: prop.loc.start.column + 1,
|
|
7539
|
+
filePath: scope.styleFilePath ?? scope.filePath,
|
|
7540
|
+
variableLine: variableLoc?.line,
|
|
7541
|
+
variableColumn: variableLoc ? variableLoc.column + 1 : void 0
|
|
7542
|
+
};
|
|
7543
|
+
}
|
|
5957
7544
|
}
|
|
5958
7545
|
if (Object.keys(locations).length) Object.defineProperty(result, COMPILED_STYLE_OBJECT_LOCATIONS, {
|
|
5959
7546
|
configurable: true,
|
|
@@ -5968,6 +7555,11 @@ function createExtractedChainValue(result, traceResult = result) {
|
|
|
5968
7555
|
defineCompiledStyleLocations(style, traceResult);
|
|
5969
7556
|
return style;
|
|
5970
7557
|
}
|
|
7558
|
+
if (result.type === "sheet") {
|
|
7559
|
+
const sheet = createExtractedSheet(result.items.filter(Array.isArray).map((item) => toExtractedStyleTuple(item)), result.sheetOptions);
|
|
7560
|
+
defineCompiledStyleLocations(sheet, traceResult);
|
|
7561
|
+
return sheet;
|
|
7562
|
+
}
|
|
5971
7563
|
if (result.type === "scope") return createExtractedScope(result.items.map(toExtractedScopeItem$1).filter((item) => item !== null));
|
|
5972
7564
|
return null;
|
|
5973
7565
|
}
|
|
@@ -6078,6 +7670,12 @@ function hashFileContent(filePath) {
|
|
|
6078
7670
|
function getStyleRuntimeImportPath(mode) {
|
|
6079
7671
|
return `${STYLE_IMPORT_PATH}/entry/${mode}`;
|
|
6080
7672
|
}
|
|
7673
|
+
function getStyleRuntimeAdapterImportPath(source, mode) {
|
|
7674
|
+
if (source === "@fluentic/style/adapter/solid") return `${getStyleRuntimeImportPath(mode)}/adapter/solid`;
|
|
7675
|
+
if (source === "@fluentic/style/adapter/preact") return `${getStyleRuntimeImportPath(mode)}/adapter/preact`;
|
|
7676
|
+
if (source === "@fluentic/style/adapter/react") return `${getStyleRuntimeImportPath(mode)}/adapter/react`;
|
|
7677
|
+
return null;
|
|
7678
|
+
}
|
|
6081
7679
|
function getStyleRuntimeCssImportPath(mode) {
|
|
6082
7680
|
return `${getStyleRuntimeImportPath(mode)}/css`;
|
|
6083
7681
|
}
|
|
@@ -6170,6 +7768,10 @@ function buildReplacement(t, chain, state, options = {}) {
|
|
|
6170
7768
|
state.usedHelpers.add(hasSpread ? FN_CREATE_EXTRACTED_STYLE_MERGE : FN_CREATE_EXTRACTED_STYLE);
|
|
6171
7769
|
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)]);
|
|
6172
7770
|
}
|
|
7771
|
+
if (chain.type === "sheet") {
|
|
7772
|
+
state.usedHelpers.add(FN_CREATE_EXTRACTED_SHEET);
|
|
7773
|
+
return t.callExpression(t.identifier(FN_CREATE_EXTRACTED_SHEET), [buildItemsArray(t, chain, 9, state, options), buildSheetOptions(t, chain)]);
|
|
7774
|
+
}
|
|
6173
7775
|
if (chain.type === "slot") {
|
|
6174
7776
|
state.usedHelpers.add(FN_CREATE_EXTRACTED_SLOT);
|
|
6175
7777
|
return t.callExpression(t.identifier(FN_CREATE_EXTRACTED_SLOT), [t.stringLiteral(chain.slotId), buildItemsArray(t, chain, 2, state, options)]);
|
|
@@ -6180,6 +7782,13 @@ function buildReplacement(t, chain, state, options = {}) {
|
|
|
6180
7782
|
}
|
|
6181
7783
|
return null;
|
|
6182
7784
|
}
|
|
7785
|
+
function buildSheetOptions(t, chain) {
|
|
7786
|
+
const options = chain.sheetOptions ?? {};
|
|
7787
|
+
const properties = [];
|
|
7788
|
+
if (options.layer !== void 0) properties.push(t.objectProperty(t.identifier("layer"), t.booleanLiteral(options.layer)));
|
|
7789
|
+
if (options.weight !== void 0) properties.push(t.objectProperty(t.identifier("weight"), t.numericLiteral(options.weight)));
|
|
7790
|
+
return t.objectExpression(properties);
|
|
7791
|
+
}
|
|
6183
7792
|
function buildStyleMergeArgs(t, chain, state, options) {
|
|
6184
7793
|
const args = [];
|
|
6185
7794
|
let chunk = [];
|
|
@@ -6208,7 +7817,7 @@ function buildItemsArray(t, chain, defaultType, state, options) {
|
|
|
6208
7817
|
chain.items.forEach((item) => {
|
|
6209
7818
|
if (isCompiledTokenItem(item)) {
|
|
6210
7819
|
if (options.getTokenOverride) options.getTokenOverride(item);
|
|
6211
|
-
else itemExpressions.push(t
|
|
7820
|
+
else itemExpressions.push(buildExtractedTokenOverrideExpression(t, item.value, state));
|
|
6212
7821
|
return;
|
|
6213
7822
|
}
|
|
6214
7823
|
if (isCompiledStyleSpreadItem(item)) return;
|
|
@@ -6298,11 +7907,26 @@ function buildVariableValueExpression(t, value, state, item, options) {
|
|
|
6298
7907
|
}
|
|
6299
7908
|
function buildExtractedTokenExpression(t, token, state) {
|
|
6300
7909
|
state.usedHelpers.add(FN_CREATE_EXTRACTED_TOKEN);
|
|
7910
|
+
const tokenNameFormat = state.options.css?.tokenNameFormat ?? DEFAULT_CONFIG.tokenNameFormat ?? null;
|
|
6301
7911
|
return t.callExpression(t.identifier(FN_CREATE_EXTRACTED_TOKEN), [
|
|
6302
7912
|
t.stringLiteral(getStyleTokenId(token)),
|
|
6303
7913
|
literalExpression(t, token.value),
|
|
6304
|
-
token.ref ? buildExtractedTokenExpression(t, token.ref, state) : t.nullLiteral()
|
|
7914
|
+
token.ref ? buildExtractedTokenExpression(t, token.ref, state) : t.nullLiteral(),
|
|
7915
|
+
getStyleTokenName(token) ? t.stringLiteral(getStyleTokenName(token)) : t.nullLiteral(),
|
|
7916
|
+
t.stringLiteral(getTokenVarName(token, tokenNameFormat))
|
|
7917
|
+
]);
|
|
7918
|
+
}
|
|
7919
|
+
function buildExtractedTokenOverrideExpression(t, token, state) {
|
|
7920
|
+
state.usedHelpers.add(FN_CREATE_EXTRACTED_TOKEN);
|
|
7921
|
+
const tokenNameFormat = state.options.css?.tokenNameFormat ?? DEFAULT_CONFIG.tokenNameFormat ?? null;
|
|
7922
|
+
const extractedToken = t.callExpression(t.identifier(FN_CREATE_EXTRACTED_TOKEN), [
|
|
7923
|
+
t.stringLiteral(getStyleTokenId(token)),
|
|
7924
|
+
t.nullLiteral(),
|
|
7925
|
+
t.nullLiteral(),
|
|
7926
|
+
getStyleTokenName(token) ? t.stringLiteral(getStyleTokenName(token)) : t.nullLiteral(),
|
|
7927
|
+
t.stringLiteral(getTokenVarName(token, tokenNameFormat))
|
|
6305
7928
|
]);
|
|
7929
|
+
return t.callExpression(extractedToken, [token.ref ? buildExtractedTokenExpression(t, token.ref, state) : literalExpression(t, token.value)]);
|
|
6306
7930
|
}
|
|
6307
7931
|
function literalExpression(t, value) {
|
|
6308
7932
|
if (typeof value === "string") return t.stringLiteral(value);
|
|
@@ -6425,8 +8049,10 @@ function getEvalScope(state) {
|
|
|
6425
8049
|
styleFilePath: state.styleFilePath,
|
|
6426
8050
|
sourcemapTrace: state.sourcemapTrace,
|
|
6427
8051
|
styleNames: state.styleNames,
|
|
8052
|
+
sheetNames: state.sheetNames,
|
|
6428
8053
|
styleMetas: state.styleMetas,
|
|
6429
|
-
bindingNodes: state.bindingNodes
|
|
8054
|
+
bindingNodes: state.bindingNodes,
|
|
8055
|
+
runtimeMode: state.runtimeMode
|
|
6430
8056
|
};
|
|
6431
8057
|
}
|
|
6432
8058
|
//#endregion
|
|
@@ -6440,8 +8066,8 @@ function compileThemeCall(path, state, opts) {
|
|
|
6440
8066
|
const tokenArg = evaluateNode(path.node.arguments[0], scope);
|
|
6441
8067
|
if (!tokenArg.ok) throw path.buildCodeFrameError(`createTheme tokens must be statically analyzable: ${tokenArg.reason}`);
|
|
6442
8068
|
if (!Array.isArray(tokenArg.value)) throw path.buildCodeFrameError("createTheme first argument must be a static array of token overrides.");
|
|
6443
|
-
const
|
|
6444
|
-
if (path.node.arguments[1] && !
|
|
8069
|
+
const stableIdArg = evaluateNode(path.node.arguments[1], scope);
|
|
8070
|
+
if (path.node.arguments[1] && !stableIdArg.ok) throw path.buildCodeFrameError(`createTheme stableId must be statically analyzable: ${stableIdArg.reason}`);
|
|
6445
8071
|
const tokens = [];
|
|
6446
8072
|
for (let i = 0, len = tokenArg.value.length; i < len; i++) {
|
|
6447
8073
|
const token = tokenArg.value[i];
|
|
@@ -6449,7 +8075,7 @@ function compileThemeCall(path, state, opts) {
|
|
|
6449
8075
|
tokens.push(token);
|
|
6450
8076
|
}
|
|
6451
8077
|
const loc = path.node.loc?.start;
|
|
6452
|
-
const id =
|
|
8078
|
+
const id = stableIdArg.ok && stableIdArg.value !== void 0 ? String(stableIdArg.value) : getStableThemeId(state.fileId, loc ? loc.line + ":" + loc.column : "createTheme");
|
|
6453
8079
|
const themeNameFormat = opts.css?.themeNameFormat || CSS_CONFIG.themeNameFormat || null;
|
|
6454
8080
|
const className = getStableThemeClassName(id, themeNameFormat);
|
|
6455
8081
|
return {
|
|
@@ -6481,6 +8107,7 @@ function createExtractPlugin(args) {
|
|
|
6481
8107
|
return {
|
|
6482
8108
|
pre() {
|
|
6483
8109
|
this.styleNames = /* @__PURE__ */ new Set();
|
|
8110
|
+
this.sheetNames = /* @__PURE__ */ new Set();
|
|
6484
8111
|
this.styleMetas = /* @__PURE__ */ new Map();
|
|
6485
8112
|
this.bindings = /* @__PURE__ */ new Map();
|
|
6486
8113
|
this.bindingNodes = /* @__PURE__ */ new Map();
|
|
@@ -6497,7 +8124,7 @@ function createExtractPlugin(args) {
|
|
|
6497
8124
|
this.filePath = this.file?.opts?.filename ?? "unknown";
|
|
6498
8125
|
this.styleFilePath = args.styleFilePath ?? this.filePath;
|
|
6499
8126
|
this.sourcemapTrace = options.dev?.sourcemapMode ?? "style";
|
|
6500
|
-
this.fileId = args.styleFilePath ?? getProjectFileId(args.projectDir, this.file?.opts?.filename);
|
|
8127
|
+
this.fileId = args.runtimeMode === "rsc-dev" ? getProjectFileId(args.projectDir, this.file?.opts?.filename) : args.styleFilePath ?? getProjectFileId(args.projectDir, this.file?.opts?.filename);
|
|
6501
8128
|
},
|
|
6502
8129
|
visitor: {
|
|
6503
8130
|
ImportDeclaration(path, state) {
|
|
@@ -6527,6 +8154,7 @@ function createExtractPlugin(args) {
|
|
|
6527
8154
|
state.styleNames.add(spec.local.name);
|
|
6528
8155
|
state.styleMetas.set(spec.local.name, meta);
|
|
6529
8156
|
}
|
|
8157
|
+
if (sourceName === "@fluentic/style/css" && imported === "createSheet") state.sheetNames.add(spec.local.name);
|
|
6530
8158
|
});
|
|
6531
8159
|
},
|
|
6532
8160
|
VariableDeclaration(path, state) {
|
|
@@ -6573,22 +8201,26 @@ function createExtractPlugin(args) {
|
|
|
6573
8201
|
state.needsExtractImport = true;
|
|
6574
8202
|
return;
|
|
6575
8203
|
}
|
|
6576
|
-
if (!state.styleNames.size) return;
|
|
6577
|
-
const chain = extractStyleChain(path.node, state.styleNames);
|
|
8204
|
+
if (!state.styleNames.size && !state.sheetNames.size) return;
|
|
8205
|
+
const chain = extractStyleChain(path.node, state.styleNames, state.sheetNames);
|
|
6578
8206
|
if (!chain) return;
|
|
6579
8207
|
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.");
|
|
6580
8208
|
const scope = getEvalScope(state);
|
|
6581
8209
|
const loc = path.node.loc?.start;
|
|
6582
8210
|
const meta = state.styleMetas.get(chain.rootName);
|
|
6583
|
-
if (!meta) return;
|
|
8211
|
+
if (chain.kind !== "sheet" && !meta) return;
|
|
6584
8212
|
let result;
|
|
6585
8213
|
try {
|
|
6586
|
-
result = compileChain(chain, state.fileId, loc, scope, options, meta, state.styleNames);
|
|
8214
|
+
result = compileChain(chain, state.fileId, loc, scope, options, state.runtimeMode, meta ?? null, state.styleNames);
|
|
6587
8215
|
} catch (error) {
|
|
6588
8216
|
const message = error instanceof Error ? error.message : String(error);
|
|
6589
8217
|
throw buildCodeFrameError(path, getSelectorCompileErrorNode(error) ?? path.node, message);
|
|
6590
8218
|
}
|
|
6591
8219
|
if (!result) return;
|
|
8220
|
+
checkCompiledImportantUsage(result, options.check?.important, (level, message) => {
|
|
8221
|
+
if (level === "error") throw path.buildCodeFrameError(message);
|
|
8222
|
+
console.warn("[fluentic-style] " + message);
|
|
8223
|
+
});
|
|
6592
8224
|
result.rules.forEach((rule) => {
|
|
6593
8225
|
state.collector.add(rule);
|
|
6594
8226
|
});
|
|
@@ -6627,6 +8259,18 @@ function createExtractPlugin(args) {
|
|
|
6627
8259
|
};
|
|
6628
8260
|
});
|
|
6629
8261
|
}
|
|
8262
|
+
function checkCompiledImportantUsage(result, options, report) {
|
|
8263
|
+
if (!options) return;
|
|
8264
|
+
let hasRawValue = false;
|
|
8265
|
+
let hasOutsideSheet = false;
|
|
8266
|
+
for (let i = 0, len = result.rules.length; i < len; i++) {
|
|
8267
|
+
const rule = result.rules[i];
|
|
8268
|
+
if (!rule.important && /!\s*important\b/i.test(rule.css)) hasRawValue = true;
|
|
8269
|
+
if (result.type !== "sheet" && rule.important) hasOutsideSheet = true;
|
|
8270
|
+
}
|
|
8271
|
+
if (hasRawValue && options.rawValue) report(options.rawValue, "Do not write raw \"!important\" values. Wrap the value with style.important(...) instead.");
|
|
8272
|
+
if (hasOutsideSheet && options.outsideSheet) report(options.outsideSheet, "style.important(...) outside createSheet is discouraged. Prefer style.weight(...) for Fluentic style priority.");
|
|
8273
|
+
}
|
|
6630
8274
|
function pruneUnusedStyleInputDeclarations(path, state) {
|
|
6631
8275
|
path.scope.crawl();
|
|
6632
8276
|
path.traverse({ VariableDeclarator(declaratorPath) {
|
|
@@ -6788,13 +8432,15 @@ function insertHoistedDeclarations(path, declarations) {
|
|
|
6788
8432
|
const body = path.node.body;
|
|
6789
8433
|
let firstRuntimeIndex = 0;
|
|
6790
8434
|
while (firstRuntimeIndex < body.length && body[firstRuntimeIndex].type === "ImportDeclaration") firstRuntimeIndex++;
|
|
8435
|
+
let runtimeInsertIndex = firstRuntimeIndex;
|
|
6791
8436
|
declarations.forEach((item) => {
|
|
6792
|
-
let insertIndex =
|
|
8437
|
+
let insertIndex = runtimeInsertIndex;
|
|
6793
8438
|
item.dependencies.forEach((name) => {
|
|
6794
8439
|
const dependencyIndex = findTopLevelDeclarationIndex(body, name);
|
|
6795
8440
|
if (dependencyIndex >= insertIndex) insertIndex = dependencyIndex + 1;
|
|
6796
8441
|
});
|
|
6797
8442
|
body.splice(insertIndex, 0, item.declaration);
|
|
8443
|
+
runtimeInsertIndex = insertIndex + 1;
|
|
6798
8444
|
});
|
|
6799
8445
|
}
|
|
6800
8446
|
function findTopLevelDeclarationIndex(body, name) {
|
|
@@ -6835,7 +8481,7 @@ function transformExtract(internal, args, deps) {
|
|
|
6835
8481
|
code: args.code,
|
|
6836
8482
|
filePath: args.filePath,
|
|
6837
8483
|
sourcemap: args.sourcemap,
|
|
6838
|
-
plugins: [plugin],
|
|
8484
|
+
plugins: [createCssPropPlugin({ options: internal.options }), plugin],
|
|
6839
8485
|
errorLabel: "[style] compiler error"
|
|
6840
8486
|
});
|
|
6841
8487
|
if (!result) return null;
|
|
@@ -6882,10 +8528,10 @@ function createCompiler(args, options) {
|
|
|
6882
8528
|
const tracer = createTracer(internal);
|
|
6883
8529
|
const collector = createCssCollector();
|
|
6884
8530
|
const compileDebug = (args) => {
|
|
6885
|
-
return rewriteTransformResult(transformDebug(internal, args, { tracer }), internal.runtimeMode);
|
|
8531
|
+
return rewriteTransformResult(transformDebug(internal, args, { tracer }), internal.runtimeMode, args.code);
|
|
6886
8532
|
};
|
|
6887
8533
|
const compileDebugRSC = (args) => {
|
|
6888
|
-
const debugResult = rewriteTransformResult(transformDebug(internal, args, { tracer }), internal.runtimeMode);
|
|
8534
|
+
const debugResult = rewriteTransformResult(transformDebug(internal, args, { tracer }), internal.runtimeMode, args.code);
|
|
6889
8535
|
if (!debugResult) return null;
|
|
6890
8536
|
const rscCollector = createCssCollector();
|
|
6891
8537
|
transformExtract(internal, args, {
|
|
@@ -6914,7 +8560,7 @@ function createCompiler(args, options) {
|
|
|
6914
8560
|
return rewriteTransformResult({
|
|
6915
8561
|
...result,
|
|
6916
8562
|
rules: collector.getItems().slice(startIndex)
|
|
6917
|
-
}, internal.runtimeMode);
|
|
8563
|
+
}, internal.runtimeMode, args.code);
|
|
6918
8564
|
};
|
|
6919
8565
|
const getExtractedCss = () => {
|
|
6920
8566
|
return extractCss(collector.getItems(), {
|
|
@@ -6944,23 +8590,73 @@ function createCompilerInternal(args, options) {
|
|
|
6944
8590
|
options
|
|
6945
8591
|
};
|
|
6946
8592
|
}
|
|
6947
|
-
function rewriteTransformResult(result, runtimeMode) {
|
|
8593
|
+
function rewriteTransformResult(result, runtimeMode, sourceCode) {
|
|
6948
8594
|
if (!result || !runtimeMode) return result;
|
|
6949
8595
|
return {
|
|
6950
8596
|
...result,
|
|
6951
|
-
code: rewriteCompilerRuntimeImports(result.code, runtimeMode)
|
|
8597
|
+
code: rewriteCompilerRuntimeImports(result.code, runtimeMode, sourceCode)
|
|
6952
8598
|
};
|
|
6953
8599
|
}
|
|
6954
|
-
function rewriteCompilerRuntimeImports(code, runtimeMode) {
|
|
6955
|
-
|
|
8600
|
+
function rewriteCompilerRuntimeImports(code, runtimeMode, sourceCode) {
|
|
8601
|
+
const importRuntimeMode = getImportRuntimeMode(runtimeMode, sourceCode);
|
|
8602
|
+
return rewriteImportSources(code, (source) => getCompilerRuntimeImportSource(source, runtimeMode, importRuntimeMode));
|
|
8603
|
+
}
|
|
8604
|
+
function getImportRuntimeMode(runtimeMode, sourceCode) {
|
|
8605
|
+
if (runtimeMode === "rsc-dev" && hasUseClientDirective(sourceCode)) return "dev";
|
|
8606
|
+
return runtimeMode;
|
|
6956
8607
|
}
|
|
6957
|
-
function getCompilerRuntimeImportSource(source, runtimeMode) {
|
|
6958
|
-
if (source === "@fluentic/style") return getStyleRuntimeImportPath(
|
|
6959
|
-
|
|
8608
|
+
function getCompilerRuntimeImportSource(source, runtimeMode, importRuntimeMode) {
|
|
8609
|
+
if (source === "@fluentic/style") return getStyleRuntimeImportPath(importRuntimeMode);
|
|
8610
|
+
const adapterImportPath = getStyleRuntimeAdapterImportPath(source, importRuntimeMode);
|
|
8611
|
+
if (adapterImportPath) return adapterImportPath;
|
|
8612
|
+
if (source === "@fluentic/style/css") return getStyleRuntimeCssImportPath(importRuntimeMode);
|
|
6960
8613
|
if (source === "@fluentic/style/entry/prod/runtime") return getStyleExtractRuntimeImportPath(runtimeMode);
|
|
6961
8614
|
if (runtimeMode === "rsc-dev" && source === "@fluentic/style/dev/rsc") return getStyleRuntimeDevRscImportPath(runtimeMode);
|
|
6962
8615
|
return null;
|
|
6963
8616
|
}
|
|
8617
|
+
function hasUseClientDirective(code) {
|
|
8618
|
+
let index = 0;
|
|
8619
|
+
while (index < code.length) {
|
|
8620
|
+
index = skipWhitespaceAndComments(code, index);
|
|
8621
|
+
const quote = code[index];
|
|
8622
|
+
if (quote !== "\"" && quote !== "'") return false;
|
|
8623
|
+
const end = code.indexOf(quote, index + 1);
|
|
8624
|
+
if (end < 0) return false;
|
|
8625
|
+
const directive = code.slice(index + 1, end);
|
|
8626
|
+
index = skipWhitespaceAndComments(code, end + 1);
|
|
8627
|
+
if (code[index] === ";") index += 1;
|
|
8628
|
+
else if (code[index] && code[index] !== "\n" && code[index] !== "\r") return false;
|
|
8629
|
+
if (directive === "use client") return true;
|
|
8630
|
+
}
|
|
8631
|
+
return false;
|
|
8632
|
+
}
|
|
8633
|
+
function skipWhitespaceAndComments(code, index) {
|
|
8634
|
+
let next = index;
|
|
8635
|
+
while (next < code.length) {
|
|
8636
|
+
const char = code[next];
|
|
8637
|
+
if (char === " " || char === " " || char === "\n" || char === "\r") {
|
|
8638
|
+
next += 1;
|
|
8639
|
+
continue;
|
|
8640
|
+
}
|
|
8641
|
+
if (char === "/" && code[next + 1] === "/") {
|
|
8642
|
+
const lineEnd = code.indexOf("\n", next + 2);
|
|
8643
|
+
next = lineEnd < 0 ? code.length : lineEnd + 1;
|
|
8644
|
+
continue;
|
|
8645
|
+
}
|
|
8646
|
+
if (char === "/" && code[next + 1] === "*") {
|
|
8647
|
+
const commentEnd = code.indexOf("*/", next + 2);
|
|
8648
|
+
next = commentEnd < 0 ? code.length : commentEnd + 2;
|
|
8649
|
+
continue;
|
|
8650
|
+
}
|
|
8651
|
+
break;
|
|
8652
|
+
}
|
|
8653
|
+
return next;
|
|
8654
|
+
}
|
|
8655
|
+
const CssPropPresets = {
|
|
8656
|
+
Solid: { adapter: "@fluentic/style/adapter/solid" },
|
|
8657
|
+
Preact: { adapter: "@fluentic/style/adapter/preact" },
|
|
8658
|
+
React: { adapter: "@fluentic/style/adapter/react" }
|
|
8659
|
+
};
|
|
6964
8660
|
//#endregion
|
|
6965
8661
|
//#region plugin/utils/constants.ts
|
|
6966
8662
|
const PLUGIN_NAME = "fluentic-style";
|
|
@@ -7091,11 +8787,12 @@ function getStyleRuntimeMode(dev, rsc = false) {
|
|
|
7091
8787
|
if (rsc) return dev ? "rsc-dev" : "rsc-prod";
|
|
7092
8788
|
return dev ? "dev" : "prod";
|
|
7093
8789
|
}
|
|
7094
|
-
function getPluginBuildConfig(options) {
|
|
8790
|
+
function getPluginBuildConfig(options, dev = false) {
|
|
7095
8791
|
const css = hasBuildConfig(options.css) ? options.css : {};
|
|
7096
8792
|
return {
|
|
7097
|
-
hoist: options.hoist !== false,
|
|
7098
|
-
css
|
|
8793
|
+
hoist: !dev && options.hoist !== false,
|
|
8794
|
+
css,
|
|
8795
|
+
check: options.check
|
|
7099
8796
|
};
|
|
7100
8797
|
}
|
|
7101
8798
|
function getPluginBuildDevConfig(options) {
|
|
@@ -7527,6 +9224,12 @@ Object.defineProperty(exports, "CSS_MODULE_ID", {
|
|
|
7527
9224
|
return CSS_MODULE_ID;
|
|
7528
9225
|
}
|
|
7529
9226
|
});
|
|
9227
|
+
Object.defineProperty(exports, "CssPropPresets", {
|
|
9228
|
+
enumerable: true,
|
|
9229
|
+
get: function() {
|
|
9230
|
+
return CssPropPresets;
|
|
9231
|
+
}
|
|
9232
|
+
});
|
|
7530
9233
|
Object.defineProperty(exports, "DEFAULT_TRANSFORM_INCLUDE_PATTERN", {
|
|
7531
9234
|
enumerable: true,
|
|
7532
9235
|
get: function() {
|
|
@@ -7648,4 +9351,4 @@ Object.defineProperty(exports, "writeParcelVirtualRuntimeFile", {
|
|
|
7648
9351
|
}
|
|
7649
9352
|
});
|
|
7650
9353
|
|
|
7651
|
-
//# sourceMappingURL=shared-
|
|
9354
|
+
//# sourceMappingURL=shared-PK52rW6T.cjs.map
|