@douyinfe/semi-animation-react 2.36.0-beta.0 → 2.36.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 CHANGED
@@ -45,17 +45,10 @@ Object.defineProperty(exports, "presets", {
45
45
  return _semiAnimation.presets;
46
46
  }
47
47
  });
48
-
49
48
  var _StyledAnimation = _interopRequireDefault(require("./src/StyledAnimation"));
50
-
51
49
  var _StyledTransition = _interopRequireDefault(require("./src/StyledTransition"));
52
-
53
50
  var _Animation = _interopRequireDefault(require("./src/Animation"));
54
-
55
51
  var _KeyFrames = _interopRequireDefault(require("./src/KeyFrames"));
56
-
57
52
  var _Transition = _interopRequireDefault(require("./src/Transition"));
58
-
59
53
  var _semiAnimation = require("@douyinfe/semi-animation");
60
-
61
54
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -4,48 +4,38 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  var _react = require("react");
9
-
10
8
  var _propTypes = _interopRequireDefault(require("prop-types"));
11
-
12
9
  var _semiAnimation = require("@douyinfe/semi-animation");
13
-
14
10
  var _noop = _interopRequireDefault(require("./utils/noop"));
15
-
16
11
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
-
18
12
  /* eslint-disable @typescript-eslint/ban-types */
19
-
20
13
  /* eslint-disable react/destructuring-assignment */
