@siberiacancode/reactuse 0.2.12 → 0.2.13

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 (412) hide show
  1. package/dist/cjs/helpers/createContext/createContext.cjs.map +1 -1
  2. package/dist/cjs/helpers/createReactiveContext/createReactiveContext.cjs.map +1 -1
  3. package/dist/cjs/helpers/createStore/createStore.cjs.map +1 -1
  4. package/dist/cjs/hooks/useActiveElement/useActiveElement.cjs +1 -1
  5. package/dist/cjs/hooks/useActiveElement/useActiveElement.cjs.map +1 -1
  6. package/dist/cjs/hooks/useAsync/useAsync.cjs.map +1 -1
  7. package/dist/cjs/hooks/useBattery/useBattery.cjs +1 -1
  8. package/dist/cjs/hooks/useBattery/useBattery.cjs.map +1 -1
  9. package/dist/cjs/hooks/useBluetooth/useBluetooth.cjs +1 -1
  10. package/dist/cjs/hooks/useBluetooth/useBluetooth.cjs.map +1 -1
  11. package/dist/cjs/hooks/useBoolean/useBoolean.cjs.map +1 -1
  12. package/dist/cjs/hooks/useBreakpoints/useBreakpoints.cjs.map +1 -1
  13. package/dist/cjs/hooks/useBrowserLanguage/useBrowserLanguage.cjs.map +1 -1
  14. package/dist/cjs/hooks/useClickOutside/useClickOutside.cjs.map +1 -1
  15. package/dist/cjs/hooks/useClipboard/useClipboard.cjs +1 -1
  16. package/dist/cjs/hooks/useClipboard/useClipboard.cjs.map +1 -1
  17. package/dist/cjs/hooks/useCookie/useCookie.cjs +1 -1
  18. package/dist/cjs/hooks/useCookie/useCookie.cjs.map +1 -1
  19. package/dist/cjs/hooks/useCookies/useCookies.cjs +1 -1
  20. package/dist/cjs/hooks/useCookies/useCookies.cjs.map +1 -1
  21. package/dist/cjs/hooks/useCopy/useCopy.cjs.map +1 -1
  22. package/dist/cjs/hooks/useCounter/useCounter.cjs +1 -1
  23. package/dist/cjs/hooks/useCounter/useCounter.cjs.map +1 -1
  24. package/dist/cjs/hooks/useCssVar/useCssVar.cjs +1 -1
  25. package/dist/cjs/hooks/useCssVar/useCssVar.cjs.map +1 -1
  26. package/dist/cjs/hooks/useDebounceCallback/useDebounceCallback.cjs.map +1 -1
  27. package/dist/cjs/hooks/useDebounceValue/useDebounceValue.cjs.map +1 -1
  28. package/dist/cjs/hooks/useDeviceMotion/useDeviceMotion.cjs +1 -1
  29. package/dist/cjs/hooks/useDeviceMotion/useDeviceMotion.cjs.map +1 -1
  30. package/dist/cjs/hooks/useDeviceOrientation/useDeviceOrientation.cjs.map +1 -1
  31. package/dist/cjs/hooks/useDevicePixelRatio/useDevicePixelRatio.cjs.map +1 -1
  32. package/dist/cjs/hooks/useDidUpdate/useDidUpdate.cjs.map +1 -1
  33. package/dist/cjs/hooks/useDisclosure/useDisclosure.cjs +1 -1
  34. package/dist/cjs/hooks/useDisclosure/useDisclosure.cjs.map +1 -1
  35. package/dist/cjs/hooks/useDisplayMedia/useDisplayMedia.cjs +1 -1
  36. package/dist/cjs/hooks/useDisplayMedia/useDisplayMedia.cjs.map +1 -1
  37. package/dist/cjs/hooks/useDocumentEvent/useDocumentEvent.cjs.map +1 -1
  38. package/dist/cjs/hooks/useDocumentTitle/useDocumentTitle.cjs +1 -1
  39. package/dist/cjs/hooks/useDocumentTitle/useDocumentTitle.cjs.map +1 -1
  40. package/dist/cjs/hooks/useDocumentVisibility/useDocumentVisibility.cjs.map +1 -1
  41. package/dist/cjs/hooks/useDoubleClick/useDoubleClick.cjs +1 -1
  42. package/dist/cjs/hooks/useDoubleClick/useDoubleClick.cjs.map +1 -1
  43. package/dist/cjs/hooks/useDropZone/useDropZone.cjs +1 -1
  44. package/dist/cjs/hooks/useDropZone/useDropZone.cjs.map +1 -1
  45. package/dist/cjs/hooks/useElementSize/useElementSize.cjs.map +1 -1
  46. package/dist/cjs/hooks/useEvent/useEvent.cjs.map +1 -1
  47. package/dist/cjs/hooks/useEventListener/useEventListener.cjs.map +1 -1
  48. package/dist/cjs/hooks/useEventSource/useEventSource.cjs +1 -1
  49. package/dist/cjs/hooks/useEventSource/useEventSource.cjs.map +1 -1
  50. package/dist/cjs/hooks/useEyeDropper/useEyeDropper.cjs.map +1 -1
  51. package/dist/cjs/hooks/useFavicon/useFavicon.cjs +1 -1
  52. package/dist/cjs/hooks/useFavicon/useFavicon.cjs.map +1 -1
  53. package/dist/cjs/hooks/useField/useField.cjs +1 -1
  54. package/dist/cjs/hooks/useField/useField.cjs.map +1 -1
  55. package/dist/cjs/hooks/useFileDialog/useFileDialog.cjs +1 -1
  56. package/dist/cjs/hooks/useFileDialog/useFileDialog.cjs.map +1 -1
  57. package/dist/cjs/hooks/useFocus/useFocus.cjs +1 -1
  58. package/dist/cjs/hooks/useFocus/useFocus.cjs.map +1 -1
  59. package/dist/cjs/hooks/useFps/useFps.cjs.map +1 -1
  60. package/dist/cjs/hooks/useFul/useFul.cjs.map +1 -1
  61. package/dist/cjs/hooks/useFullscreen/useFullscreen.cjs +1 -1
  62. package/dist/cjs/hooks/useFullscreen/useFullscreen.cjs.map +1 -1
  63. package/dist/cjs/hooks/useGamepad/useGamepad.cjs.map +1 -1
  64. package/dist/cjs/hooks/useGeolocation/useGeolocation.cjs +1 -1
  65. package/dist/cjs/hooks/useGeolocation/useGeolocation.cjs.map +1 -1
  66. package/dist/cjs/hooks/useHash/useHash.cjs.map +1 -1
  67. package/dist/cjs/hooks/useHotkeys/useHotkeys.cjs +1 -1
  68. package/dist/cjs/hooks/useHotkeys/useHotkeys.cjs.map +1 -1
  69. package/dist/cjs/hooks/useHover/useHover.cjs +1 -1
  70. package/dist/cjs/hooks/useHover/useHover.cjs.map +1 -1
  71. package/dist/cjs/hooks/useIdle/useIdle.cjs.map +1 -1
  72. package/dist/cjs/hooks/useImage/useImage.cjs.map +1 -1
  73. package/dist/cjs/hooks/useInfiniteScroll/useInfiniteScroll.cjs +1 -1
  74. package/dist/cjs/hooks/useInfiniteScroll/useInfiniteScroll.cjs.map +1 -1
  75. package/dist/cjs/hooks/useIntersectionObserver/useIntersectionObserver.cjs +1 -1
  76. package/dist/cjs/hooks/useIntersectionObserver/useIntersectionObserver.cjs.map +1 -1
  77. package/dist/cjs/hooks/useInterval/useInterval.cjs +1 -1
  78. package/dist/cjs/hooks/useInterval/useInterval.cjs.map +1 -1
  79. package/dist/cjs/hooks/useIsFirstRender/useIsFirstRender.cjs.map +1 -1
  80. package/dist/cjs/hooks/useKeyPress/useKeyPress.cjs +1 -1
  81. package/dist/cjs/hooks/useKeyPress/useKeyPress.cjs.map +1 -1
  82. package/dist/cjs/hooks/useKeyPressEvent/useKeyPressEvent.cjs +1 -1
  83. package/dist/cjs/hooks/useKeyPressEvent/useKeyPressEvent.cjs.map +1 -1
  84. package/dist/cjs/hooks/useKeyboard/useKeyboard.cjs +1 -1
  85. package/dist/cjs/hooks/useKeyboard/useKeyboard.cjs.map +1 -1
  86. package/dist/cjs/hooks/useKeysPressed/useKeysPressed.cjs +1 -1
  87. package/dist/cjs/hooks/useKeysPressed/useKeysPressed.cjs.map +1 -1
  88. package/dist/cjs/hooks/useLastChanged/useLastChanged.cjs +1 -1
  89. package/dist/cjs/hooks/useLastChanged/useLastChanged.cjs.map +1 -1
  90. package/dist/cjs/hooks/useLatest/useLatest.cjs +1 -1
  91. package/dist/cjs/hooks/useLatest/useLatest.cjs.map +1 -1
  92. package/dist/cjs/hooks/useLess/useLess.cjs.map +1 -1
  93. package/dist/cjs/hooks/useList/useList.cjs.map +1 -1
  94. package/dist/cjs/hooks/useLockCallback/useLockCallback.cjs.map +1 -1
  95. package/dist/cjs/hooks/useLogger/useLogger.cjs.map +1 -1
  96. package/dist/cjs/hooks/useLongPress/useLongPress.cjs +1 -1
  97. package/dist/cjs/hooks/useLongPress/useLongPress.cjs.map +1 -1
  98. package/dist/cjs/hooks/useMap/useMap.cjs.map +1 -1
  99. package/dist/cjs/hooks/useMeasure/useMeasure.cjs.map +1 -1
  100. package/dist/cjs/hooks/useMediaQuery/useMediaQuery.cjs.map +1 -1
  101. package/dist/cjs/hooks/useMemory/useMemory.cjs +1 -1
  102. package/dist/cjs/hooks/useMemory/useMemory.cjs.map +1 -1
  103. package/dist/cjs/hooks/useMount/useMount.cjs.map +1 -1
  104. package/dist/cjs/hooks/useMouse/useMouse.cjs.map +1 -1
  105. package/dist/cjs/hooks/useMutation/useMutation.cjs +1 -1
  106. package/dist/cjs/hooks/useMutation/useMutation.cjs.map +1 -1
  107. package/dist/cjs/hooks/useMutationObserver/useMutationObserver.cjs +1 -1
  108. package/dist/cjs/hooks/useMutationObserver/useMutationObserver.cjs.map +1 -1
  109. package/dist/cjs/hooks/useNetwork/useNetwork.cjs +1 -1
  110. package/dist/cjs/hooks/useNetwork/useNetwork.cjs.map +1 -1
  111. package/dist/cjs/hooks/useOffsetPagination/useOffsetPagination.cjs.map +1 -1
  112. package/dist/cjs/hooks/useOnce/useOnce.cjs.map +1 -1
  113. package/dist/cjs/hooks/useOnline/useOnline.cjs.map +1 -1
  114. package/dist/cjs/hooks/useOperatingSystem/useOperatingSystem.cjs.map +1 -1
  115. package/dist/cjs/hooks/useOptimistic/useOptimistic.cjs.map +1 -1
  116. package/dist/cjs/hooks/useOrientation/useOrientation.cjs.map +1 -1
  117. package/dist/cjs/hooks/useOtpCredential/useOtpCredential.cjs +1 -1
  118. package/dist/cjs/hooks/useOtpCredential/useOtpCredential.cjs.map +1 -1
  119. package/dist/cjs/hooks/usePageLeave/usePageLeave.cjs +1 -1
  120. package/dist/cjs/hooks/usePageLeave/usePageLeave.cjs.map +1 -1
  121. package/dist/cjs/hooks/usePaint/usePaint.cjs +1 -1
  122. package/dist/cjs/hooks/usePaint/usePaint.cjs.map +1 -1
  123. package/dist/cjs/hooks/useParallax/useParallax.cjs.map +1 -1
  124. package/dist/cjs/hooks/usePerformanceObserver/usePerformanceObserver.cjs +1 -1
  125. package/dist/cjs/hooks/usePerformanceObserver/usePerformanceObserver.cjs.map +1 -1
  126. package/dist/cjs/hooks/usePermission/usePermission.cjs +1 -1
  127. package/dist/cjs/hooks/usePermission/usePermission.cjs.map +1 -1
  128. package/dist/cjs/hooks/usePointerLock/usePointerLock.cjs.map +1 -1
  129. package/dist/cjs/hooks/usePostMessage/usePostMessage.cjs.map +1 -1
  130. package/dist/cjs/hooks/usePreferredColorScheme/usePreferredColorScheme.cjs.map +1 -1
  131. package/dist/cjs/hooks/usePreferredContrast/usePreferredContrast.cjs.map +1 -1
  132. package/dist/cjs/hooks/usePreferredLanguages/usePreferredLanguages.cjs.map +1 -1
  133. package/dist/cjs/hooks/usePreferredReducedMotion/usePreferredReducedMotion.cjs.map +1 -1
  134. package/dist/cjs/hooks/usePrevious/usePrevious.cjs +1 -1
  135. package/dist/cjs/hooks/usePrevious/usePrevious.cjs.map +1 -1
  136. package/dist/cjs/hooks/useQuery/useQuery.cjs +1 -1
  137. package/dist/cjs/hooks/useQuery/useQuery.cjs.map +1 -1
  138. package/dist/cjs/hooks/useQueue/useQueue.cjs.map +1 -1
  139. package/dist/cjs/hooks/useRaf/useRaf.cjs +1 -1
  140. package/dist/cjs/hooks/useRaf/useRaf.cjs.map +1 -1
  141. package/dist/cjs/hooks/useRafValue/useRafValue.cjs.map +1 -1
  142. package/dist/cjs/hooks/useRefState/useRefState.cjs.map +1 -1
  143. package/dist/cjs/hooks/useRenderCount/useRenderCount.cjs.map +1 -1
  144. package/dist/cjs/hooks/useRenderInfo/useRenderInfo.cjs.map +1 -1
  145. package/dist/cjs/hooks/useRerender/useRerender.cjs.map +1 -1
  146. package/dist/cjs/hooks/useResizeObserver/useResizeObserver.cjs +1 -1
  147. package/dist/cjs/hooks/useResizeObserver/useResizeObserver.cjs.map +1 -1
  148. package/dist/cjs/hooks/useScreenOrientation/useScreenOrientation.cjs +1 -1
  149. package/dist/cjs/hooks/useScreenOrientation/useScreenOrientation.cjs.map +1 -1
  150. package/dist/cjs/hooks/useScript/useScript.cjs +1 -1
  151. package/dist/cjs/hooks/useScript/useScript.cjs.map +1 -1
  152. package/dist/cjs/hooks/useScroll/useScroll.cjs +1 -1
  153. package/dist/cjs/hooks/useScroll/useScroll.cjs.map +1 -1
  154. package/dist/cjs/hooks/useScrollIntoView/useScrollIntoView.cjs.map +1 -1
  155. package/dist/cjs/hooks/useScrollTo/useScrollTo.cjs.map +1 -1
  156. package/dist/cjs/hooks/useSet/useSet.cjs.map +1 -1
  157. package/dist/cjs/hooks/useShare/useShare.cjs.map +1 -1
  158. package/dist/cjs/hooks/useSpeechRecognition/useSpeechRecognition.cjs +1 -1
  159. package/dist/cjs/hooks/useSpeechRecognition/useSpeechRecognition.cjs.map +1 -1
  160. package/dist/cjs/hooks/useSpeechSynthesis/useSpeechSynthesis.cjs +1 -1
  161. package/dist/cjs/hooks/useSpeechSynthesis/useSpeechSynthesis.cjs.map +1 -1
  162. package/dist/cjs/hooks/useStateHistory/useStateHistory.cjs.map +1 -1
  163. package/dist/cjs/hooks/useStep/useStep.cjs.map +1 -1
  164. package/dist/cjs/hooks/useSticky/useSticky.cjs +1 -1
  165. package/dist/cjs/hooks/useSticky/useSticky.cjs.map +1 -1
  166. package/dist/cjs/hooks/useStopwatch/useStopwatch.cjs +1 -1
  167. package/dist/cjs/hooks/useStopwatch/useStopwatch.cjs.map +1 -1
  168. package/dist/cjs/hooks/useStorage/useStorage.cjs +1 -1
  169. package/dist/cjs/hooks/useStorage/useStorage.cjs.map +1 -1
  170. package/dist/cjs/hooks/useTextDirection/useTextDirection.cjs +1 -1
  171. package/dist/cjs/hooks/useTextDirection/useTextDirection.cjs.map +1 -1
  172. package/dist/cjs/hooks/useTextSelection/useTextSelection.cjs +1 -1
  173. package/dist/cjs/hooks/useTextSelection/useTextSelection.cjs.map +1 -1
  174. package/dist/cjs/hooks/useThrottleCallback/useThrottleCallback.cjs.map +1 -1
  175. package/dist/cjs/hooks/useThrottleValue/useThrottleValue.cjs.map +1 -1
  176. package/dist/cjs/hooks/useTime/useTime.cjs.map +1 -1
  177. package/dist/cjs/hooks/useTimeout/useTimeout.cjs.map +1 -1
  178. package/dist/cjs/hooks/useTimer/useTimer.cjs +1 -1
  179. package/dist/cjs/hooks/useTimer/useTimer.cjs.map +1 -1
  180. package/dist/cjs/hooks/useToggle/useToggle.cjs.map +1 -1
  181. package/dist/cjs/hooks/useUnmount/useUnmount.cjs.map +1 -1
  182. package/dist/cjs/hooks/useUrlSearchParam/useUrlSearchParam.cjs +1 -1
  183. package/dist/cjs/hooks/useUrlSearchParam/useUrlSearchParam.cjs.map +1 -1
  184. package/dist/cjs/hooks/useUrlSearchParams/useUrlSearchParams.cjs +1 -1
  185. package/dist/cjs/hooks/useUrlSearchParams/useUrlSearchParams.cjs.map +1 -1
  186. package/dist/cjs/hooks/useVibrate/useVibrate.cjs.map +1 -1
  187. package/dist/cjs/hooks/useWakeLock/useWakeLock.cjs +1 -1
  188. package/dist/cjs/hooks/useWakeLock/useWakeLock.cjs.map +1 -1
  189. package/dist/cjs/hooks/useWebSocket/useWebSocket.cjs +1 -1
  190. package/dist/cjs/hooks/useWebSocket/useWebSocket.cjs.map +1 -1
  191. package/dist/cjs/hooks/useWindowEvent/useWindowEvent.cjs.map +1 -1
  192. package/dist/cjs/hooks/useWindowFocus/useWindowFocus.cjs.map +1 -1
  193. package/dist/cjs/hooks/useWindowScroll/useWindowScroll.cjs.map +1 -1
  194. package/dist/cjs/hooks/useWindowSize/useWindowSize.cjs +1 -1
  195. package/dist/cjs/hooks/useWindowSize/useWindowSize.cjs.map +1 -1
  196. package/dist/cjs/hooks/useWizard/useWizard.cjs +1 -1
  197. package/dist/cjs/hooks/useWizard/useWizard.cjs.map +1 -1
  198. package/dist/cjs/utils/helpers/copy.cjs.map +1 -1
  199. package/dist/cjs/utils/helpers/debounce.cjs.map +1 -1
  200. package/dist/cjs/utils/helpers/getDate.cjs.map +1 -1
  201. package/dist/cjs/utils/helpers/getElement.cjs.map +1 -1
  202. package/dist/cjs/utils/helpers/getRetry.cjs.map +1 -1
  203. package/dist/cjs/utils/helpers/isTarget.cjs.map +1 -1
  204. package/dist/cjs/utils/helpers/throttle.cjs.map +1 -1
  205. package/dist/esm/helpers/createContext/createContext.mjs.map +1 -1
  206. package/dist/esm/helpers/createReactiveContext/createReactiveContext.mjs.map +1 -1
  207. package/dist/esm/helpers/createStore/createStore.mjs.map +1 -1
  208. package/dist/esm/hooks/useActiveElement/useActiveElement.mjs +1 -1
  209. package/dist/esm/hooks/useActiveElement/useActiveElement.mjs.map +1 -1
  210. package/dist/esm/hooks/useAsync/useAsync.mjs.map +1 -1
  211. package/dist/esm/hooks/useBattery/useBattery.mjs +10 -10
  212. package/dist/esm/hooks/useBattery/useBattery.mjs.map +1 -1
  213. package/dist/esm/hooks/useBluetooth/useBluetooth.mjs +14 -15
  214. package/dist/esm/hooks/useBluetooth/useBluetooth.mjs.map +1 -1
  215. package/dist/esm/hooks/useBoolean/useBoolean.mjs.map +1 -1
  216. package/dist/esm/hooks/useBreakpoints/useBreakpoints.mjs.map +1 -1
  217. package/dist/esm/hooks/useBrowserLanguage/useBrowserLanguage.mjs.map +1 -1
  218. package/dist/esm/hooks/useClickOutside/useClickOutside.mjs.map +1 -1
  219. package/dist/esm/hooks/useClipboard/useClipboard.mjs +13 -14
  220. package/dist/esm/hooks/useClipboard/useClipboard.mjs.map +1 -1
  221. package/dist/esm/hooks/useConst/useConst.mjs.map +1 -1
  222. package/dist/esm/hooks/useCookie/useCookie.mjs +27 -27
  223. package/dist/esm/hooks/useCookie/useCookie.mjs.map +1 -1
  224. package/dist/esm/hooks/useCookies/useCookies.mjs +19 -19
  225. package/dist/esm/hooks/useCookies/useCookies.mjs.map +1 -1
  226. package/dist/esm/hooks/useCopy/useCopy.mjs.map +1 -1
  227. package/dist/esm/hooks/useCounter/useCounter.mjs +5 -6
  228. package/dist/esm/hooks/useCounter/useCounter.mjs.map +1 -1
  229. package/dist/esm/hooks/useCssVar/useCssVar.mjs +13 -14
  230. package/dist/esm/hooks/useCssVar/useCssVar.mjs.map +1 -1
  231. package/dist/esm/hooks/useDebounceCallback/useDebounceCallback.mjs.map +1 -1
  232. package/dist/esm/hooks/useDebounceValue/useDebounceValue.mjs.map +1 -1
  233. package/dist/esm/hooks/useDefault/useDefault.mjs.map +1 -1
  234. package/dist/esm/hooks/useDeviceMotion/useDeviceMotion.mjs +18 -19
  235. package/dist/esm/hooks/useDeviceMotion/useDeviceMotion.mjs.map +1 -1
  236. package/dist/esm/hooks/useDeviceOrientation/useDeviceOrientation.mjs.map +1 -1
  237. package/dist/esm/hooks/useDevicePixelRatio/useDevicePixelRatio.mjs.map +1 -1
  238. package/dist/esm/hooks/useDidUpdate/useDidUpdate.mjs.map +1 -1
  239. package/dist/esm/hooks/useDisclosure/useDisclosure.mjs +5 -11
  240. package/dist/esm/hooks/useDisclosure/useDisclosure.mjs.map +1 -1
  241. package/dist/esm/hooks/useDisplayMedia/useDisplayMedia.mjs +28 -28
  242. package/dist/esm/hooks/useDisplayMedia/useDisplayMedia.mjs.map +1 -1
  243. package/dist/esm/hooks/useDocumentEvent/useDocumentEvent.mjs.map +1 -1
  244. package/dist/esm/hooks/useDocumentTitle/useDocumentTitle.mjs +15 -15
  245. package/dist/esm/hooks/useDocumentTitle/useDocumentTitle.mjs.map +1 -1
  246. package/dist/esm/hooks/useDocumentVisibility/useDocumentVisibility.mjs.map +1 -1
  247. package/dist/esm/hooks/useDoubleClick/useDoubleClick.mjs +11 -13
  248. package/dist/esm/hooks/useDoubleClick/useDoubleClick.mjs.map +1 -1
  249. package/dist/esm/hooks/useDropZone/useDropZone.mjs +27 -28
  250. package/dist/esm/hooks/useDropZone/useDropZone.mjs.map +1 -1
  251. package/dist/esm/hooks/useElementSize/useElementSize.mjs.map +1 -1
  252. package/dist/esm/hooks/useEvent/useEvent.mjs.map +1 -1
  253. package/dist/esm/hooks/useEventListener/useEventListener.mjs.map +1 -1
  254. package/dist/esm/hooks/useEventSource/useEventSource.mjs +37 -40
  255. package/dist/esm/hooks/useEventSource/useEventSource.mjs.map +1 -1
  256. package/dist/esm/hooks/useEyeDropper/useEyeDropper.mjs.map +1 -1
  257. package/dist/esm/hooks/useFavicon/useFavicon.mjs +11 -12
  258. package/dist/esm/hooks/useFavicon/useFavicon.mjs.map +1 -1
  259. package/dist/esm/hooks/useField/useField.mjs +45 -49
  260. package/dist/esm/hooks/useField/useField.mjs.map +1 -1
  261. package/dist/esm/hooks/useFileDialog/useFileDialog.mjs +22 -25
  262. package/dist/esm/hooks/useFileDialog/useFileDialog.mjs.map +1 -1
  263. package/dist/esm/hooks/useFocus/useFocus.mjs +24 -32
  264. package/dist/esm/hooks/useFocus/useFocus.mjs.map +1 -1
  265. package/dist/esm/hooks/useFps/useFps.mjs.map +1 -1
  266. package/dist/esm/hooks/useFul/useFul.mjs.map +1 -1
  267. package/dist/esm/hooks/useFullscreen/useFullscreen.mjs +23 -24
  268. package/dist/esm/hooks/useFullscreen/useFullscreen.mjs.map +1 -1
  269. package/dist/esm/hooks/useGamepad/useGamepad.mjs.map +1 -1
  270. package/dist/esm/hooks/useGeolocation/useGeolocation.mjs +24 -24
  271. package/dist/esm/hooks/useGeolocation/useGeolocation.mjs.map +1 -1
  272. package/dist/esm/hooks/useHash/useHash.mjs.map +1 -1
  273. package/dist/esm/hooks/useHotkeys/useHotkeys.mjs +24 -25
  274. package/dist/esm/hooks/useHotkeys/useHotkeys.mjs.map +1 -1
  275. package/dist/esm/hooks/useHover/useHover.mjs +20 -22
  276. package/dist/esm/hooks/useHover/useHover.mjs.map +1 -1
  277. package/dist/esm/hooks/useIdle/useIdle.mjs.map +1 -1
  278. package/dist/esm/hooks/useImage/useImage.mjs.map +1 -1
  279. package/dist/esm/hooks/useInfiniteScroll/useInfiniteScroll.mjs +14 -14
  280. package/dist/esm/hooks/useInfiniteScroll/useInfiniteScroll.mjs.map +1 -1
  281. package/dist/esm/hooks/useIntersectionObserver/useIntersectionObserver.mjs +19 -20
  282. package/dist/esm/hooks/useIntersectionObserver/useIntersectionObserver.mjs.map +1 -1
  283. package/dist/esm/hooks/useInterval/useInterval.mjs +8 -8
  284. package/dist/esm/hooks/useInterval/useInterval.mjs.map +1 -1
  285. package/dist/esm/hooks/useIsFirstRender/useIsFirstRender.mjs.map +1 -1
  286. package/dist/esm/hooks/useKeyPress/useKeyPress.mjs +22 -24
  287. package/dist/esm/hooks/useKeyPress/useKeyPress.mjs.map +1 -1
  288. package/dist/esm/hooks/useKeyPressEvent/useKeyPressEvent.mjs +23 -23
  289. package/dist/esm/hooks/useKeyPressEvent/useKeyPressEvent.mjs.map +1 -1
  290. package/dist/esm/hooks/useKeyboard/useKeyboard.mjs +16 -22
  291. package/dist/esm/hooks/useKeyboard/useKeyboard.mjs.map +1 -1
  292. package/dist/esm/hooks/useKeysPressed/useKeysPressed.mjs +20 -20
  293. package/dist/esm/hooks/useKeysPressed/useKeysPressed.mjs.map +1 -1
  294. package/dist/esm/hooks/useLastChanged/useLastChanged.mjs +6 -6
  295. package/dist/esm/hooks/useLastChanged/useLastChanged.mjs.map +1 -1
  296. package/dist/esm/hooks/useLatest/useLatest.mjs +12 -4
  297. package/dist/esm/hooks/useLatest/useLatest.mjs.map +1 -1
  298. package/dist/esm/hooks/useLess/useLess.mjs.map +1 -1
  299. package/dist/esm/hooks/useList/useList.mjs.map +1 -1
  300. package/dist/esm/hooks/useLockCallback/useLockCallback.mjs.map +1 -1
  301. package/dist/esm/hooks/useLogger/useLogger.mjs.map +1 -1
  302. package/dist/esm/hooks/useLongPress/useLongPress.mjs +23 -27
  303. package/dist/esm/hooks/useLongPress/useLongPress.mjs.map +1 -1
  304. package/dist/esm/hooks/useMap/useMap.mjs.map +1 -1
  305. package/dist/esm/hooks/useMeasure/useMeasure.mjs.map +1 -1
  306. package/dist/esm/hooks/useMediaQuery/useMediaQuery.mjs.map +1 -1
  307. package/dist/esm/hooks/useMemory/useMemory.mjs +1 -1
  308. package/dist/esm/hooks/useMemory/useMemory.mjs.map +1 -1
  309. package/dist/esm/hooks/useMount/useMount.mjs.map +1 -1
  310. package/dist/esm/hooks/useMouse/useMouse.mjs.map +1 -1
  311. package/dist/esm/hooks/useMutation/useMutation.mjs +38 -42
  312. package/dist/esm/hooks/useMutation/useMutation.mjs.map +1 -1
  313. package/dist/esm/hooks/useMutationObserver/useMutationObserver.mjs +12 -12
  314. package/dist/esm/hooks/useMutationObserver/useMutationObserver.mjs.map +1 -1
  315. package/dist/esm/hooks/useNetwork/useNetwork.mjs +28 -28
  316. package/dist/esm/hooks/useNetwork/useNetwork.mjs.map +1 -1
  317. package/dist/esm/hooks/useOffsetPagination/useOffsetPagination.mjs.map +1 -1
  318. package/dist/esm/hooks/useOnce/useOnce.mjs.map +1 -1
  319. package/dist/esm/hooks/useOnline/useOnline.mjs.map +1 -1
  320. package/dist/esm/hooks/useOperatingSystem/useOperatingSystem.mjs.map +1 -1
  321. package/dist/esm/hooks/useOptimistic/useOptimistic.mjs.map +1 -1
  322. package/dist/esm/hooks/useOrientation/useOrientation.mjs.map +1 -1
  323. package/dist/esm/hooks/useOtpCredential/useOtpCredential.mjs +12 -13
  324. package/dist/esm/hooks/useOtpCredential/useOtpCredential.mjs.map +1 -1
  325. package/dist/esm/hooks/usePageLeave/usePageLeave.mjs +6 -6
  326. package/dist/esm/hooks/usePageLeave/usePageLeave.mjs.map +1 -1
  327. package/dist/esm/hooks/usePaint/usePaint.mjs +87 -93
  328. package/dist/esm/hooks/usePaint/usePaint.mjs.map +1 -1
  329. package/dist/esm/hooks/useParallax/useParallax.mjs.map +1 -1
  330. package/dist/esm/hooks/usePerformanceObserver/usePerformanceObserver.mjs +17 -19
  331. package/dist/esm/hooks/usePerformanceObserver/usePerformanceObserver.mjs.map +1 -1
  332. package/dist/esm/hooks/usePermission/usePermission.mjs +13 -13
  333. package/dist/esm/hooks/usePermission/usePermission.mjs.map +1 -1
  334. package/dist/esm/hooks/usePointerLock/usePointerLock.mjs.map +1 -1
  335. package/dist/esm/hooks/usePostMessage/usePostMessage.mjs.map +1 -1
  336. package/dist/esm/hooks/usePreferredColorScheme/usePreferredColorScheme.mjs.map +1 -1
  337. package/dist/esm/hooks/usePreferredContrast/usePreferredContrast.mjs.map +1 -1
  338. package/dist/esm/hooks/usePreferredDark/usePreferredDark.mjs.map +1 -1
  339. package/dist/esm/hooks/usePreferredLanguages/usePreferredLanguages.mjs.map +1 -1
  340. package/dist/esm/hooks/usePrevious/usePrevious.mjs +4 -4
  341. package/dist/esm/hooks/usePrevious/usePrevious.mjs.map +1 -1
  342. package/dist/esm/hooks/useQuery/useQuery.mjs +39 -41
  343. package/dist/esm/hooks/useQuery/useQuery.mjs.map +1 -1
  344. package/dist/esm/hooks/useQueue/useQueue.mjs.map +1 -1
  345. package/dist/esm/hooks/useRaf/useRaf.mjs +21 -21
  346. package/dist/esm/hooks/useRaf/useRaf.mjs.map +1 -1
  347. package/dist/esm/hooks/useRafValue/useRafValue.mjs.map +1 -1
  348. package/dist/esm/hooks/useRefState/useRefState.mjs.map +1 -1
  349. package/dist/esm/hooks/useRenderCount/useRenderCount.mjs.map +1 -1
  350. package/dist/esm/hooks/useRenderInfo/useRenderInfo.mjs.map +1 -1
  351. package/dist/esm/hooks/useRerender/useRerender.mjs.map +1 -1
  352. package/dist/esm/hooks/useResizeObserver/useResizeObserver.mjs +16 -17
  353. package/dist/esm/hooks/useResizeObserver/useResizeObserver.mjs.map +1 -1
  354. package/dist/esm/hooks/useScreenOrientation/useScreenOrientation.mjs +11 -11
  355. package/dist/esm/hooks/useScreenOrientation/useScreenOrientation.mjs.map +1 -1
  356. package/dist/esm/hooks/useScript/useScript.mjs +16 -16
  357. package/dist/esm/hooks/useScript/useScript.mjs.map +1 -1
  358. package/dist/esm/hooks/useScroll/useScroll.mjs +37 -39
  359. package/dist/esm/hooks/useScroll/useScroll.mjs.map +1 -1
  360. package/dist/esm/hooks/useScrollIntoView/useScrollIntoView.mjs.map +1 -1
  361. package/dist/esm/hooks/useScrollTo/useScrollTo.mjs.map +1 -1
  362. package/dist/esm/hooks/useSet/useSet.mjs.map +1 -1
  363. package/dist/esm/hooks/useShare/useShare.mjs.map +1 -1
  364. package/dist/esm/hooks/useSpeechRecognition/useSpeechRecognition.mjs +35 -35
  365. package/dist/esm/hooks/useSpeechRecognition/useSpeechRecognition.mjs.map +1 -1
  366. package/dist/esm/hooks/useSpeechSynthesis/useSpeechSynthesis.mjs +36 -42
  367. package/dist/esm/hooks/useSpeechSynthesis/useSpeechSynthesis.mjs.map +1 -1
  368. package/dist/esm/hooks/useStateHistory/useStateHistory.mjs.map +1 -1
  369. package/dist/esm/hooks/useStep/useStep.mjs.map +1 -1
  370. package/dist/esm/hooks/useSticky/useSticky.mjs +12 -12
  371. package/dist/esm/hooks/useSticky/useSticky.mjs.map +1 -1
  372. package/dist/esm/hooks/useStopwatch/useStopwatch.mjs +10 -11
  373. package/dist/esm/hooks/useStopwatch/useStopwatch.mjs.map +1 -1
  374. package/dist/esm/hooks/useStorage/useStorage.mjs +27 -27
  375. package/dist/esm/hooks/useStorage/useStorage.mjs.map +1 -1
  376. package/dist/esm/hooks/useTextDirection/useTextDirection.mjs +21 -24
  377. package/dist/esm/hooks/useTextDirection/useTextDirection.mjs.map +1 -1
  378. package/dist/esm/hooks/useTextSelection/useTextSelection.mjs +7 -7
  379. package/dist/esm/hooks/useTextSelection/useTextSelection.mjs.map +1 -1
  380. package/dist/esm/hooks/useThrottleCallback/useThrottleCallback.mjs.map +1 -1
  381. package/dist/esm/hooks/useThrottleValue/useThrottleValue.mjs.map +1 -1
  382. package/dist/esm/hooks/useTime/useTime.mjs.map +1 -1
  383. package/dist/esm/hooks/useTimeout/useTimeout.mjs.map +1 -1
  384. package/dist/esm/hooks/useTimer/useTimer.mjs +51 -54
  385. package/dist/esm/hooks/useTimer/useTimer.mjs.map +1 -1
  386. package/dist/esm/hooks/useToggle/useToggle.mjs.map +1 -1
  387. package/dist/esm/hooks/useUnmount/useUnmount.mjs.map +1 -1
  388. package/dist/esm/hooks/useUrlSearchParam/useUrlSearchParam.mjs +38 -38
  389. package/dist/esm/hooks/useUrlSearchParam/useUrlSearchParam.mjs.map +1 -1
  390. package/dist/esm/hooks/useUrlSearchParams/useUrlSearchParams.mjs +29 -29
  391. package/dist/esm/hooks/useUrlSearchParams/useUrlSearchParams.mjs.map +1 -1
  392. package/dist/esm/hooks/useVibrate/useVibrate.mjs.map +1 -1
  393. package/dist/esm/hooks/useWakeLock/useWakeLock.mjs +16 -16
  394. package/dist/esm/hooks/useWakeLock/useWakeLock.mjs.map +1 -1
  395. package/dist/esm/hooks/useWebSocket/useWebSocket.mjs +28 -38
  396. package/dist/esm/hooks/useWebSocket/useWebSocket.mjs.map +1 -1
  397. package/dist/esm/hooks/useWindowEvent/useWindowEvent.mjs.map +1 -1
  398. package/dist/esm/hooks/useWindowFocus/useWindowFocus.mjs.map +1 -1
  399. package/dist/esm/hooks/useWindowScroll/useWindowScroll.mjs.map +1 -1
  400. package/dist/esm/hooks/useWindowSize/useWindowSize.mjs +9 -9
  401. package/dist/esm/hooks/useWindowSize/useWindowSize.mjs.map +1 -1
  402. package/dist/esm/hooks/useWizard/useWizard.mjs +9 -11
  403. package/dist/esm/hooks/useWizard/useWizard.mjs.map +1 -1
  404. package/dist/esm/utils/helpers/copy.mjs.map +1 -1
  405. package/dist/esm/utils/helpers/debounce.mjs.map +1 -1
  406. package/dist/esm/utils/helpers/getDate.mjs.map +1 -1
  407. package/dist/esm/utils/helpers/getElement.mjs.map +1 -1
  408. package/dist/esm/utils/helpers/getRetry.mjs.map +1 -1
  409. package/dist/esm/utils/helpers/isTarget.mjs.map +1 -1
  410. package/dist/esm/utils/helpers/throttle.mjs.map +1 -1
  411. package/dist/types/hooks/useLatest/useLatest.d.ts +7 -2
  412. package/package.json +5 -5
