@leonsilicon/react-native-reanimated-carousel 0.0.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 (328) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +652 -0
  3. package/lib/commonjs/components/Carousel.js +2 -0
  4. package/lib/commonjs/components/Carousel.js.map +1 -0
  5. package/lib/commonjs/components/CarouselLayout.js +2 -0
  6. package/lib/commonjs/components/CarouselLayout.js.map +1 -0
  7. package/lib/commonjs/components/ItemLayout.js +2 -0
  8. package/lib/commonjs/components/ItemLayout.js.map +1 -0
  9. package/lib/commonjs/components/ItemRenderer.js +2 -0
  10. package/lib/commonjs/components/ItemRenderer.js.map +1 -0
  11. package/lib/commonjs/components/LazyView.js +2 -0
  12. package/lib/commonjs/components/LazyView.js.map +1 -0
  13. package/lib/commonjs/components/Pagination/Basic/PaginationItem.js +2 -0
  14. package/lib/commonjs/components/Pagination/Basic/PaginationItem.js.map +1 -0
  15. package/lib/commonjs/components/Pagination/Basic/index.js +2 -0
  16. package/lib/commonjs/components/Pagination/Basic/index.js.map +1 -0
  17. package/lib/commonjs/components/Pagination/Custom/PaginationItem.js +2 -0
  18. package/lib/commonjs/components/Pagination/Custom/PaginationItem.js.map +1 -0
  19. package/lib/commonjs/components/Pagination/Custom/index.js +2 -0
  20. package/lib/commonjs/components/Pagination/Custom/index.js.map +1 -0
  21. package/lib/commonjs/components/Pagination/index.js +2 -0
  22. package/lib/commonjs/components/Pagination/index.js.map +1 -0
  23. package/lib/commonjs/components/ScrollViewGesture.js +2 -0
  24. package/lib/commonjs/components/ScrollViewGesture.js.map +1 -0
  25. package/lib/commonjs/constants/index.js +2 -0
  26. package/lib/commonjs/constants/index.js.map +1 -0
  27. package/lib/commonjs/hooks/useAutoPlay.js +2 -0
  28. package/lib/commonjs/hooks/useAutoPlay.js.map +1 -0
  29. package/lib/commonjs/hooks/useCarouselController.js +2 -0
  30. package/lib/commonjs/hooks/useCarouselController.js.map +1 -0
  31. package/lib/commonjs/hooks/useCheckMounted.js +2 -0
  32. package/lib/commonjs/hooks/useCheckMounted.js.map +1 -0
  33. package/lib/commonjs/hooks/useCommonVariables.js +2 -0
  34. package/lib/commonjs/hooks/useCommonVariables.js.map +1 -0
  35. package/lib/commonjs/hooks/useInitProps.js +2 -0
  36. package/lib/commonjs/hooks/useInitProps.js.map +1 -0
  37. package/lib/commonjs/hooks/useLayoutConfig.js +2 -0
  38. package/lib/commonjs/hooks/useLayoutConfig.js.map +1 -0
  39. package/lib/commonjs/hooks/useOffsetX.js +2 -0
  40. package/lib/commonjs/hooks/useOffsetX.js.map +1 -0
  41. package/lib/commonjs/hooks/useOnProgressChange.js +2 -0
  42. package/lib/commonjs/hooks/useOnProgressChange.js.map +1 -0
  43. package/lib/commonjs/hooks/usePanGestureProxy.js +2 -0
  44. package/lib/commonjs/hooks/usePanGestureProxy.js.map +1 -0
  45. package/lib/commonjs/hooks/usePropsErrorBoundary.js +2 -0
  46. package/lib/commonjs/hooks/usePropsErrorBoundary.js.map +1 -0
  47. package/lib/commonjs/hooks/useSizeResolver.js +2 -0
  48. package/lib/commonjs/hooks/useSizeResolver.js.map +1 -0
  49. package/lib/commonjs/hooks/useUpdateGestureConfig.js +2 -0
  50. package/lib/commonjs/hooks/useUpdateGestureConfig.js.map +1 -0
  51. package/lib/commonjs/hooks/useVisibleRanges.js +2 -0
  52. package/lib/commonjs/hooks/useVisibleRanges.js.map +1 -0
  53. package/lib/commonjs/index.js +2 -0
  54. package/lib/commonjs/index.js.map +1 -0
  55. package/lib/commonjs/layouts/index.js +2 -0
  56. package/lib/commonjs/layouts/index.js.map +1 -0
  57. package/lib/commonjs/layouts/normal.js +2 -0
  58. package/lib/commonjs/layouts/normal.js.map +1 -0
  59. package/lib/commonjs/layouts/parallax.js +2 -0
  60. package/lib/commonjs/layouts/parallax.js.map +1 -0
  61. package/lib/commonjs/layouts/stack.js +2 -0
  62. package/lib/commonjs/layouts/stack.js.map +1 -0
  63. package/lib/commonjs/package.json +1 -0
  64. package/lib/commonjs/store/index.js +2 -0
  65. package/lib/commonjs/store/index.js.map +1 -0
  66. package/lib/commonjs/types.js +2 -0
  67. package/lib/commonjs/types.js.map +1 -0
  68. package/lib/commonjs/utils/compute-gesture-translation.js +2 -0
  69. package/lib/commonjs/utils/compute-gesture-translation.js.map +1 -0
  70. package/lib/commonjs/utils/compute-offset-if-data-changed.js +2 -0
  71. package/lib/commonjs/utils/compute-offset-if-data-changed.js.map +1 -0
  72. package/lib/commonjs/utils/compute-offset-if-size-changed.js +2 -0
  73. package/lib/commonjs/utils/compute-offset-if-size-changed.js.map +1 -0
  74. package/lib/commonjs/utils/compute-offset-if-sizes-changed.js +2 -0
  75. package/lib/commonjs/utils/compute-offset-if-sizes-changed.js.map +1 -0
  76. package/lib/commonjs/utils/computed-with-auto-fill-data.js +2 -0
  77. package/lib/commonjs/utils/computed-with-auto-fill-data.js.map +1 -0
  78. package/lib/commonjs/utils/deal-with-animation.js +2 -0
  79. package/lib/commonjs/utils/deal-with-animation.js.map +1 -0
  80. package/lib/commonjs/utils/handleroffset-direction.js +2 -0
  81. package/lib/commonjs/utils/handleroffset-direction.js.map +1 -0
  82. package/lib/commonjs/utils/log.js +2 -0
  83. package/lib/commonjs/utils/log.js.map +1 -0
  84. package/lib/commonjs/utils/sanitize-animation-style.js +2 -0
  85. package/lib/commonjs/utils/sanitize-animation-style.js.map +1 -0
  86. package/lib/commonjs/utils/size-resolver.js +2 -0
  87. package/lib/commonjs/utils/size-resolver.js.map +1 -0
  88. package/lib/module/components/Carousel.js +2 -0
  89. package/lib/module/components/Carousel.js.map +1 -0
  90. package/lib/module/components/CarouselLayout.js +2 -0
  91. package/lib/module/components/CarouselLayout.js.map +1 -0
  92. package/lib/module/components/ItemLayout.js +2 -0
  93. package/lib/module/components/ItemLayout.js.map +1 -0
  94. package/lib/module/components/ItemRenderer.js +2 -0
  95. package/lib/module/components/ItemRenderer.js.map +1 -0
  96. package/lib/module/components/LazyView.js +2 -0
  97. package/lib/module/components/LazyView.js.map +1 -0
  98. package/lib/module/components/Pagination/Basic/PaginationItem.js +2 -0
  99. package/lib/module/components/Pagination/Basic/PaginationItem.js.map +1 -0
  100. package/lib/module/components/Pagination/Basic/index.js +2 -0
  101. package/lib/module/components/Pagination/Basic/index.js.map +1 -0
  102. package/lib/module/components/Pagination/Custom/PaginationItem.js +2 -0
  103. package/lib/module/components/Pagination/Custom/PaginationItem.js.map +1 -0
  104. package/lib/module/components/Pagination/Custom/index.js +2 -0
  105. package/lib/module/components/Pagination/Custom/index.js.map +1 -0
  106. package/lib/module/components/Pagination/index.js +2 -0
  107. package/lib/module/components/Pagination/index.js.map +1 -0
  108. package/lib/module/components/ScrollViewGesture.js +2 -0
  109. package/lib/module/components/ScrollViewGesture.js.map +1 -0
  110. package/lib/module/constants/index.js +2 -0
  111. package/lib/module/constants/index.js.map +1 -0
  112. package/lib/module/hooks/useAutoPlay.js +2 -0
  113. package/lib/module/hooks/useAutoPlay.js.map +1 -0
  114. package/lib/module/hooks/useCarouselController.js +2 -0
  115. package/lib/module/hooks/useCarouselController.js.map +1 -0
  116. package/lib/module/hooks/useCheckMounted.js +2 -0
  117. package/lib/module/hooks/useCheckMounted.js.map +1 -0
  118. package/lib/module/hooks/useCommonVariables.js +2 -0
  119. package/lib/module/hooks/useCommonVariables.js.map +1 -0
  120. package/lib/module/hooks/useInitProps.js +2 -0
  121. package/lib/module/hooks/useInitProps.js.map +1 -0
  122. package/lib/module/hooks/useLayoutConfig.js +2 -0
  123. package/lib/module/hooks/useLayoutConfig.js.map +1 -0
  124. package/lib/module/hooks/useOffsetX.js +2 -0
  125. package/lib/module/hooks/useOffsetX.js.map +1 -0
  126. package/lib/module/hooks/useOnProgressChange.js +2 -0
  127. package/lib/module/hooks/useOnProgressChange.js.map +1 -0
  128. package/lib/module/hooks/usePanGestureProxy.js +2 -0
  129. package/lib/module/hooks/usePanGestureProxy.js.map +1 -0
  130. package/lib/module/hooks/usePropsErrorBoundary.js +2 -0
  131. package/lib/module/hooks/usePropsErrorBoundary.js.map +1 -0
  132. package/lib/module/hooks/useSizeResolver.js +2 -0
  133. package/lib/module/hooks/useSizeResolver.js.map +1 -0
  134. package/lib/module/hooks/useUpdateGestureConfig.js +2 -0
  135. package/lib/module/hooks/useUpdateGestureConfig.js.map +1 -0
  136. package/lib/module/hooks/useVisibleRanges.js +2 -0
  137. package/lib/module/hooks/useVisibleRanges.js.map +1 -0
  138. package/lib/module/index.js +2 -0
  139. package/lib/module/index.js.map +1 -0
  140. package/lib/module/layouts/index.js +2 -0
  141. package/lib/module/layouts/index.js.map +1 -0
  142. package/lib/module/layouts/normal.js +2 -0
  143. package/lib/module/layouts/normal.js.map +1 -0
  144. package/lib/module/layouts/parallax.js +2 -0
  145. package/lib/module/layouts/parallax.js.map +1 -0
  146. package/lib/module/layouts/stack.js +2 -0
  147. package/lib/module/layouts/stack.js.map +1 -0
  148. package/lib/module/store/index.js +2 -0
  149. package/lib/module/store/index.js.map +1 -0
  150. package/lib/module/types.js +2 -0
  151. package/lib/module/types.js.map +1 -0
  152. package/lib/module/utils/compute-gesture-translation.js +2 -0
  153. package/lib/module/utils/compute-gesture-translation.js.map +1 -0
  154. package/lib/module/utils/compute-offset-if-data-changed.js +2 -0
  155. package/lib/module/utils/compute-offset-if-data-changed.js.map +1 -0
  156. package/lib/module/utils/compute-offset-if-size-changed.js +2 -0
  157. package/lib/module/utils/compute-offset-if-size-changed.js.map +1 -0
  158. package/lib/module/utils/compute-offset-if-sizes-changed.js +2 -0
  159. package/lib/module/utils/compute-offset-if-sizes-changed.js.map +1 -0
  160. package/lib/module/utils/computed-with-auto-fill-data.js +2 -0
  161. package/lib/module/utils/computed-with-auto-fill-data.js.map +1 -0
  162. package/lib/module/utils/deal-with-animation.js +2 -0
  163. package/lib/module/utils/deal-with-animation.js.map +1 -0
  164. package/lib/module/utils/handleroffset-direction.js +2 -0
  165. package/lib/module/utils/handleroffset-direction.js.map +1 -0
  166. package/lib/module/utils/log.js +2 -0
  167. package/lib/module/utils/log.js.map +1 -0
  168. package/lib/module/utils/sanitize-animation-style.js +2 -0
  169. package/lib/module/utils/sanitize-animation-style.js.map +1 -0
  170. package/lib/module/utils/size-resolver.js +2 -0
  171. package/lib/module/utils/size-resolver.js.map +1 -0
  172. package/lib/typescript/components/Carousel.d.ts +8 -0
  173. package/lib/typescript/components/Carousel.d.ts.map +1 -0
  174. package/lib/typescript/components/CarouselLayout.d.ts +6 -0
  175. package/lib/typescript/components/CarouselLayout.d.ts.map +1 -0
  176. package/lib/typescript/components/ItemLayout.d.ts +15 -0
  177. package/lib/typescript/components/ItemLayout.d.ts.map +1 -0
  178. package/lib/typescript/components/ItemRenderer.d.ts +24 -0
  179. package/lib/typescript/components/ItemRenderer.d.ts.map +1 -0
  180. package/lib/typescript/components/LazyView.d.ts +8 -0
  181. package/lib/typescript/components/LazyView.d.ts.map +1 -0
  182. package/lib/typescript/components/Pagination/Basic/PaginationItem.d.ts +29 -0
  183. package/lib/typescript/components/Pagination/Basic/PaginationItem.d.ts.map +1 -0
  184. package/lib/typescript/components/Pagination/Basic/index.d.ts +23 -0
  185. package/lib/typescript/components/Pagination/Basic/index.d.ts.map +1 -0
  186. package/lib/typescript/components/Pagination/Custom/PaginationItem.d.ts +35 -0
  187. package/lib/typescript/components/Pagination/Custom/PaginationItem.d.ts.map +1 -0
  188. package/lib/typescript/components/Pagination/Custom/index.d.ts +26 -0
  189. package/lib/typescript/components/Pagination/Custom/index.d.ts.map +1 -0
  190. package/lib/typescript/components/Pagination/index.d.ts +5 -0
  191. package/lib/typescript/components/Pagination/index.d.ts.map +1 -0
  192. package/lib/typescript/components/ScrollViewGesture.d.ts +19 -0
  193. package/lib/typescript/components/ScrollViewGesture.d.ts.map +1 -0
  194. package/lib/typescript/constants/index.d.ts +9 -0
  195. package/lib/typescript/constants/index.d.ts.map +1 -0
  196. package/lib/typescript/hooks/useAutoPlay.d.ts +12 -0
  197. package/lib/typescript/hooks/useAutoPlay.d.ts.map +1 -0
  198. package/lib/typescript/hooks/useCarouselController.d.ts +28 -0
  199. package/lib/typescript/hooks/useCarouselController.d.ts.map +1 -0
  200. package/lib/typescript/hooks/useCheckMounted.d.ts +3 -0
  201. package/lib/typescript/hooks/useCheckMounted.d.ts.map +1 -0
  202. package/lib/typescript/hooks/useCommonVariables.d.ts +13 -0
  203. package/lib/typescript/hooks/useCommonVariables.d.ts.map +1 -0
  204. package/lib/typescript/hooks/useInitProps.d.ts +17 -0
  205. package/lib/typescript/hooks/useInitProps.d.ts.map +1 -0
  206. package/lib/typescript/hooks/useLayoutConfig.d.ts +10 -0
  207. package/lib/typescript/hooks/useLayoutConfig.d.ts.map +1 -0
  208. package/lib/typescript/hooks/useOffsetX.d.ts +24 -0
  209. package/lib/typescript/hooks/useOffsetX.d.ts.map +1 -0
  210. package/lib/typescript/hooks/useOnProgressChange.d.ts +14 -0
  211. package/lib/typescript/hooks/useOnProgressChange.d.ts.map +1 -0
  212. package/lib/typescript/hooks/usePanGestureProxy.d.ts +10 -0
  213. package/lib/typescript/hooks/usePanGestureProxy.d.ts.map +1 -0
  214. package/lib/typescript/hooks/usePropsErrorBoundary.d.ts +5 -0
  215. package/lib/typescript/hooks/usePropsErrorBoundary.d.ts.map +1 -0
  216. package/lib/typescript/hooks/useSizeResolver.d.ts +27 -0
  217. package/lib/typescript/hooks/useSizeResolver.d.ts.map +1 -0
  218. package/lib/typescript/hooks/useUpdateGestureConfig.d.ts +6 -0
  219. package/lib/typescript/hooks/useUpdateGestureConfig.d.ts.map +1 -0
  220. package/lib/typescript/hooks/useVisibleRanges.d.ts +23 -0
  221. package/lib/typescript/hooks/useVisibleRanges.d.ts.map +1 -0
  222. package/lib/typescript/index.d.ts +7 -0
  223. package/lib/typescript/index.d.ts.map +1 -0
  224. package/lib/typescript/layouts/index.d.ts +11 -0
  225. package/lib/typescript/layouts/index.d.ts.map +1 -0
  226. package/lib/typescript/layouts/normal.d.ts +16 -0
  227. package/lib/typescript/layouts/normal.d.ts.map +1 -0
  228. package/lib/typescript/layouts/parallax.d.ts +50 -0
  229. package/lib/typescript/layouts/parallax.d.ts.map +1 -0
  230. package/lib/typescript/layouts/stack.d.ts +38 -0
  231. package/lib/typescript/layouts/stack.d.ts.map +1 -0
  232. package/lib/typescript/store/index.d.ts +38 -0
  233. package/lib/typescript/store/index.d.ts.map +1 -0
  234. package/lib/typescript/types.d.ts +326 -0
  235. package/lib/typescript/types.d.ts.map +1 -0
  236. package/lib/typescript/utils/compute-gesture-translation.d.ts +9 -0
  237. package/lib/typescript/utils/compute-gesture-translation.d.ts.map +1 -0
  238. package/lib/typescript/utils/compute-offset-if-data-changed.d.ts +9 -0
  239. package/lib/typescript/utils/compute-offset-if-data-changed.d.ts.map +1 -0
  240. package/lib/typescript/utils/compute-offset-if-size-changed.d.ts +6 -0
  241. package/lib/typescript/utils/compute-offset-if-size-changed.d.ts.map +1 -0
  242. package/lib/typescript/utils/compute-offset-if-sizes-changed.d.ts +14 -0
  243. package/lib/typescript/utils/compute-offset-if-sizes-changed.d.ts.map +1 -0
  244. package/lib/typescript/utils/computed-with-auto-fill-data.d.ts +23 -0
  245. package/lib/typescript/utils/computed-with-auto-fill-data.d.ts.map +1 -0
  246. package/lib/typescript/utils/deal-with-animation.d.ts +3 -0
  247. package/lib/typescript/utils/deal-with-animation.d.ts.map +1 -0
  248. package/lib/typescript/utils/handleroffset-direction.d.ts +4 -0
  249. package/lib/typescript/utils/handleroffset-direction.d.ts.map +1 -0
  250. package/lib/typescript/utils/log.d.ts +7 -0
  251. package/lib/typescript/utils/log.d.ts.map +1 -0
  252. package/lib/typescript/utils/sanitize-animation-style.d.ts +3 -0
  253. package/lib/typescript/utils/sanitize-animation-style.d.ts.map +1 -0
  254. package/lib/typescript/utils/size-resolver.d.ts +87 -0
  255. package/lib/typescript/utils/size-resolver.d.ts.map +1 -0
  256. package/package.json +151 -0
  257. package/src/components/Carousel.test.tsx +1153 -0
  258. package/src/components/Carousel.tsx +35 -0
  259. package/src/components/CarouselLayout.tsx +231 -0
  260. package/src/components/ItemLayout.tsx +217 -0
  261. package/src/components/ItemRenderer.tsx +114 -0
  262. package/src/components/LazyView.test.tsx +61 -0
  263. package/src/components/LazyView.tsx +14 -0
  264. package/src/components/Pagination/Basic/PaginationItem.tsx +149 -0
  265. package/src/components/Pagination/Basic/index.tsx +98 -0
  266. package/src/components/Pagination/Custom/PaginationItem.tsx +166 -0
  267. package/src/components/Pagination/Custom/index.tsx +111 -0
  268. package/src/components/Pagination/Pagination.test.tsx +178 -0
  269. package/src/components/Pagination/index.tsx +7 -0
  270. package/src/components/ScrollViewGesture.tsx +577 -0
  271. package/src/components/rnr-demo.test.tsx +53 -0
  272. package/src/constants/index.ts +11 -0
  273. package/src/hooks/useAutoPlay.test.ts +194 -0
  274. package/src/hooks/useAutoPlay.ts +58 -0
  275. package/src/hooks/useCarouselController.test.tsx +1158 -0
  276. package/src/hooks/useCarouselController.tsx +525 -0
  277. package/src/hooks/useCheckMounted.test.ts +47 -0
  278. package/src/hooks/useCheckMounted.ts +14 -0
  279. package/src/hooks/useCommonVariables.test.tsx +384 -0
  280. package/src/hooks/useCommonVariables.ts +202 -0
  281. package/src/hooks/useInitProps.test.tsx +134 -0
  282. package/src/hooks/useInitProps.ts +111 -0
  283. package/src/hooks/useLayoutConfig.test.tsx +247 -0
  284. package/src/hooks/useLayoutConfig.ts +30 -0
  285. package/src/hooks/useOffsetX.test.ts +110 -0
  286. package/src/hooks/useOffsetX.ts +109 -0
  287. package/src/hooks/useOnProgressChange.test.tsx +207 -0
  288. package/src/hooks/useOnProgressChange.ts +105 -0
  289. package/src/hooks/usePanGestureProxy.test.tsx +368 -0
  290. package/src/hooks/usePanGestureProxy.ts +144 -0
  291. package/src/hooks/usePropsErrorBoundary.ts +138 -0
  292. package/src/hooks/useSizeResolver.test.tsx +112 -0
  293. package/src/hooks/useSizeResolver.ts +106 -0
  294. package/src/hooks/useUpdateGestureConfig.test.ts +89 -0
  295. package/src/hooks/useUpdateGestureConfig.ts +14 -0
  296. package/src/hooks/useVisibleRanges.test.tsx +366 -0
  297. package/src/hooks/useVisibleRanges.tsx +123 -0
  298. package/src/index.tsx +13 -0
  299. package/src/layouts/index.tsx +12 -0
  300. package/src/layouts/normal.ts +32 -0
  301. package/src/layouts/parallax.test.ts +239 -0
  302. package/src/layouts/parallax.ts +83 -0
  303. package/src/layouts/stack.test.ts +252 -0
  304. package/src/layouts/stack.ts +306 -0
  305. package/src/store/index.test.tsx +314 -0
  306. package/src/store/index.tsx +66 -0
  307. package/src/types.ts +348 -0
  308. package/src/utils/compute-gesture-translation.test.ts +70 -0
  309. package/src/utils/compute-gesture-translation.ts +29 -0
  310. package/src/utils/compute-offset-if-data-changed.test.ts +133 -0
  311. package/src/utils/compute-offset-if-data-changed.ts +44 -0
  312. package/src/utils/compute-offset-if-size-changed.test.ts +78 -0
  313. package/src/utils/compute-offset-if-size-changed.ts +14 -0
  314. package/src/utils/compute-offset-if-sizes-changed.test.ts +74 -0
  315. package/src/utils/compute-offset-if-sizes-changed.ts +44 -0
  316. package/src/utils/computed-with-auto-fill-data.test.ts +298 -0
  317. package/src/utils/computed-with-auto-fill-data.ts +92 -0
  318. package/src/utils/deal-with-animation.test.ts +181 -0
  319. package/src/utils/deal-with-animation.ts +17 -0
  320. package/src/utils/handleroffset-direction.test.ts +124 -0
  321. package/src/utils/handleroffset-direction.ts +18 -0
  322. package/src/utils/index.test.ts +90 -0
  323. package/src/utils/log.test.ts +134 -0
  324. package/src/utils/log.ts +12 -0
  325. package/src/utils/sanitize-animation-style.test.ts +40 -0
  326. package/src/utils/sanitize-animation-style.ts +20 -0
  327. package/src/utils/size-resolver.test.ts +193 -0
  328. package/src/utils/size-resolver.ts +216 -0
