@siberiacancode/reactuse 0.0.115 → 0.0.117
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/hooks/useActiveElement/useActiveElement.cjs.map +1 -1
- package/dist/cjs/hooks/useDidUpdate/useDidUpdate.cjs +1 -1
- package/dist/cjs/hooks/useDidUpdate/useDidUpdate.cjs.map +1 -1
- package/dist/cjs/hooks/useDoubleClick/useDoubleClick.cjs.map +1 -1
- package/dist/cjs/hooks/useFul/useFul.cjs +2 -0
- package/dist/cjs/hooks/useFul/useFul.cjs.map +1 -0
- package/dist/cjs/hooks/useIntersectionObserver/useIntersectionObserver.cjs.map +1 -1
- package/dist/cjs/hooks/useSpeechSynthesis/useSpeechSynthesis.cjs +2 -0
- package/dist/cjs/hooks/useSpeechSynthesis/useSpeechSynthesis.cjs.map +1 -0
- package/dist/cjs/hooks/useWakeLock/useWakeLock.cjs +2 -0
- package/dist/cjs/hooks/useWakeLock/useWakeLock.cjs.map +1 -0
- package/dist/cjs/hooks/useWindowFocus/useWindowFocus.cjs.map +1 -1
- package/dist/cjs/index.cjs +1 -1
- package/dist/esm/hooks/useActiveElement/useActiveElement.mjs.map +1 -1
- package/dist/esm/hooks/useDidUpdate/useDidUpdate.mjs +14 -13
- package/dist/esm/hooks/useDidUpdate/useDidUpdate.mjs.map +1 -1
- package/dist/esm/hooks/useDoubleClick/useDoubleClick.mjs.map +1 -1
- package/dist/esm/hooks/useFul/useFul.mjs +8 -0
- package/dist/esm/hooks/useFul/useFul.mjs.map +1 -0
- package/dist/esm/hooks/useIntersectionObserver/useIntersectionObserver.mjs.map +1 -1
- package/dist/esm/hooks/useSpeechSynthesis/useSpeechSynthesis.mjs +56 -0
- package/dist/esm/hooks/useSpeechSynthesis/useSpeechSynthesis.mjs.map +1 -0
- package/dist/esm/hooks/useWakeLock/useWakeLock.mjs +24 -0
- package/dist/esm/hooks/useWakeLock/useWakeLock.mjs.map +1 -0
- package/dist/esm/hooks/useWindowFocus/useWindowFocus.mjs.map +1 -1
- package/dist/esm/index.mjs +231 -225
- package/dist/esm/index.mjs.map +1 -1
- package/dist/types/hooks/index.d.ts +3 -0
- package/dist/types/hooks/useActiveElement/useActiveElement.d.ts +2 -0
- package/dist/types/hooks/useDidUpdate/useDidUpdate.d.ts +1 -1
- package/dist/types/hooks/useDoubleClick/useDoubleClick.d.ts +3 -4
- package/dist/types/hooks/useIntersectionObserver/useIntersectionObserver.d.ts +2 -0
- package/dist/types/hooks/useSpeechSynthesis/useSpeechSynthesis.d.ts +59 -0
- package/dist/types/hooks/useWakeLock/useWakeLock.d.ts +32 -0
- package/dist/types/hooks/useWindowFocus/useWindowFocus.d.ts +2 -0
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useActiveElement.cjs","sources":["../../../../src/hooks/useActiveElement/useActiveElement.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\n/**\n * @name useActiveElement\n * @description - Hook that returns the active element\n * @category Elements\n *\n * @returns {ActiveElement | null} The active element\n *\n * @example\n * const activeElement = useActiveElement();\n */\nexport const useActiveElement = <ActiveElement extends HTMLElement>() => {\n const [activeElement, setActiveElement] = useState<ActiveElement | null>(null);\n\n useEffect(() => {\n const onActiveElementChange = () =>\n setActiveElement(document?.activeElement as ActiveElement | null);\n\n window.addEventListener('focus', onActiveElementChange, true);\n window.addEventListener('blur', onActiveElementChange, true);\n\n return () => {\n window.removeEventListener('focus', onActiveElementChange, true);\n window.removeEventListener('blur', onActiveElementChange, true);\n };\n });\n\n useEffect(() => {\n const observer = new MutationObserver((mutations) => {\n mutations\n .filter((mutation) => mutation.removedNodes.length)\n .map((mutation) => Array.from(mutation.removedNodes))\n .flat()\n .forEach((node) => {\n setActiveElement((prevActiveElement) => {\n if (node === prevActiveElement) return document.activeElement as ActiveElement | null;\n return prevActiveElement;\n });\n });\n });\n\n observer.observe(document, {\n childList: true,\n subtree: true\n });\n\n return () => {\n observer.disconnect();\n };\n }, []);\n\n return activeElement;\n};\n"],"names":["useActiveElement","activeElement","setActiveElement","useState","useEffect","onActiveElementChange","observer","mutations","mutation","node","prevActiveElement"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useActiveElement.cjs","sources":["../../../../src/hooks/useActiveElement/useActiveElement.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\n/**\n * @name useActiveElement\n * @description - Hook that returns the active element\n * @category Elements\n *\n * @returns {ActiveElement | null} The active element\n *\n * @example\n * const activeElement = useActiveElement();\n *\n * @see {@link https://siberiacancode.github.io/reactuse/functions/hooks/useActiveElement.html}\n */\nexport const useActiveElement = <ActiveElement extends HTMLElement>() => {\n const [activeElement, setActiveElement] = useState<ActiveElement | null>(null);\n\n useEffect(() => {\n const onActiveElementChange = () =>\n setActiveElement(document?.activeElement as ActiveElement | null);\n\n window.addEventListener('focus', onActiveElementChange, true);\n window.addEventListener('blur', onActiveElementChange, true);\n\n return () => {\n window.removeEventListener('focus', onActiveElementChange, true);\n window.removeEventListener('blur', onActiveElementChange, true);\n };\n });\n\n useEffect(() => {\n const observer = new MutationObserver((mutations) => {\n mutations\n .filter((mutation) => mutation.removedNodes.length)\n .map((mutation) => Array.from(mutation.removedNodes))\n .flat()\n .forEach((node) => {\n setActiveElement((prevActiveElement) => {\n if (node === prevActiveElement) return document.activeElement as ActiveElement | null;\n return prevActiveElement;\n });\n });\n });\n\n observer.observe(document, {\n childList: true,\n subtree: true\n });\n\n return () => {\n observer.disconnect();\n };\n }, []);\n\n return activeElement;\n};\n"],"names":["useActiveElement","activeElement","setActiveElement","useState","useEffect","onActiveElementChange","observer","mutations","mutation","node","prevActiveElement"],"mappings":"yGAcaA,EAAmB,IAAyC,CACvE,KAAM,CAACC,EAAeC,CAAgB,EAAIC,EAAAA,SAA+B,IAAI,EAE7EC,OAAAA,EAAAA,UAAU,IAAM,CACd,MAAMC,EAAwB,IAC5BH,EAAiB,+BAAU,aAAqC,EAE3D,cAAA,iBAAiB,QAASG,EAAuB,EAAI,EACrD,OAAA,iBAAiB,OAAQA,EAAuB,EAAI,EAEpD,IAAM,CACJ,OAAA,oBAAoB,QAASA,EAAuB,EAAI,EACxD,OAAA,oBAAoB,OAAQA,EAAuB,EAAI,CAChE,CAAA,CACD,EAEDD,EAAAA,UAAU,IAAM,CACd,MAAME,EAAW,IAAI,iBAAkBC,GAAc,CAEhDA,EAAA,OAAQC,GAAaA,EAAS,aAAa,MAAM,EACjD,IAAKA,GAAa,MAAM,KAAKA,EAAS,YAAY,CAAC,EACnD,OACA,QAASC,GAAS,CACjBP,EAAkBQ,GACZD,IAASC,EAA0B,SAAS,cACzCA,CACR,CAAA,CACF,CAAA,CACJ,EAED,OAAAJ,EAAS,QAAQ,SAAU,CACzB,UAAW,GACX,QAAS,EAAA,CACV,EAEM,IAAM,CACXA,EAAS,WAAW,CACtB,CACF,EAAG,EAAE,EAEEL,CACT"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("react"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("react"),t=require("../useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.cjs"),s=(r,u)=>{const e=o.useRef(!1);t.useIsomorphicLayoutEffect(()=>()=>{e.current=!1},[]),t.useIsomorphicLayoutEffect(()=>{if(e.current)return r();e.current=!0},u)};exports.useDidUpdate=s;
|
|
2
2
|
//# sourceMappingURL=useDidUpdate.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDidUpdate.cjs","sources":["../../../../src/hooks/useDidUpdate/useDidUpdate.ts"],"sourcesContent":["import type { DependencyList, EffectCallback } from 'react';\n\nimport { useRef } from 'react';\n\nimport { useIsomorphicLayoutEffect } from '../useIsomorphicLayoutEffect/useIsomorphicLayoutEffect';\n\n/**\n * @name useDidUpdate\n * @description – Hook that triggers the effect callback on updates\n * @category Lifecycle\n *\n * @param {EffectCallback} effect The effect callback\n * @param {DependencyList} [deps] The dependencies list for the effect\n *\n * @example\n * useDidUpdate(() => console.log(\"effect runs on updates\"),
|
|
1
|
+
{"version":3,"file":"useDidUpdate.cjs","sources":["../../../../src/hooks/useDidUpdate/useDidUpdate.ts"],"sourcesContent":["import type { DependencyList, EffectCallback } from 'react';\r\n\r\nimport { useRef } from 'react';\r\n\r\nimport { useIsomorphicLayoutEffect } from '../useIsomorphicLayoutEffect/useIsomorphicLayoutEffect';\r\n\r\n/**\r\n * @name useDidUpdate\r\n * @description – Hook that triggers the effect callback on updates\r\n * @category Lifecycle\r\n *\r\n * @param {EffectCallback} effect The effect callback\r\n * @param {DependencyList} [deps] The dependencies list for the effect\r\n *\r\n * @example\r\n * useDidUpdate(() => console.log(\"effect runs on updates\"), deps);\r\n */\r\nexport const useDidUpdate = (effect: EffectCallback, deps?: DependencyList) => {\r\n const mounted = useRef(false);\r\n\r\n useIsomorphicLayoutEffect(\r\n () => () => {\r\n mounted.current = false;\r\n },\r\n []\r\n );\r\n\r\n useIsomorphicLayoutEffect(() => {\r\n if (mounted.current) {\r\n return effect();\r\n }\r\n\r\n mounted.current = true;\r\n return undefined;\r\n }, deps);\r\n};\r\n"],"names":["useDidUpdate","effect","deps","mounted","useRef","useIsomorphicLayoutEffect"],"mappings":"iLAiBaA,EAAe,CAACC,EAAwBC,IAA0B,CACvE,MAAAC,EAAUC,SAAO,EAAK,EAE5BC,EAAA,0BACE,IAAM,IAAM,CACVF,EAAQ,QAAU,EACpB,EACA,CAAA,CACF,EAEAE,EAAAA,0BAA0B,IAAM,CAC9B,GAAIF,EAAQ,QACV,OAAOF,EAAO,EAGhBE,EAAQ,QAAU,IAEjBD,CAAI,CACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDoubleClick.cjs","sources":["../../../../src/hooks/useDoubleClick/useDoubleClick.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 type DoubleClickEvents = MouseEvent | TouchEvent;\n\n// * The use double click options type */\nexport interface UseDoubleClickOptions {\n // * The threshold time in milliseconds between clicks\n threshold?: number;\n // * The callback function to be invoked on single click\n onSingleClick?: (event: DoubleClickEvents) => void;\n}\n\nexport interface UseDoubleClick {\n (\n target: HookTarget,\n callback: (event: DoubleClickEvents) => void,\n options?: UseDoubleClickOptions\n ): boolean;\n\n <Target extends Element>(\n callback: (event: DoubleClickEvents) => void,\n options?: UseDoubleClickOptions,\n target?: never\n ):
|
|
1
|
+
{"version":3,"file":"useDoubleClick.cjs","sources":["../../../../src/hooks/useDoubleClick/useDoubleClick.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 type DoubleClickEvents = MouseEvent | TouchEvent;\n\n// * The use double click options type */\nexport interface UseDoubleClickOptions {\n // * The threshold time in milliseconds between clicks\n threshold?: number;\n // * The callback function to be invoked on single click\n onSingleClick?: (event: DoubleClickEvents) => void;\n}\n\nexport interface UseDoubleClick {\n (\n target: HookTarget,\n callback: (event: DoubleClickEvents) => void,\n options?: UseDoubleClickOptions\n ): boolean;\n\n <Target extends Element>(\n callback: (event: DoubleClickEvents) => void,\n options?: UseDoubleClickOptions,\n target?: never\n ): StateRef<Target>;\n}\n\nconst DEFAULT_THRESHOLD_TIME = 300;\n\n/**\n * @name useDoubleClick\n * @description - Hook that defines the logic when double clicking an element\n * @category Sensors\n *\n * @overload\n * @param {HookTarget} target The target element to be double clicked\n * @param {(event: DoubleClickEvents) => void} callback The callback function to be invoked on double click\n * @param {UseDoubleClickOptions} [options] The options for the double click\n * @returns {boolean} The double clicking state\n *\n * @example\n * useDoubleClick(ref, () => console.log('double clicked'));\n *\n * @overload\n * @template Target The target element\n * @param {(event: DoubleClickEvents) => void} callback The callback function to be invoked on double click\n * @param {UseDoubleClickOptions} [options] The options for the double click\n * @returns {boolean} The double clicking state\n *\n * @example\n * const ref = useDoubleClick(() => console.log('double clicked'));\n *\n * @see {@link https://siberiacancode.github.io/reactuse/functions/hooks/useDoubleClick.html}\n */\nexport const useDoubleClick = ((...params: any[]): any => {\n const target = (isTarget(params[0]) ? params[0] : undefined) as HookTarget | undefined;\n const callback = (target ? params[1] : params[0]) as (event: DoubleClickEvents) => void;\n const options = (target ? params[2] : params[1]) as UseDoubleClickOptions | undefined;\n\n const timeoutIdRef = useRef<ReturnType<typeof setTimeout>>();\n const clickCountRef = useRef(0);\n const internalRef = useRefState<Element>();\n\n const internalCallbackRef = useRef(callback);\n internalCallbackRef.current = callback;\n const internalOptionsRef = useRef(options);\n internalOptionsRef.current = options;\n\n useEffect(() => {\n if (!target && !internalRef.state) return;\n\n const element = target ? getElement(target) : internalRef.current;\n if (!element) return;\n\n const onClick = (event: DoubleClickEvents) => {\n clickCountRef.current += 1;\n\n if (clickCountRef.current === 1) {\n timeoutIdRef.current = setTimeout(() => {\n if (internalOptionsRef.current?.onSingleClick)\n internalOptionsRef.current.onSingleClick(event);\n clickCountRef.current = 0;\n }, internalOptionsRef.current?.threshold ?? DEFAULT_THRESHOLD_TIME);\n }\n\n if (clickCountRef.current === 2) {\n clearTimeout(timeoutIdRef.current);\n internalCallbackRef.current(event);\n clickCountRef.current = 0;\n }\n };\n\n element.addEventListener('mousedown', onClick as EventListener);\n element.addEventListener('touchstart', onClick as EventListener);\n\n return () => {\n element.removeEventListener('mousedown', onClick as EventListener);\n element.removeEventListener('touchstart', onClick as EventListener);\n if (timeoutIdRef.current) clearTimeout(timeoutIdRef.current);\n };\n }, [target, internalRef.state]);\n\n if (target) return;\n return internalRef;\n}) as UseDoubleClick;\n"],"names":["DEFAULT_THRESHOLD_TIME","useDoubleClick","params","target","isTarget","callback","options","timeoutIdRef","useRef","clickCountRef","internalRef","useRefState","internalCallbackRef","internalOptionsRef","useEffect","element","getElement","onClick","event","_a"],"mappings":"mPAkCMA,EAAyB,IA2BlBC,EAAkB,IAAIC,IAAuB,CAClD,MAAAC,EAAUC,WAASF,EAAO,CAAC,CAAC,EAAIA,EAAO,CAAC,EAAI,OAC5CG,EAAYF,EAASD,EAAO,CAAC,EAAIA,EAAO,CAAC,EACzCI,EAAWH,EAASD,EAAO,CAAC,EAAIA,EAAO,CAAC,EAExCK,EAAeC,EAAAA,OAAsC,EACrDC,EAAgBD,SAAO,CAAC,EACxBE,EAAcC,EAAAA,YAAqB,EAEnCC,EAAsBJ,SAAOH,CAAQ,EAC3CO,EAAoB,QAAUP,EACxB,MAAAQ,EAAqBL,SAAOF,CAAO,EAqCzC,GApCAO,EAAmB,QAAUP,EAE7BQ,EAAAA,UAAU,IAAM,CACd,GAAI,CAACX,GAAU,CAACO,EAAY,MAAO,OAEnC,MAAMK,EAAUZ,EAASa,EAAAA,WAAWb,CAAM,EAAIO,EAAY,QAC1D,GAAI,CAACK,EAAS,OAER,MAAAE,EAAWC,GAA6B,OAC5CT,EAAc,SAAW,EAErBA,EAAc,UAAY,IACfF,EAAA,QAAU,WAAW,IAAM,QAClCY,EAAAN,EAAmB,UAAnB,MAAAM,EAA4B,eACXN,EAAA,QAAQ,cAAcK,CAAK,EAChDT,EAAc,QAAU,CACvB,IAAAU,EAAAN,EAAmB,UAAnB,YAAAM,EAA4B,YAAanB,CAAsB,GAGhES,EAAc,UAAY,IAC5B,aAAaF,EAAa,OAAO,EACjCK,EAAoB,QAAQM,CAAK,EACjCT,EAAc,QAAU,EAE5B,EAEQ,OAAAM,EAAA,iBAAiB,YAAaE,CAAwB,EACtDF,EAAA,iBAAiB,aAAcE,CAAwB,EAExD,IAAM,CACHF,EAAA,oBAAoB,YAAaE,CAAwB,EACzDF,EAAA,oBAAoB,aAAcE,CAAwB,EAC9DV,EAAa,SAAsB,aAAAA,EAAa,OAAO,CAC7D,CACC,EAAA,CAACJ,EAAQO,EAAY,KAAK,CAAC,EAE1B,CAAAP,EACG,OAAAO,CACT"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFul.cjs","sources":["../../../../src/hooks/useFul/useFul.ts"],"sourcesContent":["import { useEffect } from 'react';\n\n/**\n * @name useFul\n * @description - Hook that can be so useful\n * @category Humor\n *\n * @warning - This hook is a joke. Please do not use it in production code!\n *\n * @template Value The type of the value\n * @param {Value} [value] The value to be returned\n * @returns {Value} The value passed to the hook\n *\n * @example\n * const value = useFul(state);\n */\nexport const useFul = <Value>(value?: Value) => {\n useEffect(() => {\n console.warn(\"Warning: You forgot to delete the 'useFul' hook.\");\n }, []);\n\n return value;\n};\n"],"names":["useFul","value","useEffect"],"mappings":"yGAgBaA,EAAiBC,IAC5BC,EAAAA,UAAU,IAAM,CACd,QAAQ,KAAK,kDAAkD,CACjE,EAAG,EAAE,EAEED"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIntersectionObserver.cjs","sources":["../../../../src/hooks/useIntersectionObserver/useIntersectionObserver.ts"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\n\nimport type { HookTarget } from '@/utils/helpers';\n\nimport { getElement, isTarget } from '@/utils/helpers';\n\nimport type { StateRef } from '../useRefState/useRefState';\n\nimport { useRefState } from '../useRefState/useRefState';\n\n/** The intersection observer options type */\nexport interface UseIntersectionObserverOptions extends Omit<IntersectionObserverInit, 'root'> {\n enabled?: boolean;\n root?: HookTarget;\n onChange?: (entry: IntersectionObserverEntry) => void;\n}\n\n/** The intersection observer return type */\nexport interface UseIntersectionObserverReturn {\n entry?: IntersectionObserverEntry;\n inView: boolean;\n}\n\nexport interface UseIntersectionObserver {\n <Target extends Element>(\n options?: UseIntersectionObserverOptions,\n target?: never\n ): UseIntersectionObserverReturn & { ref: StateRef<Target> };\n\n (target: HookTarget, options?: UseIntersectionObserverOptions): UseIntersectionObserverReturn;\n}\n\n/**\n * @name useIntersectionObserver\n * @description - Hook that gives you intersection observer state\n * @category Browser\n *\n * @overload\n * @param {HookTarget} target The target element to detect intersection\n * @param {boolean} [options.enabled=true] The IntersectionObserver options\n * @param {((entries: IntersectionObserverEntry[], observer: IntersectionObserver) => void) | undefined} [options.onChange] The callback to execute when intersection is detected\n * @param {HookTarget} [options.root] The root element to observe\n * @returns {UseIntersectionObserverReturn} An object containing the state and the supported status\n *\n * @example\n * const { ref, entry, inView } = useIntersectionObserver();\n *\n * @overload\n * @template Target The target element\n * @param {boolean} [options.enabled=true] The IntersectionObserver options\n * @param {((entries: IntersectionObserverEntry[], observer: IntersectionObserver) => void) | undefined} [options.onChange] The callback to execute when intersection is detected\n * @param {HookTarget} [options.root] The root element to observe\n * @returns {UseIntersectionObserverReturn & { ref: StateRef<Target> }} A React ref to attach to the target element\n *\n * @example\n * const { entry, inView } = useIntersectionObserver(ref);\n */\nexport const useIntersectionObserver = ((...params: any[]) => {\n const target = (isTarget(params[0]) ? params[0] : undefined) as HookTarget | undefined;\n const options = (target ? params[1] : params[0]) as UseIntersectionObserverOptions | undefined;\n const enabled = options?.enabled ?? true;\n\n const [entry, setEntry] = useState<IntersectionObserverEntry>();\n\n const internalRef = useRefState<Element>();\n const internalOnChangeRef = useRef<UseIntersectionObserverOptions['onChange']>(options?.onChange);\n internalOnChangeRef.current = options?.onChange;\n\n useEffect(() => {\n if (!enabled && !target && !internalRef.state) return;\n\n const element = target ? getElement(target) : internalRef.current;\n if (!element) return;\n\n const observer = new IntersectionObserver(\n ([entry]) => {\n setEntry(entry);\n internalOnChangeRef.current?.(entry);\n },\n {\n ...options,\n root: options?.root ? (getElement(options.root) as Document | Element) : document\n }\n );\n\n observer.observe(element as Element);\n\n return () => {\n observer.disconnect();\n };\n }, [target, internalRef.state, options?.rootMargin, options?.threshold, options?.root, enabled]);\n\n if (target) return { entry, inView: !!entry?.isIntersecting };\n return {\n ref: internalRef,\n entry,\n inView: !!entry?.isIntersecting\n };\n}) as UseIntersectionObserver;\n"],"names":["useIntersectionObserver","params","target","isTarget","options","enabled","entry","setEntry","useState","internalRef","useRefState","internalOnChangeRef","useRef","useEffect","element","getElement","observer","_a"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useIntersectionObserver.cjs","sources":["../../../../src/hooks/useIntersectionObserver/useIntersectionObserver.ts"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\n\nimport type { HookTarget } from '@/utils/helpers';\n\nimport { getElement, isTarget } from '@/utils/helpers';\n\nimport type { StateRef } from '../useRefState/useRefState';\n\nimport { useRefState } from '../useRefState/useRefState';\n\n/** The intersection observer options type */\nexport interface UseIntersectionObserverOptions extends Omit<IntersectionObserverInit, 'root'> {\n enabled?: boolean;\n root?: HookTarget;\n onChange?: (entry: IntersectionObserverEntry) => void;\n}\n\n/** The intersection observer return type */\nexport interface UseIntersectionObserverReturn {\n entry?: IntersectionObserverEntry;\n inView: boolean;\n}\n\nexport interface UseIntersectionObserver {\n <Target extends Element>(\n options?: UseIntersectionObserverOptions,\n target?: never\n ): UseIntersectionObserverReturn & { ref: StateRef<Target> };\n\n (target: HookTarget, options?: UseIntersectionObserverOptions): UseIntersectionObserverReturn;\n}\n\n/**\n * @name useIntersectionObserver\n * @description - Hook that gives you intersection observer state\n * @category Browser\n *\n * @browserapi IntersectionObserver https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserver\n *\n * @overload\n * @param {HookTarget} target The target element to detect intersection\n * @param {boolean} [options.enabled=true] The IntersectionObserver options\n * @param {((entries: IntersectionObserverEntry[], observer: IntersectionObserver) => void) | undefined} [options.onChange] The callback to execute when intersection is detected\n * @param {HookTarget} [options.root] The root element to observe\n * @returns {UseIntersectionObserverReturn} An object containing the state and the supported status\n *\n * @example\n * const { ref, entry, inView } = useIntersectionObserver();\n *\n * @overload\n * @template Target The target element\n * @param {boolean} [options.enabled=true] The IntersectionObserver options\n * @param {((entries: IntersectionObserverEntry[], observer: IntersectionObserver) => void) | undefined} [options.onChange] The callback to execute when intersection is detected\n * @param {HookTarget} [options.root] The root element to observe\n * @returns {UseIntersectionObserverReturn & { ref: StateRef<Target> }} A React ref to attach to the target element\n *\n * @example\n * const { entry, inView } = useIntersectionObserver(ref);\n */\nexport const useIntersectionObserver = ((...params: any[]) => {\n const target = (isTarget(params[0]) ? params[0] : undefined) as HookTarget | undefined;\n const options = (target ? params[1] : params[0]) as UseIntersectionObserverOptions | undefined;\n const enabled = options?.enabled ?? true;\n\n const [entry, setEntry] = useState<IntersectionObserverEntry>();\n\n const internalRef = useRefState<Element>();\n const internalOnChangeRef = useRef<UseIntersectionObserverOptions['onChange']>(options?.onChange);\n internalOnChangeRef.current = options?.onChange;\n\n useEffect(() => {\n if (!enabled && !target && !internalRef.state) return;\n\n const element = target ? getElement(target) : internalRef.current;\n if (!element) return;\n\n const observer = new IntersectionObserver(\n ([entry]) => {\n setEntry(entry);\n internalOnChangeRef.current?.(entry);\n },\n {\n ...options,\n root: options?.root ? (getElement(options.root) as Document | Element) : document\n }\n );\n\n observer.observe(element as Element);\n\n return () => {\n observer.disconnect();\n };\n }, [target, internalRef.state, options?.rootMargin, options?.threshold, options?.root, enabled]);\n\n if (target) return { entry, inView: !!entry?.isIntersecting };\n return {\n ref: internalRef,\n entry,\n inView: !!entry?.isIntersecting\n };\n}) as UseIntersectionObserver;\n"],"names":["useIntersectionObserver","params","target","isTarget","options","enabled","entry","setEntry","useState","internalRef","useRefState","internalOnChangeRef","useRef","useEffect","element","getElement","observer","_a"],"mappings":"mPA2DaA,EAA2B,IAAIC,IAAkB,CACtD,MAAAC,EAAUC,WAASF,EAAO,CAAC,CAAC,EAAIA,EAAO,CAAC,EAAI,OAC5CG,EAAWF,EAASD,EAAO,CAAC,EAAIA,EAAO,CAAC,EACxCI,GAAUD,GAAA,YAAAA,EAAS,UAAW,GAE9B,CAACE,EAAOC,CAAQ,EAAIC,WAAoC,EAExDC,EAAcC,EAAAA,YAAqB,EACnCC,EAAsBC,EAAAA,OAAmDR,GAAA,YAAAA,EAAS,QAAQ,EA2B5F,OA1BJO,EAAoB,QAAUP,GAAA,YAAAA,EAAS,SAEvCS,EAAAA,UAAU,IAAM,CACd,GAAI,CAACR,GAAW,CAACH,GAAU,CAACO,EAAY,MAAO,OAE/C,MAAMK,EAAUZ,EAASa,EAAAA,WAAWb,CAAM,EAAIO,EAAY,QAC1D,GAAI,CAACK,EAAS,OAEd,MAAME,EAAW,IAAI,qBACnB,CAAC,CAACV,CAAK,IAAM,OACXC,EAASD,CAAK,GACdW,EAAAN,EAAoB,UAApB,MAAAM,EAAA,KAAAN,EAA8BL,EAChC,EACA,CACE,GAAGF,EACH,KAAMA,GAAA,MAAAA,EAAS,KAAQW,EAAW,WAAAX,EAAQ,IAAI,EAA2B,QAAA,CAE7E,EAEA,OAAAY,EAAS,QAAQF,CAAkB,EAE5B,IAAM,CACXE,EAAS,WAAW,CACtB,CACC,EAAA,CAACd,EAAQO,EAAY,MAAOL,GAAA,YAAAA,EAAS,WAAYA,GAAA,YAAAA,EAAS,UAAWA,GAAA,YAAAA,EAAS,KAAMC,CAAO,CAAC,EAE3FH,EAAe,CAAE,MAAAI,EAAO,OAAQ,CAAC,EAACA,GAAA,MAAAA,EAAO,eAAe,EACrD,CACL,IAAKG,EACL,MAAAH,EACA,OAAQ,CAAC,EAACA,GAAA,MAAAA,EAAO,eACnB,CACF"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("react"),R=(h={})=>{const r=typeof window<"u"&&"speechSynthesis"in window,{text:i="",lang:a="en-US",pitch:l=1,rate:p=1,voice:w=null,volume:f=1}=h,[S,s]=u.useState(!1),[y,c]=u.useState("init"),[g,m]=u.useState(),t=u.useRef(null),d=e=>{e.lang=a,e.pitch=l,e.rate=p,e.volume=f,e.voice=w,e.onstart=()=>{s(!0),c("play")},e.onpause=()=>{s(!1),c("pause")},e.onresume=()=>{s(!0),c("play")},e.onend=()=>{s(!1),c("end")},e.onerror=n=>{s(!1),m(n)}};u.useEffect(()=>{if(!r)return;const e=new SpeechSynthesisUtterance(i);return d(e),t.current=e,()=>{var n;(n=window.speechSynthesis)==null||n.cancel()}},[i,a,l,p,w,f]);const v=e=>{var n,o;r&&(e&&(t.current=new SpeechSynthesisUtterance(e),d(t.current)),(n=window.speechSynthesis)==null||n.cancel(),t.current&&((o=window.speechSynthesis)==null||o.speak(t.current)))},b=()=>{var e;r&&((e=window.speechSynthesis)==null||e.cancel(),s(!1))},k=(e=!S)=>{var n,o;r&&(e?(n=window.speechSynthesis)==null||n.resume():(o=window.speechSynthesis)==null||o.pause(),s(e))},E=()=>{var e;s(!0),(e=window.speechSynthesis)==null||e.resume()},P=()=>{var e;s(!1),(e=window.speechSynthesis)==null||e.pause()};return{supported:r,playing:S,status:y,utterance:t.current,error:g,stop:b,toggle:k,speak:v,resume:E,pause:P}};exports.useSpeechSynthesis=R;
|
|
2
|
+
//# sourceMappingURL=useSpeechSynthesis.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSpeechSynthesis.cjs","sources":["../../../../src/hooks/useSpeechSynthesis/useSpeechSynthesis.ts"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\n\n/** The use speech synthesis status type */\nexport type UseSpeechSynthesisStatus = 'end' | 'init' | 'pause' | 'play';\n\n/** The use speech synthesis options type */\nexport interface UseSpeechSynthesisOptions {\n /** Language for SpeechSynthesis */\n lang?: string;\n /** Gets and sets the pitch at which the utterance will be spoken at. */\n pitch?: number;\n /** Gets and sets the speed at which the utterance will be spoken at. */\n rate?: number;\n /** The text to be spoken */\n text?: string;\n /** Gets and sets the voice that will be used to speak the utterance. */\n voice?: SpeechSynthesisVoice | null;\n /** Gets and sets the volume that the utterance will be spoken at. */\n volume?: number;\n}\n\n/** The use speech synthesis return type */\nexport interface UseSpeechSynthesisReturn {\n /** Any error that occurred during speech synthesis. */\n error: SpeechSynthesisErrorEvent | undefined;\n /** Indicates if speech is currently playing. */\n playing: boolean;\n /** The current status of speech synthesis. */\n status: UseSpeechSynthesisStatus;\n /** Indicates if the SpeechSynthesis API is supported in the current environment. */\n supported: boolean;\n /** The SpeechSynthesisUtterance instance. */\n utterance: SpeechSynthesisUtterance | null;\n /** Function to pause speech synthesis. */\n pause: () => void;\n /** Function to resume speech synthesis. */\n resume: () => void;\n /** Function to start speech synthesis. */\n speak: () => void;\n /** Function to stop speech synthesis. */\n stop: () => void;\n /** Function to toggle between play and pause. */\n toggle: (value?: boolean) => void;\n}\n\n/**\n * @name useSpeechSynthesis\n * @description - Hook that provides speech synthesis functionality\n * @category Sensors\n *\n * @browserapi SpeechSynthesis https://developer.mozilla.org/en-US/docs/Web/API/SpeechSynthesis\n *\n * @params {string} [options.text] - The text to be spoken\n * @params {string} [options.lang] - The language to be spoken\n * @params {number} [options.pitch] - The pitch to be spoken\n * @params {number} [options.rate] - The rate to be spoken\n * @params {SpeechSynthesisVoice} [options.voice] - The voice to be spoken\n * @params {number} [options.volume] - The volume to be spoken\n * @returns {UseSpeechSynthesisReturn} An object containing the speech synthesis state and control methods\n *\n * @example\n * const { supported, playing, status, utterance, error, stop, toggle, speak, resume, pause } = useSpeechSynthesis();\n */\nexport const useSpeechSynthesis = (\n options: UseSpeechSynthesisOptions = {}\n): UseSpeechSynthesisReturn => {\n const supported = typeof window !== 'undefined' && 'speechSynthesis' in window;\n\n const { text = '', lang = 'en-US', pitch = 1, rate = 1, voice = null, volume = 1 } = options;\n\n const [playing, setPlaying] = useState(false);\n const [status, setStatus] = useState<UseSpeechSynthesisStatus>('init');\n const [error, setError] = useState<SpeechSynthesisErrorEvent>();\n const speechSynthesisUtteranceRef = useRef<SpeechSynthesisUtterance | null>(null);\n\n const bindSpeechSynthesisUtterance = (speechSynthesisUtterance: SpeechSynthesisUtterance) => {\n speechSynthesisUtterance.lang = lang;\n speechSynthesisUtterance.pitch = pitch;\n speechSynthesisUtterance.rate = rate;\n speechSynthesisUtterance.volume = volume;\n speechSynthesisUtterance.voice = voice;\n\n speechSynthesisUtterance.onstart = () => {\n setPlaying(true);\n setStatus('play');\n };\n\n speechSynthesisUtterance.onpause = () => {\n setPlaying(false);\n setStatus('pause');\n };\n\n speechSynthesisUtterance.onresume = () => {\n setPlaying(true);\n setStatus('play');\n };\n\n speechSynthesisUtterance.onend = () => {\n setPlaying(false);\n setStatus('end');\n };\n\n speechSynthesisUtterance.onerror = (event) => {\n setPlaying(false);\n setError(event);\n };\n };\n\n useEffect(() => {\n if (!supported) return;\n\n const speechSynthesisUtterance = new SpeechSynthesisUtterance(text);\n bindSpeechSynthesisUtterance(speechSynthesisUtterance);\n speechSynthesisUtteranceRef.current = speechSynthesisUtterance;\n\n return () => {\n window.speechSynthesis?.cancel();\n };\n }, [text, lang, pitch, rate, voice, volume]);\n\n const speak = (text?: string) => {\n if (!supported) return;\n\n if (text) {\n speechSynthesisUtteranceRef.current = new SpeechSynthesisUtterance(text);\n bindSpeechSynthesisUtterance(speechSynthesisUtteranceRef.current);\n }\n\n window.speechSynthesis?.cancel();\n if (speechSynthesisUtteranceRef.current)\n window.speechSynthesis?.speak(speechSynthesisUtteranceRef.current);\n };\n\n const stop = () => {\n if (!supported) return;\n\n window.speechSynthesis?.cancel();\n setPlaying(false);\n };\n\n const toggle = (value = !playing) => {\n if (!supported) return;\n\n if (value) {\n window.speechSynthesis?.resume();\n } else {\n window.speechSynthesis?.pause();\n }\n setPlaying(value);\n };\n\n const resume = () => {\n setPlaying(true);\n window.speechSynthesis?.resume();\n };\n\n const pause = () => {\n setPlaying(false);\n window.speechSynthesis?.pause();\n };\n\n return {\n supported,\n playing,\n status,\n utterance: speechSynthesisUtteranceRef.current,\n error,\n\n stop,\n toggle,\n speak,\n resume,\n pause\n };\n};\n"],"names":["useSpeechSynthesis","options","supported","text","lang","pitch","rate","voice","volume","playing","setPlaying","useState","status","setStatus","error","setError","speechSynthesisUtteranceRef","useRef","bindSpeechSynthesisUtterance","speechSynthesisUtterance","event","useEffect","_a","speak","_b","stop","toggle","value","resume","pause"],"mappings":"yGA+DaA,EAAqB,CAChCC,EAAqC,KACR,CAC7B,MAAMC,EAAY,OAAO,OAAW,KAAe,oBAAqB,OAElE,CAAE,KAAAC,EAAO,GAAI,KAAAC,EAAO,QAAS,MAAAC,EAAQ,EAAG,KAAAC,EAAO,EAAG,MAAAC,EAAQ,KAAM,OAAAC,EAAS,CAAM,EAAAP,EAE/E,CAACQ,EAASC,CAAU,EAAIC,EAAAA,SAAS,EAAK,EACtC,CAACC,EAAQC,CAAS,EAAIF,EAAAA,SAAmC,MAAM,EAC/D,CAACG,EAAOC,CAAQ,EAAIJ,WAAoC,EACxDK,EAA8BC,SAAwC,IAAI,EAE1EC,EAAgCC,GAAuD,CAC3FA,EAAyB,KAAOf,EAChCe,EAAyB,MAAQd,EACjCc,EAAyB,KAAOb,EAChCa,EAAyB,OAASX,EAClCW,EAAyB,MAAQZ,EAEjCY,EAAyB,QAAU,IAAM,CACvCT,EAAW,EAAI,EACfG,EAAU,MAAM,CAClB,EAEAM,EAAyB,QAAU,IAAM,CACvCT,EAAW,EAAK,EAChBG,EAAU,OAAO,CACnB,EAEAM,EAAyB,SAAW,IAAM,CACxCT,EAAW,EAAI,EACfG,EAAU,MAAM,CAClB,EAEAM,EAAyB,MAAQ,IAAM,CACrCT,EAAW,EAAK,EAChBG,EAAU,KAAK,CACjB,EAEyBM,EAAA,QAAWC,GAAU,CAC5CV,EAAW,EAAK,EAChBK,EAASK,CAAK,CAChB,CACF,EAEAC,EAAAA,UAAU,IAAM,CACd,GAAI,CAACnB,EAAW,OAEV,MAAAiB,EAA2B,IAAI,yBAAyBhB,CAAI,EAClE,OAAAe,EAA6BC,CAAwB,EACrDH,EAA4B,QAAUG,EAE/B,IAAM,QACXG,EAAA,OAAO,kBAAP,MAAAA,EAAwB,QAC1B,CAAA,EACC,CAACnB,EAAMC,EAAMC,EAAOC,EAAMC,EAAOC,CAAM,CAAC,EAErC,MAAAe,EAASpB,GAAkB,SAC1BD,IAEDC,IAC0Ba,EAAA,QAAU,IAAI,yBAAyBb,CAAI,EACvEe,EAA6BF,EAA4B,OAAO,IAGlEM,EAAA,OAAO,kBAAP,MAAAA,EAAwB,SACpBN,EAA4B,WACvBQ,EAAA,OAAA,kBAAA,MAAAA,EAAiB,MAAMR,EAA4B,UAC9D,EAEMS,EAAO,IAAM,OACZvB,KAELoB,EAAA,OAAO,kBAAP,MAAAA,EAAwB,SACxBZ,EAAW,EAAK,EAClB,EAEMgB,EAAS,CAACC,EAAQ,CAAClB,IAAY,SAC9BP,IAEDyB,GACFL,EAAA,OAAO,kBAAP,MAAAA,EAAwB,UAExBE,EAAA,OAAO,kBAAP,MAAAA,EAAwB,QAE1Bd,EAAWiB,CAAK,EAClB,EAEMC,EAAS,IAAM,OACnBlB,EAAW,EAAI,GACfY,EAAA,OAAO,kBAAP,MAAAA,EAAwB,QAC1B,EAEMO,EAAQ,IAAM,OAClBnB,EAAW,EAAK,GAChBY,EAAA,OAAO,kBAAP,MAAAA,EAAwB,OAC1B,EAEO,MAAA,CACL,UAAApB,EACA,QAAAO,EACA,OAAAG,EACA,UAAWI,EAA4B,QACvC,MAAAF,EAEA,KAAAW,EACA,OAAAC,EACA,MAAAH,EACA,OAAAK,EACA,MAAAC,CACF,CACF"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("react"),v=e=>{const r=typeof navigator<"u"&&"wakeLock"in navigator,[l,c]=i.useState(!1),t=i.useRef(),d=(e==null?void 0:e.immediately)??!1,n=(e==null?void 0:e.type)??"screen",s=async a=>{r&&(t.current=await navigator.wakeLock.request(a??(e==null?void 0:e.type)),t.current.addEventListener("release",()=>{c(!1),t.current=void 0}),c(!0))},u=async()=>{!r||!t.current||(await t.current.release(),t.current=void 0,c(!1))};return i.useEffect(()=>{if(!r||!d||document.visibilityState!=="visible"||n!=="screen")return;const a=async()=>{await u(),await s(n)};return document.addEventListener("visibilitychange",a),()=>{document.removeEventListener("visibilitychange",a)}},[n]),{supported:r,active:l,request:s,release:u}};exports.useWakeLock=v;
|
|
2
|
+
//# sourceMappingURL=useWakeLock.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useWakeLock.cjs","sources":["../../../../src/hooks/useWakeLock/useWakeLock.ts"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\n\n/** The use wake lock options type */\nexport interface UseWakeLockOptions {\n /** Determines if the wake lock should be automatically reacquired when the document becomes visible. */\n immediately?: boolean;\n /** A string specifying the screen wake lock type. */\n type?: WakeLockType;\n}\n\n/** The use wake lock return type */\nexport interface UseWakeLockReturn {\n /** Indicates if the wake lock is currently active. */\n active: boolean;\n /** Indicates if the Wake Lock API is supported in the current environment. */\n supported: boolean;\n /** Function to release the wake lock. */\n release: () => Promise<void>;\n /** Function to request the wake lock. */\n request: () => Promise<void>;\n}\n\n/**\n * @name useWakeLock\n * @description - Hook that provides a wake lock functionality\n * @category Browser\n *\n * @browserapi navigator.wakeLock https://developer.mozilla.org/en-US/docs/Web/API/WakeLock\n *\n * @param {immediately} [options] Configuration options for the hook.\n * @returns {UseWakeLockReturn} An object containing the wake lock state and control methods.\n *\n * @example\n * const { supported, active, request, release } = useWakeLock();\n */\nexport const useWakeLock = (options?: UseWakeLockOptions): UseWakeLockReturn => {\n const supported = typeof navigator !== 'undefined' && 'wakeLock' in navigator;\n\n const [active, setActive] = useState(false);\n const sentinel = useRef<WakeLockSentinel>();\n\n const immediately = options?.immediately ?? false;\n const type = options?.type ?? 'screen';\n\n const request = async (type?: WakeLockType) => {\n if (!supported) return;\n\n sentinel.current = await navigator.wakeLock.request(type ?? options?.type);\n sentinel.current.addEventListener('release', () => {\n setActive(false);\n sentinel.current = undefined;\n });\n\n setActive(true);\n };\n\n const release = async () => {\n if (!supported || !sentinel.current) return;\n\n await sentinel.current.release();\n sentinel.current = undefined;\n setActive(false);\n };\n\n useEffect(() => {\n if (!supported || !immediately || document.visibilityState !== 'visible' || type !== 'screen')\n return;\n\n const onVisibilityChange = async () => {\n await release();\n await request(type);\n };\n\n document.addEventListener('visibilitychange', onVisibilityChange);\n return () => {\n document.removeEventListener('visibilitychange', onVisibilityChange);\n };\n }, [type]);\n\n return { supported, active, request, release };\n};\n"],"names":["useWakeLock","options","supported","active","setActive","useState","sentinel","useRef","immediately","type","request","release","useEffect","onVisibilityChange"],"mappings":"yGAmCaA,EAAeC,GAAoD,CAC9E,MAAMC,EAAY,OAAO,UAAc,KAAe,aAAc,UAE9D,CAACC,EAAQC,CAAS,EAAIC,EAAAA,SAAS,EAAK,EACpCC,EAAWC,EAAAA,OAAyB,EAEpCC,GAAcP,GAAA,YAAAA,EAAS,cAAe,GACtCQ,GAAOR,GAAA,YAAAA,EAAS,OAAQ,SAExBS,EAAU,MAAOD,GAAwB,CACxCP,IAELI,EAAS,QAAU,MAAM,UAAU,SAAS,QAAQG,IAAQR,GAAA,YAAAA,EAAS,KAAI,EAChEK,EAAA,QAAQ,iBAAiB,UAAW,IAAM,CACjDF,EAAU,EAAK,EACfE,EAAS,QAAU,MAAA,CACpB,EAEDF,EAAU,EAAI,EAChB,EAEMO,EAAU,SAAY,CACtB,CAACT,GAAa,CAACI,EAAS,UAEtB,MAAAA,EAAS,QAAQ,QAAQ,EAC/BA,EAAS,QAAU,OACnBF,EAAU,EAAK,EACjB,EAEAQ,OAAAA,EAAAA,UAAU,IAAM,CACd,GAAI,CAACV,GAAa,CAACM,GAAe,SAAS,kBAAoB,WAAaC,IAAS,SACnF,OAEF,MAAMI,EAAqB,SAAY,CACrC,MAAMF,EAAQ,EACd,MAAMD,EAAQD,CAAI,CACpB,EAES,gBAAA,iBAAiB,mBAAoBI,CAAkB,EACzD,IAAM,CACF,SAAA,oBAAoB,mBAAoBA,CAAkB,CACrE,CAAA,EACC,CAACJ,CAAI,CAAC,EAEF,CAAE,UAAAP,EAAW,OAAAC,EAAQ,QAAAO,EAAS,QAAAC,CAAQ,CAC/C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useWindowFocus.cjs","sources":["../../../../src/hooks/useWindowFocus/useWindowFocus.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\n/**\n * @name useWindowFocus\n * @description - Hook that provides the current focus state of the window\n * @category Elements\n *\n * @returns {boolean} The current focus state of the window\n *\n * @example\n * const focused = useWindowFocus();\n */\nexport const useWindowFocus = () => {\n const [focused, setFocused] = useState(false);\n\n useEffect(() => {\n const onFocus = () => setFocused(true);\n const onBlur = () => setFocused(false);\n\n window.addEventListener('focus', onFocus);\n window.addEventListener('blur', onBlur);\n\n return () => {\n window.removeEventListener('focus', onFocus);\n window.removeEventListener('blur', onBlur);\n };\n });\n\n return focused;\n};\n"],"names":["useWindowFocus","focused","setFocused","useState","useEffect","onFocus","onBlur"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useWindowFocus.cjs","sources":["../../../../src/hooks/useWindowFocus/useWindowFocus.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\n/**\n * @name useWindowFocus\n * @description - Hook that provides the current focus state of the window\n * @category Elements\n *\n * @returns {boolean} The current focus state of the window\n *\n * @example\n * const focused = useWindowFocus();\n *\n * @see {@link https://siberiacancode.github.io/reactuse/functions/hooks/useWindowFocus.html}\n */\nexport const useWindowFocus = () => {\n const [focused, setFocused] = useState(false);\n\n useEffect(() => {\n const onFocus = () => setFocused(true);\n const onBlur = () => setFocused(false);\n\n window.addEventListener('focus', onFocus);\n window.addEventListener('blur', onBlur);\n\n return () => {\n window.removeEventListener('focus', onFocus);\n window.removeEventListener('blur', onBlur);\n };\n });\n\n return focused;\n};\n"],"names":["useWindowFocus","focused","setFocused","useState","useEffect","onFocus","onBlur"],"mappings":"yGAcaA,EAAiB,IAAM,CAClC,KAAM,CAACC,EAASC,CAAU,EAAIC,EAAAA,SAAS,EAAK,EAE5CC,OAAAA,EAAAA,UAAU,IAAM,CACR,MAAAC,EAAU,IAAMH,EAAW,EAAI,EAC/BI,EAAS,IAAMJ,EAAW,EAAK,EAE9B,cAAA,iBAAiB,QAASG,CAAO,EACjC,OAAA,iBAAiB,OAAQC,CAAM,EAE/B,IAAM,CACJ,OAAA,oBAAoB,QAASD,CAAO,EACpC,OAAA,oBAAoB,OAAQC,CAAM,CAC3C,CAAA,CACD,EAEML,CACT"}
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
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"),k=require("./hooks/useCopy/useCopy.cjs"),v=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/useDoubleClick/useDoubleClick.cjs"),W=require("./hooks/useElementSize/useElementSize.cjs"),x=require("./hooks/useEvent/useEvent.cjs"),H=require("./hooks/useEventListener/useEventListener.cjs"),U=require("./hooks/useEyeDropper/useEyeDropper.cjs"),z=require("./hooks/useFavicon/useFavicon.cjs"),G=require("./hooks/useField/useField.cjs"),Q=require("./hooks/useFileDialog/useFileDialog.cjs"),X=require("./hooks/useFocus/useFocus.cjs"),j=require("./hooks/useFps/useFps.cjs"),J=require("./hooks/useFullscreen/useFullscreen.cjs"),i=require("./hooks/useGamepad/useGamepad.cjs"),Y=require("./hooks/useGeolocation/useGeolocation.cjs"),Z=require("./hooks/useHash/useHash.cjs"),n=require("./hooks/useHotkeys/useHotkeys.cjs"),$=require("./hooks/useHover/useHover.cjs"),ee=require("./hooks/useIdle/useIdle.cjs"),se=require("./hooks/useImage/useImage.cjs"),ue=require("./hooks/useInfiniteScroll/useInfiniteScroll.cjs"),re=require("./hooks/useIntersectionObserver/useIntersectionObserver.cjs"),te=require("./hooks/useInterval/useInterval.cjs"),oe=require("./hooks/useIsFirstRender/useIsFirstRender.cjs"),ie=require("./hooks/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.cjs"),ne=require("./hooks/useKeyboard/useKeyboard.cjs"),ce=require("./hooks/useKeyPress/useKeyPress.cjs"),ae=require("./hooks/useKeyPressEvent/useKeyPressEvent.cjs"),le=require("./hooks/useKeysPressed/useKeysPressed.cjs"),qe=require("./hooks/useLastChanged/useLastChanged.cjs"),Se=require("./hooks/useLatest/useLatest.cjs"),de=require("./hooks/useLess/useLess.cjs"),ge=require("./hooks/useList/useList.cjs"),Te=require("./hooks/useLocalStorage/useLocalStorage.cjs"),Pe=require("./hooks/useLockCallback/useLockCallback.cjs"),Ce=require("./hooks/useLogger/useLogger.cjs"),Ee=require("./hooks/useLongPress/useLongPress.cjs"),me=require("./hooks/useMap/useMap.cjs"),pe=require("./hooks/useMeasure/useMeasure.cjs"),Re=require("./hooks/useMediaQuery/useMediaQuery.cjs"),Oe=require("./hooks/useMemory/useMemory.cjs"),ye=require("./hooks/useMount/useMount.cjs"),Ie=require("./hooks/useMouse/useMouse.cjs"),ke=require("./hooks/useMutation/useMutation.cjs"),ve=require("./hooks/useMutationObserver/useMutationObserver.cjs"),c=require("./hooks/useNetwork/useNetwork.cjs"),De=require("./hooks/useOffsetPagination/useOffsetPagination.cjs"),be=require("./hooks/useOnce/useOnce.cjs"),Ae=require("./hooks/useOnline/useOnline.cjs"),a=require("./hooks/useOperatingSystem/useOperatingSystem.cjs"),Me=require("./hooks/useOptimistic/useOptimistic.cjs"),fe=require("./hooks/useOrientation/useOrientation.cjs"),Le=require("./hooks/useOtpCredential/useOtpCredential.cjs"),he=require("./hooks/usePageLeave/usePageLeave.cjs"),r=require("./hooks/usePaint/usePaint.cjs"),_e=require("./hooks/useParallax/useParallax.cjs"),Ne=require("./hooks/usePerformanceObserver/usePerformanceObserver.cjs"),Be=require("./hooks/usePermission/usePermission.cjs"),Ke=require("./hooks/usePointerLock/usePointerLock.cjs"),Ve=require("./hooks/usePostMessage/usePostMessage.cjs"),Fe=require("./hooks/usePreferredColorScheme/usePreferredColorScheme.cjs"),we=require("./hooks/usePreferredContrast/usePreferredContrast.cjs"),We=require("./hooks/usePreferredDark/usePreferredDark.cjs"),xe=require("./hooks/usePreferredLanguages/usePreferredLanguages.cjs"),He=require("./hooks/usePreferredReducedMotion/usePreferredReducedMotion.cjs"),Ue=require("./hooks/usePrevious/usePrevious.cjs"),ze=require("./hooks/useQuery/useQuery.cjs"),Ge=require("./hooks/useQueue/useQueue.cjs"),Qe=require("./hooks/useRaf/useRaf.cjs"),Xe=require("./hooks/useRafValue/useRafValue.cjs"),je=require("./hooks/useRefState/useRefState.cjs"),Je=require("./hooks/useRenderCount/useRenderCount.cjs"),Ye=require("./hooks/useRenderInfo/useRenderInfo.cjs"),Ze=require("./hooks/useRerender/useRerender.cjs"),$e=require("./hooks/useResizeObserver/useResizeObserver.cjs"),es=require("./hooks/useScreenOrientation/useScreenOrientation.cjs"),l=require("./hooks/useScript/useScript.cjs"),ss=require("./hooks/useScroll/useScroll.cjs"),us=require("./hooks/useScrollIntoView/useScrollIntoView.cjs"),rs=require("./hooks/useScrollTo/useScrollTo.cjs"),ts=require("./hooks/useSessionStorage/useSessionStorage.cjs"),os=require("./hooks/useSet/useSet.cjs"),is=require("./hooks/useShare/useShare.cjs"),q=require("./hooks/useSpeechRecognition/useSpeechRecognition.cjs"),ns=require("./hooks/useStateHistory/useStateHistory.cjs"),cs=require("./hooks/useStep/useStep.cjs"),as=require("./hooks/useSticky/useSticky.cjs"),ls=require("./hooks/useStopwatch/useStopwatch.cjs"),t=require("./hooks/useStorage/useStorage.cjs"),qs=require("./hooks/useTextDirection/useTextDirection.cjs"),S=require("./hooks/useTextSelection/useTextSelection.cjs"),Ss=require("./hooks/useThrottleCallback/useThrottleCallback.cjs"),ds=require("./hooks/useThrottleValue/useThrottleValue.cjs"),gs=require("./hooks/useTime/useTime.cjs"),Ts=require("./hooks/useTimeout/useTimeout.cjs"),d=require("./hooks/useTimer/useTimer.cjs"),Ps=require("./hooks/useToggle/useToggle.cjs"),Cs=require("./hooks/useUnmount/useUnmount.cjs"),Es=require("./hooks/useVibrate/useVibrate.cjs"),ms=require("./hooks/useWebSocket/useWebSocket.cjs"),ps=require("./hooks/useWindowEvent/useWindowEvent.cjs"),Rs=require("./hooks/useWindowFocus/useWindowFocus.cjs"),g=require("./hooks/useWindowScroll/useWindowScroll.cjs"),Os=require("./hooks/useWindowSize/useWindowSize.cjs"),ys=require("./hooks/useWizard/useWizard.cjs"),T=require("./utils/helpers/copy.cjs"),Is=require("./utils/helpers/debounce.cjs"),ks=require("./utils/helpers/getDate.cjs"),o=require("./utils/helpers/getElement.cjs"),vs=require("./utils/helpers/getRetry.cjs"),Ds=require("./utils/helpers/isTarget.cjs"),bs=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=k.useCopy;exports.useCounter=v.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.useDoubleClick=w.useDoubleClick;exports.useElementSize=W.useElementSize;exports.useEvent=x.useEvent;exports.useEventListener=H.useEventListener;exports.useEyeDropper=U.useEyeDropper;exports.useFavicon=z.useFavicon;exports.useField=G.useField;exports.useFileDialog=Q.useFileDialog;exports.useFocus=X.useFocus;exports.useFps=j.useFps;exports.useFullscreen=J.useFullscreen;exports.mapGamepadToXbox360Controller=i.mapGamepadToXbox360Controller;exports.useGamepad=i.useGamepad;exports.useGeolocation=Y.useGeolocation;exports.useHash=Z.useHash;exports.isHotkeyMatch=n.isHotkeyMatch;exports.useHotkeys=n.useHotkeys;exports.useHover=$.useHover;exports.useIdle=ee.useIdle;exports.useImage=se.useImage;exports.useInfiniteScroll=ue.useInfiniteScroll;exports.useIntersectionObserver=re.useIntersectionObserver;exports.useInterval=te.useInterval;exports.useIsFirstRender=oe.useIsFirstRender;exports.useIsomorphicLayoutEffect=ie.useIsomorphicLayoutEffect;exports.useKeyboard=ne.useKeyboard;exports.useKeyPress=ce.useKeyPress;exports.useKeyPressEvent=ae.useKeyPressEvent;exports.useKeysPressed=le.useKeysPressed;exports.useLastChanged=qe.useLastChanged;exports.useLatest=Se.useLatest;exports.useLess=de.useLess;exports.useList=ge.useList;exports.useLocalStorage=Te.useLocalStorage;exports.useLockCallback=Pe.useLockCallback;exports.useLogger=Ce.useLogger;exports.useLongPress=Ee.useLongPress;exports.useMap=me.useMap;exports.useMeasure=pe.useMeasure;exports.useMediaQuery=Re.useMediaQuery;exports.useMemory=Oe.useMemory;exports.useMount=ye.useMount;exports.useMouse=Ie.useMouse;exports.useMutation=ke.useMutation;exports.useMutationObserver=ve.useMutationObserver;exports.getConnection=c.getConnection;exports.useNetwork=c.useNetwork;exports.useOffsetPagination=De.useOffsetPagination;exports.useOnce=be.useOnce;exports.useOnline=Ae.useOnline;exports.getOperatingSystem=a.getOperatingSystem;exports.useOperatingSystem=a.useOperatingSystem;exports.useOptimistic=Me.useOptimistic;exports.useOrientation=fe.useOrientation;exports.useOtpCredential=Le.useOtpCredential;exports.usePageLeave=he.usePageLeave;exports.Paint=r.Paint;exports.Pointer=r.Pointer;exports.usePaint=r.usePaint;exports.useParallax=_e.useParallax;exports.usePerformanceObserver=Ne.usePerformanceObserver;exports.usePermission=Be.usePermission;exports.usePointerLock=Ke.usePointerLock;exports.usePostMessage=Ve.usePostMessage;exports.usePreferredColorScheme=Fe.usePreferredColorScheme;exports.usePreferredContrast=we.usePreferredContrast;exports.usePreferredDark=We.usePreferredDark;exports.usePreferredLanguages=xe.usePreferredLanguages;exports.usePreferredReducedMotion=He.usePreferredReducedMotion;exports.usePrevious=Ue.usePrevious;exports.useQuery=ze.useQuery;exports.useQueue=Ge.useQueue;exports.useRaf=Qe.useRaf;exports.useRafValue=Xe.useRafValue;exports.useRefState=je.useRefState;exports.useRenderCount=Je.useRenderCount;exports.useRenderInfo=Ye.useRenderInfo;exports.useRerender=Ze.useRerender;exports.useResizeObserver=$e.useResizeObserver;exports.useScreenOrientation=es.useScreenOrientation;exports.SCRIPT_STATUS_ATTRIBUTE_NAME=l.SCRIPT_STATUS_ATTRIBUTE_NAME;exports.useScript=l.useScript;exports.useScroll=ss.useScroll;exports.useScrollIntoView=us.useScrollIntoView;exports.useScrollTo=rs.useScrollTo;exports.useSessionStorage=ts.useSessionStorage;exports.useSet=os.useSet;exports.useShare=is.useShare;exports.getSpeechRecognition=q.getSpeechRecognition;exports.useSpeechRecognition=q.useSpeechRecognition;exports.useStateHistory=ns.useStateHistory;exports.useStep=cs.useStep;exports.useSticky=as.useSticky;exports.useStopwatch=ls.useStopwatch;exports.STORAGE_EVENT=t.STORAGE_EVENT;exports.dispatchStorageEvent=t.dispatchStorageEvent;exports.useStorage=t.useStorage;exports.useTextDirection=qs.useTextDirection;exports.getRangesSelection=S.getRangesSelection;exports.useTextSelection=S.useTextSelection;exports.useThrottleCallback=Ss.useThrottleCallback;exports.useThrottleValue=ds.useThrottleValue;exports.useTime=gs.useTime;exports.useTimeout=Ts.useTimeout;exports.getTimeFromSeconds=d.getTimeFromSeconds;exports.useTimer=d.useTimer;exports.useToggle=Ps.useToggle;exports.useUnmount=Cs.useUnmount;exports.useVibrate=Es.useVibrate;exports.useWebSocket=ms.useWebSocket;exports.useWindowEvent=ps.useWindowEvent;exports.useWindowFocus=Rs.useWindowFocus;exports.scrollTo=g.scrollTo;exports.useWindowScroll=g.useWindowScroll;exports.useWindowSize=Os.useWindowSize;exports.useWizard=ys.useWizard;exports.copy=T.copy;exports.legacyCopyToClipboard=T.legacyCopyToClipboard;exports.debounce=Is.debounce;exports.getDate=ks.getDate;exports.getElement=o.getElement;exports.target=o.target;exports.targetSymbol=o.targetSymbol;exports.getRetry=vs.getRetry;exports.isTarget=Ds.isTarget;exports.throttle=bs.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"),y=require("./hooks/useBrowserLanguage/useBrowserLanguage.cjs"),R=require("./hooks/useClickOutside/useClickOutside.cjs"),O=require("./hooks/useClipboard/useClipboard.cjs"),k=require("./hooks/useConst/useConst.cjs"),s=require("./hooks/useCookie/useCookie.cjs"),u=require("./hooks/useCookies/useCookies.cjs"),I=require("./hooks/useCopy/useCopy.cjs"),v=require("./hooks/useCounter/useCounter.cjs"),D=require("./hooks/useCssVar/useCssVar.cjs"),b=require("./hooks/useDebounceCallback/useDebounceCallback.cjs"),A=require("./hooks/useDebounceValue/useDebounceValue.cjs"),L=require("./hooks/useDefault/useDefault.cjs"),M=require("./hooks/useDeviceMotion/useDeviceMotion.cjs"),f=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"),F=require("./hooks/useDocumentTitle/useDocumentTitle.cjs"),V=require("./hooks/useDocumentVisibility/useDocumentVisibility.cjs"),w=require("./hooks/useDoubleClick/useDoubleClick.cjs"),W=require("./hooks/useElementSize/useElementSize.cjs"),x=require("./hooks/useEvent/useEvent.cjs"),H=require("./hooks/useEventListener/useEventListener.cjs"),U=require("./hooks/useEyeDropper/useEyeDropper.cjs"),z=require("./hooks/useFavicon/useFavicon.cjs"),G=require("./hooks/useField/useField.cjs"),Q=require("./hooks/useFileDialog/useFileDialog.cjs"),X=require("./hooks/useFocus/useFocus.cjs"),j=require("./hooks/useFps/useFps.cjs"),J=require("./hooks/useFul/useFul.cjs"),Y=require("./hooks/useFullscreen/useFullscreen.cjs"),i=require("./hooks/useGamepad/useGamepad.cjs"),Z=require("./hooks/useGeolocation/useGeolocation.cjs"),$=require("./hooks/useHash/useHash.cjs"),n=require("./hooks/useHotkeys/useHotkeys.cjs"),ee=require("./hooks/useHover/useHover.cjs"),se=require("./hooks/useIdle/useIdle.cjs"),ue=require("./hooks/useImage/useImage.cjs"),re=require("./hooks/useInfiniteScroll/useInfiniteScroll.cjs"),te=require("./hooks/useIntersectionObserver/useIntersectionObserver.cjs"),oe=require("./hooks/useInterval/useInterval.cjs"),ie=require("./hooks/useIsFirstRender/useIsFirstRender.cjs"),ne=require("./hooks/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.cjs"),ce=require("./hooks/useKeyboard/useKeyboard.cjs"),ae=require("./hooks/useKeyPress/useKeyPress.cjs"),le=require("./hooks/useKeyPressEvent/useKeyPressEvent.cjs"),qe=require("./hooks/useKeysPressed/useKeysPressed.cjs"),Se=require("./hooks/useLastChanged/useLastChanged.cjs"),de=require("./hooks/useLatest/useLatest.cjs"),ge=require("./hooks/useLess/useLess.cjs"),Te=require("./hooks/useList/useList.cjs"),Pe=require("./hooks/useLocalStorage/useLocalStorage.cjs"),Ce=require("./hooks/useLockCallback/useLockCallback.cjs"),Ee=require("./hooks/useLogger/useLogger.cjs"),me=require("./hooks/useLongPress/useLongPress.cjs"),pe=require("./hooks/useMap/useMap.cjs"),ye=require("./hooks/useMeasure/useMeasure.cjs"),Re=require("./hooks/useMediaQuery/useMediaQuery.cjs"),Oe=require("./hooks/useMemory/useMemory.cjs"),ke=require("./hooks/useMount/useMount.cjs"),Ie=require("./hooks/useMouse/useMouse.cjs"),ve=require("./hooks/useMutation/useMutation.cjs"),De=require("./hooks/useMutationObserver/useMutationObserver.cjs"),c=require("./hooks/useNetwork/useNetwork.cjs"),be=require("./hooks/useOffsetPagination/useOffsetPagination.cjs"),Ae=require("./hooks/useOnce/useOnce.cjs"),Le=require("./hooks/useOnline/useOnline.cjs"),a=require("./hooks/useOperatingSystem/useOperatingSystem.cjs"),Me=require("./hooks/useOptimistic/useOptimistic.cjs"),fe=require("./hooks/useOrientation/useOrientation.cjs"),he=require("./hooks/useOtpCredential/useOtpCredential.cjs"),_e=require("./hooks/usePageLeave/usePageLeave.cjs"),r=require("./hooks/usePaint/usePaint.cjs"),Ne=require("./hooks/useParallax/useParallax.cjs"),Be=require("./hooks/usePerformanceObserver/usePerformanceObserver.cjs"),Ke=require("./hooks/usePermission/usePermission.cjs"),Fe=require("./hooks/usePointerLock/usePointerLock.cjs"),Ve=require("./hooks/usePostMessage/usePostMessage.cjs"),we=require("./hooks/usePreferredColorScheme/usePreferredColorScheme.cjs"),We=require("./hooks/usePreferredContrast/usePreferredContrast.cjs"),xe=require("./hooks/usePreferredDark/usePreferredDark.cjs"),He=require("./hooks/usePreferredLanguages/usePreferredLanguages.cjs"),Ue=require("./hooks/usePreferredReducedMotion/usePreferredReducedMotion.cjs"),ze=require("./hooks/usePrevious/usePrevious.cjs"),Ge=require("./hooks/useQuery/useQuery.cjs"),Qe=require("./hooks/useQueue/useQueue.cjs"),Xe=require("./hooks/useRaf/useRaf.cjs"),je=require("./hooks/useRafValue/useRafValue.cjs"),Je=require("./hooks/useRefState/useRefState.cjs"),Ye=require("./hooks/useRenderCount/useRenderCount.cjs"),Ze=require("./hooks/useRenderInfo/useRenderInfo.cjs"),$e=require("./hooks/useRerender/useRerender.cjs"),es=require("./hooks/useResizeObserver/useResizeObserver.cjs"),ss=require("./hooks/useScreenOrientation/useScreenOrientation.cjs"),l=require("./hooks/useScript/useScript.cjs"),us=require("./hooks/useScroll/useScroll.cjs"),rs=require("./hooks/useScrollIntoView/useScrollIntoView.cjs"),ts=require("./hooks/useScrollTo/useScrollTo.cjs"),os=require("./hooks/useSessionStorage/useSessionStorage.cjs"),is=require("./hooks/useSet/useSet.cjs"),ns=require("./hooks/useShare/useShare.cjs"),q=require("./hooks/useSpeechRecognition/useSpeechRecognition.cjs"),cs=require("./hooks/useSpeechSynthesis/useSpeechSynthesis.cjs"),as=require("./hooks/useStateHistory/useStateHistory.cjs"),ls=require("./hooks/useStep/useStep.cjs"),qs=require("./hooks/useSticky/useSticky.cjs"),Ss=require("./hooks/useStopwatch/useStopwatch.cjs"),t=require("./hooks/useStorage/useStorage.cjs"),ds=require("./hooks/useTextDirection/useTextDirection.cjs"),S=require("./hooks/useTextSelection/useTextSelection.cjs"),gs=require("./hooks/useThrottleCallback/useThrottleCallback.cjs"),Ts=require("./hooks/useThrottleValue/useThrottleValue.cjs"),Ps=require("./hooks/useTime/useTime.cjs"),Cs=require("./hooks/useTimeout/useTimeout.cjs"),d=require("./hooks/useTimer/useTimer.cjs"),Es=require("./hooks/useToggle/useToggle.cjs"),ms=require("./hooks/useUnmount/useUnmount.cjs"),ps=require("./hooks/useVibrate/useVibrate.cjs"),ys=require("./hooks/useWakeLock/useWakeLock.cjs"),Rs=require("./hooks/useWebSocket/useWebSocket.cjs"),Os=require("./hooks/useWindowEvent/useWindowEvent.cjs"),ks=require("./hooks/useWindowFocus/useWindowFocus.cjs"),g=require("./hooks/useWindowScroll/useWindowScroll.cjs"),Is=require("./hooks/useWindowSize/useWindowSize.cjs"),vs=require("./hooks/useWizard/useWizard.cjs"),T=require("./utils/helpers/copy.cjs"),Ds=require("./utils/helpers/debounce.cjs"),bs=require("./utils/helpers/getDate.cjs"),o=require("./utils/helpers/getElement.cjs"),As=require("./utils/helpers/getRetry.cjs"),Ls=require("./utils/helpers/isTarget.cjs"),Ms=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=y.useBrowserLanguage;exports.useClickOutside=R.useClickOutside;exports.useClipboard=O.useClipboard;exports.useConst=k.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=I.useCopy;exports.useCounter=v.useCounter;exports.useCssVar=D.useCssVar;exports.useDebounceCallback=b.useDebounceCallback;exports.useDebounceValue=A.useDebounceValue;exports.useDefault=L.useDefault;exports.useDeviceMotion=M.useDeviceMotion;exports.useDeviceOrientation=f.useDeviceOrientation;exports.useDevicePixelRatio=h.useDevicePixelRatio;exports.useDidUpdate=_.useDidUpdate;exports.useDisclosure=N.useDisclosure;exports.useDisplayMedia=B.useDisplayMedia;exports.useDocumentEvent=K.useDocumentEvent;exports.useDocumentTitle=F.useDocumentTitle;exports.useDocumentVisibility=V.useDocumentVisibility;exports.useDoubleClick=w.useDoubleClick;exports.useElementSize=W.useElementSize;exports.useEvent=x.useEvent;exports.useEventListener=H.useEventListener;exports.useEyeDropper=U.useEyeDropper;exports.useFavicon=z.useFavicon;exports.useField=G.useField;exports.useFileDialog=Q.useFileDialog;exports.useFocus=X.useFocus;exports.useFps=j.useFps;exports.useFul=J.useFul;exports.useFullscreen=Y.useFullscreen;exports.mapGamepadToXbox360Controller=i.mapGamepadToXbox360Controller;exports.useGamepad=i.useGamepad;exports.useGeolocation=Z.useGeolocation;exports.useHash=$.useHash;exports.isHotkeyMatch=n.isHotkeyMatch;exports.useHotkeys=n.useHotkeys;exports.useHover=ee.useHover;exports.useIdle=se.useIdle;exports.useImage=ue.useImage;exports.useInfiniteScroll=re.useInfiniteScroll;exports.useIntersectionObserver=te.useIntersectionObserver;exports.useInterval=oe.useInterval;exports.useIsFirstRender=ie.useIsFirstRender;exports.useIsomorphicLayoutEffect=ne.useIsomorphicLayoutEffect;exports.useKeyboard=ce.useKeyboard;exports.useKeyPress=ae.useKeyPress;exports.useKeyPressEvent=le.useKeyPressEvent;exports.useKeysPressed=qe.useKeysPressed;exports.useLastChanged=Se.useLastChanged;exports.useLatest=de.useLatest;exports.useLess=ge.useLess;exports.useList=Te.useList;exports.useLocalStorage=Pe.useLocalStorage;exports.useLockCallback=Ce.useLockCallback;exports.useLogger=Ee.useLogger;exports.useLongPress=me.useLongPress;exports.useMap=pe.useMap;exports.useMeasure=ye.useMeasure;exports.useMediaQuery=Re.useMediaQuery;exports.useMemory=Oe.useMemory;exports.useMount=ke.useMount;exports.useMouse=Ie.useMouse;exports.useMutation=ve.useMutation;exports.useMutationObserver=De.useMutationObserver;exports.getConnection=c.getConnection;exports.useNetwork=c.useNetwork;exports.useOffsetPagination=be.useOffsetPagination;exports.useOnce=Ae.useOnce;exports.useOnline=Le.useOnline;exports.getOperatingSystem=a.getOperatingSystem;exports.useOperatingSystem=a.useOperatingSystem;exports.useOptimistic=Me.useOptimistic;exports.useOrientation=fe.useOrientation;exports.useOtpCredential=he.useOtpCredential;exports.usePageLeave=_e.usePageLeave;exports.Paint=r.Paint;exports.Pointer=r.Pointer;exports.usePaint=r.usePaint;exports.useParallax=Ne.useParallax;exports.usePerformanceObserver=Be.usePerformanceObserver;exports.usePermission=Ke.usePermission;exports.usePointerLock=Fe.usePointerLock;exports.usePostMessage=Ve.usePostMessage;exports.usePreferredColorScheme=we.usePreferredColorScheme;exports.usePreferredContrast=We.usePreferredContrast;exports.usePreferredDark=xe.usePreferredDark;exports.usePreferredLanguages=He.usePreferredLanguages;exports.usePreferredReducedMotion=Ue.usePreferredReducedMotion;exports.usePrevious=ze.usePrevious;exports.useQuery=Ge.useQuery;exports.useQueue=Qe.useQueue;exports.useRaf=Xe.useRaf;exports.useRafValue=je.useRafValue;exports.useRefState=Je.useRefState;exports.useRenderCount=Ye.useRenderCount;exports.useRenderInfo=Ze.useRenderInfo;exports.useRerender=$e.useRerender;exports.useResizeObserver=es.useResizeObserver;exports.useScreenOrientation=ss.useScreenOrientation;exports.SCRIPT_STATUS_ATTRIBUTE_NAME=l.SCRIPT_STATUS_ATTRIBUTE_NAME;exports.useScript=l.useScript;exports.useScroll=us.useScroll;exports.useScrollIntoView=rs.useScrollIntoView;exports.useScrollTo=ts.useScrollTo;exports.useSessionStorage=os.useSessionStorage;exports.useSet=is.useSet;exports.useShare=ns.useShare;exports.getSpeechRecognition=q.getSpeechRecognition;exports.useSpeechRecognition=q.useSpeechRecognition;exports.useSpeechSynthesis=cs.useSpeechSynthesis;exports.useStateHistory=as.useStateHistory;exports.useStep=ls.useStep;exports.useSticky=qs.useSticky;exports.useStopwatch=Ss.useStopwatch;exports.STORAGE_EVENT=t.STORAGE_EVENT;exports.dispatchStorageEvent=t.dispatchStorageEvent;exports.useStorage=t.useStorage;exports.useTextDirection=ds.useTextDirection;exports.getRangesSelection=S.getRangesSelection;exports.useTextSelection=S.useTextSelection;exports.useThrottleCallback=gs.useThrottleCallback;exports.useThrottleValue=Ts.useThrottleValue;exports.useTime=Ps.useTime;exports.useTimeout=Cs.useTimeout;exports.getTimeFromSeconds=d.getTimeFromSeconds;exports.useTimer=d.useTimer;exports.useToggle=Es.useToggle;exports.useUnmount=ms.useUnmount;exports.useVibrate=ps.useVibrate;exports.useWakeLock=ys.useWakeLock;exports.useWebSocket=Rs.useWebSocket;exports.useWindowEvent=Os.useWindowEvent;exports.useWindowFocus=ks.useWindowFocus;exports.scrollTo=g.scrollTo;exports.useWindowScroll=g.useWindowScroll;exports.useWindowSize=Is.useWindowSize;exports.useWizard=vs.useWizard;exports.copy=T.copy;exports.legacyCopyToClipboard=T.legacyCopyToClipboard;exports.debounce=Ds.debounce;exports.getDate=bs.getDate;exports.getElement=o.getElement;exports.target=o.target;exports.targetSymbol=o.targetSymbol;exports.getRetry=As.getRetry;exports.isTarget=Ls.isTarget;exports.throttle=Ms.throttle;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useActiveElement.mjs","sources":["../../../../src/hooks/useActiveElement/useActiveElement.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\n/**\n * @name useActiveElement\n * @description - Hook that returns the active element\n * @category Elements\n *\n * @returns {ActiveElement | null} The active element\n *\n * @example\n * const activeElement = useActiveElement();\n */\nexport const useActiveElement = <ActiveElement extends HTMLElement>() => {\n const [activeElement, setActiveElement] = useState<ActiveElement | null>(null);\n\n useEffect(() => {\n const onActiveElementChange = () =>\n setActiveElement(document?.activeElement as ActiveElement | null);\n\n window.addEventListener('focus', onActiveElementChange, true);\n window.addEventListener('blur', onActiveElementChange, true);\n\n return () => {\n window.removeEventListener('focus', onActiveElementChange, true);\n window.removeEventListener('blur', onActiveElementChange, true);\n };\n });\n\n useEffect(() => {\n const observer = new MutationObserver((mutations) => {\n mutations\n .filter((mutation) => mutation.removedNodes.length)\n .map((mutation) => Array.from(mutation.removedNodes))\n .flat()\n .forEach((node) => {\n setActiveElement((prevActiveElement) => {\n if (node === prevActiveElement) return document.activeElement as ActiveElement | null;\n return prevActiveElement;\n });\n });\n });\n\n observer.observe(document, {\n childList: true,\n subtree: true\n });\n\n return () => {\n observer.disconnect();\n };\n }, []);\n\n return activeElement;\n};\n"],"names":["useActiveElement","activeElement","setActiveElement","useState","useEffect","onActiveElementChange","observer","mutations","mutation","node","prevActiveElement"],"mappings":";
|
|
1
|
+
{"version":3,"file":"useActiveElement.mjs","sources":["../../../../src/hooks/useActiveElement/useActiveElement.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\n/**\n * @name useActiveElement\n * @description - Hook that returns the active element\n * @category Elements\n *\n * @returns {ActiveElement | null} The active element\n *\n * @example\n * const activeElement = useActiveElement();\n *\n * @see {@link https://siberiacancode.github.io/reactuse/functions/hooks/useActiveElement.html}\n */\nexport const useActiveElement = <ActiveElement extends HTMLElement>() => {\n const [activeElement, setActiveElement] = useState<ActiveElement | null>(null);\n\n useEffect(() => {\n const onActiveElementChange = () =>\n setActiveElement(document?.activeElement as ActiveElement | null);\n\n window.addEventListener('focus', onActiveElementChange, true);\n window.addEventListener('blur', onActiveElementChange, true);\n\n return () => {\n window.removeEventListener('focus', onActiveElementChange, true);\n window.removeEventListener('blur', onActiveElementChange, true);\n };\n });\n\n useEffect(() => {\n const observer = new MutationObserver((mutations) => {\n mutations\n .filter((mutation) => mutation.removedNodes.length)\n .map((mutation) => Array.from(mutation.removedNodes))\n .flat()\n .forEach((node) => {\n setActiveElement((prevActiveElement) => {\n if (node === prevActiveElement) return document.activeElement as ActiveElement | null;\n return prevActiveElement;\n });\n });\n });\n\n observer.observe(document, {\n childList: true,\n subtree: true\n });\n\n return () => {\n observer.disconnect();\n };\n }, []);\n\n return activeElement;\n};\n"],"names":["useActiveElement","activeElement","setActiveElement","useState","useEffect","onActiveElementChange","observer","mutations","mutation","node","prevActiveElement"],"mappings":";AAcO,MAAMA,IAAmB,MAAyC;AACvE,QAAM,CAACC,GAAeC,CAAgB,IAAIC,EAA+B,IAAI;AAE7E,SAAAC,EAAU,MAAM;AACd,UAAMC,IAAwB,MAC5BH,EAAiB,qCAAU,aAAqC;AAE3D,kBAAA,iBAAiB,SAASG,GAAuB,EAAI,GACrD,OAAA,iBAAiB,QAAQA,GAAuB,EAAI,GAEpD,MAAM;AACJ,aAAA,oBAAoB,SAASA,GAAuB,EAAI,GACxD,OAAA,oBAAoB,QAAQA,GAAuB,EAAI;AAAA,IAChE;AAAA,EAAA,CACD,GAEDD,EAAU,MAAM;AACd,UAAME,IAAW,IAAI,iBAAiB,CAACC,MAAc;AAEhD,MAAAA,EAAA,OAAO,CAACC,MAAaA,EAAS,aAAa,MAAM,EACjD,IAAI,CAACA,MAAa,MAAM,KAAKA,EAAS,YAAY,CAAC,EACnD,OACA,QAAQ,CAACC,MAAS;AACjB,QAAAP,EAAiB,CAACQ,MACZD,MAASC,IAA0B,SAAS,gBACzCA,CACR;AAAA,MAAA,CACF;AAAA,IAAA,CACJ;AAED,WAAAJ,EAAS,QAAQ,UAAU;AAAA,MACzB,WAAW;AAAA,MACX,SAAS;AAAA,IAAA,CACV,GAEM,MAAM;AACX,MAAAA,EAAS,WAAW;AAAA,IACtB;AAAA,EACF,GAAG,EAAE,GAEEL;AACT;"}
|
|
@@ -1,18 +1,19 @@
|
|
|
1
|
-
import { useRef as
|
|
2
|
-
import { useIsomorphicLayoutEffect as
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
if (
|
|
12
|
-
return
|
|
1
|
+
import { useRef as u } from "react";
|
|
2
|
+
import { useIsomorphicLayoutEffect as e } from "../useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.mjs";
|
|
3
|
+
const s = (t, o) => {
|
|
4
|
+
const r = u(!1);
|
|
5
|
+
e(
|
|
6
|
+
() => () => {
|
|
7
|
+
r.current = !1;
|
|
8
|
+
},
|
|
9
|
+
[]
|
|
10
|
+
), e(() => {
|
|
11
|
+
if (r.current)
|
|
12
|
+
return t();
|
|
13
|
+
r.current = !0;
|
|
13
14
|
}, o);
|
|
14
15
|
};
|
|
15
16
|
export {
|
|
16
|
-
|
|
17
|
+
s as useDidUpdate
|
|
17
18
|
};
|
|
18
19
|
//# sourceMappingURL=useDidUpdate.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDidUpdate.mjs","sources":["../../../../src/hooks/useDidUpdate/useDidUpdate.ts"],"sourcesContent":["import type { DependencyList, EffectCallback } from 'react';\n\nimport { useRef } from 'react';\n\nimport { useIsomorphicLayoutEffect } from '../useIsomorphicLayoutEffect/useIsomorphicLayoutEffect';\n\n/**\n * @name useDidUpdate\n * @description – Hook that triggers the effect callback on updates\n * @category Lifecycle\n *\n * @param {EffectCallback} effect The effect callback\n * @param {DependencyList} [deps] The dependencies list for the effect\n *\n * @example\n * useDidUpdate(() => console.log(\"effect runs on updates\"),
|
|
1
|
+
{"version":3,"file":"useDidUpdate.mjs","sources":["../../../../src/hooks/useDidUpdate/useDidUpdate.ts"],"sourcesContent":["import type { DependencyList, EffectCallback } from 'react';\r\n\r\nimport { useRef } from 'react';\r\n\r\nimport { useIsomorphicLayoutEffect } from '../useIsomorphicLayoutEffect/useIsomorphicLayoutEffect';\r\n\r\n/**\r\n * @name useDidUpdate\r\n * @description – Hook that triggers the effect callback on updates\r\n * @category Lifecycle\r\n *\r\n * @param {EffectCallback} effect The effect callback\r\n * @param {DependencyList} [deps] The dependencies list for the effect\r\n *\r\n * @example\r\n * useDidUpdate(() => console.log(\"effect runs on updates\"), deps);\r\n */\r\nexport const useDidUpdate = (effect: EffectCallback, deps?: DependencyList) => {\r\n const mounted = useRef(false);\r\n\r\n useIsomorphicLayoutEffect(\r\n () => () => {\r\n mounted.current = false;\r\n },\r\n []\r\n );\r\n\r\n useIsomorphicLayoutEffect(() => {\r\n if (mounted.current) {\r\n return effect();\r\n }\r\n\r\n mounted.current = true;\r\n return undefined;\r\n }, deps);\r\n};\r\n"],"names":["useDidUpdate","effect","deps","mounted","useRef","useIsomorphicLayoutEffect"],"mappings":";;AAiBa,MAAAA,IAAe,CAACC,GAAwBC,MAA0B;AACvE,QAAAC,IAAUC,EAAO,EAAK;AAE5B,EAAAC;AAAA,IACE,MAAM,MAAM;AACV,MAAAF,EAAQ,UAAU;AAAA,IACpB;AAAA,IACA,CAAA;AAAA,EACF,GAEAE,EAA0B,MAAM;AAC9B,QAAIF,EAAQ;AACV,aAAOF,EAAO;AAGhB,IAAAE,EAAQ,UAAU;AAAA,KAEjBD,CAAI;AACT;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDoubleClick.mjs","sources":["../../../../src/hooks/useDoubleClick/useDoubleClick.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 type DoubleClickEvents = MouseEvent | TouchEvent;\n\n// * The use double click options type */\nexport interface UseDoubleClickOptions {\n // * The threshold time in milliseconds between clicks\n threshold?: number;\n // * The callback function to be invoked on single click\n onSingleClick?: (event: DoubleClickEvents) => void;\n}\n\nexport interface UseDoubleClick {\n (\n target: HookTarget,\n callback: (event: DoubleClickEvents) => void,\n options?: UseDoubleClickOptions\n ): boolean;\n\n <Target extends Element>(\n callback: (event: DoubleClickEvents) => void,\n options?: UseDoubleClickOptions,\n target?: never\n ):
|
|
1
|
+
{"version":3,"file":"useDoubleClick.mjs","sources":["../../../../src/hooks/useDoubleClick/useDoubleClick.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 type DoubleClickEvents = MouseEvent | TouchEvent;\n\n// * The use double click options type */\nexport interface UseDoubleClickOptions {\n // * The threshold time in milliseconds between clicks\n threshold?: number;\n // * The callback function to be invoked on single click\n onSingleClick?: (event: DoubleClickEvents) => void;\n}\n\nexport interface UseDoubleClick {\n (\n target: HookTarget,\n callback: (event: DoubleClickEvents) => void,\n options?: UseDoubleClickOptions\n ): boolean;\n\n <Target extends Element>(\n callback: (event: DoubleClickEvents) => void,\n options?: UseDoubleClickOptions,\n target?: never\n ): StateRef<Target>;\n}\n\nconst DEFAULT_THRESHOLD_TIME = 300;\n\n/**\n * @name useDoubleClick\n * @description - Hook that defines the logic when double clicking an element\n * @category Sensors\n *\n * @overload\n * @param {HookTarget} target The target element to be double clicked\n * @param {(event: DoubleClickEvents) => void} callback The callback function to be invoked on double click\n * @param {UseDoubleClickOptions} [options] The options for the double click\n * @returns {boolean} The double clicking state\n *\n * @example\n * useDoubleClick(ref, () => console.log('double clicked'));\n *\n * @overload\n * @template Target The target element\n * @param {(event: DoubleClickEvents) => void} callback The callback function to be invoked on double click\n * @param {UseDoubleClickOptions} [options] The options for the double click\n * @returns {boolean} The double clicking state\n *\n * @example\n * const ref = useDoubleClick(() => console.log('double clicked'));\n *\n * @see {@link https://siberiacancode.github.io/reactuse/functions/hooks/useDoubleClick.html}\n */\nexport const useDoubleClick = ((...params: any[]): any => {\n const target = (isTarget(params[0]) ? params[0] : undefined) as HookTarget | undefined;\n const callback = (target ? params[1] : params[0]) as (event: DoubleClickEvents) => void;\n const options = (target ? params[2] : params[1]) as UseDoubleClickOptions | undefined;\n\n const timeoutIdRef = useRef<ReturnType<typeof setTimeout>>();\n const clickCountRef = useRef(0);\n const internalRef = useRefState<Element>();\n\n const internalCallbackRef = useRef(callback);\n internalCallbackRef.current = callback;\n const internalOptionsRef = useRef(options);\n internalOptionsRef.current = options;\n\n useEffect(() => {\n if (!target && !internalRef.state) return;\n\n const element = target ? getElement(target) : internalRef.current;\n if (!element) return;\n\n const onClick = (event: DoubleClickEvents) => {\n clickCountRef.current += 1;\n\n if (clickCountRef.current === 1) {\n timeoutIdRef.current = setTimeout(() => {\n if (internalOptionsRef.current?.onSingleClick)\n internalOptionsRef.current.onSingleClick(event);\n clickCountRef.current = 0;\n }, internalOptionsRef.current?.threshold ?? DEFAULT_THRESHOLD_TIME);\n }\n\n if (clickCountRef.current === 2) {\n clearTimeout(timeoutIdRef.current);\n internalCallbackRef.current(event);\n clickCountRef.current = 0;\n }\n };\n\n element.addEventListener('mousedown', onClick as EventListener);\n element.addEventListener('touchstart', onClick as EventListener);\n\n return () => {\n element.removeEventListener('mousedown', onClick as EventListener);\n element.removeEventListener('touchstart', onClick as EventListener);\n if (timeoutIdRef.current) clearTimeout(timeoutIdRef.current);\n };\n }, [target, internalRef.state]);\n\n if (target) return;\n return internalRef;\n}) as UseDoubleClick;\n"],"names":["DEFAULT_THRESHOLD_TIME","useDoubleClick","params","target","isTarget","callback","options","timeoutIdRef","useRef","clickCountRef","internalRef","useRefState","internalCallbackRef","internalOptionsRef","useEffect","element","getElement","onClick","event","_a"],"mappings":";;;;AAkCA,MAAMA,IAAyB,KA2BlBC,IAAkB,IAAIC,MAAuB;AAClD,QAAAC,IAAUC,EAASF,EAAO,CAAC,CAAC,IAAIA,EAAO,CAAC,IAAI,QAC5CG,IAAYF,IAASD,EAAO,CAAC,IAAIA,EAAO,CAAC,GACzCI,IAAWH,IAASD,EAAO,CAAC,IAAIA,EAAO,CAAC,GAExCK,IAAeC,EAAsC,GACrDC,IAAgBD,EAAO,CAAC,GACxBE,IAAcC,EAAqB,GAEnCC,IAAsBJ,EAAOH,CAAQ;AAC3C,EAAAO,EAAoB,UAAUP;AACxB,QAAAQ,IAAqBL,EAAOF,CAAO;AAqCzC,MApCAO,EAAmB,UAAUP,GAE7BQ,EAAU,MAAM;AACd,QAAI,CAACX,KAAU,CAACO,EAAY,MAAO;AAEnC,UAAMK,IAAUZ,IAASa,EAAWb,CAAM,IAAIO,EAAY;AAC1D,QAAI,CAACK,EAAS;AAER,UAAAE,IAAU,CAACC,MAA6B;;AAC5C,MAAAT,EAAc,WAAW,GAErBA,EAAc,YAAY,MACfF,EAAA,UAAU,WAAW,MAAM;;AACtC,SAAIY,IAAAN,EAAmB,YAAnB,QAAAM,EAA4B,iBACXN,EAAA,QAAQ,cAAcK,CAAK,GAChDT,EAAc,UAAU;AAAA,MACvB,KAAAU,IAAAN,EAAmB,YAAnB,gBAAAM,EAA4B,cAAanB,CAAsB,IAGhES,EAAc,YAAY,MAC5B,aAAaF,EAAa,OAAO,GACjCK,EAAoB,QAAQM,CAAK,GACjCT,EAAc,UAAU;AAAA,IAE5B;AAEQ,WAAAM,EAAA,iBAAiB,aAAaE,CAAwB,GACtDF,EAAA,iBAAiB,cAAcE,CAAwB,GAExD,MAAM;AACH,MAAAF,EAAA,oBAAoB,aAAaE,CAAwB,GACzDF,EAAA,oBAAoB,cAAcE,CAAwB,GAC9DV,EAAa,WAAsB,aAAAA,EAAa,OAAO;AAAA,IAC7D;AAAA,EACC,GAAA,CAACJ,GAAQO,EAAY,KAAK,CAAC,GAE1B,CAAAP;AACG,WAAAO;AACT;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFul.mjs","sources":["../../../../src/hooks/useFul/useFul.ts"],"sourcesContent":["import { useEffect } from 'react';\n\n/**\n * @name useFul\n * @description - Hook that can be so useful\n * @category Humor\n *\n * @warning - This hook is a joke. Please do not use it in production code!\n *\n * @template Value The type of the value\n * @param {Value} [value] The value to be returned\n * @returns {Value} The value passed to the hook\n *\n * @example\n * const value = useFul(state);\n */\nexport const useFul = <Value>(value?: Value) => {\n useEffect(() => {\n console.warn(\"Warning: You forgot to delete the 'useFul' hook.\");\n }, []);\n\n return value;\n};\n"],"names":["useFul","value","useEffect"],"mappings":";AAgBa,MAAAA,IAAS,CAAQC,OAC5BC,EAAU,MAAM;AACd,UAAQ,KAAK,kDAAkD;AACjE,GAAG,EAAE,GAEED;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIntersectionObserver.mjs","sources":["../../../../src/hooks/useIntersectionObserver/useIntersectionObserver.ts"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\n\nimport type { HookTarget } from '@/utils/helpers';\n\nimport { getElement, isTarget } from '@/utils/helpers';\n\nimport type { StateRef } from '../useRefState/useRefState';\n\nimport { useRefState } from '../useRefState/useRefState';\n\n/** The intersection observer options type */\nexport interface UseIntersectionObserverOptions extends Omit<IntersectionObserverInit, 'root'> {\n enabled?: boolean;\n root?: HookTarget;\n onChange?: (entry: IntersectionObserverEntry) => void;\n}\n\n/** The intersection observer return type */\nexport interface UseIntersectionObserverReturn {\n entry?: IntersectionObserverEntry;\n inView: boolean;\n}\n\nexport interface UseIntersectionObserver {\n <Target extends Element>(\n options?: UseIntersectionObserverOptions,\n target?: never\n ): UseIntersectionObserverReturn & { ref: StateRef<Target> };\n\n (target: HookTarget, options?: UseIntersectionObserverOptions): UseIntersectionObserverReturn;\n}\n\n/**\n * @name useIntersectionObserver\n * @description - Hook that gives you intersection observer state\n * @category Browser\n *\n * @overload\n * @param {HookTarget} target The target element to detect intersection\n * @param {boolean} [options.enabled=true] The IntersectionObserver options\n * @param {((entries: IntersectionObserverEntry[], observer: IntersectionObserver) => void) | undefined} [options.onChange] The callback to execute when intersection is detected\n * @param {HookTarget} [options.root] The root element to observe\n * @returns {UseIntersectionObserverReturn} An object containing the state and the supported status\n *\n * @example\n * const { ref, entry, inView } = useIntersectionObserver();\n *\n * @overload\n * @template Target The target element\n * @param {boolean} [options.enabled=true] The IntersectionObserver options\n * @param {((entries: IntersectionObserverEntry[], observer: IntersectionObserver) => void) | undefined} [options.onChange] The callback to execute when intersection is detected\n * @param {HookTarget} [options.root] The root element to observe\n * @returns {UseIntersectionObserverReturn & { ref: StateRef<Target> }} A React ref to attach to the target element\n *\n * @example\n * const { entry, inView } = useIntersectionObserver(ref);\n */\nexport const useIntersectionObserver = ((...params: any[]) => {\n const target = (isTarget(params[0]) ? params[0] : undefined) as HookTarget | undefined;\n const options = (target ? params[1] : params[0]) as UseIntersectionObserverOptions | undefined;\n const enabled = options?.enabled ?? true;\n\n const [entry, setEntry] = useState<IntersectionObserverEntry>();\n\n const internalRef = useRefState<Element>();\n const internalOnChangeRef = useRef<UseIntersectionObserverOptions['onChange']>(options?.onChange);\n internalOnChangeRef.current = options?.onChange;\n\n useEffect(() => {\n if (!enabled && !target && !internalRef.state) return;\n\n const element = target ? getElement(target) : internalRef.current;\n if (!element) return;\n\n const observer = new IntersectionObserver(\n ([entry]) => {\n setEntry(entry);\n internalOnChangeRef.current?.(entry);\n },\n {\n ...options,\n root: options?.root ? (getElement(options.root) as Document | Element) : document\n }\n );\n\n observer.observe(element as Element);\n\n return () => {\n observer.disconnect();\n };\n }, [target, internalRef.state, options?.rootMargin, options?.threshold, options?.root, enabled]);\n\n if (target) return { entry, inView: !!entry?.isIntersecting };\n return {\n ref: internalRef,\n entry,\n inView: !!entry?.isIntersecting\n };\n}) as UseIntersectionObserver;\n"],"names":["useIntersectionObserver","params","target","isTarget","options","enabled","entry","setEntry","useState","internalRef","useRefState","internalOnChangeRef","useRef","useEffect","element","getElement","observer","_a"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"useIntersectionObserver.mjs","sources":["../../../../src/hooks/useIntersectionObserver/useIntersectionObserver.ts"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\n\nimport type { HookTarget } from '@/utils/helpers';\n\nimport { getElement, isTarget } from '@/utils/helpers';\n\nimport type { StateRef } from '../useRefState/useRefState';\n\nimport { useRefState } from '../useRefState/useRefState';\n\n/** The intersection observer options type */\nexport interface UseIntersectionObserverOptions extends Omit<IntersectionObserverInit, 'root'> {\n enabled?: boolean;\n root?: HookTarget;\n onChange?: (entry: IntersectionObserverEntry) => void;\n}\n\n/** The intersection observer return type */\nexport interface UseIntersectionObserverReturn {\n entry?: IntersectionObserverEntry;\n inView: boolean;\n}\n\nexport interface UseIntersectionObserver {\n <Target extends Element>(\n options?: UseIntersectionObserverOptions,\n target?: never\n ): UseIntersectionObserverReturn & { ref: StateRef<Target> };\n\n (target: HookTarget, options?: UseIntersectionObserverOptions): UseIntersectionObserverReturn;\n}\n\n/**\n * @name useIntersectionObserver\n * @description - Hook that gives you intersection observer state\n * @category Browser\n *\n * @browserapi IntersectionObserver https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserver\n *\n * @overload\n * @param {HookTarget} target The target element to detect intersection\n * @param {boolean} [options.enabled=true] The IntersectionObserver options\n * @param {((entries: IntersectionObserverEntry[], observer: IntersectionObserver) => void) | undefined} [options.onChange] The callback to execute when intersection is detected\n * @param {HookTarget} [options.root] The root element to observe\n * @returns {UseIntersectionObserverReturn} An object containing the state and the supported status\n *\n * @example\n * const { ref, entry, inView } = useIntersectionObserver();\n *\n * @overload\n * @template Target The target element\n * @param {boolean} [options.enabled=true] The IntersectionObserver options\n * @param {((entries: IntersectionObserverEntry[], observer: IntersectionObserver) => void) | undefined} [options.onChange] The callback to execute when intersection is detected\n * @param {HookTarget} [options.root] The root element to observe\n * @returns {UseIntersectionObserverReturn & { ref: StateRef<Target> }} A React ref to attach to the target element\n *\n * @example\n * const { entry, inView } = useIntersectionObserver(ref);\n */\nexport const useIntersectionObserver = ((...params: any[]) => {\n const target = (isTarget(params[0]) ? params[0] : undefined) as HookTarget | undefined;\n const options = (target ? params[1] : params[0]) as UseIntersectionObserverOptions | undefined;\n const enabled = options?.enabled ?? true;\n\n const [entry, setEntry] = useState<IntersectionObserverEntry>();\n\n const internalRef = useRefState<Element>();\n const internalOnChangeRef = useRef<UseIntersectionObserverOptions['onChange']>(options?.onChange);\n internalOnChangeRef.current = options?.onChange;\n\n useEffect(() => {\n if (!enabled && !target && !internalRef.state) return;\n\n const element = target ? getElement(target) : internalRef.current;\n if (!element) return;\n\n const observer = new IntersectionObserver(\n ([entry]) => {\n setEntry(entry);\n internalOnChangeRef.current?.(entry);\n },\n {\n ...options,\n root: options?.root ? (getElement(options.root) as Document | Element) : document\n }\n );\n\n observer.observe(element as Element);\n\n return () => {\n observer.disconnect();\n };\n }, [target, internalRef.state, options?.rootMargin, options?.threshold, options?.root, enabled]);\n\n if (target) return { entry, inView: !!entry?.isIntersecting };\n return {\n ref: internalRef,\n entry,\n inView: !!entry?.isIntersecting\n };\n}) as UseIntersectionObserver;\n"],"names":["useIntersectionObserver","params","target","isTarget","options","enabled","entry","setEntry","useState","internalRef","useRefState","internalOnChangeRef","useRef","useEffect","element","getElement","observer","_a"],"mappings":";;;;AA2Da,MAAAA,IAA2B,IAAIC,MAAkB;AACtD,QAAAC,IAAUC,EAASF,EAAO,CAAC,CAAC,IAAIA,EAAO,CAAC,IAAI,QAC5CG,IAAWF,IAASD,EAAO,CAAC,IAAIA,EAAO,CAAC,GACxCI,KAAUD,KAAA,gBAAAA,EAAS,YAAW,IAE9B,CAACE,GAAOC,CAAQ,IAAIC,EAAoC,GAExDC,IAAcC,EAAqB,GACnCC,IAAsBC,EAAmDR,KAAA,gBAAAA,EAAS,QAAQ;AA2B5F,SA1BJO,EAAoB,UAAUP,KAAA,gBAAAA,EAAS,UAEvCS,EAAU,MAAM;AACd,QAAI,CAACR,KAAW,CAACH,KAAU,CAACO,EAAY,MAAO;AAE/C,UAAMK,IAAUZ,IAASa,EAAWb,CAAM,IAAIO,EAAY;AAC1D,QAAI,CAACK,EAAS;AAEd,UAAME,IAAW,IAAI;AAAA,MACnB,CAAC,CAACV,CAAK,MAAM;;AACX,QAAAC,EAASD,CAAK,IACdW,IAAAN,EAAoB,YAApB,QAAAM,EAAA,KAAAN,GAA8BL;AAAAA,MAChC;AAAA,MACA;AAAA,QACE,GAAGF;AAAA,QACH,MAAMA,KAAA,QAAAA,EAAS,OAAQW,EAAWX,EAAQ,IAAI,IAA2B;AAAA,MAAA;AAAA,IAE7E;AAEA,WAAAY,EAAS,QAAQF,CAAkB,GAE5B,MAAM;AACX,MAAAE,EAAS,WAAW;AAAA,IACtB;AAAA,EACC,GAAA,CAACd,GAAQO,EAAY,OAAOL,KAAA,gBAAAA,EAAS,YAAYA,KAAA,gBAAAA,EAAS,WAAWA,KAAA,gBAAAA,EAAS,MAAMC,CAAO,CAAC,GAE3FH,IAAe,EAAE,OAAAI,GAAO,QAAQ,CAAC,EAACA,KAAA,QAAAA,EAAO,gBAAe,IACrD;AAAA,IACL,KAAKG;AAAA,IACL,OAAAH;AAAA,IACA,QAAQ,CAAC,EAACA,KAAA,QAAAA,EAAO;AAAA,EACnB;AACF;"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { useState as i, useRef as x, useEffect as P } from "react";
|
|
2
|
+
const q = (S = {}) => {
|
|
3
|
+
const r = typeof window < "u" && "speechSynthesis" in window, { text: c = "", lang: a = "en-US", pitch: p = 1, rate: l = 1, voice: w = null, volume: f = 1 } = S, [d, s] = i(!1), [y, u] = i("init"), [m, g] = i(), t = x(null), h = (e) => {
|
|
4
|
+
e.lang = a, e.pitch = p, e.rate = l, e.volume = f, e.voice = w, e.onstart = () => {
|
|
5
|
+
s(!0), u("play");
|
|
6
|
+
}, e.onpause = () => {
|
|
7
|
+
s(!1), u("pause");
|
|
8
|
+
}, e.onresume = () => {
|
|
9
|
+
s(!0), u("play");
|
|
10
|
+
}, e.onend = () => {
|
|
11
|
+
s(!1), u("end");
|
|
12
|
+
}, e.onerror = (n) => {
|
|
13
|
+
s(!1), g(n);
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
P(() => {
|
|
17
|
+
if (!r) return;
|
|
18
|
+
const e = new SpeechSynthesisUtterance(c);
|
|
19
|
+
return h(e), t.current = e, () => {
|
|
20
|
+
var n;
|
|
21
|
+
(n = window.speechSynthesis) == null || n.cancel();
|
|
22
|
+
};
|
|
23
|
+
}, [c, a, p, l, w, f]);
|
|
24
|
+
const v = (e) => {
|
|
25
|
+
var n, o;
|
|
26
|
+
r && (e && (t.current = new SpeechSynthesisUtterance(e), h(t.current)), (n = window.speechSynthesis) == null || n.cancel(), t.current && ((o = window.speechSynthesis) == null || o.speak(t.current)));
|
|
27
|
+
}, k = () => {
|
|
28
|
+
var e;
|
|
29
|
+
r && ((e = window.speechSynthesis) == null || e.cancel(), s(!1));
|
|
30
|
+
}, E = (e = !d) => {
|
|
31
|
+
var n, o;
|
|
32
|
+
r && (e ? (n = window.speechSynthesis) == null || n.resume() : (o = window.speechSynthesis) == null || o.pause(), s(e));
|
|
33
|
+
}, R = () => {
|
|
34
|
+
var e;
|
|
35
|
+
s(!0), (e = window.speechSynthesis) == null || e.resume();
|
|
36
|
+
}, b = () => {
|
|
37
|
+
var e;
|
|
38
|
+
s(!1), (e = window.speechSynthesis) == null || e.pause();
|
|
39
|
+
};
|
|
40
|
+
return {
|
|
41
|
+
supported: r,
|
|
42
|
+
playing: d,
|
|
43
|
+
status: y,
|
|
44
|
+
utterance: t.current,
|
|
45
|
+
error: m,
|
|
46
|
+
stop: k,
|
|
47
|
+
toggle: E,
|
|
48
|
+
speak: v,
|
|
49
|
+
resume: R,
|
|
50
|
+
pause: b
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
export {
|
|
54
|
+
q as useSpeechSynthesis
|
|
55
|
+
};
|
|
56
|
+
//# sourceMappingURL=useSpeechSynthesis.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSpeechSynthesis.mjs","sources":["../../../../src/hooks/useSpeechSynthesis/useSpeechSynthesis.ts"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\n\n/** The use speech synthesis status type */\nexport type UseSpeechSynthesisStatus = 'end' | 'init' | 'pause' | 'play';\n\n/** The use speech synthesis options type */\nexport interface UseSpeechSynthesisOptions {\n /** Language for SpeechSynthesis */\n lang?: string;\n /** Gets and sets the pitch at which the utterance will be spoken at. */\n pitch?: number;\n /** Gets and sets the speed at which the utterance will be spoken at. */\n rate?: number;\n /** The text to be spoken */\n text?: string;\n /** Gets and sets the voice that will be used to speak the utterance. */\n voice?: SpeechSynthesisVoice | null;\n /** Gets and sets the volume that the utterance will be spoken at. */\n volume?: number;\n}\n\n/** The use speech synthesis return type */\nexport interface UseSpeechSynthesisReturn {\n /** Any error that occurred during speech synthesis. */\n error: SpeechSynthesisErrorEvent | undefined;\n /** Indicates if speech is currently playing. */\n playing: boolean;\n /** The current status of speech synthesis. */\n status: UseSpeechSynthesisStatus;\n /** Indicates if the SpeechSynthesis API is supported in the current environment. */\n supported: boolean;\n /** The SpeechSynthesisUtterance instance. */\n utterance: SpeechSynthesisUtterance | null;\n /** Function to pause speech synthesis. */\n pause: () => void;\n /** Function to resume speech synthesis. */\n resume: () => void;\n /** Function to start speech synthesis. */\n speak: () => void;\n /** Function to stop speech synthesis. */\n stop: () => void;\n /** Function to toggle between play and pause. */\n toggle: (value?: boolean) => void;\n}\n\n/**\n * @name useSpeechSynthesis\n * @description - Hook that provides speech synthesis functionality\n * @category Sensors\n *\n * @browserapi SpeechSynthesis https://developer.mozilla.org/en-US/docs/Web/API/SpeechSynthesis\n *\n * @params {string} [options.text] - The text to be spoken\n * @params {string} [options.lang] - The language to be spoken\n * @params {number} [options.pitch] - The pitch to be spoken\n * @params {number} [options.rate] - The rate to be spoken\n * @params {SpeechSynthesisVoice} [options.voice] - The voice to be spoken\n * @params {number} [options.volume] - The volume to be spoken\n * @returns {UseSpeechSynthesisReturn} An object containing the speech synthesis state and control methods\n *\n * @example\n * const { supported, playing, status, utterance, error, stop, toggle, speak, resume, pause } = useSpeechSynthesis();\n */\nexport const useSpeechSynthesis = (\n options: UseSpeechSynthesisOptions = {}\n): UseSpeechSynthesisReturn => {\n const supported = typeof window !== 'undefined' && 'speechSynthesis' in window;\n\n const { text = '', lang = 'en-US', pitch = 1, rate = 1, voice = null, volume = 1 } = options;\n\n const [playing, setPlaying] = useState(false);\n const [status, setStatus] = useState<UseSpeechSynthesisStatus>('init');\n const [error, setError] = useState<SpeechSynthesisErrorEvent>();\n const speechSynthesisUtteranceRef = useRef<SpeechSynthesisUtterance | null>(null);\n\n const bindSpeechSynthesisUtterance = (speechSynthesisUtterance: SpeechSynthesisUtterance) => {\n speechSynthesisUtterance.lang = lang;\n speechSynthesisUtterance.pitch = pitch;\n speechSynthesisUtterance.rate = rate;\n speechSynthesisUtterance.volume = volume;\n speechSynthesisUtterance.voice = voice;\n\n speechSynthesisUtterance.onstart = () => {\n setPlaying(true);\n setStatus('play');\n };\n\n speechSynthesisUtterance.onpause = () => {\n setPlaying(false);\n setStatus('pause');\n };\n\n speechSynthesisUtterance.onresume = () => {\n setPlaying(true);\n setStatus('play');\n };\n\n speechSynthesisUtterance.onend = () => {\n setPlaying(false);\n setStatus('end');\n };\n\n speechSynthesisUtterance.onerror = (event) => {\n setPlaying(false);\n setError(event);\n };\n };\n\n useEffect(() => {\n if (!supported) return;\n\n const speechSynthesisUtterance = new SpeechSynthesisUtterance(text);\n bindSpeechSynthesisUtterance(speechSynthesisUtterance);\n speechSynthesisUtteranceRef.current = speechSynthesisUtterance;\n\n return () => {\n window.speechSynthesis?.cancel();\n };\n }, [text, lang, pitch, rate, voice, volume]);\n\n const speak = (text?: string) => {\n if (!supported) return;\n\n if (text) {\n speechSynthesisUtteranceRef.current = new SpeechSynthesisUtterance(text);\n bindSpeechSynthesisUtterance(speechSynthesisUtteranceRef.current);\n }\n\n window.speechSynthesis?.cancel();\n if (speechSynthesisUtteranceRef.current)\n window.speechSynthesis?.speak(speechSynthesisUtteranceRef.current);\n };\n\n const stop = () => {\n if (!supported) return;\n\n window.speechSynthesis?.cancel();\n setPlaying(false);\n };\n\n const toggle = (value = !playing) => {\n if (!supported) return;\n\n if (value) {\n window.speechSynthesis?.resume();\n } else {\n window.speechSynthesis?.pause();\n }\n setPlaying(value);\n };\n\n const resume = () => {\n setPlaying(true);\n window.speechSynthesis?.resume();\n };\n\n const pause = () => {\n setPlaying(false);\n window.speechSynthesis?.pause();\n };\n\n return {\n supported,\n playing,\n status,\n utterance: speechSynthesisUtteranceRef.current,\n error,\n\n stop,\n toggle,\n speak,\n resume,\n pause\n };\n};\n"],"names":["useSpeechSynthesis","options","supported","text","lang","pitch","rate","voice","volume","playing","setPlaying","useState","status","setStatus","error","setError","speechSynthesisUtteranceRef","useRef","bindSpeechSynthesisUtterance","speechSynthesisUtterance","event","useEffect","_a","speak","_b","stop","toggle","value","resume","pause"],"mappings":";AA+DO,MAAMA,IAAqB,CAChCC,IAAqC,OACR;AAC7B,QAAMC,IAAY,OAAO,SAAW,OAAe,qBAAqB,QAElE,EAAE,MAAAC,IAAO,IAAI,MAAAC,IAAO,SAAS,OAAAC,IAAQ,GAAG,MAAAC,IAAO,GAAG,OAAAC,IAAQ,MAAM,QAAAC,IAAS,EAAM,IAAAP,GAE/E,CAACQ,GAASC,CAAU,IAAIC,EAAS,EAAK,GACtC,CAACC,GAAQC,CAAS,IAAIF,EAAmC,MAAM,GAC/D,CAACG,GAAOC,CAAQ,IAAIJ,EAAoC,GACxDK,IAA8BC,EAAwC,IAAI,GAE1EC,IAA+B,CAACC,MAAuD;AAC3F,IAAAA,EAAyB,OAAOf,GAChCe,EAAyB,QAAQd,GACjCc,EAAyB,OAAOb,GAChCa,EAAyB,SAASX,GAClCW,EAAyB,QAAQZ,GAEjCY,EAAyB,UAAU,MAAM;AACvC,MAAAT,EAAW,EAAI,GACfG,EAAU,MAAM;AAAA,IAClB,GAEAM,EAAyB,UAAU,MAAM;AACvC,MAAAT,EAAW,EAAK,GAChBG,EAAU,OAAO;AAAA,IACnB,GAEAM,EAAyB,WAAW,MAAM;AACxC,MAAAT,EAAW,EAAI,GACfG,EAAU,MAAM;AAAA,IAClB,GAEAM,EAAyB,QAAQ,MAAM;AACrC,MAAAT,EAAW,EAAK,GAChBG,EAAU,KAAK;AAAA,IACjB,GAEyBM,EAAA,UAAU,CAACC,MAAU;AAC5C,MAAAV,EAAW,EAAK,GAChBK,EAASK,CAAK;AAAA,IAChB;AAAA,EACF;AAEA,EAAAC,EAAU,MAAM;AACd,QAAI,CAACnB,EAAW;AAEV,UAAAiB,IAA2B,IAAI,yBAAyBhB,CAAI;AAClE,WAAAe,EAA6BC,CAAwB,GACrDH,EAA4B,UAAUG,GAE/B,MAAM;;AACX,OAAAG,IAAA,OAAO,oBAAP,QAAAA,EAAwB;AAAA,IAC1B;AAAA,EAAA,GACC,CAACnB,GAAMC,GAAMC,GAAOC,GAAMC,GAAOC,CAAM,CAAC;AAErC,QAAAe,IAAQ,CAACpB,MAAkB;;AAC/B,IAAKD,MAEDC,MAC0Ba,EAAA,UAAU,IAAI,yBAAyBb,CAAI,GACvEe,EAA6BF,EAA4B,OAAO,KAGlEM,IAAA,OAAO,oBAAP,QAAAA,EAAwB,UACpBN,EAA4B,aACvBQ,IAAA,OAAA,oBAAA,QAAAA,EAAiB,MAAMR,EAA4B;AAAA,EAC9D,GAEMS,IAAO,MAAM;;AACjB,IAAKvB,OAELoB,IAAA,OAAO,oBAAP,QAAAA,EAAwB,UACxBZ,EAAW,EAAK;AAAA,EAClB,GAEMgB,IAAS,CAACC,IAAQ,CAAClB,MAAY;;AACnC,IAAKP,MAEDyB,KACFL,IAAA,OAAO,oBAAP,QAAAA,EAAwB,YAExBE,IAAA,OAAO,oBAAP,QAAAA,EAAwB,SAE1Bd,EAAWiB,CAAK;AAAA,EAClB,GAEMC,IAAS,MAAM;;AACnB,IAAAlB,EAAW,EAAI,IACfY,IAAA,OAAO,oBAAP,QAAAA,EAAwB;AAAA,EAC1B,GAEMO,IAAQ,MAAM;;AAClB,IAAAnB,EAAW,EAAK,IAChBY,IAAA,OAAO,oBAAP,QAAAA,EAAwB;AAAA,EAC1B;AAEO,SAAA;AAAA,IACL,WAAApB;AAAA,IACA,SAAAO;AAAA,IACA,QAAAG;AAAA,IACA,WAAWI,EAA4B;AAAA,IACvC,OAAAF;AAAA,IAEA,MAAAW;AAAA,IACA,QAAAC;AAAA,IACA,OAAAH;AAAA,IACA,QAAAK;AAAA,IACA,OAAAC;AAAA,EACF;AACF;"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { useState as v, useRef as d, useEffect as f } from "react";
|
|
2
|
+
const m = (e) => {
|
|
3
|
+
const r = typeof navigator < "u" && "wakeLock" in navigator, [u, n] = v(!1), t = d(), l = (e == null ? void 0 : e.immediately) ?? !1, c = (e == null ? void 0 : e.type) ?? "screen", i = async (a) => {
|
|
4
|
+
r && (t.current = await navigator.wakeLock.request(a ?? (e == null ? void 0 : e.type)), t.current.addEventListener("release", () => {
|
|
5
|
+
n(!1), t.current = void 0;
|
|
6
|
+
}), n(!0));
|
|
7
|
+
}, s = async () => {
|
|
8
|
+
!r || !t.current || (await t.current.release(), t.current = void 0, n(!1));
|
|
9
|
+
};
|
|
10
|
+
return f(() => {
|
|
11
|
+
if (!r || !l || document.visibilityState !== "visible" || c !== "screen")
|
|
12
|
+
return;
|
|
13
|
+
const a = async () => {
|
|
14
|
+
await s(), await i(c);
|
|
15
|
+
};
|
|
16
|
+
return document.addEventListener("visibilitychange", a), () => {
|
|
17
|
+
document.removeEventListener("visibilitychange", a);
|
|
18
|
+
};
|
|
19
|
+
}, [c]), { supported: r, active: u, request: i, release: s };
|
|
20
|
+
};
|
|
21
|
+
export {
|
|
22
|
+
m as useWakeLock
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=useWakeLock.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useWakeLock.mjs","sources":["../../../../src/hooks/useWakeLock/useWakeLock.ts"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\n\n/** The use wake lock options type */\nexport interface UseWakeLockOptions {\n /** Determines if the wake lock should be automatically reacquired when the document becomes visible. */\n immediately?: boolean;\n /** A string specifying the screen wake lock type. */\n type?: WakeLockType;\n}\n\n/** The use wake lock return type */\nexport interface UseWakeLockReturn {\n /** Indicates if the wake lock is currently active. */\n active: boolean;\n /** Indicates if the Wake Lock API is supported in the current environment. */\n supported: boolean;\n /** Function to release the wake lock. */\n release: () => Promise<void>;\n /** Function to request the wake lock. */\n request: () => Promise<void>;\n}\n\n/**\n * @name useWakeLock\n * @description - Hook that provides a wake lock functionality\n * @category Browser\n *\n * @browserapi navigator.wakeLock https://developer.mozilla.org/en-US/docs/Web/API/WakeLock\n *\n * @param {immediately} [options] Configuration options for the hook.\n * @returns {UseWakeLockReturn} An object containing the wake lock state and control methods.\n *\n * @example\n * const { supported, active, request, release } = useWakeLock();\n */\nexport const useWakeLock = (options?: UseWakeLockOptions): UseWakeLockReturn => {\n const supported = typeof navigator !== 'undefined' && 'wakeLock' in navigator;\n\n const [active, setActive] = useState(false);\n const sentinel = useRef<WakeLockSentinel>();\n\n const immediately = options?.immediately ?? false;\n const type = options?.type ?? 'screen';\n\n const request = async (type?: WakeLockType) => {\n if (!supported) return;\n\n sentinel.current = await navigator.wakeLock.request(type ?? options?.type);\n sentinel.current.addEventListener('release', () => {\n setActive(false);\n sentinel.current = undefined;\n });\n\n setActive(true);\n };\n\n const release = async () => {\n if (!supported || !sentinel.current) return;\n\n await sentinel.current.release();\n sentinel.current = undefined;\n setActive(false);\n };\n\n useEffect(() => {\n if (!supported || !immediately || document.visibilityState !== 'visible' || type !== 'screen')\n return;\n\n const onVisibilityChange = async () => {\n await release();\n await request(type);\n };\n\n document.addEventListener('visibilitychange', onVisibilityChange);\n return () => {\n document.removeEventListener('visibilitychange', onVisibilityChange);\n };\n }, [type]);\n\n return { supported, active, request, release };\n};\n"],"names":["useWakeLock","options","supported","active","setActive","useState","sentinel","useRef","immediately","type","request","release","useEffect","onVisibilityChange"],"mappings":";AAmCa,MAAAA,IAAc,CAACC,MAAoD;AAC9E,QAAMC,IAAY,OAAO,YAAc,OAAe,cAAc,WAE9D,CAACC,GAAQC,CAAS,IAAIC,EAAS,EAAK,GACpCC,IAAWC,EAAyB,GAEpCC,KAAcP,KAAA,gBAAAA,EAAS,gBAAe,IACtCQ,KAAOR,KAAA,gBAAAA,EAAS,SAAQ,UAExBS,IAAU,OAAOD,MAAwB;AAC7C,IAAKP,MAELI,EAAS,UAAU,MAAM,UAAU,SAAS,QAAQG,MAAQR,KAAA,gBAAAA,EAAS,KAAI,GAChEK,EAAA,QAAQ,iBAAiB,WAAW,MAAM;AACjD,MAAAF,EAAU,EAAK,GACfE,EAAS,UAAU;AAAA,IAAA,CACpB,GAEDF,EAAU,EAAI;AAAA,EAChB,GAEMO,IAAU,YAAY;AAC1B,IAAI,CAACT,KAAa,CAACI,EAAS,YAEtB,MAAAA,EAAS,QAAQ,QAAQ,GAC/BA,EAAS,UAAU,QACnBF,EAAU,EAAK;AAAA,EACjB;AAEA,SAAAQ,EAAU,MAAM;AACd,QAAI,CAACV,KAAa,CAACM,KAAe,SAAS,oBAAoB,aAAaC,MAAS;AACnF;AAEF,UAAMI,IAAqB,YAAY;AACrC,YAAMF,EAAQ,GACd,MAAMD,EAAQD,CAAI;AAAA,IACpB;AAES,oBAAA,iBAAiB,oBAAoBI,CAAkB,GACzD,MAAM;AACF,eAAA,oBAAoB,oBAAoBA,CAAkB;AAAA,IACrE;AAAA,EAAA,GACC,CAACJ,CAAI,CAAC,GAEF,EAAE,WAAAP,GAAW,QAAAC,GAAQ,SAAAO,GAAS,SAAAC,EAAQ;AAC/C;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useWindowFocus.mjs","sources":["../../../../src/hooks/useWindowFocus/useWindowFocus.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\n/**\n * @name useWindowFocus\n * @description - Hook that provides the current focus state of the window\n * @category Elements\n *\n * @returns {boolean} The current focus state of the window\n *\n * @example\n * const focused = useWindowFocus();\n */\nexport const useWindowFocus = () => {\n const [focused, setFocused] = useState(false);\n\n useEffect(() => {\n const onFocus = () => setFocused(true);\n const onBlur = () => setFocused(false);\n\n window.addEventListener('focus', onFocus);\n window.addEventListener('blur', onBlur);\n\n return () => {\n window.removeEventListener('focus', onFocus);\n window.removeEventListener('blur', onBlur);\n };\n });\n\n return focused;\n};\n"],"names":["useWindowFocus","focused","setFocused","useState","useEffect","onFocus","onBlur"],"mappings":";
|
|
1
|
+
{"version":3,"file":"useWindowFocus.mjs","sources":["../../../../src/hooks/useWindowFocus/useWindowFocus.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\n/**\n * @name useWindowFocus\n * @description - Hook that provides the current focus state of the window\n * @category Elements\n *\n * @returns {boolean} The current focus state of the window\n *\n * @example\n * const focused = useWindowFocus();\n *\n * @see {@link https://siberiacancode.github.io/reactuse/functions/hooks/useWindowFocus.html}\n */\nexport const useWindowFocus = () => {\n const [focused, setFocused] = useState(false);\n\n useEffect(() => {\n const onFocus = () => setFocused(true);\n const onBlur = () => setFocused(false);\n\n window.addEventListener('focus', onFocus);\n window.addEventListener('blur', onBlur);\n\n return () => {\n window.removeEventListener('focus', onFocus);\n window.removeEventListener('blur', onBlur);\n };\n });\n\n return focused;\n};\n"],"names":["useWindowFocus","focused","setFocused","useState","useEffect","onFocus","onBlur"],"mappings":";AAcO,MAAMA,IAAiB,MAAM;AAClC,QAAM,CAACC,GAASC,CAAU,IAAIC,EAAS,EAAK;AAE5C,SAAAC,EAAU,MAAM;AACR,UAAAC,IAAU,MAAMH,EAAW,EAAI,GAC/BI,IAAS,MAAMJ,EAAW,EAAK;AAE9B,kBAAA,iBAAiB,SAASG,CAAO,GACjC,OAAA,iBAAiB,QAAQC,CAAM,GAE/B,MAAM;AACJ,aAAA,oBAAoB,SAASD,CAAO,GACpC,OAAA,oBAAoB,QAAQC,CAAM;AAAA,IAC3C;AAAA,EAAA,CACD,GAEML;AACT;"}
|