postcss-convert-values 4.0.0-nightly.2020.9.3 → 4.0.0

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/CHANGELOG.md ADDED
@@ -0,0 +1,152 @@
1
+ # 4.0.0-rc.0
2
+
3
+ * Breaking: Drops support for Node 0.12, we now require at least Node 4.
4
+ * Breaking: Update PostCSS to 6.0.0.
5
+ * Breaking: Removes the deprecated options from version 2.2.0.
6
+
7
+ # 2.6.1
8
+
9
+ * Resolves an issue where IE hacks were being removed from `0` values
10
+ (thanks to @Justineo).
11
+
12
+ # 2.6.0
13
+
14
+ * Added clamping of the values for the `shape-image-threshold` property, using
15
+ the same logic as introduced in version `2.5.0`.
16
+
17
+ # 2.5.0
18
+
19
+ * Added clamping of the values for the `opacity` property to the `0-1` range.
20
+ For example, this will convert `opacity: 1.1` to `opacity: 1`.
21
+
22
+ # 2.4.1
23
+
24
+ * Resolves an issue where the units would be stripped from zero values in
25
+ custom properties (thanks to @jgerigmeyer).
26
+
27
+ # 2.4.0
28
+
29
+ * Added a `precision` option to enable rounding of decimal places for
30
+ `px` values.
31
+
32
+ # 2.3.6
33
+
34
+ * Resolves an issue with the last patch where `height: 0em` was not being
35
+ converted to `height: 0`.
36
+
37
+ # 2.3.5
38
+
39
+ * Resolves an issue where certain properties inside `@keyframes` rules would
40
+ break animation in IE due to the percentage being stripped. Now, the
41
+ percentage is preserved for these properties.
42
+
43
+ # 2.3.4
44
+
45
+ * Does not convert `height:0%` to `height:0` (and the same for `max-height`), as
46
+ they produce different results.
47
+
48
+ # 2.3.3
49
+
50
+ * Updates postcss-value-parser to version 3 (thanks to @TrySound).
51
+
52
+ # 2.3.2
53
+
54
+ * Fixed a regression where `0%` in color functions was being transformed to `0`
55
+ (thanks to @TrySound).
56
+
57
+ # 2.3.1
58
+
59
+ * Fixed a behaviour where `0deg` was being converted to `0`.
60
+
61
+ # 2.3.0
62
+
63
+ * Added an option to convert between `turn` & `deg` (thanks to @TrySound).
64
+
65
+ # 2.2.1
66
+
67
+ * Fixes a behaviour where the module would remove units from zero values inside
68
+ calc functions (thanks to @marek-saji & @TrySound).
69
+
70
+ # 2.2.0
71
+
72
+ * Renames `opts.convertLength` & `opts.convertTime` to
73
+ `opts.length` & `opts.time`; the old options will now print deprecation
74
+ warnings (thanks to @TrySound).
75
+
76
+ # 2.1.0
77
+
78
+ * Adds options to enable/disable unit conversion for time & length values.
79
+
80
+ # 2.0.1
81
+
82
+ * Bump postcss-value-parser to `2.0.2`.
83
+
84
+ # 2.0.0
85
+
86
+ * Upgraded to PostCSS 5.
87
+
88
+ # 1.3.1
89
+
90
+ * Fixes an issue where the module would convert values in gradient/url functions
91
+ since 1.3.0.
92
+
93
+ # 1.3.0
94
+
95
+ * Converted the module to use ES6.
96
+ * balanced-match, css-list & some integrated code has been replaced with
97
+ postcss-value-parser; reducing the number of moving parts in this module, and
98
+ providing a more futureproof way of parsing CSS numeric values.
99
+
100
+ # 1.2.5
101
+
102
+ * Fixes an issue where uppercase units (such as PX) were being deleted.
103
+
104
+ # 1.2.4
105
+
106
+ * Fixes convert not px or ms
107
+
108
+ # 1.2.3
109
+
110
+ * Adds support for `ch` units; previously they were removed.
111
+ * Upgrades css-list to `0.1.0`, code tidied up.
112
+
113
+ # 1.2.2
114
+
115
+ * Added support for viewport units (thanks to @TrySound).
116
+
117
+ # 1.2.1
118
+
119
+ * Fixes regressions introduced by the previous patch. Better support for
120
+ negative value transforms.
121
+
122
+ # 1.2.0
123
+
124
+ * Adds support for slash/comma separated values (thanks to @TrySound).
125
+
126
+ # 1.1.1
127
+
128
+ * Fixes an issue where trailing zeroes were not being removed in
129
+ values that were not `0` (thanks to @TrySound).
130
+
131
+ # 1.1.0
132
+
133
+ * Adds support for removing leading zeroes from `rem` values
134
+ (thanks to @tunnckoCore).
135
+
136
+ # 1.0.3
137
+
138
+ * Fixed a bug where filenames were being incorrectly transformed.
139
+
140
+ # 1.0.2
141
+
142
+ * Fixed a bug where `1.` and `.0` were not being optimised to `1` and `0`,
143
+ respectively.
144
+
145
+ # 1.0.1
146
+
147
+ * Fixed a bug where `undefined` would be stringified as the unit value, if the
148
+ value did not have a unit.
149
+
150
+ # 1.0.0
151
+
152
+ * Initial release.
package/dist/index.js CHANGED
@@ -1,108 +1,95 @@
1
- "use strict";
1
+ 'use strict';
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", {
4
- value: true
4
+ value: true
5
5
  });
