@fluentic/style 0.1.0-beta.1 → 0.1.0-beta.3
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 +31 -2
- package/README.md +80 -23
- package/atomic/atRule/utils.ts +3 -2
- package/atomic/className.ts +25 -4
- package/atomic/debug/className/className.ts +23 -2
- package/atomic/element.ts +5 -2
- package/atomic/theme.ts +4 -2
- package/atomic/token.ts +4 -2
- package/atomic/utils/css.ts +44 -19
- package/atomic/utils/format.ts +1 -1
- package/atomic/utils/hash.ts +78 -0
- package/atomic/var.ts +3 -2
- package/builder/classname/class_name_builder.ts +447 -0
- package/builder/classname/fns.ts +77 -0
- package/builder/classname/index.ts +3 -0
- package/builder/classname/types.ts +34 -0
- package/builder/data/create.ts +6 -6
- package/builder/data/data.ts +7 -7
- package/builder/data/debug.ts +1 -0
- package/builder/data/is.ts +3 -3
- package/builder/data/merge/scope.ts +18 -19
- package/builder/data/merge/style.ts +11 -0
- package/builder/data/state.ts +1 -0
- package/builder/style_builder.ts +17 -17
- package/builder/style_fns.ts +33 -33
- package/builder/types/alias.ts +10 -10
- package/builder/types/fns.ts +11 -11
- package/builder/types/types.ts +5 -5
- package/compiler/compiler/types.ts +0 -1
- package/compiler/transform/debug/plugin.ts +8 -3
- package/compiler/transform/debug/utils/debug_data.ts +73 -0
- package/compiler/transform/evaluator/evaluator.ts +33 -2
- package/compiler/transform/evaluator/tracer.ts +13 -9
- package/compiler/transform/extract/chain/chain.ts +596 -28
- package/compiler/transform/extract/plugin.ts +5 -2
- package/compiler/transform/extract/utils/state.ts +1 -0
- package/compiler/utils/constants.ts +4 -4
- package/compiler/utils/file_resolver.ts +1 -0
- package/compiler/utils/import_source.ts +3 -2
- package/config/build.ts +12 -2
- package/config/config/css.ts +3 -0
- package/config/config/debug.ts +13 -1
- package/config/config/dev.ts +17 -1
- package/config/configure.ts +10 -2
- package/config/types.ts +7 -0
- package/dev/config.ts +2 -3
- package/dialect/extracted/index.ts +5 -0
- package/dialect/index.ts +1 -0
- package/dialect/namedTokens.ts +136 -0
- package/dist/{className-C1Ht5Wvv.js → className-CKo4TxuT.js} +2 -2
- package/dist/{className-C1Ht5Wvv.js.map → className-CKo4TxuT.js.map} +1 -1
- package/dist/{className-DC2Cq8p3.js → className-ZJ5pBA-o.js} +19 -7
- package/dist/className-ZJ5pBA-o.js.map +1 -0
- package/dist/compiler/index.mjs +1 -1
- package/dist/{compiler-DENc3a2R.mjs → compiler-D5v5tJXI.mjs} +607 -114
- package/dist/compiler-D5v5tJXI.mjs.map +1 -0
- package/dist/config/index.js +2 -2
- package/dist/{config-BryWDfQX.js → config-BEvP7108.js} +12 -4
- package/dist/config-BEvP7108.js.map +1 -0
- package/dist/config-B_cbG3S6.js +1 -0
- package/dist/config-FIfi5aJ8.js +32 -0
- package/dist/config-FIfi5aJ8.js.map +1 -0
- package/dist/config-OXHoDUIo.js +6 -0
- package/dist/{config-Di2VYYKV.js.map → config-OXHoDUIo.js.map} +1 -1
- package/dist/css-CELBp6Gu.js +58 -0
- package/dist/css-CELBp6Gu.js.map +1 -0
- package/dist/{css-BowBszUt.js → css-DcuJ_jSH.js} +17 -17
- package/dist/css-DcuJ_jSH.js.map +1 -0
- package/dist/{css-ByOrugEX.js → css-dPoZJDQH.js} +80 -78
- package/dist/css-dPoZJDQH.js.map +1 -0
- package/dist/{css-DcazYor9.js → css-oOt6ZR54.js} +10 -8
- package/dist/css-oOt6ZR54.js.map +1 -0
- package/dist/css.js +1 -1
- package/dist/{css_extra-DlOnsnR1.js → css_extra-DQdCrYoC.js} +2 -2
- package/dist/{css_extra-DlOnsnR1.js.map → css_extra-DQdCrYoC.js.map} +1 -1
- package/dist/{css_extra-oIi3UEPK.js → css_extra-DeTuIlcO.js} +2 -2
- package/dist/{css_extra-oIi3UEPK.js.map → css_extra-DeTuIlcO.js.map} +1 -1
- package/dist/{data-BsqOa5br.js → data-CeYstKMP.js} +21 -12
- package/dist/data-CeYstKMP.js.map +1 -0
- package/dist/{debug-n2aZQBSa.js → debug-D96KGgpH.js} +3 -3
- package/dist/debug-D96KGgpH.js.map +1 -0
- package/dist/dev/rsc.js +9 -9
- package/dist/{dev-CcphAa3R.js → dev-fOtWB5K3.js} +7 -8
- package/dist/{dev-CcphAa3R.js.map → dev-fOtWB5K3.js.map} +1 -1
- package/dist/{dev-DfBbuLeE.js → dev-p8tW7X-A.js} +14 -4
- package/dist/dev-p8tW7X-A.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-CvqqIb7J.js} +10 -8
- package/dist/{elementMarker-Bu7gDAkE.js.map → elementMarker-CvqqIb7J.js.map} +1 -1
- package/dist/entry/dev/css.js +2 -2
- package/dist/entry/dev/jsx-dev-runtime.js +2 -1
- package/dist/entry/dev/jsx-runtime.js +2 -1
- package/dist/entry/dev.js +12 -9
- package/dist/entry/prod/css.js +2 -2
- 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 +4 -4
- package/dist/entry/prod.js +8 -8
- package/dist/entry/prod.js.map +1 -1
- package/dist/entry/rsc-dev/css.js +2 -2
- package/dist/entry/rsc-dev/dev.js +4 -5
- 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 +341 -105
- package/dist/entry/rsc-dev.js.map +1 -1
- package/dist/entry/rsc-prod/css.js +2 -2
- 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 +4 -4
- package/dist/entry/rsc-prod.js +7 -7
- package/dist/extract-DeOytHKW.js +2 -0
- package/dist/{getClassName-BlvXHYuf.js → getClassName-oiQ8CnkS.js} +3 -3
- package/dist/getClassName-oiQ8CnkS.js.map +1 -0
- package/dist/global-Cul1dX8k.js +14 -0
- package/dist/{global-CvfmFLsK.js.map → global-Cul1dX8k.js.map} +1 -1
- package/dist/global-zaCE-g1C.js +31 -0
- package/dist/global-zaCE-g1C.js.map +1 -0
- package/dist/{format-3nKBE_5t.js → hash-Bycpk3MR.js} +53 -37
- package/dist/hash-Bycpk3MR.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-D2BksHSv.js → jsx-A4cK517J.js} +7 -7
- package/dist/{jsx-D2BksHSv.js.map → jsx-A4cK517J.js.map} +1 -1
- package/dist/{jsx-CwTeyUxr.js → jsx-Ba-XV33u.js} +3 -3
- package/dist/{jsx-CwTeyUxr.js.map → jsx-Ba-XV33u.js.map} +1 -1
- package/dist/{jsx_dev_runtime-B6xs4by8.js → jsx_dev_runtime-BQcRzl5D.js} +2 -2
- package/dist/{jsx_dev_runtime-B6xs4by8.js.map → jsx_dev_runtime-BQcRzl5D.js.map} +1 -1
- package/dist/{jsx_runtime-iHLDwpcW.js → jsx_runtime-B9KEoAQN.js} +2 -2
- package/dist/{jsx_runtime-iHLDwpcW.js.map → jsx_runtime-B9KEoAQN.js.map} +1 -1
- package/dist/{jsx_runtime-04xfnsi7.js → jsx_runtime-BXcbW8Yp.js} +2 -2
- package/dist/{jsx_runtime-04xfnsi7.js.map → jsx_runtime-BXcbW8Yp.js.map} +1 -1
- package/dist/{layer-D1SaH07m.js → layer-CbQzwZF-.js} +4 -4
- package/dist/{layer-D1SaH07m.js.map → layer-CbQzwZF-.js.map} +1 -1
- package/dist/{loader-B5Kw0DD-.mjs → loader-BAth2yZ1.mjs} +3 -3
- package/dist/{loader-B5Kw0DD-.mjs.map → loader-BAth2yZ1.mjs.map} +1 -1
- package/dist/{misc-DCdYYyhK.mjs → misc-DFBKJGLT.mjs} +7 -3
- package/dist/{misc-DCdYYyhK.mjs.map → misc-DFBKJGLT.mjs.map} +1 -1
- package/dist/namedTokens-BUa6raTb.js +83 -0
- package/dist/namedTokens-BUa6raTb.js.map +1 -0
- package/dist/plugin/farm/index.mjs +2 -2
- package/dist/plugin/nextjs/index.mjs +4 -4
- package/dist/plugin/nextjs/loader.mjs +4 -4
- package/dist/plugin/parcel/optimizer.cjs +1 -1
- package/dist/plugin/parcel/optimizer.mjs +2 -2
- 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 +1 -1
- package/dist/plugin/vite/index.mjs +11 -8
- package/dist/plugin/vite/index.mjs.map +1 -1
- package/dist/plugin/webpack/index.mjs +1 -1
- package/dist/plugin/webpack/loader.mjs +2 -2
- package/dist/presets/tailwind/index.js +971 -0
- package/dist/presets/tailwind/index.js.map +1 -0
- package/dist/{property-CnLFt5kx.js → property-CF6JgpTq.js} +2 -2
- package/dist/{property-CnLFt5kx.js.map → property-CF6JgpTq.js.map} +1 -1
- package/dist/{registry-yHLRxyoo.mjs → registry-CiwvMfx8.mjs} +2 -2
- package/dist/{registry-yHLRxyoo.mjs.map → registry-CiwvMfx8.mjs.map} +1 -1
- package/dist/{rules-9HSO1pxL.js → rules-DlXcch7-.js} +13 -10
- package/dist/rules-DlXcch7-.js.map +1 -0
- package/dist/runtime-BKChZZ2-.js +52 -0
- package/dist/runtime-BKChZZ2-.js.map +1 -0
- package/dist/server.js +13 -11
- package/dist/server.js.map +1 -1
- package/dist/{shared-CxbHR89f.mjs → shared-x59dI2NW.mjs} +4 -4
- package/dist/{shared-CxbHR89f.mjs.map → shared-x59dI2NW.mjs.map} +1 -1
- package/dist/{shared-CBArHB9-.cjs → shared-yDD0nfm1.cjs} +603 -110
- package/dist/shared-yDD0nfm1.cjs.map +1 -0
- package/dist/sheet-B-uJfHRY.js +7 -0
- package/dist/sheet-B-uJfHRY.js.map +1 -0
- package/dist/{sidecar-BFakLl0X.mjs → sidecar-CJ6i4wmn.mjs} +3 -3
- package/dist/{sidecar-BFakLl0X.mjs.map → sidecar-CJ6i4wmn.mjs.map} +1 -1
- package/dist/{style-B1UUqjj5.js → style-91J0B5ef.js} +35 -7
- package/dist/style-91J0B5ef.js.map +1 -0
- package/dist/{style-v2bf70TZ.js → style-Bw5ka-Nq.js} +440 -135
- package/dist/style-Bw5ka-Nq.js.map +1 -0
- package/dist/{style-DgHbdbdF.js → style-DFFK06Of.js} +258 -82
- package/dist/style-DFFK06Of.js.map +1 -0
- package/dist/style-pz8e5To1.js +5 -0
- package/dist/{styleStore-DyNXBcUK.js → styleStore-DJ0Msgkh.js} +6 -5
- package/dist/{styleStore-DyNXBcUK.js.map → styleStore-DJ0Msgkh.js.map} +1 -1
- package/dist/{styleStore-Dea_WVbr.js → styleStore-ydQcDBD4.js} +16 -7
- package/dist/styleStore-ydQcDBD4.js.map +1 -0
- package/dist/token-DTOyFLmp.js +58 -0
- package/dist/token-DTOyFLmp.js.map +1 -0
- package/dist/{token-u_tM-mtg.js → token-DT_sCPtm.js} +125 -31
- package/dist/token-DT_sCPtm.js.map +1 -0
- package/dist/{trace-Bu_qOqRy.js → trace-CO36aenp.js} +3 -3
- package/dist/{trace-Bu_qOqRy.js.map → trace-CO36aenp.js.map} +1 -1
- package/dist/{trace-CU0rvNYr.js → trace-D8j96G57.js} +2 -2
- package/dist/{trace-CU0rvNYr.js.map → trace-D8j96G57.js.map} +1 -1
- package/dist/transform-BTJOg8Hg.js +23 -0
- package/dist/transform-BTJOg8Hg.js.map +1 -0
- package/dist/{utils-CWNHx4EC.js → utils-Bmw655wa.js} +3 -3
- package/dist/{utils-CWNHx4EC.js.map → utils-Bmw655wa.js.map} +1 -1
- package/dist/{utils-CEaq_c-A.mjs → utils-D2fygyTm.mjs} +4 -4
- package/dist/{utils-CEaq_c-A.mjs.map → utils-D2fygyTm.mjs.map} +1 -1
- package/dist/{utils-Bdbqn0f8.mjs → utils-DTXCTUlS.mjs} +3 -3
- package/dist/{utils-Bdbqn0f8.mjs.map → utils-DTXCTUlS.mjs.map} +1 -1
- package/dist/{utils-BbehLOby.js → utils-DVFxZnVC.js} +159 -76
- package/dist/utils-DVFxZnVC.js.map +1 -0
- package/dist/{utils-D7FAOyg6.js → utils-hoYnMiA7.js} +4 -4
- package/dist/{utils-D7FAOyg6.js.map → utils-hoYnMiA7.js.map} +1 -1
- package/dist/utils.js +3 -3
- package/dist/value-D-ZcRzLA.js +42 -0
- package/dist/value-D-ZcRzLA.js.map +1 -0
- package/dist/{value-BR4e2MKt.js → value-DvFkGBy2.js} +147 -28
- package/dist/value-DvFkGBy2.js.map +1 -0
- package/dist/value-dG9LK0Gq.js +85 -0
- package/dist/value-dG9LK0Gq.js.map +1 -0
- package/dist/{valueRef-lshFk1Cs.js → valueRef-CsLVJwjA.js} +2 -2
- package/dist/{valueRef-lshFk1Cs.js.map → valueRef-CsLVJwjA.js.map} +1 -1
- package/dist/{webpack-Dh6lox2l.mjs → webpack-BOU7_xld.mjs} +5 -5
- package/dist/{webpack-Dh6lox2l.mjs.map → webpack-BOU7_xld.mjs.map} +1 -1
- 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/runtime.ts +1 -1
- package/entry/rsc_dev/config.ts +1 -1
- package/entry/rsc_dev/server.ts +1 -1
- package/entry/rsc_prod/runtime.ts +1 -1
- package/entry/rsc_prod/server.ts +1 -1
- package/entry/shared/config_dev.ts +12 -0
- package/entry/shared/dev.ts +11 -2
- package/entry/shared/utils.ts +28 -0
- package/package.json +26 -9
- package/plugin/bundler/vite/plugin.ts +2 -1
- package/plugin/bundler/vite/state.ts +10 -5
- package/plugin/utils/runtimeEntry.ts +12 -0
- package/presets/tailwind/classname/index.ts +2 -0
- package/presets/tailwind/classname/transform.ts +208 -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 +430 -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/core/cache/pool.ts +1 -1
- package/runtime/extract/getClassName.ts +1 -6
- package/runtime/extract/index.ts +1 -1
- package/runtime/index.ts +8 -1
- package/runtime/types.ts +4 -2
- package/style/classname.ts +41 -0
- package/style/index.ts +1 -0
- package/style/style.ts +30 -11
- package/style/theme.ts +4 -2
- package/style/transform.ts +41 -2
- package/utils/hash.ts +4 -0
- package/atomic/layer/README.md +0 -116
- package/dist/className-DC2Cq8p3.js.map +0 -1
- package/dist/compiler-DENc3a2R.mjs.map +0 -1
- 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.map +0 -1
- package/dist/css-ByOrugEX.js.map +0 -1
- package/dist/css-DcazYor9.js.map +0 -1
- 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-DfBbuLeE.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/rules-9HSO1pxL.js.map +0 -1
- package/dist/runtime-CYqNCiaM.js +0 -53
- 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.map +0 -1
- package/dist/style-DgHbdbdF.js.map +0 -1
- package/dist/style-v2bf70TZ.js.map +0 -1
- package/dist/styleStore-Dea_WVbr.js.map +0 -1
- package/dist/token-u_tM-mtg.js.map +0 -1
- package/dist/utils-BbehLOby.js.map +0 -1
- package/dist/value-BR4e2MKt.js.map +0 -1
- package/dist/value-E8rEv2Oe.js +0 -136
- package/dist/value-E8rEv2Oe.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,10 +1,39 @@
|
|
|
1
1
|
# @fluentic/style
|
|
2
2
|
|
|
3
|
-
## 0.1.0-beta.
|
|
3
|
+
## 0.1.0-beta.3
|
|
4
4
|
|
|
5
5
|
### Patch Changes
|
|
6
6
|
|
|
7
|
-
-
|
|
7
|
+
- fd4a705: Make production class names globally dedupe extracted rules by deriving callsite-local hashing from dev mode only. Keep debug class names configurable from plugin and runtime CSS options, with dev defaulting to readable names and production defaulting to compact hashes.
|
|
8
|
+
|
|
9
|
+
## 0.1.0-beta.2
|
|
10
|
+
|
|
11
|
+
This beta adds class-name style chains, Tailwind presets, and compiler support
|
|
12
|
+
for transform-driven styling.
|
|
13
|
+
|
|
14
|
+
### Highlights
|
|
15
|
+
|
|
16
|
+
- Add `createClassNameFn` for class-name-driven style builders.
|
|
17
|
+
- Support nested class-name values, conditional falsey entries, weighted
|
|
18
|
+
class-name tokens, selector chaining, at-rules, and merges.
|
|
19
|
+
- Add compiler extraction for class-name style chains.
|
|
20
|
+
- Add Tailwind presets for both style-object and class-name authoring.
|
|
21
|
+
- Add `classNameTransform`, `classNameValue`, and transform metadata for
|
|
22
|
+
preserving source class labels in emitted rules.
|
|
23
|
+
- Add named token compiler support for static extraction and theme override
|
|
24
|
+
identity.
|
|
25
|
+
- Add configurable transform class-name formatting and hash length behavior for
|
|
26
|
+
debug output.
|
|
27
|
+
|
|
28
|
+
## 0.1.0-beta.1
|
|
29
|
+
|
|
30
|
+
This patch beta improves typed selector authoring and documentation.
|
|
31
|
+
|
|
32
|
+
### Changes
|
|
33
|
+
|
|
34
|
+
- Add `createSelectorAssert` for typed custom selector validators.
|
|
35
|
+
- Keep the public beta API moving with small usability refinements after
|
|
36
|
+
`0.1.0-beta.0`.
|
|
8
37
|
|
|
9
38
|
## 0.1.0-beta.0
|
|
10
39
|
|
package/README.md
CHANGED
|
@@ -8,9 +8,10 @@ explores a specific question inside that space: what if styles composed around
|
|
|
8
8
|
React components the same way props and state do?
|
|
9
9
|
|
|
10
10
|
With Fluentic, you start simple with type-safe `style(...)` and the JSX `css`
|
|
11
|
-
prop.
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
prop. If your team prefers utility class names, you can also create class-name
|
|
12
|
+
style chains, including a Tailwind-like preset. When a component needs variants,
|
|
13
|
+
themes, nested parts, or consumer overrides, add slots, scopes, tokens, and
|
|
14
|
+
`combineStyle(...)` so those styles stay organized around the component.
|
|
14
15
|
|
|
15
16
|
For production builds, styles are extracted into static atomic CSS output.
|
|
16
17
|
Dynamic values from props and state still work as usual.
|
|
@@ -100,6 +101,49 @@ export function Card() {
|
|
|
100
101
|
That is the smallest version of Fluentic Style: type-safe styles, selectors, and
|
|
101
102
|
a `css` prop.
|
|
102
103
|
|
|
104
|
+
## Class Name Chains
|
|
105
|
+
|
|
106
|
+
Fluentic's default authoring path is object style chains, but class-name chains
|
|
107
|
+
are supported too. A class-name chain still produces Fluentic style data, so it
|
|
108
|
+
can use the same `css` prop, selector methods, slots, scopes, debugging, runtime
|
|
109
|
+
resolution, and production extraction path.
|
|
110
|
+
|
|
111
|
+
```tsx
|
|
112
|
+
import { createClassNameFn } from '@fluentic/style';
|
|
113
|
+
import {
|
|
114
|
+
createTailwindClassNamePreset,
|
|
115
|
+
defaultTailwindTheme,
|
|
116
|
+
} from '@fluentic/style/presets/tailwind';
|
|
117
|
+
|
|
118
|
+
const tailwind = createTailwindClassNamePreset({
|
|
119
|
+
theme: defaultTailwindTheme,
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
export const { className: cx } = createClassNameFn({
|
|
123
|
+
selectors: tailwind.selectors,
|
|
124
|
+
transform: tailwind.transform,
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
const button = cx(
|
|
128
|
+
'inline-flex',
|
|
129
|
+
'items-center',
|
|
130
|
+
'gap-2',
|
|
131
|
+
'rounded-md',
|
|
132
|
+
'bg-blue-600',
|
|
133
|
+
'px-4',
|
|
134
|
+
'py-2',
|
|
135
|
+
'text-white',
|
|
136
|
+
)
|
|
137
|
+
.hover('bg-blue-700')
|
|
138
|
+
.md('px-6');
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
Class names get their meaning from a user-land transform or a preset. See
|
|
142
|
+
[Class Name Style Chains](https://fluenticstack.com/style/docs/beyond-the-basics/class-name-style-chains/)
|
|
143
|
+
for the generic API, or
|
|
144
|
+
[Tailwind Class Name Preset](https://fluenticstack.com/style/docs/presets/tailwind/class-name/)
|
|
145
|
+
for the built-in Tailwind-like class-name vocabulary.
|
|
146
|
+
|
|
103
147
|
## Scale Into Components
|
|
104
148
|
|
|
105
149
|
When a component becomes reusable, give its styles component structure.
|
|
@@ -333,7 +377,19 @@ For Next.js and other bundlers, see the
|
|
|
333
377
|
Benchmarks live in the repository's `benchmark/` folder and run against
|
|
334
378
|
production builds. Current benchmark snapshots:
|
|
335
379
|
|
|
336
|
-
|
|
380
|
+
The main production checks are runtime cost and bundle size. In the production
|
|
381
|
+
path most apps use, Fluentic extracts CSS at build time and ships the extracted
|
|
382
|
+
production runtime for `css` prop composition, dynamic values, class-name
|
|
383
|
+
merging, and token resolution. That runtime entry currently reports `5.00 KB`
|
|
384
|
+
min+gzip.
|
|
385
|
+
Browser and SSR benchmarks track whether style resolution stays fast in
|
|
386
|
+
app-shaped renders. See the
|
|
387
|
+
[Bundle Size](https://fluenticstack.com/style/docs/benchmark/bundle-size/),
|
|
388
|
+
[React App](https://fluenticstack.com/style/docs/benchmark/react-app/), and
|
|
389
|
+
[SSR Style](https://fluenticstack.com/style/docs/benchmark/ssr-style/) reports
|
|
390
|
+
for what each number measures and how to rerun it.
|
|
391
|
+
|
|
392
|
+
[React app](https://fluenticstack.com/style/docs/benchmark/react-app/), 1500-row dashboard:
|
|
337
393
|
|
|
338
394
|
| Case | Mount | Style Update |
|
|
339
395
|
| -------------------------- | ---------- | ------------ |
|
|
@@ -347,7 +403,7 @@ React app, 1500-row dashboard:
|
|
|
347
403
|
| vanilla-extract DOM | `39.85 ms` | `17.65 ms` |
|
|
348
404
|
| CSS Modules DOM | `40.35 ms` | `17.75 ms` |
|
|
349
405
|
|
|
350
|
-
SSR render-only, 500 rows:
|
|
406
|
+
[SSR render-only](https://fluenticstack.com/style/docs/benchmark/ssr-style/), 500 rows:
|
|
351
407
|
|
|
352
408
|
| Case | Dashboard Mean | Composition Mean |
|
|
353
409
|
| --------------- | -------------- | ---------------- |
|
|
@@ -357,7 +413,7 @@ SSR render-only, 500 rows:
|
|
|
357
413
|
| Fluentic token | `7.667 ms` | `8.253 ms` |
|
|
358
414
|
| StyleX | `6.826 ms` | `8.059 ms` |
|
|
359
415
|
|
|
360
|
-
Compiler transform, 100 files per corpus:
|
|
416
|
+
[Compiler transform](https://fluenticstack.com/style/docs/benchmark/compiler/), 100 files per corpus:
|
|
361
417
|
|
|
362
418
|
| Corpus | Fluentic Warm | StyleX Babel |
|
|
363
419
|
| ------------- | ------------- | ------------ |
|
|
@@ -371,23 +427,24 @@ and the public suite list.
|
|
|
371
427
|
|
|
372
428
|
## Package Exports
|
|
373
429
|
|
|
374
|
-
| Import
|
|
375
|
-
|
|
|
376
|
-
| `@fluentic/style`
|
|
377
|
-
| `@fluentic/style/css`
|
|
378
|
-
| `@fluentic/style/selector`
|
|
379
|
-
| `@fluentic/style/config`
|
|
380
|
-
| `@fluentic/style/compiler`
|
|
381
|
-
| `@fluentic/style/
|
|
382
|
-
| `@fluentic/style/dev
|
|
383
|
-
| `@fluentic/style/
|
|
384
|
-
| `@fluentic/style/
|
|
385
|
-
| `@fluentic/style/plugin/
|
|
386
|
-
| `@fluentic/style/plugin/
|
|
387
|
-
| `@fluentic/style/plugin/
|
|
388
|
-
| `@fluentic/style/plugin/
|
|
389
|
-
| `@fluentic/style/plugin/
|
|
390
|
-
| `@fluentic/style/plugin/
|
|
430
|
+
| Import | Purpose |
|
|
431
|
+
| ---------------------------------- | ------------------------------------------------------------------------------------------------------------------------ |
|
|
432
|
+
| `@fluentic/style` | Runtime API, style builders, hooks, tokens, themes, and types. |
|
|
433
|
+
| `@fluentic/style/css` | CSS helper APIs for keyframes, font faces, and at-rules. |
|
|
434
|
+
| `@fluentic/style/selector` | Selector constructors, validators, presets, and priority helpers. |
|
|
435
|
+
| `@fluentic/style/config` | Runtime configuration helpers. |
|
|
436
|
+
| `@fluentic/style/compiler` | Node-only compiler entry used by build integrations and compiler benchmarks. |
|
|
437
|
+
| `@fluentic/style/presets/tailwind` | [Tailwind-like object fields and class-name chains](https://fluenticstack.com/style/docs/presets/tailwind/). |
|
|
438
|
+
| `@fluentic/style/dev` | Development utilities. |
|
|
439
|
+
| `@fluentic/style/dev/rsc` | React Server Component dev client boundary. |
|
|
440
|
+
| `@fluentic/style/jsx` | [JSX import source without a bundler plugin](https://fluenticstack.com/style/docs/integrations/runtime-only-mode/). |
|
|
441
|
+
| `@fluentic/style/plugin/jsx` | [JSX import source after adding a bundler plugin](https://fluenticstack.com/style/docs/integrations/jsx-runtime-setup/). |
|
|
442
|
+
| `@fluentic/style/plugin/nextjs` | [Next.js App Router integration](https://fluenticstack.com/style/docs/integrations/nextjs/). |
|
|
443
|
+
| `@fluentic/style/plugin/vite` | [Vite plugin](https://fluenticstack.com/style/docs/integrations/vite/). |
|
|
444
|
+
| `@fluentic/style/plugin/webpack` | [Webpack plugin](https://fluenticstack.com/style/docs/integrations/webpack/). |
|
|
445
|
+
| `@fluentic/style/plugin/rspack` | [Rspack plugin](https://fluenticstack.com/style/docs/integrations/rspack/). |
|
|
446
|
+
| `@fluentic/style/plugin/farm` | [Farm plugin](https://fluenticstack.com/style/docs/integrations/farm/). |
|
|
447
|
+
| `@fluentic/style/plugin/parcel` | [Parcel plugin](https://fluenticstack.com/style/docs/integrations/parcel/). |
|
|
391
448
|
|
|
392
449
|
## Repository Guide
|
|
393
450
|
|
package/atomic/atRule/utils.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import { CSS_CONFIG } from '../../config/config/css';
|
|
1
2
|
import { type NamedAtRuleFormat, type NamedAtRuleInfo, type TokenNameFormat } from '../../config/types';
|
|
2
3
|
import { getStyleTokenId, isStyleTokenData, type StyleTokenData } from '../../style/token';
|
|
3
4
|
import { getCssPropertyName } from '../property';
|
|
4
5
|
import { getTokenVar } from '../token';
|
|
5
|
-
import { getIdentifierSafeHash } from '../utils/css';
|
|
6
6
|
import { createNameFormatter } from '../utils/format';
|
|
7
|
+
import { getIdentifierSafeHash } from '../utils/hash';
|
|
7
8
|
import { getCssPropertyValue } from '../value';
|
|
8
9
|
|
|
9
10
|
export function createAtRuleNameFormatter(defaultFormat: NamedAtRuleFormat, prefix?: string) {
|
|
@@ -14,7 +15,7 @@ export function createAtRuleNameFormatter(defaultFormat: NamedAtRuleFormat, pref
|
|
|
14
15
|
id: string,
|
|
15
16
|
info: NamedAtRuleInfo,
|
|
16
17
|
) => {
|
|
17
|
-
const hash = getIdentifierSafeHash(id);
|
|
18
|
+
const hash = getIdentifierSafeHash(id, CSS_CONFIG.hashLength);
|
|
18
19
|
const name = formatter(format || defaultFormat, hash, info);
|
|
19
20
|
|
|
20
21
|
if (!prefix) return name;
|
package/atomic/className.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import type { BuilderCallsite, ItemSelector } from '../builder/data';
|
|
2
|
-
import
|
|
2
|
+
import { CSS_CONFIG } from '../config/config/css';
|
|
3
|
+
import { DEV_CONFIG } from '../config/config/dev';
|
|
4
|
+
import type { ClassNameFormat, ScopeClassNameFormat, TransformClassNameFormat } from '../config/types';
|
|
3
5
|
import { hashString } from '../utils/hash';
|
|
4
|
-
import { getDebugClassName, getDebugScopeClassName } from './debug/className';
|
|
6
|
+
import { getDebugClassName, getDebugScopeClassName, getDebugTransformClassName } from './debug/className';
|
|
5
7
|
import { getDebugPropertyName } from './debug/property';
|
|
6
8
|
import { getDebugAtRuleName, getDebugSelectorName } from './debug/selector';
|
|
7
|
-
import { getIdentifierSafeHash } from './utils/
|
|
9
|
+
import { getIdentifierSafeHash } from './utils/hash';
|
|
8
10
|
import { getSelectorHash, getSelectorText } from './utils/selector';
|
|
9
11
|
|
|
10
12
|
export function getAtomicClassName(
|
|
@@ -18,6 +20,9 @@ export function getAtomicClassName(
|
|
|
18
20
|
localClassName: boolean,
|
|
19
21
|
debugClassName: boolean,
|
|
20
22
|
classNameFormat: ClassNameFormat | null,
|
|
23
|
+
transformClassName: string | null,
|
|
24
|
+
transformClassNameFormat: TransformClassNameFormat | null,
|
|
25
|
+
hashLength: number | null = null,
|
|
21
26
|
) {
|
|
22
27
|
let hash = property;
|
|
23
28
|
|
|
@@ -28,10 +33,21 @@ export function getAtomicClassName(
|
|
|
28
33
|
hash += '\n' + (atRule ? atRule.map(getSelectorHash).join('\n') : '');
|
|
29
34
|
hash += '\n' + getCallsiteHash(callsite, localClassName);
|
|
30
35
|
|
|
31
|
-
hash = getIdentifierSafeHash(
|
|
36
|
+
hash = getIdentifierSafeHash(
|
|
37
|
+
hash,
|
|
38
|
+
hashLength ?? getRuntimeClassNameHashLength(debugClassName),
|
|
39
|
+
);
|
|
32
40
|
|
|
33
41
|
if (!debugClassName) return hash;
|
|
34
42
|
|
|
43
|
+
if (transformClassName) {
|
|
44
|
+
return getDebugTransformClassName(
|
|
45
|
+
transformClassNameFormat,
|
|
46
|
+
hash,
|
|
47
|
+
{ className: transformClassName },
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
35
51
|
const propertyName = getDebugPropertyName(property, value);
|
|
36
52
|
|
|
37
53
|
const className = getDebugClassName(
|
|
@@ -59,6 +75,11 @@ export function getAtomicClassName(
|
|
|
59
75
|
return className;
|
|
60
76
|
}
|
|
61
77
|
|
|
78
|
+
function getRuntimeClassNameHashLength(debugClassName: boolean) {
|
|
79
|
+
if (debugClassName && DEV_CONFIG.isDev) return DEV_CONFIG.hashLength ?? CSS_CONFIG.hashLength ?? 3;
|
|
80
|
+
return CSS_CONFIG.hashLength ?? 7;
|
|
81
|
+
}
|
|
82
|
+
|
|
62
83
|
export function getScopeClassName(
|
|
63
84
|
className: string,
|
|
64
85
|
scopeClassNameFormat: ScopeClassNameFormat | null,
|
|
@@ -1,7 +1,16 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
ClassNameFormat,
|
|
3
|
+
ClassNameInfo,
|
|
4
|
+
ScopeClassNameFormat,
|
|
5
|
+
ScopeClassNameInfo,
|
|
6
|
+
TransformClassNameFormat,
|
|
7
|
+
TransformClassNameInfo,
|
|
8
|
+
} from '../../../config/types';
|
|
2
9
|
import { createNameFormatter } from '../../utils/format';
|
|
3
10
|
|
|
4
|
-
export const CLASS_NAME_FORMAT = '[(atRule)-][(scopeSelector)-](property)[-(selector)][-(value)]
|
|
11
|
+
export const CLASS_NAME_FORMAT = '[(atRule)-][(scopeSelector)-](property)[-(selector)][-(value)]--$hash';
|
|
12
|
+
|
|
13
|
+
export const TRANSFORM_CLASS_NAME_FORMAT = '(className)--$hash';
|
|
5
14
|
|
|
6
15
|
export const SCOPE_CLASS_NAME_FORMAT = '-(className)';
|
|
7
16
|
|
|
@@ -17,6 +26,10 @@ export const formatScopeClassName = createNameFormatter<ScopeClassNameInfo>([
|
|
|
17
26
|
'className',
|
|
18
27
|
]);
|
|
19
28
|
|
|
29
|
+
export const formatTransformClassName = createNameFormatter<TransformClassNameInfo>([
|
|
30
|
+
'className',
|
|
31
|
+
]);
|
|
32
|
+
|
|
20
33
|
export function getDebugClassName(
|
|
21
34
|
format: ClassNameFormat | null,
|
|
22
35
|
hash: string,
|
|
@@ -25,6 +38,14 @@ export function getDebugClassName(
|
|
|
25
38
|
return formatClassName(format || CLASS_NAME_FORMAT, hash, info);
|
|
26
39
|
}
|
|
27
40
|
|
|
41
|
+
export function getDebugTransformClassName(
|
|
42
|
+
format: TransformClassNameFormat | null,
|
|
43
|
+
hash: string,
|
|
44
|
+
info: TransformClassNameInfo,
|
|
45
|
+
) {
|
|
46
|
+
return formatTransformClassName(format || TRANSFORM_CLASS_NAME_FORMAT, hash, info);
|
|
47
|
+
}
|
|
48
|
+
|
|
28
49
|
export function getDebugScopeClassName(
|
|
29
50
|
format: ScopeClassNameFormat | null,
|
|
30
51
|
info: ScopeClassNameInfo,
|
package/atomic/element.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
import { CSS_CONFIG } from '../config/config/css';
|
|
2
|
+
import { DEV_CONFIG } from '../config/config/dev';
|
|
1
3
|
import type { ElementClassNameFormat, ElementClassNameInfo } from '../config/types';
|
|
2
|
-
import { escapeCssIdent
|
|
4
|
+
import { escapeCssIdent } from './utils/css';
|
|
3
5
|
import { sanitizeDebugName } from './utils/debug';
|
|
4
6
|
import { createNameFormatter } from './utils/format';
|
|
7
|
+
import { getIdentifierSafeHash } from './utils/hash';
|
|
5
8
|
|
|
6
9
|
export const ELEMENT_CLASS_NAME_FORMAT = '@(name)';
|
|
7
10
|
|
|
@@ -15,7 +18,7 @@ export function getElementClassName(
|
|
|
15
18
|
elementClassNameFormat: ElementClassNameFormat | null,
|
|
16
19
|
) {
|
|
17
20
|
const name = sanitizeDebugName(label) || null;
|
|
18
|
-
const hash = getIdentifierSafeHash(id);
|
|
21
|
+
const hash = getIdentifierSafeHash(id, DEV_CONFIG.hashLength ?? CSS_CONFIG.hashLength ?? 3);
|
|
19
22
|
|
|
20
23
|
return formatElementClassName(
|
|
21
24
|
elementClassNameFormat || ELEMENT_CLASS_NAME_FORMAT,
|
package/atomic/theme.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import { CSS_CONFIG } from '../config/config/css';
|
|
1
2
|
import type { ThemeNameFormat, ThemeNameInfo, TokenNameFormat } from '../config/types';
|
|
2
3
|
import type { StyleTokenOverride } from '../style/token';
|
|
3
4
|
import { getTokenOverrideValue, getTokenVarName } from './token';
|
|
4
|
-
import { escapeCssIdent, escapeCssValue
|
|
5
|
+
import { escapeCssIdent, escapeCssValue } from './utils/css';
|
|
5
6
|
import { createNameFormatter } from './utils/format';
|
|
7
|
+
import { getIdentifierSafeHash } from './utils/hash';
|
|
6
8
|
|
|
7
9
|
export const THEME_NAME_FORMAT = 'theme[-(name)]-$hash';
|
|
8
10
|
|
|
@@ -15,7 +17,7 @@ export function createThemeClassName(
|
|
|
15
17
|
) {
|
|
16
18
|
return formatThemeName(
|
|
17
19
|
themeNameFormat || THEME_NAME_FORMAT,
|
|
18
|
-
getIdentifierSafeHash(id),
|
|
20
|
+
getIdentifierSafeHash(id, CSS_CONFIG.hashLength),
|
|
19
21
|
{ name },
|
|
20
22
|
);
|
|
21
23
|
}
|
package/atomic/token.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import { CSS_CONFIG } from '../config/config/css';
|
|
1
2
|
import type { TokenNameFormat, TokenNameInfo } from '../config/types';
|
|
2
3
|
import { getStyleTokenId, type StyleTokenData, type StyleTokenOverride } from '../style/token';
|
|
3
|
-
import { getCssVar, getCssVarRawFallback
|
|
4
|
+
import { getCssVar, getCssVarRawFallback } from './utils/css';
|
|
4
5
|
import { createNameFormatter } from './utils/format';
|
|
6
|
+
import { getIdentifierSafeHash } from './utils/hash';
|
|
5
7
|
|
|
6
8
|
export const TOKEN_NAME_FORMAT = 'token[-(name)]-$hash';
|
|
7
9
|
|
|
@@ -15,7 +17,7 @@ export function getTokenVarName(
|
|
|
15
17
|
|
|
16
18
|
const name = formatTokenName(
|
|
17
19
|
format || TOKEN_NAME_FORMAT,
|
|
18
|
-
getIdentifierSafeHash(id),
|
|
20
|
+
getIdentifierSafeHash(id, CSS_CONFIG.hashLength),
|
|
19
21
|
{ name: id },
|
|
20
22
|
);
|
|
21
23
|
|
package/atomic/utils/css.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { hashString } from '../../utils/hash';
|
|
2
|
-
|
|
3
1
|
export function getCssVar(varName: string, value: string) {
|
|
4
2
|
return 'var(' + varName + ', ' + escapeCssValue(value) + ')';
|
|
5
3
|
}
|
|
@@ -21,29 +19,56 @@ export function escapeCssValue(value: string): string {
|
|
|
21
19
|
}
|
|
22
20
|
|
|
23
21
|
export function escapeCssIdent(ident: string): string {
|
|
24
|
-
|
|
22
|
+
let result = '';
|
|
25
23
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
24
|
+
for (let i = 0; i < ident.length; i++) {
|
|
25
|
+
const char = ident.charAt(i);
|
|
26
|
+
const code = ident.charCodeAt(i);
|
|
27
|
+
const nextCode = ident.charCodeAt(i + 1);
|
|
29
28
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
if (code === 0) {
|
|
30
|
+
result += '\uFFFD';
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
33
|
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
if (
|
|
35
|
+
(code >= 1 && code <= 31) ||
|
|
36
|
+
code === 127 ||
|
|
37
|
+
(i === 0 && code >= 48 && code <= 57) ||
|
|
38
|
+
(i === 1 && code >= 48 && code <= 57 && ident.charCodeAt(0) === 45)
|
|
39
|
+
) {
|
|
40
|
+
result += '\\' + code.toString(16) + ' ';
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
36
43
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
44
|
+
if (i === 0 && code === 45 && ident.length === 1) {
|
|
45
|
+
result += '\\-';
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (code >= 0xD800 && code <= 0xDBFF && nextCode >= 0xDC00 && nextCode <= 0xDFFF) {
|
|
50
|
+
result += char + ident.charAt(++i);
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
40
53
|
|
|
41
|
-
|
|
42
|
-
|
|
54
|
+
if (
|
|
55
|
+
code >= 128 ||
|
|
56
|
+
code === 45 ||
|
|
57
|
+
code === 95 ||
|
|
58
|
+
(code >= 48 && code <= 57) ||
|
|
59
|
+
(code >= 65 && code <= 90) ||
|
|
60
|
+
(code >= 97 && code <= 122)
|
|
61
|
+
) {
|
|
62
|
+
result += char;
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
43
65
|
|
|
44
|
-
|
|
66
|
+
result += '\\' + char;
|
|
67
|
+
}
|
|
45
68
|
|
|
46
|
-
|
|
69
|
+
return result;
|
|
70
|
+
}
|
|
47
71
|
|
|
48
|
-
|
|
72
|
+
export function sanitizeCssIdentName(value: string, fallback: string = '') {
|
|
73
|
+
return value.replace(/[^a-zA-Z0-9_-]+/g, '-').replace(/^-+|-+$/g, '') || fallback;
|
|
49
74
|
}
|
package/atomic/utils/format.ts
CHANGED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { globalData } from '../../utils/global';
|
|
2
|
+
import { hashString, normalizeHashLength } from '../../utils/hash';
|
|
3
|
+
|
|
4
|
+
type PooledHashState = {
|
|
5
|
+
byValue: Map<string, string>;
|
|
6
|
+
byHash: Map<string, string>;
|
|
7
|
+
usedByLength: number[];
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const POOLED_HASH_STATE = globalData<PooledHashState>(
|
|
11
|
+
'atomic.hashPool',
|
|
12
|
+
() => ({
|
|
13
|
+
byValue: new Map(),
|
|
14
|
+
byHash: new Map(),
|
|
15
|
+
usedByLength: [],
|
|
16
|
+
}),
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
export function getIdentifierSafeHash(value: string, startLength = 7) {
|
|
20
|
+
return getPooledHash(value, startLength);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function getPooledHash(value: string, startLength: number) {
|
|
24
|
+
const normalizedStartLength = normalizeHashLength(startLength);
|
|
25
|
+
const valueKey = normalizedStartLength + '\0' + value;
|
|
26
|
+
const existing = POOLED_HASH_STATE.byValue.get(valueKey);
|
|
27
|
+
if (existing) return existing;
|
|
28
|
+
|
|
29
|
+
let length = normalizedStartLength;
|
|
30
|
+
|
|
31
|
+
while (true) {
|
|
32
|
+
if (getPooledHashUsedCount(length) >= getIdentifierSafeHashPoolSize(length)) {
|
|
33
|
+
length++;
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
for (let index = 0; index < getIdentifierSafeHashPoolSize(length); index++) {
|
|
38
|
+
const hash = getPooledHashCandidate(value, length, index);
|
|
39
|
+
const owner = POOLED_HASH_STATE.byHash.get(hash);
|
|
40
|
+
|
|
41
|
+
if (owner !== undefined && owner !== valueKey) continue;
|
|
42
|
+
|
|
43
|
+
POOLED_HASH_STATE.byValue.set(valueKey, hash);
|
|
44
|
+
POOLED_HASH_STATE.byHash.set(hash, valueKey);
|
|
45
|
+
POOLED_HASH_STATE.usedByLength[length] = getPooledHashUsedCount(length) + 1;
|
|
46
|
+
return hash;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
length++;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function getPooledHashCandidate(
|
|
54
|
+
value: string,
|
|
55
|
+
length: number,
|
|
56
|
+
index: number,
|
|
57
|
+
) {
|
|
58
|
+
const hashValue = index === 0 ? value : value + '::' + index;
|
|
59
|
+
return getIdentifierSafeHashValue(hashString(hashValue)).slice(0, length);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function getPooledHashUsedCount(length: number) {
|
|
63
|
+
return POOLED_HASH_STATE.usedByLength[length] ?? 0;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function getIdentifierSafeHashPoolSize(length: number) {
|
|
67
|
+
if (length <= 0) return 0;
|
|
68
|
+
|
|
69
|
+
return 26 * 36 ** (length - 1);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function getIdentifierSafeHashValue(hash: string) {
|
|
73
|
+
const first = hash.charCodeAt(0);
|
|
74
|
+
|
|
75
|
+
if (first < 48 || first > 57) return hash;
|
|
76
|
+
|
|
77
|
+
return String.fromCharCode(97 + first - 48) + hash.slice(1);
|
|
78
|
+
}
|
package/atomic/var.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { CSS_CONFIG } from '../config/config/css';
|
|
1
2
|
import type { VarNameFormat, VarNameInfo } from '../config/types';
|
|
2
|
-
import { getIdentifierSafeHash } from './utils/css';
|
|
3
3
|
import { createNameFormatter } from './utils/format';
|
|
4
|
+
import { getIdentifierSafeHash } from './utils/hash';
|
|
4
5
|
|
|
5
6
|
export const VAR_NAME_FORMAT = 'var[-(name)]-$hash';
|
|
6
7
|
|
|
@@ -12,7 +13,7 @@ export function getLocalVarName(
|
|
|
12
13
|
column: number,
|
|
13
14
|
format: VarNameFormat | null | undefined,
|
|
14
15
|
) {
|
|
15
|
-
const hash = getIdentifierSafeHash(filePath + '\n' + line + ':' + column);
|
|
16
|
+
const hash = getIdentifierSafeHash(filePath + '\n' + line + ':' + column, CSS_CONFIG.hashLength);
|
|
16
17
|
const name = formatVarName(format || VAR_NAME_FORMAT, hash, { name: '' });
|
|
17
18
|
|
|
18
19
|
return '--' + name;
|