@@ -1 +1 @@
1
- {"version":3,"file":"useMap.mjs","sources":["../../../../src/hooks/useMap/useMap.ts"],"sourcesContent":["import { useState } from 'react';\n\n/** The use map return type */\nexport interface UseMapReturn<Key, Value> {\n /** The size of the map */\n size: number;\n /** The current map */\n value: Map<Key, Value>;\n /** Function to clear the map */\n clear: () => void;\n /** Function to check if a value exists in the map */\n has: (key: Key) => boolean;\n /** Function to remove a value from the map */\n remove: (key: Key) => void;\n /** Function to toggle a value in the map */\n reset: () => void;\n /** Function to add a value to the map */\n set: (key: Key, value: Value) => void;\n}\n\n/**\n * @name useMap\n * @description - Hook that manages a map structure\n * @category Utilities\n *\n * @template Value The type of the value\n * @param {Value[]} [values] The initial array of the map\n * @returns {UseMapReturn<Key, Value>} An object containing the current map and functions to interact with the map\n *\n * @example\n * const { value, set, remove, clear, reset, size, has } = useMap([1, 'one'], [2, 'two']);\n */\nexport const useMap = <Key, Value>(values?: [Key, Value][]): UseMapReturn<Key, Value> => {\n const [map, setMap] = useState(new Map(values));\n\n const set = (key: Key, value: Value) => setMap((prevMap) => new Map(prevMap).set(key, value));\n const remove = (key: Key) =>\n setMap((prevMap) => {\n if (!prevMap.has(key)) return prevMap;\n const newMap = new Map(prevMap);\n newMap.delete(key);\n return newMap;\n });\n const clear = () => setMap(new Map());\n const reset = () => setMap(new Map(values));\n const has = (key: Key) => map.has(key);\n\n return {\n value: map,\n size: map.size,\n set,\n has,\n remove,\n clear,\n reset\n };\n};\n"],"names":["useMap","values","map","setMap","useState","set","key","value","prevMap","remove","newMap","clear","reset","has"],"mappings":";AAgCa,MAAAA,IAAS,CAAaC,MAAsD;AACjF,QAAA,CAACC,GAAKC,CAAM,IAAIC,EAAS,IAAI,IAAIH,CAAM,CAAC,GAExCI,IAAM,CAACC,GAAUC,MAAiBJ,EAAO,CAACK,MAAY,IAAI,IAAIA,CAAO,EAAE,IAAIF,GAAKC,CAAK,CAAC,GACtFE,IAAS,CAACH,MACdH,EAAO,CAACK,MAAY;AAClB,QAAI,CAACA,EAAQ,IAAIF,CAAG,EAAU,QAAAE;AACxB,UAAAE,IAAS,IAAI,IAAIF,CAAO;AAC9B,WAAAE,EAAO,OAAOJ,CAAG,GACVI;AAAA,EAAA,CACR,GACGC,IAAQ,MAAMR,EAAO,oBAAI,KAAK,GAC9BS,IAAQ,MAAMT,EAAO,IAAI,IAAIF,CAAM,CAAC,GACpCY,IAAM,CAACP,MAAaJ,EAAI,IAAII,CAAG;AAE9B,SAAA;AAAA,IACL,OAAOJ;AAAA,IACP,MAAMA,EAAI;AAAA,IACV,KAAAG;AAAA,IACA,KAAAQ;AAAA,IACA,QAAAJ;AAAA,IACA,OAAAE;AAAA,IACA,OAAAC;AAAA,EACF;AACF;"}
1
+ {"version":3,"file":"useMap.mjs","sources":["../../../../src/hooks/useMap/useMap.ts"],"sourcesContent":["import { useState } from 'react';\n\n/** The use map return type */\nexport interface UseMapReturn<Key, Value> {\n /** The size of the map */\n size: number;\n /** The current map */\n value: Map<Key, Value>;\n /** Function to clear the map */\n clear: () => void;\n /** Function to check if a value exists in the map */\n has: (key: Key) => boolean;\n /** Function to remove a value from the map */\n remove: (key: Key) => void;\n /** Function to toggle a value in the map */\n reset: () => void;\n /** Function to add a value to the map */\n set: (key: Key, value: Value) => void;\n}\n\n/**\n * @name useMap\n * @description - Hook that manages a map structure\n * @category Utilities\n *\n * @template Value The type of the value\n * @param {Value[]} [values] The initial array of the map\n * @returns {UseMapReturn<Key, Value>} An object containing the current map and functions to interact with the map\n *\n * @example\n * const { value, set, remove, clear, reset, size, has } = useMap([1, 'one'], [2, 'two']);\n */\nexport const useMap = <Key, Value>(values?: [Key, Value][]): UseMapReturn<Key, Value> => {\n const [map, setMap] = useState(new Map(values));\n\n const set = (key: Key, value: Value) => setMap((prevMap) => new Map(prevMap).set(key, value));\n const remove = (key: Key) =>\n setMap((prevMap) => {\n if (!prevMap.has(key)) return prevMap;\n const newMap = new Map(prevMap);\n newMap.delete(key);\n return newMap;\n });\n const clear = () => setMap(new Map());\n const reset = () => setMap(new Map(values));\n const has = (key: Key) => map.has(key);\n\n return {\n value: map,\n size: map.size,\n set,\n has,\n remove,\n clear,\n reset\n };\n};\n"],"names":["useMap","values","map","setMap","useState","set","key","value","prevMap","remove","newMap","clear","reset","has"],"mappings":";AAgCO,MAAMA,IAAS,CAAaC,MAAsD;AACvF,QAAM,CAACC,GAAKC,CAAM,IAAIC,EAAS,IAAI,IAAIH,CAAM,CAAC,GAExCI,IAAM,CAACC,GAAUC,MAAiBJ,EAAO,CAACK,MAAY,IAAI,IAAIA,CAAO,EAAE,IAAIF,GAAKC,CAAK,CAAC,GACtFE,IAAS,CAACH,MACdH,EAAO,CAACK,MAAY;AAClB,QAAI,CAACA,EAAQ,IAAIF,CAAG,EAAG,QAAOE;AAC9B,UAAME,IAAS,IAAI,IAAIF,CAAO;AAC9B,WAAAE,EAAO,OAAOJ,CAAG,GACVI;AAAA,EAAA,CACR,GACGC,IAAQ,MAAMR,EAAO,oBAAI,KAAK,GAC9BS,IAAQ,MAAMT,EAAO,IAAI,IAAIF,CAAM,CAAC,GACpCY,IAAM,CAACP,MAAaJ,EAAI,IAAII,CAAG;AAErC,SAAO;AAAA,IACL,OAAOJ;AAAA,IACP,MAAMA,EAAI;AAAA,IACV,KAAAG;AAAA,IACA,KAAAQ;AAAA,IACA,QAAAJ;AAAA,IACA,OAAAE;AAAA,IACA,OAAAC;AAAA,EAAA;AAEJ;"}
@@ -1 +1 @@
1
- {"version":3,"file":"useMeasure.mjs","sources":["../../../../src/hooks/useMeasure/useMeasure.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\nimport type { HookTarget } from '@/utils/helpers';\n\nimport { getElement, isTarget } from '@/utils/helpers';\n\nimport type { StateRef } from '../useRefState/useRefState';\n\nimport { useRefState } from '../useRefState/useRefState';\n\n/** The use measure return type */\nexport type UseMeasureReturn = Pick<\n DOMRectReadOnly,\n 'bottom' | 'height' | 'left' | 'right' | 'top' | 'width' | 'x' | 'y'\n>;\n\nexport interface UseMeasure {\n (target: HookTarget): UseMeasureReturn;\n\n <Target extends Element>(\n target?: never\n ): UseMeasureReturn & {\n ref: StateRef<Target>;\n };\n}\n\n/**\n * @name useMeasure\n * @description - Hook to measure the size and position of an element\n * @category Browser\n *\n * @overload\n * @param {HookTarget} target The element to measure\n * @returns {UseMeasureReturn} The element's size and position\n *\n * @example\n * const { x, y, width, height, top, left, bottom, right } = useMeasure(ref);\n *\n * @overload\n * @template Target The element to measure\n * @returns {UseMeasureReturn & { ref: StateRef<Target> }} The element's size and position\n *\n * @example\n * const { ref, x, y, width, height, top, left, bottom, right } = useMeasure();\n */\nexport const useMeasure = ((...params: any[]) => {\n const target = (isTarget(params[0]) ? params[0] : undefined) as HookTarget | undefined;\n\n const internalRef = useRefState<Element>();\n const [rect, setRect] = useState({\n x: 0,\n y: 0,\n width: 0,\n height: 0,\n top: 0,\n left: 0,\n bottom: 0,\n right: 0\n });\n\n useEffect(() => {\n if (!target && !internalRef.state) return;\n\n const element = (target ? getElement(target) : internalRef.current) as Element;\n if (!element) return;\n\n const resizeObserver = new ResizeObserver((entries) => {\n const entry = entries[0];\n if (!entry) return;\n\n const { x, y, width, height, top, left, bottom, right } = entry.contentRect;\n setRect({ x, y, width, height, top, left, bottom, right });\n });\n\n resizeObserver.observe(element);\n\n return () => {\n resizeObserver.disconnect();\n };\n }, [target, internalRef.state]);\n\n if (target) return rect;\n return { ref: internalRef, ...rect };\n}) as UseMeasure;\n"],"names":["useMeasure","params","target","isTarget","internalRef","useRefState","rect","setRect","useState","useEffect","element","getElement","resizeObserver","entries","entry","x","y","width","height","top","left","bottom","right"],"mappings":";;;;AA6Ca,MAAAA,IAAc,IAAIC,MAAkB;AACzC,QAAAC,IAAUC,EAASF,EAAO,CAAC,CAAC,IAAIA,EAAO,CAAC,IAAI,QAE5CG,IAAcC,EAAqB,GACnC,CAACC,GAAMC,CAAO,IAAIC,EAAS;AAAA,IAC/B,GAAG;AAAA,IACH,GAAG;AAAA,IACH,OAAO;AAAA,IACP,QAAQ;AAAA,IACR,KAAK;AAAA,IACL,MAAM;AAAA,IACN,QAAQ;AAAA,IACR,OAAO;AAAA,EAAA,CACR;AAuBD,SArBAC,EAAU,MAAM;AACd,QAAI,CAACP,KAAU,CAACE,EAAY,MAAO;AAEnC,UAAMM,IAAWR,IAASS,EAAWT,CAAM,IAAIE,EAAY;AAC3D,QAAI,CAACM,EAAS;AAEd,UAAME,IAAiB,IAAI,eAAe,CAACC,MAAY;AAC/C,YAAAC,IAAQD,EAAQ,CAAC;AACvB,UAAI,CAACC,EAAO;AAEN,YAAA,EAAE,GAAAC,GAAG,GAAAC,GAAG,OAAAC,GAAO,QAAAC,GAAQ,KAAAC,GAAK,MAAAC,GAAM,QAAAC,GAAQ,OAAAC,EAAM,IAAIR,EAAM;AACxD,MAAAP,EAAA,EAAE,GAAAQ,GAAG,GAAAC,GAAG,OAAAC,GAAO,QAAAC,GAAQ,KAAAC,GAAK,MAAAC,GAAM,QAAAC,GAAQ,OAAAC,GAAO;AAAA,IAAA,CAC1D;AAED,WAAAV,EAAe,QAAQF,CAAO,GAEvB,MAAM;AACX,MAAAE,EAAe,WAAW;AAAA,IAC5B;AAAA,EACC,GAAA,CAACV,GAAQE,EAAY,KAAK,CAAC,GAE1BF,IAAeI,IACZ,EAAE,KAAKF,GAAa,GAAGE,EAAK;AACrC;"}
1
+ {"version":3,"file":"useMeasure.mjs","sources":["../../../../src/hooks/useMeasure/useMeasure.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\nimport type { HookTarget } from '@/utils/helpers';\n\nimport { getElement, isTarget } from '@/utils/helpers';\n\nimport type { StateRef } from '../useRefState/useRefState';\n\nimport { useRefState } from '../useRefState/useRefState';\n\n/** The use measure return type */\nexport type UseMeasureReturn = Pick<\n DOMRectReadOnly,\n 'bottom' | 'height' | 'left' | 'right' | 'top' | 'width' | 'x' | 'y'\n>;\n\nexport interface UseMeasure {\n (target: HookTarget): UseMeasureReturn;\n\n <Target extends Element>(\n target?: never\n ): UseMeasureReturn & {\n ref: StateRef<Target>;\n };\n}\n\n/**\n * @name useMeasure\n * @description - Hook to measure the size and position of an element\n * @category Browser\n *\n * @overload\n * @param {HookTarget} target The element to measure\n * @returns {UseMeasureReturn} The element's size and position\n *\n * @example\n * const { x, y, width, height, top, left, bottom, right } = useMeasure(ref);\n *\n * @overload\n * @template Target The element to measure\n * @returns {UseMeasureReturn & { ref: StateRef<Target> }} The element's size and position\n *\n * @example\n * const { ref, x, y, width, height, top, left, bottom, right } = useMeasure();\n */\nexport const useMeasure = ((...params: any[]) => {\n const target = (isTarget(params[0]) ? params[0] : undefined) as HookTarget | undefined;\n\n const internalRef = useRefState<Element>();\n const [rect, setRect] = useState({\n x: 0,\n y: 0,\n width: 0,\n height: 0,\n top: 0,\n left: 0,\n bottom: 0,\n right: 0\n });\n\n useEffect(() => {\n if (!target && !internalRef.state) return;\n\n const element = (target ? getElement(target) : internalRef.current) as Element;\n if (!element) return;\n\n const resizeObserver = new ResizeObserver((entries) => {\n const entry = entries[0];\n if (!entry) return;\n\n const { x, y, width, height, top, left, bottom, right } = entry.contentRect;\n setRect({ x, y, width, height, top, left, bottom, right });\n });\n\n resizeObserver.observe(element);\n\n return () => {\n resizeObserver.disconnect();\n };\n }, [target, internalRef.state]);\n\n if (target) return rect;\n return { ref: internalRef, ...rect };\n}) as UseMeasure;\n"],"names":["useMeasure","params","target","isTarget","internalRef","useRefState","rect","setRect","useState","useEffect","element","getElement","resizeObserver","entries","entry","x","y","width","height","top","left","bottom","right"],"mappings":";;;;AA6CO,MAAMA,IAAc,IAAIC,MAAkB;AAC/C,QAAMC,IAAUC,EAASF,EAAO,CAAC,CAAC,IAAIA,EAAO,CAAC,IAAI,QAE5CG,IAAcC,EAAA,GACd,CAACC,GAAMC,CAAO,IAAIC,EAAS;AAAA,IAC/B,GAAG;AAAA,IACH,GAAG;AAAA,IACH,OAAO;AAAA,IACP,QAAQ;AAAA,IACR,KAAK;AAAA,IACL,MAAM;AAAA,IACN,QAAQ;AAAA,IACR,OAAO;AAAA,EAAA,CACR;AAuBD,SArBAC,EAAU,MAAM;AACd,QAAI,CAACP,KAAU,CAACE,EAAY,MAAO;AAEnC,UAAMM,IAAWR,IAASS,EAAWT,CAAM,IAAIE,EAAY;AAC3D,QAAI,CAACM,EAAS;AAEd,UAAME,IAAiB,IAAI,eAAe,CAACC,MAAY;AACrD,YAAMC,IAAQD,EAAQ,CAAC;AACvB,UAAI,CAACC,EAAO;AAEZ,YAAM,EAAE,GAAAC,GAAG,GAAAC,GAAG,OAAAC,GAAO,QAAAC,GAAQ,KAAAC,GAAK,MAAAC,GAAM,QAAAC,GAAQ,OAAAC,EAAA,IAAUR,EAAM;AAChE,MAAAP,EAAQ,EAAE,GAAAQ,GAAG,GAAAC,GAAG,OAAAC,GAAO,QAAAC,GAAQ,KAAAC,GAAK,MAAAC,GAAM,QAAAC,GAAQ,OAAAC,GAAO;AAAA,IAAA,CAC1D;AAED,WAAAV,EAAe,QAAQF,CAAO,GAEvB,MAAM;AACX,MAAAE,EAAe,WAAA;AAAA,IAAW;AAAA,EAC5B,GACC,CAACV,GAAQE,EAAY,KAAK,CAAC,GAE1BF,IAAeI,IACZ,EAAE,KAAKF,GAAa,GAAGE,EAAA;AAChC;"}
@@ -1 +1 @@
1
- {"version":3,"file":"useMediaQuery.mjs","sources":["../../../../src/hooks/useMediaQuery/useMediaQuery.ts"],"sourcesContent":["import { useCallback, useSyncExternalStore } from 'react';\n\nconst getServerSnapshot = () => false;\n\n/**\n * @name useMediaQuery\n * @description - Hook that manages a media query\n * @category Browser\n *\n * @browserapi window.matchMedia https://developer.mozilla.org/en-US/docs/Web/API/Window/matchMedia\n *\n * @param {string} query The media query string\n * @returns {boolean} A boolean indicating if the media query matches\n *\n * @example\n * const matches = useMediaQuery('(max-width: 768px)');\n */\nexport const useMediaQuery = (query: string) => {\n const subscribe = useCallback(\n (callback: () => void) => {\n const matchMedia = window.matchMedia(query);\n\n matchMedia.addEventListener('change', callback);\n return () => {\n matchMedia.removeEventListener('change', callback);\n };\n },\n [query]\n );\n\n const getSnapshot = () => window.matchMedia(query).matches;\n\n return useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);\n};\n"],"names":["getServerSnapshot","useMediaQuery","query","subscribe","useCallback","callback","matchMedia","useSyncExternalStore"],"mappings":";AAEA,MAAMA,IAAoB,MAAM,IAenBC,IAAgB,CAACC,MAAkB;AAC9C,QAAMC,IAAYC;AAAA,IAChB,CAACC,MAAyB;AAClB,YAAAC,IAAa,OAAO,WAAWJ,CAAK;AAE/B,aAAAI,EAAA,iBAAiB,UAAUD,CAAQ,GACvC,MAAM;AACA,QAAAC,EAAA,oBAAoB,UAAUD,CAAQ;AAAA,MACnD;AAAA,IACF;AAAA,IACA,CAACH,CAAK;AAAA,EACR;AAIO,SAAAK,EAAqBJ,GAFR,MAAM,OAAO,WAAWD,CAAK,EAAE,SAECF,CAAiB;AACvE;"}
1
+ {"version":3,"file":"useMediaQuery.mjs","sources":["../../../../src/hooks/useMediaQuery/useMediaQuery.ts"],"sourcesContent":["import { useCallback, useSyncExternalStore } from 'react';\n\nconst getServerSnapshot = () => false;\n\n/**\n * @name useMediaQuery\n * @description - Hook that manages a media query\n * @category Browser\n *\n * @browserapi window.matchMedia https://developer.mozilla.org/en-US/docs/Web/API/Window/matchMedia\n *\n * @param {string} query The media query string\n * @returns {boolean} A boolean indicating if the media query matches\n *\n * @example\n * const matches = useMediaQuery('(max-width: 768px)');\n */\nexport const useMediaQuery = (query: string) => {\n const subscribe = useCallback(\n (callback: () => void) => {\n const matchMedia = window.matchMedia(query);\n\n matchMedia.addEventListener('change', callback);\n return () => {\n matchMedia.removeEventListener('change', callback);\n };\n },\n [query]\n );\n\n const getSnapshot = () => window.matchMedia(query).matches;\n\n return useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);\n};\n"],"names":["getServerSnapshot","useMediaQuery","query","subscribe","useCallback","callback","matchMedia","useSyncExternalStore"],"mappings":";AAEA,MAAMA,IAAoB,MAAM,IAenBC,IAAgB,CAACC,MAAkB;AAC9C,QAAMC,IAAYC;AAAA,IAChB,CAACC,MAAyB;AACxB,YAAMC,IAAa,OAAO,WAAWJ,CAAK;AAE1C,aAAAI,EAAW,iBAAiB,UAAUD,CAAQ,GACvC,MAAM;AACX,QAAAC,EAAW,oBAAoB,UAAUD,CAAQ;AAAA,MAAA;AAAA,IACnD;AAAA,IAEF,CAACH,CAAK;AAAA,EAAA;AAKR,SAAOK,EAAqBJ,GAFR,MAAM,OAAO,WAAWD,CAAK,EAAE,SAECF,CAAiB;AACvE;"}
@@ -2,7 +2,7 @@ import { useState as o } from "react";
2
2
  import { useInterval as t } from "../useInterval/useInterval.mjs";
