postcss-reduce-initial 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/package.json +9 -11
- package/src/index.js +62 -0
- package/dist/index.js +0 -66
package/package.json
CHANGED
|
@@ -1,19 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "postcss-reduce-initial",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.3",
|
|
4
4
|
"description": "Reduce initial definitions to the actual initial value, where possible.",
|
|
5
|
-
"main": "
|
|
5
|
+
"main": "src/index.js",
|
|
6
6
|
"files": [
|
|
7
7
|
"data",
|
|
8
|
-
"
|
|
8
|
+
"src/index.js",
|
|
9
9
|
"LICENSE-MIT"
|
|
10
10
|
],
|
|
11
|
-
"scripts": {
|
|
12
|
-
"acquire": "node ./src/script/acquire.mjs",
|
|
13
|
-
"prebuild": "rimraf dist",
|
|
14
|
-
"build": "babel src --config-file ../../babel.config.json --out-dir dist --ignore \"**/__tests__\"",
|
|
15
|
-
"prepare": "yarn build"
|
|
16
|
-
},
|
|
17
11
|
"keywords": [
|
|
18
12
|
"css",
|
|
19
13
|
"postcss",
|
|
@@ -42,5 +36,9 @@
|
|
|
42
36
|
},
|
|
43
37
|
"peerDependencies": {
|
|
44
38
|
"postcss": "^8.2.15"
|
|
45
|
-
}
|
|
46
|
-
|
|
39
|
+
},
|
|
40
|
+
"scripts": {
|
|
41
|
+
"acquire": "node ./src/script/acquire.mjs"
|
|
42
|
+
},
|
|
43
|
+
"readme": "# [postcss][postcss]-reduce-initial\n\n> Reduce `initial` definitions to the _actual_ initial value, where possible.\n\n## Install\n\nWith [npm](https://npmjs.org/package/postcss-reduce-initial) do:\n\n```\nnpm install postcss-reduce-initial --save\n```\n\n## Examples\n\nSee the [data](data) for more conversions. This data is courtesy\nof Mozilla.\n\n### Convert `initial` values\n\nWhen the `initial` keyword is longer than the property value, it will\nbe converted:\n\n#### Input\n\n```css\nh1 {\n min-width: initial;\n}\n```\n\n#### Output\n\n```css\nh1 {\n min-width: 0;\n}\n```\n\n### Convert values back to `initial`\n\nWhen the `initial` value is smaller than the property value, it will\nbe converted:\n\n#### Input\n\n```css\nh1 {\n transform-box: border-box;\n}\n```\n\n#### Output\n\n```css\nh1 {\n transform-box: initial;\n}\n```\n\nThis conversion is only applied when you supply a browsers list that all support\nthe `initial` keyword; it's worth noting that Internet Explorer has no support.\n\n## API\n\n### reduceInitial([options])\n\n#### options\n\n##### ignore\n\nType: `Array<String>`\nDefault: `undefined`\n\nIt contains the Array of properties that will be ignored while reducing its value to initial.\nExample : `{ ignore : [\"min-height\"] }`\n\n## Usage\n\nSee the [PostCSS documentation](https://github.com/postcss/postcss#usage) for\nexamples for your environment.\n\n## Contributors\n\nSee [CONTRIBUTORS.md](https://github.com/cssnano/cssnano/blob/master/CONTRIBUTORS.md).\n\n## License\n\n[Template:CSSData] by Mozilla Contributors is licensed under [CC-BY-SA 2.5].\n\n[template:cssdata]: https://developer.mozilla.org/en-US/docs/Template:CSSData\n[cc-by-sa 2.5]: http://creativecommons.org/licenses/by-sa/2.5/\n\nMIT © [Ben Briggs](http://beneb.info)\n\n[postcss]: https://github.com/postcss/postcss\n"
|
|
44
|
+
}
|
package/src/index.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const browserslist = require('browserslist');
|
|
3
|
+
const { isSupported } = require('caniuse-api');
|
|
4
|
+
const fromInitial = require('../data/fromInitial.json');
|
|
5
|
+
const toInitial = require('../data/toInitial.json');
|
|
6
|
+
|
|
7
|
+
const initial = 'initial';
|
|
8
|
+
|
|
9
|
+
// In most of the browser including chrome the initial for `writing-mode` is not `horizontal-tb`. Ref https://github.com/cssnano/cssnano/pull/905
|
|
10
|
+
const defaultIgnoreProps = ['writing-mode', 'transform-box'];
|
|
11
|
+
|
|
12
|
+
function pluginCreator() {
|
|
13
|
+
return {
|
|
14
|
+
postcssPlugin: 'postcss-reduce-initial',
|
|
15
|
+
|
|
16
|
+
prepare(result) {
|
|
17
|
+
const resultOpts = result.opts || {};
|
|
18
|
+
const browsers = browserslist(null, {
|
|
19
|
+
stats: resultOpts.stats,
|
|
20
|
+
path: __dirname,
|
|
21
|
+
env: resultOpts.env,
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
const initialSupport = isSupported('css-initial-value', browsers);
|
|
25
|
+
return {
|
|
26
|
+
OnceExit(css) {
|
|
27
|
+
css.walkDecls((decl) => {
|
|
28
|
+
const lowerCasedProp = decl.prop.toLowerCase();
|
|
29
|
+
const ignoreProp = new Set(
|
|
30
|
+
defaultIgnoreProps.concat(resultOpts.ignore || [])
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
if (ignoreProp.has(lowerCasedProp)) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (
|
|
38
|
+
initialSupport &&
|
|
39
|
+
Object.prototype.hasOwnProperty.call(toInitial, lowerCasedProp) &&
|
|
40
|
+
decl.value.toLowerCase() === toInitial[lowerCasedProp]
|
|
41
|
+
) {
|
|
42
|
+
decl.value = initial;
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (
|
|
47
|
+
decl.value.toLowerCase() !== initial ||
|
|
48
|
+
!fromInitial[lowerCasedProp]
|
|
49
|
+
) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
decl.value = fromInitial[lowerCasedProp];
|
|
54
|
+
});
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
pluginCreator.postcss = true;
|
|
62
|
+
module.exports = pluginCreator;
|
package/dist/index.js
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _browserslist = _interopRequireDefault(require("browserslist"));
|
|
9
|
-
|
|
10
|
-
var _caniuseApi = require("caniuse-api");
|
|
11
|
-
|
|
12
|
-
var _fromInitial = _interopRequireDefault(require("../data/fromInitial.json"));
|
|
13
|
-
|
|
14
|
-
var _toInitial = _interopRequireDefault(require("../data/toInitial.json"));
|
|
15
|
-
|
|
16
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
|
-
|
|
18
|
-
const initial = 'initial'; // In most of the browser including chrome the initial for `writing-mode` is not `horizontal-tb`. Ref https://github.com/cssnano/cssnano/pull/905
|
|
19
|
-
|
|
20
|
-
const defaultIgnoreProps = ['writing-mode', 'transform-box'];
|
|
21
|
-
|
|
22
|
-
function pluginCreator() {
|
|
23
|
-
return {
|
|
24
|
-
postcssPlugin: 'postcss-reduce-initial',
|
|
25
|
-
|
|
26
|
-
prepare(result) {
|
|
27
|
-
const resultOpts = result.opts || {};
|
|
28
|
-
const browsers = (0, _browserslist.default)(null, {
|
|
29
|
-
stats: resultOpts.stats,
|
|
30
|
-
path: __dirname,
|
|
31
|
-
env: resultOpts.env
|
|
32
|
-
});
|
|
33
|
-
const initialSupport = (0, _caniuseApi.isSupported)('css-initial-value', browsers);
|
|
34
|
-
return {
|
|
35
|
-
OnceExit(css) {
|
|
36
|
-
css.walkDecls(decl => {
|
|
37
|
-
const lowerCasedProp = decl.prop.toLowerCase();
|
|
38
|
-
const ignoreProp = new Set(defaultIgnoreProps.concat(resultOpts.ignore || []));
|
|
39
|
-
|
|
40
|
-
if (ignoreProp.has(lowerCasedProp)) {
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
if (initialSupport && Object.prototype.hasOwnProperty.call(_toInitial.default, lowerCasedProp) && decl.value.toLowerCase() === _toInitial.default[lowerCasedProp]) {
|
|
45
|
-
decl.value = initial;
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
if (decl.value.toLowerCase() !== initial || !_fromInitial.default[lowerCasedProp]) {
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
decl.value = _fromInitial.default[lowerCasedProp];
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
pluginCreator.postcss = true;
|
|
64
|
-
var _default = pluginCreator;
|
|
65
|
-
exports.default = _default;
|
|
66
|
-
module.exports = exports.default;
|