@@ -0,0 +1,17 @@
1
+ import { withSpring, withTiming } from "react-native-reanimated";
2
+
3
+ import type { WithAnimation } from "../types";
4
+
5
+ export function dealWithAnimation(
6
+ withAnimation: WithAnimation
7
+ ): (value: number, cb: (isFinished: boolean) => void) => number {
8
+ "worklet";
9
+ switch (withAnimation.type) {
10
+ case "spring":
11
+ return (value, cb) =>
12
+ withSpring(value, withAnimation.config, (isFinished) => cb(isFinished as boolean));
13
+ case "timing":
14
+ return (value, cb) =>
15
+ withTiming(value, withAnimation.config, (isFinished) => cb(isFinished as boolean));
16
+ }
17
+ }
@@ -0,0 +1,124 @@
1
+ import { useSharedValue } from "react-native-reanimated";
2
+
3
+ import { renderHook } from "@testing-library/react-hooks";
4
+
5
+ import { handlerOffsetDirection } from "./handleroffset-direction";
6
+
7
+ describe("handlerOffsetDirection", () => {
8
+ it("should return -1 when default value equals to zero", () => {
9
+ const result = renderHook(() => {
10
+ const handlerOffsetAnimVal = useSharedValue(0);
11
+ return handlerOffsetDirection(handlerOffsetAnimVal);
12
+ });
13
+
14
+ expect(result.result.current).toBe(-1);
15
+ });
16
+
17
+ it("should return 1 when default value is greater than zero", () => {
18
+ const result = renderHook(() => {
19
+ const handlerOffsetAnimVal = useSharedValue(1);
20
+ return handlerOffsetDirection(handlerOffsetAnimVal);
21
+ });
22
+
23
+ expect(result.result.current).toBe(1);
24
+ });
25
+
26
+ it("should return -1 when default value is less than zero", () => {
27
+ const result = renderHook(() => {
28
+ const handlerOffsetAnimVal = useSharedValue(-1);
29
+ return handlerOffsetDirection(handlerOffsetAnimVal);
30
+ });
31
+
32
+ expect(result.result.current).toBe(-1);
33
+ });
34
+
35
+ it("should return 1 when default value equals to zero and fixedDirection is negative", () => {
36
+ const result = renderHook(() => {
37
+ const handlerOffsetAnimVal = useSharedValue(-1);
38
+ return handlerOffsetDirection(handlerOffsetAnimVal, "positive");
39
+ });
40
+
41
+ expect(result.result.current).toBe(1);
42
+ });
43
+
44
+ it("should return -1 when default value is greater than zero and fixedDirection is negative", () => {
45
+ const result = renderHook(() => {
46
+ const handlerOffsetAnimVal = useSharedValue(1);
47
+ return handlerOffsetDirection(handlerOffsetAnimVal, "negative");
48
+ });
49
+
50
+ expect(result.result.current).toBe(-1);
51
+ });
52
+
53
+ it("should handle fractional positive values", () => {
54
+ const result = renderHook(() => {
55
+ const handlerOffsetAnimVal = useSharedValue(0.5);
56
+ return handlerOffsetDirection(handlerOffsetAnimVal);
57
+ });
58
+
59
+ expect(result.result.current).toBe(1);
60
+ });
61
+
62
+ it("should handle fractional negative values", () => {
63
+ const result = renderHook(() => {
64
+ const handlerOffsetAnimVal = useSharedValue(-0.5);
65
+ return handlerOffsetDirection(handlerOffsetAnimVal);
66
+ });
67
+
68
+ expect(result.result.current).toBe(-1);
69
+ });
70
+
71
+ it("should handle large positive values", () => {
72
+ const result = renderHook(() => {
73
+ const handlerOffsetAnimVal = useSharedValue(1000);
74
+ return handlerOffsetDirection(handlerOffsetAnimVal);
75
+ });
76
+
77
+ expect(result.result.current).toBe(1);
78
+ });
79
+
80
+ it("should handle large negative values", () => {
81
+ const result = renderHook(() => {
82
+ const handlerOffsetAnimVal = useSharedValue(-1000);
83
+ return handlerOffsetDirection(handlerOffsetAnimVal);
84
+ });
85
+
86
+ expect(result.result.current).toBe(-1);
87
+ });
88
+
89
+ it("should override with positive fixed direction", () => {
90
+ const result = renderHook(() => {
91
+ const handlerOffsetAnimVal = useSharedValue(-100);
92
+ return handlerOffsetDirection(handlerOffsetAnimVal, "positive");
93
+ });
94
+
95
+ expect(result.result.current).toBe(1);
96
+ });
97
+
98
+ it("should override with negative fixed direction", () => {
99
+ const result = renderHook(() => {
100
+ const handlerOffsetAnimVal = useSharedValue(100);
101
+ return handlerOffsetDirection(handlerOffsetAnimVal, "negative");
102
+ });
103
+
104
+ expect(result.result.current).toBe(-1);
105
+ });
106
+
107
+ it("should handle very small positive values", () => {
108
+ const result = renderHook(() => {
109
+ const handlerOffsetAnimVal = useSharedValue(0.001);
110
+ return handlerOffsetDirection(handlerOffsetAnimVal);
111
+ });
112
+
113
+ expect(result.result.current).toBe(1);
114
+ });
115
+
116
+ it("should handle very small negative values", () => {
117
+ const result = renderHook(() => {
118
+ const handlerOffsetAnimVal = useSharedValue(-0.001);
119
+ return handlerOffsetDirection(handlerOffsetAnimVal);
120
+ });
121
+
122
+ expect(result.result.current).toBe(-1);
123
+ });
124
+ });
@@ -0,0 +1,18 @@
1
+ import type { SharedValue } from "react-native-reanimated";
2
+
3
+ import type { TCarouselProps } from "../types";
4
+
5
+ export function handlerOffsetDirection(
6
+ handlerOffset: SharedValue<number>,
7
+ fixedDirection?: TCarouselProps["fixedDirection"]
8
+ ): -1 | 1 {
9
+ "worklet";
10
+
11
+ if (fixedDirection === "negative") return -1;
12
+
13
+ if (fixedDirection === "positive") return 1;
14
+
15
+ if (handlerOffset.value === 0) return -1;
16
+
17
+ return Math.sign(handlerOffset.value) as -1 | 1;
18
+ }
@@ -0,0 +1,90 @@
1
+ import { computeOffsetIfDataChanged } from "./compute-offset-if-data-changed";
2
+
3
+ describe("should work as expected", () => {
4
+ const size = 375;
5
+ const positive = -1;
6
+ const negative = 1;
7
+
8
+ const params = (params: {
9
+ direction: "positive" | "negative";
10
+ currentIndex: number;
11
+ previousLength: number;
12
+ currentLength: number;
13
+ }) => {
14
+ const { currentIndex, direction: _direction, previousLength, currentLength } = params;
15
+ const direction = _direction === "negative" ? negative : positive;
16
+ return {
17
+ direction,
18
+ handlerOffset: size * currentIndex * direction,
19
+ size,
20
+ previousLength,
21
+ currentLength,
22
+ };
23
+ };
24
+
25
+ it("The direction is negative, And changing length of data set from 4 to 3, the new index will to be 2.", async () => {
26
+ const currentIndex = 1;
27
+ const handlerOffset = computeOffsetIfDataChanged(
28
+ params({
29
+ currentIndex,
30
+ direction: "negative",
31
+ previousLength: 4,
32
+ currentLength: 3,
33
+ })
34
+ );
35
+
36
+ expect(handlerOffset / size).toBe(2 * positive);
37
+ });
38
+
39
+ it("The direction is negative, Changing length of data set from 4 to 3, the index remains original.", async () => {
40
+ const handlerOffset = computeOffsetIfDataChanged(
41
+ params({
42
+ currentIndex: 2,
43
+ direction: "negative",
44
+ previousLength: 4,
45
+ currentLength: 3,
46
+ })
47
+ );
48
+
49
+ expect(handlerOffset / size).toBe(1 * negative);
50
+ });
51
+
52
+ it("The direction is positive, Changing length of data set from 4 to 5, the index remains original.", async () => {
53
+ const handlerOffset = computeOffsetIfDataChanged(
54
+ params({
55
+ currentIndex: 3,
56
+ direction: "positive",
57
+ previousLength: 4,
58
+ currentLength: 5,
59
+ })
60
+ );
61
+
62
+ expect(handlerOffset / size).toBe(3 * positive);
63
+ });
64
+
65
+ it("The direction is negative, Changing length of data set from 4 to 5, the index remains original.", async () => {
66
+ const handlerOffset = computeOffsetIfDataChanged(
67
+ params({
68
+ currentIndex: 3,
69
+ direction: "negative",
70
+ previousLength: 4,
71
+ currentLength: 5,
72
+ })
73
+ );
74
+
75
+ expect(handlerOffset / size).toBe(4 * negative);
76
+ });
77
+
78
+ it("Changing length of data set from 0 to 3, the index remains original.", async () => {
79
+ const handlerOffset = computeOffsetIfDataChanged(
80
+ params({
81
+ currentIndex: 0,
82
+ direction: "positive",
83
+ previousLength: 0,
84
+ currentLength: 3,
85
+ })
86
+ );
87
+
88
+ expect(handlerOffset / size).toBe(0 * positive);
89
+ });
90
+ });
@@ -0,0 +1,134 @@
1
+ import { log, round } from "./log";
2
+
3
+ describe("log utilities", () => {
4
+ describe("log", () => {
5
+ const mockConsoleLog = jest.fn();
6
+ const originalConsoleLog = console.log;
7
+
8
+ beforeEach(() => {
9
+ console.log = mockConsoleLog;
10
+ });
11
+
12
+ afterEach(() => {
13
+ mockConsoleLog.mockClear();
14
+ console.log = originalConsoleLog;
15
+ });
16
+
17
+ it("should call console.log with provided arguments", () => {
18
+ const args = ["test", 123, { key: "value" }];
19
+ log(...args);
20
+
21
+ expect(mockConsoleLog).toHaveBeenCalledWith(...args);
22
+ });
23
+
24
+ it("should handle single argument", () => {
25
+ log("test");
26
+ expect(mockConsoleLog).toHaveBeenCalledWith("test");
27
+ });
28
+
29
+ it("should handle multiple arguments", () => {
30
+ log("test", 123, true);
31
+ expect(mockConsoleLog).toHaveBeenCalledWith("test", 123, true);
32
+ });
33
+
34
+ it("should handle no arguments", () => {
35
+ log();
36
+ expect(mockConsoleLog).toHaveBeenCalledWith();
37
+ });
38
+
39
+ it("should handle null and undefined", () => {
40
+ log(null, undefined);
41
+ expect(mockConsoleLog).toHaveBeenCalledWith(null, undefined);
42
+ });
43
+
44
+ it("should handle complex objects", () => {
45
+ const complexObj = {
46
+ nested: { array: [1, 2, 3] },
47
+ func: () => "test",
48
+ date: new Date("2023-01-01"),
49
+ };
50
+ log(complexObj);
51
+ expect(mockConsoleLog).toHaveBeenCalledWith(complexObj);
52
+ });
53
+
54
+ it("should handle arrays", () => {
55
+ const arr = [1, "two", { three: 3 }];
56
+ log(arr);
57
+ expect(mockConsoleLog).toHaveBeenCalledWith(arr);
58
+ });
59
+
60
+ it("should handle mixed types", () => {
61
+ log("string", 42, true, null, undefined, { key: "value" }, [1, 2, 3]);
62
+ expect(mockConsoleLog).toHaveBeenCalledWith(
63
+ "string",
64
+ 42,
65
+ true,
66
+ null,
67
+ undefined,
68
+ { key: "value" },
69
+ [1, 2, 3]
70
+ );
71
+ });
72
+ });
73
+
74
+ describe("round", () => {
75
+ it("should round positive numbers correctly", () => {
76
+ expect(round(1.4)).toBe(1);
77
+ expect(round(1.5)).toBe(2);
78
+ expect(round(1.6)).toBe(2);
79
+ });
80
+
81
+ it("should round negative numbers correctly", () => {
82
+ expect(round(-1.4)).toBe(-1);
83
+ expect(round(-1.5)).toBe(-1);
84
+ expect(round(-1.6)).toBe(-2);
85
+ });
86
+
87
+ it("should handle zero values", () => {
88
+ expect(round(0)).toBe(0);
89
+ expect(round(-0)).toBe(-0);
90
+ expect(1 / round(-0)).toBe(Number.NEGATIVE_INFINITY);
91
+ });
92
+
93
+ it("should handle integers", () => {
94
+ expect(round(5)).toBe(5);
95
+ expect(round(-5)).toBe(-5);
96
+ });
97
+
98
+ it("should handle decimal places", () => {
99
+ expect(round(Math.PI)).toBe(3);
100
+ expect(round(-Math.PI)).toBe(-3);
101
+ });
102
+
103
+ it("should handle edge cases", () => {
104
+ expect(round(0.5)).toBe(1);
105
+ expect(round(-0.5)).toBe(-0);
106
+ expect(round(1.999999)).toBe(2);
107
+ expect(round(-1.999999)).toBe(-2);
108
+ });
109
+
110
+ it("should handle very large numbers", () => {
111
+ expect(round(1e10 + 0.4)).toBe(1e10);
112
+ expect(round(1e10 + 0.6)).toBe(1e10 + 1);
113
+ });
114
+
115
+ it("should handle very small numbers", () => {
116
+ expect(round(0.00001)).toBe(0);
117
+ expect(round(-0.00001)).toBe(-0);
118
+ });
119
+
120
+ it("should handle Infinity", () => {
121
+ expect(round(Number.POSITIVE_INFINITY)).toBe(Number.POSITIVE_INFINITY);
122
+ expect(round(Number.NEGATIVE_INFINITY)).toBe(Number.NEGATIVE_INFINITY);
123
+ });
124
+
125
+ it("should handle NaN", () => {
126
+ expect(round(Number.NaN)).toBe(Number.NaN);
127
+ });
128
+
129
+ it("should handle floating point precision issues", () => {
130
+ expect(round(0.1 + 0.2)).toBe(0); // 0.1 + 0.2 = 0.30000000000000004
131
+ expect(round(1.1 + 1.2)).toBe(2); // Should round to 2
132
+ });
133
+ });
134
+ });
@@ -0,0 +1,12 @@
1
+ /**
2
+ * In worklet
3
+ * e.g. scheduleOnRN(lop, ...);
4
+ */
5
+ export function log(...msg: any) {
6
+ console.log(...msg);
7
+ }
8
+
9
+ export function round(number: number) {
10
+ "worklet";
11
+ return Math.round(number);
12
+ }
@@ -0,0 +1,40 @@
1
+ import { sanitizeAnimationStyle } from "./sanitize-animation-style";
2
+
3
+ describe("sanitizeAnimationStyle", () => {
4
+ it("rounds zIndex to an integer", () => {
5
+ const style = sanitizeAnimationStyle({
6
+ transform: [{ translateX: 12 }],
7
+ zIndex: 3.7,
8
+ });
9
+
10
+ expect(style.zIndex).toBe(4);
11
+ });
12
+
13
+ it("drops invalid zIndex values", () => {
14
+ const style = sanitizeAnimationStyle({
15
+ // invalid value from userland worklet should not flow to native styles
16
+ zIndex: Number.NaN,
17
+ });
18
+
19
+ expect(style).not.toHaveProperty("zIndex");
20
+ });
21
+
22
+ it("returns empty object for null/undefined input", () => {
23
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
24
+ expect(sanitizeAnimationStyle(null as any)).toEqual({});
25
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
26
+ expect(sanitizeAnimationStyle(undefined as any)).toEqual({});
27
+ });
28
+
29
+ it("strips non-number zIndex (e.g. string)", () => {
30
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
31
+ const style = sanitizeAnimationStyle({ opacity: 1, zIndex: "auto" as any });
32
+ expect(style).not.toHaveProperty("zIndex");
33
+ expect(style).toHaveProperty("opacity", 1);
34
+ });
35
+
36
+ it("preserves style without zIndex unchanged", () => {
37
+ const style = sanitizeAnimationStyle({ opacity: 0.5 });
38
+ expect(style).toEqual({ opacity: 0.5 });
39
+ });
40
+ });
@@ -0,0 +1,20 @@
1
+ import type { ViewStyle } from "react-native";
2
+
3
+ type MutableViewStyle = ViewStyle & { zIndex?: unknown };
4
+
5
+ export function sanitizeAnimationStyle(style: ViewStyle): ViewStyle {
6
+ "worklet";
7
+
8
+ if (!style || typeof style !== "object") return {};
9
+
10
+ const nextStyle: MutableViewStyle = { ...style };
11
+ const { zIndex, ...restStyle } = nextStyle;
12
+
13
+ if (typeof zIndex === "number") {
14
+ // Native layers are sensitive to invalid/non-integer zIndex values.
15
+ if (Number.isFinite(zIndex)) return { ...restStyle, zIndex: Math.round(zIndex) };
16
+ return restStyle;
17
+ }
18
+
19
+ return typeof zIndex === "undefined" ? nextStyle : restStyle;
20
+ }
@@ -0,0 +1,193 @@
1
+ import { makeMutable } from "react-native-reanimated";
2
+
3
+ import {
4
+ binarySearchPrefix,
5
+ binarySearchPrefixCached,
6
+ buildPrefixSum,
7
+ createUniformSizeResolver,
8
+ createVariableSizeResolver,
9
+ } from "./size-resolver";
10
+
11
+ describe("buildPrefixSum", () => {
12
+ it("returns a flat prefix for empty input", () => {
13
+ const result = buildPrefixSum(0, () => 100);
14
+ expect(result.sizes).toEqual([]);
15
+ expect(result.prefix).toEqual([0]);
16
+ expect(result.total).toBe(0);
17
+ });
18
+
19
+ it("computes cumulative offsets correctly", () => {
20
+ const widths = [80, 150, 220, 100, 300];
21
+ const result = buildPrefixSum(widths.length, (i) => widths[i]);
22
+ expect(result.sizes).toEqual([80, 150, 220, 100, 300]);
23
+ expect(result.prefix).toEqual([0, 80, 230, 450, 550, 850]);
24
+ expect(result.total).toBe(850);
25
+ });
26
+
27
+ it("treats non-finite or non-positive sizes as 0", () => {
28
+ const result = buildPrefixSum(4, (i) => [100, -50, Number.NaN, 200][i]);
29
+ expect(result.sizes).toEqual([100, 0, 0, 200]);
30
+ expect(result.prefix).toEqual([0, 100, 100, 100, 300]);
31
+ expect(result.total).toBe(300);
32
+ });
33
+ });
34
+
35
+ describe("binarySearchPrefix", () => {
36
+ const prefix = [0, 80, 230, 450, 550, 850];
37
+
38
+ it("returns 0 for target at the very start", () => {
39
+ expect(binarySearchPrefix(prefix, 0)).toBe(0);
40
+ });
41
+
42
+ it("returns last item when target is past the end", () => {
43
+ expect(binarySearchPrefix(prefix, 9999)).toBe(4);
44
+ });
45
+
46
+ it("finds the bucket for an interior offset", () => {
47
+ expect(binarySearchPrefix(prefix, 79)).toBe(0);
48
+ expect(binarySearchPrefix(prefix, 80)).toBe(1);
49
+ expect(binarySearchPrefix(prefix, 229)).toBe(1);
50
+ expect(binarySearchPrefix(prefix, 230)).toBe(2);
51
+ expect(binarySearchPrefix(prefix, 449)).toBe(2);
52
+ expect(binarySearchPrefix(prefix, 450)).toBe(3);
53
+ expect(binarySearchPrefix(prefix, 549)).toBe(3);
54
+ expect(binarySearchPrefix(prefix, 550)).toBe(4);
55
+ });
56
+
57
+ it("handles negative targets by clamping to 0", () => {
58
+ expect(binarySearchPrefix(prefix, -100)).toBe(0);
59
+ });
60
+
61
+ it("returns 0 when prefix is degenerate", () => {
62
+ expect(binarySearchPrefix([0], 100)).toBe(0);
63
+ expect(binarySearchPrefix([], 100)).toBe(0);
64
+ });
65
+ });
66
+
67
+ describe("binarySearchPrefixCached", () => {
68
+ const prefix = [0, 80, 230, 450, 550, 850];
69
+
70
+ it("uses the hint when it is correct", () => {
71
+ // target 100 → index 1; hint 1 is exactly correct
72
+ expect(binarySearchPrefixCached(prefix, 100, 1)).toBe(1);
73
+ });
74
+
75
+ it("scans ±1 around a stale hint", () => {
76
+ // target 100 → index 1; hint 0 means hint+1 is correct
77
+ expect(binarySearchPrefixCached(prefix, 100, 0)).toBe(1);
78
+ // target 100 → index 1; hint 2 means hint-1 is correct
79
+ expect(binarySearchPrefixCached(prefix, 100, 2)).toBe(1);
80
+ });
81
+
82
+ it("falls back to binary search when hint is far off", () => {
83
+ expect(binarySearchPrefixCached(prefix, 100, 4)).toBe(1);
84
+ expect(binarySearchPrefixCached(prefix, 700, 0)).toBe(4);
85
+ });
86
+
87
+ it("clamps out-of-bounds hints", () => {
88
+ expect(binarySearchPrefixCached(prefix, 100, -50)).toBe(1);
89
+ expect(binarySearchPrefixCached(prefix, 100, 9999)).toBe(1);
90
+ });
91
+ });
92
+
93
+ describe("createUniformSizeResolver", () => {
94
+ it("computes offsets as size * index", () => {
95
+ const size = makeMutable(100);
96
+ const count = makeMutable(5);
97
+ const total = makeMutable(500);
98
+ const resolver = createUniformSizeResolver({ size, count, total });
99
+
100
+ expect(resolver.variable).toBe(false);
101
+ expect(resolver.itemSize(0)).toBe(100);
102
+ expect(resolver.itemSize(3)).toBe(100);
103
+ expect(resolver.offsetAt(0)).toBe(0);
104
+ expect(resolver.offsetAt(3)).toBe(300);
105
+ expect(resolver.indexAt(0)).toBe(0);
106
+ expect(resolver.indexAt(250)).toBe(3);
107
+ expect(resolver.midpointOf(2)).toBe(250);
108
+ expect(resolver.total.value).toBe(500);
109
+ });
110
+
111
+ it("returns 0 from indexAt when size is 0", () => {
112
+ const size = makeMutable(0);
113
+ const count = makeMutable(5);
114
+ const total = makeMutable(0);
115
+ const resolver = createUniformSizeResolver({ size, count, total });
116
+ expect(resolver.indexAt(500)).toBe(0);
117
+ });
118
+ });
119
+
120
+ describe("createVariableSizeResolver", () => {
121
+ const widths = [80, 150, 220, 100, 300];
122
+ const built = buildPrefixSum(widths.length, (i) => widths[i]);
123
+
124
+ const makeResolver = (hint?: number) => {
125
+ const sizes = makeMutable(built.sizes);
126
+ const prefix = makeMutable(built.prefix);
127
+ const total = makeMutable(built.total);
128
+ const count = makeMutable(widths.length);
129
+ const hintSv = hint === undefined ? undefined : makeMutable(hint);
130
+ return {
131
+ resolver: createVariableSizeResolver({ sizes, prefix, total, count, hint: hintSv }),
132
+ hintSv,
133
+ };
134
+ };
135
+
136
+ it("reports per-item sizes", () => {
137
+ const { resolver } = makeResolver();
138
+ expect(resolver.variable).toBe(true);
139
+ expect(resolver.itemSize(0)).toBe(80);
140
+ expect(resolver.itemSize(2)).toBe(220);
141
+ expect(resolver.itemSize(4)).toBe(300);
142
+ });
143
+
144
+ it("clamps itemSize out-of-bounds index to first/last", () => {
145
+ const { resolver } = makeResolver();
146
+ expect(resolver.itemSize(-1)).toBe(80);
147
+ expect(resolver.itemSize(99)).toBe(300);
148
+ });
149
+
150
+ it("returns cumulative offsets", () => {
151
+ const { resolver } = makeResolver();
152
+ expect(resolver.offsetAt(0)).toBe(0);
153
+ expect(resolver.offsetAt(1)).toBe(80);
154
+ expect(resolver.offsetAt(2)).toBe(230);
155
+ expect(resolver.offsetAt(3)).toBe(450);
156
+ expect(resolver.offsetAt(4)).toBe(550);
157
+ expect(resolver.offsetAt(5)).toBe(850);
158
+ });
159
+
160
+ it("inverts via indexAt", () => {
161
+ const { resolver } = makeResolver();
162
+ expect(resolver.indexAt(0)).toBe(0);
163
+ expect(resolver.indexAt(79)).toBe(0);
164
+ expect(resolver.indexAt(80)).toBe(1);
165
+ expect(resolver.indexAt(229)).toBe(1);
166
+ expect(resolver.indexAt(230)).toBe(2);
167
+ expect(resolver.indexAt(845)).toBe(4);
168
+ expect(resolver.indexAt(99999)).toBe(4);
169
+ });
170
+
171
+ it("updates the hint when one is supplied", () => {
172
+ const { resolver, hintSv } = makeResolver(0);
173
+ resolver.indexAt(700); // should land at index 4
174
+ expect(hintSv!.value).toBe(4);
175
+ });
176
+
177
+ it("computes midpoints correctly", () => {
178
+ const { resolver } = makeResolver();
179
+ expect(resolver.midpointOf(0)).toBe(40); // 0 + 80/2
180
+ expect(resolver.midpointOf(2)).toBe(340); // 230 + 220/2
181
+ });
182
+
183
+ it("handles empty arrays without crashing", () => {
184
+ const sizes = makeMutable<number[]>([]);
185
+ const prefix = makeMutable<number[]>([0]);
186
+ const total = makeMutable(0);
187
+ const count = makeMutable(0);
188
+ const resolver = createVariableSizeResolver({ sizes, prefix, total, count });
189
+ expect(resolver.itemSize(0)).toBe(0);
190
+ expect(resolver.offsetAt(0)).toBe(0);
191
+ expect(resolver.indexAt(100)).toBe(0);
192
+ });
193
+ });