@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,665 @@
|
|
|
1
|
+
import { hashString } from '../../../utils/hash';
|
|
2
|
+
import type { CompilerRuntimeMode } from '../../compiler';
|
|
3
|
+
import type { CompilerOptions } from '../../compiler/types';
|
|
4
|
+
import type { CompilerCssCollector } from '../../extract/collector';
|
|
5
|
+
import {
|
|
6
|
+
FN_CREATE_EXTRACTED_THEME,
|
|
7
|
+
FN_CREATE_EXTRACTED_TOKEN,
|
|
8
|
+
FN_STYLE_PLAIN,
|
|
9
|
+
FN_STYLE_RAW,
|
|
10
|
+
FN_WITH_TOKENS,
|
|
11
|
+
IMPORT_EXTRACT,
|
|
12
|
+
} from '../../utils/constants';
|
|
13
|
+
import { createImportSourceMatcher } from '../../utils/import_source';
|
|
14
|
+
import { normalizePath } from '../../utils/path';
|
|
15
|
+
import { evaluateEnumDeclaration, evaluateNode } from '../evaluator/evaluator';
|
|
16
|
+
import { getImportedName } from '../syntax';
|
|
17
|
+
import { annotateAtRuleDeclaration } from '../syntax/static_ids';
|
|
18
|
+
import { BabelCore } from '../utils/babel';
|
|
19
|
+
import type { BabelTypes } from '../utils/babel';
|
|
20
|
+
import { babelPlugin } from '../utils/babel';
|
|
21
|
+
import { getSelectorCompileErrorNode } from '../utils/selector';
|
|
22
|
+
import { compileChain, extractStyleChain } from './chain';
|
|
23
|
+
import { pruneUnusedStyleImports } from './utils/imports';
|
|
24
|
+
import { buildReplacement } from './utils/replacement';
|
|
25
|
+
import { recordCompiledBinding } from './utils/slot';
|
|
26
|
+
import { type ExtractPluginState, getEvalScope, type HoistedDeclaration } from './utils/state';
|
|
27
|
+
import { compileThemeCall } from './utils/theme';
|
|
28
|
+
import { annotateTokenDeclaration } from './utils/token';
|
|
29
|
+
|
|
30
|
+
export type PluginState = BabelCore.PluginPass & ExtractPluginState;
|
|
31
|
+
|
|
32
|
+
type PluginArgs = {
|
|
33
|
+
options: CompilerOptions;
|
|
34
|
+
collector: CompilerCssCollector;
|
|
35
|
+
mode?: 'extract' | 'collect';
|
|
36
|
+
projectDir: string;
|
|
37
|
+
runtimeMode: CompilerRuntimeMode | null;
|
|
38
|
+
styleFilePath?: string;
|
|
39
|
+
tracer: ExtractTracer;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export type ExtractTracer = {
|
|
43
|
+
resolveImport(
|
|
44
|
+
babel: typeof BabelCore,
|
|
45
|
+
source: string,
|
|
46
|
+
fromFile: string,
|
|
47
|
+
): ReturnType<ExtractPluginState['resolveImport']>;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export function createExtractPlugin(args: PluginArgs) {
|
|
51
|
+
const { options } = args;
|
|
52
|
+
const mode = args.mode ?? 'extract';
|
|
53
|
+
|
|
54
|
+
return babelPlugin<PluginState>((babel) => {
|
|
55
|
+
const { types: t } = babel;
|
|
56
|
+
|
|
57
|
+
return {
|
|
58
|
+
pre(this) {
|
|
59
|
+
this.styleNames = new Set();
|
|
60
|
+
this.styleMetas = new Map();
|
|
61
|
+
this.bindings = new Map();
|
|
62
|
+
this.bindingNodes = new Map();
|
|
63
|
+
this.imports = new Map();
|
|
64
|
+
this.needsExtractImport = false;
|
|
65
|
+
this.usedHelpers = new Set<string>();
|
|
66
|
+
this.hoistedDeclarations = [];
|
|
67
|
+
this.runtimeTokenIndex = 0;
|
|
68
|
+
this.runtimeMode = args.runtimeMode;
|
|
69
|
+
this.options = options;
|
|
70
|
+
this.importSourceMatcher = createImportSourceMatcher(options.importSources ?? null);
|
|
71
|
+
this.resolveImport = (source, fromFile) => args.tracer.resolveImport(babel, source, fromFile);
|
|
72
|
+
this.collector = args.collector;
|
|
73
|
+
this.filePath = this.file?.opts?.filename ?? 'unknown';
|
|
74
|
+
this.styleFilePath = args.styleFilePath ?? this.filePath;
|
|
75
|
+
this.sourcemapTrace = options.dev?.sourcemapMode ?? 'style';
|
|
76
|
+
this.fileId = args.styleFilePath ?? getProjectFileId(args.projectDir, this.file?.opts?.filename);
|
|
77
|
+
},
|
|
78
|
+
|
|
79
|
+
visitor: {
|
|
80
|
+
ImportDeclaration(path, state) {
|
|
81
|
+
const source = path.node.source.value;
|
|
82
|
+
|
|
83
|
+
path.node.specifiers.forEach((spec) => {
|
|
84
|
+
if (spec.type === 'ImportSpecifier') {
|
|
85
|
+
const imported = getImportedName(spec);
|
|
86
|
+
state.imports.set(spec.local.name, { source, name: imported });
|
|
87
|
+
} else if (spec.type === 'ImportDefaultSpecifier') {
|
|
88
|
+
state.imports.set(spec.local.name, { source, name: 'default' });
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
const sourceName = typeof source === 'string' ? source : null;
|
|
93
|
+
if (!sourceName) return;
|
|
94
|
+
|
|
95
|
+
path.node.specifiers.forEach((spec) => {
|
|
96
|
+
if (spec.type !== 'ImportSpecifier' && spec.type !== 'ImportDefaultSpecifier') return;
|
|
97
|
+
|
|
98
|
+
const imported = spec.type === 'ImportSpecifier'
|
|
99
|
+
? getImportedName(spec)
|
|
100
|
+
: 'default';
|
|
101
|
+
|
|
102
|
+
const meta = state.importSourceMatcher({ source: sourceName, name: imported });
|
|
103
|
+
if (meta) {
|
|
104
|
+
state.styleNames.add(spec.local.name);
|
|
105
|
+
state.styleMetas.set(spec.local.name, meta);
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
},
|
|
109
|
+
|
|
110
|
+
VariableDeclaration(path, state) {
|
|
111
|
+
if (path.parentPath?.isExportNamedDeclaration()) return;
|
|
112
|
+
|
|
113
|
+
path.node.declarations.forEach((decl) => {
|
|
114
|
+
if (decl.id.type !== 'Identifier' || !decl.init) return;
|
|
115
|
+
|
|
116
|
+
annotateTokenDeclaration(decl, state, t);
|
|
117
|
+
annotateAtRuleDeclaration(decl, state, t);
|
|
118
|
+
|
|
119
|
+
const name = decl.id.name;
|
|
120
|
+
const scope = getEvalScope(state);
|
|
121
|
+
const result = evaluateNode(decl.init, scope);
|
|
122
|
+
|
|
123
|
+
state.bindings.set(name, result);
|
|
124
|
+
state.bindingNodes.set(name, decl.init);
|
|
125
|
+
});
|
|
126
|
+
},
|
|
127
|
+
|
|
128
|
+
ExportNamedDeclaration(path, state) {
|
|
129
|
+
if (!path.node.declaration) return;
|
|
130
|
+
if (path.node.declaration.type !== 'VariableDeclaration') return;
|
|
131
|
+
|
|
132
|
+
path.node.declaration.declarations.forEach((decl) => {
|
|
133
|
+
if (decl.id.type !== 'Identifier' || !decl.init) return;
|
|
134
|
+
|
|
135
|
+
annotateTokenDeclaration(decl, state, t);
|
|
136
|
+
annotateAtRuleDeclaration(decl, state, t);
|
|
137
|
+
|
|
138
|
+
const name = decl.id.name;
|
|
139
|
+
const scope = getEvalScope(state);
|
|
140
|
+
const result = evaluateNode(decl.init, scope);
|
|
141
|
+
|
|
142
|
+
state.bindings.set(name, result);
|
|
143
|
+
state.bindingNodes.set(name, decl.init);
|
|
144
|
+
});
|
|
145
|
+
},
|
|
146
|
+
|
|
147
|
+
TSEnumDeclaration(path, state) {
|
|
148
|
+
const name = path.node.id.name;
|
|
149
|
+
const scope = getEvalScope(state);
|
|
150
|
+
state.bindings.set(name, evaluateEnumDeclaration(path.node, scope));
|
|
151
|
+
},
|
|
152
|
+
|
|
153
|
+
CallExpression(path, state) {
|
|
154
|
+
if (
|
|
155
|
+
path.parent.type === 'MemberExpression' &&
|
|
156
|
+
!(path.parent.computed)
|
|
157
|
+
) {
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const theme = compileThemeCall(path, state, options);
|
|
162
|
+
|
|
163
|
+
if (theme) {
|
|
164
|
+
state.collector.add(theme.rule);
|
|
165
|
+
|
|
166
|
+
if (mode === 'collect') {
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
state.usedHelpers.add(FN_CREATE_EXTRACTED_THEME);
|
|
171
|
+
|
|
172
|
+
path.replaceWith(t.callExpression(
|
|
173
|
+
t.identifier(FN_CREATE_EXTRACTED_THEME),
|
|
174
|
+
[t.stringLiteral(theme.id), t.stringLiteral(theme.className)],
|
|
175
|
+
));
|
|
176
|
+
|
|
177
|
+
path.skip();
|
|
178
|
+
state.needsExtractImport = true;
|
|
179
|
+
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
if (!state.styleNames.size) return;
|
|
184
|
+
|
|
185
|
+
const chain = extractStyleChain(path.node, state.styleNames);
|
|
186
|
+
if (!chain) return;
|
|
187
|
+
|
|
188
|
+
if (
|
|
189
|
+
chain.kind === 'slot' &&
|
|
190
|
+
path.parent.type === 'CallExpression' &&
|
|
191
|
+
path.parent.callee === path.node
|
|
192
|
+
) {
|
|
193
|
+
throw path.buildCodeFrameError(
|
|
194
|
+
'Direct invocation `style.slot(...)()` is not allowed. Assign the slot to a variable first, then call it through that binding.',
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
const scope = getEvalScope(state);
|
|
199
|
+
const loc = path.node.loc?.start;
|
|
200
|
+
const meta = state.styleMetas.get(chain.rootName);
|
|
201
|
+
if (!meta) return;
|
|
202
|
+
|
|
203
|
+
let result: ReturnType<typeof compileChain>;
|
|
204
|
+
try {
|
|
205
|
+
result = compileChain(chain, state.fileId, loc, scope, options, meta, state.styleNames);
|
|
206
|
+
} catch (error) {
|
|
207
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
208
|
+
const node = getSelectorCompileErrorNode(error);
|
|
209
|
+
throw buildCodeFrameError(path, node ?? path.node, message);
|
|
210
|
+
}
|
|
211
|
+
if (!result) return;
|
|
212
|
+
|
|
213
|
+
result.rules.forEach((rule) => {
|
|
214
|
+
state.collector.add(rule);
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
if (mode === 'collect') {
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
const replacement = createChainReplacement({
|
|
222
|
+
t,
|
|
223
|
+
path,
|
|
224
|
+
state,
|
|
225
|
+
result,
|
|
226
|
+
hoist: options.hoist !== false,
|
|
227
|
+
});
|
|
228
|
+
if (!replacement) return;
|
|
229
|
+
|
|
230
|
+
recordCompiledBinding(path, state, result);
|
|
231
|
+
|
|
232
|
+
if (!replacement.hoist) {
|
|
233
|
+
path.replaceWith(replacement.expression);
|
|
234
|
+
path.skip();
|
|
235
|
+
state.needsExtractImport = true;
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
path.replaceWith(replacement.expression);
|
|
240
|
+
path.skip();
|
|
241
|
+
|
|
242
|
+
state.needsExtractImport = true;
|
|
243
|
+
},
|
|
244
|
+
|
|
245
|
+
Program: {
|
|
246
|
+
exit(path, state) {
|
|
247
|
+
if (mode === 'collect') return;
|
|
248
|
+
|
|
249
|
+
pruneUnusedStyleInputDeclarations(path, state);
|
|
250
|
+
pruneUnusedStyleImports(path, state);
|
|
251
|
+
|
|
252
|
+
if (!state.needsExtractImport) return;
|
|
253
|
+
|
|
254
|
+
const helpers = [...state.usedHelpers];
|
|
255
|
+
if (!helpers.length) return;
|
|
256
|
+
|
|
257
|
+
const importDecl = t.importDeclaration(
|
|
258
|
+
helpers.map((helper) => t.importSpecifier(t.identifier(helper), t.identifier(helper))),
|
|
259
|
+
t.stringLiteral(IMPORT_EXTRACT),
|
|
260
|
+
);
|
|
261
|
+
|
|
262
|
+
path.unshiftContainer('body', importDecl);
|
|
263
|
+
insertHoistedDeclarations(path, state.hoistedDeclarations);
|
|
264
|
+
},
|
|
265
|
+
},
|
|
266
|
+
},
|
|
267
|
+
};
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
function pruneUnusedStyleInputDeclarations(
|
|
272
|
+
path: BabelCore.NodePath<BabelTypes.Program>,
|
|
273
|
+
state: PluginState,
|
|
274
|
+
) {
|
|
275
|
+
path.scope.crawl();
|
|
276
|
+
|
|
277
|
+
path.traverse({
|
|
278
|
+
VariableDeclarator(declaratorPath) {
|
|
279
|
+
const node = declaratorPath.node;
|
|
280
|
+
|
|
281
|
+
if (declaratorPath.parentPath?.parentPath?.isExportNamedDeclaration()) return;
|
|
282
|
+
if (node.id.type !== 'Identifier') return;
|
|
283
|
+
if (!isStyleInputCall(node.init, state)) return;
|
|
284
|
+
|
|
285
|
+
const binding = declaratorPath.scope.getBinding(node.id.name);
|
|
286
|
+
if (!binding || binding.referencePaths.length) return;
|
|
287
|
+
|
|
288
|
+
const declarationPath = declaratorPath.parentPath;
|
|
289
|
+
if (!declarationPath?.isVariableDeclaration()) return;
|
|
290
|
+
|
|
291
|
+
if (declarationPath.node.declarations.length > 1) {
|
|
292
|
+
declaratorPath.remove();
|
|
293
|
+
} else {
|
|
294
|
+
declarationPath.remove();
|
|
295
|
+
}
|
|
296
|
+
},
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
path.scope.crawl();
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
function isStyleInputCall(
|
|
303
|
+
node: BabelTypes.Node | null | undefined,
|
|
304
|
+
state: PluginState,
|
|
305
|
+
) {
|
|
306
|
+
if (!node || node.type !== 'CallExpression') return false;
|
|
307
|
+
|
|
308
|
+
const callee = node.callee;
|
|
309
|
+
if (callee.type !== 'MemberExpression' || callee.computed) return false;
|
|
310
|
+
if (callee.object.type !== 'Identifier') return false;
|
|
311
|
+
if (!state.styleNames.has(callee.object.name)) return false;
|
|
312
|
+
|
|
313
|
+
const property = callee.property;
|
|
314
|
+
if (property.type !== 'Identifier') return false;
|
|
315
|
+
|
|
316
|
+
return property.name === FN_STYLE_RAW || property.name === FN_STYLE_PLAIN;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
function buildCodeFrameError(
|
|
320
|
+
path: BabelCore.NodePath<BabelTypes.Node>,
|
|
321
|
+
node: BabelTypes.Node,
|
|
322
|
+
message: string,
|
|
323
|
+
) {
|
|
324
|
+
const hub = path.hub as unknown as {
|
|
325
|
+
buildError: (node: BabelTypes.Node, message: string, ErrorCtor: ErrorConstructor) => Error;
|
|
326
|
+
};
|
|
327
|
+
|
|
328
|
+
return hub.buildError(node, message, Error);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
function getProjectFileId(projectDir: string, filePath: string | null | undefined) {
|
|
332
|
+
if (!filePath) return 'unknown';
|
|
333
|
+
|
|
334
|
+
const normalizedProjectDir = normalizePath(projectDir).replace(/\/+$/, '');
|
|
335
|
+
const normalizedFilePath = normalizePath(filePath);
|
|
336
|
+
const prefix = normalizedProjectDir + '/';
|
|
337
|
+
|
|
338
|
+
if (normalizedProjectDir && normalizedFilePath.startsWith(prefix)) {
|
|
339
|
+
return normalizedFilePath.slice(prefix.length);
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
return normalizedFilePath;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
type ChainReplacementArgs = {
|
|
346
|
+
t: typeof BabelTypes;
|
|
347
|
+
path: BabelCore.NodePath<BabelTypes.CallExpression>;
|
|
348
|
+
state: ExtractPluginState;
|
|
349
|
+
result: Parameters<typeof buildReplacement>[1];
|
|
350
|
+
hoist: boolean;
|
|
351
|
+
};
|
|
352
|
+
|
|
353
|
+
type ChainReplacement = {
|
|
354
|
+
expression: BabelTypes.Expression;
|
|
355
|
+
hoist: boolean;
|
|
356
|
+
};
|
|
357
|
+
|
|
358
|
+
function createChainReplacement(
|
|
359
|
+
args: ChainReplacementArgs,
|
|
360
|
+
): ChainReplacement | null {
|
|
361
|
+
if (!args.hoist || !shouldHoistReplacement(args.path)) {
|
|
362
|
+
const expression = buildReplacement(args.t, args.result, args.state);
|
|
363
|
+
return expression ? { expression, hoist: false } : null;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
const runtimeTokens = createRuntimeTokenCollector(args);
|
|
367
|
+
const hoistedExpression = buildReplacement(args.t, args.result, args.state, {
|
|
368
|
+
getRuntimeToken: runtimeTokens.add,
|
|
369
|
+
getTokenOverride: runtimeTokens.addOverride,
|
|
370
|
+
});
|
|
371
|
+
|
|
372
|
+
if (!hoistedExpression) return null;
|
|
373
|
+
|
|
374
|
+
const hoisted = args.path.scope.generateUidIdentifier('fluenticStyle');
|
|
375
|
+
args.state.hoistedDeclarations.push({
|
|
376
|
+
declaration: args.t.variableDeclaration('const', [
|
|
377
|
+
args.t.variableDeclarator(hoisted, hoistedExpression),
|
|
378
|
+
]),
|
|
379
|
+
dependencies: collectHoistDependencies(args.path, [args.path.node, hoistedExpression]),
|
|
380
|
+
});
|
|
381
|
+
|
|
382
|
+
if (!runtimeTokens.overrides.length) {
|
|
383
|
+
return {
|
|
384
|
+
expression: args.t.cloneNode(hoisted),
|
|
385
|
+
hoist: true,
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
args.state.usedHelpers.add(FN_WITH_TOKENS);
|
|
390
|
+
|
|
391
|
+
return {
|
|
392
|
+
expression: args.t.callExpression(args.t.identifier(FN_WITH_TOKENS), [
|
|
393
|
+
args.t.cloneNode(hoisted),
|
|
394
|
+
args.t.arrayExpression(runtimeTokens.overrides),
|
|
395
|
+
]),
|
|
396
|
+
hoist: true,
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
function shouldHoistReplacement(
|
|
401
|
+
path: BabelCore.NodePath<BabelTypes.CallExpression>,
|
|
402
|
+
): boolean {
|
|
403
|
+
return !!path.getFunctionParent();
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
function createRuntimeTokenCollector(
|
|
407
|
+
args: ChainReplacementArgs,
|
|
408
|
+
) {
|
|
409
|
+
const tokensByItem = new WeakMap<object, BabelTypes.Identifier>();
|
|
410
|
+
const overrides: BabelTypes.Expression[] = [];
|
|
411
|
+
|
|
412
|
+
return {
|
|
413
|
+
overrides,
|
|
414
|
+
addOverride(item: { valueNode: BabelTypes.Expression; }) {
|
|
415
|
+
overrides.push(args.t.cloneNode(item.valueNode));
|
|
416
|
+
},
|
|
417
|
+
add(item: object, valueNode: BabelTypes.Expression) {
|
|
418
|
+
if (canHoistRuntimeValue(args.path, valueNode)) {
|
|
419
|
+
return null;
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
const token = getRuntimeTokenIdentifier(args, tokensByItem, item);
|
|
423
|
+
|
|
424
|
+
overrides.push(
|
|
425
|
+
args.t.callExpression(args.t.cloneNode(token), [args.t.cloneNode(valueNode)]),
|
|
426
|
+
);
|
|
427
|
+
|
|
428
|
+
return args.t.cloneNode(token);
|
|
429
|
+
},
|
|
430
|
+
};
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
function canHoistRuntimeValue(
|
|
434
|
+
path: BabelCore.NodePath<BabelTypes.CallExpression>,
|
|
435
|
+
valueNode: BabelTypes.Expression,
|
|
436
|
+
): boolean {
|
|
437
|
+
return isHoistSafeRuntimeValueNode(path, valueNode);
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
function isHoistSafeRuntimeValueNode(
|
|
441
|
+
path: BabelCore.NodePath<BabelTypes.CallExpression>,
|
|
442
|
+
node: BabelTypes.Node | null | undefined,
|
|
443
|
+
): boolean {
|
|
444
|
+
if (!node) return false;
|
|
445
|
+
|
|
446
|
+
switch (node.type) {
|
|
447
|
+
case 'StringLiteral':
|
|
448
|
+
case 'NumericLiteral':
|
|
449
|
+
case 'BooleanLiteral':
|
|
450
|
+
case 'NullLiteral':
|
|
451
|
+
return true;
|
|
452
|
+
|
|
453
|
+
case 'Identifier':
|
|
454
|
+
return isImportBinding(path, node.name) || isProgramBinding(path, node.name);
|
|
455
|
+
|
|
456
|
+
case 'BinaryExpression':
|
|
457
|
+
case 'LogicalExpression':
|
|
458
|
+
return isHoistSafeRuntimeValueNode(path, node.left) &&
|
|
459
|
+
isHoistSafeRuntimeValueNode(path, node.right);
|
|
460
|
+
|
|
461
|
+
case 'TemplateLiteral':
|
|
462
|
+
return node.expressions.every((expr) => isHoistSafeRuntimeValueNode(path, expr as BabelTypes.Node));
|
|
463
|
+
|
|
464
|
+
case 'MemberExpression':
|
|
465
|
+
return isHoistSafeRuntimeValueNode(path, node.object) &&
|
|
466
|
+
(!node.computed || isHoistSafeRuntimeValueNode(path, node.property));
|
|
467
|
+
|
|
468
|
+
case 'ConditionalExpression':
|
|
469
|
+
return isHoistSafeRuntimeValueNode(path, node.test) &&
|
|
470
|
+
isHoistSafeRuntimeValueNode(path, node.consequent) &&
|
|
471
|
+
isHoistSafeRuntimeValueNode(path, node.alternate);
|
|
472
|
+
|
|
473
|
+
case 'UnaryExpression':
|
|
474
|
+
return isHoistSafeRuntimeValueNode(path, node.argument);
|
|
475
|
+
|
|
476
|
+
case 'ParenthesizedExpression':
|
|
477
|
+
case 'TSAsExpression':
|
|
478
|
+
case 'TSNonNullExpression':
|
|
479
|
+
case 'TSTypeAssertion':
|
|
480
|
+
return isHoistSafeRuntimeValueNode(path, (node as any).expression);
|
|
481
|
+
|
|
482
|
+
default:
|
|
483
|
+
return false;
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
function isImportBinding(
|
|
488
|
+
path: BabelCore.NodePath<BabelTypes.CallExpression>,
|
|
489
|
+
name: string,
|
|
490
|
+
): boolean {
|
|
491
|
+
const binding = path.scope.getBinding(name);
|
|
492
|
+
if (!binding) return false;
|
|
493
|
+
|
|
494
|
+
return binding.path.isImportSpecifier() ||
|
|
495
|
+
binding.path.isImportDefaultSpecifier() ||
|
|
496
|
+
binding.path.isImportNamespaceSpecifier();
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
function getRuntimeTokenIdentifier(
|
|
500
|
+
args: ChainReplacementArgs,
|
|
501
|
+
tokensByItem: WeakMap<object, BabelTypes.Identifier>,
|
|
502
|
+
item: object,
|
|
503
|
+
) {
|
|
504
|
+
const existing = tokensByItem.get(item);
|
|
505
|
+
if (existing) return existing;
|
|
506
|
+
|
|
507
|
+
const token = args.path.scope.generateUidIdentifier('fluenticToken');
|
|
508
|
+
const tokenIndex = args.state.runtimeTokenIndex++;
|
|
509
|
+
const tokenId = hashString(`${args.state.fileId}\nruntime:${tokenIndex}`);
|
|
510
|
+
|
|
511
|
+
tokensByItem.set(item, token);
|
|
512
|
+
args.state.usedHelpers.add(FN_CREATE_EXTRACTED_TOKEN);
|
|
513
|
+
args.state.hoistedDeclarations.push({
|
|
514
|
+
declaration: args.t.variableDeclaration('const', [
|
|
515
|
+
args.t.variableDeclarator(
|
|
516
|
+
token,
|
|
517
|
+
args.t.callExpression(args.t.identifier(FN_CREATE_EXTRACTED_TOKEN), [
|
|
518
|
+
args.t.stringLiteral(tokenId),
|
|
519
|
+
args.t.nullLiteral(),
|
|
520
|
+
]),
|
|
521
|
+
),
|
|
522
|
+
]),
|
|
523
|
+
dependencies: new Set(),
|
|
524
|
+
});
|
|
525
|
+
|
|
526
|
+
return token;
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
function collectHoistDependencies(
|
|
530
|
+
path: BabelCore.NodePath<BabelTypes.CallExpression>,
|
|
531
|
+
nodes: BabelTypes.Node[],
|
|
532
|
+
): Set<string> {
|
|
533
|
+
const dependencies = new Set<string>();
|
|
534
|
+
|
|
535
|
+
nodes.forEach((node) => {
|
|
536
|
+
collectProgramBindingIdentifiers(path, node, dependencies);
|
|
537
|
+
});
|
|
538
|
+
|
|
539
|
+
return dependencies;
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
function collectProgramBindingIdentifiers(
|
|
543
|
+
path: BabelCore.NodePath<BabelTypes.CallExpression>,
|
|
544
|
+
node: BabelTypes.Node | null | undefined,
|
|
545
|
+
dependencies: Set<string>,
|
|
546
|
+
) {
|
|
547
|
+
if (!node) return;
|
|
548
|
+
|
|
549
|
+
if (node.type === 'Identifier') {
|
|
550
|
+
if (isProgramBinding(path, node.name)) dependencies.add(node.name);
|
|
551
|
+
return;
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
if (node.type === 'MemberExpression') {
|
|
555
|
+
collectProgramBindingIdentifiers(path, node.object, dependencies);
|
|
556
|
+
if (node.computed) collectProgramBindingIdentifiers(path, node.property, dependencies);
|
|
557
|
+
return;
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
const visitorKeys = BabelCore.types.VISITOR_KEYS[node.type] ?? [];
|
|
561
|
+
visitorKeys.forEach((key) => {
|
|
562
|
+
const child = (node as unknown as Record<string, unknown>)[key];
|
|
563
|
+
if (Array.isArray(child)) {
|
|
564
|
+
child.forEach((item) => collectProgramBindingIdentifiers(path, item as BabelTypes.Node, dependencies));
|
|
565
|
+
} else {
|
|
566
|
+
collectProgramBindingIdentifiers(path, child as BabelTypes.Node, dependencies);
|
|
567
|
+
}
|
|
568
|
+
});
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
function isProgramBinding(
|
|
572
|
+
path: BabelCore.NodePath<BabelTypes.CallExpression>,
|
|
573
|
+
name: string,
|
|
574
|
+
): boolean {
|
|
575
|
+
const binding = path.scope.getBinding(name);
|
|
576
|
+
return binding?.scope.block.type === 'Program' &&
|
|
577
|
+
!binding.path.isImportSpecifier() &&
|
|
578
|
+
!binding.path.isImportDefaultSpecifier() &&
|
|
579
|
+
!binding.path.isImportNamespaceSpecifier();
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
function insertHoistedDeclarations(
|
|
583
|
+
path: BabelCore.NodePath<BabelTypes.Program>,
|
|
584
|
+
declarations: HoistedDeclaration[],
|
|
585
|
+
) {
|
|
586
|
+
if (!declarations.length) return;
|
|
587
|
+
|
|
588
|
+
const body = path.node.body;
|
|
589
|
+
let firstRuntimeIndex = 0;
|
|
590
|
+
|
|
591
|
+
while (firstRuntimeIndex < body.length && body[firstRuntimeIndex].type === 'ImportDeclaration') {
|
|
592
|
+
firstRuntimeIndex++;
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
declarations.forEach((item) => {
|
|
596
|
+
let insertIndex = firstRuntimeIndex;
|
|
597
|
+
|
|
598
|
+
item.dependencies.forEach((name) => {
|
|
599
|
+
const dependencyIndex = findTopLevelDeclarationIndex(body, name);
|
|
600
|
+
if (dependencyIndex >= insertIndex) {
|
|
601
|
+
insertIndex = dependencyIndex + 1;
|
|
602
|
+
}
|
|
603
|
+
});
|
|
604
|
+
|
|
605
|
+
body.splice(insertIndex, 0, item.declaration);
|
|
606
|
+
});
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
function findTopLevelDeclarationIndex(
|
|
610
|
+
body: BabelTypes.Program['body'],
|
|
611
|
+
name: string,
|
|
612
|
+
): number {
|
|
613
|
+
for (let i = 0; i < body.length; i++) {
|
|
614
|
+
if (statementDeclaresName(body[i], name)) return i;
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
return -1;
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
function statementDeclaresName(
|
|
621
|
+
statement: BabelTypes.Statement,
|
|
622
|
+
name: string,
|
|
623
|
+
): boolean {
|
|
624
|
+
if (statement.type === 'VariableDeclaration') {
|
|
625
|
+
return statement.declarations.some((decl) => bindingPatternDeclaresName(decl.id as BabelTypes.Node, name));
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
if (statement.type === 'ExportNamedDeclaration' && statement.declaration) {
|
|
629
|
+
return statementDeclaresName(statement.declaration, name);
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
if (statement.type === 'FunctionDeclaration' || statement.type === 'ClassDeclaration') {
|
|
633
|
+
return statement.id?.name === name;
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
return false;
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
function bindingPatternDeclaresName(
|
|
640
|
+
node: BabelTypes.Node,
|
|
641
|
+
name: string,
|
|
642
|
+
): boolean {
|
|
643
|
+
if (node.type === 'Identifier') return node.name === name;
|
|
644
|
+
|
|
645
|
+
if (node.type === 'ObjectPattern') {
|
|
646
|
+
return node.properties.some((prop) => {
|
|
647
|
+
if (prop.type === 'RestElement') return bindingPatternDeclaresName(prop.argument as BabelTypes.Node, name);
|
|
648
|
+
return bindingPatternDeclaresName(prop.value as BabelTypes.Node, name);
|
|
649
|
+
});
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
if (node.type === 'ArrayPattern') {
|
|
653
|
+
return node.elements.some((element) => !!element && bindingPatternDeclaresName(element as BabelTypes.Node, name));
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
if (node.type === 'AssignmentPattern') {
|
|
657
|
+
return bindingPatternDeclaresName(node.left, name);
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
if (node.type === 'RestElement') {
|
|
661
|
+
return bindingPatternDeclaresName(node.argument, name);
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
return false;
|
|
665
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { CompilerInternal, TransformExtractArgs, TransformExtractResult } from '../../compiler';
|
|
2
|
+
import type { CompilerCssCollector } from '../../extract';
|
|
3
|
+
import { babelTransform } from '../utils/babel';
|
|
4
|
+
import { createExtractPlugin, type ExtractTracer } from './plugin';
|
|
5
|
+
|
|
6
|
+
export type TransformExtractDeps = {
|
|
7
|
+
collector: CompilerCssCollector;
|
|
8
|
+
mode?: 'extract' | 'collect';
|
|
9
|
+
styleFilePath?: string;
|
|
10
|
+
tracer: ExtractTracer;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export function transformExtract(
|
|
14
|
+
internal: CompilerInternal,
|
|
15
|
+
args: TransformExtractArgs,
|
|
16
|
+
deps: TransformExtractDeps,
|
|
17
|
+
): TransformExtractResult | null {
|
|
18
|
+
const { collector, tracer } = deps;
|
|
19
|
+
|
|
20
|
+
const plugin = createExtractPlugin({
|
|
21
|
+
options: internal.options,
|
|
22
|
+
collector: collector,
|
|
23
|
+
mode: deps.mode,
|
|
24
|
+
projectDir: internal.projectDir,
|
|
25
|
+
runtimeMode: internal.runtimeMode,
|
|
26
|
+
styleFilePath: deps.styleFilePath,
|
|
27
|
+
tracer: tracer,
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const result = babelTransform({
|
|
31
|
+
code: args.code,
|
|
32
|
+
filePath: args.filePath,
|
|
33
|
+
sourcemap: args.sourcemap,
|
|
34
|
+
plugins: [plugin],
|
|
35
|
+
errorLabel: '[style] compiler error',
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
if (!result) return null;
|
|
39
|
+
|
|
40
|
+
return {
|
|
41
|
+
code: result.code,
|
|
42
|
+
rules: collector.getItems(),
|
|
43
|
+
sourcemap: result.sourcemap,
|
|
44
|
+
};
|
|
45
|
+
}
|