@siberiacancode/reactuse 0.2.29 → 0.2.30

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 (530) hide show
  1. package/README.md +71 -71
  2. package/dist/cjs/helpers/createContext/createContext.cjs.map +1 -1
  3. package/dist/cjs/helpers/createEventEmitter/createEventEmitter.cjs.map +1 -1
  4. package/dist/cjs/helpers/createReactiveContext/createReactiveContext.cjs.map +1 -1
  5. package/dist/cjs/helpers/createStore/createStore.cjs.map +1 -1
  6. package/dist/cjs/hooks/useActiveElement/useActiveElement.cjs.map +1 -1
  7. package/dist/cjs/hooks/useAsync/useAsync.cjs.map +1 -1
  8. package/dist/cjs/hooks/useAudio/useAudio.cjs.map +1 -1
  9. package/dist/cjs/hooks/useAutoScroll/useAutoScroll.cjs +1 -1
  10. package/dist/cjs/hooks/useAutoScroll/useAutoScroll.cjs.map +1 -1
  11. package/dist/cjs/hooks/useBattery/useBattery.cjs +1 -1
  12. package/dist/cjs/hooks/useBattery/useBattery.cjs.map +1 -1
  13. package/dist/cjs/hooks/useBluetooth/useBluetooth.cjs +1 -1
  14. package/dist/cjs/hooks/useBluetooth/useBluetooth.cjs.map +1 -1
  15. package/dist/cjs/hooks/useBoolean/useBoolean.cjs.map +1 -1
  16. package/dist/cjs/hooks/useBreakpoints/useBreakpoints.cjs.map +1 -1
  17. package/dist/cjs/hooks/useBroadcastChannel/useBroadcastChannel.cjs +1 -1
  18. package/dist/cjs/hooks/useBroadcastChannel/useBroadcastChannel.cjs.map +1 -1
  19. package/dist/cjs/hooks/useBrowserLanguage/useBrowserLanguage.cjs.map +1 -1
  20. package/dist/cjs/hooks/useClickOutside/useClickOutside.cjs.map +1 -1
  21. package/dist/cjs/hooks/useClipboard/useClipboard.cjs.map +1 -1
  22. package/dist/cjs/hooks/useConst/useConst.cjs.map +1 -1
  23. package/dist/cjs/hooks/useCookie/useCookie.cjs.map +1 -1
  24. package/dist/cjs/hooks/useCookies/useCookies.cjs.map +1 -1
  25. package/dist/cjs/hooks/useCopy/useCopy.cjs.map +1 -1
  26. package/dist/cjs/hooks/useCounter/useCounter.cjs.map +1 -1
  27. package/dist/cjs/hooks/useCssVar/useCssVar.cjs.map +1 -1
  28. package/dist/cjs/hooks/useDebounceCallback/useDebounceCallback.cjs.map +1 -1
  29. package/dist/cjs/hooks/useDebounceState/useDebounceState.cjs +2 -0
  30. package/dist/cjs/hooks/useDebounceState/useDebounceState.cjs.map +1 -0
  31. package/dist/cjs/hooks/useDebounceValue/useDebounceValue.cjs.map +1 -1
  32. package/dist/cjs/hooks/useDefault/useDefault.cjs.map +1 -1
  33. package/dist/cjs/hooks/useDeviceMotion/useDeviceMotion.cjs.map +1 -1
  34. package/dist/cjs/hooks/useDeviceOrientation/useDeviceOrientation.cjs +1 -1
  35. package/dist/cjs/hooks/useDeviceOrientation/useDeviceOrientation.cjs.map +1 -1
  36. package/dist/cjs/hooks/useDevicePixelRatio/useDevicePixelRatio.cjs +1 -1
  37. package/dist/cjs/hooks/useDevicePixelRatio/useDevicePixelRatio.cjs.map +1 -1
  38. package/dist/cjs/hooks/useDidUpdate/useDidUpdate.cjs.map +1 -1
  39. package/dist/cjs/hooks/useDisclosure/useDisclosure.cjs.map +1 -1
  40. package/dist/cjs/hooks/useDisplayMedia/useDisplayMedia.cjs.map +1 -1
  41. package/dist/cjs/hooks/useDocumentEvent/useDocumentEvent.cjs.map +1 -1
  42. package/dist/cjs/hooks/useDocumentTitle/useDocumentTitle.cjs.map +1 -1
  43. package/dist/cjs/hooks/useDocumentVisibility/useDocumentVisibility.cjs.map +1 -1
  44. package/dist/cjs/hooks/useDoubleClick/useDoubleClick.cjs.map +1 -1
  45. package/dist/cjs/hooks/useDropZone/useDropZone.cjs +1 -1
  46. package/dist/cjs/hooks/useDropZone/useDropZone.cjs.map +1 -1
  47. package/dist/cjs/hooks/useElementSize/useElementSize.cjs.map +1 -1
  48. package/dist/cjs/hooks/useEvent/useEvent.cjs.map +1 -1
  49. package/dist/cjs/hooks/useEventListener/useEventListener.cjs +1 -1
  50. package/dist/cjs/hooks/useEventListener/useEventListener.cjs.map +1 -1
  51. package/dist/cjs/hooks/useEventSource/useEventSource.cjs.map +1 -1
  52. package/dist/cjs/hooks/useEyeDropper/useEyeDropper.cjs +1 -1
  53. package/dist/cjs/hooks/useEyeDropper/useEyeDropper.cjs.map +1 -1
  54. package/dist/cjs/hooks/useFavicon/useFavicon.cjs +1 -1
  55. package/dist/cjs/hooks/useFavicon/useFavicon.cjs.map +1 -1
  56. package/dist/cjs/hooks/useField/useField.cjs.map +1 -1
  57. package/dist/cjs/hooks/useFileDialog/useFileDialog.cjs.map +1 -1
  58. package/dist/cjs/hooks/useFocus/useFocus.cjs +1 -1
  59. package/dist/cjs/hooks/useFocus/useFocus.cjs.map +1 -1
  60. package/dist/cjs/hooks/useFps/useFps.cjs.map +1 -1
  61. package/dist/cjs/hooks/useFul/useFul.cjs.map +1 -1
  62. package/dist/cjs/hooks/useFullscreen/useFullscreen.cjs.map +1 -1
  63. package/dist/cjs/hooks/useGamepad/useGamepad.cjs +1 -1
  64. package/dist/cjs/hooks/useGamepad/useGamepad.cjs.map +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.map +1 -1
  68. package/dist/cjs/hooks/useHover/useHover.cjs +1 -1
  69. package/dist/cjs/hooks/useHover/useHover.cjs.map +1 -1
  70. package/dist/cjs/hooks/useIdle/useIdle.cjs.map +1 -1
  71. package/dist/cjs/hooks/useImage/useImage.cjs.map +1 -1
  72. package/dist/cjs/hooks/useInfiniteScroll/useInfiniteScroll.cjs.map +1 -1
  73. package/dist/cjs/hooks/useIntersectionObserver/useIntersectionObserver.cjs +1 -1
  74. package/dist/cjs/hooks/useIntersectionObserver/useIntersectionObserver.cjs.map +1 -1
  75. package/dist/cjs/hooks/useInterval/useInterval.cjs.map +1 -1
  76. package/dist/cjs/hooks/useIsFirstRender/useIsFirstRender.cjs.map +1 -1
  77. package/dist/cjs/hooks/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.cjs.map +1 -1
  78. package/dist/cjs/hooks/useKeyPress/useKeyPress.cjs.map +1 -1
  79. package/dist/cjs/hooks/useKeyPressEvent/useKeyPressEvent.cjs.map +1 -1
  80. package/dist/cjs/hooks/useKeyboard/useKeyboard.cjs.map +1 -1
  81. package/dist/cjs/hooks/useKeysPressed/useKeysPressed.cjs.map +1 -1
  82. package/dist/cjs/hooks/useLastChanged/useLastChanged.cjs.map +1 -1
  83. package/dist/cjs/hooks/useLatest/useLatest.cjs.map +1 -1
  84. package/dist/cjs/hooks/useLess/useLess.cjs.map +1 -1
  85. package/dist/cjs/hooks/useList/useList.cjs.map +1 -1
  86. package/dist/cjs/hooks/useLocalStorage/useLocalStorage.cjs.map +1 -1
  87. package/dist/cjs/hooks/useLockCallback/useLockCallback.cjs.map +1 -1
  88. package/dist/cjs/hooks/useLockScroll/useLockScroll.cjs.map +1 -1
  89. package/dist/cjs/hooks/useLogger/useLogger.cjs.map +1 -1
  90. package/dist/cjs/hooks/useLongPress/useLongPress.cjs.map +1 -1
  91. package/dist/cjs/hooks/useMap/useMap.cjs.map +1 -1
  92. package/dist/cjs/hooks/useMeasure/useMeasure.cjs.map +1 -1
  93. package/dist/cjs/hooks/useMediaControls/useMediaControls.cjs.map +1 -1
  94. package/dist/cjs/hooks/useMediaQuery/useMediaQuery.cjs.map +1 -1
  95. package/dist/cjs/hooks/useMemory/useMemory.cjs +1 -1
  96. package/dist/cjs/hooks/useMemory/useMemory.cjs.map +1 -1
  97. package/dist/cjs/hooks/useMergedRef/useMergedRef.cjs +2 -0
  98. package/dist/cjs/hooks/useMergedRef/useMergedRef.cjs.map +1 -0
  99. package/dist/cjs/hooks/useMount/useMount.cjs.map +1 -1
  100. package/dist/cjs/hooks/useMouse/useMouse.cjs.map +1 -1
  101. package/dist/cjs/hooks/useMutation/useMutation.cjs +1 -1
  102. package/dist/cjs/hooks/useMutation/useMutation.cjs.map +1 -1
  103. package/dist/cjs/hooks/useMutationObserver/useMutationObserver.cjs +1 -1
  104. package/dist/cjs/hooks/useMutationObserver/useMutationObserver.cjs.map +1 -1
  105. package/dist/cjs/hooks/useNetwork/useNetwork.cjs.map +1 -1
  106. package/dist/cjs/hooks/useOffsetPagination/useOffsetPagination.cjs.map +1 -1
  107. package/dist/cjs/hooks/useOnce/useOnce.cjs.map +1 -1
  108. package/dist/cjs/hooks/useOnline/useOnline.cjs.map +1 -1
  109. package/dist/cjs/hooks/useOperatingSystem/useOperatingSystem.cjs.map +1 -1
  110. package/dist/cjs/hooks/useOptimistic/useOptimistic.cjs.map +1 -1
  111. package/dist/cjs/hooks/useOrientation/useOrientation.cjs +1 -1
  112. package/dist/cjs/hooks/useOrientation/useOrientation.cjs.map +1 -1
  113. package/dist/cjs/hooks/useOtpCredential/useOtpCredential.cjs +1 -1
  114. package/dist/cjs/hooks/useOtpCredential/useOtpCredential.cjs.map +1 -1
  115. package/dist/cjs/hooks/usePageLeave/usePageLeave.cjs.map +1 -1
  116. package/dist/cjs/hooks/usePaint/usePaint.cjs.map +1 -1
  117. package/dist/cjs/hooks/useParallax/useParallax.cjs.map +1 -1
  118. package/dist/cjs/hooks/usePerformanceObserver/usePerformanceObserver.cjs +1 -1
  119. package/dist/cjs/hooks/usePerformanceObserver/usePerformanceObserver.cjs.map +1 -1
  120. package/dist/cjs/hooks/usePermission/usePermission.cjs +1 -1
  121. package/dist/cjs/hooks/usePermission/usePermission.cjs.map +1 -1
  122. package/dist/cjs/hooks/usePictureInPicture/usePictureInPicture.cjs +1 -1
  123. package/dist/cjs/hooks/usePictureInPicture/usePictureInPicture.cjs.map +1 -1
  124. package/dist/cjs/hooks/usePointerLock/usePointerLock.cjs +1 -1
  125. package/dist/cjs/hooks/usePointerLock/usePointerLock.cjs.map +1 -1
  126. package/dist/cjs/hooks/usePostMessage/usePostMessage.cjs.map +1 -1
  127. package/dist/cjs/hooks/usePreferredColorScheme/usePreferredColorScheme.cjs.map +1 -1
  128. package/dist/cjs/hooks/usePreferredContrast/usePreferredContrast.cjs.map +1 -1
  129. package/dist/cjs/hooks/usePreferredDark/usePreferredDark.cjs.map +1 -1
  130. package/dist/cjs/hooks/usePreferredLanguages/usePreferredLanguages.cjs.map +1 -1
  131. package/dist/cjs/hooks/usePreferredReducedMotion/usePreferredReducedMotion.cjs.map +1 -1
  132. package/dist/cjs/hooks/usePrevious/usePrevious.cjs.map +1 -1
  133. package/dist/cjs/hooks/useQuery/useQuery.cjs.map +1 -1
  134. package/dist/cjs/hooks/useQueue/useQueue.cjs.map +1 -1
  135. package/dist/cjs/hooks/useRaf/useRaf.cjs.map +1 -1
  136. package/dist/cjs/hooks/useRafState/useRafState.cjs.map +1 -1
  137. package/dist/cjs/hooks/useRefState/useRefState.cjs.map +1 -1
  138. package/dist/cjs/hooks/useRenderCount/useRenderCount.cjs.map +1 -1
  139. package/dist/cjs/hooks/useRenderInfo/useRenderInfo.cjs.map +1 -1
  140. package/dist/cjs/hooks/useRerender/useRerender.cjs.map +1 -1
  141. package/dist/cjs/hooks/useResizeObserver/useResizeObserver.cjs +1 -1
  142. package/dist/cjs/hooks/useResizeObserver/useResizeObserver.cjs.map +1 -1
  143. package/dist/cjs/hooks/useRightClick/useRightClick.cjs.map +1 -1
  144. package/dist/cjs/hooks/useScript/useScript.cjs.map +1 -1
  145. package/dist/cjs/hooks/useScroll/useScroll.cjs.map +1 -1
  146. package/dist/cjs/hooks/useScrollIntoView/useScrollIntoView.cjs.map +1 -1
  147. package/dist/cjs/hooks/useScrollTo/useScrollTo.cjs.map +1 -1
  148. package/dist/cjs/hooks/useSessionStorage/useSessionStorage.cjs.map +1 -1
  149. package/dist/cjs/hooks/useSet/useSet.cjs.map +1 -1
  150. package/dist/cjs/hooks/useShallowEffect/useShallowEffect.cjs.map +1 -1
  151. package/dist/cjs/hooks/useShare/useShare.cjs +1 -1
  152. package/dist/cjs/hooks/useShare/useShare.cjs.map +1 -1
  153. package/dist/cjs/hooks/useSpeechRecognition/useSpeechRecognition.cjs.map +1 -1
  154. package/dist/cjs/hooks/useSpeechSynthesis/useSpeechSynthesis.cjs +1 -1
  155. package/dist/cjs/hooks/useSpeechSynthesis/useSpeechSynthesis.cjs.map +1 -1
  156. package/dist/cjs/hooks/useStateHistory/useStateHistory.cjs.map +1 -1
  157. package/dist/cjs/hooks/useStep/useStep.cjs.map +1 -1
  158. package/dist/cjs/hooks/useSticky/useSticky.cjs.map +1 -1
  159. package/dist/cjs/hooks/useStopwatch/useStopwatch.cjs.map +1 -1
  160. package/dist/cjs/hooks/useStorage/useStorage.cjs.map +1 -1
  161. package/dist/cjs/hooks/useTextDirection/useTextDirection.cjs +1 -1
  162. package/dist/cjs/hooks/useTextDirection/useTextDirection.cjs.map +1 -1
  163. package/dist/cjs/hooks/useTextSelection/useTextSelection.cjs.map +1 -1
  164. package/dist/cjs/hooks/useThrottleCallback/useThrottleCallback.cjs.map +1 -1
  165. package/dist/cjs/hooks/useThrottleState/useThrottleState.cjs +2 -0
  166. package/dist/cjs/hooks/useThrottleState/useThrottleState.cjs.map +1 -0
  167. package/dist/cjs/hooks/useThrottleValue/useThrottleValue.cjs.map +1 -1
  168. package/dist/cjs/hooks/useTime/useTime.cjs.map +1 -1
  169. package/dist/cjs/hooks/useTimeout/useTimeout.cjs.map +1 -1
  170. package/dist/cjs/hooks/useTimer/useTimer.cjs.map +1 -1
  171. package/dist/cjs/hooks/useToggle/useToggle.cjs.map +1 -1
  172. package/dist/cjs/hooks/useUnmount/useUnmount.cjs.map +1 -1
  173. package/dist/cjs/hooks/useUrlSearchParam/useUrlSearchParam.cjs.map +1 -1
  174. package/dist/cjs/hooks/useUrlSearchParams/useUrlSearchParams.cjs.map +1 -1
  175. package/dist/cjs/hooks/useVibrate/useVibrate.cjs +1 -1
  176. package/dist/cjs/hooks/useVibrate/useVibrate.cjs.map +1 -1
  177. package/dist/cjs/hooks/useVirtualKeyboard/useVirtualKeyboard.cjs +1 -1
  178. package/dist/cjs/hooks/useVirtualKeyboard/useVirtualKeyboard.cjs.map +1 -1
  179. package/dist/cjs/hooks/useWakeLock/useWakeLock.cjs +1 -1
  180. package/dist/cjs/hooks/useWakeLock/useWakeLock.cjs.map +1 -1
  181. package/dist/cjs/hooks/useWebSocket/useWebSocket.cjs.map +1 -1
  182. package/dist/cjs/hooks/useWindowEvent/useWindowEvent.cjs.map +1 -1
  183. package/dist/cjs/hooks/useWindowFocus/useWindowFocus.cjs.map +1 -1
  184. package/dist/cjs/hooks/useWindowScroll/useWindowScroll.cjs.map +1 -1
  185. package/dist/cjs/hooks/useWindowSize/useWindowSize.cjs.map +1 -1
  186. package/dist/cjs/hooks/useWizard/useWizard.cjs.map +1 -1
  187. package/dist/cjs/index.cjs +1 -1
  188. package/dist/esm/helpers/createContext/createContext.mjs.map +1 -1
  189. package/dist/esm/helpers/createEventEmitter/createEventEmitter.mjs.map +1 -1
  190. package/dist/esm/helpers/createReactiveContext/createReactiveContext.mjs.map +1 -1
  191. package/dist/esm/helpers/createStore/createStore.mjs.map +1 -1
  192. package/dist/esm/hooks/useActiveElement/useActiveElement.mjs.map +1 -1
  193. package/dist/esm/hooks/useAsync/useAsync.mjs.map +1 -1
  194. package/dist/esm/hooks/useAudio/useAudio.mjs.map +1 -1
  195. package/dist/esm/hooks/useAutoScroll/useAutoScroll.mjs +25 -31
  196. package/dist/esm/hooks/useAutoScroll/useAutoScroll.mjs.map +1 -1
  197. package/dist/esm/hooks/useBattery/useBattery.mjs +1 -1
  198. package/dist/esm/hooks/useBattery/useBattery.mjs.map +1 -1
  199. package/dist/esm/hooks/useBluetooth/useBluetooth.mjs +16 -18
  200. package/dist/esm/hooks/useBluetooth/useBluetooth.mjs.map +1 -1
  201. package/dist/esm/hooks/useBoolean/useBoolean.mjs.map +1 -1
  202. package/dist/esm/hooks/useBreakpoints/useBreakpoints.mjs.map +1 -1
  203. package/dist/esm/hooks/useBroadcastChannel/useBroadcastChannel.mjs +8 -8
  204. package/dist/esm/hooks/useBroadcastChannel/useBroadcastChannel.mjs.map +1 -1
  205. package/dist/esm/hooks/useBrowserLanguage/useBrowserLanguage.mjs.map +1 -1
  206. package/dist/esm/hooks/useClickOutside/useClickOutside.mjs.map +1 -1
  207. package/dist/esm/hooks/useClipboard/useClipboard.mjs.map +1 -1
  208. package/dist/esm/hooks/useConst/useConst.mjs.map +1 -1
  209. package/dist/esm/hooks/useCookie/useCookie.mjs.map +1 -1
  210. package/dist/esm/hooks/useCookies/useCookies.mjs.map +1 -1
  211. package/dist/esm/hooks/useCopy/useCopy.mjs.map +1 -1
  212. package/dist/esm/hooks/useCounter/useCounter.mjs.map +1 -1
  213. package/dist/esm/hooks/useCssVar/useCssVar.mjs.map +1 -1
  214. package/dist/esm/hooks/useDebounceCallback/useDebounceCallback.mjs.map +1 -1
  215. package/dist/esm/hooks/useDebounceState/useDebounceState.mjs +10 -0
  216. package/dist/esm/hooks/useDebounceState/useDebounceState.mjs.map +1 -0
  217. package/dist/esm/hooks/useDebounceValue/useDebounceValue.mjs.map +1 -1
  218. package/dist/esm/hooks/useDefault/useDefault.mjs.map +1 -1
  219. package/dist/esm/hooks/useDeviceMotion/useDeviceMotion.mjs.map +1 -1
  220. package/dist/esm/hooks/useDeviceOrientation/useDeviceOrientation.mjs +1 -1
  221. package/dist/esm/hooks/useDeviceOrientation/useDeviceOrientation.mjs.map +1 -1
  222. package/dist/esm/hooks/useDevicePixelRatio/useDevicePixelRatio.mjs +1 -1
  223. package/dist/esm/hooks/useDevicePixelRatio/useDevicePixelRatio.mjs.map +1 -1
  224. package/dist/esm/hooks/useDidUpdate/useDidUpdate.mjs.map +1 -1
  225. package/dist/esm/hooks/useDisclosure/useDisclosure.mjs.map +1 -1
  226. package/dist/esm/hooks/useDisplayMedia/useDisplayMedia.mjs.map +1 -1
  227. package/dist/esm/hooks/useDocumentEvent/useDocumentEvent.mjs.map +1 -1
  228. package/dist/esm/hooks/useDocumentTitle/useDocumentTitle.mjs.map +1 -1
  229. package/dist/esm/hooks/useDocumentVisibility/useDocumentVisibility.mjs.map +1 -1
  230. package/dist/esm/hooks/useDoubleClick/useDoubleClick.mjs.map +1 -1
  231. package/dist/esm/hooks/useDropZone/useDropZone.mjs +12 -12
  232. package/dist/esm/hooks/useDropZone/useDropZone.mjs.map +1 -1
  233. package/dist/esm/hooks/useElementSize/useElementSize.mjs.map +1 -1
  234. package/dist/esm/hooks/useEvent/useEvent.mjs.map +1 -1
  235. package/dist/esm/hooks/useEventListener/useEventListener.mjs +15 -15
  236. package/dist/esm/hooks/useEventListener/useEventListener.mjs.map +1 -1
  237. package/dist/esm/hooks/useEventSource/useEventSource.mjs.map +1 -1
  238. package/dist/esm/hooks/useEyeDropper/useEyeDropper.mjs +3 -3
  239. package/dist/esm/hooks/useEyeDropper/useEyeDropper.mjs.map +1 -1
  240. package/dist/esm/hooks/useFavicon/useFavicon.mjs +12 -15
  241. package/dist/esm/hooks/useFavicon/useFavicon.mjs.map +1 -1
  242. package/dist/esm/hooks/useField/useField.mjs.map +1 -1
  243. package/dist/esm/hooks/useFileDialog/useFileDialog.mjs.map +1 -1
  244. package/dist/esm/hooks/useFocus/useFocus.mjs +26 -22
  245. package/dist/esm/hooks/useFocus/useFocus.mjs.map +1 -1
  246. package/dist/esm/hooks/useFps/useFps.mjs.map +1 -1
  247. package/dist/esm/hooks/useFul/useFul.mjs.map +1 -1
  248. package/dist/esm/hooks/useFullscreen/useFullscreen.mjs.map +1 -1
  249. package/dist/esm/hooks/useGamepad/useGamepad.mjs +13 -13
  250. package/dist/esm/hooks/useGamepad/useGamepad.mjs.map +1 -1
  251. package/dist/esm/hooks/useGeolocation/useGeolocation.mjs.map +1 -1
  252. package/dist/esm/hooks/useHash/useHash.mjs.map +1 -1
  253. package/dist/esm/hooks/useHotkeys/useHotkeys.mjs.map +1 -1
  254. package/dist/esm/hooks/useHover/useHover.mjs +15 -15
  255. package/dist/esm/hooks/useHover/useHover.mjs.map +1 -1
  256. package/dist/esm/hooks/useIdle/useIdle.mjs.map +1 -1
  257. package/dist/esm/hooks/useImage/useImage.mjs.map +1 -1
  258. package/dist/esm/hooks/useInfiniteScroll/useInfiniteScroll.mjs.map +1 -1
  259. package/dist/esm/hooks/useIntersectionObserver/useIntersectionObserver.mjs +19 -18
  260. package/dist/esm/hooks/useIntersectionObserver/useIntersectionObserver.mjs.map +1 -1
  261. package/dist/esm/hooks/useInterval/useInterval.mjs.map +1 -1
  262. package/dist/esm/hooks/useIsFirstRender/useIsFirstRender.mjs.map +1 -1
  263. package/dist/esm/hooks/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.mjs.map +1 -1
  264. package/dist/esm/hooks/useKeyPress/useKeyPress.mjs.map +1 -1
  265. package/dist/esm/hooks/useKeyPressEvent/useKeyPressEvent.mjs.map +1 -1
  266. package/dist/esm/hooks/useKeyboard/useKeyboard.mjs.map +1 -1
  267. package/dist/esm/hooks/useKeysPressed/useKeysPressed.mjs.map +1 -1
  268. package/dist/esm/hooks/useLastChanged/useLastChanged.mjs.map +1 -1
  269. package/dist/esm/hooks/useLatest/useLatest.mjs.map +1 -1
  270. package/dist/esm/hooks/useLess/useLess.mjs.map +1 -1
  271. package/dist/esm/hooks/useList/useList.mjs.map +1 -1
  272. package/dist/esm/hooks/useLocalStorage/useLocalStorage.mjs.map +1 -1
  273. package/dist/esm/hooks/useLockCallback/useLockCallback.mjs.map +1 -1
  274. package/dist/esm/hooks/useLockScroll/useLockScroll.mjs.map +1 -1
  275. package/dist/esm/hooks/useLogger/useLogger.mjs.map +1 -1
  276. package/dist/esm/hooks/useLongPress/useLongPress.mjs.map +1 -1
  277. package/dist/esm/hooks/useMap/useMap.mjs.map +1 -1
  278. package/dist/esm/hooks/useMeasure/useMeasure.mjs.map +1 -1
  279. package/dist/esm/hooks/useMediaControls/useMediaControls.mjs.map +1 -1
  280. package/dist/esm/hooks/useMediaQuery/useMediaQuery.mjs.map +1 -1
  281. package/dist/esm/hooks/useMemory/useMemory.mjs +4 -4
  282. package/dist/esm/hooks/useMemory/useMemory.mjs.map +1 -1
  283. package/dist/esm/hooks/useMergedRef/useMergedRef.mjs +25 -0
  284. package/dist/esm/hooks/useMergedRef/useMergedRef.mjs.map +1 -0
  285. package/dist/esm/hooks/useMount/useMount.mjs.map +1 -1
  286. package/dist/esm/hooks/useMouse/useMouse.mjs.map +1 -1
  287. package/dist/esm/hooks/useMutation/useMutation.mjs +18 -18
  288. package/dist/esm/hooks/useMutation/useMutation.mjs.map +1 -1
  289. package/dist/esm/hooks/useMutationObserver/useMutationObserver.mjs +28 -20
  290. package/dist/esm/hooks/useMutationObserver/useMutationObserver.mjs.map +1 -1
  291. package/dist/esm/hooks/useNetwork/useNetwork.mjs.map +1 -1
  292. package/dist/esm/hooks/useOffsetPagination/useOffsetPagination.mjs.map +1 -1
  293. package/dist/esm/hooks/useOnce/useOnce.mjs.map +1 -1
  294. package/dist/esm/hooks/useOnline/useOnline.mjs.map +1 -1
  295. package/dist/esm/hooks/useOperatingSystem/useOperatingSystem.mjs.map +1 -1
  296. package/dist/esm/hooks/useOptimistic/useOptimistic.mjs.map +1 -1
  297. package/dist/esm/hooks/useOrientation/useOrientation.mjs +9 -9
  298. package/dist/esm/hooks/useOrientation/useOrientation.mjs.map +1 -1
  299. package/dist/esm/hooks/useOtpCredential/useOtpCredential.mjs +3 -3
  300. package/dist/esm/hooks/useOtpCredential/useOtpCredential.mjs.map +1 -1
  301. package/dist/esm/hooks/usePageLeave/usePageLeave.mjs.map +1 -1
  302. package/dist/esm/hooks/usePaint/usePaint.mjs.map +1 -1
  303. package/dist/esm/hooks/useParallax/useParallax.mjs.map +1 -1
  304. package/dist/esm/hooks/usePerformanceObserver/usePerformanceObserver.mjs +11 -11
  305. package/dist/esm/hooks/usePerformanceObserver/usePerformanceObserver.mjs.map +1 -1
  306. package/dist/esm/hooks/usePermission/usePermission.mjs +4 -4
  307. package/dist/esm/hooks/usePermission/usePermission.mjs.map +1 -1
  308. package/dist/esm/hooks/usePictureInPicture/usePictureInPicture.mjs +17 -17
  309. package/dist/esm/hooks/usePictureInPicture/usePictureInPicture.mjs.map +1 -1
  310. package/dist/esm/hooks/usePointerLock/usePointerLock.mjs +3 -3
  311. package/dist/esm/hooks/usePointerLock/usePointerLock.mjs.map +1 -1
  312. package/dist/esm/hooks/usePostMessage/usePostMessage.mjs.map +1 -1
  313. package/dist/esm/hooks/usePreferredColorScheme/usePreferredColorScheme.mjs.map +1 -1
  314. package/dist/esm/hooks/usePreferredContrast/usePreferredContrast.mjs.map +1 -1
  315. package/dist/esm/hooks/usePreferredDark/usePreferredDark.mjs.map +1 -1
  316. package/dist/esm/hooks/usePreferredLanguages/usePreferredLanguages.mjs.map +1 -1
  317. package/dist/esm/hooks/usePreferredReducedMotion/usePreferredReducedMotion.mjs.map +1 -1
  318. package/dist/esm/hooks/usePrevious/usePrevious.mjs.map +1 -1
  319. package/dist/esm/hooks/useQuery/useQuery.mjs.map +1 -1
  320. package/dist/esm/hooks/useQueue/useQueue.mjs.map +1 -1
  321. package/dist/esm/hooks/useRaf/useRaf.mjs.map +1 -1
  322. package/dist/esm/hooks/useRafState/useRafState.mjs.map +1 -1
  323. package/dist/esm/hooks/useRefState/useRefState.mjs.map +1 -1
  324. package/dist/esm/hooks/useRenderCount/useRenderCount.mjs.map +1 -1
  325. package/dist/esm/hooks/useRenderInfo/useRenderInfo.mjs.map +1 -1
  326. package/dist/esm/hooks/useRerender/useRerender.mjs.map +1 -1
  327. package/dist/esm/hooks/useResizeObserver/useResizeObserver.mjs +17 -16
  328. package/dist/esm/hooks/useResizeObserver/useResizeObserver.mjs.map +1 -1
  329. package/dist/esm/hooks/useRightClick/useRightClick.mjs.map +1 -1
  330. package/dist/esm/hooks/useScript/useScript.mjs.map +1 -1
  331. package/dist/esm/hooks/useScroll/useScroll.mjs.map +1 -1
  332. package/dist/esm/hooks/useScrollIntoView/useScrollIntoView.mjs.map +1 -1
  333. package/dist/esm/hooks/useScrollTo/useScrollTo.mjs.map +1 -1
  334. package/dist/esm/hooks/useSessionStorage/useSessionStorage.mjs.map +1 -1
  335. package/dist/esm/hooks/useSet/useSet.mjs.map +1 -1
  336. package/dist/esm/hooks/useShallowEffect/useShallowEffect.mjs.map +1 -1
  337. package/dist/esm/hooks/useShare/useShare.mjs +1 -1
  338. package/dist/esm/hooks/useShare/useShare.mjs.map +1 -1
  339. package/dist/esm/hooks/useSpeechRecognition/useSpeechRecognition.mjs.map +1 -1
  340. package/dist/esm/hooks/useSpeechSynthesis/useSpeechSynthesis.mjs +11 -11
  341. package/dist/esm/hooks/useSpeechSynthesis/useSpeechSynthesis.mjs.map +1 -1
  342. package/dist/esm/hooks/useStateHistory/useStateHistory.mjs.map +1 -1
  343. package/dist/esm/hooks/useStep/useStep.mjs.map +1 -1
  344. package/dist/esm/hooks/useSticky/useSticky.mjs.map +1 -1
  345. package/dist/esm/hooks/useStopwatch/useStopwatch.mjs.map +1 -1
  346. package/dist/esm/hooks/useStorage/useStorage.mjs.map +1 -1
  347. package/dist/esm/hooks/useTextDirection/useTextDirection.mjs +14 -14
  348. package/dist/esm/hooks/useTextDirection/useTextDirection.mjs.map +1 -1
  349. package/dist/esm/hooks/useTextSelection/useTextSelection.mjs.map +1 -1
  350. package/dist/esm/hooks/useThrottleCallback/useThrottleCallback.mjs.map +1 -1
  351. package/dist/esm/hooks/useThrottleState/useThrottleState.mjs +10 -0
  352. package/dist/esm/hooks/useThrottleState/useThrottleState.mjs.map +1 -0
  353. package/dist/esm/hooks/useThrottleValue/useThrottleValue.mjs.map +1 -1
  354. package/dist/esm/hooks/useTime/useTime.mjs.map +1 -1
  355. package/dist/esm/hooks/useTimeout/useTimeout.mjs.map +1 -1
  356. package/dist/esm/hooks/useTimer/useTimer.mjs.map +1 -1
  357. package/dist/esm/hooks/useToggle/useToggle.mjs.map +1 -1
  358. package/dist/esm/hooks/useUnmount/useUnmount.mjs.map +1 -1
  359. package/dist/esm/hooks/useUrlSearchParam/useUrlSearchParam.mjs.map +1 -1
  360. package/dist/esm/hooks/useUrlSearchParams/useUrlSearchParams.mjs.map +1 -1
  361. package/dist/esm/hooks/useVibrate/useVibrate.mjs +12 -12
  362. package/dist/esm/hooks/useVibrate/useVibrate.mjs.map +1 -1
  363. package/dist/esm/hooks/useVirtualKeyboard/useVirtualKeyboard.mjs +7 -7
  364. package/dist/esm/hooks/useVirtualKeyboard/useVirtualKeyboard.mjs.map +1 -1
  365. package/dist/esm/hooks/useWakeLock/useWakeLock.mjs +1 -1
  366. package/dist/esm/hooks/useWakeLock/useWakeLock.mjs.map +1 -1
  367. package/dist/esm/hooks/useWebSocket/useWebSocket.mjs.map +1 -1
  368. package/dist/esm/hooks/useWindowEvent/useWindowEvent.mjs.map +1 -1
  369. package/dist/esm/hooks/useWindowFocus/useWindowFocus.mjs.map +1 -1
  370. package/dist/esm/hooks/useWindowScroll/useWindowScroll.mjs.map +1 -1
  371. package/dist/esm/hooks/useWindowSize/useWindowSize.mjs.map +1 -1
  372. package/dist/esm/hooks/useWizard/useWizard.mjs.map +1 -1
  373. package/dist/esm/index.mjs +147 -139
  374. package/dist/esm/index.mjs.map +1 -1
  375. package/dist/types/helpers/createContext/createContext.d.ts +1 -0
  376. package/dist/types/helpers/createEventEmitter/createEventEmitter.d.ts +1 -0
  377. package/dist/types/helpers/createReactiveContext/createReactiveContext.d.ts +1 -0
  378. package/dist/types/helpers/createStore/createStore.d.ts +1 -0
  379. package/dist/types/hooks/state.d.ts +1 -0
  380. package/dist/types/hooks/useActiveElement/useActiveElement.d.ts +1 -0
  381. package/dist/types/hooks/useAsync/useAsync.d.ts +1 -0
  382. package/dist/types/hooks/useAudio/useAudio.d.ts +2 -1
  383. package/dist/types/hooks/useAutoScroll/useAutoScroll.d.ts +1 -0
  384. package/dist/types/hooks/useBattery/useBattery.d.ts +1 -0
  385. package/dist/types/hooks/useBluetooth/useBluetooth.d.ts +1 -0
  386. package/dist/types/hooks/useBoolean/useBoolean.d.ts +2 -1
  387. package/dist/types/hooks/useBreakpoints/useBreakpoints.d.ts +1 -0
  388. package/dist/types/hooks/useBroadcastChannel/useBroadcastChannel.d.ts +1 -0
  389. package/dist/types/hooks/useBrowserLanguage/useBrowserLanguage.d.ts +2 -1
  390. package/dist/types/hooks/useClickOutside/useClickOutside.d.ts +2 -1
  391. package/dist/types/hooks/useClipboard/useClipboard.d.ts +2 -1
  392. package/dist/types/hooks/useConst/useConst.d.ts +2 -1
  393. package/dist/types/hooks/useCookie/useCookie.d.ts +2 -1
  394. package/dist/types/hooks/useCookies/useCookies.d.ts +2 -1
  395. package/dist/types/hooks/useCopy/useCopy.d.ts +2 -1
  396. package/dist/types/hooks/useCounter/useCounter.d.ts +2 -1
  397. package/dist/types/hooks/useCssVar/useCssVar.d.ts +2 -1
  398. package/dist/types/hooks/useDebounceCallback/useDebounceCallback.d.ts +1 -0
  399. package/dist/types/hooks/useDebounceState/useDebounceState.d.ts +15 -0
  400. package/dist/types/hooks/useDebounceValue/useDebounceValue.d.ts +2 -1
  401. package/dist/types/hooks/useDefault/useDefault.d.ts +2 -1
  402. package/dist/types/hooks/useDeviceMotion/useDeviceMotion.d.ts +2 -1
  403. package/dist/types/hooks/useDeviceOrientation/useDeviceOrientation.d.ts +1 -0
  404. package/dist/types/hooks/useDevicePixelRatio/useDevicePixelRatio.d.ts +1 -0
  405. package/dist/types/hooks/useDidUpdate/useDidUpdate.d.ts +2 -1
  406. package/dist/types/hooks/useDisclosure/useDisclosure.d.ts +2 -1
  407. package/dist/types/hooks/useDisplayMedia/useDisplayMedia.d.ts +1 -0
  408. package/dist/types/hooks/useDocumentEvent/useDocumentEvent.d.ts +2 -1
  409. package/dist/types/hooks/useDocumentTitle/useDocumentTitle.d.ts +2 -1
  410. package/dist/types/hooks/useDocumentVisibility/useDocumentVisibility.d.ts +2 -1
  411. package/dist/types/hooks/useDoubleClick/useDoubleClick.d.ts +2 -1
  412. package/dist/types/hooks/useDropZone/useDropZone.d.ts +2 -1
  413. package/dist/types/hooks/useElementSize/useElementSize.d.ts +2 -1
  414. package/dist/types/hooks/useEvent/useEvent.d.ts +2 -1
  415. package/dist/types/hooks/useEventListener/useEventListener.d.ts +5 -2
  416. package/dist/types/hooks/useEventSource/useEventSource.d.ts +1 -0
  417. package/dist/types/hooks/useEyeDropper/useEyeDropper.d.ts +1 -0
  418. package/dist/types/hooks/useFavicon/useFavicon.d.ts +2 -1
  419. package/dist/types/hooks/useField/useField.d.ts +1 -0
  420. package/dist/types/hooks/useFileDialog/useFileDialog.d.ts +1 -0
  421. package/dist/types/hooks/useFocus/useFocus.d.ts +25 -0
  422. package/dist/types/hooks/useFps/useFps.d.ts +1 -0
  423. package/dist/types/hooks/useFul/useFul.d.ts +1 -0
  424. package/dist/types/hooks/useFullscreen/useFullscreen.d.ts +1 -0
  425. package/dist/types/hooks/useGamepad/useGamepad.d.ts +1 -0
  426. package/dist/types/hooks/useGeolocation/useGeolocation.d.ts +1 -0
  427. package/dist/types/hooks/useHash/useHash.d.ts +1 -0
  428. package/dist/types/hooks/useHotkeys/useHotkeys.d.ts +1 -0
  429. package/dist/types/hooks/useHover/useHover.d.ts +3 -0
  430. package/dist/types/hooks/useIdle/useIdle.d.ts +1 -0
  431. package/dist/types/hooks/useImage/useImage.d.ts +1 -0
  432. package/dist/types/hooks/useInfiniteScroll/useInfiniteScroll.d.ts +1 -0
  433. package/dist/types/hooks/useIntersectionObserver/useIntersectionObserver.d.ts +15 -6
  434. package/dist/types/hooks/useInterval/useInterval.d.ts +1 -0
  435. package/dist/types/hooks/useIsFirstRender/useIsFirstRender.d.ts +1 -0
  436. package/dist/types/hooks/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.d.ts +1 -0
  437. package/dist/types/hooks/useKeyPress/useKeyPress.d.ts +1 -0
  438. package/dist/types/hooks/useKeyPressEvent/useKeyPressEvent.d.ts +1 -0
  439. package/dist/types/hooks/useKeyboard/useKeyboard.d.ts +1 -0
  440. package/dist/types/hooks/useKeysPressed/useKeysPressed.d.ts +1 -2
  441. package/dist/types/hooks/useLastChanged/useLastChanged.d.ts +1 -0
  442. package/dist/types/hooks/useLatest/useLatest.d.ts +1 -0
  443. package/dist/types/hooks/useLess/useLess.d.ts +1 -0
  444. package/dist/types/hooks/useList/useList.d.ts +1 -0
  445. package/dist/types/hooks/useLocalStorage/useLocalStorage.d.ts +1 -0
  446. package/dist/types/hooks/useLockCallback/useLockCallback.d.ts +1 -0
  447. package/dist/types/hooks/useLockScroll/useLockScroll.d.ts +1 -1
  448. package/dist/types/hooks/useLogger/useLogger.d.ts +1 -0
  449. package/dist/types/hooks/useLongPress/useLongPress.d.ts +1 -0
  450. package/dist/types/hooks/useMap/useMap.d.ts +1 -0
  451. package/dist/types/hooks/useMeasure/useMeasure.d.ts +1 -0
  452. package/dist/types/hooks/useMediaControls/useMediaControls.d.ts +1 -0
  453. package/dist/types/hooks/useMediaQuery/useMediaQuery.d.ts +1 -0
  454. package/dist/types/hooks/useMemory/useMemory.d.ts +1 -0
  455. package/dist/types/hooks/useMergedRef/useMergedRef.d.ts +17 -0
  456. package/dist/types/hooks/useMount/useMount.d.ts +1 -0
  457. package/dist/types/hooks/useMouse/useMouse.d.ts +1 -0
  458. package/dist/types/hooks/useMutation/useMutation.d.ts +1 -0
  459. package/dist/types/hooks/useMutationObserver/useMutationObserver.d.ts +43 -26
  460. package/dist/types/hooks/useNetwork/useNetwork.d.ts +1 -0
  461. package/dist/types/hooks/useObject/useObject.d.ts +1 -0
  462. package/dist/types/hooks/useOffsetPagination/useOffsetPagination.d.ts +1 -0
  463. package/dist/types/hooks/useOnce/useOnce.d.ts +1 -0
  464. package/dist/types/hooks/useOnline/useOnline.d.ts +1 -0
  465. package/dist/types/hooks/useOperatingSystem/useOperatingSystem.d.ts +1 -0
  466. package/dist/types/hooks/useOptimistic/useOptimistic.d.ts +1 -0
  467. package/dist/types/hooks/useOrientation/useOrientation.d.ts +2 -1
  468. package/dist/types/hooks/useOtpCredential/useOtpCredential.d.ts +1 -0
  469. package/dist/types/hooks/usePageLeave/usePageLeave.d.ts +1 -0
  470. package/dist/types/hooks/usePaint/usePaint.d.ts +1 -0
  471. package/dist/types/hooks/useParallax/useParallax.d.ts +1 -0
  472. package/dist/types/hooks/usePerformanceObserver/usePerformanceObserver.d.ts +1 -0
  473. package/dist/types/hooks/usePermission/usePermission.d.ts +1 -0
  474. package/dist/types/hooks/usePictureInPicture/usePictureInPicture.d.ts +1 -0
  475. package/dist/types/hooks/usePointerLock/usePointerLock.d.ts +1 -0
  476. package/dist/types/hooks/usePostMessage/usePostMessage.d.ts +1 -0
  477. package/dist/types/hooks/usePreferredColorScheme/usePreferredColorScheme.d.ts +1 -0
  478. package/dist/types/hooks/usePreferredContrast/usePreferredContrast.d.ts +1 -0
  479. package/dist/types/hooks/usePreferredDark/usePreferredDark.d.ts +1 -0
  480. package/dist/types/hooks/usePreferredLanguages/usePreferredLanguages.d.ts +1 -0
  481. package/dist/types/hooks/usePreferredReducedMotion/usePreferredReducedMotion.d.ts +1 -0
  482. package/dist/types/hooks/usePrevious/usePrevious.d.ts +1 -0
  483. package/dist/types/hooks/useQuery/useQuery.d.ts +1 -0
  484. package/dist/types/hooks/useQueue/useQueue.d.ts +1 -0
  485. package/dist/types/hooks/useRaf/useRaf.d.ts +1 -0
  486. package/dist/types/hooks/useRafState/useRafState.d.ts +3 -0
  487. package/dist/types/hooks/useRefState/useRefState.d.ts +1 -0
  488. package/dist/types/hooks/useRenderCount/useRenderCount.d.ts +1 -0
  489. package/dist/types/hooks/useRenderInfo/useRenderInfo.d.ts +1 -0
  490. package/dist/types/hooks/useRerender/useRerender.d.ts +1 -0
  491. package/dist/types/hooks/useResizeObserver/useResizeObserver.d.ts +55 -31
  492. package/dist/types/hooks/useRightClick/useRightClick.d.ts +1 -0
  493. package/dist/types/hooks/useScript/useScript.d.ts +1 -0
  494. package/dist/types/hooks/useScroll/useScroll.d.ts +1 -0
  495. package/dist/types/hooks/useScrollIntoView/useScrollIntoView.d.ts +1 -0
  496. package/dist/types/hooks/useScrollTo/useScrollTo.d.ts +1 -0
  497. package/dist/types/hooks/useSessionStorage/useSessionStorage.d.ts +1 -0
  498. package/dist/types/hooks/useSet/useSet.d.ts +1 -0
  499. package/dist/types/hooks/useShallowEffect/useShallowEffect.d.ts +1 -0
  500. package/dist/types/hooks/useShare/useShare.d.ts +1 -0
  501. package/dist/types/hooks/useSpeechRecognition/useSpeechRecognition.d.ts +1 -0
  502. package/dist/types/hooks/useSpeechSynthesis/useSpeechSynthesis.d.ts +1 -0
  503. package/dist/types/hooks/useStateHistory/useStateHistory.d.ts +1 -0
  504. package/dist/types/hooks/useStep/useStep.d.ts +1 -0
  505. package/dist/types/hooks/useSticky/useSticky.d.ts +1 -0
  506. package/dist/types/hooks/useStopwatch/useStopwatch.d.ts +1 -0
  507. package/dist/types/hooks/useStorage/useStorage.d.ts +1 -0
  508. package/dist/types/hooks/useTextDirection/useTextDirection.d.ts +1 -0
  509. package/dist/types/hooks/useTextSelection/useTextSelection.d.ts +1 -0
  510. package/dist/types/hooks/useThrottleCallback/useThrottleCallback.d.ts +1 -0
  511. package/dist/types/hooks/useThrottleState/useThrottleState.d.ts +15 -0
  512. package/dist/types/hooks/useThrottleValue/useThrottleValue.d.ts +1 -0
  513. package/dist/types/hooks/useTime/useTime.d.ts +1 -0
  514. package/dist/types/hooks/useTimeout/useTimeout.d.ts +1 -0
  515. package/dist/types/hooks/useTimer/useTimer.d.ts +1 -0
  516. package/dist/types/hooks/useToggle/useToggle.d.ts +1 -0
  517. package/dist/types/hooks/useUnmount/useUnmount.d.ts +1 -0
  518. package/dist/types/hooks/useUrlSearchParam/useUrlSearchParam.d.ts +1 -0
  519. package/dist/types/hooks/useUrlSearchParams/useUrlSearchParams.d.ts +1 -0
  520. package/dist/types/hooks/useVibrate/useVibrate.d.ts +1 -0
  521. package/dist/types/hooks/useVirtualKeyboard/useVirtualKeyboard.d.ts +1 -0
  522. package/dist/types/hooks/useWakeLock/useWakeLock.d.ts +1 -0
  523. package/dist/types/hooks/useWebSocket/useWebSocket.d.ts +17 -0
  524. package/dist/types/hooks/useWindowEvent/useWindowEvent.d.ts +1 -0
  525. package/dist/types/hooks/useWindowFocus/useWindowFocus.d.ts +1 -0
  526. package/dist/types/hooks/useWindowScroll/useWindowScroll.d.ts +1 -0
  527. package/dist/types/hooks/useWindowSize/useWindowSize.d.ts +1 -0
  528. package/dist/types/hooks/useWizard/useWizard.d.ts +1 -0
  529. package/dist/types/hooks/utilities.d.ts +2 -0
  530. package/package.json +89 -89
