react-ui-animate 2.0.0 → 3.0.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.vscode/settings.json +3 -3
- package/LICENSE +21 -21
- package/README.md +115 -115
- package/dist/animation/animationType.d.ts +15 -15
- package/dist/animation/core/animation/Animation.d.ts +16 -0
- package/dist/animation/core/animation/FluidValue.d.ts +21 -0
- package/dist/animation/core/animation/RequestAnimationFrame.d.ts +8 -0
- package/dist/animation/core/animation/SpringAnimation.d.ts +41 -0
- package/dist/animation/core/animation/TimingAnimation.d.ts +35 -0
- package/dist/animation/core/animation/TransitionValue.d.ts +21 -0
- package/dist/animation/core/controllers/Animation.d.ts +16 -0
- package/dist/animation/core/controllers/FluidValue.d.ts +32 -0
- package/dist/animation/core/controllers/RequestAnimationFrame.d.ts +8 -0
- package/dist/animation/core/controllers/SpringAnimation.d.ts +41 -0
- package/dist/animation/core/controllers/TimingAnimation.d.ts +35 -0
- package/dist/animation/core/easing/Bezier.d.ts +8 -0
- package/dist/animation/core/easing/Easing.d.ts +40 -0
- package/dist/animation/core/helpers/camelCaseToKebabCase.d.ts +8 -0
- package/dist/animation/core/helpers/camelToDash.d.ts +7 -0
- package/dist/animation/core/helpers/canInterpolate.d.ts +11 -0
- package/dist/animation/core/helpers/getAnimatableObject.d.ts +22 -0
- package/dist/animation/core/helpers/getCleanProps.d.ts +10 -0
- package/dist/animation/core/helpers/getCssValue.d.ts +8 -0
- package/dist/animation/core/helpers/getNonAnimatableStyle.d.ts +6 -0
- package/dist/animation/core/helpers/index.d.ts +5 -0
- package/dist/animation/core/helpers/isDefined.d.ts +12 -0
- package/dist/animation/core/helpers/isFluidValue.d.ts +6 -0
- package/dist/animation/core/index.d.ts +11 -0
- package/dist/animation/core/interpolation/Colors.d.ts +25 -0
- package/dist/animation/core/interpolation/Interpolation.d.ts +80 -0
- package/dist/animation/core/interpolation/__tests__/Colors.test.d.ts +1 -0
- package/dist/animation/core/react/Tags.d.ts +3 -0
- package/dist/animation/core/react/TransformStyles.d.ts +8 -0
- package/dist/animation/core/react/animated.d.ts +29 -0
- package/dist/animation/core/react/combineRefs.d.ts +2 -0
- package/dist/animation/core/react/fluid.d.ts +6 -0
- package/dist/animation/core/react/functions/camelToDash.d.ts +7 -0
- package/dist/animation/core/react/functions/getAnimatableObject.d.ts +22 -0
- package/dist/animation/core/react/functions/getCleanProps.d.ts +4 -0
- package/dist/animation/core/react/functions/getCssValue.d.ts +8 -0
- package/dist/animation/core/react/functions/getNonAnimatableStyle.d.ts +6 -0
- package/dist/animation/core/react/functions/index.d.ts +7 -0
- package/dist/animation/core/react/functions/isDefined.d.ts +6 -0
- package/dist/animation/core/react/functions/isTransitionValue.d.ts +6 -0
- package/dist/animation/core/react/helpers/camelToDash.d.ts +7 -0
- package/dist/animation/core/react/helpers/canInterpolate.d.ts +7 -0
- package/dist/animation/core/react/helpers/getAnimatableObject.d.ts +22 -0
- package/dist/animation/core/react/helpers/getCleanProps.d.ts +4 -0
- package/dist/animation/core/react/helpers/getCssValue.d.ts +8 -0
- package/dist/animation/core/react/helpers/getNonAnimatableStyle.d.ts +6 -0
- package/dist/animation/core/react/helpers/index.d.ts +7 -0
- package/dist/animation/core/react/helpers/isDefined.d.ts +6 -0
- package/dist/animation/core/react/helpers/isFluidValue.d.ts +6 -0
- package/dist/animation/core/react/helpers/isTransitionValue.d.ts +6 -0
- package/dist/animation/core/react/makeFluid.d.ts +30 -0
- package/dist/animation/core/react/transforms.d.ts +6 -0
- package/dist/animation/core/react/useFluidValue.d.ts +9 -0
- package/dist/animation/core/react/useMount.d.ts +20 -0
- package/dist/animation/core/react/useMounts.d.ts +26 -0
- package/dist/animation/core/react/useTransition.d.ts +9 -0
- package/dist/animation/core/react/useTransitions.d.ts +11 -0
- package/dist/animation/core/types/animation.d.ts +54 -0
- package/dist/animation/core/types/common.d.ts +4 -0
- package/dist/animation/core/types/fluid.d.ts +19 -0
- package/dist/animation/core/types/index.d.ts +2 -0
- package/dist/animation/getInitialConfig.d.ts +3 -3
- package/dist/animation/index.d.ts +6 -6
- package/dist/animation/interpolation.d.ts +21 -21
- package/dist/animation/lib/animationType.d.ts +15 -0
- package/dist/animation/lib/getInitialConfig.d.ts +3 -0
- package/dist/animation/lib/index.d.ts +5 -0
- package/dist/animation/lib/interpolation.d.ts +20 -0
- package/dist/animation/lib/modules/AnimatedBlock.d.ts +8 -0
- package/dist/animation/lib/modules/AnimatedImage.d.ts +8 -0
- package/dist/animation/lib/modules/AnimatedInline.d.ts +8 -0
- package/dist/animation/lib/modules/MountedBlock.d.ts +29 -0
- package/dist/animation/lib/modules/ScrollableBlock.d.ts +22 -0
- package/dist/animation/lib/modules/TransitionBlock.d.ts +18 -0
- package/dist/animation/lib/modules/index.d.ts +6 -0
- package/dist/animation/lib/useAnimatedValue.d.ts +17 -0
- package/dist/animation/lib/useMountedValue.d.ts +14 -0
- package/dist/animation/modules/AnimatedBlock.d.ts +8 -8
- package/dist/animation/modules/AnimatedImage.d.ts +8 -8
- package/dist/animation/modules/AnimatedInline.d.ts +8 -8
- package/dist/animation/modules/MountedBlock.d.ts +29 -18
- package/dist/animation/modules/ScrollableBlock.d.ts +21 -21
- package/dist/animation/modules/TransitionBlock.d.ts +17 -17
- package/dist/animation/modules/index.d.ts +6 -6
- package/dist/animation/useAnimatedValue.d.ts +22 -22
- package/dist/animation/useMountedValue.d.ts +15 -15
- package/dist/gestures/controllers/DragGesture.d.ts +17 -17
- package/dist/gestures/controllers/Gesture.d.ts +20 -20
- package/dist/gestures/controllers/MouseMoveGesture.d.ts +13 -13
- package/dist/gestures/controllers/ScrollGesture.d.ts +14 -14
- package/dist/gestures/controllers/WheelGesture.d.ts +15 -15
- package/dist/gestures/controllers/index.d.ts +4 -4
- package/dist/gestures/eventAttacher.d.ts +11 -11
- package/dist/gestures/helpers/eventAttacher.d.ts +11 -0
- package/dist/gestures/helpers/index.d.ts +1 -0
- package/dist/gestures/helpers/math.d.ts +34 -0
- package/dist/gestures/helpers/withDefault.d.ts +4 -0
- package/dist/gestures/hooks/index.d.ts +5 -5
- package/dist/gestures/hooks/useDrag.d.ts +4 -4
- package/dist/gestures/hooks/useGesture.d.ts +9 -9
- package/dist/gestures/hooks/useMouseMove.d.ts +4 -4
- package/dist/gestures/hooks/useRecognizer.d.ts +10 -10
- package/dist/gestures/hooks/useScroll.d.ts +4 -4
- package/dist/gestures/hooks/useWheel.d.ts +4 -4
- package/dist/gestures/index.d.ts +2 -2
- package/dist/gestures/math.d.ts +34 -34
- package/dist/gestures/types.d.ts +51 -51
- package/dist/gestures/withDefault.d.ts +4 -4
- package/dist/hooks/index.d.ts +3 -3
- package/dist/hooks/useMeasure.d.ts +14 -14
- package/dist/hooks/useOutsideClick.d.ts +2 -2
- package/dist/hooks/useWindowDimension.d.ts +9 -9
- package/dist/index.d.ts +9 -5
- package/dist/index.js +2758 -1052
- package/dist/index.js.map +1 -1
- package/dist/utils/delay.d.ts +5 -5
- package/dist/utils/index.d.ts +1 -2
- package/dist/utils/isDefined.d.ts +1 -1
- package/ecosystem.config.js +12 -0
- package/example/README.md +46 -0
- package/example/package-lock.json +19597 -0
- package/example/package.json +45 -0
- package/example/public/favicon.ico +0 -0
- package/example/public/index.html +20 -0
- package/example/public/logo192.png +0 -0
- package/example/public/logo512.png +0 -0
- package/example/public/manifest.json +25 -0
- package/example/public/robots.txt +3 -0
- package/example/src/App.tsx +41 -0
- package/example/src/components/Draggable.tsx +46 -0
- package/example/src/components/Gestures.tsx +151 -0
- package/example/src/components/Interpolation.tsx +21 -0
- package/example/src/components/Loop.tsx +48 -0
- package/example/src/components/MountedBlock.tsx +25 -0
- package/example/src/components/MouseMove.tsx +59 -0
- package/example/src/components/MultistageTransition.tsx +34 -0
- package/example/src/components/Scroll.tsx +39 -0
- package/example/src/components/ScrollableBlock.tsx +27 -0
- package/example/src/components/SnapTo.tsx +55 -0
- package/example/src/components/TransitionBlock.tsx +37 -0
- package/example/src/components/Wheel.tsx +39 -0
- package/example/src/components/index.ts +18 -0
- package/example/src/components/svgLine.tsx +48 -0
- package/example/src/components/useAnimatedValue.tsx +57 -0
- package/example/src/components/useMountedValue.tsx +62 -0
- package/example/src/index.css +8 -0
- package/example/src/index.tsx +16 -0
- package/example/tsconfig.json +26 -0
- package/package.json +48 -48
- package/{rollup.config.js → rollup.config.mjs} +18 -18
- package/src/animation/core/controllers/Animation.ts +27 -0
- package/src/animation/core/controllers/FluidValue.ts +97 -0
- package/src/animation/core/controllers/RequestAnimationFrame.ts +13 -0
- package/src/animation/core/controllers/SpringAnimation.ts +218 -0
- package/src/animation/core/controllers/TimingAnimation.ts +152 -0
- package/src/animation/core/easing/Bezier.ts +146 -0
- package/src/animation/core/easing/Easing.ts +132 -0
- package/src/animation/core/helpers/camelCaseToKebabCase.ts +10 -0
- package/src/animation/core/helpers/getCleanProps.ts +16 -0
- package/src/animation/core/helpers/getCssValue.ts +60 -0
- package/src/animation/core/helpers/index.ts +5 -0
- package/src/animation/core/helpers/isDefined.ts +14 -0
- package/src/animation/core/helpers/isFluidValue.ts +11 -0
- package/src/animation/core/index.ts +16 -0
- package/src/animation/core/interpolation/Colors.ts +232 -0
- package/src/animation/core/interpolation/Interpolation.ts +395 -0
- package/src/animation/core/interpolation/__tests__/Colors.test.tsx +35 -0
- package/src/animation/core/react/fluid.ts +197 -0
- package/src/animation/core/react/makeFluid.ts +294 -0
- package/src/animation/core/react/transforms.ts +90 -0
- package/src/animation/core/react/useFluidValue.ts +43 -0
- package/src/animation/core/react/useMount.ts +58 -0
- package/src/animation/core/types/animation.d.ts +56 -0
- package/src/animation/core/types/common.d.ts +4 -0
- package/src/animation/core/types/fluid.d.ts +38 -0
- package/src/animation/{animationType.ts → lib/animationType.ts} +17 -17
- package/src/animation/{getInitialConfig.ts → lib/getInitialConfig.ts} +61 -61
- package/src/animation/lib/index.ts +12 -0
- package/src/animation/{interpolation.ts → lib/interpolation.ts} +47 -48
- package/src/animation/{modules → lib/modules}/AnimatedBlock.ts +8 -8
- package/src/animation/{modules → lib/modules}/AnimatedImage.ts +8 -8
- package/src/animation/{modules → lib/modules}/AnimatedInline.ts +8 -8
- package/src/animation/lib/modules/MountedBlock.tsx +51 -0
- package/src/animation/{modules → lib/modules}/ScrollableBlock.tsx +68 -69
- package/src/animation/{modules → lib/modules}/TransitionBlock.tsx +28 -29
- package/src/animation/{modules → lib/modules}/index.ts +6 -6
- package/src/animation/{useAnimatedValue.ts → lib/useAnimatedValue.ts} +60 -71
- package/src/animation/{useMountedValue.ts → lib/useMountedValue.ts} +18 -19
- package/src/gestures/controllers/DragGesture.ts +178 -177
- package/src/gestures/controllers/Gesture.ts +54 -54
- package/src/gestures/controllers/MouseMoveGesture.ts +111 -111
- package/src/gestures/controllers/ScrollGesture.ts +107 -107
- package/src/gestures/controllers/WheelGesture.ts +123 -123
- package/src/gestures/controllers/index.ts +4 -4
- package/src/gestures/{eventAttacher.ts → helpers/eventAttacher.ts} +67 -67
- package/src/gestures/helpers/index.ts +1 -0
- package/src/gestures/{math.ts → helpers/math.ts} +120 -120
- package/src/gestures/{withDefault.ts → helpers/withDefault.ts} +3 -3
- package/src/gestures/hooks/index.ts +5 -5
- package/src/gestures/hooks/useDrag.ts +14 -14
- package/src/gestures/hooks/useGesture.ts +38 -38
- package/src/gestures/hooks/useMouseMove.ts +11 -11
- package/src/gestures/hooks/useRecognizer.ts +59 -59
- package/src/gestures/hooks/useScroll.ts +11 -11
- package/src/gestures/hooks/useWheel.ts +11 -11
- package/src/gestures/{types.ts → types/index.d.ts} +49 -49
- package/src/hooks/index.ts +3 -3
- package/src/hooks/useMeasure.ts +132 -133
- package/src/hooks/useOutsideClick.ts +36 -36
- package/src/hooks/useWindowDimension.ts +58 -59
- package/src/index.ts +42 -5
- package/src/utils/delay.ts +9 -9
- package/src/utils/index.ts +1 -2
- package/tsconfig.json +24 -25
- package/src/animation/index.ts +0 -10
- package/src/animation/modules/MountedBlock.tsx +0 -25
- package/src/gestures/index.ts +0 -2
- package/src/utils/isDefined.ts +0 -4
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
|
|
3
|
-
import { ScrollEventType } from '../types';
|
|
4
|
-
import { ScrollGesture } from '../controllers';
|
|
5
|
-
import { useRecognizer } from './useRecognizer';
|
|
6
|
-
|
|
7
|
-
export function useScroll(callback: (event: ScrollEventType) => void) {
|
|
8
|
-
const gesture = React.useRef(new ScrollGesture()).current;
|
|
9
|
-
|
|
10
|
-
return useRecognizer([['scroll', gesture, callback]]);
|
|
11
|
-
}
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
import { ScrollEventType } from '../types';
|
|
4
|
+
import { ScrollGesture } from '../controllers';
|
|
5
|
+
import { useRecognizer } from './useRecognizer';
|
|
6
|
+
|
|
7
|
+
export function useScroll(callback: (event: ScrollEventType) => void) {
|
|
8
|
+
const gesture = React.useRef(new ScrollGesture()).current;
|
|
9
|
+
|
|
10
|
+
return useRecognizer([['scroll', gesture, callback]]);
|
|
11
|
+
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
|
|
3
|
-
import { WheelEventType } from '../types';
|
|
4
|
-
import { WheelGesture } from '../controllers';
|
|
5
|
-
import { useRecognizer } from './useRecognizer';
|
|
6
|
-
|
|
7
|
-
export function useWheel(callback: (event: WheelEventType) => void) {
|
|
8
|
-
const gesture = React.useRef(new WheelGesture()).current;
|
|
9
|
-
|
|
10
|
-
return useRecognizer([['wheel', gesture, callback]]);
|
|
11
|
-
}
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
import { WheelEventType } from '../types';
|
|
4
|
+
import { WheelGesture } from '../controllers';
|
|
5
|
+
import { useRecognizer } from './useRecognizer';
|
|
6
|
+
|
|
7
|
+
export function useWheel(callback: (event: WheelEventType) => void) {
|
|
8
|
+
const gesture = React.useRef(new WheelGesture()).current;
|
|
9
|
+
|
|
10
|
+
return useRecognizer([['wheel', gesture, callback]]);
|
|
11
|
+
}
|
|
@@ -1,49 +1,49 @@
|
|
|
1
|
-
type GenericEventType = {
|
|
2
|
-
velocityX: number;
|
|
3
|
-
velocityY: number;
|
|
4
|
-
directionX: number;
|
|
5
|
-
directionY: number;
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
export type DragEventType = {
|
|
9
|
-
args: Array<number | undefined>;
|
|
10
|
-
down: boolean;
|
|
11
|
-
movementX: number;
|
|
12
|
-
movementY: number;
|
|
13
|
-
offsetX: number;
|
|
14
|
-
offsetY: number;
|
|
15
|
-
distanceX: number;
|
|
16
|
-
distanceY: number;
|
|
17
|
-
cancel: () => void;
|
|
18
|
-
} & GenericEventType;
|
|
19
|
-
|
|
20
|
-
export type MouseMoveEventType = {
|
|
21
|
-
args: Array<number | undefined>;
|
|
22
|
-
event: MouseEvent;
|
|
23
|
-
target: EventTarget | undefined | null;
|
|
24
|
-
isMoving: boolean;
|
|
25
|
-
mouseX: number;
|
|
26
|
-
mouseY: number;
|
|
27
|
-
} & GenericEventType;
|
|
28
|
-
|
|
29
|
-
export type ScrollEventType = {
|
|
30
|
-
isScrolling: boolean;
|
|
31
|
-
scrollX: number;
|
|
32
|
-
scrollY: number;
|
|
33
|
-
} & GenericEventType;
|
|
34
|
-
|
|
35
|
-
export type WheelEventType = {
|
|
36
|
-
target: HTMLElement | undefined | null;
|
|
37
|
-
isWheeling: boolean;
|
|
38
|
-
movementX: number;
|
|
39
|
-
movementY: number;
|
|
40
|
-
offsetX: number;
|
|
41
|
-
offsetY: number;
|
|
42
|
-
deltaX: number;
|
|
43
|
-
deltaY: number;
|
|
44
|
-
} & GenericEventType;
|
|
45
|
-
|
|
46
|
-
export type UseDragConfig = {
|
|
47
|
-
initial?: () => { movementX: number; movementY: number };
|
|
48
|
-
};
|
|
49
|
-
export type Vector2 = { x: number; y: number };
|
|
1
|
+
type GenericEventType = {
|
|
2
|
+
velocityX: number;
|
|
3
|
+
velocityY: number;
|
|
4
|
+
directionX: number;
|
|
5
|
+
directionY: number;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export type DragEventType = {
|
|
9
|
+
args: Array<number | undefined>;
|
|
10
|
+
down: boolean;
|
|
11
|
+
movementX: number;
|
|
12
|
+
movementY: number;
|
|
13
|
+
offsetX: number;
|
|
14
|
+
offsetY: number;
|
|
15
|
+
distanceX: number;
|
|
16
|
+
distanceY: number;
|
|
17
|
+
cancel: () => void;
|
|
18
|
+
} & GenericEventType;
|
|
19
|
+
|
|
20
|
+
export type MouseMoveEventType = {
|
|
21
|
+
args: Array<number | undefined>;
|
|
22
|
+
event: MouseEvent;
|
|
23
|
+
target: EventTarget | undefined | null;
|
|
24
|
+
isMoving: boolean;
|
|
25
|
+
mouseX: number;
|
|
26
|
+
mouseY: number;
|
|
27
|
+
} & GenericEventType;
|
|
28
|
+
|
|
29
|
+
export type ScrollEventType = {
|
|
30
|
+
isScrolling: boolean;
|
|
31
|
+
scrollX: number;
|
|
32
|
+
scrollY: number;
|
|
33
|
+
} & GenericEventType;
|
|
34
|
+
|
|
35
|
+
export type WheelEventType = {
|
|
36
|
+
target: HTMLElement | undefined | null;
|
|
37
|
+
isWheeling: boolean;
|
|
38
|
+
movementX: number;
|
|
39
|
+
movementY: number;
|
|
40
|
+
offsetX: number;
|
|
41
|
+
offsetY: number;
|
|
42
|
+
deltaX: number;
|
|
43
|
+
deltaY: number;
|
|
44
|
+
} & GenericEventType;
|
|
45
|
+
|
|
46
|
+
export type UseDragConfig = {
|
|
47
|
+
initial?: () => { movementX: number; movementY: number };
|
|
48
|
+
};
|
|
49
|
+
export type Vector2 = { x: number; y: number };
|
package/src/hooks/index.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from "./useOutsideClick";
|
|
2
|
-
export * from "./useMeasure";
|
|
3
|
-
export * from "./useWindowDimension";
|
|
1
|
+
export * from "./useOutsideClick";
|
|
2
|
+
export * from "./useMeasure";
|
|
3
|
+
export * from "./useWindowDimension";
|
package/src/hooks/useMeasure.ts
CHANGED
|
@@ -1,133 +1,132 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
type MeasurementValue = number | Array<number>;
|
|
4
|
-
|
|
5
|
-
type MeasurementType = {
|
|
6
|
-
left: MeasurementValue;
|
|
7
|
-
top: MeasurementValue;
|
|
8
|
-
width: MeasurementValue;
|
|
9
|
-
height: MeasurementValue;
|
|
10
|
-
vLeft: MeasurementValue;
|
|
11
|
-
vTop: MeasurementValue;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export function useMeasure(
|
|
15
|
-
callback: (event: MeasurementType) => void,
|
|
16
|
-
deps?:
|
|
17
|
-
) {
|
|
18
|
-
const ref =
|
|
19
|
-
const elementRefs =
|
|
20
|
-
const callbackRef =
|
|
21
|
-
|
|
22
|
-
// Reinitiate callback when dependency change
|
|
23
|
-
|
|
24
|
-
callbackRef.current = callback;
|
|
25
|
-
|
|
26
|
-
return () => {
|
|
27
|
-
callbackRef.current = () => false;
|
|
28
|
-
};
|
|
29
|
-
}, deps);
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const _refElement = ref.current || document.documentElement;
|
|
33
|
-
const _refElementsMultiple = elementRefs.current;
|
|
34
|
-
|
|
35
|
-
const resizeObserver = new ResizeObserver(([entry]) => {
|
|
36
|
-
const { left, top, width, height } = entry.target.getBoundingClientRect();
|
|
37
|
-
const { pageXOffset, pageYOffset } = window;
|
|
38
|
-
|
|
39
|
-
if (callbackRef) {
|
|
40
|
-
if (_refElement === document.documentElement) {
|
|
41
|
-
return; // no-op for document
|
|
42
|
-
} else {
|
|
43
|
-
callbackRef.current({
|
|
44
|
-
left: left + pageXOffset,
|
|
45
|
-
top: top + pageYOffset,
|
|
46
|
-
width,
|
|
47
|
-
height,
|
|
48
|
-
vLeft: left,
|
|
49
|
-
vTop: top,
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
const resizeObserverMultiple = new ResizeObserver((entries) => {
|
|
56
|
-
const left: Array<number> = [];
|
|
57
|
-
const top: Array<number> = [];
|
|
58
|
-
const width: Array<number> = [];
|
|
59
|
-
const height: Array<number> = [];
|
|
60
|
-
const vLeft: Array<number> = [];
|
|
61
|
-
const vTop: Array<number> = [];
|
|
62
|
-
|
|
63
|
-
entries.forEach((entry) => {
|
|
64
|
-
const {
|
|
65
|
-
left: _left,
|
|
66
|
-
top: _top,
|
|
67
|
-
width: _width,
|
|
68
|
-
height: _height,
|
|
69
|
-
} = entry.target.getBoundingClientRect();
|
|
70
|
-
const { pageXOffset, pageYOffset } = window;
|
|
71
|
-
const _pageLeft = _left + pageXOffset;
|
|
72
|
-
const _pageTop = _top + pageYOffset;
|
|
73
|
-
|
|
74
|
-
left.push(_pageLeft);
|
|
75
|
-
top.push(_pageTop);
|
|
76
|
-
width.push(_width);
|
|
77
|
-
height.push(_height);
|
|
78
|
-
vLeft.push(_left);
|
|
79
|
-
vTop.push(_top);
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
if (callbackRef) {
|
|
83
|
-
callbackRef.current({
|
|
84
|
-
left,
|
|
85
|
-
top,
|
|
86
|
-
width,
|
|
87
|
-
height,
|
|
88
|
-
vLeft,
|
|
89
|
-
vTop,
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
if (_refElement) {
|
|
95
|
-
if (
|
|
96
|
-
_refElement === document.documentElement &&
|
|
97
|
-
_refElementsMultiple.length > 0
|
|
98
|
-
) {
|
|
99
|
-
_refElementsMultiple.forEach((element: any) => {
|
|
100
|
-
resizeObserverMultiple.observe(element.current);
|
|
101
|
-
});
|
|
102
|
-
} else {
|
|
103
|
-
resizeObserver.observe(_refElement);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
return () => {
|
|
108
|
-
if (_refElement) {
|
|
109
|
-
if (
|
|
110
|
-
_refElement === document.documentElement &&
|
|
111
|
-
_refElementsMultiple.length > 0
|
|
112
|
-
) {
|
|
113
|
-
_refElementsMultiple.forEach((element: any) => {
|
|
114
|
-
resizeObserverMultiple.unobserve(element.current);
|
|
115
|
-
});
|
|
116
|
-
} else {
|
|
117
|
-
resizeObserver.unobserve(_refElement);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
};
|
|
121
|
-
}, []);
|
|
122
|
-
|
|
123
|
-
return (index?: number) => {
|
|
124
|
-
if (index === null || index === undefined) {
|
|
125
|
-
return { ref };
|
|
126
|
-
} else {
|
|
127
|
-
elementRefs.current[index] =
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
}
|
|
1
|
+
import { useRef, useEffect, DependencyList, createRef } from 'react';
|
|
2
|
+
|
|
3
|
+
type MeasurementValue = number | Array<number>;
|
|
4
|
+
|
|
5
|
+
type MeasurementType = {
|
|
6
|
+
left: MeasurementValue;
|
|
7
|
+
top: MeasurementValue;
|
|
8
|
+
width: MeasurementValue;
|
|
9
|
+
height: MeasurementValue;
|
|
10
|
+
vLeft: MeasurementValue;
|
|
11
|
+
vTop: MeasurementValue;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export function useMeasure(
|
|
15
|
+
callback: (event: MeasurementType) => void,
|
|
16
|
+
deps?: DependencyList
|
|
17
|
+
) {
|
|
18
|
+
const ref = useRef(null);
|
|
19
|
+
const elementRefs = useRef([]);
|
|
20
|
+
const callbackRef = useRef<(event: MeasurementType) => void>(callback);
|
|
21
|
+
|
|
22
|
+
// Reinitiate callback when dependency change
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
callbackRef.current = callback;
|
|
25
|
+
|
|
26
|
+
return () => {
|
|
27
|
+
callbackRef.current = () => false;
|
|
28
|
+
};
|
|
29
|
+
}, deps);
|
|
30
|
+
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
const _refElement = ref.current || document.documentElement;
|
|
33
|
+
const _refElementsMultiple = elementRefs.current;
|
|
34
|
+
|
|
35
|
+
const resizeObserver = new ResizeObserver(([entry]) => {
|
|
36
|
+
const { left, top, width, height } = entry.target.getBoundingClientRect();
|
|
37
|
+
const { pageXOffset, pageYOffset } = window;
|
|
38
|
+
|
|
39
|
+
if (callbackRef) {
|
|
40
|
+
if (_refElement === document.documentElement) {
|
|
41
|
+
return; // no-op for document
|
|
42
|
+
} else {
|
|
43
|
+
callbackRef.current({
|
|
44
|
+
left: left + pageXOffset,
|
|
45
|
+
top: top + pageYOffset,
|
|
46
|
+
width,
|
|
47
|
+
height,
|
|
48
|
+
vLeft: left,
|
|
49
|
+
vTop: top,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
const resizeObserverMultiple = new ResizeObserver((entries) => {
|
|
56
|
+
const left: Array<number> = [];
|
|
57
|
+
const top: Array<number> = [];
|
|
58
|
+
const width: Array<number> = [];
|
|
59
|
+
const height: Array<number> = [];
|
|
60
|
+
const vLeft: Array<number> = [];
|
|
61
|
+
const vTop: Array<number> = [];
|
|
62
|
+
|
|
63
|
+
entries.forEach((entry) => {
|
|
64
|
+
const {
|
|
65
|
+
left: _left,
|
|
66
|
+
top: _top,
|
|
67
|
+
width: _width,
|
|
68
|
+
height: _height,
|
|
69
|
+
} = entry.target.getBoundingClientRect();
|
|
70
|
+
const { pageXOffset, pageYOffset } = window;
|
|
71
|
+
const _pageLeft = _left + pageXOffset;
|
|
72
|
+
const _pageTop = _top + pageYOffset;
|
|
73
|
+
|
|
74
|
+
left.push(_pageLeft);
|
|
75
|
+
top.push(_pageTop);
|
|
76
|
+
width.push(_width);
|
|
77
|
+
height.push(_height);
|
|
78
|
+
vLeft.push(_left);
|
|
79
|
+
vTop.push(_top);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
if (callbackRef) {
|
|
83
|
+
callbackRef.current({
|
|
84
|
+
left,
|
|
85
|
+
top,
|
|
86
|
+
width,
|
|
87
|
+
height,
|
|
88
|
+
vLeft,
|
|
89
|
+
vTop,
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
if (_refElement) {
|
|
95
|
+
if (
|
|
96
|
+
_refElement === document.documentElement &&
|
|
97
|
+
_refElementsMultiple.length > 0
|
|
98
|
+
) {
|
|
99
|
+
_refElementsMultiple.forEach((element: any) => {
|
|
100
|
+
resizeObserverMultiple.observe(element.current);
|
|
101
|
+
});
|
|
102
|
+
} else {
|
|
103
|
+
resizeObserver.observe(_refElement);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return () => {
|
|
108
|
+
if (_refElement) {
|
|
109
|
+
if (
|
|
110
|
+
_refElement === document.documentElement &&
|
|
111
|
+
_refElementsMultiple.length > 0
|
|
112
|
+
) {
|
|
113
|
+
_refElementsMultiple.forEach((element: any) => {
|
|
114
|
+
resizeObserverMultiple.unobserve(element.current);
|
|
115
|
+
});
|
|
116
|
+
} else {
|
|
117
|
+
resizeObserver.unobserve(_refElement);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
}, []);
|
|
122
|
+
|
|
123
|
+
return (index?: number) => {
|
|
124
|
+
if (index === null || index === undefined) {
|
|
125
|
+
return { ref };
|
|
126
|
+
} else {
|
|
127
|
+
elementRefs.current[index] = elementRefs.current[index] || createRef();
|
|
128
|
+
|
|
129
|
+
return { ref: elementRefs.current[index] };
|
|
130
|
+
}
|
|
131
|
+
}; // ...bind() or ...bind(index) for multiple
|
|
132
|
+
}
|
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
import { attachEvents } from
|
|
4
|
-
|
|
5
|
-
export function useOutsideClick(
|
|
6
|
-
elementRef:
|
|
7
|
-
callback: (event: MouseEvent) => void,
|
|
8
|
-
deps?:
|
|
9
|
-
) {
|
|
10
|
-
const callbackRef =
|
|
11
|
-
|
|
12
|
-
if (!callbackRef.current) {
|
|
13
|
-
callbackRef.current = callback;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
// Reinitiate callback when dependency change
|
|
17
|
-
|
|
18
|
-
callbackRef.current = callback;
|
|
19
|
-
|
|
20
|
-
return () => {
|
|
21
|
-
callbackRef.current = () => false;
|
|
22
|
-
};
|
|
23
|
-
}, deps);
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const handleOutsideClick = (e: MouseEvent) => {
|
|
27
|
-
if (!elementRef?.current?.contains(e.target as Element)) {
|
|
28
|
-
callbackRef.current && callbackRef.current(e);
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
const subscribe = attachEvents([document], [[
|
|
33
|
-
|
|
34
|
-
return () => subscribe && subscribe();
|
|
35
|
-
}, []);
|
|
36
|
-
}
|
|
1
|
+
import { useRef, useEffect, RefObject, DependencyList } from 'react';
|
|
2
|
+
|
|
3
|
+
import { attachEvents } from '../gestures/helpers/eventAttacher';
|
|
4
|
+
|
|
5
|
+
export function useOutsideClick(
|
|
6
|
+
elementRef: RefObject<HTMLElement>,
|
|
7
|
+
callback: (event: MouseEvent) => void,
|
|
8
|
+
deps?: DependencyList
|
|
9
|
+
) {
|
|
10
|
+
const callbackRef = useRef<(event: MouseEvent) => void>();
|
|
11
|
+
|
|
12
|
+
if (!callbackRef.current) {
|
|
13
|
+
callbackRef.current = callback;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// Reinitiate callback when dependency change
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
callbackRef.current = callback;
|
|
19
|
+
|
|
20
|
+
return () => {
|
|
21
|
+
callbackRef.current = () => false;
|
|
22
|
+
};
|
|
23
|
+
}, deps);
|
|
24
|
+
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
const handleOutsideClick = (e: MouseEvent) => {
|
|
27
|
+
if (!elementRef?.current?.contains(e.target as Element)) {
|
|
28
|
+
callbackRef.current && callbackRef.current(e);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const subscribe = attachEvents([document], [['click', handleOutsideClick]]);
|
|
33
|
+
|
|
34
|
+
return () => subscribe && subscribe();
|
|
35
|
+
}, []);
|
|
36
|
+
}
|
|
@@ -1,59 +1,58 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
type WindowDimensionType = {
|
|
4
|
-
width: number;
|
|
5
|
-
height: number;
|
|
6
|
-
innerWidth: number;
|
|
7
|
-
innerHeight: number;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
export function useWindowDimension(
|
|
11
|
-
callback: (event: WindowDimensionType) => void,
|
|
12
|
-
deps?:
|
|
13
|
-
) {
|
|
14
|
-
const windowDimensionsRef =
|
|
15
|
-
width: 0,
|
|
16
|
-
height: 0,
|
|
17
|
-
innerWidth: 0,
|
|
18
|
-
innerHeight: 0,
|
|
19
|
-
});
|
|
20
|
-
const callbackRef =
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
1
|
+
import { useRef, useEffect, DependencyList } from 'react';
|
|
2
|
+
|
|
3
|
+
type WindowDimensionType = {
|
|
4
|
+
width: number;
|
|
5
|
+
height: number;
|
|
6
|
+
innerWidth: number;
|
|
7
|
+
innerHeight: number;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export function useWindowDimension(
|
|
11
|
+
callback: (event: WindowDimensionType) => void,
|
|
12
|
+
deps?: DependencyList
|
|
13
|
+
) {
|
|
14
|
+
const windowDimensionsRef = useRef<WindowDimensionType>({
|
|
15
|
+
width: 0,
|
|
16
|
+
height: 0,
|
|
17
|
+
innerWidth: 0,
|
|
18
|
+
innerHeight: 0,
|
|
19
|
+
});
|
|
20
|
+
const callbackRef = useRef<(event: WindowDimensionType) => void>(callback);
|
|
21
|
+
|
|
22
|
+
const handleCallback: () => void = () => {
|
|
23
|
+
if (callbackRef) {
|
|
24
|
+
callbackRef.current({
|
|
25
|
+
...windowDimensionsRef.current,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
// Reinitiate callback when dependency change
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
callbackRef.current = callback;
|
|
33
|
+
|
|
34
|
+
return () => {
|
|
35
|
+
callbackRef.current = () => false;
|
|
36
|
+
};
|
|
37
|
+
}, deps);
|
|
38
|
+
|
|
39
|
+
useEffect(() => {
|
|
40
|
+
const resizeObserver = new ResizeObserver(([entry]) => {
|
|
41
|
+
const { clientWidth, clientHeight } = entry.target;
|
|
42
|
+
const { innerWidth, innerHeight } = window;
|
|
43
|
+
|
|
44
|
+
windowDimensionsRef.current = {
|
|
45
|
+
width: clientWidth,
|
|
46
|
+
height: clientHeight,
|
|
47
|
+
innerWidth,
|
|
48
|
+
innerHeight,
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
handleCallback();
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
resizeObserver.observe(document.documentElement);
|
|
55
|
+
|
|
56
|
+
return () => resizeObserver.unobserve(document.documentElement);
|
|
57
|
+
}, []);
|
|
58
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,42 @@
|
|
|
1
|
-
|
|
2
|
-
export {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
// Core
|
|
2
|
+
export { Easing, makeFluid, fluid } from './animation/core';
|
|
3
|
+
|
|
4
|
+
// react-ui-animate
|
|
5
|
+
// Modules
|
|
6
|
+
export {
|
|
7
|
+
AnimatedBlock,
|
|
8
|
+
AnimatedImage,
|
|
9
|
+
AnimatedInline,
|
|
10
|
+
AnimationConfigUtils,
|
|
11
|
+
MountedBlock,
|
|
12
|
+
ScrollableBlock,
|
|
13
|
+
TransitionBlock,
|
|
14
|
+
} from './animation/lib';
|
|
15
|
+
|
|
16
|
+
// Interpolation
|
|
17
|
+
export { bInterpolate, interpolate } from './animation/lib';
|
|
18
|
+
|
|
19
|
+
// Hooks
|
|
20
|
+
|
|
21
|
+
export { useAnimatedValue, useMountedValue } from './animation/lib';
|
|
22
|
+
|
|
23
|
+
// Helpers and Utilities
|
|
24
|
+
export { delay } from './utils';
|
|
25
|
+
|
|
26
|
+
// Hooks
|
|
27
|
+
export { useMeasure, useOutsideClick, useWindowDimension } from './hooks';
|
|
28
|
+
|
|
29
|
+
// gestures/hooks
|
|
30
|
+
export {
|
|
31
|
+
useDrag,
|
|
32
|
+
useGesture,
|
|
33
|
+
useMouseMove,
|
|
34
|
+
useScroll,
|
|
35
|
+
useWheel,
|
|
36
|
+
} from './gestures/hooks';
|
|
37
|
+
|
|
38
|
+
// gestures/helpers
|
|
39
|
+
export { bin, clamp, mix, rubberClamp, move, snapTo } from './gestures/helpers';
|
|
40
|
+
|
|
41
|
+
// Types
|
|
42
|
+
export type { UseAnimatedValueConfig } from './animation/lib';
|