forked from GitbookIO/gitbook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtailwind.config.ts
242 lines (223 loc) · 8.87 KB
/
tailwind.config.ts
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
import containerQueries from '@tailwindcss/container-queries';
import typography from '@tailwindcss/typography';
import type { Config } from 'tailwindcss';
import plugin from 'tailwindcss/plugin';
import { hexToRgb, shadesOfColor } from './src/lib/colors';
export const shades = [50, 100, 200, 300, 400, 500, 600, 700, 800, 900];
export const opacities = [0, 4, 8, 12, 16, 24, 40, 64, 72, 88, 96];
/**
* Generate a Tailwind color shades from a variable.
*/
function generateVarShades(varName: string) {
return shades.reduce(
(acc, shade) => {
acc[shade] = `rgb(var(--${varName}-${shade}) / <alpha-value>)`;
return acc;
},
{ DEFAULT: `rgb(var(--${varName}-500) / <alpha-value>)` } as Record<string, string>,
);
}
/**
* Generate a Tailwind color shades from a HEX color.
*/
function generateShades(color: string) {
const rawShades = shadesOfColor(color);
const shadeMap = shades.reduce(
(acc, shade) => {
acc[shade] = `rgb(${hexToRgb(rawShades[`${shade}`])} / <alpha-value>)`;
return acc;
},
{} as Record<string, string>,
);
shadeMap.DEFAULT = shadeMap[500];
return shadeMap;
}
function opacity() {
return opacities.reduce(
(acc, opacity, index) => {
acc[index] = `${opacity / 100}`;
return acc;
},
{} as Record<string, string>,
);
}
const config: Config = {
darkMode: 'class',
content: [
'./src/pages/**/*.{js,ts,jsx,tsx,mdx}',
'./src/components/**/*.{js,ts,jsx,tsx,mdx}',
'./src/app/**/*.{js,ts,jsx,tsx,mdx}',
],
theme: {
extend: {
fontFamily: {
sans: ['var(--font-content)'],
mono: ['var(--font-mono)'],
},
colors: {
// Dynamic colors matching the customization settings
/** primary-color used to accent elements, these colors remain unchanged when toggling between the CustomizationBackground options**/
primary: generateVarShades('primary-color'),
/** primary-base is an internal color that generates the same colors as primary-color. But it's shades will change into a grayscale if CustomizationBackground.Plain is selected. (globals.css) **/
primarybase: generateVarShades('primary-base'),
'header-background': generateVarShades('header-background'),
'header-link': generateVarShades('header-link'),
light: {
1: `color-mix(in srgb, var(--light-1), transparent calc(100% - 100% * <alpha-value>))`, //1 99%
DEFAULT: `color-mix(in srgb, var(--light-DEFAULT), transparent calc(100% - 100% * <alpha-value>))`, //(default) 96%
2: `color-mix(in srgb, var(--light-2), transparent calc(100% - 100% * <alpha-value>))`, //2 92%
3: `color-mix(in srgb, var(--light-3), transparent calc(100% - 100% * <alpha-value>))`, //4 82%
4: `color-mix(in srgb, var(--light-4), transparent calc(100% - 100% * <alpha-value>))`, //5 64%
},
dark: {
1: `color-mix(in srgb, var(--dark-1), transparent calc(100% - 100% * <alpha-value>))`, //1 99%
DEFAULT: `color-mix(in srgb, var(--dark-DEFAULT), transparent calc(100% - 100% * <alpha-value>))`, //(default) 96%
2: `color-mix(in srgb, var(--dark-2), transparent calc(100% - 100% * <alpha-value>))`, //2 92%
3: `color-mix(in srgb, var(--dark-3), transparent calc(100% - 100% * <alpha-value>))`, //4 82%
4: `color-mix(in srgb, var(--dark-4), transparent calc(100% - 100% * <alpha-value>))`, //5 64%
},
yellow: generateShades('#f4e28d'),
teal: generateShades('#3f89a1'),
pomegranate: generateShades('#f25b3a'),
periwinkle: generateShades('#acc6ee'),
},
keyframes: {
pulseAlt: {
'0%': {
transform: 'scale(0.01)',
opacity: '0',
},
'70%': {
opacity: '1',
},
'100%': {
transform: 'scale(2.8)',
opacity: '0',
},
},
fadeIn: {
'0%': {
opacity: '0',
},
'100%': {
opacity: '1',
},
},
rotateLoop: {
'0%': {
transform: 'rotate(0deg) scaleY(2.5) scaleX(2.5)',
},
'100%': {
transform: 'rotate(360deg) scaleY(2.5) scaleX(2.5)',
},
},
pingAlt: {
'0%': {
transform: 'scale(0.1)',
opacity: '0',
},
'20%': {
opacity: '1',
},
'30%, 100%': {
transform: 'scale(5)',
opacity: '0',
},
},
wag: {
'0%, 40%': {
transform: 'rotate(0deg)',
},
'45%': {
transform: 'rotate(-10deg)',
},
'55%': {
transform: 'rotate(10deg)',
},
'60%, 100%': {
transform: 'rotate(0deg)',
},
},
pathLoading: {
'0%': {
strokeDasharray: '0 100',
strokeDashoffset: '0',
opacity: '0',
},
'40%, 60%': {
strokeDasharray: '100 100',
strokeDashoffset: '0',
opacity: '1',
},
'100%': {
strokeDasharray: '100 100',
strokeDashoffset: '-100',
opacity: '0',
},
},
stroke: {
'0%': {
strokeDasharray: '0 100',
strokeDashoffset: '0',
opacity: '0',
},
'20%, 80%': {
strokeDasharray: '100 100',
strokeDashoffset: '0',
opacity: '1',
},
'100%': {
strokeDasharray: '100 100',
strokeDashoffset: '-100',
opacity: '0',
},
},
},
boxShadow: {
thinbottom: '0px 1px 0px rgba(0, 0, 0, 0.05)',
'1xs': '0px 1px 1px rgba(0, 0, 0, 0.09), 0px 3.267px 2.754px rgb(0, 0, 0, 0.05), 0px 6.278px 6.63px rgb(0, 0, 0, 0.05), 0px 14px 22px rgb(0, 0, 0, 0.04)',
},
},
opacity: opacity(),
},
plugins: [
plugin(function ({ addVariant }) {
/**
* Variant when the Table of Content navigation is open.
*/
addVariant('navigation-open', 'body.navigation-open &');
/**
* Variant when a header is displayed.
*/
addVariant('space-header', 'body:has(header) &');
/**
* Variant when the space is configured with straight corners.
*/
addVariant('straight-corners', 'html.straight-corners &');
/**
* Variant when the space is configured with a theme matching background.
*/
addVariant('plain-background', 'html.plain-background &');
/**
* Variant when the page contains a block that will be rendered in full-width mode.
*/
addVariant('page-full-width', 'body:has(.page-full-width) &');
/**
* Variant when the page is configured to hide the table of content.
* `page.layout.tableOfContents` is set to false.
*/
addVariant('page-no-toc', 'body:has(.page-no-toc) &');
/**
* Variant when the page contains an OpenAPI block.
*/
addVariant('page-api-block', 'body:has(.openapi-block) &');
/**
* Variant when the page is displayed in print mode.
*/
addVariant('print-mode', 'body:has(.print-mode) &');
}),
containerQueries,
typography,
],
};
export default config;