postcss-calc 7.0.1 → 7.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +28 -1
- package/dist/index.js +12 -3
- package/dist/lib/convertUnit.js +157 -0
- package/dist/lib/reducer.js +250 -185
- package/dist/lib/stringifier.js +17 -4
- package/dist/lib/transform.js +14 -5
- package/dist/parser.js +280 -231
- package/package.json +10 -8
- package/dist/lib/convert.js +0 -46
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,30 @@
|
|
|
1
|
+
# 7.0.5
|
|
2
|
+
|
|
3
|
+
- Fixed: reduction
|
|
4
|
+
|
|
5
|
+
# 7.0.4
|
|
6
|
+
|
|
7
|
+
- Fixed: strips away important factors from multiplications in calc() ([#107](https://github.com/postcss/postcss-calc/issues/107))
|
|
8
|
+
|
|
9
|
+
# 7.0.3
|
|
10
|
+
|
|
11
|
+
- Fixed: substracted css-variable from zero ([#111](https://github.com/postcss/postcss-calc/issues/111))
|
|
12
|
+
|
|
13
|
+
# 7.0.2
|
|
14
|
+
|
|
15
|
+
- Fixed: incorrect reduction of subtraction from zero ([#88](https://github.com/postcss/postcss-calc/issues/88))
|
|
16
|
+
- Fixed: doesn't remove calc for single function
|
|
17
|
+
- Fixed: relax parser on unknown units ([#76](https://github.com/postcss/postcss-calc/issues/76))
|
|
18
|
+
- Fixed: handle numbers with exponen composed ([#83](https://github.com/postcss/postcss-calc/pull/83))
|
|
19
|
+
- Fixed: handle plus sign before value ([#79](https://github.com/postcss/postcss-calc/pull/79))
|
|
20
|
+
- Fixed: better handle precision for nested calc ([#75](https://github.com/postcss/postcss-calc/pull/75))
|
|
21
|
+
- Fixed: properly handle nested add and sub expression inside sub expression ([#64](https://github.com/postcss/postcss-calc/issues/64))
|
|
22
|
+
- Fixed: handle uppercase units and functions ([#71](https://github.com/postcss/postcss-calc/pull/71))
|
|
23
|
+
- Fixed: do not break `calc` with single var ([cssnano/cssnano#725](https://github.com/cssnano/cssnano/issues/725))
|
|
24
|
+
- Updated: `postcss` to 7.0.27 (patch)
|
|
25
|
+
- Updated: `postcss-selector-parser` to 6.0.2
|
|
26
|
+
- Updated: `postcss-value-parser` to 4.0.2
|
|
27
|
+
|
|
1
28
|
# 7.0.1
|
|
2
29
|
|
|
3
30
|
- Updated: `postcss` to 7.0.2 (patch)
|
|
@@ -42,7 +69,7 @@
|
|
|
42
69
|
# 5.2.1 - 2016-04-10
|
|
43
70
|
|
|
44
71
|
- Fixed: support for multiline value
|
|
45
|
-
([#27](https://github.com/postcss/postcss-calc/pull/27))
|
|
72
|
+
([#27](https://github.com/postcss/postcss-calc/pull/27))
|
|
46
73
|
|
|
47
74
|
# 5.2.0 - 2016-01-08
|
|
48
75
|
|
package/dist/index.js
CHANGED
|
@@ -22,9 +22,18 @@ var _default = (0, _postcss.plugin)('postcss-calc', function (opts) {
|
|
|
22
22
|
return function (css, result) {
|
|
23
23
|
css.walk(function (node) {
|
|
24
24
|
var type = node.type;
|
|
25
|
-
|
|
26
|
-
if (type === '
|
|
27
|
-
|
|
25
|
+
|
|
26
|
+
if (type === 'decl') {
|
|
27
|
+
(0, _transform.default)(node, "value", options, result);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (type === 'atrule' && options.mediaQueries) {
|
|
31
|
+
(0, _transform.default)(node, "params", options, result);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (type === 'rule' && options.selectors) {
|
|
35
|
+
(0, _transform.default)(node, "selector", options, result);
|
|
36
|
+
}
|
|
28
37
|
});
|
|
29
38
|
};
|
|
30
39
|
});
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var conversions = {
|
|
8
|
+
// Absolute length units
|
|
9
|
+
'px': {
|
|
10
|
+
'px': 1,
|
|
11
|
+
'cm': 96 / 2.54,
|
|
12
|
+
'mm': 96 / 25.4,
|
|
13
|
+
'q': 96 / 101.6,
|
|
14
|
+
'in': 96,
|
|
15
|
+
'pt': 96 / 72,
|
|
16
|
+
'pc': 16
|
|
17
|
+
},
|
|
18
|
+
'cm': {
|
|
19
|
+
'px': 2.54 / 96,
|
|
20
|
+
'cm': 1,
|
|
21
|
+
'mm': 0.1,
|
|
22
|
+
'q': 0.025,
|
|
23
|
+
'in': 2.54,
|
|
24
|
+
'pt': 2.54 / 72,
|
|
25
|
+
'pc': 2.54 / 6
|
|
26
|
+
},
|
|
27
|
+
'mm': {
|
|
28
|
+
'px': 25.4 / 96,
|
|
29
|
+
'cm': 10,
|
|
30
|
+
'mm': 1,
|
|
31
|
+
'q': 0.25,
|
|
32
|
+
'in': 25.4,
|
|
33
|
+
'pt': 25.4 / 72,
|
|
34
|
+
'pc': 25.4 / 6
|
|
35
|
+
},
|
|
36
|
+
'q': {
|
|
37
|
+
'px': 101.6 / 96,
|
|
38
|
+
'cm': 40,
|
|
39
|
+
'mm': 4,
|
|
40
|
+
'q': 1,
|
|
41
|
+
'in': 101.6,
|
|
42
|
+
'pt': 101.6 / 72,
|
|
43
|
+
'pc': 101.6 / 6
|
|
44
|
+
},
|
|
45
|
+
'in': {
|
|
46
|
+
'px': 1 / 96,
|
|
47
|
+
'cm': 1 / 2.54,
|
|
48
|
+
'mm': 1 / 25.4,
|
|
49
|
+
'q': 1 / 101.6,
|
|
50
|
+
'in': 1,
|
|
51
|
+
'pt': 1 / 72,
|
|
52
|
+
'pc': 1 / 6
|
|
53
|
+
},
|
|
54
|
+
'pt': {
|
|
55
|
+
'px': 0.75,
|
|
56
|
+
'cm': 72 / 2.54,
|
|
57
|
+
'mm': 72 / 25.4,
|
|
58
|
+
'q': 72 / 101.6,
|
|
59
|
+
'in': 72,
|
|
60
|
+
'pt': 1,
|
|
61
|
+
'pc': 12
|
|
62
|
+
},
|
|
63
|
+
'pc': {
|
|
64
|
+
'px': 0.0625,
|
|
65
|
+
'cm': 6 / 2.54,
|
|
66
|
+
'mm': 6 / 25.4,
|
|
67
|
+
'q': 6 / 101.6,
|
|
68
|
+
'in': 6,
|
|
69
|
+
'pt': 6 / 72,
|
|
70
|
+
'pc': 1
|
|
71
|
+
},
|
|
72
|
+
// Angle units
|
|
73
|
+
'deg': {
|
|
74
|
+
'deg': 1,
|
|
75
|
+
'grad': 0.9,
|
|
76
|
+
'rad': 180 / Math.PI,
|
|
77
|
+
'turn': 360
|
|
78
|
+
},
|
|
79
|
+
'grad': {
|
|
80
|
+
'deg': 400 / 360,
|
|
81
|
+
'grad': 1,
|
|
82
|
+
'rad': 200 / Math.PI,
|
|
83
|
+
'turn': 400
|
|
84
|
+
},
|
|
85
|
+
'rad': {
|
|
86
|
+
'deg': Math.PI / 180,
|
|
87
|
+
'grad': Math.PI / 200,
|
|
88
|
+
'rad': 1,
|
|
89
|
+
'turn': Math.PI * 2
|
|
90
|
+
},
|
|
91
|
+
'turn': {
|
|
92
|
+
'deg': 1 / 360,
|
|
93
|
+
'grad': 0.0025,
|
|
94
|
+
'rad': 0.5 / Math.PI,
|
|
95
|
+
'turn': 1
|
|
96
|
+
},
|
|
97
|
+
// Duration units
|
|
98
|
+
's': {
|
|
99
|
+
's': 1,
|
|
100
|
+
'ms': 0.001
|
|
101
|
+
},
|
|
102
|
+
'ms': {
|
|
103
|
+
's': 1000,
|
|
104
|
+
'ms': 1
|
|
105
|
+
},
|
|
106
|
+
// Frequency units
|
|
107
|
+
'hz': {
|
|
108
|
+
'hz': 1,
|
|
109
|
+
'khz': 1000
|
|
110
|
+
},
|
|
111
|
+
'khz': {
|
|
112
|
+
'hz': 0.001,
|
|
113
|
+
'khz': 1
|
|
114
|
+
},
|
|
115
|
+
// Resolution units
|
|
116
|
+
'dpi': {
|
|
117
|
+
'dpi': 1,
|
|
118
|
+
'dpcm': 1 / 2.54,
|
|
119
|
+
'dppx': 1 / 96
|
|
120
|
+
},
|
|
121
|
+
'dpcm': {
|
|
122
|
+
'dpi': 2.54,
|
|
123
|
+
'dpcm': 1,
|
|
124
|
+
'dppx': 2.54 / 96
|
|
125
|
+
},
|
|
126
|
+
'dppx': {
|
|
127
|
+
'dpi': 96,
|
|
128
|
+
'dpcm': 96 / 2.54,
|
|
129
|
+
'dppx': 1
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
function convertUnit(value, sourceUnit, targetUnit, precision) {
|
|
134
|
+
var sourceUnitNormalized = sourceUnit.toLowerCase();
|
|
135
|
+
var targetUnitNormalized = targetUnit.toLowerCase();
|
|
136
|
+
|
|
137
|
+
if (!conversions[targetUnitNormalized]) {
|
|
138
|
+
throw new Error("Cannot convert to " + targetUnit);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (!conversions[targetUnitNormalized][sourceUnitNormalized]) {
|
|
142
|
+
throw new Error("Cannot convert from " + sourceUnit + " to " + targetUnit);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
var converted = conversions[targetUnitNormalized][sourceUnitNormalized] * value;
|
|
146
|
+
|
|
147
|
+
if (precision !== false) {
|
|
148
|
+
precision = Math.pow(10, parseInt(precision) || 5);
|
|
149
|
+
return Math.round(converted * precision) / precision;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
return converted;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
var _default = convertUnit;
|
|
156
|
+
exports.default = _default;
|
|
157
|
+
module.exports = exports.default;
|