@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,86 @@
|
|
|
1
|
+
import { getThemeRuleCss } from '../../../../atomic/theme';
|
|
2
|
+
import { CSS_CONFIG } from '../../../../config/config/css';
|
|
3
|
+
import { isStyleTokenOverrideData, type StyleTokenOverride } from '../../../../style/token';
|
|
4
|
+
import type { CompilerOptions } from '../../../compiler/types';
|
|
5
|
+
import type { CssExtractRule } from '../../../extract/types';
|
|
6
|
+
import { FN_CREATE_THEME, IMPORT_PATHS } from '../../../utils/constants';
|
|
7
|
+
import { evaluateNode } from '../../evaluator/evaluator';
|
|
8
|
+
import { getStableThemeClassName, getStableThemeId } from '../../syntax/static_ids';
|
|
9
|
+
import type { BabelTypes, NodePath } from '../../utils/babel';
|
|
10
|
+
import { type ExtractPluginState, getEvalScope } from './state';
|
|
11
|
+
|
|
12
|
+
export function compileThemeCall(
|
|
13
|
+
path: NodePath<BabelTypes.CallExpression>,
|
|
14
|
+
state: ExtractPluginState,
|
|
15
|
+
opts: CompilerOptions,
|
|
16
|
+
): { id: string; className: string; rule: CssExtractRule; } | null {
|
|
17
|
+
const callee = path.node.callee;
|
|
18
|
+
if (callee.type !== 'Identifier') return null;
|
|
19
|
+
|
|
20
|
+
const imp = state.imports.get(callee.name);
|
|
21
|
+
|
|
22
|
+
if (!imp || !IMPORT_PATHS.includes(imp.source) || imp.name !== FN_CREATE_THEME) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const scope = getEvalScope(state);
|
|
27
|
+
const tokenArg = evaluateNode(path.node.arguments[0] as BabelTypes.Node, scope);
|
|
28
|
+
|
|
29
|
+
if (!tokenArg.ok) {
|
|
30
|
+
throw path.buildCodeFrameError(`createTheme tokens must be statically analyzable: ${tokenArg.reason}`);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (!Array.isArray(tokenArg.value)) {
|
|
34
|
+
throw path.buildCodeFrameError('createTheme first argument must be a static array of token overrides.');
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const debugIdArg = evaluateNode(path.node.arguments[1] as BabelTypes.Node, scope);
|
|
38
|
+
|
|
39
|
+
if (path.node.arguments[1] && !debugIdArg.ok) {
|
|
40
|
+
throw path.buildCodeFrameError(`createTheme debugId must be statically analyzable: ${debugIdArg.reason}`);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const tokens: StyleTokenOverride[] = [];
|
|
44
|
+
|
|
45
|
+
for (let i = 0, len = tokenArg.value.length; i < len; i++) {
|
|
46
|
+
const token = tokenArg.value[i];
|
|
47
|
+
|
|
48
|
+
if (!isStyleTokenOverrideData(token)) {
|
|
49
|
+
throw path.buildCodeFrameError(`createTheme token at index ${i} must be a token override, e.g. token(value).`);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
tokens.push(token);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const loc = path.node.loc?.start;
|
|
56
|
+
|
|
57
|
+
const debugId = debugIdArg.ok && debugIdArg.value !== undefined
|
|
58
|
+
? String(debugIdArg.value)
|
|
59
|
+
: getStableThemeId(state.fileId, loc ? loc.line + ':' + loc.column : 'createTheme');
|
|
60
|
+
|
|
61
|
+
const id = debugId;
|
|
62
|
+
|
|
63
|
+
const themeNameFormat = opts.css?.themeNameFormat || CSS_CONFIG.themeNameFormat || null;
|
|
64
|
+
|
|
65
|
+
const className = getStableThemeClassName(
|
|
66
|
+
id,
|
|
67
|
+
themeNameFormat,
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
const css = getThemeRuleCss(
|
|
71
|
+
className,
|
|
72
|
+
tokens,
|
|
73
|
+
themeNameFormat,
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
return {
|
|
77
|
+
id,
|
|
78
|
+
className,
|
|
79
|
+
rule: {
|
|
80
|
+
dedupe: className,
|
|
81
|
+
className,
|
|
82
|
+
css,
|
|
83
|
+
priority: [0, 0, 0, 0, 0, 0, 0],
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { annotateTokenDeclaration } from '../../syntax/static_ids';
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { FN_STYLE_VALUE } from '../../utils/constants';
|
|
2
|
+
import type { BabelTypes } from '../utils/babel';
|
|
3
|
+
|
|
4
|
+
export function isStaticStyleValue(value: BabelTypes.Node): boolean {
|
|
5
|
+
if (
|
|
6
|
+
value.type === 'StringLiteral' ||
|
|
7
|
+
value.type === 'NumericLiteral' ||
|
|
8
|
+
value.type === 'BooleanLiteral' ||
|
|
9
|
+
value.type === 'NullLiteral'
|
|
10
|
+
) {
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
if (value.type === 'TemplateLiteral') {
|
|
15
|
+
return value.expressions.length === 0;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (value.type === 'ArrayExpression') {
|
|
19
|
+
const [priority, itemValue] = value.elements;
|
|
20
|
+
|
|
21
|
+
return !!priority && priority.type === 'NumericLiteral' &&
|
|
22
|
+
!!itemValue && isStaticStyleValue(itemValue);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (
|
|
26
|
+
value.type === 'CallExpression' &&
|
|
27
|
+
value.callee.type === 'MemberExpression' &&
|
|
28
|
+
!value.callee.computed &&
|
|
29
|
+
value.callee.property.type === 'Identifier' &&
|
|
30
|
+
value.callee.property.name === FN_STYLE_VALUE
|
|
31
|
+
) {
|
|
32
|
+
const [itemValue, weight] = value.arguments;
|
|
33
|
+
|
|
34
|
+
return !!itemValue && itemValue.type !== 'SpreadElement' &&
|
|
35
|
+
isStaticStyleValue(itemValue) &&
|
|
36
|
+
!!weight && weight.type === 'NumericLiteral';
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (value.type === 'UnaryExpression') {
|
|
40
|
+
return isStaticStyleValue(value.argument);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Callee } from './types';
|
|
2
|
+
|
|
3
|
+
export function isStyleChainCall(
|
|
4
|
+
callee: Callee,
|
|
5
|
+
styleNames: Set<string>,
|
|
6
|
+
): boolean {
|
|
7
|
+
if (callee.type === 'Identifier') return styleNames.has(callee.name);
|
|
8
|
+
if (callee.type !== 'MemberExpression' || callee.computed) return false;
|
|
9
|
+
|
|
10
|
+
const object = callee.object;
|
|
11
|
+
if (object.type === 'Identifier') return styleNames.has(object.name);
|
|
12
|
+
if (object.type === 'CallExpression') return isStyleChainCall(object.callee, styleNames);
|
|
13
|
+
if (object.type === 'MemberExpression') return isStyleChainCall(object, styleNames);
|
|
14
|
+
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
import { createThemeClassName } from '../../../atomic/theme';
|
|
2
|
+
import { sanitizeCssIdentName } from '../../../atomic/utils/css';
|
|
3
|
+
import type { ThemeNameFormat } from '../../../config/types';
|
|
4
|
+
import { hashString } from '../../../utils/hash';
|
|
5
|
+
import {
|
|
6
|
+
FN_CREATE_COUNTER_STYLE,
|
|
7
|
+
FN_CREATE_FONT_FACE,
|
|
8
|
+
FN_CREATE_FONT_PALETTE_VALUES,
|
|
9
|
+
FN_CREATE_KEYFRAMES,
|
|
10
|
+
FN_CREATE_POSITION_TRY,
|
|
11
|
+
FN_CREATE_THEME,
|
|
12
|
+
FN_CREATE_TOKEN,
|
|
13
|
+
FN_CREATE_TOKENS,
|
|
14
|
+
FN_CREATE_VALUES,
|
|
15
|
+
FN_STYLE_KEYFRAMES,
|
|
16
|
+
IMPORT_PATHS,
|
|
17
|
+
} from '../../utils/constants';
|
|
18
|
+
import type { BabelTypes } from '../utils/babel';
|
|
19
|
+
import { getObjectPropertyKey } from './utils';
|
|
20
|
+
|
|
21
|
+
export type StaticIdImport = {
|
|
22
|
+
source: string;
|
|
23
|
+
name: string;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export type StaticIdState = {
|
|
27
|
+
fileId: string;
|
|
28
|
+
imports: Map<string, StaticIdImport>;
|
|
29
|
+
styleNames?: Set<string>;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export function annotateTokenDeclaration(
|
|
33
|
+
decl: BabelTypes.VariableDeclarator,
|
|
34
|
+
state: StaticIdState,
|
|
35
|
+
t: typeof BabelTypes,
|
|
36
|
+
) {
|
|
37
|
+
if (decl.id.type !== 'Identifier' || !decl.init) return;
|
|
38
|
+
|
|
39
|
+
annotateTokenExpression(decl.init, decl.id.name, state, t);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function annotateAtRuleDeclaration(
|
|
43
|
+
decl: BabelTypes.VariableDeclarator,
|
|
44
|
+
state: StaticIdState,
|
|
45
|
+
t: typeof BabelTypes,
|
|
46
|
+
) {
|
|
47
|
+
if (decl.id.type !== 'Identifier' || !decl.init) return;
|
|
48
|
+
|
|
49
|
+
annotateAtRuleExpression(decl.init, decl.id.name, state, t);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function annotateThemeCall(
|
|
53
|
+
node: BabelTypes.CallExpression,
|
|
54
|
+
state: StaticIdState,
|
|
55
|
+
t: typeof BabelTypes,
|
|
56
|
+
) {
|
|
57
|
+
if (node.callee.type !== 'Identifier') return;
|
|
58
|
+
|
|
59
|
+
const imp = state.imports.get(node.callee.name);
|
|
60
|
+
|
|
61
|
+
if (!imp || !IMPORT_PATHS.includes(imp.source) || imp.name !== FN_CREATE_THEME) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const loc = node.loc?.start;
|
|
66
|
+
const locId = loc ? loc.line + ':' + loc.column : 'createTheme';
|
|
67
|
+
setStringArgWithStableId(
|
|
68
|
+
node,
|
|
69
|
+
1,
|
|
70
|
+
getStableThemeId(state.fileId, locId),
|
|
71
|
+
state.fileId,
|
|
72
|
+
locId,
|
|
73
|
+
t,
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function getStableThemeId(fileId: string, locId: string) {
|
|
78
|
+
return hashString(fileId + '\n' + locId);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export function getStableThemeClassName(
|
|
82
|
+
id: string,
|
|
83
|
+
themeNameFormat: ThemeNameFormat | null,
|
|
84
|
+
) {
|
|
85
|
+
return createThemeClassName(id, id, themeNameFormat);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function annotateTokenExpression(
|
|
89
|
+
node: BabelTypes.Node,
|
|
90
|
+
pathName: string,
|
|
91
|
+
state: StaticIdState,
|
|
92
|
+
t: typeof BabelTypes,
|
|
93
|
+
) {
|
|
94
|
+
if (node.type === 'CallExpression') {
|
|
95
|
+
annotateTokenFactoryCall(node, pathName, state, t);
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (node.type !== 'ObjectExpression') return;
|
|
100
|
+
|
|
101
|
+
for (const prop of node.properties) {
|
|
102
|
+
if (prop.type !== 'ObjectProperty' || prop.computed) continue;
|
|
103
|
+
|
|
104
|
+
const key = getObjectPropertyKey(prop);
|
|
105
|
+
if (!key) continue;
|
|
106
|
+
|
|
107
|
+
annotateTokenExpression(prop.value as BabelTypes.Node, pathName + '.' + key, state, t);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function annotateAtRuleExpression(
|
|
112
|
+
node: BabelTypes.Node,
|
|
113
|
+
pathName: string,
|
|
114
|
+
state: StaticIdState,
|
|
115
|
+
t: typeof BabelTypes,
|
|
116
|
+
) {
|
|
117
|
+
if (node.type === 'CallExpression') {
|
|
118
|
+
annotateAtRuleFactoryCall(node, pathName, state, t);
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (node.type !== 'ObjectExpression') return;
|
|
123
|
+
|
|
124
|
+
for (const prop of node.properties) {
|
|
125
|
+
if (prop.type !== 'ObjectProperty' || prop.computed) continue;
|
|
126
|
+
|
|
127
|
+
const key = getObjectPropertyKey(prop);
|
|
128
|
+
if (!key) continue;
|
|
129
|
+
|
|
130
|
+
annotateAtRuleExpression(prop.value as BabelTypes.Node, pathName + '.' + key, state, t);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function annotateAtRuleFactoryCall(
|
|
135
|
+
node: BabelTypes.CallExpression,
|
|
136
|
+
pathName: string,
|
|
137
|
+
state: StaticIdState,
|
|
138
|
+
t: typeof BabelTypes,
|
|
139
|
+
) {
|
|
140
|
+
if (
|
|
141
|
+
node.callee.type === 'MemberExpression' &&
|
|
142
|
+
!node.callee.computed &&
|
|
143
|
+
node.callee.object.type === 'Identifier' &&
|
|
144
|
+
state.styleNames?.has(node.callee.object.name) &&
|
|
145
|
+
node.callee.property.type === 'Identifier' &&
|
|
146
|
+
node.callee.property.name === FN_STYLE_KEYFRAMES
|
|
147
|
+
) {
|
|
148
|
+
setAtRuleArgWithStableId(node, 1, state.fileId, pathName, t);
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
if (node.callee.type !== 'Identifier') return;
|
|
153
|
+
|
|
154
|
+
const imp = state.imports.get(node.callee.name);
|
|
155
|
+
if (!imp || !IMPORT_PATHS.includes(imp.source)) return;
|
|
156
|
+
if (!AT_RULE_FACTORY_NAMES.has(imp.name)) return;
|
|
157
|
+
|
|
158
|
+
setAtRuleArgWithStableId(node, 1, state.fileId, pathName, t);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const AT_RULE_FACTORY_NAMES = new Set([
|
|
162
|
+
FN_CREATE_COUNTER_STYLE,
|
|
163
|
+
FN_CREATE_FONT_FACE,
|
|
164
|
+
FN_CREATE_FONT_PALETTE_VALUES,
|
|
165
|
+
FN_CREATE_KEYFRAMES,
|
|
166
|
+
FN_CREATE_POSITION_TRY,
|
|
167
|
+
]);
|
|
168
|
+
|
|
169
|
+
function annotateTokenFactoryCall(
|
|
170
|
+
node: BabelTypes.CallExpression,
|
|
171
|
+
pathName: string,
|
|
172
|
+
state: StaticIdState,
|
|
173
|
+
t: typeof BabelTypes,
|
|
174
|
+
) {
|
|
175
|
+
if (node.callee.type !== 'Identifier') return;
|
|
176
|
+
|
|
177
|
+
const imp = state.imports.get(node.callee.name);
|
|
178
|
+
if (!imp || !IMPORT_PATHS.includes(imp.source)) return;
|
|
179
|
+
|
|
180
|
+
if (imp.name === FN_CREATE_TOKEN) {
|
|
181
|
+
setStringArgWithStableId(node, 1, getStableTokenId(state.fileId, pathName), state.fileId, pathName, t);
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
if (imp.name === FN_CREATE_TOKENS) {
|
|
186
|
+
setStringArgWithStableId(node, 1, getStableTokenId(state.fileId, pathName), state.fileId, pathName, t);
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
if (imp.name === FN_CREATE_VALUES) {
|
|
191
|
+
const hasNumberArg = node.arguments[0]?.type === 'Identifier' &&
|
|
192
|
+
(node.arguments[0] as BabelTypes.Identifier).name === 'Number';
|
|
193
|
+
setStringArgWithStableId(
|
|
194
|
+
node,
|
|
195
|
+
hasNumberArg ? 2 : 1,
|
|
196
|
+
getStableTokenId(state.fileId, pathName),
|
|
197
|
+
state.fileId,
|
|
198
|
+
pathName,
|
|
199
|
+
t,
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
function setStringArgWithStableId(
|
|
205
|
+
node: BabelTypes.CallExpression,
|
|
206
|
+
index: number,
|
|
207
|
+
value: string,
|
|
208
|
+
fileId: string,
|
|
209
|
+
pathName: string,
|
|
210
|
+
t: typeof BabelTypes,
|
|
211
|
+
) {
|
|
212
|
+
const existing = node.arguments[index];
|
|
213
|
+
|
|
214
|
+
if (existing) {
|
|
215
|
+
if (existing.type === 'StringLiteral') {
|
|
216
|
+
node.arguments[index] = t.stringLiteral(getStableDebugId(existing.value, fileId, pathName));
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
while (node.arguments.length < index) {
|
|
223
|
+
node.arguments.push(t.identifier('undefined'));
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
node.arguments.push(t.stringLiteral(value));
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
function setAtRuleArgWithStableId(
|
|
230
|
+
node: BabelTypes.CallExpression,
|
|
231
|
+
index: number,
|
|
232
|
+
fileId: string,
|
|
233
|
+
pathName: string,
|
|
234
|
+
t: typeof BabelTypes,
|
|
235
|
+
) {
|
|
236
|
+
const existing = node.arguments[index];
|
|
237
|
+
const id = fileId + '\n' + pathName;
|
|
238
|
+
|
|
239
|
+
if (existing) {
|
|
240
|
+
if (existing.type === 'StringLiteral') {
|
|
241
|
+
node.arguments[index] = createStableIdObject(sanitizeTokenId(existing.value), id, t);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
while (node.arguments.length < index) {
|
|
248
|
+
node.arguments.push(t.identifier('undefined'));
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
node.arguments.push(createStableIdObject(sanitizeTokenId(pathName), id, t));
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
function createStableIdObject(
|
|
255
|
+
name: string | null,
|
|
256
|
+
id: string,
|
|
257
|
+
t: typeof BabelTypes,
|
|
258
|
+
) {
|
|
259
|
+
return t.objectExpression([
|
|
260
|
+
t.objectProperty(t.identifier('name'), name === null ? t.nullLiteral() : t.stringLiteral(name)),
|
|
261
|
+
t.objectProperty(t.identifier('id'), t.stringLiteral(id)),
|
|
262
|
+
]);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
function getStableTokenId(
|
|
266
|
+
fileId: string,
|
|
267
|
+
pathName: string,
|
|
268
|
+
) {
|
|
269
|
+
return sanitizeTokenId(pathName) + '-' + hashString(fileId + '\n' + pathName);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
function getStableDebugId(
|
|
273
|
+
debugId: string,
|
|
274
|
+
fileId: string,
|
|
275
|
+
pathName: string,
|
|
276
|
+
) {
|
|
277
|
+
return sanitizeTokenId(debugId) + '-' + hashString(fileId + '\n' + pathName);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
function sanitizeTokenId(value: string) {
|
|
281
|
+
return sanitizeCssIdentName(value, 'token');
|
|
282
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { BabelTypes } from '../utils/babel';
|
|
2
|
+
import type { Callee } from './types';
|
|
3
|
+
|
|
4
|
+
export function getCallLabel(callee: Callee): string {
|
|
5
|
+
if (callee.type === 'Identifier') return callee.name;
|
|
6
|
+
if (callee.type === 'MemberExpression') {
|
|
7
|
+
const key = callee.property.type === 'Identifier'
|
|
8
|
+
? callee.property.name
|
|
9
|
+
: callee.property.type === 'StringLiteral'
|
|
10
|
+
? callee.property.value
|
|
11
|
+
: '';
|
|
12
|
+
|
|
13
|
+
return key ? `style.${key}` : 'style';
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return 'style';
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function getObjectPropertyKey(node: BabelTypes.ObjectProperty) {
|
|
20
|
+
if (node.computed) return null;
|
|
21
|
+
if (node.key.type === 'Identifier') return node.key.name;
|
|
22
|
+
if (node.key.type === 'StringLiteral') return node.key.value;
|
|
23
|
+
if (node.key.type === 'NumericLiteral') return String(node.key.value);
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function getImportedName(spec: BabelTypes.ImportSpecifier) {
|
|
28
|
+
return spec.imported.type === 'Identifier'
|
|
29
|
+
? spec.imported.name
|
|
30
|
+
: spec.imported.value;
|
|
31
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import * as BabelCore from '@babel/core';
|
|
2
|
+
|
|
3
|
+
export { BabelCore };
|
|
4
|
+
export type { NodePath, types as BabelTypes } from '@babel/core';
|
|
5
|
+
|
|
6
|
+
export type BabelTransformArgs = {
|
|
7
|
+
code: string;
|
|
8
|
+
sourcemap?: BabelTransformSourceMap;
|
|
9
|
+
filePath?: string;
|
|
10
|
+
plugins: BabelTransformPlugins;
|
|
11
|
+
retainLines?: boolean;
|
|
12
|
+
errorLabel?: string;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export type BabelTransformResult = {
|
|
16
|
+
code: string;
|
|
17
|
+
sourcemap: string | null;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export type BabelTransformPlugins = NonNullable<
|
|
21
|
+
BabelCore.TransformOptions['plugins']
|
|
22
|
+
>;
|
|
23
|
+
|
|
24
|
+
export type BabelTransformInputSourceMap = NonNullable<BabelCore.TransformOptions['inputSourceMap']>;
|
|
25
|
+
|
|
26
|
+
export type BabelTransformSourceMap =
|
|
27
|
+
| BabelTransformInputSourceMap
|
|
28
|
+
| string
|
|
29
|
+
| null;
|
|
30
|
+
|
|
31
|
+
export function babelPlugin<State extends BabelCore.PluginPass>(
|
|
32
|
+
factory: (api: typeof BabelCore) => BabelCore.PluginObj<State>,
|
|
33
|
+
) {
|
|
34
|
+
return factory;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function babelTransform(args: BabelTransformArgs): BabelTransformResult | null {
|
|
38
|
+
let result: babel.BabelFileResult | null = null;
|
|
39
|
+
|
|
40
|
+
try {
|
|
41
|
+
const inputSourceMap = parseInputSourceMap(args.sourcemap);
|
|
42
|
+
|
|
43
|
+
result = BabelCore.transformSync(args.code, {
|
|
44
|
+
...babelTransformOptions(),
|
|
45
|
+
inputSourceMap,
|
|
46
|
+
filename: args.filePath,
|
|
47
|
+
sourceFileName: args.filePath,
|
|
48
|
+
plugins: args.plugins,
|
|
49
|
+
sourceMaps: true,
|
|
50
|
+
generatorOpts: {
|
|
51
|
+
retainLines: args.retainLines ?? false,
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
} catch (err: unknown) {
|
|
55
|
+
if (!args.errorLabel) throw err;
|
|
56
|
+
|
|
57
|
+
const message = getBabelError(err, args);
|
|
58
|
+
const error = new Error(message);
|
|
59
|
+
error.stack = undefined;
|
|
60
|
+
throw error;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (!result || !result.code) return null;
|
|
64
|
+
|
|
65
|
+
return {
|
|
66
|
+
code: result.code,
|
|
67
|
+
sourcemap: result.map ? JSON.stringify(result.map) : null,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function babelTransformOptions(): BabelCore.TransformOptions {
|
|
72
|
+
return {
|
|
73
|
+
configFile: false,
|
|
74
|
+
babelrc: false,
|
|
75
|
+
parserOpts: {
|
|
76
|
+
plugins: ['typescript', 'jsx'],
|
|
77
|
+
strictMode: false,
|
|
78
|
+
allowImportExportEverywhere: true,
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function parseInputSourceMap(sourcemap: BabelTransformSourceMap | undefined) {
|
|
84
|
+
if (!sourcemap) return undefined;
|
|
85
|
+
if (typeof sourcemap !== 'string') return sourcemap;
|
|
86
|
+
|
|
87
|
+
return JSON.parse(sourcemap) as Exclude<
|
|
88
|
+
BabelTransformInputSourceMap,
|
|
89
|
+
boolean | undefined
|
|
90
|
+
>;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function getBabelError(err: unknown, args: BabelTransformArgs) {
|
|
94
|
+
const babelErr = err as (Error & { codeFrame?: string; }) | null;
|
|
95
|
+
const msg = babelErr instanceof Error ? babelErr.message : String(err);
|
|
96
|
+
const codeFrame = babelErr?.codeFrame;
|
|
97
|
+
const suffix = codeFrame ? `\n\n${codeFrame}` : '';
|
|
98
|
+
|
|
99
|
+
return `${args.errorLabel} in ${args.filePath}:\n${msg}${suffix}`;
|
|
100
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { babelPlugin, babelTransform, type BabelTypes } from './babel';
|
|
2
|
+
|
|
3
|
+
export type RewriteImportSource = (source: string) => string | null | undefined;
|
|
4
|
+
|
|
5
|
+
export function rewriteImportSources(
|
|
6
|
+
code: string,
|
|
7
|
+
rewriteSource: RewriteImportSource,
|
|
8
|
+
) {
|
|
9
|
+
const result = babelTransform({
|
|
10
|
+
code,
|
|
11
|
+
retainLines: true,
|
|
12
|
+
sourcemap: null,
|
|
13
|
+
plugins: [createPlugin(rewriteSource)],
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
return result?.code ?? code;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function createPlugin(rewriteSource: RewriteImportSource) {
|
|
20
|
+
const rewrite = (source: BabelTypes.StringLiteral) => {
|
|
21
|
+
const nextSource = rewriteSource(source.value);
|
|
22
|
+
|
|
23
|
+
if (nextSource && nextSource !== source.value) {
|
|
24
|
+
source.value = nextSource;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
return babelPlugin((babel) => {
|
|
29
|
+
const { types: t } = babel;
|
|
30
|
+
|
|
31
|
+
return {
|
|
32
|
+
visitor: {
|
|
33
|
+
ImportDeclaration(path) {
|
|
34
|
+
rewrite(path.node.source);
|
|
35
|
+
},
|
|
36
|
+
ExportAllDeclaration(path) {
|
|
37
|
+
rewrite(path.node.source);
|
|
38
|
+
},
|
|
39
|
+
ExportNamedDeclaration(path) {
|
|
40
|
+
if (t.isStringLiteral(path.node.source)) {
|
|
41
|
+
rewrite(path.node.source);
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
});
|
|
47
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { getRelativePath, isAbsolutePath, normalizePath } from '../../utils/path';
|
|
2
|
+
|
|
3
|
+
export function getProjectFileId(projectDir: string, filePath: string | null | undefined) {
|
|
4
|
+
if (!filePath) return 'unknown';
|
|
5
|
+
|
|
6
|
+
const relativePath = getRelativePath(projectDir, filePath);
|
|
7
|
+
|
|
8
|
+
if (relativePath && !isAbsolutePath(relativePath)) {
|
|
9
|
+
filePath = relativePath;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return normalizePath(filePath);
|
|
13
|
+
}
|