postcss-normalize-timing-functions 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 +3 -7
- package/src/index.js +133 -0
- package/dist/index.js +0 -106
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "postcss-normalize-timing-functions",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.3",
|
|
4
4
|
"description": "Normalize CSS animation/transition timing functions.",
|
|
5
|
-
"main": "
|
|
5
|
+
"main": "src/index.js",
|
|
6
6
|
"files": [
|
|
7
7
|
"LICENSE-MIT",
|
|
8
|
-
"
|
|
8
|
+
"src"
|
|
9
9
|
],
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
@@ -30,9 +30,5 @@
|
|
|
30
30
|
"peerDependencies": {
|
|
31
31
|
"postcss": "^8.2.15"
|
|
32
32
|
},
|
|
33
|
-
"scripts": {
|
|
34
|
-
"prebuild": "rimraf dist",
|
|
35
|
-
"build": "babel src --config-file ../../babel.config.json --out-dir dist --ignore \"**/__tests__/\""
|
|
36
|
-
},
|
|
37
33
|
"readme": "# [postcss][postcss]-normalize-timing-functions\n\n> Normalize timing functions with PostCSS.\n\n## Install\n\nWith [npm](https://npmjs.org/package/postcss-normalize-timing-functions) do:\n\n```\nnpm install postcss-normalize-timing-functions --save\n```\n\n## Example\n\n### Input\n\n```css\ndiv {\n animate: fade 3s cubic-bezier(0.42, 0, 1, 1)\n}\n```\n\n### Output\n\n```css\ndiv {\n animate: fade 3s ease-in\n}\n``` \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\nMIT © [Ben Briggs](http://beneb.info)\n\n[postcss]: https://github.com/postcss/postcss\n"
|
|
38
34
|
}
|
package/src/index.js
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const valueParser = require('postcss-value-parser');
|
|
3
|
+
|
|
4
|
+
const getValue = (node) => parseFloat(node.value);
|
|
5
|
+
|
|
6
|
+
/* Works because toString() normalizes the formatting,
|
|
7
|
+
so comparing the string forms behaves the same as number equality*/
|
|
8
|
+
const conversions = new Map([
|
|
9
|
+
[[0.25, 0.1, 0.25, 1].toString(), 'ease'],
|
|
10
|
+
[[0, 0, 1, 1].toString(), 'linear'],
|
|
11
|
+
[[0.42, 0, 1, 1].toString(), 'ease-in'],
|
|
12
|
+
[[0, 0, 0.58, 1].toString(), 'ease-out'],
|
|
13
|
+
[[0.42, 0, 0.58, 1].toString(), 'ease-in-out'],
|
|
14
|
+
]);
|
|
15
|
+
function reduce(node) {
|
|
16
|
+
if (node.type !== 'function') {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (!node.value) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const lowerCasedValue = node.value.toLowerCase();
|
|
25
|
+
|
|
26
|
+
if (lowerCasedValue === 'steps') {
|
|
27
|
+
// Don't bother checking the step-end case as it has the same length
|
|
28
|
+
// as steps(1)
|
|
29
|
+
if (
|
|
30
|
+
node.nodes[0].type === 'word' &&
|
|
31
|
+
getValue(node.nodes[0]) === 1 &&
|
|
32
|
+
node.nodes[2] &&
|
|
33
|
+
node.nodes[2].type === 'word' &&
|
|
34
|
+
(node.nodes[2].value.toLowerCase() === 'start' ||
|
|
35
|
+
node.nodes[2].value.toLowerCase() === 'jump-start')
|
|
36
|
+
) {
|
|
37
|
+
node.type = 'word';
|
|
38
|
+
node.value = 'step-start';
|
|
39
|
+
|
|
40
|
+
delete node.nodes;
|
|
41
|
+
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (
|
|
46
|
+
node.nodes[0].type === 'word' &&
|
|
47
|
+
getValue(node.nodes[0]) === 1 &&
|
|
48
|
+
node.nodes[2] &&
|
|
49
|
+
node.nodes[2].type === 'word' &&
|
|
50
|
+
(node.nodes[2].value.toLowerCase() === 'end' ||
|
|
51
|
+
node.nodes[2].value.toLowerCase() === 'jump-end')
|
|
52
|
+
) {
|
|
53
|
+
node.type = 'word';
|
|
54
|
+
node.value = 'step-end';
|
|
55
|
+
|
|
56
|
+
delete node.nodes;
|
|
57
|
+
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// The end case is actually the browser default, so it isn't required.
|
|
62
|
+
if (
|
|
63
|
+
node.nodes[2] &&
|
|
64
|
+
node.nodes[2].type === 'word' &&
|
|
65
|
+
(node.nodes[2].value.toLowerCase() === 'end' ||
|
|
66
|
+
node.nodes[2].value.toLowerCase() === 'jump-end')
|
|
67
|
+
) {
|
|
68
|
+
node.nodes = [node.nodes[0]];
|
|
69
|
+
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (lowerCasedValue === 'cubic-bezier') {
|
|
77
|
+
const values = node.nodes
|
|
78
|
+
.filter((list, index) => {
|
|
79
|
+
return index % 2 === 0;
|
|
80
|
+
})
|
|
81
|
+
.map(getValue);
|
|
82
|
+
|
|
83
|
+
if (values.length !== 4) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const match = conversions.get(values.toString());
|
|
88
|
+
|
|
89
|
+
if (match) {
|
|
90
|
+
node.type = 'word';
|
|
91
|
+
node.value = match;
|
|
92
|
+
|
|
93
|
+
delete node.nodes;
|
|
94
|
+
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function transform(value) {
|
|
101
|
+
return valueParser(value).walk(reduce).toString();
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function pluginCreator() {
|
|
105
|
+
return {
|
|
106
|
+
postcssPlugin: 'postcss-normalize-timing-functions',
|
|
107
|
+
|
|
108
|
+
OnceExit(css) {
|
|
109
|
+
const cache = new Map();
|
|
110
|
+
|
|
111
|
+
css.walkDecls(
|
|
112
|
+
/^(-\w+-)?(animation|transition)(-timing-function)?$/i,
|
|
113
|
+
(decl) => {
|
|
114
|
+
const value = decl.value;
|
|
115
|
+
|
|
116
|
+
if (cache.has(value)) {
|
|
117
|
+
decl.value = cache.get(value);
|
|
118
|
+
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const result = transform(value);
|
|
123
|
+
|
|
124
|
+
decl.value = result;
|
|
125
|
+
cache.set(value, result);
|
|
126
|
+
}
|
|
127
|
+
);
|
|
128
|
+
},
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
pluginCreator.postcss = true;
|
|
133
|
+
module.exports = pluginCreator;
|
package/dist/index.js
DELETED
|
@@ -1,106 +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
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
|
|
12
|
-
const getValue = node => parseFloat(node.value);
|
|
13
|
-
/* Works because toString() normalizes the formatting,
|
|
14
|
-
so comparing the string forms behaves the same as number equality*/
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const conversions = new Map([[[0.25, 0.1, 0.25, 1].toString(), 'ease'], [[0, 0, 1, 1].toString(), 'linear'], [[0.42, 0, 1, 1].toString(), 'ease-in'], [[0, 0, 0.58, 1].toString(), 'ease-out'], [[0.42, 0, 0.58, 1].toString(), 'ease-in-out']]);
|
|
18
|
-
|
|
19
|
-
function reduce(node) {
|
|
20
|
-
if (node.type !== 'function') {
|
|
21
|
-
return false;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
if (!node.value) {
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const lowerCasedValue = node.value.toLowerCase();
|
|
29
|
-
|
|
30
|
-
if (lowerCasedValue === 'steps') {
|
|
31
|
-
// Don't bother checking the step-end case as it has the same length
|
|
32
|
-
// as steps(1)
|
|
33
|
-
if (node.nodes[0].type === 'word' && getValue(node.nodes[0]) === 1 && node.nodes[2] && node.nodes[2].type === 'word' && (node.nodes[2].value.toLowerCase() === 'start' || node.nodes[2].value.toLowerCase() === 'jump-start')) {
|
|
34
|
-
node.type = 'word';
|
|
35
|
-
node.value = 'step-start';
|
|
36
|
-
delete node.nodes;
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
if (node.nodes[0].type === 'word' && getValue(node.nodes[0]) === 1 && node.nodes[2] && node.nodes[2].type === 'word' && (node.nodes[2].value.toLowerCase() === 'end' || node.nodes[2].value.toLowerCase() === 'jump-end')) {
|
|
41
|
-
node.type = 'word';
|
|
42
|
-
node.value = 'step-end';
|
|
43
|
-
delete node.nodes;
|
|
44
|
-
return;
|
|
45
|
-
} // The end case is actually the browser default, so it isn't required.
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
if (node.nodes[2] && node.nodes[2].type === 'word' && (node.nodes[2].value.toLowerCase() === 'end' || node.nodes[2].value.toLowerCase() === 'jump-end')) {
|
|
49
|
-
node.nodes = [node.nodes[0]];
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
return false;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
if (lowerCasedValue === 'cubic-bezier') {
|
|
57
|
-
const values = node.nodes.filter((list, index) => {
|
|
58
|
-
return index % 2 === 0;
|
|
59
|
-
}).map(getValue);
|
|
60
|
-
|
|
61
|
-
if (values.length !== 4) {
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const match = conversions.get(values.toString());
|
|
66
|
-
|
|
67
|
-
if (match) {
|
|
68
|
-
node.type = 'word';
|
|
69
|
-
node.value = match;
|
|
70
|
-
delete node.nodes;
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
function transform(value) {
|
|
77
|
-
return (0, _postcssValueParser.default)(value).walk(reduce).toString();
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
function pluginCreator() {
|
|
81
|
-
return {
|
|
82
|
-
postcssPlugin: 'postcss-normalize-timing-functions',
|
|
83
|
-
|
|
84
|
-
OnceExit(css) {
|
|
85
|
-
const cache = new Map();
|
|
86
|
-
css.walkDecls(/^(-\w+-)?(animation|transition)(-timing-function)?$/i, decl => {
|
|
87
|
-
const value = decl.value;
|
|
88
|
-
|
|
89
|
-
if (cache.has(value)) {
|
|
90
|
-
decl.value = cache.get(value);
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
const result = transform(value);
|
|
95
|
-
decl.value = result;
|
|
96
|
-
cache.set(value, result);
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
pluginCreator.postcss = true;
|
|
104
|
-
var _default = pluginCreator;
|
|
105
|
-
exports.default = _default;
|
|
106
|
-
module.exports = exports.default;
|