@docusaurus/cssnano-preset 2.0.0-beta.20 → 2.0.0-beta.22
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/lib/index.d.ts +9 -0
- package/lib/index.js +23 -0
- package/lib/remove-overridden-custom-properties/index.d.ts +25 -0
- package/lib/remove-overridden-custom-properties/index.js +40 -0
- package/package.json +14 -6
- package/src/deps.d.ts +11 -0
- package/src/index.ts +29 -0
- package/src/remove-overridden-custom-properties/{index.js → index.ts} +14 -11
- package/index.js +0 -25
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import advancedBasePreset from 'cssnano-preset-advanced';
|
|
8
|
+
declare const preset: typeof advancedBasePreset;
|
|
9
|
+
export = preset;
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
const tslib_1 = require("tslib");
|
|
9
|
+
const cssnano_preset_advanced_1 = tslib_1.__importDefault(require("cssnano-preset-advanced"));
|
|
10
|
+
const postcss_sort_media_queries_1 = tslib_1.__importDefault(require("postcss-sort-media-queries"));
|
|
11
|
+
const remove_overridden_custom_properties_1 = tslib_1.__importDefault(require("./remove-overridden-custom-properties"));
|
|
12
|
+
const preset = function preset(opts) {
|
|
13
|
+
const advancedPreset = (0, cssnano_preset_advanced_1.default)({
|
|
14
|
+
autoprefixer: { add: false },
|
|
15
|
+
discardComments: { removeAll: true },
|
|
16
|
+
/* cSpell:ignore zindex */
|
|
17
|
+
zindex: false,
|
|
18
|
+
...opts,
|
|
19
|
+
});
|
|
20
|
+
advancedPreset.plugins.unshift([postcss_sort_media_queries_1.default, undefined], [remove_overridden_custom_properties_1.default, undefined]);
|
|
21
|
+
return advancedPreset;
|
|
22
|
+
};
|
|
23
|
+
module.exports = preset;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import type { Plugin } from 'postcss';
|
|
8
|
+
/**
|
|
9
|
+
* This PostCSS plugin will remove duplicate/same custom properties (which are
|
|
10
|
+
* actually overridden ones) **only** from `:root` selector.
|
|
11
|
+
*
|
|
12
|
+
* Depending on the presence of an `!important` rule in value of custom
|
|
13
|
+
* property, the following actions will happen:
|
|
14
|
+
*
|
|
15
|
+
* - If the same custom properties do **not** have an `!important` rule, then
|
|
16
|
+
* all of them will be removed except for the last one (which will actually be
|
|
17
|
+
* applied).
|
|
18
|
+
* - If the same custom properties have at least one `!important` rule, then
|
|
19
|
+
* only those properties that do not have this rule will be removed.
|
|
20
|
+
*/
|
|
21
|
+
declare function creator(): Plugin;
|
|
22
|
+
declare namespace creator {
|
|
23
|
+
var postcss: true;
|
|
24
|
+
}
|
|
25
|
+
export default creator;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
const isRule = (node) => node?.type === 'rule';
|
|
10
|
+
/**
|
|
11
|
+
* This PostCSS plugin will remove duplicate/same custom properties (which are
|
|
12
|
+
* actually overridden ones) **only** from `:root` selector.
|
|
13
|
+
*
|
|
14
|
+
* Depending on the presence of an `!important` rule in value of custom
|
|
15
|
+
* property, the following actions will happen:
|
|
16
|
+
*
|
|
17
|
+
* - If the same custom properties do **not** have an `!important` rule, then
|
|
18
|
+
* all of them will be removed except for the last one (which will actually be
|
|
19
|
+
* applied).
|
|
20
|
+
* - If the same custom properties have at least one `!important` rule, then
|
|
21
|
+
* only those properties that do not have this rule will be removed.
|
|
22
|
+
*/
|
|
23
|
+
function creator() {
|
|
24
|
+
return {
|
|
25
|
+
postcssPlugin: 'postcss-remove-overridden-custom-properties',
|
|
26
|
+
Declaration(decl) {
|
|
27
|
+
if (!isRule(decl.parent) || decl.parent.selector !== ':root') {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
const sameProperties = decl.parent.nodes.filter((n) => 'prop' in n && n.prop === decl.prop);
|
|
31
|
+
const hasImportantProperties = sameProperties.some((p) => 'important' in p);
|
|
32
|
+
const overriddenProperties = hasImportantProperties
|
|
33
|
+
? sameProperties.filter((p) => !('important' in p))
|
|
34
|
+
: sameProperties.slice(0, -1);
|
|
35
|
+
overriddenProperties.map((p) => p.remove());
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
creator.postcss = true;
|
|
40
|
+
exports.default = creator;
|
package/package.json
CHANGED
|
@@ -1,24 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/cssnano-preset",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.22",
|
|
4
4
|
"description": "Advanced cssnano preset for maximum optimization.",
|
|
5
|
-
"main": "index.js",
|
|
5
|
+
"main": "lib/index.js",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"publishConfig": {
|
|
8
8
|
"access": "public"
|
|
9
9
|
},
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "tsc",
|
|
12
|
+
"watch": "tsc --watch"
|
|
13
|
+
},
|
|
10
14
|
"repository": {
|
|
11
15
|
"type": "git",
|
|
12
16
|
"url": "https://github.com/facebook/docusaurus.git",
|
|
13
17
|
"directory": "packages/docusaurus-cssnano-preset"
|
|
14
18
|
},
|
|
15
19
|
"dependencies": {
|
|
16
|
-
"cssnano-preset-advanced": "^5.3.
|
|
17
|
-
"postcss": "^8.4.
|
|
18
|
-
"postcss-sort-media-queries": "^4.2.1"
|
|
20
|
+
"cssnano-preset-advanced": "^5.3.8",
|
|
21
|
+
"postcss": "^8.4.14",
|
|
22
|
+
"postcss-sort-media-queries": "^4.2.1",
|
|
23
|
+
"tslib": "^2.4.0"
|
|
19
24
|
},
|
|
20
25
|
"devDependencies": {
|
|
21
26
|
"to-vfile": "^6.1.0"
|
|
22
27
|
},
|
|
23
|
-
"
|
|
28
|
+
"engines": {
|
|
29
|
+
"node": ">=16.14"
|
|
30
|
+
},
|
|
31
|
+
"gitHead": "daf9e462c4eebb7ac26a940932311f987e768f87"
|
|
24
32
|
}
|
package/src/deps.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
declare module 'postcss-sort-media-queries' {
|
|
9
|
+
const plugin: import('postcss').PluginCreator<object>;
|
|
10
|
+
export default plugin;
|
|
11
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import advancedBasePreset from 'cssnano-preset-advanced';
|
|
9
|
+
import postCssSortMediaQueries from 'postcss-sort-media-queries';
|
|
10
|
+
import postCssRemoveOverriddenCustomProperties from './remove-overridden-custom-properties';
|
|
11
|
+
|
|
12
|
+
const preset: typeof advancedBasePreset = function preset(opts) {
|
|
13
|
+
const advancedPreset = advancedBasePreset({
|
|
14
|
+
autoprefixer: {add: false},
|
|
15
|
+
discardComments: {removeAll: true},
|
|
16
|
+
/* cSpell:ignore zindex */
|
|
17
|
+
zindex: false,
|
|
18
|
+
...opts,
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
advancedPreset.plugins.unshift(
|
|
22
|
+
[postCssSortMediaQueries, undefined],
|
|
23
|
+
[postCssRemoveOverriddenCustomProperties, undefined],
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
return advancedPreset;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export = preset;
|
|
@@ -5,6 +5,10 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
+
import type {Plugin, Rule, Node} from 'postcss';
|
|
9
|
+
|
|
10
|
+
const isRule = (node: Node | undefined): node is Rule => node?.type === 'rule';
|
|
11
|
+
|
|
8
12
|
/**
|
|
9
13
|
* This PostCSS plugin will remove duplicate/same custom properties (which are
|
|
10
14
|
* actually overridden ones) **only** from `:root` selector.
|
|
@@ -17,32 +21,31 @@
|
|
|
17
21
|
* applied).
|
|
18
22
|
* - If the same custom properties have at least one `!important` rule, then
|
|
19
23
|
* only those properties that do not have this rule will be removed.
|
|
20
|
-
* @returns {import('postcss').Plugin}
|
|
21
24
|
*/
|
|
22
|
-
|
|
25
|
+
function creator(): Plugin {
|
|
23
26
|
return {
|
|
24
27
|
postcssPlugin: 'postcss-remove-overridden-custom-properties',
|
|
25
28
|
Declaration(decl) {
|
|
26
|
-
if (decl.parent.selector !== ':root') {
|
|
29
|
+
if (!isRule(decl.parent) || decl.parent.selector !== ':root') {
|
|
27
30
|
return;
|
|
28
31
|
}
|
|
29
32
|
|
|
30
33
|
const sameProperties = decl.parent.nodes.filter(
|
|
31
|
-
(n) => n.prop === decl.prop,
|
|
34
|
+
(n) => 'prop' in n && n.prop === decl.prop,
|
|
32
35
|
);
|
|
33
|
-
const hasImportantProperties = sameProperties.some(
|
|
34
|
-
|
|
36
|
+
const hasImportantProperties = sameProperties.some(
|
|
37
|
+
(p) => 'important' in p,
|
|
35
38
|
);
|
|
36
39
|
|
|
37
40
|
const overriddenProperties = hasImportantProperties
|
|
38
|
-
? sameProperties.filter(
|
|
39
|
-
(p) => !Object.prototype.hasOwnProperty.call(p, 'important'),
|
|
40
|
-
)
|
|
41
|
+
? sameProperties.filter((p) => !('important' in p))
|
|
41
42
|
: sameProperties.slice(0, -1);
|
|
42
43
|
|
|
43
44
|
overriddenProperties.map((p) => p.remove());
|
|
44
45
|
},
|
|
45
46
|
};
|
|
46
|
-
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
creator.postcss = true as const;
|
|
47
50
|
|
|
48
|
-
|
|
51
|
+
export default creator;
|
package/index.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
const advancedBasePreset = require('cssnano-preset-advanced');
|
|
9
|
-
const postCssSortMediaQueries = require('postcss-sort-media-queries');
|
|
10
|
-
const postCssRemoveOverriddenCustomProperties = require('./src/remove-overridden-custom-properties');
|
|
11
|
-
|
|
12
|
-
module.exports = function docusaurusCssnanoPreset(opts) {
|
|
13
|
-
const advancedPreset = advancedBasePreset({
|
|
14
|
-
autoprefixer: {add: false},
|
|
15
|
-
discardComments: {removeAll: true},
|
|
16
|
-
...opts,
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
advancedPreset.plugins.unshift(
|
|
20
|
-
[postCssSortMediaQueries],
|
|
21
|
-
[postCssRemoveOverriddenCustomProperties],
|
|
22
|
-
);
|
|
23
|
-
|
|
24
|
-
return advancedPreset;
|
|
25
|
-
};
|