@siberiacancode/reactuse 0.2.22 → 0.2.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/dist/cjs/hooks/useBattery/useBattery.cjs +1 -1
  2. package/dist/cjs/hooks/useBattery/useBattery.cjs.map +1 -1
  3. package/dist/cjs/hooks/useBroadcastChannel/useBroadcastChannel.cjs +2 -0
  4. package/dist/cjs/hooks/useBroadcastChannel/useBroadcastChannel.cjs.map +1 -0
  5. package/dist/cjs/hooks/useClickOutside/useClickOutside.cjs +1 -1
  6. package/dist/cjs/hooks/useClickOutside/useClickOutside.cjs.map +1 -1
  7. package/dist/cjs/hooks/useDisplayMedia/useDisplayMedia.cjs +1 -1
  8. package/dist/cjs/hooks/useDisplayMedia/useDisplayMedia.cjs.map +1 -1
  9. package/dist/cjs/hooks/useMemory/useMemory.cjs +1 -1
  10. package/dist/cjs/hooks/useMemory/useMemory.cjs.map +1 -1
  11. package/dist/cjs/hooks/useRerender/useRerender.cjs.map +1 -1
  12. package/dist/cjs/hooks/useTextDirection/useTextDirection.cjs +1 -1
  13. package/dist/cjs/hooks/useTextDirection/useTextDirection.cjs.map +1 -1
  14. package/dist/cjs/hooks/useThrottleCallback/useThrottleCallback.cjs +1 -1
  15. package/dist/cjs/hooks/useThrottleCallback/useThrottleCallback.cjs.map +1 -1
  16. package/dist/cjs/hooks/useTime/useTime.cjs +1 -1
  17. package/dist/cjs/hooks/useTime/useTime.cjs.map +1 -1
  18. package/dist/cjs/index.cjs +1 -1
  19. package/dist/esm/hooks/useBattery/useBattery.mjs +8 -8
  20. package/dist/esm/hooks/useBattery/useBattery.mjs.map +1 -1
  21. package/dist/esm/hooks/useBroadcastChannel/useBroadcastChannel.mjs +32 -0
  22. package/dist/esm/hooks/useBroadcastChannel/useBroadcastChannel.mjs.map +1 -0
  23. package/dist/esm/hooks/useClickOutside/useClickOutside.mjs +12 -12
  24. package/dist/esm/hooks/useClickOutside/useClickOutside.mjs.map +1 -1
  25. package/dist/esm/hooks/useDisplayMedia/useDisplayMedia.mjs +23 -25
  26. package/dist/esm/hooks/useDisplayMedia/useDisplayMedia.mjs.map +1 -1
  27. package/dist/esm/hooks/useMemory/useMemory.mjs +9 -8
  28. package/dist/esm/hooks/useMemory/useMemory.mjs.map +1 -1
  29. package/dist/esm/hooks/useRerender/useRerender.mjs.map +1 -1
  30. package/dist/esm/hooks/useTextDirection/useTextDirection.mjs +9 -10
  31. package/dist/esm/hooks/useTextDirection/useTextDirection.mjs.map +1 -1
  32. package/dist/esm/hooks/useThrottleCallback/useThrottleCallback.mjs +11 -11
  33. package/dist/esm/hooks/useThrottleCallback/useThrottleCallback.mjs.map +1 -1
  34. package/dist/esm/hooks/useTime/useTime.mjs +10 -6
  35. package/dist/esm/hooks/useTime/useTime.mjs.map +1 -1
  36. package/dist/esm/index.mjs +321 -319
  37. package/dist/esm/index.mjs.map +1 -1
  38. package/dist/types/hooks/index.d.ts +1 -0
  39. package/dist/types/hooks/useBroadcastChannel/useBroadcastChannel.d.ts +32 -0
  40. package/dist/types/hooks/useTime/useTime.d.ts +8 -0
  41. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"useDisplayMedia.mjs","sources":["../../../../src/hooks/useDisplayMedia/useDisplayMedia.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 display media return type */\nexport interface UseDisplayMediaReturn {\n /** Whether screen sharing is currently active */\n sharing: boolean;\n /** The media stream object */\n stream: MediaStream | null;\n /** Whether the display media API is supported */\n supported: boolean;\n /** Start screen sharing */\n start: () => Promise<void>;\n /** Stop screen sharing */\n stop: () => void;\n}\n\n/** The use display media options type */\nexport interface UseDisplayMediaOptions {\n /** Whether to enable audio sharing */\n audio?: boolean | MediaTrackConstraints;\n /** Whether to start immediately */\n immediately?: boolean;\n /** Whether to enable video sharing */\n video?: boolean | MediaTrackConstraints;\n}\n\nexport interface UseDisplayMedia {\n (target: HookTarget, options?: UseDisplayMediaOptions): UseDisplayMediaReturn;\n\n <Target extends HTMLVideoElement>(\n options?: UseDisplayMediaOptions,\n target?: never\n ): { ref: StateRef<Target> } & UseDisplayMediaReturn;\n}\n\n/**\n * @name useDisplayMedia\n * @description - Hook that provides screen sharing functionality\n * @category Browser\n *\n * @browserapi mediaDevices.getDisplayMedia https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getDisplayMedia\n *\n * @overload\n * @param {HookTarget} target The target video element to display the media stream\n * @param {boolean | MediaTrackConstraints} [options.audio] Whether to enable audio sharing\n * @param {boolean} [options.immediately=false] Whether to start immediately\n * @param {boolean | MediaTrackConstraints} [options.video] Whether to enable video sharing\n * @returns {UseDisplayMediaReturn} Object containing stream, sharing status and control methods\n *\n * @example\n * const { stream, sharing, start, stop } = useDisplayMedia(ref);\n *\n * @overload\n * @template Target The target video element\n * @param {boolean | MediaTrackConstraints} [options.audio] Whether to enable audio sharing\n * @param {boolean} [options.immediately=false] Whether to start immediately\n * @param {boolean | MediaTrackConstraints} [options.video] Whether to enable video sharing\n * @returns {UseDisplayMediaReturn & { ref: StateRef<HTMLVideoElement> }} Object containing stream, sharing status, control methods and ref\n *\n * @example\n * const { ref, stream, sharing, start, stop } = useDisplayMedia<HTMLVideoElement>();\n */\nexport const useDisplayMedia = ((...params: any[]) => {\n const supported =\n typeof navigator !== 'undefined' &&\n 'mediaDevices' in navigator &&\n !!navigator.mediaDevices &&\n 'getDisplayMedia' in navigator.mediaDevices;\n const target = (isTarget(params[0]) ? params[0] : undefined) as HookTarget | undefined;\n const options = (params[1] ? params[1] : params[0]) as UseDisplayMediaOptions | undefined;\n const immediately = options?.immediately ?? false;\n\n const [sharing, setSharing] = useState(false);\n\n const streamRef = useRef<MediaStream | null>(null);\n const internalRef = useRefState<Element>();\n\n const stop = () => {\n if (!streamRef.current || !supported) return;\n\n const element = (target ? getElement(target) : internalRef.current) as HTMLVideoElement;\n if (!element) return;\n\n setSharing(false);\n element.srcObject = null;\n streamRef.current.getTracks().forEach((track) => track.stop());\n streamRef.current = null;\n };\n\n const start = async () => {\n if (!supported) return;\n\n const element = (target ? getElement(target) : internalRef.current) as HTMLVideoElement;\n if (!element) return;\n\n const displayMedia = await navigator.mediaDevices.getDisplayMedia({\n video: options?.video,\n audio: options?.audio\n });\n\n setSharing(true);\n streamRef.current = displayMedia;\n element.srcObject = displayMedia;\n\n displayMedia.getTracks().forEach((track) => (track.onended = stop));\n return displayMedia;\n };\n\n useEffect(() => {\n if (!supported || !immediately) return;\n if (!target && !internalRef.state) return;\n\n const element = (target ? getElement(target) : internalRef.current) as HTMLVideoElement;\n if (!element) return;\n\n start();\n\n return () => {\n stop();\n };\n }, [target, internalRef.state]);\n\n if (target)\n return {\n stream: streamRef.current,\n sharing,\n supported,\n start,\n stop\n };\n\n return {\n stream: streamRef.current,\n sharing,\n supported,\n start,\n stop,\n ref: internalRef\n };\n}) as UseDisplayMedia;\n"],"names":["useDisplayMedia","params","supported","target","isTarget","options","immediately","sharing","setSharing","useState","streamRef","useRef","internalRef","useRefState","stop","element","getElement","track","start","displayMedia","useEffect"],"mappings":";;;;AAsEO,MAAMA,IAAmB,IAAIC,MAAkB;AACpD,QAAMC,IACJ,OAAO,YAAc,OACrB,kBAAkB,aAClB,CAAC,CAAC,UAAU,gBACZ,qBAAqB,UAAU,cAC3BC,IAAUC,EAASH,EAAO,CAAC,CAAC,IAAIA,EAAO,CAAC,IAAI,QAC5CI,IAAWJ,EAAO,CAAC,IAAIA,EAAO,CAAC,IAAIA,EAAO,CAAC,GAC3CK,IAAcD,GAAS,eAAe,IAEtC,CAACE,GAASC,CAAU,IAAIC,EAAS,EAAK,GAEtCC,IAAYC,EAA2B,IAAI,GAC3CC,IAAcC,EAAA,GAEdC,IAAO,MAAM;AACjB,QAAI,CAACJ,EAAU,WAAW,CAACR,EAAW;AAEtC,UAAMa,IAAWZ,IAASa,EAAWb,CAAM,IAAIS,EAAY;AAC3D,IAAKG,MAELP,EAAW,EAAK,GAChBO,EAAQ,YAAY,MACpBL,EAAU,QAAQ,YAAY,QAAQ,CAACO,MAAUA,EAAM,MAAM,GAC7DP,EAAU,UAAU;AAAA,EAAA,GAGhBQ,IAAQ,YAAY;AACxB,QAAI,CAAChB,EAAW;AAEhB,UAAMa,IAAWZ,IAASa,EAAWb,CAAM,IAAIS,EAAY;AAC3D,QAAI,CAACG,EAAS;AAEd,UAAMI,IAAe,MAAM,UAAU,aAAa,gBAAgB;AAAA,MAChE,OAAOd,GAAS;AAAA,MAChB,OAAOA,GAAS;AAAA,IAAA,CACjB;AAED,WAAAG,EAAW,EAAI,GACfE,EAAU,UAAUS,GACpBJ,EAAQ,YAAYI,GAEpBA,EAAa,YAAY,QAAQ,CAACF,MAAWA,EAAM,UAAUH,CAAK,GAC3DK;AAAA,EAAA;AAiBT,SAdAC,EAAU,MAAM;AAKd,QAJI,GAAClB,KAAa,CAACI,KACf,CAACH,KAAU,CAACS,EAAY,SAGxB,EADaT,IAASa,EAAWb,CAAM,IAAIS,EAAY;AAG3D,aAAAM,EAAA,GAEO,MAAM;AACX,QAAAJ,EAAA;AAAA,MAAK;AAAA,EACP,GACC,CAACX,GAAQS,EAAY,KAAK,CAAC,GAE1BT,IACK;AAAA,IACL,QAAQO,EAAU;AAAA,IAClB,SAAAH;AAAA,IACA,WAAAL;AAAA,IACA,OAAAgB;AAAA,IACA,MAAAJ;AAAA,EAAA,IAGG;AAAA,IACL,QAAQJ,EAAU;AAAA,IAClB,SAAAH;AAAA,IACA,WAAAL;AAAA,IACA,OAAAgB;AAAA,IACA,MAAAJ;AAAA,IACA,KAAKF;AAAA,EAAA;AAET;"}