3
3
  const n = () => {
4
4
  const e = performance && "memory" in performance && !!performance.memory, [r, m] = o(
5
- (performance == null ? void 0 : performance.memory) ?? {
5
+ performance?.memory ?? {
6
6
  jsHeapSizeLimit: 0,
7
7
  totalJSHeapSize: 0,
8
8
  usedJSHeapSize: 0
@@ -1 +1 @@
1
- {"version":3,"file":"useMemory.mjs","sources":["../../../../src/hooks/useMemory/useMemory.ts"],"sourcesContent":["import { useState } from 'react';\n\nimport { useInterval } from '../useInterval/useInterval';\n\ndeclare global {\n interface Performance {\n memory: {\n readonly jsHeapSizeLimit: number;\n readonly totalJSHeapSize: number;\n readonly usedJSHeapSize: number;\n };\n }\n}\n\n/** The use memory return type */\nexport interface UseMemoryReturn {\n /** The memory supported status */\n supported: boolean;\n /** The current memory usage */\n value: Performance['memory'];\n}\n\n/**\n * @name useMemory\n * @description - Hook that gives you current memory usage\n * @category Browser\n *\n * @browserapi performance.memory https://developer.mozilla.org/en-US/docs/Web/API/Performance/memory\n *\n * @returns {UseMemoryReturn} An object containing the current memory usage\n *\n * @example\n * const { supported, value } = useMemory();\n */\nexport const useMemory = (): UseMemoryReturn => {\n const supported = performance && 'memory' in performance && !!performance.memory;\n const [value, setValue] = useState<Performance['memory']>(\n performance?.memory ?? {\n jsHeapSizeLimit: 0,\n totalJSHeapSize: 0,\n usedJSHeapSize: 0\n }\n );\n\n useInterval(() => setValue(performance.memory), 1000, {\n immediately: supported\n });\n\n return { supported, value };\n};\n"],"names":["useMemory","supported","value","setValue","useState","useInterval"],"mappings":";;AAkCO,MAAMA,IAAY,MAAuB;AAC9C,QAAMC,IAAY,eAAe,YAAY,eAAe,CAAC,CAAC,YAAY,QACpE,CAACC,GAAOC,CAAQ,IAAIC;AAAA,KACxB,2CAAa,WAAU;AAAA,MACrB,iBAAiB;AAAA,MACjB,iBAAiB;AAAA,MACjB,gBAAgB;AAAA,IAAA;AAAA,EAEpB;AAEA,SAAAC,EAAY,MAAMF,EAAS,YAAY,MAAM,GAAG,KAAM;AAAA,IACpD,aAAaF;AAAA,EAAA,CACd,GAEM,EAAE,WAAAA,GAAW,OAAAC,EAAM;AAC5B;"}
1
+ {"version":3,"file":"useMemory.mjs","sources":["../../../../src/hooks/useMemory/useMemory.ts"],"sourcesContent":["import { useState } from 'react';\n\nimport { useInterval } from '../useInterval/useInterval';\n\ndeclare global {\n interface Performance {\n memory: {\n readonly jsHeapSizeLimit: number;\n readonly totalJSHeapSize: number;\n readonly usedJSHeapSize: number;\n };\n }\n}\n\n/** The use memory return type */\nexport interface UseMemoryReturn {\n /** The memory supported status */\n supported: boolean;\n /** The current memory usage */\n value: Performance['memory'];\n}\n\n/**\n * @name useMemory\n * @description - Hook that gives you current memory usage\n * @category Browser\n *\n * @browserapi performance.memory https://developer.mozilla.org/en-US/docs/Web/API/Performance/memory\n *\n * @returns {UseMemoryReturn} An object containing the current memory usage\n *\n * @example\n * const { supported, value } = useMemory();\n */\nexport const useMemory = (): UseMemoryReturn => {\n const supported = performance && 'memory' in performance && !!performance.memory;\n const [value, setValue] = useState<Performance['memory']>(\n performance?.memory ?? {\n jsHeapSizeLimit: 0,\n totalJSHeapSize: 0,\n usedJSHeapSize: 0\n }\n );\n\n useInterval(() => setValue(performance.memory), 1000, {\n immediately: supported\n });\n\n return { supported, value };\n};\n"],"names":["useMemory","supported","value","setValue","useState","useInterval"],"mappings":";;AAkCO,MAAMA,IAAY,MAAuB;AAC9C,QAAMC,IAAY,eAAe,YAAY,eAAe,CAAC,CAAC,YAAY,QACpE,CAACC,GAAOC,CAAQ,IAAIC;AAAA,IACxB,aAAa,UAAU;AAAA,MACrB,iBAAiB;AAAA,MACjB,iBAAiB;AAAA,MACjB,gBAAgB;AAAA,IAAA;AAAA,EAClB;AAGF,SAAAC,EAAY,MAAMF,EAAS,YAAY,MAAM,GAAG,KAAM;AAAA,IACpD,aAAaF;AAAA,EAAA,CACd,GAEM,EAAE,WAAAA,GAAW,OAAAC,EAAA;AACtB;"}
@@ -1 +1 @@
1
- {"version":3,"file":"useMount.mjs","sources":["../../../../src/hooks/useMount/useMount.ts"],"sourcesContent":["import type { EffectCallback } from 'react';\n\nimport { useEffect } from 'react';\n\n/**\n * @name useMount\n * @description - Hook that executes a callback when the component mounts\n * @category Lifecycle\n *\n * @param {EffectCallback} effect The callback to execute\n *\n * @example\n * useMount(() => console.log('This effect runs on the initial render'));\n */\nexport const useMount = (effect: EffectCallback) => useEffect(effect, []);\n"],"names":["useMount","effect","useEffect"],"mappings":";AAcO,MAAMA,IAAW,CAACC,MAA2BC,EAAUD,GAAQ,CAAE,CAAA;"}
1
+ {"version":3,"file":"useMount.mjs","sources":["../../../../src/hooks/useMount/useMount.ts"],"sourcesContent":["import type { EffectCallback } from 'react';\n\nimport { useEffect } from 'react';\n\n/**\n * @name useMount\n * @description - Hook that executes a callback when the component mounts\n * @category Lifecycle\n *\n * @param {EffectCallback} effect The callback to execute\n *\n * @example\n * useMount(() => console.log('This effect runs on the initial render'));\n */\nexport const useMount = (effect: EffectCallback) => useEffect(effect, []);\n"],"names":["useMount","effect","useEffect"],"mappings":";AAcO,MAAMA,IAAW,CAACC,MAA2BC,EAAUD,GAAQ,CAAA,CAAE;"}
@@ -1 +1 @@
1
- {"version":3,"file":"useMouse.mjs","sources":["../../../../src/hooks/useMouse/useMouse.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\nimport type { HookTarget } from '@/utils/helpers';\n\nimport { getElement, isTarget } from '@/utils/helpers';\n\nimport type { StateRef } from '../useRefState/useRefState';\n\nimport { useRefState } from '../useRefState/useRefState';\n\n/** The use mouse return type */\nexport interface UseMouseReturn {\n /** The current mouse client x position */\n clientX: number;\n /** The current mouse client y position */\n clientY: number;\n /** The current element position x */\n elementPositionX: number;\n /** The current element position y */\n elementPositionY: number;\n /** The current element x position */\n elementX: number;\n /** The current element y position */\n elementY: number;\n /** The current mouse x position */\n x: number;\n /** The current mouse y position */\n y: number;\n}\n\nexport interface UseMouse {\n (target: HookTarget): UseMouseReturn;\n\n <Target extends Element>(\n target?: never\n ): UseMouseReturn & {\n ref: StateRef<Target>;\n };\n\n (target?: Window): UseMouseReturn;\n}\n\n/**\n * @name useMouse\n * @description - Hook that manages a mouse position\n * @category Sensors\n *\n * @overload\n * @param {HookTarget} [target=window] The target element to manage the mouse position for\n * @returns {UseMouseReturn} An object with the current mouse position\n *\n * @example\n * const { x, y, clientX, clientY, elementX, elementY, elementPositionX, elementPositionY } = useMouse(ref);\n *\n * @overload\n * @template Target The target element\n * @returns {UseMouseReturn & { ref: StateRef<Target> }} An object with the current mouse position and a ref\n *\n * @example\n * const { ref, x, y, clientX, clientY, elementX, elementY, elementPositionX, elementPositionY } = useMouse();\n */\nexport const useMouse = ((...params: any[]) => {\n const target = isTarget(params[0]) ? params[0] : undefined;\n\n const [value, setValue] = useState<UseMouseReturn>({\n x: 0,\n y: 0,\n elementX: 0,\n elementY: 0,\n elementPositionX: 0,\n elementPositionY: 0,\n clientX: 0,\n clientY: 0\n });\n\n const internalRef = useRefState<Element>();\n\n useEffect(() => {\n const onMouseMove = (event: MouseEvent) => {\n const element = (target ? getElement(target) : internalRef.current) as Element | undefined;\n\n const updatedValue = {\n x: event.pageX,\n y: event.pageY,\n clientX: event.clientX,\n clientY: event.clientY\n } as typeof value;\n\n if (element) {\n const { left, top } = element.getBoundingClientRect();\n const elementPositionX = left + window.scrollX;\n const elementPositionY = top + window.scrollY;\n const elementX = event.pageX - elementPositionX;\n const elementY = event.pageY - elementPositionY;\n\n updatedValue.elementX = elementX;\n updatedValue.elementY = elementY;\n updatedValue.elementPositionX = elementPositionX;\n updatedValue.elementPositionY = elementPositionY;\n\n setValue((prevValue) => ({\n ...prevValue,\n ...updatedValue\n }));\n } else {\n updatedValue.elementX = event.pageX;\n updatedValue.elementY = event.pageY;\n updatedValue.elementPositionX = 0;\n updatedValue.elementPositionY = 0;\n\n setValue((prevValue) => ({\n ...prevValue,\n ...updatedValue\n }));\n }\n };\n\n const onScroll = () => {\n setValue((prevValue) => ({\n ...prevValue,\n x: prevValue.x + window.scrollX - prevValue.elementPositionX,\n y: prevValue.y + window.scrollY - prevValue.elementPositionY,\n elementPositionX: window.scrollX,\n elementPositionY: window.scrollY\n }));\n };\n\n document.addEventListener('scroll', onScroll, { passive: true });\n document.addEventListener('mousemove', onMouseMove);\n return () => {\n document.removeEventListener('scroll', onScroll);\n document.removeEventListener('mousemove', onMouseMove);\n };\n }, [internalRef.state, target]);\n\n if (target) return value;\n return {\n ref: internalRef,\n ...value\n };\n}) as UseMouse;\n"],"names":["useMouse","params","target","isTarget","value","setValue","useState","internalRef","useRefState","useEffect","onMouseMove","event","element","getElement","updatedValue","left","top","elementPositionX","elementPositionY","elementX","elementY","prevValue","onScroll"],"mappings":";;;;AA6Da,MAAAA,IAAY,IAAIC,MAAkB;AACvC,QAAAC,IAASC,EAASF,EAAO,CAAC,CAAC,IAAIA,EAAO,CAAC,IAAI,QAE3C,CAACG,GAAOC,CAAQ,IAAIC,EAAyB;AAAA,IACjD,GAAG;AAAA,IACH,GAAG;AAAA,IACH,UAAU;AAAA,IACV,UAAU;AAAA,IACV,kBAAkB;AAAA,IAClB,kBAAkB;AAAA,IAClB,SAAS;AAAA,IACT,SAAS;AAAA,EAAA,CACV,GAEKC,IAAcC,EAAqB;AA4DzC,SA1DAC,EAAU,MAAM;AACR,UAAAC,IAAc,CAACC,MAAsB;AACzC,YAAMC,IAAWV,IAASW,EAAWX,CAAM,IAAIK,EAAY,SAErDO,IAAe;AAAA,QACnB,GAAGH,EAAM;AAAA,QACT,GAAGA,EAAM;AAAA,QACT,SAASA,EAAM;AAAA,QACf,SAASA,EAAM;AAAA,MACjB;AAEA,UAAIC,GAAS;AACX,cAAM,EAAE,MAAAG,GAAM,KAAAC,MAAQJ,EAAQ,sBAAsB,GAC9CK,IAAmBF,IAAO,OAAO,SACjCG,IAAmBF,IAAM,OAAO,SAChCG,IAAWR,EAAM,QAAQM,GACzBG,IAAWT,EAAM,QAAQO;AAE/B,QAAAJ,EAAa,WAAWK,GACxBL,EAAa,WAAWM,GACxBN,EAAa,mBAAmBG,GAChCH,EAAa,mBAAmBI,GAEhCb,EAAS,CAACgB,OAAe;AAAA,UACvB,GAAGA;AAAA,UACH,GAAGP;AAAA,QAAA,EACH;AAAA,MAAA;AAEF,QAAAA,EAAa,WAAWH,EAAM,OAC9BG,EAAa,WAAWH,EAAM,OAC9BG,EAAa,mBAAmB,GAChCA,EAAa,mBAAmB,GAEhCT,EAAS,CAACgB,OAAe;AAAA,UACvB,GAAGA;AAAA,UACH,GAAGP;AAAA,QAAA,EACH;AAAA,IAEN,GAEMQ,IAAW,MAAM;AACrB,MAAAjB,EAAS,CAACgB,OAAe;AAAA,QACvB,GAAGA;AAAA,QACH,GAAGA,EAAU,IAAI,OAAO,UAAUA,EAAU;AAAA,QAC5C,GAAGA,EAAU,IAAI,OAAO,UAAUA,EAAU;AAAA,QAC5C,kBAAkB,OAAO;AAAA,QACzB,kBAAkB,OAAO;AAAA,MAAA,EACzB;AAAA,IACJ;AAEA,oBAAS,iBAAiB,UAAUC,GAAU,EAAE,SAAS,IAAM,GACtD,SAAA,iBAAiB,aAAaZ,CAAW,GAC3C,MAAM;AACF,eAAA,oBAAoB,UAAUY,CAAQ,GACtC,SAAA,oBAAoB,aAAaZ,CAAW;AAAA,IACvD;AAAA,EACC,GAAA,CAACH,EAAY,OAAOL,CAAM,CAAC,GAE1BA,IAAeE,IACZ;AAAA,IACL,KAAKG;AAAA,IACL,GAAGH;AAAA,EACL;AACF;"}
1
+ {"version":3,"file":"useMouse.mjs","sources":["../../../../src/hooks/useMouse/useMouse.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\nimport type { HookTarget } from '@/utils/helpers';\n\nimport { getElement, isTarget } from '@/utils/helpers';\n\nimport type { StateRef } from '../useRefState/useRefState';\n\nimport { useRefState } from '../useRefState/useRefState';\n\n/** The use mouse return type */\nexport interface UseMouseReturn {\n /** The current mouse client x position */\n clientX: number;\n /** The current mouse client y position */\n clientY: number;\n /** The current element position x */\n elementPositionX: number;\n /** The current element position y */\n elementPositionY: number;\n /** The current element x position */\n elementX: number;\n /** The current element y position */\n elementY: number;\n /** The current mouse x position */\n x: number;\n /** The current mouse y position */\n y: number;\n}\n\nexport interface UseMouse {\n (target: HookTarget): UseMouseReturn;\n\n <Target extends Element>(\n target?: never\n ): UseMouseReturn & {\n ref: StateRef<Target>;\n };\n\n (target?: Window): UseMouseReturn;\n}\n\n/**\n * @name useMouse\n * @description - Hook that manages a mouse position\n * @category Sensors\n *\n * @overload\n * @param {HookTarget} [target=window] The target element to manage the mouse position for\n * @returns {UseMouseReturn} An object with the current mouse position\n *\n * @example\n * const { x, y, clientX, clientY, elementX, elementY, elementPositionX, elementPositionY } = useMouse(ref);\n *\n * @overload\n * @template Target The target element\n * @returns {UseMouseReturn & { ref: StateRef<Target> }} An object with the current mouse position and a ref\n *\n * @example\n * const { ref, x, y, clientX, clientY, elementX, elementY, elementPositionX, elementPositionY } = useMouse();\n */\nexport const useMouse = ((...params: any[]) => {\n const target = isTarget(params[0]) ? params[0] : undefined;\n\n const [value, setValue] = useState<UseMouseReturn>({\n x: 0,\n y: 0,\n elementX: 0,\n elementY: 0,\n elementPositionX: 0,\n elementPositionY: 0,\n clientX: 0,\n clientY: 0\n });\n\n const internalRef = useRefState<Element>();\n\n useEffect(() => {\n const onMouseMove = (event: MouseEvent) => {\n const element = (target ? getElement(target) : internalRef.current) as Element | undefined;\n\n const updatedValue = {\n x: event.pageX,\n y: event.pageY,\n clientX: event.clientX,\n clientY: event.clientY\n } as typeof value;\n\n if (element) {\n const { left, top } = element.getBoundingClientRect();\n const elementPositionX = left + window.scrollX;\n const elementPositionY = top + window.scrollY;\n const elementX = event.pageX - elementPositionX;\n const elementY = event.pageY - elementPositionY;\n\n updatedValue.elementX = elementX;\n updatedValue.elementY = elementY;\n updatedValue.elementPositionX = elementPositionX;\n updatedValue.elementPositionY = elementPositionY;\n\n setValue((prevValue) => ({\n ...prevValue,\n ...updatedValue\n }));\n } else {\n updatedValue.elementX = event.pageX;\n updatedValue.elementY = event.pageY;\n updatedValue.elementPositionX = 0;\n updatedValue.elementPositionY = 0;\n\n setValue((prevValue) => ({\n ...prevValue,\n ...updatedValue\n }));\n }\n };\n\n const onScroll = () => {\n setValue((prevValue) => ({\n ...prevValue,\n x: prevValue.x + window.scrollX - prevValue.elementPositionX,\n y: prevValue.y + window.scrollY - prevValue.elementPositionY,\n elementPositionX: window.scrollX,\n elementPositionY: window.scrollY\n }));\n };\n\n document.addEventListener('scroll', onScroll, { passive: true });\n document.addEventListener('mousemove', onMouseMove);\n return () => {\n document.removeEventListener('scroll', onScroll);\n document.removeEventListener('mousemove', onMouseMove);\n };\n }, [internalRef.state, target]);\n\n if (target) return value;\n return {\n ref: internalRef,\n ...value\n };\n}) as UseMouse;\n"],"names":["useMouse","params","target","isTarget","value","setValue","useState","internalRef","useRefState","useEffect","onMouseMove","event","element","getElement","updatedValue","left","top","elementPositionX","elementPositionY","elementX","elementY","prevValue","onScroll"],"mappings":";;;;AA6DO,MAAMA,IAAY,IAAIC,MAAkB;AAC7C,QAAMC,IAASC,EAASF,EAAO,CAAC,CAAC,IAAIA,EAAO,CAAC,IAAI,QAE3C,CAACG,GAAOC,CAAQ,IAAIC,EAAyB;AAAA,IACjD,GAAG;AAAA,IACH,GAAG;AAAA,IACH,UAAU;AAAA,IACV,UAAU;AAAA,IACV,kBAAkB;AAAA,IAClB,kBAAkB;AAAA,IAClB,SAAS;AAAA,IACT,SAAS;AAAA,EAAA,CACV,GAEKC,IAAcC,EAAA;AA4DpB,SA1DAC,EAAU,MAAM;AACd,UAAMC,IAAc,CAACC,MAAsB;AACzC,YAAMC,IAAWV,IAASW,EAAWX,CAAM,IAAIK,EAAY,SAErDO,IAAe;AAAA,QACnB,GAAGH,EAAM;AAAA,QACT,GAAGA,EAAM;AAAA,QACT,SAASA,EAAM;AAAA,QACf,SAASA,EAAM;AAAA,MAAA;AAGjB,UAAIC,GAAS;AACX,cAAM,EAAE,MAAAG,GAAM,KAAAC,MAAQJ,EAAQ,sBAAA,GACxBK,IAAmBF,IAAO,OAAO,SACjCG,IAAmBF,IAAM,OAAO,SAChCG,IAAWR,EAAM,QAAQM,GACzBG,IAAWT,EAAM,QAAQO;AAE/B,QAAAJ,EAAa,WAAWK,GACxBL,EAAa,WAAWM,GACxBN,EAAa,mBAAmBG,GAChCH,EAAa,mBAAmBI,GAEhCb,EAAS,CAACgB,OAAe;AAAA,UACvB,GAAGA;AAAA,UACH,GAAGP;AAAA,QAAA,EACH;AAAA,MAAA;AAEF,QAAAA,EAAa,WAAWH,EAAM,OAC9BG,EAAa,WAAWH,EAAM,OAC9BG,EAAa,mBAAmB,GAChCA,EAAa,mBAAmB,GAEhCT,EAAS,CAACgB,OAAe;AAAA,UACvB,GAAGA;AAAA,UACH,GAAGP;AAAA,QAAA,EACH;AAAA,IACJ,GAGIQ,IAAW,MAAM;AACrB,MAAAjB,EAAS,CAACgB,OAAe;AAAA,QACvB,GAAGA;AAAA,QACH,GAAGA,EAAU,IAAI,OAAO,UAAUA,EAAU;AAAA,QAC5C,GAAGA,EAAU,IAAI,OAAO,UAAUA,EAAU;AAAA,QAC5C,kBAAkB,OAAO;AAAA,QACzB,kBAAkB,OAAO;AAAA,MAAA,EACzB;AAAA,IAAA;AAGJ,oBAAS,iBAAiB,UAAUC,GAAU,EAAE,SAAS,IAAM,GAC/D,SAAS,iBAAiB,aAAaZ,CAAW,GAC3C,MAAM;AACX,eAAS,oBAAoB,UAAUY,CAAQ,GAC/C,SAAS,oBAAoB,aAAaZ,CAAW;AAAA,IAAA;AAAA,EACvD,GACC,CAACH,EAAY,OAAOL,CAAM,CAAC,GAE1BA,IAAeE,IACZ;AAAA,IACL,KAAKG;AAAA,IACL,GAAGH;AAAA,EAAA;AAEP;"}
@@ -1,64 +1,60 @@
1
- import { useState as S } from "react";
2
- const F = (M, y) => {
3
- const [a, g] = S(!1), [j, h] = S(!1), [k, A] = S(!1), [v, L] = S(null), [w, T] = S(null), E = (l, c) => {
4
- g(!0);
5
- const r = (c == null ? void 0 : c.attempt) ?? 0;
6
- return M(l).then((f) => {
7
- var D;
8
- return (D = c == null ? void 0 : c.onSuccess) == null || D.call(c, f), T(f), A(!0), g(!1), L(null), h(!1), f;
9
- }).catch((f) => {
10
- var x;
11
- const D = typeof (c == null ? void 0 : c.retry) == "function" ? c == null ? void 0 : c.retry(r, f) : c == null ? void 0 : c.retry, I = typeof (c == null ? void 0 : c.retryDelay) == "function" ? c == null ? void 0 : c.retryDelay(r, f) : c == null ? void 0 : c.retryDelay;
12
- if (typeof D == "boolean" && D) {
13
- if (I) {
1
+ import { useState as n } from "react";
2
+ const M = (S, c) => {
3
+ const [m, u] = n(!1), [I, f] = n(!1), [g, o] = n(!1), [h, D] = n(null), [A, E] = n(null), y = (t, r) => {
4
+ u(!0);
5
+ const e = r?.attempt ?? 0;
6
+ return S(t).then((a) => (r?.onSuccess?.(a), E(a), o(!0), u(!1), D(null), f(!1), a)).catch((a) => {
7
+ const l = typeof r?.retry == "function" ? r?.retry(e, a) : r?.retry, s = typeof r?.retryDelay == "function" ? r?.retryDelay(e, a) : r?.retryDelay;
8
+ if (typeof l == "boolean" && l) {
9
+ if (s) {
14
10
  setTimeout(
15
- () => E(l, { ...c, attempt: r + 1 }),
16
- I
11
+ () => y(t, { ...r, attempt: e + 1 }),
12
+ s
17
13
  );
18
14
  return;
19
15
  }
20
- return E(l, { ...c, attempt: r + 1 });
16
+ return y(t, { ...r, attempt: e + 1 });
21
17
  }
22
- if (D && D > r) {
23
- if (I) {
18
+ if (l && l > e) {
19
+ if (s) {
24
20
  setTimeout(
25
- () => E(l, { ...c, attempt: r + 1 }),
26
- I
21
+ () => y(t, { ...r, attempt: e + 1 }),
22
+ s
27
23
  );
28
24
  return;
29
25
  }
30
- return E(l, { ...c, attempt: r + 1 });
26
+ return y(t, { ...r, attempt: e + 1 });
31
27
  }
32
- (x = c == null ? void 0 : c.onError) == null || x.call(c, f), T(null), A(!1), g(!1), L(f), h(!0);
28
+ r?.onError?.(a), E(null), o(!1), u(!1), D(a), f(!0);
33
29
  });
34
30
  };
35
31
  return {
36
- data: w,
37
- error: v,
38
- mutate: (l, c) => {
39
- const r = {
40
- retry: (c == null ? void 0 : c.retry) ?? (y == null ? void 0 : y.retry),
41
- retryDelay: (c == null ? void 0 : c.retryDelay) ?? (y == null ? void 0 : y.retryDelay),
42
- onSuccess: (c == null ? void 0 : c.onSuccess) ?? (y == null ? void 0 : y.onSuccess),
43
- onError: (c == null ? void 0 : c.onError) ?? (y == null ? void 0 : y.onError)
32
+ data: A,
33
+ error: h,
34
+ mutate: (t, r) => {
35
+ const e = {
36
+ retry: r?.retry ?? c?.retry,
37
+ retryDelay: r?.retryDelay ?? c?.retryDelay,
38
+ onSuccess: r?.onSuccess ?? c?.onSuccess,
39
+ onError: r?.onError ?? c?.onError
44
40
  };
45
- E(l, r);
41
+ y(t, e);
46
42
  },
47
- mutateAsync: async (l, c) => {
48
- const r = {
49
- retry: (c == null ? void 0 : c.retry) ?? (y == null ? void 0 : y.retry),
50
- retryDelay: (c == null ? void 0 : c.retryDelay) ?? (y == null ? void 0 : y.retryDelay),
51
- onSuccess: (c == null ? void 0 : c.onSuccess) ?? (y == null ? void 0 : y.onSuccess),
52
- onError: (c == null ? void 0 : c.onError) ?? (y == null ? void 0 : y.onError)
43
+ mutateAsync: async (t, r) => {
44
+ const e = {
45
+ retry: r?.retry ?? c?.retry,
46
+ retryDelay: r?.retryDelay ?? c?.retryDelay,
47
+ onSuccess: r?.onSuccess ?? c?.onSuccess,
48
+ onError: r?.onError ?? c?.onError
53
49
  };
54
- return E(l, r);
50
+ return y(t, e);
55
51
  },
56
- isLoading: a,
57
- isError: j,
58
- isSuccess: k
52
+ isLoading: m,
53
+ isError: I,
54
+ isSuccess: g
59
55
  };
60
56
  };
61
57
  export {
62
- F as useMutation
58
+ M as useMutation
63
59
  };
64
60
  //# sourceMappingURL=useMutation.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"useMutation.mjs","sources":["../../../../src/hooks/useMutation/useMutation.ts"],"sourcesContent":["import { useState } from 'react';\n\n/* The type of the options */\ninterface UseMutationOptions<Data> {\n /* The retry count of requests */\n retry?: ((failureCount: number, error: Error) => boolean) | boolean | number;\n /* The retry delay of requests */\n retryDelay?: ((retry: number, error: Error) => number) | number;\n /* The callback function to be invoked on error */\n onError?: (error: Error) => void;\n /* The callback function to be invoked on success */\n onSuccess?: (data: Data) => void;\n}\n\n/* The use mutation return type */\ninterface UseMutationReturn<Body, Data> {\n /* The data of the mutation */\n data: Data | null;\n /* The error of the mutation */\n error: Error | null;\n /* The error state of the mutation */\n isError: boolean;\n /* The loading state of the mutation */\n isLoading: boolean;\n /* The success state of the mutation */\n isSuccess: boolean;\n /* The mutate function */\n mutate: (body?: Body, options?: UseMutationOptions<Data>) => void;\n /* The mutate async function */\n mutateAsync: (body?: Body, options?: UseMutationOptions<Data>) => Promise<Data>;\n}\n\nexport interface RequestOptions<Data> extends UseMutationOptions<Data> {\n /* The attempt count */\n attempt?: number;\n}\n\n/**\n * @name useMutation\n * @description - Hook that defines the logic when mutate data\n * @category Utilities\n *\n * @template Body The type of the body\n * @template Data The type of the data\n * @param {(body: Body) => Promise<Data>} callback The callback function to be invoked\n * @param {boolean | number} [options.retry] The retry count of requests\n * @param {(data: Data) => void} [options.onSuccess] The callback function to be invoked on success\n * @param {(error: Error) => void} [options.onError] The callback function to be invoked on error\n * @returns {UseMutationReturn<Data>} An object with the state of the mutation\n *\n * @example\n * const { mutate, mutateAsync, isLoading, isError, isSuccess, error, data } = useMutation((name) => Promise.resolve(name));\n */\nexport const useMutation = <Body, Data>(\n callback: (body: Body) => Promise<Data>,\n options?: UseMutationOptions<Data>\n) => {\n const [isLoading, setIsLoading] = useState(false);\n const [isError, setIsError] = useState(false);\n const [isSuccess, setIsSuccess] = useState(false);\n\n const [error, setError] = useState<Error | null>(null);\n const [data, setData] = useState<Data | null>(null);\n\n const request = (\n body: Body,\n requestOptions?: RequestOptions<Data>\n ): Promise<Data | undefined> => {\n setIsLoading(true);\n const attempt = requestOptions?.attempt ?? 0;\n\n return callback(body)\n .then((response) => {\n requestOptions?.onSuccess?.(response);\n\n setData(response);\n setIsSuccess(true);\n setIsLoading(false);\n setError(null);\n setIsError(false);\n return response;\n })\n .catch((error: Error) => {\n const retry =\n typeof requestOptions?.retry === 'function'\n ? requestOptions?.retry(attempt, error)\n : requestOptions?.retry;\n\n const retryDelay =\n typeof requestOptions?.retryDelay === 'function'\n ? requestOptions?.retryDelay(attempt, error)\n : requestOptions?.retryDelay;\n\n if (typeof retry === 'boolean' && retry) {\n if (retryDelay) {\n setTimeout(\n () => request(body, { ...requestOptions, attempt: attempt + 1 }),\n retryDelay\n );\n return;\n }\n return request(body, { ...requestOptions, attempt: attempt + 1 });\n }\n\n if (retry && retry > attempt) {\n if (retryDelay) {\n setTimeout(\n () => request(body, { ...requestOptions, attempt: attempt + 1 }),\n retryDelay\n );\n return;\n }\n return request(body, { ...requestOptions, attempt: attempt + 1 });\n }\n\n requestOptions?.onError?.(error);\n setData(null);\n setIsSuccess(false);\n setIsLoading(false);\n setError(error);\n setIsError(true);\n });\n };\n const mutate = (body: Body, mutateOptions?: UseMutationOptions<Data>) => {\n const requestOptions = {\n retry: mutateOptions?.retry ?? options?.retry,\n retryDelay: mutateOptions?.retryDelay ?? options?.retryDelay,\n onSuccess: mutateOptions?.onSuccess ?? options?.onSuccess,\n onError: mutateOptions?.onError ?? options?.onError\n };\n\n request(body, requestOptions);\n };\n\n const mutateAsync = async (body: Body, mutateOptions?: UseMutationOptions<Data>) => {\n const requestOptions = {\n retry: mutateOptions?.retry ?? options?.retry,\n retryDelay: mutateOptions?.retryDelay ?? options?.retryDelay,\n onSuccess: mutateOptions?.onSuccess ?? options?.onSuccess,\n onError: mutateOptions?.onError ?? options?.onError\n };\n\n return request(body, requestOptions) as Promise<Data>;\n };\n\n return {\n data,\n error,\n mutate,\n mutateAsync,\n isLoading,\n isError,\n isSuccess\n } as UseMutationReturn<Body, Data>;\n};\n"],"names":["useMutation","callback","options","isLoading","setIsLoading","useState","isError","setIsError","isSuccess","setIsSuccess","error","setError","data","setData","request","body","requestOptions","attempt","response","_a","retry","retryDelay","mutateOptions"],"mappings":";AAqDa,MAAAA,IAAc,CACzBC,GACAC,MACG;AACH,QAAM,CAACC,GAAWC,CAAY,IAAIC,EAAS,EAAK,GAC1C,CAACC,GAASC,CAAU,IAAIF,EAAS,EAAK,GACtC,CAACG,GAAWC,CAAY,IAAIJ,EAAS,EAAK,GAE1C,CAACK,GAAOC,CAAQ,IAAIN,EAAuB,IAAI,GAC/C,CAACO,GAAMC,CAAO,IAAIR,EAAsB,IAAI,GAE5CS,IAAU,CACdC,GACAC,MAC8B;AAC9B,IAAAZ,EAAa,EAAI;AACX,UAAAa,KAAUD,KAAA,gBAAAA,EAAgB,YAAW;AAE3C,WAAOf,EAASc,CAAI,EACjB,KAAK,CAACG,MAAa;;AAClB,cAAAC,IAAAH,KAAA,gBAAAA,EAAgB,cAAhB,QAAAG,EAAA,KAAAH,GAA4BE,IAE5BL,EAAQK,CAAQ,GAChBT,EAAa,EAAI,GACjBL,EAAa,EAAK,GAClBO,EAAS,IAAI,GACbJ,EAAW,EAAK,GACTW;AAAA,IAAA,CACR,EACA,MAAM,CAACR,MAAiB;;AACjB,YAAAU,IACJ,QAAOJ,KAAA,gBAAAA,EAAgB,UAAU,aAC7BA,KAAA,gBAAAA,EAAgB,MAAMC,GAASP,KAC/BM,KAAA,gBAAAA,EAAgB,OAEhBK,IACJ,QAAOL,KAAA,gBAAAA,EAAgB,eAAe,aAClCA,KAAA,gBAAAA,EAAgB,WAAWC,GAASP,KACpCM,KAAA,gBAAAA,EAAgB;AAElB,UAAA,OAAOI,KAAU,aAAaA,GAAO;AACvC,YAAIC,GAAY;AACd;AAAA,YACE,MAAMP,EAAQC,GAAM,EAAE,GAAGC,GAAgB,SAASC,IAAU,GAAG;AAAA,YAC/DI;AAAA,UACF;AACA;AAAA,QAAA;AAEK,eAAAP,EAAQC,GAAM,EAAE,GAAGC,GAAgB,SAASC,IAAU,GAAG;AAAA,MAAA;AAG9D,UAAAG,KAASA,IAAQH,GAAS;AAC5B,YAAII,GAAY;AACd;AAAA,YACE,MAAMP,EAAQC,GAAM,EAAE,GAAGC,GAAgB,SAASC,IAAU,GAAG;AAAA,YAC/DI;AAAA,UACF;AACA;AAAA,QAAA;AAEK,eAAAP,EAAQC,GAAM,EAAE,GAAGC,GAAgB,SAASC,IAAU,GAAG;AAAA,MAAA;AAGlE,OAAAE,IAAAH,KAAA,gBAAAA,EAAgB,YAAhB,QAAAG,EAAA,KAAAH,GAA0BN,IAC1BG,EAAQ,IAAI,GACZJ,EAAa,EAAK,GAClBL,EAAa,EAAK,GAClBO,EAASD,CAAK,GACdH,EAAW,EAAI;AAAA,IAAA,CAChB;AAAA,EACL;AAuBO,SAAA;AAAA,IACL,MAAAK;AAAA,IACA,OAAAF;AAAA,IACA,QAzBa,CAACK,GAAYO,MAA6C;AACvE,YAAMN,IAAiB;AAAA,QACrB,QAAOM,KAAA,gBAAAA,EAAe,WAASpB,KAAA,gBAAAA,EAAS;AAAA,QACxC,aAAYoB,KAAA,gBAAAA,EAAe,gBAAcpB,KAAA,gBAAAA,EAAS;AAAA,QAClD,YAAWoB,KAAA,gBAAAA,EAAe,eAAapB,KAAA,gBAAAA,EAAS;AAAA,QAChD,UAASoB,KAAA,gBAAAA,EAAe,aAAWpB,KAAA,gBAAAA,EAAS;AAAA,MAC9C;AAEA,MAAAY,EAAQC,GAAMC,CAAc;AAAA,IAC9B;AAAA,IAiBE,aAfkB,OAAOD,GAAYO,MAA6C;AAClF,YAAMN,IAAiB;AAAA,QACrB,QAAOM,KAAA,gBAAAA,EAAe,WAASpB,KAAA,gBAAAA,EAAS;AAAA,QACxC,aAAYoB,KAAA,gBAAAA,EAAe,gBAAcpB,KAAA,gBAAAA,EAAS;AAAA,QAClD,YAAWoB,KAAA,gBAAAA,EAAe,eAAapB,KAAA,gBAAAA,EAAS;AAAA,QAChD,UAASoB,KAAA,gBAAAA,EAAe,aAAWpB,KAAA,gBAAAA,EAAS;AAAA,MAC9C;AAEO,aAAAY,EAAQC,GAAMC,CAAc;AAAA,IACrC;AAAA,IAOE,WAAAb;AAAA,IACA,SAAAG;AAAA,IACA,WAAAE;AAAA,EACF;AACF;"}
1
+ {"version":3,"file":"useMutation.mjs","sources":["../../../../src/hooks/useMutation/useMutation.ts"],"sourcesContent":["import { useState } from 'react';\n\n/* The type of the options */\ninterface UseMutationOptions<Data> {\n /* The retry count of requests */\n retry?: ((failureCount: number, error: Error) => boolean) | boolean | number;\n /* The retry delay of requests */\n retryDelay?: ((retry: number, error: Error) => number) | number;\n /* The callback function to be invoked on error */\n onError?: (error: Error) => void;\n /* The callback function to be invoked on success */\n onSuccess?: (data: Data) => void;\n}\n\n/* The use mutation return type */\ninterface UseMutationReturn<Body, Data> {\n /* The data of the mutation */\n data: Data | null;\n /* The error of the mutation */\n error: Error | null;\n /* The error state of the mutation */\n isError: boolean;\n /* The loading state of the mutation */\n isLoading: boolean;\n /* The success state of the mutation */\n isSuccess: boolean;\n /* The mutate function */\n mutate: (body?: Body, options?: UseMutationOptions<Data>) => void;\n /* The mutate async function */\n mutateAsync: (body?: Body, options?: UseMutationOptions<Data>) => Promise<Data>;\n}\n\nexport interface RequestOptions<Data> extends UseMutationOptions<Data> {\n /* The attempt count */\n attempt?: number;\n}\n\n/**\n * @name useMutation\n * @description - Hook that defines the logic when mutate data\n * @category Utilities\n *\n * @template Body The type of the body\n * @template Data The type of the data\n * @param {(body: Body) => Promise<Data>} callback The callback function to be invoked\n * @param {boolean | number} [options.retry] The retry count of requests\n * @param {(data: Data) => void} [options.onSuccess] The callback function to be invoked on success\n * @param {(error: Error) => void} [options.onError] The callback function to be invoked on error\n * @returns {UseMutationReturn<Data>} An object with the state of the mutation\n *\n * @example\n * const { mutate, mutateAsync, isLoading, isError, isSuccess, error, data } = useMutation((name) => Promise.resolve(name));\n */\nexport const useMutation = <Body, Data>(\n callback: (body: Body) => Promise<Data>,\n options?: UseMutationOptions<Data>\n) => {\n const [isLoading, setIsLoading] = useState(false);\n const [isError, setIsError] = useState(false);\n const [isSuccess, setIsSuccess] = useState(false);\n\n const [error, setError] = useState<Error | null>(null);\n const [data, setData] = useState<Data | null>(null);\n\n const request = (\n body: Body,\n requestOptions?: RequestOptions<Data>\n ): Promise<Data | undefined> => {\n setIsLoading(true);\n const attempt = requestOptions?.attempt ?? 0;\n\n return callback(body)\n .then((response) => {\n requestOptions?.onSuccess?.(response);\n\n setData(response);\n setIsSuccess(true);\n setIsLoading(false);\n setError(null);\n setIsError(false);\n return response;\n })\n .catch((error: Error) => {\n const retry =\n typeof requestOptions?.retry === 'function'\n ? requestOptions?.retry(attempt, error)\n : requestOptions?.retry;\n\n const retryDelay =\n typeof requestOptions?.retryDelay === 'function'\n ? requestOptions?.retryDelay(attempt, error)\n : requestOptions?.retryDelay;\n\n if (typeof retry === 'boolean' && retry) {\n if (retryDelay) {\n setTimeout(\n () => request(body, { ...requestOptions, attempt: attempt + 1 }),\n retryDelay\n );\n return;\n }\n return request(body, { ...requestOptions, attempt: attempt + 1 });\n }\n\n if (retry && retry > attempt) {\n if (retryDelay) {\n setTimeout(\n () => request(body, { ...requestOptions, attempt: attempt + 1 }),\n retryDelay\n );\n return;\n }\n return request(body, { ...requestOptions, attempt: attempt + 1 });\n }\n\n requestOptions?.onError?.(error);\n setData(null);\n setIsSuccess(false);\n setIsLoading(false);\n setError(error);\n setIsError(true);\n });\n };\n const mutate = (body: Body, mutateOptions?: UseMutationOptions<Data>) => {\n const requestOptions = {\n retry: mutateOptions?.retry ?? options?.retry,\n retryDelay: mutateOptions?.retryDelay ?? options?.retryDelay,\n onSuccess: mutateOptions?.onSuccess ?? options?.onSuccess,\n onError: mutateOptions?.onError ?? options?.onError\n };\n\n request(body, requestOptions);\n };\n\n const mutateAsync = async (body: Body, mutateOptions?: UseMutationOptions<Data>) => {\n const requestOptions = {\n retry: mutateOptions?.retry ?? options?.retry,\n retryDelay: mutateOptions?.retryDelay ?? options?.retryDelay,\n onSuccess: mutateOptions?.onSuccess ?? options?.onSuccess,\n onError: mutateOptions?.onError ?? options?.onError\n };\n\n return request(body, requestOptions) as Promise<Data>;\n };\n\n return {\n data,\n error,\n mutate,\n mutateAsync,\n isLoading,\n isError,\n isSuccess\n } as UseMutationReturn<Body, Data>;\n};\n"],"names":["useMutation","callback","options","isLoading","setIsLoading","useState","isError","setIsError","isSuccess","setIsSuccess","error","setError","data","setData","request","body","requestOptions","attempt","response","retry","retryDelay","mutateOptions"],"mappings":";AAqDO,MAAMA,IAAc,CACzBC,GACAC,MACG;AACH,QAAM,CAACC,GAAWC,CAAY,IAAIC,EAAS,EAAK,GAC1C,CAACC,GAASC,CAAU,IAAIF,EAAS,EAAK,GACtC,CAACG,GAAWC,CAAY,IAAIJ,EAAS,EAAK,GAE1C,CAACK,GAAOC,CAAQ,IAAIN,EAAuB,IAAI,GAC/C,CAACO,GAAMC,CAAO,IAAIR,EAAsB,IAAI,GAE5CS,IAAU,CACdC,GACAC,MAC8B;AAC9B,IAAAZ,EAAa,EAAI;AACjB,UAAMa,IAAUD,GAAgB,WAAW;AAE3C,WAAOf,EAASc,CAAI,EACjB,KAAK,CAACG,OACLF,GAAgB,YAAYE,CAAQ,GAEpCL,EAAQK,CAAQ,GAChBT,EAAa,EAAI,GACjBL,EAAa,EAAK,GAClBO,EAAS,IAAI,GACbJ,EAAW,EAAK,GACTW,EACR,EACA,MAAM,CAACR,MAAiB;AACvB,YAAMS,IACJ,OAAOH,GAAgB,SAAU,aAC7BA,GAAgB,MAAMC,GAASP,CAAK,IACpCM,GAAgB,OAEhBI,IACJ,OAAOJ,GAAgB,cAAe,aAClCA,GAAgB,WAAWC,GAASP,CAAK,IACzCM,GAAgB;AAEtB,UAAI,OAAOG,KAAU,aAAaA,GAAO;AACvC,YAAIC,GAAY;AACd;AAAA,YACE,MAAMN,EAAQC,GAAM,EAAE,GAAGC,GAAgB,SAASC,IAAU,GAAG;AAAA,YAC/DG;AAAA,UAAA;AAEF;AAAA,QAAA;AAEF,eAAON,EAAQC,GAAM,EAAE,GAAGC,GAAgB,SAASC,IAAU,GAAG;AAAA,MAAA;AAGlE,UAAIE,KAASA,IAAQF,GAAS;AAC5B,YAAIG,GAAY;AACd;AAAA,YACE,MAAMN,EAAQC,GAAM,EAAE,GAAGC,GAAgB,SAASC,IAAU,GAAG;AAAA,YAC/DG;AAAA,UAAA;AAEF;AAAA,QAAA;AAEF,eAAON,EAAQC,GAAM,EAAE,GAAGC,GAAgB,SAASC,IAAU,GAAG;AAAA,MAAA;AAGlE,MAAAD,GAAgB,UAAUN,CAAK,GAC/BG,EAAQ,IAAI,GACZJ,EAAa,EAAK,GAClBL,EAAa,EAAK,GAClBO,EAASD,CAAK,GACdH,EAAW,EAAI;AAAA,IAAA,CAChB;AAAA,EAAA;AAwBL,SAAO;AAAA,IACL,MAAAK;AAAA,IACA,OAAAF;AAAA,IACA,QAzBa,CAACK,GAAYM,MAA6C;AACvE,YAAML,IAAiB;AAAA,QACrB,OAAOK,GAAe,SAASnB,GAAS;AAAA,QACxC,YAAYmB,GAAe,cAAcnB,GAAS;AAAA,QAClD,WAAWmB,GAAe,aAAanB,GAAS;AAAA,QAChD,SAASmB,GAAe,WAAWnB,GAAS;AAAA,MAAA;AAG9C,MAAAY,EAAQC,GAAMC,CAAc;AAAA,IAAA;AAAA,IAkB5B,aAfkB,OAAOD,GAAYM,MAA6C;AAClF,YAAML,IAAiB;AAAA,QACrB,OAAOK,GAAe,SAASnB,GAAS;AAAA,QACxC,YAAYmB,GAAe,cAAcnB,GAAS;AAAA,QAClD,WAAWmB,GAAe,aAAanB,GAAS;AAAA,QAChD,SAASmB,GAAe,WAAWnB,GAAS;AAAA,MAAA;AAG9C,aAAOY,EAAQC,GAAMC,CAAc;AAAA,IAAA;AAAA,IAQnC,WAAAb;AAAA,IACA,SAAAG;AAAA,IACA,WAAAE;AAAA,EAAA;AAEJ;"}
@@ -2,27 +2,27 @@ import { useState as a, useRef as b, useEffect as v } from "react";
2
2
  import { useRefState as R } from "../useRefState/useRefState.mjs";
3
3
  import { isTarget as O } from "../../utils/helpers/isTarget.mjs";
4
4
  import { getElement as g } from "../../utils/helpers/getElement.mjs";
5
- const S = (...t) => {
6
- const e = O(t[0]) ? t[0] : void 0, s = e ? t[1] : t[0], n = e ? t[2] : t[1], [r, d] = a(), m = (n == null ? void 0 : n.enabled) ?? !0, o = R(window.document.documentElement), u = b(s);
5
+ const M = (...t) => {
6
+ const e = O(t[0]) ? t[0] : void 0, s = e ? t[1] : t[0], r = e ? t[2] : t[1], [o, d] = a(), m = r?.enabled ?? !0, n = R(window.document.documentElement), u = b(s);
7
7
  u.current = s;
8
- const i = b(n);
9
- i.current = n, v(() => {
10
- if (!m && !e && !o.state) return;
11
- const l = e ? g(e) : o.current;
8
+ const i = b(r);
9
+ i.current = r, v(() => {
10
+ if (!m || !e && !n.state) return;
11
+ const l = e ? g(e) : n.current;
12
12
  if (!l) return;
13
13
  const c = new MutationObserver(u.current);
14
14
  return d(c), c.observe(l, i.current), () => {
15
15
  c.disconnect();
16
16
  };
17
- }, [e, o.state]);
18
- const f = () => r == null ? void 0 : r.disconnect();
19
- return e ? { stop: f, observer: r } : {
20
- ref: o,
17
+ }, [e, n.state]);
18
+ const f = () => o?.disconnect();
19
+ return e ? { stop: f, observer: o } : {
20
+ ref: n,
21
21
  stop: f,
22
- observer: r
22
+ observer: o
23
23
  };
24
24
  };
25
25
  export {
26
- S as useMutationObserver
26
+ M as useMutationObserver
27
27
  };
28
28
  //# sourceMappingURL=useMutationObserver.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"useMutationObserver.mjs","sources":["../../../../src/hooks/useMutationObserver/useMutationObserver.ts"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\n\nimport type { HookTarget } from '@/utils/helpers';\n\nimport { getElement, isTarget } from '@/utils/helpers';\n\nimport type { StateRef } from '../useRefState/useRefState';\n\nimport { useRefState } from '../useRefState/useRefState';\n\n/** The mutation observer target element type */\nexport type UseMutationObserverTarget = HookTarget;\n\n/** The mutation observer return type */\nexport interface UseMutationObserverReturn {\n /** The mutation observer instance */\n observer: MutationObserver;\n /** The mutation observer entries */\n stop: () => void;\n}\n\n/** The mutation observer options type */\nexport interface UseMutationObserverOptions extends MutationObserverInit {\n /** The enabled state of the mutation observer */\n enabled?: boolean;\n}\n\nexport interface UseMutationObserver {\n (\n target: HookTarget,\n callback: MutationCallback,\n options?: UseMutationObserverOptions\n ): UseMutationObserverReturn;\n\n <Target extends Element>(\n callback: MutationCallback,\n options?: UseMutationObserverOptions,\n target?: never\n ): UseMutationObserverReturn & { ref: StateRef<Target> };\n}\n\n/**\n * @name useMutationObserver\n * @description - Hook that gives you mutation observer state\n * @category Browser\n *\n * @overload\n * @template Target The target element\n * @param {MutationCallback} callback The callback to execute when mutation is detected\n * @param {boolean} [options.enabled=true] The enabled state of the mutation observer\n * @param {boolean} [options.attributes] Set to true if mutations to target's attributes are to be observed\n * @param {boolean} [options.characterData] Set to true if mutations to target's data are to be observed\n * @param {boolean} [options.childList] Set to true if mutations to target's children are to be observed\n * @param {boolean} [options.subtree] Set to true if mutations to not just target, but also target's descendants are to be observed\n * @param {boolean} [options.characterDataOldValue] Set to true if characterData is set to true or omitted and target's data before the mutation needs to be recorded\n * @param {boolean} [options.attributeOldValue] Set to a list of attribute local names (without namespace) if not all attribute mutations need to be observed and attributes is true or omitted\n * @param {string[]} [options.attributeFilter] Set to a list of attribute local names (without namespace) if not all attribute mutations need to be observed and attributes is true or omitted\n * @returns {UseMutationObserverReturn & { ref: StateRef<Target> }} An object containing the mutation observer state\n *\n * @example\n * const { ref, observer, stop } = useMutationObserver(() => console.log('callback'))\n *\n * @overload\n * @param {HookTarget} target The target element to observe\n * @param {MutationCallback} callback The callback to execute when mutation is detected\n * @param {boolean} [options.enabled=true] The enabled state of the mutation observer\n * @param {boolean} [options.attributes] Set to true if mutations to target's attributes are to be observed\n * @param {boolean} [options.characterData] Set to true if mutations to target's data are to be observed\n * @param {boolean} [options.childList] Set to true if mutations to target's children are to be observed\n * @param {boolean} [options.subtree] Set to true if mutations to not just target, but also target's descendants are to be observed\n * @param {boolean} [options.characterDataOldValue] Set to true if characterData is set to true or omitted and target's data before the mutation needs to be recorded\n * @param {boolean} [options.attributeOldValue] Set to a list of attribute local names (without namespace) if not all attribute mutations need to be observed and attributes is true or omitted\n * @param {string[]} [options.attributeFilter] Set to a list of attribute local names (without namespace) if not all attribute mutations need to be observed and attributes is true or omitted\n * @returns {UseMutationObserverReturn} An object containing the mutation observer state\n *\n * @example\n * const { observer, stop } = useMutationObserver(ref, () => console.log('callback'))\n */\nexport const useMutationObserver = ((...params: any[]) => {\n const target = (isTarget(params[0]) ? params[0] : undefined) as HookTarget | undefined;\n const callback = (target ? params[1] : params[0]) as MutationCallback;\n const options = (target ? params[2] : params[1]) as UseMutationObserverOptions | undefined;\n\n const [observer, setObserver] = useState<MutationObserver>();\n const enabled = options?.enabled ?? true;\n\n const internalRef = useRefState<Element>(window.document.documentElement);\n const internalCallbackRef = useRef<MutationCallback>(callback);\n internalCallbackRef.current = callback;\n const internalOptionsRef = useRef(options);\n internalOptionsRef.current = options;\n\n useEffect(() => {\n if (!enabled && !target && !internalRef.state) return;\n\n const element = (target ? getElement(target) : internalRef.current) as Element;\n if (!element) return;\n\n const observer = new MutationObserver(internalCallbackRef.current);\n setObserver(observer);\n observer.observe(element, internalOptionsRef.current);\n\n return () => {\n observer.disconnect();\n };\n }, [target, internalRef.state]);\n\n const stop = () => observer?.disconnect();\n\n if (target) return { stop, observer };\n return {\n ref: internalRef,\n stop,\n observer\n };\n}) as UseMutationObserver;\n"],"names":["useMutationObserver","params","target","isTarget","callback","options","observer","setObserver","useState","enabled","internalRef","useRefState","internalCallbackRef","useRef","internalOptionsRef","useEffect","element","getElement","stop"],"mappings":";;;;AA8Ea,MAAAA,IAAuB,IAAIC,MAAkB;AAClD,QAAAC,IAAUC,EAASF,EAAO,CAAC,CAAC,IAAIA,EAAO,CAAC,IAAI,QAC5CG,IAAYF,IAASD,EAAO,CAAC,IAAIA,EAAO,CAAC,GACzCI,IAAWH,IAASD,EAAO,CAAC,IAAIA,EAAO,CAAC,GAExC,CAACK,GAAUC,CAAW,IAAIC,EAA2B,GACrDC,KAAUJ,KAAA,gBAAAA,EAAS,YAAW,IAE9BK,IAAcC,EAAqB,OAAO,SAAS,eAAe,GAClEC,IAAsBC,EAAyBT,CAAQ;AAC7D,EAAAQ,EAAoB,UAAUR;AACxB,QAAAU,IAAqBD,EAAOR,CAAO;AACzC,EAAAS,EAAmB,UAAUT,GAE7BU,EAAU,MAAM;AACd,QAAI,CAACN,KAAW,CAACP,KAAU,CAACQ,EAAY,MAAO;AAE/C,UAAMM,IAAWd,IAASe,EAAWf,CAAM,IAAIQ,EAAY;AAC3D,QAAI,CAACM,EAAS;AAEd,UAAMV,IAAW,IAAI,iBAAiBM,EAAoB,OAAO;AACjE,WAAAL,EAAYD,CAAQ,GACpBA,EAAS,QAAQU,GAASF,EAAmB,OAAO,GAE7C,MAAM;AACXR,MAAAA,EAAS,WAAW;AAAA,IACtB;AAAA,EACC,GAAA,CAACJ,GAAQQ,EAAY,KAAK,CAAC;AAExB,QAAAQ,IAAO,MAAMZ,KAAA,gBAAAA,EAAU;AAE7B,SAAIJ,IAAe,EAAE,MAAAgB,GAAM,UAAAZ,EAAS,IAC7B;AAAA,IACL,KAAKI;AAAA,IACL,MAAAQ;AAAA,IACA,UAAAZ;AAAA,EACF;AACF;"}
1
+ {"version":3,"file":"useMutationObserver.mjs","sources":["../../../../src/hooks/useMutationObserver/useMutationObserver.ts"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\n\nimport type { HookTarget } from '@/utils/helpers';\n\nimport { getElement, isTarget } from '@/utils/helpers';\n\nimport type { StateRef } from '../useRefState/useRefState';\n\nimport { useRefState } from '../useRefState/useRefState';\n\n/** The mutation observer target element type */\nexport type UseMutationObserverTarget = HookTarget;\n\n/** The mutation observer return type */\nexport interface UseMutationObserverReturn {\n /** The mutation observer instance */\n observer: MutationObserver;\n /** The mutation observer entries */\n stop: () => void;\n}\n\n/** The mutation observer options type */\nexport interface UseMutationObserverOptions extends MutationObserverInit {\n /** The enabled state of the mutation observer */\n enabled?: boolean;\n}\n\nexport interface UseMutationObserver {\n (\n target: HookTarget,\n callback: MutationCallback,\n options?: UseMutationObserverOptions\n ): UseMutationObserverReturn;\n\n <Target extends Element>(\n callback: MutationCallback,\n options?: UseMutationObserverOptions,\n target?: never\n ): UseMutationObserverReturn & { ref: StateRef<Target> };\n}\n\n/**\n * @name useMutationObserver\n * @description - Hook that gives you mutation observer state\n * @category Browser\n *\n * @overload\n * @template Target The target element\n * @param {MutationCallback} callback The callback to execute when mutation is detected\n * @param {boolean} [options.enabled=true] The enabled state of the mutation observer\n * @param {boolean} [options.attributes] Set to true if mutations to target's attributes are to be observed\n * @param {boolean} [options.characterData] Set to true if mutations to target's data are to be observed\n * @param {boolean} [options.childList] Set to true if mutations to target's children are to be observed\n * @param {boolean} [options.subtree] Set to true if mutations to not just target, but also target's descendants are to be observed\n * @param {boolean} [options.characterDataOldValue] Set to true if characterData is set to true or omitted and target's data before the mutation needs to be recorded\n * @param {boolean} [options.attributeOldValue] Set to a list of attribute local names (without namespace) if not all attribute mutations need to be observed and attributes is true or omitted\n * @param {string[]} [options.attributeFilter] Set to a list of attribute local names (without namespace) if not all attribute mutations need to be observed and attributes is true or omitted\n * @returns {UseMutationObserverReturn & { ref: StateRef<Target> }} An object containing the mutation observer state\n *\n * @example\n * const { ref, observer, stop } = useMutationObserver(() => console.log('callback'))\n *\n * @overload\n * @param {HookTarget} target The target element to observe\n * @param {MutationCallback} callback The callback to execute when mutation is detected\n * @param {boolean} [options.enabled=true] The enabled state of the mutation observer\n * @param {boolean} [options.attributes] Set to true if mutations to target's attributes are to be observed\n * @param {boolean} [options.characterData] Set to true if mutations to target's data are to be observed\n * @param {boolean} [options.childList] Set to true if mutations to target's children are to be observed\n * @param {boolean} [options.subtree] Set to true if mutations to not just target, but also target's descendants are to be observed\n * @param {boolean} [options.characterDataOldValue] Set to true if characterData is set to true or omitted and target's data before the mutation needs to be recorded\n * @param {boolean} [options.attributeOldValue] Set to a list of attribute local names (without namespace) if not all attribute mutations need to be observed and attributes is true or omitted\n * @param {string[]} [options.attributeFilter] Set to a list of attribute local names (without namespace) if not all attribute mutations need to be observed and attributes is true or omitted\n * @returns {UseMutationObserverReturn} An object containing the mutation observer state\n *\n * @example\n * const { observer, stop } = useMutationObserver(ref, () => console.log('callback'))\n */\nexport const useMutationObserver = ((...params: any[]) => {\n const target = (isTarget(params[0]) ? params[0] : undefined) as HookTarget | undefined;\n const callback = (target ? params[1] : params[0]) as MutationCallback;\n const options = (target ? params[2] : params[1]) as UseMutationObserverOptions | undefined;\n\n const [observer, setObserver] = useState<MutationObserver>();\n const enabled = options?.enabled ?? true;\n\n const internalRef = useRefState<Element>(window.document.documentElement);\n const internalCallbackRef = useRef<MutationCallback>(callback);\n internalCallbackRef.current = callback;\n const internalOptionsRef = useRef(options);\n internalOptionsRef.current = options;\n\n useEffect(() => {\n if (!enabled || (!target && !internalRef.state)) return;\n\n const element = (target ? getElement(target) : internalRef.current) as Element;\n if (!element) return;\n\n const observer = new MutationObserver(internalCallbackRef.current);\n setObserver(observer);\n observer.observe(element, internalOptionsRef.current);\n\n return () => {\n observer.disconnect();\n };\n }, [target, internalRef.state]);\n\n const stop = () => observer?.disconnect();\n\n if (target) return { stop, observer };\n return {\n ref: internalRef,\n stop,\n observer\n };\n}) as UseMutationObserver;\n"],"names":["useMutationObserver","params","target","isTarget","callback","options","observer","setObserver","useState","enabled","internalRef","useRefState","internalCallbackRef","useRef","internalOptionsRef","useEffect","element","getElement","stop"],"mappings":";;;;AA8EO,MAAMA,IAAuB,IAAIC,MAAkB;AACxD,QAAMC,IAAUC,EAASF,EAAO,CAAC,CAAC,IAAIA,EAAO,CAAC,IAAI,QAC5CG,IAAYF,IAASD,EAAO,CAAC,IAAIA,EAAO,CAAC,GACzCI,IAAWH,IAASD,EAAO,CAAC,IAAIA,EAAO,CAAC,GAExC,CAACK,GAAUC,CAAW,IAAIC,EAAA,GAC1BC,IAAUJ,GAAS,WAAW,IAE9BK,IAAcC,EAAqB,OAAO,SAAS,eAAe,GAClEC,IAAsBC,EAAyBT,CAAQ;AAC7D,EAAAQ,EAAoB,UAAUR;AAC9B,QAAMU,IAAqBD,EAAOR,CAAO;AACzC,EAAAS,EAAmB,UAAUT,GAE7BU,EAAU,MAAM;AACd,QAAI,CAACN,KAAY,CAACP,KAAU,CAACQ,EAAY,MAAQ;AAEjD,UAAMM,IAAWd,IAASe,EAAWf,CAAM,IAAIQ,EAAY;AAC3D,QAAI,CAACM,EAAS;AAEd,UAAMV,IAAW,IAAI,iBAAiBM,EAAoB,OAAO;AACjE,WAAAL,EAAYD,CAAQ,GACpBA,EAAS,QAAQU,GAASF,EAAmB,OAAO,GAE7C,MAAM;AACXR,MAAAA,EAAS,WAAA;AAAA,IAAW;AAAA,EACtB,GACC,CAACJ,GAAQQ,EAAY,KAAK,CAAC;AAE9B,QAAMQ,IAAO,MAAMZ,GAAU,WAAA;AAE7B,SAAIJ,IAAe,EAAE,MAAAgB,GAAM,UAAAZ,EAAA,IACpB;AAAA,IACL,KAAKI;AAAA,IACL,MAAAQ;AAAA,IACA,UAAAZ;AAAA,EAAA;AAEJ;"}
@@ -1,6 +1,6 @@
1
- import { useState as d, useEffect as f } from "react";
2
- const r = () => (navigator == null ? void 0 : navigator.connection) || (navigator == null ? void 0 : navigator.mozConnection) || (navigator == null ? void 0 : navigator.webkitConnection), l = () => {
3
- const [i, s] = d(() => {
1
+ import { useState as s, useEffect as v } from "react";
2
+ const o = () => navigator?.connection || navigator?.mozConnection || navigator?.webkitConnection, d = () => {
3
+ const [i, a] = s(() => {
4
4
  if (typeof navigator > "u")
5
5
  return {
6
6
  online: !1,
@@ -11,39 +11,39 @@ const r = () => (navigator == null ? void 0 : navigator.connection) || (navigato
11
11
  downlinkMax: 0,
12
12
  rtt: 0
13
13
  };
14
- const a = navigator.onLine, e = r();
14
+ const n = navigator.onLine, e = o();
15
15
  return {
16
- online: a,
17
- downlink: e == null ? void 0 : e.downlink,
18
- downlinkMax: e == null ? void 0 : e.downlinkMax,
19
- effectiveType: e == null ? void 0 : e.effectiveType,
20
- rtt: e == null ? void 0 : e.rtt,
21
- saveData: e == null ? void 0 : e.saveData,
22
- type: e == null ? void 0 : e.type
16
+ online: n,
17
+ downlink: e?.downlink,
18
+ downlinkMax: e?.downlinkMax,
19
+ effectiveType: e?.effectiveType,
20
+ rtt: e?.rtt,
21
+ saveData: e?.saveData,
22
+ type: e?.type
23
23
  };
24
24
  });
25
- return f(() => {
26
- const a = () => {
27
- const v = navigator.onLine, t = r();
28
- s({
29
- online: v,
30
- downlink: t == null ? void 0 : t.downlink,
31
- downlinkMax: t == null ? void 0 : t.downlinkMax,
32
- effectiveType: t == null ? void 0 : t.effectiveType,
33
- rtt: t == null ? void 0 : t.rtt,
34
- saveData: t == null ? void 0 : t.saveData,
35
- type: t == null ? void 0 : t.type
25
+ return v(() => {
26
+ const n = () => {
27
+ const r = navigator.onLine, t = o();
28
+ a({
29
+ online: r,
30
+ downlink: t?.downlink,
31
+ downlinkMax: t?.downlinkMax,
32
+ effectiveType: t?.effectiveType,
33
+ rtt: t?.rtt,
34
+ saveData: t?.saveData,
35
+ type: t?.type
36
36
  });
37
37
  };
38
- window.addEventListener("online", a, { passive: !0 }), window.addEventListener("offline", a, { passive: !0 });
39
- const e = r();
40
- return e && e.addEventListener("change", a, { passive: !0 }), () => {
41
- window.removeEventListener("online", a), window.removeEventListener("offline", a), e && e.removeEventListener("change", a);
38
+ window.addEventListener("online", n, { passive: !0 }), window.addEventListener("offline", n, { passive: !0 });
39
+ const e = o();
40
+ return e && e.addEventListener("change", n, { passive: !0 }), () => {
41
+ window.removeEventListener("online", n), window.removeEventListener("offline", n), e && e.removeEventListener("change", n);
42
42
  };
43
43
  }), i;
44
44
  };
45
45
  export {
46
- r as getConnection,
47
- l as useNetwork
46
+ o as getConnection,
47
+ d as useNetwork
48
48
  };
49
49
  //# sourceMappingURL=useNetwork.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"useNetwork.mjs","sources":["../../../../src/hooks/useNetwork/useNetwork.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\nexport interface Connection extends EventTarget {\n readonly downlink: number;\n readonly downlinkMax: number;\n readonly effectiveType: '2g' | '3g' | '4g' | 'slow-2g';\n readonly rtt: number;\n readonly saveData: boolean;\n onChange: (event: Event) => void;\n readonly type:\n | 'bluetooth'\n | 'cellular'\n | 'ethernet'\n | 'mixed'\n | 'none'\n | 'other'\n | 'unknown'\n | 'wifi'\n | 'wimax';\n}\n\ndeclare global {\n interface Navigator {\n readonly connection: Connection;\n readonly mozConnection: Connection;\n readonly webkitConnection: Connection;\n }\n}\n\n/** The type of network connection */\nexport type ConnectionType = Connection['type'];\n/** The effective type of connection */\nexport type ConnectionEffectiveType = Connection['effectiveType'];\n\n/** The use network return type */\nexport interface UseNetworkReturn {\n /** The estimated downlink speed in megabits per seconds */\n downlink?: Connection['downlink'];\n /** The maximum downlink speed, if available */\n downlinkMax?: Connection['downlinkMax'];\n /** The effective type of connection (e.g., '2g', '3g', '4g') */\n effectiveType?: Connection['effectiveType'];\n /** Indicates if the device is currently online */\n online: boolean;\n /** The estimated round-trip time in milliseconds */\n rtt?: Connection['rtt'];\n /** Indicates if the user has enabled data saving mode */\n saveData?: Connection['saveData'];\n /** The type of network connection (e.g., 'wifi', 'cellular') */\n type?: Connection['type'];\n}\n\nexport const getConnection = () =>\n navigator?.connection || navigator?.mozConnection || navigator?.webkitConnection;\n\n/**\n * @name useNetwork\n * @description - Hook to track network status\n * @category Sensors\n *\n * @browserapi navigator.connection https://developer.mozilla.org/en-US/docs/Web/API/Navigator/connection\n *\n * @returns {UseNetworkReturn} An object containing the network status\n *\n * @example\n * const { online, downlink, downlinkMax, effectiveType, rtt, saveData, type } = useNetwork();\n */\nexport const useNetwork = (): UseNetworkReturn => {\n const [value, setValue] = useState(() => {\n if (typeof navigator === 'undefined') {\n return {\n online: false,\n type: undefined,\n effectiveType: undefined,\n saveData: false,\n downlink: 0,\n downlinkMax: 0,\n rtt: 0\n };\n }\n const online = navigator.onLine;\n const connection = getConnection();\n\n return {\n online,\n downlink: connection?.downlink,\n downlinkMax: connection?.downlinkMax,\n effectiveType: connection?.effectiveType,\n rtt: connection?.rtt,\n saveData: connection?.saveData,\n type: connection?.type\n };\n });\n\n useEffect(() => {\n const callback = () => {\n const online = navigator.onLine;\n const connection = getConnection();\n\n setValue({\n online,\n downlink: connection?.downlink,\n downlinkMax: connection?.downlinkMax,\n effectiveType: connection?.effectiveType,\n rtt: connection?.rtt,\n saveData: connection?.saveData,\n type: connection?.type\n });\n };\n window.addEventListener('online', callback, { passive: true });\n window.addEventListener('offline', callback, { passive: true });\n\n const connection = getConnection();\n\n if (connection) {\n connection.addEventListener('change', callback, { passive: true });\n }\n\n return () => {\n window.removeEventListener('online', callback);\n window.removeEventListener('offline', callback);\n\n if (connection) {\n connection.removeEventListener('change', callback);\n }\n };\n });\n\n return value;\n};\n"],"names":["getConnection","useNetwork","value","setValue","useState","online","connection","useEffect","callback"],"mappings":";AAoDO,MAAMA,IAAgB,OAC3B,uCAAW,gBAAc,uCAAW,mBAAiB,uCAAW,mBAcrDC,IAAa,MAAwB;AAChD,QAAM,CAACC,GAAOC,CAAQ,IAAIC,EAAS,MAAM;AACnC,QAAA,OAAO,YAAc;AAChB,aAAA;AAAA,QACL,QAAQ;AAAA,QACR,MAAM;AAAA,QACN,eAAe;AAAA,QACf,UAAU;AAAA,QACV,UAAU;AAAA,QACV,aAAa;AAAA,QACb,KAAK;AAAA,MACP;AAEF,UAAMC,IAAS,UAAU,QACnBC,IAAaN,EAAc;AAE1B,WAAA;AAAA,MACL,QAAAK;AAAA,MACA,UAAUC,KAAA,gBAAAA,EAAY;AAAA,MACtB,aAAaA,KAAA,gBAAAA,EAAY;AAAA,MACzB,eAAeA,KAAA,gBAAAA,EAAY;AAAA,MAC3B,KAAKA,KAAA,gBAAAA,EAAY;AAAA,MACjB,UAAUA,KAAA,gBAAAA,EAAY;AAAA,MACtB,MAAMA,KAAA,gBAAAA,EAAY;AAAA,IACpB;AAAA,EAAA,CACD;AAED,SAAAC,EAAU,MAAM;AACd,UAAMC,IAAW,MAAM;AACrB,YAAMH,IAAS,UAAU,QACnBC,IAAaN,EAAc;AAExB,MAAAG,EAAA;AAAA,QACP,QAAAE;AAAA,QACA,UAAUC,KAAAA,gBAAAA,EAAY;AAAA,QACtB,aAAaA,KAAAA,gBAAAA,EAAY;AAAA,QACzB,eAAeA,KAAAA,gBAAAA,EAAY;AAAA,QAC3B,KAAKA,KAAAA,gBAAAA,EAAY;AAAA,QACjB,UAAUA,KAAAA,gBAAAA,EAAY;AAAA,QACtB,MAAMA,KAAAA,gBAAAA,EAAY;AAAA,MAAA,CACnB;AAAA,IACH;AACA,WAAO,iBAAiB,UAAUE,GAAU,EAAE,SAAS,IAAM,GAC7D,OAAO,iBAAiB,WAAWA,GAAU,EAAE,SAAS,IAAM;AAE9D,UAAMF,IAAaN,EAAc;AAEjC,WAAIM,KACFA,EAAW,iBAAiB,UAAUE,GAAU,EAAE,SAAS,IAAM,GAG5D,MAAM;AACJ,aAAA,oBAAoB,UAAUA,CAAQ,GACtC,OAAA,oBAAoB,WAAWA,CAAQ,GAE1CF,KACSA,EAAA,oBAAoB,UAAUE,CAAQ;AAAA,IAErD;AAAA,EAAA,CACD,GAEMN;AACT;"}
1
+ {"version":3,"file":"useNetwork.mjs","sources":["../../../../src/hooks/useNetwork/useNetwork.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\nexport interface Connection extends EventTarget {\n readonly downlink: number;\n readonly downlinkMax: number;\n readonly effectiveType: '2g' | '3g' | '4g' | 'slow-2g';\n readonly rtt: number;\n readonly saveData: boolean;\n onChange: (event: Event) => void;\n readonly type:\n | 'bluetooth'\n | 'cellular'\n | 'ethernet'\n | 'mixed'\n | 'none'\n | 'other'\n | 'unknown'\n | 'wifi'\n | 'wimax';\n}\n\ndeclare global {\n interface Navigator {\n readonly connection: Connection;\n readonly mozConnection: Connection;\n readonly webkitConnection: Connection;\n }\n}\n\n/** The type of network connection */\nexport type ConnectionType = Connection['type'];\n/** The effective type of connection */\nexport type ConnectionEffectiveType = Connection['effectiveType'];\n\n/** The use network return type */\nexport interface UseNetworkReturn {\n /** The estimated downlink speed in megabits per seconds */\n downlink?: Connection['downlink'];\n /** The maximum downlink speed, if available */\n downlinkMax?: Connection['downlinkMax'];\n /** The effective type of connection (e.g., '2g', '3g', '4g') */\n effectiveType?: Connection['effectiveType'];\n /** Indicates if the device is currently online */\n online: boolean;\n /** The estimated round-trip time in milliseconds */\n rtt?: Connection['rtt'];\n /** Indicates if the user has enabled data saving mode */\n saveData?: Connection['saveData'];\n /** The type of network connection (e.g., 'wifi', 'cellular') */\n type?: Connection['type'];\n}\n\nexport const getConnection = () =>\n navigator?.connection || navigator?.mozConnection || navigator?.webkitConnection;\n\n/**\n * @name useNetwork\n * @description - Hook to track network status\n * @category Sensors\n *\n * @browserapi navigator.connection https://developer.mozilla.org/en-US/docs/Web/API/Navigator/connection\n *\n * @returns {UseNetworkReturn} An object containing the network status\n *\n * @example\n * const { online, downlink, downlinkMax, effectiveType, rtt, saveData, type } = useNetwork();\n */\nexport const useNetwork = (): UseNetworkReturn => {\n const [value, setValue] = useState(() => {\n if (typeof navigator === 'undefined') {\n return {\n online: false,\n type: undefined,\n effectiveType: undefined,\n saveData: false,\n downlink: 0,\n downlinkMax: 0,\n rtt: 0\n };\n }\n const online = navigator.onLine;\n const connection = getConnection();\n\n return {\n online,\n downlink: connection?.downlink,\n downlinkMax: connection?.downlinkMax,\n effectiveType: connection?.effectiveType,\n rtt: connection?.rtt,\n saveData: connection?.saveData,\n type: connection?.type\n };\n });\n\n useEffect(() => {\n const callback = () => {\n const online = navigator.onLine;\n const connection = getConnection();\n\n setValue({\n online,\n downlink: connection?.downlink,\n downlinkMax: connection?.downlinkMax,\n effectiveType: connection?.effectiveType,\n rtt: connection?.rtt,\n saveData: connection?.saveData,\n type: connection?.type\n });\n };\n window.addEventListener('online', callback, { passive: true });\n window.addEventListener('offline', callback, { passive: true });\n\n const connection = getConnection();\n\n if (connection) {\n connection.addEventListener('change', callback, { passive: true });\n }\n\n return () => {\n window.removeEventListener('online', callback);\n window.removeEventListener('offline', callback);\n\n if (connection) {\n connection.removeEventListener('change', callback);\n }\n };\n });\n\n return value;\n};\n"],"names":["getConnection","useNetwork","value","setValue","useState","online","connection","useEffect","callback"],"mappings":";AAoDO,MAAMA,IAAgB,MAC3B,WAAW,cAAc,WAAW,iBAAiB,WAAW,kBAcrDC,IAAa,MAAwB;AAChD,QAAM,CAACC,GAAOC,CAAQ,IAAIC,EAAS,MAAM;AACvC,QAAI,OAAO,YAAc;AACvB,aAAO;AAAA,QACL,QAAQ;AAAA,QACR,MAAM;AAAA,QACN,eAAe;AAAA,QACf,UAAU;AAAA,QACV,UAAU;AAAA,QACV,aAAa;AAAA,QACb,KAAK;AAAA,MAAA;AAGT,UAAMC,IAAS,UAAU,QACnBC,IAAaN,EAAA;AAEnB,WAAO;AAAA,MACL,QAAAK;AAAA,MACA,UAAUC,GAAY;AAAA,MACtB,aAAaA,GAAY;AAAA,MACzB,eAAeA,GAAY;AAAA,MAC3B,KAAKA,GAAY;AAAA,MACjB,UAAUA,GAAY;AAAA,MACtB,MAAMA,GAAY;AAAA,IAAA;AAAA,EACpB,CACD;AAED,SAAAC,EAAU,MAAM;AACd,UAAMC,IAAW,MAAM;AACrB,YAAMH,IAAS,UAAU,QACnBC,IAAaN,EAAA;AAEnB,MAAAG,EAAS;AAAA,QACP,QAAAE;AAAA,QACA,UAAUC,GAAY;AAAA,QACtB,aAAaA,GAAY;AAAA,QACzB,eAAeA,GAAY;AAAA,QAC3B,KAAKA,GAAY;AAAA,QACjB,UAAUA,GAAY;AAAA,QACtB,MAAMA,GAAY;AAAA,MAAA,CACnB;AAAA,IAAA;AAEH,WAAO,iBAAiB,UAAUE,GAAU,EAAE,SAAS,IAAM,GAC7D,OAAO,iBAAiB,WAAWA,GAAU,EAAE,SAAS,IAAM;AAE9D,UAAMF,IAAaN,EAAA;AAEnB,WAAIM,KACFA,EAAW,iBAAiB,UAAUE,GAAU,EAAE,SAAS,IAAM,GAG5D,MAAM;AACX,aAAO,oBAAoB,UAAUA,CAAQ,GAC7C,OAAO,oBAAoB,WAAWA,CAAQ,GAE1CF,KACFA,EAAW,oBAAoB,UAAUE,CAAQ;AAAA,IACnD;AAAA,EACF,CACD,GAEMN;AACT;"}
@@ -1 +1 @@
1
- {"version":3,"file":"useOffsetPagination.mjs","sources":["../../../../src/hooks/useOffsetPagination/useOffsetPagination.ts"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\n\n/** The use offset pagination return type */\nexport interface UseOffsetPaginationOptions {\n /** The initial page number */\n initialPage?: number;\n /** The number of items per page */\n pageSize?: number;\n /** The total number of items */\n total?: number;\n /** The callback function to be invoked when page changes */\n onPageChange?: ({ page, pageSize }: { page: number; pageSize: number }) => void;\n /** The callback function to be invoked when page count changes */\n onPageCountChange?: ({ page, pageSize }: { page: number; pageSize: number }) => void;\n /** The callback function to be invoked when page size changes */\n onPageSizeChange?: ({ page, pageSize }: { page: number; pageSize: number }) => void;\n}\n\n/** The use offset pagination return type */\nexport interface UseOffsetPaginationReturn {\n /** The number of items per page */\n currentPageSize: number;\n /** Whether the current page is the first page */\n isFirstPage: boolean;\n /** Whether the current page is the last page */\n isLastPage: boolean;\n /** The current page number */\n page: number;\n /** The total number of pages */\n pageCount: number;\n /** The callback function to go to the next page */\n next: () => void;\n /** The callback function to go to the previous page */\n prev: () => void;\n /** The callback function to set the current page */\n set: (page: number) => void;\n}\n\n/**\n * @name useOffsetPagination\n * @description - Hook that defines the logic when pagination\n * @category Utilities\n *\n * @param {UseOffsetPaginationOptions} options - The options for the hook\n * @param {number} [options.total] - The total number of items\n * @param {number} [options.pageSize] - The number of items per page\n * @param {number} [options.initialPage] - The current page\n * @param {({ page, pageSize }: { page: number; pageSize: number }) => void} [options.onPageChange] - The callback function to be invoked when page changes\n * @param {({ page, pageSize }: { page: number; pageSize: number }) => void} [options.onPageCountChange] - The callback function to be invoked when page count changes\n * @param {({ page, pageSize }: { page: number; pageSize: number }) => void} [options.onPageSizeChange] - The callback function to be invoked when page size changes\n * @returns {UseOffsetPaginationReturn} - The state of the hook\n *\n * @example\n * const { currentPage, currentPageSize, pageCount, isFirstPage, isLastPage, prev, next } = useOffsetPagination({\n * total: 100,\n * pageSize: 10,\n * page: 1,\n * onPageChange: (page) => {},\n * onPageCountChange: (pageCount) => {},\n * onPageSizeChange: (pageSize) => {}\n * });\n */\nexport const useOffsetPagination = ({\n total = Number.POSITIVE_INFINITY,\n pageSize = 10,\n initialPage = 1,\n onPageChange = () => {},\n onPageCountChange = () => {},\n onPageSizeChange = () => {}\n}: UseOffsetPaginationOptions = {}): UseOffsetPaginationReturn => {\n const [page, setPage] = useState(initialPage);\n\n const onPageChangeRef = useRef(onPageChange);\n const onPageCountChangeRef = useRef(onPageCountChange);\n const onPageSizeChangeRef = useRef(onPageSizeChange);\n\n onPageChangeRef.current = onPageChange;\n onPageCountChangeRef.current = onPageCountChange;\n onPageSizeChangeRef.current = onPageSizeChange;\n\n const pageCount = Math.max(1, Math.ceil(total / pageSize));\n\n const isFirstPage = page === 1;\n const isLastPage = page === pageCount;\n\n const next = () => {\n if (isLastPage) return onPageChange({ page: pageCount, pageSize });\n\n setPage((prevPage) => {\n const page = prevPage + 1;\n onPageChange({ page, pageSize });\n return page;\n });\n };\n\n const prev = () => {\n if (isFirstPage) return onPageChange({ page: 1, pageSize });\n\n setPage((prevPage) => {\n const page = prevPage - 1;\n onPageChange({ page, pageSize });\n return page;\n });\n };\n\n const set = (page: number) => {\n setPage(page);\n onPageChange({ page, pageSize });\n };\n\n useEffect(() => {\n onPageCountChangeRef.current({ page, pageSize });\n }, [pageCount]);\n\n useEffect(() => {\n onPageSizeChangeRef.current({ page, pageSize });\n }, [pageSize]);\n\n return {\n page,\n set,\n currentPageSize: pageSize,\n isFirstPage,\n isLastPage,\n pageCount,\n next,\n prev\n };\n};\n"],"names":["useOffsetPagination","total","pageSize","initialPage","onPageChange","onPageCountChange","onPageSizeChange","page","setPage","useState","onPageChangeRef","useRef","onPageCountChangeRef","onPageSizeChangeRef","pageCount","isFirstPage","isLastPage","next","prevPage","prev","set","useEffect"],"mappings":";AA8DO,MAAMA,IAAsB,CAAC;AAAA,EAClC,OAAAC,IAAQ,OAAO;AAAA,EACf,UAAAC,IAAW;AAAA,EACX,aAAAC,IAAc;AAAA,EACd,cAAAC,IAAe,MAAM;AAAA,EAAC;AAAA,EACtB,mBAAAC,IAAoB,MAAM;AAAA,EAAC;AAAA,EAC3B,kBAAAC,IAAmB,MAAM;AAAA,EAAA;AAC3B,IAAgC,OAAkC;AAChE,QAAM,CAACC,GAAMC,CAAO,IAAIC,EAASN,CAAW,GAEtCO,IAAkBC,EAAOP,CAAY,GACrCQ,IAAuBD,EAAON,CAAiB,GAC/CQ,IAAsBF,EAAOL,CAAgB;AAEnD,EAAAI,EAAgB,UAAUN,GAC1BQ,EAAqB,UAAUP,GAC/BQ,EAAoB,UAAUP;AAExB,QAAAQ,IAAY,KAAK,IAAI,GAAG,KAAK,KAAKb,IAAQC,CAAQ,CAAC,GAEnDa,IAAcR,MAAS,GACvBS,IAAaT,MAASO,GAEtBG,IAAO,MAAM;AACjB,QAAID,EAAmB,QAAAZ,EAAa,EAAE,MAAMU,GAAW,UAAAZ,GAAU;AAEjE,IAAAM,EAAQ,CAACU,MAAa;AACpB,YAAMX,IAAOW,IAAW;AACxB,aAAAd,EAAa,EAAE,MAAAG,GAAM,UAAAL,EAAA,CAAU,GACxBK;AAAAA,IAAA,CACR;AAAA,EACH,GAEMY,IAAO,MAAM;AACjB,QAAIJ,EAAoB,QAAAX,EAAa,EAAE,MAAM,GAAG,UAAAF,GAAU;AAE1D,IAAAM,EAAQ,CAACU,MAAa;AACpB,YAAMX,IAAOW,IAAW;AACxB,aAAAd,EAAa,EAAE,MAAAG,GAAM,UAAAL,EAAA,CAAU,GACxBK;AAAAA,IAAA,CACR;AAAA,EACH,GAEMa,IAAM,CAACb,MAAiB;AAC5B,IAAAC,EAAQD,CAAI,GACZH,EAAa,EAAE,MAAAG,GAAM,UAAAL,EAAA,CAAU;AAAA,EACjC;AAEA,SAAAmB,EAAU,MAAM;AACd,IAAAT,EAAqB,QAAQ,EAAE,MAAAL,GAAM,UAAAL,EAAA,CAAU;AAAA,EAAA,GAC9C,CAACY,CAAS,CAAC,GAEdO,EAAU,MAAM;AACd,IAAAR,EAAoB,QAAQ,EAAE,MAAAN,GAAM,UAAAL,EAAA,CAAU;AAAA,EAAA,GAC7C,CAACA,CAAQ,CAAC,GAEN;AAAA,IACL,MAAAK;AAAA,IACA,KAAAa;AAAA,IACA,iBAAiBlB;AAAA,IACjB,aAAAa;AAAA,IACA,YAAAC;AAAA,IACA,WAAAF;AAAA,IACA,MAAAG;AAAA,IACA,MAAAE;AAAA,EACF;AACF;"}
1
+ {"version":3,"file":"useOffsetPagination.mjs","sources":["../../../../src/hooks/useOffsetPagination/useOffsetPagination.ts"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\n\n/** The use offset pagination return type */\nexport interface UseOffsetPaginationOptions {\n /** The initial page number */\n initialPage?: number;\n /** The number of items per page */\n pageSize?: number;\n /** The total number of items */\n total?: number;\n /** The callback function to be invoked when page changes */\n onPageChange?: ({ page, pageSize }: { page: number; pageSize: number }) => void;\n /** The callback function to be invoked when page count changes */\n onPageCountChange?: ({ page, pageSize }: { page: number; pageSize: number }) => void;\n /** The callback function to be invoked when page size changes */\n onPageSizeChange?: ({ page, pageSize }: { page: number; pageSize: number }) => void;\n}\n\n/** The use offset pagination return type */\nexport interface UseOffsetPaginationReturn {\n /** The number of items per page */\n currentPageSize: number;\n /** Whether the current page is the first page */\n isFirstPage: boolean;\n /** Whether the current page is the last page */\n isLastPage: boolean;\n /** The current page number */\n page: number;\n /** The total number of pages */\n pageCount: number;\n /** The callback function to go to the next page */\n next: () => void;\n /** The callback function to go to the previous page */\n prev: () => void;\n /** The callback function to set the current page */\n set: (page: number) => void;\n}\n\n/**\n * @name useOffsetPagination\n * @description - Hook that defines the logic when pagination\n * @category Utilities\n *\n * @param {UseOffsetPaginationOptions} options - The options for the hook\n * @param {number} [options.total] - The total number of items\n * @param {number} [options.pageSize] - The number of items per page\n * @param {number} [options.initialPage] - The current page\n * @param {({ page, pageSize }: { page: number; pageSize: number }) => void} [options.onPageChange] - The callback function to be invoked when page changes\n * @param {({ page, pageSize }: { page: number; pageSize: number }) => void} [options.onPageCountChange] - The callback function to be invoked when page count changes\n * @param {({ page, pageSize }: { page: number; pageSize: number }) => void} [options.onPageSizeChange] - The callback function to be invoked when page size changes\n * @returns {UseOffsetPaginationReturn} - The state of the hook\n *\n * @example\n * const { currentPage, currentPageSize, pageCount, isFirstPage, isLastPage, prev, next } = useOffsetPagination({\n * total: 100,\n * pageSize: 10,\n * page: 1,\n * onPageChange: (page) => {},\n * onPageCountChange: (pageCount) => {},\n * onPageSizeChange: (pageSize) => {}\n * });\n */\nexport const useOffsetPagination = ({\n total = Number.POSITIVE_INFINITY,\n pageSize = 10,\n initialPage = 1,\n onPageChange = () => {},\n onPageCountChange = () => {},\n onPageSizeChange = () => {}\n}: UseOffsetPaginationOptions = {}): UseOffsetPaginationReturn => {\n const [page, setPage] = useState(initialPage);\n\n const onPageChangeRef = useRef(onPageChange);\n const onPageCountChangeRef = useRef(onPageCountChange);\n const onPageSizeChangeRef = useRef(onPageSizeChange);\n\n onPageChangeRef.current = onPageChange;\n onPageCountChangeRef.current = onPageCountChange;\n onPageSizeChangeRef.current = onPageSizeChange;\n\n const pageCount = Math.max(1, Math.ceil(total / pageSize));\n\n const isFirstPage = page === 1;\n const isLastPage = page === pageCount;\n\n const next = () => {\n if (isLastPage) return onPageChange({ page: pageCount, pageSize });\n\n setPage((prevPage) => {\n const page = prevPage + 1;\n onPageChange({ page, pageSize });\n return page;\n });\n };\n\n const prev = () => {\n if (isFirstPage) return onPageChange({ page: 1, pageSize });\n\n setPage((prevPage) => {\n const page = prevPage - 1;\n onPageChange({ page, pageSize });\n return page;\n });\n };\n\n const set = (page: number) => {\n setPage(page);\n onPageChange({ page, pageSize });\n };\n\n useEffect(() => {\n onPageCountChangeRef.current({ page, pageSize });\n }, [pageCount]);\n\n useEffect(() => {\n onPageSizeChangeRef.current({ page, pageSize });\n }, [pageSize]);\n\n return {\n page,\n set,\n currentPageSize: pageSize,\n isFirstPage,\n isLastPage,\n pageCount,\n next,\n prev\n };\n};\n"],"names":["useOffsetPagination","total","pageSize","initialPage","onPageChange","onPageCountChange","onPageSizeChange","page","setPage","useState","onPageChangeRef","useRef","onPageCountChangeRef","onPageSizeChangeRef","pageCount","isFirstPage","isLastPage","next","prevPage","prev","set","useEffect"],"mappings":";AA8DO,MAAMA,IAAsB,CAAC;AAAA,EAClC,OAAAC,IAAQ,OAAO;AAAA,EACf,UAAAC,IAAW;AAAA,EACX,aAAAC,IAAc;AAAA,EACd,cAAAC,IAAe,MAAM;AAAA,EAAA;AAAA,EACrB,mBAAAC,IAAoB,MAAM;AAAA,EAAA;AAAA,EAC1B,kBAAAC,IAAmB,MAAM;AAAA,EAAA;AAC3B,IAAgC,OAAkC;AAChE,QAAM,CAACC,GAAMC,CAAO,IAAIC,EAASN,CAAW,GAEtCO,IAAkBC,EAAOP,CAAY,GACrCQ,IAAuBD,EAAON,CAAiB,GAC/CQ,IAAsBF,EAAOL,CAAgB;AAEnD,EAAAI,EAAgB,UAAUN,GAC1BQ,EAAqB,UAAUP,GAC/BQ,EAAoB,UAAUP;AAE9B,QAAMQ,IAAY,KAAK,IAAI,GAAG,KAAK,KAAKb,IAAQC,CAAQ,CAAC,GAEnDa,IAAcR,MAAS,GACvBS,IAAaT,MAASO,GAEtBG,IAAO,MAAM;AACjB,QAAID,EAAY,QAAOZ,EAAa,EAAE,MAAMU,GAAW,UAAAZ,GAAU;AAEjE,IAAAM,EAAQ,CAACU,MAAa;AACpB,YAAMX,IAAOW,IAAW;AACxB,aAAAd,EAAa,EAAE,MAAAG,GAAM,UAAAL,EAAA,CAAU,GACxBK;AAAAA,IAAA,CACR;AAAA,EAAA,GAGGY,IAAO,MAAM;AACjB,QAAIJ,EAAa,QAAOX,EAAa,EAAE,MAAM,GAAG,UAAAF,GAAU;AAE1D,IAAAM,EAAQ,CAACU,MAAa;AACpB,YAAMX,IAAOW,IAAW;AACxB,aAAAd,EAAa,EAAE,MAAAG,GAAM,UAAAL,EAAA,CAAU,GACxBK;AAAAA,IAAA,CACR;AAAA,EAAA,GAGGa,IAAM,CAACb,MAAiB;AAC5B,IAAAC,EAAQD,CAAI,GACZH,EAAa,EAAE,MAAAG,GAAM,UAAAL,EAAA,CAAU;AAAA,EAAA;AAGjC,SAAAmB,EAAU,MAAM;AACd,IAAAT,EAAqB,QAAQ,EAAE,MAAAL,GAAM,UAAAL,EAAA,CAAU;AAAA,EAAA,GAC9C,CAACY,CAAS,CAAC,GAEdO,EAAU,MAAM;AACd,IAAAR,EAAoB,QAAQ,EAAE,MAAAN,GAAM,UAAAL,EAAA,CAAU;AAAA,EAAA,GAC7C,CAACA,CAAQ,CAAC,GAEN;AAAA,IACL,MAAAK;AAAA,IACA,KAAAa;AAAA,IACA,iBAAiBlB;AAAA,IACjB,aAAAa;AAAA,IACA,YAAAC;AAAA,IACA,WAAAF;AAAA,IACA,MAAAG;AAAA,IACA,MAAAE;AAAA,EAAA;AAEJ;"}
@@ -1 +1 @@
1
- {"version":3,"file":"useOnce.mjs","sources":["../../../../src/hooks/useOnce/useOnce.ts"],"sourcesContent":["import type { EffectCallback } from 'react';\n\nimport { useEffect, useRef } from 'react';\n\n/**\n * @name useEffectOnce\n * @description - Hook that runs an effect only once. Please do not use it in production code!\n * @category Humor\n *\n * @warning - This hook will run effect only once even in strict mode. Please do not use it in production code!\n *\n * @param {EffectCallback} effect The effect to run\n *\n * @example\n * useOnce(() => console.log('effect once'));\n */\nexport function useOnce(effect: EffectCallback) {\n const cleanupRef = useRef<ReturnType<EffectCallback>>(undefined);\n const hasRunRef = useRef(false);\n const hasRenderedAfterRun = useRef(false);\n\n if (hasRunRef.current) {\n hasRenderedAfterRun.current = true;\n }\n\n useEffect(() => {\n if (hasRunRef.current) return;\n\n hasRunRef.current = true;\n cleanupRef.current = effect();\n\n return () => {\n if (!hasRenderedAfterRun.current) return;\n\n if (typeof cleanupRef.current === 'function') {\n cleanupRef.current();\n }\n };\n }, []);\n}\n"],"names":["useOnce","effect","cleanupRef","useRef","hasRunRef","hasRenderedAfterRun","useEffect"],"mappings":";AAgBO,SAASA,EAAQC,GAAwB;AACxC,QAAAC,IAAaC,EAAmC,MAAS,GACzDC,IAAYD,EAAO,EAAK,GACxBE,IAAsBF,EAAO,EAAK;AAExC,EAAIC,EAAU,YACZC,EAAoB,UAAU,KAGhCC,EAAU,MAAM;AACd,QAAI,CAAAF,EAAU;AAEd,aAAAA,EAAU,UAAU,IACpBF,EAAW,UAAUD,EAAO,GAErB,MAAM;AACP,QAACI,EAAoB,WAErB,OAAOH,EAAW,WAAY,cAChCA,EAAW,QAAQ;AAAA,MAEvB;AAAA,EACF,GAAG,EAAE;AACP;"}
1
+ {"version":3,"file":"useOnce.mjs","sources":["../../../../src/hooks/useOnce/useOnce.ts"],"sourcesContent":["import type { EffectCallback } from 'react';\n\nimport { useEffect, useRef } from 'react';\n\n/**\n * @name useEffectOnce\n * @description - Hook that runs an effect only once. Please do not use it in production code!\n * @category Humor\n *\n * @warning - This hook will run effect only once even in strict mode. Please do not use it in production code!\n *\n * @param {EffectCallback} effect The effect to run\n *\n * @example\n * useOnce(() => console.log('effect once'));\n */\nexport function useOnce(effect: EffectCallback) {\n const cleanupRef = useRef<ReturnType<EffectCallback>>(undefined);\n const hasRunRef = useRef(false);\n const hasRenderedAfterRun = useRef(false);\n\n if (hasRunRef.current) {\n hasRenderedAfterRun.current = true;\n }\n\n useEffect(() => {\n if (hasRunRef.current) return;\n\n hasRunRef.current = true;\n cleanupRef.current = effect();\n\n return () => {\n if (!hasRenderedAfterRun.current) return;\n\n if (typeof cleanupRef.current === 'function') {\n cleanupRef.current();\n }\n };\n }, []);\n}\n"],"names":["useOnce","effect","cleanupRef","useRef","hasRunRef","hasRenderedAfterRun","useEffect"],"mappings":";AAgBO,SAASA,EAAQC,GAAwB;AAC9C,QAAMC,IAAaC,EAAmC,MAAS,GACzDC,IAAYD,EAAO,EAAK,GACxBE,IAAsBF,EAAO,EAAK;AAExC,EAAIC,EAAU,YACZC,EAAoB,UAAU,KAGhCC,EAAU,MAAM;AACd,QAAI,CAAAF,EAAU;AAEd,aAAAA,EAAU,UAAU,IACpBF,EAAW,UAAUD,EAAA,GAEd,MAAM;AACX,QAAKI,EAAoB,WAErB,OAAOH,EAAW,WAAY,cAChCA,EAAW,QAAA;AAAA,MACb;AAAA,EACF,GACC,EAAE;AACP;"}
@@ -1 +1 @@
1
- {"version":3,"file":"useOnline.mjs","sources":["../../../../src/hooks/useOnline/useOnline.ts"],"sourcesContent":["import { useSyncExternalStore } from 'react';\n\nconst getSnapshot = () => navigator.onLine;\nconst getServerSnapshot = () => false;\nconst subscribe = (callback: () => void) => {\n window.addEventListener('online', callback);\n window.addEventListener('offline', callback);\n return () => {\n window.removeEventListener('online', callback);\n window.removeEventListener('offline', callback);\n };\n};\n\n/**\n * @name useOnline\n * @description - Hook that manages if the user is online\n * @category Sensors\n *\n * @browserapi navigator.onLine https://developer.mozilla.org/en-US/docs/Web/API/Navigator/onLine\n *\n * @returns {boolean} A boolean indicating if the user is online\n *\n * @example\n * const online = useOnline();\n */\nexport const useOnline = () => useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);\n"],"names":["getSnapshot","getServerSnapshot","subscribe","callback","useOnline","useSyncExternalStore"],"mappings":";AAEA,MAAMA,IAAc,MAAM,UAAU,QAC9BC,IAAoB,MAAM,IAC1BC,IAAY,CAACC,OACV,OAAA,iBAAiB,UAAUA,CAAQ,GACnC,OAAA,iBAAiB,WAAWA,CAAQ,GACpC,MAAM;AACJ,SAAA,oBAAoB,UAAUA,CAAQ,GACtC,OAAA,oBAAoB,WAAWA,CAAQ;AAChD,IAeWC,IAAY,MAAMC,EAAqBH,GAAWF,GAAaC,CAAiB;"}
1
+ {"version":3,"file":"useOnline.mjs","sources":["../../../../src/hooks/useOnline/useOnline.ts"],"sourcesContent":["import { useSyncExternalStore } from 'react';\n\nconst getSnapshot = () => navigator.onLine;\nconst getServerSnapshot = () => false;\nconst subscribe = (callback: () => void) => {\n window.addEventListener('online', callback);\n window.addEventListener('offline', callback);\n return () => {\n window.removeEventListener('online', callback);\n window.removeEventListener('offline', callback);\n };\n};\n\n/**\n * @name useOnline\n * @description - Hook that manages if the user is online\n * @category Sensors\n *\n * @browserapi navigator.onLine https://developer.mozilla.org/en-US/docs/Web/API/Navigator/onLine\n *\n * @returns {boolean} A boolean indicating if the user is online\n *\n * @example\n * const online = useOnline();\n */\nexport const useOnline = () => useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);\n"],"names":["getSnapshot","getServerSnapshot","subscribe","callback","useOnline","useSyncExternalStore"],"mappings":";AAEA,MAAMA,IAAc,MAAM,UAAU,QAC9BC,IAAoB,MAAM,IAC1BC,IAAY,CAACC,OACjB,OAAO,iBAAiB,UAAUA,CAAQ,GAC1C,OAAO,iBAAiB,WAAWA,CAAQ,GACpC,MAAM;AACX,SAAO,oBAAoB,UAAUA,CAAQ,GAC7C,OAAO,oBAAoB,WAAWA,CAAQ;AAAA,IAgBrCC,IAAY,MAAMC,EAAqBH,GAAWF,GAAaC,CAAiB;"}
@@ -1 +1 @@
1
- {"version":3,"file":"useOperatingSystem.mjs","sources":["../../../../src/hooks/useOperatingSystem/useOperatingSystem.ts"],"sourcesContent":["import { useState } from 'react';\n\n/** The operating system type */\nexport type OperatingSystem = 'android' | 'ios' | 'linux' | 'macos' | 'undetermined' | 'windows';\n\nexport const getOperatingSystem = (): OperatingSystem => {\n if (typeof window === 'undefined') return 'undetermined';\n\n const { userAgent } = window.navigator;\n\n if (/Macintosh|MacIntel|MacPPC|Mac68K/i.test(userAgent)) return 'macos';\n if (/iPhone|iPad|iPod/i.test(userAgent)) return 'ios';\n if (/Win32|Win64|Windows|WinCE/i.test(userAgent)) return 'windows';\n if (/Android/i.test(userAgent)) return 'android';\n if (/Linux/i.test(userAgent)) return 'linux';\n\n return 'undetermined';\n};\n\n/**\n * @name useOperatingSystem\n * @description - Hook that returns the operating system of the current browser\n * @category Browser\n *\n * @returns {OperatingSystem} The operating system\n *\n * @example\n * const operatingSystem = useOperatingSystem();\n */\nexport const useOperatingSystem = () => {\n const [osOperatingSystem] = useState<OperatingSystem>(getOperatingSystem());\n return osOperatingSystem;\n};\n"],"names":["getOperatingSystem","userAgent","useOperatingSystem","osOperatingSystem","useState"],"mappings":";AAKO,MAAMA,IAAqB,MAAuB;AACnD,MAAA,OAAO,SAAW,IAAoB,QAAA;AAEpC,QAAA,EAAE,WAAAC,MAAc,OAAO;AAE7B,SAAI,oCAAoC,KAAKA,CAAS,IAAU,UAC5D,oBAAoB,KAAKA,CAAS,IAAU,QAC5C,6BAA6B,KAAKA,CAAS,IAAU,YACrD,WAAW,KAAKA,CAAS,IAAU,YACnC,SAAS,KAAKA,CAAS,IAAU,UAE9B;AACT,GAYaC,IAAqB,MAAM;AACtC,QAAM,CAACC,CAAiB,IAAIC,EAA0BJ,GAAoB;AACnE,SAAAG;AACT;"}
1
+ {"version":3,"file":"useOperatingSystem.mjs","sources":["../../../../src/hooks/useOperatingSystem/useOperatingSystem.ts"],"sourcesContent":["import { useState } from 'react';\n\n/** The operating system type */\nexport type OperatingSystem = 'android' | 'ios' | 'linux' | 'macos' | 'undetermined' | 'windows';\n\nexport const getOperatingSystem = (): OperatingSystem => {\n if (typeof window === 'undefined') return 'undetermined';\n\n const { userAgent } = window.navigator;\n\n if (/Macintosh|MacIntel|MacPPC|Mac68K/i.test(userAgent)) return 'macos';\n if (/iPhone|iPad|iPod/i.test(userAgent)) return 'ios';\n if (/Win32|Win64|Windows|WinCE/i.test(userAgent)) return 'windows';\n if (/Android/i.test(userAgent)) return 'android';\n if (/Linux/i.test(userAgent)) return 'linux';\n\n return 'undetermined';\n};\n\n/**\n * @name useOperatingSystem\n * @description - Hook that returns the operating system of the current browser\n * @category Browser\n *\n * @returns {OperatingSystem} The operating system\n *\n * @example\n * const operatingSystem = useOperatingSystem();\n */\nexport const useOperatingSystem = () => {\n const [osOperatingSystem] = useState<OperatingSystem>(getOperatingSystem());\n return osOperatingSystem;\n};\n"],"names":["getOperatingSystem","userAgent","useOperatingSystem","osOperatingSystem","useState"],"mappings":";AAKO,MAAMA,IAAqB,MAAuB;AACvD,MAAI,OAAO,SAAW,IAAa,QAAO;AAE1C,QAAM,EAAE,WAAAC,MAAc,OAAO;AAE7B,SAAI,oCAAoC,KAAKA,CAAS,IAAU,UAC5D,oBAAoB,KAAKA,CAAS,IAAU,QAC5C,6BAA6B,KAAKA,CAAS,IAAU,YACrD,WAAW,KAAKA,CAAS,IAAU,YACnC,SAAS,KAAKA,CAAS,IAAU,UAE9B;AACT,GAYaC,IAAqB,MAAM;AACtC,QAAM,CAACC,CAAiB,IAAIC,EAA0BJ,GAAoB;AAC1E,SAAOG;AACT;"}
@@ -1 +1 @@
1
- {"version":3,"file":"useOptimistic.mjs","sources":["../../../../src/hooks/useOptimistic/useOptimistic.ts"],"sourcesContent":["import { useRef, useState } from 'react';\n\nimport { useDidUpdate } from '../useDidUpdate/useDidUpdate';\n\nexport type UseOptimisticReturn<State> = [\n State,\n (optimisticValue: State, promise: Promise<any>) => void\n];\n\n/**\n * @name useOptimistic\n * @description - Hook that allows get optimistic value before its update\n * @category Utilities\n *\n * @template State The type of the state\n * @param {State} state The value to be returned initially and whenever no action is pending\n * @param {(currentState: State, optimisticValue: State) => State} update A pure function that takes the current state and the optimistic value passed to updateOptimistic and returns the resulting optimistic state\n * @returns {UseOptimisticReturn<State>} The resulting optimistic state, and the function to update it\n *\n * @example\n * const [optimisticValue, updateOptimistic] = useOptimistic<number>(count, (currentState, optimisticValue) => currentState + optimisticValue);\n */\nexport const useOptimistic = <State, OptimisticState = State>(\n externalState: State,\n update: (currentState: State, optimisticState: OptimisticState) => State\n) => {\n const [state, setState] = useState<State>(externalState);\n const internalUpdateRef = useRef(update);\n internalUpdateRef.current = update;\n\n const [promised, setPromised] = useState(false);\n\n useDidUpdate(() => {\n if (!promised) return;\n setState(externalState);\n setPromised(false);\n }, [promised]);\n\n const updateState = (optimisticValue: OptimisticState, promise: Promise<any>) => {\n setState((currentState) => internalUpdateRef.current(currentState, optimisticValue));\n return promise.finally(() => setPromised(true));\n };\n\n return [state, updateState] as const;\n};\n"],"names":["useOptimistic","externalState","update","state","setState","useState","internalUpdateRef","useRef","promised","setPromised","useDidUpdate","optimisticValue","promise","currentState"],"mappings":";;AAsBa,MAAAA,IAAgB,CAC3BC,GACAC,MACG;AACH,QAAM,CAACC,GAAOC,CAAQ,IAAIC,EAAgBJ,CAAa,GACjDK,IAAoBC,EAAOL,CAAM;AACvC,EAAAI,EAAkB,UAAUJ;AAE5B,QAAM,CAACM,GAAUC,CAAW,IAAIJ,EAAS,EAAK;AAE9C,SAAAK,EAAa,MAAM;AACjB,IAAKF,MACLJ,EAASH,CAAa,GACtBQ,EAAY,EAAK;AAAA,EAAA,GAChB,CAACD,CAAQ,CAAC,GAON,CAACL,GALY,CAACQ,GAAkCC,OACrDR,EAAS,CAACS,MAAiBP,EAAkB,QAAQO,GAAcF,CAAe,CAAC,GAC5EC,EAAQ,QAAQ,MAAMH,EAAY,EAAI,CAAC,EAGtB;AAC5B;"}
1
+ {"version":3,"file":"useOptimistic.mjs","sources":["../../../../src/hooks/useOptimistic/useOptimistic.ts"],"sourcesContent":["import { useRef, useState } from 'react';\n\nimport { useDidUpdate } from '../useDidUpdate/useDidUpdate';\n\nexport type UseOptimisticReturn<State> = [\n State,\n (optimisticValue: State, promise: Promise<any>) => void\n];\n\n/**\n * @name useOptimistic\n * @description - Hook that allows get optimistic value before its update\n * @category Utilities\n *\n * @template State The type of the state\n * @param {State} state The value to be returned initially and whenever no action is pending\n * @param {(currentState: State, optimisticValue: State) => State} update A pure function that takes the current state and the optimistic value passed to updateOptimistic and returns the resulting optimistic state\n * @returns {UseOptimisticReturn<State>} The resulting optimistic state, and the function to update it\n *\n * @example\n * const [optimisticValue, updateOptimistic] = useOptimistic<number>(count, (currentState, optimisticValue) => currentState + optimisticValue);\n */\nexport const useOptimistic = <State, OptimisticState = State>(\n externalState: State,\n update: (currentState: State, optimisticState: OptimisticState) => State\n) => {\n const [state, setState] = useState<State>(externalState);\n const internalUpdateRef = useRef(update);\n internalUpdateRef.current = update;\n\n const [promised, setPromised] = useState(false);\n\n useDidUpdate(() => {\n if (!promised) return;\n setState(externalState);\n setPromised(false);\n }, [promised]);\n\n const updateState = (optimisticValue: OptimisticState, promise: Promise<any>) => {\n setState((currentState) => internalUpdateRef.current(currentState, optimisticValue));\n return promise.finally(() => setPromised(true));\n };\n\n return [state, updateState] as const;\n};\n"],"names":["useOptimistic","externalState","update","state","setState","useState","internalUpdateRef","useRef","promised","setPromised","useDidUpdate","optimisticValue","promise","currentState"],"mappings":";;AAsBO,MAAMA,IAAgB,CAC3BC,GACAC,MACG;AACH,QAAM,CAACC,GAAOC,CAAQ,IAAIC,EAAgBJ,CAAa,GACjDK,IAAoBC,EAAOL,CAAM;AACvC,EAAAI,EAAkB,UAAUJ;AAE5B,QAAM,CAACM,GAAUC,CAAW,IAAIJ,EAAS,EAAK;AAE9C,SAAAK,EAAa,MAAM;AACjB,IAAKF,MACLJ,EAASH,CAAa,GACtBQ,EAAY,EAAK;AAAA,EAAA,GAChB,CAACD,CAAQ,CAAC,GAON,CAACL,GALY,CAACQ,GAAkCC,OACrDR,EAAS,CAACS,MAAiBP,EAAkB,QAAQO,GAAcF,CAAe,CAAC,GAC5EC,EAAQ,QAAQ,MAAMH,EAAY,EAAI,CAAC,EAGtB;AAC5B;"}
@@ -1 +1 @@
1
- {"version":3,"file":"useOrientation.mjs","sources":["../../../../src/hooks/useOrientation/useOrientation.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\n/** The use orientation return type */\nexport interface UseOrientationReturn {\n /** The current screen orientation angle */\n angle: number;\n /** The screen orientation type */\n type: OrientationType;\n}\n\n/**\n * @name useOrientation\n * @description - Hook that returns the current screen orientation\n * @category Browser\n *\n * @browserapi window.screen.orientation https://developer.mozilla.org/en-US/docs/Web/API/Screen/orientation\n *\n * @returns {UseOrientationReturn} An object containing the current screen orientation\n *\n * @example\n * const { angle, type } = useOrientation();\n */\nexport const useOrientation = (): UseOrientationReturn => {\n const [orientation, setOrientation] = useState<{\n angle: number;\n type: OrientationType;\n }>({ angle: 0, type: 'landscape-primary' });\n\n useEffect(() => {\n const onChange = () => setOrientation(window.screen.orientation);\n window.screen.orientation.addEventListener('change', onChange);\n return () => {\n window.screen.orientation.removeEventListener('change', onChange);\n };\n }, []);\n\n return orientation;\n};\n"],"names":["useOrientation","orientation","setOrientation","useState","useEffect","onChange"],"mappings":";AAsBO,MAAMA,IAAiB,MAA4B;AAClD,QAAA,CAACC,GAAaC,CAAc,IAAIC,EAGnC,EAAE,OAAO,GAAG,MAAM,qBAAqB;AAE1C,SAAAC,EAAU,MAAM;AACd,UAAMC,IAAW,MAAMH,EAAe,OAAO,OAAO,WAAW;AAC/D,kBAAO,OAAO,YAAY,iBAAiB,UAAUG,CAAQ,GACtD,MAAM;AACX,aAAO,OAAO,YAAY,oBAAoB,UAAUA,CAAQ;AAAA,IAClE;AAAA,EACF,GAAG,EAAE,GAEEJ;AACT;"}
1
+ {"version":3,"file":"useOrientation.mjs","sources":["../../../../src/hooks/useOrientation/useOrientation.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\n/** The use orientation return type */\nexport interface UseOrientationReturn {\n /** The current screen orientation angle */\n angle: number;\n /** The screen orientation type */\n type: OrientationType;\n}\n\n/**\n * @name useOrientation\n * @description - Hook that returns the current screen orientation\n * @category Browser\n *\n * @browserapi window.screen.orientation https://developer.mozilla.org/en-US/docs/Web/API/Screen/orientation\n *\n * @returns {UseOrientationReturn} An object containing the current screen orientation\n *\n * @example\n * const { angle, type } = useOrientation();\n */\nexport const useOrientation = (): UseOrientationReturn => {\n const [orientation, setOrientation] = useState<{\n angle: number;\n type: OrientationType;\n }>({ angle: 0, type: 'landscape-primary' });\n\n useEffect(() => {\n const onChange = () => setOrientation(window.screen.orientation);\n window.screen.orientation.addEventListener('change', onChange);\n return () => {\n window.screen.orientation.removeEventListener('change', onChange);\n };\n }, []);\n\n return orientation;\n};\n"],"names":["useOrientation","orientation","setOrientation","useState","useEffect","onChange"],"mappings":";AAsBO,MAAMA,IAAiB,MAA4B;AACxD,QAAM,CAACC,GAAaC,CAAc,IAAIC,EAGnC,EAAE,OAAO,GAAG,MAAM,qBAAqB;AAE1C,SAAAC,EAAU,MAAM;AACd,UAAMC,IAAW,MAAMH,EAAe,OAAO,OAAO,WAAW;AAC/D,kBAAO,OAAO,YAAY,iBAAiB,UAAUG,CAAQ,GACtD,MAAM;AACX,aAAO,OAAO,YAAY,oBAAoB,UAAUA,CAAQ;AAAA,IAAA;AAAA,EAClE,GACC,EAAE,GAEEJ;AACT;"}
@@ -1,25 +1,24 @@
1
- import { useState as u, useRef as f } from "react";
2
- const p = (...t) => {
3
- var i, a;
4
- const n = typeof t[0] == "function" ? t[0] : (i = t[0]) == null ? void 0 : i.onSuccess, o = typeof t[0] == "function" ? (a = t[0]) == null ? void 0 : a.onError : void 0, c = typeof navigator < "u" && "OTPCredential" in window, [l, s] = u(!1), r = f(new AbortController());
5
- return { supported: c, abort: () => {
6
- r.current.abort(), r.current = new AbortController(), r.current.signal.onabort = () => s(!0);
7
- }, aborted: l, get: async () => {
8
- if (c) {
1
+ import { useState as u, useRef as a } from "react";
2
+ const b = (...t) => {
3
+ const c = typeof t[0] == "function" ? t[0] : t[0]?.onSuccess, s = typeof t[0] == "function" ? t[0]?.onError : void 0, e = typeof navigator < "u" && "OTPCredential" in window, [i, n] = u(!1), r = a(new AbortController());
4
+ return { supported: e, abort: () => {
5
+ r.current.abort(), r.current = new AbortController(), r.current.signal.onabort = () => n(!0);
6
+ }, aborted: i, get: async () => {
7
+ if (e) {
9
8
  r.current = new AbortController();
10
9
  try {
11
- const e = await navigator.credentials.get({
10
+ const o = await navigator.credentials.get({
12
11
  otp: { transport: ["sms"] },
13
12
  signal: r.current.signal
14
13
  });
15
- return n == null || n(e), s(!1), e;
16
- } catch (e) {
17
- o == null || o(e);
14
+ return c?.(o), n(!1), o;
15
+ } catch (o) {
16
+ s?.(o);
18
17
  }
19
18
  }
20
19
  } };
21
20
  };
22
21
  export {
23
- p as useOtpCredential
22
+ b as useOtpCredential
24
23
  };
25
24
  //# sourceMappingURL=useOtpCredential.mjs.map