1 | "use strict";
|
---|
2 |
|
---|
3 | Object.defineProperty(exports, "__esModule", {
|
---|
4 | value: true
|
---|
5 | });
|
---|
6 | exports.default = normalizeTransition;
|
---|
7 |
|
---|
8 | var _postcssValueParser = require("postcss-value-parser");
|
---|
9 |
|
---|
10 | var _cssnanoUtils = require("cssnano-utils");
|
---|
11 |
|
---|
12 | var _addSpace = _interopRequireDefault(require("../lib/addSpace"));
|
---|
13 |
|
---|
14 | var _getValue = _interopRequireDefault(require("../lib/getValue"));
|
---|
15 |
|
---|
16 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
---|
17 |
|
---|
18 | // transition: [ none | <single-transition-property> ] || <time> || <single-transition-timing-function> || <time>
|
---|
19 | const timingFunctions = ['ease', 'linear', 'ease-in', 'ease-out', 'ease-in-out', 'step-start', 'step-end'];
|
---|
20 |
|
---|
21 | function normalizeTransition(parsed) {
|
---|
22 | let args = (0, _cssnanoUtils.getArguments)(parsed);
|
---|
23 | let values = args.reduce((list, arg) => {
|
---|
24 | let state = {
|
---|
25 | timingFunction: [],
|
---|
26 | property: [],
|
---|
27 | time1: [],
|
---|
28 | time2: []
|
---|
29 | };
|
---|
30 | arg.forEach(node => {
|
---|
31 | const {
|
---|
32 | type,
|
---|
33 | value
|
---|
34 | } = node;
|
---|
35 |
|
---|
36 | if (type === 'space') {
|
---|
37 | return;
|
---|
38 | }
|
---|
39 |
|
---|
40 | if (type === 'function' && ~['steps', 'cubic-bezier'].indexOf(value.toLowerCase())) {
|
---|
41 | state.timingFunction = [...state.timingFunction, node, (0, _addSpace.default)()];
|
---|
42 | } else if ((0, _postcssValueParser.unit)(value)) {
|
---|
43 | if (!state.time1.length) {
|
---|
44 | state.time1 = [...state.time1, node, (0, _addSpace.default)()];
|
---|
45 | } else {
|
---|
46 | state.time2 = [...state.time2, node, (0, _addSpace.default)()];
|
---|
47 | }
|
---|
48 | } else if (~timingFunctions.indexOf(value.toLowerCase())) {
|
---|
49 | state.timingFunction = [...state.timingFunction, node, (0, _addSpace.default)()];
|
---|
50 | } else {
|
---|
51 | state.property = [...state.property, node, (0, _addSpace.default)()];
|
---|
52 | }
|
---|
53 | });
|
---|
54 | return [...list, [...state.property, ...state.time1, ...state.timingFunction, ...state.time2]];
|
---|
55 | }, []);
|
---|
56 | return (0, _getValue.default)(values);
|
---|
57 | }
|
---|
58 |
|
---|
59 | module.exports = exports.default; |
---|