@siberiacancode/reactuse 0.2.11 → 0.2.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (413) hide show
  1. package/README.md +71 -71
  2. package/dist/cjs/helpers/createContext/createContext.cjs.map +1 -1
  3. package/dist/cjs/helpers/createReactiveContext/createReactiveContext.cjs.map +1 -1
  4. package/dist/cjs/helpers/createStore/createStore.cjs.map +1 -1
  5. package/dist/cjs/hooks/useActiveElement/useActiveElement.cjs +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/useBattery/useBattery.cjs +1 -1
  9. package/dist/cjs/hooks/useBattery/useBattery.cjs.map +1 -1
  10. package/dist/cjs/hooks/useBluetooth/useBluetooth.cjs +1 -1
  11. package/dist/cjs/hooks/useBluetooth/useBluetooth.cjs.map +1 -1
  12. package/dist/cjs/hooks/useBoolean/useBoolean.cjs.map +1 -1
  13. package/dist/cjs/hooks/useBreakpoints/useBreakpoints.cjs.map +1 -1
  14. package/dist/cjs/hooks/useBrowserLanguage/useBrowserLanguage.cjs.map +1 -1
  15. package/dist/cjs/hooks/useClickOutside/useClickOutside.cjs.map +1 -1
  16. package/dist/cjs/hooks/useClipboard/useClipboard.cjs +1 -1
  17. package/dist/cjs/hooks/useClipboard/useClipboard.cjs.map +1 -1
  18. package/dist/cjs/hooks/useCookie/useCookie.cjs +1 -1
  19. package/dist/cjs/hooks/useCookie/useCookie.cjs.map +1 -1
  20. package/dist/cjs/hooks/useCookies/useCookies.cjs +1 -1
  21. package/dist/cjs/hooks/useCookies/useCookies.cjs.map +1 -1
  22. package/dist/cjs/hooks/useCopy/useCopy.cjs.map +1 -1
  23. package/dist/cjs/hooks/useCounter/useCounter.cjs +1 -1
  24. package/dist/cjs/hooks/useCounter/useCounter.cjs.map +1 -1
  25. package/dist/cjs/hooks/useCssVar/useCssVar.cjs +1 -1
  26. package/dist/cjs/hooks/useCssVar/useCssVar.cjs.map +1 -1
  27. package/dist/cjs/hooks/useDebounceCallback/useDebounceCallback.cjs.map +1 -1
  28. package/dist/cjs/hooks/useDebounceValue/useDebounceValue.cjs.map +1 -1
  29. package/dist/cjs/hooks/useDeviceMotion/useDeviceMotion.cjs +1 -1
  30. package/dist/cjs/hooks/useDeviceMotion/useDeviceMotion.cjs.map +1 -1
  31. package/dist/cjs/hooks/useDeviceOrientation/useDeviceOrientation.cjs.map +1 -1
  32. package/dist/cjs/hooks/useDevicePixelRatio/useDevicePixelRatio.cjs.map +1 -1
  33. package/dist/cjs/hooks/useDidUpdate/useDidUpdate.cjs.map +1 -1
  34. package/dist/cjs/hooks/useDisclosure/useDisclosure.cjs +1 -1
  35. package/dist/cjs/hooks/useDisclosure/useDisclosure.cjs.map +1 -1
  36. package/dist/cjs/hooks/useDisplayMedia/useDisplayMedia.cjs +1 -1
  37. package/dist/cjs/hooks/useDisplayMedia/useDisplayMedia.cjs.map +1 -1
  38. package/dist/cjs/hooks/useDocumentEvent/useDocumentEvent.cjs.map +1 -1
  39. package/dist/cjs/hooks/useDocumentTitle/useDocumentTitle.cjs +1 -1
  40. package/dist/cjs/hooks/useDocumentTitle/useDocumentTitle.cjs.map +1 -1
  41. package/dist/cjs/hooks/useDocumentVisibility/useDocumentVisibility.cjs.map +1 -1
  42. package/dist/cjs/hooks/useDoubleClick/useDoubleClick.cjs +1 -1
  43. package/dist/cjs/hooks/useDoubleClick/useDoubleClick.cjs.map +1 -1
  44. package/dist/cjs/hooks/useDropZone/useDropZone.cjs +1 -1
  45. package/dist/cjs/hooks/useDropZone/useDropZone.cjs.map +1 -1
  46. package/dist/cjs/hooks/useElementSize/useElementSize.cjs.map +1 -1
  47. package/dist/cjs/hooks/useEvent/useEvent.cjs.map +1 -1
  48. package/dist/cjs/hooks/useEventListener/useEventListener.cjs.map +1 -1
  49. package/dist/cjs/hooks/useEventSource/useEventSource.cjs +1 -1
  50. package/dist/cjs/hooks/useEventSource/useEventSource.cjs.map +1 -1
  51. package/dist/cjs/hooks/useEyeDropper/useEyeDropper.cjs.map +1 -1
  52. package/dist/cjs/hooks/useFavicon/useFavicon.cjs +1 -1
  53. package/dist/cjs/hooks/useFavicon/useFavicon.cjs.map +1 -1
  54. package/dist/cjs/hooks/useField/useField.cjs +1 -1
  55. package/dist/cjs/hooks/useField/useField.cjs.map +1 -1
  56. package/dist/cjs/hooks/useFileDialog/useFileDialog.cjs +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 +1 -1
  63. package/dist/cjs/hooks/useFullscreen/useFullscreen.cjs.map +1 -1
  64. package/dist/cjs/hooks/useGamepad/useGamepad.cjs.map +1 -1
  65. package/dist/cjs/hooks/useGeolocation/useGeolocation.cjs +1 -1
  66. package/dist/cjs/hooks/useGeolocation/useGeolocation.cjs.map +1 -1
  67. package/dist/cjs/hooks/useHash/useHash.cjs.map +1 -1
  68. package/dist/cjs/hooks/useHotkeys/useHotkeys.cjs +1 -1
  69. package/dist/cjs/hooks/useHotkeys/useHotkeys.cjs.map +1 -1
  70. package/dist/cjs/hooks/useHover/useHover.cjs +1 -1
  71. package/dist/cjs/hooks/useHover/useHover.cjs.map +1 -1
  72. package/dist/cjs/hooks/useIdle/useIdle.cjs.map +1 -1
  73. package/dist/cjs/hooks/useImage/useImage.cjs.map +1 -1
  74. package/dist/cjs/hooks/useInfiniteScroll/useInfiniteScroll.cjs +1 -1
  75. package/dist/cjs/hooks/useInfiniteScroll/useInfiniteScroll.cjs.map +1 -1
  76. package/dist/cjs/hooks/useIntersectionObserver/useIntersectionObserver.cjs +1 -1
  77. package/dist/cjs/hooks/useIntersectionObserver/useIntersectionObserver.cjs.map +1 -1
  78. package/dist/cjs/hooks/useInterval/useInterval.cjs +1 -1
  79. package/dist/cjs/hooks/useInterval/useInterval.cjs.map +1 -1
  80. package/dist/cjs/hooks/useIsFirstRender/useIsFirstRender.cjs.map +1 -1
  81. package/dist/cjs/hooks/useKeyPress/useKeyPress.cjs +1 -1
  82. package/dist/cjs/hooks/useKeyPress/useKeyPress.cjs.map +1 -1
  83. package/dist/cjs/hooks/useKeyPressEvent/useKeyPressEvent.cjs +1 -1
  84. package/dist/cjs/hooks/useKeyPressEvent/useKeyPressEvent.cjs.map +1 -1
  85. package/dist/cjs/hooks/useKeyboard/useKeyboard.cjs +1 -1
  86. package/dist/cjs/hooks/useKeyboard/useKeyboard.cjs.map +1 -1
  87. package/dist/cjs/hooks/useKeysPressed/useKeysPressed.cjs +1 -1
  88. package/dist/cjs/hooks/useKeysPressed/useKeysPressed.cjs.map +1 -1
  89. package/dist/cjs/hooks/useLastChanged/useLastChanged.cjs +1 -1
  90. package/dist/cjs/hooks/useLastChanged/useLastChanged.cjs.map +1 -1
  91. package/dist/cjs/hooks/useLatest/useLatest.cjs +1 -1
  92. package/dist/cjs/hooks/useLatest/useLatest.cjs.map +1 -1
  93. package/dist/cjs/hooks/useLess/useLess.cjs.map +1 -1
  94. package/dist/cjs/hooks/useList/useList.cjs.map +1 -1
  95. package/dist/cjs/hooks/useLockCallback/useLockCallback.cjs.map +1 -1
  96. package/dist/cjs/hooks/useLogger/useLogger.cjs.map +1 -1
  97. package/dist/cjs/hooks/useLongPress/useLongPress.cjs +1 -1
  98. package/dist/cjs/hooks/useLongPress/useLongPress.cjs.map +1 -1
  99. package/dist/cjs/hooks/useMap/useMap.cjs.map +1 -1
  100. package/dist/cjs/hooks/useMeasure/useMeasure.cjs.map +1 -1
  101. package/dist/cjs/hooks/useMediaQuery/useMediaQuery.cjs.map +1 -1
  102. package/dist/cjs/hooks/useMemory/useMemory.cjs +1 -1
  103. package/dist/cjs/hooks/useMemory/useMemory.cjs.map +1 -1
  104. package/dist/cjs/hooks/useMount/useMount.cjs.map +1 -1
  105. package/dist/cjs/hooks/useMouse/useMouse.cjs.map +1 -1
  106. package/dist/cjs/hooks/useMutation/useMutation.cjs +1 -1
  107. package/dist/cjs/hooks/useMutation/useMutation.cjs.map +1 -1
  108. package/dist/cjs/hooks/useMutationObserver/useMutationObserver.cjs +1 -1
  109. package/dist/cjs/hooks/useMutationObserver/useMutationObserver.cjs.map +1 -1
  110. package/dist/cjs/hooks/useNetwork/useNetwork.cjs +1 -1
  111. package/dist/cjs/hooks/useNetwork/useNetwork.cjs.map +1 -1
  112. package/dist/cjs/hooks/useOffsetPagination/useOffsetPagination.cjs.map +1 -1
  113. package/dist/cjs/hooks/useOnce/useOnce.cjs.map +1 -1
  114. package/dist/cjs/hooks/useOnline/useOnline.cjs.map +1 -1
  115. package/dist/cjs/hooks/useOperatingSystem/useOperatingSystem.cjs.map +1 -1
  116. package/dist/cjs/hooks/useOptimistic/useOptimistic.cjs.map +1 -1
  117. package/dist/cjs/hooks/useOrientation/useOrientation.cjs.map +1 -1
  118. package/dist/cjs/hooks/useOtpCredential/useOtpCredential.cjs +1 -1
  119. package/dist/cjs/hooks/useOtpCredential/useOtpCredential.cjs.map +1 -1
  120. package/dist/cjs/hooks/usePageLeave/usePageLeave.cjs +1 -1
  121. package/dist/cjs/hooks/usePageLeave/usePageLeave.cjs.map +1 -1
  122. package/dist/cjs/hooks/usePaint/usePaint.cjs +1 -1
  123. package/dist/cjs/hooks/usePaint/usePaint.cjs.map +1 -1
  124. package/dist/cjs/hooks/useParallax/useParallax.cjs.map +1 -1
  125. package/dist/cjs/hooks/usePerformanceObserver/usePerformanceObserver.cjs +1 -1
  126. package/dist/cjs/hooks/usePerformanceObserver/usePerformanceObserver.cjs.map +1 -1
  127. package/dist/cjs/hooks/usePermission/usePermission.cjs +1 -1
  128. package/dist/cjs/hooks/usePermission/usePermission.cjs.map +1 -1
  129. package/dist/cjs/hooks/usePointerLock/usePointerLock.cjs.map +1 -1
  130. package/dist/cjs/hooks/usePostMessage/usePostMessage.cjs.map +1 -1
  131. package/dist/cjs/hooks/usePreferredColorScheme/usePreferredColorScheme.cjs.map +1 -1
  132. package/dist/cjs/hooks/usePreferredContrast/usePreferredContrast.cjs.map +1 -1
  133. package/dist/cjs/hooks/usePreferredLanguages/usePreferredLanguages.cjs.map +1 -1
  134. package/dist/cjs/hooks/usePreferredReducedMotion/usePreferredReducedMotion.cjs.map +1 -1
  135. package/dist/cjs/hooks/usePrevious/usePrevious.cjs +1 -1
  136. package/dist/cjs/hooks/usePrevious/usePrevious.cjs.map +1 -1
  137. package/dist/cjs/hooks/useQuery/useQuery.cjs +1 -1
  138. package/dist/cjs/hooks/useQuery/useQuery.cjs.map +1 -1
  139. package/dist/cjs/hooks/useQueue/useQueue.cjs.map +1 -1
  140. package/dist/cjs/hooks/useRaf/useRaf.cjs +1 -1
  141. package/dist/cjs/hooks/useRaf/useRaf.cjs.map +1 -1
  142. package/dist/cjs/hooks/useRafValue/useRafValue.cjs.map +1 -1
  143. package/dist/cjs/hooks/useRefState/useRefState.cjs.map +1 -1
  144. package/dist/cjs/hooks/useRenderCount/useRenderCount.cjs.map +1 -1
  145. package/dist/cjs/hooks/useRenderInfo/useRenderInfo.cjs.map +1 -1
  146. package/dist/cjs/hooks/useRerender/useRerender.cjs.map +1 -1
  147. package/dist/cjs/hooks/useResizeObserver/useResizeObserver.cjs +1 -1
  148. package/dist/cjs/hooks/useResizeObserver/useResizeObserver.cjs.map +1 -1
  149. package/dist/cjs/hooks/useScreenOrientation/useScreenOrientation.cjs +1 -1
  150. package/dist/cjs/hooks/useScreenOrientation/useScreenOrientation.cjs.map +1 -1
  151. package/dist/cjs/hooks/useScript/useScript.cjs +1 -1
  152. package/dist/cjs/hooks/useScript/useScript.cjs.map +1 -1
  153. package/dist/cjs/hooks/useScroll/useScroll.cjs +1 -1
  154. package/dist/cjs/hooks/useScroll/useScroll.cjs.map +1 -1
  155. package/dist/cjs/hooks/useScrollIntoView/useScrollIntoView.cjs.map +1 -1
  156. package/dist/cjs/hooks/useScrollTo/useScrollTo.cjs.map +1 -1
  157. package/dist/cjs/hooks/useSet/useSet.cjs.map +1 -1
  158. package/dist/cjs/hooks/useShare/useShare.cjs.map +1 -1
  159. package/dist/cjs/hooks/useSpeechRecognition/useSpeechRecognition.cjs +1 -1
  160. package/dist/cjs/hooks/useSpeechRecognition/useSpeechRecognition.cjs.map +1 -1
  161. package/dist/cjs/hooks/useSpeechSynthesis/useSpeechSynthesis.cjs +1 -1
  162. package/dist/cjs/hooks/useSpeechSynthesis/useSpeechSynthesis.cjs.map +1 -1
  163. package/dist/cjs/hooks/useStateHistory/useStateHistory.cjs.map +1 -1
  164. package/dist/cjs/hooks/useStep/useStep.cjs.map +1 -1
  165. package/dist/cjs/hooks/useSticky/useSticky.cjs +1 -1
  166. package/dist/cjs/hooks/useSticky/useSticky.cjs.map +1 -1
  167. package/dist/cjs/hooks/useStopwatch/useStopwatch.cjs +1 -1
  168. package/dist/cjs/hooks/useStopwatch/useStopwatch.cjs.map +1 -1
  169. package/dist/cjs/hooks/useStorage/useStorage.cjs +1 -1
  170. package/dist/cjs/hooks/useStorage/useStorage.cjs.map +1 -1
  171. package/dist/cjs/hooks/useTextDirection/useTextDirection.cjs +1 -1
  172. package/dist/cjs/hooks/useTextDirection/useTextDirection.cjs.map +1 -1
  173. package/dist/cjs/hooks/useTextSelection/useTextSelection.cjs +1 -1
  174. package/dist/cjs/hooks/useTextSelection/useTextSelection.cjs.map +1 -1
  175. package/dist/cjs/hooks/useThrottleCallback/useThrottleCallback.cjs.map +1 -1
  176. package/dist/cjs/hooks/useThrottleValue/useThrottleValue.cjs.map +1 -1
  177. package/dist/cjs/hooks/useTime/useTime.cjs.map +1 -1
  178. package/dist/cjs/hooks/useTimeout/useTimeout.cjs.map +1 -1
  179. package/dist/cjs/hooks/useTimer/useTimer.cjs +1 -1
  180. package/dist/cjs/hooks/useTimer/useTimer.cjs.map +1 -1
  181. package/dist/cjs/hooks/useToggle/useToggle.cjs.map +1 -1
  182. package/dist/cjs/hooks/useUnmount/useUnmount.cjs.map +1 -1
  183. package/dist/cjs/hooks/useUrlSearchParam/useUrlSearchParam.cjs +1 -1
  184. package/dist/cjs/hooks/useUrlSearchParam/useUrlSearchParam.cjs.map +1 -1
  185. package/dist/cjs/hooks/useUrlSearchParams/useUrlSearchParams.cjs +1 -1
  186. package/dist/cjs/hooks/useUrlSearchParams/useUrlSearchParams.cjs.map +1 -1
  187. package/dist/cjs/hooks/useVibrate/useVibrate.cjs.map +1 -1
  188. package/dist/cjs/hooks/useWakeLock/useWakeLock.cjs +1 -1
  189. package/dist/cjs/hooks/useWakeLock/useWakeLock.cjs.map +1 -1
  190. package/dist/cjs/hooks/useWebSocket/useWebSocket.cjs +1 -1
  191. package/dist/cjs/hooks/useWebSocket/useWebSocket.cjs.map +1 -1
  192. package/dist/cjs/hooks/useWindowEvent/useWindowEvent.cjs.map +1 -1
  193. package/dist/cjs/hooks/useWindowFocus/useWindowFocus.cjs.map +1 -1
  194. package/dist/cjs/hooks/useWindowScroll/useWindowScroll.cjs.map +1 -1
  195. package/dist/cjs/hooks/useWindowSize/useWindowSize.cjs +1 -1
  196. package/dist/cjs/hooks/useWindowSize/useWindowSize.cjs.map +1 -1
  197. package/dist/cjs/hooks/useWizard/useWizard.cjs +1 -1
  198. package/dist/cjs/hooks/useWizard/useWizard.cjs.map +1 -1
  199. package/dist/cjs/utils/helpers/copy.cjs.map +1 -1
  200. package/dist/cjs/utils/helpers/debounce.cjs.map +1 -1
  201. package/dist/cjs/utils/helpers/getDate.cjs.map +1 -1
  202. package/dist/cjs/utils/helpers/getElement.cjs.map +1 -1
  203. package/dist/cjs/utils/helpers/getRetry.cjs.map +1 -1
  204. package/dist/cjs/utils/helpers/isTarget.cjs.map +1 -1
  205. package/dist/cjs/utils/helpers/throttle.cjs.map +1 -1
  206. package/dist/esm/helpers/createContext/createContext.mjs.map +1 -1
  207. package/dist/esm/helpers/createReactiveContext/createReactiveContext.mjs.map +1 -1
  208. package/dist/esm/helpers/createStore/createStore.mjs.map +1 -1
  209. package/dist/esm/hooks/useActiveElement/useActiveElement.mjs +1 -1
  210. package/dist/esm/hooks/useActiveElement/useActiveElement.mjs.map +1 -1
  211. package/dist/esm/hooks/useAsync/useAsync.mjs.map +1 -1
  212. package/dist/esm/hooks/useBattery/useBattery.mjs +10 -10
  213. package/dist/esm/hooks/useBattery/useBattery.mjs.map +1 -1
  214. package/dist/esm/hooks/useBluetooth/useBluetooth.mjs +14 -15
  215. package/dist/esm/hooks/useBluetooth/useBluetooth.mjs.map +1 -1
  216. package/dist/esm/hooks/useBoolean/useBoolean.mjs.map +1 -1
  217. package/dist/esm/hooks/useBreakpoints/useBreakpoints.mjs.map +1 -1
  218. package/dist/esm/hooks/useBrowserLanguage/useBrowserLanguage.mjs.map +1 -1
  219. package/dist/esm/hooks/useClickOutside/useClickOutside.mjs.map +1 -1
  220. package/dist/esm/hooks/useClipboard/useClipboard.mjs +13 -14
  221. package/dist/esm/hooks/useClipboard/useClipboard.mjs.map +1 -1
  222. package/dist/esm/hooks/useConst/useConst.mjs.map +1 -1
  223. package/dist/esm/hooks/useCookie/useCookie.mjs +27 -27
  224. package/dist/esm/hooks/useCookie/useCookie.mjs.map +1 -1
  225. package/dist/esm/hooks/useCookies/useCookies.mjs +19 -19
  226. package/dist/esm/hooks/useCookies/useCookies.mjs.map +1 -1
  227. package/dist/esm/hooks/useCopy/useCopy.mjs.map +1 -1
  228. package/dist/esm/hooks/useCounter/useCounter.mjs +5 -6
  229. package/dist/esm/hooks/useCounter/useCounter.mjs.map +1 -1
  230. package/dist/esm/hooks/useCssVar/useCssVar.mjs +13 -14
  231. package/dist/esm/hooks/useCssVar/useCssVar.mjs.map +1 -1
  232. package/dist/esm/hooks/useDebounceCallback/useDebounceCallback.mjs.map +1 -1
  233. package/dist/esm/hooks/useDebounceValue/useDebounceValue.mjs.map +1 -1
  234. package/dist/esm/hooks/useDefault/useDefault.mjs.map +1 -1
  235. package/dist/esm/hooks/useDeviceMotion/useDeviceMotion.mjs +18 -19
  236. package/dist/esm/hooks/useDeviceMotion/useDeviceMotion.mjs.map +1 -1
  237. package/dist/esm/hooks/useDeviceOrientation/useDeviceOrientation.mjs.map +1 -1
  238. package/dist/esm/hooks/useDevicePixelRatio/useDevicePixelRatio.mjs.map +1 -1
  239. package/dist/esm/hooks/useDidUpdate/useDidUpdate.mjs.map +1 -1
  240. package/dist/esm/hooks/useDisclosure/useDisclosure.mjs +5 -11
  241. package/dist/esm/hooks/useDisclosure/useDisclosure.mjs.map +1 -1
  242. package/dist/esm/hooks/useDisplayMedia/useDisplayMedia.mjs +28 -28
  243. package/dist/esm/hooks/useDisplayMedia/useDisplayMedia.mjs.map +1 -1
  244. package/dist/esm/hooks/useDocumentEvent/useDocumentEvent.mjs.map +1 -1
  245. package/dist/esm/hooks/useDocumentTitle/useDocumentTitle.mjs +15 -15
  246. package/dist/esm/hooks/useDocumentTitle/useDocumentTitle.mjs.map +1 -1
  247. package/dist/esm/hooks/useDocumentVisibility/useDocumentVisibility.mjs.map +1 -1
  248. package/dist/esm/hooks/useDoubleClick/useDoubleClick.mjs +11 -13
  249. package/dist/esm/hooks/useDoubleClick/useDoubleClick.mjs.map +1 -1
  250. package/dist/esm/hooks/useDropZone/useDropZone.mjs +27 -28
  251. package/dist/esm/hooks/useDropZone/useDropZone.mjs.map +1 -1
  252. package/dist/esm/hooks/useElementSize/useElementSize.mjs.map +1 -1
  253. package/dist/esm/hooks/useEvent/useEvent.mjs.map +1 -1
  254. package/dist/esm/hooks/useEventListener/useEventListener.mjs.map +1 -1
  255. package/dist/esm/hooks/useEventSource/useEventSource.mjs +37 -40
  256. package/dist/esm/hooks/useEventSource/useEventSource.mjs.map +1 -1
  257. package/dist/esm/hooks/useEyeDropper/useEyeDropper.mjs.map +1 -1
  258. package/dist/esm/hooks/useFavicon/useFavicon.mjs +11 -12
  259. package/dist/esm/hooks/useFavicon/useFavicon.mjs.map +1 -1
  260. package/dist/esm/hooks/useField/useField.mjs +45 -49
  261. package/dist/esm/hooks/useField/useField.mjs.map +1 -1
  262. package/dist/esm/hooks/useFileDialog/useFileDialog.mjs +22 -25
  263. package/dist/esm/hooks/useFileDialog/useFileDialog.mjs.map +1 -1
  264. package/dist/esm/hooks/useFocus/useFocus.mjs +24 -32
  265. package/dist/esm/hooks/useFocus/useFocus.mjs.map +1 -1
  266. package/dist/esm/hooks/useFps/useFps.mjs.map +1 -1
  267. package/dist/esm/hooks/useFul/useFul.mjs.map +1 -1
  268. package/dist/esm/hooks/useFullscreen/useFullscreen.mjs +23 -24
  269. package/dist/esm/hooks/useFullscreen/useFullscreen.mjs.map +1 -1
  270. package/dist/esm/hooks/useGamepad/useGamepad.mjs.map +1 -1
  271. package/dist/esm/hooks/useGeolocation/useGeolocation.mjs +24 -24
  272. package/dist/esm/hooks/useGeolocation/useGeolocation.mjs.map +1 -1
  273. package/dist/esm/hooks/useHash/useHash.mjs.map +1 -1
  274. package/dist/esm/hooks/useHotkeys/useHotkeys.mjs +24 -25
  275. package/dist/esm/hooks/useHotkeys/useHotkeys.mjs.map +1 -1
  276. package/dist/esm/hooks/useHover/useHover.mjs +20 -22
  277. package/dist/esm/hooks/useHover/useHover.mjs.map +1 -1
  278. package/dist/esm/hooks/useIdle/useIdle.mjs.map +1 -1
  279. package/dist/esm/hooks/useImage/useImage.mjs.map +1 -1
  280. package/dist/esm/hooks/useInfiniteScroll/useInfiniteScroll.mjs +14 -14
  281. package/dist/esm/hooks/useInfiniteScroll/useInfiniteScroll.mjs.map +1 -1
  282. package/dist/esm/hooks/useIntersectionObserver/useIntersectionObserver.mjs +19 -20
  283. package/dist/esm/hooks/useIntersectionObserver/useIntersectionObserver.mjs.map +1 -1
  284. package/dist/esm/hooks/useInterval/useInterval.mjs +8 -8
  285. package/dist/esm/hooks/useInterval/useInterval.mjs.map +1 -1
  286. package/dist/esm/hooks/useIsFirstRender/useIsFirstRender.mjs.map +1 -1
  287. package/dist/esm/hooks/useKeyPress/useKeyPress.mjs +22 -24
  288. package/dist/esm/hooks/useKeyPress/useKeyPress.mjs.map +1 -1
  289. package/dist/esm/hooks/useKeyPressEvent/useKeyPressEvent.mjs +23 -23
  290. package/dist/esm/hooks/useKeyPressEvent/useKeyPressEvent.mjs.map +1 -1
  291. package/dist/esm/hooks/useKeyboard/useKeyboard.mjs +16 -22
  292. package/dist/esm/hooks/useKeyboard/useKeyboard.mjs.map +1 -1
  293. package/dist/esm/hooks/useKeysPressed/useKeysPressed.mjs +20 -20
  294. package/dist/esm/hooks/useKeysPressed/useKeysPressed.mjs.map +1 -1
  295. package/dist/esm/hooks/useLastChanged/useLastChanged.mjs +6 -6
  296. package/dist/esm/hooks/useLastChanged/useLastChanged.mjs.map +1 -1
  297. package/dist/esm/hooks/useLatest/useLatest.mjs +12 -4
  298. package/dist/esm/hooks/useLatest/useLatest.mjs.map +1 -1
  299. package/dist/esm/hooks/useLess/useLess.mjs.map +1 -1
  300. package/dist/esm/hooks/useList/useList.mjs.map +1 -1
  301. package/dist/esm/hooks/useLockCallback/useLockCallback.mjs.map +1 -1
  302. package/dist/esm/hooks/useLogger/useLogger.mjs.map +1 -1
  303. package/dist/esm/hooks/useLongPress/useLongPress.mjs +23 -27
  304. package/dist/esm/hooks/useLongPress/useLongPress.mjs.map +1 -1
  305. package/dist/esm/hooks/useMap/useMap.mjs.map +1 -1
  306. package/dist/esm/hooks/useMeasure/useMeasure.mjs.map +1 -1
  307. package/dist/esm/hooks/useMediaQuery/useMediaQuery.mjs.map +1 -1
  308. package/dist/esm/hooks/useMemory/useMemory.mjs +1 -1
  309. package/dist/esm/hooks/useMemory/useMemory.mjs.map +1 -1
  310. package/dist/esm/hooks/useMount/useMount.mjs.map +1 -1
  311. package/dist/esm/hooks/useMouse/useMouse.mjs.map +1 -1
  312. package/dist/esm/hooks/useMutation/useMutation.mjs +38 -42
  313. package/dist/esm/hooks/useMutation/useMutation.mjs.map +1 -1
  314. package/dist/esm/hooks/useMutationObserver/useMutationObserver.mjs +12 -12
  315. package/dist/esm/hooks/useMutationObserver/useMutationObserver.mjs.map +1 -1
  316. package/dist/esm/hooks/useNetwork/useNetwork.mjs +28 -28
  317. package/dist/esm/hooks/useNetwork/useNetwork.mjs.map +1 -1
  318. package/dist/esm/hooks/useOffsetPagination/useOffsetPagination.mjs.map +1 -1
  319. package/dist/esm/hooks/useOnce/useOnce.mjs.map +1 -1
  320. package/dist/esm/hooks/useOnline/useOnline.mjs.map +1 -1
  321. package/dist/esm/hooks/useOperatingSystem/useOperatingSystem.mjs.map +1 -1
  322. package/dist/esm/hooks/useOptimistic/useOptimistic.mjs.map +1 -1
  323. package/dist/esm/hooks/useOrientation/useOrientation.mjs.map +1 -1
  324. package/dist/esm/hooks/useOtpCredential/useOtpCredential.mjs +12 -13
  325. package/dist/esm/hooks/useOtpCredential/useOtpCredential.mjs.map +1 -1
  326. package/dist/esm/hooks/usePageLeave/usePageLeave.mjs +6 -6
  327. package/dist/esm/hooks/usePageLeave/usePageLeave.mjs.map +1 -1
  328. package/dist/esm/hooks/usePaint/usePaint.mjs +87 -93
  329. package/dist/esm/hooks/usePaint/usePaint.mjs.map +1 -1
  330. package/dist/esm/hooks/useParallax/useParallax.mjs.map +1 -1
  331. package/dist/esm/hooks/usePerformanceObserver/usePerformanceObserver.mjs +17 -19
  332. package/dist/esm/hooks/usePerformanceObserver/usePerformanceObserver.mjs.map +1 -1
  333. package/dist/esm/hooks/usePermission/usePermission.mjs +13 -13
  334. package/dist/esm/hooks/usePermission/usePermission.mjs.map +1 -1
  335. package/dist/esm/hooks/usePointerLock/usePointerLock.mjs.map +1 -1
  336. package/dist/esm/hooks/usePostMessage/usePostMessage.mjs.map +1 -1
  337. package/dist/esm/hooks/usePreferredColorScheme/usePreferredColorScheme.mjs.map +1 -1
  338. package/dist/esm/hooks/usePreferredContrast/usePreferredContrast.mjs.map +1 -1
  339. package/dist/esm/hooks/usePreferredDark/usePreferredDark.mjs.map +1 -1
  340. package/dist/esm/hooks/usePreferredLanguages/usePreferredLanguages.mjs.map +1 -1
  341. package/dist/esm/hooks/usePrevious/usePrevious.mjs +4 -4
  342. package/dist/esm/hooks/usePrevious/usePrevious.mjs.map +1 -1
  343. package/dist/esm/hooks/useQuery/useQuery.mjs +39 -41
  344. package/dist/esm/hooks/useQuery/useQuery.mjs.map +1 -1
  345. package/dist/esm/hooks/useQueue/useQueue.mjs.map +1 -1
  346. package/dist/esm/hooks/useRaf/useRaf.mjs +21 -21
  347. package/dist/esm/hooks/useRaf/useRaf.mjs.map +1 -1
  348. package/dist/esm/hooks/useRafValue/useRafValue.mjs.map +1 -1
  349. package/dist/esm/hooks/useRefState/useRefState.mjs.map +1 -1
  350. package/dist/esm/hooks/useRenderCount/useRenderCount.mjs.map +1 -1
  351. package/dist/esm/hooks/useRenderInfo/useRenderInfo.mjs.map +1 -1
  352. package/dist/esm/hooks/useRerender/useRerender.mjs.map +1 -1
  353. package/dist/esm/hooks/useResizeObserver/useResizeObserver.mjs +16 -17
  354. package/dist/esm/hooks/useResizeObserver/useResizeObserver.mjs.map +1 -1
  355. package/dist/esm/hooks/useScreenOrientation/useScreenOrientation.mjs +11 -11
  356. package/dist/esm/hooks/useScreenOrientation/useScreenOrientation.mjs.map +1 -1
  357. package/dist/esm/hooks/useScript/useScript.mjs +16 -16
  358. package/dist/esm/hooks/useScript/useScript.mjs.map +1 -1
  359. package/dist/esm/hooks/useScroll/useScroll.mjs +37 -39
  360. package/dist/esm/hooks/useScroll/useScroll.mjs.map +1 -1
  361. package/dist/esm/hooks/useScrollIntoView/useScrollIntoView.mjs.map +1 -1
  362. package/dist/esm/hooks/useScrollTo/useScrollTo.mjs.map +1 -1
  363. package/dist/esm/hooks/useSet/useSet.mjs.map +1 -1
  364. package/dist/esm/hooks/useShare/useShare.mjs.map +1 -1
  365. package/dist/esm/hooks/useSpeechRecognition/useSpeechRecognition.mjs +35 -35
  366. package/dist/esm/hooks/useSpeechRecognition/useSpeechRecognition.mjs.map +1 -1
  367. package/dist/esm/hooks/useSpeechSynthesis/useSpeechSynthesis.mjs +36 -42
  368. package/dist/esm/hooks/useSpeechSynthesis/useSpeechSynthesis.mjs.map +1 -1
  369. package/dist/esm/hooks/useStateHistory/useStateHistory.mjs.map +1 -1
  370. package/dist/esm/hooks/useStep/useStep.mjs.map +1 -1
  371. package/dist/esm/hooks/useSticky/useSticky.mjs +12 -12
  372. package/dist/esm/hooks/useSticky/useSticky.mjs.map +1 -1
  373. package/dist/esm/hooks/useStopwatch/useStopwatch.mjs +10 -11
  374. package/dist/esm/hooks/useStopwatch/useStopwatch.mjs.map +1 -1
  375. package/dist/esm/hooks/useStorage/useStorage.mjs +27 -27
  376. package/dist/esm/hooks/useStorage/useStorage.mjs.map +1 -1
  377. package/dist/esm/hooks/useTextDirection/useTextDirection.mjs +21 -24
  378. package/dist/esm/hooks/useTextDirection/useTextDirection.mjs.map +1 -1
  379. package/dist/esm/hooks/useTextSelection/useTextSelection.mjs +7 -7
  380. package/dist/esm/hooks/useTextSelection/useTextSelection.mjs.map +1 -1
  381. package/dist/esm/hooks/useThrottleCallback/useThrottleCallback.mjs.map +1 -1
  382. package/dist/esm/hooks/useThrottleValue/useThrottleValue.mjs.map +1 -1
  383. package/dist/esm/hooks/useTime/useTime.mjs.map +1 -1
  384. package/dist/esm/hooks/useTimeout/useTimeout.mjs.map +1 -1
  385. package/dist/esm/hooks/useTimer/useTimer.mjs +51 -54
  386. package/dist/esm/hooks/useTimer/useTimer.mjs.map +1 -1
  387. package/dist/esm/hooks/useToggle/useToggle.mjs.map +1 -1
  388. package/dist/esm/hooks/useUnmount/useUnmount.mjs.map +1 -1
  389. package/dist/esm/hooks/useUrlSearchParam/useUrlSearchParam.mjs +38 -38
  390. package/dist/esm/hooks/useUrlSearchParam/useUrlSearchParam.mjs.map +1 -1
  391. package/dist/esm/hooks/useUrlSearchParams/useUrlSearchParams.mjs +29 -29
  392. package/dist/esm/hooks/useUrlSearchParams/useUrlSearchParams.mjs.map +1 -1
  393. package/dist/esm/hooks/useVibrate/useVibrate.mjs.map +1 -1
  394. package/dist/esm/hooks/useWakeLock/useWakeLock.mjs +16 -16
  395. package/dist/esm/hooks/useWakeLock/useWakeLock.mjs.map +1 -1
  396. package/dist/esm/hooks/useWebSocket/useWebSocket.mjs +28 -38
  397. package/dist/esm/hooks/useWebSocket/useWebSocket.mjs.map +1 -1
  398. package/dist/esm/hooks/useWindowEvent/useWindowEvent.mjs.map +1 -1
  399. package/dist/esm/hooks/useWindowFocus/useWindowFocus.mjs.map +1 -1
  400. package/dist/esm/hooks/useWindowScroll/useWindowScroll.mjs.map +1 -1
  401. package/dist/esm/hooks/useWindowSize/useWindowSize.mjs +9 -9
  402. package/dist/esm/hooks/useWindowSize/useWindowSize.mjs.map +1 -1
  403. package/dist/esm/hooks/useWizard/useWizard.mjs +9 -11
  404. package/dist/esm/hooks/useWizard/useWizard.mjs.map +1 -1
  405. package/dist/esm/utils/helpers/copy.mjs.map +1 -1
  406. package/dist/esm/utils/helpers/debounce.mjs.map +1 -1
  407. package/dist/esm/utils/helpers/getDate.mjs.map +1 -1
  408. package/dist/esm/utils/helpers/getElement.mjs.map +1 -1
  409. package/dist/esm/utils/helpers/getRetry.mjs.map +1 -1
  410. package/dist/esm/utils/helpers/isTarget.mjs.map +1 -1
  411. package/dist/esm/utils/helpers/throttle.mjs.map +1 -1
  412. package/dist/types/hooks/useLatest/useLatest.d.ts +7 -2
  413. package/package.json +5 -5
