1 | import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
2 | import _extends from "@babel/runtime/helpers/esm/extends";
|
3 | const _excluded = ["duration", "easing", "delay"];
|
4 |
|
5 |
|
6 | export const easing = {
|
7 |
|
8 | easeInOut: 'cubic-bezier(0.4, 0, 0.2, 1)',
|
9 |
|
10 |
|
11 | easeOut: 'cubic-bezier(0.0, 0, 0.2, 1)',
|
12 |
|
13 | easeIn: 'cubic-bezier(0.4, 0, 1, 1)',
|
14 |
|
15 | sharp: 'cubic-bezier(0.4, 0, 0.6, 1)'
|
16 | };
|
17 |
|
18 |
|
19 | export const duration = {
|
20 | shortest: 150,
|
21 | shorter: 200,
|
22 | short: 250,
|
23 |
|
24 | standard: 300,
|
25 |
|
26 | complex: 375,
|
27 |
|
28 | enteringScreen: 225,
|
29 |
|
30 | leavingScreen: 195
|
31 | };
|
32 |
|
33 | function formatMs(milliseconds) {
|
34 | return `${Math.round(milliseconds)}ms`;
|
35 | }
|
36 |
|
37 | function getAutoHeightDuration(height) {
|
38 | if (!height) {
|
39 | return 0;
|
40 | }
|
41 |
|
42 | const constant = height / 36;
|
43 |
|
44 | return Math.round((4 + 15 * constant ** 0.25 + constant / 5) * 10);
|
45 | }
|
46 |
|
47 | export default function createTransitions(inputTransitions) {
|
48 | const mergedEasing = _extends({}, easing, inputTransitions.easing);
|
49 |
|
50 | const mergedDuration = _extends({}, duration, inputTransitions.duration);
|
51 |
|
52 | const create = (props = ['all'], options = {}) => {
|
53 | const {
|
54 | duration: durationOption = mergedDuration.standard,
|
55 | easing: easingOption = mergedEasing.easeInOut,
|
56 | delay = 0
|
57 | } = options,
|
58 | other = _objectWithoutPropertiesLoose(options, _excluded);
|
59 |
|
60 | if (process.env.NODE_ENV !== 'production') {
|
61 | const isString = value => typeof value === 'string';
|
62 |
|
63 |
|
64 |
|
65 | const isNumber = value => !isNaN(parseFloat(value));
|
66 |
|
67 | if (!isString(props) && !Array.isArray(props)) {
|
68 | console.error('MUI: Argument "props" must be a string or Array.');
|
69 | }
|
70 |
|
71 | if (!isNumber(durationOption) && !isString(durationOption)) {
|
72 | console.error(`MUI: Argument "duration" must be a number or a string but found ${durationOption}.`);
|
73 | }
|
74 |
|
75 | if (!isString(easingOption)) {
|
76 | console.error('MUI: Argument "easing" must be a string.');
|
77 | }
|
78 |
|
79 | if (!isNumber(delay) && !isString(delay)) {
|
80 | console.error('MUI: Argument "delay" must be a number or a string.');
|
81 | }
|
82 |
|
83 | if (Object.keys(other).length !== 0) {
|
84 | console.error(`MUI: Unrecognized argument(s) [${Object.keys(other).join(',')}].`);
|
85 | }
|
86 | }
|
87 |
|
88 | return (Array.isArray(props) ? props : [props]).map(animatedProp => `${animatedProp} ${typeof durationOption === 'string' ? durationOption : formatMs(durationOption)} ${easingOption} ${typeof delay === 'string' ? delay : formatMs(delay)}`).join(',');
|
89 | };
|
90 |
|
91 | return _extends({
|
92 | getAutoHeightDuration,
|
93 | create
|
94 | }, inputTransitions, {
|
95 | easing: mergedEasing,
|
96 | duration: mergedDuration
|
97 | });
|
98 | } |
\ | No newline at end of file |