react-simplikit 0.0.50 → 0.0.52

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