@@ -1 +1 @@
1
- {"version":3,"file":"useScript.mjs","sources":["../../../../src/hooks/useScript/useScript.ts"],"sourcesContent":["import type { ComponentProps } from 'react';\n\nimport { useEffect, useState } from 'react';\n\n/** The use script status */\nexport type UseScriptStatus = 'error' | 'loading' | 'ready' | 'unknown';\nexport const SCRIPT_STATUS_ATTRIBUTE_NAME = 'script-status';\n\n/** The use script options extends from attributes script tag */\nexport interface UseScriptOptions extends ComponentProps<'script'> {\n /** Whether to remove the script on unmount */\n removeOnUnmount?: boolean;\n}\n\n/**\n * @name useScript\n * @description - Hook that manages a script with onLoad, onError, and removeOnUnmount functionalities\n * @category Elements\n *\n * @param {string} src The source of the script\n * @param {UseScriptOptions} [options] The options of the script extends from attributes script tag\n * @param {boolean} [options.removeOnUnmount=true] Whether to remove the script on unmount\n * @param {boolean} [options.async=true] Whether to load the script asynchronously\n * @returns {UseScriptStatus} The status of the script\n *\n * @example\n * const status = useScript('https://example.com/script.js');\n */\nexport const useScript = (src: string, options: UseScriptOptions = {}) => {\n const [status, setStatus] = useState<UseScriptStatus>(() => {\n const script = document.querySelector(`script[src=\"${src}\"]`) as HTMLScriptElement;\n const scriptStatus = script?.getAttribute(SCRIPT_STATUS_ATTRIBUTE_NAME) as UseScriptStatus;\n if (scriptStatus) return scriptStatus;\n if (script) return 'unknown';\n\n return 'loading';\n });\n const { removeOnUnmount = true, async = true } = options;\n\n useEffect(() => {\n const existedScript = document.querySelector(`script[src=\"${src}\"]`) as HTMLScriptElement;\n const scriptStatus = existedScript?.getAttribute(\n SCRIPT_STATUS_ATTRIBUTE_NAME\n ) as UseScriptStatus;\n if (scriptStatus) return setStatus(scriptStatus);\n if (existedScript) return setStatus('unknown');\n\n const script = document.createElement('script');\n script.src = src;\n script.async = async;\n\n for (const [key, value] of Object.entries(options)) {\n script.setAttribute(key, String(value));\n }\n\n script.setAttribute(SCRIPT_STATUS_ATTRIBUTE_NAME, 'loading');\n document.body.appendChild(script);\n\n const onLoad = () => {\n script.setAttribute(SCRIPT_STATUS_ATTRIBUTE_NAME, 'ready');\n setStatus('ready');\n };\n\n const onError = () => {\n script.setAttribute(SCRIPT_STATUS_ATTRIBUTE_NAME, 'error');\n setStatus('error');\n };\n\n script.addEventListener('load', onLoad);\n script.addEventListener('error', onError);\n\n return () => {\n if (removeOnUnmount) script.remove();\n script.removeEventListener('load', onLoad);\n script.removeEventListener('error', onError);\n };\n }, [src, removeOnUnmount]);\n\n return status;\n};\n"],"names":["SCRIPT_STATUS_ATTRIBUTE_NAME","useScript","src","options","status","setStatus","useState","script","scriptStatus","removeOnUnmount","async","useEffect","existedScript","key","value","onLoad","onError"],"mappings":";AAMO,MAAMA,IAA+B,iBAsB/BC,IAAY,CAACC,GAAaC,IAA4B,OAAO;AACxE,QAAM,CAACC,GAAQC,CAAS,IAAIC,EAA0B,MAAM;AAC1D,UAAMC,IAAS,SAAS,cAAc,eAAeL,CAAG,IAAI,GACtDM,IAAeD,GAAQ,aAAaP,CAA4B;AACtE,WAAIQ,MACAD,IAAe,YAEZ;AAAA,EAAA,CACR,GACK,EAAE,iBAAAE,IAAkB,IAAM,OAAAC,IAAQ,OAASP;AAEjD,SAAAQ,EAAU,MAAM;AACd,UAAMC,IAAgB,SAAS,cAAc,eAAeV,CAAG,IAAI,GAC7DM,IAAeI,GAAe;AAAA,MAClCZ;AAAA,IAAA;AAEF,QAAIQ,EAAc,QAAOH,EAAUG,CAAY;AAC/C,QAAII,EAAe,QAAOP,EAAU,SAAS;AAE7C,UAAME,IAAS,SAAS,cAAc,QAAQ;AAC9C,IAAAA,EAAO,MAAML,GACbK,EAAO,QAAQG;AAEf,eAAW,CAACG,GAAKC,CAAK,KAAK,OAAO,QAAQX,CAAO;AAC/C,MAAAI,EAAO,aAAaM,GAAK,OAAOC,CAAK,CAAC;AAGxC,IAAAP,EAAO,aAAaP,GAA8B,SAAS,GAC3D,SAAS,KAAK,YAAYO,CAAM;AAEhC,UAAMQ,IAAS,MAAM;AACnB,MAAAR,EAAO,aAAaP,GAA8B,OAAO,GACzDK,EAAU,OAAO;AAAA,IAAA,GAGbW,IAAU,MAAM;AACpB,MAAAT,EAAO,aAAaP,GAA8B,OAAO,GACzDK,EAAU,OAAO;AAAA,IAAA;AAGnB,WAAAE,EAAO,iBAAiB,QAAQQ,CAAM,GACtCR,EAAO,iBAAiB,SAASS,CAAO,GAEjC,MAAM;AACX,MAAIP,OAAwB,OAAA,GAC5BF,EAAO,oBAAoB,QAAQQ,CAAM,GACzCR,EAAO,oBAAoB,SAASS,CAAO;AAAA,IAAA;AAAA,EAC7C,GACC,CAACd,GAAKO,CAAe,CAAC,GAElBL;AACT;"}
1
+ {"version":3,"file":"useScript.mjs","sources":["../../../../src/hooks/useScript/useScript.ts"],"sourcesContent":["import type { ComponentProps } from 'react';\n\nimport { useEffect, useState } from 'react';\n\n/** The use script status */\nexport type UseScriptStatus = 'error' | 'loading' | 'ready' | 'unknown';\nexport const SCRIPT_STATUS_ATTRIBUTE_NAME = 'script-status';\n\n/** The use script options extends from attributes script tag */\nexport interface UseScriptOptions extends ComponentProps<'script'> {\n /** Whether to remove the script on unmount */\n removeOnUnmount?: boolean;\n}\n\n/**\n * @name useScript\n * @description - Hook that manages a script with onLoad, onError, and removeOnUnmount functionalities\n * @category Elements\n * @usage low\n *\n * @param {string} src The source of the script\n * @param {UseScriptOptions} [options] The options of the script extends from attributes script tag\n * @param {boolean} [options.removeOnUnmount=true] Whether to remove the script on unmount\n * @param {boolean} [options.async=true] Whether to load the script asynchronously\n * @returns {UseScriptStatus} The status of the script\n *\n * @example\n * const status = useScript('https://example.com/script.js');\n */\nexport const useScript = (src: string, options: UseScriptOptions = {}) => {\n const [status, setStatus] = useState<UseScriptStatus>(() => {\n const script = document.querySelector(`script[src=\"${src}\"]`) as HTMLScriptElement;\n const scriptStatus = script?.getAttribute(SCRIPT_STATUS_ATTRIBUTE_NAME) as UseScriptStatus;\n if (scriptStatus) return scriptStatus;\n if (script) return 'unknown';\n\n return 'loading';\n });\n const { removeOnUnmount = true, async = true } = options;\n\n useEffect(() => {\n const existedScript = document.querySelector(`script[src=\"${src}\"]`) as HTMLScriptElement;\n const scriptStatus = existedScript?.getAttribute(\n SCRIPT_STATUS_ATTRIBUTE_NAME\n ) as UseScriptStatus;\n if (scriptStatus) return setStatus(scriptStatus);\n if (existedScript) return setStatus('unknown');\n\n const script = document.createElement('script');\n script.src = src;\n script.async = async;\n\n for (const [key, value] of Object.entries(options)) {\n script.setAttribute(key, String(value));\n }\n\n script.setAttribute(SCRIPT_STATUS_ATTRIBUTE_NAME, 'loading');\n document.body.appendChild(script);\n\n const onLoad = () => {\n script.setAttribute(SCRIPT_STATUS_ATTRIBUTE_NAME, 'ready');\n setStatus('ready');\n };\n\n const onError = () => {\n script.setAttribute(SCRIPT_STATUS_ATTRIBUTE_NAME, 'error');\n setStatus('error');\n };\n\n script.addEventListener('load', onLoad);\n script.addEventListener('error', onError);\n\n return () => {\n if (removeOnUnmount) script.remove();\n script.removeEventListener('load', onLoad);\n script.removeEventListener('error', onError);\n };\n }, [src, removeOnUnmount]);\n\n return status;\n};\n"],"names":["SCRIPT_STATUS_ATTRIBUTE_NAME","useScript","src","options","status","setStatus","useState","script","scriptStatus","removeOnUnmount","async","useEffect","existedScript","key","value","onLoad","onError"],"mappings":";AAMO,MAAMA,IAA+B,iBAuB/BC,IAAY,CAACC,GAAaC,IAA4B,OAAO;AACxE,QAAM,CAACC,GAAQC,CAAS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State } 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\nconst ARRIVED_STATE_THRESHOLD_PIXELS = 1;\n\nexport interface UseScrollOptions {\n /** The on scroll callback */\n onScroll?: (params: UseScrollCallbackParams, event: Event) => void;\n\n /** The on end scroll callback */\n onStop?: (event: Event) => void;\n\n /** Offset arrived states by x pixels. */\n offset?: {\n left?: number;\n right?: number;\n top?: number;\n bottom?: number;\n };\n}\n\nexport interface UseScrollCallbackParams {\n /** The element x position */\n x: number;\n /** The element y position */\n y: number;\n /** State of scroll arrived */\n arrived: {\n left: boolean;\n right: boolean;\n top: boolean;\n bottom: boolean;\n };\n /** State of scroll direction */\n directions: {\n left: boolean;\n right: boolean;\n top: boolean;\n bottom: boolean;\n };\n}\n\nexport interface UseScroll {\n (target: HookTarget, callback?: (params: UseScrollCallbackParams, event: Event) => void): boolean;\n\n (target: HookTarget, options?: UseScrollOptions): boolean;\n\n <Target extends Element>(\n callback?: (params: UseScrollCallbackParams, event: Event) => void,\n target?: never\n ): {\n ref: StateRef<Target>;\n scrolling: boolean;\n };\n\n <Target extends Element>(\n options?: UseScrollOptions,\n target?: never\n ): {\n ref: StateRef<Target>;\n scrolling: boolean;\n };\n}\n\n/**\n * @name useScroll\n * @description - Hook that allows you to control scroll a element\n * @category Sensors\n *\n * @overload\n * @template Target The target element\n * @param {ScrollBehavior} [options.behavior=auto] The behavior of scrolling\n * @param {number} [options.offset.left=0] The left offset for arrived states\n * @param {number} [options.offset.right=0] The right offset for arrived states\n * @param {number} [options.offset.top=0] The top offset for arrived states\n * @param {number} [options.offset.bottom=0] The bottom offset for arrived states\n * @param {(params: UseScrollCallbackParams, event: Event) => void} [options.onScroll] The callback function to be invoked on scroll\n * @param {(event: Event) => void} [options.onStop] The callback function to be invoked on scroll end\n * @returns {boolean} The state of scrolling\n *\n * @example\n * const scrolling = useScroll(ref, options);\n *\n * @overload\n * @template Target The target element\n * @param {(params: UseScrollCallbackParams, event: Event) => void} [callback] The callback function to be invoked on scroll\n * @returns {boolean} The state of scrolling\n *\n * @example\n * const scrolling = useScroll(ref, () => console.log('callback'));\n *\n * @overload\n * @template Target The target element\n * @param {Target} target The target element to scroll\n * @param {ScrollBehavior} [options.behavior=auto] The behavior of scrolling\n * @param {number} [options.offset.left=0] The left offset for arrived states\n * @param {number} [options.offset.right=0] The right offset for arrived states\n * @param {number} [options.offset.top=0] The top offset for arrived states\n * @param {number} [options.offset.bottom=0] The bottom offset for arrived states\n * @param {(params: UseScrollCallbackParams, event: Event) => void} [options.onScroll] The callback function to be invoked on scroll\n * @param {(event: Event) => void} [options.onStop] The callback function to be invoked on scroll end\n * @returns {[StateRef<Target>, boolean]} The state of scrolling\n *\n * @example\n * const { ref, scrolling } = useScroll(options);\n *\n * @overload\n * @template Target The target element\n * @param {Target} target The target element to scroll\n * @param {(params: UseScrollCallbackParams, event: Event) => void} [callback] The callback function to be invoked on scroll\n * @returns {[StateRef<Target>, boolean]} The state of scrolling\n *\n * @example\n * const { ref, scrolling } = useScroll(() => console.log('callback'));\n */\nexport const useScroll = ((...params: any[]) => {\n const target = (isTarget(params[0]) ? params[0] : undefined) as HookTarget | undefined;\n const options = (\n target\n ? typeof params[1] === 'object'\n ? params[1]\n : { onScroll: params[1] }\n : typeof params[0] === 'object'\n ? params[0]\n : { onScroll: params[0] }\n ) as UseScrollOptions | undefined;\n\n const internalRef = useRefState<Element>();\n const internalOptionsRef = useRef(options);\n internalOptionsRef.current = options;\n\n const [scrolling, setScrolling] = useState(false);\n const scrollPositionRef = useRef({ x: 0, y: 0 });\n\n useEffect(() => {\n if (!target && !internalRef.state) return;\n const element = (target ? getElement(target) : internalRef.current) as Element;\n\n if (!element) return;\n\n const onScrollEnd = (event: Event) => {\n setScrolling(false);\n options?.onStop?.(event);\n };\n\n const onScroll = (event: Event) => {\n setScrolling(true);\n const target = (\n event.target === document ? (event.target as Document).documentElement : event.target\n ) as HTMLElement;\n\n const { display, flexDirection, direction } = target.style;\n const directionMultiplier = direction === 'rtl' ? -1 : 1;\n\n const scrollLeft = target.scrollLeft;\n let scrollTop = target.scrollTop;\n if (target instanceof Document && !scrollTop) scrollTop = window.document.body.scrollTop;\n\n const offset = internalOptionsRef.current?.offset;\n const left = scrollLeft * directionMultiplier <= (offset?.left ?? 0);\n const right =\n scrollLeft * directionMultiplier + target.clientWidth >=\n target.scrollWidth - (offset?.right ?? 0) - ARRIVED_STATE_THRESHOLD_PIXELS;\n const top = scrollTop <= (offset?.top ?? 0);\n const bottom =\n scrollTop + target.clientHeight >=\n target.scrollHeight - (offset?.bottom ?? 0) - ARRIVED_STATE_THRESHOLD_PIXELS;\n\n const isColumnReverse = display === 'flex' && flexDirection === 'column-reverse';\n const isRowReverse = display === 'flex' && flexDirection === 'column-reverse';\n\n const params = {\n x: scrollLeft,\n y: scrollTop,\n directions: {\n left: scrollLeft < scrollPositionRef.current.x,\n right: scrollLeft > scrollPositionRef.current.x,\n top: scrollTop < scrollPositionRef.current.y,\n bottom: scrollTop > scrollPositionRef.current.y\n },\n arrived: {\n left: isRowReverse ? right : left,\n right: isRowReverse ? left : right,\n top: isColumnReverse ? bottom : top,\n bottom: isColumnReverse ? top : bottom\n }\n };\n\n scrollPositionRef.current = { x: scrollLeft, y: scrollTop };\n internalOptionsRef.current?.onScroll?.(params, event);\n };\n\n element.addEventListener('scroll', onScroll);\n element.addEventListener('scrollend', onScrollEnd);\n\n return () => {\n element.removeEventListener('scroll', onScroll);\n element.removeEventListener('scrollend', onScrollEnd);\n };\n }, [target, internalRef.state]);\n\n if (target) return scrolling;\n return {\n ref: internalRef,\n scrolling\n };\n}) as UseScroll;\n"],"names":["ARRIVED_STATE_THRESHOLD_PIXELS","useScroll","params","target","isTarget","options","internalRef","useRefState","internalOptionsRef","useRef","scrolling","setScrolling","useState","scrollPositionRef","useEffect","element","getElement","onScrollEnd","event","onScroll","display","flexDirection","direction","directionMultiplier","scrollLeft","scrollTop","offset","left","right","top","bottom","isColumnReverse","isRowReverse"],"mappings":";;;;AAUA,MAAMA,IAAiC,GAgH1BC,IAAa,IAAIC,MAAkB;AAC9C,QAAMC,IAAUC,EAASF,EAAO,CAAC,CAAC,IAAIA,EAAO,CAAC,IAAI,QAC5CG,IACJF,IACI,OAAOD,EAAO,CAAC,KAAM,WACnBA,EAAO,CAAC,IACR,EAAE,UAAUA,EAAO,CAAC,EAAA,IACtB,OAAOA,EAAO,CAAC,KAAM,WACnBA,EAAO,CAAC,IACR,EAAE,UAAUA,EAAO,CAAC,EAAA,GAGtBI,IAAcC,EAAA,GACdC,IAAqBC,EAAOJ,CAAO;AACzC,EAAAG,EAAmB,UAAUH;AAE7B,QAAM,CAACK,GAAWC,CAAY,IAAIC,EAAS,EAAK,GAC1CC,IAAoBJ,EAAO,EAAE,GAAG,GAAG,GAAG,GAAG;AAqE/C,SAnEAK,EAAU,MAAM;AACd,QAAI,CAACX,KAAU,CAACG,EAAY,MAAO;AACnC,UAAMS,IAAWZ,IAASa,EAAWb,CAAM,IAAIG,EAAY;AAE3D,QAAI,CAACS,EAAS;AAEd,UAAME,IAAc,CAACC,MAAiB;AACpC,MAAAP,EAAa,EAAK,GAClBN,GAAS,SAASa,CAAK;AAAA,IAAA,GAGnBC,IAAW,CAACD,MAAiB;AACjC,MAAAP,EAAa,EAAI;AACjB,YAAMR,IACJe,EAAM,WAAW,WAAYA,EAAM,OAAoB,kBAAkBA,EAAM,QAG3E,EAAE,SAAAE,GAAS,eAAAC,GAAe,WAAAC,EAAA,IAAcnB,EAAO,OAC/CoB,IAAsBD,MAAc,QAAQ,KAAK,GAEjDE,IAAarB,EAAO;AAC1B,UAAIsB,IAAYtB,EAAO;AACvB,MAAIA,aAAkB,YAAY,CAACsB,MAAWA,IAAY,OAAO,SAAS,KAAK;AAE/E,YAAMC,IAASlB,EAAmB,SAAS,QACrCmB,IAAOH,IAAaD,MAAwBG,GAAQ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ef, 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\nconst ARRIVED_STATE_THRESHOLD_PIXELS = 1;\n\nexport interface UseScrollOptions {\n /** The on scroll callback */\n onScroll?: (params: UseScrollCallbackParams, event: Event) => void;\n\n /** The on end scroll callback */\n onStop?: (event: Event) => void;\n\n /** Offset arrived states by x pixels. */\n offset?: {\n left?: number;\n right?: number;\n top?: number;\n bottom?: number;\n };\n}\n\nexport interface UseScrollCallbackParams {\n /** The element x position */\n x: number;\n /** The element y position */\n y: number;\n /** State of scroll arrived */\n arrived: {\n left: boolean;\n right: boolean;\n top: boolean;\n bottom: boolean;\n };\n /** State of scroll direction */\n directions: {\n left: boolean;\n right: boolean;\n top: boolean;\n bottom: boolean;\n };\n}\n\nexport interface UseScroll {\n (target: HookTarget, callback?: (params: UseScrollCallbackParams, event: Event) => void): boolean;\n\n (target: HookTarget, options?: UseScrollOptions): boolean;\n\n <Target extends Element>(\n callback?: (params: UseScrollCallbackParams, event: Event) => void,\n target?: never\n ): {\n ref: StateRef<Target>;\n scrolling: boolean;\n };\n\n <Target extends Element>(\n options?: UseScrollOptions,\n target?: never\n ): {\n ref: StateRef<Target>;\n scrolling: boolean;\n };\n}\n\n/**\n * @name useScroll\n * @description - Hook that allows you to control scroll a element\n * @category Sensors\n * @usage low\n *\n * @overload\n * @template Target The target element\n * @param {ScrollBehavior} [options.behavior=auto] The behavior of scrolling\n * @param {number} [options.offset.left=0] The left offset for arrived states\n * @param {number} [options.offset.right=0] The right offset for arrived states\n * @param {number} [options.offset.top=0] The top offset for arrived states\n * @param {number} [options.offset.bottom=0] The bottom offset for arrived states\n * @param {(params: UseScrollCallbackParams, event: Event) => void} [options.onScroll] The callback function to be invoked on scroll\n * @param {(event: Event) => void} [options.onStop] The callback function to be invoked on scroll end\n * @returns {boolean} The state of scrolling\n *\n * @example\n * const scrolling = useScroll(ref, options);\n *\n * @overload\n * @template Target The target element\n * @param {(params: UseScrollCallbackParams, event: Event) => void} [callback] The callback function to be invoked on scroll\n * @returns {boolean} The state of scrolling\n *\n * @example\n * const scrolling = useScroll(ref, () => console.log('callback'));\n *\n * @overload\n * @template Target The target element\n * @param {Target} target The target element to scroll\n * @param {ScrollBehavior} [options.behavior=auto] The behavior of scrolling\n * @param {number} [options.offset.left=0] The left offset for arrived states\n * @param {number} [options.offset.right=0] The right offset for arrived states\n * @param {number} [options.offset.top=0] The top offset for arrived states\n * @param {number} [options.offset.bottom=0] The bottom offset for arrived states\n * @param {(params: UseScrollCallbackParams, event: Event) => void} [options.onScroll] The callback function to be invoked on scroll\n * @param {(event: Event) => void} [options.onStop] The callback function to be invoked on scroll end\n * @returns {[StateRef<Target>, boolean]} The state of scrolling\n *\n * @example\n * const { ref, scrolling } = useScroll(options);\n *\n * @overload\n * @template Target The target element\n * @param {Target} target The target element to scroll\n * @param {(params: UseScrollCallbackParams, event: Event) => void} [callback] The callback function to be invoked on scroll\n * @returns {[StateRef<Target>, boolean]} The state of scrolling\n *\n * @example\n * const { ref, scrolling } = useScroll(() => console.log('callback'));\n */\nexport const useScroll = ((...params: any[]) => {\n const target = (isTarget(params[0]) ? params[0] : undefined) as HookTarget | undefined;\n const options = (\n target\n ? typeof params[1] === 'object'\n ? params[1]\n : { onScroll: params[1] }\n : typeof params[0] === 'object'\n ? params[0]\n : { onScroll: params[0] }\n ) as UseScrollOptions | undefined;\n\n const internalRef = useRefState<Element>();\n const internalOptionsRef = useRef(options);\n internalOptionsRef.current = options;\n\n const [scrolling, setScrolling] = useState(false);\n const scrollPositionRef = useRef({ x: 0, y: 0 });\n\n useEffect(() => {\n if (!target && !internalRef.state) return;\n const element = (target ? getElement(target) : internalRef.current) as Element;\n\n if (!element) return;\n\n const onScrollEnd = (event: Event) => {\n setScrolling(false);\n options?.onStop?.(event);\n };\n\n const onScroll = (event: Event) => {\n setScrolling(true);\n const target = (\n event.target === document ? (event.target as Document).documentElement : event.target\n ) as HTMLElement;\n\n const { display, flexDirection, direction } = target.style;\n const directionMultiplier = direction === 'rtl' ? -1 : 1;\n\n const scrollLeft = target.scrollLeft;\n let scrollTop = target.scrollTop;\n if (target instanceof Document && !scrollTop) scrollTop = window.document.body.scrollTop;\n\n const offset = internalOptionsRef.current?.offset;\n const left = scrollLeft * directionMultiplier <= (offset?.left ?? 0);\n const right =\n scrollLeft * directionMultiplier + target.clientWidth >=\n target.scrollWidth - (offset?.right ?? 0) - ARRIVED_STATE_THRESHOLD_PIXELS;\n const top = scrollTop <= (offset?.top ?? 0);\n const bottom =\n scrollTop + target.clientHeight >=\n target.scrollHeight - (offset?.bottom ?? 0) - ARRIVED_STATE_THRESHOLD_PIXELS;\n\n const isColumnReverse = display === 'flex' && flexDirection === 'column-reverse';\n const isRowReverse = display === 'flex' && flexDirection === 'column-reverse';\n\n const params = {\n x: scrollLeft,\n y: scrollTop,\n directions: {\n left: scrollLeft < scrollPositionRef.current.x,\n right: scrollLeft > scrollPositionRef.current.x,\n top: scrollTop < scrollPositionRef.current.y,\n bottom: scrollTop > scrollPositionRef.current.y\n },\n arrived: {\n left: isRowReverse ? right : left,\n right: isRowReverse ? left : right,\n top: isColumnReverse ? bottom : top,\n bottom: isColumnReverse ? top : bottom\n }\n };\n\n scrollPositionRef.current = { x: scrollLeft, y: scrollTop };\n internalOptionsRef.current?.onScroll?.(params, event);\n };\n\n element.addEventListener('scroll', onScroll);\n element.addEventListener('scrollend', onScrollEnd);\n\n return () => {\n element.removeEventListener('scroll', onScroll);\n element.removeEventListener('scrollend', onScrollEnd);\n };\n }, [target, internalRef.state]);\n\n if (target) return scrolling;\n return {\n ref: internalRef,\n scrolling\n };\n}) as UseScroll;\n"],"names":["ARRIVED_STATE_THRESHOLD_PIXELS","useScroll","params","target","isTarget","options","internalRef","useRefState","internalOptionsRef","useRef","scrolling","setScrolling","useState","scrollPositionRef","useEffect","element","getElement","onScrollEnd","event","onScroll","display","flexDirection","direction","directionMultiplier","scrollLeft","scrollTop","offset","left","right","top","bottom","isColumnReverse","isRowReverse"],"mappings":";;;;AAUA,MAAMA,IAAiC,GAiH1BC,IAAa,IAAIC,MAAkB;AAC9C,QAAMC,IAAUC,EAASF,EAAO,CAAC,CAAC,IAAIA,EAAO,CAAC,IAAI,QAC5CG,IACJF,IACI,OAAOD,EAAO,CAAC,KAAM,WACnBA,EAAO,CAAC,IACR,EAAE,UAAUA,EAAO,CAAC,EAAA,IACtB,OAAOA,EAAO,CAAC,KAAM,WACnBA,EAAO,CAAC,IACR,EAAE,UAAUA,EAAO,CAAC,EAAA,GAGtBI,IAAcC,EAAA,GACdC,IAAqBC,EAAOJ,CAAO;AACzC,EAAAG,EAAmB,UAAUH;AAE7B,QAAM,CAACK,GAAWC,CAAY,IAAIC,EAAS,EAAK,GAC1CC,IAAoBJ,EAAO,EAAE,GAAG,GAAG,GAAG,GAAG;AAqE/C,SAnEAK,EAAU,MAAM;AACd,QAAI,CAACX,KAAU,CAACG,EAAY,MAAO;AACnC,UAAMS,IAAWZ,IAASa,EAAWb,CAAM,IAAIG,EAAY;AAE3D,QAAI,CAACS,EAAS;AAEd,UAAME,IAAc,CAACC,MAAiB;AACpC,MAAAP,EAAa,EAAK,GAClBN,GAAS,SAASa,CAAK;AAAA,IAAA,GAGnBC,IAAW,CAACD,MAAiB;AACjC,MAAAP,EAAa,EAAI;AACjB,YAAMR,IACJe,EAAM,WAAW,WAAYA,EAAM,OAAoB,kBAAkBA,EAAM,QAG3E,EAAE,SAAAE,GAAS,eAAAC,GAAe,WAAAC,EAAA,IAAcnB,EAAO,OAC/CoB,IAAsBD,MAAc,QAAQ,KAAK,GAEjDE,IAAarB,EAAO;AAC1B,UAAIsB,IAAYtB,EAAO;AACvB,MAAIA,aAAkB,YAAY,CAACsB,MAAWA,IAAY,OAAO,SAAS,KAAK;AAE/E,YAAMC,IAASlB,EAAmB,SAAS,QACrCmB,IAAOH,IAAaD,MA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View/useScrollIntoView.ts"],"sourcesContent":["import { useEffect } 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 scroll into view options type */\nexport interface UseScrollIntoViewOptions extends ScrollIntoViewOptions {\n /** Whether to enable the scroll into view */\n enabled?: boolean;\n}\n\n/** The scroll into view return type */\nexport interface UseScrollIntoViewReturn {\n /** Function to scroll element into view */\n trigger: (params?: {\n behavior?: ScrollBehavior;\n block?: ScrollLogicalPosition;\n inline?: ScrollLogicalPosition;\n }) => void;\n}\n\nexport interface UseScrollIntoView {\n <Target extends Element>(\n options?: UseScrollIntoViewOptions,\n target?: never\n ): UseScrollIntoViewReturn & { ref: StateRef<Target> };\n\n (target: HookTarget, options?: UseScrollIntoViewOptions): UseScrollIntoViewReturn;\n}\n\n/**\n * @name useScrollIntoView\n * @description - Hook that provides functionality to scroll an element into view\n * @category Sensors\n *\n * @overload\n * @param {HookTarget} target The target element to scroll into view\n * @param {ScrollBehavior} [options.behavior='smooth'] The scrolling behavior\n * @param {ScrollLogicalPosition} [options.block='start'] The vertical alignment\n * @param {ScrollLogicalPosition} [options.inline='nearest'] The horizontal alignment\n * @returns {UseScrollIntoViewReturn} Object containing scroll function\n *\n * @example\n * const { trigger } = useScrollIntoView(ref);\n *\n * @overload\n * @template Target The target element\n * @param {ScrollBehavior} [options.behavior='smooth'] The scrolling behavior\n * @param {ScrollLogicalPosition} [options.block='start'] The vertical alignment\n * @param {ScrollLogicalPosition} [options.inline='nearest'] The horizontal alignment\n * @returns {UseScrollIntoViewReturn & { ref: StateRef<Target> }} Object containing scroll function and ref\n *\n * @example\n * const { ref, trigger } = useScrollIntoView<HTMLDivElement>();\n */\nexport const useScrollIntoView = ((...params: any[]) => {\n const target = (isTarget(params[0]) ? params[0] : undefined) as HookTarget | undefined;\n const options = (target ? params[1] : params[0]) as UseScrollIntoViewOptions | undefined;\n\n const internalRef = useRefState<Element>();\n const {\n behavior = 'smooth',\n block = 'start',\n inline = 'nearest',\n enabled = true\n } = options ?? {};\n\n useEffect(() => {\n if (!enabled) return;\n if (!target && !internalRef.state) return;\n\n const element = (target ? getElement(target) : internalRef.current) as Element;\n if (!element) return;\n\n element.scrollIntoView({\n behavior,\n block,\n inline\n });\n }, [target, internalRef.state, enabled]);\n\n const trigger = (params?: {\n behavior?: ScrollBehavior;\n block?: ScrollLogicalPosition;\n inline?: ScrollLogicalPosition;\n }) => {\n const element = (target ? getElement(target) : internalRef.current) as Element;\n if (!element) return;\n\n const { behavior, block, inline } = params ?? {};\n\n element.scrollIntoView({\n behavior,\n block,\n inline\n });\n };\n\n if (target) return { trigger };\n return { ref: internalRef, trigger };\n}) as UseScrollIntoView;\n"],"names":["useScrollIntoView","params","target","isTarget","options","internalRef","useRefState","behavior","block","inline","enabled","useEffect","element","getElement","trigger"],"mappings":";;;;AA4DO,MAAMA,IAAqB,IAAIC,MAAkB;AACtD,QAAMC,IAAUC,EAASF,EAAO,CAAC,CAAC,IAAIA,EAAO,CAAC,IAAI,QAC5CG,IAAWF,IAASD,EAAO,CAAC,IAAIA,EAAO,CAAC,GAExCI,IAAcC,EAAA,GACd;AAAA,IACJ,UAAAC,IAAW;AAAA,IACX,OAAAC,IAAQ;AAAA,IACR,QAAAC,IAAS;AAAA,IACT,SAAAC,IAAU;AAAA,EAAA,IACRN,KAAW,CAAA;AAEf,EAAAO,EAAU,MAAM;AAEd,QADI,CAACD,KACD,CAACR,KAAU,CAACG,EAAY,MAAO;AAEnC,UAAMO,IAAWV,IAASW,EAAWX,CAAM,IAAIG,EAAY;AAC3D,IAAKO,KAELA,EAAQ,eAAe;AAAA,MACrB,UAAAL;AAAA,MACA,OAAAC;AAAA,MACA,QAAAC;AAAA,IAAA,CACD;AAAA,EAAA,GACA,CAACP,GAAQG,EAAY,OAAOK,CAAO,CAAC;AAEvC,QAAMI,IAAU,CAACb,MAIX;AACJ,UAAMW,IAAWV,IAASW,EAAWX,CAAM,IAAIG,EAAY;AAC3D,QAAI,CAACO,EAAS;AAEd,UAAM,EAAE,UAAAL,GAAU,OAAAC,GAAO,QAAAC,MAAWR,KAAU,CAAA;AAE9C,IAAAW,EAAQ,eAAe;AAAA,MACrB,UAAAL;AAAAA,MACA,OAAAC;AAAAA,MACA,QAAAC;AAAAA,IAAA,CACD;AAAA,EAAA;AAGH,SAAIP,IAAe,EAAE,SAAAY,EAAA,IACd,EAAE,KAAKT,GAAa,SAAAS,EAAA;AAC7B;"}
1
+ {"version":3,"file":"useScrollIntoView.mjs","sources":["../../../../src/hooks/useScrollIntoView/useScrollIntoView.ts"],"sourcesContent":["import { useEffect } 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 scroll into view options type */\nexport interface UseScrollIntoViewOptions extends ScrollIntoViewOptions {\n /** Whether to enable the scroll into view */\n enabled?: boolean;\n}\n\n/** The scroll into view return type */\nexport interface UseScrollIntoViewReturn {\n /** Function to scroll element into view */\n trigger: (params?: {\n behavior?: ScrollBehavior;\n block?: ScrollLogicalPosition;\n inline?: ScrollLogicalPosition;\n }) => void;\n}\n\nexport interface UseScrollIntoView {\n <Target extends Element>(\n options?: UseScrollIntoViewOptions,\n target?: never\n ): UseScrollIntoViewReturn & { ref: StateRef<Target> };\n\n (target: HookTarget, options?: UseScrollIntoViewOptions): UseScrollIntoViewReturn;\n}\n\n/**\n * @name useScrollIntoView\n * @description - Hook that provides functionality to scroll an element into view\n * @category Sensors\n * @usage low\n *\n * @overload\n * @param {HookTarget} target The target element to scroll into view\n * @param {ScrollBehavior} [options.behavior='smooth'] The scrolling behavior\n * @param {ScrollLogicalPosition} [options.block='start'] The vertical alignment\n * @param {ScrollLogicalPosition} [options.inline='nearest'] The horizontal alignment\n * @returns {UseScrollIntoViewReturn} Object containing scroll function\n *\n * @example\n * const { trigger } = useScrollIntoView(ref);\n *\n * @overload\n * @template Target The target element\n * @param {ScrollBehavior} [options.behavior='smooth'] The scrolling behavior\n * @param {ScrollLogicalPosition} [options.block='start'] The vertical alignment\n * @param {ScrollLogicalPosition} [options.inline='nearest'] The horizontal alignment\n * @returns {UseScrollIntoViewReturn & { ref: StateRef<Target> }} Object containing scroll function and ref\n *\n * @example\n * const { ref, trigger } = useScrollIntoView<HTMLDivElement>();\n */\nexport const useScrollIntoView = ((...params: any[]) => {\n const target = (isTarget(params[0]) ? params[0] : undefined) as HookTarget | undefined;\n const options = (target ? params[1] : params[0]) as UseScrollIntoViewOptions | undefined;\n\n const internalRef = useRefState<Element>();\n const {\n behavior = 'smooth',\n block = 'start',\n inline = 'nearest',\n enabled = true\n } = options ?? {};\n\n useEffect(() => {\n if (!enabled) return;\n if (!target && !internalRef.state) return;\n\n const element = (target ? getElement(target) : internalRef.current) as Element;\n if (!element) return;\n\n element.scrollIntoView({\n behavior,\n block,\n inline\n });\n }, [target, internalRef.state, enabled]);\n\n const trigger = (params?: {\n behavior?: ScrollBehavior;\n block?: ScrollLogicalPosition;\n inline?: ScrollLogicalPosition;\n }) => {\n const element = (target ? getElement(target) : internalRef.current) as Element;\n if (!element) return;\n\n const { behavior, block, inline } = params ?? {};\n\n element.scrollIntoView({\n behavior,\n block,\n inline\n });\n };\n\n if (target) return { trigger };\n return { ref: internalRef, trigger };\n}) as UseScrollIntoView;\n"],"names":["useScrollIntoView","params","target","isTarget","options","internalRef","useRefState","behavior","block","inline","enabled","useEffect","element","getElement","trigger"],"mappings":";;;;AA6DO,MAAMA,IAAqB,IAAIC,MAAkB;AACtD,QAAMC,IAAUC,EAASF,EAAO,CAAC,CAAC,IAAIA,EAAO,CAAC,IAAI,QAC5CG,IAAWF,IAASD,EAAO,CAAC,IAAIA,EAAO,CAAC,GAExCI,IAAcC,EAAA,GACd;AAAA,IACJ,UAAAC,IAAW;AAAA,IACX,OAAAC,IAAQ;AAAA,IACR,QAAAC,IAAS;AAAA,IACT,SAAAC,IAAU;AAAA,EAAA,IACRN,KAAW,CAAA;AAEf,EAAAO,EAAU,MAAM;AAEd,QADI,CAACD,KACD,CAACR,KAAU,CAACG,EAAY,MAAO;AAEnC,UAAMO,IAAWV,IAASW,EAAWX,CAAM,IAAIG,EAAY;AAC3D,IAAKO,KAELA,EAAQ,eAAe;AAAA,MACrB,UAAAL;AAAA,MACA,OAAAC;AAAA,MACA,QAAAC;AAAA,IAAA,CACD;AAAA,EAAA,GACA,CAACP,GAAQG,EAAY,OAAOK,CAAO,CAAC;AAEvC,QAAMI,IAAU,CAACb,MAIX;AACJ,UAAMW,IAAWV,IAASW,EAAWX,CAAM,IAAIG,EAAY;AAC3D,QAAI,CAACO,EAAS;AAEd,UAAM,EAAE,UAAAL,GAAU,OAAAC,GAAO,QAAAC,MAAWR,KAAU,CAAA;AAE9C,IAAAW,EAAQ,eAAe;AAAA,MACrB,UAAAL;AAAAA,MACA,OAAAC;AAAAA,MACA,QAAAC;AAAAA,IAAA,CACD;AAAA,EAAA;AAGH,SAAIP,IAAe,EAAE,SAAAY,EAAA,IACd,EAAE,KAAKT,GAAa,SAAAS,EAAA;AAC7B;"}
@@ -1 +1 @@
1
- {"version":3,"file":"useScrollTo.mjs","sources":["../../../../src/hooks/useScrollTo/useScrollTo.ts"],"sourcesContent":["import { useLayoutEffect } 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 scroll to options type */\nexport interface UseScrollToOptions {\n /** The scrolling behavior */\n behavior?: ScrollBehavior;\n /** Whether to enable the scroll to */\n enabled?: boolean;\n /** The horizontal position to scroll to */\n x: number;\n /** The vertical position to scroll to */\n y: number;\n}\n\n/** The use scroll to return type */\nexport interface UseScrollToReturn {\n /** The state of scrolling */\n trigger: (params?: { x: number; y: number; behavior?: ScrollBehavior }) => void;\n}\n\nexport interface UseScrollTo {\n <Target extends Element>(\n options?: UseScrollToOptions,\n target?: never\n ): UseScrollToReturn & { ref: StateRef<Target> };\n\n (target: HookTarget, options?: UseScrollToOptions): UseScrollToReturn;\n}\n\n/**\n * @name useScrollTo\n * @description - Hook for scrolling to a specific element\n * @category Sensors\n *\n * @overload\n * @param {HookTarget} target The target element for scrolling to\n * @param {UseScrollToOptions} [options] The scroll options\n * @returns {UseScrollToReturn} The scroll trigger function\n *\n * @example\n * const trigger = useScrollTo(ref, options);\n *\n * @overload\n * @template Target The target element\n * @param {UseScrollToOptions} [options] The scroll options\n * @returns {UseScrollToReturn & { ref: StateRef<Target> }} The scroll trigger function and ref\n *\n * @example\n * const { ref, trigger } = useScrollTo(options);\n */\nexport const useScrollTo = ((...params: any[]) => {\n const target = (isTarget(params[0]) ? params[0] : undefined) as HookTarget | undefined;\n const options = (target ? params[1] : params[0]) as UseScrollToOptions | undefined;\n const { x, y, behavior = 'auto', enabled = true } = options ?? {};\n const internalRef = useRefState<Element>();\n\n useLayoutEffect(() => {\n if (!enabled) return;\n if (!target && !internalRef.state) return;\n\n const element = (target ? getElement(target) : internalRef.current) as Element;\n if (!element) return;\n\n element.scrollTo({ top: y, left: x, behavior });\n }, [target, internalRef.state]);\n\n const trigger = (params?: { x: number; y: number; behavior?: ScrollBehavior }) => {\n const element = (target ? getElement(target) : internalRef.current) as Element;\n if (!element) return;\n const { x, y, behavior } = params ?? {};\n\n element.scrollTo({ left: x, top: y, behavior });\n };\n\n if (target) return { trigger };\n return { ref: internalRef, trigger };\n}) as UseScrollTo;\n"],"names":["useScrollTo","params","target","isTarget","options","x","y","behavior","enabled","internalRef","useRefState","useLayoutEffect","element","getElement","trigger"],"mappings":";;;;AA0DO,MAAMA,IAAe,IAAIC,MAAkB;AAChD,QAAMC,IAAUC,EAASF,EAAO,CAAC,CAAC,IAAIA,EAAO,CAAC,IAAI,QAC5CG,IAAWF,IAASD,EAAO,CAAC,IAAIA,EAAO,CAAC,GACxC,EAAE,GAAAI,GAAG,GAAAC,GAAG,UAAAC,IAAW,QAAQ,SAAAC,IAAU,OAASJ,KAAW,CAAA,GACzDK,IAAcC,EAAA;AAEpB,EAAAC,EAAgB,MAAM;AAEpB,QADI,CAACH,KACD,CAACN,KAAU,CAACO,EAAY,MAAO;AAEnC,UAAMG,IAAWV,IAASW,EAAWX,CAAM,IAAIO,EAAY;AAC3D,IAAKG,KAELA,EAAQ,SAAS,EAAE,KAAKN,GAAG,MAAMD,GAAG,UAAAE,GAAU;AAAA,EAAA,GAC7C,CAACL,GAAQO,EAAY,KAAK,CAAC;AAE9B,QAAMK,IAAU,CAACb,MAAiE;AAChF,UAAMW,IAAWV,IAASW,EAAWX,CAAM,IAAIO,EAAY;AAC3D,QAAI,CAACG,EAAS;AACd,UAAM,EAAE,GAAAP,GAAG,GAAAC,GAAG,UAAAC,MAAaN,KAAU,CAAA;AAErC,IAAAW,EAAQ,SAAS,EAAE,MAAMP,GAAG,KAAKC,GAAG,UAAAC,GAAU;AAAA,EAAA;AAGhD,SAAIL,IAAe,EAAE,SAAAY,EAAA,IACd,EAAE,KAAKL,GAAa,SAAAK,EAAA;AAC7B;"}
1
+ {"version":3,"file":"useScrollTo.mjs","sources":["../../../../src/hooks/useScrollTo/useScrollTo.ts"],"sourcesContent":["import { useLayoutEffect } 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 scroll to options type */\nexport interface UseScrollToOptions {\n /** The scrolling behavior */\n behavior?: ScrollBehavior;\n /** Whether to enable the scroll to */\n enabled?: boolean;\n /** The horizontal position to scroll to */\n x: number;\n /** The vertical position to scroll to */\n y: number;\n}\n\n/** The use scroll to return type */\nexport interface UseScrollToReturn {\n /** The state of scrolling */\n trigger: (params?: { x: number; y: number; behavior?: ScrollBehavior }) => void;\n}\n\nexport interface UseScrollTo {\n <Target extends Element>(\n options?: UseScrollToOptions,\n target?: never\n ): UseScrollToReturn & { ref: StateRef<Target> };\n\n (target: HookTarget, options?: UseScrollToOptions): UseScrollToReturn;\n}\n\n/**\n * @name useScrollTo\n * @description - Hook for scrolling to a specific element\n * @category Sensors\n * @usage low\n *\n * @overload\n * @param {HookTarget} target The target element for scrolling to\n * @param {UseScrollToOptions} [options] The scroll options\n * @returns {UseScrollToReturn} The scroll trigger function\n *\n * @example\n * const trigger = useScrollTo(ref, options);\n *\n * @overload\n * @template Target The target element\n * @param {UseScrollToOptions} [options] The scroll options\n * @returns {UseScrollToReturn & { ref: StateRef<Target> }} The scroll trigger function and ref\n *\n * @example\n * const { ref, trigger } = useScrollTo(options);\n */\nexport const useScrollTo = ((...params: any[]) => {\n const target = (isTarget(params[0]) ? params[0] : undefined) as HookTarget | undefined;\n const options = (target ? params[1] : params[0]) as UseScrollToOptions | undefined;\n const { x, y, behavior = 'auto', enabled = true } = options ?? {};\n const internalRef = useRefState<Element>();\n\n useLayoutEffect(() => {\n if (!enabled) return;\n if (!target && !internalRef.state) return;\n\n const element = (target ? getElement(target) : internalRef.current) as Element;\n if (!element) return;\n\n element.scrollTo({ top: y, left: x, behavior });\n }, [target, internalRef.state]);\n\n const trigger = (params?: { x: number; y: number; behavior?: ScrollBehavior }) => {\n const element = (target ? getElement(target) : internalRef.current) as Element;\n if (!element) return;\n const { x, y, behavior } = params ?? {};\n\n element.scrollTo({ left: x, top: y, behavior });\n };\n\n if (target) return { trigger };\n return { ref: internalRef, trigger };\n}) as UseScrollTo;\n"],"names":["useScrollTo","params","target","isTarget","options","x","y","behavior","enabled","internalRef","useRefState","useLayoutEffect","element","getElement","trigger"],"mappings":";;;;AA2DO,MAAMA,IAAe,IAAIC,MAAkB;AAChD,QAAMC,IAAUC,EAASF,EAAO,CAAC,CAAC,IAAIA,EAAO,CAAC,IAAI,QAC5CG,IAAWF,IAASD,EAAO,CAAC,IAAIA,EAAO,CAAC,GACxC,EAAE,GAAAI,GAAG,GAAAC,GAAG,UAAAC,IAAW,QAAQ,SAAAC,IAAU,OAASJ,KAAW,CAAA,GACzDK,IAAcC,EAAA;AAEpB,EAAAC,EAAgB,MAAM;AAEpB,QADI,CAACH,KACD,CAACN,KAAU,CAACO,EAAY,MAAO;AAEnC,UAAMG,IAAWV,IAASW,EAAWX,CAAM,IAAIO,EAAY;AAC3D,IAAKG,KAELA,EAAQ,SAAS,EAAE,KAAKN,GAAG,MAAMD,GAAG,UAAAE,GAAU;AAAA,EAAA,GAC7C,CAACL,GAAQO,EAAY,KAAK,CAAC;AAE9B,QAAMK,IAAU,CAACb,MAAiE;AAChF,UAAMW,IAAWV,IAASW,EAAWX,CAAM,IAAIO,EAAY;AAC3D,QAAI,CAACG,EAAS;AACd,UAAM,EAAE,GAAAP,GAAG,GAAAC,GAAG,UAAAC,MAAaN,KAAU,CAAA;AAErC,IAAAW,EAAQ,SAAS,EAAE,MAAMP,GAAG,KAAKC,GAAG,UAAAC,GAAU;AAAA,EAAA;AAGhD,SAAIL,IAAe,EAAE,SAAAY,EAAA,IACd,EAAE,KAAKL,GAAa,SAAAK,EAAA;AAC7B;"}
@@ -1 +1 @@
1
- {"version":3,"file":"useSessionStorage.mjs","sources":["../../../../src/hooks/useSessionStorage/useSessionStorage.ts"],"sourcesContent":["import type { UseStorageInitialValue, UseStorageOptions } from '../useStorage/useStorage';\n\nimport { useStorage } from '../useStorage/useStorage';\n\n/**\n * @name useSessionStorage\n * @description - Hook that manages session storage value\n * @category State\n *\n * @browserapi sessionStorage https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage\n *\n * @template Value The type of the value\n * @param {string} key The key of the storage\n * @param {UseStorageInitialValue<Value>} [initialValue] The initial value of the storage\n * @param {UseStorageOptions<Value>} [options] The options of the storage\n *\n * @example\n * const { value, set, remove } = useSessionStorage('key', 'value');\n */\nexport const useSessionStorage = <Value>(\n key: string,\n initialValue?: UseStorageInitialValue<Value>,\n options?: Omit<UseStorageOptions<Value>, 'initialValue' | 'storage'>\n) =>\n useStorage(key, {\n ...options,\n initialValue,\n storage: typeof window !== 'undefined' ? window.sessionStorage : undefined\n });\n"],"names":["useSessionStorage","key","initialValue","options","useStorage"],"mappings":";AAmBO,MAAMA,IAAoB,CAC/BC,GACAC,GACAC,MAEAC,EAAWH,GAAK;AAAA,EACd,GAAGE;AAAA,EACH,cAAAD;AAAA,EACA,SAAS,OAAO,SAAW,MAAc,OAAO,iBAAiB;AACnE,CAAC;"}
1
+ {"version":3,"file":"useSessionStorage.mjs","sources":["../../../../src/hooks/useSessionStorage/useSessionStorage.ts"],"sourcesContent":["import type { UseStorageInitialValue, UseStorageOptions } from '../useStorage/useStorage';\n\nimport { useStorage } from '../useStorage/useStorage';\n\n/**\n * @name useSessionStorage\n * @description - Hook that manages session storage value\n * @category State\n * @usage medium\n *\n * @browserapi sessionStorage https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage\n *\n * @template Value The type of the value\n * @param {string} key The key of the storage\n * @param {UseStorageInitialValue<Value>} [initialValue] The initial value of the storage\n * @param {UseStorageOptions<Value>} [options] The options of the storage\n *\n * @example\n * const { value, set, remove } = useSessionStorage('key', 'value');\n */\nexport const useSessionStorage = <Value>(\n key: string,\n initialValue?: UseStorageInitialValue<Value>,\n options?: Omit<UseStorageOptions<Value>, 'initialValue' | 'storage'>\n) =>\n useStorage(key, {\n ...options,\n initialValue,\n storage: typeof window !== 'undefined' ? window.sessionStorage : undefined\n });\n"],"names":["useSessionStorage","key","initialValue","options","useStorage"],"mappings":";AAoBO,MAAMA,IAAoB,CAC/BC,GACAC,GACAC,MAEAC,EAAWH,GAAK;AAAA,EACd,GAAGE;AAAA,EACH,cAAAD;AAAA,EACA,SAAS,OAAO,SAAW,MAAc,OAAO,iBAAiB;AACnE,CAAC;"}
@@ -1 +1 @@
1
- {"version":3,"file":"useSet.mjs","sources":["../../../../src/hooks/useSet/useSet.ts"],"sourcesContent":["import { useState } from 'react';\n\n/** The use set return type */\ninterface UseSetReturn<Value> {\n /** The size of the set */\n size: number;\n /** The current set */\n value: Set<Value>;\n /** Function to add a value to the set */\n add: (value: Value) => void;\n /** Function to clear the set */\n clear: () => void;\n /** Function to get the symmetric difference of two sets */\n difference: (other: Set<Value>) => void;\n /** Function to check if a value exists in the set */\n has: (value: Value) => boolean;\n /** Function to get the difference of two sets */\n intersection: (other: Set<Value>) => void;\n /** Function to remove a value from the set */\n remove: (value: Value) => void;\n /** Function to toggle a value in the set */\n reset: () => void;\n /** Function to get the symmetric difference of two sets */\n symmetricDifference: (other: Set<Value>) => void;\n /** Function to toggle a value in the set */\n toggle: (value: Value) => void;\n /** Function to get the union of two sets */\n union: (other: Set<Value>) => void;\n}\n\n/**\n * @name useSet\n * @description - Hook that manages a set structure\n * @category State\n *\n * @template Value The type of the value\n * @param {Value[]} [values] The initial array of the set\n * @returns {UseSetReturn<Value>} An object containing the current set and functions to interact with the set\n *\n * @example\n * const { value, add, remove, clear, reset, toggle, union, intersection, difference, symmetricDifference, size, has } = useSet([1, 2, 3]);\n */\nexport const useSet = <Value>(values?: Value[]): UseSetReturn<Value> => {\n const [set, setSet] = useState(new Set(values));\n\n const add = (value: Value) => setSet((prevSet) => new Set(prevSet).add(value));\n const remove = (value: Value) =>\n setSet((prevSet) => {\n if (!prevSet.has(value)) return prevSet;\n const newSet = new Set(prevSet);\n newSet.delete(value);\n return newSet;\n });\n const clear = () => setSet(new Set());\n const reset = () => setSet(new Set(values));\n const toggle = (value: Value) =>\n setSet((prevSet) => {\n if (!prevSet.has(value)) return new Set(prevSet).add(value);\n const newSet = new Set(prevSet);\n newSet.delete(value);\n return newSet;\n });\n const union = (other: Set<Value>) => setSet(set.union(other));\n const difference = (other: Set<Value>) => setSet(set.difference(other));\n const symmetricDifference = (other: Set<Value>) => setSet(set.symmetricDifference(other));\n const intersection = (other: Set<Value>) => setSet(set.intersection(other));\n const has = (value: Value) => set.has(value);\n\n return {\n value: set,\n size: set.size,\n has,\n add,\n remove,\n clear,\n reset,\n toggle,\n union,\n difference,\n symmetricDifference,\n intersection\n };\n};\n"],"names":["useSet","values","set","setSet","useState","add","value","prevSet","remove","newSet","clear","reset","toggle","union","other","difference","symmetricDifference","intersection","has"],"mappings":";AA0CO,MAAMA,IAAS,CAAQC,MAA0C;AACtE,QAAM,CAACC,GAAKC,CAAM,IAAIC,EAAS,IAAI,IAAIH,CAAM,CAAC,GAExCI,IAAM,CAACC,MAAiBH,EAAO,CAACI,MAAY,IAAI,IAAIA,CAAO,EAAE,IAAID,CAAK,CAAC,GACvEE,IAAS,CAACF,MACdH,EAAO,CAACI,MAAY;AAClB,QAAI,CAACA,EAAQ,IAAID,CAAK,EAAG,QAAOC;AAChC,UAAME,IAAS,IAAI,IAAIF,CAAO;AAC9B,WAAAE,EAAO,OAAOH,CAAK,GACZG;AAAA,EAAA,CACR,GACGC,IAAQ,MAAMP,EAAO,oBAAI,KAAK,GAC9BQ,IAAQ,MAAMR,EAAO,IAAI,IAAIF,CAAM,CAAC,GACpCW,IAAS,CAACN,MACdH,EAAO,CAACI,MAAY;AAClB,QAAI,CAACA,EAAQ,IAAID,CAAK,EAAG,QAAO,IAAI,IAAIC,CAAO,EAAE,IAAID,CAAK;AAC1D,UAAMG,IAAS,IAAI,IAAIF,CAAO;AAC9B,WAAAE,EAAO,OAAOH,CAAK,GACZG;AAAA,EAAA,CACR,GACGI,IAAQ,CAACC,MAAsBX,EAAOD,EAAI,MAAMY,CAAK,CAAC,GACtDC,IAAa,CAACD,MAAsBX,EAAOD,EAAI,WAAWY,CAAK,CAAC,GAChEE,IAAsB,CAACF,MAAsBX,EAAOD,EAAI,oBAAoBY,CAAK,CAAC,GAClFG,IAAe,CAACH,MAAsBX,EAAOD,EAAI,aAAaY,CAAK,CAAC,GACpEI,IAAM,CAACZ,MAAiBJ,EAAI,IAAII,CAAK;AAE3C,SAAO;AAAA,IACL,OAAOJ;AAAA,IACP,MAAMA,EAAI;AAAA,IACV,KAAAgB;AAAA,IACA,KAAAb;AAAA,IACA,QAAAG;AAAA,IACA,OAAAE;AAAA,IACA,OAAAC;AAAA,IACA,QAAAC;AAAA,IACA,OAAAC;AAAA,IACA,YAAAE;AAAA,IACA,qBAAAC;AAAA,IACA,cAAAC;AAAA,EAAA;AAEJ;"}
1
+ {"version":3,"file":"useSet.mjs","sources":["../../../../src/hooks/useSet/useSet.ts"],"sourcesContent":["import { useState } from 'react';\n\n/** The use set return type */\ninterface UseSetReturn<Value> {\n /** The size of the set */\n size: number;\n /** The current set */\n value: Set<Value>;\n /** Function to add a value to the set */\n add: (value: Value) => void;\n /** Function to clear the set */\n clear: () => void;\n /** Function to get the symmetric difference of two sets */\n difference: (other: Set<Value>) => void;\n /** Function to check if a value exists in the set */\n has: (value: Value) => boolean;\n /** Function to get the difference of two sets */\n intersection: (other: Set<Value>) => void;\n /** Function to remove a value from the set */\n remove: (value: Value) => void;\n /** Function to toggle a value in the set */\n reset: () => void;\n /** Function to get the symmetric difference of two sets */\n symmetricDifference: (other: Set<Value>) => void;\n /** Function to toggle a value in the set */\n toggle: (value: Value) => void;\n /** Function to get the union of two sets */\n union: (other: Set<Value>) => void;\n}\n\n/**\n * @name useSet\n * @description - Hook that manages a set structure\n * @category State\n * @usage medium\n *\n * @template Value The type of the value\n * @param {Value[]} [values] The initial array of the set\n * @returns {UseSetReturn<Value>} An object containing the current set and functions to interact with the set\n *\n * @example\n * const { value, add, remove, clear, reset, toggle, union, intersection, difference, symmetricDifference, size, has } = useSet([1, 2, 3]);\n */\nexport const useSet = <Value>(values?: Value[]): UseSetReturn<Value> => {\n const [set, setSet] = useState(new Set(values));\n\n const add = (value: Value) => setSet((prevSet) => new Set(prevSet).add(value));\n const remove = (value: Value) =>\n setSet((prevSet) => {\n if (!prevSet.has(value)) return prevSet;\n const newSet = new Set(prevSet);\n newSet.delete(value);\n return newSet;\n });\n const clear = () => setSet(new Set());\n const reset = () => setSet(new Set(values));\n const toggle = (value: Value) =>\n setSet((prevSet) => {\n if (!prevSet.has(value)) return new Set(prevSet).add(value);\n const newSet = new Set(prevSet);\n newSet.delete(value);\n return newSet;\n });\n const union = (other: Set<Value>) => setSet(set.union(other));\n const difference = (other: Set<Value>) => setSet(set.difference(other));\n const symmetricDifference = (other: Set<Value>) => setSet(set.symmetricDifference(other));\n const intersection = (other: Set<Value>) => setSet(set.intersection(other));\n const has = (value: Value) => set.has(value);\n\n return {\n value: set,\n size: set.size,\n has,\n add,\n remove,\n clear,\n reset,\n toggle,\n union,\n difference,\n symmetricDifference,\n intersection\n };\n};\n"],"names":["useSet","values","set","setSet","useState","add","value","prevSet","remove","newSet","clear","reset","toggle","union","other","difference","symmetricDifference","intersection","has"],"mappings":";AA2CO,MAAMA,IAAS,CAAQC,MAA0C;AACtE,QAAM,CAACC,GAAKC,CAAM,IAAIC,EAAS,IAAI,IAAIH,CAAM,CAAC,GAExCI,IAAM,CAACC,MAAiBH,EAAO,CAACI,MAAY,IAAI,IAAIA,CAAO,EAAE,IAAID,CAAK,CAAC,GACvEE,IAAS,CAACF,MACdH,EAAO,CAACI,MAAY;AAClB,QAAI,CAACA,EAAQ,IAAID,CAAK,EAAG,QAAOC;AAChC,UAAME,IAAS,IAAI,IAAIF,CAAO;AAC9B,WAAAE,EAAO,OAAOH,CAAK,GACZG;AAAA,EAAA,CACR,GACGC,IAAQ,MAAMP,EAAO,oBAAI,KAAK,GAC9BQ,IAAQ,MAAMR,EAAO,IAAI,IAAIF,CAAM,CAAC,GACpCW,IAAS,CAACN,MACdH,EAAO,CAACI,MAAY;AAClB,QAAI,CAACA,EAAQ,IAAID,CAAK,EAAG,QAAO,IAAI,IAAIC,CAAO,EAAE,IAAID,CAAK;AAC1D,UAAMG,IAAS,IAAI,IAAIF,CAAO;AAC9B,WAAAE,EAAO,OAAOH,CAAK,GACZG;AAAA,EAAA,CACR,GACGI,IAAQ,CAACC,MAAsBX,EAAOD,EAAI,MAAMY,CAAK,CAAC,GACtDC,IAAa,CAACD,MAAsBX,EAAOD,EAAI,WAAWY,CAAK,CAAC,GAChEE,IAAsB,CAACF,MAAsBX,EAAOD,EAAI,oBAAoBY,CAAK,CAAC,GAClFG,IAAe,CAACH,MAAsBX,EAAOD,EAAI,aAAaY,CAAK,CAAC,GACpEI,IAAM,CAACZ,MAAiBJ,EAAI,IAAII,CAAK;AAE3C,SAAO;AAAA,IACL,OAAOJ;AAAA,IACP,MAAMA,EAAI;AAAA,IACV,KAAAgB;AAAA,IACA,KAAAb;AAAA,IACA,QAAAG;AAAA,IACA,OAAAE;AAAA,IACA,OAAAC;AAAA,IACA,QAAAC;AAAA,IACA,OAAAC;AAAA,IACA,YAAAE;AAAA,IACA,qBAAAC;AAAA,IACA,cAAAC;AAAA,EAAA;AAEJ;"}
@@ -1 +1 @@
1
- {"version":3,"file":"useShallowEffect.mjs","sources":["../../../../src/hooks/useShallowEffect/useShallowEffect.ts"],"sourcesContent":["import type { DependencyList, EffectCallback } from 'react';\n\nimport { useEffect, useRef } from 'react';\n\nexport const deepEqual = (a: any, b: any): boolean => {\n if (a === b) return true;\n if (a == null || b == null) return a === b;\n if (typeof a !== typeof b) return false;\n if (typeof a !== 'object') return a === b;\n if (Array.isArray(a) !== Array.isArray(b)) return false;\n\n if (Array.isArray(a))\n return a.length === b.length && a.every((value, index) => deepEqual(value, b[index]));\n\n const keysA = Object.keys(a);\n const keysB = Object.keys(b);\n\n if (keysA.length !== keysB.length) return false;\n\n for (const key of keysA) {\n if (!keysB.includes(key)) return false;\n if (!deepEqual(a[key], b[key])) return false;\n }\n\n return true;\n};\n\n/**\n * @name useShallowEffect\n * @description - Hook that executes an effect only when dependencies change shallowly or deeply\n * @category Lifecycle\n *\n * @param {EffectCallback} effect The effect callback\n * @param {DependencyList} [deps] The dependencies list for the effect\n *\n * @example\n * useShallowEffect(() => console.log(\"effect\"), [user]);\n */\nexport const useShallowEffect = (effect: EffectCallback, deps?: DependencyList) => {\n const depsRef = useRef<DependencyList>(deps);\n\n if (!depsRef.current || !deepEqual(deps, depsRef.current)) {\n depsRef.current = deps;\n }\n\n useEffect(effect, depsRef.current);\n};\n"],"names":["deepEqual","a","b","value","index","keysA","keysB","key","useShallowEffect","effect","deps","depsRef","useRef","useEffect"],"mappings":";AAIO,MAAMA,IAAY,CAACC,GAAQC,MAAoB;AACpD,MAAID,MAAMC,EAAG,QAAO;AACpB,MAAID,KAAK,QAAQC,KAAK,aAAaD,MAAMC;AACzC,MAAI,OAAOD,KAAM,OAAOC,EAAG,QAAO;AAClC,MAAI,OAAOD,KAAM,SAAU,QAAOA,MAAMC;AACxC,MAAI,MAAM,QAAQD,CAAC,MAAM,MAAM,QAAQC,CAAC,EAAG,QAAO;AAElD,MAAI,MAAM,QAAQD,CAAC;AACjB,WAAOA,EAAE,WAAWC,EAAE,UAAUD,EAAE,MAAM,CAACE,GAAOC,MAAUJ,EAAUG,GAAOD,EAAEE,CAAK,CAAC,CAAC;AAEtF,QAAMC,IAAQ,OAAO,KAAKJ,CAAC,GACrBK,IAAQ,OAAO,KAAKJ,CAAC;AAE3B,MAAIG,EAAM,WAAWC,EAAM,OAAQ,QAAO;AAE1C,aAAWC,KAAOF;AAEhB,QADI,CAACC,EAAM,SAASC,CAAG,KACnB,CAACP,EAAUC,EAAEM,CAAG,GAAGL,EAAEK,CAAG,CAAC,EAAG,QAAO;AAGzC,SAAO;AACT,GAaaC,IAAmB,CAACC,GAAwBC,MAA0B;AACjF,QAAMC,IAAUC,EAAuBF,CAAI;AAE3C,GAAI,CAACC,EAAQ,WAAW,CAACX,EAAUU,GAAMC,EAAQ,OAAO,OACtDA,EAAQ,UAAUD,IAGpBG,EAAUJ,GAAQE,EAAQ,OAAO;AACnC;"}
1
+ {"version":3,"file":"useShallowEffect.mjs","sources":["../../../../src/hooks/useShallowEffect/useShallowEffect.ts"],"sourcesContent":["import type { DependencyList, EffectCallback } from 'react';\n\nimport { useEffect, useRef } from 'react';\n\nexport const deepEqual = (a: any, b: any): boolean => {\n if (a === b) return true;\n if (a == null || b == null) return a === b;\n if (typeof a !== typeof b) return false;\n if (typeof a !== 'object') return a === b;\n if (Array.isArray(a) !== Array.isArray(b)) return false;\n\n if (Array.isArray(a))\n return a.length === b.length && a.every((value, index) => deepEqual(value, b[index]));\n\n const keysA = Object.keys(a);\n const keysB = Object.keys(b);\n\n if (keysA.length !== keysB.length) return false;\n\n for (const key of keysA) {\n if (!keysB.includes(key)) return false;\n if (!deepEqual(a[key], b[key])) return false;\n }\n\n return true;\n};\n\n/**\n * @name useShallowEffect\n * @description - Hook that executes an effect only when dependencies change shallowly or deeply\n * @category Lifecycle\n * @usage low\n *\n * @param {EffectCallback} effect The effect callback\n * @param {DependencyList} [deps] The dependencies list for the effect\n *\n * @example\n * useShallowEffect(() => console.log(\"effect\"), [user]);\n */\nexport const useShallowEffect = (effect: EffectCallback, deps?: DependencyList) => {\n const depsRef = useRef<DependencyList>(deps);\n\n if (!depsRef.current || !deepEqual(deps, depsRef.current)) {\n depsRef.current = deps;\n }\n\n useEffect(effect, depsRef.current);\n};\n"],"names":["deepEqual","a","b","value","index","keysA","keysB","key","useShallowEffect","effect","deps","depsRef","useRef","useEffect"],"mappings":";AAIO,MAAMA,IAAY,CAACC,GAAQC,MAAoB;AACpD,MAAID,MAAMC,EAAG,QAAO;AACpB,MAAID,KAAK,QAAQC,KAAK,aAAaD,MAAMC;AACzC,MAAI,OAAOD,KAAM,OAAOC,EAAG,QAAO;AAClC,MAAI,OAAOD,KAAM,SAAU,QAAOA,MAAMC;AACxC,MAAI,MAAM,QAAQD,CAAC,MAAM,MAAM,QAAQC,CAAC,EAAG,QAAO;AAElD,MAAI,MAAM,QAAQD,CAAC;AACjB,WAAOA,EAAE,WAAWC,EAAE,UAAUD,EAAE,MAAM,CAACE,GAAOC,MAAUJ,EAAUG,GAAOD,EAAEE,CAAK,CAAC,CAAC;AAEtF,QAAMC,IAAQ,OAAO,KAAKJ,CAAC,GACrBK,IAAQ,OAAO,KAAKJ,CAAC;AAE3B,MAAIG,EAAM,WAAWC,EAAM,OAAQ,QAAO;AAE1C,aAAWC,KAAOF;AAEhB,QADI,CAACC,EAAM,SAASC,CAAG,KACnB,CAACP,EAAUC,EAAEM,CAAG,GAAGL,EAAEK,CAAG,CAAC,EAAG,QAAO;AAGzC,SAAO;AACT,GAcaC,IAAmB,CAACC,GAAwBC,MAA0B;AACjF,QAAMC,IAAUC,EAAuBF,CAAI;AAE3C,GAAI,CAACC,EAAQ,WAAW,CAACX,EAAUU,GAAMC,EAAQ,OAAO,OACtDA,EAAQ,UAAUD,IAGpBG,EAAUJ,GAAQE,EAAQ,OAAO;AACnC;"}
@@ -1,5 +1,5 @@
1
1
  const i = (e) => {
2
- const a = typeof navigator < "u" && "share" in navigator;
2
+ const a = typeof navigator < "u" && "share" in navigator && !!navigator.share;
3
3
  return { trigger: async (t) => {
4
4
  if (!a) return;
5
5
  const r = {
@@ -1 +1 @@
1
- {"version":3,"file":"useShare.mjs","sources":["../../../../src/hooks/useShare/useShare.ts"],"sourcesContent":["/** The use share options type */\nexport interface UseShareParams {\n /** Array of files to be shared */\n files?: File[];\n /** Text content to be shared */\n text?: string;\n /** Title of the content being shared */\n title?: string;\n /** URL link to be shared */\n url?: string;\n}\n\n/** The use share return type */\nexport interface UseShareReturn {\n /** Whether the Web Share API is supported in the current environment */\n supported: boolean;\n /** Function to trigger the native share dialog */\n trigger: (shareParams: ShareData) => Promise<void>;\n}\n\n/**\n * @name useShare\n * @description - Hook that utilizes the share api\n * @category Browser\n *\n * @browserapi share https://developer.mozilla.org/en-US/docs/Web/API/Navigator/share\n *\n * @param {UseShareParams} [params] The use share options\n * @returns {UseShareReturn}\n *\n * @example\n * const { share, supported } = useShare();\n */\nexport const useShare = (params?: UseShareParams) => {\n const supported = typeof navigator !== 'undefined' && 'share' in navigator;\n\n const trigger = async (shareParams: ShareData) => {\n if (!supported) return;\n\n const data = {\n ...params,\n ...shareParams\n };\n\n if (data.files && navigator.canShare({ files: data.files })) navigator.share(data);\n\n return navigator.share(data);\n };\n\n return { trigger, supported };\n};\n"],"names":["useShare","params","supported","shareParams","data"],"mappings":"AAiCO,MAAMA,IAAW,CAACC,MAA4B;AACnD,QAAMC,IAAY,OAAO,YAAc,OAAe,WAAW;AAejE,SAAO,EAAE,SAbO,OAAOC,MAA2B;AAChD,QAAI,CAACD,EAAW;AAEhB,UAAME,IAAO;AAAA,MACX,GAAGH;AAAA,MACH,GAAGE;AAAA,IAAA;AAGL,WAAIC,EAAK,SAAS,UAAU,SAAS,EAAE,OAAOA,EAAK,MAAA,CAAO,KAAG,UAAU,MAAMA,CAAI,GAE1E,UAAU,MAAMA,CAAI;AAAA,EAAA,GAGX,WAAAF,EAAA;AACpB;"}
1
+ {"version":3,"file":"useShare.mjs","sources":["../../../../src/hooks/useShare/useShare.ts"],"sourcesContent":["/** The use share options type */\nexport interface UseShareParams {\n /** Array of files to be shared */\n files?: File[];\n /** Text content to be shared */\n text?: string;\n /** Title of the content being shared */\n title?: string;\n /** URL link to be shared */\n url?: string;\n}\n\n/** The use share return type */\nexport interface UseShareReturn {\n /** Whether the Web Share API is supported in the current environment */\n supported: boolean;\n /** Function to trigger the native share dialog */\n trigger: (shareParams: ShareData) => Promise<void>;\n}\n\n/**\n * @name useShare\n * @description - Hook that utilizes the share api\n * @category Browser\n * @usage medium\n *\n * @browserapi share https://developer.mozilla.org/en-US/docs/Web/API/Navigator/share\n *\n * @param {UseShareParams} [params] The use share options\n * @returns {UseShareReturn}\n *\n * @example\n * const { share, supported } = useShare();\n */\nexport const useShare = (params?: UseShareParams) => {\n const supported = typeof navigator !== 'undefined' && 'share' in navigator && !!navigator.share;\n\n const trigger = async (shareParams: ShareData) => {\n if (!supported) return;\n\n const data = {\n ...params,\n ...shareParams\n };\n\n if (data.files && navigator.canShare({ files: data.files })) navigator.share(data);\n\n return navigator.share(data);\n };\n\n return { trigger, supported };\n};\n"],"names":["useShare","params","supported","shareParams","data"],"mappings":"AAkCO,MAAMA,IAAW,CAACC,MAA4B;AACnD,QAAMC,IAAY,OAAO,YAAc,OAAe,WAAW,aAAa,CAAC,CAAC,UAAU;AAe1F,SAAO,EAAE,SAbO,OAAOC,MAA2B;AAChD,QAAI,CAACD,EAAW;AAEhB,UAAME,IAAO;AAAA,MACX,GAAGH;AAAA,MACH,GAAGE;AAAA,IAAA;AAGL,WAAIC,EAAK,SAAS,UAAU,SAAS,EAAE,OAAOA,EAAK,MAAA,CAAO,KAAG,UAAU,MAAMA,CAAI,GAE1E,UAAU,MAAMA,CAAI;AAAA,EAAA,GAGX,WAAAF,EAAA;AACpB;"}
@@ -1 +1 @@
1
- {"version":3,"file":"useSpeechRecognition.mjs","sources":["../../../../src/hooks/useSpeechRecognition/useSpeechRecognition.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\n/** The use speech recognition hook options type */\ninterface UseSpeechRecognitionOptions {\n /** If true, recognition continues even after pauses in speech. Default is false */\n continuous?: SpeechRecognition['continuous'];\n /** A list of grammar rules */\n grammars?: SpeechRecognition['grammars'];\n /** If true, interim (non-final) results are provided as the user speaks */\n interimResults?: SpeechRecognition['interimResults'];\n /** The language in which recognition should occur. Must be a valid BCP 47 language tag (e.g., \"en-US\", \"ru-RU\") */\n language?: SpeechRecognition['lang'];\n /** The maximum number of alternative transcripts returned for a given recognition result. Must be a positive integer */\n maxAlternatives?: SpeechRecognition['maxAlternatives'];\n /** Callback invoked when speech recognition ends */\n onEnd?: () => void;\n /** Callback invoked when an error occurs during recognition */\n onError?: (error: SpeechRecognitionErrorEvent) => void;\n /** Callback invoked when recognition produces a result */\n onResult?: (event: SpeechRecognitionEvent) => void;\n /** Callback invoked when speech recognition starts */\n onStart?: () => void;\n}\n\n/** The return type of the useSpeechRecognition hook. */\ninterface UseSpeechRecognitionReturn {\n /** The error state */\n error: SpeechRecognitionErrorEvent | null;\n /** The final transcript */\n final: boolean;\n /** Whether the hook is currently listening for speech */\n listening: boolean;\n /** The speech recognition instance */\n recognition: SpeechRecognition;\n /** Whether the current browser supports the Web Speech API */\n supported: boolean;\n /** The current transcript */\n transcript: string;\n /** Begins speech recognition */\n start: () => void;\n /** Ends speech recognition, finalizing results */\n stop: () => void;\n /** Toggles the listening state */\n toggle: (value?: boolean) => void;\n}\n\nexport const getSpeechRecognition = () =>\n window?.SpeechRecognition ?? window?.webkitSpeechRecognition;\n\n/**\n * @name useSpeechRecognition\n * @description - Hook that provides a streamlined interface for incorporating speech-to-text functionality\n * @category Browser\n *\n * @browserapi window.SpeechRecognition https://developer.mozilla.org/en-US/docs/Web/API/SpeechRecognition\n *\n * @param {boolean} [options.continuous=false] Whether recognition should continue after pauses\n * @param {boolean} [options.interimResults=false] Whether interim results should be provided\n * @param {string} [options.language=\"en-US\"] The language for recognition, as a valid BCP 47 tag\n * @param {number} [options.maxAlternatives=1] The maximum number of alternative transcripts to return\n * @param {SpeechGrammarList} [options.grammars] A list of grammar rules\n * @param {() => void} [options.onStart] Callback invoked when speech recognition starts\n * @param {() => void} [options.onEnd] Callback invoked when speech recognition ends\n * @param {(error: SpeechRecognitionErrorEvent) => void} [options.onError] Callback invoked when an error occurs during recognition\n * @param {(event: SpeechRecognitionEvent) => void} [options.onResult] Callback invoked when recognition produces a result\n * @returns {UseSpeechRecognitionReturn} An object containing the speech recognition functionality\n *\n * @example\n * const { supported, value, recognition, listening, error, start, stop, toggle } = useSpeechRecognition();\n */\nexport const useSpeechRecognition = (\n options: UseSpeechRecognitionOptions = {}\n): UseSpeechRecognitionReturn => {\n const supported = typeof window !== 'undefined' && !!getSpeechRecognition();\n\n const {\n continuous = false,\n interimResults = false,\n language = 'en-US',\n grammars,\n maxAlternatives = 1,\n onStart,\n onEnd,\n onError,\n onResult\n } = options;\n\n const [listening, setListening] = useState(false);\n const [transcript, setTranscript] = useState('');\n const [final, setFinal] = useState(false);\n const [error, setError] = useState<SpeechRecognitionErrorEvent | null>(null);\n const [recognition] = useState<SpeechRecognition>(() => {\n if (!supported) return {} as SpeechRecognition;\n\n const SpeechRecognition = getSpeechRecognition();\n const speechRecognition = new SpeechRecognition();\n\n speechRecognition.continuous = continuous;\n if (grammars) speechRecognition.grammars = grammars;\n speechRecognition.interimResults = interimResults;\n speechRecognition.lang = language;\n speechRecognition.maxAlternatives = maxAlternatives;\n\n speechRecognition.onstart = () => {\n setListening(true);\n setFinal(false);\n onStart?.();\n };\n speechRecognition.onend = () => {\n setListening(false);\n onEnd?.();\n };\n speechRecognition.onerror = (event) => {\n setError(event);\n setListening(false);\n onError?.(event);\n };\n speechRecognition.onresult = (event) => {\n console.log('onresult', event);\n const currentResult = event.results[event.resultIndex];\n const { transcript } = currentResult[0];\n\n setTranscript(transcript);\n setError(null);\n onResult?.(event);\n };\n speechRecognition.onend = () => {\n setListening(false);\n speechRecognition.lang = language;\n };\n\n return speechRecognition;\n });\n\n useEffect(() => () => recognition.stop(), []);\n\n const start = () => recognition.start();\n const stop = () => recognition.stop();\n\n const toggle = (value = !listening) => {\n if (value) return start();\n stop();\n };\n\n return {\n supported,\n transcript,\n recognition,\n final,\n listening,\n error,\n start,\n stop,\n toggle\n };\n};\n"],"names":["getSpeechRecognition","useSpeechRecognition","options","supported","continuous","interimResults","language","grammars","maxAlternatives","onStart","onEnd","onError","onResult","listening","setListening","useState","transcript","setTranscript","final","setFinal","error","setError","recognition","SpeechRecognition","speechRecognition","event","currentResult","useEffect","start","stop","value"],"mappings":";AA8CO,MAAMA,IAAuB,MAClC,QAAQ,qBAAqB,QAAQ,yBAuB1BC,IAAuB,CAClCC,IAAuC,OACR;AAC/B,QAAMC,IAAY,OAAO,SAAW,OAAe,CAAC,CAACH,EAAA,GAE/C;AAAA,IACJ,YAAAI,IAAa;AAAA,IACb,gBAAAC,IAAiB;AAAA,IACjB,UAAAC,IAAW;AAAA,IACX,UAAAC;AAAA,IACA,iBAAAC,IAAkB;AAAA,IAClB,SAAAC;AAAA,IACA,OAAAC;AAAA,IACA,SAAAC;AAAA,IACA,UAAAC;AAAA,EAAA,IACEV,GAEE,CAACW,GAAWC,CAAY,IAAIC,EAAS,EAAK,GAC1C,CAACC,GA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AA,IACA,OAAAJ;AAAA,IACA,WAAAL;AAAA,IACA,OAAAO;AAAA,IACA,OAAAQ;AAAA,IACA,MAAAC;AAAA,IACA,QAda,CAACC,IAAQ,CAACjB,MAAc;AACrC,UAAIiB,UAAcF,EAAA;AAClB,MAAAC,EAAA;AAAA,IAAK;AAAA,EAYL;AAEJ;"}
1
+ {"version":3,"file":"useSpeechRecognition.mjs","sources":["../../../../src/hooks/useSpeechRecognition/useSpeechRecognition.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\n/** The use speech recognition hook options type */\ninterface UseSpeechRecognitionOptions {\n /** If true, recognition continues even after pauses in speech. Default is false */\n continuous?: SpeechRecognition['continuous'];\n /** A list of grammar rules */\n grammars?: SpeechRecognition['grammars'];\n /** If true, interim (non-final) results are provided as the user speaks */\n interimResults?: SpeechRecognition['interimResults'];\n /** The language in which recognition should occur. Must be a valid BCP 47 language tag (e.g., \"en-US\", \"ru-RU\") */\n language?: SpeechRecognition['lang'];\n /** The maximum number of alternative transcripts returned for a given recognition result. Must be a positive integer */\n maxAlternatives?: SpeechRecognition['maxAlternatives'];\n /** Callback invoked when speech recognition ends */\n onEnd?: () => void;\n /** Callback invoked when an error occurs during recognition */\n onError?: (error: SpeechRecognitionErrorEvent) => void;\n /** Callback invoked when recognition produces a result */\n onResult?: (event: SpeechRecognitionEvent) => void;\n /** Callback invoked when speech recognition starts */\n onStart?: () => void;\n}\n\n/** The return type of the useSpeechRecognition hook. */\ninterface UseSpeechRecognitionReturn {\n /** The error state */\n error: SpeechRecognitionErrorEvent | null;\n /** The final transcript */\n final: boolean;\n /** Whether the hook is currently listening for speech */\n listening: boolean;\n /** The speech recognition instance */\n recognition: SpeechRecognition;\n /** Whether the current browser supports the Web Speech API */\n supported: boolean;\n /** The current transcript */\n transcript: string;\n /** Begins speech recognition */\n start: () => void;\n /** Ends speech recognition, finalizing results */\n stop: () => void;\n /** Toggles the listening state */\n toggle: (value?: boolean) => void;\n}\n\nexport const getSpeechRecognition = () =>\n window?.SpeechRecognition ?? window?.webkitSpeechRecognition;\n\n/**\n * @name useSpeechRecognition\n * @description - Hook that provides a streamlined interface for incorporating speech-to-text functionality\n * @category Browser\n * @usage low\n *\n * @browserapi window.SpeechRecognition https://developer.mozilla.org/en-US/docs/Web/API/SpeechRecognition\n *\n * @param {boolean} [options.continuous=false] Whether recognition should continue after pauses\n * @param {boolean} [options.interimResults=false] Whether interim results should be provided\n * @param {string} [options.language=\"en-US\"] The language for recognition, as a valid BCP 47 tag\n * @param {number} [options.maxAlternatives=1] The maximum number of alternative transcripts to return\n * @param {SpeechGrammarList} [options.grammars] A list of grammar rules\n * @param {() => void} [options.onStart] Callback invoked when speech recognition starts\n * @param {() => void} [options.onEnd] Callback invoked when speech recognition ends\n * @param {(error: SpeechRecognitionErrorEvent) => void} [options.onError] Callback invoked when an error occurs during recognition\n * @param {(event: SpeechRecognitionEvent) => void} [options.onResult] Callback invoked when recognition produces a result\n * @returns {UseSpeechRecognitionReturn} An object containing the speech recognition functionality\n *\n * @example\n * const { supported, value, recognition, listening, error, start, stop, toggle } = useSpeechRecognition();\n */\nexport const useSpeechRecognition = (\n options: UseSpeechRecognitionOptions = {}\n): UseSpeechRecognitionReturn => {\n const supported = typeof window !== 'undefined' && !!getSpeechRecognition();\n\n const {\n continuous = false,\n interimResults = false,\n language = 'en-US',\n grammars,\n maxAlternatives = 1,\n onStart,\n onEnd,\n onError,\n onResult\n } = options;\n\n const [listening, setListening] = useState(false);\n const [transcript, setTranscript] = useState('');\n const [final, setFinal] = useState(false);\n const [error, setError] = useState<SpeechRecognitionErrorEvent | null>(null);\n const [recognition] = useState<SpeechRecognition>(() => {\n if (!supported) return {} as SpeechRecognition;\n\n const SpeechRecognition = getSpeechRecognition();\n const speechRecognition = new SpeechRecognition();\n\n speechRecognition.continuous = continuous;\n if (grammars) speechRecognition.grammars = grammars;\n speechRecognition.interimResults = interimResults;\n speechRecognition.lang = language;\n speechRecognition.maxAlternatives = maxAlternatives;\n\n speechRecognition.onstart = () => {\n setListening(true);\n setFinal(false);\n onStart?.();\n };\n speechRecognition.onend = () => {\n setListening(false);\n onEnd?.();\n };\n speechRecognition.onerror = (event) => {\n setError(event);\n setListening(false);\n onError?.(event);\n };\n speechRecognition.onresult = (event) => {\n console.log('onresult', event);\n const currentResult = event.results[event.resultIndex];\n const { transcript } = currentResult[0];\n\n setTranscript(transcript);\n setError(null);\n onResult?.(event);\n };\n speechRecognition.onend = () => {\n setListening(false);\n speechRecognition.lang = language;\n };\n\n return speechRecognition;\n });\n\n useEffect(() => () => recognition.stop(), []);\n\n const start = () => recognition.start();\n const stop = () => recognition.stop();\n\n const toggle = (value = !listening) => {\n if (value) return start();\n stop();\n };\n\n return {\n supported,\n transcript,\n recognition,\n final,\n listening,\n error,\n start,\n stop,\n toggle\n };\n};\n"],"names":["getSpeechRecognition","useSpeechRecognition","options","supported","continuous","interimResults","language","grammars","maxAlternatives","onStart","onEnd","onError","onResult","listening","setListening","useState","transcript","setTranscript","final","setFinal","error","setError","recognition","SpeechRecognition","speechRecognition","event","currentResult","useEffect","start","stop","value"],"mappings":";AA8CO,MAAMA,IAAuB,MAClC,QAAQ,qBAAqB,QAAQ,yBAwB1BC,IAAuB,CAClCC,IAAuC,OACR;AAC/B,QAAMC,IAAY,OAAO,SAAW,OAAe,CAAC,CAACH,EAAA,GAE/C;AAAA,IACJ,YAAAI,IAAa;AAAA,IACb,gBAAAC,IAAiB;AAAA,IACjB,UAAAC,IAAW;AAAA,IACX,UAAAC;AAAA,IACA,iBAAAC,IAAkB;AAAA,IAClB,SAAAC;AAAA,IACA,OAAAC;AAAA,IACA,SAAAC;AAAA,IACA,UAAAC;AAAA,EAAA,IACEV,GAEE,CAACW,GAAWC,CAAY,IAAIC,EAAS,EAAK,GAC1C,CAACC,GAAYC,CAAa,IAAIF,EAAS,EAAE,GACzC,CAACG,GAAOC,CAAQ,IAAIJ,EAAS,EAAK,GAClC,CAACK,GAAOC,CAAQ,IAAIN,EAA6C,IAAI,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B,MAAc;AACrC,UAAIiB,UAAcF,EAAA;AAClB,MAAAC,EAAA;AAAA,IAAK;AAAA,EAYL;AAEJ;"}
@@ -1,30 +1,30 @@
1
- import { useState as o, useRef as b, useEffect as x } from "react";
1
+ import { useState as r, useRef as b, useEffect as x } from "react";
2
2
  const j = (d = {}) => {
3
- const t = typeof window < "u" && "speechSynthesis" in window, { text: u = "", lang: i = "en-US", pitch: c = 1, rate: a = 1, voice: p = null, volume: l = 1 } = d, [w, n] = o(!1), [h, r] = o("init"), [S, y] = o(), s = b(null), f = (e) => {
4
- e.lang = i, e.pitch = c, e.rate = a, e.volume = l, e.voice = p, e.onstart = () => {
5
- n(!0), r("play");
3
+ const t = typeof window < "u" && "speechSynthesis" in window && !!window.speechSynthesis, { text: i = "", lang: u = "en-US", pitch: c = 1, rate: p = 1, voice: a = null, volume: w = 1 } = d, [l, n] = r(!1), [h, o] = r("init"), [S, y] = r(), s = b(null), f = (e) => {
4
+ e.lang = u, e.pitch = c, e.rate = p, e.volume = w, e.voice = a, e.onstart = () => {
5
+ n(!0), o("play");
6
6
  }, e.onpause = () => {
7
- n(!1), r("pause");
7
+ n(!1), o("pause");
8
8
  }, e.onresume = () => {
9
- n(!0), r("play");
9
+ n(!0), o("play");
10
10
  }, e.onend = () => {
11
- n(!1), r("end");
11
+ n(!1), o("end");
12
12
  }, e.onerror = (R) => {
13
13
  n(!1), y(R);
14
14
  };
15
15
  };
16
16
  x(() => {
17
17
  if (!t) return;
18
- const e = new SpeechSynthesisUtterance(u);
18
+ const e = new SpeechSynthesisUtterance(i);
19
19
  return f(e), s.current = e, () => {
20
20
  window.speechSynthesis?.cancel();
21
21
  };
22
- }, [u, i, c, a, p, l]);
22
+ }, [i, u, c, p, a, w]);
23
23
  const m = (e) => {
24
24
  t && (e && (s.current = new SpeechSynthesisUtterance(e), f(s.current)), window.speechSynthesis?.cancel(), s.current && window.speechSynthesis?.speak(s.current));
25
25
  }, g = () => {
26
26
  t && (window.speechSynthesis?.cancel(), n(!1));
27
- }, v = (e = !w) => {
27
+ }, v = (e = !l) => {
28
28
  t && (e ? window.speechSynthesis?.resume() : window.speechSynthesis?.pause(), n(e));
29
29
  }, k = () => {
30
30
  n(!0), window.speechSynthesis?.resume();
@@ -33,7 +33,7 @@ const j = (d = {}) => {
33
33
  };
34
34
  return {
35
35
  supported: t,
36
- playing: w,
36
+ playing: l,
37
37
  status: h,
38
38
  utterance: s.current,
39
39
  error: S,
@@ -1 +1 @@
1
- {"version":3,"file":"useSpeechSynthesis.mjs","sources":["../../../../src/hooks/useSpeechSynthesis/useSpeechSynthesis.ts"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\n\n/** The use speech synthesis status type */\nexport type UseSpeechSynthesisStatus = 'end' | 'init' | 'pause' | 'play';\n\n/** The use speech synthesis options type */\nexport interface UseSpeechSynthesisOptions {\n /** Language for SpeechSynthesis */\n lang?: string;\n /** Gets and sets the pitch at which the utterance will be spoken at. */\n pitch?: number;\n /** Gets and sets the speed at which the utterance will be spoken at. */\n rate?: number;\n /** The text to be spoken */\n text?: string;\n /** Gets and sets the voice that will be used to speak the utterance. */\n voice?: SpeechSynthesisVoice | null;\n /** Gets and sets the volume that the utterance will be spoken at. */\n volume?: number;\n}\n\n/** The use speech synthesis return type */\nexport interface UseSpeechSynthesisReturn {\n /** Any error that occurred during speech synthesis. */\n error: SpeechSynthesisErrorEvent | undefined;\n /** Indicates if speech is currently playing. */\n playing: boolean;\n /** The current status of speech synthesis. */\n status: UseSpeechSynthesisStatus;\n /** Indicates if the SpeechSynthesis API is supported in the current environment. */\n supported: boolean;\n /** The SpeechSynthesisUtterance instance. */\n utterance: SpeechSynthesisUtterance | null;\n /** Function to pause speech synthesis. */\n pause: () => void;\n /** Function to resume speech synthesis. */\n resume: () => void;\n /** Function to start speech synthesis. */\n speak: () => void;\n /** Function to stop speech synthesis. */\n stop: () => void;\n /** Function to toggle between play and pause. */\n toggle: (value?: boolean) => void;\n}\n\n/**\n * @name useSpeechSynthesis\n * @description - Hook that provides speech synthesis functionality\n * @category Browser\n *\n * @browserapi SpeechSynthesis https://developer.mozilla.org/en-US/docs/Web/API/SpeechSynthesis\n *\n * @params {string} [options.text] - The text to be spoken\n * @params {string} [options.lang] - The language to be spoken\n * @params {number} [options.pitch] - The pitch to be spoken\n * @params {number} [options.rate] - The rate to be spoken\n * @params {SpeechSynthesisVoice} [options.voice] - The voice to be spoken\n * @params {number} [options.volume] - The volume to be spoken\n * @returns {UseSpeechSynthesisReturn} An object containing the speech synthesis state and control methods\n *\n * @example\n * const { supported, playing, status, utterance, error, stop, toggle, speak, resume, pause } = useSpeechSynthesis();\n */\nexport const useSpeechSynthesis = (\n options: UseSpeechSynthesisOptions = {}\n): UseSpeechSynthesisReturn => {\n const supported = typeof window !== 'undefined' && 'speechSynthesis' in window;\n\n const { text = '', lang = 'en-US', pitch = 1, rate = 1, voice = null, volume = 1 } = options;\n\n const [playing, setPlaying] = useState(false);\n const [status, setStatus] = useState<UseSpeechSynthesisStatus>('init');\n const [error, setError] = useState<SpeechSynthesisErrorEvent>();\n const speechSynthesisUtteranceRef = useRef<SpeechSynthesisUtterance | null>(null);\n\n const bindSpeechSynthesisUtterance = (speechSynthesisUtterance: SpeechSynthesisUtterance) => {\n speechSynthesisUtterance.lang = lang;\n speechSynthesisUtterance.pitch = pitch;\n speechSynthesisUtterance.rate = rate;\n speechSynthesisUtterance.volume = volume;\n speechSynthesisUtterance.voice = voice;\n\n speechSynthesisUtterance.onstart = () => {\n setPlaying(true);\n setStatus('play');\n };\n\n speechSynthesisUtterance.onpause = () => {\n setPlaying(false);\n setStatus('pause');\n };\n\n speechSynthesisUtterance.onresume = () => {\n setPlaying(true);\n setStatus('play');\n };\n\n speechSynthesisUtterance.onend = () => {\n setPlaying(false);\n setStatus('end');\n };\n\n speechSynthesisUtterance.onerror = (event) => {\n setPlaying(false);\n setError(event);\n };\n };\n\n useEffect(() => {\n if (!supported) return;\n\n const speechSynthesisUtterance = new SpeechSynthesisUtterance(text);\n bindSpeechSynthesisUtterance(speechSynthesisUtterance);\n speechSynthesisUtteranceRef.current = speechSynthesisUtterance;\n\n return () => {\n window.speechSynthesis?.cancel();\n };\n }, [text, lang, pitch, rate, voice, volume]);\n\n const speak = (text?: string) => {\n if (!supported) return;\n\n if (text) {\n speechSynthesisUtteranceRef.current = new SpeechSynthesisUtterance(text);\n bindSpeechSynthesisUtterance(speechSynthesisUtteranceRef.current);\n }\n\n window.speechSynthesis?.cancel();\n if (speechSynthesisUtteranceRef.current)\n window.speechSynthesis?.speak(speechSynthesisUtteranceRef.current);\n };\n\n const stop = () => {\n if (!supported) return;\n\n window.speechSynthesis?.cancel();\n setPlaying(false);\n };\n\n const toggle = (value = !playing) => {\n if (!supported) return;\n\n if (value) {\n window.speechSynthesis?.resume();\n } else {\n window.speechSynthesis?.pause();\n }\n setPlaying(value);\n };\n\n const resume = () => {\n setPlaying(true);\n window.speechSynthesis?.resume();\n };\n\n const pause = () => {\n setPlaying(false);\n window.speechSynthesis?.pause();\n };\n\n return {\n supported,\n playing,\n status,\n utterance: speechSynthesisUtteranceRef.current,\n error,\n\n stop,\n toggle,\n speak,\n resume,\n pause\n };\n};\n"],"names":["useSpeechSynthesis","options","supported","text","lang","pitch","rate","voice","volume","playing","setPlaying","useState","status","setStatus","error","setError","speechSynthesisUtteranceRef","useRef","bindSpeechSynthesisUtterance","speechSynthesisUtterance","event","useEffect","speak","stop","toggle","value","resume","pause"],"mappings":";AA+DO,MAAMA,IAAqB,CAChCC,IAAqC,OACR;AAC7B,QAAMC,IAAY,OAAO,SAAW,OAAe,qBAAqB,QAElE,EAAE,MAAAC,IAAO,IAAI,MAAAC,IAAO,SAAS,OAAAC,IAAQ,GAAG,MAAAC,IAAO,GAAG,OAAAC,IAAQ,MAAM,QAAAC,IAAS,MAAMP,GAE/E,CAACQ,GAASC,CAAU,IAAIC,EAAS,EAAK,GACtC,CAACC,GAAQC,CAAS,IAAIF,EAAmC,MAAM,GAC/D,CAACG,GAAOC,CA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AACC,IAAQ,CAAChB,MAAY;AACnC,IAAKP,MAEDuB,IACF,OAAO,iBAAiB,OAAA,IAExB,OAAO,iBAAiB,MAAA,GAE1Bf,EAAWe,CAAK;AAAA,EAAA,GAGZC,IAAS,MAAM;AACnB,IAAAhB,EAAW,EAAI,GACf,OAAO,iBAAiB,OAAA;AAAA,EAAO,GAG3BiB,IAAQ,MAAM;AAClB,IAAAjB,EAAW,EAAK,GAChB,OAAO,iBAAiB,MAAA;AAAA,EAAM;AAGhC,SAAO;AAAA,IACL,WAAAR;AAAA,IACA,SAAAO;AAAA,IACA,QAAAG;AAAA,IACA,WAAWI,EAA4B;AAAA,IACvC,OAAAF;AAAA,IAEA,MAAAS;AAAA,IACA,QAAAC;AAAA,IACA,OAAAF;AAAA,IACA,QAAAI;AAAA,IACA,OAAAC;AAAA,EAAA;AAEJ;"}
1
+ {"version":3,"file":"useSpeechSynthesis.mjs","sources":["../../../../src/hooks/useSpeechSynthesis/useSpeechSynthesis.ts"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\n\n/** The use speech synthesis status type */\nexport type UseSpeechSynthesisStatus = 'end' | 'init' | 'pause' | 'play';\n\n/** The use speech synthesis options type */\nexport interface UseSpeechSynthesisOptions {\n /** Language for SpeechSynthesis */\n lang?: string;\n /** Gets and sets the pitch at which the utterance will be spoken at. */\n pitch?: number;\n /** Gets and sets the speed at which the utterance will be spoken at. */\n rate?: number;\n /** The text to be spoken */\n text?: string;\n /** Gets and sets the voice that will be used to speak the utterance. */\n voice?: SpeechSynthesisVoice | null;\n /** Gets and sets the volume that the utterance will be spoken at. */\n volume?: number;\n}\n\n/** The use speech synthesis return type */\nexport interface UseSpeechSynthesisReturn {\n /** Any error that occurred during speech synthesis. */\n error: SpeechSynthesisErrorEvent | undefined;\n /** Indicates if speech is currently playing. */\n playing: boolean;\n /** The current status of speech synthesis. */\n status: UseSpeechSynthesisStatus;\n /** Indicates if the SpeechSynthesis API is supported in the current environment. */\n supported: boolean;\n /** The SpeechSynthesisUtterance instance. */\n utterance: SpeechSynthesisUtterance | null;\n /** Function to pause speech synthesis. */\n pause: () => void;\n /** Function to resume speech synthesis. */\n resume: () => void;\n /** Function to start speech synthesis. */\n speak: () => void;\n /** Function to stop speech synthesis. */\n stop: () => void;\n /** Function to toggle between play and pause. */\n toggle: (value?: boolean) => void;\n}\n\n/**\n * @name useSpeechSynthesis\n * @description - Hook that provides speech synthesis functionality\n * @category Browser\n * @usage low\n *\n * @browserapi SpeechSynthesis https://developer.mozilla.org/en-US/docs/Web/API/SpeechSynthesis\n *\n * @params {string} [options.text] - The text to be spoken\n * @params {string} [options.lang] - The language to be spoken\n * @params {number} [options.pitch] - The pitch to be spoken\n * @params {number} [options.rate] - The rate to be spoken\n * @params {SpeechSynthesisVoice} [options.voice] - The voice to be spoken\n * @params {number} [options.volume] - The volume to be spoken\n * @returns {UseSpeechSynthesisReturn} An object containing the speech synthesis state and control methods\n *\n * @example\n * const { supported, playing, status, utterance, error, stop, toggle, speak, resume, pause } = useSpeechSynthesis();\n */\nexport const useSpeechSynthesis = (\n options: UseSpeechSynthesisOptions = {}\n): UseSpeechSynthesisReturn => {\n const supported =\n typeof window !== 'undefined' && 'speechSynthesis' in window && !!window.speechSynthesis;\n\n const { text = '', lang = 'en-US', pitch = 1, rate = 1, voice = null, volume = 1 } = options;\n\n const [playing, setPlaying] = useState(false);\n const [status, setStatus] = useState<UseSpeechSynthesisStatus>('init');\n const [error, setError] = useState<SpeechSynthesisErrorEvent>();\n const speechSynthesisUtteranceRef = useRef<SpeechSynthesisUtterance | null>(null);\n\n const bindSpeechSynthesisUtterance = (speechSynthesisUtterance: SpeechSynthesisUtterance) => {\n speechSynthesisUtterance.lang = lang;\n speechSynthesisUtterance.pitch = pitch;\n speechSynthesisUtterance.rate = rate;\n speechSynthesisUtterance.volume = volume;\n speechSynthesisUtterance.voice = voice;\n\n speechSynthesisUtterance.onstart = () => {\n setPlaying(true);\n setStatus('play');\n };\n\n speechSynthesisUtterance.onpause = () => {\n setPlaying(false);\n setStatus('pause');\n };\n\n speechSynthesisUtterance.onresume = () => {\n setPlaying(true);\n setStatus('play');\n };\n\n speechSynthesisUtterance.onend = () => {\n setPlaying(false);\n setStatus('end');\n };\n\n speechSynthesisUtterance.onerror = (event) => {\n setPlaying(false);\n setError(event);\n };\n };\n\n useEffect(() => {\n if (!supported) return;\n\n const speechSynthesisUtterance = new SpeechSynthesisUtterance(text);\n bindSpeechSynthesisUtterance(speechSynthesisUtterance);\n speechSynthesisUtteranceRef.current = speechSynthesisUtterance;\n\n return () => {\n window.speechSynthesis?.cancel();\n };\n }, [text, lang, pitch, rate, voice, volume]);\n\n const speak = (text?: string) => {\n if (!supported) return;\n\n if (text) {\n speechSynthesisUtteranceRef.current = new SpeechSynthesisUtterance(text);\n bindSpeechSynthesisUtterance(speechSynthesisUtteranceRef.current);\n }\n\n window.speechSynthesis?.cancel();\n if (speechSynthesisUtteranceRef.current)\n window.speechSynthesis?.speak(speechSynthesisUtteranceRef.current);\n };\n\n const stop = () => {\n if (!supported) return;\n\n window.speechSynthesis?.cancel();\n setPlaying(false);\n };\n\n const toggle = (value = !playing) => {\n if (!supported) return;\n\n if (value) {\n window.speechSynthesis?.resume();\n } else {\n window.speechSynthesis?.pause();\n }\n setPlaying(value);\n };\n\n const resume = () => {\n setPlaying(true);\n window.speechSynthesis?.resume();\n };\n\n const pause = () => {\n setPlaying(false);\n window.speechSynthesis?.pause();\n };\n\n return {\n supported,\n playing,\n status,\n utterance: speechSynthesisUtteranceRef.current,\n error,\n\n stop,\n toggle,\n speak,\n resume,\n pause\n };\n};\n"],"names":["useSpeechSynthesis","options","supported","text","lang","pitch","rate","voice","volume","playing","setPlaying","useState","status","setStatus","error","setError","speechSynthesisUtteranceRef","useRef","bindSpeechSynthesisUtterance","speechSynthesisUtterance","event","useEffect","speak","stop","toggle","value","resume","pause"],"mappings":";AAgEO,MAAMA,IAAqB,CAChCC,IAAqC,OACR;AAC7B,QAAMC,IACJ,OAAO,SA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IAAKD,MAEDC,MACFa,EAA4B,UAAU,IAAI,yBAAyBb,CAAI,GACvEe,EAA6BF,EAA4B,OAAO,IAGlE,OAAO,iBAAiB,OAAA,GACpBA,EAA4B,WAC9B,OAAO,iBAAiB,MAAMA,EAA4B,OAAO;AAAA,EAAA,GAG/DO,IAAO,MAAM;AACjB,IAAKrB,MAEL,OAAO,iBAAiB,OAAA,GACxBQ,EAAW,EAAK;AAAA,EAAA,GAGZc,IAAS,CAACC,IAAQ,CAAChB,MAAY;AACnC,IAAKP,MAEDuB,IACF,OAAO,iBAAiB,OAAA,IAExB,OAAO,iBAAiB,MAAA,GAE1Bf,EAAWe,CAAK;AAAA,EAAA,GAGZC,IAAS,MAAM;AACnB,IAAAhB,EAAW,EAAI,GACf,OAAO,iBAAiB,OAAA;AAAA,EAAO,GAG3BiB,IAAQ,MAAM;AAClB,IAAAjB,EAAW,EAAK,GAChB,OAAO,iBAAiB,MAAA;AAAA,EAAM;AAGhC,SAAO;AAAA,IACL,WAAAR;AAAA,IACA,SAAAO;AAAA,IACA,QAAAG;AAAA,IACA,WAAWI,EAA4B;AAAA,IACvC,OAAAF;AAAA,IAEA,MAAAS;AAAA,IACA,QAAAC;AAAA,IACA,OAAAF;AAAA,IACA,QAAAI;AAAA,IACA,OAAAC;AAAA,EAAA;AAEJ;"}
@@ -1 +1 @@
1
- {"version":3,"file":"useStateHistory.mjs","sources":["../../../../src/hooks/useStateHistory/useStateHistory.ts"],"sourcesContent":["import { useReducer } from 'react';\n\n/** The use state history hook return type */\ninterface UseStateHistoryReturn<Value> {\n /** True if a redo operation can be performed */\n canRedo: boolean;\n /** True if an undo operation can be performed */\n canUndo: boolean;\n /** All history values */\n history: Value[];\n /** Current index in history */\n index: number;\n /** Current value */\n value: Value;\n /** Go back specified number of steps in history (default: 1) */\n back: (steps?: number) => void;\n /** Go forward specified number of steps in history (default: 1) */\n forward: (steps?: number) => void;\n /** Redo the last change */\n redo: () => void;\n /** Reset history to initial state */\n reset: () => void;\n /** Set a new value */\n set: (value: Value) => void;\n /** Undo the last change */\n undo: () => void;\n}\n\nexport type StateHistoryAction<Value> =\n | { type: 'BACK'; payload: { steps: number } }\n | { type: 'FORWARD'; payload: { steps: number } }\n | { type: 'REDO' }\n | { type: 'RESET'; payload: { initialValue: Value; capacity: number } }\n | { type: 'SET'; payload: { value: Value; capacity: number } }\n | { type: 'UNDO' };\n\nexport interface StateHistory<Value> {\n currentIndex: number;\n history: Value[];\n redoStack: Value[][];\n undoStack: Value[][];\n}\n\nexport const stateHistoryReducer = <Value>(\n state: StateHistory<Value>,\n action: StateHistoryAction<Value>\n): StateHistory<Value> => {\n switch (action.type) {\n case 'SET': {\n const { value, capacity } = action.payload;\n\n const newHistory = [...state.history.slice(0, state.currentIndex + 1), value];\n if (newHistory.length > capacity) {\n newHistory.shift();\n }\n\n const newUndoStack = [state.history, ...state.undoStack];\n if (newUndoStack.length > capacity) {\n newUndoStack.pop();\n }\n\n return {\n history: newHistory,\n currentIndex: newHistory.length - 1,\n undoStack: newUndoStack,\n redoStack: []\n };\n }\n\n case 'UNDO': {\n if (state.undoStack.length === 0) return state;\n\n return {\n history: state.undoStack[0],\n currentIndex: state.undoStack[0].length - 1,\n undoStack: state.undoStack.slice(1),\n redoStack: [state.history, ...state.redoStack]\n };\n }\n\n case 'REDO': {\n if (state.redoStack.length === 0) return state;\n\n return {\n history: state.redoStack[0],\n currentIndex: state.redoStack[0].length - 1,\n undoStack: [state.history, ...state.undoStack],\n redoStack: state.redoStack.slice(1)\n };\n }\n\n case 'BACK': {\n const { steps } = action.payload;\n return {\n ...state,\n currentIndex: Math.max(0, state.currentIndex - steps)\n };\n }\n\n case 'FORWARD': {\n const { steps } = action.payload;\n return {\n ...state,\n currentIndex: Math.min(state.currentIndex + steps, state.history.length - 1)\n };\n }\n\n case 'RESET': {\n const { initialValue, capacity } = action.payload;\n if (state.history.length === 1) return state;\n\n const newUndoStack = [state.history, ...state.undoStack];\n if (newUndoStack.length > capacity) {\n newUndoStack.pop();\n }\n\n return {\n history: [initialValue],\n currentIndex: 0,\n undoStack: newUndoStack,\n redoStack: []\n };\n }\n\n default:\n throw new Error('Unsupported action type');\n }\n};\n\n/**\n * @name useStateHistory\n * @description - Hook that manages state with history functionality\n * @category State\n *\n * @param {Value} initialValue - The initial value to start the history with\n * @param {number} [capacity=10] - Maximum number of history entries and undo actions to keep\n * @returns {UseStateHistoryReturn<Value>} Object containing current value, history array and control methods\n *\n * @example\n * const { value, history, index, set, back, forward, reset, undo, redo, canUndo, canRedo } = useStateHistory(0);\n */\nexport const useStateHistory = <Value>(\n initialValue: Value,\n capacity = 10\n): UseStateHistoryReturn<Value> => {\n const [state, dispatch] = useReducer(stateHistoryReducer<Value>, {\n history: [initialValue],\n currentIndex: 0,\n undoStack: [],\n redoStack: []\n });\n\n const value = state.history[state.currentIndex];\n const canUndo = state.undoStack.length > 0;\n const canRedo = state.redoStack.length > 0;\n\n const set = (value: Value) =>\n dispatch({\n type: 'SET',\n payload: { value, capacity }\n });\n\n const undo = () => dispatch({ type: 'UNDO' });\n\n const redo = () => dispatch({ type: 'REDO' });\n\n const back = (steps = 1) => dispatch({ type: 'BACK', payload: { steps } });\n\n const forward = (steps = 1) => dispatch({ type: 'FORWARD', payload: { steps } });\n\n const reset = () => dispatch({ type: 'RESET', payload: { initialValue, capacity } });\n\n return {\n history: state.history,\n value,\n set,\n index: state.currentIndex,\n back,\n forward,\n reset,\n undo,\n redo,\n canUndo,\n canRedo\n };\n};\n"],"names":["stateHistoryReducer","state","action","value","capacity","newHistory","newUndoStack","steps","initialValue","useStateHistory","dispatch","useReducer","canUndo","canRedo","set","undo","redo","back","forward","reset"],"mappings":";AA2CO,MAAMA,IAAsB,CACjCC,GACAC,MACwB;AACxB,UAAQA,EAAO,MAAA;AAAA,IACb,KAAK,OAAO;AACV,YAAM,EAAE,OAAAC,GAAO,UAAAC,EAAA,IAAaF,EAAO,SAE7BG,IAAa,CAAC,GAAGJ,EAAM,QAAQ,MAAM,GAA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IACA,KAAAW;AAAA,IACA,OAAOb,EAAM;AAAA,IACb,MAAAgB;AAAA,IACA,SAAAC;AAAA,IACA,OAAAC;AAAA,IACA,MAAAJ;AAAA,IACA,MAAAC;AAAA,IACA,SAAAJ;AAAA,IACA,SAAAC;AAAA,EAAA;AAEJ;"}
1
+ {"version":3,"file":"useStateHistory.mjs","sources":["../../../../src/hooks/useStateHistory/useStateHistory.ts"],"sourcesContent":["import { useReducer } from 'react';\n\n/** The use state history hook return type */\ninterface UseStateHistoryReturn<Value> {\n /** True if a redo operation can be performed */\n canRedo: boolean;\n /** True if an undo operation can be performed */\n canUndo: boolean;\n /** All history values */\n history: Value[];\n /** Current index in history */\n index: number;\n /** Current value */\n value: Value;\n /** Go back specified number of steps in history (default: 1) */\n back: (steps?: number) => void;\n /** Go forward specified number of steps in history (default: 1) */\n forward: (steps?: number) => void;\n /** Redo the last change */\n redo: () => void;\n /** Reset history to initial state */\n reset: () => void;\n /** Set a new value */\n set: (value: Value) => void;\n /** Undo the last change */\n undo: () => void;\n}\n\nexport type StateHistoryAction<Value> =\n | { type: 'BACK'; payload: { steps: number } }\n | { type: 'FORWARD'; payload: { steps: number } }\n | { type: 'REDO' }\n | { type: 'RESET'; payload: { initialValue: Value; capacity: number } }\n | { type: 'SET'; payload: { value: Value; capacity: number } }\n | { type: 'UNDO' };\n\nexport interface StateHistory<Value> {\n currentIndex: number;\n history: Value[];\n redoStack: Value[][];\n undoStack: Value[][];\n}\n\nexport const stateHistoryReducer = <Value>(\n state: StateHistory<Value>,\n action: StateHistoryAction<Value>\n): StateHistory<Value> => {\n switch (action.type) {\n case 'SET': {\n const { value, capacity } = action.payload;\n\n const newHistory = [...state.history.slice(0, state.currentIndex + 1), value];\n if (newHistory.length > capacity) {\n newHistory.shift();\n }\n\n const newUndoStack = [state.history, ...state.undoStack];\n if (newUndoStack.length > capacity) {\n newUndoStack.pop();\n }\n\n return {\n history: newHistory,\n currentIndex: newHistory.length - 1,\n undoStack: newUndoStack,\n redoStack: []\n };\n }\n\n case 'UNDO': {\n if (state.undoStack.length === 0) return state;\n\n return {\n history: state.undoStack[0],\n currentIndex: state.undoStack[0].length - 1,\n undoStack: state.undoStack.slice(1),\n redoStack: [state.history, ...state.redoStack]\n };\n }\n\n case 'REDO': {\n if (state.redoStack.length === 0) return state;\n\n return {\n history: state.redoStack[0],\n currentIndex: state.redoStack[0].length - 1,\n undoStack: [state.history, ...state.undoStack],\n redoStack: state.redoStack.slice(1)\n };\n }\n\n case 'BACK': {\n const { steps } = action.payload;\n return {\n ...state,\n currentIndex: Math.max(0, state.currentIndex - steps)\n };\n }\n\n case 'FORWARD': {\n const { steps } = action.payload;\n return {\n ...state,\n currentIndex: Math.min(state.currentIndex + steps, state.history.length - 1)\n };\n }\n\n case 'RESET': {\n const { initialValue, capacity } = action.payload;\n if (state.history.length === 1) return state;\n\n const newUndoStack = [state.history, ...state.undoStack];\n if (newUndoStack.length > capacity) {\n newUndoStack.pop();\n }\n\n return {\n history: [initialValue],\n currentIndex: 0,\n undoStack: newUndoStack,\n redoStack: []\n };\n }\n\n default:\n throw new Error('Unsupported action type');\n }\n};\n\n/**\n * @name useStateHistory\n * @description - Hook that manages state with history functionality\n * @category State\n * @usage medium\n *\n * @param {Value} initialValue - The initial value to start the history with\n * @param {number} [capacity=10] - Maximum number of history entries and undo actions to keep\n * @returns {UseStateHistoryReturn<Value>} Object containing current value, history array and control methods\n *\n * @example\n * const { value, history, index, set, back, forward, reset, undo, redo, canUndo, canRedo } = useStateHistory(0);\n */\nexport const useStateHistory = <Value>(\n initialValue: Value,\n capacity = 10\n): UseStateHistoryReturn<Value> => {\n const [state, dispatch] = useReducer(stateHistoryReducer<Value>, {\n history: [initialValue],\n currentIndex: 0,\n undoStack: [],\n redoStack: []\n });\n\n const value = state.history[state.currentIndex];\n const canUndo = state.undoStack.length > 0;\n const canRedo = state.redoStack.length > 0;\n\n const set = (value: Value) =>\n dispatch({\n type: 'SET',\n payload: { value, capacity }\n });\n\n const undo = () => dispatch({ type: 'UNDO' });\n\n const redo = () => dispatch({ type: 'REDO' });\n\n const back = (steps = 1) => dispatch({ type: 'BACK', payload: { steps } });\n\n const forward = (steps = 1) => dispatch({ type: 'FORWARD', payload: { steps } });\n\n const reset = () => dispatch({ type: 'RESET', payload: { initialValue, capacity } });\n\n return {\n history: state.history,\n value,\n set,\n index: state.currentIndex,\n back,\n forward,\n reset,\n undo,\n redo,\n canUndo,\n canRedo\n };\n};\n"],"names":["stateHistoryReducer","state","action","value","capacity","newHistory","newUndoStack","steps","initialValue","useStateHistory","dispatch","useReducer","canUndo","canRedo","set","undo","redo","back","forward","reset"],"mappings":";AA2CO,MAAMA,IAAsB,CACjCC,GACAC,MACwB;AACxB,UAAQA,EAAO,MAAA;AAAA,IACb,KAAK,OAAO;AACV,YAAM,EAAE,OAAAC,GAAO,UAAAC,EAAA,IAAaF,EAAO,SAE7BG,IAAa,CAAC,GAAGJ,EAAM,QAAQ,MAAM,GAAGA,EAAM,eAAe,CAAC,GAAGE,CAAK;AAC5E,MAAIE,EAAW,SAASD,KACtBC,EAAW,MAAA;AAGb,YAAMC,IAAe,CAACL,EAAM,SAAS,GAAGA,EAAM,SAAS;AACvD,aAAIK,EAAa,SAASF,KACxBE,EAAa,IAAA,GAGR;AAAA,QACL,SAASD;AAAA,QACT,cAAcA,EAAW,SAAS;AAAA,QAClC,WAAWC;AAAA,QACX,WAAW,CAAA;AAAA,MAAC;AAAA,IACd;AAAA,IAGF,KAAK;AACH,aAAIL,EAAM,UAAU,WAAW,IAAUA,IAElC;AAAA,QACL,SAASA,EAAM,UAAU,CAAC;AAAA,QAC1B,cAAcA,EAAM,UAAU,CAAC,EAAE,SAAS;AAAA,QAC1C,WAAWA,EAAM,UAAU,MAAM,CAAC;AAAA,QAClC,WAAW,CAACA,EAAM,SAAS,GAAGA,EAAM,SAAS;AAAA,MAAA;AAAA,IAIjD,KAAK;AACH,aAAIA,EAAM,UAAU,WAAW,IAAUA,IAElC;AAAA,QACL,SA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U,SAAS,GACnCY,IAAUZ,EAAM,UAAU,SAAS,GAEnCa,IAAM,CAACX,MACXO,EAAS;AAAA,IACP,MAAM;AAAA,IACN,SAAS,EAAE,OAAAP,GAAO,UAAAC,EAAA;AAAA,EAAS,CAC5B,GAEGW,IAAO,MAAML,EAAS,EAAE,MAAM,QAAQ,GAEtCM,IAAO,MAAMN,EAAS,EAAE,MAAM,QAAQ,GAEtCO,IAAO,CAACV,IAAQ,MAAMG,EAAS,EAAE,MAAM,QAAQ,SAAS,EAAE,OAAAH,EAAA,EAAM,CAAG,GAEnEW,IAAU,CAACX,IAAQ,MAAMG,EAAS,EAAE,MAAM,WAAW,SAAS,EAAE,OAAAH,EAAA,EAAM,CAAG,GAEzEY,IAAQ,MAAMT,EAAS,EAAE,MAAM,SAAS,SAAS,EAAE,cAAAF,GAAc,UAAAJ,EAAA,GAAY;AAEnF,SAAO;AAAA,IACL,SAASH,EAAM;AAAA,IACf,OAAAE;AAAA,IACA,KAAAW;AAAA,IACA,OAAOb,EAAM;AAAA,IACb,MAAAgB;AAAA,IACA,SAAAC;AAAA,IACA,OAAAC;AAAA,IACA,MAAAJ;AAAA,IACA,MAAAC;AAAA,IACA,SAAAJ;AAAA,IACA,SAAAC;AAAA,EAAA;AAEJ;"}
@@ -1 +1 @@
1
- {"version":3,"file":"useStep.mjs","sources":["../../../../src/hooks/useStep/useStep.ts"],"sourcesContent":["import { useRef, useState } from 'react';\n\n/** The use step params type */\nexport interface UseStepParams {\n /** Initial value for step */\n initial: number;\n /** Maximum value for step */\n max: number;\n}\n\n/** The use step return type */\nexport interface UseStepReturn {\n /** Counts of steps */\n counts: number;\n /** Current value of step */\n currentStep: number;\n /** Boolean value if current step is first */\n isFirst: boolean;\n /** Boolean value if current step is last */\n isLast: boolean;\n /** Go to back step */\n back: () => void;\n /** Go to next step */\n next: () => void;\n /** Reset current step to initial value */\n reset: () => void;\n /** Go to custom step */\n set: (value: number | 'first' | 'last') => void;\n}\n\nconst FIRST_STEP_VALUE = 1;\n\n/**\n * @name useStep\n * @description - Hook that create stepper\n * @category State\n *\n * @overload\n * @param {number} max Maximum number of steps\n * @returns {UseStepReturn} An object contains variables and functions to change the step\n *\n * @example\n * const stepper = useStep(5);\n *\n * @overload\n * @param {number} params.max Maximum number of steps\n * @param {number} params.initial Initial value for step\n * @returns {UseStepReturn} An object contains variables and functions to change the step\n *\n * @example\n * const stepper = useStep({ initial: 2, max: 5 });\n */\nexport const useStep = (params: number | UseStepParams): UseStepReturn => {\n const max = typeof params === 'object' ? params.max : params;\n const initial = typeof params === 'object' ? params.initial : FIRST_STEP_VALUE;\n\n const initialStep = useRef(\n initial > max || initial < FIRST_STEP_VALUE ? FIRST_STEP_VALUE : initial\n );\n const [currentStep, setCurrentStep] = useState(initial);\n\n const isFirst = currentStep === FIRST_STEP_VALUE;\n const isLast = currentStep === max;\n\n const next = () => {\n if (isLast) return;\n setCurrentStep((prevStep) => prevStep + 1);\n };\n\n const back = () => {\n if (isFirst) return;\n setCurrentStep((prevStep) => prevStep - 1);\n };\n\n const reset = () => setCurrentStep(initialStep.current);\n\n const set = (value: number | 'first' | 'last') => {\n if (value === 'first') return setCurrentStep(initialStep.current);\n if (value === 'last') return setCurrentStep(max);\n if (value >= max) return setCurrentStep(max);\n if (value <= FIRST_STEP_VALUE) return setCurrentStep(FIRST_STEP_VALUE);\n setCurrentStep(value);\n };\n\n return {\n counts: max,\n currentStep,\n isFirst,\n isLast,\n next,\n back,\n reset,\n set\n };\n};\n"],"names":["FIRST_STEP_VALUE","useStep","params","max","initial","initialStep","useRef","currentStep","setCurrentStep","useState","isFirst","isLast","prevStep","value"],"mappings":";AA8BA,MAAMA,IAAmB,GAsBZC,IAAU,CAACC,MAAkD;AACxE,QAAMC,IAAM,OAAOD,KAAW,WAAWA,EAAO,MAAMA,GAChDE,IAAU,OAAOF,KAAW,WAAWA,EAAO,UAAUF,GAExDK,IAAcC;AAAA,IAClBF,IAAUD,KAAOC,IAAUJ,IAAmBA,IAAmBI;AAAA,EAAA,GAE7D,CAACG,GAAaC,CAAc,IAAIC,EAASL,CAAO,GAEhDM,IAAUH,MAAgBP,GAC1BW,IAASJ,MAAgBJ;AAsB/B,SAAO;AAAA,IACL,QAAQA;AAAA,IACR,aAAAI;AAAA,IACA,SAAAG;AAAA,IACA,QAAAC;AAAA,IACA,MAzBW,MAAM;AACjB,MAAIA,KACJH,EAAe,CAACI,MAAaA,IAAW,CAAC;AAAA,IAAA;AAAA,IAwBzC,MArBW,MAAM;AACjB,MAAIF,KACJF,EAAe,CAACI,MAAaA,IAAW,CAAC;AAAA,IAAA;AAAA,IAoBzC,OAjBY,MAAMJ,EAAeH,EAAY,OAAO;AAAA,IAkBpD,KAhBU,CAACQ,MAAqC;AAChD,UAAIA,MAAU,QAAS,QAAOL,EAAeH,EAAY,OAAO;AAEhE,UADIQ,MAAU,UACVA,KAASV,EAAK,QAAOK,EAAeL,CAAG;AAC3C,UAAIU,KAASb,EAAkB,QAAOQ,EAAeR,CAAgB;AACrE,MAAAQ,EAAeK,CAAK;AAAA,IAAA;AAAA,EAWpB;AAEJ;"}
1
+ {"version":3,"file":"useStep.mjs","sources":["../../../../src/hooks/useStep/useStep.ts"],"sourcesContent":["import { useRef, useState } from 'react';\n\n/** The use step params type */\nexport interface UseStepParams {\n /** Initial value for step */\n initial: number;\n /** Maximum value for step */\n max: number;\n}\n\n/** The use step return type */\nexport interface UseStepReturn {\n /** Counts of steps */\n counts: number;\n /** Current value of step */\n currentStep: number;\n /** Boolean value if current step is first */\n isFirst: boolean;\n /** Boolean value if current step is last */\n isLast: boolean;\n /** Go to back step */\n back: () => void;\n /** Go to next step */\n next: () => void;\n /** Reset current step to initial value */\n reset: () => void;\n /** Go to custom step */\n set: (value: number | 'first' | 'last') => void;\n}\n\nconst FIRST_STEP_VALUE = 1;\n\n/**\n * @name useStep\n * @description - Hook that create stepper\n * @category State\n * @usage medium\n *\n * @overload\n * @param {number} max Maximum number of steps\n * @returns {UseStepReturn} An object contains variables and functions to change the step\n *\n * @example\n * const stepper = useStep(5);\n *\n * @overload\n * @param {number} params.max Maximum number of steps\n * @param {number} params.initial Initial value for step\n * @returns {UseStepReturn} An object contains variables and functions to change the step\n *\n * @example\n * const stepper = useStep({ initial: 2, max: 5 });\n */\nexport const useStep = (params: number | UseStepParams): UseStepReturn => {\n const max = typeof params === 'object' ? params.max : params;\n const initial = typeof params === 'object' ? params.initial : FIRST_STEP_VALUE;\n\n const initialStep = useRef(\n initial > max || initial < FIRST_STEP_VALUE ? FIRST_STEP_VALUE : initial\n );\n const [currentStep, setCurrentStep] = useState(initial);\n\n const isFirst = currentStep === FIRST_STEP_VALUE;\n const isLast = currentStep === max;\n\n const next = () => {\n if (isLast) return;\n setCurrentStep((prevStep) => prevStep + 1);\n };\n\n const back = () => {\n if (isFirst) return;\n setCurrentStep((prevStep) => prevStep - 1);\n };\n\n const reset = () => setCurrentStep(initialStep.current);\n\n const set = (value: number | 'first' | 'last') => {\n if (value === 'first') return setCurrentStep(initialStep.current);\n if (value === 'last') return setCurrentStep(max);\n if (value >= max) return setCurrentStep(max);\n if (value <= FIRST_STEP_VALUE) return setCurrentStep(FIRST_STEP_VALUE);\n setCurrentStep(value);\n };\n\n return {\n counts: max,\n currentStep,\n isFirst,\n isLast,\n next,\n back,\n reset,\n set\n };\n};\n"],"names":["FIRST_STEP_VALUE","useStep","params","max","initial","initialStep","useRef","currentStep","setCurrentStep","useState","isFirst","isLast","prevStep","value"],"mappings":";AA8BA,MAAMA,IAAmB,GAuBZC,IAAU,CAACC,MAAkD;AACxE,QAAMC,IAAM,OAAOD,KAAW,WAAWA,EAAO,MAAMA,GAChDE,IAAU,OAAOF,KAAW,WAAWA,EAAO,UAAUF,GAExDK,IAAcC;AAAA,IAClBF,IAAUD,KAAOC,IAAUJ,IAAmBA,IAAmBI;AAAA,EAAA,GAE7D,CAACG,GAAaC,CAAc,IAAIC,EAASL,CAAO,GAEhDM,IAAUH,MAAgBP,GAC1BW,IAASJ,MAAgBJ;AAsB/B,SAAO;AAAA,IACL,QAAQA;AAAA,IACR,aAAAI;AAAA,IACA,SAAAG;AAAA,IACA,QAAAC;AAAA,IACA,MAzBW,MAAM;AACjB,MAAIA,KACJH,EAAe,CAACI,MAAaA,IAAW,CAAC;AAAA,IAAA;AAAA,IAwBzC,MArBW,MAAM;AACjB,MAAIF,KACJF,EAAe,CAACI,MAAaA,IAAW,CAAC;AAAA,IAAA;AAAA,IAoBzC,OAjBY,MAAMJ,EAAeH,EAAY,OAAO;AAAA,IAkBpD,KAhBU,CAACQ,MAAqC;AAChD,UAAIA,MAAU,QAAS,QAAOL,EAAeH,EAAY,OAAO;AAEhE,UADIQ,MAAU,UACVA,KAASV,EAAK,QAAOK,EAAeL,CAAG;AAC3C,UAAIU,KAASb,EAAkB,QAAOQ,EAAeR,CAAgB;AACrE,MAAAQ,EAAeK,CAAK;AAAA,IAAA;AAAA,EAWpB;AAEJ;"}
@@ -1 +1 @@
1
- {"version":3,"file":"useSticky.mjs","sources":["../../../../src/hooks/useSticky/useSticky.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 sticky return type */\nexport interface UseStickyReturn {\n stuck: boolean;\n}\n\n/** The use sticky axis type */\nexport type UseStickyAxis = 'horizontal' | 'vertical';\n\n/** The use sticky options type */\nexport interface UseStickyOptions {\n axis?: UseStickyAxis;\n root?: HookTarget;\n}\n\nexport interface UseSticky {\n (target: HookTarget, options?: UseStickyOptions): boolean;\n\n <Target extends Element>(\n options?: UseStickyOptions,\n target?: never\n ): {\n ref: StateRef<Target>;\n } & UseStickyReturn;\n}\n\n/**\n * @name UseSticky\n * @description - Hook that allows you to detect that your sticky component is stuck\n * @category Elements\n *\n * @overload\n * @param {HookTarget} target The target sticky element\n * @param {UseStickyAxis} [options.axis='vertical'] The axis of motion of the sticky component\n * @param {UseStickyRoot} [options.root=document] The element that contains your sticky component\n * @returns {UseStickyReturn} The state of the sticky\n *\n * @example\n * const stuck = useSticky(ref);\n *\n * @overload\n * @param {UseStickyAxis} [options.axis='vertical'] The axis of motion of the sticky component\n * @param {UseStickyRoot} [options.root=document] The element that contains your sticky component\n * @returns {{ stickyRef: StateRef<Target> } & UseStickyReturn} The state of the sticky\n *\n * @example\n * const { stuck, ref } = useSticky();\n */\nexport const useSticky = ((...params: any[]) => {\n const target = (isTarget(params[0]) ? params[0] : undefined) as HookTarget | undefined;\n const options = (target ? params[1] : params[0]) as UseStickyOptions;\n const axis = options?.axis ?? 'vertical';\n\n const internalRef = useRefState<Element>();\n const [stuck, setStuck] = useState(false);\n\n useEffect(() => {\n if (!target && !internalRef.state) return;\n\n const element = (target ? getElement(target) : internalRef.current) as Element;\n\n if (!element) return;\n\n const root = (options?.root ? getElement(options.root) : document) as Element;\n const elementOffsetTop =\n element.getBoundingClientRect().top + root.scrollTop - root.getBoundingClientRect().top;\n const elementOffsetLeft =\n element.getBoundingClientRect().left + root.scrollLeft - root.getBoundingClientRect().left;\n\n const onSticky = () => {\n if (axis === 'vertical') {\n const scrollTop = root.scrollTop;\n setStuck(scrollTop >= elementOffsetTop);\n }\n\n if (axis === 'horizontal') {\n const scrollLeft = root.scrollLeft;\n setStuck(scrollLeft >= elementOffsetLeft);\n }\n };\n\n root.addEventListener('scroll', onSticky);\n window.addEventListener('resize', onSticky);\n window.addEventListener('orientationchange', onSticky);\n\n onSticky();\n\n return () => {\n root.removeEventListener('scroll', onSticky);\n window.removeEventListener('resize', onSticky);\n window.removeEventListener('orientationchange', onSticky);\n };\n }, [target, internalRef.state, axis, options?.root]);\n\n if (target) return stuck;\n return {\n stuck,\n ref: internalRef\n };\n}) as UseSticky;\n"],"names":["useSticky","params","target","isTarget","options","axis","internalRef","useRefState","stuck","setStuck","useState","useEffect","element","getElement","root","elementOffsetTop","elementOffsetLeft","onSticky","scrollTop","scroll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A,KAAKF;AAAA,EAAA;AAET;"}
1
+ {"version":3,"file":"useSticky.mjs","sources":["../../../../src/hooks/useSticky/useSticky.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 sticky return type */\nexport interface UseStickyReturn {\n stuck: boolean;\n}\n\n/** The use sticky axis type */\nexport type UseStickyAxis = 'horizontal' | 'vertical';\n\n/** The use sticky options type */\nexport interface UseStickyOptions {\n axis?: UseStickyAxis;\n root?: HookTarget;\n}\n\nexport interface UseSticky {\n (target: HookTarget, options?: UseStickyOptions): boolean;\n\n <Target extends Element>(\n options?: UseStickyOptions,\n target?: never\n ): {\n ref: StateRef<Target>;\n } & UseStickyReturn;\n}\n\n/**\n * @name UseSticky\n * @description - Hook that allows you to detect that your sticky component is stuck\n * @category Elements\n * @usage low\n *\n * @overload\n * @param {HookTarget} target The target sticky element\n * @param {UseStickyAxis} [options.axis='vertical'] The axis of motion of the sticky component\n * @param {UseStickyRoot} [options.root=document] The element that contains your sticky component\n * @returns {UseStickyReturn} The state of the sticky\n *\n * @example\n * const stuck = useSticky(ref);\n *\n * @overload\n * @param {UseStickyAxis} [options.axis='vertical'] The axis of motion of the sticky component\n * @param {UseStickyRoot} [options.root=document] The element that contains your sticky component\n * @returns {{ stickyRef: StateRef<Target> } & UseStickyReturn} The state of the sticky\n *\n * @example\n * const { stuck, ref } = useSticky();\n */\nexport const useSticky = ((...params: any[]) => {\n const target = (isTarget(params[0]) ? params[0] : undefined) as HookTarget | undefined;\n const options = (target ? params[1] : params[0]) as UseStickyOptions;\n const axis = options?.axis ?? 'vertical';\n\n const internalRef = useRefState<Element>();\n const [stuck, setStuck] = useState(false);\n\n useEffect(() => {\n if (!target && !internalRef.state) return;\n\n const element = (target ? getElement(target) : internalRef.current) as Element;\n\n if (!element) return;\n\n const root = (options?.root ? getElement(options.root) : document) as Element;\n const elementOffsetTop =\n element.getBoundingClientRect().top + root.scrollTop - root.getBoundingClientRect().top;\n const elementOffsetLeft =\n element.getBoundingClientRect().left + root.scrollLeft - root.getBoundingClientRect().left;\n\n const onSticky = () => {\n if (axis === 'vertical') {\n const scrollTop = root.scrollTop;\n setStuck(scrollTop >= elementOffsetTop);\n }\n\n if (axis === 'horizontal') {\n const scrollLeft = root.scrollLeft;\n setStuck(scrollLeft >= elementOffsetLeft);\n }\n };\n\n root.addEventListener('scroll', onSticky);\n window.addEventListener('resize', onSticky);\n window.addEventListener('orientationchange', onSticky);\n\n onSticky();\n\n return () => {\n root.removeEventListener('scroll', onSticky);\n window.removeEventListener('resize', onSticky);\n window.removeEventListener('orientationchange', onSticky);\n };\n }, [target, internalRef.state, axis, options?.root]);\n\n if (target) return stuck;\n return {\n stuck,\n ref: internalRef\n };\n}) as UseSticky;\n"],"names":["useSticky","params","target","isTarget","options","axis","internalRef","useRefState","stuck","setStuck","useState","useEffect","element","getElement","root","elementOffsetTop","elementOffsetLeft","onSticky","scrollTop","scrollLeft"],"mappings":";;;;AA0DO,MAAMA,IAAa,IAAIC,MAAkB;AAC9C,QAAMC,IAAUC,EAASF,EAAO,CAAC,CAAC,IAAIA,EAAO,CAAC,IAAI,QAC5CG,IAAWF,IAASD,EAAO,CAAC,IAAIA,EAAO,CAAC,GACxCI,IAAOD,GAAS,QAAQ,YAExBE,IAAcC,EAAA,GACd,CAACC,GAAOC,CAAQ,IAAIC,EAAS,EAAK;AAwCxC,SAtCAC,EAAU,MAAM;AACd,QAAI,CAACT,KAAU,CAACI,EAAY,MAAO;AAEnC,UAAMM,IAAWV,IAASW,EAAWX,CAAM,IAAII,EAAY;AAE3D,QAAI,CAACM,EAAS;AAEd,UAAME,IAAQV,GAAS,OAAOS,EAAWT,EAAQ,IAAI,IAAI,UACnDW,IACJH,EAAQ,wBAAwB,MAAME,EAAK,YAAYA,EAAK,sBAAA,EAAwB,KAChFE,IACJJ,EAAQ,wBAAwB,OAAOE,EAAK,aAAaA,EAAK,sBAAA,EAAwB,MAElFG,IAAW,MAAM;AACrB,UAAIZ,MAAS,YAAY;AACvB,cAAMa,IAAYJ,EAAK;AACvB,QAAAL,EAASS,KAAaH,CAAgB;AAAA,MAAA;AAGxC,UAAIV,MAAS,cAAc;AACzB,cAAMc,IAAaL,EAAK;AACxB,QAAAL,EAASU,KAAcH,CAAiB;AAAA,MAAA;AAAA,IAC1C;AAGF,WAAAF,EAAK,iBAAiB,UAAUG,CAAQ,GACxC,OAAO,iBAAiB,UAAUA,CAAQ,GAC1C,OAAO,iBAAiB,qBAAqBA,CAAQ,GAErDA,EAAA,GAEO,MAAM;AACX,MAAAH,EAAK,oBAAoB,UAAUG,CAAQ,GAC3C,OAAO,oBAAoB,UAAUA,CAAQ,GAC7C,OAAO,oBAAoB,qBAAqBA,CAAQ;AAAA,IAAA;AAAA,EAC1D,GACC,CAACf,GAAQI,EAAY,OAAOD,GAAMD,GAAS,IAAI,CAAC,GAE/CF,IAAeM,IACZ;AAAA,IACL,OAAAA;AAAA,IACA,KAAKF;AAAA,EAAA;AAET;"}
@@ -1 +1 @@
1
- {"version":3,"file":"useStopwatch.mjs","sources":["../../../../src/hooks/useStopwatch/useStopwatch.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\nconst getStopwatchTime = (time: number) => {\n if (!time)\n return {\n days: 0,\n hours: 0,\n minutes: 0,\n seconds: 0,\n count: 0\n };\n\n const days = Math.floor(time / 86400);\n const hours = Math.floor((time % 86400) / 3600);\n const minutes = Math.floor((time % 3600) / 60);\n const seconds = Math.floor(time % 60);\n\n return { days, hours, minutes, seconds, count: time };\n};\n\n/** The use stopwatch return type */\nexport interface UseStopwatchReturn {\n /** The total count of the stopwatch */\n count: number;\n /** The day count of the stopwatch */\n days: number;\n /** The hour count of the stopwatch */\n hours: number;\n /** The minute count of the stopwatch */\n minutes: number;\n /** The over state of the stopwatch */\n over: boolean;\n /** The paused state of the stopwatch */\n paused: boolean;\n /** The second count of the stopwatch */\n seconds: number;\n /** The function to pause the stopwatch */\n pause: () => void;\n /** The function to reset the stopwatch */\n reset: () => void;\n /** The function to start the stopwatch */\n start: () => void;\n /** The function to toggle the stopwatch */\n toggle: () => void;\n}\n\n/** The use stopwatch options */\nexport interface UseStopwatchOptions {\n /** The immediately state of the timer */\n immediately?: boolean;\n}\n\ninterface UseStopwatch {\n (initialTime?: number, options?: UseStopwatchOptions): UseStopwatchReturn;\n (options?: UseStopwatchOptions & { initialTime?: number }): UseStopwatchReturn;\n}\n/**\n * @name useStopwatch\n * @description - Hook that creates a stopwatch functionality\n * @category Time\n *\n * @overload\n * @param {number} [initialTime=0] The initial time of the timer\n * @param {boolean} [options.enabled=true] The enabled state of the timer\n * @returns {UseStopwatchReturn} An object containing the current time and functions to interact with the timer\n *\n * @example\n * const { seconds, minutes, start, pause, reset } = useStopwatch(1000, { enabled: false });\n *\n * @overload\n * @param {number} [options.initialTime=0] -The initial time of the timer\n * @param {boolean} [options.enabled=true] The enabled state of the timer\n * @returns {UseStopwatchReturn} An object containing the current time and functions to interact with the timer\n *\n * @example\n * const { seconds, minutes, start, pause, reset } = useStopwatch({ initialTime: 1000, enabled: false });\n */\nexport const useStopwatch = ((...params: any[]) => {\n const initialTime =\n (typeof params[0] === 'number'\n ? (params[0] as number | undefined)\n : (params[0] as UseStopwatchOptions & { initialTime?: number })?.initialTime) ?? 0;\n\n const options =\n typeof params[0] === 'number'\n ? (params[1] as UseStopwatchOptions | undefined)\n : (params[0] as (UseStopwatchOptions & { initialTime?: number }) | undefined);\n\n const immediately = options?.immediately ?? false;\n\n const [time, setTime] = useState(getStopwatchTime(initialTime));\n const [paused, setPaused] = useState(!immediately && !initialTime);\n\n useEffect(() => {\n if (paused) return;\n const onInterval = () => {\n setTime((prevTime) => {\n const updatedCount = prevTime.count + 1;\n\n if (updatedCount % 60 === 0) {\n return {\n ...prevTime,\n minutes: prevTime.minutes + 1,\n seconds: 0,\n count: updatedCount\n };\n }\n\n if (updatedCount % (60 * 60) === 0) {\n return {\n ...prevTime,\n hours: prevTime.hours + 1,\n minutes: 0,\n seconds: 0,\n count: updatedCount\n };\n }\n\n if (updatedCount % (60 * 60 * 24) === 0) {\n return {\n ...prevTime,\n days: prevTime.days + 1,\n hours: 0,\n minutes: 0,\n seconds: 0,\n count: updatedCount\n };\n }\n\n return {\n ...prevTime,\n seconds: prevTime.seconds + 1,\n count: updatedCount\n };\n });\n };\n\n const interval = setInterval(() => onInterval(), 1000);\n return () => clearInterval(interval);\n }, [paused]);\n\n return {\n ...time,\n paused,\n pause: () => setPaused(true),\n start: () => setPaused(false),\n reset: () => setTime(getStopwatchTime(initialTime)),\n toggle: () => setPaused((prevPause) => !prevPause)\n };\n}) as UseStopwatch;\n"],"names":["getStopwatchTime","time","days","hours","minutes","seconds","useStopwatch","params","initialTime","immediately","setTime","useState","paused","setPaused","useEffect","onInterval","prevTime","updatedCount","interval","prevPause"],"mappings":";AAEA,MAAMA,IAAmB,CAACC,MAAiB;AACzC,MAAI,CAACA;AACH,WAAO;AAAA,MACL,MAAM;AAAA,MACN,OAAO;AAAA,MACP,SAAS;AAAA,MACT,SAAS;AAAA,MACT,OAAO;AAAA,IAAA;AAGX,QAAMC,IAAO,KAAK,MAAMD,IAAO,KAAK,GAC9BE,IAAQ,KAAK,MAAOF,IAAO,QAAS,IAAI,GACxCG,IAAU,KAAK,MAAOH,IAAO,OAAQ,EAAE,GACvCI,IAAU,KAAK,MAAMJ,IAAO,EAAE;AAEpC,SAAO,EAAE,MAAAC,GAAM,OAAAC,GAAO,SAAAC,GAAS,SAAAC,GAAS,OAAOJ,EAAA;AACjD,GA2DaK,IAAgB,IAAIC,MAAkB;AACjD,QAAMC,KACH,OAAOD,EAAO,CAAC,KAAM,WACjBA,EAAO,CAAC,IACRA,EAAO,CAAC,GAAsD,gBAAgB,GAO/EE,KAJJ,OAAOF,EAAO,CAAC,KAAM,WAChBA,EAAO,CAAC,IACRA,E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atch.mjs","sources":["../../../../src/hooks/useStopwatch/useStopwatch.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\nconst getStopwatchTime = (time: number) => {\n if (!time)\n return {\n days: 0,\n hours: 0,\n minutes: 0,\n seconds: 0,\n count: 0\n };\n\n const days = Math.floor(time / 86400);\n const hours = Math.floor((time % 86400) / 3600);\n const minutes = Math.floor((time % 3600) / 60);\n const seconds = Math.floor(time % 60);\n\n return { days, hours, minutes, seconds, count: time };\n};\n\n/** The use stopwatch return type */\nexport interface UseStopwatchReturn {\n /** The total count of the stopwatch */\n count: number;\n /** The day count of the stopwatch */\n days: number;\n /** The hour count of the stopwatch */\n hours: number;\n /** The minute count of the stopwatch */\n minutes: number;\n /** The over state of the stopwatch */\n over: boolean;\n /** The paused state of the stopwatch */\n paused: boolean;\n /** The second count of the stopwatch */\n seconds: number;\n /** The function to pause the stopwatch */\n pause: () => void;\n /** The function to reset the stopwatch */\n reset: () => void;\n /** The function to start the stopwatch */\n start: () => void;\n /** The function to toggle the stopwatch */\n toggle: () => void;\n}\n\n/** The use stopwatch options */\nexport interface UseStopwatchOptions {\n /** The immediately state of the timer */\n immediately?: boolean;\n}\n\ninterface UseStopwatch {\n (initialTime?: number, options?: UseStopwatchOptions): UseStopwatchReturn;\n (options?: UseStopwatchOptions & { initialTime?: number }): UseStopwatchReturn;\n}\n/**\n * @name useStopwatch\n * @description - Hook that creates a stopwatch functionality\n * @category Time\n * @usage high\n *\n * @overload\n * @param {number} [initialTime=0] The initial time of the timer\n * @param {boolean} [options.enabled=true] The enabled state of the timer\n * @returns {UseStopwatchReturn} An object containing the current time and functions to interact with the timer\n *\n * @example\n * const { seconds, minutes, start, pause, reset } = useStopwatch(1000, { enabled: false });\n *\n * @overload\n * @param {number} [options.initialTime=0] -The initial time of the timer\n * @param {boolean} [options.enabled=true] The enabled state of the timer\n * @returns {UseStopwatchReturn} An object containing the current time and functions to interact with the timer\n *\n * @example\n * const { seconds, minutes, start, pause, reset } = useStopwatch({ initialTime: 1000, enabled: false });\n */\nexport const useStopwatch = ((...params: any[]) => {\n const initialTime =\n (typeof params[0] === 'number'\n ? (params[0] as number | undefined)\n : (params[0] as UseStopwatchOptions & { initialTime?: number })?.initialTime) ?? 0;\n\n const options =\n typeof params[0] === 'number'\n ? (params[1] as UseStopwatchOptions | undefined)\n : (params[0] as (UseStopwatchOptions & { initialTime?: number }) | undefined);\n\n const immediately = options?.immediately ?? false;\n\n const [time, setTime] = useState(getStopwatchTime(initialTime));\n const [paused, setPaused] = useState(!immediately && !initialTime);\n\n useEffect(() => {\n if (paused) return;\n const onInterval = () => {\n setTime((prevTime) => {\n const updatedCount = prevTime.count + 1;\n\n if (updatedCount % 60 === 0) {\n return {\n ...prevTime,\n minutes: prevTime.minutes + 1,\n seconds: 0,\n count: updatedCount\n };\n }\n\n if (updatedCount % (60 * 60) === 0) {\n return {\n ...prevTime,\n hours: prevTime.hours + 1,\n minutes: 0,\n seconds: 0,\n count: updatedCount\n };\n }\n\n if (updatedCount % (60 * 60 * 24) === 0) {\n return {\n ...prevTime,\n days: prevTime.days + 1,\n hours: 0,\n minutes: 0,\n seconds: 0,\n count: updatedCount\n };\n }\n\n return {\n ...prevTime,\n seconds: prevTime.seconds + 1,\n count: updatedCount\n };\n });\n };\n\n const interval = setInterval(() => onInterval(), 1000);\n return () => clearInterval(interval);\n }, [paused]);\n\n return {\n ...time,\n paused,\n pause: () => setPaused(true),\n start: () => setPaused(false),\n reset: () => setTime(getStopwatchTime(initialTime)),\n toggle: () => setPaused((prevPause) => !prevPause)\n };\n}) as UseStopwatch;\n"],"names":["getStopwatchTime","time","days","hours","minutes","seconds","useStopwatch","params","initialTime","immediately","setTime","useState","paused","setPaused","useEffect","onInterval","prevTime","updatedCount","interval","prevPause"],"mappings":";AAEA,MAAMA,IAAmB,CAACC,MAAiB;AACzC,MAAI,CAACA;AACH,WAAO;AAAA,MACL,MAAM;AAAA,MACN,OAAO;AAAA,MACP,SAAS;AAAA,MACT,SAAS;AA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A,UACL,GAAGD;AAAA,UACH,SAASA,EAAS,UAAU;AAAA,UAC5B,OAAOC;AAAA,QAAA;AAAA,MACT,CACD;AAAA,IAAA,GAGGC,IAAW,YAAY,MAAMH,EAAA,GAAc,GAAI;AACrD,WAAO,MAAM,cAAcG,CAAQ;AAAA,EAAA,GAClC,CAACN,CAAM,CAAC,GAEJ;AAAA,IACL,GAAGX;AAAA,IACH,QAAAW;AAAA,IACA,OAAO,MAAMC,EAAU,EAAI;AAAA,IAC3B,OAAO,MAAMA,EAAU,EAAK;AAAA,IAC5B,OAAO,MAAMH,EAAQV,EAAiBQ,CAAW,CAAC;AAAA,IAClD,QAAQ,MAAMK,EAAU,CAACM,MAAc,CAACA,CAAS;AAAA,EAAA;AAErD;"}
@@ -1 +1 @@
1
- {"version":3,"file":"useStorage.mjs","sources":["../../../../src/hooks/useStorage/useStorage.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\n/* The use storage initial value type */\nexport type UseStorageInitialValue<Value> = (() => Value) | Value;\n\n/* The use storage options type */\nexport interface UseStorageOptions<Value> {\n /* The initial value of the storage */\n initialValue?: UseStorageInitialValue<Value>;\n /* The storage to be used */\n storage?: Storage;\n /* The deserializer function to be invoked */\n deserializer?: (value: string) => Value;\n /* The serializer function to be invoked */\n serializer?: (value: Value) => string;\n}\n\n/* The use storage return type */\nexport interface UseStorageReturn<Value> {\n /* The value of the storage */\n value: Value;\n /* The error state of the storage */\n remove: () => void;\n /* The loading state of the storage */\n set: (value: Value) => void;\n}\n\nexport interface UseStorage {\n <Value>(key: string, options?: UseStorageOptions<Value>): UseStorageReturn<Value | undefined>;\n\n <Value>(\n key: string,\n initialValue?: UseStorageInitialValue<Value>\n ): UseStorageReturn<Value | undefined>;\n}\n\nexport const STORAGE_EVENT = 'reactuse-storage';\n\nexport const dispatchStorageEvent = (params: Partial<StorageEvent>) =>\n window.dispatchEvent(new StorageEvent(STORAGE_EVENT, params));\n\nconst setStorageItem = (storage: Storage, key: string, value: string) => {\n const oldValue = storage.getItem(key);\n\n storage.setItem(key, value);\n dispatchStorageEvent({\n key,\n oldValue,\n newValue: value,\n storageArea: storage\n });\n};\n\nconst removeStorageItem = (storage: Storage, key: string) => {\n const oldValue = storage.getItem(key);\n\n storage.removeItem(key);\n dispatchStorageEvent({ key, oldValue, newValue: null, storageArea: storage });\n};\n\nconst getStorageItem = (storage: Storage, key: string) => {\n const value = storage.getItem(key);\n if (!value) return undefined;\n return value;\n};\n\n/**\n * @name useStorage\n * @description - Hook that manages storage value\n * @category State\n *\n * @overload\n * @param {string} key The key of the storage\n * @param {UseStorageInitialValue<Value>} [initialValue] The initial value of the storage\n * @returns {UseStorageReturn<Value>} The value and the set function\n *\n * @overload\n * @param {string} key The key of the storage\n * @param {(value: Value) => string} [params.serializer] The serializer function\n * @param {(value: string) => Value} [params.deserializer] The deserializer function\n * @param {Storage} [params.storage] The storage\n * @param {UseStorageInitialValue<Value>} [params.initialValue] The initial value of the storage\n * @returns {UseStorageReturn<Value>} The value and the set function\n *\n * @example\n * const { value, set, remove } = useStorage('key', 'value');\n */\nexport const useStorage = (<Value>(key: string, params?: any): UseStorageReturn<Value> => {\n const options = (\n typeof params === 'object' &&\n params &&\n ('serializer' in params ||\n 'deserializer' in params ||\n 'initialValue' in params ||\n 'storage' in params)\n ? params\n : undefined\n ) as UseStorageOptions<Value>;\n\n const initialValue = (options ? options?.initialValue : params) as UseStorageInitialValue<Value>;\n\n if (typeof window === 'undefined') {\n const value = typeof initialValue === 'function' ? (initialValue as () => any)() : initialValue;\n return {\n value,\n set: () => {},\n remove: () => {}\n };\n }\n\n const serializer = (value: Value) => {\n if (options?.serializer) return options.serializer(value);\n if (typeof value === 'string') return value;\n return JSON.stringify(value);\n };\n\n const storage = options?.storage ?? window?.localStorage;\n\n const set = (value: Value) => setStorageItem(storage, key, serializer(value));\n const remove = () => removeStorageItem(storage, key);\n\n const deserializer = (value: string) => {\n if (options?.deserializer) return options.deserializer(value);\n if (value === 'undefined') return undefined as unknown as Value;\n\n try {\n return JSON.parse(value) as Value;\n } catch {\n return value as Value;\n }\n };\n\n const [value, setValue] = useState<Value | undefined>(() => {\n const storageValue = getStorageItem(storage, key);\n if (storageValue === undefined && initialValue !== undefined) {\n const value =\n typeof initialValue === 'function' ? (initialValue as () => Value)() : initialValue;\n setStorageItem(storage, key, serializer(value));\n return value;\n }\n return storageValue ? deserializer(storageValue) : undefined;\n });\n\n useEffect(() => {\n const onChange = () => {\n const storageValue = getStorageItem(storage, key);\n setValue(storageValue ? deserializer(storageValue) : undefined);\n };\n window.addEventListener(STORAGE_EVENT, onChange);\n return () => window.removeEventListener(STORAGE_EVENT, onChange);\n }, [key]);\n\n return {\n value: value as Value,\n set,\n remove\n };\n}) as UseStorage;\n"],"names":["STORAGE_EVENT","dispatchStorageEvent","params","setStorageItem","storage","key","value","oldValue","removeStorageItem","getStorageItem","useStorage","options","initialValue","serializer","set","remove","deserializer","setValue","useState","storageValue","useEffect","onChange"],"mappings":";AAoCO,MAAMA,IAAgB,oBAEhBC,IAAuB,CAACC,MACnC,OAAO,cAAc,IAAI,aAAaF,GAAeE,CAAM,CAAC,GAExDC,IAAiB,CAACC,GAAkBC,GAAaC,MAAkB;AACvE,QAAMC,IAAWH,EAAQ,QAAQC,CAAG;AAEpC,EAAAD,EAAQ,QAAQC,GAAKC,CAAK,GAC1BL,EAAqB;AAAA,IACnB,KAAAI;AAAA,IACA,UAAAE;AAAA,IACA,UAAUD;AAAA,IACV,aAAaF;AAAA,EAAA,CACd;AACH,GAEMI,IAAoB,CAACJ,GAAkBC,MAAgB;AAC3D,QAAME,IAAWH,EAAQ,QAAQC,CAAG;AAEpC,EAAAD,EAAQ,WAAWC,CAAG,GACtBJ,EAAqB,EAAE,KAAAI,GAAK,UAAAE,GAAU,UAAU,MAAM,aAAaH,GAAS;AAC9E,GAEMK,IAAiB,CAACL,GAAkBC,MAAgB;AACxD,QAAMC,IAAQF,EAAQ,QAAQC,CAAG;AACjC,MAAKC;AACL,WAAOA;A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E,IAAeH,EAAaG,CAAY,IAAI,MAAS;AAAA,IAAA;AAEhE,kBAAO,iBAAiBnB,GAAeqB,CAAQ,GACxC,MAAM,OAAO,oBAAoBrB,GAAeqB,CAAQ;AAAA,EAAA,GAC9D,CAAChB,CAAG,CAAC,GAED;AAAA,IACL,OAAAC;AAAA,IACA,KAAAQ;AAAA,IACA,QAAAC;AAAA,EAAA;AAEJ;"}
1
+ {"version":3,"file":"useStorage.mjs","sources":["../../../../src/hooks/useStorage/useStorage.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\n/* The use storage initial value type */\nexport type UseStorageInitialValue<Value> = (() => Value) | Value;\n\n/* The use storage options type */\nexport interface UseStorageOptions<Value> {\n /* The initial value of the storage */\n initialValue?: UseStorageInitialValue<Value>;\n /* The storage to be used */\n storage?: Storage;\n /* The deserializer function to be invoked */\n deserializer?: (value: string) => Value;\n /* The serializer function to be invoked */\n serializer?: (value: Value) => string;\n}\n\n/* The use storage return type */\nexport interface UseStorageReturn<Value> {\n /* The value of the storage */\n value: Value;\n /* The error state of the storage */\n remove: () => void;\n /* The loading state of the storage */\n set: (value: Value) => void;\n}\n\nexport interface UseStorage {\n <Value>(key: string, options?: UseStorageOptions<Value>): UseStorageReturn<Value | undefined>;\n\n <Value>(\n key: string,\n initialValue?: UseStorageInitialValue<Value>\n ): UseStorageReturn<Value | undefined>;\n}\n\nexport const STORAGE_EVENT = 'reactuse-storage';\n\nexport const dispatchStorageEvent = (params: Partial<StorageEvent>) =>\n window.dispatchEvent(new StorageEvent(STORAGE_EVENT, params));\n\nconst setStorageItem = (storage: Storage, key: string, value: string) => {\n const oldValue = storage.getItem(key);\n\n storage.setItem(key, value);\n dispatchStorageEvent({\n key,\n oldValue,\n newValue: value,\n storageArea: storage\n });\n};\n\nconst removeStorageItem = (storage: Storage, key: string) => {\n const oldValue = storage.getItem(key);\n\n storage.removeItem(key);\n dispatchStorageEvent({ key, oldValue, newValue: null, storageArea: storage });\n};\n\nconst getStorageItem = (storage: Storage, key: string) => {\n const value = storage.getItem(key);\n if (!value) return undefined;\n return value;\n};\n\n/**\n * @name useStorage\n * @description - Hook that manages storage value\n * @category State\n * @usage high\n *\n * @overload\n * @param {string} key The key of the storage\n * @param {UseStorageInitialValue<Value>} [initialValue] The initial value of the storage\n * @returns {UseStorageReturn<Value>} The value and the set function\n *\n * @overload\n * @param {string} key The key of the storage\n * @param {(value: Value) => string} [params.serializer] The serializer function\n * @param {(value: string) => Value} [params.deserializer] The deserializer function\n * @param {Storage} [params.storage] The storage\n * @param {UseStorageInitialValue<Value>} [params.initialValue] The initial value of the storage\n * @returns {UseStorageReturn<Value>} The value and the set function\n *\n * @example\n * const { value, set, remove } = useStorage('key', 'value');\n */\nexport const useStorage = (<Value>(key: string, params?: any): UseStorageReturn<Value> => {\n const options = (\n typeof params === 'object' &&\n params &&\n ('serializer' in params ||\n 'deserializer' in params ||\n 'initialValue' in params ||\n 'storage' in params)\n ? params\n : undefined\n ) as UseStorageOptions<Value>;\n\n const initialValue = (options ? options?.initialValue : params) as UseStorageInitialValue<Value>;\n\n if (typeof window === 'undefined') {\n const value = typeof initialValue === 'function' ? (initialValue as () => any)() : initialValue;\n return {\n value,\n set: () => {},\n remove: () => {}\n };\n }\n\n const serializer = (value: Value) => {\n if (options?.serializer) return options.serializer(value);\n if (typeof value === 'string') return value;\n return JSON.stringify(value);\n };\n\n const storage = options?.storage ?? window?.localStorage;\n\n const set = (value: Value) => setStorageItem(storage, key, serializer(value));\n const remove = () => removeStorageItem(storage, key);\n\n const deserializer = (value: string) => {\n if (options?.deserializer) return options.deserializer(value);\n if (value === 'undefined') return undefined as unknown as Value;\n\n try {\n return JSON.parse(value) as Value;\n } catch {\n return value as Value;\n }\n };\n\n const [value, setValue] = useState<Value | undefined>(() => {\n const storageValue = getStorageItem(storage, key);\n if (storageValue === undefined && initialValue !== undefined) {\n const value =\n typeof initialValue === 'function' ? (initialValue as () => Value)() : initialValue;\n setStorageItem(storage, key, serializer(value));\n return value;\n }\n return storageValue ? deserializer(storageValue) : undefined;\n });\n\n useEffect(() => {\n const onChange = () => {\n const storageValue = getStorageItem(storage, key);\n setValue(storageValue ? deserializer(storageValue) : undefined);\n };\n window.addEventListener(STORAGE_EVENT, onChange);\n return () => window.removeEventListener(STORAGE_EVENT, onChange);\n }, [key]);\n\n return {\n value: value as Value,\n set,\n remove\n };\n}) as UseStorage;\n"],"names":["STORAGE_EVENT","dispatchStorageEvent","params","setStorageItem","storage","key","value","oldValue","removeStorageItem","getStorageItem","useStorage","options","initialValue","serializer","set","remove","deserializer","setValue","useState","storageValue","useEffect","onChange"],"mappings":";AAoCO,MAAMA,IAAgB,oBAEhBC,IAAuB,CAACC,MACnC,OAAO,cAAc,IAAI,aAAaF,GAAeE,CAAM,CAAC,GAExDC,IAAiB,CAACC,GAAkBC,GAAaC,MAAkB;AACvE,QAAMC,IAAWH,EAAQ,QAAQC,CAAG;AAEpC,EAAAD,EAAQ,QAAQC,GAAKC,CAAK,GAC1BL,EAAqB;AAAA,IACnB,KAAAI;AAAA,IACA,UAAAE;AAAA,IACA,UAAUD;AAAA,IACV,aAAaF;AAAA,EAAA,CACd;AACH,GAEMI,IAAoB,CAACJ,GAAkBC,MAAgB;AAC3D,QAAME,IAAWH,EAAQ,QAAQC,CAAG;AAEpC,EAAAD,EAAQ,WAAWC,CAAG,GACtBJ,EAAqB,EAAE,KAAAI,GAAK,UAAAE,GAAU,UAAU,MAAM,aAAaH,GAAS;AAC9E,GAEMK,IAAiB,CAACL,GAAkBC,MAAgB;AACxD,QAAMC,IAAQF,EAAQ,QAAQC,CAAG;AACjC,MAAKC;AACL,WAAOA;AACT,GAwBaI,IAAc,CAAQL,GAAaH,MAA0C;AACxF,QAAMS,IACJ,OAAOT,KAAW,YAClBA,MACC,gBAAgBA,KACf,kBAAkBA,KAClB,kBAAkBA,KAClB,aAAaA,KACXA,IACA,QAGAU,IAAgBD,IAAUA,GAAS,eAAeT;AAExD,MAAI,OAAO,SAAW;AAEpB,WAA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IACA,QAAAC;AAAA,EAAA;AAEJ;"}
@@ -2,31 +2,31 @@ import { useRef as a, useState as v, useEffect as g } from "react";
2
2
  import { useRefState as A } from "../useRefState/useRefState.mjs";
3
3
  import { isTarget as R } from "../../utils/helpers/isTarget.mjs";
4
4
  import { getElement as b } from "../../utils/helpers/getElement.mjs";
5
- const E = (...o) => {
6
- const t = R(o[0]) ? o[0] : void 0, d = (t ? o[1] : o[0]) ?? "ltr", r = A(), n = a(null), i = () => (t ? b(t) : r.current)?.getAttribute("dir") ?? d, [u, c] = v(i()), s = () => {
5
+ const y = (...o) => {
6
+ const t = R(o[0]) ? o[0] : void 0, c = (t ? o[1] : o[0]) ?? "ltr", r = A(), n = a(null), i = () => typeof window > "u" ? c : (t ? b(t) : r.current)?.getAttribute("dir") ?? c, [s, u] = v(i()), f = () => {
7
7
  n.current && n.current?.removeAttribute("dir");
8
- }, f = (e) => {
9
- n.current && (c(e), n.current.setAttribute("dir", e));
8
+ }, l = (e) => {
9
+ n.current && (u(e), n.current.setAttribute("dir", e));
10
10
  };
11
11
  return g(() => {
12
12
  if (!t && !r.state) return;
13
13
  const e = (t ? b(t) : r.current) ?? document.querySelector("html");
14
14
  if (!e) return;
15
15
  n.current = e;
16
- const l = i();
17
- e.setAttribute("dir", l), c(l);
18
- const m = new MutationObserver(i);
19
- return m.observe(e, { attributes: !0 }), () => {
20
- m.disconnect();
16
+ const m = i();
17
+ e.setAttribute("dir", m), u(m);
18
+ const d = new MutationObserver(() => u(i()));
19
+ return d.observe(e, { attributes: !0 }), () => {
20
+ d.disconnect();
21
21
  };
22
- }, [r.state, t]), t ? { value: u, set: f, remove: s } : {
22
+ }, [r.state, t]), t ? { value: s, set: l, remove: f } : {
23
23
  ref: r,
24
- value: u,
25
- set: f,
26
- remove: s
24
+ value: s,
25
+ set: l,
26
+ remove: f
27
27
  };
28
28
  };
29
29
  export {
30
- E as useTextDirection
30
+ y as useTextDirection
31
31
  };
32
32
  //# sourceMappingURL=useTextDirection.mjs.map