@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,28 @@
|
|
|
1
|
+
export function shouldInjectModuleImport(code: string, moduleId: string) {
|
|
2
|
+
return !code.includes(moduleId);
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export function injectModuleImport(code: string, moduleId: string) {
|
|
6
|
+
if (!shouldInjectModuleImport(code, moduleId)) return code;
|
|
7
|
+
|
|
8
|
+
return injectCodeAfterDirectivePrologue(
|
|
9
|
+
code,
|
|
10
|
+
`import ${JSON.stringify(moduleId)};\n`,
|
|
11
|
+
);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function injectCodeAfterDirectivePrologue(
|
|
15
|
+
code: string,
|
|
16
|
+
injectedCode: string,
|
|
17
|
+
) {
|
|
18
|
+
const insertAt = getDirectivePrologueEnd(code);
|
|
19
|
+
|
|
20
|
+
return code.slice(0, insertAt) + injectedCode + code.slice(insertAt);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function getDirectivePrologueEnd(code: string) {
|
|
24
|
+
const pattern = /^(?:\s*(?:"[^"]*"|'[^']*')\s*;?)+/;
|
|
25
|
+
const match = pattern.exec(code);
|
|
26
|
+
|
|
27
|
+
return match ? match[0].length : 0;
|
|
28
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { type CompilerCssOptions, type CompilerDevOptions, CompilerRuntimeMode } from '../../compiler';
|
|
2
|
+
import type { BuildConfig, BuildDevConfig } from '../../config/build';
|
|
3
|
+
import type { PluginOptions } from './compiler';
|
|
4
|
+
|
|
5
|
+
export function getStyleRuntimeMode(dev: boolean, rsc = false): CompilerRuntimeMode {
|
|
6
|
+
if (rsc) {
|
|
7
|
+
return dev ? CompilerRuntimeMode.RscDev : CompilerRuntimeMode.RscProd;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
return dev ? CompilerRuntimeMode.Dev : CompilerRuntimeMode.Prod;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function getPluginBuildConfig(options: PluginOptions): BuildConfig {
|
|
14
|
+
const css: CompilerCssOptions = hasBuildConfig(options.css) ? options.css! : {};
|
|
15
|
+
|
|
16
|
+
return {
|
|
17
|
+
hoist: options.hoist !== false,
|
|
18
|
+
css,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function getPluginBuildDevConfig(options: PluginOptions): BuildDevConfig | null {
|
|
23
|
+
const devConfig: BuildDevConfig | null = hasBuildConfig(options.dev) ? options.dev! : null;
|
|
24
|
+
|
|
25
|
+
return devConfig;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function hasBuildConfig(config: CompilerCssOptions | CompilerDevOptions | null | undefined) {
|
|
29
|
+
if (!config) return false;
|
|
30
|
+
|
|
31
|
+
for (const key in config) {
|
|
32
|
+
if (config[key as keyof typeof config] !== undefined) return true;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function getStyleEntryDefines(
|
|
39
|
+
buildConfig: BuildConfig,
|
|
40
|
+
buildDevConfig: BuildDevConfig | null,
|
|
41
|
+
sidecarUrl: string | null,
|
|
42
|
+
stringify = true,
|
|
43
|
+
) {
|
|
44
|
+
const defines: Record<string, string> = {
|
|
45
|
+
FLUENTIC_STYLE_BUILD_CONFIG: JSON.stringify(buildConfig),
|
|
46
|
+
FLUENTIC_STYLE_DEV_CONFIG: JSON.stringify(buildDevConfig ?? {}),
|
|
47
|
+
FLUENTIC_STYLE_SIDECAR_SERVER_URL: sidecarUrl ?? '',
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
if (stringify) {
|
|
51
|
+
Object.keys(defines).forEach((key) => {
|
|
52
|
+
defines[key] = JSON.stringify(defines[key]);
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return defines;
|
|
57
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './sidecar';
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
2
|
+
import { createServer, type Server } from 'node:http';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { formatError } from '../misc';
|
|
5
|
+
import { getRequestPathname, isPortUnavailableError, readCachedPort, writeCachedPort } from './utils';
|
|
6
|
+
|
|
7
|
+
export const SIDECAR_HOST = '127.0.0.1';
|
|
8
|
+
|
|
9
|
+
export type CreateSidecarServerArgs = {
|
|
10
|
+
projectDir: string;
|
|
11
|
+
routes: Map<string, string>;
|
|
12
|
+
handlers?: Map<string, SidecarRouteHandler>;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export type SidecarRouteResponse = {
|
|
16
|
+
body: string | Buffer;
|
|
17
|
+
contentType?: string;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export type SidecarRouteHandler = () => SidecarRouteResponse | null | Promise<SidecarRouteResponse | null>;
|
|
21
|
+
|
|
22
|
+
export type StartSidecarServerArgs = {
|
|
23
|
+
host?: string;
|
|
24
|
+
portFilePath: string;
|
|
25
|
+
server: Server;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export function createSidecarServer(args: CreateSidecarServerArgs) {
|
|
29
|
+
return createServer(async (req, res) => {
|
|
30
|
+
const pathname = getRequestPathname(req.url);
|
|
31
|
+
const handler = pathname ? args.handlers?.get(pathname) : null;
|
|
32
|
+
|
|
33
|
+
if (handler) {
|
|
34
|
+
const response = await handler();
|
|
35
|
+
|
|
36
|
+
if (!response) {
|
|
37
|
+
res.statusCode = 404;
|
|
38
|
+
res.end('Not found');
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
43
|
+
res.setHeader('Content-Type', response.contentType ?? 'text/plain; charset=utf-8');
|
|
44
|
+
res.setHeader('X-Content-Type-Options', 'nosniff');
|
|
45
|
+
|
|
46
|
+
res.statusCode = 200;
|
|
47
|
+
res.end(response.body);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const filePath = pathname
|
|
52
|
+
? args.routes.get(pathname) ?? getProjectSourcePath(args.projectDir, pathname)
|
|
53
|
+
: null;
|
|
54
|
+
|
|
55
|
+
if (!filePath || !existsSync(filePath)) {
|
|
56
|
+
res.statusCode = 404;
|
|
57
|
+
res.end('Not found');
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
62
|
+
res.setHeader('Content-Type', 'text/plain; charset=utf-8');
|
|
63
|
+
res.setHeader('X-Content-Type-Options', 'nosniff');
|
|
64
|
+
|
|
65
|
+
res.statusCode = 200;
|
|
66
|
+
res.end(readFileSync(filePath, 'utf8'));
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function getProjectSourcePath(projectDir: string, pathname: string) {
|
|
71
|
+
const sourcePath = pathname
|
|
72
|
+
.replace(/^\/+/, '')
|
|
73
|
+
.replace(/^@\/?/, '');
|
|
74
|
+
|
|
75
|
+
if (!sourcePath || sourcePath.startsWith('..')) return null;
|
|
76
|
+
|
|
77
|
+
const filePath = path.resolve(projectDir, sourcePath);
|
|
78
|
+
const projectPath = path.resolve(projectDir);
|
|
79
|
+
|
|
80
|
+
return filePath === projectPath || filePath.startsWith(projectPath + path.sep)
|
|
81
|
+
? filePath
|
|
82
|
+
: null;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export async function startSidecarServer(args: StartSidecarServerArgs) {
|
|
86
|
+
const host = args.host ?? SIDECAR_HOST;
|
|
87
|
+
const cachedPort = readCachedPort({ filePath: args.portFilePath });
|
|
88
|
+
|
|
89
|
+
if (cachedPort !== null) {
|
|
90
|
+
try {
|
|
91
|
+
return await listen({ server: args.server, host, port: cachedPort });
|
|
92
|
+
} catch (error) {
|
|
93
|
+
if (!isPortUnavailableError({ error })) throw error;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const port = await listen({ server: args.server, host, port: 0 });
|
|
98
|
+
|
|
99
|
+
writeCachedPort({ filePath: args.portFilePath, port });
|
|
100
|
+
|
|
101
|
+
return port;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
type ListenArgs = {
|
|
105
|
+
host: string;
|
|
106
|
+
port: number;
|
|
107
|
+
server: Server;
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
function listen(args: ListenArgs) {
|
|
111
|
+
return new Promise<number>((resolve, reject) => {
|
|
112
|
+
const cleanup = () => {
|
|
113
|
+
args.server.off('error', onError);
|
|
114
|
+
args.server.off('listening', onListening);
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
const onError = (error: Error) => {
|
|
118
|
+
cleanup();
|
|
119
|
+
reject(error);
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
const onListening = () => {
|
|
123
|
+
cleanup();
|
|
124
|
+
|
|
125
|
+
const address = args.server.address();
|
|
126
|
+
|
|
127
|
+
if (
|
|
128
|
+
!address ||
|
|
129
|
+
typeof address !== 'object' ||
|
|
130
|
+
typeof address.port !== 'number'
|
|
131
|
+
) {
|
|
132
|
+
reject(new Error(formatError('Sourcemap sidecar server started without a TCP port.')));
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
resolve(address.port);
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
args.server.once('error', onError);
|
|
140
|
+
args.server.once('listening', onListening);
|
|
141
|
+
args.server.listen(args.port, args.host);
|
|
142
|
+
});
|
|
143
|
+
}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import type { Server } from 'node:http';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { globalData } from '../../../utils/global';
|
|
4
|
+
import { formatError } from '../misc';
|
|
5
|
+
import { createSidecarServer, SIDECAR_HOST, type SidecarRouteHandler, startSidecarServer } from './server';
|
|
6
|
+
import { createSourceUrl, getPortFilePath, getRoutePath, normalizeSidecarRoutePath } from './utils';
|
|
7
|
+
|
|
8
|
+
type SidecarServer = {
|
|
9
|
+
cacheDir: string;
|
|
10
|
+
handlers: Map<string, SidecarRouteHandler>;
|
|
11
|
+
projectDir: string;
|
|
12
|
+
port: number | null;
|
|
13
|
+
portFilePath: string;
|
|
14
|
+
routes: Map<string, string>;
|
|
15
|
+
server: Server;
|
|
16
|
+
startError: Error | null;
|
|
17
|
+
startPromise: Promise<void>;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export type SourcemapSidecar = {
|
|
21
|
+
cacheDir: string;
|
|
22
|
+
projectDir: string;
|
|
23
|
+
ensureStarted(): Promise<void>;
|
|
24
|
+
getBaseUrl(): string | null;
|
|
25
|
+
getRouteUrl(routePath: string): string;
|
|
26
|
+
getSourceUrl(filePath: string, relativePath?: string | null): string;
|
|
27
|
+
registerSource(filePath: string, routePath: string): string;
|
|
28
|
+
registerRoute(routePath: string, handler: SidecarRouteHandler): string;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export type SourcemapSidecarArgs = {
|
|
32
|
+
cacheDir: string;
|
|
33
|
+
projectDir: string;
|
|
34
|
+
routes?: Record<string, SidecarRouteHandler>;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const sidecarServers = globalData(
|
|
38
|
+
'plugin.sidecar.servers',
|
|
39
|
+
() => new Map<string, SidecarServer>(),
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
export function getSourcemapSidecar(args: SourcemapSidecarArgs): SourcemapSidecar {
|
|
43
|
+
const normalizedProjectDir = path.resolve(args.projectDir);
|
|
44
|
+
const normalizedCacheDir = path.resolve(args.cacheDir);
|
|
45
|
+
const state = getOrCreateServer(normalizedProjectDir, normalizedCacheDir);
|
|
46
|
+
|
|
47
|
+
if (args.routes) {
|
|
48
|
+
for (const [routePath, handler] of Object.entries(args.routes)) {
|
|
49
|
+
state.handlers.set(normalizeSidecarRoutePath({ routePath }), handler);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return {
|
|
54
|
+
cacheDir: normalizedCacheDir,
|
|
55
|
+
projectDir: normalizedProjectDir,
|
|
56
|
+
ensureStarted() {
|
|
57
|
+
return state.startPromise;
|
|
58
|
+
},
|
|
59
|
+
getBaseUrl() {
|
|
60
|
+
return createSidecarBaseUrl(state);
|
|
61
|
+
},
|
|
62
|
+
getRouteUrl(routePath) {
|
|
63
|
+
return createSidecarSourceUrl(
|
|
64
|
+
state,
|
|
65
|
+
normalizeSidecarRoutePath({ routePath }),
|
|
66
|
+
);
|
|
67
|
+
},
|
|
68
|
+
getSourceUrl(filePath, relativePath) {
|
|
69
|
+
return createSidecarSourceUrl(
|
|
70
|
+
state,
|
|
71
|
+
getRoutePath({
|
|
72
|
+
filePath,
|
|
73
|
+
projectDir: normalizedProjectDir,
|
|
74
|
+
relativePath,
|
|
75
|
+
}),
|
|
76
|
+
);
|
|
77
|
+
},
|
|
78
|
+
registerSource(filePath, routePath) {
|
|
79
|
+
routePath = normalizeSidecarRoutePath({ routePath });
|
|
80
|
+
|
|
81
|
+
state.routes.set(routePath, path.resolve(filePath));
|
|
82
|
+
|
|
83
|
+
return createSidecarSourceUrl(state, routePath);
|
|
84
|
+
},
|
|
85
|
+
registerRoute(routePath, handler) {
|
|
86
|
+
routePath = normalizeSidecarRoutePath({ routePath });
|
|
87
|
+
|
|
88
|
+
state.handlers.set(routePath, handler);
|
|
89
|
+
|
|
90
|
+
return createSidecarSourceUrl(state, routePath);
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function createSidecarBaseUrl(state: SidecarServer) {
|
|
96
|
+
if (state.startError || state.port === null) return null;
|
|
97
|
+
|
|
98
|
+
return `http://${SIDECAR_HOST}:${state.port}`;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function createSidecarSourceUrl(state: SidecarServer, routePath: string) {
|
|
102
|
+
if (state.startError) {
|
|
103
|
+
throw new Error(formatError(
|
|
104
|
+
`The sourcemap dev server could not start: ${state.startError.message}`,
|
|
105
|
+
));
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (state.port === null) {
|
|
109
|
+
throw new Error(formatError(
|
|
110
|
+
'The sourcemap dev server is not ready yet. Try rebuilding after the dev server finishes starting.',
|
|
111
|
+
));
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const baseUrl = createSidecarBaseUrl(state);
|
|
115
|
+
|
|
116
|
+
if (baseUrl === null) {
|
|
117
|
+
throw new Error(formatError(
|
|
118
|
+
'The sourcemap dev server is not ready yet. Try rebuilding after the dev server finishes starting.',
|
|
119
|
+
));
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return createSourceUrl({
|
|
123
|
+
baseUrl,
|
|
124
|
+
routePath,
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function getOrCreateServer(projectDir: string, cacheDir: string) {
|
|
129
|
+
const servers = sidecarServers;
|
|
130
|
+
|
|
131
|
+
const existing = servers.get(cacheDir);
|
|
132
|
+
if (existing) return existing;
|
|
133
|
+
|
|
134
|
+
const routes = new Map<string, string>();
|
|
135
|
+
const handlers = new Map<string, SidecarRouteHandler>();
|
|
136
|
+
|
|
137
|
+
const state: SidecarServer = {
|
|
138
|
+
cacheDir,
|
|
139
|
+
handlers,
|
|
140
|
+
projectDir,
|
|
141
|
+
port: null,
|
|
142
|
+
portFilePath: getPortFilePath({ cacheDir }),
|
|
143
|
+
routes,
|
|
144
|
+
server: createSidecarServer({ projectDir, routes, handlers }),
|
|
145
|
+
startError: null,
|
|
146
|
+
startPromise: Promise.resolve(),
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
state.startPromise = startServer(state).catch((error: Error) => {
|
|
150
|
+
state.startError = error;
|
|
151
|
+
throw error;
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
state.startPromise.catch(() => {});
|
|
155
|
+
state.server.unref();
|
|
156
|
+
servers.set(cacheDir, state);
|
|
157
|
+
|
|
158
|
+
return state;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
async function startServer(state: SidecarServer) {
|
|
162
|
+
state.port = await startSidecarServer({
|
|
163
|
+
host: SIDECAR_HOST,
|
|
164
|
+
portFilePath: state.portFilePath,
|
|
165
|
+
server: state.server,
|
|
166
|
+
});
|
|
167
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
|
|
4
|
+
export type GetPortFilePathArgs = {
|
|
5
|
+
cacheDir: string;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export type GetRoutePathArgs = {
|
|
9
|
+
filePath: string;
|
|
10
|
+
projectDir: string;
|
|
11
|
+
relativePath?: string | null;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export type CreateSourceUrlArgs = {
|
|
15
|
+
baseUrl: string;
|
|
16
|
+
routePath: string;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export type NormalizeRoutePathArgs = {
|
|
20
|
+
routePath: string;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export type ReadCachedPortArgs = {
|
|
24
|
+
filePath: string;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export type WriteCachedPortArgs = {
|
|
28
|
+
filePath: string;
|
|
29
|
+
port: number;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export type IsPortUnavailableErrorArgs = {
|
|
33
|
+
error: unknown;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export function getPortFilePath(args: GetPortFilePathArgs) {
|
|
37
|
+
return path.join(args.cacheDir, 'sidecar', 'port.json');
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function getRoutePath(args: GetRoutePathArgs) {
|
|
41
|
+
const routePath = normalizeRoutePath(
|
|
42
|
+
args.relativePath || path.relative(args.projectDir, args.filePath),
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
return routePath || '/' + path.basename(args.filePath);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function normalizeSidecarRoutePath(args: NormalizeRoutePathArgs) {
|
|
49
|
+
if (args.routePath.startsWith('source://@')) {
|
|
50
|
+
return normalizeRoutePath(args.routePath.slice('source://'.length));
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
try {
|
|
54
|
+
const url = new URL(args.routePath, 'http://127.0.0.1');
|
|
55
|
+
return normalizeRoutePath(url.pathname);
|
|
56
|
+
} catch {
|
|
57
|
+
return normalizeRoutePath(args.routePath);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function createSourceUrl(args: CreateSourceUrlArgs) {
|
|
62
|
+
return `${args.baseUrl.replace(/\/+$/, '')}${encodeURI(args.routePath)}`;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function getRequestPathname(url: string | undefined) {
|
|
66
|
+
if (!url) return null;
|
|
67
|
+
|
|
68
|
+
try {
|
|
69
|
+
return decodeURI(new URL(url, 'http://127.0.0.1').pathname);
|
|
70
|
+
} catch {
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function readCachedPort(args: ReadCachedPortArgs) {
|
|
76
|
+
try {
|
|
77
|
+
const file = JSON.parse(readFileSync(args.filePath, 'utf8')) as { port?: unknown; };
|
|
78
|
+
const port = file.port;
|
|
79
|
+
return typeof port === 'number' && Number.isInteger(port) && port > 0 ? port : null;
|
|
80
|
+
} catch {
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function writeCachedPort(args: WriteCachedPortArgs) {
|
|
86
|
+
try {
|
|
87
|
+
mkdirSync(path.dirname(args.filePath), { recursive: true });
|
|
88
|
+
writeFileSync(args.filePath, JSON.stringify({ port: args.port }), 'utf8');
|
|
89
|
+
} catch {
|
|
90
|
+
// The sidecar still works if the sticky-port cache cannot be written.
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export function isPortUnavailableError(args: IsPortUnavailableErrorArgs) {
|
|
95
|
+
if (!(args.error instanceof Error)) return false;
|
|
96
|
+
|
|
97
|
+
const code = (args.error as NodeJS.ErrnoException).code;
|
|
98
|
+
return code === 'EADDRINUSE' || code === 'EACCES';
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function normalizeRoutePath(filePath: string) {
|
|
102
|
+
const normalized = filePath
|
|
103
|
+
.replace(/\\/g, '/')
|
|
104
|
+
.replace(/^(\.\.\/)+/, '')
|
|
105
|
+
.replace(/^\.?\//, '')
|
|
106
|
+
.replace(/\/+/g, '/');
|
|
107
|
+
|
|
108
|
+
return normalized ? `/${normalized}` : '';
|
|
109
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { CompilerOptions, DevSourcemapMode } from '../../compiler';
|
|
2
|
+
import type { BabelTransformSourceMap } from '../../compiler/transform';
|
|
3
|
+
import { getDefaultSourcemapUrl, type GetSourcemapFilePathFn } from '../../compiler/utils/sourcemap';
|
|
4
|
+
import type { SourcemapSidecar } from './sidecar';
|
|
5
|
+
|
|
6
|
+
export type BundlerSourceMap = BabelTransformSourceMap | undefined;
|
|
7
|
+
|
|
8
|
+
export function parseBundlerSourceMap(map: string | null | undefined): any {
|
|
9
|
+
if (!map) return null;
|
|
10
|
+
return JSON.parse(map) as Exclude<BabelTransformSourceMap, string | null | undefined>;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function resolveDevSourcemapMode(
|
|
14
|
+
mode: DevSourcemapMode | undefined,
|
|
15
|
+
dev: boolean,
|
|
16
|
+
): DevSourcemapMode {
|
|
17
|
+
return mode ?? (dev ? 'sidecarServer' : 'sourceUrl');
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function resolvePluginSourcemapFilePath(
|
|
21
|
+
getSourcemapFilePath: GetSourcemapFilePathFn | undefined,
|
|
22
|
+
sourcemapSidecar: SourcemapSidecar | null,
|
|
23
|
+
): GetSourcemapFilePathFn {
|
|
24
|
+
return (info) => {
|
|
25
|
+
const defaultSourceUrl = getDefaultSourcemapUrl(info);
|
|
26
|
+
|
|
27
|
+
const sourcePath = getSourcemapFilePath?.({
|
|
28
|
+
...info,
|
|
29
|
+
sourcePath: info.sourcePath,
|
|
30
|
+
sourceUrl: defaultSourceUrl,
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
const resolvedSourceUrl = sourcePath || defaultSourceUrl;
|
|
34
|
+
|
|
35
|
+
sourcemapSidecar?.registerSource(info.absolutePath, resolvedSourceUrl);
|
|
36
|
+
|
|
37
|
+
return resolvedSourceUrl;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function resolvePluginSourcemapOptions<T extends CompilerOptions>(
|
|
42
|
+
options: T,
|
|
43
|
+
sourcemapSidecar: SourcemapSidecar | null,
|
|
44
|
+
): T {
|
|
45
|
+
return {
|
|
46
|
+
...options,
|
|
47
|
+
getSourcemapFilePath: resolvePluginSourcemapFilePath(
|
|
48
|
+
options.getSourcemapFilePath,
|
|
49
|
+
sourcemapSidecar,
|
|
50
|
+
),
|
|
51
|
+
};
|
|
52
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { EXTRACTED_CSS_MARKER } from './constants';
|
|
2
|
+
|
|
3
|
+
export const RUNTIME_MODULE_ID = 'virtual:fluentic-style';
|
|
4
|
+
export const CSS_MODULE_ID = `${RUNTIME_MODULE_ID}.css`;
|
|
5
|
+
|
|
6
|
+
export const RESOLVED_RUNTIME_MODULE_ID = `\0${RUNTIME_MODULE_ID}`;
|
|
7
|
+
export const RESOLVED_CSS_MODULE_ID = `\0${CSS_MODULE_ID}`;
|
|
8
|
+
|
|
9
|
+
export const VIRTUAL_MODULE_REQUEST_PATTERN = `^${escapeRegex(RUNTIME_MODULE_ID)}(?:\\.css)?$`;
|
|
10
|
+
export const VIRTUAL_MODULE_REQUEST_REGEX = new RegExp(VIRTUAL_MODULE_REQUEST_PATTERN);
|
|
11
|
+
|
|
12
|
+
export function createRuntimeModuleSource(
|
|
13
|
+
extract: boolean,
|
|
14
|
+
cssModuleId?: string | null,
|
|
15
|
+
) {
|
|
16
|
+
return [
|
|
17
|
+
extract && cssModuleId && `import ${JSON.stringify(cssModuleId)};`,
|
|
18
|
+
'',
|
|
19
|
+
].filter(Boolean).join('\n');
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function createRuntimeImport() {
|
|
23
|
+
return `import ${JSON.stringify(RUNTIME_MODULE_ID)};\n`;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function prependRuntimeImport(code: string) {
|
|
27
|
+
if (code.includes(RUNTIME_MODULE_ID)) return code;
|
|
28
|
+
return createRuntimeImport() + code;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function isVirtualModuleRequest(id: string, moduleId: string) {
|
|
32
|
+
const normalized = normalizeVirtualModuleId(id);
|
|
33
|
+
|
|
34
|
+
return normalized === moduleId || normalized === `\0${moduleId}`;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function getVirtualModuleId(id: string) {
|
|
38
|
+
if (isVirtualModuleRequest(id, RUNTIME_MODULE_ID)) {
|
|
39
|
+
return RESOLVED_RUNTIME_MODULE_ID;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (isVirtualModuleRequest(id, CSS_MODULE_ID)) {
|
|
43
|
+
return RESOLVED_CSS_MODULE_ID;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function loadVirtualModule(
|
|
50
|
+
id: string,
|
|
51
|
+
extract: boolean,
|
|
52
|
+
cssModuleId: string | null,
|
|
53
|
+
) {
|
|
54
|
+
if (isVirtualModuleRequest(id, RUNTIME_MODULE_ID)) {
|
|
55
|
+
return createRuntimeModuleSource(extract, cssModuleId);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (isVirtualModuleRequest(id, CSS_MODULE_ID)) {
|
|
59
|
+
return EXTRACTED_CSS_MARKER;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function normalizeVirtualModuleId(id: string) {
|
|
66
|
+
const base = id.split('?')[0]?.split('#')[0] ?? id;
|
|
67
|
+
|
|
68
|
+
if (base.startsWith('/@id/__x00__')) {
|
|
69
|
+
return `\0${base.slice('/@id/__x00__'.length)}`;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (base.startsWith('/@id/')) {
|
|
73
|
+
return base.slice('/@id/'.length);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return base;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function escapeRegex(value: string) {
|
|
80
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
81
|
+
}
|