-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerators.js
70 lines (58 loc) · 1.53 KB
/
generators.js
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
const omit = require('lodash/omit')
const twColors = require('tailwindcss/colors')
const toRGBString = hexCode => {
if (hexCode.startsWith('#')) {
let hex = hexCode.replace('#', '')
if (hex.length === 3) {
hex = `${hex[0]}${hex[0]}${hex[1]}${hex[1]}${hex[2]}${hex[2]}`
}
const r = parseInt(hex.substring(0, 2), 16)
const g = parseInt(hex.substring(2, 4), 16)
const b = parseInt(hex.substring(4, 6), 16)
return `${r}, ${g}, ${b}`
}
return hexCode
}
const colors = { primary: twColors.sky, ...twColors, gray: twColors.slate }
const except = omit(colors, [
'lightBlue',
'warmGray',
'trueGray',
'coolGray',
'blueGray',
])
function generateRootCSSVars() {
return Object.fromEntries(
Object.entries(except)
.map(([key, value]) => {
if (typeof value === 'string') {
return [[`--colors-${key}`, toRGBString(value)]]
}
return Object.entries(value).map(([shade, color]) => {
return [`--colors-${key}-${shade}`, toRGBString(color)]
})
})
.flat(1)
)
}
function generateTailwindColors() {
return Object.fromEntries(
Object.entries(except).map(([key, value]) => {
if (typeof value === 'string') {
return [`${key}`, value]
}
return [
key,
Object.fromEntries(
Object.entries(value).map(([shade]) => {
return [`${shade}`, `rgba(var(--colors-${key}-${shade}))`]
})
),
]
})
)
}
module.exports = {
generateRootCSSVars,
generateTailwindColors,
}