@siberiacancode/reactuse 0.2.11 → 0.2.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +71 -71
- package/dist/cjs/helpers/createContext/createContext.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 +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/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/useBrowserLanguage/useBrowserLanguage.cjs.map +1 -1
- package/dist/cjs/hooks/useClickOutside/useClickOutside.cjs.map +1 -1
- package/dist/cjs/hooks/useClipboard/useClipboard.cjs +1 -1
- package/dist/cjs/hooks/useClipboard/useClipboard.cjs.map +1 -1
- package/dist/cjs/hooks/useCookie/useCookie.cjs +1 -1
- package/dist/cjs/hooks/useCookie/useCookie.cjs.map +1 -1
- package/dist/cjs/hooks/useCookies/useCookies.cjs +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 +1 -1
- package/dist/cjs/hooks/useCounter/useCounter.cjs.map +1 -1
- package/dist/cjs/hooks/useCssVar/useCssVar.cjs +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/useDebounceValue/useDebounceValue.cjs.map +1 -1
- package/dist/cjs/hooks/useDeviceMotion/useDeviceMotion.cjs +1 -1
- package/dist/cjs/hooks/useDeviceMotion/useDeviceMotion.cjs.map +1 -1
- package/dist/cjs/hooks/useDeviceOrientation/useDeviceOrientation.cjs.map +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 +1 -1
- package/dist/cjs/hooks/useDisclosure/useDisclosure.cjs.map +1 -1
- package/dist/cjs/hooks/useDisplayMedia/useDisplayMedia.cjs +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 +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 +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.map +1 -1
- package/dist/cjs/hooks/useEventSource/useEventSource.cjs +1 -1
- package/dist/cjs/hooks/useEventSource/useEventSource.cjs.map +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 +1 -1
- package/dist/cjs/hooks/useField/useField.cjs.map +1 -1
- package/dist/cjs/hooks/useFileDialog/useFileDialog.cjs +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 +1 -1
- package/dist/cjs/hooks/useFullscreen/useFullscreen.cjs.map +1 -1
- package/dist/cjs/hooks/useGamepad/useGamepad.cjs.map +1 -1
- package/dist/cjs/hooks/useGeolocation/useGeolocation.cjs +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 +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 +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 +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/useKeyPress/useKeyPress.cjs +1 -1
- package/dist/cjs/hooks/useKeyPress/useKeyPress.cjs.map +1 -1
- package/dist/cjs/hooks/useKeyPressEvent/useKeyPressEvent.cjs +1 -1
- package/dist/cjs/hooks/useKeyPressEvent/useKeyPressEvent.cjs.map +1 -1
- package/dist/cjs/hooks/useKeyboard/useKeyboard.cjs +1 -1
- package/dist/cjs/hooks/useKeyboard/useKeyboard.cjs.map +1 -1
- package/dist/cjs/hooks/useKeysPressed/useKeysPressed.cjs +1 -1
- package/dist/cjs/hooks/useKeysPressed/useKeysPressed.cjs.map +1 -1
- package/dist/cjs/hooks/useLastChanged/useLastChanged.cjs +1 -1
- package/dist/cjs/hooks/useLastChanged/useLastChanged.cjs.map +1 -1
- package/dist/cjs/hooks/useLatest/useLatest.cjs +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/useLockCallback/useLockCallback.cjs.map +1 -1
- package/dist/cjs/hooks/useLogger/useLogger.cjs.map +1 -1
- package/dist/cjs/hooks/useLongPress/useLongPress.cjs +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/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/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 +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.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 +1 -1
- package/dist/cjs/hooks/usePageLeave/usePageLeave.cjs.map +1 -1
- package/dist/cjs/hooks/usePaint/usePaint.cjs +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/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/usePreferredLanguages/usePreferredLanguages.cjs.map +1 -1
- package/dist/cjs/hooks/usePreferredReducedMotion/usePreferredReducedMotion.cjs.map +1 -1
- package/dist/cjs/hooks/usePrevious/usePrevious.cjs +1 -1
- package/dist/cjs/hooks/usePrevious/usePrevious.cjs.map +1 -1
- package/dist/cjs/hooks/useQuery/useQuery.cjs +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 +1 -1
- package/dist/cjs/hooks/useRaf/useRaf.cjs.map +1 -1
- package/dist/cjs/hooks/useRafValue/useRafValue.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/useScreenOrientation/useScreenOrientation.cjs +1 -1
- package/dist/cjs/hooks/useScreenOrientation/useScreenOrientation.cjs.map +1 -1
- package/dist/cjs/hooks/useScript/useScript.cjs +1 -1
- package/dist/cjs/hooks/useScript/useScript.cjs.map +1 -1
- package/dist/cjs/hooks/useScroll/useScroll.cjs +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/useSet/useSet.cjs.map +1 -1
- package/dist/cjs/hooks/useShare/useShare.cjs.map +1 -1
- package/dist/cjs/hooks/useSpeechRecognition/useSpeechRecognition.cjs +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 +1 -1
- package/dist/cjs/hooks/useSticky/useSticky.cjs.map +1 -1
- package/dist/cjs/hooks/useStopwatch/useStopwatch.cjs +1 -1
- package/dist/cjs/hooks/useStopwatch/useStopwatch.cjs.map +1 -1
- package/dist/cjs/hooks/useStorage/useStorage.cjs +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 +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/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 +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 +1 -1
- package/dist/cjs/hooks/useUrlSearchParam/useUrlSearchParam.cjs.map +1 -1
- package/dist/cjs/hooks/useUrlSearchParams/useUrlSearchParams.cjs +1 -1
- package/dist/cjs/hooks/useUrlSearchParams/useUrlSearchParams.cjs.map +1 -1
- package/dist/cjs/hooks/useVibrate/useVibrate.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 +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 +1 -1
- package/dist/cjs/hooks/useWindowSize/useWindowSize.cjs.map +1 -1
- package/dist/cjs/hooks/useWizard/useWizard.cjs +1 -1
- package/dist/cjs/hooks/useWizard/useWizard.cjs.map +1 -1
- package/dist/cjs/utils/helpers/copy.cjs.map +1 -1
- package/dist/cjs/utils/helpers/debounce.cjs.map +1 -1
- package/dist/cjs/utils/helpers/getDate.cjs.map +1 -1
- package/dist/cjs/utils/helpers/getElement.cjs.map +1 -1
- package/dist/cjs/utils/helpers/getRetry.cjs.map +1 -1
- package/dist/cjs/utils/helpers/isTarget.cjs.map +1 -1
- package/dist/cjs/utils/helpers/throttle.cjs.map +1 -1
- package/dist/esm/helpers/createContext/createContext.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 +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/useBattery/useBattery.mjs +10 -10
- package/dist/esm/hooks/useBattery/useBattery.mjs.map +1 -1
- package/dist/esm/hooks/useBluetooth/useBluetooth.mjs +14 -15
- 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/useBrowserLanguage/useBrowserLanguage.mjs.map +1 -1
- package/dist/esm/hooks/useClickOutside/useClickOutside.mjs.map +1 -1
- package/dist/esm/hooks/useClipboard/useClipboard.mjs +13 -14
- 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 +27 -27
- package/dist/esm/hooks/useCookie/useCookie.mjs.map +1 -1
- package/dist/esm/hooks/useCookies/useCookies.mjs +19 -19
- 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 +5 -6
- package/dist/esm/hooks/useCounter/useCounter.mjs.map +1 -1
- package/dist/esm/hooks/useCssVar/useCssVar.mjs +13 -14
- package/dist/esm/hooks/useCssVar/useCssVar.mjs.map +1 -1
- package/dist/esm/hooks/useDebounceCallback/useDebounceCallback.mjs.map +1 -1
- 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 +18 -19
- package/dist/esm/hooks/useDeviceMotion/useDeviceMotion.mjs.map +1 -1
- package/dist/esm/hooks/useDeviceOrientation/useDeviceOrientation.mjs.map +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 +5 -11
- package/dist/esm/hooks/useDisclosure/useDisclosure.mjs.map +1 -1
- package/dist/esm/hooks/useDisplayMedia/useDisplayMedia.mjs +28 -28
- 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 +15 -15
- 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 +11 -13
- package/dist/esm/hooks/useDoubleClick/useDoubleClick.mjs.map +1 -1
- package/dist/esm/hooks/useDropZone/useDropZone.mjs +27 -28
- 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.map +1 -1
- package/dist/esm/hooks/useEventSource/useEventSource.mjs +37 -40
- package/dist/esm/hooks/useEventSource/useEventSource.mjs.map +1 -1
- package/dist/esm/hooks/useEyeDropper/useEyeDropper.mjs.map +1 -1
- package/dist/esm/hooks/useFavicon/useFavicon.mjs +11 -12
- package/dist/esm/hooks/useFavicon/useFavicon.mjs.map +1 -1
- package/dist/esm/hooks/useField/useField.mjs +45 -49
- package/dist/esm/hooks/useField/useField.mjs.map +1 -1
- package/dist/esm/hooks/useFileDialog/useFileDialog.mjs +22 -25
- package/dist/esm/hooks/useFileDialog/useFileDialog.mjs.map +1 -1
- package/dist/esm/hooks/useFocus/useFocus.mjs +24 -32
- 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 +23 -24
- package/dist/esm/hooks/useFullscreen/useFullscreen.mjs.map +1 -1
- package/dist/esm/hooks/useGamepad/useGamepad.mjs.map +1 -1
- package/dist/esm/hooks/useGeolocation/useGeolocation.mjs +24 -24
- 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 +24 -25
- package/dist/esm/hooks/useHotkeys/useHotkeys.mjs.map +1 -1
- package/dist/esm/hooks/useHover/useHover.mjs +20 -22
- 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 +14 -14
- package/dist/esm/hooks/useInfiniteScroll/useInfiniteScroll.mjs.map +1 -1
- package/dist/esm/hooks/useIntersectionObserver/useIntersectionObserver.mjs +19 -20
- package/dist/esm/hooks/useIntersectionObserver/useIntersectionObserver.mjs.map +1 -1
- package/dist/esm/hooks/useInterval/useInterval.mjs +8 -8
- package/dist/esm/hooks/useInterval/useInterval.mjs.map +1 -1
- package/dist/esm/hooks/useIsFirstRender/useIsFirstRender.mjs.map +1 -1
- package/dist/esm/hooks/useKeyPress/useKeyPress.mjs +22 -24
- package/dist/esm/hooks/useKeyPress/useKeyPress.mjs.map +1 -1
- package/dist/esm/hooks/useKeyPressEvent/useKeyPressEvent.mjs +23 -23
- package/dist/esm/hooks/useKeyPressEvent/useKeyPressEvent.mjs.map +1 -1
- package/dist/esm/hooks/useKeyboard/useKeyboard.mjs +16 -22
- package/dist/esm/hooks/useKeyboard/useKeyboard.mjs.map +1 -1
- package/dist/esm/hooks/useKeysPressed/useKeysPressed.mjs +20 -20
- package/dist/esm/hooks/useKeysPressed/useKeysPressed.mjs.map +1 -1
- package/dist/esm/hooks/useLastChanged/useLastChanged.mjs +6 -6
- package/dist/esm/hooks/useLastChanged/useLastChanged.mjs.map +1 -1
- package/dist/esm/hooks/useLatest/useLatest.mjs +12 -4
- 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/useLockCallback/useLockCallback.mjs.map +1 -1
- package/dist/esm/hooks/useLogger/useLogger.mjs.map +1 -1
- package/dist/esm/hooks/useLongPress/useLongPress.mjs +23 -27
- 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/useMediaQuery/useMediaQuery.mjs.map +1 -1
- package/dist/esm/hooks/useMemory/useMemory.mjs +1 -1
- package/dist/esm/hooks/useMemory/useMemory.mjs.map +1 -1
- 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 +38 -42
- package/dist/esm/hooks/useMutation/useMutation.mjs.map +1 -1
- package/dist/esm/hooks/useMutationObserver/useMutationObserver.mjs +12 -12
- package/dist/esm/hooks/useMutationObserver/useMutationObserver.mjs.map +1 -1
- package/dist/esm/hooks/useNetwork/useNetwork.mjs +28 -28
- 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.map +1 -1
- package/dist/esm/hooks/useOtpCredential/useOtpCredential.mjs +12 -13
- package/dist/esm/hooks/useOtpCredential/useOtpCredential.mjs.map +1 -1
- package/dist/esm/hooks/usePageLeave/usePageLeave.mjs +6 -6
- package/dist/esm/hooks/usePageLeave/usePageLeave.mjs.map +1 -1
- package/dist/esm/hooks/usePaint/usePaint.mjs +87 -93
- 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 +17 -19
- package/dist/esm/hooks/usePerformanceObserver/usePerformanceObserver.mjs.map +1 -1
- package/dist/esm/hooks/usePermission/usePermission.mjs +13 -13
- package/dist/esm/hooks/usePermission/usePermission.mjs.map +1 -1
- 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/usePrevious/usePrevious.mjs +4 -4
- package/dist/esm/hooks/usePrevious/usePrevious.mjs.map +1 -1
- package/dist/esm/hooks/useQuery/useQuery.mjs +39 -41
- 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 +21 -21
- package/dist/esm/hooks/useRaf/useRaf.mjs.map +1 -1
- package/dist/esm/hooks/useRafValue/useRafValue.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 +16 -17
- package/dist/esm/hooks/useResizeObserver/useResizeObserver.mjs.map +1 -1
- package/dist/esm/hooks/useScreenOrientation/useScreenOrientation.mjs +11 -11
- package/dist/esm/hooks/useScreenOrientation/useScreenOrientation.mjs.map +1 -1
- package/dist/esm/hooks/useScript/useScript.mjs +16 -16
- package/dist/esm/hooks/useScript/useScript.mjs.map +1 -1
- package/dist/esm/hooks/useScroll/useScroll.mjs +37 -39
- 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/useSet/useSet.mjs.map +1 -1
- package/dist/esm/hooks/useShare/useShare.mjs.map +1 -1
- package/dist/esm/hooks/useSpeechRecognition/useSpeechRecognition.mjs +35 -35
- package/dist/esm/hooks/useSpeechRecognition/useSpeechRecognition.mjs.map +1 -1
- package/dist/esm/hooks/useSpeechSynthesis/useSpeechSynthesis.mjs +36 -42
- 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 +12 -12
- package/dist/esm/hooks/useSticky/useSticky.mjs.map +1 -1
- package/dist/esm/hooks/useStopwatch/useStopwatch.mjs +10 -11
- package/dist/esm/hooks/useStopwatch/useStopwatch.mjs.map +1 -1
- package/dist/esm/hooks/useStorage/useStorage.mjs +27 -27
- package/dist/esm/hooks/useStorage/useStorage.mjs.map +1 -1
- package/dist/esm/hooks/useTextDirection/useTextDirection.mjs +21 -24
- package/dist/esm/hooks/useTextDirection/useTextDirection.mjs.map +1 -1
- package/dist/esm/hooks/useTextSelection/useTextSelection.mjs +7 -7
- package/dist/esm/hooks/useTextSelection/useTextSelection.mjs.map +1 -1
- package/dist/esm/hooks/useThrottleCallback/useThrottleCallback.mjs.map +1 -1
- 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 +51 -54
- 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 +38 -38
- package/dist/esm/hooks/useUrlSearchParam/useUrlSearchParam.mjs.map +1 -1
- package/dist/esm/hooks/useUrlSearchParams/useUrlSearchParams.mjs +29 -29
- package/dist/esm/hooks/useUrlSearchParams/useUrlSearchParams.mjs.map +1 -1
- package/dist/esm/hooks/useVibrate/useVibrate.mjs.map +1 -1
- package/dist/esm/hooks/useWakeLock/useWakeLock.mjs +16 -16
- package/dist/esm/hooks/useWakeLock/useWakeLock.mjs.map +1 -1
- package/dist/esm/hooks/useWebSocket/useWebSocket.mjs +28 -38
- 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 +9 -9
- package/dist/esm/hooks/useWindowSize/useWindowSize.mjs.map +1 -1
- package/dist/esm/hooks/useWizard/useWizard.mjs +9 -11
- package/dist/esm/hooks/useWizard/useWizard.mjs.map +1 -1
- package/dist/esm/utils/helpers/copy.mjs.map +1 -1
- package/dist/esm/utils/helpers/debounce.mjs.map +1 -1
- package/dist/esm/utils/helpers/getDate.mjs.map +1 -1
- package/dist/esm/utils/helpers/getElement.mjs.map +1 -1
- package/dist/esm/utils/helpers/getRetry.mjs.map +1 -1
- package/dist/esm/utils/helpers/isTarget.mjs.map +1 -1
- package/dist/esm/utils/helpers/throttle.mjs.map +1 -1
- package/dist/types/hooks/useLatest/useLatest.d.ts +7 -2
- package/package.json +5 -5
|
@@ -1,56 +1,50 @@
|
|
|
1
|
-
import { useState as
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
e.lang =
|
|
5
|
-
|
|
1
|
+
import { useState as o, useRef as b, useEffect as x } from "react";
|
|
2
|
+
const j = (d = {}) => {
|
|
3
|
+
const t = typeof window < "u" && "speechSynthesis" in window, { text: u = "", lang: i = "en-US", pitch: c = 1, rate: a = 1, voice: p = null, volume: l = 1 } = d, [w, n] = o(!1), [h, r] = o("init"), [S, y] = o(), s = b(null), f = (e) => {
|
|
4
|
+
e.lang = i, e.pitch = c, e.rate = a, e.volume = l, e.voice = p, e.onstart = () => {
|
|
5
|
+
n(!0), r("play");
|
|
6
6
|
}, e.onpause = () => {
|
|
7
|
-
|
|
7
|
+
n(!1), r("pause");
|
|
8
8
|
}, e.onresume = () => {
|
|
9
|
-
|
|
9
|
+
n(!0), r("play");
|
|
10
10
|
}, e.onend = () => {
|
|
11
|
-
|
|
12
|
-
}, e.onerror = (
|
|
13
|
-
|
|
11
|
+
n(!1), r("end");
|
|
12
|
+
}, e.onerror = (R) => {
|
|
13
|
+
n(!1), y(R);
|
|
14
14
|
};
|
|
15
15
|
};
|
|
16
|
-
|
|
17
|
-
if (!
|
|
18
|
-
const e = new SpeechSynthesisUtterance(
|
|
19
|
-
return
|
|
20
|
-
|
|
21
|
-
(n = window.speechSynthesis) == null || n.cancel();
|
|
16
|
+
x(() => {
|
|
17
|
+
if (!t) return;
|
|
18
|
+
const e = new SpeechSynthesisUtterance(u);
|
|
19
|
+
return f(e), s.current = e, () => {
|
|
20
|
+
window.speechSynthesis?.cancel();
|
|
22
21
|
};
|
|
23
|
-
}, [c, a, p, l
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
}, [u, i, c, a, p, l]);
|
|
23
|
+
const m = (e) => {
|
|
24
|
+
t && (e && (s.current = new SpeechSynthesisUtterance(e), f(s.current)), window.speechSynthesis?.cancel(), s.current && window.speechSynthesis?.speak(s.current));
|
|
25
|
+
}, g = () => {
|
|
26
|
+
t && (window.speechSynthesis?.cancel(), n(!1));
|
|
27
|
+
}, v = (e = !w) => {
|
|
28
|
+
t && (e ? window.speechSynthesis?.resume() : window.speechSynthesis?.pause(), n(e));
|
|
27
29
|
}, k = () => {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
var n, o;
|
|
32
|
-
r && (e ? (n = window.speechSynthesis) == null || n.resume() : (o = window.speechSynthesis) == null || o.pause(), s(e));
|
|
33
|
-
}, R = () => {
|
|
34
|
-
var e;
|
|
35
|
-
s(!0), (e = window.speechSynthesis) == null || e.resume();
|
|
36
|
-
}, b = () => {
|
|
37
|
-
var e;
|
|
38
|
-
s(!1), (e = window.speechSynthesis) == null || e.pause();
|
|
30
|
+
n(!0), window.speechSynthesis?.resume();
|
|
31
|
+
}, E = () => {
|
|
32
|
+
n(!1), window.speechSynthesis?.pause();
|
|
39
33
|
};
|
|
40
34
|
return {
|
|
41
|
-
supported:
|
|
42
|
-
playing:
|
|
43
|
-
status:
|
|
44
|
-
utterance:
|
|
45
|
-
error:
|
|
46
|
-
stop:
|
|
47
|
-
toggle:
|
|
48
|
-
speak:
|
|
49
|
-
resume:
|
|
50
|
-
pause:
|
|
35
|
+
supported: t,
|
|
36
|
+
playing: w,
|
|
37
|
+
status: h,
|
|
38
|
+
utterance: s.current,
|
|
39
|
+
error: S,
|
|
40
|
+
stop: g,
|
|
41
|
+
toggle: v,
|
|
42
|
+
speak: m,
|
|
43
|
+
resume: k,
|
|
44
|
+
pause: E
|
|
51
45
|
};
|
|
52
46
|
};
|
|
53
47
|
export {
|
|
54
|
-
|
|
48
|
+
j as useSpeechSynthesis
|
|
55
49
|
};
|
|
56
50
|
//# sourceMappingURL=useSpeechSynthesis.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSpeechSynthesis.mjs","sources":["../../../../src/hooks/useSpeechSynthesis/useSpeechSynthesis.ts"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\n\n/** The use speech synthesis status type */\nexport type UseSpeechSynthesisStatus = 'end' | 'init' | 'pause' | 'play';\n\n/** The use speech synthesis options type */\nexport interface UseSpeechSynthesisOptions {\n /** Language for SpeechSynthesis */\n lang?: string;\n /** Gets and sets the pitch at which the utterance will be spoken at. */\n pitch?: number;\n /** Gets and sets the speed at which the utterance will be spoken at. */\n rate?: number;\n /** The text to be spoken */\n text?: string;\n /** Gets and sets the voice that will be used to speak the utterance. */\n voice?: SpeechSynthesisVoice | null;\n /** Gets and sets the volume that the utterance will be spoken at. */\n volume?: number;\n}\n\n/** The use speech synthesis return type */\nexport interface UseSpeechSynthesisReturn {\n /** Any error that occurred during speech synthesis. */\n error: SpeechSynthesisErrorEvent | undefined;\n /** Indicates if speech is currently playing. */\n playing: boolean;\n /** The current status of speech synthesis. */\n status: UseSpeechSynthesisStatus;\n /** Indicates if the SpeechSynthesis API is supported in the current environment. */\n supported: boolean;\n /** The SpeechSynthesisUtterance instance. */\n utterance: SpeechSynthesisUtterance | null;\n /** Function to pause speech synthesis. */\n pause: () => void;\n /** Function to resume speech synthesis. */\n resume: () => void;\n /** Function to start speech synthesis. */\n speak: () => void;\n /** Function to stop speech synthesis. */\n stop: () => void;\n /** Function to toggle between play and pause. */\n toggle: (value?: boolean) => void;\n}\n\n/**\n * @name useSpeechSynthesis\n * @description - Hook that provides speech synthesis functionality\n * @category Sensors\n *\n * @browserapi SpeechSynthesis https://developer.mozilla.org/en-US/docs/Web/API/SpeechSynthesis\n *\n * @params {string} [options.text] - The text to be spoken\n * @params {string} [options.lang] - The language to be spoken\n * @params {number} [options.pitch] - The pitch to be spoken\n * @params {number} [options.rate] - The rate to be spoken\n * @params {SpeechSynthesisVoice} [options.voice] - The voice to be spoken\n * @params {number} [options.volume] - The volume to be spoken\n * @returns {UseSpeechSynthesisReturn} An object containing the speech synthesis state and control methods\n *\n * @example\n * const { supported, playing, status, utterance, error, stop, toggle, speak, resume, pause } = useSpeechSynthesis();\n */\nexport const useSpeechSynthesis = (\n options: UseSpeechSynthesisOptions = {}\n): UseSpeechSynthesisReturn => {\n const supported = typeof window !== 'undefined' && 'speechSynthesis' in window;\n\n const { text = '', lang = 'en-US', pitch = 1, rate = 1, voice = null, volume = 1 } = options;\n\n const [playing, setPlaying] = useState(false);\n const [status, setStatus] = useState<UseSpeechSynthesisStatus>('init');\n const [error, setError] = useState<SpeechSynthesisErrorEvent>();\n const speechSynthesisUtteranceRef = useRef<SpeechSynthesisUtterance | null>(null);\n\n const bindSpeechSynthesisUtterance = (speechSynthesisUtterance: SpeechSynthesisUtterance) => {\n speechSynthesisUtterance.lang = lang;\n speechSynthesisUtterance.pitch = pitch;\n speechSynthesisUtterance.rate = rate;\n speechSynthesisUtterance.volume = volume;\n speechSynthesisUtterance.voice = voice;\n\n speechSynthesisUtterance.onstart = () => {\n setPlaying(true);\n setStatus('play');\n };\n\n speechSynthesisUtterance.onpause = () => {\n setPlaying(false);\n setStatus('pause');\n };\n\n speechSynthesisUtterance.onresume = () => {\n setPlaying(true);\n setStatus('play');\n };\n\n speechSynthesisUtterance.onend = () => {\n setPlaying(false);\n setStatus('end');\n };\n\n speechSynthesisUtterance.onerror = (event) => {\n setPlaying(false);\n setError(event);\n };\n };\n\n useEffect(() => {\n if (!supported) return;\n\n const speechSynthesisUtterance = new SpeechSynthesisUtterance(text);\n bindSpeechSynthesisUtterance(speechSynthesisUtterance);\n speechSynthesisUtteranceRef.current = speechSynthesisUtterance;\n\n return () => {\n window.speechSynthesis?.cancel();\n };\n }, [text, lang, pitch, rate, voice, volume]);\n\n const speak = (text?: string) => {\n if (!supported) return;\n\n if (text) {\n speechSynthesisUtteranceRef.current = new SpeechSynthesisUtterance(text);\n bindSpeechSynthesisUtterance(speechSynthesisUtteranceRef.current);\n }\n\n window.speechSynthesis?.cancel();\n if (speechSynthesisUtteranceRef.current)\n window.speechSynthesis?.speak(speechSynthesisUtteranceRef.current);\n };\n\n const stop = () => {\n if (!supported) return;\n\n window.speechSynthesis?.cancel();\n setPlaying(false);\n };\n\n const toggle = (value = !playing) => {\n if (!supported) return;\n\n if (value) {\n window.speechSynthesis?.resume();\n } else {\n window.speechSynthesis?.pause();\n }\n setPlaying(value);\n };\n\n const resume = () => {\n setPlaying(true);\n window.speechSynthesis?.resume();\n };\n\n const pause = () => {\n setPlaying(false);\n window.speechSynthesis?.pause();\n };\n\n return {\n supported,\n playing,\n status,\n utterance: speechSynthesisUtteranceRef.current,\n error,\n\n stop,\n toggle,\n speak,\n resume,\n pause\n };\n};\n"],"names":["useSpeechSynthesis","options","supported","text","lang","pitch","rate","voice","volume","playing","setPlaying","useState","status","setStatus","error","setError","speechSynthesisUtteranceRef","useRef","bindSpeechSynthesisUtterance","speechSynthesisUtterance","event","useEffect","
|
|
1
|
+
{"version":3,"file":"useSpeechSynthesis.mjs","sources":["../../../../src/hooks/useSpeechSynthesis/useSpeechSynthesis.ts"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\n\n/** The use speech synthesis status type */\nexport type UseSpeechSynthesisStatus = 'end' | 'init' | 'pause' | 'play';\n\n/** The use speech synthesis options type */\nexport interface UseSpeechSynthesisOptions {\n /** Language for SpeechSynthesis */\n lang?: string;\n /** Gets and sets the pitch at which the utterance will be spoken at. */\n pitch?: number;\n /** Gets and sets the speed at which the utterance will be spoken at. */\n rate?: number;\n /** The text to be spoken */\n text?: string;\n /** Gets and sets the voice that will be used to speak the utterance. */\n voice?: SpeechSynthesisVoice | null;\n /** Gets and sets the volume that the utterance will be spoken at. */\n volume?: number;\n}\n\n/** The use speech synthesis return type */\nexport interface UseSpeechSynthesisReturn {\n /** Any error that occurred during speech synthesis. */\n error: SpeechSynthesisErrorEvent | undefined;\n /** Indicates if speech is currently playing. */\n playing: boolean;\n /** The current status of speech synthesis. */\n status: UseSpeechSynthesisStatus;\n /** Indicates if the SpeechSynthesis API is supported in the current environment. */\n supported: boolean;\n /** The SpeechSynthesisUtterance instance. */\n utterance: SpeechSynthesisUtterance | null;\n /** Function to pause speech synthesis. */\n pause: () => void;\n /** Function to resume speech synthesis. */\n resume: () => void;\n /** Function to start speech synthesis. */\n speak: () => void;\n /** Function to stop speech synthesis. */\n stop: () => void;\n /** Function to toggle between play and pause. */\n toggle: (value?: boolean) => void;\n}\n\n/**\n * @name useSpeechSynthesis\n * @description - Hook that provides speech synthesis functionality\n * @category Sensors\n *\n * @browserapi SpeechSynthesis https://developer.mozilla.org/en-US/docs/Web/API/SpeechSynthesis\n *\n * @params {string} [options.text] - The text to be spoken\n * @params {string} [options.lang] - The language to be spoken\n * @params {number} [options.pitch] - The pitch to be spoken\n * @params {number} [options.rate] - The rate to be spoken\n * @params {SpeechSynthesisVoice} [options.voice] - The voice to be spoken\n * @params {number} [options.volume] - The volume to be spoken\n * @returns {UseSpeechSynthesisReturn} An object containing the speech synthesis state and control methods\n *\n * @example\n * const { supported, playing, status, utterance, error, stop, toggle, speak, resume, pause } = useSpeechSynthesis();\n */\nexport const useSpeechSynthesis = (\n options: UseSpeechSynthesisOptions = {}\n): UseSpeechSynthesisReturn => {\n const supported = typeof window !== 'undefined' && 'speechSynthesis' in window;\n\n const { text = '', lang = 'en-US', pitch = 1, rate = 1, voice = null, volume = 1 } = options;\n\n const [playing, setPlaying] = useState(false);\n const [status, setStatus] = useState<UseSpeechSynthesisStatus>('init');\n const [error, setError] = useState<SpeechSynthesisErrorEvent>();\n const speechSynthesisUtteranceRef = useRef<SpeechSynthesisUtterance | null>(null);\n\n const bindSpeechSynthesisUtterance = (speechSynthesisUtterance: SpeechSynthesisUtterance) => {\n speechSynthesisUtterance.lang = lang;\n speechSynthesisUtterance.pitch = pitch;\n speechSynthesisUtterance.rate = rate;\n speechSynthesisUtterance.volume = volume;\n speechSynthesisUtterance.voice = voice;\n\n speechSynthesisUtterance.onstart = () => {\n setPlaying(true);\n setStatus('play');\n };\n\n speechSynthesisUtterance.onpause = () => {\n setPlaying(false);\n setStatus('pause');\n };\n\n speechSynthesisUtterance.onresume = () => {\n setPlaying(true);\n setStatus('play');\n };\n\n speechSynthesisUtterance.onend = () => {\n setPlaying(false);\n setStatus('end');\n };\n\n speechSynthesisUtterance.onerror = (event) => {\n setPlaying(false);\n setError(event);\n };\n };\n\n useEffect(() => {\n if (!supported) return;\n\n const speechSynthesisUtterance = new SpeechSynthesisUtterance(text);\n bindSpeechSynthesisUtterance(speechSynthesisUtterance);\n speechSynthesisUtteranceRef.current = speechSynthesisUtterance;\n\n return () => {\n window.speechSynthesis?.cancel();\n };\n }, [text, lang, pitch, rate, voice, volume]);\n\n const speak = (text?: string) => {\n if (!supported) return;\n\n if (text) {\n speechSynthesisUtteranceRef.current = new SpeechSynthesisUtterance(text);\n bindSpeechSynthesisUtterance(speechSynthesisUtteranceRef.current);\n }\n\n window.speechSynthesis?.cancel();\n if (speechSynthesisUtteranceRef.current)\n window.speechSynthesis?.speak(speechSynthesisUtteranceRef.current);\n };\n\n const stop = () => {\n if (!supported) return;\n\n window.speechSynthesis?.cancel();\n setPlaying(false);\n };\n\n const toggle = (value = !playing) => {\n if (!supported) return;\n\n if (value) {\n window.speechSynthesis?.resume();\n } else {\n window.speechSynthesis?.pause();\n }\n setPlaying(value);\n };\n\n const resume = () => {\n setPlaying(true);\n window.speechSynthesis?.resume();\n };\n\n const pause = () => {\n setPlaying(false);\n window.speechSynthesis?.pause();\n };\n\n return {\n supported,\n playing,\n status,\n utterance: speechSynthesisUtteranceRef.current,\n error,\n\n stop,\n toggle,\n speak,\n resume,\n pause\n };\n};\n"],"names":["useSpeechSynthesis","options","supported","text","lang","pitch","rate","voice","volume","playing","setPlaying","useState","status","setStatus","error","setError","speechSynthesisUtteranceRef","useRef","bindSpeechSynthesisUtterance","speechSynthesisUtterance","event","useEffect","speak","stop","toggle","value","resume","pause"],"mappings":";AA+DO,MAAMA,IAAqB,CAChCC,IAAqC,OACR;AAC7B,QAAMC,IAAY,OAAO,SAAW,OAAe,qBAAqB,QAElE,EAAE,MAAAC,IAAO,IAAI,MAAAC,IAAO,SAAS,OAAAC,IAAQ,GAAG,MAAAC,IAAO,GAAG,OAAAC,IAAQ,MAAM,QAAAC,IAAS,MAAMP,GAE/E,CAACQ,GAASC,CAAU,IAAIC,EAAS,EAAK,GACtC,CAACC,GAAQC,CAAS,IAAIF,EAAmC,MAAM,GAC/D,CAACG,GAAOC,CAAQ,IAAIJ,EAAA,GACpBK,IAA8BC,EAAwC,IAAI,GAE1EC,IAA+B,CAACC,MAAuD;AAC3F,IAAAA,EAAyB,OAAOf,GAChCe,EAAyB,QAAQd,GACjCc,EAAyB,OAAOb,GAChCa,EAAyB,SAASX,GAClCW,EAAyB,QAAQZ,GAEjCY,EAAyB,UAAU,MAAM;AACvC,MAAAT,EAAW,EAAI,GACfG,EAAU,MAAM;AAAA,IAAA,GAGlBM,EAAyB,UAAU,MAAM;AACvC,MAAAT,EAAW,EAAK,GAChBG,EAAU,OAAO;AAAA,IAAA,GAGnBM,EAAyB,WAAW,MAAM;AACxC,MAAAT,EAAW,EAAI,GACfG,EAAU,MAAM;AAAA,IAAA,GAGlBM,EAAyB,QAAQ,MAAM;AACrC,MAAAT,EAAW,EAAK,GAChBG,EAAU,KAAK;AAAA,IAAA,GAGjBM,EAAyB,UAAU,CAACC,MAAU;AAC5C,MAAAV,EAAW,EAAK,GAChBK,EAASK,CAAK;AAAA,IAAA;AAAA,EAChB;AAGF,EAAAC,EAAU,MAAM;AACd,QAAI,CAACnB,EAAW;AAEhB,UAAMiB,IAA2B,IAAI,yBAAyBhB,CAAI;AAClE,WAAAe,EAA6BC,CAAwB,GACrDH,EAA4B,UAAUG,GAE/B,MAAM;AACX,aAAO,iBAAiB,OAAA;AAAA,IAAO;AAAA,EACjC,GACC,CAAChB,GAAMC,GAAMC,GAAOC,GAAMC,GAAOC,CAAM,CAAC;AAE3C,QAAMc,IAAQ,CAACnB,MAAkB;AAC/B,IAAKD,MAEDC,MACFa,EAA4B,UAAU,IAAI,yBAAyBb,CAAI,GACvEe,EAA6BF,EAA4B,OAAO,IAGlE,OAAO,iBAAiB,OAAA,GACpBA,EAA4B,WAC9B,OAAO,iBAAiB,MAAMA,EAA4B,OAAO;AAAA,EAAA,GAG/DO,IAAO,MAAM;AACjB,IAAKrB,MAEL,OAAO,iBAAiB,OAAA,GACxBQ,EAAW,EAAK;AAAA,EAAA,GAGZc,IAAS,CAACC,IAAQ,CAAChB,MAAY;AACnC,IAAKP,MAEDuB,IACF,OAAO,iBAAiB,OAAA,IAExB,OAAO,iBAAiB,MAAA,GAE1Bf,EAAWe,CAAK;AAAA,EAAA,GAGZC,IAAS,MAAM;AACnB,IAAAhB,EAAW,EAAI,GACf,OAAO,iBAAiB,OAAA;AAAA,EAAO,GAG3BiB,IAAQ,MAAM;AAClB,IAAAjB,EAAW,EAAK,GAChB,OAAO,iBAAiB,MAAA;AAAA,EAAM;AAGhC,SAAO;AAAA,IACL,WAAAR;AAAA,IACA,SAAAO;AAAA,IACA,QAAAG;AAAA,IACA,WAAWI,EAA4B;AAAA,IACvC,OAAAF;AAAA,IAEA,MAAAS;AAAA,IACA,QAAAC;AAAA,IACA,OAAAF;AAAA,IACA,QAAAI;AAAA,IACA,OAAAC;AAAA,EAAA;AAEJ;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useStateHistory.mjs","sources":["../../../../src/hooks/useStateHistory/useStateHistory.ts"],"sourcesContent":["import { useReducer } from 'react';\n\n/** The use state history hook return type */\ninterface UseStateHistoryReturn<Value> {\n /** True if a redo operation can be performed */\n canRedo: boolean;\n /** True if an undo operation can be performed */\n canUndo: boolean;\n /** All history values */\n history: Value[];\n /** Current index in history */\n index: number;\n /** Current value */\n value: Value;\n /** Go back specified number of steps in history (default: 1) */\n back: (steps?: number) => void;\n /** Go forward specified number of steps in history (default: 1) */\n forward: (steps?: number) => void;\n /** Redo the last change */\n redo: () => void;\n /** Reset history to initial state */\n reset: () => void;\n /** Set a new value */\n set: (value: Value) => void;\n /** Undo the last change */\n undo: () => void;\n}\n\nexport type StateHistoryAction<Value> =\n | { type: 'BACK'; payload: { steps: number } }\n | { type: 'FORWARD'; payload: { steps: number } }\n | { type: 'REDO' }\n | { type: 'RESET'; payload: { initialValue: Value; capacity: number } }\n | { type: 'SET'; payload: { value: Value; capacity: number } }\n | { type: 'UNDO' };\n\nexport interface StateHistory<Value> {\n currentIndex: number;\n history: Value[];\n redoStack: Value[][];\n undoStack: Value[][];\n}\n\nexport const stateHistoryReducer = <Value>(\n state: StateHistory<Value>,\n action: StateHistoryAction<Value>\n): StateHistory<Value> => {\n switch (action.type) {\n case 'SET': {\n const { value, capacity } = action.payload;\n\n const newHistory = [...state.history.slice(0, state.currentIndex + 1), value];\n if (newHistory.length > capacity) {\n newHistory.shift();\n }\n\n const newUndoStack = [state.history, ...state.undoStack];\n if (newUndoStack.length > capacity) {\n newUndoStack.pop();\n }\n\n return {\n history: newHistory,\n currentIndex: newHistory.length - 1,\n undoStack: newUndoStack,\n redoStack: []\n };\n }\n\n case 'UNDO': {\n if (state.undoStack.length === 0) return state;\n\n return {\n history: state.undoStack[0],\n currentIndex: state.undoStack[0].length - 1,\n undoStack: state.undoStack.slice(1),\n redoStack: [state.history, ...state.redoStack]\n };\n }\n\n case 'REDO': {\n if (state.redoStack.length === 0) return state;\n\n return {\n history: state.redoStack[0],\n currentIndex: state.redoStack[0].length - 1,\n undoStack: [state.history, ...state.undoStack],\n redoStack: state.redoStack.slice(1)\n };\n }\n\n case 'BACK': {\n const { steps } = action.payload;\n return {\n ...state,\n currentIndex: Math.max(0, state.currentIndex - steps)\n };\n }\n\n case 'FORWARD': {\n const { steps } = action.payload;\n return {\n ...state,\n currentIndex: Math.min(state.currentIndex + steps, state.history.length - 1)\n };\n }\n\n case 'RESET': {\n const { initialValue, capacity } = action.payload;\n if (state.history.length === 1) return state;\n\n const newUndoStack = [state.history, ...state.undoStack];\n if (newUndoStack.length > capacity) {\n newUndoStack.pop();\n }\n\n return {\n history: [initialValue],\n currentIndex: 0,\n undoStack: newUndoStack,\n redoStack: []\n };\n }\n\n default:\n throw new Error('Unsupported action type');\n }\n};\n\n/**\n * @name useStateHistory\n * @description - Hook that manages state with history functionality\n * @category Utilities\n *\n * @param {Value} initialValue - The initial value to start the history with\n * @param {number} [capacity=10] - Maximum number of history entries and undo actions to keep\n * @returns {UseStateHistoryReturn<Value>} Object containing current value, history array and control methods\n *\n * @example\n * const { value, history, index, set, back, forward, reset, undo, redo, canUndo, canRedo } = useStateHistory(0);\n */\nexport const useStateHistory = <Value>(\n initialValue: Value,\n capacity = 10\n): UseStateHistoryReturn<Value> => {\n const [state, dispatch] = useReducer(stateHistoryReducer<Value>, {\n history: [initialValue],\n currentIndex: 0,\n undoStack: [],\n redoStack: []\n });\n\n const value = state.history[state.currentIndex];\n const canUndo = state.undoStack.length > 0;\n const canRedo = state.redoStack.length > 0;\n\n const set = (value: Value) =>\n dispatch({\n type: 'SET',\n payload: { value, capacity }\n });\n\n const undo = () => dispatch({ type: 'UNDO' });\n\n const redo = () => dispatch({ type: 'REDO' });\n\n const back = (steps = 1) => dispatch({ type: 'BACK', payload: { steps } });\n\n const forward = (steps = 1) => dispatch({ type: 'FORWARD', payload: { steps } });\n\n const reset = () => dispatch({ type: 'RESET', payload: { initialValue, capacity } });\n\n return {\n history: state.history,\n value,\n set,\n index: state.currentIndex,\n back,\n forward,\n reset,\n undo,\n redo,\n canUndo,\n canRedo\n };\n};\n"],"names":["stateHistoryReducer","state","action","value","capacity","newHistory","newUndoStack","steps","initialValue","useStateHistory","dispatch","useReducer","canUndo","canRedo","set","undo","redo","back","forward","reset"],"mappings":";
|
|
1
|
+
{"version":3,"file":"useStateHistory.mjs","sources":["../../../../src/hooks/useStateHistory/useStateHistory.ts"],"sourcesContent":["import { useReducer } from 'react';\n\n/** The use state history hook return type */\ninterface UseStateHistoryReturn<Value> {\n /** True if a redo operation can be performed */\n canRedo: boolean;\n /** True if an undo operation can be performed */\n canUndo: boolean;\n /** All history values */\n history: Value[];\n /** Current index in history */\n index: number;\n /** Current value */\n value: Value;\n /** Go back specified number of steps in history (default: 1) */\n back: (steps?: number) => void;\n /** Go forward specified number of steps in history (default: 1) */\n forward: (steps?: number) => void;\n /** Redo the last change */\n redo: () => void;\n /** Reset history to initial state */\n reset: () => void;\n /** Set a new value */\n set: (value: Value) => void;\n /** Undo the last change */\n undo: () => void;\n}\n\nexport type StateHistoryAction<Value> =\n | { type: 'BACK'; payload: { steps: number } }\n | { type: 'FORWARD'; payload: { steps: number } }\n | { type: 'REDO' }\n | { type: 'RESET'; payload: { initialValue: Value; capacity: number } }\n | { type: 'SET'; payload: { value: Value; capacity: number } }\n | { type: 'UNDO' };\n\nexport interface StateHistory<Value> {\n currentIndex: number;\n history: Value[];\n redoStack: Value[][];\n undoStack: Value[][];\n}\n\nexport const stateHistoryReducer = <Value>(\n state: StateHistory<Value>,\n action: StateHistoryAction<Value>\n): StateHistory<Value> => {\n switch (action.type) {\n case 'SET': {\n const { value, capacity } = action.payload;\n\n const newHistory = [...state.history.slice(0, state.currentIndex + 1), value];\n if (newHistory.length > capacity) {\n newHistory.shift();\n }\n\n const newUndoStack = [state.history, ...state.undoStack];\n if (newUndoStack.length > capacity) {\n newUndoStack.pop();\n }\n\n return {\n history: newHistory,\n currentIndex: newHistory.length - 1,\n undoStack: newUndoStack,\n redoStack: []\n };\n }\n\n case 'UNDO': {\n if (state.undoStack.length === 0) return state;\n\n return {\n history: state.undoStack[0],\n currentIndex: state.undoStack[0].length - 1,\n undoStack: state.undoStack.slice(1),\n redoStack: [state.history, ...state.redoStack]\n };\n }\n\n case 'REDO': {\n if (state.redoStack.length === 0) return state;\n\n return {\n history: state.redoStack[0],\n currentIndex: state.redoStack[0].length - 1,\n undoStack: [state.history, ...state.undoStack],\n redoStack: state.redoStack.slice(1)\n };\n }\n\n case 'BACK': {\n const { steps } = action.payload;\n return {\n ...state,\n currentIndex: Math.max(0, state.currentIndex - steps)\n };\n }\n\n case 'FORWARD': {\n const { steps } = action.payload;\n return {\n ...state,\n currentIndex: Math.min(state.currentIndex + steps, state.history.length - 1)\n };\n }\n\n case 'RESET': {\n const { initialValue, capacity } = action.payload;\n if (state.history.length === 1) return state;\n\n const newUndoStack = [state.history, ...state.undoStack];\n if (newUndoStack.length > capacity) {\n newUndoStack.pop();\n }\n\n return {\n history: [initialValue],\n currentIndex: 0,\n undoStack: newUndoStack,\n redoStack: []\n };\n }\n\n default:\n throw new Error('Unsupported action type');\n }\n};\n\n/**\n * @name useStateHistory\n * @description - Hook that manages state with history functionality\n * @category Utilities\n *\n * @param {Value} initialValue - The initial value to start the history with\n * @param {number} [capacity=10] - Maximum number of history entries and undo actions to keep\n * @returns {UseStateHistoryReturn<Value>} Object containing current value, history array and control methods\n *\n * @example\n * const { value, history, index, set, back, forward, reset, undo, redo, canUndo, canRedo } = useStateHistory(0);\n */\nexport const useStateHistory = <Value>(\n initialValue: Value,\n capacity = 10\n): UseStateHistoryReturn<Value> => {\n const [state, dispatch] = useReducer(stateHistoryReducer<Value>, {\n history: [initialValue],\n currentIndex: 0,\n undoStack: [],\n redoStack: []\n });\n\n const value = state.history[state.currentIndex];\n const canUndo = state.undoStack.length > 0;\n const canRedo = state.redoStack.length > 0;\n\n const set = (value: Value) =>\n dispatch({\n type: 'SET',\n payload: { value, capacity }\n });\n\n const undo = () => dispatch({ type: 'UNDO' });\n\n const redo = () => dispatch({ type: 'REDO' });\n\n const back = (steps = 1) => dispatch({ type: 'BACK', payload: { steps } });\n\n const forward = (steps = 1) => dispatch({ type: 'FORWARD', payload: { steps } });\n\n const reset = () => dispatch({ type: 'RESET', payload: { initialValue, capacity } });\n\n return {\n history: state.history,\n value,\n set,\n index: state.currentIndex,\n back,\n forward,\n reset,\n undo,\n redo,\n canUndo,\n canRedo\n };\n};\n"],"names":["stateHistoryReducer","state","action","value","capacity","newHistory","newUndoStack","steps","initialValue","useStateHistory","dispatch","useReducer","canUndo","canRedo","set","undo","redo","back","forward","reset"],"mappings":";AA2CO,MAAMA,IAAsB,CACjCC,GACAC,MACwB;AACxB,UAAQA,EAAO,MAAA;AAAA,IACb,KAAK,OAAO;AACV,YAAM,EAAE,OAAAC,GAAO,UAAAC,EAAA,IAAaF,EAAO,SAE7BG,IAAa,CAAC,GAAGJ,EAAM,QAAQ,MAAM,GAAGA,EAAM,eAAe,CAAC,GAAGE,CAAK;AAC5E,MAAIE,EAAW,SAASD,KACtBC,EAAW,MAAA;AAGb,YAAMC,IAAe,CAACL,EAAM,SAAS,GAAGA,EAAM,SAAS;AACvD,aAAIK,EAAa,SAASF,KACxBE,EAAa,IAAA,GAGR;AAAA,QACL,SAASD;AAAA,QACT,cAAcA,EAAW,SAAS;AAAA,QAClC,WAAWC;AAAA,QACX,WAAW,CAAA;AAAA,MAAC;AAAA,IACd;AAAA,IAGF,KAAK;AACH,aAAIL,EAAM,UAAU,WAAW,IAAUA,IAElC;AAAA,QACL,SAASA,EAAM,UAAU,CAAC;AAAA,QAC1B,cAAcA,EAAM,UAAU,CAAC,EAAE,SAAS;AAAA,QAC1C,WAAWA,EAAM,UAAU,MAAM,CAAC;AAAA,QAClC,WAAW,CAACA,EAAM,SAAS,GAAGA,EAAM,SAAS;AAAA,MAAA;AAAA,IAIjD,KAAK;AACH,aAAIA,EAAM,UAAU,WAAW,IAAUA,IAElC;AAAA,QACL,SAASA,EAAM,UAAU,CAAC;AAAA,QAC1B,cAAcA,EAAM,UAAU,CAAC,EAAE,SAAS;AAAA,QAC1C,WAAW,CAACA,EAAM,SAAS,GAAGA,EAAM,SAAS;AAAA,QAC7C,WAAWA,EAAM,UAAU,MAAM,CAAC;AAAA,MAAA;AAAA,IAItC,KAAK,QAAQ;AACX,YAAM,EAAE,OAAAM,MAAUL,EAAO;AACzB,aAAO;AAAA,QACL,GAAGD;AAAA,QACH,cAAc,KAAK,IAAI,GAAGA,EAAM,eAAeM,CAAK;AAAA,MAAA;AAAA,IACtD;AAAA,IAGF,KAAK,WAAW;AACd,YAAM,EAAE,OAAAA,MAAUL,EAAO;AACzB,aAAO;AAAA,QACL,GAAGD;AAAA,QACH,cAAc,KAAK,IAAIA,EAAM,eAAeM,GAAON,EAAM,QAAQ,SAAS,CAAC;AAAA,MAAA;AAAA,IAC7E;AAAA,IAGF,KAAK,SAAS;AACZ,YAAM,EAAE,cAAAO,GAAc,UAAAJ,EAAA,IAAaF,EAAO;AAC1C,UAAID,EAAM,QAAQ,WAAW,EAAG,QAAOA;AAEvC,YAAMK,IAAe,CAACL,EAAM,SAAS,GAAGA,EAAM,SAAS;AACvD,aAAIK,EAAa,SAASF,KACxBE,EAAa,IAAA,GAGR;AAAA,QACL,SAAS,CAACE,CAAY;AAAA,QACtB,cAAc;AAAA,QACd,WAAWF;AAAA,QACX,WAAW,CAAA;AAAA,MAAC;AAAA,IACd;AAAA,IAGF;AACE,YAAM,IAAI,MAAM,yBAAyB;AAAA,EAAA;AAE/C,GAcaG,IAAkB,CAC7BD,GACAJ,IAAW,OACsB;AACjC,QAAM,CAACH,GAAOS,CAAQ,IAAIC,EAAWX,GAA4B;AAAA,IAC/D,SAAS,CAACQ,CAAY;AAAA,IACtB,cAAc;AAAA,IACd,WAAW,CAAA;AAAA,IACX,WAAW,CAAA;AAAA,EAAC,CACb,GAEKL,IAAQF,EAAM,QAAQA,EAAM,YAAY,GACxCW,IAAUX,EAAM,UAAU,SAAS,GACnCY,IAAUZ,EAAM,UAAU,SAAS,GAEnCa,IAAM,CAACX,MACXO,EAAS;AAAA,IACP,MAAM;AAAA,IACN,SAAS,EAAE,OAAAP,GAAO,UAAAC,EAAA;AAAA,EAAS,CAC5B,GAEGW,IAAO,MAAML,EAAS,EAAE,MAAM,QAAQ,GAEtCM,IAAO,MAAMN,EAAS,EAAE,MAAM,QAAQ,GAEtCO,IAAO,CAACV,IAAQ,MAAMG,EAAS,EAAE,MAAM,QAAQ,SAAS,EAAE,OAAAH,EAAA,EAAM,CAAG,GAEnEW,IAAU,CAACX,IAAQ,MAAMG,EAAS,EAAE,MAAM,WAAW,SAAS,EAAE,OAAAH,EAAA,EAAM,CAAG,GAEzEY,IAAQ,MAAMT,EAAS,EAAE,MAAM,SAAS,SAAS,EAAE,cAAAF,GAAc,UAAAJ,EAAA,GAAY;AAEnF,SAAO;AAAA,IACL,SAASH,EAAM;AAAA,IACf,OAAAE;AAAA,IACA,KAAAW;AAAA,IACA,OAAOb,EAAM;AAAA,IACb,MAAAgB;AAAA,IACA,SAAAC;AAAA,IACA,OAAAC;AAAA,IACA,MAAAJ;AAAA,IACA,MAAAC;AAAA,IACA,SAAAJ;AAAA,IACA,SAAAC;AAAA,EAAA;AAEJ;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useStep.mjs","sources":["../../../../src/hooks/useStep/useStep.ts"],"sourcesContent":["import { useRef, useState } from 'react';\n\n/** The use step params type */\nexport interface UseStepParams {\n /** Initial value for step */\n initial: number;\n /** Maximum value for step */\n max: number;\n}\n\n/** The use step return type */\nexport interface UseStepReturn {\n /** Counts of steps */\n counts: number;\n /** Current value of step */\n currentStep: number;\n /** Boolean value if current step is first */\n isFirst: boolean;\n /** Boolean value if current step is last */\n isLast: boolean;\n /** Go to back step */\n back: () => void;\n /** Go to next step */\n next: () => void;\n /** Reset current step to initial value */\n reset: () => void;\n /** Go to custom step */\n set: (value: number | 'first' | 'last') => void;\n}\n\nconst FIRST_STEP_VALUE = 1;\n\n/**\n * @name useStep\n * @description - Hook that create stepper\n * @category Utilities\n *\n * @overload\n * @param {number} max Maximum number of steps\n * @returns {UseStepReturn} An object contains variables and functions to change the step\n *\n * @example\n * const stepper = useStep(5);\n *\n * @overload\n * @param {number} params.max Maximum number of steps\n * @param {number} params.initial Initial value for step\n * @returns {UseStepReturn} An object contains variables and functions to change the step\n *\n * @example\n * const stepper = useStep({ initial: 2, max: 5 });\n */\nexport const useStep = (params: number | UseStepParams): UseStepReturn => {\n const max = typeof params === 'object' ? params.max : params;\n const initial = typeof params === 'object' ? params.initial : FIRST_STEP_VALUE;\n\n const initialStep = useRef(\n initial > max || initial < FIRST_STEP_VALUE ? FIRST_STEP_VALUE : initial\n );\n const [currentStep, setCurrentStep] = useState(initial);\n\n const isFirst = currentStep === FIRST_STEP_VALUE;\n const isLast = currentStep === max;\n\n const next = () => {\n if (isLast) return;\n setCurrentStep((prevStep) => prevStep + 1);\n };\n\n const back = () => {\n if (isFirst) return;\n setCurrentStep((prevStep) => prevStep - 1);\n };\n\n const reset = () => setCurrentStep(initialStep.current);\n\n const set = (value: number | 'first' | 'last') => {\n if (value === 'first') return setCurrentStep(initialStep.current);\n if (value === 'last') return setCurrentStep(max);\n if (value >= max) return setCurrentStep(max);\n if (value <= FIRST_STEP_VALUE) return setCurrentStep(FIRST_STEP_VALUE);\n setCurrentStep(value);\n };\n\n return {\n counts: max,\n currentStep,\n isFirst,\n isLast,\n next,\n back,\n reset,\n set\n };\n};\n"],"names":["FIRST_STEP_VALUE","useStep","params","max","initial","initialStep","useRef","currentStep","setCurrentStep","useState","isFirst","isLast","prevStep","value"],"mappings":";AA8BA,MAAMA,IAAmB,GAsBZC,IAAU,CAACC,MAAkD;AACxE,QAAMC,IAAM,OAAOD,KAAW,WAAWA,EAAO,MAAMA,GAChDE,IAAU,OAAOF,KAAW,WAAWA,EAAO,UAAUF,GAExDK,IAAcC;AAAA,IAClBF,IAAUD,KAAOC,IAAUJ,IAAmBA,IAAmBI;AAAA,
|
|
1
|
+
{"version":3,"file":"useStep.mjs","sources":["../../../../src/hooks/useStep/useStep.ts"],"sourcesContent":["import { useRef, useState } from 'react';\n\n/** The use step params type */\nexport interface UseStepParams {\n /** Initial value for step */\n initial: number;\n /** Maximum value for step */\n max: number;\n}\n\n/** The use step return type */\nexport interface UseStepReturn {\n /** Counts of steps */\n counts: number;\n /** Current value of step */\n currentStep: number;\n /** Boolean value if current step is first */\n isFirst: boolean;\n /** Boolean value if current step is last */\n isLast: boolean;\n /** Go to back step */\n back: () => void;\n /** Go to next step */\n next: () => void;\n /** Reset current step to initial value */\n reset: () => void;\n /** Go to custom step */\n set: (value: number | 'first' | 'last') => void;\n}\n\nconst FIRST_STEP_VALUE = 1;\n\n/**\n * @name useStep\n * @description - Hook that create stepper\n * @category Utilities\n *\n * @overload\n * @param {number} max Maximum number of steps\n * @returns {UseStepReturn} An object contains variables and functions to change the step\n *\n * @example\n * const stepper = useStep(5);\n *\n * @overload\n * @param {number} params.max Maximum number of steps\n * @param {number} params.initial Initial value for step\n * @returns {UseStepReturn} An object contains variables and functions to change the step\n *\n * @example\n * const stepper = useStep({ initial: 2, max: 5 });\n */\nexport const useStep = (params: number | UseStepParams): UseStepReturn => {\n const max = typeof params === 'object' ? params.max : params;\n const initial = typeof params === 'object' ? params.initial : FIRST_STEP_VALUE;\n\n const initialStep = useRef(\n initial > max || initial < FIRST_STEP_VALUE ? FIRST_STEP_VALUE : initial\n );\n const [currentStep, setCurrentStep] = useState(initial);\n\n const isFirst = currentStep === FIRST_STEP_VALUE;\n const isLast = currentStep === max;\n\n const next = () => {\n if (isLast) return;\n setCurrentStep((prevStep) => prevStep + 1);\n };\n\n const back = () => {\n if (isFirst) return;\n setCurrentStep((prevStep) => prevStep - 1);\n };\n\n const reset = () => setCurrentStep(initialStep.current);\n\n const set = (value: number | 'first' | 'last') => {\n if (value === 'first') return setCurrentStep(initialStep.current);\n if (value === 'last') return setCurrentStep(max);\n if (value >= max) return setCurrentStep(max);\n if (value <= FIRST_STEP_VALUE) return setCurrentStep(FIRST_STEP_VALUE);\n setCurrentStep(value);\n };\n\n return {\n counts: max,\n currentStep,\n isFirst,\n isLast,\n next,\n back,\n reset,\n set\n };\n};\n"],"names":["FIRST_STEP_VALUE","useStep","params","max","initial","initialStep","useRef","currentStep","setCurrentStep","useState","isFirst","isLast","prevStep","value"],"mappings":";AA8BA,MAAMA,IAAmB,GAsBZC,IAAU,CAACC,MAAkD;AACxE,QAAMC,IAAM,OAAOD,KAAW,WAAWA,EAAO,MAAMA,GAChDE,IAAU,OAAOF,KAAW,WAAWA,EAAO,UAAUF,GAExDK,IAAcC;AAAA,IAClBF,IAAUD,KAAOC,IAAUJ,IAAmBA,IAAmBI;AAAA,EAAA,GAE7D,CAACG,GAAaC,CAAc,IAAIC,EAASL,CAAO,GAEhDM,IAAUH,MAAgBP,GAC1BW,IAASJ,MAAgBJ;AAsB/B,SAAO;AAAA,IACL,QAAQA;AAAA,IACR,aAAAI;AAAA,IACA,SAAAG;AAAA,IACA,QAAAC;AAAA,IACA,MAzBW,MAAM;AACjB,MAAIA,KACJH,EAAe,CAACI,MAAaA,IAAW,CAAC;AAAA,IAAA;AAAA,IAwBzC,MArBW,MAAM;AACjB,MAAIF,KACJF,EAAe,CAACI,MAAaA,IAAW,CAAC;AAAA,IAAA;AAAA,IAoBzC,OAjBY,MAAMJ,EAAeH,EAAY,OAAO;AAAA,IAkBpD,KAhBU,CAACQ,MAAqC;AAChD,UAAIA,MAAU,QAAS,QAAOL,EAAeH,EAAY,OAAO;AAEhE,UADIQ,MAAU,UACVA,KAASV,EAAK,QAAOK,EAAeL,CAAG;AAC3C,UAAIU,KAASb,EAAkB,QAAOQ,EAAeR,CAAgB;AACrE,MAAAQ,EAAeK,CAAK;AAAA,IAAA;AAAA,EAWpB;AAEJ;"}
|
|
@@ -1,32 +1,32 @@
|
|
|
1
1
|
import { useState as m, useEffect as v } from "react";
|
|
2
2
|
import { useRefState as L } from "../useRefState/useRefState.mjs";
|
|
3
|
-
import { isTarget as
|
|
3
|
+
import { isTarget as p } from "../../utils/helpers/isTarget.mjs";
|
|
4
4
|
import { getElement as d } from "../../utils/helpers/getElement.mjs";
|
|
5
|
-
const
|
|
6
|
-
const o =
|
|
5
|
+
const T = (...n) => {
|
|
6
|
+
const o = p(n[0]) ? n[0] : void 0, r = o ? n[1] : n[0], s = r?.axis ?? "vertical", i = L(), [f, u] = m(!1);
|
|
7
7
|
return v(() => {
|
|
8
8
|
if (!o && !i.state) return;
|
|
9
|
-
const
|
|
10
|
-
if (!
|
|
11
|
-
const t =
|
|
12
|
-
if (
|
|
9
|
+
const c = o ? d(o) : i.current;
|
|
10
|
+
if (!c) return;
|
|
11
|
+
const t = r?.root ? d(r.root) : document, a = c.getBoundingClientRect().top + t.scrollTop - t.getBoundingClientRect().top, g = c.getBoundingClientRect().left + t.scrollLeft - t.getBoundingClientRect().left, e = () => {
|
|
12
|
+
if (s === "vertical") {
|
|
13
13
|
const l = t.scrollTop;
|
|
14
14
|
u(l >= a);
|
|
15
15
|
}
|
|
16
|
-
if (
|
|
16
|
+
if (s === "horizontal") {
|
|
17
17
|
const l = t.scrollLeft;
|
|
18
18
|
u(l >= g);
|
|
19
19
|
}
|
|
20
20
|
};
|
|
21
|
-
return t.addEventListener("scroll",
|
|
22
|
-
t.removeEventListener("scroll",
|
|
21
|
+
return t.addEventListener("scroll", e), window.addEventListener("resize", e), window.addEventListener("orientationchange", e), e(), () => {
|
|
22
|
+
t.removeEventListener("scroll", e), window.removeEventListener("resize", e), window.removeEventListener("orientationchange", e);
|
|
23
23
|
};
|
|
24
|
-
}, [o, i.state,
|
|
24
|
+
}, [o, i.state, s, r?.root]), o ? f : {
|
|
25
25
|
stuck: f,
|
|
26
26
|
ref: i
|
|
27
27
|
};
|
|
28
28
|
};
|
|
29
29
|
export {
|
|
30
|
-
|
|
30
|
+
T as useSticky
|
|
31
31
|
};
|
|
32
32
|
//# sourceMappingURL=useSticky.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSticky.mjs","sources":["../../../../src/hooks/useSticky/useSticky.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\nimport type { HookTarget } from '@/utils/helpers';\n\nimport { getElement, isTarget } from '@/utils/helpers';\n\nimport type { StateRef } from '../useRefState/useRefState';\n\nimport { useRefState } from '../useRefState/useRefState';\n\n/** The use sticky return type */\nexport interface UseStickyReturn {\n stuck: boolean;\n}\n\n/** The use sticky axis type */\nexport type UseStickyAxis = 'horizontal' | 'vertical';\n\n/** The use sticky options type */\nexport interface UseStickyOptions {\n axis?: UseStickyAxis;\n root?: HookTarget;\n}\n\nexport interface UseSticky {\n (target: HookTarget, options?: UseStickyOptions): boolean;\n\n <Target extends Element>(\n options?: UseStickyOptions,\n target?: never\n ): { ref: StateRef<Target> } & UseStickyReturn;\n}\n\n/**\n * @name UseSticky\n * @description - Hook that allows you to detect that your sticky component is stuck\n * @category Browser\n *\n * @overload\n * @param {HookTarget} target The target sticky element\n * @param {UseStickyAxis} [options.axis='vertical'] The axis of motion of the sticky component\n * @param {UseStickyRoot} [options.root=document] The element that contains your sticky component\n * @returns {UseStickyReturn} The state of the sticky\n *\n * @example\n * const stuck = useSticky(ref);\n *\n * @overload\n * @param {UseStickyAxis} [options.axis='vertical'] The axis of motion of the sticky component\n * @param {UseStickyRoot} [options.root=document] The element that contains your sticky component\n * @returns {{ stickyRef: StateRef<Target> } & UseStickyReturn} The state of the sticky\n *\n * @example\n * const { stuck, ref } = useSticky();\n */\nexport const useSticky = ((...params: any[]) => {\n const target = (isTarget(params[0]) ? params[0] : undefined) as HookTarget | undefined;\n const options = (target ? params[1] : params[0]) as UseStickyOptions;\n const axis = options?.axis ?? 'vertical';\n\n const internalRef = useRefState<Element>();\n const [stuck, setStuck] = useState(false);\n\n useEffect(() => {\n if (!target && !internalRef.state) return;\n\n const element = (target ? getElement(target) : internalRef.current) as Element;\n\n if (!element) return;\n\n const root = (options?.root ? getElement(options.root) : document) as Element;\n const elementOffsetTop =\n element.getBoundingClientRect().top + root.scrollTop - root.getBoundingClientRect().top;\n const elementOffsetLeft =\n element.getBoundingClientRect().left + root.scrollLeft - root.getBoundingClientRect().left;\n\n const onSticky = () => {\n if (axis === 'vertical') {\n const scrollTop = root.scrollTop;\n setStuck(scrollTop >= elementOffsetTop);\n }\n\n if (axis === 'horizontal') {\n const scrollLeft = root.scrollLeft;\n setStuck(scrollLeft >= elementOffsetLeft);\n }\n };\n\n root.addEventListener('scroll', onSticky);\n window.addEventListener('resize', onSticky);\n window.addEventListener('orientationchange', onSticky);\n\n onSticky();\n\n return () => {\n root.removeEventListener('scroll', onSticky);\n window.removeEventListener('resize', onSticky);\n window.removeEventListener('orientationchange', onSticky);\n };\n }, [target, internalRef.state, axis, options?.root]);\n\n if (target) return stuck;\n return {\n stuck,\n ref: internalRef\n };\n}) as UseSticky;\n"],"names":["useSticky","params","target","isTarget","options","axis","internalRef","useRefState","stuck","setStuck","useState","useEffect","element","getElement","root","elementOffsetTop","elementOffsetLeft","onSticky","scrollTop","scrollLeft"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"useSticky.mjs","sources":["../../../../src/hooks/useSticky/useSticky.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\nimport type { HookTarget } from '@/utils/helpers';\n\nimport { getElement, isTarget } from '@/utils/helpers';\n\nimport type { StateRef } from '../useRefState/useRefState';\n\nimport { useRefState } from '../useRefState/useRefState';\n\n/** The use sticky return type */\nexport interface UseStickyReturn {\n stuck: boolean;\n}\n\n/** The use sticky axis type */\nexport type UseStickyAxis = 'horizontal' | 'vertical';\n\n/** The use sticky options type */\nexport interface UseStickyOptions {\n axis?: UseStickyAxis;\n root?: HookTarget;\n}\n\nexport interface UseSticky {\n (target: HookTarget, options?: UseStickyOptions): boolean;\n\n <Target extends Element>(\n options?: UseStickyOptions,\n target?: never\n ): { ref: StateRef<Target> } & UseStickyReturn;\n}\n\n/**\n * @name UseSticky\n * @description - Hook that allows you to detect that your sticky component is stuck\n * @category Browser\n *\n * @overload\n * @param {HookTarget} target The target sticky element\n * @param {UseStickyAxis} [options.axis='vertical'] The axis of motion of the sticky component\n * @param {UseStickyRoot} [options.root=document] The element that contains your sticky component\n * @returns {UseStickyReturn} The state of the sticky\n *\n * @example\n * const stuck = useSticky(ref);\n *\n * @overload\n * @param {UseStickyAxis} [options.axis='vertical'] The axis of motion of the sticky component\n * @param {UseStickyRoot} [options.root=document] The element that contains your sticky component\n * @returns {{ stickyRef: StateRef<Target> } & UseStickyReturn} The state of the sticky\n *\n * @example\n * const { stuck, ref } = useSticky();\n */\nexport const useSticky = ((...params: any[]) => {\n const target = (isTarget(params[0]) ? params[0] : undefined) as HookTarget | undefined;\n const options = (target ? params[1] : params[0]) as UseStickyOptions;\n const axis = options?.axis ?? 'vertical';\n\n const internalRef = useRefState<Element>();\n const [stuck, setStuck] = useState(false);\n\n useEffect(() => {\n if (!target && !internalRef.state) return;\n\n const element = (target ? getElement(target) : internalRef.current) as Element;\n\n if (!element) return;\n\n const root = (options?.root ? getElement(options.root) : document) as Element;\n const elementOffsetTop =\n element.getBoundingClientRect().top + root.scrollTop - root.getBoundingClientRect().top;\n const elementOffsetLeft =\n element.getBoundingClientRect().left + root.scrollLeft - root.getBoundingClientRect().left;\n\n const onSticky = () => {\n if (axis === 'vertical') {\n const scrollTop = root.scrollTop;\n setStuck(scrollTop >= elementOffsetTop);\n }\n\n if (axis === 'horizontal') {\n const scrollLeft = root.scrollLeft;\n setStuck(scrollLeft >= elementOffsetLeft);\n }\n };\n\n root.addEventListener('scroll', onSticky);\n window.addEventListener('resize', onSticky);\n window.addEventListener('orientationchange', onSticky);\n\n onSticky();\n\n return () => {\n root.removeEventListener('scroll', onSticky);\n window.removeEventListener('resize', onSticky);\n window.removeEventListener('orientationchange', onSticky);\n };\n }, [target, internalRef.state, axis, options?.root]);\n\n if (target) return stuck;\n return {\n stuck,\n ref: internalRef\n };\n}) as UseSticky;\n"],"names":["useSticky","params","target","isTarget","options","axis","internalRef","useRefState","stuck","setStuck","useState","useEffect","element","getElement","root","elementOffsetTop","elementOffsetLeft","onSticky","scrollTop","scrollLeft"],"mappings":";;;;AAuDO,MAAMA,IAAa,IAAIC,MAAkB;AAC9C,QAAMC,IAAUC,EAASF,EAAO,CAAC,CAAC,IAAIA,EAAO,CAAC,IAAI,QAC5CG,IAAWF,IAASD,EAAO,CAAC,IAAIA,EAAO,CAAC,GACxCI,IAAOD,GAAS,QAAQ,YAExBE,IAAcC,EAAA,GACd,CAACC,GAAOC,CAAQ,IAAIC,EAAS,EAAK;AAwCxC,SAtCAC,EAAU,MAAM;AACd,QAAI,CAACT,KAAU,CAACI,EAAY,MAAO;AAEnC,UAAMM,IAAWV,IAASW,EAAWX,CAAM,IAAII,EAAY;AAE3D,QAAI,CAACM,EAAS;AAEd,UAAME,IAAQV,GAAS,OAAOS,EAAWT,EAAQ,IAAI,IAAI,UACnDW,IACJH,EAAQ,wBAAwB,MAAME,EAAK,YAAYA,EAAK,sBAAA,EAAwB,KAChFE,IACJJ,EAAQ,wBAAwB,OAAOE,EAAK,aAAaA,EAAK,sBAAA,EAAwB,MAElFG,IAAW,MAAM;AACrB,UAAIZ,MAAS,YAAY;AACvB,cAAMa,IAAYJ,EAAK;AACvB,QAAAL,EAASS,KAAaH,CAAgB;AAAA,MAAA;AAGxC,UAAIV,MAAS,cAAc;AACzB,cAAMc,IAAaL,EAAK;AACxB,QAAAL,EAASU,KAAcH,CAAiB;AAAA,MAAA;AAAA,IAC1C;AAGF,WAAAF,EAAK,iBAAiB,UAAUG,CAAQ,GACxC,OAAO,iBAAiB,UAAUA,CAAQ,GAC1C,OAAO,iBAAiB,qBAAqBA,CAAQ,GAErDA,EAAA,GAEO,MAAM;AACX,MAAAH,EAAK,oBAAoB,UAAUG,CAAQ,GAC3C,OAAO,oBAAoB,UAAUA,CAAQ,GAC7C,OAAO,oBAAoB,qBAAqBA,CAAQ;AAAA,IAAA;AAAA,EAC1D,GACC,CAACf,GAAQI,EAAY,OAAOD,GAAMD,GAAS,IAAI,CAAC,GAE/CF,IAAeM,IACZ;AAAA,IACL,OAAAA;AAAA,IACA,KAAKF;AAAA,EAAA;AAET;"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { useState as
|
|
2
|
-
const
|
|
1
|
+
import { useState as f, useEffect as h } from "react";
|
|
2
|
+
const l = (t) => {
|
|
3
3
|
if (!t)
|
|
4
4
|
return {
|
|
5
5
|
days: 0,
|
|
@@ -8,15 +8,14 @@ const h = (t) => {
|
|
|
8
8
|
seconds: 0,
|
|
9
9
|
count: 0
|
|
10
10
|
};
|
|
11
|
-
const
|
|
12
|
-
return { days:
|
|
13
|
-
},
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
return y(() => {
|
|
11
|
+
const s = Math.floor(t / 86400), e = Math.floor(t % 86400 / 3600), c = Math.floor(t % 3600 / 60), u = Math.floor(t % 60);
|
|
12
|
+
return { days: s, hours: e, minutes: c, seconds: u, count: t };
|
|
13
|
+
}, M = (...t) => {
|
|
14
|
+
const s = (typeof t[0] == "number" ? t[0] : t[0]?.initialTime) ?? 0, e = typeof t[0] == "number" ? t[1] : t[0], [c, u] = f(l(s)), [r, d] = f(!e?.enabled);
|
|
15
|
+
return h(() => {
|
|
17
16
|
if (r) return;
|
|
18
17
|
const a = () => {
|
|
19
|
-
|
|
18
|
+
u((n) => {
|
|
20
19
|
const o = n.count + 1;
|
|
21
20
|
return o % 60 === 0 ? {
|
|
22
21
|
...n,
|
|
@@ -49,11 +48,11 @@ const h = (t) => {
|
|
|
49
48
|
paused: r,
|
|
50
49
|
pause: () => d(!0),
|
|
51
50
|
start: () => d(!1),
|
|
52
|
-
reset: () =>
|
|
51
|
+
reset: () => u(l(s)),
|
|
53
52
|
toggle: () => d((a) => !a)
|
|
54
53
|
};
|
|
55
54
|
};
|
|
56
55
|
export {
|
|
57
|
-
|
|
56
|
+
M as useStopwatch
|
|
58
57
|
};
|
|
59
58
|
//# sourceMappingURL=useStopwatch.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useStopwatch.mjs","sources":["../../../../src/hooks/useStopwatch/useStopwatch.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\nconst getStopwatchTime = (time: number) => {\n if (!time)\n return {\n days: 0,\n hours: 0,\n minutes: 0,\n seconds: 0,\n count: 0\n };\n\n const days = Math.floor(time / 86400);\n const hours = Math.floor((time % 86400) / 3600);\n const minutes = Math.floor((time % 3600) / 60);\n const seconds = Math.floor(time % 60);\n\n return { days, hours, minutes, seconds, count: time };\n};\n\n/** The use stopwatch return type */\nexport interface UseStopwatchReturn {\n /** The total count of the stopwatch */\n count: number;\n /** The day count of the stopwatch */\n days: number;\n /** The hour count of the stopwatch */\n hours: number;\n /** The minute count of the stopwatch */\n minutes: number;\n /** The over state of the stopwatch */\n over: boolean;\n /** The paused state of the stopwatch */\n paused: boolean;\n /** The second count of the stopwatch */\n seconds: number;\n /** The function to pause the stopwatch */\n pause: () => void;\n /** The function to reset the stopwatch */\n reset: () => void;\n /** The function to start the stopwatch */\n start: () => void;\n /** The function to toggle the stopwatch */\n toggle: () => void;\n}\n\n/** The use stopwatch options */\nexport interface UseStopwatchOptions {\n /** The enabled state of the timer */\n enabled?: boolean;\n}\n\ninterface UseStopwatch {\n (initialTime?: number, options?: UseStopwatchOptions): UseStopwatchReturn;\n (options?: UseStopwatchOptions & { initialTime?: number }): UseStopwatchReturn;\n}\n/**\n * @name useStopwatch\n * @description - Hook that creates a stopwatch functionality\n * @category Time\n *\n * @overload\n * @param {number} [initialTime=0] The initial time of the timer\n * @param {boolean} [options.enabled=true] The enabled state of the timer\n * @returns {UseStopwatchReturn} An object containing the current time and functions to interact with the timer\n *\n * @example\n * const { seconds, minutes, start, pause, reset } = useStopwatch(1000, { enabled: false });\n *\n * @overload\n * @param {number} [options.initialTime=0] -The initial time of the timer\n * @param {boolean} [options.enabled=true] The enabled state of the timer\n * @returns {UseStopwatchReturn} An object containing the current time and functions to interact with the timer\n *\n * @example\n * const { seconds, minutes, start, pause, reset } = useStopwatch({ initialTime: 1000, enabled: false });\n */\nexport const useStopwatch = ((...params: any[]) => {\n const initialTime =\n (typeof params[0] === 'number'\n ? (params[0] as number | undefined)\n : (params[0] as UseStopwatchOptions & { initialTime?: number })?.initialTime) ?? 0;\n\n const options =\n typeof params[0] === 'number'\n ? (params[1] as UseStopwatchOptions | undefined)\n : (params[0] as (UseStopwatchOptions & { initialTime?: number }) | undefined);\n\n const [time, setTime] = useState(getStopwatchTime(initialTime));\n const [paused, setPaused] = useState(!options?.enabled);\n\n useEffect(() => {\n if (paused) return;\n const onInterval = () => {\n setTime((prevTime) => {\n const updatedCount = prevTime.count + 1;\n\n if (updatedCount % 60 === 0) {\n return {\n ...prevTime,\n minutes: prevTime.minutes + 1,\n seconds: 0,\n count: updatedCount\n };\n }\n\n if (updatedCount % (60 * 60) === 0) {\n return {\n ...prevTime,\n hours: prevTime.hours + 1,\n minutes: 0,\n seconds: 0,\n count: updatedCount\n };\n }\n\n if (updatedCount % (60 * 60 * 24) === 0) {\n return {\n ...prevTime,\n days: prevTime.days + 1,\n hours: 0,\n minutes: 0,\n seconds: 0,\n count: updatedCount\n };\n }\n\n return {\n ...prevTime,\n seconds: prevTime.seconds + 1,\n count: updatedCount\n };\n });\n };\n\n const interval = setInterval(() => onInterval(), 1000);\n return () => clearInterval(interval);\n }, [paused]);\n\n return {\n ...time,\n paused,\n pause: () => setPaused(true),\n start: () => setPaused(false),\n reset: () => setTime(getStopwatchTime(initialTime)),\n toggle: () => setPaused((prevPause) => !prevPause)\n };\n}) as UseStopwatch;\n"],"names":["getStopwatchTime","time","days","hours","minutes","seconds","useStopwatch","params","initialTime","
|
|
1
|
+
{"version":3,"file":"useStopwatch.mjs","sources":["../../../../src/hooks/useStopwatch/useStopwatch.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\nconst getStopwatchTime = (time: number) => {\n if (!time)\n return {\n days: 0,\n hours: 0,\n minutes: 0,\n seconds: 0,\n count: 0\n };\n\n const days = Math.floor(time / 86400);\n const hours = Math.floor((time % 86400) / 3600);\n const minutes = Math.floor((time % 3600) / 60);\n const seconds = Math.floor(time % 60);\n\n return { days, hours, minutes, seconds, count: time };\n};\n\n/** The use stopwatch return type */\nexport interface UseStopwatchReturn {\n /** The total count of the stopwatch */\n count: number;\n /** The day count of the stopwatch */\n days: number;\n /** The hour count of the stopwatch */\n hours: number;\n /** The minute count of the stopwatch */\n minutes: number;\n /** The over state of the stopwatch */\n over: boolean;\n /** The paused state of the stopwatch */\n paused: boolean;\n /** The second count of the stopwatch */\n seconds: number;\n /** The function to pause the stopwatch */\n pause: () => void;\n /** The function to reset the stopwatch */\n reset: () => void;\n /** The function to start the stopwatch */\n start: () => void;\n /** The function to toggle the stopwatch */\n toggle: () => void;\n}\n\n/** The use stopwatch options */\nexport interface UseStopwatchOptions {\n /** The enabled state of the timer */\n enabled?: boolean;\n}\n\ninterface UseStopwatch {\n (initialTime?: number, options?: UseStopwatchOptions): UseStopwatchReturn;\n (options?: UseStopwatchOptions & { initialTime?: number }): UseStopwatchReturn;\n}\n/**\n * @name useStopwatch\n * @description - Hook that creates a stopwatch functionality\n * @category Time\n *\n * @overload\n * @param {number} [initialTime=0] The initial time of the timer\n * @param {boolean} [options.enabled=true] The enabled state of the timer\n * @returns {UseStopwatchReturn} An object containing the current time and functions to interact with the timer\n *\n * @example\n * const { seconds, minutes, start, pause, reset } = useStopwatch(1000, { enabled: false });\n *\n * @overload\n * @param {number} [options.initialTime=0] -The initial time of the timer\n * @param {boolean} [options.enabled=true] The enabled state of the timer\n * @returns {UseStopwatchReturn} An object containing the current time and functions to interact with the timer\n *\n * @example\n * const { seconds, minutes, start, pause, reset } = useStopwatch({ initialTime: 1000, enabled: false });\n */\nexport const useStopwatch = ((...params: any[]) => {\n const initialTime =\n (typeof params[0] === 'number'\n ? (params[0] as number | undefined)\n : (params[0] as UseStopwatchOptions & { initialTime?: number })?.initialTime) ?? 0;\n\n const options =\n typeof params[0] === 'number'\n ? (params[1] as UseStopwatchOptions | undefined)\n : (params[0] as (UseStopwatchOptions & { initialTime?: number }) | undefined);\n\n const [time, setTime] = useState(getStopwatchTime(initialTime));\n const [paused, setPaused] = useState(!options?.enabled);\n\n useEffect(() => {\n if (paused) return;\n const onInterval = () => {\n setTime((prevTime) => {\n const updatedCount = prevTime.count + 1;\n\n if (updatedCount % 60 === 0) {\n return {\n ...prevTime,\n minutes: prevTime.minutes + 1,\n seconds: 0,\n count: updatedCount\n };\n }\n\n if (updatedCount % (60 * 60) === 0) {\n return {\n ...prevTime,\n hours: prevTime.hours + 1,\n minutes: 0,\n seconds: 0,\n count: updatedCount\n };\n }\n\n if (updatedCount % (60 * 60 * 24) === 0) {\n return {\n ...prevTime,\n days: prevTime.days + 1,\n hours: 0,\n minutes: 0,\n seconds: 0,\n count: updatedCount\n };\n }\n\n return {\n ...prevTime,\n seconds: prevTime.seconds + 1,\n count: updatedCount\n };\n });\n };\n\n const interval = setInterval(() => onInterval(), 1000);\n return () => clearInterval(interval);\n }, [paused]);\n\n return {\n ...time,\n paused,\n pause: () => setPaused(true),\n start: () => setPaused(false),\n reset: () => setTime(getStopwatchTime(initialTime)),\n toggle: () => setPaused((prevPause) => !prevPause)\n };\n}) as UseStopwatch;\n"],"names":["getStopwatchTime","time","days","hours","minutes","seconds","useStopwatch","params","initialTime","options","setTime","useState","paused","setPaused","useEffect","onInterval","prevTime","updatedCount","interval","prevPause"],"mappings":";AAEA,MAAMA,IAAmB,CAACC,MAAiB;AACzC,MAAI,CAACA;AACH,WAAO;AAAA,MACL,MAAM;AAAA,MACN,OAAO;AAAA,MACP,SAAS;AAAA,MACT,SAAS;AAAA,MACT,OAAO;AAAA,IAAA;AAGX,QAAMC,IAAO,KAAK,MAAMD,IAAO,KAAK,GAC9BE,IAAQ,KAAK,MAAOF,IAAO,QAAS,IAAI,GACxCG,IAAU,KAAK,MAAOH,IAAO,OAAQ,EAAE,GACvCI,IAAU,KAAK,MAAMJ,IAAO,EAAE;AAEpC,SAAO,EAAE,MAAAC,GAAM,OAAAC,GAAO,SAAAC,GAAS,SAAAC,GAAS,OAAOJ,EAAA;AACjD,GA2DaK,IAAgB,IAAIC,MAAkB;AACjD,QAAMC,KACH,OAAOD,EAAO,CAAC,KAAM,WACjBA,EAAO,CAAC,IACRA,EAAO,CAAC,GAAsD,gBAAgB,GAE/EE,IACJ,OAAOF,EAAO,CAAC,KAAM,WAChBA,EAAO,CAAC,IACRA,EAAO,CAAC,GAET,CAACN,GAAMS,CAAO,IAAIC,EAASX,EAAiBQ,CAAW,CAAC,GACxD,CAACI,GAAQC,CAAS,IAAIF,EAAS,CAACF,GAAS,OAAO;AAEtD,SAAAK,EAAU,MAAM;AACd,QAAIF,EAAQ;AACZ,UAAMG,IAAa,MAAM;AACvB,MAAAL,EAAQ,CAACM,MAAa;AACpB,cAAMC,IAAeD,EAAS,QAAQ;AAEtC,eAAIC,IAAe,OAAO,IACjB;AAAA,UACL,GAAGD;AAAA,UACH,SAASA,EAAS,UAAU;AAAA,UAC5B,SAAS;AAAA,UACT,OAAOC;AAAA,QAAA,IAIPA,KAAgB,KAAK,QAAQ,IACxB;AAAA,UACL,GAAGD;AAAA,UACH,OAAOA,EAAS,QAAQ;AAAA,UACxB,SAAS;AAAA,UACT,SAAS;AAAA,UACT,OAAOC;AAAA,QAAA,IAIPA,KAAgB,KAAK,KAAK,QAAQ,IAC7B;AAAA,UACL,GAAGD;AAAA,UACH,MAAMA,EAAS,OAAO;AAAA,UACtB,OAAO;AAAA,UACP,SAAS;AAAA,UACT,SAAS;AAAA,UACT,OAAOC;AAAA,QAAA,IAIJ;AAAA,UACL,GAAGD;AAAA,UACH,SAASA,EAAS,UAAU;AAAA,UAC5B,OAAOC;AAAA,QAAA;AAAA,MACT,CACD;AAAA,IAAA,GAGGC,IAAW,YAAY,MAAMH,EAAA,GAAc,GAAI;AACrD,WAAO,MAAM,cAAcG,CAAQ;AAAA,EAAA,GAClC,CAACN,CAAM,CAAC,GAEJ;AAAA,IACL,GAAGX;AAAA,IACH,QAAAW;AAAA,IACA,OAAO,MAAMC,EAAU,EAAI;AAAA,IAC3B,OAAO,MAAMA,EAAU,EAAK;AAAA,IAC5B,OAAO,MAAMH,EAAQV,EAAiBQ,CAAW,CAAC;AAAA,IAClD,QAAQ,MAAMK,EAAU,CAACM,MAAc,CAACA,CAAS;AAAA,EAAA;AAErD;"}
|
|
@@ -1,47 +1,47 @@
|
|
|
1
1
|
import { useState as V, useEffect as E } from "react";
|
|
2
|
-
const c = "reactuse-storage", f = (
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
}, m = (
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
}, l = (
|
|
9
|
-
const
|
|
10
|
-
if (
|
|
11
|
-
return
|
|
12
|
-
}, I = (
|
|
13
|
-
const
|
|
2
|
+
const c = "reactuse-storage", f = (t) => window.dispatchEvent(new StorageEvent(c, t)), d = (t, n, o) => {
|
|
3
|
+
const r = t.getItem(n);
|
|
4
|
+
t.setItem(n, o), f({ key: n, oldValue: r, newValue: o, storageArea: t });
|
|
5
|
+
}, m = (t, n) => {
|
|
6
|
+
const o = t.getItem(n);
|
|
7
|
+
t.removeItem(n), f({ key: n, oldValue: o, newValue: null, storageArea: t });
|
|
8
|
+
}, l = (t, n) => {
|
|
9
|
+
const o = t.getItem(n);
|
|
10
|
+
if (o)
|
|
11
|
+
return o;
|
|
12
|
+
}, I = (t, n) => {
|
|
13
|
+
const o = typeof n == "object" && n && ("serializer" in n || "deserializer" in n || "initialValue" in n || "storage" in n) ? n : void 0, r = o ? o?.initialValue : n;
|
|
14
14
|
if (typeof window > "u")
|
|
15
15
|
return {
|
|
16
|
-
value: typeof
|
|
16
|
+
value: typeof r == "function" ? r() : r,
|
|
17
17
|
set: () => {
|
|
18
18
|
},
|
|
19
19
|
remove: () => {
|
|
20
20
|
}
|
|
21
21
|
};
|
|
22
|
-
const u = (
|
|
23
|
-
if (
|
|
24
|
-
if (
|
|
22
|
+
const u = (e) => o?.serializer ? o.serializer(e) : typeof e == "string" ? e : JSON.stringify(e), i = o?.storage ?? window?.localStorage, g = (e) => d(i, t, u(e)), v = () => m(i, t), a = (e) => {
|
|
23
|
+
if (o?.deserializer) return o.deserializer(e);
|
|
24
|
+
if (e !== "undefined")
|
|
25
25
|
try {
|
|
26
|
-
return JSON.parse(
|
|
26
|
+
return JSON.parse(e);
|
|
27
27
|
} catch {
|
|
28
|
-
return
|
|
28
|
+
return e;
|
|
29
29
|
}
|
|
30
30
|
}, [w, S] = V(() => {
|
|
31
|
-
const
|
|
32
|
-
if (
|
|
33
|
-
const s = typeof
|
|
34
|
-
return d(
|
|
31
|
+
const e = l(i, t);
|
|
32
|
+
if (e === void 0 && r !== void 0) {
|
|
33
|
+
const s = typeof r == "function" ? r() : r;
|
|
34
|
+
return d(i, t, u(s)), s;
|
|
35
35
|
}
|
|
36
|
-
return
|
|
36
|
+
return e ? a(e) : void 0;
|
|
37
37
|
});
|
|
38
38
|
return E(() => {
|
|
39
|
-
const
|
|
40
|
-
const s = l(
|
|
39
|
+
const e = () => {
|
|
40
|
+
const s = l(i, t);
|
|
41
41
|
S(s ? a(s) : void 0);
|
|
42
42
|
};
|
|
43
|
-
return window.addEventListener(c,
|
|
44
|
-
}, [
|
|
43
|
+
return window.addEventListener(c, e), () => window.removeEventListener(c, e);
|
|
44
|
+
}, [t]), {
|
|
45
45
|
value: w,
|
|
46
46
|
set: g,
|
|
47
47
|
remove: v
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useStorage.mjs","sources":["../../../../src/hooks/useStorage/useStorage.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\n/* The use storage initial value type */\nexport type UseStorageInitialValue<Value> = (() => Value) | Value;\n\n/* The use storage options type */\nexport interface UseStorageOptions<Value> {\n /* The initial value of the storage */\n initialValue?: UseStorageInitialValue<Value>;\n /* The storage to be used */\n storage?: Storage;\n /* The deserializer function to be invoked */\n deserializer?: (value: string) => Value;\n /* The serializer function to be invoked */\n serializer?: (value: Value) => string;\n}\n\n/* The use storage return type */\nexport interface UseStorageReturn<Value> {\n /* The value of the storage */\n value: Value;\n /* The error state of the storage */\n remove: () => void;\n /* The loading state of the storage */\n set: (value: Value) => void;\n}\n\nexport interface UseStorage {\n <Value>(\n key: string,\n options: UseStorageOptions<Value> & { initialValue: UseStorageInitialValue<Value> }\n ): UseStorageReturn<Value>;\n\n <Value>(key: string, options?: UseStorageOptions<Value>): UseStorageReturn<Value | undefined>;\n\n <Value>(key: string, initialValue: UseStorageInitialValue<Value>): UseStorageReturn<Value>;\n\n <Value>(key: string): UseStorageReturn<Value | undefined>;\n}\n\nexport const STORAGE_EVENT = 'reactuse-storage';\n\nexport const dispatchStorageEvent = (params: Partial<StorageEvent>) =>\n window.dispatchEvent(new StorageEvent(STORAGE_EVENT, params));\n\nconst setStorageItem = (storage: Storage, key: string, value: string) => {\n const oldValue = storage.getItem(key);\n\n storage.setItem(key, value);\n dispatchStorageEvent({ key, oldValue, newValue: value, storageArea: storage });\n};\n\nconst removeStorageItem = (storage: Storage, key: string) => {\n const oldValue = storage.getItem(key);\n\n storage.removeItem(key);\n dispatchStorageEvent({ key, oldValue, newValue: null, storageArea: storage });\n};\n\nconst getStorageItem = (storage: Storage, key: string) => {\n const value = storage.getItem(key);\n if (!value) return undefined;\n return value;\n};\n\n/**\n * @name useStorage\n * @description - Hook that manages storage value\n * @category Browser\n *\n * @overload\n * @param {string} key The key of the storage\n * @param {UseStorageInitialValue<Value>} [initialValue] The initial value of the storage\n * @returns {UseStorageReturn<Value>} The value and the set function\n *\n * @overload\n * @param {string} key The key of the storage\n * @param {(value: Value) => string} [params.serializer] The serializer function\n * @param {(value: string) => Value} [params.deserializer] The deserializer function\n * @param {Storage} [params.storage] The storage\n * @param {UseStorageInitialValue<Value>} [params.initialValue] The initial value of the storage\n * @returns {UseStorageReturn<Value>} The value and the set function\n *\n * @example\n * const { value, set, remove } = useStorage('key', 'value');\n */\nexport const useStorage = (<Value>(key: string, params?: any): UseStorageReturn<Value> => {\n const options = (\n typeof params === 'object' &&\n params &&\n ('serializer' in params ||\n 'deserializer' in params ||\n 'initialValue' in params ||\n 'storage' in params)\n ? params\n : undefined\n ) as UseStorageOptions<Value>;\n\n const initialValue = (options ? options?.initialValue : params) as UseStorageInitialValue<Value>;\n\n if (typeof window === 'undefined') {\n const value = typeof initialValue === 'function' ? (initialValue as () => any)() : initialValue;\n return {\n value,\n set: () => {},\n remove: () => {}\n };\n }\n\n const serializer = (value: Value) => {\n if (options?.serializer) return options.serializer(value);\n if (typeof value === 'string') return value;\n return JSON.stringify(value);\n };\n\n const storage = options?.storage ?? window?.localStorage;\n\n const set = (value: Value) => setStorageItem(storage, key, serializer(value));\n const remove = () => removeStorageItem(storage, key);\n\n const deserializer = (value: string) => {\n if (options?.deserializer) return options.deserializer(value);\n if (value === 'undefined') return undefined as unknown as Value;\n\n try {\n return JSON.parse(value) as Value;\n } catch {\n return value as Value;\n }\n };\n\n const [value, setValue] = useState<Value | undefined>(() => {\n const storageValue = getStorageItem(storage, key);\n if (storageValue === undefined && initialValue !== undefined) {\n const value =\n typeof initialValue === 'function' ? (initialValue as () => Value)() : initialValue;\n setStorageItem(storage, key, serializer(value));\n return value;\n }\n return storageValue ? deserializer(storageValue) : undefined;\n });\n\n useEffect(() => {\n const onChange = () => {\n const storageValue = getStorageItem(storage, key);\n setValue(storageValue ? deserializer(storageValue) : undefined);\n };\n window.addEventListener(STORAGE_EVENT, onChange);\n return () => window.removeEventListener(STORAGE_EVENT, onChange);\n }, [key]);\n\n return {\n value: value as Value,\n set,\n remove\n };\n}) as UseStorage;\n"],"names":["STORAGE_EVENT","dispatchStorageEvent","params","setStorageItem","storage","key","value","oldValue","removeStorageItem","getStorageItem","useStorage","options","initialValue","serializer","set","remove","deserializer","setValue","useState","storageValue","useEffect","onChange"],"mappings":";AAwCO,MAAMA,IAAgB,oBAEhBC,IAAuB,CAACC,MACnC,OAAO,cAAc,IAAI,aAAaF,GAAeE,CAAM,CAAC,GAExDC,IAAiB,CAACC,GAAkBC,GAAaC,MAAkB;
|
|
1
|
+
{"version":3,"file":"useStorage.mjs","sources":["../../../../src/hooks/useStorage/useStorage.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\n/* The use storage initial value type */\nexport type UseStorageInitialValue<Value> = (() => Value) | Value;\n\n/* The use storage options type */\nexport interface UseStorageOptions<Value> {\n /* The initial value of the storage */\n initialValue?: UseStorageInitialValue<Value>;\n /* The storage to be used */\n storage?: Storage;\n /* The deserializer function to be invoked */\n deserializer?: (value: string) => Value;\n /* The serializer function to be invoked */\n serializer?: (value: Value) => string;\n}\n\n/* The use storage return type */\nexport interface UseStorageReturn<Value> {\n /* The value of the storage */\n value: Value;\n /* The error state of the storage */\n remove: () => void;\n /* The loading state of the storage */\n set: (value: Value) => void;\n}\n\nexport interface UseStorage {\n <Value>(\n key: string,\n options: UseStorageOptions<Value> & { initialValue: UseStorageInitialValue<Value> }\n ): UseStorageReturn<Value>;\n\n <Value>(key: string, options?: UseStorageOptions<Value>): UseStorageReturn<Value | undefined>;\n\n <Value>(key: string, initialValue: UseStorageInitialValue<Value>): UseStorageReturn<Value>;\n\n <Value>(key: string): UseStorageReturn<Value | undefined>;\n}\n\nexport const STORAGE_EVENT = 'reactuse-storage';\n\nexport const dispatchStorageEvent = (params: Partial<StorageEvent>) =>\n window.dispatchEvent(new StorageEvent(STORAGE_EVENT, params));\n\nconst setStorageItem = (storage: Storage, key: string, value: string) => {\n const oldValue = storage.getItem(key);\n\n storage.setItem(key, value);\n dispatchStorageEvent({ key, oldValue, newValue: value, storageArea: storage });\n};\n\nconst removeStorageItem = (storage: Storage, key: string) => {\n const oldValue = storage.getItem(key);\n\n storage.removeItem(key);\n dispatchStorageEvent({ key, oldValue, newValue: null, storageArea: storage });\n};\n\nconst getStorageItem = (storage: Storage, key: string) => {\n const value = storage.getItem(key);\n if (!value) return undefined;\n return value;\n};\n\n/**\n * @name useStorage\n * @description - Hook that manages storage value\n * @category Browser\n *\n * @overload\n * @param {string} key The key of the storage\n * @param {UseStorageInitialValue<Value>} [initialValue] The initial value of the storage\n * @returns {UseStorageReturn<Value>} The value and the set function\n *\n * @overload\n * @param {string} key The key of the storage\n * @param {(value: Value) => string} [params.serializer] The serializer function\n * @param {(value: string) => Value} [params.deserializer] The deserializer function\n * @param {Storage} [params.storage] The storage\n * @param {UseStorageInitialValue<Value>} [params.initialValue] The initial value of the storage\n * @returns {UseStorageReturn<Value>} The value and the set function\n *\n * @example\n * const { value, set, remove } = useStorage('key', 'value');\n */\nexport const useStorage = (<Value>(key: string, params?: any): UseStorageReturn<Value> => {\n const options = (\n typeof params === 'object' &&\n params &&\n ('serializer' in params ||\n 'deserializer' in params ||\n 'initialValue' in params ||\n 'storage' in params)\n ? params\n : undefined\n ) as UseStorageOptions<Value>;\n\n const initialValue = (options ? options?.initialValue : params) as UseStorageInitialValue<Value>;\n\n if (typeof window === 'undefined') {\n const value = typeof initialValue === 'function' ? (initialValue as () => any)() : initialValue;\n return {\n value,\n set: () => {},\n remove: () => {}\n };\n }\n\n const serializer = (value: Value) => {\n if (options?.serializer) return options.serializer(value);\n if (typeof value === 'string') return value;\n return JSON.stringify(value);\n };\n\n const storage = options?.storage ?? window?.localStorage;\n\n const set = (value: Value) => setStorageItem(storage, key, serializer(value));\n const remove = () => removeStorageItem(storage, key);\n\n const deserializer = (value: string) => {\n if (options?.deserializer) return options.deserializer(value);\n if (value === 'undefined') return undefined as unknown as Value;\n\n try {\n return JSON.parse(value) as Value;\n } catch {\n return value as Value;\n }\n };\n\n const [value, setValue] = useState<Value | undefined>(() => {\n const storageValue = getStorageItem(storage, key);\n if (storageValue === undefined && initialValue !== undefined) {\n const value =\n typeof initialValue === 'function' ? (initialValue as () => Value)() : initialValue;\n setStorageItem(storage, key, serializer(value));\n return value;\n }\n return storageValue ? deserializer(storageValue) : undefined;\n });\n\n useEffect(() => {\n const onChange = () => {\n const storageValue = getStorageItem(storage, key);\n setValue(storageValue ? deserializer(storageValue) : undefined);\n };\n window.addEventListener(STORAGE_EVENT, onChange);\n return () => window.removeEventListener(STORAGE_EVENT, onChange);\n }, [key]);\n\n return {\n value: value as Value,\n set,\n remove\n };\n}) as UseStorage;\n"],"names":["STORAGE_EVENT","dispatchStorageEvent","params","setStorageItem","storage","key","value","oldValue","removeStorageItem","getStorageItem","useStorage","options","initialValue","serializer","set","remove","deserializer","setValue","useState","storageValue","useEffect","onChange"],"mappings":";AAwCO,MAAMA,IAAgB,oBAEhBC,IAAuB,CAACC,MACnC,OAAO,cAAc,IAAI,aAAaF,GAAeE,CAAM,CAAC,GAExDC,IAAiB,CAACC,GAAkBC,GAAaC,MAAkB;AACvE,QAAMC,IAAWH,EAAQ,QAAQC,CAAG;AAEpC,EAAAD,EAAQ,QAAQC,GAAKC,CAAK,GAC1BL,EAAqB,EAAE,KAAAI,GAAK,UAAAE,GAAU,UAAUD,GAAO,aAAaF,GAAS;AAC/E,GAEMI,IAAoB,CAACJ,GAAkBC,MAAgB;AAC3D,QAAME,IAAWH,EAAQ,QAAQC,CAAG;AAEpC,EAAAD,EAAQ,WAAWC,CAAG,GACtBJ,EAAqB,EAAE,KAAAI,GAAK,UAAAE,GAAU,UAAU,MAAM,aAAaH,GAAS;AAC9E,GAEMK,IAAiB,CAACL,GAAkBC,MAAgB;AACxD,QAAMC,IAAQF,EAAQ,QAAQC,CAAG;AACjC,MAAKC;AACL,WAAOA;AACT,GAuBaI,IAAc,CAAQL,GAAaH,MAA0C;AACxF,QAAMS,IACJ,OAAOT,KAAW,YAClBA,MACC,gBAAgBA,KACf,kBAAkBA,KAClB,kBAAkBA,KAClB,aAAaA,KACXA,IACA,QAGAU,IAAgBD,IAAUA,GAAS,eAAeT;AAExD,MAAI,OAAO,SAAW;AAEpB,WAAO;AAAA,MACL,OAFY,OAAOU,KAAiB,aAAcA,MAA+BA;AAAA,MAGjF,KAAK,MAAM;AAAA,MAAA;AAAA,MACX,QAAQ,MAAM;AAAA,MAAA;AAAA,IAAC;AAInB,QAAMC,IAAa,CAACP,MACdK,GAAS,aAAmBA,EAAQ,WAAWL,CAAK,IACpD,OAAOA,KAAU,WAAiBA,IAC/B,KAAK,UAAUA,CAAK,GAGvBF,IAAUO,GAAS,WAAW,QAAQ,cAEtCG,IAAM,CAACR,MAAiBH,EAAeC,GAASC,GAAKQ,EAAWP,CAAK,CAAC,GACtES,IAAS,MAAMP,EAAkBJ,GAASC,CAAG,GAE7CW,IAAe,CAACV,MAAkB;AACtC,QAAIK,GAAS,aAAc,QAAOA,EAAQ,aAAaL,CAAK;AAC5D,QAAIA,MAAU;AAEd,UAAI;AACF,eAAO,KAAK,MAAMA,CAAK;AAAA,MAAA,QACjB;AACN,eAAOA;AAAAA,MAAA;AAAA,EACT,GAGI,CAACA,GAAOW,CAAQ,IAAIC,EAA4B,MAAM;AAC1D,UAAMC,IAAeV,EAAeL,GAASC,CAAG;AAChD,QAAIc,MAAiB,UAAaP,MAAiB,QAAW;AAC5D,YAAMN,IACJ,OAAOM,KAAiB,aAAcA,MAAiCA;AACzE,aAAAT,EAAeC,GAASC,GAAKQ,EAAWP,CAAK,CAAC,GACvCA;AAAAA,IAAA;AAET,WAAOa,IAAeH,EAAaG,CAAY,IAAI;AAAA,EAAA,CACpD;AAED,SAAAC,EAAU,MAAM;AACd,UAAMC,IAAW,MAAM;AACrB,YAAMF,IAAeV,EAAeL,GAASC,CAAG;AAChD,MAAAY,EAASE,IAAeH,EAAaG,CAAY,IAAI,MAAS;AAAA,IAAA;AAEhE,kBAAO,iBAAiBnB,GAAeqB,CAAQ,GACxC,MAAM,OAAO,oBAAoBrB,GAAeqB,CAAQ;AAAA,EAAA,GAC9D,CAAChB,CAAG,CAAC,GAED;AAAA,IACL,OAAAC;AAAA,IACA,KAAAQ;AAAA,IACA,QAAAC;AAAA,EAAA;AAEJ;"}
|
|
@@ -1,34 +1,31 @@
|
|
|
1
|
-
import { useState as
|
|
2
|
-
import { useIsomorphicLayoutEffect as
|
|
1
|
+
import { useState as a } from "react";
|
|
2
|
+
import { useIsomorphicLayoutEffect as d } from "../useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.mjs";
|
|
3
3
|
import { useRefState as v } from "../useRefState/useRefState.mjs";
|
|
4
4
|
import { isTarget as g } from "../../utils/helpers/isTarget.mjs";
|
|
5
5
|
import { getElement as i } from "../../utils/helpers/getElement.mjs";
|
|
6
|
-
const R = (...
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
},
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
}, m = (t) => {
|
|
14
|
-
const o = e ? i(e) : r.current;
|
|
15
|
-
o && (c(t), o.setAttribute("dir", t));
|
|
6
|
+
const R = (...o) => {
|
|
7
|
+
const t = g(o[0]) ? o[0] : void 0, b = (t ? o[1] : o[0]) ?? "ltr", r = v(), s = () => (t ? i(t) : r.current)?.getAttribute("dir") ?? b, [u, c] = a(s()), m = () => {
|
|
8
|
+
const e = t ? i(t) : r.current;
|
|
9
|
+
e && e?.removeAttribute("dir");
|
|
10
|
+
}, f = (e) => {
|
|
11
|
+
const n = t ? i(t) : r.current;
|
|
12
|
+
n && (c(e), n.setAttribute("dir", e));
|
|
16
13
|
};
|
|
17
|
-
return
|
|
18
|
-
if (!
|
|
19
|
-
const
|
|
20
|
-
if (!
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
const
|
|
24
|
-
return
|
|
25
|
-
|
|
14
|
+
return d(() => {
|
|
15
|
+
if (!t && !r.state) return;
|
|
16
|
+
const e = t ? i(t) : r.current;
|
|
17
|
+
if (!e) return;
|
|
18
|
+
const n = s();
|
|
19
|
+
e.setAttribute("dir", n), c(n);
|
|
20
|
+
const l = new MutationObserver(s);
|
|
21
|
+
return l.observe(e, { attributes: !0 }), () => {
|
|
22
|
+
l.disconnect();
|
|
26
23
|
};
|
|
27
|
-
}, [r.state,
|
|
24
|
+
}, [r.state, t]), t ? { value: u, set: f, remove: m } : {
|
|
28
25
|
ref: r,
|
|
29
26
|
value: u,
|
|
30
|
-
set:
|
|
31
|
-
remove:
|
|
27
|
+
set: f,
|
|
28
|
+
remove: m
|
|
32
29
|
};
|
|
33
30
|
};
|
|
34
31
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useTextDirection.mjs","sources":["../../../../src/hooks/useTextDirection/useTextDirection.ts"],"sourcesContent":["import { 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 { useIsomorphicLayoutEffect } from '../useIsomorphicLayoutEffect/useIsomorphicLayoutEffect';\nimport { useRefState } from '../useRefState/useRefState';\n\n/** The use text direction value type */\nexport type UseTextDirectionValue = 'auto' | 'ltr' | 'rtl';\n\n/** The use text direction return type */\nexport interface UseTextDirectionReturn {\n /** The current direction */\n value: UseTextDirectionValue;\n /*** The function to remove the direction */\n remove: () => void;\n /*** The function to set the direction */\n set: (value: UseTextDirectionValue | null) => void;\n}\n\nexport interface UseTextDirection {\n (target: HookTarget, initialValue?: UseTextDirectionValue): UseTextDirectionReturn;\n\n <Target extends Element>(\n initialValue?: UseTextDirectionValue,\n target?: never\n ): UseTextDirectionReturn & { ref: StateRef<Target> };\n}\n\n/**\n * @name useTextDirection\n * @description - Hook that can get and set the direction of the element\n * @category Browser\n *\n * @overload\n * @param {HookTarget} target The target element to observe\n * @param {UseTextDirectionValue} [initialValue = 'ltr'] The initial direction of the element\n * @returns {UseTextDirectionReturn} An object containing the current text direction of the element\n *\n * @example\n * const { value, set, remove } = useTextDirection(ref);\n *\n * @overload\n * @template Target The target element type\n * @param {UseTextDirectionValue} [initialValue = 'ltr'] The initial direction of the element\n * @returns { { ref: StateRef<Target> } & UseTextDirectionReturn } An object containing the current text direction of the element\n *\n * @example\n * const { ref, value, set, remove } = useTextDirection();\n */\nexport const useTextDirection = ((...params: any[]) => {\n const target = (isTarget(params[0]) ? params[0] : undefined) as HookTarget | undefined;\n const initialValue = ((target ? params[1] : params[0]) as UseTextDirectionValue) ?? 'ltr';\n\n const internalRef = useRefState<Element>();\n\n const getDirection = () => {\n const element = (target ? getElement(target) : internalRef.current) as Element;\n return (element?.getAttribute('dir') as UseTextDirectionValue) ?? initialValue;\n };\n\n const [value, setValue] = useState<UseTextDirectionValue>(getDirection());\n\n const remove = () => {\n const element = (target ? getElement(target) : internalRef.current) as Element;\n if (!element) return;\n\n element?.removeAttribute('dir');\n };\n\n const set = (value: UseTextDirectionValue) => {\n const element = (target ? getElement(target) : internalRef.current) as Element;\n if (!element) return;\n\n setValue(value);\n element.setAttribute('dir', value);\n };\n\n useIsomorphicLayoutEffect(() => {\n if (!target && !internalRef.state) return;\n\n const element = (target ? getElement(target) : internalRef.current) as Element;\n if (!element) return;\n\n const direction = getDirection();\n element.setAttribute('dir', direction);\n setValue(direction);\n\n const observer = new MutationObserver(getDirection);\n\n observer.observe(element, { attributes: true });\n\n return () => {\n observer.disconnect();\n };\n }, [internalRef.state, target]);\n\n if (target) return { value, set, remove };\n return {\n ref: internalRef,\n value,\n set,\n remove\n };\n}) as UseTextDirection;\n"],"names":["useTextDirection","params","target","isTarget","initialValue","internalRef","useRefState","getDirection","
|
|
1
|
+
{"version":3,"file":"useTextDirection.mjs","sources":["../../../../src/hooks/useTextDirection/useTextDirection.ts"],"sourcesContent":["import { 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 { useIsomorphicLayoutEffect } from '../useIsomorphicLayoutEffect/useIsomorphicLayoutEffect';\nimport { useRefState } from '../useRefState/useRefState';\n\n/** The use text direction value type */\nexport type UseTextDirectionValue = 'auto' | 'ltr' | 'rtl';\n\n/** The use text direction return type */\nexport interface UseTextDirectionReturn {\n /** The current direction */\n value: UseTextDirectionValue;\n /*** The function to remove the direction */\n remove: () => void;\n /*** The function to set the direction */\n set: (value: UseTextDirectionValue | null) => void;\n}\n\nexport interface UseTextDirection {\n (target: HookTarget, initialValue?: UseTextDirectionValue): UseTextDirectionReturn;\n\n <Target extends Element>(\n initialValue?: UseTextDirectionValue,\n target?: never\n ): UseTextDirectionReturn & { ref: StateRef<Target> };\n}\n\n/**\n * @name useTextDirection\n * @description - Hook that can get and set the direction of the element\n * @category Browser\n *\n * @overload\n * @param {HookTarget} target The target element to observe\n * @param {UseTextDirectionValue} [initialValue = 'ltr'] The initial direction of the element\n * @returns {UseTextDirectionReturn} An object containing the current text direction of the element\n *\n * @example\n * const { value, set, remove } = useTextDirection(ref);\n *\n * @overload\n * @template Target The target element type\n * @param {UseTextDirectionValue} [initialValue = 'ltr'] The initial direction of the element\n * @returns { { ref: StateRef<Target> } & UseTextDirectionReturn } An object containing the current text direction of the element\n *\n * @example\n * const { ref, value, set, remove } = useTextDirection();\n */\nexport const useTextDirection = ((...params: any[]) => {\n const target = (isTarget(params[0]) ? params[0] : undefined) as HookTarget | undefined;\n const initialValue = ((target ? params[1] : params[0]) as UseTextDirectionValue) ?? 'ltr';\n\n const internalRef = useRefState<Element>();\n\n const getDirection = () => {\n const element = (target ? getElement(target) : internalRef.current) as Element;\n return (element?.getAttribute('dir') as UseTextDirectionValue) ?? initialValue;\n };\n\n const [value, setValue] = useState<UseTextDirectionValue>(getDirection());\n\n const remove = () => {\n const element = (target ? getElement(target) : internalRef.current) as Element;\n if (!element) return;\n\n element?.removeAttribute('dir');\n };\n\n const set = (value: UseTextDirectionValue) => {\n const element = (target ? getElement(target) : internalRef.current) as Element;\n if (!element) return;\n\n setValue(value);\n element.setAttribute('dir', value);\n };\n\n useIsomorphicLayoutEffect(() => {\n if (!target && !internalRef.state) return;\n\n const element = (target ? getElement(target) : internalRef.current) as Element;\n if (!element) return;\n\n const direction = getDirection();\n element.setAttribute('dir', direction);\n setValue(direction);\n\n const observer = new MutationObserver(getDirection);\n\n observer.observe(element, { attributes: true });\n\n return () => {\n observer.disconnect();\n };\n }, [internalRef.state, target]);\n\n if (target) return { value, set, remove };\n return {\n ref: internalRef,\n value,\n set,\n remove\n };\n}) as UseTextDirection;\n"],"names":["useTextDirection","params","target","isTarget","initialValue","internalRef","useRefState","getDirection","getElement","value","setValue","useState","remove","element","set","useIsomorphicLayoutEffect","direction","observer"],"mappings":";;;;;AAsDO,MAAMA,IAAoB,IAAIC,MAAkB;AACrD,QAAMC,IAAUC,EAASF,EAAO,CAAC,CAAC,IAAIA,EAAO,CAAC,IAAI,QAC5CG,KAAiBF,IAASD,EAAO,CAAC,IAAIA,EAAO,CAAC,MAAgC,OAE9EI,IAAcC,EAAA,GAEdC,IAAe,OACFL,IAASM,EAAWN,CAAM,IAAIG,EAAY,UAC1C,aAAa,KAAK,KAA+BD,GAG9D,CAACK,GAAOC,CAAQ,IAAIC,EAAgCJ,GAAc,GAElEK,IAAS,MAAM;AACnB,UAAMC,IAAWX,IAASM,EAAWN,CAAM,IAAIG,EAAY;AAC3D,IAAKQ,KAELA,GAAS,gBAAgB,KAAK;AAAA,EAAA,GAG1BC,IAAM,CAACL,MAAiC;AAC5C,UAAMI,IAAWX,IAASM,EAAWN,CAAM,IAAIG,EAAY;AAC3D,IAAKQ,MAELH,EAASD,CAAK,GACdI,EAAQ,aAAa,OAAOJ,CAAK;AAAA,EAAA;AAsBnC,SAnBAM,EAA0B,MAAM;AAC9B,QAAI,CAACb,KAAU,CAACG,EAAY,MAAO;AAEnC,UAAMQ,IAAWX,IAASM,EAAWN,CAAM,IAAIG,EAAY;AAC3D,QAAI,CAACQ,EAAS;AAEd,UAAMG,IAAYT,EAAA;AAClB,IAAAM,EAAQ,aAAa,OAAOG,CAAS,GACrCN,EAASM,CAAS;AAElB,UAAMC,IAAW,IAAI,iBAAiBV,CAAY;AAElD,WAAAU,EAAS,QAAQJ,GAAS,EAAE,YAAY,IAAM,GAEvC,MAAM;AACX,MAAAI,EAAS,WAAA;AAAA,IAAW;AAAA,EACtB,GACC,CAACZ,EAAY,OAAOH,CAAM,CAAC,GAE1BA,IAAe,EAAE,OAAAO,GAAO,KAAAK,GAAK,QAAAF,EAAA,IAC1B;AAAA,IACL,KAAKP;AAAA,IACL,OAAAI;AAAA,IACA,KAAAK;AAAA,IACA,QAAAF;AAAA,EAAA;AAEJ;"}
|