@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,210 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { createRequire } from 'node:module';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import type { Compilation, Compiler, WebpackPluginInstance } from 'webpack';
|
|
5
|
+
import type { Compiler as PluginCompiler } from '../../compiler';
|
|
6
|
+
import { normalizePath } from '../../compiler/utils/path';
|
|
7
|
+
import type { BuildConfig, BuildDevConfig } from '../../config/build';
|
|
8
|
+
import { createWebpackRegistry } from '../bundler/webpack/shared/registry';
|
|
9
|
+
import type { FileCssCache } from '../utils/cache';
|
|
10
|
+
import type { PluginOptions as BasePluginOptions } from '../utils/compiler';
|
|
11
|
+
import type { TransformFilter } from '../utils/filter';
|
|
12
|
+
import { getPluginBuildConfig, getPluginBuildDevConfig } from '../utils/runtimeEntry';
|
|
13
|
+
import type { SourcemapSidecar } from '../utils/sidecar';
|
|
14
|
+
import { resolvePluginSourcemapOptions } from '../utils/sourcemap';
|
|
15
|
+
import { LOADER_IMPORT_PATH } from './constants';
|
|
16
|
+
import type { PluginOptions, WebpackConfiguration } from './types';
|
|
17
|
+
|
|
18
|
+
export const nextRegistry = createWebpackRegistry('nextjs.registry');
|
|
19
|
+
|
|
20
|
+
export const PRECOLLECT_CACHE_DIRS = {
|
|
21
|
+
dev: 'nextjs/precollect/dev',
|
|
22
|
+
prod: 'nextjs/precollect/prod',
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export const NEXT_COMPILER_IDS = {
|
|
26
|
+
turbopack: 'nextjs:turbopack',
|
|
27
|
+
webpackServer: 'nextjs:webpack-server',
|
|
28
|
+
webpackClient: 'nextjs:webpack-client',
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export type { PluginCompiler };
|
|
32
|
+
|
|
33
|
+
export type NextLoaderState = {
|
|
34
|
+
compiler: PluginCompiler;
|
|
35
|
+
filter: TransformFilter;
|
|
36
|
+
dev: boolean;
|
|
37
|
+
isServer: boolean;
|
|
38
|
+
configHash: string;
|
|
39
|
+
devCssHref: string | null;
|
|
40
|
+
cssEntryImportPath: string;
|
|
41
|
+
cssCache: Pick<FileCssCache, 'setFileCss'> | null;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export type NextWebpackEntryValue = string | string[] | {
|
|
45
|
+
import?: string | string[];
|
|
46
|
+
[key: string]: unknown;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export function getTransformLoaderPath() {
|
|
50
|
+
return createRequire(import.meta.url).resolve(LOADER_IMPORT_PATH);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function getNextCacheDir(rootDir: string, cacheDir?: string) {
|
|
54
|
+
return cacheDir ?? path.join(rootDir, '.next/cache/fluentic-style');
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function getNextPrecollectCacheSubdir(dev: boolean) {
|
|
58
|
+
return dev ? PRECOLLECT_CACHE_DIRS.dev : PRECOLLECT_CACHE_DIRS.prod;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function createNextBuildConfig(options: PluginOptions): BuildConfig {
|
|
62
|
+
return getPluginBuildConfig(options);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function createNextBuildDevConfig(options: PluginOptions): BuildDevConfig | null {
|
|
66
|
+
return getPluginBuildDevConfig(options);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function createNextConfigHash(
|
|
70
|
+
buildConfig: BuildConfig,
|
|
71
|
+
dev: boolean,
|
|
72
|
+
) {
|
|
73
|
+
const values = [
|
|
74
|
+
dev ? 'dev' : 'prod',
|
|
75
|
+
buildConfig.hoist ? 'hoist' : 'no-hoist',
|
|
76
|
+
];
|
|
77
|
+
|
|
78
|
+
return createHash('sha256').update(values.join('\0')).digest('hex');
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export function resolveNextCompilerOptions(
|
|
82
|
+
options: PluginOptions,
|
|
83
|
+
sidecar: SourcemapSidecar | null,
|
|
84
|
+
buildConfig: BuildConfig,
|
|
85
|
+
buildDevConfig: BuildDevConfig | null,
|
|
86
|
+
dev: boolean,
|
|
87
|
+
): BasePluginOptions {
|
|
88
|
+
const resolved = resolvePluginSourcemapOptions({
|
|
89
|
+
...options,
|
|
90
|
+
devSourcemap: dev ? 'sidecarServer' : 'sourceUrl',
|
|
91
|
+
}, sidecar);
|
|
92
|
+
|
|
93
|
+
return {
|
|
94
|
+
...resolved,
|
|
95
|
+
css: {
|
|
96
|
+
...resolved.css,
|
|
97
|
+
...buildConfig.css,
|
|
98
|
+
},
|
|
99
|
+
dev: {
|
|
100
|
+
...resolved.dev,
|
|
101
|
+
...buildDevConfig,
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export function removeUndefinedValues<T>(value: T): T {
|
|
107
|
+
if (Array.isArray(value)) {
|
|
108
|
+
return value.map((item) => removeUndefinedValues(item)) as T;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (!value || typeof value !== 'object') {
|
|
112
|
+
return value;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const result: Record<string, unknown> = {};
|
|
116
|
+
|
|
117
|
+
for (const [key, item] of Object.entries(value)) {
|
|
118
|
+
if (item !== undefined) {
|
|
119
|
+
result[key] = removeUndefinedValues(item);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return result as T;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export function prependClientEntry(entry: unknown, moduleId: string) {
|
|
127
|
+
if (typeof entry === 'function') {
|
|
128
|
+
return async () => prependClientEntry(await entry(), moduleId);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if (!entry || typeof entry !== 'object') return entry;
|
|
132
|
+
|
|
133
|
+
const result: Record<string, unknown> = {};
|
|
134
|
+
|
|
135
|
+
for (const [key, value] of Object.entries(entry)) {
|
|
136
|
+
result[key] = prependEntryValue(value as NextWebpackEntryValue, moduleId);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return result;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export function prependEntryValue(entry: NextWebpackEntryValue, moduleId: string): NextWebpackEntryValue {
|
|
143
|
+
if (typeof entry === 'string') {
|
|
144
|
+
return entry === moduleId ? entry : [moduleId, entry];
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
if (Array.isArray(entry)) {
|
|
148
|
+
return entry.includes(moduleId) ? entry : [moduleId, ...entry];
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const imports = entry.import;
|
|
152
|
+
if (!imports) return { ...entry, import: moduleId };
|
|
153
|
+
|
|
154
|
+
return {
|
|
155
|
+
...entry,
|
|
156
|
+
import: Array.isArray(imports)
|
|
157
|
+
? imports.includes(moduleId) ? imports : [moduleId, ...imports]
|
|
158
|
+
: imports === moduleId
|
|
159
|
+
? imports
|
|
160
|
+
: [moduleId, imports],
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export function isAppLayoutFile(filePath: string) {
|
|
165
|
+
return /\/app\/(?:[^/]+\/)*layout\.[cm]?[jt]sx?$/.test(normalizePath(filePath));
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export function hasCssMarker(source: string, marker: string) {
|
|
169
|
+
return source.includes(marker);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export function replaceCssMarker(source: string, marker: string, css: string) {
|
|
173
|
+
return source.split(marker).join(css);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export function addAliases(config: WebpackConfiguration, aliases: Record<string, string>) {
|
|
177
|
+
if (!config.resolve) config.resolve = {};
|
|
178
|
+
if (!config.resolve.alias) config.resolve.alias = {};
|
|
179
|
+
Object.assign(config.resolve.alias, aliases);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export function addWebpackPlugin(config: WebpackConfiguration, plugin: WebpackPluginInstance) {
|
|
183
|
+
if (!config.plugins) config.plugins = [];
|
|
184
|
+
config.plugins.push(plugin);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export function replaceCssMarkerAsset(args: {
|
|
188
|
+
compiler: Compiler;
|
|
189
|
+
compilation: Compilation;
|
|
190
|
+
css: string;
|
|
191
|
+
marker: string;
|
|
192
|
+
}) {
|
|
193
|
+
for (const asset of args.compilation.getAssets()) {
|
|
194
|
+
if (!asset.name.endsWith('.css')) continue;
|
|
195
|
+
|
|
196
|
+
const source = asset.source.source().toString();
|
|
197
|
+
if (!hasCssMarker(source, args.marker)) continue;
|
|
198
|
+
|
|
199
|
+
args.compilation.updateAsset(
|
|
200
|
+
asset.name,
|
|
201
|
+
new args.compiler.webpack.sources.RawSource(
|
|
202
|
+
replaceCssMarker(source, args.marker, args.css),
|
|
203
|
+
),
|
|
204
|
+
);
|
|
205
|
+
|
|
206
|
+
return true;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
return false;
|
|
210
|
+
}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { compareLayerPriority } from '../../../atomic/layer';
|
|
5
|
+
import { type CompilerExtractCssArgs, type CssExtractRule, extractCss } from '../../../compiler/extract';
|
|
6
|
+
import { normalizePath } from '../../../compiler/utils/path';
|
|
7
|
+
|
|
8
|
+
export type FileCssCacheRule = CssExtractRule;
|
|
9
|
+
|
|
10
|
+
export type FileCssCacheRecord = {
|
|
11
|
+
filePath: string;
|
|
12
|
+
contentHash: string;
|
|
13
|
+
configHash: string;
|
|
14
|
+
rules: FileCssCacheRule[];
|
|
15
|
+
updatedAt: number;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export type SetFileCssArgs = {
|
|
19
|
+
filePath: string;
|
|
20
|
+
contentHash: string;
|
|
21
|
+
configHash: string;
|
|
22
|
+
rules: FileCssCacheRule[];
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export type GetFileCssArgs = CompilerExtractCssArgs & {
|
|
26
|
+
configHash?: string;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export type FileCssCacheArgs = {
|
|
30
|
+
cacheDir: string;
|
|
31
|
+
cacheSubdir: string;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export type FileCssCache = ReturnType<typeof createFileCssCache>;
|
|
35
|
+
|
|
36
|
+
export function createFileCssCache(args: FileCssCacheArgs) {
|
|
37
|
+
const rootDir = path.join(args.cacheDir, args.cacheSubdir);
|
|
38
|
+
const filesDir = path.join(rootDir, 'files');
|
|
39
|
+
|
|
40
|
+
const getFilePath = (filePath: string) => {
|
|
41
|
+
return path.join(filesDir, hashFilePath(filePath) + '.json');
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const setFileCss = (item: SetFileCssArgs) => {
|
|
45
|
+
const record: FileCssCacheRecord = {
|
|
46
|
+
filePath: normalizePath(item.filePath),
|
|
47
|
+
contentHash: item.contentHash,
|
|
48
|
+
configHash: item.configHash,
|
|
49
|
+
rules: item.rules,
|
|
50
|
+
updatedAt: Date.now(),
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
fs.mkdirSync(filesDir, { recursive: true });
|
|
54
|
+
|
|
55
|
+
fs.writeFileSync(getFilePath(record.filePath), JSON.stringify(record), 'utf8');
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const getCss = (args: GetFileCssArgs = {}) => {
|
|
59
|
+
const rules = getRules(args);
|
|
60
|
+
return extractCss(rules, args);
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const getRules = (args: GetFileCssArgs = {}) => {
|
|
64
|
+
const records = readRecords(filesDir, args);
|
|
65
|
+
const rules: FileCssCacheRule[] = [];
|
|
66
|
+
|
|
67
|
+
for (const record of records) {
|
|
68
|
+
rules.push(...record.rules);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return rules.sort((a, b) => compareLayerPriority(a.priority, b.priority));
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const clear = () => {
|
|
75
|
+
try {
|
|
76
|
+
fs.rmSync(rootDir, { recursive: true, force: true });
|
|
77
|
+
} catch {
|
|
78
|
+
// Cache cleanup is best effort.
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const invalidateFile = (filePath: string) => {
|
|
83
|
+
try {
|
|
84
|
+
fs.rmSync(getFilePath(normalizePath(filePath)));
|
|
85
|
+
} catch {
|
|
86
|
+
// Cache invalidation is best effort.
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
return {
|
|
91
|
+
rootDir,
|
|
92
|
+
filesDir,
|
|
93
|
+
setFileCss,
|
|
94
|
+
getCss,
|
|
95
|
+
getRules,
|
|
96
|
+
clear,
|
|
97
|
+
invalidateFile,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export function createFileCssContentHash(code: string) {
|
|
102
|
+
return hash(code);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export function createFileCssConfigHash(config: unknown) {
|
|
106
|
+
return hash(JSON.stringify(config ?? null));
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function readRecords(filesDir: string, args: GetFileCssArgs) {
|
|
110
|
+
let entries: string[];
|
|
111
|
+
|
|
112
|
+
try {
|
|
113
|
+
entries = fs.readdirSync(filesDir);
|
|
114
|
+
} catch {
|
|
115
|
+
return [];
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const records: FileCssCacheRecord[] = [];
|
|
119
|
+
|
|
120
|
+
for (const entry of entries) {
|
|
121
|
+
if (!entry.endsWith('.json')) continue;
|
|
122
|
+
|
|
123
|
+
try {
|
|
124
|
+
const record = JSON.parse(
|
|
125
|
+
fs.readFileSync(path.join(filesDir, entry), 'utf8'),
|
|
126
|
+
) as FileCssCacheRecord;
|
|
127
|
+
|
|
128
|
+
if (!record.filePath || !Array.isArray(record.rules)) continue;
|
|
129
|
+
if (args.configHash && record.configHash !== args.configHash) continue;
|
|
130
|
+
|
|
131
|
+
records.push(record);
|
|
132
|
+
} catch {
|
|
133
|
+
// Ignore partial cache files from interrupted dev builds.
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return records;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function hashFilePath(filePath: string) {
|
|
141
|
+
return hash(normalizePath(path.resolve(filePath)));
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function hash(text: string) {
|
|
145
|
+
return createHash('sha256').update(text).digest('hex');
|
|
146
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import type { PluginCompiler } from '../compiler';
|
|
4
|
+
|
|
5
|
+
export function getPluginCacheFilePath(
|
|
6
|
+
compiler: PluginCompiler,
|
|
7
|
+
fileName: string,
|
|
8
|
+
) {
|
|
9
|
+
return path.join(compiler.cacheDir, fileName);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function writeCacheFile(
|
|
13
|
+
cacheDir: string,
|
|
14
|
+
fileName: string,
|
|
15
|
+
content: string,
|
|
16
|
+
) {
|
|
17
|
+
const filePath = path.join(cacheDir, fileName);
|
|
18
|
+
|
|
19
|
+
if (fs.existsSync(filePath)) {
|
|
20
|
+
const size = Buffer.byteLength(content);
|
|
21
|
+
const stat = fs.statSync(filePath);
|
|
22
|
+
|
|
23
|
+
if (stat.size === size && fs.readFileSync(filePath, 'utf8') === content) {
|
|
24
|
+
return filePath;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
|
29
|
+
fs.writeFileSync(filePath, content, 'utf8');
|
|
30
|
+
|
|
31
|
+
return filePath;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function writePluginCacheFile(
|
|
35
|
+
compiler: PluginCompiler,
|
|
36
|
+
fileName: string,
|
|
37
|
+
content: string,
|
|
38
|
+
) {
|
|
39
|
+
return writeCacheFile(compiler.cacheDir, fileName, content);
|
|
40
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { createCompiler } from '../../compiler';
|
|
3
|
+
import type { Compiler, CompilerCssOptions, CompilerOptions, CompilerRuntimeMode } from '../../compiler';
|
|
4
|
+
import { PLUGIN_CACHE_DIR, PLUGIN_NAME } from './constants';
|
|
5
|
+
import type { PluginCssOutputOptions } from './cssOutput';
|
|
6
|
+
import { createTransformFilter, normalizeModuleId, type TransformFilterOptions } from './filter';
|
|
7
|
+
import type { BundlerSourceMap } from './sourcemap';
|
|
8
|
+
|
|
9
|
+
export type PluginCssOptions = CompilerCssOptions;
|
|
10
|
+
|
|
11
|
+
export type PluginOptions = CompilerOptions & TransformFilterOptions & {
|
|
12
|
+
cacheDir?: string;
|
|
13
|
+
cssOutput?: PluginCssOutputOptions;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export type PluginCompiler = ReturnType<typeof createPluginCompiler>;
|
|
17
|
+
|
|
18
|
+
export type PluginCompilerArgs = {
|
|
19
|
+
dev: boolean;
|
|
20
|
+
projectDir: string;
|
|
21
|
+
cacheDir: string;
|
|
22
|
+
options: PluginOptions;
|
|
23
|
+
runtimeMode: CompilerRuntimeMode | null;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
let nextCompilerId = 0;
|
|
27
|
+
|
|
28
|
+
export function createCompilerId(name?: string) {
|
|
29
|
+
return [PLUGIN_NAME, name, String(nextCompilerId++)].filter(Boolean).join('|');
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function getPluginCacheDir(projectDir: string, cacheDir?: string) {
|
|
33
|
+
return cacheDir ?? path.join(projectDir, PLUGIN_CACHE_DIR);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function createPluginCompiler(args: PluginCompilerArgs) {
|
|
37
|
+
const dev = args.dev;
|
|
38
|
+
const options = args.options;
|
|
39
|
+
|
|
40
|
+
const projectDir = args.projectDir;
|
|
41
|
+
const cacheDir = args.cacheDir;
|
|
42
|
+
|
|
43
|
+
const compiler = createCompiler(
|
|
44
|
+
{
|
|
45
|
+
projectDir,
|
|
46
|
+
cacheDir,
|
|
47
|
+
runtimeMode: args.runtimeMode,
|
|
48
|
+
},
|
|
49
|
+
options,
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
const filter = createTransformFilter(options);
|
|
53
|
+
|
|
54
|
+
const transform = (
|
|
55
|
+
code: string,
|
|
56
|
+
id: string,
|
|
57
|
+
sourcemap: BundlerSourceMap | null = null,
|
|
58
|
+
) => {
|
|
59
|
+
const filePath = normalizeModuleId(id);
|
|
60
|
+
|
|
61
|
+
if (!filter(filePath)) return null;
|
|
62
|
+
|
|
63
|
+
const result = dev
|
|
64
|
+
? compiler.compileDebug({ code, filePath, sourcemap })
|
|
65
|
+
: compiler.compileExtract({ code, filePath, sourcemap });
|
|
66
|
+
|
|
67
|
+
if (!result) return null;
|
|
68
|
+
|
|
69
|
+
return {
|
|
70
|
+
code: result.code,
|
|
71
|
+
map: result.sourcemap,
|
|
72
|
+
rules: 'rules' in result ? result.rules : [],
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
return {
|
|
77
|
+
projectDir,
|
|
78
|
+
cacheDir,
|
|
79
|
+
dev,
|
|
80
|
+
//
|
|
81
|
+
compiler,
|
|
82
|
+
filter,
|
|
83
|
+
transform,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export function invalidateFiles(
|
|
88
|
+
compiler: Compiler,
|
|
89
|
+
filePaths: Iterable<string>,
|
|
90
|
+
) {
|
|
91
|
+
for (const filePath of filePaths) {
|
|
92
|
+
compiler.invalidateFile({ filePath });
|
|
93
|
+
}
|
|
94
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { PluginCompiler } from './compiler';
|
|
2
|
+
import { EXTRACTED_CSS_MARKER } from './constants';
|
|
3
|
+
|
|
4
|
+
export function getExtractedCss(compiler: PluginCompiler) {
|
|
5
|
+
return compiler.compiler.getExtractedCss();
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function replaceCssMarker(text: string, css: string) {
|
|
9
|
+
return text.replace(EXTRACTED_CSS_MARKER, css);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function hasCssMarker(text: string) {
|
|
13
|
+
return text.includes(EXTRACTED_CSS_MARKER);
|
|
14
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { Features, Targets, TransformOptions } from 'lightningcss';
|
|
2
|
+
|
|
3
|
+
export type CssOutputTargets = Targets | string | string[];
|
|
4
|
+
|
|
5
|
+
export type CssOutputOptions = {
|
|
6
|
+
targets?: CssOutputTargets;
|
|
7
|
+
vendorPrefixes?: boolean;
|
|
8
|
+
minify?: boolean;
|
|
9
|
+
lightningcss?: Partial<
|
|
10
|
+
Omit<
|
|
11
|
+
TransformOptions<Record<string, never>>,
|
|
12
|
+
'code' | 'filename' | 'minify' | 'targets'
|
|
13
|
+
>
|
|
14
|
+
>;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export type PluginCssOutputOptions = boolean | CssOutputOptions;
|
|
18
|
+
|
|
19
|
+
export async function transformCssOutput(
|
|
20
|
+
css: string,
|
|
21
|
+
options: PluginCssOutputOptions | undefined,
|
|
22
|
+
filename: string,
|
|
23
|
+
): Promise<string> {
|
|
24
|
+
if (!css || !options) return css;
|
|
25
|
+
|
|
26
|
+
const outputOptions = options === true ? {} : options;
|
|
27
|
+
const lightningcss = await import('lightningcss');
|
|
28
|
+
const targets = getLightningTargets(
|
|
29
|
+
lightningcss.browserslistToTargets,
|
|
30
|
+
outputOptions.targets ?? 'defaults',
|
|
31
|
+
);
|
|
32
|
+
const exclude = getLightningExclude(lightningcss.Features, outputOptions);
|
|
33
|
+
|
|
34
|
+
const result = lightningcss.transform({
|
|
35
|
+
filename,
|
|
36
|
+
code: new TextEncoder().encode(css),
|
|
37
|
+
...outputOptions.lightningcss,
|
|
38
|
+
targets,
|
|
39
|
+
minify: outputOptions.minify,
|
|
40
|
+
exclude,
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
return new TextDecoder().decode(result.code);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function getLightningTargets(
|
|
47
|
+
browserslistToTargets: (browserslist: string[]) => Targets,
|
|
48
|
+
targets: CssOutputTargets | undefined,
|
|
49
|
+
): Targets | undefined {
|
|
50
|
+
if (!targets) return undefined;
|
|
51
|
+
if (typeof targets === 'string') return browserslistToTargets([targets]);
|
|
52
|
+
if (Array.isArray(targets)) return browserslistToTargets(targets);
|
|
53
|
+
return targets;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function getLightningExclude(
|
|
57
|
+
features: typeof Features,
|
|
58
|
+
options: CssOutputOptions,
|
|
59
|
+
) {
|
|
60
|
+
const exclude = options.lightningcss?.exclude ?? 0;
|
|
61
|
+
|
|
62
|
+
return options.vendorPrefixes === false
|
|
63
|
+
? exclude | features.VendorPrefixes
|
|
64
|
+
: exclude;
|
|
65
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import picomatch from 'picomatch';
|
|
2
|
+
import { normalizePath } from '../../compiler/utils/path';
|
|
3
|
+
|
|
4
|
+
export const DEFAULT_TRANSFORM_INCLUDE_PATTERN = '\\.[cm]?[jt]sx?$';
|
|
5
|
+
|
|
6
|
+
export const DEFAULT_TRANSFORM_INCLUDE = new RegExp(DEFAULT_TRANSFORM_INCLUDE_PATTERN);
|
|
7
|
+
|
|
8
|
+
export const DEFAULT_TRANSFORM_EXCLUDE = /node_modules/;
|
|
9
|
+
|
|
10
|
+
export type FilterPattern = string | RegExp | Array<string | RegExp>;
|
|
11
|
+
|
|
12
|
+
export type TransformFilterOptions = {
|
|
13
|
+
include?: FilterPattern;
|
|
14
|
+
exclude?: FilterPattern;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export type TransformFilter = {
|
|
18
|
+
(id: string): boolean;
|
|
19
|
+
clear(): void;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export function normalizeModuleId(id: string) {
|
|
23
|
+
return id.split('?')[0]?.split('#')[0] ?? id;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function createTransformFilter(options: TransformFilterOptions = {}): TransformFilter {
|
|
27
|
+
const includes = normalizeMatchers(options.include);
|
|
28
|
+
|
|
29
|
+
const excludes = normalizeMatchers(
|
|
30
|
+
options.exclude ?? (options.include ? undefined : DEFAULT_TRANSFORM_EXCLUDE),
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
const cache = new Map<string, boolean>();
|
|
34
|
+
|
|
35
|
+
const filter = ((id: string) => {
|
|
36
|
+
const filePath = normalizeModuleId(id);
|
|
37
|
+
const cached = cache.get(filePath);
|
|
38
|
+
|
|
39
|
+
if (cached !== undefined) return cached;
|
|
40
|
+
|
|
41
|
+
const result = shouldTransform(filePath, includes, excludes);
|
|
42
|
+
|
|
43
|
+
cache.set(filePath, result);
|
|
44
|
+
|
|
45
|
+
return result;
|
|
46
|
+
}) as TransformFilter;
|
|
47
|
+
|
|
48
|
+
filter.clear = () => {
|
|
49
|
+
cache.clear();
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
return filter;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
type FilterMatcher = (id: string) => boolean;
|
|
56
|
+
|
|
57
|
+
function normalizeMatchers(patterns?: FilterPattern) {
|
|
58
|
+
if (!patterns) return [];
|
|
59
|
+
|
|
60
|
+
const items = Array.isArray(patterns) ? patterns : [patterns];
|
|
61
|
+
|
|
62
|
+
return items.map(createMatcher);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function createMatcher(pattern: string | RegExp): FilterMatcher {
|
|
66
|
+
if (pattern instanceof RegExp) {
|
|
67
|
+
return (id) => {
|
|
68
|
+
pattern.lastIndex = 0;
|
|
69
|
+
return pattern.test(id);
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const matcher = picomatch(normalizePath(pattern), {
|
|
74
|
+
dot: true,
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
return (id) => matcher(normalizePath(id));
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function shouldTransform(
|
|
81
|
+
id: string,
|
|
82
|
+
includes: FilterMatcher[],
|
|
83
|
+
excludes: FilterMatcher[],
|
|
84
|
+
): boolean {
|
|
85
|
+
for (const exclude of excludes) {
|
|
86
|
+
if (exclude(id)) return false;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (!includes.length) {
|
|
90
|
+
return DEFAULT_TRANSFORM_INCLUDE.test(id);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
for (const include of includes) {
|
|
94
|
+
if (include(id)) return true;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from './cache';
|
|
2
|
+
export * from './compiler';
|
|
3
|
+
export * from './constants';
|
|
4
|
+
export * from './cssMarker';
|
|
5
|
+
export * from './cssOutput';
|
|
6
|
+
export * from './filter';
|
|
7
|
+
export * from './injection';
|
|
8
|
+
export * from './runtimeEntry';
|
|
9
|
+
export * from './sourcemap';
|
|
10
|
+
export * from './virtual';
|