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.
Files changed (222) hide show
  1. package/.vscode/settings.json +3 -3
  2. package/LICENSE +21 -21
  3. package/README.md +115 -115
  4. package/dist/animation/animationType.d.ts +15 -15
  5. package/dist/animation/core/animation/Animation.d.ts +16 -0
  6. package/dist/animation/core/animation/FluidValue.d.ts +21 -0
  7. package/dist/animation/core/animation/RequestAnimationFrame.d.ts +8 -0
  8. package/dist/animation/core/animation/SpringAnimation.d.ts +41 -0
  9. package/dist/animation/core/animation/TimingAnimation.d.ts +35 -0
  10. package/dist/animation/core/animation/TransitionValue.d.ts +21 -0
  11. package/dist/animation/core/controllers/Animation.d.ts +16 -0
  12. package/dist/animation/core/controllers/FluidValue.d.ts +32 -0
  13. package/dist/animation/core/controllers/RequestAnimationFrame.d.ts +8 -0
  14. package/dist/animation/core/controllers/SpringAnimation.d.ts +41 -0
  15. package/dist/animation/core/controllers/TimingAnimation.d.ts +35 -0
  16. package/dist/animation/core/easing/Bezier.d.ts +8 -0
  17. package/dist/animation/core/easing/Easing.d.ts +40 -0
  18. package/dist/animation/core/helpers/camelCaseToKebabCase.d.ts +8 -0
  19. package/dist/animation/core/helpers/camelToDash.d.ts +7 -0
  20. package/dist/animation/core/helpers/canInterpolate.d.ts +11 -0
  21. package/dist/animation/core/helpers/getAnimatableObject.d.ts +22 -0
  22. package/dist/animation/core/helpers/getCleanProps.d.ts +10 -0
  23. package/dist/animation/core/helpers/getCssValue.d.ts +8 -0
  24. package/dist/animation/core/helpers/getNonAnimatableStyle.d.ts +6 -0
  25. package/dist/animation/core/helpers/index.d.ts +5 -0
  26. package/dist/animation/core/helpers/isDefined.d.ts +12 -0
  27. package/dist/animation/core/helpers/isFluidValue.d.ts +6 -0
  28. package/dist/animation/core/index.d.ts +11 -0
  29. package/dist/animation/core/interpolation/Colors.d.ts +25 -0
  30. package/dist/animation/core/interpolation/Interpolation.d.ts +80 -0
  31. package/dist/animation/core/interpolation/__tests__/Colors.test.d.ts +1 -0
  32. package/dist/animation/core/react/Tags.d.ts +3 -0
  33. package/dist/animation/core/react/TransformStyles.d.ts +8 -0
  34. package/dist/animation/core/react/animated.d.ts +29 -0
  35. package/dist/animation/core/react/combineRefs.d.ts +2 -0
  36. package/dist/animation/core/react/fluid.d.ts +6 -0
  37. package/dist/animation/core/react/functions/camelToDash.d.ts +7 -0
  38. package/dist/animation/core/react/functions/getAnimatableObject.d.ts +22 -0
  39. package/dist/animation/core/react/functions/getCleanProps.d.ts +4 -0
  40. package/dist/animation/core/react/functions/getCssValue.d.ts +8 -0
  41. package/dist/animation/core/react/functions/getNonAnimatableStyle.d.ts +6 -0
  42. package/dist/animation/core/react/functions/index.d.ts +7 -0
  43. package/dist/animation/core/react/functions/isDefined.d.ts +6 -0
  44. package/dist/animation/core/react/functions/isTransitionValue.d.ts +6 -0
  45. package/dist/animation/core/react/helpers/camelToDash.d.ts +7 -0
  46. package/dist/animation/core/react/helpers/canInterpolate.d.ts +7 -0
  47. package/dist/animation/core/react/helpers/getAnimatableObject.d.ts +22 -0
  48. package/dist/animation/core/react/helpers/getCleanProps.d.ts +4 -0
  49. package/dist/animation/core/react/helpers/getCssValue.d.ts +8 -0
  50. package/dist/animation/core/react/helpers/getNonAnimatableStyle.d.ts +6 -0
  51. package/dist/animation/core/react/helpers/index.d.ts +7 -0
  52. package/dist/animation/core/react/helpers/isDefined.d.ts +6 -0
  53. package/dist/animation/core/react/helpers/isFluidValue.d.ts +6 -0
  54. package/dist/animation/core/react/helpers/isTransitionValue.d.ts +6 -0
  55. package/dist/animation/core/react/makeFluid.d.ts +30 -0
  56. package/dist/animation/core/react/transforms.d.ts +6 -0
  57. package/dist/animation/core/react/useFluidValue.d.ts +9 -0
  58. package/dist/animation/core/react/useMount.d.ts +20 -0
  59. package/dist/animation/core/react/useMounts.d.ts +26 -0
  60. package/dist/animation/core/react/useTransition.d.ts +9 -0
  61. package/dist/animation/core/react/useTransitions.d.ts +11 -0
  62. package/dist/animation/core/types/animation.d.ts +54 -0
  63. package/dist/animation/core/types/common.d.ts +4 -0
  64. package/dist/animation/core/types/fluid.d.ts +19 -0
  65. package/dist/animation/core/types/index.d.ts +2 -0
  66. package/dist/animation/getInitialConfig.d.ts +3 -3
  67. package/dist/animation/index.d.ts +6 -6
  68. package/dist/animation/interpolation.d.ts +21 -21
  69. package/dist/animation/lib/animationType.d.ts +15 -0
  70. package/dist/animation/lib/getInitialConfig.d.ts +3 -0
  71. package/dist/animation/lib/index.d.ts +5 -0
  72. package/dist/animation/lib/interpolation.d.ts +20 -0
  73. package/dist/animation/lib/modules/AnimatedBlock.d.ts +8 -0
  74. package/dist/animation/lib/modules/AnimatedImage.d.ts +8 -0
  75. package/dist/animation/lib/modules/AnimatedInline.d.ts +8 -0
  76. package/dist/animation/lib/modules/MountedBlock.d.ts +29 -0
  77. package/dist/animation/lib/modules/ScrollableBlock.d.ts +22 -0
  78. package/dist/animation/lib/modules/TransitionBlock.d.ts +18 -0
  79. package/dist/animation/lib/modules/index.d.ts +6 -0
  80. package/dist/animation/lib/useAnimatedValue.d.ts +17 -0
  81. package/dist/animation/lib/useMountedValue.d.ts +14 -0
  82. package/dist/animation/modules/AnimatedBlock.d.ts +8 -8
  83. package/dist/animation/modules/AnimatedImage.d.ts +8 -8
  84. package/dist/animation/modules/AnimatedInline.d.ts +8 -8
  85. package/dist/animation/modules/MountedBlock.d.ts +29 -18
  86. package/dist/animation/modules/ScrollableBlock.d.ts +21 -21
  87. package/dist/animation/modules/TransitionBlock.d.ts +17 -17
  88. package/dist/animation/modules/index.d.ts +6 -6
  89. package/dist/animation/useAnimatedValue.d.ts +22 -22
  90. package/dist/animation/useMountedValue.d.ts +15 -15
  91. package/dist/gestures/controllers/DragGesture.d.ts +17 -17
  92. package/dist/gestures/controllers/Gesture.d.ts +20 -20
  93. package/dist/gestures/controllers/MouseMoveGesture.d.ts +13 -13
  94. package/dist/gestures/controllers/ScrollGesture.d.ts +14 -14
  95. package/dist/gestures/controllers/WheelGesture.d.ts +15 -15
  96. package/dist/gestures/controllers/index.d.ts +4 -4
  97. package/dist/gestures/eventAttacher.d.ts +11 -11
  98. package/dist/gestures/helpers/eventAttacher.d.ts +11 -0
  99. package/dist/gestures/helpers/index.d.ts +1 -0
  100. package/dist/gestures/helpers/math.d.ts +34 -0
  101. package/dist/gestures/helpers/withDefault.d.ts +4 -0
  102. package/dist/gestures/hooks/index.d.ts +5 -5
  103. package/dist/gestures/hooks/useDrag.d.ts +4 -4
  104. package/dist/gestures/hooks/useGesture.d.ts +9 -9
  105. package/dist/gestures/hooks/useMouseMove.d.ts +4 -4
  106. package/dist/gestures/hooks/useRecognizer.d.ts +10 -10
  107. package/dist/gestures/hooks/useScroll.d.ts +4 -4
  108. package/dist/gestures/hooks/useWheel.d.ts +4 -4
  109. package/dist/gestures/index.d.ts +2 -2
  110. package/dist/gestures/math.d.ts +34 -34
  111. package/dist/gestures/types.d.ts +51 -51
  112. package/dist/gestures/withDefault.d.ts +4 -4
  113. package/dist/hooks/index.d.ts +3 -3
  114. package/dist/hooks/useMeasure.d.ts +14 -14
  115. package/dist/hooks/useOutsideClick.d.ts +2 -2
  116. package/dist/hooks/useWindowDimension.d.ts +9 -9
  117. package/dist/index.d.ts +9 -5
  118. package/dist/index.js +2758 -1052
  119. package/dist/index.js.map +1 -1
  120. package/dist/utils/delay.d.ts +5 -5
  121. package/dist/utils/index.d.ts +1 -2
  122. package/dist/utils/isDefined.d.ts +1 -1
  123. package/ecosystem.config.js +12 -0
  124. package/example/README.md +46 -0
  125. package/example/package-lock.json +19597 -0
  126. package/example/package.json +45 -0
  127. package/example/public/favicon.ico +0 -0
  128. package/example/public/index.html +20 -0
  129. package/example/public/logo192.png +0 -0
  130. package/example/public/logo512.png +0 -0
  131. package/example/public/manifest.json +25 -0
  132. package/example/public/robots.txt +3 -0
  133. package/example/src/App.tsx +41 -0
  134. package/example/src/components/Draggable.tsx +46 -0
  135. package/example/src/components/Gestures.tsx +151 -0
  136. package/example/src/components/Interpolation.tsx +21 -0
  137. package/example/src/components/Loop.tsx +48 -0
  138. package/example/src/components/MountedBlock.tsx +25 -0
  139. package/example/src/components/MouseMove.tsx +59 -0
  140. package/example/src/components/MultistageTransition.tsx +34 -0
  141. package/example/src/components/Scroll.tsx +39 -0
  142. package/example/src/components/ScrollableBlock.tsx +27 -0
  143. package/example/src/components/SnapTo.tsx +55 -0
  144. package/example/src/components/TransitionBlock.tsx +37 -0
  145. package/example/src/components/Wheel.tsx +39 -0
  146. package/example/src/components/index.ts +18 -0
  147. package/example/src/components/svgLine.tsx +48 -0
  148. package/example/src/components/useAnimatedValue.tsx +57 -0
  149. package/example/src/components/useMountedValue.tsx +62 -0
  150. package/example/src/index.css +8 -0
  151. package/example/src/index.tsx +16 -0
  152. package/example/tsconfig.json +26 -0
  153. package/package.json +48 -48
  154. package/{rollup.config.js → rollup.config.mjs} +18 -18
  155. package/src/animation/core/controllers/Animation.ts +27 -0
  156. package/src/animation/core/controllers/FluidValue.ts +97 -0
  157. package/src/animation/core/controllers/RequestAnimationFrame.ts +13 -0
  158. package/src/animation/core/controllers/SpringAnimation.ts +218 -0
  159. package/src/animation/core/controllers/TimingAnimation.ts +152 -0
  160. package/src/animation/core/easing/Bezier.ts +146 -0
  161. package/src/animation/core/easing/Easing.ts +132 -0
  162. package/src/animation/core/helpers/camelCaseToKebabCase.ts +10 -0
  163. package/src/animation/core/helpers/getCleanProps.ts +16 -0
  164. package/src/animation/core/helpers/getCssValue.ts +60 -0
  165. package/src/animation/core/helpers/index.ts +5 -0
  166. package/src/animation/core/helpers/isDefined.ts +14 -0
  167. package/src/animation/core/helpers/isFluidValue.ts +11 -0
  168. package/src/animation/core/index.ts +16 -0
  169. package/src/animation/core/interpolation/Colors.ts +232 -0
  170. package/src/animation/core/interpolation/Interpolation.ts +395 -0
  171. package/src/animation/core/interpolation/__tests__/Colors.test.tsx +35 -0
  172. package/src/animation/core/react/fluid.ts +197 -0
  173. package/src/animation/core/react/makeFluid.ts +294 -0
  174. package/src/animation/core/react/transforms.ts +90 -0
  175. package/src/animation/core/react/useFluidValue.ts +43 -0
  176. package/src/animation/core/react/useMount.ts +58 -0
  177. package/src/animation/core/types/animation.d.ts +56 -0
  178. package/src/animation/core/types/common.d.ts +4 -0
  179. package/src/animation/core/types/fluid.d.ts +38 -0
  180. package/src/animation/{animationType.ts → lib/animationType.ts} +17 -17
  181. package/src/animation/{getInitialConfig.ts → lib/getInitialConfig.ts} +61 -61
  182. package/src/animation/lib/index.ts +12 -0
  183. package/src/animation/{interpolation.ts → lib/interpolation.ts} +47 -48
  184. package/src/animation/{modules → lib/modules}/AnimatedBlock.ts +8 -8
  185. package/src/animation/{modules → lib/modules}/AnimatedImage.ts +8 -8
  186. package/src/animation/{modules → lib/modules}/AnimatedInline.ts +8 -8
  187. package/src/animation/lib/modules/MountedBlock.tsx +51 -0
  188. package/src/animation/{modules → lib/modules}/ScrollableBlock.tsx +68 -69
  189. package/src/animation/{modules → lib/modules}/TransitionBlock.tsx +28 -29
  190. package/src/animation/{modules → lib/modules}/index.ts +6 -6
  191. package/src/animation/{useAnimatedValue.ts → lib/useAnimatedValue.ts} +60 -71
  192. package/src/animation/{useMountedValue.ts → lib/useMountedValue.ts} +18 -19
  193. package/src/gestures/controllers/DragGesture.ts +178 -177
  194. package/src/gestures/controllers/Gesture.ts +54 -54
  195. package/src/gestures/controllers/MouseMoveGesture.ts +111 -111
  196. package/src/gestures/controllers/ScrollGesture.ts +107 -107
  197. package/src/gestures/controllers/WheelGesture.ts +123 -123
  198. package/src/gestures/controllers/index.ts +4 -4
  199. package/src/gestures/{eventAttacher.ts → helpers/eventAttacher.ts} +67 -67
  200. package/src/gestures/helpers/index.ts +1 -0
  201. package/src/gestures/{math.ts → helpers/math.ts} +120 -120
  202. package/src/gestures/{withDefault.ts → helpers/withDefault.ts} +3 -3
  203. package/src/gestures/hooks/index.ts +5 -5
  204. package/src/gestures/hooks/useDrag.ts +14 -14
  205. package/src/gestures/hooks/useGesture.ts +38 -38
  206. package/src/gestures/hooks/useMouseMove.ts +11 -11
  207. package/src/gestures/hooks/useRecognizer.ts +59 -59
  208. package/src/gestures/hooks/useScroll.ts +11 -11
  209. package/src/gestures/hooks/useWheel.ts +11 -11
  210. package/src/gestures/{types.ts → types/index.d.ts} +49 -49
  211. package/src/hooks/index.ts +3 -3
  212. package/src/hooks/useMeasure.ts +132 -133
  213. package/src/hooks/useOutsideClick.ts +36 -36
  214. package/src/hooks/useWindowDimension.ts +58 -59
  215. package/src/index.ts +42 -5
  216. package/src/utils/delay.ts +9 -9
  217. package/src/utils/index.ts +1 -2
  218. package/tsconfig.json +24 -25
  219. package/src/animation/index.ts +0 -10
  220. package/src/animation/modules/MountedBlock.tsx +0 -25
  221. package/src/gestures/index.ts +0 -2
  222. package/src/utils/isDefined.ts +0 -4
package/dist/index.js CHANGED
@@ -1,89 +1,26 @@
1
- Object.defineProperty(exports, '__esModule', { value: true });
2
-
3
- var reMotion = require('@raidipesh78/re-motion');
4
1
  var React = require('react');
2
+ var jsxRuntime = require('react/jsx-runtime');
5
3
 
