-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstyle-dictionary.config.mjs
105 lines (95 loc) · 2.56 KB
/
style-dictionary.config.mjs
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import StyleDictionary from "style-dictionary";
StyleDictionary.registerTransform({
name: "attribute/font",
type: "attribute",
transform: prop =>
({
category: prop.path[0],
type: prop.path[1],
family: prop.path[2],
weight: prop.path[3],
style: prop.path[4]
})
});
StyleDictionary.registerFormat({
name: "font-face",
format: ({ dictionary: { allTokens }, options }) => {
const fontPathPrefix = options.fontPathPrefix || "../";
// https://developer.mozilla.org/en-US/docs/Web/CSS/@font-face/src
const formatsMap = {
"woff2": "woff2",
"woff": "woff",
"ttf": "truetype",
"otf": "opentype",
"svg": "svg",
"eot": "embedded-opentype"
};
return allTokens.reduce((fontList, prop) => {
const {
attributes: { family, weight, style },
formats,
value: path
} = prop;
const urls = formats
.map(extension => `url("${fontPathPrefix}${path}.${extension}") format("${formatsMap[extension]}")`);
const fontCss = [
"@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: fallback;",
"\n}\n"
].join("");
fontList.push(fontCss);
return fontList;
}, []).join("\n");
}
});
export default {
source: [
"src/design-tokens/tokens/*.json"
],
platforms: {
"css/properties": {
transforms: ["attribute/color", "color/hsl-4", "name/kebab"],
buildPath: "src/design-tokens/compiled/",
files: [
{
destination: "properties.css",
filter: (token) => token.type !== "font",
format: "css/variables",
options: {
outputReferences(token) {
return token.attributes.outputReferences !== false;
}
}
}
]
},
"css/fonts": {
transforms: ["attribute/color", "attribute/font", "name/kebab"],
buildPath: "src/design-tokens/compiled/",
files: [
{
destination: "fonts.css",
filter: (token) => token.type === "font",
format: "font-face",
options: {
fontPathPrefix: "/src/fonts/"
}
}
]
},
"tokens": {
transforms: ["attribute/color", "attribute/cti", "color/hsl-4", "name/kebab"],
buildPath: "src/design-tokens/compiled/",
files: [
{
destination: "tokens.json",
format: "json",
}
]
},
}
};