postcss-convert-values 5.0.0-rc.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 +13 -9
- package/package.json +10 -11
- package/CHANGELOG.md +0 -55
package/dist/index.js
CHANGED
|
@@ -11,11 +11,15 @@ var _convert = _interopRequireDefault(require("./lib/convert"));
|
|
|
11
11
|
|
|
12
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
13
|
|
|
14
|
-
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var
|
|
14
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
15
15
|
|
|
16
|
-
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; }
|
|
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'];
|
|
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
|
+
|
|
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
|
+
|
|
22
|
+
const keepWhenZero = new Set(['stroke-dashoffset', 'stroke-width', 'line-height']);
|
|
19
23
|
/*
|
|
20
24
|
* Numbers without digits after the dot are technically invalid,
|
|
21
25
|
* but in that case css-value-parser returns the dot as part of the unit,
|
|
@@ -38,11 +42,11 @@ function parseWord(node, opts, keepZeroUnit) {
|
|
|
38
42
|
const u = stripLeadingDot(pair.unit);
|
|
39
43
|
|
|
40
44
|
if (num === 0) {
|
|
41
|
-
node.value = 0 + (keepZeroUnit ||
|
|
45
|
+
node.value = 0 + (keepZeroUnit || !LENGTH_UNITS.has(u.toLowerCase()) && u !== '%' ? u : '');
|
|
42
46
|
} else {
|
|
43
47
|
node.value = (0, _convert.default)(num, u, opts);
|
|
44
48
|
|
|
45
|
-
if (typeof opts.precision === 'number' && u.toLowerCase() === 'px' &&
|
|
49
|
+
if (typeof opts.precision === 'number' && u.toLowerCase() === 'px' && pair.number.includes('.')) {
|
|
46
50
|
const precision = Math.pow(10, opts.precision);
|
|
47
51
|
node.value = Math.round(parseFloat(node.value) * precision) / precision + u;
|
|
48
52
|
}
|
|
@@ -66,18 +70,18 @@ function clampOpacity(node) {
|
|
|
66
70
|
}
|
|
67
71
|
}
|
|
68
72
|
|
|
69
|
-
function
|
|
73
|
+
function shouldKeepZeroUnit(decl) {
|
|
70
74
|
const {
|
|
71
75
|
parent
|
|
72
76
|
} = decl;
|
|
73
77
|
const lowerCasedProp = decl.prop.toLowerCase();
|
|
74
|
-
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);
|
|
75
79
|
}
|
|
76
80
|
|
|
77
81
|
function transform(opts, decl) {
|
|
78
82
|
const lowerCasedProp = decl.prop.toLowerCase();
|
|
79
83
|
|
|
80
|
-
if (
|
|
84
|
+
if (lowerCasedProp.includes('flex') || lowerCasedProp.indexOf('--') === 0 || notALength.has(lowerCasedProp)) {
|
|
81
85
|
return;
|
|
82
86
|
}
|
|
83
87
|
|
|
@@ -85,7 +89,7 @@ function transform(opts, decl) {
|
|
|
85
89
|
const lowerCasedValue = node.value.toLowerCase();
|
|
86
90
|
|
|
87
91
|
if (node.type === 'word') {
|
|
88
|
-
parseWord(node, opts,
|
|
92
|
+
parseWord(node, opts, shouldKeepZeroUnit(decl));
|
|
89
93
|
|
|
90
94
|
if (lowerCasedProp === 'opacity' || lowerCasedProp === 'shape-image-threshold') {
|
|
91
95
|
clampOpacity(node);
|
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": "del-cli dist",
|
|
12
|
-
"build": "cross-env BABEL_ENV=publish babel src --config-file ../../babel.config.js --out-dir dist --ignore \"**/__tests__/\"",
|
|
13
|
-
"prepublish": "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"
|
|
@@ -36,10 +31,14 @@
|
|
|
36
31
|
"node": "^10 || ^12 || >=14.0"
|
|
37
32
|
},
|
|
38
33
|
"devDependencies": {
|
|
39
|
-
"postcss": "^8.2.
|
|
34
|
+
"postcss": "^8.2.15"
|
|
40
35
|
},
|
|
41
36
|
"peerDependencies": {
|
|
42
|
-
"postcss": "^8.2.
|
|
37
|
+
"postcss": "^8.2.15"
|
|
38
|
+
},
|
|
39
|
+
"scripts": {
|
|
40
|
+
"prebuild": "rimraf dist",
|
|
41
|
+
"build": "babel src --config-file ../../babel.config.json --out-dir dist --ignore \"**/__tests__/\""
|
|
43
42
|
},
|
|
44
|
-
"
|
|
45
|
-
}
|
|
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
|
+
}
|
package/CHANGELOG.md
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
# Change Log
|
|
2
|
-
|
|
3
|
-
All notable changes to this project will be documented in this file.
|
|
4
|
-
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
|
-
|
|
6
|
-
# [5.0.0-rc.2](https://github.com/cssnano/cssnano/compare/postcss-convert-values@5.0.0-rc.1...postcss-convert-values@5.0.0-rc.2) (2021-03-15)
|
|
7
|
-
|
|
8
|
-
**Note:** Version bump only for package postcss-convert-values
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
# [5.0.0-rc.1](https://github.com/cssnano/cssnano/compare/postcss-convert-values@5.0.0-rc.0...postcss-convert-values@5.0.0-rc.1) (2021-03-04)
|
|
15
|
-
|
|
16
|
-
**Note:** Version bump only for package postcss-convert-values
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
# 5.0.0-rc.0 (2021-02-19)
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
### Bug Fixes
|
|
26
|
-
|
|
27
|
-
* Keep math functions together ([#895](https://github.com/cssnano/cssnano/issues/895)) ([4ddf843](https://github.com/cssnano/cssnano/commit/4ddf843ca5dc64059f488113224e76165211a669))
|
|
28
|
-
* preservation of opacities defined as percentages ([#881](https://github.com/cssnano/cssnano/issues/881)) ([fd7b878](https://github.com/cssnano/cssnano/commit/fd7b878e72ed9bd20c145c9e2daa7b5d48cb1117))
|
|
29
|
-
* units being removed in math functions ([#894](https://github.com/cssnano/cssnano/issues/894)) ([1ccbd5b](https://github.com/cssnano/cssnano/commit/1ccbd5b29e1b2121efaf7b24a69aa782848966dc))
|
|
30
|
-
* **postcss-convert-values:** prevent zero units from being dropped in line-height. ([#801](https://github.com/cssnano/cssnano/issues/801)) ([d781855](https://github.com/cssnano/cssnano/commit/d78185567ae5ebcde0469cf0e55145a7a3130d3e))
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
### chore
|
|
34
|
-
|
|
35
|
-
* minimum require version of node is 10.13 ([#871](https://github.com/cssnano/cssnano/issues/871)) ([28bda24](https://github.com/cssnano/cssnano/commit/28bda243e32ce3ba89b3c358a5f78727b3732f11))
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
### Features
|
|
39
|
-
|
|
40
|
-
* migarete to PostCSS 8 ([#975](https://github.com/cssnano/cssnano/issues/975)) ([40b82dc](https://github.com/cssnano/cssnano/commit/40b82dca7f53ac02cd4fe62846dec79b898ccb49))
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
### BREAKING CHANGES
|
|
44
|
-
|
|
45
|
-
* minimum supported `postcss` version is `8.2.1`
|
|
46
|
-
* minimum require version of node is 10.13
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
## 4.1.1 (2018-09-24)
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
### Bug Fixes
|
|
54
|
-
|
|
55
|
-
* **postcss-merge-longhand:** not mangle border output ([#555](https://github.com/cssnano/cssnano/issues/555)) ([9a70605](https://github.com/cssnano/cssnano/commit/9a706050b621e7795a9bf74eb7110b5c81804ffe)), closes [#553](https://github.com/cssnano/cssnano/issues/553) [#554](https://github.com/cssnano/cssnano/issues/554)
|