-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
51 lines (41 loc) · 1.45 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
var postcss = require('postcss');
module.exports = postcss.plugin('postcss-verthorz', function () {
var VALUES = {
pv: ['padding-top', 'padding-bottom'],
ph: ['padding-left', 'padding-right'],
mv: ['margin-top', 'margin-bottom'],
mh: ['margin-left', 'margin-right']
};
var PROPS = {
'padding-vertical': VALUES.pv,
'padding-horizontal': VALUES.ph,
'padding-vert': VALUES.pv,
'padding-horz': VALUES.ph,
'pv': VALUES.pv,
'ph': VALUES.ph,
'margin-vertical': VALUES.mv,
'margin-horizontal': VALUES.mh,
'margin-vert': VALUES.mv,
'margin-horz': VALUES.mh,
'mv': VALUES.mv,
'mh': VALUES.mh
};
return function (root) {
root.walkRules(function (rule) {
rule.walkDecls(function(decl) {
var declArray = decl.value.split(' ');
var prop = decl.prop;
if (!PROPS.hasOwnProperty(prop)) return;
var properties = PROPS[prop];
properties.forEach(function(property, index) {
if (declArray.length > 1) {
decl.cloneBefore({ prop: properties[index], value: declArray[index] });
} else {
decl.cloneBefore({ prop: properties[index], value: decl.value });
}
});
decl.remove();
});
});
};
});