| [9af201e] | 1 | 'use strict';
|
|---|
| 2 | const { unit } = require('postcss-value-parser');
|
|---|
| 3 | const { getArguments } = require('cssnano-utils');
|
|---|
| 4 | const addSpace = require('../lib/addSpace');
|
|---|
| 5 | const getValue = require('../lib/getValue');
|
|---|
| 6 |
|
|---|
| 7 | // transition: [ none | <single-transition-property> ] || <time> || <single-transition-timing-function> || <time>
|
|---|
| 8 |
|
|---|
| 9 | const timingFunctions = new Set([
|
|---|
| 10 | 'ease',
|
|---|
| 11 | 'linear',
|
|---|
| 12 | 'ease-in',
|
|---|
| 13 | 'ease-out',
|
|---|
| 14 | 'ease-in-out',
|
|---|
| 15 | 'step-start',
|
|---|
| 16 | 'step-end',
|
|---|
| 17 | ]);
|
|---|
| 18 |
|
|---|
| 19 | /**
|
|---|
| 20 | * @param {import('postcss-value-parser').Node[][]} args
|
|---|
| 21 | * @return {import('postcss-value-parser').Node[][]}
|
|---|
| 22 | */
|
|---|
| 23 | function normalize(args) {
|
|---|
| 24 | const list = [];
|
|---|
| 25 | for (const arg of args) {
|
|---|
| 26 | /** @type {Record<string, import('postcss-value-parser').Node[]>} */
|
|---|
| 27 | let state = {
|
|---|
| 28 | timingFunction: [],
|
|---|
| 29 | property: [],
|
|---|
| 30 | time1: [],
|
|---|
| 31 | time2: [],
|
|---|
| 32 | };
|
|---|
| 33 |
|
|---|
| 34 | arg.forEach((node) => {
|
|---|
| 35 | const { type, value } = node;
|
|---|
| 36 |
|
|---|
| 37 | if (type === 'space') {
|
|---|
| 38 | return;
|
|---|
| 39 | }
|
|---|
| 40 |
|
|---|
| 41 | if (
|
|---|
| 42 | type === 'function' &&
|
|---|
| 43 | new Set(['steps', 'cubic-bezier']).has(value.toLowerCase())
|
|---|
| 44 | ) {
|
|---|
| 45 | state.timingFunction = [...state.timingFunction, node, addSpace()];
|
|---|
| 46 | } else if (unit(value)) {
|
|---|
| 47 | if (!state.time1.length) {
|
|---|
| 48 | state.time1 = [...state.time1, node, addSpace()];
|
|---|
| 49 | } else {
|
|---|
| 50 | state.time2 = [...state.time2, node, addSpace()];
|
|---|
| 51 | }
|
|---|
| 52 | } else if (timingFunctions.has(value.toLowerCase())) {
|
|---|
| 53 | state.timingFunction = [...state.timingFunction, node, addSpace()];
|
|---|
| 54 | } else {
|
|---|
| 55 | state.property = [...state.property, node, addSpace()];
|
|---|
| 56 | }
|
|---|
| 57 | });
|
|---|
| 58 |
|
|---|
| 59 | list.push([
|
|---|
| 60 | ...state.property,
|
|---|
| 61 | ...state.time1,
|
|---|
| 62 | ...state.timingFunction,
|
|---|
| 63 | ...state.time2,
|
|---|
| 64 | ]);
|
|---|
| 65 | }
|
|---|
| 66 | return list;
|
|---|
| 67 | }
|
|---|
| 68 | /**
|
|---|
| 69 | * @param {import('postcss-value-parser').ParsedValue} parsed
|
|---|
| 70 | * @return {string}
|
|---|
| 71 | */
|
|---|
| 72 | module.exports = function normalizeTransition(parsed) {
|
|---|
| 73 | const values = normalize(getArguments(parsed));
|
|---|
| 74 |
|
|---|
| 75 | return getValue(values);
|
|---|
| 76 | };
|
|---|