react-ui-animate 3.0.0-rc.0 → 3.0.0-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/animation/core/helpers/isDefined.d.ts +1 -1
- package/dist/animation/core/helpers/isFluidValue.d.ts +8 -4
- package/dist/animation/lib/interpolation.d.ts +20 -15
- package/dist/gestures/helpers/math.d.ts +1 -1
- package/dist/index.js +1 -2897
- package/dist/index.js.map +1 -1
- package/package.json +2 -1
- package/.vscode/settings.json +0 -3
- package/dist/animation/animationType.d.ts +0 -15
- package/dist/animation/core/animation/Animation.d.ts +0 -16
- package/dist/animation/core/animation/FluidValue.d.ts +0 -21
- package/dist/animation/core/animation/RequestAnimationFrame.d.ts +0 -8
- package/dist/animation/core/animation/SpringAnimation.d.ts +0 -41
- package/dist/animation/core/animation/TimingAnimation.d.ts +0 -35
- package/dist/animation/core/animation/TransitionValue.d.ts +0 -21
- package/dist/animation/core/helpers/camelToDash.d.ts +0 -7
- package/dist/animation/core/helpers/canInterpolate.d.ts +0 -11
- package/dist/animation/core/helpers/getAnimatableObject.d.ts +0 -22
- package/dist/animation/core/helpers/getNonAnimatableStyle.d.ts +0 -6
- package/dist/animation/core/react/Tags.d.ts +0 -3
- package/dist/animation/core/react/TransformStyles.d.ts +0 -8
- package/dist/animation/core/react/animated.d.ts +0 -29
- package/dist/animation/core/react/combineRefs.d.ts +0 -2
- package/dist/animation/core/react/functions/camelToDash.d.ts +0 -7
- package/dist/animation/core/react/functions/getAnimatableObject.d.ts +0 -22
- package/dist/animation/core/react/functions/getCleanProps.d.ts +0 -4
- package/dist/animation/core/react/functions/getCssValue.d.ts +0 -8
- package/dist/animation/core/react/functions/getNonAnimatableStyle.d.ts +0 -6
- package/dist/animation/core/react/functions/index.d.ts +0 -7
- package/dist/animation/core/react/functions/isDefined.d.ts +0 -6
- package/dist/animation/core/react/functions/isTransitionValue.d.ts +0 -6
- package/dist/animation/core/react/helpers/camelToDash.d.ts +0 -7
- package/dist/animation/core/react/helpers/canInterpolate.d.ts +0 -7
- package/dist/animation/core/react/helpers/getAnimatableObject.d.ts +0 -22
- package/dist/animation/core/react/helpers/getCleanProps.d.ts +0 -4
- package/dist/animation/core/react/helpers/getCssValue.d.ts +0 -8
- package/dist/animation/core/react/helpers/getNonAnimatableStyle.d.ts +0 -6
- package/dist/animation/core/react/helpers/index.d.ts +0 -7
- package/dist/animation/core/react/helpers/isDefined.d.ts +0 -6
- package/dist/animation/core/react/helpers/isFluidValue.d.ts +0 -6
- package/dist/animation/core/react/helpers/isTransitionValue.d.ts +0 -6
- package/dist/animation/core/react/useMounts.d.ts +0 -26
- package/dist/animation/core/react/useTransition.d.ts +0 -9
- package/dist/animation/core/react/useTransitions.d.ts +0 -11
- package/dist/animation/core/types/animation.d.ts +0 -54
- package/dist/animation/core/types/common.d.ts +0 -4
- package/dist/animation/core/types/fluid.d.ts +0 -19
- package/dist/animation/core/types/index.d.ts +0 -2
- package/dist/animation/getInitialConfig.d.ts +0 -3
- package/dist/animation/index.d.ts +0 -6
- package/dist/animation/interpolation.d.ts +0 -21
- package/dist/animation/modules/AnimatedBlock.d.ts +0 -8
- package/dist/animation/modules/AnimatedImage.d.ts +0 -8
- package/dist/animation/modules/AnimatedInline.d.ts +0 -8
- package/dist/animation/modules/MountedBlock.d.ts +0 -29
- package/dist/animation/modules/ScrollableBlock.d.ts +0 -21
- package/dist/animation/modules/TransitionBlock.d.ts +0 -17
- package/dist/animation/modules/index.d.ts +0 -6
- package/dist/animation/useAnimatedValue.d.ts +0 -22
- package/dist/animation/useMountedValue.d.ts +0 -15
- package/dist/gestures/eventAttacher.d.ts +0 -11
- package/dist/gestures/index.d.ts +0 -2
- package/dist/gestures/math.d.ts +0 -34
- package/dist/gestures/types.d.ts +0 -51
- package/dist/gestures/withDefault.d.ts +0 -4
- package/dist/utils/isDefined.d.ts +0 -1
- package/ecosystem.config.js +0 -12
- package/example/README.md +0 -46
- package/example/package-lock.json +0 -19597
- package/example/package.json +0 -45
- package/example/public/favicon.ico +0 -0
- package/example/public/index.html +0 -20
- package/example/public/logo192.png +0 -0
- package/example/public/logo512.png +0 -0
- package/example/public/manifest.json +0 -25
- package/example/public/robots.txt +0 -3
- package/example/src/App.tsx +0 -41
- package/example/src/components/Draggable.tsx +0 -46
- package/example/src/components/Gestures.tsx +0 -151
- package/example/src/components/Interpolation.tsx +0 -21
- package/example/src/components/Loop.tsx +0 -48
- package/example/src/components/MountedBlock.tsx +0 -25
- package/example/src/components/MouseMove.tsx +0 -59
- package/example/src/components/MultistageTransition.tsx +0 -34
- package/example/src/components/Scroll.tsx +0 -39
- package/example/src/components/ScrollableBlock.tsx +0 -27
- package/example/src/components/SnapTo.tsx +0 -55
- package/example/src/components/TransitionBlock.tsx +0 -37
- package/example/src/components/Wheel.tsx +0 -39
- package/example/src/components/index.ts +0 -18
- package/example/src/components/svgLine.tsx +0 -48
- package/example/src/components/useAnimatedValue.tsx +0 -57
- package/example/src/components/useMountedValue.tsx +0 -62
- package/example/src/index.css +0 -8
- package/example/src/index.tsx +0 -16
- package/example/tsconfig.json +0 -26
- package/rollup.config.mjs +0 -18
- package/src/animation/core/controllers/Animation.ts +0 -27
- package/src/animation/core/controllers/FluidValue.ts +0 -97
- package/src/animation/core/controllers/RequestAnimationFrame.ts +0 -13
- package/src/animation/core/controllers/SpringAnimation.ts +0 -218
- package/src/animation/core/controllers/TimingAnimation.ts +0 -152
- package/src/animation/core/easing/Bezier.ts +0 -146
- package/src/animation/core/easing/Easing.ts +0 -132
- package/src/animation/core/helpers/camelCaseToKebabCase.ts +0 -10
- package/src/animation/core/helpers/getCleanProps.ts +0 -16
- package/src/animation/core/helpers/getCssValue.ts +0 -60
- package/src/animation/core/helpers/index.ts +0 -5
- package/src/animation/core/helpers/isDefined.ts +0 -14
- package/src/animation/core/helpers/isFluidValue.ts +0 -11
- package/src/animation/core/index.ts +0 -16
- package/src/animation/core/interpolation/Colors.ts +0 -232
- package/src/animation/core/interpolation/Interpolation.ts +0 -395
- package/src/animation/core/interpolation/__tests__/Colors.test.tsx +0 -35
- package/src/animation/core/react/fluid.ts +0 -197
- package/src/animation/core/react/makeFluid.ts +0 -294
- package/src/animation/core/react/transforms.ts +0 -90
- package/src/animation/core/react/useFluidValue.ts +0 -43
- package/src/animation/core/react/useMount.ts +0 -58
- package/src/animation/core/types/animation.d.ts +0 -56
- package/src/animation/core/types/common.d.ts +0 -4
- package/src/animation/core/types/fluid.d.ts +0 -38
- package/src/animation/lib/animationType.ts +0 -17
- package/src/animation/lib/getInitialConfig.ts +0 -61
- package/src/animation/lib/index.ts +0 -12
- package/src/animation/lib/interpolation.ts +0 -47
- package/src/animation/lib/modules/AnimatedBlock.ts +0 -8
- package/src/animation/lib/modules/AnimatedImage.ts +0 -8
- package/src/animation/lib/modules/AnimatedInline.ts +0 -8
- package/src/animation/lib/modules/MountedBlock.tsx +0 -51
- package/src/animation/lib/modules/ScrollableBlock.tsx +0 -68
- package/src/animation/lib/modules/TransitionBlock.tsx +0 -28
- package/src/animation/lib/modules/index.ts +0 -6
- package/src/animation/lib/useAnimatedValue.ts +0 -60
- package/src/animation/lib/useMountedValue.ts +0 -18
- package/src/gestures/controllers/DragGesture.ts +0 -178
- package/src/gestures/controllers/Gesture.ts +0 -54
- package/src/gestures/controllers/MouseMoveGesture.ts +0 -111
- package/src/gestures/controllers/ScrollGesture.ts +0 -107
- package/src/gestures/controllers/WheelGesture.ts +0 -123
- package/src/gestures/controllers/index.ts +0 -4
- package/src/gestures/helpers/eventAttacher.ts +0 -67
- package/src/gestures/helpers/index.ts +0 -1
- package/src/gestures/helpers/math.ts +0 -120
- package/src/gestures/helpers/withDefault.ts +0 -3
- package/src/gestures/hooks/index.ts +0 -5
- package/src/gestures/hooks/useDrag.ts +0 -14
- package/src/gestures/hooks/useGesture.ts +0 -38
- package/src/gestures/hooks/useMouseMove.ts +0 -11
- package/src/gestures/hooks/useRecognizer.ts +0 -59
- package/src/gestures/hooks/useScroll.ts +0 -11
- package/src/gestures/hooks/useWheel.ts +0 -11
- package/src/gestures/types/index.d.ts +0 -49
- package/src/hooks/index.ts +0 -3
- package/src/hooks/useMeasure.ts +0 -132
- package/src/hooks/useOutsideClick.ts +0 -36
- package/src/hooks/useWindowDimension.ts +0 -58
- package/src/index.ts +0 -42
- package/src/utils/delay.ts +0 -9
- package/src/utils/index.ts +0 -1
- package/tsconfig.json +0 -24
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
export class Gesture {
|
|
2
|
-
currentIndex?: number;
|
|
3
|
-
lastTimeStamp: number = Date.now();
|
|
4
|
-
isActive: boolean = false;
|
|
5
|
-
targetElement?: HTMLElement; // represents the bounded element
|
|
6
|
-
targetElements: Array<HTMLElement> = []; // represents the bounded elements
|
|
7
|
-
config?: any;
|
|
8
|
-
callback?: <T>(event: T) => void;
|
|
9
|
-
_subscribe?: (eventKeys?: Array<string>) => void;
|
|
10
|
-
static _VELOCITY_LIMIT: number = 20;
|
|
11
|
-
|
|
12
|
-
// it must be overridden by other child classes
|
|
13
|
-
_initEvents() {}
|
|
14
|
-
|
|
15
|
-
// cancel events
|
|
16
|
-
// we only canceled down and move events because mouse up
|
|
17
|
-
// will not be triggered
|
|
18
|
-
_cancelEvents() {
|
|
19
|
-
if (this._subscribe) {
|
|
20
|
-
this._subscribe();
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// re-apply new callback
|
|
25
|
-
applyCallback(callback: <T>(event: T) => void) {
|
|
26
|
-
this.callback = callback;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// apply gesture
|
|
30
|
-
applyGesture({
|
|
31
|
-
targetElement,
|
|
32
|
-
targetElements,
|
|
33
|
-
callback,
|
|
34
|
-
config,
|
|
35
|
-
}: {
|
|
36
|
-
targetElement?: any;
|
|
37
|
-
targetElements?: any;
|
|
38
|
-
callback: <T>(event: T) => void;
|
|
39
|
-
config?: any;
|
|
40
|
-
}) {
|
|
41
|
-
this.targetElement = targetElement;
|
|
42
|
-
this.targetElements = targetElements.map(
|
|
43
|
-
(element: { current: any }) => element.current
|
|
44
|
-
);
|
|
45
|
-
this.callback = callback;
|
|
46
|
-
this.config = config;
|
|
47
|
-
|
|
48
|
-
// initialize events
|
|
49
|
-
this._initEvents();
|
|
50
|
-
|
|
51
|
-
// unbind
|
|
52
|
-
return () => this._subscribe && this._subscribe();
|
|
53
|
-
}
|
|
54
|
-
}
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import { attachEvents } from '../helpers/eventAttacher';
|
|
2
|
-
import { Vector2 } from '../types';
|
|
3
|
-
import { clamp } from '../helpers/math';
|
|
4
|
-
import { withDefault } from '../helpers/withDefault';
|
|
5
|
-
import { Gesture } from './Gesture';
|
|
6
|
-
|
|
7
|
-
export class MouseMoveGesture extends Gesture {
|
|
8
|
-
event?: MouseEvent;
|
|
9
|
-
isActiveID?: any;
|
|
10
|
-
movement: Vector2 = withDefault(0, 0);
|
|
11
|
-
previousMovement: Vector2 = withDefault(0, 0);
|
|
12
|
-
velocity: Vector2 = withDefault(0, 0);
|
|
13
|
-
direction: Vector2 = withDefault(0, 0);
|
|
14
|
-
|
|
15
|
-
// @override
|
|
16
|
-
// initialize the events
|
|
17
|
-
_initEvents() {
|
|
18
|
-
if (this.targetElement) {
|
|
19
|
-
this._subscribe = attachEvents(
|
|
20
|
-
[this.targetElement],
|
|
21
|
-
[['mousemove', this.onMouseMove.bind(this)]]
|
|
22
|
-
);
|
|
23
|
-
} else if (this.targetElements.length > 0) {
|
|
24
|
-
this._subscribe = attachEvents(this.targetElements, [
|
|
25
|
-
['mousemove', this.onMouseMove.bind(this)],
|
|
26
|
-
]);
|
|
27
|
-
} else {
|
|
28
|
-
this._subscribe = attachEvents(
|
|
29
|
-
[window],
|
|
30
|
-
[['mousemove', this.onMouseMove.bind(this)]]
|
|
31
|
-
);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
_handleCallback() {
|
|
36
|
-
if (this.callback) {
|
|
37
|
-
this.callback({
|
|
38
|
-
args: [this.currentIndex],
|
|
39
|
-
event: this.event,
|
|
40
|
-
isMoving: this.isActive,
|
|
41
|
-
target: this.event?.target,
|
|
42
|
-
mouseX: this.movement.x,
|
|
43
|
-
mouseY: this.movement.y,
|
|
44
|
-
velocityX: this.velocity.x,
|
|
45
|
-
velocityY: this.velocity.y,
|
|
46
|
-
directionX: this.direction.x,
|
|
47
|
-
directionY: this.direction.y,
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
onMouseMove(e: MouseEvent) {
|
|
53
|
-
// find current selected element
|
|
54
|
-
const currElem = this.targetElements.find((elem: any) => elem === e.target);
|
|
55
|
-
|
|
56
|
-
// set args
|
|
57
|
-
if (currElem) {
|
|
58
|
-
this.currentIndex = this.targetElements.indexOf(currElem);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
this.event = e;
|
|
62
|
-
|
|
63
|
-
const now: number = Date.now();
|
|
64
|
-
const deltaTime = Math.min(now - this.lastTimeStamp, 64);
|
|
65
|
-
this.lastTimeStamp = now;
|
|
66
|
-
const t = deltaTime / 1000; // seconds
|
|
67
|
-
|
|
68
|
-
const x = e.clientX;
|
|
69
|
-
const y = e.clientY;
|
|
70
|
-
|
|
71
|
-
this.movement = { x, y };
|
|
72
|
-
|
|
73
|
-
if (this.isActiveID !== -1) {
|
|
74
|
-
this.isActive = true;
|
|
75
|
-
clearTimeout(this.isActiveID);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
this.isActiveID = setTimeout(() => {
|
|
79
|
-
this.isActive = false;
|
|
80
|
-
this.direction = { x: 0, y: 0 };
|
|
81
|
-
this.velocity = { x: 0, y: 0 };
|
|
82
|
-
|
|
83
|
-
this._handleCallback();
|
|
84
|
-
}, 250); // Debounce 250 milliseconds
|
|
85
|
-
|
|
86
|
-
const diffX = this.movement.x - this.previousMovement.x;
|
|
87
|
-
const diffY = this.movement.y - this.previousMovement.y;
|
|
88
|
-
|
|
89
|
-
this.direction = {
|
|
90
|
-
x: Math.sign(diffX),
|
|
91
|
-
y: Math.sign(diffY),
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
this.velocity = {
|
|
95
|
-
x: clamp(
|
|
96
|
-
diffX / t / 1000,
|
|
97
|
-
-1 * Gesture._VELOCITY_LIMIT,
|
|
98
|
-
Gesture._VELOCITY_LIMIT
|
|
99
|
-
),
|
|
100
|
-
y: clamp(
|
|
101
|
-
diffY / t / 1000,
|
|
102
|
-
-1 * Gesture._VELOCITY_LIMIT,
|
|
103
|
-
Gesture._VELOCITY_LIMIT
|
|
104
|
-
),
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
this.previousMovement = { x: this.movement.x, y: this.movement.y };
|
|
108
|
-
|
|
109
|
-
this._handleCallback();
|
|
110
|
-
}
|
|
111
|
-
}
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import { attachEvents } from '../helpers/eventAttacher';
|
|
2
|
-
import { Vector2 } from '../types';
|
|
3
|
-
import { clamp } from '../helpers/math';
|
|
4
|
-
import { withDefault } from '../helpers/withDefault';
|
|
5
|
-
import { Gesture } from './Gesture';
|
|
6
|
-
|
|
7
|
-
export class ScrollGesture extends Gesture {
|
|
8
|
-
isActiveID?: any;
|
|
9
|
-
movement: Vector2 = withDefault(0, 0);
|
|
10
|
-
previousMovement: Vector2 = withDefault(0, 0);
|
|
11
|
-
direction: Vector2 = withDefault(0, 0);
|
|
12
|
-
velocity: Vector2 = withDefault(0, 0);
|
|
13
|
-
|
|
14
|
-
// @override
|
|
15
|
-
// initialize the events
|
|
16
|
-
_initEvents() {
|
|
17
|
-
if (this.targetElement) {
|
|
18
|
-
this._subscribe = attachEvents(
|
|
19
|
-
[this.targetElement],
|
|
20
|
-
[['scroll', this.scrollElementListener.bind(this)]]
|
|
21
|
-
);
|
|
22
|
-
} else {
|
|
23
|
-
this._subscribe = attachEvents(
|
|
24
|
-
[window],
|
|
25
|
-
[['scroll', this.scrollListener.bind(this)]]
|
|
26
|
-
);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
_handleCallback() {
|
|
31
|
-
if (this.callback) {
|
|
32
|
-
this.callback({
|
|
33
|
-
isScrolling: this.isActive,
|
|
34
|
-
scrollX: this.movement.x,
|
|
35
|
-
scrollY: this.movement.y,
|
|
36
|
-
velocityX: this.velocity.x,
|
|
37
|
-
velocityY: this.velocity.y,
|
|
38
|
-
directionX: this.direction.x,
|
|
39
|
-
directionY: this.direction.y,
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
onScroll({ x, y }: Vector2) {
|
|
45
|
-
const now: number = Date.now();
|
|
46
|
-
const deltaTime = Math.min(now - this.lastTimeStamp, 64);
|
|
47
|
-
this.lastTimeStamp = now;
|
|
48
|
-
const t = deltaTime / 1000; // seconds
|
|
49
|
-
|
|
50
|
-
this.movement = { x, y };
|
|
51
|
-
|
|
52
|
-
// Clear if scrolling
|
|
53
|
-
if (this.isActiveID !== -1) {
|
|
54
|
-
this.isActive = true;
|
|
55
|
-
clearTimeout(this.isActiveID);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
this.isActiveID = setTimeout(() => {
|
|
59
|
-
this.isActive = false;
|
|
60
|
-
this.direction = { x: 0, y: 0 };
|
|
61
|
-
|
|
62
|
-
// Reset Velocity
|
|
63
|
-
this.velocity = { x: 0, y: 0 };
|
|
64
|
-
|
|
65
|
-
this._handleCallback(); // Debounce 250milliseconds
|
|
66
|
-
}, 250);
|
|
67
|
-
|
|
68
|
-
const diffX = this.movement.x - this.previousMovement.x;
|
|
69
|
-
const diffY = this.movement.y - this.previousMovement.y;
|
|
70
|
-
|
|
71
|
-
this.direction = {
|
|
72
|
-
x: Math.sign(diffX),
|
|
73
|
-
y: Math.sign(diffY),
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
this.velocity = {
|
|
77
|
-
x: clamp(
|
|
78
|
-
diffX / t / 1000,
|
|
79
|
-
-1 * Gesture._VELOCITY_LIMIT,
|
|
80
|
-
Gesture._VELOCITY_LIMIT
|
|
81
|
-
),
|
|
82
|
-
y: clamp(
|
|
83
|
-
diffY / t / 1000,
|
|
84
|
-
-1 * Gesture._VELOCITY_LIMIT,
|
|
85
|
-
Gesture._VELOCITY_LIMIT
|
|
86
|
-
),
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
this.previousMovement = {
|
|
90
|
-
x: this.movement.x,
|
|
91
|
-
y: this.movement.y,
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
this._handleCallback();
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
scrollListener() {
|
|
98
|
-
const { pageYOffset: y, pageXOffset: x } = window;
|
|
99
|
-
this.onScroll({ x, y });
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
scrollElementListener() {
|
|
103
|
-
const x = this.targetElement?.scrollLeft || 0;
|
|
104
|
-
const y = this.targetElement?.scrollTop || 0;
|
|
105
|
-
this.onScroll({ x, y });
|
|
106
|
-
}
|
|
107
|
-
}
|
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
import { attachEvents } from '../helpers/eventAttacher';
|
|
2
|
-
import { Vector2 } from '../types';
|
|
3
|
-
import { clamp } from '../helpers/math';
|
|
4
|
-
import { withDefault } from '../helpers/withDefault';
|
|
5
|
-
import { Gesture } from './Gesture';
|
|
6
|
-
|
|
7
|
-
const LINE_HEIGHT = 40;
|
|
8
|
-
const PAGE_HEIGHT = 800;
|
|
9
|
-
|
|
10
|
-
export class WheelGesture extends Gesture {
|
|
11
|
-
isActiveID?: any;
|
|
12
|
-
movement: Vector2 = withDefault(0, 0);
|
|
13
|
-
previousMovement: Vector2 = withDefault(0, 0);
|
|
14
|
-
direction: Vector2 = withDefault(0, 0);
|
|
15
|
-
velocity: Vector2 = withDefault(0, 0);
|
|
16
|
-
delta: Vector2 = withDefault(0, 0);
|
|
17
|
-
|
|
18
|
-
// Holds offsets
|
|
19
|
-
offset: Vector2 = withDefault(0, 0);
|
|
20
|
-
translation: Vector2 = withDefault(0, 0);
|
|
21
|
-
|
|
22
|
-
// @override
|
|
23
|
-
// initialize the events
|
|
24
|
-
_initEvents() {
|
|
25
|
-
if (this.targetElement) {
|
|
26
|
-
this._subscribe = attachEvents(
|
|
27
|
-
[this.targetElement],
|
|
28
|
-
[['wheel', this.onWheel.bind(this)]]
|
|
29
|
-
);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
_handleCallback() {
|
|
34
|
-
if (this.callback) {
|
|
35
|
-
this.callback({
|
|
36
|
-
target: this.targetElement,
|
|
37
|
-
isWheeling: this.isActive,
|
|
38
|
-
deltaX: this.delta.x,
|
|
39
|
-
deltaY: this.delta.y,
|
|
40
|
-
directionX: this.direction.x,
|
|
41
|
-
directionY: this.direction.y,
|
|
42
|
-
movementX: this.movement.x,
|
|
43
|
-
movementY: this.movement.y,
|
|
44
|
-
offsetX: this.offset.x,
|
|
45
|
-
offsetY: this.offset.y,
|
|
46
|
-
velocityX: this.velocity.x,
|
|
47
|
-
velocityY: this.velocity.y,
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
onWheel(event: WheelEvent) {
|
|
53
|
-
let { deltaX, deltaY, deltaMode } = event;
|
|
54
|
-
|
|
55
|
-
const now: number = Date.now();
|
|
56
|
-
const deltaTime = Math.min(now - this.lastTimeStamp, 64);
|
|
57
|
-
this.lastTimeStamp = now;
|
|
58
|
-
const t = deltaTime / 1000; // seconds
|
|
59
|
-
|
|
60
|
-
this.isActive = true;
|
|
61
|
-
|
|
62
|
-
if (this.isActiveID !== -1) {
|
|
63
|
-
this.isActive = true;
|
|
64
|
-
clearTimeout(this.isActiveID);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
this.isActiveID = setTimeout(() => {
|
|
68
|
-
this.isActive = false;
|
|
69
|
-
this.translation = { x: this.offset.x, y: this.offset.y };
|
|
70
|
-
this._handleCallback();
|
|
71
|
-
|
|
72
|
-
this.velocity = { x: 0, y: 0 }; // Reset Velocity
|
|
73
|
-
this.movement = { x: 0, y: 0 };
|
|
74
|
-
}, 200);
|
|
75
|
-
|
|
76
|
-
// normalize wheel values, especially for Firefox
|
|
77
|
-
if (deltaMode === 1) {
|
|
78
|
-
deltaX *= LINE_HEIGHT;
|
|
79
|
-
deltaY *= LINE_HEIGHT;
|
|
80
|
-
} else if (deltaMode === 2) {
|
|
81
|
-
deltaX *= PAGE_HEIGHT;
|
|
82
|
-
deltaY *= PAGE_HEIGHT;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
this.delta = { x: deltaX, y: deltaY };
|
|
86
|
-
this.movement = {
|
|
87
|
-
x: this.movement.x + deltaX,
|
|
88
|
-
y: this.movement.y + deltaY,
|
|
89
|
-
};
|
|
90
|
-
this.offset = {
|
|
91
|
-
x: this.translation.x + this.movement.x,
|
|
92
|
-
y: this.translation.y + this.movement.y,
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
const diffX = this.movement.x - this.previousMovement.x;
|
|
96
|
-
const diffY = this.movement.y - this.previousMovement.y;
|
|
97
|
-
|
|
98
|
-
this.direction = {
|
|
99
|
-
x: Math.sign(diffX),
|
|
100
|
-
y: Math.sign(diffY),
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
this.velocity = {
|
|
104
|
-
x: clamp(
|
|
105
|
-
diffX / t / 1000,
|
|
106
|
-
-1 * Gesture._VELOCITY_LIMIT,
|
|
107
|
-
Gesture._VELOCITY_LIMIT
|
|
108
|
-
),
|
|
109
|
-
y: clamp(
|
|
110
|
-
diffY / t / 1000,
|
|
111
|
-
-1 * Gesture._VELOCITY_LIMIT,
|
|
112
|
-
Gesture._VELOCITY_LIMIT
|
|
113
|
-
),
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
this.previousMovement = {
|
|
117
|
-
x: this.movement.x,
|
|
118
|
-
y: this.movement.y,
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
this._handleCallback();
|
|
122
|
-
}
|
|
123
|
-
}
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
type MouseEventType =
|
|
2
|
-
| 'click'
|
|
3
|
-
| 'dblclick'
|
|
4
|
-
| 'mousedown'
|
|
5
|
-
| 'mousemove'
|
|
6
|
-
| 'mouseup'
|
|
7
|
-
| 'touchstart'
|
|
8
|
-
| 'touchmove'
|
|
9
|
-
| 'touchend'
|
|
10
|
-
| 'mouseenter'
|
|
11
|
-
| 'mouseleave'
|
|
12
|
-
| 'mouseout'
|
|
13
|
-
| 'mouseover'
|
|
14
|
-
| 'scroll'
|
|
15
|
-
| 'wheel'
|
|
16
|
-
| 'contextmenu';
|
|
17
|
-
|
|
18
|
-
type DomTargetTypes = Array<Window | Document | HTMLElement>;
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Attach single document / window event / HTMLElement
|
|
22
|
-
*/
|
|
23
|
-
function attachEvent(
|
|
24
|
-
domTargets: DomTargetTypes,
|
|
25
|
-
event: MouseEventType,
|
|
26
|
-
callback: (e: any) => void,
|
|
27
|
-
capture: any = false
|
|
28
|
-
) {
|
|
29
|
-
domTargets.forEach((target) => {
|
|
30
|
-
target.addEventListener(event, callback, capture);
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
return function () {
|
|
34
|
-
domTargets.forEach((target) => {
|
|
35
|
-
target.removeEventListener(event, callback, capture);
|
|
36
|
-
});
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Attach multiple document / window event / HTMLElement
|
|
42
|
-
*/
|
|
43
|
-
export function attachEvents(
|
|
44
|
-
domTargets: DomTargetTypes,
|
|
45
|
-
events: Array<
|
|
46
|
-
[event: MouseEventType, callback: (e: any) => void, capture?: any]
|
|
47
|
-
>
|
|
48
|
-
) {
|
|
49
|
-
const subscribers = new Map();
|
|
50
|
-
|
|
51
|
-
events.forEach(function ([event, callback, capture = false]) {
|
|
52
|
-
subscribers.set(event, attachEvent(domTargets, event, callback, capture));
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
return function (eventKeys?: Array<string>) {
|
|
56
|
-
for (const [eventKey, subscriber] of subscribers.entries()) {
|
|
57
|
-
if (!eventKeys) {
|
|
58
|
-
subscriber();
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
if (eventKeys.indexOf(eventKey) !== -1) {
|
|
63
|
-
subscriber();
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './math';
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* bin(booleanValue)
|
|
3
|
-
* returns 1 if booleanValue == true and 0 if booleanValue == false
|
|
4
|
-
*/
|
|
5
|
-
export function bin(bool: boolean) {
|
|
6
|
-
return bool ? 1 : 0;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* mix(progress, a, b)
|
|
11
|
-
* linear interpolation between a and b
|
|
12
|
-
*/
|
|
13
|
-
export function mix(perc: number, val1: number, val2: number) {
|
|
14
|
-
return val1 * (1 - perc) + val2 * perc;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* clamp(value, min, max)
|
|
19
|
-
* clamps value for min and max bounds
|
|
20
|
-
*/
|
|
21
|
-
export function clamp(value: number, lowerbound: number, upperbound: number) {
|
|
22
|
-
return Math.min(Math.max(value, lowerbound), upperbound);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function rubber2(distanceFromEdge: number, constant: number) {
|
|
26
|
-
return Math.pow(distanceFromEdge, constant * 5);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function rubber(distanceFromEdge: number, dimension: number, constant: number) {
|
|
30
|
-
if (dimension === 0 || Math.abs(dimension) === Infinity)
|
|
31
|
-
return rubber2(distanceFromEdge, constant);
|
|
32
|
-
return (
|
|
33
|
-
(distanceFromEdge * dimension * constant) /
|
|
34
|
-
(dimension + constant * distanceFromEdge)
|
|
35
|
-
);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* rubberClamp(value, min, max, constant?)
|
|
40
|
-
* constant is optional : default 0.15
|
|
41
|
-
* clamps the value for min and max value and
|
|
42
|
-
* extends beyond min and max values with constant
|
|
43
|
-
* factor to create elastic rubber band effect
|
|
44
|
-
*/
|
|
45
|
-
export function rubberClamp(
|
|
46
|
-
value: number,
|
|
47
|
-
lowerbound: number,
|
|
48
|
-
upperbound: number,
|
|
49
|
-
constant: number = 0.15
|
|
50
|
-
) {
|
|
51
|
-
if (constant === 0) return clamp(value, lowerbound, upperbound);
|
|
52
|
-
|
|
53
|
-
if (value < lowerbound) {
|
|
54
|
-
return (
|
|
55
|
-
-rubber(lowerbound - value, upperbound - lowerbound, constant) +
|
|
56
|
-
lowerbound
|
|
57
|
-
);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
if (value > upperbound) {
|
|
61
|
-
return (
|
|
62
|
-
+rubber(value - upperbound, upperbound - lowerbound, constant) +
|
|
63
|
-
upperbound
|
|
64
|
-
);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
return value;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* snapTo(value, velocity, snapPoints[])
|
|
72
|
-
* Calculates the final snapPoint according to given current value,
|
|
73
|
-
* velocity and snapPoints array
|
|
74
|
-
*/
|
|
75
|
-
export function snapTo(
|
|
76
|
-
value: number,
|
|
77
|
-
velocity: number,
|
|
78
|
-
snapPoints: Array<number>
|
|
79
|
-
): number {
|
|
80
|
-
const finalValue = value + velocity * 0.2;
|
|
81
|
-
const getDiff = (point: number) => Math.abs(point - finalValue);
|
|
82
|
-
const deltas = snapPoints.map(getDiff);
|
|
83
|
-
const minDelta = Math.min(...deltas);
|
|
84
|
-
|
|
85
|
-
return snapPoints.reduce(function (acc, point) {
|
|
86
|
-
if (getDiff(point) === minDelta) {
|
|
87
|
-
return point;
|
|
88
|
-
} else {
|
|
89
|
-
return acc;
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* move(array, moveIndex, toIndex)
|
|
96
|
-
* move array item from moveIndex to toIndex without array modification
|
|
97
|
-
*/
|
|
98
|
-
export function move(array: Array<any>, moveIndex: number, toIndex: number) {
|
|
99
|
-
const item = array[moveIndex];
|
|
100
|
-
const length = array.length;
|
|
101
|
-
const diff = moveIndex - toIndex;
|
|
102
|
-
|
|
103
|
-
if (diff > 0) {
|
|
104
|
-
return [
|
|
105
|
-
...array.slice(0, toIndex),
|
|
106
|
-
item,
|
|
107
|
-
...array.slice(toIndex, moveIndex),
|
|
108
|
-
...array.slice(moveIndex + 1, length),
|
|
109
|
-
];
|
|
110
|
-
} else if (diff < 0) {
|
|
111
|
-
const targetIndex = toIndex + 1;
|
|
112
|
-
return [
|
|
113
|
-
...array.slice(0, moveIndex),
|
|
114
|
-
...array.slice(moveIndex + 1, targetIndex),
|
|
115
|
-
item,
|
|
116
|
-
...array.slice(targetIndex, length),
|
|
117
|
-
];
|
|
118
|
-
}
|
|
119
|
-
return array;
|
|
120
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
|
|
3
|
-
import { DragEventType, UseDragConfig } from '../types';
|
|
4
|
-
import { DragGesture } from '../controllers';
|
|
5
|
-
import { useRecognizer } from './useRecognizer';
|
|
6
|
-
|
|
7
|
-
export function useDrag(
|
|
8
|
-
callback: (event: DragEventType) => void,
|
|
9
|
-
config?: UseDragConfig
|
|
10
|
-
) {
|
|
11
|
-
const gesture = React.useRef(new DragGesture()).current;
|
|
12
|
-
|
|
13
|
-
return useRecognizer([['drag', gesture, callback, config]]);
|
|
14
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
DragGesture,
|
|
4
|
-
MouseMoveGesture,
|
|
5
|
-
ScrollGesture,
|
|
6
|
-
WheelGesture,
|
|
7
|
-
} from '../controllers';
|
|
8
|
-
import {
|
|
9
|
-
DragEventType,
|
|
10
|
-
WheelEventType,
|
|
11
|
-
ScrollEventType,
|
|
12
|
-
MouseMoveEventType,
|
|
13
|
-
} from '../types';
|
|
14
|
-
import { useRecognizer } from './useRecognizer';
|
|
15
|
-
|
|
16
|
-
export function useGesture({
|
|
17
|
-
onDrag,
|
|
18
|
-
onWheel,
|
|
19
|
-
onScroll,
|
|
20
|
-
onMouseMove,
|
|
21
|
-
}: {
|
|
22
|
-
onDrag?: (event: DragEventType) => void;
|
|
23
|
-
onWheel?: (event: WheelEventType) => void;
|
|
24
|
-
onScroll?: (event: ScrollEventType) => void;
|
|
25
|
-
onMouseMove?: (event: MouseMoveEventType) => void;
|
|
26
|
-
}) {
|
|
27
|
-
const dragGesture = React.useRef(new DragGesture()).current;
|
|
28
|
-
const wheelGesture = React.useRef(new WheelGesture()).current;
|
|
29
|
-
const scrollGesture = React.useRef(new ScrollGesture()).current;
|
|
30
|
-
const mouseMoveGesture = React.useRef(new MouseMoveGesture()).current;
|
|
31
|
-
|
|
32
|
-
return useRecognizer([
|
|
33
|
-
['drag', dragGesture, onDrag],
|
|
34
|
-
['wheel', wheelGesture, onWheel],
|
|
35
|
-
['scroll', scrollGesture, onScroll],
|
|
36
|
-
['move', mouseMoveGesture, onMouseMove],
|
|
37
|
-
]);
|
|
38
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
|
|
3
|
-
import { MouseMoveEventType } from '../types';
|
|
4
|
-
import { MouseMoveGesture } from '../controllers';
|
|
5
|
-
import { useRecognizer } from './useRecognizer';
|
|
6
|
-
|
|
7
|
-
export function useMouseMove(callback: (event: MouseMoveEventType) => void) {
|
|
8
|
-
const gesture = React.useRef(new MouseMoveGesture()).current;
|
|
9
|
-
|
|
10
|
-
return useRecognizer([['move', gesture, callback]]);
|
|
11
|
-
}
|