main
js 65 lines 2.6 KB
Raw
1 import { readFileSync } from "node:fs"
2 import _ from "lodash"
3 import plugin from "tailwindcss/plugin.js"
4
5 const fileUrl = new URL("./src/design-tokens.json", import.meta.url)
6 const tokens = JSON.parse(readFileSync(fileUrl))
7
8 function getValue(origin, val) {
9 if (val && val.indexOf("{") === 0) {
10 const path = val.replace("{", "").replace("}", "")
11 return _.get(origin, path)
12 }
13
14 return val
15 }
16
17 export default {
18 plugins: [
19 plugin(({ addBase, theme }) => {
20 addBase({
21 h1: {
22 fontFamily: getValue(tokens, tokens?.typography?.h1?.fontFamily),
23 fontWeight: getValue(tokens, tokens?.typography?.h1?.fontWeight) || theme("fontWeight.bold"),
24 fontSize: getValue(tokens, tokens?.typography?.h1?.fontSize),
25 letterSpacing:
26 getValue(tokens, tokens?.typography?.h1?.letterSpacing) || theme("letterSpacing.tight")
27 },
28 h2: {
29 fontFamily: getValue(tokens, tokens?.typography?.h2?.fontFamily),
30 fontWeight: getValue(tokens, tokens?.typography?.h2?.fontWeight) || theme("fontWeight.bold"),
31 fontSize: getValue(tokens, tokens?.typography?.h2?.fontSize),
32 letterSpacing:
33 getValue(tokens, tokens?.typography?.h2?.letterSpacing) || theme("letterSpacing.tight")
34 },
35 h3: {
36 fontFamily: getValue(tokens, tokens?.typography?.h3?.fontFamily),
37 fontWeight: getValue(tokens, tokens?.typography?.h3?.fontWeight) || theme("fontWeight.bold"),
38 fontSize: getValue(tokens, tokens?.typography?.h3?.fontSize),
39 letterSpacing:
40 getValue(tokens, tokens?.typography?.h3?.letterSpacing) || theme("letterSpacing.tight")
41 },
42 h4: {
43 fontFamily: getValue(tokens, tokens?.typography?.h4?.fontFamily),
44 fontWeight: getValue(tokens, tokens?.typography?.h4?.fontWeight) || theme("fontWeight.medium"),
45 fontSize: getValue(tokens, tokens?.typography?.h4?.fontSize),
46 letterSpacing:
47 getValue(tokens, tokens?.typography?.h4?.letterSpacing) || theme("letterSpacing.tight")
48 },
49 h5: {
50 fontFamily: getValue(tokens, tokens?.typography?.h5?.fontFamily),
51 fontWeight: getValue(tokens, tokens?.typography?.h5?.fontWeight) || theme("fontWeight.bold"),
52 fontSize: getValue(tokens, tokens?.typography?.h5?.fontSize),
53 letterSpacing:
54 getValue(tokens, tokens?.typography?.h5?.letterSpacing) || theme("letterSpacing.tight")
55 },
56 h6: {
57 fontFamily: getValue(tokens, tokens?.typography?.h6?.fontFamily),
58 fontWeight: getValue(tokens, tokens?.typography?.h6?.fontWeight) || theme("fontWeight.bold"),
59 fontSize: getValue(tokens, tokens?.typography?.h6?.fontSize),
60 letterSpacing: getValue(tokens, tokens?.typography?.h6?.letterSpacing)
61 }
62 })
63 })
64 ]
65 }