react-ui-animate 1.2.1 → 1.4.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/dist/{animate → animation}/getInitialConfig.d.ts +0 -0
- package/dist/animation/index.d.ts +4 -0
- package/dist/{Interpolation.d.ts → animation/interpolation.d.ts} +0 -0
- package/dist/{Modules.d.ts → animation/modules.d.ts} +15 -0
- package/dist/{useAnimatedValue.d.ts → animation/useAnimatedValue.d.ts} +2 -2
- package/dist/{useMountedValue.d.ts → animation/useMountedValue.d.ts} +3 -3
- package/dist/gestures/controllers/DragGesture.d.ts +17 -0
- package/dist/gestures/controllers/Gesture.d.ts +20 -0
- package/dist/gestures/controllers/MouseMoveGesture.d.ts +13 -0
- package/dist/gestures/controllers/ScrollGesture.d.ts +14 -0
- package/dist/gestures/controllers/WheelGesture.d.ts +15 -0
- package/dist/gestures/controllers/index.d.ts +4 -0
- package/dist/gestures/eventAttacher.d.ts +11 -0
- package/dist/{animate → gestures}/hooks/index.d.ts +2 -4
- package/dist/gestures/hooks/useDrag.d.ts +4 -0
- package/dist/gestures/hooks/useGesture.d.ts +9 -0
- package/dist/gestures/hooks/useMouseMove.d.ts +4 -0
- package/dist/gestures/hooks/useRecognizer.d.ts +10 -0
- package/dist/gestures/hooks/useScroll.d.ts +4 -0
- package/dist/gestures/hooks/useWheel.d.ts +4 -0
- package/dist/gestures/index.d.ts +2 -0
- package/dist/{Math.d.ts → gestures/math.d.ts} +0 -0
- package/dist/{animate/Types.d.ts → gestures/types.d.ts} +17 -30
- package/dist/gestures/withDefault.d.ts +4 -0
- package/dist/hooks/index.d.ts +0 -4
- package/dist/hooks/useMeasure.d.ts +10 -1
- package/dist/hooks/useWindowDimension.d.ts +7 -1
- package/dist/index.d.ts +2 -5
- package/dist/index.js +848 -707
- package/dist/index.js.map +1 -1
- package/dist/utils/index.d.ts +1 -0
- package/dist/{animate → utils}/isDefined.d.ts +0 -0
- package/package.json +6 -3
- package/src/{getInitialConfig.ts → animation/getInitialConfig.ts} +0 -0
- package/src/animation/index.ts +4 -0
- package/src/{Interpolation.ts → animation/interpolation.ts} +0 -0
- package/src/{Modules.tsx → animation/modules.tsx} +26 -1
- package/src/{useAnimatedValue.ts → animation/useAnimatedValue.ts} +5 -8
- package/src/{useMountedValue.ts → animation/useMountedValue.ts} +4 -7
- package/src/gestures/controllers/DragGesture.ts +176 -0
- package/src/gestures/controllers/Gesture.ts +54 -0
- package/src/gestures/controllers/MouseMoveGesture.ts +111 -0
- package/src/gestures/controllers/ScrollGesture.ts +107 -0
- package/src/gestures/controllers/WheelGesture.ts +123 -0
- package/src/gestures/controllers/index.ts +4 -0
- package/src/gestures/eventAttacher.ts +67 -0
- package/src/gestures/hooks/index.ts +5 -0
- package/src/gestures/hooks/useDrag.ts +14 -0
- package/src/gestures/hooks/useGesture.ts +38 -0
- package/src/gestures/hooks/useMouseMove.ts +11 -0
- package/src/gestures/hooks/useRecognizer.ts +59 -0
- package/src/gestures/hooks/useScroll.ts +11 -0
- package/src/gestures/hooks/useWheel.ts +11 -0
- package/src/gestures/index.ts +2 -0
- package/src/{Math.ts → gestures/math.ts} +0 -0
- package/src/{Types.ts → gestures/types.ts} +19 -36
- package/src/gestures/withDefault.ts +3 -0
- package/src/hooks/index.ts +0 -4
- package/src/hooks/useMeasure.ts +11 -1
- package/src/hooks/useOutsideClick.ts +3 -2
- package/src/hooks/useWindowDimension.ts +7 -1
- package/src/index.ts +2 -5
- package/src/utils/index.ts +1 -0
- package/src/{isDefined.ts → utils/isDefined.ts} +0 -0
- package/tsconfig.json +1 -0
- package/dist/Types.d.ts +0 -64
- package/dist/animate/Interpolation.d.ts +0 -20
- package/dist/animate/Math.d.ts +0 -34
- package/dist/animate/Modules.d.ts +0 -32
- package/dist/animate/controllers/EventAttacher.d.ts +0 -8
- package/dist/animate/controllers/index.d.ts +0 -1
- package/dist/animate/hooks/useDrag.d.ts +0 -5
- package/dist/animate/hooks/useMeasure.d.ts +0 -5
- package/dist/animate/hooks/useMouseMove.d.ts +0 -5
- package/dist/animate/hooks/useOutsideClick.d.ts +0 -2
- package/dist/animate/hooks/useScroll.d.ts +0 -5
- package/dist/animate/hooks/useWheel.d.ts +0 -5
- package/dist/animate/hooks/useWindowDimension.d.ts +0 -3
- package/dist/animate/index.d.ts +0 -8
- package/dist/animate/useAnimatedValue.d.ts +0 -30
- package/dist/animate/useMountedValue.d.ts +0 -22
- package/dist/controllers/EventAttacher.d.ts +0 -8
- package/dist/controllers/index.d.ts +0 -1
- package/dist/core/Animation.d.ts +0 -13
- package/dist/core/Bezier.d.ts +0 -8
- package/dist/core/Colors.d.ts +0 -25
- package/dist/core/Easing.d.ts +0 -40
- package/dist/core/Interpolation.d.ts +0 -38
- package/dist/core/RequestAnimationFrame.d.ts +0 -8
- package/dist/core/SpringAnimation.d.ts +0 -39
- package/dist/core/Tags.d.ts +0 -2
- package/dist/core/TimingAnimation.d.ts +0 -34
- package/dist/core/TransformStyles.d.ts +0 -8
- package/dist/core/animated.d.ts +0 -9
- package/dist/core/index.d.ts +0 -7
- package/dist/core/useTransition.d.ts +0 -46
- package/dist/getInitialConfig.d.ts +0 -3
- package/dist/hooks/useDrag.d.ts +0 -5
- package/dist/hooks/useMouseMove.d.ts +0 -5
- package/dist/hooks/useScroll.d.ts +0 -5
- package/dist/hooks/useWheel.d.ts +0 -5
- package/dist/isDefined.d.ts +0 -1
- package/src/controllers/EventAttacher.ts +0 -35
- package/src/controllers/index.ts +0 -1
- package/src/hooks/useDrag.ts +0 -231
- package/src/hooks/useMouseMove.ts +0 -123
- package/src/hooks/useScroll.ts +0 -124
- package/src/hooks/useWheel.ts +0 -144
package/dist/index.js
CHANGED
|
@@ -3,6 +3,38 @@ 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
|
+
/**
|
|
26
|
+
* bInterpolate functions maps input range [0, 1] to given [minOutput, maxOutput]
|
|
27
|
+
* sorthand function to interpolate input range [0, 1]
|
|
28
|
+
* @param value - number | TransitionValue
|
|
29
|
+
* @param minOutput - number | string
|
|
30
|
+
* @param maxOutput - number | string
|
|
31
|
+
* @param extrapolateConfig - "clamp" | "identity" | "extend"
|
|
32
|
+
* @returns - number | TransitionValue
|
|
33
|
+
*/
|
|
34
|
+
function bInterpolate(value, minOutput, maxOutput, extrapolateConfig) {
|
|
35
|
+
return interpolate(value, [0, 1], [minOutput, maxOutput], extrapolateConfig);
|
|
36
|
+
}
|
|
37
|
+
|
|
6
38
|
/*! *****************************************************************************
|
|
7
39
|
Copyright (c) Microsoft Corporation.
|
|
8
40
|
|
|
@@ -17,6 +49,20 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
|
17
49
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
18
50
|
PERFORMANCE OF THIS SOFTWARE.
|
|
19
51
|
***************************************************************************** */
|
|
52
|
+
/* global Reflect, Promise */
|
|
53
|
+
|
|
54
|
+
var extendStatics = function(d, b) {
|
|
55
|
+
extendStatics = Object.setPrototypeOf ||
|
|
56
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
57
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
58
|
+
return extendStatics(d, b);
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
function __extends(d, b) {
|
|
62
|
+
extendStatics(d, b);
|
|
63
|
+
function __() { this.constructor = d; }
|
|
64
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
65
|
+
}
|
|
20
66
|
|
|
21
67
|
var __assign = function() {
|
|
22
68
|
__assign = Object.assign || function __assign(t) {
|
|
@@ -29,104 +75,39 @@ var __assign = function() {
|
|
|
29
75
|
return __assign.apply(this, arguments);
|
|
30
76
|
};
|
|
31
77
|
|
|
32
|
-
function
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* bin(booleanValue)
|
|
42
|
-
* returns 1 if booleanValue == true and 0 if booleanValue == false
|
|
43
|
-
*/
|
|
44
|
-
function bin(bool) {
|
|
45
|
-
return bool ? 1 : 0;
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* mix(progress, a, b)
|
|
49
|
-
* linear interpolation between a and b
|
|
50
|
-
*/
|
|
51
|
-
function mix(perc, val1, val2) {
|
|
52
|
-
return val1 * (1 - perc) + val2 * perc;
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* clamp(value, min, max)
|
|
56
|
-
* clamps value for min and max bounds
|
|
57
|
-
*/
|
|
58
|
-
function clamp(value, lowerbound, upperbound) {
|
|
59
|
-
return Math.min(Math.max(value, lowerbound), upperbound);
|
|
60
|
-
}
|
|
61
|
-
function rubber2(distanceFromEdge, constant) {
|
|
62
|
-
return Math.pow(distanceFromEdge, constant * 5);
|
|
63
|
-
}
|
|
64
|
-
function rubber(distanceFromEdge, dimension, constant) {
|
|
65
|
-
if (dimension === 0 || Math.abs(dimension) === Infinity)
|
|
66
|
-
return rubber2(distanceFromEdge, constant);
|
|
67
|
-
return ((distanceFromEdge * dimension * constant) /
|
|
68
|
-
(dimension + constant * distanceFromEdge));
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* rubberClamp(value, min, max, constant?)
|
|
72
|
-
* constant is optional : default 0.15
|
|
73
|
-
* clamps the value for min and max value and
|
|
74
|
-
* extends beyond min and max values with constant
|
|
75
|
-
* factor to create elastic rubber band effect
|
|
76
|
-
*/
|
|
77
|
-
function rubberClamp(value, lowerbound, upperbound, constant) {
|
|
78
|
-
if (constant === void 0) { constant = 0.15; }
|
|
79
|
-
if (constant === 0)
|
|
80
|
-
return clamp(value, lowerbound, upperbound);
|
|
81
|
-
if (value < lowerbound) {
|
|
82
|
-
return (-rubber(lowerbound - value, upperbound - lowerbound, constant) +
|
|
83
|
-
lowerbound);
|
|
84
|
-
}
|
|
85
|
-
if (value > upperbound) {
|
|
86
|
-
return (+rubber(value - upperbound, upperbound - lowerbound, constant) +
|
|
87
|
-
upperbound);
|
|
88
|
-
}
|
|
89
|
-
return value;
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* snapTo(value, velocity, snapPoints[])
|
|
93
|
-
* Calculates the final snapPoint according to given current value,
|
|
94
|
-
* velocity and snapPoints array
|
|
95
|
-
*/
|
|
96
|
-
function snapTo(value, velocity, snapPoints) {
|
|
97
|
-
var finalValue = value + velocity * 0.2;
|
|
98
|
-
var getDiff = function (point) { return Math.abs(point - finalValue); };
|
|
99
|
-
var deltas = snapPoints.map(getDiff);
|
|
100
|
-
var minDelta = Math.min.apply(Math, deltas);
|
|
101
|
-
return snapPoints.reduce(function (acc, point) {
|
|
102
|
-
if (getDiff(point) === minDelta) {
|
|
103
|
-
return point;
|
|
104
|
-
}
|
|
105
|
-
else {
|
|
106
|
-
return acc;
|
|
78
|
+
function __values(o) {
|
|
79
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
80
|
+
if (m) return m.call(o);
|
|
81
|
+
if (o && typeof o.length === "number") return {
|
|
82
|
+
next: function () {
|
|
83
|
+
if (o && i >= o.length) o = void 0;
|
|
84
|
+
return { value: o && o[i++], done: !o };
|
|
107
85
|
}
|
|
108
|
-
}
|
|
86
|
+
};
|
|
87
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
109
88
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
var diff = moveIndex - toIndex;
|
|
118
|
-
if (diff > 0) {
|
|
119
|
-
return __spreadArrays(array.slice(0, toIndex), [
|
|
120
|
-
item
|
|
121
|
-
], array.slice(toIndex, moveIndex), array.slice(moveIndex + 1, length));
|
|
89
|
+
|
|
90
|
+
function __read(o, n) {
|
|
91
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
92
|
+
if (!m) return o;
|
|
93
|
+
var i = m.call(o), r, ar = [], e;
|
|
94
|
+
try {
|
|
95
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
122
96
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
97
|
+
catch (error) { e = { error: error }; }
|
|
98
|
+
finally {
|
|
99
|
+
try {
|
|
100
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
101
|
+
}
|
|
102
|
+
finally { if (e) throw e.error; }
|
|
128
103
|
}
|
|
129
|
-
return
|
|
104
|
+
return ar;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function __spread() {
|
|
108
|
+
for (var ar = [], i = 0; i < arguments.length; i++)
|
|
109
|
+
ar = ar.concat(__read(arguments[i]));
|
|
110
|
+
return ar;
|
|
130
111
|
}
|
|
131
112
|
|
|
132
113
|
var getInitialConfig = function (animationType) {
|
|
@@ -153,28 +134,25 @@ var getValue = function (value) {
|
|
|
153
134
|
if (typeof value === "number" || typeof value === "string") {
|
|
154
135
|
return value;
|
|
155
136
|
}
|
|
156
|
-
else if (typeof value === "boolean") {
|
|
157
|
-
return bin(value);
|
|
158
|
-
}
|
|
159
137
|
else {
|
|
160
|
-
throw new Error("Invalid Value! Animated value only accepts string
|
|
138
|
+
throw new Error("Invalid Value! Animated value only accepts string or number.");
|
|
161
139
|
}
|
|
162
140
|
};
|
|
163
141
|
/**
|
|
164
142
|
* useAnimatedValue for animated transitions
|
|
165
143
|
*/
|
|
166
|
-
|
|
144
|
+
function useAnimatedValue(initialValue, config) {
|
|
167
145
|
var _a;
|
|
168
146
|
var _isInitial = React.useRef(true);
|
|
169
147
|
var _initialValue = getValue(initialValue);
|
|
170
148
|
var animationType = (_a = config === null || config === void 0 ? void 0 : config.animationType) !== null && _a !== void 0 ? _a : "ease"; // Defines default animation
|
|
171
149
|
var onAnimationEnd = config === null || config === void 0 ? void 0 : config.onAnimationEnd;
|
|
172
150
|
var listener = config === null || config === void 0 ? void 0 : config.listener;
|
|
173
|
-
var _b = reMotion.useTransition(_initialValue, __assign(__assign(__assign({}, getInitialConfig(animationType)), config), { onRest: function (result) {
|
|
151
|
+
var _b = __read(reMotion.useTransition(_initialValue, __assign(__assign(__assign({}, getInitialConfig(animationType)), config), { onRest: function (result) {
|
|
174
152
|
onAnimationEnd && onAnimationEnd(result);
|
|
175
153
|
}, onChange: function (value) {
|
|
176
154
|
listener && listener(value);
|
|
177
|
-
} })), animation = _b[0], setAnimation = _b[1];
|
|
155
|
+
} })), 2), animation = _b[0], setAnimation = _b[1];
|
|
178
156
|
// doesn't fire on initial render
|
|
179
157
|
React.useEffect(function () {
|
|
180
158
|
if (!_isInitial.current) {
|
|
@@ -209,7 +187,7 @@ var useAnimatedValue = function (initialValue, config) {
|
|
|
209
187
|
throw new Error("You cannot access any other property from animation node.");
|
|
210
188
|
},
|
|
211
189
|
});
|
|
212
|
-
}
|
|
190
|
+
}
|
|
213
191
|
|
|
214
192
|
/**
|
|
215
193
|
* useMountedValue handles mounting and unmounting of a component
|
|
@@ -217,12 +195,12 @@ var useAnimatedValue = function (initialValue, config) {
|
|
|
217
195
|
* @param config - useTransitionConfig
|
|
218
196
|
* @returns mountedValueFunction with a callback with argument ( animationNode, mounted )
|
|
219
197
|
*/
|
|
220
|
-
|
|
198
|
+
function useMountedValue(state, config) {
|
|
221
199
|
var _a, _b, _c, _d, _e, _f;
|
|
222
|
-
var _g = React.useState(true), initial = _g[0], setInitial = _g[1];
|
|
223
|
-
var _h = React.useState(state), mounted = _h[0], setMounted = _h[1];
|
|
200
|
+
var _g = __read(React.useState(true), 2), initial = _g[0], setInitial = _g[1];
|
|
201
|
+
var _h = __read(React.useState(state), 2), mounted = _h[0], setMounted = _h[1];
|
|
224
202
|
var _j = React.useRef(config).current, from = _j.from, enter = _j.enter, exit = _j.exit, _config = _j.config;
|
|
225
|
-
var _k = reMotion.useTransition(from, _config), animation = _k[0], setAnimation = _k[1];
|
|
203
|
+
var _k = __read(reMotion.useTransition(from, _config), 2), animation = _k[0], setAnimation = _k[1];
|
|
226
204
|
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;
|
|
227
205
|
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;
|
|
228
206
|
React.useEffect(function () {
|
|
@@ -253,38 +231,6 @@ var useMountedValue = function (state, config) {
|
|
|
253
231
|
return function (callback) {
|
|
254
232
|
return callback({ value: animation }, mounted);
|
|
255
233
|
};
|
|
256
|
-
};
|
|
257
|
-
|
|
258
|
-
/**
|
|
259
|
-
* interpolate function maps input range to output range
|
|
260
|
-
* @param value - number | TransitionValue
|
|
261
|
-
* @param inputRange - Array<number>
|
|
262
|
-
* @param outputRange - Array<string | number>
|
|
263
|
-
* @param extrapolateConfig - "clamp" | "identity" | "extend"
|
|
264
|
-
* @returns - number | TransitionValue
|
|
265
|
-
*/
|
|
266
|
-
function interpolate(value, inputRange, outputRange, extrapolateConfig) {
|
|
267
|
-
if (typeof value === "object" && reMotion.isSubscriber(value)) {
|
|
268
|
-
return reMotion.interpolateTransitionValue(value, inputRange, outputRange, extrapolateConfig);
|
|
269
|
-
}
|
|
270
|
-
else if (typeof value === "number") {
|
|
271
|
-
return reMotion.interpolateNumbers(value, inputRange, outputRange, extrapolateConfig);
|
|
272
|
-
}
|
|
273
|
-
else {
|
|
274
|
-
throw new Error("Error! " + typeof value + " cannot be interpolated");
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
/**
|
|
278
|
-
* bInterpolate functions maps input range [0, 1] to given [minOutput, maxOutput]
|
|
279
|
-
* sorthand function to interpolate input range [0, 1]
|
|
280
|
-
* @param value - number | TransitionValue
|
|
281
|
-
* @param minOutput - number | string
|
|
282
|
-
* @param maxOutput - number | string
|
|
283
|
-
* @param extrapolateConfig - "clamp" | "identity" | "extend"
|
|
284
|
-
* @returns - number | TransitionValue
|
|
285
|
-
*/
|
|
286
|
-
function bInterpolate(value, minOutput, maxOutput, extrapolateConfig) {
|
|
287
|
-
return interpolate(value, [0, 1], [minOutput, maxOutput], extrapolateConfig);
|
|
288
234
|
}
|
|
289
235
|
|
|
290
236
|
/**
|
|
@@ -318,7 +264,7 @@ var ScrollableBlock = function (props) {
|
|
|
318
264
|
React.useEffect(function () {
|
|
319
265
|
var _scrollableBlock = scrollableBlockRef.current;
|
|
320
266
|
var observer = new IntersectionObserver(function (_a) {
|
|
321
|
-
var entry =
|
|
267
|
+
var _b = __read(_a, 1), entry = _b[0];
|
|
322
268
|
var isIntersecting = entry.isIntersecting;
|
|
323
269
|
if (isIntersecting) {
|
|
324
270
|
animation.value = 1;
|
|
@@ -341,144 +287,658 @@ var ScrollableBlock = function (props) {
|
|
|
341
287
|
};
|
|
342
288
|
}, []);
|
|
343
289
|
return React.createElement("div", { ref: scrollableBlockRef }, children && children(animation));
|
|
290
|
+
};
|
|
291
|
+
/**
|
|
292
|
+
* MountedBlock handles mounting and unmounting of a component
|
|
293
|
+
* @props - state: boolean, config: InnerUseMountedValueConfig
|
|
294
|
+
* @children - (animation: { value: TransitionValue }) => React.ReactNode
|
|
295
|
+
*/
|
|
296
|
+
var MountedBlock = function (_a) {
|
|
297
|
+
var state = _a.state, children = _a.children, config = _a.config;
|
|
298
|
+
var open = useMountedValue(state, { from: 0, enter: 1, exit: 0, config: config });
|
|
299
|
+
return React.createElement(React.Fragment, null, open(function (animation, mounted) { return mounted && children(animation); }));
|
|
344
300
|
};
|
|
345
301
|
|
|
346
302
|
/**
|
|
347
303
|
* Attach single document / window event / HTMLElement
|
|
348
304
|
*/
|
|
349
|
-
function attachEvent(
|
|
305
|
+
function attachEvent(domTargets, event, callback, capture) {
|
|
350
306
|
if (capture === void 0) { capture = false; }
|
|
351
|
-
|
|
307
|
+
domTargets.forEach(function (target) {
|
|
308
|
+
target.addEventListener(event, callback, capture);
|
|
309
|
+
});
|
|
352
310
|
return function () {
|
|
353
|
-
|
|
311
|
+
domTargets.forEach(function (target) {
|
|
312
|
+
target.removeEventListener(event, callback, capture);
|
|
313
|
+
});
|
|
354
314
|
};
|
|
355
315
|
}
|
|
356
316
|
/**
|
|
357
317
|
* Attach multiple document / window event / HTMLElement
|
|
358
318
|
*/
|
|
359
|
-
function attachEvents(
|
|
360
|
-
var subscribers =
|
|
319
|
+
function attachEvents(domTargets, events) {
|
|
320
|
+
var subscribers = new Map();
|
|
361
321
|
events.forEach(function (_a) {
|
|
362
|
-
var event =
|
|
363
|
-
subscribers.
|
|
322
|
+
var _b = __read(_a, 3), event = _b[0], callback = _b[1], _c = _b[2], capture = _c === void 0 ? false : _c;
|
|
323
|
+
subscribers.set(event, attachEvent(domTargets, event, callback, capture));
|
|
364
324
|
});
|
|
365
|
-
return function () {
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
var callbackRef = React.useRef();
|
|
374
|
-
if (!callbackRef.current) {
|
|
375
|
-
callbackRef.current = callback;
|
|
376
|
-
}
|
|
377
|
-
// Reinitiate callback when dependency change
|
|
378
|
-
React.useEffect(function () {
|
|
379
|
-
callbackRef.current = callback;
|
|
380
|
-
return function () {
|
|
381
|
-
callbackRef.current = function () { return false; };
|
|
382
|
-
};
|
|
383
|
-
}, deps);
|
|
384
|
-
React.useEffect(function () {
|
|
385
|
-
var handleOutsideClick = function (e) {
|
|
386
|
-
var _a;
|
|
387
|
-
if (!((_a = elementRef === null || elementRef === void 0 ? void 0 : elementRef.current) === null || _a === void 0 ? void 0 : _a.contains(e.target))) {
|
|
388
|
-
callbackRef.current && callbackRef.current(e);
|
|
389
|
-
}
|
|
390
|
-
};
|
|
391
|
-
var subscribe = attachEvents(document, [["click", handleOutsideClick]]);
|
|
392
|
-
return function () { return subscribe && subscribe(); };
|
|
393
|
-
}, []);
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
function useMeasure(callback, deps) {
|
|
397
|
-
var ref = React.useRef(null);
|
|
398
|
-
var elementRefs = React.useRef([]);
|
|
399
|
-
var callbackRef = React.useRef(callback);
|
|
400
|
-
// Reinitiate callback when dependency change
|
|
401
|
-
React.useEffect(function () {
|
|
402
|
-
callbackRef.current = callback;
|
|
403
|
-
return function () {
|
|
404
|
-
callbackRef.current = function () { return false; };
|
|
405
|
-
};
|
|
406
|
-
}, deps);
|
|
407
|
-
React.useEffect(function () {
|
|
408
|
-
var _refElement = ref.current || document.documentElement;
|
|
409
|
-
var _refElementsMultiple = elementRefs.current;
|
|
410
|
-
var resizeObserver = new ResizeObserver(function (_a) {
|
|
411
|
-
var entry = _a[0];
|
|
412
|
-
var _b = entry.target.getBoundingClientRect(), left = _b.left, top = _b.top, width = _b.width, height = _b.height;
|
|
413
|
-
var pageXOffset = window.pageXOffset, pageYOffset = window.pageYOffset;
|
|
414
|
-
if (callbackRef) {
|
|
415
|
-
if (_refElement === document.documentElement) {
|
|
416
|
-
return; // no-op for document
|
|
325
|
+
return function (eventKeys) {
|
|
326
|
+
var e_1, _a;
|
|
327
|
+
try {
|
|
328
|
+
for (var _b = __values(subscribers.entries()), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
329
|
+
var _d = __read(_c.value, 2), eventKey = _d[0], subscriber = _d[1];
|
|
330
|
+
if (!eventKeys) {
|
|
331
|
+
subscriber();
|
|
332
|
+
return;
|
|
417
333
|
}
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
left: left + pageXOffset,
|
|
421
|
-
top: top + pageYOffset,
|
|
422
|
-
width: width,
|
|
423
|
-
height: height,
|
|
424
|
-
vLeft: left,
|
|
425
|
-
vTop: top,
|
|
426
|
-
});
|
|
334
|
+
if (eventKeys.indexOf(eventKey) !== -1) {
|
|
335
|
+
subscriber();
|
|
427
336
|
}
|
|
428
337
|
}
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
var height = [];
|
|
435
|
-
var vLeft = [];
|
|
436
|
-
var vTop = [];
|
|
437
|
-
entries.forEach(function (entry) {
|
|
438
|
-
var _a = entry.target.getBoundingClientRect(), _left = _a.left, _top = _a.top, _width = _a.width, _height = _a.height;
|
|
439
|
-
var pageXOffset = window.pageXOffset, pageYOffset = window.pageYOffset;
|
|
440
|
-
var _pageLeft = _left + pageXOffset;
|
|
441
|
-
var _pageTop = _top + pageYOffset;
|
|
442
|
-
left.push(_pageLeft);
|
|
443
|
-
top.push(_pageTop);
|
|
444
|
-
width.push(_width);
|
|
445
|
-
height.push(_height);
|
|
446
|
-
vLeft.push(_left);
|
|
447
|
-
vTop.push(_top);
|
|
448
|
-
});
|
|
449
|
-
if (callbackRef) {
|
|
450
|
-
callbackRef.current({
|
|
451
|
-
left: left,
|
|
452
|
-
top: top,
|
|
453
|
-
width: width,
|
|
454
|
-
height: height,
|
|
455
|
-
vLeft: vLeft,
|
|
456
|
-
vTop: vTop,
|
|
457
|
-
});
|
|
338
|
+
}
|
|
339
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
340
|
+
finally {
|
|
341
|
+
try {
|
|
342
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
458
343
|
}
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
344
|
+
finally { if (e_1) throw e_1.error; }
|
|
345
|
+
}
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
/**
|
|
350
|
+
* bin(booleanValue)
|
|
351
|
+
* returns 1 if booleanValue == true and 0 if booleanValue == false
|
|
352
|
+
*/
|
|
353
|
+
function bin(bool) {
|
|
354
|
+
return bool ? 1 : 0;
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* mix(progress, a, b)
|
|
358
|
+
* linear interpolation between a and b
|
|
359
|
+
*/
|
|
360
|
+
function mix(perc, val1, val2) {
|
|
361
|
+
return val1 * (1 - perc) + val2 * perc;
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* clamp(value, min, max)
|
|
365
|
+
* clamps value for min and max bounds
|
|
366
|
+
*/
|
|
367
|
+
function clamp(value, lowerbound, upperbound) {
|
|
368
|
+
return Math.min(Math.max(value, lowerbound), upperbound);
|
|
369
|
+
}
|
|
370
|
+
function rubber2(distanceFromEdge, constant) {
|
|
371
|
+
return Math.pow(distanceFromEdge, constant * 5);
|
|
372
|
+
}
|
|
373
|
+
function rubber(distanceFromEdge, dimension, constant) {
|
|
374
|
+
if (dimension === 0 || Math.abs(dimension) === Infinity)
|
|
375
|
+
return rubber2(distanceFromEdge, constant);
|
|
376
|
+
return ((distanceFromEdge * dimension * constant) /
|
|
377
|
+
(dimension + constant * distanceFromEdge));
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* rubberClamp(value, min, max, constant?)
|
|
381
|
+
* constant is optional : default 0.15
|
|
382
|
+
* clamps the value for min and max value and
|
|
383
|
+
* extends beyond min and max values with constant
|
|
384
|
+
* factor to create elastic rubber band effect
|
|
385
|
+
*/
|
|
386
|
+
function rubberClamp(value, lowerbound, upperbound, constant) {
|
|
387
|
+
if (constant === void 0) { constant = 0.15; }
|
|
388
|
+
if (constant === 0)
|
|
389
|
+
return clamp(value, lowerbound, upperbound);
|
|
390
|
+
if (value < lowerbound) {
|
|
391
|
+
return (-rubber(lowerbound - value, upperbound - lowerbound, constant) +
|
|
392
|
+
lowerbound);
|
|
393
|
+
}
|
|
394
|
+
if (value > upperbound) {
|
|
395
|
+
return (+rubber(value - upperbound, upperbound - lowerbound, constant) +
|
|
396
|
+
upperbound);
|
|
397
|
+
}
|
|
398
|
+
return value;
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* snapTo(value, velocity, snapPoints[])
|
|
402
|
+
* Calculates the final snapPoint according to given current value,
|
|
403
|
+
* velocity and snapPoints array
|
|
404
|
+
*/
|
|
405
|
+
function snapTo(value, velocity, snapPoints) {
|
|
406
|
+
var finalValue = value + velocity * 0.2;
|
|
407
|
+
var getDiff = function (point) { return Math.abs(point - finalValue); };
|
|
408
|
+
var deltas = snapPoints.map(getDiff);
|
|
409
|
+
var minDelta = Math.min.apply(Math, __spread(deltas));
|
|
410
|
+
return snapPoints.reduce(function (acc, point) {
|
|
411
|
+
if (getDiff(point) === minDelta) {
|
|
412
|
+
return point;
|
|
413
|
+
}
|
|
414
|
+
else {
|
|
415
|
+
return acc;
|
|
416
|
+
}
|
|
417
|
+
});
|
|
418
|
+
}
|
|
419
|
+
/**
|
|
420
|
+
* move(array, moveIndex, toIndex)
|
|
421
|
+
* move array item from moveIndex to toIndex without array modification
|
|
422
|
+
*/
|
|
423
|
+
function move(array, moveIndex, toIndex) {
|
|
424
|
+
var item = array[moveIndex];
|
|
425
|
+
var length = array.length;
|
|
426
|
+
var diff = moveIndex - toIndex;
|
|
427
|
+
if (diff > 0) {
|
|
428
|
+
return __spread(array.slice(0, toIndex), [
|
|
429
|
+
item
|
|
430
|
+
], array.slice(toIndex, moveIndex), array.slice(moveIndex + 1, length));
|
|
431
|
+
}
|
|
432
|
+
else if (diff < 0) {
|
|
433
|
+
var targetIndex = toIndex + 1;
|
|
434
|
+
return __spread(array.slice(0, moveIndex), array.slice(moveIndex + 1, targetIndex), [
|
|
435
|
+
item
|
|
436
|
+
], array.slice(targetIndex, length));
|
|
437
|
+
}
|
|
438
|
+
return array;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
var withDefault = function (x, y) {
|
|
442
|
+
return { x: x, y: y };
|
|
443
|
+
};
|
|
444
|
+
|
|
445
|
+
var Gesture = /** @class */ (function () {
|
|
446
|
+
function Gesture() {
|
|
447
|
+
this.lastTimeStamp = Date.now();
|
|
448
|
+
this.isActive = false;
|
|
449
|
+
this.targetElements = []; // represents the bounded elements
|
|
450
|
+
}
|
|
451
|
+
// it must be overridden by other child classes
|
|
452
|
+
Gesture.prototype._initEvents = function () { };
|
|
453
|
+
// cancel events
|
|
454
|
+
// we only canceled down and move events because mouse up
|
|
455
|
+
// will not be triggered
|
|
456
|
+
Gesture.prototype._cancelEvents = function () {
|
|
457
|
+
if (this._subscribe) {
|
|
458
|
+
this._subscribe();
|
|
459
|
+
}
|
|
460
|
+
};
|
|
461
|
+
// re-apply new callback
|
|
462
|
+
Gesture.prototype.applyCallback = function (callback) {
|
|
463
|
+
this.callback = callback;
|
|
464
|
+
};
|
|
465
|
+
// apply gesture
|
|
466
|
+
Gesture.prototype.applyGesture = function (_a) {
|
|
467
|
+
var _this = this;
|
|
468
|
+
var targetElement = _a.targetElement, targetElements = _a.targetElements, callback = _a.callback, config = _a.config;
|
|
469
|
+
this.targetElement = targetElement;
|
|
470
|
+
this.targetElements = targetElements.map(function (element) { return element.current; });
|
|
471
|
+
this.callback = callback;
|
|
472
|
+
this.config = config;
|
|
473
|
+
// initialize events
|
|
474
|
+
this._initEvents();
|
|
475
|
+
// unbind
|
|
476
|
+
return function () { return _this._subscribe && _this._subscribe(); };
|
|
477
|
+
};
|
|
478
|
+
Gesture._VELOCITY_LIMIT = 20;
|
|
479
|
+
return Gesture;
|
|
480
|
+
}());
|
|
481
|
+
|
|
482
|
+
var DragGesture = /** @class */ (function (_super) {
|
|
483
|
+
__extends(DragGesture, _super);
|
|
484
|
+
function DragGesture() {
|
|
485
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
486
|
+
_this.movementStart = withDefault(0, 0);
|
|
487
|
+
_this.initialMovement = withDefault(0, 0);
|
|
488
|
+
_this.movement = withDefault(0, 0);
|
|
489
|
+
_this.previousMovement = withDefault(0, 0);
|
|
490
|
+
_this.translation = withDefault(0, 0);
|
|
491
|
+
_this.offset = withDefault(0, 0);
|
|
492
|
+
_this.velocity = withDefault(0, 0);
|
|
493
|
+
return _this;
|
|
494
|
+
}
|
|
495
|
+
// @override
|
|
496
|
+
// initialize the events
|
|
497
|
+
DragGesture.prototype._initEvents = function () {
|
|
498
|
+
if (this.targetElement || this.targetElements.length > 0) {
|
|
499
|
+
this._subscribe = attachEvents([window], [
|
|
500
|
+
["mousedown", this.pointerDown.bind(this)],
|
|
501
|
+
["mousemove", this.pointerMove.bind(this)],
|
|
502
|
+
["mouseup", this.pointerUp.bind(this)],
|
|
503
|
+
["touchstart", this.pointerDown.bind(this), { passive: false }],
|
|
504
|
+
["touchmove", this.pointerMove.bind(this), { passive: false }],
|
|
505
|
+
["touchend", this.pointerUp.bind(this)],
|
|
506
|
+
]);
|
|
507
|
+
}
|
|
508
|
+
};
|
|
509
|
+
// @override - cancel events
|
|
510
|
+
// we only canceled down and move events because mouse up
|
|
511
|
+
// will not be triggered
|
|
512
|
+
DragGesture.prototype._cancelEvents = function () {
|
|
513
|
+
if (this._subscribe) {
|
|
514
|
+
this._subscribe(["mousedown", "mousemove", "touchstart", "touchmove"]);
|
|
515
|
+
}
|
|
516
|
+
};
|
|
517
|
+
DragGesture.prototype._handleCallback = function () {
|
|
518
|
+
var _this = this;
|
|
519
|
+
if (this.callback) {
|
|
520
|
+
this.callback({
|
|
521
|
+
args: [this.currentIndex],
|
|
522
|
+
down: this.isActive,
|
|
523
|
+
movementX: this.movement.x,
|
|
524
|
+
movementY: this.movement.y,
|
|
525
|
+
offsetX: this.translation.x,
|
|
526
|
+
offsetY: this.translation.y,
|
|
527
|
+
velocityX: this.velocity.x,
|
|
528
|
+
velocityY: this.velocity.y,
|
|
529
|
+
distanceX: Math.abs(this.movement.x),
|
|
530
|
+
distanceY: Math.abs(this.movement.y),
|
|
531
|
+
directionX: Math.sign(this.movement.x),
|
|
532
|
+
directionY: Math.sign(this.movement.y),
|
|
533
|
+
cancel: function () {
|
|
534
|
+
_this._cancelEvents();
|
|
535
|
+
},
|
|
536
|
+
});
|
|
537
|
+
}
|
|
538
|
+
};
|
|
539
|
+
DragGesture.prototype.pointerDown = function (e) {
|
|
540
|
+
var _a;
|
|
541
|
+
if (e.type === "touchstart") {
|
|
542
|
+
this.movementStart = {
|
|
543
|
+
x: e.touches[0].clientX,
|
|
544
|
+
y: e.touches[0].clientY,
|
|
545
|
+
};
|
|
546
|
+
}
|
|
547
|
+
else {
|
|
548
|
+
this.movementStart = { x: e.clientX, y: e.clientY };
|
|
549
|
+
}
|
|
550
|
+
this.movement = { x: 0, y: 0 };
|
|
551
|
+
this.offset = { x: this.translation.x, y: this.translation.y };
|
|
552
|
+
this.previousMovement = { x: 0, y: 0 };
|
|
553
|
+
this.velocity = { x: 0, y: 0 };
|
|
554
|
+
// find current selected element
|
|
555
|
+
var currElem = this.targetElements.find(function (elem) { return elem === e.target; });
|
|
556
|
+
if (e.target === this.targetElement || currElem) {
|
|
557
|
+
this.isActive = true;
|
|
558
|
+
e.preventDefault();
|
|
559
|
+
// set args
|
|
560
|
+
if (currElem) {
|
|
561
|
+
this.currentIndex = this.targetElements.indexOf(currElem);
|
|
562
|
+
}
|
|
563
|
+
// if initial function is defined then call it to get initial movementX and movementY
|
|
564
|
+
// if only select to bounded draggable element
|
|
565
|
+
var initial = ((_a = this.config) === null || _a === void 0 ? void 0 : _a.initial) && this.config.initial();
|
|
566
|
+
var initialMovementX = initial === null || initial === void 0 ? void 0 : initial.movementX;
|
|
567
|
+
var initialMovementY = initial === null || initial === void 0 ? void 0 : initial.movementY;
|
|
568
|
+
this.initialMovement = {
|
|
569
|
+
x: initialMovementX !== null && initialMovementX !== void 0 ? initialMovementX : 0,
|
|
570
|
+
y: initialMovementY !== null && initialMovementY !== void 0 ? initialMovementY : 0,
|
|
571
|
+
};
|
|
572
|
+
this.movement = {
|
|
573
|
+
x: this.initialMovement.x,
|
|
574
|
+
y: this.initialMovement.y,
|
|
575
|
+
};
|
|
576
|
+
this.previousMovement = {
|
|
577
|
+
x: this.initialMovement.x,
|
|
578
|
+
y: this.initialMovement.y,
|
|
579
|
+
};
|
|
580
|
+
this._handleCallback();
|
|
581
|
+
}
|
|
582
|
+
};
|
|
583
|
+
DragGesture.prototype.pointerMove = function (e) {
|
|
584
|
+
if (this.isActive) {
|
|
585
|
+
e.preventDefault();
|
|
586
|
+
var now = Date.now();
|
|
587
|
+
var deltaTime = Math.min(now - this.lastTimeStamp, 64);
|
|
588
|
+
this.lastTimeStamp = now;
|
|
589
|
+
var t = deltaTime / 1000;
|
|
590
|
+
if (e.type === "touchmove") {
|
|
591
|
+
this.movement = {
|
|
592
|
+
x: this.initialMovement.x +
|
|
593
|
+
(e.touches[0].clientX - this.movementStart.x),
|
|
594
|
+
y: this.initialMovement.y +
|
|
595
|
+
(e.touches[0].clientY - this.movementStart.y),
|
|
596
|
+
};
|
|
466
597
|
}
|
|
467
598
|
else {
|
|
468
|
-
|
|
599
|
+
this.movement = {
|
|
600
|
+
x: this.initialMovement.x + (e.clientX - this.movementStart.x),
|
|
601
|
+
y: this.initialMovement.y + (e.clientY - this.movementStart.y),
|
|
602
|
+
};
|
|
603
|
+
}
|
|
604
|
+
this.translation = {
|
|
605
|
+
x: this.offset.x + this.movement.x,
|
|
606
|
+
y: this.offset.y + this.movement.y,
|
|
607
|
+
};
|
|
608
|
+
this.velocity = {
|
|
609
|
+
x: clamp((this.movement.x - this.previousMovement.x) / t / 1000, -1 * Gesture._VELOCITY_LIMIT, Gesture._VELOCITY_LIMIT),
|
|
610
|
+
y: clamp((this.movement.y - this.previousMovement.y) / t / 1000, -1 * Gesture._VELOCITY_LIMIT, Gesture._VELOCITY_LIMIT),
|
|
611
|
+
};
|
|
612
|
+
this.previousMovement = {
|
|
613
|
+
x: this.movement.x,
|
|
614
|
+
y: this.movement.y,
|
|
615
|
+
};
|
|
616
|
+
this._handleCallback();
|
|
617
|
+
}
|
|
618
|
+
};
|
|
619
|
+
DragGesture.prototype.pointerUp = function () {
|
|
620
|
+
if (this.isActive) {
|
|
621
|
+
this.isActive = false;
|
|
622
|
+
this._handleCallback();
|
|
623
|
+
this._initEvents();
|
|
624
|
+
}
|
|
625
|
+
};
|
|
626
|
+
return DragGesture;
|
|
627
|
+
}(Gesture));
|
|
628
|
+
|
|
629
|
+
var MouseMoveGesture = /** @class */ (function (_super) {
|
|
630
|
+
__extends(MouseMoveGesture, _super);
|
|
631
|
+
function MouseMoveGesture() {
|
|
632
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
633
|
+
_this.movement = withDefault(0, 0);
|
|
634
|
+
_this.previousMovement = withDefault(0, 0);
|
|
635
|
+
_this.velocity = withDefault(0, 0);
|
|
636
|
+
_this.direction = withDefault(0, 0);
|
|
637
|
+
return _this;
|
|
638
|
+
}
|
|
639
|
+
// @override
|
|
640
|
+
// initialize the events
|
|
641
|
+
MouseMoveGesture.prototype._initEvents = function () {
|
|
642
|
+
if (this.targetElement) {
|
|
643
|
+
this._subscribe = attachEvents([this.targetElement], [["mousemove", this.onMouseMove.bind(this)]]);
|
|
644
|
+
}
|
|
645
|
+
else if (this.targetElements.length > 0) {
|
|
646
|
+
this._subscribe = attachEvents(this.targetElements, [
|
|
647
|
+
["mousemove", this.onMouseMove.bind(this)],
|
|
648
|
+
]);
|
|
649
|
+
}
|
|
650
|
+
else {
|
|
651
|
+
this._subscribe = attachEvents([window], [["mousemove", this.onMouseMove.bind(this)]]);
|
|
652
|
+
}
|
|
653
|
+
};
|
|
654
|
+
MouseMoveGesture.prototype._handleCallback = function () {
|
|
655
|
+
var _a;
|
|
656
|
+
if (this.callback) {
|
|
657
|
+
this.callback({
|
|
658
|
+
args: [this.currentIndex],
|
|
659
|
+
event: this.event,
|
|
660
|
+
isMoving: this.isActive,
|
|
661
|
+
target: (_a = this.event) === null || _a === void 0 ? void 0 : _a.target,
|
|
662
|
+
mouseX: this.movement.x,
|
|
663
|
+
mouseY: this.movement.y,
|
|
664
|
+
velocityX: this.velocity.x,
|
|
665
|
+
velocityY: this.velocity.y,
|
|
666
|
+
directionX: this.direction.x,
|
|
667
|
+
directionY: this.direction.y,
|
|
668
|
+
});
|
|
669
|
+
}
|
|
670
|
+
};
|
|
671
|
+
MouseMoveGesture.prototype.onMouseMove = function (e) {
|
|
672
|
+
var _this = this;
|
|
673
|
+
// find current selected element
|
|
674
|
+
var currElem = this.targetElements.find(function (elem) { return elem === e.target; });
|
|
675
|
+
// set args
|
|
676
|
+
if (currElem) {
|
|
677
|
+
this.currentIndex = this.targetElements.indexOf(currElem);
|
|
678
|
+
}
|
|
679
|
+
this.event = e;
|
|
680
|
+
var now = Date.now();
|
|
681
|
+
var deltaTime = Math.min(now - this.lastTimeStamp, 64);
|
|
682
|
+
this.lastTimeStamp = now;
|
|
683
|
+
var t = deltaTime / 1000; // seconds
|
|
684
|
+
var x = e.clientX;
|
|
685
|
+
var y = e.clientY;
|
|
686
|
+
this.movement = { x: x, y: y };
|
|
687
|
+
if (this.isActiveID !== -1) {
|
|
688
|
+
this.isActive = true;
|
|
689
|
+
clearTimeout(this.isActiveID);
|
|
690
|
+
}
|
|
691
|
+
this.isActiveID = setTimeout(function () {
|
|
692
|
+
_this.isActive = false;
|
|
693
|
+
_this.direction = { x: 0, y: 0 };
|
|
694
|
+
_this.velocity = { x: 0, y: 0 };
|
|
695
|
+
_this._handleCallback();
|
|
696
|
+
}, 250); // Debounce 250 milliseconds
|
|
697
|
+
var diffX = this.movement.x - this.previousMovement.x;
|
|
698
|
+
var diffY = this.movement.y - this.previousMovement.y;
|
|
699
|
+
this.direction = {
|
|
700
|
+
x: Math.sign(diffX),
|
|
701
|
+
y: Math.sign(diffY),
|
|
702
|
+
};
|
|
703
|
+
this.velocity = {
|
|
704
|
+
x: clamp(diffX / t / 1000, -1 * Gesture._VELOCITY_LIMIT, Gesture._VELOCITY_LIMIT),
|
|
705
|
+
y: clamp(diffY / t / 1000, -1 * Gesture._VELOCITY_LIMIT, Gesture._VELOCITY_LIMIT),
|
|
706
|
+
};
|
|
707
|
+
this.previousMovement = { x: this.movement.x, y: this.movement.y };
|
|
708
|
+
this._handleCallback();
|
|
709
|
+
};
|
|
710
|
+
return MouseMoveGesture;
|
|
711
|
+
}(Gesture));
|
|
712
|
+
|
|
713
|
+
var ScrollGesture = /** @class */ (function (_super) {
|
|
714
|
+
__extends(ScrollGesture, _super);
|
|
715
|
+
function ScrollGesture() {
|
|
716
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
717
|
+
_this.movement = withDefault(0, 0);
|
|
718
|
+
_this.previousMovement = withDefault(0, 0);
|
|
719
|
+
_this.direction = withDefault(0, 0);
|
|
720
|
+
_this.velocity = withDefault(0, 0);
|
|
721
|
+
return _this;
|
|
722
|
+
}
|
|
723
|
+
// @override
|
|
724
|
+
// initialize the events
|
|
725
|
+
ScrollGesture.prototype._initEvents = function () {
|
|
726
|
+
if (this.targetElement) {
|
|
727
|
+
this._subscribe = attachEvents([this.targetElement], [["scroll", this.scrollElementListener.bind(this)]]);
|
|
728
|
+
}
|
|
729
|
+
else {
|
|
730
|
+
this._subscribe = attachEvents([window], [["scroll", this.scrollListener.bind(this)]]);
|
|
731
|
+
}
|
|
732
|
+
};
|
|
733
|
+
ScrollGesture.prototype._handleCallback = function () {
|
|
734
|
+
if (this.callback) {
|
|
735
|
+
this.callback({
|
|
736
|
+
isScrolling: this.isActive,
|
|
737
|
+
scrollX: this.movement.x,
|
|
738
|
+
scrollY: this.movement.y,
|
|
739
|
+
velocityX: this.velocity.x,
|
|
740
|
+
velocityY: this.velocity.y,
|
|
741
|
+
directionX: this.direction.x,
|
|
742
|
+
directionY: this.direction.y,
|
|
743
|
+
});
|
|
744
|
+
}
|
|
745
|
+
};
|
|
746
|
+
ScrollGesture.prototype.onScroll = function (_a) {
|
|
747
|
+
var _this = this;
|
|
748
|
+
var x = _a.x, y = _a.y;
|
|
749
|
+
var now = Date.now();
|
|
750
|
+
var deltaTime = Math.min(now - this.lastTimeStamp, 64);
|
|
751
|
+
this.lastTimeStamp = now;
|
|
752
|
+
var t = deltaTime / 1000; // seconds
|
|
753
|
+
this.movement = { x: x, y: y };
|
|
754
|
+
// Clear if scrolling
|
|
755
|
+
if (this.isActiveID !== -1) {
|
|
756
|
+
this.isActive = true;
|
|
757
|
+
clearTimeout(this.isActiveID);
|
|
758
|
+
}
|
|
759
|
+
this.isActiveID = setTimeout(function () {
|
|
760
|
+
_this.isActive = false;
|
|
761
|
+
_this.direction = { x: 0, y: 0 };
|
|
762
|
+
// Reset Velocity
|
|
763
|
+
_this.velocity = { x: 0, y: 0 };
|
|
764
|
+
_this._handleCallback(); // Debounce 250milliseconds
|
|
765
|
+
}, 250);
|
|
766
|
+
var diffX = this.movement.x - this.previousMovement.x;
|
|
767
|
+
var diffY = this.movement.y - this.previousMovement.y;
|
|
768
|
+
this.direction = {
|
|
769
|
+
x: Math.sign(diffX),
|
|
770
|
+
y: Math.sign(diffY),
|
|
771
|
+
};
|
|
772
|
+
this.velocity = {
|
|
773
|
+
x: clamp(diffX / t / 1000, -1 * Gesture._VELOCITY_LIMIT, Gesture._VELOCITY_LIMIT),
|
|
774
|
+
y: clamp(diffY / t / 1000, -1 * Gesture._VELOCITY_LIMIT, Gesture._VELOCITY_LIMIT),
|
|
775
|
+
};
|
|
776
|
+
this.previousMovement = {
|
|
777
|
+
x: this.movement.x,
|
|
778
|
+
y: this.movement.y,
|
|
779
|
+
};
|
|
780
|
+
this._handleCallback();
|
|
781
|
+
};
|
|
782
|
+
ScrollGesture.prototype.scrollListener = function () {
|
|
783
|
+
var y = window.pageYOffset, x = window.pageXOffset;
|
|
784
|
+
this.onScroll({ x: x, y: y });
|
|
785
|
+
};
|
|
786
|
+
ScrollGesture.prototype.scrollElementListener = function () {
|
|
787
|
+
var _a, _b;
|
|
788
|
+
var x = ((_a = this.targetElement) === null || _a === void 0 ? void 0 : _a.scrollLeft) || 0;
|
|
789
|
+
var y = ((_b = this.targetElement) === null || _b === void 0 ? void 0 : _b.scrollTop) || 0;
|
|
790
|
+
this.onScroll({ x: x, y: y });
|
|
791
|
+
};
|
|
792
|
+
return ScrollGesture;
|
|
793
|
+
}(Gesture));
|
|
794
|
+
|
|
795
|
+
var LINE_HEIGHT = 40;
|
|
796
|
+
var PAGE_HEIGHT = 800;
|
|
797
|
+
var WheelGesture = /** @class */ (function (_super) {
|
|
798
|
+
__extends(WheelGesture, _super);
|
|
799
|
+
function WheelGesture() {
|
|
800
|
+
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
801
|
+
_this.movement = withDefault(0, 0);
|
|
802
|
+
_this.previousMovement = withDefault(0, 0);
|
|
803
|
+
_this.direction = withDefault(0, 0);
|
|
804
|
+
_this.velocity = withDefault(0, 0);
|
|
805
|
+
_this.delta = withDefault(0, 0);
|
|
806
|
+
// Holds offsets
|
|
807
|
+
_this.offset = withDefault(0, 0);
|
|
808
|
+
_this.translation = withDefault(0, 0);
|
|
809
|
+
return _this;
|
|
810
|
+
}
|
|
811
|
+
// @override
|
|
812
|
+
// initialize the events
|
|
813
|
+
WheelGesture.prototype._initEvents = function () {
|
|
814
|
+
if (this.targetElement) {
|
|
815
|
+
this._subscribe = attachEvents([this.targetElement], [["wheel", this.onWheel.bind(this)]]);
|
|
816
|
+
}
|
|
817
|
+
};
|
|
818
|
+
WheelGesture.prototype._handleCallback = function () {
|
|
819
|
+
if (this.callback) {
|
|
820
|
+
this.callback({
|
|
821
|
+
target: this.targetElement,
|
|
822
|
+
isWheeling: this.isActive,
|
|
823
|
+
deltaX: this.delta.x,
|
|
824
|
+
deltaY: this.delta.y,
|
|
825
|
+
directionX: this.direction.x,
|
|
826
|
+
directionY: this.direction.y,
|
|
827
|
+
movementX: this.movement.x,
|
|
828
|
+
movementY: this.movement.y,
|
|
829
|
+
offsetX: this.offset.x,
|
|
830
|
+
offsetY: this.offset.y,
|
|
831
|
+
velocityX: this.velocity.x,
|
|
832
|
+
velocityY: this.velocity.y,
|
|
833
|
+
});
|
|
834
|
+
}
|
|
835
|
+
};
|
|
836
|
+
WheelGesture.prototype.onWheel = function (event) {
|
|
837
|
+
var _this = this;
|
|
838
|
+
var deltaX = event.deltaX, deltaY = event.deltaY, deltaMode = event.deltaMode;
|
|
839
|
+
var now = Date.now();
|
|
840
|
+
var deltaTime = Math.min(now - this.lastTimeStamp, 64);
|
|
841
|
+
this.lastTimeStamp = now;
|
|
842
|
+
var t = deltaTime / 1000; // seconds
|
|
843
|
+
this.isActive = true;
|
|
844
|
+
if (this.isActiveID !== -1) {
|
|
845
|
+
this.isActive = true;
|
|
846
|
+
clearTimeout(this.isActiveID);
|
|
847
|
+
}
|
|
848
|
+
this.isActiveID = setTimeout(function () {
|
|
849
|
+
_this.isActive = false;
|
|
850
|
+
_this.translation = { x: _this.offset.x, y: _this.offset.y };
|
|
851
|
+
_this._handleCallback();
|
|
852
|
+
_this.velocity = { x: 0, y: 0 }; // Reset Velocity
|
|
853
|
+
_this.movement = { x: 0, y: 0 };
|
|
854
|
+
}, 200);
|
|
855
|
+
// normalize wheel values, especially for Firefox
|
|
856
|
+
if (deltaMode === 1) {
|
|
857
|
+
deltaX *= LINE_HEIGHT;
|
|
858
|
+
deltaY *= LINE_HEIGHT;
|
|
859
|
+
}
|
|
860
|
+
else if (deltaMode === 2) {
|
|
861
|
+
deltaX *= PAGE_HEIGHT;
|
|
862
|
+
deltaY *= PAGE_HEIGHT;
|
|
863
|
+
}
|
|
864
|
+
this.delta = { x: deltaX, y: deltaY };
|
|
865
|
+
this.movement = {
|
|
866
|
+
x: this.movement.x + deltaX,
|
|
867
|
+
y: this.movement.y + deltaY,
|
|
868
|
+
};
|
|
869
|
+
this.offset = {
|
|
870
|
+
x: this.translation.x + this.movement.x,
|
|
871
|
+
y: this.translation.y + this.movement.y,
|
|
872
|
+
};
|
|
873
|
+
var diffX = this.movement.x - this.previousMovement.x;
|
|
874
|
+
var diffY = this.movement.y - this.previousMovement.y;
|
|
875
|
+
this.direction = {
|
|
876
|
+
x: Math.sign(diffX),
|
|
877
|
+
y: Math.sign(diffY),
|
|
878
|
+
};
|
|
879
|
+
this.velocity = {
|
|
880
|
+
x: clamp(diffX / t / 1000, -1 * Gesture._VELOCITY_LIMIT, Gesture._VELOCITY_LIMIT),
|
|
881
|
+
y: clamp(diffY / t / 1000, -1 * Gesture._VELOCITY_LIMIT, Gesture._VELOCITY_LIMIT),
|
|
882
|
+
};
|
|
883
|
+
this.previousMovement = {
|
|
884
|
+
x: this.movement.x,
|
|
885
|
+
y: this.movement.y,
|
|
886
|
+
};
|
|
887
|
+
this._handleCallback();
|
|
888
|
+
};
|
|
889
|
+
return WheelGesture;
|
|
890
|
+
}(Gesture));
|
|
891
|
+
|
|
892
|
+
var useRecognizer = function (handlers) {
|
|
893
|
+
var ref = React.useRef();
|
|
894
|
+
var elementRefs = React.useRef([]);
|
|
895
|
+
var subscribers = React.useRef(new Map()).current;
|
|
896
|
+
// re-initiate callback on change
|
|
897
|
+
React.useEffect(function () {
|
|
898
|
+
var e_1, _a;
|
|
899
|
+
try {
|
|
900
|
+
for (var _b = __values(subscribers.entries()), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
901
|
+
var _d = __read(_c.value, 2), _e = _d[1], keyIndex = _e.keyIndex, gesture = _e.gesture;
|
|
902
|
+
var _f = __read(handlers[keyIndex], 3), callback = _f[2];
|
|
903
|
+
gesture.applyCallback(callback);
|
|
469
904
|
}
|
|
470
905
|
}
|
|
906
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
907
|
+
finally {
|
|
908
|
+
try {
|
|
909
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
910
|
+
}
|
|
911
|
+
finally { if (e_1) throw e_1.error; }
|
|
912
|
+
}
|
|
913
|
+
}, [handlers]);
|
|
914
|
+
React.useEffect(function () {
|
|
915
|
+
handlers.forEach(function (_a, keyIndex) {
|
|
916
|
+
var _b = __read(_a, 4), key = _b[0], gesture = _b[1], callback = _b[2], config = _b[3];
|
|
917
|
+
subscribers.set(key, {
|
|
918
|
+
keyIndex: keyIndex,
|
|
919
|
+
gesture: gesture,
|
|
920
|
+
unsubscribe: gesture.applyGesture({
|
|
921
|
+
targetElement: ref.current,
|
|
922
|
+
targetElements: elementRefs.current,
|
|
923
|
+
callback: callback,
|
|
924
|
+
config: config,
|
|
925
|
+
}),
|
|
926
|
+
});
|
|
927
|
+
});
|
|
471
928
|
return function () {
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
});
|
|
929
|
+
var e_2, _a;
|
|
930
|
+
try {
|
|
931
|
+
for (var _b = __values(subscribers.entries()), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
932
|
+
var _d = __read(_c.value, 2), unsubscribe = _d[1].unsubscribe;
|
|
933
|
+
unsubscribe && unsubscribe();
|
|
478
934
|
}
|
|
479
|
-
|
|
480
|
-
|
|
935
|
+
}
|
|
936
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
937
|
+
finally {
|
|
938
|
+
try {
|
|
939
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
481
940
|
}
|
|
941
|
+
finally { if (e_2) throw e_2.error; }
|
|
482
942
|
}
|
|
483
943
|
};
|
|
484
944
|
}, []);
|
|
@@ -491,76 +951,48 @@ function useMeasure(callback, deps) {
|
|
|
491
951
|
elementRefs.current[index] || React.createRef();
|
|
492
952
|
return { ref: elementRefs.current[index] };
|
|
493
953
|
}
|
|
494
|
-
};
|
|
954
|
+
};
|
|
955
|
+
};
|
|
956
|
+
|
|
957
|
+
function useDrag(callback, config) {
|
|
958
|
+
var gesture = React.useRef(new DragGesture()).current;
|
|
959
|
+
return useRecognizer([["drag", gesture, callback, config]]);
|
|
495
960
|
}
|
|
496
961
|
|
|
497
|
-
function
|
|
498
|
-
var
|
|
499
|
-
|
|
500
|
-
height: 0,
|
|
501
|
-
innerWidth: 0,
|
|
502
|
-
innerHeight: 0,
|
|
503
|
-
});
|
|
504
|
-
var callbackRef = React.useRef(callback);
|
|
505
|
-
var handleCallback = function () {
|
|
506
|
-
if (callbackRef) {
|
|
507
|
-
callbackRef.current(__assign({}, windowDimensionsRef.current));
|
|
508
|
-
}
|
|
509
|
-
};
|
|
510
|
-
// Reinitiate callback when dependency change
|
|
511
|
-
React.useEffect(function () {
|
|
512
|
-
callbackRef.current = callback;
|
|
513
|
-
return function () {
|
|
514
|
-
callbackRef.current = function () { return false; };
|
|
515
|
-
};
|
|
516
|
-
}, deps);
|
|
517
|
-
React.useEffect(function () {
|
|
518
|
-
var resizeObserver = new ResizeObserver(function (_a) {
|
|
519
|
-
var entry = _a[0];
|
|
520
|
-
var _b = entry.target, clientWidth = _b.clientWidth, clientHeight = _b.clientHeight;
|
|
521
|
-
var innerWidth = window.innerWidth, innerHeight = window.innerHeight;
|
|
522
|
-
windowDimensionsRef.current = {
|
|
523
|
-
width: clientWidth,
|
|
524
|
-
height: clientHeight,
|
|
525
|
-
innerWidth: innerWidth,
|
|
526
|
-
innerHeight: innerHeight,
|
|
527
|
-
};
|
|
528
|
-
handleCallback();
|
|
529
|
-
});
|
|
530
|
-
resizeObserver.observe(document.documentElement);
|
|
531
|
-
return function () { return resizeObserver.unobserve(document.documentElement); };
|
|
532
|
-
}, []);
|
|
962
|
+
function useMouseMove(callback) {
|
|
963
|
+
var gesture = React.useRef(new MouseMoveGesture()).current;
|
|
964
|
+
return useRecognizer([["move", gesture, callback]]);
|
|
533
965
|
}
|
|
534
966
|
|
|
535
|
-
function useScroll(callback
|
|
536
|
-
var
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
var
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
var
|
|
547
|
-
var
|
|
548
|
-
var
|
|
549
|
-
var
|
|
550
|
-
var
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
}
|
|
967
|
+
function useScroll(callback) {
|
|
968
|
+
var gesture = React.useRef(new ScrollGesture()).current;
|
|
969
|
+
return useRecognizer([["scroll", gesture, callback]]);
|
|
970
|
+
}
|
|
971
|
+
|
|
972
|
+
function useWheel(callback) {
|
|
973
|
+
var gesture = React.useRef(new WheelGesture()).current;
|
|
974
|
+
return useRecognizer([["wheel", gesture, callback]]);
|
|
975
|
+
}
|
|
976
|
+
|
|
977
|
+
function useGesture(_a) {
|
|
978
|
+
var onDrag = _a.onDrag, onWheel = _a.onWheel, onScroll = _a.onScroll, onMouseMove = _a.onMouseMove;
|
|
979
|
+
var dragGesture = React.useRef(new DragGesture()).current;
|
|
980
|
+
var wheelGesture = React.useRef(new WheelGesture()).current;
|
|
981
|
+
var scrollGesture = React.useRef(new ScrollGesture()).current;
|
|
982
|
+
var mouseMoveGesture = React.useRef(new MouseMoveGesture()).current;
|
|
983
|
+
return useRecognizer([
|
|
984
|
+
["drag", dragGesture, onDrag],
|
|
985
|
+
["wheel", wheelGesture, onWheel],
|
|
986
|
+
["scroll", scrollGesture, onScroll],
|
|
987
|
+
["move", mouseMoveGesture, onMouseMove],
|
|
988
|
+
]);
|
|
989
|
+
}
|
|
990
|
+
|
|
991
|
+
function useOutsideClick(elementRef, callback, deps) {
|
|
992
|
+
var callbackRef = React.useRef();
|
|
993
|
+
if (!callbackRef.current) {
|
|
994
|
+
callbackRef.current = callback;
|
|
995
|
+
}
|
|
564
996
|
// Reinitiate callback when dependency change
|
|
565
997
|
React.useEffect(function () {
|
|
566
998
|
callbackRef.current = callback;
|
|
@@ -569,104 +1001,21 @@ function useScroll(callback, deps) {
|
|
|
569
1001
|
};
|
|
570
1002
|
}, deps);
|
|
571
1003
|
React.useEffect(function () {
|
|
572
|
-
var
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
var deltaTime = Math.min(now - lastTimeStamp.current, 64);
|
|
577
|
-
lastTimeStamp.current = now;
|
|
578
|
-
var t = deltaTime / 1000; // seconds
|
|
579
|
-
scrollXY.current = { x: x, y: y };
|
|
580
|
-
// Clear if scrolling
|
|
581
|
-
if (_isScrolling.current !== -1) {
|
|
582
|
-
isScrolling.current = true;
|
|
583
|
-
clearTimeout(_isScrolling.current);
|
|
1004
|
+
var handleOutsideClick = function (e) {
|
|
1005
|
+
var _a;
|
|
1006
|
+
if (!((_a = elementRef === null || elementRef === void 0 ? void 0 : elementRef.current) === null || _a === void 0 ? void 0 : _a.contains(e.target))) {
|
|
1007
|
+
callbackRef.current && callbackRef.current(e);
|
|
584
1008
|
}
|
|
585
|
-
_isScrolling.current = setTimeout(function () {
|
|
586
|
-
isScrolling.current = false;
|
|
587
|
-
scrollDirection.current = { x: 0, y: 0 };
|
|
588
|
-
// Reset Velocity
|
|
589
|
-
velocity.current = { x: 0, y: 0 };
|
|
590
|
-
handleCallback(); // Debounce 250milliseconds
|
|
591
|
-
}, 250);
|
|
592
|
-
var diffX = scrollXY.current.x - previousScrollXY.current.x;
|
|
593
|
-
var diffY = scrollXY.current.y - previousScrollXY.current.y;
|
|
594
|
-
scrollDirection.current = {
|
|
595
|
-
x: Math.sign(diffX),
|
|
596
|
-
y: Math.sign(diffY),
|
|
597
|
-
};
|
|
598
|
-
velocity.current = {
|
|
599
|
-
x: clamp(diffX / t / 1000, -5, 5),
|
|
600
|
-
y: clamp(diffY / t / 1000, -5, 5),
|
|
601
|
-
};
|
|
602
|
-
previousScrollXY.current = {
|
|
603
|
-
x: scrollXY.current.x,
|
|
604
|
-
y: scrollXY.current.y,
|
|
605
|
-
};
|
|
606
|
-
handleCallback();
|
|
607
|
-
};
|
|
608
|
-
var scrollListener = function () {
|
|
609
|
-
var y = window.pageYOffset, x = window.pageXOffset;
|
|
610
|
-
scrollCallback({ x: x, y: y });
|
|
611
|
-
};
|
|
612
|
-
var scrollElementListener = function () {
|
|
613
|
-
var x = (_refElement === null || _refElement === void 0 ? void 0 : _refElement.scrollLeft) || 0;
|
|
614
|
-
var y = (_refElement === null || _refElement === void 0 ? void 0 : _refElement.scrollTop) || 0;
|
|
615
|
-
scrollCallback({ x: x, y: y });
|
|
616
1009
|
};
|
|
617
|
-
var subscribe;
|
|
618
|
-
if (_refElement) {
|
|
619
|
-
subscribe = attachEvents(_refElement, [
|
|
620
|
-
["scroll", scrollElementListener],
|
|
621
|
-
]);
|
|
622
|
-
}
|
|
623
|
-
else {
|
|
624
|
-
subscribe = attachEvents(window, [["scroll", scrollListener]]);
|
|
625
|
-
}
|
|
1010
|
+
var subscribe = attachEvents([document], [["click", handleOutsideClick]]);
|
|
626
1011
|
return function () { return subscribe && subscribe(); };
|
|
627
1012
|
}, []);
|
|
628
|
-
return function () { return ({ ref: ref }); }; // ...bind()
|
|
629
1013
|
}
|
|
630
1014
|
|
|
631
|
-
function
|
|
632
|
-
var _VELOCITY_LIMIT = 20;
|
|
633
|
-
var currentIndex = React.useRef(undefined);
|
|
1015
|
+
function useMeasure(callback, deps) {
|
|
634
1016
|
var ref = React.useRef(null);
|
|
635
1017
|
var elementRefs = React.useRef([]);
|
|
636
1018
|
var callbackRef = React.useRef(callback);
|
|
637
|
-
var cancelRef = React.useRef();
|
|
638
|
-
var isGestureActive = React.useRef(false);
|
|
639
|
-
// Holds only movement - always starts from 0
|
|
640
|
-
var movement = React.useRef({ x: 0, y: 0 });
|
|
641
|
-
var movementStart = React.useRef({ x: 0, y: 0 });
|
|
642
|
-
var previousMovement = React.useRef({ x: 0, y: 0 });
|
|
643
|
-
var initialMovement = React.useRef({ x: 0, y: 0 });
|
|
644
|
-
// Holds offsets
|
|
645
|
-
var translation = React.useRef({ x: 0, y: 0 });
|
|
646
|
-
var offset = React.useRef({ x: 0, y: 0 });
|
|
647
|
-
var lastTimeStamp = React.useRef(0);
|
|
648
|
-
var velocity = React.useRef({ x: 0, y: 0 });
|
|
649
|
-
var handleCallback = function () {
|
|
650
|
-
if (callbackRef) {
|
|
651
|
-
callbackRef.current({
|
|
652
|
-
args: [currentIndex.current],
|
|
653
|
-
down: isGestureActive.current,
|
|
654
|
-
movementX: movement.current.x,
|
|
655
|
-
movementY: movement.current.y,
|
|
656
|
-
offsetX: translation.current.x,
|
|
657
|
-
offsetY: translation.current.y,
|
|
658
|
-
velocityX: velocity.current.x,
|
|
659
|
-
velocityY: velocity.current.y,
|
|
660
|
-
distanceX: Math.abs(movement.current.x),
|
|
661
|
-
distanceY: Math.abs(movement.current.y),
|
|
662
|
-
directionX: Math.sign(movement.current.x),
|
|
663
|
-
directionY: Math.sign(movement.current.y),
|
|
664
|
-
cancel: function () {
|
|
665
|
-
cancelRef.current && cancelRef.current();
|
|
666
|
-
},
|
|
667
|
-
});
|
|
668
|
-
}
|
|
669
|
-
};
|
|
670
1019
|
// Reinitiate callback when dependency change
|
|
671
1020
|
React.useEffect(function () {
|
|
672
1021
|
callbackRef.current = callback;
|
|
@@ -675,122 +1024,82 @@ function useDrag(callback, config, deps) {
|
|
|
675
1024
|
};
|
|
676
1025
|
}, deps);
|
|
677
1026
|
React.useEffect(function () {
|
|
678
|
-
var
|
|
1027
|
+
var _refElement = ref.current || document.documentElement;
|
|
679
1028
|
var _refElementsMultiple = elementRefs.current;
|
|
680
|
-
var
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
1029
|
+
var resizeObserver = new ResizeObserver(function (_a) {
|
|
1030
|
+
var _b = __read(_a, 1), entry = _b[0];
|
|
1031
|
+
var _c = entry.target.getBoundingClientRect(), left = _c.left, top = _c.top, width = _c.width, height = _c.height;
|
|
1032
|
+
var pageXOffset = window.pageXOffset, pageYOffset = window.pageYOffset;
|
|
1033
|
+
if (callbackRef) {
|
|
1034
|
+
if (_refElement === document.documentElement) {
|
|
1035
|
+
return; // no-op for document
|
|
1036
|
+
}
|
|
1037
|
+
else {
|
|
1038
|
+
callbackRef.current({
|
|
1039
|
+
left: left + pageXOffset,
|
|
1040
|
+
top: top + pageYOffset,
|
|
1041
|
+
width: width,
|
|
1042
|
+
height: height,
|
|
1043
|
+
vLeft: left,
|
|
1044
|
+
vTop: top,
|
|
1045
|
+
});
|
|
1046
|
+
}
|
|
689
1047
|
}
|
|
690
|
-
};
|
|
691
|
-
var
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
1048
|
+
});
|
|
1049
|
+
var resizeObserverMultiple = new ResizeObserver(function (entries) {
|
|
1050
|
+
var left = [];
|
|
1051
|
+
var top = [];
|
|
1052
|
+
var width = [];
|
|
1053
|
+
var height = [];
|
|
1054
|
+
var vLeft = [];
|
|
1055
|
+
var vTop = [];
|
|
1056
|
+
entries.forEach(function (entry) {
|
|
1057
|
+
var _a = entry.target.getBoundingClientRect(), _left = _a.left, _top = _a.top, _width = _a.width, _height = _a.height;
|
|
1058
|
+
var pageXOffset = window.pageXOffset, pageYOffset = window.pageYOffset;
|
|
1059
|
+
var _pageLeft = _left + pageXOffset;
|
|
1060
|
+
var _pageTop = _top + pageYOffset;
|
|
1061
|
+
left.push(_pageLeft);
|
|
1062
|
+
top.push(_pageTop);
|
|
1063
|
+
width.push(_width);
|
|
1064
|
+
height.push(_height);
|
|
1065
|
+
vLeft.push(_left);
|
|
1066
|
+
vTop.push(_top);
|
|
1067
|
+
});
|
|
1068
|
+
if (callbackRef) {
|
|
1069
|
+
callbackRef.current({
|
|
1070
|
+
left: left,
|
|
1071
|
+
top: top,
|
|
1072
|
+
width: width,
|
|
1073
|
+
height: height,
|
|
1074
|
+
vLeft: vLeft,
|
|
1075
|
+
vTop: vTop,
|
|
1076
|
+
});
|
|
697
1077
|
}
|
|
698
|
-
|
|
699
|
-
|
|
1078
|
+
});
|
|
1079
|
+
if (_refElement) {
|
|
1080
|
+
if (_refElement === document.documentElement &&
|
|
1081
|
+
_refElementsMultiple.length > 0) {
|
|
1082
|
+
_refElementsMultiple.forEach(function (element) {
|
|
1083
|
+
resizeObserverMultiple.observe(element.current);
|
|
1084
|
+
});
|
|
700
1085
|
}
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
previousMovement.current = { x: 0, y: 0 };
|
|
704
|
-
velocity.current = { x: 0, y: 0 };
|
|
705
|
-
// find current selected element
|
|
706
|
-
var currElem = _refElementsMultiple.find(function (elem) { return elem.current === e.target; });
|
|
707
|
-
if (e.target === _elemRef || currElem) {
|
|
708
|
-
isGestureActive.current = true;
|
|
709
|
-
e.preventDefault();
|
|
710
|
-
// set args
|
|
711
|
-
if (currElem) {
|
|
712
|
-
currentIndex.current = _refElementsMultiple.indexOf(currElem);
|
|
713
|
-
}
|
|
714
|
-
// if initial function is defined then call it to get initial movementX and movementY
|
|
715
|
-
// if only select to bounded draggable element
|
|
716
|
-
var initial = (config === null || config === void 0 ? void 0 : config.initial) && config.initial();
|
|
717
|
-
var initialMovementX = initial === null || initial === void 0 ? void 0 : initial.movementX;
|
|
718
|
-
var initialMovementY = initial === null || initial === void 0 ? void 0 : initial.movementY;
|
|
719
|
-
initialMovement.current = {
|
|
720
|
-
x: initialMovementX !== null && initialMovementX !== void 0 ? initialMovementX : 0,
|
|
721
|
-
y: initialMovementY !== null && initialMovementY !== void 0 ? initialMovementY : 0,
|
|
722
|
-
};
|
|
723
|
-
movement.current = {
|
|
724
|
-
x: initialMovement.current.x,
|
|
725
|
-
y: initialMovement.current.y,
|
|
726
|
-
};
|
|
727
|
-
previousMovement.current = {
|
|
728
|
-
x: initialMovement.current.x,
|
|
729
|
-
y: initialMovement.current.y,
|
|
730
|
-
};
|
|
731
|
-
handleCallback();
|
|
1086
|
+
else {
|
|
1087
|
+
resizeObserver.observe(_refElement);
|
|
732
1088
|
}
|
|
733
|
-
}
|
|
734
|
-
|
|
735
|
-
if (
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
if (e.type === "touchmove") {
|
|
742
|
-
movement.current = {
|
|
743
|
-
x: initialMovement.current.x +
|
|
744
|
-
(e.touches[0].clientX - movementStart.current.x),
|
|
745
|
-
y: initialMovement.current.y +
|
|
746
|
-
(e.touches[0].clientY - movementStart.current.y),
|
|
747
|
-
};
|
|
1089
|
+
}
|
|
1090
|
+
return function () {
|
|
1091
|
+
if (_refElement) {
|
|
1092
|
+
if (_refElement === document.documentElement &&
|
|
1093
|
+
_refElementsMultiple.length > 0) {
|
|
1094
|
+
_refElementsMultiple.forEach(function (element) {
|
|
1095
|
+
resizeObserverMultiple.unobserve(element.current);
|
|
1096
|
+
});
|
|
748
1097
|
}
|
|
749
1098
|
else {
|
|
750
|
-
|
|
751
|
-
x: initialMovement.current.x + (e.clientX - movementStart.current.x),
|
|
752
|
-
y: initialMovement.current.y + (e.clientY - movementStart.current.y),
|
|
753
|
-
};
|
|
1099
|
+
resizeObserver.unobserve(_refElement);
|
|
754
1100
|
}
|
|
755
|
-
translation.current = {
|
|
756
|
-
x: offset.current.x + movement.current.x,
|
|
757
|
-
y: offset.current.y + movement.current.y,
|
|
758
|
-
};
|
|
759
|
-
velocity.current = {
|
|
760
|
-
x: clamp((movement.current.x - previousMovement.current.x) / t / 1000, -_VELOCITY_LIMIT, _VELOCITY_LIMIT),
|
|
761
|
-
y: clamp((movement.current.y - previousMovement.current.y) / t / 1000, -_VELOCITY_LIMIT, _VELOCITY_LIMIT),
|
|
762
|
-
};
|
|
763
|
-
previousMovement.current = {
|
|
764
|
-
x: movement.current.x,
|
|
765
|
-
y: movement.current.y,
|
|
766
|
-
};
|
|
767
|
-
handleCallback();
|
|
768
|
-
}
|
|
769
|
-
};
|
|
770
|
-
var pointerUp = function () {
|
|
771
|
-
if (isGestureActive.current) {
|
|
772
|
-
isGestureActive.current = false;
|
|
773
|
-
handleCallback();
|
|
774
|
-
_initEvents();
|
|
775
1101
|
}
|
|
776
1102
|
};
|
|
777
|
-
var subscribe;
|
|
778
|
-
if (_elemRef || _refElementsMultiple.length > 0) {
|
|
779
|
-
subscribe = attachEvents(window, [
|
|
780
|
-
["mousedown", pointerDown],
|
|
781
|
-
["mousemove", pointerMove],
|
|
782
|
-
["mouseup", pointerUp],
|
|
783
|
-
["touchstart", pointerDown, { passive: false }],
|
|
784
|
-
["touchmove", pointerMove, { passive: false }],
|
|
785
|
-
["touchend", pointerUp],
|
|
786
|
-
]);
|
|
787
|
-
}
|
|
788
|
-
var _cancelEvents = function () {
|
|
789
|
-
_initEvents(); // When cancel is called for first time reSubscription is undefined, so initializing reSubscribe and calling it fixes the issue
|
|
790
|
-
reSubscribe && reSubscribe();
|
|
791
|
-
};
|
|
792
|
-
cancelRef.current = _cancelEvents;
|
|
793
|
-
return function () { return subscribe && subscribe(); };
|
|
794
1103
|
}, []);
|
|
795
1104
|
return function (index) {
|
|
796
1105
|
if (index === null || index === undefined) {
|
|
@@ -801,145 +1110,20 @@ function useDrag(callback, config, deps) {
|
|
|
801
1110
|
elementRefs.current[index] || React.createRef();
|
|
802
1111
|
return { ref: elementRefs.current[index] };
|
|
803
1112
|
}
|
|
804
|
-
};
|
|
805
|
-
}
|
|
806
|
-
|
|
807
|
-
function useMouseMove(callback, deps) {
|
|
808
|
-
var _VELOCITY_LIMIT = 20;
|
|
809
|
-
var ref = React.useRef(null);
|
|
810
|
-
var callbackRef = React.useRef(callback);
|
|
811
|
-
var isMoving = React.useRef(false);
|
|
812
|
-
var _isMoving = React.useRef(-1);
|
|
813
|
-
var mouseXY = React.useRef({ x: 0, y: 0 });
|
|
814
|
-
var prevMouseXY = React.useRef({ x: 0, y: 0 });
|
|
815
|
-
var directionXY = React.useRef({ x: 0, y: 0 });
|
|
816
|
-
var velocityXY = React.useRef({ x: 0, y: 0 });
|
|
817
|
-
var currentEvent = React.useRef();
|
|
818
|
-
var lastTimeStamp = React.useRef(0);
|
|
819
|
-
var handleCallback = function () {
|
|
820
|
-
var _a;
|
|
821
|
-
if (callbackRef) {
|
|
822
|
-
callbackRef.current({
|
|
823
|
-
target: (_a = currentEvent.current) === null || _a === void 0 ? void 0 : _a.target,
|
|
824
|
-
isMoving: isMoving.current,
|
|
825
|
-
mouseX: mouseXY.current.x,
|
|
826
|
-
mouseY: mouseXY.current.y,
|
|
827
|
-
velocityX: velocityXY.current.x,
|
|
828
|
-
velocityY: velocityXY.current.y,
|
|
829
|
-
directionX: directionXY.current.x,
|
|
830
|
-
directionY: directionXY.current.y,
|
|
831
|
-
});
|
|
832
|
-
}
|
|
833
|
-
};
|
|
834
|
-
// Reinitiate callback when dependency change
|
|
835
|
-
React.useEffect(function () {
|
|
836
|
-
callbackRef.current = callback;
|
|
837
|
-
return function () {
|
|
838
|
-
callbackRef.current = function () { return false; };
|
|
839
|
-
};
|
|
840
|
-
}, deps);
|
|
841
|
-
React.useEffect(function () {
|
|
842
|
-
var _refElement = ref.current;
|
|
843
|
-
var mouseMove = function (_a) {
|
|
844
|
-
var e = _a.e, x = _a.x, y = _a.y;
|
|
845
|
-
var now = Date.now();
|
|
846
|
-
var deltaTime = Math.min(now - lastTimeStamp.current, 64);
|
|
847
|
-
lastTimeStamp.current = now;
|
|
848
|
-
var t = deltaTime / 1000; // seconds
|
|
849
|
-
mouseXY.current = { x: x, y: y };
|
|
850
|
-
currentEvent.current = e;
|
|
851
|
-
if (_isMoving.current !== -1) {
|
|
852
|
-
isMoving.current = true;
|
|
853
|
-
clearTimeout(_isMoving.current);
|
|
854
|
-
}
|
|
855
|
-
_isMoving.current = setTimeout(function () {
|
|
856
|
-
isMoving.current = false;
|
|
857
|
-
directionXY.current = { x: 0, y: 0 };
|
|
858
|
-
velocityXY.current = { x: 0, y: 0 };
|
|
859
|
-
handleCallback();
|
|
860
|
-
}, 250); // Debounce 250 milliseconds
|
|
861
|
-
var diffX = mouseXY.current.x - prevMouseXY.current.x;
|
|
862
|
-
var diffY = mouseXY.current.y - prevMouseXY.current.y;
|
|
863
|
-
directionXY.current = {
|
|
864
|
-
x: Math.sign(diffX),
|
|
865
|
-
y: Math.sign(diffY),
|
|
866
|
-
};
|
|
867
|
-
velocityXY.current = {
|
|
868
|
-
x: clamp(diffX / t / 1000, -_VELOCITY_LIMIT, _VELOCITY_LIMIT),
|
|
869
|
-
y: clamp(diffY / t / 1000, -_VELOCITY_LIMIT, _VELOCITY_LIMIT),
|
|
870
|
-
};
|
|
871
|
-
prevMouseXY.current = { x: mouseXY.current.x, y: mouseXY.current.y };
|
|
872
|
-
handleCallback();
|
|
873
|
-
};
|
|
874
|
-
var mouseMoveElementListener = function (e) {
|
|
875
|
-
/** Is offsetLeft / offsetTop needed here ???
|
|
876
|
-
* const elementOffsetLeft = _refElement?.offsetLeft || 0;
|
|
877
|
-
* const elementOffsetTop = _refElement?.offsetTop || 0;
|
|
878
|
-
*/
|
|
879
|
-
mouseMove({
|
|
880
|
-
e: e,
|
|
881
|
-
x: e.clientX,
|
|
882
|
-
y: e.clientY,
|
|
883
|
-
});
|
|
884
|
-
};
|
|
885
|
-
var mouseMoveListener = function (e) {
|
|
886
|
-
mouseMove({ e: e, x: e.clientX, y: e.clientY });
|
|
887
|
-
};
|
|
888
|
-
var subscribe;
|
|
889
|
-
if (_refElement) {
|
|
890
|
-
subscribe = attachEvents(_refElement, [
|
|
891
|
-
["mousemove", mouseMoveElementListener],
|
|
892
|
-
]);
|
|
893
|
-
}
|
|
894
|
-
else {
|
|
895
|
-
subscribe = attachEvents(window, [["mousemove", mouseMoveListener]]);
|
|
896
|
-
}
|
|
897
|
-
return function () { return subscribe && subscribe(); };
|
|
898
|
-
}, []);
|
|
899
|
-
return function () { return ({ ref: ref }); }; // ...bind()
|
|
1113
|
+
}; // ...bind() or ...bind(index) for multiple
|
|
900
1114
|
}
|
|
901
1115
|
|
|
902
|
-
|
|
903
|
-
var
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
var movementXY = React.useRef({
|
|
909
|
-
x: 0,
|
|
910
|
-
y: 0,
|
|
911
|
-
});
|
|
912
|
-
var previousMovementXY = React.useRef({
|
|
913
|
-
x: 0,
|
|
914
|
-
y: 0,
|
|
915
|
-
});
|
|
916
|
-
var deltaXY = React.useRef({
|
|
917
|
-
x: 0,
|
|
918
|
-
y: 0,
|
|
1116
|
+
function useWindowDimension(callback, deps) {
|
|
1117
|
+
var windowDimensionsRef = React.useRef({
|
|
1118
|
+
width: 0,
|
|
1119
|
+
height: 0,
|
|
1120
|
+
innerWidth: 0,
|
|
1121
|
+
innerHeight: 0,
|
|
919
1122
|
});
|
|
920
|
-
var direction = React.useRef({ x: 0, y: 0 });
|
|
921
|
-
var lastTimeStamp = React.useRef(0);
|
|
922
|
-
var velocity = React.useRef({ x: 0, y: 0 });
|
|
923
|
-
// Holds offsets
|
|
924
|
-
var offset = React.useRef({ x: 0, y: 0 });
|
|
925
|
-
var translation = React.useRef({ x: 0, y: 0 });
|
|
926
1123
|
var callbackRef = React.useRef(callback);
|
|
927
1124
|
var handleCallback = function () {
|
|
928
1125
|
if (callbackRef) {
|
|
929
|
-
callbackRef.current({
|
|
930
|
-
target: ref.current,
|
|
931
|
-
isWheeling: isWheeling.current,
|
|
932
|
-
deltaX: deltaXY.current.x,
|
|
933
|
-
deltaY: deltaXY.current.y,
|
|
934
|
-
directionX: direction.current.x,
|
|
935
|
-
directionY: direction.current.y,
|
|
936
|
-
movementX: movementXY.current.x,
|
|
937
|
-
movementY: movementXY.current.y,
|
|
938
|
-
offsetX: offset.current.x,
|
|
939
|
-
offsetY: offset.current.y,
|
|
940
|
-
velocityX: velocity.current.x,
|
|
941
|
-
velocityY: velocity.current.y,
|
|
942
|
-
});
|
|
1126
|
+
callbackRef.current(__assign({}, windowDimensionsRef.current));
|
|
943
1127
|
}
|
|
944
1128
|
};
|
|
945
1129
|
// Reinitiate callback when dependency change
|
|
@@ -950,77 +1134,33 @@ function useWheel(callback, deps) {
|
|
|
950
1134
|
};
|
|
951
1135
|
}, deps);
|
|
952
1136
|
React.useEffect(function () {
|
|
953
|
-
var
|
|
954
|
-
|
|
955
|
-
var
|
|
956
|
-
var
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
isWheeling.current = true;
|
|
963
|
-
clearTimeout(isWheelingID.current);
|
|
964
|
-
}
|
|
965
|
-
isWheelingID.current = setTimeout(function () {
|
|
966
|
-
isWheeling.current = false;
|
|
967
|
-
translation.current = { x: offset.current.x, y: offset.current.y };
|
|
968
|
-
handleCallback();
|
|
969
|
-
velocity.current = { x: 0, y: 0 }; // Reset Velocity
|
|
970
|
-
movementXY.current = { x: 0, y: 0 };
|
|
971
|
-
}, 200);
|
|
972
|
-
// normalize wheel values, especially for Firefox
|
|
973
|
-
if (deltaMode === 1) {
|
|
974
|
-
deltaX *= LINE_HEIGHT;
|
|
975
|
-
deltaY *= LINE_HEIGHT;
|
|
976
|
-
}
|
|
977
|
-
else if (deltaMode === 2) {
|
|
978
|
-
deltaX *= PAGE_HEIGHT;
|
|
979
|
-
deltaY *= PAGE_HEIGHT;
|
|
980
|
-
}
|
|
981
|
-
deltaXY.current = { x: deltaX, y: deltaY };
|
|
982
|
-
movementXY.current = {
|
|
983
|
-
x: movementXY.current.x + deltaX,
|
|
984
|
-
y: movementXY.current.y + deltaY,
|
|
985
|
-
};
|
|
986
|
-
offset.current = {
|
|
987
|
-
x: translation.current.x + movementXY.current.x,
|
|
988
|
-
y: translation.current.y + movementXY.current.y,
|
|
989
|
-
};
|
|
990
|
-
var diffX = movementXY.current.x - previousMovementXY.current.x;
|
|
991
|
-
var diffY = movementXY.current.y - previousMovementXY.current.y;
|
|
992
|
-
direction.current = {
|
|
993
|
-
x: Math.sign(diffX),
|
|
994
|
-
y: Math.sign(diffY),
|
|
995
|
-
};
|
|
996
|
-
velocity.current = {
|
|
997
|
-
x: clamp(diffX / t / 1000, -20, 20),
|
|
998
|
-
y: clamp(diffY / t / 1000, -20, 20),
|
|
999
|
-
};
|
|
1000
|
-
previousMovementXY.current = {
|
|
1001
|
-
x: movementXY.current.x,
|
|
1002
|
-
y: movementXY.current.y,
|
|
1137
|
+
var resizeObserver = new ResizeObserver(function (_a) {
|
|
1138
|
+
var _b = __read(_a, 1), entry = _b[0];
|
|
1139
|
+
var _c = entry.target, clientWidth = _c.clientWidth, clientHeight = _c.clientHeight;
|
|
1140
|
+
var innerWidth = window.innerWidth, innerHeight = window.innerHeight;
|
|
1141
|
+
windowDimensionsRef.current = {
|
|
1142
|
+
width: clientWidth,
|
|
1143
|
+
height: clientHeight,
|
|
1144
|
+
innerWidth: innerWidth,
|
|
1145
|
+
innerHeight: innerHeight,
|
|
1003
1146
|
};
|
|
1004
1147
|
handleCallback();
|
|
1005
|
-
};
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
subscribe = attachEvents(_refElement, [["wheel", wheelListener]]);
|
|
1009
|
-
}
|
|
1010
|
-
return function () { return subscribe && subscribe(); };
|
|
1148
|
+
});
|
|
1149
|
+
resizeObserver.observe(document.documentElement);
|
|
1150
|
+
return function () { return resizeObserver.unobserve(document.documentElement); };
|
|
1011
1151
|
}, []);
|
|
1012
|
-
return function () { return ({ ref: ref }); }; // ...bind()
|
|
1013
1152
|
}
|
|
1014
1153
|
|
|
1015
1154
|
Object.defineProperty(exports, 'Easing', {
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1155
|
+
enumerable: true,
|
|
1156
|
+
get: function () {
|
|
1157
|
+
return reMotion.Easing;
|
|
1158
|
+
}
|
|
1020
1159
|
});
|
|
1021
1160
|
exports.AnimatedBlock = AnimatedBlock;
|
|
1022
1161
|
exports.AnimatedImage = AnimatedImage;
|
|
1023
1162
|
exports.AnimatedInline = AnimatedInline;
|
|
1163
|
+
exports.MountedBlock = MountedBlock;
|
|
1024
1164
|
exports.ScrollableBlock = ScrollableBlock;
|
|
1025
1165
|
exports.bInterpolate = bInterpolate;
|
|
1026
1166
|
exports.bin = bin;
|
|
@@ -1033,6 +1173,7 @@ exports.rubberClamp = rubberClamp;
|
|
|
1033
1173
|
exports.snapTo = snapTo;
|
|
1034
1174
|
exports.useAnimatedValue = useAnimatedValue;
|
|
1035
1175
|
exports.useDrag = useDrag;
|
|
1176
|
+
exports.useGesture = useGesture;
|
|
1036
1177
|
exports.useMeasure = useMeasure;
|
|
1037
1178
|
exports.useMountedValue = useMountedValue;
|
|
1038
1179
|
exports.useMouseMove = useMouseMove;
|