@siberiacancode/reactuse 0.3.5 → 0.3.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/dist/cjs/helpers/createStore/createStore.cjs +1 -1
  2. package/dist/cjs/helpers/createStore/createStore.cjs.map +1 -1
  3. package/dist/cjs/hooks/useBatchedCallback/useBatchedCallback.cjs +2 -0
  4. package/dist/cjs/hooks/useBatchedCallback/useBatchedCallback.cjs.map +1 -0
  5. package/dist/cjs/hooks/useEventListener/useEventListener.cjs +1 -1
  6. package/dist/cjs/hooks/useEventListener/useEventListener.cjs.map +1 -1
  7. package/dist/cjs/hooks/useOtpCredential/useOtpCredential.cjs +1 -1
  8. package/dist/cjs/hooks/useOtpCredential/useOtpCredential.cjs.map +1 -1
  9. package/dist/cjs/hooks/useSpeechRecognition/useSpeechRecognition.cjs +1 -1
  10. package/dist/cjs/hooks/useSpeechRecognition/useSpeechRecognition.cjs.map +1 -1
  11. package/dist/cjs/hooks/useTextareaAutosize/useTextareaAutosize.cjs +1 -1
  12. package/dist/cjs/hooks/useTextareaAutosize/useTextareaAutosize.cjs.map +1 -1
  13. package/dist/cjs/index.cjs +1 -1
  14. package/dist/esm/helpers/createStore/createStore.mjs +10 -9
  15. package/dist/esm/helpers/createStore/createStore.mjs.map +1 -1
  16. package/dist/esm/hooks/useBatchedCallback/useBatchedCallback.mjs +20 -0
  17. package/dist/esm/hooks/useBatchedCallback/useBatchedCallback.mjs.map +1 -0
  18. package/dist/esm/hooks/useEventListener/useEventListener.mjs +8 -8
  19. package/dist/esm/hooks/useEventListener/useEventListener.mjs.map +1 -1
  20. package/dist/esm/hooks/useOtpCredential/useOtpCredential.mjs +14 -12
  21. package/dist/esm/hooks/useOtpCredential/useOtpCredential.mjs.map +1 -1
  22. package/dist/esm/hooks/useSpeechRecognition/useSpeechRecognition.mjs +5 -7
  23. package/dist/esm/hooks/useSpeechRecognition/useSpeechRecognition.mjs.map +1 -1
  24. package/dist/esm/hooks/useTextareaAutosize/useTextareaAutosize.mjs +36 -41
  25. package/dist/esm/hooks/useTextareaAutosize/useTextareaAutosize.mjs.map +1 -1
  26. package/dist/esm/index.mjs +53 -51
  27. package/dist/esm/index.mjs.map +1 -1
  28. package/dist/types/helpers/createStore/createStore.d.ts +5 -12
  29. package/dist/types/hooks/useBatchedCallback/useBatchedCallback.d.ts +19 -0
  30. package/dist/types/hooks/useOtpCredential/useOtpCredential.d.ts +2 -3
  31. package/dist/types/hooks/useSpeechRecognition/useSpeechRecognition.d.ts +1 -1
  32. package/dist/types/hooks/useTextareaAutosize/useTextareaAutosize.d.ts +10 -1
  33. package/dist/types/hooks/utilities.d.ts +1 -0
  34. package/package.json +1 -1
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const y=require("react"),b=s=>{let e;const o=new Set,c=t=>{const n=typeof t=="function"?t(e):t;if(!Object.is(n,e)){const S=e;e=typeof n!="object"||n===null||Array.isArray(n)?n:Object.assign({},e,n),o.forEach(f=>f(e,S))}},u=t=>(o.add(t),()=>o.delete(t)),r=()=>e,i=()=>e;typeof s=="function"?e=s(c,r):e=s;function a(t){return y.useSyncExternalStore(u,()=>t?t(r()):r(),()=>t?t(i()):i())}return{set:c,get:r,use:a,subscribe:u}};exports.createStore=b;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const y=require("react"),b=s=>{let e,o;const i=new Set,a=t=>{const n=typeof t=="function"?t(e):t;if(!Object.is(n,e)){const f=e;e=typeof n!="object"||n===null||Array.isArray(n)?n:Object.assign({},e,n),i.forEach(l=>l(e,f))}},u=t=>(i.add(t),()=>i.delete(t)),r=()=>e,c=()=>o;typeof s=="function"?o=e=s(a,r):o=e=s;function S(t){return y.useSyncExternalStore(u,()=>t?t(r()):r(),()=>t?t(c()):c())}return{set:a,get:r,getInitial:c,use:S,subscribe:u}};exports.createStore=b;
2
2
  //# sourceMappingURL=createStore.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"createStore.cjs","sources":["../../../../src/helpers/createStore/createStore.ts"],"sourcesContent":["import { useSyncExternalStore } from 'react';\n\ntype StoreSetAction<Value> = ((prev: Value) => Partial<Value>) | Partial<Value>;\n\ntype StoreListener<Value> = (state: Value, prevState: Value) => void;\n\ntype StoreCreator<Value> = (\n set: (action: StoreSetAction<Value>) => void,\n get: () => Value\n) => Value;\n\nexport interface StoreApi<Value> {\n getInitialState: () => Value;\n getState: () => Value;\n setState: (action: StoreSetAction<Value>) => void;\n subscribe: (listener: StoreListener<Value>) => () => void;\n}\n\n/**\n * @name createStore\n * @description - Creates a store with state management capabilities\n * @category Helpers\n * @usage medium\n *\n * @template Value - The type of the store state\n * @param {StateCreator<Value>} createState - Function that initializes the store state\n * @returns {StoreApi<Value>} - Object containing store methods and hook for accessing state\n *\n * @example\n * const { set, get, use, subscribe } = createStore((set) => ({\n * count: 0,\n * increment: () => set(state => ({ count: state.count + 1 }))\n * }));\n */\nexport const createStore = <Value>(createState: StoreCreator<Value> | Value) => {\n let state: Value;\n const listeners: Set<StoreListener<Value>> = new Set();\n\n const setState: StoreApi<Value>['setState'] = (action: StoreSetAction<Value>) => {\n const nextState = typeof action === 'function' ? action(state) : action;\n\n if (!Object.is(nextState, state)) {\n const prevState = state;\n state = (\n typeof nextState !== 'object' || nextState === null || Array.isArray(nextState)\n ? nextState\n : Object.assign({}, state, nextState)\n ) as Value;\n\n listeners.forEach((listener) => listener(state, prevState));\n }\n };\n\n const subscribe = (listener: StoreListener<Value>) => {\n listeners.add(listener);\n\n return () => listeners.delete(listener);\n };\n\n const getState = () => state;\n const getInitialState = () => state;\n\n if (typeof createState === 'function') {\n state = (createState as StoreCreator<Value>)(setState, getState);\n } else {\n state = createState;\n }\n\n function useStore(): Value;\n function useStore<Selected>(selector: (state: Value) => Selected): Selected;\n function useStore<Selected>(selector?: (state: Value) => Selected): Selected | Value {\n return useSyncExternalStore(\n subscribe,\n () => (selector ? selector(getState()) : getState()),\n () => (selector ? selector(getInitialState()) : getInitialState())\n );\n }\n\n return {\n set: setState,\n get: getState,\n use: useStore,\n subscribe\n };\n};\n"],"names":["createStore","createState","state","listeners","setState","action","nextState","prevState","listener","subscribe","getState","getInitialState","useStore","selector","useSyncExternalStore"],"mappings":"yGAkCaA,EAAsBC,GAA6C,CAC9E,IAAIC,EACJ,MAAMC,MAA2C,IAE3CC,EAAyCC,GAAkC,CAC/E,MAAMC,EAAY,OAAOD,GAAW,WAAaA,EAAOH,CAAK,EAAIG,EAEjE,GAAI,CAAC,OAAO,GAAGC,EAAWJ,CAAK,EAAG,CAChC,MAAMK,EAAYL,EAClBA,EACE,OAAOI,GAAc,UAAYA,IAAc,MAAQ,MAAM,QAAQA,CAAS,EAC1EA,EACA,OAAO,OAAO,CAAA,EAAIJ,EAAOI,CAAS,EAGxCH,EAAU,QAASK,GAAaA,EAASN,EAAOK,CAAS,CAAC,CAAA,CAC5D,EAGIE,EAAaD,IACjBL,EAAU,IAAIK,CAAQ,EAEf,IAAML,EAAU,OAAOK,CAAQ,GAGlCE,EAAW,IAAMR,EACjBS,EAAkB,IAAMT,EAE1B,OAAOD,GAAgB,WACzBC,EAASD,EAAoCG,EAAUM,CAAQ,EAE/DR,EAAQD,EAKV,SAASW,EAAmBC,EAAyD,CACnF,OAAOC,EAAAA,qBACLL,EACA,IAAOI,EAAWA,EAASH,EAAA,CAAU,EAAIA,EAAA,EACzC,IAAOG,EAAWA,EAASF,EAAA,CAAiB,EAAIA,EAAA,CAAgB,CAClE,CAGF,MAAO,CACL,IAAKP,EACL,IAAKM,EACL,IAAKE,EACL,UAAAH,CAAA,CAEJ"}
1
+ {"version":3,"file":"createStore.cjs","sources":["../../../../src/helpers/createStore/createStore.ts"],"sourcesContent":["import { useSyncExternalStore } from 'react';\n\ntype StoreSetAction<Value> = ((prev: Value) => Partial<Value>) | Partial<Value>;\n\ntype StoreListener<Value> = (state: Value, prevState: Value) => void;\n\ntype StoreCreator<Value> = (\n set: (action: StoreSetAction<Value>) => void,\n get: () => Value\n) => Value;\n\nexport interface StoreApi<Value> {\n get: () => Value;\n getInitial: () => Value;\n set: (action: StoreSetAction<Value>) => void;\n subscribe: (listener: StoreListener<Value>) => () => void;\n\n use: (() => Value) &\n (<Selected>(selector: (state: Value) => Selected) => Selected) &\n (<Selected>(selector?: (state: Value) => Selected) => Selected | Value);\n}\n\n/**\n * @name createStore\n * @description - Creates a store with state management capabilities\n * @category Helpers\n * @usage medium\n *\n * @template Value - The type of the store state\n * @param {StateCreator<Value>} createState - Function that initializes the store state\n * @returns {StoreApi<Value>} - Object containing store methods and hook for accessing state\n *\n * @example\n * const { set, get, use, subscribe } = createStore((set) => ({\n * count: 0,\n * increment: () => set(state => ({ count: state.count + 1 }))\n * }));\n */\nexport const createStore = <Value>(createState: StoreCreator<Value> | Value): StoreApi<Value> => {\n let state: Value;\n let initialState: Value;\n const listeners: Set<StoreListener<Value>> = new Set();\n\n const setState: StoreApi<Value>['set'] = (action: StoreSetAction<Value>) => {\n const nextState = typeof action === 'function' ? action(state) : action;\n\n if (!Object.is(nextState, state)) {\n const prevState = state;\n state = (\n typeof nextState !== 'object' || nextState === null || Array.isArray(nextState)\n ? nextState\n : Object.assign({}, state, nextState)\n ) as Value;\n\n listeners.forEach((listener) => listener(state, prevState));\n }\n };\n\n const subscribe = (listener: StoreListener<Value>) => {\n listeners.add(listener);\n\n return () => listeners.delete(listener);\n };\n\n const getState = () => state;\n const getInitialState = () => initialState;\n\n if (typeof createState === 'function') {\n initialState = state = (createState as StoreCreator<Value>)(setState, getState);\n } else {\n initialState = state = createState;\n }\n\n function useStore(): Value;\n function useStore<Selected>(selector: (state: Value) => Selected): Selected;\n function useStore<Selected>(selector?: (state: Value) => Selected): Selected | Value {\n return useSyncExternalStore(\n subscribe,\n () => (selector ? selector(getState()) : getState()),\n () => (selector ? selector(getInitialState()) : getInitialState())\n );\n }\n\n return {\n set: setState,\n get: getState,\n getInitial: getInitialState,\n use: useStore,\n subscribe\n };\n};\n"],"names":["createStore","createState","state","initialState","listeners","setState","action","nextState","prevState","listener","subscribe","getState","getInitialState","useStore","selector","useSyncExternalStore"],"mappings":"yGAsCaA,EAAsBC,GAA8D,CAC/F,IAAIC,EACAC,EACJ,MAAMC,MAA2C,IAE3CC,EAAoCC,GAAkC,CAC1E,MAAMC,EAAY,OAAOD,GAAW,WAAaA,EAAOJ,CAAK,EAAII,EAEjE,GAAI,CAAC,OAAO,GAAGC,EAAWL,CAAK,EAAG,CAChC,MAAMM,EAAYN,EAClBA,EACE,OAAOK,GAAc,UAAYA,IAAc,MAAQ,MAAM,QAAQA,CAAS,EAC1EA,EACA,OAAO,OAAO,CAAA,EAAIL,EAAOK,CAAS,EAGxCH,EAAU,QAASK,GAAaA,EAASP,EAAOM,CAAS,CAAC,CAAA,CAC5D,EAGIE,EAAaD,IACjBL,EAAU,IAAIK,CAAQ,EAEf,IAAML,EAAU,OAAOK,CAAQ,GAGlCE,EAAW,IAAMT,EACjBU,EAAkB,IAAMT,EAE1B,OAAOF,GAAgB,WACzBE,EAAeD,EAASD,EAAoCI,EAAUM,CAAQ,EAE9ER,EAAeD,EAAQD,EAKzB,SAASY,EAAmBC,EAAyD,CACnF,OAAOC,EAAAA,qBACLL,EACA,IAAOI,EAAWA,EAASH,EAAA,CAAU,EAAIA,EAAA,EACzC,IAAOG,EAAWA,EAASF,EAAA,CAAiB,EAAIA,EAAA,CAAgB,CAClE,CAGF,MAAO,CACL,IAAKP,EACL,IAAKM,EACL,WAAYC,EACZ,IAAKC,EACL,UAAAH,CAAA,CAEJ"}
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("react"),o=(r,u)=>{const n=c.useRef(r),s=c.useRef(u),e=c.useRef([]);n.current=r,s.current=u;const a=()=>{if(!e.current.length)return;const t=e.current;e.current=[],n.current(t)};return c.useMemo(()=>{const t=(...l)=>{e.current.push(l),e.current.length>=s.current&&a()};return t.flush=a,t.cancel=()=>e.current=[],t},[])};exports.useBatchedCallback=o;
2
+ //# sourceMappingURL=useBatchedCallback.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useBatchedCallback.cjs","sources":["../../../../src/hooks/useBatchedCallback/useBatchedCallback.ts"],"sourcesContent":["import { useMemo, useRef } from 'react';\n\nexport type BatchedCallback<Params extends unknown[]> = ((...args: Params) => void) & {\n flush: () => void;\n cancel: () => void;\n};\n\n/**\n * @name useBatchedCallback\n * @description - Hook that batches calls and forwards them to a callback\n * @category Utilities\n * @usage medium\n *\n * @template Params The type of the params\n * @param {(batch: Params[]) => void} callback The callback that receives a batch of calls\n * @param {number} batchSize The maximum size of a batch before it is flushed\n * @returns {BatchedCallback<Params>} The batched callback with flush and cancel helpers\n *\n * @example\n * const batched = useBatchedCallback((batch) => console.log(batch), 5);\n */\nexport const useBatchedCallback = <Params extends unknown[]>(\n callback: (batch: Params[]) => void,\n size: number\n): BatchedCallback<Params> => {\n const callbackRef = useRef(callback);\n const sizeRef = useRef(size);\n const queueRef = useRef<Params[]>([]);\n\n callbackRef.current = callback;\n sizeRef.current = size;\n\n const flush = () => {\n if (!queueRef.current.length) return;\n const batch = queueRef.current;\n queueRef.current = [];\n callbackRef.current(batch);\n };\n\n const batched = useMemo(() => {\n const batchedCallback = (...args: Params) => {\n queueRef.current.push(args);\n if (queueRef.current.length >= sizeRef.current) flush();\n };\n\n batchedCallback.flush = flush;\n batchedCallback.cancel = () => (queueRef.current = []);\n\n return batchedCallback as BatchedCallback<Params>;\n }, []);\n\n return batched;\n};\n"],"names":["useBatchedCallback","callback","size","callbackRef","useRef","sizeRef","queueRef","flush","batch","useMemo","batchedCallback","args"],"mappings":"yGAqBaA,EAAqB,CAChCC,EACAC,IAC4B,CAC5B,MAAMC,EAAcC,EAAAA,OAAOH,CAAQ,EAC7BI,EAAUD,EAAAA,OAAOF,CAAI,EACrBI,EAAWF,EAAAA,OAAiB,EAAE,EAEpCD,EAAY,QAAUF,EACtBI,EAAQ,QAAUH,EAElB,MAAMK,EAAQ,IAAM,CAClB,GAAI,CAACD,EAAS,QAAQ,OAAQ,OAC9B,MAAME,EAAQF,EAAS,QACvBA,EAAS,QAAU,CAAA,EACnBH,EAAY,QAAQK,CAAK,CAAA,EAe3B,OAZgBC,EAAAA,QAAQ,IAAM,CAC5B,MAAMC,EAAkB,IAAIC,IAAiB,CAC3CL,EAAS,QAAQ,KAAKK,CAAI,EACtBL,EAAS,QAAQ,QAAUD,EAAQ,SAASE,EAAA,CAAM,EAGxD,OAAAG,EAAgB,MAAQH,EACxBG,EAAgB,OAAS,IAAOJ,EAAS,QAAU,CAAA,EAE5CI,CAAA,EACN,EAAE,CAGP"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("react"),R=require("../useRefState/useRefState.cjs"),o=require("../../utils/helpers/isTarget.cjs"),E=((...t)=>{const e=o.isTarget(t[0])?t[0]:void 0,s=e?t[1]:t[0],c=e?t[2]:t[1],n=e?t[3]:t[2],u=n?.enabled??!0,r=R.useRefState(),f=i.useRef(c);f.current=c;const d=i.useRef(n);if(d.current=n,i.useEffect(()=>{if(!u||!e&&!r.state)return;const l=(e?o.isTarget.getElement(e):r.current)??window,g=v=>f.current(v);return l.addEventListener(s,g,n),()=>{l.removeEventListener(s,g,n)}},[e,r.state,o.isTarget.getRefState(e),s,u]),!e)return r});exports.useEventListener=E;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("react"),R=require("../useRefState/useRefState.cjs"),o=require("../../utils/helpers/isTarget.cjs"),E=((...e)=>{const t=o.isTarget(e[0])?e[0]:void 0,r=t?e[1]:e[0],c=t?e[2]:e[1],n=t?e[3]:e[2],u=n?.enabled??!0,s=R.useRefState(),f=i.useRef(c);f.current=c;const d=i.useRef(n);if(d.current=n,i.useEffect(()=>{if(!u)return;const l=(t?o.isTarget.getElement(t):s.current)??window,g=v=>f.current(v);return l.addEventListener(r,g,n),()=>{l.removeEventListener(r,g,n)}},[t,s.state,o.isTarget.getRefState(t),r,u]),!t)return s});exports.useEventListener=E;
2
2
  //# sourceMappingURL=useEventListener.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"useEventListener.cjs","sources":["../../../../src/hooks/useEventListener/useEventListener.ts"],"sourcesContent":["import { useEffect, useRef } from 'react';\n\nimport type { HookTarget } from '@/utils/helpers';\n\nimport { isTarget } from '@/utils/helpers';\n\nimport type { StateRef } from '../useRefState/useRefState';\n\nimport { useRefState } from '../useRefState/useRefState';\n\n/** The use event listener options */\nexport type UseEventListenerOptions = {\n enabled?: boolean;\n} & AddEventListenerOptions;\n\n/** The use event listener return type */\nexport type UseEventListenerReturn<Target extends Element> = StateRef<Target>;\n\nexport interface UseEventListener {\n <Event extends keyof WindowEventMap = keyof WindowEventMap>(\n target: HookTarget,\n event: Event,\n listener: (this: Window, event: WindowEventMap[Event]) => void,\n options?: UseEventListenerOptions\n ): void;\n\n <Event extends keyof DocumentEventMap = keyof DocumentEventMap>(\n target: HookTarget,\n event: Event,\n listener: (this: Document, event: DocumentEventMap[Event]) => void,\n options?: UseEventListenerOptions\n ): void;\n\n <Event extends keyof HTMLElementEventMap = keyof HTMLElementEventMap>(\n target: HookTarget,\n event: Event,\n listener: (this: Element, event: HTMLElementEventMap[Event]) => void,\n options?: UseEventListenerOptions\n ): void;\n\n <Target extends Element, Event extends keyof HTMLElementEventMap = keyof HTMLElementEventMap>(\n event: Event,\n listener: (this: Target, event: HTMLElementEventMap[Event]) => void,\n options?: UseEventListenerOptions,\n target?: never\n ): UseEventListenerReturn<Target>;\n\n <\n Target extends Element,\n Event extends keyof MediaQueryListEventMap = keyof MediaQueryListEventMap\n >(\n event: Event,\n listener: (this: Target, event: MediaQueryListEventMap[Event]) => void,\n options?: UseEventListenerOptions,\n target?: never\n ): UseEventListenerReturn<Target>;\n}\n\n/**\n * @name useEventListener\n * @description - Hook that attaches an event listener to the specified target\n * @category Browser\n * @usage necessary\n\n * @overload\n * @template Event Key of window event map\n * @param {Window} target The window object to attach the event listener to\n * @param {Event | Event[]} event An array of event types to listen for\n * @param {(this: Window, event: WindowEventMap[Event]) => void} handler The event handler function\n * @param {UseEventListenerOptions} [options] Options for the event listener\n * @returns {void}\n *\n * @example\n * useEventListener(window, 'click', () => console.log('click'));\n *\n * @overload\n * @template Event Key of window event map\n * @param {Document} target The window object to attach the event listener to\n * @param {Event | Event[]} event An array of event types to listen for\n * @param {(this: Document, event: DocumentEventMap[Event]) => void} handler The event handler function\n * @param {UseEventListenerOptions} [options] Options for the event listener\n * @returns {void}\n *\n * @example\n * useEventListener(document, 'click', () => console.log('click'));\n *\n * @overload\n * @template Event Key of window event map\n * @template Target The target element\n * @param {HookTarget} target The target element to attach the event listener to\n * @param {Event | Event[]} event An array of event types to listen for\n * @param {(this: Target, event: HTMLElementEventMap[Event]) => void} handler The event handler function\n * @param {UseEventListenerOptions} [options] Options for the event listener\n * @returns {void}\n *\n * @example\n * useEventListener(ref, 'click', () => console.log('click'));\n *\n * @overload\n * @template Event Key of window event map\n * @template Target The target element\n * @param {Event | Event[]} event An array of event types to listen for\n * @param {(this: Target, event: HTMLElementEventMap[Event] | MediaQueryListEventMap[Event]) => void} handler The event handler function\n * @param {UseEventListenerOptions} [options] Options for the event listener\n * @returns {UseEventListenerReturn<Target>} A reference to the target element\n *\n * @example\n * const ref = useEventListener('click', () => console.log('click'));\n */\nexport const useEventListener = ((...params: any[]) => {\n const target = (isTarget(params[0]) ? params[0] : undefined) as HookTarget | undefined;\n const event = (target ? params[1] : params[0]) as string;\n const listener = (target ? params[2] : params[1]) as (...arg: any[]) => undefined | void;\n const options = (target ? params[3] : params[2]) as UseEventListenerOptions | undefined;\n\n const enabled = options?.enabled ?? true;\n\n const internalRef = useRefState();\n const internalListenerRef = useRef(listener);\n internalListenerRef.current = listener;\n const internalOptionsRef = useRef(options);\n internalOptionsRef.current = options;\n\n useEffect(() => {\n if (!enabled || (!target && !internalRef.state)) return;\n\n const element =\n ((target ? isTarget.getElement(target) : internalRef.current) as Element) ?? window;\n\n const listener = (event: Event) => internalListenerRef.current(event);\n\n element.addEventListener(event, listener, options);\n return () => {\n element.removeEventListener(event, listener, options);\n };\n }, [target, internalRef.state, isTarget.getRefState(target), event, enabled]);\n\n if (target) return;\n return internalRef;\n}) as UseEventListener;\n"],"names":["useEventListener","params","target","isTarget","event","listener","options","enabled","internalRef","useRefState","internalListenerRef","useRef","internalOptionsRef","useEffect","element"],"mappings":"mMA6GaA,GAAoB,IAAIC,IAAkB,CACrD,MAAMC,EAAUC,EAAAA,SAASF,EAAO,CAAC,CAAC,EAAIA,EAAO,CAAC,EAAI,OAC5CG,EAASF,EAASD,EAAO,CAAC,EAAIA,EAAO,CAAC,EACtCI,EAAYH,EAASD,EAAO,CAAC,EAAIA,EAAO,CAAC,EACzCK,EAAWJ,EAASD,EAAO,CAAC,EAAIA,EAAO,CAAC,EAExCM,EAAUD,GAAS,SAAW,GAE9BE,EAAcC,EAAAA,YAAA,EACdC,EAAsBC,EAAAA,OAAON,CAAQ,EAC3CK,EAAoB,QAAUL,EAC9B,MAAMO,EAAqBD,EAAAA,OAAOL,CAAO,EAiBzC,GAhBAM,EAAmB,QAAUN,EAE7BO,EAAAA,UAAU,IAAM,CACd,GAAI,CAACN,GAAY,CAACL,GAAU,CAACM,EAAY,MAAQ,OAEjD,MAAMM,GACFZ,EAASC,EAAAA,SAAS,WAAWD,CAAM,EAAIM,EAAY,UAAwB,OAEzEH,EAAYD,GAAiBM,EAAoB,QAAQN,CAAK,EAEpE,OAAAU,EAAQ,iBAAiBV,EAAOC,EAAUC,CAAO,EAC1C,IAAM,CACXQ,EAAQ,oBAAoBV,EAAOC,EAAUC,CAAO,CAAA,CACtD,EACC,CAACJ,EAAQM,EAAY,MAAOL,EAAAA,SAAS,YAAYD,CAAM,EAAGE,EAAOG,CAAO,CAAC,EAExE,CAAAL,EACJ,OAAOM,CACT"}
