1
- import type { Rule } from '@unocss/core'
1
+ import type { CSSObject , Rule } from '@unocss/core'
2
2
import { toArray } from '@unocss/core'
3
3
import type { Theme } from '../theme'
4
4
import { colorResolver , colorableShadows , h , splitShorthand } from '../utils'
5
5
6
- function handleLineHeight ( s : string , theme : Theme ) {
7
- return theme . lineHeight ?. [ s ] || h . bracket . cssvar . global . rem ( s )
6
+ function handleThemeByKey ( s : string , theme : Theme , key : 'lineHeight' | 'letterSpacing' ) {
7
+ return theme [ key ] ?. [ s ] || h . bracket . cssvar . global . rem ( s )
8
8
}
9
9
10
10
export const fonts : Rule < Theme > [ ] = [
@@ -13,14 +13,21 @@ export const fonts: Rule<Theme>[] = [
13
13
/ ^ t e x t - ( .+ ) $ / ,
14
14
( [ , s = 'base' ] , { theme } ) => {
15
15
const [ size , leading ] = splitShorthand ( s , 'length' )
16
- const sizePairs = toArray ( theme . fontSize ?. [ size ] )
17
- const lineHeight = leading ? handleLineHeight ( leading , theme ) : undefined
16
+ const sizePairs = toArray ( theme . fontSize ?. [ size ] ) as [ string , string | CSSObject , string ? ]
17
+ const lineHeight = leading ? handleThemeByKey ( leading , theme , 'lineHeight' ) : undefined
18
18
19
19
if ( sizePairs ?. [ 0 ] ) {
20
- const [ fontSize , height ] = sizePairs
20
+ const [ fontSize , height , letterSpacing ] = sizePairs
21
+ if ( typeof height === 'object' ) {
22
+ return {
23
+ 'font-size' : fontSize ,
24
+ ...height ,
25
+ }
26
+ }
21
27
return {
22
28
'font-size' : fontSize ,
23
29
'line-height' : lineHeight ?? height ?? '1' ,
30
+ 'letter-spacing' : letterSpacing ? handleThemeByKey ( letterSpacing , theme , 'letterSpacing' ) : undefined ,
24
31
}
25
32
}
26
33
@@ -37,7 +44,7 @@ export const fonts: Rule<Theme>[] = [
37
44
{ autocomplete : 'text-$fontSize' } ,
38
45
] ,
39
46
[ / ^ (?: t e x t | f o n t ) - s i z e - ( .+ ) $ / , ( [ , s ] , { theme } ) => {
40
- const themed = toArray ( theme . fontSize ?. [ s ] )
47
+ const themed = toArray ( theme . fontSize ?. [ s ] ) as [ string , string | CSSObject ]
41
48
const size = themed ?. [ 0 ] ?? h . bracket . cssvar . global . rem ( s )
42
49
if ( size != null )
43
50
return { 'font-size' : size }
@@ -58,7 +65,7 @@ export const fonts: Rule<Theme>[] = [
58
65
// leadings
59
66
[
60
67
/ ^ (?: f o n t - ) ? (?: l e a d i n g | l h | l i n e - h e i g h t ) - ( .+ ) $ / ,
61
- ( [ , s ] , { theme } ) => ( { 'line-height' : handleLineHeight ( s , theme ) } ) ,
68
+ ( [ , s ] , { theme } ) => ( { 'line-height' : handleThemeByKey ( s , theme , 'lineHeight' ) } ) ,
62
69
{ autocomplete : '(leading|lh|line-height)-$lineHeight' } ,
63
70
] ,
64
71
0 commit comments