@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
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import type { TOKEN_ID } from '../../../style/token';
|
|
2
|
+
import type { TailwindTheme } from '../types';
|
|
3
|
+
|
|
4
|
+
type ScaleKey = string | number;
|
|
5
|
+
type ScaleLeaf = ((...args: any[]) => unknown) | { readonly [TOKEN_ID]: string; };
|
|
6
|
+
type KebabCaseRest<Value extends string> = Value extends `${infer Head}${infer Tail}`
|
|
7
|
+
? Head extends Lowercase<Head> ? `${Head}${KebabCaseRest<Tail>}` : `-${Lowercase<Head>}${KebabCaseRest<Tail>}`
|
|
8
|
+
: Value;
|
|
9
|
+
type KebabCase<Value extends string> = Value extends `${infer Head}${infer Tail}`
|
|
10
|
+
? `${Lowercase<Head>}${KebabCaseRest<Tail>}`
|
|
11
|
+
: Value;
|
|
12
|
+
type ScaleClassKey<Key extends ScaleKey> = Key extends string ? KebabCase<Key> : `${Key}`;
|
|
13
|
+
type KnownScaleKeys<Scale> = keyof NonNullable<Scale> extends infer Key
|
|
14
|
+
? Key extends ScaleKey ? string extends Key ? never
|
|
15
|
+
: number extends Key ? never
|
|
16
|
+
: Key
|
|
17
|
+
: never
|
|
18
|
+
: never;
|
|
19
|
+
type ScaleClassPath<Scale> = Scale extends unknown ? NonNullable<Scale> extends infer ResolvedScale ? {
|
|
20
|
+
[Key in Extract<KnownScaleKeys<ResolvedScale>, ScaleKey>]: ResolvedScale[Key] extends ScaleLeaf
|
|
21
|
+
? ScaleClassKey<Key>
|
|
22
|
+
: ResolvedScale[Key] extends Record<ScaleKey, unknown>
|
|
23
|
+
? `${ScaleClassKey<Key>}-${Extract<ScaleClassPath<ResolvedScale[Key]>, string>}`
|
|
24
|
+
: ScaleClassKey<Key>;
|
|
25
|
+
}[Extract<KnownScaleKeys<ResolvedScale>, ScaleKey>]
|
|
26
|
+
: never
|
|
27
|
+
: never;
|
|
28
|
+
type ScaleValue<Scale> = ScaleClassPath<Scale>;
|
|
29
|
+
type ArbitraryValue = `[${string}]`;
|
|
30
|
+
type ColorLiteral = 'transparent' | 'current' | 'black' | 'white';
|
|
31
|
+
type LengthLiteral = 'auto' | 'full' | 'screen' | 'min' | 'max' | 'fit' | '0';
|
|
32
|
+
type ArbitraryClassName = `[${string}:${string}]`;
|
|
33
|
+
|
|
34
|
+
type TailwindStaticClassName =
|
|
35
|
+
| 'block'
|
|
36
|
+
| 'inline-block'
|
|
37
|
+
| 'inline-flex'
|
|
38
|
+
| 'flex'
|
|
39
|
+
| 'grid'
|
|
40
|
+
| 'hidden'
|
|
41
|
+
| 'relative'
|
|
42
|
+
| 'absolute'
|
|
43
|
+
| 'fixed'
|
|
44
|
+
| 'sticky'
|
|
45
|
+
| 'items-start'
|
|
46
|
+
| 'items-end'
|
|
47
|
+
| 'items-center'
|
|
48
|
+
| 'items-baseline'
|
|
49
|
+
| 'items-stretch'
|
|
50
|
+
| 'justify-start'
|
|
51
|
+
| 'justify-end'
|
|
52
|
+
| 'justify-center'
|
|
53
|
+
| 'justify-between'
|
|
54
|
+
| 'justify-around'
|
|
55
|
+
| 'justify-evenly'
|
|
56
|
+
| 'flex-row'
|
|
57
|
+
| 'flex-row-reverse'
|
|
58
|
+
| 'flex-col'
|
|
59
|
+
| 'flex-col-reverse'
|
|
60
|
+
| 'flex-wrap'
|
|
61
|
+
| 'flex-wrap-reverse'
|
|
62
|
+
| 'shrink-0'
|
|
63
|
+
| 'overflow-hidden'
|
|
64
|
+
| 'overflow-auto'
|
|
65
|
+
| 'overflow-x-hidden'
|
|
66
|
+
| 'overflow-x-auto'
|
|
67
|
+
| 'overflow-y-hidden'
|
|
68
|
+
| 'overflow-y-auto'
|
|
69
|
+
| 'cursor-pointer'
|
|
70
|
+
| 'outline-none'
|
|
71
|
+
| 'whitespace-nowrap'
|
|
72
|
+
| 'min-w-0'
|
|
73
|
+
| 'justify-self-end';
|
|
74
|
+
|
|
75
|
+
type TailwindSpacingClassName<Theme extends TailwindTheme> =
|
|
76
|
+
| `gap-${ScaleValue<Theme['spacing']> | ArbitraryValue | LengthLiteral}`
|
|
77
|
+
| `gap-x-${ScaleValue<Theme['spacing']> | ArbitraryValue | LengthLiteral}`
|
|
78
|
+
| `gap-y-${ScaleValue<Theme['spacing']> | ArbitraryValue | LengthLiteral}`
|
|
79
|
+
| `mt-${ScaleValue<Theme['spacing']> | ArbitraryValue | LengthLiteral}`
|
|
80
|
+
| `m-${ScaleValue<Theme['spacing']> | ArbitraryValue | LengthLiteral}`
|
|
81
|
+
| `mx-${ScaleValue<Theme['spacing']> | ArbitraryValue | LengthLiteral}`
|
|
82
|
+
| `my-${ScaleValue<Theme['spacing']> | ArbitraryValue | LengthLiteral}`
|
|
83
|
+
| `p-${ScaleValue<Theme['spacing']> | ArbitraryValue | LengthLiteral}`
|
|
84
|
+
| `px-${ScaleValue<Theme['spacing']> | ArbitraryValue | LengthLiteral}`
|
|
85
|
+
| `py-${ScaleValue<Theme['spacing']> | ArbitraryValue | LengthLiteral}`
|
|
86
|
+
| `pt-${ScaleValue<Theme['spacing']> | ArbitraryValue | LengthLiteral}`
|
|
87
|
+
| `pr-${ScaleValue<Theme['spacing']> | ArbitraryValue | LengthLiteral}`
|
|
88
|
+
| `pb-${ScaleValue<Theme['spacing']> | ArbitraryValue | LengthLiteral}`
|
|
89
|
+
| `pl-${ScaleValue<Theme['spacing']> | ArbitraryValue | LengthLiteral}`;
|
|
90
|
+
|
|
91
|
+
type TailwindSizeClassName<Theme extends TailwindTheme> =
|
|
92
|
+
| `w-${ScaleValue<Theme['sizes']> | ScaleValue<Theme['spacing']> | ArbitraryValue | LengthLiteral}`
|
|
93
|
+
| `max-w-${ScaleValue<Theme['sizes']> | ScaleValue<Theme['spacing']> | ArbitraryValue | LengthLiteral}`
|
|
94
|
+
| `min-w-${ScaleValue<Theme['sizes']> | ScaleValue<Theme['spacing']> | ArbitraryValue | LengthLiteral}`
|
|
95
|
+
| `min-h-${ScaleValue<Theme['sizes']> | ScaleValue<Theme['spacing']> | ArbitraryValue | LengthLiteral}`
|
|
96
|
+
| `h-${ScaleValue<Theme['sizes']> | ScaleValue<Theme['spacing']> | ArbitraryValue | LengthLiteral}`
|
|
97
|
+
| `size-${ScaleValue<Theme['sizes']> | ScaleValue<Theme['spacing']> | ArbitraryValue | LengthLiteral}`;
|
|
98
|
+
|
|
99
|
+
type TailwindColorClassName<Theme extends TailwindTheme> =
|
|
100
|
+
| `bg-${ScaleValue<Theme['colors']> | ArbitraryValue | ColorLiteral}`
|
|
101
|
+
| `text-${ScaleValue<Theme['colors']> | ArbitraryValue | ColorLiteral}`
|
|
102
|
+
| `border-${ScaleValue<Theme['colors']> | ArbitraryValue | ColorLiteral}`
|
|
103
|
+
| `outline-${ScaleValue<Theme['colors']> | ArbitraryValue | ColorLiteral}`;
|
|
104
|
+
|
|
105
|
+
type TailwindTypographyClassName<Theme extends TailwindTheme> =
|
|
106
|
+
| `text-${ScaleValue<Theme['fontSizes']> | ArbitraryValue}`
|
|
107
|
+
| `font-${ScaleValue<Theme['fontWeights']> | ArbitraryValue}`
|
|
108
|
+
| `leading-${ScaleValue<Theme['lineHeights']> | ArbitraryValue}`;
|
|
109
|
+
|
|
110
|
+
type TailwindVisualClassName<Theme extends TailwindTheme> =
|
|
111
|
+
| `rounded-${ScaleValue<Theme['radii']> | ArbitraryValue}`
|
|
112
|
+
| `shadow-${ScaleValue<Theme['shadows']> | ArbitraryValue}`
|
|
113
|
+
| `border-${string}`;
|
|
114
|
+
|
|
115
|
+
export type TailwindClassNameFor<Theme extends TailwindTheme> =
|
|
116
|
+
| TailwindStaticClassName
|
|
117
|
+
| TailwindSpacingClassName<Theme>
|
|
118
|
+
| TailwindSizeClassName<Theme>
|
|
119
|
+
| TailwindColorClassName<Theme>
|
|
120
|
+
| TailwindTypographyClassName<Theme>
|
|
121
|
+
| TailwindVisualClassName<Theme>
|
|
122
|
+
| ArbitraryClassName;
|
|
123
|
+
|
|
124
|
+
export type TailwindClassName = TailwindClassNameFor<TailwindTheme>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { selector, selectorPriority } from '../../selector';
|
|
2
|
+
import { PrioritySelectors } from '../../selector/presets';
|
|
3
|
+
|
|
4
|
+
export const TailwindResponsiveSelectors = {
|
|
5
|
+
sm: selector('@media (min-width: 640px)', 'media'),
|
|
6
|
+
md: selector('@media (min-width: 768px)', 'media'),
|
|
7
|
+
lg: selector('@media (min-width: 1024px)', 'media'),
|
|
8
|
+
xl: selector('@media (min-width: 1280px)', 'media'),
|
|
9
|
+
xxl: selector('@media (min-width: 1536px)', 'media'),
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export const TailwindDarkSelector = selector(':where(.dark, .dark *)');
|
|
13
|
+
|
|
14
|
+
export const TailwindSelectors = selectorPriority({
|
|
15
|
+
...PrioritySelectors,
|
|
16
|
+
...TailwindResponsiveSelectors,
|
|
17
|
+
dark: TailwindDarkSelector,
|
|
18
|
+
}, [
|
|
19
|
+
'link',
|
|
20
|
+
'visited',
|
|
21
|
+
'hover',
|
|
22
|
+
'focusWithin',
|
|
23
|
+
'focus',
|
|
24
|
+
'focusVisible',
|
|
25
|
+
'active',
|
|
26
|
+
'disabled',
|
|
27
|
+
]);
|
|
@@ -0,0 +1,430 @@
|
|
|
1
|
+
import { getNamedToken } from '../../../dialect';
|
|
2
|
+
import { isStyleTokenData } from '../../../style/token';
|
|
3
|
+
import { styleTransform } from '../../../style/transform';
|
|
4
|
+
import type { CSSProperties } from '../../../style/types';
|
|
5
|
+
import { defaultTailwindTheme } from '../theme';
|
|
6
|
+
import type {
|
|
7
|
+
MergeTailwindTheme,
|
|
8
|
+
TailwindDefaultTheme,
|
|
9
|
+
TailwindScale,
|
|
10
|
+
TailwindStyleConfig,
|
|
11
|
+
TailwindStyleTransformOptions,
|
|
12
|
+
TailwindTheme,
|
|
13
|
+
} from '../types';
|
|
14
|
+
import type { TailwindExtendedStyle, TailwindStyle } from './types';
|
|
15
|
+
|
|
16
|
+
type CssOutput = Record<string, unknown>;
|
|
17
|
+
type UtilityResolver<Theme extends TailwindTheme> = (
|
|
18
|
+
value: unknown,
|
|
19
|
+
css: CssOutput,
|
|
20
|
+
theme: Theme,
|
|
21
|
+
) => void;
|
|
22
|
+
|
|
23
|
+
export function createTailwindStyleTransform<const Theme extends TailwindTheme = TailwindTheme>(
|
|
24
|
+
config: TailwindStyleConfig<Theme> = createTailwindStyleConfig({}),
|
|
25
|
+
) {
|
|
26
|
+
return createTailwindTransform<TailwindStyle<Theme>, Theme>(config);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function createTailwindExtendedStyleTransform<const Theme extends TailwindTheme = TailwindTheme>(
|
|
30
|
+
config: TailwindStyleConfig<Theme> = createTailwindStyleConfig({}),
|
|
31
|
+
) {
|
|
32
|
+
return createTailwindTransform<TailwindExtendedStyle<Theme>, Theme>(config);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function createTailwindTransform<Style, Theme extends TailwindTheme>(
|
|
36
|
+
config: TailwindStyleConfig<Theme>,
|
|
37
|
+
) {
|
|
38
|
+
const theme = config.theme;
|
|
39
|
+
|
|
40
|
+
const utilities = createTailwindUtilities<Theme>();
|
|
41
|
+
|
|
42
|
+
return styleTransform<Style>({
|
|
43
|
+
transform(style) {
|
|
44
|
+
const css: CssOutput = {};
|
|
45
|
+
|
|
46
|
+
for (const property in style) {
|
|
47
|
+
const value = style[property as keyof typeof style];
|
|
48
|
+
const utility = utilities[property];
|
|
49
|
+
|
|
50
|
+
if (utility) {
|
|
51
|
+
utility(value, css, theme);
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
css[property] = value;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return css as CSSProperties;
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const { colors: _defaultTailwindColors, ...defaultTailwindNonColorTheme } = defaultTailwindTheme;
|
|
64
|
+
|
|
65
|
+
export const defaultTailwindStyleConfig = {
|
|
66
|
+
theme: defaultTailwindNonColorTheme,
|
|
67
|
+
} as TailwindStyleConfig<TailwindDefaultTheme>;
|
|
68
|
+
|
|
69
|
+
export function createTailwindStyleConfig<const Theme extends TailwindTheme>(
|
|
70
|
+
options: TailwindStyleTransformOptions<Theme>,
|
|
71
|
+
): TailwindStyleConfig<Theme> {
|
|
72
|
+
return {
|
|
73
|
+
theme: options.theme ?? ({} as Theme),
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function createDefaultedTailwindStyleConfig<const Theme extends TailwindTheme>(
|
|
78
|
+
options: TailwindStyleTransformOptions<Theme>,
|
|
79
|
+
): TailwindStyleConfig<MergeTailwindTheme<TailwindDefaultTheme, Theme>> {
|
|
80
|
+
return mergeTailwindStyleConfig(
|
|
81
|
+
defaultTailwindStyleConfig,
|
|
82
|
+
createTailwindStyleConfig(options),
|
|
83
|
+
) as TailwindStyleConfig<MergeTailwindTheme<TailwindDefaultTheme, Theme>>;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export function mergeTailwindStyleConfig<
|
|
87
|
+
const BaseTheme extends TailwindTheme,
|
|
88
|
+
const OverrideTheme extends TailwindTheme,
|
|
89
|
+
>(
|
|
90
|
+
base: TailwindStyleConfig<BaseTheme>,
|
|
91
|
+
override: TailwindStyleConfig<OverrideTheme>,
|
|
92
|
+
): TailwindStyleConfig<BaseTheme & OverrideTheme> {
|
|
93
|
+
return {
|
|
94
|
+
theme: mergeTailwindTheme(base.theme, override.theme) as BaseTheme & OverrideTheme,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function mergeTailwindTheme(
|
|
99
|
+
base: TailwindTheme,
|
|
100
|
+
override: TailwindTheme,
|
|
101
|
+
): TailwindTheme {
|
|
102
|
+
return {
|
|
103
|
+
...base,
|
|
104
|
+
...override,
|
|
105
|
+
spacing: mergeScale(base.spacing, override.spacing),
|
|
106
|
+
colors: mergeScale(base.colors, override.colors),
|
|
107
|
+
radii: mergeScale(base.radii, override.radii),
|
|
108
|
+
fontSizes: mergeScale(base.fontSizes, override.fontSizes),
|
|
109
|
+
fontWeights: mergeScale(base.fontWeights, override.fontWeights),
|
|
110
|
+
lineHeights: mergeScale(base.lineHeights, override.lineHeights),
|
|
111
|
+
letterSpacings: mergeScale(base.letterSpacings, override.letterSpacings),
|
|
112
|
+
shadows: mergeScale(base.shadows, override.shadows),
|
|
113
|
+
sizes: mergeScale(base.sizes, override.sizes),
|
|
114
|
+
zIndices: mergeScale(base.zIndices, override.zIndices),
|
|
115
|
+
opacity: mergeScale(base.opacity, override.opacity),
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function mergeScale(
|
|
120
|
+
base: TailwindScale | undefined,
|
|
121
|
+
override: TailwindScale | undefined,
|
|
122
|
+
): TailwindScale | undefined {
|
|
123
|
+
if (!override) return base;
|
|
124
|
+
if (!base || !isMergeableScale(base)) return override;
|
|
125
|
+
if (!isMergeableScale(override)) return [override, base] as unknown as TailwindScale;
|
|
126
|
+
|
|
127
|
+
return {
|
|
128
|
+
...base,
|
|
129
|
+
...override,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function isMergeableScale(scale: TailwindScale): boolean {
|
|
134
|
+
return !!scale && typeof scale === 'object' && !Array.isArray(scale);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function createTailwindUtilities<Theme extends TailwindTheme>(): Record<string, UtilityResolver<Theme>> {
|
|
138
|
+
return {
|
|
139
|
+
block: displayUtility('block'),
|
|
140
|
+
inlineBlock: displayUtility('inline-block'),
|
|
141
|
+
inlineFlex: displayUtility('inline-flex'),
|
|
142
|
+
grid: displayUtility('grid'),
|
|
143
|
+
hidden: displayUtility('none'),
|
|
144
|
+
flex: flexUtility,
|
|
145
|
+
|
|
146
|
+
direction: mapUtility('flexDirection', {
|
|
147
|
+
row: 'row',
|
|
148
|
+
rowReverse: 'row-reverse',
|
|
149
|
+
col: 'column',
|
|
150
|
+
colReverse: 'column-reverse',
|
|
151
|
+
}),
|
|
152
|
+
wrap: mapUtility('flexWrap', {
|
|
153
|
+
true: 'wrap',
|
|
154
|
+
reverse: 'wrap-reverse',
|
|
155
|
+
}),
|
|
156
|
+
items: mapUtility('alignItems', alignmentMap),
|
|
157
|
+
justify: mapUtility('justifyContent', justifyMap),
|
|
158
|
+
content: mapUtility('alignContent', justifyMap),
|
|
159
|
+
self: mapUtility('alignSelf', alignmentMap),
|
|
160
|
+
|
|
161
|
+
p: scaleUtility('spacing', 'padding'),
|
|
162
|
+
px: scaleUtility('spacing', 'paddingInline'),
|
|
163
|
+
py: scaleUtility('spacing', 'paddingBlock'),
|
|
164
|
+
pt: scaleUtility('spacing', 'paddingTop'),
|
|
165
|
+
pr: scaleUtility('spacing', 'paddingRight'),
|
|
166
|
+
pb: scaleUtility('spacing', 'paddingBottom'),
|
|
167
|
+
pl: scaleUtility('spacing', 'paddingLeft'),
|
|
168
|
+
ps: scaleUtility('spacing', 'paddingInlineStart'),
|
|
169
|
+
pe: scaleUtility('spacing', 'paddingInlineEnd'),
|
|
170
|
+
|
|
171
|
+
m: scaleUtility('spacing', 'margin'),
|
|
172
|
+
mx: scaleUtility('spacing', 'marginInline'),
|
|
173
|
+
my: scaleUtility('spacing', 'marginBlock'),
|
|
174
|
+
mt: scaleUtility('spacing', 'marginTop'),
|
|
175
|
+
mr: scaleUtility('spacing', 'marginRight'),
|
|
176
|
+
mb: scaleUtility('spacing', 'marginBottom'),
|
|
177
|
+
ml: scaleUtility('spacing', 'marginLeft'),
|
|
178
|
+
ms: scaleUtility('spacing', 'marginInlineStart'),
|
|
179
|
+
me: scaleUtility('spacing', 'marginInlineEnd'),
|
|
180
|
+
|
|
181
|
+
gap: scaleUtility('spacing', 'gap'),
|
|
182
|
+
gapX: scaleUtility('spacing', 'columnGap'),
|
|
183
|
+
gapY: scaleUtility('spacing', 'rowGap'),
|
|
184
|
+
|
|
185
|
+
w: sizeUtility('width'),
|
|
186
|
+
minW: sizeUtility('minWidth'),
|
|
187
|
+
maxW: sizeUtility('maxWidth'),
|
|
188
|
+
h: sizeUtility('height'),
|
|
189
|
+
minH: sizeUtility('minHeight'),
|
|
190
|
+
maxH: sizeUtility('maxHeight'),
|
|
191
|
+
size: sizePairUtility,
|
|
192
|
+
|
|
193
|
+
bg: colorUtility('backgroundColor'),
|
|
194
|
+
text: textUtility,
|
|
195
|
+
borderColor: colorUtility('borderColor'),
|
|
196
|
+
outlineColor: colorUtility('outlineColor'),
|
|
197
|
+
ringColor: colorUtility('--tw-ring-color'),
|
|
198
|
+
|
|
199
|
+
textSize: scaleUtility('fontSizes', 'fontSize'),
|
|
200
|
+
font: scaleUtility('fontWeights', 'fontWeight'),
|
|
201
|
+
leading: scaleUtility('lineHeights', 'lineHeight'),
|
|
202
|
+
tracking: scaleUtility('letterSpacings', 'letterSpacing'),
|
|
203
|
+
align: propertyUtility('textAlign'),
|
|
204
|
+
|
|
205
|
+
rounded: scaleUtility('radii', 'borderRadius'),
|
|
206
|
+
roundedT: multiScaleUtility('radii', ['borderTopLeftRadius', 'borderTopRightRadius']),
|
|
207
|
+
roundedR: multiScaleUtility('radii', ['borderTopRightRadius', 'borderBottomRightRadius']),
|
|
208
|
+
roundedB: multiScaleUtility('radii', ['borderBottomRightRadius', 'borderBottomLeftRadius']),
|
|
209
|
+
roundedL: multiScaleUtility('radii', ['borderTopLeftRadius', 'borderBottomLeftRadius']),
|
|
210
|
+
roundedTl: scaleUtility('radii', 'borderTopLeftRadius'),
|
|
211
|
+
roundedTr: scaleUtility('radii', 'borderTopRightRadius'),
|
|
212
|
+
roundedBr: scaleUtility('radii', 'borderBottomRightRadius'),
|
|
213
|
+
roundedBl: scaleUtility('radii', 'borderBottomLeftRadius'),
|
|
214
|
+
|
|
215
|
+
shadow: scaleUtility('shadows', 'boxShadow'),
|
|
216
|
+
opacity: scaleUtility('opacity', 'opacity'),
|
|
217
|
+
z: scaleUtility('zIndices', 'zIndex'),
|
|
218
|
+
|
|
219
|
+
relative: positionUtility('relative'),
|
|
220
|
+
absolute: positionUtility('absolute'),
|
|
221
|
+
fixed: positionUtility('fixed'),
|
|
222
|
+
sticky: positionUtility('sticky'),
|
|
223
|
+
inset: scaleUtility('spacing', 'inset'),
|
|
224
|
+
insetX: multiScaleUtility('spacing', ['left', 'right']),
|
|
225
|
+
insetY: multiScaleUtility('spacing', ['top', 'bottom']),
|
|
226
|
+
top: scaleUtility('spacing', 'top'),
|
|
227
|
+
right: scaleUtility('spacing', 'right'),
|
|
228
|
+
bottom: scaleUtility('spacing', 'bottom'),
|
|
229
|
+
left: scaleUtility('spacing', 'left'),
|
|
230
|
+
|
|
231
|
+
select: mapUtility('userSelect', {
|
|
232
|
+
none: 'none',
|
|
233
|
+
text: 'text',
|
|
234
|
+
all: 'all',
|
|
235
|
+
auto: 'auto',
|
|
236
|
+
}),
|
|
237
|
+
pointerEvents: mapUtility('pointerEvents', {
|
|
238
|
+
none: 'none',
|
|
239
|
+
auto: 'auto',
|
|
240
|
+
}),
|
|
241
|
+
cursor: propertyUtility('cursor'),
|
|
242
|
+
overflow: propertyUtility('overflow'),
|
|
243
|
+
overflowX: propertyUtility('overflowX'),
|
|
244
|
+
overflowY: propertyUtility('overflowY'),
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
const alignmentMap = {
|
|
249
|
+
auto: 'auto',
|
|
250
|
+
start: 'flex-start',
|
|
251
|
+
end: 'flex-end',
|
|
252
|
+
center: 'center',
|
|
253
|
+
baseline: 'baseline',
|
|
254
|
+
stretch: 'stretch',
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
const justifyMap = {
|
|
258
|
+
start: 'flex-start',
|
|
259
|
+
end: 'flex-end',
|
|
260
|
+
center: 'center',
|
|
261
|
+
between: 'space-between',
|
|
262
|
+
around: 'space-around',
|
|
263
|
+
evenly: 'space-evenly',
|
|
264
|
+
stretch: 'stretch',
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
function displayUtility(display: CSSProperties['display']): UtilityResolver<TailwindTheme> {
|
|
268
|
+
return (value, css) => {
|
|
269
|
+
if (value) css.display = display;
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
function flexUtility(value: unknown, css: CssOutput) {
|
|
274
|
+
if (value === true) {
|
|
275
|
+
css.display = 'flex';
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
if (value !== false && value !== undefined) {
|
|
280
|
+
css.flex = value;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
function positionUtility(position: CSSProperties['position']): UtilityResolver<TailwindTheme> {
|
|
285
|
+
return (value, css) => {
|
|
286
|
+
if (value) css.position = position;
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
function propertyUtility(property: keyof CSSProperties): UtilityResolver<TailwindTheme> {
|
|
291
|
+
return (value, css) => {
|
|
292
|
+
if (value !== undefined) css[property] = value;
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
function scaleUtility<Theme extends TailwindTheme>(
|
|
297
|
+
scaleName: keyof TailwindTheme,
|
|
298
|
+
property: string,
|
|
299
|
+
): UtilityResolver<Theme> {
|
|
300
|
+
return (value, css, theme) => {
|
|
301
|
+
if (value !== undefined) css[property] = resolveScale(theme[scaleName], value);
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
function colorUtility(property: string): UtilityResolver<TailwindTheme> {
|
|
306
|
+
return (value, css, theme) => {
|
|
307
|
+
if (value !== undefined) css[property] = resolveScale(theme.colors, value);
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
function textUtility(value: unknown, css: CssOutput, theme: TailwindTheme) {
|
|
312
|
+
if (value === undefined) return;
|
|
313
|
+
|
|
314
|
+
if (typeof value === 'string' && textAlignValues.has(value)) {
|
|
315
|
+
css.textAlign = value;
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
const fontSize = resolveScale(theme.fontSizes, value);
|
|
320
|
+
if (fontSize !== value) {
|
|
321
|
+
css.fontSize = fontSize;
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
css.color = resolveScale(theme.colors, value);
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
function sizeUtility(property: string): UtilityResolver<TailwindTheme> {
|
|
329
|
+
return (value, css, theme) => {
|
|
330
|
+
if (value !== undefined) css[property] = resolveSize(property, theme, value);
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
function sizePairUtility(value: unknown, css: CssOutput, theme: TailwindTheme) {
|
|
335
|
+
if (value === undefined) return;
|
|
336
|
+
|
|
337
|
+
const resolved = resolveScales([theme.sizes, theme.spacing], value);
|
|
338
|
+
css.width = resolved;
|
|
339
|
+
css.height = resolved;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
function resolveSize(property: string, theme: TailwindTheme, value: unknown) {
|
|
343
|
+
if (isHeightProperty(property) && value === '$screen') return '100vh';
|
|
344
|
+
return resolveScales([theme.sizes, theme.spacing], value);
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
function isHeightProperty(property: string) {
|
|
348
|
+
return property === 'height' || property === 'minHeight' || property === 'maxHeight';
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
function multiScaleUtility(
|
|
352
|
+
scaleName: keyof TailwindTheme,
|
|
353
|
+
properties: string[],
|
|
354
|
+
): UtilityResolver<TailwindTheme> {
|
|
355
|
+
return (value, css, theme) => {
|
|
356
|
+
if (value === undefined) return;
|
|
357
|
+
|
|
358
|
+
const resolved = resolveScale(theme[scaleName], value);
|
|
359
|
+
for (let i = 0; i < properties.length; i++) {
|
|
360
|
+
css[properties[i]] = resolved;
|
|
361
|
+
}
|
|
362
|
+
};
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
function mapUtility(property: string, values: Record<string, unknown>): UtilityResolver<TailwindTheme> {
|
|
366
|
+
return (value, css) => {
|
|
367
|
+
if (value === undefined) return;
|
|
368
|
+
|
|
369
|
+
const key = String(value);
|
|
370
|
+
css[property] = key in values ? values[key] : value;
|
|
371
|
+
};
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
function resolveScale(scale: TailwindScale | undefined, value: unknown) {
|
|
375
|
+
if (!scale || isStyleTokenData(value)) return value;
|
|
376
|
+
if (Array.isArray(scale)) return resolveScales(scale, value);
|
|
377
|
+
|
|
378
|
+
const key = getScaleRef(value);
|
|
379
|
+
if (key === null) return value;
|
|
380
|
+
|
|
381
|
+
const token = getNamedToken(scale, value as string);
|
|
382
|
+
if (token) return token;
|
|
383
|
+
|
|
384
|
+
const resolved = getScaleValue(scale, key);
|
|
385
|
+
if (resolved.found) return resolved.value;
|
|
386
|
+
|
|
387
|
+
return value;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
function resolveScales(scales: (TailwindScale | undefined)[], value: unknown) {
|
|
391
|
+
if (isStyleTokenData(value)) return value;
|
|
392
|
+
|
|
393
|
+
const key = getScaleRef(value);
|
|
394
|
+
if (key === null) return value;
|
|
395
|
+
|
|
396
|
+
for (let i = 0; i < scales.length; i++) {
|
|
397
|
+
const scale = scales[i];
|
|
398
|
+
if (!scale) continue;
|
|
399
|
+
|
|
400
|
+
const token = getNamedToken(scale, value as string);
|
|
401
|
+
if (token) return token;
|
|
402
|
+
|
|
403
|
+
const resolved = getScaleValue(scale, key);
|
|
404
|
+
if (resolved.found) return resolved.value;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
return value;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
function getScaleValue(scale: TailwindScale, key: string) {
|
|
411
|
+
if (key in scale) return { found: true, value: scale[key] };
|
|
412
|
+
|
|
413
|
+
const path = key.split('.');
|
|
414
|
+
let current: unknown = scale;
|
|
415
|
+
|
|
416
|
+
for (let i = 0; i < path.length; i++) {
|
|
417
|
+
if (!current || typeof current !== 'object') return { found: false, value: undefined };
|
|
418
|
+
if (!(path[i] in current)) return { found: false, value: undefined };
|
|
419
|
+
current = (current as Record<string, unknown>)[path[i]];
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
return { found: true, value: current };
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
function getScaleRef(value: unknown) {
|
|
426
|
+
if (typeof value !== 'string' || !value.startsWith('$')) return null;
|
|
427
|
+
return value.slice(1);
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
const textAlignValues = new Set(['left', 'center', 'right', 'justify', 'start', 'end']);
|