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.
Files changed (161) hide show
  1. package/dist/animation/core/helpers/isDefined.d.ts +1 -1
  2. package/dist/animation/core/helpers/isFluidValue.d.ts +8 -4
  3. package/dist/animation/lib/interpolation.d.ts +20 -15
  4. package/dist/gestures/helpers/math.d.ts +1 -1
  5. package/dist/index.js +1 -2897
  6. package/dist/index.js.map +1 -1
  7. package/package.json +2 -1
  8. package/.vscode/settings.json +0 -3
  9. package/dist/animation/animationType.d.ts +0 -15
  10. package/dist/animation/core/animation/Animation.d.ts +0 -16
  11. package/dist/animation/core/animation/FluidValue.d.ts +0 -21
  12. package/dist/animation/core/animation/RequestAnimationFrame.d.ts +0 -8
  13. package/dist/animation/core/animation/SpringAnimation.d.ts +0 -41
  14. package/dist/animation/core/animation/TimingAnimation.d.ts +0 -35
  15. package/dist/animation/core/animation/TransitionValue.d.ts +0 -21
  16. package/dist/animation/core/helpers/camelToDash.d.ts +0 -7
  17. package/dist/animation/core/helpers/canInterpolate.d.ts +0 -11
  18. package/dist/animation/core/helpers/getAnimatableObject.d.ts +0 -22
  19. package/dist/animation/core/helpers/getNonAnimatableStyle.d.ts +0 -6
  20. package/dist/animation/core/react/Tags.d.ts +0 -3
  21. package/dist/animation/core/react/TransformStyles.d.ts +0 -8
  22. package/dist/animation/core/react/animated.d.ts +0 -29
  23. package/dist/animation/core/react/combineRefs.d.ts +0 -2
  24. package/dist/animation/core/react/functions/camelToDash.d.ts +0 -7
  25. package/dist/animation/core/react/functions/getAnimatableObject.d.ts +0 -22
  26. package/dist/animation/core/react/functions/getCleanProps.d.ts +0 -4
  27. package/dist/animation/core/react/functions/getCssValue.d.ts +0 -8
  28. package/dist/animation/core/react/functions/getNonAnimatableStyle.d.ts +0 -6
  29. package/dist/animation/core/react/functions/index.d.ts +0 -7
  30. package/dist/animation/core/react/functions/isDefined.d.ts +0 -6
  31. package/dist/animation/core/react/functions/isTransitionValue.d.ts +0 -6
  32. package/dist/animation/core/react/helpers/camelToDash.d.ts +0 -7
  33. package/dist/animation/core/react/helpers/canInterpolate.d.ts +0 -7
  34. package/dist/animation/core/react/helpers/getAnimatableObject.d.ts +0 -22
  35. package/dist/animation/core/react/helpers/getCleanProps.d.ts +0 -4
  36. package/dist/animation/core/react/helpers/getCssValue.d.ts +0 -8
  37. package/dist/animation/core/react/helpers/getNonAnimatableStyle.d.ts +0 -6
  38. package/dist/animation/core/react/helpers/index.d.ts +0 -7
  39. package/dist/animation/core/react/helpers/isDefined.d.ts +0 -6
  40. package/dist/animation/core/react/helpers/isFluidValue.d.ts +0 -6
  41. package/dist/animation/core/react/helpers/isTransitionValue.d.ts +0 -6
  42. package/dist/animation/core/react/useMounts.d.ts +0 -26
  43. package/dist/animation/core/react/useTransition.d.ts +0 -9
  44. package/dist/animation/core/react/useTransitions.d.ts +0 -11
  45. package/dist/animation/core/types/animation.d.ts +0 -54
  46. package/dist/animation/core/types/common.d.ts +0 -4
  47. package/dist/animation/core/types/fluid.d.ts +0 -19
  48. package/dist/animation/core/types/index.d.ts +0 -2
  49. package/dist/animation/getInitialConfig.d.ts +0 -3
  50. package/dist/animation/index.d.ts +0 -6
  51. package/dist/animation/interpolation.d.ts +0 -21
  52. package/dist/animation/modules/AnimatedBlock.d.ts +0 -8
  53. package/dist/animation/modules/AnimatedImage.d.ts +0 -8
  54. package/dist/animation/modules/AnimatedInline.d.ts +0 -8
  55. package/dist/animation/modules/MountedBlock.d.ts +0 -29
  56. package/dist/animation/modules/ScrollableBlock.d.ts +0 -21
  57. package/dist/animation/modules/TransitionBlock.d.ts +0 -17
  58. package/dist/animation/modules/index.d.ts +0 -6
  59. package/dist/animation/useAnimatedValue.d.ts +0 -22
  60. package/dist/animation/useMountedValue.d.ts +0 -15
  61. package/dist/gestures/eventAttacher.d.ts +0 -11
  62. package/dist/gestures/index.d.ts +0 -2
  63. package/dist/gestures/math.d.ts +0 -34
  64. package/dist/gestures/types.d.ts +0 -51
  65. package/dist/gestures/withDefault.d.ts +0 -4
  66. package/dist/utils/isDefined.d.ts +0 -1
  67. package/ecosystem.config.js +0 -12
  68. package/example/README.md +0 -46
  69. package/example/package-lock.json +0 -19597
  70. package/example/package.json +0 -45
  71. package/example/public/favicon.ico +0 -0
  72. package/example/public/index.html +0 -20
  73. package/example/public/logo192.png +0 -0
  74. package/example/public/logo512.png +0 -0
  75. package/example/public/manifest.json +0 -25
  76. package/example/public/robots.txt +0 -3
  77. package/example/src/App.tsx +0 -41
  78. package/example/src/components/Draggable.tsx +0 -46
  79. package/example/src/components/Gestures.tsx +0 -151
  80. package/example/src/components/Interpolation.tsx +0 -21
  81. package/example/src/components/Loop.tsx +0 -48
  82. package/example/src/components/MountedBlock.tsx +0 -25
  83. package/example/src/components/MouseMove.tsx +0 -59
  84. package/example/src/components/MultistageTransition.tsx +0 -34
  85. package/example/src/components/Scroll.tsx +0 -39
  86. package/example/src/components/ScrollableBlock.tsx +0 -27
  87. package/example/src/components/SnapTo.tsx +0 -55
  88. package/example/src/components/TransitionBlock.tsx +0 -37
  89. package/example/src/components/Wheel.tsx +0 -39
  90. package/example/src/components/index.ts +0 -18
  91. package/example/src/components/svgLine.tsx +0 -48
  92. package/example/src/components/useAnimatedValue.tsx +0 -57
  93. package/example/src/components/useMountedValue.tsx +0 -62
  94. package/example/src/index.css +0 -8
  95. package/example/src/index.tsx +0 -16
  96. package/example/tsconfig.json +0 -26
  97. package/rollup.config.mjs +0 -18
  98. package/src/animation/core/controllers/Animation.ts +0 -27
  99. package/src/animation/core/controllers/FluidValue.ts +0 -97
  100. package/src/animation/core/controllers/RequestAnimationFrame.ts +0 -13
  101. package/src/animation/core/controllers/SpringAnimation.ts +0 -218
  102. package/src/animation/core/controllers/TimingAnimation.ts +0 -152
  103. package/src/animation/core/easing/Bezier.ts +0 -146
  104. package/src/animation/core/easing/Easing.ts +0 -132
  105. package/src/animation/core/helpers/camelCaseToKebabCase.ts +0 -10
  106. package/src/animation/core/helpers/getCleanProps.ts +0 -16
  107. package/src/animation/core/helpers/getCssValue.ts +0 -60
  108. package/src/animation/core/helpers/index.ts +0 -5
  109. package/src/animation/core/helpers/isDefined.ts +0 -14
  110. package/src/animation/core/helpers/isFluidValue.ts +0 -11
  111. package/src/animation/core/index.ts +0 -16
  112. package/src/animation/core/interpolation/Colors.ts +0 -232
  113. package/src/animation/core/interpolation/Interpolation.ts +0 -395
  114. package/src/animation/core/interpolation/__tests__/Colors.test.tsx +0 -35
  115. package/src/animation/core/react/fluid.ts +0 -197
  116. package/src/animation/core/react/makeFluid.ts +0 -294
  117. package/src/animation/core/react/transforms.ts +0 -90
  118. package/src/animation/core/react/useFluidValue.ts +0 -43
  119. package/src/animation/core/react/useMount.ts +0 -58
  120. package/src/animation/core/types/animation.d.ts +0 -56
  121. package/src/animation/core/types/common.d.ts +0 -4
  122. package/src/animation/core/types/fluid.d.ts +0 -38
  123. package/src/animation/lib/animationType.ts +0 -17
  124. package/src/animation/lib/getInitialConfig.ts +0 -61
  125. package/src/animation/lib/index.ts +0 -12
  126. package/src/animation/lib/interpolation.ts +0 -47
  127. package/src/animation/lib/modules/AnimatedBlock.ts +0 -8
  128. package/src/animation/lib/modules/AnimatedImage.ts +0 -8
  129. package/src/animation/lib/modules/AnimatedInline.ts +0 -8
  130. package/src/animation/lib/modules/MountedBlock.tsx +0 -51
  131. package/src/animation/lib/modules/ScrollableBlock.tsx +0 -68
  132. package/src/animation/lib/modules/TransitionBlock.tsx +0 -28
  133. package/src/animation/lib/modules/index.ts +0 -6
  134. package/src/animation/lib/useAnimatedValue.ts +0 -60
  135. package/src/animation/lib/useMountedValue.ts +0 -18
  136. package/src/gestures/controllers/DragGesture.ts +0 -178
  137. package/src/gestures/controllers/Gesture.ts +0 -54
  138. package/src/gestures/controllers/MouseMoveGesture.ts +0 -111
  139. package/src/gestures/controllers/ScrollGesture.ts +0 -107
  140. package/src/gestures/controllers/WheelGesture.ts +0 -123
  141. package/src/gestures/controllers/index.ts +0 -4
  142. package/src/gestures/helpers/eventAttacher.ts +0 -67
  143. package/src/gestures/helpers/index.ts +0 -1
  144. package/src/gestures/helpers/math.ts +0 -120
  145. package/src/gestures/helpers/withDefault.ts +0 -3
  146. package/src/gestures/hooks/index.ts +0 -5
  147. package/src/gestures/hooks/useDrag.ts +0 -14
  148. package/src/gestures/hooks/useGesture.ts +0 -38
  149. package/src/gestures/hooks/useMouseMove.ts +0 -11
  150. package/src/gestures/hooks/useRecognizer.ts +0 -59
  151. package/src/gestures/hooks/useScroll.ts +0 -11
  152. package/src/gestures/hooks/useWheel.ts +0 -11
  153. package/src/gestures/types/index.d.ts +0 -49
  154. package/src/hooks/index.ts +0 -3
  155. package/src/hooks/useMeasure.ts +0 -132
  156. package/src/hooks/useOutsideClick.ts +0 -36
  157. package/src/hooks/useWindowDimension.ts +0 -58
  158. package/src/index.ts +0 -42
  159. package/src/utils/delay.ts +0 -9
  160. package/src/utils/index.ts +0 -1
  161. package/tsconfig.json +0 -24
