@douyinfe/semi-animation-react 2.24.2 → 2.25.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/index.js +0 -7
- package/lib/cjs/src/Animation.js +3 -42
- package/lib/cjs/src/KeyFrames.js +2 -26
- package/lib/cjs/src/StyledAnimation.js +5 -43
- package/lib/cjs/src/StyledTransition.js +5 -42
- package/lib/cjs/src/Transition.js +11 -48
- package/lib/cjs/src/utils/invokeFns.js +0 -2
- package/lib/cjs/src/utils/noop.js +0 -2
- package/lib/cjs/src/utils/string.js +2 -7
- package/lib/es/src/Animation.js +3 -34
- package/lib/es/src/KeyFrames.js +2 -17
- package/lib/es/src/StyledAnimation.js +5 -33
- package/lib/es/src/StyledTransition.js +5 -33
- package/lib/es/src/Transition.js +11 -39
- package/lib/es/src/utils/invokeFns.js +0 -1
- package/lib/es/src/utils/noop.js +0 -1
- package/lib/es/src/utils/string.js +2 -5
- package/package.json +44 -45
|
@@ -4,50 +4,33 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _Animation = _interopRequireDefault(require("./Animation"));
|
|
9
|
-
|
|
10
8
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
|
-
|
|
12
9
|
var _react = _interopRequireWildcard(require("react"));
|
|
13
|
-
|
|
14
10
|
var _noop = _interopRequireDefault(require("./utils/noop"));
|
|
15
|
-
|
|
16
11
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
17
|
-
|
|
18
12
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
19
|
-
|
|
20
13
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
|
-
|
|
22
14
|
var __rest = void 0 && (void 0).__rest || function (s, e) {
|
|
23
15
|
var t = {};
|
|
24
|
-
|
|
25
16
|
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
|
|
26
|
-
|
|
27
17
|
if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
28
18
|
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
|
|
29
19
|
}
|
|
30
20
|
return t;
|
|
31
21
|
};
|
|
32
|
-
/* eslint-disable eqeqeq */
|
|
33
|
-
|
|
34
|
-
|
|
35
22
|
class Transition extends _react.Component {
|
|
36
23
|
constructor() {
|
|
37
24
|
let props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
38
25
|
super(props);
|
|
39
|
-
|
|
40
26
|
this._isControlled = () => [true, false, 'enter', 'leave'].includes(this.props.state);
|
|
41
|
-
|
|
42
27
|
this.forwardInstance = instance => {
|
|
43
28
|
this.instance = instance;
|
|
44
29
|
};
|
|
45
|
-
|
|
46
30
|
this.onRest = props => {
|
|
47
31
|
const {
|
|
48
32
|
state
|
|
49
33
|
} = this.state;
|
|
50
|
-
|
|
51
34
|
if (state === 'enter') {
|
|
52
35
|
this.props.didEnter(props);
|
|
53
36
|
} else if (state === 'leave') {
|
|
@@ -57,71 +40,58 @@ class Transition extends _react.Component {
|
|
|
57
40
|
});
|
|
58
41
|
this.props.didLeave(props);
|
|
59
42
|
}
|
|
60
|
-
|
|
61
43
|
this.props.onRest(props);
|
|
62
44
|
};
|
|
63
|
-
|
|
64
45
|
this.onStart = props => {
|
|
65
46
|
const {
|
|
66
47
|
state
|
|
67
48
|
} = this.state;
|
|
68
|
-
|
|
69
49
|
if (state === 'enter') {
|
|
70
50
|
this.props.willEnter(props);
|
|
71
51
|
} else if (state === 'leave') {
|
|
72
52
|
this.props.willLeave(props);
|
|
73
53
|
}
|
|
74
|
-
|
|
75
54
|
this.props.onStart(props);
|
|
76
55
|
};
|
|
77
|
-
|
|
78
56
|
this.state = {
|
|
79
57
|
state: '',
|
|
80
58
|
lastChildren: null,
|
|
81
59
|
currentChildren: null
|
|
82
60
|
};
|
|
83
61
|
}
|
|
84
|
-
|
|
85
62
|
static getDerivedStateFromProps(props, state) {
|
|
86
63
|
const willUpdateStates = {};
|
|
87
|
-
|
|
88
|
-
|
|
64
|
+
if (props.children !== state.currentChildren
|
|
65
|
+
// && (props.children == null || state.currentChildren == null)
|
|
89
66
|
) {
|
|
90
67
|
willUpdateStates.lastChildren = state.currentChildren;
|
|
91
68
|
willUpdateStates.currentChildren = props.children;
|
|
92
|
-
|
|
93
69
|
if (props.children == null) {
|
|
94
70
|
willUpdateStates.state = 'leave';
|
|
95
71
|
} else {
|
|
96
72
|
willUpdateStates.state = 'enter';
|
|
97
73
|
}
|
|
98
74
|
}
|
|
99
|
-
|
|
100
75
|
if (props.state != null) {
|
|
101
76
|
willUpdateStates.state = props.state;
|
|
102
77
|
}
|
|
103
|
-
|
|
104
78
|
return willUpdateStates;
|
|
105
79
|
}
|
|
106
|
-
|
|
107
80
|
componentWillUnmount() {
|
|
108
81
|
if (this.instance) {
|
|
109
82
|
this.instance.destroy();
|
|
110
83
|
this.instance = null;
|
|
111
84
|
}
|
|
112
85
|
}
|
|
113
|
-
|
|
114
86
|
render() {
|
|
115
87
|
const _a = this.props,
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
let children; // eslint-disable-next-line prefer-const
|
|
124
|
-
|
|
88
|
+
{
|
|
89
|
+
from: propsFrom,
|
|
90
|
+
enter,
|
|
91
|
+
leave
|
|
92
|
+
} = _a,
|
|
93
|
+
restProps = __rest(_a, ["from", "enter", "leave"]);
|
|
94
|
+
let children;
|
|
125
95
|
let {
|
|
126
96
|
currentChildren,
|
|
127
97
|
lastChildren,
|
|
@@ -129,44 +99,37 @@ class Transition extends _react.Component {
|
|
|
129
99
|
} = this.state;
|
|
130
100
|
let from = {};
|
|
131
101
|
let to = {};
|
|
132
|
-
|
|
133
102
|
const isControlled = this._isControlled();
|
|
134
|
-
|
|
135
103
|
if (isControlled) {
|
|
136
104
|
children = this.props.children;
|
|
137
105
|
state = this.props.state;
|
|
138
106
|
} else if (currentChildren == null && lastChildren == null) {
|
|
139
107
|
return null;
|
|
140
108
|
}
|
|
141
|
-
|
|
142
109
|
if (state === 'enter') {
|
|
143
110
|
from = propsFrom;
|
|
144
111
|
to = enter;
|
|
145
|
-
|
|
146
112
|
if (!isControlled) {
|
|
147
113
|
children = currentChildren;
|
|
148
114
|
}
|
|
149
115
|
} else if (state === 'leave') {
|
|
150
116
|
from = enter;
|
|
151
117
|
to = leave;
|
|
152
|
-
|
|
153
118
|
if (!isControlled) {
|
|
154
119
|
children = lastChildren;
|
|
155
120
|
}
|
|
156
121
|
}
|
|
157
|
-
|
|
158
122
|
return /*#__PURE__*/_react.default.createElement(_Animation.default, Object.assign({}, restProps, {
|
|
159
123
|
force: true,
|
|
160
124
|
from: from,
|
|
161
125
|
to: to,
|
|
162
126
|
onRest: this.onRest,
|
|
163
127
|
onStart: this.onStart
|
|
164
|
-
}), props =>
|
|
128
|
+
}), props =>
|
|
129
|
+
// eslint-disable-next-line no-nested-ternary
|
|
165
130
|
typeof children === 'function' ? children(props) : /*#__PURE__*/(0, _react.isValidElement)(children) ? children : null);
|
|
166
131
|
}
|
|
167
|
-
|
|
168
132
|
}
|
|
169
|
-
|
|
170
133
|
exports.default = Transition;
|
|
171
134
|
Transition.propTypes = {
|
|
172
135
|
children: _propTypes.default.any,
|
|
@@ -4,10 +4,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = invokeFns;
|
|
7
|
-
|
|
8
7
|
function invokeFns(fns) {
|
|
9
8
|
let args = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
10
|
-
|
|
11
9
|
if (Array.isArray(fns) && fns.length) {
|
|
12
10
|
fns.forEach(fn => {
|
|
13
11
|
if (typeof fn === 'function') {
|
|
@@ -5,24 +5,19 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.lowerCase = lowerCase;
|
|
7
7
|
exports.upperCase = upperCase;
|
|
8
|
-
|
|
9
|
-
/* eslint-disable eqeqeq */
|
|
10
8
|
function upperCase(str, pos) {
|
|
11
9
|
if (typeof str === 'string') {
|
|
12
|
-
return str
|
|
10
|
+
return str
|
|
13
11
|
// @ts-ignore
|
|
14
12
|
.split().reduce((total, cur, index) => pos == null || pos === index ? total + cur.toUpperCase() : total + cur, '');
|
|
15
13
|
}
|
|
16
|
-
|
|
17
14
|
return str;
|
|
18
15
|
}
|
|
19
|
-
|
|
20
16
|
function lowerCase(str, pos) {
|
|
21
17
|
if (typeof str === 'string') {
|
|
22
|
-
return str
|
|
18
|
+
return str
|
|
23
19
|
// @ts-ignore
|
|
24
20
|
.split().reduce((total, cur, index) => pos == null || pos === index ? total + cur.toLowerCase() : total + cur, '');
|
|
25
21
|
}
|
|
26
|
-
|
|
27
22
|
return str;
|
|
28
23
|
}
|
package/lib/es/src/Animation.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/ban-types */
|
|
2
|
-
|
|
3
|
-
/* eslint-disable react/destructuring-assignment */
|
|
4
2
|
import { PureComponent, isValidElement } from 'react';
|
|
5
3
|
import PropTypes from 'prop-types';
|
|
6
4
|
import { Animation as SemiAnimation, events } from '@douyinfe/semi-animation';
|
|
@@ -9,29 +7,24 @@ export default class Animation extends PureComponent {
|
|
|
9
7
|
constructor() {
|
|
10
8
|
let props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
11
9
|
super(props);
|
|
12
|
-
|
|
13
10
|
this.initAnimation = props => {
|
|
14
|
-
|
|
15
|
-
props = props == null ? this.props : props; // eslint-disable-next-line prefer-const
|
|
16
|
-
|
|
11
|
+
props = props == null ? this.props : props;
|
|
17
12
|
let {
|
|
18
13
|
from,
|
|
19
14
|
to,
|
|
20
15
|
config,
|
|
21
16
|
reverse
|
|
22
17
|
} = props;
|
|
23
|
-
|
|
24
18
|
if (reverse) {
|
|
25
19
|
[from, to] = [to, from];
|
|
26
20
|
}
|
|
27
|
-
|
|
28
21
|
this.animation = new SemiAnimation({
|
|
29
22
|
from: Object.assign({}, from),
|
|
30
23
|
to: Object.assign({}, to)
|
|
31
24
|
}, Object.assign({}, config));
|
|
32
25
|
events.forEach(event => {
|
|
33
|
-
const propName =
|
|
34
|
-
|
|
26
|
+
const propName = `on${event[0].toUpperCase() + event.slice(1)}`;
|
|
27
|
+
// eslint-disable-next-line @typescript-eslint/no-shadow
|
|
35
28
|
this.animation.on(event, props => {
|
|
36
29
|
// avoid memory leak
|
|
37
30
|
if (this._mounted && !this._destroyed) {
|
|
@@ -44,61 +37,50 @@ export default class Animation extends PureComponent {
|
|
|
44
37
|
});
|
|
45
38
|
this._destroyed = false;
|
|
46
39
|
};
|
|
47
|
-
|
|
48
40
|
this.bindEvents = () => {
|
|
49
41
|
this.startOrNot = () => {
|
|
50
42
|
const {
|
|
51
43
|
immediate,
|
|
52
44
|
autoStart
|
|
53
45
|
} = this.props;
|
|
54
|
-
|
|
55
46
|
if (immediate) {
|
|
56
47
|
this.end();
|
|
57
48
|
} else if (autoStart) {
|
|
58
49
|
this.start();
|
|
59
50
|
}
|
|
60
51
|
};
|
|
61
|
-
|
|
62
52
|
this.start = () => {
|
|
63
53
|
this.animation && this.animation.start();
|
|
64
54
|
};
|
|
65
|
-
|
|
66
55
|
this.pause = () => {
|
|
67
56
|
this.animation && this.animation.pause();
|
|
68
57
|
};
|
|
69
|
-
|
|
70
58
|
this.stop = () => {
|
|
71
59
|
this.animation && this.animation.stop();
|
|
72
60
|
};
|
|
73
|
-
|
|
74
61
|
this.end = () => {
|
|
75
62
|
this.animation && this.animation.end();
|
|
76
63
|
};
|
|
77
|
-
|
|
78
64
|
this.resume = () => {
|
|
79
65
|
this.animation && this.animation.resume();
|
|
80
66
|
};
|
|
81
|
-
|
|
82
67
|
this.reset = () => {
|
|
83
68
|
if (this.animation) {
|
|
84
69
|
this.animation.reset();
|
|
85
70
|
this.startOrNot();
|
|
86
71
|
}
|
|
87
72
|
};
|
|
88
|
-
|
|
89
73
|
this.reverse = () => {
|
|
90
74
|
if (this.animation) {
|
|
91
75
|
this.animation.reverse();
|
|
92
76
|
this.startOrNot();
|
|
93
77
|
}
|
|
94
78
|
};
|
|
95
|
-
|
|
96
79
|
this.destroy = () => {
|
|
97
80
|
this._destroyed = true;
|
|
98
81
|
this.animation && this.animation.destroy();
|
|
99
82
|
};
|
|
100
83
|
};
|
|
101
|
-
|
|
102
84
|
this.state = {
|
|
103
85
|
currentStyle: {}
|
|
104
86
|
};
|
|
@@ -107,42 +89,33 @@ export default class Animation extends PureComponent {
|
|
|
107
89
|
this.initAnimation();
|
|
108
90
|
this.bindEvents();
|
|
109
91
|
}
|
|
110
|
-
|
|
111
92
|
startOrNot() {
|
|
112
93
|
throw new Error('Method not implemented.');
|
|
113
94
|
}
|
|
114
|
-
|
|
115
95
|
componentDidMount() {
|
|
116
96
|
this._mounted = true;
|
|
117
97
|
const {
|
|
118
98
|
forwardInstance
|
|
119
99
|
} = this.props;
|
|
120
|
-
|
|
121
100
|
if (this.animation === null) {
|
|
122
101
|
// didmount/willUnmount may be called twice when React.StrictMode is true in React 18, we need to ensure that this.animation is correct
|
|
123
102
|
this.initAnimation();
|
|
124
103
|
this.bindEvents();
|
|
125
104
|
}
|
|
126
|
-
|
|
127
105
|
if (typeof forwardInstance === 'function') {
|
|
128
106
|
forwardInstance(this.animation);
|
|
129
107
|
}
|
|
130
|
-
|
|
131
108
|
this.startOrNot();
|
|
132
109
|
}
|
|
133
|
-
|
|
134
110
|
componentWillUnmount() {
|
|
135
111
|
this._mounted = false;
|
|
136
|
-
|
|
137
112
|
if (this.animation) {
|
|
138
113
|
this.animation.destroy();
|
|
139
114
|
this.animation = null;
|
|
140
115
|
}
|
|
141
116
|
}
|
|
142
|
-
|
|
143
117
|
componentDidUpdate() {
|
|
144
118
|
let prevProps = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
145
|
-
|
|
146
119
|
if (this.props.reset) {
|
|
147
120
|
if (this.props.from !== prevProps.from || this.props.to !== prevProps.to) {
|
|
148
121
|
this.destroy();
|
|
@@ -150,7 +123,6 @@ export default class Animation extends PureComponent {
|
|
|
150
123
|
this.startOrNot();
|
|
151
124
|
}
|
|
152
125
|
}
|
|
153
|
-
|
|
154
126
|
if (this.props.force) {
|
|
155
127
|
if (this.props.to !== prevProps.to) {
|
|
156
128
|
this.initAnimation(Object.assign(Object.assign({}, this.props), {
|
|
@@ -160,12 +132,10 @@ export default class Animation extends PureComponent {
|
|
|
160
132
|
}
|
|
161
133
|
}
|
|
162
134
|
}
|
|
163
|
-
|
|
164
135
|
render() {
|
|
165
136
|
const {
|
|
166
137
|
children
|
|
167
138
|
} = this.props;
|
|
168
|
-
|
|
169
139
|
if (typeof children === 'function') {
|
|
170
140
|
return children(this.animation.getCurrentStates());
|
|
171
141
|
} else if ( /*#__PURE__*/isValidElement(children)) {
|
|
@@ -174,7 +144,6 @@ export default class Animation extends PureComponent {
|
|
|
174
144
|
return null;
|
|
175
145
|
}
|
|
176
146
|
}
|
|
177
|
-
|
|
178
147
|
}
|
|
179
148
|
Animation.propTypes = {
|
|
180
149
|
onStart: PropTypes.func,
|
package/lib/es/src/KeyFrames.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/* eslint-disable react/destructuring-assignment */
|
|
2
1
|
import React, { Component } from 'react';
|
|
3
2
|
import PropTypes from 'prop-types';
|
|
4
3
|
import noop from './utils/noop';
|
|
@@ -6,22 +5,17 @@ import Animation from './Animation';
|
|
|
6
5
|
export default class KeyFrames extends Component {
|
|
7
6
|
constructor() {
|
|
8
7
|
var _this;
|
|
9
|
-
|
|
10
8
|
let props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
11
9
|
super(props);
|
|
12
10
|
_this = this;
|
|
13
|
-
|
|
14
11
|
this.onFrame = function () {
|
|
15
12
|
let props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
16
13
|
const currentStyle = Object.assign({}, props);
|
|
17
|
-
|
|
18
14
|
_this.props.onFrame(currentStyle);
|
|
19
|
-
|
|
20
15
|
_this.setState({
|
|
21
16
|
currentStyle
|
|
22
17
|
});
|
|
23
18
|
};
|
|
24
|
-
|
|
25
19
|
this.next = () => {
|
|
26
20
|
let {
|
|
27
21
|
frameIndex
|
|
@@ -31,7 +25,6 @@ export default class KeyFrames extends Component {
|
|
|
31
25
|
loop
|
|
32
26
|
} = this.props;
|
|
33
27
|
frameIndex++;
|
|
34
|
-
|
|
35
28
|
if (frameIndex < frames.length - 1) {
|
|
36
29
|
this.setState({
|
|
37
30
|
frameIndex
|
|
@@ -39,38 +32,31 @@ export default class KeyFrames extends Component {
|
|
|
39
32
|
} else {
|
|
40
33
|
frameIndex = 0;
|
|
41
34
|
this.props.onRest(this.state.currentStyle);
|
|
42
|
-
|
|
43
35
|
if (loop) {
|
|
44
36
|
this.setState({
|
|
45
37
|
frameIndex
|
|
46
38
|
});
|
|
47
39
|
}
|
|
48
40
|
}
|
|
49
|
-
|
|
50
41
|
this.props.onKeyRest(this.state.currentStyle);
|
|
51
42
|
};
|
|
52
|
-
|
|
53
43
|
this.forwardInstance = instance => {
|
|
54
44
|
this.instance = instance;
|
|
55
|
-
|
|
56
45
|
if (typeof this.props.forwardInstance === 'function') {
|
|
57
46
|
this.props.forwardInstance(this.instance);
|
|
58
47
|
}
|
|
59
48
|
};
|
|
60
|
-
|
|
61
49
|
this.state = {
|
|
62
50
|
currentStyle: {},
|
|
63
51
|
frameIndex: 0
|
|
64
52
|
};
|
|
65
53
|
}
|
|
66
|
-
|
|
67
|
-
|
|
54
|
+
componentDidMount() {
|
|
55
|
+
// this.props.forwardInstance(this.instance);
|
|
68
56
|
}
|
|
69
|
-
|
|
70
57
|
componentWillUnmount() {
|
|
71
58
|
this.instance && this.instance.destroy();
|
|
72
59
|
}
|
|
73
|
-
|
|
74
60
|
render() {
|
|
75
61
|
const {
|
|
76
62
|
children,
|
|
@@ -90,7 +76,6 @@ export default class KeyFrames extends Component {
|
|
|
90
76
|
onRest: this.next
|
|
91
77
|
}), typeof children === 'function' ? children(currentStyle) : children);
|
|
92
78
|
}
|
|
93
|
-
|
|
94
79
|
}
|
|
95
80
|
KeyFrames.propTypes = {
|
|
96
81
|
frames: PropTypes.array,
|
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
/* eslint-disable react/destructuring-assignment */
|
|
2
|
-
|
|
3
|
-
/* eslint-disable prefer-const */
|
|
4
|
-
|
|
5
|
-
/* eslint-disable eqeqeq */
|
|
6
|
-
|
|
7
|
-
/* eslint-disable import/no-duplicates */
|
|
8
|
-
|
|
9
|
-
/* eslint-disable no-duplicate-imports */
|
|
10
1
|
import { PureComponent, isValidElement, cloneElement, Children } from 'react';
|
|
11
2
|
import PropTypes from 'prop-types';
|
|
12
3
|
import classnames from 'classnames';
|
|
@@ -17,11 +8,9 @@ const types = Object.values(styledTypes).reduce((arr, cur) => [...arr, ...cur],
|
|
|
17
8
|
export default class StyledAnimation extends PureComponent {
|
|
18
9
|
constructor() {
|
|
19
10
|
var _this;
|
|
20
|
-
|
|
21
11
|
let props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
22
12
|
super(props);
|
|
23
13
|
_this = this;
|
|
24
|
-
|
|
25
14
|
this._generateAnimateEvents = function (child) {
|
|
26
15
|
let props = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
27
16
|
return {
|
|
@@ -29,47 +18,39 @@ export default class StyledAnimation extends PureComponent {
|
|
|
29
18
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
30
19
|
args[_key] = arguments[_key];
|
|
31
20
|
}
|
|
32
|
-
|
|
33
21
|
return invokeFns([child && child.props && child.props.onAnimationIteration, props.onFrame], args);
|
|
34
22
|
},
|
|
35
23
|
onAnimationStart: function () {
|
|
36
24
|
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
37
25
|
args[_key2] = arguments[_key2];
|
|
38
26
|
}
|
|
39
|
-
|
|
40
27
|
return invokeFns([child && child.props && child.props.onAnimationStart, props.onStart], args);
|
|
41
28
|
},
|
|
42
29
|
onAnimationEnd: function () {
|
|
43
30
|
for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
|
|
44
31
|
args[_key3] = arguments[_key3];
|
|
45
32
|
}
|
|
46
|
-
|
|
47
33
|
return invokeFns([child && child.props && child.props.onAnimationEnd, props.onRest], args);
|
|
48
34
|
}
|
|
49
35
|
};
|
|
50
36
|
};
|
|
51
|
-
|
|
52
37
|
this._hasSpeedClass = function () {
|
|
53
38
|
let speed = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _this.props.speed;
|
|
54
39
|
return speed != null && speeds.includes(speed);
|
|
55
40
|
};
|
|
56
|
-
|
|
57
41
|
this._hasTypeClass = function () {
|
|
58
42
|
let type = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _this.props.type;
|
|
59
43
|
return type != null && types.includes(type);
|
|
60
44
|
};
|
|
61
|
-
|
|
62
45
|
this._hasDelayClass = function () {
|
|
63
46
|
let delay = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _this.props.delay;
|
|
64
47
|
return delay != null && delays.includes(delay);
|
|
65
48
|
};
|
|
66
|
-
|
|
67
49
|
this._hasLoopClass = function () {
|
|
68
50
|
let loop = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _this.props.loop;
|
|
69
51
|
return loop != null && loops.includes(loop);
|
|
70
52
|
};
|
|
71
53
|
}
|
|
72
|
-
|
|
73
54
|
render() {
|
|
74
55
|
let {
|
|
75
56
|
type,
|
|
@@ -84,20 +65,15 @@ export default class StyledAnimation extends PureComponent {
|
|
|
84
65
|
className,
|
|
85
66
|
fillMode
|
|
86
67
|
} = this.props;
|
|
87
|
-
|
|
88
68
|
const hasTypeClass = this._hasTypeClass();
|
|
89
|
-
|
|
90
69
|
const hasSpeedClass = this._hasSpeedClass();
|
|
91
|
-
|
|
92
70
|
const hasDelayClass = this._hasDelayClass();
|
|
93
|
-
|
|
94
71
|
const hasLoopClass = this._hasLoopClass();
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
[
|
|
98
|
-
[
|
|
99
|
-
[
|
|
100
|
-
["".concat(prefixCls, "-loop-").concat(loop)]: hasLoopClass
|
|
72
|
+
const animateCls = className || classnames(`${prefixCls}-animated`, {
|
|
73
|
+
[`${prefixCls}-${type}`]: Boolean(type),
|
|
74
|
+
[`${prefixCls}-speed-${speed}`]: hasSpeedClass,
|
|
75
|
+
[`${prefixCls}-delay-${delay}`]: hasDelayClass,
|
|
76
|
+
[`${prefixCls}-loop-${loop}`]: hasLoopClass
|
|
101
77
|
});
|
|
102
78
|
const animateStyle = {
|
|
103
79
|
animationTimingFunction: timing,
|
|
@@ -108,25 +84,21 @@ export default class StyledAnimation extends PureComponent {
|
|
|
108
84
|
animationDirection: reverse ? 'alternate' : 'normal',
|
|
109
85
|
animationFillMode: fillMode
|
|
110
86
|
};
|
|
111
|
-
|
|
112
87
|
if ( /*#__PURE__*/isValidElement(children)) {
|
|
113
88
|
children = Children.map(children, child => {
|
|
114
89
|
const animateEvents = this._generateAnimateEvents(child, this.props);
|
|
115
|
-
|
|
116
90
|
return /*#__PURE__*/cloneElement(child, Object.assign({
|
|
117
91
|
className: classnames(child.props.className, animateCls),
|
|
118
92
|
style: Object.assign(Object.assign({}, child.props.style), this.props.style)
|
|
119
93
|
}, animateEvents));
|
|
120
94
|
});
|
|
121
95
|
}
|
|
122
|
-
|
|
123
96
|
return typeof children === 'function' ? children({
|
|
124
97
|
animateCls,
|
|
125
98
|
animateStyle,
|
|
126
99
|
animateEvents: this._generateAnimateEvents(null, this.props)
|
|
127
100
|
}) : children;
|
|
128
101
|
}
|
|
129
|
-
|
|
130
102
|
}
|
|
131
103
|
StyledAnimation.propTypes = {
|
|
132
104
|
className: PropTypes.string,
|