postcss-normalize-timing-functions 8.0.1 → 8.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/LICENSE-MIT +1 -1
- package/README.md +1 -1
- package/package.json +21 -7
- package/src/index.js +90 -78
- package/types/index.d.ts +2 -9
- package/types/index.d.ts.map +1 -1
package/LICENSE-MIT
CHANGED
package/README.md
CHANGED
package/package.json
CHANGED
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "postcss-normalize-timing-functions",
|
|
3
|
-
"version": "8.0.
|
|
3
|
+
"version": "8.0.3",
|
|
4
4
|
"description": "Normalize CSS animation/transition timing functions.",
|
|
5
|
-
"
|
|
6
|
-
|
|
5
|
+
"exports": {
|
|
6
|
+
".": {
|
|
7
|
+
"types": "./types/index.d.ts",
|
|
8
|
+
"default": "./src/index.js"
|
|
9
|
+
},
|
|
10
|
+
"./src": "./src/index.js",
|
|
11
|
+
"./src/index": "./src/index.js",
|
|
12
|
+
"./src/index.js": "./src/index.js",
|
|
13
|
+
"./package.json": "./package.json"
|
|
14
|
+
},
|
|
7
15
|
"files": [
|
|
8
16
|
"LICENSE-MIT",
|
|
9
17
|
"src",
|
|
@@ -16,9 +24,12 @@
|
|
|
16
24
|
"author": {
|
|
17
25
|
"name": "Ben Briggs",
|
|
18
26
|
"email": "beneb.info@gmail.com",
|
|
19
|
-
"url": "
|
|
27
|
+
"url": "https://beneb.info"
|
|
28
|
+
},
|
|
29
|
+
"repository": {
|
|
30
|
+
"type": "git",
|
|
31
|
+
"url": "cssnano/cssnano"
|
|
20
32
|
},
|
|
21
|
-
"repository": "cssnano/cssnano",
|
|
22
33
|
"bugs": {
|
|
23
34
|
"url": "https://github.com/cssnano/cssnano/issues"
|
|
24
35
|
},
|
|
@@ -27,9 +38,12 @@
|
|
|
27
38
|
"node": "^22.11.0 || ^24.11.0 || >=26.0"
|
|
28
39
|
},
|
|
29
40
|
"devDependencies": {
|
|
30
|
-
"postcss": "^8.5.
|
|
41
|
+
"postcss": "^8.5.26"
|
|
31
42
|
},
|
|
32
43
|
"peerDependencies": {
|
|
33
|
-
"postcss": "^8.5.
|
|
44
|
+
"postcss": "^8.5.26"
|
|
45
|
+
},
|
|
46
|
+
"scripts": {
|
|
47
|
+
"test": "node --test"
|
|
34
48
|
}
|
|
35
49
|
}
|
package/src/index.js
CHANGED
|
@@ -3,6 +3,8 @@ const valueParser = require('postcss-value-parser');
|
|
|
3
3
|
|
|
4
4
|
/** @type {(node: valueParser.Node) => number} */
|
|
5
5
|
const getValue = (node) => parseFloat(node.value);
|
|
6
|
+
const animationTransitionRegex =
|
|
7
|
+
/^(-\w+-)?(animation|transition)(-timing-function)?$/i;
|
|
6
8
|
|
|
7
9
|
/* Works because toString() normalizes the formatting,
|
|
8
10
|
so comparing the string forms behaves the same as number equality*/
|
|
@@ -29,76 +31,86 @@ function reduce(node) {
|
|
|
29
31
|
const lowerCasedValue = node.value.toLowerCase();
|
|
30
32
|
|
|
31
33
|
if (lowerCasedValue === 'steps') {
|
|
32
|
-
|
|
33
|
-
// as steps(1)
|
|
34
|
-
if (
|
|
35
|
-
node.nodes[0].type === 'word' &&
|
|
36
|
-
getValue(node.nodes[0]) === 1 &&
|
|
37
|
-
node.nodes[2] &&
|
|
38
|
-
node.nodes[2].type === 'word' &&
|
|
39
|
-
(node.nodes[2].value.toLowerCase() === 'start' ||
|
|
40
|
-
node.nodes[2].value.toLowerCase() === 'jump-start')
|
|
41
|
-
) {
|
|
42
|
-
/** @type string */ (node.type) = 'word';
|
|
43
|
-
node.value = 'step-start';
|
|
44
|
-
|
|
45
|
-
delete (/** @type Partial<valueParser.FunctionNode> */ (node).nodes);
|
|
46
|
-
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
if (
|
|
51
|
-
node.nodes[0].type === 'word' &&
|
|
52
|
-
getValue(node.nodes[0]) === 1 &&
|
|
53
|
-
node.nodes[2] &&
|
|
54
|
-
node.nodes[2].type === 'word' &&
|
|
55
|
-
(node.nodes[2].value.toLowerCase() === 'end' ||
|
|
56
|
-
node.nodes[2].value.toLowerCase() === 'jump-end')
|
|
57
|
-
) {
|
|
58
|
-
/** @type string */ (node.type) = 'word';
|
|
59
|
-
node.value = 'step-end';
|
|
60
|
-
|
|
61
|
-
delete (/** @type Partial<valueParser.FunctionNode> */ (node).nodes);
|
|
62
|
-
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// The end case is actually the browser default, so it isn't required.
|
|
67
|
-
if (
|
|
68
|
-
node.nodes[2] &&
|
|
69
|
-
node.nodes[2].type === 'word' &&
|
|
70
|
-
(node.nodes[2].value.toLowerCase() === 'end' ||
|
|
71
|
-
node.nodes[2].value.toLowerCase() === 'jump-end')
|
|
72
|
-
) {
|
|
73
|
-
node.nodes = [node.nodes[0]];
|
|
74
|
-
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
return false;
|
|
34
|
+
return normalizeSteps(node);
|
|
79
35
|
}
|
|
80
36
|
|
|
81
37
|
if (lowerCasedValue === 'cubic-bezier') {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
38
|
+
return normalizeCubicBezier(node);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* @param {valueParser.FunctionNode} node
|
|
44
|
+
* @return {void | false}
|
|
45
|
+
*/
|
|
46
|
+
function normalizeSteps(node) {
|
|
47
|
+
const count = node.nodes[0];
|
|
48
|
+
const position = node.nodes[2];
|
|
49
|
+
const isSingleStep = count.type === 'word' && getValue(count) === 1;
|
|
50
|
+
|
|
51
|
+
if (isSingleStep && isStepPosition(position, 'start', 'jump-start')) {
|
|
52
|
+
/** @type string */ (node.type) = 'word';
|
|
53
|
+
node.value = 'step-start';
|
|
54
|
+
|
|
55
|
+
delete (/** @type Partial<valueParser.FunctionNode> */ (node).nodes);
|
|
56
|
+
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (isSingleStep && isStepPosition(position, 'end', 'jump-end')) {
|
|
61
|
+
/** @type string */ (node.type) = 'word';
|
|
62
|
+
node.value = 'step-end';
|
|
63
|
+
|
|
64
|
+
delete (/** @type Partial<valueParser.FunctionNode> */ (node).nodes);
|
|
65
|
+
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
87
68
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
69
|
+
// The end case is actually the browser default, so it isn't required.
|
|
70
|
+
if (isStepPosition(position, 'end', 'jump-end')) {
|
|
71
|
+
node.nodes = [count];
|
|
91
72
|
|
|
92
|
-
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
93
75
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
node.value = match;
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
97
78
|
|
|
98
|
-
|
|
79
|
+
/**
|
|
80
|
+
* @param {valueParser.Node | undefined} node
|
|
81
|
+
* @param {string} first
|
|
82
|
+
* @param {string} second
|
|
83
|
+
* @return {boolean}
|
|
84
|
+
*/
|
|
85
|
+
function isStepPosition(node, first, second) {
|
|
86
|
+
return (
|
|
87
|
+
node?.type === 'word' &&
|
|
88
|
+
(node.value.toLowerCase() === first || node.value.toLowerCase() === second)
|
|
89
|
+
);
|
|
90
|
+
}
|
|
99
91
|
|
|
100
|
-
|
|
101
|
-
|
|
92
|
+
/**
|
|
93
|
+
* @param {valueParser.FunctionNode} node
|
|
94
|
+
* @return {void}
|
|
95
|
+
*/
|
|
96
|
+
function normalizeCubicBezier(node) {
|
|
97
|
+
const values = node.nodes
|
|
98
|
+
.filter((list, index) => {
|
|
99
|
+
return index % 2 === 0;
|
|
100
|
+
})
|
|
101
|
+
.map(getValue);
|
|
102
|
+
|
|
103
|
+
if (values.length !== 4) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const match = conversions.get(values.toString());
|
|
108
|
+
|
|
109
|
+
if (match) {
|
|
110
|
+
/** @type string */ (node.type) = 'word';
|
|
111
|
+
node.value = match;
|
|
112
|
+
|
|
113
|
+
delete (/** @type Partial<valueParser.FunctionNode> */ (node).nodes);
|
|
102
114
|
}
|
|
103
115
|
}
|
|
104
116
|
|
|
@@ -111,36 +123,36 @@ function transform(value) {
|
|
|
111
123
|
}
|
|
112
124
|
|
|
113
125
|
/**
|
|
114
|
-
* @type {import('postcss').PluginCreator<void>}
|
|
115
126
|
* @return {import('postcss').Plugin}
|
|
116
127
|
*/
|
|
117
128
|
function pluginCreator() {
|
|
118
129
|
return {
|
|
119
130
|
postcssPlugin: 'postcss-normalize-timing-functions',
|
|
120
|
-
|
|
131
|
+
/**
|
|
132
|
+
* @param {import('postcss').Root} css
|
|
133
|
+
*/
|
|
121
134
|
OnceExit(css) {
|
|
122
135
|
const cache = new Map();
|
|
123
136
|
|
|
124
|
-
css.walkDecls(
|
|
125
|
-
|
|
126
|
-
(decl) => {
|
|
127
|
-
const value = decl.value;
|
|
137
|
+
css.walkDecls(animationTransitionRegex, (decl) => {
|
|
138
|
+
const value = decl.value;
|
|
128
139
|
|
|
129
|
-
|
|
130
|
-
|
|
140
|
+
if (cache.has(value)) {
|
|
141
|
+
decl.value = cache.get(value);
|
|
131
142
|
|
|
132
|
-
|
|
133
|
-
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
134
145
|
|
|
135
|
-
|
|
146
|
+
const result = transform(value);
|
|
136
147
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
);
|
|
148
|
+
decl.value = result;
|
|
149
|
+
cache.set(value, result);
|
|
150
|
+
});
|
|
141
151
|
},
|
|
142
152
|
};
|
|
143
153
|
}
|
|
144
154
|
|
|
145
155
|
pluginCreator.postcss = true;
|
|
146
|
-
module.exports =
|
|
156
|
+
module.exports = /** @type {import('postcss').PluginCreator<void>}*/ (
|
|
157
|
+
pluginCreator
|
|
158
|
+
);
|
package/types/index.d.ts
CHANGED
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* @type {import('postcss').PluginCreator<void>}
|
|
4
|
-
* @return {import('postcss').Plugin}
|
|
5
|
-
*/
|
|
6
|
-
declare function pluginCreator(): import("postcss").Plugin;
|
|
7
|
-
declare namespace pluginCreator {
|
|
8
|
-
let postcss: true;
|
|
9
|
-
}
|
|
1
|
+
declare const _exports: import("postcss").PluginCreator<void>;
|
|
2
|
+
export = _exports;
|
|
10
3
|
//# sourceMappingURL=index.d.ts.map
|
package/types/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":""}
|