/
index.js
330 lines (280 loc) · 10.2 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
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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
import test from 'ava';
import plugin from '..';
import {usePostCSSPlugin, processCSSFactory} from '../../../../util/testHelpers';
const {processCSS, passthroughCSS} = processCSSFactory(plugin);
test(
'linear: should convert "to top" to 0deg',
processCSS,
'background:linear-gradient(to top,#ffe500,#121)',
'background:linear-gradient(0deg,#ffe500,#121)'
);
test(
'linear: should convert "to top" to 0deg (uppercase property and value)',
processCSS,
'BACKGROUND:LINEAR-GRADIENT(TO TOP,#ffe500,#121)',
'BACKGROUND:LINEAR-GRADIENT(0deg,#ffe500,#121)'
);
test(
'linear: should convert "to right" to 90deg',
processCSS,
'background:linear-gradient(to right,#ffe500,#121)',
'background:linear-gradient(90deg,#ffe500,#121)'
);
test(
'linear: should convert "to right" to 90deg (uppercase property and value)',
processCSS,
'BACKGROUND:LINEAR-GRADIENT(TO RIGHT,#FFE500,#121)',
'BACKGROUND:LINEAR-GRADIENT(90deg,#FFE500,#121)'
);
test(
'linear: should convert "to bottom" to 180deg',
processCSS,
'background:linear-gradient(to bottom,#ffe500,#121)',
'background:linear-gradient(180deg,#ffe500,#121)'
);
test(
'linear: should convert "to left" to 270deg',
processCSS,
'background:linear-gradient(to left,#ffe500,#121)',
'background:linear-gradient(270deg,#ffe500,#121)'
);
test(
'linear: should convert "to top" to 0deg (with a solid colour)',
processCSS,
'background:#ffe500 linear-gradient(to top,#ffe500,#121)',
'background:#ffe500 linear-gradient(0deg,#ffe500,#121)'
);
test(
'repeating-linear: should convert "to top" to 0deg',
processCSS,
'background:repeating-linear-gradient(to top,#ffe500,#121)',
'background:repeating-linear-gradient(0deg,#ffe500,#121)'
);
test(
'repeating-linear: should convert "to top" to 0deg (uppercase)',
processCSS,
'background:REPEATING-LINEAR-GRADIENT(TO TOP,#ffe500,#121)',
'background:REPEATING-LINEAR-GRADIENT(0deg,#ffe500,#121)'
);
test(
'repeating-linear: should convert "to right" to 90deg',
processCSS,
'background:repeating-linear-gradient(to right,#ffe500,#121)',
'background:repeating-linear-gradient(90deg,#ffe500,#121)'
);
test(
'repeating-linear: should convert "to bottom" to 180deg',
processCSS,
'background:repeating-linear-gradient(to bottom,#ffe500,#121)',
'background:repeating-linear-gradient(180deg,#ffe500,#121)'
);
test(
'repeating-linear: should convert "to left" to 270deg',
processCSS,
'background:repeating-linear-gradient(to left,#ffe500,#121)',
'background:repeating-linear-gradient(270deg,#ffe500,#121)'
);
test(
'linear: should not convert "to top right" to an angle',
passthroughCSS,
'background:linear-gradient(to top right,#ffe500,#121)'
);
test(
'linear: should not convert "to bottom left" to an angle',
passthroughCSS,
'background:linear-gradient(to bottom left,#ffe500,#121)'
);
test(
'linear: should reduce length values if they are the same',
processCSS,
'background:linear-gradient(45deg,#ffe500 50%,#121 50%)',
'background:linear-gradient(45deg,#ffe500 50%,#121 0)'
);
test(
'linear: should reduce length values if they are the same (uppercase)',
processCSS,
'background:LINEAR-GRADIENT(45DEG,#FFE500 50%,#121 50%)',
'background:LINEAR-GRADIENT(45DEG,#FFE500 50%,#121 0)'
);
test(
'linear: should reduce length values if they are less',
processCSS,
'background:linear-gradient(45deg,#ffe500 50%,#121 25%)',
'background:linear-gradient(45deg,#ffe500 50%,#121 0)'
);
test(
'linear: should not reduce length values with different units',
passthroughCSS,
'background:linear-gradient(45deg,#ffe500 25px,#121 20%)'
);
test(
'linear: should remove the (unnecessary) start/end length values',
processCSS,
'background:linear-gradient(#ffe500 0%,#121 100%)',
'background:linear-gradient(#ffe500,#121)'
);
test(
'repeating-radial: should reduce length values if they are the same',
processCSS,
'background:repeating-radial-gradient(#121,#121 5px,#ffe500 5px,#ffe500 10px)',
'background:repeating-radial-gradient(#121,#121 5px,#ffe500 0,#ffe500 10px)'
);
test(
'repeating-radial: should reduce length values if they are the same (uppercase property and value)',
processCSS,
'BACKGROUND:REPEATING-RADIAL-GRADIENT(#121,#121 5PX,#FFE500 5PX,#FFE500 10PX)',
'BACKGROUND:REPEATING-RADIAL-GRADIENT(#121,#121 5PX,#FFE500 0,#FFE500 10PX)'
);
test(
'repeating-radial: should reduce length values if they are the same (last is zero)',
processCSS,
'BACKGROUND:REPEATING-RADIAL-GRADIENT(#121,#121 5PX,#FFE500 5PX,#FFE500 0)',
'BACKGROUND:REPEATING-RADIAL-GRADIENT(#121,#121 5PX,#FFE500 0,#FFE500 0)'
);
test(
'radial: should correctly account for "at"',
passthroughCSS,
'background:radial-gradient(at 50% 0%,rgba(74,74,74,.15),transparent 40%);'
);
test(
'radial: should correctly account for uppercase "at"',
passthroughCSS,
'background:radial-gradient(AT 50% 0%,rgba(74,74,74,.15),transparent 40%);'
);
test(
'radial: should correctly account for "at" (2)',
processCSS,
'background:radial-gradient(at 50% 0%,rgba(74,74,74,.15),transparent 40%, red 40%);',
'background:radial-gradient(at 50% 0%,rgba(74,74,74,.15),transparent 40%, red 0);'
);
test(
'radial: should correctly account for "at" (2) (uppercase)',
processCSS,
'background:radial-gradient(AT 50% 0%,RGBA(74,74,74,.15),TRANSPARENT 40%, RED 40%);',
'background:radial-gradient(AT 50% 0%,RGBA(74,74,74,.15),TRANSPARENT 40%, RED 0);'
);
test(
'radial: should correctly account with prefix "-webkit" (1)',
processCSS,
'background: -webkit-radial-gradient(50% 26%, circle, #fff, rgba(255, 255, 255, 0) 24%)',
'background: -webkit-radial-gradient(50% 26%, circle, #fff, rgba(255, 255, 255, 0) 24%)'
);
test(
'radial: should correctly account with prefix "-webkit" (1) (uppercase)',
processCSS,
'background: -WEBKIT-RADIAL-GRADIENT(50% 26%, circle, #fff, rgba(255, 255, 255, 0) 24%)',
'background: -WEBKIT-RADIAL-GRADIENT(50% 26%, circle, #fff, rgba(255, 255, 255, 0) 24%)'
);
test(
'radial: should correctly account with prefix "-webkit" (1) with px',
processCSS,
'background: -webkit-radial-gradient(50% 26px, circle, #fff, rgba(255, 255, 255, 0) 24%)',
'background: -webkit-radial-gradient(50% 26px, circle, #fff, rgba(255, 255, 255, 0) 24%)'
);
test(
'radial: should correctly account with prefix "-webkit" (1) with px (uppercase)',
processCSS,
'background: -webkit-radial-gradient(50% 26PX, circle, #fff, rgba(255, 255, 255, 0) 24%)',
'background: -webkit-radial-gradient(50% 26PX, circle, #fff, rgba(255, 255, 255, 0) 24%)'
);
test(
'radial: should correctly account with prefix "-webkit" (2)',
processCSS,
'background: -webkit-radial-gradient(center, 30% 30%, white 20%, black 10%)',
'background: -webkit-radial-gradient(center, 30% 30%, white 20%, black 0)'
);
test(
'radial: should correctly account with prefix "-webkit" (2) (uppercase)',
processCSS,
'background: -WEBKIT-RADIAL-GRADIENT(CENTER, 30% 30%, WHITE 20%, BLACK 10%)',
'background: -WEBKIT-RADIAL-GRADIENT(CENTER, 30% 30%, WHITE 20%, BLACK 0)'
);
test(
'radial: should correctly account with prefix "-webkit" (3)',
processCSS,
'background: -webkit-radial-gradient(50% 26%, #fff, rgba(255, 255, 255, 0) 24%)',
'background: -webkit-radial-gradient(50% 26%, #fff, rgba(255, 255, 255, 0) 24%)'
);
test(
'radial: should correctly account with prefix "-webkit" (4)',
processCSS,
'background: -webkit-radial-gradient(white 50%, black 40%)',
'background: -webkit-radial-gradient(white 50%, black 0)'
);
test(
'radial: should correctly account with prefix "-webkit" (4) (uppercase)',
processCSS,
'background: -WEBKIT-RADIAL-GRADIENT(WHITE 50%, BLACK 40%)',
'background: -WEBKIT-RADIAL-GRADIENT(WHITE 50%, BLACK 0)'
);
test(
'radial: should correctly account with prefix "-webkit" (4) with px (uppercase)',
processCSS,
'background: -WEBKIT-RADIAL-GRADIENT(WHITE 50px, BLACK 400PX)',
'background: -WEBKIT-RADIAL-GRADIENT(WHITE 50px, BLACK 400PX)'
);
test(
'radial: should correctly account with prefix "-webkit" (5)',
processCSS,
'background: -webkit-radial-gradient(white calc(30%), black calc(50%))',
'background: -webkit-radial-gradient(white calc(30%), black calc(50%))'
);
test(
'radial: should correctly account with prefix "-webkit" (5) (calc uppercase)',
processCSS,
'background: -webkit-radial-gradient(white CALC(30%), black calc(50%))',
'background: -webkit-radial-gradient(white CALC(30%), black calc(50%))'
);
test(
'should not mangle floating point numbers',
processCSS,
'background:linear-gradient(#fff,#fff 2em,#ccc 2em,#ccc 2.1em,#fff 2.1em)',
'background:linear-gradient(#fff,#fff 2em,#ccc 0,#ccc 2.1em,#fff 0)'
);
test(
'should not mangle floating point numbers (uppercase)',
processCSS,
'background:LINEAR-GRADIENT(#FFF,#FFF 2EM,#CCC 2EM,#CCC 2.1EM,#FFF 2.1EM)',
'background:LINEAR-GRADIENT(#FFF,#FFF 2EM,#CCC 0,#CCC 2.1EM,#FFF 0)'
);
test(
'should not mangle floating point numbers 1 (uppercase)',
processCSS,
'background:lInEaR-gRaDiEnT(#fFf,#fFf 2Em,#cCc 2eM,#cCc 2.1eM,#fFf 2.1EM)',
'background:lInEaR-gRaDiEnT(#fFf,#fFf 2Em,#cCc 0,#cCc 2.1eM,#fFf 0)'
);
test(
'should not remove the trailing zero if it is the last stop',
passthroughCSS,
'background: linear-gradient(90deg,transparent,#00aeef 0)'
);
test(
'should not remove point number if it its different type from a previous one',
passthroughCSS,
'background: linear-gradient(to left bottom,transparent calc(50% - 2px),#a7a7a8 0,#a7a7a8 calc(50% + 2px),transparent 0)'
);
test(
'should not throw on empty linear gradients',
passthroughCSS,
'background: linear-gradient()'
);
test(
'should not throw on empty radial gradients',
passthroughCSS,
'background: radial-gradient()',
);
test(
'should pass through custom property references',
passthroughCSS,
'background-image:var(--bg),linear-gradient(red,blue)'
);
test(
'should not operate on declarations without gradients',
passthroughCSS,
'background:red'
);
test(
'should use the postcss plugin api',
usePostCSSPlugin,
plugin()
);