@siberiacancode/reactuse 0.0.113 → 0.0.114
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/useClickOutside/useClickOutside.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/useEventListener/useEventListener.cjs +1 -1
- package/dist/cjs/hooks/useEventListener/useEventListener.cjs.map +1 -1
- package/dist/cjs/hooks/useSpeechRecognition/useSpeechRecognition.cjs +2 -0
- package/dist/cjs/hooks/useSpeechRecognition/useSpeechRecognition.cjs.map +1 -0
- package/dist/cjs/hooks/useWindowEvent/useWindowEvent.cjs +1 -1
- package/dist/cjs/hooks/useWindowEvent/useWindowEvent.cjs.map +1 -1
- package/dist/cjs/index.cjs +1 -1
- package/dist/esm/hooks/useClickOutside/useClickOutside.mjs.map +1 -1
- package/dist/esm/hooks/useDocumentEvent/useDocumentEvent.mjs +4 -3
- package/dist/esm/hooks/useDocumentEvent/useDocumentEvent.mjs.map +1 -1
- package/dist/esm/hooks/useEventListener/useEventListener.mjs +15 -15
- package/dist/esm/hooks/useEventListener/useEventListener.mjs.map +1 -1
- package/dist/esm/hooks/useSpeechRecognition/useSpeechRecognition.mjs +41 -0
- package/dist/esm/hooks/useSpeechRecognition/useSpeechRecognition.mjs.map +1 -0
- package/dist/esm/hooks/useWindowEvent/useWindowEvent.mjs +4 -3
- package/dist/esm/hooks/useWindowEvent/useWindowEvent.mjs.map +1 -1
- package/dist/esm/index.mjs +105 -102
- package/dist/esm/index.mjs.map +1 -1
- package/dist/types/hooks/index.d.ts +1 -0
- package/dist/types/hooks/useClickOutside/useClickOutside.d.ts +3 -1
- package/dist/types/hooks/useEventListener/useEventListener.d.ts +5 -5
- package/dist/types/hooks/useSpeechRecognition/useSpeechRecognition.d.ts +69 -0
- package/package.json +2 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useClickOutside.cjs","sources":["../../../../src/hooks/useClickOutside/useClickOutside.ts"],"sourcesContent":["import { useEffect, useRef } from 'react';\n\nimport type { HookTarget } from '@/utils/helpers';\n\nimport { getElement, isTarget } from '@/utils/helpers';\n\nimport type { StateRef } from '../useRefState/useRefState';\n\nimport { useRefState } from '../useRefState/useRefState';\n\nexport interface UseClickOutside {\n (target: HookTarget, callback: (event: Event) => void): void;\n\n <Target extends Element>(callback: (event: Event) => void, target?: never): StateRef<Target>;\n}\n\n/**\n * @name useClickOutside\n * @description - Hook to handle click events outside the specified target element(s)\n * @category Sensors\n *\n * @overload\n * @param {HookTarget} target The target element(s) to detect outside clicks for\n * @param {(event: Event) => void} callback The callback to execute when a click outside the target is detected\n * @returns {void}\n *\n * @example\n * useClickOutside(ref, () => console.log('click outside'));\n *\n * @overload\n * @template Target The target element(s)\n * @param {(event: Event) => void} callback The callback to execute when a click outside the target is detected\n * @returns {(node: Target) => void} A React ref to attach to the target element\n *\n * @example\n * const ref = useClickOutside
|
|
1
|
+
{"version":3,"file":"useClickOutside.cjs","sources":["../../../../src/hooks/useClickOutside/useClickOutside.ts"],"sourcesContent":["import { useEffect, useRef } from 'react';\n\nimport type { HookTarget } from '@/utils/helpers';\n\nimport { getElement, isTarget } from '@/utils/helpers';\n\nimport type { StateRef } from '../useRefState/useRefState';\n\nimport { useRefState } from '../useRefState/useRefState';\n\nexport interface UseClickOutside {\n (target: HookTarget, callback: (event: Event) => void): void;\n\n <Target extends Element>(callback: (event: Event) => void, target?: never): StateRef<Target>;\n}\n\n/**\n * @name useClickOutside\n * @description - Hook to handle click events outside the specified target element(s)\n * @category Sensors\n *\n * @overload\n * @param {HookTarget} target The target element(s) to detect outside clicks for\n * @param {(event: Event) => void} callback The callback to execute when a click outside the target is detected\n * @returns {void}\n *\n * @example\n * useClickOutside(ref, () => console.log('click outside'));\n *\n * @overload\n * @template Target The target element(s)\n * @param {(event: Event) => void} callback The callback to execute when a click outside the target is detected\n * @returns {(node: Target) => void} A React ref to attach to the target element\n *\n * @example\n * const ref = `useClickOutside`<HTMLDivElement>(() => console.log('click outside'));\n *\n * @see {@link https://siberiacancode.github.io/reactuse/functions/hooks/useClickOutside.html}\n */\nexport const useClickOutside = ((...params: any[]) => {\n const target = (isTarget(params[0]) ? params[0] : undefined) as HookTarget | undefined;\n const callback = (params[1] ? params[1] : params[0]) as (event: Event) => void;\n\n const internalRef = useRefState<Element>();\n const internalCallbackRef = useRef(callback);\n internalCallbackRef.current = callback;\n\n useEffect(() => {\n if (!target && !internalRef.state) return;\n const onClick = (event: Event) => {\n const element = (target ? getElement(target) : internalRef.current) as Element;\n\n if (element && !element.contains(event.target as Node)) {\n internalCallbackRef.current(event);\n }\n };\n\n document.addEventListener('click', onClick);\n\n return () => {\n document.removeEventListener('click', onClick);\n };\n }, [target, internalRef.state]);\n\n if (target) return;\n return internalRef;\n}) as UseClickOutside;\n"],"names":["useClickOutside","params","target","isTarget","callback","internalRef","useRefState","internalCallbackRef","useRef","useEffect","onClick","event","element","getElement"],"mappings":"mPAuCaA,EAAmB,IAAIC,IAAkB,CAC9C,MAAAC,EAAUC,WAASF,EAAO,CAAC,CAAC,EAAIA,EAAO,CAAC,EAAI,OAC5CG,EAAYH,EAAO,CAAC,EAAIA,EAAO,CAAC,EAAIA,EAAO,CAAC,EAE5CI,EAAcC,EAAAA,YAAqB,EACnCC,EAAsBC,SAAOJ,CAAQ,EAoB3C,GAnBAG,EAAoB,QAAUH,EAE9BK,EAAAA,UAAU,IAAM,CACd,GAAI,CAACP,GAAU,CAACG,EAAY,MAAO,OAC7B,MAAAK,EAAWC,GAAiB,CAChC,MAAMC,EAAWV,EAASW,EAAAA,WAAWX,CAAM,EAAIG,EAAY,QAEvDO,GAAW,CAACA,EAAQ,SAASD,EAAM,MAAc,GACnDJ,EAAoB,QAAQI,CAAK,CAErC,EAES,gBAAA,iBAAiB,QAASD,CAAO,EAEnC,IAAM,CACF,SAAA,oBAAoB,QAASA,CAAO,CAC/C,CACC,EAAA,CAACR,EAAQG,EAAY,KAAK,CAAC,EAE1B,CAAAH,EACG,OAAAG,CACT"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("../useEventListener/useEventListener.cjs"),s=(e,t,n)=>u.useEventListener(document,e,t,n);exports.useDocumentEvent=s;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("../useEventListener/useEventListener.cjs"),r=require("../../utils/helpers/getElement.cjs"),s=(e,t,n)=>u.useEventListener(r.target(document),e,t,n);exports.useDocumentEvent=s;
|
|
2
2
|
//# sourceMappingURL=useDocumentEvent.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDocumentEvent.cjs","sources":["../../../../src/hooks/useDocumentEvent/useDocumentEvent.ts"],"sourcesContent":["import type { UseEventListenerOptions } from '../useEventListener/useEventListener';\n\nimport { useEventListener } from '../useEventListener/useEventListener';\n\n/**\n * @name useDocumentEvent\n * @description - Hook attaches an event listener to the document object for the specified event\n * @category Browser\n *\n * @template Event Key of document event map.\n * @param {Event} event The event to listen for.\n * @param {(event: DocumentEventMap[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 * useDocumentEvent('click', () => console.log('clicked'));\n */\nexport const useDocumentEvent = <Event extends keyof DocumentEventMap>(\n event: Event,\n listener: (this: Document, event: DocumentEventMap[Event]) => any,\n options?: UseEventListenerOptions\n) => useEventListener(document, event, listener, options);\n"],"names":["useDocumentEvent","event","listener","options","useEventListener"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useDocumentEvent.cjs","sources":["../../../../src/hooks/useDocumentEvent/useDocumentEvent.ts"],"sourcesContent":["import { target } from '@/utils/helpers';\n\nimport type { UseEventListenerOptions } from '../useEventListener/useEventListener';\n\nimport { useEventListener } from '../useEventListener/useEventListener';\n\n/**\n * @name useDocumentEvent\n * @description - Hook attaches an event listener to the document object for the specified event\n * @category Browser\n *\n * @template Event Key of document event map.\n * @param {Event} event The event to listen for.\n * @param {(event: DocumentEventMap[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 * useDocumentEvent('click', () => console.log('clicked'));\n */\nexport const useDocumentEvent = <Event extends keyof DocumentEventMap>(\n event: Event,\n listener: (this: Document, event: DocumentEventMap[Event]) => any,\n options?: UseEventListenerOptions\n) => useEventListener(target(document), event, listener, options);\n"],"names":["useDocumentEvent","event","listener","options","useEventListener","target"],"mappings":"4LAoBaA,EAAmB,CAC9BC,EACAC,EACAC,IACGC,EAAAA,iBAAiBC,EAAA,OAAO,QAAQ,EAAGJ,EAAOC,EAAUC,CAAO"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const v=require("react"),E=require("../useEvent/useEvent.cjs"),f=require("../useRefState/useRefState.cjs"),g=require("../../utils/helpers/isTarget.cjs"),d=require("../../utils/helpers/getElement.cjs"),q=(...e)=>{const t=g.isTarget(e[0])?e[0]:void 0,n=t?e[1]:e[0],c=t?e[2]:e[1],r=t?e[3]:e[2],s=f.useRefState(window),u=E.useEvent(c);if(v.useEffect(()=>{const i=t?d.getElement(t):s.current;if(!i)return;const o=l=>u(l);return i.addEventListener(n,o,r),()=>{i.removeEventListener(n,o,r)}},[t,s.state,n,r]),!t)return s};exports.useEventListener=q;
|
|
2
2
|
//# sourceMappingURL=useEventListener.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useEventListener.cjs","sources":["../../../../src/hooks/useEventListener/useEventListener.ts"],"sourcesContent":["import { useEffect } 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 { useEvent } from '../useEvent/useEvent';\nimport { useRefState } from '../useRefState/useRefState';\n\n/** The use event listener options */\nexport type UseEventListenerOptions = boolean | AddEventListenerOptions;\n\n/** The use event listener return type */\nexport type UseEventListenerReturn<Target extends Element> = StateRef<Target>;\n\nexport interface UseEventListener {\n <Event extends keyof WindowEventMap = keyof WindowEventMap>(\n target:
|
|
1
|
+
{"version":3,"file":"useEventListener.cjs","sources":["../../../../src/hooks/useEventListener/useEventListener.ts"],"sourcesContent":["import { useEffect } 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 { useEvent } from '../useEvent/useEvent';\nimport { useRefState } from '../useRefState/useRefState';\n\n/** The use event listener options */\nexport type UseEventListenerOptions = boolean | AddEventListenerOptions;\n\n/** The use event listener return type */\nexport type UseEventListenerReturn<Target extends Element> = StateRef<Target>;\n\nexport interface UseEventListener {\n <Event extends keyof WindowEventMap = keyof WindowEventMap>(\n target: HookTarget,\n event: Event,\n listener: (this: Window, event: WindowEventMap[Event]) => void,\n options?: UseEventListenerOptions\n ): void;\n\n <Event extends keyof DocumentEventMap = keyof DocumentEventMap>(\n target: HookTarget,\n event: Event,\n listener: (this: Document, event: DocumentEventMap[Event]) => void,\n options?: UseEventListenerOptions\n ): void;\n\n <Event extends keyof HTMLElementEventMap = keyof HTMLElementEventMap>(\n target: HookTarget,\n event: Event,\n listener: (this: Element, event: HTMLElementEventMap[Event]) => void,\n options?: UseEventListenerOptions\n ): void;\n\n <Target extends Element, Event extends keyof HTMLElementEventMap = keyof HTMLElementEventMap>(\n event: Event,\n listener: (this: Target, event: HTMLElementEventMap[Event]) => void,\n options?: UseEventListenerOptions,\n target?: never\n ): UseEventListenerReturn<Target>;\n\n <\n Target extends Element,\n Event extends keyof MediaQueryListEventMap = keyof MediaQueryListEventMap\n >(\n event: Event,\n listener: (this: Target, event: MediaQueryListEventMap[Event]) => void,\n options?: UseEventListenerOptions,\n target?: never\n ): UseEventListenerReturn<Target>;\n}\n\n/**\n * @name useEventListener\n * @description - Hook that attaches an event listener to the specified target\n * @category Browser\n *\n * @overload\n * @template Event Key of window event map\n * @param {Window} target The window object to attach the event listener to\n * @param {Event | Event[]} event An array of event types to listen for\n * @param {(this: Window, event: WindowEventMap[Event]) => void} handler The event handler function\n * @param {UseEventListenerOptions} [options] Options for the event listener\n * @returns {void}\n *\n * @example\n * useEventListener(window, 'click', () => console.log('click'));\n *\n * @overload\n * @template Event Key of window event map\n * @param {Document} target The window object to attach the event listener to\n * @param {Event | Event[]} event An array of event types to listen for\n * @param {(this: Document, event: DocumentEventMap[Event]) => void} handler The event handler function\n * @param {UseEventListenerOptions} [options] Options for the event listener\n * @returns {void}\n *\n * @example\n * useEventListener(document, 'click', () => console.log('click'));\n *\n * @overload\n * @template Event Key of window event map\n * @template Target The target element\n * @param {HookTarget} target The target element to attach the event listener to\n * @param {Event | Event[]} event An array of event types to listen for\n * @param {(this: Target, event: HTMLElementEventMap[Event]) => void} handler The event handler function\n * @param {UseEventListenerOptions} [options] Options for the event listener\n * @returns {void}\n *\n * @example\n * useEventListener(ref, 'click', () => console.log('click'));\n *\n * @overload\n * @template Event Key of window event map\n * @template Target The target element\n * @param {Event | Event[]} event An array of event types to listen for\n * @param {(this: Target, event: HTMLElementEventMap[Event] | MediaQueryListEventMap[Event]) => void} handler The event handler function\n * @param {UseEventListenerOptions} [options] Options for the event listener\n * @returns {UseEventListenerReturn<Target>} A reference to the target element\n *\n * @example\n * const ref = useEventListener('click', () => console.log('click'));\n */\nexport const useEventListener = ((...params: any[]) => {\n const target = (isTarget(params[0]) ? params[0] : undefined) as HookTarget | undefined;\n const event = (target ? params[1] : params[0]) as string;\n const listener = (target ? params[2] : params[1]) as (...arg: any[]) => undefined | void;\n const options = (target ? params[3] : params[2]) as UseEventListenerOptions | undefined;\n\n const internalRef = useRefState(window);\n const internalListener = useEvent(listener);\n\n useEffect(() => {\n const element = target ? getElement(target) : internalRef.current;\n if (!element) return;\n\n const callback = (event: Event) => internalListener(event);\n\n element.addEventListener(event, callback, options);\n return () => {\n element.removeEventListener(event, callback, options);\n };\n }, [target, internalRef.state, event, options]);\n\n if (target) return;\n return internalRef;\n}) as UseEventListener;\n"],"names":["useEventListener","params","target","isTarget","event","listener","options","internalRef","useRefState","internalListener","useEvent","useEffect","element","getElement","callback"],"mappings":"yRA2GaA,EAAoB,IAAIC,IAAkB,CAC/C,MAAAC,EAAUC,WAASF,EAAO,CAAC,CAAC,EAAIA,EAAO,CAAC,EAAI,OAC5CG,EAASF,EAASD,EAAO,CAAC,EAAIA,EAAO,CAAC,EACtCI,EAAYH,EAASD,EAAO,CAAC,EAAIA,EAAO,CAAC,EACzCK,EAAWJ,EAASD,EAAO,CAAC,EAAIA,EAAO,CAAC,EAExCM,EAAcC,cAAY,MAAM,EAChCC,EAAmBC,WAASL,CAAQ,EAc1C,GAZAM,EAAAA,UAAU,IAAM,CACd,MAAMC,EAAUV,EAASW,EAAAA,WAAWX,CAAM,EAAIK,EAAY,QAC1D,GAAI,CAACK,EAAS,OAEd,MAAME,EAAYV,GAAiBK,EAAiBL,CAAK,EAEjD,OAAAQ,EAAA,iBAAiBR,EAAOU,EAAUR,CAAO,EAC1C,IAAM,CACHM,EAAA,oBAAoBR,EAAOU,EAAUR,CAAO,CACtD,CAAA,EACC,CAACJ,EAAQK,EAAY,MAAOH,EAAOE,CAAO,CAAC,EAE1C,CAAAJ,EACG,OAAAK,CACT"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react"),u=()=>(window==null?void 0:window.SpeechRecognition)??(window==null?void 0:window.webkitSpeechRecognition),I=(h={})=>{const g=typeof window<"u"&&!!u(),{continuous:w=!1,interimResults:b=!1,language:p="en-US",grammars:f,maxAlternatives:x=1,onStart:i,onEnd:r,onError:c,onResult:a}=h,[S,s]=n.useState(!1),[y,A]=n.useState(""),[T,j]=n.useState(!1),[k,d]=n.useState(null),[o]=n.useState(()=>{if(!g)return{};const l=u(),e=new l;return e.continuous=w,f&&(e.grammars=f),e.interimResults=b,e.lang=p,e.maxAlternatives=x,e.onstart=()=>{s(!0),j(!1),i==null||i()},e.onend=()=>{s(!1),r==null||r()},e.onerror=t=>{d(t),s(!1),c==null||c(t)},e.onresult=t=>{console.log("onresult",t);const q=t.results[t.resultIndex],{transcript:F}=q[0];A(F),d(null),a==null||a(t)},e.onend=()=>{s(!1),e.lang=p},e});n.useEffect(()=>()=>o.stop(),[]);const R=()=>o.start(),m=()=>o.stop();return{supported:g,transcript:y,recognition:o,final:T,listening:S,error:k,start:R,stop:m,toggle:(l=!S)=>{if(l)return R();m()}}};exports.getSpeechRecognition=u;exports.useSpeechRecognition=I;
|
|
2
|
+
//# sourceMappingURL=useSpeechRecognition.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSpeechRecognition.cjs","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":"yGA8CaA,EAAuB,KAClC,2BAAQ,qBAAqB,2BAAQ,yBAuB1BC,EAAuB,CAClCC,EAAuC,KACR,CAC/B,MAAMC,EAAY,OAAO,OAAW,KAAe,CAAC,CAACH,EAAqB,EAEpE,CACJ,WAAAI,EAAa,GACb,eAAAC,EAAiB,GACjB,SAAAC,EAAW,QACX,SAAAC,EACA,gBAAAC,EAAkB,EAClB,QAAAC,EACA,MAAAC,EACA,QAAAC,EACA,SAAAC,CAAA,EACEV,EAEE,CAACW,EAAWC,CAAY,EAAIC,EAAAA,SAAS,EAAK,EAC1C,CAACC,EAAYC,CAAa,EAAIF,EAAAA,SAAS,EAAE,EACzC,CAACG,EAAOC,CAAQ,EAAIJ,EAAAA,SAAS,EAAK,EAClC,CAACK,EAAOC,CAAQ,EAAIN,EAAAA,SAA6C,IAAI,EACrE,CAACO,CAAW,EAAIP,EAAAA,SAA4B,IAAM,CAClD,GAAA,CAACZ,EAAW,MAAO,CAAC,EAExB,MAAMoB,EAAoBvB,EAAqB,EACzCwB,EAAoB,IAAID,EAE9B,OAAAC,EAAkB,WAAapB,EAC3BG,MAA4B,SAAWA,GAC3CiB,EAAkB,eAAiBnB,EACnCmB,EAAkB,KAAOlB,EACzBkB,EAAkB,gBAAkBhB,EAEpCgB,EAAkB,QAAU,IAAM,CAChCV,EAAa,EAAI,EACjBK,EAAS,EAAK,EACJV,GAAA,MAAAA,GACZ,EACAe,EAAkB,MAAQ,IAAM,CAC9BV,EAAa,EAAK,EACVJ,GAAA,MAAAA,GACV,EACkBc,EAAA,QAAWC,GAAU,CACrCJ,EAASI,CAAK,EACdX,EAAa,EAAK,EAClBH,GAAA,MAAAA,EAAUc,EACZ,EACkBD,EAAA,SAAYC,GAAU,CAC9B,QAAA,IAAI,WAAYA,CAAK,EAC7B,MAAMC,EAAgBD,EAAM,QAAQA,EAAM,WAAW,EAC/C,CAAE,WAAAT,GAAeU,EAAc,CAAC,EAEtCT,EAAcD,CAAU,EACxBK,EAAS,IAAI,EACbT,GAAA,MAAAA,EAAWa,EACb,EACAD,EAAkB,MAAQ,IAAM,CAC9BV,EAAa,EAAK,EAClBU,EAAkB,KAAOlB,CAC3B,EAEOkB,CAAA,CACR,EAEDG,EAAAA,UAAU,IAAM,IAAML,EAAY,KAAK,EAAG,CAAA,CAAE,EAEtC,MAAAM,EAAQ,IAAMN,EAAY,MAAM,EAChCO,EAAO,IAAMP,EAAY,KAAK,EAO7B,MAAA,CAAE,UAAAnB,EAAW,WAAAa,EAAY,YAAAM,EAAa,MAAAJ,EAAO,UAAAL,EAAW,MAAAO,EAAO,MAAAQ,EAAO,KAAAC,EAAM,OALpE,CAACC,EAAQ,CAACjB,IAAc,CACjC,GAAAiB,SAAcF,EAAM,EACnBC,EAAA,CACP,CAE0F,CAC5F"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("../useEventListener/useEventListener.cjs"),s=require("../../utils/helpers/getElement.cjs"),i=(e,t,n)=>r.useEventListener(s.target(window),e,t,n);exports.useWindowEvent=i;
|
|
2
2
|
//# sourceMappingURL=useWindowEvent.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useWindowEvent.cjs","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":"
|
|
1
|
+
{"version":3,"file":"useWindowEvent.cjs","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":"4LAoBaA,EAAiB,CAC5BC,EACAC,EACAC,IACGC,EAAAA,iBAAiBC,EAAA,OAAO,MAAM,EAAGJ,EAAOC,EAAUC,CAAO"}
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const T=require("./hooks/useActiveElement/useActiveElement.cjs"),P=require("./hooks/useAsync/useAsync.cjs"),C=require("./hooks/useBattery/useBattery.cjs"),E=require("./hooks/useBluetooth/useBluetooth.cjs"),m=require("./hooks/useBoolean/useBoolean.cjs"),e=require("./hooks/useBreakpoints/useBreakpoints.cjs"),O=require("./hooks/useBrowserLanguage/useBrowserLanguage.cjs"),y=require("./hooks/useClickOutside/useClickOutside.cjs"),I=require("./hooks/useClipboard/useClipboard.cjs"),p=require("./hooks/useConst/useConst.cjs"),s=require("./hooks/useCookie/useCookie.cjs"),u=require("./hooks/useCookies/useCookies.cjs"),R=require("./hooks/useCopy/useCopy.cjs"),v=require("./hooks/useCounter/useCounter.cjs"),k=require("./hooks/useCssVar/useCssVar.cjs"),D=require("./hooks/useDebounceCallback/useDebounceCallback.cjs"),b=require("./hooks/useDebounceValue/useDebounceValue.cjs"),A=require("./hooks/useDefault/useDefault.cjs"),M=require("./hooks/useDeviceMotion/useDeviceMotion.cjs"),f=require("./hooks/useDeviceOrientation/useDeviceOrientation.cjs"),L=require("./hooks/useDevicePixelRatio/useDevicePixelRatio.cjs"),_=require("./hooks/useDidUpdate/useDidUpdate.cjs"),N=require("./hooks/useDisclosure/useDisclosure.cjs"),B=require("./hooks/useDisplayMedia/useDisplayMedia.cjs"),h=require("./hooks/useDocumentEvent/useDocumentEvent.cjs"),K=require("./hooks/useDocumentTitle/useDocumentTitle.cjs"),V=require("./hooks/useDocumentVisibility/useDocumentVisibility.cjs"),F=require("./hooks/useElementSize/useElementSize.cjs"),w=require("./hooks/useEvent/useEvent.cjs"),W=require("./hooks/useEventListener/useEventListener.cjs"),x=require("./hooks/useEyeDropper/useEyeDropper.cjs"),H=require("./hooks/useFavicon/useFavicon.cjs"),U=require("./hooks/useField/useField.cjs"),z=require("./hooks/useFileDialog/useFileDialog.cjs"),G=require("./hooks/useFocus/useFocus.cjs"),Q=require("./hooks/useFps/useFps.cjs"),X=require("./hooks/useFullscreen/useFullscreen.cjs"),i=require("./hooks/useGamepad/useGamepad.cjs"),j=require("./hooks/useGeolocation/useGeolocation.cjs"),J=require("./hooks/useHash/useHash.cjs"),n=require("./hooks/useHotkeys/useHotkeys.cjs"),Y=require("./hooks/useHover/useHover.cjs"),Z=require("./hooks/useIdle/useIdle.cjs"),$=require("./hooks/useImage/useImage.cjs"),ee=require("./hooks/useInfiniteScroll/useInfiniteScroll.cjs"),se=require("./hooks/useIntersectionObserver/useIntersectionObserver.cjs"),ue=require("./hooks/useInterval/useInterval.cjs"),re=require("./hooks/useIsFirstRender/useIsFirstRender.cjs"),te=require("./hooks/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.cjs"),oe=require("./hooks/useKeyboard/useKeyboard.cjs"),ie=require("./hooks/useKeyPress/useKeyPress.cjs"),ne=require("./hooks/useKeyPressEvent/useKeyPressEvent.cjs"),ce=require("./hooks/useKeysPressed/useKeysPressed.cjs"),ae=require("./hooks/useLastChanged/useLastChanged.cjs"),le=require("./hooks/useLatest/useLatest.cjs"),qe=require("./hooks/useLess/useLess.cjs"),Se=require("./hooks/useList/useList.cjs"),de=require("./hooks/useLocalStorage/useLocalStorage.cjs"),ge=require("./hooks/useLockCallback/useLockCallback.cjs"),Te=require("./hooks/useLogger/useLogger.cjs"),Pe=require("./hooks/useLongPress/useLongPress.cjs"),Ce=require("./hooks/useMap/useMap.cjs"),Ee=require("./hooks/useMeasure/useMeasure.cjs"),me=require("./hooks/useMediaQuery/useMediaQuery.cjs"),Oe=require("./hooks/useMemory/useMemory.cjs"),ye=require("./hooks/useMount/useMount.cjs"),Ie=require("./hooks/useMouse/useMouse.cjs"),pe=require("./hooks/useMutation/useMutation.cjs"),Re=require("./hooks/useMutationObserver/useMutationObserver.cjs"),c=require("./hooks/useNetwork/useNetwork.cjs"),ve=require("./hooks/useOffsetPagination/useOffsetPagination.cjs"),ke=require("./hooks/useOnce/useOnce.cjs"),De=require("./hooks/useOnline/useOnline.cjs"),a=require("./hooks/useOperatingSystem/useOperatingSystem.cjs"),be=require("./hooks/useOptimistic/useOptimistic.cjs"),Ae=require("./hooks/useOrientation/useOrientation.cjs"),Me=require("./hooks/useOtpCredential/useOtpCredential.cjs"),fe=require("./hooks/usePageLeave/usePageLeave.cjs"),r=require("./hooks/usePaint/usePaint.cjs"),Le=require("./hooks/useParallax/useParallax.cjs"),_e=require("./hooks/usePerformanceObserver/usePerformanceObserver.cjs"),Ne=require("./hooks/usePermission/usePermission.cjs"),Be=require("./hooks/usePointerLock/usePointerLock.cjs"),he=require("./hooks/usePostMessage/usePostMessage.cjs"),Ke=require("./hooks/usePreferredColorScheme/usePreferredColorScheme.cjs"),Ve=require("./hooks/usePreferredContrast/usePreferredContrast.cjs"),Fe=require("./hooks/usePreferredDark/usePreferredDark.cjs"),we=require("./hooks/usePreferredLanguages/usePreferredLanguages.cjs"),We=require("./hooks/usePreferredReducedMotion/usePreferredReducedMotion.cjs"),xe=require("./hooks/usePrevious/usePrevious.cjs"),He=require("./hooks/useQuery/useQuery.cjs"),Ue=require("./hooks/useQueue/useQueue.cjs"),ze=require("./hooks/useRaf/useRaf.cjs"),Ge=require("./hooks/useRafValue/useRafValue.cjs"),Qe=require("./hooks/useRefState/useRefState.cjs"),Xe=require("./hooks/useRenderCount/useRenderCount.cjs"),je=require("./hooks/useRenderInfo/useRenderInfo.cjs"),Je=require("./hooks/useRerender/useRerender.cjs"),Ye=require("./hooks/useResizeObserver/useResizeObserver.cjs"),Ze=require("./hooks/useScreenOrientation/useScreenOrientation.cjs"),l=require("./hooks/useScript/useScript.cjs"),$e=require("./hooks/useScroll/useScroll.cjs"),es=require("./hooks/useScrollIntoView/useScrollIntoView.cjs"),ss=require("./hooks/useScrollTo/useScrollTo.cjs"),us=require("./hooks/useSessionStorage/useSessionStorage.cjs"),rs=require("./hooks/useSet/useSet.cjs"),ts=require("./hooks/useShare/useShare.cjs"),os=require("./hooks/useStateHistory/useStateHistory.cjs"),is=require("./hooks/useStep/useStep.cjs"),ns=require("./hooks/useSticky/useSticky.cjs"),cs=require("./hooks/useStopwatch/useStopwatch.cjs"),t=require("./hooks/useStorage/useStorage.cjs"),as=require("./hooks/useTextDirection/useTextDirection.cjs"),q=require("./hooks/useTextSelection/useTextSelection.cjs"),ls=require("./hooks/useThrottleCallback/useThrottleCallback.cjs"),qs=require("./hooks/useThrottleValue/useThrottleValue.cjs"),Ss=require("./hooks/useTime/useTime.cjs"),ds=require("./hooks/useTimeout/useTimeout.cjs"),S=require("./hooks/useTimer/useTimer.cjs"),gs=require("./hooks/useToggle/useToggle.cjs"),Ts=require("./hooks/useUnmount/useUnmount.cjs"),Ps=require("./hooks/useVibrate/useVibrate.cjs"),Cs=require("./hooks/useWebSocket/useWebSocket.cjs"),Es=require("./hooks/useWindowEvent/useWindowEvent.cjs"),ms=require("./hooks/useWindowFocus/useWindowFocus.cjs"),d=require("./hooks/useWindowScroll/useWindowScroll.cjs"),Os=require("./hooks/useWindowSize/useWindowSize.cjs"),ys=require("./hooks/useWizard/useWizard.cjs"),g=require("./utils/helpers/copy.cjs"),Is=require("./utils/helpers/debounce.cjs"),ps=require("./utils/helpers/getDate.cjs"),o=require("./utils/helpers/getElement.cjs"),Rs=require("./utils/helpers/getRetry.cjs"),vs=require("./utils/helpers/isTarget.cjs"),ks=require("./utils/helpers/throttle.cjs");exports.useActiveElement=T.useActiveElement;exports.useAsync=P.useAsync;exports.useBattery=C.useBattery;exports.useBluetooth=E.useBluetooth;exports.useBoolean=m.useBoolean;exports.BREAKPOINTS_ANT_DESIGN=e.BREAKPOINTS_ANT_DESIGN;exports.BREAKPOINTS_BOOTSTRAP_V5=e.BREAKPOINTS_BOOTSTRAP_V5;exports.BREAKPOINTS_MANTINE=e.BREAKPOINTS_MANTINE;exports.BREAKPOINTS_MASTER_CSS=e.BREAKPOINTS_MASTER_CSS;exports.BREAKPOINTS_MATERIAL_UI=e.BREAKPOINTS_MATERIAL_UI;exports.BREAKPOINTS_PRIME_FLEX=e.BREAKPOINTS_PRIME_FLEX;exports.BREAKPOINTS_QUASAR_V2=e.BREAKPOINTS_QUASAR_V2;exports.BREAKPOINTS_SEMANTIC=e.BREAKPOINTS_SEMANTIC;exports.BREAKPOINTS_TAILWIND=e.BREAKPOINTS_TAILWIND;exports.useBreakpoints=e.useBreakpoints;exports.useBrowserLanguage=O.useBrowserLanguage;exports.useClickOutside=y.useClickOutside;exports.useClipboard=I.useClipboard;exports.useConst=p.useConst;exports.COOKIE_EVENT=s.COOKIE_EVENT;exports.dispatchCookieEvent=s.dispatchCookieEvent;exports.getCookie=s.getCookie;exports.getCookies=s.getCookies;exports.removeCookie=s.removeCookie;exports.removeCookieItem=s.removeCookieItem;exports.setCookie=s.setCookie;exports.setCookieItem=s.setCookieItem;exports.useCookie=s.useCookie;exports.clearCookies=u.clearCookies;exports.getParsedCookies=u.getParsedCookies;exports.useCookies=u.useCookies;exports.useCopy=R.useCopy;exports.useCounter=v.useCounter;exports.useCssVar=k.useCssVar;exports.useDebounceCallback=D.useDebounceCallback;exports.useDebounceValue=b.useDebounceValue;exports.useDefault=A.useDefault;exports.useDeviceMotion=M.useDeviceMotion;exports.useDeviceOrientation=f.useDeviceOrientation;exports.useDevicePixelRatio=L.useDevicePixelRatio;exports.useDidUpdate=_.useDidUpdate;exports.useDisclosure=N.useDisclosure;exports.useDisplayMedia=B.useDisplayMedia;exports.useDocumentEvent=h.useDocumentEvent;exports.useDocumentTitle=K.useDocumentTitle;exports.useDocumentVisibility=V.useDocumentVisibility;exports.useElementSize=F.useElementSize;exports.useEvent=w.useEvent;exports.useEventListener=W.useEventListener;exports.useEyeDropper=x.useEyeDropper;exports.useFavicon=H.useFavicon;exports.useField=U.useField;exports.useFileDialog=z.useFileDialog;exports.useFocus=G.useFocus;exports.useFps=Q.useFps;exports.useFullscreen=X.useFullscreen;exports.mapGamepadToXbox360Controller=i.mapGamepadToXbox360Controller;exports.useGamepad=i.useGamepad;exports.useGeolocation=j.useGeolocation;exports.useHash=J.useHash;exports.isHotkeyMatch=n.isHotkeyMatch;exports.useHotkeys=n.useHotkeys;exports.useHover=Y.useHover;exports.useIdle=Z.useIdle;exports.useImage=$.useImage;exports.useInfiniteScroll=ee.useInfiniteScroll;exports.useIntersectionObserver=se.useIntersectionObserver;exports.useInterval=ue.useInterval;exports.useIsFirstRender=re.useIsFirstRender;exports.useIsomorphicLayoutEffect=te.useIsomorphicLayoutEffect;exports.useKeyboard=oe.useKeyboard;exports.useKeyPress=ie.useKeyPress;exports.useKeyPressEvent=ne.useKeyPressEvent;exports.useKeysPressed=ce.useKeysPressed;exports.useLastChanged=ae.useLastChanged;exports.useLatest=le.useLatest;exports.useLess=qe.useLess;exports.useList=Se.useList;exports.useLocalStorage=de.useLocalStorage;exports.useLockCallback=ge.useLockCallback;exports.useLogger=Te.useLogger;exports.useLongPress=Pe.useLongPress;exports.useMap=Ce.useMap;exports.useMeasure=Ee.useMeasure;exports.useMediaQuery=me.useMediaQuery;exports.useMemory=Oe.useMemory;exports.useMount=ye.useMount;exports.useMouse=Ie.useMouse;exports.useMutation=pe.useMutation;exports.useMutationObserver=Re.useMutationObserver;exports.getConnection=c.getConnection;exports.useNetwork=c.useNetwork;exports.useOffsetPagination=ve.useOffsetPagination;exports.useOnce=ke.useOnce;exports.useOnline=De.useOnline;exports.getOperatingSystem=a.getOperatingSystem;exports.useOperatingSystem=a.useOperatingSystem;exports.useOptimistic=be.useOptimistic;exports.useOrientation=Ae.useOrientation;exports.useOtpCredential=Me.useOtpCredential;exports.usePageLeave=fe.usePageLeave;exports.Paint=r.Paint;exports.Pointer=r.Pointer;exports.usePaint=r.usePaint;exports.useParallax=Le.useParallax;exports.usePerformanceObserver=_e.usePerformanceObserver;exports.usePermission=Ne.usePermission;exports.usePointerLock=Be.usePointerLock;exports.usePostMessage=he.usePostMessage;exports.usePreferredColorScheme=Ke.usePreferredColorScheme;exports.usePreferredContrast=Ve.usePreferredContrast;exports.usePreferredDark=Fe.usePreferredDark;exports.usePreferredLanguages=we.usePreferredLanguages;exports.usePreferredReducedMotion=We.usePreferredReducedMotion;exports.usePrevious=xe.usePrevious;exports.useQuery=He.useQuery;exports.useQueue=Ue.useQueue;exports.useRaf=ze.useRaf;exports.useRafValue=Ge.useRafValue;exports.useRefState=Qe.useRefState;exports.useRenderCount=Xe.useRenderCount;exports.useRenderInfo=je.useRenderInfo;exports.useRerender=Je.useRerender;exports.useResizeObserver=Ye.useResizeObserver;exports.useScreenOrientation=Ze.useScreenOrientation;exports.SCRIPT_STATUS_ATTRIBUTE_NAME=l.SCRIPT_STATUS_ATTRIBUTE_NAME;exports.useScript=l.useScript;exports.useScroll=$e.useScroll;exports.useScrollIntoView=es.useScrollIntoView;exports.useScrollTo=ss.useScrollTo;exports.useSessionStorage=us.useSessionStorage;exports.useSet=rs.useSet;exports.useShare=ts.useShare;exports.useStateHistory=os.useStateHistory;exports.useStep=is.useStep;exports.useSticky=ns.useSticky;exports.useStopwatch=cs.useStopwatch;exports.STORAGE_EVENT=t.STORAGE_EVENT;exports.dispatchStorageEvent=t.dispatchStorageEvent;exports.useStorage=t.useStorage;exports.useTextDirection=as.useTextDirection;exports.getRangesSelection=q.getRangesSelection;exports.useTextSelection=q.useTextSelection;exports.useThrottleCallback=ls.useThrottleCallback;exports.useThrottleValue=qs.useThrottleValue;exports.useTime=Ss.useTime;exports.useTimeout=ds.useTimeout;exports.getTimeFromSeconds=S.getTimeFromSeconds;exports.useTimer=S.useTimer;exports.useToggle=gs.useToggle;exports.useUnmount=Ts.useUnmount;exports.useVibrate=Ps.useVibrate;exports.useWebSocket=Cs.useWebSocket;exports.useWindowEvent=Es.useWindowEvent;exports.useWindowFocus=ms.useWindowFocus;exports.scrollTo=d.scrollTo;exports.useWindowScroll=d.useWindowScroll;exports.useWindowSize=Os.useWindowSize;exports.useWizard=ys.useWizard;exports.copy=g.copy;exports.legacyCopyToClipboard=g.legacyCopyToClipboard;exports.debounce=Is.debounce;exports.getDate=ps.getDate;exports.getElement=o.getElement;exports.target=o.target;exports.targetSymbol=o.targetSymbol;exports.getRetry=Rs.getRetry;exports.isTarget=vs.isTarget;exports.throttle=ks.throttle;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const P=require("./hooks/useActiveElement/useActiveElement.cjs"),C=require("./hooks/useAsync/useAsync.cjs"),E=require("./hooks/useBattery/useBattery.cjs"),m=require("./hooks/useBluetooth/useBluetooth.cjs"),p=require("./hooks/useBoolean/useBoolean.cjs"),e=require("./hooks/useBreakpoints/useBreakpoints.cjs"),R=require("./hooks/useBrowserLanguage/useBrowserLanguage.cjs"),O=require("./hooks/useClickOutside/useClickOutside.cjs"),y=require("./hooks/useClipboard/useClipboard.cjs"),I=require("./hooks/useConst/useConst.cjs"),s=require("./hooks/useCookie/useCookie.cjs"),u=require("./hooks/useCookies/useCookies.cjs"),v=require("./hooks/useCopy/useCopy.cjs"),k=require("./hooks/useCounter/useCounter.cjs"),D=require("./hooks/useCssVar/useCssVar.cjs"),b=require("./hooks/useDebounceCallback/useDebounceCallback.cjs"),A=require("./hooks/useDebounceValue/useDebounceValue.cjs"),M=require("./hooks/useDefault/useDefault.cjs"),f=require("./hooks/useDeviceMotion/useDeviceMotion.cjs"),L=require("./hooks/useDeviceOrientation/useDeviceOrientation.cjs"),h=require("./hooks/useDevicePixelRatio/useDevicePixelRatio.cjs"),_=require("./hooks/useDidUpdate/useDidUpdate.cjs"),N=require("./hooks/useDisclosure/useDisclosure.cjs"),B=require("./hooks/useDisplayMedia/useDisplayMedia.cjs"),K=require("./hooks/useDocumentEvent/useDocumentEvent.cjs"),V=require("./hooks/useDocumentTitle/useDocumentTitle.cjs"),F=require("./hooks/useDocumentVisibility/useDocumentVisibility.cjs"),w=require("./hooks/useElementSize/useElementSize.cjs"),W=require("./hooks/useEvent/useEvent.cjs"),x=require("./hooks/useEventListener/useEventListener.cjs"),H=require("./hooks/useEyeDropper/useEyeDropper.cjs"),U=require("./hooks/useFavicon/useFavicon.cjs"),z=require("./hooks/useField/useField.cjs"),G=require("./hooks/useFileDialog/useFileDialog.cjs"),Q=require("./hooks/useFocus/useFocus.cjs"),X=require("./hooks/useFps/useFps.cjs"),j=require("./hooks/useFullscreen/useFullscreen.cjs"),i=require("./hooks/useGamepad/useGamepad.cjs"),J=require("./hooks/useGeolocation/useGeolocation.cjs"),Y=require("./hooks/useHash/useHash.cjs"),n=require("./hooks/useHotkeys/useHotkeys.cjs"),Z=require("./hooks/useHover/useHover.cjs"),$=require("./hooks/useIdle/useIdle.cjs"),ee=require("./hooks/useImage/useImage.cjs"),se=require("./hooks/useInfiniteScroll/useInfiniteScroll.cjs"),ue=require("./hooks/useIntersectionObserver/useIntersectionObserver.cjs"),re=require("./hooks/useInterval/useInterval.cjs"),te=require("./hooks/useIsFirstRender/useIsFirstRender.cjs"),oe=require("./hooks/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.cjs"),ie=require("./hooks/useKeyboard/useKeyboard.cjs"),ne=require("./hooks/useKeyPress/useKeyPress.cjs"),ce=require("./hooks/useKeyPressEvent/useKeyPressEvent.cjs"),ae=require("./hooks/useKeysPressed/useKeysPressed.cjs"),le=require("./hooks/useLastChanged/useLastChanged.cjs"),qe=require("./hooks/useLatest/useLatest.cjs"),Se=require("./hooks/useLess/useLess.cjs"),de=require("./hooks/useList/useList.cjs"),ge=require("./hooks/useLocalStorage/useLocalStorage.cjs"),Te=require("./hooks/useLockCallback/useLockCallback.cjs"),Pe=require("./hooks/useLogger/useLogger.cjs"),Ce=require("./hooks/useLongPress/useLongPress.cjs"),Ee=require("./hooks/useMap/useMap.cjs"),me=require("./hooks/useMeasure/useMeasure.cjs"),pe=require("./hooks/useMediaQuery/useMediaQuery.cjs"),Re=require("./hooks/useMemory/useMemory.cjs"),Oe=require("./hooks/useMount/useMount.cjs"),ye=require("./hooks/useMouse/useMouse.cjs"),Ie=require("./hooks/useMutation/useMutation.cjs"),ve=require("./hooks/useMutationObserver/useMutationObserver.cjs"),c=require("./hooks/useNetwork/useNetwork.cjs"),ke=require("./hooks/useOffsetPagination/useOffsetPagination.cjs"),De=require("./hooks/useOnce/useOnce.cjs"),be=require("./hooks/useOnline/useOnline.cjs"),a=require("./hooks/useOperatingSystem/useOperatingSystem.cjs"),Ae=require("./hooks/useOptimistic/useOptimistic.cjs"),Me=require("./hooks/useOrientation/useOrientation.cjs"),fe=require("./hooks/useOtpCredential/useOtpCredential.cjs"),Le=require("./hooks/usePageLeave/usePageLeave.cjs"),r=require("./hooks/usePaint/usePaint.cjs"),he=require("./hooks/useParallax/useParallax.cjs"),_e=require("./hooks/usePerformanceObserver/usePerformanceObserver.cjs"),Ne=require("./hooks/usePermission/usePermission.cjs"),Be=require("./hooks/usePointerLock/usePointerLock.cjs"),Ke=require("./hooks/usePostMessage/usePostMessage.cjs"),Ve=require("./hooks/usePreferredColorScheme/usePreferredColorScheme.cjs"),Fe=require("./hooks/usePreferredContrast/usePreferredContrast.cjs"),we=require("./hooks/usePreferredDark/usePreferredDark.cjs"),We=require("./hooks/usePreferredLanguages/usePreferredLanguages.cjs"),xe=require("./hooks/usePreferredReducedMotion/usePreferredReducedMotion.cjs"),He=require("./hooks/usePrevious/usePrevious.cjs"),Ue=require("./hooks/useQuery/useQuery.cjs"),ze=require("./hooks/useQueue/useQueue.cjs"),Ge=require("./hooks/useRaf/useRaf.cjs"),Qe=require("./hooks/useRafValue/useRafValue.cjs"),Xe=require("./hooks/useRefState/useRefState.cjs"),je=require("./hooks/useRenderCount/useRenderCount.cjs"),Je=require("./hooks/useRenderInfo/useRenderInfo.cjs"),Ye=require("./hooks/useRerender/useRerender.cjs"),Ze=require("./hooks/useResizeObserver/useResizeObserver.cjs"),$e=require("./hooks/useScreenOrientation/useScreenOrientation.cjs"),l=require("./hooks/useScript/useScript.cjs"),es=require("./hooks/useScroll/useScroll.cjs"),ss=require("./hooks/useScrollIntoView/useScrollIntoView.cjs"),us=require("./hooks/useScrollTo/useScrollTo.cjs"),rs=require("./hooks/useSessionStorage/useSessionStorage.cjs"),ts=require("./hooks/useSet/useSet.cjs"),os=require("./hooks/useShare/useShare.cjs"),q=require("./hooks/useSpeechRecognition/useSpeechRecognition.cjs"),is=require("./hooks/useStateHistory/useStateHistory.cjs"),ns=require("./hooks/useStep/useStep.cjs"),cs=require("./hooks/useSticky/useSticky.cjs"),as=require("./hooks/useStopwatch/useStopwatch.cjs"),t=require("./hooks/useStorage/useStorage.cjs"),ls=require("./hooks/useTextDirection/useTextDirection.cjs"),S=require("./hooks/useTextSelection/useTextSelection.cjs"),qs=require("./hooks/useThrottleCallback/useThrottleCallback.cjs"),Ss=require("./hooks/useThrottleValue/useThrottleValue.cjs"),ds=require("./hooks/useTime/useTime.cjs"),gs=require("./hooks/useTimeout/useTimeout.cjs"),d=require("./hooks/useTimer/useTimer.cjs"),Ts=require("./hooks/useToggle/useToggle.cjs"),Ps=require("./hooks/useUnmount/useUnmount.cjs"),Cs=require("./hooks/useVibrate/useVibrate.cjs"),Es=require("./hooks/useWebSocket/useWebSocket.cjs"),ms=require("./hooks/useWindowEvent/useWindowEvent.cjs"),ps=require("./hooks/useWindowFocus/useWindowFocus.cjs"),g=require("./hooks/useWindowScroll/useWindowScroll.cjs"),Rs=require("./hooks/useWindowSize/useWindowSize.cjs"),Os=require("./hooks/useWizard/useWizard.cjs"),T=require("./utils/helpers/copy.cjs"),ys=require("./utils/helpers/debounce.cjs"),Is=require("./utils/helpers/getDate.cjs"),o=require("./utils/helpers/getElement.cjs"),vs=require("./utils/helpers/getRetry.cjs"),ks=require("./utils/helpers/isTarget.cjs"),Ds=require("./utils/helpers/throttle.cjs");exports.useActiveElement=P.useActiveElement;exports.useAsync=C.useAsync;exports.useBattery=E.useBattery;exports.useBluetooth=m.useBluetooth;exports.useBoolean=p.useBoolean;exports.BREAKPOINTS_ANT_DESIGN=e.BREAKPOINTS_ANT_DESIGN;exports.BREAKPOINTS_BOOTSTRAP_V5=e.BREAKPOINTS_BOOTSTRAP_V5;exports.BREAKPOINTS_MANTINE=e.BREAKPOINTS_MANTINE;exports.BREAKPOINTS_MASTER_CSS=e.BREAKPOINTS_MASTER_CSS;exports.BREAKPOINTS_MATERIAL_UI=e.BREAKPOINTS_MATERIAL_UI;exports.BREAKPOINTS_PRIME_FLEX=e.BREAKPOINTS_PRIME_FLEX;exports.BREAKPOINTS_QUASAR_V2=e.BREAKPOINTS_QUASAR_V2;exports.BREAKPOINTS_SEMANTIC=e.BREAKPOINTS_SEMANTIC;exports.BREAKPOINTS_TAILWIND=e.BREAKPOINTS_TAILWIND;exports.useBreakpoints=e.useBreakpoints;exports.useBrowserLanguage=R.useBrowserLanguage;exports.useClickOutside=O.useClickOutside;exports.useClipboard=y.useClipboard;exports.useConst=I.useConst;exports.COOKIE_EVENT=s.COOKIE_EVENT;exports.dispatchCookieEvent=s.dispatchCookieEvent;exports.getCookie=s.getCookie;exports.getCookies=s.getCookies;exports.removeCookie=s.removeCookie;exports.removeCookieItem=s.removeCookieItem;exports.setCookie=s.setCookie;exports.setCookieItem=s.setCookieItem;exports.useCookie=s.useCookie;exports.clearCookies=u.clearCookies;exports.getParsedCookies=u.getParsedCookies;exports.useCookies=u.useCookies;exports.useCopy=v.useCopy;exports.useCounter=k.useCounter;exports.useCssVar=D.useCssVar;exports.useDebounceCallback=b.useDebounceCallback;exports.useDebounceValue=A.useDebounceValue;exports.useDefault=M.useDefault;exports.useDeviceMotion=f.useDeviceMotion;exports.useDeviceOrientation=L.useDeviceOrientation;exports.useDevicePixelRatio=h.useDevicePixelRatio;exports.useDidUpdate=_.useDidUpdate;exports.useDisclosure=N.useDisclosure;exports.useDisplayMedia=B.useDisplayMedia;exports.useDocumentEvent=K.useDocumentEvent;exports.useDocumentTitle=V.useDocumentTitle;exports.useDocumentVisibility=F.useDocumentVisibility;exports.useElementSize=w.useElementSize;exports.useEvent=W.useEvent;exports.useEventListener=x.useEventListener;exports.useEyeDropper=H.useEyeDropper;exports.useFavicon=U.useFavicon;exports.useField=z.useField;exports.useFileDialog=G.useFileDialog;exports.useFocus=Q.useFocus;exports.useFps=X.useFps;exports.useFullscreen=j.useFullscreen;exports.mapGamepadToXbox360Controller=i.mapGamepadToXbox360Controller;exports.useGamepad=i.useGamepad;exports.useGeolocation=J.useGeolocation;exports.useHash=Y.useHash;exports.isHotkeyMatch=n.isHotkeyMatch;exports.useHotkeys=n.useHotkeys;exports.useHover=Z.useHover;exports.useIdle=$.useIdle;exports.useImage=ee.useImage;exports.useInfiniteScroll=se.useInfiniteScroll;exports.useIntersectionObserver=ue.useIntersectionObserver;exports.useInterval=re.useInterval;exports.useIsFirstRender=te.useIsFirstRender;exports.useIsomorphicLayoutEffect=oe.useIsomorphicLayoutEffect;exports.useKeyboard=ie.useKeyboard;exports.useKeyPress=ne.useKeyPress;exports.useKeyPressEvent=ce.useKeyPressEvent;exports.useKeysPressed=ae.useKeysPressed;exports.useLastChanged=le.useLastChanged;exports.useLatest=qe.useLatest;exports.useLess=Se.useLess;exports.useList=de.useList;exports.useLocalStorage=ge.useLocalStorage;exports.useLockCallback=Te.useLockCallback;exports.useLogger=Pe.useLogger;exports.useLongPress=Ce.useLongPress;exports.useMap=Ee.useMap;exports.useMeasure=me.useMeasure;exports.useMediaQuery=pe.useMediaQuery;exports.useMemory=Re.useMemory;exports.useMount=Oe.useMount;exports.useMouse=ye.useMouse;exports.useMutation=Ie.useMutation;exports.useMutationObserver=ve.useMutationObserver;exports.getConnection=c.getConnection;exports.useNetwork=c.useNetwork;exports.useOffsetPagination=ke.useOffsetPagination;exports.useOnce=De.useOnce;exports.useOnline=be.useOnline;exports.getOperatingSystem=a.getOperatingSystem;exports.useOperatingSystem=a.useOperatingSystem;exports.useOptimistic=Ae.useOptimistic;exports.useOrientation=Me.useOrientation;exports.useOtpCredential=fe.useOtpCredential;exports.usePageLeave=Le.usePageLeave;exports.Paint=r.Paint;exports.Pointer=r.Pointer;exports.usePaint=r.usePaint;exports.useParallax=he.useParallax;exports.usePerformanceObserver=_e.usePerformanceObserver;exports.usePermission=Ne.usePermission;exports.usePointerLock=Be.usePointerLock;exports.usePostMessage=Ke.usePostMessage;exports.usePreferredColorScheme=Ve.usePreferredColorScheme;exports.usePreferredContrast=Fe.usePreferredContrast;exports.usePreferredDark=we.usePreferredDark;exports.usePreferredLanguages=We.usePreferredLanguages;exports.usePreferredReducedMotion=xe.usePreferredReducedMotion;exports.usePrevious=He.usePrevious;exports.useQuery=Ue.useQuery;exports.useQueue=ze.useQueue;exports.useRaf=Ge.useRaf;exports.useRafValue=Qe.useRafValue;exports.useRefState=Xe.useRefState;exports.useRenderCount=je.useRenderCount;exports.useRenderInfo=Je.useRenderInfo;exports.useRerender=Ye.useRerender;exports.useResizeObserver=Ze.useResizeObserver;exports.useScreenOrientation=$e.useScreenOrientation;exports.SCRIPT_STATUS_ATTRIBUTE_NAME=l.SCRIPT_STATUS_ATTRIBUTE_NAME;exports.useScript=l.useScript;exports.useScroll=es.useScroll;exports.useScrollIntoView=ss.useScrollIntoView;exports.useScrollTo=us.useScrollTo;exports.useSessionStorage=rs.useSessionStorage;exports.useSet=ts.useSet;exports.useShare=os.useShare;exports.getSpeechRecognition=q.getSpeechRecognition;exports.useSpeechRecognition=q.useSpeechRecognition;exports.useStateHistory=is.useStateHistory;exports.useStep=ns.useStep;exports.useSticky=cs.useSticky;exports.useStopwatch=as.useStopwatch;exports.STORAGE_EVENT=t.STORAGE_EVENT;exports.dispatchStorageEvent=t.dispatchStorageEvent;exports.useStorage=t.useStorage;exports.useTextDirection=ls.useTextDirection;exports.getRangesSelection=S.getRangesSelection;exports.useTextSelection=S.useTextSelection;exports.useThrottleCallback=qs.useThrottleCallback;exports.useThrottleValue=Ss.useThrottleValue;exports.useTime=ds.useTime;exports.useTimeout=gs.useTimeout;exports.getTimeFromSeconds=d.getTimeFromSeconds;exports.useTimer=d.useTimer;exports.useToggle=Ts.useToggle;exports.useUnmount=Ps.useUnmount;exports.useVibrate=Cs.useVibrate;exports.useWebSocket=Es.useWebSocket;exports.useWindowEvent=ms.useWindowEvent;exports.useWindowFocus=ps.useWindowFocus;exports.scrollTo=g.scrollTo;exports.useWindowScroll=g.useWindowScroll;exports.useWindowSize=Rs.useWindowSize;exports.useWizard=Os.useWizard;exports.copy=T.copy;exports.legacyCopyToClipboard=T.legacyCopyToClipboard;exports.debounce=ys.debounce;exports.getDate=Is.getDate;exports.getElement=o.getElement;exports.target=o.target;exports.targetSymbol=o.targetSymbol;exports.getRetry=vs.getRetry;exports.isTarget=ks.isTarget;exports.throttle=Ds.throttle;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useClickOutside.mjs","sources":["../../../../src/hooks/useClickOutside/useClickOutside.ts"],"sourcesContent":["import { useEffect, useRef } from 'react';\n\nimport type { HookTarget } from '@/utils/helpers';\n\nimport { getElement, isTarget } from '@/utils/helpers';\n\nimport type { StateRef } from '../useRefState/useRefState';\n\nimport { useRefState } from '../useRefState/useRefState';\n\nexport interface UseClickOutside {\n (target: HookTarget, callback: (event: Event) => void): void;\n\n <Target extends Element>(callback: (event: Event) => void, target?: never): StateRef<Target>;\n}\n\n/**\n * @name useClickOutside\n * @description - Hook to handle click events outside the specified target element(s)\n * @category Sensors\n *\n * @overload\n * @param {HookTarget} target The target element(s) to detect outside clicks for\n * @param {(event: Event) => void} callback The callback to execute when a click outside the target is detected\n * @returns {void}\n *\n * @example\n * useClickOutside(ref, () => console.log('click outside'));\n *\n * @overload\n * @template Target The target element(s)\n * @param {(event: Event) => void} callback The callback to execute when a click outside the target is detected\n * @returns {(node: Target) => void} A React ref to attach to the target element\n *\n * @example\n * const ref = useClickOutside
|
|
1
|
+
{"version":3,"file":"useClickOutside.mjs","sources":["../../../../src/hooks/useClickOutside/useClickOutside.ts"],"sourcesContent":["import { useEffect, useRef } from 'react';\n\nimport type { HookTarget } from '@/utils/helpers';\n\nimport { getElement, isTarget } from '@/utils/helpers';\n\nimport type { StateRef } from '../useRefState/useRefState';\n\nimport { useRefState } from '../useRefState/useRefState';\n\nexport interface UseClickOutside {\n (target: HookTarget, callback: (event: Event) => void): void;\n\n <Target extends Element>(callback: (event: Event) => void, target?: never): StateRef<Target>;\n}\n\n/**\n * @name useClickOutside\n * @description - Hook to handle click events outside the specified target element(s)\n * @category Sensors\n *\n * @overload\n * @param {HookTarget} target The target element(s) to detect outside clicks for\n * @param {(event: Event) => void} callback The callback to execute when a click outside the target is detected\n * @returns {void}\n *\n * @example\n * useClickOutside(ref, () => console.log('click outside'));\n *\n * @overload\n * @template Target The target element(s)\n * @param {(event: Event) => void} callback The callback to execute when a click outside the target is detected\n * @returns {(node: Target) => void} A React ref to attach to the target element\n *\n * @example\n * const ref = `useClickOutside`<HTMLDivElement>(() => console.log('click outside'));\n *\n * @see {@link https://siberiacancode.github.io/reactuse/functions/hooks/useClickOutside.html}\n */\nexport const useClickOutside = ((...params: any[]) => {\n const target = (isTarget(params[0]) ? params[0] : undefined) as HookTarget | undefined;\n const callback = (params[1] ? params[1] : params[0]) as (event: Event) => void;\n\n const internalRef = useRefState<Element>();\n const internalCallbackRef = useRef(callback);\n internalCallbackRef.current = callback;\n\n useEffect(() => {\n if (!target && !internalRef.state) return;\n const onClick = (event: Event) => {\n const element = (target ? getElement(target) : internalRef.current) as Element;\n\n if (element && !element.contains(event.target as Node)) {\n internalCallbackRef.current(event);\n }\n };\n\n document.addEventListener('click', onClick);\n\n return () => {\n document.removeEventListener('click', onClick);\n };\n }, [target, internalRef.state]);\n\n if (target) return;\n return internalRef;\n}) as UseClickOutside;\n"],"names":["useClickOutside","params","target","isTarget","callback","internalRef","useRefState","internalCallbackRef","useRef","useEffect","onClick","event","element","getElement"],"mappings":";;;;AAuCa,MAAAA,IAAmB,IAAIC,MAAkB;AAC9C,QAAAC,IAAUC,EAASF,EAAO,CAAC,CAAC,IAAIA,EAAO,CAAC,IAAI,QAC5CG,IAAYH,EAAO,CAAC,IAAIA,EAAO,CAAC,IAAIA,EAAO,CAAC,GAE5CI,IAAcC,EAAqB,GACnCC,IAAsBC,EAAOJ,CAAQ;AAoB3C,MAnBAG,EAAoB,UAAUH,GAE9BK,EAAU,MAAM;AACd,QAAI,CAACP,KAAU,CAACG,EAAY,MAAO;AAC7B,UAAAK,IAAU,CAACC,MAAiB;AAChC,YAAMC,IAAWV,IAASW,EAAWX,CAAM,IAAIG,EAAY;AAE3D,MAAIO,KAAW,CAACA,EAAQ,SAASD,EAAM,MAAc,KACnDJ,EAAoB,QAAQI,CAAK;AAAA,IAErC;AAES,oBAAA,iBAAiB,SAASD,CAAO,GAEnC,MAAM;AACF,eAAA,oBAAoB,SAASA,CAAO;AAAA,IAC/C;AAAA,EACC,GAAA,CAACR,GAAQG,EAAY,KAAK,CAAC,GAE1B,CAAAH;AACG,WAAAG;AACT;"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { useEventListener as
|
|
2
|
-
|
|
1
|
+
import { useEventListener as r } from "../useEventListener/useEventListener.mjs";
|
|
2
|
+
import { target as m } from "../../utils/helpers/getElement.mjs";
|
|
3
|
+
const u = (t, e, o) => r(m(document), t, e, o);
|
|
3
4
|
export {
|
|
4
|
-
|
|
5
|
+
u as useDocumentEvent
|
|
5
6
|
};
|
|
6
7
|
//# sourceMappingURL=useDocumentEvent.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDocumentEvent.mjs","sources":["../../../../src/hooks/useDocumentEvent/useDocumentEvent.ts"],"sourcesContent":["import type { UseEventListenerOptions } from '../useEventListener/useEventListener';\n\nimport { useEventListener } from '../useEventListener/useEventListener';\n\n/**\n * @name useDocumentEvent\n * @description - Hook attaches an event listener to the document object for the specified event\n * @category Browser\n *\n * @template Event Key of document event map.\n * @param {Event} event The event to listen for.\n * @param {(event: DocumentEventMap[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 * useDocumentEvent('click', () => console.log('clicked'));\n */\nexport const useDocumentEvent = <Event extends keyof DocumentEventMap>(\n event: Event,\n listener: (this: Document, event: DocumentEventMap[Event]) => any,\n options?: UseEventListenerOptions\n) => useEventListener(document, event, listener, options);\n"],"names":["useDocumentEvent","event","listener","options","useEventListener"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useDocumentEvent.mjs","sources":["../../../../src/hooks/useDocumentEvent/useDocumentEvent.ts"],"sourcesContent":["import { target } from '@/utils/helpers';\n\nimport type { UseEventListenerOptions } from '../useEventListener/useEventListener';\n\nimport { useEventListener } from '../useEventListener/useEventListener';\n\n/**\n * @name useDocumentEvent\n * @description - Hook attaches an event listener to the document object for the specified event\n * @category Browser\n *\n * @template Event Key of document event map.\n * @param {Event} event The event to listen for.\n * @param {(event: DocumentEventMap[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 * useDocumentEvent('click', () => console.log('clicked'));\n */\nexport const useDocumentEvent = <Event extends keyof DocumentEventMap>(\n event: Event,\n listener: (this: Document, event: DocumentEventMap[Event]) => any,\n options?: UseEventListenerOptions\n) => useEventListener(target(document), event, listener, options);\n"],"names":["useDocumentEvent","event","listener","options","useEventListener","target"],"mappings":";;AAoBa,MAAAA,IAAmB,CAC9BC,GACAC,GACAC,MACGC,EAAiBC,EAAO,QAAQ,GAAGJ,GAAOC,GAAUC,CAAO;"}
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import { useEffect as
|
|
2
|
-
import { useEvent as
|
|
1
|
+
import { useEffect as l } from "react";
|
|
2
|
+
import { useEvent as v } from "../useEvent/useEvent.mjs";
|
|
3
3
|
import { useRefState as m } from "../useRefState/useRefState.mjs";
|
|
4
|
-
import { isTarget as
|
|
5
|
-
import { getElement as
|
|
6
|
-
const
|
|
7
|
-
const e =
|
|
8
|
-
if (
|
|
9
|
-
const
|
|
10
|
-
if (!
|
|
11
|
-
const
|
|
12
|
-
return
|
|
13
|
-
|
|
4
|
+
import { isTarget as E } from "../../utils/helpers/isTarget.mjs";
|
|
5
|
+
import { getElement as d } from "../../utils/helpers/getElement.mjs";
|
|
6
|
+
const k = (...t) => {
|
|
7
|
+
const e = E(t[0]) ? t[0] : void 0, n = e ? t[1] : t[0], c = e ? t[2] : t[1], o = e ? t[3] : t[2], r = m(window), f = v(c);
|
|
8
|
+
if (l(() => {
|
|
9
|
+
const i = e ? d(e) : r.current;
|
|
10
|
+
if (!i) return;
|
|
11
|
+
const s = (u) => f(u);
|
|
12
|
+
return i.addEventListener(n, s, o), () => {
|
|
13
|
+
i.removeEventListener(n, s, o);
|
|
14
14
|
};
|
|
15
|
-
}, [e,
|
|
16
|
-
return
|
|
15
|
+
}, [e, r.state, n, o]), !e)
|
|
16
|
+
return r;
|
|
17
17
|
};
|
|
18
18
|
export {
|
|
19
|
-
|
|
19
|
+
k as useEventListener
|
|
20
20
|
};
|
|
21
21
|
//# sourceMappingURL=useEventListener.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useEventListener.mjs","sources":["../../../../src/hooks/useEventListener/useEventListener.ts"],"sourcesContent":["import { useEffect } 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 { useEvent } from '../useEvent/useEvent';\nimport { useRefState } from '../useRefState/useRefState';\n\n/** The use event listener options */\nexport type UseEventListenerOptions = boolean | AddEventListenerOptions;\n\n/** The use event listener return type */\nexport type UseEventListenerReturn<Target extends Element> = StateRef<Target>;\n\nexport interface UseEventListener {\n <Event extends keyof WindowEventMap = keyof WindowEventMap>(\n target:
|
|
1
|
+
{"version":3,"file":"useEventListener.mjs","sources":["../../../../src/hooks/useEventListener/useEventListener.ts"],"sourcesContent":["import { useEffect } 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 { useEvent } from '../useEvent/useEvent';\nimport { useRefState } from '../useRefState/useRefState';\n\n/** The use event listener options */\nexport type UseEventListenerOptions = boolean | AddEventListenerOptions;\n\n/** The use event listener return type */\nexport type UseEventListenerReturn<Target extends Element> = StateRef<Target>;\n\nexport interface UseEventListener {\n <Event extends keyof WindowEventMap = keyof WindowEventMap>(\n target: HookTarget,\n event: Event,\n listener: (this: Window, event: WindowEventMap[Event]) => void,\n options?: UseEventListenerOptions\n ): void;\n\n <Event extends keyof DocumentEventMap = keyof DocumentEventMap>(\n target: HookTarget,\n event: Event,\n listener: (this: Document, event: DocumentEventMap[Event]) => void,\n options?: UseEventListenerOptions\n ): void;\n\n <Event extends keyof HTMLElementEventMap = keyof HTMLElementEventMap>(\n target: HookTarget,\n event: Event,\n listener: (this: Element, event: HTMLElementEventMap[Event]) => void,\n options?: UseEventListenerOptions\n ): void;\n\n <Target extends Element, Event extends keyof HTMLElementEventMap = keyof HTMLElementEventMap>(\n event: Event,\n listener: (this: Target, event: HTMLElementEventMap[Event]) => void,\n options?: UseEventListenerOptions,\n target?: never\n ): UseEventListenerReturn<Target>;\n\n <\n Target extends Element,\n Event extends keyof MediaQueryListEventMap = keyof MediaQueryListEventMap\n >(\n event: Event,\n listener: (this: Target, event: MediaQueryListEventMap[Event]) => void,\n options?: UseEventListenerOptions,\n target?: never\n ): UseEventListenerReturn<Target>;\n}\n\n/**\n * @name useEventListener\n * @description - Hook that attaches an event listener to the specified target\n * @category Browser\n *\n * @overload\n * @template Event Key of window event map\n * @param {Window} target The window object to attach the event listener to\n * @param {Event | Event[]} event An array of event types to listen for\n * @param {(this: Window, event: WindowEventMap[Event]) => void} handler The event handler function\n * @param {UseEventListenerOptions} [options] Options for the event listener\n * @returns {void}\n *\n * @example\n * useEventListener(window, 'click', () => console.log('click'));\n *\n * @overload\n * @template Event Key of window event map\n * @param {Document} target The window object to attach the event listener to\n * @param {Event | Event[]} event An array of event types to listen for\n * @param {(this: Document, event: DocumentEventMap[Event]) => void} handler The event handler function\n * @param {UseEventListenerOptions} [options] Options for the event listener\n * @returns {void}\n *\n * @example\n * useEventListener(document, 'click', () => console.log('click'));\n *\n * @overload\n * @template Event Key of window event map\n * @template Target The target element\n * @param {HookTarget} target The target element to attach the event listener to\n * @param {Event | Event[]} event An array of event types to listen for\n * @param {(this: Target, event: HTMLElementEventMap[Event]) => void} handler The event handler function\n * @param {UseEventListenerOptions} [options] Options for the event listener\n * @returns {void}\n *\n * @example\n * useEventListener(ref, 'click', () => console.log('click'));\n *\n * @overload\n * @template Event Key of window event map\n * @template Target The target element\n * @param {Event | Event[]} event An array of event types to listen for\n * @param {(this: Target, event: HTMLElementEventMap[Event] | MediaQueryListEventMap[Event]) => void} handler The event handler function\n * @param {UseEventListenerOptions} [options] Options for the event listener\n * @returns {UseEventListenerReturn<Target>} A reference to the target element\n *\n * @example\n * const ref = useEventListener('click', () => console.log('click'));\n */\nexport const useEventListener = ((...params: any[]) => {\n const target = (isTarget(params[0]) ? params[0] : undefined) as HookTarget | undefined;\n const event = (target ? params[1] : params[0]) as string;\n const listener = (target ? params[2] : params[1]) as (...arg: any[]) => undefined | void;\n const options = (target ? params[3] : params[2]) as UseEventListenerOptions | undefined;\n\n const internalRef = useRefState(window);\n const internalListener = useEvent(listener);\n\n useEffect(() => {\n const element = target ? getElement(target) : internalRef.current;\n if (!element) return;\n\n const callback = (event: Event) => internalListener(event);\n\n element.addEventListener(event, callback, options);\n return () => {\n element.removeEventListener(event, callback, options);\n };\n }, [target, internalRef.state, event, options]);\n\n if (target) return;\n return internalRef;\n}) as UseEventListener;\n"],"names":["useEventListener","params","target","isTarget","event","listener","options","internalRef","useRefState","internalListener","useEvent","useEffect","element","getElement","callback"],"mappings":";;;;;AA2Ga,MAAAA,IAAoB,IAAIC,MAAkB;AAC/C,QAAAC,IAAUC,EAASF,EAAO,CAAC,CAAC,IAAIA,EAAO,CAAC,IAAI,QAC5CG,IAASF,IAASD,EAAO,CAAC,IAAIA,EAAO,CAAC,GACtCI,IAAYH,IAASD,EAAO,CAAC,IAAIA,EAAO,CAAC,GACzCK,IAAWJ,IAASD,EAAO,CAAC,IAAIA,EAAO,CAAC,GAExCM,IAAcC,EAAY,MAAM,GAChCC,IAAmBC,EAASL,CAAQ;AAc1C,MAZAM,EAAU,MAAM;AACd,UAAMC,IAAUV,IAASW,EAAWX,CAAM,IAAIK,EAAY;AAC1D,QAAI,CAACK,EAAS;AAEd,UAAME,IAAW,CAACV,MAAiBK,EAAiBL,CAAK;AAEjD,WAAAQ,EAAA,iBAAiBR,GAAOU,GAAUR,CAAO,GAC1C,MAAM;AACH,MAAAM,EAAA,oBAAoBR,GAAOU,GAAUR,CAAO;AAAA,IACtD;AAAA,EAAA,GACC,CAACJ,GAAQK,EAAY,OAAOH,GAAOE,CAAO,CAAC,GAE1C,CAAAJ;AACG,WAAAK;AACT;"}
|
|
@@ -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
|
|
2
|
-
|
|
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
|
-
|
|
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":"
|
|
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;"}
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { useActiveElement as r } from "./hooks/useActiveElement/useActiveElement.mjs";
|
|
2
2
|
import { useAsync as s } from "./hooks/useAsync/useAsync.mjs";
|
|
3
|
-
import { useBattery as
|
|
3
|
+
import { useBattery as p } from "./hooks/useBattery/useBattery.mjs";
|
|
4
4
|
import { useBluetooth as f } from "./hooks/useBluetooth/useBluetooth.mjs";
|
|
5
5
|
import { useBoolean as i } from "./hooks/useBoolean/useBoolean.mjs";
|
|
6
|
-
import { BREAKPOINTS_ANT_DESIGN as n, BREAKPOINTS_BOOTSTRAP_V5 as l, BREAKPOINTS_MANTINE as c, BREAKPOINTS_MASTER_CSS as S, BREAKPOINTS_MATERIAL_UI as T, BREAKPOINTS_PRIME_FLEX as
|
|
7
|
-
import { useBrowserLanguage as
|
|
6
|
+
import { BREAKPOINTS_ANT_DESIGN as n, BREAKPOINTS_BOOTSTRAP_V5 as l, BREAKPOINTS_MANTINE as c, BREAKPOINTS_MASTER_CSS as S, BREAKPOINTS_MATERIAL_UI as T, BREAKPOINTS_PRIME_FLEX as g, BREAKPOINTS_QUASAR_V2 as d, BREAKPOINTS_SEMANTIC as E, BREAKPOINTS_TAILWIND as P, useBreakpoints as C } from "./hooks/useBreakpoints/useBreakpoints.mjs";
|
|
7
|
+
import { useBrowserLanguage as R } from "./hooks/useBrowserLanguage/useBrowserLanguage.mjs";
|
|
8
8
|
import { useClickOutside as y } from "./hooks/useClickOutside/useClickOutside.mjs";
|
|
9
9
|
import { useClipboard as k } from "./hooks/useClipboard/useClipboard.mjs";
|
|
10
10
|
import { useConst as _ } from "./hooks/useConst/useConst.mjs";
|
|
11
|
-
import { COOKIE_EVENT as M, dispatchCookieEvent as N, getCookie as b, getCookies as L, removeCookie as B, removeCookieItem as
|
|
11
|
+
import { COOKIE_EVENT as M, dispatchCookieEvent as N, getCookie as b, getCookies as L, removeCookie as B, removeCookieItem as h, setCookie as K, setCookieItem as V, useCookie as F } from "./hooks/useCookie/useCookie.mjs";
|
|
12
12
|
import { clearCookies as W, getParsedCookies as U, useCookies as G } from "./hooks/useCookies/useCookies.mjs";
|
|
13
13
|
import { useCopy as z } from "./hooks/useCopy/useCopy.mjs";
|
|
14
14
|
import { useCounter as X } from "./hooks/useCounter/useCounter.mjs";
|
|
@@ -18,22 +18,22 @@ import { useDebounceValue as $ } from "./hooks/useDebounceValue/useDebounceValue
|
|
|
18
18
|
import { useDefault as oe } from "./hooks/useDefault/useDefault.mjs";
|
|
19
19
|
import { useDeviceMotion as te } from "./hooks/useDeviceMotion/useDeviceMotion.mjs";
|
|
20
20
|
import { useDeviceOrientation as me } from "./hooks/useDeviceOrientation/useDeviceOrientation.mjs";
|
|
21
|
-
import { useDevicePixelRatio as
|
|
21
|
+
import { useDevicePixelRatio as ue } from "./hooks/useDevicePixelRatio/useDevicePixelRatio.mjs";
|
|
22
22
|
import { useDidUpdate as xe } from "./hooks/useDidUpdate/useDidUpdate.mjs";
|
|
23
23
|
import { useDisclosure as ae } from "./hooks/useDisclosure/useDisclosure.mjs";
|
|
24
24
|
import { useDisplayMedia as le } from "./hooks/useDisplayMedia/useDisplayMedia.mjs";
|
|
25
25
|
import { useDocumentEvent as Se } from "./hooks/useDocumentEvent/useDocumentEvent.mjs";
|
|
26
|
-
import { useDocumentTitle as
|
|
26
|
+
import { useDocumentTitle as ge } from "./hooks/useDocumentTitle/useDocumentTitle.mjs";
|
|
27
27
|
import { useDocumentVisibility as Ee } from "./hooks/useDocumentVisibility/useDocumentVisibility.mjs";
|
|
28
28
|
import { useElementSize as Ce } from "./hooks/useElementSize/useElementSize.mjs";
|
|
29
|
-
import { useEvent as
|
|
29
|
+
import { useEvent as Re } from "./hooks/useEvent/useEvent.mjs";
|
|
30
30
|
import { useEventListener as ye } from "./hooks/useEventListener/useEventListener.mjs";
|
|
31
31
|
import { useEyeDropper as ke } from "./hooks/useEyeDropper/useEyeDropper.mjs";
|
|
32
32
|
import { useFavicon as _e } from "./hooks/useFavicon/useFavicon.mjs";
|
|
33
33
|
import { useField as Me } from "./hooks/useField/useField.mjs";
|
|
34
34
|
import { useFileDialog as be } from "./hooks/useFileDialog/useFileDialog.mjs";
|
|
35
35
|
import { useFocus as Be } from "./hooks/useFocus/useFocus.mjs";
|
|
36
|
-
import { useFps as
|
|
36
|
+
import { useFps as Ke } from "./hooks/useFps/useFps.mjs";
|
|
37
37
|
import { useFullscreen as Fe } from "./hooks/useFullscreen/useFullscreen.mjs";
|
|
38
38
|
import { mapGamepadToXbox360Controller as We, useGamepad as Ue } from "./hooks/useGamepad/useGamepad.mjs";
|
|
39
39
|
import { useGeolocation as He } from "./hooks/useGeolocation/useGeolocation.mjs";
|
|
@@ -44,7 +44,7 @@ import { useIdle as $e } from "./hooks/useIdle/useIdle.mjs";
|
|
|
44
44
|
import { useImage as oo } from "./hooks/useImage/useImage.mjs";
|
|
45
45
|
import { useInfiniteScroll as to } from "./hooks/useInfiniteScroll/useInfiniteScroll.mjs";
|
|
46
46
|
import { useIntersectionObserver as mo } from "./hooks/useIntersectionObserver/useIntersectionObserver.mjs";
|
|
47
|
-
import { useInterval as
|
|
47
|
+
import { useInterval as uo } from "./hooks/useInterval/useInterval.mjs";
|
|
48
48
|
import { useIsFirstRender as xo } from "./hooks/useIsFirstRender/useIsFirstRender.mjs";
|
|
49
49
|
import { useIsomorphicLayoutEffect as ao } from "./hooks/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.mjs";
|
|
50
50
|
import { useKeyboard as lo } from "./hooks/useKeyboard/useKeyboard.mjs";
|
|
@@ -52,13 +52,13 @@ import { useKeyPress as So } from "./hooks/useKeyPress/useKeyPress.mjs";
|
|
|
52
52
|
import { useKeyPressEvent as go } from "./hooks/useKeyPressEvent/useKeyPressEvent.mjs";
|
|
53
53
|
import { useKeysPressed as Po } from "./hooks/useKeysPressed/useKeysPressed.mjs";
|
|
54
54
|
import { useLastChanged as Io } from "./hooks/useLastChanged/useLastChanged.mjs";
|
|
55
|
-
import { useLatest as
|
|
55
|
+
import { useLatest as Oo } from "./hooks/useLatest/useLatest.mjs";
|
|
56
56
|
import { useLess as Ao } from "./hooks/useLess/useLess.mjs";
|
|
57
57
|
import { useList as vo } from "./hooks/useList/useList.mjs";
|
|
58
58
|
import { useLocalStorage as Do } from "./hooks/useLocalStorage/useLocalStorage.mjs";
|
|
59
59
|
import { useLockCallback as No } from "./hooks/useLockCallback/useLockCallback.mjs";
|
|
60
60
|
import { useLogger as Lo } from "./hooks/useLogger/useLogger.mjs";
|
|
61
|
-
import { useLongPress as
|
|
61
|
+
import { useLongPress as ho } from "./hooks/useLongPress/useLongPress.mjs";
|
|
62
62
|
import { useMap as Vo } from "./hooks/useMap/useMap.mjs";
|
|
63
63
|
import { useMeasure as wo } from "./hooks/useMeasure/useMeasure.mjs";
|
|
64
64
|
import { useMediaQuery as Uo } from "./hooks/useMediaQuery/useMediaQuery.mjs";
|
|
@@ -70,20 +70,20 @@ import { useMutationObserver as Zo } from "./hooks/useMutationObserver/useMutati
|
|
|
70
70
|
import { getConnection as er, useNetwork as or } from "./hooks/useNetwork/useNetwork.mjs";
|
|
71
71
|
import { useOffsetPagination as tr } from "./hooks/useOffsetPagination/useOffsetPagination.mjs";
|
|
72
72
|
import { useOnce as mr } from "./hooks/useOnce/useOnce.mjs";
|
|
73
|
-
import { useOnline as
|
|
73
|
+
import { useOnline as ur } from "./hooks/useOnline/useOnline.mjs";
|
|
74
74
|
import { getOperatingSystem as xr, useOperatingSystem as ir } from "./hooks/useOperatingSystem/useOperatingSystem.mjs";
|
|
75
75
|
import { useOptimistic as nr } from "./hooks/useOptimistic/useOptimistic.mjs";
|
|
76
76
|
import { useOrientation as cr } from "./hooks/useOrientation/useOrientation.mjs";
|
|
77
77
|
import { useOtpCredential as Tr } from "./hooks/useOtpCredential/useOtpCredential.mjs";
|
|
78
|
-
import { usePageLeave as
|
|
78
|
+
import { usePageLeave as dr } from "./hooks/usePageLeave/usePageLeave.mjs";
|
|
79
79
|
import { Paint as Pr, Pointer as Cr, usePaint as Ir } from "./hooks/usePaint/usePaint.mjs";
|
|
80
|
-
import { useParallax as
|
|
80
|
+
import { useParallax as Or } from "./hooks/useParallax/useParallax.mjs";
|
|
81
81
|
import { usePerformanceObserver as Ar } from "./hooks/usePerformanceObserver/usePerformanceObserver.mjs";
|
|
82
82
|
import { usePermission as vr } from "./hooks/usePermission/usePermission.mjs";
|
|
83
83
|
import { usePointerLock as Dr } from "./hooks/usePointerLock/usePointerLock.mjs";
|
|
84
84
|
import { usePostMessage as Nr } from "./hooks/usePostMessage/usePostMessage.mjs";
|
|
85
85
|
import { usePreferredColorScheme as Lr } from "./hooks/usePreferredColorScheme/usePreferredColorScheme.mjs";
|
|
86
|
-
import { usePreferredContrast as
|
|
86
|
+
import { usePreferredContrast as hr } from "./hooks/usePreferredContrast/usePreferredContrast.mjs";
|
|
87
87
|
import { usePreferredDark as Vr } from "./hooks/usePreferredDark/usePreferredDark.mjs";
|
|
88
88
|
import { usePreferredLanguages as wr } from "./hooks/usePreferredLanguages/usePreferredLanguages.mjs";
|
|
89
89
|
import { usePreferredReducedMotion as Ur } from "./hooks/usePreferredReducedMotion/usePreferredReducedMotion.mjs";
|
|
@@ -95,93 +95,95 @@ import { useRafValue as Zr } from "./hooks/useRafValue/useRafValue.mjs";
|
|
|
95
95
|
import { useRefState as et } from "./hooks/useRefState/useRefState.mjs";
|
|
96
96
|
import { useRenderCount as rt } from "./hooks/useRenderCount/useRenderCount.mjs";
|
|
97
97
|
import { useRenderInfo as st } from "./hooks/useRenderInfo/useRenderInfo.mjs";
|
|
98
|
-
import { useRerender as
|
|
98
|
+
import { useRerender as pt } from "./hooks/useRerender/useRerender.mjs";
|
|
99
99
|
import { useResizeObserver as ft } from "./hooks/useResizeObserver/useResizeObserver.mjs";
|
|
100
100
|
import { useScreenOrientation as it } from "./hooks/useScreenOrientation/useScreenOrientation.mjs";
|
|
101
101
|
import { SCRIPT_STATUS_ATTRIBUTE_NAME as nt, useScript as lt } from "./hooks/useScript/useScript.mjs";
|
|
102
102
|
import { useScroll as St } from "./hooks/useScroll/useScroll.mjs";
|
|
103
|
-
import { useScrollIntoView as
|
|
103
|
+
import { useScrollIntoView as gt } from "./hooks/useScrollIntoView/useScrollIntoView.mjs";
|
|
104
104
|
import { useScrollTo as Et } from "./hooks/useScrollTo/useScrollTo.mjs";
|
|
105
105
|
import { useSessionStorage as Ct } from "./hooks/useSessionStorage/useSessionStorage.mjs";
|
|
106
|
-
import { useSet as
|
|
106
|
+
import { useSet as Rt } from "./hooks/useSet/useSet.mjs";
|
|
107
107
|
import { useShare as yt } from "./hooks/useShare/useShare.mjs";
|
|
108
|
-
import {
|
|
109
|
-
import {
|
|
110
|
-
import {
|
|
111
|
-
import {
|
|
112
|
-
import {
|
|
113
|
-
import {
|
|
114
|
-
import {
|
|
115
|
-
import {
|
|
116
|
-
import {
|
|
117
|
-
import {
|
|
118
|
-
import {
|
|
119
|
-
import {
|
|
120
|
-
import {
|
|
121
|
-
import {
|
|
122
|
-
import {
|
|
123
|
-
import {
|
|
124
|
-
import {
|
|
125
|
-
import {
|
|
126
|
-
import {
|
|
127
|
-
import {
|
|
128
|
-
import {
|
|
129
|
-
import {
|
|
130
|
-
import {
|
|
131
|
-
import {
|
|
132
|
-
import {
|
|
133
|
-
import {
|
|
134
|
-
import {
|
|
135
|
-
import {
|
|
108
|
+
import { getSpeechRecognition as kt, useSpeechRecognition as vt } from "./hooks/useSpeechRecognition/useSpeechRecognition.mjs";
|
|
109
|
+
import { useStateHistory as Dt } from "./hooks/useStateHistory/useStateHistory.mjs";
|
|
110
|
+
import { useStep as Nt } from "./hooks/useStep/useStep.mjs";
|
|
111
|
+
import { useSticky as Lt } from "./hooks/useSticky/useSticky.mjs";
|
|
112
|
+
import { useStopwatch as ht } from "./hooks/useStopwatch/useStopwatch.mjs";
|
|
113
|
+
import { STORAGE_EVENT as Vt, dispatchStorageEvent as Ft, useStorage as wt } from "./hooks/useStorage/useStorage.mjs";
|
|
114
|
+
import { useTextDirection as Ut } from "./hooks/useTextDirection/useTextDirection.mjs";
|
|
115
|
+
import { getRangesSelection as Ht, useTextSelection as zt } from "./hooks/useTextSelection/useTextSelection.mjs";
|
|
116
|
+
import { useThrottleCallback as Xt } from "./hooks/useThrottleCallback/useThrottleCallback.mjs";
|
|
117
|
+
import { useThrottleValue as qt } from "./hooks/useThrottleValue/useThrottleValue.mjs";
|
|
118
|
+
import { useTime as Yt } from "./hooks/useTime/useTime.mjs";
|
|
119
|
+
import { useTimeout as $t } from "./hooks/useTimeout/useTimeout.mjs";
|
|
120
|
+
import { getTimeFromSeconds as os, useTimer as rs } from "./hooks/useTimer/useTimer.mjs";
|
|
121
|
+
import { useToggle as ss } from "./hooks/useToggle/useToggle.mjs";
|
|
122
|
+
import { useUnmount as ps } from "./hooks/useUnmount/useUnmount.mjs";
|
|
123
|
+
import { useVibrate as fs } from "./hooks/useVibrate/useVibrate.mjs";
|
|
124
|
+
import { useWebSocket as is } from "./hooks/useWebSocket/useWebSocket.mjs";
|
|
125
|
+
import { useWindowEvent as ns } from "./hooks/useWindowEvent/useWindowEvent.mjs";
|
|
126
|
+
import { useWindowFocus as cs } from "./hooks/useWindowFocus/useWindowFocus.mjs";
|
|
127
|
+
import { scrollTo as Ts, useWindowScroll as gs } from "./hooks/useWindowScroll/useWindowScroll.mjs";
|
|
128
|
+
import { useWindowSize as Es } from "./hooks/useWindowSize/useWindowSize.mjs";
|
|
129
|
+
import { useWizard as Cs } from "./hooks/useWizard/useWizard.mjs";
|
|
130
|
+
import { copy as Rs, legacyCopyToClipboard as Os } from "./utils/helpers/copy.mjs";
|
|
131
|
+
import { debounce as As } from "./utils/helpers/debounce.mjs";
|
|
132
|
+
import { getDate as vs } from "./utils/helpers/getDate.mjs";
|
|
133
|
+
import { getElement as Ds, target as Ms, targetSymbol as Ns } from "./utils/helpers/getElement.mjs";
|
|
134
|
+
import { getRetry as Ls } from "./utils/helpers/getRetry.mjs";
|
|
135
|
+
import { isTarget as hs } from "./utils/helpers/isTarget.mjs";
|
|
136
|
+
import { throttle as Vs } from "./utils/helpers/throttle.mjs";
|
|
136
137
|
export {
|
|
137
138
|
n as BREAKPOINTS_ANT_DESIGN,
|
|
138
139
|
l as BREAKPOINTS_BOOTSTRAP_V5,
|
|
139
140
|
c as BREAKPOINTS_MANTINE,
|
|
140
141
|
S as BREAKPOINTS_MASTER_CSS,
|
|
141
142
|
T as BREAKPOINTS_MATERIAL_UI,
|
|
142
|
-
|
|
143
|
-
|
|
143
|
+
g as BREAKPOINTS_PRIME_FLEX,
|
|
144
|
+
d as BREAKPOINTS_QUASAR_V2,
|
|
144
145
|
E as BREAKPOINTS_SEMANTIC,
|
|
145
146
|
P as BREAKPOINTS_TAILWIND,
|
|
146
147
|
M as COOKIE_EVENT,
|
|
147
148
|
Pr as Paint,
|
|
148
149
|
Cr as Pointer,
|
|
149
150
|
nt as SCRIPT_STATUS_ATTRIBUTE_NAME,
|
|
150
|
-
|
|
151
|
+
Vt as STORAGE_EVENT,
|
|
151
152
|
W as clearCookies,
|
|
152
|
-
|
|
153
|
-
|
|
153
|
+
Rs as copy,
|
|
154
|
+
As as debounce,
|
|
154
155
|
N as dispatchCookieEvent,
|
|
155
|
-
|
|
156
|
+
Ft as dispatchStorageEvent,
|
|
156
157
|
er as getConnection,
|
|
157
158
|
b as getCookie,
|
|
158
159
|
L as getCookies,
|
|
159
|
-
|
|
160
|
-
|
|
160
|
+
vs as getDate,
|
|
161
|
+
Ds as getElement,
|
|
161
162
|
xr as getOperatingSystem,
|
|
162
163
|
U as getParsedCookies,
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
164
|
+
Ht as getRangesSelection,
|
|
165
|
+
Ls as getRetry,
|
|
166
|
+
kt as getSpeechRecognition,
|
|
167
|
+
os as getTimeFromSeconds,
|
|
166
168
|
je as isHotkeyMatch,
|
|
167
|
-
|
|
168
|
-
|
|
169
|
+
hs as isTarget,
|
|
170
|
+
Os as legacyCopyToClipboard,
|
|
169
171
|
We as mapGamepadToXbox360Controller,
|
|
170
172
|
B as removeCookie,
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
173
|
+
h as removeCookieItem,
|
|
174
|
+
Ts as scrollTo,
|
|
175
|
+
K as setCookie,
|
|
174
176
|
V as setCookieItem,
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
177
|
+
Ms as target,
|
|
178
|
+
Ns as targetSymbol,
|
|
179
|
+
Vs as throttle,
|
|
178
180
|
r as useActiveElement,
|
|
179
181
|
s as useAsync,
|
|
180
|
-
|
|
182
|
+
p as useBattery,
|
|
181
183
|
f as useBluetooth,
|
|
182
184
|
i as useBoolean,
|
|
183
185
|
C as useBreakpoints,
|
|
184
|
-
|
|
186
|
+
R as useBrowserLanguage,
|
|
185
187
|
y as useClickOutside,
|
|
186
188
|
k as useClipboard,
|
|
187
189
|
_ as useConst,
|
|
@@ -195,22 +197,22 @@ export {
|
|
|
195
197
|
oe as useDefault,
|
|
196
198
|
te as useDeviceMotion,
|
|
197
199
|
me as useDeviceOrientation,
|
|
198
|
-
|
|
200
|
+
ue as useDevicePixelRatio,
|
|
199
201
|
xe as useDidUpdate,
|
|
200
202
|
ae as useDisclosure,
|
|
201
203
|
le as useDisplayMedia,
|
|
202
204
|
Se as useDocumentEvent,
|
|
203
|
-
|
|
205
|
+
ge as useDocumentTitle,
|
|
204
206
|
Ee as useDocumentVisibility,
|
|
205
207
|
Ce as useElementSize,
|
|
206
|
-
|
|
208
|
+
Re as useEvent,
|
|
207
209
|
ye as useEventListener,
|
|
208
210
|
ke as useEyeDropper,
|
|
209
211
|
_e as useFavicon,
|
|
210
212
|
Me as useField,
|
|
211
213
|
be as useFileDialog,
|
|
212
214
|
Be as useFocus,
|
|
213
|
-
|
|
215
|
+
Ke as useFps,
|
|
214
216
|
Fe as useFullscreen,
|
|
215
217
|
Ue as useGamepad,
|
|
216
218
|
He as useGeolocation,
|
|
@@ -221,7 +223,7 @@ export {
|
|
|
221
223
|
oo as useImage,
|
|
222
224
|
to as useInfiniteScroll,
|
|
223
225
|
mo as useIntersectionObserver,
|
|
224
|
-
|
|
226
|
+
uo as useInterval,
|
|
225
227
|
xo as useIsFirstRender,
|
|
226
228
|
ao as useIsomorphicLayoutEffect,
|
|
227
229
|
So as useKeyPress,
|
|
@@ -229,13 +231,13 @@ export {
|
|
|
229
231
|
lo as useKeyboard,
|
|
230
232
|
Po as useKeysPressed,
|
|
231
233
|
Io as useLastChanged,
|
|
232
|
-
|
|
234
|
+
Oo as useLatest,
|
|
233
235
|
Ao as useLess,
|
|
234
236
|
vo as useList,
|
|
235
237
|
Do as useLocalStorage,
|
|
236
238
|
No as useLockCallback,
|
|
237
239
|
Lo as useLogger,
|
|
238
|
-
|
|
240
|
+
ho as useLongPress,
|
|
239
241
|
Vo as useMap,
|
|
240
242
|
wo as useMeasure,
|
|
241
243
|
Uo as useMediaQuery,
|
|
@@ -247,20 +249,20 @@ export {
|
|
|
247
249
|
or as useNetwork,
|
|
248
250
|
tr as useOffsetPagination,
|
|
249
251
|
mr as useOnce,
|
|
250
|
-
|
|
252
|
+
ur as useOnline,
|
|
251
253
|
ir as useOperatingSystem,
|
|
252
254
|
nr as useOptimistic,
|
|
253
255
|
cr as useOrientation,
|
|
254
256
|
Tr as useOtpCredential,
|
|
255
|
-
|
|
257
|
+
dr as usePageLeave,
|
|
256
258
|
Ir as usePaint,
|
|
257
|
-
|
|
259
|
+
Or as useParallax,
|
|
258
260
|
Ar as usePerformanceObserver,
|
|
259
261
|
vr as usePermission,
|
|
260
262
|
Dr as usePointerLock,
|
|
261
263
|
Nr as usePostMessage,
|
|
262
264
|
Lr as usePreferredColorScheme,
|
|
263
|
-
|
|
265
|
+
hr as usePreferredContrast,
|
|
264
266
|
Vr as usePreferredDark,
|
|
265
267
|
wr as usePreferredLanguages,
|
|
266
268
|
Ur as usePreferredReducedMotion,
|
|
@@ -272,36 +274,37 @@ export {
|
|
|
272
274
|
et as useRefState,
|
|
273
275
|
rt as useRenderCount,
|
|
274
276
|
st as useRenderInfo,
|
|
275
|
-
|
|
277
|
+
pt as useRerender,
|
|
276
278
|
ft as useResizeObserver,
|
|
277
279
|
it as useScreenOrientation,
|
|
278
280
|
lt as useScript,
|
|
279
281
|
St as useScroll,
|
|
280
|
-
|
|
282
|
+
gt as useScrollIntoView,
|
|
281
283
|
Et as useScrollTo,
|
|
282
284
|
Ct as useSessionStorage,
|
|
283
|
-
|
|
285
|
+
Rt as useSet,
|
|
284
286
|
yt as useShare,
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
ht as
|
|
290
|
-
|
|
291
|
-
Ut as
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
$t as
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
cs as
|
|
304
|
-
|
|
305
|
-
|
|
287
|
+
vt as useSpeechRecognition,
|
|
288
|
+
Dt as useStateHistory,
|
|
289
|
+
Nt as useStep,
|
|
290
|
+
Lt as useSticky,
|
|
291
|
+
ht as useStopwatch,
|
|
292
|
+
wt as useStorage,
|
|
293
|
+
Ut as useTextDirection,
|
|
294
|
+
zt as useTextSelection,
|
|
295
|
+
Xt as useThrottleCallback,
|
|
296
|
+
qt as useThrottleValue,
|
|
297
|
+
Yt as useTime,
|
|
298
|
+
$t as useTimeout,
|
|
299
|
+
rs as useTimer,
|
|
300
|
+
ss as useToggle,
|
|
301
|
+
ps as useUnmount,
|
|
302
|
+
fs as useVibrate,
|
|
303
|
+
is as useWebSocket,
|
|
304
|
+
ns as useWindowEvent,
|
|
305
|
+
cs as useWindowFocus,
|
|
306
|
+
gs as useWindowScroll,
|
|
307
|
+
Es as useWindowSize,
|
|
308
|
+
Cs as useWizard
|
|
306
309
|
};
|
|
307
310
|
//# sourceMappingURL=index.mjs.map
|
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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -105,6 +105,7 @@ export * from './useScrollTo/useScrollTo';
|
|
|
105
105
|
export * from './useSessionStorage/useSessionStorage';
|
|
106
106
|
export * from './useSet/useSet';
|
|
107
107
|
export * from './useShare/useShare';
|
|
108
|
+
export * from './useSpeechRecognition/useSpeechRecognition';
|
|
108
109
|
export * from './useStateHistory/useStateHistory';
|
|
109
110
|
export * from './useStep/useStep';
|
|
110
111
|
export * from './useSticky/useSticky';
|
|
@@ -23,6 +23,8 @@ export interface UseClickOutside {
|
|
|
23
23
|
* @returns {(node: Target) => void} A React ref to attach to the target element
|
|
24
24
|
*
|
|
25
25
|
* @example
|
|
26
|
-
* const ref = useClickOutside
|
|
26
|
+
* const ref = `useClickOutside`<HTMLDivElement>(() => console.log('click outside'));
|
|
27
|
+
*
|
|
28
|
+
* @see {@link https://siberiacancode.github.io/reactuse/functions/hooks/useClickOutside.html}
|
|
27
29
|
*/
|
|
28
30
|
export declare const useClickOutside: UseClickOutside;
|
|
@@ -5,11 +5,11 @@ export type UseEventListenerOptions = boolean | AddEventListenerOptions;
|
|
|
5
5
|
/** The use event listener return type */
|
|
6
6
|
export type UseEventListenerReturn<Target extends Element> = StateRef<Target>;
|
|
7
7
|
export interface UseEventListener {
|
|
8
|
-
<Event extends keyof WindowEventMap = keyof WindowEventMap>(target:
|
|
9
|
-
<Event extends keyof DocumentEventMap = keyof DocumentEventMap>(target:
|
|
10
|
-
<Event extends keyof HTMLElementEventMap = keyof HTMLElementEventMap>(target: HookTarget, event: Event
|
|
11
|
-
<Target extends Element, Event extends keyof HTMLElementEventMap = keyof HTMLElementEventMap>(event: Event
|
|
12
|
-
<Target extends Element, Event extends keyof MediaQueryListEventMap = keyof MediaQueryListEventMap>(event: Event
|
|
8
|
+
<Event extends keyof WindowEventMap = keyof WindowEventMap>(target: HookTarget, event: Event, listener: (this: Window, event: WindowEventMap[Event]) => void, options?: UseEventListenerOptions): void;
|
|
9
|
+
<Event extends keyof DocumentEventMap = keyof DocumentEventMap>(target: HookTarget, event: Event, listener: (this: Document, event: DocumentEventMap[Event]) => void, options?: UseEventListenerOptions): void;
|
|
10
|
+
<Event extends keyof HTMLElementEventMap = keyof HTMLElementEventMap>(target: HookTarget, event: Event, listener: (this: Element, event: HTMLElementEventMap[Event]) => void, options?: UseEventListenerOptions): void;
|
|
11
|
+
<Target extends Element, Event extends keyof HTMLElementEventMap = keyof HTMLElementEventMap>(event: Event, listener: (this: Target, event: HTMLElementEventMap[Event]) => void, options?: UseEventListenerOptions, target?: never): UseEventListenerReturn<Target>;
|
|
12
|
+
<Target extends Element, Event extends keyof MediaQueryListEventMap = keyof MediaQueryListEventMap>(event: Event, listener: (this: Target, event: MediaQueryListEventMap[Event]) => void, options?: UseEventListenerOptions, target?: never): UseEventListenerReturn<Target>;
|
|
13
13
|
}
|
|
14
14
|
/**
|
|
15
15
|
* @name useEventListener
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/** The use speech recognition hook options type */
|
|
2
|
+
interface UseSpeechRecognitionOptions {
|
|
3
|
+
/** If true, recognition continues even after pauses in speech. Default is false */
|
|
4
|
+
continuous?: SpeechRecognition['continuous'];
|
|
5
|
+
/** A list of grammar rules */
|
|
6
|
+
grammars?: SpeechRecognition['grammars'];
|
|
7
|
+
/** If true, interim (non-final) results are provided as the user speaks */
|
|
8
|
+
interimResults?: SpeechRecognition['interimResults'];
|
|
9
|
+
/** The language in which recognition should occur. Must be a valid BCP 47 language tag (e.g., "en-US", "ru-RU") */
|
|
10
|
+
language?: SpeechRecognition['lang'];
|
|
11
|
+
/** The maximum number of alternative transcripts returned for a given recognition result. Must be a positive integer */
|
|
12
|
+
maxAlternatives?: SpeechRecognition['maxAlternatives'];
|
|
13
|
+
/** Callback invoked when speech recognition ends */
|
|
14
|
+
onEnd?: () => void;
|
|
15
|
+
/** Callback invoked when an error occurs during recognition */
|
|
16
|
+
onError?: (error: SpeechRecognitionErrorEvent) => void;
|
|
17
|
+
/** Callback invoked when recognition produces a result */
|
|
18
|
+
onResult?: (event: SpeechRecognitionEvent) => void;
|
|
19
|
+
/** Callback invoked when speech recognition starts */
|
|
20
|
+
onStart?: () => void;
|
|
21
|
+
}
|
|
22
|
+
/** The return type of the useSpeechRecognition hook. */
|
|
23
|
+
interface UseSpeechRecognitionReturn {
|
|
24
|
+
/** The error state */
|
|
25
|
+
error: SpeechRecognitionErrorEvent | null;
|
|
26
|
+
/** The final transcript */
|
|
27
|
+
final: boolean;
|
|
28
|
+
/** Whether the hook is currently listening for speech */
|
|
29
|
+
listening: boolean;
|
|
30
|
+
/** The speech recognition instance */
|
|
31
|
+
recognition: SpeechRecognition;
|
|
32
|
+
/** Whether the current browser supports the Web Speech API */
|
|
33
|
+
supported: boolean;
|
|
34
|
+
/** The current transcript */
|
|
35
|
+
transcript: string;
|
|
36
|
+
/** Begins speech recognition */
|
|
37
|
+
start: () => void;
|
|
38
|
+
/** Ends speech recognition, finalizing results */
|
|
39
|
+
stop: () => void;
|
|
40
|
+
/** Toggles the listening state */
|
|
41
|
+
toggle: (value?: boolean) => void;
|
|
42
|
+
}
|
|
43
|
+
export declare const getSpeechRecognition: () => {
|
|
44
|
+
new (): SpeechRecognition;
|
|
45
|
+
prototype: SpeechRecognition;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* @name useSpeechRecognition
|
|
49
|
+
* @description - Hook that provides a streamlined interface for incorporating speech-to-text functionality
|
|
50
|
+
* @category Sensors
|
|
51
|
+
*
|
|
52
|
+
* @browserapi window.SpeechRecognition https://developer.mozilla.org/en-US/docs/Web/API/SpeechRecognition
|
|
53
|
+
*
|
|
54
|
+
* @param {boolean} [options.continuous=false] Whether recognition should continue after pauses
|
|
55
|
+
* @param {boolean} [options.interimResults=false] Whether interim results should be provided
|
|
56
|
+
* @param {string} [options.language="en-US"] The language for recognition, as a valid BCP 47 tag
|
|
57
|
+
* @param {number} [options.maxAlternatives=1] The maximum number of alternative transcripts to return
|
|
58
|
+
* @param {SpeechGrammarList} [options.grammars] A list of grammar rules
|
|
59
|
+
* @param {() => void} [options.onStart] Callback invoked when speech recognition starts
|
|
60
|
+
* @param {() => void} [options.onEnd] Callback invoked when speech recognition ends
|
|
61
|
+
* @param {(error: SpeechRecognitionErrorEvent) => void} [options.onError] Callback invoked when an error occurs during recognition
|
|
62
|
+
* @param {(event: SpeechRecognitionEvent) => void} [options.onResult] Callback invoked when recognition produces a result
|
|
63
|
+
* @returns {UseSpeechRecognitionReturn} An object containing the speech recognition functionality
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* const { supported, value, recognition, listening, error, start, stop, toggle } = useSpeechRecognition();
|
|
67
|
+
*/
|
|
68
|
+
export declare const useSpeechRecognition: (options?: UseSpeechRecognitionOptions) => UseSpeechRecognitionReturn;
|
|
69
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@siberiacancode/reactuse",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.114",
|
|
4
4
|
"description": "The ultimate collection of react hooks",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "SIBERIA CAN CODE 🧊",
|
|
@@ -67,6 +67,7 @@
|
|
|
67
67
|
"@siberiacancode/vitest": "^2.1.0",
|
|
68
68
|
"@testing-library/dom": "^10.4.0",
|
|
69
69
|
"@testing-library/react": "^16.2.0",
|
|
70
|
+
"@types/dom-speech-recognition": "^0.0.4",
|
|
70
71
|
"@types/react": "^18.3.18",
|
|
71
72
|
"@types/react-dom": "^18.3.5",
|
|
72
73
|
"@types/web-bluetooth": "^0.0.21",
|