@siberiacancode/reactuse 0.3.1 → 0.3.2
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/hooks/useActiveElement/useActiveElement.cjs +1 -1
- package/dist/cjs/hooks/useActiveElement/useActiveElement.cjs.map +1 -1
- package/dist/cjs/hooks/useAutoScroll/useAutoScroll.cjs +1 -1
- package/dist/cjs/hooks/useAutoScroll/useAutoScroll.cjs.map +1 -1
- package/dist/cjs/hooks/useClickOutside/useClickOutside.cjs +1 -1
- package/dist/cjs/hooks/useClickOutside/useClickOutside.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/useDisplayMedia/useDisplayMedia.cjs +1 -1
- package/dist/cjs/hooks/useDisplayMedia/useDisplayMedia.cjs.map +1 -1
- package/dist/cjs/hooks/useDocumentEvent/useDocumentEvent.cjs +1 -1
- package/dist/cjs/hooks/useDocumentEvent/useDocumentEvent.cjs.map +1 -1
- package/dist/cjs/hooks/useDoubleClick/useDoubleClick.cjs +1 -1
- package/dist/cjs/hooks/useDoubleClick/useDoubleClick.cjs.map +1 -1
- package/dist/cjs/hooks/useDropZone/useDropZone.cjs +1 -1
- package/dist/cjs/hooks/useDropZone/useDropZone.cjs.map +1 -1
- package/dist/cjs/hooks/useElementSize/useElementSize.cjs +1 -1
- package/dist/cjs/hooks/useElementSize/useElementSize.cjs.map +1 -1
- package/dist/cjs/hooks/useEventListener/useEventListener.cjs +1 -1
- package/dist/cjs/hooks/useEventListener/useEventListener.cjs.map +1 -1
- package/dist/cjs/hooks/useFocus/useFocus.cjs +1 -1
- package/dist/cjs/hooks/useFocus/useFocus.cjs.map +1 -1
- package/dist/cjs/hooks/useFocusTrap/useFocusTrap.cjs +1 -1
- package/dist/cjs/hooks/useFocusTrap/useFocusTrap.cjs.map +1 -1
- package/dist/cjs/hooks/useFullscreen/useFullscreen.cjs +1 -1
- package/dist/cjs/hooks/useFullscreen/useFullscreen.cjs.map +1 -1
- package/dist/cjs/hooks/useHash/useHash.cjs.map +1 -1
- package/dist/cjs/hooks/useHotkeys/useHotkeys.cjs +1 -1
- package/dist/cjs/hooks/useHotkeys/useHotkeys.cjs.map +1 -1
- package/dist/cjs/hooks/useHover/useHover.cjs +1 -1
- package/dist/cjs/hooks/useHover/useHover.cjs.map +1 -1
- package/dist/cjs/hooks/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/useKeyPress/useKeyPress.cjs +1 -1
- package/dist/cjs/hooks/useKeyPress/useKeyPress.cjs.map +1 -1
- package/dist/cjs/hooks/useKeyPressEvent/useKeyPressEvent.cjs +1 -1
- package/dist/cjs/hooks/useKeyPressEvent/useKeyPressEvent.cjs.map +1 -1
- package/dist/cjs/hooks/useKeyboard/useKeyboard.cjs +1 -1
- package/dist/cjs/hooks/useKeyboard/useKeyboard.cjs.map +1 -1
- package/dist/cjs/hooks/useKeysPressed/useKeysPressed.cjs +1 -1
- package/dist/cjs/hooks/useKeysPressed/useKeysPressed.cjs.map +1 -1
- package/dist/cjs/hooks/useLockScroll/useLockScroll.cjs +1 -1
- package/dist/cjs/hooks/useLockScroll/useLockScroll.cjs.map +1 -1
- package/dist/cjs/hooks/useLongPress/useLongPress.cjs +1 -1
- package/dist/cjs/hooks/useLongPress/useLongPress.cjs.map +1 -1
- package/dist/cjs/hooks/useMeasure/useMeasure.cjs +1 -1
- package/dist/cjs/hooks/useMeasure/useMeasure.cjs.map +1 -1
- package/dist/cjs/hooks/useMediaControls/useMediaControls.cjs +1 -1
- package/dist/cjs/hooks/useMediaControls/useMediaControls.cjs.map +1 -1
- package/dist/cjs/hooks/useMouse/useMouse.cjs +1 -1
- package/dist/cjs/hooks/useMouse/useMouse.cjs.map +1 -1
- package/dist/cjs/hooks/useMutationObserver/useMutationObserver.cjs +1 -1
- package/dist/cjs/hooks/useMutationObserver/useMutationObserver.cjs.map +1 -1
- package/dist/cjs/hooks/usePaint/usePaint.cjs +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/usePictureInPicture/usePictureInPicture.cjs +1 -1
- package/dist/cjs/hooks/usePictureInPicture/usePictureInPicture.cjs.map +1 -1
- package/dist/cjs/hooks/useResizeObserver/useResizeObserver.cjs +1 -1
- package/dist/cjs/hooks/useResizeObserver/useResizeObserver.cjs.map +1 -1
- package/dist/cjs/hooks/useRightClick/useRightClick.cjs +1 -1
- package/dist/cjs/hooks/useRightClick/useRightClick.cjs.map +1 -1
- package/dist/cjs/hooks/useScroll/useScroll.cjs +1 -1
- package/dist/cjs/hooks/useScroll/useScroll.cjs.map +1 -1
- package/dist/cjs/hooks/useScrollIntoView/useScrollIntoView.cjs +1 -1
- package/dist/cjs/hooks/useScrollIntoView/useScrollIntoView.cjs.map +1 -1
- package/dist/cjs/hooks/useScrollTo/useScrollTo.cjs +1 -1
- package/dist/cjs/hooks/useScrollTo/useScrollTo.cjs.map +1 -1
- package/dist/cjs/hooks/useSticky/useSticky.cjs +1 -1
- package/dist/cjs/hooks/useSticky/useSticky.cjs.map +1 -1
- package/dist/cjs/hooks/useTextDirection/useTextDirection.cjs +1 -1
- package/dist/cjs/hooks/useTextDirection/useTextDirection.cjs.map +1 -1
- package/dist/cjs/hooks/useVisibility/useVisibility.cjs +1 -1
- package/dist/cjs/hooks/useVisibility/useVisibility.cjs.map +1 -1
- package/dist/cjs/hooks/useWindowEvent/useWindowEvent.cjs +1 -1
- package/dist/cjs/hooks/useWindowEvent/useWindowEvent.cjs.map +1 -1
- package/dist/cjs/hooks/useWindowSize/useWindowSize.cjs +1 -1
- package/dist/cjs/hooks/useWindowSize/useWindowSize.cjs.map +1 -1
- package/dist/cjs/index.cjs +1 -1
- package/dist/cjs/utils/helpers/isTarget.cjs +1 -1
- package/dist/cjs/utils/helpers/isTarget.cjs.map +1 -1
- package/dist/esm/hooks/useActiveElement/useActiveElement.mjs +8 -9
- package/dist/esm/hooks/useActiveElement/useActiveElement.mjs.map +1 -1
- package/dist/esm/hooks/useAutoScroll/useAutoScroll.mjs +12 -13
- package/dist/esm/hooks/useAutoScroll/useAutoScroll.mjs.map +1 -1
- package/dist/esm/hooks/useClickOutside/useClickOutside.mjs +8 -9
- package/dist/esm/hooks/useClickOutside/useClickOutside.mjs.map +1 -1
- package/dist/esm/hooks/useCssVar/useCssVar.mjs +19 -20
- package/dist/esm/hooks/useCssVar/useCssVar.mjs.map +1 -1
- package/dist/esm/hooks/useDisplayMedia/useDisplayMedia.mjs +15 -16
- package/dist/esm/hooks/useDisplayMedia/useDisplayMedia.mjs.map +1 -1
- package/dist/esm/hooks/useDocumentEvent/useDocumentEvent.mjs +3 -3
- package/dist/esm/hooks/useDocumentEvent/useDocumentEvent.mjs.map +1 -1
- package/dist/esm/hooks/useDoubleClick/useDoubleClick.mjs +17 -18
- package/dist/esm/hooks/useDoubleClick/useDoubleClick.mjs.map +1 -1
- package/dist/esm/hooks/useDropZone/useDropZone.mjs +17 -18
- package/dist/esm/hooks/useDropZone/useDropZone.mjs.map +1 -1
- package/dist/esm/hooks/useElementSize/useElementSize.mjs +12 -12
- package/dist/esm/hooks/useElementSize/useElementSize.mjs.map +1 -1
- package/dist/esm/hooks/useEventListener/useEventListener.mjs +11 -12
- package/dist/esm/hooks/useEventListener/useEventListener.mjs.map +1 -1
- package/dist/esm/hooks/useFocus/useFocus.mjs +13 -14
- package/dist/esm/hooks/useFocus/useFocus.mjs.map +1 -1
- package/dist/esm/hooks/useFocusTrap/useFocusTrap.mjs +18 -19
- package/dist/esm/hooks/useFocusTrap/useFocusTrap.mjs.map +1 -1
- package/dist/esm/hooks/useFullscreen/useFullscreen.mjs +11 -12
- package/dist/esm/hooks/useFullscreen/useFullscreen.mjs.map +1 -1
- package/dist/esm/hooks/useHash/useHash.mjs.map +1 -1
- package/dist/esm/hooks/useHotkeys/useHotkeys.mjs +8 -9
- package/dist/esm/hooks/useHotkeys/useHotkeys.mjs.map +1 -1
- package/dist/esm/hooks/useHover/useHover.mjs +12 -13
- package/dist/esm/hooks/useHover/useHover.mjs.map +1 -1
- package/dist/esm/hooks/useInfiniteScroll/useInfiniteScroll.mjs +11 -12
- package/dist/esm/hooks/useInfiniteScroll/useInfiniteScroll.mjs.map +1 -1
- package/dist/esm/hooks/useIntersectionObserver/useIntersectionObserver.mjs +19 -20
- package/dist/esm/hooks/useIntersectionObserver/useIntersectionObserver.mjs.map +1 -1
- package/dist/esm/hooks/useKeyPress/useKeyPress.mjs +8 -9
- package/dist/esm/hooks/useKeyPress/useKeyPress.mjs.map +1 -1
- package/dist/esm/hooks/useKeyPressEvent/useKeyPressEvent.mjs +11 -12
- package/dist/esm/hooks/useKeyPressEvent/useKeyPressEvent.mjs.map +1 -1
- package/dist/esm/hooks/useKeyboard/useKeyboard.mjs +11 -12
- package/dist/esm/hooks/useKeyboard/useKeyboard.mjs.map +1 -1
- package/dist/esm/hooks/useKeysPressed/useKeysPressed.mjs +11 -12
- package/dist/esm/hooks/useKeysPressed/useKeysPressed.mjs.map +1 -1
- package/dist/esm/hooks/useLockScroll/useLockScroll.mjs +12 -13
- package/dist/esm/hooks/useLockScroll/useLockScroll.mjs.map +1 -1
- package/dist/esm/hooks/useLongPress/useLongPress.mjs +13 -14
- package/dist/esm/hooks/useLongPress/useLongPress.mjs.map +1 -1
- package/dist/esm/hooks/useMeasure/useMeasure.mjs +15 -16
- package/dist/esm/hooks/useMeasure/useMeasure.mjs.map +1 -1
- package/dist/esm/hooks/useMediaControls/useMediaControls.mjs +32 -33
- package/dist/esm/hooks/useMediaControls/useMediaControls.mjs.map +1 -1
- package/dist/esm/hooks/useMouse/useMouse.mjs +12 -13
- package/dist/esm/hooks/useMouse/useMouse.mjs.map +1 -1
- package/dist/esm/hooks/useMutationObserver/useMutationObserver.mjs +11 -12
- package/dist/esm/hooks/useMutationObserver/useMutationObserver.mjs.map +1 -1
- package/dist/esm/hooks/usePaint/usePaint.mjs +23 -24
- package/dist/esm/hooks/usePaint/usePaint.mjs.map +1 -1
- package/dist/esm/hooks/useParallax/useParallax.mjs +31 -32
- package/dist/esm/hooks/useParallax/useParallax.mjs.map +1 -1
- package/dist/esm/hooks/usePictureInPicture/usePictureInPicture.mjs +11 -12
- package/dist/esm/hooks/usePictureInPicture/usePictureInPicture.mjs.map +1 -1
- package/dist/esm/hooks/useResizeObserver/useResizeObserver.mjs +11 -12
- package/dist/esm/hooks/useResizeObserver/useResizeObserver.mjs.map +1 -1
- package/dist/esm/hooks/useRightClick/useRightClick.mjs +11 -12
- package/dist/esm/hooks/useRightClick/useRightClick.mjs.map +1 -1
- package/dist/esm/hooks/useScroll/useScroll.mjs +12 -13
- package/dist/esm/hooks/useScroll/useScroll.mjs.map +1 -1
- package/dist/esm/hooks/useScrollIntoView/useScrollIntoView.mjs +20 -21
- package/dist/esm/hooks/useScrollIntoView/useScrollIntoView.mjs.map +1 -1
- package/dist/esm/hooks/useScrollTo/useScrollTo.mjs +13 -14
- package/dist/esm/hooks/useScrollTo/useScrollTo.mjs.map +1 -1
- package/dist/esm/hooks/useSticky/useSticky.mjs +11 -12
- package/dist/esm/hooks/useSticky/useSticky.mjs.map +1 -1
- package/dist/esm/hooks/useTextDirection/useTextDirection.mjs +21 -22
- package/dist/esm/hooks/useTextDirection/useTextDirection.mjs.map +1 -1
- package/dist/esm/hooks/useVisibility/useVisibility.mjs +13 -14
- package/dist/esm/hooks/useVisibility/useVisibility.mjs.map +1 -1
- package/dist/esm/hooks/useWindowEvent/useWindowEvent.mjs +4 -4
- package/dist/esm/hooks/useWindowEvent/useWindowEvent.mjs.map +1 -1
- package/dist/esm/hooks/useWindowSize/useWindowSize.mjs +12 -16
- package/dist/esm/hooks/useWindowSize/useWindowSize.mjs.map +1 -1
- package/dist/esm/index.mjs +62 -64
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/utils/helpers/isTarget.mjs +9 -3
- package/dist/esm/utils/helpers/isTarget.mjs.map +1 -1
- package/dist/types/hooks/useHash/useHash.d.ts +18 -5
- package/dist/types/utils/helpers/index.d.ts +0 -1
- package/dist/types/utils/helpers/isTarget.d.ts +19 -2
- package/package.json +1 -1
- package/dist/cjs/utils/helpers/getElement.cjs +0 -2
- package/dist/cjs/utils/helpers/getElement.cjs.map +0 -1
- package/dist/esm/utils/helpers/getElement.mjs +0 -10
- package/dist/esm/utils/helpers/getElement.mjs.map +0 -1
- package/dist/types/utils/helpers/getElement.d.ts +0 -12
|
@@ -1,32 +1,31 @@
|
|
|
1
|
-
import { useRef as a, useState as
|
|
1
|
+
import { useRef as a, useState as g, useEffect as v } from "react";
|
|
2
2
|
import { useRefState as A } from "../useRefState/useRefState.mjs";
|
|
3
|
-
import { isTarget as
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
const t = R(o[0]) ? o[0] : void 0, c = (t ? o[1] : o[0]) ?? "ltr", r = A(), n = a(null), i = () => typeof window > "u" ? c : (t ? b(t) : r.current)?.getAttribute("dir") ?? c, [s, u] = v(i()), f = () => {
|
|
3
|
+
import { isTarget as c } from "../../utils/helpers/isTarget.mjs";
|
|
4
|
+
const S = (...i) => {
|
|
5
|
+
const e = c(i[0]) ? i[0] : void 0, s = (e ? i[1] : i[0]) ?? "ltr", r = A(), n = a(null), o = () => typeof window > "u" ? s : (e ? c.getElement(e) : r.current)?.getAttribute("dir") ?? s, [f, u] = g(o()), l = () => {
|
|
7
6
|
n.current && n.current?.removeAttribute("dir");
|
|
8
|
-
},
|
|
9
|
-
n.current && (u(
|
|
7
|
+
}, m = (t) => {
|
|
8
|
+
n.current && (u(t), n.current.setAttribute("dir", t));
|
|
10
9
|
};
|
|
11
|
-
return
|
|
12
|
-
if (!
|
|
13
|
-
const
|
|
14
|
-
if (!
|
|
15
|
-
n.current =
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
const
|
|
19
|
-
return
|
|
20
|
-
|
|
10
|
+
return v(() => {
|
|
11
|
+
if (!e && !r.state) return;
|
|
12
|
+
const t = (e ? c.getElement(e) : r.current) ?? document.querySelector("html");
|
|
13
|
+
if (!t) return;
|
|
14
|
+
n.current = t;
|
|
15
|
+
const d = o();
|
|
16
|
+
t.setAttribute("dir", d), u(d);
|
|
17
|
+
const b = new MutationObserver(() => u(o()));
|
|
18
|
+
return b.observe(t, { attributes: !0 }), () => {
|
|
19
|
+
b.disconnect();
|
|
21
20
|
};
|
|
22
|
-
}, [r.state,
|
|
21
|
+
}, [r.state, e]), e ? { value: f, set: m, remove: l } : {
|
|
23
22
|
ref: r,
|
|
24
|
-
value:
|
|
25
|
-
set:
|
|
26
|
-
remove:
|
|
23
|
+
value: f,
|
|
24
|
+
set: m,
|
|
25
|
+
remove: l
|
|
27
26
|
};
|
|
28
27
|
};
|
|
29
28
|
export {
|
|
30
|
-
|
|
29
|
+
S as useTextDirection
|
|
31
30
|
};
|
|
32
31
|
//# sourceMappingURL=useTextDirection.mjs.map
|
|
@@ -1 +1 @@
|
|
|
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 {
|
|
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 { 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 * @usage medium\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 if (typeof window === 'undefined') return initialValue;\n const element = (target ? isTarget.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 ? isTarget.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(() => setValue(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","value","setValue","useState","remove","set","useEffect","element","direction","observer"],"mappings":";;;AAsDO,MAAMA,IAAoB,IAAIC,MAAkB;AACrD,QAAMC,IAAUC,EAASF,EAAO,CAAC,CAAC,IAAIA,EAAO,CAAC,IAAI,QAC5CG,KAAiBF,IAASD,EAAO,CAAC,IAAIA,EAAO,CAAC,MAAgC,OAE9EI,IAAcC,EAAA,GACdC,IAAaC,EAAgB,IAAI,GAEjCC,IAAe,MACf,OAAO,SAAW,MAAoBL,KACzBF,IAASC,EAAS,WAAWD,CAAM,IAAIG,EAAY,UACnD,aAAa,KAAK,KAA+BD,GAG9D,CAACM,GAAOC,CAAQ,IAAIC,EAAgCH,GAAc,GAElEI,IAAS,MAAM;AACnB,IAAKN,EAAW,WAEhBA,EAAW,SAAS,gBAAgB,KAAK;AAAA,EAAA,GAGrCO,IAAM,CAACJ,MAAiC;AAC5C,IAAKH,EAAW,YAEhBI,EAASD,CAAK,GACdH,EAAW,QAAQ,aAAa,OAAOG,CAAK;AAAA,EAAA;AA0B9C,SAvBAK,EAAU,MAAM;AACd,QAAI,CAACb,KAAU,CAACG,EAAY,MAAO;AAEnC,UAAMW,KACFd,IAASC,EAAS,WAAWD,CAAM,IAAIG,EAAY,YACrD,SAAS,cAAc,MAAM;AAC/B,QAAI,CAACW,EAAS;AAEd,IAAAT,EAAW,UAAUS;AAErB,UAAMC,IAAYR,EAAA;AAClB,IAAAO,EAAQ,aAAa,OAAOC,CAAS,GACrCN,EAASM,CAAS;AAElB,UAAMC,IAAW,IAAI,iBAAiB,MAAMP,EAASF,EAAA,CAAc,CAAC;AAEpE,WAAAS,EAAS,QAAQF,GAAS,EAAE,YAAY,IAAM,GAEvC,MAAM;AACX,MAAAE,EAAS,WAAA;AAAA,IAAW;AAAA,EACtB,GACC,CAACb,EAAY,OAAOH,CAAM,CAAC,GAE1BA,IAAe,EAAE,OAAAQ,GAAO,KAAAI,GAAK,QAAAD,EAAA,IAC1B;AAAA,IACL,KAAKR;AAAA,IACL,OAAAK;AAAA,IACA,KAAAI;AAAA,IACA,QAAAD;AAAA,EAAA;AAEJ;"}
|
|
@@ -1,34 +1,33 @@
|
|
|
1
|
-
import { useState as
|
|
1
|
+
import { useState as d, useRef as C, useEffect as E } from "react";
|
|
2
2
|
import { useRefState as R } from "../useRefState/useRefState.mjs";
|
|
3
|
-
import { isTarget as
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const b = n ? d(n) : r.current;
|
|
3
|
+
import { isTarget as c } from "../../utils/helpers/isTarget.mjs";
|
|
4
|
+
const V = (...e) => {
|
|
5
|
+
const n = c(e[0]) ? e[0] : void 0, t = n ? typeof e[1] == "object" ? e[1] : { onChange: e[1] } : typeof e[0] == "object" ? e[0] : { onChange: e[0] }, i = t?.onChange, f = t?.enabled ?? !0, [u, v] = d(), [o, y] = d(), r = R(), l = C(i);
|
|
6
|
+
return l.current = i, E(() => {
|
|
7
|
+
if (!f || !n && !r.state) return;
|
|
8
|
+
const b = n ? c.getElement(n) : r.current;
|
|
10
9
|
if (!b) return;
|
|
11
10
|
const s = new IntersectionObserver(
|
|
12
11
|
(h, a) => {
|
|
13
|
-
const
|
|
14
|
-
y(
|
|
12
|
+
const g = h.pop();
|
|
13
|
+
y(g), l.current?.(g, a);
|
|
15
14
|
},
|
|
16
15
|
{
|
|
17
16
|
...t,
|
|
18
|
-
root: t?.root ?
|
|
17
|
+
root: t?.root ? c.getElement(t.root) : document
|
|
19
18
|
}
|
|
20
19
|
);
|
|
21
20
|
return v(s), s.observe(b), () => {
|
|
22
21
|
s.disconnect();
|
|
23
22
|
};
|
|
24
|
-
}, [n, r.state, t?.rootMargin, t?.threshold, t?.root,
|
|
25
|
-
observer:
|
|
23
|
+
}, [n, r.state, t?.rootMargin, t?.threshold, t?.root, f]), n ? { observer: u, entry: o, inView: !!o?.isIntersecting } : {
|
|
24
|
+
observer: u,
|
|
26
25
|
ref: r,
|
|
27
26
|
entry: o,
|
|
28
27
|
inView: !!o?.isIntersecting
|
|
29
28
|
};
|
|
30
29
|
};
|
|
31
30
|
export {
|
|
32
|
-
|
|
31
|
+
V as useVisibility
|
|
33
32
|
};
|
|
34
33
|
//# sourceMappingURL=useVisibility.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useVisibility.mjs","sources":["../../../../src/hooks/useVisibility/useVisibility.ts"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\n\nimport type { HookTarget } from '@/utils/helpers';\n\nimport {
|
|
1
|
+
{"version":3,"file":"useVisibility.mjs","sources":["../../../../src/hooks/useVisibility/useVisibility.ts"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\n\nimport type { HookTarget } from '@/utils/helpers';\n\nimport { isTarget } from '@/utils/helpers';\n\nimport type { StateRef } from '../useRefState/useRefState';\n\nimport { useRefState } from '../useRefState/useRefState';\n\n/** The visibility callback type */\nexport type UseVisibilityCallback = (\n entry: IntersectionObserverEntry,\n observer: IntersectionObserver\n) => void;\n\n/** The visibility options type */\nexport interface UseVisibilityOptions extends Omit<IntersectionObserverInit, 'root'> {\n /** The enabled state of the intersection */\n enabled?: boolean;\n /** The callback to execute when intersection is detected */\n onChange?: UseVisibilityCallback;\n /** The root element to observe */\n root?: HookTarget;\n}\n\n/** The intersection observer return type */\nexport interface UseVisibilityReturn {\n /** The intersection observer entry */\n entry?: IntersectionObserverEntry;\n /** The intersection observer in view */\n inView?: boolean;\n\n /** The intersection observer instance */\n observer?: IntersectionObserver;\n}\n\nexport interface UseVisibility {\n <Target extends Element>(\n options?: UseVisibilityOptions,\n target?: never\n ): UseVisibilityReturn & { ref: StateRef<Target> };\n\n (target: HookTarget, options?: UseVisibilityOptions): UseVisibilityReturn;\n\n <Target extends Element>(\n callback: UseVisibilityCallback,\n target?: never\n ): UseVisibilityReturn & { ref: StateRef<Target> };\n\n (target: HookTarget, callback: UseVisibilityCallback): UseVisibilityReturn;\n}\n\n/**\n * @name useVisibility\n * @description - Hook that gives you visibility observer state\n * @category Sensors\n * @usage medium\n *\n * @browserapi IntersectionObserver https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserver\n *\n * @overload\n * @param {HookTarget} target The target element to detect intersection\n * @param {boolean} [options.enabled=true] The Intersection options\n * @param {((entries: IntersectionEntry[], observer: Intersection) => void) | undefined} [options.onChange] The callback to execute when intersection is detected\n * @param {HookTarget} [options.root=document] The root element to observe\n * @returns {UseVisibilityReturn} An object containing the state\n *\n * @example\n * const { ref, entries, observer } = useVisibility();\n *\n * @overload\n * @template Target The target element\n * @param {boolean} [options.enabled=true] The Intersection options\n * @param {((entries: IntersectionEntry[], observer: Intersection) => void) | undefined} [options.onChange] The callback to execute when intersection is detected\n * @param {HookTarget} [options.root=document] The root element to observe\n * @returns {UseVisibilityReturn & { ref: StateRef<Target> }} A React ref to attach to the target element\n *\n * @example\n * const { entries, observer } = useVisibility(ref);\n *\n * @overload\n * @template Target The target element\n * @param {UseVisibilityCallback} callback The callback to execute when intersection is detected\n * @returns {UseVisibilityReturn & { ref: StateRef<Target> }} A React ref to attach to the target element\n *\n * @example\n * const { ref, entries, observer } = useVisibility(() => console.log('callback'));\n *\n * @overload\n * @param {UseVisibilityCallback} callback The callback to execute when intersection is detected\n * @param {HookTarget} target The target element to detect intersection\n * @returns {UseVisibilityReturn} An object containing the state\n *\n * @example\n * const { entries, observer } = useVisibility(ref, () => console.log('callback'));\n */\nexport const useVisibility = ((...params: any[]) => {\n const target = (isTarget(params[0]) ? params[0] : undefined) as HookTarget | undefined;\n\n const options = (\n target\n ? typeof params[1] === 'object'\n ? params[1]\n : { onChange: params[1] }\n : typeof params[0] === 'object'\n ? params[0]\n : { onChange: params[0] }\n ) as UseVisibilityOptions | undefined;\n\n const callback = options?.onChange;\n const enabled = options?.enabled ?? true;\n\n const [observer, setObserver] = useState<IntersectionObserver>();\n const [entry, setEntry] = useState<IntersectionObserverEntry>();\n\n const internalRef = useRefState<Element>();\n const internalCallbackRef = useRef(callback);\n internalCallbackRef.current = callback;\n\n useEffect(() => {\n if (!enabled || (!target && !internalRef.state)) return;\n\n const element = target ? isTarget.getElement(target) : internalRef.current;\n if (!element) return;\n\n const observer = new IntersectionObserver(\n (entries: IntersectionObserverEntry[], observer: IntersectionObserver) => {\n const entry = entries.pop()!;\n setEntry(entry);\n internalCallbackRef.current?.(entry, observer);\n },\n {\n ...options,\n root: options?.root ? (isTarget.getElement(options.root) as Document | Element) : document\n }\n );\n\n setObserver(observer);\n observer.observe(element as Element);\n\n return () => {\n observer.disconnect();\n };\n }, [target, internalRef.state, options?.rootMargin, options?.threshold, options?.root, enabled]);\n\n if (target) return { observer, entry, inView: !!entry?.isIntersecting };\n return {\n observer,\n ref: internalRef,\n entry,\n inView: !!entry?.isIntersecting\n };\n}) as UseVisibility;\n"],"names":["useVisibility","params","target","isTarget","options","callback","enabled","observer","setObserver","useState","entry","setEntry","internalRef","useRefState","internalCallbackRef","useRef","useEffect","element","entries"],"mappings":";;;AAiGO,MAAMA,IAAiB,IAAIC,MAAkB;AAClD,QAAMC,IAAUC,EAASF,EAAO,CAAC,CAAC,IAAIA,EAAO,CAAC,IAAI,QAE5CG,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,IAAWD,GAAS,UACpBE,IAAUF,GAAS,WAAW,IAE9B,CAACG,GAAUC,CAAW,IAAIC,EAAA,GAC1B,CAACC,GAAOC,CAAQ,IAAIF,EAAA,GAEpBG,IAAcC,EAAA,GACdC,IAAsBC,EAAOV,CAAQ;AA6B3C,SA5BAS,EAAoB,UAAUT,GAE9BW,EAAU,MAAM;AACd,QAAI,CAACV,KAAY,CAACJ,KAAU,CAACU,EAAY,MAAQ;AAEjD,UAAMK,IAAUf,IAASC,EAAS,WAAWD,CAAM,IAAIU,EAAY;AACnE,QAAI,CAACK,EAAS;AAEd,UAAMV,IAAW,IAAI;AAAA,MACnB,CAACW,GAAsCX,MAAmC;AACxE,cAAMG,IAAQQ,EAAQ,IAAA;AACtB,QAAAP,EAASD,CAAK,GACdI,EAAoB,UAAUJ,GAAOH,CAAQ;AAAA,MAAA;AAAA,MAE/C;AAAA,QACE,GAAGH;AAAA,QACH,MAAMA,GAAS,OAAQD,EAAS,WAAWC,EAAQ,IAAI,IAA2B;AAAA,MAAA;AAAA,IACpF;AAGF,WAAAI,EAAYD,CAAQ,GACpBA,EAAS,QAAQU,CAAkB,GAE5B,MAAM;AACXV,MAAAA,EAAS,WAAA;AAAA,IAAW;AAAA,EACtB,GACC,CAACL,GAAQU,EAAY,OAAOR,GAAS,YAAYA,GAAS,WAAWA,GAAS,MAAME,CAAO,CAAC,GAE3FJ,IAAe,EAAE,UAAAK,GAAU,OAAAG,GAAO,QAAQ,CAAC,CAACA,GAAO,eAAA,IAChD;AAAA,IACL,UAAAH;AAAA,IACA,KAAKK;AAAA,IACL,OAAAF;AAAA,IACA,QAAQ,CAAC,CAACA,GAAO;AAAA,EAAA;AAErB;"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { useEventListener as
|
|
2
|
-
import {
|
|
3
|
-
const
|
|
1
|
+
import { useEventListener as t } from "../useEventListener/useEventListener.mjs";
|
|
2
|
+
import { isTarget as i } from "../../utils/helpers/isTarget.mjs";
|
|
3
|
+
const m = (e, o, r) => t(i.wrap(window), e, o, r);
|
|
4
4
|
export {
|
|
5
|
-
|
|
5
|
+
m as useWindowEvent
|
|
6
6
|
};
|
|
7
7
|
//# sourceMappingURL=useWindowEvent.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useWindowEvent.mjs","sources":["../../../../src/hooks/useWindowEvent/useWindowEvent.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"useWindowEvent.mjs","sources":["../../../../src/hooks/useWindowEvent/useWindowEvent.ts"],"sourcesContent":["import { isTarget } from '@/utils/helpers';\n\nimport type { UseEventListenerOptions } from '../useEventListener/useEventListener';\n\nimport { useEventListener } from '../useEventListener/useEventListener';\n\n/**\n * @name useWindowEvent\n * @description - Hook attaches an event listener to the window object for the specified event\n * @category Sensors\n * @usage low\n *\n * @template Event Key of window event map.\n * @param {Event} event The event to listen for.\n * @param {(event: WindowEventMap[Event]) => void} listener The callback function to be executed when the event is triggered\n * @param {UseEventListenerOptions} [options] The options for the event listener\n * @returns {void}\n *\n * @example\n * useWindowEvent('click', () => console.log('clicked'));\n */\nexport const useWindowEvent = <Event extends keyof WindowEventMap>(\n event: Event,\n listener: (this: Window, event: WindowEventMap[Event]) => any,\n options?: UseEventListenerOptions\n) => useEventListener(isTarget.wrap(window), event, listener, options);\n"],"names":["useWindowEvent","event","listener","options","useEventListener","isTarget"],"mappings":";;AAqBO,MAAMA,IAAiB,CAC5BC,GACAC,GACAC,MACGC,EAAiBC,EAAS,KAAK,MAAM,GAAGJ,GAAOC,GAAUC,CAAO;"}
|
|
@@ -1,28 +1,24 @@
|
|
|
1
|
-
import { useState as
|
|
2
|
-
const
|
|
3
|
-
const e = n?.includeScrollbar ?? !0, [
|
|
1
|
+
import { useState as h, useEffect as l } from "react";
|
|
2
|
+
const m = (n) => {
|
|
3
|
+
const e = n?.includeScrollbar ?? !0, [i, o] = h(() => typeof window > "u" ? {
|
|
4
4
|
width: Number.POSITIVE_INFINITY,
|
|
5
5
|
height: Number.POSITIVE_INFINITY
|
|
6
6
|
} : {
|
|
7
7
|
width: e ? window.innerWidth : window.document.documentElement.clientWidth,
|
|
8
8
|
height: e ? window.innerHeight : window.document.documentElement.clientHeight
|
|
9
9
|
});
|
|
10
|
-
return
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
width: window.document.documentElement.clientWidth,
|
|
17
|
-
height: window.document.documentElement.clientHeight
|
|
10
|
+
return l(() => {
|
|
11
|
+
const t = () => {
|
|
12
|
+
const { innerWidth: d, innerHeight: r, document: c } = window, { clientWidth: u, clientHeight: w } = c.documentElement;
|
|
13
|
+
o({
|
|
14
|
+
width: e ? d : u,
|
|
15
|
+
height: e ? r : w
|
|
18
16
|
});
|
|
19
17
|
};
|
|
20
|
-
return window.addEventListener("resize",
|
|
21
|
-
|
|
22
|
-
};
|
|
23
|
-
}, [n?.includeScrollbar]), d;
|
|
18
|
+
return window.addEventListener("resize", t), () => window.removeEventListener("resize", t);
|
|
19
|
+
}, [n?.includeScrollbar]), i;
|
|
24
20
|
};
|
|
25
21
|
export {
|
|
26
|
-
|
|
22
|
+
m as useWindowSize
|
|
27
23
|
};
|
|
28
24
|
//# sourceMappingURL=useWindowSize.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useWindowSize.mjs","sources":["../../../../src/hooks/useWindowSize/useWindowSize.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\n/** The use window size return type */\ninterface UseWindowSizeParams {\n /** Whether to include the scrollbar in the window size calculation */\n includeScrollbar?: boolean;\n}\n\n/** The use window size return type */\nexport interface UseWindowSizeReturn {\n /** The current window height */\n height: number;\n /** The current window width */\n width: number;\n}\n\n/**\n * @name useWindowSize\n * @description - Hook that manages a window size\n * @category Elements\n * @usage low\n *\n * @param {number} [params.initialWidth=Number.POSITIVE_INFINITY] The initial window width\n * @param {number} [params.initialHeight=Number.POSITIVE_INFINITY] The initial window height\n * @returns {UseWindowSizeReturn} An object containing the current window width and height\n *\n * @example\n * const { width, height } = useWindowSize();\n */\nexport const useWindowSize = (params?: UseWindowSizeParams) => {\n const includeScrollbar = params?.includeScrollbar ?? true;\n const [size, setSize] = useState(() => {\n if (typeof window === 'undefined') {\n return {\n width: Number.POSITIVE_INFINITY,\n height: Number.POSITIVE_INFINITY\n };\n }\n\n return {\n width: includeScrollbar ? window.innerWidth : window.document.documentElement.clientWidth,\n height: includeScrollbar ? window.innerHeight : window.document.documentElement.clientHeight\n };\n });\n\n useEffect(() => {\n const onResize = () => {\n
|
|
1
|
+
{"version":3,"file":"useWindowSize.mjs","sources":["../../../../src/hooks/useWindowSize/useWindowSize.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\n/** The use window size return type */\ninterface UseWindowSizeParams {\n /** Whether to include the scrollbar in the window size calculation */\n includeScrollbar?: boolean;\n}\n\n/** The use window size return type */\nexport interface UseWindowSizeReturn {\n /** The current window height */\n height: number;\n /** The current window width */\n width: number;\n}\n\n/**\n * @name useWindowSize\n * @description - Hook that manages a window size\n * @category Elements\n * @usage low\n *\n * @param {number} [params.initialWidth=Number.POSITIVE_INFINITY] The initial window width\n * @param {number} [params.initialHeight=Number.POSITIVE_INFINITY] The initial window height\n * @returns {UseWindowSizeReturn} An object containing the current window width and height\n *\n * @example\n * const { width, height } = useWindowSize();\n */\nexport const useWindowSize = (params?: UseWindowSizeParams) => {\n const includeScrollbar = params?.includeScrollbar ?? true;\n const [size, setSize] = useState(() => {\n if (typeof window === 'undefined') {\n return {\n width: Number.POSITIVE_INFINITY,\n height: Number.POSITIVE_INFINITY\n };\n }\n\n return {\n width: includeScrollbar ? window.innerWidth : window.document.documentElement.clientWidth,\n height: includeScrollbar ? window.innerHeight : window.document.documentElement.clientHeight\n };\n });\n\n useEffect(() => {\n const onResize = () => {\n const { innerWidth, innerHeight, document } = window;\n const { clientWidth, clientHeight } = document.documentElement;\n\n setSize({\n width: includeScrollbar ? innerWidth : clientWidth,\n height: includeScrollbar ? innerHeight : clientHeight\n });\n };\n\n window.addEventListener('resize', onResize);\n return () => window.removeEventListener('resize', onResize);\n }, [params?.includeScrollbar]);\n\n return size;\n};\n"],"names":["useWindowSize","params","includeScrollbar","size","setSize","useState","useEffect","onResize","innerWidth","innerHeight","document","clientWidth","clientHeight"],"mappings":";AA6BO,MAAMA,IAAgB,CAACC,MAAiC;AAC7D,QAAMC,IAAmBD,GAAQ,oBAAoB,IAC/C,CAACE,GAAMC,CAAO,IAAIC,EAAS,MAC3B,OAAO,SAAW,MACb;AAAA,IACL,OAAO,OAAO;AAAA,IACd,QAAQ,OAAO;AAAA,EAAA,IAIZ;AAAA,IACL,OAAOH,IAAmB,OAAO,aAAa,OAAO,SAAS,gBAAgB;AAAA,IAC9E,QAAQA,IAAmB,OAAO,cAAc,OAAO,SAAS,gBAAgB;AAAA,EAAA,CAEnF;AAED,SAAAI,EAAU,MAAM;AACd,UAAMC,IAAW,MAAM;AACrB,YAAM,EAAE,YAAAC,GAAY,aAAAC,GAAa,UAAAC,EAAA,IAAa,QACxC,EAAE,aAAAC,GAAa,cAAAC,EAAA,IAAiBF,EAAS;AAE/C,MAAAN,EAAQ;AAAA,QACN,OAAOF,IAAmBM,IAAaG;AAAA,QACvC,QAAQT,IAAmBO,IAAcG;AAAA,MAAA,CAC1C;AAAA,IAAA;AAGH,kBAAO,iBAAiB,UAAUL,CAAQ,GACnC,MAAM,OAAO,oBAAoB,UAAUA,CAAQ;AAAA,EAAA,GACzD,CAACN,GAAQ,gBAAgB,CAAC,GAEtBE;AACT;"}
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createContext as r } from "./helpers/createContext/createContext.mjs";
|
|
2
2
|
import { createEventEmitter as s } from "./helpers/createEventEmitter/createEventEmitter.mjs";
|
|
3
|
-
import { createReactiveContext as
|
|
3
|
+
import { createReactiveContext as m } from "./helpers/createReactiveContext/createReactiveContext.mjs";
|
|
4
4
|
import { createStore as f } from "./helpers/createStore/createStore.mjs";
|
|
5
5
|
import { useAsync as a } from "./hooks/useAsync/useAsync.mjs";
|
|
6
6
|
import { useLockCallback as n } from "./hooks/useLockCallback/useLockCallback.mjs";
|
|
@@ -25,7 +25,7 @@ import { mapGamepadToXbox360Controller as q, useGamepad as Z } from "./hooks/use
|
|
|
25
25
|
import { useGeolocation as J } from "./hooks/useGeolocation/useGeolocation.mjs";
|
|
26
26
|
import { timeRangeToArray as $, useMediaControls as ee } from "./hooks/useMediaControls/useMediaControls.mjs";
|
|
27
27
|
import { useMemory as re } from "./hooks/useMemory/useMemory.mjs";
|
|
28
|
-
import { getConnection as se, useNetwork as
|
|
28
|
+
import { getConnection as se, useNetwork as ue } from "./hooks/useNetwork/useNetwork.mjs";
|
|
29
29
|
import { useOnline as pe } from "./hooks/useOnline/useOnline.mjs";
|
|
30
30
|
import { useOtpCredential as xe } from "./hooks/useOtpCredential/useOtpCredential.mjs";
|
|
31
31
|
import { usePermission as ie } from "./hooks/usePermission/usePermission.mjs";
|
|
@@ -51,7 +51,7 @@ import { DEFAULT_THRESHOLD_TIME as je, useDoubleClick as Je } from "./hooks/useD
|
|
|
51
51
|
import { useDropZone as $e } from "./hooks/useDropZone/useDropZone.mjs";
|
|
52
52
|
import { useFileDialog as oo } from "./hooks/useFileDialog/useFileDialog.mjs";
|
|
53
53
|
import { useFocus as to } from "./hooks/useFocus/useFocus.mjs";
|
|
54
|
-
import { FOCUS_SELECTOR as
|
|
54
|
+
import { FOCUS_SELECTOR as uo, useFocusTrap as mo } from "./hooks/useFocusTrap/useFocusTrap.mjs";
|
|
55
55
|
import { useHover as fo } from "./hooks/useHover/useHover.mjs";
|
|
56
56
|
import { useImage as ao } from "./hooks/useImage/useImage.mjs";
|
|
57
57
|
import { useLongPress as no } from "./hooks/useLongPress/useLongPress.mjs";
|
|
@@ -71,7 +71,7 @@ import { useMount as wo } from "./hooks/useMount/useMount.mjs";
|
|
|
71
71
|
import { deepEqual as Go, useShallowEffect as Qo } from "./hooks/useShallowEffect/useShallowEffect.mjs";
|
|
72
72
|
import { useUnmount as Xo } from "./hooks/useUnmount/useUnmount.mjs";
|
|
73
73
|
import { BREAKPOINTS_ANT_DESIGN as Zo, BREAKPOINTS_BOOTSTRAP_V5 as jo, BREAKPOINTS_MANTINE as Jo, BREAKPOINTS_MASTER_CSS as Yo, BREAKPOINTS_MATERIAL_UI as $o, BREAKPOINTS_PRIME_FLEX as er, BREAKPOINTS_QUASAR_V2 as or, BREAKPOINTS_SEMANTIC as rr, BREAKPOINTS_TAILWIND as tr, useBreakpoints as sr } from "./hooks/useBreakpoints/useBreakpoints.mjs";
|
|
74
|
-
import { useDeviceMotion as
|
|
74
|
+
import { useDeviceMotion as mr } from "./hooks/useDeviceMotion/useDeviceMotion.mjs";
|
|
75
75
|
import { useDeviceOrientation as fr } from "./hooks/useDeviceOrientation/useDeviceOrientation.mjs";
|
|
76
76
|
import { useDevicePixelRatio as ar } from "./hooks/useDevicePixelRatio/useDevicePixelRatio.mjs";
|
|
77
77
|
import { useDocumentEvent as nr } from "./hooks/useDocumentEvent/useDocumentEvent.mjs";
|
|
@@ -97,7 +97,7 @@ import { useParallax as Jr } from "./hooks/useParallax/useParallax.mjs";
|
|
|
97
97
|
import { usePerformanceObserver as $r } from "./hooks/usePerformanceObserver/usePerformanceObserver.mjs";
|
|
98
98
|
import { useResizeObserver as ot } from "./hooks/useResizeObserver/useResizeObserver.mjs";
|
|
99
99
|
import { useScroll as tt } from "./hooks/useScroll/useScroll.mjs";
|
|
100
|
-
import { useScrollIntoView as
|
|
100
|
+
import { useScrollIntoView as ut } from "./hooks/useScrollIntoView/useScrollIntoView.mjs";
|
|
101
101
|
import { useScrollTo as pt } from "./hooks/useScrollTo/useScrollTo.mjs";
|
|
102
102
|
import { getRangesSelection as xt, useTextSelection as at } from "./hooks/useTextSelection/useTextSelection.mjs";
|
|
103
103
|
import { useVisibility as nt } from "./hooks/useVisibility/useVisibility.mjs";
|
|
@@ -117,7 +117,7 @@ import { getHash as qt, useHash as Zt } from "./hooks/useHash/useHash.mjs";
|
|
|
117
117
|
import { useList as Jt } from "./hooks/useList/useList.mjs";
|
|
118
118
|
import { useLocalStorage as $t } from "./hooks/useLocalStorage/useLocalStorage.mjs";
|
|
119
119
|
import { useMap as os } from "./hooks/useMap/useMap.mjs";
|
|
120
|
-
import { assignRef as ts, mergeRefs as ss, useMergedRef as
|
|
120
|
+
import { assignRef as ts, mergeRefs as ss, useMergedRef as us } from "./hooks/useMergedRef/useMergedRef.mjs";
|
|
121
121
|
import { useOffsetPagination as ps } from "./hooks/useOffsetPagination/useOffsetPagination.mjs";
|
|
122
122
|
import { useQueue as xs } from "./hooks/useQueue/useQueue.mjs";
|
|
123
123
|
import { useRafState as is } from "./hooks/useRafState/useRafState.mjs";
|
|
@@ -137,30 +137,29 @@ import { useTime as Gs } from "./hooks/useTime/useTime.mjs";
|
|
|
137
137
|
import { useTimeout as zs } from "./hooks/useTimeout/useTimeout.mjs";
|
|
138
138
|
import { getTimeFromSeconds as qs, useTimer as Zs } from "./hooks/useTimer/useTimer.mjs";
|
|
139
139
|
import { useBrowserLanguage as Js } from "./hooks/useBrowserLanguage/useBrowserLanguage.mjs";
|
|
140
|
-
import { getOperatingSystem as $s, useOperatingSystem as
|
|
141
|
-
import { usePreferredColorScheme as
|
|
142
|
-
import { usePreferredContrast as
|
|
143
|
-
import { usePreferredDark as
|
|
144
|
-
import { usePreferredLanguages as
|
|
145
|
-
import { usePreferredReducedMotion as
|
|
146
|
-
import { useConst as
|
|
147
|
-
import { useDebounceCallback as
|
|
148
|
-
import { useDebounceState as
|
|
149
|
-
import { useDebounceValue as
|
|
150
|
-
import { useEvent as
|
|
151
|
-
import { useLastChanged as
|
|
152
|
-
import { useLatest as
|
|
153
|
-
import { usePrevious as
|
|
154
|
-
import { useThrottleCallback as
|
|
155
|
-
import { useThrottleState as
|
|
156
|
-
import { useThrottleValue as
|
|
157
|
-
import { copy as
|
|
158
|
-
import { debounce as
|
|
159
|
-
import { getDate as
|
|
160
|
-
import {
|
|
161
|
-
import {
|
|
162
|
-
import {
|
|
163
|
-
import { throttle as Zm } from "./utils/helpers/throttle.mjs";
|
|
140
|
+
import { getOperatingSystem as $s, useOperatingSystem as eu } from "./hooks/useOperatingSystem/useOperatingSystem.mjs";
|
|
141
|
+
import { usePreferredColorScheme as ru } from "./hooks/usePreferredColorScheme/usePreferredColorScheme.mjs";
|
|
142
|
+
import { usePreferredContrast as su } from "./hooks/usePreferredContrast/usePreferredContrast.mjs";
|
|
143
|
+
import { usePreferredDark as mu } from "./hooks/usePreferredDark/usePreferredDark.mjs";
|
|
144
|
+
import { usePreferredLanguages as fu } from "./hooks/usePreferredLanguages/usePreferredLanguages.mjs";
|
|
145
|
+
import { usePreferredReducedMotion as au } from "./hooks/usePreferredReducedMotion/usePreferredReducedMotion.mjs";
|
|
146
|
+
import { useConst as nu } from "./hooks/useConst/useConst.mjs";
|
|
147
|
+
import { useDebounceCallback as lu } from "./hooks/useDebounceCallback/useDebounceCallback.mjs";
|
|
148
|
+
import { useDebounceState as Eu } from "./hooks/useDebounceState/useDebounceState.mjs";
|
|
149
|
+
import { useDebounceValue as gu } from "./hooks/useDebounceValue/useDebounceValue.mjs";
|
|
150
|
+
import { useEvent as Ru } from "./hooks/useEvent/useEvent.mjs";
|
|
151
|
+
import { useLastChanged as Pu } from "./hooks/useLastChanged/useLastChanged.mjs";
|
|
152
|
+
import { useLatest as Iu } from "./hooks/useLatest/useLatest.mjs";
|
|
153
|
+
import { usePrevious as Ou } from "./hooks/usePrevious/usePrevious.mjs";
|
|
154
|
+
import { useThrottleCallback as hu } from "./hooks/useThrottleCallback/useThrottleCallback.mjs";
|
|
155
|
+
import { useThrottleState as _u } from "./hooks/useThrottleState/useThrottleState.mjs";
|
|
156
|
+
import { useThrottleValue as bu } from "./hooks/useThrottleValue/useThrottleValue.mjs";
|
|
157
|
+
import { copy as Mu, legacyCopyToClipboard as Nu } from "./utils/helpers/copy.mjs";
|
|
158
|
+
import { debounce as Ku } from "./utils/helpers/debounce.mjs";
|
|
159
|
+
import { getDate as Uu } from "./utils/helpers/getDate.mjs";
|
|
160
|
+
import { getRetry as Hu } from "./utils/helpers/getRetry.mjs";
|
|
161
|
+
import { isTarget as Wu, target as Gu, targetSymbol as Qu } from "./utils/helpers/isTarget.mjs";
|
|
162
|
+
import { throttle as Xu } from "./utils/helpers/throttle.mjs";
|
|
164
163
|
export {
|
|
165
164
|
Zo as BREAKPOINTS_ANT_DESIGN,
|
|
166
165
|
jo as BREAKPOINTS_BOOTSTRAP_V5,
|
|
@@ -173,7 +172,7 @@ export {
|
|
|
173
172
|
tr as BREAKPOINTS_TAILWIND,
|
|
174
173
|
kt as COOKIE_EVENT,
|
|
175
174
|
je as DEFAULT_THRESHOLD_TIME,
|
|
176
|
-
|
|
175
|
+
uo as FOCUS_SELECTOR,
|
|
177
176
|
lo as Paint,
|
|
178
177
|
So as Pointer,
|
|
179
178
|
Co as SCRIPT_STATUS_ATTRIBUTE_NAME,
|
|
@@ -181,13 +180,13 @@ export {
|
|
|
181
180
|
_s as URL_SEARCH_PARAMS_EVENT,
|
|
182
181
|
ts as assignRef,
|
|
183
182
|
Kt as clearCookies,
|
|
184
|
-
|
|
183
|
+
Mu as copy,
|
|
185
184
|
r as createContext,
|
|
186
185
|
s as createEventEmitter,
|
|
187
186
|
Ds as createQueryString,
|
|
188
|
-
|
|
187
|
+
m as createReactiveContext,
|
|
189
188
|
f as createStore,
|
|
190
|
-
|
|
189
|
+
Ku as debounce,
|
|
191
190
|
Go as deepEqual,
|
|
192
191
|
ht as dispatchCookieEvent,
|
|
193
192
|
ys as dispatchStorageEvent,
|
|
@@ -195,18 +194,17 @@ export {
|
|
|
195
194
|
se as getConnection,
|
|
196
195
|
vt as getCookie,
|
|
197
196
|
_t as getCookies,
|
|
198
|
-
|
|
199
|
-
Hm as getElement,
|
|
197
|
+
Uu as getDate,
|
|
200
198
|
qt as getHash,
|
|
201
199
|
$s as getOperatingSystem,
|
|
202
200
|
xt as getRangesSelection,
|
|
203
|
-
|
|
201
|
+
Hu as getRetry,
|
|
204
202
|
Ae as getSpeechRecognition,
|
|
205
203
|
qs as getTimeFromSeconds,
|
|
206
204
|
Ls as getUrlSearchParams,
|
|
207
205
|
Rr as isHotkeyMatch,
|
|
208
|
-
|
|
209
|
-
|
|
206
|
+
Wu as isTarget,
|
|
207
|
+
Nu as legacyCopyToClipboard,
|
|
210
208
|
q as mapGamepadToXbox360Controller,
|
|
211
209
|
ss as mergeRefs,
|
|
212
210
|
Dt as removeCookie,
|
|
@@ -215,9 +213,9 @@ export {
|
|
|
215
213
|
Lt as setCookie,
|
|
216
214
|
Mt as setCookieItem,
|
|
217
215
|
ds as stateHistoryReducer,
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
216
|
+
Gu as target,
|
|
217
|
+
Qu as targetSymbol,
|
|
218
|
+
Xu as throttle,
|
|
221
219
|
$ as timeRangeToArray,
|
|
222
220
|
Ge as useActiveElement,
|
|
223
221
|
a as useAsync,
|
|
@@ -232,18 +230,18 @@ export {
|
|
|
232
230
|
Js as useBrowserLanguage,
|
|
233
231
|
qe as useClickOutside,
|
|
234
232
|
h as useClipboard,
|
|
235
|
-
|
|
233
|
+
nu as useConst,
|
|
236
234
|
yt as useControllableState,
|
|
237
235
|
Nt as useCookie,
|
|
238
236
|
Ft as useCookies,
|
|
239
237
|
_ as useCopy,
|
|
240
238
|
Vt as useCounter,
|
|
241
239
|
b as useCssVar,
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
240
|
+
lu as useDebounceCallback,
|
|
241
|
+
Eu as useDebounceState,
|
|
242
|
+
gu as useDebounceValue,
|
|
245
243
|
wt as useDefault,
|
|
246
|
-
|
|
244
|
+
mr as useDeviceMotion,
|
|
247
245
|
fr as useDeviceOrientation,
|
|
248
246
|
ar as useDevicePixelRatio,
|
|
249
247
|
Bo as useDidUpdate,
|
|
@@ -255,7 +253,7 @@ export {
|
|
|
255
253
|
Je as useDoubleClick,
|
|
256
254
|
$e as useDropZone,
|
|
257
255
|
Er as useElementSize,
|
|
258
|
-
|
|
256
|
+
Ru as useEvent,
|
|
259
257
|
gr as useEventListener,
|
|
260
258
|
F as useEventSource,
|
|
261
259
|
V as useEyeDropper,
|
|
@@ -263,7 +261,7 @@ export {
|
|
|
263
261
|
zt as useField,
|
|
264
262
|
oo as useFileDialog,
|
|
265
263
|
to as useFocus,
|
|
266
|
-
|
|
264
|
+
mo as useFocusTrap,
|
|
267
265
|
G as useFps,
|
|
268
266
|
ho as useFul,
|
|
269
267
|
z as useFullscreen,
|
|
@@ -283,8 +281,8 @@ export {
|
|
|
283
281
|
Lr as useKeyPressEvent,
|
|
284
282
|
vr as useKeyboard,
|
|
285
283
|
Nr as useKeysPressed,
|
|
286
|
-
|
|
287
|
-
|
|
284
|
+
Pu as useLastChanged,
|
|
285
|
+
Iu as useLatest,
|
|
288
286
|
_o as useLess,
|
|
289
287
|
Jt as useList,
|
|
290
288
|
$t as useLocalStorage,
|
|
@@ -297,16 +295,16 @@ export {
|
|
|
297
295
|
ee as useMediaControls,
|
|
298
296
|
Hr as useMediaQuery,
|
|
299
297
|
re as useMemory,
|
|
300
|
-
|
|
298
|
+
us as useMergedRef,
|
|
301
299
|
wo as useMount,
|
|
302
300
|
Wr as useMouse,
|
|
303
301
|
l as useMutation,
|
|
304
302
|
Qr as useMutationObserver,
|
|
305
|
-
|
|
303
|
+
ue as useNetwork,
|
|
306
304
|
ps as useOffsetPagination,
|
|
307
305
|
bo as useOnce,
|
|
308
306
|
pe as useOnline,
|
|
309
|
-
|
|
307
|
+
eu as useOperatingSystem,
|
|
310
308
|
E as useOptimistic,
|
|
311
309
|
Xr as useOrientation,
|
|
312
310
|
xe as useOtpCredential,
|
|
@@ -318,12 +316,12 @@ export {
|
|
|
318
316
|
ce as usePictureInPicture,
|
|
319
317
|
Se as usePointerLock,
|
|
320
318
|
Te as usePostMessage,
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
319
|
+
ru as usePreferredColorScheme,
|
|
320
|
+
su as usePreferredContrast,
|
|
321
|
+
mu as usePreferredDark,
|
|
322
|
+
fu as usePreferredLanguages,
|
|
323
|
+
au as usePreferredReducedMotion,
|
|
324
|
+
Ou as usePrevious,
|
|
327
325
|
g as useQuery,
|
|
328
326
|
xs as useQueue,
|
|
329
327
|
de as useRaf,
|
|
@@ -336,7 +334,7 @@ export {
|
|
|
336
334
|
go as useRightClick,
|
|
337
335
|
Po as useScript,
|
|
338
336
|
tt as useScroll,
|
|
339
|
-
|
|
337
|
+
ut as useScrollIntoView,
|
|
340
338
|
pt as useScrollTo,
|
|
341
339
|
Ss as useSessionStorage,
|
|
342
340
|
Ts as useSet,
|
|
@@ -351,9 +349,9 @@ export {
|
|
|
351
349
|
Os as useStorage,
|
|
352
350
|
Oo as useTextDirection,
|
|
353
351
|
at as useTextSelection,
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
352
|
+
hu as useThrottleCallback,
|
|
353
|
+
_u as useThrottleState,
|
|
354
|
+
bu as useThrottleValue,
|
|
357
355
|
Gs as useTime,
|
|
358
356
|
zs as useTimeout,
|
|
359
357
|
Zs as useTimer,
|
package/dist/esm/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1,6 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
const n = Symbol("target"), o = (e) => "current" in e ? e.current : typeof e.value == "function" ? e.value() : typeof e.value == "string" ? document.querySelector(e.value) : (e.value instanceof Document || e.value instanceof Window || e.value instanceof Element, e.value), l = (e) => ({
|
|
2
|
+
value: e,
|
|
3
|
+
type: n
|
|
4
|
+
}), u = (e) => typeof e == "object" && ("current" in e || e && e.type === n);
|
|
5
|
+
u.wrap = l;
|
|
6
|
+
u.getElement = o;
|
|
3
7
|
export {
|
|
4
|
-
|
|
8
|
+
u as isTarget,
|
|
9
|
+
l as target,
|
|
10
|
+
n as targetSymbol
|
|
5
11
|
};
|
|
6
12
|
//# sourceMappingURL=isTarget.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isTarget.mjs","sources":["../../../../src/utils/helpers/isTarget.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"isTarget.mjs","sources":["../../../../src/utils/helpers/isTarget.ts"],"sourcesContent":["import type { RefObject } from 'react';\n\nexport const targetSymbol = Symbol('target');\n\nexport type Target = (() => Element) | string | Document | Element | Window;\n\nexport type HookTarget =\n | RefObject<Element | null | undefined>\n | {\n value: Target;\n type: symbol;\n };\n\nconst getElement = (target: HookTarget) => {\n if ('current' in target) {\n return target.current;\n }\n\n if (typeof target.value === 'function') {\n return target.value();\n }\n\n if (typeof target.value === 'string') {\n return document.querySelector(target.value);\n }\n\n if (target.value instanceof Document) {\n return target.value;\n }\n\n if (target.value instanceof Window) {\n return target.value;\n }\n\n if (target.value instanceof Element) {\n return target.value;\n }\n\n return target.value;\n};\n\nexport const target = (target: Target) => ({\n value: target,\n type: targetSymbol\n});\n\nexport const isTarget = (target: HookTarget) =>\n typeof target === 'object' &&\n ('current' in target || (target && (target as any).type === targetSymbol));\n\nisTarget.wrap = target;\nisTarget.getElement = getElement;\n"],"names":["targetSymbol","getElement","target","isTarget"],"mappings":"AAEO,MAAMA,IAAe,OAAO,QAAQ,GAWrCC,IAAa,CAACC,MACd,aAAaA,IACRA,EAAO,UAGZ,OAAOA,EAAO,SAAU,aACnBA,EAAO,MAAA,IAGZ,OAAOA,EAAO,SAAU,WACnB,SAAS,cAAcA,EAAO,KAAK,KAGxCA,EAAO,iBAAiB,YAIxBA,EAAO,iBAAiB,UAIxBA,EAAO,iBAAiB,SACnBA,EAAO,QAMLA,IAAS,CAACA,OAAoB;AAAA,EACzC,OAAOA;AAAAA,EACP,MAAMF;AACR,IAEaG,IAAW,CAACD,MACvB,OAAOA,KAAW,aACjB,aAAaA,KAAWA,KAAWA,EAAe,SAASF;AAE9DG,EAAS,OAAOD;AAChBC,EAAS,aAAaF;"}
|
|
@@ -31,11 +31,7 @@ export interface UseHash {
|
|
|
31
31
|
* @returns {UseHashReturn} An array containing the hash value and a function to set the hash value
|
|
32
32
|
*
|
|
33
33
|
* @example
|
|
34
|
-
* const [hash, setHash] = useHash("initial"
|
|
35
|
-
* enabled: true,
|
|
36
|
-
* mode: "replace",
|
|
37
|
-
* onChange: (newHash) => console.log('Hash changed:', newHash)
|
|
38
|
-
* });
|
|
34
|
+
* const [hash, setHash] = useHash("initial");
|
|
39
35
|
*
|
|
40
36
|
* @overload
|
|
41
37
|
* @param {string} [initialValue] The initial hash value if no hash exists
|
|
@@ -44,6 +40,23 @@ export interface UseHash {
|
|
|
44
40
|
*
|
|
45
41
|
* @example
|
|
46
42
|
* const [hash, setHash] = useHash("initial", (newHash) => console.log('callback'));
|
|
43
|
+
*
|
|
44
|
+
* @overload
|
|
45
|
+
* @param {UseHashOptions} [options] Configuration options
|
|
46
|
+
* @param {boolean} [options.enabled] The enabled state of the hook
|
|
47
|
+
* @param {'initial' | 'replace'} [options.mode] The mode of hash setting
|
|
48
|
+
* @param {(hash: string) => void} [options.onChange] Callback function called when hash changes
|
|
49
|
+
* @returns {UseHashReturn} An array containing the hash value and a function to set the hash value
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* const [hash, setHash] = useHash();
|
|
53
|
+
*
|
|
54
|
+
* @overload
|
|
55
|
+
* @param {(hash: string) => void} [callback] Callback function called when hash changes
|
|
56
|
+
* @returns {UseHashReturn} An array containing the hash value and a function to set the hash value
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* const [hash, setHash] = useHash((newHash) => console.log('callback'));
|
|
47
60
|
*/
|
|
48
61
|
export declare const useHash: UseHash;
|
|
49
62
|
export {};
|