@siberiacancode/reactuse 0.0.113 → 0.0.115

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/dist/cjs/hooks/useClickOutside/useClickOutside.cjs.map +1 -1
  2. package/dist/cjs/hooks/useDocumentEvent/useDocumentEvent.cjs +1 -1
  3. package/dist/cjs/hooks/useDocumentEvent/useDocumentEvent.cjs.map +1 -1
  4. package/dist/cjs/hooks/useDoubleClick/useDoubleClick.cjs +2 -0
  5. package/dist/cjs/hooks/useDoubleClick/useDoubleClick.cjs.map +1 -0
  6. package/dist/cjs/hooks/useEventListener/useEventListener.cjs +1 -1
  7. package/dist/cjs/hooks/useEventListener/useEventListener.cjs.map +1 -1
  8. package/dist/cjs/hooks/useLongPress/useLongPress.cjs +1 -1
  9. package/dist/cjs/hooks/useLongPress/useLongPress.cjs.map +1 -1
  10. package/dist/cjs/hooks/useMouse/useMouse.cjs.map +1 -1
  11. package/dist/cjs/hooks/useParallax/useParallax.cjs +1 -1
  12. package/dist/cjs/hooks/useParallax/useParallax.cjs.map +1 -1
  13. package/dist/cjs/hooks/useSpeechRecognition/useSpeechRecognition.cjs +2 -0
  14. package/dist/cjs/hooks/useSpeechRecognition/useSpeechRecognition.cjs.map +1 -0
  15. package/dist/cjs/hooks/useWindowEvent/useWindowEvent.cjs +1 -1
  16. package/dist/cjs/hooks/useWindowEvent/useWindowEvent.cjs.map +1 -1
  17. package/dist/cjs/index.cjs +1 -1
  18. package/dist/esm/hooks/useClickOutside/useClickOutside.mjs.map +1 -1
  19. package/dist/esm/hooks/useDocumentEvent/useDocumentEvent.mjs +4 -3
  20. package/dist/esm/hooks/useDocumentEvent/useDocumentEvent.mjs.map +1 -1
  21. package/dist/esm/hooks/useDoubleClick/useDoubleClick.mjs +29 -0
  22. package/dist/esm/hooks/useDoubleClick/useDoubleClick.mjs.map +1 -0
  23. package/dist/esm/hooks/useEventListener/useEventListener.mjs +15 -15
  24. package/dist/esm/hooks/useEventListener/useEventListener.mjs.map +1 -1
  25. package/dist/esm/hooks/useLongPress/useLongPress.mjs +30 -17
  26. package/dist/esm/hooks/useLongPress/useLongPress.mjs.map +1 -1
  27. package/dist/esm/hooks/useMouse/useMouse.mjs.map +1 -1
  28. package/dist/esm/hooks/useParallax/useParallax.mjs +90 -85
  29. package/dist/esm/hooks/useParallax/useParallax.mjs.map +1 -1
  30. package/dist/esm/hooks/useSpeechRecognition/useSpeechRecognition.mjs +41 -0
  31. package/dist/esm/hooks/useSpeechRecognition/useSpeechRecognition.mjs.map +1 -0
  32. package/dist/esm/hooks/useWindowEvent/useWindowEvent.mjs +4 -3
  33. package/dist/esm/hooks/useWindowEvent/useWindowEvent.mjs.map +1 -1
  34. package/dist/esm/index.mjs +257 -252
  35. package/dist/esm/index.mjs.map +1 -1
  36. package/dist/types/hooks/index.d.ts +2 -0
  37. package/dist/types/hooks/useClickOutside/useClickOutside.d.ts +2 -0
  38. package/dist/types/hooks/useDoubleClick/useDoubleClick.d.ts +38 -0
  39. package/dist/types/hooks/useEventListener/useEventListener.d.ts +5 -5
  40. package/dist/types/hooks/useLongPress/useLongPress.d.ts +27 -25
  41. package/dist/types/hooks/useSpeechRecognition/useSpeechRecognition.d.ts +69 -0
  42. package/package.json +2 -1
