1 |
|
2 | import { list } from 'postcss';
|
3 | import getReplacedString from './get-replaced-string';
|
4 | import transformNode from './transform-node';
|
5 | import setVariable from './set-variable';
|
6 |
|
7 |
|
8 | export default function transformForAtrule(atrule, result, opts) {
|
9 |
|
10 | const params = list.space(atrule.params);
|
11 |
|
12 |
|
13 | const name = params[0].trim().slice(1);
|
14 | const start = Number(getReplacedString(params[2], atrule, result, opts));
|
15 | const end = Number(getReplacedString(params[4], atrule, result, opts));
|
16 | const increment = 6 in params && Number(getReplacedString(params[6], atrule, result, opts)) || 1;
|
17 | const direction = start <= end ? 1 : -1;
|
18 |
|
19 |
|
20 | for (let incrementor = start; incrementor * direction <= end * direction; incrementor += increment * direction) {
|
21 |
|
22 | setVariable(atrule, name, String(incrementor), opts);
|
23 |
|
24 |
|
25 | const clone = atrule.clone({
|
26 | parent: atrule.parent,
|
27 | variables: atrule.variables
|
28 | });
|
29 |
|
30 |
|
31 | transformNode(clone, result, opts);
|
32 |
|
33 |
|
34 | atrule.parent.insertBefore(atrule, clone.nodes);
|
35 | }
|
36 |
|
37 |
|
38 | atrule.remove();
|
39 | }
|