14
+
21
15
  class Animation extends _react.PureComponent {
22
16
  constructor() {
23
17
  let props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
24
18
  super(props);
25
-
26
19
  this.initAnimation = props => {
27
20
  // eslint-disable-next-line eqeqeq
28
- props = props == null ? this.props : props; // eslint-disable-next-line prefer-const
29
-
21
+ props = props == null ? this.props : props;
22
+ // eslint-disable-next-line prefer-const
30
23
  let {
31
24
  from,
32
25
  to,
33
26
  config,
34
27
  reverse
35
28
  } = props;
36
-
37
29
  if (reverse) {
38
30
  [from, to] = [to, from];
39
31
  }
40
-
41
32
  this.animation = new _semiAnimation.Animation({
42
33
  from: Object.assign({}, from),
43
34
  to: Object.assign({}, to)
44
35
  }, Object.assign({}, config));
45
-
46
36
  _semiAnimation.events.forEach(event => {
47
- const propName = `on${event[0].toUpperCase() + event.slice(1)}`; // eslint-disable-next-line @typescript-eslint/no-shadow
48
-
37
+ const propName = `on${event[0].toUpperCase() + event.slice(1)}`;
38
+ // eslint-disable-next-line @typescript-eslint/no-shadow
49
39
  this.animation.on(event, props => {
50
40
  // avoid memory leak
51
41
  if (this._mounted && !this._destroyed) {
@@ -56,64 +46,52 @@ class Animation extends _react.PureComponent {
56
46
  }
57
47
  });
58
48
  });
59
-
60
49
  this._destroyed = false;
61
50
  };
62
-
63
51
  this.bindEvents = () => {
64
52
  this.startOrNot = () => {
65
53
  const {
66
54
  immediate,
67
55
  autoStart
68
56
  } = this.props;
69
-
70
57
  if (immediate) {
71
58
  this.end();
72
59
  } else if (autoStart) {
73
60
  this.start();
74
61
  }
75
62
  };
76
-
77
63
  this.start = () => {
78
64
  this.animation && this.animation.start();
79
65
  };
80
-
81
66
  this.pause = () => {
82
67
  this.animation && this.animation.pause();
83
68
  };
84
-
85
69
  this.stop = () => {
86
70
  this.animation && this.animation.stop();
87
71
  };
88
-
89
72
  this.end = () => {
90
73
  this.animation && this.animation.end();
91
74
  };
92
-
93
75
  this.resume = () => {
94
76
  this.animation && this.animation.resume();
95
77
  };
96
-
97
78
  this.reset = () => {
98
79
  if (this.animation) {
99
80
  this.animation.reset();
100
81
  this.startOrNot();
101
82
  }
102
83
  };
103
-
104
84
  this.reverse = () => {
105
85
  if (this.animation) {
106
86
  this.animation.reverse();
107
87
  this.startOrNot();
108
88
  }
109
89
  };
110
-
111
90
  this.destroy = () => {
112
91
  this._destroyed = true;
113
92
  this.animation && this.animation.destroy();
114
93
  };
115
94
  };
116
-
117
95
  this.state = {
118
96
  currentStyle: {}
119
97
  };
@@ -122,42 +100,33 @@ class Animation extends _react.PureComponent {
122
100
  this.initAnimation();
123
101
  this.bindEvents();
124
102
  }
125
-
126
103
  startOrNot() {
127
104
  throw new Error('Method not implemented.');
128
105
  }
129
-
130
106
  componentDidMount() {
131
107
  this._mounted = true;
132
108
  const {
133
109
  forwardInstance
134
110
  } = this.props;
135
-
136
111
  if (this.animation === null) {
137
112
  // didmount/willUnmount may be called twice when React.StrictMode is true in React 18, we need to ensure that this.animation is correct
138
113
  this.initAnimation();
139
114
  this.bindEvents();
140
115
  }
141
-
142
116
  if (typeof forwardInstance === 'function') {
143
117
  forwardInstance(this.animation);
144
118
  }
145
-
146
119
  this.startOrNot();
147
120
  }
148
-
149
121
  componentWillUnmount() {
150
122
  this._mounted = false;
151
-
152
123
  if (this.animation) {
153
124
  this.animation.destroy();
154
125
  this.animation = null;
155
126
  }
156
127
  }
157
-
158
128
  componentDidUpdate() {
159
129
  let prevProps = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
160
-
161
130
  if (this.props.reset) {
162
131
  if (this.props.from !== prevProps.from || this.props.to !== prevProps.to) {
163
132
  this.destroy();
@@ -165,7 +134,6 @@ class Animation extends _react.PureComponent {
165
134
  this.startOrNot();
166
135
  }
167
136
  }
168
-
169
137
  if (this.props.force) {
170
138
  if (this.props.to !== prevProps.to) {
171
139
  this.initAnimation(Object.assign(Object.assign({}, this.props), {
@@ -175,12 +143,10 @@ class Animation extends _react.PureComponent {
175
143
  }
176
144
  }
177
145
  }
178
-
179
146
  render() {
180
147
  const {
181
148
  children
182
149
  } = this.props;
183
-
184
150
  if (typeof children === 'function') {
185
151
  return children(this.animation.getCurrentStates());
186
152
  } else if ( /*#__PURE__*/(0, _react.isValidElement)(children)) {
@@ -189,9 +155,7 @@ class Animation extends _react.PureComponent {
189
155
  return null;
190
156
  }
191
157
  }
192
-
193
158
  }
194
-
195
159
  exports.default = Animation;
196
160
  Animation.propTypes = {
197
161
  onStart: _propTypes.default.func,
@@ -4,41 +4,29 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  var _react = _interopRequireWildcard(require("react"));
9
-
10
8
  var _propTypes = _interopRequireDefault(require("prop-types"));
11
-
12
9
  var _noop = _interopRequireDefault(require("./utils/noop"));
13
-
14
10
  var _Animation = _interopRequireDefault(require("./Animation"));
15
-
16
11
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
-
18
12
  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); }
19
-
20
13
  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; }
21
-
22
14
  /* eslint-disable react/destructuring-assignment */
15
+
23
16
  class KeyFrames extends _react.Component {
24
17
  constructor() {
25
18
  var _this;
26
-
27
19
  let props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
28
20
  super(props);
29
21
  _this = this;
30
-
31
22
  this.onFrame = function () {
32
23
  let props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
33
24
  const currentStyle = Object.assign({}, props);
34
-
35
25
  _this.props.onFrame(currentStyle);
36
-
37
26
  _this.setState({
38
27
  currentStyle
39
28
  });
40
29
  };
41
-
42
30
  this.next = () => {
43
31
  let {
44
32
  frameIndex
@@ -48,7 +36,6 @@ class KeyFrames extends _react.Component {
48
36
  loop
49
37
  } = this.props;
50
38
  frameIndex++;
51
-
52
39
  if (frameIndex < frames.length - 1) {
53
40
  this.setState({
54
41
  frameIndex
@@ -56,38 +43,31 @@ class KeyFrames extends _react.Component {
56
43
  } else {
57
44
  frameIndex = 0;
58
45
  this.props.onRest(this.state.currentStyle);
59
-
60
46
  if (loop) {
61
47
  this.setState({
62
48
  frameIndex
63
49
  });
64
50
  }
65
51
  }
66
-
67
52
  this.props.onKeyRest(this.state.currentStyle);
68
53
  };
69
-
70
54
  this.forwardInstance = instance => {
71
55
  this.instance = instance;
72
-
73
56
  if (typeof this.props.forwardInstance === 'function') {
74
57
  this.props.forwardInstance(this.instance);
75
58
  }
76
59
  };
77
-
78
60
  this.state = {
79
61
  currentStyle: {},
80
62
  frameIndex: 0
81
63
  };
82
64
  }
83
-
84
- componentDidMount() {// this.props.forwardInstance(this.instance);
65
+ componentDidMount() {
66
+ // this.props.forwardInstance(this.instance);
85
67
  }
86
-
87
68
  componentWillUnmount() {
88
69
  this.instance && this.instance.destroy();
89
70
  }
90
-
91
71
  render() {
92
72
  const {
93
73
  children,
@@ -107,9 +87,7 @@ class KeyFrames extends _react.Component {
107
87
  onRest: this.next
108
88
  }), typeof children === 'function' ? children(currentStyle) : children);
109
89
  }
110
-
111
90
  }
112
-
113
91
  exports.default = KeyFrames;
114
92
  KeyFrames.propTypes = {
115
93
  frames: _propTypes.default.array,
@@ -4,40 +4,26 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  var _react = require("react");
9
-
10
8
  var _propTypes = _interopRequireDefault(require("prop-types"));
11
-
12
9
  var _classnames = _interopRequireDefault(require("classnames"));
13
-
14
10
  var _semiAnimationStyled = require("@douyinfe/semi-animation-styled");
15
-
16
11
  var _noop = _interopRequireDefault(require("./utils/noop"));
17
-
18
12
  var _invokeFns = _interopRequireDefault(require("./utils/invokeFns"));
19
-
20
13
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
-
22
14
  /* eslint-disable react/destructuring-assignment */
23
-
24
15
  /* eslint-disable prefer-const */
25
-
26
16
  /* eslint-disable eqeqeq */
27
-
28
17
  /* eslint-disable import/no-duplicates */
29
-
30
18
  /* eslint-disable no-duplicate-imports */
31
- const types = Object.values(_semiAnimationStyled.types).reduce((arr, cur) => [...arr, ...cur], []);
32
19
 
20
+ const types = Object.values(_semiAnimationStyled.types).reduce((arr, cur) => [...arr, ...cur], []);
33
21
  class StyledAnimation extends _react.PureComponent {
34
22
  constructor() {
35
23
  var _this;
36
-
37
24
  let props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
38
25
  super(props);
39
26
  _this = this;
40
-
41
27
  this._generateAnimateEvents = function (child) {
42
28
  let props = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
43
29
  return {
@@ -45,47 +31,39 @@ class StyledAnimation extends _react.PureComponent {
45
31
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
46
32
  args[_key] = arguments[_key];
47
33
  }
48
-
49
34
  return (0, _invokeFns.default)([child && child.props && child.props.onAnimationIteration, props.onFrame], args);
50
35
  },
51
36
  onAnimationStart: function () {
52
37
  for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
53
38
  args[_key2] = arguments[_key2];
54
39
  }
55
-
56
40
  return (0, _invokeFns.default)([child && child.props && child.props.onAnimationStart, props.onStart], args);
57
41
  },
58
42
  onAnimationEnd: function () {
59
43
  for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
60
44
  args[_key3] = arguments[_key3];
61
45
  }
62
-
63
46
  return (0, _invokeFns.default)([child && child.props && child.props.onAnimationEnd, props.onRest], args);
64
47
  }
65
48
  };
66
49
  };
67
-
68
50
  this._hasSpeedClass = function () {
69
51
  let speed = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _this.props.speed;
70
52
  return speed != null && _semiAnimationStyled.speeds.includes(speed);
71
53
  };
72
-
73
54
  this._hasTypeClass = function () {
74
55
  let type = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _this.props.type;
75
56
  return type != null && types.includes(type);
76
57
  };
77
-
78
58
  this._hasDelayClass = function () {
79
59
  let delay = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _this.props.delay;
80
60
  return delay != null && _semiAnimationStyled.delays.includes(delay);
81
61
  };
82
-
83
62
  this._hasLoopClass = function () {
84
63
  let loop = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _this.props.loop;
85
64
  return loop != null && _semiAnimationStyled.loops.includes(loop);
86
65
  };
87
66
  }
88
-
89
67
  render() {
90
68
  let {
91
69
  type,
@@ -100,15 +78,10 @@ class StyledAnimation extends _react.PureComponent {
100
78
  className,
101
79
  fillMode
102
80
  } = this.props;
103
-
104
81
  const hasTypeClass = this._hasTypeClass();
105
-
106
82
  const hasSpeedClass = this._hasSpeedClass();
107
-
108
83
  const hasDelayClass = this._hasDelayClass();
109
-
110
84
  const hasLoopClass = this._hasLoopClass();
111
-
112
85
  const animateCls = className || (0, _classnames.default)(`${prefixCls}-animated`, {
113
86
  [`${prefixCls}-${type}`]: Boolean(type),
114
87
  [`${prefixCls}-speed-${speed}`]: hasSpeedClass,
@@ -124,27 +97,22 @@ class StyledAnimation extends _react.PureComponent {
124
97
  animationDirection: reverse ? 'alternate' : 'normal',
125
98
  animationFillMode: fillMode
126
99
  };
127
-
128
100
  if ( /*#__PURE__*/(0, _react.isValidElement)(children)) {
129
101
  children = _react.Children.map(children, child => {
130
102
  const animateEvents = this._generateAnimateEvents(child, this.props);
131
-
132
103
  return /*#__PURE__*/(0, _react.cloneElement)(child, Object.assign({
133
104
  className: (0, _classnames.default)(child.props.className, animateCls),
134
105
  style: Object.assign(Object.assign({}, child.props.style), this.props.style)
135
106
  }, animateEvents));
136
107
  });
137
108
  }
138
-
139
109
  return typeof children === 'function' ? children({
140
110
  animateCls,
141
111
  animateStyle,
142
112
  animateEvents: this._generateAnimateEvents(null, this.props)
143
113
  }) : children;
144
114
  }
145
-
146
115
  }
147
-
148
116
  exports.default = StyledAnimation;
149
117
  StyledAnimation.propTypes = {
150
118
  className: _propTypes.default.string,
@@ -4,26 +4,16 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  var _react = _interopRequireWildcard(require("react"));
9
-
10
8
  var _propTypes = _interopRequireDefault(require("prop-types"));
11
-
12
9
  var _StyledAnimation = _interopRequireDefault(require("./StyledAnimation"));
13
-
14
10
  var _noop = _interopRequireDefault(require("./utils/noop"));
15
-
16
11
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
-
18
12
  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); }
19
-
20
13
  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; }
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
  }
@@ -31,19 +21,15 @@ var __rest = void 0 && (void 0).__rest || function (s, e) {
31
21
  };
32
22
  /* eslint-disable eqeqeq */
33
23
 
34
-
35
24
  class StyledTransition extends _react.Component {
36
25
  constructor() {
37
26
  let props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
38
27
  super(props);
39
-
40
28
  this._isControlled = () => [true, false, 'enter', 'leave'].includes(this.props.state);
41
-
42
29
  this.onRest = props => {
43
30
  const {
44
31
  state
45
32
  } = this.state;
46
-
47
33
  if (state === 'enter') {
48
34
  this.props.didEnter(props);
49
35
  } else if (state === 'leave') {
@@ -53,102 +39,81 @@ class StyledTransition extends _react.Component {
53
39
  });
54
40
  this.props.didLeave(props);
55
41
  }
56
-
57
42
  this.props.onRest(props);
58
43
  };
59
-
60
44
  this.onStart = props => {
61
45
  const {
62
46
  state
63
47
  } = this.state;
64
-
65
48
  if (state === 'enter') {
66
49
  this.props.willEnter(props);
67
50
  } else if (state === 'leave') {
68
51
  this.props.willLeave(props);
69
52
  }
70
-
71
53
  this.props.onStart(props);
72
54
  };
73
-
74
55
  this.state = {
75
56
  state: '',
76
57
  lastChildren: null,
77
58
  currentChildren: null
78
59
  };
79
60
  }
80
-
81
61
  static getDerivedStateFromProps(props, state) {
82
62
  const willUpdateStates = {};
83
-
84
63
  if (props.children !== state.currentChildren) {
85
64
  willUpdateStates.lastChildren = state.currentChildren;
86
65
  willUpdateStates.currentChildren = props.children;
87
-
88
66
  if (props.children == null) {
89
67
  willUpdateStates.state = 'leave';
90
68
  } else {
91
69
  willUpdateStates.state = 'enter';
92
70
  }
93
71
  }
94
-
95
72
  if (props.state != null && props.state !== state.state) {
96
73
  willUpdateStates.state = props.state;
97
74
  }
98
-
99
75
  return willUpdateStates;
100
76
  }
101
-
102
77
  render() {
103
78
  const _a = this.props,
104
- {
105
- enter,
106
- leave
107
- } = _a,
108
- restProps = __rest(_a, ["enter", "leave"]);
109
-
79
+ {
80
+ enter,
81
+ leave
82
+ } = _a,
83
+ restProps = __rest(_a, ["enter", "leave"]);
110
84
  const {
111
85
  currentChildren,
112
86
  lastChildren
113
87
  } = this.state;
114
-
115
88
  const isControlled = this._isControlled();
116
-
117
89
  let children, type;
118
90
  let {
119
91
  state
120
92
  } = this.state;
121
-
122
93
  if (isControlled) {
123
94
  children = this.props.children;
124
95
  state = this.props.state;
125
96
  } else if (currentChildren == null && lastChildren == null) {
126
97
  return null;
127
98
  }
128
-
129
99
  if (state === 'enter') {
130
100
  type = enter;
131
-
132
101
  if (!isControlled) {
133
102
  children = currentChildren;
134
103
  }
135
104
  } else if (state === 'leave') {
136
105
  type = leave;
137
-
138
106
  if (!isControlled) {
139
107
  children = lastChildren;
140
108
  }
141
109
  }
142
-
143
110
  return /*#__PURE__*/_react.default.createElement(_StyledAnimation.default, Object.assign({}, restProps, {
144
111
  type: type,
145
112
  onStart: this.onStart,
146
113
  onRest: this.onRest
147
114
  }), children);
148
115
  }
149
-
150
116
  }
151
-
152
117
  exports.default = StyledTransition;
153
118
  StyledTransition.propTypes = {
154
119
  state: _propTypes.default.string,