react-simplikit 0.0.51 → 0.0.53

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 (280) hide show
  1. package/README.md +34 -24
  2. package/dist/components/ImpressionArea/ImpressionArea.cjs +57 -0
  3. package/{esm/components/ImpressionArea/index.d.ts → dist/components/ImpressionArea/ImpressionArea.d.cts} +9 -8
  4. package/dist/components/ImpressionArea/ImpressionArea.d.mts +48 -0
  5. package/dist/components/ImpressionArea/ImpressionArea.mjs +57 -0
  6. package/dist/components/ImpressionArea/index.d.cts +2 -46
  7. package/dist/components/ImpressionArea/index.d.mts +3 -0
  8. package/dist/components/Separated/Separated.cjs +38 -0
  9. package/{esm/components/Separated/index.d.ts → dist/components/Separated/Separated.d.cts} +7 -7
  10. package/dist/components/Separated/Separated.d.mts +38 -0
  11. package/dist/components/Separated/Separated.mjs +38 -0
  12. package/dist/components/Separated/index.d.cts +2 -37
  13. package/dist/components/Separated/index.d.mts +3 -0
  14. package/dist/components/SwitchCase/SwitchCase.cjs +40 -0
  15. package/{esm/components/SwitchCase/index.d.ts → dist/components/SwitchCase/SwitchCase.d.cts} +7 -8
  16. package/dist/components/SwitchCase/SwitchCase.d.mts +45 -0
  17. package/dist/components/SwitchCase/SwitchCase.mjs +40 -0
  18. package/dist/components/SwitchCase/index.d.cts +2 -45
  19. package/dist/components/SwitchCase/index.d.mts +3 -0
  20. package/dist/hooks/useAsyncEffect/index.d.cts +2 -24
  21. package/dist/hooks/useAsyncEffect/index.d.mts +3 -0
  22. package/dist/hooks/useAsyncEffect/useAsyncEffect.cjs +39 -0
  23. package/{esm/hooks/useAsyncEffect/index.d.ts → dist/hooks/useAsyncEffect/useAsyncEffect.d.cts} +4 -3
  24. package/dist/hooks/useAsyncEffect/useAsyncEffect.d.mts +26 -0
  25. package/dist/hooks/useAsyncEffect/useAsyncEffect.mjs +39 -0
  26. package/dist/hooks/useBooleanState/useBooleanState.cjs +36 -0
  27. package/dist/hooks/useBooleanState/{index.d.cts → useBooleanState.d.cts} +4 -2
  28. package/{esm/hooks/useBooleanState/index.d.ts → dist/hooks/useBooleanState/useBooleanState.d.mts} +4 -2
  29. package/dist/hooks/useBooleanState/useBooleanState.mjs +36 -0
  30. package/dist/hooks/useCallbackOncePerRender/index.d.cts +2 -39
  31. package/dist/hooks/useCallbackOncePerRender/index.d.mts +3 -0
  32. package/dist/hooks/useCallbackOncePerRender/useCallbackOncePerRender.cjs +52 -0
  33. package/{esm/hooks/useCallbackOncePerRender/index.d.ts → dist/hooks/useCallbackOncePerRender/useCallbackOncePerRender.d.cts} +4 -3
  34. package/dist/hooks/useCallbackOncePerRender/useCallbackOncePerRender.d.mts +41 -0
  35. package/dist/hooks/useCallbackOncePerRender/useCallbackOncePerRender.mjs +52 -0
  36. package/dist/hooks/useConditionalEffect/index.d.cts +2 -42
  37. package/dist/hooks/useConditionalEffect/index.d.mts +3 -0
  38. package/dist/hooks/useConditionalEffect/useConditionalEffect.cjs +57 -0
  39. package/{esm/hooks/useConditionalEffect/index.d.ts → dist/hooks/useConditionalEffect/useConditionalEffect.d.cts} +4 -3
  40. package/dist/hooks/useConditionalEffect/useConditionalEffect.d.mts +44 -0
  41. package/dist/hooks/useConditionalEffect/useConditionalEffect.mjs +57 -0
  42. package/dist/hooks/useControlledState/index.d.cts +2 -50
  43. package/dist/hooks/useControlledState/index.d.mts +3 -0
  44. package/dist/hooks/useControlledState/useControlledState.cjs +60 -0
  45. package/{esm/hooks/useControlledState/index.d.ts → dist/hooks/useControlledState/useControlledState.d.cts} +11 -10
  46. package/dist/hooks/useControlledState/useControlledState.d.mts +52 -0
  47. package/dist/hooks/useControlledState/useControlledState.mjs +60 -0
  48. package/dist/hooks/useCounter/useCounter.cjs +75 -0
  49. package/{esm/hooks/useCounter/index.d.ts → dist/hooks/useCounter/useCounter.d.cts} +12 -10
  50. package/dist/hooks/useCounter/{index.d.cts → useCounter.d.mts} +12 -10
  51. package/dist/hooks/useCounter/useCounter.mjs +75 -0
  52. package/dist/hooks/useDebounce/debounce.cjs +49 -0
  53. package/dist/hooks/useDebounce/debounce.d.cts +8 -0
  54. package/dist/hooks/useDebounce/debounce.d.mts +8 -0
  55. package/dist/hooks/useDebounce/debounce.mjs +49 -0
  56. package/dist/hooks/useDebounce/useDebounce.cjs +66 -0
  57. package/{esm/hooks/useDebounce/index.d.ts → dist/hooks/useDebounce/useDebounce.d.cts} +6 -8
  58. package/dist/hooks/useDebounce/{index.d.cts → useDebounce.d.mts} +6 -8
  59. package/dist/hooks/useDebounce/useDebounce.mjs +66 -0
  60. package/dist/hooks/useDebouncedCallback/useDebouncedCallback.cjs +62 -0
  61. package/{esm/hooks/useDebouncedCallback/index.d.ts → dist/hooks/useDebouncedCallback/useDebouncedCallback.d.cts} +9 -7
  62. package/dist/hooks/useDebouncedCallback/{index.d.cts → useDebouncedCallback.d.mts} +9 -7
  63. package/dist/hooks/useDebouncedCallback/useDebouncedCallback.mjs +62 -0
  64. package/dist/hooks/useDoubleClick/index.d.cts +2 -45
  65. package/dist/hooks/useDoubleClick/index.d.mts +3 -0
  66. package/dist/hooks/useDoubleClick/useDoubleClick.cjs +64 -0
  67. package/{esm/hooks/useDoubleClick/index.d.ts → dist/hooks/useDoubleClick/useDoubleClick.d.cts} +8 -7
  68. package/dist/hooks/useDoubleClick/useDoubleClick.d.mts +47 -0
  69. package/dist/hooks/useDoubleClick/useDoubleClick.mjs +64 -0
  70. package/dist/hooks/useGeolocation/useGeolocation.cjs +210 -0
  71. package/{esm/hooks/useGeolocation/index.d.ts → dist/hooks/useGeolocation/useGeolocation.d.cts} +26 -24
  72. package/dist/hooks/useGeolocation/{index.d.cts → useGeolocation.d.mts} +26 -24
  73. package/dist/hooks/useGeolocation/useGeolocation.mjs +209 -0
  74. package/dist/hooks/useImpressionRef/useImpressionRef.cjs +67 -0
  75. package/{esm/hooks/useImpressionRef/index.d.ts → dist/hooks/useImpressionRef/useImpressionRef.d.cts} +10 -8
  76. package/dist/hooks/useImpressionRef/{index.d.cts → useImpressionRef.d.mts} +10 -8
  77. package/dist/hooks/useImpressionRef/useImpressionRef.mjs +67 -0
  78. package/dist/hooks/useInputState/index.d.cts +2 -22
  79. package/dist/hooks/useInputState/index.d.mts +3 -0
  80. package/dist/hooks/useInputState/useInputState.cjs +32 -0
  81. package/{esm/hooks/useInputState/index.d.ts → dist/hooks/useInputState/useInputState.d.cts} +4 -3
  82. package/dist/hooks/useInputState/useInputState.d.mts +24 -0
  83. package/dist/hooks/useInputState/useInputState.mjs +32 -0
  84. package/dist/hooks/useIntersectionObserver/useIntersectionObserver.cjs +58 -0
  85. package/dist/hooks/useIntersectionObserver/{index.d.cts → useIntersectionObserver.d.cts} +4 -2
  86. package/{esm/hooks/useIntersectionObserver/index.d.ts → dist/hooks/useIntersectionObserver/useIntersectionObserver.d.mts} +4 -2
  87. package/dist/hooks/useIntersectionObserver/useIntersectionObserver.mjs +58 -0
  88. package/dist/hooks/useInterval/useInterval.cjs +65 -0
  89. package/dist/hooks/useInterval/{index.d.cts → useInterval.d.cts} +7 -5
  90. package/{esm/hooks/useInterval/index.d.ts → dist/hooks/useInterval/useInterval.d.mts} +7 -5
  91. package/dist/hooks/useInterval/useInterval.mjs +65 -0
  92. package/dist/hooks/useIsClient/useIsClient.cjs +49 -0
  93. package/dist/hooks/useIsClient/{index.d.cts → useIsClient.d.cts} +4 -2
  94. package/{esm/hooks/useIsClient/index.d.ts → dist/hooks/useIsClient/useIsClient.d.mts} +4 -2
  95. package/dist/hooks/useIsClient/useIsClient.mjs +49 -0
  96. package/dist/hooks/useIsomorphicLayoutEffect/index.d.cts +2 -24
  97. package/dist/hooks/useIsomorphicLayoutEffect/index.d.mts +3 -0
  98. package/dist/hooks/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.cjs +25 -0
  99. package/{esm/hooks/useIsomorphicLayoutEffect/index.d.ts → dist/hooks/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.d.cts} +4 -3
  100. package/dist/hooks/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.d.mts +26 -0
  101. package/dist/hooks/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.mjs +25 -0
  102. package/dist/hooks/useList/useList.cjs +94 -0
  103. package/{esm/hooks/useList/index.d.ts → dist/hooks/useList/useList.d.cts} +10 -8
  104. package/dist/hooks/useList/{index.d.cts → useList.d.mts} +10 -8
  105. package/dist/hooks/useList/useList.mjs +94 -0
  106. package/dist/hooks/useLoading/useLoading.cjs +61 -0
  107. package/dist/hooks/useLoading/{index.d.cts → useLoading.d.cts} +4 -2
  108. package/{esm/hooks/useLoading/index.d.ts → dist/hooks/useLoading/useLoading.d.mts} +4 -2
  109. package/dist/hooks/useLoading/useLoading.mjs +61 -0
  110. package/dist/hooks/useLongPress/index.d.cts +2 -73
  111. package/dist/hooks/useLongPress/index.d.mts +3 -0
  112. package/dist/hooks/useLongPress/useLongPress.cjs +133 -0
  113. package/{esm/hooks/useLongPress/index.d.ts → dist/hooks/useLongPress/useLongPress.d.cts} +18 -17
  114. package/dist/hooks/useLongPress/useLongPress.d.mts +75 -0
  115. package/dist/hooks/useLongPress/useLongPress.mjs +133 -0
  116. package/dist/hooks/useMap/useMap.cjs +64 -0
  117. package/dist/hooks/useMap/{index.d.cts → useMap.d.cts} +12 -10
  118. package/{esm/hooks/useMap/index.d.ts → dist/hooks/useMap/useMap.d.mts} +12 -10
  119. package/dist/hooks/useMap/useMap.mjs +64 -0
  120. package/dist/hooks/useOutsideClickEffect/useOutsideClickEffect.cjs +51 -0
  121. package/dist/hooks/useOutsideClickEffect/{index.d.cts → useOutsideClickEffect.d.cts} +4 -2
  122. package/{esm/hooks/useOutsideClickEffect/index.d.ts → dist/hooks/useOutsideClickEffect/useOutsideClickEffect.d.mts} +4 -2
  123. package/dist/hooks/useOutsideClickEffect/useOutsideClickEffect.mjs +51 -0
  124. package/dist/hooks/usePreservedCallback/usePreservedCallback.cjs +41 -0
  125. package/dist/hooks/usePreservedCallback/{index.d.cts → usePreservedCallback.d.cts} +4 -2
  126. package/{esm/hooks/usePreservedCallback/index.d.ts → dist/hooks/usePreservedCallback/usePreservedCallback.d.mts} +4 -2
  127. package/dist/hooks/usePreservedCallback/usePreservedCallback.mjs +41 -0
  128. package/dist/hooks/usePreservedReference/usePreservedReference.cjs +55 -0
  129. package/dist/hooks/usePreservedReference/{index.d.cts → usePreservedReference.d.cts} +4 -2
  130. package/{esm/hooks/usePreservedReference/index.d.ts → dist/hooks/usePreservedReference/usePreservedReference.d.mts} +4 -2
  131. package/dist/hooks/usePreservedReference/usePreservedReference.mjs +55 -0
  132. package/dist/hooks/usePrevious/usePrevious.cjs +39 -0
  133. package/{esm/hooks/usePrevious/index.d.ts → dist/hooks/usePrevious/usePrevious.d.cts} +4 -2
  134. package/dist/hooks/usePrevious/{index.d.cts → usePrevious.d.mts} +4 -2
  135. package/dist/hooks/usePrevious/usePrevious.mjs +39 -0
  136. package/dist/hooks/useRefEffect/index.d.cts +2 -30
  137. package/dist/hooks/useRefEffect/index.d.mts +3 -0
  138. package/dist/hooks/useRefEffect/useRefEffect.cjs +42 -0
  139. package/{esm/hooks/useRefEffect/index.d.ts → dist/hooks/useRefEffect/useRefEffect.d.cts} +4 -3
  140. package/dist/hooks/useRefEffect/useRefEffect.d.mts +32 -0
  141. package/dist/hooks/useRefEffect/useRefEffect.mjs +42 -0
  142. package/dist/hooks/useSet/useSet.cjs +79 -0
  143. package/dist/hooks/useSet/{index.d.cts → useSet.d.cts} +9 -7
  144. package/{esm/hooks/useSet/index.d.ts → dist/hooks/useSet/useSet.d.mts} +9 -7
  145. package/dist/hooks/useSet/useSet.mjs +79 -0
  146. package/dist/hooks/useStorageState/index.d.cts +2 -60
  147. package/dist/hooks/useStorageState/index.d.mts +3 -0
  148. package/dist/hooks/useStorageState/storage.cjs +85 -0
  149. package/dist/hooks/useStorageState/storage.d.cts +10 -0
  150. package/dist/hooks/useStorageState/storage.d.mts +10 -0
  151. package/dist/hooks/useStorageState/storage.mjs +80 -0
  152. package/dist/hooks/useStorageState/useStorageState.cjs +81 -0
  153. package/{esm/hooks/useStorageState/index.d.ts → dist/hooks/useStorageState/useStorageState.d.cts} +10 -15
  154. package/dist/hooks/useStorageState/useStorageState.d.mts +56 -0
  155. package/dist/hooks/useStorageState/useStorageState.mjs +81 -0
  156. package/dist/hooks/useThrottle/throttle.cjs +19 -0
  157. package/dist/hooks/useThrottle/throttle.d.cts +19 -0
  158. package/dist/hooks/useThrottle/throttle.d.mts +19 -0
  159. package/dist/hooks/useThrottle/throttle.mjs +19 -0
  160. package/dist/hooks/useThrottle/useThrottle.cjs +49 -0
  161. package/dist/hooks/useThrottle/{index.d.cts → useThrottle.d.cts} +6 -19
  162. package/{esm/hooks/useThrottle/index.d.ts → dist/hooks/useThrottle/useThrottle.d.mts} +6 -19
  163. package/dist/hooks/useThrottle/useThrottle.mjs +49 -0
  164. package/dist/hooks/useThrottledCallback/useThrottledCallback.cjs +65 -0
  165. package/{esm/hooks/useThrottledCallback/index.d.ts → dist/hooks/useThrottledCallback/useThrottledCallback.d.cts} +8 -6
  166. package/dist/hooks/useThrottledCallback/{index.d.cts → useThrottledCallback.d.mts} +8 -6
  167. package/dist/hooks/useThrottledCallback/useThrottledCallback.mjs +65 -0
  168. package/dist/hooks/useTimeout/useTimeout.cjs +40 -0
  169. package/dist/hooks/useTimeout/{index.d.cts → useTimeout.d.cts} +4 -2
  170. package/{esm/hooks/useTimeout/index.d.ts → dist/hooks/useTimeout/useTimeout.d.mts} +4 -2
  171. package/dist/hooks/useTimeout/useTimeout.mjs +40 -0
  172. package/dist/hooks/useToggle/useToggle.cjs +34 -0
  173. package/dist/hooks/useToggle/{index.d.cts → useToggle.d.cts} +4 -4
  174. package/{esm/hooks/useToggle/index.d.ts → dist/hooks/useToggle/useToggle.d.mts} +4 -4
  175. package/dist/hooks/useToggle/useToggle.mjs +34 -0
  176. package/dist/hooks/useVisibilityEvent/useVisibilityEvent.cjs +42 -0
  177. package/{esm/hooks/useVisibilityEvent/index.d.ts → dist/hooks/useVisibilityEvent/useVisibilityEvent.d.cts} +5 -3
  178. package/dist/hooks/useVisibilityEvent/{index.d.cts → useVisibilityEvent.d.mts} +5 -3
  179. package/dist/hooks/useVisibilityEvent/useVisibilityEvent.mjs +42 -0
  180. package/dist/index.cjs +77 -1397
  181. package/dist/index.d.cts +56 -40
  182. package/dist/index.d.mts +56 -0
  183. package/dist/index.mjs +40 -0
  184. package/dist/utils/buildContext/buildContext.cjs +50 -0
  185. package/{esm/utils/buildContext/index.d.ts → dist/utils/buildContext/buildContext.d.cts} +7 -7
  186. package/dist/utils/buildContext/buildContext.d.mts +38 -0
  187. package/dist/utils/buildContext/buildContext.mjs +50 -0
  188. package/dist/utils/buildContext/index.d.cts +2 -37
  189. package/dist/utils/buildContext/index.d.mts +3 -0
  190. package/dist/utils/mergeProps/index.d.cts +2 -25
  191. package/dist/utils/mergeProps/index.d.mts +3 -0
  192. package/dist/utils/mergeProps/mergeProps.cjs +53 -0
  193. package/{esm/utils/mergeProps/index.d.ts → dist/utils/mergeProps/mergeProps.d.cts} +7 -8
  194. package/dist/utils/mergeProps/mergeProps.d.mts +25 -0
  195. package/dist/utils/mergeProps/mergeProps.mjs +53 -0
  196. package/dist/utils/mergeRefs/index.d.cts +2 -38
  197. package/dist/utils/mergeRefs/index.d.mts +3 -0
  198. package/dist/utils/mergeRefs/mergeRefs.cjs +50 -0
  199. package/{esm/utils/mergeRefs/index.d.ts → dist/utils/mergeRefs/mergeRefs.d.cts} +4 -3
  200. package/dist/utils/mergeRefs/mergeRefs.d.mts +40 -0
  201. package/dist/utils/mergeRefs/mergeRefs.mjs +50 -0
  202. package/package.json +9 -11
  203. package/dist/components/ImpressionArea/index.cjs +0 -295
  204. package/dist/components/Separated/index.cjs +0 -41
  205. package/dist/components/SwitchCase/index.cjs +0 -36
  206. package/dist/hooks/useAsyncEffect/index.cjs +0 -49
  207. package/dist/hooks/useBooleanState/index.cjs +0 -46
  208. package/dist/hooks/useCallbackOncePerRender/index.cjs +0 -63
  209. package/dist/hooks/useConditionalEffect/index.cjs +0 -51
  210. package/dist/hooks/useControlledState/index.cjs +0 -57
  211. package/dist/hooks/useCounter/index.cjs +0 -70
  212. package/dist/hooks/useDebounce/index.cjs +0 -130
  213. package/dist/hooks/useDebouncedCallback/index.cjs +0 -148
  214. package/dist/hooks/useDoubleClick/index.cjs +0 -79
  215. package/dist/hooks/useGeolocation/index.cjs +0 -154
  216. package/dist/hooks/useImpressionRef/index.cjs +0 -258
  217. package/dist/hooks/useInputState/index.cjs +0 -46
  218. package/dist/hooks/useIntersectionObserver/index.cjs +0 -95
  219. package/dist/hooks/useInterval/index.cjs +0 -84
  220. package/dist/hooks/useIsClient/index.cjs +0 -40
  221. package/dist/hooks/useIsomorphicLayoutEffect/index.cjs +0 -35
  222. package/dist/hooks/useList/index.cjs +0 -104
  223. package/dist/hooks/useLoading/index.cjs +0 -65
  224. package/dist/hooks/useLongPress/index.cjs +0 -127
  225. package/dist/hooks/useMap/index.cjs +0 -78
  226. package/dist/hooks/useOutsideClickEffect/index.cjs +0 -74
  227. package/dist/hooks/usePreservedCallback/index.cjs +0 -45
  228. package/dist/hooks/usePreservedReference/index.cjs +0 -45
  229. package/dist/hooks/usePrevious/index.cjs +0 -48
  230. package/dist/hooks/useRefEffect/index.cjs +0 -72
  231. package/dist/hooks/useSet/index.cjs +0 -105
  232. package/dist/hooks/useStorageState/index.cjs +0 -196
  233. package/dist/hooks/useThrottle/index.cjs +0 -151
  234. package/dist/hooks/useThrottledCallback/index.cjs +0 -172
  235. package/dist/hooks/useTimeout/index.cjs +0 -57
  236. package/dist/hooks/useToggle/index.cjs +0 -37
  237. package/dist/hooks/useVisibilityEvent/index.cjs +0 -47
  238. package/dist/utils/buildContext/index.cjs +0 -56
  239. package/dist/utils/mergeProps/index.cjs +0 -71
  240. package/dist/utils/mergeRefs/index.cjs +0 -46
  241. package/esm/components/ImpressionArea/index.js +0 -269
  242. package/esm/components/Separated/index.js +0 -15
  243. package/esm/components/SwitchCase/index.js +0 -10
  244. package/esm/hooks/useAsyncEffect/index.js +0 -23
  245. package/esm/hooks/useBooleanState/index.js +0 -20
  246. package/esm/hooks/useCallbackOncePerRender/index.js +0 -37
  247. package/esm/hooks/useConditionalEffect/index.js +0 -25
  248. package/esm/hooks/useControlledState/index.js +0 -31
  249. package/esm/hooks/useCounter/index.js +0 -44
  250. package/esm/hooks/useDebounce/index.js +0 -104
  251. package/esm/hooks/useDebouncedCallback/index.js +0 -122
  252. package/esm/hooks/useDoubleClick/index.js +0 -53
  253. package/esm/hooks/useGeolocation/index.js +0 -128
  254. package/esm/hooks/useImpressionRef/index.js +0 -232
  255. package/esm/hooks/useInputState/index.js +0 -20
  256. package/esm/hooks/useIntersectionObserver/index.js +0 -69
  257. package/esm/hooks/useInterval/index.js +0 -58
  258. package/esm/hooks/useIsClient/index.js +0 -14
  259. package/esm/hooks/useIsomorphicLayoutEffect/index.js +0 -9
  260. package/esm/hooks/useList/index.js +0 -78
  261. package/esm/hooks/useLoading/index.js +0 -39
  262. package/esm/hooks/useLongPress/index.js +0 -101
  263. package/esm/hooks/useMap/index.js +0 -52
  264. package/esm/hooks/useOutsideClickEffect/index.js +0 -48
  265. package/esm/hooks/usePreservedCallback/index.js +0 -19
  266. package/esm/hooks/usePreservedReference/index.js +0 -19
  267. package/esm/hooks/usePrevious/index.js +0 -22
  268. package/esm/hooks/useRefEffect/index.js +0 -46
  269. package/esm/hooks/useSet/index.js +0 -79
  270. package/esm/hooks/useStorageState/index.js +0 -170
  271. package/esm/hooks/useThrottle/index.js +0 -125
  272. package/esm/hooks/useThrottledCallback/index.js +0 -146
  273. package/esm/hooks/useTimeout/index.js +0 -31
  274. package/esm/hooks/useToggle/index.js +0 -11
  275. package/esm/hooks/useVisibilityEvent/index.js +0 -21
  276. package/esm/index.d.ts +0 -40
  277. package/esm/index.js +0 -1335
  278. package/esm/utils/buildContext/index.js +0 -30
  279. package/esm/utils/mergeProps/index.js +0 -45
  280. package/esm/utils/mergeRefs/index.js +0 -20
