-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
78 lines (62 loc) · 2.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
var postcss = require('postcss');
var units = require('units-css');
var parseCssFont = require('parse-css-font');
var assign = require('object-assign');
module.exports = postcss.plugin('postcss-increase-text-size', function (opts) {
opts = assign({
fontSizeMultiplyBy: 1.2,
lineheightMultiplyBy: 1.2,
selectorsBlackList: []
}, opts);
function propInArray(array, prop) {
return array.indexOf(prop) > -1;
}
return function (css, result) {
css.walkDecls(function (decl) {
if (propInArray(opts.selectorsBlackList, decl.parent.selector)) {
return;
}
if (decl.prop === 'font') {
var fontValue = parseCssFont(decl.value);
var fontSize = units.parse(fontValue.size);
var lineHeight = fontValue.lineHeight;
var fontValueCon;
if (fontSize.unit == 'em' || fontSize.unit == 'rem') {
fontSize = fontSize.value * opts.fontSizeMultiplyBy + fontSize.unit;
} else {
fontSize = Math.round(fontSize.value * opts.fontSizeMultiplyBy) + fontSize.unit;
}
if (lineHeight != 'normal') {
var newlineHeight = units.parse(lineHeight);
if (newlineHeight.unit == 'em' || newlineHeight.unit == 'rem') {
newlineHeight = newlineHeight.value * opts.lineheightMultiplyBy + newlineHeight.unit;
} else {
newlineHeight = Math.round(newlineHeight.value * opts.lineheightMultiplyBy) + newlineHeight.unit;
}
fontValueCon = fontSize + '/' + newlineHeight;
} else {
fontValueCon = fontSize;
}
decl.value = decl.value.replace(/(\d\S*)(\d+)?/g, fontValueCon);
}
if (decl.prop === 'font-size') {
var propUnit = units.parse(decl.value);
if (propUnit.unit == 'em' || propUnit.unit == 'rem') {
propUnit.value *= opts.fontSizeMultiplyBy;
} else {
propUnit.value = Math.round(propUnit.value * opts.fontSizeMultiplyBy);
}
decl.value = propUnit.value + propUnit.unit;
}
if (decl.prop === 'line-height') {
var propUnit = units.parse(decl.value);
if (propUnit.unit == 'em' || propUnit.unit == 'rem') {
propUnit.value *= opts.lineheightMultiplyBy;
} else {
propUnit.value = Math.round(propUnit.value * opts.lineheightMultiplyBy);
}
decl.value = propUnit.value + propUnit.unit;
}
});
};
});