postcss-reduce-transforms
Advanced tools
Comparing version
@@ -7,4 +7,2 @@ 'use strict'; | ||
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); | ||
var _has = require('has'); | ||
@@ -28,9 +26,5 @@ | ||
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } } | ||
function getValues(list, _ref, index) { | ||
var value = _ref.value; | ||
function getValues(list, { value }, index) { | ||
if (index % 2 === 0) { | ||
return [].concat(_toConsumableArray(list), [parseFloat(value)]); | ||
return [...list, parseFloat(value)]; | ||
} | ||
@@ -43,4 +37,3 @@ return list; | ||
if (values[15] && values[2] === 0 && values[3] === 0 && values[6] === 0 && values[7] === 0 && values[8] === 0 && values[9] === 0 && values[10] === 1 && values[11] === 0 && values[14] === 0 && values[15] === 1) { | ||
var nodes = node.nodes; | ||
const { nodes } = node; | ||
node.value = 'matrix'; | ||
@@ -61,12 +54,11 @@ node.nodes = [nodes[0], // a | ||
var rotate3dMappings = [['rotateX', [1, 0, 0]], // rotate3d(1, 0, 0, a) => rotateX(a) | ||
const rotate3dMappings = [['rotateX', [1, 0, 0]], // rotate3d(1, 0, 0, a) => rotateX(a) | ||
['rotateY', [0, 1, 0]], // rotate3d(0, 1, 0, a) => rotateY(a) | ||
['rotate', [0, 0, 1]]]; | ||
var rotate3dMatch = (0, _cssnanoUtilGetMatch2.default)(rotate3dMappings); | ||
const rotate3dMatch = (0, _cssnanoUtilGetMatch2.default)(rotate3dMappings); | ||
function rotate3d(node, values) { | ||
var nodes = node.nodes; | ||
var match = rotate3dMatch(values.slice(0, 3)); | ||
const { nodes } = node; | ||
const match = rotate3dMatch(values.slice(0, 3)); | ||
if (match.length) { | ||
@@ -84,14 +76,8 @@ node.value = match; | ||
function scale(node, values) { | ||
var nodes = node.nodes; | ||
const { nodes } = node; | ||
if (!nodes[2]) { | ||
return; | ||
} | ||
var _values = _slicedToArray(values, 2), | ||
first = _values[0], | ||
second = _values[1]; | ||
const [first, second] = values; | ||
// scale(sx, sy) => scale(sx) | ||
if (first === second) { | ||
@@ -116,11 +102,5 @@ node.nodes = [nodes[0]]; | ||
function scale3d(node, values) { | ||
var nodes = node.nodes; | ||
var _values2 = _slicedToArray(values, 3), | ||
first = _values2[0], | ||
second = _values2[1], | ||
third = _values2[2]; | ||
const { nodes } = node; | ||
const [first, second, third] = values; | ||
// scale3d(sx, 1, 1) => scaleX(sx) | ||
if (second === 1 && third === 1) { | ||
@@ -146,4 +126,3 @@ node.value = 'scaleX'; | ||
function translate(node, values) { | ||
var nodes = node.nodes; | ||
const { nodes } = node; | ||
if (!nodes[2]) { | ||
@@ -166,5 +145,4 @@ return; | ||
function translate3d(node, values) { | ||
var nodes = node.nodes; | ||
const { nodes } = node; | ||
// translate3d(0, 0, tz) => translateZ(tz) | ||
if (values[0] === 0 && values[1] === 0) { | ||
@@ -176,3 +154,3 @@ node.value = 'translateZ'; | ||
var reducers = { | ||
const reducers = { | ||
matrix3d, | ||
@@ -187,16 +165,24 @@ rotate3d, | ||
function reduce(node) { | ||
var nodes = node.nodes, | ||
type = node.type, | ||
value = node.value; | ||
function normalizeReducerName(name) { | ||
const lowerCasedName = name.toLowerCase(); | ||
if (type === 'function' && (0, _has2.default)(reducers, value)) { | ||
reducers[value](node, nodes.reduce(getValues, [])); | ||
if (lowerCasedName === 'rotatez') { | ||
return 'rotateZ'; | ||
} | ||
return lowerCasedName; | ||
} | ||
function reduce(node) { | ||
const { nodes, type, value } = node; | ||
const normalizedReducerName = normalizeReducerName(value); | ||
if (type === 'function' && (0, _has2.default)(reducers, normalizedReducerName)) { | ||
reducers[normalizedReducerName](node, nodes.reduce(getValues, [])); | ||
} | ||
return false; | ||
} | ||
exports.default = _postcss2.default.plugin('postcss-reduce-transforms', function () { | ||
return function (css) { | ||
css.walkDecls(/transform$/, function (decl) { | ||
exports.default = _postcss2.default.plugin('postcss-reduce-transforms', () => { | ||
return css => { | ||
css.walkDecls(/transform$/i, decl => { | ||
decl.value = (0, _postcssValueParser2.default)(decl.value).walk(reduce).toString(); | ||
@@ -203,0 +189,0 @@ }); |
{ | ||
"name": "postcss-reduce-transforms", | ||
"version": "4.0.0-rc.2", | ||
"version": "4.0.0", | ||
"description": "Reduce transform functions with PostCSS.", | ||
@@ -16,5 +16,5 @@ "main": "dist/index.js", | ||
"babel-cli": "^6.0.0", | ||
"cross-env": "^3.0.0" | ||
"cross-env": "^5.0.0" | ||
}, | ||
"homepage": "https://github.com/ben-eb/cssnano", | ||
"homepage": "https://github.com/cssnano/cssnano", | ||
"author": { | ||
@@ -25,5 +25,5 @@ "name": "Ben Briggs", | ||
}, | ||
"repository": "ben-eb/cssnano", | ||
"repository": "cssnano/cssnano", | ||
"dependencies": { | ||
"cssnano-util-get-match": "^4.0.0-rc.2", | ||
"cssnano-util-get-match": "^4.0.0", | ||
"has": "^1.0.0", | ||
@@ -34,7 +34,7 @@ "postcss": "^6.0.0", | ||
"bugs": { | ||
"url": "https://github.com/ben-eb/cssnano/issues" | ||
"url": "https://github.com/cssnano/cssnano/issues" | ||
}, | ||
"engines": { | ||
"node": ">=4" | ||
"node": ">=6.9.0" | ||
} | ||
} |
@@ -41,3 +41,3 @@ # [postcss][postcss]-reduce-transforms | ||
See [CONTRIBUTORS.md](https://github.com/ben-eb/cssnano/blob/master/CONTRIBUTORS.md). | ||
See [CONTRIBUTORS.md](https://github.com/cssnano/cssnano/blob/master/CONTRIBUTORS.md). | ||
@@ -44,0 +44,0 @@ ## License |
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
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
0
-100%7958
-9.71%155
-2.52%1
Infinity%