@@ -1,56 +0,0 @@
1
- import type { Fn } from './common';
2
-
3
- /**
4
- * Base unit which is accepted by `FluidValue`
5
- */
6
- export type Length = number | string;
7
-
8
- /**
9
- * Object passed as an argument on `onRest` function
10
- */
11
- export type ResultType = { finished: boolean; value: number };
12
-
13
- /**
14
- * Function read by `animated` hoc to determine whether it
15
- * can be animated or not
16
- */
17
- export type SubscribeFn = (
18
- onUpdate: OnUpdateFn,
19
- property: string,
20
- uuid: number
21
- ) => void;
22
-
23
- /**
24
- * Configuration object for `FluidValue`
25
- */
26
- export interface FluidValueConfig {
27
- mass?: number;
28
- tension?: number;
29
- friction?: number;
30
- duration?: number;
31
- easing?: Fn<number, number>;
32
- immediate?: boolean;
33
- delay?: number;
34
- restDistance?: number;
35
- onChange?: Fn<number, void>;
36
- onRest?: Fn<ResultType, void>;
37
- onStart?: Fn<number, void>;
38
- }
39
-
40
- /**
41
- * Object which can be assigned to animate
42
- */
43
- export type AssignValue =
44
- | Length
45
- | Fn<(next: Length, config?: FluidValueConfig) => Promise<any>, void>;
46
-
47
- export type OnUpdateCallback = Fn<ResultType, void>;
48
-
49
- /**
50
- * Function to start the animation (it starts the already subscribed animation)
51
- */
52
- export type OnUpdateFn = (
53
- updatedValue: AssignValue,
54
- config?: FluidValueConfig,
55
- callback?: OnUpdateCallback
56
- ) => void;
@@ -1,4 +0,0 @@
1
- /**
2
- * Generic function type argument of type T returns type U
3
- */
4
- export type Fn<T, U> = (value: T) => U;
@@ -1,38 +0,0 @@
1
- import {
2
- CSSProperties,
3
- HTMLAttributes,
4
- SVGAttributes,
5
- ComponentType,
6
- } from 'react';
7
-
8
- import { FluidValue } from '../controllers/FluidValue';
9
- import { styleTrasformKeys } from '../react/transforms';
10
-
11
- export type FluidTypes = 'spring' | 'timing';
12
-
13
- export type FluidCSSProperties = {
14
- [key in keyof CSSProperties]: CSSProperties[key];
15
- } & {
16
- [key in (typeof styleTrasformKeys)[number]]?: number | string | FluidValue;
17
- };
18
-
19
- export type FluidHTMLAttributes<T> = {
20
- [property in keyof HTMLAttributes<T>]:
21
- | HTMLAttributes<T>[property]
22
- | FluidValue;
23
- };
24
-
25
- export type FluidSVGAttributes<T> = {
26
- [property in keyof SVGAttributes<T>]: SVGAttributes<T>[property] | FluidValue;
27
- };
28
-
29
- export type FluidProps<T> = Omit<
30
- FluidHTMLAttributes<T> & FluidSVGAttributes<T>,
31
- 'style'
32
- > & {
33
- style?: FluidCSSProperties;
34
- };
35
-
36
- export type WrappedComponentOrTag =
37
- | ComponentType<HTMLAttributes<HTMLElement>>
38
- | keyof JSX.IntrinsicElements;
@@ -1,17 +0,0 @@
1
- import { getInitialConfig } from './getInitialConfig';
2
-
3
- export const AnimationConfigUtils = {
4
- ELASTIC: getInitialConfig('elastic'),
5
- BOUNCE: getInitialConfig('bounce'),
6
- EASE: getInitialConfig('ease'),
7
- STIFF: getInitialConfig('stiff'),
8
- WOOBLE: getInitialConfig('wooble'),
9
- EASE_IN: getInitialConfig('easein'),
10
- EASE_OUT: getInitialConfig('easeout'),
11
- EASE_IN_OUT: getInitialConfig('easeinout'),
12
- POWER1: getInitialConfig('power1'),
13
- POWER2: getInitialConfig('power2'),
14
- POWER3: getInitialConfig('power3'),
15
- POWER4: getInitialConfig('power4'),
16
- LINEAR: getInitialConfig('linear'),
17
- };
@@ -1,61 +0,0 @@
1
- import { Easing, FluidValueConfig } from '../core';
2
- export type InitialConfigType =
3
- | 'linear'
4
- | 'easein'
5
- | 'easeout'
6
- | 'easeinout'
7
- | 'ease'
8
- | 'power1'
9
- | 'power2'
10
- | 'power3'
11
- | 'power4'
12
- | 'elastic'
13
- | 'stiff'
14
- | 'wooble'
15
- | 'bounce';
16
-
17
- export const getInitialConfig = (
18
- animationType?: InitialConfigType
19
- ): FluidValueConfig => {
20
- switch (animationType) {
21
- case 'elastic':
22
- return { mass: 1, friction: 18, tension: 250 };
23
-
24
- case 'stiff':
25
- return { mass: 1, friction: 18, tension: 350 };
26
-
27
- case 'wooble':
28
- return { mass: 1, friction: 8, tension: 250 };
29
-
30
- case 'bounce':
31
- return { duration: 500, easing: Easing.bounce };
32
-
33
- case 'power1':
34
- return { duration: 500, easing: Easing.bezier(0.17, 0.42, 0.51, 0.97) };
35
-
36
- case 'power2':
37
- return { duration: 500, easing: Easing.bezier(0.07, 0.11, 0.13, 1) };
38
-
39
- case 'power3':
40
- return { duration: 500, easing: Easing.bezier(0.09, 0.7, 0.16, 1.04) };
41
-
42
- case 'power4':
43
- return { duration: 500, easing: Easing.bezier(0.05, 0.54, 0, 1.03) };
44
-
45
- case 'linear':
46
- return { duration: 500, easing: Easing.linear };
47
-
48
- case 'easein':
49
- return { duration: 500, easing: Easing.in(Easing.ease) };
50
-
51
- case 'easeout':
52
- return { duration: 500, easing: Easing.out(Easing.ease) };
53
-
54
- case 'easeinout':
55
- return { duration: 500, easing: Easing.inOut(Easing.ease) };
56
-
57
- case 'ease':
58
- default:
59
- return { mass: 1, friction: 34, tension: 290 };
60
- }
61
- };
@@ -1,12 +0,0 @@
1
- export { interpolate, bInterpolate } from './interpolation';
2
- export {
3
- AnimatedBlock,
4
- AnimatedImage,
5
- AnimatedInline,
6
- MountedBlock,
7
- ScrollableBlock,
8
- TransitionBlock,
9
- } from './modules';
10
- export { useAnimatedValue, UseAnimatedValueConfig } from './useAnimatedValue';
11
- export { useMountedValue } from './useMountedValue';
12
- export { AnimationConfigUtils } from './animationType';
@@ -1,47 +0,0 @@
1
- import { ExtrapolateConfig, FluidValue } from '../core';
2
- import { interpolate as internalInterpolate } from '../core';
3
-
4
- /**
5
- * interpolate functions maps input range to given output range
6
- * @param value - number | TransitionValue
7
- * @param inputRange - Array<number>
8
- * @param outputRange - Array<number | string>
9
- * @param extrapolateConfig - "clamp" | "identity" | "extend"
10
- * @returns - number | TransitionValue
11
- */
12
- export function interpolate(
13
- value: number | FluidValue,
14
- inputRange: Array<number>,
15
- outputRange: Array<number | string>,
16
- extrapolateConfig?: ExtrapolateConfig
17
- ) {
18
- return internalInterpolate(
19
- value as any,
20
- inputRange,
21
- outputRange,
22
- extrapolateConfig
23
- );
24
- }
25
-
26
- /**
27
- * bInterpolate functions maps input range [0, 1] to given [minOutput, maxOutput]
28
- * sorthand function to interpolate input range [0, 1]
29
- * @param value - number | TransitionValue
30
- * @param minOutput - number | string
31
- * @param maxOutput - number | string
32
- * @param extrapolateConfig - "clamp" | "identity" | "extend"
33
- * @returns - number | TransitionValue
34
- */
35
- export function bInterpolate(
36
- value: number | FluidValue,
37
- minOutput: number | string,
38
- maxOutput: number | string,
39
- extrapolateConfig?: ExtrapolateConfig
40
- ) {
41
- return internalInterpolate(
42
- value as any,
43
- [0, 1],
44
- [minOutput, maxOutput],
45
- extrapolateConfig
46
- );
47
- }
@@ -1,8 +0,0 @@
1
- import { makeFluid } from '../../core';
2
-
3
- /**
4
- * AnimatedBlock - A higher order component built upon `div` element
5
- * which can accept `AnimatedValue`. It also exposes some extra style properties like
6
- * translateX, translateY, rotateX, rotateY, scaleX, etc.
7
- */
8
- export const AnimatedBlock = makeFluid('div');
@@ -1,8 +0,0 @@
1
- import { makeFluid } from '../../core';
2
-
3
- /**
4
- * AnimatedImage - A higher order component built upon `img` element
5
- * which can accept `AnimatedValue`. It also exposes some extra style properties like
6
- * translateX, translateY, rotateX, rotateY, scaleX, etc.
7
- */
8
- export const AnimatedImage = makeFluid('img');
@@ -1,8 +0,0 @@
1
- import { makeFluid } from '../../core';
2
-
3
- /**
4
- * AnimatedInline - A higher order component built upon `span` element
5
- * which can accept `AnimatedValue`. It also exposes some extra style properties like
6
- * translateX, translateY, rotateX, rotateY, scaleX, etc.
7
- */
8
- export const AnimatedInline = makeFluid('span');
@@ -1,51 +0,0 @@
1
- import * as React from 'react';
2
- import { FluidValue, FluidValueConfig } from '../../core';
3
- import { useMountedValue } from '../useMountedValue';
4
-
5
- interface MountedValueConfig extends FluidValueConfig {}
6
-
7
- interface MountedBlockProps {
8
- state: boolean;
9
- children: (animation: { value: FluidValue }) => React.ReactNode;
10
- from?: number;
11
- enter?: number;
12
- exit?: number;
13
- config?: MountedValueConfig;
14
- enterConfig?: MountedValueConfig;
15
- exitConfig?: MountedValueConfig;
16
- }
17
-
18
- /**
19
- * MountedBlock - Higher order component which handles mounting and unmounting of a component.
20
- * @prop { boolean } state - Boolean indicating the component should mount or unmount.
21
- * @prop { function } children - Child as a function with `AnimatedValue` on `.value` property.
22
- * @prop { number } from - Number that dictates the beginning state for animation.
23
- * @prop { number } enter - Number that dictates the entry state for animation.
24
- * @prop { number } exit - Number that dictates the exit state for animation.
25
- * @prop { MountedValueConfig } config - Animation configuration for overall animation.
26
- * @prop { MountedValueConfig } enterConfig - Animation configuration for the entering state of animation.
27
- * @prop { MountedValueConfig } exitConfig - Animation configuration for the entering state of animation.
28
- */
29
- export const MountedBlock = ({
30
- state,
31
- children,
32
- from = 0,
33
- enter = 1,
34
- exit = 0,
35
- config,
36
- enterConfig,
37
- exitConfig,
38
- }: MountedBlockProps) => {
39
- const open = useMountedValue(state, {
40
- from,
41
- enter,
42
- exit,
43
- config,
44
- enterConfig,
45
- exitConfig,
46
- });
47
-
48
- return (
49
- <>{open((animation, mounted) => mounted && children(animation as any))}</>
50
- );
51
- };
@@ -1,68 +0,0 @@
1
- import * as React from 'react';
2
- import { useAnimatedValue, UseAnimatedValueConfig } from '../useAnimatedValue';
3
- import { FluidValue } from '../../core';
4
-
5
- interface ScrollableBlockProps {
6
- children?: (animation: {
7
- value?: FluidValue | string | number;
8
- }) => React.ReactNode;
9
- direction?: 'single' | 'both';
10
- threshold?: number;
11
- animationConfig?: UseAnimatedValueConfig;
12
- }
13
-
14
- /**
15
- * ScrollableBlock - Higher order component to handle the entrance or exit animation
16
- * of a component when it enters or exit the viewport. Accepts child as a function with
17
- * `AnimatedValue` as its first argument which can be interpolated on input range [0, 1]
18
- * @prop { function } children - child as a function with `AnimatedValue` as its first argument.
19
- * @prop { 'single' | 'both' } direction - single applies animation on enter once, both applies on enter and exit.
20
- * @prop { number } threshold - should be in range 0 to 1 which equivalent to `IntersectionObserver` threshold.
21
- * @prop { UseAnimatedValueConfig } animationConfig - Animation config
22
- */
23
- export const ScrollableBlock = (props: ScrollableBlockProps) => {
24
- const {
25
- children,
26
- direction = 'single',
27
- animationConfig,
28
- threshold = 0.2,
29
- } = props;
30
- const scrollableBlockRef = React.useRef<HTMLDivElement>(null);
31
- const animation = useAnimatedValue(0, animationConfig); // 0: not intersecting | 1: intersecting
32
-
33
- React.useEffect(() => {
34
- const _scrollableBlock = scrollableBlockRef.current;
35
-
36
- const observer = new IntersectionObserver(
37
- function ([entry]) {
38
- const { isIntersecting } = entry;
39
-
40
- if (isIntersecting) {
41
- animation.value = 1;
42
- } else {
43
- if (direction === 'both') animation.value = 0;
44
- }
45
- },
46
- {
47
- root: null, // FOR VIEWPORT ONLY
48
- threshold,
49
- }
50
- );
51
-
52
- if (_scrollableBlock) {
53
- observer.observe(_scrollableBlock);
54
- }
55
-
56
- return () => {
57
- if (_scrollableBlock) {
58
- observer.unobserve(_scrollableBlock);
59
- }
60
- };
61
- }, []);
62
-
63
- return (
64
- <div ref={scrollableBlockRef}>
65
- {children && children({ value: animation.value })}
66
- </div>
67
- );
68
- };
@@ -1,28 +0,0 @@
1
- import * as React from 'react';
2
- import { bin } from '../../../gestures/helpers/math';
3
- import { useAnimatedValue, UseAnimatedValueConfig } from '../useAnimatedValue';
4
- import { FluidValue } from '../../core';
5
-
6
- interface TransitionBlockProps {
7
- state: boolean;
8
- children: (animation: {
9
- value?: FluidValue | string | number;
10
- }) => React.ReactNode;
11
- config?: UseAnimatedValueConfig;
12
- }
13
-
14
- /**
15
- * TransitionBlock - Higher order component which animates on state change.
16
- * @prop { boolean } state - Boolean indicating the current state of animation, usually `false = 0 and true = 1`.
17
- * @prop { function } children - Child as a function with `AnimatedValue` on `.value` property.
18
- * @prop { UseAnimatedValueConfig } config - Animation configuration.
19
- */
20
- export const TransitionBlock = ({
21
- state,
22
- children,
23
- config,
24
- }: TransitionBlockProps) => {
25
- const amv = useAnimatedValue(bin(state), config);
26
-
27
- return <>{children({ value: amv.value })}</>;
28
- };
@@ -1,6 +0,0 @@
1
- export * from './AnimatedBlock';
2
- export * from './AnimatedInline';
3
- export * from './AnimatedImage';
4
- export * from './MountedBlock';
5
- export * from './ScrollableBlock';
6
- export * from './TransitionBlock';
@@ -1,60 +0,0 @@
1
- import { useFluidValue, FluidValueConfig, FluidValue } from '../core';
2
- import { AnimationConfigUtils } from './animationType';
3
-
4
- // useAnimatedValue value type
5
- type Length = number | string;
6
-
7
- export interface UseAnimatedValueConfig extends FluidValueConfig {}
8
-
9
- /**
10
- * `useAnimatedValue` returns an animation value with `.value` and `.currentValue` property which is
11
- * initialized when passed to argument (`initialValue`). The retured value persist until the lifetime of
12
- * a component. It doesnot cast any re-renders which can is very good for performance optimization.
13
- *
14
- * @param { string | number } initialValue - Initial value
15
- * @param { UseAnimatedValueConfig } config - Animation configuration object.
16
- */
17
- export function useAnimatedValue(
18
- initialValue: Length,
19
- config?: UseAnimatedValueConfig
20
- ) {
21
- const [animation, setAnimation] = useFluidValue(initialValue, {
22
- ...AnimationConfigUtils.EASE,
23
- ...config,
24
- });
25
-
26
- const targetObject: {
27
- value: FluidValue | string | number | undefined;
28
- currentValue: number | string;
29
- } = {
30
- value: animation,
31
- currentValue: animation.get(),
32
- };
33
-
34
- return new Proxy(targetObject, {
35
- set: function (_, key, value: any) {
36
- if (key === 'value') {
37
- if (typeof value === 'number' || typeof value === 'string') {
38
- setAnimation(value);
39
- }
40
-
41
- return true;
42
- }
43
-
44
- throw new Error('You cannot set any other property to animation node.');
45
- },
46
- get: function (_, key) {
47
- if (key === 'value') {
48
- return animation;
49
- }
50
-
51
- if (key === 'currentValue') {
52
- return animation.get();
53
- }
54
-
55
- throw new Error(
56
- 'You cannot access any other property from animation node.'
57
- );
58
- },
59
- });
60
- }
@@ -1,18 +0,0 @@
1
- import { useMount, UseMountConfig, FluidValue } from '../core';
2
-
3
- export interface UseMountedValueConfig extends UseMountConfig {}
4
-
5
- /**
6
- * `useMountedValue` handles mounting and unmounting of a component which captures current state
7
- * passed as an arugment (`state`) and exposes the shadow state which handles the mount and unmount
8
- * of a component.
9
- *
10
- * @param { boolean } state - Boolean indicating the component should mount or unmount.
11
- * @param { UseMountedValueConfig } config - Animation configuration.
12
- */
13
- export function useMountedValue(state: boolean, config: UseMountedValueConfig) {
14
- const mv = useMount(state, config);
15
- return (
16
- cb: (value: { value: FluidValue }, mounted: boolean) => React.ReactNode
17
- ) => mv((a, m) => cb({ value: a }, m));
18
- }
@@ -1,178 +0,0 @@
1
- import { attachEvents } from '../helpers/eventAttacher';
2
- import { clamp } from '../helpers/math';
3
- import { withDefault } from '../helpers/withDefault';
4
- import { Gesture } from './Gesture';
5
-
6
- import type { Vector2 } from '../types';
7
-
8
- export class DragGesture extends Gesture {
9
- movementStart: Vector2 = withDefault(0, 0);
10
- initialMovement: Vector2 = withDefault(0, 0);
11
- movement: Vector2 = withDefault(0, 0);
12
- previousMovement: Vector2 = withDefault(0, 0);
13
- translation: Vector2 = withDefault(0, 0);
14
- offset: Vector2 = withDefault(0, 0);
15
- velocity: Vector2 = withDefault(0, 0);
16
-
17
- // @override
18
- // initialize the events
19
- _initEvents() {
20
- if (this.targetElement || this.targetElements.length > 0) {
21
- this._subscribe = attachEvents(
22
- [window],
23
- [
24
- ['mousedown', this.pointerDown.bind(this)],
25
- ['mousemove', this.pointerMove.bind(this)],
26
- ['mouseup', this.pointerUp.bind(this)],
27
- ['touchstart', this.pointerDown.bind(this), { passive: false }],
28
- ['touchmove', this.pointerMove.bind(this), { passive: false }],
29
- ['touchend', this.pointerUp.bind(this)],
30
- ]
31
- );
32
- }
33
- }
34
-
35
- // @override - cancel events
36
- // we only canceled down and move events because mouse up
37
- // will not be triggered
38
- _cancelEvents() {
39
- if (this._subscribe) {
40
- this._subscribe(['mousedown', 'mousemove', 'touchstart', 'touchmove']);
41
- }
42
- }
43
-
44
- _handleCallback() {
45
- if (this.callback) {
46
- this.callback({
47
- args: [this.currentIndex],
48
- down: this.isActive,
49
- movementX: this.movement.x,
50
- movementY: this.movement.y,
51
- offsetX: this.translation.x,
52
- offsetY: this.translation.y,
53
- velocityX: this.velocity.x,
54
- velocityY: this.velocity.y,
55
- distanceX: Math.abs(this.movement.x),
56
- distanceY: Math.abs(this.movement.y),
57
- directionX: Math.sign(this.movement.x),
58
- directionY: Math.sign(this.movement.y),
59
- cancel: () => {
60
- this._cancelEvents();
61
- },
62
- });
63
- }
64
- }
65
-
66
- pointerDown(e: any) {
67
- if (e.type === 'touchstart') {
68
- this.movementStart = {
69
- x: e.touches[0].clientX,
70
- y: e.touches[0].clientY,
71
- };
72
- } else {
73
- this.movementStart = { x: e.clientX, y: e.clientY };
74
- }
75
-
76
- this.movement = { x: 0, y: 0 };
77
- this.offset = { x: this.translation.x, y: this.translation.y };
78
- this.previousMovement = { x: 0, y: 0 };
79
- this.velocity = { x: 0, y: 0 };
80
-
81
- // find current selected element
82
- const currElem = this.targetElements.find((elem: any) => elem === e.target);
83
-
84
- if (e.target === this.targetElement || currElem) {
85
- this.isActive = true;
86
- e.preventDefault();
87
-
88
- // set args
89
- if (currElem) {
90
- this.currentIndex = this.targetElements.indexOf(currElem);
91
- }
92
-
93
- // if initial function is defined then call it to get initial movementX and movementY
94
- // if only select to bounded draggable element
95
- const initial = this.config?.initial && this.config.initial();
96
- const initialMovementX = initial?.movementX;
97
- const initialMovementY = initial?.movementY;
98
-
99
- this.initialMovement = {
100
- x: initialMovementX ?? 0,
101
- y: initialMovementY ?? 0,
102
- };
103
-
104
- this.movement = {
105
- x: this.initialMovement.x,
106
- y: this.initialMovement.y,
107
- };
108
-
109
- this.previousMovement = {
110
- x: this.initialMovement.x,
111
- y: this.initialMovement.y,
112
- };
113
-
114
- this._handleCallback();
115
- }
116
- }
117
-
118
- pointerMove(e: any) {
119
- if (this.isActive) {
120
- e.preventDefault();
121
- const now = Date.now();
122
- const deltaTime = clamp(now - this.lastTimeStamp, 0.1, 64);
123
- this.lastTimeStamp = now;
124
-
125
- const t = deltaTime / 1000;
126
-
127
- if (e.type === 'touchmove') {
128
- this.movement = {
129
- x:
130
- this.initialMovement.x +
131
- (e.touches[0].clientX - this.movementStart.x),
132
- y:
133
- this.initialMovement.y +
134
- (e.touches[0].clientY - this.movementStart.y),
135
- };
136
- } else {
137
- this.movement = {
138
- x: this.initialMovement.x + (e.clientX - this.movementStart.x),
139
- y: this.initialMovement.y + (e.clientY - this.movementStart.y),
140
- };
141
- }
142
-
143
- this.translation = {
144
- x: this.offset.x + this.movement.x,
145
- y: this.offset.y + this.movement.y,
146
- };
147
-
148
- this.velocity = {
149
- x: clamp(
150
- (this.movement.x - this.previousMovement.x) / t / 1000,
151
- -1 * Gesture._VELOCITY_LIMIT,
152
- Gesture._VELOCITY_LIMIT
153
- ),
154
- y: clamp(
155
- (this.movement.y - this.previousMovement.y) / t / 1000,
156
- -1 * Gesture._VELOCITY_LIMIT,
157
- Gesture._VELOCITY_LIMIT
158
- ),
159
- };
160
-
161
- this.previousMovement = {
162
- x: this.movement.x,
163
- y: this.movement.y,
164
- };
165
-
166
- this._handleCallback();
167
- }
168
- }
169
-
170
- pointerUp() {
171
- if (this.isActive) {
172
- this.isActive = false;
173
- this._handleCallback();
174
- this._cancelEvents();
175
- this._initEvents();
176
- }
177
- }
178
- }