source: trip-planner-front/node_modules/postcss-ordered-values/dist/rules/animation.js@ 6a3a178

Last change on this file since 6a3a178 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 3.2 KB
Line 
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = normalizeAnimation;
7
8var _postcssValueParser = require("postcss-value-parser");
9
10var _cssnanoUtils = require("cssnano-utils");
11
12var _addSpace = _interopRequireDefault(require("../lib/addSpace"));
13
14var _getValue = _interopRequireDefault(require("../lib/getValue"));
15
16function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
18// animation: [ none | <keyframes-name> ] || <time> || <single-timing-function> || <time> || <single-animation-iteration-count> || <single-animation-direction> || <single-animation-fill-mode> || <single-animation-play-state>
19const isTimingFunction = (value, type) => {
20 const functions = ['steps', 'cubic-bezier', 'frames'];
21 const keywords = ['ease', 'ease-in', 'ease-in-out', 'ease-out', 'linear', 'step-end', 'step-start'];
22 return type === 'function' && functions.includes(value) || keywords.includes(value);
23};
24
25const isDirection = value => {
26 return ['normal', 'reverse', 'alternate', 'alternate-reverse'].includes(value);
27};
28
29const isFillMode = value => {
30 return ['none', 'forwards', 'backwards', 'both'].includes(value);
31};
32
33const isPlayState = value => {
34 return ['running', 'paused'].includes(value);
35};
36
37const isTime = value => {
38 const quantity = (0, _postcssValueParser.unit)(value);
39 return quantity && ['ms', 's'].includes(quantity.unit);
40};
41
42const isIterationCount = value => {
43 const quantity = (0, _postcssValueParser.unit)(value);
44 return value === 'infinite' || quantity && !quantity.unit;
45};
46
47function normalizeAnimation(parsed) {
48 const args = (0, _cssnanoUtils.getArguments)(parsed);
49 const values = args.reduce((list, arg) => {
50 const state = {
51 name: [],
52 duration: [],
53 timingFunction: [],
54 delay: [],
55 iterationCount: [],
56 direction: [],
57 fillMode: [],
58 playState: []
59 };
60 const stateConditions = [{
61 property: 'duration',
62 delegate: isTime
63 }, {
64 property: 'timingFunction',
65 delegate: isTimingFunction
66 }, {
67 property: 'delay',
68 delegate: isTime
69 }, {
70 property: 'iterationCount',
71 delegate: isIterationCount
72 }, {
73 property: 'direction',
74 delegate: isDirection
75 }, {
76 property: 'fillMode',
77 delegate: isFillMode
78 }, {
79 property: 'playState',
80 delegate: isPlayState
81 }];
82 arg.forEach(node => {
83 let {
84 type,
85 value
86 } = node;
87
88 if (type === 'space') {
89 return;
90 }
91
92 value = value.toLowerCase();
93 const hasMatch = stateConditions.some(({
94 property,
95 delegate
96 }) => {
97 if (delegate(value, type) && !state[property].length) {
98 state[property] = [node, (0, _addSpace.default)()];
99 return true;
100 }
101 });
102
103 if (!hasMatch) {
104 state.name = [...state.name, node, (0, _addSpace.default)()];
105 }
106 });
107 return [...list, [...state.name, ...state.duration, ...state.timingFunction, ...state.delay, ...state.iterationCount, ...state.direction, ...state.fillMode, ...state.playState]];
108 }, []);
109 return (0, _getValue.default)(values);
110}
111
112module.exports = exports.default;
Note: See TracBrowser for help on using the repository browser.