6
- /**
7
- * @param { number } ms - number of milliseconds to delay code execution
8
- * @returns Promise
9
- */
10
- function delay(ms) {
11
- return new Promise(function (resolve) {
12
- setTimeout(function () { return resolve(null); }, ms);
13
- });
14
- }
15
-
16
- /**
17
- * interpolate functions maps input range to given output range
18
- * @param value - number | TransitionValue
19
- * @param inputRange - Array<number>
20
- * @param outputRange - Array<number | string>
21
- * @param extrapolateConfig - "clamp" | "identity" | "extend"
22
- * @returns - number | TransitionValue
23
- */
24
- function interpolate(value, inputRange, outputRange, extrapolateConfig) {
25
- return reMotion.interpolate(value, inputRange, outputRange, extrapolateConfig);
26
- }
27
- /**
28
- * bInterpolate functions maps input range [0, 1] to given [minOutput, maxOutput]
29
- * sorthand function to interpolate input range [0, 1]
30
- * @param value - number | TransitionValue
31
- * @param minOutput - number | string
32
- * @param maxOutput - number | string
33
- * @param extrapolateConfig - "clamp" | "identity" | "extend"
34
- * @returns - number | TransitionValue
35
- */
36
- function bInterpolate(value, minOutput, maxOutput, extrapolateConfig) {
37
- return reMotion.interpolate(value, [0, 1], [minOutput, maxOutput], extrapolateConfig);
4
+ function _interopNamespaceDefault(e) {
5
+ var n = Object.create(null);
6
+ if (e) {
7
+ Object.keys(e).forEach(function (k) {
8
+ if (k !== 'default') {
9
+ var d = Object.getOwnPropertyDescriptor(e, k);
10
+ Object.defineProperty(n, k, d.get ? d : {
11
+ enumerable: true,
12
+ get: function () { return e[k]; }
13
+ });
14
+ }
15
+ });
16
+ }
17
+ n.default = e;
18
+ return Object.freeze(n);
38
19
  }
39
20
 
40
- /**
41
- * AnimatedBlock - A higher order component built upon `div` element
42
- * which can accept `AnimatedValue`. It also exposes some extra style properties like
43
- * translateX, translateY, rotateX, rotateY, scaleX, etc.
44
- */
45
- var AnimatedBlock = reMotion.makeAnimatedComponent('div');
21
+ var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
46
22
 
47
- /**
48
- * AnimatedInline - A higher order component built upon `span` element
49
- * which can accept `AnimatedValue`. It also exposes some extra style properties like
50
- * translateX, translateY, rotateX, rotateY, scaleX, etc.
51
- */
52
- var AnimatedInline = reMotion.makeAnimatedComponent('span');
53
-
54
- /**
55
- * AnimatedImage - A higher order component built upon `img` element
56
- * which can accept `AnimatedValue`. It also exposes some extra style properties like
57
- * translateX, translateY, rotateX, rotateY, scaleX, etc.
58
- */
59
- var AnimatedImage = reMotion.makeAnimatedComponent('img');
60
-
61
- /**
62
- * `useMountedValue` handles mounting and unmounting of a component which captures current state
63
- * passed as an arugment (`state`) and exposes the shadow state which handles the mount and unmount
64
- * of a component.
65
- *
66
- * @param { boolean } state - Boolean indicating the component should mount or unmount.
67
- * @param { UseMountedValueConfig } config - Animation configuration.
68
- */
69
- function useMountedValue(state, config) {
70
- var mv = reMotion.useMount(state, config);
71
- return function (cb) { return mv(function (a, m) { return cb({ value: a }, m); }); };
72
- }
73
-
74
- /**
75
- * MountedBlock - Higher order component which handles mounting and unmounting of a component.
76
- * @prop { boolean } state - Boolean indicating the component should mount or unmount.
77
- * @prop { function } children - Child as a function with `AnimatedValue` on `.value` property.
78
- * @prop { UseMountedValueConfig } config - Animation configuration.
79
- */
80
- var MountedBlock = function (_a) {
81
- var state = _a.state, children = _a.children, config = _a.config;
82
- var open = useMountedValue(state, config);
83
- return React.createElement(React.Fragment, null, open(function (animation, mounted) { return mounted && children(animation); }));
84
- };
85
-
86
- /*! *****************************************************************************
23
+ /******************************************************************************
87
24
  Copyright (c) Microsoft Corporation.
88
25
 
89
26
  Permission to use, copy, modify, and/or distribute this software for any
@@ -97,7 +34,7 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
97
34
  OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
98
35
  PERFORMANCE OF THIS SOFTWARE.
99
36
  ***************************************************************************** */
100
- /* global Reflect, Promise */
37
+ /* global Reflect, Promise, SuppressedError, Symbol */
101
38
 
102
39
  var extendStatics = function(d, b) {
103
40
  extendStatics = Object.setPrototypeOf ||
@@ -107,6 +44,8 @@ var extendStatics = function(d, b) {
107
44
  };
108
45
 
109
46
  function __extends(d, b) {
47
+ if (typeof b !== "function" && b !== null)
48
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
110
49
  extendStatics(d, b);
111
50
  function __() { this.constructor = d; }
112
51
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
@@ -123,6 +62,18 @@ var __assign = function() {
123
62
  return __assign.apply(this, arguments);
124
63
  };
125
64
 
65
+ function __rest(s, e) {
66
+ var t = {};
67
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
68
+ t[p] = s[p];
69
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
70
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
71
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
72
+ t[p[i]] = s[p[i]];
73
+ }
74
+ return t;
75
+ }
76
+
126
77
  function __values(o) {
127
78
  var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
128
79
  if (m) return m.call(o);
@@ -152,1021 +103,2774 @@ function __read(o, n) {
152
103
  return ar;
153
104
  }
154
105
 
155
- function __spread() {
156
- for (var ar = [], i = 0; i < arguments.length; i++)
157
- ar = ar.concat(__read(arguments[i]));
158
- return ar;
159
- }
160
-
161
- var getInitialConfig = function (animationType) {
162
- switch (animationType) {
163
- case 'elastic':
164
- return { mass: 1, friction: 18, tension: 250 };
165
- case 'stiff':
166
- return { mass: 1, friction: 18, tension: 350 };
167
- case 'wooble':
168
- return { mass: 1, friction: 8, tension: 250 };
169
- case 'bounce':
170
- return { duration: 500, easing: reMotion.Easing.bounce };
171
- case 'power1':
172
- return { duration: 500, easing: reMotion.Easing.bezier(0.17, 0.42, 0.51, 0.97) };
173
- case 'power2':
174
- return { duration: 500, easing: reMotion.Easing.bezier(0.07, 0.11, 0.13, 1) };
175
- case 'power3':
176
- return { duration: 500, easing: reMotion.Easing.bezier(0.09, 0.7, 0.16, 1.04) };
177
- case 'power4':
178
- return { duration: 500, easing: reMotion.Easing.bezier(0.05, 0.54, 0, 1.03) };
179
- case 'linear':
180
- return { duration: 500, easing: reMotion.Easing.linear };
181
- case 'easein':
182
- return { duration: 500, easing: reMotion.Easing.in(reMotion.Easing.ease) };
183
- case 'easeout':
184
- return { duration: 500, easing: reMotion.Easing.out(reMotion.Easing.ease) };
185
- case 'easeinout':
186
- return { duration: 500, easing: reMotion.Easing.inOut(reMotion.Easing.ease) };
187
- case 'ease':
188
- default:
189
- return { mass: 1, friction: 34, tension: 290 };
106
+ function __spreadArray(to, from, pack) {
107
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
108
+ if (ar || !(i in from)) {
109
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
110
+ ar[i] = from[i];
111
+ }
190
112
  }
113
+ return to.concat(ar || Array.prototype.slice.call(from));
114
+ }
115
+
116
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
117
+ var e = new Error(message);
118
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
191
119
  };
192
120
 
193
- var AnimationConfigUtils = {
194
- ELASTIC: getInitialConfig('elastic'),
195
- BOUNCE: getInitialConfig('bounce'),
196
- EASE: getInitialConfig('ease'),
197
- STIFF: getInitialConfig('stiff'),
198
- WOOBLE: getInitialConfig('wooble'),
199
- EASE_IN: getInitialConfig('easein'),
200
- EASE_OUT: getInitialConfig('easeout'),
201
- EASE_IN_OUT: getInitialConfig('easeinout'),
202
- POWER1: getInitialConfig('power1'),
203
- POWER2: getInitialConfig('power2'),
204
- POWER3: getInitialConfig('power3'),
205
- POWER4: getInitialConfig('power4'),
206
- LINEAR: getInitialConfig('linear'),
121
+ /**
122
+ * Base Animation class
123
+ */
124
+ var Animation = /** @class */ (function () {
125
+ function Animation() {
126
+ }
127
+ Animation.prototype._debounceOnEnd = function (result) {
128
+ var onEnd = this._onEnd;
129
+ var onRest = this._onRest;
130
+ this._onEnd = null;
131
+ this._onRest = null;
132
+ onRest && onRest(result);
133
+ onEnd && onEnd(result);
134
+ };
135
+ Animation.prototype.stop = function () { };
136
+ return Animation;
137
+ }());
138
+
139
+ var RequestAnimationFrame = {
140
+ current: function (cb) { return window.requestAnimationFrame(cb); },
141
+ inject: function (injected) {
142
+ RequestAnimationFrame.current = injected;
143
+ },
144
+ };
145
+ var CancelAnimationFrame = {
146
+ current: function (id) { return window.cancelAnimationFrame(id); },
147
+ inject: function (injected) {
148
+ CancelAnimationFrame.current = injected;
149
+ },
207
150
  };
208
151
 
209
- /**
210
- * `useAnimatedValue` returns an animation value with `.value` and `.currentValue` property which is
211
- * initialized when passed to argument (`initialValue`). The retured value persist until the lifetime of
212
- * a component. It doesnot cast any re-renders which can is very good for performance optimization.
213
- *
214
- * @param { string | number } initialValue - Initial value
215
- * @param { UseAnimatedValueConfig } config - Animation configuration object.
216
- */
217
- function useAnimatedValue(initialValue, config) {
218
- var _a = __read(reMotion.useTransition(initialValue, __assign(__assign({}, AnimationConfigUtils.EASE), config)), 2), animation = _a[0], setAnimation = _a[1];
219
- var targetObject = {
220
- value: animation,
221
- currentValue: animation.get(),
222
- };
223
- return new Proxy(targetObject, {
224
- set: function (_, key, value) {
225
- if (key === 'value') {
226
- if (typeof value === 'number' || typeof value === 'string') {
227
- setAnimation({ toValue: value });
228
- }
229
- else if (typeof value === 'object' || typeof value === 'function') {
230
- setAnimation(value);
231
- }
232
- return true;
233
- }
234
- throw new Error('You cannot set any other property to animation node.');
235
- },
236
- get: function (_, key) {
237
- if (key === 'value') {
238
- return animation;
239
- }
240
- if (key === 'currentValue') {
241
- return animation.get();
242
- }
243
- throw new Error('You cannot access any other property from animation node.');
244
- },
245
- });
152
+ /**
153
+ * Class implementing spring based animation
154
+ */
155
+ var SpringAnimation = /** @class */ (function (_super) {
156
+ __extends(SpringAnimation, _super);
157
+ function SpringAnimation(_a) {
158
+ var initialPosition = _a.initialPosition, config = _a.config;
159
+ var _b, _c, _d, _e, _f, _g;
160
+ var _this = _super.call(this) || this;
161
+ _this._overshootClamping = false;
162
+ _this._initialVelocity = 0;
163
+ _this._lastVelocity = 0;
164
+ _this._startPosition = initialPosition;
165
+ _this._position = _this._startPosition;
166
+ _this._restDisplacementThreshold = (_b = config === null || config === void 0 ? void 0 : config.restDistance) !== null && _b !== void 0 ? _b : 0.001;
167
+ _this._restSpeedThreshold = (_c = config === null || config === void 0 ? void 0 : config.restDistance) !== null && _c !== void 0 ? _c : 0.001;
168
+ _this._mass = (_d = config === null || config === void 0 ? void 0 : config.mass) !== null && _d !== void 0 ? _d : 1;
169
+ _this._tension = (_e = config === null || config === void 0 ? void 0 : config.tension) !== null && _e !== void 0 ? _e : 170;
170
+ _this._friction = (_f = config === null || config === void 0 ? void 0 : config.friction) !== null && _f !== void 0 ? _f : 26;
171
+ _this._delay = (_g = config === null || config === void 0 ? void 0 : config.delay) !== null && _g !== void 0 ? _g : 0;
172
+ _this._onRest = config === null || config === void 0 ? void 0 : config.onRest;
173
+ _this._onChange = config === null || config === void 0 ? void 0 : config.onChange;
174
+ return _this;
175
+ }
176
+ SpringAnimation.prototype.onChange = function (value) {
177
+ this._onFrame(value);
178
+ if (this._lastPosition !== value) {
179
+ if (this._onChange) {
180
+ this._onChange(value);
181
+ }
182
+ }
183
+ this._lastPosition = value;
184
+ };
185
+ SpringAnimation.prototype.onUpdate = function () {
186
+ var _this = this;
187
+ var now = Date.now();
188
+ var deltaTime = Math.min(now - this._lastTime, 64);
189
+ this._lastTime = now;
190
+ var c = this._friction;
191
+ var m = this._mass;
192
+ var k = this._tension;
193
+ var v0 = -this._lastVelocity;
194
+ var x0 = this._toValue - this._position;
195
+ var zeta = c / (2 * Math.sqrt(k * m)); // damping ratio
196
+ var omega0 = Math.sqrt(k / m); // undamped angular frequency of the oscillator (rad/ms)
197
+ var omega1 = omega0 * Math.sqrt(1 - Math.pow(zeta, 2)); // exponential decay
198
+ var t = deltaTime / 1000;
199
+ var sin1 = Math.sin(omega1 * t);
200
+ var cos1 = Math.cos(omega1 * t);
201
+ // under damped
202
+ var underDampedEnvelope = Math.exp(-zeta * omega0 * t);
203
+ var underDampedFrag1 = underDampedEnvelope *
204
+ (sin1 * ((v0 + zeta * omega0 * x0) / omega1) + x0 * cos1);
205
+ var underDampedPosition = this._toValue - underDampedFrag1;
206
+ // This looks crazy -- it's actually just the derivative of the oscillation function
207
+ var underDampedVelocity = zeta * omega0 * underDampedFrag1 -
208
+ underDampedEnvelope *
209
+ (cos1 * (v0 + zeta * omega0 * x0) - omega1 * x0 * sin1);
210
+ // critically damped
211
+ var criticallyDampedEnvelope = Math.exp(-omega0 * t);
212
+ var criticallyDampedPosition = this._toValue - criticallyDampedEnvelope * (x0 + (v0 + omega0 * x0) * t);
213
+ var criticallyDampedVelocity = criticallyDampedEnvelope *
214
+ (v0 * (t * omega0 - 1) + t * x0 * omega0 * omega0);
215
+ this.onChange(this._position);
216
+ var isOvershooting = function () {
217
+ if (_this._overshootClamping && _this._tension !== 0) {
218
+ return _this._position < _this._toValue
219
+ ? _this._position > _this._toValue
220
+ : _this._position < _this._toValue;
221
+ }
222
+ else {
223
+ return false;
224
+ }
225
+ };
226
+ var isVelocity = Math.abs(this._lastVelocity) < this._restSpeedThreshold;
227
+ var isDisplacement = this._tension === 0 ||
228
+ Math.abs(this._toValue - this._position) <
229
+ this._restDisplacementThreshold;
230
+ if (zeta < 1) {
231
+ this._position = underDampedPosition;
232
+ this._lastVelocity = underDampedVelocity;
233
+ }
234
+ else {
235
+ this._position = criticallyDampedPosition;
236
+ this._lastVelocity = criticallyDampedVelocity;
237
+ }
238
+ if (isOvershooting() || (isVelocity && isDisplacement)) {
239
+ if (this._tension !== 0) {
240
+ this._lastVelocity = 0;
241
+ this._position = this._toValue;
242
+ this.onChange(this._position);
243
+ }
244
+ // clear lastTimestamp to avoid using stale value by the next spring animation that starts after this one
245
+ this._lastTime = 0;
246
+ this._debounceOnEnd({ finished: true, value: this._toValue });
247
+ return;
248
+ }
249
+ this._animationFrame = RequestAnimationFrame.current(this.onUpdate.bind(this));
250
+ };
251
+ SpringAnimation.prototype.stop = function () {
252
+ this._active = false;
253
+ clearTimeout(this._timeout);
254
+ CancelAnimationFrame.current(this._animationFrame);
255
+ this._debounceOnEnd({ finished: false, value: this._position });
256
+ };
257
+ // Set value
258
+ SpringAnimation.prototype.set = function (toValue) {
259
+ this.stop();
260
+ this._position = toValue;
261
+ this._lastTime = 0;
262
+ this._lastVelocity = 0;
263
+ this.onChange(toValue);
264
+ };
265
+ SpringAnimation.prototype.start = function (_a) {
266
+ var _this = this;
267
+ var toValue = _a.toValue, onFrame = _a.onFrame, previousAnimation = _a.previousAnimation, onEnd = _a.onEnd;
268
+ var onStart = function () {
269
+ _this._onFrame = onFrame;
270
+ _this._active = true;
271
+ _this._toValue = toValue;
272
+ _this._onEnd = onEnd;
273
+ var now = Date.now();
274
+ if (previousAnimation instanceof SpringAnimation) {
275
+ _this._lastVelocity =
276
+ previousAnimation._lastVelocity || _this._lastVelocity || 0;
277
+ _this._lastTime = previousAnimation._lastTime || now;
278
+ }
279
+ else {
280
+ _this._lastTime = now;
281
+ }
282
+ _this._animationFrame = RequestAnimationFrame.current(_this.onUpdate.bind(_this));
283
+ };
284
+ if (this._delay !== 0) {
285
+ this._timeout = setTimeout(function () { return onStart(); }, this._delay);
286
+ }
287
+ else {
288
+ onStart();
289
+ }
290
+ };
291
+ return SpringAnimation;
292
+ }(Animation));
293
+
294
+ /**
295
+ * https://github.com/gre/bezier-easing
296
+ * BezierEasing - use bezier curve for transition easing function
297
+ * by Gaëtan Renaudeau 2014 - 2015 – MIT License
298
+ */
299
+ // These values are established by empiricism with tests (tradeoff: performance VS precision)
300
+ var NEWTON_ITERATIONS = 4;
301
+ var NEWTON_MIN_SLOPE = 0.001;
302
+ var SUBDIVISION_PRECISION = 0.0000001;
303
+ var SUBDIVISION_MAX_ITERATIONS = 10;
304
+ var kSplineTableSize = 11;
305
+ var kSampleStepSize = 1.0 / (kSplineTableSize - 1.0);
306
+ var float32ArraySupported = typeof Float32Array === "function";
307
+ function A(aA1, aA2) {
308
+ return 1.0 - 3.0 * aA2 + 3.0 * aA1;
309
+ }
310
+ function B(aA1, aA2) {
311
+ return 3.0 * aA2 - 6.0 * aA1;
312
+ }
313
+ function C(aA1) {
314
+ return 3.0 * aA1;
315
+ }
316
+ // Returns x(t) given t, x1, and x2, or y(t) given t, y1, and y2.
317
+ function calcBezier(aT, aA1, aA2) {
318
+ return ((A(aA1, aA2) * aT + B(aA1, aA2)) * aT + C(aA1)) * aT;
319
+ }
320
+ // Returns dx/dt given t, x1, and x2, or dy/dt given t, y1, and y2.
321
+ function getSlope(aT, aA1, aA2) {
322
+ return 3.0 * A(aA1, aA2) * aT * aT + 2.0 * B(aA1, aA2) * aT + C(aA1);
323
+ }
324
+ function binarySubdivide(aX, aA, aB, mX1, mX2) {
325
+ var currentX, currentT, i = 0;
326
+ do {
327
+ currentT = aA + (aB - aA) / 2.0;
328
+ currentX = calcBezier(currentT, mX1, mX2) - aX;
329
+ if (currentX > 0.0) {
330
+ aB = currentT;
331
+ }
332
+ else {
333
+ aA = currentT;
334
+ }
335
+ } while (Math.abs(currentX) > SUBDIVISION_PRECISION &&
336
+ ++i < SUBDIVISION_MAX_ITERATIONS);
337
+ return currentT;
338
+ }
339
+ function newtonRaphsonIterate(aX, aGuessT, mX1, mX2) {
340
+ for (var i = 0; i < NEWTON_ITERATIONS; ++i) {
341
+ var currentSlope = getSlope(aGuessT, mX1, mX2);
342
+ if (currentSlope === 0.0) {
343
+ return aGuessT;
344
+ }
345
+ var currentX = calcBezier(aGuessT, mX1, mX2) - aX;
346
+ aGuessT -= currentX / currentSlope;
347
+ }
348
+ return aGuessT;
349
+ }
350
+ function LinearEasing(x) {
351
+ return x;
352
+ }
353
+ function bezier(mX1, mY1, mX2, mY2) {
354
+ if (!(0 <= mX1 && mX1 <= 1 && 0 <= mX2 && mX2 <= 1)) {
355
+ throw new Error("bezier x values must be in [0, 1] range");
356
+ }
357
+ if (mX1 === mY1 && mX2 === mY2) {
358
+ return LinearEasing;
359
+ }
360
+ // Precompute samples table
361
+ var sampleValues = float32ArraySupported
362
+ ? new Float32Array(kSplineTableSize)
363
+ : new Array(kSplineTableSize);
364
+ for (var i = 0; i < kSplineTableSize; ++i) {
365
+ sampleValues[i] = calcBezier(i * kSampleStepSize, mX1, mX2);
366
+ }
367
+ function getTForX(aX) {
368
+ var intervalStart = 0.0;
369
+ var currentSample = 1;
370
+ var lastSample = kSplineTableSize - 1;
371
+ for (; currentSample !== lastSample && sampleValues[currentSample] <= aX; ++currentSample) {
372
+ intervalStart += kSampleStepSize;
373
+ }
374
+ --currentSample;
375
+ // Interpolate to provide an initial guess for t
376
+ var dist = (aX - sampleValues[currentSample]) /
377
+ (sampleValues[currentSample + 1] - sampleValues[currentSample]);
378
+ var guessForT = intervalStart + dist * kSampleStepSize;
379
+ var initialSlope = getSlope(guessForT, mX1, mX2);
380
+ if (initialSlope >= NEWTON_MIN_SLOPE) {
381
+ return newtonRaphsonIterate(aX, guessForT, mX1, mX2);
382
+ }
383
+ else if (initialSlope === 0.0) {
384
+ return guessForT;
385
+ }
386
+ else {
387
+ return binarySubdivide(aX, intervalStart, intervalStart + kSampleStepSize, mX1, mX2);
388
+ }
389
+ }
390
+ return function BezierEasing(x) {
391
+ // Because JavaScript number are imprecise, we should guarantee the extremes are right.
392
+ if (x === 0 || x === 1) {
393
+ return x;
394
+ }
395
+ return calcBezier(getTForX(x), mY1, mY2);
396
+ };
246
397
  }
247
398
 
248
- /**
249
- * ScrollableBlock - Higher order component to handle the entrance or exit animation
250
- * of a component when it enters or exit the viewport. Accepts child as a function with
251
- * `AnimatedValue` as its first argument which can be interpolated on input range [0, 1]
252
- * @prop { function } children - child as a function with `AnimatedValue` as its first argument.
253
- * @prop { 'single' | 'both' } direction - single applies animation on enter once, both applies on enter and exit.
254
- * @prop { number } threshold - should be in range 0 to 1 which equivalent to `IntersectionObserver` threshold.
255
- * @prop { UseAnimatedValueConfig } animationConfig - Animation config
256
- */
257
- var ScrollableBlock = function (props) {
258
- var children = props.children, _a = props.direction, direction = _a === void 0 ? 'single' : _a, animationConfig = props.animationConfig, _b = props.threshold, threshold = _b === void 0 ? 0.2 : _b;
259
- var scrollableBlockRef = React.useRef(null);
260
- var animation = useAnimatedValue(0, animationConfig); // 0: not intersecting | 1: intersecting
261
- React.useEffect(function () {
262
- var _scrollableBlock = scrollableBlockRef.current;
263
- var observer = new IntersectionObserver(function (_a) {
264
- var _b = __read(_a, 1), entry = _b[0];
265
- var isIntersecting = entry.isIntersecting;
266
- if (isIntersecting) {
267
- animation.value = 1;
268
- }
269
- else {
270
- if (direction === 'both')
271
- animation.value = 0;
272
- }
273
- }, {
274
- root: null,
275
- threshold: threshold,
276
- });
277
- if (_scrollableBlock) {
278
- observer.observe(_scrollableBlock);
279
- }
280
- return function () {
281
- if (_scrollableBlock) {
282
- observer.unobserve(_scrollableBlock);
283
- }
284
- };
285
- }, []);
286
- return (React.createElement("div", { ref: scrollableBlockRef }, children && children({ value: animation.value })));
399
+ /**
400
+ * Copyright (c) 2015-present, Facebook, Inc.
401
+ * All rights reserved.
402
+ *
403
+ * This source code is licensed under the MIT license found in the
404
+ * LICENSE file in the root directory of this source tree.
405
+ *
406
+ */
407
+ /**
408
+ * This class implements common easing functions. The math is pretty obscure,
409
+ * but this cool website has nice visual illustrations of what they represent:
410
+ * http://xaedes.de/dev/transitions/
411
+ */
412
+ var Easing = /** @class */ (function () {
413
+ function Easing() {
414
+ }
415
+ Easing.step0 = function (n) {
416
+ return n > 0 ? 1 : 0;
417
+ };
418
+ Easing.step1 = function (n) {
419
+ return n >= 1 ? 1 : 0;
420
+ };
421
+ Easing.linear = function (t) {
422
+ return t;
423
+ };
424
+ Easing.ease = function (t) {
425
+ return ease(t);
426
+ };
427
+ Easing.quad = function (t) {
428
+ return t * t;
429
+ };
430
+ Easing.cubic = function (t) {
431
+ return t * t * t;
432
+ };
433
+ Easing.poly = function (n) {
434
+ return function (t) { return Math.pow(t, n); };
435
+ };
436
+ Easing.sin = function (t) {
437
+ return 1 - Math.cos((t * Math.PI) / 2);
438
+ };
439
+ Easing.circle = function (t) {
440
+ return 1 - Math.sqrt(1 - t * t);
441
+ };
442
+ Easing.exp = function (t) {
443
+ return Math.pow(2, 10 * (t - 1));
444
+ };
445
+ /**
446
+ * A simple elastic interaction, similar to a spring. Default bounciness
447
+ * is 1, which overshoots a little bit once. 0 bounciness doesn't overshoot
448
+ * at all, and bounciness of N > 1 will overshoot about N times.
449
+ *
450
+ * Wolfram Plots:
451
+ *
452
+ * http://tiny.cc/elastic_b_1 (default bounciness = 1)
453
+ * http://tiny.cc/elastic_b_3 (bounciness = 3)
454
+ */
455
+ Easing.elastic = function (bounciness) {
456
+ if (bounciness === void 0) { bounciness = 1; }
457
+ var p = bounciness * Math.PI;
458
+ return function (t) {
459
+ return 1 - Math.pow(Math.cos((t * Math.PI) / 2), 3) * Math.cos(t * p);
460
+ };
461
+ };
462
+ Easing.back = function (s) {
463
+ if (s === undefined) {
464
+ s = 1.70158;
465
+ }
466
+ return function (t) { return t * t * ((s + 1) * t - s); };
467
+ };
468
+ Easing.bounce = function (t) {
469
+ if (t < 1 / 2.75) {
470
+ return 7.5625 * t * t;
471
+ }
472
+ if (t < 2 / 2.75) {
473
+ t -= 1.5 / 2.75;
474
+ return 7.5625 * t * t + 0.75;
475
+ }
476
+ if (t < 2.5 / 2.75) {
477
+ t -= 2.25 / 2.75;
478
+ return 7.5625 * t * t + 0.9375;
479
+ }
480
+ t -= 2.625 / 2.75;
481
+ return 7.5625 * t * t + 0.984375;
482
+ };
483
+ Easing.bezier = function (x1, y1, x2, y2) {
484
+ return bezier(x1, y1, x2, y2);
485
+ };
486
+ Easing.in = function (easing) {
487
+ return easing;
488
+ };
489
+ /**
490
+ * Runs an easing function backwards.
491
+ */
492
+ Easing.out = function (easing) {
493
+ return function (t) { return 1 - easing(1 - t); };
494
+ };
495
+ /**
496
+ * Makes any easing function symmetrical.
497
+ */
498
+ Easing.inOut = function (easing) {
499
+ return function (t) {
500
+ if (t < 0.5) {
501
+ return easing(t * 2) / 2;
502
+ }
503
+ return 1 - easing((1 - t) * 2) / 2;
504
+ };
505
+ };
506
+ return Easing;
507
+ }());
508
+ var ease = Easing.bezier(0.42, 0, 1, 1);
509
+
510
+ /**
511
+ * Class implementing timing based animation
512
+ */
513
+ var TimingAnimation = /** @class */ (function (_super) {
514
+ __extends(TimingAnimation, _super);
515
+ function TimingAnimation(_a) {
516
+ var initialPosition = _a.initialPosition, config = _a.config;
517
+ var _b, _c, _d;
518
+ var _this = _super.call(this) || this;
519
+ _this._fromValue = initialPosition;
520
+ _this._position = _this._fromValue;
521
+ _this._easing = (_b = config === null || config === void 0 ? void 0 : config.easing) !== null && _b !== void 0 ? _b : Easing.linear;
522
+ _this._duration = (_c = config === null || config === void 0 ? void 0 : config.duration) !== null && _c !== void 0 ? _c : 500;
523
+ _this._tempDuration = _this._duration;
524
+ // Modifiers
525
+ // here immediate acts like duration: 0
526
+ if (config === null || config === void 0 ? void 0 : config.immediate) {
527
+ _this._duration = 0;
528
+ }
529
+ _this._delay = (_d = config === null || config === void 0 ? void 0 : config.delay) !== null && _d !== void 0 ? _d : 0;
530
+ _this._onRest = config === null || config === void 0 ? void 0 : config.onRest;
531
+ _this._onChange = config === null || config === void 0 ? void 0 : config.onChange;
532
+ return _this;
533
+ }
534
+ TimingAnimation.prototype.onChange = function (value) {
535
+ this._onFrame(value);
536
+ if (this._lastPosition !== value) {
537
+ if (this._onChange) {
538
+ this._onChange(value);
539
+ }
540
+ }
541
+ this._lastPosition = value;
542
+ };
543
+ TimingAnimation.prototype.onUpdate = function () {
544
+ var now = Date.now();
545
+ var runTime = now - this._startTime;
546
+ if (runTime >= this._duration) {
547
+ this._startTime = 0;
548
+ this._position = this._toValue;
549
+ this.onChange(this._position);
550
+ this._debounceOnEnd({ finished: true, value: this._position });
551
+ return;
552
+ }
553
+ var progress = this._easing(runTime / this._duration);
554
+ this._position =
555
+ this._fromValue + (this._toValue - this._fromValue) * progress;
556
+ this.onChange(this._position);
557
+ this._animationFrame = RequestAnimationFrame.current(this.onUpdate.bind(this));
558
+ };
559
+ TimingAnimation.prototype.stop = function () {
560
+ this._active = false;
561
+ clearTimeout(this._timeout);
562
+ CancelAnimationFrame.current(this._animationFrame);
563
+ this._debounceOnEnd({ finished: false, value: this._position });
564
+ };
565
+ // Set value
566
+ TimingAnimation.prototype.set = function (toValue) {
567
+ this.stop();
568
+ this._position = toValue;
569
+ this.onChange(toValue);
570
+ };
571
+ TimingAnimation.prototype.start = function (_a) {
572
+ var _this = this;
573
+ var toValue = _a.toValue, onFrame = _a.onFrame, previousAnimation = _a.previousAnimation, onEnd = _a.onEnd;
574
+ var onStart = function () {
575
+ _this._onFrame = onFrame;
576
+ _this._active = true;
577
+ _this._onEnd = onEnd;
578
+ _this._toValue = toValue;
579
+ if (previousAnimation &&
580
+ previousAnimation instanceof TimingAnimation &&
581
+ previousAnimation._toValue === toValue &&
582
+ previousAnimation._startTime) {
583
+ _this._startTime = previousAnimation._startTime;
584
+ _this._fromValue = previousAnimation._fromValue;
585
+ }
586
+ else {
587
+ var now = Date.now();
588
+ _this._startTime = now;
589
+ _this._fromValue = _this._position;
590
+ }
591
+ _this._animationFrame = RequestAnimationFrame.current(_this.onUpdate.bind(_this));
592
+ };
593
+ if (this._delay !== 0) {
594
+ this._timeout = setTimeout(function () { return onStart(); }, this._delay);
595
+ }
596
+ else {
597
+ onStart();
598
+ }
599
+ };
600
+ return TimingAnimation;
601
+ }(Animation));
602
+
603
+ var COLOR_NUMBER_REGEX = /[+-]?\d+(\.\d+)?|[\s]?\.\d+|#([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})/gi;
604
+ var HEX_NAME_COLOR = /#[a-f\d]{3,}|transparent|aliceblue|antiquewhite|aqua|aquamarine|azure|beige|bisque|black|blanchedalmond|blue|blueviolet|brown|burlywood|burntsienna|cadetblue|chartreuse|chocolate|coral|cornflowerblue|cornsilk|crimson|cyan|darkblue|darkcyan|darkgoldenrod|darkgray|darkgreen|darkgrey|darkkhaki|darkmagenta|darkolivegreen|darkorange|darkorchid|darkred|darksalmon|darkseagreen|darkslateblue|darkslategray|darkslategrey|darkturquoise|darkviolet|deeppink|deepskyblue|dimgray|dimgrey|dodgerblue|firebrick|floralwhite|forestgreen|fuchsia|gainsboro|ghostwhite|gold|goldenrod|gray|green|greenyellow|grey|honeydew|hotpink|indianred|indigo|ivory|khaki|lavender|lavenderblush|lawngreen|lemonchiffon|lightblue|lightcoral|lightcyan|lightgoldenrodyellow|lightgray|lightgreen|lightgrey|lightpink|lightsalmon|lightseagreen|lightskyblue|lightslategray|lightslategrey|lightsteelblue|lightyellow|lime|limegreen|linen|magenta|maroon|mediumaquamarine|mediumblue|mediumorchid|mediumpurple|mediumseagreen|mediumslateblue|mediumspringgreen|mediumturquoise|mediumvioletred|midnightblue|mintcream|mistyrose|moccasin|navajowhite|navy|oldlace|olive|olivedrab|orange|orangered|orchid|palegoldenrod|palegreen|paleturquoise|palevioletred|papayawhip|peachpuff|peru|pink|plum|powderblue|purple|rebeccapurple|red|rosybrown|royalblue|saddlebrown|salmon|sandybrown|seagreen|seashell|sienna|silver|skyblue|slateblue|slategray|slategrey|snow|springgreen|steelblue|tan|teal|thistle|tomato|turquoise|violet|wheat|white|whitesmoke|yellow|yellowgreen/gi;
605
+ // Named colors
606
+ var colorNames = {
607
+ transparent: "#00000000",
608
+ aliceblue: "#f0f8ffff",
609
+ antiquewhite: "#faebd7ff",
610
+ aqua: "#00ffffff",
611
+ aquamarine: "#7fffd4ff",
612
+ azure: "#f0ffffff",
613
+ beige: "#f5f5dcff",
614
+ bisque: "#ffe4c4ff",
615
+ black: "#000000ff",
616
+ blanchedalmond: "#ffebcdff",
617
+ blue: "#0000ffff",
618
+ blueviolet: "#8a2be2ff",
619
+ brown: "#a52a2aff",
620
+ burlywood: "#deb887ff",
621
+ burntsienna: "#ea7e5dff",
622
+ cadetblue: "#5f9ea0ff",
623
+ chartreuse: "#7fff00ff",
624
+ chocolate: "#d2691eff",
625
+ coral: "#ff7f50ff",
626
+ cornflowerblue: "#6495edff",
627
+ cornsilk: "#fff8dcff",
628
+ crimson: "#dc143cff",
629
+ cyan: "#00ffffff",
630
+ darkblue: "#00008bff",
631
+ darkcyan: "#008b8bff",
632
+ darkgoldenrod: "#b8860bff",
633
+ darkgray: "#a9a9a9ff",
634
+ darkgreen: "#006400ff",
635
+ darkgrey: "#a9a9a9ff",
636
+ darkkhaki: "#bdb76bff",
637
+ darkmagenta: "#8b008bff",
638
+ darkolivegreen: "#556b2fff",
639
+ darkorange: "#ff8c00ff",
640
+ darkorchid: "#9932ccff",
641
+ darkred: "#8b0000ff",
642
+ darksalmon: "#e9967aff",
643
+ darkseagreen: "#8fbc8fff",
644
+ darkslateblue: "#483d8bff",
645
+ darkslategray: "#2f4f4fff",
646
+ darkslategrey: "#2f4f4fff",
647
+ darkturquoise: "#00ced1ff",
648
+ darkviolet: "#9400d3ff",
649
+ deeppink: "#ff1493ff",
650
+ deepskyblue: "#00bfffff",
651
+ dimgray: "#696969ff",
652
+ dimgrey: "#696969ff",
653
+ dodgerblue: "#1e90ffff",
654
+ firebrick: "#b22222ff",
655
+ floralwhite: "#fffaf0ff",
656
+ forestgreen: "#228b22ff",
657
+ fuchsia: "#ff00ffff",
658
+ gainsboro: "#dcdcdcff",
659
+ ghostwhite: "#f8f8ffff",
660
+ gold: "#ffd700ff",
661
+ goldenrod: "#daa520ff",
662
+ gray: "#808080ff",
663
+ green: "#008000ff",
664
+ greenyellow: "#adff2fff",
665
+ grey: "#808080ff",
666
+ honeydew: "#f0fff0ff",
667
+ hotpink: "#ff69b4ff",
668
+ indianred: "#cd5c5cff",
669
+ indigo: "#4b0082ff",
670
+ ivory: "#fffff0ff",
671
+ khaki: "#f0e68cff",
672
+ lavender: "#e6e6faff",
673
+ lavenderblush: "#fff0f5ff",
674
+ lawngreen: "#7cfc00ff",
675
+ lemonchiffon: "#fffacdff",
676
+ lightblue: "#add8e6ff",
677
+ lightcoral: "#f08080ff",
678
+ lightcyan: "#e0ffffff",
679
+ lightgoldenrodyellow: "#fafad2ff",
680
+ lightgray: "#d3d3d3ff",
681
+ lightgreen: "#90ee90ff",
682
+ lightgrey: "#d3d3d3ff",
683
+ lightpink: "#ffb6c1ff",
684
+ lightsalmon: "#ffa07aff",
685
+ lightseagreen: "#20b2aaff",
686
+ lightskyblue: "#87cefaff",
687
+ lightslategray: "#778899ff",
688
+ lightslategrey: "#778899ff",
689
+ lightsteelblue: "#b0c4deff",
690
+ lightyellow: "#ffffe0ff",
691
+ lime: "#00ff00ff",
692
+ limegreen: "#32cd32ff",
693
+ linen: "#faf0e6ff",
694
+ magenta: "#ff00ffff",
695
+ maroon: "#800000ff",
696
+ mediumaquamarine: "#66cdaaff",
697
+ mediumblue: "#0000cdff",
698
+ mediumorchid: "#ba55d3ff",
699
+ mediumpurple: "#9370dbff",
700
+ mediumseagreen: "#3cb371ff",
701
+ mediumslateblue: "#7b68eeff",
702
+ mediumspringgreen: "#00fa9aff",
703
+ mediumturquoise: "#48d1ccff",
704
+ mediumvioletred: "#c71585ff",
705
+ midnightblue: "#191970ff",
706
+ mintcream: "#f5fffaff",
707
+ mistyrose: "#ffe4e1ff",
708
+ moccasin: "#ffe4b5ff",
709
+ navajowhite: "#ffdeadff",
710
+ navy: "#000080ff",
711
+ oldlace: "#fdf5e6ff",
712
+ olive: "#808000ff",
713
+ olivedrab: "#6b8e23ff",
714
+ orange: "#ffa500ff",
715
+ orangered: "#ff4500ff",
716
+ orchid: "#da70d6ff",
717
+ palegoldenrod: "#eee8aaff",
718
+ palegreen: "#98fb98ff",
719
+ paleturquoise: "#afeeeeff",
720
+ palevioletred: "#db7093ff",
721
+ papayawhip: "#ffefd5ff",
722
+ peachpuff: "#ffdab9ff",
723
+ peru: "#cd853fff",
724
+ pink: "#ffc0cbff",
725
+ plum: "#dda0ddff",
726
+ powderblue: "#b0e0e6ff",
727
+ purple: "#800080ff",
728
+ rebeccapurple: "#663399ff",
729
+ red: "#ff0000ff",
730
+ rosybrown: "#bc8f8fff",
731
+ royalblue: "#4169e1ff",
732
+ saddlebrown: "#8b4513ff",
733
+ salmon: "#fa8072ff",
734
+ sandybrown: "#f4a460ff",
735
+ seagreen: "#2e8b57ff",
736
+ seashell: "#fff5eeff",
737
+ sienna: "#a0522dff",
738
+ silver: "#c0c0c0ff",
739
+ skyblue: "#87ceebff",
740
+ slateblue: "#6a5acdff",
741
+ slategray: "#708090ff",
742
+ slategrey: "#708090ff",
743
+ snow: "#fffafaff",
744
+ springgreen: "#00ff7fff",
745
+ steelblue: "#4682b4ff",
746
+ tan: "#d2b48cff",
747
+ teal: "#008080ff",
748
+ thistle: "#d8bfd8ff",
749
+ tomato: "#ff6347ff",
750
+ turquoise: "#40e0d0ff",
751
+ violet: "#ee82eeff",
752
+ wheat: "#f5deb3ff",
753
+ white: "#ffffffff",
754
+ whitesmoke: "#f5f5f5ff",
755
+ yellow: "#ffff00ff",
756
+ yellowgreen: "#9acd32ff",
287
757
  };
758
+ function conv3to6(hex) {
759
+ var regex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;
760
+ return hex.replace(regex, function (_, r, g, b) {
761
+ return "#" + r + r + g + g + b + b;
762
+ });
763
+ }
764
+ function conv6to8(hex) {
765
+ if (hex.length === 7) {
766
+ return hex + "FF";
767
+ }
768
+ return hex;
769
+ }
770
+ function hexToRgba(hex) {
771
+ var hex6 = conv3to6(hex);
772
+ var hex8 = conv6to8(hex6);
773
+ var hexRgba = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex8);
774
+ return {
775
+ r: parseInt(hexRgba[1], 16),
776
+ g: parseInt(hexRgba[2], 16),
777
+ b: parseInt(hexRgba[3], 16),
778
+ a: parseInt(hexRgba[4], 16) / 255,
779
+ };
780
+ }
781
+ function rgbaToHex(rgba) {
782
+ var r = rgba.r, g = rgba.g, b = rgba.b, a = rgba.a;
783
+ var hexR = (r | (1 << 8)).toString(16).slice(1);
784
+ var hexG = (g | (1 << 8)).toString(16).slice(1);
785
+ var hexB = (b | (1 << 8)).toString(16).slice(1);
786
+ var hexA = ((a * 255) | (1 << 8)).toString(16).slice(1);
787
+ return "#" + hexR + hexG + hexB + hexA;
788
+ }
288
789
 
289
- /**
290
- * bin(booleanValue)
291
- * returns 1 if booleanValue == true and 0 if booleanValue == false
292
- */
293
- function bin(bool) {
294
- return bool ? 1 : 0;
295
- }
296
- /**
297
- * mix(progress, a, b)
298
- * linear interpolation between a and b
299
- */
300
- function mix(perc, val1, val2) {
301
- return val1 * (1 - perc) + val2 * perc;
302
- }
303
- /**
304
- * clamp(value, min, max)
305
- * clamps value for min and max bounds
306
- */
307
- function clamp(value, lowerbound, upperbound) {
308
- return Math.min(Math.max(value, lowerbound), upperbound);
309
- }
310
- function rubber2(distanceFromEdge, constant) {
311
- return Math.pow(distanceFromEdge, constant * 5);
312
- }
313
- function rubber(distanceFromEdge, dimension, constant) {
314
- if (dimension === 0 || Math.abs(dimension) === Infinity)
315
- return rubber2(distanceFromEdge, constant);
316
- return ((distanceFromEdge * dimension * constant) /
317
- (dimension + constant * distanceFromEdge));
318
- }
319
- /**
320
- * rubberClamp(value, min, max, constant?)
321
- * constant is optional : default 0.15
322
- * clamps the value for min and max value and
323
- * extends beyond min and max values with constant
324
- * factor to create elastic rubber band effect
325
- */
326
- function rubberClamp(value, lowerbound, upperbound, constant) {
327
- if (constant === void 0) { constant = 0.15; }
328
- if (constant === 0)
329
- return clamp(value, lowerbound, upperbound);
330
- if (value < lowerbound) {
331
- return (-rubber(lowerbound - value, upperbound - lowerbound, constant) +
332
- lowerbound);
333
- }
334
- if (value > upperbound) {
335
- return (+rubber(value - upperbound, upperbound - lowerbound, constant) +
336
- upperbound);
337
- }
338
- return value;
339
- }
340
- /**
341
- * snapTo(value, velocity, snapPoints[])
342
- * Calculates the final snapPoint according to given current value,
343
- * velocity and snapPoints array
344
- */
345
- function snapTo(value, velocity, snapPoints) {
346
- var finalValue = value + velocity * 0.2;
347
- var getDiff = function (point) { return Math.abs(point - finalValue); };
348
- var deltas = snapPoints.map(getDiff);
349
- var minDelta = Math.min.apply(Math, __spread(deltas));
350
- return snapPoints.reduce(function (acc, point) {
351
- if (getDiff(point) === minDelta) {
352
- return point;
353
- }
354
- else {
355
- return acc;
356
- }
357
- });
358
- }
359
- /**
360
- * move(array, moveIndex, toIndex)
361
- * move array item from moveIndex to toIndex without array modification
362
- */
363
- function move(array, moveIndex, toIndex) {
364
- var item = array[moveIndex];
365
- var length = array.length;
366
- var diff = moveIndex - toIndex;
367
- if (diff > 0) {
368
- return __spread(array.slice(0, toIndex), [
369
- item
370
- ], array.slice(toIndex, moveIndex), array.slice(moveIndex + 1, length));
371
- }
372
- else if (diff < 0) {
373
- var targetIndex = toIndex + 1;
374
- return __spread(array.slice(0, moveIndex), array.slice(moveIndex + 1, targetIndex), [
375
- item
376
- ], array.slice(targetIndex, length));
377
- }
378
- return array;
790
+ /**
791
+ * isFluidValue to check the value is FluidValue or not
792
+ * @param value - any
793
+ * @returns - boolean
794
+ */
795
+ var isFluidValue = function (value) {
796
+ return (typeof value === 'object' &&
797
+ Object.prototype.hasOwnProperty.call(value, '_subscribe'));
798
+ };
799
+
800
+ /**
801
+ * Filters out properties with fluid values from a given props object.
802
+ * This function removes any properties that are considered fluid values,
803
+ * typically those that subscribe to updates and therefore should not be
804
+ * included in a static props object.
805
+ *
806
+ * @param props - The original props object, which may include fluid values.
807
+ * @returns A new props object with fluid values removed.
808
+ */
809
+ var getCleanProps = function (_a) {
810
+ _a.style; var props = __rest(_a, ["style"]);
811
+ return Object.fromEntries(Object.entries(props).filter(function (_a) {
812
+ var _b = __read(_a, 2); _b[0]; var value = _b[1];
813
+ return !isFluidValue(value);
814
+ }));
815
+ };
816
+
817
+ var unitlessStyleProps = [
818
+ 'borderImageOutset',
819
+ 'borderImageSlice',
820
+ 'borderImageWidth',
821
+ 'fontWeight',
822
+ 'lineHeight',
823
+ 'opacity',
824
+ 'orphans',
825
+ 'tabSize',
826
+ 'widows',
827
+ 'zIndex',
828
+ 'zoom',
829
+ // SVG-related properties
830
+ 'fillOpacity',
831
+ 'floodOpacity',
832
+ 'stopOpacity',
833
+ 'strokeDasharray',
834
+ 'strokeDashoffset',
835
+ 'strokeMiterlimit',
836
+ 'strokeOpacity',
837
+ 'strokeWidth',
838
+ // prefixed
839
+ 'animationIterationCount',
840
+ 'boxFlex',
841
+ 'boxFlexGroup',
842
+ 'boxOrdinalGroup',
843
+ 'columnCount',
844
+ 'flex',
845
+ 'flexGrow',
846
+ 'flexPositive',
847
+ 'flexShrink',
848
+ 'flexNegative',
849
+ 'flexOrder',
850
+ 'gridRow',
851
+ 'gridColumn',
852
+ 'order',
853
+ 'lineClamp',
854
+ ];
855
+ /**
856
+ * getCssValue() function to get css value with unit or without unit
857
+ * it is only for style property - it cannot be used with transform keys
858
+ * @param property - style property
859
+ * @param value - style value
860
+ * @returns - value with unit or without unit
861
+ */
862
+ function getCssValue(property, value) {
863
+ var cssValue;
864
+ if (typeof value === 'number') {
865
+ if (unitlessStyleProps.includes(property)) {
866
+ cssValue = value;
867
+ }
868
+ else {
869
+ cssValue = value + 'px';
870
+ }
871
+ }
872
+ else {
873
+ cssValue = value;
874
+ }
875
+ return cssValue;
379
876
  }
380
877
 
381
- /**
382
- * TransitionBlock - Higher order component which animates on state change.
383
- * @prop { boolean } state - Boolean indicating the current state of animation, usually `false = 0 and true = 1`.
384
- * @prop { function } children - Child as a function with `AnimatedValue` on `.value` property.
385
- * @prop { UseAnimatedValueConfig } config - Animation configuration.
386
- */
387
- var TransitionBlock = function (_a) {
388
- var state = _a.state, children = _a.children, config = _a.config;
389
- var amv = useAnimatedValue(bin(state), config);
390
- return React.createElement(React.Fragment, null, children({ value: amv.value }));
878
+ /**
879
+ * Checks if a value is defined (not null or undefined).
880
+ *
881
+ * This utility function helps in determining whether a given value is neither `null` nor `undefined`.
882
+ * It can be useful for validation checks to ensure that a value is properly defined before proceeding
883
+ * with further operations.
884
+ *
885
+ * @param {T} value - The value to check.
886
+ * @returns {boolean} - Returns `true` if the value is neither `null` nor `undefined`, otherwise returns `false`.
887
+ *
888
+ */
889
+ var isDefined = function (value) {
890
+ return value !== null && value !== undefined;
391
891
  };
392
892
 
393
- /**
394
- * Attach single document / window event / HTMLElement
395
- */
396
- function attachEvent(domTargets, event, callback, capture) {
397
- if (capture === void 0) { capture = false; }
398
- domTargets.forEach(function (target) {
399
- target.addEventListener(event, callback, capture);
400
- });
401
- return function () {
402
- domTargets.forEach(function (target) {
403
- target.removeEventListener(event, callback, capture);
404
- });
405
- };
406
- }
407
- /**
408
- * Attach multiple document / window event / HTMLElement
409
- */
410
- function attachEvents(domTargets, events) {
411
- var subscribers = new Map();
412
- events.forEach(function (_a) {
413
- var _b = __read(_a, 3), event = _b[0], callback = _b[1], _c = _b[2], capture = _c === void 0 ? false : _c;
414
- subscribers.set(event, attachEvent(domTargets, event, callback, capture));
415
- });
416
- return function (eventKeys) {
417
- var e_1, _a;
418
- try {
419
- for (var _b = __values(subscribers.entries()), _c = _b.next(); !_c.done; _c = _b.next()) {
420
- var _d = __read(_c.value, 2), eventKey = _d[0], subscriber = _d[1];
421
- if (!eventKeys) {
422
- subscriber();
423
- return;
424
- }
425
- if (eventKeys.indexOf(eventKey) !== -1) {
426
- subscriber();
427
- }
428
- }
429
- }
430
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
431
- finally {
432
- try {
433
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
434
- }
435
- finally { if (e_1) throw e_1.error; }
436
- }
437
- };
893
+ /**
894
+ * Converts a camelCase string to kebab-case.
895
+ * e.g. backgroundColor -> background-color
896
+ *
897
+ * @param str - The camelCase string to convert.
898
+ * @returns The converted kebab-case string.
899
+ */
900
+ function camelCaseToKebabCase(str) {
901
+ return str.replace(/([A-Z])/g, function (match) { return '-' + match.toLowerCase(); });
438
902
  }
439
903
 
440
- var withDefault = function (x, y) {
441
- return { x: x, y: y };
904
+ var _internalInterpolate = function (val, arr, extrapolateLeft, extrapolateRight) {
905
+ var _a = __read(arr, 4), inputMin = _a[0], inputMax = _a[1], outputMin = _a[2], outputMax = _a[3];
906
+ var result = val;
907
+ // EXTRAPOLATE
908
+ if (result < inputMin) {
909
+ if (extrapolateLeft === 'identity') {
910
+ return result;
911
+ }
912
+ else if (extrapolateLeft === 'clamp') {
913
+ result = inputMin;
914
+ }
915
+ else ;
916
+ }
917
+ if (result > inputMax) {
918
+ if (extrapolateRight === 'identity') {
919
+ return result;
920
+ }
921
+ else if (extrapolateRight === 'clamp') {
922
+ result = inputMax;
923
+ }
924
+ else ;
925
+ }
926
+ if (outputMin === outputMax) {
927
+ return outputMin;
928
+ }
929
+ if (inputMin === inputMax) {
930
+ if (val <= inputMin) {
931
+ return outputMin;
932
+ }
933
+ return outputMax;
934
+ }
935
+ // Input Range
936
+ if (inputMin === -Infinity) {
937
+ result = -result;
938
+ }
939
+ else if (inputMax === Infinity) {
940
+ result = result - inputMin;
941
+ }
942
+ else {
943
+ result = (result - inputMin) / (inputMax - inputMin);
944
+ }
945
+ // Output Range
946
+ if (outputMin === -Infinity) {
947
+ result = -result;
948
+ }
949
+ else if (outputMax === Infinity) {
950
+ result = result + outputMin;
951
+ }
952
+ else {
953
+ result = result * (outputMax - outputMin) + outputMin;
954
+ }
955
+ return result;
442
956
  };
957
+ var _getNarrowedInputArray = function (x, input, output) {
958
+ var length = input.length;
959
+ var narrowedInput = [];
960
+ // Boundaries
961
+ if (x < input[0]) {
962
+ narrowedInput = [input[0], input[1], output[0], output[1]];
963
+ }
964
+ else if (x > input[length - 1]) {
965
+ narrowedInput = [
966
+ input[length - 2],
967
+ input[length - 1],
968
+ output[length - 2],
969
+ output[length - 1],
970
+ ];
971
+ }
972
+ // Narrow the input and output ranges
973
+ for (var i = 1; i < length; ++i) {
974
+ if (x <= input[i]) {
975
+ narrowedInput = [input[i - 1], input[i], output[i - 1], output[i]];
976
+ break;
977
+ }
978
+ }
979
+ return narrowedInput;
980
+ };
981
+ var _getColorInterpolate = function (value, narrowedInput) {
982
+ var _a = __read(narrowedInput, 4), inputMin = _a[0], inputMax = _a[1], outputMin = _a[2], outputMax = _a[3];
983
+ var outputMinProcessed = hexToRgba(outputMin);
984
+ var outputMaxProcessed = hexToRgba(outputMax);
985
+ var red = _internalInterpolate(value, [inputMin, inputMax, outputMinProcessed.r, outputMaxProcessed.r], 'clamp', 'clamp');
986
+ var green = _internalInterpolate(value, [inputMin, inputMax, outputMinProcessed.g, outputMaxProcessed.g], 'clamp', 'clamp');
987
+ var blue = _internalInterpolate(value, [inputMin, inputMax, outputMinProcessed.b, outputMaxProcessed.b], 'clamp', 'clamp');
988
+ var alpha = _internalInterpolate(value, [inputMin, inputMax, outputMinProcessed.a, outputMaxProcessed.a], 'clamp', 'clamp');
989
+ return rgbaToHex({ r: red, g: green, b: blue, a: alpha });
990
+ };
991
+ var _getArrayInterpolate = function (value, narrowedInput, _extrapolateLeft, _extrapolateRight) {
992
+ var _a = __read(narrowedInput, 4), inputMin = _a[0], inputMax = _a[1], outputMin = _a[2], outputMax = _a[3];
993
+ if (outputMin.length === outputMax.length) {
994
+ return outputMin.map(function (val, index) {
995
+ if (typeof val === 'string') {
996
+ // IF IT IS STRING THEN IT MUST BE HEX COLOR
997
+ return _getColorInterpolate(value, [
998
+ inputMin,
999
+ inputMax,
1000
+ val,
1001
+ outputMax[index],
1002
+ ]);
1003
+ }
1004
+ else {
1005
+ return _internalInterpolate(value, [inputMin, inputMax, val, outputMax[index]], _extrapolateLeft, _extrapolateRight);
1006
+ }
1007
+ });
1008
+ }
1009
+ else {
1010
+ throw new Error("Array length doesn't match");
1011
+ }
1012
+ };
1013
+ var _getTemplateString = function (str) {
1014
+ return str.replace(COLOR_NUMBER_REGEX, '$');
1015
+ };
1016
+ var _getParsedStringArray = function (str) {
1017
+ return str.match(COLOR_NUMBER_REGEX).map(function (v) {
1018
+ if (v.indexOf('#') !== -1) {
1019
+ return v;
1020
+ }
1021
+ else {
1022
+ return Number(v);
1023
+ }
1024
+ });
1025
+ };
1026
+ /**
1027
+ * Function returns if the template of two strings are matched
1028
+ * i.e. they can be interpolated
1029
+ * @param str1 - first string
1030
+ * @param str2 - second string
1031
+ * @returns boolean indicating two strings matched or not
1032
+ */
1033
+ var stringMatched = function (str1, str2) {
1034
+ return _getTemplateString(str1).trim().replace(/\s/g, '') ===
1035
+ _getTemplateString(str2).trim().replace(/\s/g, '');
1036
+ };
1037
+ /**
1038
+ * Function which proccess the
1039
+ * hexadecimal colors to its proper formats
1040
+ * @param str - string
1041
+ * @returns hex color string
1042
+ */
1043
+ var getProcessedColor = function (str) {
1044
+ return str.replace(HEX_NAME_COLOR, function (match) {
1045
+ if (match.indexOf('#') !== -1) {
1046
+ return rgbaToHex(hexToRgba(match));
1047
+ }
1048
+ else if (Object.prototype.hasOwnProperty.call(colorNames, match)) {
1049
+ return colorNames[match];
1050
+ }
1051
+ else {
1052
+ throw new Error('String cannot be parsed!');
1053
+ }
1054
+ });
1055
+ };
1056
+ /**
1057
+ * interpolateNumbers to interpolate the numeric value
1058
+ * @param value - number
1059
+ * @param inputRange
1060
+ * @param outputRange
1061
+ * @param extrapolateConfig
1062
+ * @returns - number | string
1063
+ */
1064
+ function interpolateNumbers(value, inputRange, outputRange, extrapolateConfig) {
1065
+ var e_1, _a;
1066
+ var extrapolate = extrapolateConfig === null || extrapolateConfig === void 0 ? void 0 : extrapolateConfig.extrapolate;
1067
+ var extrapolateLeft = extrapolateConfig === null || extrapolateConfig === void 0 ? void 0 : extrapolateConfig.extrapolateLeft;
1068
+ var extrapolateRight = extrapolateConfig === null || extrapolateConfig === void 0 ? void 0 : extrapolateConfig.extrapolateRight;
1069
+ var narrowedInput = _getNarrowedInputArray(value, inputRange, outputRange);
1070
+ var _extrapolateLeft = 'extend';
1071
+ if (extrapolateLeft !== undefined) {
1072
+ _extrapolateLeft = extrapolateLeft;
1073
+ }
1074
+ else if (extrapolate !== undefined) {
1075
+ _extrapolateLeft = extrapolate;
1076
+ }
1077
+ var _extrapolateRight = 'extend';
1078
+ if (extrapolateRight !== undefined) {
1079
+ _extrapolateRight = extrapolateRight;
1080
+ }
1081
+ else if (extrapolate !== undefined) {
1082
+ _extrapolateRight = extrapolate;
1083
+ }
1084
+ if (outputRange.length) {
1085
+ if (typeof outputRange[0] === 'number') {
1086
+ return _internalInterpolate(value, narrowedInput, _extrapolateLeft, _extrapolateRight);
1087
+ }
1088
+ else if (Array.isArray(outputRange[0])) {
1089
+ return _getArrayInterpolate(value, narrowedInput, _extrapolateLeft, _extrapolateRight);
1090
+ }
1091
+ else {
1092
+ var _b = __read(narrowedInput, 4), inputMin = _b[0], inputMax = _b[1], outputMin = _b[2], outputMax = _b[3];
1093
+ var processedOutputMin = getProcessedColor(outputMin);
1094
+ var processedOutputMax = getProcessedColor(outputMax);
1095
+ var templateString = _getTemplateString(processedOutputMin);
1096
+ if (stringMatched(processedOutputMin, processedOutputMax)) {
1097
+ var outputMinParsed = _getParsedStringArray(processedOutputMin);
1098
+ var outputMaxParsed = _getParsedStringArray(processedOutputMax);
1099
+ var result = _getArrayInterpolate(value, [inputMin, inputMax, outputMinParsed, outputMaxParsed], _extrapolateLeft, _extrapolateRight);
1100
+ try {
1101
+ for (var result_1 = __values(result), result_1_1 = result_1.next(); !result_1_1.done; result_1_1 = result_1.next()) {
1102
+ var v = result_1_1.value;
1103
+ templateString = templateString.replace('$', v);
1104
+ }
1105
+ }
1106
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
1107
+ finally {
1108
+ try {
1109
+ if (result_1_1 && !result_1_1.done && (_a = result_1.return)) _a.call(result_1);
1110
+ }
1111
+ finally { if (e_1) throw e_1.error; }
1112
+ }
1113
+ return templateString;
1114
+ }
1115
+ else {
1116
+ throw new Error("Output range doesn't match string format!");
1117
+ }
1118
+ }
1119
+ }
1120
+ else {
1121
+ throw new Error('Output range cannot be Empty');
1122
+ }
1123
+ }
1124
+ /**
1125
+ * interpolateTransitionValue to interpolating TransitionValue type value
1126
+ * @param value
1127
+ * @param inputRange
1128
+ * @param outputRange
1129
+ * @param extrapolateConfig
1130
+ * @returns TransitionValue
1131
+ */
1132
+ var interpolateTransitionValue = function (value, inputRange, outputRange, extrapolateConfig) {
1133
+ return __assign(__assign({}, value), { isInterpolation: true, interpolationConfig: {
1134
+ inputRange: inputRange,
1135
+ outputRange: outputRange,
1136
+ extrapolateConfig: extrapolateConfig,
1137
+ } });
1138
+ };
1139
+ /**
1140
+ * interpolate function to interpolate both transition
1141
+ * as well as numerical value
1142
+ * @param value
1143
+ * @param inputRange
1144
+ * @param outputRange
1145
+ * @param extrapolateConfig
1146
+ */
1147
+ var interpolate$1 = function (value, inputRange, outputRange, extrapolateConfig) {
1148
+ if (isFluidValue(value)) {
1149
+ return interpolateTransitionValue(value, inputRange, outputRange, extrapolateConfig);
1150
+ }
1151
+ else if (typeof value === 'number') {
1152
+ return interpolateNumbers(value, inputRange, outputRange, extrapolateConfig);
1153
+ }
1154
+ else {
1155
+ throw new Error("'".concat(typeof value, "' cannot be interpolated!"));
1156
+ }
1157
+ };
1158
+ /**
1159
+ * Determines if two values can be interpolated.
1160
+ * This function checks if two values, either numbers or strings,
1161
+ * can be interpolated by ensuring they are of the same type and, in the case of strings,
1162
+ * that they are compatible for interpolation based on processed color values.
1163
+ *
1164
+ * @param previousValue - The previous value to compare. Can be a number or a string.
1165
+ * @param newValue - The new value to compare. Can be a number or a string.
1166
+ * @returns True if interpolation is possible, false otherwise.
1167
+ */
1168
+ function canInterpolate(previousValue, newValue) {
1169
+ if (typeof previousValue !== typeof newValue) {
1170
+ return false;
1171
+ }
1172
+ if (typeof newValue === 'number') {
1173
+ return true;
1174
+ }
1175
+ if (typeof previousValue === 'string') {
1176
+ var processedPreviousValue = getProcessedColor(previousValue);
1177
+ var processedNewValue = getProcessedColor(newValue);
1178
+ return (processedPreviousValue !== processedNewValue &&
1179
+ _getTemplateString(processedPreviousValue) ===
1180
+ _getTemplateString(processedNewValue));
1181
+ }
1182
+ return false;
1183
+ }
443
1184
 
444
- var Gesture = /** @class */ (function () {
445
- function Gesture() {
446
- this.lastTimeStamp = Date.now();
447
- this.isActive = false;
448
- this.targetElements = []; // represents the bounded elements
449
- }
450
- // it must be overridden by other child classes
451
- Gesture.prototype._initEvents = function () { };
452
- // cancel events
453
- // we only canceled down and move events because mouse up
454
- // will not be triggered
455
- Gesture.prototype._cancelEvents = function () {
456
- if (this._subscribe) {
457
- this._subscribe();
458
- }
459
- };
460
- // re-apply new callback
461
- Gesture.prototype.applyCallback = function (callback) {
462
- this.callback = callback;
463
- };
464
- // apply gesture
465
- Gesture.prototype.applyGesture = function (_a) {
466
- var _this = this;
467
- var targetElement = _a.targetElement, targetElements = _a.targetElements, callback = _a.callback, config = _a.config;
468
- this.targetElement = targetElement;
469
- this.targetElements = targetElements.map(function (element) { return element.current; });
470
- this.callback = callback;
471
- this.config = config;
472
- // initialize events
473
- this._initEvents();
474
- // unbind
475
- return function () { return _this._subscribe && _this._subscribe(); };
476
- };
477
- Gesture._VELOCITY_LIMIT = 20;
478
- return Gesture;
1185
+ var styleTrasformKeys = [
1186
+ 'translate',
1187
+ 'translateX',
1188
+ 'translateY',
1189
+ 'translateZ',
1190
+ 'scale',
1191
+ 'scaleX',
1192
+ 'scaleY',
1193
+ 'scaleZ',
1194
+ 'rotate',
1195
+ 'rotateX',
1196
+ 'rotateY',
1197
+ 'rotateZ',
1198
+ 'skew',
1199
+ 'skewX',
1200
+ 'skewY',
1201
+ ];
1202
+ function splitCSSValueAndUnit(value) {
1203
+ var valueMatch = value.match(/(-)?(\d+.)?\d+/g);
1204
+ var unitMatch = value.match(/px|rem|em|ex|%|cm|mm|in|pt|pc|ch|vh|vw|vmin|vmax/);
1205
+ return {
1206
+ value: Number(valueMatch),
1207
+ unit: unitMatch && unitMatch[0],
1208
+ };
1209
+ }
1210
+ // get unit of transform style property
1211
+ function getValueUnit(property, value) {
1212
+ var unit;
1213
+ var splitValue = splitCSSValueAndUnit(String(value)).value;
1214
+ var splitUnit = splitCSSValueAndUnit(String(value)).unit;
1215
+ // if string value is passed with unit then split it
1216
+ if (splitUnit) {
1217
+ return { value: splitValue, unit: splitUnit };
1218
+ }
1219
+ if (property.includes('translate') || property.includes('perspective')) {
1220
+ unit = 'px';
1221
+ }
1222
+ else if (property.includes('scale')) {
1223
+ unit = '';
1224
+ }
1225
+ else if (property.includes('rotate') || property.includes('skew')) {
1226
+ unit = 'deg';
1227
+ }
1228
+ return { value: value, unit: unit };
1229
+ }
1230
+ function getTransformValueWithUnits(property, value) {
1231
+ var valueUnit = getValueUnit(property, value);
1232
+ if (property.includes('X') ||
1233
+ property.includes('Y') ||
1234
+ property.includes('Z') ||
1235
+ property.includes('perspective') ||
1236
+ property.includes('rotate') ||
1237
+ property.includes('skew')) {
1238
+ // axis value
1239
+ return "".concat(property, "(").concat(valueUnit.value).concat(valueUnit.unit, ")");
1240
+ }
1241
+ else if (property.includes('translate') || property.indexOf('scale')) {
1242
+ // two parameter value
1243
+ return "".concat(property, "(").concat(valueUnit.value).concat(valueUnit.unit, ", ").concat(valueUnit.value).concat(valueUnit.unit, ")");
1244
+ }
1245
+ else {
1246
+ throw new Error("Error! Property '".concat(property, "' cannot be transformed"));
1247
+ }
1248
+ }
1249
+ /**
1250
+ * getTransform function returns transform string from style object
1251
+ */
1252
+ function getTransform(style) {
1253
+ return Object.entries(style)
1254
+ .map(function (_a) {
1255
+ var _b = __read(_a, 2), prop = _b[0], value = _b[1];
1256
+ return getTransformValueWithUnits(prop, value);
1257
+ })
1258
+ .reduce(function (transform, value) { return (transform += " ".concat(value)); }, '')
1259
+ .trim();
1260
+ }
1261
+ function isTransformKey(key) {
1262
+ return styleTrasformKeys.includes(key);
1263
+ }
1264
+
1265
+ /**
1266
+ * Higher-order component to make any component animatable.
1267
+ *
1268
+ * This function takes a React component or an HTML tag and returns a new component
1269
+ * that can smoothly transition between states using fluid animations. It enhances
1270
+ * the user experience by adding dynamic and engaging animations to the wrapped component.
1271
+ *
1272
+ * @param WrapperComponent - The React component or HTML tag to be wrapped with animation functionality.
1273
+ * @returns - A new component with added animation capabilities.
1274
+ *
1275
+ * The returned component uses fluid animations to smoothly transition between different
1276
+ * states. It supports both style and prop animations, handling transforms and other
1277
+ * properties seamlessly. The component ensures that animations are efficiently applied
1278
+ * and updated based on the current state and configuration of fluid values.
1279
+ *
1280
+ * @example
1281
+ * const AnimatedDiv = makeFluid('div');
1282
+ *
1283
+ * const MyComponent = () => {
1284
+ * const opacity = useAnimatedValue(1)
1285
+ * return (
1286
+ * <AnimatedDiv style={{ opacity: opacity.value }}>
1287
+ * Hello, world!
1288
+ * </AnimatedDiv>
1289
+ * )};
1290
+ */
1291
+ function makeFluid(WrapperComponent) {
1292
+ return React.forwardRef(function (givenProps, givenRef) {
1293
+ var instanceRef = React.useRef(null);
1294
+ var transformStyleRef = React.useRef({});
1295
+ var _a = React.useMemo(function () {
1296
+ var style = givenProps.style, props = __rest(givenProps, ["style"]);
1297
+ var fluidStyle = getFluids('style', style);
1298
+ var fluidProps = getFluids('props', props);
1299
+ return {
1300
+ fluids: __spreadArray(__spreadArray([], __read(fluidStyle.fluids), false), __read(fluidProps.fluids), false),
1301
+ nonFluids: __spreadArray(__spreadArray([], __read(fluidStyle.nonFluids), false), __read(fluidProps.nonFluids), false),
1302
+ };
1303
+ }, [givenProps]), fluids = _a.fluids, nonFluids = _a.nonFluids;
1304
+ var applyAnimationValues = function (_a) {
1305
+ var isTransform = _a.isTransform, propertyType = _a.propertyType, property = _a.property, value = _a.value;
1306
+ if (!instanceRef.current)
1307
+ return;
1308
+ if (propertyType === 'style') {
1309
+ if (isTransform) {
1310
+ transformStyleRef.current[property] = value;
1311
+ instanceRef.current.style.transform = getTransform(transformStyleRef.current);
1312
+ }
1313
+ else {
1314
+ instanceRef.current.style[property] = getCssValue(property, value);
1315
+ }
1316
+ }
1317
+ else if (propertyType === 'props') {
1318
+ instanceRef.current.setAttribute(camelCaseToKebabCase(property), value);
1319
+ }
1320
+ };
1321
+ React.useLayoutEffect(function () {
1322
+ nonFluids.forEach(function (_a) {
1323
+ var isTransform = _a.isTransform, property = _a.property, propertyType = _a.propertyType, value = _a.value;
1324
+ return applyAnimationValues({
1325
+ isTransform: isTransform,
1326
+ property: property,
1327
+ propertyType: propertyType,
1328
+ value: value,
1329
+ });
1330
+ });
1331
+ }, [nonFluids]);
1332
+ React.useLayoutEffect(function () {
1333
+ var subscribers = [];
1334
+ fluids.forEach(function (f) {
1335
+ var fluidValue = f.value, propertyType = f.propertyType, property = f.property, isTransform = f.isTransform;
1336
+ var _subscribe = fluidValue._subscribe, _value = fluidValue._value, _currentValue = fluidValue._currentValue, _config = fluidValue._config;
1337
+ var interpolationOutputRange = [];
1338
+ var generateAnimation = animationObjectGenerator(_config);
1339
+ var animation = null;
1340
+ var onFrame = function (value) {
1341
+ _currentValue.current = value;
1342
+ var updatedValue = fluidValue.isInterpolation
1343
+ ? interpolateNumbers(value, fluidValue.interpolationConfig.inputRange, fluidValue.interpolationConfig.outputRange, fluidValue.interpolationConfig.extrapolateConfig)
1344
+ : value;
1345
+ applyAnimationValues({
1346
+ isTransform: isTransform,
1347
+ propertyType: propertyType,
1348
+ property: property,
1349
+ value: updatedValue,
1350
+ });
1351
+ };
1352
+ var onUpdate = function (value, config, callback) {
1353
+ if (canInterpolate(_value, value)) {
1354
+ var previousAnimation = animation;
1355
+ if (previousAnimation._value !== value) {
1356
+ animation.stop();
1357
+ animation = generateAnimation(previousAnimation._position, config);
1358
+ (config === null || config === void 0 ? void 0 : config.onStart) && config.onStart(previousAnimation._position);
1359
+ if (typeof value === 'string') {
1360
+ if (!interpolationOutputRange.includes(_value)) {
1361
+ interpolationOutputRange.push(_value);
1362
+ }
1363
+ if (!interpolationOutputRange.includes(value)) {
1364
+ interpolationOutputRange.push(value);
1365
+ }
1366
+ fluidValue.isInterpolation = true;
1367
+ fluidValue.interpolationConfig = {
1368
+ inputRange: interpolationOutputRange.map(function (_, i) { return i; }),
1369
+ outputRange: interpolationOutputRange,
1370
+ };
1371
+ }
1372
+ animation.start({
1373
+ toValue: typeof value === 'string'
1374
+ ? interpolationOutputRange.indexOf(value)
1375
+ : value,
1376
+ onFrame: onFrame,
1377
+ previousAnimation: previousAnimation,
1378
+ onEnd: callback,
1379
+ });
1380
+ }
1381
+ }
1382
+ else {
1383
+ if (typeof value !== typeof _value) {
1384
+ throw new Error("Cannot assign ".concat(typeof value, " to animated ").concat(typeof _value));
1385
+ }
1386
+ applyAnimationValues({
1387
+ isTransform: isTransform,
1388
+ propertyType: propertyType,
1389
+ property: property,
1390
+ value: value,
1391
+ });
1392
+ }
1393
+ };
1394
+ animation = generateAnimation(typeof _value === 'string' ? 0 : _value);
1395
+ applyAnimationValues({
1396
+ isTransform: isTransform,
1397
+ propertyType: propertyType,
1398
+ property: property,
1399
+ value: _value,
1400
+ });
1401
+ var subscribe = _subscribe(onUpdate, property, Date.now());
1402
+ subscribers.push(subscribe);
1403
+ });
1404
+ return function () {
1405
+ subscribers.forEach(function (subscriber) { return subscriber(); });
1406
+ };
1407
+ }, []);
1408
+ return React.createElement(WrapperComponent, __assign(__assign({}, getCleanProps(givenProps)), { ref: combineRefs(instanceRef, givenRef) }));
1409
+ });
1410
+ }
1411
+ function combineRefs() {
1412
+ var refs = [];
1413
+ for (var _i = 0; _i < arguments.length; _i++) {
1414
+ refs[_i] = arguments[_i];
1415
+ }
1416
+ return function applyRef(element) {
1417
+ refs.forEach(function (ref) {
1418
+ if (!ref)
1419
+ return;
1420
+ if (typeof ref === 'function') {
1421
+ ref(element);
1422
+ return;
1423
+ }
1424
+ if ('current' in ref)
1425
+ ref.current = element;
1426
+ });
1427
+ };
1428
+ }
1429
+ function animationObjectGenerator(defaultConfig) {
1430
+ return function (value, config) {
1431
+ var animationConfig = __assign(__assign({}, defaultConfig), config);
1432
+ var Animation = isDefined(animationConfig === null || animationConfig === void 0 ? void 0 : animationConfig.duration) || (animationConfig === null || animationConfig === void 0 ? void 0 : animationConfig.immediate)
1433
+ ? TimingAnimation
1434
+ : SpringAnimation;
1435
+ return new Animation({
1436
+ initialPosition: value,
1437
+ config: animationConfig,
1438
+ });
1439
+ };
1440
+ }
1441
+ function getFluids(propertyType, props) {
1442
+ if (props === void 0) { props = {}; }
1443
+ return Object.entries(props).reduce(function (res, _a) {
1444
+ var _b = __read(_a, 2), property = _b[0], value = _b[1];
1445
+ var isTransform = propertyType === 'style' && isTransformKey(property);
1446
+ if (isFluidValue(value)) {
1447
+ res.fluids.push({ isTransform: isTransform, property: property, propertyType: propertyType, value: value });
1448
+ }
1449
+ else {
1450
+ res.nonFluids.push({ isTransform: isTransform, property: property, propertyType: propertyType, value: value });
1451
+ }
1452
+ return res;
1453
+ }, { fluids: [], nonFluids: [] });
1454
+ }
1455
+
1456
+ var tags = [
1457
+ 'a',
1458
+ 'abbr',
1459
+ 'address',
1460
+ 'area',
1461
+ 'article',
1462
+ 'aside',
1463
+ 'audio',
1464
+ 'b',
1465
+ 'base',
1466
+ 'bdi',
1467
+ 'bdo',
1468
+ 'big',
1469
+ 'blockquote',
1470
+ 'body',
1471
+ 'br',
1472
+ 'button',
1473
+ 'canvas',
1474
+ 'caption',
1475
+ 'center',
1476
+ 'cite',
1477
+ 'code',
1478
+ 'col',
1479
+ 'colgroup',
1480
+ 'data',
1481
+ 'datalist',
1482
+ 'dd',
1483
+ 'del',
1484
+ 'details',
1485
+ 'dfn',
1486
+ 'dialog',
1487
+ 'div',
1488
+ 'dl',
1489
+ 'dt',
1490
+ 'em',
1491
+ 'embed',
1492
+ 'fieldset',
1493
+ 'figcaption',
1494
+ 'figure',
1495
+ 'footer',
1496
+ 'form',
1497
+ 'h1',
1498
+ 'h2',
1499
+ 'h3',
1500
+ 'h4',
1501
+ 'h5',
1502
+ 'h6',
1503
+ 'head',
1504
+ 'header',
1505
+ 'hgroup',
1506
+ 'hr',
1507
+ 'html',
1508
+ 'i',
1509
+ 'iframe',
1510
+ 'img',
1511
+ 'input',
1512
+ 'ins',
1513
+ 'kbd',
1514
+ 'keygen',
1515
+ 'label',
1516
+ 'legend',
1517
+ 'li',
1518
+ 'link',
1519
+ 'main',
1520
+ 'map',
1521
+ 'mark',
1522
+ 'menu',
1523
+ 'menuitem',
1524
+ 'meta',
1525
+ 'meter',
1526
+ 'nav',
1527
+ 'noindex',
1528
+ 'noscript',
1529
+ 'object',
1530
+ 'ol',
1531
+ 'optgroup',
1532
+ 'option',
1533
+ 'output',
1534
+ 'p',
1535
+ 'param',
1536
+ 'picture',
1537
+ 'pre',
1538
+ 'progress',
1539
+ 'q',
1540
+ 'rp',
1541
+ 'rt',
1542
+ 'ruby',
1543
+ 's',
1544
+ 'samp',
1545
+ 'search',
1546
+ 'section',
1547
+ 'select',
1548
+ 'small',
1549
+ 'source',
1550
+ 'span',
1551
+ 'strong',
1552
+ 'style',
1553
+ 'sub',
1554
+ 'summary',
1555
+ 'sup',
1556
+ 'table',
1557
+ 'template',
1558
+ 'tbody',
1559
+ 'td',
1560
+ 'textarea',
1561
+ 'tfoot',
1562
+ 'th',
1563
+ 'thead',
1564
+ 'time',
1565
+ 'title',
1566
+ 'tr',
1567
+ 'track',
1568
+ 'u',
1569
+ 'ul',
1570
+ 'var',
1571
+ 'video',
1572
+ 'wbr',
1573
+ // SVG Tags
1574
+ 'svg',
1575
+ 'animate',
1576
+ 'animateMotion',
1577
+ 'animateTransform',
1578
+ 'circle',
1579
+ 'clipPath',
1580
+ 'defs',
1581
+ 'desc',
1582
+ 'ellipse',
1583
+ 'feBlend',
1584
+ 'feColorMatrix',
1585
+ 'feComponentTransfer',
1586
+ 'feComposite',
1587
+ 'feConvolveMatrix',
1588
+ 'feDiffuseLighting',
1589
+ 'feDisplacementMap',
1590
+ 'feDistantLight',
1591
+ 'feDropShadow',
1592
+ 'feFlood',
1593
+ 'feFuncA',
1594
+ 'feFuncB',
1595
+ 'feFuncG',
1596
+ 'feFuncR',
1597
+ 'feGaussianBlur',
1598
+ 'feImage',
1599
+ 'feMerge',
1600
+ 'feMergeNode',
1601
+ 'feMorphology',
1602
+ 'feOffset',
1603
+ 'fePointLight',
1604
+ 'feSpecularLighting',
1605
+ 'feSpotLight',
1606
+ 'feTile',
1607
+ 'feTurbulence',
1608
+ 'filter',
1609
+ 'foreignObject',
1610
+ 'g',
1611
+ 'image',
1612
+ 'line',
1613
+ 'linearGradient',
1614
+ 'marker',
1615
+ 'mask',
1616
+ 'metadata',
1617
+ 'mpath',
1618
+ 'path',
1619
+ 'pattern',
1620
+ 'polygon',
1621
+ 'polyline',
1622
+ 'radialGradient',
1623
+ 'rect',
1624
+ 'set',
1625
+ 'stop',
1626
+ 'switch',
1627
+ 'symbol',
1628
+ 'text',
1629
+ 'textPath',
1630
+ 'tspan',
1631
+ 'use',
1632
+ 'view',
1633
+ ];
1634
+ var fluid = {};
1635
+ tags.forEach(function (tag) {
1636
+ fluid[tag] = makeFluid(tag);
1637
+ });
1638
+
1639
+ /**
1640
+ * Represents a fluid value that can animate between states.
1641
+ */
1642
+ var FluidValue = /** @class */ (function () {
1643
+ /**
1644
+ * Creates a new FluidValue instance.
1645
+ * @param initialValue - The initial value of the fluid value.
1646
+ * @param config - Optional configuration for the fluid value.
1647
+ */
1648
+ function FluidValue(initialValue, config) {
1649
+ var _this = this;
1650
+ this._subscriptions = new Map();
1651
+ this._subscribe = function (onUpdate, property, uuid) {
1652
+ var e_1, _a;
1653
+ var _loop_1 = function (key) {
1654
+ if (key.property === property) {
1655
+ _this._subscriptions.set(key, onUpdate);
1656
+ return { value: function () { return _this._subscriptions.delete(key); } };
1657
+ }
1658
+ };
1659
+ try {
1660
+ for (var _b = __values(_this._subscriptions.keys()), _c = _b.next(); !_c.done; _c = _b.next()) {
1661
+ var key = _c.value;
1662
+ var state_1 = _loop_1(key);
1663
+ if (typeof state_1 === "object")
1664
+ return state_1.value;
1665
+ }
1666
+ }
1667
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
1668
+ finally {
1669
+ try {
1670
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
1671
+ }
1672
+ finally { if (e_1) throw e_1.error; }
1673
+ }
1674
+ _this._subscriptions.set({ uuid: uuid, property: property }, onUpdate);
1675
+ return function () { return _this._subscriptions.delete({ uuid: uuid, property: property }); };
1676
+ };
1677
+ this._value = initialValue;
1678
+ this._currentValue = { current: initialValue };
1679
+ this._config = config;
1680
+ this.get = function () { return _this._currentValue.current; };
1681
+ }
1682
+ /**
1683
+ * Animates from the current value to the updated value.
1684
+ * Determines whether to perform a multi-stage or single-stage transition.
1685
+ * @param updatedValue - The value to animate to, or a function that defines a multi-stage transition.
1686
+ * @param config - Optional configuration for the animation.
1687
+ * @param callback - Optional callback to be called after the animation ends.
1688
+ */
1689
+ FluidValue.prototype.setValue = function (updatedValue, config, callback) {
1690
+ var e_2, _a;
1691
+ var _this = this;
1692
+ /** Multistage transition */
1693
+ if (typeof updatedValue === 'function') {
1694
+ updatedValue(function (nextValue, nextConfig) {
1695
+ var multiStagePromise = new Promise(function (resolve) {
1696
+ var e_3, _a;
1697
+ try {
1698
+ for (var _b = __values(_this._subscriptions.keys()), _c = _b.next(); !_c.done; _c = _b.next()) {
1699
+ var subscriptionKey = _c.value;
1700
+ var updater = _this._subscriptions.get(subscriptionKey);
1701
+ if (updater) {
1702
+ updater(nextValue, nextConfig !== null && nextConfig !== void 0 ? nextConfig : config, function (result) {
1703
+ if (result.finished) {
1704
+ resolve(nextValue);
1705
+ }
1706
+ if (callback) {
1707
+ callback(result);
1708
+ }
1709
+ });
1710
+ }
1711
+ }
1712
+ }
1713
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
1714
+ finally {
1715
+ try {
1716
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
1717
+ }
1718
+ finally { if (e_3) throw e_3.error; }
1719
+ }
1720
+ });
1721
+ return multiStagePromise;
1722
+ });
1723
+ return;
1724
+ }
1725
+ try {
1726
+ /** Singlestage transition */
1727
+ for (var _b = __values(this._subscriptions.keys()), _c = _b.next(); !_c.done; _c = _b.next()) {
1728
+ var subscriptionKey = _c.value;
1729
+ var updater = this._subscriptions.get(subscriptionKey);
1730
+ updater && updater(updatedValue, config, callback);
1731
+ }
1732
+ }
1733
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
1734
+ finally {
1735
+ try {
1736
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
1737
+ }
1738
+ finally { if (e_2) throw e_2.error; }
1739
+ }
1740
+ };
1741
+ return FluidValue;
479
1742
  }());
480
1743
 
481
- var DragGesture = /** @class */ (function (_super) {
482
- __extends(DragGesture, _super);
483
- function DragGesture() {
484
- var _this = _super !== null && _super.apply(this, arguments) || this;
485
- _this.movementStart = withDefault(0, 0);
486
- _this.initialMovement = withDefault(0, 0);
487
- _this.movement = withDefault(0, 0);
488
- _this.previousMovement = withDefault(0, 0);
489
- _this.translation = withDefault(0, 0);
490
- _this.offset = withDefault(0, 0);
491
- _this.velocity = withDefault(0, 0);
492
- return _this;
493
- }
494
- // @override
495
- // initialize the events
496
- DragGesture.prototype._initEvents = function () {
497
- if (this.targetElement || this.targetElements.length > 0) {
498
- this._subscribe = attachEvents([window], [
499
- ['mousedown', this.pointerDown.bind(this)],
500
- ['mousemove', this.pointerMove.bind(this)],
501
- ['mouseup', this.pointerUp.bind(this)],
502
- ['touchstart', this.pointerDown.bind(this), { passive: false }],
503
- ['touchmove', this.pointerMove.bind(this), { passive: false }],
504
- ['touchend', this.pointerUp.bind(this)],
505
- ]);
506
- }
507
- };
508
- // @override - cancel events
509
- // we only canceled down and move events because mouse up
510
- // will not be triggered
511
- DragGesture.prototype._cancelEvents = function () {
512
- if (this._subscribe) {
513
- this._subscribe(['mousedown', 'mousemove', 'touchstart', 'touchmove']);
514
- }
515
- };
516
- DragGesture.prototype._handleCallback = function () {
517
- var _this = this;
518
- if (this.callback) {
519
- this.callback({
520
- args: [this.currentIndex],
521
- down: this.isActive,
522
- movementX: this.movement.x,
523
- movementY: this.movement.y,
524
- offsetX: this.translation.x,
525
- offsetY: this.translation.y,
526
- velocityX: this.velocity.x,
527
- velocityY: this.velocity.y,
528
- distanceX: Math.abs(this.movement.x),
529
- distanceY: Math.abs(this.movement.y),
530
- directionX: Math.sign(this.movement.x),
531
- directionY: Math.sign(this.movement.y),
532
- cancel: function () {
533
- _this._cancelEvents();
534
- },
535
- });
536
- }
537
- };
538
- DragGesture.prototype.pointerDown = function (e) {
539
- var _a;
540
- if (e.type === 'touchstart') {
541
- this.movementStart = {
542
- x: e.touches[0].clientX,
543
- y: e.touches[0].clientY,
544
- };
545
- }
546
- else {
547
- this.movementStart = { x: e.clientX, y: e.clientY };
548
- }
549
- this.movement = { x: 0, y: 0 };
550
- this.offset = { x: this.translation.x, y: this.translation.y };
551
- this.previousMovement = { x: 0, y: 0 };
552
- this.velocity = { x: 0, y: 0 };
553
- // find current selected element
554
- var currElem = this.targetElements.find(function (elem) { return elem === e.target; });
555
- if (e.target === this.targetElement || currElem) {
556
- this.isActive = true;
557
- e.preventDefault();
558
- // set args
559
- if (currElem) {
560
- this.currentIndex = this.targetElements.indexOf(currElem);
561
- }
562
- // if initial function is defined then call it to get initial movementX and movementY
563
- // if only select to bounded draggable element
564
- var initial = ((_a = this.config) === null || _a === void 0 ? void 0 : _a.initial) && this.config.initial();
565
- var initialMovementX = initial === null || initial === void 0 ? void 0 : initial.movementX;
566
- var initialMovementY = initial === null || initial === void 0 ? void 0 : initial.movementY;
567
- this.initialMovement = {
568
- x: initialMovementX !== null && initialMovementX !== void 0 ? initialMovementX : 0,
569
- y: initialMovementY !== null && initialMovementY !== void 0 ? initialMovementY : 0,
570
- };
571
- this.movement = {
572
- x: this.initialMovement.x,
573
- y: this.initialMovement.y,
574
- };
575
- this.previousMovement = {
576
- x: this.initialMovement.x,
577
- y: this.initialMovement.y,
578
- };
579
- this._handleCallback();
580
- }
581
- };
582
- DragGesture.prototype.pointerMove = function (e) {
583
- if (this.isActive) {
584
- e.preventDefault();
585
- var now = Date.now();
586
- var deltaTime = clamp(now - this.lastTimeStamp, 0.1, 64);
587
- this.lastTimeStamp = now;
588
- var t = deltaTime / 1000;
589
- if (e.type === 'touchmove') {
590
- this.movement = {
591
- x: this.initialMovement.x +
592
- (e.touches[0].clientX - this.movementStart.x),
593
- y: this.initialMovement.y +
594
- (e.touches[0].clientY - this.movementStart.y),
595
- };
596
- }
597
- else {
598
- this.movement = {
599
- x: this.initialMovement.x + (e.clientX - this.movementStart.x),
600
- y: this.initialMovement.y + (e.clientY - this.movementStart.y),
601
- };
602
- }
603
- this.translation = {
604
- x: this.offset.x + this.movement.x,
605
- y: this.offset.y + this.movement.y,
606
- };
607
- this.velocity = {
608
- x: clamp((this.movement.x - this.previousMovement.x) / t / 1000, -1 * Gesture._VELOCITY_LIMIT, Gesture._VELOCITY_LIMIT),
609
- y: clamp((this.movement.y - this.previousMovement.y) / t / 1000, -1 * Gesture._VELOCITY_LIMIT, Gesture._VELOCITY_LIMIT),
610
- };
611
- this.previousMovement = {
612
- x: this.movement.x,
613
- y: this.movement.y,
614
- };
615
- this._handleCallback();
616
- }
617
- };
618
- DragGesture.prototype.pointerUp = function () {
619
- if (this.isActive) {
620
- this.isActive = false;
621
- this._handleCallback();
622
- this._cancelEvents();
623
- this._initEvents();
624
- }
625
- };
626
- return DragGesture;
627
- }(Gesture));
1744
+ /**
1745
+ * useFluidValue
1746
+ *
1747
+ * @param value - initial value
1748
+ * @param config - the config object for `FluidValue`
1749
+ */
1750
+ var useFluidValue = function (value, config) {
1751
+ var fluid = React.useMemo(function () { return new FluidValue(value, config); }, []);
1752
+ var setFluid = React.useCallback(function (updateValue, config, callback) {
1753
+ fluid.setValue(updateValue, config, callback);
1754
+ }, []);
1755
+ return [fluid, setFluid];
1756
+ };
628
1757
 
629
- var MouseMoveGesture = /** @class */ (function (_super) {
630
- __extends(MouseMoveGesture, _super);
631
- function MouseMoveGesture() {
632
- var _this = _super !== null && _super.apply(this, arguments) || this;
633
- _this.movement = withDefault(0, 0);
634
- _this.previousMovement = withDefault(0, 0);
635
- _this.velocity = withDefault(0, 0);
636
- _this.direction = withDefault(0, 0);
637
- return _this;
638
- }
639
- // @override
640
- // initialize the events
641
- MouseMoveGesture.prototype._initEvents = function () {
642
- if (this.targetElement) {
643
- this._subscribe = attachEvents([this.targetElement], [['mousemove', this.onMouseMove.bind(this)]]);
644
- }
645
- else if (this.targetElements.length > 0) {
646
- this._subscribe = attachEvents(this.targetElements, [
647
- ['mousemove', this.onMouseMove.bind(this)],
648
- ]);
649
- }
650
- else {
651
- this._subscribe = attachEvents([window], [['mousemove', this.onMouseMove.bind(this)]]);
652
- }
653
- };
654
- MouseMoveGesture.prototype._handleCallback = function () {
655
- var _a;
656
- if (this.callback) {
657
- this.callback({
658
- args: [this.currentIndex],
659
- event: this.event,
660
- isMoving: this.isActive,
661
- target: (_a = this.event) === null || _a === void 0 ? void 0 : _a.target,
662
- mouseX: this.movement.x,
663
- mouseY: this.movement.y,
664
- velocityX: this.velocity.x,
665
- velocityY: this.velocity.y,
666
- directionX: this.direction.x,
667
- directionY: this.direction.y,
668
- });
669
- }
670
- };
671
- MouseMoveGesture.prototype.onMouseMove = function (e) {
672
- var _this = this;
673
- // find current selected element
674
- var currElem = this.targetElements.find(function (elem) { return elem === e.target; });
675
- // set args
676
- if (currElem) {
677
- this.currentIndex = this.targetElements.indexOf(currElem);
678
- }
679
- this.event = e;
680
- var now = Date.now();
681
- var deltaTime = Math.min(now - this.lastTimeStamp, 64);
682
- this.lastTimeStamp = now;
683
- var t = deltaTime / 1000; // seconds
684
- var x = e.clientX;
685
- var y = e.clientY;
686
- this.movement = { x: x, y: y };
687
- if (this.isActiveID !== -1) {
688
- this.isActive = true;
689
- clearTimeout(this.isActiveID);
690
- }
691
- this.isActiveID = setTimeout(function () {
692
- _this.isActive = false;
693
- _this.direction = { x: 0, y: 0 };
694
- _this.velocity = { x: 0, y: 0 };
695
- _this._handleCallback();
696
- }, 250); // Debounce 250 milliseconds
697
- var diffX = this.movement.x - this.previousMovement.x;
698
- var diffY = this.movement.y - this.previousMovement.y;
699
- this.direction = {
700
- x: Math.sign(diffX),
701
- y: Math.sign(diffY),
702
- };
703
- this.velocity = {
704
- x: clamp(diffX / t / 1000, -1 * Gesture._VELOCITY_LIMIT, Gesture._VELOCITY_LIMIT),
705
- y: clamp(diffY / t / 1000, -1 * Gesture._VELOCITY_LIMIT, Gesture._VELOCITY_LIMIT),
706
- };
707
- this.previousMovement = { x: this.movement.x, y: this.movement.y };
708
- this._handleCallback();
709
- };
710
- return MouseMoveGesture;
711
- }(Gesture));
1758
+ /**
1759
+ * `useMount`
1760
+ *
1761
+ * applies mounting and unmounting of a component according to state change
1762
+ * applying transitions
1763
+ *
1764
+ * @param state - boolean indicating mount state of a component
1765
+ * @param config - the config object `UseMountConfig`
1766
+ */
1767
+ var useMount = function (state, config) {
1768
+ var _a = __read(React.useState(false), 2), mounted = _a[0], setMounted = _a[1];
1769
+ var _b = React.useRef(config).current, from = _b.from, enter = _b.enter, exit = _b.exit, innerConfig = _b.config, enterConfig = _b.enterConfig, exitConfig = _b.exitConfig;
1770
+ var _c = __read(useFluidValue(from, innerConfig), 2), animation = _c[0], setAnimation = _c[1];
1771
+ React.useLayoutEffect(function () {
1772
+ if (state) {
1773
+ setMounted(true);
1774
+ queueMicrotask(function () { return setAnimation(enter, enterConfig); });
1775
+ }
1776
+ else {
1777
+ setAnimation(exit, exitConfig, function (_a) {
1778
+ var finished = _a.finished;
1779
+ if (finished) {
1780
+ setMounted(false);
1781
+ }
1782
+ });
1783
+ }
1784
+ }, [state]);
1785
+ return function (callback) { return callback(animation, mounted); };
1786
+ };
712
1787
 
713
- var ScrollGesture = /** @class */ (function (_super) {
714
- __extends(ScrollGesture, _super);
715
- function ScrollGesture() {
716
- var _this = _super !== null && _super.apply(this, arguments) || this;
717
- _this.movement = withDefault(0, 0);
718
- _this.previousMovement = withDefault(0, 0);
719
- _this.direction = withDefault(0, 0);
720
- _this.velocity = withDefault(0, 0);
721
- return _this;
722
- }
723
- // @override
724
- // initialize the events
725
- ScrollGesture.prototype._initEvents = function () {
726
- if (this.targetElement) {
727
- this._subscribe = attachEvents([this.targetElement], [['scroll', this.scrollElementListener.bind(this)]]);
728
- }
729
- else {
730
- this._subscribe = attachEvents([window], [['scroll', this.scrollListener.bind(this)]]);
731
- }
732
- };
733
- ScrollGesture.prototype._handleCallback = function () {
734
- if (this.callback) {
735
- this.callback({
736
- isScrolling: this.isActive,
737
- scrollX: this.movement.x,
738
- scrollY: this.movement.y,
739
- velocityX: this.velocity.x,
740
- velocityY: this.velocity.y,
741
- directionX: this.direction.x,
742
- directionY: this.direction.y,
743
- });
744
- }
745
- };
746
- ScrollGesture.prototype.onScroll = function (_a) {
747
- var _this = this;
748
- var x = _a.x, y = _a.y;
749
- var now = Date.now();
750
- var deltaTime = Math.min(now - this.lastTimeStamp, 64);
751
- this.lastTimeStamp = now;
752
- var t = deltaTime / 1000; // seconds
753
- this.movement = { x: x, y: y };
754
- // Clear if scrolling
755
- if (this.isActiveID !== -1) {
756
- this.isActive = true;
757
- clearTimeout(this.isActiveID);
758
- }
759
- this.isActiveID = setTimeout(function () {
760
- _this.isActive = false;
761
- _this.direction = { x: 0, y: 0 };
762
- // Reset Velocity
763
- _this.velocity = { x: 0, y: 0 };
764
- _this._handleCallback(); // Debounce 250milliseconds
765
- }, 250);
766
- var diffX = this.movement.x - this.previousMovement.x;
767
- var diffY = this.movement.y - this.previousMovement.y;
768
- this.direction = {
769
- x: Math.sign(diffX),
770
- y: Math.sign(diffY),
771
- };
772
- this.velocity = {
773
- x: clamp(diffX / t / 1000, -1 * Gesture._VELOCITY_LIMIT, Gesture._VELOCITY_LIMIT),
774
- y: clamp(diffY / t / 1000, -1 * Gesture._VELOCITY_LIMIT, Gesture._VELOCITY_LIMIT),
775
- };
776
- this.previousMovement = {
777
- x: this.movement.x,
778
- y: this.movement.y,
779
- };
780
- this._handleCallback();
781
- };
782
- ScrollGesture.prototype.scrollListener = function () {
783
- var y = window.pageYOffset, x = window.pageXOffset;
784
- this.onScroll({ x: x, y: y });
785
- };
786
- ScrollGesture.prototype.scrollElementListener = function () {
787
- var _a, _b;
788
- var x = ((_a = this.targetElement) === null || _a === void 0 ? void 0 : _a.scrollLeft) || 0;
789
- var y = ((_b = this.targetElement) === null || _b === void 0 ? void 0 : _b.scrollTop) || 0;
790
- this.onScroll({ x: x, y: y });
791
- };
792
- return ScrollGesture;
793
- }(Gesture));
1788
+ /**
1789
+ * interpolate functions maps input range to given output range
1790
+ * @param value - number | TransitionValue
1791
+ * @param inputRange - Array<number>
1792
+ * @param outputRange - Array<number | string>
1793
+ * @param extrapolateConfig - "clamp" | "identity" | "extend"
1794
+ * @returns - number | TransitionValue
1795
+ */
1796
+ function interpolate(value, inputRange, outputRange, extrapolateConfig) {
1797
+ return interpolate$1(value, inputRange, outputRange, extrapolateConfig);
1798
+ }
1799
+ /**
1800
+ * bInterpolate functions maps input range [0, 1] to given [minOutput, maxOutput]
1801
+ * sorthand function to interpolate input range [0, 1]
1802
+ * @param value - number | TransitionValue
1803
+ * @param minOutput - number | string
1804
+ * @param maxOutput - number | string
1805
+ * @param extrapolateConfig - "clamp" | "identity" | "extend"
1806
+ * @returns - number | TransitionValue
1807
+ */
1808
+ function bInterpolate(value, minOutput, maxOutput, extrapolateConfig) {
1809
+ return interpolate$1(value, [0, 1], [minOutput, maxOutput], extrapolateConfig);
1810
+ }
794
1811
 
795
- var LINE_HEIGHT = 40;
796
- var PAGE_HEIGHT = 800;
797
- var WheelGesture = /** @class */ (function (_super) {
798
- __extends(WheelGesture, _super);
799
- function WheelGesture() {
800
- var _this = _super !== null && _super.apply(this, arguments) || this;
801
- _this.movement = withDefault(0, 0);
802
- _this.previousMovement = withDefault(0, 0);
803
- _this.direction = withDefault(0, 0);
804
- _this.velocity = withDefault(0, 0);
805
- _this.delta = withDefault(0, 0);
806
- // Holds offsets
807
- _this.offset = withDefault(0, 0);
808
- _this.translation = withDefault(0, 0);
809
- return _this;
810
- }
811
- // @override
812
- // initialize the events
813
- WheelGesture.prototype._initEvents = function () {
814
- if (this.targetElement) {
815
- this._subscribe = attachEvents([this.targetElement], [['wheel', this.onWheel.bind(this)]]);
816
- }
817
- };
818
- WheelGesture.prototype._handleCallback = function () {
819
- if (this.callback) {
820
- this.callback({
821
- target: this.targetElement,
822
- isWheeling: this.isActive,
823
- deltaX: this.delta.x,
824
- deltaY: this.delta.y,
825
- directionX: this.direction.x,
826
- directionY: this.direction.y,
827
- movementX: this.movement.x,
828
- movementY: this.movement.y,
829
- offsetX: this.offset.x,
830
- offsetY: this.offset.y,
831
- velocityX: this.velocity.x,
832
- velocityY: this.velocity.y,
833
- });
834
- }
835
- };
836
- WheelGesture.prototype.onWheel = function (event) {
837
- var _this = this;
838
- var deltaX = event.deltaX, deltaY = event.deltaY, deltaMode = event.deltaMode;
839
- var now = Date.now();
840
- var deltaTime = Math.min(now - this.lastTimeStamp, 64);
841
- this.lastTimeStamp = now;
842
- var t = deltaTime / 1000; // seconds
843
- this.isActive = true;
844
- if (this.isActiveID !== -1) {
845
- this.isActive = true;
846
- clearTimeout(this.isActiveID);
847
- }
848
- this.isActiveID = setTimeout(function () {
849
- _this.isActive = false;
850
- _this.translation = { x: _this.offset.x, y: _this.offset.y };
851
- _this._handleCallback();
852
- _this.velocity = { x: 0, y: 0 }; // Reset Velocity
853
- _this.movement = { x: 0, y: 0 };
854
- }, 200);
855
- // normalize wheel values, especially for Firefox
856
- if (deltaMode === 1) {
857
- deltaX *= LINE_HEIGHT;
858
- deltaY *= LINE_HEIGHT;
859
- }
860
- else if (deltaMode === 2) {
861
- deltaX *= PAGE_HEIGHT;
862
- deltaY *= PAGE_HEIGHT;
863
- }
864
- this.delta = { x: deltaX, y: deltaY };
865
- this.movement = {
866
- x: this.movement.x + deltaX,
867
- y: this.movement.y + deltaY,
868
- };
869
- this.offset = {
870
- x: this.translation.x + this.movement.x,
871
- y: this.translation.y + this.movement.y,
872
- };
873
- var diffX = this.movement.x - this.previousMovement.x;
874
- var diffY = this.movement.y - this.previousMovement.y;
875
- this.direction = {
876
- x: Math.sign(diffX),
877
- y: Math.sign(diffY),
878
- };
879
- this.velocity = {
880
- x: clamp(diffX / t / 1000, -1 * Gesture._VELOCITY_LIMIT, Gesture._VELOCITY_LIMIT),
881
- y: clamp(diffY / t / 1000, -1 * Gesture._VELOCITY_LIMIT, Gesture._VELOCITY_LIMIT),
882
- };
883
- this.previousMovement = {
884
- x: this.movement.x,
885
- y: this.movement.y,
886
- };
887
- this._handleCallback();
888
- };
889
- return WheelGesture;
890
- }(Gesture));
1812
+ /**
1813
+ * AnimatedBlock - A higher order component built upon `div` element
1814
+ * which can accept `AnimatedValue`. It also exposes some extra style properties like
1815
+ * translateX, translateY, rotateX, rotateY, scaleX, etc.
1816
+ */
1817
+ var AnimatedBlock = makeFluid('div');
891
1818
 
892
- var useRecognizer = function (handlers) {
893
- var ref = React.useRef();
894
- var elementRefs = React.useRef([]);
895
- var subscribers = React.useRef(new Map()).current;
896
- // re-initiate callback on change
897
- React.useEffect(function () {
898
- var e_1, _a;
899
- try {
900
- for (var _b = __values(subscribers.entries()), _c = _b.next(); !_c.done; _c = _b.next()) {
901
- var _d = __read(_c.value, 2), _e = _d[1], keyIndex = _e.keyIndex, gesture = _e.gesture;
902
- var _f = __read(handlers[keyIndex], 3), callback = _f[2];
903
- gesture.applyCallback(callback);
904
- }
905
- }
906
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
907
- finally {
908
- try {
909
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
910
- }
911
- finally { if (e_1) throw e_1.error; }
912
- }
913
- }, [handlers]);
914
- React.useEffect(function () {
915
- handlers.forEach(function (_a, keyIndex) {
916
- var _b = __read(_a, 4), key = _b[0], gesture = _b[1], callback = _b[2], config = _b[3];
917
- subscribers.set(key, {
918
- keyIndex: keyIndex,
919
- gesture: gesture,
920
- unsubscribe: gesture.applyGesture({
921
- targetElement: ref.current,
922
- targetElements: elementRefs.current,
923
- callback: callback,
924
- config: config,
925
- }),
926
- });
927
- });
928
- return function () {
929
- var e_2, _a;
930
- try {
931
- for (var _b = __values(subscribers.entries()), _c = _b.next(); !_c.done; _c = _b.next()) {
932
- var _d = __read(_c.value, 2), unsubscribe = _d[1].unsubscribe;
933
- unsubscribe && unsubscribe();
934
- }
935
- }
936
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
937
- finally {
938
- try {
939
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
940
- }
941
- finally { if (e_2) throw e_2.error; }
942
- }
943
- };
944
- }, []);
945
- return function (index) {
946
- if (index === null || index === undefined) {
947
- return { ref: ref };
948
- }
949
- else {
950
- elementRefs.current[index] =
951
- elementRefs.current[index] || React.createRef();
952
- return { ref: elementRefs.current[index] };
953
- }
954
- };
1819
+ /**
1820
+ * AnimatedInline - A higher order component built upon `span` element
1821
+ * which can accept `AnimatedValue`. It also exposes some extra style properties like
1822
+ * translateX, translateY, rotateX, rotateY, scaleX, etc.
1823
+ */
1824
+ var AnimatedInline = makeFluid('span');
1825
+
1826
+ /**
1827
+ * AnimatedImage - A higher order component built upon `img` element
1828
+ * which can accept `AnimatedValue`. It also exposes some extra style properties like
1829
+ * translateX, translateY, rotateX, rotateY, scaleX, etc.
1830
+ */
1831
+ var AnimatedImage = makeFluid('img');
1832
+
1833
+ /**
1834
+ * `useMountedValue` handles mounting and unmounting of a component which captures current state
1835
+ * passed as an arugment (`state`) and exposes the shadow state which handles the mount and unmount
1836
+ * of a component.
1837
+ *
1838
+ * @param { boolean } state - Boolean indicating the component should mount or unmount.
1839
+ * @param { UseMountedValueConfig } config - Animation configuration.
1840
+ */
1841
+ function useMountedValue(state, config) {
1842
+ var mv = useMount(state, config);
1843
+ return function (cb) { return mv(function (a, m) { return cb({ value: a }, m); }); };
1844
+ }
1845
+
1846
+ /**
1847
+ * MountedBlock - Higher order component which handles mounting and unmounting of a component.
1848
+ * @prop { boolean } state - Boolean indicating the component should mount or unmount.
1849
+ * @prop { function } children - Child as a function with `AnimatedValue` on `.value` property.
1850
+ * @prop { number } from - Number that dictates the beginning state for animation.
1851
+ * @prop { number } enter - Number that dictates the entry state for animation.
1852
+ * @prop { number } exit - Number that dictates the exit state for animation.
1853
+ * @prop { MountedValueConfig } config - Animation configuration for overall animation.
1854
+ * @prop { MountedValueConfig } enterConfig - Animation configuration for the entering state of animation.
1855
+ * @prop { MountedValueConfig } exitConfig - Animation configuration for the entering state of animation.
1856
+ */
1857
+ var MountedBlock = function (_a) {
1858
+ var state = _a.state, children = _a.children, _b = _a.from, from = _b === void 0 ? 0 : _b, _c = _a.enter, enter = _c === void 0 ? 1 : _c, _d = _a.exit, exit = _d === void 0 ? 0 : _d, config = _a.config, enterConfig = _a.enterConfig, exitConfig = _a.exitConfig;
1859
+ var open = useMountedValue(state, {
1860
+ from: from,
1861
+ enter: enter,
1862
+ exit: exit,
1863
+ config: config,
1864
+ enterConfig: enterConfig,
1865
+ exitConfig: exitConfig,
1866
+ });
1867
+ return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: open(function (animation, mounted) { return mounted && children(animation); }) }));
955
1868
  };
956
1869
 
957
- function useDrag(callback, config) {
958
- var gesture = React.useRef(new DragGesture()).current;
959
- return useRecognizer([['drag', gesture, callback, config]]);
1870
+ var getInitialConfig = function (animationType) {
1871
+ switch (animationType) {
1872
+ case 'elastic':
1873
+ return { mass: 1, friction: 18, tension: 250 };
1874
+ case 'stiff':
1875
+ return { mass: 1, friction: 18, tension: 350 };
1876
+ case 'wooble':
1877
+ return { mass: 1, friction: 8, tension: 250 };
1878
+ case 'bounce':
1879
+ return { duration: 500, easing: Easing.bounce };
1880
+ case 'power1':
1881
+ return { duration: 500, easing: Easing.bezier(0.17, 0.42, 0.51, 0.97) };
1882
+ case 'power2':
1883
+ return { duration: 500, easing: Easing.bezier(0.07, 0.11, 0.13, 1) };
1884
+ case 'power3':
1885
+ return { duration: 500, easing: Easing.bezier(0.09, 0.7, 0.16, 1.04) };
1886
+ case 'power4':
1887
+ return { duration: 500, easing: Easing.bezier(0.05, 0.54, 0, 1.03) };
1888
+ case 'linear':
1889
+ return { duration: 500, easing: Easing.linear };
1890
+ case 'easein':
1891
+ return { duration: 500, easing: Easing.in(Easing.ease) };
1892
+ case 'easeout':
1893
+ return { duration: 500, easing: Easing.out(Easing.ease) };
1894
+ case 'easeinout':
1895
+ return { duration: 500, easing: Easing.inOut(Easing.ease) };
1896
+ case 'ease':
1897
+ default:
1898
+ return { mass: 1, friction: 34, tension: 290 };
1899
+ }
1900
+ };
1901
+
1902
+ var AnimationConfigUtils = {
1903
+ ELASTIC: getInitialConfig('elastic'),
1904
+ BOUNCE: getInitialConfig('bounce'),
1905
+ EASE: getInitialConfig('ease'),
1906
+ STIFF: getInitialConfig('stiff'),
1907
+ WOOBLE: getInitialConfig('wooble'),
1908
+ EASE_IN: getInitialConfig('easein'),
1909
+ EASE_OUT: getInitialConfig('easeout'),
1910
+ EASE_IN_OUT: getInitialConfig('easeinout'),
1911
+ POWER1: getInitialConfig('power1'),
1912
+ POWER2: getInitialConfig('power2'),
1913
+ POWER3: getInitialConfig('power3'),
1914
+ POWER4: getInitialConfig('power4'),
1915
+ LINEAR: getInitialConfig('linear'),
1916
+ };
1917
+
1918
+ /**
1919
+ * `useAnimatedValue` returns an animation value with `.value` and `.currentValue` property which is
1920
+ * initialized when passed to argument (`initialValue`). The retured value persist until the lifetime of
1921
+ * a component. It doesnot cast any re-renders which can is very good for performance optimization.
1922
+ *
1923
+ * @param { string | number } initialValue - Initial value
1924
+ * @param { UseAnimatedValueConfig } config - Animation configuration object.
1925
+ */
1926
+ function useAnimatedValue(initialValue, config) {
1927
+ var _a = __read(useFluidValue(initialValue, __assign(__assign({}, AnimationConfigUtils.EASE), config)), 2), animation = _a[0], setAnimation = _a[1];
1928
+ var targetObject = {
1929
+ value: animation,
1930
+ currentValue: animation.get(),
1931
+ };
1932
+ return new Proxy(targetObject, {
1933
+ set: function (_, key, value) {
1934
+ if (key === 'value') {
1935
+ if (typeof value === 'number' || typeof value === 'string') {
1936
+ setAnimation(value);
1937
+ }
1938
+ return true;
1939
+ }
1940
+ throw new Error('You cannot set any other property to animation node.');
1941
+ },
1942
+ get: function (_, key) {
1943
+ if (key === 'value') {
1944
+ return animation;
1945
+ }
1946
+ if (key === 'currentValue') {
1947
+ return animation.get();
1948
+ }
1949
+ throw new Error('You cannot access any other property from animation node.');
1950
+ },
1951
+ });
960
1952
  }
961
1953
 
962
- function useMouseMove(callback) {
963
- var gesture = React.useRef(new MouseMoveGesture()).current;
964
- return useRecognizer([['move', gesture, callback]]);
1954
+ /**
1955
+ * ScrollableBlock - Higher order component to handle the entrance or exit animation
1956
+ * of a component when it enters or exit the viewport. Accepts child as a function with
1957
+ * `AnimatedValue` as its first argument which can be interpolated on input range [0, 1]
1958
+ * @prop { function } children - child as a function with `AnimatedValue` as its first argument.
1959
+ * @prop { 'single' | 'both' } direction - single applies animation on enter once, both applies on enter and exit.
1960
+ * @prop { number } threshold - should be in range 0 to 1 which equivalent to `IntersectionObserver` threshold.
1961
+ * @prop { UseAnimatedValueConfig } animationConfig - Animation config
1962
+ */
1963
+ var ScrollableBlock = function (props) {
1964
+ var children = props.children, _a = props.direction, direction = _a === void 0 ? 'single' : _a, animationConfig = props.animationConfig, _b = props.threshold, threshold = _b === void 0 ? 0.2 : _b;
1965
+ var scrollableBlockRef = React__namespace.useRef(null);
1966
+ var animation = useAnimatedValue(0, animationConfig); // 0: not intersecting | 1: intersecting
1967
+ React__namespace.useEffect(function () {
1968
+ var _scrollableBlock = scrollableBlockRef.current;
1969
+ var observer = new IntersectionObserver(function (_a) {
1970
+ var _b = __read(_a, 1), entry = _b[0];
1971
+ var isIntersecting = entry.isIntersecting;
1972
+ if (isIntersecting) {
1973
+ animation.value = 1;
1974
+ }
1975
+ else {
1976
+ if (direction === 'both')
1977
+ animation.value = 0;
1978
+ }
1979
+ }, {
1980
+ root: null, // FOR VIEWPORT ONLY
1981
+ threshold: threshold,
1982
+ });
1983
+ if (_scrollableBlock) {
1984
+ observer.observe(_scrollableBlock);
1985
+ }
1986
+ return function () {
1987
+ if (_scrollableBlock) {
1988
+ observer.unobserve(_scrollableBlock);
1989
+ }
1990
+ };
1991
+ }, []);
1992
+ return (jsxRuntime.jsx("div", { ref: scrollableBlockRef, children: children && children({ value: animation.value }) }));
1993
+ };
1994
+
1995
+ /**
1996
+ * bin(booleanValue)
1997
+ * returns 1 if booleanValue == true and 0 if booleanValue == false
1998
+ */
1999
+ function bin(bool) {
2000
+ return bool ? 1 : 0;
2001
+ }
2002
+ /**
2003
+ * mix(progress, a, b)
2004
+ * linear interpolation between a and b
2005
+ */
2006
+ function mix(perc, val1, val2) {
2007
+ return val1 * (1 - perc) + val2 * perc;
2008
+ }
2009
+ /**
2010
+ * clamp(value, min, max)
2011
+ * clamps value for min and max bounds
2012
+ */
2013
+ function clamp(value, lowerbound, upperbound) {
2014
+ return Math.min(Math.max(value, lowerbound), upperbound);
2015
+ }
2016
+ function rubber2(distanceFromEdge, constant) {
2017
+ return Math.pow(distanceFromEdge, constant * 5);
965
2018
  }
2019
+ function rubber(distanceFromEdge, dimension, constant) {
2020
+ if (dimension === 0 || Math.abs(dimension) === Infinity)
2021
+ return rubber2(distanceFromEdge, constant);
2022
+ return ((distanceFromEdge * dimension * constant) /
2023
+ (dimension + constant * distanceFromEdge));
2024
+ }
2025
+ /**
2026
+ * rubberClamp(value, min, max, constant?)
2027
+ * constant is optional : default 0.15
2028
+ * clamps the value for min and max value and
2029
+ * extends beyond min and max values with constant
2030
+ * factor to create elastic rubber band effect
2031
+ */
2032
+ function rubberClamp(value, lowerbound, upperbound, constant) {
2033
+ if (constant === void 0) { constant = 0.15; }
2034
+ if (constant === 0)
2035
+ return clamp(value, lowerbound, upperbound);
2036
+ if (value < lowerbound) {
2037
+ return (-rubber(lowerbound - value, upperbound - lowerbound, constant) +
2038
+ lowerbound);
2039
+ }
2040
+ if (value > upperbound) {
2041
+ return (+rubber(value - upperbound, upperbound - lowerbound, constant) +
2042
+ upperbound);
2043
+ }
2044
+ return value;
2045
+ }
2046
+ /**
2047
+ * snapTo(value, velocity, snapPoints[])
2048
+ * Calculates the final snapPoint according to given current value,
2049
+ * velocity and snapPoints array
2050
+ */
2051
+ function snapTo(value, velocity, snapPoints) {
2052
+ var finalValue = value + velocity * 0.2;
2053
+ var getDiff = function (point) { return Math.abs(point - finalValue); };
2054
+ var deltas = snapPoints.map(getDiff);
2055
+ var minDelta = Math.min.apply(Math, __spreadArray([], __read(deltas), false));
2056
+ return snapPoints.reduce(function (acc, point) {
2057
+ if (getDiff(point) === minDelta) {
2058
+ return point;
2059
+ }
2060
+ else {
2061
+ return acc;
2062
+ }
2063
+ });
2064
+ }
2065
+ /**
2066
+ * move(array, moveIndex, toIndex)
2067
+ * move array item from moveIndex to toIndex without array modification
2068
+ */
2069
+ function move(array, moveIndex, toIndex) {
2070
+ var item = array[moveIndex];
2071
+ var length = array.length;
2072
+ var diff = moveIndex - toIndex;
2073
+ if (diff > 0) {
2074
+ return __spreadArray(__spreadArray(__spreadArray(__spreadArray([], __read(array.slice(0, toIndex)), false), [
2075
+ item
2076
+ ], false), __read(array.slice(toIndex, moveIndex)), false), __read(array.slice(moveIndex + 1, length)), false);
2077
+ }
2078
+ else if (diff < 0) {
2079
+ var targetIndex = toIndex + 1;
2080
+ return __spreadArray(__spreadArray(__spreadArray(__spreadArray([], __read(array.slice(0, moveIndex)), false), __read(array.slice(moveIndex + 1, targetIndex)), false), [
2081
+ item
2082
+ ], false), __read(array.slice(targetIndex, length)), false);
2083
+ }
2084
+ return array;
2085
+ }
2086
+
2087
+ /**
2088
+ * TransitionBlock - Higher order component which animates on state change.
2089
+ * @prop { boolean } state - Boolean indicating the current state of animation, usually `false = 0 and true = 1`.
2090
+ * @prop { function } children - Child as a function with `AnimatedValue` on `.value` property.
2091
+ * @prop { UseAnimatedValueConfig } config - Animation configuration.
2092
+ */
2093
+ var TransitionBlock = function (_a) {
2094
+ var state = _a.state, children = _a.children, config = _a.config;
2095
+ var amv = useAnimatedValue(bin(state), config);
2096
+ return jsxRuntime.jsx(jsxRuntime.Fragment, { children: children({ value: amv.value }) });
2097
+ };
966
2098
 
967
- function useScroll(callback) {
968
- var gesture = React.useRef(new ScrollGesture()).current;
969
- return useRecognizer([['scroll', gesture, callback]]);
2099
+ /**
2100
+ * @param { number } ms - number of milliseconds to delay code execution
2101
+ * @returns Promise
2102
+ */
2103
+ function delay(ms) {
2104
+ return new Promise(function (resolve) {
2105
+ setTimeout(function () { return resolve(null); }, ms);
2106
+ });
970
2107
  }
971
2108
 
972
- function useWheel(callback) {
973
- var gesture = React.useRef(new WheelGesture()).current;
974
- return useRecognizer([['wheel', gesture, callback]]);
2109
+ /**
2110
+ * Attach single document / window event / HTMLElement
2111
+ */
2112
+ function attachEvent(domTargets, event, callback, capture) {
2113
+ if (capture === void 0) { capture = false; }
2114
+ domTargets.forEach(function (target) {
2115
+ target.addEventListener(event, callback, capture);
2116
+ });
2117
+ return function () {
2118
+ domTargets.forEach(function (target) {
2119
+ target.removeEventListener(event, callback, capture);
2120
+ });
2121
+ };
2122
+ }
2123
+ /**
2124
+ * Attach multiple document / window event / HTMLElement
2125
+ */
2126
+ function attachEvents(domTargets, events) {
2127
+ var subscribers = new Map();
2128
+ events.forEach(function (_a) {
2129
+ var _b = __read(_a, 3), event = _b[0], callback = _b[1], _c = _b[2], capture = _c === void 0 ? false : _c;
2130
+ subscribers.set(event, attachEvent(domTargets, event, callback, capture));
2131
+ });
2132
+ return function (eventKeys) {
2133
+ var e_1, _a;
2134
+ try {
2135
+ for (var _b = __values(subscribers.entries()), _c = _b.next(); !_c.done; _c = _b.next()) {
2136
+ var _d = __read(_c.value, 2), eventKey = _d[0], subscriber = _d[1];
2137
+ if (!eventKeys) {
2138
+ subscriber();
2139
+ return;
2140
+ }
2141
+ if (eventKeys.indexOf(eventKey) !== -1) {
2142
+ subscriber();
2143
+ }
2144
+ }
2145
+ }
2146
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
2147
+ finally {
2148
+ try {
2149
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
2150
+ }
2151
+ finally { if (e_1) throw e_1.error; }
2152
+ }
2153
+ };
975
2154
  }
976
2155
 
977
- function useGesture(_a) {
978
- var onDrag = _a.onDrag, onWheel = _a.onWheel, onScroll = _a.onScroll, onMouseMove = _a.onMouseMove;
979
- var dragGesture = React.useRef(new DragGesture()).current;
980
- var wheelGesture = React.useRef(new WheelGesture()).current;
981
- var scrollGesture = React.useRef(new ScrollGesture()).current;
982
- var mouseMoveGesture = React.useRef(new MouseMoveGesture()).current;
983
- return useRecognizer([
984
- ['drag', dragGesture, onDrag],
985
- ['wheel', wheelGesture, onWheel],
986
- ['scroll', scrollGesture, onScroll],
987
- ['move', mouseMoveGesture, onMouseMove],
988
- ]);
2156
+ function useOutsideClick(elementRef, callback, deps) {
2157
+ var callbackRef = React.useRef();
2158
+ if (!callbackRef.current) {
2159
+ callbackRef.current = callback;
2160
+ }
2161
+ // Reinitiate callback when dependency change
2162
+ React.useEffect(function () {
2163
+ callbackRef.current = callback;
2164
+ return function () {
2165
+ callbackRef.current = function () { return false; };
2166
+ };
2167
+ }, deps);
2168
+ React.useEffect(function () {
2169
+ var handleOutsideClick = function (e) {
2170
+ var _a;
2171
+ if (!((_a = elementRef === null || elementRef === void 0 ? void 0 : elementRef.current) === null || _a === void 0 ? void 0 : _a.contains(e.target))) {
2172
+ callbackRef.current && callbackRef.current(e);
2173
+ }
2174
+ };
2175
+ var subscribe = attachEvents([document], [['click', handleOutsideClick]]);
2176
+ return function () { return subscribe && subscribe(); };
2177
+ }, []);
989
2178
  }
990
2179
 
991
- function useOutsideClick(elementRef, callback, deps) {
992
- var callbackRef = React.useRef();
993
- if (!callbackRef.current) {
994
- callbackRef.current = callback;
995
- }
996
- // Reinitiate callback when dependency change
997
- React.useEffect(function () {
998
- callbackRef.current = callback;
999
- return function () {
1000
- callbackRef.current = function () { return false; };
1001
- };
1002
- }, deps);
1003
- React.useEffect(function () {
1004
- var handleOutsideClick = function (e) {
1005
- var _a;
1006
- if (!((_a = elementRef === null || elementRef === void 0 ? void 0 : elementRef.current) === null || _a === void 0 ? void 0 : _a.contains(e.target))) {
1007
- callbackRef.current && callbackRef.current(e);
1008
- }
1009
- };
1010
- var subscribe = attachEvents([document], [["click", handleOutsideClick]]);
1011
- return function () { return subscribe && subscribe(); };
1012
- }, []);
2180
+ function useMeasure(callback, deps) {
2181
+ var ref = React.useRef(null);
2182
+ var elementRefs = React.useRef([]);
2183
+ var callbackRef = React.useRef(callback);
2184
+ // Reinitiate callback when dependency change
2185
+ React.useEffect(function () {
2186
+ callbackRef.current = callback;
2187
+ return function () {
2188
+ callbackRef.current = function () { return false; };
2189
+ };
2190
+ }, deps);
2191
+ React.useEffect(function () {
2192
+ var _refElement = ref.current || document.documentElement;
2193
+ var _refElementsMultiple = elementRefs.current;
2194
+ var resizeObserver = new ResizeObserver(function (_a) {
2195
+ var _b = __read(_a, 1), entry = _b[0];
2196
+ var _c = entry.target.getBoundingClientRect(), left = _c.left, top = _c.top, width = _c.width, height = _c.height;
2197
+ var pageXOffset = window.pageXOffset, pageYOffset = window.pageYOffset;
2198
+ if (callbackRef) {
2199
+ if (_refElement === document.documentElement) {
2200
+ return; // no-op for document
2201
+ }
2202
+ else {
2203
+ callbackRef.current({
2204
+ left: left + pageXOffset,
2205
+ top: top + pageYOffset,
2206
+ width: width,
2207
+ height: height,
2208
+ vLeft: left,
2209
+ vTop: top,
2210
+ });
2211
+ }
2212
+ }
2213
+ });
2214
+ var resizeObserverMultiple = new ResizeObserver(function (entries) {
2215
+ var left = [];
2216
+ var top = [];
2217
+ var width = [];
2218
+ var height = [];
2219
+ var vLeft = [];
2220
+ var vTop = [];
2221
+ entries.forEach(function (entry) {
2222
+ var _a = entry.target.getBoundingClientRect(), _left = _a.left, _top = _a.top, _width = _a.width, _height = _a.height;
2223
+ var pageXOffset = window.pageXOffset, pageYOffset = window.pageYOffset;
2224
+ var _pageLeft = _left + pageXOffset;
2225
+ var _pageTop = _top + pageYOffset;
2226
+ left.push(_pageLeft);
2227
+ top.push(_pageTop);
2228
+ width.push(_width);
2229
+ height.push(_height);
2230
+ vLeft.push(_left);
2231
+ vTop.push(_top);
2232
+ });
2233
+ if (callbackRef) {
2234
+ callbackRef.current({
2235
+ left: left,
2236
+ top: top,
2237
+ width: width,
2238
+ height: height,
2239
+ vLeft: vLeft,
2240
+ vTop: vTop,
2241
+ });
2242
+ }
2243
+ });
2244
+ if (_refElement) {
2245
+ if (_refElement === document.documentElement &&
2246
+ _refElementsMultiple.length > 0) {
2247
+ _refElementsMultiple.forEach(function (element) {
2248
+ resizeObserverMultiple.observe(element.current);
2249
+ });
2250
+ }
2251
+ else {
2252
+ resizeObserver.observe(_refElement);
2253
+ }
2254
+ }
2255
+ return function () {
2256
+ if (_refElement) {
2257
+ if (_refElement === document.documentElement &&
2258
+ _refElementsMultiple.length > 0) {
2259
+ _refElementsMultiple.forEach(function (element) {
2260
+ resizeObserverMultiple.unobserve(element.current);
2261
+ });
2262
+ }
2263
+ else {
2264
+ resizeObserver.unobserve(_refElement);
2265
+ }
2266
+ }
2267
+ };
2268
+ }, []);
2269
+ return function (index) {
2270
+ if (index === null || index === undefined) {
2271
+ return { ref: ref };
2272
+ }
2273
+ else {
2274
+ elementRefs.current[index] = elementRefs.current[index] || React.createRef();
2275
+ return { ref: elementRefs.current[index] };
2276
+ }
2277
+ }; // ...bind() or ...bind(index) for multiple
1013
2278
  }
1014
2279
 
1015
- function useMeasure(callback, deps) {
1016
- var ref = React.useRef(null);
1017
- var elementRefs = React.useRef([]);
1018
- var callbackRef = React.useRef(callback);
1019
- // Reinitiate callback when dependency change
1020
- React.useEffect(function () {
1021
- callbackRef.current = callback;
1022
- return function () {
1023
- callbackRef.current = function () { return false; };
1024
- };
1025
- }, deps);
1026
- React.useEffect(function () {
1027
- var _refElement = ref.current || document.documentElement;
1028
- var _refElementsMultiple = elementRefs.current;
1029
- var resizeObserver = new ResizeObserver(function (_a) {
1030
- var _b = __read(_a, 1), entry = _b[0];
1031
- var _c = entry.target.getBoundingClientRect(), left = _c.left, top = _c.top, width = _c.width, height = _c.height;
1032
- var pageXOffset = window.pageXOffset, pageYOffset = window.pageYOffset;
1033
- if (callbackRef) {
1034
- if (_refElement === document.documentElement) {
1035
- return; // no-op for document
1036
- }
1037
- else {
1038
- callbackRef.current({
1039
- left: left + pageXOffset,
1040
- top: top + pageYOffset,
1041
- width: width,
1042
- height: height,
1043
- vLeft: left,
1044
- vTop: top,
1045
- });
1046
- }
1047
- }
1048
- });
1049
- var resizeObserverMultiple = new ResizeObserver(function (entries) {
1050
- var left = [];
1051
- var top = [];
1052
- var width = [];
1053
- var height = [];
1054
- var vLeft = [];
1055
- var vTop = [];
1056
- entries.forEach(function (entry) {
1057
- var _a = entry.target.getBoundingClientRect(), _left = _a.left, _top = _a.top, _width = _a.width, _height = _a.height;
1058
- var pageXOffset = window.pageXOffset, pageYOffset = window.pageYOffset;
1059
- var _pageLeft = _left + pageXOffset;
1060
- var _pageTop = _top + pageYOffset;
1061
- left.push(_pageLeft);
1062
- top.push(_pageTop);
1063
- width.push(_width);
1064
- height.push(_height);
1065
- vLeft.push(_left);
1066
- vTop.push(_top);
1067
- });
1068
- if (callbackRef) {
1069
- callbackRef.current({
1070
- left: left,
1071
- top: top,
1072
- width: width,
1073
- height: height,
1074
- vLeft: vLeft,
1075
- vTop: vTop,
1076
- });
1077
- }
1078
- });
1079
- if (_refElement) {
1080
- if (_refElement === document.documentElement &&
1081
- _refElementsMultiple.length > 0) {
1082
- _refElementsMultiple.forEach(function (element) {
1083
- resizeObserverMultiple.observe(element.current);
1084
- });
1085
- }
1086
- else {
1087
- resizeObserver.observe(_refElement);
1088
- }
1089
- }
1090
- return function () {
1091
- if (_refElement) {
1092
- if (_refElement === document.documentElement &&
1093
- _refElementsMultiple.length > 0) {
1094
- _refElementsMultiple.forEach(function (element) {
1095
- resizeObserverMultiple.unobserve(element.current);
1096
- });
1097
- }
1098
- else {
1099
- resizeObserver.unobserve(_refElement);
1100
- }
1101
- }
1102
- };
1103
- }, []);
1104
- return function (index) {
1105
- if (index === null || index === undefined) {
1106
- return { ref: ref };
1107
- }
1108
- else {
1109
- elementRefs.current[index] =
1110
- elementRefs.current[index] || React.createRef();
1111
- return { ref: elementRefs.current[index] };
1112
- }
1113
- }; // ...bind() or ...bind(index) for multiple
2280
+ function useWindowDimension(callback, deps) {
2281
+ var windowDimensionsRef = React.useRef({
2282
+ width: 0,
2283
+ height: 0,
2284
+ innerWidth: 0,
2285
+ innerHeight: 0,
2286
+ });
2287
+ var callbackRef = React.useRef(callback);
2288
+ var handleCallback = function () {
2289
+ if (callbackRef) {
2290
+ callbackRef.current(__assign({}, windowDimensionsRef.current));
2291
+ }
2292
+ };
2293
+ // Reinitiate callback when dependency change
2294
+ React.useEffect(function () {
2295
+ callbackRef.current = callback;
2296
+ return function () {
2297
+ callbackRef.current = function () { return false; };
2298
+ };
2299
+ }, deps);
2300
+ React.useEffect(function () {
2301
+ var resizeObserver = new ResizeObserver(function (_a) {
2302
+ var _b = __read(_a, 1), entry = _b[0];
2303
+ var _c = entry.target, clientWidth = _c.clientWidth, clientHeight = _c.clientHeight;
2304
+ var innerWidth = window.innerWidth, innerHeight = window.innerHeight;
2305
+ windowDimensionsRef.current = {
2306
+ width: clientWidth,
2307
+ height: clientHeight,
2308
+ innerWidth: innerWidth,
2309
+ innerHeight: innerHeight,
2310
+ };
2311
+ handleCallback();
2312
+ });
2313
+ resizeObserver.observe(document.documentElement);
2314
+ return function () { return resizeObserver.unobserve(document.documentElement); };
2315
+ }, []);
1114
2316
  }
1115
2317
 
1116
- function useWindowDimension(callback, deps) {
1117
- var windowDimensionsRef = React.useRef({
1118
- width: 0,
1119
- height: 0,
1120
- innerWidth: 0,
1121
- innerHeight: 0,
1122
- });
1123
- var callbackRef = React.useRef(callback);
1124
- var handleCallback = function () {
1125
- if (callbackRef) {
1126
- callbackRef.current(__assign({}, windowDimensionsRef.current));
1127
- }
1128
- };
1129
- // Reinitiate callback when dependency change
1130
- React.useEffect(function () {
1131
- callbackRef.current = callback;
1132
- return function () {
1133
- callbackRef.current = function () { return false; };
1134
- };
1135
- }, deps);
1136
- React.useEffect(function () {
1137
- var resizeObserver = new ResizeObserver(function (_a) {
1138
- var _b = __read(_a, 1), entry = _b[0];
1139
- var _c = entry.target, clientWidth = _c.clientWidth, clientHeight = _c.clientHeight;
1140
- var innerWidth = window.innerWidth, innerHeight = window.innerHeight;
1141
- windowDimensionsRef.current = {
1142
- width: clientWidth,
1143
- height: clientHeight,
1144
- innerWidth: innerWidth,
1145
- innerHeight: innerHeight,
1146
- };
1147
- handleCallback();
1148
- });
1149
- resizeObserver.observe(document.documentElement);
1150
- return function () { return resizeObserver.unobserve(document.documentElement); };
1151
- }, []);
2318
+ var withDefault = function (x, y) {
2319
+ return { x: x, y: y };
2320
+ };
2321
+
2322
+ var Gesture = /** @class */ (function () {
2323
+ function Gesture() {
2324
+ this.lastTimeStamp = Date.now();
2325
+ this.isActive = false;
2326
+ this.targetElements = []; // represents the bounded elements
2327
+ }
2328
+ // it must be overridden by other child classes
2329
+ Gesture.prototype._initEvents = function () { };
2330
+ // cancel events
2331
+ // we only canceled down and move events because mouse up
2332
+ // will not be triggered
2333
+ Gesture.prototype._cancelEvents = function () {
2334
+ if (this._subscribe) {
2335
+ this._subscribe();
2336
+ }
2337
+ };
2338
+ // re-apply new callback
2339
+ Gesture.prototype.applyCallback = function (callback) {
2340
+ this.callback = callback;
2341
+ };
2342
+ // apply gesture
2343
+ Gesture.prototype.applyGesture = function (_a) {
2344
+ var _this = this;
2345
+ var targetElement = _a.targetElement, targetElements = _a.targetElements, callback = _a.callback, config = _a.config;
2346
+ this.targetElement = targetElement;
2347
+ this.targetElements = targetElements.map(function (element) { return element.current; });
2348
+ this.callback = callback;
2349
+ this.config = config;
2350
+ // initialize events
2351
+ this._initEvents();
2352
+ // unbind
2353
+ return function () { return _this._subscribe && _this._subscribe(); };
2354
+ };
2355
+ Gesture._VELOCITY_LIMIT = 20;
2356
+ return Gesture;
2357
+ }());
2358
+
2359
+ var DragGesture = /** @class */ (function (_super) {
2360
+ __extends(DragGesture, _super);
2361
+ function DragGesture() {
2362
+ var _this = _super.apply(this, __spreadArray([], __read(arguments), false)) || this;
2363
+ _this.movementStart = withDefault(0, 0);
2364
+ _this.initialMovement = withDefault(0, 0);
2365
+ _this.movement = withDefault(0, 0);
2366
+ _this.previousMovement = withDefault(0, 0);
2367
+ _this.translation = withDefault(0, 0);
2368
+ _this.offset = withDefault(0, 0);
2369
+ _this.velocity = withDefault(0, 0);
2370
+ return _this;
2371
+ }
2372
+ // @override
2373
+ // initialize the events
2374
+ DragGesture.prototype._initEvents = function () {
2375
+ if (this.targetElement || this.targetElements.length > 0) {
2376
+ this._subscribe = attachEvents([window], [
2377
+ ['mousedown', this.pointerDown.bind(this)],
2378
+ ['mousemove', this.pointerMove.bind(this)],
2379
+ ['mouseup', this.pointerUp.bind(this)],
2380
+ ['touchstart', this.pointerDown.bind(this), { passive: false }],
2381
+ ['touchmove', this.pointerMove.bind(this), { passive: false }],
2382
+ ['touchend', this.pointerUp.bind(this)],
2383
+ ]);
2384
+ }
2385
+ };
2386
+ // @override - cancel events
2387
+ // we only canceled down and move events because mouse up
2388
+ // will not be triggered
2389
+ DragGesture.prototype._cancelEvents = function () {
2390
+ if (this._subscribe) {
2391
+ this._subscribe(['mousedown', 'mousemove', 'touchstart', 'touchmove']);
2392
+ }
2393
+ };
2394
+ DragGesture.prototype._handleCallback = function () {
2395
+ var _this = this;
2396
+ if (this.callback) {
2397
+ this.callback({
2398
+ args: [this.currentIndex],
2399
+ down: this.isActive,
2400
+ movementX: this.movement.x,
2401
+ movementY: this.movement.y,
2402
+ offsetX: this.translation.x,
2403
+ offsetY: this.translation.y,
2404
+ velocityX: this.velocity.x,
2405
+ velocityY: this.velocity.y,
2406
+ distanceX: Math.abs(this.movement.x),
2407
+ distanceY: Math.abs(this.movement.y),
2408
+ directionX: Math.sign(this.movement.x),
2409
+ directionY: Math.sign(this.movement.y),
2410
+ cancel: function () {
2411
+ _this._cancelEvents();
2412
+ },
2413
+ });
2414
+ }
2415
+ };
2416
+ DragGesture.prototype.pointerDown = function (e) {
2417
+ var _a;
2418
+ if (e.type === 'touchstart') {
2419
+ this.movementStart = {
2420
+ x: e.touches[0].clientX,
2421
+ y: e.touches[0].clientY,
2422
+ };
2423
+ }
2424
+ else {
2425
+ this.movementStart = { x: e.clientX, y: e.clientY };
2426
+ }
2427
+ this.movement = { x: 0, y: 0 };
2428
+ this.offset = { x: this.translation.x, y: this.translation.y };
2429
+ this.previousMovement = { x: 0, y: 0 };
2430
+ this.velocity = { x: 0, y: 0 };
2431
+ // find current selected element
2432
+ var currElem = this.targetElements.find(function (elem) { return elem === e.target; });
2433
+ if (e.target === this.targetElement || currElem) {
2434
+ this.isActive = true;
2435
+ e.preventDefault();
2436
+ // set args
2437
+ if (currElem) {
2438
+ this.currentIndex = this.targetElements.indexOf(currElem);
2439
+ }
2440
+ // if initial function is defined then call it to get initial movementX and movementY
2441
+ // if only select to bounded draggable element
2442
+ var initial = ((_a = this.config) === null || _a === void 0 ? void 0 : _a.initial) && this.config.initial();
2443
+ var initialMovementX = initial === null || initial === void 0 ? void 0 : initial.movementX;
2444
+ var initialMovementY = initial === null || initial === void 0 ? void 0 : initial.movementY;
2445
+ this.initialMovement = {
2446
+ x: initialMovementX !== null && initialMovementX !== void 0 ? initialMovementX : 0,
2447
+ y: initialMovementY !== null && initialMovementY !== void 0 ? initialMovementY : 0,
2448
+ };
2449
+ this.movement = {
2450
+ x: this.initialMovement.x,
2451
+ y: this.initialMovement.y,
2452
+ };
2453
+ this.previousMovement = {
2454
+ x: this.initialMovement.x,
2455
+ y: this.initialMovement.y,
2456
+ };
2457
+ this._handleCallback();
2458
+ }
2459
+ };
2460
+ DragGesture.prototype.pointerMove = function (e) {
2461
+ if (this.isActive) {
2462
+ e.preventDefault();
2463
+ var now = Date.now();
2464
+ var deltaTime = clamp(now - this.lastTimeStamp, 0.1, 64);
2465
+ this.lastTimeStamp = now;
2466
+ var t = deltaTime / 1000;
2467
+ if (e.type === 'touchmove') {
2468
+ this.movement = {
2469
+ x: this.initialMovement.x +
2470
+ (e.touches[0].clientX - this.movementStart.x),
2471
+ y: this.initialMovement.y +
2472
+ (e.touches[0].clientY - this.movementStart.y),
2473
+ };
2474
+ }
2475
+ else {
2476
+ this.movement = {
2477
+ x: this.initialMovement.x + (e.clientX - this.movementStart.x),
2478
+ y: this.initialMovement.y + (e.clientY - this.movementStart.y),
2479
+ };
2480
+ }
2481
+ this.translation = {
2482
+ x: this.offset.x + this.movement.x,
2483
+ y: this.offset.y + this.movement.y,
2484
+ };
2485
+ this.velocity = {
2486
+ x: clamp((this.movement.x - this.previousMovement.x) / t / 1000, -1 * Gesture._VELOCITY_LIMIT, Gesture._VELOCITY_LIMIT),
2487
+ y: clamp((this.movement.y - this.previousMovement.y) / t / 1000, -1 * Gesture._VELOCITY_LIMIT, Gesture._VELOCITY_LIMIT),
2488
+ };
2489
+ this.previousMovement = {
2490
+ x: this.movement.x,
2491
+ y: this.movement.y,
2492
+ };
2493
+ this._handleCallback();
2494
+ }
2495
+ };
2496
+ DragGesture.prototype.pointerUp = function () {
2497
+ if (this.isActive) {
2498
+ this.isActive = false;
2499
+ this._handleCallback();
2500
+ this._cancelEvents();
2501
+ this._initEvents();
2502
+ }
2503
+ };
2504
+ return DragGesture;
2505
+ }(Gesture));
2506
+
2507
+ var MouseMoveGesture = /** @class */ (function (_super) {
2508
+ __extends(MouseMoveGesture, _super);
2509
+ function MouseMoveGesture() {
2510
+ var _this = _super.apply(this, __spreadArray([], __read(arguments), false)) || this;
2511
+ _this.movement = withDefault(0, 0);
2512
+ _this.previousMovement = withDefault(0, 0);
2513
+ _this.velocity = withDefault(0, 0);
2514
+ _this.direction = withDefault(0, 0);
2515
+ return _this;
2516
+ }
2517
+ // @override
2518
+ // initialize the events
2519
+ MouseMoveGesture.prototype._initEvents = function () {
2520
+ if (this.targetElement) {
2521
+ this._subscribe = attachEvents([this.targetElement], [['mousemove', this.onMouseMove.bind(this)]]);
2522
+ }
2523
+ else if (this.targetElements.length > 0) {
2524
+ this._subscribe = attachEvents(this.targetElements, [
2525
+ ['mousemove', this.onMouseMove.bind(this)],
2526
+ ]);
2527
+ }
2528
+ else {
2529
+ this._subscribe = attachEvents([window], [['mousemove', this.onMouseMove.bind(this)]]);
2530
+ }
2531
+ };
2532
+ MouseMoveGesture.prototype._handleCallback = function () {
2533
+ var _a;
2534
+ if (this.callback) {
2535
+ this.callback({
2536
+ args: [this.currentIndex],
2537
+ event: this.event,
2538
+ isMoving: this.isActive,
2539
+ target: (_a = this.event) === null || _a === void 0 ? void 0 : _a.target,
2540
+ mouseX: this.movement.x,
2541
+ mouseY: this.movement.y,
2542
+ velocityX: this.velocity.x,
2543
+ velocityY: this.velocity.y,
2544
+ directionX: this.direction.x,
2545
+ directionY: this.direction.y,
2546
+ });
2547
+ }
2548
+ };
2549
+ MouseMoveGesture.prototype.onMouseMove = function (e) {
2550
+ var _this = this;
2551
+ // find current selected element
2552
+ var currElem = this.targetElements.find(function (elem) { return elem === e.target; });
2553
+ // set args
2554
+ if (currElem) {
2555
+ this.currentIndex = this.targetElements.indexOf(currElem);
2556
+ }
2557
+ this.event = e;
2558
+ var now = Date.now();
2559
+ var deltaTime = Math.min(now - this.lastTimeStamp, 64);
2560
+ this.lastTimeStamp = now;
2561
+ var t = deltaTime / 1000; // seconds
2562
+ var x = e.clientX;
2563
+ var y = e.clientY;
2564
+ this.movement = { x: x, y: y };
2565
+ if (this.isActiveID !== -1) {
2566
+ this.isActive = true;
2567
+ clearTimeout(this.isActiveID);
2568
+ }
2569
+ this.isActiveID = setTimeout(function () {
2570
+ _this.isActive = false;
2571
+ _this.direction = { x: 0, y: 0 };
2572
+ _this.velocity = { x: 0, y: 0 };
2573
+ _this._handleCallback();
2574
+ }, 250); // Debounce 250 milliseconds
2575
+ var diffX = this.movement.x - this.previousMovement.x;
2576
+ var diffY = this.movement.y - this.previousMovement.y;
2577
+ this.direction = {
2578
+ x: Math.sign(diffX),
2579
+ y: Math.sign(diffY),
2580
+ };
2581
+ this.velocity = {
2582
+ x: clamp(diffX / t / 1000, -1 * Gesture._VELOCITY_LIMIT, Gesture._VELOCITY_LIMIT),
2583
+ y: clamp(diffY / t / 1000, -1 * Gesture._VELOCITY_LIMIT, Gesture._VELOCITY_LIMIT),
2584
+ };
2585
+ this.previousMovement = { x: this.movement.x, y: this.movement.y };
2586
+ this._handleCallback();
2587
+ };
2588
+ return MouseMoveGesture;
2589
+ }(Gesture));
2590
+
2591
+ var ScrollGesture = /** @class */ (function (_super) {
2592
+ __extends(ScrollGesture, _super);
2593
+ function ScrollGesture() {
2594
+ var _this = _super.apply(this, __spreadArray([], __read(arguments), false)) || this;
2595
+ _this.movement = withDefault(0, 0);
2596
+ _this.previousMovement = withDefault(0, 0);
2597
+ _this.direction = withDefault(0, 0);
2598
+ _this.velocity = withDefault(0, 0);
2599
+ return _this;
2600
+ }
2601
+ // @override
2602
+ // initialize the events
2603
+ ScrollGesture.prototype._initEvents = function () {
2604
+ if (this.targetElement) {
2605
+ this._subscribe = attachEvents([this.targetElement], [['scroll', this.scrollElementListener.bind(this)]]);
2606
+ }
2607
+ else {
2608
+ this._subscribe = attachEvents([window], [['scroll', this.scrollListener.bind(this)]]);
2609
+ }
2610
+ };
2611
+ ScrollGesture.prototype._handleCallback = function () {
2612
+ if (this.callback) {
2613
+ this.callback({
2614
+ isScrolling: this.isActive,
2615
+ scrollX: this.movement.x,
2616
+ scrollY: this.movement.y,
2617
+ velocityX: this.velocity.x,
2618
+ velocityY: this.velocity.y,
2619
+ directionX: this.direction.x,
2620
+ directionY: this.direction.y,
2621
+ });
2622
+ }
2623
+ };
2624
+ ScrollGesture.prototype.onScroll = function (_a) {
2625
+ var _this = this;
2626
+ var x = _a.x, y = _a.y;
2627
+ var now = Date.now();
2628
+ var deltaTime = Math.min(now - this.lastTimeStamp, 64);
2629
+ this.lastTimeStamp = now;
2630
+ var t = deltaTime / 1000; // seconds
2631
+ this.movement = { x: x, y: y };
2632
+ // Clear if scrolling
2633
+ if (this.isActiveID !== -1) {
2634
+ this.isActive = true;
2635
+ clearTimeout(this.isActiveID);
2636
+ }
2637
+ this.isActiveID = setTimeout(function () {
2638
+ _this.isActive = false;
2639
+ _this.direction = { x: 0, y: 0 };
2640
+ // Reset Velocity
2641
+ _this.velocity = { x: 0, y: 0 };
2642
+ _this._handleCallback(); // Debounce 250milliseconds
2643
+ }, 250);
2644
+ var diffX = this.movement.x - this.previousMovement.x;
2645
+ var diffY = this.movement.y - this.previousMovement.y;
2646
+ this.direction = {
2647
+ x: Math.sign(diffX),
2648
+ y: Math.sign(diffY),
2649
+ };
2650
+ this.velocity = {
2651
+ x: clamp(diffX / t / 1000, -1 * Gesture._VELOCITY_LIMIT, Gesture._VELOCITY_LIMIT),
2652
+ y: clamp(diffY / t / 1000, -1 * Gesture._VELOCITY_LIMIT, Gesture._VELOCITY_LIMIT),
2653
+ };
2654
+ this.previousMovement = {
2655
+ x: this.movement.x,
2656
+ y: this.movement.y,
2657
+ };
2658
+ this._handleCallback();
2659
+ };
2660
+ ScrollGesture.prototype.scrollListener = function () {
2661
+ var y = window.pageYOffset, x = window.pageXOffset;
2662
+ this.onScroll({ x: x, y: y });
2663
+ };
2664
+ ScrollGesture.prototype.scrollElementListener = function () {
2665
+ var _a, _b;
2666
+ var x = ((_a = this.targetElement) === null || _a === void 0 ? void 0 : _a.scrollLeft) || 0;
2667
+ var y = ((_b = this.targetElement) === null || _b === void 0 ? void 0 : _b.scrollTop) || 0;
2668
+ this.onScroll({ x: x, y: y });
2669
+ };
2670
+ return ScrollGesture;
2671
+ }(Gesture));
2672
+
2673
+ var LINE_HEIGHT = 40;
2674
+ var PAGE_HEIGHT = 800;
2675
+ var WheelGesture = /** @class */ (function (_super) {
2676
+ __extends(WheelGesture, _super);
2677
+ function WheelGesture() {
2678
+ var _this = _super.apply(this, __spreadArray([], __read(arguments), false)) || this;
2679
+ _this.movement = withDefault(0, 0);
2680
+ _this.previousMovement = withDefault(0, 0);
2681
+ _this.direction = withDefault(0, 0);
2682
+ _this.velocity = withDefault(0, 0);
2683
+ _this.delta = withDefault(0, 0);
2684
+ // Holds offsets
2685
+ _this.offset = withDefault(0, 0);
2686
+ _this.translation = withDefault(0, 0);
2687
+ return _this;
2688
+ }
2689
+ // @override
2690
+ // initialize the events
2691
+ WheelGesture.prototype._initEvents = function () {
2692
+ if (this.targetElement) {
2693
+ this._subscribe = attachEvents([this.targetElement], [['wheel', this.onWheel.bind(this)]]);
2694
+ }
2695
+ };
2696
+ WheelGesture.prototype._handleCallback = function () {
2697
+ if (this.callback) {
2698
+ this.callback({
2699
+ target: this.targetElement,
2700
+ isWheeling: this.isActive,
2701
+ deltaX: this.delta.x,
2702
+ deltaY: this.delta.y,
2703
+ directionX: this.direction.x,
2704
+ directionY: this.direction.y,
2705
+ movementX: this.movement.x,
2706
+ movementY: this.movement.y,
2707
+ offsetX: this.offset.x,
2708
+ offsetY: this.offset.y,
2709
+ velocityX: this.velocity.x,
2710
+ velocityY: this.velocity.y,
2711
+ });
2712
+ }
2713
+ };
2714
+ WheelGesture.prototype.onWheel = function (event) {
2715
+ var _this = this;
2716
+ var deltaX = event.deltaX, deltaY = event.deltaY, deltaMode = event.deltaMode;
2717
+ var now = Date.now();
2718
+ var deltaTime = Math.min(now - this.lastTimeStamp, 64);
2719
+ this.lastTimeStamp = now;
2720
+ var t = deltaTime / 1000; // seconds
2721
+ this.isActive = true;
2722
+ if (this.isActiveID !== -1) {
2723
+ this.isActive = true;
2724
+ clearTimeout(this.isActiveID);
2725
+ }
2726
+ this.isActiveID = setTimeout(function () {
2727
+ _this.isActive = false;
2728
+ _this.translation = { x: _this.offset.x, y: _this.offset.y };
2729
+ _this._handleCallback();
2730
+ _this.velocity = { x: 0, y: 0 }; // Reset Velocity
2731
+ _this.movement = { x: 0, y: 0 };
2732
+ }, 200);
2733
+ // normalize wheel values, especially for Firefox
2734
+ if (deltaMode === 1) {
2735
+ deltaX *= LINE_HEIGHT;
2736
+ deltaY *= LINE_HEIGHT;
2737
+ }
2738
+ else if (deltaMode === 2) {
2739
+ deltaX *= PAGE_HEIGHT;
2740
+ deltaY *= PAGE_HEIGHT;
2741
+ }
2742
+ this.delta = { x: deltaX, y: deltaY };
2743
+ this.movement = {
2744
+ x: this.movement.x + deltaX,
2745
+ y: this.movement.y + deltaY,
2746
+ };
2747
+ this.offset = {
2748
+ x: this.translation.x + this.movement.x,
2749
+ y: this.translation.y + this.movement.y,
2750
+ };
2751
+ var diffX = this.movement.x - this.previousMovement.x;
2752
+ var diffY = this.movement.y - this.previousMovement.y;
2753
+ this.direction = {
2754
+ x: Math.sign(diffX),
2755
+ y: Math.sign(diffY),
2756
+ };
2757
+ this.velocity = {
2758
+ x: clamp(diffX / t / 1000, -1 * Gesture._VELOCITY_LIMIT, Gesture._VELOCITY_LIMIT),
2759
+ y: clamp(diffY / t / 1000, -1 * Gesture._VELOCITY_LIMIT, Gesture._VELOCITY_LIMIT),
2760
+ };
2761
+ this.previousMovement = {
2762
+ x: this.movement.x,
2763
+ y: this.movement.y,
2764
+ };
2765
+ this._handleCallback();
2766
+ };
2767
+ return WheelGesture;
2768
+ }(Gesture));
2769
+
2770
+ var useRecognizer = function (handlers) {
2771
+ var ref = React__namespace.useRef();
2772
+ var elementRefs = React__namespace.useRef([]);
2773
+ var subscribers = React__namespace.useRef(new Map()).current;
2774
+ // re-initiate callback on change
2775
+ React__namespace.useEffect(function () {
2776
+ var e_1, _a;
2777
+ try {
2778
+ for (var _b = __values(subscribers.entries()), _c = _b.next(); !_c.done; _c = _b.next()) {
2779
+ var _d = __read(_c.value, 2), _e = _d[1], keyIndex = _e.keyIndex, gesture = _e.gesture;
2780
+ var _f = __read(handlers[keyIndex], 3), callback = _f[2];
2781
+ gesture.applyCallback(callback);
2782
+ }
2783
+ }
2784
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
2785
+ finally {
2786
+ try {
2787
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
2788
+ }
2789
+ finally { if (e_1) throw e_1.error; }
2790
+ }
2791
+ }, [handlers]);
2792
+ React__namespace.useEffect(function () {
2793
+ handlers.forEach(function (_a, keyIndex) {
2794
+ var _b = __read(_a, 4), key = _b[0], gesture = _b[1], callback = _b[2], config = _b[3];
2795
+ subscribers.set(key, {
2796
+ keyIndex: keyIndex,
2797
+ gesture: gesture,
2798
+ unsubscribe: gesture.applyGesture({
2799
+ targetElement: ref.current,
2800
+ targetElements: elementRefs.current,
2801
+ callback: callback,
2802
+ config: config,
2803
+ }),
2804
+ });
2805
+ });
2806
+ return function () {
2807
+ var e_2, _a;
2808
+ try {
2809
+ for (var _b = __values(subscribers.entries()), _c = _b.next(); !_c.done; _c = _b.next()) {
2810
+ var _d = __read(_c.value, 2), unsubscribe = _d[1].unsubscribe;
2811
+ unsubscribe && unsubscribe();
2812
+ }
2813
+ }
2814
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
2815
+ finally {
2816
+ try {
2817
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
2818
+ }
2819
+ finally { if (e_2) throw e_2.error; }
2820
+ }
2821
+ };
2822
+ }, []);
2823
+ return function (index) {
2824
+ if (index === null || index === undefined) {
2825
+ return { ref: ref };
2826
+ }
2827
+ else {
2828
+ elementRefs.current[index] =
2829
+ elementRefs.current[index] || React__namespace.createRef();
2830
+ return { ref: elementRefs.current[index] };
2831
+ }
2832
+ };
2833
+ };
2834
+
2835
+ function useDrag(callback, config) {
2836
+ var gesture = React__namespace.useRef(new DragGesture()).current;
2837
+ return useRecognizer([['drag', gesture, callback, config]]);
2838
+ }
2839
+
2840
+ function useMouseMove(callback) {
2841
+ var gesture = React__namespace.useRef(new MouseMoveGesture()).current;
2842
+ return useRecognizer([['move', gesture, callback]]);
2843
+ }
2844
+
2845
+ function useScroll(callback) {
2846
+ var gesture = React__namespace.useRef(new ScrollGesture()).current;
2847
+ return useRecognizer([['scroll', gesture, callback]]);
2848
+ }
2849
+
2850
+ function useWheel(callback) {
2851
+ var gesture = React__namespace.useRef(new WheelGesture()).current;
2852
+ return useRecognizer([['wheel', gesture, callback]]);
2853
+ }
2854
+
2855
+ function useGesture(_a) {
2856
+ var onDrag = _a.onDrag, onWheel = _a.onWheel, onScroll = _a.onScroll, onMouseMove = _a.onMouseMove;
2857
+ var dragGesture = React__namespace.useRef(new DragGesture()).current;
2858
+ var wheelGesture = React__namespace.useRef(new WheelGesture()).current;
2859
+ var scrollGesture = React__namespace.useRef(new ScrollGesture()).current;
2860
+ var mouseMoveGesture = React__namespace.useRef(new MouseMoveGesture()).current;
2861
+ return useRecognizer([
2862
+ ['drag', dragGesture, onDrag],
2863
+ ['wheel', wheelGesture, onWheel],
2864
+ ['scroll', scrollGesture, onScroll],
2865
+ ['move', mouseMoveGesture, onMouseMove],
2866
+ ]);
1152
2867
  }
1153
2868
 
1154
- Object.defineProperty(exports, 'Easing', {
1155
- enumerable: true,
1156
- get: function () {
1157
- return reMotion.Easing;
1158
- }
1159
- });
1160
- Object.defineProperty(exports, 'makeAnimatedComponent', {
1161
- enumerable: true,
1162
- get: function () {
1163
- return reMotion.makeAnimatedComponent;
1164
- }
1165
- });
1166
2869
  exports.AnimatedBlock = AnimatedBlock;
1167
2870
  exports.AnimatedImage = AnimatedImage;
1168
2871
  exports.AnimatedInline = AnimatedInline;
1169
2872
  exports.AnimationConfigUtils = AnimationConfigUtils;
2873
+ exports.Easing = Easing;
1170
2874
  exports.MountedBlock = MountedBlock;
1171
2875
  exports.ScrollableBlock = ScrollableBlock;
1172
2876
  exports.TransitionBlock = TransitionBlock;
@@ -1174,7 +2878,9 @@ exports.bInterpolate = bInterpolate;
1174
2878
  exports.bin = bin;
1175
2879
  exports.clamp = clamp;
1176
2880
  exports.delay = delay;
2881
+ exports.fluid = fluid;
1177
2882
  exports.interpolate = interpolate;
2883
+ exports.makeFluid = makeFluid;
1178
2884
  exports.mix = mix;
1179
2885
  exports.move = move;
1180
2886
  exports.rubberClamp = rubberClamp;