@fluentic/style 0.1.0-beta.1 → 0.1.0-beta.11
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 +156 -2
- package/README.md +181 -49
- package/atomic/atRule/utils.ts +3 -2
- package/atomic/className.ts +50 -12
- package/atomic/debug/className/className.ts +24 -8
- package/atomic/element.ts +5 -2
- package/atomic/rule.ts +11 -5
- package/atomic/scope.ts +19 -0
- package/atomic/theme.ts +44 -3
- package/atomic/token.ts +7 -4
- package/atomic/utils/cssIdent.ts +54 -0
- package/atomic/utils/cssVar.ts +19 -0
- package/atomic/utils/debug.ts +1 -1
- package/atomic/utils/format.ts +1 -1
- package/atomic/utils/hash.ts +14 -0
- package/atomic/utils/selector.ts +31 -1
- package/atomic/var.ts +3 -2
- package/builder/classname/class_name_builder.ts +491 -0
- package/builder/classname/fns.ts +77 -0
- package/builder/classname/index.ts +3 -0
- package/builder/classname/types.ts +41 -0
- package/builder/data/const.ts +8 -1
- package/builder/data/create.ts +52 -6
- package/builder/data/data.ts +33 -8
- package/builder/data/debug.ts +1 -0
- package/builder/data/index.ts +0 -1
- package/builder/data/is.ts +26 -3
- package/builder/data/merge/scope.ts +38 -38
- package/builder/data/merge/style.ts +115 -20
- package/builder/data/state.ts +17 -2
- package/builder/extract/index.ts +1 -0
- package/builder/extract/sheet.ts +30 -0
- package/builder/extract/token.ts +30 -14
- package/builder/extract/utils.ts +2 -0
- package/builder/extract/withTokens.ts +2 -1
- package/builder/selector_override.noop.ts +11 -0
- package/builder/selector_override.ts +31 -0
- package/builder/selector_override_core.ts +79 -0
- package/builder/style_builder.ts +144 -20
- package/builder/style_data.ts +25 -0
- package/builder/style_fns.ts +57 -57
- package/builder/token/data.ts +30 -0
- package/builder/token/index.ts +3 -0
- package/builder/token/name.ts +54 -0
- package/builder/token/symbols.ts +6 -0
- package/builder/types/alias.ts +44 -16
- package/builder/types/fns.ts +24 -16
- package/builder/types/types.ts +37 -7
- package/builder/utils.ts +1 -0
- package/compiler/compiler/compiler.ts +88 -14
- package/compiler/compiler/constants.ts +6 -0
- package/compiler/compiler/index.ts +1 -0
- package/compiler/compiler/types.ts +4 -1
- package/compiler/cssProp.ts +21 -0
- package/compiler/extract/extract.ts +42 -14
- package/compiler/extract/types.ts +2 -0
- package/compiler/index.ts +1 -0
- package/compiler/transform/cssProp/index.ts +1 -0
- package/compiler/transform/cssProp/plugin.ts +161 -0
- package/compiler/transform/debug/plugin.ts +93 -4
- package/compiler/transform/debug/transform.ts +2 -1
- package/compiler/transform/debug/utils/debug_data.ts +73 -0
- package/compiler/transform/evaluator/evaluator.ts +169 -32
- package/compiler/transform/evaluator/tracer.ts +48 -11
- package/compiler/transform/extract/chain/chain.ts +1370 -162
- package/compiler/transform/extract/chain/extract_chain.ts +12 -4
- package/compiler/transform/extract/chain/types.ts +3 -1
- package/compiler/transform/extract/plugin.ts +64 -6
- package/compiler/transform/extract/transform.ts +2 -1
- package/compiler/transform/extract/utils/replacement.ts +72 -2
- package/compiler/transform/extract/utils/state.ts +3 -0
- package/compiler/transform/extract/utils/theme.ts +6 -6
- package/compiler/transform/index.ts +1 -0
- package/compiler/transform/syntax/isStaticStyleValue.ts +15 -9
- package/compiler/transform/syntax/static_ids.ts +1 -1
- package/compiler/utils/constants.ts +12 -5
- package/compiler/utils/file_resolver.ts +2 -0
- package/compiler/utils/import_source.ts +19 -8
- package/compiler/utils/imports.ts +11 -1
- package/config/build.ts +9 -2
- package/config/config/check.ts +25 -0
- package/config/config/css.ts +18 -1
- package/config/config/debug.ts +24 -1
- package/config/config/dev.ts +17 -1
- package/config/configure.ts +19 -2
- package/config/types.ts +7 -0
- package/css/index.ts +2 -0
- package/css/sheet.ts +152 -0
- package/css/styleTarget.ts +251 -0
- package/dev/config.ts +2 -3
- package/dev/utils.ts +3 -3
- package/dialect/extracted/index.ts +5 -0
- package/dialect/index.ts +1 -0
- package/dialect/namedTokens.ts +153 -0
- package/dist/adapter/preact.js +2 -0
- package/dist/adapter/react.js +2 -0
- package/dist/adapter/solid.js +2 -0
- package/dist/className-yhJCGT0F.js +304 -0
- package/dist/className-yhJCGT0F.js.map +1 -0
- package/dist/combine-Bww7VnSr.js +1254 -0
- package/dist/combine-Bww7VnSr.js.map +1 -0
- package/dist/compiler/index.mjs +2 -2
- package/dist/{compiler-DENc3a2R.mjs → compiler-C3CEGGtI.mjs} +2335 -638
- package/dist/compiler-C3CEGGtI.mjs.map +1 -0
- package/dist/config/index.js +2 -2
- package/dist/config-BAEzRmSJ.js +6 -0
- package/dist/{config-Di2VYYKV.js.map → config-BAEzRmSJ.js.map} +1 -1
- package/dist/config-BKP5LOkt.js +35 -0
- package/dist/config-BKP5LOkt.js.map +1 -0
- package/dist/config-C5VWvTav.js +34 -0
- package/dist/config-C5VWvTav.js.map +1 -0
- package/dist/config-CB4lm2tM.js +1 -0
- package/dist/config-CDjbHwb-.js +6 -0
- package/dist/config-CDjbHwb-.js.map +1 -0
- package/dist/config-DNEnHEf3.js +36 -0
- package/dist/config-DNEnHEf3.js.map +1 -0
- package/dist/createTransformElement-D8fXZ3wA.js +34 -0
- package/dist/createTransformElement-D8fXZ3wA.js.map +1 -0
- package/dist/css-BDn0epJ8.js +1339 -0
- package/dist/css-BDn0epJ8.js.map +1 -0
- package/dist/css-CFxNrYt3.js +4040 -0
- package/dist/css-CFxNrYt3.js.map +1 -0
- package/dist/css-DEYgrj76.js +524 -0
- package/dist/css-DEYgrj76.js.map +1 -0
- package/dist/{runtime-CYqNCiaM.js → css-DWBWsyxZ.js} +16 -19
- package/dist/css-DWBWsyxZ.js.map +1 -0
- package/dist/css.js +2 -2
- package/dist/{css_extra-oIi3UEPK.js → css_extra-nTq_Gw0E.js} +2 -2
- package/dist/{css_extra-DlOnsnR1.js.map → css_extra-nTq_Gw0E.js.map} +1 -1
- package/dist/data-CDrS1Bq4.js +785 -0
- package/dist/data-CDrS1Bq4.js.map +1 -0
- package/dist/debug-BkVbf0Cz.js +52 -0
- package/dist/debug-BkVbf0Cz.js.map +1 -0
- package/dist/{debug-n2aZQBSa.js → debug-YuhEIQVO.js} +80 -4
- package/dist/debug-YuhEIQVO.js.map +1 -0
- package/dist/dev/rsc.js +10 -9
- package/dist/dev/rsc.js.map +1 -1
- package/dist/{dev-CcphAa3R.js → dev-0imWmSVb.js} +10 -10
- package/dist/dev-0imWmSVb.js.map +1 -0
- package/dist/dev.js +1 -1
- package/dist/dialect/extracted/index.js +2 -0
- package/dist/dialect/index.js +2 -0
- package/dist/{elementMarker-Bu7gDAkE.js → elementMarker-kvpMjB49.js} +164 -30
- package/dist/elementMarker-kvpMjB49.js.map +1 -0
- package/dist/entry/dev/adapter/preact.js +12 -0
- package/dist/entry/dev/adapter/preact.js.map +1 -0
- package/dist/entry/dev/adapter/react.js +12 -0
- package/dist/entry/dev/adapter/react.js.map +1 -0
- package/dist/entry/dev/adapter/solid.js +12 -0
- package/dist/entry/dev/adapter/solid.js.map +1 -0
- package/dist/entry/dev/css.js +3 -3
- package/dist/entry/dev/jsx-dev-runtime.js +2 -1
- package/dist/entry/dev/jsx-runtime.js +2 -1
- package/dist/entry/dev.js +13 -9
- package/dist/entry/prod/adapter/preact.js +12 -0
- package/dist/entry/prod/adapter/preact.js.map +1 -0
- package/dist/entry/prod/adapter/react.js +12 -0
- package/dist/entry/prod/adapter/react.js.map +1 -0
- package/dist/entry/prod/adapter/solid.js +12 -0
- package/dist/entry/prod/adapter/solid.js.map +1 -0
- package/dist/entry/prod/css.js +3 -3
- package/dist/entry/prod/extract.js +242 -3
- package/dist/entry/prod/extract.js.map +1 -0
- package/dist/entry/prod/jsx-dev-runtime.js +2 -2
- package/dist/entry/prod/jsx-runtime.js +2 -2
- package/dist/entry/prod/runtime.js +3 -4
- package/dist/entry/prod.js +84 -1201
- package/dist/entry/prod.js.map +1 -1
- package/dist/entry/rsc-dev/adapter/preact.js +13 -0
- package/dist/entry/rsc-dev/adapter/preact.js.map +1 -0
- package/dist/entry/rsc-dev/adapter/react.js +13 -0
- package/dist/entry/rsc-dev/adapter/react.js.map +1 -0
- package/dist/entry/rsc-dev/adapter/solid.js +13 -0
- package/dist/entry/rsc-dev/adapter/solid.js.map +1 -0
- package/dist/entry/rsc-dev/css.js +3 -3
- package/dist/entry/rsc-dev/dev.js +11 -13
- package/dist/entry/rsc-dev/dev.js.map +1 -1
- package/dist/entry/rsc-dev/jsx-dev-runtime.js +2 -2
- package/dist/entry/rsc-dev/jsx-runtime.js +2 -2
- package/dist/entry/rsc-dev.js +582 -664
- package/dist/entry/rsc-dev.js.map +1 -1
- package/dist/entry/rsc-prod/adapter/preact.js +2 -0
- package/dist/entry/rsc-prod/adapter/react.js +2 -0
- package/dist/entry/rsc-prod/adapter/solid.js +2 -0
- package/dist/entry/rsc-prod/css.js +9 -3
- package/dist/entry/rsc-prod/css.js.map +1 -0
- package/dist/entry/rsc-prod/jsx-dev-runtime.js +2 -2
- package/dist/entry/rsc-prod/jsx-runtime.js +2 -2
- package/dist/entry/rsc-prod/runtime.js +3 -4
- package/dist/entry/rsc-prod.js +242 -10
- package/dist/entry/rsc-prod.js.map +1 -0
- package/dist/{styleStore-Dea_WVbr.js → env-Cz8frh6e.js} +1335 -372
- package/dist/env-Cz8frh6e.js.map +1 -0
- package/dist/getClassName-9CsXbNls.js +545 -0
- package/dist/getClassName-9CsXbNls.js.map +1 -0
- package/dist/{utils-D7FAOyg6.js → getClassName-DGm-VNDo.js} +28 -65
- package/dist/getClassName-DGm-VNDo.js.map +1 -0
- package/dist/getClassName-Dtc4yyYI.js +47 -0
- package/dist/getClassName-Dtc4yyYI.js.map +1 -0
- package/dist/{getClassName-BlvXHYuf.js → getClassName-DtkplEIt.js} +56 -14
- package/dist/getClassName-DtkplEIt.js.map +1 -0
- package/dist/global-CAc9OjKx.js +14 -0
- package/dist/global-CAc9OjKx.js.map +1 -0
- package/dist/{format-3nKBE_5t.js → hash-Cr-LCWDt.js} +51 -29
- package/dist/hash-Cr-LCWDt.js.map +1 -0
- package/dist/index.js +10 -8
- package/dist/jsx/jsx-dev-runtime.js +2 -2
- package/dist/jsx/jsx-dev-runtime.server.js +1 -1
- package/dist/jsx/jsx-runtime.js +2 -2
- package/dist/jsx/jsx-runtime.server.js +1 -1
- package/dist/jsx-CVxpkS04.js +39 -0
- package/dist/jsx-CVxpkS04.js.map +1 -0
- package/dist/{jsx_dev_runtime-B6xs4by8.js → jsx_dev_runtime-D068tAsT.js} +2 -3
- package/dist/{jsx_dev_runtime-B6xs4by8.js.map → jsx_dev_runtime-D068tAsT.js.map} +1 -1
- package/dist/{jsx_runtime-iHLDwpcW.js → jsx_runtime-6Qa1lmz2.js} +2 -2
- package/dist/{jsx_runtime-iHLDwpcW.js.map → jsx_runtime-6Qa1lmz2.js.map} +1 -1
- package/dist/{jsx_runtime-04xfnsi7.js → jsx_runtime-DT1Tr9cH.js} +2 -3
- package/dist/{jsx_runtime-04xfnsi7.js.map → jsx_runtime-DT1Tr9cH.js.map} +1 -1
- package/dist/{loader-B5Kw0DD-.mjs → loader-_-VjzlrX.mjs} +13 -14
- package/dist/loader-_-VjzlrX.mjs.map +1 -0
- package/dist/{misc-DCdYYyhK.mjs → misc-B76PUnWe.mjs} +11 -6
- package/dist/misc-B76PUnWe.mjs.map +1 -0
- package/dist/namedTokens-5AayGokX.js +85 -0
- package/dist/namedTokens-5AayGokX.js.map +1 -0
- package/dist/plugin/farm/index.mjs +4 -3
- package/dist/plugin/farm/index.mjs.map +1 -1
- package/dist/plugin/nextjs/index.mjs +151 -31
- package/dist/plugin/nextjs/index.mjs.map +1 -1
- package/dist/plugin/nextjs/loader.mjs +4 -4
- package/dist/plugin/parcel/index.cjs +2 -0
- package/dist/plugin/parcel/index.mjs +3 -1
- package/dist/plugin/parcel/optimizer.cjs +3 -2
- package/dist/plugin/parcel/optimizer.cjs.map +1 -1
- package/dist/plugin/parcel/optimizer.mjs +3 -2
- package/dist/plugin/parcel/optimizer.mjs.map +1 -1
- package/dist/plugin/parcel/resolver.cjs +1 -1
- package/dist/plugin/parcel/resolver.mjs +2 -2
- package/dist/plugin/parcel/runtime.cjs +1 -1
- package/dist/plugin/parcel/runtime.mjs +1 -1
- package/dist/plugin/parcel/transformer.cjs +1 -1
- package/dist/plugin/parcel/transformer.mjs +2 -2
- package/dist/plugin/rspack/index.mjs +3 -2
- package/dist/plugin/rspack/index.mjs.map +1 -1
- package/dist/plugin/vite/index.mjs +13 -10
- package/dist/plugin/vite/index.mjs.map +1 -1
- package/dist/plugin/webpack/index.mjs +3 -2
- package/dist/plugin/webpack/loader.mjs +2 -2
- package/dist/presets/tailwind/index.js +995 -0
- package/dist/presets/tailwind/index.js.map +1 -0
- package/dist/{assert-BGdigdr5.js → presets-DSanixJV.js} +106 -2
- package/dist/presets-DSanixJV.js.map +1 -0
- package/dist/{registry-yHLRxyoo.mjs → registry-w8ET5R7v.mjs} +2 -2
- package/dist/{registry-yHLRxyoo.mjs.map → registry-w8ET5R7v.mjs.map} +1 -1
- package/dist/resolveClassNameRuntime-CJjlUP93.js +63 -0
- package/dist/resolveClassNameRuntime-CJjlUP93.js.map +1 -0
- package/dist/{rules-9HSO1pxL.js → rules-DaMaMHgb.js} +618 -138
- package/dist/rules-DaMaMHgb.js.map +1 -0
- package/dist/scope-CZdGAnl_.js +601 -0
- package/dist/scope-CZdGAnl_.js.map +1 -0
- package/dist/selector/index.js +1 -2
- package/dist/server.js +17 -11
- package/dist/server.js.map +1 -1
- package/dist/{shared-CxbHR89f.mjs → shared-C_cYxNzz.mjs} +4 -4
- package/dist/{shared-CxbHR89f.mjs.map → shared-C_cYxNzz.mjs.map} +1 -1
- package/dist/{shared-CBArHB9-.cjs → shared-PK52rW6T.cjs} +2338 -635
- package/dist/shared-PK52rW6T.cjs.map +1 -0
- package/dist/sheet-CxkO1Hwt.js +7 -0
- package/dist/sheet-CxkO1Hwt.js.map +1 -0
- package/dist/{sidecar-BFakLl0X.mjs → sidecar-BhvmXYsD.mjs} +3 -3
- package/dist/{sidecar-BFakLl0X.mjs.map → sidecar-BhvmXYsD.mjs.map} +1 -1
- package/dist/style-CAhAnRni.js +1129 -0
- package/dist/style-CAhAnRni.js.map +1 -0
- package/dist/{styleStore-DyNXBcUK.js → styleStore-BzLZwpwy.js} +8 -7
- package/dist/styleStore-BzLZwpwy.js.map +1 -0
- package/dist/styleStore-DaIJ4OPV.js +58 -0
- package/dist/styleStore-DaIJ4OPV.js.map +1 -0
- package/dist/token-D33mKTka.js +138 -0
- package/dist/token-D33mKTka.js.map +1 -0
- package/dist/{trace-Bu_qOqRy.js → trace-B3dpTRJp.js} +3 -3
- package/dist/{trace-Bu_qOqRy.js.map → trace-B3dpTRJp.js.map} +1 -1
- package/dist/{trace-CU0rvNYr.js → trace-c2WmBbmX.js} +2 -2
- package/dist/{trace-CU0rvNYr.js.map → trace-c2WmBbmX.js.map} +1 -1
- package/dist/transform-DSpimwwC.js +23 -0
- package/dist/transform-DSpimwwC.js.map +1 -0
- package/dist/{utils-Bdbqn0f8.mjs → utils-DND33M6y.mjs} +3 -3
- package/dist/{utils-Bdbqn0f8.mjs.map → utils-DND33M6y.mjs.map} +1 -1
- package/dist/utils-DZK0mfmY.js +42 -0
- package/dist/utils-DZK0mfmY.js.map +1 -0
- package/dist/utils-D_XgtMtn.js +72 -0
- package/dist/utils-D_XgtMtn.js.map +1 -0
- package/dist/utils-DxCpyV2E.js +62 -0
- package/dist/utils-DxCpyV2E.js.map +1 -0
- package/dist/{utils-BbehLOby.js → utils-H1VInWpd.js} +407 -234
- package/dist/utils-H1VInWpd.js.map +1 -0
- package/dist/utils-NdisireF.mjs +182 -0
- package/dist/utils-NdisireF.mjs.map +1 -0
- package/dist/utils.js +4 -4
- package/dist/utils.js.map +1 -1
- package/dist/value-CK0-Xbov.js +160 -0
- package/dist/value-CK0-Xbov.js.map +1 -0
- package/dist/{webpack-Dh6lox2l.mjs → webpack-D7QO0bKN.mjs} +5 -5
- package/dist/webpack-D7QO0bKN.mjs.map +1 -0
- package/entry/dev/adapter/preact.ts +8 -0
- package/entry/dev/adapter/react.ts +8 -0
- package/entry/dev/adapter/solid.ts +8 -0
- package/entry/dev/config.ts +1 -1
- package/entry/dev/index.ts +1 -0
- package/entry/dev/jsx_dev_runtime.ts +1 -0
- package/entry/dev/jsx_runtime.ts +1 -0
- package/entry/dev/sheet.ts +4 -0
- package/entry/prod/adapter/preact.ts +8 -0
- package/entry/prod/adapter/react.ts +8 -0
- package/entry/prod/adapter/solid.ts +8 -0
- package/entry/prod/config_debug.ts +2 -0
- package/entry/prod/index.ts +1 -1
- package/entry/prod/runtime.ts +4 -2
- package/entry/rsc_dev/adapter/preact.ts +9 -0
- package/entry/rsc_dev/adapter/react.ts +9 -0
- package/entry/rsc_dev/adapter/solid.ts +9 -0
- package/entry/rsc_dev/config.ts +1 -1
- package/entry/rsc_dev/server.ts +1 -1
- package/entry/rsc_prod/adapter/preact.ts +1 -0
- package/entry/rsc_prod/adapter/react.ts +1 -0
- package/entry/rsc_prod/adapter/solid.ts +1 -0
- package/entry/rsc_prod/config_debug.ts +6 -0
- package/entry/rsc_prod/index.ts +1 -1
- package/entry/rsc_prod/runtime.ts +1 -1
- package/entry/rsc_prod/server.ts +1 -1
- package/entry/shared/config_debug.ts +9 -0
- package/entry/shared/config_dev.ts +14 -0
- package/entry/shared/dev.ts +11 -2
- package/entry/shared/utils.ts +28 -0
- package/jsx/types/index.ts +1 -0
- package/jsx/types/preact.ts +14 -0
- package/jsx/{types.ts → types/react.ts} +2 -2
- package/jsx/types/solid.ts +32 -0
- package/package.json +110 -8
- package/plugin/bundler/farm/plugin.ts +2 -0
- package/plugin/bundler/parcel/optimizer.ts +1 -0
- package/plugin/bundler/parcel/plugin.ts +2 -0
- package/plugin/bundler/rspack/plugin.ts +1 -0
- package/plugin/bundler/vite/plugin.ts +5 -9
- package/plugin/bundler/vite/state.ts +11 -6
- package/plugin/bundler/webpack/plugin.ts +2 -1
- package/plugin/bundler/webpack/shared/loader.ts +9 -7
- package/plugin/nextjs/plugin.ts +249 -35
- package/plugin/nextjs/types.ts +1 -2
- package/plugin/nextjs/utils.ts +121 -0
- package/plugin/utils/compiler.ts +2 -0
- package/plugin/utils/runtimeEntry.ts +15 -2
- package/presets/tailwind/classname/index.ts +2 -0
- package/presets/tailwind/classname/transform.ts +239 -0
- package/presets/tailwind/classname/types.ts +124 -0
- package/presets/tailwind/index.ts +5 -0
- package/presets/tailwind/selectors.ts +27 -0
- package/presets/tailwind/style/index.ts +2 -0
- package/presets/tailwind/style/transform.ts +436 -0
- package/presets/tailwind/style/types.ts +346 -0
- package/presets/tailwind/theme.ts +479 -0
- package/presets/tailwind/types.ts +147 -0
- package/runtime/adapter/utils.ts +120 -0
- package/runtime/core/cache/combine.ts +76 -28
- package/runtime/core/cache/combineRuntime.ts +4 -0
- package/runtime/core/cache/index.ts +2 -1
- package/runtime/core/cache/item.ts +32 -13
- package/runtime/core/cache/itemWithResolver.ts +44 -0
- package/runtime/core/cache/pool.ts +16 -31
- package/runtime/core/cache/prop.ts +10 -8
- package/runtime/core/cache/result.ts +2 -2
- package/runtime/core/cache/stateItem.ts +16 -1
- package/runtime/core/cache/token.ts +20 -0
- package/runtime/core/cache/tokenValues.ts +19 -11
- package/runtime/core/combinedStyle.ts +4 -4
- package/runtime/extract/combineStyle.ts +211 -0
- package/runtime/extract/getClassName.ts +55 -23
- package/runtime/extract/index.ts +4 -2
- package/runtime/extract/token.ts +41 -0
- package/runtime/extract/tokenResolver.ts +17 -0
- package/runtime/index.ts +8 -1
- package/runtime/rsc/getClassName.ts +4 -0
- package/runtime/rsc/observer.ts +4 -0
- package/runtime/rsc/styleStore.ts +18 -7
- package/runtime/sheet/rule.ts +16 -12
- package/runtime/sheet/rules.ts +8 -3
- package/runtime/style/scope.ts +0 -24
- package/runtime/style/style.ts +181 -6
- package/runtime/types.ts +6 -4
- package/sheet/dev/dev_layer.ts +18 -7
- package/sheet/dev/dev_sort.ts +45 -11
- package/sheet/prod.ts +18 -7
- package/sheet/types.ts +2 -0
- package/sheet/utils/layer.ts +33 -0
- package/style/classname.ts +47 -0
- package/style/important.ts +19 -0
- package/style/index.ts +3 -0
- package/style/style.ts +47 -16
- package/style/theme.ts +4 -3
- package/style/token.ts +26 -21
- package/style/tokens.ts +18 -12
- package/style/transform.ts +41 -2
- package/style/types.ts +6 -4
- package/style/utils/expose.ts +4 -3
- package/style/value.ts +26 -11
- package/style/valueRef.ts +1 -1
- package/style/weight.ts +21 -0
- package/utils/global.ts +1 -3
- package/utils/hash.ts +4 -0
- package/utils/symbol.ts +3 -0
- package/atomic/layer/README.md +0 -116
- package/atomic/utils/css.ts +0 -49
- package/dist/assert-BGdigdr5.js.map +0 -1
- package/dist/className-C1Ht5Wvv.js +0 -144
- package/dist/className-C1Ht5Wvv.js.map +0 -1
- package/dist/className-DC2Cq8p3.js +0 -251
- package/dist/className-DC2Cq8p3.js.map +0 -1
- package/dist/compiler-DENc3a2R.mjs.map +0 -1
- package/dist/config-BryWDfQX.js +0 -25
- package/dist/config-BryWDfQX.js.map +0 -1
- package/dist/config-DKHXWhe1.js +0 -1
- package/dist/config-Di2VYYKV.js +0 -6
- package/dist/config-DloHOG6I.js +0 -13
- package/dist/config-DloHOG6I.js.map +0 -1
- package/dist/css-BowBszUt.js +0 -243
- package/dist/css-BowBszUt.js.map +0 -1
- package/dist/css-ByOrugEX.js +0 -805
- package/dist/css-ByOrugEX.js.map +0 -1
- package/dist/css-DcazYor9.js +0 -235
- package/dist/css-DcazYor9.js.map +0 -1
- package/dist/css_extra-DlOnsnR1.js +0 -8
- package/dist/css_extra-oIi3UEPK.js.map +0 -1
- package/dist/data-BsqOa5br.js +0 -473
- package/dist/data-BsqOa5br.js.map +0 -1
- package/dist/debug-BAw63qX6.js +0 -15
- package/dist/debug-BAw63qX6.js.map +0 -1
- package/dist/debug-DGki_v7g.js +0 -15
- package/dist/debug-DGki_v7g.js.map +0 -1
- package/dist/debug-n2aZQBSa.js.map +0 -1
- package/dist/dev-CcphAa3R.js.map +0 -1
- package/dist/dev-DfBbuLeE.js +0 -71
- package/dist/dev-DfBbuLeE.js.map +0 -1
- package/dist/elementMarker-Bu7gDAkE.js.map +0 -1
- package/dist/extract-CzWJeQi8.js +0 -121
- package/dist/extract-CzWJeQi8.js.map +0 -1
- package/dist/extract-DEwSDJ9Z.js +0 -2
- package/dist/format-3nKBE_5t.js.map +0 -1
- package/dist/getClassName-BlvXHYuf.js.map +0 -1
- package/dist/global-CvfmFLsK.js +0 -11
- package/dist/global-CvfmFLsK.js.map +0 -1
- package/dist/jsx-CwTeyUxr.js +0 -39
- package/dist/jsx-CwTeyUxr.js.map +0 -1
- package/dist/jsx-D2BksHSv.js +0 -38
- package/dist/jsx-D2BksHSv.js.map +0 -1
- package/dist/layer-D1SaH07m.js +0 -94
- package/dist/layer-D1SaH07m.js.map +0 -1
- package/dist/loader-B5Kw0DD-.mjs.map +0 -1
- package/dist/misc-DCdYYyhK.mjs.map +0 -1
- package/dist/presets-BhXa232U.js +0 -108
- package/dist/presets-BhXa232U.js.map +0 -1
- package/dist/property-CnLFt5kx.js +0 -406
- package/dist/property-CnLFt5kx.js.map +0 -1
- package/dist/rules-9HSO1pxL.js.map +0 -1
- package/dist/runtime-CYqNCiaM.js.map +0 -1
- package/dist/shared-CBArHB9-.cjs.map +0 -1
- package/dist/style-B-6jHipw.js +0 -5
- package/dist/style-B1UUqjj5.js +0 -743
- package/dist/style-B1UUqjj5.js.map +0 -1
- package/dist/style-DgHbdbdF.js +0 -752
- package/dist/style-DgHbdbdF.js.map +0 -1
- package/dist/style-v2bf70TZ.js +0 -1269
- package/dist/style-v2bf70TZ.js.map +0 -1
- package/dist/styleStore-Dea_WVbr.js.map +0 -1
- package/dist/styleStore-DyNXBcUK.js.map +0 -1
- package/dist/token-CKXUECuU.js +0 -76
- package/dist/token-CKXUECuU.js.map +0 -1
- package/dist/token-u_tM-mtg.js +0 -204
- package/dist/token-u_tM-mtg.js.map +0 -1
- package/dist/utils-BbehLOby.js.map +0 -1
- package/dist/utils-CEaq_c-A.mjs +0 -97
- package/dist/utils-CEaq_c-A.mjs.map +0 -1
- package/dist/utils-CWNHx4EC.js +0 -170
- package/dist/utils-CWNHx4EC.js.map +0 -1
- package/dist/utils-D7FAOyg6.js.map +0 -1
- package/dist/value-BR4e2MKt.js +0 -910
- package/dist/value-BR4e2MKt.js.map +0 -1
- package/dist/value-E8rEv2Oe.js +0 -136
- package/dist/value-E8rEv2Oe.js.map +0 -1
- package/dist/valueRef-lshFk1Cs.js +0 -16
- package/dist/valueRef-lshFk1Cs.js.map +0 -1
- package/dist/webpack-Dh6lox2l.mjs.map +0 -1
- package/dist/withTokens-LRidu3Vc.js +0 -95
- package/dist/withTokens-LRidu3Vc.js.map +0 -1
package/plugin/nextjs/plugin.ts
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import type { NextConfig } from 'next';
|
|
2
2
|
import { PHASE_DEVELOPMENT_SERVER } from 'next/constants';
|
|
3
|
+
import { createHash } from 'node:crypto';
|
|
3
4
|
import fs from 'node:fs';
|
|
4
5
|
import path from 'node:path';
|
|
5
|
-
import type { Compiler, RuleSetRule } from 'webpack';
|
|
6
|
+
import type { Compilation, Compiler, RuleSetRule } from 'webpack';
|
|
6
7
|
import type { BuildConfig, BuildDevConfig } from '../../config/build';
|
|
7
8
|
import { isPromiseLike } from '../../utils/object';
|
|
8
9
|
import {
|
|
9
10
|
BUNDLE_CSS_FILE,
|
|
10
11
|
createCompilerId,
|
|
11
12
|
createFileCssCache,
|
|
13
|
+
createFileCssContentHash,
|
|
12
14
|
createPluginCompiler,
|
|
13
15
|
DEFAULT_TRANSFORM_EXCLUDE,
|
|
14
16
|
DEFAULT_TRANSFORM_INCLUDE,
|
|
@@ -42,6 +44,7 @@ import {
|
|
|
42
44
|
createNextBuildConfig,
|
|
43
45
|
createNextBuildDevConfig,
|
|
44
46
|
createNextConfigHash,
|
|
47
|
+
createSerializableImportSources,
|
|
45
48
|
getNextCacheDir,
|
|
46
49
|
getNextPrecollectCacheSubdir,
|
|
47
50
|
getTransformLoaderPath,
|
|
@@ -49,15 +52,16 @@ import {
|
|
|
49
52
|
type NextLoaderState,
|
|
50
53
|
nextRegistry,
|
|
51
54
|
removeUndefinedValues,
|
|
52
|
-
replaceCssMarkerAsset,
|
|
53
55
|
resolveNextCompilerOptions,
|
|
56
|
+
replaceCssMarkerAsset,
|
|
54
57
|
} from './utils';
|
|
55
58
|
|
|
59
|
+
export { CssPropPresets } from '../utils';
|
|
60
|
+
export type { CompilerCssPropOptions } from '../utils';
|
|
61
|
+
|
|
56
62
|
export default plugin;
|
|
57
63
|
|
|
58
64
|
const TURBOPACK_TRANSFORM_EXTENSIONS: readonly string[] = ['*.ts', '*.tsx', '*.js', '*.jsx'];
|
|
59
|
-
const clearedPrecollectCacheRoots = new Set<string>();
|
|
60
|
-
|
|
61
65
|
type NextPhaseState = {
|
|
62
66
|
buildConfig: BuildConfig;
|
|
63
67
|
buildDevConfig: BuildDevConfig | null;
|
|
@@ -107,17 +111,20 @@ function createNextConfig(
|
|
|
107
111
|
phaseState.configHash = createNextConfigHash(
|
|
108
112
|
phaseState.buildConfig,
|
|
109
113
|
phaseState.dev,
|
|
114
|
+
options.importSources,
|
|
110
115
|
);
|
|
111
116
|
|
|
112
117
|
let sidecar: SourcemapSidecar | null = null;
|
|
113
118
|
|
|
114
119
|
if (dev) {
|
|
115
|
-
const
|
|
120
|
+
const getDevCss = () => cssCache.getCss({
|
|
121
|
+
...phaseState.buildConfig.css,
|
|
122
|
+
configHash: phaseState.configHash,
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
const route: SidecarRouteHandler = async () => ({
|
|
116
126
|
contentType: 'text/css; charset=utf-8',
|
|
117
|
-
body:
|
|
118
|
-
...phaseState.buildConfig.css,
|
|
119
|
-
configHash: phaseState.configHash,
|
|
120
|
-
}),
|
|
127
|
+
body: await waitForDevCss(getDevCss),
|
|
121
128
|
});
|
|
122
129
|
|
|
123
130
|
sidecar = getSourcemapSidecar({
|
|
@@ -143,6 +150,22 @@ function createNextConfig(
|
|
|
143
150
|
: finish();
|
|
144
151
|
}
|
|
145
152
|
|
|
153
|
+
async function waitForDevCss(getCss: () => string) {
|
|
154
|
+
let css = getCss();
|
|
155
|
+
if (css) return css;
|
|
156
|
+
|
|
157
|
+
const deadline = Date.now() + 5000;
|
|
158
|
+
|
|
159
|
+
while (Date.now() < deadline) {
|
|
160
|
+
await new Promise((resolve) => setTimeout(resolve, 25));
|
|
161
|
+
|
|
162
|
+
css = getCss();
|
|
163
|
+
if (css) return css;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
return css;
|
|
167
|
+
}
|
|
168
|
+
|
|
146
169
|
function createFluenticNextConfigResolved(
|
|
147
170
|
nextConfig: NextConfig,
|
|
148
171
|
options: PluginOptions,
|
|
@@ -159,7 +182,7 @@ function createFluenticNextConfigResolved(
|
|
|
159
182
|
const projectDir = process.cwd();
|
|
160
183
|
|
|
161
184
|
const devCssHref = dev && sidecar
|
|
162
|
-
?
|
|
185
|
+
? DEV_CSS_ROUTE
|
|
163
186
|
: null;
|
|
164
187
|
|
|
165
188
|
const turbopackCompilerId = createCompilerId(NEXT_COMPILER_IDS.turbopack);
|
|
@@ -201,6 +224,7 @@ function createFluenticNextConfigResolved(
|
|
|
201
224
|
return {
|
|
202
225
|
...nextConfig,
|
|
203
226
|
env: nextConfig.env,
|
|
227
|
+
rewrites: createNextRewrites(nextConfig.rewrites, dev && sidecar ? sidecar : null),
|
|
204
228
|
compiler: {
|
|
205
229
|
...originalCompiler,
|
|
206
230
|
define: {
|
|
@@ -243,6 +267,7 @@ function createFluenticNextConfigResolved(
|
|
|
243
267
|
cssAliases: turbopackCssAliases,
|
|
244
268
|
dev,
|
|
245
269
|
devCssHref,
|
|
270
|
+
options,
|
|
246
271
|
projectDir,
|
|
247
272
|
}),
|
|
248
273
|
webpack(config: WebpackConfiguration, context: WebpackConfigContext) {
|
|
@@ -299,6 +324,7 @@ function createFluenticNextConfigResolved(
|
|
|
299
324
|
cssOutput: options.cssOutput,
|
|
300
325
|
cssCache,
|
|
301
326
|
dev: context.dev,
|
|
327
|
+
filter: state.filter,
|
|
302
328
|
sidecar,
|
|
303
329
|
});
|
|
304
330
|
|
|
@@ -307,6 +333,45 @@ function createFluenticNextConfigResolved(
|
|
|
307
333
|
};
|
|
308
334
|
}
|
|
309
335
|
|
|
336
|
+
function createNextRewrites(
|
|
337
|
+
originalRewrites: NextConfig['rewrites'],
|
|
338
|
+
sidecar: SourcemapSidecar | null,
|
|
339
|
+
): NextConfig['rewrites'] {
|
|
340
|
+
if (!sidecar) return originalRewrites;
|
|
341
|
+
|
|
342
|
+
return async () => {
|
|
343
|
+
await sidecar.ensureStarted();
|
|
344
|
+
|
|
345
|
+
const devCssRewrite = {
|
|
346
|
+
source: DEV_CSS_ROUTE,
|
|
347
|
+
destination: sidecar.getRouteUrl(DEV_CSS_ROUTE),
|
|
348
|
+
};
|
|
349
|
+
|
|
350
|
+
const original = await originalRewrites?.();
|
|
351
|
+
|
|
352
|
+
if (!original) {
|
|
353
|
+
return {
|
|
354
|
+
beforeFiles: [devCssRewrite],
|
|
355
|
+
afterFiles: [],
|
|
356
|
+
fallback: [],
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
if (Array.isArray(original)) {
|
|
361
|
+
return {
|
|
362
|
+
beforeFiles: [devCssRewrite],
|
|
363
|
+
afterFiles: original,
|
|
364
|
+
fallback: [],
|
|
365
|
+
};
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
return {
|
|
369
|
+
...original,
|
|
370
|
+
beforeFiles: [devCssRewrite, ...(original.beforeFiles ?? [])],
|
|
371
|
+
};
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
|
|
310
375
|
function getImportableCssCacheDir(projectDir: string) {
|
|
311
376
|
return path.join(projectDir, PLUGIN_CACHE_DIR);
|
|
312
377
|
}
|
|
@@ -322,6 +387,7 @@ function createTurbopackConfig(
|
|
|
322
387
|
cssAliases: Record<string, string>;
|
|
323
388
|
dev: boolean;
|
|
324
389
|
devCssHref: string | null;
|
|
390
|
+
options: PluginOptions;
|
|
325
391
|
projectDir: string;
|
|
326
392
|
},
|
|
327
393
|
): TurbopackConfig {
|
|
@@ -351,12 +417,16 @@ function mergeTurbopackRules(
|
|
|
351
417
|
cssAliases: Record<string, string>;
|
|
352
418
|
dev: boolean;
|
|
353
419
|
devCssHref: string | null;
|
|
420
|
+
options: PluginOptions;
|
|
354
421
|
projectDir: string;
|
|
355
422
|
},
|
|
356
423
|
): TurbopackRules {
|
|
424
|
+
const compilerOptions = createSerializableTurbopackCompilerOptions(args.options);
|
|
425
|
+
|
|
357
426
|
const loaderItem: TurbopackLoaderItem = {
|
|
358
427
|
loader: LOADER_IMPORT_PATH,
|
|
359
428
|
options: removeUndefinedValues({
|
|
429
|
+
...compilerOptions,
|
|
360
430
|
buildConfig: args.buildConfig,
|
|
361
431
|
buildDevConfig: args.buildDevConfig,
|
|
362
432
|
cacheDir: args.cacheDir,
|
|
@@ -379,6 +449,55 @@ function mergeTurbopackRules(
|
|
|
379
449
|
return nextRules as TurbopackRules;
|
|
380
450
|
}
|
|
381
451
|
|
|
452
|
+
function createSerializableTurbopackCompilerOptions(
|
|
453
|
+
options: PluginOptions,
|
|
454
|
+
): Partial<PluginOptions> {
|
|
455
|
+
return removeUndefinedValues({
|
|
456
|
+
css: options.css,
|
|
457
|
+
cssProp: options.cssProp,
|
|
458
|
+
dev: options.dev,
|
|
459
|
+
hoist: options.hoist,
|
|
460
|
+
importSources: createSerializableTurbopackImportSources(options.importSources),
|
|
461
|
+
});
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
function createSerializableTurbopackImportSources(
|
|
465
|
+
importSources: PluginOptions['importSources'],
|
|
466
|
+
): PluginOptions['importSources'] | undefined {
|
|
467
|
+
const serialized = createSerializableImportSources(importSources);
|
|
468
|
+
if (!serialized) return undefined;
|
|
469
|
+
|
|
470
|
+
const result = serialized.filter((entry) => isSerializableLoaderValue(entry));
|
|
471
|
+
return result.length ? result : undefined;
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
function isSerializableLoaderValue(value: unknown): boolean {
|
|
475
|
+
if (value === null) return true;
|
|
476
|
+
|
|
477
|
+
const valueType = typeof value;
|
|
478
|
+
|
|
479
|
+
if (
|
|
480
|
+
valueType === 'string' ||
|
|
481
|
+
valueType === 'number' ||
|
|
482
|
+
valueType === 'boolean'
|
|
483
|
+
) {
|
|
484
|
+
return true;
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
if (valueType !== 'object') return false;
|
|
488
|
+
|
|
489
|
+
if (Array.isArray(value)) {
|
|
490
|
+
return value.every((item) => isSerializableLoaderValue(item));
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
const prototype = Object.getPrototypeOf(value);
|
|
494
|
+
if (prototype !== Object.prototype && prototype !== null) return false;
|
|
495
|
+
|
|
496
|
+
return Object.values(value as Record<string, unknown>).every((item) =>
|
|
497
|
+
isSerializableLoaderValue(item),
|
|
498
|
+
);
|
|
499
|
+
}
|
|
500
|
+
|
|
382
501
|
function prependTurbopackLoader(rule: unknown, loader: TurbopackLoaderItem) {
|
|
383
502
|
if (!rule || typeof rule !== 'object' || Array.isArray(rule)) {
|
|
384
503
|
return { loaders: [loader] };
|
|
@@ -428,41 +547,61 @@ function patchTurbopackExtractedCss(args: {
|
|
|
428
547
|
distDir: string;
|
|
429
548
|
projectDir: string;
|
|
430
549
|
}) {
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
const distDir = path.isAbsolute(args.distDir)
|
|
434
|
-
? args.distDir
|
|
435
|
-
: path.join(args.projectDir, args.distDir);
|
|
550
|
+
const distDir = path.resolve(args.projectDir, args.distDir);
|
|
551
|
+
const renamed = new Map<string, string>();
|
|
436
552
|
|
|
437
|
-
for (const filePath of
|
|
553
|
+
for (const filePath of findBuildFiles(path.join(distDir, 'static'), /\.css$/)) {
|
|
438
554
|
const source = fs.readFileSync(filePath, 'utf8');
|
|
439
555
|
if (!source.includes(EXTRACTED_CSS_MARKER)) continue;
|
|
440
556
|
|
|
441
|
-
|
|
557
|
+
const css = source.split(EXTRACTED_CSS_MARKER).join(args.css);
|
|
558
|
+
const hash = createHash('sha256').update(css).digest('hex').slice(0, 32);
|
|
559
|
+
const asset = path.relative(distDir, filePath).split(path.sep).join('/');
|
|
560
|
+
const hashedAsset = path.posix.join(path.posix.dirname(asset), hash + '.css');
|
|
561
|
+
fs.writeFileSync(path.join(distDir, hashedAsset), css, 'utf8');
|
|
562
|
+
renamed.set(asset, hashedAsset);
|
|
442
563
|
}
|
|
443
|
-
}
|
|
444
564
|
|
|
445
|
-
|
|
446
|
-
|
|
565
|
+
if (!renamed.size) return;
|
|
566
|
+
|
|
567
|
+
// Update Next's manifests before it renders HTML and RSC payloads. The App
|
|
568
|
+
// Router can also embed the stylesheet directly in its client reference manifest.
|
|
569
|
+
const manifestName = /manifest.*\.(js|json)$/i;
|
|
570
|
+
const manifests = [
|
|
571
|
+
...fs.readdirSync(distDir).filter((name) => manifestName.test(name)).map((name) => path.join(distDir, name)),
|
|
572
|
+
...findBuildFiles(path.join(distDir, 'server'), manifestName),
|
|
573
|
+
...findBuildFiles(path.join(distDir, 'static'), /^_buildManifest\.js$/),
|
|
574
|
+
];
|
|
575
|
+
const inlineCss = JSON.stringify(args.css).slice(1, -1);
|
|
576
|
+
for (const filePath of manifests) {
|
|
577
|
+
const source = fs.readFileSync(filePath, 'utf8');
|
|
578
|
+
let updated = source;
|
|
579
|
+
|
|
580
|
+
for (const [asset, hashedAsset] of renamed) {
|
|
581
|
+
updated = updated.split(asset).join(hashedAsset);
|
|
582
|
+
}
|
|
583
|
+
if (updated !== source) {
|
|
584
|
+
fs.writeFileSync(filePath, updated.split(EXTRACTED_CSS_MARKER).join(inlineCss), 'utf8');
|
|
585
|
+
}
|
|
586
|
+
}
|
|
447
587
|
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
} catch {
|
|
451
|
-
return [];
|
|
588
|
+
for (const asset of renamed.keys()) {
|
|
589
|
+
fs.unlinkSync(path.join(distDir, asset));
|
|
452
590
|
}
|
|
591
|
+
}
|
|
453
592
|
|
|
454
|
-
|
|
593
|
+
function findBuildFiles(dir: string, pattern: RegExp): string[] {
|
|
594
|
+
if (!fs.existsSync(dir)) return [];
|
|
455
595
|
|
|
456
|
-
|
|
596
|
+
const files: string[] = [];
|
|
597
|
+
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
457
598
|
const filePath = path.join(dir, entry.name);
|
|
458
|
-
|
|
459
599
|
if (entry.isDirectory()) {
|
|
460
|
-
files.push(...
|
|
461
|
-
} else if (entry.isFile() && entry.name
|
|
600
|
+
files.push(...findBuildFiles(filePath, pattern));
|
|
601
|
+
} else if (entry.isFile() && pattern.test(entry.name)) {
|
|
462
602
|
files.push(filePath);
|
|
463
603
|
}
|
|
464
604
|
}
|
|
465
|
-
|
|
466
605
|
return files;
|
|
467
606
|
}
|
|
468
607
|
|
|
@@ -475,6 +614,7 @@ function addLifecyclePlugin(
|
|
|
475
614
|
cssOutput: PluginCssOutputOptions | undefined;
|
|
476
615
|
cssCache: ReturnType<typeof createFileCssCache>;
|
|
477
616
|
dev: boolean;
|
|
617
|
+
filter: NextLoaderState['filter'];
|
|
478
618
|
sidecar: SourcemapSidecar | null;
|
|
479
619
|
},
|
|
480
620
|
) {
|
|
@@ -482,11 +622,6 @@ function addLifecyclePlugin(
|
|
|
482
622
|
apply(webpackCompiler: Compiler) {
|
|
483
623
|
webpackCompiler.hooks.beforeRun.tapPromise(PLUGIN_NAME, async () => {
|
|
484
624
|
await args.sidecar?.ensureStarted();
|
|
485
|
-
|
|
486
|
-
if (!args.dev && !clearedPrecollectCacheRoots.has(args.cssCache.rootDir)) {
|
|
487
|
-
clearedPrecollectCacheRoots.add(args.cssCache.rootDir);
|
|
488
|
-
args.cssCache.clear();
|
|
489
|
-
}
|
|
490
625
|
});
|
|
491
626
|
|
|
492
627
|
webpackCompiler.hooks.watchRun.tapPromise(PLUGIN_NAME, async (watchCompiler) => {
|
|
@@ -507,6 +642,8 @@ function addLifecyclePlugin(
|
|
|
507
642
|
stage: webpackCompiler.webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS,
|
|
508
643
|
},
|
|
509
644
|
async () => {
|
|
645
|
+
precollectProductionCssFromCompilation(args, compilation, webpackCompiler);
|
|
646
|
+
|
|
510
647
|
const css = await transformCssOutput(
|
|
511
648
|
args.cssCache.getCss({
|
|
512
649
|
...args.buildConfig.css,
|
|
@@ -530,3 +667,80 @@ function addLifecyclePlugin(
|
|
|
530
667
|
},
|
|
531
668
|
});
|
|
532
669
|
}
|
|
670
|
+
|
|
671
|
+
function precollectProductionCssFromCompilation(
|
|
672
|
+
args: {
|
|
673
|
+
configHash: string;
|
|
674
|
+
compiler: NextLoaderState['compiler'];
|
|
675
|
+
cssCache: ReturnType<typeof createFileCssCache>;
|
|
676
|
+
dev: boolean;
|
|
677
|
+
filter: NextLoaderState['filter'];
|
|
678
|
+
},
|
|
679
|
+
compilation: Compilation,
|
|
680
|
+
webpackCompiler: Compiler,
|
|
681
|
+
) {
|
|
682
|
+
if (args.dev) return;
|
|
683
|
+
|
|
684
|
+
const existingCss = args.cssCache.getCss({
|
|
685
|
+
configHash: args.configHash,
|
|
686
|
+
});
|
|
687
|
+
|
|
688
|
+
if (existingCss) return;
|
|
689
|
+
|
|
690
|
+
const files = getCompilationSourceFiles(compilation, webpackCompiler.context, args.filter);
|
|
691
|
+
|
|
692
|
+
for (const filePath of files) {
|
|
693
|
+
let code: string;
|
|
694
|
+
|
|
695
|
+
try {
|
|
696
|
+
code = fs.readFileSync(filePath, 'utf8');
|
|
697
|
+
} catch {
|
|
698
|
+
continue;
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
const result = args.compiler.compileExtract({
|
|
702
|
+
code,
|
|
703
|
+
filePath,
|
|
704
|
+
sourcemap: null,
|
|
705
|
+
});
|
|
706
|
+
|
|
707
|
+
if (!result) continue;
|
|
708
|
+
|
|
709
|
+
args.cssCache.setFileCss({
|
|
710
|
+
filePath,
|
|
711
|
+
contentHash: createFileCssContentHash(code),
|
|
712
|
+
configHash: args.configHash,
|
|
713
|
+
rules: result.rules,
|
|
714
|
+
});
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
function getCompilationSourceFiles(
|
|
719
|
+
compilation: Compilation,
|
|
720
|
+
projectDir: string,
|
|
721
|
+
filter: NextLoaderState['filter'],
|
|
722
|
+
) {
|
|
723
|
+
const files = new Set<string>();
|
|
724
|
+
const dependencies = compilation.fileDependencies ?? new Set<string>();
|
|
725
|
+
|
|
726
|
+
for (const filePath of dependencies) {
|
|
727
|
+
if (!isProjectSourceFile(filePath, projectDir, filter)) continue;
|
|
728
|
+
files.add(path.normalize(filePath));
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
return [...files].sort();
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
function isProjectSourceFile(
|
|
735
|
+
filePath: string,
|
|
736
|
+
projectDir: string,
|
|
737
|
+
filter: NextLoaderState['filter'],
|
|
738
|
+
) {
|
|
739
|
+
if (!path.isAbsolute(filePath)) return false;
|
|
740
|
+
if (!filePath.startsWith(projectDir + path.sep)) return false;
|
|
741
|
+
if (filePath.includes(`${path.sep}.next${path.sep}`)) return false;
|
|
742
|
+
if (filePath.includes(`${path.sep}.git${path.sep}`)) return false;
|
|
743
|
+
if (!filter(filePath)) return false;
|
|
744
|
+
|
|
745
|
+
return true;
|
|
746
|
+
}
|
package/plugin/nextjs/types.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { NextConfig } from 'next';
|
|
2
|
-
import type { PHASE_TYPE } from 'next/constants';
|
|
3
2
|
import type { OmitProps } from '../../utils/type';
|
|
4
3
|
import type { PluginOptions as BasePluginOptions } from '../utils';
|
|
5
4
|
|
|
@@ -12,7 +11,7 @@ export type NextConfigContext = {
|
|
|
12
11
|
};
|
|
13
12
|
|
|
14
13
|
export type NextConfigFunction = (
|
|
15
|
-
phase:
|
|
14
|
+
phase: string,
|
|
16
15
|
context: NextConfigContext,
|
|
17
16
|
) => MaybePromise<NextConfig>;
|
|
18
17
|
|
package/plugin/nextjs/utils.ts
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import { createHash } from 'node:crypto';
|
|
2
|
+
import fs from 'node:fs';
|
|
2
3
|
import { createRequire } from 'node:module';
|
|
3
4
|
import path from 'node:path';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
4
6
|
import type { Compilation, Compiler, WebpackPluginInstance } from 'webpack';
|
|
5
7
|
import type { Compiler as PluginCompiler } from '../../compiler';
|
|
8
|
+
import type { ImportSource } from '../../compiler/utils/import_source';
|
|
6
9
|
import { normalizePath } from '../../compiler/utils/path';
|
|
7
10
|
import type { BuildConfig, BuildDevConfig } from '../../config/build';
|
|
11
|
+
import { getStyleFnMeta } from '../../style/style';
|
|
8
12
|
import { createWebpackRegistry } from '../bundler/webpack/shared/registry';
|
|
9
13
|
import type { FileCssCache } from '../utils/cache';
|
|
10
14
|
import type { PluginOptions as BasePluginOptions } from '../utils/compiler';
|
|
@@ -69,15 +73,132 @@ export function createNextBuildDevConfig(options: PluginOptions): BuildDevConfig
|
|
|
69
73
|
export function createNextConfigHash(
|
|
70
74
|
buildConfig: BuildConfig,
|
|
71
75
|
dev: boolean,
|
|
76
|
+
importSources?: readonly ImportSource[] | null,
|
|
72
77
|
) {
|
|
73
78
|
const values = [
|
|
79
|
+
createPackageCacheIdentity(),
|
|
74
80
|
dev ? 'dev' : 'prod',
|
|
75
81
|
buildConfig.hoist ? 'hoist' : 'no-hoist',
|
|
82
|
+
JSON.stringify(createSerializableImportSources(importSources)),
|
|
76
83
|
];
|
|
77
84
|
|
|
78
85
|
return createHash('sha256').update(values.join('\0')).digest('hex');
|
|
79
86
|
}
|
|
80
87
|
|
|
88
|
+
function createPackageCacheIdentity() {
|
|
89
|
+
const require = createRequire(import.meta.url);
|
|
90
|
+
let entryPath = '';
|
|
91
|
+
|
|
92
|
+
try {
|
|
93
|
+
entryPath = require.resolve('@fluentic/style/plugin/nextjs');
|
|
94
|
+
} catch {
|
|
95
|
+
entryPath = fileURLToPath(import.meta.url);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const packageInfo = findPackageInfo(entryPath);
|
|
99
|
+
const parts = [
|
|
100
|
+
packageInfo.version,
|
|
101
|
+
normalizePath(packageInfo.packageRoot),
|
|
102
|
+
normalizePath(entryPath),
|
|
103
|
+
getStatIdentity(packageInfo.packageJsonPath),
|
|
104
|
+
getStatIdentity(entryPath),
|
|
105
|
+
];
|
|
106
|
+
|
|
107
|
+
return parts.join('\0');
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function findPackageInfo(entryPath: string) {
|
|
111
|
+
let current = path.dirname(entryPath);
|
|
112
|
+
|
|
113
|
+
while (true) {
|
|
114
|
+
const packageJsonPath = path.join(current, 'package.json');
|
|
115
|
+
|
|
116
|
+
try {
|
|
117
|
+
const pkg = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8')) as {
|
|
118
|
+
name?: string;
|
|
119
|
+
version?: string;
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
if (pkg.name === '@fluentic/style') {
|
|
123
|
+
return {
|
|
124
|
+
packageRoot: current,
|
|
125
|
+
packageJsonPath,
|
|
126
|
+
version: pkg.version ?? '',
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
} catch {
|
|
130
|
+
// Keep walking toward the filesystem root.
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const parent = path.dirname(current);
|
|
134
|
+
if (parent === current) break;
|
|
135
|
+
current = parent;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
return {
|
|
139
|
+
packageRoot: path.dirname(entryPath),
|
|
140
|
+
packageJsonPath: '',
|
|
141
|
+
version: '',
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function getStatIdentity(filePath: string) {
|
|
146
|
+
if (!filePath) return '';
|
|
147
|
+
|
|
148
|
+
try {
|
|
149
|
+
const stat = fs.statSync(filePath);
|
|
150
|
+
return `${stat.size}:${stat.mtimeMs}`;
|
|
151
|
+
} catch {
|
|
152
|
+
return '';
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export function createSerializableImportSources(
|
|
157
|
+
importSources: readonly ImportSource[] | null | undefined,
|
|
158
|
+
): ImportSource[] | undefined {
|
|
159
|
+
if (!importSources?.length) return undefined;
|
|
160
|
+
|
|
161
|
+
const result: ImportSource[] = [];
|
|
162
|
+
|
|
163
|
+
for (const entry of importSources) {
|
|
164
|
+
if (entry.check) continue;
|
|
165
|
+
|
|
166
|
+
const source = serializeImportSourcePattern(entry.source);
|
|
167
|
+
const name = entry.name;
|
|
168
|
+
const meta = entry.meta ?? (entry.styleFn ? getStyleFnMeta(entry.styleFn) : null);
|
|
169
|
+
|
|
170
|
+
if (!meta) continue;
|
|
171
|
+
if (entry.source !== undefined && source === undefined) continue;
|
|
172
|
+
|
|
173
|
+
result.push(removeUndefinedValues({
|
|
174
|
+
source,
|
|
175
|
+
name,
|
|
176
|
+
meta,
|
|
177
|
+
}));
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
return result.length ? result : undefined;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function serializeImportSourcePattern(
|
|
184
|
+
source: ImportSource['source'],
|
|
185
|
+
): string | string[] | undefined {
|
|
186
|
+
if (source === undefined) return undefined;
|
|
187
|
+
|
|
188
|
+
if (Array.isArray(source)) {
|
|
189
|
+
const result: string[] = [];
|
|
190
|
+
|
|
191
|
+
for (const item of source) {
|
|
192
|
+
if (typeof item !== 'string') return undefined;
|
|
193
|
+
result.push(item);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
return result;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
return typeof source === 'string' ? source : undefined;
|
|
200
|
+
}
|
|
201
|
+
|
|
81
202
|
export function resolveNextCompilerOptions(
|
|
82
203
|
options: PluginOptions,
|
|
83
204
|
sidecar: SourcemapSidecar | null,
|
package/plugin/utils/compiler.ts
CHANGED
|
@@ -7,6 +7,8 @@ import { createTransformFilter, normalizeModuleId, type TransformFilterOptions }
|
|
|
7
7
|
import type { BundlerSourceMap } from './sourcemap';
|
|
8
8
|
|
|
9
9
|
export type PluginCssOptions = CompilerCssOptions;
|
|
10
|
+
export { CssPropPresets } from '../../compiler';
|
|
11
|
+
export type { CompilerCssPropOptions } from '../../compiler';
|
|
10
12
|
|
|
11
13
|
export type PluginOptions = CompilerOptions & TransformFilterOptions & {
|
|
12
14
|
cacheDir?: string;
|
|
@@ -10,12 +10,13 @@ export function getStyleRuntimeMode(dev: boolean, rsc = false): CompilerRuntimeM
|
|
|
10
10
|
return dev ? CompilerRuntimeMode.Dev : CompilerRuntimeMode.Prod;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
export function getPluginBuildConfig(options: PluginOptions): BuildConfig {
|
|
13
|
+
export function getPluginBuildConfig(options: PluginOptions, dev = false): BuildConfig {
|
|
14
14
|
const css: CompilerCssOptions = hasBuildConfig(options.css) ? options.css! : {};
|
|
15
15
|
|
|
16
16
|
return {
|
|
17
|
-
hoist: options.hoist !== false,
|
|
17
|
+
hoist: !dev && options.hoist !== false,
|
|
18
18
|
css,
|
|
19
|
+
check: options.check,
|
|
19
20
|
};
|
|
20
21
|
}
|
|
21
22
|
|
|
@@ -55,3 +56,15 @@ export function getStyleEntryDefines(
|
|
|
55
56
|
|
|
56
57
|
return defines;
|
|
57
58
|
}
|
|
59
|
+
|
|
60
|
+
export function createStyleEntryGlobalSource(
|
|
61
|
+
buildConfig: BuildConfig,
|
|
62
|
+
buildDevConfig: BuildDevConfig | null,
|
|
63
|
+
sidecarUrl: string | null,
|
|
64
|
+
) {
|
|
65
|
+
const defines = getStyleEntryDefines(buildConfig, buildDevConfig, sidecarUrl, false);
|
|
66
|
+
|
|
67
|
+
return Object.entries(defines)
|
|
68
|
+
.map(([key, value]) => `globalThis[${JSON.stringify(key)}] = ${JSON.stringify(value)};`)
|
|
69
|
+
.join('\n');
|
|
70
|
+
}
|