package/README.md CHANGED
@@ -1,71 +1,71 @@
1
- <div align="center">
2
- <a href="https://reactuse.dev">
3
- <picture>
4
- <img alt="React Use logo" src="https://siberiacancode.github.io/reactuse/logo.svg" height="128">
5
- </picture>
6
- </a>
7
- <h1>React Use</h1>
8
-
9
- <a href="https://www.npmjs.com/package/@siberiacancode/reactuse"><img alt="NPM version" src="https://img.shields.io/npm/v/@siberiacancode/reactuse.svg?style=for-the-badge&labelColor=000000"></a>
10
- <a href="https://github.com/siberiacancode/reactuse/blob/main/LICENSE"><img alt="License" src="https://img.shields.io/npm/l/@siberiacancode/reactuse.svg?style=for-the-badge&labelColor=000000"></a>
11
- <a href="https://github.com/siberiacancode/reactuse/discussions"><img alt="Join the community on GitHub" src="https://img.shields.io/badge/Join%20the%20community-blueviolet.svg?style=for-the-badge&logo=React&labelColor=000000&logoWidth=20"></a>
12
-
13
- </div>
14
-
15
- React Use delivers **production-ready hooks** that solve real-world problems. Built with **TypeScript-first** approach, **SSR compatibility**, and **tree-shaking optimization** - everything you need to build modern React applications. Improve your react applications with our library 📦 designed for comfort and speed.
16
-
17
- ## Documentation
18
-
19
- Visit https://siberiacancode.github.io/reactuse to view the full documentation.
20
-
21
- ## Getting Started
22
-
23
- ```bash
24
- npm install @siberiacancode/reactuse
25
- ```
26
-
27
- ```tsx
28
- import { useCounter } from '@reactuses/core';
29
-
30
- function App() {
31
- const counter = useCounter(0);
32
-
33
- return (
34
- <div>
35
- <h1>Count: {const.value}</h1>
36
- <button onClick={() => const.inc()}>+1</button>
37
- <button onClick={() => const.dec()}>-1</button>
38
- </div>
39
- );
40
- }
41
- ```
42
-
43
- ## CLI installation
44
-
45
- Use the CLI to add hooks to your project with [useverse](https://www.npmjs.com/package/useverse).
46
-
47
- ```bash
48
- npx useverse@latest init
49
- ```
50
-
51
- ```bash
52
- npx useverse@latest add [hook]
53
- ```
54
-
55
- You will be presented with a list of hooks to choose from:
56
-
57
- ```bash
58
- Which hooks would you like to add? › Space to select. A to toggle all.
59
- Enter to submit.
60
-
61
- ◯ useActiveElement
62
- ◯ useAsync
63
- ◯ useBattery
64
- ◯ useBluetooth
65
- ◯ useBoolean
66
- ◯ useBreakpoints
67
- ◯ useBrowserLanguage
68
- ◯ useClickOutside
69
- ◯ useClipboard
70
- ◯ useConst
71
- ```
1
+ <div align="center">
2
+ <a href="https://reactuse.dev">
3
+ <picture>
4
+ <img alt="React Use logo" src="https://siberiacancode.github.io/reactuse/logo.svg" height="128">
5
+ </picture>
6
+ </a>
7
+ <h1>React Use</h1>
8
+
9
+ <a href="https://www.npmjs.com/package/@siberiacancode/reactuse"><img alt="NPM version" src="https://img.shields.io/npm/v/@siberiacancode/reactuse.svg?style=for-the-badge&labelColor=000000"></a>
10
+ <a href="https://github.com/siberiacancode/reactuse/blob/main/LICENSE"><img alt="License" src="https://img.shields.io/npm/l/@siberiacancode/reactuse.svg?style=for-the-badge&labelColor=000000"></a>
11
+ <a href="https://github.com/siberiacancode/reactuse/discussions"><img alt="Join the community on GitHub" src="https://img.shields.io/badge/Join%20the%20community-blueviolet.svg?style=for-the-badge&logo=React&labelColor=000000&logoWidth=20"></a>
12
+
13
+ </div>
14
+
15
+ React Use delivers **production-ready hooks** that solve real-world problems. Built with **TypeScript-first** approach, **SSR compatibility**, and **tree-shaking optimization** - everything you need to build modern React applications. Improve your react applications with our library 📦 designed for comfort and speed.
16
+
17
+ ## Documentation
18
+
19
+ Visit https://siberiacancode.github.io/reactuse to view the full documentation.
20
+
21
+ ## Getting Started
22
+
23
+ ```bash
24
+ npm install @siberiacancode/reactuse
25
+ ```
26
+
27
+ ```tsx
28
+ import { useCounter } from '@siberiacancode/reactuse';
29
+
30
+ function App() {
31
+ const counter = useCounter(0);
32
+
33
+ return (
34
+ <div>
35
+ <h1>Count: {const.value}</h1>
36
+ <button onClick={() => const.inc()}>+1</button>
37
+ <button onClick={() => const.dec()}>-1</button>
38
+ </div>
39
+ );
40
+ }
41
+ ```
42
+
43
+ ## CLI installation
44
+
45
+ Use the CLI to add hooks to your project with [useverse](https://www.npmjs.com/package/useverse).
46
+
47
+ ```bash
48
+ npx useverse@latest init
49
+ ```
50
+
51
+ ```bash
52
+ npx useverse@latest add [hook]
53
+ ```
54
+
55
+ You will be presented with a list of hooks to choose from:
56
+
57
+ ```bash
58
+ Which hooks would you like to add? › Space to select. A to toggle all.
59
+ Enter to submit.
60
+
61
+ ◯ useActiveElement
62
+ ◯ useAsync
63
+ ◯ useBattery
64
+ ◯ useBluetooth
65
+ ◯ useBoolean
66
+ ◯ useBreakpoints
67
+ ◯ useBrowserLanguage
68
+ ◯ useClickOutside
69
+ ◯ useClipboard
70
+ ◯ useConst
71
+ ```
@@ -1 +1 @@
1
- {"version":3,"file":"createContext.cjs","sources":["../../../../src/helpers/createContext/createContext.tsx"],"sourcesContent":["import type { JSX, ReactNode } from 'react';\n\nimport { createContext as createReactContext, useContext, useMemo, useState } from 'react';\n\n/** The create context options type */\nexport interface CreateContextOptions {\n /** Display name for the context (useful for debugging) */\n name?: string;\n /** Whether to throw an error if context is used outside of Provider */\n strict?: boolean;\n}\n\n/** The context value type */\nexport interface ContextValue<Value> {\n /** The context value */\n value: Value | undefined;\n /** The context set function */\n set: (value: Value) => void;\n}\n\n/** The provider props type */\nexport interface ProviderProps<Value> {\n /** The children */\n children?: ReactNode;\n /** The initial value */\n initialValue?: Value;\n}\n\n/** The create context return type */\nexport interface CreateContextReturn<Value> {\n /** The context instance */\n instance: React.Context<ContextValue<Value>>;\n /** The provider component */\n Provider: (props: ProviderProps<Value>) => JSX.Element;\n /** The selector hook */\n useSelect: {\n <Selected>(selector: (value: Value) => Selected): Selected;\n (): ContextValue<Value>;\n };\n}\n\n/**\n * @name createContext\n * @description - Creates a typed context with additional utilities\n * @category Helpers\n *\n * @template Value - The type of value that will be stored in the context\n * @param {Value | undefined} [defaultValue] - Default value for the context\n * @param {CreateContextOptions<Value>} [options] - Additional options for context creation\n * @returns {CreateContextReturn<Value>} Object containing context utilities and components\n *\n * @example\n * const { useSelect, instance, Provider } = createContext<number>(0);\n */\nexport const createContext = <Value,>(\n defaultValue: Value | undefined = undefined,\n options: CreateContextOptions = {}\n): CreateContextReturn<Value> => {\n const Context = createReactContext<{\n value: Value | undefined;\n set: (value: Value) => void;\n }>({\n value: defaultValue,\n set: () => {}\n });\n\n Context.displayName = options.name;\n\n function useSelect(): ContextValue<Value>;\n function useSelect<Selected>(selector: (value: Value) => Selected): Selected;\n function useSelect<Selected>(selector?: (value: Value) => Selected) {\n const context = useContext(Context);\n\n if (!context && options.strict) {\n throw new Error(`Context hook ${options.name} must be used inside a Provider`);\n }\n\n if (!selector) {\n return context;\n }\n\n return selector(context.value as Value);\n }\n\n const Provider = ({ children, initialValue }: ProviderProps<Value>) => {\n const [profile, setProfile] = useState<Value | undefined>(initialValue ?? defaultValue);\n\n const value = useMemo(\n () => ({\n value: profile,\n set: setProfile\n }),\n [profile]\n );\n\n return <Context value={value}>{children}</Context>;\n };\n\n return {\n useSelect,\n instance: Context,\n Provider\n } as const;\n};\n"],"names":["createContext","defaultValue","options","Context","createReactContext","useSelect","selector","context","useContext","children","initialValue","profile","setProfile","useState","value","useMemo","jsx"],"mappings":"wIAsDaA,EAAgB,CAC3BC,EAAkC,OAClCC,EAAgC,CAAA,IACD,CAC/B,MAAMC,EAAUC,EAAAA,cAGb,CACD,MAAOH,EACP,IAAK,IAAM,CAAA,CAAC,CACb,EAEDE,EAAQ,YAAcD,EAAQ,KAI9B,SAASG,EAAoBC,EAAuC,CAC5D,MAAAC,EAAUC,aAAWL,CAAO,EAE9B,GAAA,CAACI,GAAWL,EAAQ,OACtB,MAAM,IAAI,MAAM,gBAAgBA,EAAQ,IAAI,iCAAiC,EAG/E,OAAKI,EAIEA,EAASC,EAAQ,KAAc,EAH7BA,CAG6B,CAiBjC,MAAA,CACL,UAAAF,EACA,SAAUF,EACV,SAjBe,CAAC,CAAE,SAAAM,EAAU,aAAAC,KAAyC,CACrE,KAAM,CAACC,EAASC,CAAU,EAAIC,EAAAA,SAA4BH,GAAgBT,CAAY,EAEhFa,EAAQC,EAAA,QACZ,KAAO,CACL,MAAOJ,EACP,IAAKC,CAAA,GAEP,CAACD,CAAO,CACV,EAEO,OAAAK,EAAA,IAACb,EAAQ,CAAA,MAAAW,EAAe,SAAAL,CAAS,CAAA,CAC1C,CAMA,CACF"}
1
+ {"version":3,"file":"createContext.cjs","sources":["../../../../src/helpers/createContext/createContext.tsx"],"sourcesContent":["import type { JSX, ReactNode } from 'react';\n\nimport { createContext as createReactContext, useContext, useMemo, useState } from 'react';\n\n/** The create context options type */\nexport interface CreateContextOptions {\n /** Display name for the context (useful for debugging) */\n name?: string;\n /** Whether to throw an error if context is used outside of Provider */\n strict?: boolean;\n}\n\n/** The context value type */\nexport interface ContextValue<Value> {\n /** The context value */\n value: Value | undefined;\n /** The context set function */\n set: (value: Value) => void;\n}\n\n/** The provider props type */\nexport interface ProviderProps<Value> {\n /** The children */\n children?: ReactNode;\n /** The initial value */\n initialValue?: Value;\n}\n\n/** The create context return type */\nexport interface CreateContextReturn<Value> {\n /** The context instance */\n instance: React.Context<ContextValue<Value>>;\n /** The provider component */\n Provider: (props: ProviderProps<Value>) => JSX.Element;\n /** The selector hook */\n useSelect: {\n <Selected>(selector: (value: Value) => Selected): Selected;\n (): ContextValue<Value>;\n };\n}\n\n/**\n * @name createContext\n * @description - Creates a typed context with additional utilities\n * @category Helpers\n *\n * @template Value - The type of value that will be stored in the context\n * @param {Value | undefined} [defaultValue] - Default value for the context\n * @param {CreateContextOptions<Value>} [options] - Additional options for context creation\n * @returns {CreateContextReturn<Value>} Object containing context utilities and components\n *\n * @example\n * const { useSelect, instance, Provider } = createContext<number>(0);\n */\nexport const createContext = <Value,>(\n defaultValue: Value | undefined = undefined,\n options: CreateContextOptions = {}\n): CreateContextReturn<Value> => {\n const Context = createReactContext<{\n value: Value | undefined;\n set: (value: Value) => void;\n }>({\n value: defaultValue,\n set: () => {}\n });\n\n Context.displayName = options.name;\n\n function useSelect(): ContextValue<Value>;\n function useSelect<Selected>(selector: (value: Value) => Selected): Selected;\n function useSelect<Selected>(selector?: (value: Value) => Selected) {\n const context = useContext(Context);\n\n if (!context && options.strict) {\n throw new Error(`Context hook ${options.name} must be used inside a Provider`);\n }\n\n if (!selector) {\n return context;\n }\n\n return selector(context.value as Value);\n }\n\n const Provider = ({ children, initialValue }: ProviderProps<Value>) => {\n const [profile, setProfile] = useState<Value | undefined>(initialValue ?? defaultValue);\n\n const value = useMemo(\n () => ({\n value: profile,\n set: setProfile\n }),\n [profile]\n );\n\n return <Context value={value}>{children}</Context>;\n };\n\n return {\n useSelect,\n instance: Context,\n Provider\n } as const;\n};\n"],"names":["createContext","defaultValue","options","Context","createReactContext","useSelect","selector","context","useContext","children","initialValue","profile","setProfile","useState","value","useMemo","jsx"],"mappings":"wIAsDaA,EAAgB,CAC3BC,EAAkC,OAClCC,EAAgC,CAAA,IACD,CAC/B,MAAMC,EAAUC,EAAAA,cAGb,CACD,MAAOH,EACP,IAAK,IAAM,CAAA,CAAC,CACb,EAEDE,EAAQ,YAAcD,EAAQ,KAI9B,SAASG,EAAoBC,EAAuC,CAClE,MAAMC,EAAUC,EAAAA,WAAWL,CAAO,EAElC,GAAI,CAACI,GAAWL,EAAQ,OACtB,MAAM,IAAI,MAAM,gBAAgBA,EAAQ,IAAI,iCAAiC,EAG/E,OAAKI,EAIEA,EAASC,EAAQ,KAAc,EAH7BA,CAG6B,CAiBxC,MAAO,CACL,UAAAF,EACA,SAAUF,EACV,SAjBe,CAAC,CAAE,SAAAM,EAAU,aAAAC,KAAyC,CACrE,KAAM,CAACC,EAASC,CAAU,EAAIC,EAAAA,SAA4BH,GAAgBT,CAAY,EAEhFa,EAAQC,EAAAA,QACZ,KAAO,CACL,MAAOJ,EACP,IAAKC,CAAA,GAEP,CAACD,CAAO,CAAA,EAGV,OAAOK,EAAAA,IAACb,EAAA,CAAQ,MAAAW,EAAe,SAAAL,CAAA,CAAS,CAAA,CAMxC,CAEJ"}
@@ -1 +1 @@
1
- {"version":3,"file":"createReactiveContext.cjs","sources":["../../../../src/helpers/createReactiveContext/createReactiveContext.ts"],"sourcesContent":["import type { Context, FC, Provider, ProviderProps, RefObject } from 'react';\n\nimport {\n createContext,\n createElement,\n startTransition,\n useContext,\n useMemo,\n useRef,\n useState\n} from 'react';\n\nimport { useEvent, useIsomorphicLayoutEffect } from '@/hooks';\n\n/** The create reactive context options type */\nexport interface CreateReactiveContextOptions {\n /** Display name for the context (useful for debugging) */\n name?: string;\n /** Whether to throw an error if context is used outside of Provider */\n strict?: boolean;\n}\n\n/** The create reactive context return type */\nexport interface CreateReactiveContextReturn<Value> {\n /** The context instance */\n instance: Context<ReactiveContextValue<Value>>;\n /** The Provider component for the context */\n Provider: Provider<Value>;\n /** A hook to select a part of the context state */\n useSelector: <Selected>(selector?: (state: Value) => Selected) => Selected;\n}\n\ntype ContextListener<Value> = (value: Value) => void;\n\ninterface ReactiveContextValue<Value> {\n /** The listeners for the context */\n listeners: Set<ContextListener<Value>>;\n /** The value for the context */\n value: RefObject<Value>;\n}\n\nconst createProvider = <Value>(originalProvider: Provider<ReactiveContextValue<Value>>) => {\n const Provider: FC<ProviderProps<Value>> = (props) => {\n const valueRef = useRef(props.value);\n const contextValue = useMemo<ReactiveContextValue<Value>>(\n () => ({\n value: valueRef,\n listeners: new Set()\n }),\n []\n );\n\n useIsomorphicLayoutEffect(() => {\n if (!Object.is(valueRef.current, props.value)) {\n valueRef.current = props.value;\n\n startTransition(() => {\n contextValue.listeners.forEach((listener) => {\n listener(valueRef.current);\n });\n });\n }\n }, [props.value]);\n\n return createElement(originalProvider, { value: contextValue }, props.children);\n };\n\n return Provider as unknown as Provider<ReactiveContextValue<Value>>;\n};\n\nconst createReactiveContextSelector = <Value, Selected>(\n Context: Context<ReactiveContextValue<Value>>,\n selector: (state: Value) => Selected,\n options: CreateReactiveContextOptions = {}\n) => {\n const context = useContext(Context);\n\n if (!context && options.strict) {\n throw new Error(`Context hook ${options.name} must be used inside a Provider`);\n }\n\n const [value, setValue] = useState({\n selected: selector(context.value.current),\n value: context.value.current\n });\n\n const dispatch = useEvent((newValue: Value) => {\n setValue((prevValue) => {\n if (Object.is(prevValue.value, newValue)) return prevValue;\n\n const newSelected = selector(newValue);\n if (Object.is(prevValue.selected, newSelected)) return prevValue;\n\n return { value: newValue, selected: newSelected };\n });\n });\n\n useIsomorphicLayoutEffect(() => {\n context.listeners.add(dispatch);\n return () => {\n context.listeners.delete(dispatch);\n };\n }, [context.listeners]);\n\n return value.selected;\n};\n\n/**\n * @name createReactiveContext\n * @description - Creates a typed context selector with optimized updates for state selection\n * @category Helpers\n *\n * @warning - For complex interfaces, we strongly recommend using state management solutions outside of React like createStore, reatom, effector, or zustand instead of context\n *\n * @template Value - The type of value that will be stored in the context\n * @param {Value | undefined} [defaultValue] - Default value for the context\n * @param {CreateReactiveContextOptions<Value>} [options] - Additional options for context creation\n * @returns {CreateReactiveContextReturn<Value>} Object containing context utilities and components\n *\n * @example\n * const { Provider, useSelector, instance } = createReactiveContext<number>(0);\n */\nexport const createReactiveContext = <Value extends Record<string, any>>(\n defaultValue: Value | undefined = undefined,\n options: CreateReactiveContextOptions = {}\n) => {\n const Context = createContext<ReactiveContextValue<Value>>({\n value: { current: defaultValue as Value },\n listeners: new Set()\n });\n\n const Provider = createProvider(Context.Provider) as unknown as Provider<Value>;\n\n Context.displayName = options.name;\n\n function useSelector(): Value;\n function useSelector<SelectedValue>(selector: (state: Value) => SelectedValue): SelectedValue;\n function useSelector<SelectedValue>(selector?: (state: Value) => SelectedValue) {\n return createReactiveContextSelector(\n Context as unknown as Context<ReactiveContextValue<Value>>,\n selector ?? ((state) => state as unknown as SelectedValue),\n options\n );\n }\n\n return { instance: Context, Provider, useSelector };\n};\n"],"names":["createProvider","originalProvider","props","valueRef","useRef","contextValue","useMemo","useIsomorphicLayoutEffect","startTransition","listener","createElement","createReactiveContextSelector","Context","selector","options","context","useContext","value","setValue","useState","dispatch","useEvent","newValue","prevValue","newSelected","createReactiveContext","defaultValue","createContext","Provider","useSelector","state"],"mappings":"yOAyCMA,EAAyBC,GACeC,GAAU,CAC9C,MAAAC,EAAWC,EAAAA,OAAOF,EAAM,KAAK,EAC7BG,EAAeC,EAAA,QACnB,KAAO,CACL,MAAOH,EACP,cAAe,GAAI,GAErB,CAAA,CACF,EAEAI,OAAAA,EAAAA,0BAA0B,IAAM,CACzB,OAAO,GAAGJ,EAAS,QAASD,EAAM,KAAK,IAC1CC,EAAS,QAAUD,EAAM,MAEzBM,EAAAA,gBAAgB,IAAM,CACPH,EAAA,UAAU,QAASI,GAAa,CAC3CA,EAASN,EAAS,OAAO,CAAA,CAC1B,CAAA,CACF,EACH,EACC,CAACD,EAAM,KAAK,CAAC,EAETQ,EAAAA,cAAcT,EAAkB,CAAE,MAAOI,CAAa,EAAGH,EAAM,QAAQ,CAChF,EAKIS,EAAgC,CACpCC,EACAC,EACAC,EAAwC,CAAA,IACrC,CACG,MAAAC,EAAUC,aAAWJ,CAAO,EAE9B,GAAA,CAACG,GAAWD,EAAQ,OACtB,MAAM,IAAI,MAAM,gBAAgBA,EAAQ,IAAI,iCAAiC,EAG/E,KAAM,CAACG,EAAOC,CAAQ,EAAIC,WAAS,CACjC,SAAUN,EAASE,EAAQ,MAAM,OAAO,EACxC,MAAOA,EAAQ,MAAM,OAAA,CACtB,EAEKK,EAAWC,WAAUC,GAAoB,CAC7CJ,EAAUK,GAAc,CACtB,GAAI,OAAO,GAAGA,EAAU,MAAOD,CAAQ,EAAU,OAAAC,EAE3C,MAAAC,EAAcX,EAASS,CAAQ,EACrC,OAAI,OAAO,GAAGC,EAAU,SAAUC,CAAW,EAAUD,EAEhD,CAAE,MAAOD,EAAU,SAAUE,CAAY,CAAA,CACjD,CAAA,CACF,EAEDjB,OAAAA,EAAAA,0BAA0B,KAChBQ,EAAA,UAAU,IAAIK,CAAQ,EACvB,IAAM,CACHL,EAAA,UAAU,OAAOK,CAAQ,CACnC,GACC,CAACL,EAAQ,SAAS,CAAC,EAEfE,EAAM,QACf,EAiBaQ,EAAwB,CACnCC,EAAkC,OAClCZ,EAAwC,CAAA,IACrC,CACH,MAAMF,EAAUe,EAAAA,cAA2C,CACzD,MAAO,CAAE,QAASD,CAAsB,EACxC,cAAe,GAAI,CACpB,EAEKE,EAAW5B,EAAeY,EAAQ,QAAQ,EAEhDA,EAAQ,YAAcE,EAAQ,KAI9B,SAASe,EAA2BhB,EAA4C,CACvE,OAAAF,EACLC,EACAC,IAAciB,GAAUA,GACxBhB,CACF,CAAA,CAGF,MAAO,CAAE,SAAUF,EAAS,SAAAgB,EAAU,YAAAC,CAAY,CACpD"}
1
+ {"version":3,"file":"createReactiveContext.cjs","sources":["../../../../src/helpers/createReactiveContext/createReactiveContext.ts"],"sourcesContent":["import type { Context, FC, Provider, ProviderProps, RefObject } from 'react';\n\nimport {\n createContext,\n createElement,\n startTransition,\n useContext,\n useMemo,\n useRef,\n useState\n} from 'react';\n\nimport { useEvent, useIsomorphicLayoutEffect } from '@/hooks';\n\n/** The create reactive context options type */\nexport interface CreateReactiveContextOptions {\n /** Display name for the context (useful for debugging) */\n name?: string;\n /** Whether to throw an error if context is used outside of Provider */\n strict?: boolean;\n}\n\n/** The create reactive context return type */\nexport interface CreateReactiveContextReturn<Value> {\n /** The context instance */\n instance: Context<ReactiveContextValue<Value>>;\n /** The Provider component for the context */\n Provider: Provider<Value>;\n /** A hook to select a part of the context state */\n useSelector: <Selected>(selector?: (state: Value) => Selected) => Selected;\n}\n\ntype ContextListener<Value> = (value: Value) => void;\n\ninterface ReactiveContextValue<Value> {\n /** The listeners for the context */\n listeners: Set<ContextListener<Value>>;\n /** The value for the context */\n value: RefObject<Value>;\n}\n\nconst createProvider = <Value>(originalProvider: Provider<ReactiveContextValue<Value>>) => {\n const Provider: FC<ProviderProps<Value>> = (props) => {\n const valueRef = useRef(props.value);\n const contextValue = useMemo<ReactiveContextValue<Value>>(\n () => ({\n value: valueRef,\n listeners: new Set()\n }),\n []\n );\n\n useIsomorphicLayoutEffect(() => {\n if (!Object.is(valueRef.current, props.value)) {\n valueRef.current = props.value;\n\n startTransition(() => {\n contextValue.listeners.forEach((listener) => {\n listener(valueRef.current);\n });\n });\n }\n }, [props.value]);\n\n return createElement(originalProvider, { value: contextValue }, props.children);\n };\n\n return Provider as unknown as Provider<ReactiveContextValue<Value>>;\n};\n\nconst createReactiveContextSelector = <Value, Selected>(\n Context: Context<ReactiveContextValue<Value>>,\n selector: (state: Value) => Selected,\n options: CreateReactiveContextOptions = {}\n) => {\n const context = useContext(Context);\n\n if (!context && options.strict) {\n throw new Error(`Context hook ${options.name} must be used inside a Provider`);\n }\n\n const [value, setValue] = useState({\n selected: selector(context.value.current),\n value: context.value.current\n });\n\n const dispatch = useEvent((newValue: Value) => {\n setValue((prevValue) => {\n if (Object.is(prevValue.value, newValue)) return prevValue;\n\n const newSelected = selector(newValue);\n if (Object.is(prevValue.selected, newSelected)) return prevValue;\n\n return { value: newValue, selected: newSelected };\n });\n });\n\n useIsomorphicLayoutEffect(() => {\n context.listeners.add(dispatch);\n return () => {\n context.listeners.delete(dispatch);\n };\n }, [context.listeners]);\n\n return value.selected;\n};\n\n/**\n * @name createReactiveContext\n * @description - Creates a typed context selector with optimized updates for state selection\n * @category Helpers\n *\n * @warning - For complex interfaces, we strongly recommend using state management solutions outside of React like createStore, reatom, effector, or zustand instead of context\n *\n * @template Value - The type of value that will be stored in the context\n * @param {Value | undefined} [defaultValue] - Default value for the context\n * @param {CreateReactiveContextOptions<Value>} [options] - Additional options for context creation\n * @returns {CreateReactiveContextReturn<Value>} Object containing context utilities and components\n *\n * @example\n * const { Provider, useSelector, instance } = createReactiveContext<number>(0);\n */\nexport const createReactiveContext = <Value extends Record<string, any>>(\n defaultValue: Value | undefined = undefined,\n options: CreateReactiveContextOptions = {}\n) => {\n const Context = createContext<ReactiveContextValue<Value>>({\n value: { current: defaultValue as Value },\n listeners: new Set()\n });\n\n const Provider = createProvider(Context.Provider) as unknown as Provider<Value>;\n\n Context.displayName = options.name;\n\n function useSelector(): Value;\n function useSelector<SelectedValue>(selector: (state: Value) => SelectedValue): SelectedValue;\n function useSelector<SelectedValue>(selector?: (state: Value) => SelectedValue) {\n return createReactiveContextSelector(\n Context as unknown as Context<ReactiveContextValue<Value>>,\n selector ?? ((state) => state as unknown as SelectedValue),\n options\n );\n }\n\n return { instance: Context, Provider, useSelector };\n};\n"],"names":["createProvider","originalProvider","props","valueRef","useRef","contextValue","useMemo","useIsomorphicLayoutEffect","startTransition","listener","createElement","createReactiveContextSelector","Context","selector","options","context","useContext","value","setValue","useState","dispatch","useEvent","newValue","prevValue","newSelected","createReactiveContext","defaultValue","createContext","Provider","useSelector","state"],"mappings":"yOAyCMA,EAAyBC,GACeC,GAAU,CACpD,MAAMC,EAAWC,EAAAA,OAAOF,EAAM,KAAK,EAC7BG,EAAeC,EAAAA,QACnB,KAAO,CACL,MAAOH,EACP,cAAe,GAAI,GAErB,CAAA,CAAC,EAGHI,OAAAA,EAAAA,0BAA0B,IAAM,CACzB,OAAO,GAAGJ,EAAS,QAASD,EAAM,KAAK,IAC1CC,EAAS,QAAUD,EAAM,MAEzBM,EAAAA,gBAAgB,IAAM,CACpBH,EAAa,UAAU,QAASI,GAAa,CAC3CA,EAASN,EAAS,OAAO,CAAA,CAC1B,CAAA,CACF,EACH,EACC,CAACD,EAAM,KAAK,CAAC,EAETQ,EAAAA,cAAcT,EAAkB,CAAE,MAAOI,CAAA,EAAgBH,EAAM,QAAQ,CAAA,EAM5ES,EAAgC,CACpCC,EACAC,EACAC,EAAwC,CAAA,IACrC,CACH,MAAMC,EAAUC,EAAAA,WAAWJ,CAAO,EAElC,GAAI,CAACG,GAAWD,EAAQ,OACtB,MAAM,IAAI,MAAM,gBAAgBA,EAAQ,IAAI,iCAAiC,EAG/E,KAAM,CAACG,EAAOC,CAAQ,EAAIC,WAAS,CACjC,SAAUN,EAASE,EAAQ,MAAM,OAAO,EACxC,MAAOA,EAAQ,MAAM,OAAA,CACtB,EAEKK,EAAWC,WAAUC,GAAoB,CAC7CJ,EAAUK,GAAc,CACtB,GAAI,OAAO,GAAGA,EAAU,MAAOD,CAAQ,EAAG,OAAOC,EAEjD,MAAMC,EAAcX,EAASS,CAAQ,EACrC,OAAI,OAAO,GAAGC,EAAU,SAAUC,CAAW,EAAUD,EAEhD,CAAE,MAAOD,EAAU,SAAUE,CAAA,CAAY,CACjD,CAAA,CACF,EAEDjB,OAAAA,EAAAA,0BAA0B,KACxBQ,EAAQ,UAAU,IAAIK,CAAQ,EACvB,IAAM,CACXL,EAAQ,UAAU,OAAOK,CAAQ,CAAA,GAElC,CAACL,EAAQ,SAAS,CAAC,EAEfE,EAAM,QACf,EAiBaQ,EAAwB,CACnCC,EAAkC,OAClCZ,EAAwC,CAAA,IACrC,CACH,MAAMF,EAAUe,EAAAA,cAA2C,CACzD,MAAO,CAAE,QAASD,CAAA,EAClB,cAAe,GAAI,CACpB,EAEKE,EAAW5B,EAAeY,EAAQ,QAAQ,EAEhDA,EAAQ,YAAcE,EAAQ,KAI9B,SAASe,EAA2BhB,EAA4C,CAC9E,OAAOF,EACLC,EACAC,IAAciB,GAAUA,GACxBhB,CAAA,CACF,CAGF,MAAO,CAAE,SAAUF,EAAS,SAAAgB,EAAU,YAAAC,CAAA,CACxC"}
@@ -1 +1 @@
1
- {"version":3,"file":"createStore.cjs","sources":["../../../../src/helpers/createStore/createStore.ts"],"sourcesContent":["import { useSyncExternalStore } from 'react';\n\ntype SetStateAction<Value> = ((prev: Value) => Value) | Value;\ntype StateCreator<Value> = (\n set: (action: SetStateAction<Value>) => void,\n get: () => Value\n) => Value;\n\nexport interface StoreApi<Value> {\n getInitialState: () => Value;\n getState: () => Value;\n setState: (action: SetStateAction<Value>) => void;\n subscribe: (listener: (state: Value, prevState: Value) => void) => () => void;\n}\n\n/**\n * @name createStore\n * @description - Creates a store with state management capabilities\n * @category Helpers\n *\n * @template Value - The type of the store state\n *\n * @param {StateCreator<Value>} createState - Function that initializes the store state\n * @returns {StoreApi<Value>} - Object containing store methods and hook for accessing state\n *\n * @example\n * const { set, get, use, subscribe } = createStore((set) => ({\n * count: 0,\n * increment: () => set(state => ({ count: state.count + 1 }))\n * }));\n */\nexport const createStore = <Value>(createState: StateCreator<Value> | Value) => {\n type Listener = (state: Value, prevState: Value) => void;\n let state: Value;\n const listeners: Set<Listener> = new Set();\n\n const setState = (action: SetStateAction<Value>) => {\n const nextState =\n typeof action === 'function' ? (action as (state: Value) => Value)(state) : action;\n\n if (!Object.is(nextState, state)) {\n const prevState = state;\n state = nextState;\n listeners.forEach((listener) => listener(state, prevState));\n }\n };\n\n const getState = () => state;\n const getInitialState = () => state;\n\n const subscribe = (listener: Listener) => {\n listeners.add(listener);\n return () => listeners.delete(listener);\n };\n if (typeof createState === 'function') {\n state = (createState as StateCreator<Value>)(setState, getState);\n } else {\n state = createState;\n }\n\n const useStore = <Selected>(selector: (state: Value) => Selected) =>\n useSyncExternalStore(\n subscribe,\n () => selector(getState()),\n () => selector(getInitialState())\n );\n\n return {\n set: setState,\n get: getState,\n use: useStore,\n subscribe\n };\n};\n"],"names":["createStore","createState","state","listeners","setState","action","nextState","prevState","listener","getState","getInitialState","subscribe","selector","useSyncExternalStore"],"mappings":"yGA+BaA,EAAsBC,GAA6C,CAE1E,IAAAC,EACE,MAAAC,MAA+B,IAE/BC,EAAYC,GAAkC,CAClD,MAAMC,EACJ,OAAOD,GAAW,WAAcA,EAAmCH,CAAK,EAAIG,EAE9E,GAAI,CAAC,OAAO,GAAGC,EAAWJ,CAAK,EAAG,CAChC,MAAMK,EAAYL,EACVA,EAAAI,EACRH,EAAU,QAASK,GAAaA,EAASN,EAAOK,CAAS,CAAC,CAAA,CAE9D,EAEME,EAAW,IAAMP,EACjBQ,EAAkB,IAAMR,EAExBS,EAAaH,IACjBL,EAAU,IAAIK,CAAQ,EACf,IAAML,EAAU,OAAOK,CAAQ,GAEpC,OAAA,OAAOP,GAAgB,WAChBC,EAAAD,EAAoCG,EAAUK,CAAQ,EAEvDP,EAAAD,EAUH,CACL,IAAKG,EACL,IAAKK,EACL,IAV0BG,GAC1BC,EAAA,qBACEF,EACA,IAAMC,EAASH,GAAU,EACzB,IAAMG,EAASF,EAAiB,CAAA,CAClC,EAMA,UAAAC,CACF,CACF"}
1
+ {"version":3,"file":"createStore.cjs","sources":["../../../../src/helpers/createStore/createStore.ts"],"sourcesContent":["import { useSyncExternalStore } from 'react';\n\ntype SetStateAction<Value> = ((prev: Value) => Value) | Value;\ntype StateCreator<Value> = (\n set: (action: SetStateAction<Value>) => void,\n get: () => Value\n) => Value;\n\nexport interface StoreApi<Value> {\n getInitialState: () => Value;\n getState: () => Value;\n setState: (action: SetStateAction<Value>) => void;\n subscribe: (listener: (state: Value, prevState: Value) => void) => () => void;\n}\n\n/**\n * @name createStore\n * @description - Creates a store with state management capabilities\n * @category Helpers\n *\n * @template Value - The type of the store state\n *\n * @param {StateCreator<Value>} createState - Function that initializes the store state\n * @returns {StoreApi<Value>} - Object containing store methods and hook for accessing state\n *\n * @example\n * const { set, get, use, subscribe } = createStore((set) => ({\n * count: 0,\n * increment: () => set(state => ({ count: state.count + 1 }))\n * }));\n */\nexport const createStore = <Value>(createState: StateCreator<Value> | Value) => {\n type Listener = (state: Value, prevState: Value) => void;\n let state: Value;\n const listeners: Set<Listener> = new Set();\n\n const setState = (action: SetStateAction<Value>) => {\n const nextState =\n typeof action === 'function' ? (action as (state: Value) => Value)(state) : action;\n\n if (!Object.is(nextState, state)) {\n const prevState = state;\n state = nextState;\n listeners.forEach((listener) => listener(state, prevState));\n }\n };\n\n const getState = () => state;\n const getInitialState = () => state;\n\n const subscribe = (listener: Listener) => {\n listeners.add(listener);\n return () => listeners.delete(listener);\n };\n if (typeof createState === 'function') {\n state = (createState as StateCreator<Value>)(setState, getState);\n } else {\n state = createState;\n }\n\n const useStore = <Selected>(selector: (state: Value) => Selected) =>\n useSyncExternalStore(\n subscribe,\n () => selector(getState()),\n () => selector(getInitialState())\n );\n\n return {\n set: setState,\n get: getState,\n use: useStore,\n subscribe\n };\n};\n"],"names":["createStore","createState","state","listeners","setState","action","nextState","prevState","listener","getState","getInitialState","subscribe","selector","useSyncExternalStore"],"mappings":"yGA+BaA,EAAsBC,GAA6C,CAE9E,IAAIC,EACJ,MAAMC,MAA+B,IAE/BC,EAAYC,GAAkC,CAClD,MAAMC,EACJ,OAAOD,GAAW,WAAcA,EAAmCH,CAAK,EAAIG,EAE9E,GAAI,CAAC,OAAO,GAAGC,EAAWJ,CAAK,EAAG,CAChC,MAAMK,EAAYL,EAClBA,EAAQI,EACRH,EAAU,QAASK,GAAaA,EAASN,EAAOK,CAAS,CAAC,CAAA,CAC5D,EAGIE,EAAW,IAAMP,EACjBQ,EAAkB,IAAMR,EAExBS,EAAaH,IACjBL,EAAU,IAAIK,CAAQ,EACf,IAAML,EAAU,OAAOK,CAAQ,GAExC,OAAI,OAAOP,GAAgB,WACzBC,EAASD,EAAoCG,EAAUK,CAAQ,EAE/DP,EAAQD,EAUH,CACL,IAAKG,EACL,IAAKK,EACL,IAV0BG,GAC1BC,EAAAA,qBACEF,EACA,IAAMC,EAASH,GAAU,EACzB,IAAMG,EAASF,EAAA,CAAiB,CAAA,EAOlC,UAAAC,CAAA,CAEJ"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react"),c=()=>{const[u,n]=r.useState(null);return r.useEffect(()=>{const e=()=>n(document==null?void 0:document.activeElement);return window.addEventListener("focus",e,!0),window.addEventListener("blur",e,!0),()=>{window.removeEventListener("focus",e,!0),window.removeEventListener("blur",e,!0)}}),r.useEffect(()=>{const e=new MutationObserver(s=>{s.filter(t=>t.removedNodes.length).map(t=>Array.from(t.removedNodes)).flat().forEach(t=>{n(o=>t===o?document.activeElement:o)})});return e.observe(document,{childList:!0,subtree:!0}),()=>{e.disconnect()}},[]),u};exports.useActiveElement=c;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react"),c=()=>{const[u,n]=r.useState(null);return r.useEffect(()=>{const e=()=>n(document?.activeElement);return window.addEventListener("focus",e,!0),window.addEventListener("blur",e,!0),()=>{window.removeEventListener("focus",e,!0),window.removeEventListener("blur",e,!0)}}),r.useEffect(()=>{const e=new MutationObserver(s=>{s.filter(t=>t.removedNodes.length).map(t=>Array.from(t.removedNodes)).flat().forEach(t=>{n(o=>t===o?document.activeElement:o)})});return e.observe(document,{childList:!0,subtree:!0}),()=>{e.disconnect()}},[]),u};exports.useActiveElement=c;
2
2
  //# sourceMappingURL=useActiveElement.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"useActiveElement.cjs","sources":["../../../../src/hooks/useActiveElement/useActiveElement.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\n/**\n * @name useActiveElement\n * @description - Hook that returns the active element\n * @category Elements\n *\n * @returns {ActiveElement | null} The active element\n *\n * @example\n * const activeElement = useActiveElement();\n *\n * @see {@link https://siberiacancode.github.io/reactuse/functions/hooks/useActiveElement.html}\n */\nexport const useActiveElement = <ActiveElement extends HTMLElement>() => {\n const [activeElement, setActiveElement] = useState<ActiveElement | null>(null);\n\n useEffect(() => {\n const onActiveElementChange = () =>\n setActiveElement(document?.activeElement as ActiveElement | null);\n\n window.addEventListener('focus', onActiveElementChange, true);\n window.addEventListener('blur', onActiveElementChange, true);\n\n return () => {\n window.removeEventListener('focus', onActiveElementChange, true);\n window.removeEventListener('blur', onActiveElementChange, true);\n };\n });\n\n useEffect(() => {\n const observer = new MutationObserver((mutations) => {\n mutations\n .filter((mutation) => mutation.removedNodes.length)\n .map((mutation) => Array.from(mutation.removedNodes))\n .flat()\n .forEach((node) => {\n setActiveElement((prevActiveElement) => {\n if (node === prevActiveElement) return document.activeElement as ActiveElement | null;\n return prevActiveElement;\n });\n });\n });\n\n observer.observe(document, {\n childList: true,\n subtree: true\n });\n\n return () => {\n observer.disconnect();\n };\n }, []);\n\n return activeElement;\n};\n"],"names":["useActiveElement","activeElement","setActiveElement","useState","useEffect","onActiveElementChange","observer","mutations","mutation","node","prevActiveElement"],"mappings":"yGAcaA,EAAmB,IAAyC,CACvE,KAAM,CAACC,EAAeC,CAAgB,EAAIC,EAAAA,SAA+B,IAAI,EAE7EC,OAAAA,EAAAA,UAAU,IAAM,CACd,MAAMC,EAAwB,IAC5BH,EAAiB,+BAAU,aAAqC,EAE3D,cAAA,iBAAiB,QAASG,EAAuB,EAAI,EACrD,OAAA,iBAAiB,OAAQA,EAAuB,EAAI,EAEpD,IAAM,CACJ,OAAA,oBAAoB,QAASA,EAAuB,EAAI,EACxD,OAAA,oBAAoB,OAAQA,EAAuB,EAAI,CAChE,CAAA,CACD,EAEDD,EAAAA,UAAU,IAAM,CACd,MAAME,EAAW,IAAI,iBAAkBC,GAAc,CAEhDA,EAAA,OAAQC,GAAaA,EAAS,aAAa,MAAM,EACjD,IAAKA,GAAa,MAAM,KAAKA,EAAS,YAAY,CAAC,EACnD,OACA,QAASC,GAAS,CACjBP,EAAkBQ,GACZD,IAASC,EAA0B,SAAS,cACzCA,CACR,CAAA,CACF,CAAA,CACJ,EAED,OAAAJ,EAAS,QAAQ,SAAU,CACzB,UAAW,GACX,QAAS,EAAA,CACV,EAEM,IAAM,CACXA,EAAS,WAAW,CACtB,CACF,EAAG,EAAE,EAEEL,CACT"}
1
+ {"version":3,"file":"useActiveElement.cjs","sources":["../../../../src/hooks/useActiveElement/useActiveElement.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\n/**\n * @name useActiveElement\n * @description - Hook that returns the active element\n * @category Elements\n *\n * @returns {ActiveElement | null} The active element\n *\n * @example\n * const activeElement = useActiveElement();\n *\n * @see {@link https://siberiacancode.github.io/reactuse/functions/hooks/useActiveElement.html}\n */\nexport const useActiveElement = <ActiveElement extends HTMLElement>() => {\n const [activeElement, setActiveElement] = useState<ActiveElement | null>(null);\n\n useEffect(() => {\n const onActiveElementChange = () =>\n setActiveElement(document?.activeElement as ActiveElement | null);\n\n window.addEventListener('focus', onActiveElementChange, true);\n window.addEventListener('blur', onActiveElementChange, true);\n\n return () => {\n window.removeEventListener('focus', onActiveElementChange, true);\n window.removeEventListener('blur', onActiveElementChange, true);\n };\n });\n\n useEffect(() => {\n const observer = new MutationObserver((mutations) => {\n mutations\n .filter((mutation) => mutation.removedNodes.length)\n .map((mutation) => Array.from(mutation.removedNodes))\n .flat()\n .forEach((node) => {\n setActiveElement((prevActiveElement) => {\n if (node === prevActiveElement) return document.activeElement as ActiveElement | null;\n return prevActiveElement;\n });\n });\n });\n\n observer.observe(document, {\n childList: true,\n subtree: true\n });\n\n return () => {\n observer.disconnect();\n };\n }, []);\n\n return activeElement;\n};\n"],"names":["useActiveElement","activeElement","setActiveElement","useState","useEffect","onActiveElementChange","observer","mutations","mutation","node","prevActiveElement"],"mappings":"yGAcaA,EAAmB,IAAyC,CACvE,KAAM,CAACC,EAAeC,CAAgB,EAAIC,EAAAA,SAA+B,IAAI,EAE7EC,OAAAA,EAAAA,UAAU,IAAM,CACd,MAAMC,EAAwB,IAC5BH,EAAiB,UAAU,aAAqC,EAElE,cAAO,iBAAiB,QAASG,EAAuB,EAAI,EAC5D,OAAO,iBAAiB,OAAQA,EAAuB,EAAI,EAEpD,IAAM,CACX,OAAO,oBAAoB,QAASA,EAAuB,EAAI,EAC/D,OAAO,oBAAoB,OAAQA,EAAuB,EAAI,CAAA,CAChE,CACD,EAEDD,EAAAA,UAAU,IAAM,CACd,MAAME,EAAW,IAAI,iBAAkBC,GAAc,CACnDA,EACG,OAAQC,GAAaA,EAAS,aAAa,MAAM,EACjD,IAAKA,GAAa,MAAM,KAAKA,EAAS,YAAY,CAAC,EACnD,OACA,QAASC,GAAS,CACjBP,EAAkBQ,GACZD,IAASC,EAA0B,SAAS,cACzCA,CACR,CAAA,CACF,CAAA,CACJ,EAED,OAAAJ,EAAS,QAAQ,SAAU,CACzB,UAAW,GACX,QAAS,EAAA,CACV,EAEM,IAAM,CACXA,EAAS,WAAA,CAAW,CACtB,EACC,EAAE,EAEEL,CACT"}
@@ -1 +1 @@
1
- {"version":3,"file":"useAsync.cjs","sources":["../../../../src/hooks/useAsync/useAsync.ts"],"sourcesContent":["import type { DependencyList } from 'react';\n\nimport { useEffect, useState } from 'react';\n\n/* The use query return type */\nexport interface UseAsyncReturn<Data> {\n /* The state of the query */\n data?: Data;\n /* The error of the query */\n error?: Error;\n /* The error state of the query */\n isError: boolean;\n /* The loading state of the query */\n isLoading: boolean;\n}\n\n/**\n * @name useAsync\n * @description - Hook that provides the state of an async callback\n * @category Utilities\n *\n * @param {() => Promise<Data>} callback The async callback\n * @param {DependencyList} deps The dependencies of the callback\n * @returns {UseAsyncReturn<Data>} The state of the async callback\n *\n * @example\n * const { data, isLoading, isError, error } = useAsync(() => fetch('url'), [deps]);\n */\nexport const useAsync = <Data>(\n callback: () => Promise<Data>,\n deps: DependencyList\n): UseAsyncReturn<Data> => {\n const [isLoading, setIsLoading] = useState(true);\n const [isError, setIsError] = useState(false);\n\n const [error, setError] = useState<Error | undefined>(undefined);\n const [data, setData] = useState<Data | undefined>(undefined);\n\n useEffect(() => {\n setIsLoading(true);\n callback()\n .then((response) => {\n setData(response);\n setError(undefined);\n setIsError(false);\n })\n .catch((error: Error) => {\n setError(error);\n setIsError(true);\n })\n .finally(() => {\n setIsLoading(false);\n });\n }, deps);\n\n return {\n data,\n isLoading,\n isError,\n error\n };\n};\n"],"names":["useAsync","callback","deps","isLoading","setIsLoading","useState","isError","setIsError","error","setError","data","setData","useEffect","response"],"mappings":"yGA4BaA,EAAW,CACtBC,EACAC,IACyB,CACzB,KAAM,CAACC,EAAWC,CAAY,EAAIC,EAAAA,SAAS,EAAI,EACzC,CAACC,EAASC,CAAU,EAAIF,EAAAA,SAAS,EAAK,EAEtC,CAACG,EAAOC,CAAQ,EAAIJ,EAAAA,SAA4B,MAAS,EACzD,CAACK,EAAMC,CAAO,EAAIN,EAAAA,SAA2B,MAAS,EAE5DO,OAAAA,EAAAA,UAAU,IAAM,CACdR,EAAa,EAAI,EACRH,EAAA,EACN,KAAMY,GAAa,CAClBF,EAAQE,CAAQ,EAChBJ,EAAS,MAAS,EAClBF,EAAW,EAAK,CAAA,CACjB,EACA,MAAOC,GAAiB,CACvBC,EAASD,CAAK,EACdD,EAAW,EAAI,CAAA,CAChB,EACA,QAAQ,IAAM,CACbH,EAAa,EAAK,CAAA,CACnB,GACFF,CAAI,EAEA,CACL,KAAAQ,EACA,UAAAP,EACA,QAAAG,EACA,MAAAE,CACF,CACF"}
1
+ {"version":3,"file":"useAsync.cjs","sources":["../../../../src/hooks/useAsync/useAsync.ts"],"sourcesContent":["import type { DependencyList } from 'react';\n\nimport { useEffect, useState } from 'react';\n\n/* The use query return type */\nexport interface UseAsyncReturn<Data> {\n /* The state of the query */\n data?: Data;\n /* The error of the query */\n error?: Error;\n /* The error state of the query */\n isError: boolean;\n /* The loading state of the query */\n isLoading: boolean;\n}\n\n/**\n * @name useAsync\n * @description - Hook that provides the state of an async callback\n * @category Utilities\n *\n * @param {() => Promise<Data>} callback The async callback\n * @param {DependencyList} deps The dependencies of the callback\n * @returns {UseAsyncReturn<Data>} The state of the async callback\n *\n * @example\n * const { data, isLoading, isError, error } = useAsync(() => fetch('url'), [deps]);\n */\nexport const useAsync = <Data>(\n callback: () => Promise<Data>,\n deps: DependencyList\n): UseAsyncReturn<Data> => {\n const [isLoading, setIsLoading] = useState(true);\n const [isError, setIsError] = useState(false);\n\n const [error, setError] = useState<Error | undefined>(undefined);\n const [data, setData] = useState<Data | undefined>(undefined);\n\n useEffect(() => {\n setIsLoading(true);\n callback()\n .then((response) => {\n setData(response);\n setError(undefined);\n setIsError(false);\n })\n .catch((error: Error) => {\n setError(error);\n setIsError(true);\n })\n .finally(() => {\n setIsLoading(false);\n });\n }, deps);\n\n return {\n data,\n isLoading,\n isError,\n error\n };\n};\n"],"names":["useAsync","callback","deps","isLoading","setIsLoading","useState","isError","setIsError","error","setError","data","setData","useEffect","response"],"mappings":"yGA4BaA,EAAW,CACtBC,EACAC,IACyB,CACzB,KAAM,CAACC,EAAWC,CAAY,EAAIC,EAAAA,SAAS,EAAI,EACzC,CAACC,EAASC,CAAU,EAAIF,EAAAA,SAAS,EAAK,EAEtC,CAACG,EAAOC,CAAQ,EAAIJ,EAAAA,SAA4B,MAAS,EACzD,CAACK,EAAMC,CAAO,EAAIN,EAAAA,SAA2B,MAAS,EAE5DO,OAAAA,EAAAA,UAAU,IAAM,CACdR,EAAa,EAAI,EACjBH,EAAA,EACG,KAAMY,GAAa,CAClBF,EAAQE,CAAQ,EAChBJ,EAAS,MAAS,EAClBF,EAAW,EAAK,CAAA,CACjB,EACA,MAAOC,GAAiB,CACvBC,EAASD,CAAK,EACdD,EAAW,EAAI,CAAA,CAChB,EACA,QAAQ,IAAM,CACbH,EAAa,EAAK,CAAA,CACnB,CAAA,EACFF,CAAI,EAEA,CACL,KAAAQ,EACA,UAAAP,EACA,QAAAG,EACA,MAAAE,CAAA,CAEJ"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("react"),c=()=>{const i=typeof navigator<"u"&&"getBattery"in navigator&&typeof navigator.getBattery=="function",[g,t]=a.useState({loading:!0,level:0,charging:!1,chargingTime:0,dischargingTime:0});return a.useEffect(()=>{if(!i)return t({...g,loading:!1});let e;const n=()=>t({loading:!1,level:(e==null?void 0:e.level)??0,charging:(e==null?void 0:e.charging)??!1,dischargingTime:(e==null?void 0:e.dischargingTime)??0,chargingTime:(e==null?void 0:e.chargingTime)??0});return navigator.getBattery().then(r=>{e=r,n(),e.addEventListener("levelchange",n),e.addEventListener("chargingchange",n),e.addEventListener("chargingtimechange",n),e.addEventListener("dischargingtimechange",n)}),()=>{e&&(e.removeEventListener("levelchange",n),e.removeEventListener("chargingchange",n),e.removeEventListener("chargingtimechange",n),e.removeEventListener("dischargingtimechange",n))}},[]),{supported:i,value:g}};exports.useBattery=c;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react"),c=()=>{const n=typeof navigator<"u"&&"getBattery"in navigator&&typeof navigator.getBattery=="function",[a,i]=r.useState({loading:!0,level:0,charging:!1,chargingTime:0,dischargingTime:0});return r.useEffect(()=>{if(!n)return i({...a,loading:!1});let e;const t=()=>i({loading:!1,level:e?.level??0,charging:e?.charging??!1,dischargingTime:e?.dischargingTime??0,chargingTime:e?.chargingTime??0});return navigator.getBattery().then(g=>{e=g,t(),e.addEventListener("levelchange",t),e.addEventListener("chargingchange",t),e.addEventListener("chargingtimechange",t),e.addEventListener("dischargingtimechange",t)}),()=>{e&&(e.removeEventListener("levelchange",t),e.removeEventListener("chargingchange",t),e.removeEventListener("chargingtimechange",t),e.removeEventListener("dischargingtimechange",t))}},[]),{supported:n,value:a}};exports.useBattery=c;
2
2
  //# sourceMappingURL=useBattery.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"useBattery.cjs","sources":["../../../../src/hooks/useBattery/useBattery.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\nexport interface BatteryManager extends EventTarget {\n charging: boolean;\n chargingTime: number;\n dischargingTime: number;\n level: number;\n}\n\ndeclare global {\n interface Navigator {\n readonly getBattery: () => Promise<BatteryManager>;\n }\n}\n\n/** The use battery value type */\nexport interface UseBatteryValue {\n /** Is charging battery? */\n charging: boolean;\n /** Time until the battery is fully charged */\n chargingTime: number;\n /** Time until the battery is completely discharged */\n dischargingTime: number;\n /** Battery charge level from 0 to 1 */\n level: number;\n /** Is battery information loading? */\n loading: boolean;\n}\n\n/** The use battery return type */\nexport interface UseBatteryStateReturn {\n /** Whether the battery api is supported*/\n supported: boolean;\n /** The use battery value type */\n value: UseBatteryValue;\n}\n\n/**\n * @name useBattery\n * @description - Hook for getting information about battery status\n * @category Browser\n *\n * @browserapi navigator.getBattery https://developer.mozilla.org/en-US/docs/Web/API/Navigator/getBattery\n *\n * @returns {UseBatteryStateReturn} Object containing battery information & Battery API support\n *\n * @example\n * const { supported, loading, charging, chargingTime, dischargingTime, level } = useBattery();\n */\nexport const useBattery = (): UseBatteryStateReturn => {\n const supported =\n typeof navigator !== 'undefined' &&\n 'getBattery' in navigator &&\n typeof navigator.getBattery === 'function';\n const [value, setValue] = useState<UseBatteryValue>({\n loading: true,\n level: 0,\n charging: false,\n chargingTime: 0,\n dischargingTime: 0\n });\n\n useEffect(() => {\n if (!supported) return setValue({ ...value, loading: false });\n\n let battery: BatteryManager | null;\n\n const onChange = () =>\n setValue({\n loading: false,\n level: battery?.level ?? 0,\n charging: battery?.charging ?? false,\n dischargingTime: battery?.dischargingTime ?? 0,\n chargingTime: battery?.chargingTime ?? 0\n });\n\n navigator.getBattery().then((batteryManager) => {\n battery = batteryManager;\n onChange();\n\n battery.addEventListener('levelchange', onChange);\n battery.addEventListener('chargingchange', onChange);\n battery.addEventListener('chargingtimechange', onChange);\n battery.addEventListener('dischargingtimechange', onChange);\n });\n\n return () => {\n if (!battery) return;\n battery.removeEventListener('levelchange', onChange);\n battery.removeEventListener('chargingchange', onChange);\n battery.removeEventListener('chargingtimechange', onChange);\n battery.removeEventListener('dischargingtimechange', onChange);\n };\n }, []);\n\n return { supported, value };\n};\n"],"names":["useBattery","supported","value","setValue","useState","useEffect","battery","onChange","batteryManager"],"mappings":"yGAiDaA,EAAa,IAA6B,CAC/C,MAAAC,EACJ,OAAO,UAAc,KACrB,eAAgB,WAChB,OAAO,UAAU,YAAe,WAC5B,CAACC,EAAOC,CAAQ,EAAIC,WAA0B,CAClD,QAAS,GACT,MAAO,EACP,SAAU,GACV,aAAc,EACd,gBAAiB,CAAA,CAClB,EAEDC,OAAAA,EAAAA,UAAU,IAAM,CACV,GAAA,CAACJ,EAAkB,OAAAE,EAAS,CAAE,GAAGD,EAAO,QAAS,GAAO,EAExD,IAAAI,EAEE,MAAAC,EAAW,IACfJ,EAAS,CACP,QAAS,GACT,OAAOG,GAAA,YAAAA,EAAS,QAAS,EACzB,UAAUA,GAAA,YAAAA,EAAS,WAAY,GAC/B,iBAAiBA,GAAA,YAAAA,EAAS,kBAAmB,EAC7C,cAAcA,GAAA,YAAAA,EAAS,eAAgB,CAAA,CACxC,EAEH,iBAAU,WAAW,EAAE,KAAME,GAAmB,CACpCF,EAAAE,EACDD,EAAA,EAEDD,EAAA,iBAAiB,cAAeC,CAAQ,EACxCD,EAAA,iBAAiB,iBAAkBC,CAAQ,EAC3CD,EAAA,iBAAiB,qBAAsBC,CAAQ,EAC/CD,EAAA,iBAAiB,wBAAyBC,CAAQ,CAAA,CAC3D,EAEM,IAAM,CACND,IACGA,EAAA,oBAAoB,cAAeC,CAAQ,EAC3CD,EAAA,oBAAoB,iBAAkBC,CAAQ,EAC9CD,EAAA,oBAAoB,qBAAsBC,CAAQ,EAClDD,EAAA,oBAAoB,wBAAyBC,CAAQ,EAC/D,CACF,EAAG,EAAE,EAEE,CAAE,UAAAN,EAAW,MAAAC,CAAM,CAC5B"}
1
+ {"version":3,"file":"useBattery.cjs","sources":["../../../../src/hooks/useBattery/useBattery.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\nexport interface BatteryManager extends EventTarget {\n charging: boolean;\n chargingTime: number;\n dischargingTime: number;\n level: number;\n}\n\ndeclare global {\n interface Navigator {\n readonly getBattery: () => Promise<BatteryManager>;\n }\n}\n\n/** The use battery value type */\nexport interface UseBatteryValue {\n /** Is charging battery? */\n charging: boolean;\n /** Time until the battery is fully charged */\n chargingTime: number;\n /** Time until the battery is completely discharged */\n dischargingTime: number;\n /** Battery charge level from 0 to 1 */\n level: number;\n /** Is battery information loading? */\n loading: boolean;\n}\n\n/** The use battery return type */\nexport interface UseBatteryStateReturn {\n /** Whether the battery api is supported*/\n supported: boolean;\n /** The use battery value type */\n value: UseBatteryValue;\n}\n\n/**\n * @name useBattery\n * @description - Hook for getting information about battery status\n * @category Browser\n *\n * @browserapi navigator.getBattery https://developer.mozilla.org/en-US/docs/Web/API/Navigator/getBattery\n *\n * @returns {UseBatteryStateReturn} Object containing battery information & Battery API support\n *\n * @example\n * const { supported, loading, charging, chargingTime, dischargingTime, level } = useBattery();\n */\nexport const useBattery = (): UseBatteryStateReturn => {\n const supported =\n typeof navigator !== 'undefined' &&\n 'getBattery' in navigator &&\n typeof navigator.getBattery === 'function';\n const [value, setValue] = useState<UseBatteryValue>({\n loading: true,\n level: 0,\n charging: false,\n chargingTime: 0,\n dischargingTime: 0\n });\n\n useEffect(() => {\n if (!supported) return setValue({ ...value, loading: false });\n\n let battery: BatteryManager | null;\n\n const onChange = () =>\n setValue({\n loading: false,\n level: battery?.level ?? 0,\n charging: battery?.charging ?? false,\n dischargingTime: battery?.dischargingTime ?? 0,\n chargingTime: battery?.chargingTime ?? 0\n });\n\n navigator.getBattery().then((batteryManager) => {\n battery = batteryManager;\n onChange();\n\n battery.addEventListener('levelchange', onChange);\n battery.addEventListener('chargingchange', onChange);\n battery.addEventListener('chargingtimechange', onChange);\n battery.addEventListener('dischargingtimechange', onChange);\n });\n\n return () => {\n if (!battery) return;\n battery.removeEventListener('levelchange', onChange);\n battery.removeEventListener('chargingchange', onChange);\n battery.removeEventListener('chargingtimechange', onChange);\n battery.removeEventListener('dischargingtimechange', onChange);\n };\n }, []);\n\n return { supported, value };\n};\n"],"names":["useBattery","supported","value","setValue","useState","useEffect","battery","onChange","batteryManager"],"mappings":"yGAiDaA,EAAa,IAA6B,CACrD,MAAMC,EACJ,OAAO,UAAc,KACrB,eAAgB,WAChB,OAAO,UAAU,YAAe,WAC5B,CAACC,EAAOC,CAAQ,EAAIC,WAA0B,CAClD,QAAS,GACT,MAAO,EACP,SAAU,GACV,aAAc,EACd,gBAAiB,CAAA,CAClB,EAEDC,OAAAA,EAAAA,UAAU,IAAM,CACd,GAAI,CAACJ,EAAW,OAAOE,EAAS,CAAE,GAAGD,EAAO,QAAS,GAAO,EAE5D,IAAII,EAEJ,MAAMC,EAAW,IACfJ,EAAS,CACP,QAAS,GACT,MAAOG,GAAS,OAAS,EACzB,SAAUA,GAAS,UAAY,GAC/B,gBAAiBA,GAAS,iBAAmB,EAC7C,aAAcA,GAAS,cAAgB,CAAA,CACxC,EAEH,iBAAU,WAAA,EAAa,KAAME,GAAmB,CAC9CF,EAAUE,EACVD,EAAA,EAEAD,EAAQ,iBAAiB,cAAeC,CAAQ,EAChDD,EAAQ,iBAAiB,iBAAkBC,CAAQ,EACnDD,EAAQ,iBAAiB,qBAAsBC,CAAQ,EACvDD,EAAQ,iBAAiB,wBAAyBC,CAAQ,CAAA,CAC3D,EAEM,IAAM,CACND,IACLA,EAAQ,oBAAoB,cAAeC,CAAQ,EACnDD,EAAQ,oBAAoB,iBAAkBC,CAAQ,EACtDD,EAAQ,oBAAoB,qBAAsBC,CAAQ,EAC1DD,EAAQ,oBAAoB,wBAAyBC,CAAQ,EAAA,CAC/D,EACC,EAAE,EAEE,CAAE,UAAAN,EAAW,MAAAC,CAAA,CACtB"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react"),p=u=>{const s=typeof navigator<"u"&&"bluetooth"in navigator,{acceptAllDevices:d=!1,filters:c,optionalServices:l}=u??{},[f,r]=n.useState(!1),[e,a]=n.useState(void 0),[g,i]=n.useState(void 0),S=async()=>{if(!s)return;const o=await navigator.bluetooth.requestDevice({acceptAllDevices:d,optionalServices:l,...c&&{filters:c,acceptAllDevices:!1}});a(o)};return n.useEffect(()=>{if(e&&e.gatt){const o=async()=>{if(!e.gatt)return;const t=await e.gatt.connect();i(t),r(t.connected)},v=()=>{i(void 0),a(void 0),r(!1)};return e.addEventListener("gattserverdisconnected",v),o(),()=>{var t;e.removeEventListener("gattserverdisconnected",v),(t=e.gatt)==null||t.disconnect()}}},[e]),{supported:s,connected:f,device:e,requestDevice:S,server:g}};exports.useBluetooth=p;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react"),p=u=>{const o=typeof navigator<"u"&&"bluetooth"in navigator,{acceptAllDevices:d=!1,filters:s,optionalServices:l}=u??{},[f,c]=t.useState(!1),[e,r]=t.useState(void 0),[g,a]=t.useState(void 0),S=async()=>{if(!o)return;const n=await navigator.bluetooth.requestDevice({acceptAllDevices:d,optionalServices:l,...s&&{filters:s,acceptAllDevices:!1}});r(n)};return t.useEffect(()=>{if(e&&e.gatt){const n=async()=>{if(!e.gatt)return;const v=await e.gatt.connect();a(v),c(v.connected)},i=()=>{a(void 0),r(void 0),c(!1)};return e.addEventListener("gattserverdisconnected",i),n(),()=>{e.removeEventListener("gattserverdisconnected",i),e.gatt?.disconnect()}}},[e]),{supported:o,connected:f,device:e,requestDevice:S,server:g}};exports.useBluetooth=p;
2
2
  //# sourceMappingURL=useBluetooth.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"useBluetooth.cjs","sources":["../../../../src/hooks/useBluetooth/useBluetooth.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\n/** The use bluetooth return type */\nexport interface UseBluetoothReturn {\n /** Indicates if bluetooth device is currently connected */\n connected: boolean;\n /** Describe connected bluetooth device */\n device?: BluetoothDevice;\n /** The GATT server for connected bluetooth device */\n server?: BluetoothRemoteGATTServer;\n /** Whether the bluetooth is supported*/\n supported: boolean;\n /** Function to request bluetooth device from the user */\n requestDevice: () => Promise<void>;\n}\n\n/** The use bluetooth options type */\nexport interface UseBluetoothOptions {\n /** The options to request all bluetooth devices */\n acceptAllDevices?: boolean;\n /** Array of filters to apply when scanning bluetooth devices */\n filters?: BluetoothLEScanFilter[];\n /** Array of optional services that the application can use */\n optionalServices?: BluetoothServiceUUID[];\n}\n\n/**\n * @name useBluetooth\n * @description - Hook for getting information about bluetooth\n * @category Browser\n *\n * @browserapi navigator.bluetooth https://developer.mozilla.org/en-US/docs/Web/API/Navigator/bluetooth\n *\n * @param {boolean} [options.acceptAllDevices=false] The options to request all Bluetooth devices\n * @param {Array<BluetoothLEScanFilter>} [options.filters] Array of filters to apply when scanning Bluetooth devices\n * @param {Array<BluetoothServiceUUID>} [options.optionalServices] Array of optional services that the application can use\n * @returns {UseBluetoothReturn} Object containing battery information & Battery API support\n *\n * @example\n * const { supported, connected, device, requestDevice, server } = useBluetooth(options);\n */\nexport const useBluetooth = (options?: UseBluetoothOptions): UseBluetoothReturn => {\n const supported = typeof navigator !== 'undefined' && 'bluetooth' in navigator;\n const { acceptAllDevices = false, filters, optionalServices } = options ?? {};\n\n const [connected, setIsConnected] = useState(false);\n const [device, setDevice] = useState<BluetoothDevice | undefined>(undefined);\n const [server, setServer] = useState<BluetoothRemoteGATTServer | undefined>(undefined);\n\n const requestDevice = async () => {\n if (!supported) return;\n\n const selectedDevice = await navigator.bluetooth.requestDevice({\n acceptAllDevices,\n optionalServices,\n ...(filters && { filters, acceptAllDevices: false })\n });\n\n setDevice(selectedDevice);\n };\n\n useEffect(() => {\n if (device && device.gatt) {\n const connectToBluetoothGATTServer = async () => {\n if (!device.gatt) return;\n const gattServer = await device.gatt.connect();\n setServer(gattServer);\n setIsConnected(gattServer.connected);\n };\n\n const reset = () => {\n setServer(undefined);\n setDevice(undefined);\n setIsConnected(false);\n };\n\n device.addEventListener('gattserverdisconnected', reset);\n connectToBluetoothGATTServer();\n\n return () => {\n device.removeEventListener('gattserverdisconnected', reset);\n device.gatt?.disconnect();\n };\n }\n }, [device]);\n\n return {\n supported,\n connected,\n device,\n requestDevice,\n server\n };\n};\n"],"names":["useBluetooth","options","supported","acceptAllDevices","filters","optionalServices","connected","setIsConnected","useState","device","setDevice","server","setServer","requestDevice","selectedDevice","useEffect","connectToBluetoothGATTServer","gattServer","reset","_a"],"mappings":"yGAyCaA,EAAgBC,GAAsD,CACjF,MAAMC,EAAY,OAAO,UAAc,KAAe,cAAe,UAC/D,CAAE,iBAAAC,EAAmB,GAAO,QAAAC,EAAS,iBAAAC,CAAiB,EAAIJ,GAAW,CAAC,EAEtE,CAACK,EAAWC,CAAc,EAAIC,EAAAA,SAAS,EAAK,EAC5C,CAACC,EAAQC,CAAS,EAAIF,EAAAA,SAAsC,MAAS,EACrE,CAACG,EAAQC,CAAS,EAAIJ,EAAAA,SAAgD,MAAS,EAE/EK,EAAgB,SAAY,CAChC,GAAI,CAACX,EAAW,OAEhB,MAAMY,EAAiB,MAAM,UAAU,UAAU,cAAc,CAC7D,iBAAAX,EACA,iBAAAE,EACA,GAAID,GAAW,CAAE,QAAAA,EAAS,iBAAkB,EAAM,CAAA,CACnD,EAEDM,EAAUI,CAAc,CAC1B,EAEAC,OAAAA,EAAAA,UAAU,IAAM,CACV,GAAAN,GAAUA,EAAO,KAAM,CACzB,MAAMO,EAA+B,SAAY,CAC3C,GAAA,CAACP,EAAO,KAAM,OAClB,MAAMQ,EAAa,MAAMR,EAAO,KAAK,QAAQ,EAC7CG,EAAUK,CAAU,EACpBV,EAAeU,EAAW,SAAS,CACrC,EAEMC,EAAQ,IAAM,CAClBN,EAAU,MAAS,EACnBF,EAAU,MAAS,EACnBH,EAAe,EAAK,CACtB,EAEO,OAAAE,EAAA,iBAAiB,yBAA0BS,CAAK,EAC1BF,EAAA,EAEtB,IAAM,OACJP,EAAA,oBAAoB,yBAA0BS,CAAK,GAC1DC,EAAAV,EAAO,OAAP,MAAAU,EAAa,YACf,CAAA,CACF,EACC,CAACV,CAAM,CAAC,EAEJ,CACL,UAAAP,EACA,UAAAI,EACA,OAAAG,EACA,cAAAI,EACA,OAAAF,CACF,CACF"}
1
+ {"version":3,"file":"useBluetooth.cjs","sources":["../../../../src/hooks/useBluetooth/useBluetooth.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\n/** The use bluetooth return type */\nexport interface UseBluetoothReturn {\n /** Indicates if bluetooth device is currently connected */\n connected: boolean;\n /** Describe connected bluetooth device */\n device?: BluetoothDevice;\n /** The GATT server for connected bluetooth device */\n server?: BluetoothRemoteGATTServer;\n /** Whether the bluetooth is supported*/\n supported: boolean;\n /** Function to request bluetooth device from the user */\n requestDevice: () => Promise<void>;\n}\n\n/** The use bluetooth options type */\nexport interface UseBluetoothOptions {\n /** The options to request all bluetooth devices */\n acceptAllDevices?: boolean;\n /** Array of filters to apply when scanning bluetooth devices */\n filters?: BluetoothLEScanFilter[];\n /** Array of optional services that the application can use */\n optionalServices?: BluetoothServiceUUID[];\n}\n\n/**\n * @name useBluetooth\n * @description - Hook for getting information about bluetooth\n * @category Browser\n *\n * @browserapi navigator.bluetooth https://developer.mozilla.org/en-US/docs/Web/API/Navigator/bluetooth\n *\n * @param {boolean} [options.acceptAllDevices=false] The options to request all Bluetooth devices\n * @param {Array<BluetoothLEScanFilter>} [options.filters] Array of filters to apply when scanning Bluetooth devices\n * @param {Array<BluetoothServiceUUID>} [options.optionalServices] Array of optional services that the application can use\n * @returns {UseBluetoothReturn} Object containing battery information & Battery API support\n *\n * @example\n * const { supported, connected, device, requestDevice, server } = useBluetooth(options);\n */\nexport const useBluetooth = (options?: UseBluetoothOptions): UseBluetoothReturn => {\n const supported = typeof navigator !== 'undefined' && 'bluetooth' in navigator;\n const { acceptAllDevices = false, filters, optionalServices } = options ?? {};\n\n const [connected, setIsConnected] = useState(false);\n const [device, setDevice] = useState<BluetoothDevice | undefined>(undefined);\n const [server, setServer] = useState<BluetoothRemoteGATTServer | undefined>(undefined);\n\n const requestDevice = async () => {\n if (!supported) return;\n\n const selectedDevice = await navigator.bluetooth.requestDevice({\n acceptAllDevices,\n optionalServices,\n ...(filters && { filters, acceptAllDevices: false })\n });\n\n setDevice(selectedDevice);\n };\n\n useEffect(() => {\n if (device && device.gatt) {\n const connectToBluetoothGATTServer = async () => {\n if (!device.gatt) return;\n const gattServer = await device.gatt.connect();\n setServer(gattServer);\n setIsConnected(gattServer.connected);\n };\n\n const reset = () => {\n setServer(undefined);\n setDevice(undefined);\n setIsConnected(false);\n };\n\n device.addEventListener('gattserverdisconnected', reset);\n connectToBluetoothGATTServer();\n\n return () => {\n device.removeEventListener('gattserverdisconnected', reset);\n device.gatt?.disconnect();\n };\n }\n }, [device]);\n\n return {\n supported,\n connected,\n device,\n requestDevice,\n server\n };\n};\n"],"names":["useBluetooth","options","supported","acceptAllDevices","filters","optionalServices","connected","setIsConnected","useState","device","setDevice","server","setServer","requestDevice","selectedDevice","useEffect","connectToBluetoothGATTServer","gattServer","reset"],"mappings":"yGAyCaA,EAAgBC,GAAsD,CACjF,MAAMC,EAAY,OAAO,UAAc,KAAe,cAAe,UAC/D,CAAE,iBAAAC,EAAmB,GAAO,QAAAC,EAAS,iBAAAC,CAAA,EAAqBJ,GAAW,CAAA,EAErE,CAACK,EAAWC,CAAc,EAAIC,EAAAA,SAAS,EAAK,EAC5C,CAACC,EAAQC,CAAS,EAAIF,EAAAA,SAAsC,MAAS,EACrE,CAACG,EAAQC,CAAS,EAAIJ,EAAAA,SAAgD,MAAS,EAE/EK,EAAgB,SAAY,CAChC,GAAI,CAACX,EAAW,OAEhB,MAAMY,EAAiB,MAAM,UAAU,UAAU,cAAc,CAC7D,iBAAAX,EACA,iBAAAE,EACA,GAAID,GAAW,CAAE,QAAAA,EAAS,iBAAkB,EAAA,CAAM,CACnD,EAEDM,EAAUI,CAAc,CAAA,EAG1BC,OAAAA,EAAAA,UAAU,IAAM,CACd,GAAIN,GAAUA,EAAO,KAAM,CACzB,MAAMO,EAA+B,SAAY,CAC/C,GAAI,CAACP,EAAO,KAAM,OAClB,MAAMQ,EAAa,MAAMR,EAAO,KAAK,QAAA,EACrCG,EAAUK,CAAU,EACpBV,EAAeU,EAAW,SAAS,CAAA,EAG/BC,EAAQ,IAAM,CAClBN,EAAU,MAAS,EACnBF,EAAU,MAAS,EACnBH,EAAe,EAAK,CAAA,EAGtB,OAAAE,EAAO,iBAAiB,yBAA0BS,CAAK,EACvDF,EAAA,EAEO,IAAM,CACXP,EAAO,oBAAoB,yBAA0BS,CAAK,EAC1DT,EAAO,MAAM,WAAA,CAAW,CAC1B,CACF,EACC,CAACA,CAAM,CAAC,EAEJ,CACL,UAAAP,EACA,UAAAI,EACA,OAAAG,EACA,cAAAI,EACA,OAAAF,CAAA,CAEJ"}
@@ -1 +1 @@
1
- {"version":3,"file":"useBoolean.cjs","sources":["../../../../src/hooks/useBoolean/useBoolean.ts"],"sourcesContent":["import { useState } from 'react';\n\n/** The use boolean return type */\nexport type UseBooleanReturn = [\n /** The current boolean state value */\n value: boolean,\n /** Function to toggle the boolean state */\n toggle: (value?: boolean) => void\n];\n\n/**\n * @name useBoolean\n * @description - Hook provides opportunity to manage boolean state\n * @category Utilities\n *\n * @param {boolean} [initialValue=false] The initial boolean value\n * @returns {UseBooleanReturn} An object containing the boolean state value and utility functions to manipulate the state\n *\n * @example\n * const [on, toggle] = useBoolean()\n */\nexport const useBoolean = (initialValue = false): UseBooleanReturn => {\n const [value, setValue] = useState(initialValue);\n const toggle = (value?: boolean) => setValue((prevValue) => value ?? !prevValue);\n\n return [value, toggle];\n};\n"],"names":["useBoolean","initialValue","value","setValue","useState","prevValue"],"mappings":"yGAqBaA,EAAa,CAACC,EAAe,KAA4B,CACpE,KAAM,CAACC,EAAOC,CAAQ,EAAIC,EAAAA,SAASH,CAAY,EAGxC,MAAA,CAACC,EAFQA,GAAoBC,EAAUE,GAAcH,GAAS,CAACG,CAAS,CAE1D,CACvB"}
1
+ {"version":3,"file":"useBoolean.cjs","sources":["../../../../src/hooks/useBoolean/useBoolean.ts"],"sourcesContent":["import { useState } from 'react';\n\n/** The use boolean return type */\nexport type UseBooleanReturn = [\n /** The current boolean state value */\n value: boolean,\n /** Function to toggle the boolean state */\n toggle: (value?: boolean) => void\n];\n\n/**\n * @name useBoolean\n * @description - Hook provides opportunity to manage boolean state\n * @category Utilities\n *\n * @param {boolean} [initialValue=false] The initial boolean value\n * @returns {UseBooleanReturn} An object containing the boolean state value and utility functions to manipulate the state\n *\n * @example\n * const [on, toggle] = useBoolean()\n */\nexport const useBoolean = (initialValue = false): UseBooleanReturn => {\n const [value, setValue] = useState(initialValue);\n const toggle = (value?: boolean) => setValue((prevValue) => value ?? !prevValue);\n\n return [value, toggle];\n};\n"],"names":["useBoolean","initialValue","value","setValue","useState","prevValue"],"mappings":"yGAqBaA,EAAa,CAACC,EAAe,KAA4B,CACpE,KAAM,CAACC,EAAOC,CAAQ,EAAIC,EAAAA,SAASH,CAAY,EAG/C,MAAO,CAACC,EAFQA,GAAoBC,EAAUE,GAAcH,GAAS,CAACG,CAAS,CAE1D,CACvB"}
@@ -1 +1 @@
1
- {"version":3,"file":"useBreakpoints.cjs","sources":["../../../../src/hooks/useBreakpoints/useBreakpoints.ts"],"sourcesContent":["import { useEffect } from 'react';\n\nimport { useRerender } from '../useRerender/useRerender';\n\n/** The breakpoints type */\nexport type Breakpoints<Breakpoint extends string = string> = Record<Breakpoint, number>;\n\n/** The use breakpoints strategy */\nexport type UseBreakpointsStrategy = 'desktop-first' | 'mobile-first';\n\nconst match = (query: string) => window.matchMedia(query).matches;\n\n/** The use breakpoints return type */\nexport type UseBreakpointsReturn<Breakpoint extends string = string> = {\n /** The function that checks if the current breakpoint is greater than to the given breakpoint */\n greater: (breakpoint: Breakpoint) => boolean;\n /** The function that checks if the current breakpoint is greater than or equal to the given breakpoint */\n greaterOrEqual: (breakpoint: Breakpoint) => boolean;\n /** The function that checks if the current breakpoint is smaller than to the given breakpoint */\n smaller: (breakpoint: Breakpoint) => boolean;\n /** The function that checks if the current breakpoint is smaller than or equal to the given breakpoint */\n smallerOrEqual: (breakpoint: Breakpoint) => boolean;\n /** The function that checks if the current breakpoint is between to the given breakpoints */\n between: (a: Breakpoint, b: Breakpoint) => boolean;\n /** The function that checks if the current breakpoint is greater than to the given breakpoint */\n isGreater: (breakpoint: Breakpoint) => boolean;\n /** The function that checks if the current breakpoint is greater than or equal to the given breakpoint */\n isGreaterOrEqual: (breakpoint: Breakpoint) => boolean;\n /** The function that checks if the current breakpoint is smaller than to the given breakpoint */\n isSmaller: (breakpoint: Breakpoint) => boolean;\n /** The function that checks if the current breakpoint is smaller than or equal to the given breakpoint */\n isSmallerOrEqual: (breakpoint: Breakpoint) => boolean;\n /** The function that checks if the current breakpoint is between to the given breakpoints */\n isInBetween: (a: Breakpoint, b: Breakpoint) => boolean;\n /** The function that returns the current breakpoints */\n current: () => Breakpoint[];\n /** The function that returns the current active breakpoint */\n active: () => Breakpoint;\n} & Record<Breakpoint, boolean>;\n\n/**\n * @name useBreakpoints\n * @description - Hook that manages breakpoints\n * @category Browser\n *\n * @template {string} Breakpoint The name of the breakpoint\n * @param {Breakpoints<Breakpoint>} breakpoints The breakpoints to use\n * @param {UseBreakpointsStrategy} [strategy=min-width] The strategy to use for matching\n * @returns {UseBreakpointsReturn<Breakpoint>} An object containing the current breakpoint\n *\n * @example\n * const { greaterOrEqual, smallerOrEqual, current } = useBreakpoints({ mobile: 0, tablet: 640, laptop: 1024, desktop: 1280 });\n */\nexport const useBreakpoints = <Breakpoint extends string>(\n breakpoints: Breakpoints<Breakpoint>,\n strategy: UseBreakpointsStrategy = 'mobile-first'\n): UseBreakpointsReturn<Breakpoint> => {\n const rerender = useRerender();\n\n const getValue = (breakpoint: Breakpoint, delta?: number) => {\n if (delta) return `${Number(breakpoints[breakpoint]) + delta}px`;\n return `${breakpoints[breakpoint]}px`;\n };\n\n useEffect(() => {\n const onResize = () => rerender();\n window.addEventListener('resize', onResize);\n return () => {\n window.removeEventListener('resize', onResize);\n };\n }, []);\n\n const greaterOrEqual = (breakpoint: Breakpoint) => match(`(min-width: ${getValue(breakpoint)})`);\n const smallerOrEqual = (breakpoint: Breakpoint) => match(`(max-width: ${getValue(breakpoint)})`);\n const current = () =>\n Object.keys(breakpoints)\n .map((breakpoint) => [breakpoint, greaterOrEqual(breakpoint as Breakpoint)])\n .filter(([, value]) => value)\n .map(([breakpoint]) => breakpoint) as Breakpoint[];\n const active = () => {\n const breakpoints = current();\n return (breakpoints.length ? breakpoints.at(-1) : undefined) as Breakpoint;\n };\n\n const greater = (breakpoint: Breakpoint) => match(`(min-width: ${getValue(breakpoint, 0.1)})`);\n const smaller = (breakpoint: Breakpoint) => match(`(max-width: ${getValue(breakpoint, -0.1)})`);\n const between = (a: Breakpoint, b: Breakpoint) =>\n match(`(min-width: ${getValue(a)}) and (max-width: ${getValue(b, -0.1)})`);\n\n const breakpointsKeys = (Object.keys(breakpoints) as Breakpoint[]).reduce(\n (acc, breakpoint) => {\n const value =\n strategy === 'mobile-first' ? greaterOrEqual(breakpoint) : smallerOrEqual(breakpoint);\n acc[breakpoint] = value;\n return acc;\n },\n {} as Record<Breakpoint, boolean>\n );\n\n return {\n current,\n greaterOrEqual,\n smallerOrEqual,\n active,\n greater,\n smaller,\n between,\n isGreater: greater,\n isGreaterOrEqual: greaterOrEqual,\n isSmaller: smaller,\n isSmallerOrEqual: smallerOrEqual,\n isInBetween: between,\n ...breakpointsKeys\n };\n};\n\n/** Breakpoints from Material UI */\nexport const BREAKPOINTS_MATERIAL_UI = {\n xs: 0,\n sm: 600,\n md: 900,\n lg: 1200,\n xl: 1536\n};\n\n/** Breakpoints from Mantine */\nexport const BREAKPOINTS_MANTINE = {\n xs: 576,\n sm: 768,\n md: 992,\n lg: 1200,\n xl: 1408\n};\n\n/** Breakpoints from Tailwind */\nexport const BREAKPOINTS_TAILWIND = {\n sm: 640,\n md: 768,\n lg: 1024,\n xl: 1280,\n '2xl': 1536\n};\n\n/** Breakpoints from Bootstrap V5 */\nexport const BREAKPOINTS_BOOTSTRAP_V5 = {\n xs: 0,\n sm: 576,\n md: 768,\n lg: 992,\n xl: 1200,\n xxl: 1400\n};\n\n/** Breakpoints from Ant Design */\nexport const BREAKPOINTS_ANT_DESIGN = {\n xs: 480,\n sm: 576,\n md: 768,\n lg: 992,\n xl: 1200,\n xxl: 1600\n};\n\n/** Breakpoints from Quasar V2 */\nexport const BREAKPOINTS_QUASAR_V2 = {\n xs: 0,\n sm: 600,\n md: 1024,\n lg: 1440,\n xl: 1920\n};\n\n/** Sematic Breakpoints */\nexport const BREAKPOINTS_SEMANTIC = {\n mobileS: 320,\n mobileM: 375,\n mobileL: 425,\n tablet: 768,\n laptop: 1024,\n laptopL: 1440,\n desktop4K: 2560\n};\n\n/** Breakpoints from Master CSS */\nexport const BREAKPOINTS_MASTER_CSS = {\n '3xs': 360,\n '2xs': 480,\n xs: 600,\n sm: 768,\n md: 1024,\n lg: 1280,\n xl: 1440,\n '2xl': 1600,\n '3xl': 1920,\n '4xl': 2560\n};\n\n/** Breakpoints from PrimeFlex */\nexport const BREAKPOINTS_PRIME_FLEX = {\n sm: 576,\n md: 768,\n lg: 992,\n xl: 1200\n};\n"],"names":["match","query","useBreakpoints","breakpoints","strategy","rerender","useRerender","getValue","breakpoint","delta","useEffect","onResize","greaterOrEqual","smallerOrEqual","current","value","active","greater","smaller","between","a","b","breakpointsKeys","acc","BREAKPOINTS_MATERIAL_UI","BREAKPOINTS_MANTINE","BREAKPOINTS_TAILWIND","BREAKPOINTS_BOOTSTRAP_V5","BREAKPOINTS_ANT_DESIGN","BREAKPOINTS_QUASAR_V2","BREAKPOINTS_SEMANTIC","BREAKPOINTS_MASTER_CSS","BREAKPOINTS_PRIME_FLEX"],"mappings":"qJAUMA,EAASC,GAAkB,OAAO,WAAWA,CAAK,EAAE,QA2C7CC,EAAiB,CAC5BC,EACAC,EAAmC,iBACE,CACrC,MAAMC,EAAWC,EAAAA,YAAY,EAEvBC,EAAW,CAACC,EAAwBC,IACpCA,EAAc,GAAG,OAAON,EAAYK,CAAU,CAAC,EAAIC,CAAK,KACrD,GAAGN,EAAYK,CAAU,CAAC,KAGnCE,EAAAA,UAAU,IAAM,CACR,MAAAC,EAAW,IAAMN,EAAS,EACzB,cAAA,iBAAiB,SAAUM,CAAQ,EACnC,IAAM,CACJ,OAAA,oBAAoB,SAAUA,CAAQ,CAC/C,CACF,EAAG,EAAE,EAEC,MAAAC,EAAkBJ,GAA2BR,EAAM,eAAeO,EAASC,CAAU,CAAC,GAAG,EACzFK,EAAkBL,GAA2BR,EAAM,eAAeO,EAASC,CAAU,CAAC,GAAG,EACzFM,EAAU,IACd,OAAO,KAAKX,CAAW,EACpB,IAAKK,GAAe,CAACA,EAAYI,EAAeJ,CAAwB,CAAC,CAAC,EAC1E,OAAO,CAAC,CAAG,CAAAO,CAAK,IAAMA,CAAK,EAC3B,IAAI,CAAC,CAACP,CAAU,IAAMA,CAAU,EAC/BQ,EAAS,IAAM,CACnB,MAAMb,EAAcW,EAAQ,EAC5B,OAAQX,EAAY,OAASA,EAAY,GAAG,EAAE,EAAI,MACpD,EAEMc,EAAWT,GAA2BR,EAAM,eAAeO,EAASC,EAAY,EAAG,CAAC,GAAG,EACvFU,EAAWV,GAA2BR,EAAM,eAAeO,EAASC,EAAY,GAAI,CAAC,GAAG,EACxFW,EAAU,CAACC,EAAeC,IAC9BrB,EAAM,eAAeO,EAASa,CAAC,CAAC,qBAAqBb,EAASc,EAAG,GAAI,CAAC,GAAG,EAErEC,EAAmB,OAAO,KAAKnB,CAAW,EAAmB,OACjE,CAACoB,EAAKf,IAAe,CACnB,MAAMO,EACJX,IAAa,eAAiBQ,EAAeJ,CAAU,EAAIK,EAAeL,CAAU,EACtF,OAAAe,EAAIf,CAAU,EAAIO,EACXQ,CACT,EACA,CAAA,CACF,EAEO,MAAA,CACL,QAAAT,EACA,eAAAF,EACA,eAAAC,EACA,OAAAG,EACA,QAAAC,EACA,QAAAC,EACA,QAAAC,EACA,UAAWF,EACX,iBAAkBL,EAClB,UAAWM,EACX,iBAAkBL,EAClB,YAAaM,EACb,GAAGG,CACL,CACF,EAGaE,EAA0B,CACrC,GAAI,EACJ,GAAI,IACJ,GAAI,IACJ,GAAI,KACJ,GAAI,IACN,EAGaC,EAAsB,CACjC,GAAI,IACJ,GAAI,IACJ,GAAI,IACJ,GAAI,KACJ,GAAI,IACN,EAGaC,EAAuB,CAClC,GAAI,IACJ,GAAI,IACJ,GAAI,KACJ,GAAI,KACJ,MAAO,IACT,EAGaC,EAA2B,CACtC,GAAI,EACJ,GAAI,IACJ,GAAI,IACJ,GAAI,IACJ,GAAI,KACJ,IAAK,IACP,EAGaC,EAAyB,CACpC,GAAI,IACJ,GAAI,IACJ,GAAI,IACJ,GAAI,IACJ,GAAI,KACJ,IAAK,IACP,EAGaC,EAAwB,CACnC,GAAI,EACJ,GAAI,IACJ,GAAI,KACJ,GAAI,KACJ,GAAI,IACN,EAGaC,EAAuB,CAClC,QAAS,IACT,QAAS,IACT,QAAS,IACT,OAAQ,IACR,OAAQ,KACR,QAAS,KACT,UAAW,IACb,EAGaC,EAAyB,CACpC,MAAO,IACP,MAAO,IACP,GAAI,IACJ,GAAI,IACJ,GAAI,KACJ,GAAI,KACJ,GAAI,KACJ,MAAO,KACP,MAAO,KACP,MAAO,IACT,EAGaC,EAAyB,CACpC,GAAI,IACJ,GAAI,IACJ,GAAI,IACJ,GAAI,IACN"}
1
+ {"version":3,"file":"useBreakpoints.cjs","sources":["../../../../src/hooks/useBreakpoints/useBreakpoints.ts"],"sourcesContent":["import { useEffect } from 'react';\n\nimport { useRerender } from '../useRerender/useRerender';\n\n/** The breakpoints type */\nexport type Breakpoints<Breakpoint extends string = string> = Record<Breakpoint, number>;\n\n/** The use breakpoints strategy */\nexport type UseBreakpointsStrategy = 'desktop-first' | 'mobile-first';\n\nconst match = (query: string) => window.matchMedia(query).matches;\n\n/** The use breakpoints return type */\nexport type UseBreakpointsReturn<Breakpoint extends string = string> = {\n /** The function that checks if the current breakpoint is greater than to the given breakpoint */\n greater: (breakpoint: Breakpoint) => boolean;\n /** The function that checks if the current breakpoint is greater than or equal to the given breakpoint */\n greaterOrEqual: (breakpoint: Breakpoint) => boolean;\n /** The function that checks if the current breakpoint is smaller than to the given breakpoint */\n smaller: (breakpoint: Breakpoint) => boolean;\n /** The function that checks if the current breakpoint is smaller than or equal to the given breakpoint */\n smallerOrEqual: (breakpoint: Breakpoint) => boolean;\n /** The function that checks if the current breakpoint is between to the given breakpoints */\n between: (a: Breakpoint, b: Breakpoint) => boolean;\n /** The function that checks if the current breakpoint is greater than to the given breakpoint */\n isGreater: (breakpoint: Breakpoint) => boolean;\n /** The function that checks if the current breakpoint is greater than or equal to the given breakpoint */\n isGreaterOrEqual: (breakpoint: Breakpoint) => boolean;\n /** The function that checks if the current breakpoint is smaller than to the given breakpoint */\n isSmaller: (breakpoint: Breakpoint) => boolean;\n /** The function that checks if the current breakpoint is smaller than or equal to the given breakpoint */\n isSmallerOrEqual: (breakpoint: Breakpoint) => boolean;\n /** The function that checks if the current breakpoint is between to the given breakpoints */\n isInBetween: (a: Breakpoint, b: Breakpoint) => boolean;\n /** The function that returns the current breakpoints */\n current: () => Breakpoint[];\n /** The function that returns the current active breakpoint */\n active: () => Breakpoint;\n} & Record<Breakpoint, boolean>;\n\n/**\n * @name useBreakpoints\n * @description - Hook that manages breakpoints\n * @category Browser\n *\n * @template {string} Breakpoint The name of the breakpoint\n * @param {Breakpoints<Breakpoint>} breakpoints The breakpoints to use\n * @param {UseBreakpointsStrategy} [strategy=min-width] The strategy to use for matching\n * @returns {UseBreakpointsReturn<Breakpoint>} An object containing the current breakpoint\n *\n * @example\n * const { greaterOrEqual, smallerOrEqual, current } = useBreakpoints({ mobile: 0, tablet: 640, laptop: 1024, desktop: 1280 });\n */\nexport const useBreakpoints = <Breakpoint extends string>(\n breakpoints: Breakpoints<Breakpoint>,\n strategy: UseBreakpointsStrategy = 'mobile-first'\n): UseBreakpointsReturn<Breakpoint> => {\n const rerender = useRerender();\n\n const getValue = (breakpoint: Breakpoint, delta?: number) => {\n if (delta) return `${Number(breakpoints[breakpoint]) + delta}px`;\n return `${breakpoints[breakpoint]}px`;\n };\n\n useEffect(() => {\n const onResize = () => rerender();\n window.addEventListener('resize', onResize);\n return () => {\n window.removeEventListener('resize', onResize);\n };\n }, []);\n\n const greaterOrEqual = (breakpoint: Breakpoint) => match(`(min-width: ${getValue(breakpoint)})`);\n const smallerOrEqual = (breakpoint: Breakpoint) => match(`(max-width: ${getValue(breakpoint)})`);\n const current = () =>\n Object.keys(breakpoints)\n .map((breakpoint) => [breakpoint, greaterOrEqual(breakpoint as Breakpoint)])\n .filter(([, value]) => value)\n .map(([breakpoint]) => breakpoint) as Breakpoint[];\n const active = () => {\n const breakpoints = current();\n return (breakpoints.length ? breakpoints.at(-1) : undefined) as Breakpoint;\n };\n\n const greater = (breakpoint: Breakpoint) => match(`(min-width: ${getValue(breakpoint, 0.1)})`);\n const smaller = (breakpoint: Breakpoint) => match(`(max-width: ${getValue(breakpoint, -0.1)})`);\n const between = (a: Breakpoint, b: Breakpoint) =>\n match(`(min-width: ${getValue(a)}) and (max-width: ${getValue(b, -0.1)})`);\n\n const breakpointsKeys = (Object.keys(breakpoints) as Breakpoint[]).reduce(\n (acc, breakpoint) => {\n const value =\n strategy === 'mobile-first' ? greaterOrEqual(breakpoint) : smallerOrEqual(breakpoint);\n acc[breakpoint] = value;\n return acc;\n },\n {} as Record<Breakpoint, boolean>\n );\n\n return {\n current,\n greaterOrEqual,\n smallerOrEqual,\n active,\n greater,\n smaller,\n between,\n isGreater: greater,\n isGreaterOrEqual: greaterOrEqual,\n isSmaller: smaller,\n isSmallerOrEqual: smallerOrEqual,\n isInBetween: between,\n ...breakpointsKeys\n };\n};\n\n/** Breakpoints from Material UI */\nexport const BREAKPOINTS_MATERIAL_UI = {\n xs: 0,\n sm: 600,\n md: 900,\n lg: 1200,\n xl: 1536\n};\n\n/** Breakpoints from Mantine */\nexport const BREAKPOINTS_MANTINE = {\n xs: 576,\n sm: 768,\n md: 992,\n lg: 1200,\n xl: 1408\n};\n\n/** Breakpoints from Tailwind */\nexport const BREAKPOINTS_TAILWIND = {\n sm: 640,\n md: 768,\n lg: 1024,\n xl: 1280,\n '2xl': 1536\n};\n\n/** Breakpoints from Bootstrap V5 */\nexport const BREAKPOINTS_BOOTSTRAP_V5 = {\n xs: 0,\n sm: 576,\n md: 768,\n lg: 992,\n xl: 1200,\n xxl: 1400\n};\n\n/** Breakpoints from Ant Design */\nexport const BREAKPOINTS_ANT_DESIGN = {\n xs: 480,\n sm: 576,\n md: 768,\n lg: 992,\n xl: 1200,\n xxl: 1600\n};\n\n/** Breakpoints from Quasar V2 */\nexport const BREAKPOINTS_QUASAR_V2 = {\n xs: 0,\n sm: 600,\n md: 1024,\n lg: 1440,\n xl: 1920\n};\n\n/** Sematic Breakpoints */\nexport const BREAKPOINTS_SEMANTIC = {\n mobileS: 320,\n mobileM: 375,\n mobileL: 425,\n tablet: 768,\n laptop: 1024,\n laptopL: 1440,\n desktop4K: 2560\n};\n\n/** Breakpoints from Master CSS */\nexport const BREAKPOINTS_MASTER_CSS = {\n '3xs': 360,\n '2xs': 480,\n xs: 600,\n sm: 768,\n md: 1024,\n lg: 1280,\n xl: 1440,\n '2xl': 1600,\n '3xl': 1920,\n '4xl': 2560\n};\n\n/** Breakpoints from PrimeFlex */\nexport const BREAKPOINTS_PRIME_FLEX = {\n sm: 576,\n md: 768,\n lg: 992,\n xl: 1200\n};\n"],"names":["match","query","useBreakpoints","breakpoints","strategy","rerender","useRerender","getValue","breakpoint","delta","useEffect","onResize","greaterOrEqual","smallerOrEqual","current","value","active","greater","smaller","between","a","b","breakpointsKeys","acc","BREAKPOINTS_MATERIAL_UI","BREAKPOINTS_MANTINE","BREAKPOINTS_TAILWIND","BREAKPOINTS_BOOTSTRAP_V5","BREAKPOINTS_ANT_DESIGN","BREAKPOINTS_QUASAR_V2","BREAKPOINTS_SEMANTIC","BREAKPOINTS_MASTER_CSS","BREAKPOINTS_PRIME_FLEX"],"mappings":"qJAUMA,EAASC,GAAkB,OAAO,WAAWA,CAAK,EAAE,QA2C7CC,EAAiB,CAC5BC,EACAC,EAAmC,iBACE,CACrC,MAAMC,EAAWC,EAAAA,YAAA,EAEXC,EAAW,CAACC,EAAwBC,IACpCA,EAAc,GAAG,OAAON,EAAYK,CAAU,CAAC,EAAIC,CAAK,KACrD,GAAGN,EAAYK,CAAU,CAAC,KAGnCE,EAAAA,UAAU,IAAM,CACd,MAAMC,EAAW,IAAMN,EAAA,EACvB,cAAO,iBAAiB,SAAUM,CAAQ,EACnC,IAAM,CACX,OAAO,oBAAoB,SAAUA,CAAQ,CAAA,CAC/C,EACC,EAAE,EAEL,MAAMC,EAAkBJ,GAA2BR,EAAM,eAAeO,EAASC,CAAU,CAAC,GAAG,EACzFK,EAAkBL,GAA2BR,EAAM,eAAeO,EAASC,CAAU,CAAC,GAAG,EACzFM,EAAU,IACd,OAAO,KAAKX,CAAW,EACpB,IAAKK,GAAe,CAACA,EAAYI,EAAeJ,CAAwB,CAAC,CAAC,EAC1E,OAAO,CAAC,CAAA,CAAGO,CAAK,IAAMA,CAAK,EAC3B,IAAI,CAAC,CAACP,CAAU,IAAMA,CAAU,EAC/BQ,EAAS,IAAM,CACnB,MAAMb,EAAcW,EAAA,EACpB,OAAQX,EAAY,OAASA,EAAY,GAAG,EAAE,EAAI,MAAA,EAG9Cc,EAAWT,GAA2BR,EAAM,eAAeO,EAASC,EAAY,EAAG,CAAC,GAAG,EACvFU,EAAWV,GAA2BR,EAAM,eAAeO,EAASC,EAAY,GAAI,CAAC,GAAG,EACxFW,EAAU,CAACC,EAAeC,IAC9BrB,EAAM,eAAeO,EAASa,CAAC,CAAC,qBAAqBb,EAASc,EAAG,GAAI,CAAC,GAAG,EAErEC,EAAmB,OAAO,KAAKnB,CAAW,EAAmB,OACjE,CAACoB,EAAKf,IAAe,CACnB,MAAMO,EACJX,IAAa,eAAiBQ,EAAeJ,CAAU,EAAIK,EAAeL,CAAU,EACtF,OAAAe,EAAIf,CAAU,EAAIO,EACXQ,CAAA,EAET,CAAA,CAAC,EAGH,MAAO,CACL,QAAAT,EACA,eAAAF,EACA,eAAAC,EACA,OAAAG,EACA,QAAAC,EACA,QAAAC,EACA,QAAAC,EACA,UAAWF,EACX,iBAAkBL,EAClB,UAAWM,EACX,iBAAkBL,EAClB,YAAaM,EACb,GAAGG,CAAA,CAEP,EAGaE,EAA0B,CACrC,GAAI,EACJ,GAAI,IACJ,GAAI,IACJ,GAAI,KACJ,GAAI,IACN,EAGaC,EAAsB,CACjC,GAAI,IACJ,GAAI,IACJ,GAAI,IACJ,GAAI,KACJ,GAAI,IACN,EAGaC,EAAuB,CAClC,GAAI,IACJ,GAAI,IACJ,GAAI,KACJ,GAAI,KACJ,MAAO,IACT,EAGaC,EAA2B,CACtC,GAAI,EACJ,GAAI,IACJ,GAAI,IACJ,GAAI,IACJ,GAAI,KACJ,IAAK,IACP,EAGaC,EAAyB,CACpC,GAAI,IACJ,GAAI,IACJ,GAAI,IACJ,GAAI,IACJ,GAAI,KACJ,IAAK,IACP,EAGaC,EAAwB,CACnC,GAAI,EACJ,GAAI,IACJ,GAAI,KACJ,GAAI,KACJ,GAAI,IACN,EAGaC,EAAuB,CAClC,QAAS,IACT,QAAS,IACT,QAAS,IACT,OAAQ,IACR,OAAQ,KACR,QAAS,KACT,UAAW,IACb,EAGaC,EAAyB,CACpC,MAAO,IACP,MAAO,IACP,GAAI,IACJ,GAAI,IACJ,GAAI,KACJ,GAAI,KACJ,GAAI,KACJ,MAAO,KACP,MAAO,KACP,MAAO,IACT,EAGaC,EAAyB,CACpC,GAAI,IACJ,GAAI,IACJ,GAAI,IACJ,GAAI,IACN"}
@@ -1 +1 @@
1
- {"version":3,"file":"useBrowserLanguage.cjs","sources":["../../../../src/hooks/useBrowserLanguage/useBrowserLanguage.ts"],"sourcesContent":["import { useSyncExternalStore } from 'react';\n\nconst getSnapshot = () => navigator.language;\nconst getServerSnapshot = () => 'undetermined';\nconst subscribe = (callback: () => void) => {\n window.addEventListener('languagechange', callback);\n return () => window.removeEventListener('languagechange', callback);\n};\n\n/**\n * @name useBrowserLanguage\n * @description - Hook that returns the current browser language\n * @category Browser\n *\n * @browserapi navigator.language https://developer.mozilla.org/en-US/docs/Web/API/Navigator/language\n *\n * @returns {string} The current browser language\n *\n * @example\n * const browserLanguage = useBrowserLanguage();\n */\nexport const useBrowserLanguage = () =>\n useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);\n"],"names":["getSnapshot","getServerSnapshot","subscribe","callback","useBrowserLanguage","useSyncExternalStore"],"mappings":"yGAEMA,EAAc,IAAM,UAAU,SAC9BC,EAAoB,IAAM,eAC1BC,EAAaC,IACV,OAAA,iBAAiB,iBAAkBA,CAAQ,EAC3C,IAAM,OAAO,oBAAoB,iBAAkBA,CAAQ,GAevDC,EAAqB,IAChCC,EAAAA,qBAAqBH,EAAWF,EAAaC,CAAiB"}
1
+ {"version":3,"file":"useBrowserLanguage.cjs","sources":["../../../../src/hooks/useBrowserLanguage/useBrowserLanguage.ts"],"sourcesContent":["import { useSyncExternalStore } from 'react';\n\nconst getSnapshot = () => navigator.language;\nconst getServerSnapshot = () => 'undetermined';\nconst subscribe = (callback: () => void) => {\n window.addEventListener('languagechange', callback);\n return () => window.removeEventListener('languagechange', callback);\n};\n\n/**\n * @name useBrowserLanguage\n * @description - Hook that returns the current browser language\n * @category Browser\n *\n * @browserapi navigator.language https://developer.mozilla.org/en-US/docs/Web/API/Navigator/language\n *\n * @returns {string} The current browser language\n *\n * @example\n * const browserLanguage = useBrowserLanguage();\n */\nexport const useBrowserLanguage = () =>\n useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);\n"],"names":["getSnapshot","getServerSnapshot","subscribe","callback","useBrowserLanguage","useSyncExternalStore"],"mappings":"yGAEMA,EAAc,IAAM,UAAU,SAC9BC,EAAoB,IAAM,eAC1BC,EAAaC,IACjB,OAAO,iBAAiB,iBAAkBA,CAAQ,EAC3C,IAAM,OAAO,oBAAoB,iBAAkBA,CAAQ,GAevDC,EAAqB,IAChCC,EAAAA,qBAAqBH,EAAWF,EAAaC,CAAiB"}
@@ -1 +1 @@
1
- {"version":3,"file":"useClickOutside.cjs","sources":["../../../../src/hooks/useClickOutside/useClickOutside.ts"],"sourcesContent":["import { useEffect, useRef } 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\nexport interface UseClickOutside {\n (target: HookTarget, callback: (event: Event) => void): void;\n\n <Target extends Element>(callback: (event: Event) => void, target?: never): StateRef<Target>;\n}\n\n/**\n * @name useClickOutside\n * @description - Hook to handle click events outside the specified target element(s)\n * @category Sensors\n *\n * @overload\n * @param {HookTarget} target The target element(s) to detect outside clicks for\n * @param {(event: Event) => void} callback The callback to execute when a click outside the target is detected\n * @returns {void}\n *\n * @example\n * useClickOutside(ref, () => console.log('click outside'));\n *\n * @overload\n * @template Target The target element(s)\n * @param {(event: Event) => void} callback The callback to execute when a click outside the target is detected\n * @returns {(node: Target) => void} A React ref to attach to the target element\n *\n * @example\n * const ref = useClickOutside<HTMLDivElement>(() => console.log('click outside'));\n *\n * @see {@link https://siberiacancode.github.io/reactuse/functions/hooks/useClickOutside.html}\n */\nexport const useClickOutside = ((...params: any[]) => {\n const target = (isTarget(params[0]) ? params[0] : undefined) as HookTarget | undefined;\n const callback = (params[1] ? params[1] : params[0]) as (event: Event) => void;\n\n const internalRef = useRefState<Element>();\n const internalCallbackRef = useRef(callback);\n internalCallbackRef.current = callback;\n\n useEffect(() => {\n if (!target && !internalRef.state) return;\n const onClick = (event: Event) => {\n const element = (target ? getElement(target) : internalRef.current) as Element;\n\n if (element && !element.contains(event.target as Node)) {\n internalCallbackRef.current(event);\n }\n };\n\n document.addEventListener('click', onClick);\n\n return () => {\n document.removeEventListener('click', onClick);\n };\n }, [target, internalRef.state]);\n\n if (target) return;\n return internalRef;\n}) as UseClickOutside;\n"],"names":["useClickOutside","params","target","isTarget","callback","internalRef","useRefState","internalCallbackRef","useRef","useEffect","onClick","event","element","getElement"],"mappings":"mPAuCaA,EAAmB,IAAIC,IAAkB,CAC9C,MAAAC,EAAUC,WAASF,EAAO,CAAC,CAAC,EAAIA,EAAO,CAAC,EAAI,OAC5CG,EAAYH,EAAO,CAAC,EAAIA,EAAO,CAAC,EAAIA,EAAO,CAAC,EAE5CI,EAAcC,EAAAA,YAAqB,EACnCC,EAAsBC,SAAOJ,CAAQ,EAoB3C,GAnBAG,EAAoB,QAAUH,EAE9BK,EAAAA,UAAU,IAAM,CACd,GAAI,CAACP,GAAU,CAACG,EAAY,MAAO,OAC7B,MAAAK,EAAWC,GAAiB,CAChC,MAAMC,EAAWV,EAASW,EAAAA,WAAWX,CAAM,EAAIG,EAAY,QAEvDO,GAAW,CAACA,EAAQ,SAASD,EAAM,MAAc,GACnDJ,EAAoB,QAAQI,CAAK,CAErC,EAES,gBAAA,iBAAiB,QAASD,CAAO,EAEnC,IAAM,CACF,SAAA,oBAAoB,QAASA,CAAO,CAC/C,CACC,EAAA,CAACR,EAAQG,EAAY,KAAK,CAAC,EAE1B,CAAAH,EACG,OAAAG,CACT"}
1
+ {"version":3,"file":"useClickOutside.cjs","sources":["../../../../src/hooks/useClickOutside/useClickOutside.ts"],"sourcesContent":["import { useEffect, useRef } 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\nexport interface UseClickOutside {\n (target: HookTarget, callback: (event: Event) => void): void;\n\n <Target extends Element>(callback: (event: Event) => void, target?: never): StateRef<Target>;\n}\n\n/**\n * @name useClickOutside\n * @description - Hook to handle click events outside the specified target element(s)\n * @category Sensors\n *\n * @overload\n * @param {HookTarget} target The target element(s) to detect outside clicks for\n * @param {(event: Event) => void} callback The callback to execute when a click outside the target is detected\n * @returns {void}\n *\n * @example\n * useClickOutside(ref, () => console.log('click outside'));\n *\n * @overload\n * @template Target The target element(s)\n * @param {(event: Event) => void} callback The callback to execute when a click outside the target is detected\n * @returns {(node: Target) => void} A React ref to attach to the target element\n *\n * @example\n * const ref = useClickOutside<HTMLDivElement>(() => console.log('click outside'));\n *\n * @see {@link https://siberiacancode.github.io/reactuse/functions/hooks/useClickOutside.html}\n */\nexport const useClickOutside = ((...params: any[]) => {\n const target = (isTarget(params[0]) ? params[0] : undefined) as HookTarget | undefined;\n const callback = (params[1] ? params[1] : params[0]) as (event: Event) => void;\n\n const internalRef = useRefState<Element>();\n const internalCallbackRef = useRef(callback);\n internalCallbackRef.current = callback;\n\n useEffect(() => {\n if (!target && !internalRef.state) return;\n const onClick = (event: Event) => {\n const element = (target ? getElement(target) : internalRef.current) as Element;\n\n if (element && !element.contains(event.target as Node)) {\n internalCallbackRef.current(event);\n }\n };\n\n document.addEventListener('click', onClick);\n\n return () => {\n document.removeEventListener('click', onClick);\n };\n }, [target, internalRef.state]);\n\n if (target) return;\n return internalRef;\n}) as UseClickOutside;\n"],"names":["useClickOutside","params","target","isTarget","callback","internalRef","useRefState","internalCallbackRef","useRef","useEffect","onClick","event","element","getElement"],"mappings":"mPAuCaA,EAAmB,IAAIC,IAAkB,CACpD,MAAMC,EAAUC,EAAAA,SAASF,EAAO,CAAC,CAAC,EAAIA,EAAO,CAAC,EAAI,OAC5CG,EAAYH,EAAO,CAAC,EAAIA,EAAO,CAAC,EAAIA,EAAO,CAAC,EAE5CI,EAAcC,EAAAA,YAAA,EACdC,EAAsBC,EAAAA,OAAOJ,CAAQ,EAoB3C,GAnBAG,EAAoB,QAAUH,EAE9BK,EAAAA,UAAU,IAAM,CACd,GAAI,CAACP,GAAU,CAACG,EAAY,MAAO,OACnC,MAAMK,EAAWC,GAAiB,CAChC,MAAMC,EAAWV,EAASW,EAAAA,WAAWX,CAAM,EAAIG,EAAY,QAEvDO,GAAW,CAACA,EAAQ,SAASD,EAAM,MAAc,GACnDJ,EAAoB,QAAQI,CAAK,CACnC,EAGF,gBAAS,iBAAiB,QAASD,CAAO,EAEnC,IAAM,CACX,SAAS,oBAAoB,QAASA,CAAO,CAAA,CAC/C,EACC,CAACR,EAAQG,EAAY,KAAK,CAAC,EAE1B,CAAAH,EACJ,OAAOG,CACT"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("react"),s=require("../../utils/helpers/copy.cjs"),a=o=>{const[d,n]=u.useState(null),c=(o==null?void 0:o.enabled)??!1,t=async()=>{var e,r;try{const i=await navigator.clipboard.readText();n(i)}catch{n(((r=(e=document.getSelection)==null?void 0:e.call(document))==null?void 0:r.toString())??"")}};return u.useEffect(()=>{if(c)return document.addEventListener("copy",t),document.addEventListener("cut",t),()=>{document.removeEventListener("copy",t),document.removeEventListener("cut",t)}},[c]),{value:d,copy:async e=>{s.copy(e),n(e)}}};exports.useClipboard=a;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("react"),s=require("../../utils/helpers/copy.cjs"),u=r=>{const[a,o]=c.useState(null),n=r?.enabled??!1,e=async()=>{try{const t=await navigator.clipboard.readText();o(t)}catch{o(document.getSelection?.()?.toString()??"")}};return c.useEffect(()=>{if(n)return document.addEventListener("copy",e),document.addEventListener("cut",e),()=>{document.removeEventListener("copy",e),document.removeEventListener("cut",e)}},[n]),{value:a,copy:async t=>{s.copy(t),o(t)}}};exports.useClipboard=u;
2
2
  //# sourceMappingURL=useClipboard.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"useClipboard.cjs","sources":["../../../../src/hooks/useClipboard/useClipboard.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\nimport { copy } from '@/utils/helpers';\n\n/** The use copy to clipboard return type */\nexport interface UseCopyToClipboardReturn {\n /** The copied value */\n value: string | null;\n /** Function to copy to clipboard */\n copy: (value: string) => Promise<void>;\n}\n\n/** The use copy to clipboard params type */\nexport interface UseCopyToClipboardParams {\n /** Whether the copy to clipboard is enabled */\n enabled: boolean;\n}\n\n/**\n * @name useClipboard\n * @description - Hook that manages a copy to clipboard\n * @category Browser\n *\n * @browserapi navigator.clipboard https://developer.mozilla.org/en-US/docs/Web/API/Navigator/clipboard\n *\n * @param {boolean} [params.enabled=false] Whether the copy to clipboard is enabled\n * @returns {UseCopyToClipboardReturn} An object containing the boolean state value and utility functions to manipulate the state\n *\n * @example\n * const { value, copy } = useClipboard();\n */\nexport const useClipboard = (params?: UseCopyToClipboardParams): UseCopyToClipboardReturn => {\n const [value, setValue] = useState<string | null>(null);\n const enabled = params?.enabled ?? false;\n\n const set = async () => {\n try {\n const value = await navigator.clipboard.readText();\n setValue(value);\n } catch {\n setValue(document.getSelection?.()?.toString() ?? '');\n }\n };\n\n useEffect(() => {\n if (!enabled) return;\n\n document.addEventListener('copy', set);\n document.addEventListener('cut', set);\n return () => {\n document.removeEventListener('copy', set);\n document.removeEventListener('cut', set);\n };\n }, [enabled]);\n\n const copyToClipboard = async (value: string) => {\n copy(value);\n setValue(value);\n };\n\n return { value, copy: copyToClipboard };\n};\n"],"names":["useClipboard","params","value","setValue","useState","enabled","set","_b","_a","useEffect","copy"],"mappings":"mJA+BaA,EAAgBC,GAAgE,CAC3F,KAAM,CAACC,EAAOC,CAAQ,EAAIC,EAAAA,SAAwB,IAAI,EAChDC,GAAUJ,GAAA,YAAAA,EAAQ,UAAW,GAE7BK,EAAM,SAAY,SAClB,GAAA,CACF,MAAMJ,EAAQ,MAAM,UAAU,UAAU,SAAS,EACjDC,EAASD,CAAK,CAAA,MACR,CACNC,IAASI,GAAAC,EAAA,SAAS,eAAT,YAAAA,EAAA,6BAAAD,EAA2B,aAAc,EAAE,CAAA,CAExD,EAEAE,OAAAA,EAAAA,UAAU,IAAM,CACd,GAAKJ,EAEI,gBAAA,iBAAiB,OAAQC,CAAG,EAC5B,SAAA,iBAAiB,MAAOA,CAAG,EAC7B,IAAM,CACF,SAAA,oBAAoB,OAAQA,CAAG,EAC/B,SAAA,oBAAoB,MAAOA,CAAG,CACzC,CAAA,EACC,CAACD,CAAO,CAAC,EAOL,CAAE,MAAAH,EAAO,KALQ,MAAOA,GAAkB,CAC/CQ,EAAAA,KAAKR,CAAK,EACVC,EAASD,CAAK,CAChB,CAEsC,CACxC"}
1
+ {"version":3,"file":"useClipboard.cjs","sources":["../../../../src/hooks/useClipboard/useClipboard.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\nimport { copy } from '@/utils/helpers';\n\n/** The use copy to clipboard return type */\nexport interface UseCopyToClipboardReturn {\n /** The copied value */\n value: string | null;\n /** Function to copy to clipboard */\n copy: (value: string) => Promise<void>;\n}\n\n/** The use copy to clipboard params type */\nexport interface UseCopyToClipboardParams {\n /** Whether the copy to clipboard is enabled */\n enabled: boolean;\n}\n\n/**\n * @name useClipboard\n * @description - Hook that manages a copy to clipboard\n * @category Browser\n *\n * @browserapi navigator.clipboard https://developer.mozilla.org/en-US/docs/Web/API/Navigator/clipboard\n *\n * @param {boolean} [params.enabled=false] Whether the copy to clipboard is enabled\n * @returns {UseCopyToClipboardReturn} An object containing the boolean state value and utility functions to manipulate the state\n *\n * @example\n * const { value, copy } = useClipboard();\n */\nexport const useClipboard = (params?: UseCopyToClipboardParams): UseCopyToClipboardReturn => {\n const [value, setValue] = useState<string | null>(null);\n const enabled = params?.enabled ?? false;\n\n const set = async () => {\n try {\n const value = await navigator.clipboard.readText();\n setValue(value);\n } catch {\n setValue(document.getSelection?.()?.toString() ?? '');\n }\n };\n\n useEffect(() => {\n if (!enabled) return;\n\n document.addEventListener('copy', set);\n document.addEventListener('cut', set);\n return () => {\n document.removeEventListener('copy', set);\n document.removeEventListener('cut', set);\n };\n }, [enabled]);\n\n const copyToClipboard = async (value: string) => {\n copy(value);\n setValue(value);\n };\n\n return { value, copy: copyToClipboard };\n};\n"],"names":["useClipboard","params","value","setValue","useState","enabled","set","useEffect","copy"],"mappings":"mJA+BaA,EAAgBC,GAAgE,CAC3F,KAAM,CAACC,EAAOC,CAAQ,EAAIC,EAAAA,SAAwB,IAAI,EAChDC,EAAUJ,GAAQ,SAAW,GAE7BK,EAAM,SAAY,CACtB,GAAI,CACF,MAAMJ,EAAQ,MAAM,UAAU,UAAU,SAAA,EACxCC,EAASD,CAAK,CAAA,MACR,CACNC,EAAS,SAAS,eAAA,GAAkB,SAAA,GAAc,EAAE,CAAA,CACtD,EAGFI,OAAAA,EAAAA,UAAU,IAAM,CACd,GAAKF,EAEL,gBAAS,iBAAiB,OAAQC,CAAG,EACrC,SAAS,iBAAiB,MAAOA,CAAG,EAC7B,IAAM,CACX,SAAS,oBAAoB,OAAQA,CAAG,EACxC,SAAS,oBAAoB,MAAOA,CAAG,CAAA,CACzC,EACC,CAACD,CAAO,CAAC,EAOL,CAAE,MAAAH,EAAO,KALQ,MAAOA,GAAkB,CAC/CM,EAAAA,KAAKN,CAAK,EACVC,EAASD,CAAK,CAAA,CAGM,CACxB"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("react"),C=()=>Object.fromEntries(document.cookie.split("; ").map(o=>{const[t,...e]=o.split("="),n=decodeURIComponent(e.join("="));return[t,n]})),l=(o,t={})=>{document.cookie=`${encodeURIComponent(o)}=; expires=Thu, 01 Jan 1970 00:00:00 GMT${t.path?`; path=${t.path}`:""}${t.domain?`; domain=${t.domain}`:""}${t.maxAge?"; max-age=0":""}${t.expires?"; expires=Thu, 01 Jan 1970 00:00:00 GMT":""}${t.secure?"; secure":""}${t.sameSite?`; samesite=${t.sameSite}`:""}`},h=(o,t,e={})=>{const n=[`${encodeURIComponent(o)}=${encodeURIComponent(t)}`];e.path&&n.push(`path=${e.path}`),e.domain&&n.push(`domain=${e.domain}`),typeof e.maxAge=="number"&&n.push(`max-age=${e.maxAge}`),e.expires&&n.push(`expires=${e.expires.toUTCString()}`),e.secure&&n.push("secure"),e.httpOnly&&n.push("httpOnly"),e.sameSite&&n.push(`samesite=${e.sameSite}`),document.cookie=n.join("; ")},c="reactuse-cookie",a=()=>window.dispatchEvent(new Event(c)),s=(o,t,e)=>{h(o,t,e),a()},k=(o,t)=>{l(o,t),a()},u=o=>C()[o],g=(o,t)=>{const e=typeof t=="object"&&t&&("serializer"in t||"deserializer"in t||"initialValue"in t)?t:void 0,n=e?e==null?void 0:e.initialValue:t;if(typeof document>"u")return{value:typeof n=="function"?n():n};const d=i=>e!=null&&e.serializer?e.serializer(i):typeof i=="string"?i:JSON.stringify(i),m=i=>{if(e!=null&&e.deserializer)return e.deserializer(i);if(i!=="undefined")try{return JSON.parse(i)}catch{return i}},[v,$]=f.useState(()=>{const i=u(o);if(i===void 0&&n!==void 0){const r=typeof n=="function"?n():n;return s(o,d(r),e),r}return i?m(i):void 0});return f.useEffect(()=>{const i=()=>{const r=u(o);$(r?m(r):void 0)};return window.addEventListener(c,i),()=>window.removeEventListener(c,i)},[o]),{value:v,set:(i,r)=>s(o,d(i),{...e,...r}),remove:i=>k(o,{...e,...i})}};exports.COOKIE_EVENT=c;exports.dispatchCookieEvent=a;exports.getCookie=u;exports.getCookies=C;exports.removeCookie=l;exports.removeCookieItem=k;exports.setCookie=h;exports.setCookieItem=s;exports.useCookie=g;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("react"),C=()=>Object.fromEntries(document.cookie.split("; ").map(o=>{const[e,...t]=o.split("="),n=decodeURIComponent(t.join("="));return[e,n]})),l=(o,e={})=>{document.cookie=`${encodeURIComponent(o)}=; expires=Thu, 01 Jan 1970 00:00:00 GMT${e.path?`; path=${e.path}`:""}${e.domain?`; domain=${e.domain}`:""}${e.maxAge?"; max-age=0":""}${e.expires?"; expires=Thu, 01 Jan 1970 00:00:00 GMT":""}${e.secure?"; secure":""}${e.sameSite?`; samesite=${e.sameSite}`:""}`},h=(o,e,t={})=>{const n=[`${encodeURIComponent(o)}=${encodeURIComponent(e)}`];t.path&&n.push(`path=${t.path}`),t.domain&&n.push(`domain=${t.domain}`),typeof t.maxAge=="number"&&n.push(`max-age=${t.maxAge}`),t.expires&&n.push(`expires=${t.expires.toUTCString()}`),t.secure&&n.push("secure"),t.httpOnly&&n.push("httpOnly"),t.sameSite&&n.push(`samesite=${t.sameSite}`),document.cookie=n.join("; ")},s="reactuse-cookie",a=()=>window.dispatchEvent(new Event(s)),c=(o,e,t)=>{h(o,e,t),a()},k=(o,e)=>{l(o,e),a()},u=o=>C()[o],g=(o,e)=>{const t=typeof e=="object"&&e&&("serializer"in e||"deserializer"in e||"initialValue"in e)?e:void 0,n=t?t?.initialValue:e;if(typeof document>"u")return{value:typeof n=="function"?n():n};const d=i=>t?.serializer?t.serializer(i):typeof i=="string"?i:JSON.stringify(i),m=i=>{if(t?.deserializer)return t.deserializer(i);if(i!=="undefined")try{return JSON.parse(i)}catch{return i}},[v,$]=f.useState(()=>{const i=u(o);if(i===void 0&&n!==void 0){const r=typeof n=="function"?n():n;return c(o,d(r),t),r}return i?m(i):void 0});return f.useEffect(()=>{const i=()=>{const r=u(o);$(r?m(r):void 0)};return window.addEventListener(s,i),()=>window.removeEventListener(s,i)},[o]),{value:v,set:(i,r)=>c(o,d(i),{...t,...r}),remove:i=>k(o,{...t,...i})}};exports.COOKIE_EVENT=s;exports.dispatchCookieEvent=a;exports.getCookie=u;exports.getCookies=C;exports.removeCookie=l;exports.removeCookieItem=k;exports.setCookie=h;exports.setCookieItem=c;exports.useCookie=g;
2
2
  //# sourceMappingURL=useCookie.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"useCookie.cjs","sources":["../../../../src/hooks/useCookie/useCookie.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\nexport const getCookies = () =>\n Object.fromEntries(\n document.cookie.split('; ').map((cookie) => {\n const [key, ...value] = cookie.split('=');\n const decodedValue = decodeURIComponent(value.join('='));\n return [key, decodedValue];\n })\n );\n\nexport interface RemoveCookieParams {\n domain?: string;\n expires?: Date;\n maxAge?: number;\n path?: string;\n sameSite?: 'Lax' | 'None' | 'Strict';\n secure?: boolean;\n}\n\nexport const removeCookie = (key: string, options: RemoveCookieParams = {}) => {\n document.cookie = `${encodeURIComponent(key)}=; expires=Thu, 01 Jan 1970 00:00:00 GMT${\n options.path ? `; path=${options.path}` : ''\n }${options.domain ? `; domain=${options.domain}` : ''}${\n options.maxAge ? `; max-age=0` : ''\n }${options.expires ? `; expires=Thu, 01 Jan 1970 00:00:00 GMT` : ''}${\n options.secure ? `; secure` : ''\n }${options.sameSite ? `; samesite=${options.sameSite}` : ''}`;\n};\n\nexport interface SetCookieParams {\n domain?: string;\n expires?: Date;\n httpOnly?: boolean;\n maxAge?: number;\n path?: string;\n sameSite?: 'Lax' | 'None' | 'Strict';\n secure?: boolean;\n}\n\nexport const setCookie = (key: string, value: string, options: SetCookieParams = {}) => {\n const cookie = [`${encodeURIComponent(key)}=${encodeURIComponent(value)}`];\n\n if (options.path) cookie.push(`path=${options.path}`);\n if (options.domain) cookie.push(`domain=${options.domain}`);\n if (typeof options.maxAge === 'number') cookie.push(`max-age=${options.maxAge}`);\n if (options.expires) cookie.push(`expires=${options.expires.toUTCString()}`);\n if (options.secure) cookie.push(`secure`);\n if (options.httpOnly) cookie.push(`httpOnly`);\n if (options.sameSite) cookie.push(`samesite=${options.sameSite}`);\n\n document.cookie = cookie.join('; ');\n};\n\n/* The use cookie initial value type */\nexport type UseCookieInitialValue<Value> = (() => Value) | Value;\n\n/* The use cookie options type */\nexport interface UseCookieOptions<Value> {\n /* The domain of the cookie */\n domain?: string;\n /* The expiration date of the cookie */\n expires?: Date;\n /* Whether the cookie is httpOnly */\n httpOnly?: boolean;\n /* The initial value of the storage */\n initialValue?: UseCookieInitialValue<Value>;\n /* The maximum age of the cookie */\n maxAge?: number;\n /* The path of the cookie */\n path?: string;\n /* The sameSite of the cookie */\n sameSite?: 'Lax' | 'None' | 'Strict';\n /* Whether the cookie is secure */\n secure?: boolean;\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 cookie return type */\nexport interface UseCookieReturn<Value> {\n /* The value of the cookie */\n value: Value;\n /* The remove function */\n remove: (options?: RemoveCookieParams) => void;\n /* The set function */\n set: (value: Value, options?: SetCookieParams) => void;\n}\n\nexport const COOKIE_EVENT = 'reactuse-cookie';\n\nexport const dispatchCookieEvent = () => window.dispatchEvent(new Event(COOKIE_EVENT));\n\nexport const setCookieItem = (key: string, value: string, options?: SetCookieParams) => {\n setCookie(key, value, options);\n dispatchCookieEvent();\n};\n\nexport const removeCookieItem = (key: string, options?: RemoveCookieParams) => {\n removeCookie(key, options);\n dispatchCookieEvent();\n};\n\nexport const getCookie = (key: string): string | undefined => {\n const cookies = getCookies();\n return cookies[key];\n};\n\nexport interface UseCookie {\n <Value>(\n key: string,\n options: UseCookieOptions<Value> & {\n initialValue: UseCookieInitialValue<Value>;\n }\n ): UseCookieReturn<Value>;\n\n <Value>(key: string, options?: UseCookieOptions<Value>): UseCookieReturn<Value | undefined>;\n\n <Value>(key: string, initialValue: UseCookieInitialValue<Value>): UseCookieReturn<Value>;\n\n <Value>(key: string): UseCookieReturn<Value | undefined>;\n}\n\n/**\n * @name useCookie\n * @description - Hook that manages cookie value\n * @category Browser\n *\n * @overload\n * @template Value The type of the cookie value\n * @param {string} key The key of the cookie\n * @param {UseCookieInitialValue<Value>} [initialValue] The initial value of the cookie\n * @returns {UseCookieReturn<Value>} The value and the set function\n *\n * @overload\n * @template Value The type of the cookie value\n * @param {string} key The key of the cookie\n * @param {UseCookieOptions<Value>} options The options object\n * @param {UseCookieInitialValue<Value>} [options.initialValue] The initial value of the cookie\n * @param {(value: string) => Value} [options.deserializer] The deserializer function to be invoked\n * @param {(value: Value) => string} [options.serializer] The serializer function to be invoked\n * @returns {UseCookieReturn<Value | undefined>} The value and the set function\n *\n * @example\n * const { value, set, remove } = useCookie('key', 'value');\n */\nexport const useCookie = (<Value>(key: string, params?: any) => {\n const options = (\n typeof params === 'object' &&\n params &&\n ('serializer' in params || 'deserializer' in params || 'initialValue' in params)\n ? params\n : undefined\n ) as UseCookieOptions<Value>;\n const initialValue = (options ? options?.initialValue : params) as UseCookieInitialValue<Value>;\n\n if (typeof document === 'undefined')\n return {\n value: typeof initialValue === 'function' ? (initialValue as () => Value)() : initialValue\n } as UseCookieReturn<Value>;\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 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 cookieValue = getCookie(key);\n if (cookieValue === undefined && initialValue !== undefined) {\n const value =\n typeof initialValue === 'function' ? (initialValue as () => Value)() : initialValue;\n setCookieItem(key, serializer(value), options);\n return value;\n }\n return cookieValue ? deserializer(cookieValue) : undefined;\n });\n\n useEffect(() => {\n const onChange = () => {\n const cookieValue = getCookie(key);\n setValue(cookieValue ? deserializer(cookieValue) : undefined);\n };\n window.addEventListener(COOKIE_EVENT, onChange);\n return () => window.removeEventListener(COOKIE_EVENT, onChange);\n }, [key]);\n\n const set = (value: Value, params?: SetCookieParams) =>\n setCookieItem(key, serializer(value), { ...options, ...params });\n const remove = (params?: RemoveCookieParams) => removeCookieItem(key, { ...options, ...params });\n\n return { value, set, remove };\n}) as UseCookie;\n"],"names":["getCookies","cookie","key","value","decodedValue","removeCookie","options","setCookie","COOKIE_EVENT","dispatchCookieEvent","setCookieItem","removeCookieItem","getCookie","useCookie","params","initialValue","serializer","deserializer","setValue","useState","cookieValue","useEffect","onChange"],"mappings":"yGAEaA,EAAa,IACxB,OAAO,YACL,SAAS,OAAO,MAAM,IAAI,EAAE,IAAKC,GAAW,CAC1C,KAAM,CAACC,EAAK,GAAGC,CAAK,EAAIF,EAAO,MAAM,GAAG,EAClCG,EAAe,mBAAmBD,EAAM,KAAK,GAAG,CAAC,EAChD,MAAA,CAACD,EAAKE,CAAY,CAC1B,CAAA,CACH,EAWWC,EAAe,CAACH,EAAaI,EAA8B,KAAO,CAC7E,SAAS,OAAS,GAAG,mBAAmBJ,CAAG,CAAC,2CAC1CI,EAAQ,KAAO,UAAUA,EAAQ,IAAI,GAAK,EAC5C,GAAGA,EAAQ,OAAS,YAAYA,EAAQ,MAAM,GAAK,EAAE,GACnDA,EAAQ,OAAS,cAAgB,EACnC,GAAGA,EAAQ,QAAU,0CAA4C,EAAE,GACjEA,EAAQ,OAAS,WAAa,EAChC,GAAGA,EAAQ,SAAW,cAAcA,EAAQ,QAAQ,GAAK,EAAE,EAC7D,EAYaC,EAAY,CAACL,EAAaC,EAAeG,EAA2B,CAAA,IAAO,CAChF,MAAAL,EAAS,CAAC,GAAG,mBAAmBC,CAAG,CAAC,IAAI,mBAAmBC,CAAK,CAAC,EAAE,EAErEG,EAAQ,MAAML,EAAO,KAAK,QAAQK,EAAQ,IAAI,EAAE,EAChDA,EAAQ,QAAQL,EAAO,KAAK,UAAUK,EAAQ,MAAM,EAAE,EACtD,OAAOA,EAAQ,QAAW,YAAiB,KAAK,WAAWA,EAAQ,MAAM,EAAE,EAC3EA,EAAQ,SAAgBL,EAAA,KAAK,WAAWK,EAAQ,QAAQ,YAAa,CAAA,EAAE,EACvEA,EAAQ,QAAeL,EAAA,KAAK,QAAQ,EACpCK,EAAQ,UAAiBL,EAAA,KAAK,UAAU,EACxCK,EAAQ,UAAUL,EAAO,KAAK,YAAYK,EAAQ,QAAQ,EAAE,EAEvD,SAAA,OAASL,EAAO,KAAK,IAAI,CACpC,EAuCaO,EAAe,kBAEfC,EAAsB,IAAM,OAAO,cAAc,IAAI,MAAMD,CAAY,CAAC,EAExEE,EAAgB,CAACR,EAAaC,EAAeG,IAA8B,CAC5EC,EAAAL,EAAKC,EAAOG,CAAO,EACTG,EAAA,CACtB,EAEaE,EAAmB,CAACT,EAAaI,IAAiC,CAC7ED,EAAaH,EAAKI,CAAO,EACLG,EAAA,CACtB,EAEaG,EAAaV,GACRF,EAAW,EACZE,CAAG,EAyCPW,EAAa,CAAQX,EAAaY,IAAiB,CACxD,MAAAR,EACJ,OAAOQ,GAAW,UAClBA,IACC,eAAgBA,GAAU,iBAAkBA,GAAU,iBAAkBA,GACrEA,EACA,OAEAC,EAAgBT,EAAUA,GAAA,YAAAA,EAAS,aAAeQ,EAExD,GAAI,OAAO,SAAa,IACf,MAAA,CACL,MAAO,OAAOC,GAAiB,WAAcA,IAAiCA,CAChF,EAEI,MAAAC,EAAcb,GACdG,GAAA,MAAAA,EAAS,WAAmBA,EAAQ,WAAWH,CAAK,EACpD,OAAOA,GAAU,SAAiBA,EAC/B,KAAK,UAAUA,CAAK,EAGvBc,EAAgBd,GAAkB,CACtC,GAAIG,GAAA,MAAAA,EAAS,aAAqB,OAAAA,EAAQ,aAAaH,CAAK,EACxDA,GAAAA,IAAU,YAEV,GAAA,CACK,OAAA,KAAK,MAAMA,CAAK,CAAA,MACjB,CACCA,OAAAA,CAAA,CAEX,EAEM,CAACA,EAAOe,CAAQ,EAAIC,WAA4B,IAAM,CACpD,MAAAC,EAAcR,EAAUV,CAAG,EAC7B,GAAAkB,IAAgB,QAAaL,IAAiB,OAAW,CAC3D,MAAMZ,EACJ,OAAOY,GAAiB,WAAcA,EAAiC,EAAAA,EACzE,OAAAL,EAAcR,EAAKc,EAAWb,CAAK,EAAGG,CAAO,EACtCH,CAAA,CAEF,OAAAiB,EAAcH,EAAaG,CAAW,EAAI,MAAA,CAClD,EAEDC,OAAAA,EAAAA,UAAU,IAAM,CACd,MAAMC,EAAW,IAAM,CACf,MAAAF,EAAcR,EAAUV,CAAG,EACjCgB,EAASE,EAAcH,EAAaG,CAAW,EAAI,MAAS,CAC9D,EACO,cAAA,iBAAiBZ,EAAcc,CAAQ,EACvC,IAAM,OAAO,oBAAoBd,EAAcc,CAAQ,CAAA,EAC7D,CAACpB,CAAG,CAAC,EAMD,CAAE,MAAAC,EAAO,IAJJ,CAACA,EAAcW,IACzBJ,EAAcR,EAAKc,EAAWb,CAAK,EAAG,CAAE,GAAGG,EAAS,GAAGQ,EAAQ,EAG5C,OAFLA,GAAgCH,EAAiBT,EAAK,CAAE,GAAGI,EAAS,GAAGQ,EAAQ,CAEnE,CAC9B"}
1
+ {"version":3,"file":"useCookie.cjs","sources":["../../../../src/hooks/useCookie/useCookie.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\nexport const getCookies = () =>\n Object.fromEntries(\n document.cookie.split('; ').map((cookie) => {\n const [key, ...value] = cookie.split('=');\n const decodedValue = decodeURIComponent(value.join('='));\n return [key, decodedValue];\n })\n );\n\nexport interface RemoveCookieParams {\n domain?: string;\n expires?: Date;\n maxAge?: number;\n path?: string;\n sameSite?: 'Lax' | 'None' | 'Strict';\n secure?: boolean;\n}\n\nexport const removeCookie = (key: string, options: RemoveCookieParams = {}) => {\n document.cookie = `${encodeURIComponent(key)}=; expires=Thu, 01 Jan 1970 00:00:00 GMT${\n options.path ? `; path=${options.path}` : ''\n }${options.domain ? `; domain=${options.domain}` : ''}${\n options.maxAge ? `; max-age=0` : ''\n }${options.expires ? `; expires=Thu, 01 Jan 1970 00:00:00 GMT` : ''}${\n options.secure ? `; secure` : ''\n }${options.sameSite ? `; samesite=${options.sameSite}` : ''}`;\n};\n\nexport interface SetCookieParams {\n domain?: string;\n expires?: Date;\n httpOnly?: boolean;\n maxAge?: number;\n path?: string;\n sameSite?: 'Lax' | 'None' | 'Strict';\n secure?: boolean;\n}\n\nexport const setCookie = (key: string, value: string, options: SetCookieParams = {}) => {\n const cookie = [`${encodeURIComponent(key)}=${encodeURIComponent(value)}`];\n\n if (options.path) cookie.push(`path=${options.path}`);\n if (options.domain) cookie.push(`domain=${options.domain}`);\n if (typeof options.maxAge === 'number') cookie.push(`max-age=${options.maxAge}`);\n if (options.expires) cookie.push(`expires=${options.expires.toUTCString()}`);\n if (options.secure) cookie.push(`secure`);\n if (options.httpOnly) cookie.push(`httpOnly`);\n if (options.sameSite) cookie.push(`samesite=${options.sameSite}`);\n\n document.cookie = cookie.join('; ');\n};\n\n/* The use cookie initial value type */\nexport type UseCookieInitialValue<Value> = (() => Value) | Value;\n\n/* The use cookie options type */\nexport interface UseCookieOptions<Value> {\n /* The domain of the cookie */\n domain?: string;\n /* The expiration date of the cookie */\n expires?: Date;\n /* Whether the cookie is httpOnly */\n httpOnly?: boolean;\n /* The initial value of the storage */\n initialValue?: UseCookieInitialValue<Value>;\n /* The maximum age of the cookie */\n maxAge?: number;\n /* The path of the cookie */\n path?: string;\n /* The sameSite of the cookie */\n sameSite?: 'Lax' | 'None' | 'Strict';\n /* Whether the cookie is secure */\n secure?: boolean;\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 cookie return type */\nexport interface UseCookieReturn<Value> {\n /* The value of the cookie */\n value: Value;\n /* The remove function */\n remove: (options?: RemoveCookieParams) => void;\n /* The set function */\n set: (value: Value, options?: SetCookieParams) => void;\n}\n\nexport const COOKIE_EVENT = 'reactuse-cookie';\n\nexport const dispatchCookieEvent = () => window.dispatchEvent(new Event(COOKIE_EVENT));\n\nexport const setCookieItem = (key: string, value: string, options?: SetCookieParams) => {\n setCookie(key, value, options);\n dispatchCookieEvent();\n};\n\nexport const removeCookieItem = (key: string, options?: RemoveCookieParams) => {\n removeCookie(key, options);\n dispatchCookieEvent();\n};\n\nexport const getCookie = (key: string): string | undefined => {\n const cookies = getCookies();\n return cookies[key];\n};\n\nexport interface UseCookie {\n <Value>(\n key: string,\n options: UseCookieOptions<Value> & {\n initialValue: UseCookieInitialValue<Value>;\n }\n ): UseCookieReturn<Value>;\n\n <Value>(key: string, options?: UseCookieOptions<Value>): UseCookieReturn<Value | undefined>;\n\n <Value>(key: string, initialValue: UseCookieInitialValue<Value>): UseCookieReturn<Value>;\n\n <Value>(key: string): UseCookieReturn<Value | undefined>;\n}\n\n/**\n * @name useCookie\n * @description - Hook that manages cookie value\n * @category Browser\n *\n * @overload\n * @template Value The type of the cookie value\n * @param {string} key The key of the cookie\n * @param {UseCookieInitialValue<Value>} [initialValue] The initial value of the cookie\n * @returns {UseCookieReturn<Value>} The value and the set function\n *\n * @overload\n * @template Value The type of the cookie value\n * @param {string} key The key of the cookie\n * @param {UseCookieOptions<Value>} options The options object\n * @param {UseCookieInitialValue<Value>} [options.initialValue] The initial value of the cookie\n * @param {(value: string) => Value} [options.deserializer] The deserializer function to be invoked\n * @param {(value: Value) => string} [options.serializer] The serializer function to be invoked\n * @returns {UseCookieReturn<Value | undefined>} The value and the set function\n *\n * @example\n * const { value, set, remove } = useCookie('key', 'value');\n */\nexport const useCookie = (<Value>(key: string, params?: any) => {\n const options = (\n typeof params === 'object' &&\n params &&\n ('serializer' in params || 'deserializer' in params || 'initialValue' in params)\n ? params\n : undefined\n ) as UseCookieOptions<Value>;\n const initialValue = (options ? options?.initialValue : params) as UseCookieInitialValue<Value>;\n\n if (typeof document === 'undefined')\n return {\n value: typeof initialValue === 'function' ? (initialValue as () => Value)() : initialValue\n } as UseCookieReturn<Value>;\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 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 cookieValue = getCookie(key);\n if (cookieValue === undefined && initialValue !== undefined) {\n const value =\n typeof initialValue === 'function' ? (initialValue as () => Value)() : initialValue;\n setCookieItem(key, serializer(value), options);\n return value;\n }\n return cookieValue ? deserializer(cookieValue) : undefined;\n });\n\n useEffect(() => {\n const onChange = () => {\n const cookieValue = getCookie(key);\n setValue(cookieValue ? deserializer(cookieValue) : undefined);\n };\n window.addEventListener(COOKIE_EVENT, onChange);\n return () => window.removeEventListener(COOKIE_EVENT, onChange);\n }, [key]);\n\n const set = (value: Value, params?: SetCookieParams) =>\n setCookieItem(key, serializer(value), { ...options, ...params });\n const remove = (params?: RemoveCookieParams) => removeCookieItem(key, { ...options, ...params });\n\n return { value, set, remove };\n}) as UseCookie;\n"],"names":["getCookies","cookie","key","value","decodedValue","removeCookie","options","setCookie","COOKIE_EVENT","dispatchCookieEvent","setCookieItem","removeCookieItem","getCookie","useCookie","params","initialValue","serializer","deserializer","setValue","useState","cookieValue","useEffect","onChange"],"mappings":"yGAEaA,EAAa,IACxB,OAAO,YACL,SAAS,OAAO,MAAM,IAAI,EAAE,IAAKC,GAAW,CAC1C,KAAM,CAACC,EAAK,GAAGC,CAAK,EAAIF,EAAO,MAAM,GAAG,EAClCG,EAAe,mBAAmBD,EAAM,KAAK,GAAG,CAAC,EACvD,MAAO,CAACD,EAAKE,CAAY,CAAA,CAC1B,CACH,EAWWC,EAAe,CAACH,EAAaI,EAA8B,KAAO,CAC7E,SAAS,OAAS,GAAG,mBAAmBJ,CAAG,CAAC,2CAC1CI,EAAQ,KAAO,UAAUA,EAAQ,IAAI,GAAK,EAC5C,GAAGA,EAAQ,OAAS,YAAYA,EAAQ,MAAM,GAAK,EAAE,GACnDA,EAAQ,OAAS,cAAgB,EACnC,GAAGA,EAAQ,QAAU,0CAA4C,EAAE,GACjEA,EAAQ,OAAS,WAAa,EAChC,GAAGA,EAAQ,SAAW,cAAcA,EAAQ,QAAQ,GAAK,EAAE,EAC7D,EAYaC,EAAY,CAACL,EAAaC,EAAeG,EAA2B,CAAA,IAAO,CACtF,MAAML,EAAS,CAAC,GAAG,mBAAmBC,CAAG,CAAC,IAAI,mBAAmBC,CAAK,CAAC,EAAE,EAErEG,EAAQ,MAAML,EAAO,KAAK,QAAQK,EAAQ,IAAI,EAAE,EAChDA,EAAQ,QAAQL,EAAO,KAAK,UAAUK,EAAQ,MAAM,EAAE,EACtD,OAAOA,EAAQ,QAAW,YAAiB,KAAK,WAAWA,EAAQ,MAAM,EAAE,EAC3EA,EAAQ,SAASL,EAAO,KAAK,WAAWK,EAAQ,QAAQ,YAAA,CAAa,EAAE,EACvEA,EAAQ,QAAQL,EAAO,KAAK,QAAQ,EACpCK,EAAQ,UAAUL,EAAO,KAAK,UAAU,EACxCK,EAAQ,UAAUL,EAAO,KAAK,YAAYK,EAAQ,QAAQ,EAAE,EAEhE,SAAS,OAASL,EAAO,KAAK,IAAI,CACpC,EAuCaO,EAAe,kBAEfC,EAAsB,IAAM,OAAO,cAAc,IAAI,MAAMD,CAAY,CAAC,EAExEE,EAAgB,CAACR,EAAaC,EAAeG,IAA8B,CACtFC,EAAUL,EAAKC,EAAOG,CAAO,EAC7BG,EAAA,CACF,EAEaE,EAAmB,CAACT,EAAaI,IAAiC,CAC7ED,EAAaH,EAAKI,CAAO,EACzBG,EAAA,CACF,EAEaG,EAAaV,GACRF,EAAA,EACDE,CAAG,EAyCPW,EAAa,CAAQX,EAAaY,IAAiB,CAC9D,MAAMR,EACJ,OAAOQ,GAAW,UAClBA,IACC,eAAgBA,GAAU,iBAAkBA,GAAU,iBAAkBA,GACrEA,EACA,OAEAC,EAAgBT,EAAUA,GAAS,aAAeQ,EAExD,GAAI,OAAO,SAAa,IACtB,MAAO,CACL,MAAO,OAAOC,GAAiB,WAAcA,IAAiCA,CAAA,EAGlF,MAAMC,EAAcb,GACdG,GAAS,WAAmBA,EAAQ,WAAWH,CAAK,EACpD,OAAOA,GAAU,SAAiBA,EAC/B,KAAK,UAAUA,CAAK,EAGvBc,EAAgBd,GAAkB,CACtC,GAAIG,GAAS,aAAc,OAAOA,EAAQ,aAAaH,CAAK,EAC5D,GAAIA,IAAU,YAEd,GAAI,CACF,OAAO,KAAK,MAAMA,CAAK,CAAA,MACjB,CACN,OAAOA,CAAA,CACT,EAGI,CAACA,EAAOe,CAAQ,EAAIC,EAAAA,SAA4B,IAAM,CAC1D,MAAMC,EAAcR,EAAUV,CAAG,EACjC,GAAIkB,IAAgB,QAAaL,IAAiB,OAAW,CAC3D,MAAMZ,EACJ,OAAOY,GAAiB,WAAcA,IAAiCA,EACzE,OAAAL,EAAcR,EAAKc,EAAWb,CAAK,EAAGG,CAAO,EACtCH,CAAA,CAET,OAAOiB,EAAcH,EAAaG,CAAW,EAAI,MAAA,CAClD,EAEDC,OAAAA,EAAAA,UAAU,IAAM,CACd,MAAMC,EAAW,IAAM,CACrB,MAAMF,EAAcR,EAAUV,CAAG,EACjCgB,EAASE,EAAcH,EAAaG,CAAW,EAAI,MAAS,CAAA,EAE9D,cAAO,iBAAiBZ,EAAcc,CAAQ,EACvC,IAAM,OAAO,oBAAoBd,EAAcc,CAAQ,CAAA,EAC7D,CAACpB,CAAG,CAAC,EAMD,CAAE,MAAAC,EAAO,IAJJ,CAACA,EAAcW,IACzBJ,EAAcR,EAAKc,EAAWb,CAAK,EAAG,CAAE,GAAGG,EAAS,GAAGQ,EAAQ,EAG5C,OAFLA,GAAgCH,EAAiBT,EAAK,CAAE,GAAGI,EAAS,GAAGQ,EAAQ,CAE1E,CACvB"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("react"),n=require("../useCookie/useCookie.cjs"),u=()=>{document.cookie.split("; ").forEach(r=>{const[i]=r.split("=");n.removeCookie(i)})},m=()=>{u(),n.dispatchCookieEvent()},k=r=>{const i=e=>r!=null&&r.serializer?r.serializer(e):typeof e=="string"?e:JSON.stringify(e),d=e=>{if(r!=null&&r.deserializer)return r.deserializer(e);if(e!=="undefined")try{return JSON.parse(e)}catch{return e}},s=()=>document.cookie?Object.fromEntries(document.cookie.split("; ").map(e=>{const[t,...o]=e.split("=");if(!t||!o.length)return[];const f=decodeURIComponent(o.join("="));return[t,d(f)]}).filter(e=>e.length)):{},[l,a]=c.useState(()=>typeof window>"u"?{}:s());return c.useEffect(()=>{const e=()=>a(s());return window.addEventListener(n.COOKIE_EVENT,e),()=>{window.removeEventListener(n.COOKIE_EVENT,e)}},[]),{value:l,set:(e,t,o)=>n.setCookieItem(e,i(t),o),remove:(e,t)=>n.removeCookieItem(e,t),getAll:()=>s(),clear:()=>m()}};exports.clearCookies=u;exports.useCookies=k;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("react"),o=require("../useCookie/useCookie.cjs"),u=()=>{document.cookie.split("; ").forEach(t=>{const[i]=t.split("=");o.removeCookie(i)})},m=()=>{u(),o.dispatchCookieEvent()},k=t=>{const i=e=>t?.serializer?t.serializer(e):typeof e=="string"?e:JSON.stringify(e),d=e=>{if(t?.deserializer)return t.deserializer(e);if(e!=="undefined")try{return JSON.parse(e)}catch{return e}},s=()=>document.cookie?Object.fromEntries(document.cookie.split("; ").map(e=>{const[r,...n]=e.split("=");if(!r||!n.length)return[];const f=decodeURIComponent(n.join("="));return[r,d(f)]}).filter(e=>e.length)):{},[l,a]=c.useState(()=>typeof window>"u"?{}:s());return c.useEffect(()=>{const e=()=>a(s());return window.addEventListener(o.COOKIE_EVENT,e),()=>{window.removeEventListener(o.COOKIE_EVENT,e)}},[]),{value:l,set:(e,r,n)=>o.setCookieItem(e,i(r),n),remove:(e,r)=>o.removeCookieItem(e,r),getAll:()=>s(),clear:()=>m()}};exports.clearCookies=u;exports.useCookies=k;
2
2
  //# sourceMappingURL=useCookies.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"useCookies.cjs","sources":["../../../../src/hooks/useCookies/useCookies.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\nimport type { RemoveCookieParams, SetCookieParams } from '../useCookie/useCookie';\n\nimport {\n COOKIE_EVENT,\n dispatchCookieEvent,\n removeCookie,\n removeCookieItem,\n setCookieItem\n} from '../useCookie/useCookie';\n\n/** The cookies params type */\nexport type CookieParams = Record<string, any>;\n\n/* The use cookies options type */\nexport interface UseCookiesOptions<Value> {\n /* The deserializer function to be invoked */\n deserializer?: (value: string) => Value[keyof Value];\n /* The serializer function to be invoked */\n serializer?: (value: Value[keyof Value]) => string;\n}\n\nexport const clearCookies = () => {\n document.cookie.split('; ').forEach((cookie) => {\n const [name] = cookie.split('=');\n removeCookie(name);\n });\n};\n\nconst clearCookieItems = () => {\n clearCookies();\n dispatchCookieEvent();\n};\n\n/**\n * @name useCookies\n * @description - Hook that manages cookie values\n * @category Browser\n *\n * @overload\n * @template {object} Value The type of the cookie values\n * @returns {UseCookieReturn<Value>} The value and the set function\n *\n * @example\n * const { value, set, remove, getAll, clear } = useCookies();\n */\nexport const useCookies = <Value extends CookieParams>(options?: UseCookiesOptions<Value>) => {\n const serializer = (value: Value[keyof 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 deserializer = (value: string) => {\n if (options?.deserializer) return options.deserializer(value);\n if (value === 'undefined') return undefined as unknown as Value[keyof Value];\n\n try {\n return JSON.parse(value) as Value;\n } catch {\n return value as Value[keyof Value];\n }\n };\n\n const getParsedCookies = () => {\n if (!document.cookie) return {};\n\n return Object.fromEntries(\n document.cookie\n .split('; ')\n .map((cookie) => {\n const [key, ...value] = cookie.split('=');\n if (!key || !value.length) return [];\n const decodedValue = decodeURIComponent(value.join('='));\n return [key, deserializer(decodedValue)];\n })\n .filter((entry) => entry.length)\n );\n };\n\n const [value, setValue] = useState(() => {\n if (typeof window === 'undefined') return {} as Value;\n return getParsedCookies() as Value;\n });\n\n useEffect(() => {\n const onChange = () => setValue(getParsedCookies() as Value);\n\n window.addEventListener(COOKIE_EVENT, onChange);\n return () => {\n window.removeEventListener(COOKIE_EVENT, onChange);\n };\n }, []);\n\n const set = <Key extends keyof Value>(key: Key, value: Value[Key], options?: SetCookieParams) =>\n setCookieItem(key as string, serializer(value), options);\n\n const remove = <Key extends keyof Value>(key: Key, options?: RemoveCookieParams) =>\n removeCookieItem(key as string, options);\n const getAll = () => getParsedCookies();\n const clear = () => clearCookieItems();\n\n return { value, set, remove, getAll, clear };\n};\n"],"names":["clearCookies","cookie","name","removeCookie","clearCookieItems","dispatchCookieEvent","useCookies","options","serializer","value","deserializer","getParsedCookies","key","decodedValue","entry","setValue","useState","useEffect","onChange","COOKIE_EVENT","setCookieItem","removeCookieItem"],"mappings":"iJAuBaA,EAAe,IAAM,CAChC,SAAS,OAAO,MAAM,IAAI,EAAE,QAASC,GAAW,CAC9C,KAAM,CAACC,CAAI,EAAID,EAAO,MAAM,GAAG,EAC/BE,EAAAA,aAAaD,CAAI,CAAA,CAClB,CACH,EAEME,EAAmB,IAAM,CAChBJ,EAAA,EACOK,sBAAA,CACtB,EAcaC,EAA0CC,GAAuC,CACtF,MAAAC,EAAcC,GACdF,GAAA,MAAAA,EAAS,WAAmBA,EAAQ,WAAWE,CAAK,EACpD,OAAOA,GAAU,SAAiBA,EAC/B,KAAK,UAAUA,CAAK,EAGvBC,EAAgBD,GAAkB,CACtC,GAAIF,GAAA,MAAAA,EAAS,aAAqB,OAAAA,EAAQ,aAAaE,CAAK,EACxDA,GAAAA,IAAU,YAEV,GAAA,CACK,OAAA,KAAK,MAAMA,CAAK,CAAA,MACjB,CACCA,OAAAA,CAAA,CAEX,EAEME,EAAmB,IAClB,SAAS,OAEP,OAAO,YACZ,SAAS,OACN,MAAM,IAAI,EACV,IAAKV,GAAW,CACf,KAAM,CAACW,EAAK,GAAGH,CAAK,EAAIR,EAAO,MAAM,GAAG,EACxC,GAAI,CAACW,GAAO,CAACH,EAAM,aAAe,CAAC,EACnC,MAAMI,EAAe,mBAAmBJ,EAAM,KAAK,GAAG,CAAC,EACvD,MAAO,CAACG,EAAKF,EAAaG,CAAY,CAAC,CACxC,CAAA,EACA,OAAQC,GAAUA,EAAM,MAAM,CACnC,EAZ6B,CAAC,EAe1B,CAACL,EAAOM,CAAQ,EAAIC,WAAS,IAC7B,OAAO,OAAW,IAAoB,CAAC,EACpCL,EAAiB,CACzB,EAEDM,OAAAA,EAAAA,UAAU,IAAM,CACd,MAAMC,EAAW,IAAMH,EAASJ,GAA2B,EAEpD,cAAA,iBAAiBQ,eAAcD,CAAQ,EACvC,IAAM,CACJ,OAAA,oBAAoBC,eAAcD,CAAQ,CACnD,CACF,EAAG,EAAE,EAUE,CAAE,MAAAT,EAAO,IARJ,CAA0BG,EAAUH,EAAmBF,IACjEa,gBAAcR,EAAeJ,EAAWC,CAAK,EAAGF,CAAO,EAOpC,OALN,CAA0BK,EAAUL,IACjDc,EAAA,iBAAiBT,EAAeL,CAAO,EAIZ,OAHd,IAAMI,EAAiB,EAGD,MAFvB,IAAMP,EAAiB,CAEM,CAC7C"}
1
+ {"version":3,"file":"useCookies.cjs","sources":["../../../../src/hooks/useCookies/useCookies.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\nimport type { RemoveCookieParams, SetCookieParams } from '../useCookie/useCookie';\n\nimport {\n COOKIE_EVENT,\n dispatchCookieEvent,\n removeCookie,\n removeCookieItem,\n setCookieItem\n} from '../useCookie/useCookie';\n\n/** The cookies params type */\nexport type CookieParams = Record<string, any>;\n\n/* The use cookies options type */\nexport interface UseCookiesOptions<Value> {\n /* The deserializer function to be invoked */\n deserializer?: (value: string) => Value[keyof Value];\n /* The serializer function to be invoked */\n serializer?: (value: Value[keyof Value]) => string;\n}\n\nexport const clearCookies = () => {\n document.cookie.split('; ').forEach((cookie) => {\n const [name] = cookie.split('=');\n removeCookie(name);\n });\n};\n\nconst clearCookieItems = () => {\n clearCookies();\n dispatchCookieEvent();\n};\n\n/**\n * @name useCookies\n * @description - Hook that manages cookie values\n * @category Browser\n *\n * @overload\n * @template {object} Value The type of the cookie values\n * @returns {UseCookieReturn<Value>} The value and the set function\n *\n * @example\n * const { value, set, remove, getAll, clear } = useCookies();\n */\nexport const useCookies = <Value extends CookieParams>(options?: UseCookiesOptions<Value>) => {\n const serializer = (value: Value[keyof 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 deserializer = (value: string) => {\n if (options?.deserializer) return options.deserializer(value);\n if (value === 'undefined') return undefined as unknown as Value[keyof Value];\n\n try {\n return JSON.parse(value) as Value;\n } catch {\n return value as Value[keyof Value];\n }\n };\n\n const getParsedCookies = () => {\n if (!document.cookie) return {};\n\n return Object.fromEntries(\n document.cookie\n .split('; ')\n .map((cookie) => {\n const [key, ...value] = cookie.split('=');\n if (!key || !value.length) return [];\n const decodedValue = decodeURIComponent(value.join('='));\n return [key, deserializer(decodedValue)];\n })\n .filter((entry) => entry.length)\n );\n };\n\n const [value, setValue] = useState(() => {\n if (typeof window === 'undefined') return {} as Value;\n return getParsedCookies() as Value;\n });\n\n useEffect(() => {\n const onChange = () => setValue(getParsedCookies() as Value);\n\n window.addEventListener(COOKIE_EVENT, onChange);\n return () => {\n window.removeEventListener(COOKIE_EVENT, onChange);\n };\n }, []);\n\n const set = <Key extends keyof Value>(key: Key, value: Value[Key], options?: SetCookieParams) =>\n setCookieItem(key as string, serializer(value), options);\n\n const remove = <Key extends keyof Value>(key: Key, options?: RemoveCookieParams) =>\n removeCookieItem(key as string, options);\n const getAll = () => getParsedCookies();\n const clear = () => clearCookieItems();\n\n return { value, set, remove, getAll, clear };\n};\n"],"names":["clearCookies","cookie","name","removeCookie","clearCookieItems","dispatchCookieEvent","useCookies","options","serializer","value","deserializer","getParsedCookies","key","decodedValue","entry","setValue","useState","useEffect","onChange","COOKIE_EVENT","setCookieItem","removeCookieItem"],"mappings":"iJAuBaA,EAAe,IAAM,CAChC,SAAS,OAAO,MAAM,IAAI,EAAE,QAASC,GAAW,CAC9C,KAAM,CAACC,CAAI,EAAID,EAAO,MAAM,GAAG,EAC/BE,EAAAA,aAAaD,CAAI,CAAA,CAClB,CACH,EAEME,EAAmB,IAAM,CAC7BJ,EAAA,EACAK,sBAAA,CACF,EAcaC,EAA0CC,GAAuC,CAC5F,MAAMC,EAAcC,GACdF,GAAS,WAAmBA,EAAQ,WAAWE,CAAK,EACpD,OAAOA,GAAU,SAAiBA,EAC/B,KAAK,UAAUA,CAAK,EAGvBC,EAAgBD,GAAkB,CACtC,GAAIF,GAAS,aAAc,OAAOA,EAAQ,aAAaE,CAAK,EAC5D,GAAIA,IAAU,YAEd,GAAI,CACF,OAAO,KAAK,MAAMA,CAAK,CAAA,MACjB,CACN,OAAOA,CAAA,CACT,EAGIE,EAAmB,IAClB,SAAS,OAEP,OAAO,YACZ,SAAS,OACN,MAAM,IAAI,EACV,IAAKV,GAAW,CACf,KAAM,CAACW,EAAK,GAAGH,CAAK,EAAIR,EAAO,MAAM,GAAG,EACxC,GAAI,CAACW,GAAO,CAACH,EAAM,aAAe,CAAA,EAClC,MAAMI,EAAe,mBAAmBJ,EAAM,KAAK,GAAG,CAAC,EACvD,MAAO,CAACG,EAAKF,EAAaG,CAAY,CAAC,CAAA,CACxC,EACA,OAAQC,GAAUA,EAAM,MAAM,CAAA,EAXN,CAAA,EAezB,CAACL,EAAOM,CAAQ,EAAIC,EAAAA,SAAS,IAC7B,OAAO,OAAW,IAAoB,CAAA,EACnCL,EAAA,CACR,EAEDM,OAAAA,EAAAA,UAAU,IAAM,CACd,MAAMC,EAAW,IAAMH,EAASJ,GAA2B,EAE3D,cAAO,iBAAiBQ,EAAAA,aAAcD,CAAQ,EACvC,IAAM,CACX,OAAO,oBAAoBC,EAAAA,aAAcD,CAAQ,CAAA,CACnD,EACC,EAAE,EAUE,CAAE,MAAAT,EAAO,IARJ,CAA0BG,EAAUH,EAAmBF,IACjEa,gBAAcR,EAAeJ,EAAWC,CAAK,EAAGF,CAAO,EAOpC,OALN,CAA0BK,EAAUL,IACjDc,EAAAA,iBAAiBT,EAAeL,CAAO,EAIZ,OAHd,IAAMI,EAAA,EAGgB,MAFvB,IAAMP,EAAA,CAEiB,CACvC"}