@siberiacancode/reactuse 0.2.20 → 0.2.22

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 l=require("react"),g=require("../useRefState/useRefState.cjs"),d=require("../../utils/helpers/isTarget.cjs"),P=require("../../utils/helpers/getElement.cjs"),y=(...e)=>{const t=d.isTarget(e[0])?e[0]:void 0,r=(t?e[1]:e[0])??{},[i,u]=l.useState(!1),c=g.useRefState(),n=typeof document<"u"&&"pictureInPictureEnabled"in document,o=async()=>{if(!n)return;const f=t?P.getElement(t):c.current;f&&(await f.requestPictureInPicture(),u(!0),r.onEnter?.())},s=async()=>{n&&(await document.exitPictureInPicture(),u(!1),r.onExit?.())},a={open:i,supported:n,enter:o,exit:s,toggle:async()=>{i?await s():await o()}};return t?a:{...a,ref:c}};exports.usePictureInPicture=y;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("react"),v=require("../useRefState/useRefState.cjs"),g=require("../../utils/helpers/isTarget.cjs"),m=require("../../utils/helpers/getElement.cjs"),I=(...n)=>{const t=g.isTarget(n[0])?n[0]:void 0,r=(t?n[1]:n[0])??{},[a,u]=i.useState(!1),f=v.useRefState(),c=i.useRef(null),o=i.useRef(r);o.current=r;const s=typeof document<"u"&&"pictureInPictureEnabled"in document,l=async()=>{s&&c.current&&(await c.current.requestPictureInPicture(),u(!0),r.onEnter?.())},d=async()=>{s&&(await document.exitPictureInPicture(),u(!1),r.onExit?.())};i.useEffect(()=>{const e=t?m.getElement(t):f.current;if(!e)return;c.current=e;const P=()=>{u(!0),o.current.onEnter?.()},E=()=>{u(!1),o.current.onExit?.()};return e.addEventListener("enterpictureinpicture",P),e.addEventListener("leavepictureinpicture",E),()=>{e.removeEventListener("enterpictureinpicture",P),e.removeEventListener("leavepictureinpicture",E)}},[t]);const p={open:a,supported:s,enter:l,exit:d,toggle:async()=>{a?await d():await l()}};return t?p:{...p,ref:f}};exports.usePictureInPicture=I;
2
2
  //# sourceMappingURL=usePictureInPicture.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"usePictureInPicture.cjs","sources":["../../../../src/hooks/usePictureInPicture/usePictureInPicture.ts"],"sourcesContent":["import { useState } from 'react';\n\nimport type { HookTarget } from '@/utils/helpers';\n\nimport { getElement, isTarget } from '@/utils/helpers';\n\nimport type { StateRef } from '../useRefState/useRefState';\n\nimport { useRefState } from '../useRefState/useRefState';\n\n/** The use picture in picture options type */\nexport interface UsePictureInPictureOptions {\n /** The callback when Picture-in-Picture mode is entered */\n onEnter?: () => void;\n /** The callback when Picture-in-Picture mode is exited */\n onExit?: () => void;\n}\n\n/** The use picture in picture return type */\nexport interface UsePictureInPictureReturn {\n /** Whether Picture-in-Picture mode is currently active */\n open: boolean;\n /** Whether Picture-in-Picture mode is supported by the browser */\n supported: boolean;\n /** Request to enter Picture-in-Picture mode */\n enter: () => Promise<void>;\n /** Request to exit Picture-in-Picture mode */\n exit: () => Promise<void>;\n /** Toggle Picture-in-Picture mode */\n toggle: () => Promise<void>;\n}\n\nexport interface UsePictureInPicture {\n (target: HookTarget, options?: UsePictureInPictureOptions): UsePictureInPictureReturn;\n\n (options?: UsePictureInPictureOptions): UsePictureInPictureReturn & {\n ref: StateRef<HTMLVideoElement>;\n };\n}\n\n/**\n * @name usePictureInPicture\n * @description - Hook that provides Picture-in-Picture functionality for video elements\n * @category Browser\n *\n * @browserapi window.PictureInPicture https://developer.mozilla.org/en-US/docs/Web/API/Picture-in-Picture_API\n *\n * @overload\n * @param {HookTarget} target The target video element\n * @param {() => void} [options.onEnter] Callback when Picture-in-Picture mode is entered\n * @param {() => void} [options.onExit] Callback when Picture-in-Picture mode is exited\n * @returns {UsePictureInPictureReturn} An object containing Picture-in-Picture state and controls\n *\n * @example\n * const { open, supported, enter, exit, toggle } = usePictureInPicture(videoRef);\n *\n * @overload\n * @param {() => void} [options.onEnter] Callback when Picture-in-Picture mode is entered\n * @param {() => void} [options.onExit] Callback when Picture-in-Picture mode is exited\n * @returns {UsePictureInPictureReturn & { ref: StateRef<HTMLVideoElement> }} An object containing Picture-in-Picture state, controls and ref\n *\n * @example\n * const { ref, open, supported, enter, exit, toggle } = usePictureInPicture();\n */\nexport const usePictureInPicture = ((...params: any[]) => {\n const target = (isTarget(params[0]) ? params[0] : undefined) as HookTarget | undefined;\n const options = ((target ? params[1] : params[0]) as UsePictureInPictureOptions) ?? {};\n\n const [open, setOpen] = useState(false);\n\n const internalRef = useRefState<HTMLVideoElement>();\n\n const supported = typeof document !== 'undefined' && 'pictureInPictureEnabled' in document;\n\n const enter = async () => {\n if (!supported) return;\n\n const element = target ? (getElement(target) as HTMLVideoElement) : internalRef.current;\n\n if (!element) return;\n\n await element.requestPictureInPicture();\n setOpen(true);\n\n options.onEnter?.();\n };\n\n const exit = async () => {\n if (!supported) return;\n\n await document.exitPictureInPicture();\n setOpen(false);\n options.onExit?.();\n };\n\n const toggle = async () => {\n if (open) await exit();\n else await enter();\n };\n\n const value = {\n open,\n supported,\n enter,\n exit,\n toggle\n };\n\n if (target) return value;\n return { ...value, ref: internalRef };\n}) as UsePictureInPicture;\n"],"names":["usePictureInPicture","params","target","isTarget","options","open","setOpen","useState","internalRef","useRefState","supported","enter","element","getElement","exit","value"],"mappings":"mPAgEaA,EAAuB,IAAIC,IAAkB,CACxD,MAAMC,EAAUC,EAAAA,SAASF,EAAO,CAAC,CAAC,EAAIA,EAAO,CAAC,EAAI,OAC5CG,GAAYF,EAASD,EAAO,CAAC,EAAIA,EAAO,CAAC,IAAqC,CAAA,EAE9E,CAACI,EAAMC,CAAO,EAAIC,EAAAA,SAAS,EAAK,EAEhCC,EAAcC,EAAAA,YAAA,EAEdC,EAAY,OAAO,SAAa,KAAe,4BAA6B,SAE5EC,EAAQ,SAAY,CACxB,GAAI,CAACD,EAAW,OAEhB,MAAME,EAAUV,EAAUW,EAAAA,WAAWX,CAAM,EAAyBM,EAAY,QAE3EI,IAEL,MAAMA,EAAQ,wBAAA,EACdN,EAAQ,EAAI,EAEZF,EAAQ,UAAA,EAAU,EAGdU,EAAO,SAAY,CAClBJ,IAEL,MAAM,SAAS,qBAAA,EACfJ,EAAQ,EAAK,EACbF,EAAQ,SAAA,EAAS,EAQbW,EAAQ,CACZ,KAAAV,EACA,UAAAK,EACA,MAAAC,EACA,KAAAG,EACA,OAVa,SAAY,CACrBT,QAAYS,EAAA,QACLH,EAAA,CAAM,CAQjB,EAGF,OAAIT,EAAea,EACZ,CAAE,GAAGA,EAAO,IAAKP,CAAA,CAC1B"}
