@@ -8,7 +8,7 @@ const sd = new StyleDictionary({
8
8
css : {
9
9
prefix : 'lp' ,
10
10
transformGroup : 'css' ,
11
- transforms : [ 'name/kebab' , 'time/seconds' , 'size/rem' , 'color/rgb' ] ,
11
+ transforms : [ 'name/kebab' , 'time/seconds' , 'size/rem' , 'color/rgb' , 'attribute/font' ] ,
12
12
buildPath : 'dist/' ,
13
13
options : {
14
14
outputReferences : true ,
@@ -30,7 +30,13 @@ const sd = new StyleDictionary({
30
30
format : 'custom/media-query' ,
31
31
filter : ( token ) => token . filePath === 'src/viewport.json' ,
32
32
} ,
33
+ {
34
+ destination : 'fonts.css' ,
35
+ format : 'custom/font-face' ,
36
+ filter : ( token ) => token . $type === 'file' ,
37
+ } ,
33
38
] ,
39
+ actions : [ 'copy_assets' ] ,
34
40
} ,
35
41
js : {
36
42
transformGroup : 'js' ,
@@ -105,6 +111,26 @@ sd.registerFormat({
105
111
} ,
106
112
} ) ;
107
113
114
+ sd . registerFormat ( {
115
+ name : 'custom/font-face' ,
116
+ format : async ( { dictionary } ) => {
117
+ return dictionary . allTokens
118
+ . map ( ( token ) => {
119
+ const {
120
+ // @ts -expect-error attr
121
+ attributes : { family, weight, style } ,
122
+ formats,
123
+ $value,
124
+ } = token ;
125
+ const urls = formats . map (
126
+ ( extension : string ) => `url("./assets/${ $value } .${ extension } ") format("${ extension } ")` ,
127
+ ) ;
128
+ return `@font-face {\n\tfont-family: "${ family } ";\n\tfont-style: ${ style } ;\n\tfont-weight: ${ weight } ;\n\tsrc: ${ urls . join ( ',\n\t\t\t ' ) } ;\n\tfont-display: swap;\n}\n` ;
129
+ } )
130
+ . join ( '\n' ) ;
131
+ } ,
132
+ } ) ;
133
+
108
134
sd . registerFormat ( {
109
135
name : 'custom/json' ,
110
136
format : async ( { dictionary, options } ) => {
@@ -167,4 +193,17 @@ sd.registerTransform({
167
193
} ,
168
194
} ) ;
169
195
196
+ sd . registerTransform ( {
197
+ name : 'attribute/font' ,
198
+ type : 'attribute' ,
199
+ filter : ( token ) => token . $type === 'file' ,
200
+ transform : ( token ) => ( {
201
+ category : token . path [ 0 ] ,
202
+ type : token . path [ 1 ] ,
203
+ family : token . path [ 2 ] ,
204
+ weight : token . path [ 3 ] ,
205
+ style : token . path [ 4 ] ,
206
+ } ) ,
207
+ } ) ;
208
+
170
209
await sd . buildAllPlatforms ( ) ;
0 commit comments