index.js
2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _postcss = require('postcss');
var _postcssValueParser = require('postcss-value-parser');
var _postcssValueParser2 = _interopRequireDefault(_postcssValueParser);
var _cssnanoUtilGetMatch = require('cssnano-util-get-match');
var _cssnanoUtilGetMatch2 = _interopRequireDefault(_cssnanoUtilGetMatch);
var _map = require('./lib/map');
var _map2 = _interopRequireDefault(_map);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const getMatch = (0, _cssnanoUtilGetMatch2.default)(_map2.default);
const getValue = node => parseFloat(node.value);
function evenValues(list, index) {
return index % 2 === 0;
}
function reduce(node) {
if (node.type !== 'function') {
return false;
}
const lowerCasedValue = node.value.toLowerCase();
if (lowerCasedValue === 'steps') {
// Don't bother checking the step-end case as it has the same length
// as steps(1)
if (getValue(node.nodes[0]) === 1 && node.nodes[2] && node.nodes[2].value.toLowerCase() === 'start') {
node.type = 'word';
node.value = 'step-start';
delete node.nodes;
return;
}
// The end case is actually the browser default, so it isn't required.
if (node.nodes[2] && node.nodes[2].value.toLowerCase() === 'end') {
node.nodes = [node.nodes[0]];
return;
}
return false;
}
if (lowerCasedValue === 'cubic-bezier') {
const match = getMatch(node.nodes.filter(evenValues).map(getValue));
if (match) {
node.type = 'word';
node.value = match;
delete node.nodes;
return;
}
}
}
exports.default = (0, _postcss.plugin)('postcss-normalize-timing-functions', () => {
return css => {
const cache = {};
css.walkDecls(/(animation|transition)(-timing-function|$)/i, decl => {
const value = decl.value;
if (cache[value]) {
decl.value = cache[value];
return;
}
const result = (0, _postcssValueParser2.default)(value).walk(reduce).toString();
decl.value = result;
cache[value] = result;
});
};
});
module.exports = exports['default'];