reduce-css-calc
Advanced tools
Comparing version
@@ -0,1 +1,5 @@ | ||
# 2.1.3 - 2017-11-27 | ||
- Fixed: Incorrect reduction for a specific case (e.g. `calc(1em + (1em - 5px))`) ([#43](https://github.com/MoOx/reduce-css-calc/pull/43) - @Justineo) | ||
# 2.1.2 - 2017-11-26 | ||
@@ -2,0 +6,0 @@ |
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
value: true | ||
}); | ||
@@ -27,22 +27,22 @@ | ||
exports.default = function (value) { | ||
var precision = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 5; | ||
var precision = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 5; | ||
return (0, _postcssValueParser2.default)(value).walk(function (node) { | ||
// skip anything which isn't a calc() function | ||
if (node.type !== 'function' || !MATCH_CALC.test(node.value)) return; | ||
return (0, _postcssValueParser2.default)(value).walk(function (node) { | ||
// skip anything which isn't a calc() function | ||
if (node.type !== 'function' || !MATCH_CALC.test(node.value)) return; | ||
// stringify calc expression and produce an AST | ||
var contents = _postcssValueParser2.default.stringify(node.nodes); | ||
var ast = _parser.parser.parse(contents); | ||
// stringify calc expression and produce an AST | ||
var contents = _postcssValueParser2.default.stringify(node.nodes); | ||
var ast = _parser.parser.parse(contents); | ||
// reduce AST to its simplest form, that is, either to a single value | ||
// or a simplified calc expression | ||
var reducedAst = (0, _reducer2.default)(ast, precision); | ||
// reduce AST to its simplest form, that is, either to a single value | ||
// or a simplified calc expression | ||
var reducedAst = (0, _reducer2.default)(ast, precision); | ||
// stringify AST and write it back | ||
node.type = 'word'; | ||
node.value = (0, _stringifier2.default)(node.value, reducedAst, precision); | ||
}, true).toString(); | ||
// stringify AST and write it back | ||
node.type = 'word'; | ||
node.value = (0, _stringifier2.default)(node.value, reducedAst, precision); | ||
}, true).toString(); | ||
}; | ||
module.exports = exports['default']; |
@@ -119,7 +119,3 @@ 'use strict'; | ||
node.right = right.right; | ||
if (node.operator === '-') { | ||
node.operator = right.operator === '+' ? '-' : '+'; | ||
} | ||
node.operator = op === '-' ? flip(right.operator) : right.operator; | ||
return reduce(node, precision); | ||
@@ -126,0 +122,0 @@ } |
{ | ||
"name": "reduce-css-calc", | ||
"version": "2.1.2", | ||
"version": "2.1.3", | ||
"description": "Reduce CSS calc() function to the maximum", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -0,0 +0,0 @@ # reduce-css-calc [](https://travis-ci.org/MoOx/reduce-css-calc) |
Sorry, the diff of this file is not supported yet
48612
01040
-0.19%