@fluentic/style 0.1.0-beta.0 → 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 +154 -0
- 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 +173 -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-DweanHoB.mjs → compiler-C3CEGGtI.mjs} +2349 -647
- 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 +634 -713
- 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-DS61nRqr.mjs → loader-_-VjzlrX.mjs} +13 -14
- package/dist/loader-_-VjzlrX.mjs.map +1 -0
- package/dist/{misc-B9kqEb2N.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/presets-DSanixJV.js +243 -0
- package/dist/presets-DSanixJV.js.map +1 -0
- package/dist/{registry-CyIj8LYK.mjs → registry-w8ET5R7v.mjs} +2 -2
- package/dist/{registry-CyIj8LYK.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 +2 -3
- package/dist/server.js +17 -11
- package/dist/server.js.map +1 -1
- package/dist/{shared-CCpq1zqA.mjs → shared-C_cYxNzz.mjs} +4 -4
- package/dist/{shared-CCpq1zqA.mjs.map → shared-C_cYxNzz.mjs.map} +1 -1
- package/dist/{shared-BAL9peIw.cjs → shared-PK52rW6T.cjs} +2352 -644
- 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-4u6GnlQG.mjs → sidecar-BhvmXYsD.mjs} +3 -3
- package/dist/{sidecar-4u6GnlQG.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-DMFgOOtA.mjs → utils-DND33M6y.mjs} +3 -3
- package/dist/{utils-DMFgOOtA.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-CxS2FDYU.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 +118 -18
- 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 +12 -7
- 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/selector/assert.ts +24 -25
- package/selector/selector.ts +6 -0
- 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-h_Zkqc4E.js +0 -105
- package/dist/assert-h_Zkqc4E.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-DweanHoB.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-_te7t0M4.js +0 -473
- package/dist/data-_te7t0M4.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-DS61nRqr.mjs.map +0 -1
- package/dist/misc-B9kqEb2N.mjs.map +0 -1
- package/dist/presets-Bye3ea2x.js +0 -139
- package/dist/presets-Bye3ea2x.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-BAL9peIw.cjs.map +0 -1
- package/dist/style-4rFUy-zW.js +0 -752
- package/dist/style-4rFUy-zW.js.map +0 -1
- package/dist/style-B1UUqjj5.js +0 -743
- package/dist/style-B1UUqjj5.js.map +0 -1
- package/dist/style-Cw3NtvR0.js +0 -5
- package/dist/style-DNqQ6H-7.js +0 -1255
- package/dist/style-DNqQ6H-7.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-C7xfDxtM.mjs +0 -97
- package/dist/utils-C7xfDxtM.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-CxS2FDYU.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) {
|
|
@@ -672,6 +943,9 @@ function selectorPriority(selectors, values) {
|
|
|
672
943
|
});
|
|
673
944
|
return selectors;
|
|
674
945
|
}
|
|
946
|
+
function createSelectorAssert(fn) {
|
|
947
|
+
return fn;
|
|
948
|
+
}
|
|
675
949
|
//#endregion
|
|
676
950
|
//#region selector/presets/selectors.ts
|
|
677
951
|
const PseudoSelectors = {
|
|
@@ -737,147 +1011,39 @@ const AtRuleSelectors = {
|
|
|
737
1011
|
supports: selector("@supports $$", "supports")
|
|
738
1012
|
};
|
|
739
1013
|
const PrioritySelectors = selectorPriority({
|
|
740
|
-
...PseudoSelectors,
|
|
741
|
-
...PseudoElementSelectors,
|
|
742
|
-
...PseudoArgSelectors,
|
|
743
|
-
...ArgSelectors,
|
|
744
|
-
...AtRuleSelectors
|
|
745
|
-
}, [
|
|
746
|
-
"link",
|
|
747
|
-
"visited",
|
|
748
|
-
"hover",
|
|
749
|
-
"focusWithin",
|
|
750
|
-
"focus",
|
|
751
|
-
"focusVisible",
|
|
752
|
-
"active",
|
|
753
|
-
"disabled"
|
|
754
|
-
]);
|
|
755
|
-
selectorPriority({
|
|
756
|
-
hover: PseudoSelectors.hover,
|
|
757
|
-
active: PseudoSelectors.active,
|
|
758
|
-
focus: PseudoSelectors.focus,
|
|
759
|
-
focusWithin: PseudoSelectors.focusWithin,
|
|
760
|
-
disabled: PseudoSelectors.disabled,
|
|
761
|
-
firstChild: PseudoSelectors.firstChild,
|
|
762
|
-
lastChild: PseudoSelectors.lastChild,
|
|
763
|
-
nthChild: PseudoArgSelectors.nthChild,
|
|
764
|
-
nthOfType: PseudoArgSelectors.nthOfType,
|
|
765
|
-
is: PseudoArgSelectors.is,
|
|
766
|
-
where: PseudoArgSelectors.where,
|
|
767
|
-
not: PseudoArgSelectors.not,
|
|
768
|
-
has: PseudoArgSelectors.has,
|
|
769
|
-
...PseudoElementSelectors,
|
|
770
|
-
...ArgSelectors,
|
|
771
|
-
...AtRuleSelectors
|
|
772
|
-
}, PrioritySelectors);
|
|
773
|
-
//#endregion
|
|
774
|
-
//#region selector/validate.ts
|
|
775
|
-
function isLocalSelector(selector) {
|
|
776
|
-
const groups = parseSelector(selector);
|
|
777
|
-
if (!groups || groups.length !== 1) return false;
|
|
778
|
-
return isSelectorGroupsSelf(groups, false);
|
|
779
|
-
}
|
|
780
|
-
function isPseudoArgSelector(selector) {
|
|
781
|
-
const groups = parseSelector(selector);
|
|
782
|
-
if (!groups || groups.length !== 1) return false;
|
|
783
|
-
return isSelectorGroupsSelf(groups, true);
|
|
784
|
-
}
|
|
785
|
-
function isTagSelector(selector) {
|
|
786
|
-
const groups = parseSelector(selector);
|
|
787
|
-
if (!groups || groups.length !== 1) return false;
|
|
788
|
-
const group = groups[0];
|
|
789
|
-
return group.length === 1 && group[0].type === css_what.SelectorType.Tag;
|
|
790
|
-
}
|
|
791
|
-
function isAttrArg(value) {
|
|
792
|
-
if (!value) return false;
|
|
793
|
-
if (value.includes("[") || value.includes("]")) return false;
|
|
794
|
-
return true;
|
|
795
|
-
}
|
|
796
|
-
function isRawValue(value) {
|
|
797
|
-
if (!value) return false;
|
|
798
|
-
if (value.includes("{") || value.includes("}")) return false;
|
|
799
|
-
return true;
|
|
800
|
-
}
|
|
801
|
-
function parseSelector(selector) {
|
|
802
|
-
try {
|
|
803
|
-
return (0, css_what.parse)(selector);
|
|
804
|
-
} catch {
|
|
805
|
-
return;
|
|
806
|
-
}
|
|
807
|
-
}
|
|
808
|
-
function isSelectorGroupsSelf(groups, allowTag) {
|
|
809
|
-
for (let i = 0; i < groups.length; i++) {
|
|
810
|
-
const group = groups[i];
|
|
811
|
-
for (let j = 0; j < group.length; j++) {
|
|
812
|
-
const token = group[j];
|
|
813
|
-
if (!isAllowedSelectorType(token.type, allowTag)) return false;
|
|
814
|
-
if (token.type === css_what.SelectorType.Pseudo && Array.isArray(token.data) && !isSelectorGroupsSelf(token.data, allowTag)) return false;
|
|
815
|
-
}
|
|
816
|
-
}
|
|
817
|
-
return true;
|
|
818
|
-
}
|
|
819
|
-
function isAllowedSelectorType(type, allowTag) {
|
|
820
|
-
return type === css_what.SelectorType.Attribute || type === css_what.SelectorType.Pseudo || type === css_what.SelectorType.PseudoElement || allowTag && type === css_what.SelectorType.Tag;
|
|
821
|
-
}
|
|
822
|
-
//#endregion
|
|
823
|
-
//#region selector/assert.ts
|
|
824
|
-
function assertSelector(type, value) {
|
|
825
|
-
assertSelectorNotEmpty(value);
|
|
826
|
-
if (!type) return;
|
|
827
|
-
if (typeof type === "function") return type(value);
|
|
828
|
-
switch (type) {
|
|
829
|
-
case "local": return assertLocalSelector(value);
|
|
830
|
-
case "arg": return assertPseudoArgSelector(value);
|
|
831
|
-
case "tag": return assertTagSelector(value);
|
|
832
|
-
case "attr": return assertAttrSelector(value);
|
|
833
|
-
case "value": return assertRawValue(value);
|
|
834
|
-
case "media": return assertMediaQuery(value);
|
|
835
|
-
case "supports": return assertSupportsQuery(value);
|
|
836
|
-
case "container": return assertContainerQuery(value);
|
|
837
|
-
default: throw new Error("unsupported selector type: " + value);
|
|
838
|
-
}
|
|
839
|
-
}
|
|
840
|
-
function assertSelectorNotEmpty(value) {
|
|
841
|
-
if (!value) throw new Error("selector cannot be empty");
|
|
842
|
-
}
|
|
843
|
-
function assertLocalSelector(value) {
|
|
844
|
-
if (!isLocalSelector(value)) throw new Error("selector must target the current element only and cannot contain tags, combinators, or multiple selectors");
|
|
845
|
-
}
|
|
846
|
-
function assertPseudoArgSelector(value) {
|
|
847
|
-
if (!isPseudoArgSelector(value)) throw new Error("pseudo selector argument must contain only tags or selectors targeting the current element");
|
|
848
|
-
}
|
|
849
|
-
function assertTagSelector(value) {
|
|
850
|
-
if (!isTagSelector(value)) throw new Error("selector must be a single tag selector");
|
|
851
|
-
}
|
|
852
|
-
function assertAttrSelector(value) {
|
|
853
|
-
if (!isAttrArg(value)) throw new Error("attribute selector value must not include \"[\" or \"]\"");
|
|
854
|
-
}
|
|
855
|
-
function assertRawValue(value) {
|
|
856
|
-
if (!isRawValue(value)) throw new Error("value must not contain \"{\" or \"}\"");
|
|
857
|
-
}
|
|
858
|
-
function assertMediaQuery(value) {
|
|
859
|
-
if (!isRawValue(value)) throw new Error("media query must not contain \"{\" or \"}\"");
|
|
860
|
-
}
|
|
861
|
-
function assertSupportsQuery(value) {
|
|
862
|
-
if (!isRawValue(value)) throw new Error("supports query must not contain \"{\" or \"}\"");
|
|
863
|
-
}
|
|
864
|
-
function assertContainerQuery(value) {
|
|
865
|
-
if (!isRawValue(value)) throw new Error("container query must not contain \"{\" or \"}\"");
|
|
866
|
-
}
|
|
867
|
-
//#endregion
|
|
868
|
-
//#region builder/data/check_selector.ts
|
|
869
|
-
function checkSelector(fnPrefix, fnName, fnSelector, arg) {
|
|
870
|
-
let message = null;
|
|
871
|
-
try {
|
|
872
|
-
assertSelector(fnSelector.assert, arg);
|
|
873
|
-
} catch (error) {
|
|
874
|
-
if (typeof error === "string" && error.trim()) message = error;
|
|
875
|
-
else if (typeof error === "object" && error && error instanceof Error) message = (error.message || "").trim();
|
|
876
|
-
else message = "selector is invalid: " + arg;
|
|
877
|
-
}
|
|
878
|
-
if (!message) return;
|
|
879
|
-
throw traceError(`${fnPrefix}${fnName}(${arg || ""}): ${message}`);
|
|
880
|
-
}
|
|
1014
|
+
...PseudoSelectors,
|
|
1015
|
+
...PseudoElementSelectors,
|
|
1016
|
+
...PseudoArgSelectors,
|
|
1017
|
+
...ArgSelectors,
|
|
1018
|
+
...AtRuleSelectors
|
|
1019
|
+
}, [
|
|
1020
|
+
"link",
|
|
1021
|
+
"visited",
|
|
1022
|
+
"hover",
|
|
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);
|
|
881
1047
|
//#endregion
|
|
882
1048
|
//#region builder/data/create.ts
|
|
883
1049
|
function createStyleData(callsite) {
|
|
@@ -912,6 +1078,28 @@ function createSlotOverrideData(callsite, slotId) {
|
|
|
912
1078
|
[BUILDER_SLOT_ID]: slotId
|
|
913
1079
|
};
|
|
914
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
|
+
}
|
|
915
1103
|
function createScopeData(callsite) {
|
|
916
1104
|
return {
|
|
917
1105
|
[BUILDER_TYPE]: 4,
|
|
@@ -950,7 +1138,7 @@ function createNameFormatter(keys) {
|
|
|
950
1138
|
const name = getFormatFn(format)(info);
|
|
951
1139
|
if (!hash) return name;
|
|
952
1140
|
if (name.includes(HASH_TOKEN)) return name.replace(HASH_TOKEN, hash);
|
|
953
|
-
return name ? name + "
|
|
1141
|
+
return name ? name + "--" + hash : hash;
|
|
954
1142
|
};
|
|
955
1143
|
}
|
|
956
1144
|
function compileFormat(format, keySet) {
|
|
@@ -1043,40 +1231,51 @@ const formatClassName = createNameFormatter([
|
|
|
1043
1231
|
"selector",
|
|
1044
1232
|
"value"
|
|
1045
1233
|
]);
|
|
1046
|
-
const
|
|
1234
|
+
const formatTransformClassName = createNameFormatter(["className"]);
|
|
1047
1235
|
function getDebugClassName(format, hash, info) {
|
|
1048
|
-
return formatClassName(format || "[(atRule)-][(scopeSelector)-](property)[-(selector)][-(value)]
|
|
1049
|
-
}
|
|
1050
|
-
function getDebugScopeClassName(format, info) {
|
|
1051
|
-
return formatScopeClassName(format || "-(className)", null, info);
|
|
1052
|
-
}
|
|
1053
|
-
//#endregion
|
|
1054
|
-
//#region atomic/utils/css.ts
|
|
1055
|
-
function getCssVar(varName, value) {
|
|
1056
|
-
return "var(" + varName + ", " + escapeCssValue(value) + ")";
|
|
1236
|
+
return formatClassName(format || "[(atRule)-][(scopeSelector)-](property)[-(selector)][-(value)]--$hash", hash, info);
|
|
1057
1237
|
}
|
|
1058
|
-
function
|
|
1059
|
-
return
|
|
1238
|
+
function getDebugSheetClassName(format, hash, info) {
|
|
1239
|
+
return formatClassName(format || "sheet-(property)[-(value)]--$hash", hash, info);
|
|
1060
1240
|
}
|
|
1061
|
-
function
|
|
1062
|
-
|
|
1063
|
-
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);
|
|
1064
1243
|
}
|
|
1244
|
+
//#endregion
|
|
1245
|
+
//#region atomic/utils/cssIdent.ts
|
|
1065
1246
|
function escapeCssIdent(ident) {
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
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;
|
|
1070
1275
|
}
|
|
1071
1276
|
function sanitizeCssIdentName(value, fallback = "") {
|
|
1072
1277
|
return value.replace(/[^a-zA-Z0-9_-]+/g, "-").replace(/^-+|-+$/g, "") || fallback;
|
|
1073
1278
|
}
|
|
1074
|
-
function getIdentifierSafeHash(value) {
|
|
1075
|
-
const hash = hashString(value);
|
|
1076
|
-
const first = hash.charCodeAt(0);
|
|
1077
|
-
if (first < 48 || first > 57) return hash;
|
|
1078
|
-
return String.fromCharCode(97 + first - 48) + hash.slice(1);
|
|
1079
|
-
}
|
|
1080
1279
|
//#endregion
|
|
1081
1280
|
//#region atomic/utils/debug.ts
|
|
1082
1281
|
function normalizeDebugKeywordValue(value) {
|
|
@@ -1233,45 +1432,96 @@ function parseAtRule(rule) {
|
|
|
1233
1432
|
if (normalized.startsWith("@supports")) return compressQuery(normalized.slice(9));
|
|
1234
1433
|
return compressQuery(normalized);
|
|
1235
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
|
+
}
|
|
1236
1453
|
//#endregion
|
|
1237
1454
|
//#region atomic/utils/selector.ts
|
|
1238
|
-
function getSelectorText(selector) {
|
|
1239
|
-
return Array.isArray(selector) ? selector[0] : selector;
|
|
1455
|
+
function getSelectorText$1(selector) {
|
|
1456
|
+
return stripSheetSelectorAnchor(Array.isArray(selector) ? selector[0] : selector);
|
|
1240
1457
|
}
|
|
1241
1458
|
function getSelectorHash(selector) {
|
|
1242
1459
|
return Array.isArray(selector) ? selector.join("|") : selector;
|
|
1243
1460
|
}
|
|
1244
|
-
function getSelectorPriority(selector) {
|
|
1461
|
+
function getSelectorPriority$1(selector) {
|
|
1245
1462
|
if (!selector) return 0;
|
|
1246
1463
|
return Array.isArray(selector) ? selector[1] : 0;
|
|
1247
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
|
+
}
|
|
1248
1485
|
//#endregion
|
|
1249
1486
|
//#region atomic/className.ts
|
|
1250
|
-
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) {
|
|
1251
1488
|
let hash = property;
|
|
1252
1489
|
hash += "\n" + (priority || "");
|
|
1490
|
+
if (important) hash += "\nimportant";
|
|
1253
1491
|
hash += "\n" + value;
|
|
1254
1492
|
hash += "\n" + (selector ? getSelectorHash(selector) : "");
|
|
1255
1493
|
hash += "\n" + (parentSelector ? getSelectorHash(parentSelector) : "");
|
|
1256
1494
|
hash += "\n" + (atRule ? atRule.map(getSelectorHash).join("\n") : "");
|
|
1257
1495
|
hash += "\n" + getCallsiteHash(callsite, localClassName);
|
|
1258
|
-
hash = getIdentifierSafeHash(hash);
|
|
1496
|
+
hash = getIdentifierSafeHash(hash, hashLength ?? getRuntimeClassNameHashLength(debugClassName));
|
|
1259
1497
|
if (!debugClassName) return hash;
|
|
1498
|
+
if (transformClassName) return getDebugTransformClassName(transformClassNameFormat, hash, { className: transformClassName });
|
|
1260
1499
|
const propertyName = getDebugPropertyName(property, value);
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
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,
|
|
1265
1505
|
property: propertyName ? propertyName.property : property,
|
|
1266
1506
|
value: propertyName ? propertyName.value ?? propertyName.arbitraryValue : null
|
|
1267
1507
|
});
|
|
1268
1508
|
}
|
|
1269
|
-
function
|
|
1270
|
-
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
|
+
});
|
|
1516
|
+
}
|
|
1517
|
+
function getClassNameHashLength(options) {
|
|
1518
|
+
if (options.debugClassName && options.isDev) return options.devHashLength ?? options.cssHashLength ?? 5;
|
|
1519
|
+
return options.cssHashLength ?? 7;
|
|
1271
1520
|
}
|
|
1272
|
-
function getClassNameDedupe(property, priority, selector, parentSelector, atRule) {
|
|
1521
|
+
function getClassNameDedupe(property, priority, important, selector, parentSelector, atRule) {
|
|
1273
1522
|
let hash = property;
|
|
1274
1523
|
hash += "\n" + (priority || "");
|
|
1524
|
+
if (important) hash += "\nimportant";
|
|
1275
1525
|
hash += "\n" + (selector ? getSelectorHash(selector) : "");
|
|
1276
1526
|
hash += "\n" + (parentSelector ? getSelectorHash(parentSelector) : "");
|
|
1277
1527
|
hash += "\n" + (atRule ? atRule.map(getSelectorHash).join("\n") : "");
|
|
@@ -1308,7 +1558,8 @@ function mergeScopeData(scope, callsite, items, debug, parentSelector, scopeAtRu
|
|
|
1308
1558
|
let source;
|
|
1309
1559
|
let item;
|
|
1310
1560
|
let lookupIndex;
|
|
1311
|
-
let
|
|
1561
|
+
let weight;
|
|
1562
|
+
let important;
|
|
1312
1563
|
let value;
|
|
1313
1564
|
let atRule;
|
|
1314
1565
|
let dedupe;
|
|
@@ -1319,7 +1570,7 @@ function mergeScopeData(scope, callsite, items, debug, parentSelector, scopeAtRu
|
|
|
1319
1570
|
source = sourceItems[i];
|
|
1320
1571
|
if (!source) continue;
|
|
1321
1572
|
if (isStyleTokenOverrideData(source)) {
|
|
1322
|
-
addTokenOverride(source, styles, lookup);
|
|
1573
|
+
addTokenOverride$1(source, styles, lookup);
|
|
1323
1574
|
continue;
|
|
1324
1575
|
}
|
|
1325
1576
|
if (isScopeData(source)) {
|
|
@@ -1327,7 +1578,7 @@ function mergeScopeData(scope, callsite, items, debug, parentSelector, scopeAtRu
|
|
|
1327
1578
|
for (let j = 0, len = scopeItems.length; j < len; j++) {
|
|
1328
1579
|
item = scopeItems[j];
|
|
1329
1580
|
if (isStyleTokenOverrideData(item)) {
|
|
1330
|
-
addTokenOverride(item, styles, lookup);
|
|
1581
|
+
addTokenOverride$1(item, styles, lookup);
|
|
1331
1582
|
continue;
|
|
1332
1583
|
}
|
|
1333
1584
|
if (Array.isArray(item) || item.type !== 4) {
|
|
@@ -1348,13 +1599,10 @@ function mergeScopeData(scope, callsite, items, debug, parentSelector, scopeAtRu
|
|
|
1348
1599
|
itemDebug = getMergedScopeDebug(debug, scopeItem);
|
|
1349
1600
|
itemCallsite = getDebugFieldCallsite(itemDebug ?? null, scopeItem.property) ?? callsite ?? scopeItem.callsite;
|
|
1350
1601
|
value = scopeItem.value;
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
}
|
|
1356
|
-
dedupe = getClassNameDedupe(scopeItem.property, priority, scopeItem.selector, scopeItem.parentSelector, scopeItem.atRule);
|
|
1357
|
-
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);
|
|
1358
1606
|
scopeItem.dedupe = dedupe;
|
|
1359
1607
|
scopeItem.className = className;
|
|
1360
1608
|
scopeItem.callsite = itemCallsite;
|
|
@@ -1391,7 +1639,10 @@ function mergeScopeData(scope, callsite, items, debug, parentSelector, scopeAtRu
|
|
|
1391
1639
|
dedupe: "",
|
|
1392
1640
|
className: "",
|
|
1393
1641
|
property: overrideItem.property,
|
|
1642
|
+
weight: overrideItem.weight,
|
|
1643
|
+
important: overrideItem.important,
|
|
1394
1644
|
value: overrideItem.value,
|
|
1645
|
+
transformClassName: overrideItem.transformClassName,
|
|
1395
1646
|
token: overrideItem.token,
|
|
1396
1647
|
selector: overrideItem.selector,
|
|
1397
1648
|
atRule,
|
|
@@ -1401,13 +1652,10 @@ function mergeScopeData(scope, callsite, items, debug, parentSelector, scopeAtRu
|
|
|
1401
1652
|
parentSelector
|
|
1402
1653
|
};
|
|
1403
1654
|
value = scopeItem.value;
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
}
|
|
1409
|
-
dedupe = getClassNameDedupe(scopeItem.property, priority, scopeItem.selector, parentSelector, scopeItem.atRule);
|
|
1410
|
-
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);
|
|
1411
1659
|
scopeItem.dedupe = dedupe;
|
|
1412
1660
|
scopeItem.className = className;
|
|
1413
1661
|
const lookupKey = getScopeLookupKey(slotId, dedupe);
|
|
@@ -1418,7 +1666,7 @@ function mergeScopeData(scope, callsite, items, debug, parentSelector, scopeAtRu
|
|
|
1418
1666
|
}
|
|
1419
1667
|
return data;
|
|
1420
1668
|
}
|
|
1421
|
-
function addTokenOverride(item, styles, lookup) {
|
|
1669
|
+
function addTokenOverride$1(item, styles, lookup) {
|
|
1422
1670
|
const lookupKey = getTokenLookupKey(getStyleTokenId(item));
|
|
1423
1671
|
const lookupIndex = lookup[lookupKey];
|
|
1424
1672
|
if (typeof lookupIndex === "number") styles[lookupIndex] = item;
|
|
@@ -1472,10 +1720,23 @@ function getScopeLookupKey(slotId, dedupe) {
|
|
|
1472
1720
|
function getTokenLookupKey(tokenId) {
|
|
1473
1721
|
return "token\0" + tokenId;
|
|
1474
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
|
+
}
|
|
1475
1735
|
const formatTokenName = createNameFormatter(["name"]);
|
|
1476
1736
|
function getTokenVarName(token, format) {
|
|
1477
1737
|
const id = getStyleTokenId(token);
|
|
1478
|
-
|
|
1738
|
+
const debugName = getStyleTokenName(token);
|
|
1739
|
+
return "--" + formatTokenName(format || "token[-(name)]-$hash", getIdentifierSafeHash(id, CSS_CONFIG.hashLength), { name: debugName });
|
|
1479
1740
|
}
|
|
1480
1741
|
function getTokenVar(token, format) {
|
|
1481
1742
|
return getTokenVarFallback(token, format);
|
|
@@ -1550,6 +1811,31 @@ function shouldAppendCssPx(property) {
|
|
|
1550
1811
|
return !UNITLESS.has(property);
|
|
1551
1812
|
}
|
|
1552
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
|
|
1553
1839
|
//#region style/valueRef.ts
|
|
1554
1840
|
const AT_RULE_REF = symbol("atRule.ref");
|
|
1555
1841
|
function createAtRuleRef(data) {
|
|
@@ -1562,6 +1848,19 @@ function isAtRuleRef(value) {
|
|
|
1562
1848
|
return !!value && typeof value === "object" && value[AT_RULE_REF] === true;
|
|
1563
1849
|
}
|
|
1564
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
|
|
1565
1864
|
//#region builder/data/merge/style.ts
|
|
1566
1865
|
function mergeBuilderData(create, callsite, source, style, debug, selector, atRule, type) {
|
|
1567
1866
|
if (!style) return source;
|
|
@@ -1572,13 +1871,15 @@ function mergeBuilderData(create, callsite, source, style, debug, selector, atRu
|
|
|
1572
1871
|
let itemData;
|
|
1573
1872
|
let valueRaw;
|
|
1574
1873
|
let value;
|
|
1575
|
-
let
|
|
1874
|
+
let weight;
|
|
1875
|
+
let important;
|
|
1576
1876
|
let itemCallsite;
|
|
1577
1877
|
let className;
|
|
1578
1878
|
let dedupe;
|
|
1579
1879
|
let token;
|
|
1580
1880
|
let ref;
|
|
1581
1881
|
let variableName;
|
|
1882
|
+
let transformClassName;
|
|
1582
1883
|
let lookupIndex;
|
|
1583
1884
|
if (isStyleData(style)) {
|
|
1584
1885
|
const stylesItems = style[BUILDER_STATE].items;
|
|
@@ -1592,6 +1893,7 @@ function mergeBuilderData(create, callsite, source, style, debug, selector, atRu
|
|
|
1592
1893
|
continue;
|
|
1593
1894
|
}
|
|
1594
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 });
|
|
1595
1897
|
if (type === 2 && slotId !== null) item = Object.assign({}, item, {
|
|
1596
1898
|
type: 2,
|
|
1597
1899
|
slotId
|
|
@@ -1600,6 +1902,7 @@ function mergeBuilderData(create, callsite, source, style, debug, selector, atRu
|
|
|
1600
1902
|
type: 3,
|
|
1601
1903
|
slotId
|
|
1602
1904
|
});
|
|
1905
|
+
else if (type === 8) item = Object.assign({}, item, { type: 1 });
|
|
1603
1906
|
const itemDebug = getMergedStyleDebug(debug, item);
|
|
1604
1907
|
const debugCallsite = getDebugFieldCallsite(itemDebug, item.property);
|
|
1605
1908
|
if (debugCallsite) item = Object.assign({}, item, {
|
|
@@ -1611,17 +1914,19 @@ function mergeBuilderData(create, callsite, source, style, debug, selector, atRu
|
|
|
1611
1914
|
}
|
|
1612
1915
|
} else for (const property in style) {
|
|
1613
1916
|
valueRaw = style[property];
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
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;
|
|
1618
1924
|
}
|
|
1619
1925
|
ref = isAtRuleRef(valueRaw) ? valueRaw : null;
|
|
1620
1926
|
if (ref) valueRaw = ref.value;
|
|
1621
1927
|
token = isStyleTokenData(valueRaw) ? valueRaw : null;
|
|
1622
1928
|
variableName = getDebugFieldVarName(debug, property);
|
|
1623
1929
|
value = variableName && token ? getCssVarRawFallback(variableName, getTokenVar(token, CSS_CONFIG.tokenNameFormat ?? null)) : token ? getTokenVar(token, CSS_CONFIG.tokenNameFormat ?? null) : String(valueRaw ?? "");
|
|
1624
|
-
value = priority !== null ? [value, priority] : value;
|
|
1625
1930
|
itemCallsite = getDebugFieldCallsite(debug, property) ?? callsite;
|
|
1626
1931
|
itemData = {
|
|
1627
1932
|
runtime: runtimeType,
|
|
@@ -1630,7 +1935,10 @@ function mergeBuilderData(create, callsite, source, style, debug, selector, atRu
|
|
|
1630
1935
|
dedupe: "",
|
|
1631
1936
|
className: "",
|
|
1632
1937
|
property,
|
|
1938
|
+
weight,
|
|
1939
|
+
important,
|
|
1633
1940
|
value,
|
|
1941
|
+
transformClassName,
|
|
1634
1942
|
variable: ref ? [3, ref] : variableName && token ? [
|
|
1635
1943
|
1,
|
|
1636
1944
|
variableName,
|
|
@@ -1642,7 +1950,7 @@ function mergeBuilderData(create, callsite, source, style, debug, selector, atRu
|
|
|
1642
1950
|
atRule,
|
|
1643
1951
|
callsite: itemCallsite
|
|
1644
1952
|
};
|
|
1645
|
-
if (type === 1) {
|
|
1953
|
+
if (type === 1 || type === 8) {
|
|
1646
1954
|
items.push({
|
|
1647
1955
|
...itemData,
|
|
1648
1956
|
type: 1
|
|
@@ -1689,13 +1997,10 @@ function mergeBuilderData(create, callsite, source, style, debug, selector, atRu
|
|
|
1689
1997
|
}
|
|
1690
1998
|
const runtimeItem = item;
|
|
1691
1999
|
value = runtimeItem.value;
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
}
|
|
1697
|
-
dedupe = getClassNameDedupe(runtimeItem.property, priority, runtimeItem.selector, null, runtimeItem.atRule);
|
|
1698
|
-
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);
|
|
1699
2004
|
runtimeItem.dedupe = dedupe;
|
|
1700
2005
|
runtimeItem.className = className;
|
|
1701
2006
|
lookupIndex = lookup[dedupe];
|
|
@@ -1704,6 +2009,52 @@ function mergeBuilderData(create, callsite, source, style, debug, selector, atRu
|
|
|
1704
2009
|
}
|
|
1705
2010
|
return data;
|
|
1706
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
|
+
}
|
|
1707
2058
|
function getMergedStyleDebug(debug, item) {
|
|
1708
2059
|
if (!debug) return null;
|
|
1709
2060
|
if (debug.fields?.[item.property]) return debug;
|
|
@@ -1747,29 +2098,189 @@ function withDebugSource$1(loc, debug) {
|
|
|
1747
2098
|
];
|
|
1748
2099
|
}
|
|
1749
2100
|
//#endregion
|
|
1750
|
-
//#region builder/
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
const
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
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}`);
|
|
1767
2277
|
}
|
|
1768
2278
|
//#endregion
|
|
1769
2279
|
//#region builder/utils.ts
|
|
1770
2280
|
const FnPrefixStyle = "style.";
|
|
1771
2281
|
const FnPrefixSlot = "slot.";
|
|
1772
2282
|
const FnPrefixScope = "scope.";
|
|
2283
|
+
const FnPrefixSelector = "selector.";
|
|
1773
2284
|
function runtimeCallsite() {
|
|
1774
2285
|
return traceCallsite();
|
|
1775
2286
|
}
|
|
@@ -1830,9 +2341,9 @@ function createAtRuleFn(mergeData, fns, createFnResult, fnPrefix, fnName, fnSele
|
|
|
1830
2341
|
let arg;
|
|
1831
2342
|
let style;
|
|
1832
2343
|
let debug;
|
|
1833
|
-
let
|
|
2344
|
+
let weight = null;
|
|
1834
2345
|
if (hasArg) if (isMedia && typeof params[0] === "number") {
|
|
1835
|
-
|
|
2346
|
+
weight = params[0];
|
|
1836
2347
|
arg = params[1];
|
|
1837
2348
|
style = params[2];
|
|
1838
2349
|
debug = params[3];
|
|
@@ -1842,7 +2353,7 @@ function createAtRuleFn(mergeData, fns, createFnResult, fnPrefix, fnName, fnSele
|
|
|
1842
2353
|
debug = params[2];
|
|
1843
2354
|
}
|
|
1844
2355
|
else if (isMedia && typeof params[0] === "number") {
|
|
1845
|
-
|
|
2356
|
+
weight = params[0];
|
|
1846
2357
|
arg = fnSelector.selector;
|
|
1847
2358
|
style = params[1];
|
|
1848
2359
|
debug = params[2];
|
|
@@ -1862,7 +2373,7 @@ function createAtRuleFn(mergeData, fns, createFnResult, fnPrefix, fnName, fnSele
|
|
|
1862
2373
|
selector = hasArg ? before + normalizeSelectorArg(selector) + after : selector;
|
|
1863
2374
|
for (let j = 0, len = items.length; j < len; j++) {
|
|
1864
2375
|
const item = items[j];
|
|
1865
|
-
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]);
|
|
1866
2377
|
}
|
|
1867
2378
|
}
|
|
1868
2379
|
return createFnResult(data, fns);
|
|
@@ -1929,9 +2440,9 @@ function createScopeAtRuleFn(fnPrefix, fnName, fnSelector, cloneScope) {
|
|
|
1929
2440
|
let arg;
|
|
1930
2441
|
let data;
|
|
1931
2442
|
let debug;
|
|
1932
|
-
let
|
|
2443
|
+
let weight = null;
|
|
1933
2444
|
if (hasArg) if (isMedia && typeof params[0] === "number") {
|
|
1934
|
-
|
|
2445
|
+
weight = params[0];
|
|
1935
2446
|
arg = params[1];
|
|
1936
2447
|
data = params[2];
|
|
1937
2448
|
debug = params[3];
|
|
@@ -1941,7 +2452,7 @@ function createScopeAtRuleFn(fnPrefix, fnName, fnSelector, cloneScope) {
|
|
|
1941
2452
|
debug = params[2];
|
|
1942
2453
|
}
|
|
1943
2454
|
else if (isMedia && typeof params[0] === "number") {
|
|
1944
|
-
|
|
2455
|
+
weight = params[0];
|
|
1945
2456
|
arg = fnSelector.selector;
|
|
1946
2457
|
data = params[1];
|
|
1947
2458
|
debug = params[2];
|
|
@@ -1958,7 +2469,7 @@ function createScopeAtRuleFn(fnPrefix, fnName, fnSelector, cloneScope) {
|
|
|
1958
2469
|
selector = args[i];
|
|
1959
2470
|
if (hasArg && DEV_CONFIG.isCheckSelectorEnabled) checkSelector(fnPrefix, fnName, fnSelector, selector);
|
|
1960
2471
|
selector = hasArg ? before + normalizeSelectorArg(selector) + after : selector;
|
|
1961
|
-
result = mergeScopeItems(result, callsite, data, debug ?? null, null,
|
|
2472
|
+
result = mergeScopeItems(result, callsite, data, debug ?? null, null, weight !== null ? [selector, weight] : selector, cloneScope);
|
|
1962
2473
|
}
|
|
1963
2474
|
return result;
|
|
1964
2475
|
};
|
|
@@ -2035,6 +2546,20 @@ function createSlotBuilder(selectors, transform) {
|
|
|
2035
2546
|
traceMarker(fn, "slot");
|
|
2036
2547
|
return fn;
|
|
2037
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
|
+
}
|
|
2038
2563
|
function createScopeBuilder(selectors) {
|
|
2039
2564
|
const fns = createScopeFns(selectors, FnPrefixScope, cloneScope);
|
|
2040
2565
|
const fn = (items, debug) => {
|
|
@@ -2050,6 +2575,34 @@ function createScopeBuilder(selectors) {
|
|
|
2050
2575
|
traceMarker(fn, "scope");
|
|
2051
2576
|
return fn;
|
|
2052
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
|
+
}
|
|
2053
2606
|
function createCallableSlot(data, fns, overrideFns, transform) {
|
|
2054
2607
|
const slotId = data[BUILDER_SLOT_ID];
|
|
2055
2608
|
const callable = ((style, debug) => {
|
|
@@ -2492,7 +3045,7 @@ function getCssPropertyName(property) {
|
|
|
2492
3045
|
function createAtRuleNameFormatter(defaultFormat, prefix) {
|
|
2493
3046
|
const formatter = createNameFormatter(["name"]);
|
|
2494
3047
|
return (format, id, info) => {
|
|
2495
|
-
const hash = getIdentifierSafeHash(id);
|
|
3048
|
+
const hash = getIdentifierSafeHash(id, CSS_CONFIG.hashLength);
|
|
2496
3049
|
const name = formatter(format || defaultFormat, hash, info);
|
|
2497
3050
|
if (!prefix) return name;
|
|
2498
3051
|
return name.startsWith(prefix) ? name : prefix + name;
|
|
@@ -2656,7 +3209,499 @@ function buildPropertyCss(format, name, id, descriptors, tokens, tokenLookup, to
|
|
|
2656
3209
|
name
|
|
2657
3210
|
};
|
|
2658
3211
|
}
|
|
2659
|
-
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 }));
|
|
2660
3705
|
//#endregion
|
|
2661
3706
|
//#region style/keyframes.ts
|
|
2662
3707
|
function transformKeyframes(frames, transform) {
|
|
@@ -2684,9 +3729,11 @@ function createStyleFn(args) {
|
|
|
2684
3729
|
const fnStyle = createStyleBuilder(selectors, transform);
|
|
2685
3730
|
const fnSlot = createSlotBuilder(selectors, transform);
|
|
2686
3731
|
const fnScope = createScopeBuilder(selectors);
|
|
2687
|
-
const
|
|
2688
|
-
|
|
3732
|
+
const fnSelector = createSelectorBuilder(selectors, transform);
|
|
3733
|
+
const fnWeight = (value, weight) => {
|
|
3734
|
+
return weightValue(value, weight);
|
|
2689
3735
|
};
|
|
3736
|
+
const fnImportant = (value) => importantValue(value);
|
|
2690
3737
|
const fnRaw = (style) => style;
|
|
2691
3738
|
const fnPlain = (style) => style;
|
|
2692
3739
|
const fnKeyframes = ((frames, stableId) => createStyleKeyframes(frames, transform ?? null, stableId));
|
|
@@ -2698,16 +3745,18 @@ function createStyleFn(args) {
|
|
|
2698
3745
|
const style = fnStyle;
|
|
2699
3746
|
style.slot = fnSlot;
|
|
2700
3747
|
style.scope = fnScope;
|
|
2701
|
-
style.
|
|
3748
|
+
style.weight = fnWeight;
|
|
3749
|
+
style.important = fnImportant;
|
|
2702
3750
|
style.raw = fnRaw;
|
|
2703
3751
|
style.plain = fnPlain;
|
|
2704
3752
|
style.keyframes = fnKeyframes;
|
|
2705
3753
|
style.merge = fnMerge;
|
|
2706
|
-
|
|
3754
|
+
style.selector = fnSelector;
|
|
3755
|
+
assignStyleFnMeta(style, {
|
|
3756
|
+
mode: "StyleObject",
|
|
2707
3757
|
selectors,
|
|
2708
3758
|
transform: transform ?? null
|
|
2709
|
-
};
|
|
2710
|
-
Object.assign(style, { [META]: meta });
|
|
3759
|
+
});
|
|
2711
3760
|
return { style };
|
|
2712
3761
|
}
|
|
2713
3762
|
function mergeStyleResult(target, style) {
|
|
@@ -2716,12 +3765,17 @@ function mergeStyleResult(target, style) {
|
|
|
2716
3765
|
if (typeof chainMerge === "function") return chainMerge.call(target, style);
|
|
2717
3766
|
return target;
|
|
2718
3767
|
}
|
|
3768
|
+
function assignStyleFnMeta(styleFn, meta) {
|
|
3769
|
+
Object.assign(styleFn, { [META]: meta });
|
|
3770
|
+
return styleFn;
|
|
3771
|
+
}
|
|
2719
3772
|
function getStyleFnMeta(styleFn) {
|
|
2720
3773
|
return styleFn[META];
|
|
2721
3774
|
}
|
|
2722
3775
|
//#endregion
|
|
2723
3776
|
//#region compiler/utils/import_source.ts
|
|
2724
3777
|
const DefaultStyleFnMeta = {
|
|
3778
|
+
mode: "StyleObject",
|
|
2725
3779
|
selectors: PrioritySelectors,
|
|
2726
3780
|
transform: null
|
|
2727
3781
|
};
|
|
@@ -2738,9 +3792,11 @@ function createImportSourceMatcher(importSources) {
|
|
|
2738
3792
|
meta: DefaultStyleFnMeta
|
|
2739
3793
|
});
|
|
2740
3794
|
importSources?.forEach((entry) => {
|
|
3795
|
+
const meta = entry.meta ?? (entry.styleFn ? getStyleFnMeta(entry.styleFn) : null);
|
|
3796
|
+
if (!meta) return;
|
|
2741
3797
|
addImportSourceEntry(state, {
|
|
2742
3798
|
...entry,
|
|
2743
|
-
meta
|
|
3799
|
+
meta
|
|
2744
3800
|
});
|
|
2745
3801
|
});
|
|
2746
3802
|
return (source) => {
|
|
@@ -2832,65 +3888,6 @@ function isGlobPattern(source) {
|
|
|
2832
3888
|
return /[*?[\]{}]/.test(source) || /[!+@?*]\(/.test(source);
|
|
2833
3889
|
}
|
|
2834
3890
|
//#endregion
|
|
2835
|
-
//#region builder/extract/utils.ts
|
|
2836
|
-
function createExtractedData(type, slotId) {
|
|
2837
|
-
const data = {
|
|
2838
|
-
[BUILDER_TYPE]: type,
|
|
2839
|
-
[BUILDER_STATE]: {
|
|
2840
|
-
items: [],
|
|
2841
|
-
lookup: {}
|
|
2842
|
-
},
|
|
2843
|
-
[BUILDER_CALLSITE]: null
|
|
2844
|
-
};
|
|
2845
|
-
if (slotId !== void 0) data[BUILDER_SLOT_ID] = slotId;
|
|
2846
|
-
return data;
|
|
2847
|
-
}
|
|
2848
|
-
function copyExtractedData(target, source) {
|
|
2849
|
-
const mutable = target;
|
|
2850
|
-
mutable[BUILDER_TYPE] = source[BUILDER_TYPE];
|
|
2851
|
-
mutable[BUILDER_STATE] = source[BUILDER_STATE];
|
|
2852
|
-
mutable[BUILDER_CALLSITE] = source[BUILDER_CALLSITE];
|
|
2853
|
-
if (source[BUILDER_SLOT_ID] !== void 0) mutable[BUILDER_SLOT_ID] = source[BUILDER_SLOT_ID];
|
|
2854
|
-
}
|
|
2855
|
-
function createExtractedScopeTarget(scope, slot) {
|
|
2856
|
-
return {
|
|
2857
|
-
[BUILDER_TYPE]: 5,
|
|
2858
|
-
[BUILDER_SCOPE]: scope,
|
|
2859
|
-
[BUILDER_SCOPE_ID]: slot[BUILDER_SLOT_ID]
|
|
2860
|
-
};
|
|
2861
|
-
}
|
|
2862
|
-
function normalizeExtractedItems(type, slotId, items) {
|
|
2863
|
-
const normalized = [];
|
|
2864
|
-
let i = 0;
|
|
2865
|
-
while (i < items.length) {
|
|
2866
|
-
const item = items[i];
|
|
2867
|
-
const value = item[2];
|
|
2868
|
-
normalized.push(value === void 0 ? slotId === null ? [
|
|
2869
|
-
type,
|
|
2870
|
-
item[0],
|
|
2871
|
-
item[1]
|
|
2872
|
-
] : [
|
|
2873
|
-
type,
|
|
2874
|
-
slotId,
|
|
2875
|
-
item[0],
|
|
2876
|
-
item[1]
|
|
2877
|
-
] : slotId === null ? [
|
|
2878
|
-
type,
|
|
2879
|
-
item[0],
|
|
2880
|
-
item[1],
|
|
2881
|
-
value
|
|
2882
|
-
] : [
|
|
2883
|
-
type,
|
|
2884
|
-
slotId,
|
|
2885
|
-
item[0],
|
|
2886
|
-
item[1],
|
|
2887
|
-
value
|
|
2888
|
-
]);
|
|
2889
|
-
i++;
|
|
2890
|
-
}
|
|
2891
|
-
return normalized;
|
|
2892
|
-
}
|
|
2893
|
-
//#endregion
|
|
2894
3891
|
//#region builder/extract/scope.ts
|
|
2895
3892
|
function createExtractedScope(items) {
|
|
2896
3893
|
const scope = ((slot) => {
|
|
@@ -2901,6 +3898,16 @@ function createExtractedScope(items) {
|
|
|
2901
3898
|
return scope;
|
|
2902
3899
|
}
|
|
2903
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
|
|
2904
3911
|
//#region builder/extract/slot.ts
|
|
2905
3912
|
function createExtractedSlot(slotId, items) {
|
|
2906
3913
|
const slot = ((items) => {
|
|
@@ -2974,6 +3981,62 @@ function appendExtractedStyleTuples(target, source) {
|
|
|
2974
3981
|
}
|
|
2975
3982
|
}
|
|
2976
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
|
|
2977
4040
|
//#region style/utils/expose.ts
|
|
2978
4041
|
function exposeStyle(styles) {
|
|
2979
4042
|
return exposeStyleObject(styles);
|
|
@@ -2988,7 +4051,7 @@ function exposeStyleObject(source) {
|
|
|
2988
4051
|
return result;
|
|
2989
4052
|
}
|
|
2990
4053
|
function exposeStyleValue(value) {
|
|
2991
|
-
if (isStyleTokenData(value) || isSlotData(value)) return value;
|
|
4054
|
+
if (isStyleTokenData(value) || isSlotData(value) || isSelectorData(value)) return value;
|
|
2992
4055
|
if (!value || typeof value !== "object" || Array.isArray(value)) return void 0;
|
|
2993
4056
|
const exposed = exposeStyleObject(value);
|
|
2994
4057
|
return Reflect.ownKeys(exposed).length > 0 ? exposed : void 0;
|
|
@@ -3029,6 +4092,7 @@ function evaluateNode(node, scope) {
|
|
|
3029
4092
|
case "ParenthesizedExpression":
|
|
3030
4093
|
case "TSAsExpression":
|
|
3031
4094
|
case "TSNonNullExpression":
|
|
4095
|
+
case "TSSatisfiesExpression":
|
|
3032
4096
|
case "TSTypeAssertion": return evaluateNode(node.expression, scope);
|
|
3033
4097
|
default: return evalFail(`Cannot statically evaluate: ${node.type}`);
|
|
3034
4098
|
}
|
|
@@ -3101,14 +4165,14 @@ function evaluateMember(node, scope) {
|
|
|
3101
4165
|
if (!key.ok) return key;
|
|
3102
4166
|
const obj = evaluateNode(node.object, scope);
|
|
3103
4167
|
if (!obj.ok) return obj;
|
|
3104
|
-
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]);
|
|
3105
4169
|
return evalFail("Cannot index non-object");
|
|
3106
4170
|
}
|
|
3107
4171
|
const prop = node.property.name;
|
|
3108
4172
|
const obj = evaluateNode(node.object, scope);
|
|
3109
4173
|
if (!obj.ok) return obj;
|
|
3110
4174
|
if (obj.value == null) return evalFail(`Cannot access .${prop} on null/undefined`);
|
|
3111
|
-
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}`);
|
|
3112
4176
|
return evalOk(obj.value[prop]);
|
|
3113
4177
|
}
|
|
3114
4178
|
function evaluateObject(node, scope) {
|
|
@@ -3147,12 +4211,17 @@ function evaluateObject(node, scope) {
|
|
|
3147
4211
|
} else key = prop.key.type === "Identifier" ? prop.key.name : prop.key.value;
|
|
3148
4212
|
const val = evaluateNode(prop.value, scope);
|
|
3149
4213
|
if (!val.ok && isRequiredStaticStyleValueFail(val.reason)) return val;
|
|
3150
|
-
result[key] = val.ok ? val.value : createCompiledRuntimeValue(prop.value);
|
|
3151
|
-
if (prop.loc?.start)
|
|
3152
|
-
|
|
3153
|
-
|
|
3154
|
-
|
|
3155
|
-
|
|
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
|
+
}
|
|
3156
4225
|
} else return evalFail(`Cannot evaluate ObjectMethod in style object`);
|
|
3157
4226
|
i++;
|
|
3158
4227
|
}
|
|
@@ -3201,6 +4270,15 @@ function evaluateCall(node, scope) {
|
|
|
3201
4270
|
if (!Array.isArray(items.value)) return evalFail("createExtractedStyle items must be an array");
|
|
3202
4271
|
return evalOk(createExtractedStyle(items.value));
|
|
3203
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
|
+
}
|
|
3204
4282
|
if (imp && imp.source === "@fluentic/style/entry/prod/extract" && imp.name === "getExtractedStyleItems") {
|
|
3205
4283
|
const style = evaluateNode(node.arguments[0], scope);
|
|
3206
4284
|
if (!style.ok) return style;
|
|
@@ -3232,9 +4310,9 @@ function evaluateCall(node, scope) {
|
|
|
3232
4310
|
if (imp && STYLE_IMPORT_PATHS.has(imp.source) && imp.name === "createToken") {
|
|
3233
4311
|
const value = evaluateNode(node.arguments[0], scope);
|
|
3234
4312
|
if (!value.ok) return value;
|
|
3235
|
-
const
|
|
3236
|
-
if (!
|
|
3237
|
-
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));
|
|
3238
4316
|
}
|
|
3239
4317
|
if (imp && STYLE_IMPORT_PATHS.has(imp.source) && imp.name === "createKeyframes") {
|
|
3240
4318
|
const frames = evaluateNode(node.arguments[0], scope);
|
|
@@ -3301,16 +4379,39 @@ function evaluateCall(node, scope) {
|
|
|
3301
4379
|
const url = evaluateNode(node.arguments[0], scope);
|
|
3302
4380
|
if (!url.ok) return evalFail(`fontSrc url must be statically analyzable: ${url.reason}`);
|
|
3303
4381
|
if (typeof url.value !== "string") return evalFail("fontSrc url must be a static string");
|
|
3304
|
-
const format =
|
|
4382
|
+
const format = evaluateOptionalString(node.arguments[1], scope);
|
|
3305
4383
|
if (!format.ok) return evalFail(`fontSrc format must be statically analyzable: ${format.reason}`);
|
|
3306
4384
|
return evalOk(fontSrc(url.value, format.value));
|
|
3307
4385
|
}
|
|
3308
4386
|
if (imp && STYLE_IMPORT_PATHS.has(imp.source) && imp.name === "createTokens") {
|
|
3309
4387
|
const value = evaluateNode(node.arguments[0], scope);
|
|
3310
4388
|
if (!value.ok) return value;
|
|
3311
|
-
const
|
|
3312
|
-
if (!
|
|
3313
|
-
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);
|
|
3314
4415
|
}
|
|
3315
4416
|
if (imp && imp.source === "@fluentic/style/utils" && imp.name === "exposeStyle") {
|
|
3316
4417
|
const styles = evaluateNode(node.arguments[0], scope);
|
|
@@ -3321,13 +4422,13 @@ function evaluateCall(node, scope) {
|
|
|
3321
4422
|
if (imp && STYLE_IMPORT_PATHS.has(imp.source) && imp.name === "createValues") {
|
|
3322
4423
|
const hasNumberArg = node.arguments[0]?.type === "Identifier" && node.arguments[0].name === "Number";
|
|
3323
4424
|
const valuesNode = hasNumberArg ? node.arguments[1] : node.arguments[0];
|
|
3324
|
-
const
|
|
4425
|
+
const stableIdNode = hasNumberArg ? node.arguments[2] : node.arguments[1];
|
|
3325
4426
|
const values = evaluateNode(valuesNode, scope);
|
|
3326
4427
|
if (!values.ok) return values;
|
|
3327
|
-
const
|
|
3328
|
-
if (!
|
|
4428
|
+
const stableId = evaluateOptionalStableTokenId(stableIdNode, scope);
|
|
4429
|
+
if (!stableId.ok) return stableId;
|
|
3329
4430
|
if (!Array.isArray(values.value)) return evalFail("createValues values must be an array");
|
|
3330
|
-
return evalOk(createCompiledValues(values.value, scope, node.loc?.start, node,
|
|
4431
|
+
return evalOk(createCompiledValues(values.value, scope, node.loc?.start, node, stableId.value, hasNumberArg));
|
|
3331
4432
|
}
|
|
3332
4433
|
}
|
|
3333
4434
|
if (node.callee.type === "Identifier") {
|
|
@@ -3372,13 +4473,18 @@ function evaluateCall(node, scope) {
|
|
|
3372
4473
|
buildCss: (_name, tokens, tokenLookup, options) => buildKeyframesCss(format, stable.name, stable.id, transformedFrames, tokens, tokenLookup, options)
|
|
3373
4474
|
}));
|
|
3374
4475
|
}
|
|
3375
|
-
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)) {
|
|
3376
4477
|
const value = evaluateNode(node.arguments[0], scope);
|
|
3377
4478
|
if (!value.ok) return value;
|
|
3378
4479
|
const weight = evaluateNode(node.arguments[1], scope);
|
|
3379
4480
|
if (!weight.ok) return weight;
|
|
3380
|
-
if (typeof weight.value !== "number") return evalFail(
|
|
3381
|
-
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));
|
|
3382
4488
|
}
|
|
3383
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);
|
|
3384
4490
|
return evalFail(`Cannot statically evaluate: ${node.type}`);
|
|
@@ -3415,38 +4521,48 @@ function createCompiledTokenOverride(token, value, runtimeValue) {
|
|
|
3415
4521
|
if (isStyleTokenData(value)) return withRuntimeValue(runtimeValue, {
|
|
3416
4522
|
[TOKEN_ID]: getStyleTokenId(token),
|
|
3417
4523
|
[TOKEN_OVERRIDE]: true,
|
|
4524
|
+
[TOKEN_NAME]: getStyleTokenName(token),
|
|
3418
4525
|
value: value.value,
|
|
3419
4526
|
ref: value
|
|
3420
4527
|
});
|
|
3421
4528
|
return withRuntimeValue(runtimeValue, {
|
|
3422
4529
|
[TOKEN_ID]: getStyleTokenId(token),
|
|
3423
4530
|
[TOKEN_OVERRIDE]: true,
|
|
4531
|
+
[TOKEN_NAME]: getStyleTokenName(token),
|
|
3424
4532
|
value,
|
|
3425
4533
|
ref: null
|
|
3426
4534
|
});
|
|
3427
4535
|
}
|
|
3428
|
-
function createCompiledToken(value, scope, loc, runtimeValue,
|
|
3429
|
-
let tokenId =
|
|
4536
|
+
function createCompiledToken(value, scope, loc, runtimeValue, stableId, debugName) {
|
|
4537
|
+
let tokenId = stableId;
|
|
3430
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
|
+
});
|
|
3431
4545
|
return withRuntimeValue(runtimeValue, {
|
|
3432
4546
|
[TOKEN_ID]: tokenId,
|
|
4547
|
+
[TOKEN_NAME]: debugName === void 0 ? getStyleTokenNameFromId(stableId) : normalizeStyleTokenName(debugName),
|
|
3433
4548
|
value,
|
|
3434
4549
|
ref: null
|
|
3435
4550
|
});
|
|
3436
4551
|
}
|
|
3437
|
-
function createCompiledTokens(value, scope, loc, runtimeValue,
|
|
3438
|
-
const tokenGroupId =
|
|
4552
|
+
function createCompiledTokens(value, scope, loc, runtimeValue, stableId) {
|
|
4553
|
+
const tokenGroupId = stableId ?? createCompiledTokenGroupId(scope, loc);
|
|
4554
|
+
const tokenGroupName = getStyleTokenNameFromId(stableId);
|
|
3439
4555
|
if (Array.isArray(value)) {
|
|
3440
4556
|
const result = {};
|
|
3441
4557
|
for (let i = 0, len = value.length; i < len; i++) {
|
|
3442
4558
|
const item = value[i];
|
|
3443
|
-
result[item] = createCompiledToken(item, scope, loc, runtimeValue,
|
|
4559
|
+
result[item] = createCompiledToken(item, scope, loc, runtimeValue, getChildStableId(tokenGroupId, String(i)), getChildStyleTokenName(tokenGroupName, String(i)));
|
|
3444
4560
|
}
|
|
3445
4561
|
return result;
|
|
3446
4562
|
}
|
|
3447
4563
|
if (!value || typeof value !== "object") return {};
|
|
3448
4564
|
const result = {};
|
|
3449
|
-
assignCompiledTokenRecord(result, value, scope, loc, runtimeValue, tokenGroupId);
|
|
4565
|
+
assignCompiledTokenRecord(result, value, scope, loc, runtimeValue, tokenGroupId, tokenGroupName);
|
|
3450
4566
|
return result;
|
|
3451
4567
|
}
|
|
3452
4568
|
function createCompiledTokenGroupId(scope, loc) {
|
|
@@ -3458,22 +4574,24 @@ function createCompiledAtRuleStableId(scope, loc, value) {
|
|
|
3458
4574
|
id: (scope.styleFilePath ?? scope.filePath) + "\n" + (loc ? loc.line + ":" + loc.column : String(value))
|
|
3459
4575
|
};
|
|
3460
4576
|
}
|
|
3461
|
-
function assignCompiledTokenRecord(target, value, scope, loc, runtimeValue,
|
|
4577
|
+
function assignCompiledTokenRecord(target, value, scope, loc, runtimeValue, stableId, debugName) {
|
|
3462
4578
|
for (const key of Object.keys(value)) {
|
|
3463
4579
|
const item = value[key];
|
|
3464
|
-
const
|
|
4580
|
+
const itemStableId = getChildStableId(stableId, key);
|
|
4581
|
+
const itemDebugName = getChildStyleTokenName(debugName, key);
|
|
3465
4582
|
if (item && typeof item === "object" && !Array.isArray(item) && !isStyleTokenData(item)) {
|
|
3466
4583
|
const child = {};
|
|
3467
4584
|
target[key] = child;
|
|
3468
|
-
assignCompiledTokenRecord(child, item, scope, loc, runtimeValue,
|
|
3469
|
-
} 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);
|
|
3470
4587
|
}
|
|
3471
4588
|
}
|
|
3472
|
-
function createCompiledValues(values, scope, loc, runtimeValue,
|
|
4589
|
+
function createCompiledValues(values, scope, loc, runtimeValue, stableId, isNumber) {
|
|
3473
4590
|
const tokens = /* @__PURE__ */ new Map();
|
|
4591
|
+
const groupName = getStyleTokenNameFromId(stableId);
|
|
3474
4592
|
for (let i = 0, len = values.length; i < len; i++) {
|
|
3475
4593
|
const value = values[i];
|
|
3476
|
-
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))));
|
|
3477
4595
|
}
|
|
3478
4596
|
return {
|
|
3479
4597
|
[COMPILED_TOKEN_FACTORY]: true,
|
|
@@ -3481,6 +4599,8 @@ function createCompiledValues(values, scope, loc, runtimeValue, debugId, isNumbe
|
|
|
3481
4599
|
};
|
|
3482
4600
|
}
|
|
3483
4601
|
function parseCompiledValue(value, isNumber) {
|
|
4602
|
+
if (typeof value === "number" && Number.isFinite(value)) return value;
|
|
4603
|
+
value = String(value).split(/[;|]/)[0].trim();
|
|
3484
4604
|
if (!isNumber) return value;
|
|
3485
4605
|
const number = Number(value);
|
|
3486
4606
|
if (!Number.isFinite(number)) return value;
|
|
@@ -3489,7 +4609,10 @@ function parseCompiledValue(value, isNumber) {
|
|
|
3489
4609
|
function isCompiledTokenFactory(value) {
|
|
3490
4610
|
return !!value && typeof value === "object" && value[COMPILED_TOKEN_FACTORY] === true;
|
|
3491
4611
|
}
|
|
3492
|
-
function
|
|
4612
|
+
function evaluateOptionalStableTokenId(node, scope) {
|
|
4613
|
+
return evaluateOptionalString(node, scope);
|
|
4614
|
+
}
|
|
4615
|
+
function evaluateOptionalString(node, scope) {
|
|
3493
4616
|
if (!node) return evalOk(void 0);
|
|
3494
4617
|
const value = evaluateNode(node, scope);
|
|
3495
4618
|
if (!value.ok) return value;
|
|
@@ -3513,16 +4636,28 @@ function evaluateOptionalStableId(node, scope) {
|
|
|
3513
4636
|
id: stableId.id
|
|
3514
4637
|
});
|
|
3515
4638
|
}
|
|
3516
|
-
function
|
|
3517
|
-
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;
|
|
3518
4652
|
}
|
|
3519
4653
|
function withRuntimeValue(runtimeValue, token) {
|
|
3520
4654
|
return Object.assign({}, token, {
|
|
3521
4655
|
[TOKEN_ID]: token[TOKEN_ID],
|
|
4656
|
+
[TOKEN_NAME]: token[TOKEN_NAME] ?? null,
|
|
3522
4657
|
[COMPILED_RUNTIME_VALUE]: runtimeValue
|
|
3523
4658
|
});
|
|
3524
4659
|
}
|
|
3525
|
-
function createCompiledRuntimeValue(runtimeValue) {
|
|
4660
|
+
function createCompiledRuntimeValue$1(runtimeValue) {
|
|
3526
4661
|
return { [COMPILED_RUNTIME_VALUE]: runtimeValue };
|
|
3527
4662
|
}
|
|
3528
4663
|
function evaluateBinary(node, scope) {
|
|
@@ -3554,14 +4689,14 @@ function evaluateUnary(node, scope) {
|
|
|
3554
4689
|
function isStaticStyleValue(value) {
|
|
3555
4690
|
if (value.type === "StringLiteral" || value.type === "NumericLiteral" || value.type === "BooleanLiteral" || value.type === "NullLiteral") return true;
|
|
3556
4691
|
if (value.type === "TemplateLiteral") return value.expressions.length === 0;
|
|
3557
|
-
if (value.type === "
|
|
3558
|
-
const [priority, itemValue] = value.elements;
|
|
3559
|
-
return !!priority && priority.type === "NumericLiteral" && !!itemValue && isStaticStyleValue(itemValue);
|
|
3560
|
-
}
|
|
3561
|
-
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") {
|
|
3562
4693
|
const [itemValue, weight] = value.arguments;
|
|
3563
4694
|
return !!itemValue && itemValue.type !== "SpreadElement" && isStaticStyleValue(itemValue) && !!weight && weight.type === "NumericLiteral";
|
|
3564
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
|
+
}
|
|
3565
4700
|
if (value.type === "UnaryExpression") return isStaticStyleValue(value.argument);
|
|
3566
4701
|
return false;
|
|
3567
4702
|
}
|
|
@@ -3576,20 +4711,6 @@ function isStyleChainCall(callee, styleNames) {
|
|
|
3576
4711
|
if (object.type === "MemberExpression") return isStyleChainCall(object, styleNames);
|
|
3577
4712
|
return false;
|
|
3578
4713
|
}
|
|
3579
|
-
const formatThemeName = createNameFormatter(["name"]);
|
|
3580
|
-
function createThemeClassName(name, id, themeNameFormat) {
|
|
3581
|
-
return formatThemeName(themeNameFormat || "theme[-(name)]-$hash", getIdentifierSafeHash(id), { name });
|
|
3582
|
-
}
|
|
3583
|
-
function getThemeRuleCss(className, tokens, tokenNameFormat) {
|
|
3584
|
-
const declarations = [];
|
|
3585
|
-
for (let i = 0, len = tokens.length; i < len; i++) declarations.push(getThemeDeclaration(tokens[i], tokenNameFormat));
|
|
3586
|
-
return "." + escapeCssIdent(className) + "{" + declarations.join(";") + "}";
|
|
3587
|
-
}
|
|
3588
|
-
function getThemeDeclaration(token, tokenNameFormat) {
|
|
3589
|
-
const name = getTokenVarName(token, tokenNameFormat);
|
|
3590
|
-
const value = token.ref ? getTokenOverrideValue(token, tokenNameFormat) : escapeCssValue(String(token.value ?? ""));
|
|
3591
|
-
return name + ":" + value;
|
|
3592
|
-
}
|
|
3593
4714
|
//#endregion
|
|
3594
4715
|
//#region compiler/transform/syntax/utils.ts
|
|
3595
4716
|
function getCallLabel(callee) {
|
|
@@ -3724,60 +4845,6 @@ function sanitizeTokenId(value) {
|
|
|
3724
4845
|
return sanitizeCssIdentName(value, "token");
|
|
3725
4846
|
}
|
|
3726
4847
|
//#endregion
|
|
3727
|
-
//#region compiler/transform/utils/babel.ts
|
|
3728
|
-
function babelPlugin(factory) {
|
|
3729
|
-
return factory;
|
|
3730
|
-
}
|
|
3731
|
-
function babelTransform(args) {
|
|
3732
|
-
let result = null;
|
|
3733
|
-
try {
|
|
3734
|
-
const inputSourceMap = parseInputSourceMap(args.sourcemap);
|
|
3735
|
-
result = _babel_core.transformSync(args.code, {
|
|
3736
|
-
...babelTransformOptions(),
|
|
3737
|
-
inputSourceMap,
|
|
3738
|
-
filename: args.filePath,
|
|
3739
|
-
sourceFileName: args.filePath,
|
|
3740
|
-
plugins: args.plugins,
|
|
3741
|
-
sourceMaps: true,
|
|
3742
|
-
generatorOpts: { retainLines: args.retainLines ?? false }
|
|
3743
|
-
});
|
|
3744
|
-
} catch (err) {
|
|
3745
|
-
if (!args.errorLabel) throw err;
|
|
3746
|
-
const message = getBabelError(err, args);
|
|
3747
|
-
const error = new Error(message);
|
|
3748
|
-
error.stack = void 0;
|
|
3749
|
-
throw error;
|
|
3750
|
-
}
|
|
3751
|
-
if (!result || !result.code) return null;
|
|
3752
|
-
return {
|
|
3753
|
-
code: result.code,
|
|
3754
|
-
sourcemap: result.map ? JSON.stringify(result.map) : null
|
|
3755
|
-
};
|
|
3756
|
-
}
|
|
3757
|
-
function babelTransformOptions() {
|
|
3758
|
-
return {
|
|
3759
|
-
configFile: false,
|
|
3760
|
-
babelrc: false,
|
|
3761
|
-
parserOpts: {
|
|
3762
|
-
plugins: ["typescript", "jsx"],
|
|
3763
|
-
strictMode: false,
|
|
3764
|
-
allowImportExportEverywhere: true
|
|
3765
|
-
}
|
|
3766
|
-
};
|
|
3767
|
-
}
|
|
3768
|
-
function parseInputSourceMap(sourcemap) {
|
|
3769
|
-
if (!sourcemap) return void 0;
|
|
3770
|
-
if (typeof sourcemap !== "string") return sourcemap;
|
|
3771
|
-
return JSON.parse(sourcemap);
|
|
3772
|
-
}
|
|
3773
|
-
function getBabelError(err, args) {
|
|
3774
|
-
const babelErr = err;
|
|
3775
|
-
const msg = babelErr instanceof Error ? babelErr.message : String(err);
|
|
3776
|
-
const codeFrame = babelErr?.codeFrame;
|
|
3777
|
-
const suffix = codeFrame ? `\n\n${codeFrame}` : "";
|
|
3778
|
-
return `${args.errorLabel} in ${args.filePath}:\n${msg}${suffix}`;
|
|
3779
|
-
}
|
|
3780
|
-
//#endregion
|
|
3781
4848
|
//#region compiler/transform/utils/path.ts
|
|
3782
4849
|
function getProjectFileId$1(projectDir, filePath) {
|
|
3783
4850
|
if (!filePath) return "unknown";
|
|
@@ -3875,12 +4942,12 @@ function normalizeSelectorMessage(message) {
|
|
|
3875
4942
|
}
|
|
3876
4943
|
const formatVarName = createNameFormatter(["name"]);
|
|
3877
4944
|
function getLocalVarName(filePath, line, column, format) {
|
|
3878
|
-
const hash = getIdentifierSafeHash(filePath + "\n" + line + ":" + column);
|
|
4945
|
+
const hash = getIdentifierSafeHash(filePath + "\n" + line + ":" + column, CSS_CONFIG.hashLength);
|
|
3879
4946
|
return "--" + formatVarName(format || "var[-(name)]-$hash", hash, { name: "" });
|
|
3880
4947
|
}
|
|
3881
4948
|
//#endregion
|
|
3882
4949
|
//#region compiler/transform/debug/utils/debug_data.ts
|
|
3883
|
-
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) {
|
|
3884
4951
|
const loc = locOverride ?? node.loc?.start;
|
|
3885
4952
|
const line = loc?.line ?? 1;
|
|
3886
4953
|
const column = (loc?.column ?? 0) + 1;
|
|
@@ -3897,10 +4964,46 @@ function buildDebugDataObject(t, node, fileId, sourceUrlRef, sourceContentRef, t
|
|
|
3897
4964
|
t.objectProperty(t.identifier("fields"), buildFields(t, styleArg)),
|
|
3898
4965
|
t.objectProperty(t.identifier("vars"), buildVars(t, styleArg, fileId, tokenNameFormat))
|
|
3899
4966
|
];
|
|
4967
|
+
if (classNameArg) properties.push(t.objectProperty(t.identifier("classNames"), buildClassNames(t, node.arguments)));
|
|
3900
4968
|
properties.push(t.objectProperty(t.identifier("sourceUrl"), sourceUrlRef));
|
|
3901
4969
|
if (sourceContentRef) properties.push(t.objectProperty(t.identifier("code"), sourceContentRef));
|
|
3902
4970
|
return t.objectExpression(properties);
|
|
3903
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
|
+
}
|
|
3904
5007
|
function getShortLabel(label) {
|
|
3905
5008
|
const parts = label.split(".");
|
|
3906
5009
|
return parts[parts.length - 1] || label;
|
|
@@ -4059,7 +5162,9 @@ function createDebugPlugin(args) {
|
|
|
4059
5162
|
if (hasDebugArgument(path.node.arguments)) return;
|
|
4060
5163
|
const sourceUrlRef = getSourceUrlId(t, state);
|
|
4061
5164
|
const sourceContentRef = sourceContent ? getSourceContentId(t, state) : null;
|
|
4062
|
-
|
|
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));
|
|
4063
5168
|
},
|
|
4064
5169
|
JSXOpeningElement(path, state) {
|
|
4065
5170
|
if (options.dev?.elementClassName === false) return;
|
|
@@ -4249,14 +5354,16 @@ function getSelectorMethodPath(path) {
|
|
|
4249
5354
|
function getDebugStyleArg(t, path, state, sourcemapTrace) {
|
|
4250
5355
|
const arg = getStyleObjectArg(path, state);
|
|
4251
5356
|
if (!arg) return arg;
|
|
5357
|
+
const meta = getStyleCallMeta(path, state);
|
|
4252
5358
|
if (arg.type !== "ObjectExpression") return resolveDebugMergeObject(t, arg, path, state, sourcemapTrace) ?? arg;
|
|
4253
|
-
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);
|
|
4254
5360
|
}
|
|
4255
5361
|
function getDebugCallLoc(path, state) {
|
|
4256
5362
|
return isSelectorStyleCall(path, state) || isScopeItemSelectorCall(path, state) ? getMergeStyleLoc(path.node.callee) : null;
|
|
4257
5363
|
}
|
|
4258
5364
|
function getStyleObjectArg(path, state) {
|
|
4259
5365
|
const methodName = getSelectorMethodName(path.node.callee);
|
|
5366
|
+
if (methodName === "selector") return path.node.arguments[1];
|
|
4260
5367
|
const rootName = getStyleChainRootName(path.node.callee, state.styleNames);
|
|
4261
5368
|
const selector = methodName && rootName ? state.styleMetas.get(rootName)?.selectors[methodName] : null;
|
|
4262
5369
|
if (!selector) return path.node.arguments[0];
|
|
@@ -4264,6 +5371,10 @@ function getStyleObjectArg(path, state) {
|
|
|
4264
5371
|
const styleArgIndex = selectorArgIndex === null ? 0 : selectorArgIndex + 1;
|
|
4265
5372
|
return path.node.arguments[styleArgIndex];
|
|
4266
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
|
+
}
|
|
4267
5378
|
function isSelectorStyleCall(path, state) {
|
|
4268
5379
|
const methodName = getSelectorMethodName(path.node.callee);
|
|
4269
5380
|
if (!methodName) return false;
|
|
@@ -4368,6 +5479,46 @@ function flattenDebugObjectExpression(t, node, path, state, sourcemapTrace, seen
|
|
|
4368
5479
|
}
|
|
4369
5480
|
return t.objectExpression(properties);
|
|
4370
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
|
+
}
|
|
4371
5522
|
function resolveDebugSpreadObject(t, spread, path, state, sourcemapTrace, seen) {
|
|
4372
5523
|
const node = spread.argument;
|
|
4373
5524
|
if (node.type !== "Identifier") return null;
|
|
@@ -4637,7 +5788,7 @@ function transformDebug(internal, args, deps) {
|
|
|
4637
5788
|
code: args.code,
|
|
4638
5789
|
filePath: args.filePath,
|
|
4639
5790
|
sourcemap: args.sourcemap,
|
|
4640
|
-
plugins: [plugin],
|
|
5791
|
+
plugins: [plugin, createCssPropPlugin({ options })],
|
|
4641
5792
|
retainLines: true
|
|
4642
5793
|
});
|
|
4643
5794
|
if (!result) return null;
|
|
@@ -4650,6 +5801,12 @@ function transformDebug(internal, args, deps) {
|
|
|
4650
5801
|
//#region compiler/utils/file_resolver.ts
|
|
4651
5802
|
const contentCache = /* @__PURE__ */ new Map();
|
|
4652
5803
|
const resolver = new oxc_resolver.ResolverFactory({
|
|
5804
|
+
conditionNames: [
|
|
5805
|
+
"import",
|
|
5806
|
+
"module",
|
|
5807
|
+
"default",
|
|
5808
|
+
"types"
|
|
5809
|
+
],
|
|
4653
5810
|
extensions: [
|
|
4654
5811
|
".ts",
|
|
4655
5812
|
".tsx",
|
|
@@ -4660,7 +5817,8 @@ const resolver = new oxc_resolver.ResolverFactory({
|
|
|
4660
5817
|
".mts",
|
|
4661
5818
|
".cts"
|
|
4662
5819
|
],
|
|
4663
|
-
mainFiles: ["index"]
|
|
5820
|
+
mainFiles: ["index"],
|
|
5821
|
+
tsconfig: "auto"
|
|
4664
5822
|
});
|
|
4665
5823
|
function clearResolverCache() {
|
|
4666
5824
|
contentCache.clear();
|
|
@@ -4700,59 +5858,9 @@ function resolveFilePath(source, fromFile) {
|
|
|
4700
5858
|
}
|
|
4701
5859
|
}
|
|
4702
5860
|
//#endregion
|
|
4703
|
-
//#region atomic/rule.ts
|
|
4704
|
-
function buildAtomicRule(className, property, value, selector, parentSelector, atRules, scopeClassNameFormat) {
|
|
4705
|
-
const cssProp = getCssPropertyName(property);
|
|
4706
|
-
const cssValue = getCssPropertyValue(property, value);
|
|
4707
|
-
const classSelector = "." + escapeCssIdent(className);
|
|
4708
|
-
const itemSelector = selector ? getSelectorText(selector) : "";
|
|
4709
|
-
let selectorStr = classSelector + itemSelector;
|
|
4710
|
-
if (parentSelector) {
|
|
4711
|
-
const parentWhere = `:where(${"." + escapeCssIdent(getScopeClassName(className, scopeClassNameFormat)) + getSelectorText(parentSelector)})`;
|
|
4712
|
-
selectorStr = classSelector + parentWhere + itemSelector + "," + parentWhere + " " + selectorStr;
|
|
4713
|
-
}
|
|
4714
|
-
let rule = `${selectorStr}{${cssProp}: ${cssValue}}`;
|
|
4715
|
-
if (atRules) for (let i = atRules.length - 1; i >= 0; i--) rule = `${getSelectorText(atRules[i])}{${rule}}`;
|
|
4716
|
-
return rule;
|
|
4717
|
-
}
|
|
4718
|
-
function getAtomicRuleLayerPriority(property, priority, selector, parentSelector, atRules, isScopeRule = false) {
|
|
4719
|
-
const selectorPriority = getSelectorPriority(selector);
|
|
4720
|
-
const parentSelectorPriority = getSelectorPriority(parentSelector);
|
|
4721
|
-
const atRulePriority = getAtRulePriority$1(atRules);
|
|
4722
|
-
return [
|
|
4723
|
-
priority ?? 0,
|
|
4724
|
-
getLayerSelectorPriority(selector, parentSelector, selectorPriority),
|
|
4725
|
-
getParentSelectorPriority(parentSelector, parentSelectorPriority),
|
|
4726
|
-
getMediaPriority(atRules, atRulePriority),
|
|
4727
|
-
atRules ? atRules.length : 0,
|
|
4728
|
-
isScopeRule && !parentSelector ? 1 : 0,
|
|
4729
|
-
getPropertyPriority(property)
|
|
4730
|
-
];
|
|
4731
|
-
}
|
|
4732
|
-
function getMediaPriority(atRules, priority) {
|
|
4733
|
-
if (!atRules?.length) return LayerMediaPriorities.base;
|
|
4734
|
-
if (priority <= 0) return LayerMediaPriorities.media;
|
|
4735
|
-
return LayerMediaPriorities.priorityMedia + priority;
|
|
4736
|
-
}
|
|
4737
|
-
function getLayerSelectorPriority(selector, parentSelector, priority) {
|
|
4738
|
-
if (selector) return priority > 0 ? LayerSelectorPriorities.prioritySelector + priority : LayerSelectorPriorities.selector;
|
|
4739
|
-
if (parentSelector) return LayerSelectorPriorities.parentSelector;
|
|
4740
|
-
return LayerSelectorPriorities.base;
|
|
4741
|
-
}
|
|
4742
|
-
function getParentSelectorPriority(parentSelector, priority) {
|
|
4743
|
-
if (!parentSelector) return 0;
|
|
4744
|
-
return priority > 0 ? priority + 1 : 1;
|
|
4745
|
-
}
|
|
4746
|
-
function getAtRulePriority$1(atRules) {
|
|
4747
|
-
if (!atRules?.length) return 0;
|
|
4748
|
-
let priority = 0;
|
|
4749
|
-
for (let i = 0, len = atRules.length; i < len; i++) priority = Math.max(priority, getSelectorPriority(atRules[i]));
|
|
4750
|
-
return priority;
|
|
4751
|
-
}
|
|
4752
|
-
//#endregion
|
|
4753
5861
|
//#region compiler/transform/extract/chain/extract_chain.ts
|
|
4754
5862
|
const STATIC_MERGE_METHOD = "$$style.merge";
|
|
4755
|
-
function extractStyleChain(node, styleNames) {
|
|
5863
|
+
function extractStyleChain(node, styleNames, sheetNames = /* @__PURE__ */ new Set()) {
|
|
4756
5864
|
if (node.type !== "CallExpression") return null;
|
|
4757
5865
|
const callee = node.callee;
|
|
4758
5866
|
if (callee.type === "Identifier" && styleNames.has(callee.name)) return {
|
|
@@ -4761,6 +5869,12 @@ function extractStyleChain(node, styleNames) {
|
|
|
4761
5869
|
baseArgs: node.arguments,
|
|
4762
5870
|
methods: []
|
|
4763
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
|
+
};
|
|
4764
5878
|
if (callee.type === "MemberExpression" && !callee.computed) {
|
|
4765
5879
|
const prop = callee.property.type === "Identifier" ? callee.property.name : null;
|
|
4766
5880
|
if (!prop) return null;
|
|
@@ -4778,10 +5892,16 @@ function extractStyleChain(node, styleNames) {
|
|
|
4778
5892
|
baseArgs: node.arguments,
|
|
4779
5893
|
methods: []
|
|
4780
5894
|
};
|
|
5895
|
+
if (prop === "selector") return {
|
|
5896
|
+
kind: "selector",
|
|
5897
|
+
rootName: obj.name,
|
|
5898
|
+
baseArgs: node.arguments,
|
|
5899
|
+
methods: []
|
|
5900
|
+
};
|
|
4781
5901
|
if (prop !== "merge") return null;
|
|
4782
5902
|
const target = node.arguments[0];
|
|
4783
5903
|
if (!target) return null;
|
|
4784
|
-
const targetChain = extractStyleChain(target, styleNames);
|
|
5904
|
+
const targetChain = extractStyleChain(target, styleNames, sheetNames);
|
|
4785
5905
|
if (!targetChain) return null;
|
|
4786
5906
|
return {
|
|
4787
5907
|
...targetChain,
|
|
@@ -4793,7 +5913,7 @@ function extractStyleChain(node, styleNames) {
|
|
|
4793
5913
|
};
|
|
4794
5914
|
}
|
|
4795
5915
|
if (obj.type === "CallExpression") {
|
|
4796
|
-
const inner = extractStyleChain(obj, styleNames);
|
|
5916
|
+
const inner = extractStyleChain(obj, styleNames, sheetNames);
|
|
4797
5917
|
if (!inner) return null;
|
|
4798
5918
|
return {
|
|
4799
5919
|
...inner,
|
|
@@ -4809,15 +5929,113 @@ function extractStyleChain(node, styleNames) {
|
|
|
4809
5929
|
}
|
|
4810
5930
|
//#endregion
|
|
4811
5931
|
//#region compiler/transform/extract/chain/chain.ts
|
|
4812
|
-
function applyTransform(styleObj, transform) {
|
|
4813
|
-
|
|
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;
|
|
4814
6026
|
}
|
|
4815
6027
|
/**
|
|
4816
6028
|
* Compile a parsed chain into extracted items and CSS rules.
|
|
4817
6029
|
* Returns null if any argument cannot be statically evaluated.
|
|
4818
6030
|
*/
|
|
4819
|
-
function compileChain(chain, fileId, nodeLoc, scope, opts, meta, styleNames = /* @__PURE__ */ new Set()) {
|
|
4820
|
-
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
|
+
}
|
|
4821
6039
|
const selectors = meta.selectors;
|
|
4822
6040
|
const transform = meta.transform;
|
|
4823
6041
|
if (chain.kind === "style") return compileStyleChain(chain, selectors, fileId, scope, css, transform, styleNames, opts);
|
|
@@ -4825,13 +6043,120 @@ function compileChain(chain, fileId, nodeLoc, scope, opts, meta, styleNames = /*
|
|
|
4825
6043
|
if (chain.kind === "scope") return compileScopeChain(chain, selectors, fileId, scope, css, transform, opts);
|
|
4826
6044
|
return null;
|
|
4827
6045
|
}
|
|
4828
|
-
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) {
|
|
4829
6144
|
const css = opts.css;
|
|
6145
|
+
const isDevRuntimeMode = runtimeMode === "dev" || runtimeMode === "rsc-dev";
|
|
6146
|
+
const debugClassName = css?.debugClassName ?? isDevRuntimeMode;
|
|
4830
6147
|
return {
|
|
4831
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
|
+
}),
|
|
4832
6156
|
tokenNameFormat: css?.tokenNameFormat ?? DEFAULT_CONFIG.tokenNameFormat ?? null,
|
|
4833
|
-
localClassName:
|
|
4834
|
-
debugClassName
|
|
6157
|
+
localClassName: isDevRuntimeMode,
|
|
6158
|
+
debugClassName,
|
|
6159
|
+
runtimeMode,
|
|
4835
6160
|
scopeTargetPrefix: css?.scopeTargetPrefix ?? ""
|
|
4836
6161
|
};
|
|
4837
6162
|
}
|
|
@@ -4849,19 +6174,179 @@ function compileStyleChain(chain, selectors, fileId, scope, cssConfig, transform
|
|
|
4849
6174
|
rules
|
|
4850
6175
|
};
|
|
4851
6176
|
}
|
|
4852
|
-
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) {
|
|
4853
6338
|
if (chain.baseArgs.length > 0) {
|
|
4854
6339
|
const styleArg = evaluateNode(chain.baseArgs[0], scope);
|
|
4855
6340
|
if (!styleArg.ok) {
|
|
4856
6341
|
throwIfRequiredStaticStyleValue(styleArg);
|
|
4857
6342
|
return false;
|
|
4858
6343
|
}
|
|
4859
|
-
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;
|
|
4860
6345
|
}
|
|
4861
6346
|
let i = 0;
|
|
4862
6347
|
while (i < chain.methods.length) {
|
|
4863
6348
|
const method = chain.methods[i];
|
|
4864
|
-
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;
|
|
4865
6350
|
i++;
|
|
4866
6351
|
}
|
|
4867
6352
|
return true;
|
|
@@ -4875,7 +6360,7 @@ function compileSlotChain(chain, slotId, selectors, fileId, scope, cssConfig, tr
|
|
|
4875
6360
|
throwIfRequiredStaticStyleValue(styleArg);
|
|
4876
6361
|
return null;
|
|
4877
6362
|
}
|
|
4878
|
-
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;
|
|
4879
6364
|
}
|
|
4880
6365
|
let i = 0;
|
|
4881
6366
|
while (i < chain.methods.length) {
|
|
@@ -4908,7 +6393,7 @@ function compileScopeChain(chain, selectors, fileId, scope, cssConfig, transform
|
|
|
4908
6393
|
rules
|
|
4909
6394
|
};
|
|
4910
6395
|
}
|
|
4911
|
-
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) {
|
|
4912
6397
|
const selector = selectors[method.name];
|
|
4913
6398
|
if (!selector) return false;
|
|
4914
6399
|
validateSelectorDefinition(options.dev?.checkSelector, `style.${method.name}`, selector, method.nameNode);
|
|
@@ -4993,14 +6478,14 @@ function resolveSlotOverrideNode(node, parentSelector, atRules, selectors, fileI
|
|
|
4993
6478
|
return true;
|
|
4994
6479
|
}
|
|
4995
6480
|
if (node.type !== "CallExpression") return false;
|
|
4996
|
-
const overrideChain = extractOverrideChain(node, selectors, scope, fileId, transform, options);
|
|
6481
|
+
const overrideChain = extractOverrideChain(node, selectors, scope, fileId, cssConfig, transform, options);
|
|
4997
6482
|
if (!overrideChain) return false;
|
|
4998
6483
|
const { slotId, items: overrideItems } = overrideChain;
|
|
4999
6484
|
let i = 0;
|
|
5000
6485
|
while (i < overrideItems.length) {
|
|
5001
6486
|
const overrideItem = overrideItems[i];
|
|
5002
6487
|
const mergedAtRules = mergeAtRules(atRules, overrideItem.atRules);
|
|
5003
|
-
if (overrideItem.chain && overrideItem.meta) {
|
|
6488
|
+
if (overrideItem.chain && overrideItem.meta?.mode === "StyleObject") {
|
|
5004
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;
|
|
5005
6490
|
} else if (overrideItem.styleData !== void 0) {
|
|
5006
6491
|
if (!addStyleDataItems(overrideItem.styleData, overrideItem.selector, parentSelector, mergedAtRules, fileId, 4, slotId, items, cssRules, cssConfig, overrideItem.callsiteOverride)) return false;
|
|
@@ -5009,15 +6494,15 @@ function resolveSlotOverrideNode(node, parentSelector, atRules, selectors, fileI
|
|
|
5009
6494
|
}
|
|
5010
6495
|
return true;
|
|
5011
6496
|
}
|
|
5012
|
-
function extractOverrideChain(node, selectors, scope, fileId, transform, options) {
|
|
6497
|
+
function extractOverrideChain(node, selectors, scope, fileId, cssConfig, transform, options) {
|
|
5013
6498
|
const callee = node.callee;
|
|
5014
6499
|
if (callee.type === "MemberExpression" && !callee.computed) {
|
|
5015
6500
|
const methodName = callee.property.name;
|
|
5016
6501
|
const obj = callee.object;
|
|
5017
6502
|
if (obj.type === "CallExpression") {
|
|
5018
|
-
const inner = extractOverrideChain(obj, selectors, scope, fileId, transform, options);
|
|
6503
|
+
const inner = extractOverrideChain(obj, selectors, scope, fileId, cssConfig, transform, options);
|
|
5019
6504
|
if (!inner) return null;
|
|
5020
|
-
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);
|
|
5021
6506
|
if (!overrideItem) return null;
|
|
5022
6507
|
return {
|
|
5023
6508
|
slotId: inner.slotId,
|
|
@@ -5032,7 +6517,7 @@ function extractOverrideChain(node, selectors, scope, fileId, transform, options
|
|
|
5032
6517
|
const styleArg = evaluateNode(node.arguments[0], scope);
|
|
5033
6518
|
if (!styleArg.ok) return null;
|
|
5034
6519
|
items.push({
|
|
5035
|
-
styleObj: applyTransform(styleArg.value ?? {}, transform),
|
|
6520
|
+
styleObj: applyTransform(styleArg.value ?? {}, transform, cssConfig),
|
|
5036
6521
|
selector: null,
|
|
5037
6522
|
atRules: null
|
|
5038
6523
|
});
|
|
@@ -5042,7 +6527,7 @@ function extractOverrideChain(node, selectors, scope, fileId, transform, options
|
|
|
5042
6527
|
items
|
|
5043
6528
|
};
|
|
5044
6529
|
}
|
|
5045
|
-
function resolveOverrideMethod(methodName, args, nameNode, selectors, scope, transform, options) {
|
|
6530
|
+
function resolveOverrideMethod(methodName, args, nameNode, selectors, scope, cssConfig, transform, options) {
|
|
5046
6531
|
const sel = selectors[methodName];
|
|
5047
6532
|
if (!sel) return null;
|
|
5048
6533
|
validateSelectorDefinition(options.dev?.checkSelector, `style.${methodName}`, sel);
|
|
@@ -5069,7 +6554,7 @@ function resolveOverrideMethod(methodName, args, nameNode, selectors, scope, tra
|
|
|
5069
6554
|
callsiteOverride
|
|
5070
6555
|
};
|
|
5071
6556
|
return {
|
|
5072
|
-
styleObj: applyTransform(styleArg.value ?? {}, transform),
|
|
6557
|
+
styleObj: applyTransform(styleArg.value ?? {}, transform, cssConfig),
|
|
5073
6558
|
selector: null,
|
|
5074
6559
|
atRules: null,
|
|
5075
6560
|
callsiteOverride
|
|
@@ -5094,7 +6579,7 @@ function resolveOverrideMethod(methodName, args, nameNode, selectors, scope, tra
|
|
|
5094
6579
|
if (!styleArg.ok) return null;
|
|
5095
6580
|
const atRuleSelector = priority !== null ? [atRule, priority] : atRule;
|
|
5096
6581
|
return {
|
|
5097
|
-
styleObj: applyTransform(styleArg.value, transform),
|
|
6582
|
+
styleObj: applyTransform(styleArg.value, transform, cssConfig),
|
|
5098
6583
|
selector: null,
|
|
5099
6584
|
atRules: [atRuleSelector]
|
|
5100
6585
|
};
|
|
@@ -5110,7 +6595,7 @@ function resolveOverrideMethod(methodName, args, nameNode, selectors, scope, tra
|
|
|
5110
6595
|
const selectorText = before + normalizeSelectorArg(String(selectorArg.value ?? "")) + (after ?? "");
|
|
5111
6596
|
const itemSelector = sel.priority !== null ? [selectorText, sel.priority] : selectorText;
|
|
5112
6597
|
return {
|
|
5113
|
-
styleObj: applyTransform(styleArg.value, transform),
|
|
6598
|
+
styleObj: applyTransform(styleArg.value, transform, cssConfig),
|
|
5114
6599
|
selector: itemSelector,
|
|
5115
6600
|
atRules: null
|
|
5116
6601
|
};
|
|
@@ -5118,7 +6603,7 @@ function resolveOverrideMethod(methodName, args, nameNode, selectors, scope, tra
|
|
|
5118
6603
|
const styleArg = evaluateNode(args[0], scope);
|
|
5119
6604
|
if (!styleArg.ok) return null;
|
|
5120
6605
|
return {
|
|
5121
|
-
styleObj: applyTransform(styleArg.value, transform),
|
|
6606
|
+
styleObj: applyTransform(styleArg.value, transform, cssConfig),
|
|
5122
6607
|
selector: sel.priority !== null ? [selectorStr, sel.priority] : selectorStr,
|
|
5123
6608
|
atRules: null
|
|
5124
6609
|
};
|
|
@@ -5181,10 +6666,10 @@ function getSlotIdFromValue(value) {
|
|
|
5181
6666
|
const slotId = value.slotId;
|
|
5182
6667
|
return typeof slotId === "string" ? slotId : null;
|
|
5183
6668
|
}
|
|
5184
|
-
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) {
|
|
5185
6670
|
if (method.name === "$$style.merge") {
|
|
5186
6671
|
const mergeCallsite = callsiteOverride ?? getMergeStyleCallsite(method.nameNode, scope, options);
|
|
5187
|
-
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);
|
|
5188
6673
|
}
|
|
5189
6674
|
const selector = selectors[method.name];
|
|
5190
6675
|
if (!selector) return false;
|
|
@@ -5192,48 +6677,97 @@ function compileChainMethod(method, selectors, slotId, fileId, scope, type, cssC
|
|
|
5192
6677
|
const selectorStr = selector.selector.trim();
|
|
5193
6678
|
if (selectorStr === "...") {
|
|
5194
6679
|
const mergeCallsite = callsiteOverride ?? getMergeStyleCallsite(method.nameNode, scope, options);
|
|
5195
|
-
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);
|
|
5196
6681
|
}
|
|
5197
|
-
if (selectorStr.startsWith("@")) return compileAtRuleMethod(method, slotId, selector, selectorStr, fileId, scope, type, cssConfig, items, cssRules, transform, atRules, selectors, styleNames, options);
|
|
5198
|
-
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);
|
|
5199
6684
|
const itemSelector = selector.priority !== null ? [selectorStr, selector.priority] : selectorStr;
|
|
6685
|
+
const compiledSelector = selectorPrefix ? combineSelectors(selectorPrefix, itemSelector) : itemSelector;
|
|
5200
6686
|
const styleArg = evaluateNode(method.args[0], scope);
|
|
5201
6687
|
if (!styleArg.ok) {
|
|
5202
6688
|
throwIfRequiredStaticStyleValue(styleArg);
|
|
5203
6689
|
return false;
|
|
5204
6690
|
}
|
|
5205
|
-
return addStyleItems(applyTransform(styleArg.value, transform),
|
|
6691
|
+
return addStyleItems(applyTransform(styleArg.value, transform, cssConfig), compiledSelector, null, atRules, fileId, type, slotId, items, cssRules, cssConfig, callsiteOverride);
|
|
5206
6692
|
}
|
|
5207
|
-
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) {
|
|
5208
6694
|
if (!styleArgNode) return false;
|
|
5209
6695
|
const styleCallsite = callsiteOverride ?? getMergeStyleCallsite(mergeNode, scope, options);
|
|
5210
6696
|
const localChain = getLocalStyleChainArg(styleArgNode, scope, styleNames);
|
|
5211
6697
|
const localMeta = localChain ? scope.styleMetas?.get(localChain.rootName) : null;
|
|
5212
|
-
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);
|
|
5213
6699
|
if (styleArgNode.type === "CallExpression") {
|
|
5214
6700
|
const nestedChain = extractStyleChain(styleArgNode, styleNames);
|
|
5215
6701
|
const nestedMeta = nestedChain ? scope.styleMetas?.get(nestedChain.rootName) : null;
|
|
5216
|
-
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);
|
|
5217
6703
|
}
|
|
5218
6704
|
const styleArg = evaluateNode(styleArgNode, scope);
|
|
5219
6705
|
if (!styleArg.ok) {
|
|
5220
6706
|
throwIfRequiredStaticStyleValue(styleArg);
|
|
5221
6707
|
return false;
|
|
5222
6708
|
}
|
|
5223
|
-
if (isStyleData(styleArg.value) && isStyleDataSpreadExpression(styleArgNode)) return addStyleDataSpreadItems(styleArg.value, styleArgNode,
|
|
5224
|
-
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);
|
|
5225
6711
|
}
|
|
5226
|
-
function getLocalStyleChainArg(node, scope, styleNames) {
|
|
6712
|
+
function getLocalStyleChainArg(node, scope, styleNames, sheetNames = /* @__PURE__ */ new Set()) {
|
|
5227
6713
|
if (node.type !== "Identifier") return null;
|
|
5228
6714
|
const init = scope.bindingNodes?.get(node.name);
|
|
5229
6715
|
if (!init) return null;
|
|
5230
|
-
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;
|
|
5231
6765
|
}
|
|
5232
6766
|
function getLocalBindingNode(node, scope) {
|
|
5233
6767
|
return node?.type === "Identifier" ? scope.bindingNodes?.get(node.name) ?? null : null;
|
|
5234
6768
|
}
|
|
5235
6769
|
function getMergeStyleCallsite(node, scope, options) {
|
|
5236
|
-
if (options.dev?.sourcemapMode !== "style") return null;
|
|
6770
|
+
if ((options.dev?.sourcemapMode ?? (scope.runtimeMode === "rsc-dev" ? "style" : null)) !== "style") return null;
|
|
5237
6771
|
const loc = node?.loc?.start;
|
|
5238
6772
|
if (!loc) return null;
|
|
5239
6773
|
return {
|
|
@@ -5255,7 +6789,7 @@ function isStyleDataSpreadExpression(node) {
|
|
|
5255
6789
|
default: return false;
|
|
5256
6790
|
}
|
|
5257
6791
|
}
|
|
5258
|
-
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) {
|
|
5259
6793
|
const isMedia = selectorStr.startsWith("@media") || selectorStr.startsWith("@container");
|
|
5260
6794
|
const hasArg = selectorStr.includes("$$");
|
|
5261
6795
|
validateSelectorDefinition(options.dev?.checkSelector, `style.${method.name}`, selector, method.nameNode);
|
|
@@ -5277,22 +6811,22 @@ function compileAtRuleMethod(method, slotId, selector, selectorStr, fileId, scop
|
|
|
5277
6811
|
if (styleArg.type === "CallExpression") {
|
|
5278
6812
|
const nestedChain = extractStyleChain(styleArg, styleNames);
|
|
5279
6813
|
const nestedMeta = nestedChain ? scope.styleMetas?.get(nestedChain.rootName) : null;
|
|
5280
|
-
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);
|
|
5281
6815
|
const evaled = evaluateNode(styleArg, scope);
|
|
5282
6816
|
if (!evaled.ok) {
|
|
5283
6817
|
throwIfRequiredStaticStyleValue(evaled);
|
|
5284
6818
|
return false;
|
|
5285
6819
|
}
|
|
5286
|
-
return addStyleItems(applyTransform(evaled.value, transform),
|
|
6820
|
+
return addStyleItems(applyTransform(evaled.value, transform, cssConfig), selectorPrefix, null, nextAtRules, fileId, type, slotId, items, cssRules, cssConfig);
|
|
5287
6821
|
}
|
|
5288
6822
|
const styleResult = evaluateNode(styleArg, scope);
|
|
5289
6823
|
if (!styleResult.ok) {
|
|
5290
6824
|
throwIfRequiredStaticStyleValue(styleResult);
|
|
5291
6825
|
return false;
|
|
5292
6826
|
}
|
|
5293
|
-
return addStyleItems(applyTransform(styleResult.value, transform),
|
|
6827
|
+
return addStyleItems(applyTransform(styleResult.value, transform, cssConfig), selectorPrefix, null, nextAtRules, fileId, type, slotId, items, cssRules, cssConfig);
|
|
5294
6828
|
}
|
|
5295
|
-
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) {
|
|
5296
6830
|
const selectorStr = selector.selector.trim();
|
|
5297
6831
|
validateSelectorDefinition(options.dev?.checkSelector, `style.${method.name}`, selector, method.nameNode);
|
|
5298
6832
|
const splitToken = selectorStr.includes("$$") ? "$$" : "$";
|
|
@@ -5309,12 +6843,13 @@ function compileArgMethod(method, selector, slotId, fileId, scope, type, cssConf
|
|
|
5309
6843
|
const styleResult = evaluateNode(styleArg, scope);
|
|
5310
6844
|
if (!styleResult.ok) return false;
|
|
5311
6845
|
const selectorValues = Array.isArray(selectorArg.value) ? selectorArg.value : [selectorArg.value];
|
|
5312
|
-
const styleObj = applyTransform(styleResult.value, transform);
|
|
6846
|
+
const styleObj = applyTransform(styleResult.value, transform, cssConfig);
|
|
5313
6847
|
let i = 0;
|
|
5314
6848
|
while (i < selectorValues.length) {
|
|
5315
6849
|
const itemSelectorValue = selectorValues[i];
|
|
5316
6850
|
const selectorText = before + normalizeSelectorArg(String(itemSelectorValue ?? "")) + (after ?? "");
|
|
5317
|
-
|
|
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;
|
|
5318
6853
|
i++;
|
|
5319
6854
|
}
|
|
5320
6855
|
return true;
|
|
@@ -5383,6 +6918,8 @@ function addSlotOverrideDataItems(value, parentSelector, atRules, fileId, items,
|
|
|
5383
6918
|
dedupe: overrideItem.dedupe,
|
|
5384
6919
|
className: overrideItem.className,
|
|
5385
6920
|
property: overrideItem.property,
|
|
6921
|
+
weight: overrideItem.weight,
|
|
6922
|
+
important: overrideItem.important,
|
|
5386
6923
|
value: overrideItem.value,
|
|
5387
6924
|
variable: overrideItem.variable,
|
|
5388
6925
|
token: overrideItem.token,
|
|
@@ -5426,27 +6963,26 @@ function addExtractedScopeItem(sourceItem, items) {
|
|
|
5426
6963
|
items.push(item);
|
|
5427
6964
|
}
|
|
5428
6965
|
function addRuntimeScopeItem(sourceItem, parentSelector, atRules, fileId, items, cssRules, cssConfig, callsiteOverride = null) {
|
|
5429
|
-
|
|
6966
|
+
const weight = sourceItem.weight;
|
|
6967
|
+
let important = false;
|
|
5430
6968
|
let value = sourceItem.value;
|
|
5431
|
-
|
|
5432
|
-
priority = value[1];
|
|
5433
|
-
value = value[0];
|
|
5434
|
-
}
|
|
6969
|
+
important = sourceItem.important;
|
|
5435
6970
|
const itemParentSelector = parentSelector ?? sourceItem.parentSelector;
|
|
5436
6971
|
const itemAtRules = mergeAtRules(atRules, sourceItem.atRule);
|
|
5437
6972
|
const traceCallsite = callsiteOverride ?? sourceItem.callsite;
|
|
5438
6973
|
const valueStr = String(value ?? "");
|
|
5439
|
-
const dedupe = getClassNameDedupe(sourceItem.property,
|
|
5440
|
-
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);
|
|
5441
6976
|
const item = createCompiledItem(4, sourceItem.slotId, dedupe, className, !!itemParentSelector);
|
|
5442
6977
|
items.push(item);
|
|
5443
|
-
const css = buildAtomicRule(className, sourceItem.property, valueStr, sourceItem.selector, itemParentSelector, itemAtRules, cssConfig.scopeTargetPrefix);
|
|
5444
|
-
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);
|
|
5445
6980
|
cssRules.push({
|
|
5446
6981
|
dedupe,
|
|
5447
6982
|
className,
|
|
5448
6983
|
css,
|
|
5449
6984
|
priority: layerPriority,
|
|
6985
|
+
important,
|
|
5450
6986
|
trace: traceCallsite ? {
|
|
5451
6987
|
filePath: traceCallsite.filePath ?? fileId,
|
|
5452
6988
|
line: traceCallsite.line,
|
|
@@ -5504,21 +7040,18 @@ function addExtractedStyleItem(sourceItem, type, slotId, items) {
|
|
|
5504
7040
|
items.push(item);
|
|
5505
7041
|
}
|
|
5506
7042
|
function addRuntimeStyleItem(sourceItem, selector, parentSelector, atRules, fileId, type, slotId, items, cssRules, cssConfig, callsiteOverride = null) {
|
|
5507
|
-
|
|
7043
|
+
const weight = sourceItem.weight;
|
|
7044
|
+
const important = sourceItem.important;
|
|
5508
7045
|
let value = sourceItem.value;
|
|
5509
|
-
|
|
5510
|
-
priority = value[1];
|
|
5511
|
-
value = value[0];
|
|
5512
|
-
}
|
|
5513
|
-
const itemSelector = selector ?? sourceItem.selector;
|
|
7046
|
+
const itemSelector = selector && sourceItem.selector ? combineSelectors(selector, sourceItem.selector) : selector ?? sourceItem.selector;
|
|
5514
7047
|
const itemAtRules = mergeAtRules(atRules, sourceItem.atRule);
|
|
5515
7048
|
const variable = sourceItem.variable;
|
|
5516
7049
|
const runtimeValue = variable?.[0] === 1 ? getCompiledRuntimeValue(variable[2]) : void 0;
|
|
5517
7050
|
const shouldUseVariable = !!variable && (variable[0] !== 1 || !!sourceItem.token || !!runtimeValue);
|
|
5518
7051
|
const valueStr = variable?.[0] === 1 && !shouldUseVariable ? String(variable[2] ?? "") : String(value ?? "");
|
|
5519
|
-
const dedupe = getClassNameDedupe(sourceItem.property,
|
|
7052
|
+
const dedupe = getClassNameDedupe(sourceItem.property, weight, important, itemSelector, parentSelector, itemAtRules);
|
|
5520
7053
|
const traceCallsite = callsiteOverride ?? sourceItem.callsite;
|
|
5521
|
-
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);
|
|
5522
7055
|
const item = createCompiledItem(type, slotId, dedupe, className, !!parentSelector);
|
|
5523
7056
|
item.sourceTrace = getRuntimeStyleItemSourceTrace(sourceItem, fileId);
|
|
5524
7057
|
if (type !== 4 && variable && shouldUseVariable) {
|
|
@@ -5526,13 +7059,14 @@ function addRuntimeStyleItem(sourceItem, selector, parentSelector, atRules, file
|
|
|
5526
7059
|
if (runtimeValue) item.valueNode = runtimeValue;
|
|
5527
7060
|
}
|
|
5528
7061
|
items.push(item);
|
|
5529
|
-
const css = buildAtomicRule(className, sourceItem.property, valueStr, itemSelector, parentSelector, itemAtRules, cssConfig.scopeTargetPrefix);
|
|
5530
|
-
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);
|
|
5531
7064
|
cssRules.push({
|
|
5532
7065
|
dedupe,
|
|
5533
7066
|
className,
|
|
5534
7067
|
css,
|
|
5535
7068
|
priority: layerPriority,
|
|
7069
|
+
important,
|
|
5536
7070
|
trace: traceCallsite ? {
|
|
5537
7071
|
filePath: traceCallsite.filePath ?? fileId,
|
|
5538
7072
|
line: traceCallsite.line,
|
|
@@ -5540,6 +7074,19 @@ function addRuntimeStyleItem(sourceItem, selector, parentSelector, atRules, file
|
|
|
5540
7074
|
} : void 0
|
|
5541
7075
|
});
|
|
5542
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
|
+
}
|
|
5543
7090
|
function getRuntimeStyleItemSourceTrace(item, fileId) {
|
|
5544
7091
|
const trace = getRuntimeStyleItemValueTrace(item);
|
|
5545
7092
|
if (!trace) return void 0;
|
|
@@ -5584,11 +7131,14 @@ function addStyleItems(styleObj, selector, parentSelector, atRules, fileId, type
|
|
|
5584
7131
|
while (i < keys.length) {
|
|
5585
7132
|
const property = keys[i];
|
|
5586
7133
|
const rawValue = styleObj[property];
|
|
5587
|
-
let
|
|
7134
|
+
let weight = null;
|
|
7135
|
+
let important = false;
|
|
5588
7136
|
let value = rawValue;
|
|
5589
|
-
|
|
5590
|
-
|
|
5591
|
-
|
|
7137
|
+
let transformClassName = null;
|
|
7138
|
+
[value, weight, important] = unwrapStaticStyleValue(value);
|
|
7139
|
+
if (isClassNameValue(value)) {
|
|
7140
|
+
transformClassName = value.className;
|
|
7141
|
+
value = value.value;
|
|
5592
7142
|
}
|
|
5593
7143
|
if (value === null || value === void 0) {
|
|
5594
7144
|
i++;
|
|
@@ -5606,10 +7156,10 @@ function addStyleItems(styleObj, selector, parentSelector, atRules, fileId, type
|
|
|
5606
7156
|
column: propertyLoc.column
|
|
5607
7157
|
} : null);
|
|
5608
7158
|
const shouldUseVariable = !!(token || runtimeValue);
|
|
5609
|
-
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;
|
|
5610
7160
|
const valueStr = variableName ? token ? getCssVarRawFallback(variableName, getTokenVar(token, cssConfig.tokenNameFormat)) : `var(${variableName})` : token ? getTokenVar(token, cssConfig.tokenNameFormat) : String(value);
|
|
5611
|
-
const dedupe = getClassNameDedupe(property,
|
|
5612
|
-
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);
|
|
5613
7163
|
const item = createCompiledItem(type, slotId, dedupe, className, !!parentSelector);
|
|
5614
7164
|
item.sourceTrace = propertyCallsite ? {
|
|
5615
7165
|
property,
|
|
@@ -5634,13 +7184,14 @@ function addStyleItems(styleObj, selector, parentSelector, atRules, fileId, type
|
|
|
5634
7184
|
item.valueNode = runtimeValue ?? token[COMPILED_RUNTIME_VALUE];
|
|
5635
7185
|
}
|
|
5636
7186
|
items.push(item);
|
|
5637
|
-
const css = buildAtomicRule(className, property, valueStr, selector, parentSelector, atRules, cssConfig.scopeTargetPrefix);
|
|
5638
|
-
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);
|
|
5639
7189
|
cssRules.push({
|
|
5640
7190
|
dedupe,
|
|
5641
7191
|
className,
|
|
5642
7192
|
css,
|
|
5643
7193
|
priority: layerPriority,
|
|
7194
|
+
important,
|
|
5644
7195
|
trace: propertyCallsite ? {
|
|
5645
7196
|
filePath: propertyCallsite.filePath ?? fileId,
|
|
5646
7197
|
line: propertyCallsite.line,
|
|
@@ -5663,6 +7214,28 @@ function addStyleItems(styleObj, selector, parentSelector, atRules, fileId, type
|
|
|
5663
7214
|
}
|
|
5664
7215
|
return true;
|
|
5665
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
|
+
}
|
|
5666
7239
|
function throwIfRequiredStaticStyleValue(result) {
|
|
5667
7240
|
if (result.ok) return;
|
|
5668
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);
|
|
@@ -5798,6 +7371,12 @@ function parseAndExtractModule(projectDir, filePath, content, babel, resolveImpo
|
|
|
5798
7371
|
const styleMetas = /* @__PURE__ */ new Map();
|
|
5799
7372
|
const fileId = getProjectFileId$1(projectDir, filePath);
|
|
5800
7373
|
const importSourceMatcher = createImportSourceMatcher(options.importSources ?? null);
|
|
7374
|
+
const staticIdState = {
|
|
7375
|
+
fileId,
|
|
7376
|
+
imports,
|
|
7377
|
+
styleNames
|
|
7378
|
+
};
|
|
7379
|
+
const t = babel.types;
|
|
5801
7380
|
for (const stmt of ast.program.body) {
|
|
5802
7381
|
if (stmt.type === "ImportDeclaration") {
|
|
5803
7382
|
const source = stmt.source.value;
|
|
@@ -5822,6 +7401,7 @@ function parseAndExtractModule(projectDir, filePath, content, babel, resolveImpo
|
|
|
5822
7401
|
continue;
|
|
5823
7402
|
}
|
|
5824
7403
|
if (stmt.type === "VariableDeclaration") {
|
|
7404
|
+
annotateVariableDeclaration(stmt, staticIdState, t);
|
|
5825
7405
|
collectVariableBindings(rawBindings, stmt);
|
|
5826
7406
|
continue;
|
|
5827
7407
|
}
|
|
@@ -5845,6 +7425,7 @@ function parseAndExtractModule(projectDir, filePath, content, babel, resolveImpo
|
|
|
5845
7425
|
continue;
|
|
5846
7426
|
}
|
|
5847
7427
|
if (stmt.declaration?.type === "VariableDeclaration") {
|
|
7428
|
+
annotateVariableDeclaration(stmt.declaration, staticIdState, t);
|
|
5848
7429
|
collectVariableBindings(rawBindings, stmt.declaration);
|
|
5849
7430
|
continue;
|
|
5850
7431
|
}
|
|
@@ -5884,6 +7465,12 @@ function parseAndExtractModule(projectDir, filePath, content, babel, resolveImpo
|
|
|
5884
7465
|
});
|
|
5885
7466
|
return bindings;
|
|
5886
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
|
+
}
|
|
5887
7474
|
function collectVariableBindings(bindings, declaration) {
|
|
5888
7475
|
for (const decl of declaration.declarations) if (decl.id.type === "Identifier" && decl.init) bindings.set(decl.id.name, decl.init);
|
|
5889
7476
|
}
|
|
@@ -5894,7 +7481,7 @@ function evaluateResolvedNode(node, scope, styleNames, fileId, options) {
|
|
|
5894
7481
|
if (chain?.kind === "style" || chain?.kind === "scope") try {
|
|
5895
7482
|
const meta = scope.styleMetas?.get(chain.rootName);
|
|
5896
7483
|
if (!meta) return evalFail("Cannot resolve imported style function");
|
|
5897
|
-
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);
|
|
5898
7485
|
if (!result) return evalFail("Cannot compile imported style chain");
|
|
5899
7486
|
const extracted = createExtractedChainValue(result, options.dev?.sourcemapMode === "value" ? result : compileChain(chain, fileId, node.loc?.start, scope, {
|
|
5900
7487
|
...options,
|
|
@@ -5902,7 +7489,7 @@ function evaluateResolvedNode(node, scope, styleNames, fileId, options) {
|
|
|
5902
7489
|
...options.dev,
|
|
5903
7490
|
sourcemapMode: "value"
|
|
5904
7491
|
}
|
|
5905
|
-
}, meta, styleNames) ?? result);
|
|
7492
|
+
}, scope.runtimeMode ?? null, meta, styleNames) ?? result);
|
|
5906
7493
|
if (!extracted) return evalFail("Cannot extract imported style chain");
|
|
5907
7494
|
return evalOk(extracted);
|
|
5908
7495
|
} catch (error) {
|
|
@@ -5944,11 +7531,16 @@ function evaluateResolvedObject(node, scope, styleNames, fileId, options) {
|
|
|
5944
7531
|
const value = evaluateResolvedNode(prop.value, scope, styleNames, fileId, options);
|
|
5945
7532
|
if (!value.ok && value.reason !== "slot-ref") return value;
|
|
5946
7533
|
result[String(key.value)] = value.ok ? value.value : value;
|
|
5947
|
-
if (prop.loc?.start)
|
|
5948
|
-
|
|
5949
|
-
|
|
5950
|
-
|
|
5951
|
-
|
|
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
|
+
}
|
|
5952
7544
|
}
|
|
5953
7545
|
if (Object.keys(locations).length) Object.defineProperty(result, COMPILED_STYLE_OBJECT_LOCATIONS, {
|
|
5954
7546
|
configurable: true,
|
|
@@ -5963,6 +7555,11 @@ function createExtractedChainValue(result, traceResult = result) {
|
|
|
5963
7555
|
defineCompiledStyleLocations(style, traceResult);
|
|
5964
7556
|
return style;
|
|
5965
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
|
+
}
|
|
5966
7563
|
if (result.type === "scope") return createExtractedScope(result.items.map(toExtractedScopeItem$1).filter((item) => item !== null));
|
|
5967
7564
|
return null;
|
|
5968
7565
|
}
|
|
@@ -6073,6 +7670,12 @@ function hashFileContent(filePath) {
|
|
|
6073
7670
|
function getStyleRuntimeImportPath(mode) {
|
|
6074
7671
|
return `${STYLE_IMPORT_PATH}/entry/${mode}`;
|
|
6075
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
|
+
}
|
|
6076
7679
|
function getStyleRuntimeCssImportPath(mode) {
|
|
6077
7680
|
return `${getStyleRuntimeImportPath(mode)}/css`;
|
|
6078
7681
|
}
|
|
@@ -6165,6 +7768,10 @@ function buildReplacement(t, chain, state, options = {}) {
|
|
|
6165
7768
|
state.usedHelpers.add(hasSpread ? FN_CREATE_EXTRACTED_STYLE_MERGE : FN_CREATE_EXTRACTED_STYLE);
|
|
6166
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)]);
|
|
6167
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
|
+
}
|
|
6168
7775
|
if (chain.type === "slot") {
|
|
6169
7776
|
state.usedHelpers.add(FN_CREATE_EXTRACTED_SLOT);
|
|
6170
7777
|
return t.callExpression(t.identifier(FN_CREATE_EXTRACTED_SLOT), [t.stringLiteral(chain.slotId), buildItemsArray(t, chain, 2, state, options)]);
|
|
@@ -6175,6 +7782,13 @@ function buildReplacement(t, chain, state, options = {}) {
|
|
|
6175
7782
|
}
|
|
6176
7783
|
return null;
|
|
6177
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
|
+
}
|
|
6178
7792
|
function buildStyleMergeArgs(t, chain, state, options) {
|
|
6179
7793
|
const args = [];
|
|
6180
7794
|
let chunk = [];
|
|
@@ -6203,7 +7817,7 @@ function buildItemsArray(t, chain, defaultType, state, options) {
|
|
|
6203
7817
|
chain.items.forEach((item) => {
|
|
6204
7818
|
if (isCompiledTokenItem(item)) {
|
|
6205
7819
|
if (options.getTokenOverride) options.getTokenOverride(item);
|
|
6206
|
-
else itemExpressions.push(t
|
|
7820
|
+
else itemExpressions.push(buildExtractedTokenOverrideExpression(t, item.value, state));
|
|
6207
7821
|
return;
|
|
6208
7822
|
}
|
|
6209
7823
|
if (isCompiledStyleSpreadItem(item)) return;
|
|
@@ -6293,11 +7907,26 @@ function buildVariableValueExpression(t, value, state, item, options) {
|
|
|
6293
7907
|
}
|
|
6294
7908
|
function buildExtractedTokenExpression(t, token, state) {
|
|
6295
7909
|
state.usedHelpers.add(FN_CREATE_EXTRACTED_TOKEN);
|
|
7910
|
+
const tokenNameFormat = state.options.css?.tokenNameFormat ?? DEFAULT_CONFIG.tokenNameFormat ?? null;
|
|
6296
7911
|
return t.callExpression(t.identifier(FN_CREATE_EXTRACTED_TOKEN), [
|
|
6297
7912
|
t.stringLiteral(getStyleTokenId(token)),
|
|
6298
7913
|
literalExpression(t, token.value),
|
|
6299
|
-
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))
|
|
6300
7928
|
]);
|
|
7929
|
+
return t.callExpression(extractedToken, [token.ref ? buildExtractedTokenExpression(t, token.ref, state) : literalExpression(t, token.value)]);
|
|
6301
7930
|
}
|
|
6302
7931
|
function literalExpression(t, value) {
|
|
6303
7932
|
if (typeof value === "string") return t.stringLiteral(value);
|
|
@@ -6420,8 +8049,10 @@ function getEvalScope(state) {
|
|
|
6420
8049
|
styleFilePath: state.styleFilePath,
|
|
6421
8050
|
sourcemapTrace: state.sourcemapTrace,
|
|
6422
8051
|
styleNames: state.styleNames,
|
|
8052
|
+
sheetNames: state.sheetNames,
|
|
6423
8053
|
styleMetas: state.styleMetas,
|
|
6424
|
-
bindingNodes: state.bindingNodes
|
|
8054
|
+
bindingNodes: state.bindingNodes,
|
|
8055
|
+
runtimeMode: state.runtimeMode
|
|
6425
8056
|
};
|
|
6426
8057
|
}
|
|
6427
8058
|
//#endregion
|
|
@@ -6435,8 +8066,8 @@ function compileThemeCall(path, state, opts) {
|
|
|
6435
8066
|
const tokenArg = evaluateNode(path.node.arguments[0], scope);
|
|
6436
8067
|
if (!tokenArg.ok) throw path.buildCodeFrameError(`createTheme tokens must be statically analyzable: ${tokenArg.reason}`);
|
|
6437
8068
|
if (!Array.isArray(tokenArg.value)) throw path.buildCodeFrameError("createTheme first argument must be a static array of token overrides.");
|
|
6438
|
-
const
|
|
6439
|
-
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}`);
|
|
6440
8071
|
const tokens = [];
|
|
6441
8072
|
for (let i = 0, len = tokenArg.value.length; i < len; i++) {
|
|
6442
8073
|
const token = tokenArg.value[i];
|
|
@@ -6444,7 +8075,7 @@ function compileThemeCall(path, state, opts) {
|
|
|
6444
8075
|
tokens.push(token);
|
|
6445
8076
|
}
|
|
6446
8077
|
const loc = path.node.loc?.start;
|
|
6447
|
-
const id =
|
|
8078
|
+
const id = stableIdArg.ok && stableIdArg.value !== void 0 ? String(stableIdArg.value) : getStableThemeId(state.fileId, loc ? loc.line + ":" + loc.column : "createTheme");
|
|
6448
8079
|
const themeNameFormat = opts.css?.themeNameFormat || CSS_CONFIG.themeNameFormat || null;
|
|
6449
8080
|
const className = getStableThemeClassName(id, themeNameFormat);
|
|
6450
8081
|
return {
|
|
@@ -6476,6 +8107,7 @@ function createExtractPlugin(args) {
|
|
|
6476
8107
|
return {
|
|
6477
8108
|
pre() {
|
|
6478
8109
|
this.styleNames = /* @__PURE__ */ new Set();
|
|
8110
|
+
this.sheetNames = /* @__PURE__ */ new Set();
|
|
6479
8111
|
this.styleMetas = /* @__PURE__ */ new Map();
|
|
6480
8112
|
this.bindings = /* @__PURE__ */ new Map();
|
|
6481
8113
|
this.bindingNodes = /* @__PURE__ */ new Map();
|
|
@@ -6492,7 +8124,7 @@ function createExtractPlugin(args) {
|
|
|
6492
8124
|
this.filePath = this.file?.opts?.filename ?? "unknown";
|
|
6493
8125
|
this.styleFilePath = args.styleFilePath ?? this.filePath;
|
|
6494
8126
|
this.sourcemapTrace = options.dev?.sourcemapMode ?? "style";
|
|
6495
|
-
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);
|
|
6496
8128
|
},
|
|
6497
8129
|
visitor: {
|
|
6498
8130
|
ImportDeclaration(path, state) {
|
|
@@ -6522,6 +8154,7 @@ function createExtractPlugin(args) {
|
|
|
6522
8154
|
state.styleNames.add(spec.local.name);
|
|
6523
8155
|
state.styleMetas.set(spec.local.name, meta);
|
|
6524
8156
|
}
|
|
8157
|
+
if (sourceName === "@fluentic/style/css" && imported === "createSheet") state.sheetNames.add(spec.local.name);
|
|
6525
8158
|
});
|
|
6526
8159
|
},
|
|
6527
8160
|
VariableDeclaration(path, state) {
|
|
@@ -6568,22 +8201,26 @@ function createExtractPlugin(args) {
|
|
|
6568
8201
|
state.needsExtractImport = true;
|
|
6569
8202
|
return;
|
|
6570
8203
|
}
|
|
6571
|
-
if (!state.styleNames.size) return;
|
|
6572
|
-
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);
|
|
6573
8206
|
if (!chain) return;
|
|
6574
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.");
|
|
6575
8208
|
const scope = getEvalScope(state);
|
|
6576
8209
|
const loc = path.node.loc?.start;
|
|
6577
8210
|
const meta = state.styleMetas.get(chain.rootName);
|
|
6578
|
-
if (!meta) return;
|
|
8211
|
+
if (chain.kind !== "sheet" && !meta) return;
|
|
6579
8212
|
let result;
|
|
6580
8213
|
try {
|
|
6581
|
-
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);
|
|
6582
8215
|
} catch (error) {
|
|
6583
8216
|
const message = error instanceof Error ? error.message : String(error);
|
|
6584
8217
|
throw buildCodeFrameError(path, getSelectorCompileErrorNode(error) ?? path.node, message);
|
|
6585
8218
|
}
|
|
6586
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
|
+
});
|
|
6587
8224
|
result.rules.forEach((rule) => {
|
|
6588
8225
|
state.collector.add(rule);
|
|
6589
8226
|
});
|
|
@@ -6622,6 +8259,18 @@ function createExtractPlugin(args) {
|
|
|
6622
8259
|
};
|
|
6623
8260
|
});
|
|
6624
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
|
+
}
|
|
6625
8274
|
function pruneUnusedStyleInputDeclarations(path, state) {
|
|
6626
8275
|
path.scope.crawl();
|
|
6627
8276
|
path.traverse({ VariableDeclarator(declaratorPath) {
|
|
@@ -6783,13 +8432,15 @@ function insertHoistedDeclarations(path, declarations) {
|
|
|
6783
8432
|
const body = path.node.body;
|
|
6784
8433
|
let firstRuntimeIndex = 0;
|
|
6785
8434
|
while (firstRuntimeIndex < body.length && body[firstRuntimeIndex].type === "ImportDeclaration") firstRuntimeIndex++;
|
|
8435
|
+
let runtimeInsertIndex = firstRuntimeIndex;
|
|
6786
8436
|
declarations.forEach((item) => {
|
|
6787
|
-
let insertIndex =
|
|
8437
|
+
let insertIndex = runtimeInsertIndex;
|
|
6788
8438
|
item.dependencies.forEach((name) => {
|
|
6789
8439
|
const dependencyIndex = findTopLevelDeclarationIndex(body, name);
|
|
6790
8440
|
if (dependencyIndex >= insertIndex) insertIndex = dependencyIndex + 1;
|
|
6791
8441
|
});
|
|
6792
8442
|
body.splice(insertIndex, 0, item.declaration);
|
|
8443
|
+
runtimeInsertIndex = insertIndex + 1;
|
|
6793
8444
|
});
|
|
6794
8445
|
}
|
|
6795
8446
|
function findTopLevelDeclarationIndex(body, name) {
|
|
@@ -6830,7 +8481,7 @@ function transformExtract(internal, args, deps) {
|
|
|
6830
8481
|
code: args.code,
|
|
6831
8482
|
filePath: args.filePath,
|
|
6832
8483
|
sourcemap: args.sourcemap,
|
|
6833
|
-
plugins: [plugin],
|
|
8484
|
+
plugins: [createCssPropPlugin({ options: internal.options }), plugin],
|
|
6834
8485
|
errorLabel: "[style] compiler error"
|
|
6835
8486
|
});
|
|
6836
8487
|
if (!result) return null;
|
|
@@ -6877,10 +8528,10 @@ function createCompiler(args, options) {
|
|
|
6877
8528
|
const tracer = createTracer(internal);
|
|
6878
8529
|
const collector = createCssCollector();
|
|
6879
8530
|
const compileDebug = (args) => {
|
|
6880
|
-
return rewriteTransformResult(transformDebug(internal, args, { tracer }), internal.runtimeMode);
|
|
8531
|
+
return rewriteTransformResult(transformDebug(internal, args, { tracer }), internal.runtimeMode, args.code);
|
|
6881
8532
|
};
|
|
6882
8533
|
const compileDebugRSC = (args) => {
|
|
6883
|
-
const debugResult = rewriteTransformResult(transformDebug(internal, args, { tracer }), internal.runtimeMode);
|
|
8534
|
+
const debugResult = rewriteTransformResult(transformDebug(internal, args, { tracer }), internal.runtimeMode, args.code);
|
|
6884
8535
|
if (!debugResult) return null;
|
|
6885
8536
|
const rscCollector = createCssCollector();
|
|
6886
8537
|
transformExtract(internal, args, {
|
|
@@ -6909,7 +8560,7 @@ function createCompiler(args, options) {
|
|
|
6909
8560
|
return rewriteTransformResult({
|
|
6910
8561
|
...result,
|
|
6911
8562
|
rules: collector.getItems().slice(startIndex)
|
|
6912
|
-
}, internal.runtimeMode);
|
|
8563
|
+
}, internal.runtimeMode, args.code);
|
|
6913
8564
|
};
|
|
6914
8565
|
const getExtractedCss = () => {
|
|
6915
8566
|
return extractCss(collector.getItems(), {
|
|
@@ -6939,23 +8590,73 @@ function createCompilerInternal(args, options) {
|
|
|
6939
8590
|
options
|
|
6940
8591
|
};
|
|
6941
8592
|
}
|
|
6942
|
-
function rewriteTransformResult(result, runtimeMode) {
|
|
8593
|
+
function rewriteTransformResult(result, runtimeMode, sourceCode) {
|
|
6943
8594
|
if (!result || !runtimeMode) return result;
|
|
6944
8595
|
return {
|
|
6945
8596
|
...result,
|
|
6946
|
-
code: rewriteCompilerRuntimeImports(result.code, runtimeMode)
|
|
8597
|
+
code: rewriteCompilerRuntimeImports(result.code, runtimeMode, sourceCode)
|
|
6947
8598
|
};
|
|
6948
8599
|
}
|
|
6949
|
-
function rewriteCompilerRuntimeImports(code, runtimeMode) {
|
|
6950
|
-
|
|
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;
|
|
6951
8607
|
}
|
|
6952
|
-
function getCompilerRuntimeImportSource(source, runtimeMode) {
|
|
6953
|
-
if (source === "@fluentic/style") return getStyleRuntimeImportPath(
|
|
6954
|
-
|
|
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);
|
|
6955
8613
|
if (source === "@fluentic/style/entry/prod/runtime") return getStyleExtractRuntimeImportPath(runtimeMode);
|
|
6956
8614
|
if (runtimeMode === "rsc-dev" && source === "@fluentic/style/dev/rsc") return getStyleRuntimeDevRscImportPath(runtimeMode);
|
|
6957
8615
|
return null;
|
|
6958
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
|
+
};
|
|
6959
8660
|
//#endregion
|
|
6960
8661
|
//#region plugin/utils/constants.ts
|
|
6961
8662
|
const PLUGIN_NAME = "fluentic-style";
|
|
@@ -7086,11 +8787,12 @@ function getStyleRuntimeMode(dev, rsc = false) {
|
|
|
7086
8787
|
if (rsc) return dev ? "rsc-dev" : "rsc-prod";
|
|
7087
8788
|
return dev ? "dev" : "prod";
|
|
7088
8789
|
}
|
|
7089
|
-
function getPluginBuildConfig(options) {
|
|
8790
|
+
function getPluginBuildConfig(options, dev = false) {
|
|
7090
8791
|
const css = hasBuildConfig(options.css) ? options.css : {};
|
|
7091
8792
|
return {
|
|
7092
|
-
hoist: options.hoist !== false,
|
|
7093
|
-
css
|
|
8793
|
+
hoist: !dev && options.hoist !== false,
|
|
8794
|
+
css,
|
|
8795
|
+
check: options.check
|
|
7094
8796
|
};
|
|
7095
8797
|
}
|
|
7096
8798
|
function getPluginBuildDevConfig(options) {
|
|
@@ -7522,6 +9224,12 @@ Object.defineProperty(exports, "CSS_MODULE_ID", {
|
|
|
7522
9224
|
return CSS_MODULE_ID;
|
|
7523
9225
|
}
|
|
7524
9226
|
});
|
|
9227
|
+
Object.defineProperty(exports, "CssPropPresets", {
|
|
9228
|
+
enumerable: true,
|
|
9229
|
+
get: function() {
|
|
9230
|
+
return CssPropPresets;
|
|
9231
|
+
}
|
|
9232
|
+
});
|
|
7525
9233
|
Object.defineProperty(exports, "DEFAULT_TRANSFORM_INCLUDE_PATTERN", {
|
|
7526
9234
|
enumerable: true,
|
|
7527
9235
|
get: function() {
|
|
@@ -7643,4 +9351,4 @@ Object.defineProperty(exports, "writeParcelVirtualRuntimeFile", {
|
|
|
7643
9351
|
}
|
|
7644
9352
|
});
|
|
7645
9353
|
|
|
7646
|
-
//# sourceMappingURL=shared-
|
|
9354
|
+
//# sourceMappingURL=shared-PK52rW6T.cjs.map
|