postcss-convert-values 5.0.2 → 5.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +5 -5
- package/package.json +8 -9
package/dist/index.js
CHANGED
|
@@ -15,7 +15,7 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
|
|
|
15
15
|
|
|
16
16
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && 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; }
|
|
17
17
|
|
|
18
|
-
const LENGTH_UNITS = ['em', 'ex', 'ch', 'rem', 'vw', 'vh', 'vmin', 'vmax', 'cm', 'mm', 'q', 'in', 'pt', 'pc', 'px']; // These properties only accept percentages, so no point in trying to transform
|
|
18
|
+
const LENGTH_UNITS = new Set(['em', 'ex', 'ch', 'rem', 'vw', 'vh', 'vmin', 'vmax', 'cm', 'mm', 'q', 'in', 'pt', 'pc', 'px']); // These properties only accept percentages, so no point in trying to transform
|
|
19
19
|
|
|
20
20
|
const notALength = new Set(['descent-override', 'ascent-override', 'font-stretch', 'size-adjust', 'line-gap-override']); // Can't change the unit on these properties when they're 0
|
|
21
21
|
|
|
@@ -42,11 +42,11 @@ function parseWord(node, opts, keepZeroUnit) {
|
|
|
42
42
|
const u = stripLeadingDot(pair.unit);
|
|
43
43
|
|
|
44
44
|
if (num === 0) {
|
|
45
|
-
node.value = 0 + (keepZeroUnit ||
|
|
45
|
+
node.value = 0 + (keepZeroUnit || !LENGTH_UNITS.has(u.toLowerCase()) && u !== '%' ? u : '');
|
|
46
46
|
} else {
|
|
47
47
|
node.value = (0, _convert.default)(num, u, opts);
|
|
48
48
|
|
|
49
|
-
if (typeof opts.precision === 'number' && u.toLowerCase() === 'px' &&
|
|
49
|
+
if (typeof opts.precision === 'number' && u.toLowerCase() === 'px' && pair.number.includes('.')) {
|
|
50
50
|
const precision = Math.pow(10, opts.precision);
|
|
51
51
|
node.value = Math.round(parseFloat(node.value) * precision) / precision + u;
|
|
52
52
|
}
|
|
@@ -75,13 +75,13 @@ function shouldKeepZeroUnit(decl) {
|
|
|
75
75
|
parent
|
|
76
76
|
} = decl;
|
|
77
77
|
const lowerCasedProp = decl.prop.toLowerCase();
|
|
78
|
-
return
|
|
78
|
+
return decl.value.includes('%') && (lowerCasedProp === 'max-height' || lowerCasedProp === 'height') || parent.parent && parent.parent.name && parent.parent.name.toLowerCase() === 'keyframes' && lowerCasedProp === 'stroke-dasharray' || keepWhenZero.has(lowerCasedProp);
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
function transform(opts, decl) {
|
|
82
82
|
const lowerCasedProp = decl.prop.toLowerCase();
|
|
83
83
|
|
|
84
|
-
if (
|
|
84
|
+
if (lowerCasedProp.includes('flex') || lowerCasedProp.indexOf('--') === 0 || notALength.has(lowerCasedProp)) {
|
|
85
85
|
return;
|
|
86
86
|
}
|
|
87
87
|
|
package/package.json
CHANGED
|
@@ -1,17 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "postcss-convert-values",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.3",
|
|
4
4
|
"description": "Convert values with PostCSS (e.g. ms -> s)",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"files": [
|
|
7
7
|
"LICENSE-MIT",
|
|
8
8
|
"dist"
|
|
9
9
|
],
|
|
10
|
-
"scripts": {
|
|
11
|
-
"prebuild": "rimraf dist",
|
|
12
|
-
"build": "cross-env BABEL_ENV=publish babel src --config-file ../../babel.config.json --out-dir dist --ignore \"**/__tests__/\"",
|
|
13
|
-
"prepare": "yarn build"
|
|
14
|
-
},
|
|
15
10
|
"keywords": [
|
|
16
11
|
"css",
|
|
17
12
|
"optimisation",
|
|
@@ -27,7 +22,7 @@
|
|
|
27
22
|
},
|
|
28
23
|
"repository": "cssnano/cssnano",
|
|
29
24
|
"dependencies": {
|
|
30
|
-
"postcss-value-parser": "^4.
|
|
25
|
+
"postcss-value-parser": "^4.2.0"
|
|
31
26
|
},
|
|
32
27
|
"bugs": {
|
|
33
28
|
"url": "https://github.com/cssnano/cssnano/issues"
|
|
@@ -41,5 +36,9 @@
|
|
|
41
36
|
"peerDependencies": {
|
|
42
37
|
"postcss": "^8.2.15"
|
|
43
38
|
},
|
|
44
|
-
"
|
|
45
|
-
|
|
39
|
+
"scripts": {
|
|
40
|
+
"prebuild": "rimraf dist",
|
|
41
|
+
"build": "babel src --config-file ../../babel.config.json --out-dir dist --ignore \"**/__tests__/\""
|
|
42
|
+
},
|
|
43
|
+
"readme": "# [postcss][postcss]-convert-values\n\n> Convert values with PostCSS (e.g. ms -> s)\n\n## Install\n\nWith [npm](https://npmjs.org/package/postcss-convert-values) do:\n\n```\nnpm install postcss-convert-values --save\n```\n\n## Example\n\nThis plugin reduces CSS size by converting values to use different units\nwhere possible; for example, `500ms` can be represented as `.5s`. You can\nread more about these units in [this article][csstricks].\n\n### Input\n\n```css\nh1 {\n font-size: 16px;\n width: 0em\n}\n```\n\n### Output\n\n```css\nh1 {\n font-size: 1pc;\n width: 0\n}\n```\n\nNote that this plugin only covers conversions for duration and absolute length\nvalues. For color conversions, use [postcss-colormin][colormin].\n\n## API\n\n### convertValues([options])\n\n#### options\n\n##### length\n\nType: `boolean`\nDefault: `true`\n\nPass `false` to disable conversion from `px` to other absolute length units,\nsuch as `pc` & `pt` & vice versa.\n\n##### time\n\nType: `boolean`\nDefault: `true`\n\nPass `false` to disable conversion from `ms` to `s` & vice versa.\n\n##### angle\n\nType: `boolean`\nDefault: `true`\n\nPass `false` to disable conversion from `deg` to `turn` & vice versa.\n\n##### precision\n\nType: `boolean|number`\nDefault: `false`\n\nSpecify any numeric value here to round `px` values to that many decimal places;\nfor example, using `{precision: 2}` will round `6.66667px` to `6.67px`, and\n`{precision: 0}` will round it to `7px`. Passing `false` (the default) will\nleave these values as is.\n\nIt is recommended for most use cases to set this option to `2`.\n\n\n## Usage\n\nSee the [PostCSS documentation](https://github.com/postcss/postcss#usage) for\nexamples for your environment.\n\n\n## Contributors\n\nSee [CONTRIBUTORS.md](https://github.com/cssnano/cssnano/blob/master/CONTRIBUTORS.md).\n\n\n## License\n\nMIT © [Ben Briggs](http://beneb.info)\n\n\n[postcss]: https://github.com/postcss/postcss\n[csstricks]: https://css-tricks.com/the-lengths-of-css/\n"
|
|
44
|
+
}
|