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