aboutsummaryrefslogtreecommitdiffstats
path: root/test/_gradients.scss
blob: c11439c05b169d847f372cee9c8da6045d0eccb0 (plain) (blame)
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
// sass-lint:disable no-color-literals zero-unit

@use 'true' as *;
@use '../src/easing';
@use '../src/gradients';

@include describe('gradients') {
    @include it('easing-gradient') {
        $gradient1: gradients.easing-gradient(
            linear,
            to right,
            #000,
            ease-in-quad,
            transparent
        );

        $expected1: linear-gradient(
            to right,
            #000 0,
            mix(transparent, #000, easing.ease-in-quad(0.25) * 100%) 25%,
            mix(transparent, #000, easing.ease-in-quad(0.5)  * 100%) 50%,
            mix(transparent, #000, easing.ease-in-quad(0.75) * 100%) 75%,
            transparent 100%
        );

        @include assert-equal($gradient1, $expected1, 'Simple linear gradient');

        // ---------------------------------------------------------------------------

        $gradient2: gradients.easing-gradient(
            radial,
            1em 2em at 50% 60%,
            #000,
            ease-out-cubic,
            transparent
        );

        $expected2: radial-gradient(
            1em 2em at 50% 60%,
            #000 0,
            mix(transparent, #000, easing.ease-out-cubic(0.25) * 100%) 25%,
            mix(transparent, #000, easing.ease-out-cubic(0.5)  * 100%) 50%,
            mix(transparent, #000, easing.ease-out-cubic(0.75) * 100%) 75%,
            transparent 100%
        );

        @include assert-equal($gradient2, $expected2, 'Simple radial gradient');

        // ---------------------------------------------------------------------------

        $gradient3: gradients.easing-gradient(
            linear,
            to right,
            #000        2em,
            ease-in-quad,
            transparent 10em
        );

        $expected3: linear-gradient(
            to right,
            #000 2em,
            mix(transparent, #000, easing.ease-in-quad(0.25) * 100%) 4em,
            mix(transparent, #000, easing.ease-in-quad(0.5)  * 100%) 6em,
            mix(transparent, #000, easing.ease-in-quad(0.75) * 100%) 8em,
            transparent 10em
        );

        @include assert-equal($gradient3, $expected3, 'Linear gradient with positioned color stops');

        // ---------------------------------------------------------------------------

        $gradient4: gradients.easing-gradient(
            linear,
            to right,
            #000 20%,
            ease-in-quad,
            transparent calc(20% + 10em)
        );

        $expected4: linear-gradient(
            to right,
            #000 20%,
            mix(transparent, #000, easing.ease-in-quad(0.25) * 100%) calc(20% + (20% + 10em - 20%) * 0.25),
            mix(transparent, #000, easing.ease-in-quad(0.5)  * 100%) calc(20% + (20% + 10em - 20%) * 0.5),
            mix(transparent, #000, easing.ease-in-quad(0.75) * 100%) calc(20% + (20% + 10em - 20%) * 0.75),
            transparent calc(20% + 10em)
        );

        @include assert-equal($gradient4, $expected4, 'More advanced linear gradient with positioned color stops');

        // ---------------------------------------------------------------------------

        $gradient5: gradients.easing-gradient(
            linear,
            to right,
            #000        2em,
            #f00        7em,
            ease-in-quad,
            transparent 10em
        );

        $expected5: linear-gradient(
            to right,
            #000 2em,
            #f00 7em,
            mix(transparent, #f00, easing.ease-in-quad(0.25) * 100%) 7em + 3em * 0.25,
            mix(transparent, #f00, easing.ease-in-quad(0.5)  * 100%) 7em + 3em * 0.5,
            mix(transparent, #f00, easing.ease-in-quad(0.75) * 100%) 7em + 3em * 0.75,
            transparent 10em
        );

        @include assert-equal($gradient5, $expected5, 'Linear gradient with 3 positioned color stops, 1 easing transitions');

        // ---------------------------------------------------------------------------

        $gradient6: gradients.easing-gradient(
            linear,
            to right,
            #000        2em,
            ease-in-quad,
            #f00        7em,
            ease-in-quad,
            transparent 10em
        );

        $expected6: linear-gradient(
            to right,
            #000 2em,
            mix(#f00,        #000, easing.ease-in-quad(0.25) * 100%) 2em + 5em * 0.25,
            mix(#f00,        #000, easing.ease-in-quad(0.5)  * 100%) 2em + 5em * 0.5,
            mix(#f00,        #000, easing.ease-in-quad(0.75) * 100%) 2em + 5em * 0.75,
            #f00 7em,
            mix(transparent, #f00, easing.ease-in-quad(0.25) * 100%) 7em + 3em * 0.25,
            mix(transparent, #f00, easing.ease-in-quad(0.5)  * 100%) 7em + 3em * 0.5,
            mix(transparent, #f00, easing.ease-in-quad(0.75) * 100%) 7em + 3em * 0.75,
            transparent 10em
        );

        @include assert-equal($gradient6, $expected6, 'Linear gradient with 3 positioned color stops, 2 easing transitions');

        // ---------------------------------------------------------------------------

        $gradient7: gradients.easing-gradient(
            linear,
            to right,
            #000        2em,
            ease-in-quad,
            #f00,
            ease-in-quad,
            transparent 10em
        );

        $expected7: linear-gradient(
            to right,
            #000 2em,
            mix(#f00,        #000, easing.ease-in-quad(0.25) * 100%) 2em + 4em * 0.25,
            mix(#f00,        #000, easing.ease-in-quad(0.5)  * 100%) 2em + 4em * 0.5,
            mix(#f00,        #000, easing.ease-in-quad(0.75) * 100%) 2em + 4em * 0.75,
            #f00 6em,
            mix(transparent, #f00, easing.ease-in-quad(0.25) * 100%) 6em + 4em * 0.25,
            mix(transparent, #f00, easing.ease-in-quad(0.5)  * 100%) 6em + 4em * 0.5,
            mix(transparent, #f00, easing.ease-in-quad(0.75) * 100%) 6em + 4em * 0.75,
            transparent 10em
        );

        @include assert-equal($gradient7, $expected7, 'Linear gradient with 2 / 3 positioned color stops, 2 easing transitions');

        // ---------------------------------------------------------------------------

        $gradient8: gradients.easing-gradient(
            linear,
            to right,
            #000,
            ease-in-quad,
            #f00,
            ease-in-quad,
            transparent
        );

        $expected8: linear-gradient(
            to right,
            #000 0,
            mix(#f00,        #000, easing.ease-in-quad(0.25) * 100%) 50% * 0.25,
            mix(#f00,        #000, easing.ease-in-quad(0.5)  * 100%) 50% * 0.5,
            mix(#f00,        #000, easing.ease-in-quad(0.75) * 100%) 50% * 0.75,
            #f00 50%,
            mix(transparent, #f00, easing.ease-in-quad(0.25) * 100%) 50% + 50% * 0.25,
            mix(transparent, #f00, easing.ease-in-quad(0.5)  * 100%) 50% + 50% * 0.5,
            mix(transparent, #f00, easing.ease-in-quad(0.75) * 100%) 50% + 50% * 0.75,
            transparent 100%
        );

        @include assert-equal($gradient8, $expected8, 'Linear gradient with 0 / 3 positioned color stops, 2 easing transitions');

        // ---------------------------------------------------------------------------

        $gradient9: gradients.easing-gradient(
            linear,
            to right,
            #000,
            ease-in-quad,
            #f00,
            ease-in-quad,
            transparent 20em
        );

        $expected9: linear-gradient(
            to right,
            #000 0,
            mix(#f00,        #000, easing.ease-in-quad(0.25) * 100%) 10em * 0.25,
            mix(#f00,        #000, easing.ease-in-quad(0.5)  * 100%) 10em * 0.5,
            mix(#f00,        #000, easing.ease-in-quad(0.75) * 100%) 10em * 0.75,
            #f00 10em,
            mix(transparent, #f00, easing.ease-in-quad(0.25) * 100%) 10em + 10em * 0.25,
            mix(transparent, #f00, easing.ease-in-quad(0.5)  * 100%) 10em + 10em * 0.5,
            mix(transparent, #f00, easing.ease-in-quad(0.75) * 100%) 10em + 10em * 0.75,
            transparent 20em
        );

        @include assert-equal($gradient9, $expected9, 'Linear gradient with 1 / 3 positioned color stops, 2 easing transitions');

        // ---------------------------------------------------------------------------

        $gradient10: gradients.easing-gradient(
            linear,
            to right,
            #000,
            cubic-bezier 0.47 0 0.745 0.715,
            transparent
        );

        $expected10: linear-gradient(
            to right,
            #000 0,
            mix(transparent, #000, easing.cubic-bezier(0.47, 0, 0.745, 0.715, 0.25) * 100%) 25%,
            mix(transparent, #000, easing.cubic-bezier(0.47, 0, 0.745, 0.715, 0.5)  * 100%) 50%,
            mix(transparent, #000, easing.cubic-bezier(0.47, 0, 0.745, 0.715, 0.75) * 100%) 75%,
            transparent 100%
        );

        @include assert-equal($gradient10, $expected10, 'Simple linear gradient with custom cubic-bezier easing');

        // ---------------------------------------------------------------------------

        $gradient11: gradients.easing-gradient(
            linear,
            to right,
            #000,
            steps 4 jump-start,
            transparent
        );

        $expected11: linear-gradient(
            to right,
            #000 0,
            mix(transparent, #000, 0.25 * 100%) 0,
            mix(transparent, #000, 0.25 * 100%) 25%,
            mix(transparent, #000, 0.5  * 100%) 25%,
            mix(transparent, #000, 0.5  * 100%) 50%,
            mix(transparent, #000, 0.75 * 100%) 50%,
            mix(transparent, #000, 0.75 * 100%) 75%,
            transparent 75%,
            transparent 100%
        );

        @include assert-equal($gradient11, $expected11, 'Simple linear gradient with custom steps easing');
    }
}