@fluentic/style 0.1.0-beta.0
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 +32 -0
- package/LICENSE +21 -0
- package/README.md +409 -0
- package/atomic/atRule/counterStyle.ts +35 -0
- package/atomic/atRule/fontFace.ts +37 -0
- package/atomic/atRule/fontPaletteValues.ts +36 -0
- package/atomic/atRule/fontSrc.ts +13 -0
- package/atomic/atRule/keyframes.ts +43 -0
- package/atomic/atRule/positionTry.ts +73 -0
- package/atomic/atRule/property.ts +39 -0
- package/atomic/atRule/utils.ts +81 -0
- package/atomic/className.ts +93 -0
- package/atomic/debug/className/className.ts +33 -0
- package/atomic/debug/className/index.ts +1 -0
- package/atomic/debug/property/data.ts +59 -0
- package/atomic/debug/property/index.ts +1 -0
- package/atomic/debug/property/property.ts +59 -0
- package/atomic/debug/selector.ts +88 -0
- package/atomic/debug/value.ts +53 -0
- package/atomic/element.ts +29 -0
- package/atomic/layer/README.md +116 -0
- package/atomic/layer/index.ts +3 -0
- package/atomic/layer/layer.ts +95 -0
- package/atomic/layer/types.ts +37 -0
- package/atomic/layer/utils.ts +51 -0
- package/atomic/property/index.ts +2 -0
- package/atomic/property/presets.ts +34 -0
- package/atomic/property/property.ts +13 -0
- package/atomic/property/type_maps.ts +389 -0
- package/atomic/property/types.ts +7 -0
- package/atomic/rule.ts +116 -0
- package/atomic/theme.ts +48 -0
- package/atomic/token.ts +53 -0
- package/atomic/utils/css.ts +49 -0
- package/atomic/utils/debug.ts +37 -0
- package/atomic/utils/format.ts +192 -0
- package/atomic/utils/selector.ts +14 -0
- package/atomic/utils/types.ts +11 -0
- package/atomic/value/index.ts +2 -0
- package/atomic/value/unitless.ts +47 -0
- package/atomic/value/value.ts +17 -0
- package/atomic/var.ts +19 -0
- package/builder/data/check_selector.noop.ts +8 -0
- package/builder/data/check_selector.ts +30 -0
- package/builder/data/const.ts +25 -0
- package/builder/data/create.ts +96 -0
- package/builder/data/data.ts +63 -0
- package/builder/data/debug.ts +113 -0
- package/builder/data/index.ts +9 -0
- package/builder/data/is.ts +68 -0
- package/builder/data/merge/index.ts +2 -0
- package/builder/data/merge/scope.ts +300 -0
- package/builder/data/merge/style.ts +284 -0
- package/builder/data/merge/utils.ts +35 -0
- package/builder/data/selector.ts +11 -0
- package/builder/data/state.ts +134 -0
- package/builder/extract/index.ts +6 -0
- package/builder/extract/scope.ts +30 -0
- package/builder/extract/slot.ts +36 -0
- package/builder/extract/style.ts +89 -0
- package/builder/extract/theme.ts +16 -0
- package/builder/extract/token.ts +41 -0
- package/builder/extract/utils.ts +95 -0
- package/builder/extract/withTokens.ts +64 -0
- package/builder/index.ts +2 -0
- package/builder/style_builder.ts +234 -0
- package/builder/style_data.ts +81 -0
- package/builder/style_fns.ts +611 -0
- package/builder/types/alias.ts +83 -0
- package/builder/types/fns.ts +185 -0
- package/builder/types/index.ts +1 -0
- package/builder/types/types.ts +51 -0
- package/builder/utils.ts +19 -0
- package/compiler/compiler/cache.ts +155 -0
- package/compiler/compiler/compiler.ts +173 -0
- package/compiler/compiler/index.ts +3 -0
- package/compiler/compiler/types.ts +62 -0
- package/compiler/extract/collector.ts +25 -0
- package/compiler/extract/extract.ts +51 -0
- package/compiler/extract/index.ts +3 -0
- package/compiler/extract/types.ts +35 -0
- package/compiler/index.ts +2 -0
- package/compiler/transform/debug/index.ts +2 -0
- package/compiler/transform/debug/plugin.ts +1347 -0
- package/compiler/transform/debug/transform.ts +47 -0
- package/compiler/transform/debug/utils/debug_data.ts +187 -0
- package/compiler/transform/debug/utils/source_url.ts +29 -0
- package/compiler/transform/evaluator/evaluator.ts +1138 -0
- package/compiler/transform/evaluator/index.ts +3 -0
- package/compiler/transform/evaluator/tracer.ts +607 -0
- package/compiler/transform/evaluator/types.ts +22 -0
- package/compiler/transform/extract/chain/chain.ts +2343 -0
- package/compiler/transform/extract/chain/extract_chain.ts +89 -0
- package/compiler/transform/extract/chain/index.ts +3 -0
- package/compiler/transform/extract/chain/types.ts +37 -0
- package/compiler/transform/extract/index.ts +2 -0
- package/compiler/transform/extract/plugin.ts +665 -0
- package/compiler/transform/extract/transform.ts +45 -0
- package/compiler/transform/extract/utils/imports.ts +132 -0
- package/compiler/transform/extract/utils/replacement.ts +349 -0
- package/compiler/transform/extract/utils/slot.ts +186 -0
- package/compiler/transform/extract/utils/state.ts +48 -0
- package/compiler/transform/extract/utils/theme.ts +86 -0
- package/compiler/transform/extract/utils/token.ts +1 -0
- package/compiler/transform/index.ts +5 -0
- package/compiler/transform/syntax/index.ts +5 -0
- package/compiler/transform/syntax/isStaticStyleValue.ts +44 -0
- package/compiler/transform/syntax/isStyleChainCall.ts +16 -0
- package/compiler/transform/syntax/static_ids.ts +282 -0
- package/compiler/transform/syntax/types.ts +7 -0
- package/compiler/transform/syntax/utils.ts +31 -0
- package/compiler/transform/utils/babel.ts +100 -0
- package/compiler/transform/utils/import.ts +47 -0
- package/compiler/transform/utils/path.ts +13 -0
- package/compiler/transform/utils/selector.ts +252 -0
- package/compiler/utils/constants.ts +69 -0
- package/compiler/utils/file_resolver.ts +72 -0
- package/compiler/utils/import_source.ts +200 -0
- package/compiler/utils/imports.ts +24 -0
- package/compiler/utils/path.ts +40 -0
- package/compiler/utils/sourcemap.ts +61 -0
- package/config/build.ts +32 -0
- package/config/config/css.ts +32 -0
- package/config/config/css_extra.ts +22 -0
- package/config/config/debug.ts +26 -0
- package/config/config/dev.ts +145 -0
- package/config/config/runtime.ts +29 -0
- package/config/configure.ts +28 -0
- package/config/constants.ts +1 -0
- package/config/index.ts +2 -0
- package/config/types.ts +56 -0
- package/config/utils.ts +5 -0
- package/css/counterStyle.ts +20 -0
- package/css/fontFace.ts +25 -0
- package/css/fontPaletteValues.ts +20 -0
- package/css/index.ts +8 -0
- package/css/keyframes.ts +20 -0
- package/css/positionTry.ts +20 -0
- package/css/property.ts +32 -0
- package/css/utils.ts +56 -0
- package/dev/config.ts +16 -0
- package/dev/fns.ts +48 -0
- package/dev/index.ts +2 -0
- package/dev/trace.ts +413 -0
- package/dev/utils.ts +528 -0
- package/dist/assert-h_Zkqc4E.js +105 -0
- package/dist/assert-h_Zkqc4E.js.map +1 -0
- package/dist/className-C1Ht5Wvv.js +144 -0
- package/dist/className-C1Ht5Wvv.js.map +1 -0
- package/dist/className-DC2Cq8p3.js +251 -0
- package/dist/className-DC2Cq8p3.js.map +1 -0
- package/dist/compiler/index.mjs +2 -0
- package/dist/compiler-DweanHoB.mjs +6847 -0
- package/dist/compiler-DweanHoB.mjs.map +1 -0
- package/dist/config/index.js +3 -0
- package/dist/config-BryWDfQX.js +25 -0
- package/dist/config-BryWDfQX.js.map +1 -0
- package/dist/config-DKHXWhe1.js +1 -0
- package/dist/config-Di2VYYKV.js +6 -0
- package/dist/config-Di2VYYKV.js.map +1 -0
- package/dist/config-DloHOG6I.js +13 -0
- package/dist/config-DloHOG6I.js.map +1 -0
- package/dist/css-BowBszUt.js +243 -0
- package/dist/css-BowBszUt.js.map +1 -0
- package/dist/css-ByOrugEX.js +805 -0
- package/dist/css-ByOrugEX.js.map +1 -0
- package/dist/css-DcazYor9.js +235 -0
- package/dist/css-DcazYor9.js.map +1 -0
- package/dist/css.js +2 -0
- package/dist/css_extra-DlOnsnR1.js +8 -0
- package/dist/css_extra-DlOnsnR1.js.map +1 -0
- package/dist/css_extra-oIi3UEPK.js +8 -0
- package/dist/css_extra-oIi3UEPK.js.map +1 -0
- package/dist/data-_te7t0M4.js +473 -0
- package/dist/data-_te7t0M4.js.map +1 -0
- package/dist/debug-BAw63qX6.js +15 -0
- package/dist/debug-BAw63qX6.js.map +1 -0
- package/dist/debug-DGki_v7g.js +15 -0
- package/dist/debug-DGki_v7g.js.map +1 -0
- package/dist/debug-n2aZQBSa.js +172 -0
- package/dist/debug-n2aZQBSa.js.map +1 -0
- package/dist/dev/rsc.js +183 -0
- package/dist/dev/rsc.js.map +1 -0
- package/dist/dev-CcphAa3R.js +376 -0
- package/dist/dev-CcphAa3R.js.map +1 -0
- package/dist/dev-DfBbuLeE.js +71 -0
- package/dist/dev-DfBbuLeE.js.map +1 -0
- package/dist/dev.js +2 -0
- package/dist/elementMarker-Bu7gDAkE.js +800 -0
- package/dist/elementMarker-Bu7gDAkE.js.map +1 -0
- package/dist/entry/dev/css.js +3 -0
- package/dist/entry/dev/jsx-dev-runtime.js +3 -0
- package/dist/entry/dev/jsx-runtime.js +3 -0
- package/dist/entry/dev.js +10 -0
- package/dist/entry/prod/css.js +3 -0
- package/dist/entry/prod/extract.js +3 -0
- package/dist/entry/prod/jsx-dev-runtime.js +3 -0
- package/dist/entry/prod/jsx-runtime.js +3 -0
- package/dist/entry/prod/runtime.js +5 -0
- package/dist/entry/prod.js +1230 -0
- package/dist/entry/prod.js.map +1 -0
- package/dist/entry/rsc-dev/css.js +3 -0
- package/dist/entry/rsc-dev/dev.js +544 -0
- package/dist/entry/rsc-dev/dev.js.map +1 -0
- package/dist/entry/rsc-dev/jsx-dev-runtime.js +12 -0
- package/dist/entry/rsc-dev/jsx-dev-runtime.js.map +1 -0
- package/dist/entry/rsc-dev/jsx-runtime.js +3 -0
- package/dist/entry/rsc-dev.js +1429 -0
- package/dist/entry/rsc-dev.js.map +1 -0
- package/dist/entry/rsc-prod/css.js +3 -0
- package/dist/entry/rsc-prod/jsx-dev-runtime.js +3 -0
- package/dist/entry/rsc-prod/jsx-runtime.js +3 -0
- package/dist/entry/rsc-prod/runtime.js +5 -0
- package/dist/entry/rsc-prod.js +10 -0
- package/dist/extract-CzWJeQi8.js +121 -0
- package/dist/extract-CzWJeQi8.js.map +1 -0
- package/dist/extract-DEwSDJ9Z.js +2 -0
- package/dist/format-3nKBE_5t.js +144 -0
- package/dist/format-3nKBE_5t.js.map +1 -0
- package/dist/getClassName-BlvXHYuf.js +260 -0
- package/dist/getClassName-BlvXHYuf.js.map +1 -0
- package/dist/global-CvfmFLsK.js +11 -0
- package/dist/global-CvfmFLsK.js.map +1 -0
- package/dist/index.js +9 -0
- package/dist/jsx/jsx-dev-runtime.js +12 -0
- package/dist/jsx/jsx-dev-runtime.js.map +1 -0
- package/dist/jsx/jsx-dev-runtime.server.js +11 -0
- package/dist/jsx/jsx-dev-runtime.server.js.map +1 -0
- package/dist/jsx/jsx-runtime.js +13 -0
- package/dist/jsx/jsx-runtime.js.map +1 -0
- package/dist/jsx/jsx-runtime.server.js +12 -0
- package/dist/jsx/jsx-runtime.server.js.map +1 -0
- package/dist/jsx-CwTeyUxr.js +39 -0
- package/dist/jsx-CwTeyUxr.js.map +1 -0
- package/dist/jsx-D2BksHSv.js +38 -0
- package/dist/jsx-D2BksHSv.js.map +1 -0
- package/dist/jsx_dev_runtime-B6xs4by8.js +12 -0
- package/dist/jsx_dev_runtime-B6xs4by8.js.map +1 -0
- package/dist/jsx_runtime-04xfnsi7.js +13 -0
- package/dist/jsx_runtime-04xfnsi7.js.map +1 -0
- package/dist/jsx_runtime-iHLDwpcW.js +12 -0
- package/dist/jsx_runtime-iHLDwpcW.js.map +1 -0
- package/dist/layer-D1SaH07m.js +94 -0
- package/dist/layer-D1SaH07m.js.map +1 -0
- package/dist/loader-DS61nRqr.mjs +81 -0
- package/dist/loader-DS61nRqr.mjs.map +1 -0
- package/dist/misc-B9kqEb2N.mjs +360 -0
- package/dist/misc-B9kqEb2N.mjs.map +1 -0
- package/dist/plugin/farm/index.mjs +176 -0
- package/dist/plugin/farm/index.mjs.map +1 -0
- package/dist/plugin/nextjs/index.mjs +282 -0
- package/dist/plugin/nextjs/index.mjs.map +1 -0
- package/dist/plugin/nextjs/loader.mjs +162 -0
- package/dist/plugin/nextjs/loader.mjs.map +1 -0
- package/dist/plugin/parcel/index.cjs +9 -0
- package/dist/plugin/parcel/index.mjs +5 -0
- package/dist/plugin/parcel/optimizer.cjs +28 -0
- package/dist/plugin/parcel/optimizer.cjs.map +1 -0
- package/dist/plugin/parcel/optimizer.mjs +29 -0
- package/dist/plugin/parcel/optimizer.mjs.map +1 -0
- package/dist/plugin/parcel/resolver.cjs +17 -0
- package/dist/plugin/parcel/resolver.cjs.map +1 -0
- package/dist/plugin/parcel/resolver.mjs +18 -0
- package/dist/plugin/parcel/resolver.mjs.map +1 -0
- package/dist/plugin/parcel/runtime.cjs +17 -0
- package/dist/plugin/parcel/runtime.cjs.map +1 -0
- package/dist/plugin/parcel/runtime.mjs +17 -0
- package/dist/plugin/parcel/runtime.mjs.map +1 -0
- package/dist/plugin/parcel/transformer.cjs +41 -0
- package/dist/plugin/parcel/transformer.cjs.map +1 -0
- package/dist/plugin/parcel/transformer.mjs +41 -0
- package/dist/plugin/parcel/transformer.mjs.map +1 -0
- package/dist/plugin/rspack/index.mjs +11 -0
- package/dist/plugin/rspack/index.mjs.map +1 -0
- package/dist/plugin/vite/index.mjs +176 -0
- package/dist/plugin/vite/index.mjs.map +1 -0
- package/dist/plugin/webpack/index.mjs +2 -0
- package/dist/plugin/webpack/loader.mjs +19 -0
- package/dist/plugin/webpack/loader.mjs.map +1 -0
- package/dist/presets-Bye3ea2x.js +139 -0
- package/dist/presets-Bye3ea2x.js.map +1 -0
- package/dist/property-CnLFt5kx.js +406 -0
- package/dist/property-CnLFt5kx.js.map +1 -0
- package/dist/registry-CyIj8LYK.mjs +22 -0
- package/dist/registry-CyIj8LYK.mjs.map +1 -0
- package/dist/rules-9HSO1pxL.js +767 -0
- package/dist/rules-9HSO1pxL.js.map +1 -0
- package/dist/runtime-CYqNCiaM.js +53 -0
- package/dist/runtime-CYqNCiaM.js.map +1 -0
- package/dist/selector/index.js +3 -0
- package/dist/server.js +63 -0
- package/dist/server.js.map +1 -0
- package/dist/shared-BAL9peIw.cjs +7646 -0
- package/dist/shared-BAL9peIw.cjs.map +1 -0
- package/dist/shared-CCpq1zqA.mjs +132 -0
- package/dist/shared-CCpq1zqA.mjs.map +1 -0
- package/dist/sidecar-4u6GnlQG.mjs +236 -0
- package/dist/sidecar-4u6GnlQG.mjs.map +1 -0
- package/dist/style-4rFUy-zW.js +752 -0
- package/dist/style-4rFUy-zW.js.map +1 -0
- package/dist/style-B1UUqjj5.js +743 -0
- package/dist/style-B1UUqjj5.js.map +1 -0
- package/dist/style-Cw3NtvR0.js +5 -0
- package/dist/style-DNqQ6H-7.js +1255 -0
- package/dist/style-DNqQ6H-7.js.map +1 -0
- package/dist/styleStore-Dea_WVbr.js +2000 -0
- package/dist/styleStore-Dea_WVbr.js.map +1 -0
- package/dist/styleStore-DyNXBcUK.js +54 -0
- package/dist/styleStore-DyNXBcUK.js.map +1 -0
- package/dist/token-CKXUECuU.js +76 -0
- package/dist/token-CKXUECuU.js.map +1 -0
- package/dist/token-u_tM-mtg.js +204 -0
- package/dist/token-u_tM-mtg.js.map +1 -0
- package/dist/trace-Bu_qOqRy.js +245 -0
- package/dist/trace-Bu_qOqRy.js.map +1 -0
- package/dist/trace-CU0rvNYr.js +244 -0
- package/dist/trace-CU0rvNYr.js.map +1 -0
- package/dist/utils-BbehLOby.js +2415 -0
- package/dist/utils-BbehLOby.js.map +1 -0
- package/dist/utils-C7xfDxtM.mjs +97 -0
- package/dist/utils-C7xfDxtM.mjs.map +1 -0
- package/dist/utils-CWNHx4EC.js +170 -0
- package/dist/utils-CWNHx4EC.js.map +1 -0
- package/dist/utils-CdI6vZsP.js +37 -0
- package/dist/utils-CdI6vZsP.js.map +1 -0
- package/dist/utils-D7FAOyg6.js +129 -0
- package/dist/utils-D7FAOyg6.js.map +1 -0
- package/dist/utils-DMFgOOtA.mjs +49 -0
- package/dist/utils-DMFgOOtA.mjs.map +1 -0
- package/dist/utils.js +26 -0
- package/dist/utils.js.map +1 -0
- package/dist/value-BR4e2MKt.js +910 -0
- package/dist/value-BR4e2MKt.js.map +1 -0
- package/dist/value-E8rEv2Oe.js +136 -0
- package/dist/value-E8rEv2Oe.js.map +1 -0
- package/dist/valueRef-lshFk1Cs.js +16 -0
- package/dist/valueRef-lshFk1Cs.js.map +1 -0
- package/dist/webpack-CxS2FDYU.mjs +107 -0
- package/dist/webpack-CxS2FDYU.mjs.map +1 -0
- package/dist/withTokens-LRidu3Vc.js +95 -0
- package/dist/withTokens-LRidu3Vc.js.map +1 -0
- package/entry/dev/config.ts +2 -0
- package/entry/dev/css.ts +3 -0
- package/entry/dev/index.ts +3 -0
- package/entry/dev/jsx_dev_runtime.ts +3 -0
- package/entry/dev/jsx_runtime.ts +3 -0
- package/entry/prod/config.ts +2 -0
- package/entry/prod/css.ts +3 -0
- package/entry/prod/extract.ts +1 -0
- package/entry/prod/index.ts +3 -0
- package/entry/prod/jsx_dev_runtime.ts +3 -0
- package/entry/prod/jsx_runtime.ts +3 -0
- package/entry/prod/runtime.ts +14 -0
- package/entry/rsc_dev/config.ts +6 -0
- package/entry/rsc_dev/css.ts +3 -0
- package/entry/rsc_dev/dev.ts +5 -0
- package/entry/rsc_dev/index.ts +3 -0
- package/entry/rsc_dev/jsx_dev_runtime.ts +3 -0
- package/entry/rsc_dev/jsx_runtime.ts +3 -0
- package/entry/rsc_dev/server.ts +11 -0
- package/entry/rsc_prod/config.ts +6 -0
- package/entry/rsc_prod/css.ts +3 -0
- package/entry/rsc_prod/index.ts +3 -0
- package/entry/rsc_prod/jsx_dev_runtime.ts +3 -0
- package/entry/rsc_prod/jsx_runtime.ts +3 -0
- package/entry/rsc_prod/runtime.ts +12 -0
- package/entry/rsc_prod/server.ts +13 -0
- package/entry/shared/config.ts +5 -0
- package/entry/shared/dev.ts +19 -0
- package/entry/shared/prod.ts +4 -0
- package/index.ts +36 -0
- package/jsx/extracted/jsx_dev_runtime.ts +11 -0
- package/jsx/extracted/jsx_runtime.ts +12 -0
- package/jsx/rsc/jsx_dev_runtime.ts +11 -0
- package/jsx/rsc/jsx_runtime.ts +12 -0
- package/jsx/rsc_extracted/jsx_dev_runtime.ts +2 -0
- package/jsx/rsc_extracted/jsx_runtime.ts +2 -0
- package/jsx/runtime/jsx_dev_runtime.ts +11 -0
- package/jsx/runtime/jsx_runtime.ts +12 -0
- package/jsx/types.ts +8 -0
- package/jsx/utils.ts +59 -0
- package/package.json +298 -0
- package/plugin/bundler/farm/index.ts +1 -0
- package/plugin/bundler/farm/plugin.ts +320 -0
- package/plugin/bundler/parcel/config.json +19 -0
- package/plugin/bundler/parcel/index.ts +1 -0
- package/plugin/bundler/parcel/optimizer.ts +36 -0
- package/plugin/bundler/parcel/plugin.ts +4 -0
- package/plugin/bundler/parcel/resolver.ts +36 -0
- package/plugin/bundler/parcel/runtime.ts +23 -0
- package/plugin/bundler/parcel/shared.ts +234 -0
- package/plugin/bundler/parcel/transformer.ts +67 -0
- package/plugin/bundler/rspack/index.ts +1 -0
- package/plugin/bundler/rspack/plugin.ts +14 -0
- package/plugin/bundler/vite/index.ts +1 -0
- package/plugin/bundler/vite/plugin.ts +133 -0
- package/plugin/bundler/vite/state.ts +153 -0
- package/plugin/bundler/webpack/index.ts +1 -0
- package/plugin/bundler/webpack/loader.ts +19 -0
- package/plugin/bundler/webpack/plugin.ts +240 -0
- package/plugin/bundler/webpack/shared/index.ts +2 -0
- package/plugin/bundler/webpack/shared/loader.ts +155 -0
- package/plugin/bundler/webpack/shared/registry.ts +16 -0
- package/plugin/bundler/webpack/utils.ts +96 -0
- package/plugin/nextjs/constants.ts +7 -0
- package/plugin/nextjs/html.ts +62 -0
- package/plugin/nextjs/index.ts +2 -0
- package/plugin/nextjs/loader.ts +222 -0
- package/plugin/nextjs/plugin.ts +532 -0
- package/plugin/nextjs/types.ts +33 -0
- package/plugin/nextjs/utils.ts +210 -0
- package/plugin/utils/cache/css_cache.ts +146 -0
- package/plugin/utils/cache/file.ts +40 -0
- package/plugin/utils/cache/index.ts +2 -0
- package/plugin/utils/compiler.ts +94 -0
- package/plugin/utils/constants.ts +7 -0
- package/plugin/utils/cssMarker.ts +14 -0
- package/plugin/utils/cssOutput.ts +65 -0
- package/plugin/utils/filter.ts +98 -0
- package/plugin/utils/imports.ts +5 -0
- package/plugin/utils/index.ts +10 -0
- package/plugin/utils/injection.ts +28 -0
- package/plugin/utils/misc.ts +5 -0
- package/plugin/utils/runtimeEntry.ts +57 -0
- package/plugin/utils/sidecar/index.ts +1 -0
- package/plugin/utils/sidecar/server.ts +143 -0
- package/plugin/utils/sidecar/sidecar.ts +167 -0
- package/plugin/utils/sidecar/utils.ts +109 -0
- package/plugin/utils/sourcemap.ts +52 -0
- package/plugin/utils/virtual.ts +81 -0
- package/runtime/core/cache/combine.ts +102 -0
- package/runtime/core/cache/index.ts +5 -0
- package/runtime/core/cache/item.ts +231 -0
- package/runtime/core/cache/pool.ts +310 -0
- package/runtime/core/cache/prop.ts +283 -0
- package/runtime/core/cache/propCache.ts +62 -0
- package/runtime/core/cache/resolvedItem.ts +31 -0
- package/runtime/core/cache/result.ts +115 -0
- package/runtime/core/cache/stateItem.ts +208 -0
- package/runtime/core/cache/tokenValues.ts +150 -0
- package/runtime/core/cache/utils/tree.ts +57 -0
- package/runtime/core/cache/utils/walk.ts +24 -0
- package/runtime/core/className.ts +101 -0
- package/runtime/core/combinedStyle.ts +101 -0
- package/runtime/core/createTransformElement.ts +39 -0
- package/runtime/core/elementMarker.ts +189 -0
- package/runtime/core/elementMarkerData.ts +27 -0
- package/runtime/core/getClassName.ts +47 -0
- package/runtime/core/getSheetRules.ts +7 -0
- package/runtime/core/getToken.ts +14 -0
- package/runtime/core/index.ts +5 -0
- package/runtime/core/jsx.ts +4 -0
- package/runtime/core/resolveClassNameRuntime.ts +33 -0
- package/runtime/env.ts +7 -0
- package/runtime/extract/getClassName.ts +476 -0
- package/runtime/extract/index.ts +4 -0
- package/runtime/extract/jsx.ts +55 -0
- package/runtime/index.ts +12 -0
- package/runtime/rsc/constants.ts +6 -0
- package/runtime/rsc/dev.ts +38 -0
- package/runtime/rsc/getClassName.ts +98 -0
- package/runtime/rsc/index.ts +3 -0
- package/runtime/rsc/jsx.ts +4 -0
- package/runtime/rsc/observer.ts +238 -0
- package/runtime/rsc/styleStore.ts +82 -0
- package/runtime/sheet/element.ts +13 -0
- package/runtime/sheet/global-noop.ts +13 -0
- package/runtime/sheet/global-prod.ts +13 -0
- package/runtime/sheet/global.ts +13 -0
- package/runtime/sheet/index.ts +3 -0
- package/runtime/sheet/insert.ts +37 -0
- package/runtime/sheet/rule.ts +77 -0
- package/runtime/sheet/rules.ts +131 -0
- package/runtime/sheet/theme.ts +34 -0
- package/runtime/style/index.ts +3 -0
- package/runtime/style/scope.ts +65 -0
- package/runtime/style/style.ts +34 -0
- package/runtime/style/token.ts +1 -0
- package/runtime/types.ts +42 -0
- package/selector/assert.ts +131 -0
- package/selector/index.ts +5 -0
- package/selector/presets/default.ts +27 -0
- package/selector/presets/index.ts +3 -0
- package/selector/presets/minimal.ts +37 -0
- package/selector/presets/selectors.ts +85 -0
- package/selector/selector.ts +68 -0
- package/selector/types.ts +24 -0
- package/selector/validate.ts +91 -0
- package/sheet/dev/dev_layer.ts +151 -0
- package/sheet/dev/dev_sort.ts +249 -0
- package/sheet/dev/index.ts +129 -0
- package/sheet/dev/utils.ts +130 -0
- package/sheet/index.ts +4 -0
- package/sheet/prod.ts +109 -0
- package/sheet/sheet.ts +10 -0
- package/sheet/sourcemap.ts +70 -0
- package/sheet/types.ts +31 -0
- package/sheet/utils/dom.ts +71 -0
- package/sheet/utils/index.ts +4 -0
- package/sheet/utils/layer.ts +14 -0
- package/sheet/utils/noop.ts +11 -0
- package/sheet/utils/rule.ts +3 -0
- package/sheet/utils/sourcemap.ts +221 -0
- package/style/index.ts +9 -0
- package/style/keyframes.ts +40 -0
- package/style/style.ts +112 -0
- package/style/theme.ts +36 -0
- package/style/token.ts +101 -0
- package/style/tokens.ts +64 -0
- package/style/transform.ts +9 -0
- package/style/types.ts +32 -0
- package/style/utils/expose.ts +43 -0
- package/style/utils/index.ts +1 -0
- package/style/value.ts +103 -0
- package/style/valueRef.ts +25 -0
- package/utils/global.ts +44 -0
- package/utils/hash.ts +22 -0
- package/utils/id.ts +20 -0
- package/utils/object.ts +87 -0
- package/utils/trace.ts +211 -0
- package/utils/type.ts +22 -0
|
@@ -0,0 +1,1138 @@
|
|
|
1
|
+
import { buildCounterStyleCss, formatCounterStyleName } from '../../../atomic/atRule/counterStyle';
|
|
2
|
+
import { buildFontFaceCss, type FontFaceObject, formatFontFaceName } from '../../../atomic/atRule/fontFace';
|
|
3
|
+
import { buildFontPaletteValuesCss, formatFontPaletteValuesName } from '../../../atomic/atRule/fontPaletteValues';
|
|
4
|
+
import { fontSrc } from '../../../atomic/atRule/fontSrc';
|
|
5
|
+
import { buildKeyframesCss, formatKeyFramesName, type KeyframesObject } from '../../../atomic/atRule/keyframes';
|
|
6
|
+
import { buildPositionTryCss, formatPositionTryName } from '../../../atomic/atRule/positionTry';
|
|
7
|
+
import { buildPropertyCss, formatPropertyName, type PropertyObject } from '../../../atomic/atRule/property';
|
|
8
|
+
import { TRACE_STYLE, TRACE_VALUE } from '../../../builder/data/debug';
|
|
9
|
+
import {
|
|
10
|
+
createExtractedScope,
|
|
11
|
+
createExtractedSlot,
|
|
12
|
+
createExtractedStyle,
|
|
13
|
+
createExtractedStyleMerge,
|
|
14
|
+
getExtractedStyleItems,
|
|
15
|
+
} from '../../../builder/extract';
|
|
16
|
+
import { CSS_CONFIG } from '../../../config/config/css';
|
|
17
|
+
import { CSS_EXTRA_CONFIG } from '../../../config/config/css_extra';
|
|
18
|
+
import type { NamedAtRuleFormat, TokenNameFormat } from '../../../config/types';
|
|
19
|
+
import { transformKeyframes } from '../../../style/keyframes';
|
|
20
|
+
import type { StyleFnMeta } from '../../../style/style';
|
|
21
|
+
import {
|
|
22
|
+
getStyleTokenId,
|
|
23
|
+
isStyleTokenData,
|
|
24
|
+
type StyleTokenData,
|
|
25
|
+
type StyleTokenOverride,
|
|
26
|
+
TOKEN_ID,
|
|
27
|
+
TOKEN_OVERRIDE,
|
|
28
|
+
} from '../../../style/token';
|
|
29
|
+
import type { StyleTransform } from '../../../style/transform';
|
|
30
|
+
import { exposeStyle } from '../../../style/utils';
|
|
31
|
+
import { type AtRuleRef, createAtRuleRef } from '../../../style/valueRef';
|
|
32
|
+
import { hashString } from '../../../utils/hash';
|
|
33
|
+
import type { StableId } from '../../../utils/id';
|
|
34
|
+
import {
|
|
35
|
+
FN_CREATE_COUNTER_STYLE,
|
|
36
|
+
FN_CREATE_EXTRACTED_SCOPE,
|
|
37
|
+
FN_CREATE_EXTRACTED_SLOT,
|
|
38
|
+
FN_CREATE_EXTRACTED_STYLE,
|
|
39
|
+
FN_CREATE_EXTRACTED_STYLE_MERGE,
|
|
40
|
+
FN_CREATE_FONT_FACE,
|
|
41
|
+
FN_CREATE_FONT_PALETTE_VALUES,
|
|
42
|
+
FN_CREATE_KEYFRAMES,
|
|
43
|
+
FN_CREATE_POSITION_TRY,
|
|
44
|
+
FN_CREATE_PROPERTY,
|
|
45
|
+
FN_CREATE_TOKEN,
|
|
46
|
+
FN_CREATE_TOKENS,
|
|
47
|
+
FN_CREATE_VALUES,
|
|
48
|
+
FN_EXPOSE_STYLE,
|
|
49
|
+
FN_FONT_SRC,
|
|
50
|
+
FN_GET_EXTRACTED_STYLE_ITEMS,
|
|
51
|
+
FN_STYLE_KEYFRAMES,
|
|
52
|
+
FN_STYLE_PLAIN,
|
|
53
|
+
FN_STYLE_RAW,
|
|
54
|
+
FN_STYLE_VALUE,
|
|
55
|
+
IMPORT_EXTRACT,
|
|
56
|
+
IMPORT_PATHS,
|
|
57
|
+
STYLE_UTILS_IMPORT_PATH,
|
|
58
|
+
} from '../../utils/constants';
|
|
59
|
+
import type { BabelTypes } from '../utils/babel';
|
|
60
|
+
import type { EvalFail, EvalModuleBindings, EvalOk, EvalResult, ImportMap, ResolveImportFn } from './types';
|
|
61
|
+
|
|
62
|
+
const STYLE_IMPORT_PATHS = new Set(IMPORT_PATHS);
|
|
63
|
+
|
|
64
|
+
export const COMPILED_RUNTIME_VALUE = Symbol();
|
|
65
|
+
export const COMPILED_STYLE_OBJECT_LOCATIONS = Symbol();
|
|
66
|
+
const COMPILED_TOKEN_FACTORY = Symbol();
|
|
67
|
+
|
|
68
|
+
export type CompiledRuntimeValue = {
|
|
69
|
+
[COMPILED_RUNTIME_VALUE]?: BabelTypes.Expression;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export type CompiledStyleObjectLocations = Record<string, {
|
|
73
|
+
filePath: string;
|
|
74
|
+
line: number;
|
|
75
|
+
column: number;
|
|
76
|
+
trace?: typeof TRACE_STYLE | typeof TRACE_VALUE;
|
|
77
|
+
}>;
|
|
78
|
+
|
|
79
|
+
export type CompiledStyleObject = Record<string, unknown> & {
|
|
80
|
+
[COMPILED_STYLE_OBJECT_LOCATIONS]?: CompiledStyleObjectLocations;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
type CompiledTokenFactory = {
|
|
84
|
+
[COMPILED_TOKEN_FACTORY]: true;
|
|
85
|
+
tokens: Map<unknown, StyleTokenData>;
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
export function evalOk(value: unknown): EvalOk {
|
|
89
|
+
return { ok: true, value };
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export function evalFail(reason: string): EvalFail {
|
|
93
|
+
return { ok: false, reason };
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export type EvalScope = {
|
|
97
|
+
bindings: EvalModuleBindings;
|
|
98
|
+
imports: ImportMap;
|
|
99
|
+
resolveImport: ResolveImportFn;
|
|
100
|
+
filePath: string;
|
|
101
|
+
styleFilePath?: string;
|
|
102
|
+
styleNames?: Set<string>;
|
|
103
|
+
styleMetas?: Map<string, StyleFnMeta>;
|
|
104
|
+
bindingNodes?: Map<string, BabelTypes.Node>;
|
|
105
|
+
styleTransform?: StyleTransform | null;
|
|
106
|
+
sourcemapTrace?: 'style' | 'value';
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
export function evaluateNode(
|
|
110
|
+
node: BabelTypes.Node | null | undefined,
|
|
111
|
+
scope: EvalScope,
|
|
112
|
+
): EvalResult {
|
|
113
|
+
if (!node) return evalFail('null node');
|
|
114
|
+
|
|
115
|
+
switch (node.type) {
|
|
116
|
+
case 'StringLiteral':
|
|
117
|
+
return evalOk(node.value);
|
|
118
|
+
|
|
119
|
+
case 'NumericLiteral':
|
|
120
|
+
return evalOk(node.value);
|
|
121
|
+
|
|
122
|
+
case 'BooleanLiteral':
|
|
123
|
+
return evalOk(node.value);
|
|
124
|
+
|
|
125
|
+
case 'NullLiteral':
|
|
126
|
+
return evalOk(null);
|
|
127
|
+
|
|
128
|
+
case 'TemplateLiteral':
|
|
129
|
+
return evaluateTemplate(node, scope);
|
|
130
|
+
|
|
131
|
+
case 'Identifier':
|
|
132
|
+
return evaluateIdentifier(node, scope);
|
|
133
|
+
|
|
134
|
+
case 'MemberExpression':
|
|
135
|
+
return evaluateMember(node as BabelTypes.MemberExpression, scope);
|
|
136
|
+
|
|
137
|
+
case 'ObjectExpression':
|
|
138
|
+
return evaluateObject(node as BabelTypes.ObjectExpression, scope);
|
|
139
|
+
|
|
140
|
+
case 'ArrayExpression':
|
|
141
|
+
return evaluateArray(node as BabelTypes.ArrayExpression, scope);
|
|
142
|
+
|
|
143
|
+
case 'CallExpression':
|
|
144
|
+
return evaluateCall(node as BabelTypes.CallExpression, scope);
|
|
145
|
+
|
|
146
|
+
case 'BinaryExpression':
|
|
147
|
+
return evaluateBinary(node as BabelTypes.BinaryExpression, scope);
|
|
148
|
+
|
|
149
|
+
case 'UnaryExpression':
|
|
150
|
+
return evaluateUnary(node as BabelTypes.UnaryExpression, scope);
|
|
151
|
+
|
|
152
|
+
case 'ParenthesizedExpression':
|
|
153
|
+
case 'TSAsExpression':
|
|
154
|
+
case 'TSNonNullExpression':
|
|
155
|
+
case 'TSTypeAssertion':
|
|
156
|
+
return evaluateNode((node as any).expression, scope);
|
|
157
|
+
|
|
158
|
+
default:
|
|
159
|
+
return evalFail(`Cannot statically evaluate: ${node.type}`);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export function evaluateEnumDeclaration(
|
|
164
|
+
node: BabelTypes.TSEnumDeclaration,
|
|
165
|
+
scope: EvalScope,
|
|
166
|
+
): EvalResult {
|
|
167
|
+
const result: Record<string, string | number> = {};
|
|
168
|
+
let nextNumber = 0;
|
|
169
|
+
|
|
170
|
+
for (const member of node.members) {
|
|
171
|
+
const key = getEnumMemberKey(member.id);
|
|
172
|
+
if (key === null) return evalFail('Unsupported enum member key');
|
|
173
|
+
|
|
174
|
+
let value: string | number;
|
|
175
|
+
|
|
176
|
+
if (member.initializer) {
|
|
177
|
+
const resolved = evaluateNode(member.initializer, scope);
|
|
178
|
+
if (!resolved.ok) return resolved;
|
|
179
|
+
if (typeof resolved.value !== 'string' && typeof resolved.value !== 'number') {
|
|
180
|
+
return evalFail('Enum member value must be a string or number');
|
|
181
|
+
}
|
|
182
|
+
value = resolved.value;
|
|
183
|
+
} else {
|
|
184
|
+
value = nextNumber;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
result[key] = value;
|
|
188
|
+
if (typeof value === 'number') {
|
|
189
|
+
result[value] = key;
|
|
190
|
+
nextNumber = value + 1;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
return evalOk(result);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function getEnumMemberKey(
|
|
198
|
+
node: BabelTypes.TSEnumMember['id'],
|
|
199
|
+
): string | null {
|
|
200
|
+
if (node.type === 'Identifier') return node.name;
|
|
201
|
+
if (node.type === 'StringLiteral') return node.value;
|
|
202
|
+
return null;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
function evaluateTemplate(node: BabelTypes.TemplateLiteral, scope: EvalScope): EvalResult {
|
|
206
|
+
let result = '';
|
|
207
|
+
const quasis = node.quasis;
|
|
208
|
+
const exprs = node.expressions;
|
|
209
|
+
|
|
210
|
+
let i = 0;
|
|
211
|
+
while (i < quasis.length) {
|
|
212
|
+
result += quasis[i].value.cooked ?? quasis[i].value.raw;
|
|
213
|
+
if (i < exprs.length) {
|
|
214
|
+
const v = evaluateNode(exprs[i] as BabelTypes.Node, scope);
|
|
215
|
+
if (!v.ok) return v;
|
|
216
|
+
result += String(v.value ?? '');
|
|
217
|
+
}
|
|
218
|
+
i++;
|
|
219
|
+
}
|
|
220
|
+
return evalOk(result);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
function evaluateIdentifier(node: BabelTypes.Identifier, scope: EvalScope): EvalResult {
|
|
224
|
+
const name = node.name;
|
|
225
|
+
|
|
226
|
+
if (name === 'undefined') return evalOk(undefined);
|
|
227
|
+
if (name === 'null') return evalOk(null);
|
|
228
|
+
if (name === 'true') return evalOk(true);
|
|
229
|
+
if (name === 'false') return evalOk(false);
|
|
230
|
+
|
|
231
|
+
// Check local bindings first
|
|
232
|
+
if (scope.bindings.has(name)) {
|
|
233
|
+
const result = scope.bindings.get(name)!;
|
|
234
|
+
|
|
235
|
+
if (result.ok && isStyleTokenData(result.value)) {
|
|
236
|
+
return evalOk(withRuntimeValue(node, result.value));
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
return result;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
// Check imports
|
|
243
|
+
const imp = scope.imports.get(name);
|
|
244
|
+
|
|
245
|
+
if (imp) {
|
|
246
|
+
const exported = scope.resolveImport(imp.source, scope.filePath);
|
|
247
|
+
|
|
248
|
+
if (!exported) return evalFail(`Cannot resolve import: ${imp.source}`);
|
|
249
|
+
|
|
250
|
+
if (exported.has(imp.name)) return exported.get(imp.name)!;
|
|
251
|
+
|
|
252
|
+
return evalFail(`Export '${imp.name}' not found in ${imp.source}`);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
return evalFail(`Cannot resolve identifier: ${name}`);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
function evaluateMember(node: BabelTypes.MemberExpression, scope: EvalScope): EvalResult {
|
|
259
|
+
if (node.computed) {
|
|
260
|
+
const key = evaluateNode(node.property as BabelTypes.Node, scope);
|
|
261
|
+
if (!key.ok) return key;
|
|
262
|
+
|
|
263
|
+
const obj = evaluateNode(node.object, scope);
|
|
264
|
+
if (!obj.ok) return obj;
|
|
265
|
+
|
|
266
|
+
if (obj.value && typeof obj.value === 'object') {
|
|
267
|
+
return evalOk((obj.value as any)[key.value as string]);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
return evalFail('Cannot index non-object');
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
const prop = (node.property as BabelTypes.Identifier).name;
|
|
274
|
+
const obj = evaluateNode(node.object, scope);
|
|
275
|
+
if (!obj.ok) return obj;
|
|
276
|
+
|
|
277
|
+
if (obj.value == null) return evalFail(`Cannot access .${prop} on null/undefined`);
|
|
278
|
+
if (typeof obj.value !== 'object' && typeof obj.value !== 'string') {
|
|
279
|
+
return evalFail(`Cannot access .${prop} on ${typeof obj.value}`);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
return evalOk((obj.value as any)[prop]);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
function evaluateObject(node: BabelTypes.ObjectExpression, scope: EvalScope): EvalResult {
|
|
286
|
+
const result: CompiledStyleObject = {};
|
|
287
|
+
const locations: CompiledStyleObjectLocations = {};
|
|
288
|
+
const props = node.properties;
|
|
289
|
+
|
|
290
|
+
let i = 0;
|
|
291
|
+
|
|
292
|
+
while (i < props.length) {
|
|
293
|
+
const prop = props[i];
|
|
294
|
+
|
|
295
|
+
if (prop.type === 'SpreadElement') {
|
|
296
|
+
const v = evaluateNode(prop.argument, scope);
|
|
297
|
+
if (!v.ok) return v;
|
|
298
|
+
|
|
299
|
+
if (v.value && typeof v.value === 'object') {
|
|
300
|
+
Object.assign(result, v.value);
|
|
301
|
+
|
|
302
|
+
const sourceLocations = (v.value as CompiledStyleObject)[COMPILED_STYLE_OBJECT_LOCATIONS];
|
|
303
|
+
if (sourceLocations) {
|
|
304
|
+
const trace = scope.sourcemapTrace === 'value'
|
|
305
|
+
? TRACE_VALUE
|
|
306
|
+
: TRACE_STYLE;
|
|
307
|
+
const spreadLoc = prop.loc?.start;
|
|
308
|
+
|
|
309
|
+
for (const [key, loc] of Object.entries(sourceLocations)) {
|
|
310
|
+
locations[key] = trace === TRACE_STYLE && spreadLoc
|
|
311
|
+
? {
|
|
312
|
+
line: spreadLoc.line,
|
|
313
|
+
column: spreadLoc.column + 1,
|
|
314
|
+
filePath: scope.styleFilePath ?? scope.filePath,
|
|
315
|
+
trace,
|
|
316
|
+
}
|
|
317
|
+
: {
|
|
318
|
+
...loc,
|
|
319
|
+
trace,
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
} else if (prop.type === 'ObjectProperty') {
|
|
325
|
+
let key: string;
|
|
326
|
+
|
|
327
|
+
if (prop.computed) {
|
|
328
|
+
const k = evaluateNode(prop.key as BabelTypes.Node, scope);
|
|
329
|
+
if (!k.ok) return k;
|
|
330
|
+
|
|
331
|
+
key = String(k.value);
|
|
332
|
+
} else {
|
|
333
|
+
key = prop.key.type === 'Identifier'
|
|
334
|
+
? prop.key.name
|
|
335
|
+
: (prop.key as BabelTypes.StringLiteral).value;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
const val = evaluateNode(prop.value as BabelTypes.Node, scope);
|
|
339
|
+
|
|
340
|
+
if (!val.ok && isRequiredStaticStyleValueFail(val.reason)) return val;
|
|
341
|
+
|
|
342
|
+
result[key] = val.ok
|
|
343
|
+
? val.value
|
|
344
|
+
: createCompiledRuntimeValue(prop.value as BabelTypes.Expression);
|
|
345
|
+
|
|
346
|
+
if (prop.loc?.start) {
|
|
347
|
+
locations[key] = {
|
|
348
|
+
line: prop.loc.start.line,
|
|
349
|
+
column: prop.loc.start.column + 1,
|
|
350
|
+
filePath: scope.styleFilePath ?? scope.filePath,
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
} else {
|
|
354
|
+
return evalFail(`Cannot evaluate ObjectMethod in style object`);
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
i++;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
if (Object.keys(locations).length) {
|
|
361
|
+
Object.defineProperty(result, COMPILED_STYLE_OBJECT_LOCATIONS, {
|
|
362
|
+
configurable: true,
|
|
363
|
+
enumerable: false,
|
|
364
|
+
value: locations,
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
return evalOk(result);
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
function evaluateArray(node: BabelTypes.ArrayExpression, scope: EvalScope): EvalResult {
|
|
372
|
+
const result: unknown[] = [];
|
|
373
|
+
const elements = node.elements;
|
|
374
|
+
|
|
375
|
+
let i = 0;
|
|
376
|
+
|
|
377
|
+
while (i < elements.length) {
|
|
378
|
+
const el = elements[i];
|
|
379
|
+
|
|
380
|
+
if (!el) {
|
|
381
|
+
result.push(undefined);
|
|
382
|
+
} else if (el.type === 'SpreadElement') {
|
|
383
|
+
const v = evaluateNode(el.argument, scope);
|
|
384
|
+
if (!v.ok) return v;
|
|
385
|
+
|
|
386
|
+
if (Array.isArray(v.value)) {
|
|
387
|
+
let j = 0;
|
|
388
|
+
while (j < (v.value as unknown[]).length) {
|
|
389
|
+
result.push((v.value as unknown[])[j]);
|
|
390
|
+
j++;
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
} else {
|
|
394
|
+
const v = evaluateNode(el as BabelTypes.Node, scope);
|
|
395
|
+
if (!v.ok) return v;
|
|
396
|
+
|
|
397
|
+
result.push(v.value);
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
i++;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
return evalOk(result);
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
function isRequiredStaticStyleValueFail(reason: string) {
|
|
407
|
+
return reason.includes('createCounterStyle') ||
|
|
408
|
+
reason.includes('createFontFace') ||
|
|
409
|
+
reason.includes('createFontPaletteValues') ||
|
|
410
|
+
reason.includes('createPositionTry') ||
|
|
411
|
+
reason.includes('createProperty') ||
|
|
412
|
+
reason.includes('fontSrc');
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
function evaluateCall(node: BabelTypes.CallExpression, scope: EvalScope): EvalResult {
|
|
416
|
+
if (node.callee.type === 'Identifier') {
|
|
417
|
+
const imp = scope.imports.get(node.callee.name);
|
|
418
|
+
|
|
419
|
+
if (imp && imp.source === IMPORT_EXTRACT && imp.name === FN_CREATE_EXTRACTED_STYLE) {
|
|
420
|
+
const items = evaluateNode(node.arguments[0] as BabelTypes.Node, scope);
|
|
421
|
+
if (!items.ok) return items;
|
|
422
|
+
if (!Array.isArray(items.value)) return evalFail('createExtractedStyle items must be an array');
|
|
423
|
+
|
|
424
|
+
return evalOk(createExtractedStyle(items.value as Parameters<typeof createExtractedStyle>[0]));
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
if (imp && imp.source === IMPORT_EXTRACT && imp.name === FN_GET_EXTRACTED_STYLE_ITEMS) {
|
|
428
|
+
const style = evaluateNode(node.arguments[0] as BabelTypes.Node, scope);
|
|
429
|
+
if (!style.ok) return style;
|
|
430
|
+
|
|
431
|
+
return evalOk(getExtractedStyleItems(style.value as Parameters<typeof getExtractedStyleItems>[0]));
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
if (imp && imp.source === IMPORT_EXTRACT && imp.name === FN_CREATE_EXTRACTED_STYLE_MERGE) {
|
|
435
|
+
const parts: Parameters<typeof createExtractedStyleMerge> = [];
|
|
436
|
+
for (const arg of node.arguments) {
|
|
437
|
+
const part = evaluateNode(arg as BabelTypes.Node, scope);
|
|
438
|
+
if (!part.ok) return part;
|
|
439
|
+
parts.push(part.value as Parameters<typeof createExtractedStyleMerge>[number]);
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
return evalOk(createExtractedStyleMerge(...parts));
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
if (imp && imp.source === IMPORT_EXTRACT && imp.name === FN_CREATE_EXTRACTED_SLOT) {
|
|
446
|
+
const slotId = evaluateNode(node.arguments[0] as BabelTypes.Node, scope);
|
|
447
|
+
if (!slotId.ok) return slotId;
|
|
448
|
+
|
|
449
|
+
const items = evaluateNode(node.arguments[1] as BabelTypes.Node, scope);
|
|
450
|
+
if (!items.ok) return items;
|
|
451
|
+
if (!Array.isArray(items.value)) return evalFail('createExtractedSlot items must be an array');
|
|
452
|
+
|
|
453
|
+
return evalOk(
|
|
454
|
+
createExtractedSlot(String(slotId.value), items.value as Parameters<typeof createExtractedSlot>[1]),
|
|
455
|
+
);
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
if (imp && imp.source === IMPORT_EXTRACT && imp.name === FN_CREATE_EXTRACTED_SCOPE) {
|
|
459
|
+
const items = evaluateNode(node.arguments[0] as BabelTypes.Node, scope);
|
|
460
|
+
if (!items.ok) return items;
|
|
461
|
+
if (!Array.isArray(items.value)) return evalFail('createExtractedScope items must be an array');
|
|
462
|
+
|
|
463
|
+
return evalOk(createExtractedScope(items.value as Parameters<typeof createExtractedScope>[0]));
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
if (imp && STYLE_IMPORT_PATHS.has(imp.source) && imp.name === FN_CREATE_TOKEN) {
|
|
467
|
+
const value = evaluateNode(node.arguments[0] as BabelTypes.Node, scope);
|
|
468
|
+
if (!value.ok) return value;
|
|
469
|
+
|
|
470
|
+
const debugId = evaluateOptionalDebugId(node.arguments[1] as BabelTypes.Node, scope);
|
|
471
|
+
if (!debugId.ok) return debugId;
|
|
472
|
+
|
|
473
|
+
return evalOk(createCompiledToken(value.value, scope, node.loc?.start, node, debugId.value));
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
if (imp && STYLE_IMPORT_PATHS.has(imp.source) && imp.name === FN_CREATE_KEYFRAMES) {
|
|
477
|
+
const frames = evaluateNode(node.arguments[0] as BabelTypes.Node, scope);
|
|
478
|
+
if (!frames.ok) return frames;
|
|
479
|
+
|
|
480
|
+
const stableId = evaluateOptionalStableId(node.arguments[1] as BabelTypes.Node, scope);
|
|
481
|
+
if (!stableId.ok) return stableId;
|
|
482
|
+
|
|
483
|
+
const stable = stableId.value ?? createCompiledAtRuleStableId(scope, node.loc?.start, frames.value);
|
|
484
|
+
const format = CSS_EXTRA_CONFIG.namedRuleFormat.keyframes ?? null;
|
|
485
|
+
return evalOk(createCompiledAtRuleRef({
|
|
486
|
+
value: formatKeyFramesName(format, stable.id, { name: stable.name }),
|
|
487
|
+
buildCss: (_name, tokens, tokenLookup, options) =>
|
|
488
|
+
buildKeyframesCss(
|
|
489
|
+
format,
|
|
490
|
+
stable.name,
|
|
491
|
+
stable.id,
|
|
492
|
+
frames.value as KeyframesObject,
|
|
493
|
+
tokens,
|
|
494
|
+
tokenLookup,
|
|
495
|
+
options,
|
|
496
|
+
),
|
|
497
|
+
}));
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
if (imp && STYLE_IMPORT_PATHS.has(imp.source) && imp.name === FN_CREATE_POSITION_TRY) {
|
|
501
|
+
return evaluateDebugNamedAtRuleCall(node, scope, {
|
|
502
|
+
label: 'createPositionTry',
|
|
503
|
+
format: CSS_EXTRA_CONFIG.namedRuleFormat.positionTry ?? null,
|
|
504
|
+
formatName: formatPositionTryName,
|
|
505
|
+
buildCss: buildPositionTryCss as NamedAtRuleCssBuilder,
|
|
506
|
+
});
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
if (imp && STYLE_IMPORT_PATHS.has(imp.source) && imp.name === FN_CREATE_COUNTER_STYLE) {
|
|
510
|
+
return evaluateDebugNamedAtRuleCall(node, scope, {
|
|
511
|
+
label: 'createCounterStyle',
|
|
512
|
+
format: CSS_EXTRA_CONFIG.namedRuleFormat.counterStyle ?? null,
|
|
513
|
+
formatName: formatCounterStyleName,
|
|
514
|
+
buildCss: buildCounterStyleCss as NamedAtRuleCssBuilder,
|
|
515
|
+
});
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
if (imp && STYLE_IMPORT_PATHS.has(imp.source) && imp.name === FN_CREATE_FONT_PALETTE_VALUES) {
|
|
519
|
+
return evaluateDebugNamedAtRuleCall(node, scope, {
|
|
520
|
+
label: 'createFontPaletteValues',
|
|
521
|
+
format: CSS_EXTRA_CONFIG.namedRuleFormat.fontPaletteValues ?? null,
|
|
522
|
+
formatName: formatFontPaletteValuesName,
|
|
523
|
+
buildCss: buildFontPaletteValuesCss as NamedAtRuleCssBuilder,
|
|
524
|
+
});
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
if (imp && STYLE_IMPORT_PATHS.has(imp.source) && imp.name === FN_CREATE_PROPERTY) {
|
|
528
|
+
const name = evaluateNode(node.arguments[0] as BabelTypes.Node, scope);
|
|
529
|
+
if (!name.ok) return evalFail(`createProperty name must be statically analyzable: ${name.reason}`);
|
|
530
|
+
if (typeof name.value !== 'string') return evalFail('createProperty name must be a static string');
|
|
531
|
+
|
|
532
|
+
const descriptors = evaluateNode(node.arguments[1] as BabelTypes.Node, scope);
|
|
533
|
+
if (!descriptors.ok) {
|
|
534
|
+
return evalFail(`createProperty descriptors must be statically analyzable: ${descriptors.reason}`);
|
|
535
|
+
}
|
|
536
|
+
if (!descriptors.value || typeof descriptors.value !== 'object') {
|
|
537
|
+
return evalFail('createProperty descriptors must be a static object');
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
const cssName = name.value as `--${string}`;
|
|
541
|
+
if (!cssName.startsWith('--')) return evalFail('createProperty name must be a custom property name');
|
|
542
|
+
const format = CSS_EXTRA_CONFIG.namedRuleFormat.property ?? null;
|
|
543
|
+
const formattedName = formatPropertyName(format, cssName, { name: cssName });
|
|
544
|
+
|
|
545
|
+
return evalOk(createCompiledAtRuleRef({
|
|
546
|
+
value: formattedName,
|
|
547
|
+
buildCss: (_atRuleName, tokens, tokenLookup, options) =>
|
|
548
|
+
buildPropertyCss(
|
|
549
|
+
format,
|
|
550
|
+
cssName,
|
|
551
|
+
cssName,
|
|
552
|
+
descriptors.value as PropertyObject,
|
|
553
|
+
tokens,
|
|
554
|
+
tokenLookup,
|
|
555
|
+
options,
|
|
556
|
+
),
|
|
557
|
+
}));
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
if (imp && STYLE_IMPORT_PATHS.has(imp.source) && imp.name === FN_CREATE_FONT_FACE) {
|
|
561
|
+
const descriptors = evaluateNode(node.arguments[0] as BabelTypes.Node, scope);
|
|
562
|
+
if (!descriptors.ok) {
|
|
563
|
+
return evalFail(`createFontFace descriptors must be statically analyzable: ${descriptors.reason}`);
|
|
564
|
+
}
|
|
565
|
+
if (!descriptors.value || typeof descriptors.value !== 'object') {
|
|
566
|
+
return evalFail('createFontFace descriptors must be a static object');
|
|
567
|
+
}
|
|
568
|
+
if (typeof (descriptors.value as { src?: unknown; }).src !== 'string') {
|
|
569
|
+
return evalFail('createFontFace src must be a static string');
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
const stableId = evaluateOptionalStableId(node.arguments[1] as BabelTypes.Node, scope);
|
|
573
|
+
if (!stableId.ok) return stableId;
|
|
574
|
+
|
|
575
|
+
const fontFaceDescriptors = descriptors.value as FontFaceObject;
|
|
576
|
+
if (typeof fontFaceDescriptors.src !== 'string') {
|
|
577
|
+
return evalFail('createFontFace src must be a static string');
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
const stable = stableId.value ?? createCompiledAtRuleStableId(scope, node.loc?.start, descriptors.value);
|
|
581
|
+
const format = CSS_EXTRA_CONFIG.namedRuleFormat.fontFace ?? null;
|
|
582
|
+
return evalOk(createCompiledAtRuleRef({
|
|
583
|
+
value: formatFontFaceName(format, stable.id, { name: stable.name }),
|
|
584
|
+
buildCss: (_name, tokens, tokenLookup, options) =>
|
|
585
|
+
buildFontFaceCss(format, stable.name, stable.id, fontFaceDescriptors, tokens, tokenLookup, options),
|
|
586
|
+
}));
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
if (imp && STYLE_IMPORT_PATHS.has(imp.source) && imp.name === FN_FONT_SRC) {
|
|
590
|
+
const url = evaluateNode(node.arguments[0] as BabelTypes.Node, scope);
|
|
591
|
+
if (!url.ok) return evalFail(`fontSrc url must be statically analyzable: ${url.reason}`);
|
|
592
|
+
if (typeof url.value !== 'string') return evalFail('fontSrc url must be a static string');
|
|
593
|
+
|
|
594
|
+
const format = evaluateOptionalDebugId(node.arguments[1] as BabelTypes.Node, scope);
|
|
595
|
+
if (!format.ok) return evalFail(`fontSrc format must be statically analyzable: ${format.reason}`);
|
|
596
|
+
|
|
597
|
+
return evalOk(fontSrc(url.value, format.value));
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
if (imp && STYLE_IMPORT_PATHS.has(imp.source) && imp.name === FN_CREATE_TOKENS) {
|
|
601
|
+
const value = evaluateNode(node.arguments[0] as BabelTypes.Node, scope);
|
|
602
|
+
if (!value.ok) return value;
|
|
603
|
+
|
|
604
|
+
const debugId = evaluateOptionalDebugId(node.arguments[1] as BabelTypes.Node, scope);
|
|
605
|
+
if (!debugId.ok) return debugId;
|
|
606
|
+
|
|
607
|
+
return evalOk(createCompiledTokens(value.value, scope, node.loc?.start, node, debugId.value));
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
if (imp && imp.source === STYLE_UTILS_IMPORT_PATH && imp.name === FN_EXPOSE_STYLE) {
|
|
611
|
+
const styles = evaluateNode(node.arguments[0] as BabelTypes.Node, scope);
|
|
612
|
+
if (!styles.ok) return styles;
|
|
613
|
+
if (!styles.value || typeof styles.value !== 'object') {
|
|
614
|
+
return evalFail('exposeStyle input must be a static object');
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
return evalOk(exposeStyle(styles.value as object));
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
if (imp && STYLE_IMPORT_PATHS.has(imp.source) && imp.name === FN_CREATE_VALUES) {
|
|
621
|
+
const hasNumberArg = node.arguments[0]?.type === 'Identifier' &&
|
|
622
|
+
(node.arguments[0] as BabelTypes.Identifier).name === 'Number';
|
|
623
|
+
|
|
624
|
+
const valuesNode = hasNumberArg ? node.arguments[1] : node.arguments[0];
|
|
625
|
+
const debugNode = hasNumberArg ? node.arguments[2] : node.arguments[1];
|
|
626
|
+
|
|
627
|
+
const values = evaluateNode(valuesNode as BabelTypes.Node, scope);
|
|
628
|
+
if (!values.ok) return values;
|
|
629
|
+
|
|
630
|
+
const debugId = evaluateOptionalDebugId(debugNode as BabelTypes.Node, scope);
|
|
631
|
+
if (!debugId.ok) return debugId;
|
|
632
|
+
|
|
633
|
+
if (!Array.isArray(values.value)) {
|
|
634
|
+
return evalFail('createValues values must be an array');
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
return evalOk(createCompiledValues(values.value, scope, node.loc?.start, node, debugId.value, hasNumberArg));
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
if (node.callee.type === 'Identifier') {
|
|
642
|
+
const token = evaluateIdentifier(node.callee, scope);
|
|
643
|
+
|
|
644
|
+
if (token.ok && isStyleTokenData(token.value)) {
|
|
645
|
+
const value = evaluateNode(node.arguments[0] as BabelTypes.Node, scope);
|
|
646
|
+
if (!value.ok) return value;
|
|
647
|
+
|
|
648
|
+
return evalOk(createCompiledTokenOverride(token.value, value.value, node));
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
if (token.ok && isCompiledTokenFactory(token.value)) {
|
|
652
|
+
const value = evaluateNode(node.arguments[0] as BabelTypes.Node, scope);
|
|
653
|
+
if (!value.ok) return value;
|
|
654
|
+
|
|
655
|
+
const target = token.value.tokens.get(value.value);
|
|
656
|
+
if (!target) return evalFail(`createValues value not found: ${String(value.value)}`);
|
|
657
|
+
|
|
658
|
+
if (node.arguments.length > 1) {
|
|
659
|
+
const provide = evaluateNode(node.arguments[1] as BabelTypes.Node, scope);
|
|
660
|
+
if (!provide.ok) return provide;
|
|
661
|
+
|
|
662
|
+
return evalOk(createCompiledTokenOverride(target, provide.value, node));
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
return evalOk(withRuntimeValue(node, target));
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
if (node.callee.type === 'MemberExpression') {
|
|
670
|
+
const token = evaluateMember(node.callee, scope);
|
|
671
|
+
|
|
672
|
+
if (token.ok && isStyleTokenData(token.value)) {
|
|
673
|
+
const value = evaluateNode(node.arguments[0] as BabelTypes.Node, scope);
|
|
674
|
+
if (!value.ok) return value;
|
|
675
|
+
|
|
676
|
+
return evalOk(createCompiledTokenOverride(token.value, value.value, node));
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
if (
|
|
681
|
+
node.callee.type === 'MemberExpression' &&
|
|
682
|
+
!node.callee.computed &&
|
|
683
|
+
node.callee.property.type === 'Identifier' &&
|
|
684
|
+
node.callee.property.name === FN_STYLE_KEYFRAMES &&
|
|
685
|
+
node.callee.object.type === 'Identifier' &&
|
|
686
|
+
scope.styleNames?.has(node.callee.object.name)
|
|
687
|
+
) {
|
|
688
|
+
const frames = evaluateNode(node.arguments[0] as BabelTypes.Node, scope);
|
|
689
|
+
if (!frames.ok) return frames;
|
|
690
|
+
|
|
691
|
+
const stableId = evaluateOptionalStableId(node.arguments[1] as BabelTypes.Node, scope);
|
|
692
|
+
if (!stableId.ok) return stableId;
|
|
693
|
+
|
|
694
|
+
const stable = stableId.value ?? createCompiledAtRuleStableId(scope, node.loc?.start, frames.value);
|
|
695
|
+
const meta = scope.styleMetas?.get(node.callee.object.name);
|
|
696
|
+
const transformedFrames = transformKeyframes(
|
|
697
|
+
frames.value as KeyframesObject,
|
|
698
|
+
meta?.transform ?? scope.styleTransform ?? null,
|
|
699
|
+
);
|
|
700
|
+
const format = CSS_EXTRA_CONFIG.namedRuleFormat.keyframes ?? null;
|
|
701
|
+
|
|
702
|
+
return evalOk(createCompiledAtRuleRef({
|
|
703
|
+
value: formatKeyFramesName(format, stable.id, { name: stable.name }),
|
|
704
|
+
buildCss: (_name, tokens, tokenLookup, options) =>
|
|
705
|
+
buildKeyframesCss(format, stable.name, stable.id, transformedFrames, tokens, tokenLookup, options),
|
|
706
|
+
}));
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
if (
|
|
710
|
+
node.callee.type === 'MemberExpression' &&
|
|
711
|
+
!node.callee.computed &&
|
|
712
|
+
node.callee.property.type === 'Identifier' &&
|
|
713
|
+
node.callee.property.name === FN_STYLE_VALUE &&
|
|
714
|
+
node.callee.object.type === 'Identifier' &&
|
|
715
|
+
scope.styleNames?.has(node.callee.object.name)
|
|
716
|
+
) {
|
|
717
|
+
const value = evaluateNode(node.arguments[0] as BabelTypes.Node, scope);
|
|
718
|
+
if (!value.ok) return value;
|
|
719
|
+
|
|
720
|
+
const weight = evaluateNode(node.arguments[1] as BabelTypes.Node, scope);
|
|
721
|
+
if (!weight.ok) return weight;
|
|
722
|
+
|
|
723
|
+
if (typeof weight.value !== 'number') {
|
|
724
|
+
return evalFail('style.value weight must be a number');
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
return evalOk([weight.value, value.value]);
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
if (
|
|
731
|
+
node.callee.type === 'MemberExpression' &&
|
|
732
|
+
!node.callee.computed &&
|
|
733
|
+
node.callee.property.type === 'Identifier' &&
|
|
734
|
+
(node.callee.property.name === FN_STYLE_RAW || node.callee.property.name === FN_STYLE_PLAIN) &&
|
|
735
|
+
node.callee.object.type === 'Identifier' &&
|
|
736
|
+
scope.styleNames?.has(node.callee.object.name)
|
|
737
|
+
) {
|
|
738
|
+
return evaluateNode(node.arguments[0] as BabelTypes.Node, scope);
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
return evalFail(`Cannot statically evaluate: ${node.type}`);
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
type NamedAtRuleCssBuilder = (
|
|
745
|
+
format: NamedAtRuleFormat | null,
|
|
746
|
+
name: string | null,
|
|
747
|
+
id: string,
|
|
748
|
+
descriptors: object,
|
|
749
|
+
tokens: StyleTokenData[],
|
|
750
|
+
tokenLookup: Set<string>,
|
|
751
|
+
tokenNameFormat: TokenNameFormat | null,
|
|
752
|
+
) => BuiltAtRuleCss;
|
|
753
|
+
|
|
754
|
+
type NamedAtRuleNameFormatter = (
|
|
755
|
+
format: NamedAtRuleFormat | null,
|
|
756
|
+
hash: string,
|
|
757
|
+
info: { name: string | null; },
|
|
758
|
+
) => string;
|
|
759
|
+
|
|
760
|
+
type BuiltAtRuleCss = {
|
|
761
|
+
name: string;
|
|
762
|
+
css: string;
|
|
763
|
+
};
|
|
764
|
+
|
|
765
|
+
type NamedAtRuleConfig = {
|
|
766
|
+
label: string;
|
|
767
|
+
format: NamedAtRuleFormat | null;
|
|
768
|
+
formatName: NamedAtRuleNameFormatter;
|
|
769
|
+
buildCss: NamedAtRuleCssBuilder;
|
|
770
|
+
};
|
|
771
|
+
|
|
772
|
+
function evaluateDebugNamedAtRuleCall(
|
|
773
|
+
node: BabelTypes.CallExpression,
|
|
774
|
+
scope: EvalScope,
|
|
775
|
+
config: NamedAtRuleConfig,
|
|
776
|
+
): EvalResult {
|
|
777
|
+
const descriptors = evaluateNode(node.arguments[0] as BabelTypes.Node, scope);
|
|
778
|
+
|
|
779
|
+
if (!descriptors.ok) {
|
|
780
|
+
return evalFail(`${config.label} descriptors must be statically analyzable: ${descriptors.reason}`);
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
if (!descriptors.value || typeof descriptors.value !== 'object') {
|
|
784
|
+
return evalFail(`${config.label} descriptors must be a static object`);
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
const stableId = evaluateOptionalStableId(node.arguments[1] as BabelTypes.Node, scope);
|
|
788
|
+
|
|
789
|
+
if (!stableId.ok) {
|
|
790
|
+
return evalFail(`${config.label} stableId must be statically analyzable: ${stableId.reason}`);
|
|
791
|
+
}
|
|
792
|
+
|
|
793
|
+
const stable = stableId.value ?? createCompiledAtRuleStableId(scope, node.loc?.start, descriptors.value);
|
|
794
|
+
const name = config.formatName(config.format, stable.id, { name: stable.name });
|
|
795
|
+
|
|
796
|
+
try {
|
|
797
|
+
return evalOk(createCompiledAtRuleRef({
|
|
798
|
+
value: name,
|
|
799
|
+
buildCss: (_atRuleName, tokens, tokenLookup, options) =>
|
|
800
|
+
config.buildCss(
|
|
801
|
+
config.format,
|
|
802
|
+
stable.name,
|
|
803
|
+
stable.id,
|
|
804
|
+
descriptors.value as object,
|
|
805
|
+
tokens,
|
|
806
|
+
tokenLookup,
|
|
807
|
+
options,
|
|
808
|
+
),
|
|
809
|
+
}));
|
|
810
|
+
} catch (error) {
|
|
811
|
+
return evalFail(error instanceof Error ? error.message : String(error));
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
|
|
815
|
+
function createCompiledAtRuleRef(config: {
|
|
816
|
+
value: string;
|
|
817
|
+
buildCss: (
|
|
818
|
+
name: string,
|
|
819
|
+
tokens: StyleTokenData[],
|
|
820
|
+
tokenLookup: Set<string>,
|
|
821
|
+
tokenNameFormat: TokenNameFormat | null,
|
|
822
|
+
) => BuiltAtRuleCss;
|
|
823
|
+
}): AtRuleRef {
|
|
824
|
+
const tokens: StyleTokenData[] = [];
|
|
825
|
+
const tokenLookup = new Set<string>();
|
|
826
|
+
|
|
827
|
+
const css = config.buildCss(
|
|
828
|
+
config.value,
|
|
829
|
+
tokens,
|
|
830
|
+
tokenLookup,
|
|
831
|
+
CSS_CONFIG.tokenNameFormat || null,
|
|
832
|
+
);
|
|
833
|
+
|
|
834
|
+
return createAtRuleRef({
|
|
835
|
+
key: css.name,
|
|
836
|
+
value: css.name,
|
|
837
|
+
css: css.css,
|
|
838
|
+
tokens: tokens.length ? tokens : undefined,
|
|
839
|
+
});
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
function createCompiledTokenOverride(
|
|
843
|
+
token: StyleTokenData,
|
|
844
|
+
value: unknown,
|
|
845
|
+
runtimeValue: BabelTypes.Expression,
|
|
846
|
+
): StyleTokenOverride {
|
|
847
|
+
if (isStyleTokenData(value)) {
|
|
848
|
+
return withRuntimeValue(runtimeValue, {
|
|
849
|
+
[TOKEN_ID]: getStyleTokenId(token),
|
|
850
|
+
[TOKEN_OVERRIDE]: true,
|
|
851
|
+
value: value.value,
|
|
852
|
+
ref: value,
|
|
853
|
+
});
|
|
854
|
+
}
|
|
855
|
+
|
|
856
|
+
return withRuntimeValue(runtimeValue, {
|
|
857
|
+
[TOKEN_ID]: getStyleTokenId(token),
|
|
858
|
+
[TOKEN_OVERRIDE]: true,
|
|
859
|
+
value,
|
|
860
|
+
ref: null,
|
|
861
|
+
});
|
|
862
|
+
}
|
|
863
|
+
|
|
864
|
+
function createCompiledToken(
|
|
865
|
+
value: unknown,
|
|
866
|
+
scope: EvalScope,
|
|
867
|
+
loc: { line: number; column: number; } | null | undefined,
|
|
868
|
+
runtimeValue: BabelTypes.Expression,
|
|
869
|
+
debugId?: string,
|
|
870
|
+
): StyleTokenData {
|
|
871
|
+
let tokenId = debugId;
|
|
872
|
+
|
|
873
|
+
if (!tokenId) {
|
|
874
|
+
const hash = (scope.styleFilePath ?? scope.filePath) + '\n' +
|
|
875
|
+
(loc ? loc.line + ':' + loc.column : String(value));
|
|
876
|
+
|
|
877
|
+
tokenId = hashString(hash);
|
|
878
|
+
}
|
|
879
|
+
|
|
880
|
+
return withRuntimeValue(runtimeValue, {
|
|
881
|
+
[TOKEN_ID]: tokenId,
|
|
882
|
+
value,
|
|
883
|
+
ref: null,
|
|
884
|
+
});
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
function createCompiledTokens(
|
|
888
|
+
value: unknown,
|
|
889
|
+
scope: EvalScope,
|
|
890
|
+
loc: { line: number; column: number; } | null | undefined,
|
|
891
|
+
runtimeValue: BabelTypes.Expression,
|
|
892
|
+
debugId?: string,
|
|
893
|
+
) {
|
|
894
|
+
const tokenGroupId = debugId ?? createCompiledTokenGroupId(scope, loc);
|
|
895
|
+
|
|
896
|
+
if (Array.isArray(value)) {
|
|
897
|
+
const result: Record<PropertyKey, unknown> = {};
|
|
898
|
+
|
|
899
|
+
for (let i = 0, len = value.length; i < len; i++) {
|
|
900
|
+
const item = value[i];
|
|
901
|
+
|
|
902
|
+
result[item as PropertyKey] = createCompiledToken(
|
|
903
|
+
item,
|
|
904
|
+
scope,
|
|
905
|
+
loc,
|
|
906
|
+
runtimeValue,
|
|
907
|
+
getChildDebugId(tokenGroupId, String(i)),
|
|
908
|
+
);
|
|
909
|
+
}
|
|
910
|
+
|
|
911
|
+
return result;
|
|
912
|
+
}
|
|
913
|
+
|
|
914
|
+
if (!value || typeof value !== 'object') {
|
|
915
|
+
return {};
|
|
916
|
+
}
|
|
917
|
+
|
|
918
|
+
const result: Record<PropertyKey, unknown> = {};
|
|
919
|
+
|
|
920
|
+
assignCompiledTokenRecord(
|
|
921
|
+
result,
|
|
922
|
+
value as Record<PropertyKey, unknown>,
|
|
923
|
+
scope,
|
|
924
|
+
loc,
|
|
925
|
+
runtimeValue,
|
|
926
|
+
tokenGroupId,
|
|
927
|
+
);
|
|
928
|
+
|
|
929
|
+
return result;
|
|
930
|
+
}
|
|
931
|
+
|
|
932
|
+
function createCompiledTokenGroupId(
|
|
933
|
+
scope: EvalScope,
|
|
934
|
+
loc: { line: number; column: number; } | null | undefined,
|
|
935
|
+
) {
|
|
936
|
+
const hash = (scope.styleFilePath ?? scope.filePath) + '\n' +
|
|
937
|
+
(loc ? loc.line + ':' + loc.column : 'createTokens');
|
|
938
|
+
|
|
939
|
+
return hashString(hash);
|
|
940
|
+
}
|
|
941
|
+
|
|
942
|
+
function createCompiledAtRuleStableId(
|
|
943
|
+
scope: EvalScope,
|
|
944
|
+
loc: { line: number; column: number; } | null | undefined,
|
|
945
|
+
value: unknown,
|
|
946
|
+
): StableId {
|
|
947
|
+
return {
|
|
948
|
+
name: null,
|
|
949
|
+
id: (scope.styleFilePath ?? scope.filePath) + '\n' +
|
|
950
|
+
(loc ? loc.line + ':' + loc.column : String(value)),
|
|
951
|
+
};
|
|
952
|
+
}
|
|
953
|
+
|
|
954
|
+
function assignCompiledTokenRecord(
|
|
955
|
+
target: Record<PropertyKey, unknown>,
|
|
956
|
+
value: Record<PropertyKey, unknown>,
|
|
957
|
+
scope: EvalScope,
|
|
958
|
+
loc: { line: number; column: number; } | null | undefined,
|
|
959
|
+
runtimeValue: BabelTypes.Expression,
|
|
960
|
+
debugId?: string,
|
|
961
|
+
) {
|
|
962
|
+
for (const key of Object.keys(value)) {
|
|
963
|
+
const item = value[key];
|
|
964
|
+
const itemDebugId = getChildDebugId(debugId, key);
|
|
965
|
+
|
|
966
|
+
if (item && typeof item === 'object' && !Array.isArray(item) && !isStyleTokenData(item)) {
|
|
967
|
+
const child: Record<PropertyKey, unknown> = {};
|
|
968
|
+
|
|
969
|
+
target[key] = child;
|
|
970
|
+
|
|
971
|
+
assignCompiledTokenRecord(
|
|
972
|
+
child,
|
|
973
|
+
item as Record<PropertyKey, unknown>,
|
|
974
|
+
scope,
|
|
975
|
+
loc,
|
|
976
|
+
runtimeValue,
|
|
977
|
+
itemDebugId,
|
|
978
|
+
);
|
|
979
|
+
} else {
|
|
980
|
+
target[key] = createCompiledToken(
|
|
981
|
+
item,
|
|
982
|
+
scope,
|
|
983
|
+
loc,
|
|
984
|
+
runtimeValue,
|
|
985
|
+
itemDebugId,
|
|
986
|
+
);
|
|
987
|
+
}
|
|
988
|
+
}
|
|
989
|
+
}
|
|
990
|
+
|
|
991
|
+
function createCompiledValues(
|
|
992
|
+
values: unknown[],
|
|
993
|
+
scope: EvalScope,
|
|
994
|
+
loc: { line: number; column: number; } | null | undefined,
|
|
995
|
+
runtimeValue: BabelTypes.Expression,
|
|
996
|
+
debugId: string | undefined,
|
|
997
|
+
isNumber: boolean,
|
|
998
|
+
): CompiledTokenFactory {
|
|
999
|
+
const tokens = new Map<unknown, StyleTokenData>();
|
|
1000
|
+
|
|
1001
|
+
for (let i = 0, len = values.length; i < len; i++) {
|
|
1002
|
+
const value = values[i];
|
|
1003
|
+
|
|
1004
|
+
tokens.set(
|
|
1005
|
+
value,
|
|
1006
|
+
createCompiledToken(
|
|
1007
|
+
parseCompiledValue(value, isNumber),
|
|
1008
|
+
scope,
|
|
1009
|
+
loc,
|
|
1010
|
+
runtimeValue,
|
|
1011
|
+
getChildDebugId(debugId, hashString(String(value))),
|
|
1012
|
+
),
|
|
1013
|
+
);
|
|
1014
|
+
}
|
|
1015
|
+
|
|
1016
|
+
return { [COMPILED_TOKEN_FACTORY]: true, tokens };
|
|
1017
|
+
}
|
|
1018
|
+
|
|
1019
|
+
function parseCompiledValue(value: unknown, isNumber: boolean) {
|
|
1020
|
+
if (!isNumber) return value;
|
|
1021
|
+
|
|
1022
|
+
const number = Number(value);
|
|
1023
|
+
if (!Number.isFinite(number)) return value;
|
|
1024
|
+
|
|
1025
|
+
return number;
|
|
1026
|
+
}
|
|
1027
|
+
|
|
1028
|
+
function isCompiledTokenFactory(value: unknown): value is CompiledTokenFactory {
|
|
1029
|
+
return !!value && typeof value === 'object' && (value as CompiledTokenFactory)[COMPILED_TOKEN_FACTORY] === true;
|
|
1030
|
+
}
|
|
1031
|
+
|
|
1032
|
+
function evaluateOptionalDebugId(
|
|
1033
|
+
node: BabelTypes.Node | null | undefined,
|
|
1034
|
+
scope: EvalScope,
|
|
1035
|
+
): EvalResult & { value?: string; } {
|
|
1036
|
+
if (!node) return evalOk(undefined) as EvalResult & { value?: string; };
|
|
1037
|
+
|
|
1038
|
+
const value = evaluateNode(node, scope);
|
|
1039
|
+
if (!value.ok) return value;
|
|
1040
|
+
|
|
1041
|
+
return evalOk(value.value === undefined ? undefined : String(value.value)) as EvalResult & { value?: string; };
|
|
1042
|
+
}
|
|
1043
|
+
|
|
1044
|
+
function evaluateOptionalStableId(
|
|
1045
|
+
node: BabelTypes.Node | null | undefined,
|
|
1046
|
+
scope: EvalScope,
|
|
1047
|
+
): EvalResult & { value?: StableId; } {
|
|
1048
|
+
if (!node) return evalOk(undefined) as EvalResult & { value?: StableId; };
|
|
1049
|
+
|
|
1050
|
+
const value = evaluateNode(node, scope);
|
|
1051
|
+
if (!value.ok) return value;
|
|
1052
|
+
if (value.value === undefined) return evalOk(undefined) as EvalResult & { value?: StableId; };
|
|
1053
|
+
|
|
1054
|
+
if (typeof value.value === 'string') {
|
|
1055
|
+
return evalOk({ name: value.value, id: value.value }) as EvalResult & { value?: StableId; };
|
|
1056
|
+
}
|
|
1057
|
+
|
|
1058
|
+
if (!value.value || typeof value.value !== 'object') {
|
|
1059
|
+
return evalFail('stableId must be a string or { name, id } object') as EvalResult & { value?: StableId; };
|
|
1060
|
+
}
|
|
1061
|
+
|
|
1062
|
+
const stableId = value.value as { name?: unknown; id?: unknown; };
|
|
1063
|
+
if (stableId.name !== null && stableId.name !== undefined && typeof stableId.name !== 'string') {
|
|
1064
|
+
return evalFail('stableId.name must be a string, null, or undefined') as EvalResult & { value?: StableId; };
|
|
1065
|
+
}
|
|
1066
|
+
if (typeof stableId.id !== 'string') {
|
|
1067
|
+
return evalFail('stableId.id must be a string') as EvalResult & { value?: StableId; };
|
|
1068
|
+
}
|
|
1069
|
+
|
|
1070
|
+
return evalOk({
|
|
1071
|
+
name: stableId.name ?? null,
|
|
1072
|
+
id: stableId.id,
|
|
1073
|
+
}) as EvalResult & { value?: StableId; };
|
|
1074
|
+
}
|
|
1075
|
+
|
|
1076
|
+
function getChildDebugId(
|
|
1077
|
+
debugId: string | undefined,
|
|
1078
|
+
child: string,
|
|
1079
|
+
) {
|
|
1080
|
+
return debugId ? debugId + '--' + child : undefined;
|
|
1081
|
+
}
|
|
1082
|
+
|
|
1083
|
+
function withRuntimeValue<T extends StyleTokenData | StyleTokenOverride>(
|
|
1084
|
+
runtimeValue: BabelTypes.Expression,
|
|
1085
|
+
token: T,
|
|
1086
|
+
): T {
|
|
1087
|
+
return Object.assign({}, token, {
|
|
1088
|
+
[TOKEN_ID]: token[TOKEN_ID],
|
|
1089
|
+
[COMPILED_RUNTIME_VALUE]: runtimeValue,
|
|
1090
|
+
});
|
|
1091
|
+
}
|
|
1092
|
+
|
|
1093
|
+
function createCompiledRuntimeValue(
|
|
1094
|
+
runtimeValue: BabelTypes.Expression,
|
|
1095
|
+
): CompiledRuntimeValue {
|
|
1096
|
+
return {
|
|
1097
|
+
[COMPILED_RUNTIME_VALUE]: runtimeValue,
|
|
1098
|
+
};
|
|
1099
|
+
}
|
|
1100
|
+
|
|
1101
|
+
function evaluateBinary(node: BabelTypes.BinaryExpression, scope: EvalScope): EvalResult {
|
|
1102
|
+
const left = evaluateNode(node.left as BabelTypes.Node, scope);
|
|
1103
|
+
if (!left.ok) return left;
|
|
1104
|
+
|
|
1105
|
+
const right = evaluateNode(node.right as BabelTypes.Node, scope);
|
|
1106
|
+
if (!right.ok) return right;
|
|
1107
|
+
|
|
1108
|
+
switch (node.operator) {
|
|
1109
|
+
case '+':
|
|
1110
|
+
return evalOk((left.value as any) + (right.value as any));
|
|
1111
|
+
case '-':
|
|
1112
|
+
return evalOk((left.value as number) - (right.value as number));
|
|
1113
|
+
case '*':
|
|
1114
|
+
return evalOk((left.value as number) * (right.value as number));
|
|
1115
|
+
case '/':
|
|
1116
|
+
return evalOk((left.value as number) / (right.value as number));
|
|
1117
|
+
case '%':
|
|
1118
|
+
return evalOk((left.value as number) % (right.value as number));
|
|
1119
|
+
default:
|
|
1120
|
+
return evalFail(`Unsupported binary operator: ${node.operator}`);
|
|
1121
|
+
}
|
|
1122
|
+
}
|
|
1123
|
+
|
|
1124
|
+
function evaluateUnary(node: BabelTypes.UnaryExpression, scope: EvalScope): EvalResult {
|
|
1125
|
+
const arg = evaluateNode(node.argument, scope);
|
|
1126
|
+
if (!arg.ok) return arg;
|
|
1127
|
+
|
|
1128
|
+
switch (node.operator) {
|
|
1129
|
+
case '-':
|
|
1130
|
+
return evalOk(-(arg.value as number));
|
|
1131
|
+
case '+':
|
|
1132
|
+
return evalOk(+(arg.value as number));
|
|
1133
|
+
case '!':
|
|
1134
|
+
return evalOk(!arg.value);
|
|
1135
|
+
default:
|
|
1136
|
+
return evalFail(`Unsupported unary operator: ${node.operator}`);
|
|
1137
|
+
}
|
|
1138
|
+
}
|