-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathfont-css.ts
32 lines (32 loc) · 990 Bytes
/
font-css.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import {Transform, TransformedToken} from 'style-dictionary/types'
import {isTypography} from '../filter/isTypography.js'
import {getValue} from '../utilities/getValue.js'
type TokenTypography = {
fontFamily: string
fontSize: number
fontWeight?: number
lineHeight?: number
fontStyle?: string
}
/**
* @description convert a w3c `typography` token to a value that can be used with the css `font` property
*/
export const fontCss: Transform = {
name: 'font/css',
type: `value`,
transitive: true,
filter: isTypography,
transform: (token: TransformedToken) => {
const tokenValue = getValue<TokenTypography>(token)
if (!tokenValue) return
// font: font-style font-variant font-weight font-size/line-height font-family;
return [
tokenValue.fontStyle,
tokenValue.fontWeight,
`${tokenValue.fontSize}${tokenValue.lineHeight ? '/' + tokenValue.lineHeight : ''}`,
tokenValue.fontFamily,
]
.filter(Boolean)
.join(' ')
},
}