1
1
import { parseStyle } from '../utils/styles' ;
2
+ import { Styles } from './types' ;
3
+
4
+ function setCSSValue (
5
+ styles : Styles ,
6
+ styleName : string ,
7
+ presetName : string ,
8
+ isPropOnly = false ,
9
+ ) {
10
+ styles [ `--${ styleName } ` ] =
11
+ presetName === 'inherit'
12
+ ? 'inherit'
13
+ : `var(--${ presetName } -${ styleName } , var(--default-${ styleName } , inherit))` ;
14
+
15
+ if ( ! isPropOnly ) {
16
+ styles [ styleName ] = styles [ `--${ styleName } ` ] ;
17
+ }
18
+ }
2
19
3
20
export function presetStyle ( {
4
21
preset,
@@ -18,50 +35,38 @@ export function presetStyle({
18
35
19
36
const name = mods [ 0 ] || 'default' ;
20
37
21
- const styles : Record < string , any > = { } ;
38
+ const styles : Styles = { } ;
22
39
23
40
if ( ! fontSize ) {
24
- styles [ 'font-size' ] = styles [
25
- '--font-size'
26
- ] = `var(--${ name } -font-size, var(--initial-font-size, inherit))` ;
41
+ setCSSValue ( styles , 'font-size' , name ) ;
27
42
}
28
43
29
44
if ( ! lineHeight ) {
30
- styles [ 'line-height' ] = styles [
31
- '--line-height'
32
- ] = `var(--${ name } -line-height, var(--initial-line-height, 1.5))` ;
45
+ setCSSValue ( styles , 'line-height' , name ) ;
33
46
}
34
47
35
48
if ( ! letterSpacing ) {
36
- styles [ 'letter-spacing' ] = styles [
37
- '--letter-spacing'
38
- ] = `var(--${ name } -letter-spacing, var(--initial-letter-spacing, 0))` ;
49
+ setCSSValue ( styles , 'letter-spacing' , name ) ;
39
50
}
40
51
41
52
if ( ! fontWeight ) {
42
- styles [ 'font-weight' ] = styles [
43
- '--font-weight'
44
- ] = `var(--${ name } -font-weight, var(--initial-font-weight, 400))` ;
53
+ setCSSValue ( styles , 'font-weight' , name ) ;
45
54
}
46
55
47
56
if ( ! fontStyle ) {
48
- styles [ 'font-style' ] = styles [
49
- '--font-style'
50
- ] = `var(--${ name } -font-style, var(--initial-font-style, normal))` ;
57
+ setCSSValue ( styles , 'font-style' , name ) ;
51
58
}
52
59
53
60
if ( ! textTransform ) {
54
- styles [ 'text-transform' ] = styles [
55
- '--text-transform'
56
- ] = `var(--${ name } -text-transform, var(--initial-text-transform, none))` ;
61
+ setCSSValue ( styles , 'text-transform' , name ) ;
57
62
}
58
63
59
64
if ( ! font ) {
60
- styles [ 'font-family' ] = styles [
61
- '--font-family'
62
- ] = `var(--${ name } -font-family, var(--font))` ;
65
+ setCSSValue ( styles , 'font-family' , name ) ;
63
66
}
64
67
68
+ setCSSValue ( styles , 'bold-font-weight' , name , true ) ;
69
+
65
70
return styles ;
66
71
}
67
72
0 commit comments