@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,132 @@
|
|
|
1
|
+
import {
|
|
2
|
+
FN_BIND_SCOPE,
|
|
3
|
+
FN_COMBINE_SCOPE,
|
|
4
|
+
FN_COMBINE_STYLE,
|
|
5
|
+
FN_CREATE_THEME,
|
|
6
|
+
FN_GET_CLASS_NAME,
|
|
7
|
+
FN_GET_TOKEN,
|
|
8
|
+
IMPORT_PATHS,
|
|
9
|
+
STYLE_IMPORT_PATH,
|
|
10
|
+
} from '../../../utils/constants';
|
|
11
|
+
import { getStyleExtractRuntimeImportPath } from '../../../utils/imports';
|
|
12
|
+
import { getImportedName } from '../../syntax';
|
|
13
|
+
import type { BabelTypes, NodePath } from '../../utils/babel';
|
|
14
|
+
import type { ExtractPluginState } from './state';
|
|
15
|
+
|
|
16
|
+
const EXTRACT_RUNTIME_IMPORT_NAMES = new Set([
|
|
17
|
+
FN_BIND_SCOPE,
|
|
18
|
+
FN_COMBINE_SCOPE,
|
|
19
|
+
FN_COMBINE_STYLE,
|
|
20
|
+
FN_GET_CLASS_NAME,
|
|
21
|
+
FN_GET_TOKEN,
|
|
22
|
+
]);
|
|
23
|
+
|
|
24
|
+
export function pruneUnusedStyleImports(
|
|
25
|
+
path: NodePath<BabelTypes.Program>,
|
|
26
|
+
state: ExtractPluginState,
|
|
27
|
+
) {
|
|
28
|
+
const usedBindings = new Set<unknown>();
|
|
29
|
+
|
|
30
|
+
path.traverse({
|
|
31
|
+
Identifier(idPath: NodePath<BabelTypes.Identifier>) {
|
|
32
|
+
if (!idPath.isReferencedIdentifier()) return;
|
|
33
|
+
|
|
34
|
+
const binding = idPath.scope.getBinding(idPath.node.name);
|
|
35
|
+
if (binding) {
|
|
36
|
+
usedBindings.add(binding);
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
const body = path.get('body');
|
|
42
|
+
let i = 0;
|
|
43
|
+
|
|
44
|
+
while (i < body.length) {
|
|
45
|
+
const stmt = body[i];
|
|
46
|
+
|
|
47
|
+
if (!stmt.isImportDeclaration()) {
|
|
48
|
+
i++;
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const importDecl = stmt.node;
|
|
53
|
+
const sourceName = importDecl.source.value;
|
|
54
|
+
if (typeof sourceName !== 'string') {
|
|
55
|
+
i++;
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (!importDecl.specifiers.length) {
|
|
60
|
+
i++;
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const keptSpecifiers = importDecl.specifiers.filter((spec) => {
|
|
65
|
+
if (spec.type === 'ImportSpecifier') {
|
|
66
|
+
const imported = getImportedName(spec);
|
|
67
|
+
|
|
68
|
+
if (
|
|
69
|
+
!state.importSourceMatcher({ source: sourceName, name: imported }) &&
|
|
70
|
+
!isCompilerHandledImport(sourceName, imported)
|
|
71
|
+
) return true;
|
|
72
|
+
|
|
73
|
+
const binding = stmt.scope.getBinding(spec.local.name);
|
|
74
|
+
if (!binding) return false;
|
|
75
|
+
|
|
76
|
+
return usedBindings.has(binding);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (spec.type === 'ImportDefaultSpecifier') {
|
|
80
|
+
if (
|
|
81
|
+
!state.importSourceMatcher({ source: sourceName, name: 'default' }) &&
|
|
82
|
+
!isCompilerHandledImport(sourceName, 'default')
|
|
83
|
+
) return true;
|
|
84
|
+
|
|
85
|
+
const binding = stmt.scope.getBinding(spec.local.name);
|
|
86
|
+
if (!binding) return false;
|
|
87
|
+
|
|
88
|
+
return usedBindings.has(binding);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (spec.type === 'ImportNamespaceSpecifier') {
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return true;
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
if (!keptSpecifiers.length) {
|
|
99
|
+
stmt.remove();
|
|
100
|
+
i++;
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (keptSpecifiers.length !== importDecl.specifiers.length) {
|
|
105
|
+
importDecl.specifiers = keptSpecifiers;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (
|
|
109
|
+
sourceName === STYLE_IMPORT_PATH &&
|
|
110
|
+
keptSpecifiers.every(isExtractRuntimeImportSpecifier)
|
|
111
|
+
) {
|
|
112
|
+
importDecl.source.value = getStyleExtractRuntimeImportPath(state.runtimeMode);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
i++;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function isExtractRuntimeImportSpecifier(spec: BabelTypes.ImportDeclaration['specifiers'][number]) {
|
|
120
|
+
if (spec.type !== 'ImportSpecifier') return false;
|
|
121
|
+
|
|
122
|
+
const imported = getImportedName(spec);
|
|
123
|
+
|
|
124
|
+
return EXTRACT_RUNTIME_IMPORT_NAMES.has(imported);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function isCompilerHandledImport(
|
|
128
|
+
source: string,
|
|
129
|
+
name: string,
|
|
130
|
+
) {
|
|
131
|
+
return IMPORT_PATHS.includes(source) && name === FN_CREATE_THEME;
|
|
132
|
+
}
|
|
@@ -0,0 +1,349 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BUILDER_TYPE_SCOPE,
|
|
3
|
+
BUILDER_TYPE_SLOT,
|
|
4
|
+
BUILDER_TYPE_SLOT_OVERRIDE,
|
|
5
|
+
BUILDER_TYPE_STYLE,
|
|
6
|
+
ITEM_VALUE_NUMBER_PX,
|
|
7
|
+
ITEM_VALUE_TYPE_AT_RULE_REF,
|
|
8
|
+
ITEM_VALUE_TYPE_VARIABLE,
|
|
9
|
+
} from '../../../../builder/data/const';
|
|
10
|
+
import type { BuilderType, ExtractedItemValue } from '../../../../builder/data/state';
|
|
11
|
+
import { getStyleTokenId, isStyleTokenData, type StyleTokenData } from '../../../../style/token';
|
|
12
|
+
import type { AtRuleRefData } from '../../../../style/valueRef';
|
|
13
|
+
import {
|
|
14
|
+
FN_CREATE_EXTRACTED_SCOPE,
|
|
15
|
+
FN_CREATE_EXTRACTED_SLOT,
|
|
16
|
+
FN_CREATE_EXTRACTED_STYLE,
|
|
17
|
+
FN_CREATE_EXTRACTED_STYLE_MERGE,
|
|
18
|
+
FN_CREATE_EXTRACTED_TOKEN,
|
|
19
|
+
} from '../../../utils/constants';
|
|
20
|
+
import type { BabelTypes } from '../../utils/babel';
|
|
21
|
+
import type {
|
|
22
|
+
CompiledChainData,
|
|
23
|
+
CompiledCssItem,
|
|
24
|
+
CompiledItem,
|
|
25
|
+
CompiledStyleSpreadItem,
|
|
26
|
+
CompiledTokenItem,
|
|
27
|
+
} from '../chain';
|
|
28
|
+
import type { ExtractPluginState } from './state';
|
|
29
|
+
|
|
30
|
+
type BuildReplacementOptions = {
|
|
31
|
+
getRuntimeToken?: (item: CompiledCssItem, valueNode: BabelTypes.Expression) => BabelTypes.Expression | null;
|
|
32
|
+
getTokenOverride?: (item: CompiledTokenItem) => void;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export function buildReplacement(
|
|
36
|
+
t: typeof BabelTypes,
|
|
37
|
+
chain: CompiledChainData,
|
|
38
|
+
state: ExtractPluginState,
|
|
39
|
+
options: BuildReplacementOptions = {},
|
|
40
|
+
): BabelTypes.Expression | null {
|
|
41
|
+
if (chain.type === 'style') {
|
|
42
|
+
const hasSpread = chain.items.some(isCompiledStyleSpreadItem);
|
|
43
|
+
state.usedHelpers.add(hasSpread ? FN_CREATE_EXTRACTED_STYLE_MERGE : FN_CREATE_EXTRACTED_STYLE);
|
|
44
|
+
|
|
45
|
+
return t.callExpression(
|
|
46
|
+
t.identifier(hasSpread ? FN_CREATE_EXTRACTED_STYLE_MERGE : FN_CREATE_EXTRACTED_STYLE),
|
|
47
|
+
hasSpread
|
|
48
|
+
? buildStyleMergeArgs(t, chain, state, options)
|
|
49
|
+
: [buildItemsArray(t, chain, BUILDER_TYPE_STYLE, state, options)],
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (chain.type === 'slot') {
|
|
54
|
+
state.usedHelpers.add(FN_CREATE_EXTRACTED_SLOT);
|
|
55
|
+
|
|
56
|
+
return t.callExpression(
|
|
57
|
+
t.identifier(FN_CREATE_EXTRACTED_SLOT),
|
|
58
|
+
[
|
|
59
|
+
t.stringLiteral(chain.slotId!),
|
|
60
|
+
buildItemsArray(t, chain, BUILDER_TYPE_SLOT, state, options),
|
|
61
|
+
],
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (chain.type === 'scope') {
|
|
66
|
+
state.usedHelpers.add(FN_CREATE_EXTRACTED_SCOPE);
|
|
67
|
+
|
|
68
|
+
return t.callExpression(
|
|
69
|
+
t.identifier(FN_CREATE_EXTRACTED_SCOPE),
|
|
70
|
+
[buildItemsArray(t, chain, BUILDER_TYPE_SCOPE, state, options)],
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function buildStyleMergeArgs(
|
|
78
|
+
t: typeof BabelTypes,
|
|
79
|
+
chain: CompiledChainData,
|
|
80
|
+
state: ExtractPluginState,
|
|
81
|
+
options: BuildReplacementOptions,
|
|
82
|
+
): BabelTypes.Expression[] {
|
|
83
|
+
const args: BabelTypes.Expression[] = [];
|
|
84
|
+
let chunk: CompiledItem[] = [];
|
|
85
|
+
|
|
86
|
+
const flushChunk = () => {
|
|
87
|
+
if (chunk.length === 0) return;
|
|
88
|
+
|
|
89
|
+
args.push(buildItemsArray(
|
|
90
|
+
t,
|
|
91
|
+
{ ...chain, items: chunk },
|
|
92
|
+
BUILDER_TYPE_STYLE,
|
|
93
|
+
state,
|
|
94
|
+
options,
|
|
95
|
+
));
|
|
96
|
+
chunk = [];
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
chain.items.forEach((item) => {
|
|
100
|
+
if (isCompiledStyleSpreadItem(item)) {
|
|
101
|
+
flushChunk();
|
|
102
|
+
args.push(t.cloneNode(item.expression));
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
chunk.push(item);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
flushChunk();
|
|
110
|
+
|
|
111
|
+
return args;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function buildItemsArray(
|
|
115
|
+
t: typeof BabelTypes,
|
|
116
|
+
chain: CompiledChainData,
|
|
117
|
+
defaultType: number,
|
|
118
|
+
state: ExtractPluginState,
|
|
119
|
+
options: BuildReplacementOptions,
|
|
120
|
+
): BabelTypes.ArrayExpression {
|
|
121
|
+
const emitLegacyShape = defaultType === BUILDER_TYPE_SCOPE;
|
|
122
|
+
const itemExpressions: BabelTypes.Expression[] = [];
|
|
123
|
+
|
|
124
|
+
chain.items.forEach((item) => {
|
|
125
|
+
if (isCompiledTokenItem(item)) {
|
|
126
|
+
if (options.getTokenOverride) {
|
|
127
|
+
options.getTokenOverride(item);
|
|
128
|
+
} else {
|
|
129
|
+
itemExpressions.push(t.cloneNode(item.valueNode));
|
|
130
|
+
}
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if (isCompiledStyleSpreadItem(item)) {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const type = getItemType(item);
|
|
139
|
+
const dedupe = getItemDedupe(item);
|
|
140
|
+
const className = getItemClassName(item);
|
|
141
|
+
const value = getItemValue(item);
|
|
142
|
+
const slotId = getItemSlotId(item);
|
|
143
|
+
|
|
144
|
+
const elements: BabelTypes.Expression[] = emitLegacyShape
|
|
145
|
+
? [t.numericLiteral(type), t.stringLiteral(slotId ?? '')]
|
|
146
|
+
: [];
|
|
147
|
+
|
|
148
|
+
if (!emitLegacyShape && type === BUILDER_TYPE_SLOT) {
|
|
149
|
+
elements.push(t.stringLiteral(dedupe));
|
|
150
|
+
elements.push(t.stringLiteral(className));
|
|
151
|
+
|
|
152
|
+
if (isItemMetadataValue(value)) {
|
|
153
|
+
elements.push(buildItemValue(t, value, state, item, options));
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
itemExpressions.push(t.arrayExpression(elements));
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
elements.push(t.stringLiteral(dedupe));
|
|
161
|
+
elements.push(t.stringLiteral(className));
|
|
162
|
+
|
|
163
|
+
if ((!emitLegacyShape || type === BUILDER_TYPE_SCOPE) && isItemMetadataValue(value)) {
|
|
164
|
+
elements.push(buildItemValue(t, value, state, item, options));
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
if (emitLegacyShape && item.hasParentSelector) {
|
|
168
|
+
elements.push(t.numericLiteral(1));
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
itemExpressions.push(t.arrayExpression(elements));
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
return t.arrayExpression(itemExpressions);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function isCompiledTokenItem(
|
|
178
|
+
item: CompiledItem,
|
|
179
|
+
): item is Extract<CompiledItem, { kind: 'token'; }> {
|
|
180
|
+
return !Array.isArray(item) && item.kind === 'token';
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function isCompiledStyleSpreadItem(
|
|
184
|
+
item: CompiledItem,
|
|
185
|
+
): item is CompiledStyleSpreadItem {
|
|
186
|
+
return !Array.isArray(item) && item.kind === 'style-spread';
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function isItemMetadataValue(
|
|
190
|
+
value: ExtractedItemValue | null | undefined,
|
|
191
|
+
): value is Extract<
|
|
192
|
+
ExtractedItemValue,
|
|
193
|
+
[typeof ITEM_VALUE_TYPE_VARIABLE, string, unknown, unknown?] | [typeof ITEM_VALUE_TYPE_AT_RULE_REF, unknown]
|
|
194
|
+
> {
|
|
195
|
+
return !!value &&
|
|
196
|
+
(
|
|
197
|
+
value[0] === ITEM_VALUE_TYPE_VARIABLE ||
|
|
198
|
+
value[0] === ITEM_VALUE_TYPE_AT_RULE_REF
|
|
199
|
+
);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function getItemType(item: CompiledCssItem): BuilderType {
|
|
203
|
+
return typeof item[0] === 'number' ? item[0] as BuilderType : BUILDER_TYPE_STYLE;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function getItemSlotId(item: CompiledCssItem): string | null {
|
|
207
|
+
const type = getItemType(item);
|
|
208
|
+
|
|
209
|
+
if (type === BUILDER_TYPE_SLOT || type === BUILDER_TYPE_SLOT_OVERRIDE || type === BUILDER_TYPE_SCOPE) {
|
|
210
|
+
return item[1] as string;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
return null;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
function getItemDedupe(item: CompiledCssItem): string {
|
|
217
|
+
const type = getItemType(item);
|
|
218
|
+
|
|
219
|
+
if (type === BUILDER_TYPE_STYLE) {
|
|
220
|
+
return typeof item[0] === 'number' ? item[1] as string : item[0] as string;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
return item[2] as string;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
function getItemClassName(item: CompiledCssItem): string {
|
|
227
|
+
const type = getItemType(item);
|
|
228
|
+
|
|
229
|
+
if (type === BUILDER_TYPE_STYLE) {
|
|
230
|
+
return typeof item[0] === 'number' ? item[2] as string : item[1] as string;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
return item[3] as string;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
function getItemValue(item: CompiledCssItem): ExtractedItemValue | undefined {
|
|
237
|
+
const type = getItemType(item);
|
|
238
|
+
|
|
239
|
+
if (type === BUILDER_TYPE_SCOPE) {
|
|
240
|
+
return isExtractedScopeParentMarker(item[4])
|
|
241
|
+
? undefined
|
|
242
|
+
: item[4] as ExtractedItemValue | undefined;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
if (type === BUILDER_TYPE_STYLE) {
|
|
246
|
+
return (typeof item[0] === 'number' ? item[3] : item[2]) as ExtractedItemValue | undefined;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
return item[4] as ExtractedItemValue | undefined;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
function isExtractedScopeParentMarker(value: unknown) {
|
|
253
|
+
return value === 1 || value === true;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
function buildItemValue(
|
|
257
|
+
t: typeof BabelTypes,
|
|
258
|
+
value: ExtractedItemValue,
|
|
259
|
+
state: ExtractPluginState,
|
|
260
|
+
item: CompiledCssItem,
|
|
261
|
+
options: BuildReplacementOptions,
|
|
262
|
+
): BabelTypes.ArrayExpression {
|
|
263
|
+
if (value[0] === ITEM_VALUE_TYPE_AT_RULE_REF) {
|
|
264
|
+
return buildAtRuleRefExpression(t, value[1], state);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
if (value[0] !== ITEM_VALUE_TYPE_VARIABLE) {
|
|
268
|
+
throw new Error('Unsupported extracted item value');
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
return t.arrayExpression([
|
|
272
|
+
t.numericLiteral(value[0]),
|
|
273
|
+
t.stringLiteral(value[1]),
|
|
274
|
+
buildVariableValueExpression(t, value[2], state, item, options),
|
|
275
|
+
...(value[3] === ITEM_VALUE_NUMBER_PX ? [t.numericLiteral(ITEM_VALUE_NUMBER_PX)] : []),
|
|
276
|
+
]);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
function buildAtRuleRefExpression(
|
|
280
|
+
t: typeof BabelTypes,
|
|
281
|
+
ref: AtRuleRefData,
|
|
282
|
+
state: ExtractPluginState,
|
|
283
|
+
): BabelTypes.ArrayExpression {
|
|
284
|
+
const props: BabelTypes.ObjectProperty[] = [
|
|
285
|
+
t.objectProperty(t.identifier('key'), t.stringLiteral(ref.key)),
|
|
286
|
+
t.objectProperty(t.identifier('value'), t.stringLiteral(ref.value)),
|
|
287
|
+
t.objectProperty(t.identifier('css'), ref.css ? t.stringLiteral(ref.css) : t.nullLiteral()),
|
|
288
|
+
];
|
|
289
|
+
|
|
290
|
+
if (ref.tokens?.length) {
|
|
291
|
+
props.push(t.objectProperty(
|
|
292
|
+
t.identifier('tokens'),
|
|
293
|
+
t.arrayExpression(ref.tokens.map((token) => buildExtractedTokenExpression(t, token, state))),
|
|
294
|
+
));
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
return t.arrayExpression([
|
|
298
|
+
t.numericLiteral(ITEM_VALUE_TYPE_AT_RULE_REF),
|
|
299
|
+
t.objectExpression(props),
|
|
300
|
+
]);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
function buildVariableValueExpression(
|
|
304
|
+
t: typeof BabelTypes,
|
|
305
|
+
value: unknown,
|
|
306
|
+
state: ExtractPluginState,
|
|
307
|
+
item: CompiledCssItem,
|
|
308
|
+
options: BuildReplacementOptions,
|
|
309
|
+
): BabelTypes.Expression {
|
|
310
|
+
if (isStyleTokenData(value)) {
|
|
311
|
+
state.usedHelpers.add(FN_CREATE_EXTRACTED_TOKEN);
|
|
312
|
+
return buildExtractedTokenExpression(t, value, state);
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
const valueNode = item.valueNode;
|
|
316
|
+
const runtimeToken = valueNode ? options.getRuntimeToken?.(item, valueNode) : null;
|
|
317
|
+
if (runtimeToken) return runtimeToken;
|
|
318
|
+
|
|
319
|
+
return valueNode ? t.cloneNode(valueNode) : literalExpression(t, value);
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
function buildExtractedTokenExpression(
|
|
323
|
+
t: typeof BabelTypes,
|
|
324
|
+
token: StyleTokenData,
|
|
325
|
+
state: ExtractPluginState,
|
|
326
|
+
): BabelTypes.Expression {
|
|
327
|
+
state.usedHelpers.add(FN_CREATE_EXTRACTED_TOKEN);
|
|
328
|
+
|
|
329
|
+
return t.callExpression(
|
|
330
|
+
t.identifier(FN_CREATE_EXTRACTED_TOKEN),
|
|
331
|
+
[
|
|
332
|
+
t.stringLiteral(getStyleTokenId(token)),
|
|
333
|
+
literalExpression(t, token.value),
|
|
334
|
+
token.ref ? buildExtractedTokenExpression(t, token.ref, state) : t.nullLiteral(),
|
|
335
|
+
],
|
|
336
|
+
);
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
function literalExpression(
|
|
340
|
+
t: typeof BabelTypes,
|
|
341
|
+
value: unknown,
|
|
342
|
+
): BabelTypes.Expression {
|
|
343
|
+
if (typeof value === 'string') return t.stringLiteral(value);
|
|
344
|
+
if (typeof value === 'number') return t.numericLiteral(value);
|
|
345
|
+
if (typeof value === 'boolean') return t.booleanLiteral(value);
|
|
346
|
+
if (value === null || value === undefined) return t.nullLiteral();
|
|
347
|
+
|
|
348
|
+
return t.stringLiteral(String(value));
|
|
349
|
+
}
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import { BUILDER_TYPE_SCOPE, BUILDER_TYPE_SLOT, BUILDER_TYPE_STYLE } from '../../../../builder/data/const';
|
|
2
|
+
import {
|
|
3
|
+
createExtractedScope,
|
|
4
|
+
createExtractedSlot,
|
|
5
|
+
createExtractedStyle,
|
|
6
|
+
type ExtractedSlotTuple,
|
|
7
|
+
type ExtractedStyleTuple,
|
|
8
|
+
} from '../../../../builder/extract';
|
|
9
|
+
import { evalOk } from '../../evaluator/evaluator';
|
|
10
|
+
import type { EvalSlotRef } from '../../evaluator/types';
|
|
11
|
+
import { getObjectPropertyKey } from '../../syntax';
|
|
12
|
+
import type { BabelTypes, NodePath } from '../../utils/babel';
|
|
13
|
+
import type { CompiledChainData, CompiledCssItem, CompiledItem } from '../chain';
|
|
14
|
+
import type { ExtractPluginState } from './state';
|
|
15
|
+
|
|
16
|
+
export function recordCompiledBinding(
|
|
17
|
+
path: NodePath<BabelTypes.CallExpression>,
|
|
18
|
+
state: ExtractPluginState,
|
|
19
|
+
chain: CompiledChainData,
|
|
20
|
+
) {
|
|
21
|
+
const value = getCompiledBindingValue(chain);
|
|
22
|
+
if (value) {
|
|
23
|
+
recordCompiledValueBinding(path, state, value);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (chain.type !== 'slot' || !chain.slotId) return;
|
|
27
|
+
|
|
28
|
+
const slotRef: EvalSlotRef = {
|
|
29
|
+
ok: false,
|
|
30
|
+
reason: 'slot-ref',
|
|
31
|
+
filePath: state.fileId,
|
|
32
|
+
slotId: chain.slotId,
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const parent = path.parentPath;
|
|
36
|
+
|
|
37
|
+
if (parent?.isVariableDeclarator() && parent.node.id.type === 'Identifier') {
|
|
38
|
+
state.bindings.set(parent.node.id.name, slotRef);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (!parent?.isObjectProperty()) return;
|
|
43
|
+
if (parent.node.value !== path.node) return;
|
|
44
|
+
|
|
45
|
+
const objectPath = parent.parentPath;
|
|
46
|
+
const declaratorPath = objectPath?.parentPath;
|
|
47
|
+
|
|
48
|
+
if (!objectPath?.isObjectExpression()) return;
|
|
49
|
+
if (!declaratorPath?.isVariableDeclarator()) return;
|
|
50
|
+
if (declaratorPath.node.id.type !== 'Identifier') return;
|
|
51
|
+
|
|
52
|
+
const key = getObjectPropertyKey(parent.node);
|
|
53
|
+
if (!key) return;
|
|
54
|
+
|
|
55
|
+
const name = declaratorPath.node.id.name;
|
|
56
|
+
const current = state.bindings.get(name);
|
|
57
|
+
|
|
58
|
+
const currentValue = current?.ok && current.value && typeof current.value === 'object'
|
|
59
|
+
? current.value as Record<string, unknown>
|
|
60
|
+
: {};
|
|
61
|
+
|
|
62
|
+
state.bindings.set(name, evalOk({ ...currentValue, [key]: slotRef }));
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function recordCompiledValueBinding(
|
|
66
|
+
path: NodePath<BabelTypes.CallExpression>,
|
|
67
|
+
state: ExtractPluginState,
|
|
68
|
+
value: unknown,
|
|
69
|
+
) {
|
|
70
|
+
const parent = path.parentPath;
|
|
71
|
+
|
|
72
|
+
if (parent?.isVariableDeclarator() && parent.node.id.type === 'Identifier') {
|
|
73
|
+
state.bindings.set(parent.node.id.name, evalOk(value));
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (!parent?.isObjectProperty()) return;
|
|
78
|
+
if (parent.node.value !== path.node) return;
|
|
79
|
+
|
|
80
|
+
const objectPath = parent.parentPath;
|
|
81
|
+
const declaratorPath = objectPath?.parentPath;
|
|
82
|
+
|
|
83
|
+
if (!objectPath?.isObjectExpression()) return;
|
|
84
|
+
if (!declaratorPath?.isVariableDeclarator()) return;
|
|
85
|
+
if (declaratorPath.node.id.type !== 'Identifier') return;
|
|
86
|
+
|
|
87
|
+
const key = getObjectPropertyKey(parent.node);
|
|
88
|
+
if (!key) return;
|
|
89
|
+
|
|
90
|
+
const name = declaratorPath.node.id.name;
|
|
91
|
+
const current = state.bindings.get(name);
|
|
92
|
+
|
|
93
|
+
const currentValue = current?.ok && current.value && typeof current.value === 'object'
|
|
94
|
+
? current.value as Record<string, unknown>
|
|
95
|
+
: {};
|
|
96
|
+
|
|
97
|
+
state.bindings.set(name, evalOk({ ...currentValue, [key]: value }));
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function getCompiledBindingValue(chain: CompiledChainData) {
|
|
101
|
+
if (chain.type === 'style') {
|
|
102
|
+
return createExtractedStyle(
|
|
103
|
+
getCompiledCssItems(chain.items).map((item) => toExtractedTuple(item)) as ExtractedStyleTuple[],
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (chain.type === 'slot' && chain.slotId) {
|
|
108
|
+
return createExtractedSlot(
|
|
109
|
+
chain.slotId,
|
|
110
|
+
getCompiledCssItems(chain.items).map((item) => toExtractedTuple(item)) as ExtractedSlotTuple[],
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if (chain.type === 'scope') {
|
|
115
|
+
return createExtractedScope(chain.items.map(toExtractedScopeItem).filter((item) => item !== null));
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return null;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function getCompiledCssItems(items: CompiledItem[]): CompiledCssItem[] {
|
|
122
|
+
const result: CompiledCssItem[] = [];
|
|
123
|
+
|
|
124
|
+
items.forEach((item) => {
|
|
125
|
+
if (Array.isArray(item)) {
|
|
126
|
+
result.push(item);
|
|
127
|
+
} else if (item.kind === 'style-spread') {
|
|
128
|
+
result.push(...item.items);
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
return result;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function toExtractedScopeItem(item: CompiledItem): Parameters<typeof createExtractedScope>[0][number] | null {
|
|
136
|
+
if (!Array.isArray(item)) {
|
|
137
|
+
if (item.kind === 'style-spread') return null;
|
|
138
|
+
return item.kind === 'token' ? item.value : null;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return toExtractedScopeTuple(item);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function toExtractedTuple(item: CompiledCssItem): ExtractedStyleTuple | ExtractedSlotTuple {
|
|
145
|
+
const type = typeof item[0] === 'number' ? item[0] : BUILDER_TYPE_STYLE;
|
|
146
|
+
|
|
147
|
+
if (type === BUILDER_TYPE_STYLE) {
|
|
148
|
+
return typeof item[0] === 'number'
|
|
149
|
+
? toOptionalValueTuple(String(item[1]), String(item[2]), item[3])
|
|
150
|
+
: toOptionalValueTuple(String(item[0]), String(item[1]), item[2]);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
if (type === BUILDER_TYPE_SLOT) {
|
|
154
|
+
return toOptionalValueTuple(String(item[2]), String(item[3]), item[4]);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
if (type === BUILDER_TYPE_SCOPE) {
|
|
158
|
+
return toOptionalValueTuple(String(item[2]), String(item[3]), item[4]);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
return toOptionalValueTuple(String(item[2]), String(item[3]), item[4]);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
function toOptionalValueTuple(
|
|
165
|
+
dedupe: string,
|
|
166
|
+
className: string,
|
|
167
|
+
value: CompiledCssItem[number],
|
|
168
|
+
): ExtractedStyleTuple {
|
|
169
|
+
return value === undefined
|
|
170
|
+
? [dedupe, className]
|
|
171
|
+
: [dedupe, className, value as ExtractedStyleTuple[2]];
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function toExtractedScopeTuple(item: CompiledCssItem): Parameters<typeof createExtractedScope>[0][number] {
|
|
175
|
+
const tuple: unknown[] = [
|
|
176
|
+
BUILDER_TYPE_SCOPE,
|
|
177
|
+
item[1],
|
|
178
|
+
item[2],
|
|
179
|
+
item[3],
|
|
180
|
+
];
|
|
181
|
+
|
|
182
|
+
if (item[4] !== undefined) tuple.push(item[4]);
|
|
183
|
+
if (item.hasParentSelector) tuple.push(1);
|
|
184
|
+
|
|
185
|
+
return tuple as Parameters<typeof createExtractedScope>[0][number];
|
|
186
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { StyleFnMeta } from '../../../../style/style';
|
|
2
|
+
import type { CompilerRuntimeMode } from '../../../compiler';
|
|
3
|
+
import type { CompilerOptions } from '../../../compiler/types';
|
|
4
|
+
import type { CompilerCssCollector } from '../../../extract';
|
|
5
|
+
import type { ImportSourceMatcher } from '../../../utils/import_source';
|
|
6
|
+
import type { EvalScope } from '../../evaluator/evaluator';
|
|
7
|
+
import type { EvalModuleBindings, ImportMap, ResolveImportFn } from '../../evaluator/types';
|
|
8
|
+
import type { BabelTypes } from '../../utils/babel';
|
|
9
|
+
|
|
10
|
+
export type HoistedDeclaration = {
|
|
11
|
+
declaration: BabelTypes.Statement;
|
|
12
|
+
dependencies: Set<string>;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export type ExtractPluginState = {
|
|
16
|
+
fileId: string;
|
|
17
|
+
filePath: string;
|
|
18
|
+
styleFilePath: string;
|
|
19
|
+
sourcemapTrace: 'style' | 'value';
|
|
20
|
+
styleNames: Set<string>;
|
|
21
|
+
styleMetas: Map<string, StyleFnMeta>;
|
|
22
|
+
bindings: EvalModuleBindings;
|
|
23
|
+
bindingNodes: Map<string, BabelTypes.Node>;
|
|
24
|
+
imports: ImportMap;
|
|
25
|
+
needsExtractImport: boolean;
|
|
26
|
+
usedHelpers: Set<string>;
|
|
27
|
+
importSourceMatcher: ImportSourceMatcher;
|
|
28
|
+
resolveImport: ResolveImportFn;
|
|
29
|
+
collector: CompilerCssCollector;
|
|
30
|
+
hoistedDeclarations: HoistedDeclaration[];
|
|
31
|
+
runtimeTokenIndex: number;
|
|
32
|
+
runtimeMode: CompilerRuntimeMode | null;
|
|
33
|
+
options: CompilerOptions;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export function getEvalScope(state: ExtractPluginState): EvalScope {
|
|
37
|
+
return {
|
|
38
|
+
bindings: state.bindings,
|
|
39
|
+
imports: state.imports,
|
|
40
|
+
resolveImport: state.resolveImport,
|
|
41
|
+
filePath: state.filePath,
|
|
42
|
+
styleFilePath: state.styleFilePath,
|
|
43
|
+
sourcemapTrace: state.sourcemapTrace,
|
|
44
|
+
styleNames: state.styleNames,
|
|
45
|
+
styleMetas: state.styleMetas,
|
|
46
|
+
bindingNodes: state.bindingNodes,
|
|
47
|
+
};
|
|
48
|
+
}
|