@siberiacancode/reactuse 0.2.27 → 0.2.28

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.
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("react"),b=s=>{let e;const o=new Set,r=t=>{const S=typeof t=="function"?t(e):t;if(!Object.is(S,e)){const i=e;e=S,o.forEach(a=>a(e,i))}},n=()=>e,c=()=>e,u=t=>(o.add(t),()=>o.delete(t));return typeof s=="function"?e=s(r,n):e=s,{set:r,get:n,use:t=>f.useSyncExternalStore(u,()=>t?t(n()):n(),()=>t?t(c()):c()),subscribe:u}};exports.createStore=b;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const b=require("react"),l=o=>{let e;const r=new Set,c=t=>{const n=typeof t=="function"?t(e):t;if(!Object.is(n,e)){const a=e;e=typeof n!="object"||n===null?n:Object.assign({},e,n),r.forEach(f=>f(e,a))}},u=t=>(r.add(t),()=>r.delete(t)),s=()=>e,i=()=>e;typeof o=="function"?e=o(c,s):e=o;function S(t){return b.useSyncExternalStore(u,()=>t?t(s()):s(),()=>t?t(i()):i())}return{set:c,get:s,use:S,subscribe:u}};exports.createStore=l;
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 SetStateAction<Value> = ((prev: Value) => Value) | Value;\ntype StateCreator<Value> = (\n set: (action: SetStateAction<Value>) => void,\n get: () => Value\n) => Value;\n\nexport interface StoreApi<Value> {\n getInitialState: () => Value;\n getState: () => Value;\n setState: (action: SetStateAction<Value>) => void;\n subscribe: (listener: (state: Value, prevState: Value) => void) => () => void;\n}\n\n/**\n * @name createStore\n * @description - Creates a store with state management capabilities\n * @category Helpers\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: StateCreator<Value> | Value) => {\n type Listener = (state: Value, prevState: Value) => void;\n let state: Value;\n const listeners: Set<Listener> = new Set();\n\n const setState = (action: SetStateAction<Value>) => {\n const nextState =\n typeof action === 'function' ? (action as (state: Value) => Value)(state) : action;\n\n if (!Object.is(nextState, state)) {\n const prevState = state;\n state = nextState;\n listeners.forEach((listener) => listener(state, prevState));\n }\n };\n\n const getState = () => state;\n const getInitialState = () => state;\n\n const subscribe = (listener: Listener) => {\n listeners.add(listener);\n return () => listeners.delete(listener);\n };\n if (typeof createState === 'function') {\n state = (createState as StateCreator<Value>)(setState, getState);\n } else {\n state = createState;\n }\n\n const useStore = <Selected>(selector?: (state: Value) => Selected) =>\n useSyncExternalStore(\n subscribe,\n () => (selector ? selector(getState()) : getState()),\n () => (selector ? selector(getInitialState()) : getInitialState())\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","getState","getInitialState","subscribe","selector","useSyncExternalStore"],"mappings":"yGA8BaA,EAAsBC,GAA6C,CAE9E,IAAIC,EACJ,MAAMC,MAA+B,IAE/BC,EAAYC,GAAkC,CAClD,MAAMC,EACJ,OAAOD,GAAW,WAAcA,EAAmCH,CAAK,EAAIG,EAE9E,GAAI,CAAC,OAAO,GAAGC,EAAWJ,CAAK,EAAG,CAChC,MAAMK,EAAYL,EAClBA,EAAQI,EACRH,EAAU,QAASK,GAAaA,EAASN,EAAOK,CAAS,CAAC,CAAA,CAC5D,EAGIE,EAAW,IAAMP,EACjBQ,EAAkB,IAAMR,EAExBS,EAAaH,IACjBL,EAAU,IAAIK,CAAQ,EACf,IAAML,EAAU,OAAOK,CAAQ,GAExC,OAAI,OAAOP,GAAgB,WACzBC,EAASD,EAAoCG,EAAUK,CAAQ,EAE/DP,EAAQD,EAUH,CACL,IAAKG,EACL,IAAKK,EACL,IAV0BG,GAC1BC,EAAAA,qBACEF,EACA,IAAOC,EAAWA,EAASH,EAAA,CAAU,EAAIA,EAAA,EACzC,IAAOG,EAAWA,EAASF,EAAA,CAAiB,EAAIA,EAAA,CAAgB,EAOlE,UAAAC,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 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 *\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\n ? nextState\n : Object.assign({}, state, nextState);\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":"yGAiCaA,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,KAC3CA,EACA,OAAO,OAAO,GAAIJ,EAAOI,CAAS,EAExCH,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,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react"),f=(a,n)=>{const[u,s]=e.useState(!0),[c,r]=e.useState(!1),[i,o]=e.useState(void 0),[d,l]=e.useState(void 0);return e.useEffect(()=>{s(!0),a().then(t=>{l(t),o(void 0),r(!1)}).catch(t=>{o(t),r(!0)}).finally(()=>{s(!1)})},n),{data:d,isLoading:u,isError:c,error:i}};exports.useAsync=f;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react"),f=(a,n=[])=>{const[u,s]=e.useState(!0),[c,r]=e.useState(!1),[i,o]=e.useState(void 0),[d,l]=e.useState(void 0);return e.useEffect(()=>{s(!0),a().then(t=>{l(t),o(void 0),r(!1)}).catch(t=>{o(t),r(!0)}).finally(()=>{s(!1)})},n),{data:d,isLoading:u,isError:c,error:i}};exports.useAsync=f;
2
2
  //# sourceMappingURL=useAsync.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"useAsync.cjs","sources":["../../../../src/hooks/useAsync/useAsync.ts"],"sourcesContent":["import type { DependencyList } from 'react';\n\nimport { useEffect, useState } from 'react';\n\n/* The use query return type */\nexport interface UseAsyncReturn<Data> {\n /* The state of the query */\n data?: Data;\n /* The error of the query */\n error?: Error;\n /* The error state of the query */\n isError: boolean;\n /* The loading state of the query */\n isLoading: boolean;\n}\n\n/**\n * @name useAsync\n * @description - Hook that provides the state of an async callback\n * @category Async\n *\n * @param {() => Promise<Data>} callback The async callback\n * @param {DependencyList} deps The dependencies of the callback\n * @returns {UseAsyncReturn<Data>} The state of the async callback\n *\n * @example\n * const { data, isLoading, isError, error } = useAsync(() => fetch('url'), [deps]);\n */\nexport const useAsync = <Data>(\n callback: () => Promise<Data>,\n deps: DependencyList\n): UseAsyncReturn<Data> => {\n const [isLoading, setIsLoading] = useState(true);\n const [isError, setIsError] = useState(false);\n\n const [error, setError] = useState<Error | undefined>(undefined);\n const [data, setData] = useState<Data | undefined>(undefined);\n\n useEffect(() => {\n setIsLoading(true);\n callback()\n .then((response) => {\n setData(response);\n setError(undefined);\n setIsError(false);\n })\n .catch((error: Error) => {\n setError(error);\n setIsError(true);\n })\n .finally(() => {\n setIsLoading(false);\n });\n }, deps);\n\n return {\n data,\n isLoading,\n isError,\n error\n };\n};\n"],"names":["useAsync","callback","deps","isLoading","setIsLoading","useState","isError","setIsError","error","setError","data","setData","useEffect","response"],"mappings":"yGA4BaA,EAAW,CACtBC,EACAC,IACyB,CACzB,KAAM,CAACC,EAAWC,CAAY,EAAIC,EAAAA,SAAS,EAAI,EACzC,CAACC,EAASC,CAAU,EAAIF,EAAAA,SAAS,EAAK,EAEtC,CAACG,EAAOC,CAAQ,EAAIJ,EAAAA,SAA4B,MAAS,EACzD,CAACK,EAAMC,CAAO,EAAIN,EAAAA,SAA2B,MAAS,EAE5DO,OAAAA,EAAAA,UAAU,IAAM,CACdR,EAAa,EAAI,EACjBH,EAAA,EACG,KAAMY,GAAa,CAClBF,EAAQE,CAAQ,EAChBJ,EAAS,MAAS,EAClBF,EAAW,EAAK,CAAA,CACjB,EACA,MAAOC,GAAiB,CACvBC,EAASD,CAAK,EACdD,EAAW,EAAI,CAAA,CAChB,EACA,QAAQ,IAAM,CACbH,EAAa,EAAK,CAAA,CACnB,CAAA,EACFF,CAAI,EAEA,CACL,KAAAQ,EACA,UAAAP,EACA,QAAAG,EACA,MAAAE,CAAA,CAEJ"}