1
+ {"version":3,"file":"useEventListener.cjs","sources":["../../../../src/hooks/useEventListener/useEventListener.ts"],"sourcesContent":["import { useEffect, useRef } from 'react';\n\nimport type { HookTarget } from '@/utils/helpers';\n\nimport { isTarget } from '@/utils/helpers';\n\nimport type { StateRef } from '../useRefState/useRefState';\n\nimport { useRefState } from '../useRefState/useRefState';\n\n/** The use event listener options */\nexport type UseEventListenerOptions = {\n enabled?: boolean;\n} & AddEventListenerOptions;\n\n/** The use event listener return type */\nexport type UseEventListenerReturn<Target extends Element> = StateRef<Target>;\n\nexport interface UseEventListener {\n <Event extends keyof WindowEventMap = keyof WindowEventMap>(\n target: HookTarget,\n event: Event,\n listener: (this: Window, event: WindowEventMap[Event]) => void,\n options?: UseEventListenerOptions\n ): void;\n\n <Event extends keyof DocumentEventMap = keyof DocumentEventMap>(\n target: HookTarget,\n event: Event,\n listener: (this: Document, event: DocumentEventMap[Event]) => void,\n options?: UseEventListenerOptions\n ): void;\n\n <Event extends keyof HTMLElementEventMap = keyof HTMLElementEventMap>(\n target: HookTarget,\n event: Event,\n listener: (this: Element, event: HTMLElementEventMap[Event]) => void,\n options?: UseEventListenerOptions\n ): void;\n\n <Target extends Element, Event extends keyof HTMLElementEventMap = keyof HTMLElementEventMap>(\n event: Event,\n listener: (this: Target, event: HTMLElementEventMap[Event]) => void,\n options?: UseEventListenerOptions,\n target?: never\n ): UseEventListenerReturn<Target>;\n\n <\n Target extends Element,\n Event extends keyof MediaQueryListEventMap = keyof MediaQueryListEventMap\n >(\n event: Event,\n listener: (this: Target, event: MediaQueryListEventMap[Event]) => void,\n options?: UseEventListenerOptions,\n target?: never\n ): UseEventListenerReturn<Target>;\n}\n\n/**\n * @name useEventListener\n * @description - Hook that attaches an event listener to the specified target\n * @category Browser\n * @usage necessary\n\n * @overload\n * @template Event Key of window event map\n * @param {Window} target The window object to attach the event listener to\n * @param {Event | Event[]} event An array of event types to listen for\n * @param {(this: Window, event: WindowEventMap[Event]) => void} handler The event handler function\n * @param {UseEventListenerOptions} [options] Options for the event listener\n * @returns {void}\n *\n * @example\n * useEventListener(window, 'click', () => console.log('click'));\n *\n * @overload\n * @template Event Key of window event map\n * @param {Document} target The window object to attach the event listener to\n * @param {Event | Event[]} event An array of event types to listen for\n * @param {(this: Document, event: DocumentEventMap[Event]) => void} handler The event handler function\n * @param {UseEventListenerOptions} [options] Options for the event listener\n * @returns {void}\n *\n * @example\n * useEventListener(document, 'click', () => console.log('click'));\n *\n * @overload\n * @template Event Key of window event map\n * @template Target The target element\n * @param {HookTarget} target The target element to attach the event listener to\n * @param {Event | Event[]} event An array of event types to listen for\n * @param {(this: Target, event: HTMLElementEventMap[Event]) => void} handler The event handler function\n * @param {UseEventListenerOptions} [options] Options for the event listener\n * @returns {void}\n *\n * @example\n * useEventListener(ref, 'click', () => console.log('click'));\n *\n * @overload\n * @template Event Key of window event map\n * @template Target The target element\n * @param {Event | Event[]} event An array of event types to listen for\n * @param {(this: Target, event: HTMLElementEventMap[Event] | MediaQueryListEventMap[Event]) => void} handler The event handler function\n * @param {UseEventListenerOptions} [options] Options for the event listener\n * @returns {UseEventListenerReturn<Target>} A reference to the target element\n *\n * @example\n * const ref = useEventListener('click', () => console.log('click'));\n */\nexport const useEventListener = ((...params: any[]) => {\n const target = (isTarget(params[0]) ? params[0] : undefined) as HookTarget | undefined;\n const event = (target ? params[1] : params[0]) as string;\n const listener = (target ? params[2] : params[1]) as (...arg: any[]) => undefined | void;\n const options = (target ? params[3] : params[2]) as UseEventListenerOptions | undefined;\n\n const enabled = options?.enabled ?? true;\n\n const internalRef = useRefState();\n const internalListenerRef = useRef(listener);\n internalListenerRef.current = listener;\n const internalOptionsRef = useRef(options);\n internalOptionsRef.current = options;\n\n useEffect(() => {\n if (!enabled) return;\n\n const element =\n ((target ? isTarget.getElement(target) : internalRef.current) as Element) ?? window;\n\n const listener = (event: Event) => internalListenerRef.current(event);\n\n element.addEventListener(event, listener, options);\n return () => {\n element.removeEventListener(event, listener, options);\n };\n }, [target, internalRef.state, isTarget.getRefState(target), event, enabled]);\n\n if (target) return;\n return internalRef;\n}) as UseEventListener;\n"],"names":["useEventListener","params","target","isTarget","event","listener","options","enabled","internalRef","useRefState","internalListenerRef","useRef","internalOptionsRef","useEffect","element"],"mappings":"mMA6GaA,GAAoB,IAAIC,IAAkB,CACrD,MAAMC,EAAUC,EAAAA,SAASF,EAAO,CAAC,CAAC,EAAIA,EAAO,CAAC,EAAI,OAC5CG,EAASF,EAASD,EAAO,CAAC,EAAIA,EAAO,CAAC,EACtCI,EAAYH,EAASD,EAAO,CAAC,EAAIA,EAAO,CAAC,EACzCK,EAAWJ,EAASD,EAAO,CAAC,EAAIA,EAAO,CAAC,EAExCM,EAAUD,GAAS,SAAW,GAE9BE,EAAcC,EAAAA,YAAA,EACdC,EAAsBC,EAAAA,OAAON,CAAQ,EAC3CK,EAAoB,QAAUL,EAC9B,MAAMO,EAAqBD,EAAAA,OAAOL,CAAO,EAiBzC,GAhBAM,EAAmB,QAAUN,EAE7BO,EAAAA,UAAU,IAAM,CACd,GAAI,CAACN,EAAS,OAEd,MAAMO,GACFZ,EAASC,EAAAA,SAAS,WAAWD,CAAM,EAAIM,EAAY,UAAwB,OAEzEH,EAAYD,GAAiBM,EAAoB,QAAQN,CAAK,EAEpE,OAAAU,EAAQ,iBAAiBV,EAAOC,EAAUC,CAAO,EAC1C,IAAM,CACXQ,EAAQ,oBAAoBV,EAAOC,EAAUC,CAAO,CAAA,CACtD,EACC,CAACJ,EAAQM,EAAY,MAAOL,EAAAA,SAAS,YAAYD,CAAM,EAAGE,EAAOG,CAAO,CAAC,EAExE,CAAAL,EACJ,OAAOM,CACT"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("react"),u=((...t)=>{const n=typeof navigator<"u"&&"OTPCredential"in navigator&&!!navigator.OTPCredential,s=typeof t[0]=="function"?t[0]:t[0]?.onSuccess,a=typeof t[0]=="function"?t[0]?.onError:void 0,[i,o]=c.useState(!1),e=c.useRef(new AbortController);return{supported:n,abort:()=>{e.current.abort(),e.current=new AbortController,e.current.signal.onabort=()=>o(!0)},aborted:i,get:async()=>{if(n){e.current=new AbortController;try{const r=await navigator.credentials.get({otp:{transport:["sms"]},signal:e.current.signal});return s?.(r),o(!1),r}catch(r){a?.(r)}}}}});exports.useOtpCredential=u;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("react"),a=((...e)=>{const n=typeof navigator<"u"&&"OTPCredential"in navigator&&!!navigator.OTPCredential,o=typeof e[0]=="object"?e[0]:{onSuccess:e[0]},t=c.useRef(new AbortController);return{supported:n,abort:()=>{t.current.abort(),t.current=new AbortController},get:async()=>{if(n){t.current=new AbortController;try{const r=await navigator.credentials.get({otp:{transport:["sms"]},signal:t.current.signal});return o.onSuccess?.(r),r}catch(r){o.onError?.(r)}}}}});exports.useOtpCredential=a;
2
2
  //# sourceMappingURL=useOtpCredential.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"useOtpCredential.cjs","sources":["../../../../src/hooks/useOtpCredential/useOtpCredential.ts"],"sourcesContent":["import { useRef, useState } from 'react';\n\ndeclare global {\n interface OTPOptions {\n readonly transport: string[];\n }\n\n interface CredentialRequestOptions {\n readonly otp: OTPOptions;\n }\n\n interface Credential {\n readonly code: string;\n }\n}\n\n/* The use otp credential callback type */\nexport type UseOtpCredentialCallback = (otp: Credential | null) => void;\n\n/* The use otp credential options type */\nexport interface UseOtpCredentialParams {\n /* The callback function to be invoked on error */\n onError: (error: any) => void;\n /* The callback function to be invoked on success */\n onSuccess: (credential: Credential | null) => void;\n}\n\n/* The use otp credential return type */\nexport interface UseOtpCredentialReturn {\n /* The abort function */\n abort: AbortController['abort'];\n /* The aborted state of the query */\n aborted: boolean;\n /* The supported state of the otp credential */\n supported: boolean;\n /* The get otp credential function */\n get: () => Promise<Credential | null>;\n}\n\nexport interface UseOtpCredential {\n (callback?: UseOtpCredentialCallback): UseOtpCredentialReturn;\n\n (params?: UseOtpCredentialParams): UseOtpCredentialReturn;\n}\n\n/**\n * @name useOtpCredential\n * @description - Hook that creates an otp credential\n * @category Browser\n * @usage low\n *\n * @browserapi navigator.credentials https://developer.mozilla.org/en-US/docs/Web/API/Navigator/credentials\n *\n * @overload\n * @param {UseOtpCredentialCallback} callback The callback function to be invoked\n * @returns {UseOtpCredentialReturn}\n *\n * @example\n * useOtpCredential((credential) => console.log(credential));\n *\n * @overload\n * @param {UseOtpCredentialCallback} params.onSuccess The callback function to be invoked on success\n * @param {UseOtpCredentialCallback} params.onError The callback function to be invoked on error\n * @returns {UseOtpCredentialReturn}\n *\n * @example\n * useOtpCredential({ onSuccess: (credential) => console.log(credential), onError: (error) => console.log(error) });\n */\nexport const useOtpCredential = ((...params: any[]) => {\n const supported =\n typeof navigator !== 'undefined' && 'OTPCredential' in navigator && !!navigator.OTPCredential;\n\n const onSuccess =\n typeof params[0] === 'function'\n ? (params[0] as UseOtpCredentialCallback | undefined)\n : (params[0] as UseOtpCredentialParams | undefined)?.onSuccess;\n\n const onError =\n typeof params[0] === 'function'\n ? (params[0] as UseOtpCredentialParams | undefined)?.onError\n : undefined;\n\n const [aborted, setAborted] = useState(false);\n\n const abortControllerRef = useRef<AbortController>(new AbortController());\n\n const get = async () => {\n if (!supported) return;\n\n abortControllerRef.current = new AbortController();\n try {\n const credential = await navigator.credentials.get({\n otp: { transport: ['sms'] },\n signal: abortControllerRef.current.signal\n });\n onSuccess?.(credential);\n setAborted(false);\n return credential;\n } catch (error) {\n onError?.(error);\n }\n };\n\n const abort = () => {\n abortControllerRef.current.abort();\n abortControllerRef.current = new AbortController();\n abortControllerRef.current.signal.onabort = () => setAborted(true);\n };\n\n return { supported, abort, aborted, get };\n}) as UseOtpCredential;\n"],"names":["useOtpCredential","params","supported","onSuccess","onError","aborted","setAborted","useState","abortControllerRef","useRef","credential","error"],"mappings":"yGAoEaA,GAAoB,IAAIC,IAAkB,CACrD,MAAMC,EACJ,OAAO,UAAc,KAAe,kBAAmB,WAAa,CAAC,CAAC,UAAU,cAE5EC,EACJ,OAAOF,EAAO,CAAC,GAAM,WAChBA,EAAO,CAAC,EACRA,EAAO,CAAC,GAA0C,UAEnDG,EACJ,OAAOH,EAAO,CAAC,GAAM,WAChBA,EAAO,CAAC,GAA0C,QACnD,OAEA,CAACI,EAASC,CAAU,EAAIC,EAAAA,SAAS,EAAK,EAEtCC,EAAqBC,EAAAA,OAAwB,IAAI,eAAiB,EAyBxE,MAAO,CAAE,UAAAP,EAAW,MANN,IAAM,CAClBM,EAAmB,QAAQ,MAAA,EAC3BA,EAAmB,QAAU,IAAI,gBACjCA,EAAmB,QAAQ,OAAO,QAAU,IAAMF,EAAW,EAAI,CAAA,EAGxC,QAAAD,EAAS,IAvBxB,SAAY,CACtB,GAAKH,EAEL,CAAAM,EAAmB,QAAU,IAAI,gBACjC,GAAI,CACF,MAAME,EAAa,MAAM,UAAU,YAAY,IAAI,CACjD,IAAK,CAAE,UAAW,CAAC,KAAK,CAAA,EACxB,OAAQF,EAAmB,QAAQ,MAAA,CACpC,EACD,OAAAL,IAAYO,CAAU,EACtBJ,EAAW,EAAK,EACTI,CAAA,OACAC,EAAO,CACdP,IAAUO,CAAK,CAAA,EACjB,CASkC,CACtC"}
1
+ {"version":3,"file":"useOtpCredential.cjs","sources":["../../../../src/hooks/useOtpCredential/useOtpCredential.ts"],"sourcesContent":["import { useRef } from 'react';\n\ndeclare global {\n interface OTPOptions {\n readonly transport: string[];\n }\n\n interface CredentialRequestOptions {\n readonly otp: OTPOptions;\n }\n\n interface Credential {\n readonly code: string;\n }\n}\n\n/* The use otp credential callback type */\nexport type UseOtpCredentialCallback = (otp: Credential | null) => void;\n\n/* The use otp credential options type */\nexport interface UseOtpCredentialParams {\n /* The callback function to be invoked on error */\n onError?: (error: any) => void;\n /* The callback function to be invoked on success */\n onSuccess?: (credential: Credential | null) => void;\n}\n\n/* The use otp credential return type */\nexport interface UseOtpCredentialReturn {\n /* The abort function */\n abort: AbortController['abort'];\n /* The supported state of the otp credential */\n supported: boolean;\n /* The get otp credential function */\n get: () => Promise<Credential | null>;\n}\n\nexport interface UseOtpCredential {\n (callback?: UseOtpCredentialCallback): UseOtpCredentialReturn;\n\n (params?: UseOtpCredentialParams): UseOtpCredentialReturn;\n}\n\n/**\n * @name useOtpCredential\n * @description - Hook that creates an otp credential\n * @category Browser\n * @usage low\n *\n * @browserapi navigator.credentials https://developer.mozilla.org/en-US/docs/Web/API/Navigator/credentials\n *\n * @overload\n * @param {UseOtpCredentialCallback} callback The callback function to be invoked\n * @returns {UseOtpCredentialReturn}\n *\n * @example\n * useOtpCredential((credential) => console.log(credential));\n *\n * @overload\n * @param {UseOtpCredentialCallback} params.onSuccess The callback function to be invoked on success\n * @param {UseOtpCredentialCallback} params.onError The callback function to be invoked on error\n * @returns {UseOtpCredentialReturn}\n *\n * @example\n * useOtpCredential({ onSuccess: (credential) => console.log(credential), onError: (error) => console.log(error) });\n */\nexport const useOtpCredential = ((...params: any[]) => {\n const supported =\n typeof navigator !== 'undefined' && 'OTPCredential' in navigator && !!navigator.OTPCredential;\n\n const options =\n typeof params[0] === 'object'\n ? params[0]\n : {\n onSuccess: params[0]\n };\n\n const abortControllerRef = useRef<AbortController>(new AbortController());\n\n const get = async () => {\n if (!supported) return;\n\n abortControllerRef.current = new AbortController();\n try {\n const credential = await navigator.credentials.get({\n otp: { transport: ['sms'] },\n signal: abortControllerRef.current.signal\n });\n options.onSuccess?.(credential);\n\n return credential;\n } catch (error) {\n options.onError?.(error);\n }\n };\n\n const abort = () => {\n abortControllerRef.current.abort();\n abortControllerRef.current = new AbortController();\n };\n\n return { supported, abort, get };\n}) as UseOtpCredential;\n"],"names":["useOtpCredential","params","supported","options","abortControllerRef","useRef","credential","error"],"mappings":"yGAkEaA,GAAoB,IAAIC,IAAkB,CACrD,MAAMC,EACJ,OAAO,UAAc,KAAe,kBAAmB,WAAa,CAAC,CAAC,UAAU,cAE5EC,EACJ,OAAOF,EAAO,CAAC,GAAM,SACjBA,EAAO,CAAC,EACR,CACE,UAAWA,EAAO,CAAC,CAAA,EAGrBG,EAAqBC,EAAAA,OAAwB,IAAI,eAAiB,EAwBxE,MAAO,CAAE,UAAAH,EAAW,MALN,IAAM,CAClBE,EAAmB,QAAQ,MAAA,EAC3BA,EAAmB,QAAU,IAAI,eAAgB,EAGxB,IAtBf,SAAY,CACtB,GAAKF,EAEL,CAAAE,EAAmB,QAAU,IAAI,gBACjC,GAAI,CACF,MAAME,EAAa,MAAM,UAAU,YAAY,IAAI,CACjD,IAAK,CAAE,UAAW,CAAC,KAAK,CAAA,EACxB,OAAQF,EAAmB,QAAQ,MAAA,CACpC,EACD,OAAAD,EAAQ,YAAYG,CAAU,EAEvBA,CAAA,OACAC,EAAO,CACdJ,EAAQ,UAAUI,CAAK,CAAA,EACzB,CAQyB,CAC7B"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react"),i=()=>window?.SpeechRecognition??window?.webkitSpeechRecognition,F=(S={})=>{const c=typeof window<"u"&&!!i(),{continuous:d=!1,interimResults:R=!1,language:a="en-US",grammars:u,maxAlternatives:m=1,onStart:h,onEnd:w,onError:E,onResult:b}=S,[l,s]=n.useState(!1),[x,y]=n.useState(""),[A,T]=n.useState(!1),[j,g]=n.useState(null),[o]=n.useState(()=>{if(!c)return{};const r=i(),e=new r;return e.continuous=d,u&&(e.grammars=u),e.interimResults=R,e.lang=a,e.maxAlternatives=m,e.onstart=()=>{s(!0),T(!1),h?.()},e.onend=()=>{s(!1),w?.()},e.onerror=t=>{g(t),s(!1),E?.(t)},e.onresult=t=>{const k=t.results[t.resultIndex],{transcript:q}=k[0];y(q),g(null),b?.(t)},e.onend=()=>{s(!1),e.lang=a},e});n.useEffect(()=>()=>o.stop(),[]);const p=()=>o.start(),f=()=>o.stop();return{supported:c,transcript:x,recognition:o,final:A,listening:l,error:j,start:p,stop:f,toggle:(r=!l)=>{if(r)return p();f()}}};exports.getSpeechRecognition=i;exports.useSpeechRecognition=F;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react"),i=()=>window?.SpeechRecognition??window?.webkitSpeechRecognition,v=(S={})=>{const c=typeof window<"u"&&!!i(),{continuous:d=!1,interimResults:R=!1,language:a="en-US",grammars:u,maxAlternatives:m=1,onStart:h,onEnd:w,onError:E,onResult:b}=S,[l,s]=n.useState(!1),[x,y]=n.useState(""),[A,T]=n.useState(!1),[j,g]=n.useState(null),[o]=n.useState(()=>{if(!c)return;const r=i(),t=new r;return t.continuous=d,u&&(t.grammars=u),t.interimResults=R,t.lang=a,t.maxAlternatives=m,t.onstart=()=>{s(!0),T(!1),h?.()},t.onerror=e=>{g(e),s(!1),E?.(e)},t.onresult=e=>{const k=e.results[e.resultIndex],{transcript:q}=k[0];s(!1),y(q),g(null),b?.(e)},t.onend=()=>{s(!1),w?.(),t.lang=a},t});n.useEffect(()=>()=>o?.stop(),[]);const p=()=>o?.start(),f=()=>o?.stop();return{supported:c,transcript:x,recognition:o,final:A,listening:l,error:j,start:p,stop:f,toggle:(r=!l)=>{if(r)return p();f()}}};exports.getSpeechRecognition=i;exports.useSpeechRecognition=v;
2
2
  //# sourceMappingURL=useSpeechRecognition.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"useSpeechRecognition.cjs","sources":["../../../../src/hooks/useSpeechRecognition/useSpeechRecognition.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\n/** The use speech recognition hook options type */\ninterface UseSpeechRecognitionOptions {\n /** If true, recognition continues even after pauses in speech. Default is false */\n continuous?: SpeechRecognition['continuous'];\n /** A list of grammar rules */\n grammars?: SpeechRecognition['grammars'];\n /** If true, interim (non-final) results are provided as the user speaks */\n interimResults?: SpeechRecognition['interimResults'];\n /** The language in which recognition should occur. Must be a valid BCP 47 language tag (e.g., \"en-US\", \"ru-RU\") */\n language?: SpeechRecognition['lang'];\n /** The maximum number of alternative transcripts returned for a given recognition result. Must be a positive integer */\n maxAlternatives?: SpeechRecognition['maxAlternatives'];\n /** Callback invoked when speech recognition ends */\n onEnd?: () => void;\n /** Callback invoked when an error occurs during recognition */\n onError?: (error: SpeechRecognitionErrorEvent) => void;\n /** Callback invoked when recognition produces a result */\n onResult?: (event: SpeechRecognitionEvent) => void;\n /** Callback invoked when speech recognition starts */\n onStart?: () => void;\n}\n\n/** The return type of the useSpeechRecognition hook. */\ninterface UseSpeechRecognitionReturn {\n /** The error state */\n error: SpeechRecognitionErrorEvent | null;\n /** The final transcript */\n final: boolean;\n /** Whether the hook is currently listening for speech */\n listening: boolean;\n /** The speech recognition instance */\n recognition: SpeechRecognition;\n /** Whether the current browser supports the Web Speech API */\n supported: boolean;\n /** The current transcript */\n transcript: string;\n /** Begins speech recognition */\n start: () => void;\n /** Ends speech recognition, finalizing results */\n stop: () => void;\n /** Toggles the listening state */\n toggle: (value?: boolean) => void;\n}\n\nexport const getSpeechRecognition = () =>\n window?.SpeechRecognition ?? window?.webkitSpeechRecognition;\n\n/**\n * @name useSpeechRecognition\n * @description - Hook that provides a streamlined interface for incorporating speech-to-text functionality\n * @category Browser\n * @usage low\n *\n * @browserapi window.SpeechRecognition https://developer.mozilla.org/en-US/docs/Web/API/SpeechRecognition\n *\n * @param {boolean} [options.continuous=false] Whether recognition should continue after pauses\n * @param {boolean} [options.interimResults=false] Whether interim results should be provided\n * @param {string} [options.language=\"en-US\"] The language for recognition, as a valid BCP 47 tag\n * @param {number} [options.maxAlternatives=1] The maximum number of alternative transcripts to return\n * @param {SpeechGrammarList} [options.grammars] A list of grammar rules\n * @param {() => void} [options.onStart] Callback invoked when speech recognition starts\n * @param {() => void} [options.onEnd] Callback invoked when speech recognition ends\n * @param {(error: SpeechRecognitionErrorEvent) => void} [options.onError] Callback invoked when an error occurs during recognition\n * @param {(event: SpeechRecognitionEvent) => void} [options.onResult] Callback invoked when recognition produces a result\n * @returns {UseSpeechRecognitionReturn} An object containing the speech recognition functionality\n *\n * @example\n * const { supported, value, recognition, listening, error, start, stop, toggle } = useSpeechRecognition();\n */\nexport const useSpeechRecognition = (\n options: UseSpeechRecognitionOptions = {}\n): UseSpeechRecognitionReturn => {\n const supported = typeof window !== 'undefined' && !!getSpeechRecognition();\n\n const {\n continuous = false,\n interimResults = false,\n language = 'en-US',\n grammars,\n maxAlternatives = 1,\n onStart,\n onEnd,\n onError,\n onResult\n } = options;\n\n const [listening, setListening] = useState(false);\n const [transcript, setTranscript] = useState('');\n const [final, setFinal] = useState(false);\n const [error, setError] = useState<SpeechRecognitionErrorEvent | null>(null);\n const [recognition] = useState<SpeechRecognition>(() => {\n if (!supported) return {} as SpeechRecognition;\n\n const SpeechRecognition = getSpeechRecognition();\n const speechRecognition = new SpeechRecognition();\n\n speechRecognition.continuous = continuous;\n if (grammars) speechRecognition.grammars = grammars;\n speechRecognition.interimResults = interimResults;\n speechRecognition.lang = language;\n speechRecognition.maxAlternatives = maxAlternatives;\n\n speechRecognition.onstart = () => {\n setListening(true);\n setFinal(false);\n onStart?.();\n };\n speechRecognition.onend = () => {\n setListening(false);\n onEnd?.();\n };\n speechRecognition.onerror = (event) => {\n setError(event);\n setListening(false);\n onError?.(event);\n };\n speechRecognition.onresult = (event) => {\n const currentResult = event.results[event.resultIndex];\n const { transcript } = currentResult[0];\n\n setTranscript(transcript);\n setError(null);\n onResult?.(event);\n };\n speechRecognition.onend = () => {\n setListening(false);\n speechRecognition.lang = language;\n };\n\n return speechRecognition;\n });\n\n useEffect(() => () => recognition.stop(), []);\n\n const start = () => recognition.start();\n const stop = () => recognition.stop();\n\n const toggle = (value = !listening) => {\n if (value) return start();\n stop();\n };\n\n return {\n supported,\n transcript,\n recognition,\n final,\n listening,\n error,\n start,\n stop,\n toggle\n };\n};\n"],"names":["getSpeechRecognition","useSpeechRecognition","options","supported","continuous","interimResults","language","grammars","maxAlternatives","onStart","onEnd","onError","onResult","listening","setListening","useState","transcript","setTranscript","final","setFinal","error","setError","recognition","SpeechRecognition","speechRecognition","event","currentResult","useEffect","start","stop","value"],"mappings":"yGA8CaA,EAAuB,IAClC,QAAQ,mBAAqB,QAAQ,wBAwB1BC,EAAuB,CAClCC,EAAuC,KACR,CAC/B,MAAMC,EAAY,OAAO,OAAW,KAAe,CAAC,CAACH,EAAA,EAE/C,CACJ,WAAAI,EAAa,GACb,eAAAC,EAAiB,GACjB,SAAAC,EAAW,QACX,SAAAC,EACA,gBAAAC,EAAkB,EAClB,QAAAC,EACA,MAAAC,EACA,QAAAC,EACA,SAAAC,CAAA,EACEV,EAEE,CAACW,EAAWC,CAAY,EAAIC,EAAAA,SAAS,EAAK,EAC1C,CAACC,EAAYC,CAAa,EAAIF,EAAAA,SAAS,EAAE,EACzC,CAACG,EAAOC,CAAQ,EAAIJ,EAAAA,SAAS,EAAK,EAClC,CAACK,EAAOC,CAAQ,EAAIN,EAAAA,SAA6C,IAAI,EACrE,CAACO,CAAW,EAAIP,EAAAA,SAA4B,IAAM,CACtD,GAAI,CAACZ,EAAW,MAAO,CAAA,EAEvB,MAAMoB,EAAoBvB,EAAA,EACpBwB,EAAoB,IAAID,EAE9B,OAAAC,EAAkB,WAAapB,EAC3BG,MAA4B,SAAWA,GAC3CiB,EAAkB,eAAiBnB,EACnCmB,EAAkB,KAAOlB,EACzBkB,EAAkB,gBAAkBhB,EAEpCgB,EAAkB,QAAU,IAAM,CAChCV,EAAa,EAAI,EACjBK,EAAS,EAAK,EACdV,IAAA,CAAU,EAEZe,EAAkB,MAAQ,IAAM,CAC9BV,EAAa,EAAK,EAClBJ,IAAA,CAAQ,EAEVc,EAAkB,QAAWC,GAAU,CACrCJ,EAASI,CAAK,EACdX,EAAa,EAAK,EAClBH,IAAUc,CAAK,CAAA,EAEjBD,EAAkB,SAAYC,GAAU,CACtC,MAAMC,EAAgBD,EAAM,QAAQA,EAAM,WAAW,EAC/C,CAAE,WAAAT,GAAeU,EAAc,CAAC,EAEtCT,EAAcD,CAAU,EACxBK,EAAS,IAAI,EACbT,IAAWa,CAAK,CAAA,EAElBD,EAAkB,MAAQ,IAAM,CAC9BV,EAAa,EAAK,EAClBU,EAAkB,KAAOlB,CAAA,EAGpBkB,CAAA,CACR,EAEDG,EAAAA,UAAU,IAAM,IAAML,EAAY,KAAA,EAAQ,CAAA,CAAE,EAE5C,MAAMM,EAAQ,IAAMN,EAAY,MAAA,EAC1BO,EAAO,IAAMP,EAAY,KAAA,EAO/B,MAAO,CACL,UAAAnB,EACA,WAAAa,EACA,YAAAM,EACA,MAAAJ,EACA,UAAAL,EACA,MAAAO,EACA,MAAAQ,EACA,KAAAC,EACA,OAda,CAACC,EAAQ,CAACjB,IAAc,CACrC,GAAIiB,SAAcF,EAAA,EAClBC,EAAA,CAAK,CAYL,CAEJ"}
1
+ {"version":3,"file":"useSpeechRecognition.cjs","sources":["../../../../src/hooks/useSpeechRecognition/useSpeechRecognition.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\n/** The use speech recognition hook options type */\ninterface UseSpeechRecognitionOptions {\n /** If true, recognition continues even after pauses in speech. Default is false */\n continuous?: SpeechRecognition['continuous'];\n /** A list of grammar rules */\n grammars?: SpeechRecognition['grammars'];\n /** If true, interim (non-final) results are provided as the user speaks */\n interimResults?: SpeechRecognition['interimResults'];\n /** The language in which recognition should occur. Must be a valid BCP 47 language tag (e.g., \"en-US\", \"ru-RU\") */\n language?: SpeechRecognition['lang'];\n /** The maximum number of alternative transcripts returned for a given recognition result. Must be a positive integer */\n maxAlternatives?: SpeechRecognition['maxAlternatives'];\n /** Callback invoked when speech recognition ends */\n onEnd?: () => void;\n /** Callback invoked when an error occurs during recognition */\n onError?: (error: SpeechRecognitionErrorEvent) => void;\n /** Callback invoked when recognition produces a result */\n onResult?: (event: SpeechRecognitionEvent) => void;\n /** Callback invoked when speech recognition starts */\n onStart?: () => void;\n}\n\n/** The return type of the useSpeechRecognition hook. */\ninterface UseSpeechRecognitionReturn {\n /** The error state */\n error: SpeechRecognitionErrorEvent | null;\n /** The final transcript */\n final: boolean;\n /** Whether the hook is currently listening for speech */\n listening: boolean;\n /** The speech recognition instance */\n recognition?: SpeechRecognition;\n /** Whether the current browser supports the Web Speech API */\n supported: boolean;\n /** The current transcript */\n transcript: string;\n /** Begins speech recognition */\n start: () => void;\n /** Ends speech recognition, finalizing results */\n stop: () => void;\n /** Toggles the listening state */\n toggle: (value?: boolean) => void;\n}\n\nexport const getSpeechRecognition = () =>\n window?.SpeechRecognition ?? window?.webkitSpeechRecognition;\n\n/**\n * @name useSpeechRecognition\n * @description - Hook that provides a streamlined interface for incorporating speech-to-text functionality\n * @category Browser\n * @usage low\n *\n * @browserapi window.SpeechRecognition https://developer.mozilla.org/en-US/docs/Web/API/SpeechRecognition\n *\n * @param {boolean} [options.continuous=false] Whether recognition should continue after pauses\n * @param {boolean} [options.interimResults=false] Whether interim results should be provided\n * @param {string} [options.language=\"en-US\"] The language for recognition, as a valid BCP 47 tag\n * @param {number} [options.maxAlternatives=1] The maximum number of alternative transcripts to return\n * @param {SpeechGrammarList} [options.grammars] A list of grammar rules\n * @param {() => void} [options.onStart] Callback invoked when speech recognition starts\n * @param {() => void} [options.onEnd] Callback invoked when speech recognition ends\n * @param {(error: SpeechRecognitionErrorEvent) => void} [options.onError] Callback invoked when an error occurs during recognition\n * @param {(event: SpeechRecognitionEvent) => void} [options.onResult] Callback invoked when recognition produces a result\n * @returns {UseSpeechRecognitionReturn} An object containing the speech recognition functionality\n *\n * @example\n * const { supported, value, recognition, listening, error, start, stop, toggle } = useSpeechRecognition();\n */\nexport const useSpeechRecognition = (\n options: UseSpeechRecognitionOptions = {}\n): UseSpeechRecognitionReturn => {\n const supported = typeof window !== 'undefined' && !!getSpeechRecognition();\n\n const {\n continuous = false,\n interimResults = false,\n language = 'en-US',\n grammars,\n maxAlternatives = 1,\n onStart,\n onEnd,\n onError,\n onResult\n } = options;\n\n const [listening, setListening] = useState(false);\n const [transcript, setTranscript] = useState('');\n const [final, setFinal] = useState(false);\n const [error, setError] = useState<SpeechRecognitionErrorEvent | null>(null);\n const [recognition] = useState<SpeechRecognition | undefined>(() => {\n if (!supported) return undefined;\n\n const SpeechRecognition = getSpeechRecognition();\n const speechRecognition = new SpeechRecognition();\n\n speechRecognition.continuous = continuous;\n if (grammars) speechRecognition.grammars = grammars;\n speechRecognition.interimResults = interimResults;\n speechRecognition.lang = language;\n speechRecognition.maxAlternatives = maxAlternatives;\n\n speechRecognition.onstart = () => {\n setListening(true);\n setFinal(false);\n onStart?.();\n };\n speechRecognition.onerror = (event) => {\n setError(event);\n setListening(false);\n onError?.(event);\n };\n speechRecognition.onresult = (event) => {\n const currentResult = event.results[event.resultIndex];\n const { transcript } = currentResult[0];\n\n setListening(false);\n setTranscript(transcript);\n setError(null);\n onResult?.(event);\n };\n speechRecognition.onend = () => {\n setListening(false);\n onEnd?.();\n speechRecognition.lang = language;\n };\n\n return speechRecognition;\n });\n\n useEffect(() => () => recognition?.stop(), []);\n\n const start = () => recognition?.start();\n const stop = () => recognition?.stop();\n\n const toggle = (value = !listening) => {\n if (value) return start();\n stop();\n };\n\n return {\n supported,\n transcript,\n recognition,\n final,\n listening,\n error,\n start,\n stop,\n toggle\n };\n};\n"],"names":["getSpeechRecognition","useSpeechRecognition","options","supported","continuous","interimResults","language","grammars","maxAlternatives","onStart","onEnd","onError","onResult","listening","setListening","useState","transcript","setTranscript","final","setFinal","error","setError","recognition","SpeechRecognition","speechRecognition","event","currentResult","useEffect","start","stop","value"],"mappings":"yGA8CaA,EAAuB,IAClC,QAAQ,mBAAqB,QAAQ,wBAwB1BC,EAAuB,CAClCC,EAAuC,KACR,CAC/B,MAAMC,EAAY,OAAO,OAAW,KAAe,CAAC,CAACH,EAAA,EAE/C,CACJ,WAAAI,EAAa,GACb,eAAAC,EAAiB,GACjB,SAAAC,EAAW,QACX,SAAAC,EACA,gBAAAC,EAAkB,EAClB,QAAAC,EACA,MAAAC,EACA,QAAAC,EACA,SAAAC,CAAA,EACEV,EAEE,CAACW,EAAWC,CAAY,EAAIC,EAAAA,SAAS,EAAK,EAC1C,CAACC,EAAYC,CAAa,EAAIF,EAAAA,SAAS,EAAE,EACzC,CAACG,EAAOC,CAAQ,EAAIJ,EAAAA,SAAS,EAAK,EAClC,CAACK,EAAOC,CAAQ,EAAIN,EAAAA,SAA6C,IAAI,EACrE,CAACO,CAAW,EAAIP,EAAAA,SAAwC,IAAM,CAClE,GAAI,CAACZ,EAAW,OAEhB,MAAMoB,EAAoBvB,EAAA,EACpBwB,EAAoB,IAAID,EAE9B,OAAAC,EAAkB,WAAapB,EAC3BG,MAA4B,SAAWA,GAC3CiB,EAAkB,eAAiBnB,EACnCmB,EAAkB,KAAOlB,EACzBkB,EAAkB,gBAAkBhB,EAEpCgB,EAAkB,QAAU,IAAM,CAChCV,EAAa,EAAI,EACjBK,EAAS,EAAK,EACdV,IAAA,CAAU,EAEZe,EAAkB,QAAWC,GAAU,CACrCJ,EAASI,CAAK,EACdX,EAAa,EAAK,EAClBH,IAAUc,CAAK,CAAA,EAEjBD,EAAkB,SAAYC,GAAU,CACtC,MAAMC,EAAgBD,EAAM,QAAQA,EAAM,WAAW,EAC/C,CAAE,WAAAT,GAAeU,EAAc,CAAC,EAEtCZ,EAAa,EAAK,EAClBG,EAAcD,CAAU,EACxBK,EAAS,IAAI,EACbT,IAAWa,CAAK,CAAA,EAElBD,EAAkB,MAAQ,IAAM,CAC9BV,EAAa,EAAK,EAClBJ,IAAA,EACAc,EAAkB,KAAOlB,CAAA,EAGpBkB,CAAA,CACR,EAEDG,EAAAA,UAAU,IAAM,IAAML,GAAa,KAAA,EAAQ,CAAA,CAAE,EAE7C,MAAMM,EAAQ,IAAMN,GAAa,MAAA,EAC3BO,EAAO,IAAMP,GAAa,KAAA,EAOhC,MAAO,CACL,UAAAnB,EACA,WAAAa,EACA,YAAAM,EACA,MAAAJ,EACA,UAAAL,EACA,MAAAO,EACA,MAAAQ,EACA,KAAAC,EACA,OAda,CAACC,EAAQ,CAACjB,IAAc,CACrC,GAAIiB,SAAcF,EAAA,EAClBC,EAAA,CAAK,CAYL,CAEJ"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("react"),y=require("../useRefState/useRefState.cjs"),h=require("../../utils/helpers/isTarget.cjs"),H=((...i)=>{const t=h.isTarget(i[0])?i[0]:void 0,r=t?i[1]:typeof i[0]=="string"?{initialValue:i[0]}:i[0],[a,g]=c.useState(r?.initialValue??""),u=y.useRefState(),o=c.useRef(null),s=()=>{const e=o.current;if(!e)return;const n=e.style.minHeight,l=e.style.maxHeight;e.style.height="auto",e.style.minHeight="auto",e.style.maxHeight="none";const f=e.scrollHeight;e.style.height=`${f}px`,e.style.minHeight=n,e.style.maxHeight=l,r?.onResize?.()};c.useEffect(()=>{if(!t&&!u.state)return;const e=t?h.isTarget.getElement(t):u.current;if(!e)return;o.current=e,r?.initialValue&&(e.value=r.initialValue),s();const n=f=>{const x=f.target.value;g(x),requestAnimationFrame(()=>{s()})},l=()=>{requestAnimationFrame(()=>{s()})};return e.addEventListener("input",n),e.addEventListener("resize",l),()=>{e.removeEventListener("input",n),e.removeEventListener("resize",l)}},[t,u.state,h.isTarget.getRefState(t),r?.initialValue]),c.useEffect(()=>{const e=o.current;e&&(e.value=a,requestAnimationFrame(()=>{s()}))},[a]);const m=e=>{g(e);const n=o.current;n&&(n.value=e,requestAnimationFrame(()=>{s()}))},v=()=>g("");return t?{value:a,setValue:m,clear:v}:{ref:u,value:a,setValue:m,clear:v}});exports.useTextareaAutosize=H;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("react"),R=require("../useRefState/useRefState.cjs"),f=require("../../utils/helpers/isTarget.cjs"),m=((...t)=>{const n=f.isTarget(t[0])?t[0]:void 0,s=n?typeof t[1]=="object"?t[1]:{initialValue:t[1]}:typeof t[0]=="object"?t[0]:{initialValue:t[0]},[h,v]=l.useState(s?.initialValue??""),o=R.useRefState(),c=l.useRef(null),x=l.useRef(0),a=()=>{const e=c.current;if(!e)return;const i=e.style.minHeight,u=e.style.maxHeight;e.style.height="auto",e.style.minHeight="auto",e.style.maxHeight="none";const r=e.scrollHeight;e.style.height=`${r}px`,e.style.minHeight=i,e.style.maxHeight=u,r!==x.current&&s?.onResize?.(),x.current=r},g=e=>{v(e);const i=c.current;i&&(i.value=e,requestAnimationFrame(()=>{a()}))};l.useEffect(()=>{if(!n&&!o.state)return;const e=n?f.isTarget.getElement(n):o.current;if(!e)return;c.current=e,s?.initialValue&&(e.value=s.initialValue),a();const i=r=>{const H=r.target.value;g(H),requestAnimationFrame(()=>{a()})},u=()=>{requestAnimationFrame(()=>{a()})};return e.addEventListener("input",i),e.addEventListener("resize",u),()=>{e.removeEventListener("input",i),e.removeEventListener("resize",u)}},[n,o.state,f.isTarget.getRefState(n)]);const y=()=>v("");return n?{value:h,set:g,clear:y}:{ref:o,value:h,set:g,clear:y}});exports.useTextareaAutosize=m;
2
2
  //# sourceMappingURL=useTextareaAutosize.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"useTextareaAutosize.cjs","sources":["../../../../src/hooks/useTextareaAutosize/useTextareaAutosize.ts"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\n\nimport type { HookTarget } from '@/utils/helpers';\n\nimport { isTarget } from '@/utils/helpers';\n\nimport type { StateRef } from '../useRefState/useRefState';\n\nimport { useRefState } from '../useRefState/useRefState';\n\n/** The use textarea autosize options */\nexport interface UseTextareaAutosizeOptions {\n /** The initial value for the textarea */\n initialValue?: string;\n /** Callback function called when the textarea size changes */\n onResize?: () => void;\n}\n\n/** The use textarea autosize return type */\nexport interface UseTextareaAutosizeReturn {\n /** The current value of the textarea */\n value: string;\n /** Function to clear the textarea value */\n clear: () => void;\n /** Function to set the textarea value */\n setValue: (value: string) => void;\n}\n\nexport interface UseTextareaAutosize {\n (target: HookTarget, options?: UseTextareaAutosizeOptions): UseTextareaAutosizeReturn;\n\n <Target extends HTMLTextAreaElement = HTMLTextAreaElement>(\n initialValue: string,\n target?: never\n ): UseTextareaAutosizeReturn & {\n ref: StateRef<Target>;\n };\n\n <Target extends HTMLTextAreaElement = HTMLTextAreaElement>(\n options?: UseTextareaAutosizeOptions,\n target?: never\n ): UseTextareaAutosizeReturn & {\n ref: StateRef<Target>;\n };\n}\n\n/**\n * @name useTextareaAutosize\n * @description - Hook that automatically adjusts textarea height based on content\n * @category Elements\n * @usage medium\n *\n * @overload\n * @param {HookTarget} target The target textarea element\n * @param {string} [options.initialValue] The initial value for the textarea\n * @param {Function} [options.onResize] Callback function called when the textarea size changes\n * @returns {UseTextareaAutosizeReturn} An object containing value, setValue and clear\n *\n * @example\n * const { value, setValue, clear } = useTextareaAutosize(ref);\n *\n * @overload\n * @template Target The textarea element type\n * @param {string} initialValue The initial value for the textarea\n * @returns {UseTextareaAutosizeReturn & { ref: StateRef<Target> }} An object containing ref, value, setValue and clear\n *\n * @example\n * const { ref, value, setValue, clear } = useTextareaAutosize('initial');\n *\n * @overload\n * @template Target The textarea element type\n * @param {string} [options.initialValue] The initial value for the textarea\n * @param {Function} [options.onResize] Callback function called when the textarea size changes\n * @returns {UseTextareaAutosizeReturn & { ref: StateRef<Target> }} An object containing ref, value, setValue and clear\n *\n * @example\n * const { ref, value, setValue, clear } = useTextareaAutosize();\n */\nexport const useTextareaAutosize = ((...params: any[]) => {\n const target = (isTarget(params[0]) ? params[0] : undefined) as HookTarget | undefined;\n\n const options = (\n target ? params[1] : typeof params[0] === 'string' ? { initialValue: params[0] } : params[0]\n ) as UseTextareaAutosizeOptions | undefined;\n\n const [value, setValue] = useState(options?.initialValue ?? '');\n const internalRef = useRefState<HTMLTextAreaElement>();\n const textareaRef = useRef<HTMLTextAreaElement | null>(null);\n\n const onTextareaResize = () => {\n const textarea = textareaRef.current;\n if (!textarea) return;\n\n const originalMinHeight = textarea.style.minHeight;\n const originalMaxHeight = textarea.style.maxHeight;\n\n textarea.style.height = 'auto';\n textarea.style.minHeight = 'auto';\n textarea.style.maxHeight = 'none';\n\n const scrollHeight = textarea.scrollHeight;\n\n textarea.style.height = `${scrollHeight}px`;\n textarea.style.minHeight = originalMinHeight;\n textarea.style.maxHeight = originalMaxHeight;\n\n options?.onResize?.();\n };\n\n useEffect(() => {\n if (!target && !internalRef.state) return;\n\n const element = (\n target ? isTarget.getElement(target) : internalRef.current\n ) as HTMLTextAreaElement;\n if (!element) return;\n\n textareaRef.current = element;\n if (options?.initialValue) element.value = options.initialValue;\n\n onTextareaResize();\n\n const onInput = (event: InputEvent) => {\n const newValue = (event.target as HTMLTextAreaElement).value;\n setValue(newValue);\n\n requestAnimationFrame(() => {\n onTextareaResize();\n });\n };\n\n const onResize = () => {\n requestAnimationFrame(() => {\n onTextareaResize();\n });\n };\n\n element.addEventListener('input', onInput as EventListener);\n element.addEventListener('resize', onResize as EventListener);\n\n return () => {\n element.removeEventListener('input', onInput as EventListener);\n element.removeEventListener('resize', onResize as EventListener);\n };\n }, [target, internalRef.state, isTarget.getRefState(target), options?.initialValue]);\n\n useEffect(() => {\n const textarea = textareaRef.current;\n if (!textarea) return;\n textarea.value = value;\n requestAnimationFrame(() => {\n onTextareaResize();\n });\n }, [value]);\n\n const setTextareaValue = (newValue: string) => {\n setValue(newValue);\n const textarea = textareaRef.current;\n if (textarea) {\n textarea.value = newValue;\n requestAnimationFrame(() => {\n onTextareaResize();\n });\n }\n };\n\n const clear = () => setValue('');\n\n if (target)\n return {\n value,\n setValue: setTextareaValue,\n clear\n };\n return {\n ref: internalRef,\n value,\n setValue: setTextareaValue,\n clear\n };\n}) as UseTextareaAutosize;\n"],"names":["useTextareaAutosize","params","target","isTarget","options","value","setValue","useState","internalRef","useRefState","textareaRef","useRef","onTextareaResize","textarea","originalMinHeight","originalMaxHeight","scrollHeight","useEffect","element","onInput","event","newValue","onResize","setTextareaValue","clear"],"mappings":"mMA8EaA,GAAuB,IAAIC,IAAkB,CACxD,MAAMC,EAAUC,EAAAA,SAASF,EAAO,CAAC,CAAC,EAAIA,EAAO,CAAC,EAAI,OAE5CG,EACJF,EAASD,EAAO,CAAC,EAAI,OAAOA,EAAO,CAAC,GAAM,SAAW,CAAE,aAAcA,EAAO,CAAC,CAAA,EAAMA,EAAO,CAAC,EAGvF,CAACI,EAAOC,CAAQ,EAAIC,EAAAA,SAASH,GAAS,cAAgB,EAAE,EACxDI,EAAcC,EAAAA,YAAA,EACdC,EAAcC,EAAAA,OAAmC,IAAI,EAErDC,EAAmB,IAAM,CAC7B,MAAMC,EAAWH,EAAY,QAC7B,GAAI,CAACG,EAAU,OAEf,MAAMC,EAAoBD,EAAS,MAAM,UACnCE,EAAoBF,EAAS,MAAM,UAEzCA,EAAS,MAAM,OAAS,OACxBA,EAAS,MAAM,UAAY,OAC3BA,EAAS,MAAM,UAAY,OAE3B,MAAMG,EAAeH,EAAS,aAE9BA,EAAS,MAAM,OAAS,GAAGG,CAAY,KACvCH,EAAS,MAAM,UAAYC,EAC3BD,EAAS,MAAM,UAAYE,EAE3BX,GAAS,WAAA,CAAW,EAGtBa,EAAAA,UAAU,IAAM,CACd,GAAI,CAACf,GAAU,CAACM,EAAY,MAAO,OAEnC,MAAMU,EACJhB,EAASC,EAAAA,SAAS,WAAWD,CAAM,EAAIM,EAAY,QAErD,GAAI,CAACU,EAAS,OAEdR,EAAY,QAAUQ,EAClBd,GAAS,eAAcc,EAAQ,MAAQd,EAAQ,cAEnDQ,EAAA,EAEA,MAAMO,EAAWC,GAAsB,CACrC,MAAMC,EAAYD,EAAM,OAA+B,MACvDd,EAASe,CAAQ,EAEjB,sBAAsB,IAAM,CAC1BT,EAAA,CAAiB,CAClB,CAAA,EAGGU,EAAW,IAAM,CACrB,sBAAsB,IAAM,CAC1BV,EAAA,CAAiB,CAClB,CAAA,EAGH,OAAAM,EAAQ,iBAAiB,QAASC,CAAwB,EAC1DD,EAAQ,iBAAiB,SAAUI,CAAyB,EAErD,IAAM,CACXJ,EAAQ,oBAAoB,QAASC,CAAwB,EAC7DD,EAAQ,oBAAoB,SAAUI,CAAyB,CAAA,CACjE,EACC,CAACpB,EAAQM,EAAY,MAAOL,EAAAA,SAAS,YAAYD,CAAM,EAAGE,GAAS,YAAY,CAAC,EAEnFa,EAAAA,UAAU,IAAM,CACd,MAAMJ,EAAWH,EAAY,QACxBG,IACLA,EAAS,MAAQR,EACjB,sBAAsB,IAAM,CAC1BO,EAAA,CAAiB,CAClB,EAAA,EACA,CAACP,CAAK,CAAC,EAEV,MAAMkB,EAAoBF,GAAqB,CAC7Cf,EAASe,CAAQ,EACjB,MAAMR,EAAWH,EAAY,QACzBG,IACFA,EAAS,MAAQQ,EACjB,sBAAsB,IAAM,CAC1BT,EAAA,CAAiB,CAClB,EACH,EAGIY,EAAQ,IAAMlB,EAAS,EAAE,EAE/B,OAAIJ,EACK,CACL,MAAAG,EACA,SAAUkB,EACV,MAAAC,CAAA,EAEG,CACL,IAAKhB,EACL,MAAAH,EACA,SAAUkB,EACV,MAAAC,CAAA,CAEJ"}
1
+ {"version":3,"file":"useTextareaAutosize.cjs","sources":["../../../../src/hooks/useTextareaAutosize/useTextareaAutosize.ts"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\n\nimport type { HookTarget } from '@/utils/helpers';\n\nimport { isTarget } from '@/utils/helpers';\n\nimport type { StateRef } from '../useRefState/useRefState';\n\nimport { useRefState } from '../useRefState/useRefState';\n\n/** The use textarea autosize options */\nexport interface UseTextareaAutosizeOptions {\n /** The initial value for the textarea */\n initialValue?: string;\n /** Callback function called when the textarea size changes */\n onResize?: () => void;\n}\n\n/** The use textarea autosize return type */\nexport interface UseTextareaAutosizeReturn {\n /** The current value of the textarea */\n value: string;\n /** Function to clear the textarea value */\n clear: () => void;\n /** Function to set the textarea value */\n set: (value: string) => void;\n}\n\nexport interface UseTextareaAutosize {\n (target: HookTarget, options?: UseTextareaAutosizeOptions): UseTextareaAutosizeReturn;\n\n (target: HookTarget, initialValue: string): UseTextareaAutosizeReturn;\n\n <Target extends HTMLTextAreaElement = HTMLTextAreaElement>(\n initialValue: string,\n target?: never\n ): UseTextareaAutosizeReturn & {\n ref: StateRef<Target>;\n };\n\n <Target extends HTMLTextAreaElement = HTMLTextAreaElement>(\n options?: UseTextareaAutosizeOptions,\n target?: never\n ): UseTextareaAutosizeReturn & {\n ref: StateRef<Target>;\n };\n}\n\n/**\n * @name useTextareaAutosize\n * @description - Hook that automatically adjusts textarea height based on content\n * @category Elements\n * @usage medium\n *\n * @overload\n * @param {HookTarget} target The target textarea element\n * @param {string} [options.initialValue] The initial value for the textarea\n * @param {Function} [options.onResize] Callback function called when the textarea size changes\n * @returns {UseTextareaAutosizeReturn} An object containing value, setValue and clear\n *\n * @example\n * const { value, setValue, clear } = useTextareaAutosize(ref);\n *\n * @overload\n * @param {HookTarget} target The target textarea element\n * @param {string} initialValue The initial value for the textarea\n * @returns {UseTextareaAutosizeReturn} An object containing value, setValue and clear\n *\n * @example\n * const { value, setValue, clear } = useTextareaAutosize(ref, 'initial');\n *\n * @overload\n * @template Target The textarea element type\n * @param {string} initialValue The initial value for the textarea\n * @returns {UseTextareaAutosizeReturn & { ref: StateRef<Target> }} An object containing ref, value, setValue and clear\n *\n * @example\n * const { ref, value, setValue, clear } = useTextareaAutosize('initial');\n *\n * @overload\n * @template Target The textarea element type\n * @param {string} [options.initialValue] The initial value for the textarea\n * @param {Function} [options.onResize] Callback function called when the textarea size changes\n * @returns {UseTextareaAutosizeReturn & { ref: StateRef<Target> }} An object containing ref, value, setValue and clear\n *\n * @example\n * const { ref, value, setValue, clear } = useTextareaAutosize();\n */\nexport const useTextareaAutosize = ((...params: any[]) => {\n const target = (isTarget(params[0]) ? params[0] : undefined) as HookTarget | undefined;\n\n const options = (\n target\n ? typeof params[1] === 'object'\n ? params[1]\n : { initialValue: params[1] }\n : typeof params[0] === 'object'\n ? params[0]\n : { initialValue: params[0] }\n ) as UseTextareaAutosizeOptions | undefined;\n\n const [value, setValue] = useState(options?.initialValue ?? '');\n const internalRef = useRefState<HTMLTextAreaElement>();\n const textareaRef = useRef<HTMLTextAreaElement | null>(null);\n const scrollHeightRef = useRef(0);\n\n const onTextareaResize = () => {\n const textarea = textareaRef.current;\n if (!textarea) return;\n\n const originalMinHeight = textarea.style.minHeight;\n const originalMaxHeight = textarea.style.maxHeight;\n\n textarea.style.height = 'auto';\n textarea.style.minHeight = 'auto';\n textarea.style.maxHeight = 'none';\n\n const scrollHeight = textarea.scrollHeight;\n\n textarea.style.height = `${scrollHeight}px`;\n textarea.style.minHeight = originalMinHeight;\n textarea.style.maxHeight = originalMaxHeight;\n\n if (scrollHeight !== scrollHeightRef.current) options?.onResize?.();\n scrollHeightRef.current = scrollHeight;\n };\n\n const setTextareaValue = (newValue: string) => {\n setValue(newValue);\n const textarea = textareaRef.current;\n if (!textarea) return;\n textarea.value = newValue;\n requestAnimationFrame(() => {\n onTextareaResize();\n });\n };\n\n useEffect(() => {\n if (!target && !internalRef.state) return;\n\n const element = (\n target ? isTarget.getElement(target) : internalRef.current\n ) as HTMLTextAreaElement;\n if (!element) return;\n\n textareaRef.current = element;\n if (options?.initialValue) element.value = options.initialValue;\n\n onTextareaResize();\n\n const onInput = (event: InputEvent) => {\n const newValue = (event.target as HTMLTextAreaElement).value;\n setTextareaValue(newValue);\n\n requestAnimationFrame(() => {\n onTextareaResize();\n });\n };\n\n const onResize = () => {\n requestAnimationFrame(() => {\n onTextareaResize();\n });\n };\n\n element.addEventListener('input', onInput as EventListener);\n element.addEventListener('resize', onResize as EventListener);\n\n return () => {\n element.removeEventListener('input', onInput as EventListener);\n element.removeEventListener('resize', onResize as EventListener);\n };\n }, [target, internalRef.state, isTarget.getRefState(target)]);\n\n const clear = () => setValue('');\n\n if (target)\n return {\n value,\n set: setTextareaValue,\n clear\n };\n return {\n ref: internalRef,\n value,\n set: setTextareaValue,\n clear\n };\n}) as UseTextareaAutosize;\n"],"names":["useTextareaAutosize","params","target","isTarget","options","value","setValue","useState","internalRef","useRefState","textareaRef","useRef","scrollHeightRef","onTextareaResize","textarea","originalMinHeight","originalMaxHeight","scrollHeight","setTextareaValue","newValue","useEffect","element","onInput","event","onResize","clear"],"mappings":"mMAwFaA,GAAuB,IAAIC,IAAkB,CACxD,MAAMC,EAAUC,EAAAA,SAASF,EAAO,CAAC,CAAC,EAAIA,EAAO,CAAC,EAAI,OAE5CG,EACJF,EACI,OAAOD,EAAO,CAAC,GAAM,SACnBA,EAAO,CAAC,EACR,CAAE,aAAcA,EAAO,CAAC,CAAA,EAC1B,OAAOA,EAAO,CAAC,GAAM,SACnBA,EAAO,CAAC,EACR,CAAE,aAAcA,EAAO,CAAC,CAAA,EAG1B,CAACI,EAAOC,CAAQ,EAAIC,EAAAA,SAASH,GAAS,cAAgB,EAAE,EACxDI,EAAcC,EAAAA,YAAA,EACdC,EAAcC,EAAAA,OAAmC,IAAI,EACrDC,EAAkBD,EAAAA,OAAO,CAAC,EAE1BE,EAAmB,IAAM,CAC7B,MAAMC,EAAWJ,EAAY,QAC7B,GAAI,CAACI,EAAU,OAEf,MAAMC,EAAoBD,EAAS,MAAM,UACnCE,EAAoBF,EAAS,MAAM,UAEzCA,EAAS,MAAM,OAAS,OACxBA,EAAS,MAAM,UAAY,OAC3BA,EAAS,MAAM,UAAY,OAE3B,MAAMG,EAAeH,EAAS,aAE9BA,EAAS,MAAM,OAAS,GAAGG,CAAY,KACvCH,EAAS,MAAM,UAAYC,EAC3BD,EAAS,MAAM,UAAYE,EAEvBC,IAAiBL,EAAgB,SAASR,GAAS,WAAA,EACvDQ,EAAgB,QAAUK,CAAA,EAGtBC,EAAoBC,GAAqB,CAC7Cb,EAASa,CAAQ,EACjB,MAAML,EAAWJ,EAAY,QACxBI,IACLA,EAAS,MAAQK,EACjB,sBAAsB,IAAM,CAC1BN,EAAA,CAAiB,CAClB,EAAA,EAGHO,EAAAA,UAAU,IAAM,CACd,GAAI,CAAClB,GAAU,CAACM,EAAY,MAAO,OAEnC,MAAMa,EACJnB,EAASC,EAAAA,SAAS,WAAWD,CAAM,EAAIM,EAAY,QAErD,GAAI,CAACa,EAAS,OAEdX,EAAY,QAAUW,EAClBjB,GAAS,eAAciB,EAAQ,MAAQjB,EAAQ,cAEnDS,EAAA,EAEA,MAAMS,EAAWC,GAAsB,CACrC,MAAMJ,EAAYI,EAAM,OAA+B,MACvDL,EAAiBC,CAAQ,EAEzB,sBAAsB,IAAM,CAC1BN,EAAA,CAAiB,CAClB,CAAA,EAGGW,EAAW,IAAM,CACrB,sBAAsB,IAAM,CAC1BX,EAAA,CAAiB,CAClB,CAAA,EAGH,OAAAQ,EAAQ,iBAAiB,QAASC,CAAwB,EAC1DD,EAAQ,iBAAiB,SAAUG,CAAyB,EAErD,IAAM,CACXH,EAAQ,oBAAoB,QAASC,CAAwB,EAC7DD,EAAQ,oBAAoB,SAAUG,CAAyB,CAAA,CACjE,EACC,CAACtB,EAAQM,EAAY,MAAOL,EAAAA,SAAS,YAAYD,CAAM,CAAC,CAAC,EAE5D,MAAMuB,EAAQ,IAAMnB,EAAS,EAAE,EAE/B,OAAIJ,EACK,CACL,MAAAG,EACA,IAAKa,EACL,MAAAO,CAAA,EAEG,CACL,IAAKjB,EACL,MAAAH,EACA,IAAKa,EACL,MAAAO,CAAA,CAEJ"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const k=require("./helpers/createContext/createContext.cjs"),v=require("./helpers/createEventEmitter/createEventEmitter.cjs"),A=require("./helpers/createReactiveContext/createReactiveContext.cjs"),h=require("./helpers/createStore/createStore.cjs"),f=require("./hooks/useAsync/useAsync.cjs"),b=require("./hooks/useLockCallback/useLockCallback.cjs"),D=require("./hooks/useMutation/useMutation.cjs"),L=require("./hooks/useOptimistic/useOptimistic.cjs"),M=require("./hooks/useQuery/useQuery.cjs"),_=require("./hooks/useAudio/useAudio.cjs"),N=require("./hooks/useBattery/useBattery.cjs"),B=require("./hooks/useBluetooth/useBluetooth.cjs"),F=require("./hooks/useBroadcastChannel/useBroadcastChannel.cjs"),K=require("./hooks/useClipboard/useClipboard.cjs"),V=require("./hooks/useCopy/useCopy.cjs"),U=require("./hooks/useCssVar/useCssVar.cjs"),w=require("./hooks/useDisplayMedia/useDisplayMedia.cjs"),H=require("./hooks/useDocumentTitle/useDocumentTitle.cjs"),x=require("./hooks/useEventSource/useEventSource.cjs"),W=require("./hooks/useEyeDropper/useEyeDropper.cjs"),z=require("./hooks/useFavicon/useFavicon.cjs"),Q=require("./hooks/useFps/useFps.cjs"),G=require("./hooks/useFullscreen/useFullscreen.cjs"),n=require("./hooks/useGamepad/useGamepad.cjs"),X=require("./hooks/useGeolocation/useGeolocation.cjs"),c=require("./hooks/useMediaControls/useMediaControls.cjs"),Z=require("./hooks/useMemory/useMemory.cjs"),a=require("./hooks/useNetwork/useNetwork.cjs"),j=require("./hooks/useOnline/useOnline.cjs"),J=require("./hooks/useOtpCredential/useOtpCredential.cjs"),Y=require("./hooks/usePermission/usePermission.cjs"),$=require("./hooks/usePictureInPicture/usePictureInPicture.cjs"),ee=require("./hooks/usePointerLock/usePointerLock.cjs"),se=require("./hooks/usePostMessage/usePostMessage.cjs"),ue=require("./hooks/useRaf/useRaf.cjs"),re=require("./hooks/useShare/useShare.cjs"),l=require("./hooks/useSpeechRecognition/useSpeechRecognition.cjs"),te=require("./hooks/useSpeechSynthesis/useSpeechSynthesis.cjs"),oe=require("./hooks/useVibrate/useVibrate.cjs"),ie=require("./hooks/useVirtualKeyboard/useVirtualKeyboard.cjs"),ne=require("./hooks/useWakeLock/useWakeLock.cjs"),ce=require("./hooks/useWebSocket/useWebSocket.cjs"),ae=require("./hooks/useLogger/useLogger.cjs"),le=require("./hooks/useRenderCount/useRenderCount.cjs"),Se=require("./hooks/useRenderInfo/useRenderInfo.cjs"),qe=require("./hooks/useRerender/useRerender.cjs"),de=require("./hooks/useActiveElement/useActiveElement.cjs"),ge=require("./hooks/useAutoScroll/useAutoScroll.cjs"),Te=require("./hooks/useClickOutside/useClickOutside.cjs"),S=require("./hooks/useDoubleClick/useDoubleClick.cjs"),Ee=require("./hooks/useDropZone/useDropZone.cjs"),Ce=require("./hooks/useFileDialog/useFileDialog.cjs"),Re=require("./hooks/useFocus/useFocus.cjs"),q=require("./hooks/useFocusTrap/useFocusTrap.cjs"),Pe=require("./hooks/useHover/useHover.cjs"),me=require("./hooks/useImage/useImage.cjs"),ye=require("./hooks/useLongPress/useLongPress.cjs"),t=require("./hooks/usePaint/usePaint.cjs"),pe=require("./hooks/useRightClick/useRightClick.cjs"),d=require("./hooks/useScript/useScript.cjs"),Ie=require("./hooks/useSticky/useSticky.cjs"),Oe=require("./hooks/useTextareaAutosize/useTextareaAutosize.cjs"),ke=require("./hooks/useTextDirection/useTextDirection.cjs"),ve=require("./hooks/useFul/useFul.cjs"),Ae=require("./hooks/useLess/useLess.cjs"),he=require("./hooks/useOnce/useOnce.cjs"),fe=require("./hooks/useAsyncEffect/useAsyncEffect.cjs"),be=require("./hooks/useDidUpdate/useDidUpdate.cjs"),De=require("./hooks/useIsFirstRender/useIsFirstRender.cjs"),Le=require("./hooks/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.cjs"),Me=require("./hooks/useMount/useMount.cjs"),g=require("./hooks/useShallowEffect/useShallowEffect.cjs"),_e=require("./hooks/useUnmount/useUnmount.cjs"),e=require("./hooks/useBreakpoints/useBreakpoints.cjs"),Ne=require("./hooks/useDeviceMotion/useDeviceMotion.cjs"),Be=require("./hooks/useDeviceOrientation/useDeviceOrientation.cjs"),Fe=require("./hooks/useDevicePixelRatio/useDevicePixelRatio.cjs"),Ke=require("./hooks/useDocumentEvent/useDocumentEvent.cjs"),Ve=require("./hooks/useDocumentVisibility/useDocumentVisibility.cjs"),Ue=require("./hooks/useElementSize/useElementSize.cjs"),we=require("./hooks/useEventListener/useEventListener.cjs"),T=require("./hooks/useHotkeys/useHotkeys.cjs"),He=require("./hooks/useIdle/useIdle.cjs"),xe=require("./hooks/useInfiniteScroll/useInfiniteScroll.cjs"),We=require("./hooks/useIntersectionObserver/useIntersectionObserver.cjs"),ze=require("./hooks/useKeyboard/useKeyboard.cjs"),Qe=require("./hooks/useKeyPress/useKeyPress.cjs"),Ge=require("./hooks/useKeyPressEvent/useKeyPressEvent.cjs"),Xe=require("./hooks/useKeysPressed/useKeysPressed.cjs"),Ze=require("./hooks/useLockScroll/useLockScroll.cjs"),je=require("./hooks/useMeasure/useMeasure.cjs"),Je=require("./hooks/useMediaQuery/useMediaQuery.cjs"),Ye=require("./hooks/useMouse/useMouse.cjs"),$e=require("./hooks/useMutationObserver/useMutationObserver.cjs"),es=require("./hooks/useOrientation/useOrientation.cjs"),ss=require("./hooks/usePageLeave/usePageLeave.cjs"),us=require("./hooks/useParallax/useParallax.cjs"),rs=require("./hooks/usePerformanceObserver/usePerformanceObserver.cjs"),ts=require("./hooks/useResizeObserver/useResizeObserver.cjs"),os=require("./hooks/useScroll/useScroll.cjs"),is=require("./hooks/useScrollIntoView/useScrollIntoView.cjs"),ns=require("./hooks/useScrollTo/useScrollTo.cjs"),E=require("./hooks/useTextSelection/useTextSelection.cjs"),cs=require("./hooks/useVisibility/useVisibility.cjs"),as=require("./hooks/useWindowEvent/useWindowEvent.cjs"),ls=require("./hooks/useWindowFocus/useWindowFocus.cjs"),C=require("./hooks/useWindowScroll/useWindowScroll.cjs"),Ss=require("./hooks/useWindowSize/useWindowSize.cjs"),qs=require("./hooks/useBoolean/useBoolean.cjs"),ds=require("./hooks/useControllableState/useControllableState.cjs"),s=require("./hooks/useCookie/useCookie.cjs"),R=require("./hooks/useCookies/useCookies.cjs"),gs=require("./hooks/useCounter/useCounter.cjs"),Ts=require("./hooks/useDefault/useDefault.cjs"),Es=require("./hooks/useDisclosure/useDisclosure.cjs"),Cs=require("./hooks/useField/useField.cjs"),P=require("./hooks/useHash/useHash.cjs"),Rs=require("./hooks/useList/useList.cjs"),Ps=require("./hooks/useLocalStorage/useLocalStorage.cjs"),ms=require("./hooks/useMap/useMap.cjs"),o=require("./hooks/useMergedRef/useMergedRef.cjs"),ys=require("./hooks/useOffsetPagination/useOffsetPagination.cjs"),ps=require("./hooks/useQueue/useQueue.cjs"),Is=require("./hooks/useRafState/useRafState.cjs"),m=require("./hooks/useRefState/useRefState.cjs"),Os=require("./hooks/useSessionStorage/useSessionStorage.cjs"),ks=require("./hooks/useSet/useSet.cjs"),y=require("./hooks/useStateHistory/useStateHistory.cjs"),vs=require("./hooks/useStep/useStep.cjs"),i=require("./hooks/useStorage/useStorage.cjs"),As=require("./hooks/useToggle/useToggle.cjs"),u=require("./hooks/useUrlSearchParam/useUrlSearchParam.cjs"),hs=require("./hooks/useUrlSearchParams/useUrlSearchParams.cjs"),fs=require("./hooks/useWizard/useWizard.cjs"),bs=require("./hooks/useInterval/useInterval.cjs"),Ds=require("./hooks/useStopwatch/useStopwatch.cjs"),Ls=require("./hooks/useTime/useTime.cjs"),Ms=require("./hooks/useTimeout/useTimeout.cjs"),p=require("./hooks/useTimer/useTimer.cjs"),_s=require("./hooks/useBrowserLanguage/useBrowserLanguage.cjs"),I=require("./hooks/useOperatingSystem/useOperatingSystem.cjs"),Ns=require("./hooks/usePreferredColorScheme/usePreferredColorScheme.cjs"),Bs=require("./hooks/usePreferredContrast/usePreferredContrast.cjs"),Fs=require("./hooks/usePreferredDark/usePreferredDark.cjs"),Ks=require("./hooks/usePreferredLanguages/usePreferredLanguages.cjs"),Vs=require("./hooks/usePreferredReducedMotion/usePreferredReducedMotion.cjs"),Us=require("./hooks/useConst/useConst.cjs"),ws=require("./hooks/useDebounceCallback/useDebounceCallback.cjs"),Hs=require("./hooks/useDebounceState/useDebounceState.cjs"),xs=require("./hooks/useDebounceValue/useDebounceValue.cjs"),Ws=require("./hooks/useEvent/useEvent.cjs"),zs=require("./hooks/useLastChanged/useLastChanged.cjs"),Qs=require("./hooks/useLatest/useLatest.cjs"),Gs=require("./hooks/usePrevious/usePrevious.cjs"),Xs=require("./hooks/useThrottleCallback/useThrottleCallback.cjs"),Zs=require("./hooks/useThrottleState/useThrottleState.cjs"),js=require("./hooks/useThrottleValue/useThrottleValue.cjs"),O=require("./utils/helpers/copy.cjs"),Js=require("./utils/helpers/debounce.cjs"),Ys=require("./utils/helpers/getDate.cjs"),$s=require("./utils/helpers/getRetry.cjs"),r=require("./utils/helpers/isTarget.cjs"),eu=require("./utils/helpers/throttle.cjs");exports.createContext=k.createContext;exports.createEventEmitter=v.createEventEmitter;exports.createReactiveContext=A.createReactiveContext;exports.createStore=h.createStore;exports.useAsync=f.useAsync;exports.useLockCallback=b.useLockCallback;exports.useMutation=D.useMutation;exports.useOptimistic=L.useOptimistic;exports.useQuery=M.useQuery;exports.useAudio=_.useAudio;exports.useBattery=N.useBattery;exports.useBluetooth=B.useBluetooth;exports.useBroadcastChannel=F.useBroadcastChannel;exports.useClipboard=K.useClipboard;exports.useCopy=V.useCopy;exports.useCssVar=U.useCssVar;exports.useDisplayMedia=w.useDisplayMedia;exports.useDocumentTitle=H.useDocumentTitle;exports.useEventSource=x.useEventSource;exports.useEyeDropper=W.useEyeDropper;exports.useFavicon=z.useFavicon;exports.useFps=Q.useFps;exports.useFullscreen=G.useFullscreen;exports.mapGamepadToXbox360Controller=n.mapGamepadToXbox360Controller;exports.useGamepad=n.useGamepad;exports.useGeolocation=X.useGeolocation;exports.timeRangeToArray=c.timeRangeToArray;exports.useMediaControls=c.useMediaControls;exports.useMemory=Z.useMemory;exports.getConnection=a.getConnection;exports.useNetwork=a.useNetwork;exports.useOnline=j.useOnline;exports.useOtpCredential=J.useOtpCredential;exports.usePermission=Y.usePermission;exports.usePictureInPicture=$.usePictureInPicture;exports.usePointerLock=ee.usePointerLock;exports.usePostMessage=se.usePostMessage;exports.useRaf=ue.useRaf;exports.useShare=re.useShare;exports.getSpeechRecognition=l.getSpeechRecognition;exports.useSpeechRecognition=l.useSpeechRecognition;exports.useSpeechSynthesis=te.useSpeechSynthesis;exports.useVibrate=oe.useVibrate;exports.useVirtualKeyboard=ie.useVirtualKeyboard;exports.useWakeLock=ne.useWakeLock;exports.useWebSocket=ce.useWebSocket;exports.useLogger=ae.useLogger;exports.useRenderCount=le.useRenderCount;exports.useRenderInfo=Se.useRenderInfo;exports.useRerender=qe.useRerender;exports.useActiveElement=de.useActiveElement;exports.useAutoScroll=ge.useAutoScroll;exports.useClickOutside=Te.useClickOutside;exports.DEFAULT_THRESHOLD_TIME=S.DEFAULT_THRESHOLD_TIME;exports.useDoubleClick=S.useDoubleClick;exports.useDropZone=Ee.useDropZone;exports.useFileDialog=Ce.useFileDialog;exports.useFocus=Re.useFocus;exports.FOCUS_SELECTOR=q.FOCUS_SELECTOR;exports.useFocusTrap=q.useFocusTrap;exports.useHover=Pe.useHover;exports.useImage=me.useImage;exports.useLongPress=ye.useLongPress;exports.Paint=t.Paint;exports.Pointer=t.Pointer;exports.usePaint=t.usePaint;exports.useRightClick=pe.useRightClick;exports.SCRIPT_STATUS_ATTRIBUTE_NAME=d.SCRIPT_STATUS_ATTRIBUTE_NAME;exports.useScript=d.useScript;exports.useSticky=Ie.useSticky;exports.useTextareaAutosize=Oe.useTextareaAutosize;exports.useTextDirection=ke.useTextDirection;exports.useFul=ve.useFul;exports.useLess=Ae.useLess;exports.useOnce=he.useOnce;exports.useAsyncEffect=fe.useAsyncEffect;exports.useDidUpdate=be.useDidUpdate;exports.useIsFirstRender=De.useIsFirstRender;exports.useIsomorphicLayoutEffect=Le.useIsomorphicLayoutEffect;exports.useMount=Me.useMount;exports.deepEqual=g.deepEqual;exports.useShallowEffect=g.useShallowEffect;exports.useUnmount=_e.useUnmount;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.useDeviceMotion=Ne.useDeviceMotion;exports.useDeviceOrientation=Be.useDeviceOrientation;exports.useDevicePixelRatio=Fe.useDevicePixelRatio;exports.useDocumentEvent=Ke.useDocumentEvent;exports.useDocumentVisibility=Ve.useDocumentVisibility;exports.useElementSize=Ue.useElementSize;exports.useEventListener=we.useEventListener;exports.isHotkeyMatch=T.isHotkeyMatch;exports.useHotkeys=T.useHotkeys;exports.useIdle=He.useIdle;exports.useInfiniteScroll=xe.useInfiniteScroll;exports.useIntersectionObserver=We.useIntersectionObserver;exports.useKeyboard=ze.useKeyboard;exports.useKeyPress=Qe.useKeyPress;exports.useKeyPressEvent=Ge.useKeyPressEvent;exports.useKeysPressed=Xe.useKeysPressed;exports.useLockScroll=Ze.useLockScroll;exports.useMeasure=je.useMeasure;exports.useMediaQuery=Je.useMediaQuery;exports.useMouse=Ye.useMouse;exports.useMutationObserver=$e.useMutationObserver;exports.useOrientation=es.useOrientation;exports.usePageLeave=ss.usePageLeave;exports.useParallax=us.useParallax;exports.usePerformanceObserver=rs.usePerformanceObserver;exports.useResizeObserver=ts.useResizeObserver;exports.useScroll=os.useScroll;exports.useScrollIntoView=is.useScrollIntoView;exports.useScrollTo=ns.useScrollTo;exports.getRangesSelection=E.getRangesSelection;exports.useTextSelection=E.useTextSelection;exports.useVisibility=cs.useVisibility;exports.useWindowEvent=as.useWindowEvent;exports.useWindowFocus=ls.useWindowFocus;exports.scrollTo=C.scrollTo;exports.useWindowScroll=C.useWindowScroll;exports.useWindowSize=Ss.useWindowSize;exports.useBoolean=qs.useBoolean;exports.useControllableState=ds.useControllableState;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=R.clearCookies;exports.useCookies=R.useCookies;exports.useCounter=gs.useCounter;exports.useDefault=Ts.useDefault;exports.useDisclosure=Es.useDisclosure;exports.useField=Cs.useField;exports.getHash=P.getHash;exports.useHash=P.useHash;exports.useList=Rs.useList;exports.useLocalStorage=Ps.useLocalStorage;exports.useMap=ms.useMap;exports.assignRef=o.assignRef;exports.mergeRefs=o.mergeRefs;exports.useMergedRef=o.useMergedRef;exports.useOffsetPagination=ys.useOffsetPagination;exports.useQueue=ps.useQueue;exports.useRafState=Is.useRafState;exports.createRefState=m.createRefState;exports.useRefState=m.useRefState;exports.useSessionStorage=Os.useSessionStorage;exports.useSet=ks.useSet;exports.stateHistoryReducer=y.stateHistoryReducer;exports.useStateHistory=y.useStateHistory;exports.useStep=vs.useStep;exports.STORAGE_EVENT=i.STORAGE_EVENT;exports.dispatchStorageEvent=i.dispatchStorageEvent;exports.useStorage=i.useStorage;exports.useToggle=As.useToggle;exports.URL_SEARCH_PARAMS_EVENT=u.URL_SEARCH_PARAMS_EVENT;exports.createQueryString=u.createQueryString;exports.dispatchUrlSearchParamsEvent=u.dispatchUrlSearchParamsEvent;exports.getUrlSearchParams=u.getUrlSearchParams;exports.useUrlSearchParam=u.useUrlSearchParam;exports.useUrlSearchParams=hs.useUrlSearchParams;exports.useWizard=fs.useWizard;exports.useInterval=bs.useInterval;exports.useStopwatch=Ds.useStopwatch;exports.useTime=Ls.useTime;exports.useTimeout=Ms.useTimeout;exports.getTimeFromSeconds=p.getTimeFromSeconds;exports.useTimer=p.useTimer;exports.useBrowserLanguage=_s.useBrowserLanguage;exports.getOperatingSystem=I.getOperatingSystem;exports.useOperatingSystem=I.useOperatingSystem;exports.usePreferredColorScheme=Ns.usePreferredColorScheme;exports.usePreferredContrast=Bs.usePreferredContrast;exports.usePreferredDark=Fs.usePreferredDark;exports.usePreferredLanguages=Ks.usePreferredLanguages;exports.usePreferredReducedMotion=Vs.usePreferredReducedMotion;exports.useConst=Us.useConst;exports.useDebounceCallback=ws.useDebounceCallback;exports.useDebounceState=Hs.useDebounceState;exports.useDebounceValue=xs.useDebounceValue;exports.useEvent=Ws.useEvent;exports.useLastChanged=zs.useLastChanged;exports.useLatest=Qs.useLatest;exports.usePrevious=Gs.usePrevious;exports.useThrottleCallback=Xs.useThrottleCallback;exports.useThrottleState=Zs.useThrottleState;exports.useThrottleValue=js.useThrottleValue;exports.copy=O.copy;exports.legacyCopyToClipboard=O.legacyCopyToClipboard;exports.debounce=Js.debounce;exports.getDate=Ys.getDate;exports.getRetry=$s.getRetry;exports.getRefState=r.getRefState;exports.isTarget=r.isTarget;exports.target=r.target;exports.targetSymbol=r.targetSymbol;exports.throttle=eu.throttle;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const I=require("./helpers/createContext/createContext.cjs"),O=require("./helpers/createEventEmitter/createEventEmitter.cjs"),v=require("./helpers/createReactiveContext/createReactiveContext.cjs"),A=require("./helpers/createStore/createStore.cjs"),f=require("./hooks/useAsync/useAsync.cjs"),b=require("./hooks/useLockCallback/useLockCallback.cjs"),D=require("./hooks/useMutation/useMutation.cjs"),L=require("./hooks/useOptimistic/useOptimistic.cjs"),M=require("./hooks/useQuery/useQuery.cjs"),_=require("./hooks/useAudio/useAudio.cjs"),B=require("./hooks/useBattery/useBattery.cjs"),N=require("./hooks/useBluetooth/useBluetooth.cjs"),F=require("./hooks/useBroadcastChannel/useBroadcastChannel.cjs"),K=require("./hooks/useClipboard/useClipboard.cjs"),V=require("./hooks/useCopy/useCopy.cjs"),U=require("./hooks/useCssVar/useCssVar.cjs"),w=require("./hooks/useDisplayMedia/useDisplayMedia.cjs"),H=require("./hooks/useDocumentTitle/useDocumentTitle.cjs"),x=require("./hooks/useEventSource/useEventSource.cjs"),W=require("./hooks/useEyeDropper/useEyeDropper.cjs"),z=require("./hooks/useFavicon/useFavicon.cjs"),Q=require("./hooks/useFps/useFps.cjs"),G=require("./hooks/useFullscreen/useFullscreen.cjs"),n=require("./hooks/useGamepad/useGamepad.cjs"),X=require("./hooks/useGeolocation/useGeolocation.cjs"),c=require("./hooks/useMediaControls/useMediaControls.cjs"),Z=require("./hooks/useMemory/useMemory.cjs"),a=require("./hooks/useNetwork/useNetwork.cjs"),j=require("./hooks/useOnline/useOnline.cjs"),J=require("./hooks/useOtpCredential/useOtpCredential.cjs"),Y=require("./hooks/usePermission/usePermission.cjs"),$=require("./hooks/usePictureInPicture/usePictureInPicture.cjs"),ee=require("./hooks/usePointerLock/usePointerLock.cjs"),se=require("./hooks/usePostMessage/usePostMessage.cjs"),ue=require("./hooks/useRaf/useRaf.cjs"),re=require("./hooks/useShare/useShare.cjs"),l=require("./hooks/useSpeechRecognition/useSpeechRecognition.cjs"),te=require("./hooks/useSpeechSynthesis/useSpeechSynthesis.cjs"),oe=require("./hooks/useVibrate/useVibrate.cjs"),ie=require("./hooks/useVirtualKeyboard/useVirtualKeyboard.cjs"),ne=require("./hooks/useWakeLock/useWakeLock.cjs"),ce=require("./hooks/useWebSocket/useWebSocket.cjs"),ae=require("./hooks/useLogger/useLogger.cjs"),le=require("./hooks/useRenderCount/useRenderCount.cjs"),Se=require("./hooks/useRenderInfo/useRenderInfo.cjs"),qe=require("./hooks/useRerender/useRerender.cjs"),de=require("./hooks/useActiveElement/useActiveElement.cjs"),ge=require("./hooks/useAutoScroll/useAutoScroll.cjs"),Te=require("./hooks/useClickOutside/useClickOutside.cjs"),S=require("./hooks/useDoubleClick/useDoubleClick.cjs"),Ee=require("./hooks/useDropZone/useDropZone.cjs"),Ce=require("./hooks/useFileDialog/useFileDialog.cjs"),Re=require("./hooks/useFocus/useFocus.cjs"),q=require("./hooks/useFocusTrap/useFocusTrap.cjs"),Pe=require("./hooks/useHover/useHover.cjs"),me=require("./hooks/useImage/useImage.cjs"),ye=require("./hooks/useLongPress/useLongPress.cjs"),t=require("./hooks/usePaint/usePaint.cjs"),pe=require("./hooks/useRightClick/useRightClick.cjs"),d=require("./hooks/useScript/useScript.cjs"),ke=require("./hooks/useSticky/useSticky.cjs"),he=require("./hooks/useTextareaAutosize/useTextareaAutosize.cjs"),Ie=require("./hooks/useTextDirection/useTextDirection.cjs"),Oe=require("./hooks/useFul/useFul.cjs"),ve=require("./hooks/useLess/useLess.cjs"),Ae=require("./hooks/useOnce/useOnce.cjs"),fe=require("./hooks/useAsyncEffect/useAsyncEffect.cjs"),be=require("./hooks/useDidUpdate/useDidUpdate.cjs"),De=require("./hooks/useIsFirstRender/useIsFirstRender.cjs"),Le=require("./hooks/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.cjs"),Me=require("./hooks/useMount/useMount.cjs"),g=require("./hooks/useShallowEffect/useShallowEffect.cjs"),_e=require("./hooks/useUnmount/useUnmount.cjs"),e=require("./hooks/useBreakpoints/useBreakpoints.cjs"),Be=require("./hooks/useDeviceMotion/useDeviceMotion.cjs"),Ne=require("./hooks/useDeviceOrientation/useDeviceOrientation.cjs"),Fe=require("./hooks/useDevicePixelRatio/useDevicePixelRatio.cjs"),Ke=require("./hooks/useDocumentEvent/useDocumentEvent.cjs"),Ve=require("./hooks/useDocumentVisibility/useDocumentVisibility.cjs"),Ue=require("./hooks/useElementSize/useElementSize.cjs"),we=require("./hooks/useEventListener/useEventListener.cjs"),T=require("./hooks/useHotkeys/useHotkeys.cjs"),He=require("./hooks/useIdle/useIdle.cjs"),xe=require("./hooks/useInfiniteScroll/useInfiniteScroll.cjs"),We=require("./hooks/useIntersectionObserver/useIntersectionObserver.cjs"),ze=require("./hooks/useKeyboard/useKeyboard.cjs"),Qe=require("./hooks/useKeyPress/useKeyPress.cjs"),Ge=require("./hooks/useKeyPressEvent/useKeyPressEvent.cjs"),Xe=require("./hooks/useKeysPressed/useKeysPressed.cjs"),Ze=require("./hooks/useLockScroll/useLockScroll.cjs"),je=require("./hooks/useMeasure/useMeasure.cjs"),Je=require("./hooks/useMediaQuery/useMediaQuery.cjs"),Ye=require("./hooks/useMouse/useMouse.cjs"),$e=require("./hooks/useMutationObserver/useMutationObserver.cjs"),es=require("./hooks/useOrientation/useOrientation.cjs"),ss=require("./hooks/usePageLeave/usePageLeave.cjs"),us=require("./hooks/useParallax/useParallax.cjs"),rs=require("./hooks/usePerformanceObserver/usePerformanceObserver.cjs"),ts=require("./hooks/useResizeObserver/useResizeObserver.cjs"),os=require("./hooks/useScroll/useScroll.cjs"),is=require("./hooks/useScrollIntoView/useScrollIntoView.cjs"),ns=require("./hooks/useScrollTo/useScrollTo.cjs"),E=require("./hooks/useTextSelection/useTextSelection.cjs"),cs=require("./hooks/useVisibility/useVisibility.cjs"),as=require("./hooks/useWindowEvent/useWindowEvent.cjs"),ls=require("./hooks/useWindowFocus/useWindowFocus.cjs"),C=require("./hooks/useWindowScroll/useWindowScroll.cjs"),Ss=require("./hooks/useWindowSize/useWindowSize.cjs"),qs=require("./hooks/useBoolean/useBoolean.cjs"),ds=require("./hooks/useControllableState/useControllableState.cjs"),s=require("./hooks/useCookie/useCookie.cjs"),R=require("./hooks/useCookies/useCookies.cjs"),gs=require("./hooks/useCounter/useCounter.cjs"),Ts=require("./hooks/useDefault/useDefault.cjs"),Es=require("./hooks/useDisclosure/useDisclosure.cjs"),Cs=require("./hooks/useField/useField.cjs"),P=require("./hooks/useHash/useHash.cjs"),Rs=require("./hooks/useList/useList.cjs"),Ps=require("./hooks/useLocalStorage/useLocalStorage.cjs"),ms=require("./hooks/useMap/useMap.cjs"),o=require("./hooks/useMergedRef/useMergedRef.cjs"),ys=require("./hooks/useOffsetPagination/useOffsetPagination.cjs"),ps=require("./hooks/useQueue/useQueue.cjs"),ks=require("./hooks/useRafState/useRafState.cjs"),m=require("./hooks/useRefState/useRefState.cjs"),hs=require("./hooks/useSessionStorage/useSessionStorage.cjs"),Is=require("./hooks/useSet/useSet.cjs"),y=require("./hooks/useStateHistory/useStateHistory.cjs"),Os=require("./hooks/useStep/useStep.cjs"),i=require("./hooks/useStorage/useStorage.cjs"),vs=require("./hooks/useToggle/useToggle.cjs"),u=require("./hooks/useUrlSearchParam/useUrlSearchParam.cjs"),As=require("./hooks/useUrlSearchParams/useUrlSearchParams.cjs"),fs=require("./hooks/useWizard/useWizard.cjs"),bs=require("./hooks/useInterval/useInterval.cjs"),Ds=require("./hooks/useStopwatch/useStopwatch.cjs"),Ls=require("./hooks/useTime/useTime.cjs"),Ms=require("./hooks/useTimeout/useTimeout.cjs"),p=require("./hooks/useTimer/useTimer.cjs"),_s=require("./hooks/useBrowserLanguage/useBrowserLanguage.cjs"),k=require("./hooks/useOperatingSystem/useOperatingSystem.cjs"),Bs=require("./hooks/usePreferredColorScheme/usePreferredColorScheme.cjs"),Ns=require("./hooks/usePreferredContrast/usePreferredContrast.cjs"),Fs=require("./hooks/usePreferredDark/usePreferredDark.cjs"),Ks=require("./hooks/usePreferredLanguages/usePreferredLanguages.cjs"),Vs=require("./hooks/usePreferredReducedMotion/usePreferredReducedMotion.cjs"),Us=require("./hooks/useBatchedCallback/useBatchedCallback.cjs"),ws=require("./hooks/useConst/useConst.cjs"),Hs=require("./hooks/useDebounceCallback/useDebounceCallback.cjs"),xs=require("./hooks/useDebounceState/useDebounceState.cjs"),Ws=require("./hooks/useDebounceValue/useDebounceValue.cjs"),zs=require("./hooks/useEvent/useEvent.cjs"),Qs=require("./hooks/useLastChanged/useLastChanged.cjs"),Gs=require("./hooks/useLatest/useLatest.cjs"),Xs=require("./hooks/usePrevious/usePrevious.cjs"),Zs=require("./hooks/useThrottleCallback/useThrottleCallback.cjs"),js=require("./hooks/useThrottleState/useThrottleState.cjs"),Js=require("./hooks/useThrottleValue/useThrottleValue.cjs"),h=require("./utils/helpers/copy.cjs"),Ys=require("./utils/helpers/debounce.cjs"),$s=require("./utils/helpers/getDate.cjs"),eu=require("./utils/helpers/getRetry.cjs"),r=require("./utils/helpers/isTarget.cjs"),su=require("./utils/helpers/throttle.cjs");exports.createContext=I.createContext;exports.createEventEmitter=O.createEventEmitter;exports.createReactiveContext=v.createReactiveContext;exports.createStore=A.createStore;exports.useAsync=f.useAsync;exports.useLockCallback=b.useLockCallback;exports.useMutation=D.useMutation;exports.useOptimistic=L.useOptimistic;exports.useQuery=M.useQuery;exports.useAudio=_.useAudio;exports.useBattery=B.useBattery;exports.useBluetooth=N.useBluetooth;exports.useBroadcastChannel=F.useBroadcastChannel;exports.useClipboard=K.useClipboard;exports.useCopy=V.useCopy;exports.useCssVar=U.useCssVar;exports.useDisplayMedia=w.useDisplayMedia;exports.useDocumentTitle=H.useDocumentTitle;exports.useEventSource=x.useEventSource;exports.useEyeDropper=W.useEyeDropper;exports.useFavicon=z.useFavicon;exports.useFps=Q.useFps;exports.useFullscreen=G.useFullscreen;exports.mapGamepadToXbox360Controller=n.mapGamepadToXbox360Controller;exports.useGamepad=n.useGamepad;exports.useGeolocation=X.useGeolocation;exports.timeRangeToArray=c.timeRangeToArray;exports.useMediaControls=c.useMediaControls;exports.useMemory=Z.useMemory;exports.getConnection=a.getConnection;exports.useNetwork=a.useNetwork;exports.useOnline=j.useOnline;exports.useOtpCredential=J.useOtpCredential;exports.usePermission=Y.usePermission;exports.usePictureInPicture=$.usePictureInPicture;exports.usePointerLock=ee.usePointerLock;exports.usePostMessage=se.usePostMessage;exports.useRaf=ue.useRaf;exports.useShare=re.useShare;exports.getSpeechRecognition=l.getSpeechRecognition;exports.useSpeechRecognition=l.useSpeechRecognition;exports.useSpeechSynthesis=te.useSpeechSynthesis;exports.useVibrate=oe.useVibrate;exports.useVirtualKeyboard=ie.useVirtualKeyboard;exports.useWakeLock=ne.useWakeLock;exports.useWebSocket=ce.useWebSocket;exports.useLogger=ae.useLogger;exports.useRenderCount=le.useRenderCount;exports.useRenderInfo=Se.useRenderInfo;exports.useRerender=qe.useRerender;exports.useActiveElement=de.useActiveElement;exports.useAutoScroll=ge.useAutoScroll;exports.useClickOutside=Te.useClickOutside;exports.DEFAULT_THRESHOLD_TIME=S.DEFAULT_THRESHOLD_TIME;exports.useDoubleClick=S.useDoubleClick;exports.useDropZone=Ee.useDropZone;exports.useFileDialog=Ce.useFileDialog;exports.useFocus=Re.useFocus;exports.FOCUS_SELECTOR=q.FOCUS_SELECTOR;exports.useFocusTrap=q.useFocusTrap;exports.useHover=Pe.useHover;exports.useImage=me.useImage;exports.useLongPress=ye.useLongPress;exports.Paint=t.Paint;exports.Pointer=t.Pointer;exports.usePaint=t.usePaint;exports.useRightClick=pe.useRightClick;exports.SCRIPT_STATUS_ATTRIBUTE_NAME=d.SCRIPT_STATUS_ATTRIBUTE_NAME;exports.useScript=d.useScript;exports.useSticky=ke.useSticky;exports.useTextareaAutosize=he.useTextareaAutosize;exports.useTextDirection=Ie.useTextDirection;exports.useFul=Oe.useFul;exports.useLess=ve.useLess;exports.useOnce=Ae.useOnce;exports.useAsyncEffect=fe.useAsyncEffect;exports.useDidUpdate=be.useDidUpdate;exports.useIsFirstRender=De.useIsFirstRender;exports.useIsomorphicLayoutEffect=Le.useIsomorphicLayoutEffect;exports.useMount=Me.useMount;exports.deepEqual=g.deepEqual;exports.useShallowEffect=g.useShallowEffect;exports.useUnmount=_e.useUnmount;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.useDeviceMotion=Be.useDeviceMotion;exports.useDeviceOrientation=Ne.useDeviceOrientation;exports.useDevicePixelRatio=Fe.useDevicePixelRatio;exports.useDocumentEvent=Ke.useDocumentEvent;exports.useDocumentVisibility=Ve.useDocumentVisibility;exports.useElementSize=Ue.useElementSize;exports.useEventListener=we.useEventListener;exports.isHotkeyMatch=T.isHotkeyMatch;exports.useHotkeys=T.useHotkeys;exports.useIdle=He.useIdle;exports.useInfiniteScroll=xe.useInfiniteScroll;exports.useIntersectionObserver=We.useIntersectionObserver;exports.useKeyboard=ze.useKeyboard;exports.useKeyPress=Qe.useKeyPress;exports.useKeyPressEvent=Ge.useKeyPressEvent;exports.useKeysPressed=Xe.useKeysPressed;exports.useLockScroll=Ze.useLockScroll;exports.useMeasure=je.useMeasure;exports.useMediaQuery=Je.useMediaQuery;exports.useMouse=Ye.useMouse;exports.useMutationObserver=$e.useMutationObserver;exports.useOrientation=es.useOrientation;exports.usePageLeave=ss.usePageLeave;exports.useParallax=us.useParallax;exports.usePerformanceObserver=rs.usePerformanceObserver;exports.useResizeObserver=ts.useResizeObserver;exports.useScroll=os.useScroll;exports.useScrollIntoView=is.useScrollIntoView;exports.useScrollTo=ns.useScrollTo;exports.getRangesSelection=E.getRangesSelection;exports.useTextSelection=E.useTextSelection;exports.useVisibility=cs.useVisibility;exports.useWindowEvent=as.useWindowEvent;exports.useWindowFocus=ls.useWindowFocus;exports.scrollTo=C.scrollTo;exports.useWindowScroll=C.useWindowScroll;exports.useWindowSize=Ss.useWindowSize;exports.useBoolean=qs.useBoolean;exports.useControllableState=ds.useControllableState;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=R.clearCookies;exports.useCookies=R.useCookies;exports.useCounter=gs.useCounter;exports.useDefault=Ts.useDefault;exports.useDisclosure=Es.useDisclosure;exports.useField=Cs.useField;exports.getHash=P.getHash;exports.useHash=P.useHash;exports.useList=Rs.useList;exports.useLocalStorage=Ps.useLocalStorage;exports.useMap=ms.useMap;exports.assignRef=o.assignRef;exports.mergeRefs=o.mergeRefs;exports.useMergedRef=o.useMergedRef;exports.useOffsetPagination=ys.useOffsetPagination;exports.useQueue=ps.useQueue;exports.useRafState=ks.useRafState;exports.createRefState=m.createRefState;exports.useRefState=m.useRefState;exports.useSessionStorage=hs.useSessionStorage;exports.useSet=Is.useSet;exports.stateHistoryReducer=y.stateHistoryReducer;exports.useStateHistory=y.useStateHistory;exports.useStep=Os.useStep;exports.STORAGE_EVENT=i.STORAGE_EVENT;exports.dispatchStorageEvent=i.dispatchStorageEvent;exports.useStorage=i.useStorage;exports.useToggle=vs.useToggle;exports.URL_SEARCH_PARAMS_EVENT=u.URL_SEARCH_PARAMS_EVENT;exports.createQueryString=u.createQueryString;exports.dispatchUrlSearchParamsEvent=u.dispatchUrlSearchParamsEvent;exports.getUrlSearchParams=u.getUrlSearchParams;exports.useUrlSearchParam=u.useUrlSearchParam;exports.useUrlSearchParams=As.useUrlSearchParams;exports.useWizard=fs.useWizard;exports.useInterval=bs.useInterval;exports.useStopwatch=Ds.useStopwatch;exports.useTime=Ls.useTime;exports.useTimeout=Ms.useTimeout;exports.getTimeFromSeconds=p.getTimeFromSeconds;exports.useTimer=p.useTimer;exports.useBrowserLanguage=_s.useBrowserLanguage;exports.getOperatingSystem=k.getOperatingSystem;exports.useOperatingSystem=k.useOperatingSystem;exports.usePreferredColorScheme=Bs.usePreferredColorScheme;exports.usePreferredContrast=Ns.usePreferredContrast;exports.usePreferredDark=Fs.usePreferredDark;exports.usePreferredLanguages=Ks.usePreferredLanguages;exports.usePreferredReducedMotion=Vs.usePreferredReducedMotion;exports.useBatchedCallback=Us.useBatchedCallback;exports.useConst=ws.useConst;exports.useDebounceCallback=Hs.useDebounceCallback;exports.useDebounceState=xs.useDebounceState;exports.useDebounceValue=Ws.useDebounceValue;exports.useEvent=zs.useEvent;exports.useLastChanged=Qs.useLastChanged;exports.useLatest=Gs.useLatest;exports.usePrevious=Xs.usePrevious;exports.useThrottleCallback=Zs.useThrottleCallback;exports.useThrottleState=js.useThrottleState;exports.useThrottleValue=Js.useThrottleValue;exports.copy=h.copy;exports.legacyCopyToClipboard=h.legacyCopyToClipboard;exports.debounce=Ys.debounce;exports.getDate=$s.getDate;exports.getRetry=eu.getRetry;exports.getRefState=r.getRefState;exports.isTarget=r.isTarget;exports.target=r.target;exports.targetSymbol=r.targetSymbol;exports.throttle=su.throttle;
2
2
  //# sourceMappingURL=index.cjs.map
@@ -1,25 +1,26 @@
1
1
  import { useSyncExternalStore as p } from "react";
2
2
  const b = (o) => {
3
- let e;
4
- const r = /* @__PURE__ */ new Set(), c = (t) => {
3
+ let e, r;
4
+ const i = /* @__PURE__ */ new Set(), c = (t) => {
5
5
  const n = typeof t == "function" ? t(e) : t;
6
6
  if (!Object.is(n, e)) {
7
- const a = e;
8
- e = typeof n != "object" || n === null || Array.isArray(n) ? n : Object.assign({}, e, n), r.forEach((S) => S(e, a));
7
+ const S = e;
8
+ e = typeof n != "object" || n === null || Array.isArray(n) ? n : Object.assign({}, e, n), i.forEach((l) => l(e, S));
9
9
  }
10
- }, u = (t) => (r.add(t), () => r.delete(t)), s = () => e, f = () => e;
11
- typeof o == "function" ? e = o(c, s) : e = o;
12
- function i(t) {
10
+ }, u = (t) => (i.add(t), () => i.delete(t)), s = () => e, a = () => r;
11
+ typeof o == "function" ? r = e = o(c, s) : r = e = o;
12
+ function f(t) {
13
13
  return p(
14
14
  u,
15
15
  () => t ? t(s()) : s(),
16
- () => t ? t(f()) : f()
16
+ () => t ? t(a()) : a()
17
17
  );
18
18
  }
19
19
  return {
20
20
  set: c,
21
21
  get: s,
22
- use: i,
22
+ getInitial: a,
23
+ use: f,
23
24
  subscribe: u
24
25
  };
25
26
  };
@@ -1 +1 @@
1
- {"version":3,"file":"createStore.mjs","sources":["../../../../src/helpers/createStore/createStore.ts"],"sourcesContent":["import { useSyncExternalStore } from 'react';\n\ntype StoreSetAction<Value> = ((prev: Value) => Partial<Value>) | Partial<Value>;\n\ntype StoreListener<Value> = (state: Value, prevState: Value) => void;\n\ntype StoreCreator<Value> = (\n set: (action: StoreSetAction<Value>) => void,\n get: () => Value\n) => Value;\n\nexport interface StoreApi<Value> {\n getInitialState: () => Value;\n getState: () => Value;\n setState: (action: StoreSetAction<Value>) => void;\n subscribe: (listener: StoreListener<Value>) => () => void;\n}\n\n/**\n * @name createStore\n * @description - Creates a store with state management capabilities\n * @category Helpers\n * @usage medium\n *\n * @template Value - The type of the store state\n * @param {StateCreator<Value>} createState - Function that initializes the store state\n * @returns {StoreApi<Value>} - Object containing store methods and hook for accessing state\n *\n * @example\n * const { set, get, use, subscribe } = createStore((set) => ({\n * count: 0,\n * increment: () => set(state => ({ count: state.count + 1 }))\n * }));\n */\nexport const createStore = <Value>(createState: StoreCreator<Value> | Value) => {\n let state: Value;\n const listeners: Set<StoreListener<Value>> = new Set();\n\n const setState: StoreApi<Value>['setState'] = (action: StoreSetAction<Value>) => {\n const nextState = typeof action === 'function' ? action(state) : action;\n\n if (!Object.is(nextState, state)) {\n const prevState = state;\n state = (\n typeof nextState !== 'object' || nextState === null || Array.isArray(nextState)\n ? nextState\n : Object.assign({}, state, nextState)\n ) as Value;\n\n listeners.forEach((listener) => listener(state, prevState));\n }\n };\n\n const subscribe = (listener: StoreListener<Value>) => {\n listeners.add(listener);\n\n return () => listeners.delete(listener);\n };\n\n const getState = () => state;\n const getInitialState = () => state;\n\n if (typeof createState === 'function') {\n state = (createState as StoreCreator<Value>)(setState, getState);\n } else {\n state = createState;\n }\n\n function useStore(): Value;\n function useStore<Selected>(selector: (state: Value) => Selected): Selected;\n function useStore<Selected>(selector?: (state: Value) => Selected): Selected | Value {\n return useSyncExternalStore(\n subscribe,\n () => (selector ? selector(getState()) : getState()),\n () => (selector ? selector(getInitialState()) : getInitialState())\n );\n }\n\n return {\n set: setState,\n get: getState,\n use: useStore,\n subscribe\n };\n};\n"],"names":["createStore","createState","state","listeners","setState","action","nextState","prevState","listener","subscribe","getState","getInitialState","useStore","selector","useSyncExternalStore"],"mappings":";AAkCO,MAAMA,IAAc,CAAQC,MAA6C;AAC9E,MAAIC;AACJ,QAAMC,wBAA2C,IAAA,GAE3CC,IAAwC,CAACC,MAAkC;AAC/E,UAAMC,IAAY,OAAOD,KAAW,aAAaA,EAAOH,CAAK,IAAIG;AAEjE,QAAI,CAAC,OAAO,GAAGC,GAAWJ,CAAK,GAAG;AAChC,YAAMK,IAAYL;AAClB,MAAAA,IACE,OAAOI,KAAc,YAAYA,MAAc,QAAQ,MAAM,QAAQA,CAAS,IAC1EA,IACA,OAAO,OAAO,CAAA,GAAIJ,GAAOI,CAAS,GAGxCH,EAAU,QAAQ,CAACK,MAAaA,EAASN,GAAOK,CAAS,CAAC;AAAA,IAAA;AAAA,EAC5D,GAGIE,IAAY,CAACD,OACjBL,EAAU,IAAIK,CAAQ,GAEf,MAAML,EAAU,OAAOK,CAAQ,IAGlCE,IAAW,MAAMR,GACjBS,IAAkB,MAAMT;AAE9B,EAAI,OAAOD,KAAgB,aACzBC,IAASD,EAAoCG,GAAUM,CAAQ,IAE/DR,IAAQD;AAKV,WAASW,EAAmBC,GAAyD;AACnF,WAAOC;AAAA,MACLL;AAAA,MACA,MAAOI,IAAWA,EAASH,EAAA,CAAU,IAAIA,EAAA;AAAA,MACzC,MAAOG,IAAWA,EAASF,EAAA,CAAiB,IAAIA,EAAA;AAAA,IAAgB;AAAA,EAClE;AAGF,SAAO;AAAA,IACL,KAAKP;AAAA,IACL,KAAKM;AAAA,IACL,KAAKE;AAAA,IACL,WAAAH;AAAA,EAAA;AAEJ;"}
1
+ {"version":3,"file":"createStore.mjs","sources":["../../../../src/helpers/createStore/createStore.ts"],"sourcesContent":["import { useSyncExternalStore } from 'react';\n\ntype StoreSetAction<Value> = ((prev: Value) => Partial<Value>) | Partial<Value>;\n\ntype StoreListener<Value> = (state: Value, prevState: Value) => void;\n\ntype StoreCreator<Value> = (\n set: (action: StoreSetAction<Value>) => void,\n get: () => Value\n) => Value;\n\nexport interface StoreApi<Value> {\n get: () => Value;\n getInitial: () => Value;\n set: (action: StoreSetAction<Value>) => void;\n subscribe: (listener: StoreListener<Value>) => () => void;\n\n use: (() => Value) &\n (<Selected>(selector: (state: Value) => Selected) => Selected) &\n (<Selected>(selector?: (state: Value) => Selected) => Selected | Value);\n}\n\n/**\n * @name createStore\n * @description - Creates a store with state management capabilities\n * @category Helpers\n * @usage medium\n *\n * @template Value - The type of the store state\n * @param {StateCreator<Value>} createState - Function that initializes the store state\n * @returns {StoreApi<Value>} - Object containing store methods and hook for accessing state\n *\n * @example\n * const { set, get, use, subscribe } = createStore((set) => ({\n * count: 0,\n * increment: () => set(state => ({ count: state.count + 1 }))\n * }));\n */\nexport const createStore = <Value>(createState: StoreCreator<Value> | Value): StoreApi<Value> => {\n let state: Value;\n let initialState: Value;\n const listeners: Set<StoreListener<Value>> = new Set();\n\n const setState: StoreApi<Value>['set'] = (action: StoreSetAction<Value>) => {\n const nextState = typeof action === 'function' ? action(state) : action;\n\n if (!Object.is(nextState, state)) {\n const prevState = state;\n state = (\n typeof nextState !== 'object' || nextState === null || Array.isArray(nextState)\n ? nextState\n : Object.assign({}, state, nextState)\n ) as Value;\n\n listeners.forEach((listener) => listener(state, prevState));\n }\n };\n\n const subscribe = (listener: StoreListener<Value>) => {\n listeners.add(listener);\n\n return () => listeners.delete(listener);\n };\n\n const getState = () => state;\n const getInitialState = () => initialState;\n\n if (typeof createState === 'function') {\n initialState = state = (createState as StoreCreator<Value>)(setState, getState);\n } else {\n initialState = state = createState;\n }\n\n function useStore(): Value;\n function useStore<Selected>(selector: (state: Value) => Selected): Selected;\n function useStore<Selected>(selector?: (state: Value) => Selected): Selected | Value {\n return useSyncExternalStore(\n subscribe,\n () => (selector ? selector(getState()) : getState()),\n () => (selector ? selector(getInitialState()) : getInitialState())\n );\n }\n\n return {\n set: setState,\n get: getState,\n getInitial: getInitialState,\n use: useStore,\n subscribe\n };\n};\n"],"names":["createStore","createState","state","initialState","listeners","setState","action","nextState","prevState","listener","subscribe","getState","getInitialState","useStore","selector","useSyncExternalStore"],"mappings":";AAsCO,MAAMA,IAAc,CAAQC,MAA8D;AAC/F,MAAIC,GACAC;AACJ,QAAMC,wBAA2C,IAAA,GAE3CC,IAAmC,CAACC,MAAkC;AAC1E,UAAMC,IAAY,OAAOD,KAAW,aAAaA,EAAOJ,CAAK,IAAII;AAEjE,QAAI,CAAC,OAAO,GAAGC,GAAWL,CAAK,GAAG;AAChC,YAAMM,IAAYN;AAClB,MAAAA,IACE,OAAOK,KAAc,YAAYA,MAAc,QAAQ,MAAM,QAAQA,CAAS,IAC1EA,IACA,OAAO,OAAO,CAAA,GAAIL,GAAOK,CAAS,GAGxCH,EAAU,QAAQ,CAACK,MAAaA,EAASP,GAAOM,CAAS,CAAC;AAAA,IAAA;AAAA,EAC5D,GAGIE,IAAY,CAACD,OACjBL,EAAU,IAAIK,CAAQ,GAEf,MAAML,EAAU,OAAOK,CAAQ,IAGlCE,IAAW,MAAMT,GACjBU,IAAkB,MAAMT;AAE9B,EAAI,OAAOF,KAAgB,aACzBE,IAAeD,IAASD,EAAoCI,GAAUM,CAAQ,IAE9ER,IAAeD,IAAQD;AAKzB,WAASY,EAAmBC,GAAyD;AACnF,WAAOC;AAAA,MACLL;AAAA,MACA,MAAOI,IAAWA,EAASH,EAAA,CAAU,IAAIA,EAAA;AAAA,MACzC,MAAOG,IAAWA,EAASF,EAAA,CAAiB,IAAIA,EAAA;AAAA,IAAgB;AAAA,EAClE;AAGF,SAAO;AAAA,IACL,KAAKP;AAAA,IACL,KAAKM;AAAA,IACL,YAAYC;AAAA,IACZ,KAAKC;AAAA,IACL,WAAAH;AAAA,EAAA;AAEJ;"}
@@ -0,0 +1,20 @@
1
+ import { useRef as r, useMemo as h } from "react";
2
+ const b = (c, n) => {
3
+ const u = r(c), s = r(n), e = r([]);
4
+ u.current = c, s.current = n;
5
+ const o = () => {
6
+ if (!e.current.length) return;
7
+ const t = e.current;
8
+ e.current = [], u.current(t);
9
+ };
10
+ return h(() => {
11
+ const t = (...a) => {
12
+ e.current.push(a), e.current.length >= s.current && o();
13
+ };
14
+ return t.flush = o, t.cancel = () => e.current = [], t;
15
+ }, []);
16
+ };
17
+ export {
18
+ b as useBatchedCallback
19
+ };
20
+ //# sourceMappingURL=useBatchedCallback.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useBatchedCallback.mjs","sources":["../../../../src/hooks/useBatchedCallback/useBatchedCallback.ts"],"sourcesContent":["import { useMemo, useRef } from 'react';\n\nexport type BatchedCallback<Params extends unknown[]> = ((...args: Params) => void) & {\n flush: () => void;\n cancel: () => void;\n};\n\n/**\n * @name useBatchedCallback\n * @description - Hook that batches calls and forwards them to a callback\n * @category Utilities\n * @usage medium\n *\n * @template Params The type of the params\n * @param {(batch: Params[]) => void} callback The callback that receives a batch of calls\n * @param {number} batchSize The maximum size of a batch before it is flushed\n * @returns {BatchedCallback<Params>} The batched callback with flush and cancel helpers\n *\n * @example\n * const batched = useBatchedCallback((batch) => console.log(batch), 5);\n */\nexport const useBatchedCallback = <Params extends unknown[]>(\n callback: (batch: Params[]) => void,\n size: number\n): BatchedCallback<Params> => {\n const callbackRef = useRef(callback);\n const sizeRef = useRef(size);\n const queueRef = useRef<Params[]>([]);\n\n callbackRef.current = callback;\n sizeRef.current = size;\n\n const flush = () => {\n if (!queueRef.current.length) return;\n const batch = queueRef.current;\n queueRef.current = [];\n callbackRef.current(batch);\n };\n\n const batched = useMemo(() => {\n const batchedCallback = (...args: Params) => {\n queueRef.current.push(args);\n if (queueRef.current.length >= sizeRef.current) flush();\n };\n\n batchedCallback.flush = flush;\n batchedCallback.cancel = () => (queueRef.current = []);\n\n return batchedCallback as BatchedCallback<Params>;\n }, []);\n\n return batched;\n};\n"],"names":["useBatchedCallback","callback","size","callbackRef","useRef","sizeRef","queueRef","flush","batch","useMemo","batchedCallback","args"],"mappings":";AAqBO,MAAMA,IAAqB,CAChCC,GACAC,MAC4B;AAC5B,QAAMC,IAAcC,EAAOH,CAAQ,GAC7BI,IAAUD,EAAOF,CAAI,GACrBI,IAAWF,EAAiB,EAAE;AAEpC,EAAAD,EAAY,UAAUF,GACtBI,EAAQ,UAAUH;AAElB,QAAMK,IAAQ,MAAM;AAClB,QAAI,CAACD,EAAS,QAAQ,OAAQ;AAC9B,UAAME,IAAQF,EAAS;AACvB,IAAAA,EAAS,UAAU,CAAA,GACnBH,EAAY,QAAQK,CAAK;AAAA,EAAA;AAe3B,SAZgBC,EAAQ,MAAM;AAC5B,UAAMC,IAAkB,IAAIC,MAAiB;AAC3C,MAAAL,EAAS,QAAQ,KAAKK,CAAI,GACtBL,EAAS,QAAQ,UAAUD,EAAQ,WAASE,EAAA;AAAA,IAAM;AAGxD,WAAAG,EAAgB,QAAQH,GACxBG,EAAgB,SAAS,MAAOJ,EAAS,UAAU,CAAA,GAE5CI;AAAA,EAAA,GACN,EAAE;AAGP;"}
@@ -1,18 +1,18 @@
1
1
  import { useRef as d, useEffect as E } from "react";
2
2
  import { useRefState as g } from "../useRefState/useRefState.mjs";
3
3
  import { isTarget as i } from "../../utils/helpers/isTarget.mjs";
4
- const w = ((...t) => {
5
- const e = i(t[0]) ? t[0] : void 0, o = e ? t[1] : t[0], s = e ? t[2] : t[1], n = e ? t[3] : t[2], c = n?.enabled ?? !0, r = g(), f = d(s);
4
+ const w = ((...e) => {
5
+ const t = i(e[0]) ? e[0] : void 0, r = t ? e[1] : e[0], s = t ? e[2] : e[1], n = t ? e[3] : e[2], c = n?.enabled ?? !0, o = g(), f = d(s);
6
6
  f.current = s;
7
7
  const v = d(n);
8
8
  if (v.current = n, E(() => {
9
- if (!c || !e && !r.state) return;
10
- const u = (e ? i.getElement(e) : r.current) ?? window, l = (R) => f.current(R);
11
- return u.addEventListener(o, l, n), () => {
12
- u.removeEventListener(o, l, n);
9
+ if (!c) return;
10
+ const u = (t ? i.getElement(t) : o.current) ?? window, l = (R) => f.current(R);
11
+ return u.addEventListener(r, l, n), () => {
12
+ u.removeEventListener(r, l, n);
13
13
  };
14
- }, [e, r.state, i.getRefState(e), o, c]), !e)
15
- return r;
14
+ }, [t, o.state, i.getRefState(t), r, c]), !t)
15
+ return o;
16
16
  });
17
17
  export {
18
18
  w as useEventListener
@@ -1 +1 @@
1
- {"version":3,"file":"useEventListener.mjs","sources":["../../../../src/hooks/useEventListener/useEventListener.ts"],"sourcesContent":["import { useEffect, useRef } from 'react';\n\nimport type { HookTarget } from '@/utils/helpers';\n\nimport { isTarget } from '@/utils/helpers';\n\nimport type { StateRef } from '../useRefState/useRefState';\n\nimport { useRefState } from '../useRefState/useRefState';\n\n/** The use event listener options */\nexport type UseEventListenerOptions = {\n enabled?: boolean;\n} & AddEventListenerOptions;\n\n/** The use event listener return type */\nexport type UseEventListenerReturn<Target extends Element> = StateRef<Target>;\n\nexport interface UseEventListener {\n <Event extends keyof WindowEventMap = keyof WindowEventMap>(\n target: HookTarget,\n event: Event,\n listener: (this: Window, event: WindowEventMap[Event]) => void,\n options?: UseEventListenerOptions\n ): void;\n\n <Event extends keyof DocumentEventMap = keyof DocumentEventMap>(\n target: HookTarget,\n event: Event,\n listener: (this: Document, event: DocumentEventMap[Event]) => void,\n options?: UseEventListenerOptions\n ): void;\n\n <Event extends keyof HTMLElementEventMap = keyof HTMLElementEventMap>(\n target: HookTarget,\n event: Event,\n listener: (this: Element, event: HTMLElementEventMap[Event]) => void,\n options?: UseEventListenerOptions\n ): void;\n\n <Target extends Element, Event extends keyof HTMLElementEventMap = keyof HTMLElementEventMap>(\n event: Event,\n listener: (this: Target, event: HTMLElementEventMap[Event]) => void,\n options?: UseEventListenerOptions,\n target?: never\n ): UseEventListenerReturn<Target>;\n\n <\n Target extends Element,\n Event extends keyof MediaQueryListEventMap = keyof MediaQueryListEventMap\n >(\n event: Event,\n listener: (this: Target, event: MediaQueryListEventMap[Event]) => void,\n options?: UseEventListenerOptions,\n target?: never\n ): UseEventListenerReturn<Target>;\n}\n\n/**\n * @name useEventListener\n * @description - Hook that attaches an event listener to the specified target\n * @category Browser\n * @usage necessary\n\n * @overload\n * @template Event Key of window event map\n * @param {Window} target The window object to attach the event listener to\n * @param {Event | Event[]} event An array of event types to listen for\n * @param {(this: Window, event: WindowEventMap[Event]) => void} handler The event handler function\n * @param {UseEventListenerOptions} [options] Options for the event listener\n * @returns {void}\n *\n * @example\n * useEventListener(window, 'click', () => console.log('click'));\n *\n * @overload\n * @template Event Key of window event map\n * @param {Document} target The window object to attach the event listener to\n * @param {Event | Event[]} event An array of event types to listen for\n * @param {(this: Document, event: DocumentEventMap[Event]) => void} handler The event handler function\n * @param {UseEventListenerOptions} [options] Options for the event listener\n * @returns {void}\n *\n * @example\n * useEventListener(document, 'click', () => console.log('click'));\n *\n * @overload\n * @template Event Key of window event map\n * @template Target The target element\n * @param {HookTarget} target The target element to attach the event listener to\n * @param {Event | Event[]} event An array of event types to listen for\n * @param {(this: Target, event: HTMLElementEventMap[Event]) => void} handler The event handler function\n * @param {UseEventListenerOptions} [options] Options for the event listener\n * @returns {void}\n *\n * @example\n * useEventListener(ref, 'click', () => console.log('click'));\n *\n * @overload\n * @template Event Key of window event map\n * @template Target The target element\n * @param {Event | Event[]} event An array of event types to listen for\n * @param {(this: Target, event: HTMLElementEventMap[Event] | MediaQueryListEventMap[Event]) => void} handler The event handler function\n * @param {UseEventListenerOptions} [options] Options for the event listener\n * @returns {UseEventListenerReturn<Target>} A reference to the target element\n *\n * @example\n * const ref = useEventListener('click', () => console.log('click'));\n */\nexport const useEventListener = ((...params: any[]) => {\n const target = (isTarget(params[0]) ? params[0] : undefined) as HookTarget | undefined;\n const event = (target ? params[1] : params[0]) as string;\n const listener = (target ? params[2] : params[1]) as (...arg: any[]) => undefined | void;\n const options = (target ? params[3] : params[2]) as UseEventListenerOptions | undefined;\n\n const enabled = options?.enabled ?? true;\n\n const internalRef = useRefState();\n const internalListenerRef = useRef(listener);\n internalListenerRef.current = listener;\n const internalOptionsRef = useRef(options);\n internalOptionsRef.current = options;\n\n useEffect(() => {\n if (!enabled || (!target && !internalRef.state)) return;\n\n const element =\n ((target ? isTarget.getElement(target) : internalRef.current) as Element) ?? window;\n\n const listener = (event: Event) => internalListenerRef.current(event);\n\n element.addEventListener(event, listener, options);\n return () => {\n element.removeEventListener(event, listener, options);\n };\n }, [target, internalRef.state, isTarget.getRefState(target), event, enabled]);\n\n if (target) return;\n return internalRef;\n}) as UseEventListener;\n"],"names":["useEventListener","params","target","isTarget","event","listener","options","enabled","internalRef","useRefState","internalListenerRef","useRef","internalOptionsRef","useEffect","element"],"mappings":";;;AA6GO,MAAMA,KAAoB,IAAIC,MAAkB;AACrD,QAAMC,IAAUC,EAASF,EAAO,CAAC,CAAC,IAAIA,EAAO,CAAC,IAAI,QAC5CG,IAASF,IAASD,EAAO,CAAC,IAAIA,EAAO,CAAC,GACtCI,IAAYH,IAASD,EAAO,CAAC,IAAIA,EAAO,CAAC,GACzCK,IAAWJ,IAASD,EAAO,CAAC,IAAIA,EAAO,CAAC,GAExCM,IAAUD,GAAS,WAAW,IAE9BE,IAAcC,EAAA,GACdC,IAAsBC,EAAON,CAAQ;AAC3C,EAAAK,EAAoB,UAAUL;AAC9B,QAAMO,IAAqBD,EAAOL,CAAO;AAiBzC,MAhBAM,EAAmB,UAAUN,GAE7BO,EAAU,MAAM;AACd,QAAI,CAACN,KAAY,CAACL,KAAU,CAACM,EAAY,MAAQ;AAEjD,UAAMM,KACFZ,IAASC,EAAS,WAAWD,CAAM,IAAIM,EAAY,YAAwB,QAEzEH,IAAW,CAACD,MAAiBM,EAAoB,QAAQN,CAAK;AAEpE,WAAAU,EAAQ,iBAAiBV,GAAOC,GAAUC,CAAO,GAC1C,MAAM;AACX,MAAAQ,EAAQ,oBAAoBV,GAAOC,GAAUC,CAAO;AAAA,IAAA;AAAA,EACtD,GACC,CAACJ,GAAQM,EAAY,OAAOL,EAAS,YAAYD,CAAM,GAAGE,GAAOG,CAAO,CAAC,GAExE,CAAAL;AACJ,WAAOM;AACT;"}
1
+ {"version":3,"file":"useEventListener.mjs","sources":["../../../../src/hooks/useEventListener/useEventListener.ts"],"sourcesContent":["import { useEffect, useRef } from 'react';\n\nimport type { HookTarget } from '@/utils/helpers';\n\nimport { isTarget } from '@/utils/helpers';\n\nimport type { StateRef } from '../useRefState/useRefState';\n\nimport { useRefState } from '../useRefState/useRefState';\n\n/** The use event listener options */\nexport type UseEventListenerOptions = {\n enabled?: boolean;\n} & AddEventListenerOptions;\n\n/** The use event listener return type */\nexport type UseEventListenerReturn<Target extends Element> = StateRef<Target>;\n\nexport interface UseEventListener {\n <Event extends keyof WindowEventMap = keyof WindowEventMap>(\n target: HookTarget,\n event: Event,\n listener: (this: Window, event: WindowEventMap[Event]) => void,\n options?: UseEventListenerOptions\n ): void;\n\n <Event extends keyof DocumentEventMap = keyof DocumentEventMap>(\n target: HookTarget,\n event: Event,\n listener: (this: Document, event: DocumentEventMap[Event]) => void,\n options?: UseEventListenerOptions\n ): void;\n\n <Event extends keyof HTMLElementEventMap = keyof HTMLElementEventMap>(\n target: HookTarget,\n event: Event,\n listener: (this: Element, event: HTMLElementEventMap[Event]) => void,\n options?: UseEventListenerOptions\n ): void;\n\n <Target extends Element, Event extends keyof HTMLElementEventMap = keyof HTMLElementEventMap>(\n event: Event,\n listener: (this: Target, event: HTMLElementEventMap[Event]) => void,\n options?: UseEventListenerOptions,\n target?: never\n ): UseEventListenerReturn<Target>;\n\n <\n Target extends Element,\n Event extends keyof MediaQueryListEventMap = keyof MediaQueryListEventMap\n >(\n event: Event,\n listener: (this: Target, event: MediaQueryListEventMap[Event]) => void,\n options?: UseEventListenerOptions,\n target?: never\n ): UseEventListenerReturn<Target>;\n}\n\n/**\n * @name useEventListener\n * @description - Hook that attaches an event listener to the specified target\n * @category Browser\n * @usage necessary\n\n * @overload\n * @template Event Key of window event map\n * @param {Window} target The window object to attach the event listener to\n * @param {Event | Event[]} event An array of event types to listen for\n * @param {(this: Window, event: WindowEventMap[Event]) => void} handler The event handler function\n * @param {UseEventListenerOptions} [options] Options for the event listener\n * @returns {void}\n *\n * @example\n * useEventListener(window, 'click', () => console.log('click'));\n *\n * @overload\n * @template Event Key of window event map\n * @param {Document} target The window object to attach the event listener to\n * @param {Event | Event[]} event An array of event types to listen for\n * @param {(this: Document, event: DocumentEventMap[Event]) => void} handler The event handler function\n * @param {UseEventListenerOptions} [options] Options for the event listener\n * @returns {void}\n *\n * @example\n * useEventListener(document, 'click', () => console.log('click'));\n *\n * @overload\n * @template Event Key of window event map\n * @template Target The target element\n * @param {HookTarget} target The target element to attach the event listener to\n * @param {Event | Event[]} event An array of event types to listen for\n * @param {(this: Target, event: HTMLElementEventMap[Event]) => void} handler The event handler function\n * @param {UseEventListenerOptions} [options] Options for the event listener\n * @returns {void}\n *\n * @example\n * useEventListener(ref, 'click', () => console.log('click'));\n *\n * @overload\n * @template Event Key of window event map\n * @template Target The target element\n * @param {Event | Event[]} event An array of event types to listen for\n * @param {(this: Target, event: HTMLElementEventMap[Event] | MediaQueryListEventMap[Event]) => void} handler The event handler function\n * @param {UseEventListenerOptions} [options] Options for the event listener\n * @returns {UseEventListenerReturn<Target>} A reference to the target element\n *\n * @example\n * const ref = useEventListener('click', () => console.log('click'));\n */\nexport const useEventListener = ((...params: any[]) => {\n const target = (isTarget(params[0]) ? params[0] : undefined) as HookTarget | undefined;\n const event = (target ? params[1] : params[0]) as string;\n const listener = (target ? params[2] : params[1]) as (...arg: any[]) => undefined | void;\n const options = (target ? params[3] : params[2]) as UseEventListenerOptions | undefined;\n\n const enabled = options?.enabled ?? true;\n\n const internalRef = useRefState();\n const internalListenerRef = useRef(listener);\n internalListenerRef.current = listener;\n const internalOptionsRef = useRef(options);\n internalOptionsRef.current = options;\n\n useEffect(() => {\n if (!enabled) return;\n\n const element =\n ((target ? isTarget.getElement(target) : internalRef.current) as Element) ?? window;\n\n const listener = (event: Event) => internalListenerRef.current(event);\n\n element.addEventListener(event, listener, options);\n return () => {\n element.removeEventListener(event, listener, options);\n };\n }, [target, internalRef.state, isTarget.getRefState(target), event, enabled]);\n\n if (target) return;\n return internalRef;\n}) as UseEventListener;\n"],"names":["useEventListener","params","target","isTarget","event","listener","options","enabled","internalRef","useRefState","internalListenerRef","useRef","internalOptionsRef","useEffect","element"],"mappings":";;;AA6GO,MAAMA,KAAoB,IAAIC,MAAkB;AACrD,QAAMC,IAAUC,EAASF,EAAO,CAAC,CAAC,IAAIA,EAAO,CAAC,IAAI,QAC5CG,IAASF,IAASD,EAAO,CAAC,IAAIA,EAAO,CAAC,GACtCI,IAAYH,IAASD,EAAO,CAAC,IAAIA,EAAO,CAAC,GACzCK,IAAWJ,IAASD,EAAO,CAAC,IAAIA,EAAO,CAAC,GAExCM,IAAUD,GAAS,WAAW,IAE9BE,IAAcC,EAAA,GACdC,IAAsBC,EAAON,CAAQ;AAC3C,EAAAK,EAAoB,UAAUL;AAC9B,QAAMO,IAAqBD,EAAOL,CAAO;AAiBzC,MAhBAM,EAAmB,UAAUN,GAE7BO,EAAU,MAAM;AACd,QAAI,CAACN,EAAS;AAEd,UAAMO,KACFZ,IAASC,EAAS,WAAWD,CAAM,IAAIM,EAAY,YAAwB,QAEzEH,IAAW,CAACD,MAAiBM,EAAoB,QAAQN,CAAK;AAEpE,WAAAU,EAAQ,iBAAiBV,GAAOC,GAAUC,CAAO,GAC1C,MAAM;AACX,MAAAQ,EAAQ,oBAAoBV,GAAOC,GAAUC,CAAO;AAAA,IAAA;AAAA,EACtD,GACC,CAACJ,GAAQM,EAAY,OAAOL,EAAS,YAAYD,CAAM,GAAGE,GAAOG,CAAO,CAAC,GAExE,CAAAL;AACJ,WAAOM;AACT;"}
@@ -1,24 +1,26 @@
1
- import { useState as i, useRef as l } from "react";
2
- const b = ((...t) => {
3
- const e = typeof navigator < "u" && "OTPCredential" in navigator && !!navigator.OTPCredential, c = typeof t[0] == "function" ? t[0] : t[0]?.onSuccess, s = typeof t[0] == "function" ? t[0]?.onError : void 0, [a, n] = i(!1), r = l(new AbortController());
1
+ import { useRef as c } from "react";
2
+ const l = ((...o) => {
3
+ const e = typeof navigator < "u" && "OTPCredential" in navigator && !!navigator.OTPCredential, n = typeof o[0] == "object" ? o[0] : {
4
+ onSuccess: o[0]
5
+ }, t = c(new AbortController());
4
6
  return { supported: e, abort: () => {
5
- r.current.abort(), r.current = new AbortController(), r.current.signal.onabort = () => n(!0);
6
- }, aborted: a, get: async () => {
7
+ t.current.abort(), t.current = new AbortController();
8
+ }, get: async () => {
7
9
  if (e) {
8
- r.current = new AbortController();
10
+ t.current = new AbortController();
9
11
  try {
10
- const o = await navigator.credentials.get({
12
+ const r = await navigator.credentials.get({
11
13
  otp: { transport: ["sms"] },
12
- signal: r.current.signal
14
+ signal: t.current.signal
13
15
  });
14
- return c?.(o), n(!1), o;
15
- } catch (o) {
16
- s?.(o);
16
+ return n.onSuccess?.(r), r;
17
+ } catch (r) {
18
+ n.onError?.(r);
17
19
  }
18
20
  }
19
21
  } };
20
22
  });
21
23
  export {
22
- b as useOtpCredential
24
+ l as useOtpCredential
23
25
  };
24
26
  //# sourceMappingURL=useOtpCredential.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"useOtpCredential.mjs","sources":["../../../../src/hooks/useOtpCredential/useOtpCredential.ts"],"sourcesContent":["import { useRef, useState } from 'react';\n\ndeclare global {\n interface OTPOptions {\n readonly transport: string[];\n }\n\n interface CredentialRequestOptions {\n readonly otp: OTPOptions;\n }\n\n interface Credential {\n readonly code: string;\n }\n}\n\n/* The use otp credential callback type */\nexport type UseOtpCredentialCallback = (otp: Credential | null) => void;\n\n/* The use otp credential options type */\nexport interface UseOtpCredentialParams {\n /* The callback function to be invoked on error */\n onError: (error: any) => void;\n /* The callback function to be invoked on success */\n onSuccess: (credential: Credential | null) => void;\n}\n\n/* The use otp credential return type */\nexport interface UseOtpCredentialReturn {\n /* The abort function */\n abort: AbortController['abort'];\n /* The aborted state of the query */\n aborted: boolean;\n /* The supported state of the otp credential */\n supported: boolean;\n /* The get otp credential function */\n get: () => Promise<Credential | null>;\n}\n\nexport interface UseOtpCredential {\n (callback?: UseOtpCredentialCallback): UseOtpCredentialReturn;\n\n (params?: UseOtpCredentialParams): UseOtpCredentialReturn;\n}\n\n/**\n * @name useOtpCredential\n * @description - Hook that creates an otp credential\n * @category Browser\n * @usage low\n *\n * @browserapi navigator.credentials https://developer.mozilla.org/en-US/docs/Web/API/Navigator/credentials\n *\n * @overload\n * @param {UseOtpCredentialCallback} callback The callback function to be invoked\n * @returns {UseOtpCredentialReturn}\n *\n * @example\n * useOtpCredential((credential) => console.log(credential));\n *\n * @overload\n * @param {UseOtpCredentialCallback} params.onSuccess The callback function to be invoked on success\n * @param {UseOtpCredentialCallback} params.onError The callback function to be invoked on error\n * @returns {UseOtpCredentialReturn}\n *\n * @example\n * useOtpCredential({ onSuccess: (credential) => console.log(credential), onError: (error) => console.log(error) });\n */\nexport const useOtpCredential = ((...params: any[]) => {\n const supported =\n typeof navigator !== 'undefined' && 'OTPCredential' in navigator && !!navigator.OTPCredential;\n\n const onSuccess =\n typeof params[0] === 'function'\n ? (params[0] as UseOtpCredentialCallback | undefined)\n : (params[0] as UseOtpCredentialParams | undefined)?.onSuccess;\n\n const onError =\n typeof params[0] === 'function'\n ? (params[0] as UseOtpCredentialParams | undefined)?.onError\n : undefined;\n\n const [aborted, setAborted] = useState(false);\n\n const abortControllerRef = useRef<AbortController>(new AbortController());\n\n const get = async () => {\n if (!supported) return;\n\n abortControllerRef.current = new AbortController();\n try {\n const credential = await navigator.credentials.get({\n otp: { transport: ['sms'] },\n signal: abortControllerRef.current.signal\n });\n onSuccess?.(credential);\n setAborted(false);\n return credential;\n } catch (error) {\n onError?.(error);\n }\n };\n\n const abort = () => {\n abortControllerRef.current.abort();\n abortControllerRef.current = new AbortController();\n abortControllerRef.current.signal.onabort = () => setAborted(true);\n };\n\n return { supported, abort, aborted, get };\n}) as UseOtpCredential;\n"],"names":["useOtpCredential","params","supported","onSuccess","onError","aborted","setAborted","useState","abortControllerRef","useRef","credential","error"],"mappings":";AAoEO,MAAMA,KAAoB,IAAIC,MAAkB;AACrD,QAAMC,IACJ,OAAO,YAAc,OAAe,mBAAmB,aAAa,CAAC,CAAC,UAAU,eAE5EC,IACJ,OAAOF,EAAO,CAAC,KAAM,aAChBA,EAAO,CAAC,IACRA,EAAO,CAAC,GAA0C,WAEnDG,IACJ,OAAOH,EAAO,CAAC,KAAM,aAChBA,EAAO,CAAC,GAA0C,UACnD,QAEA,CAACI,GAASC,CAAU,IAAIC,EAAS,EAAK,GAEtCC,IAAqBC,EAAwB,IAAI,iBAAiB;AAyBxE,SAAO,EAAE,WAAAP,GAAW,OANN,MAAM;AAClB,IAAAM,EAAmB,QAAQ,MAAA,GAC3BA,EAAmB,UAAU,IAAI,gBAAA,GACjCA,EAAmB,QAAQ,OAAO,UAAU,MAAMF,EAAW,EAAI;AAAA,EAAA,GAGxC,SAAAD,GAAS,KAvBxB,YAAY;AACtB,QAAKH,GAEL;AAAA,MAAAM,EAAmB,UAAU,IAAI,gBAAA;AACjC,UAAI;AACF,cAAME,IAAa,MAAM,UAAU,YAAY,IAAI;AAAA,UACjD,KAAK,EAAE,WAAW,CAAC,KAAK,EAAA;AAAA,UACxB,QAAQF,EAAmB,QAAQ;AAAA,QAAA,CACpC;AACD,eAAAL,IAAYO,CAAU,GACtBJ,EAAW,EAAK,GACTI;AAAA,MAAA,SACAC,GAAO;AACd,QAAAP,IAAUO,CAAK;AAAA,MAAA;AAAA;AAAA,EACjB,EASkC;AACtC;"}
1
+ {"version":3,"file":"useOtpCredential.mjs","sources":["../../../../src/hooks/useOtpCredential/useOtpCredential.ts"],"sourcesContent":["import { useRef } from 'react';\n\ndeclare global {\n interface OTPOptions {\n readonly transport: string[];\n }\n\n interface CredentialRequestOptions {\n readonly otp: OTPOptions;\n }\n\n interface Credential {\n readonly code: string;\n }\n}\n\n/* The use otp credential callback type */\nexport type UseOtpCredentialCallback = (otp: Credential | null) => void;\n\n/* The use otp credential options type */\nexport interface UseOtpCredentialParams {\n /* The callback function to be invoked on error */\n onError?: (error: any) => void;\n /* The callback function to be invoked on success */\n onSuccess?: (credential: Credential | null) => void;\n}\n\n/* The use otp credential return type */\nexport interface UseOtpCredentialReturn {\n /* The abort function */\n abort: AbortController['abort'];\n /* The supported state of the otp credential */\n supported: boolean;\n /* The get otp credential function */\n get: () => Promise<Credential | null>;\n}\n\nexport interface UseOtpCredential {\n (callback?: UseOtpCredentialCallback): UseOtpCredentialReturn;\n\n (params?: UseOtpCredentialParams): UseOtpCredentialReturn;\n}\n\n/**\n * @name useOtpCredential\n * @description - Hook that creates an otp credential\n * @category Browser\n * @usage low\n *\n * @browserapi navigator.credentials https://developer.mozilla.org/en-US/docs/Web/API/Navigator/credentials\n *\n * @overload\n * @param {UseOtpCredentialCallback} callback The callback function to be invoked\n * @returns {UseOtpCredentialReturn}\n *\n * @example\n * useOtpCredential((credential) => console.log(credential));\n *\n * @overload\n * @param {UseOtpCredentialCallback} params.onSuccess The callback function to be invoked on success\n * @param {UseOtpCredentialCallback} params.onError The callback function to be invoked on error\n * @returns {UseOtpCredentialReturn}\n *\n * @example\n * useOtpCredential({ onSuccess: (credential) => console.log(credential), onError: (error) => console.log(error) });\n */\nexport const useOtpCredential = ((...params: any[]) => {\n const supported =\n typeof navigator !== 'undefined' && 'OTPCredential' in navigator && !!navigator.OTPCredential;\n\n const options =\n typeof params[0] === 'object'\n ? params[0]\n : {\n onSuccess: params[0]\n };\n\n const abortControllerRef = useRef<AbortController>(new AbortController());\n\n const get = async () => {\n if (!supported) return;\n\n abortControllerRef.current = new AbortController();\n try {\n const credential = await navigator.credentials.get({\n otp: { transport: ['sms'] },\n signal: abortControllerRef.current.signal\n });\n options.onSuccess?.(credential);\n\n return credential;\n } catch (error) {\n options.onError?.(error);\n }\n };\n\n const abort = () => {\n abortControllerRef.current.abort();\n abortControllerRef.current = new AbortController();\n };\n\n return { supported, abort, get };\n}) as UseOtpCredential;\n"],"names":["useOtpCredential","params","supported","options","abortControllerRef","useRef","credential","error"],"mappings":";AAkEO,MAAMA,KAAoB,IAAIC,MAAkB;AACrD,QAAMC,IACJ,OAAO,YAAc,OAAe,mBAAmB,aAAa,CAAC,CAAC,UAAU,eAE5EC,IACJ,OAAOF,EAAO,CAAC,KAAM,WACjBA,EAAO,CAAC,IACR;AAAA,IACE,WAAWA,EAAO,CAAC;AAAA,EAAA,GAGrBG,IAAqBC,EAAwB,IAAI,iBAAiB;AAwBxE,SAAO,EAAE,WAAAH,GAAW,OALN,MAAM;AAClB,IAAAE,EAAmB,QAAQ,MAAA,GAC3BA,EAAmB,UAAU,IAAI,gBAAA;AAAA,EAAgB,GAGxB,KAtBf,YAAY;AACtB,QAAKF,GAEL;AAAA,MAAAE,EAAmB,UAAU,IAAI,gBAAA;AACjC,UAAI;AACF,cAAME,IAAa,MAAM,UAAU,YAAY,IAAI;AAAA,UACjD,KAAK,EAAE,WAAW,CAAC,KAAK,EAAA;AAAA,UACxB,QAAQF,EAAmB,QAAQ;AAAA,QAAA,CACpC;AACD,eAAAD,EAAQ,YAAYG,CAAU,GAEvBA;AAAA,MAAA,SACAC,GAAO;AACd,QAAAJ,EAAQ,UAAUI,CAAK;AAAA,MAAA;AAAA;AAAA,EACzB,EAQyB;AAC7B;"}
@@ -11,23 +11,21 @@ const f = () => window?.SpeechRecognition ?? window?.webkitSpeechRecognition, q
11
11
  onError: x,
12
12
  onResult: E
13
13
  } = d, [l, s] = e(!1), [A, b] = e(""), [k, y] = e(!1), [F, u] = e(null), [o] = e(() => {
14
- if (!i) return {};
14
+ if (!i) return;
15
15
  const r = f(), t = new r();
16
16
  return t.continuous = m, a && (t.grammars = a), t.interimResults = R, t.lang = c, t.maxAlternatives = w, t.onstart = () => {
17
17
  s(!0), y(!1), S?.();
18
- }, t.onend = () => {
19
- s(!1), h?.();
20
18
  }, t.onerror = (n) => {
21
19
  u(n), s(!1), x?.(n);
22
20
  }, t.onresult = (n) => {
23
21
  const I = n.results[n.resultIndex], { transcript: L } = I[0];
24
- b(L), u(null), E?.(n);
22
+ s(!1), b(L), u(null), E?.(n);
25
23
  }, t.onend = () => {
26
- s(!1), t.lang = c;
24
+ s(!1), h?.(), t.lang = c;
27
25
  }, t;
28
26
  });
29
- T(() => () => o.stop(), []);
30
- const g = () => o.start(), p = () => o.stop();
27
+ T(() => () => o?.stop(), []);
28
+ const g = () => o?.start(), p = () => o?.stop();
31
29
  return {
32
30
  supported: i,
33
31
  transcript: A,
@@ -1 +1 @@
1
- {"version":3,"file":"useSpeechRecognition.mjs","sources":["../../../../src/hooks/useSpeechRecognition/useSpeechRecognition.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\n/** The use speech recognition hook options type */\ninterface UseSpeechRecognitionOptions {\n /** If true, recognition continues even after pauses in speech. Default is false */\n continuous?: SpeechRecognition['continuous'];\n /** A list of grammar rules */\n grammars?: SpeechRecognition['grammars'];\n /** If true, interim (non-final) results are provided as the user speaks */\n interimResults?: SpeechRecognition['interimResults'];\n /** The language in which recognition should occur. Must be a valid BCP 47 language tag (e.g., \"en-US\", \"ru-RU\") */\n language?: SpeechRecognition['lang'];\n /** The maximum number of alternative transcripts returned for a given recognition result. Must be a positive integer */\n maxAlternatives?: SpeechRecognition['maxAlternatives'];\n /** Callback invoked when speech recognition ends */\n onEnd?: () => void;\n /** Callback invoked when an error occurs during recognition */\n onError?: (error: SpeechRecognitionErrorEvent) => void;\n /** Callback invoked when recognition produces a result */\n onResult?: (event: SpeechRecognitionEvent) => void;\n /** Callback invoked when speech recognition starts */\n onStart?: () => void;\n}\n\n/** The return type of the useSpeechRecognition hook. */\ninterface UseSpeechRecognitionReturn {\n /** The error state */\n error: SpeechRecognitionErrorEvent | null;\n /** The final transcript */\n final: boolean;\n /** Whether the hook is currently listening for speech */\n listening: boolean;\n /** The speech recognition instance */\n recognition: SpeechRecognition;\n /** Whether the current browser supports the Web Speech API */\n supported: boolean;\n /** The current transcript */\n transcript: string;\n /** Begins speech recognition */\n start: () => void;\n /** Ends speech recognition, finalizing results */\n stop: () => void;\n /** Toggles the listening state */\n toggle: (value?: boolean) => void;\n}\n\nexport const getSpeechRecognition = () =>\n window?.SpeechRecognition ?? window?.webkitSpeechRecognition;\n\n/**\n * @name useSpeechRecognition\n * @description - Hook that provides a streamlined interface for incorporating speech-to-text functionality\n * @category Browser\n * @usage low\n *\n * @browserapi window.SpeechRecognition https://developer.mozilla.org/en-US/docs/Web/API/SpeechRecognition\n *\n * @param {boolean} [options.continuous=false] Whether recognition should continue after pauses\n * @param {boolean} [options.interimResults=false] Whether interim results should be provided\n * @param {string} [options.language=\"en-US\"] The language for recognition, as a valid BCP 47 tag\n * @param {number} [options.maxAlternatives=1] The maximum number of alternative transcripts to return\n * @param {SpeechGrammarList} [options.grammars] A list of grammar rules\n * @param {() => void} [options.onStart] Callback invoked when speech recognition starts\n * @param {() => void} [options.onEnd] Callback invoked when speech recognition ends\n * @param {(error: SpeechRecognitionErrorEvent) => void} [options.onError] Callback invoked when an error occurs during recognition\n * @param {(event: SpeechRecognitionEvent) => void} [options.onResult] Callback invoked when recognition produces a result\n * @returns {UseSpeechRecognitionReturn} An object containing the speech recognition functionality\n *\n * @example\n * const { supported, value, recognition, listening, error, start, stop, toggle } = useSpeechRecognition();\n */\nexport const useSpeechRecognition = (\n options: UseSpeechRecognitionOptions = {}\n): UseSpeechRecognitionReturn => {\n const supported = typeof window !== 'undefined' && !!getSpeechRecognition();\n\n const {\n continuous = false,\n interimResults = false,\n language = 'en-US',\n grammars,\n maxAlternatives = 1,\n onStart,\n onEnd,\n onError,\n onResult\n } = options;\n\n const [listening, setListening] = useState(false);\n const [transcript, setTranscript] = useState('');\n const [final, setFinal] = useState(false);\n const [error, setError] = useState<SpeechRecognitionErrorEvent | null>(null);\n const [recognition] = useState<SpeechRecognition>(() => {\n if (!supported) return {} as SpeechRecognition;\n\n const SpeechRecognition = getSpeechRecognition();\n const speechRecognition = new SpeechRecognition();\n\n speechRecognition.continuous = continuous;\n if (grammars) speechRecognition.grammars = grammars;\n speechRecognition.interimResults = interimResults;\n speechRecognition.lang = language;\n speechRecognition.maxAlternatives = maxAlternatives;\n\n speechRecognition.onstart = () => {\n setListening(true);\n setFinal(false);\n onStart?.();\n };\n speechRecognition.onend = () => {\n setListening(false);\n onEnd?.();\n };\n speechRecognition.onerror = (event) => {\n setError(event);\n setListening(false);\n onError?.(event);\n };\n speechRecognition.onresult = (event) => {\n const currentResult = event.results[event.resultIndex];\n const { transcript } = currentResult[0];\n\n setTranscript(transcript);\n setError(null);\n onResult?.(event);\n };\n speechRecognition.onend = () => {\n setListening(false);\n speechRecognition.lang = language;\n };\n\n return speechRecognition;\n });\n\n useEffect(() => () => recognition.stop(), []);\n\n const start = () => recognition.start();\n const stop = () => recognition.stop();\n\n const toggle = (value = !listening) => {\n if (value) return start();\n stop();\n };\n\n return {\n supported,\n transcript,\n recognition,\n final,\n listening,\n error,\n start,\n stop,\n toggle\n };\n};\n"],"names":["getSpeechRecognition","useSpeechRecognition","options","supported","continuous","interimResults","language","grammars","maxAlternatives","onStart","onEnd","onError","onResult","listening","setListening","useState","transcript","setTranscript","final","setFinal","error","setError","recognition","SpeechRecognition","speechRecognition","event","currentResult","useEffect","start","stop","value"],"mappings":";AA8CO,MAAMA,IAAuB,MAClC,QAAQ,qBAAqB,QAAQ,yBAwB1BC,IAAuB,CAClCC,IAAuC,OACR;AAC/B,QAAMC,IAAY,OAAO,SAAW,OAAe,CAAC,CAACH,EAAA,GAE/C;AAAA,IACJ,YAAAI,IAAa;AAAA,IACb,gBAAAC,IAAiB;AAAA,IACjB,UAAAC,IAAW;AAAA,IACX,UAAAC;AAAA,IACA,iBAAAC,IAAkB;AAAA,IAClB,SAAAC;AAAA,IACA,OAAAC;AAAA,IACA,SAAAC;AAAA,IACA,UAAAC;AAAA,EAAA,IACEV,GAEE,CAACW,GAAWC,CAAY,IAAIC,EAAS,EAAK,GAC1C,CAACC,GAAYC,CAAa,IAAIF,EAAS,EAAE,GACzC,CAACG,GAAOC,CAAQ,IAAIJ,EAAS,EAAK,GAClC,CAACK,GAAOC,CAAQ,IAAIN,EAA6C,IAAI,GACrE,CAACO,CAAW,IAAIP,EAA4B,MAAM;AACtD,QAAI,CAACZ,EAAW,QAAO,CAAA;AAEvB,UAAMoB,IAAoBvB,EAAA,GACpBwB,IAAoB,IAAID,EAAA;AAE9B,WAAAC,EAAkB,aAAapB,GAC3BG,QAA4B,WAAWA,IAC3CiB,EAAkB,iBAAiBnB,GACnCmB,EAAkB,OAAOlB,GACzBkB,EAAkB,kBAAkBhB,GAEpCgB,EAAkB,UAAU,MAAM;AAChC,MAAAV,EAAa,EAAI,GACjBK,EAAS,EAAK,GACdV,IAAA;AAAA,IAAU,GAEZe,EAAkB,QAAQ,MAAM;AAC9B,MAAAV,EAAa,EAAK,GAClBJ,IAAA;AAAA,IAAQ,GAEVc,EAAkB,UAAU,CAACC,MAAU;AACrC,MAAAJ,EAASI,CAAK,GACdX,EAAa,EAAK,GAClBH,IAAUc,CAAK;AAAA,IAAA,GAEjBD,EAAkB,WAAW,CAACC,MAAU;AACtC,YAAMC,IAAgBD,EAAM,QAAQA,EAAM,WAAW,GAC/C,EAAE,YAAAT,MAAeU,EAAc,CAAC;AAEtC,MAAAT,EAAcD,CAAU,GACxBK,EAAS,IAAI,GACbT,IAAWa,CAAK;AAAA,IAAA,GAElBD,EAAkB,QAAQ,MAAM;AAC9B,MAAAV,EAAa,EAAK,GAClBU,EAAkB,OAAOlB;AAAA,IAAA,GAGpBkB;AAAA,EAAA,CACR;AAED,EAAAG,EAAU,MAAM,MAAML,EAAY,KAAA,GAAQ,CAAA,CAAE;AAE5C,QAAMM,IAAQ,MAAMN,EAAY,MAAA,GAC1BO,IAAO,MAAMP,EAAY,KAAA;AAO/B,SAAO;AAAA,IACL,WAAAnB;AAAA,IACA,YAAAa;AAAA,IACA,aAAAM;AAAA,IACA,OAAAJ;AAAA,IACA,WAAAL;AAAA,IACA,OAAAO;AAAA,IACA,OAAAQ;AAAA,IACA,MAAAC;AAAA,IACA,QAda,CAACC,IAAQ,CAACjB,MAAc;AACrC,UAAIiB,UAAcF,EAAA;AAClB,MAAAC,EAAA;AAAA,IAAK;AAAA,EAYL;AAEJ;"}
1
+ {"version":3,"file":"useSpeechRecognition.mjs","sources":["../../../../src/hooks/useSpeechRecognition/useSpeechRecognition.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\n/** The use speech recognition hook options type */\ninterface UseSpeechRecognitionOptions {\n /** If true, recognition continues even after pauses in speech. Default is false */\n continuous?: SpeechRecognition['continuous'];\n /** A list of grammar rules */\n grammars?: SpeechRecognition['grammars'];\n /** If true, interim (non-final) results are provided as the user speaks */\n interimResults?: SpeechRecognition['interimResults'];\n /** The language in which recognition should occur. Must be a valid BCP 47 language tag (e.g., \"en-US\", \"ru-RU\") */\n language?: SpeechRecognition['lang'];\n /** The maximum number of alternative transcripts returned for a given recognition result. Must be a positive integer */\n maxAlternatives?: SpeechRecognition['maxAlternatives'];\n /** Callback invoked when speech recognition ends */\n onEnd?: () => void;\n /** Callback invoked when an error occurs during recognition */\n onError?: (error: SpeechRecognitionErrorEvent) => void;\n /** Callback invoked when recognition produces a result */\n onResult?: (event: SpeechRecognitionEvent) => void;\n /** Callback invoked when speech recognition starts */\n onStart?: () => void;\n}\n\n/** The return type of the useSpeechRecognition hook. */\ninterface UseSpeechRecognitionReturn {\n /** The error state */\n error: SpeechRecognitionErrorEvent | null;\n /** The final transcript */\n final: boolean;\n /** Whether the hook is currently listening for speech */\n listening: boolean;\n /** The speech recognition instance */\n recognition?: SpeechRecognition;\n /** Whether the current browser supports the Web Speech API */\n supported: boolean;\n /** The current transcript */\n transcript: string;\n /** Begins speech recognition */\n start: () => void;\n /** Ends speech recognition, finalizing results */\n stop: () => void;\n /** Toggles the listening state */\n toggle: (value?: boolean) => void;\n}\n\nexport const getSpeechRecognition = () =>\n window?.SpeechRecognition ?? window?.webkitSpeechRecognition;\n\n/**\n * @name useSpeechRecognition\n * @description - Hook that provides a streamlined interface for incorporating speech-to-text functionality\n * @category Browser\n * @usage low\n *\n * @browserapi window.SpeechRecognition https://developer.mozilla.org/en-US/docs/Web/API/SpeechRecognition\n *\n * @param {boolean} [options.continuous=false] Whether recognition should continue after pauses\n * @param {boolean} [options.interimResults=false] Whether interim results should be provided\n * @param {string} [options.language=\"en-US\"] The language for recognition, as a valid BCP 47 tag\n * @param {number} [options.maxAlternatives=1] The maximum number of alternative transcripts to return\n * @param {SpeechGrammarList} [options.grammars] A list of grammar rules\n * @param {() => void} [options.onStart] Callback invoked when speech recognition starts\n * @param {() => void} [options.onEnd] Callback invoked when speech recognition ends\n * @param {(error: SpeechRecognitionErrorEvent) => void} [options.onError] Callback invoked when an error occurs during recognition\n * @param {(event: SpeechRecognitionEvent) => void} [options.onResult] Callback invoked when recognition produces a result\n * @returns {UseSpeechRecognitionReturn} An object containing the speech recognition functionality\n *\n * @example\n * const { supported, value, recognition, listening, error, start, stop, toggle } = useSpeechRecognition();\n */\nexport const useSpeechRecognition = (\n options: UseSpeechRecognitionOptions = {}\n): UseSpeechRecognitionReturn => {\n const supported = typeof window !== 'undefined' && !!getSpeechRecognition();\n\n const {\n continuous = false,\n interimResults = false,\n language = 'en-US',\n grammars,\n maxAlternatives = 1,\n onStart,\n onEnd,\n onError,\n onResult\n } = options;\n\n const [listening, setListening] = useState(false);\n const [transcript, setTranscript] = useState('');\n const [final, setFinal] = useState(false);\n const [error, setError] = useState<SpeechRecognitionErrorEvent | null>(null);\n const [recognition] = useState<SpeechRecognition | undefined>(() => {\n if (!supported) return undefined;\n\n const SpeechRecognition = getSpeechRecognition();\n const speechRecognition = new SpeechRecognition();\n\n speechRecognition.continuous = continuous;\n if (grammars) speechRecognition.grammars = grammars;\n speechRecognition.interimResults = interimResults;\n speechRecognition.lang = language;\n speechRecognition.maxAlternatives = maxAlternatives;\n\n speechRecognition.onstart = () => {\n setListening(true);\n setFinal(false);\n onStart?.();\n };\n speechRecognition.onerror = (event) => {\n setError(event);\n setListening(false);\n onError?.(event);\n };\n speechRecognition.onresult = (event) => {\n const currentResult = event.results[event.resultIndex];\n const { transcript } = currentResult[0];\n\n setListening(false);\n setTranscript(transcript);\n setError(null);\n onResult?.(event);\n };\n speechRecognition.onend = () => {\n setListening(false);\n onEnd?.();\n speechRecognition.lang = language;\n };\n\n return speechRecognition;\n });\n\n useEffect(() => () => recognition?.stop(), []);\n\n const start = () => recognition?.start();\n const stop = () => recognition?.stop();\n\n const toggle = (value = !listening) => {\n if (value) return start();\n stop();\n };\n\n return {\n supported,\n transcript,\n recognition,\n final,\n listening,\n error,\n start,\n stop,\n toggle\n };\n};\n"],"names":["getSpeechRecognition","useSpeechRecognition","options","supported","continuous","interimResults","language","grammars","maxAlternatives","onStart","onEnd","onError","onResult","listening","setListening","useState","transcript","setTranscript","final","setFinal","error","setError","recognition","SpeechRecognition","speechRecognition","event","currentResult","useEffect","start","stop","value"],"mappings":";AA8CO,MAAMA,IAAuB,MAClC,QAAQ,qBAAqB,QAAQ,yBAwB1BC,IAAuB,CAClCC,IAAuC,OACR;AAC/B,QAAMC,IAAY,OAAO,SAAW,OAAe,CAAC,CAACH,EAAA,GAE/C;AAAA,IACJ,YAAAI,IAAa;AAAA,IACb,gBAAAC,IAAiB;AAAA,IACjB,UAAAC,IAAW;AAAA,IACX,UAAAC;AAAA,IACA,iBAAAC,IAAkB;AAAA,IAClB,SAAAC;AAAA,IACA,OAAAC;AAAA,IACA,SAAAC;AAAA,IACA,UAAAC;AAAA,EAAA,IACEV,GAEE,CAACW,GAAWC,CAAY,IAAIC,EAAS,EAAK,GAC1C,CAACC,GAAYC,CAAa,IAAIF,EAAS,EAAE,GACzC,CAACG,GAAOC,CAAQ,IAAIJ,EAAS,EAAK,GAClC,CAACK,GAAOC,CAAQ,IAAIN,EAA6C,IAAI,GACrE,CAACO,CAAW,IAAIP,EAAwC,MAAM;AAClE,QAAI,CAACZ,EAAW;AAEhB,UAAMoB,IAAoBvB,EAAA,GACpBwB,IAAoB,IAAID,EAAA;AAE9B,WAAAC,EAAkB,aAAapB,GAC3BG,QAA4B,WAAWA,IAC3CiB,EAAkB,iBAAiBnB,GACnCmB,EAAkB,OAAOlB,GACzBkB,EAAkB,kBAAkBhB,GAEpCgB,EAAkB,UAAU,MAAM;AAChC,MAAAV,EAAa,EAAI,GACjBK,EAAS,EAAK,GACdV,IAAA;AAAA,IAAU,GAEZe,EAAkB,UAAU,CAACC,MAAU;AACrC,MAAAJ,EAASI,CAAK,GACdX,EAAa,EAAK,GAClBH,IAAUc,CAAK;AAAA,IAAA,GAEjBD,EAAkB,WAAW,CAACC,MAAU;AACtC,YAAMC,IAAgBD,EAAM,QAAQA,EAAM,WAAW,GAC/C,EAAE,YAAAT,MAAeU,EAAc,CAAC;AAEtC,MAAAZ,EAAa,EAAK,GAClBG,EAAcD,CAAU,GACxBK,EAAS,IAAI,GACbT,IAAWa,CAAK;AAAA,IAAA,GAElBD,EAAkB,QAAQ,MAAM;AAC9B,MAAAV,EAAa,EAAK,GAClBJ,IAAA,GACAc,EAAkB,OAAOlB;AAAA,IAAA,GAGpBkB;AAAA,EAAA,CACR;AAED,EAAAG,EAAU,MAAM,MAAML,GAAa,KAAA,GAAQ,CAAA,CAAE;AAE7C,QAAMM,IAAQ,MAAMN,GAAa,MAAA,GAC3BO,IAAO,MAAMP,GAAa,KAAA;AAOhC,SAAO;AAAA,IACL,WAAAnB;AAAA,IACA,YAAAa;AAAA,IACA,aAAAM;AAAA,IACA,OAAAJ;AAAA,IACA,WAAAL;AAAA,IACA,OAAAO;AAAA,IACA,OAAAQ;AAAA,IACA,MAAAC;AAAA,IACA,QAda,CAACC,IAAQ,CAACjB,MAAc;AACrC,UAAIiB,UAAcF,EAAA;AAClB,MAAAC,EAAA;AAAA,IAAK;AAAA,EAYL;AAEJ;"}
@@ -1,58 +1,53 @@
1
- import { useState as H, useRef as y, useEffect as x } from "react";
1
+ import { useState as y, useRef as v, useEffect as R } from "react";
2
2
  import { useRefState as V } from "../useRefState/useRefState.mjs";
3
3
  import { isTarget as f } from "../../utils/helpers/isTarget.mjs";
4
- const d = ((...i) => {
5
- const t = f(i[0]) ? i[0] : void 0, r = t ? i[1] : typeof i[0] == "string" ? { initialValue: i[0] } : i[0], [a, c] = H(r?.initialValue ?? ""), o = V(), u = y(null), s = () => {
6
- const e = u.current;
4
+ const p = ((...t) => {
5
+ const n = f(t[0]) ? t[0] : void 0, o = n ? typeof t[1] == "object" ? t[1] : { initialValue: t[1] } : typeof t[0] == "object" ? t[0] : { initialValue: t[0] }, [g, h] = y(o?.initialValue ?? ""), s = V(), l = v(null), m = v(0), a = () => {
6
+ const e = l.current;
7
7
  if (!e) return;
8
- const n = e.style.minHeight, l = e.style.maxHeight;
8
+ const i = e.style.minHeight, u = e.style.maxHeight;
9
9
  e.style.height = "auto", e.style.minHeight = "auto", e.style.maxHeight = "none";
10
- const g = e.scrollHeight;
11
- e.style.height = `${g}px`, e.style.minHeight = n, e.style.maxHeight = l, r?.onResize?.();
10
+ const r = e.scrollHeight;
11
+ e.style.height = `${r}px`, e.style.minHeight = i, e.style.maxHeight = u, r !== m.current && o?.onResize?.(), m.current = r;
12
+ }, c = (e) => {
13
+ h(e);
14
+ const i = l.current;
15
+ i && (i.value = e, requestAnimationFrame(() => {
16
+ a();
17
+ }));
12
18
  };
13
- x(() => {
14
- if (!t && !o.state) return;
15
- const e = t ? f.getElement(t) : o.current;
19
+ R(() => {
20
+ if (!n && !s.state) return;
21
+ const e = n ? f.getElement(n) : s.current;
16
22
  if (!e) return;
17
- u.current = e, r?.initialValue && (e.value = r.initialValue), s();
18
- const n = (g) => {
19
- const v = g.target.value;
20
- c(v), requestAnimationFrame(() => {
21
- s();
23
+ l.current = e, o?.initialValue && (e.value = o.initialValue), a();
24
+ const i = (r) => {
25
+ const H = r.target.value;
26
+ c(H), requestAnimationFrame(() => {
27
+ a();
22
28
  });
23
- }, l = () => {
29
+ }, u = () => {
24
30
  requestAnimationFrame(() => {
25
- s();
31
+ a();
26
32
  });
27
33
  };
28
- return e.addEventListener("input", n), e.addEventListener("resize", l), () => {
29
- e.removeEventListener("input", n), e.removeEventListener("resize", l);
34
+ return e.addEventListener("input", i), e.addEventListener("resize", u), () => {
35
+ e.removeEventListener("input", i), e.removeEventListener("resize", u);
30
36
  };
31
- }, [t, o.state, f.getRefState(t), r?.initialValue]), x(() => {
32
- const e = u.current;
33
- e && (e.value = a, requestAnimationFrame(() => {
34
- s();
35
- }));
36
- }, [a]);
37
- const m = (e) => {
38
- c(e);
39
- const n = u.current;
40
- n && (n.value = e, requestAnimationFrame(() => {
41
- s();
42
- }));
43
- }, h = () => c("");
44
- return t ? {
45
- value: a,
46
- setValue: m,
47
- clear: h
37
+ }, [n, s.state, f.getRefState(n)]);
38
+ const x = () => h("");
39
+ return n ? {
40
+ value: g,
41
+ set: c,
42
+ clear: x
48
43
  } : {
49
- ref: o,
50
- value: a,
51
- setValue: m,
52
- clear: h
44
+ ref: s,
45
+ value: g,
46
+ set: c,
47
+ clear: x
53
48
  };
54
49
  });
55
50
  export {
56
- d as useTextareaAutosize
51
+ p as useTextareaAutosize
57
52
  };
58
53
  //# sourceMappingURL=useTextareaAutosize.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"useTextareaAutosize.mjs","sources":["../../../../src/hooks/useTextareaAutosize/useTextareaAutosize.ts"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\n\nimport type { HookTarget } from '@/utils/helpers';\n\nimport { isTarget } from '@/utils/helpers';\n\nimport type { StateRef } from '../useRefState/useRefState';\n\nimport { useRefState } from '../useRefState/useRefState';\n\n/** The use textarea autosize options */\nexport interface UseTextareaAutosizeOptions {\n /** The initial value for the textarea */\n initialValue?: string;\n /** Callback function called when the textarea size changes */\n onResize?: () => void;\n}\n\n/** The use textarea autosize return type */\nexport interface UseTextareaAutosizeReturn {\n /** The current value of the textarea */\n value: string;\n /** Function to clear the textarea value */\n clear: () => void;\n /** Function to set the textarea value */\n setValue: (value: string) => void;\n}\n\nexport interface UseTextareaAutosize {\n (target: HookTarget, options?: UseTextareaAutosizeOptions): UseTextareaAutosizeReturn;\n\n <Target extends HTMLTextAreaElement = HTMLTextAreaElement>(\n initialValue: string,\n target?: never\n ): UseTextareaAutosizeReturn & {\n ref: StateRef<Target>;\n };\n\n <Target extends HTMLTextAreaElement = HTMLTextAreaElement>(\n options?: UseTextareaAutosizeOptions,\n target?: never\n ): UseTextareaAutosizeReturn & {\n ref: StateRef<Target>;\n };\n}\n\n/**\n * @name useTextareaAutosize\n * @description - Hook that automatically adjusts textarea height based on content\n * @category Elements\n * @usage medium\n *\n * @overload\n * @param {HookTarget} target The target textarea element\n * @param {string} [options.initialValue] The initial value for the textarea\n * @param {Function} [options.onResize] Callback function called when the textarea size changes\n * @returns {UseTextareaAutosizeReturn} An object containing value, setValue and clear\n *\n * @example\n * const { value, setValue, clear } = useTextareaAutosize(ref);\n *\n * @overload\n * @template Target The textarea element type\n * @param {string} initialValue The initial value for the textarea\n * @returns {UseTextareaAutosizeReturn & { ref: StateRef<Target> }} An object containing ref, value, setValue and clear\n *\n * @example\n * const { ref, value, setValue, clear } = useTextareaAutosize('initial');\n *\n * @overload\n * @template Target The textarea element type\n * @param {string} [options.initialValue] The initial value for the textarea\n * @param {Function} [options.onResize] Callback function called when the textarea size changes\n * @returns {UseTextareaAutosizeReturn & { ref: StateRef<Target> }} An object containing ref, value, setValue and clear\n *\n * @example\n * const { ref, value, setValue, clear } = useTextareaAutosize();\n */\nexport const useTextareaAutosize = ((...params: any[]) => {\n const target = (isTarget(params[0]) ? params[0] : undefined) as HookTarget | undefined;\n\n const options = (\n target ? params[1] : typeof params[0] === 'string' ? { initialValue: params[0] } : params[0]\n ) as UseTextareaAutosizeOptions | undefined;\n\n const [value, setValue] = useState(options?.initialValue ?? '');\n const internalRef = useRefState<HTMLTextAreaElement>();\n const textareaRef = useRef<HTMLTextAreaElement | null>(null);\n\n const onTextareaResize = () => {\n const textarea = textareaRef.current;\n if (!textarea) return;\n\n const originalMinHeight = textarea.style.minHeight;\n const originalMaxHeight = textarea.style.maxHeight;\n\n textarea.style.height = 'auto';\n textarea.style.minHeight = 'auto';\n textarea.style.maxHeight = 'none';\n\n const scrollHeight = textarea.scrollHeight;\n\n textarea.style.height = `${scrollHeight}px`;\n textarea.style.minHeight = originalMinHeight;\n textarea.style.maxHeight = originalMaxHeight;\n\n options?.onResize?.();\n };\n\n useEffect(() => {\n if (!target && !internalRef.state) return;\n\n const element = (\n target ? isTarget.getElement(target) : internalRef.current\n ) as HTMLTextAreaElement;\n if (!element) return;\n\n textareaRef.current = element;\n if (options?.initialValue) element.value = options.initialValue;\n\n onTextareaResize();\n\n const onInput = (event: InputEvent) => {\n const newValue = (event.target as HTMLTextAreaElement).value;\n setValue(newValue);\n\n requestAnimationFrame(() => {\n onTextareaResize();\n });\n };\n\n const onResize = () => {\n requestAnimationFrame(() => {\n onTextareaResize();\n });\n };\n\n element.addEventListener('input', onInput as EventListener);\n element.addEventListener('resize', onResize as EventListener);\n\n return () => {\n element.removeEventListener('input', onInput as EventListener);\n element.removeEventListener('resize', onResize as EventListener);\n };\n }, [target, internalRef.state, isTarget.getRefState(target), options?.initialValue]);\n\n useEffect(() => {\n const textarea = textareaRef.current;\n if (!textarea) return;\n textarea.value = value;\n requestAnimationFrame(() => {\n onTextareaResize();\n });\n }, [value]);\n\n const setTextareaValue = (newValue: string) => {\n setValue(newValue);\n const textarea = textareaRef.current;\n if (textarea) {\n textarea.value = newValue;\n requestAnimationFrame(() => {\n onTextareaResize();\n });\n }\n };\n\n const clear = () => setValue('');\n\n if (target)\n return {\n value,\n setValue: setTextareaValue,\n clear\n };\n return {\n ref: internalRef,\n value,\n setValue: setTextareaValue,\n clear\n };\n}) as UseTextareaAutosize;\n"],"names":["useTextareaAutosize","params","target","isTarget","options","value","setValue","useState","internalRef","useRefState","textareaRef","useRef","onTextareaResize","textarea","originalMinHeight","originalMaxHeight","scrollHeight","useEffect","element","onInput","event","newValue","onResize","setTextareaValue","clear"],"mappings":";;;AA8EO,MAAMA,KAAuB,IAAIC,MAAkB;AACxD,QAAMC,IAAUC,EAASF,EAAO,CAAC,CAAC,IAAIA,EAAO,CAAC,IAAI,QAE5CG,IACJF,IAASD,EAAO,CAAC,IAAI,OAAOA,EAAO,CAAC,KAAM,WAAW,EAAE,cAAcA,EAAO,CAAC,EAAA,IAAMA,EAAO,CAAC,GAGvF,CAACI,GAAOC,CAAQ,IAAIC,EAASH,GAAS,gBAAgB,EAAE,GACxDI,IAAcC,EAAA,GACdC,IAAcC,EAAmC,IAAI,GAErDC,IAAmB,MAAM;AAC7B,UAAMC,IAAWH,EAAY;AAC7B,QAAI,CAACG,EAAU;AAEf,UAAMC,IAAoBD,EAAS,MAAM,WACnCE,IAAoBF,EAAS,MAAM;AAEzC,IAAAA,EAAS,MAAM,SAAS,QACxBA,EAAS,MAAM,YAAY,QAC3BA,EAAS,MAAM,YAAY;AAE3B,UAAMG,IAAeH,EAAS;AAE9B,IAAAA,EAAS,MAAM,SAAS,GAAGG,CAAY,MACvCH,EAAS,MAAM,YAAYC,GAC3BD,EAAS,MAAM,YAAYE,GAE3BX,GAAS,WAAA;AAAA,EAAW;AAGtB,EAAAa,EAAU,MAAM;AACd,QAAI,CAACf,KAAU,CAACM,EAAY,MAAO;AAEnC,UAAMU,IACJhB,IAASC,EAAS,WAAWD,CAAM,IAAIM,EAAY;AAErD,QAAI,CAACU,EAAS;AAEd,IAAAR,EAAY,UAAUQ,GAClBd,GAAS,iBAAcc,EAAQ,QAAQd,EAAQ,eAEnDQ,EAAA;AAEA,UAAMO,IAAU,CAACC,MAAsB;AACrC,YAAMC,IAAYD,EAAM,OAA+B;AACvD,MAAAd,EAASe,CAAQ,GAEjB,sBAAsB,MAAM;AAC1B,QAAAT,EAAA;AAAA,MAAiB,CAClB;AAAA,IAAA,GAGGU,IAAW,MAAM;AACrB,4BAAsB,MAAM;AAC1B,QAAAV,EAAA;AAAA,MAAiB,CAClB;AAAA,IAAA;AAGH,WAAAM,EAAQ,iBAAiB,SAASC,CAAwB,GAC1DD,EAAQ,iBAAiB,UAAUI,CAAyB,GAErD,MAAM;AACX,MAAAJ,EAAQ,oBAAoB,SAASC,CAAwB,GAC7DD,EAAQ,oBAAoB,UAAUI,CAAyB;AAAA,IAAA;AAAA,EACjE,GACC,CAACpB,GAAQM,EAAY,OAAOL,EAAS,YAAYD,CAAM,GAAGE,GAAS,YAAY,CAAC,GAEnFa,EAAU,MAAM;AACd,UAAMJ,IAAWH,EAAY;AAC7B,IAAKG,MACLA,EAAS,QAAQR,GACjB,sBAAsB,MAAM;AAC1B,MAAAO,EAAA;AAAA,IAAiB,CAClB;AAAA,EAAA,GACA,CAACP,CAAK,CAAC;AAEV,QAAMkB,IAAmB,CAACF,MAAqB;AAC7C,IAAAf,EAASe,CAAQ;AACjB,UAAMR,IAAWH,EAAY;AAC7B,IAAIG,MACFA,EAAS,QAAQQ,GACjB,sBAAsB,MAAM;AAC1B,MAAAT,EAAA;AAAA,IAAiB,CAClB;AAAA,EACH,GAGIY,IAAQ,MAAMlB,EAAS,EAAE;AAE/B,SAAIJ,IACK;AAAA,IACL,OAAAG;AAAA,IACA,UAAUkB;AAAA,IACV,OAAAC;AAAA,EAAA,IAEG;AAAA,IACL,KAAKhB;AAAA,IACL,OAAAH;AAAA,IACA,UAAUkB;AAAA,IACV,OAAAC;AAAA,EAAA;AAEJ;"}
1
+ {"version":3,"file":"useTextareaAutosize.mjs","sources":["../../../../src/hooks/useTextareaAutosize/useTextareaAutosize.ts"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\n\nimport type { HookTarget } from '@/utils/helpers';\n\nimport { isTarget } from '@/utils/helpers';\n\nimport type { StateRef } from '../useRefState/useRefState';\n\nimport { useRefState } from '../useRefState/useRefState';\n\n/** The use textarea autosize options */\nexport interface UseTextareaAutosizeOptions {\n /** The initial value for the textarea */\n initialValue?: string;\n /** Callback function called when the textarea size changes */\n onResize?: () => void;\n}\n\n/** The use textarea autosize return type */\nexport interface UseTextareaAutosizeReturn {\n /** The current value of the textarea */\n value: string;\n /** Function to clear the textarea value */\n clear: () => void;\n /** Function to set the textarea value */\n set: (value: string) => void;\n}\n\nexport interface UseTextareaAutosize {\n (target: HookTarget, options?: UseTextareaAutosizeOptions): UseTextareaAutosizeReturn;\n\n (target: HookTarget, initialValue: string): UseTextareaAutosizeReturn;\n\n <Target extends HTMLTextAreaElement = HTMLTextAreaElement>(\n initialValue: string,\n target?: never\n ): UseTextareaAutosizeReturn & {\n ref: StateRef<Target>;\n };\n\n <Target extends HTMLTextAreaElement = HTMLTextAreaElement>(\n options?: UseTextareaAutosizeOptions,\n target?: never\n ): UseTextareaAutosizeReturn & {\n ref: StateRef<Target>;\n };\n}\n\n/**\n * @name useTextareaAutosize\n * @description - Hook that automatically adjusts textarea height based on content\n * @category Elements\n * @usage medium\n *\n * @overload\n * @param {HookTarget} target The target textarea element\n * @param {string} [options.initialValue] The initial value for the textarea\n * @param {Function} [options.onResize] Callback function called when the textarea size changes\n * @returns {UseTextareaAutosizeReturn} An object containing value, setValue and clear\n *\n * @example\n * const { value, setValue, clear } = useTextareaAutosize(ref);\n *\n * @overload\n * @param {HookTarget} target The target textarea element\n * @param {string} initialValue The initial value for the textarea\n * @returns {UseTextareaAutosizeReturn} An object containing value, setValue and clear\n *\n * @example\n * const { value, setValue, clear } = useTextareaAutosize(ref, 'initial');\n *\n * @overload\n * @template Target The textarea element type\n * @param {string} initialValue The initial value for the textarea\n * @returns {UseTextareaAutosizeReturn & { ref: StateRef<Target> }} An object containing ref, value, setValue and clear\n *\n * @example\n * const { ref, value, setValue, clear } = useTextareaAutosize('initial');\n *\n * @overload\n * @template Target The textarea element type\n * @param {string} [options.initialValue] The initial value for the textarea\n * @param {Function} [options.onResize] Callback function called when the textarea size changes\n * @returns {UseTextareaAutosizeReturn & { ref: StateRef<Target> }} An object containing ref, value, setValue and clear\n *\n * @example\n * const { ref, value, setValue, clear } = useTextareaAutosize();\n */\nexport const useTextareaAutosize = ((...params: any[]) => {\n const target = (isTarget(params[0]) ? params[0] : undefined) as HookTarget | undefined;\n\n const options = (\n target\n ? typeof params[1] === 'object'\n ? params[1]\n : { initialValue: params[1] }\n : typeof params[0] === 'object'\n ? params[0]\n : { initialValue: params[0] }\n ) as UseTextareaAutosizeOptions | undefined;\n\n const [value, setValue] = useState(options?.initialValue ?? '');\n const internalRef = useRefState<HTMLTextAreaElement>();\n const textareaRef = useRef<HTMLTextAreaElement | null>(null);\n const scrollHeightRef = useRef(0);\n\n const onTextareaResize = () => {\n const textarea = textareaRef.current;\n if (!textarea) return;\n\n const originalMinHeight = textarea.style.minHeight;\n const originalMaxHeight = textarea.style.maxHeight;\n\n textarea.style.height = 'auto';\n textarea.style.minHeight = 'auto';\n textarea.style.maxHeight = 'none';\n\n const scrollHeight = textarea.scrollHeight;\n\n textarea.style.height = `${scrollHeight}px`;\n textarea.style.minHeight = originalMinHeight;\n textarea.style.maxHeight = originalMaxHeight;\n\n if (scrollHeight !== scrollHeightRef.current) options?.onResize?.();\n scrollHeightRef.current = scrollHeight;\n };\n\n const setTextareaValue = (newValue: string) => {\n setValue(newValue);\n const textarea = textareaRef.current;\n if (!textarea) return;\n textarea.value = newValue;\n requestAnimationFrame(() => {\n onTextareaResize();\n });\n };\n\n useEffect(() => {\n if (!target && !internalRef.state) return;\n\n const element = (\n target ? isTarget.getElement(target) : internalRef.current\n ) as HTMLTextAreaElement;\n if (!element) return;\n\n textareaRef.current = element;\n if (options?.initialValue) element.value = options.initialValue;\n\n onTextareaResize();\n\n const onInput = (event: InputEvent) => {\n const newValue = (event.target as HTMLTextAreaElement).value;\n setTextareaValue(newValue);\n\n requestAnimationFrame(() => {\n onTextareaResize();\n });\n };\n\n const onResize = () => {\n requestAnimationFrame(() => {\n onTextareaResize();\n });\n };\n\n element.addEventListener('input', onInput as EventListener);\n element.addEventListener('resize', onResize as EventListener);\n\n return () => {\n element.removeEventListener('input', onInput as EventListener);\n element.removeEventListener('resize', onResize as EventListener);\n };\n }, [target, internalRef.state, isTarget.getRefState(target)]);\n\n const clear = () => setValue('');\n\n if (target)\n return {\n value,\n set: setTextareaValue,\n clear\n };\n return {\n ref: internalRef,\n value,\n set: setTextareaValue,\n clear\n };\n}) as UseTextareaAutosize;\n"],"names":["useTextareaAutosize","params","target","isTarget","options","value","setValue","useState","internalRef","useRefState","textareaRef","useRef","scrollHeightRef","onTextareaResize","textarea","originalMinHeight","originalMaxHeight","scrollHeight","setTextareaValue","newValue","useEffect","element","onInput","event","onResize","clear"],"mappings":";;;AAwFO,MAAMA,KAAuB,IAAIC,MAAkB;AACxD,QAAMC,IAAUC,EAASF,EAAO,CAAC,CAAC,IAAIA,EAAO,CAAC,IAAI,QAE5CG,IACJF,IACI,OAAOD,EAAO,CAAC,KAAM,WACnBA,EAAO,CAAC,IACR,EAAE,cAAcA,EAAO,CAAC,EAAA,IAC1B,OAAOA,EAAO,CAAC,KAAM,WACnBA,EAAO,CAAC,IACR,EAAE,cAAcA,EAAO,CAAC,EAAA,GAG1B,CAACI,GAAOC,CAAQ,IAAIC,EAASH,GAAS,gBAAgB,EAAE,GACxDI,IAAcC,EAAA,GACdC,IAAcC,EAAmC,IAAI,GACrDC,IAAkBD,EAAO,CAAC,GAE1BE,IAAmB,MAAM;AAC7B,UAAMC,IAAWJ,EAAY;AAC7B,QAAI,CAACI,EAAU;AAEf,UAAMC,IAAoBD,EAAS,MAAM,WACnCE,IAAoBF,EAAS,MAAM;AAEzC,IAAAA,EAAS,MAAM,SAAS,QACxBA,EAAS,MAAM,YAAY,QAC3BA,EAAS,MAAM,YAAY;AAE3B,UAAMG,IAAeH,EAAS;AAE9B,IAAAA,EAAS,MAAM,SAAS,GAAGG,CAAY,MACvCH,EAAS,MAAM,YAAYC,GAC3BD,EAAS,MAAM,YAAYE,GAEvBC,MAAiBL,EAAgB,WAASR,GAAS,WAAA,GACvDQ,EAAgB,UAAUK;AAAA,EAAA,GAGtBC,IAAmB,CAACC,MAAqB;AAC7C,IAAAb,EAASa,CAAQ;AACjB,UAAML,IAAWJ,EAAY;AAC7B,IAAKI,MACLA,EAAS,QAAQK,GACjB,sBAAsB,MAAM;AAC1B,MAAAN,EAAA;AAAA,IAAiB,CAClB;AAAA,EAAA;AAGH,EAAAO,EAAU,MAAM;AACd,QAAI,CAAClB,KAAU,CAACM,EAAY,MAAO;AAEnC,UAAMa,IACJnB,IAASC,EAAS,WAAWD,CAAM,IAAIM,EAAY;AAErD,QAAI,CAACa,EAAS;AAEd,IAAAX,EAAY,UAAUW,GAClBjB,GAAS,iBAAciB,EAAQ,QAAQjB,EAAQ,eAEnDS,EAAA;AAEA,UAAMS,IAAU,CAACC,MAAsB;AACrC,YAAMJ,IAAYI,EAAM,OAA+B;AACvD,MAAAL,EAAiBC,CAAQ,GAEzB,sBAAsB,MAAM;AAC1B,QAAAN,EAAA;AAAA,MAAiB,CAClB;AAAA,IAAA,GAGGW,IAAW,MAAM;AACrB,4BAAsB,MAAM;AAC1B,QAAAX,EAAA;AAAA,MAAiB,CAClB;AAAA,IAAA;AAGH,WAAAQ,EAAQ,iBAAiB,SAASC,CAAwB,GAC1DD,EAAQ,iBAAiB,UAAUG,CAAyB,GAErD,MAAM;AACX,MAAAH,EAAQ,oBAAoB,SAASC,CAAwB,GAC7DD,EAAQ,oBAAoB,UAAUG,CAAyB;AAAA,IAAA;AAAA,EACjE,GACC,CAACtB,GAAQM,EAAY,OAAOL,EAAS,YAAYD,CAAM,CAAC,CAAC;AAE5D,QAAMuB,IAAQ,MAAMnB,EAAS,EAAE;AAE/B,SAAIJ,IACK;AAAA,IACL,OAAAG;AAAA,IACA,KAAKa;AAAA,IACL,OAAAO;AAAA,EAAA,IAEG;AAAA,IACL,KAAKjB;AAAA,IACL,OAAAH;AAAA,IACA,KAAKa;AAAA,IACL,OAAAO;AAAA,EAAA;AAEJ;"}
@@ -13,7 +13,7 @@ import { useBluetooth as I } from "./hooks/useBluetooth/useBluetooth.mjs";
13
13
  import { useBroadcastChannel as O } from "./hooks/useBroadcastChannel/useBroadcastChannel.mjs";
14
14
  import { useClipboard as h } from "./hooks/useClipboard/useClipboard.mjs";
15
15
  import { useCopy as _ } from "./hooks/useCopy/useCopy.mjs";
16
- import { useCssVar as b } from "./hooks/useCssVar/useCssVar.mjs";
16
+ import { useCssVar as D } from "./hooks/useCssVar/useCssVar.mjs";
17
17
  import { useDisplayMedia as M } from "./hooks/useDisplayMedia/useDisplayMedia.mjs";
18
18
  import { useDocumentTitle as B } from "./hooks/useDocumentTitle/useDocumentTitle.mjs";
19
19
  import { useEventSource as F } from "./hooks/useEventSource/useEventSource.mjs";
@@ -38,7 +38,7 @@ import { getSpeechRecognition as Ae, useSpeechRecognition as Ie } from "./hooks/
38
38
  import { useSpeechSynthesis as Oe } from "./hooks/useSpeechSynthesis/useSpeechSynthesis.mjs";
39
39
  import { useVibrate as he } from "./hooks/useVibrate/useVibrate.mjs";
40
40
  import { useVirtualKeyboard as _e } from "./hooks/useVirtualKeyboard/useVirtualKeyboard.mjs";
41
- import { useWakeLock as be } from "./hooks/useWakeLock/useWakeLock.mjs";
41
+ import { useWakeLock as De } from "./hooks/useWakeLock/useWakeLock.mjs";
42
42
  import { useWebSocket as Me } from "./hooks/useWebSocket/useWebSocket.mjs";
43
43
  import { useLogger as Be } from "./hooks/useLogger/useLogger.mjs";
44
44
  import { useRenderCount as Fe } from "./hooks/useRenderCount/useRenderCount.mjs";
@@ -62,7 +62,7 @@ import { useSticky as Io } from "./hooks/useSticky/useSticky.mjs";
62
62
  import { useTextareaAutosize as Oo } from "./hooks/useTextareaAutosize/useTextareaAutosize.mjs";
63
63
  import { useTextDirection as ho } from "./hooks/useTextDirection/useTextDirection.mjs";
64
64
  import { useFul as _o } from "./hooks/useFul/useFul.mjs";
65
- import { useLess as bo } from "./hooks/useLess/useLess.mjs";
65
+ import { useLess as Do } from "./hooks/useLess/useLess.mjs";
66
66
  import { useOnce as Mo } from "./hooks/useOnce/useOnce.mjs";
67
67
  import { useAsyncEffect as Bo } from "./hooks/useAsyncEffect/useAsyncEffect.mjs";
68
68
  import { useDidUpdate as Fo } from "./hooks/useDidUpdate/useDidUpdate.mjs";
@@ -83,7 +83,7 @@ import { isHotkeyMatch as Pr, useHotkeys as Ar } from "./hooks/useHotkeys/useHot
83
83
  import { useIdle as yr } from "./hooks/useIdle/useIdle.mjs";
84
84
  import { useInfiniteScroll as kr } from "./hooks/useInfiniteScroll/useInfiniteScroll.mjs";
85
85
  import { useIntersectionObserver as vr } from "./hooks/useIntersectionObserver/useIntersectionObserver.mjs";
86
- import { useKeyboard as Dr } from "./hooks/useKeyboard/useKeyboard.mjs";
86
+ import { useKeyboard as br } from "./hooks/useKeyboard/useKeyboard.mjs";
87
87
  import { useKeyPress as Lr } from "./hooks/useKeyPress/useKeyPress.mjs";
88
88
  import { useKeyPressEvent as Nr } from "./hooks/useKeyPressEvent/useKeyPressEvent.mjs";
89
89
  import { useKeysPressed as Kr } from "./hooks/useKeysPressed/useKeysPressed.mjs";
@@ -108,7 +108,7 @@ import { scrollTo as dt, useWindowScroll as Ct } from "./hooks/useWindowScroll/u
108
108
  import { useWindowSize as At } from "./hooks/useWindowSize/useWindowSize.mjs";
109
109
  import { useBoolean as yt } from "./hooks/useBoolean/useBoolean.mjs";
110
110
  import { useControllableState as kt } from "./hooks/useControllableState/useControllableState.mjs";
111
- import { COOKIE_EVENT as vt, dispatchCookieEvent as _t, getCookie as Dt, getCookies as bt, removeCookie as Lt, removeCookieItem as Mt, setCookie as Nt, setCookieItem as Bt, useCookie as Kt } from "./hooks/useCookie/useCookie.mjs";
111
+ import { COOKIE_EVENT as vt, dispatchCookieEvent as _t, getCookie as bt, getCookies as Dt, removeCookie as Lt, removeCookieItem as Mt, setCookie as Nt, setCookieItem as Bt, useCookie as Kt } from "./hooks/useCookie/useCookie.mjs";
112
112
  import { clearCookies as Ut, useCookies as Vt } from "./hooks/useCookies/useCookies.mjs";
113
113
  import { useCounter as wt } from "./hooks/useCounter/useCounter.mjs";
114
114
  import { useDefault as zt } from "./hooks/useDefault/useDefault.mjs";
@@ -128,7 +128,7 @@ import { useSet as ds } from "./hooks/useSet/useSet.mjs";
128
128
  import { stateHistoryReducer as Ps, useStateHistory as As } from "./hooks/useStateHistory/useStateHistory.mjs";
129
129
  import { useStep as ys } from "./hooks/useStep/useStep.mjs";
130
130
  import { STORAGE_EVENT as ks, dispatchStorageEvent as hs, useStorage as vs } from "./hooks/useStorage/useStorage.mjs";
131
- import { useToggle as Ds } from "./hooks/useToggle/useToggle.mjs";
131
+ import { useToggle as bs } from "./hooks/useToggle/useToggle.mjs";
132
132
  import { URL_SEARCH_PARAMS_EVENT as Ls, createQueryString as Ms, dispatchUrlSearchParamsEvent as Ns, getUrlSearchParams as Bs, useUrlSearchParam as Ks } from "./hooks/useUrlSearchParam/useUrlSearchParam.mjs";
133
133
  import { useUrlSearchParams as Us } from "./hooks/useUrlSearchParams/useUrlSearchParams.mjs";
134
134
  import { useWizard as Hs } from "./hooks/useWizard/useWizard.mjs";
@@ -144,23 +144,24 @@ import { usePreferredContrast as pu } from "./hooks/usePreferredContrast/usePref
144
144
  import { usePreferredDark as xu } from "./hooks/usePreferredDark/usePreferredDark.mjs";
145
145
  import { usePreferredLanguages as iu } from "./hooks/usePreferredLanguages/usePreferredLanguages.mjs";
146
146
  import { usePreferredReducedMotion as cu } from "./hooks/usePreferredReducedMotion/usePreferredReducedMotion.mjs";
147
- import { useConst as Su } from "./hooks/useConst/useConst.mjs";
148
- import { useDebounceCallback as Tu } from "./hooks/useDebounceCallback/useDebounceCallback.mjs";
149
- import { useDebounceState as Ru } from "./hooks/useDebounceState/useDebounceState.mjs";
150
- import { useDebounceValue as Cu } from "./hooks/useDebounceValue/useDebounceValue.mjs";
151
- import { useEvent as Au } from "./hooks/useEvent/useEvent.mjs";
152
- import { useLastChanged as yu } from "./hooks/useLastChanged/useLastChanged.mjs";
153
- import { useLatest as ku } from "./hooks/useLatest/useLatest.mjs";
154
- import { usePrevious as vu } from "./hooks/usePrevious/usePrevious.mjs";
155
- import { useThrottleCallback as Du } from "./hooks/useThrottleCallback/useThrottleCallback.mjs";
156
- import { useThrottleState as Lu } from "./hooks/useThrottleState/useThrottleState.mjs";
157
- import { useThrottleValue as Nu } from "./hooks/useThrottleValue/useThrottleValue.mjs";
158
- import { copy as Ku, legacyCopyToClipboard as Fu } from "./utils/helpers/copy.mjs";
159
- import { debounce as Vu } from "./utils/helpers/debounce.mjs";
160
- import { getDate as wu } from "./utils/helpers/getDate.mjs";
161
- import { getRetry as zu } from "./utils/helpers/getRetry.mjs";
162
- import { getRefState as Qu, isTarget as Xu, target as qu, targetSymbol as Zu } from "./utils/helpers/isTarget.mjs";
163
- import { throttle as Ju } from "./utils/helpers/throttle.mjs";
147
+ import { useBatchedCallback as Su } from "./hooks/useBatchedCallback/useBatchedCallback.mjs";
148
+ import { useConst as Tu } from "./hooks/useConst/useConst.mjs";
149
+ import { useDebounceCallback as Ru } from "./hooks/useDebounceCallback/useDebounceCallback.mjs";
150
+ import { useDebounceState as Cu } from "./hooks/useDebounceState/useDebounceState.mjs";
151
+ import { useDebounceValue as Au } from "./hooks/useDebounceValue/useDebounceValue.mjs";
152
+ import { useEvent as yu } from "./hooks/useEvent/useEvent.mjs";
153
+ import { useLastChanged as ku } from "./hooks/useLastChanged/useLastChanged.mjs";
154
+ import { useLatest as vu } from "./hooks/useLatest/useLatest.mjs";
155
+ import { usePrevious as bu } from "./hooks/usePrevious/usePrevious.mjs";
156
+ import { useThrottleCallback as Lu } from "./hooks/useThrottleCallback/useThrottleCallback.mjs";
157
+ import { useThrottleState as Nu } from "./hooks/useThrottleState/useThrottleState.mjs";
158
+ import { useThrottleValue as Ku } from "./hooks/useThrottleValue/useThrottleValue.mjs";
159
+ import { copy as Uu, legacyCopyToClipboard as Vu } from "./utils/helpers/copy.mjs";
160
+ import { debounce as wu } from "./utils/helpers/debounce.mjs";
161
+ import { getDate as zu } from "./utils/helpers/getDate.mjs";
162
+ import { getRetry as Qu } from "./utils/helpers/getRetry.mjs";
163
+ import { getRefState as qu, isTarget as Zu, target as ju, targetSymbol as Ju } from "./utils/helpers/isTarget.mjs";
164
+ import { throttle as $u } from "./utils/helpers/throttle.mjs";
164
165
  export {
165
166
  Jo as BREAKPOINTS_ANT_DESIGN,
166
167
  Yo as BREAKPOINTS_BOOTSTRAP_V5,
@@ -181,33 +182,33 @@ export {
181
182
  Ls as URL_SEARCH_PARAMS_EVENT,
182
183
  us as assignRef,
183
184
  Ut as clearCookies,
184
- Ku as copy,
185
+ Uu as copy,
185
186
  r as createContext,
186
187
  s as createEventEmitter,
187
188
  Ms as createQueryString,
188
189
  m as createReactiveContext,
189
190
  Ss as createRefState,
190
191
  f as createStore,
191
- Vu as debounce,
192
+ wu as debounce,
192
193
  Qo as deepEqual,
193
194
  _t as dispatchCookieEvent,
194
195
  hs as dispatchStorageEvent,
195
196
  Ns as dispatchUrlSearchParamsEvent,
196
197
  se as getConnection,
197
- Dt as getCookie,
198
- bt as getCookies,
199
- wu as getDate,
198
+ bt as getCookie,
199
+ Dt as getCookies,
200
+ zu as getDate,
200
201
  jt as getHash,
201
202
  ru as getOperatingSystem,
202
203
  it as getRangesSelection,
203
- Qu as getRefState,
204
- zu as getRetry,
204
+ qu as getRefState,
205
+ Qu as getRetry,
205
206
  Ae as getSpeechRecognition,
206
207
  Js as getTimeFromSeconds,
207
208
  Bs as getUrlSearchParams,
208
209
  Pr as isHotkeyMatch,
209
- Xu as isTarget,
210
- Fu as legacyCopyToClipboard,
210
+ Zu as isTarget,
211
+ Vu as legacyCopyToClipboard,
211
212
  q as mapGamepadToXbox360Controller,
212
213
  ms as mergeRefs,
213
214
  Lt as removeCookie,
@@ -216,15 +217,16 @@ export {
216
217
  Nt as setCookie,
217
218
  Bt as setCookieItem,
218
219
  Ps as stateHistoryReducer,
219
- qu as target,
220
- Zu as targetSymbol,
221
- Ju as throttle,
220
+ ju as target,
221
+ Ju as targetSymbol,
222
+ $u as throttle,
222
223
  $ as timeRangeToArray,
223
224
  ze as useActiveElement,
224
225
  a as useAsync,
225
226
  Bo as useAsyncEffect,
226
227
  d as useAudio,
227
228
  Qe as useAutoScroll,
229
+ Su as useBatchedCallback,
228
230
  P as useBattery,
229
231
  I as useBluetooth,
230
232
  yt as useBoolean,
@@ -233,16 +235,16 @@ export {
233
235
  eu as useBrowserLanguage,
234
236
  qe as useClickOutside,
235
237
  h as useClipboard,
236
- Su as useConst,
238
+ Tu as useConst,
237
239
  kt as useControllableState,
238
240
  Kt as useCookie,
239
241
  Vt as useCookies,
240
242
  _ as useCopy,
241
243
  wt as useCounter,
242
- b as useCssVar,
243
- Tu as useDebounceCallback,
244
- Ru as useDebounceState,
245
- Cu as useDebounceValue,
244
+ D as useCssVar,
245
+ Ru as useDebounceCallback,
246
+ Cu as useDebounceState,
247
+ Au as useDebounceValue,
246
248
  zt as useDefault,
247
249
  fr as useDeviceMotion,
248
250
  ar as useDeviceOrientation,
@@ -256,7 +258,7 @@ export {
256
258
  Je as useDoubleClick,
257
259
  $e as useDropZone,
258
260
  gr as useElementSize,
259
- Au as useEvent,
261
+ yu as useEvent,
260
262
  dr as useEventListener,
261
263
  F as useEventSource,
262
264
  V as useEyeDropper,
@@ -282,11 +284,11 @@ export {
282
284
  wo as useIsomorphicLayoutEffect,
283
285
  Lr as useKeyPress,
284
286
  Nr as useKeyPressEvent,
285
- Dr as useKeyboard,
287
+ br as useKeyboard,
286
288
  Kr as useKeysPressed,
287
- yu as useLastChanged,
288
- ku as useLatest,
289
- bo as useLess,
289
+ ku as useLastChanged,
290
+ vu as useLatest,
291
+ Do as useLess,
290
292
  $t as useList,
291
293
  os as useLocalStorage,
292
294
  n as useLockCallback,
@@ -324,7 +326,7 @@ export {
324
326
  xu as usePreferredDark,
325
327
  iu as usePreferredLanguages,
326
328
  cu as usePreferredReducedMotion,
327
- vu as usePrevious,
329
+ bu as usePrevious,
328
330
  g as useQuery,
329
331
  is as useQueue,
330
332
  Re as useRaf,
@@ -353,20 +355,20 @@ export {
353
355
  ho as useTextDirection,
354
356
  nt as useTextSelection,
355
357
  Oo as useTextareaAutosize,
356
- Du as useThrottleCallback,
357
- Lu as useThrottleState,
358
- Nu as useThrottleValue,
358
+ Lu as useThrottleCallback,
359
+ Nu as useThrottleState,
360
+ Ku as useThrottleValue,
359
361
  Xs as useTime,
360
362
  Zs as useTimeout,
361
363
  Ys as useTimer,
362
- Ds as useToggle,
364
+ bs as useToggle,
363
365
  Zo as useUnmount,
364
366
  Ks as useUrlSearchParam,
365
367
  Us as useUrlSearchParams,
366
368
  he as useVibrate,
367
369
  _e as useVirtualKeyboard,
368
370
  lt as useVisibility,
369
- be as useWakeLock,
371
+ De as useWakeLock,
370
372
  Me as useWebSocket,
371
373
  Et as useWindowEvent,
372
374
  gt as useWindowFocus,
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -2,10 +2,11 @@ type StoreSetAction<Value> = ((prev: Value) => Partial<Value>) | Partial<Value>;
2
2
  type StoreListener<Value> = (state: Value, prevState: Value) => void;
3
3
  type StoreCreator<Value> = (set: (action: StoreSetAction<Value>) => void, get: () => Value) => Value;
4
4
  export interface StoreApi<Value> {
5
- getInitialState: () => Value;
6
- getState: () => Value;
7
- setState: (action: StoreSetAction<Value>) => void;
5
+ get: () => Value;
6
+ getInitial: () => Value;
7
+ set: (action: StoreSetAction<Value>) => void;
8
8
  subscribe: (listener: StoreListener<Value>) => () => void;
9
+ use: (() => Value) & (<Selected>(selector: (state: Value) => Selected) => Selected) & (<Selected>(selector?: (state: Value) => Selected) => Selected | Value);
9
10
  }
10
11
  /**
11
12
  * @name createStore
@@ -23,13 +24,5 @@ export interface StoreApi<Value> {
23
24
  * increment: () => set(state => ({ count: state.count + 1 }))
24
25
  * }));
25
26
  */
26
- export declare const createStore: <Value>(createState: StoreCreator<Value> | Value) => {
27
- set: (action: StoreSetAction<Value>) => void;
28
- get: () => Value;
29
- use: {
30
- (): Value;
31
- <Selected>(selector: (state: Value) => Selected): Selected;
32
- };
33
- subscribe: (listener: StoreListener<Value>) => () => boolean;
34
- };
27
+ export declare const createStore: <Value>(createState: StoreCreator<Value> | Value) => StoreApi<Value>;
35
28
  export {};
@@ -0,0 +1,19 @@
1
+ export type BatchedCallback<Params extends unknown[]> = ((...args: Params) => void) & {
2
+ flush: () => void;
3
+ cancel: () => void;
4
+ };
5
+ /**
6
+ * @name useBatchedCallback
7
+ * @description - Hook that batches calls and forwards them to a callback
8
+ * @category Utilities
9
+ * @usage medium
10
+ *
11
+ * @template Params The type of the params
12
+ * @param {(batch: Params[]) => void} callback The callback that receives a batch of calls
13
+ * @param {number} batchSize The maximum size of a batch before it is flushed
14
+ * @returns {BatchedCallback<Params>} The batched callback with flush and cancel helpers
15
+ *
16
+ * @example
17
+ * const batched = useBatchedCallback((batch) => console.log(batch), 5);
18
+ */
19
+ export declare const useBatchedCallback: <Params extends unknown[]>(callback: (batch: Params[]) => void, size: number) => BatchedCallback<Params>;
@@ -11,12 +11,11 @@ declare global {
11
11
  }
12
12
  export type UseOtpCredentialCallback = (otp: Credential | null) => void;
13
13
  export interface UseOtpCredentialParams {
14
- onError: (error: any) => void;
15
- onSuccess: (credential: Credential | null) => void;
14
+ onError?: (error: any) => void;
15
+ onSuccess?: (credential: Credential | null) => void;
16
16
  }
17
17
  export interface UseOtpCredentialReturn {
18
18
  abort: AbortController['abort'];
19
- aborted: boolean;
20
19
  supported: boolean;
21
20
  get: () => Promise<Credential | null>;
22
21
  }
@@ -28,7 +28,7 @@ interface UseSpeechRecognitionReturn {
28
28
  /** Whether the hook is currently listening for speech */
29
29
  listening: boolean;
30
30
  /** The speech recognition instance */
31
- recognition: SpeechRecognition;
31
+ recognition?: SpeechRecognition;
32
32
  /** Whether the current browser supports the Web Speech API */
33
33
  supported: boolean;
34
34
  /** The current transcript */
@@ -14,10 +14,11 @@ export interface UseTextareaAutosizeReturn {
14
14
  /** Function to clear the textarea value */
15
15
  clear: () => void;
16
16
  /** Function to set the textarea value */
17
- setValue: (value: string) => void;
17
+ set: (value: string) => void;
18
18
  }
19
19
  export interface UseTextareaAutosize {
20
20
  (target: HookTarget, options?: UseTextareaAutosizeOptions): UseTextareaAutosizeReturn;
21
+ (target: HookTarget, initialValue: string): UseTextareaAutosizeReturn;
21
22
  <Target extends HTMLTextAreaElement = HTMLTextAreaElement>(initialValue: string, target?: never): UseTextareaAutosizeReturn & {
22
23
  ref: StateRef<Target>;
23
24
  };
@@ -41,6 +42,14 @@ export interface UseTextareaAutosize {
41
42
  * const { value, setValue, clear } = useTextareaAutosize(ref);
42
43
  *
43
44
  * @overload
45
+ * @param {HookTarget} target The target textarea element
46
+ * @param {string} initialValue The initial value for the textarea
47
+ * @returns {UseTextareaAutosizeReturn} An object containing value, setValue and clear
48
+ *
49
+ * @example
50
+ * const { value, setValue, clear } = useTextareaAutosize(ref, 'initial');
51
+ *
52
+ * @overload
44
53
  * @template Target The textarea element type
45
54
  * @param {string} initialValue The initial value for the textarea
46
55
  * @returns {UseTextareaAutosizeReturn & { ref: StateRef<Target> }} An object containing ref, value, setValue and clear
@@ -1,3 +1,4 @@
1
+ export * from './useBatchedCallback/useBatchedCallback';
1
2
  export * from './useConst/useConst';
2
3
  export * from './useDebounceCallback/useDebounceCallback';
3
4
  export * from './useDebounceState/useDebounceState';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@siberiacancode/reactuse",
3
- "version": "0.3.5",
3
+ "version": "0.3.6",
4
4
  "description": "The ultimate collection of react hooks",
5
5
  "author": {
6
6
  "name": "SIBERIA CAN CODE 🧊",