@douyinfe/semi-animation 2.61.0-alpha.1 → 2.61.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/README.md ADDED
@@ -0,0 +1,193 @@
1
+ > Provides basic JS animation engine:
2
+
3
+ - Simulate animation changes based on interpolation,the performance is more natural
4
+ - Support the definition of various easing functions
5
+ - Provides a complete life cycle hook and operation method, allowing developers to freely control the animation
6
+
7
+ ## Install
8
+
9
+ ```sh
10
+ npm install @douyinfe/semi-animation
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ### Animation
16
+
17
+ `semi-animation` provides a class called `Animation` . It has a complete life cycle hook and control method to support operating animation like audio and video.
18
+
19
+ - Use in JS
20
+
21
+ ```js
22
+ import { Animation } from '@douyinfe/semi-animation';
23
+
24
+ const div = document.createElement('span');
25
+ div.style.display = 'inline-block';
26
+ document.body.appendChild(div);
27
+
28
+ const animation = new Animation({
29
+ from: { value: 0 },
30
+ to: { value: 1 },
31
+ });
32
+
33
+ animation.on('frame', props => {
34
+ const num = props.value.toFixed(2);
35
+ div.style.transform = `scale(${num})`;
36
+ div.innerText = num;
37
+ });
38
+ ```
39
+
40
+ - Use in React
41
+
42
+ ```jsx
43
+ import { Animation } from '@douyinfe/semi-animation';
44
+ import { Component } from 'react';
45
+
46
+ class App extends Component {
47
+ constructor(props) {
48
+ super(props);
49
+ this.state = { value: 0 };
50
+
51
+ this.animation = new Animation({
52
+ from: { value: 0 },
53
+ to: { value: 1 },
54
+ });
55
+
56
+ this.animation.on('frame', props => {
57
+ this.setState({ value: props.value.toFixed(2) });
58
+ });
59
+ }
60
+
61
+ componentDidMount() {
62
+ this.animation.start();
63
+ }
64
+
65
+ componentWillUnmount() {
66
+ this.animation.destroy();
67
+ }
68
+
69
+ render() {
70
+ const { value } = this.state;
71
+
72
+ return <div style={{ display: 'inline-block', transform: `scale(${value})` }}>{value}</div>;
73
+ }
74
+ }
75
+ ```
76
+
77
+ - Use in Vue
78
+
79
+ ```html
80
+ <template>
81
+ <div :style="{ transform: `scale(${value})`, display: 'inline-block' }">{{value}}</div>
82
+ </template>
83
+
84
+ <script>
85
+ import { Animation } from '@douyinfe/semi-animation';
86
+
87
+ export default {
88
+ data() {
89
+ return { value: 0 };
90
+ },
91
+ created() {
92
+ this.animation = new Animation({
93
+ from: { value: 0 },
94
+ to: { value: 1 },
95
+ });
96
+
97
+ this.animation.on('frame', props => {
98
+ this.value = props.value;
99
+ });
100
+ },
101
+ mounted() {
102
+ this.animation.start();
103
+ },
104
+ beforeDestroy() {
105
+ this.animation.destroy();
106
+ },
107
+ };
108
+ </script>
109
+ ```
110
+
111
+ Show results:
112
+
113
+ ![](docs/assets/img/semi-animation-demo-simple.gif)
114
+
115
+ ### API
116
+
117
+ ```js
118
+ new Animation({ ...props }, { ...config });
119
+ ```
120
+
121
+ **props**
122
+
123
+ | Prop Name | Type | Required | Default | Description |
124
+ | ------ | ------ | -------- | ------ | -------- |
125
+ | from | Object | Y | | Initial state |
126
+ | to | Object | Y | | Termination state |
127
+
128
+ **config**
129
+
130
+ | Prop Name | Type | Required | Default | Description |
131
+ | -------- | ---------------- | -------- | ------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
132
+ | duration | Number | N | 1000 | Animation duration. If this parameter is passed in, the easing function of the animation will use easing or linear function,unit: ms | |
133
+ | easing | Function\|String | N | | Easing function for animation. If duration is not passed, the spring easing function is used by default. If the duration parameter is passed in, the linear easing function will be used by default.For example, incoming `"cubic-bezier(.17,.67,.83,.67)"` will cause the animation frame update performed according to this easing function | |
134
+ | tension | Number | N | 170 | Tension, used for spring easing function |
135
+ | friction | Number | N | 14 | Friction, used for spring easing function |
136
+
137
+ **Instance methods**
138
+
139
+ | Name | Params | Return | Description |
140
+ | ---------------- | ------------------------------------------------------------ | ------ | --------------------------------------------------------------------- |
141
+ | start | | | Start the animation |
142
+ | pause | | | Pause the animation.After pausing, you must use the resume method to continue playing, not using start. |
143
+ | resume | | | Continue the animation.Only has an effect when the animation is paused. |
144
+ | reverse | | | Reverse the animation |
145
+ | stop | | | Stop the animation.Only have an effect during animation playback, pause, and after end |
146
+ | end | | | Immediately terminate the animation, and pass the final state value of the animation to the callback method |
147
+ | reset | | | Reset the animation |
148
+ | destroy | | | Destroy the animation |
149
+ | getInitialStates | | Object | Get the initial state |
150
+ | getCurrentStates | | Object | Get the current state |
151
+ | getFinalStates | | Object | Get the final state |
152
+ | on | eventName:string, eventHandler:Function(props: object): void | | Binding event callback method。The parameters received by each callback are the current animation state objects. |
153
+
154
+ #### Supported events
155
+
156
+ - `start`: Triggered when the animation starts
157
+ - `pause`: Triggered when the animation pauses(The event is triggered when the animation state is changed from playing to pause, and it will not be triggered in other cases)
158
+ - `resume`: Triggered when the animation continues to play(The event is triggered when the animation state is changed from paused to playing, and it will not be triggered in other cases)
159
+ - `frame`: Triggered when the animation frame is updated
160
+ - `rest`: Triggered when the animation ends(The event will be triggered when the animation ends normally)
161
+ - `stop`: Triggered when the animation stops(This event is triggered when the instance stop method is called)
162
+
163
+ Developers can use `animation.on(eventName: string, cb: Function(currentStyle: object))` to bind the above events.
164
+
165
+ ```jsx
166
+ import { Animation } from '@douyinfe/semi-animation';
167
+ // ...
168
+ const animation = new Animation(
169
+ {
170
+ from: { value1: 0, value2: 1 /* ... */ },
171
+ to: { value1: 1, value2: 2 /* ... */ },
172
+ },
173
+ {
174
+ duration: 1000, // After passing in duration, the default is linear interpolation
175
+ }
176
+ );
177
+
178
+ animation.on('frame', currentState => {
179
+ // currentState: is the state value object at the current moment
180
+ // { value1: xxx, value2: xxx, ... }
181
+ });
182
+
183
+ // The callbacks such as start and pause are the same as the frame above, and the parameters are also the same.
184
+ animation.on('start', currentState => { /* ... */ });
185
+ animation.on('pause', currentState => { /* ... */ });
186
+ animation.on('resume', currentState => { /* ... */ });
187
+ animation.on('rest', currentState => { /* ... */ });
188
+ animation.on('stop', currentState => { /* ... */ });
189
+ ```
190
+
191
+ ## Licence
192
+
193
+ MIT
package/lib/cjs/index.js CHANGED
@@ -44,6 +44,6 @@ var _constants = require("./src/constants");
44
44
  var _Animation = _interopRequireDefault(require("./src/Animation"));
45
45
  var _interpolate = _interopRequireDefault(require("./src/interpolate"));
46
46
  var _presets = _interopRequireDefault(require("./src/presets"));
47
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
48
- function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
49
- function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
47
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
48
+ 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); }
49
+ 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; }
@@ -11,7 +11,7 @@ var _stripStyle = _interopRequireDefault(require("./stripStyle"));
11
11
  var _stepper = _interopRequireDefault(require("./stepper"));
12
12
  var _mapToZero = _interopRequireDefault(require("./mapToZero"));
13
13
  var _wrapValue = _interopRequireDefault(require("./wrapValue"));
14
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
15
  const now = () => Date.now();
16
16
  const msPerFrame = 1000 / 60;
17
17
  /**
@@ -4,4 +4,5 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.events = void 0;
7
- const events = exports.events = ['start', 'frame', 'pause', 'resume', 'stop', 'rest'];
7
+ const events = ['start', 'frame', 'pause', 'resume', 'stop', 'rest'];
8
+ exports.events = events;
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.default = getEasing;
7
7
  exports.easingMap = void 0;
8
8
  var _bezierEasing = _interopRequireDefault(require("bezier-easing"));
9
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
9
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
10
  function minMax(val, min, max) {
11
11
  return Math.min(Math.max(val, min), max);
12
12
  }
@@ -23,14 +23,17 @@ function elastic() {
23
23
  return t => t === 0 || t === 1 ? t : -a * Math.pow(2, 10 * (t - 1)) * Math.sin((t - 1 - p / (Math.PI * 2) * Math.asin(1 / a)) * (Math.PI * 2) / p);
24
24
  }
25
25
  // anime.js/src/index.js
26
- const easingMap = exports.easingMap = (() => {
26
+ const easingMap = (() => {
27
27
  const names = ['Quad', 'Cubic', 'Quart', 'Quint', 'Sine', 'Expo', 'Circ', 'Back', 'Elastic'];
28
28
  // Approximated Penner equations http://matthewlein.com/ceaser/
29
29
  const curves = {
30
30
  In: [[0.55, 0.085, 0.68, 0.53] /* inQuad */, [0.55, 0.055, 0.675, 0.19] /* inCubic */, [0.895, 0.03, 0.685, 0.22] /* inQuart */, [0.755, 0.05, 0.855, 0.06] /* inQuint */, [0.47, 0.0, 0.745, 0.715] /* inSine */, [0.95, 0.05, 0.795, 0.035] /* inExpo */, [0.6, 0.04, 0.98, 0.335] /* inCirc */, [0.6, -0.28, 0.735, 0.045] /* inBack */, elastic /* inElastic */],
31
+
31
32
  Out: [[0.25, 0.46, 0.45, 0.94] /* outQuad */, [0.215, 0.61, 0.355, 1.0] /* outCubic */, [0.165, 0.84, 0.44, 1.0] /* outQuart */, [0.23, 1.0, 0.32, 1.0] /* outQuint */, [0.39, 0.575, 0.565, 1.0] /* outSine */, [0.19, 1.0, 0.22, 1.0] /* outExpo */, [0.075, 0.82, 0.165, 1.0] /* outCirc */, [0.175, 0.885, 0.32, 1.275] /* outBack */, (a, p) => t => 1 - elastic(a, p)(1 - t) /* outElastic */],
33
+
32
34
  InOut: [[0.455, 0.03, 0.515, 0.955] /* inOutQuad */, [0.645, 0.045, 0.355, 1.0] /* inOutCubic */, [0.77, 0.0, 0.175, 1.0] /* inOutQuart */, [0.86, 0.0, 0.07, 1.0] /* inOutQuint */, [0.445, 0.05, 0.55, 0.95] /* inOutSine */, [1.0, 0.0, 0.0, 1.0] /* inOutExpo */, [0.785, 0.135, 0.15, 0.86] /* inOutCirc */, [0.68, -0.55, 0.265, 1.55] /* inOutBack */, (a, p) => t => t < 0.5 ? elastic(a, p)(t * 2) / 2 : 1 - elastic(a, p)(t * -2 + 2) / 2 /* inOutElastic */]
33
35
  };
36
+
34
37
  const eases = {
35
38
  linear: [0.25, 0.25, 0.75, 0.75]
36
39
  };
@@ -46,6 +49,7 @@ const easingMap = exports.easingMap = (() => {
46
49
  * @param {string|Function} easing
47
50
  * @returns {Function}
48
51
  */
52
+ exports.easingMap = easingMap;
49
53
  function getEasing(easing) {
50
54
  if (typeof easing === 'function') {
51
55
  return easing;
@@ -8,7 +8,7 @@ exports.default = void 0;
8
8
  * stiffness is like tension
9
9
  * damping is like friction
10
10
  */
11
- var _default = exports.default = {
11
+ var _default = {
12
12
  default: {
13
13
  tension: 170,
14
14
  friction: 26
@@ -33,4 +33,5 @@ var _default = exports.default = {
33
33
  tension: 280,
34
34
  friction: 120
35
35
  }
36
- };
36
+ };
37
+ exports.default = _default;
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = shouldStopAnimation;
7
7
  var _shouldUseBezier = _interopRequireDefault(require("./shouldUseBezier"));
8
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
8
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
9
9
  /**
10
10
  * usage assumption: currentStyle values have already been rendered but it says
11
11
  * nothing of whether currentStyle is stale (see unreadPropStyle)
@@ -12,4 +12,5 @@ const log = function (text) {
12
12
  console.log(text, ...rest);
13
13
  }
14
14
  };
15
- var _default = exports.default = log;
15
+ var _default = log;
16
+ exports.default = _default;
@@ -7,7 +7,7 @@ exports.default = wrapValue;
7
7
  var _getEasing = _interopRequireDefault(require("./getEasing"));
8
8
  var _presets = _interopRequireDefault(require("./presets"));
9
9
  var _shouldUseBezier = _interopRequireDefault(require("./shouldUseBezier"));
10
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
11
  const defaultConfig = Object.assign(Object.assign({}, _presets.default.default), {
12
12
  precision: 0.01
13
13
  });
@@ -20,9 +20,12 @@ export const easingMap = (() => {
20
20
  // Approximated Penner equations http://matthewlein.com/ceaser/
21
21
  const curves = {
22
22
  In: [[0.55, 0.085, 0.68, 0.53] /* inQuad */, [0.55, 0.055, 0.675, 0.19] /* inCubic */, [0.895, 0.03, 0.685, 0.22] /* inQuart */, [0.755, 0.05, 0.855, 0.06] /* inQuint */, [0.47, 0.0, 0.745, 0.715] /* inSine */, [0.95, 0.05, 0.795, 0.035] /* inExpo */, [0.6, 0.04, 0.98, 0.335] /* inCirc */, [0.6, -0.28, 0.735, 0.045] /* inBack */, elastic /* inElastic */],
23
+
23
24
  Out: [[0.25, 0.46, 0.45, 0.94] /* outQuad */, [0.215, 0.61, 0.355, 1.0] /* outCubic */, [0.165, 0.84, 0.44, 1.0] /* outQuart */, [0.23, 1.0, 0.32, 1.0] /* outQuint */, [0.39, 0.575, 0.565, 1.0] /* outSine */, [0.19, 1.0, 0.22, 1.0] /* outExpo */, [0.075, 0.82, 0.165, 1.0] /* outCirc */, [0.175, 0.885, 0.32, 1.275] /* outBack */, (a, p) => t => 1 - elastic(a, p)(1 - t) /* outElastic */],
25
+
24
26
  InOut: [[0.455, 0.03, 0.515, 0.955] /* inOutQuad */, [0.645, 0.045, 0.355, 1.0] /* inOutCubic */, [0.77, 0.0, 0.175, 1.0] /* inOutQuart */, [0.86, 0.0, 0.07, 1.0] /* inOutQuint */, [0.445, 0.05, 0.55, 0.95] /* inOutSine */, [1.0, 0.0, 0.0, 1.0] /* inOutExpo */, [0.785, 0.135, 0.15, 0.86] /* inOutCirc */, [0.68, -0.55, 0.265, 1.55] /* inOutBack */, (a, p) => t => t < 0.5 ? elastic(a, p)(t * 2) / 2 : 1 - elastic(a, p)(t * -2 + 2) / 2 /* inOutElastic */]
25
27
  };
28
+
26
29
  const eases = {
27
30
  linear: [0.25, 0.25, 0.75, 0.75]
28
31
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@douyinfe/semi-animation",
3
- "version": "2.61.0-alpha.1",
3
+ "version": "2.61.0",
4
4
  "description": "animation base library for semi-ui",
5
5
  "keywords": [
6
6
  "animation",
@@ -42,5 +42,5 @@
42
42
  "merge2": "^1.4.1",
43
43
  "react-storybook-addon-props-combinations": "^1.1.0"
44
44
  },
45
- "gitHead": "ba06de12d059c24363f1ef151dbf4076ea3969a5"
45
+ "gitHead": "8f2bdc04e4622628802f4e4469446ca275ebba8f"
46
46
  }