@douyinfe/semi-animation-react 2.1.0 → 2.1.4

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.
@@ -0,0 +1,6 @@
1
+ export { default as StyledAnimation } from './src/StyledAnimation';
2
+ export { default as StyledTransition } from './src/StyledTransition';
3
+ export { default as Animation } from './src/Animation';
4
+ export { default as KeyFrames } from './src/KeyFrames';
5
+ export { default as Transition } from './src/Transition';
6
+ export { interpolate, presets } from '@douyinfe/semi-animation';
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+
3
+ var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
4
+
5
+ var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
6
+
7
+ _Object$defineProperty(exports, "__esModule", {
8
+ value: true
9
+ });
10
+
11
+ _Object$defineProperty(exports, "Animation", {
12
+ enumerable: true,
13
+ get: function () {
14
+ return _Animation.default;
15
+ }
16
+ });
17
+
18
+ _Object$defineProperty(exports, "KeyFrames", {
19
+ enumerable: true,
20
+ get: function () {
21
+ return _KeyFrames.default;
22
+ }
23
+ });
24
+
25
+ _Object$defineProperty(exports, "StyledAnimation", {
26
+ enumerable: true,
27
+ get: function () {
28
+ return _StyledAnimation.default;
29
+ }
30
+ });
31
+
32
+ _Object$defineProperty(exports, "StyledTransition", {
33
+ enumerable: true,
34
+ get: function () {
35
+ return _StyledTransition.default;
36
+ }
37
+ });
38
+
39
+ _Object$defineProperty(exports, "Transition", {
40
+ enumerable: true,
41
+ get: function () {
42
+ return _Transition.default;
43
+ }
44
+ });
45
+
46
+ _Object$defineProperty(exports, "interpolate", {
47
+ enumerable: true,
48
+ get: function () {
49
+ return _semiAnimation.interpolate;
50
+ }
51
+ });
52
+
53
+ _Object$defineProperty(exports, "presets", {
54
+ enumerable: true,
55
+ get: function () {
56
+ return _semiAnimation.presets;
57
+ }
58
+ });
59
+
60
+ var _StyledAnimation = _interopRequireDefault(require("./src/StyledAnimation"));
61
+
62
+ var _StyledTransition = _interopRequireDefault(require("./src/StyledTransition"));
63
+
64
+ var _Animation = _interopRequireDefault(require("./src/Animation"));
65
+
66
+ var _KeyFrames = _interopRequireDefault(require("./src/KeyFrames"));
67
+
68
+ var _Transition = _interopRequireDefault(require("./src/Transition"));
69
+
70
+ var _semiAnimation = require("@douyinfe/semi-animation");
@@ -0,0 +1,70 @@
1
+ import React, { PureComponent } from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import noop from './utils/noop';
4
+ export interface AnimationProps {
5
+ onStart?: Function;
6
+ onFrame?: Function;
7
+ onPause?: Function;
8
+ onResume?: Function;
9
+ onStop?: Function;
10
+ onRest?: Function;
11
+ children?: React.ReactNode;
12
+ from?: Record<string, any>;
13
+ to?: Record<string, any>;
14
+ reverse?: boolean;
15
+ reset?: boolean;
16
+ force?: boolean;
17
+ config?: Record<string, any>;
18
+ autoStart?: boolean;
19
+ forwardInstance?: (value: any) => void;
20
+ immediate?: boolean;
21
+ }
22
+ export default class Animation extends PureComponent<AnimationProps> {
23
+ static propTypes: {
24
+ onStart: PropTypes.Requireable<(...args: any[]) => any>;
25
+ onFrame: PropTypes.Requireable<(...args: any[]) => any>;
26
+ onPause: PropTypes.Requireable<(...args: any[]) => any>;
27
+ onResume: PropTypes.Requireable<(...args: any[]) => any>;
28
+ onStop: PropTypes.Requireable<(...args: any[]) => any>;
29
+ onRest: PropTypes.Requireable<(...args: any[]) => any>;
30
+ children: PropTypes.Requireable<any>;
31
+ from: PropTypes.Requireable<object>;
32
+ to: PropTypes.Requireable<object>;
33
+ reverse: PropTypes.Requireable<boolean>;
34
+ reset: PropTypes.Requireable<boolean>;
35
+ force: PropTypes.Requireable<boolean>;
36
+ config: PropTypes.Requireable<object>;
37
+ autoStart: PropTypes.Requireable<boolean>;
38
+ forwardInstance: PropTypes.Requireable<(...args: any[]) => any>;
39
+ immediate: PropTypes.Requireable<boolean>;
40
+ };
41
+ static defaultProps: {
42
+ autoStart: boolean;
43
+ force: boolean;
44
+ onStart: typeof noop;
45
+ onFrame: typeof noop;
46
+ onPause: typeof noop;
47
+ onResume: typeof noop;
48
+ onStop: typeof noop;
49
+ onRest: typeof noop;
50
+ };
51
+ _mounted: boolean;
52
+ _destroyed: boolean;
53
+ animation: any;
54
+ reverse: () => void;
55
+ destroy: () => void;
56
+ reset: () => void;
57
+ resume: () => void;
58
+ end: () => void;
59
+ stop: () => void;
60
+ pause: () => void;
61
+ start: () => void;
62
+ constructor(props?: {});
63
+ startOrNot(): void;
64
+ componentDidMount(): void;
65
+ componentWillUnmount(): void;
66
+ componentDidUpdate(prevProps?: AnimationProps): void;
67
+ initAnimation: (props?: AnimationProps) => void;
68
+ bindEvents: () => void;
69
+ render(): any;
70
+ }
@@ -0,0 +1,228 @@
1
+ "use strict";
2
+
3
+ var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
4
+
5
+ var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
6
+
7
+ _Object$defineProperty(exports, "__esModule", {
8
+ value: true
9
+ });
10
+
11
+ exports.default = void 0;
12
+
13
+ var _assign = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/assign"));
14
+
15
+ var _forEach = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/for-each"));
16
+
17
+ var _slice = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/slice"));
18
+
19
+ var _reverse = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/reverse"));
20
+
21
+ var _react = require("react");
22
+
23
+ var _propTypes = _interopRequireDefault(require("prop-types"));
24
+
25
+ var _semiAnimation = require("@douyinfe/semi-animation");
26
+
27
+ var _noop = _interopRequireDefault(require("./utils/noop"));
28
+
29
+ /* eslint-disable @typescript-eslint/ban-types */
30
+
31
+ /* eslint-disable react/destructuring-assignment */
32
+ class Animation extends _react.PureComponent {
33
+ constructor() {
34
+ let props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
35
+ super(props);
36
+
37
+ this.initAnimation = props => {
38
+ // eslint-disable-next-line eqeqeq
39
+ props = props == null ? this.props : props; // eslint-disable-next-line prefer-const
40
+
41
+ let {
42
+ from,
43
+ to,
44
+ config,
45
+ reverse
46
+ } = props;
47
+
48
+ if (reverse) {
49
+ [from, to] = [to, from];
50
+ }
51
+
52
+ this.animation = new _semiAnimation.Animation({
53
+ from: (0, _assign.default)({}, from),
54
+ to: (0, _assign.default)({}, to)
55
+ }, (0, _assign.default)({}, config));
56
+ (0, _forEach.default)(_semiAnimation.events).call(_semiAnimation.events, event => {
57
+ const propName = "on".concat(event[0].toUpperCase() + (0, _slice.default)(event).call(event, 1)); // eslint-disable-next-line @typescript-eslint/no-shadow
58
+
59
+ this.animation.on(event, props => {
60
+ // avoid memory leak
61
+ if (this._mounted && !this._destroyed) {
62
+ this.setState({
63
+ currentStyle: (0, _assign.default)({}, props)
64
+ });
65
+ this.props[propName](props);
66
+ }
67
+ });
68
+ });
69
+ this._destroyed = false;
70
+ };
71
+
72
+ this.bindEvents = () => {
73
+ this.startOrNot = () => {
74
+ const {
75
+ immediate,
76
+ autoStart
77
+ } = this.props;
78
+
79
+ if (immediate) {
80
+ this.end();
81
+ } else if (autoStart) {
82
+ this.start();
83
+ }
84
+ };
85
+
86
+ this.start = () => {
87
+ this.animation && this.animation.start();
88
+ };
89
+
90
+ this.pause = () => {
91
+ this.animation && this.animation.pause();
92
+ };
93
+
94
+ this.stop = () => {
95
+ this.animation && this.animation.stop();
96
+ };
97
+
98
+ this.end = () => {
99
+ this.animation && this.animation.end();
100
+ };
101
+
102
+ this.resume = () => {
103
+ this.animation && this.animation.resume();
104
+ };
105
+
106
+ this.reset = () => {
107
+ if (this.animation) {
108
+ this.animation.reset();
109
+ this.startOrNot();
110
+ }
111
+ };
112
+
113
+ this.reverse = () => {
114
+ if (this.animation) {
115
+ var _context;
116
+
117
+ (0, _reverse.default)(_context = this.animation).call(_context);
118
+ this.startOrNot();
119
+ }
120
+ };
121
+
122
+ this.destroy = () => {
123
+ this._destroyed = true;
124
+ this.animation && this.animation.destroy();
125
+ };
126
+ };
127
+
128
+ this.state = {
129
+ currentStyle: {}
130
+ };
131
+ this._mounted = false;
132
+ this._destroyed = false;
133
+ this.initAnimation();
134
+ this.bindEvents();
135
+ }
136
+
137
+ startOrNot() {
138
+ throw new Error('Method not implemented.');
139
+ }
140
+
141
+ componentDidMount() {
142
+ this._mounted = true;
143
+ const {
144
+ forwardInstance
145
+ } = this.props;
146
+
147
+ if (typeof forwardInstance === 'function') {
148
+ forwardInstance(this.animation);
149
+ }
150
+
151
+ this.startOrNot();
152
+ }
153
+
154
+ componentWillUnmount() {
155
+ this._mounted = false;
156
+
157
+ if (this.animation) {
158
+ this.animation.destroy();
159
+ this.animation = null;
160
+ }
161
+ }
162
+
163
+ componentDidUpdate() {
164
+ let prevProps = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
165
+
166
+ if (this.props.reset) {
167
+ if (this.props.from !== prevProps.from || this.props.to !== prevProps.to) {
168
+ this.destroy();
169
+ this.initAnimation();
170
+ this.startOrNot();
171
+ }
172
+ }
173
+
174
+ if (this.props.force) {
175
+ if (this.props.to !== prevProps.to) {
176
+ this.initAnimation((0, _assign.default)((0, _assign.default)({}, this.props), {
177
+ from: prevProps.to
178
+ }));
179
+ this.startOrNot();
180
+ }
181
+ }
182
+ }
183
+
184
+ render() {
185
+ const {
186
+ children
187
+ } = this.props;
188
+
189
+ if (typeof children === 'function') {
190
+ return children(this.animation.getCurrentStates());
191
+ } else if ( /*#__PURE__*/(0, _react.isValidElement)(children)) {
192
+ return children;
193
+ } else {
194
+ return null;
195
+ }
196
+ }
197
+
198
+ }
199
+
200
+ exports.default = Animation;
201
+ Animation.propTypes = {
202
+ onStart: _propTypes.default.func,
203
+ onFrame: _propTypes.default.func,
204
+ onPause: _propTypes.default.func,
205
+ onResume: _propTypes.default.func,
206
+ onStop: _propTypes.default.func,
207
+ onRest: _propTypes.default.func,
208
+ children: _propTypes.default.any,
209
+ from: _propTypes.default.object,
210
+ to: _propTypes.default.object,
211
+ reverse: _propTypes.default.bool,
212
+ reset: _propTypes.default.bool,
213
+ force: _propTypes.default.bool,
214
+ config: _propTypes.default.object,
215
+ autoStart: _propTypes.default.bool,
216
+ forwardInstance: _propTypes.default.func,
217
+ immediate: _propTypes.default.bool
218
+ };
219
+ Animation.defaultProps = {
220
+ autoStart: true,
221
+ force: false,
222
+ onStart: _noop.default,
223
+ onFrame: _noop.default,
224
+ onPause: _noop.default,
225
+ onResume: _noop.default,
226
+ onStop: _noop.default,
227
+ onRest: _noop.default
228
+ };
@@ -0,0 +1,39 @@
1
+ import { Component } from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import noop from './utils/noop';
4
+ export interface KeyFramesProps {
5
+ frames?: any[];
6
+ loop?: boolean;
7
+ forwardInstance?: (value: any) => void;
8
+ onFrame?: (value: any) => void;
9
+ onKeyRest?: (value: Record<string, any>) => void;
10
+ onRest?: (value: Record<string, any>) => void;
11
+ }
12
+ export interface KeyFramesStates {
13
+ currentStyle: Record<string, any>;
14
+ frameIndex: number;
15
+ }
16
+ export default class KeyFrames extends Component<KeyFramesProps, KeyFramesStates> {
17
+ static propTypes: {
18
+ frames: PropTypes.Requireable<any[]>;
19
+ loop: PropTypes.Requireable<boolean>;
20
+ onFrame: PropTypes.Requireable<(...args: any[]) => any>;
21
+ onKeyRest: PropTypes.Requireable<(...args: any[]) => any>;
22
+ onRest: PropTypes.Requireable<(...args: any[]) => any>;
23
+ };
24
+ static defaultProps: {
25
+ frames: any[];
26
+ loop: boolean;
27
+ onKeyRest: typeof noop;
28
+ onRest: typeof noop;
29
+ onFrame: typeof noop;
30
+ };
31
+ instance: any;
32
+ constructor(props?: {});
33
+ onFrame: (props?: {}) => void;
34
+ next: () => void;
35
+ forwardInstance: (instance: any) => void;
36
+ componentDidMount(): void;
37
+ componentWillUnmount(): void;
38
+ render(): JSX.Element;
39
+ }
@@ -0,0 +1,136 @@
1
+ "use strict";
2
+
3
+ var _WeakMap = require("@babel/runtime-corejs3/core-js-stable/weak-map");
4
+
5
+ var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
6
+
7
+ var _Object$getOwnPropertyDescriptor = require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor");
8
+
9
+ var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
10
+
11
+ _Object$defineProperty(exports, "__esModule", {
12
+ value: true
13
+ });
14
+
15
+ exports.default = void 0;
16
+
17
+ var _assign = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/assign"));
18
+
19
+ var _react = _interopRequireWildcard(require("react"));
20
+
21
+ var _propTypes = _interopRequireDefault(require("prop-types"));
22
+
23
+ var _noop = _interopRequireDefault(require("./utils/noop"));
24
+
25
+ var _Animation = _interopRequireDefault(require("./Animation"));
26
+
27
+ 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); }
28
+
29
+ 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; }
30
+
31
+ /* eslint-disable react/destructuring-assignment */
32
+ class KeyFrames extends _react.Component {
33
+ constructor() {
34
+ var _this;
35
+
36
+ let props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
37
+ super(props);
38
+ _this = this;
39
+
40
+ this.onFrame = function () {
41
+ let props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
42
+ const currentStyle = (0, _assign.default)({}, props);
43
+
44
+ _this.props.onFrame(currentStyle);
45
+
46
+ _this.setState({
47
+ currentStyle
48
+ });
49
+ };
50
+
51
+ this.next = () => {
52
+ let {
53
+ frameIndex
54
+ } = this.state;
55
+ const {
56
+ frames,
57
+ loop
58
+ } = this.props;
59
+ frameIndex++;
60
+
61
+ if (frameIndex < frames.length - 1) {
62
+ this.setState({
63
+ frameIndex
64
+ });
65
+ } else {
66
+ frameIndex = 0;
67
+ this.props.onRest(this.state.currentStyle);
68
+
69
+ if (loop) {
70
+ this.setState({
71
+ frameIndex
72
+ });
73
+ }
74
+ }
75
+
76
+ this.props.onKeyRest(this.state.currentStyle);
77
+ };
78
+
79
+ this.forwardInstance = instance => {
80
+ this.instance = instance;
81
+
82
+ if (typeof this.props.forwardInstance === 'function') {
83
+ this.props.forwardInstance(this.instance);
84
+ }
85
+ };
86
+
87
+ this.state = {
88
+ currentStyle: {},
89
+ frameIndex: 0
90
+ };
91
+ }
92
+
93
+ componentDidMount() {// this.props.forwardInstance(this.instance);
94
+ }
95
+
96
+ componentWillUnmount() {
97
+ this.instance && this.instance.destroy();
98
+ }
99
+
100
+ render() {
101
+ const {
102
+ children,
103
+ frames
104
+ } = this.props;
105
+ const {
106
+ frameIndex,
107
+ currentStyle
108
+ } = this.state;
109
+ const from = frames[frameIndex];
110
+ const to = frames[frameIndex + 1];
111
+ return /*#__PURE__*/_react.default.createElement(_Animation.default, (0, _assign.default)({}, this.props, {
112
+ forwardInstance: this.forwardInstance,
113
+ from: from,
114
+ to: to,
115
+ onFrame: this.onFrame,
116
+ onRest: this.next
117
+ }), typeof children === 'function' ? children(currentStyle) : children);
118
+ }
119
+
120
+ }
121
+
122
+ exports.default = KeyFrames;
123
+ KeyFrames.propTypes = {
124
+ frames: _propTypes.default.array,
125
+ loop: _propTypes.default.bool,
126
+ onFrame: _propTypes.default.func,
127
+ onKeyRest: _propTypes.default.func,
128
+ onRest: _propTypes.default.func
129
+ };
130
+ KeyFrames.defaultProps = {
131
+ frames: [],
132
+ loop: false,
133
+ onKeyRest: _noop.default,
134
+ onRest: _noop.default,
135
+ onFrame: _noop.default
136
+ };
@@ -0,0 +1,56 @@
1
+ import React, { PureComponent } from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import noop from './utils/noop';
4
+ export interface StyledAnimationProps {
5
+ className?: string;
6
+ type?: any;
7
+ style?: React.CSSProperties;
8
+ speed?: string | number;
9
+ delay?: string | number;
10
+ reverse?: boolean | string;
11
+ loop?: string | number;
12
+ children?: any;
13
+ onStart?: (value: any) => void;
14
+ onFrame?: (value: any) => void;
15
+ onRest?: (value: any) => void;
16
+ prefixCls?: string;
17
+ timing?: string;
18
+ duration?: string | number;
19
+ fillMode?: string;
20
+ }
21
+ export default class StyledAnimation extends PureComponent<StyledAnimationProps> {
22
+ static propTypes: {
23
+ className: PropTypes.Requireable<string>;
24
+ type: PropTypes.Requireable<any>;
25
+ speed: PropTypes.Requireable<string | number>;
26
+ delay: PropTypes.Requireable<string | number>;
27
+ reverse: PropTypes.Requireable<string | boolean>;
28
+ loop: PropTypes.Requireable<string | number>;
29
+ children: PropTypes.Requireable<any>;
30
+ onStart: PropTypes.Requireable<(...args: any[]) => any>;
31
+ onFrame: PropTypes.Requireable<(...args: any[]) => any>;
32
+ onRest: PropTypes.Requireable<(...args: any[]) => any>;
33
+ prefixCls: PropTypes.Requireable<string>;
34
+ timing: PropTypes.Requireable<string>;
35
+ duration: PropTypes.Requireable<string | number>;
36
+ fillMode: PropTypes.Requireable<string>;
37
+ };
38
+ static defaultProps: {
39
+ prefixCls: string;
40
+ speed: string;
41
+ onFrame: typeof noop;
42
+ onStart: typeof noop;
43
+ onRest: typeof noop;
44
+ };
45
+ constructor(props?: {});
46
+ _generateAnimateEvents: (child: React.ReactElement, props?: StyledAnimationProps) => {
47
+ onAnimationIteration: (...args: any) => void;
48
+ onAnimationStart: (...args: any) => void;
49
+ onAnimationEnd: (...args: any) => void;
50
+ };
51
+ _hasSpeedClass: (speed?: string | number) => boolean;
52
+ _hasTypeClass: (type?: any) => any;
53
+ _hasDelayClass: (delay?: string | number) => boolean;
54
+ _hasLoopClass: (loop?: string | number) => boolean;
55
+ render(): any;
56
+ }