1 | 'use strict';
|
2 | const transform = require('./lib/transform.js');
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 | function pluginCreator(opts) {
|
17 | const options = Object.assign(
|
18 | {
|
19 | precision: 5,
|
20 | preserve: false,
|
21 | warnWhenCannotResolve: false,
|
22 | mediaQueries: false,
|
23 | selectors: false,
|
24 | },
|
25 | opts
|
26 | );
|
27 |
|
28 | return {
|
29 | postcssPlugin: 'postcss-calc',
|
30 | OnceExit(css, { result }) {
|
31 | css.walk((node) => {
|
32 | const { type } = node;
|
33 | if (type === 'decl') {
|
34 | transform(node, 'value', options, result);
|
35 | }
|
36 |
|
37 | if (type === 'atrule' && options.mediaQueries) {
|
38 | transform(node, 'params', options, result);
|
39 | }
|
40 |
|
41 | if (type === 'rule' && options.selectors) {
|
42 | transform(node, 'selector', options, result);
|
43 | }
|
44 | });
|
45 | },
|
46 | };
|
47 | }
|
48 |
|
49 | pluginCreator.postcss = true;
|
50 |
|
51 | module.exports = pluginCreator;
|