postcss-merge-idents 5.0.1 → 5.1.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/package.json +10 -13
- package/src/index.js +146 -0
- package/types/index.d.ts +9 -0
- package/CHANGELOG.md +0 -69
- package/dist/index.js +0 -103
package/package.json
CHANGED
|
@@ -1,17 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "postcss-merge-idents",
|
|
3
|
-
"version": "5.0
|
|
3
|
+
"version": "5.1.0",
|
|
4
4
|
"description": "Merge keyframe and counter style identifiers.",
|
|
5
|
-
"main": "
|
|
5
|
+
"main": "src/index.js",
|
|
6
|
+
"types": "types/index.d.ts",
|
|
6
7
|
"files": [
|
|
7
|
-
"
|
|
8
|
-
"LICENSE-MIT"
|
|
8
|
+
"src",
|
|
9
|
+
"LICENSE-MIT",
|
|
10
|
+
"types"
|
|
9
11
|
],
|
|
10
|
-
"scripts": {
|
|
11
|
-
"prebuild": "del-cli dist",
|
|
12
|
-
"build": "cross-env BABEL_ENV=publish babel src --config-file ../../babel.config.json --out-dir dist --ignore \"**/__tests__/\"",
|
|
13
|
-
"prepublish": "yarn build"
|
|
14
|
-
},
|
|
15
12
|
"keywords": [
|
|
16
13
|
"css",
|
|
17
14
|
"merge",
|
|
@@ -27,8 +24,8 @@
|
|
|
27
24
|
},
|
|
28
25
|
"repository": "cssnano/cssnano",
|
|
29
26
|
"dependencies": {
|
|
30
|
-
"cssnano-utils": "^
|
|
31
|
-
"postcss-value-parser": "^4.
|
|
27
|
+
"cssnano-utils": "^3.1.0",
|
|
28
|
+
"postcss-value-parser": "^4.2.0"
|
|
32
29
|
},
|
|
33
30
|
"bugs": {
|
|
34
31
|
"url": "https://github.com/cssnano/cssnano/issues"
|
|
@@ -42,5 +39,5 @@
|
|
|
42
39
|
"peerDependencies": {
|
|
43
40
|
"postcss": "^8.2.15"
|
|
44
41
|
},
|
|
45
|
-
"
|
|
46
|
-
}
|
|
42
|
+
"readme": "# [postcss][postcss]-merge-idents\n\n> Merge keyframe and counter style identifiers.\n\n\n## Install\n\nWith [npm](https://npmjs.org/package/postcss-merge-idents) do:\n\n```\nnpm install postcss-merge-idents --save\n```\n\n\n## Example\n\nThis module will merge identifiers such as `@keyframes` and `@counter-style`,\nif their properties are identical. Then, it will update those declarations that\ndepend on the duplicated property.\n\n### Input\n\n```css\n@keyframes rotate {\n from { transform: rotate(0) }\n to { transform: rotate(360deg) }\n}\n\n@keyframes flip {\n from { transform: rotate(0) }\n to { transform: rotate(360deg) }\n}\n\n.rotate {\n animation-name: rotate\n}\n\n.flip {\n animation-name: flip\n}\n```\n\n### Output\n\n```css\n@keyframes flip {\n from { transform: rotate(0) }\n to { transform: rotate(360deg) }\n}\n\n.rotate {\n animation-name: flip\n}\n\n.flip {\n animation-name: flip\n}\n```\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"
|
|
43
|
+
}
|
package/src/index.js
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const valueParser = require('postcss-value-parser');
|
|
3
|
+
const { sameParent } = require('cssnano-utils');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @param {Record<string, string>} obj
|
|
7
|
+
* @return {(key: string) => string}
|
|
8
|
+
*/
|
|
9
|
+
function canonical(obj) {
|
|
10
|
+
// Prevent potential infinite loops
|
|
11
|
+
let stack = 50;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @param {string} key
|
|
15
|
+
* @return {string}
|
|
16
|
+
*/
|
|
17
|
+
return function recurse(key) {
|
|
18
|
+
if (
|
|
19
|
+
Object.prototype.hasOwnProperty.call(obj, key) &&
|
|
20
|
+
obj[key] !== key &&
|
|
21
|
+
stack
|
|
22
|
+
) {
|
|
23
|
+
stack--;
|
|
24
|
+
|
|
25
|
+
return recurse(obj[key]);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
stack = 50;
|
|
29
|
+
|
|
30
|
+
return key;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* @param {import('postcss').Root} css
|
|
36
|
+
* @return {void}
|
|
37
|
+
*/
|
|
38
|
+
function mergeAtRules(css) {
|
|
39
|
+
const pairs = [
|
|
40
|
+
{
|
|
41
|
+
atrule: /keyframes/i,
|
|
42
|
+
decl: /animation/i,
|
|
43
|
+
/** @type {import('postcss').AtRule[]} */
|
|
44
|
+
cache: [],
|
|
45
|
+
replacements: {},
|
|
46
|
+
/** @type {import('postcss').Declaration[]} */
|
|
47
|
+
decls: [],
|
|
48
|
+
/** @type {import('postcss').AtRule[]} */
|
|
49
|
+
removals: [],
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
atrule: /counter-style/i,
|
|
53
|
+
decl: /(list-style|system)/i,
|
|
54
|
+
cache: [],
|
|
55
|
+
replacements: {},
|
|
56
|
+
decls: [],
|
|
57
|
+
removals: [],
|
|
58
|
+
},
|
|
59
|
+
];
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* @type {{atrule: RegExp, decl: RegExp, replacements: Record<string, string>, removals: import('postcss').AtRule[], cache: import('postcss').AtRule[], decls: import('postcss').Declaration[]}}
|
|
63
|
+
*/
|
|
64
|
+
let relevant;
|
|
65
|
+
|
|
66
|
+
css.walk((node) => {
|
|
67
|
+
if (node.type === 'atrule') {
|
|
68
|
+
relevant = pairs.filter((pair) =>
|
|
69
|
+
pair.atrule.test(node.name.toLowerCase())
|
|
70
|
+
)[0];
|
|
71
|
+
|
|
72
|
+
if (!relevant) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (relevant.cache.length < 1) {
|
|
77
|
+
relevant.cache.push(node);
|
|
78
|
+
return;
|
|
79
|
+
} else {
|
|
80
|
+
let toString = node.nodes.toString();
|
|
81
|
+
|
|
82
|
+
relevant.cache.forEach((cached) => {
|
|
83
|
+
if (
|
|
84
|
+
cached.name.toLowerCase() === node.name.toLowerCase() &&
|
|
85
|
+
sameParent(
|
|
86
|
+
/** @type {any} */ (cached),
|
|
87
|
+
/** @type {any} */ (node)
|
|
88
|
+
) &&
|
|
89
|
+
cached.nodes.toString() === toString
|
|
90
|
+
) {
|
|
91
|
+
relevant.removals.push(cached);
|
|
92
|
+
relevant.replacements[cached.params] = node.params;
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
relevant.cache.push(node);
|
|
97
|
+
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (node.type === 'decl') {
|
|
103
|
+
relevant = pairs.filter((pair) =>
|
|
104
|
+
pair.decl.test(node.prop.toLowerCase())
|
|
105
|
+
)[0];
|
|
106
|
+
|
|
107
|
+
if (!relevant) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
relevant.decls.push(node);
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
pairs.forEach((pair) => {
|
|
116
|
+
let canon = canonical(pair.replacements);
|
|
117
|
+
|
|
118
|
+
pair.decls.forEach((decl) => {
|
|
119
|
+
decl.value = valueParser(decl.value)
|
|
120
|
+
.walk((node) => {
|
|
121
|
+
if (node.type === 'word') {
|
|
122
|
+
node.value = canon(node.value);
|
|
123
|
+
}
|
|
124
|
+
})
|
|
125
|
+
.toString();
|
|
126
|
+
});
|
|
127
|
+
pair.removals.forEach((cached) => cached.remove());
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* @type {import('postcss').PluginCreator<void>}
|
|
133
|
+
* @return {import('postcss').Plugin}
|
|
134
|
+
*/
|
|
135
|
+
function pluginCreator() {
|
|
136
|
+
return {
|
|
137
|
+
postcssPlugin: 'postcss-merge-idents',
|
|
138
|
+
|
|
139
|
+
OnceExit(css) {
|
|
140
|
+
mergeAtRules(css);
|
|
141
|
+
},
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
pluginCreator.postcss = true;
|
|
146
|
+
module.exports = pluginCreator;
|
package/types/index.d.ts
ADDED
package/CHANGELOG.md
DELETED
|
@@ -1,69 +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.1](https://github.com/cssnano/cssnano/compare/postcss-merge-idents@5.0.0...postcss-merge-idents@5.0.1) (2021-05-19)
|
|
7
|
-
|
|
8
|
-
**Note:** Version bump only for package postcss-merge-idents
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
# [5.0.0](https://github.com/cssnano/cssnano/compare/postcss-merge-idents@5.0.0-rc.2...postcss-merge-idents@5.0.0) (2021-04-06)
|
|
15
|
-
|
|
16
|
-
**Note:** Version bump only for package postcss-merge-idents
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
# [5.0.0-rc.2](https://github.com/cssnano/cssnano/compare/postcss-merge-idents@5.0.0-rc.1...postcss-merge-idents@5.0.0-rc.2) (2021-03-15)
|
|
23
|
-
|
|
24
|
-
**Note:** Version bump only for package postcss-merge-idents
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
# [5.0.0-rc.1](https://github.com/cssnano/cssnano/compare/postcss-merge-idents@5.0.0-rc.0...postcss-merge-idents@5.0.0-rc.1) (2021-03-04)
|
|
31
|
-
|
|
32
|
-
**Note:** Version bump only for package postcss-merge-idents
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
# 5.0.0-rc.0 (2021-02-19)
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
### Bug Fixes
|
|
42
|
-
|
|
43
|
-
* **merge-rules, merge-idents:** add support for nested at-rules ([#719](https://github.com/cssnano/cssnano/issues/719)) ([cdedda7](https://github.com/cssnano/cssnano/commit/cdedda7f9d67873d872add044ad34c91616579f3))
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
### chore
|
|
47
|
-
|
|
48
|
-
* minimum require version of node is 10.13 ([#871](https://github.com/cssnano/cssnano/issues/871)) ([28bda24](https://github.com/cssnano/cssnano/commit/28bda243e32ce3ba89b3c358a5f78727b3732f11))
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
### Features
|
|
52
|
-
|
|
53
|
-
* migarete to PostCSS 8 ([#975](https://github.com/cssnano/cssnano/issues/975)) ([40b82dc](https://github.com/cssnano/cssnano/commit/40b82dca7f53ac02cd4fe62846dec79b898ccb49))
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
### BREAKING CHANGES
|
|
57
|
-
|
|
58
|
-
* minimum supported `postcss` version is `8.2.1`
|
|
59
|
-
* minimum require version of node is 10.13
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
## 4.1.1 (2018-09-24)
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
### Bug Fixes
|
|
67
|
-
|
|
68
|
-
* better handle uppercase atrule and properties in `postcss-merge-idents` ([#610](https://github.com/cssnano/cssnano/issues/610)) ([d177936](https://github.com/cssnano/cssnano/commit/d177936b2656ad286490bedc3c4ab9773a63e5bc))
|
|
69
|
-
* **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)
|
package/dist/index.js
DELETED
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _postcssValueParser = _interopRequireDefault(require("postcss-value-parser"));
|
|
9
|
-
|
|
10
|
-
var _cssnanoUtils = require("cssnano-utils");
|
|
11
|
-
|
|
12
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
|
|
14
|
-
function canonical(obj) {
|
|
15
|
-
// Prevent potential infinite loops
|
|
16
|
-
let stack = 50;
|
|
17
|
-
return function recurse(key) {
|
|
18
|
-
if (Object.prototype.hasOwnProperty.call(obj, key) && obj[key] !== key && stack) {
|
|
19
|
-
stack--;
|
|
20
|
-
return recurse(obj[key]);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
stack = 50;
|
|
24
|
-
return key;
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function mergeAtRules(css, pairs) {
|
|
29
|
-
pairs.forEach(pair => {
|
|
30
|
-
pair.cache = [];
|
|
31
|
-
pair.replacements = [];
|
|
32
|
-
pair.decls = [];
|
|
33
|
-
pair.removals = [];
|
|
34
|
-
});
|
|
35
|
-
let relevant;
|
|
36
|
-
css.walk(node => {
|
|
37
|
-
if (node.type === 'atrule') {
|
|
38
|
-
relevant = pairs.filter(pair => pair.atrule.test(node.name.toLowerCase()))[0];
|
|
39
|
-
|
|
40
|
-
if (!relevant) {
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
if (relevant.cache.length < 1) {
|
|
45
|
-
relevant.cache.push(node);
|
|
46
|
-
return;
|
|
47
|
-
} else {
|
|
48
|
-
let toString = node.nodes.toString();
|
|
49
|
-
relevant.cache.forEach(cached => {
|
|
50
|
-
if (cached.name.toLowerCase() === node.name.toLowerCase() && (0, _cssnanoUtils.sameParent)(cached, node) && cached.nodes.toString() === toString) {
|
|
51
|
-
relevant.removals.push(cached);
|
|
52
|
-
relevant.replacements[cached.params] = node.params;
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
relevant.cache.push(node);
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
if (node.type === 'decl') {
|
|
61
|
-
relevant = pairs.filter(pair => pair.decl.test(node.prop.toLowerCase()))[0];
|
|
62
|
-
|
|
63
|
-
if (!relevant) {
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
relevant.decls.push(node);
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
pairs.forEach(pair => {
|
|
71
|
-
let canon = canonical(pair.replacements);
|
|
72
|
-
pair.decls.forEach(decl => {
|
|
73
|
-
decl.value = (0, _postcssValueParser.default)(decl.value).walk(node => {
|
|
74
|
-
if (node.type === 'word') {
|
|
75
|
-
node.value = canon(node.value);
|
|
76
|
-
}
|
|
77
|
-
}).toString();
|
|
78
|
-
});
|
|
79
|
-
pair.removals.forEach(cached => cached.remove());
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
function pluginCreator() {
|
|
84
|
-
return {
|
|
85
|
-
postcssPlugin: 'postcss-merge-idents',
|
|
86
|
-
|
|
87
|
-
OnceExit(css) {
|
|
88
|
-
mergeAtRules(css, [{
|
|
89
|
-
atrule: /keyframes/i,
|
|
90
|
-
decl: /animation/i
|
|
91
|
-
}, {
|
|
92
|
-
atrule: /counter-style/i,
|
|
93
|
-
decl: /(list-style|system)/i
|
|
94
|
-
}]);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
pluginCreator.postcss = true;
|
|
101
|
-
var _default = pluginCreator;
|
|
102
|
-
exports.default = _default;
|
|
103
|
-
module.exports = exports.default;
|