postcss-convert-values
Advanced tools
Comparing version 2.6.1 to 4.0.0-nightly.2020.1.9
@@ -1,108 +0,108 @@ | ||
'use strict'; | ||
"use strict"; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
var _postcss = require('postcss'); | ||
var _postcss = _interopRequireDefault(require("postcss")); | ||
var _postcss2 = _interopRequireDefault(_postcss); | ||
var _postcssValueParser = _interopRequireWildcard(require("postcss-value-parser")); | ||
var _postcssValueParser = require('postcss-value-parser'); | ||
var _convert = _interopRequireDefault(require("./lib/convert")); | ||
var _postcssValueParser2 = _interopRequireDefault(_postcssValueParser); | ||
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; } | ||
var _convert = require('./lib/convert'); | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
var _convert2 = _interopRequireDefault(_convert); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var LENGTH_UNITS = ['em', 'ex', 'ch', 'rem', 'vw', 'vh', 'vmin', 'vmax', 'cm', 'mm', 'q', 'in', 'pt', 'pc', 'px']; | ||
const LENGTH_UNITS = ['em', 'ex', 'ch', 'rem', 'vw', 'vh', 'vmin', 'vmax', 'cm', 'mm', 'q', 'in', 'pt', 'pc', 'px']; | ||
function parseWord(node, opts, keepZeroUnit) { | ||
var pair = (0, _postcssValueParser.unit)(node.value); | ||
if (pair) { | ||
var num = Number(pair.number); | ||
var u = pair.unit.toLowerCase(); | ||
if (num === 0) { | ||
node.value = keepZeroUnit || !~LENGTH_UNITS.indexOf(u) && u !== '%' ? 0 + u : 0; | ||
} else { | ||
node.value = (0, _convert2.default)(num, u, opts); | ||
const pair = (0, _postcssValueParser.unit)(node.value); | ||
if (typeof opts.precision === 'number' && u === 'px' && ~pair.number.indexOf('.')) { | ||
var precision = Math.pow(10, opts.precision); | ||
node.value = Math.round(parseFloat(node.value) * precision) / precision + u; | ||
} | ||
} | ||
if (pair) { | ||
const num = Number(pair.number); | ||
const u = pair.unit; | ||
if (num === 0) { | ||
node.value = keepZeroUnit || !~LENGTH_UNITS.indexOf(u.toLowerCase()) && u !== '%' ? 0 + u : 0; | ||
} else { | ||
node.value = (0, _convert.default)(num, u, opts); | ||
if (typeof opts.precision === 'number' && u.toLowerCase() === 'px' && ~pair.number.indexOf('.')) { | ||
const precision = Math.pow(10, opts.precision); | ||
node.value = Math.round(parseFloat(node.value) * precision) / precision + u; | ||
} | ||
} | ||
} | ||
} | ||
function clampOpacity(node) { | ||
var pair = (0, _postcssValueParser.unit)(node.value); | ||
if (!pair) { | ||
return; | ||
} | ||
var num = Number(pair.number); | ||
if (num > 1) { | ||
node.value = 1 + pair.unit; | ||
} else if (num < 0) { | ||
node.value = 0 + pair.unit; | ||
} | ||
} | ||
const pair = (0, _postcssValueParser.unit)(node.value); | ||
function shouldStripPercent(_ref) { | ||
var value = _ref.value, | ||
prop = _ref.prop, | ||
parent = _ref.parent; | ||
if (!pair) { | ||
return; | ||
} | ||
return ~value.indexOf('%') && (prop === 'max-height' || prop === 'height') || parent.parent && parent.parent.name === 'keyframes' && prop === 'stroke-dasharray' || prop === 'stroke-dashoffset' || prop === 'stroke-width'; | ||
let num = Number(pair.number); | ||
if (num > 1) { | ||
node.value = pair.unit === '%' ? num + pair.unit : 1 + pair.unit; | ||
} else if (num < 0) { | ||
node.value = 0 + pair.unit; | ||
} | ||
} | ||
function transform(opts) { | ||
return function (decl) { | ||
var prop = decl.prop; | ||
function shouldKeepUnit(decl) { | ||
const { | ||
parent | ||
} = decl; | ||
const lowerCasedProp = decl.prop.toLowerCase(); | ||
return ~decl.value.indexOf('%') && (lowerCasedProp === 'max-height' || lowerCasedProp === 'height') || parent.parent && parent.parent.name && parent.parent.name.toLowerCase() === 'keyframes' && lowerCasedProp === 'stroke-dasharray' || lowerCasedProp === 'stroke-dashoffset' || lowerCasedProp === 'stroke-width' || lowerCasedProp === 'line-height'; | ||
} | ||
if (~prop.indexOf('flex') || prop.indexOf('--') === 0) { | ||
return; | ||
} | ||
function transform(opts, decl) { | ||
const lowerCasedProp = decl.prop.toLowerCase(); | ||
decl.value = (0, _postcssValueParser2.default)(decl.value).walk(function (node) { | ||
if (node.type === 'word') { | ||
parseWord(node, opts, shouldStripPercent(decl)); | ||
if (prop === 'opacity' || prop === 'shape-image-threshold') { | ||
clampOpacity(node); | ||
} | ||
} else if (node.type === 'function') { | ||
if (node.value === 'calc' || node.value === 'hsl' || node.value === 'hsla') { | ||
(0, _postcssValueParser.walk)(node.nodes, function (n) { | ||
if (n.type === 'word') { | ||
parseWord(n, opts, true); | ||
} | ||
}); | ||
return false; | ||
} | ||
if (node.value === 'url') { | ||
return false; | ||
} | ||
} | ||
}).toString(); | ||
}; | ||
} | ||
if (~lowerCasedProp.indexOf('flex') || lowerCasedProp.indexOf('--') === 0) { | ||
return; | ||
} | ||
var plugin = 'postcss-convert-values'; | ||
decl.value = (0, _postcssValueParser.default)(decl.value).walk(node => { | ||
const lowerCasedValue = node.value.toLowerCase(); | ||
exports.default = _postcss2.default.plugin(plugin, function () { | ||
var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : { precision: false }; | ||
if (node.type === 'word') { | ||
parseWord(node, opts, shouldKeepUnit(decl)); | ||
if (opts.length === undefined && opts.convertLength !== undefined) { | ||
console.warn(plugin + ': `convertLength` option is deprecated. Use `length`'); | ||
opts.length = opts.convertLength; | ||
if (lowerCasedProp === 'opacity' || lowerCasedProp === 'shape-image-threshold') { | ||
clampOpacity(node); | ||
} | ||
} else if (node.type === 'function') { | ||
if (lowerCasedValue === 'calc' || lowerCasedValue === 'min' || lowerCasedValue === 'max' || lowerCasedValue === 'clamp' || lowerCasedValue === 'hsl' || lowerCasedValue === 'hsla') { | ||
(0, _postcssValueParser.walk)(node.nodes, n => { | ||
if (n.type === 'word') { | ||
parseWord(n, opts, true); | ||
} | ||
}); | ||
return false; | ||
} | ||
if (lowerCasedValue === 'url') { | ||
return false; | ||
} | ||
} | ||
if (opts.length === undefined && opts.convertTime !== undefined) { | ||
console.warn(plugin + ': `convertTime` option is deprecated. Use `time`'); | ||
opts.time = opts.convertTime; | ||
} | ||
return function (css) { | ||
return css.walkDecls(transform(opts)); | ||
}; | ||
}).toString(); | ||
} | ||
const plugin = 'postcss-convert-values'; | ||
var _default = _postcss.default.plugin(plugin, (opts = { | ||
precision: false | ||
}) => { | ||
return css => css.walkDecls(transform.bind(null, opts)); | ||
}); | ||
module.exports = exports['default']; | ||
exports.default = _default; | ||
module.exports = exports.default; |
@@ -1,88 +0,85 @@ | ||
'use strict'; | ||
"use strict"; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = _default; | ||
const lengthConv = { | ||
in: 96, | ||
px: 1, | ||
pt: 4 / 3, | ||
pc: 16 | ||
}; | ||
const timeConv = { | ||
s: 1000, | ||
ms: 1 | ||
}; | ||
const angleConv = { | ||
turn: 360, | ||
deg: 1 | ||
}; | ||
exports.default = function (number, unit, _ref) { | ||
var time = _ref.time, | ||
length = _ref.length, | ||
angle = _ref.angle; | ||
function dropLeadingZero(number) { | ||
const value = String(number); | ||
var value = dropLeadingZero(number) + (unit ? unit : ''); | ||
var converted = void 0; | ||
if (length !== false && unit in lengthConv) { | ||
converted = transform(number, unit, lengthConv); | ||
if (number % 1) { | ||
if (value[0] === '0') { | ||
return value.slice(1); | ||
} | ||
if (time !== false && unit in timeConv) { | ||
converted = transform(number, unit, timeConv); | ||
if (value[0] === '-' && value[1] === '0') { | ||
return '-' + value.slice(2); | ||
} | ||
} | ||
if (angle !== false && unit in angleConv) { | ||
converted = transform(number, unit, angleConv); | ||
} | ||
return value; | ||
} | ||
if (converted && converted.length < value.length) { | ||
value = converted; | ||
function transform(number, unit, conversion) { | ||
const lowerCasedUnit = unit.toLowerCase(); | ||
let one, base; | ||
let convertionUnits = Object.keys(conversion).filter(u => { | ||
if (conversion[u] === 1) { | ||
one = u; | ||
} | ||
return value; | ||
}; | ||
return lowerCasedUnit !== u; | ||
}); | ||
var lengthConv = { | ||
in: 96, | ||
px: 1, | ||
pt: 4 / 3, | ||
pc: 16 | ||
}; | ||
if (lowerCasedUnit === one) { | ||
base = number / conversion[lowerCasedUnit]; | ||
} else { | ||
base = number * conversion[lowerCasedUnit]; | ||
} | ||
var timeConv = { | ||
s: 1000, | ||
ms: 1 | ||
}; | ||
return convertionUnits.map(u => dropLeadingZero(base / conversion[u]) + u).reduce((a, b) => a.length < b.length ? a : b); | ||
} | ||
var angleConv = { | ||
turn: 360, | ||
deg: 1 | ||
}; | ||
function _default(number, unit, { | ||
time, | ||
length, | ||
angle | ||
}) { | ||
let value = dropLeadingZero(number) + (unit ? unit : ''); | ||
let converted; | ||
function dropLeadingZero(number) { | ||
var value = String(number); | ||
if (length !== false && unit.toLowerCase() in lengthConv) { | ||
converted = transform(number, unit, lengthConv); | ||
} | ||
if (number % 1) { | ||
if (value[0] === '0') { | ||
return value.slice(1); | ||
} | ||
if (time !== false && unit.toLowerCase() in timeConv) { | ||
converted = transform(number, unit, timeConv); | ||
} | ||
if (value[0] === '-' && value[1] === '0') { | ||
return '-' + value.slice(2); | ||
} | ||
} | ||
if (angle !== false && unit.toLowerCase() in angleConv) { | ||
converted = transform(number, unit, angleConv); | ||
} | ||
return value; | ||
} | ||
if (converted && converted.length < value.length) { | ||
value = converted; | ||
} | ||
function transform(number, unit, conversion) { | ||
var one = void 0, | ||
base = void 0; | ||
var convertionUnits = Object.keys(conversion).filter(function (u) { | ||
if (conversion[u] === 1) { | ||
one = u; | ||
} | ||
return unit !== u; | ||
}); | ||
if (unit === one) { | ||
base = number / conversion[unit]; | ||
} else { | ||
base = number * conversion[unit]; | ||
} | ||
return convertionUnits.map(function (u) { | ||
return dropLeadingZero(base / conversion[u]) + u; | ||
}).reduce(function (a, b) { | ||
return a.length < b.length ? a : b; | ||
}); | ||
return value; | ||
} | ||
module.exports = exports['default']; | ||
module.exports = exports.default; |
{ | ||
"name": "postcss-convert-values", | ||
"version": "2.6.1", | ||
"version": "4.0.0-nightly.2020.1.9", | ||
"description": "Convert values with PostCSS (e.g. ms -> s)", | ||
@@ -11,8 +11,5 @@ "main": "dist/index.js", | ||
"scripts": { | ||
"contributorAdd": "all-contributors add", | ||
"contributorGenerate": "all-contributors generate", | ||
"pretest": "eslint src", | ||
"prepublish": "del-cli dist && BABEL_ENV=publish babel src --out-dir dist --ignore /__tests__/", | ||
"test": "ava", | ||
"test-012": "ava" | ||
"prebuild": "", | ||
"build": "cross-env BABEL_ENV=publish babel src --config-file ../../babel.config.js --out-dir dist --ignore \"**/__tests__/\"", | ||
"prepublish": "" | ||
}, | ||
@@ -26,19 +23,3 @@ "keywords": [ | ||
"license": "MIT", | ||
"devDependencies": { | ||
"all-contributors-cli": "^3.0.5", | ||
"ava": "^0.17.0", | ||
"babel-cli": "^6.3.17", | ||
"babel-core": "^6.3.26", | ||
"babel-plugin-add-module-exports": "^0.2.1", | ||
"babel-preset-es2015": "^6.3.13", | ||
"babel-preset-es2015-loose": "^7.0.0", | ||
"babel-preset-stage-0": "^6.3.13", | ||
"babel-register": "^6.9.0", | ||
"del-cli": "^0.2.0", | ||
"eslint": "^3.0.0", | ||
"eslint-config-cssnano": "^3.0.0", | ||
"eslint-plugin-babel": "^3.3.0", | ||
"eslint-plugin-import": "^2.0.1" | ||
}, | ||
"homepage": "https://github.com/ben-eb/postcss-convert-values", | ||
"homepage": "https://github.com/cssnano/cssnano", | ||
"author": { | ||
@@ -49,13 +30,13 @@ "name": "Ben Briggs", | ||
}, | ||
"repository": "ben-eb/postcss-convert-values", | ||
"repository": "cssnano/cssnano", | ||
"dependencies": { | ||
"postcss": "^5.0.11", | ||
"postcss-value-parser": "^3.1.2" | ||
"postcss": "^7.0.16", | ||
"postcss-value-parser": "^3.3.1" | ||
}, | ||
"ava": { | ||
"require": "babel-register" | ||
"bugs": { | ||
"url": "https://github.com/cssnano/cssnano/issues" | ||
}, | ||
"eslintConfig": { | ||
"extends": "cssnano" | ||
"engines": { | ||
"node": ">=10.13.0" | ||
} | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
# [postcss][postcss]-convert-values [![Build Status](https://travis-ci.org/ben-eb/postcss-convert-values.svg?branch=master)][ci] [![NPM version](https://badge.fury.io/js/postcss-convert-values.svg)][npm] [![Dependency Status](https://gemnasium.com/ben-eb/postcss-convert-values.svg)][deps] | ||
# [postcss][postcss]-convert-values | ||
@@ -81,15 +81,13 @@ > Convert values with PostCSS (e.g. ms -> s) | ||
## Usage | ||
See the [PostCSS documentation](https://github.com/postcss/postcss#usage) for | ||
examples for your environment. | ||
## Contributors | ||
Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds/all-contributors#emoji-key)): | ||
See [CONTRIBUTORS.md](https://github.com/cssnano/cssnano/blob/master/CONTRIBUTORS.md). | ||
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --> | ||
| [<img src="https://avatars.githubusercontent.com/u/1282980?v=3" width="100px;"/><br /><sub>Ben Briggs</sub>](http://beneb.info)<br />[💻](https://github.com/ben-eb/postcss-convert-values/commits?author=ben-eb) [📖](https://github.com/ben-eb/postcss-convert-values/commits?author=ben-eb) 👀 [⚠️](https://github.com/ben-eb/postcss-convert-values/commits?author=ben-eb) | [<img src="https://avatars.githubusercontent.com/u/5635476?v=3" width="100px;"/><br /><sub>Bogdan Chadkin</sub>](https://github.com/TrySound)<br />[💻](https://github.com/ben-eb/postcss-convert-values/commits?author=TrySound) [📖](https://github.com/ben-eb/postcss-convert-values/commits?author=TrySound) 👀 [⚠️](https://github.com/ben-eb/postcss-convert-values/commits?author=TrySound) | [<img src="https://avatars.githubusercontent.com/u/177485?v=3" width="100px;"/><br /><sub>Roman Komarov</sub>](http://kizu.ru/en/)<br />[🐛](https://github.com/ben-eb/postcss-convert-values/issues?q=author%3Akizu) | [<img src="https://avatars.githubusercontent.com/u/5103477?v=3" width="100px;"/><br /><sub>Dmitry Kiselyov</sub>](http://codepen.io/dmitrykiselyov)<br />[🐛](https://github.com/ben-eb/postcss-convert-values/issues?q=author%3Admitrykiselyov) | [<img src="https://avatars.githubusercontent.com/u/5038030?v=3" width="100px;"/><br /><sub>Charlike Mike Reagent</sub>](http://www.tunnckocore.tk)<br />[💻](https://github.com/ben-eb/postcss-convert-values/commits?author=tunnckoCore) [⚠️](https://github.com/ben-eb/postcss-convert-values/commits?author=tunnckoCore) | [<img src="https://avatars.githubusercontent.com/u/815848?v=3" width="100px;"/><br /><sub>Vyacheslav Shebanov</sub>](https://github.com/Termina1)<br />[📖](https://github.com/ben-eb/postcss-convert-values/commits?author=Termina1) | [<img src="https://avatars.githubusercontent.com/u/192323?v=3" width="100px;"/><br /><sub>Marek ‘saji’ Augustynowicz</sub>](http://twitter.com/saji_)<br />[💻](https://github.com/ben-eb/postcss-convert-values/commits?author=marek-saji) [⚠️](https://github.com/ben-eb/postcss-convert-values/commits?author=marek-saji) | | ||
| :---: | :---: | :---: | :---: | :---: | :---: | :---: | | ||
| [<img src="https://avatars.githubusercontent.com/u/552316?v=3" width="100px;"/><br /><sub>Jonny Gerig Meyer</sub>](www.oddbird.net)<br />[💻](https://github.com/ben-eb/postcss-convert-values/commits?author=jgerigmeyer) [⚠️](https://github.com/ben-eb/postcss-convert-values/commits?author=jgerigmeyer) | [<img src="https://avatars.githubusercontent.com/u/1726061?v=3" width="100px;"/><br /><sub>GU Yiling</sub>](http://lync.in/)<br />[💻](https://github.com/ben-eb/postcss-convert-values/commits?author=Justineo) [⚠️](https://github.com/ben-eb/postcss-convert-values/commits?author=Justineo) | | ||
<!-- ALL-CONTRIBUTORS-LIST:END --> | ||
This project follows the [all-contributors] specification. Contributions of | ||
any kind welcome! | ||
## License | ||
@@ -100,9 +98,3 @@ | ||
[all-contributors]: https://github.com/kentcdodds/all-contributors | ||
[ci]: https://travis-ci.org/ben-eb/postcss-convert-values | ||
[colormin]: https://github.com/ben-eb/postcss-colormin | ||
[deps]: https://gemnasium.com/ben-eb/postcss-convert-values | ||
[npm]: http://badge.fury.io/js/postcss-convert-values | ||
[postcss]: https://github.com/postcss/postcss | ||
[postcss]: https://github.com/postcss/postcss | ||
[csstricks]: https://css-tricks.com/the-lengths-of-css/ |
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
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
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
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
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
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 website
QualityPackage does not have a website.
Found 1 instance in 1 package
0
0
9772
5
152
99
1
+ Addedpicocolors@0.2.1(transitive)
+ Addedpostcss@7.0.39(transitive)
+ Addedsource-map@0.6.1(transitive)
- Removedansi-regex@2.1.1(transitive)
- Removedansi-styles@2.2.1(transitive)
- Removedchalk@1.1.3(transitive)
- Removedescape-string-regexp@1.0.5(transitive)
- Removedhas-ansi@2.0.0(transitive)
- Removedhas-flag@1.0.0(transitive)
- Removedjs-base64@2.6.4(transitive)
- Removedpostcss@5.2.18(transitive)
- Removedsource-map@0.5.7(transitive)
- Removedstrip-ansi@3.0.1(transitive)
- Removedsupports-color@2.0.03.2.3(transitive)
Updatedpostcss@^7.0.16
Updatedpostcss-value-parser@^3.3.1