@douyinfe/semi-animation-react 2.1.0-alpha.1 → 2.1.0-alpha.2

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.
@@ -11,8 +11,7 @@ import PropTypes from 'prop-types';
11
11
  import { Animation as SemiAnimation, events } from '@douyinfe/semi-animation';
12
12
  import noop from './utils/noop';
13
13
  export default class Animation extends PureComponent {
14
- constructor() {
15
- let props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
14
+ constructor(props = {}) {
16
15
  super(props);
17
16
 
18
17
  this.initAnimation = props => {
@@ -144,9 +143,7 @@ export default class Animation extends PureComponent {
144
143
  }
145
144
  }
146
145
 
147
- componentDidUpdate() {
148
- let prevProps = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
149
-
146
+ componentDidUpdate(prevProps = {}) {
150
147
  if (this.props.reset) {
151
148
  if (this.props.from !== prevProps.from || this.props.to !== prevProps.to) {
152
149
  this.destroy();
@@ -6,21 +6,14 @@ import PropTypes from 'prop-types';
6
6
  import noop from './utils/noop';
7
7
  import Animation from './Animation';
8
8
  export default class KeyFrames extends Component {
9
- constructor() {
10
- var _this;
11
-
12
- let props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
9
+ constructor(props = {}) {
13
10
  super(props);
14
- _this = this;
15
-
16
- this.onFrame = function () {
17
- let props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
18
11
 
12
+ this.onFrame = (props = {}) => {
19
13
  const currentStyle = _Object$assign({}, props);
20
14
 
21
- _this.props.onFrame(currentStyle);
22
-
23
- _this.setState({
15
+ this.props.onFrame(currentStyle);
16
+ this.setState({
24
17
  currentStyle
25
18
  });
26
19
  };
@@ -1,5 +1,6 @@
1
1
  import React, { PureComponent } from 'react';
2
2
  import PropTypes from 'prop-types';
3
+ import '@douyinfe/semi-animation-styled';
3
4
  import noop from './utils/noop';
4
5
  export interface StyledAnimationProps {
5
6
  className?: string;
@@ -19,6 +19,8 @@ import _Object$assign from "@babel/runtime-corejs3/core-js-stable/object/assign"
19
19
  import { PureComponent, isValidElement, cloneElement, Children } from 'react';
20
20
  import PropTypes from 'prop-types';
21
21
  import classnames from 'classnames';
22
+ import '@douyinfe/semi-animation-styled'; // eslint-disable-next-line @typescript-eslint/no-duplicate-imports
23
+
22
24
  import { types as styledTypes, loops, delays, speeds } from '@douyinfe/semi-animation-styled';
23
25
  import noop from './utils/noop';
24
26
  import invokeFns from './utils/invokeFns';
@@ -26,59 +28,22 @@ import invokeFns from './utils/invokeFns';
26
28
  const types = _reduceInstanceProperty(_context = _Object$values(styledTypes)).call(_context, (arr, cur) => [...arr, ...cur], []);
27
29
 
28
30
  export default class StyledAnimation extends PureComponent {
29
- constructor() {
30
- var _this;
31
-
32
- let props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
31
+ constructor(props = {}) {
33
32
  super(props);
34
- _this = this;
35
-
36
- this._generateAnimateEvents = function (child) {
37
- let props = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
38
- return {
39
- onAnimationIteration: function () {
40
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
41
- args[_key] = arguments[_key];
42
- }
43
-
44
- return invokeFns([child && child.props && child.props.onAnimationIteration, props.onFrame], args);
45
- },
46
- onAnimationStart: function () {
47
- for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
48
- args[_key2] = arguments[_key2];
49
- }
50
-
51
- return invokeFns([child && child.props && child.props.onAnimationStart, props.onStart], args);
52
- },
53
- onAnimationEnd: function () {
54
- for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
55
- args[_key3] = arguments[_key3];
56
- }
57
-
58
- return invokeFns([child && child.props && child.props.onAnimationEnd, props.onRest], args);
59
- }
60
- };
61
- };
62
33
 
63
- this._hasSpeedClass = function () {
64
- let speed = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _this.props.speed;
65
- return speed != null && _includesInstanceProperty(speeds).call(speeds, speed);
66
- };
34
+ this._generateAnimateEvents = (child, props = {}) => ({
35
+ onAnimationIteration: (...args) => invokeFns([child && child.props && child.props.onAnimationIteration, props.onFrame], args),
36
+ onAnimationStart: (...args) => invokeFns([child && child.props && child.props.onAnimationStart, props.onStart], args),
37
+ onAnimationEnd: (...args) => invokeFns([child && child.props && child.props.onAnimationEnd, props.onRest], args)
38
+ });
67
39
 
68
- this._hasTypeClass = function () {
69
- let type = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _this.props.type;
70
- return type != null && _includesInstanceProperty(types).call(types, type);
71
- };
40
+ this._hasSpeedClass = (speed = this.props.speed) => speed != null && _includesInstanceProperty(speeds).call(speeds, speed);
72
41
 
73
- this._hasDelayClass = function () {
74
- let delay = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _this.props.delay;
75
- return delay != null && _includesInstanceProperty(delays).call(delays, delay);
76
- };
42
+ this._hasTypeClass = (type = this.props.type) => type != null && _includesInstanceProperty(types).call(types, type);
77
43
 
78
- this._hasLoopClass = function () {
79
- let loop = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _this.props.loop;
80
- return loop != null && _includesInstanceProperty(loops).call(loops, loop);
81
- };
44
+ this._hasDelayClass = (delay = this.props.delay) => delay != null && _includesInstanceProperty(delays).call(delays, delay);
45
+
46
+ this._hasLoopClass = (loop = this.props.loop) => loop != null && _includesInstanceProperty(loops).call(loops, loop);
82
47
  }
83
48
 
84
49
  render() {
@@ -21,8 +21,7 @@ import PropTypes from 'prop-types';
21
21
  import StyledAnimation from './StyledAnimation';
22
22
  import noop from './utils/noop';
23
23
  export default class StyledTransition extends Component {
24
- constructor() {
25
- let props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
24
+ constructor(props = {}) {
26
25
  super(props);
27
26
 
28
27
  this._isControlled = () => {
@@ -21,8 +21,7 @@ import PropTypes from 'prop-types';
21
21
  import React, { Component, isValidElement } from 'react';
22
22
  import noop from './utils/noop';
23
23
  export default class Transition extends Component {
24
- constructor() {
25
- let props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
24
+ constructor(props = {}) {
26
25
  super(props);
27
26
 
28
27
  this._isControlled = () => {
@@ -1,8 +1,6 @@
1
1
  import _Array$isArray from "@babel/runtime-corejs3/core-js-stable/array/is-array";
2
2
  import _forEachInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/for-each";
3
- export default function invokeFns(fns) {
4
- let args = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
5
-
3
+ export default function invokeFns(fns, args = []) {
6
4
  if (_Array$isArray(fns) && fns.length) {
7
5
  _forEachInstanceProperty(fns).call(fns, fn => {
8
6
  if (typeof fn === 'function') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@douyinfe/semi-animation-react",
3
- "version": "2.1.0-alpha.1",
3
+ "version": "2.1.0-alpha.2",
4
4
  "description": "motion library for semi-ui-react",
5
5
  "keywords": [
6
6
  "motion",
@@ -12,7 +12,7 @@
12
12
  "README.md"
13
13
  ],
14
14
  "license": "MIT",
15
- "main": "lib/cjs/index.js",
15
+ "main": "lib/es/index.js",
16
16
  "module": "lib/es/index.js",
17
17
  "typings": "lib/es/index.d.ts",
18
18
  "repository": {
@@ -26,8 +26,8 @@
26
26
  },
27
27
  "dependencies": {
28
28
  "@babel/runtime-corejs3": "^7.15.4",
29
- "@douyinfe/semi-animation": "2.1.0-alpha.1",
30
- "@douyinfe/semi-animation-styled": "2.1.0-alpha.1",
29
+ "@douyinfe/semi-animation": "2.1.0-alpha.2",
30
+ "@douyinfe/semi-animation-styled": "2.1.0-alpha.2",
31
31
  "classnames": "^2.2.6"
32
32
  },
33
33
  "peerDependencies": {
@@ -51,5 +51,5 @@
51
51
  "prop-types": "15.7.2",
52
52
  "react-storybook-addon-props-combinations": "^1.1.0"
53
53
  },
54
- "gitHead": "1c0cec8640fb0f5da95138054e3fed1f304deff8"
54
+ "gitHead": "50381484f8df8aaa00285cf0a2ee01edf0083115"
55
55
  }
@@ -1,6 +0,0 @@
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';
package/lib/cjs/index.js DELETED
@@ -1,70 +0,0 @@
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");
@@ -1,70 +0,0 @@
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
- }
@@ -1,228 +0,0 @@
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
- };
@@ -1,39 +0,0 @@
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
- }