1
+ {"version":3,"file":"useDisplayMedia.mjs","sources":["../../../../src/hooks/useDisplayMedia/useDisplayMedia.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 display media return type */\nexport interface UseDisplayMediaReturn {\n /** Whether screen sharing is currently active */\n sharing: boolean;\n /** The media stream object */\n stream: MediaStream | null;\n /** Whether the display media API is supported */\n supported: boolean;\n /** Start screen sharing */\n start: () => Promise<void>;\n /** Stop screen sharing */\n stop: () => void;\n}\n\n/** The use display media options type */\nexport interface UseDisplayMediaOptions {\n /** Whether to enable audio sharing */\n audio?: boolean | MediaTrackConstraints;\n /** Whether to start immediately */\n immediately?: boolean;\n /** Whether to enable video sharing */\n video?: boolean | MediaTrackConstraints;\n}\n\nexport interface UseDisplayMedia {\n (target: HookTarget, options?: UseDisplayMediaOptions): UseDisplayMediaReturn;\n\n <Target extends HTMLVideoElement>(\n options?: UseDisplayMediaOptions,\n target?: never\n ): { ref: StateRef<Target> } & UseDisplayMediaReturn;\n}\n\n/**\n * @name useDisplayMedia\n * @description - Hook that provides screen sharing functionality\n * @category Browser\n *\n * @browserapi mediaDevices.getDisplayMedia https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getDisplayMedia\n *\n * @overload\n * @param {HookTarget} target The target video element to display the media stream\n * @param {boolean | MediaTrackConstraints} [options.audio] Whether to enable audio sharing\n * @param {boolean} [options.immediately=false] Whether to start immediately\n * @param {boolean | MediaTrackConstraints} [options.video] Whether to enable video sharing\n * @returns {UseDisplayMediaReturn} Object containing stream, sharing status and control methods\n *\n * @example\n * const { stream, sharing, start, stop } = useDisplayMedia(ref);\n *\n * @overload\n * @template Target The target video element\n * @param {boolean | MediaTrackConstraints} [options.audio] Whether to enable audio sharing\n * @param {boolean} [options.immediately=false] Whether to start immediately\n * @param {boolean | MediaTrackConstraints} [options.video] Whether to enable video sharing\n * @returns {UseDisplayMediaReturn & { ref: StateRef<HTMLVideoElement> }} Object containing stream, sharing status, control methods and ref\n *\n * @example\n * const { ref, stream, sharing, start, stop } = useDisplayMedia<HTMLVideoElement>();\n */\nexport const useDisplayMedia = ((...params: any[]) => {\n const supported =\n typeof navigator !== 'undefined' &&\n 'mediaDevices' in navigator &&\n !!navigator.mediaDevices &&\n 'getDisplayMedia' in navigator.mediaDevices;\n const target = (isTarget(params[0]) ? params[0] : undefined) as HookTarget | undefined;\n const options = (params[1] ? params[1] : params[0]) as UseDisplayMediaOptions | undefined;\n const immediately = options?.immediately ?? false;\n\n const [sharing, setSharing] = useState(false);\n\n const elementRef = useRef<HTMLVideoElement | null>(null);\n const streamRef = useRef<MediaStream | null>(null);\n const internalRef = useRefState<Element>();\n\n const stop = () => {\n if (!streamRef.current || !supported || !elementRef.current) return;\n\n setSharing(false);\n elementRef.current.srcObject = null;\n streamRef.current.getTracks().forEach((track) => track.stop());\n streamRef.current = null;\n };\n\n const start = async () => {\n if (!supported || !elementRef.current) return;\n\n const displayMedia = await navigator.mediaDevices.getDisplayMedia({\n video: options?.video,\n audio: options?.audio\n });\n\n setSharing(true);\n streamRef.current = displayMedia;\n elementRef.current.srcObject = displayMedia;\n\n displayMedia.getTracks().forEach((track) => (track.onended = stop));\n return displayMedia;\n };\n\n useEffect(() => {\n if (!supported || (!target && !internalRef.state)) return;\n\n const element = (target ? getElement(target) : internalRef.current) as HTMLVideoElement;\n\n if (!element) return;\n\n elementRef.current = element;\n\n if (!immediately) return;\n\n start();\n\n return () => {\n stop();\n };\n }, [target, internalRef.state]);\n\n if (target)\n return {\n stream: streamRef.current,\n sharing,\n supported,\n start,\n stop\n };\n\n return {\n stream: streamRef.current,\n sharing,\n supported,\n start,\n stop,\n ref: internalRef\n };\n}) as UseDisplayMedia;\n"],"names":["useDisplayMedia","params","supported","target","isTarget","options","immediately","sharing","setSharing","useState","elementRef","useRef","streamRef","internalRef","useRefState","stop","track","start","displayMedia","useEffect","element","getElement"],"mappings":";;;;AAsEO,MAAMA,IAAmB,IAAIC,MAAkB;AACpD,QAAMC,IACJ,OAAO,YAAc,OACrB,kBAAkB,aAClB,CAAC,CAAC,UAAU,gBACZ,qBAAqB,UAAU,cAC3BC,IAAUC,EAASH,EAAO,CAAC,CAAC,IAAIA,EAAO,CAAC,IAAI,QAC5CI,IAAWJ,EAAO,CAAC,IAAIA,EAAO,CAAC,IAAIA,EAAO,CAAC,GAC3CK,IAAcD,GAAS,eAAe,IAEtC,CAACE,GAASC,CAAU,IAAIC,EAAS,EAAK,GAEtCC,IAAaC,EAAgC,IAAI,GACjDC,IAAYD,EAA2B,IAAI,GAC3CE,IAAcC,EAAA,GAEdC,IAAO,MAAM;AACjB,IAAI,CAACH,EAAU,WAAW,CAACV,KAAa,CAACQ,EAAW,YAEpDF,EAAW,EAAK,GAChBE,EAAW,QAAQ,YAAY,MAC/BE,EAAU,QAAQ,YAAY,QAAQ,CAACI,MAAUA,EAAM,MAAM,GAC7DJ,EAAU,UAAU;AAAA,EAAA,GAGhBK,IAAQ,YAAY;AACxB,QAAI,CAACf,KAAa,CAACQ,EAAW,QAAS;AAEvC,UAAMQ,IAAe,MAAM,UAAU,aAAa,gBAAgB;AAAA,MAChE,OAAOb,GAAS;AAAA,MAChB,OAAOA,GAAS;AAAA,IAAA,CACjB;AAED,WAAAG,EAAW,EAAI,GACfI,EAAU,UAAUM,GACpBR,EAAW,QAAQ,YAAYQ,GAE/BA,EAAa,YAAY,QAAQ,CAACF,MAAWA,EAAM,UAAUD,CAAK,GAC3DG;AAAA,EAAA;AAqBT,SAlBAC,EAAU,MAAM;AACd,QAAI,CAACjB,KAAc,CAACC,KAAU,CAACU,EAAY,MAAQ;AAEnD,UAAMO,IAAWjB,IAASkB,EAAWlB,CAAM,IAAIU,EAAY;AAE3D,QAAKO,MAELV,EAAW,UAAUU,GAEjB,EAACd;AAEL,aAAAW,EAAA,GAEO,MAAM;AACX,QAAAF,EAAA;AAAA,MAAK;AAAA,EACP,GACC,CAACZ,GAAQU,EAAY,KAAK,CAAC,GAE1BV,IACK;AAAA,IACL,QAAQS,EAAU;AAAA,IAClB,SAAAL;AAAA,IACA,WAAAL;AAAA,IACA,OAAAe;AAAA,IACA,MAAAF;AAAA,EAAA,IAGG;AAAA,IACL,QAAQH,EAAU;AAAA,IAClB,SAAAL;AAAA,IACA,WAAAL;AAAA,IACA,OAAAe;AAAA,IACA,MAAAF;AAAA,IACA,KAAKF;AAAA,EAAA;AAET;"}
@@ -1,18 +1,19 @@
1
- import { useState as o } from "react";
2
- import { useInterval as t } from "../useInterval/useInterval.mjs";
3
- const n = () => {
4
- const e = performance && "memory" in performance && !!performance.memory, [r, m] = o(
1
+ import { useState as m, useEffect as a } from "react";
2
+ const p = () => {
3
+ const e = performance && "memory" in performance && !!performance.memory, [r, t] = m(
5
4
  performance?.memory ?? {
6
5
  jsHeapSizeLimit: 0,
7
6
  totalJSHeapSize: 0,
8
7
  usedJSHeapSize: 0
9
8
  }
10
9
  );
11
- return t(() => m(performance.memory), 1e3, {
12
- immediately: e
13
- }), { supported: e, value: r };
10
+ return a(() => {
11
+ if (!e) return;
12
+ const o = setInterval(() => t(performance.memory), 1e3);
13
+ return () => clearInterval(o);
14
+ }, []), { supported: e, value: r };
14
15
  };
15
16
  export {
16
- n as useMemory
17
+ p as useMemory
17
18
  };
18
19
  //# sourceMappingURL=useMemory.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"useMemory.mjs","sources":["../../../../src/hooks/useMemory/useMemory.ts"],"sourcesContent":["import { useState } from 'react';\n\nimport { useInterval } from '../useInterval/useInterval';\n\ndeclare global {\n interface Performance {\n memory: {\n readonly jsHeapSizeLimit: number;\n readonly totalJSHeapSize: number;\n readonly usedJSHeapSize: number;\n };\n }\n}\n\n/** The use memory return type */\nexport interface UseMemoryReturn {\n /** The memory supported status */\n supported: boolean;\n /** The current memory usage */\n value: Performance['memory'];\n}\n\n/**\n * @name useMemory\n * @description - Hook that gives you current memory usage\n * @category Browser\n *\n * @browserapi performance.memory https://developer.mozilla.org/en-US/docs/Web/API/Performance/memory\n *\n * @returns {UseMemoryReturn} An object containing the current memory usage\n *\n * @example\n * const { supported, value } = useMemory();\n */\nexport const useMemory = (): UseMemoryReturn => {\n const supported = performance && 'memory' in performance && !!performance.memory;\n const [value, setValue] = useState<Performance['memory']>(\n performance?.memory ?? {\n jsHeapSizeLimit: 0,\n totalJSHeapSize: 0,\n usedJSHeapSize: 0\n }\n );\n\n useInterval(() => setValue(performance.memory), 1000, {\n immediately: supported\n });\n\n return { supported, value };\n};\n"],"names":["useMemory","supported","value","setValue","useState","useInterval"],"mappings":";;AAkCO,MAAMA,IAAY,MAAuB;AAC9C,QAAMC,IAAY,eAAe,YAAY,eAAe,CAAC,CAAC,YAAY,QACpE,CAACC,GAAOC,CAAQ,IAAIC;AAAA,IACxB,aAAa,UAAU;AAAA,MACrB,iBAAiB;AAAA,MACjB,iBAAiB;AAAA,MACjB,gBAAgB;AAAA,IAAA;AAAA,EAClB;AAGF,SAAAC,EAAY,MAAMF,EAAS,YAAY,MAAM,GAAG,KAAM;AAAA,IACpD,aAAaF;AAAA,EAAA,CACd,GAEM,EAAE,WAAAA,GAAW,OAAAC,EAAA;AACtB;"}
1
+ {"version":3,"file":"useMemory.mjs","sources":["../../../../src/hooks/useMemory/useMemory.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\ndeclare global {\n interface Performance {\n memory: {\n readonly jsHeapSizeLimit: number;\n readonly totalJSHeapSize: number;\n readonly usedJSHeapSize: number;\n };\n }\n}\n\n/** The use memory return type */\nexport interface UseMemoryReturn {\n /** The memory supported status */\n supported: boolean;\n /** The current memory usage */\n value: Performance['memory'];\n}\n\n/**\n * @name useMemory\n * @description - Hook that gives you current memory usage\n * @category Browser\n *\n * @browserapi performance.memory https://developer.mozilla.org/en-US/docs/Web/API/Performance/memory\n *\n * @returns {UseMemoryReturn} An object containing the current memory usage\n *\n * @example\n * const { supported, value } = useMemory();\n */\nexport const useMemory = (): UseMemoryReturn => {\n const supported = performance && 'memory' in performance && !!performance.memory;\n const [value, setValue] = useState<Performance['memory']>(\n performance?.memory ?? {\n jsHeapSizeLimit: 0,\n totalJSHeapSize: 0,\n usedJSHeapSize: 0\n }\n );\n\n useEffect(() => {\n if (!supported) return;\n\n const intervalId = setInterval(() => setValue(performance.memory), 1000);\n\n return () => clearInterval(intervalId);\n }, []);\n\n return { supported, value };\n};\n"],"names":["useMemory","supported","value","setValue","useState","useEffect","intervalId"],"mappings":";AAgCO,MAAMA,IAAY,MAAuB;AAC9C,QAAMC,IAAY,eAAe,YAAY,eAAe,CAAC,CAAC,YAAY,QACpE,CAACC,GAAOC,CAAQ,IAAIC;AAAA,IACxB,aAAa,UAAU;AAAA,MACrB,iBAAiB;AAAA,MACjB,iBAAiB;AAAA,MACjB,gBAAgB;AAAA,IAAA;AAAA,EAClB;AAGF,SAAAC,EAAU,MAAM;AACd,QAAI,CAACJ,EAAW;AAEhB,UAAMK,IAAa,YAAY,MAAMH,EAAS,YAAY,MAAM,GAAG,GAAI;AAEvE,WAAO,MAAM,cAAcG,CAAU;AAAA,EAAA,GACpC,EAAE,GAEE,EAAE,WAAAL,GAAW,OAAAC,EAAA;AACtB;"}
@@ -1 +1 @@
1
- {"version":3,"file":"useRerender.mjs","sources":["../../../../src/hooks/useRerender/useRerender.ts"],"sourcesContent":["import { useReducer } from 'react';\n\n/** The use rerender return type */\ntype UseRerenderReturn = () => void;\n\n/**\n * @name useRerender\n * @description - Hook that defines the logic to force rerender a component\n * @category Lifecycle\n *\n * @returns {UseRerenderReturn} The rerender function\n *\n * @example\n * const rerender = useRerender();\n */\nexport const useRerender = (): UseRerenderReturn => {\n const rerender = useReducer(() => ({}), {})[1];\n return rerender;\n};\n"],"names":["useRerender","useReducer"],"mappings":";AAeO,MAAMA,IAAc,MACRC,EAAW,OAAO,CAAA,IAAK,CAAA,CAAE,EAAE,CAAC;"}
1
+ {"version":3,"file":"useRerender.mjs","sources":["../../../../src/hooks/useRerender/useRerender.ts"],"sourcesContent":["import { useReducer } from 'react';\n\n/** The use rerender return type */\ntype UseRerenderReturn = () => void;\n\n/**\n * @name useRerender\n * @description - Hook that defines the logic to force rerender a component\n * @category Lifecycle\n *\n * @returns {UseRerenderReturn} The rerender function\n *\n * @example\n * const rerender = useRerender();\n */\nexport const useRerender = (): UseRerenderReturn => useReducer(() => ({}), {})[1];\n"],"names":["useRerender","useReducer"],"mappings":";AAeO,MAAMA,IAAc,MAAyBC,EAAW,OAAO,CAAA,IAAK,CAAA,CAAE,EAAE,CAAC;"}
@@ -1,17 +1,16 @@
1
- import { useState as a } from "react";
2
- import { useIsomorphicLayoutEffect as d } from "../useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.mjs";
1
+ import { useState as d, useEffect as a } from "react";
3
2
  import { useRefState as v } from "../useRefState/useRefState.mjs";
4
3
  import { isTarget as g } from "../../utils/helpers/isTarget.mjs";
5
4
  import { getElement as i } from "../../utils/helpers/getElement.mjs";
6
- const R = (...o) => {
7
- const t = g(o[0]) ? o[0] : void 0, b = (t ? o[1] : o[0]) ?? "ltr", r = v(), s = () => (t ? i(t) : r.current)?.getAttribute("dir") ?? b, [u, c] = a(s()), m = () => {
5
+ const E = (...o) => {
6
+ const t = g(o[0]) ? o[0] : void 0, b = (t ? o[1] : o[0]) ?? "ltr", r = v(), s = () => (t ? i(t) : r.current)?.getAttribute("dir") ?? b, [u, c] = d(s()), f = () => {
8
7
  const e = t ? i(t) : r.current;
9
8
  e && e?.removeAttribute("dir");
10
- }, f = (e) => {
9
+ }, m = (e) => {
11
10
  const n = t ? i(t) : r.current;
12
11
  n && (c(e), n.setAttribute("dir", e));
13
12
  };
14
- return d(() => {
13
+ return a(() => {
15
14
  if (!t && !r.state) return;
16
15
  const e = t ? i(t) : r.current;
17
16
  if (!e) return;
@@ -21,14 +20,14 @@ const R = (...o) => {
21
20
  return l.observe(e, { attributes: !0 }), () => {
22
21
  l.disconnect();
23
22
  };
24
- }, [r.state, t]), t ? { value: u, set: f, remove: m } : {
23
+ }, [r.state, t]), t ? { value: u, set: m, remove: f } : {
25
24
  ref: r,
26
25
  value: u,
27
- set: f,
28
- remove: m
26
+ set: m,
27
+ remove: f
29
28
  };
30
29
  };
31
30
  export {
32
- R as useTextDirection
31
+ E as useTextDirection
33
32
  };
34
33
  //# sourceMappingURL=useTextDirection.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"useTextDirection.mjs","sources":["../../../../src/hooks/useTextDirection/useTextDirection.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 { useIsomorphicLayoutEffect } from '../useIsomorphicLayoutEffect/useIsomorphicLayoutEffect';\nimport { useRefState } from '../useRefState/useRefState';\n\n/** The use text direction value type */\nexport type UseTextDirectionValue = 'auto' | 'ltr' | 'rtl';\n\n/** The use text direction return type */\nexport interface UseTextDirectionReturn {\n /** The current direction */\n value: UseTextDirectionValue;\n /*** The function to remove the direction */\n remove: () => void;\n /*** The function to set the direction */\n set: (value: UseTextDirectionValue | null) => void;\n}\n\nexport interface UseTextDirection {\n (target: HookTarget, initialValue?: UseTextDirectionValue): UseTextDirectionReturn;\n\n <Target extends Element>(\n initialValue?: UseTextDirectionValue,\n target?: never\n ): UseTextDirectionReturn & { ref: StateRef<Target> };\n}\n\n/**\n * @name useTextDirection\n * @description - Hook that can get and set the direction of the element\n * @category Browser\n *\n * @overload\n * @param {HookTarget} target The target element to observe\n * @param {UseTextDirectionValue} [initialValue = 'ltr'] The initial direction of the element\n * @returns {UseTextDirectionReturn} An object containing the current text direction of the element\n *\n * @example\n * const { value, set, remove } = useTextDirection(ref);\n *\n * @overload\n * @template Target The target element type\n * @param {UseTextDirectionValue} [initialValue = 'ltr'] The initial direction of the element\n * @returns { { ref: StateRef<Target> } & UseTextDirectionReturn } An object containing the current text direction of the element\n *\n * @example\n * const { ref, value, set, remove } = useTextDirection();\n */\nexport const useTextDirection = ((...params: any[]) => {\n const target = (isTarget(params[0]) ? params[0] : undefined) as HookTarget | undefined;\n const initialValue = ((target ? params[1] : params[0]) as UseTextDirectionValue) ?? 'ltr';\n\n const internalRef = useRefState<Element>();\n\n const getDirection = () => {\n const element = (target ? getElement(target) : internalRef.current) as Element;\n return (element?.getAttribute('dir') as UseTextDirectionValue) ?? initialValue;\n };\n\n const [value, setValue] = useState<UseTextDirectionValue>(getDirection());\n\n const remove = () => {\n const element = (target ? getElement(target) : internalRef.current) as Element;\n if (!element) return;\n\n element?.removeAttribute('dir');\n };\n\n const set = (value: UseTextDirectionValue) => {\n const element = (target ? getElement(target) : internalRef.current) as Element;\n if (!element) return;\n\n setValue(value);\n element.setAttribute('dir', value);\n };\n\n useIsomorphicLayoutEffect(() => {\n if (!target && !internalRef.state) return;\n\n const element = (target ? getElement(target) : internalRef.current) as Element;\n if (!element) return;\n\n const direction = getDirection();\n element.setAttribute('dir', direction);\n setValue(direction);\n\n const observer = new MutationObserver(getDirection);\n\n observer.observe(element, { attributes: true });\n\n return () => {\n observer.disconnect();\n };\n }, [internalRef.state, target]);\n\n if (target) return { value, set, remove };\n return {\n ref: internalRef,\n value,\n set,\n remove\n };\n}) as UseTextDirection;\n"],"names":["useTextDirection","params","target","isTarget","initialValue","internalRef","useRefState","getDirection","getElement","value","setValue","useState","remove","element","set","useIsomorphicLayoutEffect","direction","observer"],"mappings":";;;;;AAsDO,MAAMA,IAAoB,IAAIC,MAAkB;AACrD,QAAMC,IAAUC,EAASF,EAAO,CAAC,CAAC,IAAIA,EAAO,CAAC,IAAI,QAC5CG,KAAiBF,IAASD,EAAO,CAAC,IAAIA,EAAO,CAAC,MAAgC,OAE9EI,IAAcC,EAAA,GAEdC,IAAe,OACFL,IAASM,EAAWN,CAAM,IAAIG,EAAY,UAC1C,aAAa,KAAK,KAA+BD,GAG9D,CAACK,GAAOC,CAAQ,IAAIC,EAAgCJ,GAAc,GAElEK,IAAS,MAAM;AACnB,UAAMC,IAAWX,IAASM,EAAWN,CAAM,IAAIG,EAAY;AAC3D,IAAKQ,KAELA,GAAS,gBAAgB,KAAK;AAAA,EAAA,GAG1BC,IAAM,CAACL,MAAiC;AAC5C,UAAMI,IAAWX,IAASM,EAAWN,CAAM,IAAIG,EAAY;AAC3D,IAAKQ,MAELH,EAASD,CAAK,GACdI,EAAQ,aAAa,OAAOJ,CAAK;AAAA,EAAA;AAsBnC,SAnBAM,EAA0B,MAAM;AAC9B,QAAI,CAACb,KAAU,CAACG,EAAY,MAAO;AAEnC,UAAMQ,IAAWX,IAASM,EAAWN,CAAM,IAAIG,EAAY;AAC3D,QAAI,CAACQ,EAAS;AAEd,UAAMG,IAAYT,EAAA;AAClB,IAAAM,EAAQ,aAAa,OAAOG,CAAS,GACrCN,EAASM,CAAS;AAElB,UAAMC,IAAW,IAAI,iBAAiBV,CAAY;AAElD,WAAAU,EAAS,QAAQJ,GAAS,EAAE,YAAY,IAAM,GAEvC,MAAM;AACX,MAAAI,EAAS,WAAA;AAAA,IAAW;AAAA,EACtB,GACC,CAACZ,EAAY,OAAOH,CAAM,CAAC,GAE1BA,IAAe,EAAE,OAAAO,GAAO,KAAAK,GAAK,QAAAF,EAAA,IAC1B;AAAA,IACL,KAAKP;AAAA,IACL,OAAAI;AAAA,IACA,KAAAK;AAAA,IACA,QAAAF;AAAA,EAAA;AAEJ;"}
1
+ {"version":3,"file":"useTextDirection.mjs","sources":["../../../../src/hooks/useTextDirection/useTextDirection.ts"],"sourcesContent":["import { useEffect, 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 text direction value type */\nexport type UseTextDirectionValue = 'auto' | 'ltr' | 'rtl';\n\n/** The use text direction return type */\nexport interface UseTextDirectionReturn {\n /** The current direction */\n value: UseTextDirectionValue;\n /*** The function to remove the direction */\n remove: () => void;\n /*** The function to set the direction */\n set: (value: UseTextDirectionValue | null) => void;\n}\n\nexport interface UseTextDirection {\n (target: HookTarget, initialValue?: UseTextDirectionValue): UseTextDirectionReturn;\n\n <Target extends Element>(\n initialValue?: UseTextDirectionValue,\n target?: never\n ): UseTextDirectionReturn & { ref: StateRef<Target> };\n}\n\n/**\n * @name useTextDirection\n * @description - Hook that can get and set the direction of the element\n * @category Browser\n *\n * @overload\n * @param {HookTarget} target The target element to observe\n * @param {UseTextDirectionValue} [initialValue = 'ltr'] The initial direction of the element\n * @returns {UseTextDirectionReturn} An object containing the current text direction of the element\n *\n * @example\n * const { value, set, remove } = useTextDirection(ref);\n *\n * @overload\n * @template Target The target element type\n * @param {UseTextDirectionValue} [initialValue = 'ltr'] The initial direction of the element\n * @returns { { ref: StateRef<Target> } & UseTextDirectionReturn } An object containing the current text direction of the element\n *\n * @example\n * const { ref, value, set, remove } = useTextDirection();\n */\nexport const useTextDirection = ((...params: any[]) => {\n const target = (isTarget(params[0]) ? params[0] : undefined) as HookTarget | undefined;\n const initialValue = ((target ? params[1] : params[0]) as UseTextDirectionValue) ?? 'ltr';\n\n const internalRef = useRefState<Element>();\n\n const getDirection = () => {\n const element = (target ? getElement(target) : internalRef.current) as Element;\n return (element?.getAttribute('dir') as UseTextDirectionValue) ?? initialValue;\n };\n\n const [value, setValue] = useState<UseTextDirectionValue>(getDirection());\n\n const remove = () => {\n const element = (target ? getElement(target) : internalRef.current) as Element;\n if (!element) return;\n\n element?.removeAttribute('dir');\n };\n\n const set = (value: UseTextDirectionValue) => {\n const element = (target ? getElement(target) : internalRef.current) as Element;\n if (!element) return;\n\n setValue(value);\n element.setAttribute('dir', value);\n };\n\n useEffect(() => {\n if (!target && !internalRef.state) return;\n\n const element = (target ? getElement(target) : internalRef.current) as Element;\n if (!element) return;\n\n const direction = getDirection();\n element.setAttribute('dir', direction);\n setValue(direction);\n\n const observer = new MutationObserver(getDirection);\n\n observer.observe(element, { attributes: true });\n\n return () => {\n observer.disconnect();\n };\n }, [internalRef.state, target]);\n\n if (target) return { value, set, remove };\n return {\n ref: internalRef,\n value,\n set,\n remove\n };\n}) as UseTextDirection;\n"],"names":["useTextDirection","params","target","isTarget","initialValue","internalRef","useRefState","getDirection","getElement","value","setValue","useState","remove","element","set","useEffect","direction","observer"],"mappings":";;;;AAqDO,MAAMA,IAAoB,IAAIC,MAAkB;AACrD,QAAMC,IAAUC,EAASF,EAAO,CAAC,CAAC,IAAIA,EAAO,CAAC,IAAI,QAC5CG,KAAiBF,IAASD,EAAO,CAAC,IAAIA,EAAO,CAAC,MAAgC,OAE9EI,IAAcC,EAAA,GAEdC,IAAe,OACFL,IAASM,EAAWN,CAAM,IAAIG,EAAY,UAC1C,aAAa,KAAK,KAA+BD,GAG9D,CAACK,GAAOC,CAAQ,IAAIC,EAAgCJ,GAAc,GAElEK,IAAS,MAAM;AACnB,UAAMC,IAAWX,IAASM,EAAWN,CAAM,IAAIG,EAAY;AAC3D,IAAKQ,KAELA,GAAS,gBAAgB,KAAK;AAAA,EAAA,GAG1BC,IAAM,CAACL,MAAiC;AAC5C,UAAMI,IAAWX,IAASM,EAAWN,CAAM,IAAIG,EAAY;AAC3D,IAAKQ,MAELH,EAASD,CAAK,GACdI,EAAQ,aAAa,OAAOJ,CAAK;AAAA,EAAA;AAsBnC,SAnBAM,EAAU,MAAM;AACd,QAAI,CAACb,KAAU,CAACG,EAAY,MAAO;AAEnC,UAAMQ,IAAWX,IAASM,EAAWN,CAAM,IAAIG,EAAY;AAC3D,QAAI,CAACQ,EAAS;AAEd,UAAMG,IAAYT,EAAA;AAClB,IAAAM,EAAQ,aAAa,OAAOG,CAAS,GACrCN,EAASM,CAAS;AAElB,UAAMC,IAAW,IAAI,iBAAiBV,CAAY;AAElD,WAAAU,EAAS,QAAQJ,GAAS,EAAE,YAAY,IAAM,GAEvC,MAAM;AACX,MAAAI,EAAS,WAAA;AAAA,IAAW;AAAA,EACtB,GACC,CAACZ,EAAY,OAAOH,CAAM,CAAC,GAE1BA,IAAe,EAAE,OAAAO,GAAO,KAAAK,GAAK,QAAAF,EAAA,IAC1B;AAAA,IACL,KAAKP;AAAA,IACL,OAAAI;AAAA,IACA,KAAAK;AAAA,IACA,QAAAF;AAAA,EAAA;AAEJ;"}
@@ -1,16 +1,16 @@
1
- import { useRef as r, useMemo as m } from "react";
2
- const h = (o, c) => {
3
- const u = r(o), t = r(null), e = r(!1), l = r(c), n = r(null);
4
- return u.current = o, l.current = c, m(() => {
1
+ import { useRef as t, useMemo as m } from "react";
2
+ const h = (o, u) => {
3
+ const c = t(o), r = t(null), e = t(!1), l = t(u), n = t(null);
4
+ return c.current = o, l.current = u, m(() => {
5
5
  const s = () => {
6
- e.current = !1, n.current && (u.current.apply(void 0, n.current), n.current = null, setTimeout(s, l.current));
7
- }, a = () => {
8
- t.current && (clearTimeout(t.current), t.current = null, e.current = !1);
9
- }, f = function(...i) {
10
- n.current = i, !e.current && (u.current.apply(this, i), e.current = !0, t.current = setTimeout(s, l.current));
6
+ e.current = !1, n.current && (c.current.apply(void 0, n.current), n.current = null, setTimeout(s, l.current));
7
+ }, f = () => {
8
+ r.current && (clearTimeout(r.current), r.current = null, e.current = !1);
9
+ }, i = function(...a) {
10
+ n.current = a, !e.current && (c.current.apply(this, a), e.current = !0, r.current = setTimeout(s, l.current));
11
11
  };
12
- return f.cancel = a, console.log("cancel", t.current), a(), f;
13
- }, [c]);
12
+ return i.cancel = f, f(), i;
13
+ }, [u]);
14
14
  };
15
15
  export {
16
16
  h as useThrottleCallback
@@ -1 +1 @@
1
- {"version":3,"file":"useThrottleCallback.mjs","sources":["../../../../src/hooks/useThrottleCallback/useThrottleCallback.ts"],"sourcesContent":["import { useMemo, useRef } from 'react';\n\nexport type ThrottledCallback<Params extends unknown[]> = ((...args: Params) => void) & {\n cancel: () => void;\n};\n\n/**\n * @name useThrottleCallback\n * @description - Hook that creates a throttled callback\n * @category Utilities\n *\n * @template Params The type of the params\n * @template Return The type of the return\n * @param {(...args: Params) => Return} callback The callback function\n * @param {number} delay The delay in milliseconds\n * @returns {(...args: Params) => Return} The callback with throttle\n *\n * @example\n * const throttled = useThrottleCallback(() => console.log('callback'), 500);\n */\nexport const useThrottleCallback = <Params extends unknown[], Return>(\n callback: (...args: Params) => Return,\n delay: number\n): ThrottledCallback<Params> => {\n const internalCallbackRef = useRef(callback);\n const timeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n const isCalledRef = useRef(false);\n const delayRef = useRef(delay);\n const lastArgsRef = useRef<Params | null>(null);\n\n internalCallbackRef.current = callback;\n delayRef.current = delay;\n\n const throttled = useMemo(() => {\n const timer = () => {\n isCalledRef.current = false;\n\n if (!lastArgsRef.current) return;\n internalCallbackRef.current.apply(this, lastArgsRef.current);\n lastArgsRef.current = null;\n setTimeout(timer, delayRef.current);\n };\n\n const cancel = () => {\n if (!timeoutRef.current) return;\n clearTimeout(timeoutRef.current);\n timeoutRef.current = null;\n isCalledRef.current = false;\n };\n\n const throttledCallback = function (this: any, ...args: Params) {\n lastArgsRef.current = args;\n if (isCalledRef.current) return;\n\n internalCallbackRef.current.apply(this, args);\n isCalledRef.current = true;\n timeoutRef.current = setTimeout(timer, delayRef.current);\n };\n\n throttledCallback.cancel = cancel;\n\n console.log('cancel', timeoutRef.current);\n cancel();\n return throttledCallback;\n }, [delay]);\n\n return throttled;\n};\n"],"names":["useThrottleCallback","callback","delay","internalCallbackRef","useRef","timeoutRef","isCalledRef","delayRef","lastArgsRef","useMemo","timer","cancel","throttledCallback","args"],"mappings":";AAoBO,MAAMA,IAAsB,CACjCC,GACAC,MAC8B;AAC9B,QAAMC,IAAsBC,EAAOH,CAAQ,GACrCI,IAAaD,EAA6C,IAAI,GAC9DE,IAAcF,EAAO,EAAK,GAC1BG,IAAWH,EAAOF,CAAK,GACvBM,IAAcJ,EAAsB,IAAI;AAE9C,SAAAD,EAAoB,UAAUF,GAC9BM,EAAS,UAAUL,GAEDO,EAAQ,MAAM;AAC9B,UAAMC,IAAQ,MAAM;AAGlB,MAFAJ,EAAY,UAAU,IAEjBE,EAAY,YACjBL,EAAoB,QAAQ,MAAM,QAAMK,EAAY,OAAO,GAC3DA,EAAY,UAAU,MACtB,WAAWE,GAAOH,EAAS,OAAO;AAAA,IAAA,GAG9BI,IAAS,MAAM;AACnB,MAAKN,EAAW,YAChB,aAAaA,EAAW,OAAO,GAC/BA,EAAW,UAAU,MACrBC,EAAY,UAAU;AAAA,IAAA,GAGlBM,IAAoB,YAAwBC,GAAc;AAE9D,MADAL,EAAY,UAAUK,GAClB,CAAAP,EAAY,YAEhBH,EAAoB,QAAQ,MAAM,MAAMU,CAAI,GAC5CP,EAAY,UAAU,IACtBD,EAAW,UAAU,WAAWK,GAAOH,EAAS,OAAO;AAAA,IAAA;AAGzD,WAAAK,EAAkB,SAASD,GAE3B,QAAQ,IAAI,UAAUN,EAAW,OAAO,GACxCM,EAAA,GACOC;AAAA,EAAA,GACN,CAACV,CAAK,CAAC;AAGZ;"}
1
+ {"version":3,"file":"useThrottleCallback.mjs","sources":["../../../../src/hooks/useThrottleCallback/useThrottleCallback.ts"],"sourcesContent":["import { useMemo, useRef } from 'react';\n\nexport type ThrottledCallback<Params extends unknown[]> = ((...args: Params) => void) & {\n cancel: () => void;\n};\n\n/**\n * @name useThrottleCallback\n * @description - Hook that creates a throttled callback\n * @category Utilities\n *\n * @template Params The type of the params\n * @template Return The type of the return\n * @param {(...args: Params) => Return} callback The callback function\n * @param {number} delay The delay in milliseconds\n * @returns {(...args: Params) => Return} The callback with throttle\n *\n * @example\n * const throttled = useThrottleCallback(() => console.log('callback'), 500);\n */\nexport const useThrottleCallback = <Params extends unknown[], Return>(\n callback: (...args: Params) => Return,\n delay: number\n): ThrottledCallback<Params> => {\n const internalCallbackRef = useRef(callback);\n const timeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n const isCalledRef = useRef(false);\n const delayRef = useRef(delay);\n const lastArgsRef = useRef<Params | null>(null);\n\n internalCallbackRef.current = callback;\n delayRef.current = delay;\n\n const throttled = useMemo(() => {\n const timer = () => {\n isCalledRef.current = false;\n\n if (!lastArgsRef.current) return;\n internalCallbackRef.current.apply(this, lastArgsRef.current);\n lastArgsRef.current = null;\n setTimeout(timer, delayRef.current);\n };\n\n const cancel = () => {\n if (!timeoutRef.current) return;\n clearTimeout(timeoutRef.current);\n timeoutRef.current = null;\n isCalledRef.current = false;\n };\n\n const throttledCallback = function (this: any, ...args: Params) {\n lastArgsRef.current = args;\n if (isCalledRef.current) return;\n\n internalCallbackRef.current.apply(this, args);\n isCalledRef.current = true;\n timeoutRef.current = setTimeout(timer, delayRef.current);\n };\n\n throttledCallback.cancel = cancel;\n\n cancel();\n return throttledCallback;\n }, [delay]);\n\n return throttled;\n};\n"],"names":["useThrottleCallback","callback","delay","internalCallbackRef","useRef","timeoutRef","isCalledRef","delayRef","lastArgsRef","useMemo","timer","cancel","throttledCallback","args"],"mappings":";AAoBO,MAAMA,IAAsB,CACjCC,GACAC,MAC8B;AAC9B,QAAMC,IAAsBC,EAAOH,CAAQ,GACrCI,IAAaD,EAA6C,IAAI,GAC9DE,IAAcF,EAAO,EAAK,GAC1BG,IAAWH,EAAOF,CAAK,GACvBM,IAAcJ,EAAsB,IAAI;AAE9C,SAAAD,EAAoB,UAAUF,GAC9BM,EAAS,UAAUL,GAEDO,EAAQ,MAAM;AAC9B,UAAMC,IAAQ,MAAM;AAGlB,MAFAJ,EAAY,UAAU,IAEjBE,EAAY,YACjBL,EAAoB,QAAQ,MAAM,QAAMK,EAAY,OAAO,GAC3DA,EAAY,UAAU,MACtB,WAAWE,GAAOH,EAAS,OAAO;AAAA,IAAA,GAG9BI,IAAS,MAAM;AACnB,MAAKN,EAAW,YAChB,aAAaA,EAAW,OAAO,GAC/BA,EAAW,UAAU,MACrBC,EAAY,UAAU;AAAA,IAAA,GAGlBM,IAAoB,YAAwBC,GAAc;AAE9D,MADAL,EAAY,UAAUK,GAClB,CAAAP,EAAY,YAEhBH,EAAoB,QAAQ,MAAM,MAAMU,CAAI,GAC5CP,EAAY,UAAU,IACtBD,EAAW,UAAU,WAAWK,GAAOH,EAAS,OAAO;AAAA,IAAA;AAGzD,WAAAK,EAAkB,SAASD,GAE3BA,EAAA,GACOC;AAAA,EAAA,GACN,CAACV,CAAK,CAAC;AAGZ;"}
@@ -1,11 +1,15 @@
1
- import { useState as m } from "react";
2
- import { useInterval as o } from "../useInterval/useInterval.mjs";
1
+ import { useState as o, useEffect as s } from "react";
3
2
  import { getDate as e } from "../../utils/helpers/getDate.mjs";
4
- const p = () => {
5
- const [t, r] = m(e());
6
- return o(() => r(e()), 1e3), t;
3
+ const a = () => {
4
+ const [t, r] = o(e());
5
+ return s(() => {
6
+ const m = setInterval(() => r(e()), 1e3);
7
+ return () => {
8
+ clearInterval(m);
9
+ };
10
+ }, []), t;
7
11
  };
8
12
  export {
9
- p as useTime
13
+ a as useTime
10
14
  };
11
15
  //# sourceMappingURL=useTime.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"useTime.mjs","sources":["../../../../src/hooks/useTime/useTime.ts"],"sourcesContent":["import { useState } from 'react';\n\nimport { getDate } from '@/utils/helpers';\n\nimport { useInterval } from '../useInterval/useInterval';\n\nexport interface UseTimeReturn {\n day: number;\n hours: number;\n meridiemHours: { value: number; type: string };\n minutes: number;\n month: number;\n seconds: number;\n timestamp: number;\n year: number;\n}\n\n/**\n * @name useTime\n * @description - Hook that gives you current time in different values\n * @category Time\n *\n * @returns {UseTimeReturn} An object containing the current time\n *\n * @example\n * const { seconds, minutes, hours, meridiemHours, day, month, year, timestamp } = useTime();\n */\nexport const useTime = (): UseTimeReturn => {\n const [time, setTime] = useState(getDate());\n useInterval(() => setTime(getDate()), 1000);\n return time;\n};\n"],"names":["useTime","time","setTime","useState","getDate","useInterval"],"mappings":";;;AA2BO,MAAMA,IAAU,MAAqB;AAC1C,QAAM,CAACC,GAAMC,CAAO,IAAIC,EAASC,GAAS;AAC1C,SAAAC,EAAY,MAAMH,EAAQE,EAAA,CAAS,GAAG,GAAI,GACnCH;AACT;"}
1
+ {"version":3,"file":"useTime.mjs","sources":["../../../../src/hooks/useTime/useTime.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\nimport { getDate } from '@/utils/helpers';\n\nexport interface UseTimeReturn {\n /** The current day of the month (1-31) */\n day: number;\n /** The current hour in 24-hour format (0-23) */\n hours: number;\n /** The current hour in 12-hour format with meridiem type (AM/PM) */\n meridiemHours: { value: number; type: string };\n /** The current minute (0-59) */\n minutes: number;\n /** The current month (1-12) */\n month: number;\n /** The current second (0-59) */\n seconds: number;\n /** The current Unix timestamp in milliseconds */\n timestamp: number;\n /** The current year */\n year: number;\n}\n\n/**\n * @name useTime\n * @description - Hook that gives you current time in different values\n * @category Time\n *\n * @returns {UseTimeReturn} An object containing the current time\n *\n * @example\n * const { seconds, minutes, hours, meridiemHours, day, month, year, timestamp } = useTime();\n */\nexport const useTime = (): UseTimeReturn => {\n const [time, setTime] = useState(getDate());\n\n useEffect(() => {\n const timerId = setInterval(() => setTime(getDate()), 1000);\n\n return () => {\n clearInterval(timerId);\n };\n }, []);\n\n return time;\n};\n"],"names":["useTime","time","setTime","useState","getDate","useEffect","timerId"],"mappings":";;AAiCO,MAAMA,IAAU,MAAqB;AAC1C,QAAM,CAACC,GAAMC,CAAO,IAAIC,EAASC,GAAS;AAE1C,SAAAC,EAAU,MAAM;AACd,UAAMC,IAAU,YAAY,MAAMJ,EAAQE,EAAA,CAAS,GAAG,GAAI;AAE1D,WAAO,MAAM;AACX,oBAAcE,CAAO;AAAA,IAAA;AAAA,EACvB,GACC,EAAE,GAEEL;AACT;"}