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'];
|
---|
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 = defaultIgnoreProps.concat(resultOpts.ignore || []);
|
---|
39 |
|
---|
40 | if (ignoreProp.includes(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; |
---|