1
+ {"version":3,"file":"usePictureInPicture.cjs","sources":["../../../../src/hooks/usePictureInPicture/usePictureInPicture.ts"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\n\nimport type { HookTarget } from '@/utils/helpers';\n\nimport { getElement, isTarget } from '@/utils/helpers';\n\nimport type { StateRef } from '../useRefState/useRefState';\n\nimport { useRefState } from '../useRefState/useRefState';\n\n/** The use picture in picture options type */\nexport interface UsePictureInPictureOptions {\n /** The callback when Picture-in-Picture mode is entered */\n onEnter?: () => void;\n /** The callback when Picture-in-Picture mode is exited */\n onExit?: () => void;\n}\n\n/** The use picture in picture return type */\nexport interface UsePictureInPictureReturn {\n /** Whether Picture-in-Picture mode is currently active */\n open: boolean;\n /** Whether Picture-in-Picture mode is supported by the browser */\n supported: boolean;\n /** Request to enter Picture-in-Picture mode */\n enter: () => Promise<void>;\n /** Request to exit Picture-in-Picture mode */\n exit: () => Promise<void>;\n /** Toggle Picture-in-Picture mode */\n toggle: () => Promise<void>;\n}\n\nexport interface UsePictureInPicture {\n (target: HookTarget, options?: UsePictureInPictureOptions): UsePictureInPictureReturn;\n\n (options?: UsePictureInPictureOptions): UsePictureInPictureReturn & {\n ref: StateRef<HTMLVideoElement>;\n };\n}\n\n/**\n * @name usePictureInPicture\n * @description - Hook that provides Picture-in-Picture functionality for video elements\n * @category Browser\n *\n * @browserapi window.PictureInPicture https://developer.mozilla.org/en-US/docs/Web/API/Picture-in-Picture_API\n *\n * @overload\n * @param {HookTarget} target The target video element\n * @param {() => void} [options.onEnter] Callback when Picture-in-Picture mode is entered\n * @param {() => void} [options.onExit] Callback when Picture-in-Picture mode is exited\n * @returns {UsePictureInPictureReturn} An object containing Picture-in-Picture state and controls\n *\n * @example\n * const { open, supported, enter, exit, toggle } = usePictureInPicture(videoRef);\n *\n * @overload\n * @param {() => void} [options.onEnter] Callback when Picture-in-Picture mode is entered\n * @param {() => void} [options.onExit] Callback when Picture-in-Picture mode is exited\n * @returns {UsePictureInPictureReturn & { ref: StateRef<HTMLVideoElement> }} An object containing Picture-in-Picture state, controls and ref\n *\n * @example\n * const { ref, open, supported, enter, exit, toggle } = usePictureInPicture();\n */\nexport const usePictureInPicture = ((...params: any[]) => {\n const target = (isTarget(params[0]) ? params[0] : undefined) as HookTarget | undefined;\n const options = ((target ? params[1] : params[0]) as UsePictureInPictureOptions) ?? {};\n\n const [open, setOpen] = useState(false);\n\n const internalRef = useRefState<HTMLVideoElement>();\n const elementRef = useRef<HTMLVideoElement>(null);\n const onOptionsRef = useRef<UsePictureInPictureOptions>(options);\n onOptionsRef.current = options;\n\n const supported = typeof document !== 'undefined' && 'pictureInPictureEnabled' in document;\n\n const enter = async () => {\n if (!supported) return;\n\n if (!elementRef.current) return;\n\n await elementRef.current.requestPictureInPicture();\n setOpen(true);\n\n options.onEnter?.();\n };\n\n const exit = async () => {\n if (!supported) return;\n\n await document.exitPictureInPicture();\n setOpen(false);\n options.onExit?.();\n };\n\n useEffect(() => {\n const element = target ? (getElement(target) as HTMLVideoElement) : internalRef.current;\n if (!element) return;\n\n elementRef.current = element;\n\n const onEnterPictureInPicture = () => {\n setOpen(true);\n onOptionsRef.current.onEnter?.();\n };\n\n const onLeavePictureInPicture = () => {\n setOpen(false);\n onOptionsRef.current.onExit?.();\n };\n\n element.addEventListener('enterpictureinpicture', onEnterPictureInPicture);\n element.addEventListener('leavepictureinpicture', onLeavePictureInPicture);\n\n return () => {\n element.removeEventListener('enterpictureinpicture', onEnterPictureInPicture);\n element.removeEventListener('leavepictureinpicture', onLeavePictureInPicture);\n };\n }, [target]);\n\n const toggle = async () => {\n if (open) await exit();\n else await enter();\n };\n\n const value = {\n open,\n supported,\n enter,\n exit,\n toggle\n };\n\n if (target) return value;\n return { ...value, ref: internalRef };\n}) as UsePictureInPicture;\n"],"names":["usePictureInPicture","params","target","isTarget","options","open","setOpen","useState","internalRef","useRefState","elementRef","useRef","onOptionsRef","supported","enter","exit","useEffect","element","getElement","onEnterPictureInPicture","onLeavePictureInPicture","value"],"mappings":"mPAgEaA,EAAuB,IAAIC,IAAkB,CACxD,MAAMC,EAAUC,EAAAA,SAASF,EAAO,CAAC,CAAC,EAAIA,EAAO,CAAC,EAAI,OAC5CG,GAAYF,EAASD,EAAO,CAAC,EAAIA,EAAO,CAAC,IAAqC,CAAA,EAE9E,CAACI,EAAMC,CAAO,EAAIC,EAAAA,SAAS,EAAK,EAEhCC,EAAcC,EAAAA,YAAA,EACdC,EAAaC,EAAAA,OAAyB,IAAI,EAC1CC,EAAeD,EAAAA,OAAmCP,CAAO,EAC/DQ,EAAa,QAAUR,EAEvB,MAAMS,EAAY,OAAO,SAAa,KAAe,4BAA6B,SAE5EC,EAAQ,SAAY,CACnBD,GAEAH,EAAW,UAEhB,MAAMA,EAAW,QAAQ,wBAAA,EACzBJ,EAAQ,EAAI,EAEZF,EAAQ,UAAA,EAAU,EAGdW,EAAO,SAAY,CAClBF,IAEL,MAAM,SAAS,qBAAA,EACfP,EAAQ,EAAK,EACbF,EAAQ,SAAA,EAAS,EAGnBY,EAAAA,UAAU,IAAM,CACd,MAAMC,EAAUf,EAAUgB,EAAAA,WAAWhB,CAAM,EAAyBM,EAAY,QAChF,GAAI,CAACS,EAAS,OAEdP,EAAW,QAAUO,EAErB,MAAME,EAA0B,IAAM,CACpCb,EAAQ,EAAI,EACZM,EAAa,QAAQ,UAAA,CAAU,EAG3BQ,EAA0B,IAAM,CACpCd,EAAQ,EAAK,EACbM,EAAa,QAAQ,SAAA,CAAS,EAGhC,OAAAK,EAAQ,iBAAiB,wBAAyBE,CAAuB,EACzEF,EAAQ,iBAAiB,wBAAyBG,CAAuB,EAElE,IAAM,CACXH,EAAQ,oBAAoB,wBAAyBE,CAAuB,EAC5EF,EAAQ,oBAAoB,wBAAyBG,CAAuB,CAAA,CAC9E,EACC,CAAClB,CAAM,CAAC,EAOX,MAAMmB,EAAQ,CACZ,KAAAhB,EACA,UAAAQ,EACA,MAAAC,EACA,KAAAC,EACA,OAVa,SAAY,CACrBV,QAAYU,EAAA,QACLD,EAAA,CAAM,CAQjB,EAGF,OAAIZ,EAAemB,EACZ,CAAE,GAAGA,EAAO,IAAKb,CAAA,CAC1B"}
@@ -1 +1 @@
1
- {"version":3,"file":"useShallowEffect.cjs","sources":["../../../../src/hooks/useShallowEffect/useShallowEffect.ts"],"sourcesContent":["import type { DependencyList, EffectCallback } from 'react';\n\nimport { useEffect, useRef } from 'react';\n\nexport const deepEqual = (a: any, b: any): boolean => {\n if (a === b) return true;\n if (a == null || b == null) return a === b;\n if (typeof a !== typeof b) return false;\n if (typeof a !== 'object') return a === b;\n if (Array.isArray(a) !== Array.isArray(b)) return false;\n\n if (Array.isArray(a))\n return a.length === b.length && a.every((value, index) => deepEqual(value, b[index]));\n\n const keysA = Object.keys(a);\n const keysB = Object.keys(b);\n\n if (keysA.length !== keysB.length) return false;\n\n for (const key of keysA) {\n if (!keysB.includes(key)) return false;\n if (!deepEqual(a[key], b[key])) return false;\n }\n\n return true;\n};\n\n/**\n * @name useShallowEffect\n * @description - Hook that executes an effect only when dependencies change shallowly or deeply.\n * @category Lifecycle\n *\n * @param {EffectCallback} effect The effect callback\n * @param {DependencyList} [deps] The dependencies list for the effect\n *\n * @example\n * useShallowEffect(() => console.log(\"effect\"), [user]);\n */\nexport const useShallowEffect = (effect: EffectCallback, deps?: DependencyList) => {\n const depsRef = useRef<DependencyList>(deps);\n\n if (!depsRef.current || !deepEqual(deps, depsRef.current)) {\n depsRef.current = deps;\n }\n\n useEffect(effect, depsRef.current);\n};\n"],"names":["deepEqual","a","b","value","index","keysA","keysB","key","useShallowEffect","effect","deps","depsRef","useRef","useEffect"],"mappings":"yGAIaA,EAAY,CAACC,EAAQC,IAAoB,CACpD,GAAID,IAAMC,EAAG,MAAO,GACpB,GAAID,GAAK,MAAQC,GAAK,YAAaD,IAAMC,EACzC,GAAI,OAAOD,GAAM,OAAOC,EAAG,MAAO,GAClC,GAAI,OAAOD,GAAM,SAAU,OAAOA,IAAMC,EACxC,GAAI,MAAM,QAAQD,CAAC,IAAM,MAAM,QAAQC,CAAC,EAAG,MAAO,GAElD,GAAI,MAAM,QAAQD,CAAC,EACjB,OAAOA,EAAE,SAAWC,EAAE,QAAUD,EAAE,MAAM,CAACE,EAAOC,IAAUJ,EAAUG,EAAOD,EAAEE,CAAK,CAAC,CAAC,EAEtF,MAAMC,EAAQ,OAAO,KAAKJ,CAAC,EACrBK,EAAQ,OAAO,KAAKJ,CAAC,EAE3B,GAAIG,EAAM,SAAWC,EAAM,OAAQ,MAAO,GAE1C,UAAWC,KAAOF,EAEhB,GADI,CAACC,EAAM,SAASC,CAAG,GACnB,CAACP,EAAUC,EAAEM,CAAG,EAAGL,EAAEK,CAAG,CAAC,EAAG,MAAO,GAGzC,MAAO,EACT,EAaaC,EAAmB,CAACC,EAAwBC,IAA0B,CACjF,MAAMC,EAAUC,EAAAA,OAAuBF,CAAI,GAEvC,CAACC,EAAQ,SAAW,CAACX,EAAUU,EAAMC,EAAQ,OAAO,KACtDA,EAAQ,QAAUD,GAGpBG,YAAUJ,EAAQE,EAAQ,OAAO,CACnC"}
1
+ {"version":3,"file":"useShallowEffect.cjs","sources":["../../../../src/hooks/useShallowEffect/useShallowEffect.ts"],"sourcesContent":["import type { DependencyList, EffectCallback } from 'react';\n\nimport { useEffect, useRef } from 'react';\n\nexport const deepEqual = (a: any, b: any): boolean => {\n if (a === b) return true;\n if (a == null || b == null) return a === b;\n if (typeof a !== typeof b) return false;\n if (typeof a !== 'object') return a === b;\n if (Array.isArray(a) !== Array.isArray(b)) return false;\n\n if (Array.isArray(a))\n return a.length === b.length && a.every((value, index) => deepEqual(value, b[index]));\n\n const keysA = Object.keys(a);\n const keysB = Object.keys(b);\n\n if (keysA.length !== keysB.length) return false;\n\n for (const key of keysA) {\n if (!keysB.includes(key)) return false;\n if (!deepEqual(a[key], b[key])) return false;\n }\n\n return true;\n};\n\n/**\n * @name useShallowEffect\n * @description - Hook that executes an effect only when dependencies change shallowly or deeply\n * @category Lifecycle\n *\n * @param {EffectCallback} effect The effect callback\n * @param {DependencyList} [deps] The dependencies list for the effect\n *\n * @example\n * useShallowEffect(() => console.log(\"effect\"), [user]);\n */\nexport const useShallowEffect = (effect: EffectCallback, deps?: DependencyList) => {\n const depsRef = useRef<DependencyList>(deps);\n\n if (!depsRef.current || !deepEqual(deps, depsRef.current)) {\n depsRef.current = deps;\n }\n\n useEffect(effect, depsRef.current);\n};\n"],"names":["deepEqual","a","b","value","index","keysA","keysB","key","useShallowEffect","effect","deps","depsRef","useRef","useEffect"],"mappings":"yGAIaA,EAAY,CAACC,EAAQC,IAAoB,CACpD,GAAID,IAAMC,EAAG,MAAO,GACpB,GAAID,GAAK,MAAQC,GAAK,YAAaD,IAAMC,EACzC,GAAI,OAAOD,GAAM,OAAOC,EAAG,MAAO,GAClC,GAAI,OAAOD,GAAM,SAAU,OAAOA,IAAMC,EACxC,GAAI,MAAM,QAAQD,CAAC,IAAM,MAAM,QAAQC,CAAC,EAAG,MAAO,GAElD,GAAI,MAAM,QAAQD,CAAC,EACjB,OAAOA,EAAE,SAAWC,EAAE,QAAUD,EAAE,MAAM,CAACE,EAAOC,IAAUJ,EAAUG,EAAOD,EAAEE,CAAK,CAAC,CAAC,EAEtF,MAAMC,EAAQ,OAAO,KAAKJ,CAAC,EACrBK,EAAQ,OAAO,KAAKJ,CAAC,EAE3B,GAAIG,EAAM,SAAWC,EAAM,OAAQ,MAAO,GAE1C,UAAWC,KAAOF,EAEhB,GADI,CAACC,EAAM,SAASC,CAAG,GACnB,CAACP,EAAUC,EAAEM,CAAG,EAAGL,EAAEK,CAAG,CAAC,EAAG,MAAO,GAGzC,MAAO,EACT,EAaaC,EAAmB,CAACC,EAAwBC,IAA0B,CACjF,MAAMC,EAAUC,EAAAA,OAAuBF,CAAI,GAEvC,CAACC,EAAQ,SAAW,CAACX,EAAUU,EAAMC,EAAQ,OAAO,KACtDA,EAAQ,QAAUD,GAGpBG,YAAUJ,EAAQE,EAAQ,OAAO,CACnC"}
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("react"),I=require("../useDidUpdate/useDidUpdate.cjs"),m=o=>{const e=Math.ceil(o),i=Math.floor(e/(60*60*24)),c=Math.floor(e%(60*60*24)/(60*60)),t=Math.floor(e%(60*60)/60);return{seconds:Math.floor(e%60),minutes:t,hours:c,days:i}},R=(...o)=>{const e=Math.max(o[0]??0,0),i=typeof o[1]=="object"?o[1]:{onExpire:o[1]},[c,t]=d.useState(e>0&&(i?.immediately??!0)),[u,r]=d.useState(e),l=d.useRef(void 0),f=d.useRef(i);f.current=i??{},I.useDidUpdate(()=>{if(e<=0){t(!1),r(0);return}t(!0),r(e)},[e]),d.useEffect(()=>{if(!c)return;f.current?.onStart?.();const n=()=>{f.current?.onTick?.(u),r(s=>{const a=s-1;return a===0&&(t(!1),f.current?.onExpire?.()),a})};return l.current=setInterval(n,1e3),()=>{clearInterval(l.current)}},[c]);const S=()=>t(!1),p=()=>{u<=0||t(!0)},v=()=>{u<=0||t(!c)},h=(n,s=!0)=>{r(n),s&&t(!0)},M=()=>{e<=0||(t(!0),r(e))},T=()=>{t(!1),r(0)},g=n=>r(s=>s+n),y=n=>{r(s=>{const a=s-n;return a<=0?(t(!1),0):a})};return{...m(u),count:u,pause:S,active:c,resume:p,toggle:v,start:M,restart:h,clear:T,increase:g,decrease:y}};exports.getTimeFromSeconds=m;exports.useTimer=R;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("react"),I=require("../useDidUpdate/useDidUpdate.cjs"),m=o=>{const e=Math.ceil(o),u=Math.floor(e/(60*60*24)),c=Math.floor(e%(60*60*24)/(60*60)),t=Math.floor(e%(60*60)/60);return{seconds:Math.floor(e%60),minutes:t,hours:c,days:u}},R=(...o)=>{const e=Math.max(o[0]??0,0),u=typeof o[1]=="object"?o[1]:{onExpire:o[1]},[c,t]=d.useState(e>0&&(u?.immediately??!0)),[i,r]=d.useState(e),l=d.useRef(void 0),f=d.useRef(u);f.current=u??{},I.useDidUpdate(()=>{if(e<=0){t(!1),r(0);return}t(!0),r(e)},[e]),d.useEffect(()=>{if(!c)return;f.current?.onStart?.();const s=()=>{r(n=>{f.current?.onTick?.(n);const a=n-1;return a===0&&(t(!1),f.current?.onExpire?.()),a})};return l.current=setInterval(s,1e3),()=>{clearInterval(l.current)}},[c]);const S=()=>t(!1),p=()=>{i<=0||t(!0)},h=()=>{i<=0||t(!c)},v=(s,n=!0)=>{r(s),n&&t(!0)},M=()=>{e<=0||(t(!0),r(e))},T=()=>{t(!1),r(0)},g=s=>r(n=>n+s),y=s=>{r(n=>{const a=n-s;return a<=0?(t(!1),0):a})};return{...m(i),count:i,pause:S,active:c,resume:p,toggle:h,start:M,restart:v,clear:T,increase:g,decrease:y}};exports.getTimeFromSeconds=m;exports.useTimer=R;
2
2
  //# sourceMappingURL=useTimer.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"useTimer.cjs","sources":["../../../../src/hooks/useTimer/useTimer.ts"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\n\nimport { useDidUpdate } from '../useDidUpdate/useDidUpdate';\n\nexport type PositiveInteger<Value extends number> = `${Value}` extends `-${any}` | `${any}.${any}`\n ? never\n : Value;\n\nexport const getTimeFromSeconds = (timestamp: number) => {\n const roundedTimestamp = Math.ceil(timestamp);\n const days = Math.floor(roundedTimestamp / (60 * 60 * 24));\n const hours = Math.floor((roundedTimestamp % (60 * 60 * 24)) / (60 * 60));\n const minutes = Math.floor((roundedTimestamp % (60 * 60)) / 60);\n const seconds = Math.floor(roundedTimestamp % 60);\n\n return {\n seconds,\n minutes,\n hours,\n days\n };\n};\n\n/** The use timer options type */\nexport interface UseTimerOptions {\n /** Whether the timer should start automatically */\n immediately?: boolean;\n /** The function to be executed when the timer is expired */\n onExpire?: () => void;\n /** The function to be executed when the timer is started */\n onStart?: () => void;\n /** Callback function to be executed on each tick of the timer */\n onTick?: (seconds: number) => void;\n}\n\n/** The use timer return type */\nexport interface UseTimerReturn {\n /** flag to indicate if timer is active or not */\n active: boolean;\n /** The total count of the timer */\n count: number;\n /** The day count of the timer */\n days: number;\n /** The hour count of the timer */\n hours: number;\n /** The minute count of the timer */\n minutes: number;\n /** The second count of the timer */\n seconds: number;\n /** The function to clear the timer */\n clear: () => void;\n /** The function to decrease the timer */\n decrease: (seconds: PositiveInteger<number>) => void;\n /** The function to increase the timer */\n increase: (seconds: PositiveInteger<number>) => void;\n /** The function to pause the timer */\n pause: () => void;\n /** The function to restart the timer */\n restart: (time: PositiveInteger<number>, immediately?: boolean) => void;\n /** The function to resume the timer */\n resume: () => void;\n /** The function to start the timer */\n start: () => void;\n /** The function to toggle the timer */\n toggle: () => void;\n}\n\nexport interface UseTimer {\n (): UseTimerReturn;\n\n (seconds: PositiveInteger<number>, callback: () => void): UseTimerReturn;\n\n (seconds: PositiveInteger<number>, options?: UseTimerOptions): UseTimerReturn;\n}\n\n/**\n * @name useTimer\n * @description - Hook that creates a timer functionality\n * @category Time\n *\n * @overload\n * @returns {UseTimerReturn} An object containing the timer properties and functions\n *\n * @example\n * const { days, hours, minutes, seconds, toggle, pause, start, restart, resume, active, decrease, increase } = useTimer();\n *\n * @overload\n * @param {number} seconds The seconds value that define for how long the timer will be running\n * @param {() => void} callback The function to be executed once countdown timer is expired\n * @returns {UseTimerReturn} An object containing the timer properties and functions\n *\n * @example\n * const { days, hours, minutes, seconds, toggle, pause, start, restart, resume, active, decrease, increase } = useTimer(1000, () => console.log('ready'));\n *\n * @overload\n * @param {number} seconds The seconds value that define for how long the timer will be running\n * @param {boolean} [options.immediately=true] The flag to decide if timer should start automatically\n * @param {() => void} [options.onExpire] The function to be executed when the timer is expired\n * @param {(timestamp: number) => void} [options.onTick] The function to be executed on each tick of the timer\n * @returns {UseTimerReturn} An object containing the timer properties and functions\n *\n * @example\n * const { days, hours, minutes, seconds, toggle, pause, start, restart, resume, active, decrease, increase } = useTimer(1000);\n */\nexport const useTimer = ((...params: any[]) => {\n const initialSeconds = Math.max((params[0] ?? 0) as PositiveInteger<number>, 0);\n const options = (typeof params[1] === 'object' ? params[1] : { onExpire: params[1] }) as\n | UseTimerOptions\n | undefined;\n\n const [active, setActive] = useState(initialSeconds > 0 && (options?.immediately ?? true));\n const [seconds, setSeconds] = useState(initialSeconds);\n\n const intervalIdRef = useRef<ReturnType<typeof setInterval>>(undefined);\n const optionsRef = useRef<UseTimerOptions>(options);\n optionsRef.current = options ?? {};\n\n useDidUpdate(() => {\n if (initialSeconds <= 0) {\n setActive(false);\n setSeconds(0);\n return;\n }\n\n setActive(true);\n setSeconds(initialSeconds);\n }, [initialSeconds]);\n\n useEffect(() => {\n if (!active) return;\n\n optionsRef.current?.onStart?.();\n const onInterval = () => {\n optionsRef.current?.onTick?.(seconds);\n setSeconds((prevSeconds) => {\n const updatedSeconds = prevSeconds - 1;\n if (updatedSeconds === 0) {\n setActive(false);\n optionsRef.current?.onExpire?.();\n }\n return updatedSeconds;\n });\n };\n\n intervalIdRef.current = setInterval(onInterval, 1000);\n return () => {\n clearInterval(intervalIdRef.current);\n };\n }, [active]);\n\n const pause = () => setActive(false);\n const resume = () => {\n if (seconds <= 0) return;\n setActive(true);\n };\n\n const toggle = () => {\n if (seconds <= 0) return;\n setActive(!active);\n };\n\n const restart = (seconds: PositiveInteger<number>, immediately = true) => {\n setSeconds(seconds);\n if (immediately) setActive(true);\n };\n\n const start = () => {\n if (initialSeconds <= 0) return;\n\n setActive(true);\n setSeconds(initialSeconds);\n };\n\n const clear = () => {\n setActive(false);\n setSeconds(0);\n };\n\n const increase = (seconds: PositiveInteger<number>) =>\n setSeconds((prevSeconds) => prevSeconds + seconds);\n const decrease = (seconds: PositiveInteger<number>) => {\n setSeconds((prevSeconds) => {\n const updatedSeconds = prevSeconds - seconds;\n if (updatedSeconds <= 0) {\n setActive(false);\n return 0;\n } else {\n return updatedSeconds;\n }\n });\n };\n\n return {\n ...getTimeFromSeconds(seconds),\n count: seconds,\n pause,\n active,\n resume,\n toggle,\n start,\n restart,\n clear,\n increase,\n decrease\n };\n}) as UseTimer;\n"],"names":["getTimeFromSeconds","timestamp","roundedTimestamp","days","hours","minutes","useTimer","params","initialSeconds","options","active","setActive","useState","seconds","setSeconds","intervalIdRef","useRef","optionsRef","useDidUpdate","useEffect","onInterval","prevSeconds","updatedSeconds","pause","resume","toggle","restart","immediately","start","clear","increase","decrease"],"mappings":"uJAQaA,EAAsBC,GAAsB,CACvD,MAAMC,EAAmB,KAAK,KAAKD,CAAS,EACtCE,EAAO,KAAK,MAAMD,GAAoB,GAAK,GAAK,GAAG,EACnDE,EAAQ,KAAK,MAAOF,GAAoB,GAAK,GAAK,KAAQ,GAAK,GAAG,EAClEG,EAAU,KAAK,MAAOH,GAAoB,GAAK,IAAO,EAAE,EAG9D,MAAO,CACL,QAHc,KAAK,MAAMA,EAAmB,EAAE,EAI9C,QAAAG,EACA,MAAAD,EACA,KAAAD,CAAA,CAEJ,EAmFaG,EAAY,IAAIC,IAAkB,CAC7C,MAAMC,EAAiB,KAAK,IAAKD,EAAO,CAAC,GAAK,EAA+B,CAAC,EACxEE,EAAW,OAAOF,EAAO,CAAC,GAAM,SAAWA,EAAO,CAAC,EAAI,CAAE,SAAUA,EAAO,CAAC,CAAA,EAI3E,CAACG,EAAQC,CAAS,EAAIC,EAAAA,SAASJ,EAAiB,IAAMC,GAAS,aAAe,GAAK,EACnF,CAACI,EAASC,CAAU,EAAIF,EAAAA,SAASJ,CAAc,EAE/CO,EAAgBC,EAAAA,OAAuC,MAAS,EAChEC,EAAaD,EAAAA,OAAwBP,CAAO,EAClDQ,EAAW,QAAUR,GAAW,CAAA,EAEhCS,EAAAA,aAAa,IAAM,CACjB,GAAIV,GAAkB,EAAG,CACvBG,EAAU,EAAK,EACfG,EAAW,CAAC,EACZ,MAAA,CAGFH,EAAU,EAAI,EACdG,EAAWN,CAAc,CAAA,EACxB,CAACA,CAAc,CAAC,EAEnBW,EAAAA,UAAU,IAAM,CACd,GAAI,CAACT,EAAQ,OAEbO,EAAW,SAAS,UAAA,EACpB,MAAMG,EAAa,IAAM,CACvBH,EAAW,SAAS,SAASJ,CAAO,EACpCC,EAAYO,GAAgB,CAC1B,MAAMC,EAAiBD,EAAc,EACrC,OAAIC,IAAmB,IACrBX,EAAU,EAAK,EACfM,EAAW,SAAS,WAAA,GAEfK,CAAA,CACR,CAAA,EAGH,OAAAP,EAAc,QAAU,YAAYK,EAAY,GAAI,EAC7C,IAAM,CACX,cAAcL,EAAc,OAAO,CAAA,CACrC,EACC,CAACL,CAAM,CAAC,EAEX,MAAMa,EAAQ,IAAMZ,EAAU,EAAK,EAC7Ba,EAAS,IAAM,CACfX,GAAW,GACfF,EAAU,EAAI,CAAA,EAGVc,EAAS,IAAM,CACfZ,GAAW,GACfF,EAAU,CAACD,CAAM,CAAA,EAGbgB,EAAU,CAACb,EAAkCc,EAAc,KAAS,CACxEb,EAAWD,CAAO,EACdc,KAAuB,EAAI,CAAA,EAG3BC,EAAQ,IAAM,CACdpB,GAAkB,IAEtBG,EAAU,EAAI,EACdG,EAAWN,CAAc,EAAA,EAGrBqB,EAAQ,IAAM,CAClBlB,EAAU,EAAK,EACfG,EAAW,CAAC,CAAA,EAGRgB,EAAYjB,GAChBC,EAAYO,GAAgBA,EAAcR,CAAO,EAC7CkB,EAAYlB,GAAqC,CACrDC,EAAYO,GAAgB,CAC1B,MAAMC,EAAiBD,EAAcR,EACrC,OAAIS,GAAkB,GACpBX,EAAU,EAAK,EACR,GAEAW,CACT,CACD,CAAA,EAGH,MAAO,CACL,GAAGtB,EAAmBa,CAAO,EAC7B,MAAOA,EACP,MAAAU,EACA,OAAAb,EACA,OAAAc,EACA,OAAAC,EACA,MAAAG,EACA,QAAAF,EACA,MAAAG,EACA,SAAAC,EACA,SAAAC,CAAA,CAEJ"}
1
+ {"version":3,"file":"useTimer.cjs","sources":["../../../../src/hooks/useTimer/useTimer.ts"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\n\nimport { useDidUpdate } from '../useDidUpdate/useDidUpdate';\n\nexport type PositiveInteger<Value extends number> = `${Value}` extends `-${any}` | `${any}.${any}`\n ? never\n : Value;\n\nexport const getTimeFromSeconds = (timestamp: number) => {\n const roundedTimestamp = Math.ceil(timestamp);\n const days = Math.floor(roundedTimestamp / (60 * 60 * 24));\n const hours = Math.floor((roundedTimestamp % (60 * 60 * 24)) / (60 * 60));\n const minutes = Math.floor((roundedTimestamp % (60 * 60)) / 60);\n const seconds = Math.floor(roundedTimestamp % 60);\n\n return {\n seconds,\n minutes,\n hours,\n days\n };\n};\n\n/** The use timer options type */\nexport interface UseTimerOptions {\n /** Whether the timer should start automatically */\n immediately?: boolean;\n /** The function to be executed when the timer is expired */\n onExpire?: () => void;\n /** The function to be executed when the timer is started */\n onStart?: () => void;\n /** Callback function to be executed on each tick of the timer */\n onTick?: (seconds: number) => void;\n}\n\n/** The use timer return type */\nexport interface UseTimerReturn {\n /** flag to indicate if timer is active or not */\n active: boolean;\n /** The total count of the timer */\n count: number;\n /** The day count of the timer */\n days: number;\n /** The hour count of the timer */\n hours: number;\n /** The minute count of the timer */\n minutes: number;\n /** The second count of the timer */\n seconds: number;\n /** The function to clear the timer */\n clear: () => void;\n /** The function to decrease the timer */\n decrease: (seconds: PositiveInteger<number>) => void;\n /** The function to increase the timer */\n increase: (seconds: PositiveInteger<number>) => void;\n /** The function to pause the timer */\n pause: () => void;\n /** The function to restart the timer */\n restart: (time: PositiveInteger<number>, immediately?: boolean) => void;\n /** The function to resume the timer */\n resume: () => void;\n /** The function to start the timer */\n start: () => void;\n /** The function to toggle the timer */\n toggle: () => void;\n}\n\nexport interface UseTimer {\n (): UseTimerReturn;\n\n (seconds: PositiveInteger<number>, callback: () => void): UseTimerReturn;\n\n (seconds: PositiveInteger<number>, options?: UseTimerOptions): UseTimerReturn;\n}\n\n/**\n * @name useTimer\n * @description - Hook that creates a timer functionality\n * @category Time\n *\n * @overload\n * @returns {UseTimerReturn} An object containing the timer properties and functions\n *\n * @example\n * const { days, hours, minutes, seconds, toggle, pause, start, restart, resume, active, decrease, increase } = useTimer();\n *\n * @overload\n * @param {number} seconds The seconds value that define for how long the timer will be running\n * @param {() => void} callback The function to be executed once countdown timer is expired\n * @returns {UseTimerReturn} An object containing the timer properties and functions\n *\n * @example\n * const { days, hours, minutes, seconds, toggle, pause, start, restart, resume, active, decrease, increase } = useTimer(1000, () => console.log('ready'));\n *\n * @overload\n * @param {number} seconds The seconds value that define for how long the timer will be running\n * @param {boolean} [options.immediately=true] The flag to decide if timer should start automatically\n * @param {() => void} [options.onExpire] The function to be executed when the timer is expired\n * @param {(timestamp: number) => void} [options.onTick] The function to be executed on each tick of the timer\n * @returns {UseTimerReturn} An object containing the timer properties and functions\n *\n * @example\n * const { days, hours, minutes, seconds, toggle, pause, start, restart, resume, active, decrease, increase } = useTimer(1000);\n */\nexport const useTimer = ((...params: any[]) => {\n const initialSeconds = Math.max((params[0] ?? 0) as PositiveInteger<number>, 0);\n const options = (typeof params[1] === 'object' ? params[1] : { onExpire: params[1] }) as\n | UseTimerOptions\n | undefined;\n\n const [active, setActive] = useState(initialSeconds > 0 && (options?.immediately ?? true));\n const [seconds, setSeconds] = useState(initialSeconds);\n\n const intervalIdRef = useRef<ReturnType<typeof setInterval>>(undefined);\n const optionsRef = useRef<UseTimerOptions>(options);\n optionsRef.current = options ?? {};\n\n useDidUpdate(() => {\n if (initialSeconds <= 0) {\n setActive(false);\n setSeconds(0);\n return;\n }\n\n setActive(true);\n setSeconds(initialSeconds);\n }, [initialSeconds]);\n\n useEffect(() => {\n if (!active) return;\n\n optionsRef.current?.onStart?.();\n const onInterval = () => {\n setSeconds((prevSeconds) => {\n optionsRef.current?.onTick?.(prevSeconds);\n const updatedSeconds = prevSeconds - 1;\n if (updatedSeconds === 0) {\n setActive(false);\n optionsRef.current?.onExpire?.();\n }\n return updatedSeconds;\n });\n };\n\n intervalIdRef.current = setInterval(onInterval, 1000);\n return () => {\n clearInterval(intervalIdRef.current);\n };\n }, [active]);\n\n const pause = () => setActive(false);\n const resume = () => {\n if (seconds <= 0) return;\n setActive(true);\n };\n\n const toggle = () => {\n if (seconds <= 0) return;\n setActive(!active);\n };\n\n const restart = (seconds: PositiveInteger<number>, immediately = true) => {\n setSeconds(seconds);\n if (immediately) setActive(true);\n };\n\n const start = () => {\n if (initialSeconds <= 0) return;\n\n setActive(true);\n setSeconds(initialSeconds);\n };\n\n const clear = () => {\n setActive(false);\n setSeconds(0);\n };\n\n const increase = (seconds: PositiveInteger<number>) =>\n setSeconds((prevSeconds) => prevSeconds + seconds);\n const decrease = (seconds: PositiveInteger<number>) => {\n setSeconds((prevSeconds) => {\n const updatedSeconds = prevSeconds - seconds;\n if (updatedSeconds <= 0) {\n setActive(false);\n return 0;\n } else {\n return updatedSeconds;\n }\n });\n };\n\n return {\n ...getTimeFromSeconds(seconds),\n count: seconds,\n pause,\n active,\n resume,\n toggle,\n start,\n restart,\n clear,\n increase,\n decrease\n };\n}) as UseTimer;\n"],"names":["getTimeFromSeconds","timestamp","roundedTimestamp","days","hours","minutes","useTimer","params","initialSeconds","options","active","setActive","useState","seconds","setSeconds","intervalIdRef","useRef","optionsRef","useDidUpdate","useEffect","onInterval","prevSeconds","updatedSeconds","pause","resume","toggle","restart","immediately","start","clear","increase","decrease"],"mappings":"uJAQaA,EAAsBC,GAAsB,CACvD,MAAMC,EAAmB,KAAK,KAAKD,CAAS,EACtCE,EAAO,KAAK,MAAMD,GAAoB,GAAK,GAAK,GAAG,EACnDE,EAAQ,KAAK,MAAOF,GAAoB,GAAK,GAAK,KAAQ,GAAK,GAAG,EAClEG,EAAU,KAAK,MAAOH,GAAoB,GAAK,IAAO,EAAE,EAG9D,MAAO,CACL,QAHc,KAAK,MAAMA,EAAmB,EAAE,EAI9C,QAAAG,EACA,MAAAD,EACA,KAAAD,CAAA,CAEJ,EAmFaG,EAAY,IAAIC,IAAkB,CAC7C,MAAMC,EAAiB,KAAK,IAAKD,EAAO,CAAC,GAAK,EAA+B,CAAC,EACxEE,EAAW,OAAOF,EAAO,CAAC,GAAM,SAAWA,EAAO,CAAC,EAAI,CAAE,SAAUA,EAAO,CAAC,CAAA,EAI3E,CAACG,EAAQC,CAAS,EAAIC,EAAAA,SAASJ,EAAiB,IAAMC,GAAS,aAAe,GAAK,EACnF,CAACI,EAASC,CAAU,EAAIF,EAAAA,SAASJ,CAAc,EAE/CO,EAAgBC,EAAAA,OAAuC,MAAS,EAChEC,EAAaD,EAAAA,OAAwBP,CAAO,EAClDQ,EAAW,QAAUR,GAAW,CAAA,EAEhCS,EAAAA,aAAa,IAAM,CACjB,GAAIV,GAAkB,EAAG,CACvBG,EAAU,EAAK,EACfG,EAAW,CAAC,EACZ,MAAA,CAGFH,EAAU,EAAI,EACdG,EAAWN,CAAc,CAAA,EACxB,CAACA,CAAc,CAAC,EAEnBW,EAAAA,UAAU,IAAM,CACd,GAAI,CAACT,EAAQ,OAEbO,EAAW,SAAS,UAAA,EACpB,MAAMG,EAAa,IAAM,CACvBN,EAAYO,GAAgB,CAC1BJ,EAAW,SAAS,SAASI,CAAW,EACxC,MAAMC,EAAiBD,EAAc,EACrC,OAAIC,IAAmB,IACrBX,EAAU,EAAK,EACfM,EAAW,SAAS,WAAA,GAEfK,CAAA,CACR,CAAA,EAGH,OAAAP,EAAc,QAAU,YAAYK,EAAY,GAAI,EAC7C,IAAM,CACX,cAAcL,EAAc,OAAO,CAAA,CACrC,EACC,CAACL,CAAM,CAAC,EAEX,MAAMa,EAAQ,IAAMZ,EAAU,EAAK,EAC7Ba,EAAS,IAAM,CACfX,GAAW,GACfF,EAAU,EAAI,CAAA,EAGVc,EAAS,IAAM,CACfZ,GAAW,GACfF,EAAU,CAACD,CAAM,CAAA,EAGbgB,EAAU,CAACb,EAAkCc,EAAc,KAAS,CACxEb,EAAWD,CAAO,EACdc,KAAuB,EAAI,CAAA,EAG3BC,EAAQ,IAAM,CACdpB,GAAkB,IAEtBG,EAAU,EAAI,EACdG,EAAWN,CAAc,EAAA,EAGrBqB,EAAQ,IAAM,CAClBlB,EAAU,EAAK,EACfG,EAAW,CAAC,CAAA,EAGRgB,EAAYjB,GAChBC,EAAYO,GAAgBA,EAAcR,CAAO,EAC7CkB,EAAYlB,GAAqC,CACrDC,EAAYO,GAAgB,CAC1B,MAAMC,EAAiBD,EAAcR,EACrC,OAAIS,GAAkB,GACpBX,EAAU,EAAK,EACR,GAEAW,CACT,CACD,CAAA,EAGH,MAAO,CACL,GAAGtB,EAAmBa,CAAO,EAC7B,MAAOA,EACP,MAAAU,EACA,OAAAb,EACA,OAAAc,EACA,OAAAC,EACA,MAAAG,EACA,QAAAF,EACA,MAAAG,EACA,SAAAC,EACA,SAAAC,CAAA,CAEJ"}
@@ -1,26 +1,40 @@
1
- import { useState as l } from "react";
2
- import { useRefState as m } from "../useRefState/useRefState.mjs";
3
- import { isTarget as p } from "../../utils/helpers/isTarget.mjs";
4
- import { getElement as d } from "../../utils/helpers/getElement.mjs";
5
- const E = (...t) => {
6
- const e = p(t[0]) ? t[0] : void 0, r = (e ? t[1] : t[0]) ?? {}, [o, i] = l(!1), c = m(), n = typeof document < "u" && "pictureInPictureEnabled" in document, u = async () => {
7
- if (!n) return;
8
- const a = e ? d(e) : c.current;
9
- a && (await a.requestPictureInPicture(), i(!0), r.onEnter?.());
10
- }, s = async () => {
11
- n && (await document.exitPictureInPicture(), i(!1), r.onExit?.());
12
- }, f = {
13
- open: o,
14
- supported: n,
15
- enter: u,
16
- exit: s,
1
+ import { useState as v, useRef as E, useEffect as P } from "react";
2
+ import { useRefState as g } from "../useRefState/useRefState.mjs";
3
+ import { isTarget as I } from "../../utils/helpers/isTarget.mjs";
4
+ import { getElement as x } from "../../utils/helpers/getElement.mjs";
5
+ const S = (...n) => {
6
+ const t = I(n[0]) ? n[0] : void 0, r = (t ? n[1] : n[0]) ?? {}, [s, i] = v(!1), f = g(), c = E(null), u = E(r);
7
+ u.current = r;
8
+ const o = typeof document < "u" && "pictureInPictureEnabled" in document, a = async () => {
9
+ o && c.current && (await c.current.requestPictureInPicture(), i(!0), r.onEnter?.());
10
+ }, p = async () => {
11
+ o && (await document.exitPictureInPicture(), i(!1), r.onExit?.());
12
+ };
13
+ P(() => {
14
+ const e = t ? x(t) : f.current;
15
+ if (!e) return;
16
+ c.current = e;
17
+ const m = () => {
18
+ i(!0), u.current.onEnter?.();
19
+ }, d = () => {
20
+ i(!1), u.current.onExit?.();
21
+ };
22
+ return e.addEventListener("enterpictureinpicture", m), e.addEventListener("leavepictureinpicture", d), () => {
23
+ e.removeEventListener("enterpictureinpicture", m), e.removeEventListener("leavepictureinpicture", d);
24
+ };
25
+ }, [t]);
26
+ const l = {
27
+ open: s,
28
+ supported: o,
29
+ enter: a,
30
+ exit: p,
17
31
  toggle: async () => {
18
- o ? await s() : await u();
32
+ s ? await p() : await a();
19
33
  }
20
34
  };
21
- return e ? f : { ...f, ref: c };
35
+ return t ? l : { ...l, ref: f };
22
36
  };
23
37
  export {
24
- E as usePictureInPicture
38
+ S as usePictureInPicture
25
39
  };
26
40
  //# sourceMappingURL=usePictureInPicture.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"usePictureInPicture.mjs","sources":["../../../../src/hooks/usePictureInPicture/usePictureInPicture.ts"],"sourcesContent":["import { useState } from 'react';\n\nimport type { HookTarget } from '@/utils/helpers';\n\nimport { getElement, isTarget } from '@/utils/helpers';\n\nimport type { StateRef } from '../useRefState/useRefState';\n\nimport { useRefState } from '../useRefState/useRefState';\n\n/** The use picture in picture options type */\nexport interface UsePictureInPictureOptions {\n /** The callback when Picture-in-Picture mode is entered */\n onEnter?: () => void;\n /** The callback when Picture-in-Picture mode is exited */\n onExit?: () => void;\n}\n\n/** The use picture in picture return type */\nexport interface UsePictureInPictureReturn {\n /** Whether Picture-in-Picture mode is currently active */\n open: boolean;\n /** Whether Picture-in-Picture mode is supported by the browser */\n supported: boolean;\n /** Request to enter Picture-in-Picture mode */\n enter: () => Promise<void>;\n /** Request to exit Picture-in-Picture mode */\n exit: () => Promise<void>;\n /** Toggle Picture-in-Picture mode */\n toggle: () => Promise<void>;\n}\n\nexport interface UsePictureInPicture {\n (target: HookTarget, options?: UsePictureInPictureOptions): UsePictureInPictureReturn;\n\n (options?: UsePictureInPictureOptions): UsePictureInPictureReturn & {\n ref: StateRef<HTMLVideoElement>;\n };\n}\n\n/**\n * @name usePictureInPicture\n * @description - Hook that provides Picture-in-Picture functionality for video elements\n * @category Browser\n *\n * @browserapi window.PictureInPicture https://developer.mozilla.org/en-US/docs/Web/API/Picture-in-Picture_API\n *\n * @overload\n * @param {HookTarget} target The target video element\n * @param {() => void} [options.onEnter] Callback when Picture-in-Picture mode is entered\n * @param {() => void} [options.onExit] Callback when Picture-in-Picture mode is exited\n * @returns {UsePictureInPictureReturn} An object containing Picture-in-Picture state and controls\n *\n * @example\n * const { open, supported, enter, exit, toggle } = usePictureInPicture(videoRef);\n *\n * @overload\n * @param {() => void} [options.onEnter] Callback when Picture-in-Picture mode is entered\n * @param {() => void} [options.onExit] Callback when Picture-in-Picture mode is exited\n * @returns {UsePictureInPictureReturn & { ref: StateRef<HTMLVideoElement> }} An object containing Picture-in-Picture state, controls and ref\n *\n * @example\n * const { ref, open, supported, enter, exit, toggle } = usePictureInPicture();\n */\nexport const usePictureInPicture = ((...params: any[]) => {\n const target = (isTarget(params[0]) ? params[0] : undefined) as HookTarget | undefined;\n const options = ((target ? params[1] : params[0]) as UsePictureInPictureOptions) ?? {};\n\n const [open, setOpen] = useState(false);\n\n const internalRef = useRefState<HTMLVideoElement>();\n\n const supported = typeof document !== 'undefined' && 'pictureInPictureEnabled' in document;\n\n const enter = async () => {\n if (!supported) return;\n\n const element = target ? (getElement(target) as HTMLVideoElement) : internalRef.current;\n\n if (!element) return;\n\n await element.requestPictureInPicture();\n setOpen(true);\n\n options.onEnter?.();\n };\n\n const exit = async () => {\n if (!supported) return;\n\n await document.exitPictureInPicture();\n setOpen(false);\n options.onExit?.();\n };\n\n const toggle = async () => {\n if (open) await exit();\n else await enter();\n };\n\n const value = {\n open,\n supported,\n enter,\n exit,\n toggle\n };\n\n if (target) return value;\n return { ...value, ref: internalRef };\n}) as UsePictureInPicture;\n"],"names":["usePictureInPicture","params","target","isTarget","options","open","setOpen","useState","internalRef","useRefState","supported","enter","element","getElement","exit","value"],"mappings":";;;;AAgEO,MAAMA,IAAuB,IAAIC,MAAkB;AACxD,QAAMC,IAAUC,EAASF,EAAO,CAAC,CAAC,IAAIA,EAAO,CAAC,IAAI,QAC5CG,KAAYF,IAASD,EAAO,CAAC,IAAIA,EAAO,CAAC,MAAqC,CAAA,GAE9E,CAACI,GAAMC,CAAO,IAAIC,EAAS,EAAK,GAEhCC,IAAcC,EAAA,GAEdC,IAAY,OAAO,WAAa,OAAe,6BAA6B,UAE5EC,IAAQ,YAAY;AACxB,QAAI,CAACD,EAAW;AAEhB,UAAME,IAAUV,IAAUW,EAAWX,CAAM,IAAyBM,EAAY;AAEhF,IAAKI,MAEL,MAAMA,EAAQ,wBAAA,GACdN,EAAQ,EAAI,GAEZF,EAAQ,UAAA;AAAA,EAAU,GAGdU,IAAO,YAAY;AACvB,IAAKJ,MAEL,MAAM,SAAS,qBAAA,GACfJ,EAAQ,EAAK,GACbF,EAAQ,SAAA;AAAA,EAAS,GAQbW,IAAQ;AAAA,IACZ,MAAAV;AAAA,IACA,WAAAK;AAAA,IACA,OAAAC;AAAA,IACA,MAAAG;AAAA,IACA,QAVa,YAAY;AACzB,MAAIT,UAAYS,EAAA,UACLH,EAAA;AAAA,IAAM;AAAA,EAQjB;AAGF,SAAIT,IAAea,IACZ,EAAE,GAAGA,GAAO,KAAKP,EAAA;AAC1B;"}
1
+ {"version":3,"file":"usePictureInPicture.mjs","sources":["../../../../src/hooks/usePictureInPicture/usePictureInPicture.ts"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\n\nimport type { HookTarget } from '@/utils/helpers';\n\nimport { getElement, isTarget } from '@/utils/helpers';\n\nimport type { StateRef } from '../useRefState/useRefState';\n\nimport { useRefState } from '../useRefState/useRefState';\n\n/** The use picture in picture options type */\nexport interface UsePictureInPictureOptions {\n /** The callback when Picture-in-Picture mode is entered */\n onEnter?: () => void;\n /** The callback when Picture-in-Picture mode is exited */\n onExit?: () => void;\n}\n\n/** The use picture in picture return type */\nexport interface UsePictureInPictureReturn {\n /** Whether Picture-in-Picture mode is currently active */\n open: boolean;\n /** Whether Picture-in-Picture mode is supported by the browser */\n supported: boolean;\n /** Request to enter Picture-in-Picture mode */\n enter: () => Promise<void>;\n /** Request to exit Picture-in-Picture mode */\n exit: () => Promise<void>;\n /** Toggle Picture-in-Picture mode */\n toggle: () => Promise<void>;\n}\n\nexport interface UsePictureInPicture {\n (target: HookTarget, options?: UsePictureInPictureOptions): UsePictureInPictureReturn;\n\n (options?: UsePictureInPictureOptions): UsePictureInPictureReturn & {\n ref: StateRef<HTMLVideoElement>;\n };\n}\n\n/**\n * @name usePictureInPicture\n * @description - Hook that provides Picture-in-Picture functionality for video elements\n * @category Browser\n *\n * @browserapi window.PictureInPicture https://developer.mozilla.org/en-US/docs/Web/API/Picture-in-Picture_API\n *\n * @overload\n * @param {HookTarget} target The target video element\n * @param {() => void} [options.onEnter] Callback when Picture-in-Picture mode is entered\n * @param {() => void} [options.onExit] Callback when Picture-in-Picture mode is exited\n * @returns {UsePictureInPictureReturn} An object containing Picture-in-Picture state and controls\n *\n * @example\n * const { open, supported, enter, exit, toggle } = usePictureInPicture(videoRef);\n *\n * @overload\n * @param {() => void} [options.onEnter] Callback when Picture-in-Picture mode is entered\n * @param {() => void} [options.onExit] Callback when Picture-in-Picture mode is exited\n * @returns {UsePictureInPictureReturn & { ref: StateRef<HTMLVideoElement> }} An object containing Picture-in-Picture state, controls and ref\n *\n * @example\n * const { ref, open, supported, enter, exit, toggle } = usePictureInPicture();\n */\nexport const usePictureInPicture = ((...params: any[]) => {\n const target = (isTarget(params[0]) ? params[0] : undefined) as HookTarget | undefined;\n const options = ((target ? params[1] : params[0]) as UsePictureInPictureOptions) ?? {};\n\n const [open, setOpen] = useState(false);\n\n const internalRef = useRefState<HTMLVideoElement>();\n const elementRef = useRef<HTMLVideoElement>(null);\n const onOptionsRef = useRef<UsePictureInPictureOptions>(options);\n onOptionsRef.current = options;\n\n const supported = typeof document !== 'undefined' && 'pictureInPictureEnabled' in document;\n\n const enter = async () => {\n if (!supported) return;\n\n if (!elementRef.current) return;\n\n await elementRef.current.requestPictureInPicture();\n setOpen(true);\n\n options.onEnter?.();\n };\n\n const exit = async () => {\n if (!supported) return;\n\n await document.exitPictureInPicture();\n setOpen(false);\n options.onExit?.();\n };\n\n useEffect(() => {\n const element = target ? (getElement(target) as HTMLVideoElement) : internalRef.current;\n if (!element) return;\n\n elementRef.current = element;\n\n const onEnterPictureInPicture = () => {\n setOpen(true);\n onOptionsRef.current.onEnter?.();\n };\n\n const onLeavePictureInPicture = () => {\n setOpen(false);\n onOptionsRef.current.onExit?.();\n };\n\n element.addEventListener('enterpictureinpicture', onEnterPictureInPicture);\n element.addEventListener('leavepictureinpicture', onLeavePictureInPicture);\n\n return () => {\n element.removeEventListener('enterpictureinpicture', onEnterPictureInPicture);\n element.removeEventListener('leavepictureinpicture', onLeavePictureInPicture);\n };\n }, [target]);\n\n const toggle = async () => {\n if (open) await exit();\n else await enter();\n };\n\n const value = {\n open,\n supported,\n enter,\n exit,\n toggle\n };\n\n if (target) return value;\n return { ...value, ref: internalRef };\n}) as UsePictureInPicture;\n"],"names":["usePictureInPicture","params","target","isTarget","options","open","setOpen","useState","internalRef","useRefState","elementRef","useRef","onOptionsRef","supported","enter","exit","useEffect","element","getElement","onEnterPictureInPicture","onLeavePictureInPicture","value"],"mappings":";;;;AAgEO,MAAMA,IAAuB,IAAIC,MAAkB;AACxD,QAAMC,IAAUC,EAASF,EAAO,CAAC,CAAC,IAAIA,EAAO,CAAC,IAAI,QAC5CG,KAAYF,IAASD,EAAO,CAAC,IAAIA,EAAO,CAAC,MAAqC,CAAA,GAE9E,CAACI,GAAMC,CAAO,IAAIC,EAAS,EAAK,GAEhCC,IAAcC,EAAA,GACdC,IAAaC,EAAyB,IAAI,GAC1CC,IAAeD,EAAmCP,CAAO;AAC/D,EAAAQ,EAAa,UAAUR;AAEvB,QAAMS,IAAY,OAAO,WAAa,OAAe,6BAA6B,UAE5EC,IAAQ,YAAY;AACxB,IAAKD,KAEAH,EAAW,YAEhB,MAAMA,EAAW,QAAQ,wBAAA,GACzBJ,EAAQ,EAAI,GAEZF,EAAQ,UAAA;AAAA,EAAU,GAGdW,IAAO,YAAY;AACvB,IAAKF,MAEL,MAAM,SAAS,qBAAA,GACfP,EAAQ,EAAK,GACbF,EAAQ,SAAA;AAAA,EAAS;AAGnB,EAAAY,EAAU,MAAM;AACd,UAAMC,IAAUf,IAAUgB,EAAWhB,CAAM,IAAyBM,EAAY;AAChF,QAAI,CAACS,EAAS;AAEd,IAAAP,EAAW,UAAUO;AAErB,UAAME,IAA0B,MAAM;AACpC,MAAAb,EAAQ,EAAI,GACZM,EAAa,QAAQ,UAAA;AAAA,IAAU,GAG3BQ,IAA0B,MAAM;AACpC,MAAAd,EAAQ,EAAK,GACbM,EAAa,QAAQ,SAAA;AAAA,IAAS;AAGhC,WAAAK,EAAQ,iBAAiB,yBAAyBE,CAAuB,GACzEF,EAAQ,iBAAiB,yBAAyBG,CAAuB,GAElE,MAAM;AACX,MAAAH,EAAQ,oBAAoB,yBAAyBE,CAAuB,GAC5EF,EAAQ,oBAAoB,yBAAyBG,CAAuB;AAAA,IAAA;AAAA,EAC9E,GACC,CAAClB,CAAM,CAAC;AAOX,QAAMmB,IAAQ;AAAA,IACZ,MAAAhB;AAAA,IACA,WAAAQ;AAAA,IACA,OAAAC;AAAA,IACA,MAAAC;AAAA,IACA,QAVa,YAAY;AACzB,MAAIV,UAAYU,EAAA,UACLD,EAAA;AAAA,IAAM;AAAA,EAQjB;AAGF,SAAIZ,IAAemB,IACZ,EAAE,GAAGA,GAAO,KAAKb,EAAA;AAC1B;"}
@@ -1 +1 @@
1
- {"version":3,"file":"useShallowEffect.mjs","sources":["../../../../src/hooks/useShallowEffect/useShallowEffect.ts"],"sourcesContent":["import type { DependencyList, EffectCallback } from 'react';\n\nimport { useEffect, useRef } from 'react';\n\nexport const deepEqual = (a: any, b: any): boolean => {\n if (a === b) return true;\n if (a == null || b == null) return a === b;\n if (typeof a !== typeof b) return false;\n if (typeof a !== 'object') return a === b;\n if (Array.isArray(a) !== Array.isArray(b)) return false;\n\n if (Array.isArray(a))\n return a.length === b.length && a.every((value, index) => deepEqual(value, b[index]));\n\n const keysA = Object.keys(a);\n const keysB = Object.keys(b);\n\n if (keysA.length !== keysB.length) return false;\n\n for (const key of keysA) {\n if (!keysB.includes(key)) return false;\n if (!deepEqual(a[key], b[key])) return false;\n }\n\n return true;\n};\n\n/**\n * @name useShallowEffect\n * @description - Hook that executes an effect only when dependencies change shallowly or deeply.\n * @category Lifecycle\n *\n * @param {EffectCallback} effect The effect callback\n * @param {DependencyList} [deps] The dependencies list for the effect\n *\n * @example\n * useShallowEffect(() => console.log(\"effect\"), [user]);\n */\nexport const useShallowEffect = (effect: EffectCallback, deps?: DependencyList) => {\n const depsRef = useRef<DependencyList>(deps);\n\n if (!depsRef.current || !deepEqual(deps, depsRef.current)) {\n depsRef.current = deps;\n }\n\n useEffect(effect, depsRef.current);\n};\n"],"names":["deepEqual","a","b","value","index","keysA","keysB","key","useShallowEffect","effect","deps","depsRef","useRef","useEffect"],"mappings":";AAIO,MAAMA,IAAY,CAACC,GAAQC,MAAoB;AACpD,MAAID,MAAMC,EAAG,QAAO;AACpB,MAAID,KAAK,QAAQC,KAAK,aAAaD,MAAMC;AACzC,MAAI,OAAOD,KAAM,OAAOC,EAAG,QAAO;AAClC,MAAI,OAAOD,KAAM,SAAU,QAAOA,MAAMC;AACxC,MAAI,MAAM,QAAQD,CAAC,MAAM,MAAM,QAAQC,CAAC,EAAG,QAAO;AAElD,MAAI,MAAM,QAAQD,CAAC;AACjB,WAAOA,EAAE,WAAWC,EAAE,UAAUD,EAAE,MAAM,CAACE,GAAOC,MAAUJ,EAAUG,GAAOD,EAAEE,CAAK,CAAC,CAAC;AAEtF,QAAMC,IAAQ,OAAO,KAAKJ,CAAC,GACrBK,IAAQ,OAAO,KAAKJ,CAAC;AAE3B,MAAIG,EAAM,WAAWC,EAAM,OAAQ,QAAO;AAE1C,aAAWC,KAAOF;AAEhB,QADI,CAACC,EAAM,SAASC,CAAG,KACnB,CAACP,EAAUC,EAAEM,CAAG,GAAGL,EAAEK,CAAG,CAAC,EAAG,QAAO;AAGzC,SAAO;AACT,GAaaC,IAAmB,CAACC,GAAwBC,MAA0B;AACjF,QAAMC,IAAUC,EAAuBF,CAAI;AAE3C,GAAI,CAACC,EAAQ,WAAW,CAACX,EAAUU,GAAMC,EAAQ,OAAO,OACtDA,EAAQ,UAAUD,IAGpBG,EAAUJ,GAAQE,EAAQ,OAAO;AACnC;"}
1
+ {"version":3,"file":"useShallowEffect.mjs","sources":["../../../../src/hooks/useShallowEffect/useShallowEffect.ts"],"sourcesContent":["import type { DependencyList, EffectCallback } from 'react';\n\nimport { useEffect, useRef } from 'react';\n\nexport const deepEqual = (a: any, b: any): boolean => {\n if (a === b) return true;\n if (a == null || b == null) return a === b;\n if (typeof a !== typeof b) return false;\n if (typeof a !== 'object') return a === b;\n if (Array.isArray(a) !== Array.isArray(b)) return false;\n\n if (Array.isArray(a))\n return a.length === b.length && a.every((value, index) => deepEqual(value, b[index]));\n\n const keysA = Object.keys(a);\n const keysB = Object.keys(b);\n\n if (keysA.length !== keysB.length) return false;\n\n for (const key of keysA) {\n if (!keysB.includes(key)) return false;\n if (!deepEqual(a[key], b[key])) return false;\n }\n\n return true;\n};\n\n/**\n * @name useShallowEffect\n * @description - Hook that executes an effect only when dependencies change shallowly or deeply\n * @category Lifecycle\n *\n * @param {EffectCallback} effect The effect callback\n * @param {DependencyList} [deps] The dependencies list for the effect\n *\n * @example\n * useShallowEffect(() => console.log(\"effect\"), [user]);\n */\nexport const useShallowEffect = (effect: EffectCallback, deps?: DependencyList) => {\n const depsRef = useRef<DependencyList>(deps);\n\n if (!depsRef.current || !deepEqual(deps, depsRef.current)) {\n depsRef.current = deps;\n }\n\n useEffect(effect, depsRef.current);\n};\n"],"names":["deepEqual","a","b","value","index","keysA","keysB","key","useShallowEffect","effect","deps","depsRef","useRef","useEffect"],"mappings":";AAIO,MAAMA,IAAY,CAACC,GAAQC,MAAoB;AACpD,MAAID,MAAMC,EAAG,QAAO;AACpB,MAAID,KAAK,QAAQC,KAAK,aAAaD,MAAMC;AACzC,MAAI,OAAOD,KAAM,OAAOC,EAAG,QAAO;AAClC,MAAI,OAAOD,KAAM,SAAU,QAAOA,MAAMC;AACxC,MAAI,MAAM,QAAQD,CAAC,MAAM,MAAM,QAAQC,CAAC,EAAG,QAAO;AAElD,MAAI,MAAM,QAAQD,CAAC;AACjB,WAAOA,EAAE,WAAWC,EAAE,UAAUD,EAAE,MAAM,CAACE,GAAOC,MAAUJ,EAAUG,GAAOD,EAAEE,CAAK,CAAC,CAAC;AAEtF,QAAMC,IAAQ,OAAO,KAAKJ,CAAC,GACrBK,IAAQ,OAAO,KAAKJ,CAAC;AAE3B,MAAIG,EAAM,WAAWC,EAAM,OAAQ,QAAO;AAE1C,aAAWC,KAAOF;AAEhB,QADI,CAACC,EAAM,SAASC,CAAG,KACnB,CAACP,EAAUC,EAAEM,CAAG,GAAGL,EAAEK,CAAG,CAAC,EAAG,QAAO;AAGzC,SAAO;AACT,GAaaC,IAAmB,CAACC,GAAwBC,MAA0B;AACjF,QAAMC,IAAUC,EAAuBF,CAAI;AAE3C,GAAI,CAACC,EAAQ,WAAW,CAACX,EAAUU,GAAMC,EAAQ,OAAO,OACtDA,EAAQ,UAAUD,IAGpBG,EAAUJ,GAAQE,EAAQ,OAAO;AACnC;"}
@@ -1,16 +1,16 @@
1
1
  import { useState as l, useRef as m, useEffect as g } from "react";
2
2
  import { useDidUpdate as y } from "../useDidUpdate/useDidUpdate.mjs";
3
3
  const E = (s) => {
4
- const t = Math.ceil(s), i = Math.floor(t / (60 * 60 * 24)), c = Math.floor(t % (60 * 60 * 24) / (60 * 60)), e = Math.floor(t % (60 * 60) / 60);
4
+ const t = Math.ceil(s), u = Math.floor(t / (60 * 60 * 24)), c = Math.floor(t % (60 * 60 * 24) / (60 * 60)), e = Math.floor(t % (60 * 60) / 60);
5
5
  return {
6
6
  seconds: Math.floor(t % 60),
7
7
  minutes: e,
8
8
  hours: c,
9
- days: i
9
+ days: u
10
10
  };
11
11
  }, j = (...s) => {
12
- const t = Math.max(s[0] ?? 0, 0), i = typeof s[1] == "object" ? s[1] : { onExpire: s[1] }, [c, e] = l(t > 0 && (i?.immediately ?? !0)), [u, n] = l(t), d = m(void 0), f = m(i);
13
- f.current = i ?? {}, y(() => {
12
+ const t = Math.max(s[0] ?? 0, 0), u = typeof s[1] == "object" ? s[1] : { onExpire: s[1] }, [c, e] = l(t > 0 && (u?.immediately ?? !0)), [i, n] = l(t), d = m(void 0), f = m(u);
13
+ f.current = u ?? {}, y(() => {
14
14
  if (t <= 0) {
15
15
  e(!1), n(0);
16
16
  return;
@@ -19,41 +19,42 @@ const E = (s) => {
19
19
  }, [t]), g(() => {
20
20
  if (!c) return;
21
21
  f.current?.onStart?.();
22
- const r = () => {
23
- f.current?.onTick?.(u), n((o) => {
24
- const a = o - 1;
22
+ const o = () => {
23
+ n((r) => {
24
+ f.current?.onTick?.(r);
25
+ const a = r - 1;
25
26
  return a === 0 && (e(!1), f.current?.onExpire?.()), a;
26
27
  });
27
28
  };
28
- return d.current = setInterval(r, 1e3), () => {
29
+ return d.current = setInterval(o, 1e3), () => {
29
30
  clearInterval(d.current);
30
31
  };
31
32
  }, [c]);
32
33
  const p = () => e(!1), h = () => {
33
- u <= 0 || e(!0);
34
+ i <= 0 || e(!0);
34
35
  }, v = () => {
35
- u <= 0 || e(!c);
36
- }, S = (r, o = !0) => {
37
- n(r), o && e(!0);
38
- }, M = () => {
36
+ i <= 0 || e(!c);
37
+ }, M = (o, r = !0) => {
38
+ n(o), r && e(!0);
39
+ }, S = () => {
39
40
  t <= 0 || (e(!0), n(t));
40
41
  }, x = () => {
41
42
  e(!1), n(0);
42
- }, I = (r) => n((o) => o + r), T = (r) => {
43
- n((o) => {
44
- const a = o - r;
43
+ }, I = (o) => n((r) => r + o), T = (o) => {
44
+ n((r) => {
45
+ const a = r - o;
45
46
  return a <= 0 ? (e(!1), 0) : a;
46
47
  });
47
48
  };
48
49
  return {
49
- ...E(u),
50
- count: u,
50
+ ...E(i),
51
+ count: i,
51
52
  pause: p,
52
53
  active: c,
53
54
  resume: h,
54
55
  toggle: v,
55
- start: M,
56
- restart: S,
56
+ start: S,
57
+ restart: M,
57
58
  clear: x,
58
59
  increase: I,
59
60
  decrease: T
@@ -1 +1 @@
1
- {"version":3,"file":"useTimer.mjs","sources":["../../../../src/hooks/useTimer/useTimer.ts"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\n\nimport { useDidUpdate } from '../useDidUpdate/useDidUpdate';\n\nexport type PositiveInteger<Value extends number> = `${Value}` extends `-${any}` | `${any}.${any}`\n ? never\n : Value;\n\nexport const getTimeFromSeconds = (timestamp: number) => {\n const roundedTimestamp = Math.ceil(timestamp);\n const days = Math.floor(roundedTimestamp / (60 * 60 * 24));\n const hours = Math.floor((roundedTimestamp % (60 * 60 * 24)) / (60 * 60));\n const minutes = Math.floor((roundedTimestamp % (60 * 60)) / 60);\n const seconds = Math.floor(roundedTimestamp % 60);\n\n return {\n seconds,\n minutes,\n hours,\n days\n };\n};\n\n/** The use timer options type */\nexport interface UseTimerOptions {\n /** Whether the timer should start automatically */\n immediately?: boolean;\n /** The function to be executed when the timer is expired */\n onExpire?: () => void;\n /** The function to be executed when the timer is started */\n onStart?: () => void;\n /** Callback function to be executed on each tick of the timer */\n onTick?: (seconds: number) => void;\n}\n\n/** The use timer return type */\nexport interface UseTimerReturn {\n /** flag to indicate if timer is active or not */\n active: boolean;\n /** The total count of the timer */\n count: number;\n /** The day count of the timer */\n days: number;\n /** The hour count of the timer */\n hours: number;\n /** The minute count of the timer */\n minutes: number;\n /** The second count of the timer */\n seconds: number;\n /** The function to clear the timer */\n clear: () => void;\n /** The function to decrease the timer */\n decrease: (seconds: PositiveInteger<number>) => void;\n /** The function to increase the timer */\n increase: (seconds: PositiveInteger<number>) => void;\n /** The function to pause the timer */\n pause: () => void;\n /** The function to restart the timer */\n restart: (time: PositiveInteger<number>, immediately?: boolean) => void;\n /** The function to resume the timer */\n resume: () => void;\n /** The function to start the timer */\n start: () => void;\n /** The function to toggle the timer */\n toggle: () => void;\n}\n\nexport interface UseTimer {\n (): UseTimerReturn;\n\n (seconds: PositiveInteger<number>, callback: () => void): UseTimerReturn;\n\n (seconds: PositiveInteger<number>, options?: UseTimerOptions): UseTimerReturn;\n}\n\n/**\n * @name useTimer\n * @description - Hook that creates a timer functionality\n * @category Time\n *\n * @overload\n * @returns {UseTimerReturn} An object containing the timer properties and functions\n *\n * @example\n * const { days, hours, minutes, seconds, toggle, pause, start, restart, resume, active, decrease, increase } = useTimer();\n *\n * @overload\n * @param {number} seconds The seconds value that define for how long the timer will be running\n * @param {() => void} callback The function to be executed once countdown timer is expired\n * @returns {UseTimerReturn} An object containing the timer properties and functions\n *\n * @example\n * const { days, hours, minutes, seconds, toggle, pause, start, restart, resume, active, decrease, increase } = useTimer(1000, () => console.log('ready'));\n *\n * @overload\n * @param {number} seconds The seconds value that define for how long the timer will be running\n * @param {boolean} [options.immediately=true] The flag to decide if timer should start automatically\n * @param {() => void} [options.onExpire] The function to be executed when the timer is expired\n * @param {(timestamp: number) => void} [options.onTick] The function to be executed on each tick of the timer\n * @returns {UseTimerReturn} An object containing the timer properties and functions\n *\n * @example\n * const { days, hours, minutes, seconds, toggle, pause, start, restart, resume, active, decrease, increase } = useTimer(1000);\n */\nexport const useTimer = ((...params: any[]) => {\n const initialSeconds = Math.max((params[0] ?? 0) as PositiveInteger<number>, 0);\n const options = (typeof params[1] === 'object' ? params[1] : { onExpire: params[1] }) as\n | UseTimerOptions\n | undefined;\n\n const [active, setActive] = useState(initialSeconds > 0 && (options?.immediately ?? true));\n const [seconds, setSeconds] = useState(initialSeconds);\n\n const intervalIdRef = useRef<ReturnType<typeof setInterval>>(undefined);\n const optionsRef = useRef<UseTimerOptions>(options);\n optionsRef.current = options ?? {};\n\n useDidUpdate(() => {\n if (initialSeconds <= 0) {\n setActive(false);\n setSeconds(0);\n return;\n }\n\n setActive(true);\n setSeconds(initialSeconds);\n }, [initialSeconds]);\n\n useEffect(() => {\n if (!active) return;\n\n optionsRef.current?.onStart?.();\n const onInterval = () => {\n optionsRef.current?.onTick?.(seconds);\n setSeconds((prevSeconds) => {\n const updatedSeconds = prevSeconds - 1;\n if (updatedSeconds === 0) {\n setActive(false);\n optionsRef.current?.onExpire?.();\n }\n return updatedSeconds;\n });\n };\n\n intervalIdRef.current = setInterval(onInterval, 1000);\n return () => {\n clearInterval(intervalIdRef.current);\n };\n }, [active]);\n\n const pause = () => setActive(false);\n const resume = () => {\n if (seconds <= 0) return;\n setActive(true);\n };\n\n const toggle = () => {\n if (seconds <= 0) return;\n setActive(!active);\n };\n\n const restart = (seconds: PositiveInteger<number>, immediately = true) => {\n setSeconds(seconds);\n if (immediately) setActive(true);\n };\n\n const start = () => {\n if (initialSeconds <= 0) return;\n\n setActive(true);\n setSeconds(initialSeconds);\n };\n\n const clear = () => {\n setActive(false);\n setSeconds(0);\n };\n\n const increase = (seconds: PositiveInteger<number>) =>\n setSeconds((prevSeconds) => prevSeconds + seconds);\n const decrease = (seconds: PositiveInteger<number>) => {\n setSeconds((prevSeconds) => {\n const updatedSeconds = prevSeconds - seconds;\n if (updatedSeconds <= 0) {\n setActive(false);\n return 0;\n } else {\n return updatedSeconds;\n }\n });\n };\n\n return {\n ...getTimeFromSeconds(seconds),\n count: seconds,\n pause,\n active,\n resume,\n toggle,\n start,\n restart,\n clear,\n increase,\n decrease\n };\n}) as UseTimer;\n"],"names":["getTimeFromSeconds","timestamp","roundedTimestamp","days","hours","minutes","useTimer","params","initialSeconds","options","active","setActive","useState","seconds","setSeconds","intervalIdRef","useRef","optionsRef","useDidUpdate","useEffect","onInterval","prevSeconds","updatedSeconds","pause","resume","toggle","restart","immediately","start","clear","increase","decrease"],"mappings":"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"}
1
+ {"version":3,"file":"useTimer.mjs","sources":["../../../../src/hooks/useTimer/useTimer.ts"],"sourcesContent":["import { useEffect, useRef, useState } from 'react';\n\nimport { useDidUpdate } from '../useDidUpdate/useDidUpdate';\n\nexport type PositiveInteger<Value extends number> = `${Value}` extends `-${any}` | `${any}.${any}`\n ? never\n : Value;\n\nexport const getTimeFromSeconds = (timestamp: number) => {\n const roundedTimestamp = Math.ceil(timestamp);\n const days = Math.floor(roundedTimestamp / (60 * 60 * 24));\n const hours = Math.floor((roundedTimestamp % (60 * 60 * 24)) / (60 * 60));\n const minutes = Math.floor((roundedTimestamp % (60 * 60)) / 60);\n const seconds = Math.floor(roundedTimestamp % 60);\n\n return {\n seconds,\n minutes,\n hours,\n days\n };\n};\n\n/** The use timer options type */\nexport interface UseTimerOptions {\n /** Whether the timer should start automatically */\n immediately?: boolean;\n /** The function to be executed when the timer is expired */\n onExpire?: () => void;\n /** The function to be executed when the timer is started */\n onStart?: () => void;\n /** Callback function to be executed on each tick of the timer */\n onTick?: (seconds: number) => void;\n}\n\n/** The use timer return type */\nexport interface UseTimerReturn {\n /** flag to indicate if timer is active or not */\n active: boolean;\n /** The total count of the timer */\n count: number;\n /** The day count of the timer */\n days: number;\n /** The hour count of the timer */\n hours: number;\n /** The minute count of the timer */\n minutes: number;\n /** The second count of the timer */\n seconds: number;\n /** The function to clear the timer */\n clear: () => void;\n /** The function to decrease the timer */\n decrease: (seconds: PositiveInteger<number>) => void;\n /** The function to increase the timer */\n increase: (seconds: PositiveInteger<number>) => void;\n /** The function to pause the timer */\n pause: () => void;\n /** The function to restart the timer */\n restart: (time: PositiveInteger<number>, immediately?: boolean) => void;\n /** The function to resume the timer */\n resume: () => void;\n /** The function to start the timer */\n start: () => void;\n /** The function to toggle the timer */\n toggle: () => void;\n}\n\nexport interface UseTimer {\n (): UseTimerReturn;\n\n (seconds: PositiveInteger<number>, callback: () => void): UseTimerReturn;\n\n (seconds: PositiveInteger<number>, options?: UseTimerOptions): UseTimerReturn;\n}\n\n/**\n * @name useTimer\n * @description - Hook that creates a timer functionality\n * @category Time\n *\n * @overload\n * @returns {UseTimerReturn} An object containing the timer properties and functions\n *\n * @example\n * const { days, hours, minutes, seconds, toggle, pause, start, restart, resume, active, decrease, increase } = useTimer();\n *\n * @overload\n * @param {number} seconds The seconds value that define for how long the timer will be running\n * @param {() => void} callback The function to be executed once countdown timer is expired\n * @returns {UseTimerReturn} An object containing the timer properties and functions\n *\n * @example\n * const { days, hours, minutes, seconds, toggle, pause, start, restart, resume, active, decrease, increase } = useTimer(1000, () => console.log('ready'));\n *\n * @overload\n * @param {number} seconds The seconds value that define for how long the timer will be running\n * @param {boolean} [options.immediately=true] The flag to decide if timer should start automatically\n * @param {() => void} [options.onExpire] The function to be executed when the timer is expired\n * @param {(timestamp: number) => void} [options.onTick] The function to be executed on each tick of the timer\n * @returns {UseTimerReturn} An object containing the timer properties and functions\n *\n * @example\n * const { days, hours, minutes, seconds, toggle, pause, start, restart, resume, active, decrease, increase } = useTimer(1000);\n */\nexport const useTimer = ((...params: any[]) => {\n const initialSeconds = Math.max((params[0] ?? 0) as PositiveInteger<number>, 0);\n const options = (typeof params[1] === 'object' ? params[1] : { onExpire: params[1] }) as\n | UseTimerOptions\n | undefined;\n\n const [active, setActive] = useState(initialSeconds > 0 && (options?.immediately ?? true));\n const [seconds, setSeconds] = useState(initialSeconds);\n\n const intervalIdRef = useRef<ReturnType<typeof setInterval>>(undefined);\n const optionsRef = useRef<UseTimerOptions>(options);\n optionsRef.current = options ?? {};\n\n useDidUpdate(() => {\n if (initialSeconds <= 0) {\n setActive(false);\n setSeconds(0);\n return;\n }\n\n setActive(true);\n setSeconds(initialSeconds);\n }, [initialSeconds]);\n\n useEffect(() => {\n if (!active) return;\n\n optionsRef.current?.onStart?.();\n const onInterval = () => {\n setSeconds((prevSeconds) => {\n optionsRef.current?.onTick?.(prevSeconds);\n const updatedSeconds = prevSeconds - 1;\n if (updatedSeconds === 0) {\n setActive(false);\n optionsRef.current?.onExpire?.();\n }\n return updatedSeconds;\n });\n };\n\n intervalIdRef.current = setInterval(onInterval, 1000);\n return () => {\n clearInterval(intervalIdRef.current);\n };\n }, [active]);\n\n const pause = () => setActive(false);\n const resume = () => {\n if (seconds <= 0) return;\n setActive(true);\n };\n\n const toggle = () => {\n if (seconds <= 0) return;\n setActive(!active);\n };\n\n const restart = (seconds: PositiveInteger<number>, immediately = true) => {\n setSeconds(seconds);\n if (immediately) setActive(true);\n };\n\n const start = () => {\n if (initialSeconds <= 0) return;\n\n setActive(true);\n setSeconds(initialSeconds);\n };\n\n const clear = () => {\n setActive(false);\n setSeconds(0);\n };\n\n const increase = (seconds: PositiveInteger<number>) =>\n setSeconds((prevSeconds) => prevSeconds + seconds);\n const decrease = (seconds: PositiveInteger<number>) => {\n setSeconds((prevSeconds) => {\n const updatedSeconds = prevSeconds - seconds;\n if (updatedSeconds <= 0) {\n setActive(false);\n return 0;\n } else {\n return updatedSeconds;\n }\n });\n };\n\n return {\n ...getTimeFromSeconds(seconds),\n count: seconds,\n pause,\n active,\n resume,\n toggle,\n start,\n restart,\n clear,\n increase,\n decrease\n };\n}) as UseTimer;\n"],"names":["getTimeFromSeconds","timestamp","roundedTimestamp","days","hours","minutes","useTimer","params","initialSeconds","options","active","setActive","useState","seconds","setSeconds","intervalIdRef","useRef","optionsRef","useDidUpdate","useEffect","onInterval","prevSeconds","updatedSeconds","pause","resume","toggle","restart","immediately","start","clear","increase","decrease"],"mappings":"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"}
@@ -2,7 +2,7 @@ import { DependencyList, EffectCallback } from 'react';
2
2
  export declare const deepEqual: (a: any, b: any) => boolean;
3
3
  /**
4
4
  * @name useShallowEffect
5
- * @description - Hook that executes an effect only when dependencies change shallowly or deeply.
5
+ * @description - Hook that executes an effect only when dependencies change shallowly or deeply
6
6
  * @category Lifecycle
7
7
  *
8
8
  * @param {EffectCallback} effect The effect callback
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@siberiacancode/reactuse",
3
- "version": "0.2.20",
3
+ "version": "0.2.22",
4
4
  "description": "The ultimate collection of react hooks",
5
5
  "author": {
6
6
  "name": "SIBERIA CAN CODE 🧊",