@siberiacancode/reactuse 0.2.29 → 0.2.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +71 -71
- package/dist/cjs/helpers/createContext/createContext.cjs.map +1 -1
- package/dist/cjs/helpers/createEventEmitter/createEventEmitter.cjs.map +1 -1
- package/dist/cjs/helpers/createReactiveContext/createReactiveContext.cjs.map +1 -1
- package/dist/cjs/helpers/createStore/createStore.cjs.map +1 -1
- package/dist/cjs/hooks/useActiveElement/useActiveElement.cjs.map +1 -1
- package/dist/cjs/hooks/useAsync/useAsync.cjs.map +1 -1
- package/dist/cjs/hooks/useAudio/useAudio.cjs.map +1 -1
- package/dist/cjs/hooks/useAutoScroll/useAutoScroll.cjs +1 -1
- package/dist/cjs/hooks/useAutoScroll/useAutoScroll.cjs.map +1 -1
- package/dist/cjs/hooks/useBattery/useBattery.cjs +1 -1
- package/dist/cjs/hooks/useBattery/useBattery.cjs.map +1 -1
- package/dist/cjs/hooks/useBluetooth/useBluetooth.cjs +1 -1
- package/dist/cjs/hooks/useBluetooth/useBluetooth.cjs.map +1 -1
- package/dist/cjs/hooks/useBoolean/useBoolean.cjs.map +1 -1
- package/dist/cjs/hooks/useBreakpoints/useBreakpoints.cjs.map +1 -1
- package/dist/cjs/hooks/useBroadcastChannel/useBroadcastChannel.cjs +1 -1
- package/dist/cjs/hooks/useBroadcastChannel/useBroadcastChannel.cjs.map +1 -1
- package/dist/cjs/hooks/useBrowserLanguage/useBrowserLanguage.cjs.map +1 -1
- package/dist/cjs/hooks/useClickOutside/useClickOutside.cjs.map +1 -1
- package/dist/cjs/hooks/useClipboard/useClipboard.cjs.map +1 -1
- package/dist/cjs/hooks/useConst/useConst.cjs.map +1 -1
- package/dist/cjs/hooks/useCookie/useCookie.cjs.map +1 -1
- package/dist/cjs/hooks/useCookies/useCookies.cjs.map +1 -1
- package/dist/cjs/hooks/useCopy/useCopy.cjs.map +1 -1
- package/dist/cjs/hooks/useCounter/useCounter.cjs.map +1 -1
- package/dist/cjs/hooks/useCssVar/useCssVar.cjs.map +1 -1
- package/dist/cjs/hooks/useDebounceCallback/useDebounceCallback.cjs.map +1 -1
- package/dist/cjs/hooks/useDebounceState/useDebounceState.cjs +2 -0
- package/dist/cjs/hooks/useDebounceState/useDebounceState.cjs.map +1 -0
- package/dist/cjs/hooks/useDebounceValue/useDebounceValue.cjs.map +1 -1
- package/dist/cjs/hooks/useDefault/useDefault.cjs.map +1 -1
- package/dist/cjs/hooks/useDeviceMotion/useDeviceMotion.cjs.map +1 -1
- package/dist/cjs/hooks/useDeviceOrientation/useDeviceOrientation.cjs +1 -1
- package/dist/cjs/hooks/useDeviceOrientation/useDeviceOrientation.cjs.map +1 -1
- package/dist/cjs/hooks/useDevicePixelRatio/useDevicePixelRatio.cjs +1 -1
- package/dist/cjs/hooks/useDevicePixelRatio/useDevicePixelRatio.cjs.map +1 -1
- package/dist/cjs/hooks/useDidUpdate/useDidUpdate.cjs.map +1 -1
- package/dist/cjs/hooks/useDisclosure/useDisclosure.cjs.map +1 -1
- package/dist/cjs/hooks/useDisplayMedia/useDisplayMedia.cjs.map +1 -1
- package/dist/cjs/hooks/useDocumentEvent/useDocumentEvent.cjs.map +1 -1
- package/dist/cjs/hooks/useDocumentTitle/useDocumentTitle.cjs.map +1 -1
- package/dist/cjs/hooks/useDocumentVisibility/useDocumentVisibility.cjs.map +1 -1
- package/dist/cjs/hooks/useDoubleClick/useDoubleClick.cjs.map +1 -1
- package/dist/cjs/hooks/useDropZone/useDropZone.cjs +1 -1
- package/dist/cjs/hooks/useDropZone/useDropZone.cjs.map +1 -1
- package/dist/cjs/hooks/useElementSize/useElementSize.cjs.map +1 -1
- package/dist/cjs/hooks/useEvent/useEvent.cjs.map +1 -1
- package/dist/cjs/hooks/useEventListener/useEventListener.cjs +1 -1
- package/dist/cjs/hooks/useEventListener/useEventListener.cjs.map +1 -1
- package/dist/cjs/hooks/useEventSource/useEventSource.cjs.map +1 -1
- package/dist/cjs/hooks/useEyeDropper/useEyeDropper.cjs +1 -1
- package/dist/cjs/hooks/useEyeDropper/useEyeDropper.cjs.map +1 -1
- package/dist/cjs/hooks/useFavicon/useFavicon.cjs +1 -1
- package/dist/cjs/hooks/useFavicon/useFavicon.cjs.map +1 -1
- package/dist/cjs/hooks/useField/useField.cjs.map +1 -1
- package/dist/cjs/hooks/useFileDialog/useFileDialog.cjs.map +1 -1
- package/dist/cjs/hooks/useFocus/useFocus.cjs +1 -1
- package/dist/cjs/hooks/useFocus/useFocus.cjs.map +1 -1
- package/dist/cjs/hooks/useFps/useFps.cjs.map +1 -1
- package/dist/cjs/hooks/useFul/useFul.cjs.map +1 -1
- package/dist/cjs/hooks/useFullscreen/useFullscreen.cjs.map +1 -1
- package/dist/cjs/hooks/useGamepad/useGamepad.cjs +1 -1
- package/dist/cjs/hooks/useGamepad/useGamepad.cjs.map +1 -1
- package/dist/cjs/hooks/useGeolocation/useGeolocation.cjs.map +1 -1
- package/dist/cjs/hooks/useHash/useHash.cjs.map +1 -1
- package/dist/cjs/hooks/useHotkeys/useHotkeys.cjs.map +1 -1
- package/dist/cjs/hooks/useHover/useHover.cjs +1 -1
- package/dist/cjs/hooks/useHover/useHover.cjs.map +1 -1
- package/dist/cjs/hooks/useIdle/useIdle.cjs.map +1 -1
- package/dist/cjs/hooks/useImage/useImage.cjs.map +1 -1
- package/dist/cjs/hooks/useInfiniteScroll/useInfiniteScroll.cjs.map +1 -1
- package/dist/cjs/hooks/useIntersectionObserver/useIntersectionObserver.cjs +1 -1
- package/dist/cjs/hooks/useIntersectionObserver/useIntersectionObserver.cjs.map +1 -1
- package/dist/cjs/hooks/useInterval/useInterval.cjs.map +1 -1
- package/dist/cjs/hooks/useIsFirstRender/useIsFirstRender.cjs.map +1 -1
- package/dist/cjs/hooks/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.cjs.map +1 -1
- package/dist/cjs/hooks/useKeyPress/useKeyPress.cjs.map +1 -1
- package/dist/cjs/hooks/useKeyPressEvent/useKeyPressEvent.cjs.map +1 -1
- package/dist/cjs/hooks/useKeyboard/useKeyboard.cjs.map +1 -1
- package/dist/cjs/hooks/useKeysPressed/useKeysPressed.cjs.map +1 -1
- package/dist/cjs/hooks/useLastChanged/useLastChanged.cjs.map +1 -1
- package/dist/cjs/hooks/useLatest/useLatest.cjs.map +1 -1
- package/dist/cjs/hooks/useLess/useLess.cjs.map +1 -1
- package/dist/cjs/hooks/useList/useList.cjs.map +1 -1
- package/dist/cjs/hooks/useLocalStorage/useLocalStorage.cjs.map +1 -1
- package/dist/cjs/hooks/useLockCallback/useLockCallback.cjs.map +1 -1
- package/dist/cjs/hooks/useLockScroll/useLockScroll.cjs.map +1 -1
- package/dist/cjs/hooks/useLogger/useLogger.cjs.map +1 -1
- package/dist/cjs/hooks/useLongPress/useLongPress.cjs.map +1 -1
- package/dist/cjs/hooks/useMap/useMap.cjs.map +1 -1
- package/dist/cjs/hooks/useMeasure/useMeasure.cjs.map +1 -1
- package/dist/cjs/hooks/useMediaControls/useMediaControls.cjs.map +1 -1
- package/dist/cjs/hooks/useMediaQuery/useMediaQuery.cjs.map +1 -1
- package/dist/cjs/hooks/useMemory/useMemory.cjs +1 -1
- package/dist/cjs/hooks/useMemory/useMemory.cjs.map +1 -1
- package/dist/cjs/hooks/useMergedRef/useMergedRef.cjs +2 -0
- package/dist/cjs/hooks/useMergedRef/useMergedRef.cjs.map +1 -0
- package/dist/cjs/hooks/useMount/useMount.cjs.map +1 -1
- package/dist/cjs/hooks/useMouse/useMouse.cjs.map +1 -1
- package/dist/cjs/hooks/useMutation/useMutation.cjs +1 -1
- package/dist/cjs/hooks/useMutation/useMutation.cjs.map +1 -1
- package/dist/cjs/hooks/useMutationObserver/useMutationObserver.cjs +1 -1
- package/dist/cjs/hooks/useMutationObserver/useMutationObserver.cjs.map +1 -1
- package/dist/cjs/hooks/useNetwork/useNetwork.cjs.map +1 -1
- package/dist/cjs/hooks/useOffsetPagination/useOffsetPagination.cjs.map +1 -1
- package/dist/cjs/hooks/useOnce/useOnce.cjs.map +1 -1
- package/dist/cjs/hooks/useOnline/useOnline.cjs.map +1 -1
- package/dist/cjs/hooks/useOperatingSystem/useOperatingSystem.cjs.map +1 -1
- package/dist/cjs/hooks/useOptimistic/useOptimistic.cjs.map +1 -1
- package/dist/cjs/hooks/useOrientation/useOrientation.cjs +1 -1
- package/dist/cjs/hooks/useOrientation/useOrientation.cjs.map +1 -1
- package/dist/cjs/hooks/useOtpCredential/useOtpCredential.cjs +1 -1
- package/dist/cjs/hooks/useOtpCredential/useOtpCredential.cjs.map +1 -1
- package/dist/cjs/hooks/usePageLeave/usePageLeave.cjs.map +1 -1
- package/dist/cjs/hooks/usePaint/usePaint.cjs.map +1 -1
- package/dist/cjs/hooks/useParallax/useParallax.cjs.map +1 -1
- package/dist/cjs/hooks/usePerformanceObserver/usePerformanceObserver.cjs +1 -1
- package/dist/cjs/hooks/usePerformanceObserver/usePerformanceObserver.cjs.map +1 -1
- package/dist/cjs/hooks/usePermission/usePermission.cjs +1 -1
- package/dist/cjs/hooks/usePermission/usePermission.cjs.map +1 -1
- package/dist/cjs/hooks/usePictureInPicture/usePictureInPicture.cjs +1 -1
- package/dist/cjs/hooks/usePictureInPicture/usePictureInPicture.cjs.map +1 -1
- package/dist/cjs/hooks/usePointerLock/usePointerLock.cjs +1 -1
- package/dist/cjs/hooks/usePointerLock/usePointerLock.cjs.map +1 -1
- package/dist/cjs/hooks/usePostMessage/usePostMessage.cjs.map +1 -1
- package/dist/cjs/hooks/usePreferredColorScheme/usePreferredColorScheme.cjs.map +1 -1
- package/dist/cjs/hooks/usePreferredContrast/usePreferredContrast.cjs.map +1 -1
- package/dist/cjs/hooks/usePreferredDark/usePreferredDark.cjs.map +1 -1
- package/dist/cjs/hooks/usePreferredLanguages/usePreferredLanguages.cjs.map +1 -1
- package/dist/cjs/hooks/usePreferredReducedMotion/usePreferredReducedMotion.cjs.map +1 -1
- package/dist/cjs/hooks/usePrevious/usePrevious.cjs.map +1 -1
- package/dist/cjs/hooks/useQuery/useQuery.cjs.map +1 -1
- package/dist/cjs/hooks/useQueue/useQueue.cjs.map +1 -1
- package/dist/cjs/hooks/useRaf/useRaf.cjs.map +1 -1
- package/dist/cjs/hooks/useRafState/useRafState.cjs.map +1 -1
- package/dist/cjs/hooks/useRefState/useRefState.cjs.map +1 -1
- package/dist/cjs/hooks/useRenderCount/useRenderCount.cjs.map +1 -1
- package/dist/cjs/hooks/useRenderInfo/useRenderInfo.cjs.map +1 -1
- package/dist/cjs/hooks/useRerender/useRerender.cjs.map +1 -1
- package/dist/cjs/hooks/useResizeObserver/useResizeObserver.cjs +1 -1
- package/dist/cjs/hooks/useResizeObserver/useResizeObserver.cjs.map +1 -1
- package/dist/cjs/hooks/useRightClick/useRightClick.cjs.map +1 -1
- package/dist/cjs/hooks/useScript/useScript.cjs.map +1 -1
- package/dist/cjs/hooks/useScroll/useScroll.cjs.map +1 -1
- package/dist/cjs/hooks/useScrollIntoView/useScrollIntoView.cjs.map +1 -1
- package/dist/cjs/hooks/useScrollTo/useScrollTo.cjs.map +1 -1
- package/dist/cjs/hooks/useSessionStorage/useSessionStorage.cjs.map +1 -1
- package/dist/cjs/hooks/useSet/useSet.cjs.map +1 -1
- package/dist/cjs/hooks/useShallowEffect/useShallowEffect.cjs.map +1 -1
- package/dist/cjs/hooks/useShare/useShare.cjs +1 -1
- package/dist/cjs/hooks/useShare/useShare.cjs.map +1 -1
- package/dist/cjs/hooks/useSpeechRecognition/useSpeechRecognition.cjs.map +1 -1
- package/dist/cjs/hooks/useSpeechSynthesis/useSpeechSynthesis.cjs +1 -1
- package/dist/cjs/hooks/useSpeechSynthesis/useSpeechSynthesis.cjs.map +1 -1
- package/dist/cjs/hooks/useStateHistory/useStateHistory.cjs.map +1 -1
- package/dist/cjs/hooks/useStep/useStep.cjs.map +1 -1
- package/dist/cjs/hooks/useSticky/useSticky.cjs.map +1 -1
- package/dist/cjs/hooks/useStopwatch/useStopwatch.cjs.map +1 -1
- package/dist/cjs/hooks/useStorage/useStorage.cjs.map +1 -1
- package/dist/cjs/hooks/useTextDirection/useTextDirection.cjs +1 -1
- package/dist/cjs/hooks/useTextDirection/useTextDirection.cjs.map +1 -1
- package/dist/cjs/hooks/useTextSelection/useTextSelection.cjs.map +1 -1
- package/dist/cjs/hooks/useThrottleCallback/useThrottleCallback.cjs.map +1 -1
- package/dist/cjs/hooks/useThrottleState/useThrottleState.cjs +2 -0
- package/dist/cjs/hooks/useThrottleState/useThrottleState.cjs.map +1 -0
- package/dist/cjs/hooks/useThrottleValue/useThrottleValue.cjs.map +1 -1
- package/dist/cjs/hooks/useTime/useTime.cjs.map +1 -1
- package/dist/cjs/hooks/useTimeout/useTimeout.cjs.map +1 -1
- package/dist/cjs/hooks/useTimer/useTimer.cjs.map +1 -1
- package/dist/cjs/hooks/useToggle/useToggle.cjs.map +1 -1
- package/dist/cjs/hooks/useUnmount/useUnmount.cjs.map +1 -1
- package/dist/cjs/hooks/useUrlSearchParam/useUrlSearchParam.cjs.map +1 -1
- package/dist/cjs/hooks/useUrlSearchParams/useUrlSearchParams.cjs.map +1 -1
- package/dist/cjs/hooks/useVibrate/useVibrate.cjs +1 -1
- package/dist/cjs/hooks/useVibrate/useVibrate.cjs.map +1 -1
- package/dist/cjs/hooks/useVirtualKeyboard/useVirtualKeyboard.cjs +1 -1
- package/dist/cjs/hooks/useVirtualKeyboard/useVirtualKeyboard.cjs.map +1 -1
- package/dist/cjs/hooks/useWakeLock/useWakeLock.cjs +1 -1
- package/dist/cjs/hooks/useWakeLock/useWakeLock.cjs.map +1 -1
- package/dist/cjs/hooks/useWebSocket/useWebSocket.cjs.map +1 -1
- package/dist/cjs/hooks/useWindowEvent/useWindowEvent.cjs.map +1 -1
- package/dist/cjs/hooks/useWindowFocus/useWindowFocus.cjs.map +1 -1
- package/dist/cjs/hooks/useWindowScroll/useWindowScroll.cjs.map +1 -1
- package/dist/cjs/hooks/useWindowSize/useWindowSize.cjs.map +1 -1
- package/dist/cjs/hooks/useWizard/useWizard.cjs.map +1 -1
- package/dist/cjs/index.cjs +1 -1
- package/dist/esm/helpers/createContext/createContext.mjs.map +1 -1
- package/dist/esm/helpers/createEventEmitter/createEventEmitter.mjs.map +1 -1
- package/dist/esm/helpers/createReactiveContext/createReactiveContext.mjs.map +1 -1
- package/dist/esm/helpers/createStore/createStore.mjs.map +1 -1
- package/dist/esm/hooks/useActiveElement/useActiveElement.mjs.map +1 -1
- package/dist/esm/hooks/useAsync/useAsync.mjs.map +1 -1
- package/dist/esm/hooks/useAudio/useAudio.mjs.map +1 -1
- package/dist/esm/hooks/useAutoScroll/useAutoScroll.mjs +25 -31
- package/dist/esm/hooks/useAutoScroll/useAutoScroll.mjs.map +1 -1
- package/dist/esm/hooks/useBattery/useBattery.mjs +1 -1
- package/dist/esm/hooks/useBattery/useBattery.mjs.map +1 -1
- package/dist/esm/hooks/useBluetooth/useBluetooth.mjs +16 -18
- package/dist/esm/hooks/useBluetooth/useBluetooth.mjs.map +1 -1
- package/dist/esm/hooks/useBoolean/useBoolean.mjs.map +1 -1
- package/dist/esm/hooks/useBreakpoints/useBreakpoints.mjs.map +1 -1
- package/dist/esm/hooks/useBroadcastChannel/useBroadcastChannel.mjs +8 -8
- package/dist/esm/hooks/useBroadcastChannel/useBroadcastChannel.mjs.map +1 -1
- package/dist/esm/hooks/useBrowserLanguage/useBrowserLanguage.mjs.map +1 -1
- package/dist/esm/hooks/useClickOutside/useClickOutside.mjs.map +1 -1
- package/dist/esm/hooks/useClipboard/useClipboard.mjs.map +1 -1
- package/dist/esm/hooks/useConst/useConst.mjs.map +1 -1
- package/dist/esm/hooks/useCookie/useCookie.mjs.map +1 -1
- package/dist/esm/hooks/useCookies/useCookies.mjs.map +1 -1
- package/dist/esm/hooks/useCopy/useCopy.mjs.map +1 -1
- package/dist/esm/hooks/useCounter/useCounter.mjs.map +1 -1
- package/dist/esm/hooks/useCssVar/useCssVar.mjs.map +1 -1
- package/dist/esm/hooks/useDebounceCallback/useDebounceCallback.mjs.map +1 -1
- package/dist/esm/hooks/useDebounceState/useDebounceState.mjs +10 -0
- package/dist/esm/hooks/useDebounceState/useDebounceState.mjs.map +1 -0
- package/dist/esm/hooks/useDebounceValue/useDebounceValue.mjs.map +1 -1
- package/dist/esm/hooks/useDefault/useDefault.mjs.map +1 -1
- package/dist/esm/hooks/useDeviceMotion/useDeviceMotion.mjs.map +1 -1
- package/dist/esm/hooks/useDeviceOrientation/useDeviceOrientation.mjs +1 -1
- package/dist/esm/hooks/useDeviceOrientation/useDeviceOrientation.mjs.map +1 -1
- package/dist/esm/hooks/useDevicePixelRatio/useDevicePixelRatio.mjs +1 -1
- package/dist/esm/hooks/useDevicePixelRatio/useDevicePixelRatio.mjs.map +1 -1
- package/dist/esm/hooks/useDidUpdate/useDidUpdate.mjs.map +1 -1
- package/dist/esm/hooks/useDisclosure/useDisclosure.mjs.map +1 -1
- package/dist/esm/hooks/useDisplayMedia/useDisplayMedia.mjs.map +1 -1
- package/dist/esm/hooks/useDocumentEvent/useDocumentEvent.mjs.map +1 -1
- package/dist/esm/hooks/useDocumentTitle/useDocumentTitle.mjs.map +1 -1
- package/dist/esm/hooks/useDocumentVisibility/useDocumentVisibility.mjs.map +1 -1
- package/dist/esm/hooks/useDoubleClick/useDoubleClick.mjs.map +1 -1
- package/dist/esm/hooks/useDropZone/useDropZone.mjs +12 -12
- package/dist/esm/hooks/useDropZone/useDropZone.mjs.map +1 -1
- package/dist/esm/hooks/useElementSize/useElementSize.mjs.map +1 -1
- package/dist/esm/hooks/useEvent/useEvent.mjs.map +1 -1
- package/dist/esm/hooks/useEventListener/useEventListener.mjs +15 -15
- package/dist/esm/hooks/useEventListener/useEventListener.mjs.map +1 -1
- package/dist/esm/hooks/useEventSource/useEventSource.mjs.map +1 -1
- package/dist/esm/hooks/useEyeDropper/useEyeDropper.mjs +3 -3
- package/dist/esm/hooks/useEyeDropper/useEyeDropper.mjs.map +1 -1
- package/dist/esm/hooks/useFavicon/useFavicon.mjs +12 -15
- package/dist/esm/hooks/useFavicon/useFavicon.mjs.map +1 -1
- package/dist/esm/hooks/useField/useField.mjs.map +1 -1
- package/dist/esm/hooks/useFileDialog/useFileDialog.mjs.map +1 -1
- package/dist/esm/hooks/useFocus/useFocus.mjs +26 -22
- package/dist/esm/hooks/useFocus/useFocus.mjs.map +1 -1
- package/dist/esm/hooks/useFps/useFps.mjs.map +1 -1
- package/dist/esm/hooks/useFul/useFul.mjs.map +1 -1
- package/dist/esm/hooks/useFullscreen/useFullscreen.mjs.map +1 -1
- package/dist/esm/hooks/useGamepad/useGamepad.mjs +13 -13
- package/dist/esm/hooks/useGamepad/useGamepad.mjs.map +1 -1
- package/dist/esm/hooks/useGeolocation/useGeolocation.mjs.map +1 -1
- package/dist/esm/hooks/useHash/useHash.mjs.map +1 -1
- package/dist/esm/hooks/useHotkeys/useHotkeys.mjs.map +1 -1
- package/dist/esm/hooks/useHover/useHover.mjs +15 -15
- package/dist/esm/hooks/useHover/useHover.mjs.map +1 -1
- package/dist/esm/hooks/useIdle/useIdle.mjs.map +1 -1
- package/dist/esm/hooks/useImage/useImage.mjs.map +1 -1
- package/dist/esm/hooks/useInfiniteScroll/useInfiniteScroll.mjs.map +1 -1
- package/dist/esm/hooks/useIntersectionObserver/useIntersectionObserver.mjs +19 -18
- package/dist/esm/hooks/useIntersectionObserver/useIntersectionObserver.mjs.map +1 -1
- package/dist/esm/hooks/useInterval/useInterval.mjs.map +1 -1
- package/dist/esm/hooks/useIsFirstRender/useIsFirstRender.mjs.map +1 -1
- package/dist/esm/hooks/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.mjs.map +1 -1
- package/dist/esm/hooks/useKeyPress/useKeyPress.mjs.map +1 -1
- package/dist/esm/hooks/useKeyPressEvent/useKeyPressEvent.mjs.map +1 -1
- package/dist/esm/hooks/useKeyboard/useKeyboard.mjs.map +1 -1
- package/dist/esm/hooks/useKeysPressed/useKeysPressed.mjs.map +1 -1
- package/dist/esm/hooks/useLastChanged/useLastChanged.mjs.map +1 -1
- package/dist/esm/hooks/useLatest/useLatest.mjs.map +1 -1
- package/dist/esm/hooks/useLess/useLess.mjs.map +1 -1
- package/dist/esm/hooks/useList/useList.mjs.map +1 -1
- package/dist/esm/hooks/useLocalStorage/useLocalStorage.mjs.map +1 -1
- package/dist/esm/hooks/useLockCallback/useLockCallback.mjs.map +1 -1
- package/dist/esm/hooks/useLockScroll/useLockScroll.mjs.map +1 -1
- package/dist/esm/hooks/useLogger/useLogger.mjs.map +1 -1
- package/dist/esm/hooks/useLongPress/useLongPress.mjs.map +1 -1
- package/dist/esm/hooks/useMap/useMap.mjs.map +1 -1
- package/dist/esm/hooks/useMeasure/useMeasure.mjs.map +1 -1
- package/dist/esm/hooks/useMediaControls/useMediaControls.mjs.map +1 -1
- package/dist/esm/hooks/useMediaQuery/useMediaQuery.mjs.map +1 -1
- package/dist/esm/hooks/useMemory/useMemory.mjs +4 -4
- package/dist/esm/hooks/useMemory/useMemory.mjs.map +1 -1
- package/dist/esm/hooks/useMergedRef/useMergedRef.mjs +25 -0
- package/dist/esm/hooks/useMergedRef/useMergedRef.mjs.map +1 -0
- package/dist/esm/hooks/useMount/useMount.mjs.map +1 -1
- package/dist/esm/hooks/useMouse/useMouse.mjs.map +1 -1
- package/dist/esm/hooks/useMutation/useMutation.mjs +18 -18
- package/dist/esm/hooks/useMutation/useMutation.mjs.map +1 -1
- package/dist/esm/hooks/useMutationObserver/useMutationObserver.mjs +28 -20
- package/dist/esm/hooks/useMutationObserver/useMutationObserver.mjs.map +1 -1
- package/dist/esm/hooks/useNetwork/useNetwork.mjs.map +1 -1
- package/dist/esm/hooks/useOffsetPagination/useOffsetPagination.mjs.map +1 -1
- package/dist/esm/hooks/useOnce/useOnce.mjs.map +1 -1
- package/dist/esm/hooks/useOnline/useOnline.mjs.map +1 -1
- package/dist/esm/hooks/useOperatingSystem/useOperatingSystem.mjs.map +1 -1
- package/dist/esm/hooks/useOptimistic/useOptimistic.mjs.map +1 -1
- package/dist/esm/hooks/useOrientation/useOrientation.mjs +9 -9
- package/dist/esm/hooks/useOrientation/useOrientation.mjs.map +1 -1
- package/dist/esm/hooks/useOtpCredential/useOtpCredential.mjs +3 -3
- package/dist/esm/hooks/useOtpCredential/useOtpCredential.mjs.map +1 -1
- package/dist/esm/hooks/usePageLeave/usePageLeave.mjs.map +1 -1
- package/dist/esm/hooks/usePaint/usePaint.mjs.map +1 -1
- package/dist/esm/hooks/useParallax/useParallax.mjs.map +1 -1
- package/dist/esm/hooks/usePerformanceObserver/usePerformanceObserver.mjs +11 -11
- package/dist/esm/hooks/usePerformanceObserver/usePerformanceObserver.mjs.map +1 -1
- package/dist/esm/hooks/usePermission/usePermission.mjs +4 -4
- package/dist/esm/hooks/usePermission/usePermission.mjs.map +1 -1
- package/dist/esm/hooks/usePictureInPicture/usePictureInPicture.mjs +17 -17
- package/dist/esm/hooks/usePictureInPicture/usePictureInPicture.mjs.map +1 -1
- package/dist/esm/hooks/usePointerLock/usePointerLock.mjs +3 -3
- package/dist/esm/hooks/usePointerLock/usePointerLock.mjs.map +1 -1
- package/dist/esm/hooks/usePostMessage/usePostMessage.mjs.map +1 -1
- package/dist/esm/hooks/usePreferredColorScheme/usePreferredColorScheme.mjs.map +1 -1
- package/dist/esm/hooks/usePreferredContrast/usePreferredContrast.mjs.map +1 -1
- package/dist/esm/hooks/usePreferredDark/usePreferredDark.mjs.map +1 -1
- package/dist/esm/hooks/usePreferredLanguages/usePreferredLanguages.mjs.map +1 -1
- package/dist/esm/hooks/usePreferredReducedMotion/usePreferredReducedMotion.mjs.map +1 -1
- package/dist/esm/hooks/usePrevious/usePrevious.mjs.map +1 -1
- package/dist/esm/hooks/useQuery/useQuery.mjs.map +1 -1
- package/dist/esm/hooks/useQueue/useQueue.mjs.map +1 -1
- package/dist/esm/hooks/useRaf/useRaf.mjs.map +1 -1
- package/dist/esm/hooks/useRafState/useRafState.mjs.map +1 -1
- package/dist/esm/hooks/useRefState/useRefState.mjs.map +1 -1
- package/dist/esm/hooks/useRenderCount/useRenderCount.mjs.map +1 -1
- package/dist/esm/hooks/useRenderInfo/useRenderInfo.mjs.map +1 -1
- package/dist/esm/hooks/useRerender/useRerender.mjs.map +1 -1
- package/dist/esm/hooks/useResizeObserver/useResizeObserver.mjs +17 -16
- package/dist/esm/hooks/useResizeObserver/useResizeObserver.mjs.map +1 -1
- package/dist/esm/hooks/useRightClick/useRightClick.mjs.map +1 -1
- package/dist/esm/hooks/useScript/useScript.mjs.map +1 -1
- package/dist/esm/hooks/useScroll/useScroll.mjs.map +1 -1
- package/dist/esm/hooks/useScrollIntoView/useScrollIntoView.mjs.map +1 -1
- package/dist/esm/hooks/useScrollTo/useScrollTo.mjs.map +1 -1
- package/dist/esm/hooks/useSessionStorage/useSessionStorage.mjs.map +1 -1
- package/dist/esm/hooks/useSet/useSet.mjs.map +1 -1
- package/dist/esm/hooks/useShallowEffect/useShallowEffect.mjs.map +1 -1
- package/dist/esm/hooks/useShare/useShare.mjs +1 -1
- package/dist/esm/hooks/useShare/useShare.mjs.map +1 -1
- package/dist/esm/hooks/useSpeechRecognition/useSpeechRecognition.mjs.map +1 -1
- package/dist/esm/hooks/useSpeechSynthesis/useSpeechSynthesis.mjs +11 -11
- package/dist/esm/hooks/useSpeechSynthesis/useSpeechSynthesis.mjs.map +1 -1
- package/dist/esm/hooks/useStateHistory/useStateHistory.mjs.map +1 -1
- package/dist/esm/hooks/useStep/useStep.mjs.map +1 -1
- package/dist/esm/hooks/useSticky/useSticky.mjs.map +1 -1
- package/dist/esm/hooks/useStopwatch/useStopwatch.mjs.map +1 -1
- package/dist/esm/hooks/useStorage/useStorage.mjs.map +1 -1
- package/dist/esm/hooks/useTextDirection/useTextDirection.mjs +14 -14
- package/dist/esm/hooks/useTextDirection/useTextDirection.mjs.map +1 -1
- package/dist/esm/hooks/useTextSelection/useTextSelection.mjs.map +1 -1
- package/dist/esm/hooks/useThrottleCallback/useThrottleCallback.mjs.map +1 -1
- package/dist/esm/hooks/useThrottleState/useThrottleState.mjs +10 -0
- package/dist/esm/hooks/useThrottleState/useThrottleState.mjs.map +1 -0
- package/dist/esm/hooks/useThrottleValue/useThrottleValue.mjs.map +1 -1
- package/dist/esm/hooks/useTime/useTime.mjs.map +1 -1
- package/dist/esm/hooks/useTimeout/useTimeout.mjs.map +1 -1
- package/dist/esm/hooks/useTimer/useTimer.mjs.map +1 -1
- package/dist/esm/hooks/useToggle/useToggle.mjs.map +1 -1
- package/dist/esm/hooks/useUnmount/useUnmount.mjs.map +1 -1
- package/dist/esm/hooks/useUrlSearchParam/useUrlSearchParam.mjs.map +1 -1
- package/dist/esm/hooks/useUrlSearchParams/useUrlSearchParams.mjs.map +1 -1
- package/dist/esm/hooks/useVibrate/useVibrate.mjs +12 -12
- package/dist/esm/hooks/useVibrate/useVibrate.mjs.map +1 -1
- package/dist/esm/hooks/useVirtualKeyboard/useVirtualKeyboard.mjs +7 -7
- package/dist/esm/hooks/useVirtualKeyboard/useVirtualKeyboard.mjs.map +1 -1
- package/dist/esm/hooks/useWakeLock/useWakeLock.mjs +1 -1
- package/dist/esm/hooks/useWakeLock/useWakeLock.mjs.map +1 -1
- package/dist/esm/hooks/useWebSocket/useWebSocket.mjs.map +1 -1
- package/dist/esm/hooks/useWindowEvent/useWindowEvent.mjs.map +1 -1
- package/dist/esm/hooks/useWindowFocus/useWindowFocus.mjs.map +1 -1
- package/dist/esm/hooks/useWindowScroll/useWindowScroll.mjs.map +1 -1
- package/dist/esm/hooks/useWindowSize/useWindowSize.mjs.map +1 -1
- package/dist/esm/hooks/useWizard/useWizard.mjs.map +1 -1
- package/dist/esm/index.mjs +147 -139
- package/dist/esm/index.mjs.map +1 -1
- package/dist/types/helpers/createContext/createContext.d.ts +1 -0
- package/dist/types/helpers/createEventEmitter/createEventEmitter.d.ts +1 -0
- package/dist/types/helpers/createReactiveContext/createReactiveContext.d.ts +1 -0
- package/dist/types/helpers/createStore/createStore.d.ts +1 -0
- package/dist/types/hooks/state.d.ts +1 -0
- package/dist/types/hooks/useActiveElement/useActiveElement.d.ts +1 -0
- package/dist/types/hooks/useAsync/useAsync.d.ts +1 -0
- package/dist/types/hooks/useAudio/useAudio.d.ts +2 -1
- package/dist/types/hooks/useAutoScroll/useAutoScroll.d.ts +1 -0
- package/dist/types/hooks/useBattery/useBattery.d.ts +1 -0
- package/dist/types/hooks/useBluetooth/useBluetooth.d.ts +1 -0
- package/dist/types/hooks/useBoolean/useBoolean.d.ts +2 -1
- package/dist/types/hooks/useBreakpoints/useBreakpoints.d.ts +1 -0
- package/dist/types/hooks/useBroadcastChannel/useBroadcastChannel.d.ts +1 -0
- package/dist/types/hooks/useBrowserLanguage/useBrowserLanguage.d.ts +2 -1
- package/dist/types/hooks/useClickOutside/useClickOutside.d.ts +2 -1
- package/dist/types/hooks/useClipboard/useClipboard.d.ts +2 -1
- package/dist/types/hooks/useConst/useConst.d.ts +2 -1
- package/dist/types/hooks/useCookie/useCookie.d.ts +2 -1
- package/dist/types/hooks/useCookies/useCookies.d.ts +2 -1
- package/dist/types/hooks/useCopy/useCopy.d.ts +2 -1
- package/dist/types/hooks/useCounter/useCounter.d.ts +2 -1
- package/dist/types/hooks/useCssVar/useCssVar.d.ts +2 -1
- package/dist/types/hooks/useDebounceCallback/useDebounceCallback.d.ts +1 -0
- package/dist/types/hooks/useDebounceState/useDebounceState.d.ts +15 -0
- package/dist/types/hooks/useDebounceValue/useDebounceValue.d.ts +2 -1
- package/dist/types/hooks/useDefault/useDefault.d.ts +2 -1
- package/dist/types/hooks/useDeviceMotion/useDeviceMotion.d.ts +2 -1
- package/dist/types/hooks/useDeviceOrientation/useDeviceOrientation.d.ts +1 -0
- package/dist/types/hooks/useDevicePixelRatio/useDevicePixelRatio.d.ts +1 -0
- package/dist/types/hooks/useDidUpdate/useDidUpdate.d.ts +2 -1
- package/dist/types/hooks/useDisclosure/useDisclosure.d.ts +2 -1
- package/dist/types/hooks/useDisplayMedia/useDisplayMedia.d.ts +1 -0
- package/dist/types/hooks/useDocumentEvent/useDocumentEvent.d.ts +2 -1
- package/dist/types/hooks/useDocumentTitle/useDocumentTitle.d.ts +2 -1
- package/dist/types/hooks/useDocumentVisibility/useDocumentVisibility.d.ts +2 -1
- package/dist/types/hooks/useDoubleClick/useDoubleClick.d.ts +2 -1
- package/dist/types/hooks/useDropZone/useDropZone.d.ts +2 -1
- package/dist/types/hooks/useElementSize/useElementSize.d.ts +2 -1
- package/dist/types/hooks/useEvent/useEvent.d.ts +2 -1
- package/dist/types/hooks/useEventListener/useEventListener.d.ts +5 -2
- package/dist/types/hooks/useEventSource/useEventSource.d.ts +1 -0
- package/dist/types/hooks/useEyeDropper/useEyeDropper.d.ts +1 -0
- package/dist/types/hooks/useFavicon/useFavicon.d.ts +2 -1
- package/dist/types/hooks/useField/useField.d.ts +1 -0
- package/dist/types/hooks/useFileDialog/useFileDialog.d.ts +1 -0
- package/dist/types/hooks/useFocus/useFocus.d.ts +25 -0
- package/dist/types/hooks/useFps/useFps.d.ts +1 -0
- package/dist/types/hooks/useFul/useFul.d.ts +1 -0
- package/dist/types/hooks/useFullscreen/useFullscreen.d.ts +1 -0
- package/dist/types/hooks/useGamepad/useGamepad.d.ts +1 -0
- package/dist/types/hooks/useGeolocation/useGeolocation.d.ts +1 -0
- package/dist/types/hooks/useHash/useHash.d.ts +1 -0
- package/dist/types/hooks/useHotkeys/useHotkeys.d.ts +1 -0
- package/dist/types/hooks/useHover/useHover.d.ts +3 -0
- package/dist/types/hooks/useIdle/useIdle.d.ts +1 -0
- package/dist/types/hooks/useImage/useImage.d.ts +1 -0
- package/dist/types/hooks/useInfiniteScroll/useInfiniteScroll.d.ts +1 -0
- package/dist/types/hooks/useIntersectionObserver/useIntersectionObserver.d.ts +15 -6
- package/dist/types/hooks/useInterval/useInterval.d.ts +1 -0
- package/dist/types/hooks/useIsFirstRender/useIsFirstRender.d.ts +1 -0
- package/dist/types/hooks/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.d.ts +1 -0
- package/dist/types/hooks/useKeyPress/useKeyPress.d.ts +1 -0
- package/dist/types/hooks/useKeyPressEvent/useKeyPressEvent.d.ts +1 -0
- package/dist/types/hooks/useKeyboard/useKeyboard.d.ts +1 -0
- package/dist/types/hooks/useKeysPressed/useKeysPressed.d.ts +1 -2
- package/dist/types/hooks/useLastChanged/useLastChanged.d.ts +1 -0
- package/dist/types/hooks/useLatest/useLatest.d.ts +1 -0
- package/dist/types/hooks/useLess/useLess.d.ts +1 -0
- package/dist/types/hooks/useList/useList.d.ts +1 -0
- package/dist/types/hooks/useLocalStorage/useLocalStorage.d.ts +1 -0
- package/dist/types/hooks/useLockCallback/useLockCallback.d.ts +1 -0
- package/dist/types/hooks/useLockScroll/useLockScroll.d.ts +1 -1
- package/dist/types/hooks/useLogger/useLogger.d.ts +1 -0
- package/dist/types/hooks/useLongPress/useLongPress.d.ts +1 -0
- package/dist/types/hooks/useMap/useMap.d.ts +1 -0
- package/dist/types/hooks/useMeasure/useMeasure.d.ts +1 -0
- package/dist/types/hooks/useMediaControls/useMediaControls.d.ts +1 -0
- package/dist/types/hooks/useMediaQuery/useMediaQuery.d.ts +1 -0
- package/dist/types/hooks/useMemory/useMemory.d.ts +1 -0
- package/dist/types/hooks/useMergedRef/useMergedRef.d.ts +17 -0
- package/dist/types/hooks/useMount/useMount.d.ts +1 -0
- package/dist/types/hooks/useMouse/useMouse.d.ts +1 -0
- package/dist/types/hooks/useMutation/useMutation.d.ts +1 -0
- package/dist/types/hooks/useMutationObserver/useMutationObserver.d.ts +43 -26
- package/dist/types/hooks/useNetwork/useNetwork.d.ts +1 -0
- package/dist/types/hooks/useObject/useObject.d.ts +1 -0
- package/dist/types/hooks/useOffsetPagination/useOffsetPagination.d.ts +1 -0
- package/dist/types/hooks/useOnce/useOnce.d.ts +1 -0
- package/dist/types/hooks/useOnline/useOnline.d.ts +1 -0
- package/dist/types/hooks/useOperatingSystem/useOperatingSystem.d.ts +1 -0
- package/dist/types/hooks/useOptimistic/useOptimistic.d.ts +1 -0
- package/dist/types/hooks/useOrientation/useOrientation.d.ts +2 -1
- package/dist/types/hooks/useOtpCredential/useOtpCredential.d.ts +1 -0
- package/dist/types/hooks/usePageLeave/usePageLeave.d.ts +1 -0
- package/dist/types/hooks/usePaint/usePaint.d.ts +1 -0
- package/dist/types/hooks/useParallax/useParallax.d.ts +1 -0
- package/dist/types/hooks/usePerformanceObserver/usePerformanceObserver.d.ts +1 -0
- package/dist/types/hooks/usePermission/usePermission.d.ts +1 -0
- package/dist/types/hooks/usePictureInPicture/usePictureInPicture.d.ts +1 -0
- package/dist/types/hooks/usePointerLock/usePointerLock.d.ts +1 -0
- package/dist/types/hooks/usePostMessage/usePostMessage.d.ts +1 -0
- package/dist/types/hooks/usePreferredColorScheme/usePreferredColorScheme.d.ts +1 -0
- package/dist/types/hooks/usePreferredContrast/usePreferredContrast.d.ts +1 -0
- package/dist/types/hooks/usePreferredDark/usePreferredDark.d.ts +1 -0
- package/dist/types/hooks/usePreferredLanguages/usePreferredLanguages.d.ts +1 -0
- package/dist/types/hooks/usePreferredReducedMotion/usePreferredReducedMotion.d.ts +1 -0
- package/dist/types/hooks/usePrevious/usePrevious.d.ts +1 -0
- package/dist/types/hooks/useQuery/useQuery.d.ts +1 -0
- package/dist/types/hooks/useQueue/useQueue.d.ts +1 -0
- package/dist/types/hooks/useRaf/useRaf.d.ts +1 -0
- package/dist/types/hooks/useRafState/useRafState.d.ts +3 -0
- package/dist/types/hooks/useRefState/useRefState.d.ts +1 -0
- package/dist/types/hooks/useRenderCount/useRenderCount.d.ts +1 -0
- package/dist/types/hooks/useRenderInfo/useRenderInfo.d.ts +1 -0
- package/dist/types/hooks/useRerender/useRerender.d.ts +1 -0
- package/dist/types/hooks/useResizeObserver/useResizeObserver.d.ts +55 -31
- package/dist/types/hooks/useRightClick/useRightClick.d.ts +1 -0
- package/dist/types/hooks/useScript/useScript.d.ts +1 -0
- package/dist/types/hooks/useScroll/useScroll.d.ts +1 -0
- package/dist/types/hooks/useScrollIntoView/useScrollIntoView.d.ts +1 -0
- package/dist/types/hooks/useScrollTo/useScrollTo.d.ts +1 -0
- package/dist/types/hooks/useSessionStorage/useSessionStorage.d.ts +1 -0
- package/dist/types/hooks/useSet/useSet.d.ts +1 -0
- package/dist/types/hooks/useShallowEffect/useShallowEffect.d.ts +1 -0
- package/dist/types/hooks/useShare/useShare.d.ts +1 -0
- package/dist/types/hooks/useSpeechRecognition/useSpeechRecognition.d.ts +1 -0
- package/dist/types/hooks/useSpeechSynthesis/useSpeechSynthesis.d.ts +1 -0
- package/dist/types/hooks/useStateHistory/useStateHistory.d.ts +1 -0
- package/dist/types/hooks/useStep/useStep.d.ts +1 -0
- package/dist/types/hooks/useSticky/useSticky.d.ts +1 -0
- package/dist/types/hooks/useStopwatch/useStopwatch.d.ts +1 -0
- package/dist/types/hooks/useStorage/useStorage.d.ts +1 -0
- package/dist/types/hooks/useTextDirection/useTextDirection.d.ts +1 -0
- package/dist/types/hooks/useTextSelection/useTextSelection.d.ts +1 -0
- package/dist/types/hooks/useThrottleCallback/useThrottleCallback.d.ts +1 -0
- package/dist/types/hooks/useThrottleState/useThrottleState.d.ts +15 -0
- package/dist/types/hooks/useThrottleValue/useThrottleValue.d.ts +1 -0
- package/dist/types/hooks/useTime/useTime.d.ts +1 -0
- package/dist/types/hooks/useTimeout/useTimeout.d.ts +1 -0
- package/dist/types/hooks/useTimer/useTimer.d.ts +1 -0
- package/dist/types/hooks/useToggle/useToggle.d.ts +1 -0
- package/dist/types/hooks/useUnmount/useUnmount.d.ts +1 -0
- package/dist/types/hooks/useUrlSearchParam/useUrlSearchParam.d.ts +1 -0
- package/dist/types/hooks/useUrlSearchParams/useUrlSearchParams.d.ts +1 -0
- package/dist/types/hooks/useVibrate/useVibrate.d.ts +1 -0
- package/dist/types/hooks/useVirtualKeyboard/useVirtualKeyboard.d.ts +1 -0
- package/dist/types/hooks/useWakeLock/useWakeLock.d.ts +1 -0
- package/dist/types/hooks/useWebSocket/useWebSocket.d.ts +17 -0
- package/dist/types/hooks/useWindowEvent/useWindowEvent.d.ts +1 -0
- package/dist/types/hooks/useWindowFocus/useWindowFocus.d.ts +1 -0
- package/dist/types/hooks/useWindowScroll/useWindowScroll.d.ts +1 -0
- package/dist/types/hooks/useWindowSize/useWindowSize.d.ts +1 -0
- package/dist/types/hooks/useWizard/useWizard.d.ts +1 -0
- package/dist/types/hooks/utilities.d.ts +2 -0
- package/package.json +89 -89
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useBattery.mjs","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: supported,\n level: 0,\n charging: false,\n chargingTime: 0,\n dischargingTime: 0\n });\n\n useEffect(() => {\n if (!supported) return;\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
|
|
1
|
+
{"version":3,"file":"useBattery.mjs","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 * @usage low\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\n const [value, setValue] = useState<UseBatteryValue>({\n loading: supported,\n level: 0,\n charging: false,\n chargingTime: 0,\n dischargingTime: 0\n });\n\n useEffect(() => {\n if (!supported) return;\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":";AAkDO,MAAMA,IAAa,MAA6B;AACrD,QAAMC,IACJ,OAAO,YAAc,OACrB,gBAAgB,aAChB,OAAO,UAAU,cAAe,YAE5B,CAACC,GAAOC,CAAQ,IAAIC,EAA0B;AAAA,IAClD,SAASH;AAAA,IACT,OAAO;AAAA,IACP,UAAU;AAAA,IACV,cAAc;AAAA,IACd,iBAAiB;AAAA,EAAA,CAClB;AAED,SAAAI,EAAU,MAAM;AACd,QAAI,CAACJ,EAAW;AAEhB,QAAIK;AAEJ,UAAMC,IAAW,MACfJ,EAAS;AAAA,MACP,SAAS;AAAA,MACT,OAAOG,GAAS,SAAS;AAAA,MACzB,UAAUA,GAAS,YAAY;AAAA,MAC/B,iBAAiBA,GAAS,mBAAmB;AAAA,MAC7C,cAAcA,GAAS,gBAAgB;AAAA,IAAA,CACxC;AAEH,qBAAU,WAAA,EAAa,KAAK,CAACE,MAAmB;AAC9C,MAAAF,IAAUE,GACVD,EAAA,GAEAD,EAAQ,iBAAiB,eAAeC,CAAQ,GAChDD,EAAQ,iBAAiB,kBAAkBC,CAAQ,GACnDD,EAAQ,iBAAiB,sBAAsBC,CAAQ,GACvDD,EAAQ,iBAAiB,yBAAyBC,CAAQ;AAAA,IAAA,CAC3D,GAEM,MAAM;AACX,MAAKD,MACLA,EAAQ,oBAAoB,eAAeC,CAAQ,GACnDD,EAAQ,oBAAoB,kBAAkBC,CAAQ,GACtDD,EAAQ,oBAAoB,sBAAsBC,CAAQ,GAC1DD,EAAQ,oBAAoB,yBAAyBC,CAAQ;AAAA,IAAA;AAAA,EAC/D,GACC,EAAE,GAEE,EAAE,WAAAN,GAAW,OAAAC,EAAA;AACtB;"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { useState as
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
if (!
|
|
1
|
+
import { useState as o, useEffect as D } from "react";
|
|
2
|
+
const S = (d) => {
|
|
3
|
+
const n = typeof navigator < "u" && "bluetooth" in navigator && !!navigator.bluetooth, { acceptAllDevices: l = !1, filters: c, optionalServices: u } = d ?? {}, [f, s] = o(!1), [e, r] = o(void 0), [g, i] = o(void 0), p = async () => {
|
|
4
|
+
if (!n) return;
|
|
5
5
|
const t = await navigator.bluetooth.requestDevice({
|
|
6
6
|
acceptAllDevices: l,
|
|
7
7
|
optionalServices: u,
|
|
@@ -10,20 +10,18 @@ const h = (d) => {
|
|
|
10
10
|
r(t);
|
|
11
11
|
};
|
|
12
12
|
return D(() => {
|
|
13
|
-
if (e
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
};
|
|
24
|
-
}
|
|
13
|
+
if (!e?.gatt) return;
|
|
14
|
+
const t = async () => {
|
|
15
|
+
const v = await e.gatt.connect();
|
|
16
|
+
i(v), s(v.connected);
|
|
17
|
+
}, a = () => {
|
|
18
|
+
i(void 0), r(void 0), s(!1);
|
|
19
|
+
};
|
|
20
|
+
return e.addEventListener("gattserverdisconnected", a), t(), () => {
|
|
21
|
+
e.removeEventListener("gattserverdisconnected", a), e.gatt?.disconnect();
|
|
22
|
+
};
|
|
25
23
|
}, [e]), {
|
|
26
|
-
supported:
|
|
24
|
+
supported: n,
|
|
27
25
|
connected: f,
|
|
28
26
|
device: e,
|
|
29
27
|
requestDevice: p,
|
|
@@ -31,6 +29,6 @@ const h = (d) => {
|
|
|
31
29
|
};
|
|
32
30
|
};
|
|
33
31
|
export {
|
|
34
|
-
|
|
32
|
+
S as useBluetooth
|
|
35
33
|
};
|
|
36
34
|
//# sourceMappingURL=useBluetooth.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useBluetooth.mjs","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
|
|
1
|
+
{"version":3,"file":"useBluetooth.mjs","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 * @usage low\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 =\n typeof navigator !== 'undefined' && 'bluetooth' in navigator && !!navigator.bluetooth;\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?.gatt) return;\n\n const connectToBluetoothGATTServer = async () => {\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 }, [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":";AA0CO,MAAMA,IAAe,CAACC,MAAsD;AACjF,QAAMC,IACJ,OAAO,YAAc,OAAe,eAAe,aAAa,CAAC,CAAC,UAAU,WACxE,EAAE,kBAAAC,IAAmB,IAAO,SAAAC,GAAS,kBAAAC,EAAA,IAAqBJ,KAAW,CAAA,GAErE,CAACK,GAAWC,CAAc,IAAIC,EAAS,EAAK,GAC5C,CAACC,GAAQC,CAAS,IAAIF,EAAsC,MAAS,GACrE,CAACG,GAAQC,CAAS,IAAIJ,EAAgD,MAAS,GAE/EK,IAAgB,YAAY;AAChC,QAAI,CAACX,EAAW;AAEhB,UAAMY,IAAiB,MAAM,UAAU,UAAU,cAAc;AAAA,MAC7D,kBAAAX;AAAA,MACA,kBAAAE;AAAA,MACA,GAAID,KAAW,EAAE,SAAAA,GAAS,kBAAkB,GAAA;AAAA,IAAM,CACnD;AAED,IAAAM,EAAUI,CAAc;AAAA,EAAA;AAG1B,SAAAC,EAAU,MAAM;AACd,QAAI,CAACN,GAAQ,KAAM;AAEnB,UAAMO,IAA+B,YAAY;AAC/C,YAAMC,IAAa,MAAMR,EAAO,KAAM,QAAA;AACtC,MAAAG,EAAUK,CAAU,GACpBV,EAAeU,EAAW,SAAS;AAAA,IAAA,GAG/BC,IAAQ,MAAM;AAClB,MAAAN,EAAU,MAAS,GACnBF,EAAU,MAAS,GACnBH,EAAe,EAAK;AAAA,IAAA;AAGtB,WAAAE,EAAO,iBAAiB,0BAA0BS,CAAK,GACvDF,EAAA,GAEO,MAAM;AACX,MAAAP,EAAO,oBAAoB,0BAA0BS,CAAK,GAC1DT,EAAO,MAAM,WAAA;AAAA,IAAW;AAAA,EAC1B,GACC,CAACA,CAAM,CAAC,GAEJ;AAAA,IACL,WAAAP;AAAA,IACA,WAAAI;AAAA,IACA,QAAAG;AAAA,IACA,eAAAI;AAAA,IACA,QAAAF;AAAA,EAAA;AAEJ;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useBoolean.mjs","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 State\n
|
|
1
|
+
{"version":3,"file":"useBoolean.mjs","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 State\n * @usage necessary\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":";AAsBO,MAAMA,IAAa,CAACC,IAAe,OAA4B;AACpE,QAAM,CAACC,GAAOC,CAAQ,IAAIC,EAASH,CAAY;AAG/C,SAAO,CAACC,GAFO,CAACA,MAAoBC,EAAS,CAACE,MAAcH,KAAS,CAACG,CAAS,CAE1D;AACvB;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useBreakpoints.mjs","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":";;AAUA,MAAMA,IAAQ,CAACC,MAAkB,OAAO,WAAWA,CAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"useBreakpoints.mjs","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 * @usage medium\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":"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"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { useState as
|
|
2
|
-
const
|
|
3
|
-
const o = typeof window < "u" && "BroadcastChannel" in window, [i, c] =
|
|
4
|
-
|
|
1
|
+
import { useState as t, useRef as p, useEffect as w } from "react";
|
|
2
|
+
const C = (s, d) => {
|
|
3
|
+
const o = typeof window < "u" && "BroadcastChannel" in window && !!window.BroadcastChannel, [i, c] = t(!1), [l, f] = t(), [v, E] = t(), e = p(void 0);
|
|
4
|
+
w(() => {
|
|
5
5
|
if (!o) return;
|
|
6
6
|
e.current = new BroadcastChannel(s);
|
|
7
|
-
const r = (
|
|
8
|
-
f(
|
|
9
|
-
}, a = (
|
|
7
|
+
const r = (n) => {
|
|
8
|
+
f(n.data), d?.(n.data);
|
|
9
|
+
}, a = (n) => E(n), u = () => c(!0);
|
|
10
10
|
return e.current.addEventListener("message", r), e.current.addEventListener("messageerror", a), e.current.addEventListener("close", u), () => {
|
|
11
11
|
e.current && (e.current.removeEventListener("message", r), e.current.removeEventListener("messageerror", a), e.current.removeEventListener("close", u), e.current.close());
|
|
12
12
|
};
|
|
@@ -27,6 +27,6 @@ const w = (s, d) => {
|
|
|
27
27
|
};
|
|
28
28
|
};
|
|
29
29
|
export {
|
|
30
|
-
|
|
30
|
+
C as useBroadcastChannel
|
|
31
31
|
};
|
|
32
32
|
//# sourceMappingURL=useBroadcastChannel.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useBroadcastChannel.mjs","sources":["../../../../src/hooks/useBroadcastChannel/useBroadcastChannel.ts"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\n\n/** The use broadcast channel return type */\nexport interface UseBroadcastChannelReturn<Data = unknown> {\n /** The underlying BroadcastChannel instance if supported, undefined otherwise */\n channel?: BroadcastChannel;\n /** Whether the channel has been closed */\n closed: boolean;\n /** The most recently received data from other contexts */\n data?: Data;\n /** Error object if any error occurred during channel operations */\n error?: Event;\n /** Whether the BroadcastChannel API is supported in the current environment */\n supported: boolean;\n /** Function to close the channel and clean up resources */\n close: () => void;\n /** Function to send data to other contexts through the channel */\n post: (data: Data) => void;\n}\n\n/**\n * @name useBroadcastChannel\n * @description Hook that provides cross-tab/window communication\n * @category Browser\n *\n * @browserapi BroadcastChannel https://developer.mozilla.org/en-US/docs/Web/API/BroadcastChannel\n *\n * @param {string} name The name of the channel\n * @param {Function} callback A callback function that will be called when a message is received\n * @returns {UseBroadcastChannelReturn} An object containing the channel state and controls\n *\n * @example\n * const { supported, data, post, error } = useBroadcastChannel('channel');\n */\nexport const useBroadcastChannel = <Data = unknown>(\n name: string,\n callback?: (data: Data) => void\n): UseBroadcastChannelReturn<Data> => {\n const supported
|
|
1
|
+
{"version":3,"file":"useBroadcastChannel.mjs","sources":["../../../../src/hooks/useBroadcastChannel/useBroadcastChannel.ts"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\n\n/** The use broadcast channel return type */\nexport interface UseBroadcastChannelReturn<Data = unknown> {\n /** The underlying BroadcastChannel instance if supported, undefined otherwise */\n channel?: BroadcastChannel;\n /** Whether the channel has been closed */\n closed: boolean;\n /** The most recently received data from other contexts */\n data?: Data;\n /** Error object if any error occurred during channel operations */\n error?: Event;\n /** Whether the BroadcastChannel API is supported in the current environment */\n supported: boolean;\n /** Function to close the channel and clean up resources */\n close: () => void;\n /** Function to send data to other contexts through the channel */\n post: (data: Data) => void;\n}\n\n/**\n * @name useBroadcastChannel\n * @description Hook that provides cross-tab/window communication\n * @category Browser\n * @usage low\n *\n * @browserapi BroadcastChannel https://developer.mozilla.org/en-US/docs/Web/API/BroadcastChannel\n *\n * @param {string} name The name of the channel\n * @param {Function} callback A callback function that will be called when a message is received\n * @returns {UseBroadcastChannelReturn} An object containing the channel state and controls\n *\n * @example\n * const { supported, data, post, error } = useBroadcastChannel('channel');\n */\nexport const useBroadcastChannel = <Data = unknown>(\n name: string,\n callback?: (data: Data) => void\n): UseBroadcastChannelReturn<Data> => {\n const supported =\n typeof window !== 'undefined' && 'BroadcastChannel' in window && !!window.BroadcastChannel;\n\n const [closed, setClosed] = useState(false);\n const [data, setData] = useState<Data>();\n const [error, setError] = useState<MessageEvent>();\n const channelRef = useRef<BroadcastChannel>(undefined);\n\n useEffect(() => {\n if (!supported) return;\n\n channelRef.current = new BroadcastChannel(name);\n\n const onMessage = (event: MessageEvent) => {\n setData(event.data);\n callback?.(event.data);\n };\n const onMessageError = (event: MessageEvent) => setError(event);\n const onClose = () => setClosed(true);\n\n channelRef.current.addEventListener('message', onMessage);\n channelRef.current.addEventListener('messageerror', onMessageError);\n channelRef.current.addEventListener('close', onClose);\n\n return () => {\n if (channelRef.current) {\n channelRef.current.removeEventListener('message', onMessage);\n channelRef.current.removeEventListener('messageerror', onMessageError);\n channelRef.current.removeEventListener('close', onClose);\n channelRef.current.close();\n }\n };\n }, [name]);\n\n const post = (data: Data) => {\n console.log('post', data, channelRef.current);\n if (!channelRef.current) return;\n channelRef.current.postMessage(data);\n };\n\n const close = () => {\n if (!channelRef.current) return;\n channelRef.current.close();\n setClosed(true);\n };\n\n return {\n supported,\n channel: channelRef.current,\n data,\n post,\n close,\n error,\n closed\n };\n};\n"],"names":["useBroadcastChannel","name","callback","supported","closed","setClosed","useState","data","setData","error","setError","channelRef","useRef","useEffect","onMessage","event","onMessageError","onClose","post","close"],"mappings":";AAmCO,MAAMA,IAAsB,CACjCC,GACAC,MACoC;AACpC,QAAMC,IACJ,OAAO,SAAW,OAAe,sBAAsB,UAAU,CAAC,CAAC,OAAO,kBAEtE,CAACC,GAAQC,CAAS,IAAIC,EAAS,EAAK,GACpC,CAACC,GAAMC,CAAO,IAAIF,EAAA,GAClB,CAACG,GAAOC,CAAQ,IAAIJ,EAAA,GACpBK,IAAaC,EAAyB,MAAS;AAErD,EAAAC,EAAU,MAAM;AACd,QAAI,CAACV,EAAW;AAEhB,IAAAQ,EAAW,UAAU,IAAI,iBAAiBV,CAAI;AAE9C,UAAMa,IAAY,CAACC,MAAwB;AACzC,MAAAP,EAAQO,EAAM,IAAI,GAClBb,IAAWa,EAAM,IAAI;AAAA,IAAA,GAEjBC,IAAiB,CAACD,MAAwBL,EAASK,CAAK,GACxDE,IAAU,MAAMZ,EAAU,EAAI;AAEpC,WAAAM,EAAW,QAAQ,iBAAiB,WAAWG,CAAS,GACxDH,EAAW,QAAQ,iBAAiB,gBAAgBK,CAAc,GAClEL,EAAW,QAAQ,iBAAiB,SAASM,CAAO,GAE7C,MAAM;AACX,MAAIN,EAAW,YACbA,EAAW,QAAQ,oBAAoB,WAAWG,CAAS,GAC3DH,EAAW,QAAQ,oBAAoB,gBAAgBK,CAAc,GACrEL,EAAW,QAAQ,oBAAoB,SAASM,CAAO,GACvDN,EAAW,QAAQ,MAAA;AAAA,IACrB;AAAA,EACF,GACC,CAACV,CAAI,CAAC;AAET,QAAMiB,IAAO,CAACX,MAAe;AAE3B,IADA,QAAQ,IAAI,QAAQA,GAAMI,EAAW,OAAO,GACvCA,EAAW,WAChBA,EAAW,QAAQ,YAAYJ,CAAI;AAAA,EAAA,GAG/BY,IAAQ,MAAM;AAClB,IAAKR,EAAW,YAChBA,EAAW,QAAQ,MAAA,GACnBN,EAAU,EAAI;AAAA,EAAA;AAGhB,SAAO;AAAA,IACL,WAAAF;AAAA,IACA,SAASQ,EAAW;AAAA,IACpB,MAAAJ;AAAA,IACA,MAAAW;AAAA,IACA,OAAAC;AAAA,IACA,OAAAV;AAAA,IACA,QAAAL;AAAA,EAAA;AAEJ;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useBrowserLanguage.mjs","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 User\n
|
|
1
|
+
{"version":3,"file":"useBrowserLanguage.mjs","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 User\n * @usage medium\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":";AAEA,MAAMA,IAAc,MAAM,UAAU,UAC9BC,IAAoB,MAAM,gBAC1BC,IAAY,CAACC,OACjB,OAAO,iBAAiB,kBAAkBA,CAAQ,GAC3C,MAAM,OAAO,oBAAoB,kBAAkBA,CAAQ,IAgBvDC,IAAqB,MAChCC,EAAqBH,GAAWF,GAAaC,CAAiB;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useClickOutside.mjs","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 Elements\n
|
|
1
|
+
{"version":3,"file":"useClickOutside.mjs","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 Elements \n * @usage necessary\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":";;;;AAwCO,MAAMA,IAAmB,IAAIC,MAAkB;AACpD,QAAMC,IAAUC,EAASF,EAAO,CAAC,CAAC,IAAIA,EAAO,CAAC,IAAI,QAC5CG,IAAYH,EAAO,CAAC,IAAIA,EAAO,CAAC,IAAIA,EAAO,CAAC,GAE5CI,IAAcC,EAAA,GACdC,IAAsBC,EAAOJ,CAAQ;AAoB3C,MAnBAG,EAAoB,UAAUH,GAE9BK,EAAU,MAAM;AACd,QAAI,CAACP,KAAU,CAACG,EAAY,MAAO;AACnC,UAAMK,IAAU,CAACC,MAAiB;AAChC,YAAMC,IAAWV,IAASW,EAAWX,CAAM,IAAIG,EAAY;AAE3D,MAAIO,KAAW,CAACA,EAAQ,SAASD,EAAM,MAAc,KACnDJ,EAAoB,QAAQI,CAAK;AAAA,IACnC;AAGF,oBAAS,iBAAiB,SAASD,CAAO,GAEnC,MAAM;AACX,eAAS,oBAAoB,SAASA,CAAO;AAAA,IAAA;AAAA,EAC/C,GACC,CAACR,GAAQG,EAAY,KAAK,CAAC,GAE1B,CAAAH;AACJ,WAAOG;AACT;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useClipboard.mjs","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
|
|
1
|
+
{"version":3,"file":"useClipboard.mjs","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 * @usage medium\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":";;AAgCO,MAAMA,IAAe,CAACC,MAAgE;AAC3F,QAAM,CAACC,GAAOC,CAAQ,IAAIC,EAAwB,IAAI,GAChDC,IAAUJ,GAAQ,WAAW,IAE7BK,IAAM,YAAY;AACtB,QAAI;AACF,YAAMJ,IAAQ,MAAM,UAAU,UAAU,SAAA;AACxC,MAAAC,EAASD,CAAK;AAAA,IAAA,QACR;AACN,MAAAC,EAAS,SAAS,eAAA,GAAkB,SAAA,KAAc,EAAE;AAAA,IAAA;AAAA,EACtD;AAGF,SAAAI,EAAU,MAAM;AACd,QAAKF;AAEL,sBAAS,iBAAiB,QAAQC,CAAG,GACrC,SAAS,iBAAiB,OAAOA,CAAG,GAC7B,MAAM;AACX,iBAAS,oBAAoB,QAAQA,CAAG,GACxC,SAAS,oBAAoB,OAAOA,CAAG;AAAA,MAAA;AAAA,EACzC,GACC,CAACD,CAAO,CAAC,GAOL,EAAE,OAAAH,GAAO,MALQ,OAAOA,MAAkB;AAC/C,IAAAM,EAAKN,CAAK,GACVC,EAASD,CAAK;AAAA,EAAA,EAGM;AACxB;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useConst.mjs","sources":["../../../../src/hooks/useConst/useConst.ts"],"sourcesContent":["import { useRef } from 'react';\n\n/**\n * @name useConst\n * @description - Hook that returns the constant value\n * @category Utilities\n
|
|
1
|
+
{"version":3,"file":"useConst.mjs","sources":["../../../../src/hooks/useConst/useConst.ts"],"sourcesContent":["import { useRef } from 'react';\n\n/**\n * @name useConst\n * @description - Hook that returns the constant value\n * @category Utilities\n * @usage high\n\n * @template Value The type of the value\n * @param {(() => Value) | Value} initialValue The initial value of the constant\n * @returns {Value} The constant value\n *\n * @example\n * const value = useConst('value');\n */\nexport const useConst = <Value>(initialValue: (() => Value) | Value) =>\n useRef<Value>(typeof initialValue === 'function' ? (initialValue as () => Value)() : initialValue)\n .current;\n"],"names":["useConst","initialValue","useRef"],"mappings":";AAeO,MAAMA,IAAW,CAAQC,MAC9BC,EAAc,OAAOD,KAAiB,aAAcA,MAAiCA,CAAY,EAC9F;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCookie.mjs","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 State\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":"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"}
|
|
1
|
+
{"version":3,"file":"useCookie.mjs","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 State\n * @usage medium\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":"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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCookies.mjs","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 State\n
|
|
1
|
+
{"version":3,"file":"useCookies.mjs","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 State\n * @usage medium\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":";;AAuBO,MAAMA,IAAe,MAAM;AAChC,WAAS,OAAO,MAAM,IAAI,EAAE,QAAQ,CAACC,MAAW;AAC9C,UAAM,CAACC,CAAI,IAAID,EAAO,MAAM,GAAG;AAC/B,IAAAE,EAAaD,CAAI;AAAA,EAAA,CAClB;AACH,GAEME,IAAmB,MAAM;AAC7B,EAAAJ,EAAA,GACAK,EAAA;AACF,GAeaC,IAAa,CAA6BC,MAAuC;AAC5F,QAAMC,IAAa,CAACC,MACdF,GAAS,aAAmBA,EAAQ,WAAWE,CAAK,IACpD,OAAOA,KAAU,WAAiBA,IAC/B,KAAK,UAAUA,CAAK,GAGvBC,IAAe,CAACD,MAAkB;AACtC,QAAIF,GAAS,aAAc,QAAOA,EAAQ,aAAaE,CAAK;AAC5D,QAAIA,MAAU;AAEd,UAAI;AACF,eAAO,KAAK,MAAMA,CAAK;AAAA,MAAA,QACjB;AACN,eAAOA;AAAAA,MAAA;AAAA,EACT,GAGIE,IAAmB,MAClB,SAAS,SAEP,OAAO;AAAA,IACZ,SAAS,OACN,MAAM,IAAI,EACV,IAAI,CAACV,MAAW;AACf,YAAM,CAACW,GAAK,GAAGH,CAAK,IAAIR,EAAO,MAAM,GAAG;AACxC,UAAI,CAACW,KAAO,CAACH,EAAM,eAAe,CAAA;AAClC,YAAMI,IAAe,mBAAmBJ,EAAM,KAAK,GAAG,CAAC;AACvD,aAAO,CAACG,GAAKF,EAAaG,CAAY,CAAC;AAAA,IAAA,CACxC,EACA,OAAO,CAACC,MAAUA,EAAM,MAAM;AAAA,EAAA,IAXN,CAAA,GAezB,CAACL,GAAOM,CAAQ,IAAIC,EAAS,MAC7B,OAAO,SAAW,MAAoB,CAAA,IACnCL,EAAA,CACR;AAED,SAAAM,EAAU,MAAM;AACd,UAAMC,IAAW,MAAMH,EAASJ,GAA2B;AAE3D,kBAAO,iBAAiBQ,GAAcD,CAAQ,GACvC,MAAM;AACX,aAAO,oBAAoBC,GAAcD,CAAQ;AAAA,IAAA;AAAA,EACnD,GACC,EAAE,GAUE,EAAE,OAAAT,GAAO,KARJ,CAA0BG,GAAUH,GAAmBF,MACjEa,EAAcR,GAAeJ,EAAWC,CAAK,GAAGF,CAAO,GAOpC,QALN,CAA0BK,GAAUL,MACjDc,EAAiBT,GAAeL,CAAO,GAIZ,QAHd,MAAMI,EAAA,GAGgB,OAFvB,MAAMP,EAAA,EAEiB;AACvC;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCopy.mjs","sources":["../../../../src/hooks/useCopy/useCopy.ts"],"sourcesContent":["import { useState } from 'react';\n\nimport { copy } from '@/utils/helpers';\n\n/** The use copy return type */\nexport interface UseCopyReturn {\n /** Whether copy is in progress */\n copied: boolean;\n /** The copied value */\n value?: string;\n /** Function to copy text */\n copy: (value: string) => Promise<void>;\n}\n\n/** The use copy params type */\nexport interface UseCopyParams {\n /** Reset delay in milliseconds */\n resetDelay?: number;\n}\n\n/**\n * @name useCopy\n * @description - Hook that manages copying text with status reset\n * @category Browser\n
|
|
1
|
+
{"version":3,"file":"useCopy.mjs","sources":["../../../../src/hooks/useCopy/useCopy.ts"],"sourcesContent":["import { useState } from 'react';\n\nimport { copy } from '@/utils/helpers';\n\n/** The use copy return type */\nexport interface UseCopyReturn {\n /** Whether copy is in progress */\n copied: boolean;\n /** The copied value */\n value?: string;\n /** Function to copy text */\n copy: (value: string) => Promise<void>;\n}\n\n/** The use copy params type */\nexport interface UseCopyParams {\n /** Reset delay in milliseconds */\n resetDelay?: number;\n}\n\n/**\n * @name useCopy\n * @description - Hook that manages copying text with status reset\n * @category Browser\n * @usage medium\n\n * @browserapi navigator.clipboard https://developer.mozilla.org/en-US/docs/Web/API/Navigator/clipboard\n *\n * @param {number} [delay=1000] Delay in ms before resetting copied status\n * @returns {UseCopyReturn} An object containing the copied value, status and copy function\n *\n * @example\n * const { copied, value, copy } = useCopy();\n */\nexport const useCopy = (delay: number = 1000): UseCopyReturn => {\n const [value, setValue] = useState<string | undefined>();\n const [copied, setCopied] = useState(false);\n\n const copyToClipboard = async (text: string) => {\n await copy(text);\n setValue(text);\n setCopied(true);\n setTimeout(() => setCopied(false), delay);\n };\n\n return { value, copied, copy: copyToClipboard };\n};\n"],"names":["useCopy","delay","value","setValue","useState","copied","setCopied","text","copy"],"mappings":";;AAkCO,MAAMA,IAAU,CAACC,IAAgB,QAAwB;AAC9D,QAAM,CAACC,GAAOC,CAAQ,IAAIC,EAAA,GACpB,CAACC,GAAQC,CAAS,IAAIF,EAAS,EAAK;AAS1C,SAAO,EAAE,OAAAF,GAAO,QAAAG,GAAQ,MAPA,OAAOE,MAAiB;AAC9C,UAAMC,EAAKD,CAAI,GACfJ,EAASI,CAAI,GACbD,EAAU,EAAI,GACd,WAAW,MAAMA,EAAU,EAAK,GAAGL,CAAK;AAAA,EAAA,EAGZ;AAChC;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCounter.mjs","sources":["../../../../src/hooks/useCounter/useCounter.ts"],"sourcesContent":["import type { Dispatch, SetStateAction } from 'react';\n\nimport { useState } from 'react';\n\n/** The use counter options */\nexport interface UseCounterOptions {\n /** The max of count value */\n max?: number;\n /** The min of count value */\n min?: number;\n}\n\n/** The use counter return type */\nexport interface UseCounterReturn {\n /** Function to set a specific value to the counter */\n set: Dispatch<SetStateAction<number>>;\n /** The current count value */\n value: number;\n /** Function to decrement the counter */\n dec: (value?: number) => void;\n /** Function to increment the counter */\n inc: (value?: number) => void;\n /** Function to reset the counter to its initial value. */\n reset: () => void;\n}\n\nexport interface UseCounter {\n (initialValue?: number, options?: UseCounterOptions): UseCounterReturn;\n\n (options: UseCounterOptions & { initialValue?: number }, initialValue?: never): UseCounterReturn;\n}\n\n/**\n * @name useCounter\n * @description - Hook that manages a counter\n * @category State\n
|
|
1
|
+
{"version":3,"file":"useCounter.mjs","sources":["../../../../src/hooks/useCounter/useCounter.ts"],"sourcesContent":["import type { Dispatch, SetStateAction } from 'react';\n\nimport { useState } from 'react';\n\n/** The use counter options */\nexport interface UseCounterOptions {\n /** The max of count value */\n max?: number;\n /** The min of count value */\n min?: number;\n}\n\n/** The use counter return type */\nexport interface UseCounterReturn {\n /** Function to set a specific value to the counter */\n set: Dispatch<SetStateAction<number>>;\n /** The current count value */\n value: number;\n /** Function to decrement the counter */\n dec: (value?: number) => void;\n /** Function to increment the counter */\n inc: (value?: number) => void;\n /** Function to reset the counter to its initial value. */\n reset: () => void;\n}\n\nexport interface UseCounter {\n (initialValue?: number, options?: UseCounterOptions): UseCounterReturn;\n\n (options: UseCounterOptions & { initialValue?: number }, initialValue?: never): UseCounterReturn;\n}\n\n/**\n * @name useCounter\n * @description - Hook that manages a counter\n * @category State\n * @usage low\n\n * @overload\n * @param {number} [initialValue=0] The initial number value\n * @param {number} [options.min=Number.NEGATIVE_INFINITY] The min of count value\n * @param {number} [options.max=Number.POSITIVE_INFINITY] The max of count value\n * @returns {UseCounterReturn} An object containing the current count and functions to interact with the counter\n\n * @overload\n * @param {number} [params.initialValue=0] The initial number value\n * @param {number} [params.min=Number.NEGATIVE_INFINITY] The min of count value\n * @param {number} [params.max=Number.POSITIVE_INFINITY] The max of count value\n * @returns {UseCounterReturn} An object containing the current count and functions to interact with the counter\n *\n * @example\n * const { count, dec, inc, reset, set } = useCounter(5);\n *\n * @example\n * const { count, dec, inc, reset, set } = useCounter({ initialValue: 5, min: 0, max: 10 });\n */\nexport const useCounter = ((...params: any[]) => {\n const initialValue =\n typeof params[0] === 'number'\n ? params[0]\n : (params[0] as UseCounterOptions & { initialValue?: number })?.initialValue;\n const { max = Number.POSITIVE_INFINITY, min = Number.NEGATIVE_INFINITY } =\n typeof params[0] === 'number'\n ? ((params[1] ?? {}) as UseCounterOptions)\n : ((params[0] ?? {}) as UseCounterOptions & { initialValue?: number });\n\n const [value, setValue] = useState(initialValue ?? 0);\n\n const inc = (value: number = 1) => {\n setValue((prevValue) => {\n if (typeof max === 'number' && prevValue === max) return prevValue;\n return Math.max(Math.min(max, prevValue + value), min);\n });\n };\n\n const dec = (value: number = 1) => {\n setValue((prevValue) => {\n if (typeof min === 'number' && prevValue === min) return prevValue;\n return Math.min(Math.max(min, prevValue - value), max);\n });\n };\n\n const reset = () => {\n const value = initialValue ?? 0;\n if (typeof max === 'number' && value > max) return setValue(max);\n if (typeof min === 'number' && value < min) return setValue(min);\n setValue(value);\n };\n\n const set = (value: SetStateAction<number>) => {\n setValue((prevValue) => {\n const updatedCount = Math.max(\n min,\n Math.min(max, typeof value === 'number' ? value : value(prevValue))\n );\n\n return updatedCount;\n });\n };\n\n return { value, set, inc, dec, reset };\n}) as UseCounter;\n"],"names":["useCounter","params","initialValue","max","min","value","setValue","useState","prevValue"],"mappings":";AAwDO,MAAMA,IAAc,IAAIC,MAAkB;AAC/C,QAAMC,IACJ,OAAOD,EAAO,CAAC,KAAM,WACjBA,EAAO,CAAC,IACPA,EAAO,CAAC,GAAqD,cAC9D,EAAE,KAAAE,IAAM,OAAO,mBAAmB,KAAAC,IAAM,OAAO,kBAAA,IACnD,OAAOH,EAAO,CAAC,KAAM,WACfA,EAAO,CAAC,KAAK,CAAA,IACbA,EAAO,CAAC,KAAK,CAAA,GAEf,CAACI,GAAOC,CAAQ,IAAIC,EAASL,KAAgB,CAAC;AAkCpD,SAAO,EAAE,OAAAG,GAAO,KAXJ,CAACA,MAAkC;AAC7C,IAAAC,EAAS,CAACE,MACa,KAAK;AAAA,MACxBJ;AAAA,MACA,KAAK,IAAID,GAAK,OAAOE,KAAU,WAAWA,IAAQA,EAAMG,CAAS,CAAC;AAAA,IAAA,CAIrE;AAAA,EAAA,GAGkB,KAhCT,CAACH,IAAgB,MAAM;AACjC,IAAAC,EAAS,CAACE,MACJ,OAAOL,KAAQ,YAAYK,MAAcL,IAAYK,IAClD,KAAK,IAAI,KAAK,IAAIL,GAAKK,IAAYH,CAAK,GAAGD,CAAG,CACtD;AAAA,EAAA,GA4BuB,KAzBd,CAACC,IAAgB,MAAM;AACjC,IAAAC,EAAS,CAACE,MACJ,OAAOJ,KAAQ,YAAYI,MAAcJ,IAAYI,IAClD,KAAK,IAAI,KAAK,IAAIJ,GAAKI,IAAYH,CAAK,GAAGF,CAAG,CACtD;AAAA,EAAA,GAqB4B,OAlBjB,MAAM;AAClB,UAAME,IAAQH,KAAgB;AAC9B,QAAI,OAAOC,KAAQ,YAAYE,IAAQF,EAAK,QAAOG,EAASH,CAAG;AAC/D,QAAI,OAAOC,KAAQ,YAAYC,IAAQD,EAAK,QAAOE,EAASF,CAAG;AAC/D,IAAAE,EAASD,CAAK;AAAA,EAAA,EAce;AACjC;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCssVar.mjs","sources":["../../../../src/hooks/useCssVar/useCssVar.ts"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\n\nimport type { HookTarget } from '@/utils/helpers';\n\nimport { getElement, isTarget } from '@/utils/helpers';\n\nimport type { StateRef } from '../useRefState/useRefState';\n\nimport { useRefState } from '../useRefState/useRefState';\n\n/** The css variable return type */\nexport interface UseCssVarReturn {\n /** The value of the CSS variable */\n value: string;\n /** Remove the value of the CSS variable */\n remove: () => void;\n /** Set the value of the CSS variable */\n set: (value: string) => void;\n}\n\nexport interface UseCssVar {\n <Target extends HTMLElement>(\n key: string,\n initialValue?: string\n ): UseCssVarReturn & {\n ref: StateRef<Target>;\n };\n\n (target: HookTarget, key: string, initialValue?: string): UseCssVarReturn;\n}\n\n/**\n * @name useCssVar\n * @description - Hook that returns the value of a css variable\n * @category Browser\n
|
|
1
|
+
{"version":3,"file":"useCssVar.mjs","sources":["../../../../src/hooks/useCssVar/useCssVar.ts"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\n\nimport type { HookTarget } from '@/utils/helpers';\n\nimport { getElement, isTarget } from '@/utils/helpers';\n\nimport type { StateRef } from '../useRefState/useRefState';\n\nimport { useRefState } from '../useRefState/useRefState';\n\n/** The css variable return type */\nexport interface UseCssVarReturn {\n /** The value of the CSS variable */\n value: string;\n /** Remove the value of the CSS variable */\n remove: () => void;\n /** Set the value of the CSS variable */\n set: (value: string) => void;\n}\n\nexport interface UseCssVar {\n <Target extends HTMLElement>(\n key: string,\n initialValue?: string\n ): UseCssVarReturn & {\n ref: StateRef<Target>;\n };\n\n (target: HookTarget, key: string, initialValue?: string): UseCssVarReturn;\n}\n\n/**\n * @name useCssVar\n * @description - Hook that returns the value of a css variable\n * @category Browser\n * @usage low\n\n * @overload\n * @param {string} key The CSS variable key\n * @param {string} initialValue The initial value of the CSS variable\n * @returns {UseCssVarReturn & { ref: StateRef<Element> }} The object containing the value of the CSS variable and ref\n *\n * @example\n * const { ref, value, set, remove } = useCssVar('--color', 'red');\n *\n * @overload\n * @param {HookTarget} target The target element\n * @param {string} key The CSS variable key\n * @param {string} initialValue The initial value of the CSS variable\n * @returns {UseCssVarReturn} The object containing the value of the CSS variable\n *\n * @example\n * const { value, set, remove } = useCssVar(ref, '--color', 'red');\n */\nexport const useCssVar = ((...params: any[]) => {\n const target = (isTarget(params[0]) ? params[0] : undefined) as HookTarget | undefined;\n const key = (target ? params[1] : params[0]) as string;\n const initialValue = (target ? params[2] : params[1]) as string | undefined;\n\n const [value, setValue] = useState(initialValue ?? '');\n const internalRef = useRefState<HTMLElement>();\n const elementRef = useRef<HTMLElement>(null);\n\n const set = (value: string) => {\n if (!elementRef.current) return;\n const element = elementRef.current;\n\n if (!element.style) return;\n element.style.setProperty(key, value);\n setValue(value);\n };\n\n const remove = () => {\n if (!elementRef.current) return;\n const element = elementRef.current;\n if (!element.style) return;\n\n element.style.removeProperty(key);\n setValue('');\n };\n\n useEffect(() => {\n if (!initialValue) return;\n\n const element =\n ((target ? getElement(target) : internalRef.current) as HTMLElement) ??\n window.document.documentElement;\n\n if (!element.style) return;\n element.style.setProperty(key, initialValue);\n setValue(initialValue);\n }, []);\n\n useEffect(() => {\n const element =\n ((target ? getElement(target) : internalRef.current) as HTMLElement) ??\n window.document.documentElement;\n\n elementRef.current = element;\n\n const onChange = () => {\n const value = window.getComputedStyle(element).getPropertyValue(key)?.trim();\n\n setValue(value ?? initialValue);\n };\n\n const observer = new MutationObserver(onChange);\n\n observer.observe(element, { attributeFilter: ['style', 'class'] });\n\n return () => {\n observer.disconnect();\n };\n }, [target, internalRef.state]);\n\n if (target) return { value, set, remove };\n return { ref: internalRef, value, set, remove };\n}) as UseCssVar;\n"],"names":["useCssVar","params","target","isTarget","key","initialValue","value","setValue","useState","internalRef","useRefState","elementRef","useRef","set","element","remove","useEffect","getElement","onChange","observer"],"mappings":";;;;AAsDO,MAAMA,IAAa,IAAIC,MAAkB;AAC9C,QAAMC,IAAUC,EAASF,EAAO,CAAC,CAAC,IAAIA,EAAO,CAAC,IAAI,QAC5CG,IAAOF,IAASD,EAAO,CAAC,IAAIA,EAAO,CAAC,GACpCI,IAAgBH,IAASD,EAAO,CAAC,IAAIA,EAAO,CAAC,GAE7C,CAACK,GAAOC,CAAQ,IAAIC,EAASH,KAAgB,EAAE,GAC/CI,IAAcC,EAAA,GACdC,IAAaC,EAAoB,IAAI,GAErCC,IAAM,CAACP,MAAkB;AAC7B,QAAI,CAACK,EAAW,QAAS;AACzB,UAAMG,IAAUH,EAAW;AAE3B,IAAKG,EAAQ,UACbA,EAAQ,MAAM,YAAYV,GAAKE,CAAK,GACpCC,EAASD,CAAK;AAAA,EAAA,GAGVS,IAAS,MAAM;AACnB,QAAI,CAACJ,EAAW,QAAS;AACzB,UAAMG,IAAUH,EAAW;AAC3B,IAAKG,EAAQ,UAEbA,EAAQ,MAAM,eAAeV,CAAG,GAChCG,EAAS,EAAE;AAAA,EAAA;AAqCb,SAlCAS,EAAU,MAAM;AACd,QAAI,CAACX,EAAc;AAEnB,UAAMS,KACFZ,IAASe,EAAWf,CAAM,IAAIO,EAAY,YAC5C,OAAO,SAAS;AAElB,IAAKK,EAAQ,UACbA,EAAQ,MAAM,YAAYV,GAAKC,CAAY,GAC3CE,EAASF,CAAY;AAAA,EAAA,GACpB,EAAE,GAELW,EAAU,MAAM;AACd,UAAMF,KACFZ,IAASe,EAAWf,CAAM,IAAIO,EAAY,YAC5C,OAAO,SAAS;AAElB,IAAAE,EAAW,UAAUG;AAErB,UAAMI,IAAW,MAAM;AACrB,YAAMZ,IAAQ,OAAO,iBAAiBQ,CAAO,EAAE,iBAAiBV,CAAG,GAAG,KAAA;AAEtE,MAAAG,EAASD,KAASD,CAAY;AAAA,IAAA,GAG1Bc,IAAW,IAAI,iBAAiBD,CAAQ;AAE9C,WAAAC,EAAS,QAAQL,GAAS,EAAE,iBAAiB,CAAC,SAAS,OAAO,GAAG,GAE1D,MAAM;AACX,MAAAK,EAAS,WAAA;AAAA,IAAW;AAAA,EACtB,GACC,CAACjB,GAAQO,EAAY,KAAK,CAAC,GAE1BP,IAAe,EAAE,OAAAI,GAAO,KAAAO,GAAK,QAAAE,EAAA,IAC1B,EAAE,KAAKN,GAAa,OAAAH,GAAO,KAAAO,GAAK,QAAAE,EAAA;AACzC;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDebounceCallback.mjs","sources":["../../../../src/hooks/useDebounceCallback/useDebounceCallback.ts"],"sourcesContent":["import { useMemo, useRef } from 'react';\n\nexport type DebouncedCallback<Params extends unknown[]> = ((...args: Params) => void) & {\n cancel: () => void;\n};\n\n/**\n * @name useDebounceCallback\n * @description - Hook that creates a debounced callback\n * @category Utilities\n *\n * @template Params The type of the params\n * @template Return The type of the return\n * @param {(...args: Params) => Return} callback The callback function\n * @param {number} delay The delay in milliseconds\n * @returns {(...args: Params) => Return} The callback with debounce\n *\n * @example\n * const debouncedCallback = useDebounceCallback(() => console.log('callback'), 500);\n */\nexport const useDebounceCallback = <Params extends unknown[], Return>(\n callback: (...args: Params) => Return,\n delay: number\n): DebouncedCallback<Params> => {\n const internalCallbackRef = useRef(callback);\n const timerRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n const delayRef = useRef(delay);\n\n internalCallbackRef.current = callback;\n delayRef.current = delay;\n\n const debounced = useMemo(() => {\n const cancel = () => {\n if (!timerRef.current) return;\n clearTimeout(timerRef.current);\n timerRef.current = null;\n };\n\n const debouncedCallback = function (this: any, ...args: Params) {\n cancel();\n timerRef.current = setTimeout(() => {\n internalCallbackRef.current.apply(this, args);\n }, delayRef.current);\n };\n\n debouncedCallback.cancel = cancel;\n\n return debouncedCallback;\n }, []);\n\n return debounced;\n};\n"],"names":["useDebounceCallback","callback","delay","internalCallbackRef","useRef","timerRef","delayRef","useMemo","cancel","debouncedCallback","args"],"mappings":";
|
|
1
|
+
{"version":3,"file":"useDebounceCallback.mjs","sources":["../../../../src/hooks/useDebounceCallback/useDebounceCallback.ts"],"sourcesContent":["import { useMemo, useRef } from 'react';\n\nexport type DebouncedCallback<Params extends unknown[]> = ((...args: Params) => void) & {\n cancel: () => void;\n};\n\n/**\n * @name useDebounceCallback\n * @description - Hook that creates a debounced callback\n * @category Utilities\n * @usage high\n *\n * @template Params The type of the params\n * @template Return The type of the return\n * @param {(...args: Params) => Return} callback The callback function\n * @param {number} delay The delay in milliseconds\n * @returns {(...args: Params) => Return} The callback with debounce\n *\n * @example\n * const debouncedCallback = useDebounceCallback(() => console.log('callback'), 500);\n */\nexport const useDebounceCallback = <Params extends unknown[], Return>(\n callback: (...args: Params) => Return,\n delay: number\n): DebouncedCallback<Params> => {\n const internalCallbackRef = useRef(callback);\n const timerRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n const delayRef = useRef(delay);\n\n internalCallbackRef.current = callback;\n delayRef.current = delay;\n\n const debounced = useMemo(() => {\n const cancel = () => {\n if (!timerRef.current) return;\n clearTimeout(timerRef.current);\n timerRef.current = null;\n };\n\n const debouncedCallback = function (this: any, ...args: Params) {\n cancel();\n timerRef.current = setTimeout(() => {\n internalCallbackRef.current.apply(this, args);\n }, delayRef.current);\n };\n\n debouncedCallback.cancel = cancel;\n\n return debouncedCallback;\n }, []);\n\n return debounced;\n};\n"],"names":["useDebounceCallback","callback","delay","internalCallbackRef","useRef","timerRef","delayRef","useMemo","cancel","debouncedCallback","args"],"mappings":";AAqBO,MAAMA,IAAsB,CACjCC,GACAC,MAC8B;AAC9B,QAAMC,IAAsBC,EAAOH,CAAQ,GACrCI,IAAWD,EAA6C,IAAI,GAC5DE,IAAWF,EAAOF,CAAK;AAE7B,SAAAC,EAAoB,UAAUF,GAC9BK,EAAS,UAAUJ,GAEDK,EAAQ,MAAM;AAC9B,UAAMC,IAAS,MAAM;AACnB,MAAKH,EAAS,YACd,aAAaA,EAAS,OAAO,GAC7BA,EAAS,UAAU;AAAA,IAAA,GAGfI,IAAoB,YAAwBC,GAAc;AAC9D,MAAAF,EAAA,GACAH,EAAS,UAAU,WAAW,MAAM;AAClC,QAAAF,EAAoB,QAAQ,MAAM,MAAMO,CAAI;AAAA,MAAA,GAC3CJ,EAAS,OAAO;AAAA,IAAA;AAGrB,WAAAG,EAAkB,SAASD,GAEpBC;AAAA,EAAA,GACN,EAAE;AAGP;"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { useState as n } from "react";
|
|
2
|
+
import { useDebounceCallback as a } from "../useDebounceCallback/useDebounceCallback.mjs";
|
|
3
|
+
const b = (e, t) => {
|
|
4
|
+
const [o, u] = n(e), c = a(u, t);
|
|
5
|
+
return [o, c];
|
|
6
|
+
};
|
|
7
|
+
export {
|
|
8
|
+
b as useDebounceState
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=useDebounceState.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useDebounceState.mjs","sources":["../../../../src/hooks/useDebounceState/useDebounceState.ts"],"sourcesContent":["import { useState } from 'react';\n\nimport { useDebounceCallback } from '../useDebounceCallback/useDebounceCallback';\n\n/**\n * @name useDebounceState\n * @description - Hook that creates a debounced state\n * @category Utilities\n * @usage high\n\n * @template Value The type of the value\n * @param {Value} value The value to be debounced\n * @param {number} delay The delay in milliseconds\n * @returns {[Value, (value: Value) => void]} The debounced state\n *\n * @example\n * const [debouncedValue, setDebouncedValue] = useDebounceState(value, 500);\n */\nexport const useDebounceState = <Value>(initialValue: Value, delay: number) => {\n const [debouncedValue, setDebouncedValue] = useState(initialValue);\n const debouncedSetState = useDebounceCallback(setDebouncedValue, delay);\n\n return [debouncedValue, debouncedSetState] as const;\n};\n"],"names":["useDebounceState","initialValue","delay","debouncedValue","setDebouncedValue","useState","debouncedSetState","useDebounceCallback"],"mappings":";;AAkBO,MAAMA,IAAmB,CAAQC,GAAqBC,MAAkB;AAC7E,QAAM,CAACC,GAAgBC,CAAiB,IAAIC,EAASJ,CAAY,GAC3DK,IAAoBC,EAAoBH,GAAmBF,CAAK;AAEtE,SAAO,CAACC,GAAgBG,CAAiB;AAC3C;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDebounceValue.mjs","sources":["../../../../src/hooks/useDebounceValue/useDebounceValue.ts"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\n\nimport { useDebounceCallback } from '../useDebounceCallback/useDebounceCallback';\n\n/**\n * @name useDebounceValue\n * @description - Hook that creates a debounced value\n * @category Utilities\n
|
|
1
|
+
{"version":3,"file":"useDebounceValue.mjs","sources":["../../../../src/hooks/useDebounceValue/useDebounceValue.ts"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\n\nimport { useDebounceCallback } from '../useDebounceCallback/useDebounceCallback';\n\n/**\n * @name useDebounceValue\n * @description - Hook that creates a debounced value\n * @category Utilities\n * @usage high\n\n * @template Value The type of the value\n * @param {Value} value The value to be debounced\n * @param {number} delay The delay in milliseconds\n * @returns {Value} The debounced value\n *\n * @example\n * const debouncedValue = useDebounceValue(value, 500);\n */\nexport const useDebounceValue = <Value>(value: Value, delay: number) => {\n const previousValueRef = useRef(value);\n const [debouncedValue, setDebounceValue] = useState(value);\n\n const debouncedSetState = useDebounceCallback(setDebounceValue, delay);\n\n useEffect(() => {\n if (previousValueRef.current === value) return;\n debouncedSetState(value);\n previousValueRef.current = value;\n }, [value]);\n\n return debouncedValue;\n};\n"],"names":["useDebounceValue","value","delay","previousValueRef","useRef","debouncedValue","setDebounceValue","useState","debouncedSetState","useDebounceCallback","useEffect"],"mappings":";;AAkBO,MAAMA,IAAmB,CAAQC,GAAcC,MAAkB;AACtE,QAAMC,IAAmBC,EAAOH,CAAK,GAC/B,CAACI,GAAgBC,CAAgB,IAAIC,EAASN,CAAK,GAEnDO,IAAoBC,EAAoBH,GAAkBJ,CAAK;AAErE,SAAAQ,EAAU,MAAM;AACd,IAAIP,EAAiB,YAAYF,MACjCO,EAAkBP,CAAK,GACvBE,EAAiB,UAAUF;AAAA,EAAA,GAC1B,CAACA,CAAK,CAAC,GAEHI;AACT;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDefault.mjs","sources":["../../../../src/hooks/useDefault/useDefault.ts"],"sourcesContent":["import { useState } from 'react';\n\n/**\n * @name useDefault\n * @description - Hook that returns the default value\n * @category State\n
|
|
1
|
+
{"version":3,"file":"useDefault.mjs","sources":["../../../../src/hooks/useDefault/useDefault.ts"],"sourcesContent":["import { useState } from 'react';\n\n/**\n * @name useDefault\n * @description - Hook that returns the default value\n * @category State\n * @usage medium\n\n * @template Value The type of the value\n * @param {Value} initialValue The initial value\n * @param {Value} defaultValue The default value\n * @returns {[Value, (value: Value) => void]} An array containing the current value and a function to set the value\n *\n * @example\n * const [value, setValue] = useDefault(initialValue, defaultValue);\n */\nexport const useDefault = <Value>(initialValue: (() => Value) | Value, defaultValue: Value) => {\n const [value, setValue] = useState<Value | null | undefined>(initialValue);\n return [value === undefined || value === null ? defaultValue : value, setValue] as const;\n};\n"],"names":["useDefault","initialValue","defaultValue","value","setValue","useState"],"mappings":";AAgBO,MAAMA,IAAa,CAAQC,GAAqCC,MAAwB;AAC7F,QAAM,CAACC,GAAOC,CAAQ,IAAIC,EAAmCJ,CAAY;AACzE,SAAO,CAAwBE,KAAiBD,GAAsBE,CAAQ;AAChF;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDeviceMotion.mjs","sources":["../../../../src/hooks/useDeviceMotion/useDeviceMotion.ts"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\n\nimport { throttle } from '@/utils/helpers';\n\nexport interface UseDeviceMotionReturn {\n acceleration: DeviceMotionEventAcceleration;\n accelerationIncludingGravity: DeviceMotionEventAcceleration;\n interval: DeviceMotionEvent['interval'];\n rotationRate: DeviceMotionEventRotationRate;\n}\n\nexport interface UseDeviceMotionParams {\n /** The delay in milliseconds */\n delay?: number;\n /** Whether to enable the hook */\n enabled?: boolean;\n /** The callback function to be invoked */\n callback?: (event: DeviceMotionEvent) => void;\n}\n\n/**\n * @name useDeviceMotion\n * @description - Hook that work with device motion\n * @category
|
|
1
|
+
{"version":3,"file":"useDeviceMotion.mjs","sources":["../../../../src/hooks/useDeviceMotion/useDeviceMotion.ts"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\n\nimport { throttle } from '@/utils/helpers';\n\nexport interface UseDeviceMotionReturn {\n acceleration: DeviceMotionEventAcceleration;\n accelerationIncludingGravity: DeviceMotionEventAcceleration;\n interval: DeviceMotionEvent['interval'];\n rotationRate: DeviceMotionEventRotationRate;\n}\n\nexport interface UseDeviceMotionParams {\n /** The delay in milliseconds */\n delay?: number;\n /** Whether to enable the hook */\n enabled?: boolean;\n /** The callback function to be invoked */\n callback?: (event: DeviceMotionEvent) => void;\n}\n\n/**\n * @name useDeviceMotion\n * @description - Hook that work with device motion\n * @category Sensors\n * @usage low\n *\n * @browserapi DeviceMotionEvent https://developer.mozilla.org/en-US/docs/Web/API/Window/DeviceMotionEvent\n *\n * @param {number} [delay=1000] The delay in milliseconds\n * @param {(event: DeviceMotionEvent) => void} [callback] The callback function to be invoked\n * @param {boolean} [enabled=true] Whether to enable the hook\n * @returns {UseDeviceMotionReturn} The device motion data and interval\n *\n * @example\n * const { interval, rotationRate, acceleration, accelerationIncludingGravity } = useDeviceMotion();\n */\nexport const useDeviceMotion = (params?: UseDeviceMotionParams) => {\n const enabled = params?.enabled ?? true;\n const delay = params?.delay ?? 1000;\n const [value, setValue] = useState<UseDeviceMotionReturn>({\n interval: 0,\n rotationRate: { alpha: null, beta: null, gamma: null },\n acceleration: { x: null, y: null, z: null },\n accelerationIncludingGravity: { x: null, y: null, z: null }\n });\n const internalCallbackRef = useRef(params?.callback);\n internalCallbackRef.current = params?.callback;\n\n useEffect(() => {\n if (!enabled) return;\n\n const onDeviceMotion = throttle<[DeviceMotionEvent]>((event) => {\n internalCallbackRef.current?.(event);\n\n setValue({\n interval: event.interval,\n rotationRate: {\n ...value.rotationRate,\n ...event.rotationRate\n },\n acceleration: {\n ...value.acceleration,\n ...event.acceleration\n },\n accelerationIncludingGravity: {\n ...value.accelerationIncludingGravity,\n ...event.accelerationIncludingGravity\n }\n });\n }, delay);\n\n window.addEventListener('devicemotion', onDeviceMotion);\n\n return () => {\n window.removeEventListener('devicemotion', onDeviceMotion);\n };\n }, [delay, enabled]);\n\n return value;\n};\n"],"names":["useDeviceMotion","params","enabled","delay","value","setValue","useState","internalCallbackRef","useRef","useEffect","onDeviceMotion","throttle","event"],"mappings":";;AAoCO,MAAMA,IAAkB,CAACC,MAAmC;AACjE,QAAMC,IAAUD,GAAQ,WAAW,IAC7BE,IAAQF,GAAQ,SAAS,KACzB,CAACG,GAAOC,CAAQ,IAAIC,EAAgC;AAAA,IACxD,UAAU;AAAA,IACV,cAAc,EAAE,OAAO,MAAM,MAAM,MAAM,OAAO,KAAA;AAAA,IAChD,cAAc,EAAE,GAAG,MAAM,GAAG,MAAM,GAAG,KAAA;AAAA,IACrC,8BAA8B,EAAE,GAAG,MAAM,GAAG,MAAM,GAAG,KAAA;AAAA,EAAK,CAC3D,GACKC,IAAsBC,EAAOP,GAAQ,QAAQ;AACnD,SAAAM,EAAoB,UAAUN,GAAQ,UAEtCQ,EAAU,MAAM;AACd,QAAI,CAACP,EAAS;AAEd,UAAMQ,IAAiBC,EAA8B,CAACC,MAAU;AAC9D,MAAAL,EAAoB,UAAUK,CAAK,GAEnCP,EAAS;AAAA,QACP,UAAUO,EAAM;AAAA,QAChB,cAAc;AAAA,UACZ,GAAGR,EAAM;AAAA,UACT,GAAGQ,EAAM;AAAA,QAAA;AAAA,QAEX,cAAc;AAAA,UACZ,GAAGR,EAAM;AAAA,UACT,GAAGQ,EAAM;AAAA,QAAA;AAAA,QAEX,8BAA8B;AAAA,UAC5B,GAAGR,EAAM;AAAA,UACT,GAAGQ,EAAM;AAAA,QAAA;AAAA,MACX,CACD;AAAA,IAAA,GACAT,CAAK;AAER,kBAAO,iBAAiB,gBAAgBO,CAAc,GAE/C,MAAM;AACX,aAAO,oBAAoB,gBAAgBA,CAAc;AAAA,IAAA;AAAA,EAC3D,GACC,CAACP,GAAOD,CAAO,CAAC,GAEZE;AACT;"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useState as o, useEffect as r } from "react";
|
|
2
2
|
const l = () => {
|
|
3
|
-
const t = typeof window < "u" && "DeviceOrientationEvent" in window, [a, i] = o({
|
|
3
|
+
const t = typeof window < "u" && "DeviceOrientationEvent" in window && !!window.DeviceOrientationEvent, [a, i] = o({
|
|
4
4
|
alpha: null,
|
|
5
5
|
beta: null,
|
|
6
6
|
gamma: null,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDeviceOrientation.mjs","sources":["../../../../src/hooks/useDeviceOrientation/useDeviceOrientation.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\n/* The use device orientation value type */\nexport interface UseDeviceOrientationValue {\n /** The current absolute value */\n absolute: boolean;\n /** A number representing the motion of the device around the z axis, express in degrees with values ranging from 0 to 360 */\n alpha: number | null;\n /** A number representing the motion of the device around the x axis, express in degrees with values ranging from -180 to 180 */\n beta: number | null;\n /** A number representing the motion of the device around the y axis, express in degrees with values ranging from -90 to 90 */\n gamma: number | null;\n}\n\n/* The use device orientation return type */\nexport interface UseDeviceOrientationReturn {\n /** Whether the device orientation is supported */\n supported: boolean;\n /** The current device orientation value */\n value: UseDeviceOrientationValue;\n}\n\n/**\n * @name useDeviceOrientation\n * @description - Hook that provides the current device orientation\n * @category Sensors\n *\n * @browserapi DeviceOrientationEvent https://developer.mozilla.org/en-US/docs/Web/API/Window/DeviceOrientationEvent\n *\n * @returns {UseDeviceOrientationReturn} The current device orientation\n *\n * @example\n * const { supported, value } = useDeviceOrientation();\n */\nexport const useDeviceOrientation = (): UseDeviceOrientationReturn => {\n const supported
|
|
1
|
+
{"version":3,"file":"useDeviceOrientation.mjs","sources":["../../../../src/hooks/useDeviceOrientation/useDeviceOrientation.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\n/* The use device orientation value type */\nexport interface UseDeviceOrientationValue {\n /** The current absolute value */\n absolute: boolean;\n /** A number representing the motion of the device around the z axis, express in degrees with values ranging from 0 to 360 */\n alpha: number | null;\n /** A number representing the motion of the device around the x axis, express in degrees with values ranging from -180 to 180 */\n beta: number | null;\n /** A number representing the motion of the device around the y axis, express in degrees with values ranging from -90 to 90 */\n gamma: number | null;\n}\n\n/* The use device orientation return type */\nexport interface UseDeviceOrientationReturn {\n /** Whether the device orientation is supported */\n supported: boolean;\n /** The current device orientation value */\n value: UseDeviceOrientationValue;\n}\n\n/**\n * @name useDeviceOrientation\n * @description - Hook that provides the current device orientation\n * @category Sensors\n * @usage low\n *\n * @browserapi DeviceOrientationEvent https://developer.mozilla.org/en-US/docs/Web/API/Window/DeviceOrientationEvent\n *\n * @returns {UseDeviceOrientationReturn} The current device orientation\n *\n * @example\n * const { supported, value } = useDeviceOrientation();\n */\nexport const useDeviceOrientation = (): UseDeviceOrientationReturn => {\n const supported =\n typeof window !== 'undefined' &&\n 'DeviceOrientationEvent' in window &&\n !!window.DeviceOrientationEvent;\n\n const [value, setValue] = useState<UseDeviceOrientationValue>({\n alpha: null,\n beta: null,\n gamma: null,\n absolute: false\n });\n\n useEffect(() => {\n if (!supported) return;\n\n const onDeviceOrientation = (event: DeviceOrientationEvent) =>\n setValue({\n alpha: event.alpha,\n beta: event.beta,\n gamma: event.gamma,\n absolute: event.absolute\n });\n\n window.addEventListener('deviceorientation', onDeviceOrientation);\n return () => {\n window.removeEventListener('deviceorientation', onDeviceOrientation);\n };\n }, []);\n\n return {\n supported,\n value\n };\n};\n"],"names":["useDeviceOrientation","supported","value","setValue","useState","useEffect","onDeviceOrientation","event"],"mappings":";AAmCO,MAAMA,IAAuB,MAAkC;AACpE,QAAMC,IACJ,OAAO,SAAW,OAClB,4BAA4B,UAC5B,CAAC,CAAC,OAAO,wBAEL,CAACC,GAAOC,CAAQ,IAAIC,EAAoC;AAAA,IAC5D,OAAO;AAAA,IACP,MAAM;AAAA,IACN,OAAO;AAAA,IACP,UAAU;AAAA,EAAA,CACX;AAED,SAAAC,EAAU,MAAM;AACd,QAAI,CAACJ,EAAW;AAEhB,UAAMK,IAAsB,CAACC,MAC3BJ,EAAS;AAAA,MACP,OAAOI,EAAM;AAAA,MACb,MAAMA,EAAM;AAAA,MACZ,OAAOA,EAAM;AAAA,MACb,UAAUA,EAAM;AAAA,IAAA,CACjB;AAEH,kBAAO,iBAAiB,qBAAqBD,CAAmB,GACzD,MAAM;AACX,aAAO,oBAAoB,qBAAqBA,CAAmB;AAAA,IAAA;AAAA,EACrE,GACC,EAAE,GAEE;AAAA,IACL,WAAAL;AAAA,IACA,OAAAC;AAAA,EAAA;AAEJ;"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useState as d, useEffect as a } from "react";
|
|
2
2
|
const r = () => {
|
|
3
|
-
const e = typeof window < "u" && typeof window.matchMedia == "function" && typeof window.devicePixelRatio == "number", [i, n] = d(window.devicePixelRatio
|
|
3
|
+
const e = typeof window < "u" && typeof window.matchMedia == "function" && typeof window.devicePixelRatio == "number", [i, n] = d(e ? window.devicePixelRatio : 1);
|
|
4
4
|
return a(() => {
|
|
5
5
|
if (!e) return;
|
|
6
6
|
const t = () => n(window.devicePixelRatio), o = window.matchMedia(`(resolution: ${window.devicePixelRatio}dppx)`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDevicePixelRatio.mjs","sources":["../../../../src/hooks/useDevicePixelRatio/useDevicePixelRatio.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\n/** The use device pixel ratio return type */\nexport interface UseDevicePixelRatioReturn {\n /** The ratio of the resolution in physical pixels to the resolution in CSS pixels */\n ratio: number;\n /** Whether the device pixel ratio is supported*/\n supported: boolean;\n}\n\n/**\n * @name useDevicePixelRatio\n * @description - Hook that returns the device's pixel ratio\n * @category Utilities\n *\n * @browserapi window.devicePixelRatio https://developer.mozilla.org/en-US/docs/Web/API/Window/devicePixelRatio\n *\n * @returns {UseDevicePixelRatioReturn} The ratio and supported flag\n *\n * @example\n * const { supported, ratio } = useDevicePixelRatio();\n */\nexport const useDevicePixelRatio = (): UseDevicePixelRatioReturn => {\n const supported =\n typeof window !== 'undefined' &&\n typeof window.matchMedia === 'function' &&\n typeof window.devicePixelRatio === 'number';\n\n const [ratio, setRatio] = useState
|
|
1
|
+
{"version":3,"file":"useDevicePixelRatio.mjs","sources":["../../../../src/hooks/useDevicePixelRatio/useDevicePixelRatio.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\n/** The use device pixel ratio return type */\nexport interface UseDevicePixelRatioReturn {\n /** The ratio of the resolution in physical pixels to the resolution in CSS pixels */\n ratio: number;\n /** Whether the device pixel ratio is supported*/\n supported: boolean;\n}\n\n/**\n * @name useDevicePixelRatio\n * @description - Hook that returns the device's pixel ratio\n * @category Utilities\n * @usage low\n *\n * @browserapi window.devicePixelRatio https://developer.mozilla.org/en-US/docs/Web/API/Window/devicePixelRatio\n *\n * @returns {UseDevicePixelRatioReturn} The ratio and supported flag\n *\n * @example\n * const { supported, ratio } = useDevicePixelRatio();\n */\nexport const useDevicePixelRatio = (): UseDevicePixelRatioReturn => {\n const supported =\n typeof window !== 'undefined' &&\n typeof window.matchMedia === 'function' &&\n typeof window.devicePixelRatio === 'number';\n\n const [ratio, setRatio] = useState(supported ? window.devicePixelRatio : 1);\n\n useEffect(() => {\n if (!supported) return;\n\n const onChange = () => setRatio(window.devicePixelRatio);\n\n const media = window.matchMedia(`(resolution: ${window.devicePixelRatio}dppx)`);\n media.addEventListener('change', onChange);\n return () => {\n media.removeEventListener('change', onChange);\n };\n }, [ratio]);\n\n return { supported, ratio };\n};\n"],"names":["useDevicePixelRatio","supported","ratio","setRatio","useState","useEffect","onChange","media"],"mappings":";AAuBO,MAAMA,IAAsB,MAAiC;AAClE,QAAMC,IACJ,OAAO,SAAW,OAClB,OAAO,OAAO,cAAe,cAC7B,OAAO,OAAO,oBAAqB,UAE/B,CAACC,GAAOC,CAAQ,IAAIC,EAASH,IAAY,OAAO,mBAAmB,CAAC;AAE1E,SAAAI,EAAU,MAAM;AACd,QAAI,CAACJ,EAAW;AAEhB,UAAMK,IAAW,MAAMH,EAAS,OAAO,gBAAgB,GAEjDI,IAAQ,OAAO,WAAW,gBAAgB,OAAO,gBAAgB,OAAO;AAC9E,WAAAA,EAAM,iBAAiB,UAAUD,CAAQ,GAClC,MAAM;AACX,MAAAC,EAAM,oBAAoB,UAAUD,CAAQ;AAAA,IAAA;AAAA,EAC9C,GACC,CAACJ,CAAK,CAAC,GAEH,EAAE,WAAAD,GAAW,OAAAC,EAAA;AACtB;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDidUpdate.mjs","sources":["../../../../src/hooks/useDidUpdate/useDidUpdate.ts"],"sourcesContent":["import type { DependencyList, EffectCallback } from 'react';\n\nimport { useRef } from 'react';\n\nimport { useIsomorphicLayoutEffect } from '../useIsomorphicLayoutEffect/useIsomorphicLayoutEffect';\n\n/**\n * @name useDidUpdate\n * @description – Hook that triggers the effect callback on updates\n * @category Lifecycle\n
|
|
1
|
+
{"version":3,"file":"useDidUpdate.mjs","sources":["../../../../src/hooks/useDidUpdate/useDidUpdate.ts"],"sourcesContent":["import type { DependencyList, EffectCallback } from 'react';\n\nimport { useRef } from 'react';\n\nimport { useIsomorphicLayoutEffect } from '../useIsomorphicLayoutEffect/useIsomorphicLayoutEffect';\n\n/**\n * @name useDidUpdate\n * @description – Hook that triggers the effect callback on updates\n * @category Lifecycle\n * @usage necessary\n\n * @param {EffectCallback} effect The effect callback\n * @param {DependencyList} [deps] The dependencies list for the effect\n *\n * @example\n * useDidUpdate(() => console.log(\"effect runs on updates\"), deps);\n */\nexport const useDidUpdate = (effect: EffectCallback, deps?: DependencyList) => {\n const mounted = useRef(false);\n\n useIsomorphicLayoutEffect(\n () => () => {\n mounted.current = false;\n },\n []\n );\n\n useIsomorphicLayoutEffect(() => {\n if (mounted.current) {\n return effect();\n }\n\n mounted.current = true;\n return undefined;\n }, deps);\n};\n"],"names":["useDidUpdate","effect","deps","mounted","useRef","useIsomorphicLayoutEffect"],"mappings":";;AAkBO,MAAMA,IAAe,CAACC,GAAwBC,MAA0B;AAC7E,QAAMC,IAAUC,EAAO,EAAK;AAE5B,EAAAC;AAAA,IACE,MAAM,MAAM;AACV,MAAAF,EAAQ,UAAU;AAAA,IAAA;AAAA,IAEpB,CAAA;AAAA,EAAC,GAGHE,EAA0B,MAAM;AAC9B,QAAIF,EAAQ;AACV,aAAOF,EAAA;AAGT,IAAAE,EAAQ,UAAU;AAAA,EACX,GACND,CAAI;AACT;"}
|