-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
192 lines (181 loc) · 4.32 KB
/
index.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
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
const plugin = require("tailwindcss/plugin")
module.exports = plugin(({ theme, addUtilities, matchUtilities }) => {
matchUtilities(
{
mask: (value) => ({
maskImage: value,
/**
* Default vars
*/
// linear-gradient props
'--tw-mask-direction': 'to bottom',
// radial-gradient props
'--tw-mask-shape': '',
'--tw-mask-reach': 'closest-side',
'--tw-mask-at': 'center',
// stops
'--tw-mask-from-opacity': '1',
'--tw-mask-point-from': '',
'--tw-mask-from': 'rgba(0,0,0,var(--tw-mask-from-opacity)) var(--tw-mask-point-from)',
'--tw-mask-to-opacity': '0',
'--tw-mask-point-to': '',
'--tw-mask-to': 'rgba(0,0,0,var(--tw-mask-to-opacity)) var(--tw-mask-point-to)',
'--tw-mask-stops': 'var(--tw-mask-from), var(--tw-mask-to)',
}),
},
{
values: {
none: 'none',
linear: 'linear-gradient(var(--tw-mask-direction), var(--tw-mask-stops))',
radial:
'radial-gradient(var(--tw-mask-shape) var(--tw-mask-reach) at var(--tw-mask-at), var(--tw-mask-stops))',
},
}
)
// - direction
// NOTE: Can accept angle as an arbitrary value, e.g. `mask-dir-[30deg]`
matchUtilities(
{
'mask-dir': (value) => ({
'--tw-mask-direction': value,
}),
},
{
values: {
'to-t': 'to top',
'to-tl': 'to top left',
'to-tr': 'to top right',
'to-r': 'to right',
'to-b': 'to bottom',
'to-bl': 'to bottom left',
'to-br': 'to bottom right',
'to-l': 'to left',
},
}
)
// - shape
addUtilities({
'.mask-shape-circle': {
'--tw-mask-shape': 'circle',
},
'.mask-shape-ellipse': {
'--tw-mask-shape': 'ellipse',
},
})
// - size
// NOTE: Can accept X Y size as an arbitrary value, e.g. `mask-reach-[25%_25%]`
matchUtilities(
{
'mask-reach': (value) => ({
'--tw-mask-reach': value,
}),
},
{
values: {
// as-they-are values
'closest-side': 'closest-side',
'closest-corner': 'closest-corner',
'farthest-side': 'farthest-side',
'farthest-corner': 'farthest-corner',
// aliases
'contain': 'closest-side',
'cover': 'farthest-corner',
},
},
)
// - position
// NOTE: Can accept X Y position as an arbitrary value, e.g. `mask-at-[50%_10px]`
matchUtilities(
{
'mask-at': (value) => ({
'--tw-mask-at': value,
}),
},
{
values: {
center: 'center',
t: 'top',
tl: 'top left',
tr: 'top right',
b: 'bottom',
bl: 'bottom left',
br: 'bottom right',
r: 'right',
l: 'left',
},
}
)
// - stops' colors
// NOTE: Can accept custom opacity as an arbitrary value, e.g. `mask-dir-[0.25]`
matchUtilities(
{
'mask-from': (value) => ({
'--tw-mask-from-opacity': value,
}),
'mask-to': (value) => ({
'--tw-mask-to-opacity': value,
}),
'mask-via': (value) => ({
'--tw-mask-point-via': '',
'--tw-mask-stops': `var(--tw-mask-from), rgba(0,0,0,${value}) var(--tw-mask-point-via), var(--tw-mask-to)`,
}),
},
{ values: theme('opacity') }
)
// - stops' points
matchUtilities({
'mask-point-from': (value) => ({
'--tw-mask-point-from': value,
}),
'mask-point-to': (value) => ({
'--tw-mask-point-to': value,
}),
'mask-point-via': (value) => ({
'--tw-mask-point-via': value,
}),
})
// Additional attributes
// repeat
addUtilities({
'.mask-repeat': {
maskRepeat: 'repeat',
},
'.mask-repeat-x': {
maskRepeat: 'repeat-x',
},
'.mask-repeat-y': {
maskRepeat: 'repeat-y',
},
'.mask-repeat-space': {
maskRepeat: 'space',
},
'.mask-repeat-round': {
maskRepeat: 'round',
},
'.mask-no-repeat': {
maskRepeat: 'no-repeat',
},
})
// size
matchUtilities(
{
'mask-size': (value) => ({
maskSize: value,
}),
},
{
values: theme('backgroundSize')
},
)
// position
matchUtilities(
{
'mask-position': (value) => ({
maskPosition: value,
}),
},
{
values: theme('backgroundPosition')
},
)
})