source: frontend/node_modules/postcss-ordered-values/src/rules/transition.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 1.9 KB
RevLine 
[9af201e]1'use strict';
2const { unit } = require('postcss-value-parser');
3const { getArguments } = require('cssnano-utils');
4const addSpace = require('../lib/addSpace');
5const getValue = require('../lib/getValue');
6
7// transition: [ none | <single-transition-property> ] || <time> || <single-transition-timing-function> || <time>
8
9const 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 */
23function 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 */
72module.exports = function normalizeTransition(parsed) {
73 const values = normalize(getArguments(parsed));
74
75 return getValue(values);
76};
Note: See TracBrowser for help on using the repository browser.