react-ui-animate 1.4.4 → 2.0.0-rc.1
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/.vscode/settings.json +3 -0
- package/dist/animation/animationType.d.ts +7 -0
- package/dist/animation/getInitialConfig.d.ts +3 -3
- package/dist/animation/index.d.ts +5 -4
- package/dist/animation/interpolation.d.ts +3 -11
- package/dist/animation/modules.d.ts +18 -10
- package/dist/animation/useAnimatedValue.d.ts +11 -23
- package/dist/animation/useMountedValue.d.ts +5 -14
- package/dist/gestures/controllers/DragGesture.d.ts +2 -2
- package/dist/index.js +69 -109
- package/dist/index.js.map +1 -1
- package/dist/utils/delay.d.ts +5 -0
- package/dist/utils/index.d.ts +2 -1
- package/package.json +2 -2
- package/src/animation/animationType.ts +9 -0
- package/src/animation/getInitialConfig.ts +12 -13
- package/src/animation/index.ts +9 -4
- package/src/animation/interpolation.ts +5 -38
- package/src/animation/modules.tsx +12 -12
- package/src/animation/useAnimatedValue.ts +22 -89
- package/src/animation/useMountedValue.ts +25 -37
- package/src/gestures/controllers/DragGesture.ts +16 -15
- package/src/utils/delay.ts +9 -0
- package/src/utils/index.ts +2 -1
package/dist/index.js
CHANGED
|
@@ -3,25 +3,6 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
3
3
|
var reMotion = require('@raidipesh78/re-motion');
|
|
4
4
|
var React = require('react');
|
|
5
5
|
|
|
6
|
-
/**
|
|
7
|
-
* interpolate function maps input range to output range
|
|
8
|
-
* @param value - number | TransitionValue
|
|
9
|
-
* @param inputRange - Array<number>
|
|
10
|
-
* @param outputRange - Array<string | number>
|
|
11
|
-
* @param extrapolateConfig - "clamp" | "identity" | "extend"
|
|
12
|
-
* @returns - number | TransitionValue
|
|
13
|
-
*/
|
|
14
|
-
function interpolate(value, inputRange, outputRange, extrapolateConfig) {
|
|
15
|
-
if (typeof value === "object" && reMotion.isSubscriber(value)) {
|
|
16
|
-
return reMotion.interpolateTransitionValue(value, inputRange, outputRange, extrapolateConfig);
|
|
17
|
-
}
|
|
18
|
-
else if (typeof value === "number") {
|
|
19
|
-
return reMotion.interpolateNumbers(value, inputRange, outputRange, extrapolateConfig);
|
|
20
|
-
}
|
|
21
|
-
else {
|
|
22
|
-
throw new Error("Error! " + typeof value + " cannot be interpolated");
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
6
|
/**
|
|
26
7
|
* bInterpolate functions maps input range [0, 1] to given [minOutput, maxOutput]
|
|
27
8
|
* sorthand function to interpolate input range [0, 1]
|
|
@@ -32,7 +13,7 @@ function interpolate(value, inputRange, outputRange, extrapolateConfig) {
|
|
|
32
13
|
* @returns - number | TransitionValue
|
|
33
14
|
*/
|
|
34
15
|
function bInterpolate(value, minOutput, maxOutput, extrapolateConfig) {
|
|
35
|
-
return interpolate(value, [0, 1], [minOutput, maxOutput], extrapolateConfig);
|
|
16
|
+
return reMotion.interpolate(value, [0, 1], [minOutput, maxOutput], extrapolateConfig);
|
|
36
17
|
}
|
|
37
18
|
|
|
38
19
|
/*! *****************************************************************************
|
|
@@ -110,83 +91,36 @@ function __spread() {
|
|
|
110
91
|
return ar;
|
|
111
92
|
}
|
|
112
93
|
|
|
113
|
-
var getInitialConfig = function (animationType) {
|
|
114
|
-
switch (animationType) {
|
|
115
|
-
case "elastic":
|
|
116
|
-
return { mass: 1, friction: 18, tension: 250 };
|
|
117
|
-
case "stiff":
|
|
118
|
-
return { mass: 1, friction: 18, tension: 350 };
|
|
119
|
-
case "wooble":
|
|
120
|
-
return { mass: 1, friction: 8, tension: 250 };
|
|
121
|
-
case "bounce":
|
|
122
|
-
return { duration: 500, easing: reMotion.Easing.bounce };
|
|
123
|
-
case "ease":
|
|
124
|
-
default:
|
|
125
|
-
return { mass: 1, friction: 26, tension: 170 };
|
|
126
|
-
}
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* getValue checks for type of initialValue and throws error
|
|
131
|
-
* for type other than AnimatedValueType
|
|
132
|
-
*/
|
|
133
|
-
var getValue = function (value) {
|
|
134
|
-
if (typeof value === "number" || typeof value === "string") {
|
|
135
|
-
return value;
|
|
136
|
-
}
|
|
137
|
-
else {
|
|
138
|
-
throw new Error("Invalid Value! Animated value only accepts string or number.");
|
|
139
|
-
}
|
|
140
|
-
};
|
|
141
94
|
/**
|
|
142
95
|
* useAnimatedValue for animated transitions
|
|
143
96
|
*/
|
|
144
97
|
function useAnimatedValue(initialValue, config) {
|
|
145
|
-
var _a;
|
|
146
|
-
var _isInitial = React.useRef(true);
|
|
147
|
-
var _initialValue = getValue(initialValue);
|
|
148
|
-
var animationType = (_a = config === null || config === void 0 ? void 0 : config.animationType) !== null && _a !== void 0 ? _a : "ease"; // Defines default animation
|
|
149
|
-
var onAnimationEnd = config === null || config === void 0 ? void 0 : config.onAnimationEnd;
|
|
150
|
-
var listener = config === null || config === void 0 ? void 0 : config.listener;
|
|
151
|
-
var _b = __read(reMotion.useTransition(_initialValue, __assign(__assign(__assign({}, getInitialConfig(animationType)), config), { onRest: function (result) {
|
|
152
|
-
if (result.finished) {
|
|
153
|
-
onAnimationEnd && onAnimationEnd(result.value);
|
|
154
|
-
}
|
|
155
|
-
}, onChange: function (value) {
|
|
156
|
-
listener && listener(value);
|
|
157
|
-
} })), 2), animation = _b[0], setAnimation = _b[1];
|
|
158
|
-
// doesn't fire on initial render
|
|
159
|
-
React.useEffect(function () {
|
|
160
|
-
if (!_isInitial.current) {
|
|
161
|
-
setAnimation({ toValue: _initialValue });
|
|
162
|
-
}
|
|
163
|
-
_isInitial.current = false;
|
|
164
|
-
}, [_initialValue]);
|
|
98
|
+
var _a = __read(reMotion.useTransition(initialValue, config), 2), animation = _a[0], setAnimation = _a[1];
|
|
165
99
|
var targetObject = {
|
|
166
100
|
value: animation,
|
|
167
101
|
currentValue: animation.get(),
|
|
168
102
|
};
|
|
169
103
|
return new Proxy(targetObject, {
|
|
170
104
|
set: function (_, key, value) {
|
|
171
|
-
if (key ===
|
|
172
|
-
if (typeof value ===
|
|
105
|
+
if (key === 'value') {
|
|
106
|
+
if (typeof value === 'number' || typeof value === 'string') {
|
|
173
107
|
setAnimation({ toValue: value });
|
|
174
108
|
}
|
|
175
|
-
else if (typeof value ===
|
|
176
|
-
setAnimation(
|
|
109
|
+
else if (typeof value === 'object' || typeof value === 'function') {
|
|
110
|
+
setAnimation(value);
|
|
177
111
|
}
|
|
178
112
|
return true;
|
|
179
113
|
}
|
|
180
|
-
throw new Error(
|
|
114
|
+
throw new Error('You cannot set any other property to animation node.');
|
|
181
115
|
},
|
|
182
116
|
get: function (_, key) {
|
|
183
|
-
if (key ===
|
|
117
|
+
if (key === 'value') {
|
|
184
118
|
return animation;
|
|
185
119
|
}
|
|
186
|
-
if (key ===
|
|
120
|
+
if (key === 'currentValue') {
|
|
187
121
|
return animation.get();
|
|
188
122
|
}
|
|
189
|
-
throw new Error(
|
|
123
|
+
throw new Error('You cannot access any other property from animation node.');
|
|
190
124
|
},
|
|
191
125
|
});
|
|
192
126
|
}
|
|
@@ -195,26 +129,23 @@ function useAnimatedValue(initialValue, config) {
|
|
|
195
129
|
* useMountedValue handles mounting and unmounting of a component
|
|
196
130
|
* @param state - boolean
|
|
197
131
|
* @param config - useTransitionConfig
|
|
198
|
-
* @returns mountedValueFunction with a callback with argument ( animationNode, mounted )
|
|
132
|
+
* @returns mountedValueFunction with a callback with argument ( { value: animationNode }, mounted )
|
|
199
133
|
*/
|
|
200
134
|
function useMountedValue(state, config) {
|
|
201
|
-
var
|
|
202
|
-
var
|
|
203
|
-
var
|
|
204
|
-
var
|
|
205
|
-
var _k = __read(reMotion.useTransition(from, _config), 2), animation = _k[0], setAnimation = _k[1];
|
|
206
|
-
var enterDuration = (_b = (_a = config.config) === null || _a === void 0 ? void 0 : _a.enterDuration) !== null && _b !== void 0 ? _b : (_c = config.config) === null || _c === void 0 ? void 0 : _c.duration;
|
|
207
|
-
var exitDuration = (_e = (_d = config.config) === null || _d === void 0 ? void 0 : _d.exitDuration) !== null && _e !== void 0 ? _e : (_f = config.config) === null || _f === void 0 ? void 0 : _f.exitDuration;
|
|
135
|
+
var initial = React.useRef(true);
|
|
136
|
+
var _a = __read(React.useState(state), 2), mounted = _a[0], setMounted = _a[1];
|
|
137
|
+
var _b = React.useRef(config).current, from = _b.from, enter = _b.enter, exit = _b.exit, innerConfig = _b.config, enterConfig = _b.enterConfig, exitConfig = _b.exitConfig;
|
|
138
|
+
var _c = __read(reMotion.useTransition(from, innerConfig), 2), animation = _c[0], setAnimation = _c[1];
|
|
208
139
|
React.useEffect(function () {
|
|
209
140
|
if (state) {
|
|
210
|
-
|
|
141
|
+
initial.current = true;
|
|
211
142
|
setMounted(true);
|
|
212
143
|
}
|
|
213
144
|
else {
|
|
214
|
-
|
|
145
|
+
initial.current = false;
|
|
215
146
|
setAnimation({
|
|
216
147
|
toValue: exit,
|
|
217
|
-
|
|
148
|
+
config: exitConfig,
|
|
218
149
|
}, function (_a) {
|
|
219
150
|
var finished = _a.finished;
|
|
220
151
|
if (finished) {
|
|
@@ -224,15 +155,13 @@ function useMountedValue(state, config) {
|
|
|
224
155
|
}
|
|
225
156
|
}, [state]);
|
|
226
157
|
React.useEffect(function () {
|
|
227
|
-
if (mounted && initial) {
|
|
158
|
+
if (mounted && initial.current) {
|
|
228
159
|
setAnimation({
|
|
229
160
|
toValue: enter,
|
|
230
|
-
|
|
231
|
-
}, function () {
|
|
232
|
-
return;
|
|
161
|
+
config: enterConfig,
|
|
233
162
|
});
|
|
234
163
|
}
|
|
235
|
-
}, [mounted, initial]);
|
|
164
|
+
}, [mounted, initial.current]);
|
|
236
165
|
return function (callback) {
|
|
237
166
|
return callback({ value: animation }, mounted);
|
|
238
167
|
};
|
|
@@ -247,15 +176,15 @@ function makeAnimatedComponent(WrappedComponent) {
|
|
|
247
176
|
/**
|
|
248
177
|
* AnimatedBlock : Animated Div
|
|
249
178
|
*/
|
|
250
|
-
var AnimatedBlock = reMotion.makeAnimatedComponent(
|
|
179
|
+
var AnimatedBlock = reMotion.makeAnimatedComponent('div');
|
|
251
180
|
/**
|
|
252
181
|
* AnimatedInline : Animated Span
|
|
253
182
|
*/
|
|
254
|
-
var AnimatedInline = reMotion.makeAnimatedComponent(
|
|
183
|
+
var AnimatedInline = reMotion.makeAnimatedComponent('span');
|
|
255
184
|
/**
|
|
256
185
|
* AnimatedImage : Animated Image
|
|
257
186
|
*/
|
|
258
|
-
var AnimatedImage = reMotion.makeAnimatedComponent(
|
|
187
|
+
var AnimatedImage = reMotion.makeAnimatedComponent('img');
|
|
259
188
|
/**
|
|
260
189
|
* ScrollableBlock
|
|
261
190
|
* Used to animate element when enter into viewport
|
|
@@ -263,7 +192,7 @@ var AnimatedImage = reMotion.makeAnimatedComponent("img");
|
|
|
263
192
|
* animated value goes from 0 to 1 when appear on viewport & vice versa.
|
|
264
193
|
*/
|
|
265
194
|
var ScrollableBlock = function (props) {
|
|
266
|
-
var children = props.children, _a = props.direction, direction = _a === void 0 ?
|
|
195
|
+
var children = props.children, _a = props.direction, direction = _a === void 0 ? 'single' : _a, animationConfig = props.animationConfig, _b = props.threshold, threshold = _b === void 0 ? 0.2 : _b;
|
|
267
196
|
var scrollableBlockRef = React.useRef(null);
|
|
268
197
|
var animation = useAnimatedValue(0, animationConfig); // 0: not intersecting | 1: intersecting
|
|
269
198
|
React.useEffect(function () {
|
|
@@ -275,7 +204,7 @@ var ScrollableBlock = function (props) {
|
|
|
275
204
|
animation.value = 1;
|
|
276
205
|
}
|
|
277
206
|
else {
|
|
278
|
-
if (direction ===
|
|
207
|
+
if (direction === 'both')
|
|
279
208
|
animation.value = 0;
|
|
280
209
|
}
|
|
281
210
|
}, {
|
|
@@ -300,10 +229,34 @@ var ScrollableBlock = function (props) {
|
|
|
300
229
|
*/
|
|
301
230
|
var MountedBlock = function (_a) {
|
|
302
231
|
var state = _a.state, children = _a.children, config = _a.config;
|
|
303
|
-
var open = useMountedValue(state,
|
|
232
|
+
var open = useMountedValue(state, config);
|
|
304
233
|
return React.createElement(React.Fragment, null, open(function (animation, mounted) { return mounted && children(animation); }));
|
|
305
234
|
};
|
|
306
235
|
|
|
236
|
+
var getInitialConfig = function (animationType) {
|
|
237
|
+
switch (animationType) {
|
|
238
|
+
case 'elastic':
|
|
239
|
+
return { mass: 1, friction: 18, tension: 250 };
|
|
240
|
+
case 'stiff':
|
|
241
|
+
return { mass: 1, friction: 18, tension: 350 };
|
|
242
|
+
case 'wooble':
|
|
243
|
+
return { mass: 1, friction: 8, tension: 250 };
|
|
244
|
+
case 'bounce':
|
|
245
|
+
return { duration: 500, easing: reMotion.Easing.bounce };
|
|
246
|
+
case 'ease':
|
|
247
|
+
default:
|
|
248
|
+
return { mass: 1, friction: 26, tension: 170 };
|
|
249
|
+
}
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
var AnimationConfigUtils = {
|
|
253
|
+
ELASTIC: getInitialConfig('elastic'),
|
|
254
|
+
BOUNCE: getInitialConfig('bounce'),
|
|
255
|
+
EASE: getInitialConfig('ease'),
|
|
256
|
+
STIFF: getInitialConfig('stiff'),
|
|
257
|
+
WOOBLE: getInitialConfig('wooble'),
|
|
258
|
+
};
|
|
259
|
+
|
|
307
260
|
/**
|
|
308
261
|
* Attach single document / window event / HTMLElement
|
|
309
262
|
*/
|
|
@@ -502,12 +455,12 @@ var DragGesture = /** @class */ (function (_super) {
|
|
|
502
455
|
DragGesture.prototype._initEvents = function () {
|
|
503
456
|
if (this.targetElement || this.targetElements.length > 0) {
|
|
504
457
|
this._subscribe = attachEvents([window], [
|
|
505
|
-
[
|
|
506
|
-
[
|
|
507
|
-
[
|
|
508
|
-
[
|
|
509
|
-
[
|
|
510
|
-
[
|
|
458
|
+
['mousedown', this.pointerDown.bind(this)],
|
|
459
|
+
['mousemove', this.pointerMove.bind(this)],
|
|
460
|
+
['mouseup', this.pointerUp.bind(this)],
|
|
461
|
+
['touchstart', this.pointerDown.bind(this), { passive: false }],
|
|
462
|
+
['touchmove', this.pointerMove.bind(this), { passive: false }],
|
|
463
|
+
['touchend', this.pointerUp.bind(this)],
|
|
511
464
|
]);
|
|
512
465
|
}
|
|
513
466
|
};
|
|
@@ -516,7 +469,7 @@ var DragGesture = /** @class */ (function (_super) {
|
|
|
516
469
|
// will not be triggered
|
|
517
470
|
DragGesture.prototype._cancelEvents = function () {
|
|
518
471
|
if (this._subscribe) {
|
|
519
|
-
this._subscribe([
|
|
472
|
+
this._subscribe(['mousedown', 'mousemove', 'touchstart', 'touchmove']);
|
|
520
473
|
}
|
|
521
474
|
};
|
|
522
475
|
DragGesture.prototype._handleCallback = function () {
|
|
@@ -543,7 +496,7 @@ var DragGesture = /** @class */ (function (_super) {
|
|
|
543
496
|
};
|
|
544
497
|
DragGesture.prototype.pointerDown = function (e) {
|
|
545
498
|
var _a;
|
|
546
|
-
if (e.type ===
|
|
499
|
+
if (e.type === 'touchstart') {
|
|
547
500
|
this.movementStart = {
|
|
548
501
|
x: e.touches[0].clientX,
|
|
549
502
|
y: e.touches[0].clientY,
|
|
@@ -589,10 +542,10 @@ var DragGesture = /** @class */ (function (_super) {
|
|
|
589
542
|
if (this.isActive) {
|
|
590
543
|
e.preventDefault();
|
|
591
544
|
var now = Date.now();
|
|
592
|
-
var deltaTime =
|
|
545
|
+
var deltaTime = clamp(now - this.lastTimeStamp, 0.1, 64);
|
|
593
546
|
this.lastTimeStamp = now;
|
|
594
547
|
var t = deltaTime / 1000;
|
|
595
|
-
if (e.type ===
|
|
548
|
+
if (e.type === 'touchmove') {
|
|
596
549
|
this.movement = {
|
|
597
550
|
x: this.initialMovement.x +
|
|
598
551
|
(e.touches[0].clientX - this.movementStart.x),
|
|
@@ -625,6 +578,7 @@ var DragGesture = /** @class */ (function (_super) {
|
|
|
625
578
|
if (this.isActive) {
|
|
626
579
|
this.isActive = false;
|
|
627
580
|
this._handleCallback();
|
|
581
|
+
this._cancelEvents();
|
|
628
582
|
this._initEvents();
|
|
629
583
|
}
|
|
630
584
|
};
|
|
@@ -1162,15 +1116,21 @@ Object.defineProperty(exports, 'Easing', {
|
|
|
1162
1116
|
return reMotion.Easing;
|
|
1163
1117
|
}
|
|
1164
1118
|
});
|
|
1119
|
+
Object.defineProperty(exports, 'interpolate', {
|
|
1120
|
+
enumerable: true,
|
|
1121
|
+
get: function () {
|
|
1122
|
+
return reMotion.interpolate;
|
|
1123
|
+
}
|
|
1124
|
+
});
|
|
1165
1125
|
exports.AnimatedBlock = AnimatedBlock;
|
|
1166
1126
|
exports.AnimatedImage = AnimatedImage;
|
|
1167
1127
|
exports.AnimatedInline = AnimatedInline;
|
|
1128
|
+
exports.AnimationConfigUtils = AnimationConfigUtils;
|
|
1168
1129
|
exports.MountedBlock = MountedBlock;
|
|
1169
1130
|
exports.ScrollableBlock = ScrollableBlock;
|
|
1170
1131
|
exports.bInterpolate = bInterpolate;
|
|
1171
1132
|
exports.bin = bin;
|
|
1172
1133
|
exports.clamp = clamp;
|
|
1173
|
-
exports.interpolate = interpolate;
|
|
1174
1134
|
exports.makeAnimatedComponent = makeAnimatedComponent;
|
|
1175
1135
|
exports.mix = mix;
|
|
1176
1136
|
exports.move = move;
|