@siberiacancode/reactuse 0.2.25 → 0.2.26
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/dist/cjs/helpers/createStore/createStore.cjs +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/useAutoScroll/useAutoScroll.cjs.map +1 -1
- package/dist/cjs/hooks/useBoolean/useBoolean.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/useCookie/useCookie.cjs.map +1 -1
- package/dist/cjs/hooks/useCookies/useCookies.cjs.map +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/useDefault/useDefault.cjs.map +1 -1
- package/dist/cjs/hooks/useDisclosure/useDisclosure.cjs.map +1 -1
- package/dist/cjs/hooks/useDisplayMedia/useDisplayMedia.cjs.map +1 -1
- package/dist/cjs/hooks/useDocumentTitle/useDocumentTitle.cjs.map +1 -1
- package/dist/cjs/hooks/useDoubleClick/useDoubleClick.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/useEventSource/useEventSource.cjs.map +1 -1
- package/dist/cjs/hooks/useField/useField.cjs.map +1 -1
- package/dist/cjs/hooks/useFileDialog/useFileDialog.cjs.map +1 -1
- package/dist/cjs/hooks/useFocus/useFocus.cjs.map +1 -1
- package/dist/cjs/hooks/useFps/useFps.cjs.map +1 -1
- package/dist/cjs/hooks/useHash/useHash.cjs.map +1 -1
- package/dist/cjs/hooks/useHover/useHover.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/useLastChanged/useLastChanged.cjs.map +1 -1
- package/dist/cjs/hooks/useList/useList.cjs.map +1 -1
- package/dist/cjs/hooks/useLocalStorage/useLocalStorage.cjs.map +1 -1
- package/dist/cjs/hooks/useLockCallback/useLockCallback.cjs.map +1 -1
- package/dist/cjs/hooks/useLockScroll/useLockScroll.cjs +2 -0
- package/dist/cjs/hooks/useLockScroll/useLockScroll.cjs.map +1 -0
- package/dist/cjs/hooks/useLogger/useLogger.cjs.map +1 -1
- package/dist/cjs/hooks/useLongPress/useLongPress.cjs.map +1 -1
- package/dist/cjs/hooks/useMap/useMap.cjs.map +1 -1
- package/dist/cjs/hooks/useMutation/useMutation.cjs.map +1 -1
- package/dist/cjs/hooks/useMutationObserver/useMutationObserver.cjs.map +1 -1
- package/dist/cjs/hooks/useNetwork/useNetwork.cjs.map +1 -1
- package/dist/cjs/hooks/useOffsetPagination/useOffsetPagination.cjs.map +1 -1
- package/dist/cjs/hooks/useOnline/useOnline.cjs.map +1 -1
- package/dist/cjs/hooks/useOperatingSystem/useOperatingSystem.cjs.map +1 -1
- package/dist/cjs/hooks/useOptimistic/useOptimistic.cjs.map +1 -1
- package/dist/cjs/hooks/useOrientation/useOrientation.cjs +1 -1
- package/dist/cjs/hooks/useOrientation/useOrientation.cjs.map +1 -1
- package/dist/cjs/hooks/usePaint/usePaint.cjs.map +1 -1
- package/dist/cjs/hooks/useParallax/useParallax.cjs +1 -1
- package/dist/cjs/hooks/useParallax/useParallax.cjs.map +1 -1
- package/dist/cjs/hooks/usePointerLock/usePointerLock.cjs.map +1 -1
- package/dist/cjs/hooks/usePreferredColorScheme/usePreferredColorScheme.cjs.map +1 -1
- package/dist/cjs/hooks/usePreferredContrast/usePreferredContrast.cjs.map +1 -1
- package/dist/cjs/hooks/usePreferredDark/usePreferredDark.cjs.map +1 -1
- package/dist/cjs/hooks/usePreferredLanguages/usePreferredLanguages.cjs.map +1 -1
- package/dist/cjs/hooks/usePreferredReducedMotion/usePreferredReducedMotion.cjs.map +1 -1
- package/dist/cjs/hooks/useQuery/useQuery.cjs.map +1 -1
- package/dist/cjs/hooks/useQueue/useQueue.cjs.map +1 -1
- package/dist/cjs/hooks/useRaf/useRaf.cjs.map +1 -1
- package/dist/cjs/hooks/{useRafValue/useRafValue.cjs → useRafState/useRafState.cjs} +2 -2
- package/dist/cjs/hooks/useRafState/useRafState.cjs.map +1 -0
- 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.map +1 -1
- package/dist/cjs/hooks/useScript/useScript.cjs.map +1 -1
- package/dist/cjs/hooks/useScroll/useScroll.cjs.map +1 -1
- package/dist/cjs/hooks/useSessionStorage/useSessionStorage.cjs.map +1 -1
- package/dist/cjs/hooks/useSet/useSet.cjs.map +1 -1
- package/dist/cjs/hooks/useSpeechRecognition/useSpeechRecognition.cjs.map +1 -1
- package/dist/cjs/hooks/useSpeechSynthesis/useSpeechSynthesis.cjs.map +1 -1
- package/dist/cjs/hooks/useStateHistory/useStateHistory.cjs.map +1 -1
- package/dist/cjs/hooks/useStep/useStep.cjs.map +1 -1
- package/dist/cjs/hooks/useSticky/useSticky.cjs.map +1 -1
- package/dist/cjs/hooks/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/useToggle/useToggle.cjs.map +1 -1
- package/dist/cjs/hooks/useUrlSearchParam/useUrlSearchParam.cjs.map +1 -1
- package/dist/cjs/hooks/useUrlSearchParams/useUrlSearchParams.cjs.map +1 -1
- package/dist/cjs/hooks/useWizard/useWizard.cjs.map +1 -1
- package/dist/cjs/index.cjs +1 -1
- package/dist/esm/helpers/createStore/createStore.mjs +16 -16
- package/dist/esm/helpers/createStore/createStore.mjs.map +1 -1
- package/dist/esm/hooks/useActiveElement/useActiveElement.mjs +9 -10
- package/dist/esm/hooks/useActiveElement/useActiveElement.mjs.map +1 -1
- package/dist/esm/hooks/useAsync/useAsync.mjs.map +1 -1
- package/dist/esm/hooks/useAutoScroll/useAutoScroll.mjs.map +1 -1
- package/dist/esm/hooks/useBoolean/useBoolean.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/useCookie/useCookie.mjs.map +1 -1
- package/dist/esm/hooks/useCookies/useCookies.mjs.map +1 -1
- package/dist/esm/hooks/useCounter/useCounter.mjs.map +1 -1
- package/dist/esm/hooks/useCssVar/useCssVar.mjs +27 -24
- package/dist/esm/hooks/useCssVar/useCssVar.mjs.map +1 -1
- package/dist/esm/hooks/useDefault/useDefault.mjs.map +1 -1
- package/dist/esm/hooks/useDisclosure/useDisclosure.mjs.map +1 -1
- package/dist/esm/hooks/useDisplayMedia/useDisplayMedia.mjs.map +1 -1
- package/dist/esm/hooks/useDocumentTitle/useDocumentTitle.mjs +3 -1
- package/dist/esm/hooks/useDocumentTitle/useDocumentTitle.mjs.map +1 -1
- package/dist/esm/hooks/useDoubleClick/useDoubleClick.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/useEventSource/useEventSource.mjs +3 -1
- package/dist/esm/hooks/useEventSource/useEventSource.mjs.map +1 -1
- package/dist/esm/hooks/useField/useField.mjs.map +1 -1
- package/dist/esm/hooks/useFileDialog/useFileDialog.mjs.map +1 -1
- package/dist/esm/hooks/useFocus/useFocus.mjs.map +1 -1
- package/dist/esm/hooks/useFps/useFps.mjs.map +1 -1
- package/dist/esm/hooks/useHash/useHash.mjs.map +1 -1
- package/dist/esm/hooks/useHover/useHover.mjs.map +1 -1
- package/dist/esm/hooks/useImage/useImage.mjs.map +1 -1
- package/dist/esm/hooks/useInfiniteScroll/useInfiniteScroll.mjs +27 -27
- package/dist/esm/hooks/useInfiniteScroll/useInfiniteScroll.mjs.map +1 -1
- package/dist/esm/hooks/useIntersectionObserver/useIntersectionObserver.mjs +5 -5
- package/dist/esm/hooks/useIntersectionObserver/useIntersectionObserver.mjs.map +1 -1
- package/dist/esm/hooks/useLastChanged/useLastChanged.mjs.map +1 -1
- package/dist/esm/hooks/useList/useList.mjs +15 -6
- package/dist/esm/hooks/useList/useList.mjs.map +1 -1
- package/dist/esm/hooks/useLocalStorage/useLocalStorage.mjs.map +1 -1
- package/dist/esm/hooks/useLockCallback/useLockCallback.mjs.map +1 -1
- package/dist/esm/hooks/useLockScroll/useLockScroll.mjs +44 -0
- package/dist/esm/hooks/useLockScroll/useLockScroll.mjs.map +1 -0
- package/dist/esm/hooks/useLogger/useLogger.mjs.map +1 -1
- package/dist/esm/hooks/useLongPress/useLongPress.mjs.map +1 -1
- package/dist/esm/hooks/useMap/useMap.mjs.map +1 -1
- package/dist/esm/hooks/useMutation/useMutation.mjs.map +1 -1
- package/dist/esm/hooks/useMutationObserver/useMutationObserver.mjs.map +1 -1
- package/dist/esm/hooks/useNetwork/useNetwork.mjs.map +1 -1
- package/dist/esm/hooks/useOffsetPagination/useOffsetPagination.mjs.map +1 -1
- package/dist/esm/hooks/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 +25 -9
- package/dist/esm/hooks/useOrientation/useOrientation.mjs.map +1 -1
- package/dist/esm/hooks/usePaint/usePaint.mjs +14 -2
- package/dist/esm/hooks/usePaint/usePaint.mjs.map +1 -1
- package/dist/esm/hooks/useParallax/useParallax.mjs +9 -9
- package/dist/esm/hooks/useParallax/useParallax.mjs.map +1 -1
- package/dist/esm/hooks/usePointerLock/usePointerLock.mjs.map +1 -1
- package/dist/esm/hooks/usePreferredColorScheme/usePreferredColorScheme.mjs.map +1 -1
- package/dist/esm/hooks/usePreferredContrast/usePreferredContrast.mjs.map +1 -1
- package/dist/esm/hooks/usePreferredDark/usePreferredDark.mjs.map +1 -1
- package/dist/esm/hooks/usePreferredLanguages/usePreferredLanguages.mjs.map +1 -1
- package/dist/esm/hooks/usePreferredReducedMotion/usePreferredReducedMotion.mjs.map +1 -1
- package/dist/esm/hooks/useQuery/useQuery.mjs.map +1 -1
- package/dist/esm/hooks/useQueue/useQueue.mjs.map +1 -1
- package/dist/esm/hooks/useRaf/useRaf.mjs.map +1 -1
- package/dist/esm/hooks/{useRafValue/useRafValue.mjs → useRafState/useRafState.mjs} +2 -2
- package/dist/esm/hooks/useRafState/useRafState.mjs.map +1 -0
- 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.map +1 -1
- package/dist/esm/hooks/useScript/useScript.mjs.map +1 -1
- package/dist/esm/hooks/useScroll/useScroll.mjs.map +1 -1
- package/dist/esm/hooks/useSessionStorage/useSessionStorage.mjs.map +1 -1
- package/dist/esm/hooks/useSet/useSet.mjs.map +1 -1
- package/dist/esm/hooks/useSpeechRecognition/useSpeechRecognition.mjs +14 -4
- package/dist/esm/hooks/useSpeechRecognition/useSpeechRecognition.mjs.map +1 -1
- package/dist/esm/hooks/useSpeechSynthesis/useSpeechSynthesis.mjs.map +1 -1
- package/dist/esm/hooks/useStateHistory/useStateHistory.mjs.map +1 -1
- package/dist/esm/hooks/useStep/useStep.mjs.map +1 -1
- package/dist/esm/hooks/useSticky/useSticky.mjs.map +1 -1
- package/dist/esm/hooks/useStorage/useStorage.mjs.map +1 -1
- package/dist/esm/hooks/useTextDirection/useTextDirection.mjs +19 -20
- package/dist/esm/hooks/useTextDirection/useTextDirection.mjs.map +1 -1
- package/dist/esm/hooks/useToggle/useToggle.mjs.map +1 -1
- package/dist/esm/hooks/useUrlSearchParam/useUrlSearchParam.mjs.map +1 -1
- package/dist/esm/hooks/useUrlSearchParams/useUrlSearchParams.mjs.map +1 -1
- package/dist/esm/hooks/useWizard/useWizard.mjs.map +1 -1
- package/dist/esm/index.mjs +323 -323
- package/dist/types/helpers/createStore/createStore.d.ts +1 -1
- package/dist/types/hooks/async.d.ts +5 -0
- package/dist/types/hooks/browser.d.ts +32 -0
- package/dist/types/hooks/debug.d.ts +4 -0
- package/dist/types/hooks/elements.d.ts +14 -0
- package/dist/types/hooks/fun.d.ts +3 -0
- package/dist/types/hooks/index.d.ts +11 -143
- package/dist/types/hooks/lifecycle.d.ts +6 -0
- package/dist/types/hooks/sensors.d.ts +34 -0
- package/dist/types/hooks/state.d.ts +25 -0
- package/dist/types/hooks/time.d.ts +5 -0
- package/dist/types/hooks/useAsync/useAsync.d.ts +1 -1
- package/dist/types/hooks/useAutoScroll/useAutoScroll.d.ts +1 -1
- package/dist/types/hooks/useBoolean/useBoolean.d.ts +1 -1
- package/dist/types/hooks/useBrowserLanguage/useBrowserLanguage.d.ts +1 -1
- package/dist/types/hooks/useClickOutside/useClickOutside.d.ts +1 -1
- package/dist/types/hooks/useCookie/useCookie.d.ts +1 -1
- package/dist/types/hooks/useCookies/useCookies.d.ts +1 -1
- package/dist/types/hooks/useCounter/useCounter.d.ts +1 -1
- package/dist/types/hooks/useCssVar/useCssVar.d.ts +1 -1
- package/dist/types/hooks/useDefault/useDefault.d.ts +1 -1
- package/dist/types/hooks/useDisclosure/useDisclosure.d.ts +1 -1
- package/dist/types/hooks/useDocumentTitle/useDocumentTitle.d.ts +2 -0
- package/dist/types/hooks/useDoubleClick/useDoubleClick.d.ts +1 -1
- package/dist/types/hooks/useEvent/useEvent.d.ts +1 -1
- package/dist/types/hooks/useField/useField.d.ts +1 -1
- package/dist/types/hooks/useFileDialog/useFileDialog.d.ts +1 -1
- package/dist/types/hooks/useFocus/useFocus.d.ts +1 -1
- package/dist/types/hooks/useFps/useFps.d.ts +1 -1
- package/dist/types/hooks/useHash/useHash.d.ts +1 -1
- package/dist/types/hooks/useHover/useHover.d.ts +1 -1
- package/dist/types/hooks/useImage/useImage.d.ts +1 -1
- package/dist/types/hooks/useIntersectionObserver/useIntersectionObserver.d.ts +7 -6
- package/dist/types/hooks/useLastChanged/useLastChanged.d.ts +1 -1
- package/dist/types/hooks/useList/useList.d.ts +1 -1
- package/dist/types/hooks/useLocalStorage/useLocalStorage.d.ts +1 -1
- package/dist/types/hooks/useLockCallback/useLockCallback.d.ts +1 -1
- package/dist/types/hooks/useLockScroll/useLockScroll.d.ts +49 -0
- package/dist/types/hooks/useLogger/useLogger.d.ts +1 -1
- package/dist/types/hooks/useLongPress/useLongPress.d.ts +1 -1
- package/dist/types/hooks/useMap/useMap.d.ts +1 -1
- package/dist/types/hooks/useMutation/useMutation.d.ts +1 -1
- package/dist/types/hooks/useMutationObserver/useMutationObserver.d.ts +1 -1
- package/dist/types/hooks/useNetwork/useNetwork.d.ts +1 -1
- package/dist/types/hooks/useOffsetPagination/useOffsetPagination.d.ts +1 -1
- package/dist/types/hooks/useOnline/useOnline.d.ts +1 -1
- package/dist/types/hooks/useOperatingSystem/useOperatingSystem.d.ts +1 -1
- package/dist/types/hooks/useOptimistic/useOptimistic.d.ts +1 -1
- package/dist/types/hooks/useOrientation/useOrientation.d.ts +26 -11
- package/dist/types/hooks/usePaint/usePaint.d.ts +1 -1
- package/dist/types/hooks/usePointerLock/usePointerLock.d.ts +1 -1
- package/dist/types/hooks/usePreferredColorScheme/usePreferredColorScheme.d.ts +1 -1
- package/dist/types/hooks/usePreferredContrast/usePreferredContrast.d.ts +1 -1
- package/dist/types/hooks/usePreferredDark/usePreferredDark.d.ts +1 -1
- package/dist/types/hooks/usePreferredLanguages/usePreferredLanguages.d.ts +1 -1
- package/dist/types/hooks/usePreferredReducedMotion/usePreferredReducedMotion.d.ts +1 -1
- package/dist/types/hooks/useQuery/useQuery.d.ts +1 -1
- package/dist/types/hooks/useQueue/useQueue.d.ts +1 -1
- package/dist/types/hooks/useRaf/useRaf.d.ts +1 -1
- package/dist/types/hooks/{useRafValue/useRafValue.d.ts → useRafState/useRafState.d.ts} +6 -6
- package/dist/types/hooks/useRefState/useRefState.d.ts +1 -1
- package/dist/types/hooks/useRenderCount/useRenderCount.d.ts +1 -1
- package/dist/types/hooks/useRenderInfo/useRenderInfo.d.ts +6 -1
- package/dist/types/hooks/useRerender/useRerender.d.ts +1 -1
- package/dist/types/hooks/useResizeObserver/useResizeObserver.d.ts +1 -1
- package/dist/types/hooks/useRightClick/useRightClick.d.ts +37 -0
- package/dist/types/hooks/useScript/useScript.d.ts +1 -1
- package/dist/types/hooks/useSessionStorage/useSessionStorage.d.ts +1 -1
- package/dist/types/hooks/useSet/useSet.d.ts +1 -1
- package/dist/types/hooks/useSpeechRecognition/useSpeechRecognition.d.ts +1 -1
- package/dist/types/hooks/useSpeechSynthesis/useSpeechSynthesis.d.ts +1 -1
- package/dist/types/hooks/useStateHistory/useStateHistory.d.ts +1 -1
- package/dist/types/hooks/useStep/useStep.d.ts +1 -1
- package/dist/types/hooks/useSticky/useSticky.d.ts +1 -1
- package/dist/types/hooks/useStorage/useStorage.d.ts +1 -1
- package/dist/types/hooks/useTextDirection/useTextDirection.d.ts +2 -2
- package/dist/types/hooks/useToggle/useToggle.d.ts +1 -1
- package/dist/types/hooks/useUrlSearchParam/useUrlSearchParam.d.ts +1 -1
- package/dist/types/hooks/useUrlSearchParams/useUrlSearchParams.d.ts +1 -1
- package/dist/types/hooks/useWizard/useWizard.d.ts +1 -1
- package/dist/types/hooks/user.d.ts +7 -0
- package/dist/types/hooks/utilities.d.ts +9 -0
- package/dist/types/utils/helpers/getElement.d.ts +1 -1
- package/package.json +89 -89
- package/dist/cjs/hooks/useRafValue/useRafValue.cjs.map +0 -1
- package/dist/cjs/hooks/useScreenOrientation/useScreenOrientation.cjs +0 -2
- package/dist/cjs/hooks/useScreenOrientation/useScreenOrientation.cjs.map +0 -1
- package/dist/esm/hooks/useRafValue/useRafValue.mjs.map +0 -1
- package/dist/esm/hooks/useScreenOrientation/useScreenOrientation.mjs +0 -31
- package/dist/esm/hooks/useScreenOrientation/useScreenOrientation.mjs.map +0 -1
- package/dist/types/hooks/useScreenOrientation/useScreenOrientation.d.ts +0 -35
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useQueue.mjs","sources":["../../../../src/hooks/useQueue/useQueue.ts"],"sourcesContent":["import { useState } from 'react';\nimport { flushSync } from 'react-dom';\n\n/** The use queue return type */\nexport interface UseQueueReturn<Value> {\n /** Get the first element of the queue */\n first: Value;\n /** Get the last element of the queue */\n last: Value;\n /** The current queue */\n queue: Value[];\n /** Get the size of the queue */\n size: number;\n /** Add an element to the queue */\n add: (element: Value) => void;\n /** Clear the queue */\n clear: () => void;\n /** Remove an element from the queue */\n remove: () => Value;\n}\n\n/**\n * @name useQueue\n * @description - Hook that manages a queue\n * @category
|
|
1
|
+
{"version":3,"file":"useQueue.mjs","sources":["../../../../src/hooks/useQueue/useQueue.ts"],"sourcesContent":["import { useState } from 'react';\nimport { flushSync } from 'react-dom';\n\n/** The use queue return type */\nexport interface UseQueueReturn<Value> {\n /** Get the first element of the queue */\n first: Value;\n /** Get the last element of the queue */\n last: Value;\n /** The current queue */\n queue: Value[];\n /** Get the size of the queue */\n size: number;\n /** Add an element to the queue */\n add: (element: Value) => void;\n /** Clear the queue */\n clear: () => void;\n /** Remove an element from the queue */\n remove: () => Value;\n}\n\n/**\n * @name useQueue\n * @description - Hook that manages a queue\n * @category State\n *\n * @template Value The type of the value\n * @param {Value[]} [initialValue=[]] The initial value of the queue\n * @returns {UseQueueReturn} An object containing the current queue and functions to interact with the queue\n *\n * @example\n * const { queue, add, remove, clear, first, last, size } = useQueue([1, 2, 3]);\n */\nexport const useQueue = <Value>(initialValue: Value[] = []): UseQueueReturn<Value> => {\n const [queue, setQueue] = useState(initialValue);\n\n const add = (element: Value) => setQueue((queue) => [...queue, element]);\n const clear = () => setQueue([]);\n const remove = () => {\n let removed;\n flushSync(() => {\n setQueue(([first, ...rest]) => {\n removed = first;\n return rest;\n });\n });\n\n return removed as Value;\n };\n\n return {\n add,\n remove,\n clear,\n first: queue[0],\n last: queue[queue.length - 1],\n size: queue.length,\n queue\n };\n};\n"],"names":["useQueue","initialValue","queue","setQueue","useState","element","removed","flushSync","first","rest"],"mappings":";;AAiCO,MAAMA,IAAW,CAAQC,IAAwB,OAA8B;AACpF,QAAM,CAACC,GAAOC,CAAQ,IAAIC,EAASH,CAAY;AAgB/C,SAAO;AAAA,IACL,KAfU,CAACI,MAAmBF,EAAS,CAACD,MAAU,CAAC,GAAGA,GAAOG,CAAO,CAAC;AAAA,IAgBrE,QAda,MAAM;AACnB,UAAIC;AACJ,aAAAC,EAAU,MAAM;AACd,QAAAJ,EAAS,CAAC,CAACK,GAAU,GAAAC,CAAI,OACvBH,IAAUE,GACHC,EACR;AAAA,MAAA,CACF,GAEMH;AAAA,IAAA;AAAA,IAMP,OAhBY,MAAMH,EAAS,EAAE;AAAA,IAiB7B,OAAOD,EAAM,CAAC;AAAA,IACd,MAAMA,EAAMA,EAAM,SAAS,CAAC;AAAA,IAC5B,MAAMA,EAAM;AAAA,IACZ,OAAAA;AAAA,EAAA;AAEJ;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRaf.mjs","sources":["../../../../src/hooks/useRaf/useRaf.ts"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\n\n/* The use raf params type */\nexport interface UseRafParams {\n /** The delta between each frame in milliseconds */\n delta: number;\n /** The timestamp of the current frame in milliseconds */\n timestamp: DOMHighResTimeStamp;\n}\n\n/* The use raf type */\nexport type UseRafCallback = (params: UseRafParams) => void;\n\n/* The use raf options type */\nexport interface UseRafOptions {\n /** The delay between each frame in milliseconds */\n delay?: number;\n /** Whether the callback should be enabled */\n enabled?: boolean;\n}\n\n/* The use raf return type */\nexport interface UseRafReturn {\n /** Whether the callback is active */\n active: boolean;\n /** Function to pause the callback */\n pause: () => void;\n /** Function to resume the callback */\n resume: () => void;\n}\n\n/**\n * @name useRaf\n * @description - Hook that defines the logic for raf callback\n * @category
|
|
1
|
+
{"version":3,"file":"useRaf.mjs","sources":["../../../../src/hooks/useRaf/useRaf.ts"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\n\n/* The use raf params type */\nexport interface UseRafParams {\n /** The delta between each frame in milliseconds */\n delta: number;\n /** The timestamp of the current frame in milliseconds */\n timestamp: DOMHighResTimeStamp;\n}\n\n/* The use raf type */\nexport type UseRafCallback = (params: UseRafParams) => void;\n\n/* The use raf options type */\nexport interface UseRafOptions {\n /** The delay between each frame in milliseconds */\n delay?: number;\n /** Whether the callback should be enabled */\n enabled?: boolean;\n}\n\n/* The use raf return type */\nexport interface UseRafReturn {\n /** Whether the callback is active */\n active: boolean;\n /** Function to pause the callback */\n pause: () => void;\n /** Function to resume the callback */\n resume: () => void;\n}\n\n/**\n * @name useRaf\n * @description - Hook that defines the logic for raf callback\n * @category Browser\n *\n * @browserapi requestAnimationFrame https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame\n *\n * @param {UseRafCallback} callback The callback to execute\n * @param {number} [options.delay] The delay between each frame in milliseconds\n * @param {boolean} [options.enabled=true] Whether the callback should be enabled\n * @returns {UseRafCallbackReturn} An object of raf callback functions\n *\n * @example\n * useRaf(() => console.log('callback'));\n */\nexport const useRaf = (callback: UseRafCallback, options?: UseRafOptions): UseRafReturn => {\n const rafIdRef = useRef<number | null>(null);\n const previousFrameTimestampRef = useRef(0);\n const [active, setActive] = useState(false);\n const enabled = options?.enabled ?? true;\n\n const internalCallbackRef = useRef(callback);\n internalCallbackRef.current = callback;\n\n const loop = (timestamp: DOMHighResTimeStamp) => {\n const delta = timestamp - previousFrameTimestampRef.current;\n\n if (options?.delay && delta < options?.delay) {\n rafIdRef.current = window.requestAnimationFrame(loop);\n return;\n }\n\n previousFrameTimestampRef.current = timestamp;\n internalCallbackRef.current({ delta, timestamp });\n rafIdRef.current = window.requestAnimationFrame(loop);\n };\n\n const resume = () => {\n if (active) return;\n setActive(true);\n previousFrameTimestampRef.current = 0;\n rafIdRef.current = window.requestAnimationFrame(loop);\n };\n\n function pause() {\n if (!rafIdRef.current) return;\n\n setActive(false);\n window.cancelAnimationFrame(rafIdRef.current);\n rafIdRef.current = null;\n }\n\n useEffect(() => {\n if (!enabled) return;\n resume();\n\n return pause;\n }, [enabled, options?.delay]);\n\n return {\n active,\n pause,\n resume\n };\n};\n"],"names":["useRaf","callback","options","rafIdRef","useRef","previousFrameTimestampRef","active","setActive","useState","enabled","internalCallbackRef","loop","timestamp","delta","resume","pause","useEffect"],"mappings":";AA8CO,MAAMA,IAAS,CAACC,GAA0BC,MAA0C;AACzF,QAAMC,IAAWC,EAAsB,IAAI,GACrCC,IAA4BD,EAAO,CAAC,GACpC,CAACE,GAAQC,CAAS,IAAIC,EAAS,EAAK,GACpCC,IAAUP,GAAS,WAAW,IAE9BQ,IAAsBN,EAAOH,CAAQ;AAC3C,EAAAS,EAAoB,UAAUT;AAE9B,QAAMU,IAAO,CAACC,MAAmC;AAC/C,UAAMC,IAAQD,IAAYP,EAA0B;AAEpD,QAAIH,GAAS,SAASW,IAAQX,GAAS,OAAO;AAC5C,MAAAC,EAAS,UAAU,OAAO,sBAAsBQ,CAAI;AACpD;AAAA,IAAA;AAGF,IAAAN,EAA0B,UAAUO,GACpCF,EAAoB,QAAQ,EAAE,OAAAG,GAAO,WAAAD,EAAA,CAAW,GAChDT,EAAS,UAAU,OAAO,sBAAsBQ,CAAI;AAAA,EAAA,GAGhDG,IAAS,MAAM;AACnB,IAAIR,MACJC,EAAU,EAAI,GACdF,EAA0B,UAAU,GACpCF,EAAS,UAAU,OAAO,sBAAsBQ,CAAI;AAAA,EAAA;AAGtD,WAASI,IAAQ;AACf,IAAKZ,EAAS,YAEdI,EAAU,EAAK,GACf,OAAO,qBAAqBJ,EAAS,OAAO,GAC5CA,EAAS,UAAU;AAAA,EAAA;AAGrB,SAAAa,EAAU,MAAM;AACd,QAAKP;AACL,aAAAK,EAAA,GAEOC;AAAA,EAAA,GACN,CAACN,GAASP,GAAS,KAAK,CAAC,GAErB;AAAA,IACL,QAAAI;AAAA,IACA,OAAAS;AAAA,IACA,QAAAD;AAAA,EAAA;AAEJ;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useRafState.mjs","sources":["../../../../src/hooks/useRafState/useRafState.ts"],"sourcesContent":["import { useRef, useState } from 'react';\n\nimport { useUnmount } from '../useUnmount/useUnmount';\n\n/* The use raf value params type */\nexport type UseRafStateReturn<Value> = [Value, (value: Value) => void];\n\n/**\n * @name useRafState\n * @description - Hook that returns the value and a function to set the value\n * @category State\n *\n * @template Value The type of the value\n * @param {Value} initialValue The initial value\n * @returns {UseRafStateReturn<Value>} An array containing the value and a function to set the value\n *\n * @example\n * const [value, setValue] = useRafState(initialValue);\n */\nexport const useRafState = <Value>(initialValue: (() => Value) | Value) => {\n const rafIdRef = useRef(0);\n const [value, setValue] = useState(initialValue);\n\n const set = (value: Value) => {\n cancelAnimationFrame(rafIdRef.current);\n rafIdRef.current = requestAnimationFrame(() => setValue(value));\n };\n\n useUnmount(() => cancelAnimationFrame(rafIdRef.current));\n\n return [value, set] as const;\n};\n"],"names":["useRafState","initialValue","rafIdRef","useRef","value","setValue","useState","set","useUnmount"],"mappings":";;AAmBO,MAAMA,IAAc,CAAQC,MAAwC;AACzE,QAAMC,IAAWC,EAAO,CAAC,GACnB,CAACC,GAAOC,CAAQ,IAAIC,EAASL,CAAY,GAEzCM,IAAM,CAACH,MAAiB;AAC5B,yBAAqBF,EAAS,OAAO,GACrCA,EAAS,UAAU,sBAAsB,MAAMG,EAASD,CAAK,CAAC;AAAA,EAAA;AAGhE,SAAAI,EAAW,MAAM,qBAAqBN,EAAS,OAAO,CAAC,GAEhD,CAACE,GAAOG,CAAG;AACpB;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRefState.mjs","sources":["../../../../src/hooks/useRefState/useRefState.ts"],"sourcesContent":["import { useState } from 'react';\n\nexport interface StateRef<Value> {\n (node: Value): void;\n current: Value;\n state?: Value;\n}\n\nconst createRefState = <Value>(\n initialValue: Value | undefined,\n setState: (value: Value) => void\n) => {\n let temp = initialValue;\n function ref(value: Value) {\n if (temp === value) return;\n temp = value;\n setState(temp);\n }\n\n Object.defineProperty(ref, 'current', {\n get() {\n return temp;\n },\n set(value: Value) {\n if (temp === value) return;\n temp = value;\n setState(temp);\n },\n configurable: true,\n enumerable: true\n });\n\n return ref as StateRef<Value>;\n};\n\n/**\n * @name useRefState\n * @description - Hook that returns the state reference of the value\n * @category
|
|
1
|
+
{"version":3,"file":"useRefState.mjs","sources":["../../../../src/hooks/useRefState/useRefState.ts"],"sourcesContent":["import { useState } from 'react';\n\nexport interface StateRef<Value> {\n (node: Value): void;\n current: Value;\n state?: Value;\n}\n\nconst createRefState = <Value>(\n initialValue: Value | undefined,\n setState: (value: Value) => void\n) => {\n let temp = initialValue;\n function ref(value: Value) {\n if (temp === value) return;\n temp = value;\n setState(temp);\n }\n\n Object.defineProperty(ref, 'current', {\n get() {\n return temp;\n },\n set(value: Value) {\n if (temp === value) return;\n temp = value;\n setState(temp);\n },\n configurable: true,\n enumerable: true\n });\n\n return ref as StateRef<Value>;\n};\n\n/**\n * @name useRefState\n * @description - Hook that returns the state reference of the value\n * @category State\n *\n * @template Value The type of the value\n * @param {Value} [initialValue] The initial value\n * @returns {StateRef<Value>} The current value\n *\n * @example\n * const internalRefState = useRefState();\n */\nexport const useRefState = <Value>(initialValue?: Value) => {\n const [state, setState] = useState<Value | undefined>(initialValue);\n const [ref] = useState(() => createRefState<Value>(initialValue, setState));\n ref.state = state;\n return ref;\n};\n"],"names":["createRefState","initialValue","setState","temp","ref","value","useRefState","state","useState"],"mappings":";AAQA,MAAMA,IAAiB,CACrBC,GACAC,MACG;AACH,MAAIC,IAAOF;AACX,WAASG,EAAIC,GAAc;AACzB,IAAIF,MAASE,MACbF,IAAOE,GACPH,EAASC,CAAI;AAAA,EAAA;AAGf,gBAAO,eAAeC,GAAK,WAAW;AAAA,IACpC,MAAM;AACJ,aAAOD;AAAA,IAAA;AAAA,IAET,IAAIE,GAAc;AAChB,MAAIF,MAASE,MACbF,IAAOE,GACPH,EAASC,CAAI;AAAA,IAAA;AAAA,IAEf,cAAc;AAAA,IACd,YAAY;AAAA,EAAA,CACb,GAEMC;AACT,GAcaE,IAAc,CAAQL,MAAyB;AAC1D,QAAM,CAACM,GAAOL,CAAQ,IAAIM,EAA4BP,CAAY,GAC5D,CAACG,CAAG,IAAII,EAAS,MAAMR,EAAsBC,GAAcC,CAAQ,CAAC;AAC1E,SAAAE,EAAI,QAAQG,GACLH;AACT;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRenderCount.mjs","sources":["../../../../src/hooks/useRenderCount/useRenderCount.ts"],"sourcesContent":["import { useEffect, useRef } from 'react';\n\n/**\n * @name useRenderCount\n * @description - Hook returns count component render times\n * @category
|
|
1
|
+
{"version":3,"file":"useRenderCount.mjs","sources":["../../../../src/hooks/useRenderCount/useRenderCount.ts"],"sourcesContent":["import { useEffect, useRef } from 'react';\n\n/**\n * @name useRenderCount\n * @description - Hook returns count component render times\n * @category Debug\n *\n * @returns {number} A number which determines how many times component renders\n *\n * @example\n * const renderCount = useRenderCount();\n */\nexport const useRenderCount = () => {\n const renderCountRef = useRef(0);\n\n useEffect(() => {\n renderCountRef.current += 1;\n });\n\n return renderCountRef.current;\n};\n"],"names":["useRenderCount","renderCountRef","useRef","useEffect"],"mappings":";AAYO,MAAMA,IAAiB,MAAM;AAClC,QAAMC,IAAiBC,EAAO,CAAC;AAE/B,SAAAC,EAAU,MAAM;AACd,IAAAF,EAAe,WAAW;AAAA,EAAA,CAC3B,GAEMA,EAAe;AACxB;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRenderInfo.mjs","sources":["../../../../src/hooks/useRenderInfo/useRenderInfo.ts"],"sourcesContent":["import { useRef } from 'react';\n\nexport interface UseRenderInfoReturn {\n component: string;\n renders: number;\n sinceLast: number;\n timestamp: number | null;\n}\n\n/**\n * @name useRenderInfo\n * @description - Hook for getting information about component rerender\n * @category
|
|
1
|
+
{"version":3,"file":"useRenderInfo.mjs","sources":["../../../../src/hooks/useRenderInfo/useRenderInfo.ts"],"sourcesContent":["import { useRef } from 'react';\n\n/** The use render info return type */\nexport interface UseRenderInfoReturn {\n /** The name of the component */\n component: string;\n /** The number of renders */\n renders: number;\n /** The time since the last render */\n sinceLast: number;\n /** The timestamp of the render */\n timestamp: number | null;\n}\n\n/**\n * @name useRenderInfo\n * @description - Hook for getting information about component rerender\n * @category Debug\n *\n * @param {string} [name='Unknown'] Component name\n * @param {boolean} [log=true] Toggle logging\n * @returns {UseRenderInfoReturn} An object containing rerender information\n *\n * @example\n * const rerenderInfo = useRenderInfo('Component');\n */\nexport const useRenderInfo = (name: string = 'Unknown', log: boolean = true) => {\n const renderInfoRef = useRef<UseRenderInfoReturn>({\n component: name,\n renders: 0,\n timestamp: Date.now(),\n sinceLast: 0\n });\n const now = Date.now();\n\n renderInfoRef.current.renders += 1;\n renderInfoRef.current.sinceLast = renderInfoRef.current.timestamp\n ? now - renderInfoRef.current.timestamp\n : 0;\n renderInfoRef.current.timestamp = now;\n\n if (log) {\n console.group(`${name} info, render number: ${renderInfoRef.current.renders}`);\n console.log(`Timestamp: ${renderInfoRef.current.timestamp}`);\n console.log(`Since last render: ${renderInfoRef.current.sinceLast}`);\n console.log(`Renders: ${renderInfoRef.current.renders}`);\n console.dir(renderInfoRef.current);\n console.groupEnd();\n }\n\n return renderInfoRef.current;\n};\n"],"names":["useRenderInfo","name","log","renderInfoRef","useRef","now"],"mappings":";AA0BO,MAAMA,IAAgB,CAACC,IAAe,WAAWC,IAAe,OAAS;AAC9E,QAAMC,IAAgBC,EAA4B;AAAA,IAChD,WAAWH;AAAA,IACX,SAAS;AAAA,IACT,WAAW,KAAK,IAAA;AAAA,IAChB,WAAW;AAAA,EAAA,CACZ,GACKI,IAAM,KAAK,IAAA;AAEjB,SAAAF,EAAc,QAAQ,WAAW,GACjCA,EAAc,QAAQ,YAAYA,EAAc,QAAQ,YACpDE,IAAMF,EAAc,QAAQ,YAC5B,GACJA,EAAc,QAAQ,YAAYE,GAE9BH,MACF,QAAQ,MAAM,GAAGD,CAAI,yBAAyBE,EAAc,QAAQ,OAAO,EAAE,GAC7E,QAAQ,IAAI,cAAcA,EAAc,QAAQ,SAAS,EAAE,GAC3D,QAAQ,IAAI,sBAAsBA,EAAc,QAAQ,SAAS,EAAE,GACnE,QAAQ,IAAI,YAAYA,EAAc,QAAQ,OAAO,EAAE,GACvD,QAAQ,IAAIA,EAAc,OAAO,GACjC,QAAQ,SAAA,IAGHA,EAAc;AACvB;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRerender.mjs","sources":["../../../../src/hooks/useRerender/useRerender.ts"],"sourcesContent":["import { useReducer } from 'react';\n\n/** The use rerender return type */\ntype UseRerenderReturn = () => void;\n\n/**\n * @name useRerender\n * @description - Hook that defines the logic to force rerender a component\n * @category
|
|
1
|
+
{"version":3,"file":"useRerender.mjs","sources":["../../../../src/hooks/useRerender/useRerender.ts"],"sourcesContent":["import { useReducer } from 'react';\n\n/** The use rerender return type */\ntype UseRerenderReturn = () => void;\n\n/**\n * @name useRerender\n * @description - Hook that defines the logic to force rerender a component\n * @category Debug\n *\n * @returns {UseRerenderReturn} The rerender function\n *\n * @example\n * const rerender = useRerender();\n */\nexport const useRerender = (): UseRerenderReturn => useReducer(() => ({}), {})[1];\n"],"names":["useRerender","useReducer"],"mappings":";AAeO,MAAMA,IAAc,MAAyBC,EAAW,OAAO,CAAA,IAAK,CAAA,CAAE,EAAE,CAAC;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useResizeObserver.mjs","sources":["../../../../src/hooks/useResizeObserver/useResizeObserver.ts"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\n\nimport type { HookTarget } from '@/utils/helpers';\n\nimport { getElement, isTarget } from '@/utils/helpers';\n\nimport type { StateRef } from '../useRefState/useRefState';\n\nimport { useRefState } from '../useRefState/useRefState';\n\n/** The resize observer options type */\nexport interface UseResizeObserverOptions extends ResizeObserverOptions {\n /** The enabled state */\n enabled?: boolean;\n /** The resize observer callback */\n onChange?: (entries: ResizeObserverEntry[], observer: ResizeObserver) => void;\n}\n\n/** The resize observer return type */\nexport interface UseResizeObserverReturn {\n /** The resize observer entries */\n entries: ResizeObserverEntry[];\n}\n\nexport interface UseResizeObserver {\n (target: HookTarget, options?: UseResizeObserverOptions): UseResizeObserverReturn;\n\n <Target extends Element>(\n options?: UseResizeObserverOptions,\n target?: never\n ): UseResizeObserverReturn & { ref: StateRef<Target> };\n}\n\n/**\n * @name useResizeObserver\n * @description - Hook that gives you resize observer state\n * @category
|
|
1
|
+
{"version":3,"file":"useResizeObserver.mjs","sources":["../../../../src/hooks/useResizeObserver/useResizeObserver.ts"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\n\nimport type { HookTarget } from '@/utils/helpers';\n\nimport { getElement, isTarget } from '@/utils/helpers';\n\nimport type { StateRef } from '../useRefState/useRefState';\n\nimport { useRefState } from '../useRefState/useRefState';\n\n/** The resize observer options type */\nexport interface UseResizeObserverOptions extends ResizeObserverOptions {\n /** The enabled state */\n enabled?: boolean;\n /** The resize observer callback */\n onChange?: (entries: ResizeObserverEntry[], observer: ResizeObserver) => void;\n}\n\n/** The resize observer return type */\nexport interface UseResizeObserverReturn {\n /** The resize observer entries */\n entries: ResizeObserverEntry[];\n}\n\nexport interface UseResizeObserver {\n (target: HookTarget, options?: UseResizeObserverOptions): UseResizeObserverReturn;\n\n <Target extends Element>(\n options?: UseResizeObserverOptions,\n target?: never\n ): UseResizeObserverReturn & { ref: StateRef<Target> };\n}\n\n/**\n * @name useResizeObserver\n * @description - Hook that gives you resize observer state\n * @category Sensors\n *\n * @browserapi ResizeObserver https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver\n *\n * @overload\n * @template Target The target element\n * @param {boolean} [options.enabled=true] The IntersectionObserver options\n * @param {boolean} [options.box] The IntersectionObserver options\n * @param {(entries: ResizeObserverEntry[], observer: ResizeObserver) => void} [options.onChange] The callback to execute when resize is detected\n * @returns {UseResizeObserverReturn & { ref: StateRef<Target> }} An object containing the resize observer state\n *\n * @example\n * const { ref, entries } = useResizeObserver();\n *\n * @overload\n * @template Target The target element\n * @param {HookTarget} target The target element to observe\n * @param {boolean} [options.enabled=true] The IntersectionObserver options\n * @param {boolean} [options.box] The IntersectionObserver options\n * @param {(entries: ResizeObserverEntry[], observer: ResizeObserver) => void} [options.onChange] The callback to execute when resize is detected\n * @returns {UseResizeObserverReturn} An object containing the resize observer state\n *\n * @example\n * const { entries } = useResizeObserver(ref);\n */\nexport const useResizeObserver = ((...params: any[]) => {\n const target = (isTarget(params[0]) ? params[0] : undefined) as HookTarget | undefined;\n const options = (target ? params[1] : params[0]) as UseResizeObserverOptions | undefined;\n const enabled = options?.enabled ?? true;\n\n const [entries, setEntries] = useState<ResizeObserverEntry[]>([]);\n\n const internalRef = useRefState<Element>();\n const internalOnChangeRef = useRef<UseResizeObserverOptions['onChange']>(options?.onChange);\n internalOnChangeRef.current = options?.onChange;\n\n useEffect(() => {\n if (!enabled || (!target && !internalRef.state)) return;\n\n const element = target ? getElement(target) : internalRef.current;\n if (!element) return;\n\n const observer = new ResizeObserver((entries) => {\n setEntries(entries);\n internalOnChangeRef.current?.(entries, observer);\n });\n observer.observe(element as Element, options);\n\n return () => {\n observer.disconnect();\n };\n }, [target, internalRef.state, options?.box, enabled]);\n\n if (target) return { entries };\n return {\n ref: internalRef,\n entries\n };\n}) as UseResizeObserver;\n"],"names":["useResizeObserver","params","target","isTarget","options","enabled","entries","setEntries","useState","internalRef","useRefState","internalOnChangeRef","useRef","useEffect","element","getElement","observer"],"mappings":";;;;AA6DO,MAAMA,IAAqB,IAAIC,MAAkB;AACtD,QAAMC,IAAUC,EAASF,EAAO,CAAC,CAAC,IAAIA,EAAO,CAAC,IAAI,QAC5CG,IAAWF,IAASD,EAAO,CAAC,IAAIA,EAAO,CAAC,GACxCI,IAAUD,GAAS,WAAW,IAE9B,CAACE,GAASC,CAAU,IAAIC,EAAgC,CAAA,CAAE,GAE1DC,IAAcC,EAAA,GACdC,IAAsBC,EAA6CR,GAAS,QAAQ;AAoB1F,SAnBAO,EAAoB,UAAUP,GAAS,UAEvCS,EAAU,MAAM;AACd,QAAI,CAACR,KAAY,CAACH,KAAU,CAACO,EAAY,MAAQ;AAEjD,UAAMK,IAAUZ,IAASa,EAAWb,CAAM,IAAIO,EAAY;AAC1D,QAAI,CAACK,EAAS;AAEd,UAAME,IAAW,IAAI,eAAe,CAACV,MAAY;AAC/C,MAAAC,EAAWD,CAAO,GAClBK,EAAoB,UAAUL,GAASU,CAAQ;AAAA,IAAA,CAChD;AACD,WAAAA,EAAS,QAAQF,GAAoBV,CAAO,GAErC,MAAM;AACX,MAAAY,EAAS,WAAA;AAAA,IAAW;AAAA,EACtB,GACC,CAACd,GAAQO,EAAY,OAAOL,GAAS,KAAKC,CAAO,CAAC,GAEjDH,IAAe,EAAE,SAAAI,EAAA,IACd;AAAA,IACL,KAAKG;AAAA,IACL,SAAAH;AAAA,EAAA;AAEJ;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useScript.mjs","sources":["../../../../src/hooks/useScript/useScript.ts"],"sourcesContent":["import type { ComponentProps } from 'react';\n\nimport { useEffect, useState } from 'react';\n\n/** The use script status */\nexport type UseScriptStatus = 'error' | 'loading' | 'ready' | 'unknown';\nexport const SCRIPT_STATUS_ATTRIBUTE_NAME = 'script-status';\n\n/** The use script options extends from attributes script tag */\nexport interface UseScriptOptions extends ComponentProps<'script'> {\n /** Whether to remove the script on unmount */\n removeOnUnmount?: boolean;\n}\n\n/**\n * @name useScript\n * @description - Hook that manages a script with onLoad, onError, and removeOnUnmount functionalities\n * @category
|
|
1
|
+
{"version":3,"file":"useScript.mjs","sources":["../../../../src/hooks/useScript/useScript.ts"],"sourcesContent":["import type { ComponentProps } from 'react';\n\nimport { useEffect, useState } from 'react';\n\n/** The use script status */\nexport type UseScriptStatus = 'error' | 'loading' | 'ready' | 'unknown';\nexport const SCRIPT_STATUS_ATTRIBUTE_NAME = 'script-status';\n\n/** The use script options extends from attributes script tag */\nexport interface UseScriptOptions extends ComponentProps<'script'> {\n /** Whether to remove the script on unmount */\n removeOnUnmount?: boolean;\n}\n\n/**\n * @name useScript\n * @description - Hook that manages a script with onLoad, onError, and removeOnUnmount functionalities\n * @category Elements\n *\n * @param {string} src The source of the script\n * @param {UseScriptOptions} [options] The options of the script extends from attributes script tag\n * @param {boolean} [options.removeOnUnmount=true] Whether to remove the script on unmount\n * @param {boolean} [options.async=true] Whether to load the script asynchronously\n * @returns {UseScriptStatus} The status of the script\n *\n * @example\n * const status = useScript('https://example.com/script.js');\n */\nexport const useScript = (src: string, options: UseScriptOptions = {}) => {\n const [status, setStatus] = useState<UseScriptStatus>(() => {\n const script = document.querySelector(`script[src=\"${src}\"]`) as HTMLScriptElement;\n const scriptStatus = script?.getAttribute(SCRIPT_STATUS_ATTRIBUTE_NAME) as UseScriptStatus;\n if (scriptStatus) return scriptStatus;\n if (script) return 'unknown';\n\n return 'loading';\n });\n const { removeOnUnmount = true, async = true } = options;\n\n useEffect(() => {\n const existedScript = document.querySelector(`script[src=\"${src}\"]`) as HTMLScriptElement;\n const scriptStatus = existedScript?.getAttribute(\n SCRIPT_STATUS_ATTRIBUTE_NAME\n ) as UseScriptStatus;\n if (scriptStatus) return setStatus(scriptStatus);\n if (existedScript) return setStatus('unknown');\n\n const script = document.createElement('script');\n script.src = src;\n script.async = async;\n\n for (const [key, value] of Object.entries(options)) {\n script.setAttribute(key, String(value));\n }\n\n script.setAttribute(SCRIPT_STATUS_ATTRIBUTE_NAME, 'loading');\n document.body.appendChild(script);\n\n const onLoad = () => {\n script.setAttribute(SCRIPT_STATUS_ATTRIBUTE_NAME, 'ready');\n setStatus('ready');\n };\n\n const onError = () => {\n script.setAttribute(SCRIPT_STATUS_ATTRIBUTE_NAME, 'error');\n setStatus('error');\n };\n\n script.addEventListener('load', onLoad);\n script.addEventListener('error', onError);\n\n return () => {\n if (removeOnUnmount) script.remove();\n script.removeEventListener('load', onLoad);\n script.removeEventListener('error', onError);\n };\n }, [src, removeOnUnmount]);\n\n return status;\n};\n"],"names":["SCRIPT_STATUS_ATTRIBUTE_NAME","useScript","src","options","status","setStatus","useState","script","scriptStatus","removeOnUnmount","async","useEffect","existedScript","key","value","onLoad","onError"],"mappings":";AAMO,MAAMA,IAA+B,iBAsB/BC,IAAY,CAACC,GAAaC,IAA4B,OAAO;AACxE,QAAM,CAACC,GAAQC,CAAS,IAAIC,EAA0B,MAAM;AAC1D,UAAMC,IAAS,SAAS,cAAc,eAAeL,CAAG,IAAI,GACtDM,IAAeD,GAAQ,aAAaP,CAA4B;AACtE,WAAIQ,MACAD,IAAe,YAEZ;AAAA,EAAA,CACR,GACK,EAAE,iBAAAE,IAAkB,IAAM,OAAAC,IAAQ,OAASP;AAEjD,SAAAQ,EAAU,MAAM;AACd,UAAMC,IAAgB,SAAS,cAAc,eAAeV,CAAG,IAAI,GAC7DM,IAAeI,GAAe;AAAA,MAClCZ;AAAA,IAAA;AAEF,QAAIQ,EAAc,QAAOH,EAAUG,CAAY;AAC/C,QAAII,EAAe,QAAOP,EAAU,SAAS;AAE7C,UAAME,IAAS,SAAS,cAAc,QAAQ;AAC9C,IAAAA,EAAO,MAAML,GACbK,EAAO,QAAQG;AAEf,eAAW,CAACG,GAAKC,CAAK,KAAK,OAAO,QAAQX,CAAO;AAC/C,MAAAI,EAAO,aAAaM,GAAK,OAAOC,CAAK,CAAC;AAGxC,IAAAP,EAAO,aAAaP,GAA8B,SAAS,GAC3D,SAAS,KAAK,YAAYO,CAAM;AAEhC,UAAMQ,IAAS,MAAM;AACnB,MAAAR,EAAO,aAAaP,GAA8B,OAAO,GACzDK,EAAU,OAAO;AAAA,IAAA,GAGbW,IAAU,MAAM;AACpB,MAAAT,EAAO,aAAaP,GAA8B,OAAO,GACzDK,EAAU,OAAO;AAAA,IAAA;AAGnB,WAAAE,EAAO,iBAAiB,QAAQQ,CAAM,GACtCR,EAAO,iBAAiB,SAASS,CAAO,GAEjC,MAAM;AACX,MAAIP,OAAwB,OAAA,GAC5BF,EAAO,oBAAoB,QAAQQ,CAAM,GACzCR,EAAO,oBAAoB,SAASS,CAAO;AAAA,IAAA;AAAA,EAC7C,GACC,CAACd,GAAKO,CAAe,CAAC,GAElBL;AACT;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useScroll.mjs","sources":["../../../../src/hooks/useScroll/useScroll.ts"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\r\n\r\nimport type { HookTarget } from '@/utils/helpers';\r\n\r\nimport { getElement, isTarget } from '@/utils/helpers';\r\n\r\nimport type { StateRef } from '../useRefState/useRefState';\r\n\r\nimport { useRefState } from '../useRefState/useRefState';\r\n\r\nconst ARRIVED_STATE_THRESHOLD_PIXELS = 1;\r\n\r\nexport interface UseScrollOptions {\r\n /** The on scroll callback */\r\n onScroll?: (params: UseScrollCallbackParams, event: Event) => void;\r\n\r\n /** The on end scroll callback */\r\n onStop?: (event: Event) => void;\r\n\r\n /** Offset arrived states by x pixels. */\r\n offset?: {\r\n left?: number;\r\n right?: number;\r\n top?: number;\r\n bottom?: number;\r\n };\r\n}\r\n\r\nexport interface UseScrollCallbackParams {\r\n /** The element x position */\r\n x: number;\r\n /** The element y position */\r\n y: number;\r\n /** State of scroll arrived */\r\n arrived: {\r\n left: boolean;\r\n right: boolean;\r\n top: boolean;\r\n bottom: boolean;\r\n };\r\n /** State of scroll direction */\r\n directions: {\r\n left: boolean;\r\n right: boolean;\r\n top: boolean;\r\n bottom: boolean;\r\n };\r\n}\r\n\r\nexport interface UseScroll {\r\n (target: HookTarget, callback?: (params: UseScrollCallbackParams, event: Event) => void): boolean;\r\n\r\n (target: HookTarget, options?: UseScrollOptions): boolean;\r\n\r\n <Target extends Element>(\r\n callback?: (params: UseScrollCallbackParams, event: Event) => void,\r\n target?: never\r\n ): {\r\n ref: StateRef<Target>;\r\n scrolling: boolean;\r\n };\r\n\r\n <Target extends Element>(\r\n options?: UseScrollOptions,\r\n target?: never\r\n ): {\r\n ref: StateRef<Target>;\r\n scrolling: boolean;\r\n };\r\n}\r\n\r\n/**\r\n * @name useScroll\r\n * @description - Hook that allows you to control scroll a element\r\n * @category Sensors\r\n *\r\n * @overload\r\n * @template Target The target element\r\n * @param {ScrollBehavior} [options.behavior=auto] The behavior of scrolling\r\n * @param {number} [options.offset.left=0] The left offset for arrived states\r\n * @param {number} [options.offset.right=0] The right offset for arrived states\r\n * @param {number} [options.offset.top=0] The top offset for arrived states\r\n * @param {number} [options.offset.bottom=0] The bottom offset for arrived states\r\n * @param {(params: UseScrollCallbackParams, event: Event) => void} [options.onScroll] The callback function to be invoked on scroll\r\n * @param {(event: Event) => void} [options.onStop] The callback function to be invoked on scroll end\r\n * @returns {boolean} The state of scrolling\r\n *\r\n * @example\r\n * const scrolling = useScroll(ref, options);\r\n *\r\n * @overload\r\n * @template Target The target element\r\n * @param {(params: UseScrollCallbackParams, event: Event) => void} [callback] The callback function to be invoked on scroll\r\n * @returns {boolean} The state of scrolling\r\n *\r\n * @example\r\n * const scrolling = useScroll(ref, () => console.log('callback'));\r\n *\r\n * @overload\r\n * @template Target The target element\r\n * @param {Target} target The target element to scroll\r\n * @param {ScrollBehavior} [options.behavior=auto] The behavior of scrolling\r\n * @param {number} [options.offset.left=0] The left offset for arrived states\r\n * @param {number} [options.offset.right=0] The right offset for arrived states\r\n * @param {number} [options.offset.top=0] The top offset for arrived states\r\n * @param {number} [options.offset.bottom=0] The bottom offset for arrived states\r\n * @param {(params: UseScrollCallbackParams, event: Event) => void} [options.onScroll] The callback function to be invoked on scroll\r\n * @param {(event: Event) => void} [options.onStop] The callback function to be invoked on scroll end\r\n * @returns {[StateRef<Target>, boolean]} The state of scrolling\r\n *\r\n * @example\r\n * const { ref, scrolling } = useScroll(options);\r\n *\r\n * @overload\r\n * @template Target The target element\r\n * @param {Target} target The target element to scroll\r\n * @param {(params: UseScrollCallbackParams, event: Event) => void} [callback] The callback function to be invoked on scroll\r\n * @returns {[StateRef<Target>, boolean]} The state of scrolling\r\n *\r\n * @example\r\n * const { ref, scrolling } = useScroll(() => console.log('callback'));\r\n */\r\nexport const useScroll = ((...params: any[]) => {\r\n const target = (isTarget(params[0]) ? params[0] : undefined) as HookTarget | undefined;\r\n const options = (\r\n target\r\n ? typeof params[1] === 'object'\r\n ? params[1]\r\n : { onScroll: params[1] }\r\n : typeof params[0] === 'object'\r\n ? params[0]\r\n : { onScroll: params[0] }\r\n ) as UseScrollOptions | undefined;\r\n\r\n const internalRef = useRefState<Element>();\r\n const internalOptionsRef = useRef(options);\r\n internalOptionsRef.current = options;\r\n\r\n const [scrolling, setScrolling] = useState(false);\r\n const scrollPositionRef = useRef({ x: 0, y: 0 });\r\n\r\n useEffect(() => {\r\n if (!target && !internalRef.state) return;\r\n const element = (target ? getElement(target) : internalRef.current) as Element;\r\n\r\n if (!element) return;\r\n\r\n const onScrollEnd = (event: Event) => {\r\n setScrolling(false);\r\n options?.onStop?.(event);\r\n };\r\n\r\n const onScroll = (event: Event) => {\r\n setScrolling(true);\r\n const target = (\r\n event.target === document ? (event.target as Document).documentElement : event.target\r\n ) as HTMLElement;\r\n\r\n const { display, flexDirection, direction } = target.style;\r\n const directionMultiplier = direction === 'rtl' ? -1 : 1;\r\n\r\n const scrollLeft = target.scrollLeft;\r\n let scrollTop = target.scrollTop;\r\n if (target instanceof Document && !scrollTop) scrollTop = window.document.body.scrollTop;\r\n\r\n const offset = internalOptionsRef.current?.offset;\r\n const left = scrollLeft * directionMultiplier <= (offset?.left ?? 0);\r\n const right =\r\n scrollLeft * directionMultiplier + target.clientWidth >=\r\n target.scrollWidth - (offset?.right ?? 0) - ARRIVED_STATE_THRESHOLD_PIXELS;\r\n const top = scrollTop <= (offset?.top ?? 0);\r\n const bottom =\r\n scrollTop + target.clientHeight >=\r\n target.scrollHeight - (offset?.bottom ?? 0) - ARRIVED_STATE_THRESHOLD_PIXELS;\r\n\r\n const isColumnReverse = display === 'flex' && flexDirection === 'column-reverse';\r\n const isRowReverse = display === 'flex' && flexDirection === 'column-reverse';\r\n\r\n const params = {\r\n x: scrollLeft,\r\n y: scrollTop,\r\n directions: {\r\n left: scrollLeft < scrollPositionRef.current.x,\r\n right: scrollLeft > scrollPositionRef.current.x,\r\n top: scrollTop < scrollPositionRef.current.y,\r\n bottom: scrollTop > scrollPositionRef.current.y\r\n },\r\n arrived: {\r\n left: isRowReverse ? right : left,\r\n right: isRowReverse ? left : right,\r\n top: isColumnReverse ? bottom : top,\r\n bottom: isColumnReverse ? top : bottom\r\n }\r\n };\r\n\r\n scrollPositionRef.current = { x: scrollLeft, y: scrollTop };\r\n internalOptionsRef.current?.onScroll?.(params, event);\r\n };\r\n\r\n element.addEventListener('scroll', onScroll);\r\n element.addEventListener('scrollend', onScrollEnd);\r\n\r\n return () => {\r\n element.removeEventListener('scroll', onScroll);\r\n element.removeEventListener('scrollend', onScrollEnd);\r\n };\r\n }, [target, internalRef.state]);\r\n\r\n if (target) return scrolling;\r\n return {\r\n ref: internalRef,\r\n scrolling\r\n };\r\n}) as UseScroll;\r\n"],"names":["ARRIVED_STATE_THRESHOLD_PIXELS","useScroll","params","target","isTarget","options","internalRef","useRefState","internalOptionsRef","useRef","scrolling","setScrolling","useState","scrollPositionRef","useEffect","element","getElement","onScrollEnd","event","onScroll","display","flexDirection","direction","directionMultiplier","scrollLeft","scrollTop","offset","left","right","top","bottom","isColumnReverse","isRowReverse"],"mappings":";;;;AAUA,MAAMA,IAAiC,GAgH1BC,IAAa,IAAIC,MAAkB;AAC9C,QAAMC,IAAUC,EAASF,EAAO,CAAC,CAAC,IAAIA,EAAO,CAAC,IAAI,QAC5CG,IACJF,IACI,OAAOD,EAAO,CAAC,KAAM,WACnBA,EAAO,CAAC,IACR,EAAE,UAAUA,EAAO,CAAC,EAAA,IACtB,OAAOA,EAAO,CAAC,KAAM,WACnBA,EAAO,CAAC,IACR,EAAE,UAAUA,EAAO,CAAC,EAAA,GAGtBI,IAAcC,EAAA,GACdC,IAAqBC,EAAOJ,CAAO;AACzC,EAAAG,EAAmB,UAAUH;AAE7B,QAAM,CAACK,GAAWC,CAAY,IAAIC,EAAS,EAAK,GAC1CC,IAAoBJ,EAAO,EAAE,GAAG,GAAG,GAAG,GAAG;AAqE/C,SAnEAK,EAAU,MAAM;AACd,QAAI,CAACX,KAAU,CAACG,EAAY,MAAO;AACnC,UAAMS,IAAWZ,IAASa,EAAWb,CAAM,IAAIG,EAAY;AAE3D,QAAI,CAACS,EAAS;AAEd,UAAME,IAAc,CAACC,MAAiB;AACpC,MAAAP,EAAa,EAAK,GAClBN,GAAS,SAASa,CAAK;AAAA,IAAA,GAGnBC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AAA;AAGtD,WAAAH,EAAQ,iBAAiB,UAAUI,CAAQ,GAC3CJ,EAAQ,iBAAiB,aAAaE,CAAW,GAE1C,MAAM;AACX,MAAAF,EAAQ,oBAAoB,UAAUI,CAAQ,GAC9CJ,EAAQ,oBAAoB,aAAaE,CAAW;AAAA,IAAA;AAAA,EACtD,GACC,CAACd,GAAQG,EAAY,KAAK,CAAC,GAE1BH,IAAeO,IACZ;AAAA,IACL,KAAKJ;AAAA,IACL,WAAAI;AAAA,EAAA;AAEJ;"}
|
|
1
|
+
{"version":3,"file":"useScroll.mjs","sources":["../../../../src/hooks/useScroll/useScroll.ts"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\n\nimport type { HookTarget } from '@/utils/helpers';\n\nimport { getElement, isTarget } from '@/utils/helpers';\n\nimport type { StateRef } from '../useRefState/useRefState';\n\nimport { useRefState } from '../useRefState/useRefState';\n\nconst ARRIVED_STATE_THRESHOLD_PIXELS = 1;\n\nexport interface UseScrollOptions {\n /** The on scroll callback */\n onScroll?: (params: UseScrollCallbackParams, event: Event) => void;\n\n /** The on end scroll callback */\n onStop?: (event: Event) => void;\n\n /** Offset arrived states by x pixels. */\n offset?: {\n left?: number;\n right?: number;\n top?: number;\n bottom?: number;\n };\n}\n\nexport interface UseScrollCallbackParams {\n /** The element x position */\n x: number;\n /** The element y position */\n y: number;\n /** State of scroll arrived */\n arrived: {\n left: boolean;\n right: boolean;\n top: boolean;\n bottom: boolean;\n };\n /** State of scroll direction */\n directions: {\n left: boolean;\n right: boolean;\n top: boolean;\n bottom: boolean;\n };\n}\n\nexport interface UseScroll {\n (target: HookTarget, callback?: (params: UseScrollCallbackParams, event: Event) => void): boolean;\n\n (target: HookTarget, options?: UseScrollOptions): boolean;\n\n <Target extends Element>(\n callback?: (params: UseScrollCallbackParams, event: Event) => void,\n target?: never\n ): {\n ref: StateRef<Target>;\n scrolling: boolean;\n };\n\n <Target extends Element>(\n options?: UseScrollOptions,\n target?: never\n ): {\n ref: StateRef<Target>;\n scrolling: boolean;\n };\n}\n\n/**\n * @name useScroll\n * @description - Hook that allows you to control scroll a element\n * @category Sensors\n *\n * @overload\n * @template Target The target element\n * @param {ScrollBehavior} [options.behavior=auto] The behavior of scrolling\n * @param {number} [options.offset.left=0] The left offset for arrived states\n * @param {number} [options.offset.right=0] The right offset for arrived states\n * @param {number} [options.offset.top=0] The top offset for arrived states\n * @param {number} [options.offset.bottom=0] The bottom offset for arrived states\n * @param {(params: UseScrollCallbackParams, event: Event) => void} [options.onScroll] The callback function to be invoked on scroll\n * @param {(event: Event) => void} [options.onStop] The callback function to be invoked on scroll end\n * @returns {boolean} The state of scrolling\n *\n * @example\n * const scrolling = useScroll(ref, options);\n *\n * @overload\n * @template Target The target element\n * @param {(params: UseScrollCallbackParams, event: Event) => void} [callback] The callback function to be invoked on scroll\n * @returns {boolean} The state of scrolling\n *\n * @example\n * const scrolling = useScroll(ref, () => console.log('callback'));\n *\n * @overload\n * @template Target The target element\n * @param {Target} target The target element to scroll\n * @param {ScrollBehavior} [options.behavior=auto] The behavior of scrolling\n * @param {number} [options.offset.left=0] The left offset for arrived states\n * @param {number} [options.offset.right=0] The right offset for arrived states\n * @param {number} [options.offset.top=0] The top offset for arrived states\n * @param {number} [options.offset.bottom=0] The bottom offset for arrived states\n * @param {(params: UseScrollCallbackParams, event: Event) => void} [options.onScroll] The callback function to be invoked on scroll\n * @param {(event: Event) => void} [options.onStop] The callback function to be invoked on scroll end\n * @returns {[StateRef<Target>, boolean]} The state of scrolling\n *\n * @example\n * const { ref, scrolling } = useScroll(options);\n *\n * @overload\n * @template Target The target element\n * @param {Target} target The target element to scroll\n * @param {(params: UseScrollCallbackParams, event: Event) => void} [callback] The callback function to be invoked on scroll\n * @returns {[StateRef<Target>, boolean]} The state of scrolling\n *\n * @example\n * const { ref, scrolling } = useScroll(() => console.log('callback'));\n */\nexport const useScroll = ((...params: any[]) => {\n const target = (isTarget(params[0]) ? params[0] : undefined) as HookTarget | undefined;\n const options = (\n target\n ? typeof params[1] === 'object'\n ? params[1]\n : { onScroll: params[1] }\n : typeof params[0] === 'object'\n ? params[0]\n : { onScroll: params[0] }\n ) as UseScrollOptions | undefined;\n\n const internalRef = useRefState<Element>();\n const internalOptionsRef = useRef(options);\n internalOptionsRef.current = options;\n\n const [scrolling, setScrolling] = useState(false);\n const scrollPositionRef = useRef({ x: 0, y: 0 });\n\n useEffect(() => {\n if (!target && !internalRef.state) return;\n const element = (target ? getElement(target) : internalRef.current) as Element;\n\n if (!element) return;\n\n const onScrollEnd = (event: Event) => {\n setScrolling(false);\n options?.onStop?.(event);\n };\n\n const onScroll = (event: Event) => {\n setScrolling(true);\n const target = (\n event.target === document ? (event.target as Document).documentElement : event.target\n ) as HTMLElement;\n\n const { display, flexDirection, direction } = target.style;\n const directionMultiplier = direction === 'rtl' ? -1 : 1;\n\n const scrollLeft = target.scrollLeft;\n let scrollTop = target.scrollTop;\n if (target instanceof Document && !scrollTop) scrollTop = window.document.body.scrollTop;\n\n const offset = internalOptionsRef.current?.offset;\n const left = scrollLeft * directionMultiplier <= (offset?.left ?? 0);\n const right =\n scrollLeft * directionMultiplier + target.clientWidth >=\n target.scrollWidth - (offset?.right ?? 0) - ARRIVED_STATE_THRESHOLD_PIXELS;\n const top = scrollTop <= (offset?.top ?? 0);\n const bottom =\n scrollTop + target.clientHeight >=\n target.scrollHeight - (offset?.bottom ?? 0) - ARRIVED_STATE_THRESHOLD_PIXELS;\n\n const isColumnReverse = display === 'flex' && flexDirection === 'column-reverse';\n const isRowReverse = display === 'flex' && flexDirection === 'column-reverse';\n\n const params = {\n x: scrollLeft,\n y: scrollTop,\n directions: {\n left: scrollLeft < scrollPositionRef.current.x,\n right: scrollLeft > scrollPositionRef.current.x,\n top: scrollTop < scrollPositionRef.current.y,\n bottom: scrollTop > scrollPositionRef.current.y\n },\n arrived: {\n left: isRowReverse ? right : left,\n right: isRowReverse ? left : right,\n top: isColumnReverse ? bottom : top,\n bottom: isColumnReverse ? top : bottom\n }\n };\n\n scrollPositionRef.current = { x: scrollLeft, y: scrollTop };\n internalOptionsRef.current?.onScroll?.(params, event);\n };\n\n element.addEventListener('scroll', onScroll);\n element.addEventListener('scrollend', onScrollEnd);\n\n return () => {\n element.removeEventListener('scroll', onScroll);\n element.removeEventListener('scrollend', onScrollEnd);\n };\n }, [target, internalRef.state]);\n\n if (target) return scrolling;\n return {\n ref: internalRef,\n scrolling\n };\n}) as UseScroll;\n"],"names":["ARRIVED_STATE_THRESHOLD_PIXELS","useScroll","params","target","isTarget","options","internalRef","useRefState","internalOptionsRef","useRef","scrolling","setScrolling","useState","scrollPositionRef","useEffect","element","getElement","onScrollEnd","event","onScroll","display","flexDirection","direction","directionMultiplier","scrollLeft","scrollTop","offset","left","right","top","bottom","isColumnReverse","isRowReverse"],"mappings":";;;;AAUA,MAAMA,IAAiC,GAgH1BC,IAAa,IAAIC,MAAkB;AAC9C,QAAMC,IAAUC,EAASF,EAAO,CAAC,CAAC,IAAIA,EAAO,CAAC,IAAI,QAC5CG,IACJF,IACI,OAAOD,EAAO,CAAC,KAAM,WACnBA,EAAO,CAAC,IACR,EAAE,UAAUA,EAAO,CAAC,EAAA,IACtB,OAAOA,EAAO,CAAC,KAAM,WACnBA,EAAO,CAAC,IACR,EAAE,UAAUA,EAAO,CAAC,EAAA,GAGtBI,IAAcC,EAAA,GACdC,IAAqBC,EAAOJ,CAAO;AACzC,EAAAG,EAAmB,UAAUH;AAE7B,QAAM,CAACK,GAAWC,CAAY,IAAIC,EAAS,EAAK,GAC1CC,IAAoBJ,EAAO,EAAE,GAAG,GAAG,GAAG,GAAG;AAqE/C,SAnEAK,EAAU,MAAM;AACd,QAAI,CAACX,KAAU,CAACG,EAAY,MAAO;AACnC,UAAMS,IAAWZ,IAASa,EAAWb,CAAM,IAAIG,EAAY;AAE3D,QAAI,CAACS,EAAS;AAEd,UAAME,IAAc,CAACC,MAAiB;AACpC,MAAAP,EAAa,EAAK,GAClBN,GAAS,SAASa,CAAK;AAAA,IA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AK;AAAA,IAAA;AAGtD,WAAAH,EAAQ,iBAAiB,UAAUI,CAAQ,GAC3CJ,EAAQ,iBAAiB,aAAaE,CAAW,GAE1C,MAAM;AACX,MAAAF,EAAQ,oBAAoB,UAAUI,CAAQ,GAC9CJ,EAAQ,oBAAoB,aAAaE,CAAW;AAAA,IAAA;AAAA,EACtD,GACC,CAACd,GAAQG,EAAY,KAAK,CAAC,GAE1BH,IAAeO,IACZ;AAAA,IACL,KAAKJ;AAAA,IACL,WAAAI;AAAA,EAAA;AAEJ;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSessionStorage.mjs","sources":["../../../../src/hooks/useSessionStorage/useSessionStorage.ts"],"sourcesContent":["import type { UseStorageInitialValue, UseStorageOptions } from '../useStorage/useStorage';\n\nimport { useStorage } from '../useStorage/useStorage';\n\n/**\n * @name useSessionStorage\n * @description - Hook that manages session storage value\n * @category
|
|
1
|
+
{"version":3,"file":"useSessionStorage.mjs","sources":["../../../../src/hooks/useSessionStorage/useSessionStorage.ts"],"sourcesContent":["import type { UseStorageInitialValue, UseStorageOptions } from '../useStorage/useStorage';\n\nimport { useStorage } from '../useStorage/useStorage';\n\n/**\n * @name useSessionStorage\n * @description - Hook that manages session storage value\n * @category State\n *\n * @browserapi sessionStorage https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage\n *\n * @template Value The type of the value\n * @param {string} key The key of the storage\n * @param {UseStorageInitialValue<Value>} [initialValue] The initial value of the storage\n * @param {UseStorageOptions<Value>} [options] The options of the storage\n *\n * @example\n * const { value, set, remove } = useSessionStorage('key', 'value');\n */\nexport const useSessionStorage = <Value>(\n key: string,\n initialValue?: UseStorageInitialValue<Value>,\n options?: Omit<UseStorageOptions<Value>, 'initialValue' | 'storage'>\n) =>\n useStorage(key, {\n ...options,\n initialValue,\n storage: typeof window !== 'undefined' ? window.sessionStorage : undefined\n });\n"],"names":["useSessionStorage","key","initialValue","options","useStorage"],"mappings":";AAmBO,MAAMA,IAAoB,CAC/BC,GACAC,GACAC,MAEAC,EAAWH,GAAK;AAAA,EACd,GAAGE;AAAA,EACH,cAAAD;AAAA,EACA,SAAS,OAAO,SAAW,MAAc,OAAO,iBAAiB;AACnE,CAAC;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSet.mjs","sources":["../../../../src/hooks/useSet/useSet.ts"],"sourcesContent":["import { useState } from 'react';\n\n/** The use set return type */\ninterface UseSetReturn<Value> {\n /** The size of the set */\n size: number;\n /** The current set */\n value: Set<Value>;\n /** Function to add a value to the set */\n add: (value: Value) => void;\n /** Function to clear the set */\n clear: () => void;\n /** Function to get the symmetric difference of two sets */\n difference: (other: Set<Value>) => void;\n /** Function to check if a value exists in the set */\n has: (value: Value) => boolean;\n /** Function to get the difference of two sets */\n intersection: (other: Set<Value>) => void;\n /** Function to remove a value from the set */\n remove: (value: Value) => void;\n /** Function to toggle a value in the set */\n reset: () => void;\n /** Function to get the symmetric difference of two sets */\n symmetricDifference: (other: Set<Value>) => void;\n /** Function to toggle a value in the set */\n toggle: (value: Value) => void;\n /** Function to get the union of two sets */\n union: (other: Set<Value>) => void;\n}\n\n/**\n * @name useSet\n * @description - Hook that manages a set structure\n * @category
|
|
1
|
+
{"version":3,"file":"useSet.mjs","sources":["../../../../src/hooks/useSet/useSet.ts"],"sourcesContent":["import { useState } from 'react';\n\n/** The use set return type */\ninterface UseSetReturn<Value> {\n /** The size of the set */\n size: number;\n /** The current set */\n value: Set<Value>;\n /** Function to add a value to the set */\n add: (value: Value) => void;\n /** Function to clear the set */\n clear: () => void;\n /** Function to get the symmetric difference of two sets */\n difference: (other: Set<Value>) => void;\n /** Function to check if a value exists in the set */\n has: (value: Value) => boolean;\n /** Function to get the difference of two sets */\n intersection: (other: Set<Value>) => void;\n /** Function to remove a value from the set */\n remove: (value: Value) => void;\n /** Function to toggle a value in the set */\n reset: () => void;\n /** Function to get the symmetric difference of two sets */\n symmetricDifference: (other: Set<Value>) => void;\n /** Function to toggle a value in the set */\n toggle: (value: Value) => void;\n /** Function to get the union of two sets */\n union: (other: Set<Value>) => void;\n}\n\n/**\n * @name useSet\n * @description - Hook that manages a set structure\n * @category State\n *\n * @template Value The type of the value\n * @param {Value[]} [values] The initial array of the set\n * @returns {UseSetReturn<Value>} An object containing the current set and functions to interact with the set\n *\n * @example\n * const { value, add, remove, clear, reset, toggle, union, intersection, difference, symmetricDifference, size, has } = useSet([1, 2, 3]);\n */\nexport const useSet = <Value>(values?: Value[]): UseSetReturn<Value> => {\n const [set, setSet] = useState(new Set(values));\n\n const add = (value: Value) => setSet((prevSet) => new Set(prevSet).add(value));\n const remove = (value: Value) =>\n setSet((prevSet) => {\n if (!prevSet.has(value)) return prevSet;\n const newSet = new Set(prevSet);\n newSet.delete(value);\n return newSet;\n });\n const clear = () => setSet(new Set());\n const reset = () => setSet(new Set(values));\n const toggle = (value: Value) =>\n setSet((prevSet) => {\n if (!prevSet.has(value)) return new Set(prevSet).add(value);\n const newSet = new Set(prevSet);\n newSet.delete(value);\n return newSet;\n });\n const union = (other: Set<Value>) => setSet(set.union(other));\n const difference = (other: Set<Value>) => setSet(set.difference(other));\n const symmetricDifference = (other: Set<Value>) => setSet(set.symmetricDifference(other));\n const intersection = (other: Set<Value>) => setSet(set.intersection(other));\n const has = (value: Value) => set.has(value);\n\n return {\n value: set,\n size: set.size,\n has,\n add,\n remove,\n clear,\n reset,\n toggle,\n union,\n difference,\n symmetricDifference,\n intersection\n };\n};\n"],"names":["useSet","values","set","setSet","useState","add","value","prevSet","remove","newSet","clear","reset","toggle","union","other","difference","symmetricDifference","intersection","has"],"mappings":";AA0CO,MAAMA,IAAS,CAAQC,MAA0C;AACtE,QAAM,CAACC,GAAKC,CAAM,IAAIC,EAAS,IAAI,IAAIH,CAAM,CAAC,GAExCI,IAAM,CAACC,MAAiBH,EAAO,CAACI,MAAY,IAAI,IAAIA,CAAO,EAAE,IAAID,CAAK,CAAC,GACvEE,IAAS,CAACF,MACdH,EAAO,CAACI,MAAY;AAClB,QAAI,CAACA,EAAQ,IAAID,CAAK,EAAG,QAAOC;AAChC,UAAME,IAAS,IAAI,IAAIF,CAAO;AAC9B,WAAAE,EAAO,OAAOH,CAAK,GACZG;AAAA,EAAA,CACR,GACGC,IAAQ,MAAMP,EAAO,oBAAI,KAAK,GAC9BQ,IAAQ,MAAMR,EAAO,IAAI,IAAIF,CAAM,CAAC,GACpCW,IAAS,CAACN,MACdH,EAAO,CAACI,MAAY;AAClB,QAAI,CAACA,EAAQ,IAAID,CAAK,EAAG,QAAO,IAAI,IAAIC,CAAO,EAAE,IAAID,CAAK;AAC1D,UAAMG,IAAS,IAAI,IAAIF,CAAO;AAC9B,WAAAE,EAAO,OAAOH,CAAK,GACZG;AAAA,EAAA,CACR,GACGI,IAAQ,CAACC,MAAsBX,EAAOD,EAAI,MAAMY,CAAK,CAAC,GACtDC,IAAa,CAACD,MAAsBX,EAAOD,EAAI,WAAWY,CAAK,CAAC,GAChEE,IAAsB,CAACF,MAAsBX,EAAOD,EAAI,oBAAoBY,CAAK,CAAC,GAClFG,IAAe,CAACH,MAAsBX,EAAOD,EAAI,aAAaY,CAAK,CAAC,GACpEI,IAAM,CAACZ,MAAiBJ,EAAI,IAAII,CAAK;AAE3C,SAAO;AAAA,IACL,OAAOJ;AAAA,IACP,MAAMA,EAAI;AAAA,IACV,KAAAgB;AAAA,IACA,KAAAb;AAAA,IACA,QAAAG;AAAA,IACA,OAAAE;AAAA,IACA,OAAAC;AAAA,IACA,QAAAC;AAAA,IACA,OAAAC;AAAA,IACA,YAAAE;AAAA,IACA,qBAAAC;AAAA,IACA,cAAAC;AAAA,EAAA;AAEJ;"}
|
|
@@ -29,10 +29,20 @@ const f = () => window?.SpeechRecognition ?? window?.webkitSpeechRecognition, q
|
|
|
29
29
|
});
|
|
30
30
|
T(() => () => s.stop(), []);
|
|
31
31
|
const g = () => s.start(), p = () => s.stop();
|
|
32
|
-
return {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
return {
|
|
33
|
+
supported: i,
|
|
34
|
+
transcript: A,
|
|
35
|
+
recognition: s,
|
|
36
|
+
final: k,
|
|
37
|
+
listening: a,
|
|
38
|
+
error: F,
|
|
39
|
+
start: g,
|
|
40
|
+
stop: p,
|
|
41
|
+
toggle: (r = !a) => {
|
|
42
|
+
if (r) return g();
|
|
43
|
+
p();
|
|
44
|
+
}
|
|
45
|
+
};
|
|
36
46
|
};
|
|
37
47
|
export {
|
|
38
48
|
f as getSpeechRecognition,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSpeechRecognition.mjs","sources":["../../../../src/hooks/useSpeechRecognition/useSpeechRecognition.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\n/** The use speech recognition hook options type */\ninterface UseSpeechRecognitionOptions {\n /** If true, recognition continues even after pauses in speech. Default is false */\n continuous?: SpeechRecognition['continuous'];\n /** A list of grammar rules */\n grammars?: SpeechRecognition['grammars'];\n /** If true, interim (non-final) results are provided as the user speaks */\n interimResults?: SpeechRecognition['interimResults'];\n /** The language in which recognition should occur. Must be a valid BCP 47 language tag (e.g., \"en-US\", \"ru-RU\") */\n language?: SpeechRecognition['lang'];\n /** The maximum number of alternative transcripts returned for a given recognition result. Must be a positive integer */\n maxAlternatives?: SpeechRecognition['maxAlternatives'];\n /** Callback invoked when speech recognition ends */\n onEnd?: () => void;\n /** Callback invoked when an error occurs during recognition */\n onError?: (error: SpeechRecognitionErrorEvent) => void;\n /** Callback invoked when recognition produces a result */\n onResult?: (event: SpeechRecognitionEvent) => void;\n /** Callback invoked when speech recognition starts */\n onStart?: () => void;\n}\n\n/** The return type of the useSpeechRecognition hook. */\ninterface UseSpeechRecognitionReturn {\n /** The error state */\n error: SpeechRecognitionErrorEvent | null;\n /** The final transcript */\n final: boolean;\n /** Whether the hook is currently listening for speech */\n listening: boolean;\n /** The speech recognition instance */\n recognition: SpeechRecognition;\n /** Whether the current browser supports the Web Speech API */\n supported: boolean;\n /** The current transcript */\n transcript: string;\n /** Begins speech recognition */\n start: () => void;\n /** Ends speech recognition, finalizing results */\n stop: () => void;\n /** Toggles the listening state */\n toggle: (value?: boolean) => void;\n}\n\nexport const getSpeechRecognition = () =>\n window?.SpeechRecognition ?? window?.webkitSpeechRecognition;\n\n/**\n * @name useSpeechRecognition\n * @description - Hook that provides a streamlined interface for incorporating speech-to-text functionality\n * @category
|
|
1
|
+
{"version":3,"file":"useSpeechRecognition.mjs","sources":["../../../../src/hooks/useSpeechRecognition/useSpeechRecognition.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\n/** The use speech recognition hook options type */\ninterface UseSpeechRecognitionOptions {\n /** If true, recognition continues even after pauses in speech. Default is false */\n continuous?: SpeechRecognition['continuous'];\n /** A list of grammar rules */\n grammars?: SpeechRecognition['grammars'];\n /** If true, interim (non-final) results are provided as the user speaks */\n interimResults?: SpeechRecognition['interimResults'];\n /** The language in which recognition should occur. Must be a valid BCP 47 language tag (e.g., \"en-US\", \"ru-RU\") */\n language?: SpeechRecognition['lang'];\n /** The maximum number of alternative transcripts returned for a given recognition result. Must be a positive integer */\n maxAlternatives?: SpeechRecognition['maxAlternatives'];\n /** Callback invoked when speech recognition ends */\n onEnd?: () => void;\n /** Callback invoked when an error occurs during recognition */\n onError?: (error: SpeechRecognitionErrorEvent) => void;\n /** Callback invoked when recognition produces a result */\n onResult?: (event: SpeechRecognitionEvent) => void;\n /** Callback invoked when speech recognition starts */\n onStart?: () => void;\n}\n\n/** The return type of the useSpeechRecognition hook. */\ninterface UseSpeechRecognitionReturn {\n /** The error state */\n error: SpeechRecognitionErrorEvent | null;\n /** The final transcript */\n final: boolean;\n /** Whether the hook is currently listening for speech */\n listening: boolean;\n /** The speech recognition instance */\n recognition: SpeechRecognition;\n /** Whether the current browser supports the Web Speech API */\n supported: boolean;\n /** The current transcript */\n transcript: string;\n /** Begins speech recognition */\n start: () => void;\n /** Ends speech recognition, finalizing results */\n stop: () => void;\n /** Toggles the listening state */\n toggle: (value?: boolean) => void;\n}\n\nexport const getSpeechRecognition = () =>\n window?.SpeechRecognition ?? window?.webkitSpeechRecognition;\n\n/**\n * @name useSpeechRecognition\n * @description - Hook that provides a streamlined interface for incorporating speech-to-text functionality\n * @category Browser\n *\n * @browserapi window.SpeechRecognition https://developer.mozilla.org/en-US/docs/Web/API/SpeechRecognition\n *\n * @param {boolean} [options.continuous=false] Whether recognition should continue after pauses\n * @param {boolean} [options.interimResults=false] Whether interim results should be provided\n * @param {string} [options.language=\"en-US\"] The language for recognition, as a valid BCP 47 tag\n * @param {number} [options.maxAlternatives=1] The maximum number of alternative transcripts to return\n * @param {SpeechGrammarList} [options.grammars] A list of grammar rules\n * @param {() => void} [options.onStart] Callback invoked when speech recognition starts\n * @param {() => void} [options.onEnd] Callback invoked when speech recognition ends\n * @param {(error: SpeechRecognitionErrorEvent) => void} [options.onError] Callback invoked when an error occurs during recognition\n * @param {(event: SpeechRecognitionEvent) => void} [options.onResult] Callback invoked when recognition produces a result\n * @returns {UseSpeechRecognitionReturn} An object containing the speech recognition functionality\n *\n * @example\n * const { supported, value, recognition, listening, error, start, stop, toggle } = useSpeechRecognition();\n */\nexport const useSpeechRecognition = (\n options: UseSpeechRecognitionOptions = {}\n): UseSpeechRecognitionReturn => {\n const supported = typeof window !== 'undefined' && !!getSpeechRecognition();\n\n const {\n continuous = false,\n interimResults = false,\n language = 'en-US',\n grammars,\n maxAlternatives = 1,\n onStart,\n onEnd,\n onError,\n onResult\n } = options;\n\n const [listening, setListening] = useState(false);\n const [transcript, setTranscript] = useState('');\n const [final, setFinal] = useState(false);\n const [error, setError] = useState<SpeechRecognitionErrorEvent | null>(null);\n const [recognition] = useState<SpeechRecognition>(() => {\n if (!supported) return {} as SpeechRecognition;\n\n const SpeechRecognition = getSpeechRecognition();\n const speechRecognition = new SpeechRecognition();\n\n speechRecognition.continuous = continuous;\n if (grammars) speechRecognition.grammars = grammars;\n speechRecognition.interimResults = interimResults;\n speechRecognition.lang = language;\n speechRecognition.maxAlternatives = maxAlternatives;\n\n speechRecognition.onstart = () => {\n setListening(true);\n setFinal(false);\n onStart?.();\n };\n speechRecognition.onend = () => {\n setListening(false);\n onEnd?.();\n };\n speechRecognition.onerror = (event) => {\n setError(event);\n setListening(false);\n onError?.(event);\n };\n speechRecognition.onresult = (event) => {\n console.log('onresult', event);\n const currentResult = event.results[event.resultIndex];\n const { transcript } = currentResult[0];\n\n setTranscript(transcript);\n setError(null);\n onResult?.(event);\n };\n speechRecognition.onend = () => {\n setListening(false);\n speechRecognition.lang = language;\n };\n\n return speechRecognition;\n });\n\n useEffect(() => () => recognition.stop(), []);\n\n const start = () => recognition.start();\n const stop = () => recognition.stop();\n\n const toggle = (value = !listening) => {\n if (value) return start();\n stop();\n };\n\n return {\n supported,\n transcript,\n recognition,\n final,\n listening,\n error,\n start,\n stop,\n toggle\n };\n};\n"],"names":["getSpeechRecognition","useSpeechRecognition","options","supported","continuous","interimResults","language","grammars","maxAlternatives","onStart","onEnd","onError","onResult","listening","setListening","useState","transcript","setTranscript","final","setFinal","error","setError","recognition","SpeechRecognition","speechRecognition","event","currentResult","useEffect","start","stop","value"],"mappings":";AA8CO,MAAMA,IAAuB,MAClC,QAAQ,qBAAqB,QAAQ,yBAuB1BC,IAAuB,CAClCC,IAAuC,OACR;AAC/B,QAAMC,IAAY,OAAO,SAAW,OAAe,CAAC,CAACH,EAAA,GAE/C;AAAA,IACJ,YAAAI,IAAa;AAAA,IACb,gBAAAC,IAAiB;AAAA,IACjB,UAAAC,IAAW;AAAA,IACX,UAAAC;AAAA,IACA,iBAAAC,IAAkB;AAAA,IAClB,SAAAC;AAAA,IACA,OAAAC;AAAA,IACA,SAAAC;AAAA,IACA,UAAAC;AAAA,EAAA,IACEV,GAEE,CAACW,GAAWC,CAAY,IAAIC,EAAS,EAAK,GAC1C,CAACC,GAAYC,CAAa,IAAIF,EAAS,EAAE,GACzC,CAACG,GAAOC,CAAQ,IAAIJ,EAAS,EAAK,GAClC,CAACK,GAAO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A,IACA,QAda,CAACC,IAAQ,CAACjB,MAAc;AACrC,UAAIiB,UAAcF,EAAA;AAClB,MAAAC,EAAA;AAAA,IAAK;AAAA,EAYL;AAEJ;"}
|
|
@@ -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
|
|
1
|
+
{"version":3,"file":"useSpeechSynthesis.mjs","sources":["../../../../src/hooks/useSpeechSynthesis/useSpeechSynthesis.ts"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\n\n/** The use speech synthesis status type */\nexport type UseSpeechSynthesisStatus = 'end' | 'init' | 'pause' | 'play';\n\n/** The use speech synthesis options type */\nexport interface UseSpeechSynthesisOptions {\n /** Language for SpeechSynthesis */\n lang?: string;\n /** Gets and sets the pitch at which the utterance will be spoken at. */\n pitch?: number;\n /** Gets and sets the speed at which the utterance will be spoken at. */\n rate?: number;\n /** The text to be spoken */\n text?: string;\n /** Gets and sets the voice that will be used to speak the utterance. */\n voice?: SpeechSynthesisVoice | null;\n /** Gets and sets the volume that the utterance will be spoken at. */\n volume?: number;\n}\n\n/** The use speech synthesis return type */\nexport interface UseSpeechSynthesisReturn {\n /** Any error that occurred during speech synthesis. */\n error: SpeechSynthesisErrorEvent | undefined;\n /** Indicates if speech is currently playing. */\n playing: boolean;\n /** The current status of speech synthesis. */\n status: UseSpeechSynthesisStatus;\n /** Indicates if the SpeechSynthesis API is supported in the current environment. */\n supported: boolean;\n /** The SpeechSynthesisUtterance instance. */\n utterance: SpeechSynthesisUtterance | null;\n /** Function to pause speech synthesis. */\n pause: () => void;\n /** Function to resume speech synthesis. */\n resume: () => void;\n /** Function to start speech synthesis. */\n speak: () => void;\n /** Function to stop speech synthesis. */\n stop: () => void;\n /** Function to toggle between play and pause. */\n toggle: (value?: boolean) => void;\n}\n\n/**\n * @name useSpeechSynthesis\n * @description - Hook that provides speech synthesis functionality\n * @category Browser\n *\n * @browserapi SpeechSynthesis https://developer.mozilla.org/en-US/docs/Web/API/SpeechSynthesis\n *\n * @params {string} [options.text] - The text to be spoken\n * @params {string} [options.lang] - The language to be spoken\n * @params {number} [options.pitch] - The pitch to be spoken\n * @params {number} [options.rate] - The rate to be spoken\n * @params {SpeechSynthesisVoice} [options.voice] - The voice to be spoken\n * @params {number} [options.volume] - The volume to be spoken\n * @returns {UseSpeechSynthesisReturn} An object containing the speech synthesis state and control methods\n *\n * @example\n * const { supported, playing, status, utterance, error, stop, toggle, speak, resume, pause } = useSpeechSynthesis();\n */\nexport const useSpeechSynthesis = (\n options: UseSpeechSynthesisOptions = {}\n): UseSpeechSynthesisReturn => {\n const supported = typeof window !== 'undefined' && 'speechSynthesis' in window;\n\n const { text = '', lang = 'en-US', pitch = 1, rate = 1, voice = null, volume = 1 } = options;\n\n const [playing, setPlaying] = useState(false);\n const [status, setStatus] = useState<UseSpeechSynthesisStatus>('init');\n const [error, setError] = useState<SpeechSynthesisErrorEvent>();\n const speechSynthesisUtteranceRef = useRef<SpeechSynthesisUtterance | null>(null);\n\n const bindSpeechSynthesisUtterance = (speechSynthesisUtterance: SpeechSynthesisUtterance) => {\n speechSynthesisUtterance.lang = lang;\n speechSynthesisUtterance.pitch = pitch;\n speechSynthesisUtterance.rate = rate;\n speechSynthesisUtterance.volume = volume;\n speechSynthesisUtterance.voice = voice;\n\n speechSynthesisUtterance.onstart = () => {\n setPlaying(true);\n setStatus('play');\n };\n\n speechSynthesisUtterance.onpause = () => {\n setPlaying(false);\n setStatus('pause');\n };\n\n speechSynthesisUtterance.onresume = () => {\n setPlaying(true);\n setStatus('play');\n };\n\n speechSynthesisUtterance.onend = () => {\n setPlaying(false);\n setStatus('end');\n };\n\n speechSynthesisUtterance.onerror = (event) => {\n setPlaying(false);\n setError(event);\n };\n };\n\n useEffect(() => {\n if (!supported) return;\n\n const speechSynthesisUtterance = new SpeechSynthesisUtterance(text);\n bindSpeechSynthesisUtterance(speechSynthesisUtterance);\n speechSynthesisUtteranceRef.current = speechSynthesisUtterance;\n\n return () => {\n window.speechSynthesis?.cancel();\n };\n }, [text, lang, pitch, rate, voice, volume]);\n\n const speak = (text?: string) => {\n if (!supported) return;\n\n if (text) {\n speechSynthesisUtteranceRef.current = new SpeechSynthesisUtterance(text);\n bindSpeechSynthesisUtterance(speechSynthesisUtteranceRef.current);\n }\n\n window.speechSynthesis?.cancel();\n if (speechSynthesisUtteranceRef.current)\n window.speechSynthesis?.speak(speechSynthesisUtteranceRef.current);\n };\n\n const stop = () => {\n if (!supported) return;\n\n window.speechSynthesis?.cancel();\n setPlaying(false);\n };\n\n const toggle = (value = !playing) => {\n if (!supported) return;\n\n if (value) {\n window.speechSynthesis?.resume();\n } else {\n window.speechSynthesis?.pause();\n }\n setPlaying(value);\n };\n\n const resume = () => {\n setPlaying(true);\n window.speechSynthesis?.resume();\n };\n\n const pause = () => {\n setPlaying(false);\n window.speechSynthesis?.pause();\n };\n\n return {\n supported,\n playing,\n status,\n utterance: speechSynthesisUtteranceRef.current,\n error,\n\n stop,\n toggle,\n speak,\n resume,\n pause\n };\n};\n"],"names":["useSpeechSynthesis","options","supported","text","lang","pitch","rate","voice","volume","playing","setPlaying","useState","status","setStatus","error","setError","speechSynthesisUtteranceRef","useRef","bindSpeechSynthesisUtterance","speechSynthesisUtterance","event","useEffect","speak","stop","toggle","value","resume","pause"],"mappings":";AA+DO,MAAMA,IAAqB,CAChCC,IAAqC,OACR;AAC7B,QAAMC,IAAY,OAAO,SAAW,OAAe,qBAAqB,QAElE,EAAE,MAAAC,IAAO,IAAI,MAAAC,IAAO,SAAS,OAAAC,IAAQ,GAAG,MAAAC,IAAO,GAAG,OAAAC,IAAQ,MAAM,QAAAC,IAAS,MAAMP,GAE/E,CAACQ,GAASC,CAAU,IAAIC,EAAS,EAAK,GACtC,CAACC,GAAQC,CAAS,IAAIF,EAAmC,MAAM,GAC/D,CAACG,GAAOC,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,MAA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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
|
|
1
|
+
{"version":3,"file":"useStateHistory.mjs","sources":["../../../../src/hooks/useStateHistory/useStateHistory.ts"],"sourcesContent":["import { useReducer } from 'react';\n\n/** The use state history hook return type */\ninterface UseStateHistoryReturn<Value> {\n /** True if a redo operation can be performed */\n canRedo: boolean;\n /** True if an undo operation can be performed */\n canUndo: boolean;\n /** All history values */\n history: Value[];\n /** Current index in history */\n index: number;\n /** Current value */\n value: Value;\n /** Go back specified number of steps in history (default: 1) */\n back: (steps?: number) => void;\n /** Go forward specified number of steps in history (default: 1) */\n forward: (steps?: number) => void;\n /** Redo the last change */\n redo: () => void;\n /** Reset history to initial state */\n reset: () => void;\n /** Set a new value */\n set: (value: Value) => void;\n /** Undo the last change */\n undo: () => void;\n}\n\nexport type StateHistoryAction<Value> =\n | { type: 'BACK'; payload: { steps: number } }\n | { type: 'FORWARD'; payload: { steps: number } }\n | { type: 'REDO' }\n | { type: 'RESET'; payload: { initialValue: Value; capacity: number } }\n | { type: 'SET'; payload: { value: Value; capacity: number } }\n | { type: 'UNDO' };\n\nexport interface StateHistory<Value> {\n currentIndex: number;\n history: Value[];\n redoStack: Value[][];\n undoStack: Value[][];\n}\n\nexport const stateHistoryReducer = <Value>(\n state: StateHistory<Value>,\n action: StateHistoryAction<Value>\n): StateHistory<Value> => {\n switch (action.type) {\n case 'SET': {\n const { value, capacity } = action.payload;\n\n const newHistory = [...state.history.slice(0, state.currentIndex + 1), value];\n if (newHistory.length > capacity) {\n newHistory.shift();\n }\n\n const newUndoStack = [state.history, ...state.undoStack];\n if (newUndoStack.length > capacity) {\n newUndoStack.pop();\n }\n\n return {\n history: newHistory,\n currentIndex: newHistory.length - 1,\n undoStack: newUndoStack,\n redoStack: []\n };\n }\n\n case 'UNDO': {\n if (state.undoStack.length === 0) return state;\n\n return {\n history: state.undoStack[0],\n currentIndex: state.undoStack[0].length - 1,\n undoStack: state.undoStack.slice(1),\n redoStack: [state.history, ...state.redoStack]\n };\n }\n\n case 'REDO': {\n if (state.redoStack.length === 0) return state;\n\n return {\n history: state.redoStack[0],\n currentIndex: state.redoStack[0].length - 1,\n undoStack: [state.history, ...state.undoStack],\n redoStack: state.redoStack.slice(1)\n };\n }\n\n case 'BACK': {\n const { steps } = action.payload;\n return {\n ...state,\n currentIndex: Math.max(0, state.currentIndex - steps)\n };\n }\n\n case 'FORWARD': {\n const { steps } = action.payload;\n return {\n ...state,\n currentIndex: Math.min(state.currentIndex + steps, state.history.length - 1)\n };\n }\n\n case 'RESET': {\n const { initialValue, capacity } = action.payload;\n if (state.history.length === 1) return state;\n\n const newUndoStack = [state.history, ...state.undoStack];\n if (newUndoStack.length > capacity) {\n newUndoStack.pop();\n }\n\n return {\n history: [initialValue],\n currentIndex: 0,\n undoStack: newUndoStack,\n redoStack: []\n };\n }\n\n default:\n throw new Error('Unsupported action type');\n }\n};\n\n/**\n * @name useStateHistory\n * @description - Hook that manages state with history functionality\n * @category State\n *\n * @param {Value} initialValue - The initial value to start the history with\n * @param {number} [capacity=10] - Maximum number of history entries and undo actions to keep\n * @returns {UseStateHistoryReturn<Value>} Object containing current value, history array and control methods\n *\n * @example\n * const { value, history, index, set, back, forward, reset, undo, redo, canUndo, canRedo } = useStateHistory(0);\n */\nexport const useStateHistory = <Value>(\n initialValue: Value,\n capacity = 10\n): UseStateHistoryReturn<Value> => {\n const [state, dispatch] = useReducer(stateHistoryReducer<Value>, {\n history: [initialValue],\n currentIndex: 0,\n undoStack: [],\n redoStack: []\n });\n\n const value = state.history[state.currentIndex];\n const canUndo = state.undoStack.length > 0;\n const canRedo = state.redoStack.length > 0;\n\n const set = (value: Value) =>\n dispatch({\n type: 'SET',\n payload: { value, capacity }\n });\n\n const undo = () => dispatch({ type: 'UNDO' });\n\n const redo = () => dispatch({ type: 'REDO' });\n\n const back = (steps = 1) => dispatch({ type: 'BACK', payload: { steps } });\n\n const forward = (steps = 1) => dispatch({ type: 'FORWARD', payload: { steps } });\n\n const reset = () => dispatch({ type: 'RESET', payload: { initialValue, capacity } });\n\n return {\n history: state.history,\n value,\n set,\n index: state.currentIndex,\n back,\n forward,\n reset,\n undo,\n redo,\n canUndo,\n canRedo\n };\n};\n"],"names":["stateHistoryReducer","state","action","value","capacity","newHistory","newUndoStack","steps","initialValue","useStateHistory","dispatch","useReducer","canUndo","canRedo","set","undo","redo","back","forward","reset"],"mappings":";AA2CO,MAAMA,IAAsB,CACjCC,GACAC,MACwB;AACxB,UAAQA,EAAO,MAAA;AAAA,IACb,KAAK,OAAO;AACV,YAAM,EAAE,OAAAC,GAAO,UAAAC,EAAA,IAAaF,EAAO,SAE7BG,IAAa,CAAC,GAAGJ,EAAM,QAAQ,MAAM,GAAGA,EAAM,eAAe,CAAC,GAAGE,CAAK;AAC5E,MAAIE,EAAW,SAASD,KACtBC,EAAW,MAAA;AAGb,YAAMC,IAAe,CAAC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AAAJ;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
|
|
1
|
+
{"version":3,"file":"useStep.mjs","sources":["../../../../src/hooks/useStep/useStep.ts"],"sourcesContent":["import { useRef, useState } from 'react';\n\n/** The use step params type */\nexport interface UseStepParams {\n /** Initial value for step */\n initial: number;\n /** Maximum value for step */\n max: number;\n}\n\n/** The use step return type */\nexport interface UseStepReturn {\n /** Counts of steps */\n counts: number;\n /** Current value of step */\n currentStep: number;\n /** Boolean value if current step is first */\n isFirst: boolean;\n /** Boolean value if current step is last */\n isLast: boolean;\n /** Go to back step */\n back: () => void;\n /** Go to next step */\n next: () => void;\n /** Reset current step to initial value */\n reset: () => void;\n /** Go to custom step */\n set: (value: number | 'first' | 'last') => void;\n}\n\nconst FIRST_STEP_VALUE = 1;\n\n/**\n * @name useStep\n * @description - Hook that create stepper\n * @category State\n *\n * @overload\n * @param {number} max Maximum number of steps\n * @returns {UseStepReturn} An object contains variables and functions to change the step\n *\n * @example\n * const stepper = useStep(5);\n *\n * @overload\n * @param {number} params.max Maximum number of steps\n * @param {number} params.initial Initial value for step\n * @returns {UseStepReturn} An object contains variables and functions to change the step\n *\n * @example\n * const stepper = useStep({ initial: 2, max: 5 });\n */\nexport const useStep = (params: number | UseStepParams): UseStepReturn => {\n const max = typeof params === 'object' ? params.max : params;\n const initial = typeof params === 'object' ? params.initial : FIRST_STEP_VALUE;\n\n const initialStep = useRef(\n initial > max || initial < FIRST_STEP_VALUE ? FIRST_STEP_VALUE : initial\n );\n const [currentStep, setCurrentStep] = useState(initial);\n\n const isFirst = currentStep === FIRST_STEP_VALUE;\n const isLast = currentStep === max;\n\n const next = () => {\n if (isLast) return;\n setCurrentStep((prevStep) => prevStep + 1);\n };\n\n const back = () => {\n if (isFirst) return;\n setCurrentStep((prevStep) => prevStep - 1);\n };\n\n const reset = () => setCurrentStep(initialStep.current);\n\n const set = (value: number | 'first' | 'last') => {\n if (value === 'first') return setCurrentStep(initialStep.current);\n if (value === 'last') return setCurrentStep(max);\n if (value >= max) return setCurrentStep(max);\n if (value <= FIRST_STEP_VALUE) return setCurrentStep(FIRST_STEP_VALUE);\n setCurrentStep(value);\n };\n\n return {\n counts: max,\n currentStep,\n isFirst,\n isLast,\n next,\n back,\n reset,\n set\n };\n};\n"],"names":["FIRST_STEP_VALUE","useStep","params","max","initial","initialStep","useRef","currentStep","setCurrentStep","useState","isFirst","isLast","prevStep","value"],"mappings":";AA8BA,MAAMA,IAAmB,GAsBZC,IAAU,CAACC,MAAkD;AACxE,QAAMC,IAAM,OAAOD,KAAW,WAAWA,EAAO,MAAMA,GAChDE,IAAU,OAAOF,KAAW,WAAWA,EAAO,UAAUF,GAExDK,IAAcC;AAAA,IAClBF,IAAUD,KAAOC,IAAUJ,IAAmBA,IAAmBI;AAAA,EAAA,GAE7D,CAACG,GAAaC,CAAc,IAAIC,EAASL,CAAO,GAEhDM,IAAUH,MAAgBP,GAC1BW,IAASJ,MAAgBJ;AAsB/B,SAAO;AAAA,IACL,QAAQA;AAAA,IACR,aAAAI;AAAA,IACA,SAAAG;AAAA,IACA,QAAAC;AAAA,IACA,MAzBW,MAAM;AACjB,MAAIA,KACJH,EAAe,CAACI,MAAaA,IAAW,CAAC;AAAA,IAAA;AAAA,IAwBzC,MArBW,MAAM;AACjB,MAAIF,KACJF,EAAe,CAACI,MAAaA,IAAW,CAAC;AAAA,IAAA;AAAA,IAoBzC,OAjBY,MAAMJ,EAAeH,EAAY,OAAO;AAAA,IAkBpD,KAhBU,CAACQ,MAAqC;AAChD,UAAIA,MAAU,QAAS,QAAOL,EAAeH,EAAY,OAAO;AAEhE,UADIQ,MAAU,UACVA,KAASV,EAAK,QAAOK,EAAeL,CAAG;AAC3C,UAAIU,KAASb,EAAkB,QAAOQ,EAAeR,CAAgB;AACrE,MAAAQ,EAAeK,CAAK;AAAA,IAAA;AAAA,EAWpB;AAEJ;"}
|
|
@@ -1 +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 ): {
|
|
1
|
+
{"version":3,"file":"useSticky.mjs","sources":["../../../../src/hooks/useSticky/useSticky.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\nimport type { HookTarget } from '@/utils/helpers';\n\nimport { getElement, isTarget } from '@/utils/helpers';\n\nimport type { StateRef } from '../useRefState/useRefState';\n\nimport { useRefState } from '../useRefState/useRefState';\n\n/** The use sticky return type */\nexport interface UseStickyReturn {\n stuck: boolean;\n}\n\n/** The use sticky axis type */\nexport type UseStickyAxis = 'horizontal' | 'vertical';\n\n/** The use sticky options type */\nexport interface UseStickyOptions {\n axis?: UseStickyAxis;\n root?: HookTarget;\n}\n\nexport interface UseSticky {\n (target: HookTarget, options?: UseStickyOptions): boolean;\n\n <Target extends Element>(\n options?: UseStickyOptions,\n target?: never\n ): {\n ref: StateRef<Target>;\n } & UseStickyReturn;\n}\n\n/**\n * @name UseSticky\n * @description - Hook that allows you to detect that your sticky component is stuck\n * @category Elements\n *\n * @overload\n * @param {HookTarget} target The target sticky element\n * @param {UseStickyAxis} [options.axis='vertical'] The axis of motion of the sticky component\n * @param {UseStickyRoot} [options.root=document] The element that contains your sticky component\n * @returns {UseStickyReturn} The state of the sticky\n *\n * @example\n * const stuck = useSticky(ref);\n *\n * @overload\n * @param {UseStickyAxis} [options.axis='vertical'] The axis of motion of the sticky component\n * @param {UseStickyRoot} [options.root=document] The element that contains your sticky component\n * @returns {{ stickyRef: StateRef<Target> } & UseStickyReturn} The state of the sticky\n *\n * @example\n * const { stuck, ref } = useSticky();\n */\nexport const useSticky = ((...params: any[]) => {\n const target = (isTarget(params[0]) ? params[0] : undefined) as HookTarget | undefined;\n const options = (target ? params[1] : params[0]) as UseStickyOptions;\n const axis = options?.axis ?? 'vertical';\n\n const internalRef = useRefState<Element>();\n const [stuck, setStuck] = useState(false);\n\n useEffect(() => {\n if (!target && !internalRef.state) return;\n\n const element = (target ? getElement(target) : internalRef.current) as Element;\n\n if (!element) return;\n\n const root = (options?.root ? getElement(options.root) : document) as Element;\n const elementOffsetTop =\n element.getBoundingClientRect().top + root.scrollTop - root.getBoundingClientRect().top;\n const elementOffsetLeft =\n element.getBoundingClientRect().left + root.scrollLeft - root.getBoundingClientRect().left;\n\n const onSticky = () => {\n if (axis === 'vertical') {\n const scrollTop = root.scrollTop;\n setStuck(scrollTop >= elementOffsetTop);\n }\n\n if (axis === 'horizontal') {\n const scrollLeft = root.scrollLeft;\n setStuck(scrollLeft >= elementOffsetLeft);\n }\n };\n\n root.addEventListener('scroll', onSticky);\n window.addEventListener('resize', onSticky);\n window.addEventListener('orientationchange', onSticky);\n\n onSticky();\n\n return () => {\n root.removeEventListener('scroll', onSticky);\n window.removeEventListener('resize', onSticky);\n window.removeEventListener('orientationchange', onSticky);\n };\n }, [target, internalRef.state, axis, options?.root]);\n\n if (target) return stuck;\n return {\n stuck,\n ref: internalRef\n };\n}) as UseSticky;\n"],"names":["useSticky","params","target","isTarget","options","axis","internalRef","useRefState","stuck","setStuck","useState","useEffect","element","getElement","root","elementOffsetTop","elementOffsetLeft","onSticky","scrollTop","scrollLeft"],"mappings":";;;;AAyDO,MAAMA,IAAa,IAAIC,MAAkB;AAC9C,QAAMC,IAAUC,EAASF,EAAO,CAAC,CAAC,IAAIA,EAAO,CAAC,IAAI,QAC5CG,IAAWF,IAASD,EAAO,CAAC,IAAIA,EAAO,CAAC,GACxCI,IAAOD,GAAS,QAAQ,YAExBE,IAAcC,EAAA,GACd,CAACC,GAAOC,CAAQ,IAAIC,EAAS,EAAK;AAwCxC,SAtCAC,EAAU,MAAM;AACd,QAAI,CAACT,KAAU,CAACI,EAAY,MAAO;AAEnC,UAAMM,IAAWV,IAASW,EAAWX,CAAM,IAAII,EAAY;AAE3D,QAAI,CAACM,EAAS;AAEd,UAAME,IAAQV,GAAS,OAAOS,EAAWT,EAAQ,IAAI,IAAI,UACnDW,IACJH,EAAQ,wBAAwB,MAAME,EAAK,YAAYA,EAAK,sBAAA,EAAwB,KAChFE,IACJJ,EAAQ,wBAAwB,OAAOE,EAAK,aAAaA,EAAK,sBAAA,EAAwB,MAElFG,IAAW,MAAM;AACrB,UAAIZ,MAAS,YAAY;AACvB,cAAMa,IAAYJ,EAAK;AACvB,QAAAL,EAASS,KAAaH,CAAgB;AAAA,MAAA;AAGxC,UAAIV,MAAS,cAAc;AACzB,cAAMc,IAAaL,EAAK;AACxB,QAAAL,EAASU,KAAcH,CAAiB;AAAA,MAAA;AAAA,IAC1C;AAGF,WAAAF,EAAK,iBAAiB,UAAUG,CAAQ,GACxC,OAAO,iBAAiB,UAAUA,CAAQ,GAC1C,OAAO,iBAAiB,qBAAqBA,CAAQ,GAErDA,EAAA,GAEO,MAAM;AACX,MAAAH,EAAK,oBAAoB,UAAUG,CAAQ,GAC3C,OAAO,oBAAoB,UAAUA,CAAQ,GAC7C,OAAO,oBAAoB,qBAAqBA,CAAQ;AAAA,IAAA;AAAA,EAC1D,GACC,CAACf,GAAQI,EAAY,OAAOD,GAAMD,GAAS,IAAI,CAAC,GAE/CF,IAAeM,IACZ;AAAA,IACL,OAAAA;AAAA,IACA,KAAKF;AAAA,EAAA;AAET;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useStorage.mjs","sources":["../../../../src/hooks/useStorage/useStorage.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\n/* The use storage initial value type */\nexport type UseStorageInitialValue<Value> = (() => Value) | Value;\n\n/* The use storage options type */\nexport interface UseStorageOptions<Value> {\n /* The initial value of the storage */\n initialValue?: UseStorageInitialValue<Value>;\n /* The storage to be used */\n storage?: Storage;\n /* The deserializer function to be invoked */\n deserializer?: (value: string) => Value;\n /* The serializer function to be invoked */\n serializer?: (value: Value) => string;\n}\n\n/* The use storage return type */\nexport interface UseStorageReturn<Value> {\n /* The value of the storage */\n value: Value;\n /* The error state of the storage */\n remove: () => void;\n /* The loading state of the storage */\n set: (value: Value) => void;\n}\n\nexport interface UseStorage {\n <Value>(key: string, options?: UseStorageOptions<Value>): UseStorageReturn<Value | undefined>;\n\n <Value>(\n key: string,\n initialValue?: UseStorageInitialValue<Value>\n ): UseStorageReturn<Value | undefined>;\n}\n\nexport const STORAGE_EVENT = 'reactuse-storage';\n\nexport const dispatchStorageEvent = (params: Partial<StorageEvent>) =>\n window.dispatchEvent(new StorageEvent(STORAGE_EVENT, params));\n\nconst setStorageItem = (storage: Storage, key: string, value: string) => {\n const oldValue = storage.getItem(key);\n\n storage.setItem(key, value);\n dispatchStorageEvent({\n key,\n oldValue,\n newValue: value,\n storageArea: storage\n });\n};\n\nconst removeStorageItem = (storage: Storage, key: string) => {\n const oldValue = storage.getItem(key);\n\n storage.removeItem(key);\n dispatchStorageEvent({ key, oldValue, newValue: null, storageArea: storage });\n};\n\nconst getStorageItem = (storage: Storage, key: string) => {\n const value = storage.getItem(key);\n if (!value) return undefined;\n return value;\n};\n\n/**\n * @name useStorage\n * @description - Hook that manages storage value\n * @category
|
|
1
|
+
{"version":3,"file":"useStorage.mjs","sources":["../../../../src/hooks/useStorage/useStorage.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\n/* The use storage initial value type */\nexport type UseStorageInitialValue<Value> = (() => Value) | Value;\n\n/* The use storage options type */\nexport interface UseStorageOptions<Value> {\n /* The initial value of the storage */\n initialValue?: UseStorageInitialValue<Value>;\n /* The storage to be used */\n storage?: Storage;\n /* The deserializer function to be invoked */\n deserializer?: (value: string) => Value;\n /* The serializer function to be invoked */\n serializer?: (value: Value) => string;\n}\n\n/* The use storage return type */\nexport interface UseStorageReturn<Value> {\n /* The value of the storage */\n value: Value;\n /* The error state of the storage */\n remove: () => void;\n /* The loading state of the storage */\n set: (value: Value) => void;\n}\n\nexport interface UseStorage {\n <Value>(key: string, options?: UseStorageOptions<Value>): UseStorageReturn<Value | undefined>;\n\n <Value>(\n key: string,\n initialValue?: UseStorageInitialValue<Value>\n ): UseStorageReturn<Value | undefined>;\n}\n\nexport const STORAGE_EVENT = 'reactuse-storage';\n\nexport const dispatchStorageEvent = (params: Partial<StorageEvent>) =>\n window.dispatchEvent(new StorageEvent(STORAGE_EVENT, params));\n\nconst setStorageItem = (storage: Storage, key: string, value: string) => {\n const oldValue = storage.getItem(key);\n\n storage.setItem(key, value);\n dispatchStorageEvent({\n key,\n oldValue,\n newValue: value,\n storageArea: storage\n });\n};\n\nconst removeStorageItem = (storage: Storage, key: string) => {\n const oldValue = storage.getItem(key);\n\n storage.removeItem(key);\n dispatchStorageEvent({ key, oldValue, newValue: null, storageArea: storage });\n};\n\nconst getStorageItem = (storage: Storage, key: string) => {\n const value = storage.getItem(key);\n if (!value) return undefined;\n return value;\n};\n\n/**\n * @name useStorage\n * @description - Hook that manages storage value\n * @category State\n *\n * @overload\n * @param {string} key The key of the storage\n * @param {UseStorageInitialValue<Value>} [initialValue] The initial value of the storage\n * @returns {UseStorageReturn<Value>} The value and the set function\n *\n * @overload\n * @param {string} key The key of the storage\n * @param {(value: Value) => string} [params.serializer] The serializer function\n * @param {(value: string) => Value} [params.deserializer] The deserializer function\n * @param {Storage} [params.storage] The storage\n * @param {UseStorageInitialValue<Value>} [params.initialValue] The initial value of the storage\n * @returns {UseStorageReturn<Value>} The value and the set function\n *\n * @example\n * const { value, set, remove } = useStorage('key', 'value');\n */\nexport const useStorage = (<Value>(key: string, params?: any): UseStorageReturn<Value> => {\n const options = (\n typeof params === 'object' &&\n params &&\n ('serializer' in params ||\n 'deserializer' in params ||\n 'initialValue' in params ||\n 'storage' in params)\n ? params\n : undefined\n ) as UseStorageOptions<Value>;\n\n const initialValue = (options ? options?.initialValue : params) as UseStorageInitialValue<Value>;\n\n if (typeof window === 'undefined') {\n const value = typeof initialValue === 'function' ? (initialValue as () => any)() : initialValue;\n return {\n value,\n set: () => {},\n remove: () => {}\n };\n }\n\n const serializer = (value: Value) => {\n if (options?.serializer) return options.serializer(value);\n if (typeof value === 'string') return value;\n return JSON.stringify(value);\n };\n\n const storage = options?.storage ?? window?.localStorage;\n\n const set = (value: Value) => setStorageItem(storage, key, serializer(value));\n const remove = () => removeStorageItem(storage, key);\n\n const deserializer = (value: string) => {\n if (options?.deserializer) return options.deserializer(value);\n if (value === 'undefined') return undefined as unknown as Value;\n\n try {\n return JSON.parse(value) as Value;\n } catch {\n return value as Value;\n }\n };\n\n const [value, setValue] = useState<Value | undefined>(() => {\n const storageValue = getStorageItem(storage, key);\n if (storageValue === undefined && initialValue !== undefined) {\n const value =\n typeof initialValue === 'function' ? (initialValue as () => Value)() : initialValue;\n setStorageItem(storage, key, serializer(value));\n return value;\n }\n return storageValue ? deserializer(storageValue) : undefined;\n });\n\n useEffect(() => {\n const onChange = () => {\n const storageValue = getStorageItem(storage, key);\n setValue(storageValue ? deserializer(storageValue) : undefined);\n };\n window.addEventListener(STORAGE_EVENT, onChange);\n return () => window.removeEventListener(STORAGE_EVENT, onChange);\n }, [key]);\n\n return {\n value: value as Value,\n set,\n remove\n };\n}) as UseStorage;\n"],"names":["STORAGE_EVENT","dispatchStorageEvent","params","setStorageItem","storage","key","value","oldValue","removeStorageItem","getStorageItem","useStorage","options","initialValue","serializer","set","remove","deserializer","setValue","useState","storageValue","useEffect","onChange"],"mappings":";AAoCO,MAAMA,IAAgB,oBAEhBC,IAAuB,CAACC,MACnC,OAAO,cAAc,IAAI,aAAaF,GAAeE,CAAM,CAAC,GAExDC,IAAiB,CAACC,GAAkBC,GAAaC,MAAkB;AACvE,QAAMC,IAAWH,EAAQ,QAAQC,CAAG;AAEpC,EAAAD,EAAQ,QAAQC,GAAKC,CAAK,GAC1BL,EAAqB;AAAA,IACnB,KAAAI;AAAA,IACA,UAAAE;AAAA,IACA,UAAUD;AAAA,IACV,aAAaF;AAAA,EAAA,CACd;AACH,GAEMI,IAAoB,CAACJ,GAAkBC,MAAgB;AAC3D,QAAME,IAAWH,EAAQ,QAAQC,CAAG;AAEpC,EAAAD,EAAQ,WAAWC,CAAG,GACtBJ,EAAqB,EAAE,KAAAI,GAAK,UAAAE,GAAU,UAAU,MAAM,aAAaH,GAAS;AAC9E,GAEMK,IAAiB,CAACL,GAAkBC,MAAgB;AACxD,QAAMC,IAAQF,EAAQ,QAAQC,CAAG;AACjC,MAAKC;AACL,WAAOA;AACT,GAuBaI,IAAc,CAAQL,GAAaH,MAA0C;AACxF,QAAMS,IACJ,OAAOT,KAAW,YAClBA,MACC,gBAAgBA,KACf,kBAAkBA,KAClB,kBAAkBA,KAClB,aAAaA,KACXA,IACA,QAGA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AAChB,CAAG,CAAC,GAED;AAAA,IACL,OAAAC;AAAA,IACA,KAAAQ;AAAA,IACA,QAAAC;AAAA,EAAA;AAEJ;"}
|
|
@@ -1,30 +1,29 @@
|
|
|
1
|
-
import { useState as
|
|
2
|
-
import { useRefState as
|
|
3
|
-
import { isTarget as
|
|
4
|
-
import { getElement as
|
|
1
|
+
import { useRef as a, useState as v, useEffect as g } from "react";
|
|
2
|
+
import { useRefState as A } from "../useRefState/useRefState.mjs";
|
|
3
|
+
import { isTarget as R } from "../../utils/helpers/isTarget.mjs";
|
|
4
|
+
import { getElement as b } from "../../utils/helpers/getElement.mjs";
|
|
5
5
|
const E = (...o) => {
|
|
6
|
-
const t =
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const n = t ? i(t) : r.current;
|
|
11
|
-
n && (c(e), n.setAttribute("dir", e));
|
|
6
|
+
const t = R(o[0]) ? o[0] : void 0, d = (t ? o[1] : o[0]) ?? "ltr", r = A(), n = a(null), i = () => (t ? b(t) : r.current)?.getAttribute("dir") ?? d, [u, c] = v(i()), s = () => {
|
|
7
|
+
n.current && n.current?.removeAttribute("dir");
|
|
8
|
+
}, f = (e) => {
|
|
9
|
+
n.current && (c(e), n.current.setAttribute("dir", e));
|
|
12
10
|
};
|
|
13
|
-
return
|
|
11
|
+
return g(() => {
|
|
14
12
|
if (!t && !r.state) return;
|
|
15
|
-
const e = t ?
|
|
13
|
+
const e = (t ? b(t) : r.current) ?? document.querySelector("html");
|
|
16
14
|
if (!e) return;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
15
|
+
n.current = e;
|
|
16
|
+
const l = i();
|
|
17
|
+
e.setAttribute("dir", l), c(l);
|
|
18
|
+
const m = new MutationObserver(i);
|
|
19
|
+
return m.observe(e, { attributes: !0 }), () => {
|
|
20
|
+
m.disconnect();
|
|
22
21
|
};
|
|
23
|
-
}, [r.state, t]), t ? { value: u, set:
|
|
22
|
+
}, [r.state, t]), t ? { value: u, set: f, remove: s } : {
|
|
24
23
|
ref: r,
|
|
25
24
|
value: u,
|
|
26
|
-
set:
|
|
27
|
-
remove:
|
|
25
|
+
set: f,
|
|
26
|
+
remove: s
|
|
28
27
|
};
|
|
29
28
|
};
|
|
30
29
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useTextDirection.mjs","sources":["../../../../src/hooks/useTextDirection/useTextDirection.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 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
|
|
1
|
+
{"version":3,"file":"useTextDirection.mjs","sources":["../../../../src/hooks/useTextDirection/useTextDirection.ts"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\n\nimport type { HookTarget } from '@/utils/helpers';\n\nimport { getElement, isTarget } from '@/utils/helpers';\n\nimport type { StateRef } from '../useRefState/useRefState';\n\nimport { useRefState } from '../useRefState/useRefState';\n\n/** The 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 Elements\n *\n * @overload\n * @param {HookTarget} [target=document.querySelector('html')] 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();\n const elementRef = useRef<Element>(null);\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 if (!elementRef.current) return;\n\n elementRef.current?.removeAttribute('dir');\n };\n\n const set = (value: UseTextDirectionValue) => {\n if (!elementRef.current) return;\n\n setValue(value);\n elementRef.current.setAttribute('dir', value);\n };\n\n useEffect(() => {\n if (!target && !internalRef.state) return;\n\n const element =\n ((target ? getElement(target) : internalRef.current) as Element) ??\n document.querySelector('html');\n if (!element) return;\n\n elementRef.current = element;\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","elementRef","useRef","getDirection","getElement","value","setValue","useState","remove","set","useEffect","element","direction","observer"],"mappings":";;;;AAqDO,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,GACdC,IAAaC,EAAgB,IAAI,GAEjCC,IAAe,OACFP,IAASQ,EAAWR,CAAM,IAAIG,EAAY,UAC1C,aAAa,KAAK,KAA+BD,GAG9D,CAACO,GAAOC,CAAQ,IAAIC,EAAgCJ,GAAc,GAElEK,IAAS,MAAM;AACnB,IAAKP,EAAW,WAEhBA,EAAW,SAAS,gBAAgB,KAAK;AAAA,EAAA,GAGrCQ,IAAM,CAACJ,MAAiC;AAC5C,IAAKJ,EAAW,YAEhBK,EAASD,CAAK,GACdJ,EAAW,QAAQ,aAAa,OAAOI,CAAK;AAAA,EAAA;AA0B9C,SAvBAK,EAAU,MAAM;AACd,QAAI,CAACd,KAAU,CAACG,EAAY,MAAO;AAEnC,UAAMY,KACFf,IAASQ,EAAWR,CAAM,IAAIG,EAAY,YAC5C,SAAS,cAAc,MAAM;AAC/B,QAAI,CAACY,EAAS;AAEd,IAAAV,EAAW,UAAUU;AAErB,UAAMC,IAAYT,EAAA;AAClB,IAAAQ,EAAQ,aAAa,OAAOC,CAAS,GACrCN,EAASM,CAAS;AAElB,UAAMC,IAAW,IAAI,iBAAiBV,CAAY;AAElD,WAAAU,EAAS,QAAQF,GAAS,EAAE,YAAY,IAAM,GAEvC,MAAM;AACX,MAAAE,EAAS,WAAA;AAAA,IAAW;AAAA,EACtB,GACC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