postcss-calc
Advanced tools
Comparing version
@@ -0,1 +1,14 @@ | ||
# 7.0.0 | ||
- Changed: Updated postcss-selector-parser to version 5.0.0-rc.3 | ||
- Changed: Dropped reduce-css-calc as a dependency | ||
- Fixed: Support constant() and env() ([#42](https://github.com/postcss/postcss-calc/issues/42), [#48](https://github.com/postcss/postcss-calc/issues/48)) | ||
- Fixed: Support custom properties with "calc" in its name ([#50](https://github.com/postcss/postcss-calc/issues/50)) | ||
- Fixed: Remove unnecessary whitespace around `*` and `/` ([cssnano#625](https://github.com/cssnano/cssnano/issues/625)) | ||
- Fixed: Arithmetic bugs around subtraction ([#49](https://github.com/postcss/postcss-calc/issues/49)) | ||
- Fixed: Handling of nested calc statements ([reduce-css-calc#49](https://github.com/MoOx/reduce-css-calc/issues/49)) | ||
- Fixed: Bugs regarding complex calculations ([reduce-cs-calc#45](https://github.com/MoOx/reduce-css-calc/issues/45)) | ||
- Fixed: `100%` incorrectly being transformed to `1` ([reduce-css-calc#44](https://github.com/MoOx/reduce-css-calc/issues/44)) | ||
- Added: support for case-insensitive calc statements | ||
# 6.0.2 - 2018-09-25 | ||
@@ -2,0 +15,0 @@ |
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
@@ -6,12 +6,11 @@ Object.defineProperty(exports, "__esModule", { | ||
}); | ||
exports.default = void 0; | ||
var _postcss = require('postcss'); | ||
var _postcss = require("postcss"); | ||
var _transform = require('./lib/transform'); | ||
var _transform = _interopRequireDefault(require("./lib/transform")); | ||
var _transform2 = _interopRequireDefault(_transform); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
exports.default = (0, _postcss.plugin)('postcss-calc', function (opts) { | ||
var _default = (0, _postcss.plugin)('postcss-calc', function (opts) { | ||
var options = Object.assign({ | ||
@@ -24,13 +23,13 @@ precision: 5, | ||
}, opts); | ||
return function (css, result) { | ||
css.walk(function (node) { | ||
var type = node.type; | ||
if (type === 'decl') (0, _transform2.default)(node, "value", options, result); | ||
if (type === 'atrule' && options.mediaQueries) (0, _transform2.default)(node, "params", options, result); | ||
if (type === 'rule' && options.selectors) (0, _transform2.default)(node, "selector", options, result); | ||
if (type === 'decl') (0, _transform.default)(node, "value", options, result); | ||
if (type === 'atrule' && options.mediaQueries) (0, _transform.default)(node, "params", options, result); | ||
if (type === 'rule' && options.selectors) (0, _transform.default)(node, "selector", options, result); | ||
}); | ||
}; | ||
}); | ||
module.exports = exports['default']; | ||
exports.default = _default; | ||
module.exports = exports.default; |
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
@@ -6,56 +6,60 @@ Object.defineProperty(exports, "__esModule", { | ||
}); | ||
exports.default = void 0; | ||
var _postcssSelectorParser = require('postcss-selector-parser'); | ||
var _postcssSelectorParser = _interopRequireDefault(require("postcss-selector-parser")); | ||
var _postcssSelectorParser2 = _interopRequireDefault(_postcssSelectorParser); | ||
var _postcssValueParser = _interopRequireDefault(require("postcss-value-parser")); | ||
var _reduceCssCalc = require('reduce-css-calc'); | ||
var _parser = require("../parser"); | ||
var _reduceCssCalc2 = _interopRequireDefault(_reduceCssCalc); | ||
var _reducer = _interopRequireDefault(require("./reducer")); | ||
var _stringifier = _interopRequireDefault(require("./stringifier")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var MATCH_CALC = /((?:\-[a-z]+\-)?calc)/; | ||
// eslint-disable-next-line import/no-unresolved | ||
var MATCH_CALC = /((?:-(moz|webkit)-)?calc)/i; | ||
function transformValue(value, options, result, item) { | ||
if (!value) { | ||
return value; | ||
} | ||
return (0, _postcssValueParser.default)(value).walk(function (node) { | ||
// skip anything which isn't a calc() function | ||
if (node.type !== 'function' || !MATCH_CALC.test(node.value)) return node; // stringify calc expression and produce an AST | ||
var reduced = (0, _reduceCssCalc2.default)(value, options.precision); | ||
// if the warnWhenCannotResolve option is on, inform the user that the calc | ||
// expression could not be resolved to a single value | ||
if (options.warnWhenCannotResolve && MATCH_CALC.test(reduced)) { | ||
result.warn("Could not reduce expression: " + value, { plugin: 'postcss-calc', node: item }); | ||
} | ||
var contents = _postcssValueParser.default.stringify(node.nodes); | ||
return reduced; | ||
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, _reducer.default)(ast, options.precision, item); // stringify AST and write it back | ||
node.type = 'word'; | ||
node.value = (0, _stringifier.default)(node.value, reducedAst, value, options, result, item); | ||
}, true).toString(); | ||
} | ||
function transformSelector(value, options, result, item) { | ||
return (0, _postcssSelectorParser2.default)(function (selectors) { | ||
return (0, _postcssSelectorParser.default)(function (selectors) { | ||
selectors.walk(function (node) { | ||
// attribute value | ||
// e.g. the "calc(3*3)" part of "div[data-size="calc(3*3)"]" | ||
if (node.type === 'attribute') { | ||
var val = transformValue(node.raws.unquoted, options, result, item); | ||
node.value = node.quoted ? '"' + val + '"' : val; | ||
} | ||
if (node.type === 'attribute' && node.value) { | ||
node.setValue(transformValue(node.value, options, result, item)); | ||
} // tag value | ||
// e.g. the "calc(3*3)" part of "div:nth-child(2n + calc(3*3))" | ||
// tag value | ||
// e.g. the "calc(3*3)" part of "div:nth-child(2n + calc(3*3))" | ||
if (node.type === 'tag') node.value = transformValue(node.value, options, result, item); | ||
return; | ||
}); | ||
}).process(value).result.toString(); | ||
}).processSync(value); | ||
} | ||
exports.default = function (node, property, options, result) { | ||
var value = property === "selector" ? transformSelector(node[property], options, result, node) : transformValue(node[property], options, result, node); | ||
// if the preserve option is enabled and the value has changed, write the | ||
var _default = function _default(node, property, options, result) { | ||
var value = property === "selector" ? transformSelector(node[property], options, result, node) : transformValue(node[property], options, result, node); // if the preserve option is enabled and the value has changed, write the | ||
// transformed value into a cloned node which is inserted before the current | ||
// node, preserving the original value. Otherwise, overwrite the original | ||
// value. | ||
if (options.preserve && node[property] !== value) { | ||
@@ -68,2 +72,3 @@ var clone = node.clone(); | ||
module.exports = exports['default']; | ||
exports.default = _default; | ||
module.exports = exports.default; |
{ | ||
"name": "postcss-calc", | ||
"version": "6.0.2", | ||
"version": "7.0.0", | ||
"description": "PostCSS plugin to reduce calc()", | ||
@@ -18,8 +18,8 @@ "keywords": [ | ||
"scripts": { | ||
"prepublish": "npm run build && del-cli dist/__tests__", | ||
"build": "del-cli dist && cross-env BABEL_ENV=publish babel src --out-dir dist", | ||
"prepublish": "npm run build", | ||
"build": "del-cli dist && cross-env BABEL_ENV=publish babel src --out-dir dist --ignore src/__tests__/**/*.js && jison src/parser.jison -o dist/parser.js", | ||
"pretest": "eslint src && npm run build", | ||
"test": "ava src/__tests__/" | ||
"test": "ava" | ||
}, | ||
"author": "Maxime Thirouin", | ||
"author": "Andy Jansson", | ||
"license": "MIT", | ||
@@ -32,15 +32,17 @@ "repository": "https://github.com/postcss/postcss-calc.git", | ||
"devDependencies": { | ||
"ava": "^0.19.1", | ||
"babel-cli": "^6.18.0", | ||
"babel-core": "^6.21.0", | ||
"babel-eslint": "^7.1.1", | ||
"babel-plugin-add-module-exports": "^0.2.1", | ||
"babel-preset-env": "^1.4.0", | ||
"babel-register": "^6.18.0", | ||
"cross-env": "^4.0.0", | ||
"del-cli": "^0.2.1", | ||
"eslint": "^3.12.2", | ||
"eslint-config-i-am-meticulous": "^6.0.1", | ||
"eslint-plugin-babel": "^4.0.0", | ||
"eslint-plugin-import": "^2.2.0" | ||
"@babel/cli": "^7.0.0", | ||
"@babel/core": "^7.0.0", | ||
"@babel/polyfill": "^7.0.0", | ||
"@babel/preset-env": "^7.0.0", | ||
"@babel/register": "^7.0.0", | ||
"ava": "^1.0.0-beta.8", | ||
"babel-eslint": "^10.0.1", | ||
"babel-plugin-add-module-exports": "^1.0.0", | ||
"cross-env": "^5.2.0", | ||
"del-cli": "^1.1.0", | ||
"eslint": "^5.6.1", | ||
"eslint-config-i-am-meticulous": "^11.0.0", | ||
"eslint-plugin-babel": "^5.2.1", | ||
"eslint-plugin-import": "^2.2.0", | ||
"jison-gho": "^0.6.1-215" | ||
}, | ||
@@ -50,8 +52,11 @@ "dependencies": { | ||
"postcss": "^7.0.2", | ||
"postcss-selector-parser": "^2.2.2", | ||
"reduce-css-calc": "^2.0.0" | ||
"postcss-selector-parser": "^5.0.0-rc.3", | ||
"postcss-value-parser": "^3.3.0" | ||
}, | ||
"ava": { | ||
"require": "babel-register" | ||
"require": [ | ||
"@babel/register", | ||
"@babel/polyfill" | ||
] | ||
} | ||
} |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
144767
1156.11%10
66.67%3511
4581.33%15
15.38%2
100%+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
- Removed