@@ -1,22 +1,35 @@
1
- import { useState as E, useRef as m } from "react";
2
- const P = 400, s = (L, e) => {
3
- const [f, l] = E(!1), u = m(), a = m(!1), T = (r) => {
4
- var c;
5
- (c = e == null ? void 0 : e.onStart) == null || c.call(e, r), a.current = !0, u.current = setTimeout(() => {
6
- L(r), l(!0);
7
- }, (e == null ? void 0 : e.threshold) ?? P);
8
- }, d = (r) => {
9
- var c, h;
10
- f ? (c = e == null ? void 0 : e.onFinish) == null || c.call(e, r) : a.current && ((h = e == null ? void 0 : e.onCancel) == null || h.call(e, r)), l(!1), a.current = !1, u.current && clearTimeout(u.current);
1
+ import { useState as T, useRef as l, useEffect as S } from "react";
2
+ import { useRefState as g } from "../useRefState/useRefState.mjs";
3
+ import { isTarget as C } from "../../utils/helpers/isTarget.mjs";
4
+ import { getElement as P } from "../../utils/helpers/getElement.mjs";
5
+ const b = 400, I = (...o) => {
6
+ const n = C(o[0]) ? o[0] : void 0, E = n ? o[1] : o[0], L = n ? o[2] : o[1], [w, h] = T(!1), u = l(), v = l(!1), f = g(), R = l(E);
7
+ R.current = E;
8
+ const c = l(L);
9
+ return c.current = L, S(() => {
10
+ if (!n && !f.state) return;
11
+ const e = n ? P(n) : f.current;
12
+ if (!e) return;
13
+ const a = (i) => {
14
+ var s, r, d;
15
+ (r = (s = c.current) == null ? void 0 : s.onStart) == null || r.call(s, i), v.current = !0, u.current = setTimeout(() => {
16
+ R.current(i), h(!0);
17
+ }, ((d = c.current) == null ? void 0 : d.threshold) ?? b);
18
+ }, t = (i) => {
19
+ h((s) => {
20
+ var r, d, m, p;
21
+ return s ? (d = (r = c.current) == null ? void 0 : r.onFinish) == null || d.call(r, i) : v.current && ((p = (m = c.current) == null ? void 0 : m.onCancel) == null || p.call(m, i)), !1;
22
+ }), v.current = !1, u.current && clearTimeout(u.current);
23
+ };
24
+ return e.addEventListener("mousedown", a), e.addEventListener("touchstart", a), e.addEventListener("mouseup", t), e.addEventListener("touchend", t), window.addEventListener("mouseup", t), window.addEventListener("touchend", t), () => {
25
+ e.removeEventListener("mousedown", a), e.removeEventListener("touchstart", a), e.removeEventListener("mouseup", t), e.removeEventListener("touchend", t), window.removeEventListener("mouseup", t), window.removeEventListener("touchend", t), u.current && clearTimeout(u.current);
26
+ };
27
+ }, [n, f.state]), n ? w : {
28
+ ref: f,
29
+ pressed: w
11
30
  };
12
- return [{
13
- onMouseDown: T,
14
- onTouchStart: T,
15
- onMouseUp: d,
16
- onTouchEnd: d
17
- }, f];
18
31
  };
19
32
  export {
20
- s as useLongPress
33
+ I as useLongPress
21
34
  };
22
35
  //# sourceMappingURL=useLongPress.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"useLongPress.mjs","sources":["../../../../src/hooks/useLongPress/useLongPress.ts"],"sourcesContent":["import type { MouseEventHandler, RefObject, TouchEventHandler } from 'react';\n\nimport { useRef, useState } from 'react';\n\n// * The use long press target type */\nexport type UseLongPressTarget = (() => Element) | Element | RefObject<Element | null | undefined>;\n\nexport type LongPressReactEvents<Target extends Element = Element> =\n | MouseEventHandler<Target>\n | TouchEventHandler<Target>;\n\n// * The use long press options type */\nexport interface UseLongPressOptions {\n // * The threshold time in milliseconds\n threshold?: number;\n // * The callback function to be invoked on long press cancel\n onCancel?: (event: LongPressReactEvents) => void;\n // * The callback function to be invoked on long press end\n onFinish?: (event: LongPressReactEvents) => void;\n // * The callback function to be invoked on long press start\n onStart?: (event: LongPressReactEvents) => void;\n}\n\n// * The use long press bind type */\nexport interface UseLongPressBind {\n /** The callback function to be invoked on mouse down */\n onMouseDown: MouseEventHandler<Element>;\n /** The callback function to be invoked on mouse up */\n onMouseUp: MouseEventHandler<Element>;\n /** The callback function to be invoked on touch end */\n onTouchEnd: TouchEventHandler<Element>;\n /** The callback function to be invoked on touch start */\n onTouchStart: TouchEventHandler<Element>;\n}\n\n// * The use long press return type */\nexport type UseLongPressReturn = [UseLongPressBind, boolean];\n\nconst DEFAULT_THRESHOLD_TIME = 400;\n\n/**\n * @name useLongPress\n * @description - Hook that defines the logic when long pressing an element\n * @category Sensors\n *\n * @template Target The target element\n * @param {Target} target The target element to be long pressed\n * @param {(event: Event) => void} callback The callback function to be invoked on long press\n * @param {number} [options.threshold=400] The threshold time in milliseconds\n * @param {(event: Event) => void} [options.onStart] The callback function to be invoked on long press start\n * @param {(event: Event) => void} [options.onFinish] The callback function to be invoked on long press finish\n * @param {(event: Event) => void} [options.onCancel] The callback function to be invoked on long press cancel\n * @returns {UseLongPressReturn<Target>} The ref of the target element\n *\n * @example\n * const [bind, longPressing] = useLongPress(() => console.log('callback'));\n */\nexport const useLongPress = (\n callback: (event: LongPressReactEvents) => void,\n options?: UseLongPressOptions\n): UseLongPressReturn => {\n const [isLongPressActive, setIsLongPressActive] = useState(false);\n const timeoutIdRef = useRef<ReturnType<typeof setTimeout>>();\n const isPressed = useRef(false);\n\n const start = (event: LongPressReactEvents) => {\n options?.onStart?.(event);\n\n isPressed.current = true;\n timeoutIdRef.current = setTimeout(() => {\n callback(event);\n setIsLongPressActive(true);\n }, options?.threshold ?? DEFAULT_THRESHOLD_TIME);\n };\n\n const cancel = (event: LongPressReactEvents) => {\n if (isLongPressActive) {\n options?.onFinish?.(event);\n } else if (isPressed.current) {\n options?.onCancel?.(event);\n }\n\n setIsLongPressActive(false);\n isPressed.current = false;\n\n if (timeoutIdRef.current) clearTimeout(timeoutIdRef.current);\n };\n\n const bind = {\n onMouseDown: start,\n onTouchStart: start,\n onMouseUp: cancel,\n onTouchEnd: cancel\n } as unknown as UseLongPressBind;\n\n return [bind, isLongPressActive];\n};\n"],"names":["DEFAULT_THRESHOLD_TIME","useLongPress","callback","options","isLongPressActive","setIsLongPressActive","useState","timeoutIdRef","useRef","isPressed","start","event","_a","cancel","_b"],"mappings":";AAsCA,MAAMA,IAAyB,KAmBlBC,IAAe,CAC1BC,GACAC,MACuB;AACvB,QAAM,CAACC,GAAmBC,CAAoB,IAAIC,EAAS,EAAK,GAC1DC,IAAeC,EAAsC,GACrDC,IAAYD,EAAO,EAAK,GAExBE,IAAQ,CAACC,MAAgC;;AAC7C,KAAAC,IAAAT,KAAA,gBAAAA,EAAS,YAAT,QAAAS,EAAA,KAAAT,GAAmBQ,IAEnBF,EAAU,UAAU,IACPF,EAAA,UAAU,WAAW,MAAM;AACtC,MAAAL,EAASS,CAAK,GACdN,EAAqB,EAAI;AAAA,IAAA,IACxBF,KAAA,gBAAAA,EAAS,cAAaH,CAAsB;AAAA,EACjD,GAEMa,IAAS,CAACF,MAAgC;;AAC9C,IAAIP,KACFQ,IAAAT,KAAA,gBAAAA,EAAS,aAAT,QAAAS,EAAA,KAAAT,GAAoBQ,KACXF,EAAU,aACnBK,IAAAX,KAAA,gBAAAA,EAAS,aAAT,QAAAW,EAAA,KAAAX,GAAoBQ,KAGtBN,EAAqB,EAAK,GAC1BI,EAAU,UAAU,IAEhBF,EAAa,WAAsB,aAAAA,EAAa,OAAO;AAAA,EAC7D;AASO,SAAA,CAPM;AAAA,IACX,aAAaG;AAAA,IACb,cAAcA;AAAA,IACd,WAAWG;AAAA,IACX,YAAYA;AAAA,EACd,GAEcT,CAAiB;AACjC;"}
1
+ {"version":3,"file":"useLongPress.mjs","sources":["../../../../src/hooks/useLongPress/useLongPress.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\nexport type LongPressEvents = MouseEvent | TouchEvent;\n\n// * The use long press options type */\nexport interface UseLongPressOptions {\n // * The threshold time in milliseconds\n threshold?: number;\n // * The callback function to be invoked on long press cancel\n onCancel?: (event: LongPressEvents) => void;\n // * The callback function to be invoked on long press end\n onFinish?: (event: LongPressEvents) => void;\n // * The callback function to be invoked on long press start\n onStart?: (event: LongPressEvents) => void;\n}\n\nexport interface UseLongPress {\n (\n target: HookTarget,\n callback: (event: LongPressEvents) => void,\n options?: UseLongPressOptions\n ): boolean;\n\n <Target extends Element>(\n callback: (event: LongPressEvents) => void,\n options?: UseLongPressOptions,\n target?: never\n ): {\n ref: StateRef<Target>;\n pressed: boolean;\n };\n}\n\nconst DEFAULT_THRESHOLD_TIME = 400;\n\n/**\n * @name useLongPress\n * @description - Hook that defines the logic when long pressing an element\n * @category Sensors\n *\n * @overload\n * @param {HookTarget} target The target element to be long pressed\n * @param {(event: LongPressEvents) => void} callback The callback function to be invoked on long press\n * @param {UseLongPressOptions} [options] The options for the long press\n * @returns {boolean} The long pressing state\n *\n * @example\n * const pressed = useLongPress(ref, () => console.log('callback'));\n *\n * @overload\n * @template Target The target element\n * @param {(event: LongPressEvents) => void} callback The callback function to be invoked on long press\n * @param {UseLongPressOptions} [options] The options for the long press\n * @returns {boolean} The long pressing state\n *\n * @example\n * const { ref, pressed } = useLongPress(() => console.log('callback'));\n */\nexport const useLongPress = ((...params: any[]): any => {\n const target = (isTarget(params[0]) ? params[0] : undefined) as HookTarget | undefined;\n const callback = (target ? params[1] : params[0]) as (event: LongPressEvents) => void;\n const options = (target ? params[2] : params[1]) as UseLongPressOptions | undefined;\n\n const [pressed, setPressed] = useState(false);\n const timeoutIdRef = useRef<ReturnType<typeof setTimeout>>();\n const isPressedRef = useRef(false);\n const internalRef = useRefState<Element>();\n\n const internalCallbackRef = useRef(callback);\n internalCallbackRef.current = callback;\n const internalOptionsRef = useRef(options);\n internalOptionsRef.current = options;\n\n useEffect(() => {\n if (!target && !internalRef.state) return;\n\n const element = target ? getElement(target) : internalRef.current;\n if (!element) return;\n\n const onStart = (event: LongPressEvents) => {\n internalOptionsRef.current?.onStart?.(event);\n\n isPressedRef.current = true;\n timeoutIdRef.current = setTimeout(() => {\n internalCallbackRef.current(event);\n setPressed(true);\n }, internalOptionsRef.current?.threshold ?? DEFAULT_THRESHOLD_TIME);\n };\n\n const onCancel = (event: LongPressEvents) => {\n setPressed((prevPressed) => {\n if (prevPressed) {\n internalOptionsRef.current?.onFinish?.(event);\n } else if (isPressedRef.current) {\n internalOptionsRef.current?.onCancel?.(event);\n }\n\n return false;\n });\n\n isPressedRef.current = false;\n if (timeoutIdRef.current) clearTimeout(timeoutIdRef.current);\n };\n\n element.addEventListener('mousedown', onStart as EventListener);\n element.addEventListener('touchstart', onStart as EventListener);\n element.addEventListener('mouseup', onCancel as EventListener);\n element.addEventListener('touchend', onCancel as EventListener);\n window.addEventListener('mouseup', onCancel as EventListener);\n window.addEventListener('touchend', onCancel as EventListener);\n\n return () => {\n element.removeEventListener('mousedown', onStart as EventListener);\n element.removeEventListener('touchstart', onStart as EventListener);\n element.removeEventListener('mouseup', onCancel as EventListener);\n element.removeEventListener('touchend', onCancel as EventListener);\n window.removeEventListener('mouseup', onCancel as EventListener);\n window.removeEventListener('touchend', onCancel as EventListener);\n\n if (timeoutIdRef.current) clearTimeout(timeoutIdRef.current);\n };\n }, [target, internalRef.state]);\n\n if (target) return pressed;\n return {\n ref: internalRef,\n pressed\n };\n}) as UseLongPress;\n"],"names":["DEFAULT_THRESHOLD_TIME","useLongPress","params","target","isTarget","callback","options","pressed","setPressed","useState","timeoutIdRef","useRef","isPressedRef","internalRef","useRefState","internalCallbackRef","internalOptionsRef","useEffect","element","getElement","onStart","event","_b","_a","_c","onCancel","prevPressed","_d"],"mappings":";;;;AAyCA,MAAMA,IAAyB,KAyBlBC,IAAgB,IAAIC,MAAuB;AAChD,QAAAC,IAAUC,EAASF,EAAO,CAAC,CAAC,IAAIA,EAAO,CAAC,IAAI,QAC5CG,IAAYF,IAASD,EAAO,CAAC,IAAIA,EAAO,CAAC,GACzCI,IAAWH,IAASD,EAAO,CAAC,IAAIA,EAAO,CAAC,GAExC,CAACK,GAASC,CAAU,IAAIC,EAAS,EAAK,GACtCC,IAAeC,EAAsC,GACrDC,IAAeD,EAAO,EAAK,GAC3BE,IAAcC,EAAqB,GAEnCC,IAAsBJ,EAAON,CAAQ;AAC3C,EAAAU,EAAoB,UAAUV;AACxB,QAAAW,IAAqBL,EAAOL,CAAO;AAqDzC,SApDAU,EAAmB,UAAUV,GAE7BW,EAAU,MAAM;AACd,QAAI,CAACd,KAAU,CAACU,EAAY,MAAO;AAEnC,UAAMK,IAAUf,IAASgB,EAAWhB,CAAM,IAAIU,EAAY;AAC1D,QAAI,CAACK,EAAS;AAER,UAAAE,IAAU,CAACC,MAA2B;;AACvB,OAAAC,KAAAC,IAAAP,EAAA,YAAA,gBAAAO,EAAS,YAAT,QAAAD,EAAA,KAAAC,GAAmBF,IAEtCT,EAAa,UAAU,IACVF,EAAA,UAAU,WAAW,MAAM;AACtC,QAAAK,EAAoB,QAAQM,CAAK,GACjCb,EAAW,EAAI;AAAA,MACd,KAAAgB,IAAAR,EAAmB,YAAnB,gBAAAQ,EAA4B,cAAaxB,CAAsB;AAAA,IACpE,GAEMyB,IAAW,CAACJ,MAA2B;AAC3C,MAAAb,EAAW,CAACkB,MAAgB;;AAC1B,eAAIA,KACiBJ,KAAAC,IAAAP,EAAA,YAAA,gBAAAO,EAAS,aAAT,QAAAD,EAAA,KAAAC,GAAoBF,KAC9BT,EAAa,aACHe,KAAAH,IAAAR,EAAA,YAAA,gBAAAQ,EAAS,aAAT,QAAAG,EAAA,KAAAH,GAAoBH,KAGlC;AAAA,MAAA,CACR,GAEDT,EAAa,UAAU,IACnBF,EAAa,WAAsB,aAAAA,EAAa,OAAO;AAAA,IAC7D;AAEQ,WAAAQ,EAAA,iBAAiB,aAAaE,CAAwB,GACtDF,EAAA,iBAAiB,cAAcE,CAAwB,GACvDF,EAAA,iBAAiB,WAAWO,CAAyB,GACrDP,EAAA,iBAAiB,YAAYO,CAAyB,GACvD,OAAA,iBAAiB,WAAWA,CAAyB,GACrD,OAAA,iBAAiB,YAAYA,CAAyB,GAEtD,MAAM;AACH,MAAAP,EAAA,oBAAoB,aAAaE,CAAwB,GACzDF,EAAA,oBAAoB,cAAcE,CAAwB,GAC1DF,EAAA,oBAAoB,WAAWO,CAAyB,GACxDP,EAAA,oBAAoB,YAAYO,CAAyB,GAC1D,OAAA,oBAAoB,WAAWA,CAAyB,GACxD,OAAA,oBAAoB,YAAYA,CAAyB,GAE5Df,EAAa,WAAsB,aAAAA,EAAa,OAAO;AAAA,IAC7D;AAAA,EACC,GAAA,CAACP,GAAQU,EAAY,KAAK,CAAC,GAE1BV,IAAeI,IACZ;AAAA,IACL,KAAKM;AAAA,IACL,SAAAN;AAAA,EACF;AACF;"}
@@ -1 +1 @@
1
- {"version":3,"file":"useMouse.mjs","sources":["../../../../src/hooks/useMouse/useMouse.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 mouse return type */\nexport interface UseMouseReturn {\n /** The current element */\n element?: Element;\n /** The current element position x */\n elementPositionX: number;\n /** The current element position y */\n elementPositionY: number;\n /** The current element x position */\n elementX: number;\n /** The current element y position */\n elementY: number;\n /** The current mouse x position */\n x: number;\n /** The current mouse y position */\n y: number;\n}\n\nexport interface UseMouse {\n (target: HookTarget): UseMouseReturn;\n\n <Target extends Element>(target?: never): UseMouseReturn & { ref: StateRef<Target> };\n}\n\n/**\n * @name useMouse\n * @description - Hook that manages a mouse position\n * @category Sensors\n *\n * @overload\n * @param {HookTarget} target The target element to manage the mouse position for\n * @returns {UseMouseReturn} An object with the current mouse position\n *\n * @example\n * const { x, y, elementX, elementY, elementPositionX, elementPositionY } = useMouse(ref);\n *\n * @overload\n * @template Target The target element\n * @returns {UseMouseReturn & { ref: StateRef<Target> }} An object with the current mouse position and a ref\n *\n * @example\n * const { ref, x, y, elementX, elementY, elementPositionX, elementPositionY } = useMouse();\n */\nexport const useMouse = ((...params: any[]) => {\n const target = isTarget(params[0]) ? params[0] : undefined;\n\n const [value, setValue] = useState<UseMouseReturn>({\n x: 0,\n y: 0,\n element: undefined,\n elementX: 0,\n elementY: 0,\n elementPositionX: 0,\n elementPositionY: 0\n });\n\n const internalRef = useRefState<Element>();\n\n useEffect(() => {\n if (!target && !internalRef.state) return;\n const onMouseMove = (event: MouseEvent) => {\n const element = (target ? getElement(target) : internalRef.current) as Element;\n if (!element) return;\n\n const updatedValue = {\n x: event.pageX,\n y: event.pageY\n } as typeof value;\n\n const { left, top } = element.getBoundingClientRect();\n const elementPositionX = left + window.scrollX;\n const elementPositionY = top + window.scrollY;\n const elementX = event.pageX - elementPositionX;\n const elementY = event.pageY - elementPositionY;\n\n updatedValue.element = element;\n updatedValue.elementX = elementX;\n updatedValue.elementY = elementY;\n updatedValue.elementPositionX = elementPositionX;\n updatedValue.elementPositionY = elementPositionY;\n\n setValue((prevValue) => ({\n ...prevValue,\n ...updatedValue\n }));\n };\n\n document.addEventListener('mousemove', onMouseMove);\n return () => {\n document.removeEventListener('mousemove', onMouseMove);\n };\n }, [internalRef.state, target]);\n\n if (target) return value;\n return {\n ref: internalRef,\n ...value\n };\n}) as UseMouse;\n"],"names":["useMouse","params","target","isTarget","value","setValue","useState","internalRef","useRefState","useEffect","onMouseMove","event","element","getElement","updatedValue","left","top","elementPositionX","elementPositionY","elementX","elementY","prevValue"],"mappings":";;;;AAqDa,MAAAA,IAAY,IAAIC,MAAkB;AACvC,QAAAC,IAASC,EAASF,EAAO,CAAC,CAAC,IAAIA,EAAO,CAAC,IAAI,QAE3C,CAACG,GAAOC,CAAQ,IAAIC,EAAyB;AAAA,IACjD,GAAG;AAAA,IACH,GAAG;AAAA,IACH,SAAS;AAAA,IACT,UAAU;AAAA,IACV,UAAU;AAAA,IACV,kBAAkB;AAAA,IAClB,kBAAkB;AAAA,EAAA,CACnB,GAEKC,IAAcC,EAAqB;AAqCzC,SAnCAC,EAAU,MAAM;AACd,QAAI,CAACP,KAAU,CAACK,EAAY,MAAO;AAC7B,UAAAG,IAAc,CAACC,MAAsB;AACzC,YAAMC,IAAWV,IAASW,EAAWX,CAAM,IAAIK,EAAY;AAC3D,UAAI,CAACK,EAAS;AAEd,YAAME,IAAe;AAAA,QACnB,GAAGH,EAAM;AAAA,QACT,GAAGA,EAAM;AAAA,MACX,GAEM,EAAE,MAAAI,GAAM,KAAAC,MAAQJ,EAAQ,sBAAsB,GAC9CK,IAAmBF,IAAO,OAAO,SACjCG,IAAmBF,IAAM,OAAO,SAChCG,IAAWR,EAAM,QAAQM,GACzBG,IAAWT,EAAM,QAAQO;AAE/B,MAAAJ,EAAa,UAAUF,GACvBE,EAAa,WAAWK,GACxBL,EAAa,WAAWM,GACxBN,EAAa,mBAAmBG,GAChCH,EAAa,mBAAmBI,GAEhCb,EAAS,CAACgB,OAAe;AAAA,QACvB,GAAGA;AAAA,QACH,GAAGP;AAAA,MAAA,EACH;AAAA,IACJ;AAES,oBAAA,iBAAiB,aAAaJ,CAAW,GAC3C,MAAM;AACF,eAAA,oBAAoB,aAAaA,CAAW;AAAA,IACvD;AAAA,EACC,GAAA,CAACH,EAAY,OAAOL,CAAM,CAAC,GAE1BA,IAAeE,IACZ;AAAA,IACL,KAAKG;AAAA,IACL,GAAGH;AAAA,EACL;AACF;"}
1
+ {"version":3,"file":"useMouse.mjs","sources":["../../../../src/hooks/useMouse/useMouse.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 mouse return type */\nexport interface UseMouseReturn {\n /** The current element */\n element?: Element;\n /** The current element position x */\n elementPositionX: number;\n /** The current element position y */\n elementPositionY: number;\n /** The current element x position */\n elementX: number;\n /** The current element y position */\n elementY: number;\n /** The current mouse x position */\n x: number;\n /** The current mouse y position */\n y: number;\n}\n\nexport interface UseMouse {\n (target: HookTarget): UseMouseReturn;\n\n <Target extends Element>(target?: never): UseMouseReturn & { ref: StateRef<Target> };\n}\n\n/**\n * @name useMouse\n * @description - Hook that manages a mouse position\n * @category Sensors\n *\n * @overload\n * @param {HookTarget} target The target element to manage the mouse position for\n * @returns {UseMouseReturn} An object with the current mouse position\n *\n * @example\n * const { x, y, elementX, elementY, elementPositionX, elementPositionY } = useMouse(ref);\n *\n * @overload\n * @template Target The target element\n * @returns {UseMouseReturn & { ref: StateRef<Target> }} An object with the current mouse position and a ref\n *\n * @example\n * const { ref, x, y, elementX, elementY, elementPositionX, elementPositionY } = useMouse();\n */\nexport const useMouse = ((...params: any[]) => {\n const target = isTarget(params[0]) ? params[0] : undefined;\n\n const [value, setValue] = useState<UseMouseReturn>({\n x: 0,\n y: 0,\n element: undefined,\n elementX: 0,\n elementY: 0,\n elementPositionX: 0,\n elementPositionY: 0\n });\n\n const internalRef = useRefState<Element>();\n\n useEffect(() => {\n if (!target && !internalRef.state) return;\n\n const onMouseMove = (event: MouseEvent) => {\n const element = (target ? getElement(target) : internalRef.current) as Element;\n if (!element) return;\n\n const updatedValue = {\n x: event.pageX,\n y: event.pageY\n } as typeof value;\n\n const { left, top } = element.getBoundingClientRect();\n const elementPositionX = left + window.scrollX;\n const elementPositionY = top + window.scrollY;\n const elementX = event.pageX - elementPositionX;\n const elementY = event.pageY - elementPositionY;\n\n updatedValue.element = element;\n updatedValue.elementX = elementX;\n updatedValue.elementY = elementY;\n updatedValue.elementPositionX = elementPositionX;\n updatedValue.elementPositionY = elementPositionY;\n\n setValue((prevValue) => ({\n ...prevValue,\n ...updatedValue\n }));\n };\n\n document.addEventListener('mousemove', onMouseMove);\n return () => {\n document.removeEventListener('mousemove', onMouseMove);\n };\n }, [internalRef.state, target]);\n\n if (target) return value;\n return {\n ref: internalRef,\n ...value\n };\n}) as UseMouse;\n"],"names":["useMouse","params","target","isTarget","value","setValue","useState","internalRef","useRefState","useEffect","onMouseMove","event","element","getElement","updatedValue","left","top","elementPositionX","elementPositionY","elementX","elementY","prevValue"],"mappings":";;;;AAqDa,MAAAA,IAAY,IAAIC,MAAkB;AACvC,QAAAC,IAASC,EAASF,EAAO,CAAC,CAAC,IAAIA,EAAO,CAAC,IAAI,QAE3C,CAACG,GAAOC,CAAQ,IAAIC,EAAyB;AAAA,IACjD,GAAG;AAAA,IACH,GAAG;AAAA,IACH,SAAS;AAAA,IACT,UAAU;AAAA,IACV,UAAU;AAAA,IACV,kBAAkB;AAAA,IAClB,kBAAkB;AAAA,EAAA,CACnB,GAEKC,IAAcC,EAAqB;AAsCzC,SApCAC,EAAU,MAAM;AACd,QAAI,CAACP,KAAU,CAACK,EAAY,MAAO;AAE7B,UAAAG,IAAc,CAACC,MAAsB;AACzC,YAAMC,IAAWV,IAASW,EAAWX,CAAM,IAAIK,EAAY;AAC3D,UAAI,CAACK,EAAS;AAEd,YAAME,IAAe;AAAA,QACnB,GAAGH,EAAM;AAAA,QACT,GAAGA,EAAM;AAAA,MACX,GAEM,EAAE,MAAAI,GAAM,KAAAC,MAAQJ,EAAQ,sBAAsB,GAC9CK,IAAmBF,IAAO,OAAO,SACjCG,IAAmBF,IAAM,OAAO,SAChCG,IAAWR,EAAM,QAAQM,GACzBG,IAAWT,EAAM,QAAQO;AAE/B,MAAAJ,EAAa,UAAUF,GACvBE,EAAa,WAAWK,GACxBL,EAAa,WAAWM,GACxBN,EAAa,mBAAmBG,GAChCH,EAAa,mBAAmBI,GAEhCb,EAAS,CAACgB,OAAe;AAAA,QACvB,GAAGA;AAAA,QACH,GAAGP;AAAA,MAAA,EACH;AAAA,IACJ;AAES,oBAAA,iBAAiB,aAAaJ,CAAW,GAC3C,MAAM;AACF,eAAA,oBAAoB,aAAaA,CAAW;AAAA,IACvD;AAAA,EACC,GAAA,CAACH,EAAY,OAAOL,CAAM,CAAC,GAE1BA,IAAeE,IACZ;AAAA,IACL,KAAKG;AAAA,IACL,GAAGH;AAAA,EACL;AACF;"}
@@ -1,94 +1,99 @@
1
- import { useState as h, useEffect as k } from "react";
2
- import { useDeviceOrientation as R } from "../useDeviceOrientation/useDeviceOrientation.mjs";
3
- import { useMouse as T } from "../useMouse/useMouse.mjs";
4
- import { useRefState as x } from "../useRefState/useRefState.mjs";
5
- import { useScreenOrientation as j } from "../useScreenOrientation/useScreenOrientation.mjs";
6
- import { isTarget as w } from "../../utils/helpers/isTarget.mjs";
7
- const E = (...r) => {
8
- const u = w(r[0]) ? r[0] : void 0, v = r[1] ? r[1] : r[0], c = x(), a = T(u ?? c), i = j(), t = R(), {
9
- deviceOrientationRollAdjust: d = (n) => n,
10
- deviceOrientationTiltAdjust: p = (n) => n,
11
- mouseRollAdjust: f = (n) => n,
12
- mouseTiltAdjust: g = (n) => n
13
- } = v ?? {}, [m, b] = h({
1
+ import { useState as x, useEffect as B } from "react";
2
+ import { useDeviceOrientation as C } from "../useDeviceOrientation/useDeviceOrientation.mjs";
3
+ import { useRefState as D } from "../useRefState/useRefState.mjs";
4
+ import { useScreenOrientation as P } from "../useScreenOrientation/useScreenOrientation.mjs";
5
+ import { isTarget as X } from "../../utils/helpers/isTarget.mjs";
6
+ import { getElement as Y } from "../../utils/helpers/getElement.mjs";
7
+ const G = (...a) => {
8
+ const n = X(a[0]) ? a[0] : void 0, p = a[1] ? a[1] : a[0], i = D(), s = P(), e = C(), {
9
+ deviceOrientationRollAdjust: g = (o) => o,
10
+ deviceOrientationTiltAdjust: f = (o) => o,
11
+ mouseRollAdjust: b = (o) => o,
12
+ mouseTiltAdjust: y = (o) => o
13
+ } = p ?? {}, [u, O] = x({
14
14
  roll: 0,
15
15
  tilt: 0,
16
16
  source: "mouse"
17
- }), s = () => t.supported && (t.value.alpha || t.value.gamma) ? "deviceOrientation" : "mouse", y = () => {
18
- if (s() === "deviceOrientation") {
19
- let e;
20
- switch (i.value.orientationType) {
21
- case "landscape-primary":
22
- e = t.value.gamma / 90;
23
- break;
24
- case "landscape-secondary":
25
- e = -t.value.gamma / 90;
26
- break;
27
- case "portrait-primary":
28
- e = -t.value.beta / 90;
29
- break;
30
- case "portrait-secondary":
31
- e = t.value.beta / 90;
32
- break;
33
- default:
34
- e = -t.value.beta / 90;
35
- }
36
- return d(e);
37
- } else {
38
- if (!a.element) return 0;
39
- const e = a.y - a.elementPositionY, o = a.element.getBoundingClientRect().height, l = -(e - o / 2) / o;
40
- return f(l);
41
- }
42
- }, O = () => {
43
- if (s() === "deviceOrientation") {
44
- let e;
45
- switch (i.value.orientationType) {
46
- case "landscape-primary":
47
- e = t.value.beta / 90;
48
- break;
49
- case "landscape-secondary":
50
- e = -t.value.beta / 90;
51
- break;
52
- case "portrait-primary":
53
- e = t.value.gamma / 90;
54
- break;
55
- case "portrait-secondary":
56
- e = -t.value.gamma / 90;
57
- break;
58
- default:
59
- e = t.value.gamma / 90;
60
- }
61
- return p(e);
62
- } else {
63
- if (!a.element) return 0;
64
- const e = a.x - a.elementPositionX, o = a.element.getBoundingClientRect().width, l = (e - o / 2) / o;
65
- return g(l);
66
- }
67
- };
68
- return k(() => {
69
- if (!a.element) return;
70
- const n = s(), e = y(), o = O();
71
- b({
72
- roll: e,
73
- source: n,
74
- tilt: o
75
- });
17
+ });
18
+ return B(() => {
19
+ if (!n && !i.state) return;
20
+ const o = n ? Y(n) : i.current;
21
+ if (!o) return;
22
+ console.log("element", o);
23
+ const m = (v) => {
24
+ const { left: h, top: k } = o.getBoundingClientRect(), w = h + window.scrollX, R = k + window.scrollY, c = () => e.supported && (e.value.alpha || e.value.gamma) ? "deviceOrientation" : "mouse", T = () => {
25
+ if (c() === "deviceOrientation") {
26
+ let t;
27
+ switch (s.value.orientationType) {
28
+ case "landscape-primary":
29
+ t = e.value.gamma / 90;
30
+ break;
31
+ case "landscape-secondary":
32
+ t = -e.value.gamma / 90;
33
+ break;
34
+ case "portrait-primary":
35
+ t = -e.value.beta / 90;
36
+ break;
37
+ case "portrait-secondary":
38
+ t = e.value.beta / 90;
39
+ break;
40
+ default:
41
+ t = -e.value.beta / 90;
42
+ }
43
+ return g(t);
44
+ } else {
45
+ const t = v.pageY - R, r = o.getBoundingClientRect().height, l = -(t - r / 2) / r;
46
+ return b(l);
47
+ }
48
+ }, j = () => {
49
+ if (c() === "deviceOrientation") {
50
+ let t;
51
+ switch (s.value.orientationType) {
52
+ case "landscape-primary":
53
+ t = e.value.beta / 90;
54
+ break;
55
+ case "landscape-secondary":
56
+ t = -e.value.beta / 90;
57
+ break;
58
+ case "portrait-primary":
59
+ t = e.value.gamma / 90;
60
+ break;
61
+ case "portrait-secondary":
62
+ t = -e.value.gamma / 90;
63
+ break;
64
+ default:
65
+ t = e.value.gamma / 90;
66
+ }
67
+ return f(t);
68
+ } else {
69
+ const t = v.pageX - w, r = o.getBoundingClientRect().width, l = (t - r / 2) / r;
70
+ return y(l);
71
+ }
72
+ }, A = c(), E = T(), S = j();
73
+ O({
74
+ roll: E,
75
+ source: A,
76
+ tilt: S
77
+ });
78
+ };
79
+ return document.addEventListener("mousemove", m), () => {
80
+ document.removeEventListener("mousemove", m);
81
+ };
76
82
  }, [
77
- i.value.angle,
78
- i.value.orientationType,
79
- t.value.gamma,
80
- t.value.beta,
81
- t.value.alpha,
82
- t.value.absolute,
83
- a.x,
84
- a.y,
85
- a.element
86
- ]), u ? { value: m } : {
87
- ref: c,
88
- value: m
83
+ n,
84
+ i.state,
85
+ s.value.angle,
86
+ s.value.orientationType,
87
+ e.value.gamma,
88
+ e.value.beta,
89
+ e.value.alpha,
90
+ e.value.absolute
91
+ ]), n ? { value: u } : {
92
+ ref: i,
93
+ value: u
89
94
  };
90
95
  };
91
96
  export {
92
- E as useParallax
97
+ G as useParallax
93
98
  };
94
99
  //# sourceMappingURL=useParallax.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"useParallax.mjs","sources":["../../../../src/hooks/useParallax/useParallax.ts"],"sourcesContent":["import { useEffect, 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 { useDeviceOrientation } from '../useDeviceOrientation/useDeviceOrientation';\nimport { useMouse } from '../useMouse/useMouse';\nimport { useRefState } from '../useRefState/useRefState';\nimport { useScreenOrientation } from '../useScreenOrientation/useScreenOrientation';\n\n/** The use parallax value type */\nexport interface UseParallaxValue {\n /** Roll value. Scaled to `-0.5 ~ 0.5` */\n roll: number;\n /** Sensor source, can be `mouse` or `deviceOrientation` */\n source: 'deviceOrientation' | 'mouse';\n /** Tilt value. Scaled to `-0.5 ~ 0.5` */\n tilt: number;\n}\n\n/** The use parallax options type */\nexport interface UseParallaxOptions {\n /** Device orientation roll adjust function */\n deviceOrientationRollAdjust?: (value: number) => number;\n /** Device orientation tilt adjust function */\n deviceOrientationTiltAdjust?: (value: number) => number;\n /** Mouse roll adjust function */\n mouseRollAdjust?: (value: number) => number;\n /** Mouse tilt adjust function */\n mouseTiltAdjust?: (value: number) => number;\n}\n\ninterface UseParallaxReturn {\n value: UseParallaxValue;\n}\n\nexport interface UseParallax {\n (target: HookTarget, options?: UseParallaxOptions): UseParallaxReturn;\n\n <Target extends Element>(\n options?: UseParallaxOptions,\n target?: never\n ): UseParallaxReturn & {\n ref: StateRef<Target>;\n };\n}\n\n/**\n * @name useParallax\n * @description - Hook to help create parallax effect\n * @category Sensors\n *\n * @overload\n * @param {HookTarget} target The target element for the parallax effect\n * @param {UseParallaxOptions} options The options for the parallax effect\n * @returns {UseParallaxReturn} An object of parallax values\n *\n * @example\n * const { value } = useParallax(ref);\n *\n * @overload\n * @template Target The target element for the parallax effect\n * @param {UseParallaxOptions} options The options for the parallax effect\n * @returns {UseParallaxReturn & { ref: StateRef<Target> }} An object of parallax values\n *\n * @example\n * const { ref, value } = useParallax();\n */\nexport const useParallax = ((...params: any[]) => {\n const target = (isTarget(params[0]) ? params[0] : undefined) as HookTarget | undefined;\n const options = (params[1] ? params[1] : params[0]) as UseParallaxOptions | undefined;\n\n const internalRef = useRefState<Element>();\n\n const mouse = useMouse(target ?? internalRef);\n const screenOrientation = useScreenOrientation();\n const deviceOrientation = useDeviceOrientation();\n\n const {\n deviceOrientationRollAdjust = (value) => value,\n deviceOrientationTiltAdjust = (value) => value,\n mouseRollAdjust = (value) => value,\n mouseTiltAdjust = (value) => value\n } = (options ?? {}) as UseParallaxOptions;\n\n const [value, setValue] = useState({\n roll: 0,\n tilt: 0,\n source: 'mouse'\n });\n\n const getSource = () => {\n const isDeviceOrientation =\n deviceOrientation.supported &&\n (deviceOrientation.value.alpha || deviceOrientation.value.gamma);\n\n if (isDeviceOrientation) return 'deviceOrientation';\n return 'mouse';\n };\n\n const getRoll = () => {\n const source = getSource();\n if (source === 'deviceOrientation') {\n let value: number;\n switch (screenOrientation.value.orientationType) {\n case 'landscape-primary':\n value = deviceOrientation.value.gamma! / 90;\n break;\n case 'landscape-secondary':\n value = -deviceOrientation.value.gamma! / 90;\n break;\n case 'portrait-primary':\n value = -deviceOrientation.value.beta! / 90;\n break;\n case 'portrait-secondary':\n value = deviceOrientation.value.beta! / 90;\n break;\n default:\n value = -deviceOrientation.value.beta! / 90;\n }\n return deviceOrientationRollAdjust(value);\n } else {\n if (!mouse.element) return 0;\n const y = mouse.y - mouse.elementPositionY;\n const height = mouse.element.getBoundingClientRect().height;\n const value = -(y - height / 2) / height;\n return mouseRollAdjust(value);\n }\n };\n\n const getTilt = () => {\n const source = getSource();\n if (source === 'deviceOrientation') {\n let value: number;\n switch (screenOrientation.value.orientationType) {\n case 'landscape-primary':\n value = deviceOrientation.value.beta! / 90;\n break;\n case 'landscape-secondary':\n value = -deviceOrientation.value.beta! / 90;\n break;\n case 'portrait-primary':\n value = deviceOrientation.value.gamma! / 90;\n break;\n case 'portrait-secondary':\n value = -deviceOrientation.value.gamma! / 90;\n break;\n default:\n value = deviceOrientation.value.gamma! / 90;\n }\n return deviceOrientationTiltAdjust(value);\n } else {\n if (!mouse.element) return 0;\n const x = mouse.x - mouse.elementPositionX;\n const width = mouse.element.getBoundingClientRect().width;\n const value = (x - width / 2) / width;\n return mouseTiltAdjust(value);\n }\n };\n\n useEffect(() => {\n if (!mouse.element) return;\n\n const source = getSource();\n const roll = getRoll();\n const tilt = getTilt();\n\n setValue({\n roll,\n source,\n tilt\n });\n }, [\n screenOrientation.value.angle,\n screenOrientation.value.orientationType,\n deviceOrientation.value.gamma,\n deviceOrientation.value.beta,\n deviceOrientation.value.alpha,\n deviceOrientation.value.absolute,\n mouse.x,\n mouse.y,\n mouse.element\n ]);\n\n if (target) return { value };\n\n return {\n ref: internalRef,\n value\n };\n}) as UseParallax;\n"],"names":["useParallax","params","target","isTarget","options","internalRef","useRefState","mouse","useMouse","screenOrientation","useScreenOrientation","deviceOrientation","useDeviceOrientation","deviceOrientationRollAdjust","value","deviceOrientationTiltAdjust","mouseRollAdjust","mouseTiltAdjust","setValue","useState","getSource","getRoll","y","height","getTilt","x","width","useEffect","source","roll","tilt"],"mappings":";;;;;;AAuEa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A,IACxBJ,EAAM;AAAA,IACNA,EAAM;AAAA,IACNA,EAAM;AAAA,EAAA,CACP,GAEGL,IAAe,EAAE,OAAAY,EAAM,IAEpB;AAAA,IACL,KAAKT;AAAA,IACL,OAAAS;AAAA,EACF;AACF;"}
1
+ {"version":3,"file":"useParallax.mjs","sources":["../../../../src/hooks/useParallax/useParallax.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 { useDeviceOrientation } from '../useDeviceOrientation/useDeviceOrientation';\nimport { useRefState } from '../useRefState/useRefState';\nimport { useScreenOrientation } from '../useScreenOrientation/useScreenOrientation';\n\n/** The use parallax value type */\nexport interface UseParallaxValue {\n /** Roll value. Scaled to `-0.5 ~ 0.5` */\n roll: number;\n /** Sensor source, can be `mouse` or `deviceOrientation` */\n source: 'deviceOrientation' | 'mouse';\n /** Tilt value. Scaled to `-0.5 ~ 0.5` */\n tilt: number;\n}\n\n/** The use parallax options type */\nexport interface UseParallaxOptions {\n /** Device orientation roll adjust function */\n deviceOrientationRollAdjust?: (value: number) => number;\n /** Device orientation tilt adjust function */\n deviceOrientationTiltAdjust?: (value: number) => number;\n /** Mouse roll adjust function */\n mouseRollAdjust?: (value: number) => number;\n /** Mouse tilt adjust function */\n mouseTiltAdjust?: (value: number) => number;\n}\n\ninterface UseParallaxReturn {\n value: UseParallaxValue;\n}\n\nexport interface UseParallax {\n (target: HookTarget, options?: UseParallaxOptions): UseParallaxReturn;\n\n <Target extends Element>(\n options?: UseParallaxOptions,\n target?: never\n ): UseParallaxReturn & {\n ref: StateRef<Target>;\n };\n}\n\n/**\n * @name useParallax\n * @description - Hook to help create parallax effect\n * @category Sensors\n *\n * @overload\n * @param {HookTarget} target The target element for the parallax effect\n * @param {UseParallaxOptions} options The options for the parallax effect\n * @returns {UseParallaxReturn} An object of parallax values\n *\n * @example\n * const { value } = useParallax(ref);\n *\n * @overload\n * @template Target The target element for the parallax effect\n * @param {UseParallaxOptions} options The options for the parallax effect\n * @returns {UseParallaxReturn & { ref: StateRef<Target> }} An object of parallax values\n *\n * @example\n * const { ref, value } = useParallax();\n */\nexport const useParallax = ((...params: any[]) => {\n const target = (isTarget(params[0]) ? params[0] : undefined) as HookTarget | undefined;\n const options = (params[1] ? params[1] : params[0]) as UseParallaxOptions | undefined;\n\n const internalRef = useRefState<Element>();\n\n const screenOrientation = useScreenOrientation();\n const deviceOrientation = useDeviceOrientation();\n\n const {\n deviceOrientationRollAdjust = (value) => value,\n deviceOrientationTiltAdjust = (value) => value,\n mouseRollAdjust = (value) => value,\n mouseTiltAdjust = (value) => value\n } = (options ?? {}) as UseParallaxOptions;\n\n const [value, setValue] = useState({\n roll: 0,\n tilt: 0,\n source: 'mouse'\n });\n\n useEffect(() => {\n if (!target && !internalRef.state) return;\n\n const element = (target ? getElement(target) : internalRef.current) as Element;\n if (!element) return;\n\n console.log('element', element);\n const onMouseMove = (event: MouseEvent) => {\n const { left, top } = element.getBoundingClientRect();\n const elementPositionX = left + window.scrollX;\n const elementPositionY = top + window.scrollY;\n\n const getSource = () => {\n const isDeviceOrientation =\n deviceOrientation.supported &&\n (deviceOrientation.value.alpha || deviceOrientation.value.gamma);\n\n if (isDeviceOrientation) return 'deviceOrientation';\n return 'mouse';\n };\n\n const getRoll = () => {\n const source = getSource();\n if (source === 'deviceOrientation') {\n let value: number;\n switch (screenOrientation.value.orientationType) {\n case 'landscape-primary':\n value = deviceOrientation.value.gamma! / 90;\n break;\n case 'landscape-secondary':\n value = -deviceOrientation.value.gamma! / 90;\n break;\n case 'portrait-primary':\n value = -deviceOrientation.value.beta! / 90;\n break;\n case 'portrait-secondary':\n value = deviceOrientation.value.beta! / 90;\n break;\n default:\n value = -deviceOrientation.value.beta! / 90;\n }\n return deviceOrientationRollAdjust(value);\n } else {\n const y = event.pageY - elementPositionY;\n const height = element.getBoundingClientRect().height;\n const value = -(y - height / 2) / height;\n return mouseRollAdjust(value);\n }\n };\n\n const getTilt = () => {\n const source = getSource();\n if (source === 'deviceOrientation') {\n let value: number;\n switch (screenOrientation.value.orientationType) {\n case 'landscape-primary':\n value = deviceOrientation.value.beta! / 90;\n break;\n case 'landscape-secondary':\n value = -deviceOrientation.value.beta! / 90;\n break;\n case 'portrait-primary':\n value = deviceOrientation.value.gamma! / 90;\n break;\n case 'portrait-secondary':\n value = -deviceOrientation.value.gamma! / 90;\n break;\n default:\n value = deviceOrientation.value.gamma! / 90;\n }\n return deviceOrientationTiltAdjust(value);\n } else {\n const x = event.pageX - elementPositionX;\n const width = element.getBoundingClientRect().width;\n const value = (x - width / 2) / width;\n return mouseTiltAdjust(value);\n }\n };\n\n const source = getSource();\n const roll = getRoll();\n const tilt = getTilt();\n\n setValue({\n roll,\n source,\n tilt\n });\n };\n\n document.addEventListener('mousemove', onMouseMove);\n return () => {\n document.removeEventListener('mousemove', onMouseMove);\n };\n }, [\n target,\n internalRef.state,\n screenOrientation.value.angle,\n screenOrientation.value.orientationType,\n deviceOrientation.value.gamma,\n deviceOrientation.value.beta,\n deviceOrientation.value.alpha,\n deviceOrientation.value.absolute\n ]);\n\n if (target) return { value };\n\n return {\n ref: internalRef,\n value\n };\n}) as UseParallax;\n"],"names":["useParallax","params","target","isTarget","options","internalRef","useRefState","screenOrientation","useScreenOrientation","deviceOrientation","useDeviceOrientation","deviceOrientationRollAdjust","value","deviceOrientationTiltAdjust","mouseRollAdjust","mouseTiltAdjust","setValue","useState","useEffect","element","getElement","onMouseMove","event","left","top","elementPositionX","elementPositionY","getSource","getRoll","y","height","getTilt","x","width","source","roll","tilt"],"mappings":";;;;;;AAsEa,MAAAA,IAAe,IAAIC,MAAkB;AAC1C,QAAAC,IAAUC,EAASF,EAAO,CAAC,CAAC,IAAIA,EAAO,CAAC,IAAI,QAC5CG,IAAWH,EAAO,CAAC,IAAIA,EAAO,CAAC,IAAIA,EAAO,CAAC,GAE3CI,IAAcC,EAA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ACxBE,EAAkB,MAAM;AAAA,IACxBA,EAAkB,MAAM;AAAA,IACxBA,EAAkB,MAAM;AAAA,IACxBA,EAAkB,MAAM;AAAA,EAAA,CACzB,GAEGP,IAAe,EAAE,OAAAU,EAAM,IAEpB;AAAA,IACL,KAAKP;AAAA,IACL,OAAAO;AAAA,EACF;AACF;"}
@@ -0,0 +1,41 @@
1
+ import { useState as n, useEffect as U } from "react";
2
+ const R = () => (window == null ? void 0 : window.SpeechRecognition) ?? (window == null ? void 0 : window.webkitSpeechRecognition), z = (h = {}) => {
3
+ const u = typeof window < "u" && !!R(), {
4
+ continuous: S = !1,
5
+ interimResults: x = !1,
6
+ language: g = "en-US",
7
+ grammars: p,
8
+ maxAlternatives: A = 1,
9
+ onStart: r,
10
+ onEnd: i,
11
+ onError: c,
12
+ onResult: l
13
+ } = h, [f, s] = n(!1), [b, k] = n(""), [y, F] = n(!1), [I, m] = n(null), [o] = n(() => {
14
+ if (!u) return {};
15
+ const a = R(), t = new a();
16
+ return t.continuous = S, p && (t.grammars = p), t.interimResults = x, t.lang = g, t.maxAlternatives = A, t.onstart = () => {
17
+ s(!0), F(!1), r == null || r();
18
+ }, t.onend = () => {
19
+ s(!1), i == null || i();
20
+ }, t.onerror = (e) => {
21
+ m(e), s(!1), c == null || c(e);
22
+ }, t.onresult = (e) => {
23
+ console.log("onresult", e);
24
+ const L = e.results[e.resultIndex], { transcript: T } = L[0];
25
+ k(T), m(null), l == null || l(e);
26
+ }, t.onend = () => {
27
+ s(!1), t.lang = g;
28
+ }, t;
29
+ });
30
+ U(() => () => o.stop(), []);
31
+ const d = () => o.start(), w = () => o.stop();
32
+ return { supported: u, transcript: b, recognition: o, final: y, listening: f, error: I, start: d, stop: w, toggle: (a = !f) => {
33
+ if (a) return d();
34
+ w();
35
+ } };
36
+ };
37
+ export {
38
+ R as getSpeechRecognition,
39
+ z as useSpeechRecognition
40
+ };
41
+ //# sourceMappingURL=useSpeechRecognition.mjs.map
@@ -0,0 +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 Sensors\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 { supported, transcript, recognition, final, listening, error, start, stop, toggle };\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,OAClC,iCAAQ,uBAAqB,iCAAQ,0BAuB1BC,IAAuB,CAClCC,IAAuC,OACR;AAC/B,QAAMC,IAAY,OAAO,SAAW,OAAe,CAAC,CAACH,EAAqB,GAEpE;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,GAAOC,CAAQ,IAAIN,EAA6C,IAAI,GACrE,CAACO,CAAW,IAAIP,EAA4B,MAAM;AAClD,QAAA,CAACZ,EAAW,QAAO,CAAC;AAExB,UAAMoB,IAAoBvB,EAAqB,GACzCwB,IAAoB,IAAID,EAAkB;AAEhD,WAAAC,EAAkB,aAAapB,GAC3BG,QAA4B,WAAWA,IAC3CiB,EAAkB,iBAAiBnB,GACnCmB,EAAkB,OAAOlB,GACzBkB,EAAkB,kBAAkBhB,GAEpCgB,EAAkB,UAAU,MAAM;AAChC,MAAAV,EAAa,EAAI,GACjBK,EAAS,EAAK,GACJV,KAAA,QAAAA;AAAA,IACZ,GACAe,EAAkB,QAAQ,MAAM;AAC9B,MAAAV,EAAa,EAAK,GACVJ,KAAA,QAAAA;AAAA,IACV,GACkBc,EAAA,UAAU,CAACC,MAAU;AACrC,MAAAJ,EAASI,CAAK,GACdX,EAAa,EAAK,GAClBH,KAAA,QAAAA,EAAUc;AAAA,IACZ,GACkBD,EAAA,WAAW,CAACC,MAAU;AAC9B,cAAA,IAAI,YAAYA,CAAK;AAC7B,YAAMC,IAAgBD,EAAM,QAAQA,EAAM,WAAW,GAC/C,EAAE,YAAAT,MAAeU,EAAc,CAAC;AAEtC,MAAAT,EAAcD,CAAU,GACxBK,EAAS,IAAI,GACbT,KAAA,QAAAA,EAAWa;AAAA,IACb,GACAD,EAAkB,QAAQ,MAAM;AAC9B,MAAAV,EAAa,EAAK,GAClBU,EAAkB,OAAOlB;AAAA,IAC3B,GAEOkB;AAAA,EAAA,CACR;AAED,EAAAG,EAAU,MAAM,MAAML,EAAY,KAAK,GAAG,CAAA,CAAE;AAEtC,QAAAM,IAAQ,MAAMN,EAAY,MAAM,GAChCO,IAAO,MAAMP,EAAY,KAAK;AAO7B,SAAA,EAAE,WAAAnB,GAAW,YAAAa,GAAY,aAAAM,GAAa,OAAAJ,GAAO,WAAAL,GAAW,OAAAO,GAAO,OAAAQ,GAAO,MAAAC,GAAM,QALpE,CAACC,IAAQ,CAACjB,MAAc;AACjC,QAAAiB,UAAcF,EAAM;AACnB,IAAAC,EAAA;AAAA,EACP,EAE0F;AAC5F;"}
@@ -1,6 +1,7 @@
1
- import { useEventListener as t } from "../useEventListener/useEventListener.mjs";
2
- const r = (e, n, o) => t(window, e, n, o);
1
+ import { useEventListener as r } from "../useEventListener/useEventListener.mjs";
2
+ import { target as n } from "../../utils/helpers/getElement.mjs";
3
+ const s = (t, e, o) => r(n(window), t, e, o);
3
4
  export {
4
- r as useWindowEvent
5
+ s as useWindowEvent
5
6
  };
6
7
  //# sourceMappingURL=useWindowEvent.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"useWindowEvent.mjs","sources":["../../../../src/hooks/useWindowEvent/useWindowEvent.ts"],"sourcesContent":["import 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 Browser\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(window, event, listener, options);\n"],"names":["useWindowEvent","event","listener","options","useEventListener"],"mappings":";AAkBa,MAAAA,IAAiB,CAC5BC,GACAC,GACAC,MACGC,EAAiB,QAAQH,GAAOC,GAAUC,CAAO;"}
1
+ {"version":3,"file":"useWindowEvent.mjs","sources":["../../../../src/hooks/useWindowEvent/useWindowEvent.ts"],"sourcesContent":["import { target } 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 Browser\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(target(window), event, listener, options);\n"],"names":["useWindowEvent","event","listener","options","useEventListener","target"],"mappings":";;AAoBa,MAAAA,IAAiB,CAC5BC,GACAC,GACAC,MACGC,EAAiBC,EAAO,MAAM,GAAGJ,GAAOC,GAAUC,CAAO;"}