package/esm/index.js DELETED
@@ -1,1335 +0,0 @@
1
- "use client";
2
-
3
- // src/components/ImpressionArea/ImpressionArea.tsx
4
- import { forwardRef } from "react";
5
-
6
- // src/hooks/useImpressionRef/useImpressionRef.ts
7
- import { useRef as useRef4 } from "react";
8
-
9
- // src/hooks/useDebouncedCallback/useDebouncedCallback.ts
10
- import { useCallback as useCallback2, useEffect as useEffect2, useMemo, useRef as useRef2 } from "react";
11
-
12
- // src/hooks/useDebounce/debounce.ts
13
- function debounce(func, debounceMs, { edges = ["leading", "trailing"] } = {}) {
14
- let pendingThis = void 0;
15
- let pendingArgs = null;
16
- const leading = edges != null && edges.includes("leading");
17
- const trailing = edges == null || edges.includes("trailing");
18
- const invoke = () => {
19
- if (pendingArgs !== null) {
20
- func.apply(pendingThis, pendingArgs);
21
- pendingThis = void 0;
22
- pendingArgs = null;
23
- }
24
- };
25
- const onTimerEnd = () => {
26
- if (trailing) {
27
- invoke();
28
- }
29
- cancel();
30
- };
31
- let timeoutId = null;
32
- const schedule = () => {
33
- if (timeoutId != null) {
34
- clearTimeout(timeoutId);
35
- }
36
- timeoutId = setTimeout(() => {
37
- timeoutId = null;
38
- onTimerEnd();
39
- }, debounceMs);
40
- };
41
- const cancelTimer = () => {
42
- if (timeoutId !== null) {
43
- clearTimeout(timeoutId);
44
- timeoutId = null;
45
- }
46
- };
47
- const cancel = () => {
48
- cancelTimer();
49
- pendingThis = void 0;
50
- pendingArgs = null;
51
- };
52
- const debounced = function(...args) {
53
- pendingThis = this;
54
- pendingArgs = args;
55
- const isFirstCall = timeoutId == null;
56
- schedule();
57
- if (leading && isFirstCall) {
58
- invoke();
59
- }
60
- };
61
- debounced.cancel = cancel;
62
- return debounced;
63
- }
64
-
65
- // src/hooks/usePreservedCallback/usePreservedCallback.ts
66
- import { useCallback, useEffect, useRef } from "react";
67
- function usePreservedCallback(callback) {
68
- const callbackRef = useRef(callback);
69
- useEffect(
70
- function syncCallbackRef() {
71
- callbackRef.current = callback;
72
- },
73
- [callback]
74
- );
75
- return useCallback((...args) => {
76
- return callbackRef.current(...args);
77
- }, []);
78
- }
79
-
80
- // src/hooks/useDebouncedCallback/useDebouncedCallback.ts
81
- function useDebouncedCallback({
82
- onChange,
83
- timeThreshold,
84
- leading = false,
85
- trailing = true
86
- }) {
87
- const handleChange = usePreservedCallback(onChange);
88
- const ref = useRef2({ value: false, clearPreviousDebounce: () => {
89
- } });
90
- useEffect2(function clearDebouncedOnUnmount() {
91
- const current = ref.current;
92
- return () => {
93
- current.clearPreviousDebounce();
94
- };
95
- }, []);
96
- const edges = useMemo(() => {
97
- const _edges = [];
98
- if (leading) {
99
- _edges.push("leading");
100
- }
101
- if (trailing) {
102
- _edges.push("trailing");
103
- }
104
- return _edges;
105
- }, [leading, trailing]);
106
- return useCallback2(
107
- (nextValue) => {
108
- if (nextValue === ref.current.value) {
109
- return;
110
- }
111
- const debounced = debounce(
112
- () => {
113
- handleChange(nextValue);
114
- ref.current.value = nextValue;
115
- },
116
- timeThreshold,
117
- { edges }
118
- );
119
- ref.current.clearPreviousDebounce();
120
- debounced();
121
- ref.current.clearPreviousDebounce = debounced.cancel;
122
- },
123
- [handleChange, timeThreshold, edges]
124
- );
125
- }
126
-
127
- // src/hooks/useIntersectionObserver/useIntersectionObserver.ts
128
- import { useMemo as useMemo2 } from "react";
129
-
130
- // src/hooks/useRefEffect/useRefEffect.ts
131
- import { useCallback as useCallback3, useRef as useRef3 } from "react";
132
- function useRefEffect(callback, deps) {
133
- const preservedCallback = usePreservedCallback(callback);
134
- const cleanupCallbackRef = useRef3(() => {
135
- });
136
- const effect = useCallback3(
137
- (element) => {
138
- cleanupCallbackRef.current();
139
- cleanupCallbackRef.current = () => {
140
- };
141
- if (element == null) {
142
- return;
143
- }
144
- const cleanup = preservedCallback(element);
145
- if (typeof cleanup === "function") {
146
- cleanupCallbackRef.current = cleanup;
147
- }
148
- },
149
- // eslint-disable-next-line react-hooks/exhaustive-deps
150
- [preservedCallback, ...deps]
151
- );
152
- return effect;
153
- }
154
-
155
- // src/hooks/useIntersectionObserver/useIntersectionObserver.ts
156
- function useIntersectionObserver(callback, options) {
157
- const preservedCallback = usePreservedCallback(callback);
158
- const observer = useMemo2(() => {
159
- if (typeof IntersectionObserver === "undefined") {
160
- return;
161
- }
162
- return new IntersectionObserver(([entry]) => {
163
- preservedCallback(entry);
164
- }, options);
165
- }, [preservedCallback, options]);
166
- return useRefEffect(
167
- (element) => {
168
- observer?.observe(element);
169
- return () => {
170
- observer?.unobserve(element);
171
- };
172
- },
173
- [preservedCallback, options]
174
- );
175
- }
176
-
177
- // src/hooks/useVisibilityEvent/useVisibilityEvent.ts
178
- import { useCallback as useCallback4, useEffect as useEffect3 } from "react";
179
- function useVisibilityEvent(callback, options = {}) {
180
- const handleVisibilityChange = useCallback4(() => {
181
- callback(document.visibilityState);
182
- }, [callback]);
183
- useEffect3(() => {
184
- if (options?.immediate ?? false) {
185
- handleVisibilityChange();
186
- }
187
- document.addEventListener("visibilitychange", handleVisibilityChange);
188
- return () => {
189
- document.removeEventListener("visibilitychange", handleVisibilityChange);
190
- };
191
- }, [handleVisibilityChange, options?.immediate]);
192
- }
193
-
194
- // src/hooks/useImpressionRef/useImpressionRef.ts
195
- function useImpressionRef({
196
- onImpressionStart = () => {
197
- },
198
- onImpressionEnd = () => {
199
- },
200
- rootMargin,
201
- areaThreshold = 0,
202
- timeThreshold = 0
203
- }) {
204
- const impressionStartHandler = usePreservedCallback(onImpressionStart);
205
- const impressionEndHandler = usePreservedCallback(onImpressionEnd);
206
- const isIntersectingRef = useRef4(false);
207
- const impressionEventHandler = useDebouncedCallback({
208
- timeThreshold,
209
- onChange: (impressed) => {
210
- (impressed ? impressionStartHandler : impressionEndHandler)();
211
- },
212
- leading: true
213
- });
214
- useVisibilityEvent((documentVisible) => {
215
- if (!isIntersectingRef.current) {
216
- return;
217
- }
218
- impressionEventHandler(documentVisible === "visible");
219
- });
220
- return useIntersectionObserver(
221
- (entry) => {
222
- if (document.visibilityState === "hidden") {
223
- return;
224
- }
225
- const currentRatio = entry.intersectionRatio;
226
- const isIntersecting = areaThreshold === 0 ? entry.isIntersecting : currentRatio >= areaThreshold;
227
- isIntersectingRef.current = isIntersecting;
228
- impressionEventHandler(isIntersecting);
229
- },
230
- { rootMargin, threshold: areaThreshold }
231
- );
232
- }
233
-
234
- // src/utils/mergeRefs/mergeRefs.ts
235
- function mergeRefs(...refs) {
236
- return (value) => {
237
- for (const ref of refs) {
238
- if (ref == null) {
239
- continue;
240
- }
241
- if (typeof ref === "function") {
242
- ref(value);
243
- continue;
244
- }
245
- ref.current = value;
246
- }
247
- };
248
- }
249
-
250
- // src/components/ImpressionArea/ImpressionArea.tsx
251
- import { jsx } from "react/jsx-runtime";
252
- var ImpressionArea = forwardRef(ImpressionAreaImpl);
253
- function ImpressionAreaImpl({ as, rootMargin, areaThreshold, timeThreshold, onImpressionStart, onImpressionEnd, ...props }, ref) {
254
- const Component = as ?? "div";
255
- const impressionRef = useImpressionRef({
256
- onImpressionStart,
257
- onImpressionEnd,
258
- areaThreshold,
259
- timeThreshold,
260
- rootMargin
261
- });
262
- return /* @__PURE__ */ jsx(Component, { ref: mergeRefs(ref, impressionRef), ...props });
263
- }
264
- Object.assign(ImpressionArea, {
265
- displayName: "ImpressionArea"
266
- });
267
-
268
- // src/components/Separated/Separated.tsx
269
- import { Children, Fragment, isValidElement } from "react";
270
- import { Fragment as Fragment2, jsx as jsx2, jsxs } from "react/jsx-runtime";
271
- function Separated({ children, by: separator }) {
272
- const childrenArray = Children.toArray(children).filter(isValidElement);
273
- return /* @__PURE__ */ jsx2(Fragment2, { children: childrenArray.map((child, i, { length }) => /* @__PURE__ */ jsxs(Fragment, { children: [
274
- child,
275
- i + 1 !== length && separator
276
- ] }, child.key ?? i)) });
277
- }
278
-
279
- // src/components/SwitchCase/SwitchCase.tsx
280
- function SwitchCase({ value, caseBy, defaultComponent = () => null }) {
281
- const stringifiedValue = String(value);
282
- return (caseBy[stringifiedValue] ?? defaultComponent)();
283
- }
284
-
285
- // src/hooks/useAsyncEffect/useAsyncEffect.ts
286
- import { useEffect as useEffect4 } from "react";
287
- function useAsyncEffect(effect, deps) {
288
- useEffect4(() => {
289
- let cleanup;
290
- let isCleaned = false;
291
- effect().then((result) => {
292
- cleanup = result;
293
- if (isCleaned) {
294
- cleanup?.();
295
- }
296
- });
297
- return () => {
298
- isCleaned = true;
299
- cleanup?.();
300
- };
301
- }, deps);
302
- }
303
-
304
- // src/hooks/useBooleanState/useBooleanState.ts
305
- import { useCallback as useCallback5, useState } from "react";
306
- function useBooleanState(defaultValue = false) {
307
- const [bool, setBool] = useState(defaultValue);
308
- const setTrue = useCallback5(() => {
309
- setBool(true);
310
- }, []);
311
- const setFalse = useCallback5(() => {
312
- setBool(false);
313
- }, []);
314
- const toggle2 = useCallback5(() => {
315
- setBool((prevBool) => !prevBool);
316
- }, []);
317
- return [bool, setTrue, setFalse, toggle2];
318
- }
319
-
320
- // src/hooks/useCallbackOncePerRender/useCallbackOncePerRender.ts
321
- import { useEffect as useEffect5, useRef as useRef5 } from "react";
322
- function useCallbackOncePerRender(callback, deps) {
323
- const hasFired = useRef5(false);
324
- useEffect5(() => {
325
- hasFired.current = false;
326
- }, deps);
327
- return usePreservedCallback((...args) => {
328
- if (hasFired.current) {
329
- return;
330
- }
331
- callback(...args);
332
- hasFired.current = true;
333
- });
334
- }
335
-
336
- // src/hooks/useConditionalEffect/useConditionalEffect.ts
337
- import { useCallback as useCallback6, useEffect as useEffect6, useRef as useRef6 } from "react";
338
- function useConditionalEffect(effect, deps, condition) {
339
- const prevDepsRef = useRef6(void 0);
340
- const memoizedCondition = useCallback6(condition, deps);
341
- if (deps.length === 0) {
342
- console.warn(
343
- "useConditionalEffect received an empty dependency array. This may indicate missing dependencies and could lead to unexpected behavior."
344
- );
345
- }
346
- const shouldRun = memoizedCondition(prevDepsRef.current, deps);
347
- useEffect6(() => {
348
- if (shouldRun) {
349
- const cleanup = effect();
350
- prevDepsRef.current = deps;
351
- return cleanup;
352
- }
353
- prevDepsRef.current = deps;
354
- }, deps);
355
- }
356
-
357
- // src/hooks/useControlledState/useControlledState.ts
358
- import { useCallback as useCallback7, useState as useState2 } from "react";
359
- function useControlledState({
360
- value: valueProp,
361
- defaultValue,
362
- onChange,
363
- equalityFn = Object.is
364
- }) {
365
- const [uncontrolledState, setUncontrolledState] = useState2(defaultValue);
366
- const controlled = valueProp !== void 0;
367
- const value = controlled ? valueProp : uncontrolledState;
368
- const setValue = useCallback7(
369
- (next) => {
370
- const nextValue = isSetStateAction(next) ? next(value) : next;
371
- if (equalityFn(value, nextValue) === true) return;
372
- if (controlled === false) setUncontrolledState(nextValue);
373
- if (controlled === true && nextValue === void 0) setUncontrolledState(nextValue);
374
- onChange?.(nextValue);
375
- },
376
- [controlled, onChange, equalityFn, value]
377
- );
378
- return [value, setValue];
379
- }
380
- function isSetStateAction(next) {
381
- return typeof next === "function";
382
- }
383
-
384
- // src/hooks/useCounter/useCounter.ts
385
- import { useCallback as useCallback8, useState as useState3 } from "react";
386
- var validateValue = (value, { min, max }) => {
387
- if (min !== void 0 && value < min) {
388
- return min;
389
- }
390
- if (max !== void 0 && value > max) {
391
- return max;
392
- }
393
- return value;
394
- };
395
- function useCounter(initialValue = 0, { min, max, step = 1 } = {}) {
396
- const [count, setCountState] = useState3(() => validateValue(initialValue, { min, max }));
397
- const setCount = useCallback8(
398
- (value) => {
399
- setCountState((prev) => {
400
- const nextValue = typeof value === "function" ? value(prev) : value;
401
- return validateValue(nextValue, { min, max });
402
- });
403
- },
404
- [min, max]
405
- );
406
- const increment = useCallback8(() => {
407
- setCount((prev) => prev + step);
408
- }, [setCount, step]);
409
- const decrement = useCallback8(() => {
410
- setCount((prev) => prev - step);
411
- }, [setCount, step]);
412
- const reset = useCallback8(() => {
413
- setCount(initialValue);
414
- }, [setCount, initialValue]);
415
- return {
416
- count,
417
- increment,
418
- decrement,
419
- reset,
420
- setCount
421
- };
422
- }
423
-
424
- // src/hooks/useDebounce/useDebounce.ts
425
- import { useEffect as useEffect7 } from "react";
426
- import { useMemo as useMemo3 } from "react";
427
- function useDebounce(callback, wait, options = {}) {
428
- const preservedCallback = usePreservedCallback(callback);
429
- const { leading = false, trailing = true } = options;
430
- const edges = useMemo3(() => {
431
- const _edges = [];
432
- if (leading) {
433
- _edges.push("leading");
434
- }
435
- if (trailing) {
436
- _edges.push("trailing");
437
- }
438
- return _edges;
439
- }, [leading, trailing]);
440
- const debounced = useMemo3(() => {
441
- return debounce(preservedCallback, wait, { edges });
442
- }, [preservedCallback, wait, edges]);
443
- useEffect7(
444
- function cancelDebouncedOnUnmount() {
445
- return () => {
446
- debounced.cancel();
447
- };
448
- },
449
- [debounced]
450
- );
451
- return debounced;
452
- }
453
-
454
- // src/hooks/useDoubleClick/useDoubleClick.ts
455
- import { useCallback as useCallback9, useEffect as useEffect8, useRef as useRef7 } from "react";
456
- function useDoubleClick({
457
- delay = 250,
458
- click,
459
- doubleClick
460
- }) {
461
- const clickTimeout = useRef7(null);
462
- const clearClickTimeout = usePreservedCallback(() => {
463
- if (clickTimeout.current != null) {
464
- window.clearTimeout(clickTimeout.current);
465
- clickTimeout.current = null;
466
- }
467
- });
468
- useEffect8(() => () => clearClickTimeout(), [clearClickTimeout]);
469
- const handleEvent = useCallback9(
470
- (event) => {
471
- clearClickTimeout();
472
- if (click && event.detail === 1) {
473
- clickTimeout.current = window.setTimeout(() => {
474
- click(event);
475
- }, delay);
476
- }
477
- if (event.detail === 2) {
478
- doubleClick(event);
479
- }
480
- },
481
- [click, doubleClick, delay, clearClickTimeout]
482
- );
483
- return handleEvent;
484
- }
485
-
486
- // src/hooks/useGeolocation/useGeolocation.ts
487
- import { useCallback as useCallback10, useEffect as useEffect9, useRef as useRef8, useState as useState4 } from "react";
488
- var CustomGeoLocationError = class extends Error {
489
- code;
490
- constructor({ code, message }) {
491
- super(message);
492
- this.name = "CustomGeoLocationError";
493
- this.code = code;
494
- }
495
- };
496
- var GeolocationMountBehavior = {
497
- GET: "get",
498
- WATCH: "watch"
499
- };
500
- function useGeolocation(options) {
501
- const [state, setState] = useState4({
502
- loading: !!options?.mountBehavior,
503
- error: null,
504
- data: null
505
- });
506
- const [isTracking, setIsTracking] = useState4(false);
507
- const watchIdRef = useRef8(null);
508
- const checkGeolocationSupport = useCallback10(() => {
509
- if (typeof window === "undefined" || navigator.geolocation === void 0) {
510
- setState((prev) => ({
511
- ...prev,
512
- loading: false,
513
- error: new CustomGeoLocationError({
514
- code: 0,
515
- message: "Geolocation is not supported by this environment."
516
- })
517
- }));
518
- return false;
519
- }
520
- return true;
521
- }, []);
522
- const handleSuccess = useCallback10((position) => {
523
- const { coords } = position;
524
- setState((prev) => ({
525
- ...prev,
526
- loading: false,
527
- error: null,
528
- data: {
529
- latitude: coords.latitude,
530
- longitude: coords.longitude,
531
- accuracy: coords.accuracy,
532
- altitude: coords.altitude,
533
- altitudeAccuracy: coords.altitudeAccuracy,
534
- heading: coords.heading,
535
- speed: coords.speed,
536
- timestamp: position.timestamp
537
- }
538
- }));
539
- }, []);
540
- const handleError = useCallback10((error) => {
541
- const { code, message } = error;
542
- setState((prev) => ({
543
- ...prev,
544
- loading: false,
545
- error: new CustomGeoLocationError({ code, message })
546
- }));
547
- }, []);
548
- const getGeolocationOptions = useCallback10(
549
- () => ({
550
- enableHighAccuracy: options?.enableHighAccuracy,
551
- maximumAge: options?.maximumAge,
552
- timeout: options?.timeout
553
- }),
554
- [options?.enableHighAccuracy, options?.maximumAge, options?.timeout]
555
- );
556
- const getCurrentPosition = useCallback10(() => {
557
- if (!checkGeolocationSupport()) {
558
- return;
559
- }
560
- setState((prev) => ({ ...prev, loading: true }));
561
- navigator.geolocation.getCurrentPosition(handleSuccess, handleError, getGeolocationOptions());
562
- }, [handleSuccess, handleError, getGeolocationOptions, checkGeolocationSupport]);
563
- const startTracking = useCallback10(() => {
564
- if (!checkGeolocationSupport()) {
565
- return;
566
- }
567
- if (watchIdRef.current !== null) {
568
- navigator.geolocation.clearWatch(watchIdRef.current);
569
- }
570
- setState((prev) => ({ ...prev, loading: true }));
571
- watchIdRef.current = navigator.geolocation.watchPosition(
572
- (position) => {
573
- setIsTracking(true);
574
- handleSuccess(position);
575
- },
576
- handleError,
577
- getGeolocationOptions()
578
- );
579
- }, [handleSuccess, handleError, getGeolocationOptions, checkGeolocationSupport]);
580
- const stopTracking = useCallback10(() => {
581
- if (watchIdRef.current === null) {
582
- return;
583
- }
584
- navigator.geolocation.clearWatch(watchIdRef.current);
585
- watchIdRef.current = null;
586
- setIsTracking(false);
587
- }, []);
588
- useEffect9(() => {
589
- if (options?.mountBehavior === GeolocationMountBehavior.WATCH) {
590
- startTracking();
591
- } else if (options?.mountBehavior === GeolocationMountBehavior.GET) {
592
- getCurrentPosition();
593
- }
594
- return () => {
595
- if (watchIdRef.current !== null) {
596
- navigator.geolocation.clearWatch(watchIdRef.current);
597
- watchIdRef.current = null;
598
- }
599
- };
600
- }, [options?.mountBehavior, getCurrentPosition, startTracking]);
601
- return {
602
- ...state,
603
- getCurrentPosition,
604
- startTracking,
605
- stopTracking,
606
- isTracking
607
- };
608
- }
609
-
610
- // src/hooks/useInputState/useInputState.ts
611
- import { useCallback as useCallback11, useState as useState5 } from "react";
612
- function useInputState(initialValue = "", transformValue = echo) {
613
- const [value, setValue] = useState5(initialValue);
614
- const handleValueChange = useCallback11(
615
- ({ target: { value: value2 } }) => {
616
- setValue(transformValue(value2));
617
- },
618
- [transformValue]
619
- );
620
- return [value, handleValueChange];
621
- }
622
- function echo(v) {
623
- return v;
624
- }
625
-
626
- // src/hooks/useInterval/useInterval.ts
627
- import { useEffect as useEffect10, useRef as useRef9 } from "react";
628
- function useInterval(callback, options) {
629
- const delay = typeof options === "number" ? options : options.delay;
630
- const immediate = typeof options === "number" ? false : options.immediate;
631
- const enabled = typeof options === "number" ? true : options.enabled ?? true;
632
- const preservedCallback = usePreservedCallback(callback);
633
- const immediateCalledRef = useRef9(false);
634
- useEffect10(
635
- function runImmediateCallback() {
636
- if (immediate !== true) {
637
- immediateCalledRef.current = false;
638
- return;
639
- }
640
- if (!enabled) {
641
- return;
642
- }
643
- if (immediateCalledRef.current) {
644
- return;
645
- }
646
- immediateCalledRef.current = true;
647
- preservedCallback();
648
- },
649
- [immediate, preservedCallback, enabled]
650
- );
651
- useEffect10(
652
- function startInterval() {
653
- if (!enabled) {
654
- return;
655
- }
656
- const id = setInterval(preservedCallback, delay);
657
- return () => clearInterval(id);
658
- },
659
- [delay, preservedCallback, enabled]
660
- );
661
- }
662
-
663
- // src/hooks/useIsClient/useIsClient.ts
664
- import { useEffect as useEffect11, useState as useState6 } from "react";
665
- function useIsClient() {
666
- const [isClient, setIsClient] = useState6(false);
667
- useEffect11(function syncClientState() {
668
- setIsClient(true);
669
- }, []);
670
- return isClient;
671
- }
672
-
673
- // src/hooks/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.ts
674
- import { useEffect as useEffect12, useLayoutEffect } from "react";
675
- var isServer = typeof window === "undefined";
676
- var useIsomorphicLayoutEffect = isServer ? useEffect12 : useLayoutEffect;
677
-
678
- // src/hooks/useList/useList.ts
679
- import { useMemo as useMemo5, useState as useState7 } from "react";
680
-
681
- // src/hooks/usePreservedReference/usePreservedReference.ts
682
- import { useMemo as useMemo4, useRef as useRef10 } from "react";
683
- function usePreservedReference(value, areValuesEqual = areDeeplyEqual) {
684
- const ref = useRef10(value);
685
- return useMemo4(() => {
686
- if (!areValuesEqual(ref.current, value)) {
687
- ref.current = value;
688
- }
689
- return ref.current;
690
- }, [areValuesEqual, value]);
691
- }
692
- function areDeeplyEqual(x, y) {
693
- return JSON.stringify(x) === JSON.stringify(y);
694
- }
695
-
696
- // src/hooks/useList/useList.ts
697
- function useList(initialState = []) {
698
- const [list, setList] = useState7(initialState);
699
- const preservedInitialState = usePreservedReference(initialState);
700
- const push = usePreservedCallback((value) => {
701
- setList((prev) => [...prev, value]);
702
- });
703
- const insertAt = usePreservedCallback((index, value) => {
704
- setList((prev) => {
705
- const next = [...prev];
706
- next.splice(index, 0, value);
707
- return next;
708
- });
709
- });
710
- const updateAt = usePreservedCallback((index, value) => {
711
- setList((prev) => {
712
- const next = [...prev];
713
- next[index] = value;
714
- return next;
715
- });
716
- });
717
- const removeAt = usePreservedCallback((index) => {
718
- setList((prev) => {
719
- const next = [...prev];
720
- next.splice(index, 1);
721
- return next;
722
- });
723
- });
724
- const setAll = usePreservedCallback((values) => {
725
- setList(values);
726
- });
727
- const reset = usePreservedCallback(() => {
728
- setList(preservedInitialState);
729
- });
730
- const actions = useMemo5(
731
- () => ({ push, insertAt, updateAt, removeAt, setAll, reset }),
732
- [push, insertAt, updateAt, removeAt, setAll, reset]
733
- );
734
- return [list, actions];
735
- }
736
-
737
- // src/hooks/useLoading/useLoading.ts
738
- import { useCallback as useCallback12, useEffect as useEffect13, useMemo as useMemo6, useRef as useRef11, useState as useState8 } from "react";
739
- function useLoading() {
740
- const [loading, setLoading] = useState8(false);
741
- const ref = useIsMountedRef();
742
- const startTransition = useCallback12(
743
- async (promise) => {
744
- try {
745
- setLoading(true);
746
- const data = await promise;
747
- return data;
748
- } finally {
749
- if (ref.isMounted) {
750
- setLoading(false);
751
- }
752
- }
753
- },
754
- [ref.isMounted]
755
- );
756
- return useMemo6(() => [loading, startTransition], [loading, startTransition]);
757
- }
758
- function useIsMountedRef() {
759
- const ref = useRef11({ isMounted: true }).current;
760
- useEffect13(
761
- function trackMountedState() {
762
- ref.isMounted = true;
763
- return () => {
764
- ref.isMounted = false;
765
- };
766
- },
767
- [ref]
768
- );
769
- return ref;
770
- }
771
-
772
- // src/hooks/useLongPress/useLongPress.ts
773
- import { useCallback as useCallback13, useRef as useRef12 } from "react";
774
- function useLongPress(onLongPress, { delay = 500, moveThreshold, onClick, onLongPressEnd } = {}) {
775
- const timeoutRef = useRef12(null);
776
- const isLongPressActiveRef = useRef12(false);
777
- const initialPositionRef = useRef12({ x: 0, y: 0 });
778
- const preservedOnLongPress = usePreservedCallback(onLongPress);
779
- const preservedOnClick = usePreservedCallback(onClick || (() => {
780
- }));
781
- const preservedOnLongPressEnd = usePreservedCallback(onLongPressEnd || (() => {
782
- }));
783
- const hasThreshold = moveThreshold?.x !== void 0 || moveThreshold?.y !== void 0;
784
- const getClientPosition = useCallback13((event) => {
785
- if ("touches" in event.nativeEvent) {
786
- const touch = event.nativeEvent.touches[0];
787
- return { x: touch.clientX, y: touch.clientY };
788
- }
789
- return {
790
- x: event.nativeEvent.clientX,
791
- y: event.nativeEvent.clientY
792
- };
793
- }, []);
794
- const isMovedBeyondThreshold = useCallback13(
795
- (event) => {
796
- const { x, y } = getClientPosition(event);
797
- const deltaX = Math.abs(x - initialPositionRef.current.x);
798
- const deltaY = Math.abs(y - initialPositionRef.current.y);
799
- return moveThreshold?.x !== void 0 && deltaX > moveThreshold.x || moveThreshold?.y !== void 0 && deltaY > moveThreshold.y;
800
- },
801
- [getClientPosition, moveThreshold]
802
- );
803
- const cancelLongPress = useCallback13(() => {
804
- if (timeoutRef.current !== null) {
805
- window.clearTimeout(timeoutRef.current);
806
- timeoutRef.current = null;
807
- }
808
- }, []);
809
- const handlePressStart = useCallback13(
810
- (event) => {
811
- cancelLongPress();
812
- const position = getClientPosition(event);
813
- initialPositionRef.current = position;
814
- isLongPressActiveRef.current = false;
815
- timeoutRef.current = window.setTimeout(() => {
816
- isLongPressActiveRef.current = true;
817
- preservedOnLongPress(event);
818
- }, delay);
819
- },
820
- [cancelLongPress, delay, getClientPosition, preservedOnLongPress]
821
- );
822
- const handlePressEnd = useCallback13(
823
- (event) => {
824
- if (isLongPressActiveRef.current) {
825
- preservedOnLongPressEnd(event);
826
- } else if (timeoutRef.current !== null) {
827
- preservedOnClick(event);
828
- }
829
- cancelLongPress();
830
- isLongPressActiveRef.current = false;
831
- },
832
- [cancelLongPress, preservedOnClick, preservedOnLongPressEnd]
833
- );
834
- const handlePressMove = useCallback13(
835
- (event) => {
836
- if (timeoutRef.current !== null && isMovedBeyondThreshold(event)) {
837
- cancelLongPress();
838
- }
839
- },
840
- [cancelLongPress, isMovedBeyondThreshold]
841
- );
842
- return {
843
- onMouseDown: handlePressStart,
844
- onMouseUp: handlePressEnd,
845
- onMouseLeave: cancelLongPress,
846
- onTouchStart: handlePressStart,
847
- onTouchEnd: handlePressEnd,
848
- ...hasThreshold ? { onTouchMove: handlePressMove, onMouseMove: handlePressMove } : {}
849
- };
850
- }
851
-
852
- // src/hooks/useMap/useMap.ts
853
- import { useCallback as useCallback14, useMemo as useMemo7, useState as useState9 } from "react";
854
- function useMap(initialState = /* @__PURE__ */ new Map()) {
855
- const [map, setMap] = useState9(() => new Map(initialState));
856
- const preservedInitialState = usePreservedReference(initialState);
857
- const set = useCallback14((key, value) => {
858
- setMap((prev) => {
859
- const nextMap = new Map(prev);
860
- nextMap.set(key, value);
861
- return nextMap;
862
- });
863
- }, []);
864
- const setAll = useCallback14((entries) => {
865
- setMap(() => new Map(entries));
866
- }, []);
867
- const remove = useCallback14((key) => {
868
- setMap((prev) => {
869
- const nextMap = new Map(prev);
870
- nextMap.delete(key);
871
- return nextMap;
872
- });
873
- }, []);
874
- const reset = useCallback14(() => {
875
- setMap(() => new Map(preservedInitialState));
876
- }, [preservedInitialState]);
877
- const actions = useMemo7(() => {
878
- return { set, setAll, remove, reset };
879
- }, [set, setAll, remove, reset]);
880
- return [map, actions];
881
- }
882
-
883
- // src/hooks/useOutsideClickEffect/useOutsideClickEffect.ts
884
- import { useEffect as useEffect14, useRef as useRef13 } from "react";
885
- function useOutsideClickEffect(container, callback) {
886
- const containers = useRef13([]);
887
- const handleDocumentClick = usePreservedCallback(({ target }) => {
888
- if (target === null) {
889
- return;
890
- }
891
- if (containers.current.length === 0) {
892
- return;
893
- }
894
- if (containers.current.some((x) => x.contains(target))) {
895
- return;
896
- }
897
- callback();
898
- });
899
- useEffect14(() => {
900
- containers.current = [container].flat(1).filter((item) => item != null);
901
- }, [container]);
902
- useEffect14(() => {
903
- document.addEventListener("click", handleDocumentClick);
904
- return () => {
905
- document.removeEventListener("click", handleDocumentClick);
906
- };
907
- }, [handleDocumentClick]);
908
- }
909
-
910
- // src/hooks/usePrevious/usePrevious.ts
911
- import { useRef as useRef14 } from "react";
912
- var strictEquals = (prev, next) => prev === next;
913
- function usePrevious(state, compare = strictEquals) {
914
- const prevRef = useRef14(state);
915
- const currentRef = useRef14(state);
916
- const isFirstRender = useRef14(true);
917
- if (isFirstRender.current) {
918
- isFirstRender.current = false;
919
- return prevRef.current;
920
- }
921
- if (!compare(currentRef.current, state)) {
922
- prevRef.current = currentRef.current;
923
- currentRef.current = state;
924
- }
925
- return prevRef.current;
926
- }
927
-
928
- // src/hooks/useSet/useSet.ts
929
- import { useMemo as useMemo8, useState as useState10 } from "react";
930
- function useSet(initialState = /* @__PURE__ */ new Set()) {
931
- const [set, setSet] = useState10(() => new Set(initialState));
932
- const preservedInitialState = usePreservedReference(initialState);
933
- const add = usePreservedCallback((value) => {
934
- setSet((prev) => {
935
- const nextSet = new Set(prev);
936
- nextSet.add(value);
937
- return nextSet;
938
- });
939
- });
940
- const remove = usePreservedCallback((value) => {
941
- setSet((prev) => {
942
- const nextSet = new Set(prev);
943
- nextSet.delete(value);
944
- return nextSet;
945
- });
946
- });
947
- const toggle2 = usePreservedCallback((value) => {
948
- setSet((prev) => {
949
- const nextSet = new Set(prev);
950
- if (nextSet.has(value)) {
951
- nextSet.delete(value);
952
- } else {
953
- nextSet.add(value);
954
- }
955
- return nextSet;
956
- });
957
- });
958
- const setAll = usePreservedCallback((values) => {
959
- setSet(() => new Set(values));
960
- });
961
- const reset = usePreservedCallback(() => {
962
- setSet(() => new Set(preservedInitialState));
963
- });
964
- const actions = useMemo8(
965
- () => ({ add, remove, toggle: toggle2, setAll, reset }),
966
- [add, remove, toggle2, setAll, reset]
967
- );
968
- return [set, actions];
969
- }
970
-
971
- // src/hooks/useStorageState/useStorageState.ts
972
- import { useCallback as useCallback15, useRef as useRef15, useSyncExternalStore } from "react";
973
-
974
- // src/hooks/useStorageState/storage.ts
975
- var MemoStorage = class {
976
- storage = /* @__PURE__ */ new Map();
977
- get(key) {
978
- return this.storage.get(key) ?? null;
979
- }
980
- set(key, value) {
981
- this.storage.set(key, value);
982
- }
983
- remove(key) {
984
- this.storage.delete(key);
985
- }
986
- clear() {
987
- this.storage.clear();
988
- }
989
- };
990
- var LocalStorage = class {
991
- static canUse() {
992
- const TEST_KEY = generateTestKey();
993
- try {
994
- localStorage.setItem(TEST_KEY, "test");
995
- localStorage.removeItem(TEST_KEY);
996
- return true;
997
- } catch {
998
- return false;
999
- }
1000
- }
1001
- get(key) {
1002
- return localStorage.getItem(key);
1003
- }
1004
- set(key, value) {
1005
- localStorage.setItem(key, value);
1006
- }
1007
- remove(key) {
1008
- localStorage.removeItem(key);
1009
- }
1010
- clear() {
1011
- localStorage.clear();
1012
- }
1013
- };
1014
- var SessionStorage = class {
1015
- static canUse() {
1016
- const TEST_KEY = generateTestKey();
1017
- try {
1018
- sessionStorage.setItem(TEST_KEY, "test");
1019
- sessionStorage.removeItem(TEST_KEY);
1020
- return true;
1021
- } catch {
1022
- return false;
1023
- }
1024
- }
1025
- get(key) {
1026
- return sessionStorage.getItem(key);
1027
- }
1028
- set(key, value) {
1029
- sessionStorage.setItem(key, value);
1030
- }
1031
- remove(key) {
1032
- sessionStorage.removeItem(key);
1033
- }
1034
- clear() {
1035
- sessionStorage.clear();
1036
- }
1037
- };
1038
- function generateTestKey() {
1039
- return new Array(4).fill(null).map(() => Math.random().toString(36).slice(2)).join("");
1040
- }
1041
- function generateStorage() {
1042
- if (LocalStorage.canUse()) {
1043
- return new LocalStorage();
1044
- }
1045
- return new MemoStorage();
1046
- }
1047
- function generateSessionStorage() {
1048
- if (SessionStorage.canUse()) {
1049
- return new SessionStorage();
1050
- }
1051
- return new MemoStorage();
1052
- }
1053
- var safeLocalStorage = generateStorage();
1054
- var safeSessionStorage = generateSessionStorage();
1055
-
1056
- // src/hooks/useStorageState/useStorageState.ts
1057
- var listeners = /* @__PURE__ */ new Set();
1058
- var emitListeners = () => {
1059
- listeners.forEach((listener) => listener());
1060
- };
1061
- function isPlainObject(value) {
1062
- if (typeof value !== "object") {
1063
- return false;
1064
- }
1065
- const proto = Object.getPrototypeOf(value);
1066
- const hasObjectPrototype = proto === Object.prototype;
1067
- if (!hasObjectPrototype) {
1068
- return false;
1069
- }
1070
- return Object.prototype.toString.call(value) === "[object Object]";
1071
- }
1072
- var ensureSerializable = (value) => {
1073
- if (value[0] != null && !["string", "number", "boolean"].includes(typeof value[0]) && !(isPlainObject(value[0]) || Array.isArray(value[0]))) {
1074
- throw new Error("Received a non-serializable value");
1075
- }
1076
- return value;
1077
- };
1078
- function useStorageState(key, {
1079
- storage = safeLocalStorage,
1080
- defaultValue,
1081
- ...options
1082
- } = {}) {
1083
- const serializedDefaultValue = defaultValue;
1084
- const cache = useRef15({
1085
- data: null,
1086
- parsed: serializedDefaultValue
1087
- });
1088
- const getSnapshot = useCallback15(() => {
1089
- const deserializer = "deserializer" in options ? options.deserializer : JSON.parse;
1090
- const data = storage.get(key);
1091
- if (data !== cache.current.data) {
1092
- try {
1093
- cache.current.parsed = data != null ? deserializer(data) : defaultValue;
1094
- } catch {
1095
- cache.current.parsed = serializedDefaultValue;
1096
- }
1097
- cache.current.data = data;
1098
- }
1099
- return cache.current.parsed;
1100
- }, [defaultValue, key, storage]);
1101
- const storageState = useSyncExternalStore(
1102
- (onStoreChange) => {
1103
- listeners.add(onStoreChange);
1104
- const handler = (event) => {
1105
- if (event.key === key) {
1106
- onStoreChange();
1107
- }
1108
- };
1109
- window.addEventListener("storage", handler);
1110
- return () => {
1111
- listeners.delete(onStoreChange);
1112
- window.removeEventListener("storage", handler);
1113
- };
1114
- },
1115
- () => getSnapshot(),
1116
- () => serializedDefaultValue
1117
- );
1118
- const setStorageState = useCallback15(
1119
- (value) => {
1120
- const serializer = "serializer" in options ? options.serializer : JSON.stringify;
1121
- const nextValue = typeof value === "function" ? value(getSnapshot()) : value;
1122
- if (nextValue == null) {
1123
- storage.remove(key);
1124
- } else {
1125
- storage.set(key, serializer(nextValue));
1126
- }
1127
- emitListeners();
1128
- },
1129
- [getSnapshot, key, storage]
1130
- );
1131
- const refreshStorageState = useCallback15(() => {
1132
- setStorageState(getSnapshot());
1133
- }, [storage, getSnapshot, setStorageState]);
1134
- return ensureSerializable([storageState, setStorageState, refreshStorageState]);
1135
- }
1136
-
1137
- // src/hooks/useThrottle/useThrottle.ts
1138
- import { useEffect as useEffect15, useMemo as useMemo9 } from "react";
1139
-
1140
- // src/hooks/useThrottle/throttle.ts
1141
- function throttle(func, throttleMs, { edges = ["leading", "trailing"] } = {}) {
1142
- let pendingAt = null;
1143
- const debounced = debounce(func, throttleMs, { edges });
1144
- const throttled = function(...args) {
1145
- if (pendingAt == null) {
1146
- pendingAt = Date.now();
1147
- } else {
1148
- if (Date.now() - pendingAt >= throttleMs) {
1149
- pendingAt = Date.now();
1150
- debounced.cancel();
1151
- }
1152
- }
1153
- debounced(...args);
1154
- };
1155
- throttled.cancel = debounced.cancel;
1156
- return throttled;
1157
- }
1158
-
1159
- // src/hooks/useThrottle/useThrottle.ts
1160
- function useThrottle(callback, wait, options) {
1161
- const preservedCallback = usePreservedCallback(callback);
1162
- const preservedOptions = usePreservedReference(options ?? {});
1163
- const throttledCallback = useMemo9(
1164
- () => throttle(preservedCallback, wait, preservedOptions),
1165
- [preservedOptions, preservedCallback, wait]
1166
- );
1167
- useEffect15(() => {
1168
- return () => {
1169
- throttledCallback.cancel();
1170
- };
1171
- }, [throttledCallback]);
1172
- return throttledCallback;
1173
- }
1174
-
1175
- // src/hooks/useThrottledCallback/useThrottledCallback.ts
1176
- import { useCallback as useCallback16, useEffect as useEffect16, useRef as useRef16 } from "react";
1177
- function useThrottledCallback({
1178
- onChange,
1179
- timeThreshold,
1180
- edges = ["leading", "trailing"]
1181
- }) {
1182
- const handleChange = usePreservedCallback(onChange);
1183
- const ref = useRef16({ value: false, clearPreviousThrottle: () => {
1184
- } });
1185
- useEffect16(function cleanupThrottleOnUnmount() {
1186
- const current = ref.current;
1187
- return () => {
1188
- current.clearPreviousThrottle();
1189
- };
1190
- }, []);
1191
- const preservedEdges = usePreservedReference(edges);
1192
- return useCallback16(
1193
- (nextValue) => {
1194
- if (nextValue === ref.current.value) {
1195
- return;
1196
- }
1197
- const throttled = throttle(
1198
- () => {
1199
- handleChange(nextValue);
1200
- ref.current.value = nextValue;
1201
- },
1202
- timeThreshold,
1203
- { edges: preservedEdges }
1204
- );
1205
- ref.current.clearPreviousThrottle();
1206
- throttled();
1207
- ref.current.clearPreviousThrottle = throttled.cancel;
1208
- },
1209
- [handleChange, timeThreshold, preservedEdges]
1210
- );
1211
- }
1212
-
1213
- // src/hooks/useTimeout/useTimeout.ts
1214
- import { useEffect as useEffect17 } from "react";
1215
- function useTimeout(callback, delay = 0) {
1216
- const preservedCallback = usePreservedCallback(callback);
1217
- useEffect17(() => {
1218
- const timeoutId = setTimeout(preservedCallback, delay);
1219
- return () => clearTimeout(timeoutId);
1220
- }, [delay, preservedCallback]);
1221
- }
1222
-
1223
- // src/hooks/useToggle/useToggle.ts
1224
- import { useReducer } from "react";
1225
- function useToggle(initialValue = false) {
1226
- return useReducer(toggle, initialValue);
1227
- }
1228
- var toggle = (state) => !state;
1229
-
1230
- // src/utils/buildContext/buildContext.tsx
1231
- import { createContext, useContext, useMemo as useMemo10 } from "react";
1232
- import { jsx as jsx3 } from "react/jsx-runtime";
1233
- function buildContext(contextName, defaultContextValues) {
1234
- const Context = createContext(defaultContextValues ?? void 0);
1235
- function Provider({ children, ...contextValues }) {
1236
- const value = useMemo10(
1237
- () => Object.keys(contextValues).length > 0 ? contextValues : null,
1238
- // eslint-disable-next-line react-hooks/exhaustive-deps
1239
- [...Object.values(contextValues)]
1240
- );
1241
- return /* @__PURE__ */ jsx3(Context.Provider, { value, children });
1242
- }
1243
- function useInnerContext() {
1244
- const context = useContext(Context);
1245
- if (context != null) {
1246
- return context;
1247
- }
1248
- if (defaultContextValues != null) {
1249
- return defaultContextValues;
1250
- }
1251
- throw new Error(`\`${contextName}Context\` must be used within \`${contextName}Provider\``);
1252
- }
1253
- return [Provider, useInnerContext];
1254
- }
1255
-
1256
- // src/utils/mergeProps/mergeProps.ts
1257
- function mergeProps(...props) {
1258
- return props.reduce(pushProp, {});
1259
- }
1260
- function pushProp(prev, curr) {
1261
- for (const key in curr) {
1262
- if (curr[key] === void 0) continue;
1263
- switch (key) {
1264
- case "className": {
1265
- prev[key] = [prev[key], curr[key]].join(" ").trim();
1266
- break;
1267
- }
1268
- case "style": {
1269
- prev[key] = mergeStyle(prev[key], curr[key]);
1270
- break;
1271
- }
1272
- default: {
1273
- const mergedFunction = mergeFunction(prev[key], curr[key]);
1274
- if (mergedFunction) {
1275
- prev[key] = mergedFunction;
1276
- } else if (curr[key] !== void 0) {
1277
- prev[key] = curr[key];
1278
- }
1279
- }
1280
- }
1281
- }
1282
- return prev;
1283
- }
1284
- function mergeStyle(a, b) {
1285
- if (a == null) return b;
1286
- return { ...a, ...b };
1287
- }
1288
- function mergeFunction(a, b) {
1289
- if (typeof a === "function" && typeof b === "function") {
1290
- return (...args) => {
1291
- a(...args);
1292
- b(...args);
1293
- };
1294
- }
1295
- }
1296
- export {
1297
- ImpressionArea,
1298
- Separated,
1299
- SwitchCase,
1300
- buildContext,
1301
- mergeProps,
1302
- mergeRefs,
1303
- useAsyncEffect,
1304
- useBooleanState,
1305
- useCallbackOncePerRender,
1306
- useConditionalEffect,
1307
- useControlledState,
1308
- useCounter,
1309
- useDebounce,
1310
- useDebouncedCallback,
1311
- useDoubleClick,
1312
- useGeolocation,
1313
- useImpressionRef,
1314
- useInputState,
1315
- useIntersectionObserver,
1316
- useInterval,
1317
- useIsClient,
1318
- useIsomorphicLayoutEffect,
1319
- useList,
1320
- useLoading,
1321
- useLongPress,
1322
- useMap,
1323
- useOutsideClickEffect,
1324
- usePreservedCallback,
1325
- usePreservedReference,
1326
- usePrevious,
1327
- useRefEffect,
1328
- useSet,
1329
- useStorageState,
1330
- useThrottle,
1331
- useThrottledCallback,
1332
- useTimeout,
1333
- useToggle,
1334
- useVisibilityEvent
1335
- };