1
+ {"version":3,"file":"useAsync.cjs","sources":["../../../../src/hooks/useAsync/useAsync.ts"],"sourcesContent":["import type { DependencyList } from 'react';\n\nimport { useEffect, useState } from 'react';\n\n/* The use query return type */\nexport interface UseAsyncReturn<Data> {\n /* The state of the query */\n data?: Data;\n /* The error of the query */\n error?: Error;\n /* The error state of the query */\n isError: boolean;\n /* The loading state of the query */\n isLoading: boolean;\n}\n\n/**\n * @name useAsync\n * @description - Hook that provides the state of an async callback\n * @category Async\n *\n * @param {() => Promise<Data>} callback The async callback\n * @param {DependencyList} [deps=[]] The dependencies of the callback\n * @returns {UseAsyncReturn<Data>} The state of the async callback\n *\n * @example\n * const { data, isLoading, isError, error } = useAsync(() => fetch('url'), [deps]);\n */\nexport const useAsync = <Data>(\n callback: () => Promise<Data>,\n deps: DependencyList = []\n): UseAsyncReturn<Data> => {\n const [isLoading, setIsLoading] = useState(true);\n const [isError, setIsError] = useState(false);\n\n const [error, setError] = useState<Error | undefined>(undefined);\n const [data, setData] = useState<Data | undefined>(undefined);\n\n useEffect(() => {\n setIsLoading(true);\n callback()\n .then((response) => {\n setData(response);\n setError(undefined);\n setIsError(false);\n })\n .catch((error: Error) => {\n setError(error);\n setIsError(true);\n })\n .finally(() => {\n setIsLoading(false);\n });\n }, deps);\n\n return {\n data,\n isLoading,\n isError,\n error\n };\n};\n"],"names":["useAsync","callback","deps","isLoading","setIsLoading","useState","isError","setIsError","error","setError","data","setData","useEffect","response"],"mappings":"yGA4BaA,EAAW,CACtBC,EACAC,EAAuB,KACE,CACzB,KAAM,CAACC,EAAWC,CAAY,EAAIC,EAAAA,SAAS,EAAI,EACzC,CAACC,EAASC,CAAU,EAAIF,EAAAA,SAAS,EAAK,EAEtC,CAACG,EAAOC,CAAQ,EAAIJ,EAAAA,SAA4B,MAAS,EACzD,CAACK,EAAMC,CAAO,EAAIN,EAAAA,SAA2B,MAAS,EAE5DO,OAAAA,EAAAA,UAAU,IAAM,CACdR,EAAa,EAAI,EACjBH,EAAA,EACG,KAAMY,GAAa,CAClBF,EAAQE,CAAQ,EAChBJ,EAAS,MAAS,EAClBF,EAAW,EAAK,CAAA,CACjB,EACA,MAAOC,GAAiB,CACvBC,EAASD,CAAK,EACdD,EAAW,EAAI,CAAA,CAChB,EACA,QAAQ,IAAM,CACbH,EAAa,EAAK,CAAA,CACnB,CAAA,EACFF,CAAI,EAEA,CACL,KAAAQ,EACA,UAAAP,EACA,QAAAG,EACA,MAAAE,CAAA,CAEJ"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("../useQuery/useQuery.cjs"),m=async(s,i={})=>new Promise((r,g)=>{const e=new Image,{srcset:o,sizes:c,class:a,loading:n,crossorigin:l,referrerPolicy:t}=i;e.src=s,o&&(e.srcset=o),c&&(e.sizes=c),a&&(e.className=a),n&&(e.loading=n),l&&(e.crossOrigin=l),t&&(e.referrerPolicy=t),e.onload=()=>r(e),e.onerror=g}),u=(s,i,r={})=>f.useQuery(()=>m(s,i),{keys:[s,...r.keys??[]],...r});exports.useImage=u;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const y=require("../useQuery/useQuery.cjs"),t=async(s,e={})=>new Promise((o,f)=>{const r=new Image,{srcset:c,sizes:a,class:l,loading:i,crossorigin:g,referrerPolicy:n}=e;r.src=s,c&&(r.srcset=c),a&&(r.sizes=a),l&&(r.className=l),i&&(r.loading=i),g&&(r.crossOrigin=g),n&&(r.referrerPolicy=n),r.onload=()=>o(r),r.onerror=f}),u=(s,e)=>y.useQuery(()=>t(s,{alt:e?.alt,class:e?.class,crossorigin:e?.crossorigin,loading:e?.loading,referrerPolicy:e?.referrerPolicy,sizes:e?.sizes,srcset:e?.srcset}),{keys:[s,...e?.keys??[]],onSuccess:e?.onSuccess,onError:e?.onError,refetchInterval:e?.refetchInterval,retry:e?.retry});exports.useImage=u;
2
2
  //# sourceMappingURL=useImage.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"useImage.cjs","sources":["../../../../src/hooks/useImage/useImage.ts"],"sourcesContent":["import type { UseQueryOptions, UseQueryReturn } from '../useQuery/useQuery';\n\nimport { useQuery } from '../useQuery/useQuery';\n\n/** The use image options */\nexport interface UseImageOptions {\n /** The alt of the image */\n alt?: string;\n /** The class of the image */\n class?: string;\n /** The crossorigin of the image */\n crossorigin?: string;\n /** The loading of the image */\n loading?: HTMLImageElement['loading'];\n /** The referrer policy of the image */\n referrerPolicy?: HTMLImageElement['referrerPolicy'];\n /** The sizes of the image */\n sizes?: string;\n /** The srcset of the image */\n srcset?: string;\n}\n\n/** The use image return type */\nexport type UseImageReturn = UseQueryReturn<HTMLImageElement>;\n\nconst loadImage = async (src: string, options: UseImageOptions = {}): Promise<HTMLImageElement> =>\n new Promise((resolve, reject) => {\n const img = new Image();\n const { srcset, sizes, class: className, loading, crossorigin, referrerPolicy } = options;\n\n img.src = src;\n if (srcset) img.srcset = srcset;\n if (sizes) img.sizes = sizes;\n if (className) img.className = className;\n if (loading) img.loading = loading;\n if (crossorigin) img.crossOrigin = crossorigin;\n\n if (referrerPolicy) img.referrerPolicy = referrerPolicy;\n\n img.onload = () => resolve(img);\n img.onerror = reject;\n });\n\n/**\n * @name useImage\n * @description - Hook that load an image in the browser\n * @category Elements\n *\n * @param {string} src The source of the image\n * @param {string} [options.srcset] The srcset of the image\n * @param {string} [options.sizes] The sizes of the image\n * @param {string} [options.alt] The alt of the image\n * @param {string} [options.class] The class of the image\n * @param {HTMLImageElement['loading']} [options.loading] The loading of the image\n * @param {string} [options.crossorigin] The crossorigin of the image\n * @param {HTMLImageElement['referrerPolicy']} [options.referrerPolicy] The referrerPolicy of the image\n * @param {DependencyList} [useQueryOptions.keys] The dependencies for the hook\n * @param {(data: Data) => void} [useQueryOptions.onSuccess] The callback function to be invoked on success\n * @param {(error: Error) => void} [useQueryOptions.onError] The callback function to be invoked on error\n * @param {number} [useQueryOptions.refetchInterval] The refetch interval\n * @param {boolean | number} [useQueryOptions.retry] The retry count of requests\n * @returns {UseImageReturn} An object with the state of the image\n *\n * @example\n * const { data, isLoading, isError, isSuccess, error, refetch, isRefetching } = useImage('https://example.com/image.png');\n */\nexport const useImage = (\n src: string,\n options?: UseImageOptions,\n useQueryOptions: Omit<\n UseQueryOptions<HTMLImageElement, HTMLImageElement>,\n 'initialData' | 'placeholderData' | 'select'\n > = {}\n) =>\n useQuery(() => loadImage(src, options), {\n keys: [src, ...(useQueryOptions.keys ?? [])],\n ...useQueryOptions\n });\n"],"names":["loadImage","src","options","resolve","reject","img","srcset","sizes","className","loading","crossorigin","referrerPolicy","useImage","useQueryOptions","useQuery"],"mappings":"4HAyBMA,EAAY,MAAOC,EAAaC,EAA2B,CAAA,IAC/D,IAAI,QAAQ,CAACC,EAASC,IAAW,CAC/B,MAAMC,EAAM,IAAI,MACV,CAAE,OAAAC,EAAQ,MAAAC,EAAO,MAAOC,EAAW,QAAAC,EAAS,YAAAC,EAAa,eAAAC,GAAmBT,EAElFG,EAAI,IAAMJ,EACNK,MAAY,OAASA,GACrBC,MAAW,MAAQA,GACnBC,MAAe,UAAYA,GAC3BC,MAAa,QAAUA,GACvBC,MAAiB,YAAcA,GAE/BC,MAAoB,eAAiBA,GAEzCN,EAAI,OAAS,IAAMF,EAAQE,CAAG,EAC9BA,EAAI,QAAUD,CAChB,CAAC,EAyBUQ,EAAW,CACtBX,EACAC,EACAW,EAGI,CAAA,IAEJC,EAAAA,SAAS,IAAMd,EAAUC,EAAKC,CAAO,EAAG,CACtC,KAAM,CAACD,EAAK,GAAIY,EAAgB,MAAQ,CAAA,CAAG,EAC3C,GAAGA,CACL,CAAC"}
1
+ {"version":3,"file":"useImage.cjs","sources":["../../../../src/hooks/useImage/useImage.ts"],"sourcesContent":["import type { UseQueryOptions, UseQueryReturn } from '../useQuery/useQuery';\n\nimport { useQuery } from '../useQuery/useQuery';\n\n/** The use image options */\nexport interface UseImageOptions {\n /** The alt of the image */\n alt?: string;\n /** The class of the image */\n class?: string;\n /** The crossorigin of the image */\n crossorigin?: string;\n /** The loading of the image */\n loading?: HTMLImageElement['loading'];\n /** The referrer policy of the image */\n referrerPolicy?: HTMLImageElement['referrerPolicy'];\n /** The sizes of the image */\n sizes?: string;\n /** The srcset of the image */\n srcset?: string;\n}\n\n/** The use image return type */\nexport type UseImageReturn = UseQueryReturn<HTMLImageElement>;\n\nconst loadImage = async (src: string, options: UseImageOptions = {}): Promise<HTMLImageElement> =>\n new Promise((resolve, reject) => {\n const img = new Image();\n const { srcset, sizes, class: className, loading, crossorigin, referrerPolicy } = options;\n\n img.src = src;\n if (srcset) img.srcset = srcset;\n if (sizes) img.sizes = sizes;\n if (className) img.className = className;\n if (loading) img.loading = loading;\n if (crossorigin) img.crossOrigin = crossorigin;\n\n if (referrerPolicy) img.referrerPolicy = referrerPolicy;\n\n img.onload = () => resolve(img);\n img.onerror = reject;\n });\n\n/**\n * @name useImage\n * @description - Hook that load an image in the browser\n * @category Elements\n *\n * @param {string} src The source of the image\n * @param {string} [options.srcset] The srcset of the image\n * @param {string} [options.sizes] The sizes of the image\n * @param {string} [options.alt] The alt of the image\n * @param {string} [options.class] The class of the image\n * @param {HTMLImageElement['loading']} [options.loading] The loading of the image\n * @param {string} [options.crossorigin] The crossorigin of the image\n * @param {HTMLImageElement['referrerPolicy']} [options.referrerPolicy] The referrerPolicy of the image\n * @param {DependencyList} [options.keys] The dependencies for the hook\n * @param {(data: Data) => void} [options.onSuccess] The callback function to be invoked on success\n * @param {(error: Error) => void} [options.onError] The callback function to be invoked on error\n * @param {number} [options.refetchInterval] The refetch interval\n * @param {boolean | number} [options.retry] The retry count of requests\n * @returns {UseImageReturn} An object with the state of the image\n *\n * @example\n * const { data, isLoading, isError, isSuccess, error, refetch, isRefetching } = useImage('https://example.com/image.png');\n */\nexport const useImage = (\n src: string,\n options?: UseImageOptions &\n Omit<\n UseQueryOptions<HTMLImageElement, HTMLImageElement>,\n 'initialData' | 'placeholderData' | 'select'\n >\n) =>\n useQuery(\n () =>\n loadImage(src, {\n alt: options?.alt,\n class: options?.class,\n crossorigin: options?.crossorigin,\n loading: options?.loading,\n referrerPolicy: options?.referrerPolicy,\n sizes: options?.sizes,\n srcset: options?.srcset\n }),\n {\n keys: [src, ...(options?.keys ?? [])],\n onSuccess: options?.onSuccess,\n onError: options?.onError,\n refetchInterval: options?.refetchInterval,\n retry: options?.retry\n }\n );\n"],"names":["loadImage","src","options","resolve","reject","img","srcset","sizes","className","loading","crossorigin","referrerPolicy","useImage","useQuery"],"mappings":"4HAyBMA,EAAY,MAAOC,EAAaC,EAA2B,CAAA,IAC/D,IAAI,QAAQ,CAACC,EAASC,IAAW,CAC/B,MAAMC,EAAM,IAAI,MACV,CAAE,OAAAC,EAAQ,MAAAC,EAAO,MAAOC,EAAW,QAAAC,EAAS,YAAAC,EAAa,eAAAC,GAAmBT,EAElFG,EAAI,IAAMJ,EACNK,MAAY,OAASA,GACrBC,MAAW,MAAQA,GACnBC,MAAe,UAAYA,GAC3BC,MAAa,QAAUA,GACvBC,MAAiB,YAAcA,GAE/BC,MAAoB,eAAiBA,GAEzCN,EAAI,OAAS,IAAMF,EAAQE,CAAG,EAC9BA,EAAI,QAAUD,CAChB,CAAC,EAyBUQ,EAAW,CACtBX,EACAC,IAMAW,EAAAA,SACE,IACEb,EAAUC,EAAK,CACb,IAAKC,GAAS,IACd,MAAOA,GAAS,MAChB,YAAaA,GAAS,YACtB,QAASA,GAAS,QAClB,eAAgBA,GAAS,eACzB,MAAOA,GAAS,MAChB,OAAQA,GAAS,MAAA,CAClB,EACH,CACE,KAAM,CAACD,EAAK,GAAIC,GAAS,MAAQ,CAAA,CAAG,EACpC,UAAWA,GAAS,UACpB,QAASA,GAAS,QAClB,gBAAiBA,GAAS,gBAC1B,MAAOA,GAAS,KAAA,CAEpB"}
@@ -1 +1 @@
1
- {"version":3,"file":"useVirtualKeyboard.cjs","sources":["../../../../src/hooks/useVirtualKeyboard/useVirtualKeyboard.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\ndeclare global {\n interface Navigator {\n virtualKeyboard?: {\n boundingRect: DOMRect;\n overlaysContent: boolean;\n show: () => void;\n hide: () => void;\n addEventListener: (type: 'geometrychange', listener: EventListener) => void;\n removeEventListener: (type: 'geometrychange', listener: EventListener) => void;\n };\n }\n}\n\n/** The use virtual keyboard return type */\nexport interface UseVirtualKeyboardReturn {\n /** Whether the virtual keyboard is currently open */\n opened: boolean;\n /** Whether the VirtualKeyboard API is supported */\n supported: boolean;\n /** Change the overlays content */\n changeOverlaysContent: (overlaysContent: boolean) => void;\n /** Hide the virtual keyboard */\n hide: () => void;\n /** Show the virtual keyboard */\n show: () => void;\n}\n\n/**\n * @name useVirtualKeyboard\n * @description - Hook that manages virtual keyboard state\n * @category Browser\n *\n * @browserapi VirtualKeyboard https://developer.mozilla.org/en-US/docs/Web/API/VirtualKeyboard\n *\n * @warning - This hook has a fallback for virtual keyboard detection. If the virtual keyboard is not supported, the methods will not work.\n *\n * @param {boolean} [initialValue=false] The initial state value for keyboard visibility\n * @returns {UseVirtualKeyboardReturn} An object containing keyboard state and control methods\n *\n * @example\n * const { opened, show, hide, supported, changeOverlaysContent } = useVirtualKeyboard();\n */\nexport const useVirtualKeyboard = (initialValue = false): UseVirtualKeyboardReturn => {\n const supported =\n (typeof window !== 'undefined' && 'visualViewport' in window) ||\n (typeof navigator !== 'undefined' && 'virtualKeyboard' in navigator);\n\n const [opened, setOpened] = useState(initialValue);\n\n const hide = () => {\n if (!navigator.virtualKeyboard) return;\n navigator.virtualKeyboard.hide();\n setOpened(false);\n };\n\n const show = () => {\n if (!navigator.virtualKeyboard) return;\n navigator.virtualKeyboard.show();\n setOpened(true);\n };\n\n const changeOverlaysContent = (overlaysContent: boolean) => {\n if (!navigator.virtualKeyboard) return;\n navigator.virtualKeyboard.overlaysContent = overlaysContent;\n };\n\n useEffect(() => {\n if (!supported) return;\n\n const onResize = () => setOpened(window.screen.height - 300 > window.visualViewport!.height);\n\n const onGeometryChange = (event: Event) => {\n const { height } = (event.target as any).boundingRect as DOMRect;\n setOpened(height > 0);\n };\n\n navigator.virtualKeyboard &&\n navigator.virtualKeyboard.addEventListener('geometrychange', onGeometryChange);\n window.visualViewport && window.visualViewport.addEventListener('resize', onResize);\n\n return () => {\n navigator.virtualKeyboard &&\n navigator.virtualKeyboard.removeEventListener('geometrychange', onGeometryChange);\n window.visualViewport && window.visualViewport.removeEventListener('resize', onResize);\n };\n }, []);\n\n return {\n opened,\n show,\n hide,\n changeOverlaysContent,\n supported\n };\n};\n"],"names":["useVirtualKeyboard","initialValue","supported","opened","setOpened","useState","hide","show","changeOverlaysContent","overlaysContent","useEffect","onResize","onGeometryChange","event","height"],"mappings":"yGA4CaA,EAAqB,CAACC,EAAe,KAAoC,CACpF,MAAMC,EACH,OAAO,OAAW,KAAe,mBAAoB,QACrD,OAAO,UAAc,KAAe,oBAAqB,UAEtD,CAACC,EAAQC,CAAS,EAAIC,EAAAA,SAASJ,CAAY,EAE3CK,EAAO,IAAM,CACZ,UAAU,kBACf,UAAU,gBAAgB,KAAA,EAC1BF,EAAU,EAAK,EAAA,EAGXG,EAAO,IAAM,CACZ,UAAU,kBACf,UAAU,gBAAgB,KAAA,EAC1BH,EAAU,EAAI,EAAA,EAGVI,EAAyBC,GAA6B,CACrD,UAAU,kBACf,UAAU,gBAAgB,gBAAkBA,EAAA,EAG9CC,OAAAA,EAAAA,UAAU,IAAM,CACd,GAAI,CAACR,EAAW,OAEhB,MAAMS,EAAW,IAAMP,EAAU,OAAO,OAAO,OAAS,IAAM,OAAO,eAAgB,MAAM,EAErFQ,EAAoBC,GAAiB,CACzC,KAAM,CAAE,OAAAC,CAAA,EAAYD,EAAM,OAAe,aACzCT,EAAUU,EAAS,CAAC,CAAA,EAGtB,iBAAU,iBACR,UAAU,gBAAgB,iBAAiB,iBAAkBF,CAAgB,EAC/E,OAAO,gBAAkB,OAAO,eAAe,iBAAiB,SAAUD,CAAQ,EAE3E,IAAM,CACX,UAAU,iBACR,UAAU,gBAAgB,oBAAoB,iBAAkBC,CAAgB,EAClF,OAAO,gBAAkB,OAAO,eAAe,oBAAoB,SAAUD,CAAQ,CAAA,CACvF,EACC,EAAE,EAEE,CACL,OAAAR,EACA,KAAAI,EACA,KAAAD,EACA,sBAAAE,EACA,UAAAN,CAAA,CAEJ"}
1
+ {"version":3,"file":"useVirtualKeyboard.cjs","sources":["../../../../src/hooks/useVirtualKeyboard/useVirtualKeyboard.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\r\n\r\ndeclare global {\r\n interface Navigator {\r\n virtualKeyboard?: {\r\n boundingRect: DOMRect;\r\n overlaysContent: boolean;\r\n show: () => void;\r\n hide: () => void;\r\n addEventListener: (type: 'geometrychange', listener: EventListener) => void;\r\n removeEventListener: (type: 'geometrychange', listener: EventListener) => void;\r\n };\r\n }\r\n}\r\n\r\n/** The use virtual keyboard return type */\r\nexport interface UseVirtualKeyboardReturn {\r\n /** Whether the virtual keyboard is currently open */\r\n opened: boolean;\r\n /** Whether the VirtualKeyboard API is supported */\r\n supported: boolean;\r\n /** Change the overlays content */\r\n changeOverlaysContent: (overlaysContent: boolean) => void;\r\n /** Hide the virtual keyboard */\r\n hide: () => void;\r\n /** Show the virtual keyboard */\r\n show: () => void;\r\n}\r\n\r\n/**\r\n * @name useVirtualKeyboard\r\n * @description - Hook that manages virtual keyboard state\r\n * @category Browser\r\n *\r\n * @browserapi VirtualKeyboard https://developer.mozilla.org/en-US/docs/Web/API/VirtualKeyboard\r\n *\r\n * @warning - This hook has a fallback for virtual keyboard detection. If the virtual keyboard is not supported, the methods will not work.\r\n *\r\n * @param {boolean} [initialValue=false] The initial state value for keyboard visibility\r\n * @returns {UseVirtualKeyboardReturn} An object containing keyboard state and control methods\r\n *\r\n * @example\r\n * const { opened, show, hide, supported, changeOverlaysContent } = useVirtualKeyboard();\r\n */\r\nexport const useVirtualKeyboard = (initialValue = false): UseVirtualKeyboardReturn => {\r\n const supported =\r\n (typeof window !== 'undefined' && 'visualViewport' in window) ||\r\n (typeof navigator !== 'undefined' && 'virtualKeyboard' in navigator);\r\n\r\n const [opened, setOpened] = useState(initialValue);\r\n\r\n const hide = () => {\r\n if (!navigator.virtualKeyboard) return;\r\n navigator.virtualKeyboard.hide();\r\n setOpened(false);\r\n };\r\n\r\n const show = () => {\r\n if (!navigator.virtualKeyboard) return;\r\n navigator.virtualKeyboard.show();\r\n setOpened(true);\r\n };\r\n\r\n const changeOverlaysContent = (overlaysContent: boolean) => {\r\n if (!navigator.virtualKeyboard) return;\r\n navigator.virtualKeyboard.overlaysContent = overlaysContent;\r\n };\r\n\r\n useEffect(() => {\r\n if (!supported) return;\r\n\r\n const onResize = () => setOpened(window.screen.height - 300 > window.visualViewport!.height);\r\n\r\n const onGeometryChange = (event: Event) => {\r\n const { height } = (event.target as any).boundingRect as DOMRect;\r\n setOpened(height > 0);\r\n };\r\n\r\n navigator.virtualKeyboard &&\r\n navigator.virtualKeyboard.addEventListener('geometrychange', onGeometryChange);\r\n window.visualViewport && window.visualViewport.addEventListener('resize', onResize);\r\n\r\n return () => {\r\n navigator.virtualKeyboard &&\r\n navigator.virtualKeyboard.removeEventListener('geometrychange', onGeometryChange);\r\n window.visualViewport && window.visualViewport.removeEventListener('resize', onResize);\r\n };\r\n }, []);\r\n\r\n return {\r\n opened,\r\n show,\r\n hide,\r\n changeOverlaysContent,\r\n supported\r\n };\r\n};\r\n"],"names":["useVirtualKeyboard","initialValue","supported","opened","setOpened","useState","hide","show","changeOverlaysContent","overlaysContent","useEffect","onResize","onGeometryChange","event","height"],"mappings":"yGA4CaA,EAAqB,CAACC,EAAe,KAAoC,CACpF,MAAMC,EACH,OAAO,OAAW,KAAe,mBAAoB,QACrD,OAAO,UAAc,KAAe,oBAAqB,UAEtD,CAACC,EAAQC,CAAS,EAAIC,EAAAA,SAASJ,CAAY,EAE3CK,EAAO,IAAM,CACZ,UAAU,kBACf,UAAU,gBAAgB,KAAA,EAC1BF,EAAU,EAAK,EAAA,EAGXG,EAAO,IAAM,CACZ,UAAU,kBACf,UAAU,gBAAgB,KAAA,EAC1BH,EAAU,EAAI,EAAA,EAGVI,EAAyBC,GAA6B,CACrD,UAAU,kBACf,UAAU,gBAAgB,gBAAkBA,EAAA,EAG9CC,OAAAA,EAAAA,UAAU,IAAM,CACd,GAAI,CAACR,EAAW,OAEhB,MAAMS,EAAW,IAAMP,EAAU,OAAO,OAAO,OAAS,IAAM,OAAO,eAAgB,MAAM,EAErFQ,EAAoBC,GAAiB,CACzC,KAAM,CAAE,OAAAC,CAAA,EAAYD,EAAM,OAAe,aACzCT,EAAUU,EAAS,CAAC,CAAA,EAGtB,iBAAU,iBACR,UAAU,gBAAgB,iBAAiB,iBAAkBF,CAAgB,EAC/E,OAAO,gBAAkB,OAAO,eAAe,iBAAiB,SAAUD,CAAQ,EAE3E,IAAM,CACX,UAAU,iBACR,UAAU,gBAAgB,oBAAoB,iBAAkBC,CAAgB,EAClF,OAAO,gBAAkB,OAAO,eAAe,oBAAoB,SAAUD,CAAQ,CAAA,CACvF,EACC,EAAE,EAEE,CACL,OAAAR,EACA,KAAAI,EACA,KAAAD,EACA,sBAAAE,EACA,UAAAN,CAAA,CAEJ"}
@@ -1,25 +1,29 @@
1
- import { useSyncExternalStore as a } from "react";
2
- const d = (s) => {
1
+ import { useSyncExternalStore as p } from "react";
2
+ const g = (o) => {
3
3
  let e;
4
- const o = /* @__PURE__ */ new Set(), r = (t) => {
5
- const S = typeof t == "function" ? t(e) : t;
6
- if (!Object.is(S, e)) {
7
- const f = e;
8
- e = S, o.forEach((i) => i(e, f));
4
+ const r = /* @__PURE__ */ new Set(), c = (t) => {
5
+ const n = typeof t == "function" ? t(e) : t;
6
+ if (!Object.is(n, e)) {
7
+ const S = e;
8
+ e = typeof n != "object" || n === null ? n : Object.assign({}, e, n), r.forEach((a) => a(e, S));
9
9
  }
10
- }, n = () => e, c = () => e, u = (t) => (o.add(t), () => o.delete(t));
11
- return typeof s == "function" ? e = s(r, n) : e = s, {
12
- set: r,
13
- get: n,
14
- use: (t) => a(
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) {
13
+ return p(
15
14
  u,
16
- () => t ? t(n()) : n(),
17
- () => t ? t(c()) : c()
18
- ),
15
+ () => t ? t(s()) : s(),
16
+ () => t ? t(f()) : f()
17
+ );
18
+ }
19
+ return {
20
+ set: c,
21
+ get: s,
22
+ use: i,
19
23
  subscribe: u
20
24
  };
21
25
  };
22
26
  export {
23
- d as createStore
27
+ g as createStore
24
28
  };
25
29
  //# sourceMappingURL=createStore.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"createStore.mjs","sources":["../../../../src/helpers/createStore/createStore.ts"],"sourcesContent":["import { useSyncExternalStore } from 'react';\n\ntype SetStateAction<Value> = ((prev: Value) => Value) | Value;\ntype StateCreator<Value> = (\n set: (action: SetStateAction<Value>) => void,\n get: () => Value\n) => Value;\n\nexport interface StoreApi<Value> {\n getInitialState: () => Value;\n getState: () => Value;\n setState: (action: SetStateAction<Value>) => void;\n subscribe: (listener: (state: Value, prevState: Value) => void) => () => void;\n}\n\n/**\n * @name createStore\n * @description - Creates a store with state management capabilities\n * @category Helpers\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: StateCreator<Value> | Value) => {\n type Listener = (state: Value, prevState: Value) => void;\n let state: Value;\n const listeners: Set<Listener> = new Set();\n\n const setState = (action: SetStateAction<Value>) => {\n const nextState =\n typeof action === 'function' ? (action as (state: Value) => Value)(state) : action;\n\n if (!Object.is(nextState, state)) {\n const prevState = state;\n state = nextState;\n listeners.forEach((listener) => listener(state, prevState));\n }\n };\n\n const getState = () => state;\n const getInitialState = () => state;\n\n const subscribe = (listener: Listener) => {\n listeners.add(listener);\n return () => listeners.delete(listener);\n };\n if (typeof createState === 'function') {\n state = (createState as StateCreator<Value>)(setState, getState);\n } else {\n state = createState;\n }\n\n const useStore = <Selected>(selector?: (state: Value) => Selected) =>\n useSyncExternalStore(\n subscribe,\n () => (selector ? selector(getState()) : getState()),\n () => (selector ? selector(getInitialState()) : getInitialState())\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","getState","getInitialState","subscribe","selector","useSyncExternalStore"],"mappings":";AA8BO,MAAMA,IAAc,CAAQC,MAA6C;AAE9E,MAAIC;AACJ,QAAMC,wBAA+B,IAAA,GAE/BC,IAAW,CAACC,MAAkC;AAClD,UAAMC,IACJ,OAAOD,KAAW,aAAcA,EAAmCH,CAAK,IAAIG;AAE9E,QAAI,CAAC,OAAO,GAAGC,GAAWJ,CAAK,GAAG;AAChC,YAAMK,IAAYL;AAClB,MAAAA,IAAQI,GACRH,EAAU,QAAQ,CAACK,MAAaA,EAASN,GAAOK,CAAS,CAAC;AAAA,IAAA;AAAA,EAC5D,GAGIE,IAAW,MAAMP,GACjBQ,IAAkB,MAAMR,GAExBS,IAAY,CAACH,OACjBL,EAAU,IAAIK,CAAQ,GACf,MAAML,EAAU,OAAOK,CAAQ;AAExC,SAAI,OAAOP,KAAgB,aACzBC,IAASD,EAAoCG,GAAUK,CAAQ,IAE/DP,IAAQD,GAUH;AAAA,IACL,KAAKG;AAAA,IACL,KAAKK;AAAA,IACL,KAVe,CAAWG,MAC1BC;AAAA,MACEF;AAAA,MACA,MAAOC,IAAWA,EAASH,EAAA,CAAU,IAAIA,EAAA;AAAA,MACzC,MAAOG,IAAWA,EAASF,EAAA,CAAiB,IAAIA,EAAA;AAAA,IAAgB;AAAA,IAOlE,WAAAC;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 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 *\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\n ? nextState\n : Object.assign({}, state, nextState);\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":";AAiCO,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,OAC3CA,IACA,OAAO,OAAO,IAAIJ,GAAOI,CAAS,GAExCH,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,5 +1,5 @@
1
1
  import { useState as t, useEffect as l } from "react";
2
- const v = (a, n) => {
2
+ const v = (a, n = []) => {
3
3
  const [c, s] = t(!0), [i, e] = t(!1), [f, o] = t(void 0), [u, d] = t(void 0);
4
4
  return l(() => {
5
5
  s(!0), a().then((r) => {
@@ -1 +1 @@
1
- {"version":3,"file":"useAsync.mjs","sources":["../../../../src/hooks/useAsync/useAsync.ts"],"sourcesContent":["import type { DependencyList } from 'react';\n\nimport { useEffect, useState } from 'react';\n\n/* The use query return type */\nexport interface UseAsyncReturn<Data> {\n /* The state of the query */\n data?: Data;\n /* The error of the query */\n error?: Error;\n /* The error state of the query */\n isError: boolean;\n /* The loading state of the query */\n isLoading: boolean;\n}\n\n/**\n * @name useAsync\n * @description - Hook that provides the state of an async callback\n * @category Async\n *\n * @param {() => Promise<Data>} callback The async callback\n * @param {DependencyList} deps The dependencies of the callback\n * @returns {UseAsyncReturn<Data>} The state of the async callback\n *\n * @example\n * const { data, isLoading, isError, error } = useAsync(() => fetch('url'), [deps]);\n */\nexport const useAsync = <Data>(\n callback: () => Promise<Data>,\n deps: DependencyList\n): UseAsyncReturn<Data> => {\n const [isLoading, setIsLoading] = useState(true);\n const [isError, setIsError] = useState(false);\n\n const [error, setError] = useState<Error | undefined>(undefined);\n const [data, setData] = useState<Data | undefined>(undefined);\n\n useEffect(() => {\n setIsLoading(true);\n callback()\n .then((response) => {\n setData(response);\n setError(undefined);\n setIsError(false);\n })\n .catch((error: Error) => {\n setError(error);\n setIsError(true);\n })\n .finally(() => {\n setIsLoading(false);\n });\n }, deps);\n\n return {\n data,\n isLoading,\n isError,\n error\n };\n};\n"],"names":["useAsync","callback","deps","isLoading","setIsLoading","useState","isError","setIsError","error","setError","data","setData","useEffect","response"],"mappings":";AA4BO,MAAMA,IAAW,CACtBC,GACAC,MACyB;AACzB,QAAM,CAACC,GAAWC,CAAY,IAAIC,EAAS,EAAI,GACzC,CAACC,GAASC,CAAU,IAAIF,EAAS,EAAK,GAEtC,CAACG,GAAOC,CAAQ,IAAIJ,EAA4B,MAAS,GACzD,CAACK,GAAMC,CAAO,IAAIN,EAA2B,MAAS;AAE5D,SAAAO,EAAU,MAAM;AACd,IAAAR,EAAa,EAAI,GACjBH,EAAA,EACG,KAAK,CAACY,MAAa;AAClB,MAAAF,EAAQE,CAAQ,GAChBJ,EAAS,MAAS,GAClBF,EAAW,EAAK;AAAA,IAAA,CACjB,EACA,MAAM,CAACC,MAAiB;AACvB,MAAAC,EAASD,CAAK,GACdD,EAAW,EAAI;AAAA,IAAA,CAChB,EACA,QAAQ,MAAM;AACb,MAAAH,EAAa,EAAK;AAAA,IAAA,CACnB;AAAA,EAAA,GACFF,CAAI,GAEA;AAAA,IACL,MAAAQ;AAAA,IACA,WAAAP;AAAA,IACA,SAAAG;AAAA,IACA,OAAAE;AAAA,EAAA;AAEJ;"}
1
+ {"version":3,"file":"useAsync.mjs","sources":["../../../../src/hooks/useAsync/useAsync.ts"],"sourcesContent":["import type { DependencyList } from 'react';\n\nimport { useEffect, useState } from 'react';\n\n/* The use query return type */\nexport interface UseAsyncReturn<Data> {\n /* The state of the query */\n data?: Data;\n /* The error of the query */\n error?: Error;\n /* The error state of the query */\n isError: boolean;\n /* The loading state of the query */\n isLoading: boolean;\n}\n\n/**\n * @name useAsync\n * @description - Hook that provides the state of an async callback\n * @category Async\n *\n * @param {() => Promise<Data>} callback The async callback\n * @param {DependencyList} [deps=[]] The dependencies of the callback\n * @returns {UseAsyncReturn<Data>} The state of the async callback\n *\n * @example\n * const { data, isLoading, isError, error } = useAsync(() => fetch('url'), [deps]);\n */\nexport const useAsync = <Data>(\n callback: () => Promise<Data>,\n deps: DependencyList = []\n): UseAsyncReturn<Data> => {\n const [isLoading, setIsLoading] = useState(true);\n const [isError, setIsError] = useState(false);\n\n const [error, setError] = useState<Error | undefined>(undefined);\n const [data, setData] = useState<Data | undefined>(undefined);\n\n useEffect(() => {\n setIsLoading(true);\n callback()\n .then((response) => {\n setData(response);\n setError(undefined);\n setIsError(false);\n })\n .catch((error: Error) => {\n setError(error);\n setIsError(true);\n })\n .finally(() => {\n setIsLoading(false);\n });\n }, deps);\n\n return {\n data,\n isLoading,\n isError,\n error\n };\n};\n"],"names":["useAsync","callback","deps","isLoading","setIsLoading","useState","isError","setIsError","error","setError","data","setData","useEffect","response"],"mappings":";AA4BO,MAAMA,IAAW,CACtBC,GACAC,IAAuB,OACE;AACzB,QAAM,CAACC,GAAWC,CAAY,IAAIC,EAAS,EAAI,GACzC,CAACC,GAASC,CAAU,IAAIF,EAAS,EAAK,GAEtC,CAACG,GAAOC,CAAQ,IAAIJ,EAA4B,MAAS,GACzD,CAACK,GAAMC,CAAO,IAAIN,EAA2B,MAAS;AAE5D,SAAAO,EAAU,MAAM;AACd,IAAAR,EAAa,EAAI,GACjBH,EAAA,EACG,KAAK,CAACY,MAAa;AAClB,MAAAF,EAAQE,CAAQ,GAChBJ,EAAS,MAAS,GAClBF,EAAW,EAAK;AAAA,IAAA,CACjB,EACA,MAAM,CAACC,MAAiB;AACvB,MAAAC,EAASD,CAAK,GACdD,EAAW,EAAI;AAAA,IAAA,CAChB,EACA,QAAQ,MAAM;AACb,MAAAH,EAAa,EAAK;AAAA,IAAA,CACnB;AAAA,EAAA,GACFF,CAAI,GAEA;AAAA,IACL,MAAAQ;AAAA,IACA,WAAAP;AAAA,IACA,SAAAG;AAAA,IACA,OAAAE;AAAA,EAAA;AAEJ;"}
@@ -1,11 +1,25 @@
1
- import { useQuery as g } from "../useQuery/useQuery.mjs";
2
- const t = async (e, o = {}) => new Promise((r, m) => {
3
- const s = new Image(), { srcset: i, sizes: c, class: a, loading: n, crossorigin: f, referrerPolicy: l } = o;
4
- s.src = e, i && (s.srcset = i), c && (s.sizes = c), a && (s.className = a), n && (s.loading = n), f && (s.crossOrigin = f), l && (s.referrerPolicy = l), s.onload = () => r(s), s.onerror = m;
5
- }), d = (e, o, r = {}) => g(() => t(e, o), {
6
- keys: [e, ...r.keys ?? []],
7
- ...r
8
- });
1
+ import { useQuery as y } from "../useQuery/useQuery.mjs";
2
+ const m = async (s, r = {}) => new Promise((n, o) => {
3
+ const e = new Image(), { srcset: c, sizes: a, class: l, loading: i, crossorigin: f, referrerPolicy: g } = r;
4
+ e.src = s, c && (e.srcset = c), a && (e.sizes = a), l && (e.className = l), i && (e.loading = i), f && (e.crossOrigin = f), g && (e.referrerPolicy = g), e.onload = () => n(e), e.onerror = o;
5
+ }), d = (s, r) => y(
6
+ () => m(s, {
7
+ alt: r?.alt,
8
+ class: r?.class,
9
+ crossorigin: r?.crossorigin,
10
+ loading: r?.loading,
11
+ referrerPolicy: r?.referrerPolicy,
12
+ sizes: r?.sizes,
13
+ srcset: r?.srcset
14
+ }),
15
+ {
16
+ keys: [s, ...r?.keys ?? []],
17
+ onSuccess: r?.onSuccess,
18
+ onError: r?.onError,
19
+ refetchInterval: r?.refetchInterval,
20
+ retry: r?.retry
21
+ }
22
+ );
9
23
  export {
10
24
  d as useImage
11
25
  };
@@ -1 +1 @@
1
- {"version":3,"file":"useImage.mjs","sources":["../../../../src/hooks/useImage/useImage.ts"],"sourcesContent":["import type { UseQueryOptions, UseQueryReturn } from '../useQuery/useQuery';\n\nimport { useQuery } from '../useQuery/useQuery';\n\n/** The use image options */\nexport interface UseImageOptions {\n /** The alt of the image */\n alt?: string;\n /** The class of the image */\n class?: string;\n /** The crossorigin of the image */\n crossorigin?: string;\n /** The loading of the image */\n loading?: HTMLImageElement['loading'];\n /** The referrer policy of the image */\n referrerPolicy?: HTMLImageElement['referrerPolicy'];\n /** The sizes of the image */\n sizes?: string;\n /** The srcset of the image */\n srcset?: string;\n}\n\n/** The use image return type */\nexport type UseImageReturn = UseQueryReturn<HTMLImageElement>;\n\nconst loadImage = async (src: string, options: UseImageOptions = {}): Promise<HTMLImageElement> =>\n new Promise((resolve, reject) => {\n const img = new Image();\n const { srcset, sizes, class: className, loading, crossorigin, referrerPolicy } = options;\n\n img.src = src;\n if (srcset) img.srcset = srcset;\n if (sizes) img.sizes = sizes;\n if (className) img.className = className;\n if (loading) img.loading = loading;\n if (crossorigin) img.crossOrigin = crossorigin;\n\n if (referrerPolicy) img.referrerPolicy = referrerPolicy;\n\n img.onload = () => resolve(img);\n img.onerror = reject;\n });\n\n/**\n * @name useImage\n * @description - Hook that load an image in the browser\n * @category Elements\n *\n * @param {string} src The source of the image\n * @param {string} [options.srcset] The srcset of the image\n * @param {string} [options.sizes] The sizes of the image\n * @param {string} [options.alt] The alt of the image\n * @param {string} [options.class] The class of the image\n * @param {HTMLImageElement['loading']} [options.loading] The loading of the image\n * @param {string} [options.crossorigin] The crossorigin of the image\n * @param {HTMLImageElement['referrerPolicy']} [options.referrerPolicy] The referrerPolicy of the image\n * @param {DependencyList} [useQueryOptions.keys] The dependencies for the hook\n * @param {(data: Data) => void} [useQueryOptions.onSuccess] The callback function to be invoked on success\n * @param {(error: Error) => void} [useQueryOptions.onError] The callback function to be invoked on error\n * @param {number} [useQueryOptions.refetchInterval] The refetch interval\n * @param {boolean | number} [useQueryOptions.retry] The retry count of requests\n * @returns {UseImageReturn} An object with the state of the image\n *\n * @example\n * const { data, isLoading, isError, isSuccess, error, refetch, isRefetching } = useImage('https://example.com/image.png');\n */\nexport const useImage = (\n src: string,\n options?: UseImageOptions,\n useQueryOptions: Omit<\n UseQueryOptions<HTMLImageElement, HTMLImageElement>,\n 'initialData' | 'placeholderData' | 'select'\n > = {}\n) =>\n useQuery(() => loadImage(src, options), {\n keys: [src, ...(useQueryOptions.keys ?? [])],\n ...useQueryOptions\n });\n"],"names":["loadImage","src","options","resolve","reject","img","srcset","sizes","className","loading","crossorigin","referrerPolicy","useImage","useQueryOptions","useQuery"],"mappings":";AAyBA,MAAMA,IAAY,OAAOC,GAAaC,IAA2B,CAAA,MAC/D,IAAI,QAAQ,CAACC,GAASC,MAAW;AAC/B,QAAMC,IAAM,IAAI,MAAA,GACV,EAAE,QAAAC,GAAQ,OAAAC,GAAO,OAAOC,GAAW,SAAAC,GAAS,aAAAC,GAAa,gBAAAC,MAAmBT;AAElF,EAAAG,EAAI,MAAMJ,GACNK,QAAY,SAASA,IACrBC,QAAW,QAAQA,IACnBC,QAAe,YAAYA,IAC3BC,QAAa,UAAUA,IACvBC,QAAiB,cAAcA,IAE/BC,QAAoB,iBAAiBA,IAEzCN,EAAI,SAAS,MAAMF,EAAQE,CAAG,GAC9BA,EAAI,UAAUD;AAChB,CAAC,GAyBUQ,IAAW,CACtBX,GACAC,GACAW,IAGI,CAAA,MAEJC,EAAS,MAAMd,EAAUC,GAAKC,CAAO,GAAG;AAAA,EACtC,MAAM,CAACD,GAAK,GAAIY,EAAgB,QAAQ,CAAA,CAAG;AAAA,EAC3C,GAAGA;AACL,CAAC;"}
1
+ {"version":3,"file":"useImage.mjs","sources":["../../../../src/hooks/useImage/useImage.ts"],"sourcesContent":["import type { UseQueryOptions, UseQueryReturn } from '../useQuery/useQuery';\n\nimport { useQuery } from '../useQuery/useQuery';\n\n/** The use image options */\nexport interface UseImageOptions {\n /** The alt of the image */\n alt?: string;\n /** The class of the image */\n class?: string;\n /** The crossorigin of the image */\n crossorigin?: string;\n /** The loading of the image */\n loading?: HTMLImageElement['loading'];\n /** The referrer policy of the image */\n referrerPolicy?: HTMLImageElement['referrerPolicy'];\n /** The sizes of the image */\n sizes?: string;\n /** The srcset of the image */\n srcset?: string;\n}\n\n/** The use image return type */\nexport type UseImageReturn = UseQueryReturn<HTMLImageElement>;\n\nconst loadImage = async (src: string, options: UseImageOptions = {}): Promise<HTMLImageElement> =>\n new Promise((resolve, reject) => {\n const img = new Image();\n const { srcset, sizes, class: className, loading, crossorigin, referrerPolicy } = options;\n\n img.src = src;\n if (srcset) img.srcset = srcset;\n if (sizes) img.sizes = sizes;\n if (className) img.className = className;\n if (loading) img.loading = loading;\n if (crossorigin) img.crossOrigin = crossorigin;\n\n if (referrerPolicy) img.referrerPolicy = referrerPolicy;\n\n img.onload = () => resolve(img);\n img.onerror = reject;\n });\n\n/**\n * @name useImage\n * @description - Hook that load an image in the browser\n * @category Elements\n *\n * @param {string} src The source of the image\n * @param {string} [options.srcset] The srcset of the image\n * @param {string} [options.sizes] The sizes of the image\n * @param {string} [options.alt] The alt of the image\n * @param {string} [options.class] The class of the image\n * @param {HTMLImageElement['loading']} [options.loading] The loading of the image\n * @param {string} [options.crossorigin] The crossorigin of the image\n * @param {HTMLImageElement['referrerPolicy']} [options.referrerPolicy] The referrerPolicy of the image\n * @param {DependencyList} [options.keys] The dependencies for the hook\n * @param {(data: Data) => void} [options.onSuccess] The callback function to be invoked on success\n * @param {(error: Error) => void} [options.onError] The callback function to be invoked on error\n * @param {number} [options.refetchInterval] The refetch interval\n * @param {boolean | number} [options.retry] The retry count of requests\n * @returns {UseImageReturn} An object with the state of the image\n *\n * @example\n * const { data, isLoading, isError, isSuccess, error, refetch, isRefetching } = useImage('https://example.com/image.png');\n */\nexport const useImage = (\n src: string,\n options?: UseImageOptions &\n Omit<\n UseQueryOptions<HTMLImageElement, HTMLImageElement>,\n 'initialData' | 'placeholderData' | 'select'\n >\n) =>\n useQuery(\n () =>\n loadImage(src, {\n alt: options?.alt,\n class: options?.class,\n crossorigin: options?.crossorigin,\n loading: options?.loading,\n referrerPolicy: options?.referrerPolicy,\n sizes: options?.sizes,\n srcset: options?.srcset\n }),\n {\n keys: [src, ...(options?.keys ?? [])],\n onSuccess: options?.onSuccess,\n onError: options?.onError,\n refetchInterval: options?.refetchInterval,\n retry: options?.retry\n }\n );\n"],"names":["loadImage","src","options","resolve","reject","img","srcset","sizes","className","loading","crossorigin","referrerPolicy","useImage","useQuery"],"mappings":";AAyBA,MAAMA,IAAY,OAAOC,GAAaC,IAA2B,CAAA,MAC/D,IAAI,QAAQ,CAACC,GAASC,MAAW;AAC/B,QAAMC,IAAM,IAAI,MAAA,GACV,EAAE,QAAAC,GAAQ,OAAAC,GAAO,OAAOC,GAAW,SAAAC,GAAS,aAAAC,GAAa,gBAAAC,MAAmBT;AAElF,EAAAG,EAAI,MAAMJ,GACNK,QAAY,SAASA,IACrBC,QAAW,QAAQA,IACnBC,QAAe,YAAYA,IAC3BC,QAAa,UAAUA,IACvBC,QAAiB,cAAcA,IAE/BC,QAAoB,iBAAiBA,IAEzCN,EAAI,SAAS,MAAMF,EAAQE,CAAG,GAC9BA,EAAI,UAAUD;AAChB,CAAC,GAyBUQ,IAAW,CACtBX,GACAC,MAMAW;AAAA,EACE,MACEb,EAAUC,GAAK;AAAA,IACb,KAAKC,GAAS;AAAA,IACd,OAAOA,GAAS;AAAA,IAChB,aAAaA,GAAS;AAAA,IACtB,SAASA,GAAS;AAAA,IAClB,gBAAgBA,GAAS;AAAA,IACzB,OAAOA,GAAS;AAAA,IAChB,QAAQA,GAAS;AAAA,EAAA,CAClB;AAAA,EACH;AAAA,IACE,MAAM,CAACD,GAAK,GAAIC,GAAS,QAAQ,CAAA,CAAG;AAAA,IACpC,WAAWA,GAAS;AAAA,IACpB,SAASA,GAAS;AAAA,IAClB,iBAAiBA,GAAS;AAAA,IAC1B,OAAOA,GAAS;AAAA,EAAA;AAEpB;"}
@@ -1 +1 @@
1
- {"version":3,"file":"useVirtualKeyboard.mjs","sources":["../../../../src/hooks/useVirtualKeyboard/useVirtualKeyboard.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\ndeclare global {\n interface Navigator {\n virtualKeyboard?: {\n boundingRect: DOMRect;\n overlaysContent: boolean;\n show: () => void;\n hide: () => void;\n addEventListener: (type: 'geometrychange', listener: EventListener) => void;\n removeEventListener: (type: 'geometrychange', listener: EventListener) => void;\n };\n }\n}\n\n/** The use virtual keyboard return type */\nexport interface UseVirtualKeyboardReturn {\n /** Whether the virtual keyboard is currently open */\n opened: boolean;\n /** Whether the VirtualKeyboard API is supported */\n supported: boolean;\n /** Change the overlays content */\n changeOverlaysContent: (overlaysContent: boolean) => void;\n /** Hide the virtual keyboard */\n hide: () => void;\n /** Show the virtual keyboard */\n show: () => void;\n}\n\n/**\n * @name useVirtualKeyboard\n * @description - Hook that manages virtual keyboard state\n * @category Browser\n *\n * @browserapi VirtualKeyboard https://developer.mozilla.org/en-US/docs/Web/API/VirtualKeyboard\n *\n * @warning - This hook has a fallback for virtual keyboard detection. If the virtual keyboard is not supported, the methods will not work.\n *\n * @param {boolean} [initialValue=false] The initial state value for keyboard visibility\n * @returns {UseVirtualKeyboardReturn} An object containing keyboard state and control methods\n *\n * @example\n * const { opened, show, hide, supported, changeOverlaysContent } = useVirtualKeyboard();\n */\nexport const useVirtualKeyboard = (initialValue = false): UseVirtualKeyboardReturn => {\n const supported =\n (typeof window !== 'undefined' && 'visualViewport' in window) ||\n (typeof navigator !== 'undefined' && 'virtualKeyboard' in navigator);\n\n const [opened, setOpened] = useState(initialValue);\n\n const hide = () => {\n if (!navigator.virtualKeyboard) return;\n navigator.virtualKeyboard.hide();\n setOpened(false);\n };\n\n const show = () => {\n if (!navigator.virtualKeyboard) return;\n navigator.virtualKeyboard.show();\n setOpened(true);\n };\n\n const changeOverlaysContent = (overlaysContent: boolean) => {\n if (!navigator.virtualKeyboard) return;\n navigator.virtualKeyboard.overlaysContent = overlaysContent;\n };\n\n useEffect(() => {\n if (!supported) return;\n\n const onResize = () => setOpened(window.screen.height - 300 > window.visualViewport!.height);\n\n const onGeometryChange = (event: Event) => {\n const { height } = (event.target as any).boundingRect as DOMRect;\n setOpened(height > 0);\n };\n\n navigator.virtualKeyboard &&\n navigator.virtualKeyboard.addEventListener('geometrychange', onGeometryChange);\n window.visualViewport && window.visualViewport.addEventListener('resize', onResize);\n\n return () => {\n navigator.virtualKeyboard &&\n navigator.virtualKeyboard.removeEventListener('geometrychange', onGeometryChange);\n window.visualViewport && window.visualViewport.removeEventListener('resize', onResize);\n };\n }, []);\n\n return {\n opened,\n show,\n hide,\n changeOverlaysContent,\n supported\n };\n};\n"],"names":["useVirtualKeyboard","initialValue","supported","opened","setOpened","useState","hide","show","changeOverlaysContent","overlaysContent","useEffect","onResize","onGeometryChange","event","height"],"mappings":";AA4CO,MAAMA,IAAqB,CAACC,IAAe,OAAoC;AACpF,QAAMC,IACH,OAAO,SAAW,OAAe,oBAAoB,UACrD,OAAO,YAAc,OAAe,qBAAqB,WAEtD,CAACC,GAAQC,CAAS,IAAIC,EAASJ,CAAY,GAE3CK,IAAO,MAAM;AACjB,IAAK,UAAU,oBACf,UAAU,gBAAgB,KAAA,GAC1BF,EAAU,EAAK;AAAA,EAAA,GAGXG,IAAO,MAAM;AACjB,IAAK,UAAU,oBACf,UAAU,gBAAgB,KAAA,GAC1BH,EAAU,EAAI;AAAA,EAAA,GAGVI,IAAwB,CAACC,MAA6B;AAC1D,IAAK,UAAU,oBACf,UAAU,gBAAgB,kBAAkBA;AAAA,EAAA;AAG9C,SAAAC,EAAU,MAAM;AACd,QAAI,CAACR,EAAW;AAEhB,UAAMS,IAAW,MAAMP,EAAU,OAAO,OAAO,SAAS,MAAM,OAAO,eAAgB,MAAM,GAErFQ,IAAmB,CAACC,MAAiB;AACzC,YAAM,EAAE,QAAAC,EAAA,IAAYD,EAAM,OAAe;AACzC,MAAAT,EAAUU,IAAS,CAAC;AAAA,IAAA;AAGtB,qBAAU,mBACR,UAAU,gBAAgB,iBAAiB,kBAAkBF,CAAgB,GAC/E,OAAO,kBAAkB,OAAO,eAAe,iBAAiB,UAAUD,CAAQ,GAE3E,MAAM;AACX,gBAAU,mBACR,UAAU,gBAAgB,oBAAoB,kBAAkBC,CAAgB,GAClF,OAAO,kBAAkB,OAAO,eAAe,oBAAoB,UAAUD,CAAQ;AAAA,IAAA;AAAA,EACvF,GACC,EAAE,GAEE;AAAA,IACL,QAAAR;AAAA,IACA,MAAAI;AAAA,IACA,MAAAD;AAAA,IACA,uBAAAE;AAAA,IACA,WAAAN;AAAA,EAAA;AAEJ;"}
1
+ {"version":3,"file":"useVirtualKeyboard.mjs","sources":["../../../../src/hooks/useVirtualKeyboard/useVirtualKeyboard.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\r\n\r\ndeclare global {\r\n interface Navigator {\r\n virtualKeyboard?: {\r\n boundingRect: DOMRect;\r\n overlaysContent: boolean;\r\n show: () => void;\r\n hide: () => void;\r\n addEventListener: (type: 'geometrychange', listener: EventListener) => void;\r\n removeEventListener: (type: 'geometrychange', listener: EventListener) => void;\r\n };\r\n }\r\n}\r\n\r\n/** The use virtual keyboard return type */\r\nexport interface UseVirtualKeyboardReturn {\r\n /** Whether the virtual keyboard is currently open */\r\n opened: boolean;\r\n /** Whether the VirtualKeyboard API is supported */\r\n supported: boolean;\r\n /** Change the overlays content */\r\n changeOverlaysContent: (overlaysContent: boolean) => void;\r\n /** Hide the virtual keyboard */\r\n hide: () => void;\r\n /** Show the virtual keyboard */\r\n show: () => void;\r\n}\r\n\r\n/**\r\n * @name useVirtualKeyboard\r\n * @description - Hook that manages virtual keyboard state\r\n * @category Browser\r\n *\r\n * @browserapi VirtualKeyboard https://developer.mozilla.org/en-US/docs/Web/API/VirtualKeyboard\r\n *\r\n * @warning - This hook has a fallback for virtual keyboard detection. If the virtual keyboard is not supported, the methods will not work.\r\n *\r\n * @param {boolean} [initialValue=false] The initial state value for keyboard visibility\r\n * @returns {UseVirtualKeyboardReturn} An object containing keyboard state and control methods\r\n *\r\n * @example\r\n * const { opened, show, hide, supported, changeOverlaysContent } = useVirtualKeyboard();\r\n */\r\nexport const useVirtualKeyboard = (initialValue = false): UseVirtualKeyboardReturn => {\r\n const supported =\r\n (typeof window !== 'undefined' && 'visualViewport' in window) ||\r\n (typeof navigator !== 'undefined' && 'virtualKeyboard' in navigator);\r\n\r\n const [opened, setOpened] = useState(initialValue);\r\n\r\n const hide = () => {\r\n if (!navigator.virtualKeyboard) return;\r\n navigator.virtualKeyboard.hide();\r\n setOpened(false);\r\n };\r\n\r\n const show = () => {\r\n if (!navigator.virtualKeyboard) return;\r\n navigator.virtualKeyboard.show();\r\n setOpened(true);\r\n };\r\n\r\n const changeOverlaysContent = (overlaysContent: boolean) => {\r\n if (!navigator.virtualKeyboard) return;\r\n navigator.virtualKeyboard.overlaysContent = overlaysContent;\r\n };\r\n\r\n useEffect(() => {\r\n if (!supported) return;\r\n\r\n const onResize = () => setOpened(window.screen.height - 300 > window.visualViewport!.height);\r\n\r\n const onGeometryChange = (event: Event) => {\r\n const { height } = (event.target as any).boundingRect as DOMRect;\r\n setOpened(height > 0);\r\n };\r\n\r\n navigator.virtualKeyboard &&\r\n navigator.virtualKeyboard.addEventListener('geometrychange', onGeometryChange);\r\n window.visualViewport && window.visualViewport.addEventListener('resize', onResize);\r\n\r\n return () => {\r\n navigator.virtualKeyboard &&\r\n navigator.virtualKeyboard.removeEventListener('geometrychange', onGeometryChange);\r\n window.visualViewport && window.visualViewport.removeEventListener('resize', onResize);\r\n };\r\n }, []);\r\n\r\n return {\r\n opened,\r\n show,\r\n hide,\r\n changeOverlaysContent,\r\n supported\r\n };\r\n};\r\n"],"names":["useVirtualKeyboard","initialValue","supported","opened","setOpened","useState","hide","show","changeOverlaysContent","overlaysContent","useEffect","onResize","onGeometryChange","event","height"],"mappings":";AA4CO,MAAMA,IAAqB,CAACC,IAAe,OAAoC;AACpF,QAAMC,IACH,OAAO,SAAW,OAAe,oBAAoB,UACrD,OAAO,YAAc,OAAe,qBAAqB,WAEtD,CAACC,GAAQC,CAAS,IAAIC,EAASJ,CAAY,GAE3CK,IAAO,MAAM;AACjB,IAAK,UAAU,oBACf,UAAU,gBAAgB,KAAA,GAC1BF,EAAU,EAAK;AAAA,EAAA,GAGXG,IAAO,MAAM;AACjB,IAAK,UAAU,oBACf,UAAU,gBAAgB,KAAA,GAC1BH,EAAU,EAAI;AAAA,EAAA,GAGVI,IAAwB,CAACC,MAA6B;AAC1D,IAAK,UAAU,oBACf,UAAU,gBAAgB,kBAAkBA;AAAA,EAAA;AAG9C,SAAAC,EAAU,MAAM;AACd,QAAI,CAACR,EAAW;AAEhB,UAAMS,IAAW,MAAMP,EAAU,OAAO,OAAO,SAAS,MAAM,OAAO,eAAgB,MAAM,GAErFQ,IAAmB,CAACC,MAAiB;AACzC,YAAM,EAAE,QAAAC,EAAA,IAAYD,EAAM,OAAe;AACzC,MAAAT,EAAUU,IAAS,CAAC;AAAA,IAAA;AAGtB,qBAAU,mBACR,UAAU,gBAAgB,iBAAiB,kBAAkBF,CAAgB,GAC/E,OAAO,kBAAkB,OAAO,eAAe,iBAAiB,UAAUD,CAAQ,GAE3E,MAAM;AACX,gBAAU,mBACR,UAAU,gBAAgB,oBAAoB,kBAAkBC,CAAgB,GAClF,OAAO,kBAAkB,OAAO,eAAe,oBAAoB,UAAUD,CAAQ;AAAA,IAAA;AAAA,EACvF,GACC,EAAE,GAEE;AAAA,IACL,QAAAR;AAAA,IACA,MAAAI;AAAA,IACA,MAAAD;AAAA,IACA,uBAAAE;AAAA,IACA,WAAAN;AAAA,EAAA;AAEJ;"}
@@ -1,10 +1,11 @@
1
- type SetStateAction<Value> = ((prev: Value) => Value) | Value;
2
- type StateCreator<Value> = (set: (action: SetStateAction<Value>) => void, get: () => Value) => Value;
1
+ type StoreSetAction<Value> = ((prev: Value) => Partial<Value>) | Partial<Value>;
2
+ type StoreListener<Value> = (state: Value, prevState: Value) => void;
3
+ type StoreCreator<Value> = (set: (action: StoreSetAction<Value>) => void, get: () => Value) => Value;
3
4
  export interface StoreApi<Value> {
4
5
  getInitialState: () => Value;
5
6
  getState: () => Value;
6
- setState: (action: SetStateAction<Value>) => void;
7
- subscribe: (listener: (state: Value, prevState: Value) => void) => () => void;
7
+ setState: (action: StoreSetAction<Value>) => void;
8
+ subscribe: (listener: StoreListener<Value>) => () => void;
8
9
  }
9
10
  /**
10
11
  * @name createStore
@@ -21,10 +22,13 @@ export interface StoreApi<Value> {
21
22
  * increment: () => set(state => ({ count: state.count + 1 }))
22
23
  * }));
23
24
  */
24
- export declare const createStore: <Value>(createState: StateCreator<Value> | Value) => {
25
- set: (action: SetStateAction<Value>) => void;
25
+ export declare const createStore: <Value>(createState: StoreCreator<Value> | Value) => {
26
+ set: (action: StoreSetAction<Value>) => void;
26
27
  get: () => Value;
27
- use: <Selected>(selector?: (state: Value) => Selected) => Value | Selected;
28
- subscribe: (listener: (state: Value, prevState: Value) => void) => () => boolean;
28
+ use: {
29
+ (): Value;
30
+ <Selected>(selector: (state: Value) => Selected): Selected;
31
+ };
32
+ subscribe: (listener: StoreListener<Value>) => () => boolean;
29
33
  };
30
34
  export {};
@@ -11,10 +11,10 @@ export interface UseAsyncReturn<Data> {
11
11
  * @category Async
12
12
  *
13
13
  * @param {() => Promise<Data>} callback The async callback
14
- * @param {DependencyList} deps The dependencies of the callback
14
+ * @param {DependencyList} [deps=[]] The dependencies of the callback
15
15
  * @returns {UseAsyncReturn<Data>} The state of the async callback
16
16
  *
17
17
  * @example
18
18
  * const { data, isLoading, isError, error } = useAsync(() => fetch('url'), [deps]);
19
19
  */
20
- export declare const useAsync: <Data>(callback: () => Promise<Data>, deps: DependencyList) => UseAsyncReturn<Data>;
20
+ export declare const useAsync: <Data>(callback: () => Promise<Data>, deps?: DependencyList) => UseAsyncReturn<Data>;
@@ -31,14 +31,14 @@ export type UseImageReturn = UseQueryReturn<HTMLImageElement>;
31
31
  * @param {HTMLImageElement['loading']} [options.loading] The loading of the image
32
32
  * @param {string} [options.crossorigin] The crossorigin of the image
33
33
  * @param {HTMLImageElement['referrerPolicy']} [options.referrerPolicy] The referrerPolicy of the image
34
- * @param {DependencyList} [useQueryOptions.keys] The dependencies for the hook
35
- * @param {(data: Data) => void} [useQueryOptions.onSuccess] The callback function to be invoked on success
36
- * @param {(error: Error) => void} [useQueryOptions.onError] The callback function to be invoked on error
37
- * @param {number} [useQueryOptions.refetchInterval] The refetch interval
38
- * @param {boolean | number} [useQueryOptions.retry] The retry count of requests
34
+ * @param {DependencyList} [options.keys] The dependencies for the hook
35
+ * @param {(data: Data) => void} [options.onSuccess] The callback function to be invoked on success
36
+ * @param {(error: Error) => void} [options.onError] The callback function to be invoked on error
37
+ * @param {number} [options.refetchInterval] The refetch interval
38
+ * @param {boolean | number} [options.retry] The retry count of requests
39
39
  * @returns {UseImageReturn} An object with the state of the image
40
40
  *
41
41
  * @example
42
42
  * const { data, isLoading, isError, isSuccess, error, refetch, isRefetching } = useImage('https://example.com/image.png');
43
43
  */
44
- export declare const useImage: (src: string, options?: UseImageOptions, useQueryOptions?: Omit<UseQueryOptions<HTMLImageElement, HTMLImageElement>, "initialData" | "placeholderData" | "select">) => UseQueryReturn<HTMLImageElement>;
44
+ export declare const useImage: (src: string, options?: UseImageOptions & Omit<UseQueryOptions<HTMLImageElement, HTMLImageElement>, "initialData" | "placeholderData" | "select">) => UseQueryReturn<HTMLImageElement>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@siberiacancode/reactuse",
3
- "version": "0.2.27",
3
+ "version": "0.2.28",
4
4
  "description": "The ultimate collection of react hooks",
5
5
  "author": {
6
6
  "name": "SIBERIA CAN CODE 🧊",