postcss-normalize-positions
Advanced tools
Comparing version 4.0.1 to 4.0.2
@@ -37,6 +37,7 @@ 'use strict'; | ||
function transform(decl) { | ||
const values = (0, _postcssValueParser2.default)(decl.value); | ||
const args = (0, _cssnanoUtilGetArguments2.default)(values); | ||
function transform(value) { | ||
const parsed = (0, _postcssValueParser2.default)(value); | ||
const args = (0, _cssnanoUtilGetArguments2.default)(parsed); | ||
const relevant = []; | ||
args.forEach(arg => { | ||
@@ -47,10 +48,14 @@ relevant.push({ | ||
}); | ||
arg.forEach((part, index) => { | ||
const isPosition = ~directions.indexOf(part.value.toLowerCase()) || (0, _postcssValueParser.unit)(part.value); | ||
const len = relevant.length - 1; | ||
if (relevant[len].start === null && isPosition) { | ||
relevant[len].start = index; | ||
relevant[len].end = index; | ||
return; | ||
} | ||
if (relevant[len].start !== null) { | ||
@@ -61,4 +66,6 @@ if (part.type === 'space') { | ||
relevant[len].end = index; | ||
return; | ||
} | ||
return; | ||
@@ -68,2 +75,3 @@ } | ||
}); | ||
relevant.forEach((range, index) => { | ||
@@ -73,8 +81,12 @@ if (range.start === null) { | ||
} | ||
const position = args[index].slice(range.start, range.end + 1); | ||
if (position.length > 3) { | ||
return; | ||
} | ||
const firstValue = position[0].value.toLowerCase(); | ||
const secondValue = position[2] && position[2].value ? position[2].value.toLowerCase() : null; | ||
if (position.length === 1 || secondValue === 'center') { | ||
@@ -84,20 +96,28 @@ if (secondValue) { | ||
} | ||
const map = Object.assign({}, horizontal, { | ||
center | ||
}); | ||
if ((0, _has2.default)(map, firstValue)) { | ||
position[0].value = map[firstValue]; | ||
} | ||
return; | ||
} | ||
if (firstValue === 'center' && ~directions.indexOf(secondValue)) { | ||
position[0].value = position[1].value = ''; | ||
if ((0, _has2.default)(horizontal, secondValue)) { | ||
position[2].value = horizontal[secondValue]; | ||
} | ||
return; | ||
} | ||
if ((0, _has2.default)(horizontal, firstValue) && (0, _has2.default)(vertical, secondValue)) { | ||
position[0].value = horizontal[firstValue]; | ||
position[2].value = vertical[secondValue]; | ||
return; | ||
@@ -107,11 +127,30 @@ } else if ((0, _has2.default)(vertical, firstValue) && (0, _has2.default)(horizontal, secondValue)) { | ||
position[2].value = vertical[firstValue]; | ||
return; | ||
} | ||
}); | ||
decl.value = values.toString(); | ||
return parsed.toString(); | ||
} | ||
exports.default = (0, _postcss.plugin)('postcss-normalize-positions', () => { | ||
return css => css.walkDecls(/^(background(-position)?|(-webkit-)?perspective-origin)$/i, transform); | ||
return css => { | ||
const cache = {}; | ||
css.walkDecls(/^(background(-position)?|(-webkit-)?perspective-origin)$/i, decl => { | ||
const value = decl.value; | ||
if (cache[value]) { | ||
decl.value = cache[value]; | ||
return; | ||
} | ||
const result = transform(value); | ||
decl.value = result; | ||
cache[value] = result; | ||
}); | ||
}; | ||
}); | ||
module.exports = exports['default']; |
{ | ||
"name": "postcss-normalize-positions", | ||
"version": "4.0.1", | ||
"version": "4.0.2", | ||
"description": "Normalize keyword values for position into length values.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
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
6736
106
0
4