-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfontVariationSettingsPlugin.js
More file actions
78 lines (72 loc) · 1.91 KB
/
fontVariationSettingsPlugin.js
File metadata and controls
78 lines (72 loc) · 1.91 KB
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
import plugin from "tailwindcss/plugin";
const fontVariationSettings = plugin(function ({ addUtilities }) {
const stretch = {
ultracondensed: 50,
extracondensed: 62.5,
condensed: 75,
semicondensed: 87.5,
base: 100,
semiexpanded: 112.5,
expanded: 125,
extraexpanded: 150,
ultraexpanded: 200,
};
const weights = {
thin: 100,
extraLight: 200,
light: 300,
normal: 400,
medium: 500,
semibold: 600,
bold: 700,
extrabold: 800,
black: 900,
};
// Custom weights with italic, stretch, italic and stretch.
Object.entries(weights).forEach((i) => {
const [key, value] = i;
const select = `.font-${key}`;
const baseData = {};
baseData[select] = {
fontWeight: value,
fontVariationSettings: `'wght' ${value}`,
};
Object.entries(stretch).forEach((i) => {
const [sKey, sValue] = i;
const sSelect = `&.font-${sKey}`;
const sSelectItalic = `&.italic.font-${sKey}`;
baseData[select][sSelectItalic] = {
fontVariationSettings: `'slnt' 1, 'wdth' ${sValue}, 'wght' ${value}`,
};
baseData[select][sSelect] = {
fontVariationSettings: `'wdth' ${sValue}, 'wght' ${value}`,
};
});
(baseData["&.italic"] = {
fontVariationSettings: `'slnt' 1, 'wght' ${value}`,
}),
addUtilities(baseData);
});
// Custom stretch alone and with italic.
Object.entries(stretch).forEach((i) => {
const [key, value] = i;
const select = `.font-${key}`;
const stretchData = {};
stretchData[select] = {
fontStretch: value,
fontVariationSettings: `'wdth' ${value}`,
"&.italic": {
fontVariationSettings: `'slnt' 1, 'wdth' ${value}`,
},
};
addUtilities(stretchData);
});
// Plain italic.
addUtilities({
".italic": {
fontStyle: "italic",
fontVariationSettings: "'slnt' 1",
},
});
});
export default fontVariationSettings;