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
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { useWheel } from 'react-ui-animate';
|
|
2
|
+
|
|
3
|
+
export const Wheel = () => {
|
|
4
|
+
const bind = useWheel(function (event) {
|
|
5
|
+
console.log('WHEEL', event);
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
return (
|
|
9
|
+
<>
|
|
10
|
+
<div
|
|
11
|
+
{...bind()}
|
|
12
|
+
style={{
|
|
13
|
+
width: 500,
|
|
14
|
+
height: 500,
|
|
15
|
+
overflowY: 'auto',
|
|
16
|
+
backgroundColor: '#3399ff',
|
|
17
|
+
}}
|
|
18
|
+
>
|
|
19
|
+
<div style={{ height: 2000 }} />
|
|
20
|
+
</div>
|
|
21
|
+
|
|
22
|
+
<div style={{ height: 2000 }} />
|
|
23
|
+
|
|
24
|
+
{Array(5)
|
|
25
|
+
.fill(null)
|
|
26
|
+
.map((_, i) => (
|
|
27
|
+
<div
|
|
28
|
+
key={i}
|
|
29
|
+
style={{
|
|
30
|
+
width: 100,
|
|
31
|
+
height: 100,
|
|
32
|
+
backgroundColor: '#3399ff',
|
|
33
|
+
marginBottom: 10,
|
|
34
|
+
}}
|
|
35
|
+
/>
|
|
36
|
+
))}
|
|
37
|
+
</>
|
|
38
|
+
);
|
|
39
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export * from './Draggable';
|
|
2
|
+
export * from './Gestures';
|
|
3
|
+
export * from './MountedBlock';
|
|
4
|
+
export * from './ScrollableBlock';
|
|
5
|
+
export * from './svgLine';
|
|
6
|
+
export * from './useAnimatedValue';
|
|
7
|
+
export * from './useMountedValue';
|
|
8
|
+
export * from './MouseMove';
|
|
9
|
+
export * from './Scroll';
|
|
10
|
+
export * from './Wheel';
|
|
11
|
+
export * from './Gestures';
|
|
12
|
+
export * from './Interpolation';
|
|
13
|
+
export * from './MultistageTransition';
|
|
14
|
+
export * from './Loop';
|
|
15
|
+
export * from './SnapTo';
|
|
16
|
+
export * from './TransitionBlock';
|
|
17
|
+
export * from './useAnimatedValue';
|
|
18
|
+
export * from './useMountedValue';
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import {
|
|
2
|
+
useAnimatedValue,
|
|
3
|
+
useDrag,
|
|
4
|
+
AnimationConfigUtils,
|
|
5
|
+
fluid,
|
|
6
|
+
} from 'react-ui-animate';
|
|
7
|
+
|
|
8
|
+
export function SVGLine() {
|
|
9
|
+
const dragX = useAnimatedValue(0, { immediate: true });
|
|
10
|
+
const followX = useAnimatedValue(0, { ...AnimationConfigUtils.ELASTIC });
|
|
11
|
+
|
|
12
|
+
const circleBind = useDrag(({ movementX }) => {
|
|
13
|
+
dragX.value = movementX;
|
|
14
|
+
followX.value = movementX;
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
return (
|
|
18
|
+
<div className='App'>
|
|
19
|
+
<svg
|
|
20
|
+
style={{
|
|
21
|
+
border: '1px solid #3399ff',
|
|
22
|
+
}}
|
|
23
|
+
width={200}
|
|
24
|
+
height={200}
|
|
25
|
+
xmlns='http://www.w3.org/2000/svg'
|
|
26
|
+
>
|
|
27
|
+
<fluid.line
|
|
28
|
+
x1={followX.value}
|
|
29
|
+
y1='10'
|
|
30
|
+
x2={dragX.value}
|
|
31
|
+
y2='50'
|
|
32
|
+
stroke='black'
|
|
33
|
+
/>
|
|
34
|
+
<fluid.circle cx={followX.value} cy='10' r='2' fill='red' />
|
|
35
|
+
<fluid.circle
|
|
36
|
+
{...circleBind()}
|
|
37
|
+
style={{
|
|
38
|
+
cursor: 'pointer',
|
|
39
|
+
}}
|
|
40
|
+
cx={dragX.value}
|
|
41
|
+
cy='50'
|
|
42
|
+
r='5'
|
|
43
|
+
fill='red'
|
|
44
|
+
/>
|
|
45
|
+
</svg>
|
|
46
|
+
</div>
|
|
47
|
+
);
|
|
48
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { useAnimatedValue, AnimatedBlock } from 'react-ui-animate';
|
|
3
|
+
|
|
4
|
+
export const UseAnimatedValue: React.FC = () => {
|
|
5
|
+
// const width = useAnimatedValue(100);
|
|
6
|
+
const bg = useAnimatedValue('position');
|
|
7
|
+
|
|
8
|
+
return (
|
|
9
|
+
<>
|
|
10
|
+
<AnimatedBlock
|
|
11
|
+
a={bg.value}
|
|
12
|
+
style={{
|
|
13
|
+
width: 100,
|
|
14
|
+
height: 100,
|
|
15
|
+
backgroundColor: 'red',
|
|
16
|
+
position: bg.value,
|
|
17
|
+
left: 0,
|
|
18
|
+
top: 0,
|
|
19
|
+
}}
|
|
20
|
+
/>
|
|
21
|
+
<button onClick={() => (bg.value = 'absolute')}>Animate</button>
|
|
22
|
+
{/* <button onClick={() => (bg.value = '#00ff00')}>Green</button> */}
|
|
23
|
+
|
|
24
|
+
{/* <div style={{ perspective: 200 }}>
|
|
25
|
+
<AnimatedBlock
|
|
26
|
+
style={{
|
|
27
|
+
perspective: 400,
|
|
28
|
+
width: width.value,
|
|
29
|
+
height: 100,
|
|
30
|
+
backgroundColor: interpolate(
|
|
31
|
+
width.value,
|
|
32
|
+
[100, 500],
|
|
33
|
+
['#3399ff', 'red']
|
|
34
|
+
),
|
|
35
|
+
translateX: interpolate(width.value, [100, 500], [0, 200]),
|
|
36
|
+
rotateX: interpolate(width.value, [100, 500], [0, 45]),
|
|
37
|
+
}}
|
|
38
|
+
/>
|
|
39
|
+
</div>
|
|
40
|
+
|
|
41
|
+
<button
|
|
42
|
+
onClick={() => {
|
|
43
|
+
width.value = 100;
|
|
44
|
+
}}
|
|
45
|
+
>
|
|
46
|
+
LEFT
|
|
47
|
+
</button>
|
|
48
|
+
<button
|
|
49
|
+
onClick={() => {
|
|
50
|
+
width.value = 500;
|
|
51
|
+
}}
|
|
52
|
+
>
|
|
53
|
+
RIGHT
|
|
54
|
+
</button> */}
|
|
55
|
+
</>
|
|
56
|
+
);
|
|
57
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {
|
|
3
|
+
useMountedValue,
|
|
4
|
+
AnimatedBlock,
|
|
5
|
+
bInterpolate,
|
|
6
|
+
useAnimatedValue,
|
|
7
|
+
} from 'react-ui-animate';
|
|
8
|
+
|
|
9
|
+
export const UseMountedValue: React.FC = () => {
|
|
10
|
+
const x = useAnimatedValue(0);
|
|
11
|
+
const [open, setOpen] = React.useState(true);
|
|
12
|
+
const mountedValue = useMountedValue(open, {
|
|
13
|
+
from: 0,
|
|
14
|
+
enter: 1,
|
|
15
|
+
exit: 0,
|
|
16
|
+
config: {
|
|
17
|
+
duration: 200,
|
|
18
|
+
},
|
|
19
|
+
enterConfig: { duration: 2000 },
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
return (
|
|
23
|
+
<>
|
|
24
|
+
<AnimatedBlock
|
|
25
|
+
radius={x.value}
|
|
26
|
+
style={{
|
|
27
|
+
width: 100,
|
|
28
|
+
height: 100,
|
|
29
|
+
backgroundColor: '#3399ff',
|
|
30
|
+
translateX: 100,
|
|
31
|
+
rotate: x.value,
|
|
32
|
+
}}
|
|
33
|
+
onClick={() => (x.value = 45)}
|
|
34
|
+
/>
|
|
35
|
+
{mountedValue(
|
|
36
|
+
(animation, mounted) =>
|
|
37
|
+
mounted && (
|
|
38
|
+
<AnimatedBlock
|
|
39
|
+
style={{
|
|
40
|
+
width: bInterpolate(animation.value, 100, 500),
|
|
41
|
+
height: 100,
|
|
42
|
+
backgroundColor: bInterpolate(
|
|
43
|
+
animation.value,
|
|
44
|
+
'red',
|
|
45
|
+
'#3399ff'
|
|
46
|
+
),
|
|
47
|
+
translateX: 45,
|
|
48
|
+
}}
|
|
49
|
+
/>
|
|
50
|
+
)
|
|
51
|
+
)}
|
|
52
|
+
|
|
53
|
+
<button
|
|
54
|
+
onClick={() => {
|
|
55
|
+
setOpen((prev) => !prev);
|
|
56
|
+
}}
|
|
57
|
+
>
|
|
58
|
+
ANIMATE ME
|
|
59
|
+
</button>
|
|
60
|
+
</>
|
|
61
|
+
);
|
|
62
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import ReactDOM from 'react-dom/client';
|
|
3
|
+
|
|
4
|
+
import './index.css';
|
|
5
|
+
|
|
6
|
+
import App from './App';
|
|
7
|
+
|
|
8
|
+
const root = ReactDOM.createRoot(
|
|
9
|
+
document.getElementById('root') as HTMLElement
|
|
10
|
+
);
|
|
11
|
+
|
|
12
|
+
root.render(
|
|
13
|
+
<React.StrictMode>
|
|
14
|
+
<App />
|
|
15
|
+
</React.StrictMode>
|
|
16
|
+
);
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"strict": true,
|
|
4
|
+
"esModuleInterop": true,
|
|
5
|
+
"lib": [
|
|
6
|
+
"dom",
|
|
7
|
+
"es2015"
|
|
8
|
+
],
|
|
9
|
+
"downlevelIteration": true,
|
|
10
|
+
"jsx": "react-jsx",
|
|
11
|
+
"target": "es5",
|
|
12
|
+
"allowJs": true,
|
|
13
|
+
"skipLibCheck": true,
|
|
14
|
+
"forceConsistentCasingInFileNames": true,
|
|
15
|
+
"noEmit": true,
|
|
16
|
+
"module": "esnext",
|
|
17
|
+
"moduleResolution": "node",
|
|
18
|
+
"resolveJsonModule": true,
|
|
19
|
+
"isolatedModules": true,
|
|
20
|
+
"allowSyntheticDefaultImports": true,
|
|
21
|
+
"noFallthroughCasesInSwitch": true
|
|
22
|
+
},
|
|
23
|
+
"include": [
|
|
24
|
+
"src"
|
|
25
|
+
]
|
|
26
|
+
}
|
package/package.json
CHANGED
|
@@ -1,48 +1,48 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "react-ui-animate",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "React library for gestures and animation",
|
|
5
|
-
"main": "dist/index.js",
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
},
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
"@types/
|
|
14
|
-
"@types/
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
"build": "rollup -c",
|
|
27
|
-
"start": "rollup -c -w",
|
|
28
|
-
"test": "echo \"Error: no test specified\" && exit 1",
|
|
29
|
-
"version:minor": "npm version --no-git-tag-version minor",
|
|
30
|
-
"version:major": "npm version --no-git-tag-version major",
|
|
31
|
-
"version:patch": "npm version --no-git-tag-version patch"
|
|
32
|
-
},
|
|
33
|
-
"repository": {
|
|
34
|
-
"type": "git",
|
|
35
|
-
"url": "git+https://github.com/dipeshrai123/react-ui-animate.git"
|
|
36
|
-
},
|
|
37
|
-
"keywords": [
|
|
38
|
-
"gesture",
|
|
39
|
-
"animation",
|
|
40
|
-
"react-ui-animate"
|
|
41
|
-
],
|
|
42
|
-
"author": "Dipesh Rai",
|
|
43
|
-
"license": "MIT",
|
|
44
|
-
"bugs": {
|
|
45
|
-
"url": "https://github.com/dipeshrai123/react-ui-animate/issues"
|
|
46
|
-
},
|
|
47
|
-
"homepage": "https://github.com/dipeshrai123/react-ui-animate#readme"
|
|
48
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "react-ui-animate",
|
|
3
|
+
"version": "3.0.0-rc.0",
|
|
4
|
+
"description": "React library for gestures and animation",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"peerDependencies": {
|
|
7
|
+
"react": ">=16.8.0 || >=17.0.0 || >=18.0.0"
|
|
8
|
+
},
|
|
9
|
+
"devDependencies": {
|
|
10
|
+
"@types/jest": "^29.5.12",
|
|
11
|
+
"@types/node": "^20.14.9",
|
|
12
|
+
"@types/react": "^18.3.3",
|
|
13
|
+
"@types/react-dom": "^18.3.0",
|
|
14
|
+
"@types/resize-observer-browser": "^0.1.11",
|
|
15
|
+
"babel-core": "^5.8.38",
|
|
16
|
+
"babel-runtime": "^6.26.0",
|
|
17
|
+
"react": "^18.3.1",
|
|
18
|
+
"react-dom": "^18.3.1",
|
|
19
|
+
"rollup": "^4.18.0",
|
|
20
|
+
"rollup-plugin-typescript2": "^0.36.0",
|
|
21
|
+
"typescript": "^5.5.2"
|
|
22
|
+
},
|
|
23
|
+
"scripts": {
|
|
24
|
+
"dev:start": "pm2 start ecosystem.config.js",
|
|
25
|
+
"dev:end": "pm2 stop ecosystem.config.js",
|
|
26
|
+
"build": "rollup -c",
|
|
27
|
+
"start": "rollup -c -w",
|
|
28
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
29
|
+
"version:minor": "npm version --no-git-tag-version minor",
|
|
30
|
+
"version:major": "npm version --no-git-tag-version major",
|
|
31
|
+
"version:patch": "npm version --no-git-tag-version patch"
|
|
32
|
+
},
|
|
33
|
+
"repository": {
|
|
34
|
+
"type": "git",
|
|
35
|
+
"url": "git+https://github.com/dipeshrai123/react-ui-animate.git"
|
|
36
|
+
},
|
|
37
|
+
"keywords": [
|
|
38
|
+
"gesture",
|
|
39
|
+
"animation",
|
|
40
|
+
"react-ui-animate"
|
|
41
|
+
],
|
|
42
|
+
"author": "Dipesh Rai",
|
|
43
|
+
"license": "MIT",
|
|
44
|
+
"bugs": {
|
|
45
|
+
"url": "https://github.com/dipeshrai123/react-ui-animate/issues"
|
|
46
|
+
},
|
|
47
|
+
"homepage": "https://github.com/dipeshrai123/react-ui-animate#readme"
|
|
48
|
+
}
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import typescript from "rollup-plugin-typescript2";
|
|
2
|
-
|
|
3
|
-
import pkg from "./package.json";
|
|
4
|
-
|
|
5
|
-
export default {
|
|
6
|
-
input: "src/index.ts",
|
|
7
|
-
output: [
|
|
8
|
-
{
|
|
9
|
-
file: pkg.main,
|
|
10
|
-
format: "cjs",
|
|
11
|
-
exports: "named",
|
|
12
|
-
sourcemap: true,
|
|
13
|
-
strict: false,
|
|
14
|
-
},
|
|
15
|
-
],
|
|
16
|
-
plugins: [typescript(
|
|
17
|
-
external: ["react", "react-dom"],
|
|
18
|
-
};
|
|
1
|
+
import typescript from "rollup-plugin-typescript2";
|
|
2
|
+
|
|
3
|
+
import pkg from "./package.json" assert { type: "json" };
|
|
4
|
+
|
|
5
|
+
export default {
|
|
6
|
+
input: "src/index.ts",
|
|
7
|
+
output: [
|
|
8
|
+
{
|
|
9
|
+
file: pkg.main,
|
|
10
|
+
format: "cjs",
|
|
11
|
+
exports: "named",
|
|
12
|
+
sourcemap: true,
|
|
13
|
+
strict: false,
|
|
14
|
+
},
|
|
15
|
+
],
|
|
16
|
+
plugins: [typescript()],
|
|
17
|
+
external: ["react", "react-dom"],
|
|
18
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { ResultType } from '../types/animation';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Base Animation class
|
|
5
|
+
*/
|
|
6
|
+
export class Animation {
|
|
7
|
+
_active: boolean;
|
|
8
|
+
_onEnd: any;
|
|
9
|
+
/**
|
|
10
|
+
* it is necessary to add _onRest function as well
|
|
11
|
+
* because _onEnd is always re-assigned with onUpdate callback
|
|
12
|
+
* so that _onRest function is not fired, so we have to duplicate it
|
|
13
|
+
*/
|
|
14
|
+
_onRest?: any;
|
|
15
|
+
|
|
16
|
+
_debounceOnEnd(result: ResultType) {
|
|
17
|
+
const onEnd = this._onEnd;
|
|
18
|
+
const onRest = this._onRest;
|
|
19
|
+
this._onEnd = null;
|
|
20
|
+
this._onRest = null;
|
|
21
|
+
|
|
22
|
+
onRest && onRest(result);
|
|
23
|
+
onEnd && onEnd(result);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
stop() {}
|
|
27
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
Length,
|
|
3
|
+
ResultType,
|
|
4
|
+
SubscribeFn,
|
|
5
|
+
FluidValueConfig,
|
|
6
|
+
OnUpdateFn,
|
|
7
|
+
AssignValue,
|
|
8
|
+
} from '../types/animation';
|
|
9
|
+
import type { Fn } from '../types/common';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Represents a fluid value that can animate between states.
|
|
13
|
+
*/
|
|
14
|
+
export class FluidValue {
|
|
15
|
+
public _subscribe: SubscribeFn;
|
|
16
|
+
public _value: Length;
|
|
17
|
+
public _config?: FluidValueConfig;
|
|
18
|
+
public _currentValue: { current: Length };
|
|
19
|
+
public _subscriptions: Map<{ uuid: number; property: string }, OnUpdateFn>;
|
|
20
|
+
|
|
21
|
+
public get: () => Length;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Creates a new FluidValue instance.
|
|
25
|
+
* @param initialValue - The initial value of the fluid value.
|
|
26
|
+
* @param config - Optional configuration for the fluid value.
|
|
27
|
+
*/
|
|
28
|
+
constructor(initialValue: Length, config?: FluidValueConfig) {
|
|
29
|
+
this._subscriptions = new Map();
|
|
30
|
+
this._subscribe = (
|
|
31
|
+
onUpdate: OnUpdateFn,
|
|
32
|
+
property: string,
|
|
33
|
+
uuid: number
|
|
34
|
+
) => {
|
|
35
|
+
for (const key of this._subscriptions.keys()) {
|
|
36
|
+
if (key.property === property) {
|
|
37
|
+
this._subscriptions.set(key, onUpdate);
|
|
38
|
+
return () => this._subscriptions.delete(key);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
this._subscriptions.set({ uuid, property }, onUpdate);
|
|
43
|
+
return () => this._subscriptions.delete({ uuid, property });
|
|
44
|
+
};
|
|
45
|
+
this._value = initialValue;
|
|
46
|
+
this._currentValue = { current: initialValue };
|
|
47
|
+
this._config = config;
|
|
48
|
+
this.get = () => this._currentValue.current;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Animates from the current value to the updated value.
|
|
53
|
+
* Determines whether to perform a multi-stage or single-stage transition.
|
|
54
|
+
* @param updatedValue - The value to animate to, or a function that defines a multi-stage transition.
|
|
55
|
+
* @param config - Optional configuration for the animation.
|
|
56
|
+
* @param callback - Optional callback to be called after the animation ends.
|
|
57
|
+
*/
|
|
58
|
+
setValue(
|
|
59
|
+
updatedValue: AssignValue,
|
|
60
|
+
config?: FluidValueConfig,
|
|
61
|
+
callback?: Fn<ResultType, void>
|
|
62
|
+
) {
|
|
63
|
+
/** Multistage transition */
|
|
64
|
+
if (typeof updatedValue === 'function') {
|
|
65
|
+
updatedValue((nextValue, nextConfig) => {
|
|
66
|
+
const multiStagePromise = new Promise((resolve) => {
|
|
67
|
+
for (const subscriptionKey of this._subscriptions.keys()) {
|
|
68
|
+
const updater = this._subscriptions.get(subscriptionKey);
|
|
69
|
+
|
|
70
|
+
if (updater) {
|
|
71
|
+
updater(nextValue, nextConfig ?? config, function (result) {
|
|
72
|
+
if (result.finished) {
|
|
73
|
+
resolve(nextValue);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (callback) {
|
|
77
|
+
callback(result);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
return multiStagePromise;
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** Singlestage transition */
|
|
91
|
+
for (const subscriptionKey of this._subscriptions.keys()) {
|
|
92
|
+
const updater = this._subscriptions.get(subscriptionKey);
|
|
93
|
+
|
|
94
|
+
updater && updater(updatedValue, config, callback);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export const RequestAnimationFrame = {
|
|
2
|
+
current: (cb: any) => window.requestAnimationFrame(cb),
|
|
3
|
+
inject(injected: any) {
|
|
4
|
+
RequestAnimationFrame.current = injected;
|
|
5
|
+
},
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export const CancelAnimationFrame = {
|
|
9
|
+
current: (id: any) => window.cancelAnimationFrame(id),
|
|
10
|
+
inject(injected: any) {
|
|
11
|
+
CancelAnimationFrame.current = injected;
|
|
12
|
+
},
|
|
13
|
+
};
|