@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,67 @@
|
|
|
1
|
+
import { DEFAULT_TRANSFORM_INCLUDE_PATTERN } from '../../utils';
|
|
2
|
+
import { createFileCssContentHash } from '../../utils/cache';
|
|
3
|
+
import { parseBundlerSourceMap } from '../../utils/sourcemap';
|
|
4
|
+
import {
|
|
5
|
+
createParcelError,
|
|
6
|
+
ensureParcelSidecarStarted,
|
|
7
|
+
getParcelState,
|
|
8
|
+
isParcelGeneratedRuntimeFile,
|
|
9
|
+
prependParcelRuntimeImport,
|
|
10
|
+
replaceParcelDefines,
|
|
11
|
+
Transformer,
|
|
12
|
+
writeParcelCssFile,
|
|
13
|
+
} from './shared';
|
|
14
|
+
|
|
15
|
+
const TRANSFORM_INCLUDE_REGEX = new RegExp(DEFAULT_TRANSFORM_INCLUDE_PATTERN);
|
|
16
|
+
|
|
17
|
+
export default new Transformer({
|
|
18
|
+
async transform({ asset, options }: any) {
|
|
19
|
+
const current = getParcelState(options);
|
|
20
|
+
await ensureParcelSidecarStarted(current);
|
|
21
|
+
|
|
22
|
+
const code = await asset.getCode();
|
|
23
|
+
const filePath = asset.filePath;
|
|
24
|
+
const maybeMap = await asset.getMap();
|
|
25
|
+
const sourcemap = maybeMap?.toVLQ ? maybeMap.toVLQ() : maybeMap;
|
|
26
|
+
|
|
27
|
+
let nextCode = code;
|
|
28
|
+
|
|
29
|
+
if (TRANSFORM_INCLUDE_REGEX.test(filePath)) {
|
|
30
|
+
try {
|
|
31
|
+
const result = current.transform(
|
|
32
|
+
code,
|
|
33
|
+
filePath,
|
|
34
|
+
parseBundlerSourceMap(toSourceMapString(sourcemap)),
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
if (result) {
|
|
38
|
+
const rules = Array.isArray(result.rules) ? result.rules : [];
|
|
39
|
+
|
|
40
|
+
nextCode = result.code;
|
|
41
|
+
current.cssCache.setFileCss({
|
|
42
|
+
filePath,
|
|
43
|
+
contentHash: createFileCssContentHash(code),
|
|
44
|
+
configHash: current.cssConfigHash,
|
|
45
|
+
rules,
|
|
46
|
+
});
|
|
47
|
+
writeParcelCssFile(current);
|
|
48
|
+
}
|
|
49
|
+
} catch (error) {
|
|
50
|
+
throw createParcelError(error);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
nextCode = replaceParcelDefines(nextCode, current);
|
|
55
|
+
if (!isParcelGeneratedRuntimeFile(current, filePath)) {
|
|
56
|
+
nextCode = prependParcelRuntimeImport(nextCode, current, filePath);
|
|
57
|
+
}
|
|
58
|
+
asset.setCode(nextCode);
|
|
59
|
+
|
|
60
|
+
return [asset];
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
function toSourceMapString(map: unknown) {
|
|
65
|
+
if (!map) return null;
|
|
66
|
+
return typeof map === 'string' ? map : JSON.stringify(map);
|
|
67
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './plugin';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { plugin as webpackPlugin } from '../webpack';
|
|
2
|
+
import type { PluginOptions } from '../webpack';
|
|
3
|
+
|
|
4
|
+
export type { PluginOptions };
|
|
5
|
+
|
|
6
|
+
export default plugin;
|
|
7
|
+
|
|
8
|
+
export function plugin(options: PluginOptions = {}) {
|
|
9
|
+
return {
|
|
10
|
+
apply(compiler: unknown) {
|
|
11
|
+
webpackPlugin(options).apply(compiler as never);
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './plugin';
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import type { Plugin } from 'vite';
|
|
2
|
+
import {
|
|
3
|
+
invalidateFiles,
|
|
4
|
+
PLUGIN_NAME,
|
|
5
|
+
type PluginCssOptions,
|
|
6
|
+
type PluginOptions,
|
|
7
|
+
transformCssOutput,
|
|
8
|
+
} from '../../utils';
|
|
9
|
+
import { hasCssMarker, replaceCssMarker } from '../../utils/cssMarker';
|
|
10
|
+
import { formatError } from '../../utils/misc';
|
|
11
|
+
import { getVirtualModuleId, RESOLVED_RUNTIME_MODULE_ID } from '../../utils/virtual';
|
|
12
|
+
import { createVitePluginState } from './state';
|
|
13
|
+
|
|
14
|
+
export type { PluginCssOptions, PluginOptions };
|
|
15
|
+
|
|
16
|
+
type CssAsset = {
|
|
17
|
+
source: string;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export default plugin;
|
|
21
|
+
|
|
22
|
+
export function plugin(options: PluginOptions = {}): Plugin {
|
|
23
|
+
const state = createVitePluginState(options);
|
|
24
|
+
|
|
25
|
+
return {
|
|
26
|
+
name: PLUGIN_NAME,
|
|
27
|
+
enforce: 'pre',
|
|
28
|
+
|
|
29
|
+
async config(config, env) {
|
|
30
|
+
return state.getConfig(config, env);
|
|
31
|
+
},
|
|
32
|
+
|
|
33
|
+
configResolved(resolvedConfig) {
|
|
34
|
+
state.setConfig(resolvedConfig);
|
|
35
|
+
},
|
|
36
|
+
|
|
37
|
+
async buildStart() {
|
|
38
|
+
state.getState();
|
|
39
|
+
await state.ensureSidecarStarted();
|
|
40
|
+
},
|
|
41
|
+
|
|
42
|
+
resolveId(id) {
|
|
43
|
+
return getVirtualModuleId(id);
|
|
44
|
+
},
|
|
45
|
+
|
|
46
|
+
load(id) {
|
|
47
|
+
if (getVirtualModuleId(id) === RESOLVED_RUNTIME_MODULE_ID) {
|
|
48
|
+
return state.loadRuntimeModule();
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
|
|
52
|
+
handleHotUpdate(ctx) {
|
|
53
|
+
const current = state.getCurrentState();
|
|
54
|
+
if (!current) return;
|
|
55
|
+
|
|
56
|
+
invalidateFiles(current.compiler, [ctx.file]);
|
|
57
|
+
current.filter.clear();
|
|
58
|
+
},
|
|
59
|
+
|
|
60
|
+
transformIndexHtml: {
|
|
61
|
+
order: 'pre',
|
|
62
|
+
handler() {
|
|
63
|
+
return state.getHtmlEntryScript();
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
|
|
67
|
+
async transform(code, id) {
|
|
68
|
+
const current = state.getState();
|
|
69
|
+
await state.ensureSidecarStarted();
|
|
70
|
+
|
|
71
|
+
if (!current.filter(id)) return null;
|
|
72
|
+
|
|
73
|
+
let result: ReturnType<typeof current.transform>;
|
|
74
|
+
try {
|
|
75
|
+
result = current.transform(code, id);
|
|
76
|
+
} catch (error) {
|
|
77
|
+
this.error(toCleanViteError(error, id));
|
|
78
|
+
}
|
|
79
|
+
if (!result) return null;
|
|
80
|
+
|
|
81
|
+
return {
|
|
82
|
+
code: result.code,
|
|
83
|
+
map: result.map ? JSON.parse(result.map) : null,
|
|
84
|
+
};
|
|
85
|
+
},
|
|
86
|
+
|
|
87
|
+
async generateBundle(_, bundle) {
|
|
88
|
+
if (state.isServe()) return;
|
|
89
|
+
|
|
90
|
+
const css = await transformCssOutput(
|
|
91
|
+
state.getState().compiler.getExtractedCss(),
|
|
92
|
+
options.cssOutput,
|
|
93
|
+
'fluentic-style.css',
|
|
94
|
+
);
|
|
95
|
+
if (!css) return;
|
|
96
|
+
|
|
97
|
+
let cssAsset: CssAsset | null = null;
|
|
98
|
+
|
|
99
|
+
for (const item of Object.values(bundle)) {
|
|
100
|
+
if (item.type !== 'asset') continue;
|
|
101
|
+
if (!item.fileName.endsWith('.css')) continue;
|
|
102
|
+
if (typeof item.source !== 'string') continue;
|
|
103
|
+
|
|
104
|
+
if (!cssAsset && item.source) cssAsset = item as CssAsset;
|
|
105
|
+
|
|
106
|
+
if (hasCssMarker(item.source)) {
|
|
107
|
+
item.source = replaceCssMarker(item.source, css);
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (cssAsset) {
|
|
113
|
+
cssAsset.source = cssAsset.source ? `${cssAsset.source}\n${css}` : css;
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
this.warn(formatError(
|
|
118
|
+
'No CSS asset was emitted by Vite, so extracted CSS could not be attached. ' +
|
|
119
|
+
'Import a CSS file from your app entry/root layout so Vite owns the output filename and hashing.',
|
|
120
|
+
));
|
|
121
|
+
},
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function toCleanViteError(error: unknown, id: string) {
|
|
126
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
127
|
+
|
|
128
|
+
return {
|
|
129
|
+
id,
|
|
130
|
+
message,
|
|
131
|
+
stack: '',
|
|
132
|
+
};
|
|
133
|
+
}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import type { ConfigEnv, ResolvedConfig, UserConfig } from 'vite';
|
|
3
|
+
import { normalizePath } from '../../../compiler/utils/path';
|
|
4
|
+
import {
|
|
5
|
+
BUNDLE_CSS_FILE,
|
|
6
|
+
createPluginCompiler,
|
|
7
|
+
EXTRACTED_CSS_MARKER,
|
|
8
|
+
getPluginBuildConfig,
|
|
9
|
+
getPluginBuildDevConfig,
|
|
10
|
+
getPluginCacheDir,
|
|
11
|
+
type PluginCompiler,
|
|
12
|
+
type PluginOptions,
|
|
13
|
+
resolvePluginSourcemapFilePath,
|
|
14
|
+
writePluginCacheFile,
|
|
15
|
+
} from '../../utils';
|
|
16
|
+
import { formatError } from '../../utils/misc';
|
|
17
|
+
import { getStyleEntryDefines, getStyleRuntimeMode } from '../../utils/runtimeEntry';
|
|
18
|
+
import type { SourcemapSidecar } from '../../utils/sidecar';
|
|
19
|
+
import { getSourcemapSidecar } from '../../utils/sidecar';
|
|
20
|
+
import { resolveDevSourcemapMode } from '../../utils/sourcemap';
|
|
21
|
+
import { RUNTIME_MODULE_ID } from '../../utils/virtual';
|
|
22
|
+
|
|
23
|
+
const htmlEntryInjectTo: 'head-prepend' = 'head-prepend';
|
|
24
|
+
|
|
25
|
+
export function createVitePluginState(options: PluginOptions) {
|
|
26
|
+
let config: ResolvedConfig | null = null;
|
|
27
|
+
let state: PluginCompiler | null = null;
|
|
28
|
+
let sidecar: SourcemapSidecar | null = null;
|
|
29
|
+
|
|
30
|
+
return {
|
|
31
|
+
setConfig(value: ResolvedConfig) {
|
|
32
|
+
config = value;
|
|
33
|
+
},
|
|
34
|
+
|
|
35
|
+
getCurrentState() {
|
|
36
|
+
return state;
|
|
37
|
+
},
|
|
38
|
+
|
|
39
|
+
isServe() {
|
|
40
|
+
return config?.command === 'serve';
|
|
41
|
+
},
|
|
42
|
+
|
|
43
|
+
async getConfig(config: UserConfig, env: ConfigEnv) {
|
|
44
|
+
const dev = env.command === 'serve';
|
|
45
|
+
const buildConfig = getPluginBuildConfig(options);
|
|
46
|
+
const buildDevConfig = getPluginBuildDevConfig(options);
|
|
47
|
+
const sidecarUrl = await getSidecarUrl(dev, getViteRoot(config));
|
|
48
|
+
|
|
49
|
+
return {
|
|
50
|
+
define: getStyleEntryDefines(buildConfig, buildDevConfig, sidecarUrl),
|
|
51
|
+
};
|
|
52
|
+
},
|
|
53
|
+
|
|
54
|
+
getHtmlEntryScript() {
|
|
55
|
+
if (this.isServe()) return [];
|
|
56
|
+
|
|
57
|
+
return [{
|
|
58
|
+
tag: 'script',
|
|
59
|
+
attrs: { type: 'module' },
|
|
60
|
+
children: `import ${JSON.stringify(RUNTIME_MODULE_ID)};`,
|
|
61
|
+
injectTo: htmlEntryInjectTo,
|
|
62
|
+
}];
|
|
63
|
+
},
|
|
64
|
+
|
|
65
|
+
loadRuntimeModule() {
|
|
66
|
+
const current = this.getState();
|
|
67
|
+
|
|
68
|
+
if (current.dev) return 'export {};';
|
|
69
|
+
|
|
70
|
+
const cssFilePath = writePluginCacheFile(current, BUNDLE_CSS_FILE, EXTRACTED_CSS_MARKER);
|
|
71
|
+
|
|
72
|
+
return `import ${JSON.stringify(toViteFsImport(cssFilePath))};\n`;
|
|
73
|
+
},
|
|
74
|
+
|
|
75
|
+
async ensureSidecarStarted() {
|
|
76
|
+
await sidecar?.ensureStarted();
|
|
77
|
+
},
|
|
78
|
+
|
|
79
|
+
getState() {
|
|
80
|
+
if (!config) {
|
|
81
|
+
throw new Error(formatError('Vite config has not been resolved yet.'));
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (state) return state;
|
|
85
|
+
|
|
86
|
+
const dev = config.command === 'serve';
|
|
87
|
+
const cacheDir = getPluginCacheDir(config.root, options.cacheDir);
|
|
88
|
+
const devSourcemap = resolveDevSourcemapMode(options.devSourcemap, dev);
|
|
89
|
+
|
|
90
|
+
ensureSidecar(dev, config.root);
|
|
91
|
+
|
|
92
|
+
state = createPluginCompiler({
|
|
93
|
+
dev,
|
|
94
|
+
projectDir: config.root,
|
|
95
|
+
cacheDir,
|
|
96
|
+
options: {
|
|
97
|
+
...options,
|
|
98
|
+
devSourcemap,
|
|
99
|
+
getSourcemapFilePath: resolvePluginSourcemapFilePath(
|
|
100
|
+
options.getSourcemapFilePath,
|
|
101
|
+
sidecar,
|
|
102
|
+
),
|
|
103
|
+
},
|
|
104
|
+
runtimeMode: getStyleRuntimeMode(dev),
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
return state;
|
|
108
|
+
},
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
async function getSidecarUrl(dev: boolean, root: string) {
|
|
112
|
+
const current = ensureSidecar(dev, root);
|
|
113
|
+
|
|
114
|
+
await current?.ensureStarted();
|
|
115
|
+
|
|
116
|
+
return current?.getBaseUrl() ?? '';
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function ensureSidecar(dev: boolean, root: string) {
|
|
120
|
+
if (!dev) return null;
|
|
121
|
+
|
|
122
|
+
const devSourcemap = resolveDevSourcemapMode(options.devSourcemap, true);
|
|
123
|
+
if (devSourcemap !== 'sidecarServer') return null;
|
|
124
|
+
|
|
125
|
+
if (!sidecar) {
|
|
126
|
+
sidecar = createViteSidecar({ options, root });
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return sidecar;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function createViteSidecar(args: {
|
|
134
|
+
options: PluginOptions;
|
|
135
|
+
root: string;
|
|
136
|
+
}) {
|
|
137
|
+
return getSourcemapSidecar({
|
|
138
|
+
projectDir: args.root,
|
|
139
|
+
cacheDir: getPluginCacheDir(args.root, args.options.cacheDir),
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function getViteRoot(config: Pick<UserConfig | ResolvedConfig, 'root'>) {
|
|
144
|
+
return path.resolve(config.root ?? process.cwd());
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function toViteFsImport(filePath: string) {
|
|
148
|
+
const normalized = normalizePath(filePath);
|
|
149
|
+
|
|
150
|
+
return normalized.startsWith('/')
|
|
151
|
+
? `/@fs${normalized}`
|
|
152
|
+
: `/@fs/${normalized}`;
|
|
153
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './plugin';
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { createWebpackLoader } from './shared/loader';
|
|
2
|
+
import { type WebpackLoaderState, webpackRegistry } from './utils';
|
|
3
|
+
|
|
4
|
+
const loader = createWebpackLoader<WebpackLoaderState>({
|
|
5
|
+
getEntry: webpackRegistry.getEntry,
|
|
6
|
+
missingCompilerMessage: 'webpack compiler is not registered.',
|
|
7
|
+
transform({ code, entry, filePath, inputMap }) {
|
|
8
|
+
const result = entry.transform(code, filePath, inputMap ?? null);
|
|
9
|
+
|
|
10
|
+
if (!result) return null;
|
|
11
|
+
|
|
12
|
+
return {
|
|
13
|
+
code: result.code,
|
|
14
|
+
sourcemap: result.map,
|
|
15
|
+
};
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
export default loader;
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
import type { Compiler, RuleSetRule, WebpackPluginInstance } from 'webpack';
|
|
2
|
+
import { getStyleRuntimeImportPath } from '../../../compiler/utils/imports';
|
|
3
|
+
import {
|
|
4
|
+
BUNDLE_CSS_FILE,
|
|
5
|
+
createCompilerId,
|
|
6
|
+
createPluginCompiler,
|
|
7
|
+
DEFAULT_TRANSFORM_EXCLUDE,
|
|
8
|
+
DEFAULT_TRANSFORM_INCLUDE,
|
|
9
|
+
EXTRACTED_CSS_MARKER,
|
|
10
|
+
getPluginCacheDir,
|
|
11
|
+
invalidateFiles,
|
|
12
|
+
PLUGIN_NAME,
|
|
13
|
+
type PluginOptions,
|
|
14
|
+
resolvePluginSourcemapFilePath,
|
|
15
|
+
transformCssOutput,
|
|
16
|
+
writePluginCacheFile,
|
|
17
|
+
} from '../../utils';
|
|
18
|
+
import { formatError } from '../../utils/misc';
|
|
19
|
+
import {
|
|
20
|
+
getPluginBuildConfig,
|
|
21
|
+
getPluginBuildDevConfig,
|
|
22
|
+
getStyleEntryDefines,
|
|
23
|
+
getStyleRuntimeMode,
|
|
24
|
+
} from '../../utils/runtimeEntry';
|
|
25
|
+
import { getSourcemapSidecar } from '../../utils/sidecar';
|
|
26
|
+
import { resolveDevSourcemapMode } from '../../utils/sourcemap';
|
|
27
|
+
import {
|
|
28
|
+
createWebpackRuntimeModuleSource,
|
|
29
|
+
getStylePackageDistPath,
|
|
30
|
+
getTransformLoaderPath,
|
|
31
|
+
hasWebpackCssMarker,
|
|
32
|
+
prependWebpackRuntimeEntry,
|
|
33
|
+
replaceWebpackCssMarker,
|
|
34
|
+
type WebpackLoaderState,
|
|
35
|
+
webpackRegistry,
|
|
36
|
+
} from './utils';
|
|
37
|
+
|
|
38
|
+
export type { PluginOptions };
|
|
39
|
+
|
|
40
|
+
const WEBPACK_RUNTIME_FILE = 'webpack-runtime.js';
|
|
41
|
+
|
|
42
|
+
export default plugin;
|
|
43
|
+
|
|
44
|
+
export function plugin(options: PluginOptions = {}) {
|
|
45
|
+
return new WebpackPlugin(options);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
class WebpackPlugin implements WebpackPluginInstance {
|
|
49
|
+
private readonly options: PluginOptions;
|
|
50
|
+
|
|
51
|
+
constructor(options: PluginOptions = {}) {
|
|
52
|
+
this.options = options;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
apply(compiler: Compiler) {
|
|
56
|
+
const dev = compiler.options.mode === 'development';
|
|
57
|
+
const extract = !dev;
|
|
58
|
+
|
|
59
|
+
const buildConfig = getPluginBuildConfig(this.options);
|
|
60
|
+
const buildDevConfig = getPluginBuildDevConfig(this.options);
|
|
61
|
+
const cacheDir = getPluginCacheDir(compiler.context, this.options.cacheDir);
|
|
62
|
+
const devSourcemap = resolveDevSourcemapMode(this.options.devSourcemap, dev);
|
|
63
|
+
|
|
64
|
+
const sourcemapSidecar = devSourcemap === 'sidecarServer'
|
|
65
|
+
? getSourcemapSidecar({ projectDir: compiler.context, cacheDir })
|
|
66
|
+
: null;
|
|
67
|
+
|
|
68
|
+
const getSourcemapFilePath = resolvePluginSourcemapFilePath(
|
|
69
|
+
this.options.getSourcemapFilePath,
|
|
70
|
+
sourcemapSidecar,
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
const runtimeMode = getStyleRuntimeMode(dev);
|
|
74
|
+
const useRuntimeSidecarUrl = isRspackCompiler(compiler) && devSourcemap === 'sidecarServer';
|
|
75
|
+
|
|
76
|
+
const createRuntimeSource = (sidecarUrl: string | null = null) =>
|
|
77
|
+
createWebpackRuntimeModuleSource(
|
|
78
|
+
extract,
|
|
79
|
+
cssFilePath,
|
|
80
|
+
useRuntimeSidecarUrl
|
|
81
|
+
? {
|
|
82
|
+
runtimeImportPath: getStyleRuntimeImportPath(runtimeMode),
|
|
83
|
+
sidecarUrl,
|
|
84
|
+
}
|
|
85
|
+
: undefined,
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
const state = createPluginCompiler({
|
|
89
|
+
projectDir: compiler.context,
|
|
90
|
+
cacheDir,
|
|
91
|
+
dev,
|
|
92
|
+
options: { ...this.options, devSourcemap, getSourcemapFilePath },
|
|
93
|
+
runtimeMode,
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
const cssFilePath = extract
|
|
97
|
+
? writePluginCacheFile(state, BUNDLE_CSS_FILE, EXTRACTED_CSS_MARKER)
|
|
98
|
+
: null;
|
|
99
|
+
|
|
100
|
+
const runtimeFilePath = writePluginCacheFile(
|
|
101
|
+
state,
|
|
102
|
+
WEBPACK_RUNTIME_FILE,
|
|
103
|
+
createRuntimeSource(),
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
const compilerId = createCompilerId('webpack');
|
|
107
|
+
|
|
108
|
+
webpackRegistry.setEntry<WebpackLoaderState>(compilerId, {
|
|
109
|
+
transform: state.transform,
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
compiler.options.entry = prependWebpackRuntimeEntry(
|
|
113
|
+
compiler.options.entry,
|
|
114
|
+
runtimeFilePath,
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
addTransformLoader(compiler, this.options, compilerId);
|
|
118
|
+
|
|
119
|
+
const entryDefines = getStyleEntryDefines(buildConfig, buildDevConfig, null);
|
|
120
|
+
|
|
121
|
+
compiler.options.plugins ??= [];
|
|
122
|
+
compiler.options.plugins.push(
|
|
123
|
+
new compiler.webpack.DefinePlugin(entryDefines),
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
compiler.hooks.beforeRun.tapPromise(PLUGIN_NAME, async () => {
|
|
127
|
+
await sourcemapSidecar?.ensureStarted();
|
|
128
|
+
|
|
129
|
+
Object.assign(
|
|
130
|
+
entryDefines,
|
|
131
|
+
getStyleEntryDefines(
|
|
132
|
+
buildConfig,
|
|
133
|
+
buildDevConfig,
|
|
134
|
+
sourcemapSidecar?.getBaseUrl() || null,
|
|
135
|
+
),
|
|
136
|
+
);
|
|
137
|
+
writePluginCacheFile(
|
|
138
|
+
state,
|
|
139
|
+
WEBPACK_RUNTIME_FILE,
|
|
140
|
+
createRuntimeSource(sourcemapSidecar?.getBaseUrl() || null),
|
|
141
|
+
);
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
compiler.hooks.watchRun.tapPromise(PLUGIN_NAME, async (watchCompiler) => {
|
|
145
|
+
await sourcemapSidecar?.ensureStarted();
|
|
146
|
+
Object.assign(
|
|
147
|
+
entryDefines,
|
|
148
|
+
getStyleEntryDefines(
|
|
149
|
+
buildConfig,
|
|
150
|
+
buildDevConfig,
|
|
151
|
+
sourcemapSidecar?.getBaseUrl() || null,
|
|
152
|
+
),
|
|
153
|
+
);
|
|
154
|
+
writePluginCacheFile(
|
|
155
|
+
state,
|
|
156
|
+
WEBPACK_RUNTIME_FILE,
|
|
157
|
+
createRuntimeSource(sourcemapSidecar?.getBaseUrl() || null),
|
|
158
|
+
);
|
|
159
|
+
|
|
160
|
+
const files = watchCompiler.modifiedFiles;
|
|
161
|
+
if (!files || !files.size) return;
|
|
162
|
+
|
|
163
|
+
invalidateFiles(state.compiler, files);
|
|
164
|
+
state.filter.clear();
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => {
|
|
168
|
+
if (dev) return;
|
|
169
|
+
|
|
170
|
+
compilation.hooks.processAssets.tapPromise(
|
|
171
|
+
{
|
|
172
|
+
name: PLUGIN_NAME,
|
|
173
|
+
stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS,
|
|
174
|
+
},
|
|
175
|
+
async () => {
|
|
176
|
+
const css = await transformCssOutput(
|
|
177
|
+
state.compiler.getExtractedCss(),
|
|
178
|
+
this.options.cssOutput,
|
|
179
|
+
BUNDLE_CSS_FILE,
|
|
180
|
+
);
|
|
181
|
+
if (!css) return;
|
|
182
|
+
|
|
183
|
+
for (const asset of compilation.getAssets()) {
|
|
184
|
+
if (!asset.name.endsWith('.css')) continue;
|
|
185
|
+
|
|
186
|
+
const source = asset.source.source().toString();
|
|
187
|
+
if (!hasWebpackCssMarker(source, EXTRACTED_CSS_MARKER)) continue;
|
|
188
|
+
|
|
189
|
+
compilation.updateAsset(
|
|
190
|
+
asset.name,
|
|
191
|
+
new compiler.webpack.sources.RawSource(
|
|
192
|
+
replaceWebpackCssMarker(source, EXTRACTED_CSS_MARKER, css),
|
|
193
|
+
),
|
|
194
|
+
);
|
|
195
|
+
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
compilation.warnings.push(
|
|
200
|
+
new Error(formatError(
|
|
201
|
+
'No CSS asset containing the Fluentic marker was emitted by Webpack, so extracted CSS could not be attached. ' +
|
|
202
|
+
'Make sure your Webpack config handles CSS imports so Webpack owns the output filename, hashing, and runtime loading.',
|
|
203
|
+
)),
|
|
204
|
+
);
|
|
205
|
+
},
|
|
206
|
+
);
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
function addTransformLoader(
|
|
212
|
+
compiler: Compiler,
|
|
213
|
+
options: PluginOptions,
|
|
214
|
+
compilerId: string,
|
|
215
|
+
) {
|
|
216
|
+
const loader = {
|
|
217
|
+
loader: getTransformLoaderPath(),
|
|
218
|
+
options: { ...options, compilerId },
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
const rule: RuleSetRule = {
|
|
222
|
+
use: [loader],
|
|
223
|
+
enforce: 'pre',
|
|
224
|
+
test: DEFAULT_TRANSFORM_INCLUDE,
|
|
225
|
+
exclude: options.include ? undefined : [
|
|
226
|
+
DEFAULT_TRANSFORM_EXCLUDE,
|
|
227
|
+
getStylePackageDistPath(),
|
|
228
|
+
],
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
compiler.options.module.rules.unshift(rule);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
function isRspackCompiler(compiler: Compiler) {
|
|
235
|
+
const webpack = compiler.webpack as typeof compiler.webpack & {
|
|
236
|
+
rspackVersion?: unknown;
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
return typeof webpack.rspackVersion === 'string';
|
|
240
|
+
}
|