6
- exports.default = void 0;
7
6
 
8
- var _postcss = _interopRequireDefault(require("postcss"));
7
+ var _postcss = require('postcss');
9
8
 
10
- var _postcssValueParser = _interopRequireWildcard(require("postcss-value-parser"));
9
+ var _postcss2 = _interopRequireDefault(_postcss);
11
10
 
12
- var _convert = _interopRequireDefault(require("./lib/convert"));
11
+ var _postcssValueParser = require('postcss-value-parser');
13
12
 
14
- function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
13
+ var _postcssValueParser2 = _interopRequireDefault(_postcssValueParser);
15
14
 
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; }
15
+ var _convert = require('./lib/convert');
16
+
17
+ var _convert2 = _interopRequireDefault(_convert);
17
18
 
18
19
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
20
 
20
21
  const LENGTH_UNITS = ['em', 'ex', 'ch', 'rem', 'vw', 'vh', 'vmin', 'vmax', 'cm', 'mm', 'q', 'in', 'pt', 'pc', 'px'];
21
22
 
22
23
  function parseWord(node, opts, keepZeroUnit) {
23
- const pair = (0, _postcssValueParser.unit)(node.value);
24
-
25
- if (pair) {
26
- const num = Number(pair.number);
27
- const u = pair.unit;
28
-
29
- if (num === 0) {
30
- node.value = keepZeroUnit || !~LENGTH_UNITS.indexOf(u.toLowerCase()) && u !== '%' ? 0 + u : 0;
31
- } else {
32
- node.value = (0, _convert.default)(num, u, opts);
33
-
34
- if (typeof opts.precision === 'number' && u.toLowerCase() === 'px' && ~pair.number.indexOf('.')) {
35
- const precision = Math.pow(10, opts.precision);
36
- node.value = Math.round(parseFloat(node.value) * precision) / precision + u;
37
- }
24
+ const pair = (0, _postcssValueParser.unit)(node.value);
25
+ if (pair) {
26
+ const num = Number(pair.number);
27
+ const u = pair.unit;
28
+ if (num === 0) {
29
+ node.value = keepZeroUnit || !~LENGTH_UNITS.indexOf(u.toLowerCase()) && u !== '%' ? 0 + u : 0;
30
+ } else {
31
+ node.value = (0, _convert2.default)(num, u, opts);
32
+
33
+ if (typeof opts.precision === 'number' && u.toLowerCase() === 'px' && ~pair.number.indexOf('.')) {
34
+ const precision = Math.pow(10, opts.precision);
35
+ node.value = Math.round(parseFloat(node.value) * precision) / precision + u;
36
+ }
37
+ }
38
38
  }
39
- }
40
39
  }
41
40
 
42
41
  function clampOpacity(node) {
43
- const pair = (0, _postcssValueParser.unit)(node.value);
44
-
45
- if (!pair) {
46
- return;
47
- }
48
-
49
- let num = Number(pair.number);
50
-
51
- if (num > 1) {
52
- node.value = pair.unit === '%' ? num + pair.unit : 1 + pair.unit;
53
- } else if (num < 0) {
54
- node.value = 0 + pair.unit;
55
- }
42
+ const pair = (0, _postcssValueParser.unit)(node.value);
43
+ if (!pair) {
44
+ return;
45
+ }
46
+ let num = Number(pair.number);
47
+ if (num > 1) {
48
+ node.value = 1 + pair.unit;
49
+ } else if (num < 0) {
50
+ node.value = 0 + pair.unit;
51
+ }
56
52
  }
57
53
 
58
- function shouldKeepUnit(decl) {
59
- const {
60
- parent
61
- } = decl;
62
- const lowerCasedProp = decl.prop.toLowerCase();
63
- 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';
54
+ function shouldStripPercent(decl) {
55
+ const { parent } = decl;
56
+ const lowerCasedProp = decl.prop.toLowerCase();
57
+ 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';
64
58
  }
65
59
 
66
60
  function transform(opts, decl) {
67
- const lowerCasedProp = decl.prop.toLowerCase();
68
-
69
- if (~lowerCasedProp.indexOf('flex') || lowerCasedProp.indexOf('--') === 0) {
70
- return;
71
- }
72
-
73
- decl.value = (0, _postcssValueParser.default)(decl.value).walk(node => {
74
- const lowerCasedValue = node.value.toLowerCase();
75
-
76
- if (node.type === 'word') {
77
- parseWord(node, opts, shouldKeepUnit(decl));
78
-
79
- if (lowerCasedProp === 'opacity' || lowerCasedProp === 'shape-image-threshold') {
80
- clampOpacity(node);
81
- }
82
- } else if (node.type === 'function') {
83
- if (lowerCasedValue === 'calc' || lowerCasedValue === 'min' || lowerCasedValue === 'max' || lowerCasedValue === 'clamp' || lowerCasedValue === 'hsl' || lowerCasedValue === 'hsla') {
84
- (0, _postcssValueParser.walk)(node.nodes, n => {
85
- if (n.type === 'word') {
86
- parseWord(n, opts, true);
87
- }
88
- });
89
- return false;
90
- }
91
-
92
- if (lowerCasedValue === 'url') {
93
- return false;
94
- }
61
+ const lowerCasedProp = decl.prop.toLowerCase();
62
+ if (~lowerCasedProp.indexOf('flex') || lowerCasedProp.indexOf('--') === 0) {
63
+ return;
95
64
  }
96
- }).toString();
65
+
66
+ decl.value = (0, _postcssValueParser2.default)(decl.value).walk(node => {
67
+ const lowerCasedValue = node.value.toLowerCase();
68
+
69
+ if (node.type === 'word') {
70
+ parseWord(node, opts, shouldStripPercent(decl));
71
+ if (lowerCasedProp === 'opacity' || lowerCasedProp === 'shape-image-threshold') {
72
+ clampOpacity(node);
73
+ }
74
+ } else if (node.type === 'function') {
75
+ if (lowerCasedValue === 'calc' || lowerCasedValue === 'hsl' || lowerCasedValue === 'hsla') {
76
+ (0, _postcssValueParser.walk)(node.nodes, n => {
77
+ if (n.type === 'word') {
78
+ parseWord(n, opts, true);
79
+ }
80
+ });
81
+ return false;
82
+ }
83
+ if (lowerCasedValue === 'url') {
84
+ return false;
85
+ }
86
+ }
87
+ }).toString();
97
88
  }
98
89
 
99
90
  const plugin = 'postcss-convert-values';
100
91
 
101
- var _default = _postcss.default.plugin(plugin, (opts = {
102
- precision: false
103
- }) => {
104
- return css => css.walkDecls(transform.bind(null, opts));
92
+ exports.default = _postcss2.default.plugin(plugin, (opts = { precision: false }) => {
93
+ return css => css.walkDecls(transform.bind(null, opts));
105
94
  });
106
-
107
- exports.default = _default;
108
- module.exports = exports.default;
95
+ module.exports = exports['default'];
@@ -1,85 +1,82 @@
1
- "use strict";
1
+ 'use strict';
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", {
4
- value: true
4
+ value: true
5
5
  });
6
- exports.default = _default;
7
- const lengthConv = {
8
- in: 96,
9
- px: 1,
10
- pt: 4 / 3,
11
- pc: 16
12
- };
13
- const timeConv = {
14
- s: 1000,
15
- ms: 1
16
- };
17
- const angleConv = {
18
- turn: 360,
19
- deg: 1
20
- };
21
6
 
22
- function dropLeadingZero(number) {
23
- const value = String(number);
7
+ exports.default = function (number, unit, { time, length, angle }) {
8
+ let value = dropLeadingZero(number) + (unit ? unit : '');
9
+ let converted;
24
10
 
25
- if (number % 1) {
26
- if (value[0] === '0') {
27
- return value.slice(1);
11
+ if (length !== false && unit.toLowerCase() in lengthConv) {
12
+ converted = transform(number, unit, lengthConv);
28
13
  }
29
14
 
30
- if (value[0] === '-' && value[1] === '0') {
31
- return '-' + value.slice(2);
15
+ if (time !== false && unit.toLowerCase() in timeConv) {
16
+ converted = transform(number, unit, timeConv);
32
17
  }
33
- }
34
18
 
35
- return value;
36
- }
19
+ if (angle !== false && unit.toLowerCase() in angleConv) {
20
+ converted = transform(number, unit, angleConv);
21
+ }
37
22
 
38
- function transform(number, unit, conversion) {
39
- const lowerCasedUnit = unit.toLowerCase();
40
- let one, base;
41
- let convertionUnits = Object.keys(conversion).filter(u => {
42
- if (conversion[u] === 1) {
43
- one = u;
23
+ if (converted && converted.length < value.length) {
24
+ value = converted;
44
25
  }
45
26
 
46
- return lowerCasedUnit !== u;
47
- });
27
+ return value;
28
+ };
29
+
30
+ const lengthConv = {
31
+ in: 96,
32
+ px: 1,
33
+ pt: 4 / 3,
34
+ pc: 16
35
+ };
48
36
 
49
- if (lowerCasedUnit === one) {
50
- base = number / conversion[lowerCasedUnit];
51
- } else {
52
- base = number * conversion[lowerCasedUnit];
53
- }
37
+ const timeConv = {
38
+ s: 1000,
39
+ ms: 1
40
+ };
54
41
 
55
- return convertionUnits.map(u => dropLeadingZero(base / conversion[u]) + u).reduce((a, b) => a.length < b.length ? a : b);
56
- }
42
+ const angleConv = {
43
+ turn: 360,
44
+ deg: 1
45
+ };
57
46
 
58
- function _default(number, unit, {
59
- time,
60
- length,
61
- angle
62
- }) {
63
- let value = dropLeadingZero(number) + (unit ? unit : '');
64
- let converted;
47
+ function dropLeadingZero(number) {
48
+ const value = String(number);
65
49
 
66
- if (length !== false && unit.toLowerCase() in lengthConv) {
67
- converted = transform(number, unit, lengthConv);
68
- }
50
+ if (number % 1) {
51
+ if (value[0] === '0') {
52
+ return value.slice(1);
53
+ }
69
54
 
70
- if (time !== false && unit.toLowerCase() in timeConv) {
71
- converted = transform(number, unit, timeConv);
72
- }
55
+ if (value[0] === '-' && value[1] === '0') {
56
+ return '-' + value.slice(2);
57
+ }
58
+ }
73
59
 
74
- if (angle !== false && unit.toLowerCase() in angleConv) {
75
- converted = transform(number, unit, angleConv);
76
- }
60
+ return value;
61
+ }
77
62
 
78
- if (converted && converted.length < value.length) {
79
- value = converted;
80
- }
63
+ function transform(number, unit, conversion) {
64
+ const lowerCasedUnit = unit.toLowerCase();
65
+ let one, base;
66
+ let convertionUnits = Object.keys(conversion).filter(u => {
67
+ if (conversion[u] === 1) {
68
+ one = u;
69
+ }
70
+ return lowerCasedUnit !== u;
71
+ });
72
+
73
+ if (lowerCasedUnit === one) {
74
+ base = number / conversion[lowerCasedUnit];
75
+ } else {
76
+ base = number * conversion[lowerCasedUnit];
77
+ }
81
78
 
82
- return value;
79
+ return convertionUnits.map(u => dropLeadingZero(base / conversion[u]) + u).reduce((a, b) => a.length < b.length ? a : b);
83
80
  }
84
81
 
85
- module.exports = exports.default;
82
+ module.exports = exports['default'];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "postcss-convert-values",
3
- "version": "4.0.0-nightly.2020.9.3",
3
+ "version": "4.0.0",
4
4
  "description": "Convert values with PostCSS (e.g. ms -> s)",
5
5
  "main": "dist/index.js",
6
6
  "files": [
@@ -8,9 +8,7 @@
8
8
  "dist"
9
9
  ],
10
10
  "scripts": {
11
- "prebuild": "",
12
- "build": "cross-env BABEL_ENV=publish babel src --config-file ../../babel.config.js --out-dir dist --ignore \"**/__tests__/\"",
13
- "prepublish": ""
11
+ "prepublish": "cross-env BABEL_ENV=publish babel src --out-dir dist --ignore /__tests__/"
14
12
  },
15
13
  "keywords": [
16
14
  "css",
@@ -19,6 +17,10 @@
19
17
  "postcss-plugin"
20
18
  ],
21
19
  "license": "MIT",
20
+ "devDependencies": {
21
+ "babel-cli": "^6.0.0",
22
+ "cross-env": "^5.0.0"
23
+ },
22
24
  "homepage": "https://github.com/cssnano/cssnano",
23
25
  "author": {
24
26
  "name": "Ben Briggs",
@@ -27,13 +29,13 @@
27
29
  },
28
30
  "repository": "cssnano/cssnano",
29
31
  "dependencies": {
30
- "postcss": "^7.0.16",
31
- "postcss-value-parser": "^3.3.1"
32
+ "postcss": "^6.0.0",
33
+ "postcss-value-parser": "^3.0.0"
32
34
  },
33
35
  "bugs": {
34
36
  "url": "https://github.com/cssnano/cssnano/issues"
35
37
  },
36
38
  "engines": {
37
- "node": ">=10.13.0"
39
+ "node": ">=6.9.0"
38
40
  }
39
- }
41
+ }